From 91d04c64771832a0b8815ffbe1f0f9920320d94d Mon Sep 17 00:00:00 2001 From: Pamela Dragosh Date: Tue, 14 Feb 2017 19:41:00 -0500 Subject: [PATCH] Initial OpenECOMP policy/engine commit Change-Id: I7dbff37733b661643dd4d1caefa3d7dccc361b6e Signed-off-by: Pamela Dragosh --- .gitattributes | 40 + .gitignore | 29 + .gitreview | 4 + BRMSGateway/config.properties | 84 + BRMSGateway/policyLogger.properties | 44 + BRMSGateway/pom.xml | 112 + .../policy/brmsInterface/BRMSGateway.java | 88 + .../policy/brmsInterface/BRMSHandler.java | 134 + .../openecomp/policy/brmsInterface/BRMSPush.java | 627 + .../policy/brmsInterface/ControllerPOJO.java | 52 + .../policy/brmsInterface/NotificationPOJO.java | 52 + BRMSGateway/src/main/resources/log4j.properties | 48 + BRMSGateway/src/main/resources/logback.xml | 252 + ECOMP-PAP-REST/.gitignore | 4 + ECOMP-PAP-REST/WebContent/META-INF/MANIFEST.MF | 2 + ECOMP-PAP-REST/WebContent/README.txt | 0 ECOMP-PAP-REST/autopush.properties | 22 + ECOMP-PAP-REST/dictionaryItemsAPI.json | 52 + ECOMP-PAP-REST/policyLogger.properties | 44 + ECOMP-PAP-REST/pom.xml | 259 + ECOMP-PAP-REST/src/main/java/hibernate.cfg.xml | 73 + .../policy/pap/xacml/rest/HibernateSession.java | 60 + .../openecomp/policy/pap/xacml/rest/WebConfig.java | 80 + .../policy/pap/xacml/rest/XACMLPapServlet.java | 4858 ++ .../policy/pap/xacml/rest/adapters/GridData.java | 62 + .../pap/xacml/rest/adapters/PolicyRestAdapter.java | 480 + .../pap/xacml/rest/adapters/package-info.java | 27 + .../pap/xacml/rest/components/ActionPolicy.java | 626 + .../pap/xacml/rest/components/AutoPushPolicy.java | 170 + .../xacml/rest/components/ClosedLoopPolicy.java | 552 + .../pap/xacml/rest/components/ConfigPolicy.java | 693 + .../rest/components/CreateBrmsParamPolicy.java | 896 + .../xacml/rest/components/CreateBrmsRawPolicy.java | 661 + .../CreateClosedLoopPerformanceMetrics.java | 506 + .../components/CreateNewMicroSerivceModel.java | 305 + .../pap/xacml/rest/components/DecisionPolicy.java | 633 + .../rest/components/FirewallConfigPolicy.java | 1871 + .../rest/components/MicroServiceConfigPolicy.java | 561 + .../policy/pap/xacml/rest/components/Policy.java | 455 + .../pap/xacml/rest/components/PolicyDBDao.java | 3936 ++ .../rest/components/PolicyDBDaoTransaction.java | 202 + .../pap/xacml/rest/components/package-info.java | 27 + .../ActionPolicyDictionaryController.java | 201 + .../rest/controller/BRMSDictionaryController.java | 183 + .../CheckDictionaryDuplicateEntries.java | 65 + .../controller/ClosedLoopDictionaryController.java | 764 + .../DecisionPolicyDictionaryController.java | 188 + .../DescriptiveDictionaryController.java | 190 + .../rest/controller/DictionaryController.java | 366 + .../controller/DictionaryImportController.java | 617 + .../controller/EnforcerDictionaryController.java | 127 + .../controller/FirewallDictionaryController.java | 1578 + .../MicroServiceDictionaryController.java | 718 + .../PolicyScopeDictionaryController.java | 667 + .../rest/controller/SafePolicyController.java | 319 + .../pap/xacml/rest/controller/package-info.java | 27 + .../pap/xacml/rest/daoimpl/ActionListDaoImpl.java | 158 + .../rest/daoimpl/ActionPolicyDictDaoImpl.java | 185 + .../xacml/rest/daoimpl/AddressGroupDaoImpl.java | 157 + .../pap/xacml/rest/daoimpl/AttributeDaoImpl.java | 157 + .../rest/daoimpl/BRMSParamTemplateDaoImpl.java | 157 + .../pap/xacml/rest/daoimpl/CategoryDaoImpl.java | 76 + .../pap/xacml/rest/daoimpl/DCAEUUIDDaoImpl.java | 157 + .../xacml/rest/daoimpl/DecisionPolicyDaoImpl.java | 158 + .../rest/daoimpl/DescriptiveScopeDaoImpl.java | 182 + .../pap/xacml/rest/daoimpl/EcompNameDaoImpl.java | 167 + .../xacml/rest/daoimpl/EnforcerPolicyDaoImpl.java | 132 + .../daoimpl/FirewallDictionaryListDaoImpl.java | 202 + .../rest/daoimpl/GroupPolicyScopeListDaoImpl.java | 182 + .../daoimpl/MicroServiceConfigNameDaoImpl.java | 158 + .../rest/daoimpl/MicroServiceLocationDaoImpl.java | 158 + .../rest/daoimpl/MicroServiceModelsDaoImpl.java | 161 + .../pap/xacml/rest/daoimpl/PEPOptionsDaoImpl.java | 159 + .../rest/daoimpl/PolicyScopeClosedLoopDaoImpl.java | 181 + .../rest/daoimpl/PolicyScopeResourceDaoImpl.java | 181 + .../rest/daoimpl/PolicyScopeServiceDaoImpl.java | 182 + .../xacml/rest/daoimpl/PolicyScopeTypeDaoImpl.java | 182 + .../pap/xacml/rest/daoimpl/PortListDaoImpl.java | 158 + .../pap/xacml/rest/daoimpl/PrefixListDaoImpl.java | 158 + .../xacml/rest/daoimpl/ProtocolListDaoImpl.java | 158 + .../pap/xacml/rest/daoimpl/RiskTypeDaoImpl.java | 167 + .../rest/daoimpl/SafePolicyWarningDaoImpl.java | 181 + .../xacml/rest/daoimpl/SecurityZoneDaoImpl.java | 157 + .../rest/daoimpl/ServiceDictionaryDaoImpl.java | 157 + .../xacml/rest/daoimpl/ServiceGroupDaoImpl.java | 158 + .../pap/xacml/rest/daoimpl/ServiceListDaoImpl.java | 159 + .../xacml/rest/daoimpl/SiteDictionaryDaoImpl.java | 159 + .../pap/xacml/rest/daoimpl/TermListDaoImpl.java | 181 + .../pap/xacml/rest/daoimpl/UserInfoDaoImpl.java | 138 + .../pap/xacml/rest/daoimpl/VNFTypeDaoImpl.java | 158 + .../pap/xacml/rest/daoimpl/VSCLActionDaoImpl.java | 158 + .../rest/daoimpl/VarbindDictionaryDaoImpl.java | 181 + .../policy/pap/xacml/rest/daoimpl/ZoneDaoImpl.java | 159 + .../pap/xacml/rest/model/PDPPolicyContainer.java | 349 + .../pap/xacml/rest/model/RemoveGroupPolicy.java | 105 + .../policy/pap/xacml/rest/model/package-info.java | 27 + .../policy/pap/xacml/rest/util/JPAUtils.java | 242 + .../policy/pap/xacml/rest/util/JsonMessage.java | 67 + .../pap/xacml/rest/util/PolicyContainer.java | 121 + .../rest/util/PolicyItemSetChangeNotifier.java | 96 + .../pap/xacml/restAuth/AuthenticationService.java | 74 + .../policy/pap/xacml/restAuth/CheckPDP.java | 203 + .../xacml/restAuth/PAPAuthenticationFilter.java | 130 + .../src/main/resources/META-INF/drop.ddl | 7 + .../src/main/resources/META-INF/persistence.xml | 201 + ECOMP-PAP-REST/src/main/resources/log4j.properties | 71 + ECOMP-PAP-REST/src/main/resources/logback.xml | 253 + ECOMP-PAP-REST/src/main/resources/spring.xml | 46 + .../policy/pap/ia/DbAuditCompareEntriesTest.java | 519 + .../policy/pap/xacml/rest/XACMLPapServletTest.java | 368 + .../pap/xacml/rest/components/PolicyDBDaoTest.java | 823 + .../pap/xacml/rest/jpa/PolicyEntityTest.java | 802 + ECOMP-PAP-REST/test.properties | 22 + ECOMP-PAP-REST/xacml.pap.properties | 155 + ECOMP-PAP-REST/xacml.pap.test.properties | 151 + ECOMP-PDP-REST/.gitignore | 4 + ECOMP-PDP-REST/WebContent/META-INF/MANIFEST.MF | 2 + ECOMP-PDP-REST/WebContent/WEB-INF/.gitignore | 1 + ECOMP-PDP-REST/config_testing/xacml.pip.properties | 23 + .../config_testing/xacml.policy.properties | 24 + ECOMP-PDP-REST/policyLogger.properties | 44 + ECOMP-PDP-REST/pom.xml | 206 + .../openecomp/policy/pdp/rest/PapUrlResolver.java | 387 + .../openecomp/policy/pdp/rest/XACMLPdpLoader.java | 695 + .../policy/pdp/rest/XACMLPdpRegisterThread.java | 333 + .../openecomp/policy/pdp/rest/XACMLPdpServlet.java | 1138 + .../pdp/rest/impl/XACMLPdpPIPFinderFactory.java | 88 + .../pdp/rest/impl/XACMLPdpPolicyFinderFactory.java | 208 + .../policy/pdp/rest/jmx/PdpRestMBeanListener.java | 87 + .../policy/pdp/rest/jmx/PdpRestMonitor.java | 161 + .../policy/pdp/rest/jmx/PdpRestMonitorMBean.java | 40 + .../ManualNotificationUpdateThread.java | 151 + .../pdp/rest/notifications/Notification.java | 52 + .../rest/notifications/NotificationController.java | 391 + .../pdp/rest/notifications/NotificationServer.java | 141 + .../policy/pdp/rest/notifications/Removed.java | 52 + .../policy/pdp/rest/notifications/Updated.java | 61 + .../pdp/rest/notifications/package-info.java | 28 + .../pdp/rest/restAuth/AuthenticationService.java | 72 + .../pdp/rest/restAuth/PDPAuthenticationFilter.java | 78 + ECOMP-PDP-REST/src/main/resources/log4j.properties | 71 + ECOMP-PDP-REST/src/main/resources/logback.xml | 253 + .../policy/pdp/rest/PapUrlResolverTest.java | 355 + .../policy/pdp/rest/XACMLPdpServletTest.java | 395 + ECOMP-PDP-REST/xacml.pdp.properties | 152 + ECOMP-PDP/.gitignore | 13 + ECOMP-PDP/logging.properties | 29 + ECOMP-PDP/policyLogger.properties | 44 + ECOMP-PDP/pom.xml | 114 + ECOMP-PDP/sql/xacmlTest.mv.db | Bin 0 -> 143360 bytes .../openecomp/policy/xacml/action/FindAction.java | 377 + .../policy/xacml/action/package-info.java | 30 + .../custom/EcompFunctionDefinitionFactory.java | 85 + .../openecomp/policy/xacml/pdp/ECOMPPDPEngine.java | 64 + .../policy/xacml/pdp/ECOMPPDPEngineFactory.java | 54 + .../FunctionDefinitionCustomRegexpMatch.java | 123 + .../policy/xacml/pdp/std/functions/PolicyList.java | 60 + .../FunctionDefinitionAccessPermittedTest.java | 522 + .../pdp/test/FunctionDefinitionArithmeticTest.java | 717 + .../pdp/test/FunctionDefinitionBagIsInTest.java | 221 + .../test/FunctionDefinitionBagOneAndOnlyTest.java | 224 + .../pdp/test/FunctionDefinitionBagSizeTest.java | 158 + .../policy/pdp/test/FunctionDefinitionBagTest.java | 547 + .../pdp/test/FunctionDefinitionBaseTest.java | 131 + .../pdp/test/FunctionDefinitionComparisonTest.java | 1366 + .../FunctionDefinitionDateTimeArithmeticTest.java | 1602 + .../pdp/test/FunctionDefinitionEqualityTest.java | 1192 + .../test/FunctionDefinitionHigherOrderBagTest.java | 2193 + .../FunctionDefinitionHomogeneousSimpleTest.java | 151 + .../pdp/test/FunctionDefinitionLogicalTest.java | 422 + ...FunctionDefinitionNumberTypeConversionTest.java | 119 + .../test/FunctionDefinitionRegexpMatchTest.java | 511 + .../policy/pdp/test/FunctionDefinitionSetTest.java | 1903 + .../test/FunctionDefinitionSpecialMatchTest.java | 487 + .../FunctionDefinitionStringConversionTest.java | 2504 + ...unctionDefinitionStringEqualIgnoreCaseTest.java | 129 + .../FunctionDefinitionStringFunctionsTest.java | 1497 + .../FunctionDefinitionStringNormalizeTest.java | 118 + ...FunctionDefinitionURIStringConcatenateTest.java | 185 + .../pdp/test/FunctionDefinitionXPathTest.java | 1127 + .../org/openecomp/policy/pdp/test/PDPTest.java | 42 + .../org/openecomp/policy/pdp/test/TestRunner.java | 44 + .../policy/pdp/test/conformance/Conformance.java | 634 + .../pdp/test/conformance/ConformancePIPEngine.java | 244 + .../test/conformance/ConformanceRepository.java | 127 + .../test/conformance/ConformanceScopeResolver.java | 123 + .../pdp/test/conformance/ConformanceTest.java | 104 + .../test/conformance/ConformanceTestEngine.java | 221 + .../test/conformance/ConformanceTestResult.java | 122 + .../pdp/test/conformance/ConformanceTestSet.java | 182 + .../pdp/test/conformance/ResponseMatchResult.java | 137 + .../pdp/test/conformance/ResultMatchResult.java | 136 + .../pdp/test/custom/CustomDataTypeFactory.java | 88 + .../custom/CustomFunctionDefinitionFactory.java | 90 + .../policy/pdp/test/custom/DataTypePrivateKey.java | 54 + .../policy/pdp/test/custom/DataTypePublicKey.java | 54 + .../pdp/test/custom/FunctionDefinitionDecrypt.java | 162 + .../openecomp/policy/pdp/test/custom/TestBase.java | 1084 + .../policy/pdp/test/custom/TestCustom.java | 394 + ECOMP-PDP/src/test/resources/log4j.properties | 42 + ECOMP-PDP/src/test/resources/logback.xml | 252 + ECOMP-PDP/src/test/resources/logging.properties | 32 + ECOMP-PDP/src/test/resources/xacml.pip.properties | 23 + .../src/test/resources/xacml.policy.properties | 25 + ECOMP-PDP/testclient.properties | 21 + ECOMP-PDP/testpdp.properties | 21 + ECOMP-PDP/xacml.pap.properties | 107 + ECOMP-PDP/xacml.pdp.properties | 86 + ECOMP-PDP/xacml.properties | 46 + ECOMP-REST/.gitignore | 6 + ECOMP-REST/policyLogger.properties | 44 + ECOMP-REST/pom.xml | 116 + .../java/org/openecomp/policy/rest/XACMLRest.java | 220 + .../openecomp/policy/rest/XACMLRestProperties.java | 443 + .../policy/rest/XacmlAdminAuthorization.java | 223 + .../openecomp/policy/rest/dao/ActionListDao.java | 33 + .../policy/rest/dao/ActionPolicyDictDao.java | 34 + .../openecomp/policy/rest/dao/AddressGroupDao.java | 33 + .../openecomp/policy/rest/dao/AttributeDao.java | 35 + .../policy/rest/dao/BRMSParamTemplateDao.java | 33 + .../org/openecomp/policy/rest/dao/CategoryDao.java | 29 + .../org/openecomp/policy/rest/dao/DCAEUUIDDao.java | 33 + .../policy/rest/dao/DecisionPolicyDao.java | 33 + .../policy/rest/dao/DescriptiveScopeDao.java | 35 + .../openecomp/policy/rest/dao/EcompNameDao.java | 34 + .../policy/rest/dao/EnforcerPolicyDao.java | 32 + .../policy/rest/dao/FirewallDictionaryListDao.java | 37 + .../policy/rest/dao/GroupPolicyScopeListDao.java | 34 + .../policy/rest/dao/MicroServiceConfigNameDao.java | 33 + .../policy/rest/dao/MicroServiceLocationDao.java | 33 + .../policy/rest/dao/MicroServiceModelsDao.java | 33 + .../openecomp/policy/rest/dao/PEPOptionsDao.java | 35 + .../policy/rest/dao/PolicyScopeClosedLoopDao.java | 34 + .../policy/rest/dao/PolicyScopeResourceDao.java | 34 + .../policy/rest/dao/PolicyScopeServiceDao.java | 34 + .../policy/rest/dao/PolicyScopeTypeDao.java | 34 + .../org/openecomp/policy/rest/dao/PortListDao.java | 33 + .../openecomp/policy/rest/dao/PrefixListDao.java | 33 + .../openecomp/policy/rest/dao/ProtocolListDao.java | 33 + .../org/openecomp/policy/rest/dao/RiskTypeDao.java | 34 + .../policy/rest/dao/SafePolicyWarningDao.java | 34 + .../openecomp/policy/rest/dao/SecurityZoneDao.java | 33 + .../policy/rest/dao/ServiceDictionaryDao.java | 33 + .../openecomp/policy/rest/dao/ServiceGroupDao.java | 33 + .../openecomp/policy/rest/dao/ServiceListDao.java | 34 + .../policy/rest/dao/SiteDictionaryDao.java | 33 + .../org/openecomp/policy/rest/dao/TermListDao.java | 34 + .../org/openecomp/policy/rest/dao/UserInfoDao.java | 32 + .../org/openecomp/policy/rest/dao/VNFTypeDao.java | 34 + .../openecomp/policy/rest/dao/VSCLActionDao.java | 35 + .../policy/rest/dao/VarbindDictionaryDao.java | 34 + .../org/openecomp/policy/rest/dao/ZoneDao.java | 33 + .../openecomp/policy/rest/dao/package-info.java | 27 + .../policy/rest/jpa/ActionBodyEntity.java | 198 + .../org/openecomp/policy/rest/jpa/ActionList.java | 106 + .../policy/rest/jpa/ActionPolicyDict.java | 215 + .../openecomp/policy/rest/jpa/AddressGroup.java | 115 + .../org/openecomp/policy/rest/jpa/Attribute.java | 376 + .../policy/rest/jpa/AttributeAssignment.java | 93 + .../policy/rest/jpa/BRMSParamTemplate.java | 142 + .../org/openecomp/policy/rest/jpa/Category.java | 219 + .../policy/rest/jpa/ClosedLoopD2Services.java | 177 + .../openecomp/policy/rest/jpa/ClosedLoopSite.java | 178 + .../policy/rest/jpa/ConfigurationDataEntity.java | 227 + .../openecomp/policy/rest/jpa/ConstraintType.java | 117 + .../openecomp/policy/rest/jpa/ConstraintValue.java | 116 + .../org/openecomp/policy/rest/jpa/DCAEUsers.java | 103 + .../org/openecomp/policy/rest/jpa/DCAEuuid.java | 103 + .../policy/rest/jpa/DatabaseLockEntity.java | 47 + .../org/openecomp/policy/rest/jpa/Datatype.java | 245 + .../policy/rest/jpa/DecisionSettings.java | 245 + .../policy/rest/jpa/DescriptiveScope.java | 182 + .../org/openecomp/policy/rest/jpa/EcompName.java | 178 + .../openecomp/policy/rest/jpa/EnforcingType.java | 96 + .../policy/rest/jpa/FirewallDictionaryList.java | 185 + .../policy/rest/jpa/FunctionArgument.java | 122 + .../policy/rest/jpa/FunctionDefinition.java | 219 + .../policy/rest/jpa/GlobalRoleSettings.java | 93 + .../org/openecomp/policy/rest/jpa/GroupEntity.java | 276 + .../policy/rest/jpa/GroupPolicyScopeList.java | 114 + .../policy/rest/jpa/GroupServiceList.java | 107 + .../policy/rest/jpa/MicroServiceConfigName.java | 103 + .../policy/rest/jpa/MicroServiceLocation.java | 103 + .../policy/rest/jpa/MicroServiceModels.java | 172 + .../org/openecomp/policy/rest/jpa/Obadvice.java | 227 + .../policy/rest/jpa/ObadviceExpression.java | 126 + .../org/openecomp/policy/rest/jpa/PEPOptions.java | 184 + .../openecomp/policy/rest/jpa/PIPConfigParam.java | 147 + .../policy/rest/jpa/PIPConfiguration.java | 572 + .../org/openecomp/policy/rest/jpa/PIPResolver.java | 365 + .../policy/rest/jpa/PIPResolverParam.java | 147 + .../org/openecomp/policy/rest/jpa/PIPType.java | 131 + .../org/openecomp/policy/rest/jpa/PREFIXLIST.java | 117 + .../org/openecomp/policy/rest/jpa/PdpEntity.java | 247 + .../policy/rest/jpa/PolicyAlgorithms.java | 116 + .../policy/rest/jpa/PolicyDBDaoEntity.java | 150 + .../policy/rest/jpa/PolicyEditorScopes.java | 159 + .../openecomp/policy/rest/jpa/PolicyEntity.java | 318 + .../policy/rest/jpa/PolicyManagement.java | 162 + .../org/openecomp/policy/rest/jpa/PolicyRoles.java | 102 + .../policy/rest/jpa/PolicyScopeClosedLoop.java | 101 + .../policy/rest/jpa/PolicyScopeResource.java | 101 + .../policy/rest/jpa/PolicyScopeService.java | 101 + .../openecomp/policy/rest/jpa/PolicyScopeType.java | 101 + .../org/openecomp/policy/rest/jpa/PolicyScore.java | 109 + .../openecomp/policy/rest/jpa/PolicyVersion.java | 182 + .../org/openecomp/policy/rest/jpa/PortList.java | 107 + .../openecomp/policy/rest/jpa/ProtocolList.java | 108 + .../policy/rest/jpa/RemoteCatalogValues.java | 103 + .../org/openecomp/policy/rest/jpa/RiskType.java | 178 + .../openecomp/policy/rest/jpa/RuleAlgorithms.java | 125 + .../policy/rest/jpa/SafePolicyWarning.java | 109 + .../openecomp/policy/rest/jpa/SecurityZone.java | 104 + .../org/openecomp/policy/rest/jpa/ServiceList.java | 157 + .../org/openecomp/policy/rest/jpa/SystemLogDB.java | 173 + .../org/openecomp/policy/rest/jpa/TermList.java | 262 + .../org/openecomp/policy/rest/jpa/UserInfo.java | 76 + .../java/org/openecomp/policy/rest/jpa/VMType.java | 103 + .../org/openecomp/policy/rest/jpa/VNFType.java | 174 + .../org/openecomp/policy/rest/jpa/VSCLAction.java | 174 + .../policy/rest/jpa/VarbindDictionary.java | 185 + .../rest/jpa/WatchPolicyNotificationTable.java | 80 + .../java/org/openecomp/policy/rest/jpa/Zone.java | 104 + .../openecomp/policy/rest/jpa/package-info.java | 27 + .../policy/rest/util/LockdownListener.java | 36 + .../policy/rest/util/MSAttributeObject.java | 88 + .../policy/rest/util/MSAttributeValue.java | 60 + .../openecomp/policy/rest/util/MSModelUtitils.java | 450 + .../openecomp/policy/rest/util/ModelObject.java | 157 + .../org/openecomp/policy/rest/util/Webapps.java | 113 + .../org/openecomp/policy/rest/XACMLRestTest.java | 108 + ECOMP-TEST/.gitignore | 2 + ECOMP-TEST/policyLogger.properties | 44 + ECOMP-TEST/pom.xml | 157 + ECOMP-TEST/sql/xacmlTest.mv.db | Bin 0 -> 143360 bytes .../org/openecomp/policy/pdp/test/TestBase.java | 1082 + .../pdp/test/annotations/TestAnnotation.java | 240 + .../policy/pdp/test/conformance/Conformance.java | 634 + .../pdp/test/conformance/ConformancePIPEngine.java | 242 + .../test/conformance/ConformanceRepository.java | 127 + .../test/conformance/ConformanceScopeResolver.java | 121 + .../pdp/test/conformance/ConformanceTest.java | 104 + .../test/conformance/ConformanceTestEngine.java | 219 + .../test/conformance/ConformanceTestResult.java | 122 + .../pdp/test/conformance/ConformanceTestSet.java | 180 + .../pdp/test/conformance/ResponseMatchResult.java | 137 + .../pdp/test/conformance/ResultMatchResult.java | 136 + .../pdp/test/custom/CustomDataTypeFactory.java | 88 + .../custom/CustomFunctionDefinitionFactory.java | 90 + .../policy/pdp/test/custom/DataTypePrivateKey.java | 54 + .../policy/pdp/test/custom/DataTypePublicKey.java | 54 + .../pdp/test/custom/FunctionDefinitionDecrypt.java | 162 + .../policy/pdp/test/custom/TestCustom.java | 393 + .../policy/pdp/test/policy/TestPolicy.java | 794 + .../test/std/dom/DOMResponseConformanceTest.java | 196 + .../policy/pdp/test/std/dom/DOMResponseTest.java | 2316 + .../FunctionDefinitionAccessPermittedTest.java | 522 + .../FunctionDefinitionArithmeticTest.java | 717 + .../functions/FunctionDefinitionBagIsInTest.java | 221 + .../FunctionDefinitionBagOneAndOnlyTest.java | 224 + .../functions/FunctionDefinitionBagSizeTest.java | 158 + .../std/functions/FunctionDefinitionBagTest.java | 547 + .../std/functions/FunctionDefinitionBaseTest.java | 131 + .../FunctionDefinitionComparisonTest.java | 1367 + .../FunctionDefinitionDateTimeArithmeticTest.java | 1602 + .../functions/FunctionDefinitionEqualityTest.java | 1192 + .../FunctionDefinitionHigherOrderBagTest.java | 2193 + .../FunctionDefinitionHomogeneousSimpleTest.java | 150 + .../functions/FunctionDefinitionLogicalTest.java | 422 + ...FunctionDefinitionNumberTypeConversionTest.java | 119 + .../FunctionDefinitionRegexpMatchTest.java | 511 + .../std/functions/FunctionDefinitionSetTest.java | 1903 + .../FunctionDefinitionSpecialMatchTest.java | 488 + .../FunctionDefinitionStringConversionTest.java | 2504 + ...unctionDefinitionStringEqualIgnoreCaseTest.java | 129 + .../FunctionDefinitionStringFunctionsTest.java | 1497 + .../FunctionDefinitionStringNormalizeTest.java | 118 + ...FunctionDefinitionURIStringConcatenateTest.java | 185 + .../std/functions/FunctionDefinitionXPathTest.java | 1127 + .../pdp/test/std/json/RequestCategoryTest.java | 4174 ++ .../pdp/test/std/json/RequestConformanceTest.java | 255 + .../test/std/json/RequestDefaultCategoryTest.java | 1427 + .../policy/pdp/test/std/json/RequestMainTest.java | 1076 + .../pdp/test/std/json/ResponseConformanceTest.java | 370 + .../policy/pdp/test/std/json/ResponseTest.java | 2297 + ECOMP-TEST/src/test/resources/log4j.properties | 42 + ECOMP-TEST/src/test/resources/logging.properties | 32 + ECOMP-TEST/src/test/resources/xacml.pip.properties | 23 + .../src/test/resources/xacml.policy.properties | 25 + ECOMP-TEST/testclient.properties | 21 + ECOMP-TEST/testpdp.properties | 21 + ECOMP-TEST/xacml.pap.properties | 107 + ECOMP-TEST/xacml.pdp.properties | 86 + ECOMP-XACML/.gitignore | 5 + ECOMP-XACML/policyLogger.properties | 44 + ECOMP-XACML/pom.xml | 150 + ECOMP-XACML/sql/xacmlTest.mv.db | Bin 0 -> 143360 bytes .../policy/xacml/api/XACMLErrorConstants.java | 56 + .../xacml/api/pap/ECOMPPapEngineFactory.java | 38 + .../policy/xacml/api/pap/EcompPAPPolicy.java | 89 + .../openecomp/policy/xacml/api/pap/EcompPDP.java | 46 + .../policy/xacml/api/pap/EcompPDPGroup.java | 11 + .../policy/xacml/api/pap/PAPPolicyEngine.java | 66 + .../openecomp/policy/xacml/std/pap/StdEngine.java | 1087 + .../policy/xacml/std/pap/StdEngineFactory.java | 57 + .../policy/xacml/std/pap/StdPAPPolicy.java | 889 + .../org/openecomp/policy/xacml/std/pap/StdPDP.java | 222 + .../policy/xacml/std/pap/StdPDPGroup.java | 1031 + .../policy/xacml/std/pap/StdPDPGroupStatus.java | 405 + .../xacml/std/pap/StdPDPItemSetChangeNotifier.java | 84 + .../policy/xacml/std/pap/StdPDPPIPConfig.java | 217 + .../policy/xacml/std/pap/StdPDPPolicy.java | 368 + .../policy/xacml/std/pap/StdPDPStatus.java | 265 + .../xacml/std/pip/engines/aaf/AAFEngine.java | 276 + .../openecomp/policy/xacml/util/MetricsUtil.java | 80 + .../policy/xacml/util/XACMLPolicyScanner.java | 727 + .../policy/xacml/util/XACMLPolicyWriter.java | 344 + ECOMP-XACML/src/main/resources/xacml.properties | 46 + .../xacml/test/DOMResponseConformanceTest.java | 196 + .../policy/xacml/test/DOMResponseTest.java | 2316 + .../policy/xacml/test/TestAnnotation.java | 239 + .../org/openecomp/policy/xacml/test/TestBase.java | 1082 + .../openecomp/policy/xacml/test/TestPolicy.java | 792 + .../policy/xacml/test/XACMLEngineTest.java | 84 + .../xacml/test/components/XACMLPDPPolicyTest.java | 49 + .../xacml/test/json/RequestCategoryTest.java | 4174 ++ .../xacml/test/json/RequestConformanceTest.java | 253 + .../test/json/RequestDefaultCategoryTest.java | 1427 + .../policy/xacml/test/json/RequestMainTest.java | 1076 + .../xacml/test/json/ResponseConformanceTest.java | 370 + .../policy/xacml/test/json/ResponseTest.java | 2297 + ECOMP-XACML/src/test/resources/log4j.properties | 42 + ECOMP-XACML/src/test/resources/logback.xml | 252 + ECOMP-XACML/src/test/resources/logging.properties | 32 + .../src/test/resources/xacml.pip.properties | 23 + .../src/test/resources/xacml.policy.properties | 25 + ECOMP-XACML/testclient.properties | 21 + ECOMP-XACML/testpdp.properties | 21 + ECOMP-XACML/xacml.pap.properties | 107 + ECOMP-XACML/xacml.pdp.properties | 86 + ECOMP-XACML/xacml.properties | 46 + LICENSE.txt | 16 + LogParser/.gitignore | 2 + LogParser/LineTest.txt | 9 + LogParser/LineTest2.txt | 7 + LogParser/parserlog.properties | 38 + LogParser/policyLogger.properties | 44 + LogParser/pom.xml | 113 + LogParser/src/META-INF/MANIFEST.MF | 3 + .../org/openecomp/xacml/parser/LogEntryObject.java | 74 + .../java/org/openecomp/xacml/parser/ParseLog.java | 437 + LogParser/src/main/scripts/parserlog.sh | 130 + .../org/openecomp/xacml/parser/ParseLogTest.java | 382 + LogParser/test_config.properties | 31 + PolicyEngineAPI/Config/Config.properties | 26 + PolicyEngineAPI/policyLogger.properties | 44 + PolicyEngineAPI/pom.xml | 165 + PolicyEngineAPI/src/log4j.properties | 48 + .../org/openecomp/policy/api/AttributeType.java | 66 + .../policy/api/ConfigRequestParameters.java | 148 + .../policy/api/DecisionRequestParameters.java | 104 + .../org/openecomp/policy/api/DecisionResponse.java | 43 + .../policy/api/DeletePolicyCondition.java | 53 + .../policy/api/DeletePolicyParameters.java | 101 + .../openecomp/policy/api/DictionaryParameters.java | 83 + .../org/openecomp/policy/api/DictionaryType.java | 73 + .../policy/api/EventRequestParameters.java | 89 + .../org/openecomp/policy/api/ImportParameters.java | 194 + .../openecomp/policy/api/NotificationScheme.java | 61 + .../openecomp/policy/api/PolicyChangeResponse.java | 44 + .../java/org/openecomp/policy/api/PolicyClass.java | 56 + .../org/openecomp/policy/api/PolicyConfig.java | 123 + .../policy/api/PolicyConfigException.java | 49 + .../openecomp/policy/api/PolicyConfigStatus.java | 68 + .../org/openecomp/policy/api/PolicyConfigType.java | 73 + .../org/openecomp/policy/api/PolicyDecision.java | 57 + .../policy/api/PolicyDecisionException.java | 50 + .../org/openecomp/policy/api/PolicyEngine.java | 575 + .../policy/api/PolicyEngineException.java | 49 + .../openecomp/policy/api/PolicyEventException.java | 49 + .../org/openecomp/policy/api/PolicyParameters.java | 497 + .../org/openecomp/policy/api/PolicyResponse.java | 77 + .../openecomp/policy/api/PolicyResponseStatus.java | 73 + .../java/org/openecomp/policy/api/PolicyType.java | 61 + .../openecomp/policy/api/PushPolicyParameters.java | 131 + .../org/openecomp/policy/api/RuleProvider.java | 53 + .../org/openecomp/policy/api/package-info.java | 36 + .../org/openecomp/policy/std/AutoClientEnd.java | 244 + .../org/openecomp/policy/std/AutoClientUEB.java | 170 + .../org/openecomp/policy/std/ManualClientEnd.java | 138 + .../openecomp/policy/std/ManualClientEndUEB.java | 173 + .../java/org/openecomp/policy/std/MatchStore.java | 246 + .../java/org/openecomp/policy/std/Matches.java | 48 + .../policy/std/NotificationUnMarshal.java | 69 + .../openecomp/policy/std/StdDecisionResponse.java | 55 + .../policy/std/StdPolicyChangeResponse.java | 47 + .../org/openecomp/policy/std/StdPolicyConfig.java | 168 + .../org/openecomp/policy/std/StdPolicyEngine.java | 4227 ++ .../openecomp/policy/std/StdPolicyResponse.java | 98 + .../java/org/openecomp/policy/std/StdStatus.java | 235 + .../org/openecomp/policy/std/package-info.java | 27 + .../src/main/resources/log4j.properties | 56 + PolicyEngineAPI/src/main/resources/logback.xml | 252 + .../policy/std/test/AutoClientEndTest.java | 312 + .../policy/std/test/AutoClientUEBTest.java | 569 + .../org/openecomp/policy/std/test/Handler.java | 120 + .../policy/std/test/ManualClientEndTest.java | 195 + .../policy/std/test/ManualClientEndUEBTest.java | 164 + .../openecomp/policy/std/test/MatchStoreTest.java | 774 + .../org/openecomp/policy/std/test/MatchesTest.java | 216 + .../policy/std/test/NotificationStoreTest.java | 359 + .../policy/std/test/NotificationUnMarshalTest.java | 256 + .../policy/std/test/StdLoadedPolicyTest.java | 314 + .../policy/std/test/StdPDPNotificationTest.java | 311 + .../std/test/StdPolicyChangeResponseTest.java | 166 + .../policy/std/test/StdPolicyConfigTest.java | 821 + .../policy/std/test/StdPolicyEngineTest.java | 1002 + .../policy/std/test/StdPolicyResponseTest.java | 348 + .../policy/std/test/StdRemovedPolicyTest.java | 206 + .../openecomp/policy/std/test/StdStatusTest.java | 1433 + .../openecomp/policy/std/test/package-info.java | 27 + .../openecomp/policy/test/ActionPolicyApiTest.java | 240 + .../openecomp/policy/test/AttributeTypeTest.java | 81 + .../policy/test/ConfigBasePolicyTest.java | 325 + .../policy/test/ConfigFirewallPolicyTest.java | 256 + .../policy/test/ConfigRequestParametersTest.java | 362 + .../policy/test/DecisionPolicyApiTest.java | 221 + .../policy/test/DecisionRequestParametersTest.java | 232 + .../policy/test/DeletePolicyConditionTest.java | 91 + .../policy/test/DeletePolicyParametersTest.java | 314 + .../policy/test/EventRequestParametersTest.java | 193 + .../policy/test/GetConfigByPolicyNameTest.java | 64 + .../policy/test/GetConfigStringStringMapTest.java | 251 + .../policy/test/GetConfigStringStringTest.java | 207 + .../openecomp/policy/test/GetConfigStringTest.java | 175 + .../policy/test/ImportParametersTest.java | 464 + .../openecomp/policy/test/LoadedPolicyTest.java | 75 + .../policy/test/NotificationHandlerTest.java | 73 + .../policy/test/NotificationSchemeTest.java | 91 + .../policy/test/NotificationTypeTest.java | 91 + .../openecomp/policy/test/PDPNotificationTest.java | 75 + .../policy/test/PolicyChangeResponseTest.java | 73 + .../org/openecomp/policy/test/PolicyClassTest.java | 91 + .../policy/test/PolicyConfigExceptionTest.java | 183 + .../policy/test/PolicyConfigStatusTest.java | 133 + .../openecomp/policy/test/PolicyConfigTest.java | 80 + .../policy/test/PolicyConfigTypeTest.java | 91 + .../policy/test/PolicyDecisionExceptionTest.java | 183 + .../openecomp/policy/test/PolicyDecisionTest.java | 91 + .../policy/test/PolicyEngineExceptionTest.java | 183 + .../policy/test/PolicyEngineInterfaceTest.java | 672 + .../openecomp/policy/test/PolicyEngineTest.java | 172 + .../policy/test/PolicyEventExceptionTest.java | 183 + .../policy/test/PolicyParametersTest.java | 1406 + .../policy/test/PolicyResponseStatusTest.java | 154 + .../openecomp/policy/test/PolicyResponseTest.java | 75 + .../org/openecomp/policy/test/PolicyTypeTest.java | 91 + .../policy/test/PushPolicyParametersTest.java | 269 + .../openecomp/policy/test/RemovedPolicyTest.java | 73 + .../org/openecomp/policy/test/SendEventTest.java | 153 + .../java/org/openecomp/policy/test/TestRunner.java | 49 + .../org/openecomp/policy/test/UpdateTypeTest.java | 91 + .../org/openecomp/policy/test/package-info.java | 24 + PolicyEngineClient/.gitignore | 1 + PolicyEngineClient/config.properties | 53 + PolicyEngineClient/config.test.properties | 24 + PolicyEngineClient/input.testCases | 419 + PolicyEngineClient/policyLogger.properties | 44 + PolicyEngineClient/pom.xml | 62 + .../openecomp/policyEngine/ActionPolicyClient.java | 117 + .../policyEngine/BrmsParamPolicyClient.java | 107 + .../policyEngine/BrmsRawPolicyClient.java | 144 + .../policyEngine/ClosedLoopPolicyClient.java | 119 + .../ClosedLoopPolicyPerformanceMetricClient.java | 121 + .../policyEngine/ConfigBasePolicyClient.java | 92 + .../policyEngine/ConfigFirewallPolicyClient.java | 117 + .../policyEngine/DecisionPolicyClient.java | 116 + .../openecomp/policyEngine/DeletePolicyClient.java | 62 + .../openecomp/policyEngine/GeneralTestClient.java | 398 + .../openecomp/policyEngine/GetConfigSample.java | 41 + .../java/org/openecomp/policyEngine/Handler.java | 121 + .../policyEngine/ImportMicroServiceClient.java | 56 + .../policyEngine/ListConfigPoliciesClient.java | 83 + .../org/openecomp/policyEngine/MainClient.java | 162 + .../policyEngine/MicroServicesPolicyClient.java | 121 + .../policyEngine/PolicyEngineTestClient.java | 201 + .../openecomp/policyEngine/PushPoliciesToPDP.java | 59 + PolicyEngineUtils/policyLogger.properties | 44 + PolicyEngineUtils/pom.xml | 85 + .../org/openecomp/policy/api/LoadedPolicy.java | 57 + .../openecomp/policy/api/NotificationHandler.java | 34 + .../org/openecomp/policy/api/NotificationType.java | 58 + .../org/openecomp/policy/api/PDPNotification.java | 52 + .../org/openecomp/policy/api/RemovedPolicy.java | 41 + .../java/org/openecomp/policy/api/UpdateType.java | 54 + .../openecomp/policy/jpa/BackUpMonitorEntity.java | 117 + .../openecomp/policy/std/NotificationStore.java | 264 + .../org/openecomp/policy/std/StdLoadedPolicy.java | 72 + .../openecomp/policy/std/StdPDPNotification.java | 80 + .../org/openecomp/policy/std/StdRemovedPolicy.java | 49 + .../openecomp/policy/utils/AAFPolicyClient.java | 208 + .../openecomp/policy/utils/AAFPolicyException.java | 48 + .../org/openecomp/policy/utils/BackUpHandler.java | 41 + .../org/openecomp/policy/utils/BackUpMonitor.java | 378 + .../org/openecomp/policy/utils/PolicyAccess.java | 107 + .../org/openecomp/policy/utils/PolicyUtils.java | 59 + .../src/main/resources/META-INF/persistencePU.xml | 29 + .../java/org/openecomp/policy/test/Handler.java | 38 + .../org/openecomp/policy/test/PolicyUtilsTest.java | 69 + .../openecomp/policy/test/testBackUpMonitor.java | 121 + PyPDPServer/client.properties | 22 + PyPDPServer/config.properties | 49 + PyPDPServer/policyLogger.properties | 44 + PyPDPServer/pom.xml | 257 + .../policy/pypdp/ConfigFirewallPolicyRequest.java | 128 + .../org/openecomp/policy/pypdp/ConfigRequest.java | 182 + .../policy/pypdp/DeletePolicyRequest.java | 80 + .../org/openecomp/policy/pypdp/EventRequest.java | 83 + .../openecomp/policy/pypdp/ListConfigRequest.java | 69 + .../policy/pypdp/PolicyCreateUpdateRequest.java | 124 + .../openecomp/policy/pypdp/PushPolicyRequest.java | 90 + .../pypdp/authorization/AuthenticationFilter.java | 80 + .../pypdp/authorization/AuthenticationService.java | 232 + .../policy/pypdp/authorization/Config.java | 300 + .../policy/pypdp/controller/Application.java | 80 + .../pypdp/controller/PolicyEngineServices.java | 556 + .../policy/pypdp/jmx/PyPdpMBeanListener.java | 75 + .../openecomp/policy/pypdp/jmx/PyPdpMonitor.java | 90 + .../policy/pypdp/jmx/PyPdpMonitorMBean.java | 28 + .../model_pojo/PepConfigFirewallPolicyRequest.java | 82 + .../model_pojo/PepConfigPolicyNameRequest.java | 39 + .../pypdp/model_pojo/PepConfigPolicyRequest.java | 187 + .../pypdp/model_pojo/PepPushPolicyRequest.java | 66 + .../policy/pypdp/model_pojo/PyPolicyConfig.java | 95 + .../policy/pypdp/notifications/Notification.java | 50 + .../notifications/NotificationController.java | 149 + .../pypdp/notifications/NotificationServer.java | 90 + PyPDPServer/src/main/resources/log4j.properties | 56 + PyPDPServer/src/main/resources/logback.xml | 252 + .../src/test/java/testpypdp/AuthorizationTest.java | 382 + .../src/test/java/testpypdp/ConfigRequestTest.java | 82 + .../java/testpypdp/NotificationControllerTest.java | 129 + .../java/testpypdp/PolicyEngineServicesTest.java | 969 + README.md | 9 + ...clipse.wst.jsdt.core.javascriptValidator.launch | 7 + ecomp-sdk-app/.gitignore | 2 + ecomp-sdk-app/README.md | 20 + .../EcompSdkDDLMySql_1610_Complete_OS.sql | 1421 + .../EcompSdkDMLMySql_1610_Complete_OS.sql | 2928 + ecomp-sdk-app/policyLogger.properties | 44 + ecomp-sdk-app/pom.xml | 324 + .../openecomp/policy/adapter/AddressGroupJson.java | 79 + .../org/openecomp/policy/adapter/AddressJson.java | 44 + .../openecomp/policy/adapter/AddressMembers.java | 46 + .../policy/adapter/AutoPushTabAdapter.java | 42 + .../policy/adapter/ClosedLoopFaultBody.java | 280 + .../ClosedLoopFaultTriggerUISignatures.java | 44 + .../openecomp/policy/adapter/ClosedLoopPMBody.java | 133 + .../adapter/ClosedLoopPerformanceMetrics.java | 36 + .../openecomp/policy/adapter/ClosedLoopPolicy.java | 61 + .../policy/adapter/ClosedLoopPolicyConditions.java | 39 + .../policy/adapter/ClosedLoopPolicyStatus.java | 41 + .../policy/adapter/ClosedLoopSignatures.java | 52 + .../policy/adapter/DeletePolicyCondition.java | 38 + .../openecomp/policy/adapter/DeployNowJson.java | 36 + .../org/openecomp/policy/adapter/GridData.java | 54 + .../openecomp/policy/adapter/PolicyAdapter.java | 619 + .../policy/adapter/PolicyExportAdapter.java | 36 + .../org/openecomp/policy/adapter/PrefixIPList.java | 74 + .../openecomp/policy/adapter/ServiceGroupJson.java | 79 + .../openecomp/policy/adapter/ServiceListJson.java | 107 + .../openecomp/policy/adapter/ServiceMembers.java | 48 + .../org/openecomp/policy/adapter/ServicesJson.java | 44 + .../java/org/openecomp/policy/adapter/Term.java | 201 + .../openecomp/policy/adapter/TermCollector.java | 132 + .../java/org/openecomp/policy/admin/CheckPDP.java | 187 + .../policy/admin/PAPNotificationBroadcaster.java | 120 + .../policy/admin/PolicyManagerServlet.java | 1334 + .../policy/admin/PolicyNotificationMail.java | 140 + .../openecomp/policy/admin/RESTfulPAPEngine.java | 732 + .../org/openecomp/policy/admin/XacmlAdminUI.java | 266 + .../policy/components/ElasticSearchComponent.java | 426 + .../policy/components/HumanPolicyComponent.java | 982 + .../policy/components/PolicyImportWindow.java | 226 + .../openecomp/policy/conf/HibernateSession.java | 60 + .../policy/controller/ActionPolicyController.java | 535 + .../policy/controller/AdminTabController.java | 100 + .../policy/controller/AutoPushController.java | 433 + .../controller/CreateBRMSParamController.java | 723 + .../policy/controller/CreateBRMSRawController.java | 440 + .../CreateClosedLoopFaultController.java | 889 + .../controller/CreateClosedLoopPMController.java | 422 + .../CreateDcaeMicroServiceController.java | 987 + .../controller/CreateFirewallController.java | 1292 + .../policy/controller/CreatePolicyController.java | 484 + .../policy/controller/DashboardController.java | 430 + .../controller/DecisionPolicyController.java | 507 + .../openecomp/policy/controller/PDPController.java | 302 + .../policy/controller/PolicyController.java | 418 + .../PolicyExportAndImportController.java | 563 + .../controller/PolicyNotificationController.java | 122 + .../policy/controller/PolicyRolesController.java | 137 + .../controller/PolicyValidationController.java | 300 + .../policy/dao/FunctionDefinitionDao.java | 32 + .../policy/dao/GlobalRoleSettingsDao.java | 33 + .../org/openecomp/policy/dao/GroupEntityDao.java | 39 + .../org/openecomp/policy/dao/PDPEntityDao.java | 33 + .../policy/dao/PolicyEditorScopesDao.java | 37 + .../org/openecomp/policy/dao/PolicyRolesDao.java | 37 + .../org/openecomp/policy/dao/PolicyVersionDao.java | 38 + .../policy/dao/RemoteCatalogValuesDao.java | 34 + .../java/org/openecomp/policy/dao/RolesDao.java | 38 + .../openecomp/policy/dao/RuleAlgorithmsDao.java | 31 + .../org/openecomp/policy/dao/SystemLogDbDao.java | 33 + .../policy/dao/WatchPolicyNotificationDao.java | 35 + .../policy/daoImp/ActionPolicyDictDaoImpl.java | 178 + .../policy/daoImp/AddressGroupDaoImpl.java | 152 + .../policy/daoImp/BRMSParamTemplateDaoImpl.java | 152 + .../policy/daoImp/DescriptiveScopeDaoImpl.java | 177 + .../daoImp/FirewallDictionaryListDaoImpl.java | 196 + .../policy/daoImp/FunctionDefinitionDaoImpl.java | 94 + .../policy/daoImp/GlobalRoleSettingsDaoImpl.java | 91 + .../policy/daoImp/GroupEntityDaoImpl.java | 124 + .../policy/daoImp/GroupPolicyScopeListDaoImpl.java | 177 + .../policy/daoImp/MicroServiceModelsDaoImpl.java | 156 + .../openecomp/policy/daoImp/PDPEntityDaoImpl.java | 68 + .../policy/daoImp/PolicyEditorScopesDaoImpl.java | 193 + .../policy/daoImp/PolicyRolesDaoImpl.java | 159 + .../policy/daoImp/PolicyVersionDaoImpl.java | 216 + .../openecomp/policy/daoImp/PrefixListDaoImpl.java | 153 + .../policy/daoImp/RemoteCatalogValuesDaoImpl.java | 150 + .../org/openecomp/policy/daoImp/RolesDaoImpl.java | 109 + .../policy/daoImp/RuleAlgorithmsDaoImpl.java | 68 + .../policy/daoImp/SafePolicyWarningDaoImpl.java | 181 + .../policy/daoImp/SecurityZoneDaoImpl.java | 152 + .../policy/daoImp/ServiceGroupDaoImpl.java | 153 + .../policy/daoImp/ServiceListDaoImpl.java | 154 + .../policy/daoImp/SystemLogDbDaoImpl.java | 93 + .../openecomp/policy/daoImp/TermListDaoImpl.java | 176 + .../openecomp/policy/daoImp/UserInfoDaoImpl.java | 123 + .../policy/daoImp/VarbindDictionaryDaoImpl.java | 177 + .../daoImp/WatchPolicyNotificationDaoImpl.java | 173 + .../openecomp/policy/elk/client/ElkConnector.java | 1235 + .../java/org/openecomp/policy/elk/client/Pair.java | 35 + .../elk/client/PolicyElasticSearchController.java | 756 + .../openecomp/policy/elk/client/PolicyLocator.java | 53 + .../openecomp/policy/elk/converter/ElkRecord.java | 42 + .../openecomp/policy/elk/converter/Xacml2Elk.java | 978 + .../openecomp/policy/model/PDPGroupContainer.java | 531 + .../openecomp/policy/model/PDPPolicyContainer.java | 348 + .../java/org/openecomp/policy/model/Roles.java | 95 + .../policy/utils/ConfigurableRESTUtils.java | 163 + .../openecomp/policy/utils/PolicyContainer.java | 121 + .../policy/utils/PolicyItemSetChangeNotifier.java | 95 + .../utils/XACMLPolicyWriterWithPapNotify.java | 494 + .../portalapp/conf/ExternalAppConfig.java | 188 + .../portalapp/conf/ExternalAppInitializer.java | 60 + .../portalapp/conf/HibernateMappingLocations.java | 37 + .../controller/AngularSinglePageController.java | 48 + .../portalapp/controller/CallflowController.java | 44 + .../controller/ElasticSearchController.java | 128 + .../portalapp/controller/LeafletMapContoller.java | 43 + .../portalapp/controller/PostDroolsController.java | 138 + .../controller/UserProfileController.java | 72 + .../portalapp/controller/WelcomeController.java | 43 + .../java/org/openecomp/portalapp/model/Result.java | 37 + .../org/openecomp/portalapp/scheduler/LogJob.java | 47 + .../openecomp/portalapp/scheduler/LogRegistry.java | 57 + .../openecomp/portalapp/scheduler/Register.java | 82 + .../portalapp/scheduler/RegistryAdapter.java | 108 + .../portalapp/service/AdminAuthExtension.java | 84 + .../service/OnBoardingApiServiceImplPolicy.java | 348 + .../portalapp/uebhandler/InitUebHandler.java | 73 + .../portalapp/uebhandler/MainUebHandler.java | 104 + .../uebhandler/WidgetNotificationHandler.java | 46 + .../portalapp/util/CustomLoggingFilter.java | 54 + ecomp-sdk-app/src/main/resources/att-rules.drl | 16 + ecomp-sdk-app/src/main/resources/cache.ccf | 30 + ecomp-sdk-app/src/main/resources/logback.xml | 370 + .../src/main/resources/mchange-log.properties | 23 + ecomp-sdk-app/src/main/resources/portal.properties | 69 + ecomp-sdk-app/src/main/resources/state-rules.drl | 38 + .../src/main/webapp/WEB-INF/conf/quartz.properties | 30 + .../src/main/webapp/WEB-INF/conf/raptor.properties | 187 + .../WEB-INF/conf/raptor_app_fusion.properties | 39 + .../WEB-INF/conf/raptor_db_fusion.properties | 19 + .../main/webapp/WEB-INF/conf/raptor_pdf.properties | 49 + .../src/main/webapp/WEB-INF/conf/sql.properties | 322 + .../src/main/webapp/WEB-INF/conf/system.properties | 105 + .../src/main/webapp/WEB-INF/defs/definitions.xml | 22 + .../webapp/WEB-INF/fusion/conf/fusion.properties | 61 + .../webapp/WEB-INF/fusion/defs/definitions.xml | 240 + .../src/main/webapp/WEB-INF/fusion/jsp/.gitignore | 0 .../main/webapp/WEB-INF/fusion/jsp/broadcast.jsp | 137 + .../webapp/WEB-INF/fusion/jsp/broadcast_list.jsp | 201 + .../webapp/WEB-INF/fusion/jsp/collaborateList.jsp | 146 + .../main/webapp/WEB-INF/fusion/jsp/data_out.jsp | 20 + .../webapp/WEB-INF/fusion/jsp/ebz/ebz_footer.jsp | 46 + .../webapp/WEB-INF/fusion/jsp/ebz/ebz_header.jsp | 799 + .../WEB-INF/fusion/jsp/ebz/loginSnippet.html | 120 + .../webapp/WEB-INF/fusion/jsp/ebz_template.jsp | 45 + .../fusion/jsp/ebz_template_noheader_nofooter.jsp | 35 + .../fusion/jsp/ebz_template_report_embedded.jsp | 48 + .../webapp/WEB-INF/fusion/jsp/es_search_demo.jsp | 97 + .../webapp/WEB-INF/fusion/jsp/es_suggest_demo.jsp | 97 + .../webapp/WEB-INF/fusion/jsp/frame_insert.jsp | 44 + .../src/main/webapp/WEB-INF/fusion/jsp/include.jsp | 30 + .../main/webapp/WEB-INF/fusion/jsp/jcs_admin.jsp | 144 + .../src/main/webapp/WEB-INF/fusion/jsp/meta.jsp | 36 + .../webapp/WEB-INF/fusion/jsp/popup_modal.html | 324 + .../WEB-INF/fusion/jsp/popup_modal_role.html | 274 + .../fusion/jsp/popup_modal_rolefunction.html | 87 + .../main/webapp/WEB-INF/fusion/jsp/post_search.jsp | 356 + .../src/main/webapp/WEB-INF/fusion/jsp/profile.jsp | 442 + .../webapp/WEB-INF/fusion/jsp/profile_search.jsp | 104 + .../src/main/webapp/WEB-INF/fusion/jsp/role.jsp | 286 + .../WEB-INF/fusion/jsp/role_function_list.jsp | 213 + .../main/webapp/WEB-INF/fusion/jsp/role_list.jsp | 139 + .../main/webapp/WEB-INF/fusion/jsp/usage_list.jsp | 87 + .../WEB-INF/fusion/jsp/webrtc/collaboration.jsp | 492 + .../main/webapp/WEB-INF/fusion/orm/Fusion.hbm.xml | 352 + .../fusion/orm/RNoteBookIntegration.hbm.xml | 44 + .../webapp/WEB-INF/fusion/orm/Workflow.hbm.xml | 48 + .../fusion/raptor/custom_header_include.jsp | 135 + .../WEB-INF/fusion/raptor/custom_js_include.jsp | 31 + .../fusion/raptor/date_end_field_run_sql.jsp | 38 + .../fusion/raptor/date_start_field_run_sql.jsp | 39 + .../fusion/raptor/default_field_run_sql.jsp | 39 + .../webapp/WEB-INF/fusion/raptor/disclaimer.jsp | 38 + .../webapp/WEB-INF/fusion/raptor/error_include.jsp | 58 + .../webapp/WEB-INF/fusion/raptor/error_page.jsp | 229 + .../main/webapp/WEB-INF/fusion/raptor/footer.jsp | 25 + .../fusion/raptor/popup_drill_down_report.jsp | 601 + .../fusion/raptor/popup_import_semaphore.jsp | 80 + .../WEB-INF/fusion/raptor/popup_semaphore.jsp | 419 + .../webapp/WEB-INF/fusion/raptor/popup_sql.jsp | 55 + .../WEB-INF/fusion/raptor/popup_table_cols.jsp | 171 + .../WEB-INF/fusion/raptor/popup_testrun_sql.jsp | 103 + .../WEB-INF/fusion/raptor/report_download_csv.jsp | 89 + .../WEB-INF/fusion/raptor/report_download_pdf.jsp | 40 + .../WEB-INF/fusion/raptor/report_download_xls.jsp | 64 + .../webapp/WEB-INF/fusion/raptor/report_ebz.jsp | 179 + .../webapp/WEB-INF/fusion/raptor/report_import.jsp | 69 + .../webapp/WEB-INF/fusion/raptor/report_sample.jsp | 40 + .../webapp/WEB-INF/fusion/raptor/report_search.jsp | 2432 + .../webapp/WEB-INF/fusion/raptor/report_wizard.jsp | 309 + .../WEB-INF/fusion/raptor/test_field_run_sql.jsp | 39 + .../webapp/WEB-INF/fusion/raptor/test_run_sql.jsp | 38 + .../WEB-INF/fusion/raptor/tree/folderNav.jsp | 483 + .../webapp/WEB-INF/fusion/raptor/tree/testTree.jsp | 248 + .../fusion/raptor/wizard_adhoc_schedule.jsp | 733 + .../webapp/WEB-INF/fusion/raptor/wizard_chart.jsp | 1335 + .../fusion/raptor/wizard_columns_add_multi.jsp | 96 + .../WEB-INF/fusion/raptor/wizard_columns_edit.jsp | 1127 + .../WEB-INF/fusion/raptor/wizard_columns_list.jsp | 157 + .../fusion/raptor/wizard_columns_order_all.jsp | 88 + .../fusion/raptor/wizard_data_forecasting.jsp | 184 + .../WEB-INF/fusion/raptor/wizard_definition.jsp | 1122 + .../WEB-INF/fusion/raptor/wizard_filters_edit.jsp | 320 + .../WEB-INF/fusion/raptor/wizard_filters_list.jsp | 115 + .../fusion/raptor/wizard_form_fields_edit.jsp | 771 + .../fusion/raptor/wizard_form_fields_list.jsp | 107 + .../WEB-INF/fusion/raptor/wizard_javascript.jsp | 167 + .../webapp/WEB-INF/fusion/raptor/wizard_log.jsp | 109 + .../webapp/WEB-INF/fusion/raptor/wizard_map.jsp | 424 + .../webapp/WEB-INF/fusion/raptor/wizard_run.jsp | 74 + .../WEB-INF/fusion/raptor/wizard_schedule.jsp | 376 + .../raptor/wizard_schedule_formfield_include.jsp | 754 + .../fusion/raptor/wizard_schedule_multiple.jsp | 157 + .../WEB-INF/fusion/raptor/wizard_schedule_only.jsp | 172 + .../raptor/wizard_schedule_only_from_search.jsp | 173 + .../WEB-INF/fusion/raptor/wizard_sorting_edit.jsp | 86 + .../WEB-INF/fusion/raptor/wizard_sorting_list.jsp | 116 + .../fusion/raptor/wizard_sorting_order_all.jsp | 112 + .../WEB-INF/fusion/raptor/wizard_sql_def.jsp | 226 + .../WEB-INF/fusion/raptor/wizard_tables_edit.jsp | 369 + .../WEB-INF/fusion/raptor/wizard_tables_list.jsp | 85 + .../WEB-INF/fusion/raptor/wizard_user_access.jsp | 184 + .../src/main/webapp/WEB-INF/jsp/error.jsp | 20 + .../src/main/webapp/WEB-INF/jsp/leafletMap.jsp | 288 + .../src/main/webapp/WEB-INF/jsp/login_external.jsp | 154 + .../src/main/webapp/WEB-INF/jsp/net_map.jsp | 38 + .../src/main/webapp/WEB-INF/jsp/user_profile.jsp | 84 + .../src/main/webapp/WEB-INF/jsp/welcome.jsp | 629 + ecomp-sdk-app/src/main/webapp/WEB-INF/web.xml | 24 + .../fusion/external/angular-1.5/angular-animate.js | 4121 ++ .../external/angular-1.5/angular-animate.min.js | 56 + .../angular-1.5/angular-animate.min.js.map | 8 + .../fusion/external/angular-1.5/angular-aria.js | 398 + .../external/angular-1.5/angular-aria.min.js | 14 + .../external/angular-1.5/angular-aria.min.js.map | 8 + .../fusion/external/angular-1.5/angular-cookies.js | 322 + .../external/angular-1.5/angular-cookies.min.js | 9 + .../angular-1.5/angular-cookies.min.js.map | 8 + .../fusion/external/angular-1.5/angular-csp.css | 20 + .../fusion/external/angular-1.5/angular-loader.js | 484 + .../external/angular-1.5/angular-loader.min.js | 10 + .../external/angular-1.5/angular-loader.min.js.map | 8 + .../external/angular-1.5/angular-message-format.js | 980 + .../angular-1.5/angular-message-format.min.js | 26 + .../angular-1.5/angular-message-format.min.js.map | 8 + .../external/angular-1.5/angular-messages.js | 687 + .../external/angular-1.5/angular-messages.min.js | 12 + .../angular-1.5/angular-messages.min.js.map | 8 + .../fusion/external/angular-1.5/angular-mocks.js | 2842 + .../external/angular-1.5/angular-resource.js | 768 + .../external/angular-1.5/angular-resource.min.js | 15 + .../angular-1.5/angular-resource.min.js.map | 8 + .../fusion/external/angular-1.5/angular-route.js | 1016 + .../external/angular-1.5/angular-route.min.js | 15 + .../external/angular-1.5/angular-route.min.js.map | 8 + .../external/angular-1.5/angular-sanitize.js | 717 + .../external/angular-1.5/angular-sanitize.min.js | 15 + .../angular-1.5/angular-sanitize.min.js.map | 8 + .../external/angular-1.5/angular-scenario.js | 41849 ++++++++++++ .../fusion/external/angular-1.5/angular-touch.js | 729 + .../external/angular-1.5/angular-touch.min.js | 14 + .../external/angular-1.5/angular-touch.min.js.map | 8 + .../app/fusion/external/angular-1.5/angular.js | 30428 +++++++++ .../app/fusion/external/angular-1.5/angular.min.js | 307 + .../fusion/external/angular-1.5/angular.min.js.map | 8 + .../app/fusion/external/angular-1.5/errors.json | 1 + .../app/fusion/external/angular-1.5/version.json | 1 + .../app/fusion/external/angular-1.5/version.txt | 1 + .../angular-ui/ui-bootstrap-tpls-1.1.2.min.js | 10 + .../angular-ui/ui-bootstrap-tpls-1.2.4.min.js | 10 + .../webapp/app/fusion/external/bootstrap/bs.css | 678 + .../webapp/app/fusion/external/d3/css/nv.d3.css | 656 + .../main/webapp/app/fusion/external/d3/js/cie.js | 155 + .../app/fusion/external/d3/js/colorbrewer.js | 302 + .../main/webapp/app/fusion/external/d3/js/core.js | 122 + .../app/fusion/external/d3/js/crossfilter.js | 1180 + .../app/fusion/external/d3/js/crossfilter.min.js | 1 + .../webapp/app/fusion/external/d3/js/d3.geom.js | 816 + .../main/webapp/app/fusion/external/d3/js/d3.js | 5 + .../app/fusion/external/d3/js/d3.layout.cloud.js | 433 + .../webapp/app/fusion/external/d3/js/d3.layout.js | 908 + .../main/webapp/app/fusion/external/d3/js/d3.v2.js | 7037 ++ .../webapp/app/fusion/external/d3/js/d3.v2.min.js | 4 + .../webapp/app/fusion/external/d3/js/d3.v3.min.js | 1 + .../webapp/app/fusion/external/d3/js/fisheye.js | 86 + .../main/webapp/app/fusion/external/d3/js/hive.js | 80 + .../webapp/app/fusion/external/d3/js/horizon.js | 192 + .../app/fusion/external/d3/js/interactiveLayer.js | 251 + .../main/webapp/app/fusion/external/d3/js/intro.js | 1 + .../app/fusion/external/d3/js/models/axis-min.js | 1 + .../app/fusion/external/d3/js/models/axis.js | 470 + .../app/fusion/external/d3/js/models/axis.min.js | 1 + .../fusion/external/d3/js/models/backup/bullet.js | 250 + .../external/d3/js/models/backup/bulletChart.js | 349 + .../fusion/external/d3/js/models/boilerplate.js | 104 + .../app/fusion/external/d3/js/models/bullet.js | 385 + .../fusion/external/d3/js/models/bulletChart.js | 343 + .../external/d3/js/models/cumulativeLineChart.js | 782 + .../fusion/external/d3/js/models/discreteBar.js | 349 + .../external/d3/js/models/discreteBarChart.js | 333 + .../fusion/external/d3/js/models/distribution.js | 148 + .../fusion/external/d3/js/models/historicalBar.js | 331 + .../external/d3/js/models/historicalBarChart.js | 419 + .../fusion/external/d3/js/models/indentedTree.js | 337 + .../app/fusion/external/d3/js/models/legend.js | 270 + .../app/fusion/external/d3/js/models/line.js | 284 + .../app/fusion/external/d3/js/models/lineChart.js | 465 + .../external/d3/js/models/linePlusBarChart.js | 433 + .../d3/js/models/linePlusBarWithFocusChart.js | 658 + .../external/d3/js/models/lineWithFisheye.js | 200 + .../external/d3/js/models/lineWithFisheyeChart.js | 297 + .../external/d3/js/models/lineWithFocusChart.js | 574 + .../app/fusion/external/d3/js/models/multiBar.js | 461 + .../fusion/external/d3/js/models/multiBarChart.js | 524 + .../external/d3/js/models/multiBarHorizontal.js | 424 + .../d3/js/models/multiBarHorizontalChart.js | 434 + .../external/d3/js/models/multiBarTimeSeries.js | 384 + .../d3/js/models/multiBarTimeSeriesChart.js | 405 + .../app/fusion/external/d3/js/models/multiChart.js | 452 + .../app/fusion/external/d3/js/models/ohlcBar.js | 380 + .../external/d3/js/models/parallelCoordinates.js | 239 + .../webapp/app/fusion/external/d3/js/models/pie.js | 400 + .../app/fusion/external/d3/js/models/pieChart.js | 292 + .../app/fusion/external/d3/js/models/scatter.js | 674 + .../fusion/external/d3/js/models/scatterChart.js | 628 + .../external/d3/js/models/scatterPlusLineChart.js | 620 + .../app/fusion/external/d3/js/models/sparkline.js | 194 + .../fusion/external/d3/js/models/sparklinePlus.js | 295 + .../fusion/external/d3/js/models/stackedArea.js | 368 + .../external/d3/js/models/stackedAreaChart.js | 629 + .../main/webapp/app/fusion/external/d3/js/nv.d3.js | 13097 ++++ .../webapp/app/fusion/external/d3/js/nv.d3.min.js | 1 + .../main/webapp/app/fusion/external/d3/js/outro.js | 1 + .../webapp/app/fusion/external/d3/js/sankey.js | 292 + .../webapp/app/fusion/external/d3/js/tooltip.js | 490 + .../main/webapp/app/fusion/external/d3/js/utils.js | 152 + .../external/ebz/angular_js/angular-animate.js | 3721 + .../external/ebz/angular_js/angular-cookies.js | 206 + .../external/ebz/angular_js/angular-route.js | 911 + .../external/ebz/angular_js/angular-route.min.js | 14 + .../external/ebz/angular_js/angular-sanitize.js | 647 + .../external/ebz/angular_js/angular-touch.js | 628 + .../app/fusion/external/ebz/angular_js/angular.js | 22024 ++++++ .../app/fusion/external/ebz/angular_js/app.js | 6 + .../external/ebz/angular_js/checklist-model.js | 99 + .../external/ebz/angular_js/checklist-model.min.js | 1 + .../app/fusion/external/ebz/angular_js/gestures.js | 1495 + .../app/fusion/external/ebz/angular_js/ng_base.js | 4 + .../external/ebz/angular_js/ui-charts-tpls.js | 3909 ++ .../app/fusion/external/ebz/ebz_header/footer.css | 311 + .../app/fusion/external/ebz/ebz_header/header.css | 1866 + .../external/ebz/ebz_header/portal_ebz_header.css | 63 + .../main/webapp/app/fusion/external/ebz/fn-ebz.css | 1614 + .../fusion/external/ebz/images/headerChatIcon.png | Bin 0 -> 465 bytes .../external/ebz/images/no_favorites_star.png | Bin 0 -> 2794 bytes .../app/fusion/external/ebz/js/attHeaderSnippet.js | 210 + .../webapp/app/fusion/external/ebz/js/footer.js | 110 + .../fusion/external/ebz/sandbox/att-abs-tpls.js | 20451 ++++++ .../external/ebz/sandbox/att-abs-tpls.min.js | 22 + .../fusion/external/ebz/sandbox/styles/base.css | 6198 ++ .../app/fusion/external/ebz/sandbox/styles/btn.css | 1 + .../fusion/external/ebz/sandbox/styles/demo.css | 2 + .../fusion/external/ebz/sandbox/styles/dtpk.css | 9 + .../fusion/external/ebz/sandbox/styles/frms.css | 1 + .../ebz/sandbox/styles/ie/backgroundsize.min.htc | 12 + .../ebz/sandbox/styles/images/calendar-icon.png | Bin 0 -> 515635 bytes .../ebz/sandbox/styles/images/checkbox.png | Bin 0 -> 1170 bytes .../external/ebz/sandbox/styles/images/down.png | Bin 0 -> 1059 bytes .../ebz/sandbox/styles/images/icon-close-modal.png | Bin 0 -> 1634 bytes .../styles/images/icon-informative-modal.png | Bin 0 -> 5018 bytes .../sandbox/styles/images/icon-warning-modal.png | Bin 0 -> 3831 bytes .../external/ebz/sandbox/styles/images/loader.gif | Bin 0 -> 5732 bytes .../styles/images/loading-spinner-medium.png | Bin 0 -> 2021 bytes .../styles/images/loading-spinner-orange.png | Bin 0 -> 2087 bytes .../styles/images/loading_balls_black-small.gif | Bin 0 -> 3209 bytes .../sandbox/styles/images/loading_balls_black.gif | Bin 0 -> 2636 bytes .../styles/images/loading_balls_blue-small.gif | Bin 0 -> 3210 bytes .../sandbox/styles/images/loading_balls_blue.gif | Bin 0 -> 2636 bytes .../styles/images/loading_balls_white-small.gif | Bin 0 -> 2060 bytes .../sandbox/styles/images/loading_balls_white.gif | Bin 0 -> 1924 bytes .../ebz/sandbox/styles/images/loading_dots.gif | Bin 0 -> 3736 bytes .../ebz/sandbox/styles/images/magnify_glass.png | Bin 0 -> 556 bytes .../ebz/sandbox/styles/images/oops-exclamation.png | Bin 0 -> 836 bytes .../external/ebz/sandbox/styles/images/radio.jpg | Bin 0 -> 1352 bytes .../ebz/sandbox/styles/images/select-arrows.png | Bin 0 -> 1373 bytes .../ebz/sandbox/styles/images/treearrow.png | Bin 0 -> 17821 bytes .../external/ebz/sandbox/styles/images/up.png | Bin 0 -> 1064 bytes .../ebz/sandbox/styles/images/upanddown.png | Bin 0 -> 1033 bytes .../ebz/sandbox/styles/pages/iconography.css | 2 + .../fusion/external/ebz/sandbox/styles/sldr.css | 1 + .../fusion/external/ebz/sandbox/styles/style.css | 1 + .../app/fusion/external/ebz/sandbox/styles/tbs.css | 1 + .../app/fusion/external/ionicons-2.0.1/.gitignore | 4 + .../app/fusion/external/ionicons-2.0.1/LICENSE | 21 + .../app/fusion/external/ionicons-2.0.1/bower.json | 31 + .../fusion/external/ionicons-2.0.1/component.json | 19 + .../fusion/external/ionicons-2.0.1/composer.json | 36 + .../external/ionicons-2.0.1/css/ionicons.css | 1480 + .../external/ionicons-2.0.1/css/ionicons.min.css | 11 + .../external/ionicons-2.0.1/fonts/ionicons.eot | Bin 0 -> 120724 bytes .../external/ionicons-2.0.1/fonts/ionicons.svg | 2230 + .../external/ionicons-2.0.1/fonts/ionicons.ttf | Bin 0 -> 188508 bytes .../external/ionicons-2.0.1/fonts/ionicons.woff | Bin 0 -> 67904 bytes .../ionicons-2.0.1/less/_ionicons-font.less | 27 + .../ionicons-2.0.1/less/_ionicons-icons.less | 1473 + .../ionicons-2.0.1/less/_ionicons-variables.less | 747 + .../external/ionicons-2.0.1/less/ionicons.less | 3 + .../ionicons-2.0.1/png/512/alert-circled.png | Bin 0 -> 2551 bytes .../external/ionicons-2.0.1/png/512/alert.png | Bin 0 -> 766 bytes .../ionicons-2.0.1/png/512/android-add-contact.png | Bin 0 -> 3279 bytes .../ionicons-2.0.1/png/512/android-add.png | Bin 0 -> 240 bytes .../ionicons-2.0.1/png/512/android-alarm.png | Bin 0 -> 6428 bytes .../ionicons-2.0.1/png/512/android-archive.png | Bin 0 -> 1628 bytes .../ionicons-2.0.1/png/512/android-arrow-back.png | Bin 0 -> 1218 bytes .../png/512/android-arrow-down-left.png | Bin 0 -> 1451 bytes .../png/512/android-arrow-down-right.png | Bin 0 -> 1462 bytes .../png/512/android-arrow-forward.png | Bin 0 -> 1191 bytes .../png/512/android-arrow-up-left.png | Bin 0 -> 1499 bytes .../png/512/android-arrow-up-right.png | Bin 0 -> 1482 bytes .../ionicons-2.0.1/png/512/android-battery.png | Bin 0 -> 238 bytes .../ionicons-2.0.1/png/512/android-book.png | Bin 0 -> 3746 bytes .../ionicons-2.0.1/png/512/android-calendar.png | Bin 0 -> 849 bytes .../ionicons-2.0.1/png/512/android-call.png | Bin 0 -> 4766 bytes .../ionicons-2.0.1/png/512/android-camera.png | Bin 0 -> 3871 bytes .../ionicons-2.0.1/png/512/android-chat.png | Bin 0 -> 3577 bytes .../ionicons-2.0.1/png/512/android-checkmark.png | Bin 0 -> 1846 bytes .../ionicons-2.0.1/png/512/android-clock.png | Bin 0 -> 5268 bytes .../ionicons-2.0.1/png/512/android-close.png | Bin 0 -> 2156 bytes .../ionicons-2.0.1/png/512/android-contact.png | Bin 0 -> 3658 bytes .../ionicons-2.0.1/png/512/android-contacts.png | Bin 0 -> 4299 bytes .../ionicons-2.0.1/png/512/android-data.png | Bin 0 -> 4808 bytes .../ionicons-2.0.1/png/512/android-developer.png | Bin 0 -> 4115 bytes .../ionicons-2.0.1/png/512/android-display.png | Bin 0 -> 4909 bytes .../ionicons-2.0.1/png/512/android-download.png | Bin 0 -> 4890 bytes .../ionicons-2.0.1/png/512/android-drawer.png | Bin 0 -> 190 bytes .../ionicons-2.0.1/png/512/android-dropdown.png | Bin 0 -> 777 bytes .../ionicons-2.0.1/png/512/android-earth.png | Bin 0 -> 6517 bytes .../ionicons-2.0.1/png/512/android-folder.png | Bin 0 -> 1688 bytes .../ionicons-2.0.1/png/512/android-forums.png | Bin 0 -> 1739 bytes .../ionicons-2.0.1/png/512/android-friends.png | Bin 0 -> 4868 bytes .../ionicons-2.0.1/png/512/android-hand.png | Bin 0 -> 4650 bytes .../ionicons-2.0.1/png/512/android-image.png | Bin 0 -> 1433 bytes .../ionicons-2.0.1/png/512/android-inbox.png | Bin 0 -> 3018 bytes .../ionicons-2.0.1/png/512/android-information.png | Bin 0 -> 3370 bytes .../ionicons-2.0.1/png/512/android-keypad.png | Bin 0 -> 1055 bytes .../ionicons-2.0.1/png/512/android-lightbulb.png | Bin 0 -> 3515 bytes .../ionicons-2.0.1/png/512/android-locate.png | Bin 0 -> 5003 bytes .../ionicons-2.0.1/png/512/android-location.png | Bin 0 -> 3067 bytes .../ionicons-2.0.1/png/512/android-mail.png | Bin 0 -> 3455 bytes .../ionicons-2.0.1/png/512/android-microphone.png | Bin 0 -> 3267 bytes .../ionicons-2.0.1/png/512/android-mixer.png | Bin 0 -> 2727 bytes .../ionicons-2.0.1/png/512/android-more.png | Bin 0 -> 224 bytes .../ionicons-2.0.1/png/512/android-note.png | Bin 0 -> 249 bytes .../ionicons-2.0.1/png/512/android-playstore.png | Bin 0 -> 3165 bytes .../ionicons-2.0.1/png/512/android-printer.png | Bin 0 -> 1721 bytes .../ionicons-2.0.1/png/512/android-promotion.png | Bin 0 -> 2374 bytes .../ionicons-2.0.1/png/512/android-reminder.png | Bin 0 -> 2890 bytes .../ionicons-2.0.1/png/512/android-remove.png | Bin 0 -> 160 bytes .../ionicons-2.0.1/png/512/android-search.png | Bin 0 -> 4232 bytes .../ionicons-2.0.1/png/512/android-send.png | Bin 0 -> 2079 bytes .../ionicons-2.0.1/png/512/android-settings.png | Bin 0 -> 3883 bytes .../ionicons-2.0.1/png/512/android-share.png | Bin 0 -> 3212 bytes .../ionicons-2.0.1/png/512/android-social-user.png | Bin 0 -> 3644 bytes .../ionicons-2.0.1/png/512/android-social.png | Bin 0 -> 3849 bytes .../ionicons-2.0.1/png/512/android-sort.png | Bin 0 -> 197 bytes .../png/512/android-stair-drawer.png | Bin 0 -> 209 bytes .../ionicons-2.0.1/png/512/android-star.png | Bin 0 -> 2926 bytes .../ionicons-2.0.1/png/512/android-stopwatch.png | Bin 0 -> 5225 bytes .../ionicons-2.0.1/png/512/android-storage.png | Bin 0 -> 233 bytes .../ionicons-2.0.1/png/512/android-system-back.png | Bin 0 -> 1796 bytes .../ionicons-2.0.1/png/512/android-system-home.png | Bin 0 -> 1107 bytes .../png/512/android-system-windows.png | Bin 0 -> 202 bytes .../ionicons-2.0.1/png/512/android-timer.png | Bin 0 -> 3904 bytes .../ionicons-2.0.1/png/512/android-trash.png | Bin 0 -> 2865 bytes .../ionicons-2.0.1/png/512/android-user-menu.png | Bin 0 -> 3568 bytes .../ionicons-2.0.1/png/512/android-volume.png | Bin 0 -> 6022 bytes .../ionicons-2.0.1/png/512/android-wifi.png | Bin 0 -> 4868 bytes .../external/ionicons-2.0.1/png/512/aperture.png | Bin 0 -> 9500 bytes .../external/ionicons-2.0.1/png/512/archive.png | Bin 0 -> 2445 bytes .../ionicons-2.0.1/png/512/arrow-down-a.png | Bin 0 -> 1173 bytes .../ionicons-2.0.1/png/512/arrow-down-b.png | Bin 0 -> 1307 bytes .../ionicons-2.0.1/png/512/arrow-down-c.png | Bin 0 -> 1966 bytes .../ionicons-2.0.1/png/512/arrow-expand.png | Bin 0 -> 2498 bytes .../png/512/arrow-graph-down-left.png | Bin 0 -> 2478 bytes .../png/512/arrow-graph-down-right.png | Bin 0 -> 2545 bytes .../ionicons-2.0.1/png/512/arrow-graph-up-left.png | Bin 0 -> 2440 bytes .../png/512/arrow-graph-up-right.png | Bin 0 -> 2440 bytes .../ionicons-2.0.1/png/512/arrow-left-a.png | Bin 0 -> 1260 bytes .../ionicons-2.0.1/png/512/arrow-left-b.png | Bin 0 -> 1608 bytes .../ionicons-2.0.1/png/512/arrow-left-c.png | Bin 0 -> 1662 bytes .../external/ionicons-2.0.1/png/512/arrow-move.png | Bin 0 -> 1948 bytes .../ionicons-2.0.1/png/512/arrow-resize.png | Bin 0 -> 1266 bytes .../ionicons-2.0.1/png/512/arrow-return-left.png | Bin 0 -> 1082 bytes .../ionicons-2.0.1/png/512/arrow-return-right.png | Bin 0 -> 1124 bytes .../ionicons-2.0.1/png/512/arrow-right-a.png | Bin 0 -> 1317 bytes .../ionicons-2.0.1/png/512/arrow-right-b.png | Bin 0 -> 1671 bytes .../ionicons-2.0.1/png/512/arrow-right-c.png | Bin 0 -> 1657 bytes .../ionicons-2.0.1/png/512/arrow-shrink.png | Bin 0 -> 2594 bytes .../external/ionicons-2.0.1/png/512/arrow-swap.png | Bin 0 -> 1521 bytes .../external/ionicons-2.0.1/png/512/arrow-up-a.png | Bin 0 -> 1115 bytes .../external/ionicons-2.0.1/png/512/arrow-up-b.png | Bin 0 -> 1343 bytes .../external/ionicons-2.0.1/png/512/arrow-up-c.png | Bin 0 -> 2002 bytes .../external/ionicons-2.0.1/png/512/asterisk.png | Bin 0 -> 4023 bytes .../fusion/external/ionicons-2.0.1/png/512/at.png | Bin 0 -> 5852 bytes .../fusion/external/ionicons-2.0.1/png/512/bag.png | Bin 0 -> 3665 bytes .../ionicons-2.0.1/png/512/battery-charging.png | Bin 0 -> 1897 bytes .../ionicons-2.0.1/png/512/battery-empty.png | Bin 0 -> 1019 bytes .../ionicons-2.0.1/png/512/battery-full.png | Bin 0 -> 982 bytes .../ionicons-2.0.1/png/512/battery-half.png | Bin 0 -> 1320 bytes .../ionicons-2.0.1/png/512/battery-low.png | Bin 0 -> 1342 bytes .../external/ionicons-2.0.1/png/512/beaker.png | Bin 0 -> 3931 bytes .../external/ionicons-2.0.1/png/512/beer.png | Bin 0 -> 4559 bytes .../external/ionicons-2.0.1/png/512/bluetooth.png | Bin 0 -> 2909 bytes .../external/ionicons-2.0.1/png/512/bonfire.png | Bin 0 -> 4852 bytes .../external/ionicons-2.0.1/png/512/bookmark.png | Bin 0 -> 1102 bytes .../external/ionicons-2.0.1/png/512/briefcase.png | Bin 0 -> 1475 bytes .../fusion/external/ionicons-2.0.1/png/512/bug.png | Bin 0 -> 4736 bytes .../external/ionicons-2.0.1/png/512/calculator.png | Bin 0 -> 1315 bytes .../external/ionicons-2.0.1/png/512/calendar.png | Bin 0 -> 2577 bytes .../external/ionicons-2.0.1/png/512/camera.png | Bin 0 -> 4190 bytes .../external/ionicons-2.0.1/png/512/card.png | Bin 0 -> 1494 bytes .../external/ionicons-2.0.1/png/512/cash.png | Bin 0 -> 3435 bytes .../ionicons-2.0.1/png/512/chatbox-working.png | Bin 0 -> 2301 bytes .../external/ionicons-2.0.1/png/512/chatbox.png | Bin 0 -> 1870 bytes .../external/ionicons-2.0.1/png/512/chatboxes.png | Bin 0 -> 2562 bytes .../ionicons-2.0.1/png/512/chatbubble-working.png | Bin 0 -> 3028 bytes .../external/ionicons-2.0.1/png/512/chatbubble.png | Bin 0 -> 2579 bytes .../ionicons-2.0.1/png/512/chatbubbles.png | Bin 0 -> 3751 bytes .../ionicons-2.0.1/png/512/checkmark-circled.png | Bin 0 -> 3687 bytes .../ionicons-2.0.1/png/512/checkmark-round.png | Bin 0 -> 2367 bytes .../external/ionicons-2.0.1/png/512/checkmark.png | Bin 0 -> 2134 bytes .../ionicons-2.0.1/png/512/chevron-down.png | Bin 0 -> 1689 bytes .../ionicons-2.0.1/png/512/chevron-left.png | Bin 0 -> 1769 bytes .../ionicons-2.0.1/png/512/chevron-right.png | Bin 0 -> 1831 bytes .../external/ionicons-2.0.1/png/512/chevron-up.png | Bin 0 -> 1677 bytes .../external/ionicons-2.0.1/png/512/clipboard.png | Bin 0 -> 2593 bytes .../external/ionicons-2.0.1/png/512/clock.png | Bin 0 -> 5866 bytes .../ionicons-2.0.1/png/512/close-circled.png | Bin 0 -> 3809 bytes .../ionicons-2.0.1/png/512/close-round.png | Bin 0 -> 2177 bytes .../external/ionicons-2.0.1/png/512/close.png | Bin 0 -> 2244 bytes .../ionicons-2.0.1/png/512/closed-captioning.png | Bin 0 -> 3665 bytes .../external/ionicons-2.0.1/png/512/cloud.png | Bin 0 -> 2067 bytes .../ionicons-2.0.1/png/512/code-download.png | Bin 0 -> 2423 bytes .../ionicons-2.0.1/png/512/code-working.png | Bin 0 -> 2433 bytes .../external/ionicons-2.0.1/png/512/code.png | Bin 0 -> 1720 bytes .../external/ionicons-2.0.1/png/512/coffee.png | Bin 0 -> 3205 bytes .../external/ionicons-2.0.1/png/512/compass.png | Bin 0 -> 7318 bytes .../external/ionicons-2.0.1/png/512/compose.png | Bin 0 -> 4296 bytes .../ionicons-2.0.1/png/512/connection-bars.png | Bin 0 -> 214 bytes .../external/ionicons-2.0.1/png/512/contrast.png | Bin 0 -> 4087 bytes .../external/ionicons-2.0.1/png/512/cube.png | Bin 0 -> 3265 bytes .../external/ionicons-2.0.1/png/512/disc.png | Bin 0 -> 4935 bytes .../ionicons-2.0.1/png/512/document-text.png | Bin 0 -> 1918 bytes .../external/ionicons-2.0.1/png/512/document.png | Bin 0 -> 1914 bytes .../external/ionicons-2.0.1/png/512/drag.png | Bin 0 -> 178 bytes .../external/ionicons-2.0.1/png/512/earth.png | Bin 0 -> 6476 bytes .../external/ionicons-2.0.1/png/512/edit.png | Bin 0 -> 2741 bytes .../fusion/external/ionicons-2.0.1/png/512/egg.png | Bin 0 -> 4234 bytes .../external/ionicons-2.0.1/png/512/eject.png | Bin 0 -> 3209 bytes .../external/ionicons-2.0.1/png/512/email.png | Bin 0 -> 3125 bytes .../ionicons-2.0.1/png/512/eye-disabled.png | Bin 0 -> 3558 bytes .../fusion/external/ionicons-2.0.1/png/512/eye.png | Bin 0 -> 3297 bytes .../external/ionicons-2.0.1/png/512/female.png | Bin 0 -> 2779 bytes .../external/ionicons-2.0.1/png/512/filing.png | Bin 0 -> 2349 bytes .../ionicons-2.0.1/png/512/film-marker.png | Bin 0 -> 2645 bytes .../external/ionicons-2.0.1/png/512/fireball.png | Bin 0 -> 3325 bytes .../external/ionicons-2.0.1/png/512/flag.png | Bin 0 -> 2337 bytes .../external/ionicons-2.0.1/png/512/flame.png | Bin 0 -> 3012 bytes .../external/ionicons-2.0.1/png/512/flash-off.png | Bin 0 -> 5437 bytes .../external/ionicons-2.0.1/png/512/flash.png | Bin 0 -> 1965 bytes .../external/ionicons-2.0.1/png/512/flask.png | Bin 0 -> 2939 bytes .../external/ionicons-2.0.1/png/512/folder.png | Bin 0 -> 1689 bytes .../external/ionicons-2.0.1/png/512/fork-repo.png | Bin 0 -> 3236 bytes .../external/ionicons-2.0.1/png/512/fork.png | Bin 0 -> 3007 bytes .../external/ionicons-2.0.1/png/512/forward.png | Bin 0 -> 2142 bytes .../external/ionicons-2.0.1/png/512/funnel.png | Bin 0 -> 3354 bytes .../ionicons-2.0.1/png/512/game-controller-a.png | Bin 0 -> 2548 bytes .../ionicons-2.0.1/png/512/game-controller-b.png | Bin 0 -> 3623 bytes .../external/ionicons-2.0.1/png/512/gear-a.png | Bin 0 -> 3806 bytes .../external/ionicons-2.0.1/png/512/gear-b.png | Bin 0 -> 2756 bytes .../external/ionicons-2.0.1/png/512/grid.png | Bin 0 -> 1066 bytes .../external/ionicons-2.0.1/png/512/hammer.png | Bin 0 -> 2493 bytes .../external/ionicons-2.0.1/png/512/happy.png | Bin 0 -> 5732 bytes .../external/ionicons-2.0.1/png/512/headphone.png | Bin 0 -> 4082 bytes .../ionicons-2.0.1/png/512/heart-broken.png | Bin 0 -> 4007 bytes .../external/ionicons-2.0.1/png/512/heart.png | Bin 0 -> 2322 bytes .../external/ionicons-2.0.1/png/512/help-buoy.png | Bin 0 -> 5824 bytes .../ionicons-2.0.1/png/512/help-circled.png | Bin 0 -> 3940 bytes .../external/ionicons-2.0.1/png/512/help.png | Bin 0 -> 2678 bytes .../external/ionicons-2.0.1/png/512/home.png | Bin 0 -> 1275 bytes .../external/ionicons-2.0.1/png/512/icecream.png | Bin 0 -> 2317 bytes .../png/512/icon-social-google-plus-outline.png | Bin 0 -> 4071 bytes .../png/512/icon-social-google-plus.png | Bin 0 -> 3888 bytes .../external/ionicons-2.0.1/png/512/image.png | Bin 0 -> 2952 bytes .../external/ionicons-2.0.1/png/512/images.png | Bin 0 -> 5073 bytes .../ionicons-2.0.1/png/512/information-circled.png | Bin 0 -> 3300 bytes .../ionicons-2.0.1/png/512/information.png | Bin 0 -> 2236 bytes .../external/ionicons-2.0.1/png/512/ionic.png | Bin 0 -> 5541 bytes .../ionicons-2.0.1/png/512/ios7-alarm-outline.png | Bin 0 -> 5769 bytes .../external/ionicons-2.0.1/png/512/ios7-alarm.png | Bin 0 -> 3922 bytes .../ionicons-2.0.1/png/512/ios7-albums-outline.png | Bin 0 -> 231 bytes .../ionicons-2.0.1/png/512/ios7-albums.png | Bin 0 -> 226 bytes .../png/512/ios7-americanfootball-outline.png | Bin 0 -> 5767 bytes .../png/512/ios7-americanfootball.png | Bin 0 -> 5675 bytes .../png/512/ios7-analytics-outline.png | Bin 0 -> 5847 bytes .../ionicons-2.0.1/png/512/ios7-analytics.png | Bin 0 -> 4406 bytes .../ionicons-2.0.1/png/512/ios7-arrow-back.png | Bin 0 -> 881 bytes .../ionicons-2.0.1/png/512/ios7-arrow-down.png | Bin 0 -> 1451 bytes .../ionicons-2.0.1/png/512/ios7-arrow-forward.png | Bin 0 -> 898 bytes .../ionicons-2.0.1/png/512/ios7-arrow-left.png | Bin 0 -> 1550 bytes .../ionicons-2.0.1/png/512/ios7-arrow-right.png | Bin 0 -> 1537 bytes .../png/512/ios7-arrow-thin-down.png | Bin 0 -> 1632 bytes .../png/512/ios7-arrow-thin-left.png | Bin 0 -> 1258 bytes .../png/512/ios7-arrow-thin-right.png | Bin 0 -> 1235 bytes .../ionicons-2.0.1/png/512/ios7-arrow-thin-up.png | Bin 0 -> 1647 bytes .../ionicons-2.0.1/png/512/ios7-arrow-up.png | Bin 0 -> 1482 bytes .../ionicons-2.0.1/png/512/ios7-at-outline.png | Bin 0 -> 4303 bytes .../external/ionicons-2.0.1/png/512/ios7-at.png | Bin 0 -> 4153 bytes .../png/512/ios7-barcode-outline.png | Bin 0 -> 233 bytes .../ionicons-2.0.1/png/512/ios7-barcode.png | Bin 0 -> 219 bytes .../png/512/ios7-baseball-outline.png | Bin 0 -> 6676 bytes .../ionicons-2.0.1/png/512/ios7-baseball.png | Bin 0 -> 5565 bytes .../png/512/ios7-basketball-outline.png | Bin 0 -> 6200 bytes .../ionicons-2.0.1/png/512/ios7-basketball.png | Bin 0 -> 6525 bytes .../ionicons-2.0.1/png/512/ios7-bell-outline.png | Bin 0 -> 3615 bytes .../external/ionicons-2.0.1/png/512/ios7-bell.png | Bin 0 -> 2769 bytes .../ionicons-2.0.1/png/512/ios7-bolt-outline.png | Bin 0 -> 2384 bytes .../external/ionicons-2.0.1/png/512/ios7-bolt.png | Bin 0 -> 1892 bytes .../png/512/ios7-bookmarks-outline.png | Bin 0 -> 2454 bytes .../ionicons-2.0.1/png/512/ios7-bookmarks.png | Bin 0 -> 2172 bytes .../ionicons-2.0.1/png/512/ios7-box-outline.png | Bin 0 -> 1602 bytes .../external/ionicons-2.0.1/png/512/ios7-box.png | Bin 0 -> 1032 bytes .../png/512/ios7-briefcase-outline.png | Bin 0 -> 1359 bytes .../ionicons-2.0.1/png/512/ios7-briefcase.png | Bin 0 -> 1316 bytes .../png/512/ios7-browsers-outline.png | Bin 0 -> 372 bytes .../ionicons-2.0.1/png/512/ios7-browsers.png | Bin 0 -> 357 bytes .../png/512/ios7-calculator-outline.png | Bin 0 -> 1785 bytes .../ionicons-2.0.1/png/512/ios7-calculator.png | Bin 0 -> 1500 bytes .../png/512/ios7-calendar-outline.png | Bin 0 -> 236 bytes .../ionicons-2.0.1/png/512/ios7-calendar.png | Bin 0 -> 230 bytes .../ionicons-2.0.1/png/512/ios7-camera-outline.png | Bin 0 -> 3582 bytes .../ionicons-2.0.1/png/512/ios7-camera.png | Bin 0 -> 3099 bytes .../ionicons-2.0.1/png/512/ios7-cart-outline.png | Bin 0 -> 2861 bytes .../external/ionicons-2.0.1/png/512/ios7-cart.png | Bin 0 -> 2200 bytes .../png/512/ios7-chatboxes-outline.png | Bin 0 -> 901 bytes .../ionicons-2.0.1/png/512/ios7-chatboxes.png | Bin 0 -> 512 bytes .../png/512/ios7-chatbubble-outline.png | Bin 0 -> 3640 bytes .../ionicons-2.0.1/png/512/ios7-chatbubble.png | Bin 0 -> 2259 bytes .../png/512/ios7-checkmark-empty.png | Bin 0 -> 920 bytes .../png/512/ios7-checkmark-outline.png | Bin 0 -> 4706 bytes .../ionicons-2.0.1/png/512/ios7-checkmark.png | Bin 0 -> 3080 bytes .../ionicons-2.0.1/png/512/ios7-circle-filled.png | Bin 0 -> 6478 bytes .../ionicons-2.0.1/png/512/ios7-circle-outline.png | Bin 0 -> 4120 bytes .../ionicons-2.0.1/png/512/ios7-clock-outline.png | Bin 0 -> 4320 bytes .../external/ionicons-2.0.1/png/512/ios7-clock.png | Bin 0 -> 2762 bytes .../ionicons-2.0.1/png/512/ios7-close-empty.png | Bin 0 -> 1204 bytes .../ionicons-2.0.1/png/512/ios7-close-outline.png | Bin 0 -> 4999 bytes .../external/ionicons-2.0.1/png/512/ios7-close.png | Bin 0 -> 3426 bytes .../png/512/ios7-cloud-download-outline.png | Bin 0 -> 3953 bytes .../ionicons-2.0.1/png/512/ios7-cloud-download.png | Bin 0 -> 2782 bytes .../ionicons-2.0.1/png/512/ios7-cloud-outline.png | Bin 0 -> 3339 bytes .../png/512/ios7-cloud-upload-outline.png | Bin 0 -> 3927 bytes .../ionicons-2.0.1/png/512/ios7-cloud-upload.png | Bin 0 -> 2815 bytes .../external/ionicons-2.0.1/png/512/ios7-cloud.png | Bin 0 -> 2082 bytes .../png/512/ios7-cloudy-night-outline.png | Bin 0 -> 3814 bytes .../ionicons-2.0.1/png/512/ios7-cloudy-night.png | Bin 0 -> 2870 bytes .../ionicons-2.0.1/png/512/ios7-cloudy-outline.png | Bin 0 -> 2280 bytes .../ionicons-2.0.1/png/512/ios7-cloudy.png | Bin 0 -> 1572 bytes .../ionicons-2.0.1/png/512/ios7-cog-outline.png | Bin 0 -> 8008 bytes .../external/ionicons-2.0.1/png/512/ios7-cog.png | Bin 0 -> 6029 bytes .../png/512/ios7-compose-outline.png | Bin 0 -> 1584 bytes .../ionicons-2.0.1/png/512/ios7-compose.png | Bin 0 -> 2061 bytes .../png/512/ios7-contact-outline.png | Bin 0 -> 4846 bytes .../ionicons-2.0.1/png/512/ios7-contact.png | Bin 0 -> 4218 bytes .../ionicons-2.0.1/png/512/ios7-copy-outline.png | Bin 0 -> 927 bytes .../external/ionicons-2.0.1/png/512/ios7-copy.png | Bin 0 -> 782 bytes .../png/512/ios7-download-outline.png | Bin 0 -> 1163 bytes .../ionicons-2.0.1/png/512/ios7-download.png | Bin 0 -> 1135 bytes .../external/ionicons-2.0.1/png/512/ios7-drag.png | Bin 0 -> 165 bytes .../ionicons-2.0.1/png/512/ios7-email-outline.png | Bin 0 -> 2592 bytes .../external/ionicons-2.0.1/png/512/ios7-email.png | Bin 0 -> 4167 bytes .../ionicons-2.0.1/png/512/ios7-expand.png | Bin 0 -> 485 bytes .../ionicons-2.0.1/png/512/ios7-eye-outline.png | Bin 0 -> 4381 bytes .../external/ionicons-2.0.1/png/512/ios7-eye.png | Bin 0 -> 2973 bytes .../png/512/ios7-fastforward-outline.png | Bin 0 -> 2726 bytes .../ionicons-2.0.1/png/512/ios7-fastforward.png | Bin 0 -> 2158 bytes .../ionicons-2.0.1/png/512/ios7-filing-outline.png | Bin 0 -> 2041 bytes .../ionicons-2.0.1/png/512/ios7-filing.png | Bin 0 -> 1933 bytes .../ionicons-2.0.1/png/512/ios7-film-outline.png | Bin 0 -> 772 bytes .../external/ionicons-2.0.1/png/512/ios7-film.png | Bin 0 -> 722 bytes .../ionicons-2.0.1/png/512/ios7-flag-outline.png | Bin 0 -> 1928 bytes .../external/ionicons-2.0.1/png/512/ios7-flag.png | Bin 0 -> 1483 bytes .../ionicons-2.0.1/png/512/ios7-folder-outline.png | Bin 0 -> 1606 bytes .../ionicons-2.0.1/png/512/ios7-folder.png | Bin 0 -> 1640 bytes .../png/512/ios7-football-outline.png | Bin 0 -> 6266 bytes .../ionicons-2.0.1/png/512/ios7-football.png | Bin 0 -> 5391 bytes .../ionicons-2.0.1/png/512/ios7-gear-outline.png | Bin 0 -> 5721 bytes .../external/ionicons-2.0.1/png/512/ios7-gear.png | Bin 0 -> 3445 bytes .../png/512/ios7-glasses-outline.png | Bin 0 -> 3597 bytes .../ionicons-2.0.1/png/512/ios7-glasses.png | Bin 0 -> 2350 bytes .../ionicons-2.0.1/png/512/ios7-heart-outline.png | Bin 0 -> 3097 bytes .../external/ionicons-2.0.1/png/512/ios7-heart.png | Bin 0 -> 2078 bytes .../ionicons-2.0.1/png/512/ios7-help-empty.png | Bin 0 -> 1669 bytes .../ionicons-2.0.1/png/512/ios7-help-outline.png | Bin 0 -> 5608 bytes .../external/ionicons-2.0.1/png/512/ios7-help.png | Bin 0 -> 3587 bytes .../ionicons-2.0.1/png/512/ios7-home-outline.png | Bin 0 -> 1710 bytes .../external/ionicons-2.0.1/png/512/ios7-home.png | Bin 0 -> 1518 bytes .../png/512/ios7-infinite-outline.png | Bin 0 -> 3028 bytes .../ionicons-2.0.1/png/512/ios7-infinite.png | Bin 0 -> 2989 bytes .../png/512/ios7-information-empty.png | Bin 0 -> 837 bytes .../png/512/ios7-information-outline.png | Bin 0 -> 4563 bytes .../ionicons-2.0.1/png/512/ios7-information.png | Bin 0 -> 2959 bytes .../ionicons-2.0.1/png/512/ios7-ionic-outline.png | Bin 0 -> 5780 bytes .../ionicons-2.0.1/png/512/ios7-keypad-outline.png | Bin 0 -> 7485 bytes .../ionicons-2.0.1/png/512/ios7-keypad.png | Bin 0 -> 7505 bytes .../png/512/ios7-lightbulb-outline.png | Bin 0 -> 3791 bytes .../ionicons-2.0.1/png/512/ios7-lightbulb.png | Bin 0 -> 2696 bytes .../png/512/ios7-location-outline.png | Bin 0 -> 4116 bytes .../ionicons-2.0.1/png/512/ios7-location.png | Bin 0 -> 2767 bytes .../ionicons-2.0.1/png/512/ios7-locked-outline.png | Bin 0 -> 2640 bytes .../ionicons-2.0.1/png/512/ios7-locked.png | Bin 0 -> 2674 bytes .../ionicons-2.0.1/png/512/ios7-loop-strong.png | Bin 0 -> 4101 bytes .../external/ionicons-2.0.1/png/512/ios7-loop.png | Bin 0 -> 4270 bytes .../ionicons-2.0.1/png/512/ios7-medkit-outline.png | Bin 0 -> 1386 bytes .../ionicons-2.0.1/png/512/ios7-medkit.png | Bin 0 -> 1373 bytes .../ionicons-2.0.1/png/512/ios7-mic-off.png | Bin 0 -> 7597 bytes .../ionicons-2.0.1/png/512/ios7-mic-outline.png | Bin 0 -> 3550 bytes .../external/ionicons-2.0.1/png/512/ios7-mic.png | Bin 0 -> 3878 bytes .../ionicons-2.0.1/png/512/ios7-minus-empty.png | Bin 0 -> 153 bytes .../ionicons-2.0.1/png/512/ios7-minus-outline.png | Bin 0 -> 4137 bytes .../external/ionicons-2.0.1/png/512/ios7-minus.png | Bin 0 -> 2520 bytes .../png/512/ios7-monitor-outline.png | Bin 0 -> 225 bytes .../ionicons-2.0.1/png/512/ios7-monitor.png | Bin 0 -> 230 bytes .../ionicons-2.0.1/png/512/ios7-moon-outline.png | Bin 0 -> 2566 bytes .../external/ionicons-2.0.1/png/512/ios7-moon.png | Bin 0 -> 1784 bytes .../ionicons-2.0.1/png/512/ios7-more-outline.png | Bin 0 -> 1598 bytes .../external/ionicons-2.0.1/png/512/ios7-more.png | Bin 0 -> 1700 bytes .../ionicons-2.0.1/png/512/ios7-musical-note.png | Bin 0 -> 1521 bytes .../ionicons-2.0.1/png/512/ios7-musical-notes.png | Bin 0 -> 2124 bytes .../png/512/ios7-navigate-outline.png | Bin 0 -> 4901 bytes .../ionicons-2.0.1/png/512/ios7-navigate.png | Bin 0 -> 3333 bytes .../ionicons-2.0.1/png/512/ios7-paper-outline.png | Bin 0 -> 1361 bytes .../external/ionicons-2.0.1/png/512/ios7-paper.png | Bin 0 -> 1197 bytes .../png/512/ios7-paperplane-outline.png | Bin 0 -> 2952 bytes .../ionicons-2.0.1/png/512/ios7-paperplane.png | Bin 0 -> 4805 bytes .../png/512/ios7-partlysunny-outline.png | Bin 0 -> 4823 bytes .../ionicons-2.0.1/png/512/ios7-partlysunny.png | Bin 0 -> 4052 bytes .../ionicons-2.0.1/png/512/ios7-pause-outline.png | Bin 0 -> 227 bytes .../external/ionicons-2.0.1/png/512/ios7-pause.png | Bin 0 -> 213 bytes .../ionicons-2.0.1/png/512/ios7-paw-outline.png | Bin 0 -> 6318 bytes .../external/ionicons-2.0.1/png/512/ios7-paw.png | Bin 0 -> 4119 bytes .../ionicons-2.0.1/png/512/ios7-people-outline.png | Bin 0 -> 5295 bytes .../ionicons-2.0.1/png/512/ios7-people.png | Bin 0 -> 3439 bytes .../ionicons-2.0.1/png/512/ios7-person-outline.png | Bin 0 -> 3189 bytes .../ionicons-2.0.1/png/512/ios7-person.png | Bin 0 -> 2046 bytes .../png/512/ios7-personadd-outline.png | Bin 0 -> 3246 bytes .../ionicons-2.0.1/png/512/ios7-personadd.png | Bin 0 -> 2110 bytes .../ionicons-2.0.1/png/512/ios7-photos-outline.png | Bin 0 -> 234 bytes .../ionicons-2.0.1/png/512/ios7-photos.png | Bin 0 -> 226 bytes .../ionicons-2.0.1/png/512/ios7-pie-outline.png | Bin 0 -> 4549 bytes .../external/ionicons-2.0.1/png/512/ios7-pie.png | Bin 0 -> 3646 bytes .../ionicons-2.0.1/png/512/ios7-play-outline.png | Bin 0 -> 1474 bytes .../external/ionicons-2.0.1/png/512/ios7-play.png | Bin 0 -> 1216 bytes .../ionicons-2.0.1/png/512/ios7-plus-empty.png | Bin 0 -> 204 bytes .../ionicons-2.0.1/png/512/ios7-plus-outline.png | Bin 0 -> 4415 bytes .../external/ionicons-2.0.1/png/512/ios7-plus.png | Bin 0 -> 2970 bytes .../png/512/ios7-pricetag-outline.png | Bin 0 -> 3007 bytes .../ionicons-2.0.1/png/512/ios7-pricetag.png | Bin 0 -> 2593 bytes .../png/512/ios7-pricetags-outline.png | Bin 0 -> 3563 bytes .../ionicons-2.0.1/png/512/ios7-pricetags.png | Bin 0 -> 3219 bytes .../png/512/ios7-printer-outline.png | Bin 0 -> 1764 bytes .../ionicons-2.0.1/png/512/ios7-printer.png | Bin 0 -> 1456 bytes .../ionicons-2.0.1/png/512/ios7-pulse-strong.png | Bin 0 -> 3326 bytes .../external/ionicons-2.0.1/png/512/ios7-pulse.png | Bin 0 -> 2955 bytes .../ionicons-2.0.1/png/512/ios7-rainy-outline.png | Bin 0 -> 3346 bytes .../external/ionicons-2.0.1/png/512/ios7-rainy.png | Bin 0 -> 2567 bytes .../png/512/ios7-recording-outline.png | Bin 0 -> 4926 bytes .../ionicons-2.0.1/png/512/ios7-recording.png | Bin 0 -> 3762 bytes .../ionicons-2.0.1/png/512/ios7-redo-outline.png | Bin 0 -> 3094 bytes .../external/ionicons-2.0.1/png/512/ios7-redo.png | Bin 0 -> 2054 bytes .../ionicons-2.0.1/png/512/ios7-refresh-empty.png | Bin 0 -> 2685 bytes .../png/512/ios7-refresh-outline.png | Bin 0 -> 6021 bytes .../ionicons-2.0.1/png/512/ios7-refresh.png | Bin 0 -> 4579 bytes .../ionicons-2.0.1/png/512/ios7-reload.png | Bin 0 -> 4195 bytes .../png/512/ios7-reverse-camera-outline.png | Bin 0 -> 3404 bytes .../ionicons-2.0.1/png/512/ios7-reverse-camera.png | Bin 0 -> 3019 bytes .../ionicons-2.0.1/png/512/ios7-rewind-outline.png | Bin 0 -> 2898 bytes .../ionicons-2.0.1/png/512/ios7-rewind.png | Bin 0 -> 2362 bytes .../ionicons-2.0.1/png/512/ios7-search-strong.png | Bin 0 -> 3329 bytes .../ionicons-2.0.1/png/512/ios7-search.png | Bin 0 -> 3361 bytes .../png/512/ios7-settings-strong.png | Bin 0 -> 1714 bytes .../ionicons-2.0.1/png/512/ios7-settings.png | Bin 0 -> 2160 bytes .../ionicons-2.0.1/png/512/ios7-shrink.png | Bin 0 -> 490 bytes .../png/512/ios7-skipbackward-outline.png | Bin 0 -> 1890 bytes .../ionicons-2.0.1/png/512/ios7-skipbackward.png | Bin 0 -> 1533 bytes .../png/512/ios7-skipforward-outline.png | Bin 0 -> 1827 bytes .../ionicons-2.0.1/png/512/ios7-skipforward.png | Bin 0 -> 1556 bytes .../external/ionicons-2.0.1/png/512/ios7-snowy.png | Bin 0 -> 3775 bytes .../png/512/ios7-speedometer-outline.png | Bin 0 -> 4678 bytes .../ionicons-2.0.1/png/512/ios7-speedometer.png | Bin 0 -> 5748 bytes .../ionicons-2.0.1/png/512/ios7-star-half.png | Bin 0 -> 3431 bytes .../ionicons-2.0.1/png/512/ios7-star-outline.png | Bin 0 -> 3572 bytes .../external/ionicons-2.0.1/png/512/ios7-star.png | Bin 0 -> 2463 bytes .../png/512/ios7-stopwatch-outline.png | Bin 0 -> 4823 bytes .../ionicons-2.0.1/png/512/ios7-stopwatch.png | Bin 0 -> 3451 bytes .../ionicons-2.0.1/png/512/ios7-sunny-outline.png | Bin 0 -> 2669 bytes .../external/ionicons-2.0.1/png/512/ios7-sunny.png | Bin 0 -> 2506 bytes .../png/512/ios7-telephone-outline.png | Bin 0 -> 3779 bytes .../ionicons-2.0.1/png/512/ios7-telephone.png | Bin 0 -> 2352 bytes .../png/512/ios7-tennisball-outline.png | Bin 0 -> 5535 bytes .../ionicons-2.0.1/png/512/ios7-tennisball.png | Bin 0 -> 6356 bytes .../png/512/ios7-thunderstorm-outline.png | Bin 0 -> 3053 bytes .../ionicons-2.0.1/png/512/ios7-thunderstorm.png | Bin 0 -> 2492 bytes .../ionicons-2.0.1/png/512/ios7-time-outline.png | Bin 0 -> 5875 bytes .../external/ionicons-2.0.1/png/512/ios7-time.png | Bin 0 -> 4136 bytes .../ionicons-2.0.1/png/512/ios7-timer-outline.png | Bin 0 -> 4578 bytes .../external/ionicons-2.0.1/png/512/ios7-timer.png | Bin 0 -> 6013 bytes .../ionicons-2.0.1/png/512/ios7-toggle-outline.png | Bin 0 -> 5660 bytes .../ionicons-2.0.1/png/512/ios7-toggle.png | Bin 0 -> 4825 bytes .../ionicons-2.0.1/png/512/ios7-trash-outline.png | Bin 0 -> 4497 bytes .../external/ionicons-2.0.1/png/512/ios7-trash.png | Bin 0 -> 2760 bytes .../ionicons-2.0.1/png/512/ios7-undo-outline.png | Bin 0 -> 3114 bytes .../external/ionicons-2.0.1/png/512/ios7-undo.png | Bin 0 -> 1954 bytes .../png/512/ios7-unlocked-outline.png | Bin 0 -> 2580 bytes .../ionicons-2.0.1/png/512/ios7-unlocked.png | Bin 0 -> 2605 bytes .../ionicons-2.0.1/png/512/ios7-upload-outline.png | Bin 0 -> 1128 bytes .../ionicons-2.0.1/png/512/ios7-upload.png | Bin 0 -> 1085 bytes .../png/512/ios7-videocam-outline.png | Bin 0 -> 2038 bytes .../ionicons-2.0.1/png/512/ios7-videocam.png | Bin 0 -> 2715 bytes .../ionicons-2.0.1/png/512/ios7-volume-high.png | Bin 0 -> 2977 bytes .../ionicons-2.0.1/png/512/ios7-volume-low.png | Bin 0 -> 956 bytes .../png/512/ios7-wineglass-outline.png | Bin 0 -> 2527 bytes .../ionicons-2.0.1/png/512/ios7-wineglass.png | Bin 0 -> 2013 bytes .../ionicons-2.0.1/png/512/ios7-world-outline.png | Bin 0 -> 7420 bytes .../external/ionicons-2.0.1/png/512/ios7-world.png | Bin 0 -> 10031 bytes .../external/ionicons-2.0.1/png/512/ipad.png | Bin 0 -> 1356 bytes .../external/ionicons-2.0.1/png/512/iphone.png | Bin 0 -> 1651 bytes .../external/ionicons-2.0.1/png/512/ipod.png | Bin 0 -> 3207 bytes .../fusion/external/ionicons-2.0.1/png/512/jet.png | Bin 0 -> 2856 bytes .../fusion/external/ionicons-2.0.1/png/512/key.png | Bin 0 -> 2722 bytes .../external/ionicons-2.0.1/png/512/knife.png | Bin 0 -> 1822 bytes .../external/ionicons-2.0.1/png/512/laptop.png | Bin 0 -> 2474 bytes .../external/ionicons-2.0.1/png/512/leaf.png | Bin 0 -> 3440 bytes .../external/ionicons-2.0.1/png/512/levels.png | Bin 0 -> 2431 bytes .../external/ionicons-2.0.1/png/512/lightbulb.png | Bin 0 -> 2474 bytes .../external/ionicons-2.0.1/png/512/link.png | Bin 0 -> 2306 bytes .../external/ionicons-2.0.1/png/512/load-a.png | Bin 0 -> 3941 bytes .../external/ionicons-2.0.1/png/512/load-b.png | Bin 0 -> 5473 bytes .../external/ionicons-2.0.1/png/512/load-c.png | Bin 0 -> 4337 bytes .../external/ionicons-2.0.1/png/512/load-d.png | Bin 0 -> 6618 bytes .../external/ionicons-2.0.1/png/512/location.png | Bin 0 -> 2739 bytes .../external/ionicons-2.0.1/png/512/locked.png | Bin 0 -> 2494 bytes .../external/ionicons-2.0.1/png/512/log-in.png | Bin 0 -> 1460 bytes .../external/ionicons-2.0.1/png/512/log-out.png | Bin 0 -> 1637 bytes .../external/ionicons-2.0.1/png/512/loop.png | Bin 0 -> 3794 bytes .../external/ionicons-2.0.1/png/512/magnet.png | Bin 0 -> 4495 bytes .../external/ionicons-2.0.1/png/512/male.png | Bin 0 -> 3788 bytes .../fusion/external/ionicons-2.0.1/png/512/man.png | Bin 0 -> 2126 bytes .../fusion/external/ionicons-2.0.1/png/512/map.png | Bin 0 -> 4906 bytes .../external/ionicons-2.0.1/png/512/medkit.png | Bin 0 -> 1605 bytes .../external/ionicons-2.0.1/png/512/merge.png | Bin 0 -> 3879 bytes .../external/ionicons-2.0.1/png/512/mic-a.png | Bin 0 -> 4098 bytes .../external/ionicons-2.0.1/png/512/mic-b.png | Bin 0 -> 2576 bytes .../external/ionicons-2.0.1/png/512/mic-c.png | Bin 0 -> 1726 bytes .../ionicons-2.0.1/png/512/minus-circled.png | Bin 0 -> 2655 bytes .../ionicons-2.0.1/png/512/minus-round.png | Bin 0 -> 937 bytes .../external/ionicons-2.0.1/png/512/minus.png | Bin 0 -> 160 bytes .../external/ionicons-2.0.1/png/512/model-s.png | Bin 0 -> 4262 bytes .../external/ionicons-2.0.1/png/512/monitor.png | Bin 0 -> 1469 bytes .../external/ionicons-2.0.1/png/512/more.png | Bin 0 -> 3357 bytes .../external/ionicons-2.0.1/png/512/mouse.png | Bin 0 -> 2891 bytes .../external/ionicons-2.0.1/png/512/music-note.png | Bin 0 -> 2519 bytes .../ionicons-2.0.1/png/512/navicon-round.png | Bin 0 -> 1628 bytes .../external/ionicons-2.0.1/png/512/navicon.png | Bin 0 -> 175 bytes .../external/ionicons-2.0.1/png/512/navigate.png | Bin 0 -> 1693 bytes .../external/ionicons-2.0.1/png/512/network.png | Bin 0 -> 3041 bytes .../external/ionicons-2.0.1/png/512/no-smoking.png | Bin 0 -> 5816 bytes .../external/ionicons-2.0.1/png/512/nuclear.png | Bin 0 -> 3618 bytes .../external/ionicons-2.0.1/png/512/outlet.png | Bin 0 -> 2882 bytes .../ionicons-2.0.1/png/512/paper-airplane.png | Bin 0 -> 3678 bytes .../external/ionicons-2.0.1/png/512/paperclip.png | Bin 0 -> 2710 bytes .../external/ionicons-2.0.1/png/512/pause.png | Bin 0 -> 1340 bytes .../external/ionicons-2.0.1/png/512/person-add.png | Bin 0 -> 2410 bytes .../ionicons-2.0.1/png/512/person-stalker.png | Bin 0 -> 3272 bytes .../external/ionicons-2.0.1/png/512/person.png | Bin 0 -> 2258 bytes .../external/ionicons-2.0.1/png/512/pie-graph.png | Bin 0 -> 3608 bytes .../fusion/external/ionicons-2.0.1/png/512/pin.png | Bin 0 -> 2270 bytes .../external/ionicons-2.0.1/png/512/pinpoint.png | Bin 0 -> 4799 bytes .../external/ionicons-2.0.1/png/512/pizza.png | Bin 0 -> 4548 bytes .../external/ionicons-2.0.1/png/512/plane.png | Bin 0 -> 3218 bytes .../external/ionicons-2.0.1/png/512/planet.png | Bin 0 -> 4319 bytes .../external/ionicons-2.0.1/png/512/play.png | Bin 0 -> 1787 bytes .../ionicons-2.0.1/png/512/playstation.png | Bin 0 -> 3275 bytes .../ionicons-2.0.1/png/512/plus-circled.png | Bin 0 -> 3114 bytes .../external/ionicons-2.0.1/png/512/plus-round.png | Bin 0 -> 1567 bytes .../external/ionicons-2.0.1/png/512/plus.png | Bin 0 -> 223 bytes .../external/ionicons-2.0.1/png/512/podium.png | Bin 0 -> 209 bytes .../external/ionicons-2.0.1/png/512/pound.png | Bin 0 -> 2383 bytes .../external/ionicons-2.0.1/png/512/power.png | Bin 0 -> 4727 bytes .../external/ionicons-2.0.1/png/512/pricetag.png | Bin 0 -> 2457 bytes .../external/ionicons-2.0.1/png/512/pricetags.png | Bin 0 -> 2906 bytes .../external/ionicons-2.0.1/png/512/printer.png | Bin 0 -> 1869 bytes .../ionicons-2.0.1/png/512/pull-request.png | Bin 0 -> 3613 bytes .../external/ionicons-2.0.1/png/512/qr-scanner.png | Bin 0 -> 1842 bytes .../external/ionicons-2.0.1/png/512/quote.png | Bin 0 -> 1743 bytes .../ionicons-2.0.1/png/512/radio-waves.png | Bin 0 -> 4978 bytes .../external/ionicons-2.0.1/png/512/record.png | Bin 0 -> 3779 bytes .../external/ionicons-2.0.1/png/512/refresh.png | Bin 0 -> 3582 bytes .../external/ionicons-2.0.1/png/512/reply-all.png | Bin 0 -> 3033 bytes .../external/ionicons-2.0.1/png/512/reply.png | Bin 0 -> 2131 bytes .../external/ionicons-2.0.1/png/512/ribbon-a.png | Bin 0 -> 6449 bytes .../external/ionicons-2.0.1/png/512/ribbon-b.png | Bin 0 -> 5913 bytes .../fusion/external/ionicons-2.0.1/png/512/sad.png | Bin 0 -> 5517 bytes .../external/ionicons-2.0.1/png/512/scissors.png | Bin 0 -> 5061 bytes .../external/ionicons-2.0.1/png/512/search.png | Bin 0 -> 3229 bytes .../external/ionicons-2.0.1/png/512/settings.png | Bin 0 -> 4141 bytes .../external/ionicons-2.0.1/png/512/share.png | Bin 0 -> 2616 bytes .../external/ionicons-2.0.1/png/512/shuffle.png | Bin 0 -> 3420 bytes .../ionicons-2.0.1/png/512/skip-backward.png | Bin 0 -> 2421 bytes .../ionicons-2.0.1/png/512/skip-forward.png | Bin 0 -> 2402 bytes .../png/512/social-android-outline.png | Bin 0 -> 3772 bytes .../ionicons-2.0.1/png/512/social-android.png | Bin 0 -> 2784 bytes .../png/512/social-apple-outline.png | Bin 0 -> 4104 bytes .../ionicons-2.0.1/png/512/social-apple.png | Bin 0 -> 2647 bytes .../png/512/social-bitcoin-outline.png | Bin 0 -> 3790 bytes .../ionicons-2.0.1/png/512/social-bitcoin.png | Bin 0 -> 2424 bytes .../png/512/social-buffer-outline.png | Bin 0 -> 3913 bytes .../ionicons-2.0.1/png/512/social-buffer.png | Bin 0 -> 4687 bytes .../png/512/social-designernews-outline.png | Bin 0 -> 4754 bytes .../ionicons-2.0.1/png/512/social-designernews.png | Bin 0 -> 4242 bytes .../png/512/social-dribbble-outline.png | Bin 0 -> 5588 bytes .../ionicons-2.0.1/png/512/social-dribbble.png | Bin 0 -> 6983 bytes .../png/512/social-dropbox-outline.png | Bin 0 -> 5113 bytes .../ionicons-2.0.1/png/512/social-dropbox.png | Bin 0 -> 6161 bytes .../png/512/social-facebook-outline.png | Bin 0 -> 1788 bytes .../ionicons-2.0.1/png/512/social-facebook.png | Bin 0 -> 1402 bytes .../png/512/social-foursquare-outline.png | Bin 0 -> 3364 bytes .../ionicons-2.0.1/png/512/social-foursquare.png | Bin 0 -> 3021 bytes .../png/512/social-freebsd-devil.png | Bin 0 -> 5300 bytes .../png/512/social-github-outline.png | Bin 0 -> 7475 bytes .../ionicons-2.0.1/png/512/social-github.png | Bin 0 -> 4561 bytes .../png/512/social-google-outline.png | Bin 0 -> 3890 bytes .../ionicons-2.0.1/png/512/social-google.png | Bin 0 -> 3682 bytes .../png/512/social-googleplus-outline.png | Bin 0 -> 4071 bytes .../ionicons-2.0.1/png/512/social-googleplus.png | Bin 0 -> 3888 bytes .../png/512/social-hackernews-outline.png | Bin 0 -> 1994 bytes .../ionicons-2.0.1/png/512/social-hackernews.png | Bin 0 -> 1905 bytes .../png/512/social-instagram-outline.png | Bin 0 -> 3317 bytes .../ionicons-2.0.1/png/512/social-instagram.png | Bin 0 -> 4403 bytes .../png/512/social-linkedin-outline.png | Bin 0 -> 2370 bytes .../ionicons-2.0.1/png/512/social-linkedin.png | Bin 0 -> 2275 bytes .../png/512/social-pinterest-outline.png | Bin 0 -> 6933 bytes .../ionicons-2.0.1/png/512/social-pinterest.png | Bin 0 -> 5532 bytes .../png/512/social-reddit-outline.png | Bin 0 -> 6414 bytes .../ionicons-2.0.1/png/512/social-reddit.png | Bin 0 -> 4498 bytes .../ionicons-2.0.1/png/512/social-rss-outline.png | Bin 0 -> 5945 bytes .../external/ionicons-2.0.1/png/512/social-rss.png | Bin 0 -> 4789 bytes .../png/512/social-skype-outline.png | Bin 0 -> 5608 bytes .../ionicons-2.0.1/png/512/social-skype.png | Bin 0 -> 4269 bytes .../png/512/social-tumblr-outline.png | Bin 0 -> 2725 bytes .../ionicons-2.0.1/png/512/social-tumblr.png | Bin 0 -> 1946 bytes .../external/ionicons-2.0.1/png/512/social-tux.png | Bin 0 -> 7103 bytes .../png/512/social-twitter-outline.png | Bin 0 -> 5569 bytes .../ionicons-2.0.1/png/512/social-twitter.png | Bin 0 -> 3405 bytes .../ionicons-2.0.1/png/512/social-usd-outline.png | Bin 0 -> 5744 bytes .../external/ionicons-2.0.1/png/512/social-usd.png | Bin 0 -> 3446 bytes .../png/512/social-vimeo-outline.png | Bin 0 -> 5525 bytes .../ionicons-2.0.1/png/512/social-vimeo.png | Bin 0 -> 3456 bytes .../png/512/social-windows-outline.png | Bin 0 -> 1775 bytes .../ionicons-2.0.1/png/512/social-windows.png | Bin 0 -> 2550 bytes .../png/512/social-wordpress-outline.png | Bin 0 -> 6418 bytes .../ionicons-2.0.1/png/512/social-wordpress.png | Bin 0 -> 5465 bytes .../png/512/social-yahoo-outline.png | Bin 0 -> 2119 bytes .../ionicons-2.0.1/png/512/social-yahoo.png | Bin 0 -> 1729 bytes .../png/512/social-youtube-outline.png | Bin 0 -> 4655 bytes .../ionicons-2.0.1/png/512/social-youtube.png | Bin 0 -> 2511 bytes .../ionicons-2.0.1/png/512/speakerphone.png | Bin 0 -> 4310 bytes .../ionicons-2.0.1/png/512/speedometer.png | Bin 0 -> 4238 bytes .../external/ionicons-2.0.1/png/512/spoon.png | Bin 0 -> 2306 bytes .../external/ionicons-2.0.1/png/512/star.png | Bin 0 -> 2195 bytes .../external/ionicons-2.0.1/png/512/stats-bars.png | Bin 0 -> 218 bytes .../external/ionicons-2.0.1/png/512/steam.png | Bin 0 -> 3875 bytes .../external/ionicons-2.0.1/png/512/stop.png | Bin 0 -> 1090 bytes .../ionicons-2.0.1/png/512/thermometer.png | Bin 0 -> 1980 bytes .../external/ionicons-2.0.1/png/512/thumbsdown.png | Bin 0 -> 2288 bytes .../external/ionicons-2.0.1/png/512/thumbsup.png | Bin 0 -> 2356 bytes .../ionicons-2.0.1/png/512/toggle-filled.png | Bin 0 -> 3194 bytes .../external/ionicons-2.0.1/png/512/toggle.png | Bin 0 -> 3599 bytes .../external/ionicons-2.0.1/png/512/trash-a.png | Bin 0 -> 2752 bytes .../external/ionicons-2.0.1/png/512/trash-b.png | Bin 0 -> 1882 bytes .../external/ionicons-2.0.1/png/512/trophy.png | Bin 0 -> 3579 bytes .../external/ionicons-2.0.1/png/512/umbrella.png | Bin 0 -> 3416 bytes .../external/ionicons-2.0.1/png/512/university.png | Bin 0 -> 3167 bytes .../external/ionicons-2.0.1/png/512/unlocked.png | Bin 0 -> 2412 bytes .../external/ionicons-2.0.1/png/512/upload.png | Bin 0 -> 2480 bytes .../fusion/external/ionicons-2.0.1/png/512/usb.png | Bin 0 -> 3950 bytes .../ionicons-2.0.1/png/512/videocamera.png | Bin 0 -> 2381 bytes .../ionicons-2.0.1/png/512/volume-high.png | Bin 0 -> 4334 bytes .../ionicons-2.0.1/png/512/volume-medium.png | Bin 0 -> 3174 bytes .../ionicons-2.0.1/png/512/volume-mute.png | Bin 0 -> 4803 bytes .../external/ionicons-2.0.1/png/512/wand.png | Bin 0 -> 1933 bytes .../external/ionicons-2.0.1/png/512/waterdrop.png | Bin 0 -> 3169 bytes .../external/ionicons-2.0.1/png/512/wifi.png | Bin 0 -> 3037 bytes .../external/ionicons-2.0.1/png/512/wineglass.png | Bin 0 -> 3734 bytes .../external/ionicons-2.0.1/png/512/woman.png | Bin 0 -> 3592 bytes .../external/ionicons-2.0.1/png/512/wrench.png | Bin 0 -> 2866 bytes .../external/ionicons-2.0.1/png/512/xbox.png | Bin 0 -> 4958 bytes .../app/fusion/external/ionicons-2.0.1/readme.md | 60 + .../ionicons-2.0.1/scss/_ionicons-font.scss | 27 + .../ionicons-2.0.1/scss/_ionicons-icons.scss | 1473 + .../ionicons-2.0.1/scss/_ionicons-variables.scss | 741 + .../external/ionicons-2.0.1/scss/ionicons.scss | 15 + .../external/ionicons-2.0.1/src/alert-circled.svg | 11 + .../fusion/external/ionicons-2.0.1/src/alert.svg | 9 + .../ionicons-2.0.1/src/android-add-circle.svg | 12 + .../external/ionicons-2.0.1/src/android-add.svg | 11 + .../ionicons-2.0.1/src/android-alarm-clock.svg | 15 + .../external/ionicons-2.0.1/src/android-alert.svg | 12 + .../external/ionicons-2.0.1/src/android-apps.svg | 12 + .../ionicons-2.0.1/src/android-archive.svg | 12 + .../ionicons-2.0.1/src/android-arrow-back.svg | 11 + .../ionicons-2.0.1/src/android-arrow-down.svg | 11 + .../src/android-arrow-dropdown-circle.svg | 10 + .../ionicons-2.0.1/src/android-arrow-dropdown.svg | 9 + .../src/android-arrow-dropleft-circle.svg | 10 + .../ionicons-2.0.1/src/android-arrow-dropleft.svg | 9 + .../src/android-arrow-dropright-circle.svg | 10 + .../ionicons-2.0.1/src/android-arrow-dropright.svg | 9 + .../src/android-arrow-dropup-circle.svg | 10 + .../ionicons-2.0.1/src/android-arrow-dropup.svg | 9 + .../ionicons-2.0.1/src/android-arrow-forward.svg | 11 + .../ionicons-2.0.1/src/android-arrow-up.svg | 11 + .../external/ionicons-2.0.1/src/android-attach.svg | 15 + .../external/ionicons-2.0.1/src/android-bar.svg | 12 + .../ionicons-2.0.1/src/android-bicycle.svg | 19 + .../external/ionicons-2.0.1/src/android-boat.svg | 16 + .../ionicons-2.0.1/src/android-bookmark.svg | 7 + .../external/ionicons-2.0.1/src/android-bulb.svg | 18 + .../external/ionicons-2.0.1/src/android-bus.svg | 18 + .../ionicons-2.0.1/src/android-calendar.svg | 11 + .../external/ionicons-2.0.1/src/android-call.svg | 10 + .../external/ionicons-2.0.1/src/android-camera.svg | 12 + .../external/ionicons-2.0.1/src/android-cancel.svg | 11 + .../external/ionicons-2.0.1/src/android-car.svg | 15 + .../external/ionicons-2.0.1/src/android-cart.svg | 14 + .../external/ionicons-2.0.1/src/android-chat.svg | 12 + .../ionicons-2.0.1/src/android-checkbox-blank.svg | 12 + .../src/android-checkbox-outline-blank.svg | 13 + .../src/android-checkbox-outline.svg | 13 + .../ionicons-2.0.1/src/android-checkbox.svg | 13 + .../src/android-checkmark-circle.svg | 9 + .../ionicons-2.0.1/src/android-clipboard.svg | 10 + .../external/ionicons-2.0.1/src/android-close.svg | 12 + .../ionicons-2.0.1/src/android-cloud-circle.svg | 16 + .../ionicons-2.0.1/src/android-cloud-done.svg | 12 + .../ionicons-2.0.1/src/android-cloud-outline.svg | 16 + .../external/ionicons-2.0.1/src/android-cloud.svg | 9 + .../ionicons-2.0.1/src/android-color-palette.svg | 17 + .../ionicons-2.0.1/src/android-compass.svg | 9 + .../ionicons-2.0.1/src/android-contact.svg | 15 + .../ionicons-2.0.1/src/android-contacts.svg | 26 + .../ionicons-2.0.1/src/android-contract.svg | 12 + .../external/ionicons-2.0.1/src/android-create.svg | 13 + .../external/ionicons-2.0.1/src/android-delete.svg | 10 + .../ionicons-2.0.1/src/android-desktop.svg | 13 + .../ionicons-2.0.1/src/android-document.svg | 10 + .../ionicons-2.0.1/src/android-done-all.svg | 13 + .../external/ionicons-2.0.1/src/android-done.svg | 13 + .../ionicons-2.0.1/src/android-download.svg | 9 + .../external/ionicons-2.0.1/src/android-drafts.svg | 15 + .../external/ionicons-2.0.1/src/android-exit.svg | 9 + .../external/ionicons-2.0.1/src/android-expand.svg | 12 + .../src/android-favorite-outline.svg | 13 + .../ionicons-2.0.1/src/android-favorite.svg | 11 + .../external/ionicons-2.0.1/src/android-film.svg | 9 + .../ionicons-2.0.1/src/android-folder-open.svg | 10 + .../external/ionicons-2.0.1/src/android-folder.svg | 14 + .../external/ionicons-2.0.1/src/android-funnel.svg | 7 + .../external/ionicons-2.0.1/src/android-globe.svg | 24 + .../external/ionicons-2.0.1/src/android-hand.svg | 15 + .../ionicons-2.0.1/src/android-hangout.svg | 9 + .../external/ionicons-2.0.1/src/android-happy.svg | 12 + .../external/ionicons-2.0.1/src/android-home.svg | 9 + .../external/ionicons-2.0.1/src/android-image.svg | 13 + .../external/ionicons-2.0.1/src/android-laptop.svg | 14 + .../external/ionicons-2.0.1/src/android-list.svg | 10 + .../external/ionicons-2.0.1/src/android-locate.svg | 16 + .../external/ionicons-2.0.1/src/android-lock.svg | 14 + .../external/ionicons-2.0.1/src/android-mail.svg | 13 + .../external/ionicons-2.0.1/src/android-map.svg | 16 + .../external/ionicons-2.0.1/src/android-menu.svg | 11 + .../ionicons-2.0.1/src/android-microphone-off.svg | 17 + .../ionicons-2.0.1/src/android-microphone.svg | 12 + .../ionicons-2.0.1/src/android-more-horizontal.svg | 9 + .../ionicons-2.0.1/src/android-more-vertical.svg | 9 + .../ionicons-2.0.1/src/android-navigate.svg | 11 + .../src/android-notifications-none.svg | 11 + .../src/android-notifications-off.svg | 13 + .../ionicons-2.0.1/src/android-notifications.svg | 9 + .../external/ionicons-2.0.1/src/android-open.svg | 9 + .../ionicons-2.0.1/src/android-options.svg | 26 + .../external/ionicons-2.0.1/src/android-people.svg | 11 + .../ionicons-2.0.1/src/android-person-add.svg | 17 + .../external/ionicons-2.0.1/src/android-person.svg | 10 + .../ionicons-2.0.1/src/android-phone-landscape.svg | 12 + .../ionicons-2.0.1/src/android-phone-portrait.svg | 12 + .../external/ionicons-2.0.1/src/android-pin.svg | 11 + .../external/ionicons-2.0.1/src/android-plane.svg | 12 + .../ionicons-2.0.1/src/android-playstore.svg | 11 + .../external/ionicons-2.0.1/src/android-print.svg | 10 + .../src/android-radio-button-off.svg | 12 + .../ionicons-2.0.1/src/android-radio-button-on.svg | 13 + .../ionicons-2.0.1/src/android-refresh.svg | 11 + .../ionicons-2.0.1/src/android-remove-circle.svg | 10 + .../external/ionicons-2.0.1/src/android-remove.svg | 7 + .../ionicons-2.0.1/src/android-restaurant.svg | 17 + .../external/ionicons-2.0.1/src/android-sad.svg | 16 + .../external/ionicons-2.0.1/src/android-search.svg | 19 + .../external/ionicons-2.0.1/src/android-send.svg | 7 + .../ionicons-2.0.1/src/android-settings.svg | 19 + .../ionicons-2.0.1/src/android-share-alt.svg | 16 + .../external/ionicons-2.0.1/src/android-share.svg | 12 + .../ionicons-2.0.1/src/android-star-half.svg | 9 + .../ionicons-2.0.1/src/android-star-outline.svg | 10 + .../external/ionicons-2.0.1/src/android-star.svg | 10 + .../ionicons-2.0.1/src/android-stopwatch.svg | 21 + .../external/ionicons-2.0.1/src/android-subway.svg | 13 + .../external/ionicons-2.0.1/src/android-sunny.svg | 18 + .../external/ionicons-2.0.1/src/android-sync.svg | 10 + .../ionicons-2.0.1/src/android-textsms.svg | 10 + .../external/ionicons-2.0.1/src/android-time.svg | 15 + .../external/ionicons-2.0.1/src/android-train.svg | 15 + .../external/ionicons-2.0.1/src/android-unlock.svg | 10 + .../external/ionicons-2.0.1/src/android-upload.svg | 9 + .../ionicons-2.0.1/src/android-volume-down.svg | 8 + .../ionicons-2.0.1/src/android-volume-mute.svg | 7 + .../ionicons-2.0.1/src/android-volume-off.svg | 15 + .../ionicons-2.0.1/src/android-volume-up.svg | 9 + .../external/ionicons-2.0.1/src/android-walk.svg | 12 + .../ionicons-2.0.1/src/android-warning.svg | 11 + .../external/ionicons-2.0.1/src/android-watch.svg | 15 + .../external/ionicons-2.0.1/src/android-wifi.svg | 14 + .../external/ionicons-2.0.1/src/aperture.svg | 20 + .../fusion/external/ionicons-2.0.1/src/archive.svg | 12 + .../external/ionicons-2.0.1/src/arrow-down-a.svg | 7 + .../external/ionicons-2.0.1/src/arrow-down-b.svg | 8 + .../external/ionicons-2.0.1/src/arrow-down-c.svg | 9 + .../external/ionicons-2.0.1/src/arrow-expand.svg | 12 + .../ionicons-2.0.1/src/arrow-graph-down-left.svg | 7 + .../ionicons-2.0.1/src/arrow-graph-down-right.svg | 7 + .../ionicons-2.0.1/src/arrow-graph-up-left.svg | 7 + .../ionicons-2.0.1/src/arrow-graph-up-right.svg | 7 + .../external/ionicons-2.0.1/src/arrow-left-a.svg | 7 + .../external/ionicons-2.0.1/src/arrow-left-b.svg | 8 + .../external/ionicons-2.0.1/src/arrow-left-c.svg | 9 + .../external/ionicons-2.0.1/src/arrow-move.svg | 8 + .../external/ionicons-2.0.1/src/arrow-resize.svg | 8 + .../ionicons-2.0.1/src/arrow-return-left.svg | 8 + .../ionicons-2.0.1/src/arrow-return-right.svg | 8 + .../external/ionicons-2.0.1/src/arrow-right-a.svg | 7 + .../external/ionicons-2.0.1/src/arrow-right-b.svg | 8 + .../external/ionicons-2.0.1/src/arrow-right-c.svg | 9 + .../external/ionicons-2.0.1/src/arrow-shrink.svg | 12 + .../external/ionicons-2.0.1/src/arrow-swap.svg | 10 + .../external/ionicons-2.0.1/src/arrow-up-a.svg | 7 + .../external/ionicons-2.0.1/src/arrow-up-b.svg | 8 + .../external/ionicons-2.0.1/src/arrow-up-c.svg | 9 + .../external/ionicons-2.0.1/src/asterisk.svg | 8 + .../app/fusion/external/ionicons-2.0.1/src/at.svg | 25 + .../ionicons-2.0.1/src/backspace-outline.svg | 21 + .../external/ionicons-2.0.1/src/backspace.svg | 17 + .../app/fusion/external/ionicons-2.0.1/src/bag.svg | 10 + .../ionicons-2.0.1/src/battery-charging.svg | 9 + .../external/ionicons-2.0.1/src/battery-empty.svg | 8 + .../external/ionicons-2.0.1/src/battery-full.svg | 8 + .../external/ionicons-2.0.1/src/battery-half.svg | 9 + .../external/ionicons-2.0.1/src/battery-low.svg | 9 + .../fusion/external/ionicons-2.0.1/src/beaker.svg | 20 + .../fusion/external/ionicons-2.0.1/src/beer.svg | 28 + .../external/ionicons-2.0.1/src/bluetooth.svg | 18 + .../fusion/external/ionicons-2.0.1/src/bonfire.svg | 32 + .../external/ionicons-2.0.1/src/bookmark.svg | 10 + .../fusion/external/ionicons-2.0.1/src/bowtie.svg | 22 + .../external/ionicons-2.0.1/src/briefcase.svg | 12 + .../app/fusion/external/ionicons-2.0.1/src/bug.svg | 30 + .../external/ionicons-2.0.1/src/calculator.svg | 10 + .../external/ionicons-2.0.1/src/calendar.svg | 12 + .../fusion/external/ionicons-2.0.1/src/camera.svg | 15 + .../fusion/external/ionicons-2.0.1/src/card.svg | 14 + .../fusion/external/ionicons-2.0.1/src/cash.svg | 31 + .../ionicons-2.0.1/src/chatbox-working.svg | 11 + .../fusion/external/ionicons-2.0.1/src/chatbox.svg | 8 + .../external/ionicons-2.0.1/src/chatboxes.svg | 12 + .../ionicons-2.0.1/src/chatbubble-working.svg | 12 + .../external/ionicons-2.0.1/src/chatbubble.svg | 9 + .../external/ionicons-2.0.1/src/chatbubbles.svg | 16 + .../ionicons-2.0.1/src/checkmark-circled.svg | 13 + .../ionicons-2.0.1/src/checkmark-round.svg | 9 + .../external/ionicons-2.0.1/src/checkmark.svg | 10 + .../external/ionicons-2.0.1/src/chevron-down.svg | 9 + .../external/ionicons-2.0.1/src/chevron-left.svg | 9 + .../external/ionicons-2.0.1/src/chevron-right.svg | 9 + .../external/ionicons-2.0.1/src/chevron-up.svg | 9 + .../external/ionicons-2.0.1/src/clipboard.svg | 22 + .../fusion/external/ionicons-2.0.1/src/clock.svg | 21 + .../external/ionicons-2.0.1/src/close-circled.svg | 13 + .../external/ionicons-2.0.1/src/close-round.svg | 9 + .../fusion/external/ionicons-2.0.1/src/close.svg | 10 + .../ionicons-2.0.1/src/closed-captioning.svg | 31 + .../fusion/external/ionicons-2.0.1/src/cloud.svg | 9 + .../external/ionicons-2.0.1/src/code-download.svg | 31 + .../external/ionicons-2.0.1/src/code-working.svg | 21 + .../fusion/external/ionicons-2.0.1/src/code.svg | 14 + .../fusion/external/ionicons-2.0.1/src/coffee.svg | 13 + .../fusion/external/ionicons-2.0.1/src/compass.svg | 16 + .../fusion/external/ionicons-2.0.1/src/compose.svg | 14 + .../ionicons-2.0.1/src/connection-bars.svg | 12 + .../external/ionicons-2.0.1/src/contrast.svg | 9 + .../fusion/external/ionicons-2.0.1/src/crop.svg | 11 + .../fusion/external/ionicons-2.0.1/src/cube.svg | 19 + .../fusion/external/ionicons-2.0.1/src/disc.svg | 13 + .../external/ionicons-2.0.1/src/document-text.svg | 15 + .../external/ionicons-2.0.1/src/document.svg | 10 + .../fusion/external/ionicons-2.0.1/src/drag.svg | 11 + .../fusion/external/ionicons-2.0.1/src/earth.svg | 44 + .../fusion/external/ionicons-2.0.1/src/easel.svg | 15 + .../fusion/external/ionicons-2.0.1/src/edit.svg | 13 + .../app/fusion/external/ionicons-2.0.1/src/egg.svg | 7 + .../fusion/external/ionicons-2.0.1/src/eject.svg | 12 + .../external/ionicons-2.0.1/src/email-unread.svg | 19 + .../fusion/external/ionicons-2.0.1/src/email.svg | 15 + .../src/erlenmeyer-flask-bubbles.svg | 15 + .../ionicons-2.0.1/src/erlenmeyer-flask.svg | 21 + .../external/ionicons-2.0.1/src/eye-disabled.svg | 18 + .../app/fusion/external/ionicons-2.0.1/src/eye.svg | 15 + .../fusion/external/ionicons-2.0.1/src/female.svg | 8 + .../fusion/external/ionicons-2.0.1/src/filing.svg | 12 + .../external/ionicons-2.0.1/src/film-marker.svg | 10 + .../external/ionicons-2.0.1/src/fireball.svg | 16 + .../fusion/external/ionicons-2.0.1/src/flag.svg | 12 + .../fusion/external/ionicons-2.0.1/src/flame.svg | 11 + .../external/ionicons-2.0.1/src/flash-off.svg | 16 + .../fusion/external/ionicons-2.0.1/src/flash.svg | 7 + .../fusion/external/ionicons-2.0.1/src/folder.svg | 14 + .../external/ionicons-2.0.1/src/fork-repo.svg | 20 + .../fusion/external/ionicons-2.0.1/src/fork.svg | 14 + .../fusion/external/ionicons-2.0.1/src/forward.svg | 9 + .../fusion/external/ionicons-2.0.1/src/funnel.svg | 13 + .../fusion/external/ionicons-2.0.1/src/gear-a.svg | 15 + .../fusion/external/ionicons-2.0.1/src/gear-b.svg | 11 + .../fusion/external/ionicons-2.0.1/src/grid.svg | 32 + .../fusion/external/ionicons-2.0.1/src/hammer.svg | 11 + .../external/ionicons-2.0.1/src/happy-outline.svg | 23 + .../fusion/external/ionicons-2.0.1/src/happy.svg | 20 + .../external/ionicons-2.0.1/src/headphone.svg | 15 + .../external/ionicons-2.0.1/src/heart-broken.svg | 17 + .../fusion/external/ionicons-2.0.1/src/heart.svg | 10 + .../external/ionicons-2.0.1/src/help-buoy.svg | 13 + .../external/ionicons-2.0.1/src/help-circled.svg | 15 + .../fusion/external/ionicons-2.0.1/src/help.svg | 14 + .../fusion/external/ionicons-2.0.1/src/home.svg | 9 + .../external/ionicons-2.0.1/src/icecream.svg | 15 + .../fusion/external/ionicons-2.0.1/src/image.svg | 13 + .../fusion/external/ionicons-2.0.1/src/images.svg | 20 + .../ionicons-2.0.1/src/information-circled.svg | 11 + .../external/ionicons-2.0.1/src/information.svg | 10 + .../fusion/external/ionicons-2.0.1/src/ionic.svg | 18 + .../ionicons-2.0.1/src/ios-alarm-outline.svg | 21 + .../external/ionicons-2.0.1/src/ios-alarm.svg | 14 + .../ionicons-2.0.1/src/ios-albums-outline.svg | 11 + .../external/ionicons-2.0.1/src/ios-albums.svg | 11 + .../src/ios-americanfootball-outline.svg | 24 + .../ionicons-2.0.1/src/ios-americanfootball.svg | 21 + .../ionicons-2.0.1/src/ios-analytics-outline.svg | 24 + .../external/ionicons-2.0.1/src/ios-analytics.svg | 17 + .../external/ionicons-2.0.1/src/ios-arrow-back.svg | 7 + .../external/ionicons-2.0.1/src/ios-arrow-down.svg | 7 + .../ionicons-2.0.1/src/ios-arrow-forward.svg | 7 + .../external/ionicons-2.0.1/src/ios-arrow-left.svg | 7 + .../ionicons-2.0.1/src/ios-arrow-right.svg | 7 + .../ionicons-2.0.1/src/ios-arrow-thin-down.svg | 9 + .../ionicons-2.0.1/src/ios-arrow-thin-left.svg | 9 + .../ionicons-2.0.1/src/ios-arrow-thin-right.svg | 9 + .../ionicons-2.0.1/src/ios-arrow-thin-up.svg | 9 + .../external/ionicons-2.0.1/src/ios-arrow-up.svg | 7 + .../external/ionicons-2.0.1/src/ios-at-outline.svg | 26 + .../fusion/external/ionicons-2.0.1/src/ios-at.svg | 24 + .../ionicons-2.0.1/src/ios-barcode-outline.svg | 15 + .../external/ionicons-2.0.1/src/ios-barcode.svg | 10 + .../ionicons-2.0.1/src/ios-baseball-outline.svg | 35 + .../external/ionicons-2.0.1/src/ios-baseball.svg | 27 + .../ionicons-2.0.1/src/ios-basketball-outline.svg | 25 + .../external/ionicons-2.0.1/src/ios-basketball.svg | 21 + .../ionicons-2.0.1/src/ios-bell-outline.svg | 13 + .../external/ionicons-2.0.1/src/ios-bell.svg | 11 + .../ionicons-2.0.1/src/ios-body-outline.svg | 27 + .../external/ionicons-2.0.1/src/ios-body.svg | 17 + .../ionicons-2.0.1/src/ios-bolt-outline.svg | 8 + .../external/ionicons-2.0.1/src/ios-bolt.svg | 7 + .../ionicons-2.0.1/src/ios-book-outline.svg | 13 + .../external/ionicons-2.0.1/src/ios-book.svg | 12 + .../ionicons-2.0.1/src/ios-bookmarks-outline.svg | 13 + .../external/ionicons-2.0.1/src/ios-bookmarks.svg | 13 + .../ionicons-2.0.1/src/ios-box-outline.svg | 13 + .../fusion/external/ionicons-2.0.1/src/ios-box.svg | 10 + .../ionicons-2.0.1/src/ios-briefcase-outline.svg | 11 + .../external/ionicons-2.0.1/src/ios-briefcase.svg | 13 + .../ionicons-2.0.1/src/ios-browsers-outline.svg | 12 + .../external/ionicons-2.0.1/src/ios-browsers.svg | 10 + .../ionicons-2.0.1/src/ios-calculator-outline.svg | 19 + .../external/ionicons-2.0.1/src/ios-calculator.svg | 9 + .../ionicons-2.0.1/src/ios-calendar-outline.svg | 14 + .../external/ionicons-2.0.1/src/ios-calendar.svg | 12 + .../ionicons-2.0.1/src/ios-camera-outline.svg | 17 + .../external/ionicons-2.0.1/src/ios-camera.svg | 13 + .../ionicons-2.0.1/src/ios-cart-outline.svg | 16 + .../external/ionicons-2.0.1/src/ios-cart.svg | 14 + .../ionicons-2.0.1/src/ios-chatboxes-outline.svg | 10 + .../external/ionicons-2.0.1/src/ios-chatboxes.svg | 10 + .../ionicons-2.0.1/src/ios-chatbubble-outline.svg | 14 + .../external/ionicons-2.0.1/src/ios-chatbubble.svg | 11 + .../ionicons-2.0.1/src/ios-checkmark-empty.svg | 10 + .../ionicons-2.0.1/src/ios-checkmark-outline.svg | 14 + .../external/ionicons-2.0.1/src/ios-checkmark.svg | 10 + .../ionicons-2.0.1/src/ios-circle-filled.svg | 18 + .../ionicons-2.0.1/src/ios-circle-outline.svg | 13 + .../ionicons-2.0.1/src/ios-clock-outline.svg | 12 + .../external/ionicons-2.0.1/src/ios-clock.svg | 10 + .../ionicons-2.0.1/src/ios-close-empty.svg | 13 + .../ionicons-2.0.1/src/ios-close-outline.svg | 20 + .../external/ionicons-2.0.1/src/ios-close.svg | 16 + .../src/ios-cloud-download-outline.svg | 19 + .../ionicons-2.0.1/src/ios-cloud-download.svg | 12 + .../ionicons-2.0.1/src/ios-cloud-outline.svg | 12 + .../src/ios-cloud-upload-outline.svg | 20 + .../ionicons-2.0.1/src/ios-cloud-upload.svg | 13 + .../external/ionicons-2.0.1/src/ios-cloud.svg | 9 + .../src/ios-cloudy-night-outline.svg | 24 + .../ionicons-2.0.1/src/ios-cloudy-night.svg | 21 + .../ionicons-2.0.1/src/ios-cloudy-outline.svg | 17 + .../external/ionicons-2.0.1/src/ios-cloudy.svg | 14 + .../ionicons-2.0.1/src/ios-cog-outline.svg | 29 + .../fusion/external/ionicons-2.0.1/src/ios-cog.svg | 23 + .../src/ios-color-filter-outline.svg | 25 + .../ionicons-2.0.1/src/ios-color-filter.svg | 29 + .../ionicons-2.0.1/src/ios-color-wand-outline.svg | 17 + .../external/ionicons-2.0.1/src/ios-color-wand.svg | 16 + .../ionicons-2.0.1/src/ios-compose-outline.svg | 14 + .../external/ionicons-2.0.1/src/ios-compose.svg | 13 + .../ionicons-2.0.1/src/ios-contact-outline.svg | 13 + .../external/ionicons-2.0.1/src/ios-contact.svg | 13 + .../ionicons-2.0.1/src/ios-copy-outline.svg | 11 + .../external/ionicons-2.0.1/src/ios-copy.svg | 12 + .../ionicons-2.0.1/src/ios-crop-strong.svg | 12 + .../external/ionicons-2.0.1/src/ios-crop.svg | 12 + .../ionicons-2.0.1/src/ios-download-outline.svg | 14 + .../external/ionicons-2.0.1/src/ios-download.svg | 11 + .../external/ionicons-2.0.1/src/ios-drag.svg | 11 + .../ionicons-2.0.1/src/ios-email-outline.svg | 8 + .../external/ionicons-2.0.1/src/ios-email.svg | 11 + .../ionicons-2.0.1/src/ios-eye-outline.svg | 18 + .../fusion/external/ionicons-2.0.1/src/ios-eye.svg | 13 + .../ionicons-2.0.1/src/ios-fastforward-outline.svg | 8 + .../ionicons-2.0.1/src/ios-fastforward.svg | 7 + .../ionicons-2.0.1/src/ios-filing-outline.svg | 9 + .../external/ionicons-2.0.1/src/ios-filing.svg | 11 + .../ionicons-2.0.1/src/ios-film-outline.svg | 9 + .../external/ionicons-2.0.1/src/ios-film.svg | 11 + .../ionicons-2.0.1/src/ios-flag-outline.svg | 13 + .../external/ionicons-2.0.1/src/ios-flag.svg | 11 + .../ionicons-2.0.1/src/ios-flame-outline.svg | 14 + .../external/ionicons-2.0.1/src/ios-flame.svg | 11 + .../ionicons-2.0.1/src/ios-flask-outline.svg | 19 + .../external/ionicons-2.0.1/src/ios-flask.svg | 17 + .../ionicons-2.0.1/src/ios-flower-outline.svg | 75 + .../external/ionicons-2.0.1/src/ios-flower.svg | 38 + .../ionicons-2.0.1/src/ios-folder-outline.svg | 11 + .../external/ionicons-2.0.1/src/ios-folder.svg | 13 + .../ionicons-2.0.1/src/ios-football-outline.svg | 20 + .../external/ionicons-2.0.1/src/ios-football.svg | 14 + .../src/ios-game-controller-a-outline.svg | 26 + .../ionicons-2.0.1/src/ios-game-controller-a.svg | 19 + .../src/ios-game-controller-b-outline.svg | 35 + .../ionicons-2.0.1/src/ios-game-controller-b.svg | 23 + .../ionicons-2.0.1/src/ios-gear-outline.svg | 40 + .../external/ionicons-2.0.1/src/ios-gear.svg | 17 + .../ionicons-2.0.1/src/ios-glasses-outline.svg | 12 + .../external/ionicons-2.0.1/src/ios-glasses.svg | 11 + .../ionicons-2.0.1/src/ios-grid-view-outline.svg | 8 + .../external/ionicons-2.0.1/src/ios-grid-view.svg | 11 + .../ionicons-2.0.1/src/ios-heart-outline.svg | 15 + .../external/ionicons-2.0.1/src/ios-heart.svg | 9 + .../external/ionicons-2.0.1/src/ios-help-empty.svg | 12 + .../ionicons-2.0.1/src/ios-help-outline.svg | 22 + .../external/ionicons-2.0.1/src/ios-help.svg | 12 + .../ionicons-2.0.1/src/ios-home-outline.svg | 11 + .../external/ionicons-2.0.1/src/ios-home.svg | 10 + .../ionicons-2.0.1/src/ios-infinite-outline.svg | 17 + .../external/ionicons-2.0.1/src/ios-infinite.svg | 16 + .../ionicons-2.0.1/src/ios-information-empty.svg | 12 + .../ionicons-2.0.1/src/ios-information-outline.svg | 17 + .../ionicons-2.0.1/src/ios-information.svg | 11 + .../ionicons-2.0.1/src/ios-ionic-outline.svg | 18 + .../ionicons-2.0.1/src/ios-keypad-outline.svg | 28 + .../external/ionicons-2.0.1/src/ios-keypad.svg | 20 + .../ionicons-2.0.1/src/ios-lightbulb-outline.svg | 17 + .../external/ionicons-2.0.1/src/ios-lightbulb.svg | 16 + .../ionicons-2.0.1/src/ios-list-outline.svg | 23 + .../external/ionicons-2.0.1/src/ios-list.svg | 11 + .../ionicons-2.0.1/src/ios-location-outline.svg | 14 + .../external/ionicons-2.0.1/src/ios-location.svg | 8 + .../ionicons-2.0.1/src/ios-locked-outline.svg | 14 + .../external/ionicons-2.0.1/src/ios-locked.svg | 12 + .../ionicons-2.0.1/src/ios-loop-strong.svg | 18 + .../external/ionicons-2.0.1/src/ios-loop.svg | 22 + .../ionicons-2.0.1/src/ios-medical-outline.svg | 10 + .../external/ionicons-2.0.1/src/ios-medical.svg | 8 + .../ionicons-2.0.1/src/ios-medkit-outline.svg | 14 + .../external/ionicons-2.0.1/src/ios-medkit.svg | 13 + .../external/ionicons-2.0.1/src/ios-mic-off.svg | 14 + .../ionicons-2.0.1/src/ios-mic-outline.svg | 12 + .../fusion/external/ionicons-2.0.1/src/ios-mic.svg | 12 + .../ionicons-2.0.1/src/ios-minus-empty.svg | 9 + .../ionicons-2.0.1/src/ios-minus-outline.svg | 16 + .../external/ionicons-2.0.1/src/ios-minus.svg | 10 + .../ionicons-2.0.1/src/ios-monitor-outline.svg | 7 + .../external/ionicons-2.0.1/src/ios-monitor.svg | 10 + .../ionicons-2.0.1/src/ios-moon-outline.svg | 15 + .../external/ionicons-2.0.1/src/ios-moon.svg | 13 + .../ionicons-2.0.1/src/ios-more-outline.svg | 14 + .../external/ionicons-2.0.1/src/ios-more.svg | 11 + .../ionicons-2.0.1/src/ios-musical-note.svg | 9 + .../ionicons-2.0.1/src/ios-musical-notes.svg | 9 + .../ionicons-2.0.1/src/ios-navigate-outline.svg | 12 + .../external/ionicons-2.0.1/src/ios-navigate.svg | 10 + .../ionicons-2.0.1/src/ios-nutrition-outline.svg | 29 + .../external/ionicons-2.0.1/src/ios-nutrition.svg | 17 + .../ionicons-2.0.1/src/ios-paper-outline.svg | 14 + .../external/ionicons-2.0.1/src/ios-paper.svg | 8 + .../ionicons-2.0.1/src/ios-paperplane-outline.svg | 8 + .../external/ionicons-2.0.1/src/ios-paperplane.svg | 10 + .../ionicons-2.0.1/src/ios-partlysunny-outline.svg | 33 + .../ionicons-2.0.1/src/ios-partlysunny.svg | 28 + .../ionicons-2.0.1/src/ios-pause-outline.svg | 10 + .../external/ionicons-2.0.1/src/ios-pause.svg | 10 + .../ionicons-2.0.1/src/ios-paw-outline.svg | 43 + .../fusion/external/ionicons-2.0.1/src/ios-paw.svg | 26 + .../ionicons-2.0.1/src/ios-people-outline.svg | 44 + .../external/ionicons-2.0.1/src/ios-people.svg | 29 + .../ionicons-2.0.1/src/ios-person-outline.svg | 22 + .../external/ionicons-2.0.1/src/ios-person.svg | 13 + .../ionicons-2.0.1/src/ios-personadd-outline.svg | 25 + .../external/ionicons-2.0.1/src/ios-personadd.svg | 16 + .../ionicons-2.0.1/src/ios-photos-outline.svg | 10 + .../external/ionicons-2.0.1/src/ios-photos.svg | 10 + .../ionicons-2.0.1/src/ios-pie-outline.svg | 16 + .../fusion/external/ionicons-2.0.1/src/ios-pie.svg | 11 + .../ionicons-2.0.1/src/ios-pint-outline.svg | 17 + .../external/ionicons-2.0.1/src/ios-pint.svg | 12 + .../ionicons-2.0.1/src/ios-play-outline.svg | 9 + .../external/ionicons-2.0.1/src/ios-play.svg | 9 + .../external/ionicons-2.0.1/src/ios-plus-empty.svg | 9 + .../ionicons-2.0.1/src/ios-plus-outline.svg | 18 + .../external/ionicons-2.0.1/src/ios-plus.svg | 10 + .../ionicons-2.0.1/src/ios-pricetag-outline.svg | 11 + .../external/ionicons-2.0.1/src/ios-pricetag.svg | 11 + .../ionicons-2.0.1/src/ios-pricetags-outline.svg | 12 + .../external/ionicons-2.0.1/src/ios-pricetags.svg | 16 + .../ionicons-2.0.1/src/ios-printer-outline.svg | 12 + .../external/ionicons-2.0.1/src/ios-printer.svg | 17 + .../ionicons-2.0.1/src/ios-pulse-strong.svg | 12 + .../external/ionicons-2.0.1/src/ios-pulse.svg | 12 + .../ionicons-2.0.1/src/ios-rainy-outline.svg | 20 + .../external/ionicons-2.0.1/src/ios-rainy.svg | 17 + .../ionicons-2.0.1/src/ios-recording-outline.svg | 15 + .../external/ionicons-2.0.1/src/ios-recording.svg | 14 + .../ionicons-2.0.1/src/ios-redo-outline.svg | 11 + .../external/ionicons-2.0.1/src/ios-redo.svg | 10 + .../ionicons-2.0.1/src/ios-refresh-empty.svg | 10 + .../ionicons-2.0.1/src/ios-refresh-outline.svg | 15 + .../external/ionicons-2.0.1/src/ios-refresh.svg | 11 + .../external/ionicons-2.0.1/src/ios-reload.svg | 11 + .../src/ios-reverse-camera-outline.svg | 20 + .../ionicons-2.0.1/src/ios-reverse-camera.svg | 15 + .../ionicons-2.0.1/src/ios-rewind-outline.svg | 8 + .../external/ionicons-2.0.1/src/ios-rewind.svg | 7 + .../ionicons-2.0.1/src/ios-rose-outline.svg | 29 + .../external/ionicons-2.0.1/src/ios-rose.svg | 18 + .../ionicons-2.0.1/src/ios-search-strong.svg | 10 + .../external/ionicons-2.0.1/src/ios-search.svg | 10 + .../ionicons-2.0.1/src/ios-settings-strong.svg | 14 + .../external/ionicons-2.0.1/src/ios-settings.svg | 24 + .../ionicons-2.0.1/src/ios-shuffle-strong.svg | 18 + .../external/ionicons-2.0.1/src/ios-shuffle.svg | 20 + .../src/ios-skipbackward-outline.svg | 8 + .../ionicons-2.0.1/src/ios-skipbackward.svg | 7 + .../ionicons-2.0.1/src/ios-skipforward-outline.svg | 8 + .../ionicons-2.0.1/src/ios-skipforward.svg | 7 + .../external/ionicons-2.0.1/src/ios-snowy.svg | 26 + .../ionicons-2.0.1/src/ios-speedometer-outline.svg | 24 + .../ionicons-2.0.1/src/ios-speedometer.svg | 28 + .../external/ionicons-2.0.1/src/ios-star-half.svg | 8 + .../ionicons-2.0.1/src/ios-star-outline.svg | 8 + .../external/ionicons-2.0.1/src/ios-star.svg | 7 + .../ionicons-2.0.1/src/ios-stopwatch-outline.svg | 15 + .../external/ionicons-2.0.1/src/ios-stopwatch.svg | 13 + .../ionicons-2.0.1/src/ios-sunny-outline.svg | 27 + .../external/ionicons-2.0.1/src/ios-sunny.svg | 26 + .../ionicons-2.0.1/src/ios-telephone-outline.svg | 17 + .../external/ionicons-2.0.1/src/ios-telephone.svg | 12 + .../ionicons-2.0.1/src/ios-tennisball-outline.svg | 19 + .../external/ionicons-2.0.1/src/ios-tennisball.svg | 25 + .../src/ios-thunderstorm-outline.svg | 22 + .../ionicons-2.0.1/src/ios-thunderstorm.svg | 17 + .../ionicons-2.0.1/src/ios-time-outline.svg | 36 + .../external/ionicons-2.0.1/src/ios-time.svg | 27 + .../ionicons-2.0.1/src/ios-timer-outline.svg | 11 + .../external/ionicons-2.0.1/src/ios-timer.svg | 12 + .../ionicons-2.0.1/src/ios-toggle-outline.svg | 22 + .../external/ionicons-2.0.1/src/ios-toggle.svg | 16 + .../ionicons-2.0.1/src/ios-trash-outline.svg | 17 + .../external/ionicons-2.0.1/src/ios-trash.svg | 12 + .../ionicons-2.0.1/src/ios-undo-outline.svg | 11 + .../external/ionicons-2.0.1/src/ios-undo.svg | 10 + .../ionicons-2.0.1/src/ios-unlocked-outline.svg | 14 + .../external/ionicons-2.0.1/src/ios-unlocked.svg | 12 + .../ionicons-2.0.1/src/ios-upload-outline.svg | 14 + .../external/ionicons-2.0.1/src/ios-upload.svg | 10 + .../ionicons-2.0.1/src/ios-videocam-outline.svg | 12 + .../external/ionicons-2.0.1/src/ios-videocam.svg | 11 + .../ionicons-2.0.1/src/ios-volume-high.svg | 19 + .../external/ionicons-2.0.1/src/ios-volume-low.svg | 7 + .../ionicons-2.0.1/src/ios-wineglass-outline.svg | 15 + .../external/ionicons-2.0.1/src/ios-wineglass.svg | 11 + .../ionicons-2.0.1/src/ios-world-outline.svg | 22 + .../external/ionicons-2.0.1/src/ios-world.svg | 29 + .../fusion/external/ionicons-2.0.1/src/ipad.svg | 10 + .../fusion/external/ionicons-2.0.1/src/iphone.svg | 13 + .../fusion/external/ionicons-2.0.1/src/ipod.svg | 13 + .../app/fusion/external/ionicons-2.0.1/src/jet.svg | 14 + .../app/fusion/external/ionicons-2.0.1/src/key.svg | 14 + .../fusion/external/ionicons-2.0.1/src/knife.svg | 9 + .../fusion/external/ionicons-2.0.1/src/laptop.svg | 10 + .../fusion/external/ionicons-2.0.1/src/leaf.svg | 12 + .../fusion/external/ionicons-2.0.1/src/levels.svg | 16 + .../external/ionicons-2.0.1/src/lightbulb.svg | 21 + .../fusion/external/ionicons-2.0.1/src/link.svg | 15 + .../fusion/external/ionicons-2.0.1/src/load-a.svg | 17 + .../fusion/external/ionicons-2.0.1/src/load-b.svg | 20 + .../fusion/external/ionicons-2.0.1/src/load-c.svg | 21 + .../fusion/external/ionicons-2.0.1/src/load-d.svg | 28 + .../external/ionicons-2.0.1/src/location.svg | 11 + .../ionicons-2.0.1/src/lock-combination.svg | 28 + .../fusion/external/ionicons-2.0.1/src/locked.svg | 11 + .../fusion/external/ionicons-2.0.1/src/log-in.svg | 14 + .../fusion/external/ionicons-2.0.1/src/log-out.svg | 17 + .../fusion/external/ionicons-2.0.1/src/loop.svg | 14 + .../fusion/external/ionicons-2.0.1/src/magnet.svg | 14 + .../fusion/external/ionicons-2.0.1/src/male.svg | 10 + .../app/fusion/external/ionicons-2.0.1/src/man.svg | 12 + .../app/fusion/external/ionicons-2.0.1/src/map.svg | 30 + .../fusion/external/ionicons-2.0.1/src/medkit.svg | 12 + .../fusion/external/ionicons-2.0.1/src/merge.svg | 13 + .../fusion/external/ionicons-2.0.1/src/mic-a.svg | 15 + .../fusion/external/ionicons-2.0.1/src/mic-b.svg | 17 + .../fusion/external/ionicons-2.0.1/src/mic-c.svg | 8 + .../external/ionicons-2.0.1/src/minus-circled.svg | 9 + .../external/ionicons-2.0.1/src/minus-round.svg | 8 + .../fusion/external/ionicons-2.0.1/src/minus.svg | 7 + .../fusion/external/ionicons-2.0.1/src/model-s.svg | 33 + .../fusion/external/ionicons-2.0.1/src/monitor.svg | 12 + .../fusion/external/ionicons-2.0.1/src/more.svg | 12 + .../fusion/external/ionicons-2.0.1/src/mouse.svg | 24 + .../external/ionicons-2.0.1/src/music-note.svg | 10 + .../external/ionicons-2.0.1/src/navicon-round.svg | 14 + .../fusion/external/ionicons-2.0.1/src/navicon.svg | 11 + .../external/ionicons-2.0.1/src/navigate.svg | 7 + .../fusion/external/ionicons-2.0.1/src/network.svg | 12 + .../external/ionicons-2.0.1/src/no-smoking.svg | 33 + .../fusion/external/ionicons-2.0.1/src/nuclear.svg | 18 + .../fusion/external/ionicons-2.0.1/src/outlet.svg | 16 + .../external/ionicons-2.0.1/src/paintbrush.svg | 18 + .../external/ionicons-2.0.1/src/paintbucket.svg | 12 + .../external/ionicons-2.0.1/src/paper-airplane.svg | 13 + .../external/ionicons-2.0.1/src/paperclip.svg | 13 + .../fusion/external/ionicons-2.0.1/src/pause.svg | 12 + .../external/ionicons-2.0.1/src/person-add.svg | 13 + .../external/ionicons-2.0.1/src/person-stalker.svg | 18 + .../fusion/external/ionicons-2.0.1/src/person.svg | 10 + .../external/ionicons-2.0.1/src/pie-graph.svg | 11 + .../app/fusion/external/ionicons-2.0.1/src/pin.svg | 11 + .../external/ionicons-2.0.1/src/pinpoint.svg | 11 + .../fusion/external/ionicons-2.0.1/src/pizza.svg | 20 + .../fusion/external/ionicons-2.0.1/src/plane.svg | 10 + .../fusion/external/ionicons-2.0.1/src/planet.svg | 21 + .../fusion/external/ionicons-2.0.1/src/play.svg | 8 + .../external/ionicons-2.0.1/src/playstation.svg | 27 + .../external/ionicons-2.0.1/src/plus-circled.svg | 10 + .../external/ionicons-2.0.1/src/plus-round.svg | 9 + .../fusion/external/ionicons-2.0.1/src/plus.svg | 7 + .../fusion/external/ionicons-2.0.1/src/podium.svg | 11 + .../fusion/external/ionicons-2.0.1/src/pound.svg | 11 + .../fusion/external/ionicons-2.0.1/src/power.svg | 15 + .../external/ionicons-2.0.1/src/pricetag.svg | 13 + .../external/ionicons-2.0.1/src/pricetags.svg | 18 + .../fusion/external/ionicons-2.0.1/src/printer.svg | 14 + .../external/ionicons-2.0.1/src/pull-request.svg | 16 + .../external/ionicons-2.0.1/src/qr-scanner.svg | 12 + .../fusion/external/ionicons-2.0.1/src/quote.svg | 16 + .../external/ionicons-2.0.1/src/radio-waves.svg | 25 + .../fusion/external/ionicons-2.0.1/src/record.svg | 7 + .../fusion/external/ionicons-2.0.1/src/refresh.svg | 15 + .../external/ionicons-2.0.1/src/reply-all.svg | 12 + .../fusion/external/ionicons-2.0.1/src/reply.svg | 9 + .../external/ionicons-2.0.1/src/ribbon-a.svg | 14 + .../external/ionicons-2.0.1/src/ribbon-b.svg | 18 + .../external/ionicons-2.0.1/src/sad-outline.svg | 28 + .../app/fusion/external/ionicons-2.0.1/src/sad.svg | 20 + .../external/ionicons-2.0.1/src/scissors.svg | 23 + .../fusion/external/ionicons-2.0.1/src/search.svg | 10 + .../external/ionicons-2.0.1/src/settings.svg | 18 + .../fusion/external/ionicons-2.0.1/src/share.svg | 11 + .../fusion/external/ionicons-2.0.1/src/shuffle.svg | 11 + .../external/ionicons-2.0.1/src/skip-backward.svg | 15 + .../external/ionicons-2.0.1/src/skip-forward.svg | 15 + .../ionicons-2.0.1/src/social-android-outline.svg | 29 + .../external/ionicons-2.0.1/src/social-android.svg | 22 + .../ionicons-2.0.1/src/social-angular-outline.svg | 11 + .../external/ionicons-2.0.1/src/social-angular.svg | 11 + .../ionicons-2.0.1/src/social-apple-outline.svg | 20 + .../external/ionicons-2.0.1/src/social-apple.svg | 14 + .../ionicons-2.0.1/src/social-bitcoin-outline.svg | 27 + .../external/ionicons-2.0.1/src/social-bitcoin.svg | 14 + .../ionicons-2.0.1/src/social-buffer-outline.svg | 24 + .../external/ionicons-2.0.1/src/social-buffer.svg | 18 + .../ionicons-2.0.1/src/social-chrome-outline.svg | 17 + .../external/ionicons-2.0.1/src/social-chrome.svg | 22 + .../ionicons-2.0.1/src/social-codepen-outline.svg | 26 + .../external/ionicons-2.0.1/src/social-codepen.svg | 26 + .../ionicons-2.0.1/src/social-css3-outline.svg | 12 + .../external/ionicons-2.0.1/src/social-css3.svg | 14 + .../src/social-designernews-outline.svg | 18 + .../ionicons-2.0.1/src/social-designernews.svg | 18 + .../ionicons-2.0.1/src/social-dribbble-outline.svg | 15 + .../ionicons-2.0.1/src/social-dribbble.svg | 26 + .../ionicons-2.0.1/src/social-dropbox-outline.svg | 13 + .../external/ionicons-2.0.1/src/social-dropbox.svg | 13 + .../ionicons-2.0.1/src/social-euro-outline.svg | 19 + .../external/ionicons-2.0.1/src/social-euro.svg | 12 + .../ionicons-2.0.1/src/social-facebook-outline.svg | 9 + .../ionicons-2.0.1/src/social-facebook.svg | 8 + .../src/social-foursquare-outline.svg | 22 + .../ionicons-2.0.1/src/social-foursquare.svg | 20 + .../ionicons-2.0.1/src/social-freebsd-devil.svg | 22 + .../ionicons-2.0.1/src/social-github-outline.svg | 24 + .../external/ionicons-2.0.1/src/social-github.svg | 14 + .../ionicons-2.0.1/src/social-google-outline.svg | 19 + .../external/ionicons-2.0.1/src/social-google.svg | 20 + .../src/social-googleplus-outline.svg | 18 + .../ionicons-2.0.1/src/social-googleplus.svg | 17 + .../src/social-hackernews-outline.svg | 12 + .../ionicons-2.0.1/src/social-hackernews.svg | 9 + .../ionicons-2.0.1/src/social-html5-outline.svg | 13 + .../external/ionicons-2.0.1/src/social-html5.svg | 9 + .../src/social-instagram-outline.svg | 12 + .../ionicons-2.0.1/src/social-instagram.svg | 18 + .../src/social-javascript-outline.svg | 27 + .../ionicons-2.0.1/src/social-javascript.svg | 17 + .../ionicons-2.0.1/src/social-linkedin-outline.svg | 22 + .../ionicons-2.0.1/src/social-linkedin.svg | 13 + .../ionicons-2.0.1/src/social-markdown.svg | 14 + .../external/ionicons-2.0.1/src/social-nodejs.svg | 26 + .../external/ionicons-2.0.1/src/social-octocat.svg | 28 + .../src/social-pinterest-outline.svg | 14 + .../ionicons-2.0.1/src/social-pinterest.svg | 15 + .../external/ionicons-2.0.1/src/social-python.svg | 21 + .../ionicons-2.0.1/src/social-reddit-outline.svg | 26 + .../external/ionicons-2.0.1/src/social-reddit.svg | 18 + .../ionicons-2.0.1/src/social-rss-outline.svg | 16 + .../external/ionicons-2.0.1/src/social-rss.svg | 12 + .../external/ionicons-2.0.1/src/social-sass.svg | 35 + .../ionicons-2.0.1/src/social-skype-outline.svg | 26 + .../external/ionicons-2.0.1/src/social-skype.svg | 20 + .../ionicons-2.0.1/src/social-snapchat-outline.svg | 42 + .../ionicons-2.0.1/src/social-snapchat.svg | 31 + .../ionicons-2.0.1/src/social-tumblr-outline.svg | 13 + .../external/ionicons-2.0.1/src/social-tumblr.svg | 10 + .../external/ionicons-2.0.1/src/social-tux.svg | 53 + .../ionicons-2.0.1/src/social-twitch-outline.svg | 13 + .../external/ionicons-2.0.1/src/social-twitch.svg | 9 + .../ionicons-2.0.1/src/social-twitter-outline.svg | 19 + .../external/ionicons-2.0.1/src/social-twitter.svg | 12 + .../ionicons-2.0.1/src/social-usd-outline.svg | 44 + .../external/ionicons-2.0.1/src/social-usd.svg | 24 + .../ionicons-2.0.1/src/social-vimeo-outline.svg | 23 + .../external/ionicons-2.0.1/src/social-vimeo.svg | 18 + .../ionicons-2.0.1/src/social-whatsapp-outline.svg | 25 + .../ionicons-2.0.1/src/social-whatsapp.svg | 18 + .../ionicons-2.0.1/src/social-windows-outline.svg | 17 + .../external/ionicons-2.0.1/src/social-windows.svg | 17 + .../src/social-wordpress-outline.svg | 16 + .../ionicons-2.0.1/src/social-wordpress.svg | 20 + .../ionicons-2.0.1/src/social-yahoo-outline.svg | 10 + .../external/ionicons-2.0.1/src/social-yahoo.svg | 8 + .../ionicons-2.0.1/src/social-yen-outline.svg | 9 + .../external/ionicons-2.0.1/src/social-yen.svg | 8 + .../ionicons-2.0.1/src/social-youtube-outline.svg | 22 + .../external/ionicons-2.0.1/src/social-youtube.svg | 12 + .../ionicons-2.0.1/src/soup-can-outline.svg | 28 + .../external/ionicons-2.0.1/src/soup-can.svg | 16 + .../external/ionicons-2.0.1/src/speakerphone.svg | 19 + .../external/ionicons-2.0.1/src/speedometer.svg | 15 + .../fusion/external/ionicons-2.0.1/src/spoon.svg | 10 + .../fusion/external/ionicons-2.0.1/src/star.svg | 7 + .../external/ionicons-2.0.1/src/stats-bars.svg | 12 + .../fusion/external/ionicons-2.0.1/src/steam.svg | 20 + .../fusion/external/ionicons-2.0.1/src/stop.svg | 8 + .../external/ionicons-2.0.1/src/thermometer.svg | 11 + .../external/ionicons-2.0.1/src/thumbsdown.svg | 13 + .../external/ionicons-2.0.1/src/thumbsup.svg | 13 + .../external/ionicons-2.0.1/src/toggle-filled.svg | 11 + .../fusion/external/ionicons-2.0.1/src/toggle.svg | 12 + .../external/ionicons-2.0.1/src/transgender.svg | 12 + .../fusion/external/ionicons-2.0.1/src/trash-a.svg | 10 + .../fusion/external/ionicons-2.0.1/src/trash-b.svg | 13 + .../fusion/external/ionicons-2.0.1/src/trophy.svg | 16 + .../external/ionicons-2.0.1/src/tshirt-outline.svg | 11 + .../fusion/external/ionicons-2.0.1/src/tshirt.svg | 8 + .../external/ionicons-2.0.1/src/umbrella.svg | 18 + .../external/ionicons-2.0.1/src/university.svg | 11 + .../external/ionicons-2.0.1/src/unlocked.svg | 10 + .../fusion/external/ionicons-2.0.1/src/upload.svg | 9 + .../app/fusion/external/ionicons-2.0.1/src/usb.svg | 22 + .../external/ionicons-2.0.1/src/videocamera.svg | 11 + .../external/ionicons-2.0.1/src/volume-high.svg | 15 + .../external/ionicons-2.0.1/src/volume-low.svg | 11 + .../external/ionicons-2.0.1/src/volume-medium.svg | 13 + .../external/ionicons-2.0.1/src/volume-mute.svg | 14 + .../fusion/external/ionicons-2.0.1/src/wand.svg | 17 + .../external/ionicons-2.0.1/src/waterdrop.svg | 11 + .../fusion/external/ionicons-2.0.1/src/wifi.svg | 16 + .../external/ionicons-2.0.1/src/wineglass.svg | 21 + .../fusion/external/ionicons-2.0.1/src/woman.svg | 13 + .../fusion/external/ionicons-2.0.1/src/wrench.svg | 11 + .../fusion/external/ionicons-2.0.1/src/xbox.svg | 21 + .../fusion/external/samples/css/images/blank.gif | Bin 0 -> 49 bytes .../app/fusion/external/samples/css/scribble.css | 40 + .../app/fusion/external/samples/css/slider.css | 142 + .../fusion/external/samples/css/spacegallery.css | 18 + .../fusion/external/samples/html/area_chart.html | 49 + .../fusion/external/samples/html/bar_chart.html | 95 + .../external/samples/html/d3_gauges_demo.html | 39 + .../external/samples/html/data/speedometer2.csv | 16 + .../external/samples/html/data/speedometer3.csv | 2 + .../fusion/external/samples/html/data/worddata.csv | 22 + .../app/fusion/external/samples/html/donut_d3.html | 43 + .../external/samples/html/js/area_chart.min.js | 1 + .../fusion/external/samples/html/js/donut.min.js | 1 + .../fusion/external/samples/html/js/gauges.min.js | 1 + .../external/samples/html/js/line_chart.min.js | 1 + .../external/samples/html/js/pie_chart.min.js | 1 + .../external/samples/html/js/worddata.min.js | 1 + .../fusion/external/samples/html/line_chart.html | 49 + .../fusion/external/samples/html/pie_chart.html | 38 + .../fusion/external/samples/html/wordcloud.html | 37 + .../external/samples/images/Calendar-16x16.png | Bin 0 -> 552 bytes .../fusion/external/samples/images/arrow-next.png | Bin 0 -> 1561 bytes .../fusion/external/samples/images/arrow-prev.png | Bin 0 -> 1557 bytes .../images/carousel/slide_b_drive_test_map.png | Bin 0 -> 202465 bytes .../images/carousel/slide_b_eppt_county.png | Bin 0 -> 21222 bytes .../images/carousel/slide_b_eppt_regression.png | Bin 0 -> 11536 bytes .../images/carousel/slide_b_ios_throughput.png | Bin 0 -> 26131 bytes .../samples/images/carousel/slide_b_lata_map.png | Bin 0 -> 192031 bytes .../images/carousel/slide_b_lata_map_legend.png | Bin 0 -> 3021 bytes .../images/carousel/slide_b_nova_sdn_map.png | Bin 0 -> 179361 bytes .../fusion/external/samples/images/copyicon.png | Bin 0 -> 235 bytes .../fusion/external/samples/images/deleteicon.gif | Bin 0 -> 579 bytes .../external/samples/images/example-frame.png | Bin 0 -> 33699 bytes .../app/fusion/external/samples/images/loading.gif | Bin 0 -> 6820 bytes .../external/samples/images/tunnels/1_mon.png | Bin 0 -> 22762 bytes .../external/samples/images/tunnels/2_tue.png | Bin 0 -> 22772 bytes .../external/samples/images/tunnels/3_wed.png | Bin 0 -> 24012 bytes .../external/samples/images/tunnels/4_thu.png | Bin 0 -> 23902 bytes .../external/samples/images/tunnels/5_fri.png | Bin 0 -> 22349 bytes .../external/samples/images/tunnels/6_sat.png | Bin 0 -> 23674 bytes .../external/samples/images/tunnels/7_sun.png | Bin 0 -> 22845 bytes .../samples/images/tunnels/BH_DLSTX_IN.png | Bin 0 -> 10575 bytes .../samples/images/tunnels/BH_DLSTX_OUT.png | Bin 0 -> 10460 bytes .../external/samples/images/tunnels/BH_Nat.png | Bin 0 -> 10420 bytes .../external/samples/images/tunnels/BH_Nat_Def.png | Bin 0 -> 8941 bytes .../samples/images/tunnels/BH_Nat_Priority.png | Bin 0 -> 10590 bytes .../app/fusion/external/samples/js/FusionCharts.js | 361 + .../app/fusion/external/samples/js/charts.js | 132 + .../app/fusion/external/samples/js/scribble.js | 19 + .../external/samples/js/slides.min.jquery.js | 20 + .../app/fusion/external/samples/js/spacegallery.js | 235 + .../samples/org_chart/css/bootstrap.min.css | 351 + .../external/samples/org_chart/css/custom.css | 97 + .../samples/org_chart/css/jquery.jOrgChart.css | 51 + .../external/samples/org_chart/css/prettify.css | 1 + .../fusion/external/samples/org_chart/example.html | 85 + .../external/samples/org_chart/example_vsp.html | 88 + .../external/samples/org_chart/images/bkgd.png | Bin 0 -> 133 bytes .../samples/org_chart/images/raspberry.jpg | Bin 0 -> 5755 bytes .../external/samples/org_chart/jquery.jOrgChart.js | 267 + .../fusion/external/samples/org_chart/prettify.js | 28 + .../app/fusion/external/utils/js/browserCheck.js | 24 + .../src/main/webapp/app/fusion/images/Rlogo.jpg | Bin 0 -> 3173 bytes .../src/main/webapp/app/fusion/images/Thumbs.db | Bin 0 -> 102912 bytes .../main/webapp/app/fusion/images/action_icon.png | Bin 0 -> 2388 bytes .../app/fusion/images/action_list_spacer.gif | Bin 0 -> 73 bytes .../src/main/webapp/app/fusion/images/active.png | Bin 0 -> 682 bytes .../src/main/webapp/app/fusion/images/add.png | Bin 0 -> 352 bytes .../webapp/app/fusion/images/add_tool_button.png | Bin 0 -> 31105 bytes .../src/main/webapp/app/fusion/images/addicon.png | Bin 0 -> 463 bytes .../app/fusion/images/application_window_bg.jpg | Bin 0 -> 914 bytes .../main/webapp/app/fusion/images/arrow-next.png | Bin 0 -> 1561 bytes .../main/webapp/app/fusion/images/arrow-prev.png | Bin 0 -> 1557 bytes .../fusion/images/att_angular_gridster/grips.png | Bin 0 -> 951 bytes .../main/webapp/app/fusion/images/backButton.png | Bin 0 -> 816 bytes .../src/main/webapp/app/fusion/images/blank.gif | Bin 0 -> 49 bytes .../main/webapp/app/fusion/images/blueButton.png | Bin 0 -> 1468 bytes .../main/webapp/app/fusion/images/body_graphic.jpg | Bin 0 -> 20667 bytes .../src/main/webapp/app/fusion/images/bubble.png | Bin 0 -> 662 bytes .../src/main/webapp/app/fusion/images/cache.png | Bin 0 -> 1081 bytes .../src/main/webapp/app/fusion/images/calendar.gif | Bin 0 -> 929 bytes .../src/main/webapp/app/fusion/images/chevron.png | Bin 0 -> 252 bytes .../webapp/app/fusion/images/close_container.gif | Bin 0 -> 85 bytes .../webapp/app/fusion/images/collapsed-icon.png | Bin 0 -> 1379 bytes .../main/webapp/app/fusion/images/column-bg.png | Bin 0 -> 165 bytes .../app/fusion/images/copyicon-highlighted.png | Bin 0 -> 264 bytes .../src/main/webapp/app/fusion/images/copyicon.png | Bin 0 -> 235 bytes .../src/main/webapp/app/fusion/images/csv_icon.jpg | Bin 0 -> 632 bytes .../src/main/webapp/app/fusion/images/csv_icon.png | Bin 0 -> 938 bytes .../webapp/app/fusion/images/customers-add.png | Bin 0 -> 755 bytes .../webapp/app/fusion/images/customers-search.png | Bin 0 -> 976 bytes .../main/webapp/app/fusion/images/customers.png | Bin 0 -> 749 bytes .../main/webapp/app/fusion/images/decrypted.png | Bin 0 -> 628 bytes .../app/fusion/images/deleteicon-highlighted.gif | Bin 0 -> 592 bytes .../app/fusion/images/deleteicon-highlighted.png | Bin 0 -> 566 bytes .../main/webapp/app/fusion/images/deleteicon.gif | Bin 0 -> 579 bytes .../src/main/webapp/app/fusion/images/editicon.gif | Bin 0 -> 360 bytes .../main/webapp/app/fusion/images/error_type.gif | Bin 0 -> 398 bytes .../webapp/app/fusion/images/example-frame.png | Bin 0 -> 33699 bytes .../webapp/app/fusion/images/excelicon_multi.gif | Bin 0 -> 1028 bytes .../main/webapp/app/fusion/images/executeicon.png | Bin 0 -> 1076 bytes .../webapp/app/fusion/images/expanded-icon.png | Bin 0 -> 1372 bytes .../src/main/webapp/app/fusion/images/file-add.png | Bin 0 -> 675 bytes .../main/webapp/app/fusion/images/file_import.png | Bin 0 -> 653 bytes .../webapp/app/fusion/images/file_save-all.png | Bin 0 -> 610 bytes .../main/webapp/app/fusion/images/filter_icon.png | Bin 0 -> 29069 bytes .../main/webapp/app/fusion/images/folder_add.png | Bin 0 -> 772 bytes .../webapp/app/fusion/images/folder_closed.png | Bin 0 -> 559 bytes .../webapp/app/fusion/images/folder_delete.png | Bin 0 -> 767 bytes .../main/webapp/app/fusion/images/folder_edit.png | Bin 0 -> 829 bytes .../main/webapp/app/fusion/images/folder_open.png | Bin 0 -> 632 bytes .../main/webapp/app/fusion/images/folder_user.png | Bin 0 -> 887 bytes .../src/main/webapp/app/fusion/images/funnel.png | Bin 0 -> 543 bytes .../src/main/webapp/app/fusion/images/fusion.gif | Bin 0 -> 8821 bytes .../main/webapp/app/fusion/images/grayButton.png | Bin 0 -> 1361 bytes .../app/fusion/images/gray_add_tool_button.png | Bin 0 -> 30883 bytes .../webapp/app/fusion/images/headerChatIcon.png | Bin 0 -> 465 bytes .../webapp/app/fusion/images/icon_remove_all.gif | Bin 0 -> 982 bytes .../src/main/webapp/app/fusion/images/inactive.png | Bin 0 -> 842 bytes .../main/webapp/app/fusion/images/info_type.gif | Bin 0 -> 291 bytes .../app/fusion/images/layout/panel-e-w-toggle.png | Bin 0 -> 459 bytes .../app/fusion/images/layout/panel-n-s-toggle.png | Bin 0 -> 335 bytes .../main/webapp/app/fusion/images/leftButton.png | Bin 0 -> 681 bytes .../src/main/webapp/app/fusion/images/loading.gif | Bin 0 -> 6820 bytes .../main/webapp/app/fusion/images/loading_bar.gif | Bin 0 -> 28954 bytes .../main/webapp/app/fusion/images/login_button.gif | Bin 0 -> 1222 bytes .../src/main/webapp/app/fusion/images/m1.gif | Bin 0 -> 636 bytes .../src/main/webapp/app/fusion/images/mail.png | Bin 0 -> 449 bytes .../src/main/webapp/app/fusion/images/map.png | Bin 0 -> 611 bytes .../main/webapp/app/fusion/images/menu/bubble.png | Bin 0 -> 662 bytes .../webapp/app/fusion/images/menu/file_import.png | Bin 0 -> 653 bytes .../app/fusion/images/menu/file_save-all.png | Bin 0 -> 610 bytes .../main/webapp/app/fusion/images/menu/mail.png | Bin 0 -> 449 bytes .../main/webapp/app/fusion/images/menu/profile.png | Bin 0 -> 462 bytes .../webapp/app/fusion/images/menu/speechbubble.png | Bin 0 -> 458 bytes .../main/webapp/app/fusion/images/menu/users.png | Bin 0 -> 938 bytes .../src/main/webapp/app/fusion/images/minus.gif | Bin 0 -> 75 bytes .../fusion/images/mobile_logo_att_header_black.png | Bin 0 -> 34762 bytes .../fusion/images/mobile_logo_att_header_grey.png | Bin 0 -> 34636 bytes .../images/mobile_logo_att_header_horizontal.png | Bin 0 -> 5202 bytes .../fusion/images/mobile_logo_att_header_white.png | Bin 0 -> 34475 bytes .../main/webapp/app/fusion/images/modify_icon.gif | Bin 0 -> 246 bytes .../src/main/webapp/app/fusion/images/note-add.png | Bin 0 -> 589 bytes .../main/webapp/app/fusion/images/note-search.png | Bin 0 -> 876 bytes .../src/main/webapp/app/fusion/images/note.png | Bin 0 -> 583 bytes .../src/main/webapp/app/fusion/images/notes.png | Bin 0 -> 673 bytes .../src/main/webapp/app/fusion/images/offline.png | Bin 0 -> 3483 bytes .../main/webapp/app/fusion/images/offlineMsg.gif | Bin 0 -> 1004 bytes .../src/main/webapp/app/fusion/images/online.png | Bin 0 -> 888 bytes .../src/main/webapp/app/fusion/images/page.gif | Bin 0 -> 131 bytes .../main/webapp/app/fusion/images/pagination.png | Bin 0 -> 724 bytes .../webapp/app/fusion/images/panel-e-w-toggle.png | Bin 0 -> 459 bytes .../webapp/app/fusion/images/panel-n-s-toggle.png | Bin 0 -> 335 bytes .../src/main/webapp/app/fusion/images/pix.gif | Bin 0 -> 49 bytes .../src/main/webapp/app/fusion/images/plus.gif | Bin 0 -> 78 bytes .../src/main/webapp/app/fusion/images/printer.gif | Bin 0 -> 1036 bytes .../src/main/webapp/app/fusion/images/profile.png | Bin 0 -> 462 bytes .../main/webapp/app/fusion/images/report-add.png | Bin 0 -> 724 bytes .../webapp/app/fusion/images/report-favorite.png | Bin 0 -> 693 bytes .../main/webapp/app/fusion/images/report-my.png | Bin 0 -> 739 bytes .../webapp/app/fusion/images/report-public.png | Bin 0 -> 776 bytes .../src/main/webapp/app/fusion/images/report.png | Bin 0 -> 563 bytes .../src/main/webapp/app/fusion/images/reports.png | Bin 0 -> 769 bytes .../app/fusion/images/results-first-active.png | Bin 0 -> 545 bytes .../app/fusion/images/results-first-disabled.png | Bin 0 -> 421 bytes .../app/fusion/images/results-last-active.png | Bin 0 -> 541 bytes .../app/fusion/images/results-last-disabled.png | Bin 0 -> 421 bytes .../app/fusion/images/results-next-active.png | Bin 0 -> 416 bytes .../app/fusion/images/results-next-disabled.png | Bin 0 -> 326 bytes .../app/fusion/images/results-prev-active.png | Bin 0 -> 421 bytes .../app/fusion/images/results-prev-disabled.png | Bin 0 -> 322 bytes .../webapp/app/fusion/images/resultset_last.png | Bin 0 -> 506 bytes .../app/fusion/images/resultset_previous.png | Bin 0 -> 381 bytes .../webapp/app/fusion/images/return_to_top.gif | Bin 0 -> 846 bytes .../main/webapp/app/fusion/images/rightButton.png | Bin 0 -> 731 bytes .../src/main/webapp/app/fusion/images/search.png | Bin 0 -> 3501 bytes .../webapp/app/fusion/images/search_profile.png | Bin 0 -> 880 bytes .../src/main/webapp/app/fusion/images/sort_asc.gif | Bin 0 -> 57 bytes .../main/webapp/app/fusion/images/sort_desc.gif | Bin 0 -> 58 bytes .../src/main/webapp/app/fusion/images/spacer.gif | Bin 0 -> 43 bytes .../main/webapp/app/fusion/images/success_type.gif | Bin 0 -> 260 bytes .../src/main/webapp/app/fusion/images/swoosh.gif | Bin 0 -> 14250 bytes .../src/main/webapp/app/fusion/images/tab-hm.png | Bin 0 -> 249 bytes .../src/main/webapp/app/fusion/images/tab-v-hm.png | Bin 0 -> 317 bytes .../src/main/webapp/app/fusion/images/tab.png | Bin 0 -> 343 bytes .../main/webapp/app/fusion/images/table-add.png | Bin 0 -> 3314 bytes .../main/webapp/app/fusion/images/table-delete.png | Bin 0 -> 3342 bytes .../main/webapp/app/fusion/images/table-edit.png | Bin 0 -> 3348 bytes .../src/main/webapp/app/fusion/images/table.png | Bin 0 -> 496 bytes .../src/main/webapp/app/fusion/images/tabs-bg.png | Bin 0 -> 147 bytes .../main/webapp/app/fusion/images/toolButton.gif | Bin 0 -> 414 bytes .../main/webapp/app/fusion/images/toolButton.png | Bin 0 -> 531 bytes .../src/main/webapp/app/fusion/images/toolbar.png | Bin 0 -> 171 bytes .../src/main/webapp/app/fusion/images/users.png | Bin 0 -> 938 bytes .../main/webapp/app/fusion/images/warning_type.gif | Bin 0 -> 1055 bytes .../src/main/webapp/app/fusion/images/webphone.ico | Bin 0 -> 241 bytes .../main/webapp/app/fusion/images/whiteButton.png | Bin 0 -> 1430 bytes .../scripts/controllers/nbook-framecontroller.js | 34 + .../scripts/controllers/nbookController.js | 179 + .../scripts/controllers/notebookFrameController.js | 65 + .../scripts/dependency/angular.js | 29400 ++++++++ .../scripts/view-models/notebook-frame.html | 85 + .../scripts/view-models/notebook-viz.html | 26 + .../scripts/view-models/notebook.htm | 54 + .../scripts/view-models/notebookInputs.html | 90 + .../att_angular_gridster/angular-gridster.js | 2244 + .../att_angular_gridster/ui-gridster-tpls.js | 168 + .../fusion/scripts/controllers/adminController.js | 65 + .../fusion/scripts/controllers/admin_menu_edit.js | 230 + .../fusion/scripts/controllers/ase-controller.js | 22 + .../scripts/controllers/broadcast-controller.js | 79 + .../controllers/broadcast-list-controller.js | 120 + .../controllers/collaborate-list-controller.js | 63 + .../app/fusion/scripts/controllers/dummy.txt | 0 .../controllers/fn_menu_add_popup_controller.js | 281 + .../scripts/controllers/jcs-admin-controller.js | 83 + .../scripts/controllers/modelpopupController.js | 40 + .../scripts/controllers/post-search-controller.js | 202 + .../scripts/controllers/profile-controller.js | 286 + .../controllers/profile-search-controller.js | 80 + .../scripts/controllers/profileController.js | 38 + .../fusion/scripts/controllers/role-controller.js | 226 + .../controllers/role-function-list-controller.js | 157 + .../scripts/controllers/role-list-controller.js | 102 + .../controllers/rolefunctionpopupController.js | 84 + .../controllers/rolepopupmodelController.js | 205 + .../scripts/controllers/self-profile-controller.js | 284 + .../scripts/controllers/usage-list-controller.js | 41 + .../scripts/controllers/workflows/workflowApp.js | 24 + .../controllers/workflows/workflowController.js | 509 + .../controllers/workflows/workflowRouting.js | 26 + .../webapp/app/fusion/scripts/directives/dummy.txt | 0 .../webapp/app/fusion/scripts/directives/footer.js | 30 + .../webapp/app/fusion/scripts/directives/header.js | 504 + .../app/fusion/scripts/directives/leftMenu.js | 203 + .../webapp/app/fusion/scripts/jquery.resize.js | 139 + .../main/webapp/app/fusion/scripts/layout/debug.js | 329 + .../app/fusion/scripts/layout/jquery-latest.js | 9555 +++ .../app/fusion/scripts/layout/jquery-ui-latest.js | 14879 ++++ .../fusion/scripts/layout/jquery.layout-latest.js | 6086 ++ .../main/webapp/app/fusion/scripts/modalService.js | 185 + .../main/webapp/app/fusion/scripts/moment.min.js | 6 + .../app/fusion/scripts/services/adminService.js | 160 + .../app/fusion/scripts/services/headerService.js | 89 + .../app/fusion/scripts/services/leftMenuService.js | 54 + .../app/fusion/scripts/services/profileService.js | 98 + .../app/fusion/scripts/services/userInfoService.js | 51 + .../app/fusion/scripts/socket/peerBroadcast.js | 122 + .../main/webapp/app/fusion/scripts/utils/dummy.txt | 0 .../app/fusion/scripts/utils/page-resource.js | 95 + .../fusion/scripts/utils/sandbox-resources.html | 9 + .../scripts/view-models/admin-page/admin.html | 115 + .../scripts/view-models/admin-page/profile.html | 47 + .../app/fusion/scripts/view-models/dummy.txt | 0 .../app/fusion/scripts/view-models/footer.html | 42 + .../app/fusion/scripts/view-models/header.html | 186 + .../app/fusion/scripts/view-models/left_menu.html | 41 + .../view-models/profile-page/admin_menu_edit.html | 175 + .../view-models/profile-page/broadcast.html | 61 + .../view-models/profile-page/broadcast_list.html | 71 + .../view-models/profile-page/collaborate_list.html | 57 + .../view-models/profile-page/jcs_admin.html | 87 + .../view-models/profile-page/popup_modal.html | 282 + .../profile-page/popup_modal_fn_menu_add.html | 155 + .../profile-page/popup_modal_fn_menu_edit.html | 148 + .../view-models/profile-page/popup_modal_role.html | 82 + .../profile-page/popup_modal_rolefunction.html | 46 + .../view-models/profile-page/post_search.html | 139 + .../view-models/profile-page/profile_detail.html | 188 + .../view-models/profile-page/profile_search.html | 72 + .../scripts/view-models/profile-page/role.html | 118 + .../profile-page/role_function_list.html | 88 + .../view-models/profile-page/role_list.html | 61 + .../view-models/profile-page/self_profile.html | 183 + .../view-models/profile-page/usage_list.html | 64 + .../view-models/workflows/workflow-landing.html | 130 + .../view-models/workflows/workflow-listing.html | 85 + .../view-models/workflows/workflow-new.html | 108 + .../view-models/workflows/workflow-preview.html | 36 + .../view-models/workflows/workflow-remove.html | 38 + .../view-models/workflows/workflow-schedule.html | 116 + .../fusion/scripts/webrtc/RTCMultiConnection.js | 6788 ++ .../app/fusion/scripts/webrtc/getSourceId.html | 78 + .../att_angular_gridster/sandbox-gridster.css | 173 + .../styles/att_angular_gridster/ui-gridster.css | 116 + .../main/webapp/app/fusion/styles/fusion-sunny.css | 362 + .../main/webapp/app/fusion/styles/jquery-ui.css | 1225 + .../fusion/styles/layout/layout-default-latest.css | 224 + .../app/fusion/styles/workflows/workflows.css | 50 + .../drools/controller/drools-list-controller.js | 62 + .../drools/controller/drools-view-controller.js | 64 + .../drools/controller/droolsController.js | 30 + .../app/fusionapp/drools/controller/dummy.txt | 0 .../app/fusionapp/drools/directives/dummy.txt | 0 .../app/fusionapp/drools/services/droolsService.js | 76 + .../webapp/app/fusionapp/drools/utils/dummy.txt | 0 .../fusionapp/drools/view-models/droolsList.html | 47 + .../drools/view-models/droolsSinglePage.html | 92 + .../fusionapp/drools/view-models/droolsView.html | 61 + .../app/fusionapp/drools/view-models/dummy.txt | 0 .../main/webapp/app/fusionapp/external/dummy.txt | 0 .../src/main/webapp/app/fusionapp/fonts/dummy.txt | 0 .../main/webapp/app/fusionapp/icons/7450-icon.png | Bin 0 -> 465 bytes .../main/webapp/app/fusionapp/icons/7450-text.png | Bin 0 -> 295 bytes .../main/webapp/app/fusionapp/icons/7750-icon.png | Bin 0 -> 565 bytes .../main/webapp/app/fusionapp/icons/7750-text.png | Bin 0 -> 632 bytes .../webapp/app/fusionapp/icons/apn-dns-icon.png | Bin 0 -> 1065 bytes .../webapp/app/fusionapp/icons/apn-dns-text.png | Bin 0 -> 901 bytes .../main/webapp/app/fusionapp/icons/atcf-icon.png | Bin 0 -> 388 bytes .../main/webapp/app/fusionapp/icons/atcf-text.png | Bin 0 -> 650 bytes .../main/webapp/app/fusionapp/icons/atgw-icon.png | Bin 0 -> 388 bytes .../main/webapp/app/fusionapp/icons/atgw-text.png | Bin 0 -> 780 bytes .../main/webapp/app/fusionapp/icons/bgcf-icon.png | Bin 0 -> 388 bytes .../main/webapp/app/fusionapp/icons/bgcf-text.png | Bin 0 -> 645 bytes .../main/webapp/app/fusionapp/icons/com-icon.png | Bin 0 -> 437 bytes .../main/webapp/app/fusionapp/icons/cpm-icon.png | Bin 0 -> 201 bytes .../main/webapp/app/fusionapp/icons/cpm-text.png | Bin 0 -> 572 bytes .../webapp/app/fusionapp/icons/default-icon.png | Bin 0 -> 329 bytes .../webapp/app/fusionapp/icons/dra-epc-icon.png | Bin 0 -> 700 bytes .../webapp/app/fusionapp/icons/dra-epc-text.png | Bin 0 -> 820 bytes .../webapp/app/fusionapp/icons/dra-ims-icon.png | Bin 0 -> 700 bytes .../webapp/app/fusionapp/icons/dra-ims-text.png | Bin 0 -> 851 bytes .../main/webapp/app/fusionapp/icons/dslam-icon.png | Bin 0 -> 774 bytes .../main/webapp/app/fusionapp/icons/dslam-text.png | Bin 0 -> 739 bytes .../main/webapp/app/fusionapp/icons/eatf-icon.png | Bin 0 -> 437 bytes .../main/webapp/app/fusionapp/icons/eatf-text.png | Bin 0 -> 439 bytes .../main/webapp/app/fusionapp/icons/ecscf-icon.png | Bin 0 -> 855 bytes .../main/webapp/app/fusionapp/icons/ecscf-text.png | Bin 0 -> 604 bytes .../main/webapp/app/fusionapp/icons/emsc-icon.png | Bin 0 -> 388 bytes .../main/webapp/app/fusionapp/icons/enb-icon.png | Bin 0 -> 1127 bytes .../main/webapp/app/fusionapp/icons/enb-text.png | Bin 0 -> 627 bytes .../main/webapp/app/fusionapp/icons/enum-icon.png | Bin 0 -> 646 bytes .../main/webapp/app/fusionapp/icons/enum-text.png | Bin 0 -> 551 bytes .../main/webapp/app/fusionapp/icons/esmlc-icon.png | Bin 0 -> 388 bytes .../main/webapp/app/fusionapp/icons/esmlc-text.png | Bin 0 -> 701 bytes .../main/webapp/app/fusionapp/icons/ettcs-icon.png | Bin 0 -> 95 bytes .../main/webapp/app/fusionapp/icons/ettcs-text.png | Bin 0 -> 95 bytes .../main/webapp/app/fusionapp/icons/gmlc-icon.png | Bin 0 -> 388 bytes .../main/webapp/app/fusionapp/icons/gmlc-text.png | Bin 0 -> 755 bytes .../main/webapp/app/fusionapp/icons/hlr-icon.png | Bin 0 -> 646 bytes .../main/webapp/app/fusionapp/icons/hlr-text.png | Bin 0 -> 376 bytes .../webapp/app/fusionapp/icons/hss-epc-icon.png | Bin 0 -> 646 bytes .../webapp/app/fusionapp/icons/hss-epc-text.png | Bin 0 -> 726 bytes .../webapp/app/fusionapp/icons/hss-ims-icon.png | Bin 0 -> 646 bytes .../webapp/app/fusionapp/icons/hss-ims-text.png | Bin 0 -> 757 bytes .../main/webapp/app/fusionapp/icons/icscf-icon.png | Bin 0 -> 855 bytes .../main/webapp/app/fusionapp/icons/icscf-text.png | Bin 0 -> 657 bytes .../main/webapp/app/fusionapp/icons/ipag-icon.png | Bin 0 -> 95 bytes .../main/webapp/app/fusionapp/icons/ipag-text.png | Bin 0 -> 95 bytes .../main/webapp/app/fusionapp/icons/isbc-icon.png | Bin 0 -> 855 bytes .../main/webapp/app/fusionapp/icons/isbc-text.png | Bin 0 -> 649 bytes .../main/webapp/app/fusionapp/icons/iwf-icon.png | Bin 0 -> 696 bytes .../main/webapp/app/fusionapp/icons/iwf-text.png | Bin 0 -> 595 bytes .../webapp/app/fusionapp/icons/lrf-rdf-icon.png | Bin 0 -> 953 bytes .../webapp/app/fusionapp/icons/lrf-rdf-text.png | Bin 0 -> 638 bytes .../webapp/app/fusionapp/icons/lrg-rdf-text.png | Bin 0 -> 769 bytes .../main/webapp/app/fusionapp/icons/mgc8-icon.png | Bin 0 -> 388 bytes .../main/webapp/app/fusionapp/icons/mgc8-text.png | Bin 0 -> 771 bytes .../webapp/app/fusionapp/icons/mgcf-emsc-icon.png | Bin 0 -> 388 bytes .../webapp/app/fusionapp/icons/mgcf-emsc-text.png | Bin 0 -> 1140 bytes .../main/webapp/app/fusionapp/icons/mgw-icon.png | Bin 0 -> 388 bytes .../main/webapp/app/fusionapp/icons/mgw-text.png | Bin 0 -> 823 bytes .../main/webapp/app/fusionapp/icons/mind-icon.png | Bin 0 -> 646 bytes .../main/webapp/app/fusionapp/icons/mind-text.png | Bin 0 -> 550 bytes .../main/webapp/app/fusionapp/icons/mme-icon.png | Bin 0 -> 232 bytes .../main/webapp/app/fusionapp/icons/mme-text.png | Bin 0 -> 252 bytes .../main/webapp/app/fusionapp/icons/mrf-icon.png | Bin 0 -> 437 bytes .../main/webapp/app/fusionapp/icons/mrf-text.png | Bin 0 -> 504 bytes .../main/webapp/app/fusionapp/icons/msc-icon.png | Bin 0 -> 388 bytes .../main/webapp/app/fusionapp/icons/msn-icon.png | Bin 0 -> 465 bytes .../main/webapp/app/fusionapp/icons/msn-text.png | Bin 0 -> 318 bytes .../main/webapp/app/fusionapp/icons/multi-icon.png | Bin 0 -> 329 bytes .../main/webapp/app/fusionapp/icons/n7450-icon.png | Bin 0 -> 464 bytes .../main/webapp/app/fusionapp/icons/n7450-text.png | Bin 0 -> 295 bytes .../webapp/app/fusionapp/icons/n7750a-icon.png | Bin 0 -> 393 bytes .../webapp/app/fusionapp/icons/n7750a-text.png | Bin 0 -> 258 bytes .../webapp/app/fusionapp/icons/n7750b-icon.png | Bin 0 -> 393 bytes .../webapp/app/fusionapp/icons/n7750b-text.png | Bin 0 -> 258 bytes .../webapp/app/fusionapp/icons/n7750c-icon.png | Bin 0 -> 391 bytes .../webapp/app/fusionapp/icons/n7750c-text.png | Bin 0 -> 258 bytes .../webapp/app/fusionapp/icons/n7750d-icon.png | Bin 0 -> 391 bytes .../webapp/app/fusionapp/icons/n7750d-text.png | Bin 0 -> 258 bytes .../main/webapp/app/fusionapp/icons/nb-icon.png | Bin 0 -> 1127 bytes .../main/webapp/app/fusionapp/icons/nb-text.png | Bin 0 -> 499 bytes .../main/webapp/app/fusionapp/icons/pas-icon.png | Bin 0 -> 700 bytes .../main/webapp/app/fusionapp/icons/pas-text.png | Bin 0 -> 596 bytes .../main/webapp/app/fusionapp/icons/pcef-icon.png | Bin 0 -> 785 bytes .../main/webapp/app/fusionapp/icons/pcef-text.png | Bin 0 -> 539 bytes .../main/webapp/app/fusionapp/icons/pcrf-icon.png | Bin 0 -> 785 bytes .../main/webapp/app/fusionapp/icons/pcrf-text.png | Bin 0 -> 594 bytes .../main/webapp/app/fusionapp/icons/pcscf-icon.png | Bin 0 -> 855 bytes .../main/webapp/app/fusionapp/icons/pcscf-text.png | Bin 0 -> 744 bytes .../main/webapp/app/fusionapp/icons/pgw-icon.png | Bin 0 -> 388 bytes .../main/webapp/app/fusionapp/icons/pgw-text.png | Bin 0 -> 807 bytes .../main/webapp/app/fusionapp/icons/plrf-icon.png | Bin 0 -> 953 bytes .../main/webapp/app/fusionapp/icons/plrf-text.png | Bin 0 -> 735 bytes .../main/webapp/app/fusionapp/icons/psap-icon.png | Bin 0 -> 322 bytes .../webapp/app/fusionapp/icons/pstn-tdm-icon.png | Bin 0 -> 95 bytes .../webapp/app/fusionapp/icons/pstn-tdm-text.png | Bin 0 -> 95 bytes .../main/webapp/app/fusionapp/icons/rg-icon.png | Bin 0 -> 388 bytes .../main/webapp/app/fusionapp/icons/rg-text.png | Bin 0 -> 540 bytes .../main/webapp/app/fusionapp/icons/rnc-icon.png | Bin 0 -> 591 bytes .../main/webapp/app/fusionapp/icons/rnc-text.png | Bin 0 -> 646 bytes .../main/webapp/app/fusionapp/icons/sbc-icon.png | Bin 0 -> 855 bytes .../main/webapp/app/fusionapp/icons/sbc-text.png | Bin 0 -> 632 bytes .../main/webapp/app/fusionapp/icons/sccas-icon.png | Bin 0 -> 437 bytes .../main/webapp/app/fusionapp/icons/sccas-text.png | Bin 0 -> 861 bytes .../main/webapp/app/fusionapp/icons/scscf-icon.png | Bin 0 -> 855 bytes .../main/webapp/app/fusionapp/icons/scscf-text.png | Bin 0 -> 704 bytes .../main/webapp/app/fusionapp/icons/sdg-icon.png | Bin 0 -> 491 bytes .../main/webapp/app/fusionapp/icons/sdg-text.png | Bin 0 -> 696 bytes .../webapp/app/fusionapp/icons/sgsns4-icon.png | Bin 0 -> 230 bytes .../webapp/app/fusionapp/icons/sgsns4-text.png | Bin 0 -> 469 bytes .../main/webapp/app/fusionapp/icons/sgw-icon.png | Bin 0 -> 388 bytes .../main/webapp/app/fusionapp/icons/sgw-text.png | Bin 0 -> 884 bytes .../main/webapp/app/fusionapp/icons/siad-icon.png | Bin 0 -> 774 bytes .../main/webapp/app/fusionapp/icons/siad-text.png | Bin 0 -> 753 bytes .../webapp/app/fusionapp/icons/ss7-gport-icon.png | Bin 0 -> 286 bytes .../webapp/app/fusionapp/icons/ss7-gport-text.png | Bin 0 -> 418 bytes .../webapp/app/fusionapp/icons/ss7gport-icon.png | Bin 0 -> 646 bytes .../webapp/app/fusionapp/icons/ss7gport-text.png | Bin 0 -> 1011 bytes .../webapp/app/fusionapp/icons/switch-icon.png | Bin 0 -> 877 bytes .../main/webapp/app/fusionapp/icons/tas-icon.png | Bin 0 -> 437 bytes .../main/webapp/app/fusionapp/icons/tas-text.png | Bin 0 -> 858 bytes .../webapp/app/fusionapp/icons/transcoder-icon.png | Bin 0 -> 774 bytes .../webapp/app/fusionapp/icons/transcoder-text.png | Bin 0 -> 1242 bytes .../main/webapp/app/fusionapp/icons/ue-icon.png | Bin 0 -> 577 bytes .../webapp/app/fusionapp/icons/uephone-icon.png | Bin 0 -> 1190 bytes .../webapp/app/fusionapp/icons/usp-dns-icon.png | Bin 0 -> 1065 bytes .../webapp/app/fusionapp/icons/usp-dns-text.png | Bin 0 -> 826 bytes .../src/main/webapp/app/fusionapp/images/dummy.txt | 0 .../app/fusionapp/scripts/controller/dummy.txt | 0 .../scripts/controller/sample-page-controller.js | 80 + .../controller/sample-page-iframe-controller.js | 23 + .../scripts/controller/sampleController.js | 30 + .../app/fusionapp/scripts/directives/dummy.txt | 0 .../webapp/app/fusionapp/scripts/utils/dummy.txt | 0 .../app/fusionapp/scripts/view-models/dummy.txt | 0 .../app/fusionapp/scripts/view-models/sample.html | 60 + .../scripts/view-models/sampleWithIframe.html | 22 + .../scripts/view-models/singlePageSample.html | 87 + .../src/main/webapp/app/fusionapp/styles/dummy.txt | 0 .../app/policyApp/CSS/Notification/angular-csp.css | 22 + .../Notification/angular-ui-notification.min.css | 1 + .../Notification/angular-ui-notification.min.js | 1 + .../webapp/app/policyApp/CSS/bootstrap.min.css | 5 + .../main/webapp/app/policyApp/CSS/bootstrap.min.js | 7 + .../src/main/webapp/app/policyApp/CSS/select.css | 287 + .../src/main/webapp/app/policyApp/CSS/select.js | 1748 + .../src/main/webapp/app/policyApp/CSS/w3.css | 360 + .../app/policyApp/JSONDataFiles/JSONConfig.json | 132 + .../webapp/app/policyApp/Properties/config.json | 3 + .../Windows/Dictionary/ActionPolicyDictionary.html | 89 + .../Windows/Dictionary/AttributeDictionary.html | 80 + .../Windows/Dictionary/BRMSParamDictionary.html | 47 + .../Windows/Dictionary/CLPepOptionsDictionary.html | 65 + .../Dictionary/CLServiceTypeDictionary.html | 43 + .../Windows/Dictionary/CLSiteDictionary.html | 43 + .../Windows/Dictionary/CLVarbindDictionary.html | 48 + .../Windows/Dictionary/CLVnfTypeDictionary.html | 43 + .../Windows/Dictionary/CLVsclActionDictionary.html | 43 + .../Dictionary/DecisionSettingsDictionary.html | 60 + .../Dictionary/DescriptiveScopeDictionary.html | 65 + .../Windows/Dictionary/EcompNameDictionary.html | 43 + .../Windows/Dictionary/EnforcerTypeDictionary.html | 51 + .../Windows/Dictionary/FWActionListDictionary.html | 43 + .../Dictionary/FWAddressGroupDictionary.html | 62 + .../Windows/Dictionary/FWParentListDictionary.html | 81 + .../Windows/Dictionary/FWPortListDictionary.html | 43 + .../Windows/Dictionary/FWPrefixListDictionary.html | 49 + .../Dictionary/FWProtocolListDictionary.html | 43 + .../Dictionary/FWSecurityZoneDictionary.html | 43 + .../Dictionary/FWServiceGroupDictionary.html | 57 + .../Dictionary/FWServiceListDictionary.html | 87 + .../Windows/Dictionary/FWTermListDictionary.html | 176 + .../Windows/Dictionary/FWZoneDictionary.html | 43 + .../Windows/Dictionary/MSConfigNameDictionary.html | 43 + .../Windows/Dictionary/MSDCAEUUIDDictionary.html | 43 + .../Windows/Dictionary/MSLocationDictionary.html | 43 + .../Windows/Dictionary/MSModelsDictionary.html | 41 + .../Windows/Dictionary/PSClosedLoopDictionary.html | 43 + .../Dictionary/PSGroupPolicyScopeDictionary.html | 65 + .../Windows/Dictionary/PSResourceDictionary.html | 43 + .../Windows/Dictionary/PSServiceDictionary.html | 43 + .../Windows/Dictionary/PSTypeDictionary.html | 43 + .../Windows/Dictionary/RiskTypeDictionary.html | 43 + .../Dictionary/SafePolicyWarningDictionary.html | 49 + .../app/policyApp/Windows/Edit_Roles_Window.html | 48 + .../Windows/PDPTabWindows/AddorEditPDPtoGroup.html | 56 + .../Windows/PDPTabWindows/PdpStatusWindow.html | 73 + .../PushtabWindow/removeGroupPoliciesWindow.html | 35 + .../app/policyApp/Windows/new_PDPGroup_Window.html | 94 + .../app/policyApp/controller/AutoPushController.js | 201 + .../RemovePDPGroupPoliciesController.js | 85 + .../policyApp/controller/DictionaryController.js | 82 + .../webapp/app/policyApp/controller/FileSaver.js | 170 + .../controller/ImportDictionaryController.js | 53 + .../PDPTabController/AddorEditPdpInGroup.js | 62 + .../PDPTabController/PDPGroupStatusController.js | 44 + .../controller/PolicyAddScopeRoleController.js | 65 + .../policyApp/controller/PolicyRolesController.js | 95 + .../policyApp/controller/dashboardController.js | 125 + .../controller/dashboard_Logging_Controller.js | 81 + .../BRMSParamDictController.js | 88 + .../CLPepOptionsDictController.js | 120 + .../CLServiceDictController.js | 75 + .../dictionaryController/CLSiteDictController.js | 75 + .../CLVarbindDictController.js | 75 + .../CLVnfTypeDictController.js | 75 + .../CLVsclActionDictController.js | 75 + .../DecisionSettingsDictController.js | 75 + .../DescriptiveSearchDictController.js | 121 + .../dictionaryController/EnforcerDictController.js | 70 + .../FWActionListDictController.js | 75 + .../FWAddressGroupDictController.js | 120 + .../FWParentListDictController.js | 156 + .../FWPortListDictController.js | 75 + .../FWPrefixListDictController.js | 103 + .../FWProtocolListDictController.js | 75 + .../FWSecurityZoneDictController.js | 75 + .../FWServiceGroupDictController.js | 121 + .../FWServiceListDictController.js | 147 + .../FWTermListDictController.js | 331 + .../dictionaryController/FWZoneDictController.js | 75 + .../MSConfigNameDictController.js | 76 + .../MSDcaeUUIDDictController.js | 76 + .../MSLocationDictController.js | 76 + .../dictionaryController/MSModelsDictController.js | 87 + .../PSClosedLoopDictController.js | 75 + .../PSGroupPolicyScopeDictController.js | 137 + .../PSResourceDictController.js | 75 + .../PSServiceDictController.js | 75 + .../dictionaryController/PSTypeDictController.js | 76 + .../dictionaryController/RiskTypeDictController.js | 75 + .../SafePolicyWarningDictController.js | 107 + .../actionPolicyDictController.js | 119 + .../attributeDictController.js | 109 + .../ecompNameEditorController.js | 74 + .../BRMSParamDictGridController.js | 127 + .../CLPepOptionsDictGridController.js | 183 + .../CLServiceDictGridController.js | 161 + .../CLSiteDictGridController.js | 161 + .../CLVarbindDictGridController.js | 184 + .../CLVnfTypeDictGridController.js | 181 + .../CLVsclActionDictGridController.js | 183 + .../DecisionSettingsDictGridController.js | 151 + .../DescriptiveScopeDictGridController.js | 150 + .../EnforcerTypeDictGridController.js | 126 + .../FWActionListDictGridController.js | 145 + .../FWAddressGroupDictGridController.js | 146 + .../FWParentListDictGridController.js | 149 + .../FWPortListDictGridController.js | 132 + .../FWPrefixListDictGridController.js | 148 + .../FWProtocolListDictGridController.js | 157 + .../FWSecurityZoneDictGridController.js | 147 + .../FWServiceGroupDictGridController.js | 147 + .../FWServiceListDictGridController.js | 162 + .../FWTermListDictGridController.js | 159 + .../FWZoneDictGridController.js | 148 + .../MSConfigNameDictGridController.js | 124 + .../MSDcaeUUIDDictGridController.js | 124 + .../MSLocationDictGridController.js | 124 + .../MSModelDictGridController.js | 124 + .../PSClosedLoopDictGridController.js | 123 + .../PSGroupPolicyScopeDictGridController.js | 127 + .../PSResourceDictGridController.js | 123 + .../PSServiceDictGridController.js | 122 + .../PSTypeDictGridController.js | 122 + .../RiskTypeDictGridController.js | 152 + .../SafePolicyWarningDictGridController.js | 127 + .../actionPolicyDictGridController.js | 161 + .../attributeDictGridController.js | 159 + .../ecompNameDictGridController.js | 152 + .../policyApp/controller/editorTabController.js | 211 + .../app/policyApp/controller/pdpController.js | 178 + .../controller/pdpGroupPopUpController.js | 179 + .../controller/policyAdminTabController.js | 70 + .../app/policyApp/controller/policyController.js | 65 + .../main/webapp/app/policyApp/images/loading.gif | Bin 0 -> 6820 bytes .../webapp/app/policyApp/images/loading_bar.gif | Bin 0 -> 28954 bytes .../src/main/webapp/app/policyApp/libs/README.md | 48 + .../bower_components/angular-cookies/.bower.json | 19 + .../bower_components/angular-cookies/README.md | 68 + .../angular-cookies/angular-cookies.js | 207 + .../angular-cookies/angular-cookies.min.js | 8 + .../angular-cookies/angular-cookies.min.js.map | 8 + .../bower_components/angular-cookies/bower.json | 9 + .../libs/bower_components/angular-cookies/index.js | 2 + .../bower_components/angular-cookies/package.json | 26 + .../angular-translate/angular-translate.min.js | 6 + .../libs/bower_components/angular/.bower.json | 17 + .../libs/bower_components/angular/README.md | 64 + .../libs/bower_components/angular/angular-csp.css | 13 + .../libs/bower_components/angular/angular.js | 26451 +++++++ .../libs/bower_components/angular/angular.min.js | 253 + .../bower_components/angular/angular.min.js.gzip | Bin 0 -> 46451 bytes .../bower_components/angular/angular.min.js.map | 8 + .../libs/bower_components/angular/bower.json | 8 + .../libs/bower_components/angular/index.js | 2 + .../libs/bower_components/angular/package.json | 25 + .../bootstrap/dist/css/bootstrap.min.css | 6 + .../bootstrap/dist/js/bootstrap.min.js | 7 + .../fonts/glyphicons-halflings-regular.eot | Bin 0 -> 20127 bytes .../fonts/glyphicons-halflings-regular.svg | 288 + .../fonts/glyphicons-halflings-regular.ttf | Bin 0 -> 45404 bytes .../fonts/glyphicons-halflings-regular.woff | Bin 0 -> 23424 bytes .../fonts/glyphicons-halflings-regular.woff2 | Bin 0 -> 18028 bytes .../bootswatch/paper/bootstrap.min.css | 11 + .../libs/bower_components/jquery/.bower.json | 38 + .../libs/bower_components/jquery/MIT-LICENSE.txt | 21 + .../libs/bower_components/jquery/bower.json | 28 + .../libs/bower_components/jquery/dist/jquery.js | 9210 +++ .../bower_components/jquery/dist/jquery.min.js | 5 + .../bower_components/jquery/dist/jquery.min.map | 1 + .../libs/bower_components/jquery/src/ajax.js | 786 + .../libs/bower_components/jquery/src/ajax/jsonp.js | 89 + .../libs/bower_components/jquery/src/ajax/load.js | 75 + .../bower_components/jquery/src/ajax/parseJSON.js | 13 + .../bower_components/jquery/src/ajax/parseXML.js | 28 + .../bower_components/jquery/src/ajax/script.js | 64 + .../bower_components/jquery/src/ajax/var/nonce.js | 5 + .../bower_components/jquery/src/ajax/var/rquery.js | 3 + .../libs/bower_components/jquery/src/ajax/xhr.js | 136 + .../libs/bower_components/jquery/src/attributes.js | 11 + .../bower_components/jquery/src/attributes/attr.js | 141 + .../jquery/src/attributes/classes.js | 158 + .../bower_components/jquery/src/attributes/prop.js | 94 + .../jquery/src/attributes/support.js | 35 + .../bower_components/jquery/src/attributes/val.js | 161 + .../libs/bower_components/jquery/src/callbacks.js | 205 + .../libs/bower_components/jquery/src/core.js | 502 + .../bower_components/jquery/src/core/access.js | 60 + .../libs/bower_components/jquery/src/core/init.js | 123 + .../bower_components/jquery/src/core/parseHTML.js | 39 + .../libs/bower_components/jquery/src/core/ready.js | 97 + .../jquery/src/core/var/rsingleTag.js | 4 + .../libs/bower_components/jquery/src/css.js | 450 + .../jquery/src/css/addGetHookIf.js | 22 + .../libs/bower_components/jquery/src/css/curCSS.js | 57 + .../jquery/src/css/defaultDisplay.js | 70 + .../jquery/src/css/hiddenVisibleSelectors.js | 15 + .../bower_components/jquery/src/css/support.js | 96 + .../libs/bower_components/jquery/src/css/swap.js | 28 + .../jquery/src/css/var/cssExpand.js | 3 + .../jquery/src/css/var/getStyles.js | 12 + .../jquery/src/css/var/isHidden.js | 13 + .../bower_components/jquery/src/css/var/rmargin.js | 3 + .../jquery/src/css/var/rnumnonpx.js | 5 + .../libs/bower_components/jquery/src/data.js | 178 + .../libs/bower_components/jquery/src/data/Data.js | 181 + .../bower_components/jquery/src/data/accepts.js | 20 + .../jquery/src/data/var/data_priv.js | 5 + .../jquery/src/data/var/data_user.js | 5 + .../libs/bower_components/jquery/src/deferred.js | 149 + .../libs/bower_components/jquery/src/deprecated.js | 13 + .../libs/bower_components/jquery/src/dimensions.js | 50 + .../libs/bower_components/jquery/src/effects.js | 648 + .../bower_components/jquery/src/effects/Tween.js | 114 + .../jquery/src/effects/animatedSelector.js | 13 + .../libs/bower_components/jquery/src/event.js | 868 + .../libs/bower_components/jquery/src/event/ajax.js | 13 + .../bower_components/jquery/src/event/alias.js | 39 + .../bower_components/jquery/src/event/support.js | 9 + .../bower_components/jquery/src/exports/amd.js | 24 + .../bower_components/jquery/src/exports/global.js | 32 + .../libs/bower_components/jquery/src/intro.js | 44 + .../libs/bower_components/jquery/src/jquery.js | 37 + .../bower_components/jquery/src/manipulation.js | 580 + .../jquery/src/manipulation/_evalUrl.js | 18 + .../jquery/src/manipulation/support.js | 32 + .../jquery/src/manipulation/var/rcheckableType.js | 3 + .../libs/bower_components/jquery/src/offset.js | 207 + .../libs/bower_components/jquery/src/outro.js | 1 + .../libs/bower_components/jquery/src/queue.js | 142 + .../bower_components/jquery/src/queue/delay.js | 22 + .../bower_components/jquery/src/selector-native.js | 172 + .../bower_components/jquery/src/selector-sizzle.js | 14 + .../libs/bower_components/jquery/src/selector.js | 1 + .../libs/bower_components/jquery/src/serialize.js | 111 + .../jquery/src/sizzle/dist/sizzle.js | 2067 + .../jquery/src/sizzle/dist/sizzle.min.js | 3 + .../jquery/src/sizzle/dist/sizzle.min.map | 1 + .../libs/bower_components/jquery/src/traversing.js | 199 + .../jquery/src/traversing/findFilter.js | 100 + .../jquery/src/traversing/var/rneedsContext.js | 6 + .../libs/bower_components/jquery/src/var/arr.js | 3 + .../bower_components/jquery/src/var/class2type.js | 4 + .../libs/bower_components/jquery/src/var/concat.js | 5 + .../libs/bower_components/jquery/src/var/hasOwn.js | 5 + .../bower_components/jquery/src/var/indexOf.js | 5 + .../libs/bower_components/jquery/src/var/pnum.js | 3 + .../libs/bower_components/jquery/src/var/push.js | 5 + .../bower_components/jquery/src/var/rnotwhite.js | 3 + .../libs/bower_components/jquery/src/var/slice.js | 5 + .../jquery/src/var/strundefined.js | 3 + .../bower_components/jquery/src/var/support.js | 4 + .../bower_components/jquery/src/var/toString.js | 5 + .../libs/bower_components/jquery/src/wrap.js | 79 + .../ng-file-upload/ng-file-upload.min.js | 3 + .../main/webapp/app/policyApp/libs/html2canvas.js | 3010 + .../webapp/app/policyApp/libs/jquery.base64.js | 190 + .../main/webapp/app/policyApp/libs/jspdf/jspdf.js | 303 + .../webapp/app/policyApp/libs/jspdf/libs/base64.js | 143 + .../app/policyApp/libs/jspdf/libs/sprintf.js | 152 + .../webapp/app/policyApp/libs/jspdf/pdfmake.js | 68149 +++++++++++++++++++ .../app/policyApp/libs/tableExport.jquery.json | 1 + .../main/webapp/app/policyApp/libs/tableExport.js | 359 + .../webapp/app/policyApp/main/policy_Editor.html | 323 + .../Dictionary/ActionPolicyDictionary.html | 23 + .../Dictionary/AttributeDictionary.html | 26 + .../Dictionary/BRMSParamDictionary.html | 23 + .../Dictionary/CLPepOptionsDictionary.html | 23 + .../Dictionary/CLServiceDictionary.html | 23 + .../policy-models/Dictionary/CLSiteDictionary.html | 23 + .../Dictionary/CLVNFTypeDictionary.html | 23 + .../Dictionary/CLVSCLActionDictionary.html | 23 + .../Dictionary/CLVarbindDictionary.html | 23 + .../Dictionary/DecisionSettingsDictionary.html | 23 + .../Dictionary/DescriptiveScopeDictionary.html | 23 + .../Dictionary/EcompNameDictionary.html | 23 + .../Dictionary/EnforcerTypeDictionary.html | 23 + .../Dictionary/FWActionLisdtDictionary.html | 23 + .../Dictionary/FWActionListDictionary.html | 23 + .../Dictionary/FWAddressGroupDictionary.html | 23 + .../Dictionary/FWParentListDictionary.html | 23 + .../Dictionary/FWPortListDictionary.html | 23 + .../Dictionary/FWPrefixListDictionary.html | 23 + .../Dictionary/FWProtocolListDictionary.html | 23 + .../Dictionary/FWSecurityZoneDictionary.html | 23 + .../Dictionary/FWServiceGroupDictionary.html | 23 + .../Dictionary/FWServiceListDictionary.html | 23 + .../Dictionary/FWTermListDictionary.html | 23 + .../policy-models/Dictionary/FWZoneDictionary.html | 23 + .../Dictionary/MSConfigNameDictionary.html | 23 + .../Dictionary/MSDcaeUUIDDictionary.html | 23 + .../Dictionary/MSLocationDictionary.html | 23 + .../Dictionary/MSModelDictionary.html | 23 + .../Dictionary/PSClosedLoopDictionary.html | 23 + .../Dictionary/PSGroupPolicyScopeDictionary.html | 23 + .../Dictionary/PSResourceDictionary.html | 23 + .../Dictionary/PSServiceDictionary.html | 23 + .../policy-models/Dictionary/PSTypeDictionary.html | 23 + .../Dictionary/RiskTypeDictionary.html | 23 + .../Dictionary/SafePolicyWarningDictionary.html | 23 + .../ActionPolicyController.js | 175 + .../BRMSParamPolicyController.js | 210 + .../BRMSRawPolicyController.js | 147 + .../BaseConfigPolicyController.js | 185 + .../ClosedLoopFaultController.js | 790 + .../ClosedLoopPMController.js | 178 + .../DCAEMicroServicePolicyController.js | 694 + .../DecisionPolicyController.js | 212 + .../ExportPolicyController.js | 108 + .../FirewallPolicyController.js | 234 + .../PolicyDictionaryService.js | 522 + .../PolicyTemplates/ActionPolicyTemplate.html | 103 + .../PolicyTemplates/BRMSParamPolicyTemplate.html | 112 + .../PolicyTemplates/BRMSRawPolicyTemplate.html | 99 + .../Editor/PolicyTemplates/BasePolicyTemplate.html | 126 + .../ClosedLoopFaultPolicyTemplate.html | 350 + .../ClosedLoopPMPolicyTemplate.html | 141 + .../DCAEMicroServicePolicyTemplate.html | 108 + .../PolicyTemplates/DecisionPolicyTemplate.html | 130 + .../PolicyTemplates/DescribePolicyTemplate.html | 50 + .../PolicyTemplates/ExportPolicyTemplate.html | 35 + .../PolicyTemplates/FirewallPolicyTemplate.html | 116 + .../Editor/PolicyTemplates/PolicyTypeTemplate.html | 79 + .../policy-models/Editor/css/normalize-legacy.css | 545 + .../policy-models/Editor/css/normalize.css | 439 + .../policyApp/policy-models/Editor/css/styles.css | 86 + .../policy-models/Editor/src/css/animations.css | 183 + .../policy-models/Editor/src/css/dialogs.css | 85 + .../policy-models/Editor/src/css/main.css | 336 + .../policyApp/policy-models/Editor/src/js/app.js | 47 + .../Editor/src/js/controllers/main.js | 426 + .../src/js/controllers/selector-controller.js | 47 + .../Editor/src/js/directives/directives.js | 60 + .../policy-models/Editor/src/js/entities/item.js | 351 + .../policy-models/Editor/src/js/filters/filters.js | 41 + .../Editor/src/js/providers/config.js | 90 + .../Editor/src/js/providers/translations.js | 353 + .../Editor/src/js/services/RolesService.js | 41 + .../Editor/src/js/services/filenavigator.js | 199 + .../Editor/src/js/services/fileuploader.js | 73 + .../src/templates/current-folder-breadcrumb.html | 34 + .../Editor/src/templates/item-context-menu.html | 102 + .../Editor/src/templates/item-toolbar.html | 25 + .../Editor/src/templates/main-icons.html | 43 + .../Editor/src/templates/main-table-modal.html | 66 + .../Editor/src/templates/main-table.html | 100 + .../policy-models/Editor/src/templates/main.html | 34 + .../policy-models/Editor/src/templates/modals.html | 385 + .../policy-models/Editor/src/templates/navbar.html | 127 + .../Editor/src/templates/sidebar.html | 34 + .../Editor/src/templates/spinner.html | 25 + .../policyApp/policy-models/policy_AdminTab.html | 35 + .../policyApp/policy-models/policy_AutoPush.html | 68 + .../policy-models/policy_DashboardHealth.html | 39 + .../policy-models/policy_DashboardLogging.html | 44 + .../policyApp/policy-models/policy_Dictionary.html | 104 + .../policy-models/policy_PDPManagement.html | 98 + .../app/policyApp/policy-models/policy_Roles.html | 29 + .../app/policyApp/service/AdminTabService.js | 56 + .../app/policyApp/service/AutoPushService.js | 41 + .../app/policyApp/service/ClosedLoopPMService.js | 42 + .../app/policyApp/service/DashboardService.js | 99 + .../service/Dictionary/CLDictionaryService.js | 132 + .../service/Dictionary/DictionaryService.js | 148 + .../service/Dictionary/FWDictionaryService.js | 339 + .../service/Dictionary/MSDictionaryService.js | 96 + .../service/Dictionary/PolicyScopeService.js | 182 + .../service/Dictionary/SafePolicyService.js | 92 + .../app/policyApp/service/ExportPolicyService.js | 41 + .../webapp/app/policyApp/service/PDPService.js | 53 + .../webapp/app/policyApp/service/PapUrlService.js | 39 + .../app/policyApp/service/RolesTabService.js | 56 + ecomp-sdk-app/src/main/webapp/index.jsp | 24 + ecomp-sdk-app/src/main/webapp/manifest.jsp | 47 + .../css/att_angular_gridster/sandbox-gridster.css | 173 + .../css/att_angular_gridster/ui-gridster.css | 116 + .../main/webapp/static/fusion/css/fusion-sunny.css | 362 + .../main/webapp/static/fusion/css/jquery-ui.css | 1225 + .../fusion/css/layout/layout-default-latest.css | 224 + .../src/main/webapp/static/fusion/d3/css/nv.d3.css | 656 + .../src/main/webapp/static/fusion/d3/js/cie.js | 155 + .../main/webapp/static/fusion/d3/js/colorbrewer.js | 302 + .../src/main/webapp/static/fusion/d3/js/core.js | 122 + .../main/webapp/static/fusion/d3/js/crossfilter.js | 1180 + .../webapp/static/fusion/d3/js/crossfilter.min.js | 1 + .../src/main/webapp/static/fusion/d3/js/d3.geom.js | 816 + .../src/main/webapp/static/fusion/d3/js/d3.js | 5 + .../webapp/static/fusion/d3/js/d3.layout.cloud.js | 433 + .../main/webapp/static/fusion/d3/js/d3.layout.js | 908 + .../src/main/webapp/static/fusion/d3/js/d3.v2.js | 7037 ++ .../main/webapp/static/fusion/d3/js/d3.v2.min.js | 4 + .../main/webapp/static/fusion/d3/js/d3.v3.min.js | 1 + .../src/main/webapp/static/fusion/d3/js/fisheye.js | 86 + .../src/main/webapp/static/fusion/d3/js/hive.js | 80 + .../src/main/webapp/static/fusion/d3/js/horizon.js | 192 + .../webapp/static/fusion/d3/js/interactiveLayer.js | 251 + .../src/main/webapp/static/fusion/d3/js/intro.js | 1 + .../webapp/static/fusion/d3/js/models/axis-min.js | 1 + .../main/webapp/static/fusion/d3/js/models/axis.js | 470 + .../webapp/static/fusion/d3/js/models/axis.min.js | 1 + .../static/fusion/d3/js/models/backup/bullet.js | 250 + .../fusion/d3/js/models/backup/bulletChart.js | 349 + .../static/fusion/d3/js/models/boilerplate.js | 104 + .../webapp/static/fusion/d3/js/models/bullet.js | 385 + .../static/fusion/d3/js/models/bulletChart.js | 343 + .../fusion/d3/js/models/cumulativeLineChart.js | 782 + .../static/fusion/d3/js/models/discreteBar.js | 349 + .../static/fusion/d3/js/models/discreteBarChart.js | 333 + .../static/fusion/d3/js/models/distribution.js | 148 + .../static/fusion/d3/js/models/historicalBar.js | 331 + .../fusion/d3/js/models/historicalBarChart.js | 419 + .../static/fusion/d3/js/models/indentedTree.js | 337 + .../webapp/static/fusion/d3/js/models/legend.js | 270 + .../main/webapp/static/fusion/d3/js/models/line.js | 284 + .../webapp/static/fusion/d3/js/models/lineChart.js | 465 + .../static/fusion/d3/js/models/linePlusBarChart.js | 433 + .../d3/js/models/linePlusBarWithFocusChart.js | 658 + .../static/fusion/d3/js/models/lineWithFisheye.js | 200 + .../fusion/d3/js/models/lineWithFisheyeChart.js | 297 + .../fusion/d3/js/models/lineWithFocusChart.js | 574 + .../webapp/static/fusion/d3/js/models/multiBar.js | 461 + .../static/fusion/d3/js/models/multiBarChart.js | 524 + .../fusion/d3/js/models/multiBarHorizontal.js | 424 + .../fusion/d3/js/models/multiBarHorizontalChart.js | 434 + .../fusion/d3/js/models/multiBarTimeSeries.js | 384 + .../fusion/d3/js/models/multiBarTimeSeriesChart.js | 405 + .../static/fusion/d3/js/models/multiChart.js | 452 + .../webapp/static/fusion/d3/js/models/ohlcBar.js | 380 + .../fusion/d3/js/models/parallelCoordinates.js | 239 + .../main/webapp/static/fusion/d3/js/models/pie.js | 400 + .../webapp/static/fusion/d3/js/models/pieChart.js | 292 + .../webapp/static/fusion/d3/js/models/scatter.js | 674 + .../static/fusion/d3/js/models/scatterChart.js | 628 + .../fusion/d3/js/models/scatterPlusLineChart.js | 620 + .../webapp/static/fusion/d3/js/models/sparkline.js | 194 + .../static/fusion/d3/js/models/sparklinePlus.js | 295 + .../static/fusion/d3/js/models/stackedArea.js | 368 + .../static/fusion/d3/js/models/stackedAreaChart.js | 629 + .../src/main/webapp/static/fusion/d3/js/nv.d3.js | 13097 ++++ .../main/webapp/static/fusion/d3/js/nv.d3.min.js | 1 + .../src/main/webapp/static/fusion/d3/js/outro.js | 1 + .../src/main/webapp/static/fusion/d3/js/sankey.js | 292 + .../src/main/webapp/static/fusion/d3/js/tooltip.js | 490 + .../src/main/webapp/static/fusion/d3/js/utils.js | 152 + .../webapp/static/fusion/images/Logo_att_labs.png | Bin 0 -> 2011 bytes .../src/main/webapp/static/fusion/images/Rlogo.jpg | Bin 0 -> 3173 bytes .../src/main/webapp/static/fusion/images/Thumbs.db | Bin 0 -> 102912 bytes .../webapp/static/fusion/images/action_icon.png | Bin 0 -> 2388 bytes .../static/fusion/images/action_list_spacer.gif | Bin 0 -> 73 bytes .../main/webapp/static/fusion/images/active.png | Bin 0 -> 682 bytes .../src/main/webapp/static/fusion/images/add.png | Bin 0 -> 352 bytes .../static/fusion/images/add_tool_button.png | Bin 0 -> 31105 bytes .../main/webapp/static/fusion/images/addicon.png | Bin 0 -> 463 bytes .../static/fusion/images/application_window_bg.jpg | Bin 0 -> 914 bytes .../webapp/static/fusion/images/arrow-next.png | Bin 0 -> 1561 bytes .../webapp/static/fusion/images/arrow-prev.png | Bin 0 -> 1557 bytes .../fusion/images/att_angular_gridster/grips.png | Bin 0 -> 951 bytes .../webapp/static/fusion/images/backButton.png | Bin 0 -> 816 bytes .../src/main/webapp/static/fusion/images/blank.gif | Bin 0 -> 49 bytes .../webapp/static/fusion/images/blueButton.png | Bin 0 -> 1468 bytes .../main/webapp/static/fusion/images/bubble.png | Bin 0 -> 662 bytes .../src/main/webapp/static/fusion/images/cache.png | Bin 0 -> 1081 bytes .../main/webapp/static/fusion/images/calendar.gif | Bin 0 -> 929 bytes .../main/webapp/static/fusion/images/chevron.png | Bin 0 -> 252 bytes .../static/fusion/images/close_container.gif | Bin 0 -> 85 bytes .../webapp/static/fusion/images/collapsed-icon.png | Bin 0 -> 1379 bytes .../main/webapp/static/fusion/images/column-bg.png | Bin 0 -> 165 bytes .../static/fusion/images/copyicon-highlighted.png | Bin 0 -> 264 bytes .../main/webapp/static/fusion/images/copyicon.png | Bin 0 -> 235 bytes .../main/webapp/static/fusion/images/csv_icon.jpg | Bin 0 -> 632 bytes .../main/webapp/static/fusion/images/csv_icon.png | Bin 0 -> 938 bytes .../webapp/static/fusion/images/customers-add.png | Bin 0 -> 755 bytes .../static/fusion/images/customers-search.png | Bin 0 -> 976 bytes .../main/webapp/static/fusion/images/customers.png | Bin 0 -> 749 bytes .../main/webapp/static/fusion/images/decrypted.png | Bin 0 -> 628 bytes .../fusion/images/deleteicon-highlighted.gif | Bin 0 -> 592 bytes .../fusion/images/deleteicon-highlighted.png | Bin 0 -> 566 bytes .../webapp/static/fusion/images/deleteicon.gif | Bin 0 -> 579 bytes .../src/main/webapp/static/fusion/images/ecomp.png | Bin 0 -> 107597 bytes .../webapp/static/fusion/images/ecomp_trans.png | Bin 0 -> 109926 bytes .../main/webapp/static/fusion/images/editicon.gif | Bin 0 -> 360 bytes .../webapp/static/fusion/images/error_type.gif | Bin 0 -> 398 bytes .../webapp/static/fusion/images/example-frame.png | Bin 0 -> 33699 bytes .../static/fusion/images/excelicon_multi.gif | Bin 0 -> 1028 bytes .../webapp/static/fusion/images/executeicon.png | Bin 0 -> 1076 bytes .../webapp/static/fusion/images/expanded-icon.png | Bin 0 -> 1372 bytes .../main/webapp/static/fusion/images/file-add.png | Bin 0 -> 675 bytes .../webapp/static/fusion/images/file_import.png | Bin 0 -> 653 bytes .../webapp/static/fusion/images/file_save-all.png | Bin 0 -> 610 bytes .../webapp/static/fusion/images/filter_icon.png | Bin 0 -> 29069 bytes .../webapp/static/fusion/images/folder_add.png | Bin 0 -> 772 bytes .../webapp/static/fusion/images/folder_closed.png | Bin 0 -> 559 bytes .../webapp/static/fusion/images/folder_delete.png | Bin 0 -> 767 bytes .../webapp/static/fusion/images/folder_edit.png | Bin 0 -> 829 bytes .../webapp/static/fusion/images/folder_open.png | Bin 0 -> 632 bytes .../webapp/static/fusion/images/folder_user.png | Bin 0 -> 887 bytes .../main/webapp/static/fusion/images/funnel.png | Bin 0 -> 543 bytes .../main/webapp/static/fusion/images/fusion.gif | Bin 0 -> 8821 bytes .../webapp/static/fusion/images/grayButton.png | Bin 0 -> 1361 bytes .../static/fusion/images/gray_add_tool_button.png | Bin 0 -> 30883 bytes .../webapp/static/fusion/images/headerChatIcon.png | Bin 0 -> 465 bytes .../static/fusion/images/icon_remove_all.gif | Bin 0 -> 982 bytes .../main/webapp/static/fusion/images/inactive.png | Bin 0 -> 842 bytes .../main/webapp/static/fusion/images/info_type.gif | Bin 0 -> 291 bytes .../fusion/images/layout/panel-e-w-toggle.png | Bin 0 -> 459 bytes .../fusion/images/layout/panel-n-s-toggle.png | Bin 0 -> 335 bytes .../webapp/static/fusion/images/leftButton.png | Bin 0 -> 681 bytes .../main/webapp/static/fusion/images/loading.gif | Bin 0 -> 6820 bytes .../webapp/static/fusion/images/loading_bar.gif | Bin 0 -> 28954 bytes .../webapp/static/fusion/images/login_button.gif | Bin 0 -> 1222 bytes .../main/webapp/static/fusion/images/logo_att.jpg | Bin 0 -> 3145 bytes .../static/fusion/images/logo_att_header.jpg | Bin 0 -> 3145 bytes .../static/fusion/images/logo_att_header.png | Bin 0 -> 43961 bytes .../webapp/static/fusion/images/logo_header.png | Bin 0 -> 37087 bytes .../src/main/webapp/static/fusion/images/m1.gif | Bin 0 -> 636 bytes .../src/main/webapp/static/fusion/images/mail.png | Bin 0 -> 449 bytes .../src/main/webapp/static/fusion/images/map.png | Bin 0 -> 611 bytes .../webapp/static/fusion/images/menu/bubble.png | Bin 0 -> 662 bytes .../static/fusion/images/menu/file_import.png | Bin 0 -> 653 bytes .../static/fusion/images/menu/file_save-all.png | Bin 0 -> 610 bytes .../main/webapp/static/fusion/images/menu/mail.png | Bin 0 -> 449 bytes .../webapp/static/fusion/images/menu/profile.png | Bin 0 -> 462 bytes .../static/fusion/images/menu/speechbubble.png | Bin 0 -> 458 bytes .../webapp/static/fusion/images/menu/users.png | Bin 0 -> 938 bytes .../src/main/webapp/static/fusion/images/minus.gif | Bin 0 -> 75 bytes .../fusion/images/mobile_logo_att_header_black.png | Bin 0 -> 34762 bytes .../fusion/images/mobile_logo_att_header_grey.png | Bin 0 -> 34636 bytes .../images/mobile_logo_att_header_horizontal.png | Bin 0 -> 5202 bytes .../fusion/images/mobile_logo_att_header_white.png | Bin 0 -> 34475 bytes .../webapp/static/fusion/images/modify_icon.gif | Bin 0 -> 246 bytes .../static/fusion/images/no_favorites_star.png | Bin 0 -> 2794 bytes .../main/webapp/static/fusion/images/note-add.png | Bin 0 -> 589 bytes .../webapp/static/fusion/images/note-search.png | Bin 0 -> 876 bytes .../src/main/webapp/static/fusion/images/note.png | Bin 0 -> 583 bytes .../src/main/webapp/static/fusion/images/notes.png | Bin 0 -> 673 bytes .../main/webapp/static/fusion/images/offline.png | Bin 0 -> 3483 bytes .../webapp/static/fusion/images/offlineMsg.gif | Bin 0 -> 1004 bytes .../main/webapp/static/fusion/images/online.png | Bin 0 -> 888 bytes .../src/main/webapp/static/fusion/images/page.gif | Bin 0 -> 131 bytes .../webapp/static/fusion/images/pagination.png | Bin 0 -> 724 bytes .../static/fusion/images/panel-e-w-toggle.png | Bin 0 -> 459 bytes .../static/fusion/images/panel-n-s-toggle.png | Bin 0 -> 335 bytes .../src/main/webapp/static/fusion/images/pix.gif | Bin 0 -> 49 bytes .../src/main/webapp/static/fusion/images/plus.gif | Bin 0 -> 78 bytes .../main/webapp/static/fusion/images/printer.gif | Bin 0 -> 1036 bytes .../main/webapp/static/fusion/images/profile.png | Bin 0 -> 462 bytes .../webapp/static/fusion/images/report-add.png | Bin 0 -> 724 bytes .../static/fusion/images/report-favorite.png | Bin 0 -> 693 bytes .../main/webapp/static/fusion/images/report-my.png | Bin 0 -> 739 bytes .../webapp/static/fusion/images/report-public.png | Bin 0 -> 776 bytes .../main/webapp/static/fusion/images/report.png | Bin 0 -> 563 bytes .../main/webapp/static/fusion/images/reports.png | Bin 0 -> 769 bytes .../static/fusion/images/results-first-active.png | Bin 0 -> 545 bytes .../fusion/images/results-first-disabled.png | Bin 0 -> 421 bytes .../static/fusion/images/results-last-active.png | Bin 0 -> 541 bytes .../static/fusion/images/results-last-disabled.png | Bin 0 -> 421 bytes .../static/fusion/images/results-next-active.png | Bin 0 -> 416 bytes .../static/fusion/images/results-next-disabled.png | Bin 0 -> 326 bytes .../static/fusion/images/results-prev-active.png | Bin 0 -> 421 bytes .../static/fusion/images/results-prev-disabled.png | Bin 0 -> 322 bytes .../webapp/static/fusion/images/resultset_last.png | Bin 0 -> 506 bytes .../static/fusion/images/resultset_previous.png | Bin 0 -> 381 bytes .../webapp/static/fusion/images/return_to_top.gif | Bin 0 -> 846 bytes .../webapp/static/fusion/images/rightButton.png | Bin 0 -> 731 bytes .../main/webapp/static/fusion/images/search.png | Bin 0 -> 3501 bytes .../webapp/static/fusion/images/search_profile.png | Bin 0 -> 880 bytes .../main/webapp/static/fusion/images/sort_asc.gif | Bin 0 -> 57 bytes .../main/webapp/static/fusion/images/sort_desc.gif | Bin 0 -> 58 bytes .../main/webapp/static/fusion/images/spacer.gif | Bin 0 -> 43 bytes .../webapp/static/fusion/images/success_type.gif | Bin 0 -> 260 bytes .../main/webapp/static/fusion/images/swoosh.gif | Bin 0 -> 14250 bytes .../main/webapp/static/fusion/images/tab-hm.png | Bin 0 -> 249 bytes .../main/webapp/static/fusion/images/tab-v-hm.png | Bin 0 -> 317 bytes .../src/main/webapp/static/fusion/images/tab.png | Bin 0 -> 343 bytes .../main/webapp/static/fusion/images/table-add.png | Bin 0 -> 3314 bytes .../webapp/static/fusion/images/table-delete.png | Bin 0 -> 3342 bytes .../webapp/static/fusion/images/table-edit.png | Bin 0 -> 3348 bytes .../src/main/webapp/static/fusion/images/table.png | Bin 0 -> 496 bytes .../main/webapp/static/fusion/images/tabs-bg.png | Bin 0 -> 147 bytes .../webapp/static/fusion/images/toolButton.gif | Bin 0 -> 414 bytes .../webapp/static/fusion/images/toolButton.png | Bin 0 -> 531 bytes .../main/webapp/static/fusion/images/toolbar.png | Bin 0 -> 171 bytes .../src/main/webapp/static/fusion/images/users.png | Bin 0 -> 938 bytes .../webapp/static/fusion/images/warning_type.gif | Bin 0 -> 1055 bytes .../main/webapp/static/fusion/images/webphone.ico | Bin 0 -> 241 bytes .../webapp/static/fusion/images/whiteButton.png | Bin 0 -> 1430 bytes .../js/att_angular_gridster/angular-gridster.js | 2244 + .../js/att_angular_gridster/ui-gridster-tpls.js | 168 + .../main/webapp/static/fusion/js/jquery.resize.js | 139 + .../main/webapp/static/fusion/js/layout/debug.js | 329 + .../static/fusion/js/layout/jquery-latest.js | 9555 +++ .../static/fusion/js/layout/jquery-ui-latest.js | 14879 ++++ .../fusion/js/layout/jquery.layout-latest.js | 6086 ++ .../src/main/webapp/static/fusion/js/moment.min.js | 6 + .../main/webapp/static/fusion/raptor/css/Style.css | 77 + .../static/fusion/raptor/css/bd_quantum_raptor.css | 305 + .../webapp/static/fusion/raptor/css/calendar.css | 97 + .../webapp/static/fusion/raptor/css/dashboard.css | 36 + .../webapp/static/fusion/raptor/css/drupal.css | 83 + .../fusion/raptor/css/form-field-tooltip.css | 12 + .../static/fusion/raptor/css/mobile_raptor.css | 73 + .../webapp/static/fusion/raptor/css/novamap.css | 25 + .../webapp/static/fusion/raptor/css/picker.css | 40 + .../main/webapp/static/fusion/raptor/css/ral.css | 1437 + .../webapp/static/fusion/raptor/css/raptor.css | 62 + .../static/fusion/raptor/css/tree/context-menu.css | 57 + .../webapp/static/fusion/raptor/d3/css/nv.d3.css | 656 + .../main/webapp/static/fusion/raptor/d3/js/cie.js | 155 + .../static/fusion/raptor/d3/js/colorbrewer.js | 302 + .../main/webapp/static/fusion/raptor/d3/js/core.js | 122 + .../static/fusion/raptor/d3/js/crossfilter.js | 1180 + .../static/fusion/raptor/d3/js/crossfilter.min.js | 1 + .../webapp/static/fusion/raptor/d3/js/d3.geom.js | 816 + .../main/webapp/static/fusion/raptor/d3/js/d3.js | 3015 + .../webapp/static/fusion/raptor/d3/js/d3.layout.js | 908 + .../webapp/static/fusion/raptor/d3/js/d3.v2.js | 7033 ++ .../webapp/static/fusion/raptor/d3/js/d3.v2.min.js | 4 + .../webapp/static/fusion/raptor/d3/js/d3.v3.js | 8444 +++ .../webapp/static/fusion/raptor/d3/js/d3.v3.min.js | 1 + .../webapp/static/fusion/raptor/d3/js/fisheye.js | 86 + .../main/webapp/static/fusion/raptor/d3/js/hive.js | 80 + .../webapp/static/fusion/raptor/d3/js/horizon.js | 192 + .../static/fusion/raptor/d3/js/interactiveLayer.js | 251 + .../webapp/static/fusion/raptor/d3/js/intro.js | 1 + .../static/fusion/raptor/d3/js/models/axis-min.js | 1 + .../static/fusion/raptor/d3/js/models/axis.js | 470 + .../static/fusion/raptor/d3/js/models/axis.min.js | 1 + .../fusion/raptor/d3/js/models/boilerplate.js | 104 + .../static/fusion/raptor/d3/js/models/bullet.js | 385 + .../fusion/raptor/d3/js/models/bulletChart.js | 343 + .../raptor/d3/js/models/cumulativeLineChart.js | 782 + .../fusion/raptor/d3/js/models/discreteBar.js | 349 + .../fusion/raptor/d3/js/models/discreteBarChart.js | 333 + .../fusion/raptor/d3/js/models/distribution.js | 148 + .../fusion/raptor/d3/js/models/historicalBar.js | 331 + .../raptor/d3/js/models/historicalBarChart.js | 419 + .../fusion/raptor/d3/js/models/indentedTree.js | 337 + .../static/fusion/raptor/d3/js/models/legend.js | 270 + .../static/fusion/raptor/d3/js/models/line.js | 284 + .../static/fusion/raptor/d3/js/models/lineChart.js | 465 + .../fusion/raptor/d3/js/models/linePlusBarChart.js | 433 + .../d3/js/models/linePlusBarWithFocusChart.js | 658 + .../fusion/raptor/d3/js/models/lineWithFisheye.js | 200 + .../raptor/d3/js/models/lineWithFisheyeChart.js | 297 + .../raptor/d3/js/models/lineWithFocusChart.js | 574 + .../static/fusion/raptor/d3/js/models/multiBar.js | 461 + .../fusion/raptor/d3/js/models/multiBarChart.js | 524 + .../raptor/d3/js/models/multiBarHorizontal.js | 424 + .../raptor/d3/js/models/multiBarHorizontalChart.js | 434 + .../raptor/d3/js/models/multiBarTimeSeries.js | 384 + .../raptor/d3/js/models/multiBarTimeSeriesChart.js | 405 + .../fusion/raptor/d3/js/models/multiChart.js | 452 + .../static/fusion/raptor/d3/js/models/ohlcBar.js | 380 + .../raptor/d3/js/models/parallelCoordinates.js | 239 + .../static/fusion/raptor/d3/js/models/pie.js | 400 + .../static/fusion/raptor/d3/js/models/pie.js.bak | 400 + .../static/fusion/raptor/d3/js/models/pieChart.js | 292 + .../static/fusion/raptor/d3/js/models/scatter.js | 674 + .../fusion/raptor/d3/js/models/scatterChart.js | 628 + .../raptor/d3/js/models/scatterPlusLineChart.js | 620 + .../static/fusion/raptor/d3/js/models/sparkline.js | 194 + .../fusion/raptor/d3/js/models/sparklinePlus.js | 295 + .../fusion/raptor/d3/js/models/stackedArea.js | 368 + .../fusion/raptor/d3/js/models/stackedAreaChart.js | 629 + .../webapp/static/fusion/raptor/d3/js/nv.d3.min.js | 1 + .../webapp/static/fusion/raptor/d3/js/outro.js | 1 + .../webapp/static/fusion/raptor/d3/js/sankey.js | 292 + .../webapp/static/fusion/raptor/d3/js/tooltip.js | 490 + .../webapp/static/fusion/raptor/d3/js/utils.js | 152 + .../static/fusion/raptor/dy3/js/dashed-canvas.js | 176 + .../webapp/static/fusion/raptor/dy3/js/data.js | 63 + .../static/fusion/raptor/dy3/js/dygraph-canvas.js | 816 + .../fusion/raptor/dy3/js/dygraph-combined.js | 2 + .../raptor/dy3/js/dygraph-combined_bak_color.js | 2 + .../static/fusion/raptor/dy3/js/dygraph-dev.js | 45 + .../static/fusion/raptor/dy3/js/dygraph-externs.js | 93 + .../static/fusion/raptor/dy3/js/dygraph-gviz.js | 82 + .../raptor/dy3/js/dygraph-interaction-model.js | 676 + .../static/fusion/raptor/dy3/js/dygraph-layout.js | 349 + .../raptor/dy3/js/dygraph-options-reference.js | 867 + .../static/fusion/raptor/dy3/js/dygraph-options.js | 384 + .../fusion/raptor/dy3/js/dygraph-plugin-base.js | 4 + .../fusion/raptor/dy3/js/dygraph-plugin-install.js | 19 + .../static/fusion/raptor/dy3/js/dygraph-tickers.js | 487 + .../static/fusion/raptor/dy3/js/dygraph-utils.js | 1305 + .../webapp/static/fusion/raptor/dy3/js/dygraph.js | 3857 ++ .../webapp/static/fusion/raptor/dy3/js/excanvas.js | 924 + .../static/fusion/raptor/dy3/js/interaction.js | 333 + .../static/fusion/raptor/dy3/js/interaction.min.js | 1 + .../static/fusion/raptor/dy3/js/interaction_sun.js | 303 + .../static/fusion/raptor/dy3/js/moment.min.js | 6 + .../static/fusion/raptor/dy3/js/phantom-driver.js | 206 + .../static/fusion/raptor/dy3/js/phantom-perf.js | 94 + .../static/fusion/raptor/dy3/js/plugins/README | 113 + .../fusion/raptor/dy3/js/plugins/annotations.js | 182 + .../static/fusion/raptor/dy3/js/plugins/axes.js | 315 + .../fusion/raptor/dy3/js/plugins/chart-labels.js | 202 + .../static/fusion/raptor/dy3/js/plugins/grid.js | 124 + .../static/fusion/raptor/dy3/js/plugins/legend.js | 332 + .../fusion/raptor/dy3/js/plugins/range-selector.js | 852 + .../fusion/raptor/dy3/js/rgbcolor/rgbcolor.js | 257 + .../static/fusion/raptor/dy3/js/stacktrace.js | 411 + .../static/fusion/raptor/dy3/js/strftime/Doxyfile | 243 + .../fusion/raptor/dy3/js/strftime/strftime-min.js | 1 + .../fusion/raptor/dy3/js/strftime/strftime.js | 731 + .../static/fusion/raptor/ebz/date_time_picker.css | 557 + .../static/fusion/raptor/ebz/date_time_picker.js | 277 + .../webapp/static/fusion/raptor/ebz/dynamicform.js | 112 + .../main/webapp/static/fusion/raptor/ebz/moment.js | 3688 + .../webapp/static/fusion/raptor/ebz/multiselect.js | 62 + .../webapp/static/fusion/raptor/ebz/quick_links.js | 33 + .../fusion/raptor/ebz/report_chart_wizard.html | 313 + .../fusion/raptor/ebz/report_chart_wizard.js | 671 + .../static/fusion/raptor/ebz/report_run.html | 67 + .../webapp/static/fusion/raptor/ebz/report_run.js | 293 + .../static/fusion/raptor/ebz/report_search.html | 34 + .../static/fusion/raptor/ebz/report_search.js | 136 + .../static/fusion/raptor/images/RAPTOR_BANNER.jpg | Bin 0 -> 6249 bytes .../static/fusion/raptor/images/accessicon.gif | Bin 0 -> 329 bytes .../webapp/static/fusion/raptor/images/active.gif | Bin 0 -> 338 bytes .../webapp/static/fusion/raptor/images/addbtn.png | Bin 0 -> 662 bytes .../static/fusion/raptor/images/ajax-loader.gif | Bin 0 -> 673 bytes .../static/fusion/raptor/images/arrow_add.gif | Bin 0 -> 469 bytes .../static/fusion/raptor/images/arrow_add_edge.gif | Bin 0 -> 564 bytes .../fusion/raptor/images/arrow_add_multiple.gif | Bin 0 -> 748 bytes .../static/fusion/raptor/images/arrow_add_one.gif | Bin 0 -> 631 bytes .../static/fusion/raptor/images/arrow_back.gif | Bin 0 -> 621 bytes .../static/fusion/raptor/images/arrow_cancel.gif | Bin 0 -> 652 bytes .../static/fusion/raptor/images/arrow_left.gif | Bin 0 -> 382 bytes .../static/fusion/raptor/images/arrow_left2.gif | Bin 0 -> 399 bytes .../static/fusion/raptor/images/arrow_next.gif | Bin 0 -> 609 bytes .../static/fusion/raptor/images/arrow_plus.gif | Bin 0 -> 67 bytes .../fusion/raptor/images/arrow_reorder_all.gif | Bin 0 -> 686 bytes .../fusion/raptor/images/arrow_reorder_all.png | Bin 0 -> 29837 bytes .../static/fusion/raptor/images/arrow_right.gif | Bin 0 -> 381 bytes .../static/fusion/raptor/images/arrow_right2.gif | Bin 0 -> 399 bytes .../static/fusion/raptor/images/arrow_save.gif | Bin 0 -> 606 bytes .../static/fusion/raptor/images/button_import.png | Bin 0 -> 546 bytes .../static/fusion/raptor/images/calendar_icon.gif | Bin 0 -> 552 bytes .../fusion/raptor/images/calendar_icon_nav.gif | Bin 0 -> 538 bytes .../fusion/raptor/images/calendar_icon_nav1.gif | Bin 0 -> 1065 bytes .../static/fusion/raptor/images/calender_icon.gif | Bin 0 -> 552 bytes .../fusion/raptor/images/columnblankdown.gif | Bin 0 -> 192 bytes .../static/fusion/raptor/images/columnblankup.gif | Bin 0 -> 193 bytes .../static/fusion/raptor/images/columndown.gif | Bin 0 -> 124 bytes .../static/fusion/raptor/images/columnup.gif | Bin 0 -> 126 bytes .../static/fusion/raptor/images/crosshairs.png | Bin 0 -> 218 bytes .../static/fusion/raptor/images/csv_icon.gif | Bin 0 -> 447 bytes .../static/fusion/raptor/images/deleteicon.gif | Bin 0 -> 80 bytes .../static/fusion/raptor/images/downloadicon.gif | Bin 0 -> 74 bytes .../static/fusion/raptor/images/excel2007.jpg | Bin 0 -> 761 bytes .../static/fusion/raptor/images/excel2007.png | Bin 0 -> 3186 bytes .../static/fusion/raptor/images/excelicon.gif | Bin 0 -> 1055 bytes .../fusion/raptor/images/excelicon_multi.gif | Bin 0 -> 1026 bytes .../fusion/raptor/images/green-arrow-right.gif | Bin 0 -> 201 bytes .../static/fusion/raptor/images/green-arrow.gif | Bin 0 -> 195 bytes .../static/fusion/raptor/images/grnarrowdn.gif | Bin 0 -> 74 bytes .../static/fusion/raptor/images/grnarrowup.gif | Bin 0 -> 106 bytes .../main/webapp/static/fusion/raptor/images/h.png | Bin 0 -> 380 bytes .../static/fusion/raptor/images/inactive.gif | Bin 0 -> 352 bytes .../webapp/static/fusion/raptor/images/loader.gif | Bin 0 -> 958 bytes .../webapp/static/fusion/raptor/images/loading.gif | Bin 0 -> 4176 bytes .../static/fusion/raptor/images/lookup_arrow.gif | Bin 0 -> 645 bytes .../static/fusion/raptor/images/maps/blue.png | Bin 0 -> 1309 bytes .../static/fusion/raptor/images/maps/green.png | Bin 0 -> 1190 bytes .../static/fusion/raptor/images/maps/lightblue.png | Bin 0 -> 1269 bytes .../fusion/raptor/images/maps/map_iphone.jpg | Bin 0 -> 712 bytes .../static/fusion/raptor/images/maps/orange.png | Bin 0 -> 3413 bytes .../static/fusion/raptor/images/maps/pink.png | Bin 0 -> 1321 bytes .../static/fusion/raptor/images/maps/purple.png | Bin 0 -> 1324 bytes .../static/fusion/raptor/images/maps/red.png | Bin 0 -> 1305 bytes .../static/fusion/raptor/images/maps/yellow.png | Bin 0 -> 1309 bytes .../webapp/static/fusion/raptor/images/minus.gif | Bin 0 -> 75 bytes .../static/fusion/raptor/images/modify_icon.gif | Bin 0 -> 246 bytes .../webapp/static/fusion/raptor/images/page.gif | Bin 0 -> 554 bytes .../static/fusion/raptor/images/pdficon_large.gif | Bin 0 -> 434 bytes .../static/fusion/raptor/images/pdficon_small.gif | Bin 0 -> 361 bytes .../static/fusion/raptor/images/pen_paper.gif | Bin 0 -> 618 bytes .../webapp/static/fusion/raptor/images/plus.gif | Bin 0 -> 78 bytes .../static/fusion/raptor/images/popupicon.gif | Bin 0 -> 79 bytes .../static/fusion/raptor/images/position.png | Bin 0 -> 267 bytes .../webapp/static/fusion/raptor/images/printer.gif | Bin 0 -> 1019 bytes .../static/fusion/raptor/images/progress.gif | Bin 0 -> 734 bytes .../static/fusion/raptor/images/question_mark.jpg | Bin 0 -> 426 bytes .../static/fusion/raptor/images/quickhelp_dk.gif | Bin 0 -> 155 bytes .../static/fusion/raptor/images/quickhelp_lt.gif | Bin 0 -> 897 bytes .../webapp/static/fusion/raptor/images/r_back.gif | Bin 0 -> 918 bytes .../webapp/static/fusion/raptor/images/raptor.jpg | Bin 0 -> 889 bytes .../static/fusion/raptor/images/raptor_logo.gif | Bin 0 -> 3150 bytes .../static/fusion/raptor/images/raptor_logo.jpg | Bin 0 -> 1827 bytes .../static/fusion/raptor/images/required.gif | Bin 0 -> 854 bytes .../static/fusion/raptor/images/shareicon.gif | Bin 0 -> 542 bytes .../main/webapp/static/fusion/raptor/images/sv.png | Bin 0 -> 11373 bytes .../static/fusion/raptor/images/tab_left.gif | Bin 0 -> 137 bytes .../static/fusion/raptor/images/tab_left_sel.gif | Bin 0 -> 106 bytes .../static/fusion/raptor/images/tab_right.gif | Bin 0 -> 138 bytes .../static/fusion/raptor/images/tab_right_sel.gif | Bin 0 -> 104 bytes .../static/fusion/raptor/images/test_run.gif | Bin 0 -> 330 bytes .../webapp/static/fusion/raptor/images/text.gif | Bin 0 -> 141 bytes .../raptor/images/tree/context-menu-gradient.gif | Bin 0 -> 807 bytes .../raptor/images/tree/dhtmlgoodies_folder.gif | Bin 0 -> 1120 bytes .../raptor/images/tree/dhtmlgoodies_minus.gif | Bin 0 -> 197 bytes .../raptor/images/tree/dhtmlgoodies_plus.gif | Bin 0 -> 200 bytes .../raptor/images/tree/dhtmlgoodies_sheet.gif | Bin 0 -> 906 bytes .../images/tree/dhtmlgoodies_sheet_crosstab.gif | Bin 0 -> 1144 bytes .../images/tree/dhtmlgoodies_sheet_dashboard.gif | Bin 0 -> 1164 bytes .../images/tree/dhtmlgoodies_sheet_graph.gif | Bin 0 -> 983 bytes .../fusion/raptor/images/tree/dragDrop_ind1.gif | Bin 0 -> 53 bytes .../fusion/raptor/images/tree/dragDrop_ind2.gif | Bin 0 -> 56 bytes .../fusion/raptor/images/tree/folder_close.gif | Bin 0 -> 283 bytes .../fusion/raptor/images/tree/folder_dots.gif | Bin 0 -> 68 bytes .../fusion/raptor/images/tree/folder_folder.gif | Bin 0 -> 980 bytes .../fusion/raptor/images/tree/folder_lastsub.gif | Bin 0 -> 78 bytes .../fusion/raptor/images/tree/folder_open.gif | Bin 0 -> 286 bytes .../fusion/raptor/images/tree/folder_sub.gif | Bin 0 -> 265 bytes .../fusion/raptor/images/tree/grnarrowleft.gif | Bin 0 -> 854 bytes .../fusion/raptor/images/tree/grnarrowright.gif | Bin 0 -> 845 bytes .../static/fusion/raptor/images/txt_icon.gif | Bin 0 -> 154 bytes .../webapp/static/fusion/raptor/images/uF033.png | Bin 0 -> 520 bytes .../webapp/static/fusion/raptor/images/uF034.png | Bin 0 -> 536 bytes .../webapp/static/fusion/raptor/images/uF035.png | Bin 0 -> 487 bytes .../webapp/static/fusion/raptor/images/uF036.png | Bin 0 -> 482 bytes .../fusion/raptor/img/BorderLayout-24x24.png | Bin 0 -> 1369 bytes .../static/fusion/raptor/img/Calendar-16x16.png | Bin 0 -> 552 bytes .../static/fusion/raptor/img/DeleteCross-16x16.png | Bin 0 -> 750 bytes .../webapp/static/fusion/raptor/img/addbtn.png | Bin 0 -> 662 bytes .../static/fusion/raptor/img/button_import.png | Bin 0 -> 546 bytes .../fusion/raptor/img/copyicon-highlighted.png | Bin 0 -> 264 bytes .../webapp/static/fusion/raptor/img/copyicon.png | Bin 0 -> 235 bytes .../static/fusion/raptor/img/cross-small.png | Bin 0 -> 291 bytes .../webapp/static/fusion/raptor/img/csv_icon.gif | Bin 0 -> 447 bytes .../webapp/static/fusion/raptor/img/csv_icon.jpg | Bin 0 -> 632 bytes .../webapp/static/fusion/raptor/img/csv_icon.png | Bin 0 -> 938 bytes .../fusion/raptor/img/deleteicon-highlighted.gif | Bin 0 -> 592 bytes .../fusion/raptor/img/deleteicon-highlighted.png | Bin 0 -> 566 bytes .../webapp/static/fusion/raptor/img/deleteicon.gif | Bin 0 -> 579 bytes .../static/fusion/raptor/img/downloadicon.gif | Bin 0 -> 74 bytes .../webapp/static/fusion/raptor/img/editicon.gif | Bin 0 -> 360 bytes .../webapp/static/fusion/raptor/img/excel2007.jpg | Bin 0 -> 761 bytes .../webapp/static/fusion/raptor/img/excelicon.gif | Bin 0 -> 1055 bytes .../static/fusion/raptor/img/excelicon_multi.gif | Bin 0 -> 1026 bytes .../static/fusion/raptor/img/executeicon.png | Bin 0 -> 1076 bytes .../static/fusion/raptor/img/file_import.png | Bin 0 -> 653 bytes .../static/fusion/raptor/img/pdficon_small.gif | Bin 0 -> 361 bytes .../webapp/static/fusion/raptor/img/pen_paper.gif | Bin 0 -> 618 bytes .../static/fusion/raptor/img/pencil-small.png | Bin 0 -> 309 bytes .../webapp/static/fusion/raptor/img/report-add.png | Bin 0 -> 724 bytes .../static/fusion/raptor/img/report-favorite.png | Bin 0 -> 693 bytes .../webapp/static/fusion/raptor/img/report-my.png | Bin 0 -> 739 bytes .../static/fusion/raptor/img/report-public.png | Bin 0 -> 776 bytes .../webapp/static/fusion/raptor/img/report.png | Bin 0 -> 563 bytes .../webapp/static/fusion/raptor/img/reports.png | Bin 0 -> 769 bytes .../webapp/static/fusion/raptor/img/search.gif | Bin 0 -> 223 bytes .../webapp/static/fusion/raptor/img/search.png | Bin 0 -> 3501 bytes .../webapp/static/fusion/raptor/img/tick-small.png | Bin 0 -> 283 bytes .../static/fusion/raptor/js/CalendarPopup.js | 1486 + .../main/webapp/static/fusion/raptor/js/ajax.js | 214 + .../fusion/raptor/js/ajax_dynamic_content.js | 97 + .../static/fusion/raptor/js/cingular_button.js | 217 + .../main/webapp/static/fusion/raptor/js/drupal.js | 1018 + .../static/fusion/raptor/js/editabledropdown.js | 363 + .../static/fusion/raptor/js/form-field-tooltip.js | 715 + .../main/webapp/static/fusion/raptor/js/gmap.js | 634 + .../main/webapp/static/fusion/raptor/js/jquery.js | 4376 ++ .../webapp/static/fusion/raptor/js/jquery.min.js | 154 + .../static/fusion/raptor/js/label_quantum.js | 5 + .../webapp/static/fusion/raptor/js/nova_button.js | 1184 + .../static/fusion/raptor/js/other_scripts.js | 331 + .../fusion/raptor/js/persist_table_header.js | 47 + .../static/fusion/raptor/js/prototype-1.6.0.3.js | 4320 ++ .../main/webapp/static/fusion/raptor/js/raptor.js | 314 + .../static/fusion/raptor/js/rounded-corners.js | 353 + .../main/webapp/static/fusion/raptor/js/script.js | 482 + .../webapp/static/fusion/raptor/js/tree/ajax.js | 194 + .../webapp/static/fusion/raptor/uigrid/ui-grid.css | 1971 + .../webapp/static/fusion/raptor/uigrid/ui-grid.eot | Bin 0 -> 8728 bytes .../webapp/static/fusion/raptor/uigrid/ui-grid.js | 26735 ++++++++ .../webapp/static/fusion/raptor/uigrid/ui-grid.svg | 34 + .../webapp/static/fusion/raptor/uigrid/ui-grid.ttf | Bin 0 -> 8564 bytes .../static/fusion/raptor/uigrid/ui-grid.woff | Bin 0 -> 4792 bytes .../static/fusion/sample/css/images/blank.gif | Bin 0 -> 49 bytes .../webapp/static/fusion/sample/css/scribble.css | 40 + .../webapp/static/fusion/sample/css/slider.css | 142 + .../static/fusion/sample/css/spacegallery.css | 18 + .../webapp/static/fusion/sample/css/welcome.css | 169 + .../static/fusion/sample/html/area_chart.html | 49 + .../static/fusion/sample/html/bar_chart.html | 95 + .../static/fusion/sample/html/d3_gauges_demo.html | 39 + .../fusion/sample/html/data/speedometer2.csv | 16 + .../fusion/sample/html/data/speedometer3.csv | 2 + .../static/fusion/sample/html/data/worddata.csv | 22 + .../webapp/static/fusion/sample/html/donut_d3.html | 43 + .../static/fusion/sample/html/js/area_chart.min.js | 1 + .../static/fusion/sample/html/js/donut.min.js | 1 + .../static/fusion/sample/html/js/gauges.min.js | 1 + .../static/fusion/sample/html/js/line_chart.min.js | 1 + .../static/fusion/sample/html/js/pie_chart.min.js | 1 + .../static/fusion/sample/html/js/worddata.min.js | 1 + .../static/fusion/sample/html/line_chart.html | 49 + .../static/fusion/sample/html/pie_chart.html | 38 + .../static/fusion/sample/html/wordcloud.html | 37 + .../static/fusion/sample/images/Calendar-16x16.png | Bin 0 -> 552 bytes .../static/fusion/sample/images/arrow-next.png | Bin 0 -> 1561 bytes .../static/fusion/sample/images/arrow-prev.png | Bin 0 -> 1557 bytes .../images/carousel/slide_b_drive_test_map.png | Bin 0 -> 202465 bytes .../sample/images/carousel/slide_b_eppt_county.png | Bin 0 -> 21222 bytes .../images/carousel/slide_b_eppt_regression.png | Bin 0 -> 11536 bytes .../images/carousel/slide_b_ios_throughput.png | Bin 0 -> 26131 bytes .../sample/images/carousel/slide_b_lata_map.png | Bin 0 -> 192031 bytes .../images/carousel/slide_b_lata_map_legend.png | Bin 0 -> 3021 bytes .../images/carousel/slide_b_nova_sdn_map.png | Bin 0 -> 179361 bytes .../static/fusion/sample/images/copyicon.png | Bin 0 -> 235 bytes .../static/fusion/sample/images/deleteicon.gif | Bin 0 -> 579 bytes .../static/fusion/sample/images/example-frame.png | Bin 0 -> 33699 bytes .../webapp/static/fusion/sample/images/loading.gif | Bin 0 -> 6820 bytes .../static/fusion/sample/images/tunnels/1_mon.png | Bin 0 -> 22762 bytes .../static/fusion/sample/images/tunnels/2_tue.png | Bin 0 -> 22772 bytes .../static/fusion/sample/images/tunnels/3_wed.png | Bin 0 -> 24012 bytes .../static/fusion/sample/images/tunnels/4_thu.png | Bin 0 -> 23902 bytes .../static/fusion/sample/images/tunnels/5_fri.png | Bin 0 -> 22349 bytes .../static/fusion/sample/images/tunnels/6_sat.png | Bin 0 -> 23674 bytes .../static/fusion/sample/images/tunnels/7_sun.png | Bin 0 -> 22845 bytes .../fusion/sample/images/tunnels/BH_DLSTX_IN.png | Bin 0 -> 10575 bytes .../fusion/sample/images/tunnels/BH_DLSTX_OUT.png | Bin 0 -> 10460 bytes .../static/fusion/sample/images/tunnels/BH_Nat.png | Bin 0 -> 10420 bytes .../fusion/sample/images/tunnels/BH_Nat_Def.png | Bin 0 -> 8941 bytes .../sample/images/tunnels/BH_Nat_Priority.png | Bin 0 -> 10590 bytes .../webapp/static/fusion/sample/js/FusionCharts.js | 361 + .../main/webapp/static/fusion/sample/js/charts.js | 132 + .../fusion/sample/js/jquery.flexslider-min.js | 5 + .../webapp/static/fusion/sample/js/scribble.js | 19 + .../static/fusion/sample/js/slides.min.jquery.js | 20 + .../webapp/static/fusion/sample/js/spacegallery.js | 235 + .../fusion/sample/org_chart/css/bootstrap.min.css | 351 + .../static/fusion/sample/org_chart/css/custom.css | 97 + .../sample/org_chart/css/jquery.jOrgChart.css | 51 + .../fusion/sample/org_chart/css/prettify.css | 1 + .../static/fusion/sample/org_chart/example.html | 85 + .../fusion/sample/org_chart/example_vsp.html | 88 + .../static/fusion/sample/org_chart/images/bkgd.png | Bin 0 -> 133 bytes .../fusion/sample/org_chart/images/raspberry.jpg | Bin 0 -> 5755 bytes .../fusion/sample/org_chart/jquery.jOrgChart.js | 267 + .../static/fusion/sample/org_chart/prettify.js | 28 + .../src/main/webapp/static/js/jquery-1.10.2.js | 9789 +++ .../src/main/webapp/static/js/jquery-ui.js | 16617 +++++ .../src/main/webapp/static/js/jquery.mask.min.js | 12 + .../src/main/webapp/static/js/modalService.js | 169 + ecomp-sdk-app/src/main/webapp/static/js/search.js | 829 + .../java/org/openecomp/portalapp/SanityTest.java | 20 + .../controller/CollaborationControllerTest.java | 27 + .../openecomp/portalapp/controller/NetMapTest.java | 19 + .../portalapp/service/ProfileServiceTest.java | 37 + .../core/MockApplicationContextTestSuite.java | 126 + .../services/WorkflowScheduleServiceTest.java | 41 + ecomp-sdk-app/xacml.admin.properties | 204 + packages/base/pom.xml | 251 + packages/base/src/assembly/zip.xml | 84 + packages/base/src/files/bin/backup.sh | 151 + packages/base/src/files/bin/certtool.sh | 207 + packages/base/src/files/bin/java/log4j.properties | 31 + packages/base/src/files/bin/monitor.sh | 139 + packages/base/src/files/bin/policy.sh | 275 + packages/base/src/files/etc/cron.d/logrotate.cron | 1 + packages/base/src/files/etc/cron.d/monitor.cron | 1 + .../base/src/files/etc/logrotate.d/monitor.conf | 7 + packages/base/src/files/etc/monitor/monitor.cfg | 16 + packages/base/src/files/etc/profile.d/env.sh | 27 + packages/base/src/files/etc/profile.d/su.cfg | 1 + .../src/files/install/mysql/bin/cleanup_policy.sh | 92 + .../base/src/files/install/mysql/bin/db_backup.sh | 84 + .../src/files/install/mysql/bin/db_backup_data.sh | 84 + .../files/install/mysql/bin/db_backup_remote.sh | 88 + .../base/src/files/install/mysql/bin/db_restore.sh | 97 + .../src/files/install/mysql/bin/db_restore_data.sh | 103 + .../base/src/files/install/mysql/bin/db_upgrade.sh | 150 + .../files/install/mysql/bin/db_upgrade_remote.sh | 173 + .../install/mysql/data/161000_upgrade_script.sql | 6443 ++ .../files/install/servers/brmsgw/client.properties | 22 + .../files/install/servers/brmsgw/config.properties | 87 + .../servers/brmsgw/config/policyLogger.properties | 44 + .../src/files/install/servers/brmsgw/init.d/brmsgw | 134 + .../servers/common/logparser/init.d/logparserd | 131 + .../install/servers/common/tomcat/bin/setenv.sh | 31 + .../install/servers/common/tomcat/conf/server.xml | 167 + .../install/servers/common/tomcat/init.d/tomcatd | 91 + .../files/install/servers/configs/conf/server.xml | 169 + .../install/servers/console/bin/JSONConfig.json | 132 + .../install/servers/console/bin/Policy-Admin.xml | 565 + .../console/bin/config/policyLogger.properties | 44 + .../install/servers/console/bin/model.properties | 22 + .../install/servers/console/bin/sql/log.h2.db | Bin 0 -> 2127872 bytes .../install/servers/console/bin/sql/xacml.h2.db | Bin 0 -> 292864 bytes .../Config_BRMS_Param_BRMSParamvFWDemoPolicy.1.xml | 93 + .../Config_BRMS_Param_BRMSParamvLBDemoPolicy.1.xml | 93 + .../admin/repository/com/Config_MS_vFirewall.1.xml | 114 + .../repository/com/Config_MS_vLoadBalancer.1.xml | 114 + .../servers/console/bin/xacml.admin.properties | 203 + .../files/install/servers/console/conf/server.xml | 172 + .../ecomp/WEB-INF/classes/portal.properties | 73 + .../servers/ecomp/WEB-INF/conf/system.properties | 84 + .../ecomp/app/policyApp/Properties/config.json | 3 + .../install/servers/pap/bin/autopush.properties | 22 + .../servers/pap/bin/config/policyLogger.properties | 44 + .../files/install/servers/pap/bin/test.properties | 21 + .../install/servers/pap/bin/xacml.pap.properties | 132 + ....Config_BRMS_Param_BRMSParamvFWDemoPolicy.1.txt | 1116 + ....Config_BRMS_Param_BRMSParamvLBDemoPolicy.1.txt | 1116 + .../webapps/Config/com.Config_MS_vFirewall.1.json | 1 + .../Config/com.Config_MS_vLoadBalancer.1.json | 1 + .../paplp/bin/config/policyLogger.properties | 44 + .../install/servers/paplp/bin/parserlog.properties | 57 + .../servers/pdp/bin/config/policyLogger.properties | 44 + .../install/servers/pdp/bin/xacml.pdp.properties | 125 + .../pdplp/bin/config/policyLogger.properties | 44 + .../install/servers/pdplp/bin/parserlog.properties | 57 + .../install/servers/pypdp/bin/client.properties | 22 + .../install/servers/pypdp/bin/config.properties | 51 + .../pypdp/bin/config/policyLogger.properties | 44 + packages/base/src/files/m2/settings.xml | 82 + packages/install/pom.xml | 71 + packages/install/src/assembly/zip.xml | 42 + packages/install/src/files/base.conf | 19 + packages/install/src/files/brmsgw.conf | 42 + packages/install/src/files/console.conf | 134 + packages/install/src/files/mysql.conf | 5 + packages/install/src/files/pap.conf | 52 + packages/install/src/files/paplp.conf | 12 + packages/install/src/files/pdp.conf | 36 + packages/install/src/files/pdplp.conf | 12 + packages/install/src/files/pypdp.conf | 25 + packages/pom.xml | 66 + pom.xml | 233 + project-configs/maven/conf/settings.xml | 165 + version.properties | 35 + 3879 files changed, 903905 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 .gitreview create mode 100644 BRMSGateway/config.properties create mode 100644 BRMSGateway/policyLogger.properties create mode 100644 BRMSGateway/pom.xml create mode 100644 BRMSGateway/src/main/java/org/openecomp/policy/brmsInterface/BRMSGateway.java create mode 100644 BRMSGateway/src/main/java/org/openecomp/policy/brmsInterface/BRMSHandler.java create mode 100644 BRMSGateway/src/main/java/org/openecomp/policy/brmsInterface/BRMSPush.java create mode 100644 BRMSGateway/src/main/java/org/openecomp/policy/brmsInterface/ControllerPOJO.java create mode 100644 BRMSGateway/src/main/java/org/openecomp/policy/brmsInterface/NotificationPOJO.java create mode 100644 BRMSGateway/src/main/resources/log4j.properties create mode 100644 BRMSGateway/src/main/resources/logback.xml create mode 100644 ECOMP-PAP-REST/.gitignore create mode 100644 ECOMP-PAP-REST/WebContent/META-INF/MANIFEST.MF create mode 100644 ECOMP-PAP-REST/WebContent/README.txt create mode 100644 ECOMP-PAP-REST/autopush.properties create mode 100644 ECOMP-PAP-REST/dictionaryItemsAPI.json create mode 100644 ECOMP-PAP-REST/policyLogger.properties create mode 100644 ECOMP-PAP-REST/pom.xml create mode 100644 ECOMP-PAP-REST/src/main/java/hibernate.cfg.xml create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/HibernateSession.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/WebConfig.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/XACMLPapServlet.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/adapters/GridData.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/adapters/PolicyRestAdapter.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/adapters/package-info.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/ActionPolicy.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/AutoPushPolicy.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/ClosedLoopPolicy.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/ConfigPolicy.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/CreateBrmsParamPolicy.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/CreateBrmsRawPolicy.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/CreateClosedLoopPerformanceMetrics.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/CreateNewMicroSerivceModel.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/DecisionPolicy.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/FirewallConfigPolicy.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/MicroServiceConfigPolicy.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/Policy.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/PolicyDBDao.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/PolicyDBDaoTransaction.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/package-info.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/ActionPolicyDictionaryController.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/BRMSDictionaryController.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/CheckDictionaryDuplicateEntries.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/ClosedLoopDictionaryController.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/DecisionPolicyDictionaryController.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/DescriptiveDictionaryController.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/DictionaryController.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/DictionaryImportController.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/EnforcerDictionaryController.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/FirewallDictionaryController.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/MicroServiceDictionaryController.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/PolicyScopeDictionaryController.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/SafePolicyController.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/package-info.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/ActionListDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/ActionPolicyDictDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/AddressGroupDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/AttributeDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/BRMSParamTemplateDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/CategoryDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/DCAEUUIDDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/DecisionPolicyDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/DescriptiveScopeDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/EcompNameDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/EnforcerPolicyDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/FirewallDictionaryListDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/GroupPolicyScopeListDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/MicroServiceConfigNameDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/MicroServiceLocationDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/MicroServiceModelsDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/PEPOptionsDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/PolicyScopeClosedLoopDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/PolicyScopeResourceDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/PolicyScopeServiceDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/PolicyScopeTypeDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/PortListDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/PrefixListDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/ProtocolListDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/RiskTypeDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/SafePolicyWarningDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/SecurityZoneDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/ServiceDictionaryDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/ServiceGroupDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/ServiceListDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/SiteDictionaryDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/TermListDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/UserInfoDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/VNFTypeDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/VSCLActionDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/VarbindDictionaryDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/ZoneDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/model/PDPPolicyContainer.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/model/RemoveGroupPolicy.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/model/package-info.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/util/JPAUtils.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/util/JsonMessage.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/util/PolicyContainer.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/util/PolicyItemSetChangeNotifier.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/restAuth/AuthenticationService.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/restAuth/CheckPDP.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/restAuth/PAPAuthenticationFilter.java create mode 100644 ECOMP-PAP-REST/src/main/resources/META-INF/drop.ddl create mode 100644 ECOMP-PAP-REST/src/main/resources/META-INF/persistence.xml create mode 100644 ECOMP-PAP-REST/src/main/resources/log4j.properties create mode 100644 ECOMP-PAP-REST/src/main/resources/logback.xml create mode 100644 ECOMP-PAP-REST/src/main/resources/spring.xml create mode 100644 ECOMP-PAP-REST/src/test/java/org/openecomp/policy/pap/ia/DbAuditCompareEntriesTest.java create mode 100644 ECOMP-PAP-REST/src/test/java/org/openecomp/policy/pap/xacml/rest/XACMLPapServletTest.java create mode 100644 ECOMP-PAP-REST/src/test/java/org/openecomp/policy/pap/xacml/rest/components/PolicyDBDaoTest.java create mode 100644 ECOMP-PAP-REST/src/test/java/org/openecomp/policy/pap/xacml/rest/jpa/PolicyEntityTest.java create mode 100644 ECOMP-PAP-REST/test.properties create mode 100644 ECOMP-PAP-REST/xacml.pap.properties create mode 100644 ECOMP-PAP-REST/xacml.pap.test.properties create mode 100644 ECOMP-PDP-REST/.gitignore create mode 100644 ECOMP-PDP-REST/WebContent/META-INF/MANIFEST.MF create mode 100644 ECOMP-PDP-REST/WebContent/WEB-INF/.gitignore create mode 100644 ECOMP-PDP-REST/config_testing/xacml.pip.properties create mode 100644 ECOMP-PDP-REST/config_testing/xacml.policy.properties create mode 100644 ECOMP-PDP-REST/policyLogger.properties create mode 100644 ECOMP-PDP-REST/pom.xml create mode 100644 ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/PapUrlResolver.java create mode 100644 ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/XACMLPdpLoader.java create mode 100644 ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/XACMLPdpRegisterThread.java create mode 100644 ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/XACMLPdpServlet.java create mode 100644 ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/impl/XACMLPdpPIPFinderFactory.java create mode 100644 ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/impl/XACMLPdpPolicyFinderFactory.java create mode 100644 ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/jmx/PdpRestMBeanListener.java create mode 100644 ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/jmx/PdpRestMonitor.java create mode 100644 ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/jmx/PdpRestMonitorMBean.java create mode 100644 ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/notifications/ManualNotificationUpdateThread.java create mode 100644 ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/notifications/Notification.java create mode 100644 ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/notifications/NotificationController.java create mode 100644 ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/notifications/NotificationServer.java create mode 100644 ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/notifications/Removed.java create mode 100644 ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/notifications/Updated.java create mode 100644 ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/notifications/package-info.java create mode 100644 ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/restAuth/AuthenticationService.java create mode 100644 ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/restAuth/PDPAuthenticationFilter.java create mode 100644 ECOMP-PDP-REST/src/main/resources/log4j.properties create mode 100644 ECOMP-PDP-REST/src/main/resources/logback.xml create mode 100644 ECOMP-PDP-REST/src/test/java/org/openecomp/policy/pdp/rest/PapUrlResolverTest.java create mode 100644 ECOMP-PDP-REST/src/test/java/org/openecomp/policy/pdp/rest/XACMLPdpServletTest.java create mode 100644 ECOMP-PDP-REST/xacml.pdp.properties create mode 100644 ECOMP-PDP/.gitignore create mode 100644 ECOMP-PDP/logging.properties create mode 100644 ECOMP-PDP/policyLogger.properties create mode 100644 ECOMP-PDP/pom.xml create mode 100644 ECOMP-PDP/sql/xacmlTest.mv.db create mode 100644 ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/action/FindAction.java create mode 100644 ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/action/package-info.java create mode 100644 ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/custom/EcompFunctionDefinitionFactory.java create mode 100644 ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/pdp/ECOMPPDPEngine.java create mode 100644 ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/pdp/ECOMPPDPEngineFactory.java create mode 100644 ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/pdp/std/functions/FunctionDefinitionCustomRegexpMatch.java create mode 100644 ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/pdp/std/functions/PolicyList.java create mode 100644 ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionAccessPermittedTest.java create mode 100644 ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionArithmeticTest.java create mode 100644 ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionBagIsInTest.java create mode 100644 ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionBagOneAndOnlyTest.java create mode 100644 ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionBagSizeTest.java create mode 100644 ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionBagTest.java create mode 100644 ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionBaseTest.java create mode 100644 ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionComparisonTest.java create mode 100644 ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionDateTimeArithmeticTest.java create mode 100644 ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionEqualityTest.java create mode 100644 ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionHigherOrderBagTest.java create mode 100644 ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionHomogeneousSimpleTest.java create mode 100644 ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionLogicalTest.java create mode 100644 ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionNumberTypeConversionTest.java create mode 100644 ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionRegexpMatchTest.java create mode 100644 ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionSetTest.java create mode 100644 ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionSpecialMatchTest.java create mode 100644 ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionStringConversionTest.java create mode 100644 ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionStringEqualIgnoreCaseTest.java create mode 100644 ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionStringFunctionsTest.java create mode 100644 ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionStringNormalizeTest.java create mode 100644 ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionURIStringConcatenateTest.java create mode 100644 ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionXPathTest.java create mode 100644 ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/PDPTest.java create mode 100644 ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/TestRunner.java create mode 100644 ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/conformance/Conformance.java create mode 100644 ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/conformance/ConformancePIPEngine.java create mode 100644 ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/conformance/ConformanceRepository.java create mode 100644 ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/conformance/ConformanceScopeResolver.java create mode 100644 ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/conformance/ConformanceTest.java create mode 100644 ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/conformance/ConformanceTestEngine.java create mode 100644 ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/conformance/ConformanceTestResult.java create mode 100644 ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/conformance/ConformanceTestSet.java create mode 100644 ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/conformance/ResponseMatchResult.java create mode 100644 ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/conformance/ResultMatchResult.java create mode 100644 ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/custom/CustomDataTypeFactory.java create mode 100644 ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/custom/CustomFunctionDefinitionFactory.java create mode 100644 ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/custom/DataTypePrivateKey.java create mode 100644 ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/custom/DataTypePublicKey.java create mode 100644 ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/custom/FunctionDefinitionDecrypt.java create mode 100644 ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/custom/TestBase.java create mode 100644 ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/custom/TestCustom.java create mode 100644 ECOMP-PDP/src/test/resources/log4j.properties create mode 100644 ECOMP-PDP/src/test/resources/logback.xml create mode 100644 ECOMP-PDP/src/test/resources/logging.properties create mode 100644 ECOMP-PDP/src/test/resources/xacml.pip.properties create mode 100644 ECOMP-PDP/src/test/resources/xacml.policy.properties create mode 100644 ECOMP-PDP/testclient.properties create mode 100644 ECOMP-PDP/testpdp.properties create mode 100644 ECOMP-PDP/xacml.pap.properties create mode 100644 ECOMP-PDP/xacml.pdp.properties create mode 100644 ECOMP-PDP/xacml.properties create mode 100644 ECOMP-REST/.gitignore create mode 100644 ECOMP-REST/policyLogger.properties create mode 100644 ECOMP-REST/pom.xml create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/XACMLRest.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/XACMLRestProperties.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/XacmlAdminAuthorization.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/ActionListDao.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/ActionPolicyDictDao.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/AddressGroupDao.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/AttributeDao.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/BRMSParamTemplateDao.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/CategoryDao.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/DCAEUUIDDao.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/DecisionPolicyDao.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/DescriptiveScopeDao.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/EcompNameDao.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/EnforcerPolicyDao.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/FirewallDictionaryListDao.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/GroupPolicyScopeListDao.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/MicroServiceConfigNameDao.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/MicroServiceLocationDao.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/MicroServiceModelsDao.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/PEPOptionsDao.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/PolicyScopeClosedLoopDao.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/PolicyScopeResourceDao.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/PolicyScopeServiceDao.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/PolicyScopeTypeDao.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/PortListDao.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/PrefixListDao.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/ProtocolListDao.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/RiskTypeDao.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/SafePolicyWarningDao.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/SecurityZoneDao.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/ServiceDictionaryDao.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/ServiceGroupDao.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/ServiceListDao.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/SiteDictionaryDao.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/TermListDao.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/UserInfoDao.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/VNFTypeDao.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/VSCLActionDao.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/VarbindDictionaryDao.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/ZoneDao.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/package-info.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/ActionBodyEntity.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/ActionList.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/ActionPolicyDict.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/AddressGroup.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/Attribute.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/AttributeAssignment.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/BRMSParamTemplate.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/Category.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/ClosedLoopD2Services.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/ClosedLoopSite.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/ConfigurationDataEntity.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/ConstraintType.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/ConstraintValue.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/DCAEUsers.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/DCAEuuid.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/DatabaseLockEntity.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/Datatype.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/DecisionSettings.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/DescriptiveScope.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/EcompName.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/EnforcingType.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/FirewallDictionaryList.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/FunctionArgument.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/FunctionDefinition.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/GlobalRoleSettings.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/GroupEntity.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/GroupPolicyScopeList.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/GroupServiceList.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/MicroServiceConfigName.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/MicroServiceLocation.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/MicroServiceModels.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/Obadvice.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/ObadviceExpression.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PEPOptions.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PIPConfigParam.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PIPConfiguration.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PIPResolver.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PIPResolverParam.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PIPType.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PREFIXLIST.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PdpEntity.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PolicyAlgorithms.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PolicyDBDaoEntity.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PolicyEditorScopes.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PolicyEntity.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PolicyManagement.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PolicyRoles.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PolicyScopeClosedLoop.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PolicyScopeResource.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PolicyScopeService.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PolicyScopeType.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PolicyScore.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PolicyVersion.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PortList.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/ProtocolList.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/RemoteCatalogValues.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/RiskType.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/RuleAlgorithms.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/SafePolicyWarning.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/SecurityZone.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/ServiceList.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/SystemLogDB.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/TermList.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/UserInfo.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/VMType.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/VNFType.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/VSCLAction.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/VarbindDictionary.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/WatchPolicyNotificationTable.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/Zone.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/package-info.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/util/LockdownListener.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/util/MSAttributeObject.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/util/MSAttributeValue.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/util/MSModelUtitils.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/util/ModelObject.java create mode 100644 ECOMP-REST/src/main/java/org/openecomp/policy/rest/util/Webapps.java create mode 100644 ECOMP-REST/src/test/java/org/openecomp/policy/rest/XACMLRestTest.java create mode 100644 ECOMP-TEST/.gitignore create mode 100644 ECOMP-TEST/policyLogger.properties create mode 100644 ECOMP-TEST/pom.xml create mode 100644 ECOMP-TEST/sql/xacmlTest.mv.db create mode 100644 ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/TestBase.java create mode 100644 ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/annotations/TestAnnotation.java create mode 100644 ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/conformance/Conformance.java create mode 100644 ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/conformance/ConformancePIPEngine.java create mode 100644 ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/conformance/ConformanceRepository.java create mode 100644 ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/conformance/ConformanceScopeResolver.java create mode 100644 ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/conformance/ConformanceTest.java create mode 100644 ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/conformance/ConformanceTestEngine.java create mode 100644 ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/conformance/ConformanceTestResult.java create mode 100644 ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/conformance/ConformanceTestSet.java create mode 100644 ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/conformance/ResponseMatchResult.java create mode 100644 ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/conformance/ResultMatchResult.java create mode 100644 ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/custom/CustomDataTypeFactory.java create mode 100644 ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/custom/CustomFunctionDefinitionFactory.java create mode 100644 ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/custom/DataTypePrivateKey.java create mode 100644 ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/custom/DataTypePublicKey.java create mode 100644 ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/custom/FunctionDefinitionDecrypt.java create mode 100644 ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/custom/TestCustom.java create mode 100644 ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/policy/TestPolicy.java create mode 100644 ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/dom/DOMResponseConformanceTest.java create mode 100644 ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/dom/DOMResponseTest.java create mode 100644 ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionAccessPermittedTest.java create mode 100644 ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionArithmeticTest.java create mode 100644 ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionBagIsInTest.java create mode 100644 ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionBagOneAndOnlyTest.java create mode 100644 ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionBagSizeTest.java create mode 100644 ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionBagTest.java create mode 100644 ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionBaseTest.java create mode 100644 ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionComparisonTest.java create mode 100644 ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionDateTimeArithmeticTest.java create mode 100644 ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionEqualityTest.java create mode 100644 ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionHigherOrderBagTest.java create mode 100644 ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionHomogeneousSimpleTest.java create mode 100644 ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionLogicalTest.java create mode 100644 ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionNumberTypeConversionTest.java create mode 100644 ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionRegexpMatchTest.java create mode 100644 ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionSetTest.java create mode 100644 ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionSpecialMatchTest.java create mode 100644 ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionStringConversionTest.java create mode 100644 ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionStringEqualIgnoreCaseTest.java create mode 100644 ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionStringFunctionsTest.java create mode 100644 ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionStringNormalizeTest.java create mode 100644 ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionURIStringConcatenateTest.java create mode 100644 ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionXPathTest.java create mode 100644 ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/json/RequestCategoryTest.java create mode 100644 ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/json/RequestConformanceTest.java create mode 100644 ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/json/RequestDefaultCategoryTest.java create mode 100644 ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/json/RequestMainTest.java create mode 100644 ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/json/ResponseConformanceTest.java create mode 100644 ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/json/ResponseTest.java create mode 100644 ECOMP-TEST/src/test/resources/log4j.properties create mode 100644 ECOMP-TEST/src/test/resources/logging.properties create mode 100644 ECOMP-TEST/src/test/resources/xacml.pip.properties create mode 100644 ECOMP-TEST/src/test/resources/xacml.policy.properties create mode 100644 ECOMP-TEST/testclient.properties create mode 100644 ECOMP-TEST/testpdp.properties create mode 100644 ECOMP-TEST/xacml.pap.properties create mode 100644 ECOMP-TEST/xacml.pdp.properties create mode 100644 ECOMP-XACML/.gitignore create mode 100644 ECOMP-XACML/policyLogger.properties create mode 100644 ECOMP-XACML/pom.xml create mode 100644 ECOMP-XACML/sql/xacmlTest.mv.db create mode 100644 ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/api/XACMLErrorConstants.java create mode 100644 ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/api/pap/ECOMPPapEngineFactory.java create mode 100644 ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/api/pap/EcompPAPPolicy.java create mode 100644 ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/api/pap/EcompPDP.java create mode 100644 ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/api/pap/EcompPDPGroup.java create mode 100644 ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/api/pap/PAPPolicyEngine.java create mode 100644 ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/std/pap/StdEngine.java create mode 100644 ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/std/pap/StdEngineFactory.java create mode 100644 ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/std/pap/StdPAPPolicy.java create mode 100644 ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/std/pap/StdPDP.java create mode 100644 ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/std/pap/StdPDPGroup.java create mode 100644 ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/std/pap/StdPDPGroupStatus.java create mode 100644 ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/std/pap/StdPDPItemSetChangeNotifier.java create mode 100644 ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/std/pap/StdPDPPIPConfig.java create mode 100644 ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/std/pap/StdPDPPolicy.java create mode 100644 ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/std/pap/StdPDPStatus.java create mode 100644 ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/std/pip/engines/aaf/AAFEngine.java create mode 100644 ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/util/MetricsUtil.java create mode 100644 ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/util/XACMLPolicyScanner.java create mode 100644 ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/util/XACMLPolicyWriter.java create mode 100644 ECOMP-XACML/src/main/resources/xacml.properties create mode 100644 ECOMP-XACML/src/test/java/org/openecomp/policy/xacml/test/DOMResponseConformanceTest.java create mode 100644 ECOMP-XACML/src/test/java/org/openecomp/policy/xacml/test/DOMResponseTest.java create mode 100644 ECOMP-XACML/src/test/java/org/openecomp/policy/xacml/test/TestAnnotation.java create mode 100644 ECOMP-XACML/src/test/java/org/openecomp/policy/xacml/test/TestBase.java create mode 100644 ECOMP-XACML/src/test/java/org/openecomp/policy/xacml/test/TestPolicy.java create mode 100644 ECOMP-XACML/src/test/java/org/openecomp/policy/xacml/test/XACMLEngineTest.java create mode 100644 ECOMP-XACML/src/test/java/org/openecomp/policy/xacml/test/components/XACMLPDPPolicyTest.java create mode 100644 ECOMP-XACML/src/test/java/org/openecomp/policy/xacml/test/json/RequestCategoryTest.java create mode 100644 ECOMP-XACML/src/test/java/org/openecomp/policy/xacml/test/json/RequestConformanceTest.java create mode 100644 ECOMP-XACML/src/test/java/org/openecomp/policy/xacml/test/json/RequestDefaultCategoryTest.java create mode 100644 ECOMP-XACML/src/test/java/org/openecomp/policy/xacml/test/json/RequestMainTest.java create mode 100644 ECOMP-XACML/src/test/java/org/openecomp/policy/xacml/test/json/ResponseConformanceTest.java create mode 100644 ECOMP-XACML/src/test/java/org/openecomp/policy/xacml/test/json/ResponseTest.java create mode 100644 ECOMP-XACML/src/test/resources/log4j.properties create mode 100644 ECOMP-XACML/src/test/resources/logback.xml create mode 100644 ECOMP-XACML/src/test/resources/logging.properties create mode 100644 ECOMP-XACML/src/test/resources/xacml.pip.properties create mode 100644 ECOMP-XACML/src/test/resources/xacml.policy.properties create mode 100644 ECOMP-XACML/testclient.properties create mode 100644 ECOMP-XACML/testpdp.properties create mode 100644 ECOMP-XACML/xacml.pap.properties create mode 100644 ECOMP-XACML/xacml.pdp.properties create mode 100644 ECOMP-XACML/xacml.properties create mode 100644 LICENSE.txt create mode 100644 LogParser/.gitignore create mode 100644 LogParser/LineTest.txt create mode 100644 LogParser/LineTest2.txt create mode 100644 LogParser/parserlog.properties create mode 100644 LogParser/policyLogger.properties create mode 100644 LogParser/pom.xml create mode 100644 LogParser/src/META-INF/MANIFEST.MF create mode 100644 LogParser/src/main/java/org/openecomp/xacml/parser/LogEntryObject.java create mode 100644 LogParser/src/main/java/org/openecomp/xacml/parser/ParseLog.java create mode 100644 LogParser/src/main/scripts/parserlog.sh create mode 100644 LogParser/src/test/java/org/openecomp/xacml/parser/ParseLogTest.java create mode 100644 LogParser/test_config.properties create mode 100644 PolicyEngineAPI/Config/Config.properties create mode 100644 PolicyEngineAPI/policyLogger.properties create mode 100644 PolicyEngineAPI/pom.xml create mode 100644 PolicyEngineAPI/src/log4j.properties create mode 100644 PolicyEngineAPI/src/main/java/org/openecomp/policy/api/AttributeType.java create mode 100644 PolicyEngineAPI/src/main/java/org/openecomp/policy/api/ConfigRequestParameters.java create mode 100644 PolicyEngineAPI/src/main/java/org/openecomp/policy/api/DecisionRequestParameters.java create mode 100644 PolicyEngineAPI/src/main/java/org/openecomp/policy/api/DecisionResponse.java create mode 100644 PolicyEngineAPI/src/main/java/org/openecomp/policy/api/DeletePolicyCondition.java create mode 100644 PolicyEngineAPI/src/main/java/org/openecomp/policy/api/DeletePolicyParameters.java create mode 100644 PolicyEngineAPI/src/main/java/org/openecomp/policy/api/DictionaryParameters.java create mode 100644 PolicyEngineAPI/src/main/java/org/openecomp/policy/api/DictionaryType.java create mode 100644 PolicyEngineAPI/src/main/java/org/openecomp/policy/api/EventRequestParameters.java create mode 100644 PolicyEngineAPI/src/main/java/org/openecomp/policy/api/ImportParameters.java create mode 100644 PolicyEngineAPI/src/main/java/org/openecomp/policy/api/NotificationScheme.java create mode 100644 PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyChangeResponse.java create mode 100644 PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyClass.java create mode 100644 PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyConfig.java create mode 100644 PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyConfigException.java create mode 100644 PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyConfigStatus.java create mode 100644 PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyConfigType.java create mode 100644 PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyDecision.java create mode 100644 PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyDecisionException.java create mode 100644 PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyEngine.java create mode 100644 PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyEngineException.java create mode 100644 PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyEventException.java create mode 100644 PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyParameters.java create mode 100644 PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyResponse.java create mode 100644 PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyResponseStatus.java create mode 100644 PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyType.java create mode 100644 PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PushPolicyParameters.java create mode 100644 PolicyEngineAPI/src/main/java/org/openecomp/policy/api/RuleProvider.java create mode 100644 PolicyEngineAPI/src/main/java/org/openecomp/policy/api/package-info.java create mode 100644 PolicyEngineAPI/src/main/java/org/openecomp/policy/std/AutoClientEnd.java create mode 100644 PolicyEngineAPI/src/main/java/org/openecomp/policy/std/AutoClientUEB.java create mode 100644 PolicyEngineAPI/src/main/java/org/openecomp/policy/std/ManualClientEnd.java create mode 100644 PolicyEngineAPI/src/main/java/org/openecomp/policy/std/ManualClientEndUEB.java create mode 100644 PolicyEngineAPI/src/main/java/org/openecomp/policy/std/MatchStore.java create mode 100644 PolicyEngineAPI/src/main/java/org/openecomp/policy/std/Matches.java create mode 100644 PolicyEngineAPI/src/main/java/org/openecomp/policy/std/NotificationUnMarshal.java create mode 100644 PolicyEngineAPI/src/main/java/org/openecomp/policy/std/StdDecisionResponse.java create mode 100644 PolicyEngineAPI/src/main/java/org/openecomp/policy/std/StdPolicyChangeResponse.java create mode 100644 PolicyEngineAPI/src/main/java/org/openecomp/policy/std/StdPolicyConfig.java create mode 100644 PolicyEngineAPI/src/main/java/org/openecomp/policy/std/StdPolicyEngine.java create mode 100644 PolicyEngineAPI/src/main/java/org/openecomp/policy/std/StdPolicyResponse.java create mode 100644 PolicyEngineAPI/src/main/java/org/openecomp/policy/std/StdStatus.java create mode 100644 PolicyEngineAPI/src/main/java/org/openecomp/policy/std/package-info.java create mode 100644 PolicyEngineAPI/src/main/resources/log4j.properties create mode 100644 PolicyEngineAPI/src/main/resources/logback.xml create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/AutoClientEndTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/AutoClientUEBTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/Handler.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/ManualClientEndTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/ManualClientEndUEBTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/MatchStoreTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/MatchesTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/NotificationStoreTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/NotificationUnMarshalTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/StdLoadedPolicyTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/StdPDPNotificationTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/StdPolicyChangeResponseTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/StdPolicyConfigTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/StdPolicyEngineTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/StdPolicyResponseTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/StdRemovedPolicyTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/StdStatusTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/package-info.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/test/ActionPolicyApiTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/test/AttributeTypeTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/test/ConfigBasePolicyTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/test/ConfigFirewallPolicyTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/test/ConfigRequestParametersTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/test/DecisionPolicyApiTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/test/DecisionRequestParametersTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/test/DeletePolicyConditionTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/test/DeletePolicyParametersTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/test/EventRequestParametersTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/test/GetConfigByPolicyNameTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/test/GetConfigStringStringMapTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/test/GetConfigStringStringTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/test/GetConfigStringTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/test/ImportParametersTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/test/LoadedPolicyTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/test/NotificationHandlerTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/test/NotificationSchemeTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/test/NotificationTypeTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PDPNotificationTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyChangeResponseTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyClassTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyConfigExceptionTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyConfigStatusTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyConfigTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyConfigTypeTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyDecisionExceptionTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyDecisionTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyEngineExceptionTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyEngineInterfaceTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyEngineTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyEventExceptionTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyParametersTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyResponseStatusTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyResponseTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyTypeTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PushPolicyParametersTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/test/RemovedPolicyTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/test/SendEventTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/test/TestRunner.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/test/UpdateTypeTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/openecomp/policy/test/package-info.java create mode 100644 PolicyEngineClient/.gitignore create mode 100644 PolicyEngineClient/config.properties create mode 100644 PolicyEngineClient/config.test.properties create mode 100644 PolicyEngineClient/input.testCases create mode 100644 PolicyEngineClient/policyLogger.properties create mode 100644 PolicyEngineClient/pom.xml create mode 100644 PolicyEngineClient/src/main/java/org/openecomp/policyEngine/ActionPolicyClient.java create mode 100644 PolicyEngineClient/src/main/java/org/openecomp/policyEngine/BrmsParamPolicyClient.java create mode 100644 PolicyEngineClient/src/main/java/org/openecomp/policyEngine/BrmsRawPolicyClient.java create mode 100644 PolicyEngineClient/src/main/java/org/openecomp/policyEngine/ClosedLoopPolicyClient.java create mode 100644 PolicyEngineClient/src/main/java/org/openecomp/policyEngine/ClosedLoopPolicyPerformanceMetricClient.java create mode 100644 PolicyEngineClient/src/main/java/org/openecomp/policyEngine/ConfigBasePolicyClient.java create mode 100644 PolicyEngineClient/src/main/java/org/openecomp/policyEngine/ConfigFirewallPolicyClient.java create mode 100644 PolicyEngineClient/src/main/java/org/openecomp/policyEngine/DecisionPolicyClient.java create mode 100644 PolicyEngineClient/src/main/java/org/openecomp/policyEngine/DeletePolicyClient.java create mode 100644 PolicyEngineClient/src/main/java/org/openecomp/policyEngine/GeneralTestClient.java create mode 100644 PolicyEngineClient/src/main/java/org/openecomp/policyEngine/GetConfigSample.java create mode 100644 PolicyEngineClient/src/main/java/org/openecomp/policyEngine/Handler.java create mode 100644 PolicyEngineClient/src/main/java/org/openecomp/policyEngine/ImportMicroServiceClient.java create mode 100644 PolicyEngineClient/src/main/java/org/openecomp/policyEngine/ListConfigPoliciesClient.java create mode 100644 PolicyEngineClient/src/main/java/org/openecomp/policyEngine/MainClient.java create mode 100644 PolicyEngineClient/src/main/java/org/openecomp/policyEngine/MicroServicesPolicyClient.java create mode 100644 PolicyEngineClient/src/main/java/org/openecomp/policyEngine/PolicyEngineTestClient.java create mode 100644 PolicyEngineClient/src/main/java/org/openecomp/policyEngine/PushPoliciesToPDP.java create mode 100644 PolicyEngineUtils/policyLogger.properties create mode 100644 PolicyEngineUtils/pom.xml create mode 100644 PolicyEngineUtils/src/main/java/org/openecomp/policy/api/LoadedPolicy.java create mode 100644 PolicyEngineUtils/src/main/java/org/openecomp/policy/api/NotificationHandler.java create mode 100644 PolicyEngineUtils/src/main/java/org/openecomp/policy/api/NotificationType.java create mode 100644 PolicyEngineUtils/src/main/java/org/openecomp/policy/api/PDPNotification.java create mode 100644 PolicyEngineUtils/src/main/java/org/openecomp/policy/api/RemovedPolicy.java create mode 100644 PolicyEngineUtils/src/main/java/org/openecomp/policy/api/UpdateType.java create mode 100644 PolicyEngineUtils/src/main/java/org/openecomp/policy/jpa/BackUpMonitorEntity.java create mode 100644 PolicyEngineUtils/src/main/java/org/openecomp/policy/std/NotificationStore.java create mode 100644 PolicyEngineUtils/src/main/java/org/openecomp/policy/std/StdLoadedPolicy.java create mode 100644 PolicyEngineUtils/src/main/java/org/openecomp/policy/std/StdPDPNotification.java create mode 100644 PolicyEngineUtils/src/main/java/org/openecomp/policy/std/StdRemovedPolicy.java create mode 100644 PolicyEngineUtils/src/main/java/org/openecomp/policy/utils/AAFPolicyClient.java create mode 100644 PolicyEngineUtils/src/main/java/org/openecomp/policy/utils/AAFPolicyException.java create mode 100644 PolicyEngineUtils/src/main/java/org/openecomp/policy/utils/BackUpHandler.java create mode 100644 PolicyEngineUtils/src/main/java/org/openecomp/policy/utils/BackUpMonitor.java create mode 100644 PolicyEngineUtils/src/main/java/org/openecomp/policy/utils/PolicyAccess.java create mode 100644 PolicyEngineUtils/src/main/java/org/openecomp/policy/utils/PolicyUtils.java create mode 100644 PolicyEngineUtils/src/main/resources/META-INF/persistencePU.xml create mode 100644 PolicyEngineUtils/src/test/java/org/openecomp/policy/test/Handler.java create mode 100644 PolicyEngineUtils/src/test/java/org/openecomp/policy/test/PolicyUtilsTest.java create mode 100644 PolicyEngineUtils/src/test/java/org/openecomp/policy/test/testBackUpMonitor.java create mode 100644 PyPDPServer/client.properties create mode 100644 PyPDPServer/config.properties create mode 100644 PyPDPServer/policyLogger.properties create mode 100644 PyPDPServer/pom.xml create mode 100644 PyPDPServer/src/main/java/org/openecomp/policy/pypdp/ConfigFirewallPolicyRequest.java create mode 100644 PyPDPServer/src/main/java/org/openecomp/policy/pypdp/ConfigRequest.java create mode 100644 PyPDPServer/src/main/java/org/openecomp/policy/pypdp/DeletePolicyRequest.java create mode 100644 PyPDPServer/src/main/java/org/openecomp/policy/pypdp/EventRequest.java create mode 100644 PyPDPServer/src/main/java/org/openecomp/policy/pypdp/ListConfigRequest.java create mode 100644 PyPDPServer/src/main/java/org/openecomp/policy/pypdp/PolicyCreateUpdateRequest.java create mode 100644 PyPDPServer/src/main/java/org/openecomp/policy/pypdp/PushPolicyRequest.java create mode 100644 PyPDPServer/src/main/java/org/openecomp/policy/pypdp/authorization/AuthenticationFilter.java create mode 100644 PyPDPServer/src/main/java/org/openecomp/policy/pypdp/authorization/AuthenticationService.java create mode 100644 PyPDPServer/src/main/java/org/openecomp/policy/pypdp/authorization/Config.java create mode 100644 PyPDPServer/src/main/java/org/openecomp/policy/pypdp/controller/Application.java create mode 100644 PyPDPServer/src/main/java/org/openecomp/policy/pypdp/controller/PolicyEngineServices.java create mode 100644 PyPDPServer/src/main/java/org/openecomp/policy/pypdp/jmx/PyPdpMBeanListener.java create mode 100644 PyPDPServer/src/main/java/org/openecomp/policy/pypdp/jmx/PyPdpMonitor.java create mode 100644 PyPDPServer/src/main/java/org/openecomp/policy/pypdp/jmx/PyPdpMonitorMBean.java create mode 100644 PyPDPServer/src/main/java/org/openecomp/policy/pypdp/model_pojo/PepConfigFirewallPolicyRequest.java create mode 100644 PyPDPServer/src/main/java/org/openecomp/policy/pypdp/model_pojo/PepConfigPolicyNameRequest.java create mode 100644 PyPDPServer/src/main/java/org/openecomp/policy/pypdp/model_pojo/PepConfigPolicyRequest.java create mode 100644 PyPDPServer/src/main/java/org/openecomp/policy/pypdp/model_pojo/PepPushPolicyRequest.java create mode 100644 PyPDPServer/src/main/java/org/openecomp/policy/pypdp/model_pojo/PyPolicyConfig.java create mode 100644 PyPDPServer/src/main/java/org/openecomp/policy/pypdp/notifications/Notification.java create mode 100644 PyPDPServer/src/main/java/org/openecomp/policy/pypdp/notifications/NotificationController.java create mode 100644 PyPDPServer/src/main/java/org/openecomp/policy/pypdp/notifications/NotificationServer.java create mode 100644 PyPDPServer/src/main/resources/log4j.properties create mode 100644 PyPDPServer/src/main/resources/logback.xml create mode 100644 PyPDPServer/src/test/java/testpypdp/AuthorizationTest.java create mode 100644 PyPDPServer/src/test/java/testpypdp/ConfigRequestTest.java create mode 100644 PyPDPServer/src/test/java/testpypdp/NotificationControllerTest.java create mode 100644 PyPDPServer/src/test/java/testpypdp/PolicyEngineServicesTest.java create mode 100644 README.md create mode 100644 ecomp-sdk-app/.externalToolBuilders/org.eclipse.wst.jsdt.core.javascriptValidator.launch create mode 100644 ecomp-sdk-app/.gitignore create mode 100644 ecomp-sdk-app/README.md create mode 100644 ecomp-sdk-app/db-scripts/EcompSdkDDLMySql_1610_Complete_OS.sql create mode 100644 ecomp-sdk-app/db-scripts/EcompSdkDMLMySql_1610_Complete_OS.sql create mode 100644 ecomp-sdk-app/policyLogger.properties create mode 100644 ecomp-sdk-app/pom.xml create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/AddressGroupJson.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/AddressJson.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/AddressMembers.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/AutoPushTabAdapter.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/ClosedLoopFaultBody.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/ClosedLoopFaultTriggerUISignatures.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/ClosedLoopPMBody.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/ClosedLoopPerformanceMetrics.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/ClosedLoopPolicy.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/ClosedLoopPolicyConditions.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/ClosedLoopPolicyStatus.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/ClosedLoopSignatures.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/DeletePolicyCondition.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/DeployNowJson.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/GridData.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/PolicyAdapter.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/PolicyExportAdapter.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/PrefixIPList.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/ServiceGroupJson.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/ServiceListJson.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/ServiceMembers.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/ServicesJson.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/Term.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/TermCollector.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/admin/CheckPDP.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/admin/PAPNotificationBroadcaster.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/admin/PolicyManagerServlet.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/admin/PolicyNotificationMail.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/admin/RESTfulPAPEngine.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/admin/XacmlAdminUI.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/components/ElasticSearchComponent.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/components/HumanPolicyComponent.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/components/PolicyImportWindow.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/conf/HibernateSession.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/ActionPolicyController.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/AdminTabController.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/AutoPushController.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/CreateBRMSParamController.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/CreateBRMSRawController.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/CreateClosedLoopFaultController.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/CreateClosedLoopPMController.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/CreateDcaeMicroServiceController.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/CreateFirewallController.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/CreatePolicyController.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/DashboardController.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/DecisionPolicyController.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/PDPController.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/PolicyController.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/PolicyExportAndImportController.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/PolicyNotificationController.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/PolicyRolesController.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/PolicyValidationController.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/dao/FunctionDefinitionDao.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/dao/GlobalRoleSettingsDao.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/dao/GroupEntityDao.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/dao/PDPEntityDao.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/dao/PolicyEditorScopesDao.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/dao/PolicyRolesDao.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/dao/PolicyVersionDao.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/dao/RemoteCatalogValuesDao.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/dao/RolesDao.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/dao/RuleAlgorithmsDao.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/dao/SystemLogDbDao.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/dao/WatchPolicyNotificationDao.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/ActionPolicyDictDaoImpl.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/AddressGroupDaoImpl.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/BRMSParamTemplateDaoImpl.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/DescriptiveScopeDaoImpl.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/FirewallDictionaryListDaoImpl.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/FunctionDefinitionDaoImpl.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/GlobalRoleSettingsDaoImpl.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/GroupEntityDaoImpl.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/GroupPolicyScopeListDaoImpl.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/MicroServiceModelsDaoImpl.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/PDPEntityDaoImpl.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/PolicyEditorScopesDaoImpl.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/PolicyRolesDaoImpl.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/PolicyVersionDaoImpl.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/PrefixListDaoImpl.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/RemoteCatalogValuesDaoImpl.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/RolesDaoImpl.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/RuleAlgorithmsDaoImpl.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/SafePolicyWarningDaoImpl.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/SecurityZoneDaoImpl.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/ServiceGroupDaoImpl.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/ServiceListDaoImpl.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/SystemLogDbDaoImpl.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/TermListDaoImpl.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/UserInfoDaoImpl.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/VarbindDictionaryDaoImpl.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/WatchPolicyNotificationDaoImpl.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/elk/client/ElkConnector.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/elk/client/Pair.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/elk/client/PolicyElasticSearchController.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/elk/client/PolicyLocator.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/elk/converter/ElkRecord.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/elk/converter/Xacml2Elk.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/model/PDPGroupContainer.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/model/PDPPolicyContainer.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/model/Roles.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/utils/ConfigurableRESTUtils.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/utils/PolicyContainer.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/utils/PolicyItemSetChangeNotifier.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/policy/utils/XACMLPolicyWriterWithPapNotify.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/portalapp/conf/ExternalAppConfig.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/portalapp/conf/ExternalAppInitializer.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/portalapp/conf/HibernateMappingLocations.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/portalapp/controller/AngularSinglePageController.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/portalapp/controller/CallflowController.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/portalapp/controller/ElasticSearchController.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/portalapp/controller/LeafletMapContoller.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/portalapp/controller/PostDroolsController.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/portalapp/controller/UserProfileController.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/portalapp/controller/WelcomeController.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/portalapp/model/Result.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/portalapp/scheduler/LogJob.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/portalapp/scheduler/LogRegistry.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/portalapp/scheduler/Register.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/portalapp/scheduler/RegistryAdapter.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/portalapp/service/AdminAuthExtension.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/portalapp/service/OnBoardingApiServiceImplPolicy.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/portalapp/uebhandler/InitUebHandler.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/portalapp/uebhandler/MainUebHandler.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/portalapp/uebhandler/WidgetNotificationHandler.java create mode 100644 ecomp-sdk-app/src/main/java/org/openecomp/portalapp/util/CustomLoggingFilter.java create mode 100644 ecomp-sdk-app/src/main/resources/att-rules.drl create mode 100644 ecomp-sdk-app/src/main/resources/cache.ccf create mode 100644 ecomp-sdk-app/src/main/resources/logback.xml create mode 100644 ecomp-sdk-app/src/main/resources/mchange-log.properties create mode 100644 ecomp-sdk-app/src/main/resources/portal.properties create mode 100644 ecomp-sdk-app/src/main/resources/state-rules.drl create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/conf/quartz.properties create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/conf/raptor.properties create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/conf/raptor_app_fusion.properties create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/conf/raptor_db_fusion.properties create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/conf/raptor_pdf.properties create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/conf/sql.properties create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/conf/system.properties create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/defs/definitions.xml create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/conf/fusion.properties create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/defs/definitions.xml create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/.gitignore create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/broadcast.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/broadcast_list.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/collaborateList.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/data_out.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/ebz/ebz_footer.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/ebz/ebz_header.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/ebz/loginSnippet.html create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/ebz_template.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/ebz_template_noheader_nofooter.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/ebz_template_report_embedded.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/es_search_demo.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/es_suggest_demo.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/frame_insert.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/include.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/jcs_admin.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/meta.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/popup_modal.html create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/popup_modal_role.html create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/popup_modal_rolefunction.html create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/post_search.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/profile.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/profile_search.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/role.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/role_function_list.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/role_list.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/usage_list.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/webrtc/collaboration.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/orm/Fusion.hbm.xml create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/orm/RNoteBookIntegration.hbm.xml create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/orm/Workflow.hbm.xml create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/custom_header_include.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/custom_js_include.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/date_end_field_run_sql.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/date_start_field_run_sql.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/default_field_run_sql.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/disclaimer.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/error_include.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/error_page.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/footer.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/popup_drill_down_report.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/popup_import_semaphore.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/popup_semaphore.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/popup_sql.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/popup_table_cols.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/popup_testrun_sql.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/report_download_csv.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/report_download_pdf.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/report_download_xls.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/report_ebz.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/report_import.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/report_sample.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/report_search.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/report_wizard.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/test_field_run_sql.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/test_run_sql.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/tree/folderNav.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/tree/testTree.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_adhoc_schedule.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_chart.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_columns_add_multi.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_columns_edit.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_columns_list.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_columns_order_all.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_data_forecasting.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_definition.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_filters_edit.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_filters_list.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_form_fields_edit.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_form_fields_list.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_javascript.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_log.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_map.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_run.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_schedule.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_schedule_formfield_include.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_schedule_multiple.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_schedule_only.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_schedule_only_from_search.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_sorting_edit.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_sorting_list.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_sorting_order_all.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_sql_def.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_tables_edit.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_tables_list.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_user_access.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/jsp/error.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/jsp/leafletMap.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/jsp/login_external.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/jsp/net_map.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/jsp/user_profile.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/jsp/welcome.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/WEB-INF/web.xml create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-animate.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-animate.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-animate.min.js.map create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-aria.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-aria.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-aria.min.js.map create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-cookies.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-cookies.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-cookies.min.js.map create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-csp.css create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-loader.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-loader.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-loader.min.js.map create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-message-format.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-message-format.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-message-format.min.js.map create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-messages.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-messages.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-messages.min.js.map create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-mocks.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-resource.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-resource.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-resource.min.js.map create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-route.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-route.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-route.min.js.map create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-sanitize.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-sanitize.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-sanitize.min.js.map create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-scenario.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-touch.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-touch.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-touch.min.js.map create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular.min.js.map create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/errors.json create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/version.json create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/version.txt create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-ui/ui-bootstrap-tpls-1.1.2.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-ui/ui-bootstrap-tpls-1.2.4.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/bootstrap/bs.css create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/css/nv.d3.css create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/cie.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/colorbrewer.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/core.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/crossfilter.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/crossfilter.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/d3.geom.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/d3.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/d3.layout.cloud.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/d3.layout.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/d3.v2.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/d3.v2.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/d3.v3.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/fisheye.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/hive.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/horizon.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/interactiveLayer.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/intro.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/models/axis-min.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/models/axis.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/models/axis.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/models/backup/bullet.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/models/backup/bulletChart.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/models/boilerplate.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/models/bullet.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/models/bulletChart.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/models/cumulativeLineChart.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/models/discreteBar.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/models/discreteBarChart.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/models/distribution.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/models/historicalBar.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/models/historicalBarChart.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/models/indentedTree.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/models/legend.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/models/line.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/models/lineChart.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/models/linePlusBarChart.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/models/linePlusBarWithFocusChart.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/models/lineWithFisheye.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/models/lineWithFisheyeChart.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/models/lineWithFocusChart.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/models/multiBar.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/models/multiBarChart.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/models/multiBarHorizontal.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/models/multiBarHorizontalChart.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/models/multiBarTimeSeries.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/models/multiBarTimeSeriesChart.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/models/multiChart.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/models/ohlcBar.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/models/parallelCoordinates.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/models/pie.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/models/pieChart.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/models/scatter.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/models/scatterChart.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/models/scatterPlusLineChart.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/models/sparkline.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/models/sparklinePlus.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/models/stackedArea.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/models/stackedAreaChart.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/nv.d3.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/nv.d3.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/outro.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/sankey.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/tooltip.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/d3/js/utils.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ebz/angular_js/angular-animate.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ebz/angular_js/angular-cookies.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ebz/angular_js/angular-route.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ebz/angular_js/angular-route.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ebz/angular_js/angular-sanitize.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ebz/angular_js/angular-touch.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ebz/angular_js/angular.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ebz/angular_js/app.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ebz/angular_js/checklist-model.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ebz/angular_js/checklist-model.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ebz/angular_js/gestures.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ebz/angular_js/ng_base.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ebz/angular_js/ui-charts-tpls.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ebz/ebz_header/footer.css create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ebz/ebz_header/header.css create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ebz/ebz_header/portal_ebz_header.css create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ebz/fn-ebz.css create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ebz/images/headerChatIcon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ebz/images/no_favorites_star.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ebz/js/attHeaderSnippet.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ebz/js/footer.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ebz/sandbox/att-abs-tpls.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ebz/sandbox/att-abs-tpls.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ebz/sandbox/styles/base.css create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ebz/sandbox/styles/btn.css create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ebz/sandbox/styles/demo.css create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ebz/sandbox/styles/dtpk.css create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ebz/sandbox/styles/frms.css create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ebz/sandbox/styles/ie/backgroundsize.min.htc create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ebz/sandbox/styles/images/calendar-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ebz/sandbox/styles/images/checkbox.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ebz/sandbox/styles/images/down.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ebz/sandbox/styles/images/icon-close-modal.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ebz/sandbox/styles/images/icon-informative-modal.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ebz/sandbox/styles/images/icon-warning-modal.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ebz/sandbox/styles/images/loader.gif create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ebz/sandbox/styles/images/loading-spinner-medium.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ebz/sandbox/styles/images/loading-spinner-orange.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ebz/sandbox/styles/images/loading_balls_black-small.gif create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ebz/sandbox/styles/images/loading_balls_black.gif create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ebz/sandbox/styles/images/loading_balls_blue-small.gif create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ebz/sandbox/styles/images/loading_balls_blue.gif create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ebz/sandbox/styles/images/loading_balls_white-small.gif create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ebz/sandbox/styles/images/loading_balls_white.gif create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ebz/sandbox/styles/images/loading_dots.gif create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ebz/sandbox/styles/images/magnify_glass.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ebz/sandbox/styles/images/oops-exclamation.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ebz/sandbox/styles/images/radio.jpg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ebz/sandbox/styles/images/select-arrows.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ebz/sandbox/styles/images/treearrow.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ebz/sandbox/styles/images/up.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ebz/sandbox/styles/images/upanddown.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ebz/sandbox/styles/pages/iconography.css create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ebz/sandbox/styles/sldr.css create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ebz/sandbox/styles/style.css create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ebz/sandbox/styles/tbs.css create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/.gitignore create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/LICENSE create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/bower.json create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/component.json create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/composer.json create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/css/ionicons.css create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/css/ionicons.min.css create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/fonts/ionicons.eot create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/fonts/ionicons.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/fonts/ionicons.ttf create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/fonts/ionicons.woff create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/less/_ionicons-font.less create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/less/_ionicons-icons.less create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/less/_ionicons-variables.less create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/less/ionicons.less create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/alert-circled.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/alert.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-add-contact.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-add.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-alarm.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-archive.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-arrow-back.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-arrow-down-left.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-arrow-down-right.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-arrow-forward.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-arrow-up-left.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-arrow-up-right.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-battery.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-book.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-calendar.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-call.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-camera.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-chat.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-checkmark.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-clock.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-close.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-contact.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-contacts.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-data.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-developer.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-display.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-download.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-drawer.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-dropdown.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-earth.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-folder.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-forums.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-friends.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-hand.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-image.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-inbox.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-information.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-keypad.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-lightbulb.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-locate.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-location.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-mail.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-microphone.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-mixer.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-more.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-note.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-playstore.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-printer.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-promotion.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-reminder.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-remove.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-search.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-send.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-settings.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-share.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-social-user.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-social.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-sort.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-stair-drawer.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-star.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-stopwatch.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-storage.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-system-back.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-system-home.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-system-windows.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-timer.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-trash.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-user-menu.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-volume.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/android-wifi.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/aperture.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/archive.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/arrow-down-a.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/arrow-down-b.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/arrow-down-c.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/arrow-expand.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/arrow-graph-down-left.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/arrow-graph-down-right.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/arrow-graph-up-left.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/arrow-graph-up-right.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/arrow-left-a.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/arrow-left-b.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/arrow-left-c.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/arrow-move.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/arrow-resize.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/arrow-return-left.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/arrow-return-right.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/arrow-right-a.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/arrow-right-b.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/arrow-right-c.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/arrow-shrink.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/arrow-swap.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/arrow-up-a.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/arrow-up-b.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/arrow-up-c.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/asterisk.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/at.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/bag.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/battery-charging.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/battery-empty.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/battery-full.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/battery-half.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/battery-low.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/beaker.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/beer.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/bluetooth.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/bonfire.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/bookmark.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/briefcase.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/bug.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/calculator.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/calendar.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/camera.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/card.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/cash.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/chatbox-working.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/chatbox.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/chatboxes.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/chatbubble-working.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/chatbubble.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/chatbubbles.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/checkmark-circled.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/checkmark-round.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/checkmark.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/chevron-down.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/chevron-left.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/chevron-right.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/chevron-up.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/clipboard.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/clock.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/close-circled.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/close-round.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/close.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/closed-captioning.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/cloud.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/code-download.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/code-working.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/code.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/coffee.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/compass.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/compose.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/connection-bars.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/contrast.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/cube.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/disc.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/document-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/document.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/drag.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/earth.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/edit.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/egg.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/eject.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/email.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/eye-disabled.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/eye.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/female.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/filing.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/film-marker.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/fireball.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/flag.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/flame.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/flash-off.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/flash.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/flask.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/folder.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/fork-repo.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/fork.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/forward.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/funnel.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/game-controller-a.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/game-controller-b.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/gear-a.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/gear-b.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/grid.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/hammer.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/happy.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/headphone.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/heart-broken.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/heart.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/help-buoy.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/help-circled.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/help.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/home.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/icecream.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/icon-social-google-plus-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/icon-social-google-plus.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/image.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/images.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/information-circled.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/information.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ionic.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-alarm-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-alarm.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-albums-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-albums.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-americanfootball-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-americanfootball.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-analytics-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-analytics.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-arrow-back.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-arrow-down.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-arrow-forward.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-arrow-left.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-arrow-right.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-arrow-thin-down.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-arrow-thin-left.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-arrow-thin-right.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-arrow-thin-up.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-arrow-up.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-at-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-at.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-barcode-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-barcode.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-baseball-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-baseball.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-basketball-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-basketball.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-bell-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-bell.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-bolt-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-bolt.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-bookmarks-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-bookmarks.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-box-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-box.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-briefcase-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-briefcase.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-browsers-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-browsers.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-calculator-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-calculator.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-calendar-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-calendar.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-camera-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-camera.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-cart-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-cart.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-chatboxes-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-chatboxes.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-chatbubble-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-chatbubble.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-checkmark-empty.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-checkmark-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-checkmark.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-circle-filled.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-circle-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-clock-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-clock.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-close-empty.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-close-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-close.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-cloud-download-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-cloud-download.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-cloud-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-cloud-upload-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-cloud-upload.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-cloud.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-cloudy-night-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-cloudy-night.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-cloudy-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-cloudy.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-cog-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-cog.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-compose-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-compose.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-contact-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-contact.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-copy-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-copy.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-download-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-download.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-drag.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-email-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-email.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-expand.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-eye-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-eye.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-fastforward-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-fastforward.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-filing-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-filing.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-film-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-film.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-flag-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-flag.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-folder-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-folder.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-football-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-football.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-gear-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-gear.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-glasses-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-glasses.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-heart-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-heart.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-help-empty.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-help-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-help.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-home-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-home.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-infinite-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-infinite.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-information-empty.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-information-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-information.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-ionic-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-keypad-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-keypad.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-lightbulb-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-lightbulb.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-location-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-location.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-locked-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-locked.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-loop-strong.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-loop.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-medkit-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-medkit.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-mic-off.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-mic-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-mic.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-minus-empty.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-minus-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-minus.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-monitor-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-monitor.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-moon-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-moon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-more-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-more.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-musical-note.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-musical-notes.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-navigate-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-navigate.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-paper-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-paper.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-paperplane-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-paperplane.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-partlysunny-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-partlysunny.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-pause-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-pause.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-paw-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-paw.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-people-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-people.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-person-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-person.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-personadd-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-personadd.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-photos-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-photos.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-pie-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-pie.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-play-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-play.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-plus-empty.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-plus-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-plus.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-pricetag-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-pricetag.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-pricetags-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-pricetags.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-printer-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-printer.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-pulse-strong.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-pulse.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-rainy-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-rainy.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-recording-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-recording.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-redo-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-redo.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-refresh-empty.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-refresh-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-refresh.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-reload.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-reverse-camera-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-reverse-camera.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-rewind-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-rewind.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-search-strong.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-search.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-settings-strong.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-settings.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-shrink.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-skipbackward-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-skipbackward.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-skipforward-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-skipforward.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-snowy.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-speedometer-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-speedometer.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-star-half.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-star-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-star.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-stopwatch-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-stopwatch.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-sunny-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-sunny.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-telephone-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-telephone.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-tennisball-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-tennisball.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-thunderstorm-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-thunderstorm.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-time-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-time.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-timer-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-timer.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-toggle-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-toggle.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-trash-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-trash.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-undo-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-undo.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-unlocked-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-unlocked.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-upload-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-upload.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-videocam-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-videocam.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-volume-high.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-volume-low.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-wineglass-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-wineglass.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-world-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ios7-world.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ipad.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/iphone.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ipod.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/jet.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/key.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/knife.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/laptop.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/leaf.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/levels.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/lightbulb.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/link.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/load-a.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/load-b.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/load-c.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/load-d.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/location.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/locked.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/log-in.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/log-out.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/loop.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/magnet.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/male.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/man.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/map.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/medkit.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/merge.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/mic-a.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/mic-b.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/mic-c.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/minus-circled.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/minus-round.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/minus.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/model-s.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/monitor.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/more.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/mouse.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/music-note.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/navicon-round.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/navicon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/navigate.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/network.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/no-smoking.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/nuclear.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/outlet.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/paper-airplane.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/paperclip.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/pause.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/person-add.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/person-stalker.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/person.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/pie-graph.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/pin.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/pinpoint.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/pizza.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/plane.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/planet.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/play.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/playstation.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/plus-circled.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/plus-round.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/plus.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/podium.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/pound.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/power.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/pricetag.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/pricetags.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/printer.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/pull-request.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/qr-scanner.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/quote.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/radio-waves.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/record.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/refresh.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/reply-all.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/reply.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ribbon-a.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/ribbon-b.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/sad.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/scissors.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/search.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/settings.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/share.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/shuffle.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/skip-backward.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/skip-forward.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/social-android-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/social-android.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/social-apple-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/social-apple.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/social-bitcoin-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/social-bitcoin.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/social-buffer-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/social-buffer.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/social-designernews-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/social-designernews.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/social-dribbble-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/social-dribbble.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/social-dropbox-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/social-dropbox.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/social-facebook-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/social-facebook.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/social-foursquare-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/social-foursquare.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/social-freebsd-devil.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/social-github-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/social-github.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/social-google-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/social-google.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/social-googleplus-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/social-googleplus.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/social-hackernews-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/social-hackernews.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/social-instagram-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/social-instagram.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/social-linkedin-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/social-linkedin.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/social-pinterest-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/social-pinterest.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/social-reddit-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/social-reddit.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/social-rss-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/social-rss.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/social-skype-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/social-skype.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/social-tumblr-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/social-tumblr.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/social-tux.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/social-twitter-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/social-twitter.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/social-usd-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/social-usd.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/social-vimeo-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/social-vimeo.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/social-windows-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/social-windows.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/social-wordpress-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/social-wordpress.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/social-yahoo-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/social-yahoo.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/social-youtube-outline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/social-youtube.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/speakerphone.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/speedometer.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/spoon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/star.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/stats-bars.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/steam.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/stop.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/thermometer.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/thumbsdown.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/thumbsup.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/toggle-filled.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/toggle.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/trash-a.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/trash-b.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/trophy.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/umbrella.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/university.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/unlocked.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/upload.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/usb.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/videocamera.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/volume-high.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/volume-medium.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/volume-mute.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/wand.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/waterdrop.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/wifi.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/wineglass.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/woman.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/wrench.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/png/512/xbox.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/readme.md create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/scss/_ionicons-font.scss create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/scss/_ionicons-icons.scss create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/scss/_ionicons-variables.scss create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/scss/ionicons.scss create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/alert-circled.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/alert.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-add-circle.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-add.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-alarm-clock.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-alert.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-apps.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-archive.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-arrow-back.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-arrow-down.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-arrow-dropdown-circle.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-arrow-dropdown.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-arrow-dropleft-circle.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-arrow-dropleft.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-arrow-dropright-circle.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-arrow-dropright.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-arrow-dropup-circle.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-arrow-dropup.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-arrow-forward.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-arrow-up.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-attach.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-bar.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-bicycle.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-boat.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-bookmark.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-bulb.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-bus.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-calendar.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-call.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-camera.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-cancel.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-car.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-cart.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-chat.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-checkbox-blank.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-checkbox-outline-blank.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-checkbox-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-checkbox.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-checkmark-circle.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-clipboard.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-close.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-cloud-circle.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-cloud-done.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-cloud-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-cloud.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-color-palette.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-compass.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-contact.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-contacts.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-contract.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-create.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-delete.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-desktop.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-document.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-done-all.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-done.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-download.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-drafts.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-exit.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-expand.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-favorite-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-favorite.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-film.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-folder-open.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-folder.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-funnel.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-globe.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-hand.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-hangout.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-happy.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-home.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-image.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-laptop.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-list.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-locate.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-lock.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-mail.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-map.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-menu.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-microphone-off.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-microphone.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-more-horizontal.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-more-vertical.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-navigate.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-notifications-none.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-notifications-off.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-notifications.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-open.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-options.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-people.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-person-add.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-person.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-phone-landscape.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-phone-portrait.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-pin.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-plane.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-playstore.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-print.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-radio-button-off.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-radio-button-on.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-refresh.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-remove-circle.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-remove.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-restaurant.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-sad.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-search.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-send.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-settings.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-share-alt.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-share.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-star-half.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-star-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-star.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-stopwatch.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-subway.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-sunny.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-sync.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-textsms.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-time.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-train.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-unlock.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-upload.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-volume-down.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-volume-mute.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-volume-off.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-volume-up.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-walk.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-warning.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-watch.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/android-wifi.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/aperture.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/archive.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/arrow-down-a.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/arrow-down-b.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/arrow-down-c.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/arrow-expand.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/arrow-graph-down-left.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/arrow-graph-down-right.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/arrow-graph-up-left.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/arrow-graph-up-right.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/arrow-left-a.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/arrow-left-b.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/arrow-left-c.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/arrow-move.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/arrow-resize.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/arrow-return-left.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/arrow-return-right.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/arrow-right-a.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/arrow-right-b.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/arrow-right-c.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/arrow-shrink.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/arrow-swap.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/arrow-up-a.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/arrow-up-b.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/arrow-up-c.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/asterisk.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/at.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/backspace-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/backspace.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/bag.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/battery-charging.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/battery-empty.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/battery-full.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/battery-half.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/battery-low.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/beaker.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/beer.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/bluetooth.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/bonfire.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/bookmark.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/bowtie.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/briefcase.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/bug.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/calculator.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/calendar.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/camera.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/card.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/cash.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/chatbox-working.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/chatbox.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/chatboxes.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/chatbubble-working.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/chatbubble.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/chatbubbles.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/checkmark-circled.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/checkmark-round.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/checkmark.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/chevron-down.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/chevron-left.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/chevron-right.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/chevron-up.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/clipboard.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/clock.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/close-circled.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/close-round.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/close.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/closed-captioning.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/cloud.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/code-download.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/code-working.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/code.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/coffee.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/compass.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/compose.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/connection-bars.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/contrast.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/crop.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/cube.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/disc.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/document-text.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/document.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/drag.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/earth.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/easel.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/edit.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/egg.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/eject.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/email-unread.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/email.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/erlenmeyer-flask-bubbles.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/erlenmeyer-flask.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/eye-disabled.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/eye.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/female.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/filing.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/film-marker.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/fireball.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/flag.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/flame.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/flash-off.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/flash.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/folder.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/fork-repo.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/fork.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/forward.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/funnel.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/gear-a.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/gear-b.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/grid.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/hammer.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/happy-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/happy.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/headphone.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/heart-broken.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/heart.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/help-buoy.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/help-circled.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/help.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/home.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/icecream.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/image.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/images.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/information-circled.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/information.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ionic.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-alarm-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-alarm.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-albums-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-albums.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-americanfootball-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-americanfootball.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-analytics-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-analytics.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-arrow-back.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-arrow-down.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-arrow-forward.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-arrow-left.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-arrow-right.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-arrow-thin-down.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-arrow-thin-left.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-arrow-thin-right.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-arrow-thin-up.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-arrow-up.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-at-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-at.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-barcode-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-barcode.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-baseball-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-baseball.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-basketball-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-basketball.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-bell-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-bell.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-body-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-body.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-bolt-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-bolt.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-book-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-book.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-bookmarks-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-bookmarks.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-box-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-box.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-briefcase-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-briefcase.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-browsers-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-browsers.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-calculator-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-calculator.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-calendar-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-calendar.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-camera-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-camera.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-cart-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-cart.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-chatboxes-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-chatboxes.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-chatbubble-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-chatbubble.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-checkmark-empty.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-checkmark-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-checkmark.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-circle-filled.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-circle-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-clock-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-clock.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-close-empty.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-close-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-close.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-cloud-download-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-cloud-download.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-cloud-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-cloud-upload-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-cloud-upload.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-cloud.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-cloudy-night-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-cloudy-night.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-cloudy-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-cloudy.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-cog-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-cog.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-color-filter-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-color-filter.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-color-wand-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-color-wand.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-compose-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-compose.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-contact-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-contact.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-copy-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-copy.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-crop-strong.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-crop.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-download-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-download.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-drag.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-email-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-email.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-eye-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-eye.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-fastforward-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-fastforward.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-filing-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-filing.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-film-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-film.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-flag-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-flag.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-flame-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-flame.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-flask-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-flask.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-flower-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-flower.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-folder-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-folder.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-football-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-football.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-game-controller-a-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-game-controller-a.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-game-controller-b-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-game-controller-b.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-gear-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-gear.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-glasses-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-glasses.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-grid-view-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-grid-view.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-heart-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-heart.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-help-empty.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-help-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-help.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-home-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-home.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-infinite-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-infinite.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-information-empty.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-information-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-information.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-ionic-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-keypad-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-keypad.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-lightbulb-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-lightbulb.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-list-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-list.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-location-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-location.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-locked-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-locked.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-loop-strong.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-loop.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-medical-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-medical.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-medkit-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-medkit.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-mic-off.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-mic-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-mic.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-minus-empty.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-minus-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-minus.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-monitor-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-monitor.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-moon-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-moon.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-more-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-more.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-musical-note.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-musical-notes.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-navigate-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-navigate.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-nutrition-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-nutrition.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-paper-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-paper.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-paperplane-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-paperplane.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-partlysunny-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-partlysunny.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-pause-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-pause.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-paw-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-paw.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-people-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-people.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-person-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-person.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-personadd-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-personadd.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-photos-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-photos.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-pie-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-pie.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-pint-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-pint.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-play-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-play.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-plus-empty.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-plus-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-plus.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-pricetag-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-pricetag.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-pricetags-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-pricetags.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-printer-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-printer.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-pulse-strong.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-pulse.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-rainy-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-rainy.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-recording-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-recording.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-redo-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-redo.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-refresh-empty.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-refresh-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-refresh.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-reload.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-reverse-camera-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-reverse-camera.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-rewind-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-rewind.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-rose-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-rose.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-search-strong.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-search.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-settings-strong.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-settings.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-shuffle-strong.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-shuffle.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-skipbackward-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-skipbackward.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-skipforward-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-skipforward.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-snowy.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-speedometer-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-speedometer.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-star-half.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-star-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-star.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-stopwatch-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-stopwatch.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-sunny-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-sunny.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-telephone-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-telephone.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-tennisball-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-tennisball.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-thunderstorm-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-thunderstorm.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-time-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-time.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-timer-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-timer.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-toggle-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-toggle.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-trash-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-trash.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-undo-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-undo.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-unlocked-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-unlocked.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-upload-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-upload.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-videocam-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-videocam.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-volume-high.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-volume-low.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-wineglass-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-wineglass.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-world-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ios-world.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ipad.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/iphone.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ipod.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/jet.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/key.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/knife.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/laptop.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/leaf.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/levels.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/lightbulb.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/link.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/load-a.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/load-b.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/load-c.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/load-d.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/location.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/lock-combination.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/locked.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/log-in.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/log-out.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/loop.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/magnet.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/male.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/man.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/map.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/medkit.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/merge.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/mic-a.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/mic-b.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/mic-c.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/minus-circled.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/minus-round.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/minus.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/model-s.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/monitor.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/more.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/mouse.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/music-note.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/navicon-round.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/navicon.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/navigate.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/network.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/no-smoking.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/nuclear.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/outlet.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/paintbrush.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/paintbucket.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/paper-airplane.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/paperclip.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/pause.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/person-add.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/person-stalker.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/person.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/pie-graph.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/pin.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/pinpoint.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/pizza.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/plane.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/planet.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/play.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/playstation.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/plus-circled.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/plus-round.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/plus.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/podium.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/pound.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/power.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/pricetag.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/pricetags.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/printer.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/pull-request.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/qr-scanner.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/quote.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/radio-waves.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/record.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/refresh.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/reply-all.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/reply.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ribbon-a.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/ribbon-b.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/sad-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/sad.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/scissors.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/search.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/settings.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/share.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/shuffle.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/skip-backward.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/skip-forward.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-android-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-android.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-angular-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-angular.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-apple-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-apple.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-bitcoin-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-bitcoin.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-buffer-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-buffer.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-chrome-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-chrome.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-codepen-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-codepen.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-css3-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-css3.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-designernews-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-designernews.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-dribbble-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-dribbble.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-dropbox-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-dropbox.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-euro-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-euro.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-facebook-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-facebook.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-foursquare-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-foursquare.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-freebsd-devil.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-github-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-github.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-google-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-google.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-googleplus-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-googleplus.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-hackernews-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-hackernews.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-html5-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-html5.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-instagram-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-instagram.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-javascript-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-javascript.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-linkedin-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-linkedin.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-markdown.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-nodejs.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-octocat.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-pinterest-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-pinterest.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-python.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-reddit-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-reddit.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-rss-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-rss.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-sass.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-skype-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-skype.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-snapchat-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-snapchat.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-tumblr-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-tumblr.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-tux.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-twitch-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-twitch.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-twitter-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-twitter.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-usd-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-usd.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-vimeo-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-vimeo.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-whatsapp-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-whatsapp.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-windows-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-windows.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-wordpress-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-wordpress.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-yahoo-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-yahoo.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-yen-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-yen.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-youtube-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/social-youtube.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/soup-can-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/soup-can.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/speakerphone.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/speedometer.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/spoon.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/star.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/stats-bars.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/steam.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/stop.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/thermometer.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/thumbsdown.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/thumbsup.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/toggle-filled.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/toggle.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/transgender.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/trash-a.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/trash-b.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/trophy.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/tshirt-outline.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/tshirt.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/umbrella.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/university.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/unlocked.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/upload.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/usb.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/videocamera.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/volume-high.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/volume-low.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/volume-medium.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/volume-mute.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/wand.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/waterdrop.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/wifi.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/wineglass.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/woman.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/wrench.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/ionicons-2.0.1/src/xbox.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/css/images/blank.gif create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/css/scribble.css create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/css/slider.css create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/css/spacegallery.css create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/html/area_chart.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/html/bar_chart.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/html/d3_gauges_demo.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/html/data/speedometer2.csv create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/html/data/speedometer3.csv create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/html/data/worddata.csv create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/html/donut_d3.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/html/js/area_chart.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/html/js/donut.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/html/js/gauges.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/html/js/line_chart.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/html/js/pie_chart.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/html/js/worddata.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/html/line_chart.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/html/pie_chart.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/html/wordcloud.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/images/Calendar-16x16.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/images/arrow-next.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/images/arrow-prev.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/images/carousel/slide_b_drive_test_map.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/images/carousel/slide_b_eppt_county.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/images/carousel/slide_b_eppt_regression.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/images/carousel/slide_b_ios_throughput.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/images/carousel/slide_b_lata_map.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/images/carousel/slide_b_lata_map_legend.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/images/carousel/slide_b_nova_sdn_map.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/images/copyicon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/images/deleteicon.gif create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/images/example-frame.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/images/loading.gif create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/images/tunnels/1_mon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/images/tunnels/2_tue.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/images/tunnels/3_wed.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/images/tunnels/4_thu.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/images/tunnels/5_fri.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/images/tunnels/6_sat.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/images/tunnels/7_sun.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/images/tunnels/BH_DLSTX_IN.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/images/tunnels/BH_DLSTX_OUT.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/images/tunnels/BH_Nat.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/images/tunnels/BH_Nat_Def.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/images/tunnels/BH_Nat_Priority.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/js/FusionCharts.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/js/charts.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/js/scribble.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/js/slides.min.jquery.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/js/spacegallery.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/org_chart/css/bootstrap.min.css create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/org_chart/css/custom.css create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/org_chart/css/jquery.jOrgChart.css create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/org_chart/css/prettify.css create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/org_chart/example.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/org_chart/example_vsp.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/org_chart/images/bkgd.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/org_chart/images/raspberry.jpg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/org_chart/jquery.jOrgChart.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/samples/org_chart/prettify.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/external/utils/js/browserCheck.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/Rlogo.jpg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/Thumbs.db create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/action_icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/action_list_spacer.gif create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/active.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/add.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/add_tool_button.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/addicon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/application_window_bg.jpg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/arrow-next.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/arrow-prev.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/att_angular_gridster/grips.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/backButton.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/blank.gif create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/blueButton.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/body_graphic.jpg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/bubble.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/cache.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/calendar.gif create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/chevron.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/close_container.gif create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/collapsed-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/column-bg.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/copyicon-highlighted.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/copyicon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/csv_icon.jpg create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/csv_icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/customers-add.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/customers-search.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/customers.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/decrypted.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/deleteicon-highlighted.gif create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/deleteicon-highlighted.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/deleteicon.gif create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/editicon.gif create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/error_type.gif create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/example-frame.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/excelicon_multi.gif create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/executeicon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/expanded-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/file-add.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/file_import.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/file_save-all.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/filter_icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/folder_add.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/folder_closed.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/folder_delete.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/folder_edit.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/folder_open.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/folder_user.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/funnel.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/fusion.gif create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/grayButton.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/gray_add_tool_button.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/headerChatIcon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/icon_remove_all.gif create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/inactive.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/info_type.gif create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/layout/panel-e-w-toggle.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/layout/panel-n-s-toggle.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/leftButton.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/loading.gif create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/loading_bar.gif create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/login_button.gif create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/m1.gif create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/mail.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/map.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/menu/bubble.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/menu/file_import.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/menu/file_save-all.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/menu/mail.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/menu/profile.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/menu/speechbubble.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/menu/users.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/minus.gif create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/mobile_logo_att_header_black.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/mobile_logo_att_header_grey.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/mobile_logo_att_header_horizontal.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/mobile_logo_att_header_white.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/modify_icon.gif create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/note-add.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/note-search.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/note.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/notes.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/offline.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/offlineMsg.gif create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/online.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/page.gif create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/pagination.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/panel-e-w-toggle.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/panel-n-s-toggle.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/pix.gif create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/plus.gif create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/printer.gif create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/profile.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/report-add.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/report-favorite.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/report-my.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/report-public.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/report.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/reports.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/results-first-active.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/results-first-disabled.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/results-last-active.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/results-last-disabled.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/results-next-active.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/results-next-disabled.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/results-prev-active.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/results-prev-disabled.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/resultset_last.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/resultset_previous.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/return_to_top.gif create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/rightButton.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/search.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/search_profile.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/sort_asc.gif create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/sort_desc.gif create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/spacer.gif create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/success_type.gif create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/swoosh.gif create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/tab-hm.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/tab-v-hm.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/tab.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/table-add.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/table-delete.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/table-edit.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/table.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/tabs-bg.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/toolButton.gif create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/toolButton.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/toolbar.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/users.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/warning_type.gif create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/webphone.ico create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/images/whiteButton.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/notebook-integration/scripts/controllers/nbook-framecontroller.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/notebook-integration/scripts/controllers/nbookController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/notebook-integration/scripts/controllers/notebookFrameController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/notebook-integration/scripts/dependency/angular.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/notebook-integration/scripts/view-models/notebook-frame.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/notebook-integration/scripts/view-models/notebook-viz.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/notebook-integration/scripts/view-models/notebook.htm create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/notebook-integration/scripts/view-models/notebookInputs.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/att_angular_gridster/angular-gridster.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/att_angular_gridster/ui-gridster-tpls.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/adminController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/admin_menu_edit.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/ase-controller.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/broadcast-controller.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/broadcast-list-controller.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/collaborate-list-controller.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/dummy.txt create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/fn_menu_add_popup_controller.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/jcs-admin-controller.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/modelpopupController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/post-search-controller.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/profile-controller.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/profile-search-controller.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/profileController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/role-controller.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/role-function-list-controller.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/role-list-controller.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/rolefunctionpopupController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/rolepopupmodelController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/self-profile-controller.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/usage-list-controller.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/workflows/workflowApp.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/workflows/workflowController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/workflows/workflowRouting.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/directives/dummy.txt create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/directives/footer.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/directives/header.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/directives/leftMenu.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/jquery.resize.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/layout/debug.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/layout/jquery-latest.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/layout/jquery-ui-latest.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/layout/jquery.layout-latest.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/modalService.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/moment.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/services/adminService.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/services/headerService.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/services/leftMenuService.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/services/profileService.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/services/userInfoService.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/socket/peerBroadcast.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/utils/dummy.txt create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/utils/page-resource.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/utils/sandbox-resources.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/admin-page/admin.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/admin-page/profile.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/dummy.txt create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/footer.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/header.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/left_menu.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/admin_menu_edit.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/broadcast.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/broadcast_list.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/collaborate_list.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/jcs_admin.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/popup_modal.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/popup_modal_fn_menu_add.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/popup_modal_fn_menu_edit.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/popup_modal_role.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/popup_modal_rolefunction.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/post_search.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/profile_detail.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/profile_search.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/role.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/role_function_list.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/role_list.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/self_profile.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/usage_list.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/workflows/workflow-landing.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/workflows/workflow-listing.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/workflows/workflow-new.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/workflows/workflow-preview.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/workflows/workflow-remove.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/workflows/workflow-schedule.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/webrtc/RTCMultiConnection.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/scripts/webrtc/getSourceId.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/styles/att_angular_gridster/sandbox-gridster.css create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/styles/att_angular_gridster/ui-gridster.css create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/styles/fusion-sunny.css create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/styles/jquery-ui.css create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/styles/layout/layout-default-latest.css create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusion/styles/workflows/workflows.css create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/drools/controller/drools-list-controller.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/drools/controller/drools-view-controller.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/drools/controller/droolsController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/drools/controller/dummy.txt create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/drools/directives/dummy.txt create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/drools/services/droolsService.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/drools/utils/dummy.txt create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/drools/view-models/droolsList.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/drools/view-models/droolsSinglePage.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/drools/view-models/droolsView.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/drools/view-models/dummy.txt create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/external/dummy.txt create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/fonts/dummy.txt create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/7450-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/7450-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/7750-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/7750-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/apn-dns-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/apn-dns-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/atcf-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/atcf-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/atgw-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/atgw-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/bgcf-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/bgcf-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/com-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/cpm-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/cpm-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/default-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/dra-epc-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/dra-epc-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/dra-ims-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/dra-ims-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/dslam-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/dslam-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/eatf-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/eatf-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/ecscf-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/ecscf-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/emsc-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/enb-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/enb-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/enum-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/enum-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/esmlc-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/esmlc-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/ettcs-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/ettcs-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/gmlc-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/gmlc-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/hlr-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/hlr-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/hss-epc-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/hss-epc-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/hss-ims-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/hss-ims-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/icscf-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/icscf-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/ipag-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/ipag-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/isbc-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/isbc-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/iwf-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/iwf-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/lrf-rdf-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/lrf-rdf-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/lrg-rdf-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/mgc8-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/mgc8-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/mgcf-emsc-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/mgcf-emsc-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/mgw-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/mgw-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/mind-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/mind-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/mme-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/mme-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/mrf-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/mrf-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/msc-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/msn-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/msn-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/multi-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/n7450-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/n7450-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/n7750a-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/n7750a-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/n7750b-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/n7750b-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/n7750c-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/n7750c-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/n7750d-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/n7750d-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/nb-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/nb-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/pas-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/pas-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/pcef-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/pcef-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/pcrf-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/pcrf-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/pcscf-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/pcscf-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/pgw-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/pgw-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/plrf-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/plrf-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/psap-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/pstn-tdm-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/pstn-tdm-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/rg-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/rg-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/rnc-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/rnc-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/sbc-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/sbc-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/sccas-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/sccas-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/scscf-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/scscf-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/sdg-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/sdg-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/sgsns4-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/sgsns4-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/sgw-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/sgw-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/siad-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/siad-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/ss7-gport-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/ss7-gport-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/ss7gport-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/ss7gport-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/switch-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/tas-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/tas-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/transcoder-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/transcoder-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/ue-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/uephone-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/usp-dns-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/usp-dns-text.png create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/images/dummy.txt create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/scripts/controller/dummy.txt create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/scripts/controller/sample-page-controller.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/scripts/controller/sample-page-iframe-controller.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/scripts/controller/sampleController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/scripts/directives/dummy.txt create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/scripts/utils/dummy.txt create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/scripts/view-models/dummy.txt create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/scripts/view-models/sample.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/scripts/view-models/sampleWithIframe.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/scripts/view-models/singlePageSample.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/fusionapp/styles/dummy.txt create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/CSS/Notification/angular-csp.css create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/CSS/Notification/angular-ui-notification.min.css create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/CSS/Notification/angular-ui-notification.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/CSS/bootstrap.min.css create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/CSS/bootstrap.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/CSS/select.css create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/CSS/select.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/CSS/w3.css create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/JSONDataFiles/JSONConfig.json create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/Properties/config.json create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/ActionPolicyDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/AttributeDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/BRMSParamDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/CLPepOptionsDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/CLServiceTypeDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/CLSiteDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/CLVarbindDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/CLVnfTypeDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/CLVsclActionDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/DecisionSettingsDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/DescriptiveScopeDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/EcompNameDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/EnforcerTypeDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/FWActionListDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/FWAddressGroupDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/FWParentListDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/FWPortListDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/FWPrefixListDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/FWProtocolListDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/FWSecurityZoneDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/FWServiceGroupDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/FWServiceListDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/FWTermListDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/FWZoneDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/MSConfigNameDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/MSDCAEUUIDDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/MSLocationDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/MSModelsDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/PSClosedLoopDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/PSGroupPolicyScopeDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/PSResourceDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/PSServiceDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/PSTypeDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/RiskTypeDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/SafePolicyWarningDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Edit_Roles_Window.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/PDPTabWindows/AddorEditPDPtoGroup.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/PDPTabWindows/PdpStatusWindow.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/PushtabWindow/removeGroupPoliciesWindow.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/new_PDPGroup_Window.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/AutoPushController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/AutoPushTabController/RemovePDPGroupPoliciesController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/DictionaryController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/FileSaver.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/ImportDictionaryController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/PDPTabController/AddorEditPdpInGroup.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/PDPTabController/PDPGroupStatusController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/PolicyAddScopeRoleController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/PolicyRolesController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dashboardController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dashboard_Logging_Controller.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/BRMSParamDictController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/CLPepOptionsDictController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/CLServiceDictController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/CLSiteDictController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/CLVarbindDictController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/CLVnfTypeDictController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/CLVsclActionDictController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/DecisionSettingsDictController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/DescriptiveSearchDictController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/EnforcerDictController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/FWActionListDictController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/FWAddressGroupDictController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/FWParentListDictController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/FWPortListDictController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/FWPrefixListDictController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/FWProtocolListDictController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/FWSecurityZoneDictController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/FWServiceGroupDictController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/FWServiceListDictController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/FWTermListDictController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/FWZoneDictController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/MSConfigNameDictController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/MSDcaeUUIDDictController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/MSLocationDictController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/MSModelsDictController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/PSClosedLoopDictController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/PSGroupPolicyScopeDictController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/PSResourceDictController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/PSServiceDictController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/PSTypeDictController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/RiskTypeDictController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/SafePolicyWarningDictController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/actionPolicyDictController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/attributeDictController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/ecompNameEditorController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/BRMSParamDictGridController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/CLPepOptionsDictGridController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/CLServiceDictGridController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/CLSiteDictGridController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/CLVarbindDictGridController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/CLVnfTypeDictGridController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/CLVsclActionDictGridController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/DecisionSettingsDictGridController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/DescriptiveScopeDictGridController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/EnforcerTypeDictGridController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/FWActionListDictGridController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/FWAddressGroupDictGridController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/FWParentListDictGridController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/FWPortListDictGridController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/FWPrefixListDictGridController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/FWProtocolListDictGridController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/FWSecurityZoneDictGridController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/FWServiceGroupDictGridController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/FWServiceListDictGridController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/FWTermListDictGridController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/FWZoneDictGridController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/MSConfigNameDictGridController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/MSDcaeUUIDDictGridController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/MSLocationDictGridController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/MSModelDictGridController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/PSClosedLoopDictGridController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/PSGroupPolicyScopeDictGridController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/PSResourceDictGridController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/PSServiceDictGridController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/PSTypeDictGridController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/RiskTypeDictGridController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/SafePolicyWarningDictGridController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/actionPolicyDictGridController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/attributeDictGridController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/ecompNameDictGridController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/editorTabController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/pdpController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/pdpGroupPopUpController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/policyAdminTabController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/controller/policyController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/images/loading.gif create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/images/loading_bar.gif create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/README.md create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular-cookies/.bower.json create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular-cookies/README.md create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular-cookies/angular-cookies.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular-cookies/angular-cookies.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular-cookies/angular-cookies.min.js.map create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular-cookies/bower.json create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular-cookies/index.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular-cookies/package.json create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular-translate/angular-translate.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular/.bower.json create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular/README.md create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular/angular-csp.css create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular/angular.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular/angular.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular/angular.min.js.gzip create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular/angular.min.js.map create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular/bower.json create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular/index.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular/package.json create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/bootstrap/dist/css/bootstrap.min.css create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/bootstrap/dist/js/bootstrap.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/bootswatch/fonts/glyphicons-halflings-regular.eot create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/bootswatch/fonts/glyphicons-halflings-regular.svg create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/bootswatch/fonts/glyphicons-halflings-regular.ttf create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/bootswatch/fonts/glyphicons-halflings-regular.woff create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/bootswatch/fonts/glyphicons-halflings-regular.woff2 create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/bootswatch/paper/bootstrap.min.css create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/.bower.json create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/MIT-LICENSE.txt create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/bower.json create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/dist/jquery.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/dist/jquery.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/dist/jquery.min.map create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/ajax.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/ajax/jsonp.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/ajax/load.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/ajax/parseJSON.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/ajax/parseXML.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/ajax/script.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/ajax/var/nonce.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/ajax/var/rquery.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/ajax/xhr.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/attributes.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/attributes/attr.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/attributes/classes.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/attributes/prop.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/attributes/support.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/attributes/val.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/callbacks.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/core.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/core/access.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/core/init.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/core/parseHTML.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/core/ready.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/core/var/rsingleTag.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/css.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/css/addGetHookIf.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/css/curCSS.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/css/defaultDisplay.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/css/hiddenVisibleSelectors.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/css/support.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/css/swap.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/css/var/cssExpand.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/css/var/getStyles.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/css/var/isHidden.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/css/var/rmargin.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/css/var/rnumnonpx.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/data.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/data/Data.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/data/accepts.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/data/var/data_priv.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/data/var/data_user.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/deferred.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/deprecated.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/dimensions.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/effects.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/effects/Tween.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/effects/animatedSelector.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/event.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/event/ajax.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/event/alias.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/event/support.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/exports/amd.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/exports/global.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/intro.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/jquery.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/manipulation.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/manipulation/_evalUrl.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/manipulation/support.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/manipulation/var/rcheckableType.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/offset.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/outro.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/queue.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/queue/delay.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/selector-native.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/selector-sizzle.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/selector.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/serialize.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/sizzle/dist/sizzle.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/sizzle/dist/sizzle.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/sizzle/dist/sizzle.min.map create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/traversing.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/traversing/findFilter.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/traversing/var/rneedsContext.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/var/arr.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/var/class2type.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/var/concat.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/var/hasOwn.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/var/indexOf.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/var/pnum.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/var/push.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/var/rnotwhite.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/var/slice.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/var/strundefined.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/var/support.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/var/toString.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/jquery/src/wrap.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/ng-file-upload/ng-file-upload.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/html2canvas.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/jquery.base64.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/jspdf/jspdf.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/jspdf/libs/base64.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/jspdf/libs/sprintf.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/jspdf/pdfmake.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/tableExport.jquery.json create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/libs/tableExport.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/main/policy_Editor.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Dictionary/ActionPolicyDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Dictionary/AttributeDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Dictionary/BRMSParamDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Dictionary/CLPepOptionsDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Dictionary/CLServiceDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Dictionary/CLSiteDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Dictionary/CLVNFTypeDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Dictionary/CLVSCLActionDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Dictionary/CLVarbindDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Dictionary/DecisionSettingsDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Dictionary/DescriptiveScopeDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Dictionary/EcompNameDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Dictionary/EnforcerTypeDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Dictionary/FWActionLisdtDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Dictionary/FWActionListDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Dictionary/FWAddressGroupDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Dictionary/FWParentListDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Dictionary/FWPortListDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Dictionary/FWPrefixListDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Dictionary/FWProtocolListDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Dictionary/FWSecurityZoneDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Dictionary/FWServiceGroupDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Dictionary/FWServiceListDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Dictionary/FWTermListDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Dictionary/FWZoneDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Dictionary/MSConfigNameDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Dictionary/MSDcaeUUIDDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Dictionary/MSLocationDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Dictionary/MSModelDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Dictionary/PSClosedLoopDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Dictionary/PSGroupPolicyScopeDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Dictionary/PSResourceDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Dictionary/PSServiceDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Dictionary/PSTypeDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Dictionary/RiskTypeDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Dictionary/SafePolicyWarningDictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/ActionPolicyController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/BRMSParamPolicyController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/BRMSRawPolicyController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/BaseConfigPolicyController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/ClosedLoopFaultController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/ClosedLoopPMController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/DCAEMicroServicePolicyController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/DecisionPolicyController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/ExportPolicyController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/FirewallPolicyController.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/PolicyDictionaryService.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplates/ActionPolicyTemplate.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplates/BRMSParamPolicyTemplate.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplates/BRMSRawPolicyTemplate.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplates/BasePolicyTemplate.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplates/ClosedLoopFaultPolicyTemplate.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplates/ClosedLoopPMPolicyTemplate.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplates/DCAEMicroServicePolicyTemplate.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplates/DecisionPolicyTemplate.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplates/DescribePolicyTemplate.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplates/ExportPolicyTemplate.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplates/FirewallPolicyTemplate.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplates/PolicyTypeTemplate.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Editor/css/normalize-legacy.css create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Editor/css/normalize.css create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Editor/css/styles.css create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Editor/src/css/animations.css create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Editor/src/css/dialogs.css create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Editor/src/css/main.css create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Editor/src/js/app.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Editor/src/js/controllers/main.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Editor/src/js/controllers/selector-controller.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Editor/src/js/directives/directives.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Editor/src/js/entities/item.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Editor/src/js/filters/filters.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Editor/src/js/providers/config.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Editor/src/js/providers/translations.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Editor/src/js/services/RolesService.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Editor/src/js/services/filenavigator.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Editor/src/js/services/fileuploader.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Editor/src/templates/current-folder-breadcrumb.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Editor/src/templates/item-context-menu.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Editor/src/templates/item-toolbar.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Editor/src/templates/main-icons.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Editor/src/templates/main-table-modal.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Editor/src/templates/main-table.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Editor/src/templates/main.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Editor/src/templates/modals.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Editor/src/templates/navbar.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Editor/src/templates/sidebar.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/Editor/src/templates/spinner.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/policy_AdminTab.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/policy_AutoPush.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/policy_DashboardHealth.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/policy_DashboardLogging.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/policy_Dictionary.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/policy_PDPManagement.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/policy-models/policy_Roles.html create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/service/AdminTabService.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/service/AutoPushService.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/service/ClosedLoopPMService.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/service/DashboardService.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/service/Dictionary/CLDictionaryService.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/service/Dictionary/DictionaryService.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/service/Dictionary/FWDictionaryService.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/service/Dictionary/MSDictionaryService.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/service/Dictionary/PolicyScopeService.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/service/Dictionary/SafePolicyService.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/service/ExportPolicyService.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/service/PDPService.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/service/PapUrlService.js create mode 100644 ecomp-sdk-app/src/main/webapp/app/policyApp/service/RolesTabService.js create mode 100644 ecomp-sdk-app/src/main/webapp/index.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/manifest.jsp create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/css/att_angular_gridster/sandbox-gridster.css create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/css/att_angular_gridster/ui-gridster.css create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/css/fusion-sunny.css create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/css/jquery-ui.css create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/css/layout/layout-default-latest.css create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/css/nv.d3.css create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/cie.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/colorbrewer.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/core.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/crossfilter.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/crossfilter.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/d3.geom.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/d3.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/d3.layout.cloud.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/d3.layout.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/d3.v2.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/d3.v2.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/d3.v3.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/fisheye.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/hive.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/horizon.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/interactiveLayer.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/intro.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/models/axis-min.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/models/axis.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/models/axis.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/models/backup/bullet.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/models/backup/bulletChart.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/models/boilerplate.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/models/bullet.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/models/bulletChart.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/models/cumulativeLineChart.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/models/discreteBar.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/models/discreteBarChart.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/models/distribution.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/models/historicalBar.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/models/historicalBarChart.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/models/indentedTree.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/models/legend.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/models/line.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/models/lineChart.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/models/linePlusBarChart.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/models/linePlusBarWithFocusChart.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/models/lineWithFisheye.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/models/lineWithFisheyeChart.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/models/lineWithFocusChart.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/models/multiBar.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/models/multiBarChart.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/models/multiBarHorizontal.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/models/multiBarHorizontalChart.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/models/multiBarTimeSeries.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/models/multiBarTimeSeriesChart.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/models/multiChart.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/models/ohlcBar.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/models/parallelCoordinates.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/models/pie.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/models/pieChart.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/models/scatter.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/models/scatterChart.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/models/scatterPlusLineChart.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/models/sparkline.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/models/sparklinePlus.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/models/stackedArea.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/models/stackedAreaChart.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/nv.d3.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/nv.d3.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/outro.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/sankey.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/tooltip.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/d3/js/utils.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/Logo_att_labs.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/Rlogo.jpg create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/Thumbs.db create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/action_icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/action_list_spacer.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/active.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/add.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/add_tool_button.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/addicon.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/application_window_bg.jpg create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/arrow-next.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/arrow-prev.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/att_angular_gridster/grips.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/backButton.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/blank.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/blueButton.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/bubble.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/cache.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/calendar.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/chevron.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/close_container.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/collapsed-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/column-bg.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/copyicon-highlighted.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/copyicon.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/csv_icon.jpg create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/csv_icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/customers-add.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/customers-search.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/customers.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/decrypted.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/deleteicon-highlighted.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/deleteicon-highlighted.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/deleteicon.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/ecomp.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/ecomp_trans.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/editicon.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/error_type.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/example-frame.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/excelicon_multi.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/executeicon.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/expanded-icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/file-add.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/file_import.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/file_save-all.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/filter_icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/folder_add.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/folder_closed.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/folder_delete.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/folder_edit.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/folder_open.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/folder_user.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/funnel.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/fusion.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/grayButton.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/gray_add_tool_button.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/headerChatIcon.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/icon_remove_all.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/inactive.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/info_type.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/layout/panel-e-w-toggle.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/layout/panel-n-s-toggle.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/leftButton.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/loading.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/loading_bar.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/login_button.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/logo_att.jpg create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/logo_att_header.jpg create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/logo_att_header.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/logo_header.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/m1.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/mail.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/map.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/menu/bubble.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/menu/file_import.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/menu/file_save-all.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/menu/mail.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/menu/profile.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/menu/speechbubble.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/menu/users.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/minus.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/mobile_logo_att_header_black.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/mobile_logo_att_header_grey.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/mobile_logo_att_header_horizontal.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/mobile_logo_att_header_white.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/modify_icon.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/no_favorites_star.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/note-add.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/note-search.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/note.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/notes.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/offline.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/offlineMsg.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/online.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/page.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/pagination.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/panel-e-w-toggle.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/panel-n-s-toggle.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/pix.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/plus.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/printer.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/profile.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/report-add.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/report-favorite.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/report-my.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/report-public.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/report.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/reports.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/results-first-active.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/results-first-disabled.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/results-last-active.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/results-last-disabled.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/results-next-active.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/results-next-disabled.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/results-prev-active.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/results-prev-disabled.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/resultset_last.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/resultset_previous.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/return_to_top.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/rightButton.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/search.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/search_profile.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/sort_asc.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/sort_desc.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/spacer.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/success_type.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/swoosh.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/tab-hm.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/tab-v-hm.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/tab.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/table-add.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/table-delete.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/table-edit.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/table.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/tabs-bg.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/toolButton.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/toolButton.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/toolbar.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/users.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/warning_type.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/webphone.ico create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/images/whiteButton.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/js/att_angular_gridster/angular-gridster.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/js/att_angular_gridster/ui-gridster-tpls.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/js/jquery.resize.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/js/layout/debug.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/js/layout/jquery-latest.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/js/layout/jquery-ui-latest.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/js/layout/jquery.layout-latest.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/js/moment.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/css/Style.css create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/css/bd_quantum_raptor.css create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/css/calendar.css create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/css/dashboard.css create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/css/drupal.css create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/css/form-field-tooltip.css create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/css/mobile_raptor.css create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/css/novamap.css create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/css/picker.css create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/css/ral.css create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/css/raptor.css create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/css/tree/context-menu.css create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/css/nv.d3.css create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/cie.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/colorbrewer.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/core.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/crossfilter.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/crossfilter.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/d3.geom.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/d3.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/d3.layout.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/d3.v2.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/d3.v2.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/d3.v3.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/d3.v3.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/fisheye.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/hive.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/horizon.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/interactiveLayer.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/intro.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/models/axis-min.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/models/axis.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/models/axis.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/models/boilerplate.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/models/bullet.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/models/bulletChart.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/models/cumulativeLineChart.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/models/discreteBar.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/models/discreteBarChart.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/models/distribution.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/models/historicalBar.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/models/historicalBarChart.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/models/indentedTree.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/models/legend.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/models/line.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/models/lineChart.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/models/linePlusBarChart.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/models/linePlusBarWithFocusChart.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/models/lineWithFisheye.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/models/lineWithFisheyeChart.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/models/lineWithFocusChart.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/models/multiBar.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/models/multiBarChart.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/models/multiBarHorizontal.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/models/multiBarHorizontalChart.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/models/multiBarTimeSeries.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/models/multiBarTimeSeriesChart.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/models/multiChart.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/models/ohlcBar.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/models/parallelCoordinates.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/models/pie.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/models/pie.js.bak create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/models/pieChart.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/models/scatter.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/models/scatterChart.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/models/scatterPlusLineChart.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/models/sparkline.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/models/sparklinePlus.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/models/stackedArea.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/models/stackedAreaChart.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/nv.d3.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/outro.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/sankey.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/tooltip.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/d3/js/utils.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/dy3/js/dashed-canvas.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/dy3/js/data.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/dy3/js/dygraph-canvas.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/dy3/js/dygraph-combined.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/dy3/js/dygraph-combined_bak_color.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/dy3/js/dygraph-dev.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/dy3/js/dygraph-externs.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/dy3/js/dygraph-gviz.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/dy3/js/dygraph-interaction-model.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/dy3/js/dygraph-layout.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/dy3/js/dygraph-options-reference.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/dy3/js/dygraph-options.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/dy3/js/dygraph-plugin-base.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/dy3/js/dygraph-plugin-install.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/dy3/js/dygraph-tickers.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/dy3/js/dygraph-utils.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/dy3/js/dygraph.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/dy3/js/excanvas.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/dy3/js/interaction.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/dy3/js/interaction.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/dy3/js/interaction_sun.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/dy3/js/moment.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/dy3/js/phantom-driver.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/dy3/js/phantom-perf.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/dy3/js/plugins/README create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/dy3/js/plugins/annotations.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/dy3/js/plugins/axes.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/dy3/js/plugins/chart-labels.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/dy3/js/plugins/grid.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/dy3/js/plugins/legend.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/dy3/js/plugins/range-selector.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/dy3/js/rgbcolor/rgbcolor.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/dy3/js/stacktrace.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/dy3/js/strftime/Doxyfile create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/dy3/js/strftime/strftime-min.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/dy3/js/strftime/strftime.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/ebz/date_time_picker.css create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/ebz/date_time_picker.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/ebz/dynamicform.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/ebz/moment.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/ebz/multiselect.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/ebz/quick_links.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/ebz/report_chart_wizard.html create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/ebz/report_chart_wizard.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/ebz/report_run.html create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/ebz/report_run.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/ebz/report_search.html create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/ebz/report_search.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/RAPTOR_BANNER.jpg create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/accessicon.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/active.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/addbtn.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/ajax-loader.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/arrow_add.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/arrow_add_edge.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/arrow_add_multiple.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/arrow_add_one.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/arrow_back.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/arrow_cancel.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/arrow_left.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/arrow_left2.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/arrow_next.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/arrow_plus.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/arrow_reorder_all.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/arrow_reorder_all.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/arrow_right.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/arrow_right2.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/arrow_save.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/button_import.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/calendar_icon.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/calendar_icon_nav.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/calendar_icon_nav1.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/calender_icon.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/columnblankdown.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/columnblankup.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/columndown.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/columnup.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/crosshairs.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/csv_icon.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/deleteicon.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/downloadicon.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/excel2007.jpg create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/excel2007.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/excelicon.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/excelicon_multi.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/green-arrow-right.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/green-arrow.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/grnarrowdn.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/grnarrowup.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/h.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/inactive.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/loader.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/loading.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/lookup_arrow.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/maps/blue.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/maps/green.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/maps/lightblue.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/maps/map_iphone.jpg create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/maps/orange.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/maps/pink.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/maps/purple.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/maps/red.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/maps/yellow.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/minus.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/modify_icon.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/page.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/pdficon_large.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/pdficon_small.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/pen_paper.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/plus.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/popupicon.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/position.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/printer.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/progress.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/question_mark.jpg create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/quickhelp_dk.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/quickhelp_lt.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/r_back.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/raptor.jpg create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/raptor_logo.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/raptor_logo.jpg create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/required.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/shareicon.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/sv.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/tab_left.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/tab_left_sel.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/tab_right.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/tab_right_sel.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/test_run.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/text.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/tree/context-menu-gradient.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/tree/dhtmlgoodies_folder.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/tree/dhtmlgoodies_minus.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/tree/dhtmlgoodies_plus.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/tree/dhtmlgoodies_sheet.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/tree/dhtmlgoodies_sheet_crosstab.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/tree/dhtmlgoodies_sheet_dashboard.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/tree/dhtmlgoodies_sheet_graph.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/tree/dragDrop_ind1.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/tree/dragDrop_ind2.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/tree/folder_close.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/tree/folder_dots.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/tree/folder_folder.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/tree/folder_lastsub.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/tree/folder_open.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/tree/folder_sub.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/tree/grnarrowleft.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/tree/grnarrowright.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/txt_icon.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/uF033.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/uF034.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/uF035.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/images/uF036.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/img/BorderLayout-24x24.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/img/Calendar-16x16.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/img/DeleteCross-16x16.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/img/addbtn.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/img/button_import.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/img/copyicon-highlighted.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/img/copyicon.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/img/cross-small.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/img/csv_icon.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/img/csv_icon.jpg create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/img/csv_icon.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/img/deleteicon-highlighted.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/img/deleteicon-highlighted.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/img/deleteicon.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/img/downloadicon.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/img/editicon.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/img/excel2007.jpg create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/img/excelicon.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/img/excelicon_multi.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/img/executeicon.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/img/file_import.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/img/pdficon_small.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/img/pen_paper.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/img/pencil-small.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/img/report-add.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/img/report-favorite.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/img/report-my.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/img/report-public.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/img/report.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/img/reports.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/img/search.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/img/search.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/img/tick-small.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/js/CalendarPopup.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/js/ajax.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/js/ajax_dynamic_content.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/js/cingular_button.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/js/drupal.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/js/editabledropdown.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/js/form-field-tooltip.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/js/gmap.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/js/jquery.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/js/jquery.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/js/label_quantum.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/js/nova_button.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/js/other_scripts.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/js/persist_table_header.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/js/prototype-1.6.0.3.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/js/raptor.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/js/rounded-corners.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/js/script.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/js/tree/ajax.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/uigrid/ui-grid.css create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/uigrid/ui-grid.eot create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/uigrid/ui-grid.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/uigrid/ui-grid.svg create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/uigrid/ui-grid.ttf create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/uigrid/ui-grid.woff create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/css/images/blank.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/css/scribble.css create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/css/slider.css create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/css/spacegallery.css create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/css/welcome.css create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/html/area_chart.html create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/html/bar_chart.html create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/html/d3_gauges_demo.html create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/html/data/speedometer2.csv create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/html/data/speedometer3.csv create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/html/data/worddata.csv create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/html/donut_d3.html create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/html/js/area_chart.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/html/js/donut.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/html/js/gauges.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/html/js/line_chart.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/html/js/pie_chart.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/html/js/worddata.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/html/line_chart.html create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/html/pie_chart.html create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/html/wordcloud.html create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/images/Calendar-16x16.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/images/arrow-next.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/images/arrow-prev.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/images/carousel/slide_b_drive_test_map.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/images/carousel/slide_b_eppt_county.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/images/carousel/slide_b_eppt_regression.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/images/carousel/slide_b_ios_throughput.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/images/carousel/slide_b_lata_map.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/images/carousel/slide_b_lata_map_legend.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/images/carousel/slide_b_nova_sdn_map.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/images/copyicon.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/images/deleteicon.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/images/example-frame.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/images/loading.gif create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/images/tunnels/1_mon.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/images/tunnels/2_tue.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/images/tunnels/3_wed.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/images/tunnels/4_thu.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/images/tunnels/5_fri.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/images/tunnels/6_sat.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/images/tunnels/7_sun.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/images/tunnels/BH_DLSTX_IN.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/images/tunnels/BH_DLSTX_OUT.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/images/tunnels/BH_Nat.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/images/tunnels/BH_Nat_Def.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/images/tunnels/BH_Nat_Priority.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/js/FusionCharts.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/js/charts.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/js/jquery.flexslider-min.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/js/scribble.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/js/slides.min.jquery.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/js/spacegallery.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/org_chart/css/bootstrap.min.css create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/org_chart/css/custom.css create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/org_chart/css/jquery.jOrgChart.css create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/org_chart/css/prettify.css create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/org_chart/example.html create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/org_chart/example_vsp.html create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/org_chart/images/bkgd.png create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/org_chart/images/raspberry.jpg create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/org_chart/jquery.jOrgChart.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/sample/org_chart/prettify.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/js/jquery-1.10.2.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/js/jquery-ui.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/js/jquery.mask.min.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/js/modalService.js create mode 100644 ecomp-sdk-app/src/main/webapp/static/js/search.js create mode 100644 ecomp-sdk-app/src/test/java/org/openecomp/portalapp/SanityTest.java create mode 100644 ecomp-sdk-app/src/test/java/org/openecomp/portalapp/controller/CollaborationControllerTest.java create mode 100644 ecomp-sdk-app/src/test/java/org/openecomp/portalapp/controller/NetMapTest.java create mode 100644 ecomp-sdk-app/src/test/java/org/openecomp/portalapp/service/ProfileServiceTest.java create mode 100644 ecomp-sdk-app/src/test/java/org/openecomp/portalsdk/core/MockApplicationContextTestSuite.java create mode 100644 ecomp-sdk-app/src/test/java/org/openecomp/portalsdk/workflow/services/WorkflowScheduleServiceTest.java create mode 100644 ecomp-sdk-app/xacml.admin.properties create mode 100755 packages/base/pom.xml create mode 100644 packages/base/src/assembly/zip.xml create mode 100644 packages/base/src/files/bin/backup.sh create mode 100644 packages/base/src/files/bin/certtool.sh create mode 100644 packages/base/src/files/bin/java/log4j.properties create mode 100644 packages/base/src/files/bin/monitor.sh create mode 100644 packages/base/src/files/bin/policy.sh create mode 100644 packages/base/src/files/etc/cron.d/logrotate.cron create mode 100644 packages/base/src/files/etc/cron.d/monitor.cron create mode 100644 packages/base/src/files/etc/logrotate.d/monitor.conf create mode 100644 packages/base/src/files/etc/monitor/monitor.cfg create mode 100644 packages/base/src/files/etc/profile.d/env.sh create mode 100644 packages/base/src/files/etc/profile.d/su.cfg create mode 100644 packages/base/src/files/install/mysql/bin/cleanup_policy.sh create mode 100644 packages/base/src/files/install/mysql/bin/db_backup.sh create mode 100644 packages/base/src/files/install/mysql/bin/db_backup_data.sh create mode 100644 packages/base/src/files/install/mysql/bin/db_backup_remote.sh create mode 100644 packages/base/src/files/install/mysql/bin/db_restore.sh create mode 100644 packages/base/src/files/install/mysql/bin/db_restore_data.sh create mode 100644 packages/base/src/files/install/mysql/bin/db_upgrade.sh create mode 100644 packages/base/src/files/install/mysql/bin/db_upgrade_remote.sh create mode 100644 packages/base/src/files/install/mysql/data/161000_upgrade_script.sql create mode 100644 packages/base/src/files/install/servers/brmsgw/client.properties create mode 100644 packages/base/src/files/install/servers/brmsgw/config.properties create mode 100644 packages/base/src/files/install/servers/brmsgw/config/policyLogger.properties create mode 100644 packages/base/src/files/install/servers/brmsgw/init.d/brmsgw create mode 100755 packages/base/src/files/install/servers/common/logparser/init.d/logparserd create mode 100644 packages/base/src/files/install/servers/common/tomcat/bin/setenv.sh create mode 100644 packages/base/src/files/install/servers/common/tomcat/conf/server.xml create mode 100644 packages/base/src/files/install/servers/common/tomcat/init.d/tomcatd create mode 100644 packages/base/src/files/install/servers/configs/conf/server.xml create mode 100644 packages/base/src/files/install/servers/console/bin/JSONConfig.json create mode 100644 packages/base/src/files/install/servers/console/bin/Policy-Admin.xml create mode 100644 packages/base/src/files/install/servers/console/bin/config/policyLogger.properties create mode 100644 packages/base/src/files/install/servers/console/bin/model.properties create mode 100644 packages/base/src/files/install/servers/console/bin/sql/log.h2.db create mode 100644 packages/base/src/files/install/servers/console/bin/sql/xacml.h2.db create mode 100644 packages/base/src/files/install/servers/console/bin/workspace/admin/repository/com/Config_BRMS_Param_BRMSParamvFWDemoPolicy.1.xml create mode 100644 packages/base/src/files/install/servers/console/bin/workspace/admin/repository/com/Config_BRMS_Param_BRMSParamvLBDemoPolicy.1.xml create mode 100644 packages/base/src/files/install/servers/console/bin/workspace/admin/repository/com/Config_MS_vFirewall.1.xml create mode 100644 packages/base/src/files/install/servers/console/bin/workspace/admin/repository/com/Config_MS_vLoadBalancer.1.xml create mode 100644 packages/base/src/files/install/servers/console/bin/xacml.admin.properties create mode 100644 packages/base/src/files/install/servers/console/conf/server.xml create mode 100644 packages/base/src/files/install/servers/ecomp/WEB-INF/classes/portal.properties create mode 100644 packages/base/src/files/install/servers/ecomp/WEB-INF/conf/system.properties create mode 100644 packages/base/src/files/install/servers/ecomp/app/policyApp/Properties/config.json create mode 100644 packages/base/src/files/install/servers/pap/bin/autopush.properties create mode 100644 packages/base/src/files/install/servers/pap/bin/config/policyLogger.properties create mode 100644 packages/base/src/files/install/servers/pap/bin/test.properties create mode 100644 packages/base/src/files/install/servers/pap/bin/xacml.pap.properties create mode 100644 packages/base/src/files/install/servers/pap/webapps/Config/com.Config_BRMS_Param_BRMSParamvFWDemoPolicy.1.txt create mode 100644 packages/base/src/files/install/servers/pap/webapps/Config/com.Config_BRMS_Param_BRMSParamvLBDemoPolicy.1.txt create mode 100644 packages/base/src/files/install/servers/pap/webapps/Config/com.Config_MS_vFirewall.1.json create mode 100644 packages/base/src/files/install/servers/pap/webapps/Config/com.Config_MS_vLoadBalancer.1.json create mode 100644 packages/base/src/files/install/servers/paplp/bin/config/policyLogger.properties create mode 100644 packages/base/src/files/install/servers/paplp/bin/parserlog.properties create mode 100644 packages/base/src/files/install/servers/pdp/bin/config/policyLogger.properties create mode 100644 packages/base/src/files/install/servers/pdp/bin/xacml.pdp.properties create mode 100644 packages/base/src/files/install/servers/pdplp/bin/config/policyLogger.properties create mode 100755 packages/base/src/files/install/servers/pdplp/bin/parserlog.properties create mode 100644 packages/base/src/files/install/servers/pypdp/bin/client.properties create mode 100644 packages/base/src/files/install/servers/pypdp/bin/config.properties create mode 100644 packages/base/src/files/install/servers/pypdp/bin/config/policyLogger.properties create mode 100644 packages/base/src/files/m2/settings.xml create mode 100644 packages/install/pom.xml create mode 100644 packages/install/src/assembly/zip.xml create mode 100644 packages/install/src/files/base.conf create mode 100644 packages/install/src/files/brmsgw.conf create mode 100644 packages/install/src/files/console.conf create mode 100755 packages/install/src/files/mysql.conf create mode 100644 packages/install/src/files/pap.conf create mode 100755 packages/install/src/files/paplp.conf create mode 100644 packages/install/src/files/pdp.conf create mode 100755 packages/install/src/files/pdplp.conf create mode 100644 packages/install/src/files/pypdp.conf create mode 100644 packages/pom.xml create mode 100644 pom.xml create mode 100644 project-configs/maven/conf/settings.xml create mode 100644 version.properties diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..47c989c59 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,40 @@ +# Handle line endings automatically for files detected as text +# and leave all files detected as binary untouched. +* text=auto + +# +# The above will handle all files NOT found below +# +# These files are text and should be normalized (Convert crlf => lf) +*.css text +*.df text +*.htm text +*.html text +*.java text +*.js text +*.json text +*.jsp text +*.jspf text +*.properties text +*.sh text +*.svg text +*.tld text +*.txt text +*.xml text +*.conf text +*.env text +*.cron text + +# These files are binary and should be left untouched +# (binary is a macro for -text -diff) +*.class binary +*.dll binary +*.ear binary +*.gif binary +*.ico binary +*.jar binary +*.jpg binary +*.jpeg binary +*.png binary +*.so binary +*.war binary diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..32d8e38a5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,29 @@ +.project +.settings +.classpath +.jupiter +.pydevproject +target +.metadata/ +ASTRAGateway/policyEngineLog.log +LogParser/IntegrityMonitor.log +PolicyEngineAPI/policyEngineLog.log +PyPDPServer/src/main/java/controller/.PolicyEngineServices.java.swp +XACML-PAP-ADMIN/sql/xacmlTest.trace.db +XACML-PAP-ADMIN/src/main/resources/META-INF/generatedCreate.ddl +XACML-PAP-ADMIN/src/main/resources/META-INF/generatedDrop.ddl +XACML-PAP-ADMIN/src/main/webapp/VAADIN/themes/xacml_pap_admin/addons.scss +XACML-PAP-REST/catalina.base_IS_UNDEFINED/logs/Policy/XACML-PAP-REST/audit.log +XACML-PAP-REST/catalina.base_IS_UNDEFINED/logs/Policy/XACML-PAP-REST/debug.log +XACML-PAP-REST/catalina.base_IS_UNDEFINED/logs/Policy/XACML-PAP-REST/error.log +XACML-PAP-REST/catalina.base_IS_UNDEFINED/logs/Policy/XACML-PAP-REST/metrics.log +XACML-PAP-REST/pdps/default/xacml.pip.properties +XACML-PAP-REST/pdps/default/xacml.policy.properties +XACML-PAP-REST/pdps/xacml.properties +XACML-PAP-REST/sql/xacmlTest.trace.db +XACML-PAP-REST/src/main/resources/META-INF/generatedCreate.ddl +XACML-PDP-REST/catalina.base_IS_UNDEFINED/logs/Policy/XACML-PDP-REST/audit.log +XACML-PDP-REST/catalina.base_IS_UNDEFINED/logs/Policy/XACML-PDP-REST/debug.log +XACML-PDP-REST/catalina.base_IS_UNDEFINED/logs/Policy/XACML-PDP-REST/error.log +XACML-PDP-REST/catalina.base_IS_UNDEFINED/logs/Policy/XACML-PDP-REST/metrics.log +XACML-REST/IntegrityMonitor.log diff --git a/.gitreview b/.gitreview new file mode 100644 index 000000000..baf026ec6 --- /dev/null +++ b/.gitreview @@ -0,0 +1,4 @@ +[gerrit] +host=gerrit.openecomp.org +port=29418 +project=policy/engine.git diff --git a/BRMSGateway/config.properties b/BRMSGateway/config.properties new file mode 100644 index 000000000..bf846de09 --- /dev/null +++ b/BRMSGateway/config.properties @@ -0,0 +1,84 @@ +### +# ============LICENSE_START======================================================= +# ECOMP Policy Engine +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +PDP_URL2 = https://localhost:8081/pdp/ , testpdp, alpha123 +PAP_URL = http://localhost:9090/pap/ , testpap, alpha123 +NOTIFICATION_TYPE=websocket +NOTIFICATION_UEB_SERVERS= +CLIENT_ID= +CLIENT_KEY= + +# BRMS Properties. +## defaultName is the default group name to which the rule gets pushed if no artifactID is specified. +defaultName = default +## repositoryID +repositoryID = releases +## reposiroryName +repositoryName = Releases +## repositoryURL +repositoryURL = http://nexus:8081/nexus/content/repositories/releases +## repositoryUsername & Password +repositoryUsername=admin +repositoryPassword=admin123 +## policyKeyID the value of Policy Key whose value will be the group Name. +policyKeyID = controller +# UEB Notification Details. +UEB_URL=vm1.mr.simpledemo.openecomp.org +UEB_TOPIC=PDPD-CONFIGURATION +UEB_API_KEY= +UEB_API_SECRET= + +## GroupNames can be comma separated values. +groupNames = default, vFW , vDNS +default.groupID = org.openecomp.policy-engine +default.artifactID = drlPDPGroup +vFW.groupID= org.openecomp.policy-engine.drools.vFW +vFW.artifactID= policy-vFW-rules +vDNS.groupID= org.openecomp.policy-engine.drools.vDNS +vDNS.artifactID= policy-vDNS-rules + + +#Integrity Monitor values +#database driver for Integrity Monitor +javax.persistence.jdbc.driver=com.mysql.jdbc.Driver +#database URL for Integrity Monitor +javax.persistence.jdbc.url=jdbc:mysql://localhost:3306/xacml +#database username for Integrity Monitor +javax.persistence.jdbc.user=policy_user +#database password for Integrity Monitor +javax.persistence.jdbc.password=password +#resource name +RESOURCE_NAME=site_1.brmsgw_1 +#***Properties for IntegrityMonitor integration defined in IntegrityMonitorProperties.java*** +site_name=site_1 +node_type=brms_gateway +fp_monitor_interval=30 +failed_counter_threshold=3 +test_trans_interval=20 +write_fpc_interval=5 +max_fpc_update_interval=60 +test_via_jmx=false +ping_interval=30000 +# +# +# +brms.dependency.version=1.0.0-SNAPSHOT + +ENVIRONMENT = DEVL diff --git a/BRMSGateway/policyLogger.properties b/BRMSGateway/policyLogger.properties new file mode 100644 index 000000000..d3d477256 --- /dev/null +++ b/BRMSGateway/policyLogger.properties @@ -0,0 +1,44 @@ +### +# ============LICENSE_START======================================================= +# ECOMP Policy Engine +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +################################## Set concurrentHashMap and timer info ####################### +#Timer initial delay and the delay between in milliseconds before task is to be execute. +timer.delay.time=1000 +#Timer scheduleAtFixedRate period - time in milliseconds between successive task executions. +check.interval= 30000 +#Longest time an event info can be stored in the concurrentHashMap for logging - in seconds. +event.expired.time=86400 +#Size of the concurrentHashMap which stores the event starting time, etc - when its size reaches this limit, the Timer gets executed +#to remove all expired records from this concurrentHashMap. +concurrentHashMap.limit=5000 +#Size of the concurrentHashMap - when its size drops to this point, stop the Timer +stop.check.point=2500 +################################### Set logging format ############################################# +# set EELF for EELF logging format, set LOG4J for using log4j, set SYSTEMOUT for using system.out.println +logger.type=EELF +#################################### Set level for EELF or SYSTEMOUT logging ################################## +# Set level for debug file. Set DEBUG to enable .info, .warn and .debug; set INFO for enable .info and .warn; set OFF to disable all +debugLogger.level=INFO +# Set level for metrics file. Set OFF to disable; set ON to enable +metricsLogger.level=ON +# Set level for error file. Set OFF to disable; set ON to enable +error.level=ON +# Set level for audit file. Set OFF to disable; set ON to enable +audit.level=ON diff --git a/BRMSGateway/pom.xml b/BRMSGateway/pom.xml new file mode 100644 index 000000000..16eae6a98 --- /dev/null +++ b/BRMSGateway/pom.xml @@ -0,0 +1,112 @@ + + + + 4.0.0 + + org.openecomp.policy.engine + PolicyEngineSuite + 1.0.0-SNAPSHOT + + org.openecomp.policy.engine + BRMSGateway + This application will take in BRMS rules and acts as interface between PR and PDP XACML + + + org.openecomp.policy.engine + PolicyEngineAPI + ${project.version} + + + com.att.nsa + cambriaClient + + + + + org.apache.maven + maven-model + 2.2.1 + + + org.apache.maven.shared + maven-invoker + 2.2 + + + org.openecomp.policy.common + integrity-monitor + ${common-modules.version} + + + org.sonatype.nexus + nexus-rest-client-java + 2.3.1 + + + com.att.nsa + cambriaClient + 0.0.1 + + + org.slf4j + slf4j-log4j12 + + + + + org.apache.httpcomponents + httpclient + 4.5.2 + + + + + + + org.apache.maven.plugins + maven-assembly-plugin + 2.2 + + + + true + lib/ + org.openecomp.policy.brmsInterface.BRMSGateway + + + + jar-with-dependencies + + + + + make-assembly + package + + single + + + + + + + diff --git a/BRMSGateway/src/main/java/org/openecomp/policy/brmsInterface/BRMSGateway.java b/BRMSGateway/src/main/java/org/openecomp/policy/brmsInterface/BRMSGateway.java new file mode 100644 index 000000000..70c537c69 --- /dev/null +++ b/BRMSGateway/src/main/java/org/openecomp/policy/brmsInterface/BRMSGateway.java @@ -0,0 +1,88 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.brmsInterface; + +import org.openecomp.policy.api.NotificationScheme; +import org.openecomp.policy.api.PolicyEngine; + +//import org.apache.log4j.Logger; + +//import org.apache.commons.logging.Log; +//import org.apache.commons.logging.LogFactory; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + + +/** + * BRMSGateway: This application acts as the Gateway interface between the PDP XACML and PDP Drools. + * The listens for BRMS based policies and pushes them to the specified Policy Repository, from where the PDP Drools reads the Rule Jar. + * + * @version 0.1 + */ +public class BRMSGateway { +// private static final Logger logger = Logger.getLogger(BRMSGateway.class.getName()); + private static final Logger logger = FlexLogger.getLogger(BRMSGateway.class); + private static final String configFile = "config.properties"; + + private static PolicyEngine policyEngine = null; + + public static void main(String[] args) throws Exception{ + // Initialize Handler. + logger.info("Initializing BRMS Handler"); + BRMSHandler bRMSHandler = null; + try{ + bRMSHandler = new BRMSHandler(configFile); + }catch(NullPointerException e){ + logger.error("Check your property file: " + e.getMessage()); + System.exit(1); + } + + // Set Handler with Auto Notification and initialize policyEngine + try{ + logger.info("Initializing policyEngine with Auto Notifications"); + policyEngine= new PolicyEngine(configFile,NotificationScheme.AUTO_ALL_NOTIFICATIONS, bRMSHandler); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_UNKNOWN+"Error while Initializing Policy Engine " + e.getMessage()); + } + + //Keep Running.... + Runnable runnable = new Runnable(){ + public void run(){ + while (true){ + try { + Thread.sleep(30000); + } catch (InterruptedException e) { + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR+"Thread Exception " + e.getMessage()); + } + } + } + }; + Thread thread = new Thread(runnable); + thread.start(); + } + + public static PolicyEngine getPolicyEngine(){ + return policyEngine; + } +} diff --git a/BRMSGateway/src/main/java/org/openecomp/policy/brmsInterface/BRMSHandler.java b/BRMSGateway/src/main/java/org/openecomp/policy/brmsInterface/BRMSHandler.java new file mode 100644 index 000000000..2cc178736 --- /dev/null +++ b/BRMSGateway/src/main/java/org/openecomp/policy/brmsInterface/BRMSHandler.java @@ -0,0 +1,134 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.brmsInterface; + +import java.util.Collection; + +import org.openecomp.policy.api.ConfigRequestParameters; +import org.openecomp.policy.api.LoadedPolicy; +import org.openecomp.policy.api.NotificationType; +import org.openecomp.policy.api.PDPNotification; +import org.openecomp.policy.api.PolicyConfig; +import org.openecomp.policy.api.PolicyConfigStatus; +import org.openecomp.policy.api.PolicyEngine; +import org.openecomp.policy.api.RemovedPolicy; +import org.openecomp.policy.utils.BackUpHandler; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +//import org.apache.log4j.Logger; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +/** + * BRMSHandler: Notification Handler which listens for PDP Notifications. + * Take action only for BRMS policies. + * + * @version 0.3 + */ +public class BRMSHandler implements BackUpHandler{ + +// private static final Logger logger = Logger.getLogger(BRMSHandler.class.getName()); + private static final Logger logger = FlexLogger.getLogger(BRMSHandler.class.getName()); + // This Values are fixed for BRMS based rules. Don't change until they are changed during creation in PAP-ADMIN. + //private static final String ecompName = "DROOLS"; + //private static final String configName = "BRMS_RAW_RULE"; + + private BRMSPush bRMSPush = null; + + public BRMSHandler(String propertiesFile) throws Exception{ + bRMSPush = new BRMSPush(propertiesFile, this); + } + + @Override + public void notificationReceived(PDPNotification notification) { + logger.info("Notification Recieved"); + logger.info(notification.getNotificationType().toString()); + bRMSPush.initiate(); + if(BRMSPush.getBackUpMonitor().getFlag()){ + logger.info("Master Application performing on Notification "); + runOnNotification(notification); + }else{ + logger.info("Slave application Skipping Notification.. "); + } + } + + private void removedPolicies(Collection removedPolicies){ + Boolean removed = false; + logger.info("Removed Policies"); + for(RemovedPolicy removedPolicy: removedPolicies){ + logger.info(removedPolicy.getPolicyName()); + logger.info(removedPolicy.getVersionNo()); + if(removedPolicy.getPolicyName().contains("_BRMS_")){ + try{ + String name = removedPolicy.getPolicyName().substring(removedPolicy.getPolicyName().indexOf("_BRMS_")+6, removedPolicy.getPolicyName().length()); + name= name.substring(name.indexOf("_")+1,name.length()); + logger.info("Policy Removed with this policy Name : " + name); + bRMSPush.removeRule(name); + removed = true; + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW+"Rertriving policy failed " + e.getMessage()); + } + } + } + if(removed){ + bRMSPush.pushRules(); + } + } + + public void runOnNotification(PDPNotification notification){ + if(notification.getNotificationType().equals(NotificationType.REMOVE)){ + removedPolicies(notification.getRemovedPolicies()); + }else if(notification.getNotificationType().equals(NotificationType.UPDATE)|| notification.getNotificationType().equals(NotificationType.BOTH)){ + logger.info("Updated Policies: \n"); + for(LoadedPolicy updatedPolicy: notification.getLoadedPolicies()){ + logger.info("policyName : " + updatedPolicy.getPolicyName()); + logger.info("policyVersion :" + updatedPolicy.getVersionNo()); + logger.info("Matches: " + updatedPolicy.getMatches()); + // Checking the Name is correct or not. + if(updatedPolicy.getPolicyName().contains("_BRMS_")){ + try{ + PolicyEngine policyEngine = BRMSGateway.getPolicyEngine(); + if(policyEngine!=null){ + ConfigRequestParameters configRequestParameters = new ConfigRequestParameters(); + configRequestParameters.setPolicyName(updatedPolicy.getPolicyName()); + Collection policyConfigs = policyEngine.getConfig(configRequestParameters); + for(PolicyConfig policyConfig: policyConfigs){ + if(policyConfig.getPolicyConfigStatus().equals(PolicyConfigStatus.CONFIG_RETRIEVED)){ + String name = policyConfig.getPolicyName().substring(policyConfig.getPolicyName().indexOf("_BRMS_")+6, policyConfig.getPolicyName().length()); + name= name.substring(name.indexOf("_")+1,name.length()); + logger.info("Policy Retrieved with this Name notified: " + name); + bRMSPush.addRule(name,policyConfig.toOther(),policyConfig.getResponseAttributes()); + }else{ + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR +"Fail to retrieve policy so rule will not be pushed to PolicyRepo !!!!\n\n"); + } + } + } + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW+"Rertriving policy failed " + e.getMessage()); + } + } + } + bRMSPush.pushRules(); + } + } +} diff --git a/BRMSGateway/src/main/java/org/openecomp/policy/brmsInterface/BRMSPush.java b/BRMSGateway/src/main/java/org/openecomp/policy/brmsInterface/BRMSPush.java new file mode 100644 index 000000000..3ea8d624d --- /dev/null +++ b/BRMSGateway/src/main/java/org/openecomp/policy/brmsInterface/BRMSPush.java @@ -0,0 +1,627 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.brmsInterface; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.Writer; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.security.GeneralSecurityException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Set; +import java.util.UUID; + +import org.apache.commons.io.FileUtils; +import org.apache.commons.lang.StringEscapeUtils; +import org.apache.maven.model.Dependency; +import org.apache.maven.model.DeploymentRepository; +import org.apache.maven.model.DistributionManagement; +import org.apache.maven.model.Exclusion; +import org.apache.maven.model.Model; +import org.apache.maven.model.io.xpp3.MavenXpp3Writer; +import org.apache.maven.shared.invoker.DefaultInvocationRequest; +import org.apache.maven.shared.invoker.DefaultInvoker; +import org.apache.maven.shared.invoker.InvocationRequest; +import org.apache.maven.shared.invoker.InvocationResult; +import org.apache.maven.shared.invoker.Invoker; +import org.codehaus.plexus.util.IOUtil; +import org.codehaus.plexus.util.WriterFactory; +import org.openecomp.policy.utils.BackUpHandler; +import org.openecomp.policy.utils.BackUpMonitor; +import org.openecomp.policy.utils.PolicyUtils; +import org.sonatype.nexus.client.NexusClient; +import org.sonatype.nexus.client.NexusClientException; +import org.sonatype.nexus.client.NexusConnectionException; +import org.sonatype.nexus.client.rest.NexusRestClient; +import org.sonatype.nexus.rest.model.NexusArtifact; + +//import org.apache.log4j.Logger; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; +import org.openecomp.policy.common.im.AdministrativeStateException; +import org.openecomp.policy.common.im.IntegrityMonitor; +import com.att.nsa.cambria.client.CambriaBatchingPublisher; +import com.att.nsa.cambria.client.CambriaClientBuilders; +import com.att.nsa.cambria.client.CambriaClientBuilders.PublisherBuilder; +import com.fasterxml.jackson.core.JsonProcessingException; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + + +/** + * BRMSPush: Application responsible to push policies to the BRMS PDP Policy Repository (PR). + * Mavenize and push policy to PR + * + * @version 0.4 + */ +@SuppressWarnings("deprecation") +public class BRMSPush { + + + private static final Logger logger = FlexLogger.getLogger(BRMSPush.class.getName()); + private static final String projectsLocation = "RuleProjects"; + private static final String goals[] = {"clean", "deploy"}; + + private static Map modifiedGroups = new HashMap(); + private static IntegrityMonitor im; + private static BackUpMonitor bm; + private static String resourceName = null; + private List groupIDs = null; + private List artifactIDs= null; //"test" + private Map names= null; // "Rules" + private String defaultName = null; + private String repID = null; // "ecomp_policy-3rd-party" + private String repName = null; // "d2policy-snapshots" + private String repURL= null; + private String repUserName = null; + private ArrayList controllers; + private HashMap versions = new HashMap(); + private String repPassword = null; + private String policyKeyID = null; + private List matchingList = null; + private boolean createFlag = false; + private String uebList = null; + private String pubTopic = null; + private PublisherBuilder pubBuilder = null; + private Long uebDelay = Long.parseLong("5000"); + private static String brmsdependencyversion = null; + + public BRMSPush(String propertiesFile, BackUpHandler handler) throws Exception{ + Properties config = new Properties(); + Path file = Paths.get(propertiesFile); + if(Files.notExists(file)){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE+"Config File doesn't Exist in the specified Path " + file.toString()); + throw new Exception(XACMLErrorConstants.ERROR_DATA_ISSUE+"Config File doesn't Exist in the specified Path " + file.toString()); + }else{ + if(file.toString().endsWith(".properties")){ + InputStream in; + in = new FileInputStream(file.toFile()); + config.load(in); + // Grab the Properties. + defaultName = config.getProperty("defaultName").replaceAll(" ", ""); + if(defaultName==null){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "defaultName property is missing from the property file "); + throw new Exception(XACMLErrorConstants.ERROR_DATA_ISSUE + "defaultName property is missing from the property file"); + } + repID = config.getProperty("repositoryID").replaceAll(" ", ""); + if(repID==null){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "repositoryID property is missing from the property file "); + throw new Exception(XACMLErrorConstants.ERROR_DATA_ISSUE + "repositoryID property is missing from the property file "); + } + repName = config.getProperty("repositoryName").replaceAll(" ", ""); + if(repName==null){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "repositoryName property is missing from the property file "); + throw new Exception(XACMLErrorConstants.ERROR_DATA_ISSUE + "repositoryName property is missing from the property file "); + } + repURL = config.getProperty("repositoryURL").replaceAll(" ", ""); + if(repURL==null){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "repositoryURL property is missing from the property file "); + throw new Exception(XACMLErrorConstants.ERROR_DATA_ISSUE + "repositoryURL property is missing from the property file "); + } + repUserName = config.getProperty("repositoryUsername").trim(); + repPassword = config.getProperty("repositoryPassword").trim(); + if(repUserName==null || repPassword==null){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "repostoryUserName and respositoryPassword properties are required."); + throw new Exception(XACMLErrorConstants.ERROR_DATA_ISSUE + "repostoryUserName and respositoryPassword properties are required."); + } + policyKeyID = config.getProperty("policyKeyID").replaceAll(" ", ""); + if(policyKeyID==null){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "policyKeyID property is missing from the property file "); + throw new Exception(XACMLErrorConstants.ERROR_DATA_ISSUE + "policyKeyID property is missing from the property file "); + } + brmsdependencyversion = config.getProperty("brms.dependency.version").replaceAll(" ", ""); + if(brmsdependencyversion==null){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "brmsdependencyversion property is missing from the property file "); + throw new Exception(XACMLErrorConstants.ERROR_DATA_ISSUE + "brmsdependencyversion property is missing from the property file "); + } + readGroups(config); + logger.info("Trying to set up IntegrityMonitor"); + try { + logger.info("Trying to set up IntegrityMonitor"); + resourceName = config.getProperty("RESOURCE_NAME").replaceAll(" ", "");; + if(resourceName==null){ + logger.warn("RESOURCE_NAME is missing setting default value. "); + resourceName = "brmsgw_pdp01"; + } + im = IntegrityMonitor.getInstance(resourceName, config); + } catch (Exception e) { + logger.error("Error starting Integerity Monitor: " + e); + } + logger.info("Trying to set up BackUpMonitor"); + try { + bm = BackUpMonitor.getInstance(BackUpMonitor.ResourceNode.BRMS.toString(), resourceName, config, handler); + } catch (Exception e) { + logger.error("Error starting BackUpMonitor: " + e); + } + // Setting up the Publisher for UEB + uebList = config.getProperty("UEB_URL").trim(); + pubTopic = config.getProperty("UEB_TOPIC").trim(); + String apiKey = config.getProperty("UEB_API_KEY"); + String apiSecret = config.getProperty("UEB_API_SECRET"); + if(uebList==null || pubTopic==null){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "UEB properties are missing from the property file "); + throw new Exception(XACMLErrorConstants.ERROR_DATA_ISSUE + "UEB properties are missing from the property file "); + } + pubBuilder = new CambriaClientBuilders.PublisherBuilder(); + pubBuilder.usingHosts(uebList) + .onTopic(pubTopic); + if(apiKey!=null && !apiKey.isEmpty() && + apiSecret!=null && !apiSecret.isEmpty()) { + apiKey= apiKey.trim(); + apiSecret = apiSecret.trim(); + pubBuilder.authenticatedBy(apiKey, apiSecret); + } + String uDelay = config.getProperty("UEB_DELAY"); + if(uDelay!=null && !uDelay.isEmpty()){ + uDelay = uDelay.trim(); + try{ + uebDelay = Long.parseLong(uDelay); + }catch (NumberFormatException e){ + logger.error("UEB_DELAY not a long format number" + e); + } + } + } + } + } + + /** + * Will Initialize the variables required for BRMSPush. + */ + public void initiate() { + modifiedGroups = new HashMap(); + controllers = new ArrayList(); + try { + bm.updateNotification(); + } catch (Exception e) { + logger.error("Error while updating Notification: " + e.getMessage()); + } + } + + /** + * Will Add rules to projects. Creates necessary folders if required. + */ + public void addRule(String name, String rule, Map responseAttributes) { + // 1 check the response Attributes and determine if this belongs to any projects. + // 2 if not create folder // new File("Projects\\test").mkdirs(); + // 3 create pom. + // 4 copy the rule. + // 5 store the groups that have been updated. + String kSessionName=null; + String selectedName = null; + + if(!responseAttributes.isEmpty()){ + // Pick selected Value + for(String key: responseAttributes.keySet()){ + if(key.equals(policyKeyID)){ + selectedName = responseAttributes.get(key); + } + //kmodule configurations + else if (key.equals("kSessionName")){ + kSessionName=responseAttributes.get(key); + } + } + + } + // If no Match then pick Default. + if(selectedName==null){ + selectedName = defaultName; + } + if(names.containsKey(selectedName)){ + //If the key is not got as parameters set by the user, setting the default value for kSessionName as closedLoop + if(kSessionName==null){ + if(selectedName==defaultName){ + kSessionName="closedloop"; + }else{ + kSessionName= selectedName; + } + } + // create directories if missing. + createProject(projectsLocation+File.separator+getArtifactID(selectedName)+File.separator+"src"+File.separator+"main"+File.separator+"resources",kSessionName); + copyDataToFile(projectsLocation+File.separator+getArtifactID(selectedName)+File.separator+"src"+File.separator+"main"+File.separator+"resources"+File.separator+"rules"+File.separator+name+".drl", rule); + addModifiedGroup(selectedName, "update"); // Will check for Create Later after generating the Pom. + } + } + + /** + * Will Push policies to the PolicyRepo. + * + * @param notificationType type of notification Type. + */ + public void pushRules(){ + // Check how many groups have been updated. + // Invoke their Maven process. + try { + im.startTransaction(); + } catch (AdministrativeStateException e) { + logger.error("Error while starting Transaction " + e); + } catch (Exception e) { + logger.error("Error while starting Transaction " + e); + } + if(!modifiedGroups.isEmpty()){ + Boolean flag = false; + for(String group: modifiedGroups.keySet()){ + try{ + InvocationRequest request = new DefaultInvocationRequest(); + createPom(group); + request.setPomFile(new File(projectsLocation+File.separator+getArtifactID(group)+File.separator+"pom.xml")); + request.setGoals(Arrays.asList(goals)); + Invoker invoker = new DefaultInvoker(); + InvocationResult result = invoker.execute(request); + if(result.getExecutionException()!=null){ + logger.error(result.getExecutionException()); + }else if(result.getExitCode()!=0){ + logger.error("Maven Invocation failure..!"); + } + if(result.getExitCode()==0){ + logger.info("Build Completed..!"); + if (createFlag) { + addNotification(group, "create"); + }else{ + addNotification(group, modifiedGroups.get(group)); + } + flag = true; + } + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW+"Maven Invocation issue for "+getArtifactID(group) + e.getMessage()); + } + } + if(flag){ + sendNotification(controllers); + } + } + im.endTransaction(); + } + + /** + * Removes a Rule from Rule Projects. + */ + public void removeRule(String name){ + File file = new File(projectsLocation); + matchingList = new ArrayList(); + searchFile(file,name); + for(File matchingFile: matchingList){ + if(matchingFile.delete()){ + logger.info("Deleted File.. " + matchingFile.getAbsolutePath()); + String groupName = getName(matchingFile.toString()); + String ruleFolder= projectsLocation+File.separator+getArtifactID(groupName)+File.separator+"src"+File.separator+"main"+File.separator+"resources"+File.separator+"rules"; + if(new File(ruleFolder).listFiles().length==0){ + removedRuleModifiedGroup(groupName); + }else{ + addModifiedGroup(groupName, "update"); // This is an update in terms of PDPD. + } + } + } + } + + private void addModifiedGroup(String controllerName, String operation) { + modifiedGroups.put(controllerName, operation); + } + + private void addNotification(String controllerName, String operation) { + ControllerPOJO controllerPOJO = new ControllerPOJO(); + controllerPOJO.setName(controllerName); + controllerPOJO.setOperation(operation); + HashMap drools = new HashMap(); + drools.put("groupId", getGroupID(controllerName)); + drools.put("artifactId", getArtifactID(controllerName)); + drools.put("version", versions.get(controllerName)); + controllerPOJO.setDrools(drools); + controllers.add(controllerPOJO); + try { + logger.debug("Notification added: " + + PolicyUtils.objectToJsonString(controllerPOJO)); + } catch (JsonProcessingException e) { + logger.error(XACMLErrorConstants.ERROR_SCHEMA_INVALID + + "Json Processing Error " + e); + } + } + + private void removedRuleModifiedGroup(String controllerName){ + // This will be sending Notification to PDPD directly to Lock + ControllerPOJO controllerPOJO = new ControllerPOJO(); + controllerPOJO.setName(controllerName); + controllerPOJO.setOperation("lock"); + List controllers = new ArrayList(); + controllers.add(controllerPOJO); + sendNotification(controllers); + } + + private void sendNotification(List controllers){ + NotificationPOJO notification = new NotificationPOJO(); + String requestId = UUID.randomUUID().toString(); + logger.info("Generating notification RequestID : " + requestId); + notification.setRequestID(requestId); + notification.setEntity("controller"); + notification.setControllers(controllers); + try { + String notificationJson = PolicyUtils.objectToJsonString(notification); + logger.info("Sending Notification :\n" + notificationJson); + sendMessage(notificationJson); + } catch (IOException | GeneralSecurityException | InterruptedException e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error while sending notification to PDP-D " + e.getMessage()); + } + } + + private void sendMessage(String message) throws IOException, GeneralSecurityException, InterruptedException { + // Sending Message through UEB interface. + CambriaBatchingPublisher pub = pubBuilder.build(); + pub.send( "MyPartitionKey", message); + logger.debug("Message Published on UEB :" + uebList + "for Topic: " + pubTopic); + Thread.sleep(uebDelay); + pub.close(); + } + + private void searchFile(File file, String name) { + if(file.isDirectory()){ + logger.info("Searching Directory..." + file.getAbsolutePath()); + if(file.canRead()){ + for(File temp: file.listFiles()){ + if(temp.isDirectory()){ + // Recursive search. + searchFile(temp, name); + }else{ + if(temp.getName().equals(name+".drl")){ + matchingList.add(temp); + } + } + } + } + } + } + + private void createPom(String name){ + Model model = new Model(); + model.setModelVersion("4.0.0"); + model.setGroupId(getGroupID(name)); + model.setArtifactId(getArtifactID(name)); + model.setVersion(incrementVersion(name)); + model.setName(name); + DistributionManagement distributionManagement = new DistributionManagement(); + DeploymentRepository repository = new DeploymentRepository(); + repository.setId(repID); + repository.setName(repName); + repository.setUrl(repURL); + distributionManagement.setRepository(repository); + model.setDistributionManagement(distributionManagement); + // Depenendency Mangement goes here. + List dependencyList= new ArrayList(); + + String version= StringEscapeUtils.escapeJava(brmsdependencyversion); + + Dependency demoDependency = new Dependency(); + demoDependency.setGroupId("org.openecomp.policy.drools-applications"); + demoDependency.setArtifactId("demo"); + demoDependency.setVersion(version); + dependencyList.add(demoDependency); + + Dependency controlloopDependency = new Dependency(); + controlloopDependency.setGroupId("org.openecomp.policy.drools-applications"); + controlloopDependency.setArtifactId("controlloop"); + controlloopDependency.setVersion(version); + dependencyList.add(controlloopDependency); + + Dependency restDependency = new Dependency(); + restDependency.setGroupId("org.openecomp.policy.drools-applications"); + restDependency.setArtifactId("rest"); + restDependency.setVersion(version); + dependencyList.add(restDependency); + + Dependency appcDependency = new Dependency(); + appcDependency.setGroupId("org.openecomp.policy.drools-applications"); + appcDependency.setArtifactId("appc"); + appcDependency.setVersion(version); + dependencyList.add(appcDependency); + + Dependency aaiDependency = new Dependency(); + aaiDependency.setGroupId("org.openecomp.policy.drools-applications"); + aaiDependency.setArtifactId("aai"); + aaiDependency.setVersion(version); + dependencyList.add(aaiDependency); + + Dependency msoDependency = new Dependency(); + msoDependency.setGroupId("org.openecomp.policy.drools-applications"); + msoDependency.setArtifactId("mso"); + msoDependency.setVersion(version); + dependencyList.add(msoDependency); + + Dependency trafficgeneratorDependency = new Dependency(); + trafficgeneratorDependency.setGroupId("org.openecomp.policy.drools-applications"); + trafficgeneratorDependency.setArtifactId("trafficgenerator"); + trafficgeneratorDependency.setVersion(version); + dependencyList.add(trafficgeneratorDependency); + + + model.setDependencies(dependencyList); + + Writer writer = null; + try{ + writer = WriterFactory.newXmlWriter(new File(projectsLocation+File.separator+getArtifactID(name)+File.separator+"pom.xml")); + MavenXpp3Writer pomWriter = new MavenXpp3Writer(); + pomWriter.write(writer, model); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW+"Error while creating POM for " + getArtifactID(name) + e.getMessage()); + }finally{ + IOUtil.close(writer); + } + } + + private void createProject(String path,String ksessionName){ + new File(path+File.separator+"rules").mkdirs(); + new File(path+File.separator+"META-INF").mkdirs(); + if(!Files.exists(Paths.get(path+File.separator+"META-INF"+File.separator+"kmodule.xml"))){ + // Hard coding XML for PDP Drools to accept our Rules. + String xml = "" + "\n"+ + "" +"\n"+ + "" + "\n" + + ""+ "\n" + + ""; + copyDataToFile(path+File.separator+"META-INF"+File.separator+"kmodule.xml", xml); + } + } + + private void copyDataToFile(String file, String rule) { + try{ + FileUtils.writeStringToFile(new File(file), rule); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW+"Error while creating Rule for " + file + e.getMessage()); + } + } + + private void readGroups(Properties config) throws Exception{ + String[] groupNames = null; + if(config.getProperty("groupNames").contains(",")){ + groupNames = config.getProperty("groupNames").replaceAll(" ", "").split(","); + }else{ + groupNames = new String[]{config.getProperty("groupNames").replaceAll(" ", "")}; + } + if(groupNames==null || groupNames.length==0){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "groupNames property is missing or empty from the property file "); + throw new Exception(XACMLErrorConstants.ERROR_DATA_ISSUE + "groupNames property is missing or empty from the property file "); + } + names = new HashMap(); + groupIDs = new ArrayList(); + artifactIDs = new ArrayList(); + for(int counter=0; counter < groupNames.length ;counter++){ + String name = groupNames[counter]; + String groupID = config.getProperty(name+".groupID"); + if(groupID==null){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + name+".groupID property is missing from the property file "); + throw new Exception(XACMLErrorConstants.ERROR_DATA_ISSUE + name+".groupID property is missing from the property file "); + } + String artifactID = config.getProperty(name+".artifactID"); + if(artifactID==null){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + name+".artifactID property is missing from the property file "); + throw new Exception(XACMLErrorConstants.ERROR_DATA_ISSUE + name+".artifactID property is missing from the property file "); + } + // Add to list if we got all + names.put(name, counter); + groupIDs.add(groupID); + artifactIDs.add(artifactID); + } + } + + private String getGroupID(String name){ + return groupIDs.get(names.get(name)); + } + + private String getArtifactID(String name){ + return artifactIDs.get(names.get(name)); + } + + private String getName(String filePath){ + filePath = filePath.replaceFirst(projectsLocation, "").substring(1); + String artifactName = filePath.substring(0, filePath.indexOf(File.separator)); + for(String name : names.keySet()){ + if(artifactName.equals(getArtifactID(name))){ + return name; + } + } + // If not found return default + return defaultName; + } + + private String incrementVersion(String name) { + final NexusClient client = new NexusRestClient(); + String newVersion = "0.1.0"; + createFlag = false; + try { + client.connect(repURL.substring(0, repURL.indexOf(repURL.split(":[0-9]+\\/nexus")[1])), repUserName, repPassword); + final NexusArtifact template = new NexusArtifact(); + template.setGroupId(getGroupID(name)); + template.setArtifactId(getArtifactID(name)); + final List artifacts = client.searchByGAV(template); + int bigMajor = 0; + int bigMinor = 0; + for(NexusArtifact artifact : artifacts){ + String version = artifact.getVersion(); + int majorVal = Integer.parseInt(version.substring(0, version.indexOf("."))); + int minorVal = Integer.parseInt(version.substring(version.indexOf(".")+1,version.lastIndexOf("."))); + if(majorVal > bigMajor){ + bigMajor = majorVal; + bigMinor = minorVal; + }else if((bigMajor==majorVal) && (minorVal > bigMinor)){ + bigMinor = minorVal; + } + } + if(bigMinor>=9){ + bigMajor = bigMajor+1; + bigMinor = 0; + }else{ + bigMinor = bigMinor+1; + } + if(artifacts.isEmpty()){ + // This is new artifact. + newVersion = "0.1.0"; + }else{ + newVersion = bigMajor + "." + bigMinor + artifacts.get(0).getVersion().substring(artifacts.get(0).getVersion().lastIndexOf(".")); + } + } catch (NexusClientException | NexusConnectionException | NullPointerException e) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "version number increment failed will be using default version " +e.getMessage()); + } finally { + try { + client.disconnect(); + } catch (NexusClientException | NexusConnectionException e) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "failed to disconnect Connection from Nexus." +e.getMessage()); + } + } + if(newVersion.equals("0.1.0")){ + createFlag = true; + } + versions.put(name, newVersion); + logger.info("Controller: " + name + "is on version: "+ newVersion); + return newVersion; + } + + // Return BackUpMonitor + public static BackUpMonitor getBackUpMonitor(){ + return bm; + } +} diff --git a/BRMSGateway/src/main/java/org/openecomp/policy/brmsInterface/ControllerPOJO.java b/BRMSGateway/src/main/java/org/openecomp/policy/brmsInterface/ControllerPOJO.java new file mode 100644 index 000000000..546925bdf --- /dev/null +++ b/BRMSGateway/src/main/java/org/openecomp/policy/brmsInterface/ControllerPOJO.java @@ -0,0 +1,52 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.brmsInterface; + +import java.util.Map; + +/** + * POJO for controller information. + * + */ +public class ControllerPOJO { + private String name; + private Map drools; + private String operation; + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + public Map getDrools() { + return drools; + } + public void setDrools(Map drools) { + this.drools = drools; + } + public String getOperation() { + return operation; + } + public void setOperation(String operation) { + this.operation = operation; + } +} + diff --git a/BRMSGateway/src/main/java/org/openecomp/policy/brmsInterface/NotificationPOJO.java b/BRMSGateway/src/main/java/org/openecomp/policy/brmsInterface/NotificationPOJO.java new file mode 100644 index 000000000..116a7b41f --- /dev/null +++ b/BRMSGateway/src/main/java/org/openecomp/policy/brmsInterface/NotificationPOJO.java @@ -0,0 +1,52 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.brmsInterface; + +import java.util.List; + +/** + * This POJO will be transformed to JSON for Notification Purposes. + * + */ +public class NotificationPOJO { + private String requestID; + private String entity; + private List controllers; + public String getRequestID() { + return requestID; + } + public void setRequestID(String requestID) { + this.requestID = requestID; + } + public String getEntity() { + return entity; + } + public void setEntity(String entity) { + this.entity = entity; + } + public List getControllers() { + return controllers; + } + public void setControllers(List controllers) { + this.controllers = controllers; + } + +} diff --git a/BRMSGateway/src/main/resources/log4j.properties b/BRMSGateway/src/main/resources/log4j.properties new file mode 100644 index 000000000..71f359644 --- /dev/null +++ b/BRMSGateway/src/main/resources/log4j.properties @@ -0,0 +1,48 @@ +### +# ============LICENSE_START======================================================= +# ECOMP Policy Engine +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +# +# Use this properties for debugging and development. +# +# +# Set root logger level to DEBUG and its only appender to A1. +log4j.rootLogger=INFO, FILE + +# A1 is set to be a DailyRollingFileAppender. +log4j.appender.FILE=org.apache.log4j.DailyRollingFileAppender + +# Set the name of the file +log4j.appender.FILE.File=BRMSLog.log + +# Set the immediate flush to true (default) +log4j.appender.FILE.ImmediateFlush=true + +# Set the threshold to debug mode +log4j.appender.FILE.Threshold=debug + +# Set the append to false, should not overwrite +log4j.appender.FILE.Append=true + +# Set the DatePattern +log4j.appender.FILE.DatePattern='.'yyyy-MM-dd + +# A1 uses PatternLayout. +log4j.appender.FILE.layout=org.apache.log4j.PatternLayout +log4j.appender.FILE.layout.ConversionPattern=%d{yyyy_MM_dd_HH_mm_ss_SSS} [%t] %-5p %l- %m%n diff --git a/BRMSGateway/src/main/resources/logback.xml b/BRMSGateway/src/main/resources/logback.xml new file mode 100644 index 000000000..af6dd3353 --- /dev/null +++ b/BRMSGateway/src/main/resources/logback.xml @@ -0,0 +1,252 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --> + + + + + + + + + + + + + + + + + + + + ${defaultPattern} + + + + + + + + + + + + + ${logDirectory}/${auditLogName}.log + + ${logDirectory}/${auditLogName}.%i.log.zip + + 1 + 9 + + + 5MB + + + ${defaultAuditPattern} + + + + + 256 + + + + + + + + ${logDirectory}/${metricsLogName}.log + + ${logDirectory}/${metricsLogName}.%i.log.zip + + 1 + 9 + + + 5MB + + + + ${defaultMetricPattern} + + + + + 256 + + + + + + + + ${logDirectory}/${errorLogName}.log + + ${logDirectory}/${errorLogName}.%i.log.zip + + 1 + 9 + + + ERROR + + + 5MB + + + ${defaultErrorPattern} + + + + + 256 + + + + + + + ${debugLogDirectory}/${debugLogName}.log + + ${debugLogDirectory}/${debugLogName}.%i.log.zip + + 1 + 9 + + + INFO + + + 5MB + + + ${debugLoggerPattern} + + + + + 256 + + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ECOMP-PAP-REST/.gitignore b/ECOMP-PAP-REST/.gitignore new file mode 100644 index 000000000..8567d5825 --- /dev/null +++ b/ECOMP-PAP-REST/.gitignore @@ -0,0 +1,4 @@ +/build/ +/target/ +/target/ +/target/ diff --git a/ECOMP-PAP-REST/WebContent/META-INF/MANIFEST.MF b/ECOMP-PAP-REST/WebContent/META-INF/MANIFEST.MF new file mode 100644 index 000000000..59499bce4 --- /dev/null +++ b/ECOMP-PAP-REST/WebContent/META-INF/MANIFEST.MF @@ -0,0 +1,2 @@ +Manifest-Version: 1.0 + diff --git a/ECOMP-PAP-REST/WebContent/README.txt b/ECOMP-PAP-REST/WebContent/README.txt new file mode 100644 index 000000000..e69de29bb diff --git a/ECOMP-PAP-REST/autopush.properties b/ECOMP-PAP-REST/autopush.properties new file mode 100644 index 000000000..481c33c56 --- /dev/null +++ b/ECOMP-PAP-REST/autopush.properties @@ -0,0 +1,22 @@ +### +# ============LICENSE_START======================================================= +# ECOMP-PAP-REST +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +default.policyType= +default.policyScope= diff --git a/ECOMP-PAP-REST/dictionaryItemsAPI.json b/ECOMP-PAP-REST/dictionaryItemsAPI.json new file mode 100644 index 000000000..4a4219700 --- /dev/null +++ b/ECOMP-PAP-REST/dictionaryItemsAPI.json @@ -0,0 +1,52 @@ +{ + "dictionary": [{ + "type": "commmon", + "dictionaries": [{ + "name": "attribute", + "table": "Attribute", + "fields": [{ + "name": "xacmlId" + }, { + "name": "description" + }, { + "name": "categoryBean" + }, { + "name": "datatypeBean" + }, { + "name": "priority" + }, { + "name": "attributeValue" + }] + }, { + "name": "ecompname", + "table": "EcompName", + "fields": [{ + "name": "ecompName" + }, { + "name": "description" + }] + }] + }, { + "type": "action", + "dictionaries": [{ + "name": "action", + "table": "ActionPolicyDict", + "fields": [{ + "name": "type" + }, { + "name": "url" + }, { + "name": "method" + }, { + "name": "header" + }, { + "name": "body" + }, { + "name": "attributeName" + }, { + "name": "description" + }] + }] + }] + +} diff --git a/ECOMP-PAP-REST/policyLogger.properties b/ECOMP-PAP-REST/policyLogger.properties new file mode 100644 index 000000000..a597a7a22 --- /dev/null +++ b/ECOMP-PAP-REST/policyLogger.properties @@ -0,0 +1,44 @@ +### +# ============LICENSE_START======================================================= +# ECOMP-PAP-REST +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +################################### Set concurrentHashMap and timer info ####################### +#Timer initial delay and the delay between in milliseconds before task is to be execute. +timer.delay.time=1000 +#Timer scheduleAtFixedRate period - time in milliseconds between successive task executions. +check.interval= 30000 +#Longest time an event info can be stored in the concurrentHashMap for logging - in seconds. +event.expired.time=86400 +#Size of the concurrentHashMap which stores the event starting time, etc - when its size reaches this limit, the Timer gets executed +#to remove all expired records from this concurrentHashMap. +concurrentHashMap.limit=5000 +#Size of the concurrentHashMap - when its size drops to this point, stop the Timer +stop.check.point=2500 +################################### Set logging format ############################################# +# set EELF for EELF logging format, set LOG4J for using log4j, set SYSTEMOUT for using system.out.println +logger.type=EELF +#################################### Set level for EELF or SYSTEMOUT logging ################################## +# Set level for debug file. Set DEBUG to enable .info, .warn and .debug; set INFO for enable .info and .warn; set OFF to disable all +debugLogger.level=INFO +# Set level for metrics file. Set OFF to disable; set ON to enable +metricsLogger.level=ON +# Set level for error file. Set OFF to disable; set ON to enable +error.level=ON +# Set level for audit file. Set OFF to disable; set ON to enable +audit.level=ON diff --git a/ECOMP-PAP-REST/pom.xml b/ECOMP-PAP-REST/pom.xml new file mode 100644 index 000000000..b3d406692 --- /dev/null +++ b/ECOMP-PAP-REST/pom.xml @@ -0,0 +1,259 @@ + + + + + + + 4.0.0 + org.openecomp.policy.engine + ECOMP-PAP-REST + ECOMP-PAP-REST + war + + org.openecomp.policy.engine + PolicyEngineSuite + 1.0.0-SNAPSHOT + + + + + maven-war-plugin + 2.1 + + true + + + src/main/java/ + WEB-INF/classes/ + + hibernate.cfg.xml + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.2 + + 1.8 + 1.8 + + + + + + + + org.openecomp.policy.engine + PolicyEngineUtils + ${project.version} + + + org.apache.commons + commons-lang3 + 3.4 + + + org.openecomp.policy.engine + ECOMP-PDP + ${project.version} + + + org.openecomp.policy.common + ECOMP-Logging + ${common-modules.version} + + + javax.servlet + javax.servlet-api + 3.1.0 + + + commons-logging + commons-logging + 1.1.3 + + + javax.servlet + servlet-api + + + + + org.apache.commons + commons-compress + 1.8 + + + commons-fileupload + commons-fileupload + 1.3.1 + + + log4j + apache-log4j-extras + 1.2.17 + + + commons-io + commons-io + 2.4 + + + io.netty + netty + 3.5.0.Final + + + com.google.guava + guava + 14.0.1 + + + com.fasterxml.jackson.core + jackson-databind + 2.3.0-rc1 + + + org.json + json + [20090211,) + + + org.eclipse.jgit + org.eclipse.jgit + 3.2.0.201312181205-r + + + junit + junit + 4.11 + test + + + org.apache.tomcat + tomcat-jdbc + 8.0.24 + + + com.h2database + h2 + [1.4.186,) + + + com.github.fge + json-patch + 1.9 + + + org.eclipse.persistence + javax.persistence + 2.1.0 + + + org.eclipse.persistence + eclipselink + 2.6.0 + + + + mysql + mysql-connector-java + 5.1.30 + + + org.mariadb.jdbc + mariadb-java-client + 1.2.3 + + + org.mockito + mockito-core + 1.9.5 + + + javax.servlet + javax.servlet-api + 3.0.1 + provided + + + org.springframework + spring-mock + 2.0.8 + + + com.mockrunner + mockrunner + 0.3.1 + + + + org.springframework + spring-core + ${springframework.version} + + + org.springframework + spring-web + ${springframework.version} + + + org.springframework + spring-webmvc + ${springframework.version} + + + org.springframework + spring-tx + ${springframework.version} + + + org.springframework + spring-context-support + ${springframework.version} + + + org.springframework + spring-orm + ${springframework.version} + + + + org.hibernate + hibernate-core + ${hibernate.version} + + + org.hibernate + hibernate-validator + 5.1.3.Final + + + + 4.2.0.RELEASE + 4.3.11.Final + 2.0.2 + + diff --git a/ECOMP-PAP-REST/src/main/java/hibernate.cfg.xml b/ECOMP-PAP-REST/src/main/java/hibernate.cfg.xml new file mode 100644 index 000000000..33f5177d2 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/hibernate.cfg.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/HibernateSession.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/HibernateSession.java new file mode 100644 index 000000000..17babfa2e --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/HibernateSession.java @@ -0,0 +1,60 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest; + +import org.hibernate.HibernateException; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.cfg.Configuration; + + +public class HibernateSession{ + private static SessionFactory xacmlsessionFactory; + + + static { + try { + Configuration configuration= new Configuration(); + configuration.setProperty("hibernate.connection.url", XACMLPapServlet.papDbUrl); + configuration.setProperty("hibernate.connection.username", XACMLPapServlet.papDbUser); + configuration.setProperty("hibernate.connection.password", XACMLPapServlet.papDbPassword); + configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect"); + configuration.setProperty("hibernate.connection.driver_class", XACMLPapServlet.papDbDriver); + configuration.setProperty("hibernate.show_sql", "false"); + configuration.setProperty("hibernate.connection.autocommit", "true"); + configuration.setProperty("hibernate.c3p0.min_size", "5"); + configuration.setProperty("hibernate.c3p0.max_size", "200"); + configuration.setProperty("hibernate.c3p0.timeout", "3600"); + configuration.setProperty("hibernate.c3p0.idle_test_period", "3600"); + + StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()); + xacmlsessionFactory = configuration.configure("/hibernate.cfg.xml").buildSessionFactory(builder.build()); + + } catch (Throwable ex) { + throw new ExceptionInInitializerError(ex); + } + } + public static Session getSessionFactory() throws HibernateException { + return xacmlsessionFactory.openSession(); + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/WebConfig.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/WebConfig.java new file mode 100644 index 000000000..b84049c87 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/WebConfig.java @@ -0,0 +1,80 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.util.Base64; +import java.util.Properties; + +import javax.servlet.ServletContext; +import javax.servlet.ServletRegistration; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.web.WebApplicationInitializer; +import org.springframework.web.context.support.XmlWebApplicationContext; +import org.springframework.web.servlet.DispatcherServlet; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + + +public class WebConfig implements WebApplicationInitializer { + + private static final Log logger = LogFactory.getLog(WebConfig.class); + + @Override + public void onStartup(ServletContext container) { + + //need to get properties for userid and password on the pap to get authorization string used in URI Mapping + Properties prop = new Properties(); + String propFileName = "xacml.pap.properties"; + + try { + InputStream is = new FileInputStream(propFileName); + prop.load(is); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "property file '" + propFileName + "' not found in the classpath"); + } + + String papID = prop.getProperty("xacml.rest.pap.userid"); + String papPass = prop.getProperty("xacml.rest.pap.password"); + + String usernameAndPassword = papID+":"+papPass; + String authorizationString = Base64.getEncoder().encodeToString(usernameAndPassword.getBytes()); + + + XmlWebApplicationContext appContext = new XmlWebApplicationContext(); + appContext.setConfigLocation("classpath:spring.xml"); + + System.out.println("Spring XML File Location: " + appContext.getConfigLocations()); + logger.info("Spring XML File Location: " + appContext.getConfigLocations()); + + ServletRegistration.Dynamic dispatcher = + container.addServlet("dispatcher", new DispatcherServlet(appContext)); + dispatcher.setLoadOnStartup(1); + dispatcher.addMapping("/@Auth@"+authorizationString+"/ecomp/*"); + } + + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/XACMLPapServlet.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/XACMLPapServlet.java new file mode 100644 index 000000000..efc707085 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/XACMLPapServlet.java @@ -0,0 +1,4858 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.UnsupportedEncodingException; +import java.io.Writer; +import java.net.ConnectException; +import java.net.HttpURLConnection; +import java.net.InetAddress; +import java.net.MalformedURLException; +import java.net.SocketTimeoutException; +import java.net.URI; +import java.net.URL; +import java.net.URLDecoder; +import java.net.UnknownHostException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Set; +import java.util.UUID; +import java.util.concurrent.CopyOnWriteArrayList; + +import javax.persistence.EntityManager; +import javax.persistence.Persistence; +import javax.persistence.Query; +import javax.persistence.EntityManagerFactory; +import javax.servlet.Servlet; +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebInitParam; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + +import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicySetType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType; + +import org.apache.commons.io.FilenameUtils; +import org.apache.commons.io.IOUtils; +import org.openecomp.policy.pap.xacml.rest.adapters.PolicyRestAdapter; +import org.openecomp.policy.pap.xacml.rest.components.ActionPolicy; +import org.openecomp.policy.pap.xacml.rest.components.AutoPushPolicy; +import org.openecomp.policy.pap.xacml.rest.components.ClosedLoopPolicy; +import org.openecomp.policy.pap.xacml.rest.components.ConfigPolicy; +import org.openecomp.policy.pap.xacml.rest.components.CreateBrmsParamPolicy; +import org.openecomp.policy.pap.xacml.rest.components.CreateBrmsRawPolicy; +import org.openecomp.policy.pap.xacml.rest.components.CreateClosedLoopPerformanceMetrics; +import org.openecomp.policy.pap.xacml.rest.components.CreateNewMicroSerivceModel; +import org.openecomp.policy.pap.xacml.rest.components.DecisionPolicy; +import org.openecomp.policy.pap.xacml.rest.components.FirewallConfigPolicy; +import org.openecomp.policy.pap.xacml.rest.components.MicroServiceConfigPolicy; +import org.openecomp.policy.pap.xacml.rest.components.Policy; +import org.openecomp.policy.pap.xacml.rest.components.PolicyDBDao; +import org.openecomp.policy.pap.xacml.rest.components.PolicyDBDaoTransaction; +import org.openecomp.policy.pap.xacml.rest.model.RemoveGroupPolicy; +import org.openecomp.policy.pap.xacml.rest.util.JPAUtils; +import org.openecomp.policy.pap.xacml.restAuth.CheckPDP; +import org.openecomp.policy.rest.XACMLRest; +import org.openecomp.policy.rest.XACMLRestProperties; +import org.openecomp.policy.rest.jpa.ActionPolicyDict; +import org.openecomp.policy.rest.jpa.BRMSParamTemplate; +import org.openecomp.policy.rest.jpa.MicroServiceModels; +import org.openecomp.policy.rest.jpa.PolicyEditorScopes; +import org.openecomp.policy.rest.jpa.PolicyScore; +import org.openecomp.policy.rest.jpa.PolicyVersion; +import org.openecomp.policy.rest.jpa.UserInfo; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import javax.persistence.PersistenceException; + +import org.openecomp.policy.common.logging.ECOMPLoggingContext; +import org.openecomp.policy.common.logging.ECOMPLoggingUtils; +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.eelf.PolicyLogger; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; +import org.openecomp.policy.xacml.api.pap.ECOMPPapEngineFactory; +import org.openecomp.policy.xacml.api.pap.EcompPDP; +import org.openecomp.policy.xacml.api.pap.EcompPDPGroup; +import org.openecomp.policy.xacml.api.pap.PAPPolicyEngine; + +import com.att.research.xacml.api.pap.PAPException; +//import com.att.research.xacml.api.pap.PDP; +//import com.att.research.xacml.api.pap.PDPGroup; +import com.att.research.xacml.api.pap.PDPPolicy; +import com.att.research.xacml.api.pap.PDPStatus; +import org.openecomp.policy.xacml.std.pap.StdPAPPolicy; +import org.openecomp.policy.xacml.std.pap.StdPDP; +import org.openecomp.policy.xacml.std.pap.StdPDPGroup; +import org.openecomp.policy.xacml.std.pap.StdPDPPolicy; +import org.openecomp.policy.xacml.std.pap.StdPDPStatus; +import org.openecomp.policy.xacml.std.pap.StdPDPItemSetChangeNotifier.StdItemSetChangeListener; +import org.openecomp.policy.xacml.util.XACMLPolicyScanner; + +import com.att.research.xacml.util.FactoryException; +import com.att.research.xacml.util.XACMLProperties; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.base.Joiner; +import com.google.common.base.Splitter; +import org.openecomp.policy.common.im.AdministrativeStateException; +import org.openecomp.policy.common.im.ForwardProgressException; + +//IntegrityMontitor +import org.openecomp.policy.common.im.IntegrityMonitor; +import org.openecomp.policy.common.im.IntegrityMonitorProperties; +import org.openecomp.policy.common.im.StandbyStatusException; +//IntegrityAudit +import org.openecomp.policy.common.ia.IntegrityAudit; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + + +/** + * Servlet implementation class XacmlPapServlet + * + * + */ +@WebServlet( + description = "Implements the XACML PAP RESTful API.", + urlPatterns = { "/" }, + loadOnStartup=1, + initParams = { + @WebInitParam(name = "XACML_PROPERTIES_NAME", value = "xacml.pap.properties", description = "The location of the properties file holding configuration information.") + }) + +public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeListener, Runnable { + private static final long serialVersionUID = 1L; + private static final Logger logger = FlexLogger.getLogger(XACMLPapServlet.class); + + private static String CONFIG_HOME = getConfigHome(); + private static String ACTION_HOME = getActionHome(); + + // audit (transaction) logger + private static final Logger auditLogger = FlexLogger.getLogger("auditLogger"); + + private IntegrityMonitor im; + private IntegrityAudit ia; + + /* + * + * papEngine - This is our engine workhorse that manages the PDP Groups and Nodes. + */ + private PAPPolicyEngine papEngine = null; + /* + * This PAP instance's own URL. + * + * Need this when creating URLs to send to the PDPs so they can GET the Policy files from this process. + */ + private static String papURL = null; + + /* + * These are the parameters needed for DB access from the PAP + */ + public static String papDbDriver = null; + public static String papDbUrl = null; + public static String papDbUser = null; + public static String papDbPassword = null; + private static Integer papTransWait = null; + private static Integer papTransTimeout = null; + private static Integer papAuditTimeout = null; + private static Boolean papAuditFlag = null; + private static Boolean papFileSystemAudit = null; + private static Boolean autoPushFlag = false; + private static String papResourceName = null; + private static Integer fpMonitorInterval = null; + private static Integer failedCounterThreshold = null; + private static Integer testTransInterval = null; + private static Integer writeFpcInterval = null; + private static String papSiteName=null; + private static String papNodeType=null; + private static String papDependencyGroups = null; + private String storedRequestId = null; + private static int papIntegrityAuditPeriodSeconds = -1; + private static String[] papDependencyGroupsFlatArray = null; + + //The entity manager factory for JPA access + private EntityManagerFactory emf; + + //Persistence Unit for JPA + private static final String PERSISTENCE_UNIT = "XACML-PAP-REST"; + private static final String AUDIT_PAP_PERSISTENCE_UNIT = "auditPapPU"; + + + /* + * List of Admin Console URLs. + * Used to send notifications when configuration changes. + * + * The CopyOnWriteArrayList *should* protect from concurrency errors. + * This list is seldom changed but often read, so the costs of this approach make sense. + */ + private static final CopyOnWriteArrayList adminConsoleURLStringList = new CopyOnWriteArrayList(); + + // Mike M 11/24 Client Headers. + private static final String ENVIRONMENT_HEADER = "Environment"; + private static String environment = null; + + /* + * This thread may be invoked upon startup to initiate sending PDP policy/pip configuration when + * this servlet starts. Its configurable by the admin. + */ + private Thread initiateThread = null; + + /* + // The heartbeat thread. + */ + private static Heartbeat heartbeat = null; + private static Thread heartbeatThread = null; + + private ECOMPLoggingContext baseLoggingContext = null; + + private PolicyDBDao policyDBDao; + private AutoPushPolicy autoPushPolicy; + /** + * @see HttpServlet#HttpServlet() + */ + public XACMLPapServlet() { + super(); + } + /* + * PDP FIle + */ + private static String pdpFile = null; + public static String getPDPFile(){ + return XACMLPapServlet.pdpFile; + } + + /** + * @see Servlet#init(ServletConfig) + */ + public void init(ServletConfig config) throws ServletException { + + + try { + // + // Logging stuff.... + // + baseLoggingContext = new ECOMPLoggingContext(); + // fixed data that will be the same in all logging output goes here + try { + String hostname = InetAddress.getLocalHost().getCanonicalHostName(); + baseLoggingContext.setServer(hostname); + } catch (UnknownHostException e) { + logger.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Unable to get hostname for logging"); + } + + // + // Initialize + // + XACMLRest.xacmlInit(config); + // + // Load the properties + // + XACMLRest.loadXacmlProperties(null, null); + + /* + * Retrieve the property values for db access and audits from the xacml.pap.properties + */ + //Null string occurs when a property is not present + try{ + papDbDriver = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_DB_DRIVER); + if(papDbDriver == null){ + throw new PAPException("papDbDriver is null"); + } + } + catch(Exception e){ + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "XACMLPapServlet", " ERROR: Bad property entry"); + throw e; + } + try{ + papDbUrl = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_DB_URL); + if(papDbUrl == null){ + throw new PAPException("papDbUrl is null"); + } + } catch(Exception e){ + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "XACMLPapServlet", " ERROR: Bad property entry"); + throw e; + } + try{ + papDbUser = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_DB_USER); + if(papDbUser == null){ + throw new PAPException("papDbUser is null"); + } + }catch(Exception e){ + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "XACMLPapServlet", " ERROR: Bad property entry"); + throw e; + } + try{ + papDbPassword = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_DB_PASSWORD); + if(papDbPassword == null){ + throw new PAPException("papDbPassword is null"); + } + }catch(Exception e){ + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "XACMLPapServlet", " ERROR: Bad property entry"); + throw e; + } + + environment = XACMLProperties.getProperty("ENVIRONMENT", "DEVL"); + + //Integer will throw an exception of anything is missing or unrecognized + papTransWait = Integer.parseInt(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_TRANS_WAIT)); + papTransTimeout = Integer.parseInt(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_TRANS_TIMEOUT)); + papAuditTimeout = Integer.parseInt(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_AUDIT_TIMEOUT)); + + //Boolean will default to false if anything is missing or unrecognized + papAuditFlag = Boolean.parseBoolean(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_RUN_AUDIT_FLAG)); + papFileSystemAudit = Boolean.parseBoolean(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_AUDIT_FLAG)); + + //PAP Auto Push + autoPushFlag = Boolean.parseBoolean(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_PUSH_FLAG)); + // if Auto push then Load with properties. + if(autoPushFlag){ + String file; + try{ + file = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_PUSH_FILE); + if(file.endsWith(".properties")){ + autoPushPolicy = new AutoPushPolicy(file); + }else{ + throw new Exception(); + } + }catch(Exception e){ + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " Missing property or not a proper property file check for: " + XACMLRestProperties.PROP_PAP_PUSH_FILE ); + logger.info("Overriding the autoPushFlag to False..."); + autoPushFlag = false; + } + } + + try{ + papResourceName = XACMLProperties.getProperty(XACMLRestProperties.PAP_RESOURCE_NAME); + if(papResourceName == null){ + throw new PAPException("papResourceName is null"); + } + }catch(Exception e){ + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "XACMLPapServlet", " ERROR: Bad property entry"); + throw e; + } + + try{ + papSiteName = XACMLProperties.getProperty(XACMLRestProperties.PAP_SITE_NAME); + if(papSiteName == null){ + throw new PAPException("papSiteName is null"); + } + }catch(Exception e){ + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "XACMLPapServlet", " ERROR: Bad property entry"); + throw e; + } + try{ + papNodeType = XACMLProperties.getProperty(XACMLRestProperties.PAP_NODE_TYPE); + if(papNodeType == null){ + throw new PAPException("papNodeType is null"); + } + }catch(Exception e){ + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "XACMLPapServlet", " ERROR: Bad property entry"); + throw e; + } + try{ + papDependencyGroups = XACMLProperties.getProperty(XACMLRestProperties.PAP_DEPENDENCY_GROUPS); + if(papDependencyGroups == null){ + throw new PAPException("papDependencyGroups is null"); + } + //Now we have flattened the array into a simple comma-separated list + papDependencyGroupsFlatArray = papDependencyGroups.split("[;,]"); + + //clean up the entries + for (int i = 0 ; i < papDependencyGroupsFlatArray.length ; i ++){ + papDependencyGroupsFlatArray[i] = papDependencyGroupsFlatArray[i].trim(); + } + try{ + if(XACMLProperties.getProperty(XACMLRestProperties.PAP_INTEGRITY_AUDIT_PERIOD_SECONDS) != null){ + papIntegrityAuditPeriodSeconds = Integer.parseInt(XACMLProperties.getProperty(XACMLRestProperties.PAP_INTEGRITY_AUDIT_PERIOD_SECONDS).trim()); + }else{ + //nothing to do. The parameter is optional + } + }catch(Exception e){ + String msg = "integrity_audit_period_seconds "; + logger.error("\n\nERROR: " + msg + "Bad property entry: " + e.getMessage() + "\n"); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "XACMLPapServlet", " ERROR: " + msg +"Bad property entry"); + throw e; + } + }catch(Exception e){ + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "XACMLPapServlet", " ERROR: Bad property entry"); + throw e; + } + + //Integer will throw an exception of anything is missing or unrecognized + fpMonitorInterval = Integer.parseInt(XACMLProperties.getProperty(IntegrityMonitorProperties.FP_MONITOR_INTERVAL)); + failedCounterThreshold = Integer.parseInt(XACMLProperties.getProperty(IntegrityMonitorProperties.FAILED_COUNTER_THRESHOLD)); + testTransInterval = Integer.parseInt(XACMLProperties.getProperty(IntegrityMonitorProperties.TEST_TRANS_INTERVAL)); + writeFpcInterval = Integer.parseInt(XACMLProperties.getProperty(IntegrityMonitorProperties.WRITE_FPC_INTERVAL)); + + logger.debug("\n\n\n**************************************" + + "\n**************************************" + + "\n" + + "\n papDbDriver = " + papDbDriver + + "\n papDbUrl = " + papDbUrl + + "\n papDbUser = " + papDbUser + + "\n papDbPassword = " + papDbPassword + + "\n papTransWait = " + papTransWait + + "\n papTransTimeout = " + papTransTimeout + + "\n papAuditTimeout = " + papAuditTimeout + + "\n papAuditFlag = " + papAuditFlag + + "\n papFileSystemAudit = " + papFileSystemAudit + + "\n autoPushFlag = " + autoPushFlag + + "\n papResourceName = " + papResourceName + + "\n fpMonitorInterval = " + fpMonitorInterval + + "\n failedCounterThreshold = " + failedCounterThreshold + + "\n testTransInterval = " + testTransInterval + + "\n writeFpcInterval = " + writeFpcInterval + + "\n papSiteName = " + papSiteName + + "\n papNodeType = " + papNodeType + + "\n papDependencyGroupsList = " + papDependencyGroups + + "\n papIntegrityAuditPeriodSeconds = " + papIntegrityAuditPeriodSeconds + + "\n\n**************************************" + + "\n**************************************"); + + // + // Pull custom persistence settings + // + + Properties properties; + try { + properties = XACMLProperties.getProperties();//XACMLRestProperties.getProperties(); + logger.debug("\n\n\n**************************************" + + "\n**************************************" + + "\n\n" + + "properties = " + properties + + "\n\n**************************************"); + + } catch (IOException e) { + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "XACMLPapServlet", " Error loading properties with: " + + "XACMLProperties.getProperties()"); + throw new ServletException(e.getMessage(), e.getCause()); + } + + // Create an IntegrityMonitor + im = IntegrityMonitor.getInstance(papResourceName,properties); + + // Create an IntegrityAudit + ia = new IntegrityAudit(papResourceName, AUDIT_PAP_PERSISTENCE_UNIT, properties); + ia.startAuditThread(); + + // + // Create the entity manager factory + // + emf = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT, properties); + // + // Did it get created? + // + if (emf == null) { + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " Error creating entity manager factory with persistence unit: " + + PERSISTENCE_UNIT); + throw new ServletException("Unable to create Entity Manager Factory"); + } + // + // we are about to call the PDPs and give them their configuration. + // To do that we need to have the URL of this PAP so we can construct the Policy file URLs + // + XACMLPapServlet.papURL = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_URL); + /* + * Create the PolicyDBDao singleton + */ + //Create the policyDBDao + policyDBDao = PolicyDBDao.getPolicyDBDaoInstance(getEmf()); + boolean performFileToDatabaseAudit = false; + if (Boolean.parseBoolean(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_RUN_AUDIT_FLAG))){ + if (Boolean.parseBoolean(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_AUDIT_FLAG))){ + //get an AuditTransaction to lock out all other transactions + PolicyDBDaoTransaction auditTrans = policyDBDao.getNewAuditTransaction(); + policyDBDao.auditLocalFileSystem(); + //release the transaction lock + auditTrans.close(); + }else{ + performFileToDatabaseAudit = true; + } + } + + + + // + // Load our PAP engine, first create a factory + // + ECOMPPapEngineFactory factory = ECOMPPapEngineFactory.newInstance(XACMLProperties.getProperty(XACMLProperties.PROP_PAP_PAPENGINEFACTORY)); + // + // The factory knows how to go about creating a PAP Engine + // + this.papEngine = (PAPPolicyEngine) factory.newEngine(); + PolicyDBDaoTransaction addNewGroup = null; + try{ + + if(((org.openecomp.policy.xacml.std.pap.StdEngine)papEngine).wasDefaultGroupJustAdded){ + addNewGroup = policyDBDao.getNewTransaction(); + EcompPDPGroup group = papEngine.getDefaultGroup(); + addNewGroup.createGroup(group.getId(), group.getName(), group.getDescription(), "automaticallyAdded"); + addNewGroup.commitTransaction(); + addNewGroup = policyDBDao.getNewTransaction(); + addNewGroup.changeDefaultGroup(group, "automaticallyAdded"); + addNewGroup.commitTransaction(); + } + + } catch(Exception e){ + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "XACMLPapServlet", " Error creating new default group in the database"); + if(addNewGroup != null){ + addNewGroup.rollbackTransaction(); + } + } + + policyDBDao.setPapEngine((PAPPolicyEngine) this.papEngine); + + + if(performFileToDatabaseAudit){ + //get an AuditTransaction to lock out all other transactions + PolicyDBDaoTransaction auditTrans = policyDBDao.getNewAuditTransaction(); + policyDBDao.auditLocalDatabase((PAPPolicyEngine) this.papEngine); + //release the transaction lock + auditTrans.close(); + } + + // + // PDPId File location + // + XACMLPapServlet.pdpFile = XACMLProperties.getProperty(XACMLRestProperties.PROP_PDP_IDFILE); + if (XACMLPapServlet.pdpFile == null) { + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + + " The PDP Id Authentication File Property is not valid: " + + XACMLRestProperties.PROP_PDP_IDFILE); + throw new PAPException("The PDP Id Authentication File Property :"+ XACMLRestProperties.PROP_PDP_IDFILE+ " is not Valid. "); + } + // + // Sanity check that a URL was defined somewhere, its essential. + // + // How to check that its valid? We can validate the form, but since we are in the init() method we + // are not fully loaded yet so we really couldn't ping ourself to see if the URL will work. One + // will have to look for errors in the PDP logs to determine if they are failing to initiate a + // request to this servlet. + // + if (XACMLPapServlet.papURL == null) { + + throw new PAPException("The property " + XACMLRestProperties.PROP_PAP_URL + " is not valid: " + XACMLPapServlet.papURL); + } + // + // Configurable - have the PAP servlet initiate sending the latest PDP policy/pip configuration + // to all its known PDP nodes. + // + // Note: parseBoolean will return false if there is no property defined. This is fine for a default. + // + if (Boolean.parseBoolean(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_INITIATE_PDP_CONFIG))) { + this.initiateThread = new Thread(this); + this.initiateThread.start(); + } + // + // After startup, the PAP does Heartbeats to each of the PDPs periodically + // + XACMLPapServlet.heartbeat = new Heartbeat((PAPPolicyEngine) this.papEngine); + XACMLPapServlet.heartbeatThread = new Thread(XACMLPapServlet.heartbeat); + XACMLPapServlet.heartbeatThread.start(); + } catch (FactoryException | PAPException e) { + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "XACMLPapServlet", " Failed to create engine"); + throw new ServletException (XACMLErrorConstants.ERROR_SYSTEM_ERROR + "PAP not initialized; error: "+e); + } catch (Exception e) { + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "XACMLPapServlet", " Failed to create engine - unexpected error"); + throw new ServletException (XACMLErrorConstants.ERROR_SYSTEM_ERROR + "PAP not initialized; unexpected error: "+e); } + } + + /** + * Thread used only during PAP startup to initiate change messages to all known PDPs. + * This must be on a separate thread so that any GET requests from the PDPs during this update can be serviced. + */ + @Override + public void run() { + // + // send the current configuration to all the PDPs that we know about + // + changed(); + } + + + /** + * @see Servlet#destroy() + * + * Depending on how this servlet is run, we may or may not care about cleaning up the resources. + * For now we assume that we do care. + */ + public void destroy() { + // + // Make sure our threads are destroyed + // + if (XACMLPapServlet.heartbeatThread != null) { + // + // stop the heartbeat + // + try { + if (XACMLPapServlet.heartbeat != null) { + XACMLPapServlet.heartbeat.terminate(); + } + XACMLPapServlet.heartbeatThread.interrupt(); + XACMLPapServlet.heartbeatThread.join(); + } catch (InterruptedException e) { + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "XACMLPapServlet", " Error stopping heartbeat"); + } + } + if (this.initiateThread != null) { + try { + this.initiateThread.interrupt(); + this.initiateThread.join(); + } catch (InterruptedException e) { + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "XACMLPapServlet", " Error stopping thread"); + } + } + } + + /** + * + * Called by: + * - PDP nodes to register themselves with the PAP, and + * - Admin Console to make changes in the PDP Groups. + * + * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) + */ + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + ECOMPLoggingContext loggingContext = ECOMPLoggingUtils.getLoggingContextForRequest(request, baseLoggingContext); + + loggingContext.transactionStarted(); + loggingContext.setServiceName("PAP.post"); // we may set a more specific value later + if ((loggingContext.getRequestID() == null) || (loggingContext.getRequestID() == "")){ + UUID requestID = UUID.randomUUID(); + loggingContext.setRequestID(requestID.toString()); + PolicyLogger.info("requestID not provided in call to XACMLPapSrvlet (doPost) so we generated one"); + } else { + PolicyLogger.info("requestID was provided in call to XACMLPapSrvlet (doPost)"); + } + // dummy metric.log example posted below as proof of concept + loggingContext.metricStarted(); + loggingContext.metricEnded(); + PolicyLogger.metrics("Metric example posted here - 1 of 2"); + loggingContext.metricStarted(); + loggingContext.metricEnded(); + PolicyLogger.metrics("Metric example posted here - 2 of 2"); + // dummy metric.log example posted above as proof of concept + PolicyDBDaoTransaction pdpTransaction = null; + + //This im.startTransaction() covers all Post transactions + try { + im.startTransaction(); + } catch (AdministrativeStateException ae){ + String message = "POST interface called for PAP " + papResourceName + " but it has an Administrative" + + " state of " + im.getStateManager().getAdminState() + + "\n Exception Message: " + ae.getMessage(); + logger.info(message); + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + " " + message); + loggingContext.transactionEnded(); + + PolicyLogger.audit("Transaction Failed - See Error.log"); + + response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message); + return; + }catch (StandbyStatusException se) { + se.printStackTrace(); + String message = "POST interface called for PAP " + papResourceName + " but it has a Standby Status" + + " of " + im.getStateManager().getStandbyStatus() + + "\n Exception Message: " + se.getMessage(); + logger.info(message); + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + " " + message); + loggingContext.transactionEnded(); + + PolicyLogger.audit("Transaction Failed - See Error.log"); + + response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message); + return; + } + + try { + + XACMLRest.dumpRequest(request); + + // since getParameter reads the content string, explicitly get the content before doing that. + // Simply getting the inputStream seems to protect it against being consumed by getParameter. + request.getInputStream(); + + + String groupId = request.getParameter("groupId"); + String apiflag = request.getParameter("apiflag"); + + if (groupId != null) { + // Is this from the Admin Console or API? + if(apiflag!=null) { + if (apiflag.equalsIgnoreCase("api")) { + // this is from the API so we need to check the client credentials before processing the request + if(authorizeRequest(request)){ + doACPost(request, response, groupId, loggingContext); + // Mike B - ended loggingContext transacton & added EELF 'Success' EELF Audit.log message + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Ended Successfully"); + im.endTransaction(); + return; + } else { + String message = "PEP not Authorized for making this Request!! \n Contact Administrator for this Scope. "; + PolicyLogger.error(MessageCodes.ERROR_PERMISSIONS + " " + message); + loggingContext.transactionEnded(); + + PolicyLogger.audit("Transaction Failed - See Error.log"); + + response.sendError(HttpServletResponse.SC_FORBIDDEN, message); + im.endTransaction(); + return; + } + } + } + + // this is from the Admin Console, so handle separately + doACPost(request, response, groupId, loggingContext); + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Ended Successfully"); + im.endTransaction(); + return; + + } + + + // + // Request is from a PDP. + // It is coming up and asking for its config + // + loggingContext.setServiceName("PDP:PAP.register"); + + + // + // Get the PDP's ID + // + String id = this.getPDPID(request); + String jmxport = this.getPDPJMX(request); + //logger.info("doPost from: " + id); + logger.info("Request(doPost) from PDP coming up: " + id); + // + // Get the PDP Object + // + EcompPDP pdp = this.papEngine.getPDP(id); + // + // Is it known? + // + if (pdp == null) { + logger.info("Unknown PDP: " + id); + // PDP ID Check is performed Here. + if(CheckPDP.validateID(id)){ + pdpTransaction = policyDBDao.getNewTransaction(); + try { + //this.papEngine.newPDP(id, this.papEngine.getDefaultGroup(), id, "Registered on first startup"); + pdpTransaction.addPdpToGroup(id, this.papEngine.getDefaultGroup().getId(), id, "Registered on first startup", Integer.parseInt(jmxport), "PDP autoregister"); + this.papEngine.newPDP(id, this.papEngine.getDefaultGroup(), id, "Registered on first startup", Integer.parseInt(jmxport)); + } catch (NullPointerException | PAPException | IllegalArgumentException | IllegalStateException | PersistenceException e) { + pdpTransaction.rollbackTransaction(); + String message = "Failed to create new PDP for id: " + id; + PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "XACMLPapServlet", " " + message); + loggingContext.transactionEnded(); + + PolicyLogger.audit("Transaction Failed - See Error.log"); + + PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "XACMLPapServlet", " " + message); + response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); + im.endTransaction(); + return; + } + // get the PDP we just created + pdp = this.papEngine.getPDP(id); + if (pdp == null) { + if(pdpTransaction != null){ + pdpTransaction.rollbackTransaction(); + } + String message = "Failed to create new PDP for id: " + id; + PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW + " " + message); + loggingContext.transactionEnded(); + + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message); + im.endTransaction(); + return; + } + } else { + String message = "PDP is Unauthorized to Connect to PAP: "+ id; + PolicyLogger.error(MessageCodes.ERROR_PERMISSIONS + " " + message); + loggingContext.transactionEnded(); + response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "PDP not Authorized to connect to this PAP. Please contact the PAP Admin for registration."); + PolicyLogger.audit("Transaction Failed - See Error.log"); + im.endTransaction(); + return; + } + // get the PDP we just created + pdp = this.papEngine.getPDP(id); + if (pdp == null) { + if(pdpTransaction != null){ + pdpTransaction.rollbackTransaction(); + } + String message = "Failed to create new PDP for id: " + id; + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + " " + message); + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message); + im.endTransaction(); + return; + } + try{ + pdpTransaction.commitTransaction(); + } catch(Exception e){ + PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "XACMLPapServlet", "Could not commit transaction to put pdp in the database"); + } + } + + if (jmxport != null && jmxport != ""){ + ((StdPDP) pdp).setJmxPort(Integer.valueOf(jmxport)); + } + + // + // Get the PDP's Group + // + EcompPDPGroup group = this.papEngine.getPDPGroup((EcompPDP) pdp); + if (group == null) { + PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW + " PDP not associated with any group, even the default"); + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "PDP not associated with any group, even the default"); + im.endTransaction(); + return; + } + // + // Determine what group the PDP node is in and get + // its policy/pip properties. + // + Properties policies = group.getPolicyProperties(); + Properties pipconfig = group.getPipConfigProperties(); + // + // Get the current policy/pip configuration that the PDP has + // + Properties pdpProperties = new Properties(); + pdpProperties.load(request.getInputStream()); + logger.info("PDP Current Properties: " + pdpProperties.toString()); + logger.info("Policies: " + (policies != null ? policies.toString() : "null")); + logger.info("Pip config: " + (pipconfig != null ? pipconfig.toString() : "null")); + // + // Validate the node's properties + // + boolean isCurrent = this.isPDPCurrent(policies, pipconfig, pdpProperties); + // + // Send back current configuration + // + if (isCurrent == false) { + // + // Tell the PDP we are sending back the current policies/pip config + // + logger.info("PDP configuration NOT current."); + if (policies != null) { + // + // Put URL's into the properties in case the PDP needs to + // retrieve them. + // + this.populatePolicyURL(request.getRequestURL(), policies); + // + // Copy the properties to the output stream + // + policies.store(response.getOutputStream(), ""); + } + if (pipconfig != null) { + // + // Copy the properties to the output stream + // + pipconfig.store(response.getOutputStream(), ""); + } + // + // We are good - and we are sending them information + // + response.setStatus(HttpServletResponse.SC_OK); + + setPDPSummaryStatus(pdp, PDPStatus.Status.OUT_OF_SYNCH); + } else { + // + // Tell them they are good + // + response.setStatus(HttpServletResponse.SC_NO_CONTENT); + + setPDPSummaryStatus(pdp, PDPStatus.Status.UP_TO_DATE); + + } + // + // tell the AC that something changed + // + notifyAC(); + loggingContext.transactionEnded(); + auditLogger.info("Success"); + PolicyLogger.audit("Transaction Ended Successfully"); + } catch (PAPException e) { + if(pdpTransaction != null){ + pdpTransaction.rollbackTransaction(); + } + logger.debug(XACMLErrorConstants.ERROR_PROCESS_FLOW + "POST exception: " + e, e); + loggingContext.transactionEnded(); + + PolicyLogger.audit("Transaction Failed - See Error.log"); + + response.sendError(500, e.getMessage()); + im.endTransaction(); + return; + } + //Catch anything that fell through + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Ended"); + im.endTransaction(); + } + + /** + * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) + */ + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + ECOMPLoggingContext loggingContext = ECOMPLoggingUtils.getLoggingContextForRequest(request, baseLoggingContext); + loggingContext.transactionStarted(); + loggingContext.setServiceName("PAP.get"); // we may set a more specific value later + if ((loggingContext.getRequestID() == null) || (loggingContext.getRequestID() == "")){ + UUID requestID = UUID.randomUUID(); + loggingContext.setRequestID(requestID.toString()); + PolicyLogger.info("requestID not provided in call to XACMLPapSrvlet (doGet) so we generated one"); + } else { + PolicyLogger.info("requestID was provided in call to XACMLPapSrvlet (doGet)"); + } + // dummy metric.log example posted below as proof of concept + loggingContext.metricStarted(); + loggingContext.metricEnded(); + PolicyLogger.metrics("Metric example posted here - 1 of 2"); + loggingContext.metricStarted(); + loggingContext.metricEnded(); + PolicyLogger.metrics("Metric example posted here - 2 of 2"); + // dummy metric.log example posted above as proof of concept + try { + XACMLRest.dumpRequest(request); + String pathInfo = request.getRequestURI(); + logger.info("path info: " + pathInfo); + if (pathInfo != null){ + //DO NOT do a im.startTransaction for the test request + if (pathInfo.equals("/pap/test")) { + logger.info("Test request received"); + try { + im.evaluateSanity(); + //If we make it this far, all is well + String message = "GET:/pap/test called and PAP " + papResourceName + " is OK"; + logger.info(message); + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.setStatus(HttpServletResponse.SC_OK); + return; + }catch (ForwardProgressException fpe){ + //No forward progress is being made + String message = "GET:/pap/test called and PAP " + papResourceName + " is not making forward progress." + + " Exception Message: " + fpe.getMessage(); + logger.info(message); + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + " " + message); + loggingContext.transactionEnded(); + + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message); + return; + }catch (AdministrativeStateException ase){ + //Administrative State is locked + String message = "GET:/pap/test called and PAP " + papResourceName + " Administrative State is LOCKED " + + " Exception Message: " + ase.getMessage(); + logger.info(message); + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + " " + message); + loggingContext.transactionEnded(); + + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message); + return; + }catch (StandbyStatusException sse){ + //Administrative State is locked + String message = "GET:/pap/test called and PAP " + papResourceName + " Standby Status is NOT PROVIDING SERVICE " + + " Exception Message: " + sse.getMessage(); + logger.info(message); + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + " " + message); + loggingContext.transactionEnded(); + + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message); + return; + }catch (Exception e) { + //A subsystem is not making progress, is locked, standby or is not responding + String eMsg = e.getMessage(); + if(eMsg == null){ + eMsg = "No Exception Message"; + } + String message = "GET:/pap/test called and PAP " + papResourceName + " has had a subsystem failure." + + " Exception Message: " + eMsg; + logger.info(message); + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + " " + message); + loggingContext.transactionEnded(); + + PolicyLogger.audit("Transaction Failed - See Error.log"); + //Get the specific list of subsystems that failed + String ssFailureList = null; + for(String failedSS : papDependencyGroupsFlatArray){ + if(eMsg.contains(failedSS)){ + if(ssFailureList == null){ + ssFailureList = failedSS; + }else{ + ssFailureList = ssFailureList.concat(","+failedSS); + } + } + } + if(ssFailureList == null){ + ssFailureList = "UnknownSubSystem"; + } + response.addHeader("X-ECOMP-SubsystemFailure", ssFailureList); + response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message); + return; + } + } + } + + //This im.startTransaction() covers all other Get transactions + try { + im.startTransaction(); + } catch (AdministrativeStateException ae){ + String message = "GET interface called for PAP " + papResourceName + " but it has an Administrative" + + " state of " + im.getStateManager().getAdminState() + + "\n Exception Message: " + ae.getMessage(); + logger.info(message); + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + " " + message); + loggingContext.transactionEnded(); + + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message); + return; + }catch (StandbyStatusException se) { + se.printStackTrace(); + String message = "GET interface called for PAP " + papResourceName + " but it has a Standby Status" + + " of " + im.getStateManager().getStandbyStatus() + + "\n Exception Message: " + se.getMessage(); + logger.info(message); + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + " " + message); + loggingContext.transactionEnded(); + + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message); + return; + } + + + // Request from the API to get the gitPath + String apiflag = request.getParameter("apiflag"); + if (apiflag!=null) { + if(authorizeRequest(request)){ + + + // Request from the API to get the gitPath + if (apiflag.equalsIgnoreCase("gitPath")) { + getGitPath(request, response); + // Mike B - ended loggingContext transacton & added EELF 'Success' EELF Audit.log message + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Ended Successfully"); + im.endTransaction(); + return; + } + + // Request from the API to get the ActiveVersion from the PolicyVersion table + if (apiflag.equalsIgnoreCase("version")){ + getActiveVersion(request, response); + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Ended Successfully"); + im.endTransaction(); + return; + } + + // Request from the API to get the URI from the gitpath + if (apiflag.equalsIgnoreCase("uri")){ + getSelectedURI(request, response); + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Ended Successfully"); + im.endTransaction(); + return; + } + + } else { + String message = "PEP not Authorized for making this Request!! \n Contact Administrator for this Scope. "; + PolicyLogger.error(MessageCodes.ERROR_PERMISSIONS + " " + message); + loggingContext.transactionEnded(); + + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(HttpServletResponse.SC_FORBIDDEN, message); + im.endTransaction(); + return; + } + + } + + + // Is this from the Admin Console? + String groupId = request.getParameter("groupId"); + if (groupId != null) { + // this is from the Admin Console, so handle separately + doACGet(request, response, groupId, loggingContext); + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Ended Successfully"); + im.endTransaction(); + return; + } + + // + // Get the PDP's ID + // + String id = this.getPDPID(request); + logger.info("doGet from: " + id); + // + // Get the PDP Object + // + EcompPDP pdp = this.papEngine.getPDP(id); + // + // Is it known? + // + if (pdp == null) { + // + // Check if request came from localhost + // + if (request.getRemoteHost().equals("localhost") || + request.getRemoteHost().equals("127.0.0.1") || + request.getRemoteHost().equals(request.getLocalAddr())) { + // + // Return status information - basically all the groups + // + loggingContext.setServiceName("PAP.getGroups"); + Set groups = papEngine.getEcompPDPGroups(); + + // convert response object to JSON and include in the response + ObjectMapper mapper = new ObjectMapper(); + mapper.writeValue(response.getOutputStream(), groups); + response.setHeader("content-type", "application/json"); + response.setStatus(HttpServletResponse.SC_OK); + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Ended Successfully"); + im.endTransaction(); + return; + } + String message = "Unknown PDP: " + id + " from " + request.getRemoteHost() + " us: " + request.getLocalAddr(); + PolicyLogger.error(MessageCodes.ERROR_PERMISSIONS + " " + message); + loggingContext.transactionEnded(); + + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(HttpServletResponse.SC_UNAUTHORIZED, message); + im.endTransaction(); + return; + } + + loggingContext.setServiceName("PAP.getPolicy"); + + // + // Get the PDP's Group + // + EcompPDPGroup group = this.papEngine.getPDPGroup((EcompPDP) pdp); + if (group == null) { + String message = "No group associated with pdp " + pdp.getId(); + logger.warn(XACMLErrorConstants.ERROR_PERMISSIONS + message); + loggingContext.transactionEnded(); + + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(HttpServletResponse.SC_UNAUTHORIZED, message); + im.endTransaction(); + return; + } + // + // Which policy do they want? + // + String policyId = request.getParameter("id"); + if (policyId == null) { + String message = "Did not specify an id for the policy"; + logger.warn(XACMLErrorConstants.ERROR_DATA_ISSUE + message); + loggingContext.transactionEnded(); + + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(HttpServletResponse.SC_NOT_FOUND, message); + im.endTransaction(); + return; + } + PDPPolicy policy = group.getPolicy(policyId); + if (policy == null) { + String message = "Unknown policy: " + policyId; + logger.warn(XACMLErrorConstants.ERROR_DATA_ISSUE + message); + loggingContext.transactionEnded(); + + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(HttpServletResponse.SC_NOT_FOUND, message); + im.endTransaction(); + return; + } + // + // Get its stream + // + logger.warn("PolicyDebugging: Policy Validity: " + policy.isValid() + "\n " + + "Policy Name : " + policy.getName() + "\n Policy URI: " + policy.getLocation().toString() ); + try (InputStream is = policy.getStream(); OutputStream os = response.getOutputStream()) { + // + // Send the policy back + // + IOUtils.copy(is, os); + + response.setStatus(HttpServletResponse.SC_OK); + loggingContext.transactionEnded(); + auditLogger.info("Success"); + PolicyLogger.audit("Transaction Ended Successfully"); + } catch (PAPException e) { + String message = "Failed to open policy id " + policyId; + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " " + message); + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(HttpServletResponse.SC_NOT_FOUND, message); + } + } catch (PAPException e) { + PolicyLogger.error(MessageCodes.ERROR_UNKNOWN, e, "XACMLPapServlet", " GET exception"); + loggingContext.transactionEnded(); + + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(500, e.getMessage()); + im.endTransaction(); + return; + } + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Ended"); + im.endTransaction(); + } + + + /** + * Requests from the PolicyEngine API to update the PDP Group with pushed policy + * + * @param request + * @param response + * @param groupId + * @param loggingContext + * @throws ServletException + * @throws IOException + */ + private void updateGroupsFromAPI(HttpServletRequest request, HttpServletResponse response, String groupId, ECOMPLoggingContext loggingContext) throws IOException { + PolicyDBDaoTransaction acPutTransaction = policyDBDao.getNewTransaction(); + try { + + + // for PUT operations the group may or may not need to exist before the operation can be done + StdPDPGroup group = (StdPDPGroup) papEngine.getGroup(groupId); + + // get the request content into a String + String json = null; + + // read the inputStream into a buffer (trick found online scans entire input looking for end-of-file) + java.util.Scanner scanner = new java.util.Scanner(request.getInputStream()); + scanner.useDelimiter("\\A"); + json = scanner.hasNext() ? scanner.next() : ""; + scanner.close(); + logger.info("JSON request from PolicyEngine API: " + json); + + // convert Object sent as JSON into local object + ObjectMapper mapper = new ObjectMapper(); + + Object objectFromJSON = mapper.readValue(json, StdPDPPolicy.class); + + StdPDPPolicy policy = (StdPDPPolicy) objectFromJSON; + + Set policies = new HashSet(); + + if(policy!=null){ + policies.add(policy); + } + + //Get the current policies from the Group and Add the new one + Set currentPoliciesInGroup = new HashSet(); + currentPoliciesInGroup = group.getPolicies(); + + //If the selected policy is in the group we must remove it because the name is default + Iterator policyIterator = policies.iterator(); + logger.debug("policyIterator....." + policies); + while (policyIterator.hasNext()) { + PDPPolicy selPolicy = policyIterator.next(); + for (PDPPolicy existingPolicy : currentPoliciesInGroup) { + if (existingPolicy.getId().equals(selPolicy.getId())) { + group.removePolicyFromGroup(existingPolicy); + logger.debug("Removing policy: " + existingPolicy); + break; + } + } + } + + if(currentPoliciesInGroup!=null){ + policies.addAll(currentPoliciesInGroup); + } + group.setPolicies(policies); + + // Assume that this is an update of an existing PDP Group + loggingContext.setServiceName("PolicyEngineAPI:PAP.updateGroup"); + + try{ + acPutTransaction.updateGroup(group, "XACMLPapServlet.doACPut"); + } catch(Exception e){ + PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "XACMLPapServlet", " Error while updating group in the database: " + +"group="+group.getId()); + throw new PAPException(e.getMessage()); + } + + papEngine.updateGroup(group); + response.setStatus(HttpServletResponse.SC_NO_CONTENT); + response.addHeader("operation", "push"); + response.addHeader("policyId", policy.getId()); + response.addHeader("groupId", groupId); + if (logger.isDebugEnabled()) { + logger.debug("Group '" + group.getId() + "' updated"); + } + + acPutTransaction.commitTransaction(); + + notifyAC(); + + // Group changed, which might include changing the policies + groupChanged(group); + loggingContext.transactionEnded(); + auditLogger.info("Success"); + PolicyLogger.audit("Transaction Ended Successfully"); + return; + } catch (PAPException e) { + acPutTransaction.rollbackTransaction(); + PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "XACMLPapServlet", " API PUT exception"); + loggingContext.transactionEnded(); + + PolicyLogger.audit("Transaction Failed - See Error.log"); + + String message = XACMLErrorConstants.ERROR_PROCESS_FLOW + "Exception in request to update group from API - See Error.log on on the PAP."; + response.sendError(500, e.getMessage()); + response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); + response.addHeader("error","addGroupError"); + response.addHeader("message", message); + return; + } + + } + + private void getActiveVersion(HttpServletRequest request, HttpServletResponse response) { + //Setup EntityManager to communicate with the PolicyVersion table of the DB + EntityManager em = null; + em = (EntityManager) emf.createEntityManager(); + + if (em==null){ + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " Error creating entity manager with persistence unit: " + PERSISTENCE_UNIT); + try { + throw new Exception("Unable to create Entity Manager Factory"); + } catch (Exception e) { + e.printStackTrace(); + } + } + + String policyScope = request.getParameter("policyScope"); + String filePrefix = request.getParameter("filePrefix"); + String policyName = request.getParameter("policyName"); + + String pvName = policyScope + File.separator + filePrefix + policyName; + int activeVersion = 0; + + + //Get the Active Version to use in the ID + em.getTransaction().begin(); + Query query = em.createQuery("Select p from PolicyVersion p where p.policyName=:pname"); + query.setParameter("pname", pvName); + + @SuppressWarnings("rawtypes") + List result = query.getResultList(); + PolicyVersion versionEntity = null; + if (!result.isEmpty()) { + versionEntity = (PolicyVersion) result.get(0); + em.persist(versionEntity); + activeVersion = versionEntity.getActiveVersion(); + em.getTransaction().commit(); + } else { + logger.debug("No PolicyVersion using policyName found"); + } + + //clean up connection + em.close(); + if (String.valueOf(activeVersion)!=null || !String.valueOf(activeVersion).equalsIgnoreCase("")) { + response.setStatus(HttpServletResponse.SC_OK); + response.addHeader("version", String.valueOf(activeVersion)); + } else { + response.setStatus(HttpServletResponse.SC_NOT_FOUND); + } + + + } + + private void getSelectedURI(HttpServletRequest request, + HttpServletResponse response) { + + String gitPath = request.getParameter("gitPath"); + + File file = new File(gitPath); + + logger.debug("The fileItem is : " + file.toString()); + + URI selectedURI = file.toURI(); + + String uri = selectedURI.toString(); + + if (!uri.equalsIgnoreCase("")) { + response.setStatus(HttpServletResponse.SC_OK); + response.addHeader("selectedURI", uri); + } else { + response.setStatus(HttpServletResponse.SC_NOT_FOUND); + } + } + + /* + * getGitPath() method to get the gitPath using data from the JSON string + * when deleting policies using doAPIDelete() + */ + private File getPolicyFile(String policyName){ + + Path workspacePath = Paths.get(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_WORKSPACE), "admin"); + Path repositoryPath = Paths.get(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_REPOSITORY)); + Path gitPath = Paths.get(workspacePath.toString(), repositoryPath.getFileName().toString()); + + //getting the fullpath of the gitPath and convert to string + String fullGitPath = gitPath.toAbsolutePath().toString(); + String finalGitPath = null; + + //creating the parentPath directory for the Admin Console use + if(fullGitPath.contains("\\")){ + finalGitPath = fullGitPath.replace("ECOMP-PAP-REST", "ecomp-sdk-app"); + }else{ + finalGitPath = fullGitPath.replace("pap", "console"); + } + + finalGitPath += File.separator + policyName; + + File file = new File(finalGitPath); + + return file; + + } + + /* + * getGitPath() method to get the gitPath using data from the http request + * and send back in response when pushing policies + */ + private void getGitPath(HttpServletRequest request, + HttpServletResponse response) { + + String policyScope = request.getParameter("policyScope"); + String filePrefix = request.getParameter("filePrefix"); + String policyName = request.getParameter("policyName"); + String activeVersion = request.getParameter("activeVersion"); + + Path workspacePath = Paths.get(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_WORKSPACE), "admin"); + Path repositoryPath = Paths.get(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_REPOSITORY)); + Path gitPath = Paths.get(workspacePath.toString(), repositoryPath.getFileName().toString()); + + //getting the fullpath of the gitPath and convert to string + String fullGitPath = gitPath.toAbsolutePath().toString(); + String finalGitPath = null; + + //creating the parentPath directory for the Admin Console use + if(fullGitPath.contains("\\")){ + finalGitPath = fullGitPath.replace("ECOMP-PAP-REST", "ecomp-sdk-app"); + }else{ + finalGitPath = fullGitPath.replace("pap", "console"); + } + + finalGitPath += File.separator + policyScope + File.separator + filePrefix + policyName + "." + activeVersion + ".xml"; + File file = new File(finalGitPath); + URI uri = file.toURI(); + + // + // Extract XACML policy information + // + Boolean isValid = false; + String policyId = null; + String description = null; + String version = null; + + URL url; + try { + url = uri.toURL(); + Object rootElement = XACMLPolicyScanner.readPolicy(url.openStream()); + if (rootElement == null || + ( + ! (rootElement instanceof PolicySetType) && + ! (rootElement instanceof PolicyType) + ) ) { + logger.warn("No root policy element in URI: " + uri.toString() + " : " + rootElement); + isValid = false; + } else { + if (rootElement instanceof PolicySetType) { + policyId = ((PolicySetType)rootElement).getPolicySetId(); + description = ((PolicySetType)rootElement).getDescription(); + isValid = true; + version = ((PolicySetType)rootElement).getVersion(); + } else if (rootElement instanceof PolicyType) { + policyId = ((PolicyType)rootElement).getPolicyId(); + description = ((PolicyType)rootElement).getDescription(); + version = ((PolicyType)rootElement).getVersion(); + isValid = true; + } else { + PolicyLogger.error("Unknown root element: " + rootElement.getClass().getCanonicalName()); + } + } + } catch (Exception e) { + logger.error("Exception Occured While Extracting Policy Information"); + } + + if (!finalGitPath.equalsIgnoreCase("") || policyId!=null || description!=null || version!=null || isValid!=null) { + response.setStatus(HttpServletResponse.SC_OK); + response.addHeader("gitPath", finalGitPath); + response.addHeader("policyId", policyId); + response.addHeader("description", description); + response.addHeader("version", version); + response.addHeader("isValid", isValid.toString()); + } else { + response.setStatus(HttpServletResponse.SC_NOT_FOUND); + } + + } + + /** + * Given a version string consisting of integers with dots between them, convert it into an array of ints. + * + * @param version + * @return + * @throws NumberFormatException + */ + public static int[] versionStringToArray(String version) throws NumberFormatException { + if (version == null || version.length() == 0) { + return new int[0]; + } + String[] stringArray = version.split("\\."); + int[] resultArray = new int[stringArray.length]; + for (int i = 0; i < stringArray.length; i++) { + resultArray[i] = Integer.parseInt(stringArray[i]); + } + return resultArray; + } + + protected String getPDPID(HttpServletRequest request) { + String pdpURL = request.getHeader(XACMLRestProperties.PROP_PDP_HTTP_HEADER_ID); + if (pdpURL == null || pdpURL.isEmpty()) { + // + // Should send back its port for identification + // + logger.warn(XACMLErrorConstants.ERROR_DATA_ISSUE + "PDP did not send custom header"); + pdpURL = ""; + } + return pdpURL; + } + + protected String getPDPJMX(HttpServletRequest request) { + String pdpJMMX = request.getHeader(XACMLRestProperties.PROP_PDP_HTTP_HEADER_JMX_PORT); + if (pdpJMMX == null || pdpJMMX.isEmpty()) { + // + // Should send back its port for identification + // + logger.warn(XACMLErrorConstants.ERROR_DATA_ISSUE + "PDP did not send custom header for JMX Port so the value of 0 is assigned"); + return null; + } + return pdpJMMX; + } + private boolean isPDPCurrent(Properties policies, Properties pipconfig, Properties pdpProperties) { + String localRootPolicies = policies.getProperty(XACMLProperties.PROP_ROOTPOLICIES); + String localReferencedPolicies = policies.getProperty(XACMLProperties.PROP_REFERENCEDPOLICIES); + if (localRootPolicies == null || localReferencedPolicies == null) { + logger.warn(XACMLErrorConstants.ERROR_DATA_ISSUE + "Missing property on PAP server: RootPolicies="+localRootPolicies+" ReferencedPolicies="+localReferencedPolicies); + return false; + } + // + // Compare the policies and pipconfig properties to the pdpProperties + // + try { + // + // the policy properties includes only xacml.rootPolicies and + // xacml.referencedPolicies without any .url entries + // + Properties pdpPolicies = XACMLProperties.getPolicyProperties(pdpProperties, false); + Properties pdpPipConfig = XACMLProperties.getPipProperties(pdpProperties); + if (localRootPolicies.equals(pdpPolicies.getProperty(XACMLProperties.PROP_ROOTPOLICIES)) && + localReferencedPolicies.equals(pdpPolicies.getProperty(XACMLProperties.PROP_REFERENCEDPOLICIES)) && + pdpPipConfig.equals(pipconfig)) { + // + // The PDP is current + // + return true; + } + } catch (Exception e) { + // we get here if the PDP did not include either xacml.rootPolicies or xacml.pip.engines, + // or if there are policies that do not have a corresponding ".url" property. + // Either of these cases means that the PDP is not up-to-date, so just drop-through to return false. + PolicyLogger.error(MessageCodes.ERROR_SCHEMA_INVALID, e, "XACMLPapServlet", " PDP Error"); + } + return false; + } + + private void populatePolicyURL(StringBuffer urlPath, Properties policies) { + String lists[] = new String[2]; + lists[0] = policies.getProperty(XACMLProperties.PROP_ROOTPOLICIES); + lists[1] = policies.getProperty(XACMLProperties.PROP_REFERENCEDPOLICIES); + for (String list : lists) { + if (list != null && list.isEmpty() == false) { + for (String id : Splitter.on(',').trimResults().omitEmptyStrings().split(list)) { + String url = urlPath + "?id=" + id; + logger.info("Policy URL for " + id + ": " + url); + policies.setProperty(id + ".url", url); + } + } + } + } + + + /** + * @see HttpServlet#doPut(HttpServletRequest request, HttpServletResponse response) + */ + protected void doPut(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + ECOMPLoggingContext loggingContext = ECOMPLoggingUtils.getLoggingContextForRequest(request, baseLoggingContext); + storedRequestId = loggingContext.getRequestID(); + loggingContext.transactionStarted(); + loggingContext.setServiceName("PAP.put"); // we may set a more specific value later + if ((loggingContext.getRequestID() == null) || (loggingContext.getRequestID() == "")){ + UUID requestID = UUID.randomUUID(); + loggingContext.setRequestID(requestID.toString()); + PolicyLogger.info("requestID not provided in call to XACMLPapSrvlet (doPut) so we generated one"); + } else { + PolicyLogger.info("requestID was provided in call to XACMLPapSrvlet (doPut)"); + } + // dummy metric.log example posted below as proof of concept + loggingContext.metricStarted(); + loggingContext.metricEnded(); + PolicyLogger.metrics("Metric example posted here - 1 of 2"); + loggingContext.metricStarted(); + loggingContext.metricEnded(); + PolicyLogger.metrics("Metric example posted here - 2 of 2"); + //This im.startTransaction() covers all Put transactions + try { + im.startTransaction(); + } catch (AdministrativeStateException ae){ + String message = "PUT interface called for PAP " + papResourceName + " but it has an Administrative" + + " state of " + im.getStateManager().getAdminState() + + "\n Exception Message: " + ae.getMessage(); + logger.info(message); + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + " " + message); + loggingContext.transactionEnded(); + + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message); + return; + }catch (StandbyStatusException se) { + se.printStackTrace(); + String message = "PUT interface called for PAP " + papResourceName + " but it has a Standby Status" + + " of " + im.getStateManager().getStandbyStatus() + + "\n Exception Message: " + se.getMessage(); + logger.info(message); + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + " " + message); + loggingContext.transactionEnded(); + + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message); + return; + } + + XACMLRest.dumpRequest(request); + + // + // since getParameter reads the content string, explicitly get the content before doing that. + // Simply getting the inputStream seems to protect it against being consumed by getParameter. + // + request.getInputStream(); + + //need to check if request is from the API or Admin console + String apiflag = request.getParameter("apiflag"); + + //This would occur if a PolicyDBDao notification was received + String policyDBDaoRequestUrl = request.getParameter("policydbdaourl"); + if(policyDBDaoRequestUrl != null){ + String policyDBDaoRequestEntityId = request.getParameter("entityid"); + //String policyDBDaoRequestEntityType = request.getParameter("entitytype"); + String policyDBDaoRequestEntityType = request.getParameter("entitytype"); + String policyDBDaoRequestExtraData = request.getParameter("extradata"); + if(policyDBDaoRequestEntityId == null || policyDBDaoRequestEntityType == null){ + response.sendError(400, "entityid or entitytype not supplied"); + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Ended Successfully"); + im.endTransaction(); + return; + } + policyDBDao.handleIncomingHttpNotification(policyDBDaoRequestUrl,policyDBDaoRequestEntityId,policyDBDaoRequestEntityType,policyDBDaoRequestExtraData,this); + response.setStatus(200); + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Ended Successfully"); + im.endTransaction(); + return; + } + + //This would occur if we received a notification of a policy creation or update + String policyToCreateUpdate = request.getParameter("policyToCreateUpdate"); + if(policyToCreateUpdate != null){ + if(logger.isDebugEnabled()){ + logger.debug("\nXACMLPapServlet.doPut() - before decoding" + + "\npolicyToCreateUpdate = " + policyToCreateUpdate); + } + //decode it + try{ + policyToCreateUpdate = URLDecoder.decode(policyToCreateUpdate, "UTF-8"); + if(logger.isDebugEnabled()){ + logger.debug("\nXACMLPapServlet.doPut() - after decoding" + + "\npolicyToCreateUpdate = " + policyToCreateUpdate); + } + } catch(UnsupportedEncodingException e){ + PolicyLogger.error("\nXACMLPapServlet.doPut() - Unsupported URL encoding of policyToCreateUpdate (UTF-8)" + + "\npolicyToCreateUpdate = " + policyToCreateUpdate); + response.sendError(500,"policyToCreateUpdate encoding not supported" + + "\nfailure with the following exception: " + e); + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Failed - See error.log"); + im.endTransaction(); + return; + } + + //send it to PolicyDBDao + PolicyDBDaoTransaction createUpdateTransaction = policyDBDao.getNewTransaction(); + try{ + createUpdateTransaction.createPolicy(policyToCreateUpdate, "XACMLPapServlet.doPut"); + }catch(Exception e){ + createUpdateTransaction.rollbackTransaction(); + response.sendError(500,"createUpdateTransaction.createPolicy(policyToCreateUpdate, XACMLPapServlet.doPut) " + + "\nfailure with the following exception: " + e); + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Failed - See error.log"); + im.endTransaction(); + return; + } + createUpdateTransaction.commitTransaction(); + // Before sending Ok. Lets call AutoPush. + if(autoPushFlag){ + Set changedGroups = autoPushPolicy.checkGroupsToPush(policyToCreateUpdate, this.papEngine); + if(!changedGroups.isEmpty()){ + for(StdPDPGroup group: changedGroups){ + try{ + papEngine.updateGroup(group); + if (logger.isDebugEnabled()) { + logger.debug("Group '" + group.getId() + "' updated"); + } + notifyAC(); + // Group changed, which might include changing the policies + groupChanged(group); + }catch(Exception e){ + PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW + " Failed to Push policy. "); + } + } + } + } + response.setStatus(HttpServletResponse.SC_OK); + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Ended Successfully"); + im.endTransaction(); + return; + } + + /* + * Request for Micro Service Import + */ + String microServiceCreation = request.getParameter("importService"); + if (microServiceCreation != null) { + if(authorizeRequest(request)){ + if (microServiceCreation.contains("MICROSERVICE")){ + doImportMicroServicePut(request, response); + im.endTransaction(); + return; + } + } else { + String message = "PEP not Authorized for making this Request!! \n Contact Administrator for this Scope. "; + logger.error(XACMLErrorConstants.ERROR_PERMISSIONS + message ); + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(HttpServletResponse.SC_FORBIDDEN, message); + return; + } + } + //This would occur if we received a notification of a policy rename from AC + String oldPolicyName = request.getParameter("oldPolicyName"); + String newPolicyName = request.getParameter("newPolicyName"); + if(oldPolicyName != null && newPolicyName != null){ + if(logger.isDebugEnabled()){ + logger.debug("\nXACMLPapServlet.doPut() - before decoding" + + "\npolicyToCreateUpdate = " + " "); + } + //decode it + try{ + oldPolicyName = URLDecoder.decode(oldPolicyName, "UTF-8"); + newPolicyName = URLDecoder.decode(newPolicyName, "UTF-8"); + if(logger.isDebugEnabled()){ + logger.debug("\nXACMLPapServlet.doPut() - after decoding" + + "\npolicyToCreateUpdate = " + " "); + } + } catch(UnsupportedEncodingException e){ + PolicyLogger.error("\nXACMLPapServlet.doPut() - Unsupported URL encoding of policyToCreateUpdate (UTF-8)" + + "\npolicyToCreateUpdate = " + " "); + response.sendError(500,"policyToCreateUpdate encoding not supported" + + "\nfailure with the following exception: " + e); + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Failed - See error.log"); + im.endTransaction(); + return; + } + //send it to PolicyDBDao + PolicyDBDaoTransaction renameTransaction = policyDBDao.getNewTransaction(); + try{ + renameTransaction.renamePolicy(oldPolicyName,newPolicyName, "XACMLPapServlet.doPut"); + }catch(Exception e){ + renameTransaction.rollbackTransaction(); + response.sendError(500,"createUpdateTransaction.createPolicy(policyToCreateUpdate, XACMLPapServlet.doPut) " + + "\nfailure with the following exception: " + e); + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Failed - See error.log"); + im.endTransaction(); + return; + } + renameTransaction.commitTransaction(); + response.setStatus(HttpServletResponse.SC_OK); + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Ended Successfully"); + im.endTransaction(); + return; + } + + + // + // See if this is Admin Console registering itself with us + // + String acURLString = request.getParameter("adminConsoleURL"); + if (acURLString != null) { + loggingContext.setServiceName("AC:PAP.register"); + // + // remember this Admin Console for future updates + // + if ( ! adminConsoleURLStringList.contains(acURLString)) { + adminConsoleURLStringList.add(acURLString); + } + if (logger.isDebugEnabled()) { + logger.debug("Admin Console registering with URL: " + acURLString); + } + response.setStatus(HttpServletResponse.SC_NO_CONTENT); + loggingContext.transactionEnded(); + auditLogger.info("Success"); + PolicyLogger.audit("Transaction Ended Successfully"); + im.endTransaction(); + return; + } + + /* + * This is to update the PDP Group with the policy/policies being pushed + * Part of a 2 step process to push policie to the PDP that can now be done + * From both the Admin Console and the PolicyEngine API + */ + String groupId = request.getParameter("groupId"); + if (groupId != null) { + if(apiflag!=null){ + if(apiflag.equalsIgnoreCase("addPolicyToGroup")){ + updateGroupsFromAPI(request, response, groupId, loggingContext); + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Ended Successfully"); + im.endTransaction(); + return; + } + } + // + // this is from the Admin Console, so handle separately + // + doACPut(request, response, groupId, loggingContext); + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Ended Successfully"); + im.endTransaction(); + return; + } + + // + // Request is for policy validation and creation + // + if (apiflag != null && apiflag.equalsIgnoreCase("admin")){ + /* + * this request is from the Admin Console + */ + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Ended Successfully"); + doACPolicyPut(request, response); + im.endTransaction(); + return; + + } else if (apiflag != null && apiflag.equalsIgnoreCase("api")) { + /* + * this request is from the Policy Creation API + */ + // Authenticating the Request here. + if(authorizeRequest(request)){ + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Ended Successfully"); + doPolicyAPIPut(request, response); + im.endTransaction(); + return; + } else { + String message = "PEP not Authorized for making this Request!! \n Contact Administrator for this Scope. "; + PolicyLogger.error(MessageCodes.ERROR_PERMISSIONS + " " + message); + loggingContext.transactionEnded(); + + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(HttpServletResponse.SC_FORBIDDEN, message); + im.endTransaction(); + return; + } + + } + + + // + // We do not expect anything from anywhere else. + // This method is here in case we ever need to support other operations. + // + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Request does not have groupId or apiflag"); + loggingContext.transactionEnded(); + + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Request does not have groupId or apiflag"); + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Failed - See error.log"); + im.endTransaction(); + } + + /** + * @see HttpServlet#doDelete(HttpServletRequest request, HttpServletResponse response) + */ + protected void doDelete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + ECOMPLoggingContext loggingContext = ECOMPLoggingUtils.getLoggingContextForRequest(request, baseLoggingContext); + loggingContext.transactionStarted(); + loggingContext.setServiceName("PAP.delete"); // we may set a more specific value later + if ((loggingContext.getRequestID() == null) || (loggingContext.getRequestID() == "")){ + UUID requestID = UUID.randomUUID(); + loggingContext.setRequestID(requestID.toString()); + PolicyLogger.info("requestID not provided in call to XACMLPapSrvlet (doDelete) so we generated one"); + } else { + PolicyLogger.info("requestID was provided in call to XACMLPapSrvlet (doDelete)"); + } + loggingContext.metricStarted(); + loggingContext.metricEnded(); + PolicyLogger.metrics("Metric example posted here - 1 of 2"); + loggingContext.metricStarted(); + loggingContext.metricEnded(); + PolicyLogger.metrics("Metric example posted here - 2 of 2"); + + //This im.startTransaction() covers all Delete transactions + try { + im.startTransaction(); + } catch (AdministrativeStateException ae){ + String message = "DELETE interface called for PAP " + papResourceName + " but it has an Administrative" + + " state of " + im.getStateManager().getAdminState() + + "\n Exception Message: " + ae.getMessage(); + logger.info(message); + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + " " + message); + loggingContext.transactionEnded(); + + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message); + return; + }catch (StandbyStatusException se) { + se.printStackTrace(); + String message = "PUT interface called for PAP " + papResourceName + " but it has a Standby Status" + + " of " + im.getStateManager().getStandbyStatus() + + "\n Exception Message: " + se.getMessage(); + logger.info(message); + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + " " + message); + loggingContext.transactionEnded(); + + PolicyLogger.audit("Transaction Failed - See Error.log"); + + response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message); + return; + } + + XACMLRest.dumpRequest(request); + + String groupId = request.getParameter("groupId"); + String apiflag = request.getParameter("apiflag"); + + if (groupId != null) { + // Is this from the Admin Console or API? + if(apiflag!=null) { + if (apiflag.equalsIgnoreCase("deletePapApi")) { + // this is from the API so we need to check the client credentials before processing the request + if(authorizeRequest(request)){ + doAPIDeleteFromPAP(request, response, loggingContext); + return; + } else { + String message = "PEP not Authorized for making this Request!! \n Contact Administrator for this Scope. "; + PolicyLogger.error(MessageCodes.ERROR_PERMISSIONS + " " + message); + loggingContext.transactionEnded(); + + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(HttpServletResponse.SC_FORBIDDEN, message); + return; + } + } else if (apiflag.equalsIgnoreCase("deletePdpApi")) { + if(authorizeRequest(request)){ + doAPIDeleteFromPDP(request, response, loggingContext); + return; + } else { + String message = "PEP not Authorized for making this Request!! \n Contact Administrator for this Scope. "; + PolicyLogger.error(MessageCodes.ERROR_PERMISSIONS + " " + message); + loggingContext.transactionEnded(); + + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(HttpServletResponse.SC_FORBIDDEN, message); + return; + } + } + } + + // this is from the Admin Console, so handle separately + doACDelete(request, response, groupId, loggingContext); + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Ended Successfully"); + im.endTransaction(); + return; + + } + // + // We do not expect anything from anywhere else. + // This method is here in case we ever need to support other operations. + // + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " Request does not have groupId"); + loggingContext.transactionEnded(); + + PolicyLogger.audit("Transaction Failed - See Error.log"); + + response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Request does not have groupId"); + + //Catch anything that fell through + im.endTransaction(); + + } + // + // Admin Console request handling + // + + /** + * Requests from the Admin Console to GET info about the Groups and PDPs + * + * @param request + * @param response + * @param groupId + * @param loggingContext + * @throws ServletException + * @throws IOException + */ + private void doACGet(HttpServletRequest request, HttpServletResponse response, String groupId, ECOMPLoggingContext loggingContext) throws ServletException, IOException { + try { + String parameterDefault = request.getParameter("default"); + String pdpId = request.getParameter("pdpId"); + String pdpGroup = request.getParameter("getPDPGroup"); + if ("".equals(groupId)) { + // request IS from AC but does not identify a group by name + if (parameterDefault != null) { + // Request is for the Default group (whatever its id) + loggingContext.setServiceName("AC:PAP.getDefaultGroup"); + + EcompPDPGroup group = papEngine.getDefaultGroup(); + + // convert response object to JSON and include in the response + ObjectMapper mapper = new ObjectMapper(); + mapper.writeValue(response.getOutputStream(), group); + + if (logger.isDebugEnabled()) { + logger.debug("GET Default group req from '" + request.getRequestURL() + "'"); + } + response.setStatus(HttpServletResponse.SC_OK); + response.setHeader("content-type", "application/json"); + response.getOutputStream().close(); + loggingContext.transactionEnded(); + auditLogger.info("Success"); + PolicyLogger.audit("Transaction Ended Successfully"); + return; + + } else if (pdpId != null) { + // Request is related to a PDP + if (pdpGroup == null) { + // Request is for the PDP itself + // Request is for the (unspecified) group containing a given PDP + loggingContext.setServiceName("AC:PAP.getPDP"); + EcompPDP pdp = papEngine.getPDP(pdpId); + + // convert response object to JSON and include in the response + ObjectMapper mapper = new ObjectMapper(); + mapper.writeValue(response.getOutputStream(), pdp); + + if (logger.isDebugEnabled()) { + logger.debug("GET pdp '" + pdpId + "' req from '" + request.getRequestURL() + "'"); + } + response.setStatus(HttpServletResponse.SC_OK); + response.setHeader("content-type", "application/json"); + response.getOutputStream().close(); + loggingContext.transactionEnded(); + auditLogger.info("Success"); + PolicyLogger.audit("Transaction Ended Successfully"); + return; + + } else { + // Request is for the group containing a given PDP + loggingContext.setServiceName("AC:PAP.getGroupForPDP"); + EcompPDP pdp = papEngine.getPDP(pdpId); + EcompPDPGroup group = papEngine.getPDPGroup((EcompPDP) pdp); + + // convert response object to JSON and include in the response + ObjectMapper mapper = new ObjectMapper(); + mapper.writeValue(response.getOutputStream(), group); + + if (logger.isDebugEnabled()) { + logger.debug("GET PDP '" + pdpId + "' Group req from '" + request.getRequestURL() + "'"); + } + response.setStatus(HttpServletResponse.SC_OK); + response.setHeader("content-type", "application/json"); + response.getOutputStream().close(); + loggingContext.transactionEnded(); + auditLogger.info("Success"); + PolicyLogger.audit("Transaction Ended Successfully"); + return; + } + + } else { + // request is for top-level properties about all groups + loggingContext.setServiceName("AC:PAP.getAllGroups"); + Set groups = papEngine.getEcompPDPGroups(); + + // convert response object to JSON and include in the response + ObjectMapper mapper = new ObjectMapper(); + mapper.writeValue(response.getOutputStream(), groups); + + if (logger.isDebugEnabled()) { + logger.debug("GET All groups req"); + } + response.setStatus(HttpServletResponse.SC_OK); + response.setHeader("content-type", "application/json"); + response.getOutputStream().close(); + loggingContext.transactionEnded(); + auditLogger.info("Success"); + PolicyLogger.audit("Transaction Ended Successfully"); + return; + } + } + + // for all other GET operations the group must exist before the operation can be done + EcompPDPGroup group = papEngine.getGroup(groupId); + if (group == null) { + String message = "Unknown groupId '" + groupId + "'"; + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " " + message); + loggingContext.transactionEnded(); + + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(HttpServletResponse.SC_NOT_FOUND, message); + return; + } + + + // Figure out which request this is based on the parameters + String policyId = request.getParameter("policyId"); + + if (policyId != null) { + // retrieve a policy + loggingContext.setServiceName("AC:PAP.getPolicy"); + // + // convert response object to JSON and include in the response + // + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " GET Policy not implemented"); + loggingContext.transactionEnded(); + + PolicyLogger.audit("Transaction Failed - See Error.log"); + + response.sendError(HttpServletResponse.SC_BAD_REQUEST, "GET Policy not implemented"); + + } else { + // No other parameters, so return the identified Group + loggingContext.setServiceName("AC:PAP.getGroup"); + + // convert response object to JSON and include in the response + ObjectMapper mapper = new ObjectMapper(); + mapper.writeValue(response.getOutputStream(), group); + + if (logger.isDebugEnabled()) { + logger.debug("GET group '" + group.getId() + "' req from '" + request.getRequestURL() + "'"); + } + response.setStatus(HttpServletResponse.SC_OK); + response.setHeader("content-type", "application/json"); + response.getOutputStream().close(); + loggingContext.transactionEnded(); + auditLogger.info("Success"); + PolicyLogger.audit("Transaction Ended Successfully"); + return; + } + + // + // Currently there are no other GET calls from the AC. + // The AC uses the "GET All Groups" operation to fill its local cache and uses that cache for all other GETs without calling the PAP. + // Other GETs that could be called: + // Specific Group (groupId=) + // A Policy (groupId= policyId=) + // A PDP (groupId= pdpId=) + + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " UNIMPLEMENTED "); + loggingContext.transactionEnded(); + + PolicyLogger.audit("Transaction Failed - See Error.log"); + + response.sendError(HttpServletResponse.SC_BAD_REQUEST, "UNIMPLEMENTED"); + } catch (PAPException e) { + PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "XACMLPapServlet", " AC Get exception"); + loggingContext.transactionEnded(); + + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(500, e.getMessage()); + return; + } + + } + + /** + * Requests from the Admin Console for validating and creating policies + * + * @param request + * @param response + * @param groupId + * @throws JsonMappingException + * @throws JsonParseException + * @throws ServletException + * @throws IOException + */ + private void doACPolicyPut(HttpServletRequest request, + HttpServletResponse response) throws JsonParseException, JsonMappingException, IOException { + + String operation = request.getParameter("operation"); + String policyType = request.getParameter("policyType"); + String apiflag = request.getParameter("apiflag"); + + if ( policyType != null ) { + PolicyRestAdapter policyAdapter = new PolicyRestAdapter(); + Policy newPolicy = null; + // get the request content into a String + String json = null; + // read the inputStream into a buffer (trick found online scans entire input looking for end-of-file) + java.util.Scanner scanner = new java.util.Scanner(request.getInputStream()); + scanner.useDelimiter("\\A"); + json = scanner.hasNext() ? scanner.next() : ""; + scanner.close(); + logger.info("JSON request from AC: " + json); + // convert Object sent as JSON into local object + ObjectMapper mapper = new ObjectMapper(); + Object objectFromJSON = mapper.readValue(json, StdPAPPolicy.class); + + StdPAPPolicy policy = (StdPAPPolicy) objectFromJSON; + + //Set policyAdapter values including parentPath (Common to all policy types) + //Set values for policy adapter + try { + if (operation.equalsIgnoreCase("validate")) { + policyAdapter.setPolicyName(policy.getPolicyName()); + policyAdapter.setConfigType(policy.getConfigType()); + policyAdapter.setConfigBodyData(policy.getConfigBodyData()); + } else { + policyAdapter = setDataToPolicyAdapter(policy, policyType, apiflag); + } + } catch (Exception e1) { + logger.error("Exception occured While Setting Values for Policy Adapter"+e1); + } + // Calling Component class per policy type + if (policyType.equalsIgnoreCase("Config")) { + String configPolicyType = policy.getConfigPolicyType(); + if (configPolicyType != null && configPolicyType.equalsIgnoreCase("Firewall Config")) { + newPolicy = new FirewallConfigPolicy(policyAdapter); + } + else if (configPolicyType != null && configPolicyType.equalsIgnoreCase("BRMS_Raw")) { + newPolicy = new CreateBrmsRawPolicy(policyAdapter); + }else if (configPolicyType != null && configPolicyType.equalsIgnoreCase("BRMS_Param")) { + policyAdapter.setBrmsParamBody(policy.getDrlRuleAndUIParams()); + newPolicy = new CreateBrmsParamPolicy(policyAdapter); + } + else if (configPolicyType != null && configPolicyType.equalsIgnoreCase("Base")) { + newPolicy = new ConfigPolicy(policyAdapter); + }else if (configPolicyType != null && configPolicyType.equalsIgnoreCase("ClosedLoop_Fault")) { + newPolicy = new ClosedLoopPolicy(policyAdapter); + }else if (configPolicyType != null && configPolicyType.equalsIgnoreCase("ClosedLoop_PM")) { + newPolicy = new CreateClosedLoopPerformanceMetrics(policyAdapter); + }else if (configPolicyType != null && configPolicyType.equalsIgnoreCase("DCAE Micro Service")) { + newPolicy = new MicroServiceConfigPolicy(policyAdapter); + } + + } else if (policyType.equalsIgnoreCase("Action")) { + newPolicy = new ActionPolicy(policyAdapter); + } else if (policyType.equalsIgnoreCase("Decision")) { + newPolicy = new DecisionPolicy(policyAdapter); + } + + // Validation + if (operation != null && operation.equalsIgnoreCase("validate")) { + + // validate the body data if applicable and return a response to the PAP-ADMIN (Config Base only) + if (newPolicy.validateConfigForm()) { + response.setStatus(HttpServletResponse.SC_OK); + response.addHeader("isValidData", "true"); + } else { + response.setStatus(HttpServletResponse.SC_OK); + response.addHeader("isValidData", "false"); + } + + } + + // Create or Update Policy + if (operation != null && (operation.equalsIgnoreCase("create") || operation.equalsIgnoreCase("update"))) { + + // create the policy and return a response to the PAP-ADMIN + PolicyDBDaoTransaction policyDBDaoTransaction = policyDBDao.getNewTransaction(); + try { + Map successMap; + newPolicy.prepareToSave(); + policyDBDaoTransaction.createPolicy(newPolicy, "doACPolicyPut"); + successMap = newPolicy.savePolicies(); + if (successMap.containsKey("success")) { + policyDBDaoTransaction.commitTransaction(); + response.setStatus(HttpServletResponse.SC_OK); + response.addHeader("successMapKey", "success"); + response.addHeader("finalPolicyPath", policyAdapter.getFinalPolicyPath()); + } else { + policyDBDaoTransaction.rollbackTransaction(); + response.setStatus(HttpServletResponse.SC_OK); + } + } catch (Exception e) { + policyDBDaoTransaction.rollbackTransaction(); + PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "XACMLPapServlet", " Could not save policy "); + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + } + } + + } + + } + + private void doPolicyAPIPut(HttpServletRequest request, + HttpServletResponse response) throws IOException, ServletException { + String operation = request.getParameter("operation"); + String policyType = request.getParameter("policyType"); + String apiflag = request.getParameter("apiflag"); + + + if ( policyType != null ) { + PolicyRestAdapter policyAdapter = new PolicyRestAdapter(); + Policy newPolicy = null; + + // get the request content into a String + String json = null; + + // read the inputStream into a buffer (trick found online scans entire input looking for end-of-file) + java.util.Scanner scanner = new java.util.Scanner(request.getInputStream()); + scanner.useDelimiter("\\A"); + json = scanner.hasNext() ? scanner.next() : ""; + scanner.close(); + logger.info("JSON request from API: " + json); + + // convert Object sent as JSON into local object + ObjectMapper mapper = new ObjectMapper(); + + Object objectFromJSON = mapper.readValue(json, StdPAPPolicy.class); + + StdPAPPolicy policy = (StdPAPPolicy) objectFromJSON; + + //Set policyAdapter values including parentPath (Common to all policy types) + try { + policyAdapter = setDataToPolicyAdapter(policy, policyType, apiflag); + } catch (Exception e1) { + logger.error(XACMLErrorConstants.ERROR_UNKNOWN + + "Could not set data to policy adapter ",e1); + } + + // Calling Component class per policy type + if (policyType.equalsIgnoreCase("Config")) { + String configPolicyType = policy.getConfigPolicyType(); + if (configPolicyType != null && configPolicyType.equalsIgnoreCase("Firewall Config")) { + + newPolicy = new FirewallConfigPolicy(policyAdapter); + + } + else if (configPolicyType != null && configPolicyType.equalsIgnoreCase("BRMS_Raw")) { + + newPolicy = new CreateBrmsRawPolicy(policyAdapter); + + }else if (configPolicyType != null && configPolicyType.equalsIgnoreCase("BRMS_Param")) { + + policyAdapter.setBrmsParamBody(policy.getDrlRuleAndUIParams()); + //check for valid actionAttributes + //Setup EntityManager to communicate with the PolicyVersion table of the DB + EntityManager em = null; + em = (EntityManager) emf.createEntityManager(); + + Map ruleAndUIValue=policyAdapter.getBrmsParamBody(); + String modelName= ruleAndUIValue.get("templateName"); + logger.info("Template name from API is: "+modelName); + + Query getModel = em.createNamedQuery("BRMSParamTemplate.findAll"); + List modelList = getModel.getResultList(); + Boolean isValidService = false; + for (Object id : modelList) { + BRMSParamTemplate value = (BRMSParamTemplate)id; + logger.info("Template value from dictionary is: "+value); + if (modelName.equals(value.getRuleName())) { + isValidService = true; + break; + } + } + + em.close(); + + if (isValidService) { + newPolicy = new CreateBrmsParamPolicy(policyAdapter); + } else { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Invalid Template. The template name, " + + modelName + + " was not found in the dictionary."); + response.addHeader("error", "missingTemplate"); + response.addHeader("modelName", modelName); + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + return; + } + } + else if (configPolicyType != null && configPolicyType.equalsIgnoreCase("Base")) { + + newPolicy = new ConfigPolicy(policyAdapter); + + }else if (configPolicyType != null && configPolicyType.equalsIgnoreCase("ClosedLoop_Fault")) { + + newPolicy = new ClosedLoopPolicy(policyAdapter); + + }else if (configPolicyType != null && configPolicyType.equalsIgnoreCase("ClosedLoop_PM")) { + + newPolicy = new CreateClosedLoopPerformanceMetrics(policyAdapter); + + }else if (configPolicyType != null && configPolicyType.equalsIgnoreCase("DCAE Micro Service")) { + + //check for valid actionAttributes + //Setup EntityManager to communicate with the PolicyVersion table of the DB + EntityManager em = null; + em = (EntityManager) emf.createEntityManager(); + + String modelName = policy.getServiceType(); + String modelVersion = policy.getVersion(); + + Query getModel = em.createNamedQuery("MicroServiceModels.findAll"); + List modelList = getModel.getResultList(); + Boolean isValidService = false; + for (Object id : modelList) { + MicroServiceModels value = (MicroServiceModels)id; + if (modelName.equals(value.getModelName()) && modelVersion.equals(value.getVersion())) { + isValidService = true; + break; + } + } + + em.close(); + + if (isValidService) { + newPolicy = new MicroServiceConfigPolicy(policyAdapter); + } else { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Invalid Service or Version. The Service Model, " + + modelName + " of version " + modelVersion + + " was not found in the dictionary."); + response.addHeader("error", "serviceModelDB"); + response.addHeader("modelName", modelName); + response.addHeader("modelVersion", modelVersion); + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + return; + } + + } + + } else if (policyType.equalsIgnoreCase("Action")) { + + //check for valid actionAttributes + //Setup EntityManager to communicate with the PolicyVersion table of the DB + EntityManager em = null; + em = (EntityManager) emf.createEntityManager(); + + String attributeName = policy.getActionAttribute(); + + Query getActionAttributes = em.createNamedQuery("ActionPolicyDict.findAll"); + List actionAttributesList = getActionAttributes.getResultList(); + Boolean isAttribute = false; + for (Object id : actionAttributesList) { + ActionPolicyDict value = (ActionPolicyDict)id; + if (attributeName.equals(value.getAttributeName())) { + isAttribute = true; + break; + } + } + + em.close(); + + if (isAttribute) { + newPolicy = new ActionPolicy(policyAdapter); + } else { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Could not fine " + attributeName + " in the ActionPolicyDict table."); + response.addHeader("error", "actionPolicyDB"); + response.addHeader("actionAttribute", attributeName); + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + return; + } + + } else if (policyType.equalsIgnoreCase("Decision")) { + + newPolicy = new DecisionPolicy(policyAdapter); + + } + + // Create or Update Policy + if (operation != null && (operation.equalsIgnoreCase("create") || operation.equalsIgnoreCase("update"))) { + + // create the policy and return a response to the PAP-ADMIN + if (newPolicy.validateConfigForm()) { + PolicyDBDaoTransaction policyDBDaoTransaction = policyDBDao.getNewTransaction(); + try { + + // added check for existing policy when new policy is created to + // unique API error for "policy already exists" + Boolean isNewPolicy = newPolicy.prepareToSave(); + if(isNewPolicy){ + policyDBDaoTransaction.createPolicy(newPolicy, "doPolicyAPIPut"); + } + Map successMap = newPolicy.savePolicies(); + if (successMap.containsKey("success")) { + + EntityManager apiEm = null; + apiEm = (EntityManager) emf.createEntityManager(); + // + // Did it get created? + // + if (apiEm == null) { + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " Error creating entity manager with persistence unit: " + PERSISTENCE_UNIT); + ServletException e = new ServletException("Unable to create Entity Manager Factory"); + e.printStackTrace(); + throw e; + } + + String finalPath = policyAdapter.getFinalPolicyPath(); + // + //Check the database entry if a scope is available in PolicyEditorScope table or not. + //If not exists create a new entry. + // + String dirName = finalPath.toString().substring(finalPath.toString().indexOf("repository")+11, finalPath.toString().lastIndexOf(File.separator)); + apiEm.getTransaction().begin(); + Query query = apiEm.createQuery("Select p from PolicyEditorScopes p where p.scopeName=:sname"); + query.setParameter("sname", dirName); + + @SuppressWarnings("rawtypes") + List result = query.getResultList(); + if(result.isEmpty()){ + PolicyEditorScopes scopeEntity = new PolicyEditorScopes(); + scopeEntity.setScopeName(dirName); + UserInfo user = new UserInfo(); + user.setUserLoginId("API"); + user.setUserName("API"); + scopeEntity.setUserCreatedBy(user); + scopeEntity.setUserModifiedBy(user); + try{ + apiEm.persist(scopeEntity); + apiEm.getTransaction().commit(); + }catch(Exception e){ + PolicyLogger.error("Exception Occured while inserting a new Entry to PolicyEditorScopes table"+e); + apiEm.getTransaction().rollback(); + }finally{ + apiEm.close(); + } + }else{ + PolicyLogger.info("Scope Already Exists in PolicyEditorScopes table, Hence Closing the Transaction"); + apiEm.close(); + } + + policyDBDaoTransaction.commitTransaction(); + response.setStatus(HttpServletResponse.SC_OK); + response.addHeader("successMapKey", "success"); + response.addHeader("policyName", policyAdapter.getPolicyName()); + + if (operation.equalsIgnoreCase("update")) { + response.addHeader("operation", "update"); + } else { + response.addHeader("operation", "create"); + } + } else if (successMap.containsKey("EXISTS")) { + policyDBDaoTransaction.rollbackTransaction(); + response.setStatus(HttpServletResponse.SC_CONFLICT); + response.addHeader("error", "policyExists"); + response.addHeader("policyName", policyAdapter.getPolicyName()); + } else if (successMap.containsKey("fwdberror")) { + policyDBDaoTransaction.rollbackTransaction(); + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + response.addHeader("error", "FWDBError"); + response.addHeader("policyName", policyAdapter.getPolicyName()); + }else { + policyDBDaoTransaction.rollbackTransaction(); + response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); + response.addHeader("error", "error"); + } + } catch (Exception e) { + policyDBDaoTransaction.rollbackTransaction(); + String message = XACMLErrorConstants.ERROR_PROCESS_FLOW + + "Could not save policy " + e; + PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "XACMLPapServlet", " Could not save policy"); + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + response.addHeader("error", "savePolicy"); + response.addHeader("message", message); + } + } + } + } + } + + private PolicyRestAdapter setDataToPolicyAdapter(StdPAPPolicy policy, String policyType, String apiflag) throws Exception { + PolicyRestAdapter policyAdapter = new PolicyRestAdapter(); + int highestVersion = 0; + + if (policy.getHighestVersion()!=null) { + highestVersion = policy.getHighestVersion(); + } + + EntityManager apiEm = null; + apiEm = (EntityManager) emf.createEntityManager(); + + // + // Did it get created? + // + if (apiEm == null) { + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + + " Error creating entity manager with persistence unit: " + + PERSISTENCE_UNIT); + throw new ServletException("Unable to create Entity Manager Factory"); + } + + Path workspacePath = Paths.get(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_WORKSPACE), "admin"); + Path repositoryPath = Paths.get(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_REPOSITORY)); + Path gitPath = Paths.get(workspacePath.toString(), repositoryPath.getFileName().toString()); + + /* + * Getting and Setting the parent path for Admin Console use when reading the policy files + */ + //domain chosen by the client to store the policy action files + String domain = policy.getDomainDir(); + + //adding the domain to the gitPath + Path path; + String gitPathString = gitPath.toString(); + + if (gitPathString.contains("\\")) { + path = Paths.get(gitPath + "\\" + policy.getDomainDir()); + } else { + path = Paths.get(gitPath + "/" + policy.getDomainDir()); + + } + logger.debug("path is: " + path.toString()); + + //getting the fullpath of the gitPath and convert to string + String policyDir = path.toAbsolutePath().toString(); + String parentPath = null; + + //creating the parentPath directory for the Admin Console use + File file; + if(policyDir.contains("\\")) + { + parentPath = policyDir.replace("ECOMP-PAP-REST", "ecomp-sdk-app"); + file = new File(parentPath); + } + else + { + parentPath = policyDir.replace("pap", "console"); + file = new File(parentPath); + + } + + //Get the policy file from the git repository + String filePrefix = null; + if (policyType.equalsIgnoreCase("Config")) { + if (policy.getConfigPolicyType().equalsIgnoreCase("Firewall Config")) { + filePrefix = "Config_FW_"; + }else if (policy.getConfigPolicyType().equalsIgnoreCase("ClosedLoop_Fault")) { + filePrefix = "Config_Fault_"; + }else if (policy.getConfigPolicyType().equalsIgnoreCase("ClosedLoop_PM")) { + filePrefix = "Config_PM_"; + }else if (policy.getConfigPolicyType().equalsIgnoreCase("DCAE Micro Service")) { + filePrefix = "Config_MS_"; + } else if (policy.getConfigPolicyType().equalsIgnoreCase("BRMS_Raw")) { + filePrefix = "Config_BRMS_Raw_"; + } else if (policy.getConfigPolicyType().equalsIgnoreCase("BRMS_Param")) { + filePrefix = "Config_BRMS_Param_"; + } + else { + filePrefix = "Config_"; + } + } else if (policyType.equalsIgnoreCase("Action")) { + filePrefix = "Action_"; + } else if (policyType.equalsIgnoreCase("Decision")) { + filePrefix = "Decision_"; + } + + + String pvName = domain + File.separator + filePrefix + policy.getPolicyName(); + + //create the directory if it does not exist + Boolean fileDir=true; + if (!file.exists()){ + fileDir = new File(parentPath).mkdirs(); + } + + //set the parent path in the policy adapter + if (!fileDir){ + logger.debug("Unable to create the policy directory"); + } + + logger.debug("ParentPath is: " + parentPath.toString()); + policyAdapter.setParentPath(parentPath.toString()); + policyAdapter.setApiflag(apiflag); + + if (policy.isEditPolicy()) { + + if(apiflag.equalsIgnoreCase("api")) { + + //Get the Highest Version to Update + apiEm.getTransaction().begin(); + Query query = apiEm.createQuery("Select p from PolicyVersion p where p.policyName=:pname"); + query.setParameter("pname", pvName); + + @SuppressWarnings("rawtypes") + List result = query.getResultList(); + PolicyVersion versionEntity = null; + if (!result.isEmpty()) { + versionEntity = (PolicyVersion) result.get(0); + apiEm.persist(versionEntity); + highestVersion = versionEntity.getHigherVersion(); + int activeVersion = versionEntity.getActiveVersion(); + + Calendar calendar = Calendar.getInstance(); + Timestamp modifyDate = new Timestamp(calendar.getTime().getTime()); + + //update table with highestVersion + try{ + versionEntity.setHigherVersion(highestVersion+1); + versionEntity.setActiveVersion(activeVersion+1); + versionEntity.setCreatedBy("API"); + versionEntity.setModifiedBy("API"); + versionEntity.setModifiedDate(modifyDate); + + apiEm.getTransaction().commit(); + + }catch(Exception e){ + apiEm.getTransaction().rollback(); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "XACMLPapServlet", " ERROR"); + } finally { + apiEm.close(); + } + } else { + logger.debug("\nNo PolicyVersion using policyName found"); + } + + } + + File policyFile = null; + if(policy.getOldPolicyFileName() != null && policy.getOldPolicyFileName().endsWith("Draft.1")) { + policyFile = new File(parentPath.toString() + File.separator + policy.getOldPolicyFileName() + ".xml"); + } else { + policyFile = new File(parentPath.toString() + File.separator + filePrefix + policy.getPolicyName() +"."+(highestVersion)+ ".xml"); + } + + if (policyFile.exists()) { + DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); + Document doc = dBuilder.parse(policyFile); + + doc.getDocumentElement().normalize(); + + String version = doc.getDocumentElement().getAttribute("Version"); + + NodeList rList = doc.getElementsByTagName("Rule"); + Node rNode = rList.item(0); + Element rElement = (Element) rNode; + + String ruleID = null; + if (rNode!=null){ + ruleID = rElement.getAttribute("RuleId"); + } else { + ruleID = newRuleID(); + } + + policyAdapter.setPolicyID(newPolicyID()); + policyAdapter.setRuleID(ruleID); + policyAdapter.setVersion(version); + + } else { + PolicyLogger.error(MessageCodes.ERROR_UNKNOWN + " The policy file at the path " + policyFile + " does not exist."); + } + + } else { + + highestVersion = 1; + if (apiflag.equalsIgnoreCase("api")) { + Calendar calendar = Calendar.getInstance(); + Timestamp createdDate = new Timestamp(calendar.getTime().getTime()); + + apiEm.getTransaction().begin(); + Query query = apiEm.createQuery("Select p from PolicyVersion p where p.policyName=:pname"); + query.setParameter("pname", pvName); + + @SuppressWarnings("rawtypes") + List result = query.getResultList(); + + if (result.isEmpty()) { + + try{ + PolicyVersion versionEntity = new PolicyVersion(); + apiEm.persist(versionEntity); + versionEntity.setPolicyName(pvName); + versionEntity.setHigherVersion(highestVersion); + versionEntity.setActiveVersion(highestVersion); + versionEntity.setCreatedBy("API"); + versionEntity.setModifiedBy("API"); + versionEntity.setCreatedDate(createdDate); + versionEntity.setModifiedDate(createdDate); + + apiEm.getTransaction().commit(); + + }catch(Exception e){ + apiEm.getTransaction().rollback(); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "XACMLPapServlet", " ERROR"); + } finally { + apiEm.close(); + } + } + } + + policyAdapter.setPolicyID(newPolicyID()); + policyAdapter.setRuleID(newRuleID()); + + } + + /* + * set policy adapter values for Building JSON object containing policy data + */ + //Common among policy types + policyAdapter.setPolicyName(policy.getPolicyName()); + policyAdapter.setPolicyDescription(policy.getPolicyDescription()); + policyAdapter.setEcompName(policy.getEcompName()); //Config Base and Decision Policies + policyAdapter.setHighestVersion(highestVersion); + policyAdapter.setRuleCombiningAlgId("urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:permit-overrides"); + policyAdapter.setUserGitPath(gitPath.toString()); + policyAdapter.setPolicyType(policyType); + policyAdapter.setDynamicFieldConfigAttributes(policy.getDynamicFieldConfigAttributes()); + policyAdapter.setEditPolicy(policy.isEditPolicy()); + policyAdapter.setEntityManagerFactory(getEmf()); + + + //Config Specific + policyAdapter.setConfigName(policy.getConfigName()); //Base and Firewall + policyAdapter.setConfigBodyData(policy.getConfigBodyData()); //Base + policyAdapter.setConfigType(policy.getConfigType()); //Base + policyAdapter.setJsonBody(policy.getJsonBody()); //Firewall, ClosedLoop, and GoC + policyAdapter.setConfigPolicyType(policy.getConfigPolicyType()); + policyAdapter.setDraft(policy.isDraft()); //ClosedLoop_Fault + policyAdapter.setServiceType(policy.getServiceType()); //ClosedLoop_PM + policyAdapter.setUuid(policy.getUuid()); //Micro Service + policyAdapter.setLocation(policy.getMsLocation()); //Micro Service + policyAdapter.setPriority(policy.getPriority()); //Micro Service + policyAdapter.setPolicyScope(policy.getDomainDir()); + policyAdapter.setRiskType(policy.getRiskType()); //Safe Policy Attributes + policyAdapter.setRiskLevel(policy.getRiskLevel());//Safe Policy Attributes + policyAdapter.setGuard(policy.getGuard());//Safe Policy Attributes + policyAdapter.setTtlDate(policy.getTTLDate());//Safe Policy Attributes + + //Action Policy Specific + policyAdapter.setActionAttribute(policy.getActionAttribute()); //comboDictValue + policyAdapter.setActionPerformer(policy.getActionPerformer()); + policyAdapter.setDynamicRuleAlgorithmLabels(policy.getDynamicRuleAlgorithmLabels()); + policyAdapter.setDynamicRuleAlgorithmCombo(policy.getDynamicRuleAlgorithmCombo()); + policyAdapter.setDynamicRuleAlgorithmField1(policy.getDynamicRuleAlgorithmField1()); + policyAdapter.setDynamicRuleAlgorithmField2(policy.getDynamicRuleAlgorithmField2()); + + //Decision Policy Specific + policyAdapter.setDynamicSettingsMap(policy.getDynamicSettingsMap()); + policyAdapter.setProviderComboBox(policy.getProviderComboBox()); + + return policyAdapter; + } + + public String newPolicyID() { + return Joiner.on(':').skipNulls().join((XACMLPapServlet.getDomain().startsWith("urn") ? null : "urn"), + XACMLPapServlet.getDomain().replaceAll("[/\\\\.]", ":"), + "xacml", "policy", "id", UUID.randomUUID()); + } + + public String newRuleID() { + return Joiner.on(':').skipNulls().join((XACMLPapServlet.getDomain().startsWith("urn") ? null : "urn"), + XACMLPapServlet.getDomain().replaceAll("[/\\\\.]", ":"), + "xacml", "rule", "id", UUID.randomUUID()); + } + + public static String getDomain() { + return XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_DOMAIN, "urn"); + } + + + /** + * Requests from the Admin Console for operations not on single specific objects + * + * @param request + * @param response + * @param groupId + * @param loggingContext + * @throws ServletException + * @throws IOException + */ + private void doACPost(HttpServletRequest request, HttpServletResponse response, String groupId, ECOMPLoggingContext loggingContext) throws ServletException, IOException { + PolicyDBDaoTransaction doACPostTransaction = null; + + try { + String groupName = request.getParameter("groupName"); + String groupDescription = request.getParameter("groupDescription"); + String apiflag = request.getParameter("apiflag"); + + if (groupName != null && groupDescription != null) { + // Args: group= groupName= groupDescription= <= create a new group + loggingContext.setServiceName("AC:PAP.createGroup"); + + String unescapedName = URLDecoder.decode(groupName, "UTF-8"); + String unescapedDescription = URLDecoder.decode(groupDescription, "UTF-8"); + PolicyDBDaoTransaction newGroupTransaction = policyDBDao.getNewTransaction(); + try { + newGroupTransaction.createGroup(PolicyDBDao.createNewPDPGroupId(unescapedName), unescapedName, unescapedDescription,"XACMLPapServlet.doACPost"); + papEngine.newGroup(unescapedName, unescapedDescription); + newGroupTransaction.commitTransaction(); + } catch (Exception e) { + newGroupTransaction.rollbackTransaction(); + PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "XACMLPapServlet", " Unable to create new group"); + loggingContext.transactionEnded(); + + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(500, "Unable to create new group '" + groupId + "'"); + return; + } + response.setStatus(HttpServletResponse.SC_NO_CONTENT); + if (logger.isDebugEnabled()) { + logger.debug("New Group '" + groupId + "' created"); + } + // tell the Admin Consoles there is a change + notifyAC(); + // new group by definition has no PDPs, so no need to notify them of changes + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Failed - See Error.log"); + auditLogger.info("Success"); + PolicyLogger.audit("Transaction Ended Successfully"); + return; + } + + // for all remaining POST operations the group must exist before the operation can be done + EcompPDPGroup group = papEngine.getGroup(groupId); + if (group == null) { + String message = "Unknown groupId '" + groupId + "'"; + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " " + message); + loggingContext.transactionEnded(); + + PolicyLogger.audit("Transaction Failed - See Error.log"); + if (apiflag!=null){ + response.addHeader("error", "unknownGroupId"); + response.addHeader("operation", "push"); + response.addHeader("message", message); + response.setStatus(HttpServletResponse.SC_NOT_FOUND); + } else { + response.sendError(HttpServletResponse.SC_NOT_FOUND, message); + } + return; + } + + // determine the operation needed based on the parameters in the request + if (request.getParameter("policyId") != null) { + // Args: group= policy= <= copy file + // copy a policy from the request contents into a file in the group's directory on this machine + if(apiflag!=null){ + loggingContext.setServiceName("PolicyEngineAPI:PAP.postPolicy"); + } else { + loggingContext.setServiceName("AC:PAP.postPolicy"); + } + + String policyId = request.getParameter("policyId"); + PolicyDBDaoTransaction addPolicyToGroupTransaction = policyDBDao.getNewTransaction(); + try { + InputStream is = null; + if (apiflag != null){ + // get the request content into a String if the request is from API + String json = null; + // read the inputStream into a buffer (trick found online scans entire input looking for end-of-file) + java.util.Scanner scanner = new java.util.Scanner(request.getInputStream()); + scanner.useDelimiter("\\A"); + json = scanner.hasNext() ? scanner.next() : ""; + scanner.close(); + logger.info("JSON request from API: " + json); + + // convert Object sent as JSON into local object + ObjectMapper mapper = new ObjectMapper(); + + Object objectFromJSON = mapper.readValue(json, StdPAPPolicy.class); + + StdPAPPolicy policy = (StdPAPPolicy) objectFromJSON; + + is = new FileInputStream(new File(policy.getLocation())); + } else { + is = request.getInputStream(); + + } + + addPolicyToGroupTransaction.addPolicyToGroup(group.getId(), policyId,"XACMLPapServlet.doACPost"); + ((StdPDPGroup) group).copyPolicyToFile(policyId, is); + addPolicyToGroupTransaction.commitTransaction(); + + } catch (Exception e) { + addPolicyToGroupTransaction.rollbackTransaction(); + String message = "Policy '" + policyId + "' not copied to group '" + groupId +"': " + e; + PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW + " " + message); + loggingContext.transactionEnded(); + + PolicyLogger.audit("Transaction Failed - See Error.log"); + + if (apiflag!=null){ + response.addHeader("error", "policyCopyError"); + response.addHeader("message", message); + response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); + } else { + response.sendError(500, message); + } + return; + } + + // policy file copied ok and the Group was updated on the PDP + response.setStatus(HttpServletResponse.SC_NO_CONTENT); + response.addHeader("operation", "push"); + response.addHeader("policyId", policyId); + response.addHeader("groupId", groupId); + if (logger.isDebugEnabled()) { + logger.debug("policy '" + policyId + "' copied to directory for group '" + groupId + "'"); + } + + loggingContext.transactionEnded(); + auditLogger.info("Success"); + PolicyLogger.audit("Transaction Ended Successfully"); + return; + + } else if (request.getParameter("default") != null) { + // Args: group= default=true <= make default + // change the current default group to be the one identified in the request. + loggingContext.setServiceName("AC:PAP.setDefaultGroup"); + // + // This is a POST operation rather than a PUT "update group" because of the side-effect that the current default group is also changed. + // It should never be the case that multiple groups are currently marked as the default, but protect against that anyway. + PolicyDBDaoTransaction setDefaultGroupTransaction = policyDBDao.getNewTransaction(); + try { + setDefaultGroupTransaction.changeDefaultGroup(group, "XACMLPapServlet.doACPost"); + papEngine.SetDefaultGroup(group); + setDefaultGroupTransaction.commitTransaction(); + } catch (Exception e) { + setDefaultGroupTransaction.rollbackTransaction(); + PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "XACMLPapServlet", " Unable to set group"); + loggingContext.transactionEnded(); + + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(500, "Unable to set group '" + groupId + "' to default"); + return; + } + + response.setStatus(HttpServletResponse.SC_NO_CONTENT); + if (logger.isDebugEnabled()) { + logger.debug("Group '" + groupId + "' set to be default"); + } + // Notify the Admin Consoles that something changed + // For now the AC cannot handle anything more detailed than the whole set of PDPGroups, so just notify on that + //TODO - Future: FIGURE OUT WHAT LEVEL TO NOTIFY: 2 groups or entire set - currently notify AC to update whole configuration of all groups + notifyAC(); + // This does not affect any PDPs in the existing groups, so no need to notify them of this change + loggingContext.transactionEnded(); + auditLogger.info("Success"); + PolicyLogger.audit("Transaction Ended Successfully"); + return; + + } else if (request.getParameter("pdpId") != null) { + doACPostTransaction = policyDBDao.getNewTransaction(); + // Args: group= pdpId= <= move PDP to group + loggingContext.setServiceName("AC:PAP.movePDP"); + + String pdpId = request.getParameter("pdpId"); + EcompPDP pdp = papEngine.getPDP(pdpId); + + EcompPDPGroup originalGroup = papEngine.getPDPGroup((EcompPDP) pdp); + try{ + doACPostTransaction.movePdp(pdp, group, "XACMLPapServlet.doACPost"); + }catch(Exception e){ + PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "XACMLPapServlet", + " Error while moving pdp in the database: " + +"pdp="+pdp.getId()+",to group="+group.getId()); + throw new PAPException(e.getMessage()); + } + papEngine.movePDP((EcompPDP) pdp, group); + + response.setStatus(HttpServletResponse.SC_NO_CONTENT); + if (logger.isDebugEnabled()) { + logger.debug("PDP '" + pdp.getId() +"' moved to group '" + group.getId() + "' set to be default"); + } + + // update the status of both the original group and the new one + ((StdPDPGroup)originalGroup).resetStatus(); + ((StdPDPGroup)group).resetStatus(); + + // Notify the Admin Consoles that something changed + // For now the AC cannot handle anything more detailed than the whole set of PDPGroups, so just notify on that + notifyAC(); + // Need to notify the PDP that it's config may have changed + pdpChanged(pdp); + doACPostTransaction.commitTransaction(); + loggingContext.transactionEnded(); + auditLogger.info("Success"); + PolicyLogger.audit("Transaction Ended Successfully"); + return; + + + } + } catch (PAPException e) { + if(doACPostTransaction != null){ + doACPostTransaction.rollbackTransaction(); + } + PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "XACMLPapServlet", " AC POST exception"); + loggingContext.transactionEnded(); + + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(500, e.getMessage()); + return; + } + } + + /** + * Requests from the Admin Console to create new items or update existing ones + * + * @param request + * @param response + * @param groupId + * @param loggingContext + * @throws ServletException + * @throws IOException + */ + private void doACPut(HttpServletRequest request, HttpServletResponse response, String groupId, ECOMPLoggingContext loggingContext) throws ServletException, IOException { + PolicyDBDaoTransaction acPutTransaction = policyDBDao.getNewTransaction(); + try { + + + // for PUT operations the group may or may not need to exist before the operation can be done + EcompPDPGroup group = papEngine.getGroup(groupId); + + // determine the operation needed based on the parameters in the request + + // for remaining operations the group must exist before the operation can be done + if (group == null) { + String message = "Unknown groupId '" + groupId + "'"; + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " " + message); + loggingContext.transactionEnded(); + + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(HttpServletResponse.SC_NOT_FOUND, message); + return; + } + if (request.getParameter("policy") != null) { + // group= policy= contents=policy file <= Create new policy file in group dir, or replace it if it already exists (do not touch properties) + loggingContext.setServiceName("AC:PAP.putPolicy"); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " PARTIALLY IMPLEMENTED!!! ACTUAL CHANGES SHOULD BE MADE BY PAP SERVLET!!! "); + response.setStatus(HttpServletResponse.SC_NO_CONTENT); + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Failed - See Error.log"); + auditLogger.info("Success"); + PolicyLogger.audit("Transaction Ended Successfully"); + return; + } else if (request.getParameter("pdpId") != null) { + // ARGS: group= pdpId= <= create a new PDP or Update an Existing one + + String pdpId = request.getParameter("pdpId"); + if (papEngine.getPDP(pdpId) == null) { + loggingContext.setServiceName("AC:PAP.createPDP"); + } else { + loggingContext.setServiceName("AC:PAP.updatePDP"); + } + + // get the request content into a String + String json = null; + // read the inputStream into a buffer (trick found online scans entire input looking for end-of-file) + java.util.Scanner scanner = new java.util.Scanner(request.getInputStream()); + scanner.useDelimiter("\\A"); + json = scanner.hasNext() ? scanner.next() : ""; + scanner.close(); + logger.info("JSON request from AC: " + json); + + // convert Object sent as JSON into local object + ObjectMapper mapper = new ObjectMapper(); + + Object objectFromJSON = mapper.readValue(json, StdPDP.class); + + if (pdpId == null || + objectFromJSON == null || + ! (objectFromJSON instanceof StdPDP) || + ((StdPDP)objectFromJSON).getId() == null || + ! ((StdPDP)objectFromJSON).getId().equals(pdpId)) { + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " PDP new/update had bad input. pdpId=" + pdpId + " objectFromJSON="+objectFromJSON); + loggingContext.transactionEnded(); + + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(500, "Bad input, pdpid="+pdpId+" object="+objectFromJSON); + } + StdPDP pdp = (StdPDP) objectFromJSON; + + if (papEngine.getPDP(pdpId) == null) { + // this is a request to create a new PDP object + try{ + acPutTransaction.addPdpToGroup(pdp.getId(), group.getId(), pdp.getName(), pdp.getDescription(), pdp.getJmxPort(),"XACMLPapServlet.doACPut"); + } catch(Exception e){ + PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "XACMLPapServlet", " Error while adding pdp to group in the database: " + +"pdp="+pdp.getId()+",to group="+group.getId()); + throw new PAPException(e.getMessage()); + } + papEngine.newPDP(pdp.getId(), group, pdp.getName(), pdp.getDescription(), pdp.getJmxPort()); + } else { + try{ + acPutTransaction.updatePdp(pdp, "XACMLPapServlet.doACPut"); + } catch(Exception e){ + PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "XACMLPapServlet", " Error while updating pdp in the database: " + +"pdp="+pdp.getId()); + throw new PAPException(e.getMessage()); + } + // this is a request to update the pdp + papEngine.updatePDP(pdp); + } + + response.setStatus(HttpServletResponse.SC_NO_CONTENT); + if (logger.isDebugEnabled()) { + logger.debug("PDP '" + pdpId + "' created/updated"); + } + + // adjust the group's state including the new PDP + ((StdPDPGroup)group).resetStatus(); + + // tell the Admin Consoles there is a change + notifyAC(); + // this might affect the PDP, so notify it of the change + pdpChanged(pdp); + acPutTransaction.commitTransaction(); + loggingContext.transactionEnded(); + auditLogger.info("Success"); + PolicyLogger.audit("Transaction Ended Successfully"); + return; + } else if (request.getParameter("pipId") != null) { + // group= pipId= contents=pip properties <= add a PIP to pip config, or replace it if it already exists (lenient operation) + loggingContext.setServiceName("AC:PAP.putPIP"); + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + " UNIMPLEMENTED"); + loggingContext.transactionEnded(); + + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(HttpServletResponse.SC_BAD_REQUEST, "UNIMPLEMENTED"); + return; + } else { + // Assume that this is an update of an existing PDP Group + // ARGS: group= <= Update an Existing Group + loggingContext.setServiceName("AC:PAP.updateGroup"); + + // get the request content into a String + String json = null; + // read the inputStream into a buffer (trick found online scans entire input looking for end-of-file) + java.util.Scanner scanner = new java.util.Scanner(request.getInputStream()); + scanner.useDelimiter("\\A"); + json = scanner.hasNext() ? scanner.next() : ""; + scanner.close(); + logger.info("JSON request from AC: " + json); + + // convert Object sent as JSON into local object + ObjectMapper mapper = new ObjectMapper(); + + Object objectFromJSON = mapper.readValue(json, StdPDPGroup.class); + + if (objectFromJSON == null || + ! (objectFromJSON instanceof StdPDPGroup) || + ! ((StdPDPGroup)objectFromJSON).getId().equals(group.getId())) { + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " Group update had bad input. id=" + group.getId() + " objectFromJSON="+objectFromJSON); + loggingContext.transactionEnded(); + + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(500, "Bad input, id="+group.getId() +" object="+objectFromJSON); + } + + // The Path on the PAP side is not carried on the RESTful interface with the AC + // (because it is local to the PAP) + // so we need to fill that in before submitting the group for update + ((StdPDPGroup)objectFromJSON).setDirectory(((StdPDPGroup)group).getDirectory()); + + try{ + acPutTransaction.updateGroup((StdPDPGroup)objectFromJSON, "XACMLPapServlet.doACPut"); + } catch(Exception e){ + PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW + " Error while updating group in the database: " + +"group="+group.getId()); + throw new PAPException(e.getMessage()); + } + papEngine.updateGroup((StdPDPGroup)objectFromJSON); + + + response.setStatus(HttpServletResponse.SC_NO_CONTENT); + if (logger.isDebugEnabled()) { + logger.debug("Group '" + group.getId() + "' updated"); + } + acPutTransaction.commitTransaction(); + // tell the Admin Consoles there is a change + notifyAC(); + // Group changed, which might include changing the policies + groupChanged(group); + + loggingContext.transactionEnded(); + auditLogger.info("Success"); + PolicyLogger.audit("Transaction Ended Successfully"); + return; + } + } catch (PAPException e) { + acPutTransaction.rollbackTransaction(); + PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "XACMLPapServlet", " AC PUT exception"); + loggingContext.transactionEnded(); + + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(500, e.getMessage()); + return; + } + } + + /** + * Requests from the Admin Console to delete/remove items + * + * @param request + * @param response + * @param groupId + * @param loggingContext + * @throws ServletException + * @throws IOException + */ + private void doACDelete(HttpServletRequest request, HttpServletResponse response, String groupId, ECOMPLoggingContext loggingContext) throws ServletException, IOException { + + //This is temporary code to allow deletes to propagate to the database since delete is not implemented + String isDeleteNotify = request.getParameter("isDeleteNotify"); + if(isDeleteNotify != null){ + String policyToDelete = request.getParameter("policyToDelete"); + try{ + policyToDelete = URLDecoder.decode(policyToDelete,"UTF-8"); + } catch(UnsupportedEncodingException e){ + PolicyLogger.error("Unsupported URL encoding of policyToDelete (UTF-8"); + response.sendError(500,"policyToDelete encoding not supported"); + return; + } + PolicyDBDaoTransaction deleteTransaction = policyDBDao.getNewTransaction(); + try{ + deleteTransaction.deletePolicy(policyToDelete); + } catch(Exception e){ + deleteTransaction.rollbackTransaction(); + response.sendError(500,"deleteTransaction.deleteTransaction(policyToDelete) " + + "\nfailure with the following exception: " + e); + return; + } + deleteTransaction.commitTransaction(); + response.setStatus(HttpServletResponse.SC_OK); + return; + } + PolicyDBDaoTransaction removePdpOrGroupTransaction = policyDBDao.getNewTransaction(); + try { + // for all DELETE operations the group must exist before the operation can be done + loggingContext.setServiceName("AC:PAP.delete"); + EcompPDPGroup group = papEngine.getGroup(groupId); + if (group == null) { + String message = "Unknown groupId '" + groupId + "'"; + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " " + message); + loggingContext.transactionEnded(); + + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(HttpServletResponse.SC_NOT_FOUND, "Unknown groupId '" + groupId +"'"); + return; + } + + + // determine the operation needed based on the parameters in the request + if (request.getParameter("policy") != null) { + // group= policy= [delete=] <= delete policy file from group + loggingContext.setServiceName("AC:PAP.deletePolicy"); + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + " UNIMPLEMENTED"); + //DATABASE so can policies not be deleted? or doesn't matter maybe as long as this gets called + loggingContext.transactionEnded(); + + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(HttpServletResponse.SC_BAD_REQUEST, "UNIMPLEMENTED"); + return; + } else if (request.getParameter("pdpId") != null) { + // ARGS: group= pdpId= <= delete PDP + String pdpId = request.getParameter("pdpId"); + EcompPDP pdp = papEngine.getPDP(pdpId); + + try{ + removePdpOrGroupTransaction.removePdpFromGroup(pdp.getId(),"XACMLPapServlet.doACDelete"); + } catch(Exception e){ + throw new PAPException(); + } + papEngine.removePDP((EcompPDP) pdp); + + // adjust the status of the group, which may have changed when we removed this PDP + ((StdPDPGroup)group).resetStatus(); + + response.setStatus(HttpServletResponse.SC_NO_CONTENT); + notifyAC(); + + // update the PDP and tell it that it has NO Policies (which prevents it from serving PEP Requests) + pdpChanged(pdp); + removePdpOrGroupTransaction.commitTransaction(); + loggingContext.transactionEnded(); + auditLogger.info("Success"); + PolicyLogger.audit("Transaction Ended Successfully"); + return; + } else if (request.getParameter("pipId") != null) { + // group= pipId= <= delete PIP config for given engine + + loggingContext.setServiceName("AC:PAP.deletePIPConfig"); + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + " UNIMPLEMENTED"); + loggingContext.transactionEnded(); + + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(HttpServletResponse.SC_BAD_REQUEST, "UNIMPLEMENTED"); + return; + } else { + // ARGS: group= movePDPsToGroupId= <= delete a group and move all its PDPs to the given group + String moveToGroupId = request.getParameter("movePDPsToGroupId"); + EcompPDPGroup moveToGroup = null; + if (moveToGroupId != null) { + moveToGroup = papEngine.getGroup(moveToGroupId); + } + + // get list of PDPs in the group being deleted so we can notify them that they got changed + Set movedPDPs = new HashSet(); + movedPDPs.addAll(group.getEcompPdps()); + + // do the move/remove + try{ + removePdpOrGroupTransaction.deleteGroup(group, moveToGroup,"XACMLPapServlet.doACDelete"); + } catch(Exception e){ + PolicyLogger.error(MessageCodes.ERROR_UNKNOWN, e, "XACMLPapServlet", " Failed to delete PDP Group. Exception"); + e.printStackTrace(); + throw new PAPException(e.getMessage()); + } + papEngine.removeGroup(group, moveToGroup); + + response.setStatus(HttpServletResponse.SC_NO_CONTENT); + notifyAC(); + // notify any PDPs in the removed set that their config may have changed + for (EcompPDP pdp : movedPDPs) { + pdpChanged(pdp); + } + removePdpOrGroupTransaction.commitTransaction(); + loggingContext.transactionEnded(); + auditLogger.info("Success"); + PolicyLogger.audit("Transaction Ended Successfully"); + return; + } + + } catch (PAPException e) { + removePdpOrGroupTransaction.rollbackTransaction(); + PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "XACMLPapServlet", " AC DELETE exception"); + loggingContext.transactionEnded(); + + PolicyLogger.audit("Transaction Failed - See Error.log"); + PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "XACMLPapServlet", " Exception in request processing"); + response.sendError(500, e.getMessage()); + return; + } + } + + + /** + * Requests from the API to delete/remove items + * + * @param request + * @param response + * @param groupId + * @param loggingContext + * @throws ServletException + * @throws IOException + */ + private void doAPIDeleteFromPAP(HttpServletRequest request, HttpServletResponse response, ECOMPLoggingContext loggingContext) throws ServletException, IOException { + + // get the request content into a String + String json = null; + + // read the inputStream into a buffer (trick found online scans entire input looking for end-of-file) + java.util.Scanner scanner = new java.util.Scanner(request.getInputStream()); + scanner.useDelimiter("\\A"); + json = scanner.hasNext() ? scanner.next() : ""; + scanner.close(); + logger.info("JSON request from API: " + json); + + // convert Object sent as JSON into local object + ObjectMapper mapper = new ObjectMapper(); + + Object objectFromJSON = mapper.readValue(json, StdPAPPolicy.class); + + StdPAPPolicy policy = (StdPAPPolicy) objectFromJSON; + + String policyName = policy.getPolicyName(); + String fileSeparator = File.separator; + policyName = policyName.replaceFirst("\\.", "\\"+fileSeparator); + + File file = getPolicyFile(policyName); + String domain = getParentPathSubScopeDir(file); + Boolean policyFileDeleted = false; + Boolean configFileDeleted = false; + Boolean policyVersionScoreDeleted = false; + + if (policy.getDeleteCondition().equalsIgnoreCase("All Versions")){ + + //check for extension in policyName + String removexmlExtension = null; + String removeVersion = null; + if (policyName.contains("xml")) { + removexmlExtension = file.toString().substring(0, file.toString().lastIndexOf(".")); + removeVersion = removexmlExtension.substring(0, removexmlExtension.lastIndexOf(".")); + } else { + removeVersion = file.toString(); + } + + File dirXML = new File(file.getParent()); + File[] listofXMLFiles = dirXML.listFiles(); + + for (File files : listofXMLFiles) { + //delete the xml files from the Repository + if (files.isFile() && files.toString().contains(removeVersion)) { + JPAUtils jpaUtils = null; + try { + jpaUtils = JPAUtils.getJPAUtilsInstance(emf); + } catch (Exception e) { + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "XACMLPapServlet", " Could not create JPAUtils instance on the PAP"); + e.printStackTrace(); + response.addHeader("error", "jpautils"); + response.addHeader("operation", "delete"); + response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); + return; + } + + if (jpaUtils.dbLockdownIgnoreErrors()) { + logger.warn("Policies are locked down"); + response.addHeader("operation", "delete"); + response.addHeader("lockdown", "true"); + response.setStatus(HttpServletResponse.SC_ACCEPTED); + return; + } + + //Propagates delete to the database + Boolean deletedFromDB = notifyDBofDelete(files.toString()); + + if (deletedFromDB) { + logger.info("Policy deleted from the database. Continuing with file delete"); + } else { + PolicyLogger.error("Failed to delete Policy from database. Aborting file delete"); + response.addHeader("error", "deleteDB"); + response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); + return; + } + + if (files.delete()) { + if (logger.isDebugEnabled()) { + logger.debug("Deleted file: " + files.toString()); + } + policyFileDeleted = true; + } else { + logger.warn(XACMLErrorConstants.ERROR_DATA_ISSUE + + "Cannot delete the policy file in specified location: " + files.getAbsolutePath()); + response.addHeader("error", "deleteFile"); + response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR ); + return; + } + + // Get tomcat home directory for deleting config data + logger.info("print the path:" +domain); + String path = domain.replace('\\', '.'); + if(path.contains("/")){ + path = path.replace('/', '.'); + logger.info("print the path:" +path); + } + String fileName = FilenameUtils.removeExtension(file.getName()); + String removeVersionInFileName = fileName.substring(0, fileName.lastIndexOf(".")); + String fileLocation = null; + + if(CONFIG_HOME == null){ + CONFIG_HOME = getConfigHome(); + } + if(ACTION_HOME == null){ + ACTION_HOME = getActionHome(); + } + + + if (fileName != null && fileName.contains("Config_")) { + fileLocation = CONFIG_HOME; + } else if (fileName != null && fileName.contains("Action_")) { + fileLocation = ACTION_HOME; + } + + if (logger.isDebugEnabled()) { + logger.debug("Attempting to rename file from the location: "+ fileLocation); + } + + if(!files.toString().contains("Decision_")){ + // Get the file from the saved location + File dir = new File(fileLocation); + File[] listOfFiles = dir.listFiles(); + + for (File file1 : listOfFiles) { + if (file1.isFile() && file1.getName().contains( path + removeVersionInFileName)) { + try { + if (file1.delete()) { + if (logger.isDebugEnabled()) { + logger.debug("Deleted file: " + file1.toString()); + } + configFileDeleted = true; + } else { + logger.warn(XACMLErrorConstants.ERROR_DATA_ISSUE + + "Cannot delete the configuration or action body file in specified location: " + file1.getAbsolutePath()); + response.addHeader("error", "deleteConfig"); + response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR ); + return; + } + } catch (Exception e) { + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "XACMLPapServlet", " Failed to Delete file"); + } + } + configFileDeleted = true; + } + } else { + configFileDeleted = true; + } + + //Delete the Policy from Database Policy Version table + if (policyFileDeleted && configFileDeleted) { + String removeExtension = domain + removeVersionInFileName; + EntityManager em = (EntityManager) emf.createEntityManager(); + + Query getPolicyVersion = em.createQuery("Select p from PolicyVersion p where p.policyName=:pname"); + Query getPolicyScore = em.createQuery("Select p from PolicyScore p where p.PolicyName=:pname"); + getPolicyVersion.setParameter("pname", removeExtension); + getPolicyScore.setParameter("pname", removeExtension); + + @SuppressWarnings("rawtypes") + List pvResult = getPolicyVersion.getResultList(); + @SuppressWarnings("rawtypes") + List psResult = getPolicyScore.getResultList(); + + + try{ + em.getTransaction().begin(); + if (!pvResult.isEmpty()) { + for (Object id : pvResult) { + PolicyVersion versionEntity = (PolicyVersion)id; + em.remove(versionEntity); + } + } else { + logger.debug("No PolicyVersion record found in database."); + } + + if (!psResult.isEmpty()) { + for (Object id : psResult) { + PolicyScore scoreEntity = (PolicyScore)id; + em.remove(scoreEntity); + } + } else { + PolicyLogger.error("No PolicyScore record found in database."); + } + em.getTransaction().commit(); + policyVersionScoreDeleted = true; + }catch(Exception e){ + em.getTransaction().rollback(); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "XACMLPapServlet", " ERROR"); + response.addHeader("error", "deleteDB"); + response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); + return; + } finally { + em.close(); + } + } + } + } + //If Specific version is requested for delete + } else if (policy.getDeleteCondition().equalsIgnoreCase("Current Version")) { + String policyScoreName = domain + file.getName().toString(); + String policyVersionName = policyScoreName.substring(0, policyScoreName.indexOf(".")); + String versionExtension = policyScoreName.substring(policyScoreName.indexOf(".")+1); + String removexmlExtension = file.toString().substring(0, file.toString().lastIndexOf(".")); + String getVersion = removexmlExtension.substring(removexmlExtension.indexOf(".")+1); + String removeVersion = removexmlExtension.substring(0, removexmlExtension.lastIndexOf(".")); + + + JPAUtils jpaUtils = null; + try { + jpaUtils = JPAUtils.getJPAUtilsInstance(emf); + } catch (Exception e) { + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "XACMLPapServlet", " Could not create JPAUtils instance on the PAP"); + e.printStackTrace(); + response.addHeader("error", "jpautils"); + response.addHeader("operation", "delete"); + response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); + return; + } + + if (jpaUtils.dbLockdownIgnoreErrors()) { + logger.warn("Policies are locked down"); + response.addHeader("lockdown", "true"); + response.addHeader("operation", "delete"); + response.setStatus(HttpServletResponse.SC_ACCEPTED); + return; + } + + //Propagates delete to the database + Boolean deletedFromDB = notifyDBofDelete(file.toString()); + + if (deletedFromDB) { + logger.info("Policy deleted from the database. Continuing with file delete"); + } else { + PolicyLogger.error("Failed to delete Policy from database. Aborting file delete"); + response.addHeader("error", "deleteDB"); + response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); + return; + } + + if (file.delete()) { + if (logger.isDebugEnabled()) { + logger.debug("Deleted file: " + file.toString()); + } + policyFileDeleted = true; + } else { + logger.warn(XACMLErrorConstants.ERROR_DATA_ISSUE + + "Cannot delete the policy file in specified location: " + file.getAbsolutePath()); + response.addHeader("error", "deleteFile"); + response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR ); + return; + } + + // Get tomcat home directory for deleting config data + logger.info("print the path:" +domain); + String path = domain.replace('\\', '.'); + if(path.contains("/")){ + path = path.replace('/', '.'); + logger.info("print the path:" +path); + } + String fileName = FilenameUtils.removeExtension(file.getName()); + String removeVersionInFileName = fileName.substring(0, fileName.lastIndexOf(".")); + String fileLocation = null; + + if(CONFIG_HOME == null){ + CONFIG_HOME = getConfigHome(); + } + if(ACTION_HOME == null){ + ACTION_HOME = getActionHome(); + } + + + if (fileName != null && fileName.contains("Config_")) { + fileLocation = CONFIG_HOME; + } else if (fileName != null && fileName.contains("Action_")) { + fileLocation = ACTION_HOME; + } + + if (logger.isDebugEnabled()) { + logger.debug("Attempting to rename file from the location: "+ fileLocation); + } + + if(!file.toString().contains("Decision_")){ + // Get the file from the saved location + File dir = new File(fileLocation); + File[] listOfFiles = dir.listFiles(); + + for (File file1 : listOfFiles) { + if (file1.isFile() && file1.getName().contains( path + fileName)) { + try { + if (file1.delete()) { + if (logger.isDebugEnabled()) { + logger.debug("Deleted file: " + file1.toString()); + } + configFileDeleted = true; + } else { + logger.warn(XACMLErrorConstants.ERROR_DATA_ISSUE + + "Cannot delete the configuration or action body file in specified location: " + file1.getAbsolutePath()); + response.addHeader("error", "deleteConfig"); + response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR ); + return; + } + } catch (Exception e) { + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "XACMLPapServlet", " Failed to Delete file"); + } + } + configFileDeleted = true; + } + } else { + configFileDeleted = true; + } + + //Delete the Policy from Database and set Active Version based on the deleted file. + int highestVersion = 0; + if (policyFileDeleted && configFileDeleted) { + String removeExtension = domain + removeVersionInFileName; + EntityManager em = (EntityManager) emf.createEntityManager(); + + Query getPolicyVersion = em.createQuery("Select p from PolicyVersion p where p.policyName=:pname"); + Query getPolicyScore = em.createQuery("Select p from PolicyScore p where p.PolicyName=:pname"); + getPolicyVersion.setParameter("pname", removeExtension); + getPolicyScore.setParameter("pname", removeExtension); + + @SuppressWarnings("rawtypes") + List pvResult = getPolicyVersion.getResultList(); + @SuppressWarnings("rawtypes") + List psResult = getPolicyScore.getResultList(); + + + try{ + em.getTransaction().begin(); + if (!pvResult.isEmpty()) { + PolicyVersion versionEntity = null; + for (Object id : pvResult) { + versionEntity = (PolicyVersion)id; + if(versionEntity.getPolicyName().equals(removeExtension)){ + highestVersion = versionEntity.getHigherVersion(); + em.remove(versionEntity); + } + } + + int i = 0; + int version = Integer.parseInt(getVersion); + + if(version == highestVersion) { + for(i = highestVersion; i>=1; i--){ + highestVersion = highestVersion - 1; + String dirXML = removeVersion + "." + highestVersion + ".xml"; + File filenew = new File(dirXML); + + if(filenew.exists()){ + break; + } + + } + } + + versionEntity.setPolicyName(removeExtension); + versionEntity.setHigherVersion(highestVersion); + versionEntity.setActiveVersion(highestVersion); + versionEntity.setModifiedBy("API"); + + em.persist(versionEntity); + + } else { + logger.debug("No PolicyVersion record found in database."); + } + + if (!psResult.isEmpty()) { + for (Object id : psResult) { + PolicyScore scoreEntity = (PolicyScore)id; + if(scoreEntity.getPolicyName().equals(policyVersionName) && scoreEntity.getVersionExtension().equals(versionExtension)){ + em.remove(scoreEntity); + } + } + } else { + PolicyLogger.error("No PolicyScore record found in database."); + } + em.getTransaction().commit(); + policyVersionScoreDeleted = true; + }catch(Exception e){ + em.getTransaction().rollback(); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "XACMLPapServlet", " ERROR"); + response.addHeader("error", "deleteDB"); + response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); + return; + } finally { + em.close(); + } + } + } + + if (policyFileDeleted && configFileDeleted && policyVersionScoreDeleted) { + response.setStatus(HttpServletResponse.SC_OK); + response.addHeader("successMapKey", "success"); + response.addHeader("operation", "delete"); + return; + } else { + PolicyLogger.error(MessageCodes.ERROR_UNKNOWN + "Failed to delete the policy for an unknown reason. Check the file system and other logs for further information."); + + response.addHeader("error", "unknown"); + response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR ); + return; + } + + } + + private void doImportMicroServicePut(HttpServletRequest request, HttpServletResponse response) { + String importServiceCreation = request.getParameter("importService");; + String fileName = request.getParameter("fileName"); + String version = request.getParameter("version"); + String serviceName = request.getParameter("serviceName"); + CreateNewMicroSerivceModel newMS = null; + + String randomID = UUID.randomUUID().toString(); + + if ( importServiceCreation != null || fileName != null) { + File extracDir = new File("ExtractDir"); + if (!extracDir.exists()){ + extracDir.mkdirs(); + } + if (fileName.contains(".xmi")){ + // get the request content into a String + String xmi = null; + + // read the inputStream into a buffer (trick found online scans entire input looking for end-of-file) + java.util.Scanner scanner; + try { + scanner = new java.util.Scanner(request.getInputStream()); + scanner.useDelimiter("\\A"); + xmi = scanner.hasNext() ? scanner.next() : ""; + scanner.close(); + } catch (IOException e1) { + logger.error("Error in reading in file from API call"); + return; + } + + logger.info("XML request from API for import new Service"); + + //Might need to seperate by , for more than one file. + + try (Writer writer = new BufferedWriter(new OutputStreamWriter( + new FileOutputStream("ExtractDir" + File.separator + randomID+".xmi"), "utf-8"))) { + writer.write(xmi); + } catch (IOException e) { + logger.error("Error in reading in file from API call"); + return; + } + }else{ + try { + InputStream inputStream = request.getInputStream() ; + + FileOutputStream outputStream = new FileOutputStream("ExtractDir" + File.separator + randomID+".zip"); + byte[] buffer = new byte[4096]; + int bytesRead = -1 ; + while ((bytesRead = inputStream.read(buffer)) != -1) { + outputStream.write(buffer, 0, bytesRead) ; + } + + outputStream.close() ; + inputStream.close() ; + + } catch (IOException e) { + logger.error("Error in reading in Zip File from API call"); + return; + } + } + + newMS = new CreateNewMicroSerivceModel(fileName, serviceName, "API IMPORT", version, randomID); + Map successMap = newMS.addValuesToNewModel(); + if (successMap.containsKey("success")) { + successMap.clear(); + successMap = newMS.saveImportService(); + } + + + // create the policy and return a response to the PAP-ADMIN + if (successMap.containsKey("success")) { + response.setStatus(HttpServletResponse.SC_OK); + response.addHeader("successMapKey", "success"); + response.addHeader("operation", "import"); + response.addHeader("service", serviceName); + } else if (successMap.containsKey("DBError")) { + if (successMap.get("DBError").contains("EXISTS")){ + response.setStatus(HttpServletResponse.SC_CONFLICT); + response.addHeader("service", serviceName); + response.addHeader("error", "modelExistsDB"); + }else{ + response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); + response.addHeader("error", "importDB"); + } + response.addHeader("operation", "import"); + response.addHeader("service", serviceName); + }else if (successMap.get("error").contains("MISSING")){ + response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); + response.addHeader("error", "missing"); + response.addHeader("operation", "import"); + response.addHeader("service", serviceName); + } + } + } + + private void doAPIDeleteFromPDP(HttpServletRequest request, HttpServletResponse response, ECOMPLoggingContext loggingContext) throws ServletException, IOException { + + String policyName = request.getParameter("policyName"); + String groupId = request.getParameter("groupId"); + String responseString = null; + + // for PUT operations the group may or may not need to exist before the operation can be done + EcompPDPGroup group = null; + try { + group = papEngine.getGroup(groupId); + } catch (PAPException e) { + logger.error("Exception occured While PUT operation is performing for PDP Group"+e); + } + + if (group == null) { + String message = "Unknown groupId '" + groupId + "'"; + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " " + message); + loggingContext.transactionEnded(); + + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.addHeader("error", "UnknownGroup"); + response.sendError(HttpServletResponse.SC_NOT_FOUND, message); + return; + } else { + + loggingContext.setServiceName("API:PAP.deletPolicyFromPDPGroup"); + + if (policyName.contains("xml")) { + logger.debug("The full file name including the extension was provided for policyName.. continue."); + } else { + String message = XACMLErrorConstants.ERROR_DATA_ISSUE + "Invalid policyName... " + + "policyName must be the full name of the file to be deleted including version and extension"; + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " Invalid policyName... " + + "policyName must be the full name of the file to be deleted including version and extension"); + response.addHeader("error", "invalidPolicyName"); + response.sendError(HttpServletResponse.SC_BAD_REQUEST, message); + return; + } + RemoveGroupPolicy removePolicy = new RemoveGroupPolicy((StdPDPGroup) group); + + PDPPolicy policy = group.getPolicy(policyName); + + if (policy != null) { + removePolicy.prepareToRemove(policy); + EcompPDPGroup updatedGroup = removePolicy.getUpdatedObject(); + responseString = deletePolicyFromPDPGroup(updatedGroup, loggingContext); + } else { + String message = XACMLErrorConstants.ERROR_DATA_ISSUE + "Policy does not exist on the PDP."; + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " Policy does not exist on the PDP."); + response.addHeader("error", "noPolicyExist"); + response.sendError(HttpServletResponse.SC_BAD_REQUEST, message); + return; + } + } + + if (responseString.equals("success")) { + logger.info("Policy successfully deleted!"); + PolicyLogger.audit("Policy successfully deleted!"); + response.setStatus(HttpServletResponse.SC_OK); + response.addHeader("successMapKey", "success"); + response.addHeader("operation", "delete"); + return; + } else if (responseString.equals("No Group")) { + String message = XACMLErrorConstants.ERROR_DATA_ISSUE + "Group update had bad input."; + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " Group update had bad input."); + response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); + response.addHeader("error", "groupUpdate"); + response.addHeader("message", message); + return; + } else if (responseString.equals("DB Error")) { + PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW + " Error while updating group in the database"); + response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); + response.addHeader("error", "deleteDB"); + return; + } else { + PolicyLogger.error(MessageCodes.ERROR_UNKNOWN + " Failed to delete the policy for an unknown reason. Check the file system and other logs for further information."); + response.addHeader("error", "unknown"); + response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR ); + return; + } + + } + + protected String getParentPathSubScopeDir(File file) { + String domain1 = null; + + Path workspacePath = Paths.get(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_WORKSPACE), "admin"); + Path repositoryPath = Paths.get(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_REPOSITORY)); + Path gitPath = Paths.get(workspacePath.toString(), repositoryPath.getFileName().toString()); + + String policyDir = file.getAbsolutePath(); + int startIndex = policyDir.indexOf(gitPath.toString()) + gitPath.toString().length() + 1; + policyDir = policyDir.substring(startIndex, policyDir.length()); + if(policyDir.contains("Config_")){ + domain1 = policyDir.substring(0,policyDir.indexOf("Config_")); + }else if(policyDir.contains("Action_")){ + domain1 = policyDir.substring(0,policyDir.indexOf("Action_")); + }else{ + domain1 = policyDir.substring(0,policyDir.indexOf("Decision_")); + } + logger.info("print the main domain value"+policyDir); + + return domain1; + } + + /* + * method to delete the policy from the database and return notification when using API + */ + private Boolean notifyDBofDelete (String policyToDelete) { + //String policyToDelete = request.getParameter("policyToDelete"); + try{ + policyToDelete = URLDecoder.decode(policyToDelete,"UTF-8"); + } catch(UnsupportedEncodingException e){ + PolicyLogger.error("Unsupported URL encoding of policyToDelete (UTF-8)"); + return false; + } + PolicyDBDaoTransaction deleteTransaction = policyDBDao.getNewTransaction(); + try{ + deleteTransaction.deletePolicy(policyToDelete); + } catch(Exception e){ + deleteTransaction.rollbackTransaction(); + return false; + } + deleteTransaction.commitTransaction(); + return true; + } + + private String deletePolicyFromPDPGroup (EcompPDPGroup group, ECOMPLoggingContext loggingContext){ + PolicyDBDaoTransaction acPutTransaction = policyDBDao.getNewTransaction(); + + String response = null; + loggingContext.setServiceName("API:PAP.updateGroup"); + + EcompPDPGroup existingGroup = null; + try { + existingGroup = papEngine.getGroup(group.getId()); + } catch (PAPException e1) { + logger.error("Exception occured While Deleting Policy From PDP Group"+e1); + } + + if (group == null || + ! (group instanceof StdPDPGroup) || + ! (group.getId().equals(existingGroup.getId()))) { + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " Group update had bad input. id=" + existingGroup.getId() + " objectFromJSON="+group); + loggingContext.transactionEnded(); + + PolicyLogger.audit("Transaction Failed - See Error.log"); + + response = "No Group"; + return response; + } + + // The Path on the PAP side is not carried on the RESTful interface with the AC + // (because it is local to the PAP) + // so we need to fill that in before submitting the group for update + ((StdPDPGroup)group).setDirectory(((StdPDPGroup)existingGroup).getDirectory()); + + try{ + acPutTransaction.updateGroup(group, "XACMLPapServlet.doAPIDelete"); + } catch(Exception e){ + PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "XACMLPapServlet", " Error while updating group in the database: " + +"group="+existingGroup.getId()); + response = "DB Error"; + return response; + } + + try { + papEngine.updateGroup(group); + } catch (PAPException e) { + logger.error("Exception occured While Updating PDP Groups"+e); + response = "error in updateGroup method"; + } + + if (logger.isDebugEnabled()) { + logger.debug("Group '" + group.getId() + "' updated"); + } + + acPutTransaction.commitTransaction(); + + // Group changed, which might include changing the policies + try { + groupChanged(existingGroup); + } catch (Exception e) { + logger.error("Exception occured in Group Change Method"+e); + response = "error in groupChanged method"; + } + + if (response==null){ + response = "success"; + PolicyLogger.audit("Policy successfully deleted!"); + PolicyLogger.audit("Transaction Ended Successfully"); + } + + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Ended"); + return response; + } + + + // + // Heartbeat thread - periodically check on PDPs' status + // + + /** + * Heartbeat with all known PDPs. + * + * Implementation note: + * + * The PDPs are contacted Sequentially, not in Parallel. + * + * If we did this in parallel using multiple threads we would simultaneously use + * - 1 thread and + * - 1 connection + * for EACH PDP. + * This could become a resource problem since we already use multiple threads and connections for updating the PDPs + * when user changes occur. + * Using separate threads can also make it tricky dealing with timeouts on PDPs that are non-responsive. + * + * The Sequential operation does a heartbeat request to each PDP one at a time. + * This has the flaw that any PDPs that do not respond will hold up the entire heartbeat sequence until they timeout. + * If there are a lot of non-responsive PDPs and the timeout is large-ish (the default is 20 seconds) + * it could take a long time to cycle through all of the PDPs. + * That means that this may not notice a PDP being down in a predictable time. + * + * + */ + private class Heartbeat implements Runnable { + private PAPPolicyEngine papEngine; + private Set pdps = new HashSet(); + private int heartbeatInterval; + private int heartbeatTimeout; + + public volatile boolean isRunning = false; + + public synchronized boolean isRunning() { + return this.isRunning; + } + + public synchronized void terminate() { + this.isRunning = false; + } + + public Heartbeat(PAPPolicyEngine papEngine2) { + this.papEngine = papEngine2; + this.heartbeatInterval = Integer.parseInt(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_HEARTBEAT_INTERVAL, "10000")); + this.heartbeatTimeout = Integer.parseInt(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_HEARTBEAT_TIMEOUT, "10000")); + } + + @Override + public void run() { + // + // Set ourselves as running + // + synchronized(this) { + this.isRunning = true; + } + HashMap idToURLMap = new HashMap(); + try { + while (this.isRunning()) { + // Wait the given time + Thread.sleep(heartbeatInterval); + + // get the list of PDPs (may have changed since last time) + pdps.clear(); + synchronized(papEngine) { + try { + for (EcompPDPGroup g : papEngine.getEcompPDPGroups()) { + for (EcompPDP p : g.getEcompPdps()) { + pdps.add(p); + } + } + } catch (PAPException e) { + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "XACMLPapServlet", "Heartbeat unable to read PDPs from PAPEngine"); + } + } + // + // Check for shutdown + // + if (this.isRunning() == false) { + logger.info("isRunning is false, getting out of loop."); + break; + } + + // try to get the summary status from each PDP + boolean changeSeen = false; + for (EcompPDP pdp : pdps) { + // + // Check for shutdown + // + if (this.isRunning() == false) { + logger.info("isRunning is false, getting out of loop."); + break; + } + // the id of the PDP is its url (though we add a query parameter) + URL pdpURL = idToURLMap.get(pdp.getId()); + if (pdpURL == null) { + // haven't seen this PDP before + String fullURLString = null; + try { + // Check PDP ID + if(CheckPDP.validateID(pdp.getId())){ + fullURLString = pdp.getId() + "?type=hb"; + pdpURL = new URL(fullURLString); + idToURLMap.put(pdp.getId(), pdpURL); + } + } catch (MalformedURLException e) { + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "XACMLPapServlet", " PDP id '" + fullURLString + "' is not a valid URL"); + continue; + } + } + + // Do a GET with type HeartBeat + String newStatus = ""; + + HttpURLConnection connection = null; + try { + + // + // Open up the connection + // + connection = (HttpURLConnection)pdpURL.openConnection(); + // + // Setup our method and headers + // + connection.setRequestMethod("GET"); + connection.setConnectTimeout(heartbeatTimeout); + // Added for Authentication + String encoding = CheckPDP.getEncoding(pdp.getId()); + if(encoding !=null){ + connection.setRequestProperty("Authorization", "Basic " + encoding); + } + // + // Do the connect + // + connection.connect(); + if (connection.getResponseCode() == 204) { + newStatus = connection.getHeaderField(XACMLRestProperties.PROP_PDP_HTTP_HEADER_HB); + if (logger.isDebugEnabled()) { + logger.debug("Heartbeat '" + pdp.getId() + "' status='" + newStatus + "'"); + } + } else { + // anything else is an unexpected result + newStatus = PDPStatus.Status.UNKNOWN.toString(); + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + " Heartbeat connect response code " + connection.getResponseCode() + ": " + pdp.getId()); + } + } catch (UnknownHostException e) { + newStatus = PDPStatus.Status.NO_SUCH_HOST.toString(); + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "XACMLPapServlet", " Heartbeat '" + pdp.getId() + "' NO_SUCH_HOST"); + } catch (SocketTimeoutException e) { + newStatus = PDPStatus.Status.CANNOT_CONNECT.toString(); + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "XACMLPapServlet", " Heartbeat '" + pdp.getId() + "' connection timeout"); + } catch (ConnectException e) { + newStatus = PDPStatus.Status.CANNOT_CONNECT.toString(); + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "XACMLPapServlet", " Heartbeat '" + pdp.getId() + "' cannot connect"); + } catch (Exception e) { + newStatus = PDPStatus.Status.UNKNOWN.toString(); + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "XACMLPapServlet", "Heartbeat '" + pdp.getId() + "' connect exception"); + } finally { + // cleanup the connection + connection.disconnect(); + } + + if ( ! pdp.getStatus().getStatus().toString().equals(newStatus)) { + if (logger.isDebugEnabled()) { + logger.debug("previous status='" + pdp.getStatus().getStatus()+"' new Status='" + newStatus + "'"); + } + try { + setPDPSummaryStatus(pdp, newStatus); + } catch (PAPException e) { + PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "XACMLPapServlet", "Unable to set state for PDP '" + pdp.getId()); + } + changeSeen = true; + } + + } + // + // Check for shutdown + // + if (this.isRunning() == false) { + logger.info("isRunning is false, getting out of loop."); + break; + } + + // if any of the PDPs changed state, tell the ACs to update + if (changeSeen) { + notifyAC(); + } + + } + } catch (InterruptedException e) { + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + " Heartbeat interrupted. Shutting down"); + this.terminate(); + } + } + } + + + // + // HELPER to change Group status when PDP status is changed + // + // (Must NOT be called from a method that is synchronized on the papEngine or it may deadlock) + // + + private void setPDPSummaryStatus(EcompPDP pdp, PDPStatus.Status newStatus) throws PAPException { + setPDPSummaryStatus(pdp, newStatus.toString()); + } + + private void setPDPSummaryStatus(EcompPDP pdp, String newStatus) throws PAPException { + synchronized(papEngine) { + StdPDPStatus status = new StdPDPStatus(); + status.setStatus(PDPStatus.Status.valueOf(newStatus)); + ((StdPDP)pdp).setStatus(status); + + // now adjust the group + StdPDPGroup group = (StdPDPGroup)papEngine.getPDPGroup((EcompPDP) pdp); + // if the PDP was just deleted it may transiently exist but not be in a group + if (group != null) { + group.resetStatus(); + } + } + } + + + // + // Callback methods telling this servlet to notify PDPs of changes made by the PAP StdEngine + // in the PDP group directories + // + + @Override + public void changed() { + // all PDPs in all groups need to be updated/sync'd + Set groups; + try { + groups = papEngine.getEcompPDPGroups(); + } catch (PAPException e) { + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "XACMLPapServlet", " getPDPGroups failed"); + throw new RuntimeException(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Unable to get Groups: " + e); + } + for (EcompPDPGroup group : groups) { + groupChanged(group); + } + } + + @Override + public void groupChanged(EcompPDPGroup group) { + // all PDPs within one group need to be updated/sync'd + for (EcompPDP pdp : group.getEcompPdps()) { + pdpChanged(pdp); + } + } + + @Override + public void pdpChanged(EcompPDP pdp) { + // kick off a thread to do an event notification for each PDP. + // This needs to be on a separate thread so that PDPs that do not respond (down, non-existent, etc) + // do not block the PSP response to the AC, which would freeze the GUI until all PDPs sequentially respond or time-out. + // begin - Fix to maintain requestId - including storedRequestId in UpdatePDPThread to be used later when calling PDP + // Thread t = new Thread(new UpdatePDPThread(pdp)); + Thread t = new Thread(new UpdatePDPThread(pdp, storedRequestId)); + // end - Fix to maintain requestId + if(CheckPDP.validateID(pdp.getId())){ + t.start(); + } + } + + private class UpdatePDPThread implements Runnable { + private EcompPDP pdp; + // begin - Fix to maintain requestId - define requestId under class to be used later when calling PDP + private String requestId; + // end - Fix to maintain requestId + + // remember which PDP to notify + public UpdatePDPThread(EcompPDP pdp) { + this.pdp = pdp; + } + + // begin - Fix to maintain requestId - clone UpdatePDPThread method with different method signature so to include requestId to be used later when calling PDP + public UpdatePDPThread(EcompPDP pdp, String storedRequestId) { + this.pdp = pdp; + requestId = storedRequestId; + } + // end - Fix to maintain requestId + + public void run() { + // send the current configuration to one PDP + HttpURLConnection connection = null; + // get a new logging context for the thread + ECOMPLoggingContext loggingContext = new ECOMPLoggingContext(baseLoggingContext); + try { + loggingContext.setServiceName("PAP:PDP.putConfig"); + // get a new transaction (request) ID and update the logging context. + // begin - Fix to maintain requestId - replace unconditioned generation of new requestID so it won't be used later when calling PDP + // If a requestId was provided, use it, otherwise generate one; post to loggingContext to be used later when calling PDP + // UUID requestID = UUID.randomUUID(); + // loggingContext.setRequestID(requestID.toString()); + if ((requestId == null) || (requestId == "")) { + UUID requestID = UUID.randomUUID(); + loggingContext.setRequestID(requestID.toString()); + PolicyLogger.info("requestID not provided in call to XACMLPapSrvlet (UpdatePDPThread) so we generated one: " + loggingContext.getRequestID()); + } else { + loggingContext.setRequestID(requestId); + PolicyLogger.info("requestID was provided in call to XACMLPapSrvlet (UpdatePDPThread): " + loggingContext.getRequestID()); + } + // end - Fix to maintain requestId + loggingContext.transactionStarted(); + // dummy metric.log example posted below as proof of concept + loggingContext.metricStarted(); + loggingContext.metricEnded(); + PolicyLogger.metrics("Metric example posted here - 1 of 2"); + loggingContext.metricStarted(); + loggingContext.metricEnded(); + PolicyLogger.metrics("Metric example posted here - 2 of 2"); + // dummy metric.log example posted above as proof of concept + + // + // the Id of the PDP is its URL + // + if (logger.isDebugEnabled()) { + logger.debug("creating url for id '" + pdp.getId() + "'"); + } + //TODO - currently always send both policies and pips. Do we care enough to add code to allow sending just one or the other? + //TODO (need to change "cache=", implying getting some input saying which to change) + URL url = new URL(pdp.getId() + "?cache=all"); + + // + // Open up the connection + // + connection = (HttpURLConnection)url.openConnection(); + // + // Setup our method and headers + // + connection.setRequestMethod("PUT"); + // Added for Authentication + String encoding = CheckPDP.getEncoding(pdp.getId()); + if(encoding !=null){ + connection.setRequestProperty("Authorization", "Basic " + encoding); + } + connection.setRequestProperty("Content-Type", "text/x-java-properties"); + // begin - Fix to maintain requestId - post requestID from loggingContext in PDP request header for call to PDP, then reinit storedRequestId to null + // connection.setRequestProperty("X-ECOMP-RequestID", requestID.toString()); + connection.setRequestProperty("X-ECOMP-RequestID", loggingContext.getRequestID()); + storedRequestId = null; + // end - Fix to maintain requestId + // + // Adding this in. It seems the HttpUrlConnection class does NOT + // properly forward our headers for POST re-direction. It does so + // for a GET re-direction. + // + // So we need to handle this ourselves. + // + //TODO - is this needed for a PUT? seems better to leave in for now? + // connection.setInstanceFollowRedirects(false); + // + // PLD - MUST be able to handle re-directs. + // + connection.setInstanceFollowRedirects(true); + connection.setDoOutput(true); + try (OutputStream os = connection.getOutputStream()) { + + EcompPDPGroup group = papEngine.getPDPGroup((EcompPDP) pdp); + // if the PDP was just deleted, there is no group, but we want to send an update anyway + if (group == null) { + // create blank properties files + Properties policyProperties = new Properties(); + policyProperties.put(XACMLProperties.PROP_ROOTPOLICIES, ""); + policyProperties.put(XACMLProperties.PROP_REFERENCEDPOLICIES, ""); + policyProperties.store(os, ""); + + Properties pipProps = new Properties(); + pipProps.setProperty(XACMLProperties.PROP_PIP_ENGINES, ""); + pipProps.store(os, ""); + + } else { + // send properties from the current group + group.getPolicyProperties().store(os, ""); + Properties policyLocations = new Properties(); + for (PDPPolicy policy : group.getPolicies()) { + policyLocations.put(policy.getId() + ".url", XACMLPapServlet.papURL + "?id=" + policy.getId()); + } + policyLocations.store(os, ""); + group.getPipConfigProperties().store(os, ""); + } + + } catch (Exception e) { + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "XACMLPapServlet", " Failed to send property file to " + pdp.getId()); + // Since this is a server-side error, it probably does not reflect a problem on the client, + // so do not change the PDP status. + return; + } + // + // Do the connect + // + connection.connect(); + if (connection.getResponseCode() == 204) { + logger.info("Success. We are configured correctly."); + loggingContext.transactionEnded(); + auditLogger.info("Success. PDP is configured correctly."); + PolicyLogger.audit("Transaction Success. PDP is configured correctly."); + setPDPSummaryStatus(pdp, PDPStatus.Status.UP_TO_DATE); + } else if (connection.getResponseCode() == 200) { + logger.info("Success. PDP needs to update its configuration."); + loggingContext.transactionEnded(); + auditLogger.info("Success. PDP needs to update its configuration."); + PolicyLogger.audit("Transaction Success. PDP is configured correctly."); + setPDPSummaryStatus(pdp, PDPStatus.Status.OUT_OF_SYNCH); + } else { + logger.warn("Failed: " + connection.getResponseCode() + " message: " + connection.getResponseMessage()); + loggingContext.transactionEnded(); + auditLogger.warn("Failed: " + connection.getResponseCode() + " message: " + connection.getResponseMessage()); + PolicyLogger.audit("Transaction Failed: " + connection.getResponseCode() + " message: " + connection.getResponseMessage()); + + setPDPSummaryStatus(pdp, PDPStatus.Status.UNKNOWN); + } + } catch (Exception e) { + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "XACMLPapServlet", " Unable to sync config with PDP '" + pdp.getId() + "'"); + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Failed: Unable to sync config with PDP '" + pdp.getId() + "': " + e); + try { + setPDPSummaryStatus(pdp, PDPStatus.Status.UNKNOWN); + } catch (PAPException e1) { + PolicyLogger.audit("Transaction Failed: Unable to set status of PDP " + pdp.getId() + " to UNKNOWN: " + e); + + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "XACMLPapServlet", " Unable to set status of PDP '" + pdp.getId() + "' to UNKNOWN"); + } + } finally { + // cleanup the connection + connection.disconnect(); + + // tell the AC to update it's status info + notifyAC(); + } + + } + } + + // + // RESTful Interface from PAP to ACs notifying them of changes + // + + private void notifyAC() { + // kick off a thread to do one event notification for all registered ACs + // This needs to be on a separate thread so that ACs can make calls back to PAP to get the updated Group data + // as part of processing this message on their end. + Thread t = new Thread(new NotifyACThread()); + t.start(); + } + + private class NotifyACThread implements Runnable { + + public void run() { + List disconnectedACs = new ArrayList(); + + // There should be no Concurrent exception here because the list is a CopyOnWriteArrayList. + // The "for each" loop uses the collection's iterator under the covers, so it should be correct. + for (String acURL : adminConsoleURLStringList) { + HttpURLConnection connection = null; + try { + + acURL += "?PAPNotification=true"; + + //TODO - Currently we just tell AC that "Something changed" without being specific. Do we want to tell it which group/pdp changed? + //TODO - If so, put correct parameters into the Query string here + acURL += "&objectType=all" + "&action=update"; + + if (logger.isDebugEnabled()) { + logger.debug("creating url for id '" + acURL + "'"); + } + //TODO - currently always send both policies and pips. Do we care enough to add code to allow sending just one or the other? + //TODO (need to change "cache=", implying getting some input saying which to change) + + URL url = new URL(acURL ); + + // + // Open up the connection + // + connection = (HttpURLConnection)url.openConnection(); + // + // Setup our method and headers + // + connection.setRequestMethod("PUT"); + connection.setRequestProperty("Content-Type", "text/x-java-properties"); + // + // Adding this in. It seems the HttpUrlConnection class does NOT + // properly forward our headers for POST re-direction. It does so + // for a GET re-direction. + // + // So we need to handle this ourselves. + // + //TODO - is this needed for a PUT? seems better to leave in for now? + connection.setInstanceFollowRedirects(false); + // + // Do not include any data in the PUT because this is just a + // notification to the AC. + // The AC will use GETs back to the PAP to get what it needs + // to fill in the screens. + // + + // + // Do the connect + // + connection.connect(); + if (connection.getResponseCode() == 204) { + logger.info("Success. We updated correctly."); + } else { + logger.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Failed: " + connection.getResponseCode() + " message: " + connection.getResponseMessage()); + } + + } catch (Exception e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Unable to sync config AC '" + acURL + "': " + e, e); + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "XACMLPapServlet", " Unable to sync config AC '" + acURL + "'"); + disconnectedACs.add(acURL); + } finally { + // cleanup the connection + connection.disconnect(); + } + } + + // remove any ACs that are no longer connected + if (disconnectedACs.size() > 0) { + adminConsoleURLStringList.removeAll(disconnectedACs); + } + + } + } + + /* + * Added by Mike M in 1602 release for Authorizing the PEP Requests for Granularity. + */ + private boolean authorizeRequest(HttpServletRequest request) { + if(request instanceof HttpServletRequest) { + + // Get the client Credentials from the Request header. + String clientCredentials = request.getHeader(ENVIRONMENT_HEADER); + + // Check if the Client is Authorized. + if(clientCredentials!=null && clientCredentials.equalsIgnoreCase(environment)){ + return true; + }else{ + return false; + } + } else { + return false; + } + } + + public static String getConfigHome(){ + try { + loadWebapps(); + } catch (Exception e) { + return null; + } + return CONFIG_HOME; + } + + public static String getActionHome(){ + try { + loadWebapps(); + } catch (Exception e) { + return null; + } + return ACTION_HOME; + } + + private static void loadWebapps() throws Exception{ + if(ACTION_HOME == null || CONFIG_HOME == null){ + Path webappsPath = Paths.get(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_WEBAPPS)); + //Sanity Check + if (webappsPath == null) { + PolicyLogger.error("Invalid Webapps Path Location property : " + XACMLRestProperties.PROP_PAP_WEBAPPS); + throw new Exception("Invalid Webapps Path Location property : " + XACMLRestProperties.PROP_PAP_WEBAPPS); + } + Path webappsPathConfig; + Path webappsPathAction; + if(webappsPath.toString().contains("\\")) + { + webappsPathConfig = Paths.get(webappsPath.toString()+"\\Config"); + webappsPathAction = Paths.get(webappsPath.toString()+"\\Action"); + } + else + { + webappsPathConfig = Paths.get(webappsPath.toString()+"/Config"); + webappsPathAction = Paths.get(webappsPath.toString()+"/Action"); + } + if (Files.notExists(webappsPathConfig)) + { + try { + Files.createDirectories(webappsPathConfig); + } catch (IOException e) { + PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "XACMLPapServlet", " Failed to create config directory: " + + webappsPathConfig.toAbsolutePath().toString()); + } + } + if (Files.notExists(webappsPathAction)) + { + try { + Files.createDirectories(webappsPathAction); + } catch (IOException e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Failed to create config directory: " + + webappsPathAction.toAbsolutePath().toString(), e); + } + } + ACTION_HOME = webappsPathAction.toString(); + CONFIG_HOME = webappsPathConfig.toString(); + } + } + + /** + * @return the emf + */ + public EntityManagerFactory getEmf() { + return emf; + } + public IntegrityMonitor getIm() { + return im; + } + + public IntegrityAudit getIa() { + return ia; + } +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/adapters/GridData.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/adapters/GridData.java new file mode 100644 index 000000000..86f42bcbe --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/adapters/GridData.java @@ -0,0 +1,62 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.adapters; + +import java.util.ArrayList; + +public class GridData { + private ArrayList attributes; + private ArrayList alAttributes; + private ArrayList transportProtocols; + private ArrayList appProtocols; + + public ArrayList getAttributes() { + return attributes; + } + + public void setAttributes(ArrayList attributes) { + this.attributes = attributes; + } + + public ArrayList getAlAttributes() { + return alAttributes; + } + + public void setAlAttributes(ArrayList alAttributes) { + this.alAttributes = alAttributes; + } + + public ArrayList getAppProtocols() { + return appProtocols; + } + + public void setAppProtocols(ArrayList appProtocols) { + this.appProtocols = appProtocols; + } + + public ArrayList getTransportProtocols() { + return transportProtocols; + } + + public void setTransportProtocols(ArrayList transportProtocols) { + this.transportProtocols = transportProtocols; + } +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/adapters/PolicyRestAdapter.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/adapters/PolicyRestAdapter.java new file mode 100644 index 000000000..19af8b08c --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/adapters/PolicyRestAdapter.java @@ -0,0 +1,480 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.adapters; + +import java.util.List; +import java.util.Map; + +import javax.persistence.EntityManagerFactory; + +//import org.openecomp.policy.pap.xacml.rest.model.GitRepositoryContainer; + +public class PolicyRestAdapter { + + private Object data; + private String policyName = null; + private String configBodyData = null; + private String configType = null; + private String policyID = null; + private String policyType = null; + private String configPolicyType = null; + private String policyDescription = null; + private String ecompName = null; + private String configName = null; + private String ruleID = null; + private String ruleCombiningAlgId = null; + private Map dynamicFieldConfigAttributes; + private Map dynamicSettingsMap; + private Map dropDownMap; + private String actionPerformer = null; + private String actionAttribute = null; + private List dynamicRuleAlgorithmLabels; + private List dynamicRuleAlgorithmCombo; + private List dynamicRuleAlgorithmField1; + private List dynamicRuleAlgorithmField2; + private List dynamicVariableList; + private List dataTypeList; + private String parentPath; + private boolean isValidData = false; + private String adminNotification = null; + private boolean isEditPolicy = false; + private boolean isViewPolicy = false; + private boolean isDraft = false; + private Object policyData = null; + private String gitPath; + private boolean readOnly; + private String configHome; + private String configUrl; + private String finalPolicyPath; + private String version; + private String jsonBody; + private String apiflag; + private String prevJsonBody; + private Integer highestVersion; +// private String actionDictHeader = null; +// private String actionDictType = null; +// private String actionDictUrl = null; +// private String actionDictMethod = null; + private String serviceType = null; + private String uuid = null; + private String location = null; + private String priority = null; + private Map brmsParamBody=null; + private EntityManagerFactory entityManagerFactory = null; + private Boolean policyExists = false; + private String policyScope; + private String providerComboBox = null; + private String riskType; + private String guard; + private String riskLevel; + private String ttlDate; + + + public Integer getHighestVersion() { + return highestVersion; + } + public void setHighestVersion(Integer highestVersion) { + this.highestVersion = highestVersion; + } + public Object getData() { + return data; + } + public void setData(Object data) { + this.data = data; + } + public String getPolicyName() { + return policyName; + } + public void setPolicyName(String policyName) { + this.policyName = policyName; + } + public String getConfigBodyData() { + return configBodyData; + } + public void setConfigBodyData(String configBodyData) { + this.configBodyData = configBodyData; + } + public String getConfigType() { + return configType; + } + public void setConfigType(String configType) { + this.configType = configType; + } + public String getPolicyID() { + return policyID; + } + public void setPolicyID(String policyID) { + this.policyID = policyID; + } + public String getPolicyType() { + return policyType; + } + public void setPolicyType(String policyType) { + this.policyType = policyType; + } + public String getPolicyDescription() { + return policyDescription; + } + public void setPolicyDescription(String policyDescription) { + this.policyDescription = policyDescription; + } + public String getEcompName() { + return ecompName; + } + public void setEcompName(String ecompName) { + this.ecompName = ecompName; + } + public String getConfigName() { + return configName; + } + public void setConfigName(String configName) { + this.configName = configName; + } + public String getRuleID() { + return ruleID; + } + public void setRuleID(String ruleID) { + this.ruleID = ruleID; + } + public String getRuleCombiningAlgId() { + return ruleCombiningAlgId; + } + public void setRuleCombiningAlgId(String ruleCombiningAlgId) { + this.ruleCombiningAlgId = ruleCombiningAlgId; + } + public Map getDynamicFieldConfigAttributes() { + return dynamicFieldConfigAttributes; + } + public void setDynamicFieldConfigAttributes( + Map dynamicFieldConfigAttributes) { + this.dynamicFieldConfigAttributes = dynamicFieldConfigAttributes; + } + public String getParentPath() { + return parentPath; + } + public void setParentPath(String parentPath) { + this.parentPath = parentPath; + } + public boolean isEditPolicy() { + return isEditPolicy; + } + public void setEditPolicy(boolean isEditPolicy) { + this.isEditPolicy = isEditPolicy; + } + public boolean isViewPolicy() { + return isViewPolicy; + } + public void setViewPolicy(boolean isViewPolicy) { + this.isViewPolicy = isViewPolicy; + } + public Object getPolicyData() { + return policyData; + } + public void setPolicyData(Object policyData) { + this.policyData = policyData; + } + public boolean isReadOnly() { + return readOnly; + } + public void setReadOnly(boolean readOnly) { + this.readOnly = readOnly; + } + public String getUserGitPath() { + return gitPath; + } + public void setUserGitPath(String gitPath) { + this.gitPath = gitPath; + } + public boolean isValidData() { + return isValidData; + } + public void setValidData(boolean isValidData) { + this.isValidData = isValidData; + } + public String getAdminNotification() { + return adminNotification; + } + public void setAdminNotification(String adminNotification) { + this.adminNotification = adminNotification; + } + public String getConfigHome() { + return configHome; + } + public void setConfigHome(String configHome) { + this.configHome = configHome; + } + public String getConfigUrl() { + return configUrl; + } + public void setConfigUrl(String configUrl) { + this.configUrl = configUrl; + } + public String getFinalPolicyPath() { + return finalPolicyPath; + } + public void setFinalPolicyPath(String finalPolicyPath) { + this.finalPolicyPath = finalPolicyPath; + } + public String getVersion() { + return version; + } + public void setVersion(String version) { + this.version = version; + } + public String getJsonBody() { + return jsonBody; + } + public void setJsonBody(String jsonBody) { + this.jsonBody = jsonBody; + } + public String getPrevJsonBody() { + return prevJsonBody; + } + public void setPrevJsonBody(String prevJsonBody) { + this.prevJsonBody = prevJsonBody; + } + public String getApiflag() { + return apiflag; + } + public void setApiflag(String apiflag) { + this.apiflag = apiflag; + } + /** + * @return the actionPerformer + */ + public String getActionPerformer() { + return actionPerformer; + } + /** + * @param actionPerformer the actionPerformer to set + */ + public void setActionPerformer(String actionPerformer) { + this.actionPerformer = actionPerformer; + } + /** + * @return the actionAttribute + */ + public String getActionAttribute() { + return actionAttribute; + } + /** + * @param actionAttribute the actionAttribute to set + */ + public void setActionAttribute(String actionAttribute) { + this.actionAttribute = actionAttribute; + } + /** + * @return the dynamicRuleAlgorithmLabels + */ + public List getDynamicRuleAlgorithmLabels() { + return dynamicRuleAlgorithmLabels; + } + /** + * @param dynamicRuleAlgorithmLabels the dynamicRuleAlgorithmLabels to set + */ + public void setDynamicRuleAlgorithmLabels( + List dynamicRuleAlgorithmLabels) { + this.dynamicRuleAlgorithmLabels = dynamicRuleAlgorithmLabels; + } + /** + * @return the dynamicRuleAlgorithmCombo + */ + public List getDynamicRuleAlgorithmCombo() { + return dynamicRuleAlgorithmCombo; + } + /** + * @param dynamicRuleAlgorithmCombo the dynamicRuleAlgorithmCombo to set + */ + public void setDynamicRuleAlgorithmCombo(List dynamicRuleAlgorithmCombo) { + this.dynamicRuleAlgorithmCombo = dynamicRuleAlgorithmCombo; + } + /** + * @return the dynamicRuleAlgorithmField1 + */ + public List getDynamicRuleAlgorithmField1() { + return dynamicRuleAlgorithmField1; + } + /** + * @param dynamicRuleAlgorithmField1 the dynamicRuleAlgorithmField1 to set + */ + public void setDynamicRuleAlgorithmField1( + List dynamicRuleAlgorithmField1) { + this.dynamicRuleAlgorithmField1 = dynamicRuleAlgorithmField1; + } + /** + * @return the dynamicRuleAlgorithmField2 + */ + public List getDynamicRuleAlgorithmField2() { + return dynamicRuleAlgorithmField2; + } + /** + * @param dynamicRuleAlgorithmField2 the dynamicRuleAlgorithmField2 to set + */ + public void setDynamicRuleAlgorithmField2( + List dynamicRuleAlgorithmField2) { + this.dynamicRuleAlgorithmField2 = dynamicRuleAlgorithmField2; + } + public Map getDropDownMap() { + return dropDownMap; + } + public void setDropDownMap(Map dropDownMap) { + this.dropDownMap = dropDownMap; + } +/* public String getActionDictHeader() { + return actionDictHeader; + } + public void setActionDictHeader(String actionDictHeader) { + this.actionDictHeader = actionDictHeader; + } + public String getActionDictType() { + return actionDictType; + } + public void setActionDictType(String actionDictType) { + this.actionDictType = actionDictType; + } + public String getActionDictUrl() { + return actionDictUrl; + } + public void setActionDictUrl(String actionDictUrl) { + this.actionDictUrl = actionDictUrl; + } + public String getActionDictMethod() { + return actionDictMethod; + } + public void setActionDictMethod(String actionDictMethod) { + this.actionDictMethod = actionDictMethod; + }*/ + public Map getDynamicSettingsMap() { + return dynamicSettingsMap; + } + public void setDynamicSettingsMap(Map dynamicSettingsMap) { + this.dynamicSettingsMap = dynamicSettingsMap; + } + public List getDynamicVariableList() { + return dynamicVariableList; + } + public void setDynamicVariableList(List dynamicVariableList) { + this.dynamicVariableList = dynamicVariableList; + } + public List getDataTypeList() { + return dataTypeList; + } + public void setDataTypeList(List dataTypeList) { + this.dataTypeList = dataTypeList; + } + public boolean isDraft() { + return isDraft; + } + public void setDraft(boolean isDraft) { + this.isDraft = isDraft; + } + public String getConfigPolicyType() { + return configPolicyType; + } + public void setConfigPolicyType(String configPolicyType) { + this.configPolicyType = configPolicyType; + } + public String getServiceType() { + return serviceType; + } + public void setServiceType(String serviceType) { + this.serviceType = serviceType; + } + public String getUuid() { + return uuid; + } + public void setUuid(String uuid) { + this.uuid = uuid; + } + public String getLocation() { + return location; + } + public void setLocation(String location) { + this.location = location; + } + public String getPriority() { + return priority; + } + public void setPriority(String priority) { + this.priority = priority; + } + public Map getBrmsParamBody() { + return brmsParamBody; + } + public void setBrmsParamBody(Map brmsParamBody) { + this.brmsParamBody = brmsParamBody; + } + public EntityManagerFactory getEntityManagerFactory() { + return entityManagerFactory; + } + public void setEntityManagerFactory(EntityManagerFactory entityManagerFactory) { + this.entityManagerFactory = entityManagerFactory; + } + /** + * @return the policyExists + */ + public Boolean getPolicyExists() { + return policyExists; + } + /** + * @param policyExists the policyExists to set + */ + public void setPolicyExists(Boolean policyExists) { + this.policyExists = policyExists; + } + public String getPolicyScope() { + return policyScope; + } + + public void setPolicyScope(String domainDir) { + this. policyScope=domainDir; + } + public String getProviderComboBox() { + return providerComboBox; + } + public void setProviderComboBox(String providerComboBox) { + this.providerComboBox = providerComboBox; + } + public String getRiskType() { + return riskType; + } + public void setRiskType(String riskType) { + this.riskType = riskType; + } + public String getGuard() { + return guard; + } + public void setGuard(String guard) { + this.guard = guard; + } + public String getRiskLevel() { + return riskLevel; + } + public void setRiskLevel(String riskLevel) { + this.riskLevel = riskLevel; + } + public String getTtlDate() { + return ttlDate; + } + public void setTtlDate(String ttlDate) { + this.ttlDate = ttlDate; + } +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/adapters/package-info.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/adapters/package-info.java new file mode 100644 index 000000000..fd5f06462 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/adapters/package-info.java @@ -0,0 +1,27 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + * + */ +/** + * + */ +package org.openecomp.policy.pap.xacml.rest.adapters; diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/ActionPolicy.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/ActionPolicy.java new file mode 100644 index 000000000..b6e003c91 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/ActionPolicy.java @@ -0,0 +1,626 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.components; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Arrays; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.Query; + +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.ApplyType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeAssignmentExpressionType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.ConditionType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.EffectType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObjectFactory; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObligationExpressionType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObligationExpressionsType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.RuleType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType; + +import org.apache.commons.io.FilenameUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openecomp.policy.pap.xacml.rest.adapters.PolicyRestAdapter; +import org.openecomp.policy.pap.xacml.rest.util.JPAUtils; +import org.openecomp.policy.rest.jpa.ActionPolicyDict; +import org.openecomp.policy.rest.jpa.Datatype; +import org.openecomp.policy.rest.jpa.FunctionDefinition; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.eelf.PolicyLogger; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +public class ActionPolicy extends Policy { + + /** + * Config Fields + */ + private static final Logger logger = FlexLogger.getLogger(ConfigPolicy.class); + + public static final String JSON_CONFIG = "JSON"; + public static final String XML_CONFIG = "XML"; + public static final String PROPERTIES_CONFIG = "PROPERTIES"; + public static final String OTHER_CONFIG = "OTHER"; + + public static final String PDP_ACTION = "PDP"; + public static final String PEP_ACTION = "PEP"; + public static final String TYPE_ACTION = "REST"; + + public static final String GET_METHOD = "GET"; + public static final String PUT_METHOD = "PUT"; + public static final String POST_METHOD = "POST"; + + public static final String PERFORMER_ATTRIBUTEID = "performer"; + public static final String TYPE_ATTRIBUTEID = "type"; + public static final String METHOD_ATTRIBUTEID = "method"; + public static final String HEADERS_ATTRIBUTEID = "headers"; + public static final String URL_ATTRIBUTEID = "url"; + public static final String BODY_ATTRIBUTEID = "body"; + + List dynamicLabelRuleAlgorithms = new LinkedList(); + List dynamicFieldFunctionRuleAlgorithms = new LinkedList(); + List dynamicFieldOneRuleAlgorithms = new LinkedList(); + List dynamicFieldTwoRuleAlgorithms = new LinkedList(); + + protected Map dropDownMap = new HashMap(); + + public ActionPolicy() { + super(); + } + + public ActionPolicy(PolicyRestAdapter policyAdapter){ + this.policyAdapter = policyAdapter; + } + + @Override + public Map savePolicies() throws Exception { + + Map successMap = new HashMap(); + if(isPolicyExists()){ + successMap.put("EXISTS", "This Policy already exist on the PAP"); + return successMap; + } + + if(!isPreparedToSave()){ + //Prep and configure the policy for saving + prepareToSave(); + } + + // Until here we prepared the data and here calling the method to create xml. + Path newPolicyPath = null; + newPolicyPath = Paths.get(policyAdapter.getParentPath().toString(), policyName); + successMap = createPolicy(newPolicyPath,getCorrectPolicyDataObject() ); + if (successMap.containsKey("success")) { + Path finalPolicyPath = getFinalPolicyPath(); + policyAdapter.setFinalPolicyPath(finalPolicyPath.toString()); + } + return successMap; + } + + //This is the method for preparing the policy for saving. We have broken it out + //separately because the fully configured policy is used for multiple things + @Override + public boolean prepareToSave() throws Exception{ + + if(isPreparedToSave()){ + //we have already done this + return true; + } + + int version = 0; + String policyID = policyAdapter.getPolicyID(); + + if (policyAdapter.isEditPolicy()) { + version = policyAdapter.getHighestVersion() + 1; + } else { + version = 1; + } + + // Create the Instance for pojo, PolicyType object is used in marshalling. + if (policyAdapter.getPolicyType().equals("Action")) { + PolicyType policyConfig = new PolicyType(); + + policyConfig.setVersion(Integer.toString(version)); + policyConfig.setPolicyId(policyID); + policyConfig.setTarget(new TargetType()); + policyAdapter.setData(policyConfig); + } + + if (policyAdapter.getData() != null) { + + // Save off everything + // making ready all the required elements to generate the action policy xml. + // Get the uniqueness for policy name. + Path newFile = getNextFilename(Paths.get(policyAdapter.getParentPath().toString()), policyAdapter.getPolicyType(), policyAdapter.getPolicyName(), version); + if (newFile == null) { + //TODO:EELF Cleanup - Remove logger + //logger.error("Policy already Exists, cannot create the policy."); + PolicyLogger.error("Policy already Exists, cannot create the policy."); + setPolicyExists(true); + return false; + } + policyName = newFile.getFileName().toString(); + + // Action body is optional so checking value provided or not + //String actionBodyString = policyAdapter.getActionBody(); + String comboDictValue = policyAdapter.getActionAttribute(); + String actionBody = getActionPolicyDict(comboDictValue).getBody(); + if(!(actionBody==null || "".equals(actionBody))){ + saveActionBody(policyName, actionBody); + } + + // Make sure the filename ends with an extension + if (policyName.endsWith(".xml") == false) { + policyName = policyName + ".xml"; + } + + PolicyType actionPolicy = (PolicyType) policyAdapter.getData(); + + actionPolicy.setDescription(policyAdapter.getPolicyDescription()); + + actionPolicy.setRuleCombiningAlgId(policyAdapter.getRuleCombiningAlgId()); + + AllOfType allOf = new AllOfType(); + + Map dynamicFieldComponentAttributes = policyAdapter.getDynamicFieldConfigAttributes(); + + // If there is any dynamic field attributes create the matches here + for (String keyField : dynamicFieldComponentAttributes.keySet()) { + String key = keyField; + String value = dynamicFieldComponentAttributes.get(key); + MatchType dynamicMatch = createDynamicMatch(key, value); + allOf.getMatch().add(dynamicMatch); + } + + AnyOfType anyOf = new AnyOfType(); + anyOf.getAllOf().add(allOf); + + TargetType target = new TargetType(); + target.getAnyOf().add(anyOf); + + // Adding the target to the policy element + actionPolicy.setTarget(target); + + RuleType rule = new RuleType(); + rule.setRuleId(policyAdapter.getRuleID()); + + rule.setEffect(EffectType.PERMIT); + rule.setTarget(new TargetType()); + + dynamicLabelRuleAlgorithms = policyAdapter.getDynamicRuleAlgorithmLabels(); + dynamicFieldFunctionRuleAlgorithms = policyAdapter.getDynamicRuleAlgorithmCombo(); + dynamicFieldOneRuleAlgorithms = policyAdapter.getDynamicRuleAlgorithmField1(); + dynamicFieldTwoRuleAlgorithms = policyAdapter.getDynamicRuleAlgorithmField2(); + //dropDownMap = policyAdapter.getDropDownMap(); + dropDownMap = createDropDownMap(); + + // Rule attributes are optional and dynamic so check and add them to condition. + if (dynamicLabelRuleAlgorithms != null && dynamicLabelRuleAlgorithms.size() > 0) { + boolean isCompound = false; + ConditionType condition = new ConditionType(); + int index = dynamicFieldOneRuleAlgorithms.size() - 1; + + for (String labelAttr : dynamicLabelRuleAlgorithms) { + // if the rule algorithm as a label means it is a compound + if (dynamicFieldOneRuleAlgorithms.get(index).toString().equals(labelAttr)) { + ApplyType actionApply = new ApplyType(); + + String selectedFunction = (String) dynamicFieldFunctionRuleAlgorithms.get(index).toString(); + String value1 = (String) dynamicFieldOneRuleAlgorithms.get(index).toString(); + String value2 = dynamicFieldTwoRuleAlgorithms.get(index).toString(); + actionApply.setFunctionId(dropDownMap.get(selectedFunction)); + actionApply.getExpression().add(new ObjectFactory().createApply(getInnerActionApply(value1))); + actionApply.getExpression().add(new ObjectFactory().createApply(getInnerActionApply(value2))); + condition.setExpression(new ObjectFactory().createApply(actionApply)); + isCompound = true; + } + + } + // if rule algorithm not a compound + if (!isCompound) { + condition.setExpression(new ObjectFactory().createApply(getInnerActionApply(dynamicLabelRuleAlgorithms.get(index).toString()))); + } + rule.setCondition(condition); + } + // set the obligations to rule + rule.setObligationExpressions(getObligationExpressions()); + actionPolicy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().add(rule); + policyAdapter.setPolicyData(actionPolicy); + } else { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Unsupported data object." + policyAdapter.getData().getClass().getCanonicalName()); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + "Unsupported data object." + policyAdapter.getData().getClass().getCanonicalName()); + } + + setPreparedToSave(true); + return true; + } + + // Saving the json Configurations file if exists at server location for action policy. + private void saveActionBody(String policyName, String actionBodyData) { + int version = 0; + int highestVersion = 0; + String domain = getParentPathSubScopeDir(); + String path = domain.replace('\\', '.'); + String removeExtension = policyName.substring(0, policyName.indexOf(".xml")); + String removeVersion = removeExtension.substring(0, removeExtension.indexOf(".")); + if (policyAdapter.isEditPolicy()) { + highestVersion = policyAdapter.getHighestVersion(); + if(highestVersion != 0){ + version = highestVersion + 1; + } + } else { + version = 1; + } + if(path.contains("/")){ + path = domain.replace('/', '.'); + logger.info("print the path:" +path); + } + try { + + File file = new File(ACTION_HOME + File.separator + path + "." + removeVersion + "." + version + ".json"); + + if (logger.isDebugEnabled()) + logger.debug("The action body is at " + file.getAbsolutePath()); + + // if file doesn't exists, then create it + if (!file.exists()) { + file.createNewFile(); + } + File configHomeDir = new File(ACTION_HOME); + File[] listOfFiles = configHomeDir.listFiles(); + if (listOfFiles != null){ + for(File eachFile : listOfFiles){ + if(eachFile.isFile()){ + String fileNameWithoutExtension = FilenameUtils.removeExtension(eachFile.getName()); + String actionFileNameWithoutExtension = FilenameUtils.removeExtension(path + "." + policyName); + if (fileNameWithoutExtension.equals(actionFileNameWithoutExtension)){ + //delete the file + if (logger.isInfoEnabled()) + logger.info("Deleting action body is at " + eachFile.getAbsolutePath()); + eachFile.delete(); + } + } + } + } + FileWriter fw = new FileWriter(file.getAbsoluteFile()); + BufferedWriter bw = new BufferedWriter(fw); + bw.write(actionBodyData); + bw.close(); + + if (logger.isInfoEnabled()) { + logger.info("Action Body is succesfully saved at " + file.getAbsolutePath()); + } + } catch (IOException e) { + e.printStackTrace(); + } + + } + + // Data required for obligation part is setting here. + private ObligationExpressionsType getObligationExpressions() { + + // TODO: add code to get all these values from dictionary + ObligationExpressionsType obligations = new ObligationExpressionsType(); + + ObligationExpressionType obligation = new ObligationExpressionType(); + String comboDictValue = policyAdapter.getActionAttribute(); + obligation.setObligationId(comboDictValue); + obligation.setFulfillOn(EffectType.PERMIT); + + // Add Action Assignment: + AttributeAssignmentExpressionType assignment1 = new AttributeAssignmentExpressionType(); + assignment1.setAttributeId(PERFORMER_ATTRIBUTEID); + assignment1.setCategory(CATEGORY_RECIPIENT_SUBJECT); + + AttributeValueType actionNameAttributeValue = new AttributeValueType(); + actionNameAttributeValue.setDataType(STRING_DATATYPE); + actionNameAttributeValue.getContent().add(performer.get(policyAdapter.getActionPerformer())); + + assignment1.setExpression(new ObjectFactory().createAttributeValue(actionNameAttributeValue)); + obligation.getAttributeAssignmentExpression().add(assignment1); + + // Add Type Assignment: + AttributeAssignmentExpressionType assignmentType = new AttributeAssignmentExpressionType(); + assignmentType.setAttributeId(TYPE_ATTRIBUTEID); + assignmentType.setCategory(CATEGORY_RESOURCE); + + AttributeValueType typeAttributeValue = new AttributeValueType(); + typeAttributeValue.setDataType(STRING_DATATYPE); + String actionDictType = getActionPolicyDict(comboDictValue).getType(); + typeAttributeValue.getContent().add(actionDictType); + + assignmentType.setExpression(new ObjectFactory().createAttributeValue(typeAttributeValue)); + obligation.getAttributeAssignmentExpression().add(assignmentType); + + // Add Rest_URL Assignment: + AttributeAssignmentExpressionType assignmentURL = new AttributeAssignmentExpressionType(); + assignmentURL.setAttributeId(URL_ATTRIBUTEID); + assignmentURL.setCategory(CATEGORY_RESOURCE); + + AttributeValueType actionURLAttributeValue = new AttributeValueType(); + actionURLAttributeValue.setDataType(URI_DATATYPE); + String actionDictUrl = getActionPolicyDict(comboDictValue).getUrl(); + actionURLAttributeValue.getContent().add(actionDictUrl); + + assignmentURL.setExpression(new ObjectFactory().createAttributeValue(actionURLAttributeValue)); + obligation.getAttributeAssignmentExpression().add(assignmentURL); + + // Add Method Assignment: + AttributeAssignmentExpressionType assignmentMethod = new AttributeAssignmentExpressionType(); + assignmentMethod.setAttributeId(METHOD_ATTRIBUTEID); + assignmentMethod.setCategory(CATEGORY_RESOURCE); + + AttributeValueType methodAttributeValue = new AttributeValueType(); + methodAttributeValue.setDataType(STRING_DATATYPE); + String actionDictMethod = getActionPolicyDict(comboDictValue).getMethod(); + methodAttributeValue.getContent().add(actionDictMethod); + + assignmentMethod.setExpression(new ObjectFactory().createAttributeValue(methodAttributeValue)); + obligation.getAttributeAssignmentExpression().add(assignmentMethod); + + // Add JSON_URL Assignment: + String actionBody = getActionPolicyDict(comboDictValue).getBody(); + if (!actionBody.equals(null)) { + //if(!(actionBody==null || "".equals(actionBody))){ + AttributeAssignmentExpressionType assignmentJsonURL = new AttributeAssignmentExpressionType(); + assignmentJsonURL.setAttributeId(BODY_ATTRIBUTEID); + assignmentJsonURL.setCategory(CATEGORY_RESOURCE); + + AttributeValueType jsonURLAttributeValue = new AttributeValueType(); + jsonURLAttributeValue.setDataType(URI_DATATYPE); + final Path gitPath = Paths.get(policyAdapter.getUserGitPath().toString());; + String policyDir = policyAdapter.getParentPath().toString(); + int startIndex1 = policyDir.indexOf(gitPath.toString()) + gitPath.toString().length() + 1; + policyDir = policyDir.substring(startIndex1, policyDir.length()); + logger.info("print the main domain value"+policyDir); + String path = policyDir.replace('\\', '.'); + if(path.contains("/")){ + path = policyDir.replace('/', '.'); + logger.info("print the path:" +path); + } + jsonURLAttributeValue.getContent().add(CONFIG_URL + "/Action/" + path + "." +FilenameUtils.removeExtension(policyName) + ".json"); + + assignmentJsonURL.setExpression(new ObjectFactory().createAttributeValue(jsonURLAttributeValue)); + obligation.getAttributeAssignmentExpression().add(assignmentJsonURL); + } + + if(!getActionPolicyDict(comboDictValue).getHeader().equals(null)){ + String headerVal = getActionPolicyDict(comboDictValue).getHeader(); + if(headerVal != null && !headerVal.equals("")){ + // parse it on : to get number of headers + String[] result = headerVal.split(":"); + System.out.println(Arrays.toString(result)); + for (String eachString : result){ + // parse each value on = + String[] textFieldVals = eachString.split("="); + obligation.getAttributeAssignmentExpression().add(addDynamicHeaders(textFieldVals[0], textFieldVals[1])); + } + } + + } + + obligations.getObligationExpression().add(obligation); + return obligations; + } + + + // if compound setting the inner apply here + protected ApplyType getInnerActionApply(String value1Label) { + ApplyType actionApply = new ApplyType(); + int index = 0; + // check the index for the label. + for (String labelAttr : dynamicLabelRuleAlgorithms) { + if (labelAttr.equals(value1Label)) { + String value1 = dynamicFieldOneRuleAlgorithms.get(index).toString(); + // check if the row contains label again + for (String labelValue : dynamicLabelRuleAlgorithms) { + if (labelValue.equals(value1)) { + return getCompoundApply(index); + } + } + + // Getting the values from the form. + String functionKey = dynamicFieldFunctionRuleAlgorithms.get(index).toString(); + String value2 = dynamicFieldTwoRuleAlgorithms.get(index).toString(); + actionApply.setFunctionId(dropDownMap.get(functionKey)); + // if two text field are rule attributes. + if ((value1.contains(RULE_VARIABLE)) && (value2.contains(RULE_VARIABLE))) { + ApplyType innerActionApply1 = new ApplyType(); + ApplyType innerActionApply2 = new ApplyType(); + AttributeDesignatorType attributeDesignator1 = new AttributeDesignatorType(); + AttributeDesignatorType attributeDesignator2 = new AttributeDesignatorType(); + // If selected function is Integer function set integer functionID + if (functionKey.toLowerCase().contains("integer")) { + innerActionApply1.setFunctionId(FUNTION_INTEGER_ONE_AND_ONLY); + innerActionApply2.setFunctionId(FUNTION_INTEGER_ONE_AND_ONLY); + attributeDesignator1.setDataType(INTEGER_DATATYPE); + attributeDesignator2.setDataType(INTEGER_DATATYPE); + } else { + // If selected function is not a Integer function + // set String functionID + innerActionApply1.setFunctionId(FUNCTION_STRING_ONE_AND_ONLY); + innerActionApply2.setFunctionId(FUNCTION_STRING_ONE_AND_ONLY); + attributeDesignator1.setDataType(STRING_DATATYPE); + attributeDesignator2.setDataType(STRING_DATATYPE); + } + attributeDesignator1.setCategory(CATEGORY_RESOURCE); + attributeDesignator2.setCategory(CATEGORY_RESOURCE); + + // Here set actual field values + attributeDesignator1.setAttributeId(value1.contains("resource:") ? value1.substring(9): value1.substring(8)); + attributeDesignator2.setAttributeId(value1.contains("resource:") ? value1.substring(9): value1.substring(8)); + + innerActionApply1.getExpression().add(new ObjectFactory().createAttributeDesignator(attributeDesignator1)); + innerActionApply2.getExpression().add(new ObjectFactory().createAttributeDesignator(attributeDesignator2)); + + actionApply.getExpression().add(new ObjectFactory().createApply(innerActionApply1)); + actionApply.getExpression().add(new ObjectFactory().createApply(innerActionApply2)); + + } else {// if either of one text field is rule attribute. + ApplyType innerActionApply = new ApplyType(); + AttributeDesignatorType attributeDesignator = new AttributeDesignatorType(); + AttributeValueType actionConditionAttributeValue = new AttributeValueType(); + + if (functionKey.toLowerCase().contains("integer")) { + innerActionApply.setFunctionId(FUNTION_INTEGER_ONE_AND_ONLY); + actionConditionAttributeValue.setDataType(INTEGER_DATATYPE); + attributeDesignator.setDataType(INTEGER_DATATYPE); + } else { + innerActionApply.setFunctionId(FUNCTION_STRING_ONE_AND_ONLY); + actionConditionAttributeValue.setDataType(STRING_DATATYPE); + attributeDesignator.setDataType(STRING_DATATYPE); + } + + String attributeId = null; + String attributeValue = null; + + // Find which textField has rule attribute and set it as + attributeId = value1; + attributeValue = value2; + + if (attributeId != null) { + attributeDesignator.setCategory(CATEGORY_RESOURCE); + attributeDesignator.setAttributeId(attributeId); + } + actionConditionAttributeValue.getContent().add(attributeValue); + innerActionApply.getExpression().add(new ObjectFactory().createAttributeDesignator(attributeDesignator)); + // Decide the order of element based the values. + if (attributeId.equals(value1)) { + actionApply.getExpression().add(new ObjectFactory().createApply(innerActionApply)); + actionApply.getExpression().add(new ObjectFactory().createAttributeValue(actionConditionAttributeValue)); + } else { + actionApply.getExpression().add(new ObjectFactory().createAttributeValue(actionConditionAttributeValue)); + actionApply.getExpression().add(new ObjectFactory().createApply(innerActionApply)); + } + } + } + index++; + } + return actionApply; + } + + // if the rule algorithm is multiple compound one setting the apply + protected ApplyType getCompoundApply(int index) { + ApplyType actionApply = new ApplyType(); + String selectedFunction = dynamicFieldFunctionRuleAlgorithms.get(index).toString(); + String value1 = dynamicFieldOneRuleAlgorithms.get(index).toString(); + String value2 = dynamicFieldTwoRuleAlgorithms.get(index).toString(); + actionApply.setFunctionId(dropDownMap.get(selectedFunction)); + actionApply.getExpression().add(new ObjectFactory().createApply(getInnerActionApply(value1))); + actionApply.getExpression().add(new ObjectFactory().createApply(getInnerActionApply(value2))); + return actionApply; + } + + // Adding the dynamic headers if any + private AttributeAssignmentExpressionType addDynamicHeaders(String header, String value) { + AttributeAssignmentExpressionType assignmentHeaders = new AttributeAssignmentExpressionType(); + assignmentHeaders.setAttributeId("headers:" + header); + assignmentHeaders.setCategory(CATEGORY_RESOURCE); + + AttributeValueType headersAttributeValue = new AttributeValueType(); + headersAttributeValue.setDataType(STRING_DATATYPE); + headersAttributeValue.getContent().add(value); + + assignmentHeaders.setExpression(new ObjectFactory().createAttributeValue(headersAttributeValue)); + return assignmentHeaders; + } + + private Map createDropDownMap(){ + JPAUtils jpaUtils = null; + try { + jpaUtils = JPAUtils.getJPAUtilsInstance(policyAdapter.getEntityManagerFactory()); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + Map> functionMap = jpaUtils.getFunctionDatatypeMap(); + Map dropDownMap = new HashMap(); + for (Datatype id : functionMap.keySet()) { + List functionDefinitions = (List) functionMap + .get(id); + for (FunctionDefinition functionDef : functionDefinitions) { + dropDownMap.put(functionDef.getShortname(),functionDef.getXacmlid()); + } + } + + return dropDownMap; + } + + private ActionPolicyDict getActionPolicyDict(String attributeName){ + ActionPolicyDict retObj = new ActionPolicyDict(); + //EntityManagerFactory emf = policyAdapter.getEntityManagerFactory(); + //EntityManager em = emf.createEntityManager(); + EntityManager em = policyAdapter.getEntityManagerFactory().createEntityManager(); + Query getActionPolicyDicts = em.createNamedQuery("ActionPolicyDict.findAll"); + List actionPolicyDicts = getActionPolicyDicts.getResultList(); + + for (Object id : actionPolicyDicts) { + //ActionPolicyDict actionPolicyList = actionPolicyDicts.getItem(id).getEntity(); + ActionPolicyDict actionPolicy = (ActionPolicyDict) id; + if(attributeName.equals(actionPolicy.getAttributeName())){ + retObj = actionPolicy; + break; + } + } + + try{ + em.getTransaction().commit(); + } catch(Exception e){ + try{ + em.getTransaction().rollback(); + } catch(Exception e2){ + e2.printStackTrace(); + } + } + em.close(); + + return retObj; + } + + @Override + public Object getCorrectPolicyDataObject() { + return policyAdapter.getPolicyData(); + } + + + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/AutoPushPolicy.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/AutoPushPolicy.java new file mode 100644 index 000000000..61498e2ac --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/AutoPushPolicy.java @@ -0,0 +1,170 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.components; + +import java.io.File; +import java.io.FileInputStream; +import java.nio.file.Paths; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Properties; +import java.util.Set; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.eelf.PolicyLogger; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; +import org.openecomp.policy.xacml.api.pap.EcompPDPGroup; +import org.openecomp.policy.xacml.api.pap.PAPPolicyEngine; + +import com.att.research.xacml.api.pap.PAPEngine; +import com.att.research.xacml.api.pap.PDPPolicy; +import org.openecomp.policy.xacml.std.pap.StdPDPGroup; +import org.openecomp.policy.xacml.std.pap.StdPDPPolicy; +/** + * Auto Push Policy based on the property file properties. + * + * @version 0.1 + */ +public class AutoPushPolicy { + + private static final Logger logger = FlexLogger.getLogger(AutoPushPolicy.class); + + private String filePath = null; + private Properties properties; + private Long newModified; + private Long oldModified; + private File propFile; + + + /** + * Constructor Pass in the property file path. + */ + public AutoPushPolicy(String file){ + filePath = file; + properties = new Properties(); + propFile = Paths.get(filePath).toFile(); + readFile(); + } + + /** + * Checks Policy with all the Groups which has set such Property. + * Else returns Empty Set. + * + * @param policyToCreateUpdate + * @param papEngine + */ + public Set checkGroupsToPush(String policyToCreateUpdate, PAPPolicyEngine papEngine) { + Set changedGroups= new HashSet(); + // Check if the file has been modified. then re-load the properties file. + newModified = propFile.lastModified(); + try { + if(newModified!=oldModified){ + // File has been updated. + readFile(); + } + // Read the File name as its made. + String gitPath = PolicyDBDao.getGitPath(); + String policyId = policyToCreateUpdate.substring(policyToCreateUpdate.indexOf(gitPath)+gitPath.length()+1); + String policyName = policyId.substring(policyId.lastIndexOf(File.separator)+1,policyId.lastIndexOf(".")); + policyName = policyName.substring(0,policyName.lastIndexOf(".")); + policyId = policyId.replace("/", "."); + if(policyId.contains("\\")){ + policyId = policyId.replace("\\", "."); + } + logger.info("Policy ID : " + policyId); + logger.info("Policy Name : " + policyName); + // Read in Groups + for(EcompPDPGroup pdpGroup: papEngine.getEcompPDPGroups()){ + String groupName = pdpGroup.getName(); + Boolean typeFlag = false; + Boolean scopeFlag = false; + if(properties.containsKey(groupName + ".policyType")){ + String type= properties.getProperty(groupName + ".policyType").replaceAll(" ",""); + if(type.equals("")){ + type = " "; + } + typeFlag = policyName.contains(type); + } + if(properties.containsKey(groupName + ".policyScope")){ + String scope = properties.getProperty(groupName + ".policyScope").replaceAll(" ", ""); + if(scope.equals("")){ + scope = " "; + } + scopeFlag = policyId.contains(scope); + } + if(typeFlag || scopeFlag){ + StdPDPGroup group = addToGroup(policyId,policyName, policyToCreateUpdate, (StdPDPGroup)pdpGroup); + changedGroups.add(group); + } + } + } catch (Exception e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error while processing the auto push for " + policyToCreateUpdate +"\n " + e.getMessage()); + PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "AutoPushPolicy", "Error while processing the auto push for " + policyToCreateUpdate); + } + return changedGroups; + } + + private void readFile(){ + try { + properties.load(new FileInputStream(propFile)); + oldModified = propFile.lastModified(); + } catch (Exception e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error while loading in the auto push properties file. " + propFile.toString()); + PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "AutoPushPolicy", "Error while loading in the auto push properties file."); + } + } + + private StdPDPGroup addToGroup(String policyId, String policyName, String policyToCreateUpdate, StdPDPGroup pdpGroup) throws Exception{ + // Add to group. Send Notification. + StdPDPPolicy policy = new StdPDPPolicy(policyId, true, policyName, Paths.get(policyToCreateUpdate).toUri()); + //Get the current policies from the Group and Add the new one + Set currentPoliciesInGroup = pdpGroup.getPolicies(); + Set policies = new HashSet(); + if(policy!=null){ + policies.add(policy); + } + pdpGroup.copyPolicyToFile(policyId, new FileInputStream(Paths.get(policyToCreateUpdate).toFile())); + //If the selected policy is in the group we must remove it because the name is default + Iterator policyIterator = policies.iterator(); + while (policyIterator.hasNext()) { + PDPPolicy selPolicy = policyIterator.next(); + for (PDPPolicy existingPolicy : currentPoliciesInGroup) { + if (existingPolicy.getId().equals(selPolicy.getId())) { + pdpGroup.removePolicyFromGroup(existingPolicy); + logger.debug("Removing policy: " + existingPolicy); + break; + } + } + } + if(currentPoliciesInGroup!=null){ + policies.addAll(currentPoliciesInGroup); + } + pdpGroup.setPolicies(policies); + return pdpGroup; + } +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/ClosedLoopPolicy.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/ClosedLoopPolicy.java new file mode 100644 index 000000000..8c3e34d6e --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/ClosedLoopPolicy.java @@ -0,0 +1,552 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.components; + +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; +import java.net.URI; +import java.net.URISyntaxException; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.Map; +import java.util.StringTokenizer; + +import javax.json.stream.JsonGenerationException; + +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionsType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeAssignmentExpressionType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.EffectType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObjectFactory; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.RuleType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType; + +import org.apache.commons.io.FilenameUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openecomp.policy.pap.xacml.rest.adapters.PolicyRestAdapter; + +import com.att.research.xacml.std.IdentifierImpl; + +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.eelf.PolicyLogger; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +public class ClosedLoopPolicy extends Policy { + + /** + * Config Fields + */ + private static final Logger logger = FlexLogger.getLogger(ConfigPolicy.class); + + public ClosedLoopPolicy() { + super(); + } + + public ClosedLoopPolicy(PolicyRestAdapter policyAdapter){ + this.policyAdapter = policyAdapter; + } + + //save configuration of the policy based on the policyname + private void saveConfigurations(String policyName, String prevPolicyName, String jsonBody) { + String domain = getParentPathSubScopeDir(); + String path = domain.replace('\\', '.'); + if(path.contains("/")){ + path = domain.replace('/', '.'); + logger.info("print the path:" +path); + } + try { + String body = jsonBody; + try { + try{ + //Remove the trapMaxAge in Verification Signature + body = body.replace(",\"trapMaxAge\":null", ""); + }catch(Exception e){ + logger.debug("No Trap Max Age in JSON body"); + } + this.policyAdapter.setJsonBody(body); + } catch (Exception e) { + e.printStackTrace(); + } + + System.out.println(body); + if(policyName.endsWith(".xml")){ + policyName = policyName.substring(0, policyName.lastIndexOf(".xml")); + } + PrintWriter out = new PrintWriter(CONFIG_HOME + File.separator+path + "."+ policyName +".json"); + out.println(body); + out.close(); + + } catch (JsonGenerationException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + + } + + //Utility to read json data from the existing file to a string + static String readFile(String path, Charset encoding) throws IOException { + + byte[] encoded = Files.readAllBytes(Paths.get(path)); + return new String(encoded, encoding); + + } + + //create the configuration file based on the policy name on adding the extension as .json + private String getConfigFile(String filename) { + filename = FilenameUtils.removeExtension(filename); + if (filename.endsWith(".xml")) { + filename = filename.substring(0, filename.length() - 4); + } + filename = filename + ".json"; + return filename; + } + + @Override + public Map savePolicies() throws Exception { + + Map successMap = new HashMap(); + if(isPolicyExists()){ + successMap.put("EXISTS", "This Policy already exist on the PAP"); + return successMap; + } + + if(!isPreparedToSave()){ + prepareToSave(); + } + + // Until here we prepared the data and here calling the method to create xml. + Path newPolicyPath = null; + newPolicyPath = Paths.get(policyAdapter.getParentPath().toString(), policyName); + + successMap = createPolicy(newPolicyPath,getCorrectPolicyDataObject()); + if (successMap.containsKey("success")) { + Path finalPolicyPath = getFinalPolicyPath(); + policyAdapter.setFinalPolicyPath(finalPolicyPath.toString()); + } + return successMap; + } + + //This is the method for preparing the policy for saving. We have broken it out + //separately because the fully configured policy is used for multiple things + @Override + public boolean prepareToSave() throws Exception{ + + if(isPreparedToSave()){ + //we have already done this + return true; + } + + int version = 0; + String policyID = policyAdapter.getPolicyID(); + + if (policyAdapter.isEditPolicy()) { + version = policyAdapter.getHighestVersion() + 1; + } else { + version = 1; + } + + // Create the Instance for pojo, PolicyType object is used in marshalling. + if (policyAdapter.getPolicyType().equals("Config")) { + PolicyType policyConfig = new PolicyType(); + + policyConfig.setVersion(Integer.toString(version)); + policyConfig.setPolicyId(policyID); + policyConfig.setTarget(new TargetType()); + policyAdapter.setData(policyConfig); + } + + if (policyAdapter.getData() != null) { + + //delete the closed loop draft file and configuration file, if validation is success after editing the draft policy + String prevPolicyName = null; + if(policyAdapter.isEditPolicy()){ + prevPolicyName = "Config_Fault_" + policyAdapter.getPolicyName() + "." + policyAdapter.getHighestVersion() + ".xml"; + + if (policyAdapter.isDraft()) { + policyName = "Config_Fault_" + policyAdapter.getPolicyName() + "_Draft"; + } else { + policyName = "Config_Fault_" + policyAdapter.getPolicyName(); + } + + //delete the closed loop draft configuration file, if validation is success after editing the draft policy + final Path gitPath = Paths.get(policyAdapter.getUserGitPath()); + String policyDir = policyAdapter.getParentPath(); + int startIndex = policyDir.indexOf(gitPath.toString()) + gitPath.toString().length() + 1; + policyDir = policyDir.substring(startIndex, policyDir.length()); + logger.info("print the main domain value"+policyDir); + String path = policyDir.replace('\\', '.'); + if(path.contains("/")){ + path = policyDir.replace('/', '.'); + logger.info("print the path:" +path); + } + String fileName = FilenameUtils.removeExtension(policyName); + + final String tempPath = path; + String fileLocation = null; + if (fileName != null && fileName.contains("Config_Fault_")) { + fileLocation = CONFIG_HOME; + } + // Get the file from the saved location + File dir = new File(fileLocation); + File[] listOfFiles = dir.listFiles(); + for (File file : listOfFiles) { + String configFile = null; + if(!policyAdapter.isDraft()){ + configFile = fileName + "_Draft"; + }else{ + configFile = fileName; + } + if (file.isFile() && file.getName().contains( tempPath + "." + configFile)) { + try { + if (file.delete() == false) { + throw new Exception( + "No known error, Delete failed"); + } + } catch (Exception e) { + logger.error("Failed to Delete file: " + + e.getLocalizedMessage()); + } + } + } + } + + // Save off everything + // making ready all the required elements to generate the action policy xml. + // Get the uniqueness for policy name. + String policyName1 = null; + if(policyAdapter.isDraft()){ + policyName1 = policyAdapter.getPolicyName() + "_Draft"; + }else{ + policyName1 = policyAdapter.getPolicyName(); + } + + Path newFile = this.getNextLoopFilename(Paths.get(policyAdapter.getParentPath()), policyAdapter.getPolicyType(), policyAdapter.getConfigPolicyType(), policyName1, version); + if (newFile == null) { + //TODO:EELF Cleanup - Remove logger + //logger.error("File already exists, cannot create the policy."); + PolicyLogger.error("File already exists, cannot create the policy."); + setPolicyExists(true); + return false; + } + + policyName = newFile.getFileName().toString(); + + // Save the Configurations file with the policy name with extention based on selection. + String jsonBody = policyAdapter.getJsonBody(); + saveConfigurations(policyName, prevPolicyName, jsonBody); + + // Make sure the filename ends with an extension + if (policyName.endsWith(".xml") == false) { + policyName = policyName + ".xml"; + } + + PolicyType faultPolicy = (PolicyType) policyAdapter.getData(); + + faultPolicy.setDescription(policyAdapter.getPolicyDescription()); + + faultPolicy.setRuleCombiningAlgId(policyAdapter.getRuleCombiningAlgId()); + + AllOfType allOfOne = new AllOfType(); + File policyFilePath = new File(policyAdapter.getParentPath().toString(), policyName); + String policyDir = policyFilePath.getParentFile().getName(); + String fileName = FilenameUtils.removeExtension(policyName); + fileName = policyDir + "." + fileName + ".xml"; + String name = fileName.substring(fileName.lastIndexOf("\\") + 1, fileName.length()); + if ((name == null) || (name.equals(""))) { + name = fileName.substring(fileName.lastIndexOf("/") + 1, fileName.length()); + } + allOfOne.getMatch().add(createMatch("PolicyName", name)); + AllOfType allOf = new AllOfType(); + // Adding the matches to AllOfType element + // Match for Ecomp + allOf.getMatch().add(createMatch("ECOMPName", policyAdapter.getEcompName())); + // Match for riskType + allOf.getMatch().add( + createDynamicMatch("RiskType", policyAdapter.getRiskType())); + // Match for riskLevel + allOf.getMatch().add( + createDynamicMatch("RiskLevel", String.valueOf(policyAdapter.getRiskLevel()))); + // Match for riskguard + allOf.getMatch().add( + createDynamicMatch("guard", policyAdapter.getGuard())); + // Match for ttlDate + allOf.getMatch().add( + createDynamicMatch("TTLDate", policyAdapter.getTtlDate())); + + AnyOfType anyOf = new AnyOfType(); + anyOf.getAllOf().add(allOfOne); + anyOf.getAllOf().add(allOf); + + TargetType target = new TargetType(); + ((TargetType) target).getAnyOf().add(anyOf); + // Adding the target to the policy element + faultPolicy.setTarget((TargetType) target); + + RuleType rule = new RuleType(); + rule.setRuleId(policyAdapter.getRuleID()); + rule.setEffect(EffectType.PERMIT); + + // Create Target in Rule + AllOfType allOfInRule = new AllOfType(); + + // Creating match for ACCESS in rule target + MatchType accessMatch = new MatchType(); + AttributeValueType accessAttributeValue = new AttributeValueType(); + accessAttributeValue.setDataType(STRING_DATATYPE); + accessAttributeValue.getContent().add("ACCESS"); + accessMatch.setAttributeValue(accessAttributeValue); + AttributeDesignatorType accessAttributeDesignator = new AttributeDesignatorType(); + URI accessURI = null; + try { + accessURI = new URI(ACTION_ID); + } catch (URISyntaxException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(e.getStackTrace()); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "CreateClosedLoopPolicy", "Exception creating ACCESS URI"); + } + accessAttributeDesignator.setCategory(CATEGORY_ACTION); + accessAttributeDesignator.setDataType(STRING_DATATYPE); + accessAttributeDesignator.setAttributeId(new IdentifierImpl(accessURI).stringValue()); + accessMatch.setAttributeDesignator(accessAttributeDesignator); + accessMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE); + + // Creating Config Match in rule Target + MatchType closedMatch = new MatchType(); + AttributeValueType closedAttributeValue = new AttributeValueType(); + closedAttributeValue.setDataType(STRING_DATATYPE); + closedAttributeValue.getContent().add("Config"); + closedMatch.setAttributeValue(closedAttributeValue); + AttributeDesignatorType closedAttributeDesignator = new AttributeDesignatorType(); + URI closedURI = null; + try { + closedURI = new URI(RESOURCE_ID); + } catch (URISyntaxException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(e.getStackTrace()); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "CreateClosedLoopPolicy", "Exception creating closed URI"); + } + closedAttributeDesignator.setCategory(CATEGORY_RESOURCE); + closedAttributeDesignator.setDataType(STRING_DATATYPE); + closedAttributeDesignator.setAttributeId(new IdentifierImpl(closedURI).stringValue()); + closedMatch.setAttributeDesignator(closedAttributeDesignator); + closedMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE); + + allOfInRule.getMatch().add(accessMatch); + allOfInRule.getMatch().add(closedMatch); + + AnyOfType anyOfInRule = new AnyOfType(); + anyOfInRule.getAllOf().add(allOfInRule); + + TargetType targetInRule = new TargetType(); + targetInRule.getAnyOf().add(anyOfInRule); + + rule.setTarget(targetInRule); + rule.setAdviceExpressions(getAdviceExpressions(version, policyName)); + + faultPolicy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().add(rule); + policyAdapter.setPolicyData(faultPolicy); + + } else { + //TODO:EELF Cleanup - Remove logger + //logger.error("Unsupported data object." + policyAdapter.getData().getClass().getCanonicalName()); + PolicyLogger.error("Unsupported data object." + policyAdapter.getData().getClass().getCanonicalName()); + } + + setPreparedToSave(true); + return true; + } + + // Data required for Advice part is setting here. + private AdviceExpressionsType getAdviceExpressions(int version, String fileName) { + AdviceExpressionsType advices = new AdviceExpressionsType(); + AdviceExpressionType advice = new AdviceExpressionType(); + advice.setAdviceId("faultID"); + advice.setAppliesTo(EffectType.PERMIT); + // For Configuration + AttributeAssignmentExpressionType assignment1 = new AttributeAssignmentExpressionType(); + assignment1.setAttributeId("type"); + assignment1.setCategory(CATEGORY_RESOURCE); + assignment1.setIssuer(""); + + AttributeValueType configNameAttributeValue = new AttributeValueType(); + configNameAttributeValue.setDataType(STRING_DATATYPE); + configNameAttributeValue.getContent().add("Configuration"); + assignment1.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue)); + + advice.getAttributeAssignmentExpression().add(assignment1); + final Path gitPath = Paths.get(policyAdapter.getUserGitPath().toString()); + // For Config file Url if configurations are provided. + AttributeAssignmentExpressionType assignment2 = new AttributeAssignmentExpressionType(); + assignment2.setAttributeId("URLID"); + assignment2.setCategory(CATEGORY_RESOURCE); + assignment2.setIssuer(""); + + AttributeValueType AttributeValue = new AttributeValueType(); + AttributeValue.setDataType(URI_DATATYPE); + String policyDir1 = policyAdapter.getParentPath().toString(); + int startIndex1 = policyDir1.indexOf(gitPath.toString()) + gitPath.toString().length() + 1; + policyDir1 = policyDir1.substring(startIndex1, policyDir1.length()); + logger.info("print the main domain value"+policyDir1); + String path = policyDir1.replace('\\', '.'); + if(path.contains("/")){ + path = policyDir1.replace('/', '.'); + logger.info("print the path:" +path); + } + + String content = CONFIG_URL +"/Config/" + path + "." + getConfigFile(policyName); + System.out.println("URL value :" + content); + AttributeValue.getContent().add(content); + assignment2.setExpression(new ObjectFactory().createAttributeValue(AttributeValue)); + + advice.getAttributeAssignmentExpression().add(assignment2); + AttributeAssignmentExpressionType assignment3 = new AttributeAssignmentExpressionType(); + assignment3.setAttributeId("PolicyName"); + assignment3.setCategory(CATEGORY_RESOURCE); + assignment3.setIssuer(""); + + AttributeValueType attributeValue3 = new AttributeValueType(); + attributeValue3.setDataType(STRING_DATATYPE); + String policyDir = policyAdapter.getParentPath().toString(); + int startIndex = policyDir.indexOf(gitPath.toString()) + gitPath.toString().length() + 1; + policyDir = policyDir.substring(startIndex, policyDir.length()); + StringTokenizer tokenizer = null; + StringBuffer buffer = new StringBuffer(); + if (policyDir.contains("\\")) { + tokenizer = new StringTokenizer(policyDir, "\\"); + } else { + tokenizer = new StringTokenizer(policyDir, "/"); + } + if (tokenizer != null) { + while (tokenizer.hasMoreElements()) { + String value = tokenizer.nextToken(); + buffer.append(value); + buffer.append("."); + } + } + fileName = FilenameUtils.removeExtension(fileName); + fileName = buffer.toString() + fileName + ".xml"; + String name = fileName.substring(fileName.lastIndexOf("\\") + 1, fileName.length()); + if ((name == null) || (name.equals(""))) { + name = fileName.substring(fileName.lastIndexOf("/") + 1, fileName.length()); + } + attributeValue3.getContent().add(name); + assignment3.setExpression(new ObjectFactory().createAttributeValue(attributeValue3)); + advice.getAttributeAssignmentExpression().add(assignment3); + + AttributeAssignmentExpressionType assignment4 = new AttributeAssignmentExpressionType(); + assignment4.setAttributeId("VersionNumber"); + assignment4.setCategory(CATEGORY_RESOURCE); + assignment4.setIssuer(""); + + AttributeValueType configNameAttributeValue4 = new AttributeValueType(); + configNameAttributeValue4.setDataType(STRING_DATATYPE); + configNameAttributeValue4.getContent().add(Integer.toString(version)); + assignment4.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue4)); + + advice.getAttributeAssignmentExpression().add(assignment4); + + AttributeAssignmentExpressionType assignment5 = new AttributeAssignmentExpressionType(); + assignment5.setAttributeId("matching:" + this.ECOMPID); + assignment5.setCategory(CATEGORY_RESOURCE); + assignment5.setIssuer(""); + + AttributeValueType configNameAttributeValue5 = new AttributeValueType(); + configNameAttributeValue5.setDataType(STRING_DATATYPE); + configNameAttributeValue5.getContent().add(policyAdapter.getEcompName()); + assignment5.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue5)); + + advice.getAttributeAssignmentExpression().add(assignment5); + + //Risk Attributes + AttributeAssignmentExpressionType assignment6 = new AttributeAssignmentExpressionType(); + assignment6.setAttributeId("RiskType"); + assignment6.setCategory(CATEGORY_RESOURCE); + assignment6.setIssuer(""); + + AttributeValueType configNameAttributeValue6 = new AttributeValueType(); + configNameAttributeValue6.setDataType(STRING_DATATYPE); + configNameAttributeValue6.getContent().add(policyAdapter.getRiskType()); + assignment6.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue6)); + + advice.getAttributeAssignmentExpression().add(assignment6); + + AttributeAssignmentExpressionType assignment7 = new AttributeAssignmentExpressionType(); + assignment7.setAttributeId("RiskLevel"); + assignment7.setCategory(CATEGORY_RESOURCE); + assignment7.setIssuer(""); + + AttributeValueType configNameAttributeValue7 = new AttributeValueType(); + configNameAttributeValue7.setDataType(STRING_DATATYPE); + configNameAttributeValue7.getContent().add(policyAdapter.getRiskLevel()); + assignment7.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue7)); + + advice.getAttributeAssignmentExpression().add(assignment7); + + AttributeAssignmentExpressionType assignment8 = new AttributeAssignmentExpressionType(); + assignment8.setAttributeId("guard"); + assignment8.setCategory(CATEGORY_RESOURCE); + assignment8.setIssuer(""); + + AttributeValueType configNameAttributeValue8 = new AttributeValueType(); + configNameAttributeValue8.setDataType(STRING_DATATYPE); + configNameAttributeValue8.getContent().add(policyAdapter.getGuard()); + assignment8.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue8)); + + advice.getAttributeAssignmentExpression().add(assignment8); + + AttributeAssignmentExpressionType assignment9 = new AttributeAssignmentExpressionType(); + assignment9.setAttributeId("TTLDate"); + assignment9.setCategory(CATEGORY_RESOURCE); + assignment9.setIssuer(""); + + AttributeValueType configNameAttributeValue9 = new AttributeValueType(); + configNameAttributeValue9.setDataType(STRING_DATATYPE); + configNameAttributeValue9.getContent().add(policyAdapter.getTtlDate()); + assignment9.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue9)); + + advice.getAttributeAssignmentExpression().add(assignment9); + + + + advices.getAdviceExpression().add(advice); + return advices; + } + + @Override + public Object getCorrectPolicyDataObject() { + return policyAdapter.getPolicyData(); + } + + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/ConfigPolicy.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/ConfigPolicy.java new file mode 100644 index 000000000..a339b1564 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/ConfigPolicy.java @@ -0,0 +1,693 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.components; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.StringReader; +import java.net.URI; +import java.net.URISyntaxException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.Map; +import java.util.Scanner; +import java.util.StringTokenizer; + +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; + +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionsType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeAssignmentExpressionType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.EffectType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObjectFactory; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.RuleType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType; + +import org.apache.commons.io.FilenameUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openecomp.policy.pap.xacml.rest.adapters.PolicyRestAdapter; +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.eelf.PolicyLogger; + +import org.xml.sax.ErrorHandler; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.SAXParseException; +import org.xml.sax.XMLReader; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; +import com.att.research.xacml.std.IdentifierImpl; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +public class ConfigPolicy extends Policy { + + /** + * Config Fields + */ + private static final Logger logger = FlexLogger.getLogger(ConfigPolicy.class); + + public static final String JSON_CONFIG = "JSON"; + public static final String XML_CONFIG = "XML"; + public static final String PROPERTIES_CONFIG = "PROPERTIES"; + public static final String OTHER_CONFIG = "OTHER"; + + private String configBodyData; + + public ConfigPolicy() { + super(); + } + + public ConfigPolicy(PolicyRestAdapter policyAdapter){ + this.policyAdapter = policyAdapter; + } + + // Saving the Configurations file at server location for config policy. + protected void saveConfigurations(String policyName) { + final Path gitPath = Paths.get(policyAdapter.getUserGitPath().toString()); + String policyDir = policyAdapter.getParentPath().toString(); + int startIndex = policyDir.indexOf(gitPath.toString()) + gitPath.toString().length() + 1; + policyDir = policyDir.substring(startIndex, policyDir.length()); + logger.info("print the main domain value"+policyDir); + String path = policyDir.replace('\\', '.'); + if(path.contains("/")){ + path = policyDir.replace('/', '.'); + logger.info("print the path:" +path); + } + + try { + File file; + String configFileName = getConfigFile(policyName); + if(CONFIG_HOME.contains("\\")) + { + file = new File(CONFIG_HOME + "\\" + path + "."+ configFileName); + } + else + { + file = new File(CONFIG_HOME + "/" + path + "."+ configFileName); + } + + // if file doesnt exists, then create it + if (!file.exists()) { + file.createNewFile(); + } + + + File configHomeDir = new File(CONFIG_HOME); + File[] listOfFiles = configHomeDir.listFiles(); + if (listOfFiles != null){ + for(File eachFile : listOfFiles){ + if(eachFile.isFile()){ + String fileNameWithoutExtension = FilenameUtils.removeExtension(eachFile.getName()); + String configFileNameWithoutExtension = FilenameUtils.removeExtension(path + "." + configFileName); + if (fileNameWithoutExtension.equals(configFileNameWithoutExtension)){ + //delete the file + eachFile.delete(); + } + } + } + } + + FileWriter fw = new FileWriter(file.getAbsoluteFile()); + BufferedWriter bw = new BufferedWriter(fw); + bw.write(configBodyData); + bw.close(); + if (logger.isDebugEnabled()) { + logger.debug("Configuration is succesfully saved"); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + + // Here we are adding the extension for the configurations file based on the + // config type selection for saving. + private String getConfigFile(String filename) { + filename = FilenameUtils.removeExtension(filename); + if (filename.endsWith(".xml")) { + filename = filename.substring(0, filename.length() - 4); + } + String id = policyAdapter.getConfigType(); + + if (id != null) { + if (id.equalsIgnoreCase(JSON_CONFIG)) { + filename = filename + ".json"; + } + if (id.equalsIgnoreCase(XML_CONFIG)) { + filename = filename + ".xml"; + } + if (id.equalsIgnoreCase(PROPERTIES_CONFIG)) { + filename = filename + ".properties"; + } + if (id.equalsIgnoreCase(OTHER_CONFIG)) { + filename = filename + ".txt"; + } + } + return filename; + } + + // Validations for Config form + /* + * FORM VALIDATION WILL BE DONE BY THE PAP-ADMIN before creating JSON object... + * BODY VALIDATION WILL BE DONE BY THE PAP-REST after receiving and deserializing the JSON object + */ + public boolean validateConfigForm() { + + isValidForm = true; + + /* + * Validate Text Area Body + */ + configBodyData = policyAdapter.getConfigBodyData(); + String id = policyAdapter.getConfigType(); + if (id != null) { + if (id.equals(JSON_CONFIG)) { + if (!isJSONValid(configBodyData)) { + isValidForm = false; + } + } else if (id.equals(XML_CONFIG)) { + if (!isXMLValid(configBodyData)) { + isValidForm = false; + } + } else if (id.equals(PROPERTIES_CONFIG)) { + if (!isPropValid(configBodyData)||configBodyData.equals("")) { + isValidForm = false; + } + } else if (id.equals(OTHER_CONFIG)) { + if (configBodyData.equals("")) { + isValidForm = false; + } + } + } + return isValidForm; + + } + + // Validation for XML. + private boolean isXMLValid(String data) { + + SAXParserFactory factory = SAXParserFactory.newInstance(); + factory.setValidating(false); + factory.setNamespaceAware(true); + try { + SAXParser parser = factory.newSAXParser(); + XMLReader reader = parser.getXMLReader(); + reader.setErrorHandler(new XMLErrorHandler()); + reader.parse(new InputSource(new StringReader(data))); + } catch (ParserConfigurationException e) { + return false; + } catch (SAXException e) { + return false; + } catch (IOException e) { + return false; + } + return true; + + } + + // Validation for Properties file. + public boolean isPropValid(String prop) { + + Scanner scanner = new Scanner(prop); + while (scanner.hasNextLine()) { + String line = scanner.nextLine(); + line.replaceAll("\\s+", ""); + if (line.startsWith("#")) { + continue; + } else { + if (line.contains("=")) { + String[] parts = line.split("="); + if (parts.length < 2) { + scanner.close(); + return false; + } + } else { + scanner.close(); + return false; + } + } + } + scanner.close(); + return true; + + } + + public class XMLErrorHandler implements ErrorHandler { + + public void warning(SAXParseException e) throws SAXException { + System.out.println(e.getMessage()); + } + + public void error(SAXParseException e) throws SAXException { + System.out.println(e.getMessage()); + } + + public void fatalError(SAXParseException e) throws SAXException { + System.out.println(e.getMessage()); + } + + } + + @Override + public Map savePolicies() throws Exception { + + Map successMap = new HashMap(); + if(isPolicyExists()){ + successMap.put("EXISTS", "This Policy already exist on the PAP"); + return successMap; + } + + if(!isPreparedToSave()){ + //Prep and configure the policy for saving + prepareToSave(); + } + + // Until here we prepared the data and here calling the method to create xml. + Path newPolicyPath = null; + newPolicyPath = Paths.get(policyAdapter.getParentPath().toString(), policyName); + successMap = createPolicy(newPolicyPath,getCorrectPolicyDataObject() ); + if (successMap.containsKey("success")) { + Path finalPolicyPath = getFinalPolicyPath(); + policyAdapter.setFinalPolicyPath(finalPolicyPath.toString()); + } + return successMap; + } + + //This is the method for preparing the policy for saving. We have broken it out + //separately because the fully configured policy is used for multiple things + @Override + public boolean prepareToSave() throws Exception{ + + if(isPreparedToSave()){ + //we have already done this + return true; + } + + int version = 0; + String policyID = policyAdapter.getPolicyID(); + + if (policyAdapter.isEditPolicy()) { + version = policyAdapter.getHighestVersion() + 1; + } else { + version = 1; + } + + // Create the Instance for pojo, PolicyType object is used in marshalling. + if (policyAdapter.getPolicyType().equals("Config")) { + PolicyType policyConfig = new PolicyType(); + + policyConfig.setVersion(Integer.toString(version)); + policyConfig.setPolicyId(policyID); + policyConfig.setTarget(new TargetType()); + policyAdapter.setData(policyConfig); + } + + if (policyAdapter.getData() != null) { + + // Save off everything + // making ready all the required elements to generate the action policy xml. + // Get the uniqueness for policy name. + Path newFile = getNextFilename(Paths.get(policyAdapter.getParentPath().toString()), policyAdapter.getPolicyType(), policyAdapter.getPolicyName(), version); + if (newFile == null) { + //TODO:EELF Cleanup - Remove logger + //logger.error("File already exists"); + PolicyLogger.error("File alrady exists"); + setPolicyExists(true); + return false; + } + policyName = newFile.getFileName().toString(); + + // Body is optional so checking. + configBodyData = policyAdapter.getConfigBodyData(); + if (!configBodyData.equals("")) { + // Save the Configurations file with the policy name with extention based on selection. + saveConfigurations(policyName); + } + + // Make sure the filename ends with an extension + if (policyName.endsWith(".xml") == false) { + policyName = policyName + ".xml"; + } + + + PolicyType configPolicy = (PolicyType) policyAdapter.getData(); + + configPolicy.setDescription(policyAdapter.getPolicyDescription()); + + configPolicy.setRuleCombiningAlgId(policyAdapter.getRuleCombiningAlgId()); + AllOfType allOfOne = new AllOfType(); + final Path gitPath = Paths.get(policyAdapter.getUserGitPath().toString()); + String policyDir = policyAdapter.getParentPath().toString(); + int startIndex = policyDir.indexOf(gitPath.toString()) + gitPath.toString().length() + 1; + policyDir = policyDir.substring(startIndex, policyDir.length()); + logger.info("print the main domain value "+policyDir); + String path = policyDir.replace('\\', '.'); + if(path.contains("/")){ + path = policyDir.replace('/', '.'); + logger.info("print the path:" +path); + } + String fileName = FilenameUtils.removeExtension(policyName); + fileName = path + "." + fileName + ".xml"; + String name = fileName.substring(fileName.lastIndexOf("\\") + 1, fileName.length()); + if ((name == null) || (name.equals(""))) { + name = fileName.substring(fileName.lastIndexOf("/") + 1, fileName.length()); + } + allOfOne.getMatch().add(createMatch("PolicyName", name)); + AllOfType allOf = new AllOfType(); + + // Adding the matches to AllOfType element Match for Ecomp + allOf.getMatch().add(createMatch("ECOMPName", policyAdapter.getEcompName())); + // Match for riskType + allOf.getMatch().add( + createDynamicMatch("RiskType", policyAdapter.getRiskType())); + // Match for riskLevel + allOf.getMatch().add( + createDynamicMatch("RiskLevel", String.valueOf(policyAdapter.getRiskLevel()))); + // Match for riskguard + allOf.getMatch().add( + createDynamicMatch("guard", policyAdapter.getGuard())); + // Match for ttlDate + allOf.getMatch().add( + createDynamicMatch("TTLDate", policyAdapter.getTtlDate())); + // Match for ConfigName + allOf.getMatch().add(createMatch("ConfigName", policyAdapter.getConfigName())); + + Map dynamicFieldConfigAttributes = policyAdapter.getDynamicFieldConfigAttributes(); + + // If there is any dynamic field create the matches here + for (String keyField : dynamicFieldConfigAttributes.keySet()) { + String key = keyField; + String value = dynamicFieldConfigAttributes.get(key); + MatchType dynamicMatch = createDynamicMatch(key, value); + allOf.getMatch().add(dynamicMatch); + } + + AnyOfType anyOf = new AnyOfType(); + anyOf.getAllOf().add(allOfOne); + anyOf.getAllOf().add(allOf); + + TargetType target = new TargetType(); + ((TargetType) target).getAnyOf().add(anyOf); + + // Adding the target to the policy element + configPolicy.setTarget((TargetType) target); + + RuleType rule = new RuleType(); + rule.setRuleId(policyAdapter.getRuleID()); + + rule.setEffect(EffectType.PERMIT); + + // Create Target in Rule + AllOfType allOfInRule = new AllOfType(); + + // Creating match for ACCESS in rule target + MatchType accessMatch = new MatchType(); + AttributeValueType accessAttributeValue = new AttributeValueType(); + accessAttributeValue.setDataType(STRING_DATATYPE); + accessAttributeValue.getContent().add("ACCESS"); + accessMatch.setAttributeValue(accessAttributeValue); + AttributeDesignatorType accessAttributeDesignator = new AttributeDesignatorType(); + URI accessURI = null; + try { + accessURI = new URI(ACTION_ID); + } catch (URISyntaxException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e.getStackTrace()); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "ConfigPolicy", "Exception creating ACCESS URI"); + } + accessAttributeDesignator.setCategory(CATEGORY_ACTION); + accessAttributeDesignator.setDataType(STRING_DATATYPE); + accessAttributeDesignator.setAttributeId(new IdentifierImpl(accessURI).stringValue()); + accessMatch.setAttributeDesignator(accessAttributeDesignator); + accessMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE); + + // Creating Config Match in rule Target + MatchType configMatch = new MatchType(); + AttributeValueType configAttributeValue = new AttributeValueType(); + configAttributeValue.setDataType(STRING_DATATYPE); + configAttributeValue.getContent().add("Config"); + configMatch.setAttributeValue(configAttributeValue); + AttributeDesignatorType configAttributeDesignator = new AttributeDesignatorType(); + URI configURI = null; + try { + configURI = new URI(RESOURCE_ID); + } catch (URISyntaxException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e.getStackTrace()); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "ConfigPolicy", "Exception creating Config URI"); + } + configAttributeDesignator.setCategory(CATEGORY_RESOURCE); + configAttributeDesignator.setDataType(STRING_DATATYPE); + configAttributeDesignator.setAttributeId(new IdentifierImpl(configURI).stringValue()); + configMatch.setAttributeDesignator(configAttributeDesignator); + configMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE); + + allOfInRule.getMatch().add(accessMatch); + allOfInRule.getMatch().add(configMatch); + + AnyOfType anyOfInRule = new AnyOfType(); + anyOfInRule.getAllOf().add(allOfInRule); + + TargetType targetInRule = new TargetType(); + targetInRule.getAnyOf().add(anyOfInRule); + + rule.setTarget(targetInRule); + rule.setAdviceExpressions(getAdviceExpressions(version, policyName)); + + configPolicy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().add(rule); + policyAdapter.setPolicyData(configPolicy); + + } else { + //TODO:EELF Cleanup - Remove logger + //logger.error("Unsupported data object." + policyAdapter.getData().getClass().getCanonicalName()); + PolicyLogger.error("Unsupported data object." + policyAdapter.getData().getClass().getCanonicalName()); + } + setPreparedToSave(true); + return true; + } + + // Data required for Advice part is setting here. + private AdviceExpressionsType getAdviceExpressions(int version, String fileName) { + AdviceExpressionsType advices = new AdviceExpressionsType(); + AdviceExpressionType advice = new AdviceExpressionType(); + advice.setAdviceId("configID"); + advice.setAppliesTo(EffectType.PERMIT); + + // For Configuration + AttributeAssignmentExpressionType assignment1 = new AttributeAssignmentExpressionType(); + assignment1.setAttributeId("type"); + assignment1.setCategory(CATEGORY_RESOURCE); + assignment1.setIssuer(""); + + AttributeValueType configNameAttributeValue = new AttributeValueType(); + configNameAttributeValue.setDataType(STRING_DATATYPE); + configNameAttributeValue.getContent().add("Configuration"); + assignment1.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue)); + + advice.getAttributeAssignmentExpression().add(assignment1); + final Path gitPath = Paths.get(policyAdapter.getUserGitPath().toString()); + + // For Config file Url if configurations are provided. + if (policyAdapter.getConfigType() != null) { + AttributeAssignmentExpressionType assignment2 = new AttributeAssignmentExpressionType(); + assignment2.setAttributeId("URLID"); + assignment2.setCategory(CATEGORY_RESOURCE); + assignment2.setIssuer(""); + + AttributeValueType AttributeValue = new AttributeValueType(); + AttributeValue.setDataType(URI_DATATYPE); + String policyDir1 = policyAdapter.getParentPath().toString(); + int startIndex1 = policyDir1.indexOf(gitPath.toString()) + gitPath.toString().length() + 1; + policyDir1 = policyDir1.substring(startIndex1, policyDir1.length()); + logger.info("print the main domain value"+policyDir1); + String path = policyDir1.replace('\\', '.'); + if(path.contains("/")){ + path = policyDir1.replace('/', '.'); + logger.info("print the path:" +path); + } + + String content = "$URL" + "/Config/" + path + "." + getConfigFile(policyName); + System.out.println("URL value :" + content); + AttributeValue.getContent().add(content); + assignment2.setExpression(new ObjectFactory().createAttributeValue(AttributeValue)); + + advice.getAttributeAssignmentExpression().add(assignment2); + AttributeAssignmentExpressionType assignment3 = new AttributeAssignmentExpressionType(); + assignment3.setAttributeId("PolicyName"); + assignment3.setCategory(CATEGORY_RESOURCE); + assignment3.setIssuer(""); + + AttributeValueType attributeValue3 = new AttributeValueType(); + attributeValue3.setDataType(STRING_DATATYPE); + String policyDir = policyAdapter.getParentPath().toString(); + int startIndex = policyDir.indexOf(gitPath.toString()) + gitPath.toString().length() + 1; + policyDir = policyDir.substring(startIndex, policyDir.length()); + StringTokenizer tokenizer = null; + StringBuffer buffer = new StringBuffer(); + if (policyDir.contains("\\")) { + tokenizer = new StringTokenizer(policyDir, "\\"); + } else { + tokenizer = new StringTokenizer(policyDir, "/"); + } + if (tokenizer != null) { + while (tokenizer.hasMoreElements()) { + String value = tokenizer.nextToken(); + buffer.append(value); + buffer.append("."); + } + } + fileName = FilenameUtils.removeExtension(fileName); + fileName = buffer.toString() + fileName + ".xml"; + String name = fileName.substring(fileName.lastIndexOf("\\") + 1, fileName.length()); + if ((name == null) || (name.equals(""))) { + name = fileName.substring(fileName.lastIndexOf("/") + 1, fileName.length()); + } + attributeValue3.getContent().add(name); + assignment3.setExpression(new ObjectFactory().createAttributeValue(attributeValue3)); + advice.getAttributeAssignmentExpression().add(assignment3); + + AttributeAssignmentExpressionType assignment4 = new AttributeAssignmentExpressionType(); + assignment4.setAttributeId("VersionNumber"); + assignment4.setCategory(CATEGORY_RESOURCE); + assignment4.setIssuer(""); + + AttributeValueType configNameAttributeValue4 = new AttributeValueType(); + configNameAttributeValue4.setDataType(STRING_DATATYPE); + configNameAttributeValue4.getContent().add(Integer.toString(version)); + assignment4.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue4)); + + advice.getAttributeAssignmentExpression().add(assignment4); + + AttributeAssignmentExpressionType assignment5 = new AttributeAssignmentExpressionType(); + assignment5.setAttributeId("matching:" + this.ECOMPID); + assignment5.setCategory(CATEGORY_RESOURCE); + assignment5.setIssuer(""); + + AttributeValueType configNameAttributeValue5 = new AttributeValueType(); + configNameAttributeValue5.setDataType(STRING_DATATYPE); + configNameAttributeValue5.getContent().add(policyAdapter.getEcompName()); + assignment5.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue5)); + + advice.getAttributeAssignmentExpression().add(assignment5); + + AttributeAssignmentExpressionType assignment6 = new AttributeAssignmentExpressionType(); + assignment6.setAttributeId("matching:" + this.CONFIGID); + assignment6.setCategory(CATEGORY_RESOURCE); + assignment6.setIssuer(""); + + AttributeValueType configNameAttributeValue6 = new AttributeValueType(); + configNameAttributeValue6.setDataType(STRING_DATATYPE); + configNameAttributeValue6.getContent().add(policyAdapter.getConfigName()); + assignment6.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue6)); + + advice.getAttributeAssignmentExpression().add(assignment6); + + Map dynamicFieldConfigAttributes = policyAdapter.getDynamicFieldConfigAttributes(); + for (String keyField : dynamicFieldConfigAttributes.keySet()) { + String key = keyField; + String value = dynamicFieldConfigAttributes.get(key); + AttributeAssignmentExpressionType assignment7 = new AttributeAssignmentExpressionType(); + assignment7.setAttributeId("matching:" + key); + assignment7.setCategory(CATEGORY_RESOURCE); + assignment7.setIssuer(""); + + AttributeValueType configNameAttributeValue7 = new AttributeValueType(); + configNameAttributeValue7.setDataType(STRING_DATATYPE); + configNameAttributeValue7.getContent().add(value); + assignment7.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue7)); + + advice.getAttributeAssignmentExpression().add(assignment7); + } + } + + //Risk Attributes + AttributeAssignmentExpressionType assignment8 = new AttributeAssignmentExpressionType(); + assignment8.setAttributeId("RiskType"); + assignment8.setCategory(CATEGORY_RESOURCE); + assignment8.setIssuer(""); + + AttributeValueType configNameAttributeValue8 = new AttributeValueType(); + configNameAttributeValue8.setDataType(STRING_DATATYPE); + configNameAttributeValue8.getContent().add(policyAdapter.getRiskType()); + assignment8.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue8)); + + advice.getAttributeAssignmentExpression().add(assignment8); + + AttributeAssignmentExpressionType assignment9 = new AttributeAssignmentExpressionType(); + assignment9.setAttributeId("RiskLevel"); + assignment9.setCategory(CATEGORY_RESOURCE); + assignment9.setIssuer(""); + + AttributeValueType configNameAttributeValue9 = new AttributeValueType(); + configNameAttributeValue9.setDataType(STRING_DATATYPE); + configNameAttributeValue9.getContent().add(policyAdapter.getRiskLevel()); + assignment9.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue9)); + + advice.getAttributeAssignmentExpression().add(assignment9); + + AttributeAssignmentExpressionType assignment10 = new AttributeAssignmentExpressionType(); + assignment10.setAttributeId("guard"); + assignment10.setCategory(CATEGORY_RESOURCE); + assignment10.setIssuer(""); + + AttributeValueType configNameAttributeValue10 = new AttributeValueType(); + configNameAttributeValue10.setDataType(STRING_DATATYPE); + configNameAttributeValue10.getContent().add(policyAdapter.getGuard()); + assignment10.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue10)); + + advice.getAttributeAssignmentExpression().add(assignment10); + + AttributeAssignmentExpressionType assignment11 = new AttributeAssignmentExpressionType(); + assignment11.setAttributeId("TTLDate"); + assignment11.setCategory(CATEGORY_RESOURCE); + assignment11.setIssuer(""); + + AttributeValueType configNameAttributeValue11 = new AttributeValueType(); + configNameAttributeValue11.setDataType(STRING_DATATYPE); + configNameAttributeValue11.getContent().add(policyAdapter.getTtlDate()); + assignment11.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue11)); + + advice.getAttributeAssignmentExpression().add(assignment11); + + + advices.getAdviceExpression().add(advice); + return advices; + } + + @Override + public Object getCorrectPolicyDataObject() { + return policyAdapter.getPolicyData(); + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/CreateBrmsParamPolicy.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/CreateBrmsParamPolicy.java new file mode 100644 index 000000000..6e18da524 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/CreateBrmsParamPolicy.java @@ -0,0 +1,896 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.components; + +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; +import java.net.URI; +import java.net.URISyntaxException; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; +import java.util.StringTokenizer; +import java.util.regex.Pattern; +import java.util.regex.Matcher; + +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionsType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeAssignmentExpressionType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.EffectType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObjectFactory; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.RuleType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType; + +import org.apache.commons.io.FilenameUtils; +import org.openecomp.policy.pap.xacml.rest.adapters.PolicyRestAdapter; +import org.openecomp.policy.rest.XACMLRestProperties; + +import com.att.research.xacml.std.IdentifierImpl; +import com.att.research.xacml.util.XACMLProperties; + +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.eelf.PolicyLogger; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +public class CreateBrmsParamPolicy extends Policy { + /** + * Config Fields + */ + private static final Logger logger = FlexLogger + .getLogger(CreateBrmsParamPolicy.class); + + /* + * These are the parameters needed for DB access from the PAP + */ + private static String papDbDriver = null; + private static String papDbUrl = null; + private static String papDbUser = null; + private static String papDbPassword = null; + + public CreateBrmsParamPolicy() { + super(); + } + + public CreateBrmsParamPolicy(PolicyRestAdapter policyAdapter) { + this.policyAdapter = policyAdapter; + this.policyAdapter.setConfigType(policyAdapter.getConfigType()); + + } + + public String expandConfigBody(String ruleContents, + Map brmsParamBody + ) { + + Set keySet= new HashSet(); + + Map copyMap=new HashMap<>(); + copyMap.putAll(brmsParamBody); + copyMap.put("policyName", policyAdapter.getPolicyName()); + copyMap.put("policyScope", policyAdapter.getPolicyScope()); + copyMap.put("policyVersion",policyAdapter.getHighestVersion().toString()); + + //Finding all the keys in the Map data-structure. + keySet= copyMap.keySet(); + Iterator iterator = keySet.iterator(); + Pattern p; + Matcher m; + while(iterator.hasNext()) { + //Converting the first character of the key into a lower case. + String input= iterator.next(); + String output = Character.toLowerCase(input.charAt(0)) + + (input.length() > 1 ? input.substring(1) : ""); + //Searching for a pattern in the String using the key. + p=Pattern.compile("\\$\\{"+output+"\\}"); + m=p.matcher(ruleContents); + //Replacing the value with the inputs provided by the user in the editor. + String finalInput = copyMap.get(input); + if(finalInput.contains("$")){ + finalInput = finalInput.replace("$", "\\$"); + } + ruleContents=m.replaceAll(finalInput); + } + System.out.println(ruleContents); + return ruleContents; + } + + // Saving the Configurations file at server location for config policy. + protected void saveConfigurations(String policyName, String prevPolicyName, + String ruleBody) { + final Path gitPath = Paths.get(policyAdapter.getUserGitPath() + .toString()); + String policyDir = policyAdapter.getParentPath().toString(); + int startIndex = policyDir.indexOf(gitPath.toString()) + + gitPath.toString().length() + 1; + policyDir = policyDir.substring(startIndex, policyDir.length()); + logger.info("print the main domain value" + policyDir); + String path = policyDir.replace('\\', '.'); + if (path.contains("/")) { + path = policyDir.replace('/', '.'); + logger.info("print the path:" + path); + } + + + String configFileName = getConfigFile(policyName); + try{ + // Getting the previous policy Config Json file to be used for + // updating the dictionary tables + if (policyAdapter.isEditPolicy()) { + + String prevConfigFileName = getConfigFile(prevPolicyName); + + File oldFile; + if (CONFIG_HOME.contains("\\")) { + oldFile = new File(CONFIG_HOME + "\\" + path + "." + + prevConfigFileName); + } else { + oldFile = new File(CONFIG_HOME + "/" + path + "." + + prevConfigFileName); + } + + String filepath = oldFile.toString(); + + String prevJsonBody = readFile(filepath, StandardCharsets.UTF_8); + policyAdapter.setPrevJsonBody(prevJsonBody); + } + + File configHomeDir = new File(CONFIG_HOME); + File[] listOfFiles = configHomeDir.listFiles(); + if (listOfFiles != null) { + for (File eachFile : listOfFiles) { + if (eachFile.isFile()) { + String fileNameWithoutExtension = FilenameUtils + .removeExtension(eachFile.getName()); + String configFileNameWithoutExtension = FilenameUtils + .removeExtension(configFileName); + if (fileNameWithoutExtension + .equals(configFileNameWithoutExtension)) { + // delete the file + eachFile.delete(); + } + } + } + } + } + catch(IOException e){ + + } + try { + + if (policyName.endsWith(".xml")) { + policyName = policyName.substring(0, + policyName.lastIndexOf(".xml")); + } + PrintWriter out = new PrintWriter(CONFIG_HOME + File.separator + + path + "." + policyName + ".txt"); + String expandedBody=expandConfigBody(ruleBody,policyAdapter.getBrmsParamBody()); + out.println(expandedBody); + out.close(); + + } catch (Exception e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "CreateBrmsParamPolicy", "Exception saving configuration file"); + } + } + + // Utility to read json data from the existing file to a string + static String readFile(String path, Charset encoding) throws IOException { + + byte[] encoded = Files.readAllBytes(Paths.get(path)); + return new String(encoded, encoding); + + } + + // Here we are adding the extension for the configurations file based on the + // config type selection for saving. + private String getConfigFile(String filename) { + filename = FilenameUtils.removeExtension(filename); + if (filename.endsWith(".txt")) { + filename = filename.substring(0, filename.length() - 3); + } + + filename = filename + ".txt"; + return filename; + } + + // Validations for Config form + public boolean validateConfigForm() { + + // Validating mandatory Fields. + isValidForm = true; + return isValidForm; + + } + + @Override + public Map savePolicies() throws Exception { + + Map successMap = new HashMap(); + if(isPolicyExists()){ + successMap.put("EXISTS", "This Policy already exist on the PAP"); + return successMap; + } + + if (!isPreparedToSave()) { + prepareToSave(); + } + // Until here we prepared the data and here calling the method to create + // xml. + Path newPolicyPath = null; + newPolicyPath = Paths.get(policyAdapter.getParentPath().toString(), + policyName); + + Boolean dbIsUpdated = true; + + successMap = new HashMap(); + if (dbIsUpdated) { + successMap = createPolicy(newPolicyPath, + getCorrectPolicyDataObject()); + } else { + //TODO:EELF Cleanup - Remove logger + //logger.error("Failed to Update the Database Dictionary Tables."); + PolicyLogger.error("Failed to Update the Database Dictionary Tables."); + + // remove the new json file + String jsonBody = policyAdapter.getPrevJsonBody(); + saveConfigurations(policyName, "", jsonBody); + successMap.put("error", "DB UPDATE"); + } + + if (successMap.containsKey("success")) { + Path finalPolicyPath = getFinalPolicyPath(); + policyAdapter.setFinalPolicyPath(finalPolicyPath.toString()); + } + return successMap; + } + + private String getValueFromDictionary(String templateName){ + + Connection con = null; + Statement st = null; + ResultSet rs = null; + + /* + * Retrieve the property values for db access from the xacml.pap.properties + */ + papDbDriver = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_DB_DRIVER); + papDbUrl = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_DB_URL); + papDbUser = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_DB_USER); + papDbPassword = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_DB_PASSWORD); + + String ruleTemplate=null; + + try { + //Get DB Connection + Class.forName(papDbDriver); + con = DriverManager.getConnection(papDbUrl,papDbUser,papDbPassword); + st = con.createStatement(); + + String queryString="select rule from BRMSParamTemplate where param_template_name=\""; + queryString=queryString+templateName+"\""; + + rs = st.executeQuery(queryString); + if(rs.next()){ + ruleTemplate=rs.getString("rule"); + } + rs.close(); + }catch (ClassNotFoundException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(e.getMessage()); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "CreateBrmsParamPolicy", "Exception querying BRMSParamTemplate"); + System.out.println(e.getMessage()); + + } catch (SQLException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(e.getMessage()); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "CreateBrmsParamPolicy", "Exception querying BRMSParamTemplate"); + System.out.println(e.getMessage()); + } finally { + try{ + if (con!=null) con.close(); + if (rs!=null) rs.close(); + if (st!=null) st.close(); + } catch (Exception ex){} + } + return ruleTemplate; + + } + + protected Map findType(String rule) { + Map mapFieldType= new HashMap(); + if(rule!=null){ + try { + String params = ""; + Boolean flag = false; + Boolean comment = false; + String lines[] = rule.split("\n"); + for(String line : lines){ + if (line.isEmpty() || line.startsWith("//")) { + continue; + } + if (line.startsWith("/*")) { + comment = true; + continue; + } + if (line.contains("//")) { + if(!(line.contains("http://") || line.contains("https://"))){ + line = line.split("\\/\\/")[0]; + } + } + if (line.contains("/*")) { + comment = true; + if (line.contains("*/")) { + try { + comment = false; + line = line.split("\\/\\*")[0] + + line.split("\\*\\/")[1].replace("*/", ""); + } catch (Exception e) { + line = line.split("\\/\\*")[0]; + } + } else { + line = line.split("\\/\\*")[0]; + } + } + if (line.contains("*/")) { + comment = false; + try { + line = line.split("\\*\\/")[1].replace("*/", ""); + } catch (Exception e) { + line = ""; + } + } + if (comment) { + continue; + } + if (flag) { + params = params + line; + } + if (line.contains("declare Params")) { + params = params + line; + flag = true; + } + if (line.contains("end") && flag) { + break; + } + } + params = params.replace("declare Params", "").replace("end", "") + .replaceAll("\\s+", ""); + String[] components = params.split(":"); + String caption = ""; + for (int i = 0; i < components.length; i++) { + String type = ""; + if (i == 0) { + caption = components[i]; + } + if(caption.equals("")){ + break; + } + String nextComponent = ""; + try { + nextComponent = components[i + 1]; + } catch (Exception e) { + nextComponent = components[i]; + } + //If the type is of type String then we add the UI Item and type to the map. + if (nextComponent.startsWith("String")) { + type = "String"; + mapFieldType.put(caption, type); + caption = nextComponent.replace("String", ""); + } else if (nextComponent.startsWith("int")) { + type = "int"; + mapFieldType.put(caption, type); + caption = nextComponent.replace("int", ""); + } + } + } catch (Exception e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e); + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "CreateBrmsParamPolicy", "Exception parsing file in findType"); + } + } + return mapFieldType; + } + + // This is the method for preparing the policy for saving. We have broken it + // out + // separately because the fully configured policy is used for multiple + // things + @Override + public boolean prepareToSave() throws Exception { + + if (isPreparedToSave()) { + // we have already done this + return true; + } + + int version = 0; + String policyID = policyAdapter.getPolicyID(); + + if (policyAdapter.isEditPolicy()) { + // version = Integer.parseInt(policyAdapter.getVersion()) + 1; + version = policyAdapter.getHighestVersion() + 1; + } else { + version = 1; + } + + // Create the Instance for pojo, PolicyType object is used in + // marshalling. + if (policyAdapter.getPolicyType().equals("Config")) { + PolicyType policyConfig = new PolicyType(); + + policyConfig.setVersion(Integer.toString(version)); + policyConfig.setPolicyId(policyID); + policyConfig.setTarget(new TargetType()); + policyAdapter.setData(policyConfig); + } + + if (policyAdapter.getData() != null) { + + // Save off everything + // making ready all the required elements to generate the action + // policy xml. + // Get the uniqueness for policy name. + String prevPolicyName = null; + if (policyAdapter.isEditPolicy()) { + prevPolicyName = "Config_BRMS_Param_" + policyAdapter.getPolicyName() + + "." + policyAdapter.getHighestVersion() + ".xml"; + } + + Path newFile = getNextFilename( + Paths.get(policyAdapter.getParentPath().toString()), + (policyAdapter.getPolicyType() + "_BRMS_Param"), + policyAdapter.getPolicyName(), version); + + if (newFile == null) { + //TODO:EELF Cleanup - Remove logger + //logger.error("Policy already Exists, cannot create the policy."); + PolicyLogger.error("Policy already Exists, cannot create the policy."); + setPolicyExists(true); + return false; + } + policyName = newFile.getFileName().toString(); + + + Map ruleAndUIValue= policyAdapter.getBrmsParamBody(); + String tempateValue= ruleAndUIValue.get("templateName"); + String valueFromDictionary= getValueFromDictionary(tempateValue); + + //Get the type of the UI Fields. + Map typeOfUIField=findType(valueFromDictionary); + String generatedRule=null; + String body = ""; + + try { + + try { + body = "/* Autogenerated Code Please Don't change/remove this comment section. This is for the UI purpose. \n\t " + + "<$%BRMSParamTemplate=" + tempateValue + "%$> \n */ \n"; + body = body + valueFromDictionary + "\n"; + generatedRule = "rule \"Params\" \n\tsalience 1000 \n\twhen\n\tthen\n\t\tParams params = new Params();"; + + //We first read the map data structure(ruleAndUIValue) received from the PAP-ADMIN + //We ignore if the key is "templateName as we are interested only in the UI fields and its value. + //We have one more map data structure(typeOfUIField) created by parsing the Drools rule. + //From the type of the UI field(String/int) we structure whether to put the "" or not. + for (Map.Entry entry : ruleAndUIValue.entrySet()) { + if(entry.getKey()!="templateName") + { + for(Map.Entry fieldType:typeOfUIField.entrySet()) + { + if(fieldType.getKey().equalsIgnoreCase(entry.getKey())) + { + String key = entry.getKey().substring(0, 1).toUpperCase() + entry.getKey().substring(1); + if(fieldType.getValue()=="String") + { + //Type is String + generatedRule = generatedRule + "\n\t\tparams.set" + + key + "(\"" + + entry.getValue() + "\");"; + } + else{ + generatedRule = generatedRule + "\n\t\tparams.set" + + key + "(" + + entry.getValue() + ");"; + } + } + } + } + } + + generatedRule = generatedRule + + "\n\t\tinsert(params);\nend"; + logger.info("New rule generated with :" + generatedRule); + body = body + generatedRule; + } catch (Exception e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "CreateBrmsParamPolicy", "Exception saving policy"); + } + } + catch (Exception e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "CreateBrmsParamPolicy", "Exception saving policy"); + } + + saveConfigurations(policyName,prevPolicyName,body); + + // Make sure the filename ends with an extension + if (policyName.endsWith(".xml") == false) { + policyName = policyName + ".xml"; + } + + PolicyType configPolicy = (PolicyType) policyAdapter.getData(); + + configPolicy.setDescription(policyAdapter.getPolicyDescription()); + + configPolicy.setRuleCombiningAlgId(policyAdapter + .getRuleCombiningAlgId()); + + AllOfType allOfOne = new AllOfType(); + File policyFilePath = new File(policyAdapter.getParentPath() + .toString(), policyName); + String policyDir = policyFilePath.getParentFile().getName(); + String fileName = FilenameUtils.removeExtension(policyName); + fileName = policyDir + "." + fileName + ".xml"; + String name = fileName.substring(fileName.lastIndexOf("\\") + 1, + fileName.length()); + if ((name == null) || (name.equals(""))) { + name = fileName.substring(fileName.lastIndexOf("/") + 1, + fileName.length()); + } + allOfOne.getMatch().add(createMatch("PolicyName", name)); + + + AllOfType allOf = new AllOfType(); + + // Match for ECOMPName + allOf.getMatch().add( + createMatch("ECOMPName", policyAdapter.getEcompName())); + allOf.getMatch().add( + createMatch("ConfigName", policyAdapter.getConfigName())); + // Match for riskType + allOf.getMatch().add( + createDynamicMatch("RiskType", policyAdapter.getRiskType())); + // Match for riskLevel + allOf.getMatch().add( + createDynamicMatch("RiskLevel", String.valueOf(policyAdapter.getRiskLevel()))); + // Match for riskguard + allOf.getMatch().add( + createDynamicMatch("guard", policyAdapter.getGuard())); + // Match for ttlDate + allOf.getMatch().add( + createDynamicMatch("TTLDate", policyAdapter.getTtlDate())); + AnyOfType anyOf = new AnyOfType(); + anyOf.getAllOf().add(allOfOne); + anyOf.getAllOf().add(allOf); + + TargetType target = new TargetType(); + ((TargetType) target).getAnyOf().add(anyOf); + + // Adding the target to the policy element + configPolicy.setTarget((TargetType) target); + + RuleType rule = new RuleType(); + rule.setRuleId(policyAdapter.getRuleID()); + + rule.setEffect(EffectType.PERMIT); + + // Create Target in Rule + AllOfType allOfInRule = new AllOfType(); + + // Creating match for ACCESS in rule target + MatchType accessMatch = new MatchType(); + AttributeValueType accessAttributeValue = new AttributeValueType(); + accessAttributeValue.setDataType(STRING_DATATYPE); + accessAttributeValue.getContent().add("ACCESS"); + accessMatch.setAttributeValue(accessAttributeValue); + AttributeDesignatorType accessAttributeDesignator = new AttributeDesignatorType(); + URI accessURI = null; + try { + accessURI = new URI(ACTION_ID); + } catch (URISyntaxException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + //+ e.getStackTrace()); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "CreateBrmsParamPolicy", "Exception creating ACCESS URI"); + } + accessAttributeDesignator.setCategory(CATEGORY_ACTION); + accessAttributeDesignator.setDataType(STRING_DATATYPE); + accessAttributeDesignator.setAttributeId(new IdentifierImpl( + accessURI).stringValue()); + accessMatch.setAttributeDesignator(accessAttributeDesignator); + accessMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE); + + // Creating Config Match in rule Target + MatchType configMatch = new MatchType(); + AttributeValueType configAttributeValue = new AttributeValueType(); + configAttributeValue.setDataType(STRING_DATATYPE); + + configAttributeValue.getContent().add("Config"); + + configMatch.setAttributeValue(configAttributeValue); + AttributeDesignatorType configAttributeDesignator = new AttributeDesignatorType(); + URI configURI = null; + try { + configURI = new URI(RESOURCE_ID); + } catch (URISyntaxException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + //+ e.getStackTrace()); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "CreateBrmsParamPolicy", "Exception creating Config URI"); + } + + configAttributeDesignator.setCategory(CATEGORY_RESOURCE); + configAttributeDesignator.setDataType(STRING_DATATYPE); + configAttributeDesignator.setAttributeId(new IdentifierImpl( + configURI).stringValue()); + configMatch.setAttributeDesignator(configAttributeDesignator); + configMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE); + + allOfInRule.getMatch().add(accessMatch); + allOfInRule.getMatch().add(configMatch); + + AnyOfType anyOfInRule = new AnyOfType(); + anyOfInRule.getAllOf().add(allOfInRule); + + TargetType targetInRule = new TargetType(); + targetInRule.getAnyOf().add(anyOfInRule); + + rule.setTarget(targetInRule); + rule.setAdviceExpressions(getAdviceExpressions(version, policyName)); + + configPolicy + .getCombinerParametersOrRuleCombinerParametersOrVariableDefinition() + .add(rule); + policyAdapter.setPolicyData(configPolicy); + + } else { + //TODO:EELF Cleanup - Remove logger + //logger.error("Unsupported data object." + //+ policyAdapter.getData().getClass().getCanonicalName()); + PolicyLogger.error("Unsupported data object." + + policyAdapter.getData().getClass().getCanonicalName()); + } + setPreparedToSave(true); + return true; + } + + // Data required for Advice part is setting here. + private AdviceExpressionsType getAdviceExpressions(int version, + String fileName) { + + //Policy Config ID Assignment + AdviceExpressionsType advices = new AdviceExpressionsType(); + AdviceExpressionType advice = new AdviceExpressionType(); + advice.setAdviceId("BRMSPARAMID"); + advice.setAppliesTo(EffectType.PERMIT); + // For Configuration + AttributeAssignmentExpressionType assignment1 = new AttributeAssignmentExpressionType(); + assignment1.setAttributeId("type"); + assignment1.setCategory(CATEGORY_RESOURCE); + assignment1.setIssuer(""); + AttributeValueType configNameAttributeValue = new AttributeValueType(); + configNameAttributeValue.setDataType(STRING_DATATYPE); + configNameAttributeValue.getContent().add("Configuration"); + assignment1.setExpression(new ObjectFactory() + .createAttributeValue(configNameAttributeValue)); + advice.getAttributeAssignmentExpression().add(assignment1); + + // For Config file Url if configurations are provided. + // URL ID Assignment + final Path gitPath = Paths.get(policyAdapter.getUserGitPath() + .toString()); + AttributeAssignmentExpressionType assignment2 = new AttributeAssignmentExpressionType(); + assignment2.setAttributeId("URLID"); + assignment2.setCategory(CATEGORY_RESOURCE); + assignment2.setIssuer(""); + AttributeValueType AttributeValue = new AttributeValueType(); + AttributeValue.setDataType(URI_DATATYPE); + String policyDir1 = policyAdapter.getParentPath().toString(); + int startIndex1 = policyDir1.indexOf(gitPath.toString()) + + gitPath.toString().length() + 1; + policyDir1 = policyDir1.substring(startIndex1, policyDir1.length()); + logger.info("print the main domain value" + policyDir1); + String path = policyDir1.replace('\\', '.'); + if (path.contains("/")) { + path = policyDir1.replace('/', '.'); + logger.info("print the path:" + path); + } + String content = CONFIG_URL + "/Config/" + path + "." + + getConfigFile(policyName); + + AttributeValue.getContent().add(content); + assignment2.setExpression(new ObjectFactory() + .createAttributeValue(AttributeValue)); + advice.getAttributeAssignmentExpression().add(assignment2); + + // Policy Name Assignment + AttributeAssignmentExpressionType assignment3 = new AttributeAssignmentExpressionType(); + assignment3.setAttributeId("PolicyName"); + assignment3.setCategory(CATEGORY_RESOURCE); + assignment3.setIssuer(""); + AttributeValueType attributeValue3 = new AttributeValueType(); + attributeValue3.setDataType(STRING_DATATYPE); + String policyDir = policyAdapter.getParentPath().toString(); + int startIndex = policyDir.indexOf(gitPath.toString()) + + gitPath.toString().length() + 1; + policyDir = policyDir.substring(startIndex, policyDir.length()); + StringTokenizer tokenizer = null; + StringBuffer buffer = new StringBuffer(); + if (policyDir.contains("\\")) { + tokenizer = new StringTokenizer(policyDir, "\\"); + } else { + tokenizer = new StringTokenizer(policyDir, "/"); + } + if (tokenizer != null) { + while (tokenizer.hasMoreElements()) { + String value = tokenizer.nextToken(); + buffer.append(value); + buffer.append("."); + } + } + fileName = FilenameUtils.removeExtension(fileName); + fileName = buffer.toString() + fileName + ".xml"; + System.out.println(fileName); + String name = fileName.substring(fileName.lastIndexOf("\\") + 1, + fileName.length()); + if ((name == null) || (name.equals(""))) { + name = fileName.substring(fileName.lastIndexOf("/") + 1, + fileName.length()); + } + System.out.println(name); + attributeValue3.getContent().add(name); + assignment3.setExpression(new ObjectFactory() + .createAttributeValue(attributeValue3)); + advice.getAttributeAssignmentExpression().add(assignment3); + + // Version Number Assignment + AttributeAssignmentExpressionType assignment4 = new AttributeAssignmentExpressionType(); + assignment4.setAttributeId("VersionNumber"); + assignment4.setCategory(CATEGORY_RESOURCE); + assignment4.setIssuer(""); + AttributeValueType configNameAttributeValue4 = new AttributeValueType(); + configNameAttributeValue4.setDataType(STRING_DATATYPE); + configNameAttributeValue4.getContent().add(Integer.toString(version)); + assignment4.setExpression(new ObjectFactory() + .createAttributeValue(configNameAttributeValue4)); + advice.getAttributeAssignmentExpression().add(assignment4); + + // Ecomp Name Assignment + AttributeAssignmentExpressionType assignment5 = new AttributeAssignmentExpressionType(); + assignment5.setAttributeId("matching:" + this.ECOMPID); + assignment5.setCategory(CATEGORY_RESOURCE); + assignment5.setIssuer(""); + AttributeValueType configNameAttributeValue5 = new AttributeValueType(); + configNameAttributeValue5.setDataType(STRING_DATATYPE); + configNameAttributeValue5.getContent().add(policyAdapter.getEcompName()); + assignment5.setExpression(new ObjectFactory() + .createAttributeValue(configNameAttributeValue5)); + advice.getAttributeAssignmentExpression().add(assignment5); + + + //Config Name Assignment + AttributeAssignmentExpressionType assignment6 = new AttributeAssignmentExpressionType(); + assignment6.setAttributeId("matching:" + this.CONFIGID); + assignment6.setCategory(CATEGORY_RESOURCE); + assignment6.setIssuer(""); + AttributeValueType configNameAttributeValue6 = new AttributeValueType(); + configNameAttributeValue6.setDataType(STRING_DATATYPE); + configNameAttributeValue6.getContent().add(policyAdapter.getConfigName()); + assignment6.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue6)); + advice.getAttributeAssignmentExpression().add(assignment6); + + Map dynamicFieldConfigAttributes = policyAdapter.getDynamicFieldConfigAttributes(); + for (String keyField : dynamicFieldConfigAttributes.keySet()) { + String key = keyField; + String value = dynamicFieldConfigAttributes.get(key); + AttributeAssignmentExpressionType assignment7 = new AttributeAssignmentExpressionType(); + assignment7.setAttributeId("key:" + key); + assignment7.setCategory(CATEGORY_RESOURCE); + assignment7.setIssuer(""); + + AttributeValueType configNameAttributeValue7 = new AttributeValueType(); + configNameAttributeValue7.setDataType(STRING_DATATYPE); + configNameAttributeValue7.getContent().add(value); + assignment7.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue7)); + + advice.getAttributeAssignmentExpression().add(assignment7); + } + + //Risk Attributes + AttributeAssignmentExpressionType assignment8 = new AttributeAssignmentExpressionType(); + assignment8.setAttributeId("RiskType"); + assignment8.setCategory(CATEGORY_RESOURCE); + assignment8.setIssuer(""); + + AttributeValueType configNameAttributeValue8 = new AttributeValueType(); + configNameAttributeValue8.setDataType(STRING_DATATYPE); + configNameAttributeValue8.getContent().add(policyAdapter.getRiskType()); + assignment8.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue8)); + + advice.getAttributeAssignmentExpression().add(assignment8); + + AttributeAssignmentExpressionType assignment9 = new AttributeAssignmentExpressionType(); + assignment9.setAttributeId("RiskLevel"); + assignment9.setCategory(CATEGORY_RESOURCE); + assignment9.setIssuer(""); + + AttributeValueType configNameAttributeValue9 = new AttributeValueType(); + configNameAttributeValue9.setDataType(STRING_DATATYPE); + configNameAttributeValue9.getContent().add(policyAdapter.getRiskLevel()); + assignment9.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue9)); + + advice.getAttributeAssignmentExpression().add(assignment9); + + AttributeAssignmentExpressionType assignment10 = new AttributeAssignmentExpressionType(); + assignment10.setAttributeId("guard"); + assignment10.setCategory(CATEGORY_RESOURCE); + assignment10.setIssuer(""); + + AttributeValueType configNameAttributeValue10 = new AttributeValueType(); + configNameAttributeValue10.setDataType(STRING_DATATYPE); + configNameAttributeValue10.getContent().add(policyAdapter.getGuard()); + assignment10.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue10)); + + advice.getAttributeAssignmentExpression().add(assignment10); + + AttributeAssignmentExpressionType assignment11 = new AttributeAssignmentExpressionType(); + assignment11.setAttributeId("TTLDate"); + assignment11.setCategory(CATEGORY_RESOURCE); + assignment11.setIssuer(""); + + AttributeValueType configNameAttributeValue11 = new AttributeValueType(); + configNameAttributeValue11.setDataType(STRING_DATATYPE); + configNameAttributeValue11.getContent().add(policyAdapter.getTtlDate()); + assignment11.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue11)); + + advice.getAttributeAssignmentExpression().add(assignment11); + + advices.getAdviceExpression().add(advice); + return advices; + } + + @Override + public Object getCorrectPolicyDataObject() { + return policyAdapter.getData(); + } +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/CreateBrmsRawPolicy.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/CreateBrmsRawPolicy.java new file mode 100644 index 000000000..d77abf0f1 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/CreateBrmsRawPolicy.java @@ -0,0 +1,661 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.components; + + +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; +import java.net.URI; +import java.net.URISyntaxException; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.Map; +import java.util.StringTokenizer; + +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionsType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeAssignmentExpressionType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.EffectType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObjectFactory; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.RuleType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType; + +import org.apache.commons.io.FilenameUtils; +import org.openecomp.policy.pap.xacml.rest.adapters.PolicyRestAdapter; + +import com.att.research.xacml.std.IdentifierImpl; + +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.eelf.PolicyLogger; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + + +public class CreateBrmsRawPolicy extends Policy { + /** + * Config Fields + */ + private static final Logger logger = FlexLogger + .getLogger(CreateBrmsRawPolicy.class); + + public static final String JSON_CONFIG = "JSON"; + public static final String XML_CONFIG = "XML"; + public static final String PROPERTIES_CONFIG = "PROPERTIES"; + public static final String OTHER_CONFIG = "OTHER"; + + public CreateBrmsRawPolicy() { + super(); + } + + public CreateBrmsRawPolicy(PolicyRestAdapter policyAdapter) { + this.policyAdapter = policyAdapter; + this.policyAdapter.setConfigType(policyAdapter.getConfigType()); + + } + + // Saving the Configurations file at server location for config policy. + protected void saveConfigurations(String policyName, String prevPolicyName, + String jsonBody) { + final Path gitPath = Paths.get(policyAdapter.getUserGitPath() + .toString()); + String policyDir = policyAdapter.getParentPath().toString(); + int startIndex = policyDir.indexOf(gitPath.toString()) + + gitPath.toString().length() + 1; + policyDir = policyDir.substring(startIndex, policyDir.length()); + logger.info("print the main domain value" + policyDir); + String path = policyDir.replace('\\', '.'); + if (path.contains("/")) { + path = policyDir.replace('/', '.'); + logger.info("print the path:" + path); + } + + try { + String configFileName = getConfigFile(policyName); + + File file; + if (CONFIG_HOME.contains("\\")) { + file = new File(CONFIG_HOME + "\\" + path + "." + + configFileName); + } else { + file = new File(CONFIG_HOME + "/" + path + "." + configFileName); + } + + // if file doesnt exists, then create it + if (!file.exists()) { + file.createNewFile(); + } + + // Getting the previous policy Config Json file to be used for + // updating the dictionary tables + if (policyAdapter.isEditPolicy()) { + + String prevConfigFileName = getConfigFile(prevPolicyName); + + File oldFile; + if (CONFIG_HOME.contains("\\")) { + oldFile = new File(CONFIG_HOME + "\\" + path + "." + + prevConfigFileName); + } else { + oldFile = new File(CONFIG_HOME + "/" + path + "." + + prevConfigFileName); + } + + String filepath = oldFile.toString(); + + String prevJsonBody = readFile(filepath, StandardCharsets.UTF_8); + policyAdapter.setPrevJsonBody(prevJsonBody); + } + + File configHomeDir = new File(CONFIG_HOME); + File[] listOfFiles = configHomeDir.listFiles(); + if (listOfFiles != null) { + for (File eachFile : listOfFiles) { + if (eachFile.isFile()) { + String fileNameWithoutExtension = FilenameUtils + .removeExtension(eachFile.getName()); + String configFileNameWithoutExtension = FilenameUtils + .removeExtension(configFileName); + if (fileNameWithoutExtension + .equals(configFileNameWithoutExtension)) { + // delete the file + eachFile.delete(); + } + } + } + } + + /*FileWriter fw = new FileWriter(file.getAbsoluteFile()); + BufferedWriter bw = new BufferedWriter(fw); + bw.write(jsonBody); + bw.close(); + if (logger.isDebugEnabled()) { + logger.debug("Configuration is succesfully saved"); + }*/ + + try { + + if (policyName.endsWith(".xml")) { + policyName = policyName.substring(0, + policyName.lastIndexOf(".xml")); + } + PrintWriter out = new PrintWriter(CONFIG_HOME + File.separator + + path + "." + policyName + ".txt"); + out.println(jsonBody); + out.close(); + + } catch (Exception e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "CreateBrmsRawPolicy", "Exception saving configurations file"); + } + + } catch (IOException e) { + e.printStackTrace(); + } + } + + // Utility to read json data from the existing file to a string + static String readFile(String path, Charset encoding) throws IOException { + + byte[] encoded = Files.readAllBytes(Paths.get(path)); + return new String(encoded, encoding); + + } + + // Here we are adding the extension for the configurations file based on the + // config type selection for saving. + private String getConfigFile(String filename) { + filename = FilenameUtils.removeExtension(filename); + if (filename.endsWith(".txt")) { + filename = filename.substring(0, filename.length() - 3); + } + + filename = filename + ".txt"; + return filename; + } + + // Validations for Config form + public boolean validateConfigForm() { + + // Validating mandatory Fields. + isValidForm = true; + return isValidForm; + + } + + @Override + public Map savePolicies() throws Exception { + + Map successMap = new HashMap(); + if(isPolicyExists()){ + successMap.put("EXISTS", "This Policy already exist on the PAP"); + return successMap; + } + + if (!isPreparedToSave()) { + prepareToSave(); + } + // Until here we prepared the data and here calling the method to create + // xml. + Path newPolicyPath = null; + newPolicyPath = Paths.get(policyAdapter.getParentPath().toString(), + policyName); + + Boolean dbIsUpdated = true; + + successMap = new HashMap(); + if (dbIsUpdated) { + successMap = createPolicy(newPolicyPath, + getCorrectPolicyDataObject()); + } else { + //TODO:EELF Cleanup - Remove logger + //logger.error("Failed to Update the Database Dictionary Tables."); + PolicyLogger.error("Failed to Update the Database Dictionary Tables."); + + // remove the new json file + String jsonBody = policyAdapter.getPrevJsonBody(); + saveConfigurations(policyName, "", jsonBody); + successMap.put("error", "DB UPDATE"); + } + + if (successMap.containsKey("success")) { + Path finalPolicyPath = getFinalPolicyPath(); + policyAdapter.setFinalPolicyPath(finalPolicyPath.toString()); + } + return successMap; + } + + // This is the method for preparing the policy for saving. We have broken it + // out + // separately because the fully configured policy is used for multiple + // things + @Override + public boolean prepareToSave() throws Exception { + + if (isPreparedToSave()) { + // we have already done this + return true; + } + + int version = 0; + String policyID = policyAdapter.getPolicyID(); + + if (policyAdapter.isEditPolicy()) { + // version = Integer.parseInt(policyAdapter.getVersion()) + 1; + version = policyAdapter.getHighestVersion() + 1; + } else { + version = 1; + } + + // Create the Instance for pojo, PolicyType object is used in + // marshalling. + if (policyAdapter.getPolicyType().equals("Config")) { + PolicyType policyConfig = new PolicyType(); + + policyConfig.setVersion(Integer.toString(version)); + policyConfig.setPolicyId(policyID); + policyConfig.setTarget(new TargetType()); + policyAdapter.setData(policyConfig); + } + + if (policyAdapter.getData() != null) { + + // Save off everything + // making ready all the required elements to generate the action + // policy xml. + // Get the uniqueness for policy name. + String prevPolicyName = null; + if (policyAdapter.isEditPolicy()) { + prevPolicyName = "Config_BRMS_Raw_" + policyAdapter.getPolicyName() + + "." + policyAdapter.getHighestVersion() + ".xml"; + } + //if (!policyAdapter.isEditPolicy()) { + Path newFile = getNextFilename( + Paths.get(policyAdapter.getParentPath().toString()), + (policyAdapter.getPolicyType() + "_BRMS_Raw"), + policyAdapter.getPolicyName(), version); + + if (newFile == null) { + //TODO:EELF Cleanup - Remove logger + //logger.error("File already exists, cannot create the policy."); + PolicyLogger.error("File already exists, cannot create the policy."); + setPolicyExists(true); + return false; + } + policyName = newFile.getFileName().toString(); + //} + + //String jsonBody = policyAdapter.getJsonBody(); + String configBody=policyAdapter.getConfigBodyData(); + saveConfigurations(policyName, prevPolicyName, configBody); + + // Make sure the filename ends with an extension + if (policyName.endsWith(".xml") == false) { + policyName = policyName + ".xml"; + } + + PolicyType configPolicy = (PolicyType) policyAdapter.getData(); + + configPolicy.setDescription(policyAdapter.getPolicyDescription()); + + configPolicy.setRuleCombiningAlgId(policyAdapter + .getRuleCombiningAlgId()); + + AllOfType allOfOne = new AllOfType(); + File policyFilePath = new File(policyAdapter.getParentPath() + .toString(), policyName); + String policyDir = policyFilePath.getParentFile().getName(); + String fileName = FilenameUtils.removeExtension(policyName); + fileName = policyDir + "." + fileName + ".xml"; + String name = fileName.substring(fileName.lastIndexOf("\\") + 1, + fileName.length()); + if ((name == null) || (name.equals(""))) { + name = fileName.substring(fileName.lastIndexOf("/") + 1, + fileName.length()); + } + allOfOne.getMatch().add(createMatch("PolicyName", name)); + + + AllOfType allOf = new AllOfType(); + + // Match for ECOMPName + allOf.getMatch().add( + createMatch("ECOMPName", policyAdapter.getEcompName())); + allOf.getMatch().add( + createMatch("ConfigName", policyAdapter.getConfigName())); + // Match for riskType + allOf.getMatch().add( + createDynamicMatch("RiskType", policyAdapter.getRiskType())); + // Match for riskLevel + allOf.getMatch().add( + createDynamicMatch("RiskLevel", String.valueOf(policyAdapter.getRiskLevel()))); + // Match for riskguard + allOf.getMatch().add( + createDynamicMatch("guard", policyAdapter.getGuard())); + // Match for ttlDate + allOf.getMatch().add( + createDynamicMatch("TTLDate", policyAdapter.getTtlDate())); + AnyOfType anyOf = new AnyOfType(); + anyOf.getAllOf().add(allOfOne); + anyOf.getAllOf().add(allOf); + + TargetType target = new TargetType(); + ((TargetType) target).getAnyOf().add(anyOf); + + // Adding the target to the policy element + configPolicy.setTarget((TargetType) target); + + RuleType rule = new RuleType(); + rule.setRuleId(policyAdapter.getRuleID()); + + rule.setEffect(EffectType.PERMIT); + + // Create Target in Rule + AllOfType allOfInRule = new AllOfType(); + + // Creating match for ACCESS in rule target + MatchType accessMatch = new MatchType(); + AttributeValueType accessAttributeValue = new AttributeValueType(); + accessAttributeValue.setDataType(STRING_DATATYPE); + accessAttributeValue.getContent().add("ACCESS"); + accessMatch.setAttributeValue(accessAttributeValue); + AttributeDesignatorType accessAttributeDesignator = new AttributeDesignatorType(); + URI accessURI = null; + try { + accessURI = new URI(ACTION_ID); + } catch (URISyntaxException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + //+ e.getStackTrace()); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "CreateBrmsRawPolicy", "Exception creating ACCESS URI"); + } + accessAttributeDesignator.setCategory(CATEGORY_ACTION); + accessAttributeDesignator.setDataType(STRING_DATATYPE); + accessAttributeDesignator.setAttributeId(new IdentifierImpl( + accessURI).stringValue()); + accessMatch.setAttributeDesignator(accessAttributeDesignator); + accessMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE); + + // Creating Config Match in rule Target + MatchType configMatch = new MatchType(); + AttributeValueType configAttributeValue = new AttributeValueType(); + configAttributeValue.setDataType(STRING_DATATYPE); + + configAttributeValue.getContent().add("Config"); + + configMatch.setAttributeValue(configAttributeValue); + AttributeDesignatorType configAttributeDesignator = new AttributeDesignatorType(); + URI configURI = null; + try { + configURI = new URI(RESOURCE_ID); + } catch (URISyntaxException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + //+ e.getStackTrace()); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "CreateBrmsRawPolicy", "Exception creating Config URI"); + } + + configAttributeDesignator.setCategory(CATEGORY_RESOURCE); + configAttributeDesignator.setDataType(STRING_DATATYPE); + configAttributeDesignator.setAttributeId(new IdentifierImpl( + configURI).stringValue()); + configMatch.setAttributeDesignator(configAttributeDesignator); + configMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE); + + allOfInRule.getMatch().add(accessMatch); + allOfInRule.getMatch().add(configMatch); + + AnyOfType anyOfInRule = new AnyOfType(); + anyOfInRule.getAllOf().add(allOfInRule); + + TargetType targetInRule = new TargetType(); + targetInRule.getAnyOf().add(anyOfInRule); + + rule.setTarget(targetInRule); + rule.setAdviceExpressions(getAdviceExpressions(version, policyName)); + + configPolicy + .getCombinerParametersOrRuleCombinerParametersOrVariableDefinition() + .add(rule); + policyAdapter.setPolicyData(configPolicy); + + } else { + //TODO:EELF Cleanup - Remove logger + //logger.error("Unsupported data object." + //+ policyAdapter.getData().getClass().getCanonicalName()); + PolicyLogger.error("Unsupported data object." + + policyAdapter.getData().getClass().getCanonicalName()); + } + setPreparedToSave(true); + return true; + } + + // Data required for Advice part is setting here. + private AdviceExpressionsType getAdviceExpressions(int version, + String fileName) { + + // Policy Config ID Assignment + AdviceExpressionsType advices = new AdviceExpressionsType(); + AdviceExpressionType advice = new AdviceExpressionType(); + advice.setAdviceId("BRMSRAWID"); + advice.setAppliesTo(EffectType.PERMIT); + // For Configuration + AttributeAssignmentExpressionType assignment1 = new AttributeAssignmentExpressionType(); + assignment1.setAttributeId("type"); + assignment1.setCategory(CATEGORY_RESOURCE); + assignment1.setIssuer(""); + AttributeValueType configNameAttributeValue = new AttributeValueType(); + configNameAttributeValue.setDataType(STRING_DATATYPE); + configNameAttributeValue.getContent().add("Configuration"); + assignment1.setExpression(new ObjectFactory() + .createAttributeValue(configNameAttributeValue)); + advice.getAttributeAssignmentExpression().add(assignment1); + + // For Config file Url if configurations are provided. + // URL ID Assignment + final Path gitPath = Paths.get(policyAdapter.getUserGitPath() + .toString()); + AttributeAssignmentExpressionType assignment2 = new AttributeAssignmentExpressionType(); + assignment2.setAttributeId("URLID"); + assignment2.setCategory(CATEGORY_RESOURCE); + assignment2.setIssuer(""); + AttributeValueType AttributeValue = new AttributeValueType(); + AttributeValue.setDataType(URI_DATATYPE); + String policyDir1 = policyAdapter.getParentPath().toString(); + int startIndex1 = policyDir1.indexOf(gitPath.toString()) + + gitPath.toString().length() + 1; + policyDir1 = policyDir1.substring(startIndex1, policyDir1.length()); + logger.info("print the main domain value" + policyDir1); + String path = policyDir1.replace('\\', '.'); + if (path.contains("/")) { + path = policyDir1.replace('/', '.'); + logger.info("print the path:" + path); + } + String content = CONFIG_URL + "/Config/" + path + "." + + getConfigFile(policyName); + + AttributeValue.getContent().add(content); + assignment2.setExpression(new ObjectFactory() + .createAttributeValue(AttributeValue)); + advice.getAttributeAssignmentExpression().add(assignment2); + + // Policy Name Assignment + AttributeAssignmentExpressionType assignment3 = new AttributeAssignmentExpressionType(); + assignment3.setAttributeId("PolicyName"); + assignment3.setCategory(CATEGORY_RESOURCE); + assignment3.setIssuer(""); + AttributeValueType attributeValue3 = new AttributeValueType(); + attributeValue3.setDataType(STRING_DATATYPE); + String policyDir = policyAdapter.getParentPath().toString(); + int startIndex = policyDir.indexOf(gitPath.toString()) + + gitPath.toString().length() + 1; + policyDir = policyDir.substring(startIndex, policyDir.length()); + StringTokenizer tokenizer = null; + StringBuffer buffer = new StringBuffer(); + if (policyDir.contains("\\")) { + tokenizer = new StringTokenizer(policyDir, "\\"); + } else { + tokenizer = new StringTokenizer(policyDir, "/"); + } + if (tokenizer != null) { + while (tokenizer.hasMoreElements()) { + String value = tokenizer.nextToken(); + buffer.append(value); + buffer.append("."); + } + } + fileName = FilenameUtils.removeExtension(fileName); + fileName = buffer.toString() + fileName + ".xml"; + System.out.println(fileName); + String name = fileName.substring(fileName.lastIndexOf("\\") + 1, + fileName.length()); + if ((name == null) || (name.equals(""))) { + name = fileName.substring(fileName.lastIndexOf("/") + 1, + fileName.length()); + } + System.out.println(name); + attributeValue3.getContent().add(name); + assignment3.setExpression(new ObjectFactory() + .createAttributeValue(attributeValue3)); + advice.getAttributeAssignmentExpression().add(assignment3); + + // Version Number Assignment + AttributeAssignmentExpressionType assignment4 = new AttributeAssignmentExpressionType(); + assignment4.setAttributeId("VersionNumber"); + assignment4.setCategory(CATEGORY_RESOURCE); + assignment4.setIssuer(""); + AttributeValueType configNameAttributeValue4 = new AttributeValueType(); + configNameAttributeValue4.setDataType(STRING_DATATYPE); + configNameAttributeValue4.getContent().add(Integer.toString(version)); + assignment4.setExpression(new ObjectFactory() + .createAttributeValue(configNameAttributeValue4)); + advice.getAttributeAssignmentExpression().add(assignment4); + + // Ecomp Name Assignment + AttributeAssignmentExpressionType assignment5 = new AttributeAssignmentExpressionType(); + assignment5.setAttributeId("matching:" + this.ECOMPID); + assignment5.setCategory(CATEGORY_RESOURCE); + assignment5.setIssuer(""); + AttributeValueType configNameAttributeValue5 = new AttributeValueType(); + configNameAttributeValue5.setDataType(STRING_DATATYPE); + configNameAttributeValue5.getContent().add(policyAdapter.getEcompName()); + assignment5.setExpression(new ObjectFactory() + .createAttributeValue(configNameAttributeValue5)); + advice.getAttributeAssignmentExpression().add(assignment5); + + + //Config Name Assignment + AttributeAssignmentExpressionType assignment6 = new AttributeAssignmentExpressionType(); + assignment6.setAttributeId("matching:" + this.CONFIGID); + assignment6.setCategory(CATEGORY_RESOURCE); + assignment6.setIssuer(""); + AttributeValueType configNameAttributeValue6 = new AttributeValueType(); + configNameAttributeValue6.setDataType(STRING_DATATYPE); + configNameAttributeValue6.getContent().add(policyAdapter.getConfigName()); + assignment6.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue6)); + advice.getAttributeAssignmentExpression().add(assignment6); + + Map dynamicFieldConfigAttributes = policyAdapter.getDynamicFieldConfigAttributes(); + for (String keyField : dynamicFieldConfigAttributes.keySet()) { + String key = keyField; + String value = dynamicFieldConfigAttributes.get(key); + AttributeAssignmentExpressionType assignment7 = new AttributeAssignmentExpressionType(); + assignment7.setAttributeId("key:" + key); + assignment7.setCategory(CATEGORY_RESOURCE); + assignment7.setIssuer(""); + + AttributeValueType configNameAttributeValue7 = new AttributeValueType(); + configNameAttributeValue7.setDataType(STRING_DATATYPE); + configNameAttributeValue7.getContent().add(value); + assignment7.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue7)); + + advice.getAttributeAssignmentExpression().add(assignment7); + } + + //Risk Attributes + AttributeAssignmentExpressionType assignment8 = new AttributeAssignmentExpressionType(); + assignment8.setAttributeId("RiskType"); + assignment8.setCategory(CATEGORY_RESOURCE); + assignment8.setIssuer(""); + + AttributeValueType configNameAttributeValue8 = new AttributeValueType(); + configNameAttributeValue8.setDataType(STRING_DATATYPE); + configNameAttributeValue8.getContent().add(policyAdapter.getRiskType()); + assignment8.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue8)); + + advice.getAttributeAssignmentExpression().add(assignment8); + + AttributeAssignmentExpressionType assignment9 = new AttributeAssignmentExpressionType(); + assignment9.setAttributeId("RiskLevel"); + assignment9.setCategory(CATEGORY_RESOURCE); + assignment9.setIssuer(""); + + AttributeValueType configNameAttributeValue9 = new AttributeValueType(); + configNameAttributeValue9.setDataType(STRING_DATATYPE); + configNameAttributeValue9.getContent().add(policyAdapter.getRiskLevel()); + assignment9.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue9)); + + advice.getAttributeAssignmentExpression().add(assignment9); + + AttributeAssignmentExpressionType assignment10 = new AttributeAssignmentExpressionType(); + assignment10.setAttributeId("guard"); + assignment10.setCategory(CATEGORY_RESOURCE); + assignment10.setIssuer(""); + + AttributeValueType configNameAttributeValue10 = new AttributeValueType(); + configNameAttributeValue10.setDataType(STRING_DATATYPE); + configNameAttributeValue10.getContent().add(policyAdapter.getGuard()); + assignment10.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue10)); + + advice.getAttributeAssignmentExpression().add(assignment10); + + AttributeAssignmentExpressionType assignment11 = new AttributeAssignmentExpressionType(); + assignment11.setAttributeId("TTLDate"); + assignment11.setCategory(CATEGORY_RESOURCE); + assignment11.setIssuer(""); + + AttributeValueType configNameAttributeValue11 = new AttributeValueType(); + configNameAttributeValue11.setDataType(STRING_DATATYPE); + configNameAttributeValue11.getContent().add(policyAdapter.getTtlDate()); + assignment11.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue11)); + + advice.getAttributeAssignmentExpression().add(assignment11); + + advices.getAdviceExpression().add(advice); + return advices; + } + + @Override + public Object getCorrectPolicyDataObject() { + return policyAdapter.getData(); + } +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/CreateClosedLoopPerformanceMetrics.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/CreateClosedLoopPerformanceMetrics.java new file mode 100644 index 000000000..578efc228 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/CreateClosedLoopPerformanceMetrics.java @@ -0,0 +1,506 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.components; + + +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; +import java.net.URI; +import java.net.URISyntaxException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.Map; +import java.util.StringTokenizer; + +import javax.json.stream.JsonGenerationException; + +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionsType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeAssignmentExpressionType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.EffectType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObjectFactory; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.RuleType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType; + +import org.apache.commons.io.FilenameUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openecomp.policy.pap.xacml.rest.adapters.PolicyRestAdapter; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; +import com.att.research.xacml.std.IdentifierImpl; + +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.eelf.PolicyLogger; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +public class CreateClosedLoopPerformanceMetrics extends Policy { + + /** + * Config Fields + */ + private static final Logger logger = FlexLogger.getLogger(ConfigPolicy.class); + + public CreateClosedLoopPerformanceMetrics() { + super(); + } + + public CreateClosedLoopPerformanceMetrics(PolicyRestAdapter policyAdapter){ + this.policyAdapter = policyAdapter; + } + + //save configuration of the policy based on the policyname + private void saveConfigurations(String policyName, String prevPolicyName, String jsonBody) { + String domain = getParentPathSubScopeDir(); + String path = domain.replace('\\', '.'); + if(path.contains("/")){ + path = domain.replace('/', '.'); + logger.info("print the path:" +path); + } + try { + String body = null; + try { + body = jsonBody; + } catch (Exception e) { + e.printStackTrace(); + } + + System.out.println(body); + if(policyName.endsWith(".xml")){ + policyName = policyName.substring(0, policyName.lastIndexOf(".xml")); + } + PrintWriter out = new PrintWriter(CONFIG_HOME + File.separator+path + "."+ policyName +".json"); + out.println(body); + out.close(); + + } catch (JsonGenerationException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + + } + + //getting the policy name and setting to configuration on adding .json + private String getConfigFile(String filename) { + filename = FilenameUtils.removeExtension(filename); + if (filename.endsWith(".xml")) { + filename = filename.substring(0, filename.length() - 4); + } + filename = filename +".json"; + return filename; + } + + @Override + public Map savePolicies() throws Exception { + + Map successMap = new HashMap(); + if(isPolicyExists()){ + successMap.put("EXISTS", "This Policy already exist on the PAP"); + return successMap; + } + + if(!isPreparedToSave()){ + //Prep and configure the policy for saving + prepareToSave(); + } + + // Until here we prepared the data and here calling the method to create xml. + Path newPolicyPath = null; + newPolicyPath = Paths.get(policyAdapter.getParentPath().toString(), policyName); + successMap = createPolicy(newPolicyPath,getCorrectPolicyDataObject() ); + if (successMap.containsKey("success")) { + Path finalPolicyPath = getFinalPolicyPath(); + policyAdapter.setFinalPolicyPath(finalPolicyPath.toString()); + } + return successMap; + } + + //This is the method for preparing the policy for saving. We have broken it out + //separately because the fully configured policy is used for multiple things + @Override + public boolean prepareToSave() throws Exception{ + + if(isPreparedToSave()){ + //we have already done this + return true; + } + + int version = 0; + String policyID = policyAdapter.getPolicyID(); + + if (policyAdapter.isEditPolicy()) { + version = policyAdapter.getHighestVersion() + 1; + } else { + version = 1; + } + + // Create the Instance for pojo, PolicyType object is used in marshalling. + if (policyAdapter.getPolicyType().equals("Config")) { + PolicyType policyConfig = new PolicyType(); + + policyConfig.setVersion(Integer.toString(version)); + policyConfig.setPolicyId(policyID); + policyConfig.setTarget(new TargetType()); + policyAdapter.setData(policyConfig); + } + + if (policyAdapter.getData() != null) { + + // Save off everything + // making ready all the required elements to generate the action policy xml. + // Get the uniqueness for policy name. + String prevPolicyName = null; + if(policyAdapter.isEditPolicy()){ + prevPolicyName = "Config_PM_" + policyAdapter.getPolicyName() + "." + policyAdapter.getHighestVersion() + ".xml"; + } + + Path newFile = this.getNextLoopFilename(Paths.get(policyAdapter.getParentPath()), policyAdapter.getPolicyType(), policyAdapter.getConfigPolicyType(), policyAdapter.getPolicyName(), version); + + if (newFile == null) { + //TODO:EELF Cleanup - Remove logger + //logger.error("File already exists, cannot create the policy."); + PolicyLogger.error("File already exists, cannot create the policy."); + setPolicyExists(true); + return false; + } + + policyName = newFile.getFileName().toString(); + + // Save the Configurations file with the policy name with extention based on selection. + String jsonBody = policyAdapter.getJsonBody(); + saveConfigurations(policyName, prevPolicyName, jsonBody); + + // Make sure the filename ends with an extension + if (policyName.endsWith(".xml") == false) { + policyName = policyName + ".xml"; + } + + + PolicyType configPolicy = (PolicyType) policyAdapter.getData(); + + configPolicy.setDescription(policyAdapter.getPolicyDescription()); + + configPolicy.setRuleCombiningAlgId(policyAdapter.getRuleCombiningAlgId()); + + AllOfType allOfOne = new AllOfType(); + final Path gitPath = Paths.get(policyAdapter.getUserGitPath().toString()); + String policyDir = policyAdapter.getParentPath().toString(); + int startIndex = policyDir.indexOf(gitPath.toString()) + gitPath.toString().length() + 1; + policyDir = policyDir.substring(startIndex, policyDir.length()); + logger.info("print the main domain value "+policyDir); + String path = policyDir.replace('\\', '.'); + if(path.contains("/")){ + path = policyDir.replace('/', '.'); + logger.info("print the path:" +path); + } + String fileName = FilenameUtils.removeExtension(policyName); + fileName = path + "." + fileName + ".xml"; + String name = fileName.substring(fileName.lastIndexOf("\\") + 1, fileName.length()); + if ((name == null) || (name.equals(""))) { + name = fileName.substring(fileName.lastIndexOf("/") + 1, fileName.length()); + } + allOfOne.getMatch().add(createMatch("PolicyName", name)); + AllOfType allOf = new AllOfType(); + + // Adding the matches to AllOfType element Match for Ecomp + allOf.getMatch().add(createMatch("ECOMPName", policyAdapter.getEcompName())); + // Match for riskType + allOf.getMatch().add( + createDynamicMatch("RiskType", policyAdapter.getRiskType())); + // Match for riskLevel + allOf.getMatch().add( + createDynamicMatch("RiskLevel", String.valueOf(policyAdapter.getRiskLevel()))); + // Match for riskguard + allOf.getMatch().add( + createDynamicMatch("guard", policyAdapter.getGuard())); + // Match for ttlDate + allOf.getMatch().add( + createDynamicMatch("TTLDate", policyAdapter.getTtlDate())); + // Match for ServiceType + allOf.getMatch().add(createMatch("ServiceType", policyAdapter.getServiceType())); + + AnyOfType anyOf = new AnyOfType(); + anyOf.getAllOf().add(allOfOne); + anyOf.getAllOf().add(allOf); + + TargetType target = new TargetType(); + ((TargetType) target).getAnyOf().add(anyOf); + + // Adding the target to the policy element + configPolicy.setTarget((TargetType) target); + + RuleType rule = new RuleType(); + rule.setRuleId(policyAdapter.getRuleID()); + + rule.setEffect(EffectType.PERMIT); + + // Create Target in Rule + AllOfType allOfInRule = new AllOfType(); + + // Creating match for ACCESS in rule target + MatchType accessMatch = new MatchType(); + AttributeValueType accessAttributeValue = new AttributeValueType(); + accessAttributeValue.setDataType(STRING_DATATYPE); + accessAttributeValue.getContent().add("ACCESS"); + accessMatch.setAttributeValue(accessAttributeValue); + AttributeDesignatorType accessAttributeDesignator = new AttributeDesignatorType(); + URI accessURI = null; + try { + accessURI = new URI(ACTION_ID); + } catch (URISyntaxException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e.getStackTrace()); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "CreateClosedLoopPerformanceMetrics", "Exception creating ACCESS URI"); + } + accessAttributeDesignator.setCategory(CATEGORY_ACTION); + accessAttributeDesignator.setDataType(STRING_DATATYPE); + accessAttributeDesignator.setAttributeId(new IdentifierImpl(accessURI).stringValue()); + accessMatch.setAttributeDesignator(accessAttributeDesignator); + accessMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE); + + // Creating Config Match in rule Target + MatchType configMatch = new MatchType(); + AttributeValueType configAttributeValue = new AttributeValueType(); + configAttributeValue.setDataType(STRING_DATATYPE); + configAttributeValue.getContent().add("Config"); + configMatch.setAttributeValue(configAttributeValue); + AttributeDesignatorType configAttributeDesignator = new AttributeDesignatorType(); + URI configURI = null; + try { + configURI = new URI(RESOURCE_ID); + } catch (URISyntaxException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e.getStackTrace()); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "CreateClosedLoopPerformanceMetrics", "Exception creating Config URI"); + } + configAttributeDesignator.setCategory(CATEGORY_RESOURCE); + configAttributeDesignator.setDataType(STRING_DATATYPE); + configAttributeDesignator.setAttributeId(new IdentifierImpl(configURI).stringValue()); + configMatch.setAttributeDesignator(configAttributeDesignator); + configMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE); + + allOfInRule.getMatch().add(accessMatch); + allOfInRule.getMatch().add(configMatch); + + AnyOfType anyOfInRule = new AnyOfType(); + anyOfInRule.getAllOf().add(allOfInRule); + + TargetType targetInRule = new TargetType(); + targetInRule.getAnyOf().add(anyOfInRule); + + rule.setTarget(targetInRule); + rule.setAdviceExpressions(getAdviceExpressions(version, policyName)); + + configPolicy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().add(rule); + policyAdapter.setPolicyData(configPolicy); + + } else { + //TODO:EELF Cleanup - Remove logger + //logger.error("Unsupported data object." + policyAdapter.getData().getClass().getCanonicalName()); + PolicyLogger.error("Unsupported data object." + policyAdapter.getData().getClass().getCanonicalName()); + } + setPreparedToSave(true); + return true; + } + + // Data required for Advice part is setting here. + @SuppressWarnings("static-access") + private AdviceExpressionsType getAdviceExpressions(int version, String fileName) { + AdviceExpressionsType advices = new AdviceExpressionsType(); + AdviceExpressionType advice = new AdviceExpressionType(); + advice.setAdviceId("PMID"); + advice.setAppliesTo(EffectType.PERMIT); + // For Configuration + AttributeAssignmentExpressionType assignment1 = new AttributeAssignmentExpressionType(); + assignment1.setAttributeId("type"); + assignment1.setCategory(CATEGORY_RESOURCE); + assignment1.setIssuer(""); + + AttributeValueType configNameAttributeValue = new AttributeValueType(); + configNameAttributeValue.setDataType(STRING_DATATYPE); + configNameAttributeValue.getContent().add("Configuration"); + assignment1.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue)); + + advice.getAttributeAssignmentExpression().add(assignment1); + final Path gitPath = Paths.get(policyAdapter.getUserGitPath().toString()); + // For Config file Url if configurations are provided. + AttributeAssignmentExpressionType assignment2 = new AttributeAssignmentExpressionType(); + assignment2.setAttributeId("URLID"); + assignment2.setCategory(CATEGORY_RESOURCE); + assignment2.setIssuer(""); + + AttributeValueType AttributeValue = new AttributeValueType(); + AttributeValue.setDataType(URI_DATATYPE); + String policyDir1 = policyAdapter.getParentPath().toString(); + int startIndex1 = policyDir1.indexOf(gitPath.toString()) + gitPath.toString().length() + 1; + policyDir1 = policyDir1.substring(startIndex1, policyDir1.length()); + logger.info("print the main domain value"+policyDir1); + String path = policyDir1.replace('\\', '.'); + if(path.contains("/")){ + path = policyDir1.replace('/', '.'); + logger.info("print the path:" +path); + } + String content = CONFIG_URL +"/Config/" + path + "." + getConfigFile(policyName); + System.out.println("URL value :" + content); + AttributeValue.getContent().add(content); + assignment2.setExpression(new ObjectFactory().createAttributeValue(AttributeValue)); + + advice.getAttributeAssignmentExpression().add(assignment2); + AttributeAssignmentExpressionType assignment3 = new AttributeAssignmentExpressionType(); + assignment3.setAttributeId("PolicyName"); + assignment3.setCategory(CATEGORY_RESOURCE); + assignment3.setIssuer(""); + + AttributeValueType attributeValue3 = new AttributeValueType(); + attributeValue3.setDataType(STRING_DATATYPE); + String policyDir = policyAdapter.getParentPath().toString(); + int startIndex = policyDir.indexOf(gitPath.toString()) + gitPath.toString().length() + 1; + policyDir = policyDir.substring(startIndex, policyDir.length()); + StringTokenizer tokenizer = null; + StringBuffer buffer = new StringBuffer(); + if (policyDir.contains("\\")) { + tokenizer = new StringTokenizer(policyDir, "\\"); + } else { + tokenizer = new StringTokenizer(policyDir, "/"); + } + if (tokenizer != null) { + while (tokenizer.hasMoreElements()) { + String value = tokenizer.nextToken(); + buffer.append(value); + buffer.append("."); + } + } + fileName = FilenameUtils.removeExtension(fileName); + fileName = buffer.toString() + fileName + ".xml"; + String name = fileName.substring(fileName.lastIndexOf("\\") + 1, fileName.length()); + if ((name == null) || (name.equals(""))) { + name = fileName.substring(fileName.lastIndexOf("/") + 1, fileName.length()); + } + attributeValue3.getContent().add(name); + assignment3.setExpression(new ObjectFactory().createAttributeValue(attributeValue3)); + advice.getAttributeAssignmentExpression().add(assignment3); + + AttributeAssignmentExpressionType assignment4 = new AttributeAssignmentExpressionType(); + assignment4.setAttributeId("VersionNumber"); + assignment4.setCategory(CATEGORY_RESOURCE); + assignment4.setIssuer(""); + + AttributeValueType configNameAttributeValue4 = new AttributeValueType(); + configNameAttributeValue4.setDataType(STRING_DATATYPE); + configNameAttributeValue4.getContent().add(Integer.toString(version)); + assignment4.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue4)); + + advice.getAttributeAssignmentExpression().add(assignment4); + + AttributeAssignmentExpressionType assignment5 = new AttributeAssignmentExpressionType(); + assignment5.setAttributeId("matching:" + this.ECOMPID); + assignment5.setCategory(CATEGORY_RESOURCE); + assignment5.setIssuer(""); + + AttributeValueType configNameAttributeValue5 = new AttributeValueType(); + configNameAttributeValue5.setDataType(STRING_DATATYPE); + configNameAttributeValue5.getContent().add(policyAdapter.getEcompName()); + assignment5.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue5)); + + advice.getAttributeAssignmentExpression().add(assignment5); + + AttributeAssignmentExpressionType assignment6 = new AttributeAssignmentExpressionType(); + assignment6.setAttributeId("matching:" + this.CLOSEDLOOPID); + assignment6.setCategory(CATEGORY_RESOURCE); + assignment6.setIssuer(""); + + AttributeValueType configNameAttributeValue6 = new AttributeValueType(); + configNameAttributeValue6.setDataType(STRING_DATATYPE); + configNameAttributeValue6.getContent().add(policyAdapter.getServiceType()); + assignment6.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue6)); + + advice.getAttributeAssignmentExpression().add(assignment6); + + //Risk Attributes + AttributeAssignmentExpressionType assignment7 = new AttributeAssignmentExpressionType(); + assignment7.setAttributeId("RiskType"); + assignment7.setCategory(CATEGORY_RESOURCE); + assignment7.setIssuer(""); + + AttributeValueType configNameAttributeValue7 = new AttributeValueType(); + configNameAttributeValue7.setDataType(STRING_DATATYPE); + configNameAttributeValue7.getContent().add(policyAdapter.getRiskType()); + assignment7.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue7)); + + advice.getAttributeAssignmentExpression().add(assignment7); + + AttributeAssignmentExpressionType assignment8 = new AttributeAssignmentExpressionType(); + assignment8.setAttributeId("RiskLevel"); + assignment8.setCategory(CATEGORY_RESOURCE); + assignment8.setIssuer(""); + + AttributeValueType configNameAttributeValue8 = new AttributeValueType(); + configNameAttributeValue8.setDataType(STRING_DATATYPE); + configNameAttributeValue8.getContent().add(policyAdapter.getRiskLevel()); + assignment8.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue8)); + + advice.getAttributeAssignmentExpression().add(assignment8); + + AttributeAssignmentExpressionType assignment9 = new AttributeAssignmentExpressionType(); + assignment9.setAttributeId("guard"); + assignment9.setCategory(CATEGORY_RESOURCE); + assignment9.setIssuer(""); + + AttributeValueType configNameAttributeValue9 = new AttributeValueType(); + configNameAttributeValue9.setDataType(STRING_DATATYPE); + configNameAttributeValue9.getContent().add(policyAdapter.getGuard()); + assignment9.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue9)); + + advice.getAttributeAssignmentExpression().add(assignment9); + + AttributeAssignmentExpressionType assignment10 = new AttributeAssignmentExpressionType(); + assignment10.setAttributeId("TTLDate"); + assignment10.setCategory(CATEGORY_RESOURCE); + assignment10.setIssuer(""); + + AttributeValueType configNameAttributeValue10 = new AttributeValueType(); + configNameAttributeValue10.setDataType(STRING_DATATYPE); + configNameAttributeValue10.getContent().add(policyAdapter.getTtlDate()); + assignment10.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue10)); + + advice.getAttributeAssignmentExpression().add(assignment10); + + advices.getAdviceExpression().add(advice); + return advices; + } + + @Override + public Object getCorrectPolicyDataObject() { + // TODO Auto-generated method stub + return policyAdapter.getPolicyData(); + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/CreateNewMicroSerivceModel.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/CreateNewMicroSerivceModel.java new file mode 100644 index 000000000..73479fd2b --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/CreateNewMicroSerivceModel.java @@ -0,0 +1,305 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.components; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; + +import org.apache.commons.io.FileUtils; +import org.apache.commons.lang.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +//import org.eclipse.emf.common.util.URI; +//import org.eclipse.emf.ecore.EPackage; +//import org.eclipse.emf.ecore.resource.Resource; +//import org.eclipse.emf.ecore.resource.ResourceSet; +//import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; +//import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; +import org.openecomp.policy.rest.XACMLRestProperties; +import org.openecomp.policy.rest.jpa.MicroServiceModels; +import org.openecomp.policy.rest.jpa.UserInfo; +import org.openecomp.policy.rest.util.MSAttributeObject; +import org.openecomp.policy.rest.util.MSModelUtitils; + +import com.att.research.xacml.util.XACMLProperties; + +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.eelf.PolicyLogger; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +public class CreateNewMicroSerivceModel { + private static final Logger logger = FlexLogger.getLogger(CreateNewMicroSerivceModel.class); + private MicroServiceModels newModel = null; + private HashMap classMap = new HashMap(); + private String directory; + + /* + * These are the parameters needed for DB access from the PAP + */ + private static String papDbDriver = null; + private static String papDbUrl = null; + private static String papDbUser = null; + private static String papDbPassword = null; + + MSModelUtitils utils = new MSModelUtitils(); + + public CreateNewMicroSerivceModel(String fileName, String serviceName, String string, String version) { + super(); + } + + public CreateNewMicroSerivceModel(String importFile, String modelName, String description, String version, String randomID) { + + Map successMap = new HashMap(); + this.newModel = new MicroServiceModels(); + this.newModel.setDescription(description); + this.newModel.setVersion(version); + this.newModel.setModelName(modelName); + UserInfo userInfo = new UserInfo(); + userInfo.setUserLoginId("API"); + this.newModel.setUserCreatedBy(userInfo); + String cleanUpFile = null; + + HashMap tempMap = new HashMap(); + //Need to delete the file + if (importFile.contains(".zip")){ + extractFolder(randomID + ".zip"); + File directory = new File("ExtractDir" + File.separator + randomID); + List fileList = listModelFiles(directory.toString()); + //get all the files from a directory + File[] fList = directory.listFiles(); + for (File file : fileList){ + if (file.isFile()){ + tempMap = utils.processEpackage(file.getAbsolutePath()); + classMap.putAll(tempMap); + } + } + cleanUpFile = "ExtractDir" + File.separator + randomID + ".zip"; + try { + FileUtils.deleteDirectory(new File("ExtractDir" + File.separator + randomID)); + FileUtils.deleteDirectory(new File(randomID)); + File deleteFile = new File(cleanUpFile); + FileUtils.forceDelete(deleteFile); + } catch (IOException e) { + logger.error("Failed to unzip model file " + randomID); + } + }else { + tempMap = utils.processEpackage("ExtractDir" + File.separator + randomID+".xmi"); + classMap.putAll(tempMap); + cleanUpFile = "ExtractDir" + File.separator + randomID+".xmi"; + File deleteFile = new File(cleanUpFile); + deleteFile.delete(); + } + + // addValuesToNewModel(); + + + } + + private List listModelFiles(String directoryName) { + File directory = new File(directoryName); + List resultList = new ArrayList(); + File[] fList = directory.listFiles(); + for (File file : fList) { + if (file.isFile()) { + resultList.add(file); + } else if (file.isDirectory()) { + resultList.addAll(listModelFiles(file.getAbsolutePath())); + } + } + return resultList; + } + + private void extractFolder(String zipFile) { + int BUFFER = 2048; + File file = new File(zipFile); + + ZipFile zip; + try { + zip = new ZipFile("ExtractDir" + File.separator +file); + String newPath = zipFile.substring(0, zipFile.length() - 4); + this.directory = "ExtractDir" + File.separator + zipFile.substring(0, zipFile.length() - 4); + new File(newPath).mkdir(); + Enumeration zipFileEntries = zip.entries(); + + // Process each entry + while (zipFileEntries.hasMoreElements()) + { + // grab a zip file entry + ZipEntry entry = (ZipEntry) zipFileEntries.nextElement(); + String currentEntry = entry.getName(); + File destFile = new File("ExtractDir" + File.separator + newPath + File.separator + currentEntry); + File destinationParent = destFile.getParentFile(); + + destinationParent.mkdirs(); + + if (!entry.isDirectory()) + { + BufferedInputStream is = new BufferedInputStream(zip + .getInputStream(entry)); + int currentByte; + + byte data[] = new byte[BUFFER]; + + FileOutputStream fos = new FileOutputStream(destFile); + BufferedOutputStream dest = new BufferedOutputStream(fos, + BUFFER); + + while ((currentByte = is.read(data, 0, BUFFER)) != -1) { + dest.write(data, 0, currentByte); + } + dest.flush(); + dest.close(); + is.close(); + } + + if (currentEntry.endsWith(".zip")) + { + extractFolder(destFile.getAbsolutePath()); + } + } + } catch (IOException e) { + logger.error("Failed to unzip model file " + zipFile); + } + } + + public Map addValuesToNewModel() { + + Map successMap = new HashMap(); + MSAttributeObject mainClass = null; + ArrayList dependency = null; + String subAttribute = null; + + if (!classMap.containsKey(this.newModel.getModelName())){ + logger.error("Model Provided does not contain the service name provided in request. Unable to import new model"); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "AddValuesToNewModel", "Unable to pull out required values, file missing service name provided in request"); + successMap.put("error", "MISSING"); + return successMap; + } + mainClass = classMap.get(this.newModel.getModelName()); + String dependTemp = StringUtils.replaceEach(mainClass.getDependency(), new String[]{"[", "]", " "}, new String[]{"", "", ""}); + this.newModel.setDependency(dependTemp); + if (!this.newModel.getDependency().equals("")){ + dependency = new ArrayList(Arrays.asList(dependTemp.split(","))); + dependency = utils.getFullDependencyList(dependency, classMap); + if (!dependency.isEmpty()){ + for (String element : dependency){ + MSAttributeObject temp = new MSAttributeObject(); + if (classMap.containsKey(element)){ + temp = classMap.get(element); + mainClass.addAllRefAttribute(temp.getRefAttribute()); + mainClass.addAllAttribute(temp.getAttribute()); + } + } + } + } + subAttribute = utils.createSubAttributes(dependency, classMap, this.newModel.getModelName()); + + this.newModel.setSub_attributes(subAttribute); + this.newModel.setAttributes(mainClass.getAttribute().toString().replace("{", "").replace("}", "")); + this.newModel.setRef_attributes(mainClass.getRefAttribute().toString().replace("{", "").replace("}", "")); + successMap.put("success", "success"); + return successMap; + + } + + public Map saveImportService(){ + Map successMap = new HashMap(); + + Connection con = null; + Statement st = null; + ResultSet rs = null; + String modelName = this.newModel.getModelName(); + String imported_by = "API";//////////////////////////////////////////// + String version = this.newModel.getVersion(); + String insertQuery = null; + int ID = 0; + + /* + * Retrieve the property values for db access from the xacml.pap.properties + */ + papDbDriver = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_DB_DRIVER); + papDbUrl = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_DB_URL); + papDbUser = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_DB_USER); + papDbPassword = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_DB_PASSWORD); + + try { + //Get DB Connection + Class.forName(papDbDriver); + con = DriverManager.getConnection(papDbUrl,papDbUser,papDbPassword); + st = con.createStatement(); + String queryString ="SELECT * FROM MicroServiceModels WHERE modelName='" + modelName + "' AND version='" + version+ "';"; + rs = st.executeQuery(queryString); + + if(rs.next()){ + successMap.put("DBError", "EXISTS"); + logger.error("Import new service failed. Service already exists"); + }else{ + rs = st.executeQuery("SELECT MAX(ID) AS ID FROM MicroServiceModels;"); + if(rs.next()){ + ID = rs.getInt("ID"); + ID++; + } + + insertQuery = "INSERT INTO MicroServiceModels (ID, modelName, Dependency, DESCRIPTION, attributes, ref_attributes, sub_attributes, version, imported_by) " + + "VALUES("+ID+",'"+modelName+"','"+ this.newModel.getDependency()+"','"+this.newModel.getDescription()+"','"+this.newModel.getAttributes()+ + "','"+this.newModel.getRef_attributes()+"','"+this.newModel.getSub_attributes()+"','"+version+"','"+imported_by+"')"; + st.executeUpdate(insertQuery); + successMap.put("success", "success"); + } + rs.close(); + }catch (ClassNotFoundException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(e.getMessage()); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "saveImportService", "Exception querying MicroServiceModels"); + successMap.put("DBError", "Error Query"); + } catch (SQLException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(e.getMessage()); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "saveImportService", "Exception querying MicroServiceModels"); + successMap.put("DBError", "Error Query"); + } finally { + try{ + if (con!=null) con.close(); + if (rs!=null) rs.close(); + if (st!=null) st.close(); + } catch (Exception ex){} + } + + return successMap; + } +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/DecisionPolicy.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/DecisionPolicy.java new file mode 100644 index 000000000..822768f6d --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/DecisionPolicy.java @@ -0,0 +1,633 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.components; + +import java.net.URI; +import java.net.URISyntaxException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import javax.persistence.EntityManager; +import javax.persistence.Query; + +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionsType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.ApplyType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeAssignmentExpressionType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.ConditionType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.EffectType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObjectFactory; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.RuleType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.VariableDefinitionType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.VariableReferenceType; + +import org.apache.commons.io.FilenameUtils; +import org.openecomp.policy.pap.xacml.rest.adapters.PolicyRestAdapter; +import org.openecomp.policy.pap.xacml.rest.util.JPAUtils; +import org.openecomp.policy.rest.jpa.Datatype; +import org.openecomp.policy.rest.jpa.DecisionSettings; +import org.openecomp.policy.rest.jpa.FunctionDefinition; +import org.openecomp.policy.xacml.std.pip.engines.aaf.AAFEngine; + +import com.att.research.xacml.std.IdentifierImpl; + +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.eelf.PolicyLogger; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +public class DecisionPolicy extends Policy { + + /** + * Config Fields + */ + private static final Logger logger = FlexLogger.getLogger(ConfigPolicy.class); + + public static final String JSON_CONFIG = "JSON"; + public static final String XML_CONFIG = "XML"; + public static final String PROPERTIES_CONFIG = "PROPERTIES"; + public static final String OTHER_CONFIG = "OTHER"; + + public static final String PDP_ACTION = "PDP"; + public static final String PEP_ACTION = "PEP"; + public static final String TYPE_ACTION = "REST"; + + public static final String GET_METHOD = "GET"; + public static final String PUT_METHOD = "PUT"; + public static final String POST_METHOD = "POST"; + + public static final String PERFORMER_ATTRIBUTEID = "performer"; + public static final String TYPE_ATTRIBUTEID = "type"; + public static final String METHOD_ATTRIBUTEID = "method"; + public static final String HEADERS_ATTRIBUTEID = "headers"; + public static final String URL_ATTRIBUTEID = "url"; + public static final String BODY_ATTRIBUTEID = "body"; + + public static final String FUNCTION_NOT = "urn:oasis:names:tc:xacml:1.0:function:not"; + + private static final String AAFProvider = "AAF"; + //private static final String CustomProvider = "Custom"; + + List dynamicLabelRuleAlgorithms = new LinkedList(); + List dynamicFieldComboRuleAlgorithms = new LinkedList(); + List dynamicFieldOneRuleAlgorithms = new LinkedList(); + List dynamicFieldTwoRuleAlgorithms = new LinkedList(); + //List dynamicVariableList = new LinkedList(); + List dataTypeList = new LinkedList(); + + protected Map dropDownMap = new HashMap(); + + + public DecisionPolicy() { + super(); + } + + public DecisionPolicy(PolicyRestAdapter policyAdapter){ + this.policyAdapter = policyAdapter; + } + + @Override + public Map savePolicies() throws Exception { + + Map successMap = new HashMap(); + if(isPolicyExists()){ + successMap.put("EXISTS", "This Policy already exist on the PAP"); + return successMap; + } + + if(!isPreparedToSave()){ + //Prep and configure the policy for saving + prepareToSave(); + } + + // Until here we prepared the data and here calling the method to create xml. + Path newPolicyPath = null; + newPolicyPath = Paths.get(policyAdapter.getParentPath().toString(), policyName); + successMap = createPolicy(newPolicyPath, getCorrectPolicyDataObject()); + if (successMap.containsKey("success")) { + Path finalPolicyPath = getFinalPolicyPath(); + policyAdapter.setFinalPolicyPath(finalPolicyPath.toString()); + } + return successMap; + } + + //This is the method for preparing the policy for saving. We have broken it out + //separately because the fully configured policy is used for multiple things + @Override + public boolean prepareToSave() throws Exception{ + + if(isPreparedToSave()){ + //we have already done this + return true; + } + + int version = 0; + String policyID = policyAdapter.getPolicyID(); + + if (policyAdapter.isEditPolicy()) { + version = policyAdapter.getHighestVersion() + 1; + } else { + version = 1; + } + + // Create the Instance for pojo, PolicyType object is used in marshalling. + if (policyAdapter.getPolicyType().equals("Decision")) { + PolicyType policyConfig = new PolicyType(); + + policyConfig.setVersion(Integer.toString(version)); + policyConfig.setPolicyId(policyID); + policyConfig.setTarget(new TargetType()); + policyAdapter.setData(policyConfig); + } + + if (policyAdapter.getData() != null) { + + // Save off everything + // making ready all the required elements to generate the action policy xml. + // Get the uniqueness for policy name. + Path newFile = getNextFilename(Paths.get(policyAdapter.getParentPath().toString()), policyAdapter.getPolicyType(), policyAdapter.getPolicyName(), version); + if (newFile == null) { + //TODO:EELF Cleanup - Remove logger + //logger.error("File already exists, cannot create the policy."); + PolicyLogger.error("File already exists, cannot create the policy."); + setPolicyExists(true); + return false; + } + policyName = newFile.getFileName().toString(); + + // Make sure the filename ends with an extension + if (policyName.endsWith(".xml") == false) { + policyName = policyName + ".xml"; + } + + PolicyType decisionPolicy = (PolicyType) policyAdapter.getData(); + + decisionPolicy.setDescription(policyAdapter.getPolicyDescription()); + + decisionPolicy.setRuleCombiningAlgId(policyAdapter.getRuleCombiningAlgId()); + AllOfType allOfOne = new AllOfType(); + final Path gitPath = Paths.get(policyAdapter.getUserGitPath().toString()); + String policyDir = policyAdapter.getParentPath().toString(); + int startIndex = policyDir.indexOf(gitPath.toString()) + gitPath.toString().length() + 1; + policyDir = policyDir.substring(startIndex, policyDir.length()); + logger.info("print the main domain value "+policyDir); + String path = policyDir.replace('\\', '.'); + if(path.contains("/")){ + path = policyDir.replace('/', '.'); + logger.info("print the path:" +path); + } + String fileName = FilenameUtils.removeExtension(policyName); + fileName = path + "." + fileName + ".xml"; + String name = fileName.substring(fileName.lastIndexOf("\\") + 1, fileName.length()); + if ((name == null) || (name.equals(""))) { + name = fileName.substring(fileName.lastIndexOf("/") + 1, fileName.length()); + } + allOfOne.getMatch().add(createMatch("PolicyName", name)); + + AllOfType allOf = new AllOfType(); + + // Match for Ecomp + allOf.getMatch().add(createMatch("ECOMPName", (policyAdapter.getEcompName()))); + + Map dynamicFieldComponentAttributes = policyAdapter.getDynamicFieldConfigAttributes(); + if(policyAdapter.getProviderComboBox()!=null && policyAdapter.getProviderComboBox().equals(AAFProvider)){ + dynamicFieldComponentAttributes = new HashMap(); + } + + // If there is any dynamic field attributes create the matches here + for (String keyField : dynamicFieldComponentAttributes.keySet()) { + String key = keyField; + String value = dynamicFieldComponentAttributes.get(key); + MatchType dynamicMatch = createDynamicMatch(key, value); + allOf.getMatch().add(dynamicMatch); + } + + AnyOfType anyOf = new AnyOfType(); + anyOf.getAllOf().add(allOfOne); + anyOf.getAllOf().add(allOf); + + TargetType target = new TargetType(); + target.getAnyOf().add(anyOf); + decisionPolicy.setTarget(target); + + Map dynamicFieldDecisionSettings = policyAdapter.getDynamicSettingsMap(); + + //dynamicVariableList = policyAdapter.getDynamicVariableList(); + if(policyAdapter.getProviderComboBox()!=null && policyAdapter.getProviderComboBox().equals(AAFProvider)){ + dynamicFieldDecisionSettings = new HashMap(); + } + + // settings are dynamic so check how many rows are added and add all + for (String keyField : dynamicFieldDecisionSettings.keySet()) { + String key = keyField; + String value = dynamicFieldDecisionSettings.get(key); + //String dataType = (String) dynamicVariableList.get(counter); + String dataType = getDataType(key); + VariableDefinitionType dynamicVariable = createDynamicVariable(key, value, dataType); + decisionPolicy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().add(dynamicVariable); + } + + createRule(decisionPolicy, true); + createRule(decisionPolicy, false); + } + + setPreparedToSave(true); + return true; + } + + private DecisionSettings findDecisionSettingsBySettingId(String settingId) { + DecisionSettings decisionSetting = null; + + EntityManager em = policyAdapter.getEntityManagerFactory().createEntityManager(); + Query getDecisionSettings = em.createNamedQuery("DecisionSettings.findAll"); + List decisionSettingsList = getDecisionSettings.getResultList(); + + for (Object id : decisionSettingsList) { + decisionSetting = (DecisionSettings) id; + if (decisionSetting.getXacmlId().equals(settingId)) { + break; + } + } + return decisionSetting; + } + + private void createRule(PolicyType decisionPolicy, boolean permitRule) { + RuleType rule = new RuleType(); + + rule.setRuleId(policyAdapter.getRuleID()); + + if (permitRule) { + rule.setEffect(EffectType.PERMIT); + } else { + rule.setEffect(EffectType.DENY); + } + rule.setTarget(new TargetType()); + + // Create Target in Rule + AllOfType allOfInRule = new AllOfType(); + + // Creating match for ACCESS in rule target + MatchType accessMatch = new MatchType(); + AttributeValueType accessAttributeValue = new AttributeValueType(); + accessAttributeValue.setDataType(STRING_DATATYPE); + accessAttributeValue.getContent().add("DECIDE"); + accessMatch.setAttributeValue(accessAttributeValue); + AttributeDesignatorType accessAttributeDesignator = new AttributeDesignatorType(); + URI accessURI = null; + try { + accessURI = new URI(ACTION_ID); + } catch (URISyntaxException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e.getStackTrace()); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "DecisionPolicy", "Exception creating ACCESS URI"); + } + accessAttributeDesignator.setCategory(CATEGORY_ACTION); + accessAttributeDesignator.setDataType(STRING_DATATYPE); + accessAttributeDesignator.setAttributeId(new IdentifierImpl(accessURI).stringValue()); + accessMatch.setAttributeDesignator(accessAttributeDesignator); + accessMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE); + + dynamicLabelRuleAlgorithms = policyAdapter.getDynamicRuleAlgorithmLabels(); + dynamicFieldComboRuleAlgorithms = policyAdapter.getDynamicRuleAlgorithmCombo(); + dynamicFieldOneRuleAlgorithms = policyAdapter.getDynamicRuleAlgorithmField1(); + dynamicFieldTwoRuleAlgorithms = policyAdapter.getDynamicRuleAlgorithmField2(); + dropDownMap = createDropDownMap(); + + if(policyAdapter.getProviderComboBox()!=null && policyAdapter.getProviderComboBox().equals(AAFProvider)){ + // Values for AAF Provider are here for XML Creation. + ConditionType condition = new ConditionType(); + ApplyType decisionApply = new ApplyType(); + String selectedFunction = "boolean-equal"; + + AttributeValueType value1 = new AttributeValueType(); + value1.setDataType(BOOLEAN_DATATYPE); + value1.getContent().add("true"); + + AttributeDesignatorType value2 = new AttributeDesignatorType(); + value2.setAttributeId(AAFEngine.AAF_RESULT); + value2.setCategory(CATEGORY_RESOURCE); + value2.setDataType(BOOLEAN_DATATYPE); + value2.setMustBePresent(false); + + ApplyType innerDecisionApply = new ApplyType(); + innerDecisionApply.setFunctionId(FUNCTION_BOOLEAN_ONE_AND_ONLY); + innerDecisionApply.getExpression().add(new ObjectFactory().createAttributeDesignator(value2)); + + decisionApply.setFunctionId(dropDownMap.get(selectedFunction)); + decisionApply.getExpression().add(new ObjectFactory().createAttributeValue(value1)); + decisionApply.getExpression().add(new ObjectFactory().createApply(innerDecisionApply)); + condition.setExpression(new ObjectFactory().createApply(decisionApply)); + if (!permitRule) { + ApplyType notOuterApply = new ApplyType(); + notOuterApply.setFunctionId(FUNCTION_NOT); + notOuterApply.getExpression().add(condition.getExpression()); + condition.setExpression(new ObjectFactory().createApply(notOuterApply)); + } + rule.setCondition(condition); + allOfInRule.getMatch().add(accessMatch); + + AnyOfType anyOfInRule = new AnyOfType(); + anyOfInRule.getAllOf().add(allOfInRule); + + TargetType targetInRule = new TargetType(); + targetInRule.getAnyOf().add(anyOfInRule); + + rule.setTarget(targetInRule); + if(!permitRule){ + AdviceExpressionsType adviceExpressions = new AdviceExpressionsType(); + AdviceExpressionType adviceExpression = new AdviceExpressionType(); + adviceExpression.setAdviceId(AAFProvider); + adviceExpression.setAppliesTo(EffectType.DENY); + AttributeAssignmentExpressionType assignment = new AttributeAssignmentExpressionType(); + assignment.setAttributeId("aaf.response"); + assignment.setCategory(CATEGORY_RESOURCE); + AttributeDesignatorType value = new AttributeDesignatorType(); + value.setAttributeId(AAFEngine.AAF_RESPONSE); + value.setCategory(CATEGORY_RESOURCE); + value.setDataType(STRING_DATATYPE); + value.setMustBePresent(false); + assignment.setExpression(new ObjectFactory().createAttributeDesignator(value)); + adviceExpression.getAttributeAssignmentExpression().add(assignment); + adviceExpressions.getAdviceExpression().add(adviceExpression); + rule.setAdviceExpressions(adviceExpressions); + } + decisionPolicy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().add(rule); + policyAdapter.setPolicyData(decisionPolicy); + + }else if (dynamicLabelRuleAlgorithms != null && dynamicLabelRuleAlgorithms.size() > 0) { + boolean isCompound = false; + ConditionType condition = new ConditionType(); + int index = dynamicFieldOneRuleAlgorithms.size() - 1; + + for (String labelAttr : dynamicLabelRuleAlgorithms) { + // if the rule algorithm as a label means it is a compound + if (dynamicFieldOneRuleAlgorithms.get(index).toString().equals(labelAttr)) { + ApplyType decisionApply = new ApplyType(); + + String selectedFunction = (String) dynamicFieldComboRuleAlgorithms.get(index).toString(); + String value1 = (String) dynamicFieldOneRuleAlgorithms.get(index).toString(); + String value2 = dynamicFieldTwoRuleAlgorithms.get(index).toString(); + decisionApply.setFunctionId(dropDownMap.get(selectedFunction)); + decisionApply.getExpression().add(new ObjectFactory().createApply(getInnerDecisionApply(value1))); + decisionApply.getExpression().add(new ObjectFactory().createApply(getInnerDecisionApply(value2))); + condition.setExpression(new ObjectFactory().createApply(decisionApply)); + isCompound = true; + } + + // if rule algorithm not a compound + if (!isCompound) { + condition.setExpression(new ObjectFactory().createApply(getInnerDecisionApply(dynamicLabelRuleAlgorithms.get(index).toString()))); + } + } + if (!permitRule) { + ApplyType notOuterApply = new ApplyType(); + notOuterApply.setFunctionId(FUNCTION_NOT); + notOuterApply.getExpression().add(condition.getExpression()); + condition.setExpression(new ObjectFactory().createApply(notOuterApply)); + } + rule.setCondition(condition); + allOfInRule.getMatch().add(accessMatch); + + AnyOfType anyOfInRule = new AnyOfType(); + anyOfInRule.getAllOf().add(allOfInRule); + + TargetType targetInRule = new TargetType(); + targetInRule.getAnyOf().add(anyOfInRule); + + rule.setTarget(targetInRule); + + decisionPolicy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().add(rule); + policyAdapter.setPolicyData(decisionPolicy); + + } else { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Unsupported data object."+ policyAdapter.getData().getClass().getCanonicalName()); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + "Unsupported data object."+ policyAdapter.getData().getClass().getCanonicalName()); + } + + } + + // if compound setting the inner apply here + protected ApplyType getInnerDecisionApply(String value1Label) { + ApplyType decisionApply = new ApplyType(); + int index = 0; + // check the index for the label. + for (String labelAttr : dynamicLabelRuleAlgorithms) { + if (labelAttr.equals(value1Label)) { + String value1 = (String) dynamicFieldOneRuleAlgorithms.get(index).toString(); + populateDataTypeList(value1); + + // check if the row contains label again + for (String labelValue : dynamicLabelRuleAlgorithms) { + if (labelValue.equals(value1)) { + return getCompoundDecisionApply(index); + } + } + + // Getting the values from the form. + String functionKey = (String) dynamicFieldComboRuleAlgorithms.get(index).toString(); + String value2 = dynamicFieldTwoRuleAlgorithms.get(index).toString(); + decisionApply.setFunctionId(dropDownMap.get(functionKey)); + // if two text field are rule attributes. + if ((value1.contains(RULE_VARIABLE)) && (value2.contains(RULE_VARIABLE))) { + ApplyType innerDecisionApply1 = new ApplyType(); + ApplyType innerDecisionApply2 = new ApplyType(); + AttributeDesignatorType attributeDesignator1 = new AttributeDesignatorType(); + AttributeDesignatorType attributeDesignator2 = new AttributeDesignatorType(); + //If selected function is Integer function set integer functionID + if(functionKey.toLowerCase().contains("integer")){ + innerDecisionApply1.setFunctionId(FUNTION_INTEGER_ONE_AND_ONLY ); + innerDecisionApply2.setFunctionId(FUNTION_INTEGER_ONE_AND_ONLY); + attributeDesignator1.setDataType(INTEGER_DATATYPE); + attributeDesignator2.setDataType(INTEGER_DATATYPE); + } else{ + //If selected function is not a Integer function set String functionID + innerDecisionApply1.setFunctionId(FUNCTION_STRING_ONE_AND_ONLY); + innerDecisionApply2.setFunctionId(FUNCTION_STRING_ONE_AND_ONLY); + attributeDesignator1.setDataType(STRING_DATATYPE); + attributeDesignator2.setDataType(STRING_DATATYPE); + } + attributeDesignator1.setCategory(CATEGORY_RESOURCE); + attributeDesignator2.setCategory(CATEGORY_RESOURCE); + //Here set actual field values + attributeDesignator1.setAttributeId(value1. contains("resource:")?value1.substring( 9):value1.substring(8)); + attributeDesignator2.setAttributeId(value1. contains("resource:")?value1.substring( 9):value1.substring(8)); + innerDecisionApply1.getExpression().add(new ObjectFactory().createAttributeDesignator( attributeDesignator1)); + innerDecisionApply2.getExpression().add(new ObjectFactory().createAttributeDesignator( attributeDesignator2)); + decisionApply.getExpression().add(new ObjectFactory().createApply(innerDecisionApply1)); + decisionApply.getExpression().add(new ObjectFactory().createApply(innerDecisionApply2)); + } else { + // if either of one text field is rule attribute. + if (!value1.startsWith("S_")) { + ApplyType innerDecisionApply = new ApplyType(); + AttributeDesignatorType attributeDesignator = new AttributeDesignatorType(); + AttributeValueType decisionConditionAttributeValue = new AttributeValueType(); + + if (functionKey.toLowerCase().contains("integer")) { + innerDecisionApply.setFunctionId(FUNTION_INTEGER_ONE_AND_ONLY); + decisionConditionAttributeValue.setDataType(INTEGER_DATATYPE); + attributeDesignator.setDataType(INTEGER_DATATYPE); + } else { + innerDecisionApply.setFunctionId(FUNCTION_STRING_ONE_AND_ONLY); + decisionConditionAttributeValue.setDataType(STRING_DATATYPE); + attributeDesignator.setDataType(STRING_DATATYPE); + } + + String attributeId = null; + String attributeValue = null; + + // Find which textField has rule attribute and set it as + // attributeId and the other as attributeValue. + attributeId = value1; + attributeValue = value2; + + if (attributeId != null) { + attributeDesignator.setCategory(CATEGORY_RESOURCE); + attributeDesignator.setAttributeId(attributeId); + } + decisionConditionAttributeValue.getContent().add(attributeValue); + innerDecisionApply.getExpression().add(new ObjectFactory().createAttributeDesignator(attributeDesignator)); + decisionApply.getExpression().add(new ObjectFactory().createAttributeValue(decisionConditionAttributeValue)); + decisionApply.getExpression().add(new ObjectFactory().createApply(innerDecisionApply)); + } else { + value1 = value1.substring(2, value1.length()); + VariableReferenceType variableReferenceType = new VariableReferenceType(); + variableReferenceType.setVariableId(value1); + + String dataType = dataTypeList.get(index); + + AttributeValueType decisionConditionAttributeValue = new AttributeValueType(); + decisionConditionAttributeValue.setDataType(dataType); + decisionConditionAttributeValue.getContent().add(value2); + decisionApply.getExpression().add(new ObjectFactory().createVariableReference(variableReferenceType)); + decisionApply.getExpression().add(new ObjectFactory().createAttributeValue(decisionConditionAttributeValue)); + } + } + } + index++; + } + return decisionApply; + } + + // if the rule algorithm is multiple compound one setting the apply + protected ApplyType getCompoundDecisionApply(int index) { + ApplyType decisionApply = new ApplyType(); + String selectedFunction = dynamicFieldComboRuleAlgorithms.get(index).toString(); + String value1 = dynamicFieldOneRuleAlgorithms.get(index).toString(); + String value2 = dynamicFieldTwoRuleAlgorithms.get(index).toString(); + decisionApply.setFunctionId(dropDownMap.get(selectedFunction)); + decisionApply.getExpression().add(new ObjectFactory().createApply(getInnerDecisionApply(value1))); + decisionApply.getExpression().add(new ObjectFactory().createApply(getInnerDecisionApply(value2))); + return decisionApply; + } + + private VariableDefinitionType createDynamicVariable(String key, String value, String dataType) { + VariableDefinitionType dynamicVariable = new VariableDefinitionType(); + AttributeValueType dynamicAttributeValue = new AttributeValueType(); + + dynamicAttributeValue.setDataType(dataType); + dynamicAttributeValue.getContent().add(value); + + dynamicVariable.setVariableId(key); + dynamicVariable.setExpression(new ObjectFactory().createAttributeValue(dynamicAttributeValue)); + + return dynamicVariable; + + } + + private void populateDataTypeList(String value1) { + + ///String value1 = dynamicFieldDecisionOneRuleAlgorithms.get(index).getValue().toString(); + String dataType = null; + + if(value1.contains("S_")) { + value1 = value1.substring(2, value1.length()); + DecisionSettings decisionSettings = findDecisionSettingsBySettingId(value1); + if (decisionSettings != null && decisionSettings.getDatatypeBean().getShortName().equals("string")) { + dataType = STRING_DATATYPE; + } else if (decisionSettings != null && decisionSettings.getDatatypeBean().getShortName().equals("boolean")) { + dataType = BOOLEAN_DATATYPE; + } else { + dataType = INTEGER_DATATYPE; + } + } else { + dataType = "OTHER"; + } + + dataTypeList.add(dataType); + } + + private Map createDropDownMap(){ + JPAUtils jpaUtils = null; + try { + jpaUtils = JPAUtils.getJPAUtilsInstance(policyAdapter.getEntityManagerFactory()); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + Map> functionMap = jpaUtils.getFunctionDatatypeMap(); + Map dropDownMap = new HashMap(); + for (Datatype id : functionMap.keySet()) { + List functionDefinitions = (List) functionMap + .get(id); + for (FunctionDefinition functionDef : functionDefinitions) { + dropDownMap.put(functionDef.getShortname(),functionDef.getXacmlid()); + } + } + + return dropDownMap; + } + + private String getDataType(String key) { + + DecisionSettings decisionSettings = findDecisionSettingsBySettingId(key); + String dataType = null; + + if (decisionSettings != null && decisionSettings.getDatatypeBean().getShortName().equals("string")) { + dataType = STRING_DATATYPE; + } else if (decisionSettings != null && decisionSettings.getDatatypeBean().getShortName().equals("boolean")) { + dataType = BOOLEAN_DATATYPE; + } else { + dataType = INTEGER_DATATYPE; + } + + return dataType; + } + + @Override + public Object getCorrectPolicyDataObject() { + return policyAdapter.getData(); + } + + + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/FirewallConfigPolicy.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/FirewallConfigPolicy.java new file mode 100644 index 000000000..ad7525b85 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/FirewallConfigPolicy.java @@ -0,0 +1,1871 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.components; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.StringReader; +import java.net.URI; +import java.net.URISyntaxException; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.HashMap; +import java.util.Map; +import java.util.StringTokenizer; + +import javax.json.Json; +import javax.json.JsonArray; +import javax.json.JsonException; +import javax.json.JsonObject; +import javax.json.JsonReader; +import javax.json.JsonString; +import javax.json.JsonValue; + +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionsType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeAssignmentExpressionType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.EffectType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObjectFactory; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.RuleType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType; + +import org.apache.commons.io.FilenameUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openecomp.policy.pap.xacml.rest.adapters.PolicyRestAdapter; +import org.openecomp.policy.rest.XACMLRestProperties; +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.eelf.PolicyLogger; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; +import com.att.research.xacml.std.IdentifierImpl; +import com.att.research.xacml.util.XACMLProperties; +import com.fasterxml.jackson.databind.JsonNode; +import com.github.fge.jackson.JsonLoader; +import com.github.fge.jsonpatch.JsonPatch; +import com.github.fge.jsonpatch.diff.JsonDiff; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +public class FirewallConfigPolicy extends Policy { + /** + * Config Fields + */ + private static final Logger logger = FlexLogger.getLogger(FirewallConfigPolicy.class); + + public static final String JSON_CONFIG = "JSON"; + public static final String XML_CONFIG = "XML"; + public static final String PROPERTIES_CONFIG = "PROPERTIES"; + public static final String OTHER_CONFIG = "OTHER"; + + /* + * These are the parameters needed for DB access from the PAP + */ + private static String papDbDriver = null; + private static String papDbUrl = null; + private static String papDbUser = null; + private static String papDbPassword = null; + + public FirewallConfigPolicy() { + super(); + } + + public FirewallConfigPolicy(PolicyRestAdapter policyAdapter) { + this.policyAdapter = policyAdapter; + this.policyAdapter.setConfigType(policyAdapter.getConfigType()); + + } + + // Saving the Configurations file at server location for config policy. + protected void saveConfigurations(String policyName, String prevPolicyName, String jsonBody) { + final Path gitPath = Paths.get(policyAdapter.getUserGitPath().toString()); + String policyDir = policyAdapter.getParentPath().toString(); + int startIndex = policyDir.indexOf(gitPath.toString()) + gitPath.toString().length() + 1; + policyDir = policyDir.substring(startIndex, policyDir.length()); + logger.info("print the main domain value"+policyDir); + String path = policyDir.replace('\\', '.'); + if(path.contains("/")){ + path = policyDir.replace('/', '.'); + logger.info("print the path:" +path); + } + + try { + String configFileName = getConfigFile(policyName); + + File file; + if(CONFIG_HOME.contains("\\")) + { + file = new File(CONFIG_HOME + "\\" + path + "."+ configFileName); + } + else + { + file = new File(CONFIG_HOME + "/" + path + "."+ configFileName); + } + + // if file doesnt exists, then create it + if (!file.exists()) { + file.createNewFile(); + } + + //Getting the previous policy Config Json file to be used for updating the dictionary tables + if (policyAdapter.isEditPolicy()) { + + String prevConfigFileName = getConfigFile(prevPolicyName); + + File oldFile; + if(CONFIG_HOME.contains("\\")) + { + oldFile = new File(CONFIG_HOME + "\\" + path + "."+ prevConfigFileName); + } + else + { + oldFile = new File(CONFIG_HOME + "/" + path + "."+ prevConfigFileName); + } + + String filepath = oldFile.toString(); + + String prevJsonBody = readFile(filepath, StandardCharsets.UTF_8); + policyAdapter.setPrevJsonBody(prevJsonBody); + } + + + File configHomeDir = new File(CONFIG_HOME); + File[] listOfFiles = configHomeDir.listFiles(); + if (listOfFiles != null){ + for(File eachFile : listOfFiles){ + if(eachFile.isFile()){ + String fileNameWithoutExtension = FilenameUtils.removeExtension(eachFile.getName()); + String configFileNameWithoutExtension = FilenameUtils.removeExtension(configFileName); + if (fileNameWithoutExtension.equals(configFileNameWithoutExtension)){ + //delete the file + eachFile.delete(); + } + } + } + } + + FileWriter fw = new FileWriter(file.getAbsoluteFile()); + BufferedWriter bw = new BufferedWriter(fw); + bw.write(jsonBody); + bw.close(); + if (logger.isDebugEnabled()) { + logger.debug("Configuration is succesfully saved"); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + + //Utility to read json data from the existing file to a string + static String readFile(String path, Charset encoding) throws IOException { + + byte[] encoded = Files.readAllBytes(Paths.get(path)); + return new String(encoded, encoding); + + } + + // Here we are adding the extension for the configurations file based on the + // config type selection for saving. + private String getConfigFile(String filename) { + filename = FilenameUtils.removeExtension(filename); + if (filename.endsWith(".json")) { + filename = filename.substring(0, filename.length() - 4); + } + + filename=filename+".json"; + return filename; + } + + + // Validations for Config form + public boolean validateConfigForm() { + + // Validating mandatory Fields. + isValidForm = true; + return isValidForm; + + } + + @Override + public Map savePolicies() throws Exception { + + Map successMap = new HashMap(); + if(isPolicyExists()){ + successMap.put("EXISTS", "This Policy already exist on the PAP"); + return successMap; + } + + if(!isPreparedToSave()){ + prepareToSave(); + } + + // Until here we prepared the data and here calling the method to create xml. + Path newPolicyPath = null; + newPolicyPath = Paths.get(policyAdapter.getParentPath().toString(), policyName); + Boolean dbIsUpdated = false; + if (policyAdapter.getApiflag().equalsIgnoreCase("admin")){ + dbIsUpdated = true; + } else { + if (policyAdapter.isEditPolicy()) { + dbIsUpdated = updateFirewallDictionaryData(policyAdapter.getJsonBody(), policyAdapter.getPrevJsonBody()); + } else { + dbIsUpdated = insertFirewallDicionaryData(policyAdapter.getJsonBody()); + } + } + + if(dbIsUpdated) { + successMap = createPolicy(newPolicyPath,getCorrectPolicyDataObject() ); + } else { + //TODO:EELF Cleanup - Remove logger + //logger.error("Failed to Update the Database Dictionary Tables."); + PolicyLogger.error("Failed to Update the Database Dictionary Tables."); + + //remove the new json file + String jsonBody = policyAdapter.getPrevJsonBody(); + if (jsonBody!=null){ + saveConfigurations(policyName, "", jsonBody); + } else { + saveConfigurations(policyName, "", ""); + } + successMap.put("fwdberror", "DB UPDATE"); + } + + if (successMap.containsKey("success")) { + Path finalPolicyPath = getFinalPolicyPath(); + policyAdapter.setFinalPolicyPath(finalPolicyPath.toString()); + } + return successMap; + } + + //This is the method for preparing the policy for saving. We have broken it out + //separately because the fully configured policy is used for multiple things + @Override + public boolean prepareToSave() throws Exception{ + + if(isPreparedToSave()){ + //we have already done this + return true; + } + + int version = 0; + String policyID = policyAdapter.getPolicyID(); + + if (policyAdapter.isEditPolicy()) { + version = policyAdapter.getHighestVersion() + 1; + } else { + version = 1; + } + + // Create the Instance for pojo, PolicyType object is used in marshalling. + if (policyAdapter.getPolicyType().equals("Config")) { + PolicyType policyConfig = new PolicyType(); + + policyConfig.setVersion(Integer.toString(version)); + policyConfig.setPolicyId(policyID); + policyConfig.setTarget(new TargetType()); + policyAdapter.setData(policyConfig); + } + + if (policyAdapter.getData() != null) { + + // Save off everything + // making ready all the required elements to generate the action policy xml. + // Get the uniqueness for policy name. + String prevPolicyName = null; + if(policyAdapter.isEditPolicy()){ + prevPolicyName = "Config_FW_" + policyAdapter.getPolicyName() + "." + policyAdapter.getHighestVersion() + ".xml"; + } + + Path newFile = getNextFilename(Paths.get(policyAdapter.getParentPath().toString()), + (policyAdapter.getPolicyType() + "_FW"), policyAdapter.getPolicyName(), version); + + if (newFile == null) { + //TODO:EELF Cleanup - Remove logger + //logger.error("Policy already Exists, cannot create the policy."); + PolicyLogger.error("Policy already Exists, cannot create the policy."); + setPolicyExists(true); + return false; + } + policyName = newFile.getFileName().toString(); + + String jsonBody = policyAdapter.getJsonBody(); + saveConfigurations(policyName, prevPolicyName, jsonBody); + + // Make sure the filename ends with an extension + if (policyName.endsWith(".xml") == false) { + policyName = policyName + ".xml"; + } + + PolicyType configPolicy = (PolicyType) policyAdapter.getData(); + + configPolicy.setDescription(policyAdapter.getPolicyDescription()); + + configPolicy.setRuleCombiningAlgId(policyAdapter.getRuleCombiningAlgId()); + + AllOfType allOfOne = new AllOfType(); + File policyFilePath = new File(policyAdapter.getParentPath().toString(), policyName); + String policyDir = policyFilePath.getParentFile().getName(); + String fileName = FilenameUtils.removeExtension(policyName); + fileName = policyDir + "." + fileName + ".xml"; + String name = fileName.substring(fileName.lastIndexOf("\\") + 1, fileName.length()); + if ((name == null) || (name.equals(""))) { + name = fileName.substring(fileName.lastIndexOf("/") + 1, fileName.length()); + } + allOfOne.getMatch().add(createMatch("PolicyName", name)); + AllOfType allOf = new AllOfType(); + + // Match for ConfigName + allOf.getMatch().add(createMatch("ConfigName", policyAdapter.getConfigName())); + // Match for riskType + allOf.getMatch().add( + createDynamicMatch("RiskType", policyAdapter.getRiskType())); + // Match for riskLevel + allOf.getMatch().add( + createDynamicMatch("RiskLevel", String.valueOf(policyAdapter.getRiskLevel()))); + // Match for riskguard + allOf.getMatch().add( + createDynamicMatch("guard", policyAdapter.getGuard())); + // Match for ttlDate + allOf.getMatch().add( + createDynamicMatch("TTLDate", policyAdapter.getTtlDate())); + AnyOfType anyOf = new AnyOfType(); + anyOf.getAllOf().add(allOfOne); + anyOf.getAllOf().add(allOf); + + TargetType target = new TargetType(); + ((TargetType) target).getAnyOf().add(anyOf); + + // Adding the target to the policy element + configPolicy.setTarget((TargetType) target); + + RuleType rule = new RuleType(); + rule.setRuleId(policyAdapter.getRuleID()); + + rule.setEffect(EffectType.PERMIT); + + // Create Target in Rule + AllOfType allOfInRule = new AllOfType(); + + // Creating match for ACCESS in rule target + MatchType accessMatch = new MatchType(); + AttributeValueType accessAttributeValue = new AttributeValueType(); + accessAttributeValue.setDataType(STRING_DATATYPE); + accessAttributeValue.getContent().add("ACCESS"); + accessMatch.setAttributeValue(accessAttributeValue); + AttributeDesignatorType accessAttributeDesignator = new AttributeDesignatorType(); + URI accessURI = null; + try { + accessURI = new URI(ACTION_ID); + } catch (URISyntaxException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e.getStackTrace()); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "FirewallConfigPolicy", "Exception creating ACCESS URI"); + } + accessAttributeDesignator.setCategory(CATEGORY_ACTION); + accessAttributeDesignator.setDataType(STRING_DATATYPE); + accessAttributeDesignator.setAttributeId(new IdentifierImpl(accessURI).stringValue()); + accessMatch.setAttributeDesignator(accessAttributeDesignator); + accessMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE); + + // Creating Config Match in rule Target + MatchType configMatch = new MatchType(); + AttributeValueType configAttributeValue = new AttributeValueType(); + configAttributeValue.setDataType(STRING_DATATYPE); + + configAttributeValue.getContent().add("Config"); + + configMatch.setAttributeValue(configAttributeValue); + AttributeDesignatorType configAttributeDesignator = new AttributeDesignatorType(); + URI configURI = null; + try { + configURI = new URI(RESOURCE_ID); + } catch (URISyntaxException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e.getStackTrace()); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "FirewallConfigPolicy", "Exception creating Config URI"); + } + + configAttributeDesignator.setCategory(CATEGORY_RESOURCE); + configAttributeDesignator.setDataType(STRING_DATATYPE); + configAttributeDesignator.setAttributeId(new IdentifierImpl(configURI).stringValue()); + configMatch.setAttributeDesignator(configAttributeDesignator); + configMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE); + + allOfInRule.getMatch().add(accessMatch); + allOfInRule.getMatch().add(configMatch); + + AnyOfType anyOfInRule = new AnyOfType(); + anyOfInRule.getAllOf().add(allOfInRule); + + TargetType targetInRule = new TargetType(); + targetInRule.getAnyOf().add(anyOfInRule); + + rule.setTarget(targetInRule); + rule.setAdviceExpressions(getAdviceExpressions(version, policyName)); + + configPolicy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().add(rule); + policyAdapter.setPolicyData(configPolicy); + + } else { + //TODO:EELF Cleanup - Remove logger + //logger.error("Unsupported data object." + policyAdapter.getData().getClass().getCanonicalName()); + PolicyLogger.error("Unsupported data object." + policyAdapter.getData().getClass().getCanonicalName()); + } + setPreparedToSave(true); + return true; + } + + // Data required for Advice part is setting here. + private AdviceExpressionsType getAdviceExpressions(int version, String fileName) { + + //Firewall Config ID Assignment + AdviceExpressionsType advices = new AdviceExpressionsType(); + AdviceExpressionType advice = new AdviceExpressionType(); + advice.setAdviceId("firewallConfigID"); + advice.setAppliesTo(EffectType.PERMIT); + // For Configuration + AttributeAssignmentExpressionType assignment1 = new AttributeAssignmentExpressionType(); + assignment1.setAttributeId("type"); + assignment1.setCategory(CATEGORY_RESOURCE); + assignment1.setIssuer(""); + AttributeValueType configNameAttributeValue = new AttributeValueType(); + configNameAttributeValue.setDataType(STRING_DATATYPE); + configNameAttributeValue.getContent().add("Configuration"); + assignment1.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue)); + advice.getAttributeAssignmentExpression().add(assignment1); + + // For Config file Url if configurations are provided. + //URL ID Assignment + final Path gitPath = Paths.get(policyAdapter.getUserGitPath().toString()); + AttributeAssignmentExpressionType assignment2 = new AttributeAssignmentExpressionType(); + assignment2.setAttributeId("URLID"); + assignment2.setCategory(CATEGORY_RESOURCE); + assignment2.setIssuer(""); + AttributeValueType AttributeValue = new AttributeValueType(); + AttributeValue.setDataType(URI_DATATYPE); + String policyDir1 = policyAdapter.getParentPath().toString(); + int startIndex1 = policyDir1.indexOf(gitPath.toString()) + gitPath.toString().length() + 1; + policyDir1 = policyDir1.substring(startIndex1, policyDir1.length()); + logger.info("print the main domain value"+policyDir1); + String path = policyDir1.replace('\\', '.'); + if(path.contains("/")){ + path = policyDir1.replace('/', '.'); + logger.info("print the path:" +path); + } + String content = CONFIG_URL + "/Config/" + path + "." + getConfigFile(policyName); + + AttributeValue.getContent().add(content); + assignment2.setExpression(new ObjectFactory().createAttributeValue(AttributeValue)); + advice.getAttributeAssignmentExpression().add(assignment2); + + //Policy Name Assignment + AttributeAssignmentExpressionType assignment3 = new AttributeAssignmentExpressionType(); + assignment3.setAttributeId("PolicyName"); + assignment3.setCategory(CATEGORY_RESOURCE); + assignment3.setIssuer(""); + AttributeValueType attributeValue3 = new AttributeValueType(); + attributeValue3.setDataType(STRING_DATATYPE); + String policyDir = policyAdapter.getParentPath().toString(); + int startIndex = policyDir.indexOf(gitPath.toString()) + gitPath.toString().length() + 1; + policyDir = policyDir.substring(startIndex, policyDir.length()); + StringTokenizer tokenizer = null; + StringBuffer buffer = new StringBuffer(); + if (policyDir.contains("\\")) { + tokenizer = new StringTokenizer(policyDir, "\\"); + } else { + tokenizer = new StringTokenizer(policyDir, "/"); + } + if (tokenizer != null) { + while (tokenizer.hasMoreElements()) { + String value = tokenizer.nextToken(); + buffer.append(value); + buffer.append("."); + } + } + fileName = FilenameUtils.removeExtension(fileName); + fileName = buffer.toString() + fileName + ".xml"; + System.out.println(fileName); + String name = fileName.substring(fileName.lastIndexOf("\\") + 1, fileName.length()); + if ((name == null) || (name.equals(""))) { + name = fileName.substring(fileName.lastIndexOf("/") + 1, fileName.length()); + } + System.out.println(name); + attributeValue3.getContent().add(name); + assignment3.setExpression(new ObjectFactory().createAttributeValue(attributeValue3)); + advice.getAttributeAssignmentExpression().add(assignment3); + + //Version Number Assignment + AttributeAssignmentExpressionType assignment4 = new AttributeAssignmentExpressionType(); + assignment4.setAttributeId("VersionNumber"); + assignment4.setCategory(CATEGORY_RESOURCE); + assignment4.setIssuer(""); + AttributeValueType configNameAttributeValue4 = new AttributeValueType(); + configNameAttributeValue4.setDataType(STRING_DATATYPE); + configNameAttributeValue4.getContent().add(Integer.toString(version)); + assignment4.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue4)); + advice.getAttributeAssignmentExpression().add(assignment4); + + //Ecomp Name Assignment + AttributeAssignmentExpressionType assignment5 = new AttributeAssignmentExpressionType(); + assignment5.setAttributeId("matching:" + this.ECOMPID); + assignment5.setCategory(CATEGORY_RESOURCE); + assignment5.setIssuer(""); + AttributeValueType configNameAttributeValue5 = new AttributeValueType(); + configNameAttributeValue5.setDataType(STRING_DATATYPE); + assignment5.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue5)); + advice.getAttributeAssignmentExpression().add(assignment5); + + //Config Name Assignment + AttributeAssignmentExpressionType assignment6 = new AttributeAssignmentExpressionType(); + assignment6.setAttributeId("matching:" + this.CONFIGID); + assignment6.setCategory(CATEGORY_RESOURCE); + assignment6.setIssuer(""); + AttributeValueType configNameAttributeValue6 = new AttributeValueType(); + configNameAttributeValue6.setDataType(STRING_DATATYPE); + configNameAttributeValue6.getContent().add(policyAdapter.getConfigName()); + assignment6.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue6)); + advice.getAttributeAssignmentExpression().add(assignment6); + + //Risk Attributes + AttributeAssignmentExpressionType assignment7 = new AttributeAssignmentExpressionType(); + assignment7.setAttributeId("RiskType"); + assignment7.setCategory(CATEGORY_RESOURCE); + assignment7.setIssuer(""); + + AttributeValueType configNameAttributeValue7 = new AttributeValueType(); + configNameAttributeValue7.setDataType(STRING_DATATYPE); + configNameAttributeValue7.getContent().add(policyAdapter.getRiskType()); + assignment7.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue7)); + + advice.getAttributeAssignmentExpression().add(assignment7); + + AttributeAssignmentExpressionType assignment8 = new AttributeAssignmentExpressionType(); + assignment8.setAttributeId("RiskLevel"); + assignment8.setCategory(CATEGORY_RESOURCE); + assignment8.setIssuer(""); + + AttributeValueType configNameAttributeValue8 = new AttributeValueType(); + configNameAttributeValue8.setDataType(STRING_DATATYPE); + configNameAttributeValue8.getContent().add(policyAdapter.getRiskLevel()); + assignment8.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue8)); + + advice.getAttributeAssignmentExpression().add(assignment8); + + AttributeAssignmentExpressionType assignment9 = new AttributeAssignmentExpressionType(); + assignment9.setAttributeId("guard"); + assignment9.setCategory(CATEGORY_RESOURCE); + assignment9.setIssuer(""); + + AttributeValueType configNameAttributeValue9 = new AttributeValueType(); + configNameAttributeValue9.setDataType(STRING_DATATYPE); + configNameAttributeValue9.getContent().add(policyAdapter.getGuard()); + assignment9.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue9)); + + advice.getAttributeAssignmentExpression().add(assignment9); + + AttributeAssignmentExpressionType assignment10 = new AttributeAssignmentExpressionType(); + assignment10.setAttributeId("TTLDate"); + assignment10.setCategory(CATEGORY_RESOURCE); + assignment10.setIssuer(""); + + AttributeValueType configNameAttributeValue10 = new AttributeValueType(); + configNameAttributeValue10.setDataType(STRING_DATATYPE); + configNameAttributeValue10.getContent().add(policyAdapter.getTtlDate()); + assignment10.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue10)); + + advice.getAttributeAssignmentExpression().add(assignment10); + + int index = 0; + + advices.getAdviceExpression().add(advice); + return advices; + } + + + private Boolean insertFirewallDicionaryData (String jsonBody) throws SQLException { + + + JsonObject json = null; + if (jsonBody != null) { + + //Read jsonBody to JsonObject + json = stringToJson(jsonBody); + + JsonArray firewallRules = null; + JsonArray serviceGroup = null; + JsonArray addressGroup = null; + String securityZone=null; + + Connection con = null; + Statement st = null; + ResultSet rs = null; + + /* + * Retrieve the property values for db access from the xacml.pap.properties + */ + papDbDriver = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_DB_DRIVER); + papDbUrl = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_DB_URL); + papDbUser = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_DB_USER); + papDbPassword = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_DB_PASSWORD); + + //insert data into tables + try { + //Get DB Connection + Class.forName(papDbDriver); + con = DriverManager.getConnection(papDbUrl,papDbUser,papDbPassword); + st = con.createStatement(); + + firewallRules = json.getJsonArray("firewallRuleList"); + serviceGroup = json.getJsonArray("serviceGroups"); + addressGroup = json.getJsonArray("addressGroups"); + securityZone=json.getString("primaryParentZoneId").toString(); + + logger.info("Parent child: securityZone from JSON: "+securityZone); + String insertQuery = null; + + //Inserting childPolicy and its parent to the FWChildToParent DB table + if(securityZone!=null){ + //Its a child Policy. + //Retrieve the parent name from the securityZone Id + String retrieveParentQuery= "select parent from fwparent where securityZone='"; + + retrieveParentQuery=retrieveParentQuery+securityZone+"';"; + logger.info("Parent child: Query to retrieve parent "+retrieveParentQuery); + rs = st.executeQuery(retrieveParentQuery); + + String parent=null; + if(rs.next()){ + parent = rs.getString("parent"); + } + rs.close(); + + + String insertQueryChildTable="INSERT INTO FWChildToParent(child, parent) VALUES ('"; + insertQueryChildTable=insertQueryChildTable+policyAdapter.getPolicyName()+"','"+parent+"');"; + logger.info("Parent child: Insert child and parent to DB: "+insertQueryChildTable); + st.executeUpdate(insertQueryChildTable); + + } + + /* + * Inserting firewallRuleList data into the Terms, SecurityZone, and Action tables + */ + if (firewallRules != null) { + + int termID = 0; + int zoneID = 0; + int actionID = 0; + + rs = st.executeQuery("SELECT MAX(ID) AS ID FROM TERM;"); + if(rs.next()){ + termID = rs.getInt("ID"); + } + rs.close(); + + rs = st.executeQuery("SELECT MAX(ID) AS ID FROM ZONE;"); + if(rs.next()){ + zoneID = rs.getInt("ID"); + } + rs.close(); + + rs = st.executeQuery("SELECT MAX(ID) AS ID FROM ACTIONLIST;"); + if(rs.next()){ + actionID = rs.getInt("ID"); + } + rs.close(); + + int i = 0; + for(JsonValue jsonValue : firewallRules) { + + //increment ID Primary Keys + termID = termID + 1; + zoneID = zoneID + 1; + actionID = actionID + 1; + + /* + * Populate ArrayLists with values from the JSON + */ + //create the JSON object from the JSON Array for each iteration through the for loop + JsonObject ruleListobj = firewallRules.getJsonObject(i); + + //get values from JSON fields of firewallRulesList Array + String ruleName = ruleListobj.get("ruleName").toString(); + String action = ruleListobj.get("action").toString(); + String description = ruleListobj.get("description").toString(); + + rs = st.executeQuery("SELECT * FROM TERM WHERE TERMNAME = "+ ruleName + ";"); + + if (rs.next()) { + st.executeUpdate("DELETE FROM TERM WHERE TERMNAME = "+ ruleName + ";"); + } + rs.close(); + + //getting fromZone Array field from the firewallRulesList + JsonArray fromZoneArray = ruleListobj.getJsonArray("fromZones"); + String fromZoneString = null; + + int fromZoneIndex = 0; + for (JsonValue fromZoneJsonValue : fromZoneArray) { + String value = fromZoneArray.get(fromZoneIndex).toString(); + value = value.replace("\"", ""); + + if (fromZoneString != null) { + fromZoneString = fromZoneString.concat(",").concat(value); + + } else { + fromZoneString = value; + } + + fromZoneIndex++; + + } + String fromZoneInsert = "'"+fromZoneString+"'"; + + //getting toZone Array field from the firewallRulesList + JsonArray toZoneArray = ruleListobj.getJsonArray("toZones"); + String toZoneString = null; + + int toZoneIndex = 0; + for (JsonValue toZoneJsonValue : toZoneArray) { + String value = toZoneArray.get(toZoneIndex).toString(); + value = value.replace("\"", ""); + + if (toZoneString != null) { + toZoneString = toZoneString.concat(",").concat(value); + + } else { + toZoneString = value; + } + + toZoneIndex++; + + } + String toZoneInsert = "'"+toZoneString+"'"; + + //getting sourceList Array fields from the firewallRulesList + JsonArray srcListArray = ruleListobj.getJsonArray("sourceList"); + String srcListString = null; + + int srcListIndex = 0; + for (JsonValue srcListJsonValue : srcListArray) { + JsonObject srcListObj = srcListArray.getJsonObject(srcListIndex); + String type = srcListObj.get("type").toString().replace("\"", ""); + + String value = null; + if(type.equals("REFERENCE")||type.equals("GROUP")){ + value = srcListObj.get("name").toString(); + } else if (type.equalsIgnoreCase("ANY")){ + value = null; + } else { + value = srcListObj.get("value").toString(); + } + + if (value!=null){ + value = value.replace("\"", ""); + } + + if (srcListString != null) { + srcListString = srcListString.concat(",").concat(value); + + } else { + srcListString = value; + } + + srcListIndex++; + + } + String srcListInsert = "'"+srcListString+"'"; + + //getting destinationList Array fields from the firewallRulesList + JsonArray destListArray = ruleListobj.getJsonArray("destinationList"); + String destListString = null; + + int destListIndex = 0; + for (JsonValue destListJsonValue : destListArray) { + JsonObject destListObj = destListArray.getJsonObject(destListIndex); + String type = destListObj.get("type").toString().replace("\"", ""); + + String value = null; + if(type.equals("REFERENCE")||type.equals("GROUP")){ + value = destListObj.get("name").toString(); + } else if (type.equalsIgnoreCase("ANY")){ + value = null; + } else { + value = destListObj.get("value").toString(); + } + + if (value!=null){ + value = value.replace("\"", ""); + } + + if (destListString != null) { + destListString = destListString.concat(",").concat(value); + } else { + destListString = value; + } + + destListIndex++; + } + String destListInsert = "'"+destListString+"'"; + + //getting destServices Array fields from the firewallRulesList + JsonArray destServicesArray = ruleListobj.getJsonArray("destServices"); + String destPortListString = null; + + int destPortListIndex = 0; + for (JsonValue destListJsonValue : destServicesArray) { + JsonObject destServicesObj = destServicesArray.getJsonObject(destPortListIndex); + String type = destServicesObj.get("type").toString().replace("\"", ""); + + String value = null; + if(type.equals("REFERENCE")||type.equals("GROUP")){ + value = destServicesObj.get("name").toString(); + } else if (type.equalsIgnoreCase("ANY")){ + value = null; + } else { + value = destServicesObj.get("value").toString(); + } + + if (value!=null){ + value = value.replace("\"", ""); + } + + if (destPortListString != null) { + destPortListString = destPortListString.concat(",").concat(value); + } else { + destPortListString = value; + } + + destPortListIndex++; + } + String destPortListInsert = "'"+destPortListString+"'"; + + /* + * Create Queries to INSERT data into database tables and execute + */ + String termSql = "INSERT INTO Term (ID, TERMNAME, SRCIPLIST, DESTIPLIST, PROTOCOLLIST, PORTLIST, SRCPORTLIST," + + " DESTPORTLIST, ACTION, DESCRIPTION, FROMZONE, TOZONE, CREATED_BY, MODIFIED_DATE) VALUES ("+termID+"," + +ruleName+","+srcListInsert+","+destListInsert+","+ "null"+","+"null"+","+"null"+","+destPortListInsert+"," + +action+","+description+","+fromZoneInsert+","+toZoneInsert+",'API',"+ "null"+ "); "; + termSql = termSql.replace('"', '\''); + st.addBatch(termSql); + + String actionSql = "INSERT INTO ACTIONLIST (ID, ACTIONNAME, DESCRIPTION) VALUES ("+actionID+","+action+","+action+"); "; + actionSql = actionSql.replace('"', '\''); + st.addBatch(actionSql); + + st.executeBatch(); + + i++; + } + + } + + /* + * Inserting serviceGroups data into the ServiceGroup, ServiceList, ProtocolList, and PortList tables + */ + if (serviceGroup != null) { + + int serviceGroupID = 0; + int serviceListID = 0; + int protocolID = 0; + int portID = 0; + + + rs = st.executeQuery("SELECT MAX(ID) AS ID FROM SERVICEGROUP;"); + if(rs.next()){ + serviceGroupID = rs.getInt("ID"); + } + rs.close(); + + rs = st.executeQuery("SELECT MAX(ID) AS ID FROM GROUPSERVICELIST;"); + if(rs.next()){ + serviceListID = rs.getInt("ID"); + } + rs.close(); + + rs = st.executeQuery("SELECT MAX(ID) AS ID FROM PROTOCOLLIST;"); + if(rs.next()){ + protocolID = rs.getInt("ID"); + } + rs.close(); + + rs = st.executeQuery("SELECT MAX(ID) AS ID FROM PORTLIST;"); + if(rs.next()){ + portID = rs.getInt("ID"); + } + rs.close(); + + int i = 0; + for(JsonValue jsonValue : serviceGroup) { + + /* + * Populate ArrayLists with values from the JSON + */ + //create the JSON object from the JSON Array for each iteration through the for loop + JsonObject svcGroupListobj = serviceGroup.getJsonObject(i); + + String serviceListName = svcGroupListobj.get("name").toString(); + + String description = null; + if (svcGroupListobj.containsKey("description")){ + description = svcGroupListobj.get("description").toString(); + } + + //getting members Array from the serviceGroup + JsonArray membersArray = svcGroupListobj.getJsonArray("members"); + + //String type = svcGroupListobj.get("type").toString(); + Boolean isServiceGroup = false; + if (membersArray!=null){ + String membersType = membersArray.getJsonObject(0).get("type").toString(); + if (membersType.contains("REFERENCE")) { + isServiceGroup = true; + } + } + + //Insert values into GROUPSERVICELIST table if name begins with Group + if (isServiceGroup) { + + //increment ID Primary Keys + serviceListID = serviceListID + 1; + + String name = null; + + int membersIndex = 0; + for (JsonValue membersValue : membersArray) { + JsonObject membersObj = membersArray.getJsonObject(membersIndex); + //String value = membersObj.get("name").toString(); + String type = membersObj.get("type").toString().replace("\"", ""); + + String value = null; + if(type.equals("REFERENCE")||type.equals("GROUP")||type.equals("SERVICE")){ + value = membersObj.get("name").toString(); + } else if (type.equalsIgnoreCase("ANY")){ + value = null; + } else { + value = membersObj.get("value").toString(); + } + + if(value != null){ + value = value.replace("\"", ""); + } + + if (name != null) { + name = name.concat(",").concat(value); + } else { + name = value; + } + + membersIndex++; + } + String nameInsert = "'"+name+"'"; + + insertQuery = "INSERT INTO GROUPSERVICELIST (ID, NAME, SERVICELIST) " + + "VALUES("+serviceListID+","+serviceListName+","+nameInsert+")"; + + //Replace double quote with single quote + insertQuery = insertQuery.replace('"', '\''); + + //Execute the queries to Insert data + st.executeUpdate(insertQuery); + + } else { //Insert JSON data serviceList table, protollist table, and portlist table + + //increment ID Primary Keys + protocolID = protocolID + 1; + portID = portID + 1; + serviceGroupID = serviceGroupID + 1; + + String type = svcGroupListobj.get("type").toString(); + String transportProtocol = svcGroupListobj.get("transportProtocol").toString(); + String ports = svcGroupListobj.get("ports").toString(); + + /* + * Create Queries to INSERT data into database table and execute + */ + String serviceSql = "INSERT INTO SERVICEGROUP (ID, NAME, DESCRIPTION, TYPE, TRANSPORTPROTOCOL, APPPROTOCOL, PORTS) " + + "VALUES("+serviceGroupID+","+serviceListName+","+description+","+type+"," + + transportProtocol+","+"null,"+ports+"); "; + serviceSql = serviceSql.replace('"', '\''); + st.addBatch(serviceSql); + + String protSql = "INSERT INTO PROTOCOLLIST (ID, PROTOCOLNAME, DESCRIPTION) VALUES("+protocolID+","+transportProtocol+","+transportProtocol+"); "; + protSql = protSql.replace('"', '\''); + st.addBatch(protSql); + + String portSql = "INSERT INTO PORTLIST (ID, PORTNAME, DESCRIPTION) VALUES("+portID+","+ports+","+ports+");"; + portSql = portSql.replace('"', '\''); + st.addBatch(portSql); + + st.executeBatch(); + + } + + + + i++; + } + } + + /* + * Inserting addressGroup data into the ADDRESSGROUP table + */ + if (addressGroup != null) { + int prefixID = 0; + int addressID = 0; + + rs = st.executeQuery("SELECT MAX(ID) AS ID FROM PREFIXLIST;"); + if(rs.next()){ + prefixID = rs.getInt("ID"); + } + rs.close(); + + rs = st.executeQuery("SELECT MAX(ID) AS ID FROM ADDRESSGROUP;"); + if(rs.next()){ + addressID = rs.getInt("ID"); + } + rs.close(); + + + int i = 0; + for(JsonValue jsonValue : addressGroup) { + + /* + * Populate ArrayLists with values from the JSON + */ + //create the JSON object from the JSON Array for each iteration through the for loop + JsonObject addressGroupObj = addressGroup.getJsonObject(i); + + //create JSON array for members + JsonArray membersArray = addressGroupObj.getJsonArray("members"); + String addressGroupName = addressGroupObj.get("name").toString(); + + String description = null; + if (addressGroupObj.containsKey("description")){ + description = addressGroupObj.get("description").toString(); + } + + String prefixIP = null; + String type = null; + + int membersIndex = 0; + for (JsonValue membersValue : membersArray) { + JsonObject membersObj = membersArray.getJsonObject(membersIndex); + //String value = membersObj.get("value").toString(); + type = membersObj.get("type").toString().replace("\"", ""); + + String value = null; + if(type.equals("REFERENCE")||type.equals("GROUP")||type.equals("SERVICE")){ + value = membersObj.get("name").toString(); + } else if (type.equalsIgnoreCase("ANY")){ + value = null; + } else { + value = membersObj.get("value").toString(); + } + + if(value != null){ + value = value.replace("\"", ""); + } + + if (prefixIP != null) { + prefixIP = prefixIP.concat(",").concat(value); + } else { + prefixIP = value; + } + + membersIndex++; + } + String prefixList = "'"+prefixIP+"'"; + + Boolean isAddressGroup = type.contains("REFERENCE"); + + if (isAddressGroup) { + //increment ID Primary Keys + addressID = addressID + 1; + + insertQuery = "INSERT INTO ADDRESSGROUP (ID, NAME, DESCRIPTION, PREFIXLIST) " + + "VALUES("+addressID+","+addressGroupName+","+description+","+prefixList+")"; + } else { + //increment ID Primary Key + prefixID = prefixID + 1; + + insertQuery = "INSERT INTO PREFIXLIST (ID, PL_NAME, PL_VALUE, DESCRIPTION) " + + "VALUES("+prefixID+","+addressGroupName+","+prefixList+","+description+")"; + + } + + + //Replace double quote with single quote + insertQuery = insertQuery.replace('"', '\''); + + //Execute the queries to Insert data + st.executeUpdate(insertQuery); + + i++; + } + + } + + /* + * Remove duplicate values from 'lookup' dictionary tables + */ + //ProtocolList Table + String protoDelete = "DELETE FROM protocollist USING protocollist, protocollist p1 " + + "WHERE protocollist.id > p1.id AND protocollist.protocolname = p1.protocolname;"; + st.addBatch(protoDelete); + + //PortList Table + String portListDelete = "DELETE FROM portlist USING portlist, portlist p1 " + + "WHERE portlist.id > p1.id AND portlist.portname = p1.portname; "; + st.addBatch(portListDelete); + + //PrefixList Table + String prefixListDelete = "DELETE FROM prefixlist USING prefixlist, prefixlist p1 " + + "WHERE prefixlist.id > p1.id AND prefixlist.pl_name = p1.pl_name AND " + + "prefixlist.pl_value = p1.pl_value AND prefixlist.description = p1.description; "; + st.addBatch(prefixListDelete); + + //GroupServiceList + String groupServiceDelete = "DELETE FROM groupservicelist USING groupservicelist, groupservicelist g1 " + + "WHERE groupservicelist.id > g1.id AND groupservicelist.name = g1.name AND " + + "groupservicelist.serviceList = g1.serviceList; "; + st.addBatch(groupServiceDelete); + + st.executeBatch(); + + } catch (ClassNotFoundException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(e.getMessage()); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "FirewallConfigPolicy", "Exception building Firewall queries "); + System.out.println(e.getMessage()); + return false; + + } catch (SQLException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(e.getMessage()); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "FirewallConfigPolicy", "Exception executing Firewall queries"); + System.out.println(e.getMessage()); + return false; + } catch (Exception e) { + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "FirewallConfigPolicy", "Exception getting Json values"); + System.out.println(e.getMessage()); + return false; + } finally { + try{ + if (con!=null) con.close(); + if (rs!=null) rs.close(); + if (st!=null) st.close(); + } catch (Exception ex){} + } + return true; + + } else { + return false; + } + + } + + + private Boolean updateFirewallDictionaryData(String jsonBody, String prevJsonBody) { + + JsonObject oldJson = null; + JsonObject newJson = null; + + if (jsonBody != null || prevJsonBody != null) { + + oldJson = stringToJson(prevJsonBody); + newJson = stringToJson(jsonBody); + + //if no changes to the json then return true + if (oldJson.equals(newJson)) { + return true; + } + + JsonArray firewallRules = null; + JsonArray serviceGroup = null; + JsonArray addressGroup = null; + + firewallRules = newJson.getJsonArray("firewallRuleList"); + serviceGroup = newJson.getJsonArray("serviceGroups"); + addressGroup = newJson.getJsonArray("addressGroups"); + + Connection con = null; + Statement st = null; + ResultSet rs = null; + + /* + * Retrieve the property values for db access from the xacml.pap.properties + */ + papDbDriver = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_DB_DRIVER); + papDbUrl = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_DB_URL); + papDbUser = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_DB_USER); + papDbPassword = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_DB_PASSWORD); + + //insert data into tables + try { + + //Get DB Connection + Class.forName(papDbDriver); + con = DriverManager.getConnection(papDbUrl,papDbUser,papDbPassword); + st = con.createStatement(); + + JsonNode jsonDiff = createPatch(jsonBody, prevJsonBody); + + int i = 0; + for (JsonNode node : jsonDiff) { + //String path = jsonDiff.get(i).asText(); + String jsonpatch = jsonDiff.get(i).toString(); + + JsonObject patchObj = stringToJson(jsonpatch); + + String path = patchObj.get("path").toString().replace('"', ' ').trim(); + + if (path.contains("firewallRuleList")) { + int termID = 0; + int zoneID = 0; + int actionID = 0; + + rs = st.executeQuery("SELECT MAX(ID) AS ID FROM TERM;"); + if(rs.next()){ + termID = rs.getInt("ID"); + } + rs.close(); + + rs = st.executeQuery("SELECT MAX(ID) AS ID FROM ZONE;"); + if(rs.next()){ + zoneID = rs.getInt("ID"); + } + rs.close(); + + rs = st.executeQuery("SELECT MAX(ID) AS ID FROM ACTIONLIST;"); + if(rs.next()){ + actionID = rs.getInt("ID"); + } + rs.close(); + + String insertQuery = null; + + /* + * Inserting firewallRuleList data into the Terms, SecurityZone, and Action tables + */ + int ri = 0; + for(JsonValue jsonValue : firewallRules) { + + //increment ID Primary Keys + termID = termID + 1; + zoneID = zoneID + 1; + actionID = actionID + 1; + + /* + * Populate ArrayLists with values from the JSON + */ + //create the JSON object from the JSON Array for each iteration through the for loop + JsonObject ruleListobj = firewallRules.getJsonObject(ri); + + //get values from JSON fields of firewallRulesList Array + String ruleName = ruleListobj.get("ruleName").toString().replace('"', '\''); + String action = ruleListobj.get("action").toString().replace('"', '\''); + String description = ruleListobj.get("description").toString().replace('"', '\''); + + rs = st.executeQuery("SELECT * FROM TERM WHERE TERMNAME = "+ ruleName + ";"); + + if (rs.next()) { + st.executeUpdate("DELETE FROM TERM WHERE TERMNAME = "+ ruleName + ";"); + } + rs.close(); + + //getting fromZone Array field from the firewallRulesList + JsonArray fromZoneArray = ruleListobj.getJsonArray("fromZones"); + String fromZoneString = null; + + int fromZoneIndex = 0; + for (JsonValue fromZoneJsonValue : fromZoneArray) { + String value = fromZoneArray.get(fromZoneIndex).toString(); + value = value.replace("\"", ""); + + if (fromZoneString != null) { + fromZoneString = fromZoneString.concat(",").concat(value); + + } else { + fromZoneString = value; + } + + fromZoneIndex++; + + } + String fromZoneInsert = "'"+fromZoneString+"'"; + + //getting toZone Array field from the firewallRulesList + JsonArray toZoneArray = ruleListobj.getJsonArray("toZones"); + String toZoneString = null; + + int toZoneIndex = 0; + for (JsonValue toZoneJsonValue : toZoneArray) { + String value = toZoneArray.get(toZoneIndex).toString(); + value = value.replace("\"", ""); + + if (toZoneString != null) { + toZoneString = toZoneString.concat(",").concat(value); + + } else { + toZoneString = value; + } + + toZoneIndex++; + + } + String toZoneInsert = "'"+toZoneString+"'"; + //getting sourceList Array fields from the firewallRulesList + JsonArray srcListArray = ruleListobj.getJsonArray("sourceList"); + String srcListString = null; + + int srcListIndex = 0; + for (JsonValue srcListJsonValue : srcListArray) { + JsonObject srcListObj = srcListArray.getJsonObject(srcListIndex); + String type = srcListObj.get("type").toString().replace("\"", ""); + + String value = null; + if(type.equals("REFERENCE")||type.equals("GROUP")){ + value = srcListObj.get("name").toString(); + } else if (type.equalsIgnoreCase("ANY")){ + value = null; + } else { + value = srcListObj.get("value").toString(); + } + + if(value != null){ + value = value.replace("\"", ""); + } + + if (srcListString != null) { + srcListString = srcListString.concat(",").concat(value); + + } else { + srcListString = value; + } + + srcListIndex++; + + } + String srcListInsert = "'"+srcListString+"'"; + + //getting destinationList Array fields from the firewallRulesList + JsonArray destListArray = ruleListobj.getJsonArray("destinationList"); + String destListString = null; + + int destListIndex = 0; + for (JsonValue destListJsonValue : destListArray) { + JsonObject destListObj = destListArray.getJsonObject(destListIndex); + String type = destListObj.get("type").toString().replace("\"", ""); + + String value = null; + if(type.equals("REFERENCE")||type.equals("GROUP")){ + value = destListObj.get("name").toString(); + } else if (type.equalsIgnoreCase("ANY")){ + value = null; + } else { + value = destListObj.get("value").toString(); + } + + if(value != null){ + value = value.replace("\"", ""); + } + + if (destListString != null) { + destListString = destListString.concat(",").concat(value); + } else { + destListString = value; + } + + destListIndex++; + } + String destListInsert = "'"+destListString+"'"; + + //getting destServices Array fields from the firewallRulesList + JsonArray destServicesArray = ruleListobj.getJsonArray("destServices"); + String destPortListString = null; + + int destPortListIndex = 0; + for (JsonValue destListJsonValue : destServicesArray) { + JsonObject destServicesObj = destServicesArray.getJsonObject(destPortListIndex); + String type = destServicesObj.get("type").toString().replace("\"", ""); + + String value = null; + if(type.equals("REFERENCE")||type.equals("GROUP")){ + value = destServicesObj.get("name").toString(); + } else if (type.equalsIgnoreCase("ANY")){ + value = null; + } else { + value = destServicesObj.get("value").toString(); + } + + if(value != null){ + value = value.replace("\"", ""); + } + + if (destPortListString != null) { + destPortListString = destPortListString.concat(",").concat(value); + } else { + destPortListString = value; + } + + destPortListIndex++; + } + String destPortListInsert = "'"+destPortListString+"'"; + + /* + * Create Queries to INSERT data into database tables and execute + */ + + //Insert Into Terms table + String termSql = "INSERT INTO Term (ID, TERMNAME, SRCIPLIST, DESTIPLIST, PROTOCOLLIST, PORTLIST, SRCPORTLIST," + + " DESTPORTLIST, ACTION, DESCRIPTION, FROMZONE, TOZONE, CREATED_BY, MODIFIED_DATE) VALUES ("+termID+"," + +ruleName+","+srcListInsert+","+destListInsert+","+ "null"+","+"null"+","+"null"+","+destPortListInsert+"," + +action+","+description+","+fromZoneInsert+","+toZoneInsert+",'API',"+ "null"+ "); "; + + termSql = termSql.replace('"', '\''); + st.addBatch(termSql); + + rs = st.executeQuery("SELECT * FROM ACTIONLIST WHERE ACTIONNAME = " + action + ";"); + + String actionSql = null; + if (rs.next()) { + //do nothing + } else { + actionSql = "INSERT INTO ACTIONLIST (ID, ACTIONNAME, DESCRIPTION) VALUES ("+actionID+","+action+","+action+") "; + actionSql = actionSql.replace('"', '\''); + st.addBatch(actionSql); + } + + st.executeBatch(); + + ri++; + } + + } + + if (path.contains("serviceGroups")) { + int serviceGroupID = 0; + int serviceListID = 0; + int protocolID = 0; + int portID = 0; + + + rs = st.executeQuery("SELECT MAX(ID) AS ID FROM SERVICEGROUP;"); + if(rs.next()){ + serviceGroupID = rs.getInt("ID"); + } + rs.close(); + + rs = st.executeQuery("SELECT MAX(ID) AS ID FROM GROUPSERVICELIST;"); + if(rs.next()){ + serviceListID = rs.getInt("ID"); + } + rs.close(); + + rs = st.executeQuery("SELECT MAX(ID) AS ID FROM PROTOCOLLIST;"); + if(rs.next()){ + protocolID = rs.getInt("ID"); + } + rs.close(); + + rs = st.executeQuery("SELECT MAX(ID) AS ID FROM PORTLIST;"); + if(rs.next()){ + portID = rs.getInt("ID"); + } + rs.close(); + + String insertQuery = null; + + /* + * Inserting serviceGroups data into the ServiceGroup, ServiceList, ProtocolList, and PortList tables + */ + int si = 0; + for(JsonValue jsonValue : serviceGroup) { + + /* + * Populate ArrayLists with values from the JSON + */ + //create the JSON object from the JSON Array for each iteration through the for loop + JsonObject svcGroupListobj = serviceGroup.getJsonObject(si); + + String groupName = svcGroupListobj.get("name").toString().replace('"', '\''); + + String description = null; + if (svcGroupListobj.containsKey("description")){ + description = svcGroupListobj.get("description").toString().replace('"', '\''); + } + + JsonArray membersArray = svcGroupListobj.getJsonArray("members"); + + Boolean isServiceGroup = false; + if (membersArray!=null){ + String membersType = membersArray.getJsonObject(0).get("type").toString(); + if (membersType.contains("REFERENCE")) { + isServiceGroup = true; + } + } + + //Insert values into GROUPSERVICELIST table if name begins with Group + if (isServiceGroup) { + + rs = st.executeQuery("SELECT * FROM GROUPSERVICELIST WHERE NAME = "+ groupName + ";"); + + if (rs.next()) { + st.executeUpdate("DELETE FROM GROUPSERVICELIST WHERE NAME = "+ groupName + ";"); + } + rs.close(); + //increment ID Primary Keys + serviceListID = serviceListID + 1; + + String name = null; + int membersIndex = 0; + for (JsonValue membersValue : membersArray) { + JsonObject membersObj = membersArray.getJsonObject(membersIndex); + String type = membersObj.get("type").toString().replace("\"", ""); + + String value = null; + if(type.equals("REFERENCE")||type.equals("GROUP")||type.equals("SERVICE")){ + value = membersObj.get("name").toString(); + } else if (type.equalsIgnoreCase("ANY")){ + value = null; + } else { + value = membersObj.get("value").toString(); + } + + if(value != null){ + value = value.replace("\"", ""); + } + + if (name != null) { + name = name.concat(",").concat(value); + } else { + name = value; + } + + membersIndex++; + } + String nameInsert = "'"+name+"'"; + + insertQuery = "INSERT INTO GROUPSERVICELIST (ID, NAME, SERVICELIST) " + + "VALUES("+serviceListID+","+groupName+","+nameInsert+")"; + + //Replace double quote with single quote + insertQuery = insertQuery.replace('"', '\''); + + //Execute the queries to Insert data + st.executeUpdate(insertQuery); + + } else { //Insert JSON data serviceGroup table, protocollist table, and portlist table + + //increment ID Primary Keys + protocolID = protocolID + 1; + portID = portID + 1; + serviceGroupID = serviceGroupID + 1; + + String type = svcGroupListobj.get("type").toString().replace('"', '\''); + String transportProtocol = svcGroupListobj.get("transportProtocol").toString().replace('"', '\''); + String ports = svcGroupListobj.get("ports").toString().replace('"', '\''); + + rs = st.executeQuery("SELECT * FROM SERVICEGROUP WHERE NAME = "+ groupName + ";"); + + if (rs.next()) { + st.executeUpdate("DELETE FROM SERVICEGROUP WHERE NAME = "+ groupName + ";"); + } + rs.close(); + + String svcGroupSql = "INSERT INTO SERVICEGROUP (ID, NAME, DESCRIPTION, TYPE, TRANSPORTPROTOCOL, APPPROTOCOL, PORTS) " + + "VALUES("+serviceGroupID+","+groupName+","+description+","+type+"," + + transportProtocol+","+"null,"+ports+"); "; + svcGroupSql = svcGroupSql.replace('"', '\''); + st.addBatch(svcGroupSql); + + rs = st.executeQuery("SELECT * FROM PROTOCOLLIST WHERE PROTOCOLNAME = " + transportProtocol + ";"); + + String protoSql = null; + if (rs.next()) { + //do nothing + } else { + protoSql = "INSERT INTO PROTOCOLLIST (ID, PROTOCOLNAME, DESCRIPTION) " + + "VALUES("+protocolID+","+transportProtocol+","+transportProtocol+"); "; + protoSql = protoSql.replace('"', '\''); + st.addBatch(protoSql); + + } + rs.close(); + + rs = st.executeQuery("SELECT * FROM PORTLIST WHERE PORTNAME = " + ports + ";"); + + String portSql = null; + if (rs.next()) { + //do nothing + } else { + portSql = "INSERT INTO PORTLIST (ID, PORTNAME, DESCRIPTION) VALUES("+portID+","+ports+","+ports+"); "; + portSql = portSql.replace('"', '\''); + st.addBatch(portSql); + } + rs.close(); + + st.executeBatch(); + + } + + + si++; + } + + } + + if (path.contains("addressGroups")) { + /* + * Inserting addressGroup data into the ADDRESSGROUP table + */ + int prefixID = 0; + int addressID = 0; + + rs = st.executeQuery("SELECT MAX(ID) AS ID FROM PREFIXLIST;"); + if(rs.next()){ + prefixID = rs.getInt("ID"); + } + rs.close(); + + rs = st.executeQuery("SELECT MAX(ID) AS ID FROM ADDRESSGROUP;"); + if(rs.next()){ + addressID = rs.getInt("ID"); + } + rs.close(); + + String insertQuery = null; + + int ai = 0; + for(JsonValue jsonValue : addressGroup) { + + /* + * Populate ArrayLists with values from the JSON + */ + //create the JSON object from the JSON Array for each iteration through the for loop + JsonObject addressGroupObj = addressGroup.getJsonObject(ai); + + //create JSON array for members + JsonArray membersArray = addressGroupObj.getJsonArray("members"); + String addressGroupName = addressGroupObj.get("name").toString().replace('"', '\''); + + String description = null; + if (addressGroupObj.containsKey("description")){ + description = addressGroupObj.get("description").toString().replace('"', '\''); + } + + String prefixIP = null; + String type = null; + int membersIndex = 0; + for (JsonValue membersValue : membersArray) { + JsonObject membersObj = membersArray.getJsonObject(membersIndex); + type = membersObj.get("type").toString().replace("\"", ""); + + String value = null; + if(type.equals("REFERENCE")||type.equals("GROUP")||type.equals("SERVICE")){ + value = membersObj.get("name").toString(); + } else if (type.equalsIgnoreCase("ANY")){ + value = null; + } else { + value = membersObj.get("value").toString(); + } + + if(value != null){ + value = value.replace("\"", ""); + } + + if (prefixIP != null) { + prefixIP = prefixIP.concat(",").concat(value); + } else { + prefixIP = value; + } + + membersIndex++; + } + String prefixList = "'"+prefixIP+"'"; + + Boolean isAddressGroup = type.contains("REFERENCE"); + + if (isAddressGroup) { + + rs = st.executeQuery("SELECT * FROM ADDRESSGROUP WHERE NAME = "+ addressGroupName + ";"); + + if (rs.next()) { + st.executeUpdate("DELETE FROM ADDRESSGROUP WHERE NAME = "+ addressGroupName + ";"); + } + rs.close(); + //increment ID Primary Keys + addressID = addressID + 1; + + insertQuery = "INSERT INTO ADDRESSGROUP (ID, NAME, DESCRIPTION, PREFIXLIST) " + + "VALUES("+addressID+","+addressGroupName+","+description+","+prefixList+")"; + + + + } else { + + rs = st.executeQuery("SELECT * FROM PREFIXLIST WHERE PL_NAME = "+ addressGroupName + ";"); + + if (rs.next()) { + st.executeUpdate("DELETE FROM PREFIXLIST WHERE PL_NAME = "+ addressGroupName + ";"); + } + rs.close(); + //increment ID Primary Key + prefixID = prefixID + 1; + + insertQuery = "INSERT INTO PREFIXLIST (ID, PL_NAME, PL_VALUE, DESCRIPTION) " + + "VALUES("+prefixID+","+addressGroupName+","+prefixList+","+description+")"; + + } + + + //Replace double quote with single quote + insertQuery = insertQuery.replace('"', '\''); + + //Execute the queries to Insert data + st.executeUpdate(insertQuery); + + ai++; + } + + } + + i++; + } + + /* + * Remove duplicate values from 'lookup' dictionary tables + */ + //ProtocolList Table + String protoDelete = "DELETE FROM protocollist USING protocollist, protocollist p1 " + + "WHERE protocollist.id > p1.id AND protocollist.protocolname = p1.protocolname;"; + st.addBatch(protoDelete); + + //PortList Table + String portListDelete = "DELETE FROM portlist USING portlist, portlist p1 " + + "WHERE portlist.id > p1.id AND portlist.portname = p1.portname; "; + st.addBatch(portListDelete); + + //PrefixList Table + String prefixListDelete = "DELETE FROM prefixlist USING prefixlist, prefixlist p1 " + + "WHERE prefixlist.id > p1.id AND prefixlist.pl_name = p1.pl_name AND " + + "prefixlist.pl_value = p1.pl_value AND prefixlist.description = p1.description; "; + st.addBatch(prefixListDelete); + + //GroupServiceList + String groupServiceDelete = "DELETE FROM groupservicelist USING groupservicelist, groupservicelist g1 " + + "WHERE groupservicelist.id > g1.id AND groupservicelist.name = g1.name AND " + + "groupservicelist.serviceList = g1.serviceList; "; + st.addBatch(groupServiceDelete); + + st.executeBatch(); + + } catch (ClassNotFoundException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(e.getMessage()); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "FirewallConfigPolicy", "Exception building Firewall queries"); + System.out.println(e.getMessage()); + return false; + + } catch (SQLException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(e.getMessage()); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "FirewallConfigPolicy", "Exception executing Firewall queries"); + System.out.println(e.getMessage()); + return false; + } finally { + try{ + if (con!=null) con.close(); + if (rs!=null) rs.close(); + if (st!=null) st.close(); + } catch (Exception ex){} + } + return true; + + } else { + return false; + } + +} + + private JsonObject stringToJson(String jsonString) { + + JsonObject json = null; + if (jsonString != null) { + + //Read jsonBody to JsonObject + StringReader in = null; + + in = new StringReader(jsonString); + + JsonReader jsonReader = Json.createReader(in); + json = jsonReader.readObject(); + } + + return json; + } + + + private JsonNode createPatch(String json, String oldJson) { + JsonNode oldJason = null; + JsonNode updatedJason = null; + + try { + oldJason = JsonLoader.fromString(oldJson); + updatedJason = JsonLoader.fromString(json); + } catch (IOException e) { + e.printStackTrace(); + } + + JsonPatch jsonPatch = JsonDiff.asJsonPatch(oldJason, updatedJason); + JsonNode patchNode = JsonDiff.asJson(oldJason, updatedJason); + System.out.println("Sending Patch:" + jsonPatch); + return patchNode; + + } + + @Override + public Object getCorrectPolicyDataObject() { + return policyAdapter.getPolicyData(); + } + +} + + + diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/MicroServiceConfigPolicy.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/MicroServiceConfigPolicy.java new file mode 100644 index 000000000..c65b0be9d --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/MicroServiceConfigPolicy.java @@ -0,0 +1,561 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.components; + +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; +import java.net.URI; +import java.net.URISyntaxException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.Map; +import java.util.StringTokenizer; + +import javax.json.stream.JsonGenerationException; + +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionsType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeAssignmentExpressionType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.EffectType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObjectFactory; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.RuleType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType; + +import org.apache.commons.io.FilenameUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openecomp.policy.pap.xacml.rest.adapters.PolicyRestAdapter; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; +import com.att.research.xacml.std.IdentifierImpl; + +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.eelf.PolicyLogger; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +public class MicroServiceConfigPolicy extends Policy { + + /** + * Config Fields + */ + private static final Logger logger = FlexLogger.getLogger(ConfigPolicy.class); + + public MicroServiceConfigPolicy() { + super(); + } + + public MicroServiceConfigPolicy(PolicyRestAdapter policyAdapter){ + this.policyAdapter = policyAdapter; + } + + //save configuration of the policy based on the policyname + private void saveConfigurations(String policyName, String prevPolicyName, String jsonBody) { + String domain = getParentPathSubScopeDir(); + String path = domain.replace('\\', '.'); + if(path.contains("/")){ + path = domain.replace('/', '.'); + logger.info("print the path:" +path); + } + try { + String body = null; + try { + body = jsonBody; + } catch (Exception e) { + e.printStackTrace(); + } + + System.out.println(body); + if(policyName.endsWith(".xml")){ + policyName = policyName.substring(0, policyName.lastIndexOf(".xml")); + } + PrintWriter out = new PrintWriter(CONFIG_HOME + File.separator+path + "."+ policyName +".json"); + out.println(body); + out.close(); + + } catch (JsonGenerationException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + + } + + //getting the policy name and setting to configuration on adding .json + private String getConfigFile(String filename) { + filename = FilenameUtils.removeExtension(filename); + if (filename.endsWith(".xml")) { + filename = filename.substring(0, filename.length() - 4); + } + filename = filename +".json"; + return filename; + } + + @Override + public Map savePolicies() throws Exception { + + Map successMap = new HashMap(); + if(isPolicyExists()){ + successMap.put("EXISTS", "This Policy already exist on the PAP"); + return successMap; + } + + if(!isPreparedToSave()){ + //Prep and configure the policy for saving + prepareToSave(); + } + + // Until here we prepared the data and here calling the method to create xml. + Path newPolicyPath = null; + newPolicyPath = Paths.get(policyAdapter.getParentPath().toString(), policyName); + successMap = createPolicy(newPolicyPath,getCorrectPolicyDataObject() ); + if (successMap.containsKey("success")) { + Path finalPolicyPath = getFinalPolicyPath(); + policyAdapter.setFinalPolicyPath(finalPolicyPath.toString()); + } + return successMap; + } + + //This is the method for preparing the policy for saving. We have broken it out + //separately because the fully configured policy is used for multiple things + @Override + public boolean prepareToSave() throws Exception{ + + if(isPreparedToSave()){ + //we have already done this + return true; + } + + int version = 0; + String policyID = policyAdapter.getPolicyID(); + + if (policyAdapter.isEditPolicy()) { + version = policyAdapter.getHighestVersion() + 1; + } else { + version = 1; + } + + // Create the Instance for pojo, PolicyType object is used in marshalling. + if (policyAdapter.getPolicyType().equals("Config")) { + PolicyType policyConfig = new PolicyType(); + + policyConfig.setVersion(Integer.toString(version)); + policyConfig.setPolicyId(policyID); + policyConfig.setTarget(new TargetType()); + policyAdapter.setData(policyConfig); + } + + if (policyAdapter.getData() != null) { + + // Save off everything + // making ready all the required elements to generate the action policy xml. + // Get the uniqueness for policy name. + String prevPolicyName = null; + if(policyAdapter.isEditPolicy()){ + prevPolicyName = "Config_MS_" + policyAdapter.getPolicyName() + "." + policyAdapter.getHighestVersion() + ".xml"; + } + + Path newFile = this.getNextLoopFilename(Paths.get(policyAdapter.getParentPath()), policyAdapter.getPolicyType(), + policyAdapter.getConfigPolicyType(), policyAdapter.getPolicyName(), version); + + if (newFile == null) { + //TODO:EELF Cleanup - Remove logger + //logger.error("Policy already Exists, cannot create the policy."); + PolicyLogger.error("Policy already Exists, cannot create the policy."); + setPolicyExists(true); + return false; + } + + policyName = newFile.getFileName().toString(); + + // Save the Configurations file with the policy name with extention based on selection. + String jsonBody = policyAdapter.getJsonBody(); + saveConfigurations(policyName, prevPolicyName, jsonBody); + + // Make sure the filename ends with an extension + if (policyName.endsWith(".xml") == false) { + policyName = policyName + ".xml"; + } + + + PolicyType configPolicy = (PolicyType) policyAdapter.getData(); + + configPolicy.setDescription(policyAdapter.getPolicyDescription()); + + configPolicy.setRuleCombiningAlgId(policyAdapter.getRuleCombiningAlgId()); + + AllOfType allOfOne = new AllOfType(); + final Path gitPath = Paths.get(policyAdapter.getUserGitPath().toString()); + String policyDir = policyAdapter.getParentPath().toString(); + int startIndex = policyDir.indexOf(gitPath.toString()) + gitPath.toString().length() + 1; + policyDir = policyDir.substring(startIndex, policyDir.length()); + logger.info("print the main domain value "+policyDir); + String path = policyDir.replace('\\', '.'); + if(path.contains("/")){ + path = policyDir.replace('/', '.'); + logger.info("print the path:" +path); + } + String fileName = FilenameUtils.removeExtension(policyName); + fileName = path + "." + fileName + ".xml"; + String name = fileName.substring(fileName.lastIndexOf("\\") + 1, fileName.length()); + if ((name == null) || (name.equals(""))) { + name = fileName.substring(fileName.lastIndexOf("/") + 1, fileName.length()); + } + + // Match for policyName + allOfOne.getMatch().add(createMatch("PolicyName", name)); + + AllOfType allOf = new AllOfType(); + + // Adding the matches to AllOfType element Match for Ecomp + allOf.getMatch().add(createMatch("ECOMPName", policyAdapter.getEcompName())); + // Match for ConfigName + allOf.getMatch().add(createMatch("ConfigName", policyAdapter.getConfigName())); + // Match for Service + allOf.getMatch().add(createDynamicMatch("service", policyAdapter.getServiceType())); + // Match for uuid + allOf.getMatch().add(createDynamicMatch("uuid", policyAdapter.getUuid())); + // Match for location + allOf.getMatch().add(createDynamicMatch("location", policyAdapter.getLocation())); + // Match for riskType + allOf.getMatch().add( + createDynamicMatch("RiskType", policyAdapter.getRiskType())); + // Match for riskLevel + allOf.getMatch().add( + createDynamicMatch("RiskLevel", String.valueOf(policyAdapter.getRiskLevel()))); + // Match for riskguard + allOf.getMatch().add( + createDynamicMatch("guard", policyAdapter.getGuard())); + // Match for ttlDate + allOf.getMatch().add( + createDynamicMatch("TTLDate", policyAdapter.getTtlDate())); + + AnyOfType anyOf = new AnyOfType(); + anyOf.getAllOf().add(allOfOne); + anyOf.getAllOf().add(allOf); + + TargetType target = new TargetType(); + ((TargetType) target).getAnyOf().add(anyOf); + + // Adding the target to the policy element + configPolicy.setTarget((TargetType) target); + + RuleType rule = new RuleType(); + rule.setRuleId(policyAdapter.getRuleID()); + + rule.setEffect(EffectType.PERMIT); + + // Create Target in Rule + AllOfType allOfInRule = new AllOfType(); + + // Creating match for ACCESS in rule target + MatchType accessMatch = new MatchType(); + AttributeValueType accessAttributeValue = new AttributeValueType(); + accessAttributeValue.setDataType(STRING_DATATYPE); + accessAttributeValue.getContent().add("ACCESS"); + accessMatch.setAttributeValue(accessAttributeValue); + AttributeDesignatorType accessAttributeDesignator = new AttributeDesignatorType(); + URI accessURI = null; + try { + accessURI = new URI(ACTION_ID); + } catch (URISyntaxException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e.getStackTrace()); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "MicroServiceConfigPolicy", "Exception creating ACCESS URI"); + } + accessAttributeDesignator.setCategory(CATEGORY_ACTION); + accessAttributeDesignator.setDataType(STRING_DATATYPE); + accessAttributeDesignator.setAttributeId(new IdentifierImpl(accessURI).stringValue()); + accessMatch.setAttributeDesignator(accessAttributeDesignator); + accessMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE); + + // Creating Config Match in rule Target + MatchType configMatch = new MatchType(); + AttributeValueType configAttributeValue = new AttributeValueType(); + configAttributeValue.setDataType(STRING_DATATYPE); + configAttributeValue.getContent().add("Config"); + configMatch.setAttributeValue(configAttributeValue); + AttributeDesignatorType configAttributeDesignator = new AttributeDesignatorType(); + URI configURI = null; + try { + configURI = new URI(RESOURCE_ID); + } catch (URISyntaxException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e.getStackTrace()); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "MicroServiceConfigPolicy", "Exception creating Config URI"); + } + configAttributeDesignator.setCategory(CATEGORY_RESOURCE); + configAttributeDesignator.setDataType(STRING_DATATYPE); + configAttributeDesignator.setAttributeId(new IdentifierImpl(configURI).stringValue()); + configMatch.setAttributeDesignator(configAttributeDesignator); + configMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE); + + allOfInRule.getMatch().add(accessMatch); + allOfInRule.getMatch().add(configMatch); + + AnyOfType anyOfInRule = new AnyOfType(); + anyOfInRule.getAllOf().add(allOfInRule); + + TargetType targetInRule = new TargetType(); + targetInRule.getAnyOf().add(anyOfInRule); + + rule.setTarget(targetInRule); + rule.setAdviceExpressions(getAdviceExpressions(version, policyName)); + + configPolicy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().add(rule); + policyAdapter.setPolicyData(configPolicy); + + } else { + //TODO:EELF Cleanup - Remove logger + //logger.error("Unsupported data object." + policyAdapter.getData().getClass().getCanonicalName()); + PolicyLogger.error("Unsupported data object." + policyAdapter.getData().getClass().getCanonicalName()); + } + setPreparedToSave(true); + return true; + } + + // Data required for Advice part is setting here. + private AdviceExpressionsType getAdviceExpressions(int version, String fileName) { + AdviceExpressionsType advices = new AdviceExpressionsType(); + AdviceExpressionType advice = new AdviceExpressionType(); + advice.setAdviceId("MSID"); + advice.setAppliesTo(EffectType.PERMIT); + // For Configuration + AttributeAssignmentExpressionType assignment1 = new AttributeAssignmentExpressionType(); + assignment1.setAttributeId("type"); + assignment1.setCategory(CATEGORY_RESOURCE); + assignment1.setIssuer(""); + + AttributeValueType configNameAttributeValue = new AttributeValueType(); + configNameAttributeValue.setDataType(STRING_DATATYPE); + configNameAttributeValue.getContent().add("Configuration"); + assignment1.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue)); + + advice.getAttributeAssignmentExpression().add(assignment1); + final Path gitPath = Paths.get(policyAdapter.getUserGitPath().toString()); + // For Config file Url if configurations are provided. + AttributeAssignmentExpressionType assignment2 = new AttributeAssignmentExpressionType(); + assignment2.setAttributeId("URLID"); + assignment2.setCategory(CATEGORY_RESOURCE); + assignment2.setIssuer(""); + + AttributeValueType AttributeValue = new AttributeValueType(); + AttributeValue.setDataType(URI_DATATYPE); + String policyDir1 = policyAdapter.getParentPath().toString(); + int startIndex1 = policyDir1.indexOf(gitPath.toString()) + gitPath.toString().length() + 1; + policyDir1 = policyDir1.substring(startIndex1, policyDir1.length()); + logger.info("print the main domain value"+policyDir1); + String path = policyDir1.replace('\\', '.'); + if(path.contains("/")){ + path = policyDir1.replace('/', '.'); + logger.info("print the path:" +path); + } + String content = CONFIG_URL +"/Config/" + path + "." + getConfigFile(policyName); + System.out.println("URL value :" + content); + AttributeValue.getContent().add(content); + assignment2.setExpression(new ObjectFactory().createAttributeValue(AttributeValue)); + + advice.getAttributeAssignmentExpression().add(assignment2); + AttributeAssignmentExpressionType assignment3 = new AttributeAssignmentExpressionType(); + assignment3.setAttributeId("PolicyName"); + assignment3.setCategory(CATEGORY_RESOURCE); + assignment3.setIssuer(""); + + AttributeValueType attributeValue3 = new AttributeValueType(); + attributeValue3.setDataType(STRING_DATATYPE); + String policyDir = policyAdapter.getParentPath().toString(); + int startIndex = policyDir.indexOf(gitPath.toString()) + gitPath.toString().length() + 1; + policyDir = policyDir.substring(startIndex, policyDir.length()); + StringTokenizer tokenizer = null; + StringBuffer buffer = new StringBuffer(); + if (policyDir.contains("\\")) { + tokenizer = new StringTokenizer(policyDir, "\\"); + } else { + tokenizer = new StringTokenizer(policyDir, "/"); + } + if (tokenizer != null) { + while (tokenizer.hasMoreElements()) { + String value = tokenizer.nextToken(); + buffer.append(value); + buffer.append("."); + } + } + fileName = FilenameUtils.removeExtension(fileName); + fileName = buffer.toString() + fileName + ".xml"; + String name = fileName.substring(fileName.lastIndexOf("\\") + 1, fileName.length()); + if ((name == null) || (name.equals(""))) { + name = fileName.substring(fileName.lastIndexOf("/") + 1, fileName.length()); + } + attributeValue3.getContent().add(name); + assignment3.setExpression(new ObjectFactory().createAttributeValue(attributeValue3)); + advice.getAttributeAssignmentExpression().add(assignment3); + + AttributeAssignmentExpressionType assignment4 = new AttributeAssignmentExpressionType(); + assignment4.setAttributeId("VersionNumber"); + assignment4.setCategory(CATEGORY_RESOURCE); + assignment4.setIssuer(""); + + AttributeValueType configNameAttributeValue4 = new AttributeValueType(); + configNameAttributeValue4.setDataType(STRING_DATATYPE); + configNameAttributeValue4.getContent().add(Integer.toString(version)); + assignment4.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue4)); + + advice.getAttributeAssignmentExpression().add(assignment4); + + AttributeAssignmentExpressionType assignment5 = new AttributeAssignmentExpressionType(); + assignment5.setAttributeId("matching:" + this.ECOMPID); + assignment5.setCategory(CATEGORY_RESOURCE); + assignment5.setIssuer(""); + + AttributeValueType configNameAttributeValue5 = new AttributeValueType(); + configNameAttributeValue5.setDataType(STRING_DATATYPE); + configNameAttributeValue5.getContent().add(policyAdapter.getEcompName()); + assignment5.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue5)); + + advice.getAttributeAssignmentExpression().add(assignment5); + + AttributeAssignmentExpressionType assignment6 = new AttributeAssignmentExpressionType(); + assignment6.setAttributeId("matching:" + this.CONFIGID); + assignment6.setCategory(CATEGORY_RESOURCE); + assignment6.setIssuer(""); + + AttributeValueType configNameAttributeValue6 = new AttributeValueType(); + configNameAttributeValue6.setDataType(STRING_DATATYPE); + configNameAttributeValue6.getContent().add(policyAdapter.getConfigName()); + assignment6.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue6)); + + advice.getAttributeAssignmentExpression().add(assignment6); + AttributeAssignmentExpressionType assignment7 = new AttributeAssignmentExpressionType(); + assignment7.setAttributeId("matching:service"); + assignment7.setCategory(CATEGORY_RESOURCE); + assignment7.setIssuer(""); + + AttributeValueType configNameAttributeValue7 = new AttributeValueType(); + configNameAttributeValue7.setDataType(STRING_DATATYPE); + configNameAttributeValue7.getContent().add(policyAdapter.getServiceType()); + assignment7.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue7)); + + advice.getAttributeAssignmentExpression().add(assignment7); + + AttributeAssignmentExpressionType assignment8 = new AttributeAssignmentExpressionType(); + assignment8.setAttributeId("matching:uuid"); + assignment8.setCategory(CATEGORY_RESOURCE); + assignment8.setIssuer(""); + + AttributeValueType configNameAttributeValue8 = new AttributeValueType(); + configNameAttributeValue8.setDataType(STRING_DATATYPE); + configNameAttributeValue8.getContent().add(policyAdapter.getUuid()); + assignment8.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue8)); + + advice.getAttributeAssignmentExpression().add(assignment8); + + AttributeAssignmentExpressionType assignment9 = new AttributeAssignmentExpressionType(); + assignment9.setAttributeId("matching:Location"); + assignment9.setCategory(CATEGORY_RESOURCE); + assignment9.setIssuer(""); + + AttributeValueType configNameAttributeValue9 = new AttributeValueType(); + configNameAttributeValue9.setDataType(STRING_DATATYPE); + configNameAttributeValue9.getContent().add(policyAdapter.getLocation()); + assignment9.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue9)); + + advice.getAttributeAssignmentExpression().add(assignment9); + + AttributeAssignmentExpressionType assignment10 = new AttributeAssignmentExpressionType(); + assignment10.setAttributeId("Priority"); + assignment10.setCategory(CATEGORY_RESOURCE); + assignment10.setIssuer(""); + + AttributeValueType configNameAttributeValue10 = new AttributeValueType(); + configNameAttributeValue10.setDataType(STRING_DATATYPE); + configNameAttributeValue10.getContent().add(policyAdapter.getPriority()); + assignment10.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue10)); + + advice.getAttributeAssignmentExpression().add(assignment10); + + //Risk Attributes + AttributeAssignmentExpressionType assignment11 = new AttributeAssignmentExpressionType(); + assignment11.setAttributeId("RiskType"); + assignment11.setCategory(CATEGORY_RESOURCE); + assignment11.setIssuer(""); + + AttributeValueType configNameAttributeValue11 = new AttributeValueType(); + configNameAttributeValue11.setDataType(STRING_DATATYPE); + configNameAttributeValue11.getContent().add(policyAdapter.getRiskType()); + assignment11.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue11)); + + advice.getAttributeAssignmentExpression().add(assignment11); + + AttributeAssignmentExpressionType assignment12 = new AttributeAssignmentExpressionType(); + assignment12.setAttributeId("RiskLevel"); + assignment12.setCategory(CATEGORY_RESOURCE); + assignment12.setIssuer(""); + + AttributeValueType configNameAttributeValue12 = new AttributeValueType(); + configNameAttributeValue12.setDataType(STRING_DATATYPE); + configNameAttributeValue12.getContent().add(policyAdapter.getRiskLevel()); + assignment12.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue12)); + + advice.getAttributeAssignmentExpression().add(assignment12); + + AttributeAssignmentExpressionType assignment13 = new AttributeAssignmentExpressionType(); + assignment13.setAttributeId("guard"); + assignment13.setCategory(CATEGORY_RESOURCE); + assignment13.setIssuer(""); + + AttributeValueType configNameAttributeValue13 = new AttributeValueType(); + configNameAttributeValue13.setDataType(STRING_DATATYPE); + configNameAttributeValue13.getContent().add(policyAdapter.getRiskLevel()); + assignment13.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue13)); + + advice.getAttributeAssignmentExpression().add(assignment13); + + AttributeAssignmentExpressionType assignment14 = new AttributeAssignmentExpressionType(); + assignment14.setAttributeId("TTLDate"); + assignment14.setCategory(CATEGORY_RESOURCE); + assignment14.setIssuer(""); + + AttributeValueType configNameAttributeValue14 = new AttributeValueType(); + configNameAttributeValue14.setDataType(STRING_DATATYPE); + configNameAttributeValue14.getContent().add(policyAdapter.getTtlDate()); + assignment14.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue14)); + + advice.getAttributeAssignmentExpression().add(assignment14); + + advices.getAdviceExpression().add(advice); + return advices; + } + + @Override + public Object getCorrectPolicyDataObject() { + return policyAdapter.getPolicyData(); + } + + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/Policy.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/Policy.java new file mode 100644 index 000000000..09c90de68 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/Policy.java @@ -0,0 +1,455 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.components; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.net.URISyntaxException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.Map; + +import javax.json.Json; +import javax.json.JsonReader; + +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType; + +import org.apache.commons.io.FilenameUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.json.JSONObject; +import org.openecomp.policy.pap.xacml.rest.adapters.PolicyRestAdapter; +import org.openecomp.policy.rest.XACMLRestProperties; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; +import com.att.research.xacml.std.IdentifierImpl; +import org.openecomp.policy.xacml.util.XACMLPolicyWriter; +import com.att.research.xacml.util.XACMLProperties; +import com.att.research.xacmlatt.pdp.policy.PolicyDef; +import com.att.research.xacmlatt.pdp.policy.dom.DOMPolicyDef; + +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.eelf.PolicyLogger; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +public abstract class Policy { + + /** + * Common Fields + */ + public static final String GET_INT_TYPE = "Integer"; + public static final String GET_STRING_TYPE = "String"; + + public static final String ECOMPID = "ECOMPName"; + public static final String CONFIGID = "ConfigName"; + public static final String CLOSEDLOOPID = "ServiceType"; + + public static final String CONFIG_POLICY = "Config"; + public static final String ACTION_POLICY = "Action"; + public static final String DECISION_POLICY = "Decision"; + + protected String policyName = null; + private static final Logger logger = FlexLogger.getLogger(Policy.class); + + boolean isValidForm = true; + + private Path finalPolicyPath = null; + + private boolean preparedToSave = false; + + private boolean policyExists = false; + + public Path getFinalPolicyPath() { + return finalPolicyPath; + } + + public void setFinalPolicyPath(Path finalPolicyPath) { + this.finalPolicyPath = finalPolicyPath; + } + + // Constants Used in XML Creation + public static final String CATEGORY_RECIPIENT_SUBJECT = "urn:oasis:names:tc:xacml:1.0:subject-category:recipient-subject"; + public static final String CATEGORY_RESOURCE = "urn:oasis:names:tc:xacml:3.0:attribute-category:resource"; + public static final String CATEGORY_ACTION = "urn:oasis:names:tc:xacml:3.0:attribute-category:action"; + public static final String CATEGORY_ACCESS_SUBJECT = "urn:oasis:names:tc:xacml:1.0:subject-category:access-subject"; + public static final String ACTION_ID = "urn:oasis:names:tc:xacml:1.0:action:action-id"; + public static final String SUBJECT_ID = "urn:oasis:names:tc:xacml:1.0:subject:subject-id"; + public static final String RESOURCE_ID = "urn:oasis:names:tc:xacml:1.0:resource:resource-id"; + public static final String FUNTION_INTEGER_ONE_AND_ONLY = "urn:oasis:names:tc:xacml:1.0:function:integer-one-and-only"; + public static final String FUNCTION_STRING_ONE_AND_ONLY = "urn:oasis:names:tc:xacml:1.0:function:string-one-and-only"; + public static final String FUNCTION_BOOLEAN_ONE_AND_ONLY = "urn:oasis:names:tc:xacml:1.0:function:boolean-one-and-only"; + public static final String FUNCTION_STRING_EQUAL = "urn:oasis:names:tc:xacml:1.0:function:string-equal"; + public static final String FUNCTION_STRING_REGEX_MATCH = "org.openecomp.function.regex-match"; + public static final String FUNCTION_STRING_EQUAL_IGNORE = "urn:oasis:names:tc:xacml:3.0:function:string-equal-ignore-case"; + public static final String INTEGER_DATATYPE = "http://www.w3.org/2001/XMLSchema#integer"; + public static final String BOOLEAN_DATATYPE = "http://www.w3.org/2001/XMLSchema#boolean"; + public static final String STRING_DATATYPE = "http://www.w3.org/2001/XMLSchema#string"; + public static final String URI_DATATYPE = "http://www.w3.org/2001/XMLSchema#anyURI"; + public static final String RULE_VARIABLE = "var:"; + public static final String EMPTY_STRING = ""; + private static final String String = null; + + public static String CONFIG_HOME = null; + public static String ACTION_HOME = null; + public static String CONFIG_URL = null; + + protected Map performer = new HashMap(); + + private static String actionHome = null; + private static String configHome = null; + + public PolicyRestAdapter policyAdapter = null; + String ruleID = ""; + + public Policy() { + CONFIG_HOME = getConfigHome(); + ACTION_HOME = getActionHome(); + CONFIG_URL = "$URL"; + performer.put("PDP", "PDPAction"); + performer.put("PEP", "PEPAction"); + } + + //Each policy type seems to either use policyData or data field policy adapter when + //getting the xml to save the policy. Instead of keep this hardcoded in the save method, + //this method makes it usable outside. + /** + * Return the data field of the PolicyAdapter that will be used when saving this policy + * with the savePolicies method. + * @return Either the PolicyAdapter.getData() or PolicyAdapter.getPolicyData() + */ + public abstract Object getCorrectPolicyDataObject(); + public abstract Map savePolicies() throws Exception; + + //This is the method for preparing the policy for saving. We have broken it out + //separately because the fully configured policy is used for multiple things + public abstract boolean prepareToSave() throws Exception; + + + // create match for ecomp and config name + protected MatchType createMatch(String key, String value) { + MatchType match = new MatchType(); + + AttributeValueType attributeValue = new AttributeValueType(); + attributeValue.setDataType(STRING_DATATYPE); + attributeValue.getContent().add(value); + match.setAttributeValue(attributeValue); + AttributeDesignatorType attributeDesignator = new AttributeDesignatorType(); + URI uri = null; + try { + uri = new URI(key); + } catch (URISyntaxException e) { + e.printStackTrace(); + } + attributeDesignator.setCategory(CATEGORY_ACCESS_SUBJECT); + attributeDesignator.setDataType(STRING_DATATYPE); + attributeDesignator.setAttributeId(new IdentifierImpl(uri).stringValue()); + match.setAttributeDesignator(attributeDesignator); + match.setMatchId(FUNCTION_STRING_REGEX_MATCH); + return match; + } + + // Creating the match for dynamically added components. + protected MatchType createDynamicMatch(String key, String value) { + MatchType dynamicMatch = new MatchType(); + AttributeValueType dynamicAttributeValue = new AttributeValueType(); + //Attribute attribute = findAttributeByAttributeId(key); + String dataType = null; + // if (value.matches("[0-9]+")) { + // dataType = INTEGER_DATATYPE; + // } else { + // dataType = STRING_DATATYPE; + // } + dataType = STRING_DATATYPE; + dynamicAttributeValue.setDataType(dataType); + dynamicAttributeValue.getContent().add(value); + dynamicMatch.setAttributeValue(dynamicAttributeValue); + + AttributeDesignatorType dynamicAttributeDesignator = new AttributeDesignatorType(); + + URI dynamicURI = null; + try { + dynamicURI = new URI(key); + } catch (URISyntaxException e) { + e.printStackTrace();// log msg + } + dynamicAttributeDesignator.setCategory(CATEGORY_RESOURCE); + dynamicAttributeDesignator.setDataType(dataType); + dynamicAttributeDesignator.setAttributeId(new IdentifierImpl(dynamicURI).stringValue()); + dynamicMatch.setAttributeDesignator(dynamicAttributeDesignator); + dynamicMatch.setMatchId(FUNCTION_STRING_REGEX_MATCH); + + return dynamicMatch; + } + + //validation for numeric + protected boolean isNumeric(String str) + { + for (char c : str.toCharArray()) + { + if (!Character.isDigit(c)) return false; + } + return true; + } + + // Validation for json. + protected static boolean isJSONValid(String data) { + try { + new JSONObject(data); + InputStream stream = new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8)); + JsonReader jsonReader = Json.createReader(stream); + System.out.println("Json Value is: " + jsonReader.read().toString() ); + } catch (Exception e) { + return false; + } + return true; + } + + // the Policy Name as Unique One throws error + protected Path getNextFilename(Path parent, String policyType, String polcyFileName, Integer version) { + policyType = FilenameUtils.removeExtension(policyType); + polcyFileName = FilenameUtils.removeExtension(polcyFileName); + Path newFile = null; + String policyDir = EMPTY_STRING; + String absolutePath = parent.toString(); + if (absolutePath != null && !absolutePath.equals(EMPTY_STRING)) { + policyDir = absolutePath.substring(absolutePath.lastIndexOf("\\") + 1, absolutePath.length()); + if (policyDir == null || policyDir.equals(EMPTY_STRING)) { + policyDir = absolutePath.substring(absolutePath.lastIndexOf("/") + 1, absolutePath.length()); + } + } + + String fileName = "default"; + if (policyDir != null && !policyDir.equals(EMPTY_STRING)) { + fileName = policyType + "_" + String.format(polcyFileName) + "." + version + ".xml"; + } + if (fileName != null) { + newFile = Paths.get(parent.toString(), fileName); + } + if (Files.notExists(newFile)) { + return newFile; + } + return null; + } + + protected Path getNextLoopFilename(Path parentPath, String policyType, + String policyConfigType, String policyFileName, Integer version) { + policyType = FilenameUtils.removeExtension(policyType); + policyConfigType = FilenameUtils.removeExtension(policyConfigType); + policyFileName = FilenameUtils.removeExtension(policyFileName); + Path newFile = null; + String policyDir = EMPTY_STRING; + String absolutePath = parentPath.toString(); + if (absolutePath != null && !absolutePath.equals(EMPTY_STRING)) { + policyDir = absolutePath.substring(absolutePath.lastIndexOf("\\") + 1, absolutePath.length()); + if (policyDir == null || policyDir.equals(EMPTY_STRING)) { + policyDir = absolutePath.substring(absolutePath.lastIndexOf("/") + 1, absolutePath.length()); + } + } + + String fileName = "default"; + if (policyDir != null && !policyDir.equals(EMPTY_STRING)) { + if(policyConfigType.equals("ClosedLoop_PM")){ + fileName = policyType + "_" + "PM" + "_" +java.lang.String.format(policyFileName) + "." +version +".xml"; + }else if(policyConfigType.equals("ClosedLoop_Fault")){ + fileName = policyType + "_" + "Fault" + "_" +java.lang.String.format(policyFileName) + "." + version + ".xml"; + }else if(policyConfigType.equals("ClosedLoop_Fault")){ + fileName = policyType + "_" + "Fault" + "_" +java.lang.String.format(policyFileName) + "." + version + ".xml"; + }else if(policyConfigType.equals("DCAE Micro Service")){ + fileName = policyType + "_" + "MS" + "_" + java.lang.String.format(policyFileName) + "." + version + ".xml"; + } + } + if (fileName != null) { + newFile = Paths.get(parentPath.toString(), fileName); + } + if (Files.notExists(newFile)) { + return newFile; + } + return null; + } + + + //create policy once all the validations are completed + protected Map createPolicy(final Path policyPath, final Object policyData) { + Map success = new HashMap(); + // + // Is the root a PolicySet or Policy? + // + + if (policyData instanceof PolicyType) { + // + // Write it out + // + //Does not need to be XACMLPolicyWriterWithPapNotify since it is already in the PAP + //and this transaction is intercepted up stream. + InputStream inputStream = XACMLPolicyWriter.getXmlAsInputStream((PolicyType) policyData); + try { + PolicyDef policyDef = DOMPolicyDef.load(inputStream); + if (policyDef != null) { + //This is does not need to be XACMLPolicyWriterWithPapNotification since it is already in the PAP + //and the transaction was intercepted up stream + finalPolicyPath = XACMLPolicyWriter.writePolicyFile(policyPath, (PolicyType) policyData); + this.setFinalPolicyPath(finalPolicyPath); + } else{ + success.put("validation", "PolicyDef Validation Failed"); + } + } catch (Exception e) { + success.put("error", "Validation Failed"); + } + + } else { + //TODO:EELF Cleanup - Remove logger + //logger.error("Unknown data type sent back."); + PolicyLogger.error("Unknown data type sent back."); + return success; + } + // + // Did it get written? + // + if (finalPolicyPath == null || !Files.exists(finalPolicyPath)) { + //TODO:EELF Cleanup - Remove logger + //logger.error("Failed to write policy file."); + PolicyLogger.error("Failed to write policy file."); + return success; + } + try { + success.put("success", "success"); + } finally { + // vaadin framework will handle exception. + } + return success; + } + + public static String getConfigHome(){ + try { + loadWebapps(); + } catch (Exception e) { + return null; + } + return configHome; + } + + public static String getActionHome(){ + try { + loadWebapps(); + } catch (Exception e) { + return null; + } + return actionHome; + } + + private static void loadWebapps() throws Exception{ + if(actionHome == null || configHome == null){ + Path webappsPath = Paths.get(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_WEBAPPS)); + //Sanity Check + if (webappsPath == null) { + //TODO:EELF Cleanup - Remove logger + //logger.error("Invalid Webapps Path Location property : " + XACMLRestProperties.PROP_PAP_WEBAPPS); + PolicyLogger.error("Invalid Webapps Path Location property : " + XACMLRestProperties.PROP_PAP_WEBAPPS); + throw new Exception("Invalid Webapps Path Location property : " + XACMLRestProperties.PROP_PAP_WEBAPPS); + } + Path webappsPathConfig; + Path webappsPathAction; + if(webappsPath.toString().contains("\\")) + { + webappsPathConfig = Paths.get(webappsPath.toString()+"\\Config"); + webappsPathAction = Paths.get(webappsPath.toString()+"\\Action"); + } + else + { + webappsPathConfig = Paths.get(webappsPath.toString()+"/Config"); + webappsPathAction = Paths.get(webappsPath.toString()+"/Action"); + } + if (Files.notExists(webappsPathConfig)) + { + try { + Files.createDirectories(webappsPathConfig); + } catch (IOException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Failed to create config directory: " + //+ webappsPathConfig.toAbsolutePath().toString(), e); + PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "Policy", "Failed to create config directory"); + } + } + if (Files.notExists(webappsPathAction)) + { + try { + Files.createDirectories(webappsPathAction); + } catch (IOException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Failed to create config directory: " + //+ webappsPathAction.toAbsolutePath().toString(), e); + PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "Policy", "Failed to create config directory"); + } + } + actionHome = webappsPathAction.toString(); + configHome = webappsPathConfig.toString(); + } + } + + protected String getParentPathSubScopeDir() { + + final Path gitPath = Paths.get(policyAdapter.getUserGitPath().toString()); + String policyDir = policyAdapter.getParentPath().toString(); + int startIndex = policyDir.indexOf(gitPath.toString()) + gitPath.toString().length() + 1; + policyDir = policyDir.substring(startIndex, policyDir.length()); + + return policyDir; + } + + + public boolean validateConfigForm() { + // TODO Auto-generated method stub + return true; + } + + /** + * @return the preparedToSave + */ + public boolean isPreparedToSave() { + return preparedToSave; + } + + /** + * @param preparedToSave the preparedToSave to set + */ + protected void setPreparedToSave(boolean preparedToSave) { + this.preparedToSave = preparedToSave; + } + + public boolean isPolicyExists() { + return policyExists; + } + + public void setPolicyExists(boolean policyExists) { + this.policyExists = policyExists; + } + + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/PolicyDBDao.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/PolicyDBDao.java new file mode 100644 index 000000000..bdd7534d8 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/PolicyDBDao.java @@ -0,0 +1,3936 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.components; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.io.StringReader; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.ProtocolException; +import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.nio.file.InvalidPathException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.security.Key; +import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.Base64; +import java.util.Calendar; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Set; +import java.util.UUID; + +import javax.crypto.Cipher; +import javax.crypto.spec.SecretKeySpec; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.LockModeType; +import javax.persistence.PersistenceException; +import javax.persistence.Query; +import javax.persistence.RollbackException; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathFactory; + +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.FilenameUtils; +import org.apache.commons.io.IOUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openecomp.policy.pap.xacml.rest.XACMLPapServlet; +import org.openecomp.policy.pap.xacml.rest.adapters.PolicyRestAdapter; +import org.openecomp.policy.rest.XACMLRestProperties; +import org.openecomp.policy.rest.jpa.ActionBodyEntity; +import org.openecomp.policy.rest.jpa.ConfigurationDataEntity; +import org.openecomp.policy.rest.jpa.DatabaseLockEntity; +import org.openecomp.policy.rest.jpa.GroupEntity; +import org.openecomp.policy.rest.jpa.PdpEntity; +import org.openecomp.policy.rest.jpa.PolicyDBDaoEntity; +import org.openecomp.policy.rest.jpa.PolicyEntity; +import org.openecomp.policy.rest.jpa.PolicyVersion; +import org.openecomp.policy.rest.util.Webapps; +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.eelf.PolicyLogger; + +import org.xml.sax.InputSource; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; +import org.openecomp.policy.xacml.api.pap.EcompPDP; +import org.openecomp.policy.xacml.api.pap.EcompPDPGroup; +import org.openecomp.policy.xacml.api.pap.PAPPolicyEngine; + +import com.att.research.xacml.api.pap.PAPEngine; +import com.att.research.xacml.api.pap.PAPException; +import com.att.research.xacml.api.pap.PDP; +//import com.att.research.xacml.api.pap.PDPGroup; +import com.att.research.xacml.api.pap.PDPPolicy; +import org.openecomp.policy.xacml.std.pap.StdPDPGroup; +import org.openecomp.policy.xacml.std.pap.StdPDPPolicy; +import org.openecomp.policy.xacml.util.XACMLPolicyScanner; +import org.openecomp.policy.xacml.util.XACMLPolicyWriter; +import com.att.research.xacml.util.XACMLProperties; + +import org.w3c.dom.Document; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +public class PolicyDBDao { + private static final Logger logger = FlexLogger.getLogger(PolicyDBDao.class); + private List otherServers; + private EntityManagerFactory emf; + private static PolicyDBDao currentInstance = null; + private PAPPolicyEngine papEngine; + + public static final String JSON_CONFIG = "JSON"; + public static final String XML_CONFIG = "XML"; + public static final String PROPERTIES_CONFIG = "PROPERTIES"; + public static final String OTHER_CONFIG = "OTHER"; + public static final String AUDIT_USER = "audit"; + + /** + * Get an instance of a PolicyDBDao. It creates one if it does not exist. + * Only one instance is allowed to be created per server. + * @param emf The EntityFactoryManager to be used for database connections + * @return The new instance of PolicyDBDao or throw exception if the given emf is null. + * @throws IllegalStateException if a PolicyDBDao has already been constructed. Call getPolicyDBDaoInstance() to get this. + */ + public static PolicyDBDao getPolicyDBDaoInstance(EntityManagerFactory emf) throws Exception{ + logger.debug("getPolicyDBDaoInstance(EntityManagerFactory emf) as getPolicyDBDaoInstance("+emf+") called"); + if(currentInstance == null){ + if(emf != null){ + currentInstance = new PolicyDBDao(emf); + return currentInstance; + } + throw new IllegalStateException("The EntityManagerFactory is Null"); + } + return currentInstance; + } + + /** + * Gets the current instance of PolicyDBDao. + * @return The instance of PolicyDBDao or throws exception if the given instance is null. + * @throws IllegalStateException if a PolicyDBDao instance is null. Call createPolicyDBDaoInstance(EntityManagerFactory emf) to get this. + */ + public static PolicyDBDao getPolicyDBDaoInstance() throws Exception{ + logger.debug("getPolicyDBDaoInstance() as getPolicyDBDaoInstance() called"); + if(currentInstance != null){ + return currentInstance; + } + throw new IllegalStateException("The PolicyDBDao.currentInstance is Null. Use getPolicyDBDao(EntityManagerFactory emf)"); + } + public void setPapEngine(PAPPolicyEngine papEngine2){ + this.papEngine = (PAPPolicyEngine) papEngine2; + } + private PolicyDBDao(EntityManagerFactory emf){ + logger.debug("PolicyDBDao(EntityManagerFactory emf) as PolicyDBDao("+emf+") called"); + this.emf = emf; + + //not needed in this release + if(!register()){ + //TODO:EELF Cleanup - Remove logger + //logger.error("This server's PolicyDBDao instance could not be registered and may not reveive updates"); + PolicyLogger.error("This server's PolicyDBDao instance could not be registered and may not reveive updates"); + } + + otherServers = getRemotePolicyDBDaoList(); + if(logger.isDebugEnabled()){ + logger.debug("Number of remote PolicyDBDao instances: "+otherServers.size()); + } + if(otherServers.size() < 1){ + logger.warn("List of PolicyDBDao servers is empty or could not be retrieved"); + } + //otherServers = new LinkedList(); + //otherServers.add((Object)"http://localhost:8071/pap/"); + } + + //not static because we are going to be using the instance's emf + //waitTime in ms to wait for lock, or -1 to wait forever (no) + private void startTransactionSynced(EntityManager entityMgr,int waitTime){ + logger.debug("\n\nstartTransactionSynced(EntityManager entityMgr,int waitTime) as " + + "\n startTransactionSynced("+entityMgr+","+waitTime+") called\n\n"); + DatabaseLockEntity lock = null; + + entityMgr.setProperty("javax.persistence.query.timeout", waitTime); + entityMgr.getTransaction().begin(); + + if(logger.isDebugEnabled()){ + Map properties = entityMgr.getProperties(); + logger.debug("\n\nstartTransactionSynced():" + + "\n entityManager.getProperties() = " + properties + + "\n\n"); + } + try{ + if(logger.isDebugEnabled()){ + logger.debug("\n\nstartTransactionSynced():" + + "\n ATTEMPT to get the DB lock" + + "\n\n"); + } + lock = entityMgr.find(DatabaseLockEntity.class, 1, LockModeType.PESSIMISTIC_WRITE); + if(logger.isDebugEnabled()){ + logger.debug("\n\nstartTransactionSynced():" + + "\n GOT the DB lock" + + "\n\n"); + } + } catch(Exception e){ + System.out.println("Could not get lock entity"); + e.printStackTrace(); + } + if(lock == null){ + throw new IllegalStateException("The lock row does not exist in the table. Please create a primary key with value = 1."); + } + + } + /** + * Gets the list of other registered PolicyDBDaos from the database + * @return List (type PolicyDBDaoEntity) of other PolicyDBDaos + */ + private List getRemotePolicyDBDaoList(){ + logger.debug("getRemotePolicyDBDaoList() as getRemotePolicyDBDaoList() called"); + List policyDBDaoEntityList = new LinkedList(); + EntityManager em = emf.createEntityManager(); + startTransactionSynced(em, 1000); + try{ + Query getPolicyDBDaoEntityQuery = em.createNamedQuery("PolicyDBDaoEntity.findAll"); + policyDBDaoEntityList = getPolicyDBDaoEntityQuery.getResultList(); + + } catch(Exception e){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Caught Exception on: getPolicyDBDaoEntityQuery.getResultList()",e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Exception querying for other registered PolicyDBDaos"); + logger.warn("List of remote PolicyDBDaos will be empty"); + } + try{ + em.getTransaction().commit(); + } catch(Exception e){ + try{ + em.getTransaction().rollback(); + } catch(Exception e2){ + + } + } + em.close(); + return policyDBDaoEntityList; + } + + public PolicyDBDaoTransaction getNewTransaction(){ + logger.debug("getNewTransaction() as getNewTransaction() called"); + return (PolicyDBDaoTransaction)(new PolicyDBDaoTransactionInstance()); + } + + /* + * Because the normal transactions are not used in audits, we can use the same transaction + * mechanism to get a transaction and obtain the emlock and the DB lock. We just need to + * provide different transaction timeout values in ms because the audit will run longer + * than normal transactions. + */ + public PolicyDBDaoTransaction getNewAuditTransaction(){ + logger.debug("getNewAuditTransaction() as getNewAuditTransaction() called"); + //Use the standard transaction wait time in ms + int auditWaitMs = Integer.parseInt(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_TRANS_WAIT)); + //Use the (extended) audit timeout time in ms + int auditTimeoutMs = Integer.parseInt(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_AUDIT_TIMEOUT)); + return (PolicyDBDaoTransaction)(new PolicyDBDaoTransactionInstance(auditTimeoutMs, auditWaitMs)); + } + + + /** + * Checks if two strings are equal. Null strings ARE allowed. + * @param one A String or null to compare + * @param two A String or null to compare + */ + private static boolean stringEquals(String one, String two){ + logger.debug("stringEquals(String one, String two) as stringEquals("+one+", "+two+") called"); + if(one == null && two == null){ + return true; + } + if(one == null || two == null){ + return false; + } + return one.equals(two); + } + + /** + * Computes the scope in dotted format based on an absolute path and a path that divides the scope. + * @param fullPath An absolute path including scope folders and other folders(does not have to be absolute, must just contain scope and other folders before) + * @param pathToExclude The path that acts as a division between the scope and the other folders + * @return The scope in dotted format (org.openecomp) + */ + private static String computeScope(String fullPath, String pathToExclude){ + logger.debug("computeScope(String fullPath, String pathToExclude) as computeScope("+fullPath+", "+pathToExclude+") called"); + int excludeIndex = fullPath.indexOf(pathToExclude); + String scopePath = fullPath.substring(excludeIndex+pathToExclude.length()); + String scope = scopePath.replace('\\', '.'); + scope = scope.replace('/', '.'); + if(scope.charAt(0) == '.'){ + scope = scope.substring(1); + } + if(scope.charAt(scope.length()-1) == '.'){ + scope = scope.substring(0, scope.length()-1); + } + return scope; + } + + /** + * Returns the url of this local pap server, removing the username and password, if they are present + * @return The url of this local pap server + */ + private String[] getPapUrlUserPass(){ + logger.debug("getPapUrl() as getPapUrl() called"); + String url = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_URL); + if(url == null){ + return null; + } + return splitPapUrlUserPass(url); + + + } + private String[] splitPapUrlUserPass(String url){ + String[] urlUserPass = new String[3]; + String[] commaSplit = url.split(","); + urlUserPass[0] = commaSplit[0]; + if(commaSplit.length > 2){ + urlUserPass[1] = commaSplit[1]; + urlUserPass[2] = commaSplit[2]; + } + if(urlUserPass[1] == null || urlUserPass[1].equals("")){ + String usernamePropertyValue = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_USERID); + if(usernamePropertyValue != null){ + urlUserPass[1] = usernamePropertyValue; + } + } + if(urlUserPass[2] == null || urlUserPass[2].equals("")){ + String passwordPropertyValue = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_PASS); + if(passwordPropertyValue != null){ + urlUserPass[2] = passwordPropertyValue; + } + } + //if there is no comma, for some reason there is no username and password, so don't try to cut them off + return urlUserPass; + } + + private static String encryptPassword(String password) throws Exception{ + Cipher cipher = Cipher.getInstance("AES"); + cipher.init(Cipher.ENCRYPT_MODE, aesKey()); + byte[] encryption = cipher.doFinal(password.getBytes("UTF-8")); + System.out.println(encryption); + return new String(Base64.getMimeEncoder().encode(encryption),"UTF-8"); + } + + private static String decryptPassword(String encryptedPassword) throws Exception{ + Cipher cipher = Cipher.getInstance("AES"); + cipher.init(Cipher.DECRYPT_MODE, aesKey()); + byte[] password = cipher.doFinal(Base64.getDecoder().decode(encryptedPassword.getBytes("UTF-8"))); + return new String(password,"UTF-8"); + } + private static Key aesKey(){ + byte[] aesValue = (new String("njrmbklcxtoplawf")).getBytes(); + return new SecretKeySpec(aesValue,"AES"); + } + /** + * Register the PolicyDBDao instance in the PolicyDBDaoEntity table + * @return Boolean, were we able to register? + */ + private boolean register(){ + logger.debug("register() as register() called"); + String[] url = getPapUrlUserPass(); + EntityManager em = emf.createEntityManager(); + try{ + startTransactionSynced(em, 1000); + } catch(IllegalStateException e){ + logger.debug ("\nPolicyDBDao.register() caught an IllegalStateException: \n" +e + "\n"); + DatabaseLockEntity lock; + lock = em.find(DatabaseLockEntity.class, 1); + if(lock==null){ + lock = new DatabaseLockEntity(); + em.persist(lock); + lock.setKey(1); + try{ + em.flush(); + em.getTransaction().commit(); + em.close(); + } catch(Exception e2){ + //TODO:EELF Cleanup - Remove logger + //logger.error("COULD NOT CREATE DATABASELOCK ROW. WILL TRY ONE MORE TIME \n\n Exception: \n" + e2); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e2, "PolicyDBDao", "COULD NOT CREATE DATABASELOCK ROW. WILL TRY ONE MORE TIME"); + e2.printStackTrace(); + } + em = null; + em = emf.createEntityManager(); + try{ + startTransactionSynced(em, 1000); + } catch(Exception e3){ + //still not working + String msg = "DATABASE LOCKING NOT WORKING. CONCURRENCY CONTROL NOT WORKING"; + //TODO:EELF Cleanup - Remove logger + //logger.error(msg); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e3, "PolicyDBDao", msg); + throw new IllegalStateException("msg" + "\n" + e3); + } + } + } + logger.debug("\nPolicyDBDao.register. Database locking and concurrency control is initialized\n"); + PolicyDBDaoEntity foundPolicyDBDaoEntity = em.find(PolicyDBDaoEntity.class, url[0]); + Query getPolicyDBDaoEntityQuery = em.createQuery("SELECT e FROM PolicyDBDaoEntity e WHERE e.policyDBDaoUrl=:url"); + getPolicyDBDaoEntityQuery.setParameter("url", url[0]); + if(foundPolicyDBDaoEntity == null){ + //em.getTransaction().begin(); + PolicyDBDaoEntity newPolicyDBDaoEntity = new PolicyDBDaoEntity(); + em.persist(newPolicyDBDaoEntity); + newPolicyDBDaoEntity.setPolicyDBDaoUrl(url[0]); + newPolicyDBDaoEntity.setDescription("PAP server at "+url[0]); + newPolicyDBDaoEntity.setUsername(url[1]); + try{ + newPolicyDBDaoEntity.setPassword(encryptPassword(url[2])); + } catch(Exception e){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Could not encrypt PAP password",e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Could not encrypt PAP password"); + } + /* + try{ + em.getTransaction().commit(); + } catch(RollbackException e){ + logger.error("Caught RollbackException during PolicyDBDao Registration on: em.getTransaction().commit()",e); + em.close(); + return false; + } catch(Exception e2){ + logger.error("Caught Exception during PolicyDBDao Registration on: em.getTransaction().commit()",e2); + em.close(); + return false; + } + */ + try{ + em.getTransaction().commit(); + } catch(Exception e){ + try{ + em.getTransaction().rollback(); + } catch(Exception e2){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Could not add new PolicyDBDao to the database",e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e2, "PolicyDBDao", "Could not add new PolicyDBDao to the database"); + } + } + } else { + //em.getTransaction().begin(); + //just want to update in order to change modified date + String encryptedPassword = null; + try{ + encryptedPassword = encryptPassword(url[2]); + } catch(Exception e){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Could not encrypt PAP password",e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Could not encrypt PAP password"); + } + if(url[1] != null && !stringEquals(url[1], foundPolicyDBDaoEntity.getUsername())){ + foundPolicyDBDaoEntity.setUsername(url[1]); + } + if(encryptedPassword != null && !stringEquals(encryptedPassword, foundPolicyDBDaoEntity.getPassword())){ + foundPolicyDBDaoEntity.setPassword(encryptedPassword); + } + foundPolicyDBDaoEntity.preUpdate(); + try{ + em.getTransaction().commit(); + } catch(Exception e){ + try{ + em.getTransaction().rollback(); + } catch(Exception e2){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Could not update PolicyDBDao in the database",e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e2, "PolicyDBDao", "Could not update PolicyDBDao in the database"); + } + } + /* + try{ + em.getTransaction().commit(); + } catch(RollbackException e){ + logger.error("Caught RollbackException during PolicyDBDao Registration on: em.getTransaction().commit()",e); + em.close(); + return false; + } catch(Exception e2){ + logger.error("Caught Exception during PolicyDBDao Registration on: em.getTransaction().commit()",e2); + em.getTransaction().rollback(); + return false; + } + */ + } + em.close(); + logger.debug("\nPolicyDBDao.register(). Success!!\n"); + return true; + } + public void notifyOthers(long entityId,String entityType){ + notifyOthers(entityId,entityType,null); + } + public void notifyOthers(long entityId, String entityType, String newGroupId){ + logger.debug("notifyOthers(long entityId, String entityType, long newGroupId) as notifyOthers("+entityId+","+entityType+","+newGroupId+") called"); + LinkedList notifyThreads = new LinkedList(); + + //we're going to run notiftions in parellel threads to speed things up + for(Object obj : otherServers){ + + Thread newNotifyThread = new Thread(new NotifyOtherThread(obj, entityId, entityType, newGroupId)); + + newNotifyThread.start(); + + notifyThreads.add(newNotifyThread); + + } + //we want to wait for all notifications to complete or timeout before we unlock the interface and allow more changes + for(Thread t : notifyThreads){ + try { + t.join(); + } catch (Exception e) { + logger.warn("Could not join a notifcation thread"); + } + } + + + } + + private class NotifyOtherThread implements Runnable { + public NotifyOtherThread(Object obj, long entityId, String entityType, String newGroupId){ + this.obj = obj; + this.entityId = entityId; + this.entityType = entityType; + this.newGroupId = newGroupId; + } + private Object obj; + private long entityId; + private String entityType; + private String newGroupId; + @Override + public void run(){ + //naming of 'o' is for backwards compatibility with the rest of the function + PolicyDBDaoEntity dbdEntity = (PolicyDBDaoEntity)obj; + String o = dbdEntity.getPolicyDBDaoUrl(); + String username = dbdEntity.getUsername(); + String password; + try{ + password = decryptPassword(dbdEntity.getPassword()); + } catch(Exception e){ + //if we can't decrypt, might as well try it anyway + password = dbdEntity.getPassword(); + } + Base64.Encoder encoder = Base64.getEncoder(); + String encoding = encoder.encodeToString((username+":"+password).getBytes(StandardCharsets.UTF_8)); + HttpURLConnection connection = null; + UUID requestID = UUID.randomUUID(); + //loggingContext.setRequestID(requestID.toString()); + //loggingContext.transactionStarted(); + URL url; + try { + String papUrl = getPapUrlUserPass()[0]; + if(papUrl == null){ + papUrl = "undefined"; + } + logger.debug("We are going to try to notify "+o); + //is this our own url? + String ourUrl = o; + try{ + ourUrl = splitPapUrlUserPass((String)o)[0]; + }catch(Exception e){ + ourUrl = o; + } + if(o == null){ + o = "undefined"; + } + if(papUrl.equals(ourUrl)){ + logger.debug(((String)o)+" is our url, skipping notify"); + return; + } + if(newGroupId == null){ + url = new URL(((String)o)+"?policydbdaourl="+papUrl+"&entityid="+entityId+"&entitytype="+entityType); + } else { + url = new URL(((String)o)+"?policydbdaourl="+papUrl+"&entityid="+entityId+"&entitytype="+entityType+"&extradata="+newGroupId); + } + } catch (MalformedURLException e) { + logger.warn("Caught MalformedURLException on: new URL()", e); + return; + } + // + // Open up the connection + // + logger.debug("Connecting with url: "+url); + try { + connection = (HttpURLConnection)url.openConnection(); + } catch (Exception e) { + logger.warn("Caught exception on: url.openConnection()",e); + return; + } + // + // Setup our method and headers + // + try { + connection.setRequestMethod("PUT"); + } catch (ProtocolException e) { + //why would this error ever occur? + logger.warn("Caught ProtocolException on connection.setRequestMethod(\"PUT\");",e); + return; + } + connection.setRequestProperty("Authorization", "Basic " + encoding); + connection.setRequestProperty("Accept", "text/x-java-properties"); + connection.setRequestProperty("Content-Type", "text/x-java-properties"); + connection.setRequestProperty("requestID", requestID.toString()); + int readTimeout; + try{ + readTimeout = Integer.parseInt(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_NOTIFY_TIMEOUT)); + + } catch(Exception e){ + logger.error("xacml.rest.pap.notify.timeoutms property not set, using a default."); + readTimeout = 10000; + } + connection.setReadTimeout(readTimeout); + connection.setConnectTimeout(readTimeout); + connection.setUseCaches(false); + // + // Adding this in. It seems the HttpUrlConnection class does NOT + // properly forward our headers for POST re-direction. It does so + // for a GET re-direction. + // + // So we need to handle this ourselves. + // + connection.setInstanceFollowRedirects(false); + connection.setDoOutput(true); + connection.setDoInput(true); + try { + connection.connect(); + } catch (Exception e) { + logger.warn("Caught exception on: connection.connect()",e); + return; + } + try { + if (connection.getResponseCode() == 200) { + logger.info("Received response 200 from pap server on notify"); + //notified = true; + } else { + logger.warn("connection response code not 200, received: "+connection.getResponseCode()); + } + } catch (Exception e) { + logger.warn("Caught Exception on: connection.getResponseCode() ", e); + } + + + connection.disconnect(); + } + } + + private static String getElementFromXMLString(String element, String xml) { + InputSource source = new InputSource(new StringReader(xml)); + + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + String description = ""; + try{ + DocumentBuilder db = dbf.newDocumentBuilder(); + Document document = db.parse(source); + + XPathFactory xpathFactory = XPathFactory.newInstance(); + XPath xpath = xpathFactory.newXPath(); + + if (element.endsWith("/")){ + element = element.substring(0, element.length() -1); + } + + description = xpath.evaluate("/Policy" + element + "/text()", document); + }catch(Exception e){ + + } + + + System.out.println("description_" + description); + return description; + } + private static String evaluateXPath(String expression, String xml) { + InputSource source = new InputSource(new StringReader(xml)); + + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + String description = ""; + try{ + DocumentBuilder db = dbf.newDocumentBuilder(); + Document document = db.parse(source); + + XPathFactory xpathFactory = XPathFactory.newInstance(); + XPath xpath = xpathFactory.newXPath(); + + + description = xpath.evaluate(expression, document); + }catch(Exception e){ + + } + + + System.out.println("description_" + description); + return description; + } + + private static String getDescriptionFromXacml(String xacmlData){ + //FIXME completely untested. Probably not a good idea to use. UPDATE: kind of tested + String openTag = ""; + String closeTag = ""; + int descIndex = xacmlData.indexOf(openTag); + int endDescIndex = xacmlData.indexOf(closeTag); + String desc = xacmlData.substring(descIndex+openTag.length(),endDescIndex); + return desc; + } + private final String POLICY_NOTIFICATION = "policy"; + private final String PDP_NOTIFICATION = "pdp"; + private final String GROUP_NOTIFICATION = "group"; + public void handleIncomingHttpNotification(String url, String entityId, String entityType, String extraData, XACMLPapServlet xacmlPapServlet){ + logger.info("DBDao url: " + url + " has reported an update on "+entityType+" entity "+entityId); + PolicyDBDaoTransaction transaction = this.getNewTransaction(); + switch(entityType){ + + case POLICY_NOTIFICATION: + try{ + handleIncomingPolicyChange(url, entityId,extraData); + } catch(Exception e){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Caught exception on handleIncomingPolicyChange("+url+", "+entityId+", "+extraData+")",e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Caught exception on handleIncomingPolicyChange("+url+", "+entityId+", "+extraData+")"); + } + break; + case PDP_NOTIFICATION: + try{ + handleIncomingPdpChange(url, entityId, transaction); + } catch(Exception e){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Caught exception on handleIncomingPdpChange("+url+", "+entityId+", "+transaction+")",e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Caught exception on handleIncomingPdpChange("+url+", "+entityId+", "+transaction+")"); + } + break; + case GROUP_NOTIFICATION: + try{ + handleIncomingGroupChange(url, entityId, extraData, transaction, xacmlPapServlet); + }catch(Exception e){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Caught exception on handleIncomingGroupChange("+url+", "+entityId+", "+extraData+", "+transaction+", "+xacmlPapServlet+")",e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Caught exception on handleIncomingGroupChange("+url+", "+entityId+", "+extraData+", "+transaction+", "+xacmlPapServlet+")"); + } + break; + } + //no changes should be being made in this function, we still need to close + transaction.rollbackTransaction(); + } + private void handleIncomingGroupChange(String url, String groupId, String extraData,PolicyDBDaoTransaction transaction,XACMLPapServlet xacmlPapServlet) throws PAPException{ + + GroupEntity groupRecord = null; + long groupIdLong = -1; + try{ + groupIdLong = Long.parseLong(groupId); + } catch(NumberFormatException e){ + throw new IllegalArgumentException("groupId "+groupId+" cannot be parsed into a long"); + } + try{ + groupRecord = transaction.getGroup(groupIdLong); + } catch(Exception e){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Caught Exception trying to get pdp group record with transaction.getGroup("+groupIdLong+");",e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Caught Exception trying to get pdp group record with transaction.getGroup("+groupIdLong+");"); + throw new PAPException("Could not get local group "+groupIdLong); + } + if(groupRecord == null){ + throw new PersistenceException("The group record returned is null"); + } + //compare to local fs + //does group folder exist + EcompPDPGroup localGroup = null; + try { + localGroup = papEngine.getGroup(groupRecord.getGroupId()); + } catch (Exception e) { + logger.warn("Caught PAPException trying to get local pdp group with papEngine.getGroup("+groupId+");",e); + //throw new PAPException("Could not get local group "+groupId); + } + if(localGroup == null && extraData != null){ + //here we can try to load an old group id from the extraData + try{ + localGroup = papEngine.getGroup(extraData); + }catch(Exception e){ + logger.warn("Caught PAPException trying to get local pdp group with papEngine.getGroup("+extraData+");",e); + } + } + if(localGroup != null && groupRecord.isDeleted()){ + EcompPDPGroup newLocalGroup = null; + if(extraData != null){ + try { + newLocalGroup = papEngine.getGroup(extraData); + } catch (PAPException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error("Caught PAPException trying to get new pdp group with papEngine.getGroup("+extraData+");",e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Caught PAPException trying to get new pdp group with papEngine.getGroup("+extraData+");"); + //throw new PAPException("Could not get new local group "+newGroupId); + + } + } + try { + papEngine.removeGroup(localGroup, newLocalGroup); + } catch (NullPointerException | PAPException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error("Caught PAPException trying to get remove pdp group with papEngine.removeGroup("+localGroup+", "+newLocalGroup+");",e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Caught PAPException trying to get remove pdp group with papEngine.removeGroup("+localGroup+", "+newLocalGroup+");"); + throw new PAPException("Could not remove group "+groupId); + } + } + else if(localGroup == null){ + //creating a new group + try { + papEngine.newGroup(groupRecord.getgroupName(), groupRecord.getDescription()); + } catch (NullPointerException | PAPException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error("Caught PAPException trying to create pdp group with papEngine.newGroup(groupRecord.getgroupName(), groupRecord.getDescription());",e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Caught PAPException trying to create pdp group with papEngine.newGroup(groupRecord.getgroupName(), groupRecord.getDescription());"); + throw new PAPException("Could not create group "+groupRecord); + } + try { + localGroup = papEngine.getGroup(groupRecord.getGroupId()); + } catch (PAPException e1) { + //TODO:EELF Cleanup - Remove logger + //logger.error("Caught PAPException trying to get pdp group we just created with papEngine.getGroup(groupRecord.getGroupId());\nAny PDPs or policies in the new group may not have been added",e1); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e1, "PolicyDBDao", "Caught PAPException trying to get pdp group we just created with papEngine.getGroup(groupRecord.getGroupId());\nAny PDPs or policies in the new group may not have been added"); + return; + //throw new PAPException("Could not get group "+groupRecord); + } + //add possible pdps to group + List pdpsInGroup = transaction.getPdpsInGroup(Long.parseLong(groupRecord.getGroupId())); + for(Object pdpO : pdpsInGroup){ + PdpEntity pdp = (PdpEntity)pdpO; + try { + papEngine.newPDP(pdp.getPdpId(), localGroup, pdp.getPdpName(), pdp.getDescription(), pdp.getJmxPort()); + } catch (NullPointerException | PAPException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error("Caught PAPException trying to get create pdp with papEngine.newPDP(pdp.getPdpId(), localGroup, pdp.getPdpName(), pdp.getDescription(), pdp.getJmxPort());",e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Caught PAPException trying to get create pdp with papEngine.newPDP(pdp.getPdpId(), localGroup, pdp.getPdpName(), pdp.getDescription(), pdp.getJmxPort());"); + throw new PAPException("Could not create pdp "+pdp); + } + } + //add possible policies to group (filesystem only, apparently) + } else { + if(!(localGroup instanceof StdPDPGroup)){ + throw new PAPException("group is not a StdPDPGroup"); + } + //clone the object + //because it will be comparing the new group to its own version + StdPDPGroup localGroupClone = new StdPDPGroup(localGroup.getId(),localGroup.isDefaultGroup(),localGroup.getName(),localGroup.getDescription(),((StdPDPGroup)localGroup).getDirectory()); + localGroupClone.setEcompPdps(localGroup.getEcompPdps()); + localGroupClone.setPipConfigs(localGroup.getPipConfigs()); + localGroupClone.setStatus(localGroup.getStatus()); + //we are updating a group or adding a policy or changing default + //set default if it should be + if(!localGroupClone.isDefaultGroup() && groupRecord.isDefaultGroup()){ + try { + papEngine.SetDefaultGroup(localGroup); + return; + } catch (PAPException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error("Caught PAPException trying to set default group with papEngine.SetDefaultGroup("+localGroupClone+");",e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Caught PAPException trying to set default group with papEngine.SetDefaultGroup("+localGroupClone+");"); + throw new PAPException("Could not set default group to "+localGroupClone); + } + } + boolean needToUpdate = false; + if(updateGroupPoliciesInFileSystem(localGroupClone,localGroup, groupRecord, transaction)){ + needToUpdate = true; + } + if(!stringEquals(localGroupClone.getId(),groupRecord.getGroupId()) || !stringEquals(localGroupClone.getName(),groupRecord.getgroupName())){ + //changing ids + //we do not want to change the id, the papEngine will do this for us, it needs to know the old id + localGroupClone.setName(groupRecord.getgroupName()); + needToUpdate = true; + } + if(!stringEquals(localGroupClone.getDescription(),groupRecord.getDescription())){ + localGroupClone.setDescription(groupRecord.getDescription()); + needToUpdate = true; + } + if(needToUpdate){ + try { + + papEngine.updateGroup(localGroupClone); + } catch (PAPException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error("Caught PAPException trying to update group with papEngine.updateGroup("+localGroupClone+");",e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Caught PAPException trying to update group with papEngine.updateGroup("+localGroupClone+");"); + throw new PAPException("Could not update group "+localGroupClone); + } + } + + } + //call command that corresponds to the change that was made + } + //this will also handle removes, since incoming pdpGroup has no policies internally, we are just going to add them all in from the db + private boolean updateGroupPoliciesInFileSystem(EcompPDPGroup pdpGroup,EcompPDPGroup oldPdpGroup, GroupEntity groupRecord, PolicyDBDaoTransaction transaction) throws PAPException{ + if(!(pdpGroup instanceof StdPDPGroup)){ + throw new PAPException("group is not a StdPDPGroup"); + } + StdPDPGroup group = (StdPDPGroup)pdpGroup; + //this must always be true since we don't explicitly know when a delete is occuring + boolean didUpdate = true; + HashMap currentPolicySet = new HashMap(oldPdpGroup.getPolicies().size()); + HashSet newPolicySet = new HashSet(); + for(PDPPolicy pdpPolicy : oldPdpGroup.getPolicies()){ + currentPolicySet.put(pdpPolicy.getId(), pdpPolicy); + } + for(PolicyEntity policy : groupRecord.getPolicies()){ + String pdpPolicyName = getPdpPolicyName(policy.getPolicyName(), policy.getScope()); + if(group.getPolicy(pdpPolicyName) == null){ + didUpdate = true; + if(currentPolicySet.containsKey(pdpPolicyName)){ + newPolicySet.add(currentPolicySet.get(pdpPolicyName)); + } else{ + InputStream policyStream = new ByteArrayInputStream(policy.getPolicyData().getBytes()); + group.copyPolicyToFile(pdpPolicyName,policyStream); + ((StdPDPPolicy)(group.getPolicy(pdpPolicyName))).setName(removeExtensionAndVersionFromPolicyName(policy.getPolicyName())); + try { + policyStream.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + } + if(didUpdate){ + newPolicySet.addAll(group.getPolicies()); + group.setPolicies(newPolicySet); + } + return didUpdate; + + } + private String removeExtensionAndVersionFromPolicyName(String originalPolicyName){ + String policyName = originalPolicyName; + try{ + policyName = removeFileExtension(policyName); + policyName = policyName.substring(0,policyName.lastIndexOf('.')); + if(isNullOrEmpty(policyName)){ + throw new Exception(); + } + } catch(Exception e){ + policyName = originalPolicyName; + } + return policyName; + } + + private void handleIncomingPdpChange(String url, String pdpId, PolicyDBDaoTransaction transaction) throws PAPException{ + //get pdp + long pdpIdLong = -1; + try{ + pdpIdLong = Long.parseLong(pdpId); + }catch(NumberFormatException e){ + throw new IllegalArgumentException("pdpId "+pdpId+" cannot be parsed into a long"); + } + PdpEntity pdpRecord = null; + try{ + pdpRecord = transaction.getPdp(pdpIdLong); + }catch(Exception e){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Caught Exception trying to get pdp record with transaction.getPdp("+pdpIdLong+");",e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Caught Exception trying to get pdp record with transaction.getPdp("+pdpIdLong+");"); + throw new PAPException("Could not get local pdp "+pdpIdLong); + } + if(pdpRecord == null){ + throw new PersistenceException("The pdpRecord returned is null"); + } + PDP localPdp = null; + try { + localPdp = papEngine.getPDP(pdpRecord.getPdpId()); + } catch (PAPException e) { + logger.warn("Caught PAPException trying to get local pdp with papEngine.getPDP("+pdpId+");",e); + } + if(localPdp != null && pdpRecord.isDeleted()){ + try { + papEngine.removePDP((EcompPDP) localPdp); + } catch (PAPException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error("Caught PAPException trying to get remove pdp with papEngine.removePDP("+localPdp+");",e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Caught PAPException trying to get remove pdp with papEngine.removePDP("+localPdp+");"); + throw new PAPException("Could not remove pdp "+pdpId); + } + } + else if(localPdp == null){ + //add new pdp + //get group + + EcompPDPGroup localGroup = null; + try { + localGroup = papEngine.getGroup(pdpRecord.getGroup().getGroupId()); + } catch (PAPException e1) { + //TODO:EELF Cleanup - Remove logger + //logger.error("Caught PAPException trying to get local group to add pdp to with papEngine.getGroup(pdpRecord.getGroup().getGroupId());",e1); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e1, "PolicyDBDao", "Caught PAPException trying to get local group to add pdp to with papEngine.getGroup(pdpRecord.getGroup().getGroupId());"); + throw new PAPException("Could not get local group"); + } + try { + papEngine.newPDP(pdpRecord.getPdpId(), localGroup, pdpRecord.getPdpName(), pdpRecord.getDescription(), pdpRecord.getJmxPort()); + } catch (NullPointerException | PAPException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error("Caught PAPException trying to create pdp with papEngine.newPDP("+pdpRecord.getPdpId()+", "+localGroup+", "+pdpRecord.getPdpName()+", "+pdpRecord.getDescription()+", "+pdpRecord.getJmxPort()+");",e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Caught PAPException trying to create pdp with papEngine.newPDP("+pdpRecord.getPdpId()+", "+localGroup+", "+pdpRecord.getPdpName()+", "+pdpRecord.getDescription()+", "+pdpRecord.getJmxPort()+");"); + throw new PAPException("Could not create pdp "+pdpRecord); + } + } else { + boolean needToUpdate = false; + if(!stringEquals(localPdp.getId(),pdpRecord.getPdpId()) || !stringEquals(localPdp.getName(),pdpRecord.getPdpName())){ + //again, we don't want to change the id, the papEngine will do this + localPdp.setName(pdpRecord.getPdpName()); + needToUpdate = true; + } + if(!stringEquals(localPdp.getDescription(),pdpRecord.getDescription())){ + localPdp.setDescription(pdpRecord.getDescription()); + needToUpdate = true; + } + String localPdpGroupId = null; + try{ + localPdpGroupId = papEngine.getPDPGroup((EcompPDP) localPdp).getId(); + } catch(PAPException e){ + //could be null or something, just warn at this point + logger.warn("Caught PAPException trying to get id of local group that pdp is in with localPdpGroupId = papEngine.getPDPGroup(localPdp).getId();",e); + //throw new PAPException("Could not get local group"); + } + if(!stringEquals(localPdpGroupId,pdpRecord.getGroup().getGroupId())){ + EcompPDPGroup newPdpGroup = null; + try{ + newPdpGroup = papEngine.getGroup(pdpRecord.getGroup().getGroupId()); + }catch(PAPException e){ + //ok, now we have an issue. Time to stop things + //TODO:EELF Cleanup - Remove logger + //logger.error("Caught PAPException trying to get id of local group to move pdp to with papEngine.getGroup(pdpRecord.getGroup().getGroupId());",e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Caught PAPException trying to get id of local group to move pdp to with papEngine.getGroup(pdpRecord.getGroup().getGroupId());"); + throw new PAPException("Could not get local group"); + } + try{ + papEngine.movePDP((EcompPDP) localPdp, newPdpGroup); + }catch(PAPException e){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Caught PAPException trying to move pdp with papEngine.movePDP(localPdp, newPdpGroup);",e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Caught PAPException trying to move pdp with papEngine.movePDP(localPdp, newPdpGroup);"); + throw new PAPException("Could not move pdp "+localPdp); + } + } + if(((PdpEntity) localPdp).getJmxPort() != pdpRecord.getJmxPort()){ + ((PdpEntity) localPdp).setJmxPort(pdpRecord.getJmxPort()); + needToUpdate = true; + } + if(needToUpdate){ + try { + papEngine.updatePDP((EcompPDP) localPdp); + } catch (PAPException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error("Caught PAPException trying to update pdp with papEngine.updatePdp("+localPdp+");",e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Caught PAPException trying to update pdp with papEngine.updatePdp("+localPdp+");"); + throw new PAPException("Could not update pdp "+localPdp); + } + } + } + //compare to local situation + //call command to update + } + private void handleIncomingPolicyChange(String url, String policyId,String oldPathString){ + EntityManager em = emf.createEntityManager(); + Query getPolicyEntityQuery = em.createNamedQuery("PolicyEntity.FindById"); + getPolicyEntityQuery.setParameter("id", Long.valueOf(policyId)); + + @SuppressWarnings("unchecked") + List policies = getPolicyEntityQuery.getResultList(); + PolicyEntity policy = null; + if (policies.size() > 0){ + policy = policies.get(0); + } + + String policyRepo = buildPolicyScopeDirectory(policy); + + Path policyPath = Paths.get(policyRepo); + String action = "unknown action"; + try { + + if(policy.isDeleted()){ + logger.debug("Deleting Policy: " + policy.getPolicyName()); + action = "delete"; + Path newPath = Paths.get(policyPath.toString(), policy.getPolicyName()); + Files.deleteIfExists(newPath); + + Path subFile = null; + + if (policy.getConfigurationData()!= null){ + subFile = getPolicySubFile(policy.getConfigurationData().getConfigurationName(), "Config"); + }else if(policy.getActionBodyEntity()!= null){ + subFile = getPolicySubFile(policy.getActionBodyEntity().getActionBodyName(), "Action"); + } + + if(subFile != null){ + Files.deleteIfExists(subFile); + } + + }else{ + logger.debug("Updating/Creating Policy: " + policy.getPolicyName()); + action = "update"; + Files.createDirectories(policyPath); + Path newPath = Paths.get(policyPath.toString(), policy.getPolicyName()); + Files.deleteIfExists(newPath); + if(!isNullOrEmpty(oldPathString)){ + try{ + String[] scopeName = getScopeAndNameAndType(oldPathString); + Path oldPath = Paths.get(buildPolicyScopeDirectory(scopeName[0]),scopeName[1]); + Files.delete(oldPath.toAbsolutePath()); + }catch(Exception e){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Could not delete the old policy before rename: "+oldPathString,e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Could not delete the old policy before rename: "+oldPathString); + } + } + Object policyData = XACMLPolicyScanner.readPolicy(IOUtils.toInputStream(policy.getPolicyData())); + XACMLPolicyWriter.writePolicyFile(newPath, (PolicyType) policyData); + + if (policy.getConfigurationData()!= null){ + if(!isNullOrEmpty(oldPathString)){ + try{ + String[] oldPolicyScopeName = getScopeAndNameAndType(oldPathString); + String oldConfigFileName = getConfigFile(oldPolicyScopeName[1],oldPolicyScopeName[0],policy.getConfigurationData().getConfigType()); + Path oldConfigFilePath = getPolicySubFile(oldConfigFileName, "Config"); + logger.debug("Trying to delete: "+oldConfigFilePath.toString()); + Files.delete(oldConfigFilePath); + }catch(Exception e){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Could not delete the old policy config before rename for policy: "+oldPathString,e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Could not delete the old policy config before rename for policy: "+oldPathString); + } + } + writePolicySubFile(policy, "Config"); + + }else if(policy.getActionBodyEntity()!= null){ + if(!isNullOrEmpty(oldPathString)){ + try{ + String[] oldPolicyScopeName = getScopeAndNameAndType(oldPathString); + String oldActionFileName = getConfigFile(oldPolicyScopeName[1],oldPolicyScopeName[0],ConfigPolicy.JSON_CONFIG); + Path oldActionFilePath = getPolicySubFile(oldActionFileName, "Action"); + logger.debug("Trying to delete: "+oldActionFilePath.toString()); + Files.delete(oldActionFilePath); + }catch(Exception e){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Could not delete the old policy action body before rename for policy: "+oldPathString,e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Could not delete the old policy action body before rename for policy: "+oldPathString); + } + } + writePolicySubFile(policy, "Action"); + } + + } + } catch (IOException e1) { + //TODO:EELF Cleanup - Remove logger + //logger.error("Error occurred while performing [" + action + "] of Policy File: " + policy.getPolicyName(), e1); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e1, "PolicyDBDao", "Error occurred while performing [" + action + "] of Policy File: " + policy.getPolicyName()); + } + } + + //FIXME error correcting and logs + private void createGroupsFromDatabase(){ + //get list of groups + boolean foundDefault = false; + //need to avoid infinite loop, just in case + boolean alreadyRunAdd = false; + while(!foundDefault){ + + EntityManager em = emf.createEntityManager(); + Query getGroups = em.createQuery("SELECT g FROM GroupEntity g WHERE g.deleted=:deleted"); + getGroups.setParameter("deleted", false); + List groups = getGroups.getResultList(); + em.close(); + //make a folder for each group in pdps folders + Path pdpsPath = Paths.get("pdps"); + try { + FileUtils.forceDelete(pdpsPath.toFile()); + } catch (Exception e) { + e.printStackTrace(); + } + try { + FileUtils.forceMkdir(pdpsPath.toFile()); + } catch (Exception e) { + e.printStackTrace(); + } + Properties propertyFileProperties = new Properties(); + String groupList = ""; + String defaultGroup = ""; + for(Object o : groups){ + GroupEntity group = (GroupEntity)o; + Path groupPath = Paths.get(pdpsPath.toString(), group.getGroupId()); + try { + FileUtils.forceMkdir(groupPath.toFile()); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + Properties policyProperties = new Properties(); + String rootPolicies = ""; + for(PolicyEntity policy : group.getPolicies()){ + Path newPolicyPath = Paths.get(groupPath.toString(),getPdpPolicyName(policy.getPolicyName(),policy.getScope())); + File newPolicyFile = newPolicyPath.toFile(); + try { + newPolicyFile.createNewFile(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + try { + FileOutputStream policyFileStream = new FileOutputStream(newPolicyFile); + policyFileStream.write(policy.getPolicyData().getBytes("UTF-8")); + policyFileStream.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + policyProperties.setProperty(getPdpPolicyName(policy.getPolicyName(),policy.getScope())+".name",removeExtensionAndVersionFromPolicyName(policy.getPolicyName())); + rootPolicies += ",".concat(getPdpPolicyName(policy.getPolicyName(),policy.getScope())); + } + Path xacmlPolicyPropertiesPath = Paths.get(groupPath.toString(),"xacml.policy.properties"); + File xacmlPolicyPropertiesFile = xacmlPolicyPropertiesPath.toFile(); + if(rootPolicies.length() > 0){ + rootPolicies = rootPolicies.substring(1); + } + policyProperties.setProperty("xacml.referencedPolicies", ""); + policyProperties.setProperty("xacml.rootPolicies", rootPolicies); + + try { + xacmlPolicyPropertiesFile.createNewFile(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + try { + FileOutputStream xacmlPolicyPropertiesFileStream = new FileOutputStream(xacmlPolicyPropertiesFile); + //xacmlPolicyPropertiesFileStream.write(xacmlPolicyProperties.getBytes("UTF-8")); + policyProperties.store(xacmlPolicyPropertiesFileStream, ""); + xacmlPolicyPropertiesFileStream.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + em = emf.createEntityManager(); + Query getPdpsQuery = em.createQuery("SELECT p FROM PdpEntity p WHERE p.groupEntity=:group AND p.deleted=:deleted"); + getPdpsQuery.setParameter("group", group); + getPdpsQuery.setParameter("deleted", false); + List pdps = getPdpsQuery.getResultList(); + em.close(); + String pdpLine = ""; + for(Object o2 : pdps){ + PdpEntity pdp = (PdpEntity)o2; + pdpLine += ",".concat(pdp.getPdpId()); + propertyFileProperties.setProperty(pdp.getPdpId()+".description",pdp.getDescription()); + propertyFileProperties.setProperty(pdp.getPdpId()+".jmxport",String.valueOf(pdp.getJmxPort())); + propertyFileProperties.setProperty(pdp.getPdpId()+".name",pdp.getPdpName()); + } + if(pdpLine.length() > 0){ + pdpLine = pdpLine.substring(1); + } + propertyFileProperties.setProperty(group.getGroupId()+".description", group.getDescription()); + propertyFileProperties.setProperty(group.getGroupId()+".name", group.getgroupName()); + propertyFileProperties.setProperty(group.getGroupId()+".pdps",pdpLine); + groupList += ",".concat(group.getGroupId()); + if(group.isDefaultGroup()){ + defaultGroup = group.getGroupId(); + foundDefault = true; + } + } + if(!foundDefault && !alreadyRunAdd){ + alreadyRunAdd = true; + //add default group to db + try{ + em = emf.createEntityManager(); + em.getTransaction().begin(); + GroupEntity newDefaultGroup = new GroupEntity(); + em.persist(newDefaultGroup); + newDefaultGroup.setDescription("The default group where new PDP's are put."); + newDefaultGroup.setGroupId("default"); + newDefaultGroup.setGroupName("default"); + newDefaultGroup.setDefaultGroup(true); + newDefaultGroup.setCreatedBy("automaticallyAdded"); + newDefaultGroup.setModifiedBy("automaticallyAdded"); + em.flush(); + em.getTransaction().commit(); + continue; + } catch(Exception e){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Could not add a new default group to the database",e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Could not add a new default group to the database"); + } + } + + Path xacmlPropertiesPath = Paths.get(pdpsPath.toString(),"xacml.properties"); + File xacmlPropertiesFile = xacmlPropertiesPath.toFile(); + if(groupList.length()>0){ + groupList = groupList.substring(1); + } + propertyFileProperties.setProperty("xacml.pap.groups",groupList); + propertyFileProperties.setProperty("xacml.pap.groups.default",defaultGroup); + try { + xacmlPropertiesFile.createNewFile(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + try { + FileOutputStream xacmlPropertiesFileStream = new FileOutputStream(xacmlPropertiesFile); + //xacmlPropertiesFileStream.write(fileContents.getBytes("UTF-8")); + propertyFileProperties.store(xacmlPropertiesFileStream, ""); + xacmlPropertiesFileStream.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + //if we get this far down, something went wrong and we don't want to get stuck in the loop + foundDefault = true; + } + //put policies in group folder + //create xacml.policy.properties in each folder with list of policies in that folder + //get list of pdps + //create xacml.properties with list of groups and pdps and other info + } + + + //FIXME error checking and logging + private String getPdpPolicyName(String name, String scope){ + String finalName = ""; + finalName += scope; + finalName += "."; + finalName += removeFileExtension(name); + finalName += ".xml"; + return finalName; + } + private String removeFileExtension(String fileName){ + return fileName.substring(0, fileName.lastIndexOf('.')); + } + + private String buildPolicyScopeDirectory(PolicyEntity policy){ + String repo = buildPolicyDirectory(); + + String policyScope = policy.getScope(); + if(policyScope == null){ + policyScope = ""; + //TODO:EELF Cleanup - Remove logger + //logger.error("buildPolicyScopeDirectory("+policy+") computed null policyScope. Using blank."); + PolicyLogger.error("buildPolicyScopeDirectory("+policy+") computed null policyScope. Using blank."); + } else { + policyScope = policyScope.replace(".", FileSystems.getDefault().getSeparator()); + } + if(policyScope == null){ + policyScope = ""; + //TODO:EELF Cleanup - Remove logger + //logger.error("buildPolicyScopeDirectory("+policy+") computed null policyScope. Using blank."); + PolicyLogger.error("buildPolicyScopeDirectory("+policy+") computed null policyScope. Using blank."); + } + if(repo == null){ + //TODO:EELF Cleanup - Remove logger + //logger.error("buildPolicyScopeDirectory("+policy+") received null repo. Using blank."); + PolicyLogger.error("buildPolicyScopeDirectory("+policy+") received null repo. Using blank."); + repo = ""; + } + Path returnPath = Paths.get(repo + FileSystems.getDefault().getSeparator() + policyScope); + if(returnPath != null){ + return returnPath.toString(); + } else { + //TODO:EELF Cleanup - Remove logger + //logger.error("buildPolicyScopeDirectory("+policy+") computed null path"); + PolicyLogger.error("buildPolicyScopeDirectory("+policy+") received null repo. Using blank."); + return ""; + } + + + } + private String buildPolicyScopeDirectory(String policyScope){ + String repo = buildPolicyDirectory(); + policyScope = policyScope.replace(".", FileSystems.getDefault().getSeparator()); + return repo + FileSystems.getDefault().getSeparator() + policyScope; + + } + + private static String buildPolicyDirectory(){ + Path workspacePath = Paths.get(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_WORKSPACE), getDefaultWorkspace()); + Path repositoryPath = Paths.get(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_REPOSITORY)); + Path gitPath = Paths.get(workspacePath.toString(), repositoryPath.getFileName().toString()); + + /* + * Getting and Setting the parent path for Admin Console use when reading the policy files + */ + //domain chosen by the client to store the policy action files + //String domain = policy.getDomainDir(); + + + + //getting the fullpath of the gitPath and convert to string + String policyDir = gitPath.toAbsolutePath().toString(); + + + if(policyDir.contains("\\")){ + policyDir = policyDir.replace("XACML-PAP-REST", "XACML-PAP-ADMIN"); + }else{ + if (policyDir.contains("pap")){ + policyDir = policyDir.replace("pap", "console"); + } + } + logger.debug("policyDir: " + policyDir); + return policyDir; + } + + private Path getPolicySubFile(String filename, String subFileType){ + logger.debug("getPolicySubFile(" + filename + ", " + subFileType + ")"); + Path filePath = Paths.get(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_WEBAPPS).toString(), subFileType); + File file = null; + + filename = FilenameUtils.removeExtension(filename); + + for(File tmpFile : filePath.toFile().listFiles()){ + if (FilenameUtils.removeExtension(tmpFile.getName()).equals(filename)){ + file = tmpFile; + } + } + + Path finalPath = null; + if (file!= null){ + finalPath = Paths.get(file.getAbsolutePath()); + } + + logger.debug("end of getPolicySubFile: " + finalPath); + return finalPath; + } + + private boolean writePolicySubFile(PolicyEntity policy, String policyType){ + logger.info("writePolicySubFile with policyName[" + policy.getPolicyName() + "] and policyType[" + policyType + "]"); + String type = null; + String subTypeName = null; + String subTypeBody = null; + if (policyType.equalsIgnoreCase("config")){ + type = "Config"; + subTypeName = FilenameUtils.removeExtension(policy.getConfigurationData().getConfigurationName()); + subTypeBody = policy.getConfigurationData().getConfigBody(); + + String configType = policy.getConfigurationData().getConfigType(); + + + if (configType != null) { + if (configType.equals(JSON_CONFIG)) { + subTypeName = subTypeName + ".json"; + } + if (configType.equals(XML_CONFIG)) { + subTypeName = subTypeName + ".xml"; + } + if (configType.equals(PROPERTIES_CONFIG)) { + subTypeName = subTypeName + ".properties"; + } + if (configType.equals(OTHER_CONFIG)) { + subTypeName = subTypeName + ".txt"; + } + } + + }else if (policyType.equalsIgnoreCase("action")){ + type = "Action"; + subTypeName = policy.getActionBodyEntity().getActionBodyName(); + subTypeBody = policy.getActionBodyEntity().getActionBody(); + + + } + Path filePath = Paths.get(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_WEBAPPS).toString(), type); + + if(subTypeBody == null){ + subTypeBody = ""; + } + boolean success = false; + try { + Files.deleteIfExists(Paths.get(filePath.toString(), subTypeName)); + File file = Paths.get(filePath.toString(),subTypeName).toFile(); + file.createNewFile(); + FileWriter fileWriter = new FileWriter(file, false); // false to overwrite + fileWriter.write(subTypeBody); + fileWriter.close(); + success = true; + + } catch (Exception e) { + //TODO:EELF Cleanup - Remove logger + //logger.error("Exception occured while creating Configuration File for Policy : " + policy.getPolicyName(), e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Exception occured while creating Configuration File for Policy : " + policy.getPolicyName()); + } + + return success; + + } + + private String getPolicySubType(String filename){ + String type = null; + + if (filename != null) { + if (FilenameUtils.getExtension(filename).equalsIgnoreCase("json")) { + type = ConfigPolicy.JSON_CONFIG; + } + if (FilenameUtils.getExtension(filename).equalsIgnoreCase("xml")) { + type = ConfigPolicy.XML_CONFIG; + } + if (FilenameUtils.getExtension(filename).equalsIgnoreCase("properties")) { + type = ConfigPolicy.PROPERTIES_CONFIG; + } + if (FilenameUtils.getExtension(filename).equalsIgnoreCase("txt")) { + type = ConfigPolicy.OTHER_CONFIG; + } + } + + return type; + + } + + + private void convertFileToDBEntry(Path path){ + logger.info("convertFileToDBEntry"); + + if(path.toString().contains(".git")){ + return; + } + + String filename = path.getFileName().toString(); + if (filename.contains(".svnignore")){ + return; + } + + String[] scopeAndName = getScopeAndNameAndType(path.toString()); + + if(scopeAndName == null){ + //TODO:EELF Cleanup - Remove logger + //logger.error("convertFileToDBEntry error: getScopeAndNameAndType(" + path.toString() + " is null!"); + PolicyLogger.error("convertFileToDBEntry error: getScopeAndNameAndType(" + path.toString() + " is null!"); + return; + } + + EntityManager em = emf.createEntityManager(); + em.getTransaction().begin(); + + PolicyEntity policy = new PolicyEntity(); + em.persist(policy); + String policyScope = scopeAndName[0]; + String policyName = scopeAndName[1]; + policy.setScope(policyScope); + policy.setPolicyName(policyName); + policy.setCreatedBy(AUDIT_USER); + policy.setModifiedBy(AUDIT_USER); + + String newScope = policyScope.replace(".", File.separator); + String newName = FilenameUtils.removeExtension(policyName); + int version = 1; + try{ + //we want the last index +1 because we don't want the dot + version = Integer.parseInt(newName.substring(newName.lastIndexOf(".")+1)); + } catch(Exception e){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Could not get the policy version number from "+newName); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Could not get the policy version number from "+newName); + } + newName = newScope + File.separator + newName.substring(0, newName.lastIndexOf(".")); + + Query query = em.createNamedQuery("PolicyVersion.findByPolicyName"); + query.setParameter("pname", newName); + + List result = query.getResultList(); + PolicyVersion versionEntity = null; + + if (!result.isEmpty()) { + logger.info("Result is not empty"); + versionEntity = (PolicyVersion) result.get(0); + int highestVersion = Math.max(versionEntity.getHigherVersion(),version); + versionEntity.setHigherVersion(highestVersion); + versionEntity.setActiveVersion(highestVersion); + }else{ + logger.info("result is empty"); + Calendar calendar = Calendar.getInstance(); + Timestamp createdDate = new Timestamp(calendar.getTime().getTime()); + + versionEntity = new PolicyVersion(); + em.persist(versionEntity); + versionEntity.setPolicyName(newName); + versionEntity.setHigherVersion(version); + versionEntity.setActiveVersion(version); + versionEntity.setCreatedBy(AUDIT_USER); + versionEntity.setModifiedBy(AUDIT_USER); + versionEntity.setCreatedDate(createdDate); + versionEntity.setModifiedDate(createdDate); + } + + + try { + String policyContent = new String(Files.readAllBytes(path)); + policy.setDescription(getElementFromXMLString("/Description", policyContent)); + policy.setPolicyData(policyContent); + } catch (IOException e1) { + //TODO:EELF Cleanup - Remove logger + //logger.error("convertFileToDBEntry error settingPolicyData: " + e1.getMessage()); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e1, "PolicyDBDao", "convertFileToDBEntry error settingPolicyData"); + em.getTransaction().rollback(); + em.close(); + return; + } + + if((scopeAndName[2].equalsIgnoreCase("Config"))){ + String scopeName = scopeAndName[0] + "." + scopeAndName[1]; + Path subFilePath = getPolicySubFile(scopeName, scopeAndName[2]); + try { + String content = new String(Files.readAllBytes(subFilePath)); + String configName = subFilePath.getFileName().toString(); + ConfigurationDataEntity configData = new ConfigurationDataEntity(); + em.persist(configData); + configData.setConfigurationName(subFilePath.getFileName().toString()); + configData.setConfigBody(content); + configData.setConfigType(getPolicySubType(configName)); + configData.setCreatedBy(AUDIT_USER); + configData.setModifiedBy(AUDIT_USER); + policy.setConfigurationData(configData); + + } catch (Exception e) { + //TODO:EELF Cleanup - Remove logger + //logger.error("convertFileToDBEntry error for Config policy: " + e.getMessage()); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "convertFileToDBEntry error for Config policy"); + em.getTransaction().rollback(); + em.close(); + return; + } + }else if(scopeAndName[2].equalsIgnoreCase("Action")){ + String scopeName = scopeAndName[0] + "." + scopeAndName[1]; + Path subFilePath = getPolicySubFile(scopeName, scopeAndName[2]); + try { + String content = new String(Files.readAllBytes(subFilePath)); + ActionBodyEntity actionBody = new ActionBodyEntity(); + em.persist(actionBody); + actionBody.setActionBodyName(subFilePath.getFileName().toString()); + actionBody.setActionBody(content); + actionBody.setCreatedBy(AUDIT_USER); + actionBody.setModifiedBy(AUDIT_USER); + policy.setActionBodyEntity(actionBody); + + } catch (Exception e) { + //TODO:EELF Cleanup - Remove logger + //logger.error("convertFileToDBEntry error for Action policy: " + e.getMessage()); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "convertFileToDBEntry error for Action policy"); + em.getTransaction().rollback(); + em.close(); + return; + } + } + logger.debug("convertFileToDBEntry commit transaction"); + em.getTransaction().commit(); + em.close(); + } + + private void deleteAllPolicyTables(){ + EntityManager em = emf.createEntityManager(); + em.getTransaction().begin(); + Query deletePolicyEntityTableUpdate = em.createNamedQuery("PolicyEntity.deleteAll"); + Query deleteActionBodyEntityTableUpdate = em.createNamedQuery("ActionBodyEntity.deleteAll"); + Query deleteConfigurationDataEntityTableUpdate = em.createNamedQuery("ConfigurationDataEntity.deleteAll"); + Query deletePolicyVersionEntityTableUpdate = em.createNamedQuery("PolicyVersion.deleteAll"); + deletePolicyEntityTableUpdate.executeUpdate(); + deleteActionBodyEntityTableUpdate.executeUpdate(); + deleteConfigurationDataEntityTableUpdate.executeUpdate(); + deletePolicyVersionEntityTableUpdate.executeUpdate(); + em.getTransaction().commit(); + em.close(); + + } + + public void auditLocalDatabase(PAPPolicyEngine papEngine2){ + logger.debug("PolicyDBDao.auditLocalDatabase() is called"); + Path webappsPath = Paths.get(buildPolicyDirectory()); + try{ + deleteAllGroupTables(); + deleteAllPolicyTables(); + Files.createDirectories(webappsPath); + Files.walk(webappsPath).filter(Files::isRegularFile).forEach(this::convertFileToDBEntry); + auditGroups(papEngine2); + } catch(Exception e){ + //TODO:EELF Cleanup - Remove logger + //logger.error("auditLocalDatabase() error: " + e.getMessage()); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "auditLocalDatabase() error"); + e.printStackTrace(); + } + } + + /** + * Audits and loads the local file system to match the database version. + */ + @SuppressWarnings("unchecked") + public void auditLocalFileSystem(){ + logger.debug("PolicyDBDau.auditLocalFileSystem() is called"); + + Path webappsPath = Paths.get(buildPolicyDirectory()); + Path configFilesPath = Paths.get(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_WEBAPPS).toString(), "Config"); + Path actionFilesPath = Paths.get(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_WEBAPPS).toString(), "Action"); + try { + Files.createDirectories(configFilesPath); + Files.createDirectories(actionFilesPath); + FileUtils.cleanDirectory(actionFilesPath.toFile()); + FileUtils.cleanDirectory(configFilesPath.toFile()); + if (webappsPath.toFile().exists()){ + FileUtils.cleanDirectory(webappsPath.toFile()); + } + Path repoWithScope = Paths.get(webappsPath.toString(), XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_DOMAIN)); + Files.createDirectories(repoWithScope); + } catch (IOException e2) { + //TODO:EELF Cleanup - Remove logger + //logger.error("Error occurred while creating / clearing Config and Policy filesystem directories", e2); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e2, "PolicyDBDao", "Error occurred while creating / clearing Config and Policy filesystem directories"); + } + + List policyEntityList; + try{ + EntityManager em = emf.createEntityManager(); + Query getPolicyEntitiesQuery = em.createNamedQuery("PolicyEntity.findAllByDeletedFlag"); + getPolicyEntitiesQuery.setParameter("deleted", false); + policyEntityList = getPolicyEntitiesQuery.getResultList(); + } catch(Exception e){ + policyEntityList = new LinkedList(); + } + + for (PolicyEntity policy: policyEntityList){ + String name = ""; + try { + if (!policy.isDeleted()){ + name = policy.getPolicyName(); + String scope = policy.getScope(); + + scope = scope.replace(".", "//"); + if (policy.getConfigurationData()!=null){ + writePolicySubFile(policy, "Config"); + } + else if(policy.getActionBodyEntity()!=null){ + writePolicySubFile(policy, "Action"); + } + + + Path fileLocation = Paths.get(webappsPath.toString(), scope); + + Files.createDirectories(fileLocation); + Path newPath = Paths.get(fileLocation.toString(), name); + Object policyData = XACMLPolicyScanner.readPolicy(IOUtils.toInputStream(policy.getPolicyData())); + XACMLPolicyWriter.writePolicyFile(newPath, (PolicyType) policyData); + } + } catch (Exception e1) { + //TODO:EELF Cleanup - Remove logger + //logger.error("Error occurred while creating Policy File: " + name, e1); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e1, "PolicyDBDao", "Error occurred while creating Policy File: " + name); + } + } + createGroupsFromDatabase(); + } + + public void deleteAllGroupTables(){ + logger.debug("PolicyDBDao.deleteAllGroupTables() called"); + EntityManager em = emf.createEntityManager(); + em.getTransaction().begin(); + + Query deletePdpEntityEntityTableUpdate = em.createNamedQuery("PdpEntity.deleteAll"); + deletePdpEntityEntityTableUpdate.executeUpdate(); + + Query deleteGroupEntityTableUpdate = em.createNamedQuery("GroupEntity.deleteAll"); + deleteGroupEntityTableUpdate.executeUpdate(); + + em.getTransaction().commit(); + em.close(); + } + + @SuppressWarnings("unchecked") + public void auditGroups(PAPPolicyEngine papEngine2){ + logger.debug("PolicyDBDao.auditGroups() called"); + + EntityManager em = emf.createEntityManager(); + em.getTransaction().begin(); + final String AUDIT_STR = "Audit"; + try{ + + Set groups = papEngine2.getEcompPDPGroups(); + + for (EcompPDPGroup grp : groups){ + try{ + GroupEntity groupEntity = new GroupEntity(); + em.persist(groupEntity); + groupEntity.setGroupName(grp.getName()); + groupEntity.setDescription(grp.getDescription()); + groupEntity.setDefaultGroup(grp.isDefaultGroup()); + groupEntity.setCreatedBy(AUDIT_STR); + groupEntity.setGroupId(createNewPDPGroupId(grp.getId())); + groupEntity.setModifiedBy(AUDIT_STR); + Set pdps = grp.getEcompPdps(); + + for(EcompPDP pdp : pdps){ + PdpEntity pdpEntity = new PdpEntity(); + em.persist(pdpEntity); + pdpEntity.setGroup(groupEntity); + pdpEntity.setJmxPort(pdp.getJmxPort()); + pdpEntity.setPdpId(pdp.getId()); + pdpEntity.setPdpName(pdp.getName()); + pdpEntity.setModifiedBy(AUDIT_STR); + pdpEntity.setCreatedBy(AUDIT_STR); + + } + + Set policies = grp.getPolicies(); + + for(PDPPolicy policy : policies){ + try{ + String[] stringArray = getNameScopeAndVersionFromPdpPolicy(policy.getId()); + List policyEntityList; + Query getPolicyEntitiesQuery = em.createNamedQuery("PolicyEntity.findByNameAndScope"); + getPolicyEntitiesQuery.setParameter("name", stringArray[0]); + getPolicyEntitiesQuery.setParameter("scope", stringArray[1]); + + policyEntityList = getPolicyEntitiesQuery.getResultList(); + PolicyEntity policyEntity = null; + if(policyEntityList.size() < 1){ + policyEntity = addPolicyThatOnlyExistsInPdpGroup(policy.getId(),Paths.get("pdps",grp.getId(),policy.getId()),em); + } else { + policyEntity = policyEntityList.get(0); + } + if(policyEntity != null){ + groupEntity.addPolicyToGroup(policyEntity); + } + }catch(Exception e2){ + //TODO:EELF Cleanup - Remove logger + //logger.error("ERROR: " + e2); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e2, "PolicyDBDao", "Exception auditGroups inner catch"); + } + } + }catch(Exception e1){ + //TODO:EELF Cleanup - Remove logger + //logger.error("ERROR: " + e1); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e1, "PolicyDBDao", "Exception auditGroups middle catch"); + } + } + }catch(Exception e){ + em.getTransaction().rollback(); + //TODO:EELF Cleanup - Remove logger + //logger.error("ERROR: " + e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Exception auditGroups outer catch"); + em.close(); + return; + } + + em.getTransaction().commit(); + em.close(); + + } + + private PolicyEntity addPolicyThatOnlyExistsInPdpGroup(String polId, Path path,EntityManager em){ + String filename = path.getFileName().toString(); + if (filename.contains(".svnignore")){ + return null; + } + + String[] scopeAndName = getNameScopeAndVersionFromPdpPolicy(polId); + + if(scopeAndName == null){ + //TODO:EELF Cleanup - Remove logger + //logger.error("convertFileToDBEntry error: getScopeAndNameAndType(" + polId.toString() + " is null!"); + PolicyLogger.error("convertFileToDBEntry error: getScopeAndNameAndType(" + polId.toString() + " is null!"); + return null; + } + + + PolicyEntity policy = new PolicyEntity(); + em.persist(policy); + String policyScope = scopeAndName[1]; + String policyName = scopeAndName[0]; + policy.setScope(policyScope); + policy.setPolicyName(policyName); + policy.setCreatedBy(AUDIT_USER); + policy.setModifiedBy(AUDIT_USER); + policy.setDeleted(true); + + try { + String policyContent = new String(Files.readAllBytes(path)); + policy.setDescription(getElementFromXMLString("/Description", policyContent)); + policy.setPolicyData(policyContent); + em.flush(); + //em.getTransaction().commit(); + } catch (IOException e1) { + // TODO Auto-generated catch block + //TODO:EELF Cleanup - Remove logger + //logger.error("convertFileToDBEntry error settingPolicyData: " + e1.getMessage()); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e1, "PolicyDBDao", "convertFileToDBEntry error settingPolicyData"); + return null; + } + //em.close(); + return policy; + } + + private String getConfigFile(String filename, String scope, PolicyRestAdapter policy){ + if(policy == null){ + return getConfigFile(filename, scope, (String)null); + } + return getConfigFile(filename, scope, policy.getConfigType()); + } + //copied from ConfigPolicy.java and modified + // Here we are adding the extension for the configurations file based on the + // config type selection for saving. + private String getConfigFile(String filename, String scope, String configType) { + logger.debug("getConfigFile(String filename, String scope, String configType) as getConfigFile("+filename+", "+scope+", "+configType+") called"); + filename = FilenameUtils.removeExtension(filename); +// if (filename.endsWith(".xml")) { +// filename = filename.substring(0, filename.length() - 4); +// } + String id = configType; + + if (id != null) { + if (id.equals(ConfigPolicy.JSON_CONFIG) || id.contains("Firewall")) { + filename = filename + ".json"; + } + if (id.equals(ConfigPolicy.XML_CONFIG)) { + filename = filename + ".xml"; + } + if (id.equals(ConfigPolicy.PROPERTIES_CONFIG)) { + filename = filename + ".properties"; + } + if (id.equals(ConfigPolicy.OTHER_CONFIG)) { + filename = filename + ".txt"; + } + } + return scope + "." + filename; + } + + /** + * Constructs the file name of a policy. + * @param policy The name of a policy (ex: mypolicy1) + * @return The file name of the policy (ex: Config_mypolicy1.xml) + * @deprecated + */ + @SuppressWarnings("unused") + private String getName(PolicyRestAdapter policy){ + logger.debug("getName(PolicyRestAdapter policy) as getName("+policy+") called"); + String namePrefix = ""; + if(policy.getPolicyType().contains("Config")){ + namePrefix = namePrefix.concat(policy.getPolicyType()); + if(policy.getConfigType().contains("Firewall")){ + namePrefix = namePrefix.concat("_FW"); + } + } + String concats = namePrefix + "_" +policy.getPolicyName() + ".xml"; + return concats; + } + + private String stripPolicyName(String policyFileName){ + String policyName = policyFileName; + try{ + policyName = policyName.substring(policyName.indexOf('_')+1); + policyName = removeFileExtension(policyName); + }catch(Exception e){ + throw new IllegalArgumentException("Could not get name out of policy file name: "+policyName); + } + return policyName; + } + //FIXME error check, logs + private String[] getNameScopeAndVersionFromPdpPolicy(String fileName){ + String[] splitByDots = fileName.split("\\."); + if(splitByDots.length < 3){ + //throw something + return null; + } + String policyName = splitByDots[splitByDots.length-3]; + String version = splitByDots[splitByDots.length-2]; + //policy names now include version + policyName += "."+version +".xml"; + String scope = ""; + for(int i=0;i 0){ + scope = scope.substring(1); + } + String[] returnArray = new String[3]; + returnArray[0] = policyName; + returnArray[2] = version; + returnArray[1] = scope; + return returnArray; + } + + /** + * Constructs the complete repository path based on the properties files + * @return The repository path + */ + public static String getGitPath(){ + logger.debug("getGitPath() as getGitPath() called"); + Path workspacePath = Paths.get(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_WORKSPACE), "admin"); + Path repositoryPath = Paths.get(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_REPOSITORY)); + Path gitPath = Paths.get(workspacePath.toString(), repositoryPath.getFileName().toString()); + logger.debug("after gitPath: " + gitPath); + return gitPath.toString(); + } + + //copied from StdEngine.java + public static String createNewPDPGroupId(String name) { + String id = name; + // replace "bad" characters with sequences that will be ok for file names and properties keys. + id = id.replace(" ", "_sp_"); + id = id.replace("\t", "_tab_"); + id = id.replace("\\", "_bksl_"); + id = id.replace("/", "_sl_"); + id = id.replace(":", "_col_"); + id = id.replace("*", "_ast_"); + id = id.replace("?", "_q_"); + id = id.replace("\"", "_quo_"); + id = id.replace("<", "_lt_"); + id = id.replace(">", "_gt_"); + id = id.replace("|", "_bar_"); + id = id.replace("=", "_eq_"); + id = id.replace(",", "_com_"); + id = id.replace(";", "_scom_"); + + return id; + } + + /** + * Checks if any of the given strings are empty or null + * @param strings One or more Strings (or nulls) to check if they are null or empty + * @return true if one or more of the given strings are empty or null + */ + private static boolean isNullOrEmpty(String... strings){ + for(String s : strings){ + if(!(s instanceof String)){ + return true; + } + if(s.equals("")){ + return true; + } + } + return false; + } + + /** + * Computes the scope, name, and type of a policy based on its file path + * @param path The file path of the policy (including the xml policy file) + * @return A string array of size 3. 1: the scope of the policy 2: the name of the policy (Config_mypol.xml) 3: the type (Config). Or, null if the path can not be parsed. + */ + private static String[] getScopeAndNameAndType(String path){ + logger.debug("getScopeAndNameAndType(String path) as getScopeAndNameAndType("+path+") called"); + if(path == null){ + + } + String gitPath = getGitPath(); + + ArrayList gitPathParts = new ArrayList(); + Iterator gitPathIterator = Paths.get(gitPath).iterator(); + while(gitPathIterator.hasNext()){ + gitPathParts.add(gitPathIterator.next().toString()); + } + for(int i=0;i= path.length()){ + logger.debug("gitPath length(): " + gitPath.length() + ">= path.length(): " + path.length() + ". Returning null"); + return null; + } + String scopeAndName = path.substring(path.indexOf(gitPath)+gitPath.length()); + + logger.debug("scopeAndName: " + scopeAndName); + String policyType = null; + String[] policyTypes = {"Config_","Action_","Decision_"}; + for(String pType : policyTypes){ + if(scopeAndName.contains(pType)){ + policyType = pType; + } + } + if(policyType == null){ + return null; + } + String scope = scopeAndName.substring(0,scopeAndName.indexOf(policyType)); + String name = scopeAndName.substring(scopeAndName.indexOf(policyType), scopeAndName.length()); + scope = scope.replace('\\', '.'); + scope = scope.replace('/', '.'); + if(scope.length()<1){ + return null; + } + if(scope.charAt(0) == '.'){ + if(scope.length() < 2){ + logger.debug("getScopeAndNameAndType error: " + scope.length() + " < 2. " + "| scope.charAt(0)==."); + return null; + } + scope = scope.substring(1); + } + if(scope.charAt(scope.length()-1) == '.'){ + if(scope.length() < 2){ + logger.debug("getScopeAndNameAndType error: " + scope.length() + " < 2" + "| scope.charAt(scope.length()-1)==."); + return null; + } + scope = scope.substring(0,scope.length()-1); + } + if(name.length()<1){ + logger.debug("getScopeAndNameAndType error: name.length()<1"); + return null; + } + if(name.charAt(0) == '.'){ + if(name.length() < 2){ + logger.debug("getScopeAndNameAndType error: " + name.length() + " < 2. " + "| scope.charAt(0)==."); + return null; + } + name = name.substring(1); + } + String[] returnArray = new String[3]; + returnArray[0] = scope; + returnArray[1] = name; + //remove the underscore and return it + returnArray[2] = policyType.substring(0, policyType.length()-1); + return returnArray; + } + + + private class PolicyDBDaoTransactionInstance implements PolicyDBDaoTransaction { + private EntityManager em; + private final Object emLock = new Object(); + long policyId; + long groupId; + long pdpId; + String newGroupId; + private boolean operationRun = false; + private final Thread transactionTimer; + + private PolicyDBDaoTransactionInstance(){ + //call the constructor with arguments + this(Integer.parseInt(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_TRANS_TIMEOUT)), + Integer.parseInt(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_TRANS_WAIT))); + } + //timeout is how long the transaction can sit before rolling back + //wait time is how long to wait for the transaction to start before throwing an exception + private PolicyDBDaoTransactionInstance(int transactionTimeout, int transactionWaitTime){ + if(logger.isDebugEnabled()){ + logger.debug("\n\nPolicyDBDaoTransactionInstance() as PolicyDBDaoTransactionInstance() called:" + + "\n transactionTimeout = " + transactionTimeout + + "\n transactionWaitTime = " + transactionWaitTime + "\n\n"); + } + this.em = emf.createEntityManager(); + policyId = -1; + groupId = -1; + pdpId = -1; + newGroupId = null; + synchronized(emLock){ + try{ + startTransactionSynced(this.em,transactionWaitTime); + } catch(Exception e){ + throw new PersistenceException("Could not lock transaction within "+transactionWaitTime+" milliseconds"); + } + } + class TransactionTimer implements Runnable { + + private int sleepTime; + public TransactionTimer(int timeout){ + this.sleepTime = timeout; + } + @Override + public void run() { + if(logger.isDebugEnabled()){ + Date date= new java.util.Date(); + logger.debug("\n\nTransactionTimer.run() - SLEEPING: " + + "\n sleepTime (ms) = " + sleepTime + + "\n TimeStamp = " + date.getTime() + + "\n\n"); + } + try { + Thread.sleep(sleepTime); + } catch (InterruptedException e) { + //probably, the transaction was completed, the last thing we want to do is roll back + if(logger.isDebugEnabled()){ + Date date= new java.util.Date(); + logger.debug("\n\nTransactionTimer.run() - WAKE Interrupt: " + + "\n TimeStamp = " + date.getTime() + + "\n\n"); + } + return; + } + if(logger.isDebugEnabled()){ + Date date= new java.util.Date(); + logger.debug("\n\nTransactionTimer.run() - WAKE Timeout: " + + "\n TimeStamp = " + date.getTime() + + "\n\n"); + } + rollbackTransaction(); + } + + } + + transactionTimer = new Thread(new TransactionTimer(transactionTimeout),"transactionTimerThread"); + transactionTimer.start(); + + + } + + private void checkBeforeOperationRun(){ + checkBeforeOperationRun(false); + } + private void checkBeforeOperationRun(boolean justCheckOpen){ + if(!isTransactionOpen()){ + //TODO:EELF Cleanup - Remove logger + //logger.error("There is no transaction currently open"); + PolicyLogger.error("There is no transaction currently open"); + throw new IllegalStateException("There is no transaction currently open"); + } + if(operationRun && !justCheckOpen){ + //TODO:EELF Cleanup - Remove logger + //logger.error("An operation has already been performed and the current transaction should be committed"); + PolicyLogger.error("An operation has already been performed and the current transaction should be committed"); + throw new IllegalStateException("An operation has already been performed and the current transaction should be committed"); + } + operationRun = true; + } + @Override + public void commitTransaction() { + synchronized(emLock){ + logger.debug("commitTransaction() as commitTransaction() called"); + if(!isTransactionOpen()){ + logger.warn("There is no open transaction to commit"); + //throw new IllegalStateException("There is no open transaction to commit"); + try{ + em.close(); + } catch(Exception e){ + e.printStackTrace(); + } + return; + } + try{ + em.getTransaction().commit(); + } catch(RollbackException e){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Caught RollbackException on em.getTransaction().commit()",e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Caught RollbackException on em.getTransaction().commit()"); + throw new PersistenceException("The commit failed. Message:\n"+e.getMessage()); + } + em.close(); + //FIXME need to revisit + if(policyId >= 0){ + + if(newGroupId != null){ + try{ + notifyOthers(policyId,POLICY_NOTIFICATION,newGroupId); + } catch(Exception e){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Caught Exception on notifyOthers("+policyId+","+POLICY_NOTIFICATION+","+newGroupId+")",e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Caught Exception on notifyOthers("+policyId+","+POLICY_NOTIFICATION+","+newGroupId+")"); + } + } else { + try{ + notifyOthers(policyId,POLICY_NOTIFICATION); + } catch(Exception e){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Caught Exception on notifyOthers("+policyId+","+POLICY_NOTIFICATION+")",e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Caught Exception on notifyOthers("+policyId+","+POLICY_NOTIFICATION+")"); + } + } + } + if(groupId >= 0){ + //we don't want commit to fail just because this does + if(newGroupId != null){ + try{ + notifyOthers(groupId,GROUP_NOTIFICATION,newGroupId); + } catch(Exception e){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Caught Exception on notifyOthers("+groupId+","+GROUP_NOTIFICATION+","+newGroupId+")",e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Caught Exception on notifyOthers("+groupId+","+GROUP_NOTIFICATION+","+newGroupId+")"); + } + } else { + try{ + notifyOthers(groupId,GROUP_NOTIFICATION); + } catch(Exception e){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Caught Exception on notifyOthers("+groupId+","+GROUP_NOTIFICATION+")",e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Caught Exception on notifyOthers("+groupId+","+GROUP_NOTIFICATION+")"); + } + } + } + if(pdpId >= 0){ + //we don't want commit to fail just because this does + try{ + notifyOthers(pdpId,PDP_NOTIFICATION); + } catch(Exception e){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Caught Exception on notifyOthers("+pdpId+","+PDP_NOTIFICATION+")",e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Caught Exception on notifyOthers("+pdpId+","+PDP_NOTIFICATION+")"); + } + } + } + if(transactionTimer instanceof Thread){ + transactionTimer.interrupt(); + } + } + + @Override + public void rollbackTransaction() { + logger.debug("rollbackTransaction() as rollbackTransaction() called"); + synchronized(emLock){ + if(isTransactionOpen()){ + + try{ + em.getTransaction().rollback(); + } catch(Exception e){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Could not rollback transaction"); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Could not rollback transaction"); + } + try{ + em.close(); + }catch(Exception e){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Could not close EntityManager"); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Could not close EntityManager"); + } + + } else { + try{ + em.close(); + }catch(Exception e){ + logger.warn("Could not close already closed transaction"); + } + } + + } + if(transactionTimer instanceof Thread){ + transactionTimer.interrupt(); + } + + + } + + private void createPolicy(PolicyRestAdapter policy, String username, String policyScope, String policyName, String policyDataString) { + logger.debug("createPolicy(PolicyRestAdapter policy, String username, String policyScope, String policyName, String policyDataString) as createPolicy("+policy+", "+username+", "+policyScope+", "+policyName+", "+policyDataString+") called"); + synchronized(emLock){ + checkBeforeOperationRun(); + //em.getTransaction().begin(); + //FIXME if the policy is already found but deleted, when we update it should we reset the created by and version number? + Query createPolicyQuery = em.createQuery("SELECT p FROM PolicyEntity p WHERE p.scope=:scope AND p.policyName=:policyName"); + createPolicyQuery.setParameter("scope", policyScope); + createPolicyQuery.setParameter("policyName", policyName); + //createPolicyQuery.setParameter("deleted", false); + List createPolicyQueryList = createPolicyQuery.getResultList(); + PolicyEntity newPolicyEntity; + boolean update; + if(createPolicyQueryList.size() < 1){ + newPolicyEntity = new PolicyEntity(); + update = false; + } else if(createPolicyQueryList.size() > 1){ + //something went wrong + //TODO:EELF Cleanup - Remove logger + //logger.error("Somehow, more than one policy with the same scope, name, and deleted status were found in the database"); + PolicyLogger.error("Somehow, more than one policy with the same scope, name, and deleted status were found in the database"); + throw new PersistenceException("Somehow, more than one policy with the same scope, name, and deleted status were found in the database"); + } else { + newPolicyEntity = (PolicyEntity)createPolicyQueryList.get(0); + update = true; + } + + ActionBodyEntity newActionBodyEntity = null; + if(policy.getPolicyType().equals("Action")){ + boolean abupdate = false; + if(newPolicyEntity.getActionBodyEntity() == null){ + newActionBodyEntity = new ActionBodyEntity(); + }else{ + newActionBodyEntity = em.find(ActionBodyEntity.class, newPolicyEntity.getActionBodyEntity().getActionBodyId()); + abupdate = true; + } + + if(newActionBodyEntity != null){ + if(!abupdate){ + em.persist(newActionBodyEntity); + } + //build the file path + //trim the .xml off the end + String policyNameClean = FilenameUtils.removeExtension(policyName); + String actionBodyName = policyScope + "." + policyNameClean + ".json"; + Path actionBodyPath = Paths.get(Webapps.getActionHome(), actionBodyName); + if(logger.isDebugEnabled()){ + logger.debug("\nPolicyDBDao.createPolicy" + + "\n actionBodyPath = " + actionBodyPath); + } + //get the action body + String actionBodyString = null; + String actionBodyPathStr = null; + InputStream fileContentStream = null; + + if (Files.exists(actionBodyPath)) { + try { + actionBodyPathStr = (actionBodyPath != null ? actionBodyPath.toString() : null); + fileContentStream = new FileInputStream(actionBodyPathStr); + actionBodyString = IOUtils.toString(fileContentStream); + if(logger.isDebugEnabled()){ + logger.debug("\nPolicyDBDao.createPolicy" + + "\n actionBodyPathStr = " + actionBodyPathStr + + "\n actionBodyString = " + actionBodyString); + } + } catch (FileNotFoundException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error("Caught FileNotFoundException on new actionBodyPathStr FileInputStream("+actionBodyPathStr+")",e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Caught FileNotFoundException on new actionBodyPathStr FileInputStream("+actionBodyPathStr+")"); + throw new IllegalArgumentException("The actionBodyPathStr file path " + actionBodyPathStr + " does not exist" + + "\nEXCEPTION: " + e); + } catch(IOException e2){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Caught IOException on actionBodyPath newIOUtils.toString("+fileContentStream+")",e2); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e2, "PolicyDBDao", "Caught IOException on actionBodyPath newIOUtils.toString("+fileContentStream+")"); + throw new IllegalArgumentException("The actionBodyPath file path cannot be read" + fileContentStream + + "\nEXCEPTION: " + e2); + } finally { + IOUtils.closeQuietly(fileContentStream); + } + + if(actionBodyString == null){ + throw new IllegalArgumentException("The file path (" + actionBodyPathStr + ") cannot be read"); + } + + } else { + actionBodyString = "{}"; + } + + newActionBodyEntity.setActionBody(actionBodyString); + newActionBodyEntity.setActionBodyName(actionBodyName); + newActionBodyEntity.setModifiedBy("PolicyDBDao.createPolicy()"); + newActionBodyEntity.setDeleted(false); + if(!abupdate){ + newActionBodyEntity.setCreatedBy("PolicyDBDao.createPolicy()"); + } + if(logger.isDebugEnabled()){ + logger.debug("\nPolicyDBDao.createPolicy" + + "\n newActionBodyEntity.getActionBody() = " + newActionBodyEntity.getActionBody() + + "\n newActionBodyEntity.getActionBodyName() = " + newActionBodyEntity.getActionBodyName() + + "\n newActionBodyEntity.getModifiedBy() = " + newActionBodyEntity.getModifiedBy() + + "\n newActionBodyEntity.getCreatedBy() = " + newActionBodyEntity.getCreatedBy() + + "\n newActionBodyEntity.isDeleted() = " + newActionBodyEntity.isDeleted() + + "\n FLUSHING to DB"); + } + //push the actionBodyEntity to the DB + em.flush(); + }else{ + //newActionBodyEntity == null + //We have a actionBody in the policy but we found no actionBody in the DB + String msg = "\n\nPolicyDBDao.createPolicy - Incoming Action policy had an " + + "actionBody, but it could not be found in the DB for update." + + "\n policyScope = " + policyScope + + "\n policyName = " + policyName + "\n\n"; + //TODO:EELF Cleanup - Remove logger + //logger.error(msg); + PolicyLogger.error("PolicyDBDao.createPolicy - Incoming Action policy had an actionBody, but it could not be found in the DB for update: policyName = " + policyName); + throw new IllegalArgumentException(msg); + } + } + + ConfigurationDataEntity newConfigurationDataEntity; + if(policy.getPolicyType().equals("Config")){ + boolean configUpdate; + if(newPolicyEntity.getConfigurationData() == null){ + newConfigurationDataEntity = new ConfigurationDataEntity(); + configUpdate = false; + } else { + newConfigurationDataEntity = em.find(ConfigurationDataEntity.class, newPolicyEntity.getConfigurationData().getConfigurationDataId()); + configUpdate = true; + } + + if(newConfigurationDataEntity != null){ + if(!configUpdate){ + em.persist(newConfigurationDataEntity); + } + //ConfigPolicy configPolicy = (ConfigPolicy)policy; + if(!stringEquals(newConfigurationDataEntity.getConfigurationName(),getConfigFile(policyName,policyScope,policy))){ + newConfigurationDataEntity.setConfigurationName(getConfigFile(policyName,policyScope,policy)); + } + if(newConfigurationDataEntity.getConfigType() == null || !newConfigurationDataEntity.getConfigType().equals(policy.getConfigType())){ + newConfigurationDataEntity.setConfigType(policy.getConfigType()); + } + if(!configUpdate){ + newConfigurationDataEntity.setCreatedBy(username); + } + if(newConfigurationDataEntity.getModifiedBy() == null || !newConfigurationDataEntity.getModifiedBy().equals(username)){ + newConfigurationDataEntity.setModifiedBy(username); + } + if(newConfigurationDataEntity.getDescription() == null || !newConfigurationDataEntity.getDescription().equals("")){ + newConfigurationDataEntity.setDescription(""); + } + if(newConfigurationDataEntity.getConfigBody() == null || newConfigurationDataEntity.getConfigBody().isEmpty() || + (!newConfigurationDataEntity.getConfigBody().equals(policy.getConfigBodyData()))){ + //hopefully one of these won't be null + if(policy.getConfigBodyData() == null){ + newConfigurationDataEntity.setConfigBody(policy.getJsonBody()); + }else{ + newConfigurationDataEntity.setConfigBody(policy.getConfigBodyData()); + } + } + if(newConfigurationDataEntity.isDeleted() == true){ + newConfigurationDataEntity.setDeleted(false); + } + + em.flush(); + }else{//newConfigurationDataEntity == null + //We have a configurationData body in the policy but we found no configurationData body + //in the DB + String msg = "\n\nPolicyDBDao.createPolicy - Incoming Config policy had a " + + "configurationData body, but it could not be found in the DB for update." + + "\n policyScope = " + policyScope + + "\n policyName = " + policyName + "\n\n"; + //TODO:EELF Cleanup - Remove logger + //logger.error(msg); + PolicyLogger.error("PolicyDBDao.createPolicy - Incoming Config policy had a configurationData body, but it could not be found in the DB for update: policyName = " + policyName); + throw new IllegalArgumentException(msg); + } + + } else { + newConfigurationDataEntity = null; + } + if(!update){ + em.persist(newPolicyEntity); + } + + policyId = newPolicyEntity.getPolicyId(); + //policy version is now part of policy name + /* + if(update){ + try{ + String versionString = evaluateXPath("Policy/@Version", policyDataString); + int versionNum = Integer.parseInt(versionString); + if(versionNum < 1){ + throw new NumberFormatException(); + } + newPolicyEntity.setPolicyVersion(versionNum); + } catch(Exception e){ + if(newPolicyEntity.isDeleted()){ + newPolicyEntity.resetPolicyVersion(); + } else { + newPolicyEntity.advancePolicyVersion(); + } + } + + + } + */ + if(!stringEquals(newPolicyEntity.getPolicyName(),policyName)){ + newPolicyEntity.setPolicyName(policyName); + } + if(!stringEquals(newPolicyEntity.getCreatedBy(),username)){ + newPolicyEntity.setCreatedBy(username); + } + if(!stringEquals(newPolicyEntity.getDescription(),policy.getPolicyDescription())){ + newPolicyEntity.setDescription(policy.getPolicyDescription()); + } + if(!stringEquals(newPolicyEntity.getModifiedBy(),username)){ + newPolicyEntity.setModifiedBy(username); + } + if(!stringEquals(newPolicyEntity.getPolicyData(),policyDataString)){ + newPolicyEntity.setPolicyData(policyDataString); + } + if(!stringEquals(newPolicyEntity.getScope(),policyScope)){ + newPolicyEntity.setScope(policyScope); + } + if(newPolicyEntity.isDeleted() == true){ + newPolicyEntity.setDeleted(false); + } + newPolicyEntity.setConfigurationData(newConfigurationDataEntity); + newPolicyEntity.setActionBodyEntity(newActionBodyEntity); + + + em.flush(); + this.policyId = newPolicyEntity.getPolicyId(); + } + + return; + } + + @SuppressWarnings("unused") + public PolicyEntity getPolicy(int policyID){ + return getPolicy(policyID,null,null); + } + public PolicyEntity getPolicy(String policyName,String scope){ + return getPolicy(-1,policyName,scope); + } + private PolicyEntity getPolicy(int policyID, String policyName,String scope){ + logger.debug("getPolicy(int policyId, String policyName) as getPolicy("+policyID+","+policyName+") called"); + if(policyID < 0 && isNullOrEmpty(policyName,scope)){ + throw new IllegalArgumentException("policyID must be at least 0 or policyName must be not null or blank"); + } + + synchronized(emLock){ + checkBeforeOperationRun(true); + //check if group exists + String policyId; + Query policyQuery; + if(!isNullOrEmpty(policyName,scope)){ + policyId = policyName; + policyQuery = em.createQuery("SELECT p FROM PolicyEntity p WHERE p.policyName=:name AND p.scope=:scope"); + policyQuery.setParameter("name", policyId); + policyQuery.setParameter("scope", scope); + } else{ + policyId = String.valueOf(policyID); + policyQuery = em.createNamedQuery("PolicyEntity.FindById"); + policyQuery.setParameter("id", policyId); + } + List policyQueryList; + try{ + policyQueryList = policyQuery.getResultList(); + }catch(Exception e){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Caught Exception trying to get policy with policyQuery.getResultList()",e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Caught Exception trying to get policy with policyQuery.getResultList()"); + throw new PersistenceException("Query failed trying to get policy "+policyId); + } + if(policyQueryList.size() < 1){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Policy does not exist with id "+policyId); + PolicyLogger.error("Policy does not exist with id "+policyId); + throw new PersistenceException("Group policy is being added to does not exist with id "+policyId); + } else if(policyQueryList.size() > 1){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Somehow, more than one policy with the id "+policyId+" were found in the database"); + PolicyLogger.error("Somehow, more than one policy with the id "+policyId+" were found in the database"); + throw new PersistenceException("Somehow, more than one policy with the id "+policyId+" were found in the database"); + } + return (PolicyEntity)policyQueryList.get(0); + } + } + + @Override + public void renamePolicy(String oldPath, String newPath,String username){ + String[] oldPolicy = getScopeAndNameAndType(oldPath); + String[] newPolicy = getScopeAndNameAndType(newPath); + if(oldPolicy == null || newPolicy == null){ + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW+"Could not parse one or more of the path names: " + //+oldPath+", "+newPath); + PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW+"Could not parse one or more of the path names: " + +oldPath+", "+newPath); + throw new IllegalArgumentException("Could not parse one or more of the path names"); + } + synchronized (emLock) { + checkBeforeOperationRun(); + + PolicyEntity existingPolicy; + boolean existingPolicyDeleted = false; + List groups = null; + try{ + existingPolicy = getPolicy(newPolicy[1],newPolicy[0]); + } catch(Exception e){ + existingPolicy = null; + } + if(existingPolicy != null && !existingPolicy.isDeleted()){ + logger.error("The policy named "+existingPolicy.getPolicyName()+" already exists, cannot rename policy: "+newPolicy); + throw new IllegalArgumentException("The policy named "+existingPolicy.getPolicyName()+" already exists, cannot rename policy: "+newPolicy); + } else if(existingPolicy != null && existingPolicy.isDeleted()){ + try{ + Query getGroups = em.createQuery("SELECT g FROM GroupEntity g JOIN g.policies p WHERE p.policyId=:pid"); + + getGroups.setParameter("pid", existingPolicy.getPolicyId()); + groups = getGroups.getResultList(); + }catch(Exception e){ + groups = new LinkedList(); + } + for(Object o : groups){ + + GroupEntity group = (GroupEntity)o; + group.removePolicyFromGroup(existingPolicy); + } + try{ + em.flush(); + }catch(Exception e){ + logger.error("Error while removing the policy from groups: "+existingPolicy.getPolicyName()); + } + try{ + em.remove(existingPolicy); + em.flush(); + }catch(Exception e){ + logger.error("Could not remove the existing deleted policy: "+existingPolicy.getPolicyName()); + } + existingPolicyDeleted = true; + //create the new policy + //for each of the groups, add the new policy + } + + PolicyEntity policyToRename; + try{ + policyToRename = getPolicy(oldPolicy[1],oldPolicy[0]); + } catch(Exception e){ + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW+"Could not get policy record to rename: " + //+oldPolicy[1],e); + PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "PolicyDBDao", "Could not get policy record to rename: " + +oldPolicy[1]); + throw new PersistenceException("Could not get policy record to rename"); + } + String policyDataString = null; + InputStream fileContentStream = null; + String policyFilePath = Paths.get(oldPath).toAbsolutePath().toString(); + //I want to try the old path first, then if it doesn't work, try the new path + for(int i=0;i<2;i++){ + try { + fileContentStream = new FileInputStream(policyFilePath); + policyDataString = IOUtils.toString(fileContentStream); + } catch (FileNotFoundException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error("Caught FileNotFoundException on new FileInputStream("+policyFilePath+")",e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Caught FileNotFoundException on new FileInputStream("+policyFilePath+")"); + //if we can't find the oldPath, we'll try the new path + if(i == 0){ + policyFilePath = Paths.get(newPath).toAbsolutePath().toString(); + continue; + } + throw new IllegalArgumentException("The file path does not exist"); + } catch(IOException e2){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Caught IOException on newIOUtils.toString("+fileContentStream+")",e2); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e2, "PolicyDBDao", "Caught IOException on newIOUtils.toString("+fileContentStream+")"); + throw new IllegalArgumentException("The file path cannot be read"); + } finally { + IOUtils.closeQuietly(fileContentStream); + } + if(policyDataString == null){ + throw new IllegalArgumentException("The file path cannot be read"); + } + //escape the loop + i=2; + } + policyToRename.setPolicyName(newPolicy[1]); + policyToRename.setPolicyData(policyDataString); + policyToRename.setScope(newPolicy[0]); + policyToRename.setModifiedBy(username); + if(policyToRename.getConfigurationData() != null){ + //String configType = getPolicySubType(policyToRename.getConfigurationData().getConfigurationName()); + String configType = policyToRename.getConfigurationData().getConfigType(); + policyToRename.getConfigurationData().setConfigurationName(getConfigFile(newPolicy[1], newPolicy[0], configType)); + policyToRename.getConfigurationData().setModifiedBy(username); + } + if(policyToRename.getActionBodyEntity() != null){ + String newActionName = newPolicy[0]+"."+removeFileExtension(newPolicy[1])+".json"; + policyToRename.getActionBodyEntity().setActionBodyName(newActionName); + policyToRename.getActionBodyEntity().setModifiedBy(username); + } + if(existingPolicyDeleted){ + for(Object o : groups){ + + GroupEntity group = (GroupEntity)o; + group.addPolicyToGroup(policyToRename); + } + } + em.flush(); + this.policyId = policyToRename.getPolicyId(); + this.newGroupId = oldPath; + } + } + + @Override + public GroupEntity getGroup(long groupKey){ + logger.debug("getGroup(int groupKey) as getGroup("+groupKey+") called"); + if(groupKey < 0){ + throw new IllegalArgumentException("groupKey must be at least 0"); + } + synchronized(emLock){ + checkBeforeOperationRun(true); + //check if group exists + Query groupQuery = em.createQuery("SELECT g FROM GroupEntity g WHERE g.groupKey=:groupKey"); + groupQuery.setParameter("groupKey", groupKey); + List groupQueryList; + try{ + groupQueryList = groupQuery.getResultList(); + }catch(Exception e){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Caught Exception trying to get group with groupQuery.getResultList()",e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Caught Exception trying to get group with groupQuery.getResultList()"); + throw new PersistenceException("Query failed trying to get group "+groupKey); + } + if(groupQueryList.size() < 1){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Group does not exist with groupKey "+groupKey); + PolicyLogger.error("Group does not exist with groupKey "+groupKey); + throw new PersistenceException("Group does not exist with groupKey "+groupKey); + } else if(groupQueryList.size() > 1){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Somehow, more than one group with the groupKey "+groupKey+" were found in the database"); + PolicyLogger.error("Somehow, more than one group with the groupKey "+groupKey+" were found in the database"); + throw new PersistenceException("Somehow, more than one group with the groupKey "+groupKey+" were found in the database"); + } + return (GroupEntity)groupQueryList.get(0); + } + } + + @Override + public GroupEntity getGroup(String groupId){ + logger.debug("getGroup(String groupId) as getGroup("+groupId+") called"); + if(isNullOrEmpty(groupId)){ + throw new IllegalArgumentException("groupId must not be null or empty"); + } + synchronized(emLock){ + checkBeforeOperationRun(true); + //check if group exists + Query groupQuery = em.createQuery("SELECT g FROM GroupEntity g WHERE g.groupId=:groupId"); + groupQuery.setParameter("groupId", groupId); + List groupQueryList; + try{ + groupQueryList = groupQuery.getResultList(); + }catch(Exception e){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Caught Exception trying to get group with groupQuery.getResultList()",e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Caught Exception trying to get group with groupQuery.getResultList()"); + throw new PersistenceException("Query failed trying to get group "+groupId); + } + if(groupQueryList.size() < 1){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Group does not exist with id "+groupId); + PolicyLogger.error("Group does not exist with id "+groupId); + throw new PersistenceException("Group does not exist with id "+groupId); + } else if(groupQueryList.size() > 1){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Somehow, more than one group with the id "+groupId+" were found in the database"); + PolicyLogger.error("Somehow, more than one group with the id "+groupId+" were found in the database"); + throw new PersistenceException("Somehow, more than one group with the id "+groupId+" were found in the database"); + } + return (GroupEntity)groupQueryList.get(0); + } + } + @Override + public List getPdpsInGroup(long groupKey){ + logger.debug("getPdpsInGroup(int groupKey) as getPdpsInGroup("+groupKey+") called"); + if(groupKey < 0){ + throw new IllegalArgumentException("groupId must not be < 0"); + } + synchronized(emLock){ + checkBeforeOperationRun(true); + Query pdpsQuery = em.createQuery("SELECT p FROM PdpEntity p WHERE p.groupEntity=:group"); + pdpsQuery.setParameter("group", getGroup(groupKey)); + return pdpsQuery.getResultList(); + } + } + @Override + public PdpEntity getPdp(long pdpKey){ + logger.debug("getPdp(int pdpKey) as getPdp("+pdpKey+") called"); + if(pdpKey < 0){ + throw new IllegalArgumentException("pdpKey must be at least 0"); + } + synchronized(emLock){ + checkBeforeOperationRun(true); + //check if group exists + Query pdpQuery = em.createQuery("SELECT p FROM PdpEntity p WHERE p.pdpKey=:pdpKey"); + pdpQuery.setParameter("pdpKey", pdpKey); + List pdpQueryList; + try{ + pdpQueryList = pdpQuery.getResultList(); + }catch(Exception e){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Caught Exception trying to get pdp with pdpQuery.getResultList()",e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Caught Exception trying to get pdp with pdpQuery.getResultList()"); + throw new PersistenceException("Query failed trying to get pdp "+pdpKey); + } + if(pdpQueryList.size() < 1){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Pdp does not exist with pdpKey "+pdpKey); + PolicyLogger.error("Pdp does not exist with pdpKey "+pdpKey); + throw new PersistenceException("Pdp does not exist with pdpKey "+pdpKey); + } else if(pdpQueryList.size() > 1){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Somehow, more than one pdp with the pdpKey "+pdpKey+" were found in the database"); + PolicyLogger.error("Somehow, more than one pdp with the pdpKey "+pdpKey+" were found in the database"); + throw new PersistenceException("Somehow, more than one pdp with the pdpKey "+pdpKey+" were found in the database"); + } + return (PdpEntity)pdpQueryList.get(0); + } + } + + //FIXME: maybe this should be boolean + public void deletePolicy(String policyToDeletes){ + synchronized(emLock){ +// if(isTransactionOpen()){ +// logger.error("A transaction is already open which has not been committed"); +// throw new IllegalStateException("A transaction is already open which has not been committed"); +// } + checkBeforeOperationRun(); + logger.debug("deletePolicy(String policyToDeletes) as deletePolicy("+policyToDeletes+") called"); + String[] scopeNameAndType = getScopeAndNameAndType(policyToDeletes); + if(scopeNameAndType == null){ + throw new IllegalArgumentException("Could not parse file path"); + } + String realScope = scopeNameAndType[0]; + String realName = scopeNameAndType[1]; +// if(isTransactionOpen()){ +// throw new IllegalStateException("A transaction is already open which has not been committed"); +// } + Query deletePolicyQuery = em.createQuery("SELECT p FROM PolicyEntity p WHERE p.scope=:scope AND p.policyName=:policyName AND p.deleted=:deleted"); + deletePolicyQuery.setParameter("scope",realScope); + deletePolicyQuery.setParameter("policyName", realName); + deletePolicyQuery.setParameter("deleted", false); + List deletePolicyQueryList = deletePolicyQuery.getResultList(); + if(deletePolicyQueryList.size() < 1){ + logger.warn("The policy being deleted could not be found."); + return; + } else if(deletePolicyQueryList.size() > 1){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Somehow, more than one policy with the same scope, name, and deleted status were found in the database"); + PolicyLogger.error("Somehow, more than one policy with the same scope, name, and deleted status were found in the database"); + throw new PersistenceException("Somehow, more than one policy with the same scope, name, and deleted status were found in the database"); + } else { + //em.getTransaction().begin(); + PolicyEntity policyToDelete = (PolicyEntity)deletePolicyQueryList.get(0); + policyToDelete.setDeleted(true); + if(policyToDelete.getConfigurationData() != null){ + ConfigurationDataEntity cde = em.find(ConfigurationDataEntity.class,policyToDelete.getConfigurationData().getConfigurationDataId()); + if(cde != null){ + cde.setDeleted(true); + } + } + if(policyToDelete.getActionBodyEntity() != null){ + ActionBodyEntity abe = em.find(ActionBodyEntity.class,policyToDelete.getActionBodyEntity().getActionBodyId()); + if(abe != null){ + abe.setDeleted(true); + } + } + + em.flush(); + this.policyId = policyToDelete.getPolicyId(); + + } + } + + } + + + @Override + public boolean isTransactionOpen() { + logger.debug("isTransactionOpen() as isTransactionOpen() called"); + synchronized(emLock){ + return em.isOpen() && em.getTransaction().isActive(); + } + } + + + @Override + public void clonePolicy(String oldPolicyPath, String newPolicyPath, String username){ + String[] oldPolicyData = getScopeAndNameAndType(oldPolicyPath); + String[] newPolicyData = getScopeAndNameAndType(newPolicyPath); + if(oldPolicyData == null || newPolicyData == null){ + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW+"Could not parse one or more of the path names: " + //+oldPolicyPath+", "+newPolicyPath); + PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW+"Could not parse one or more of the path names: " + +oldPolicyPath+", "+newPolicyPath); + throw new IllegalArgumentException("Could not parse the oldPolicyPath or newPolicyPath"); + } + PolicyEntity oldPolicy; + try{ + oldPolicy = getPolicy(oldPolicyData[1],oldPolicyData[0]); + }catch(Exception e){ + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW+"Could not get policy record to clone: " + //+oldPolicyData[1],e); + PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "PolicyDBDao", "Could not get policy record to clone: " + +oldPolicyData[1]); + throw new PersistenceException("Could not get policy record to clone"); + } + ConfigurationDataEntity clonedConfig = null; + if(oldPolicy.getConfigurationData() != null){ + clonedConfig = new ConfigurationDataEntity(); + em.persist(clonedConfig); + clonedConfig.setConfigBody(oldPolicy.getConfigurationData().getConfigBody()); + clonedConfig.setConfigType(oldPolicy.getConfigurationData().getConfigType()); + clonedConfig.setCreatedBy(username); + clonedConfig.setConfigurationName(getConfigFile(newPolicyData[1], newPolicyData[0], oldPolicy.getConfigurationData().getConfigType())); + clonedConfig.setDescription(oldPolicy.getConfigurationData().getDescription()); + clonedConfig.setModifiedBy(username); + em.flush(); + } + ActionBodyEntity clonedAction = null; + if(oldPolicy.getActionBodyEntity() != null){ + clonedAction = new ActionBodyEntity(); + em.persist(clonedAction); + clonedAction.setActionBody(oldPolicy.getActionBodyEntity().getActionBody()); + clonedAction.setActionBodyName(newPolicyData[0]+"."+newPolicyData[1]+".json"); + clonedAction.setCreatedBy(username); + clonedAction.setModifiedBy(username); + em.flush(); + } + + + } + + @Override + public void createPolicy(String filePath, String username) { + logger.debug("createPolicy(String filePath, String username) as createPolicy("+filePath+","+username+") called"); + //get just the scope and file name + //its actually scope, name, and type now + String[] scopeAndName = getScopeAndNameAndType(filePath); + if(scopeAndName == null){ + throw new IllegalArgumentException("The file path could not be parsed"); + } + PolicyRestAdapter policy = new PolicyRestAdapter(); + + policy.setPolicyType(scopeAndName[2]); + policy.setPolicyDescription(""); + + String policyName = scopeAndName[1]; + try{ + policyName = stripPolicyName(policyName); + }catch(IllegalArgumentException e){ + if(scopeAndName[2].equals("Config")){ + //TODO:EELF Cleanup - Remove logger + //logger.error(e.getMessage()); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Exception calling stripPolicyName with policy name: "+policyName); + throw new IllegalArgumentException(e.getMessage(),e); + } else { + logger.warn(e.getMessage()); + } + } + policy.setPolicyName(policyName); + String policyDataString = null; + InputStream fileContentStream = null; + try { + fileContentStream = new FileInputStream(filePath); + policyDataString = IOUtils.toString(fileContentStream); + } catch (FileNotFoundException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error("Caught FileNotFoundException on new FileInputStream("+filePath+")",e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Caught FileNotFoundException on new FileInputStream("+filePath+")"); + throw new IllegalArgumentException("The file path does not exist"); + } catch(IOException e2){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Caught IOException on newIOUtils.toString("+fileContentStream+")",e2); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e2, "PolicyDBDao", "Caught IOException on newIOUtils.toString("+fileContentStream+")"); + throw new IllegalArgumentException("The file path cannot be read"); + } finally { + IOUtils.closeQuietly(fileContentStream); + } + if(policyDataString == null){ + throw new IllegalArgumentException("The file path cannot be read"); + } + try{ + String policyDescription = getElementFromXMLString("/Description", policyDataString); + if(policyDescription != null){ + policy.setPolicyDescription(policyDescription); + } + } catch(Exception e){ + logger.warn("Could not get description from the policy file"); + } + if(scopeAndName[2].equals("Config")){ + //this method is not used for config, since there is no way to get config info (could be modified to) + String configPath; + try{ + configPath = evaluateXPath("/Policy/Rule/AdviceExpressions/AdviceExpression[contains(@AdviceId,'ID')]/AttributeAssignmentExpression[@AttributeId='URLID']/AttributeValue/text()", policyDataString); + if(configPath == null){ + throw new NullPointerException("configPath is null"); + } + } catch(Exception e){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Could not get config file path from policy file",e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Could not get config file path from policy file"); + throw new IllegalArgumentException("Could not get config file path from policy file"); + } + configPath = processConfigPath(configPath); + logger.debug("The location of our config file is: "+configPath); + policy.setConfigType(getPolicySubType(configPath)); + logger.debug("Config type is: "+policy.getConfigType()); + + String configDataString = readConfigFile(configPath); + policy.setConfigBodyData(configDataString); + } + createPolicy(policy,username,scopeAndName[0],scopeAndName[1],policyDataString); + } + private String processConfigPath(String configPath){ + String webappsPath = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_WEBAPPS); + if(webappsPath == null){ + logger.error("Webapps property does not exist"); + throw new IllegalArgumentException("Webapps property does not exist"); + } + configPath = configPath.replace("$URL", webappsPath); + //make sure the correct slashes are in + try{ + configPath = Paths.get(configPath).toString(); + } catch(InvalidPathException e){ + logger.error("Invalid config path: "+configPath); + throw new IllegalArgumentException("Invalid config path: "+configPath); + } + return configPath; + } + private String readConfigFile(String configPath){ + String configDataString = null; + InputStream configContentStream = null; + try { + configContentStream = new FileInputStream(configPath); + configDataString = IOUtils.toString(configContentStream); + } catch (FileNotFoundException e) { + logger.error("Caught FileNotFoundException on new FileInputStream("+configPath+")",e); + throw new IllegalArgumentException("The config file path does not exist"); + } catch(IOException e2){ + logger.error("Caught IOException on newIOUtils.toString("+configContentStream+")",e2); + throw new IllegalArgumentException("The config file path cannot be read"); + } finally { + IOUtils.closeQuietly(configContentStream); + } + if(configDataString == null){ + throw new IllegalArgumentException("The config file path cannot be read"); + } + return configDataString; + } + + @Override + public void createPolicy(Policy policy, String username){ + logger.debug("createPolicy(PolicyRestAdapter policy, String username) as createPolicy("+policy+","+username+") called"); + String policyScope = computeScope(policy.policyAdapter.getParentPath(),policy.policyAdapter.getUserGitPath()); + + //Does not need to be XACMLPolicyWriterWithPapNotify since it is already in the PAP + //and this transaction is intercepted up stream. + InputStream policyXmlStream = XACMLPolicyWriter.getXmlAsInputStream((PolicyType)policy.getCorrectPolicyDataObject()); + String policyDataString; + try { + policyDataString = IOUtils.toString(policyXmlStream); + } catch (IOException e) { + policyDataString = "could not read"; + //TODO:EELF Cleanup - Remove logger + //logger.error("Caught IOException on IOUtils.toString("+policyXmlStream+")",e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Caught IOException on IOUtils.toString("+policyXmlStream+")"); + throw new IllegalArgumentException("Cannot parse the policy xml from the PolicyRestAdapter."); + } + IOUtils.closeQuietly(policyXmlStream); + String configPath = ""; + if (policy.policyAdapter.getPolicyType().equalsIgnoreCase("Config")) { + configPath = evaluateXPath("/Policy/Rule/AdviceExpressions/AdviceExpression[contains(@AdviceId,'ID')]/AttributeAssignmentExpression[@AttributeId='URLID']/AttributeValue/text()", policyDataString); + } else if (policy.policyAdapter.getPolicyType().equalsIgnoreCase("Action")) { + configPath = evaluateXPath("/Policy/Rule/ObligationExpressions/ObligationExpression[contains(@ObligationId, " +policy.policyAdapter.getActionAttribute()+ ")]/AttributeAssignmentExpression[@AttributeId='body']/AttributeValue/text()", policyDataString); + } + + String prefix = null; + if (policy.policyAdapter.getPolicyType().equalsIgnoreCase("Config")) { + + prefix = configPath.substring(configPath.indexOf(policyScope+".")+policyScope.concat(".").length(), configPath.indexOf(policy.policyAdapter.getPolicyName())); + if(isNullOrEmpty(policy.policyAdapter.getConfigBodyData())){ + String configData = ""; + try{ + String newConfigPath = configPath; + try{ + newConfigPath = processConfigPath(newConfigPath); + }catch(Exception e2){ + logger.error("Could not process config path: "+newConfigPath,e2); + } + configData = readConfigFile(newConfigPath); + }catch(Exception e){ + logger.error("Could not read config body data for "+configPath,e); + } + policy.policyAdapter.setConfigBodyData(configData); + } + + } else if (policy.policyAdapter.getPolicyType().equalsIgnoreCase("Action")) { + + prefix = "Action_"; + + } else if (policy.policyAdapter.getPolicyType().equalsIgnoreCase("Decision")) { + + prefix = "Decision_"; + } + + if(!(policy.policyAdapter.getData() instanceof PolicyType)){ + //TODO:EELF Cleanup - Remove logger + //logger.error("The data field is not an instance of PolicyType"); + PolicyLogger.error("The data field is not an instance of PolicyType"); + throw new IllegalArgumentException("The data field is not an instance of PolicyType"); + } + String finalName = prefix+policy.policyAdapter.getPolicyName()+"."+((PolicyType)policy.policyAdapter.getData()).getVersion()+".xml"; + if(policy.policyAdapter.getConfigType() == null || policy.policyAdapter.getConfigType().equals("")){ + //we need to make it + //get the config file extension + String ext = ""; + if (configPath != null) { + if (!configPath.equalsIgnoreCase("")) { + ext = configPath.substring(configPath.lastIndexOf('.'), configPath.length());; + } + } + + if(ext.contains("txt")){ + policy.policyAdapter.setConfigType(OTHER_CONFIG); + } else if(ext.contains("json")){ + policy.policyAdapter.setConfigType(JSON_CONFIG); + } else if(ext.contains("xml")){ + policy.policyAdapter.setConfigType(XML_CONFIG); + } else if(ext.contains("properties")){ + policy.policyAdapter.setConfigType(PROPERTIES_CONFIG); + } else { + if (policy.policyAdapter.getPolicyType().equalsIgnoreCase("Action")){ + policy.policyAdapter.setConfigType(JSON_CONFIG); + } + } + } + createPolicy(policy.policyAdapter, username, policyScope,finalName,policyDataString); + + } + + @Override + public void close(){ + synchronized(emLock){ + if(em.isOpen()){ + if(em.getTransaction().isActive()){ + em.getTransaction().rollback(); + } + em.close(); + } + if(transactionTimer instanceof Thread){ + transactionTimer.interrupt(); + } + } + } + + + + @Override + public void createGroup(String groupId, String groupName, String groupDescription, String username) { + logger.debug("deletePolicy(String policyToDeletes) as createGroup("+groupId+", "+groupName+", "+groupDescription+") called"); +// if(isTransactionOpen()){ +// logger.error("A transaction is already open which has not been committed"); +// throw new IllegalStateException("A transaction is already open which has not been committed"); +// } + //parameter check + if(isNullOrEmpty(groupId, groupName, username)){ + throw new IllegalArgumentException("groupId, groupName, and username must not be null or empty"); + } + if(!(groupDescription instanceof String)){ + groupDescription = ""; + } + + synchronized(emLock){ + checkBeforeOperationRun(); + Query checkGroupQuery = em.createQuery("SELECT g FROM GroupEntity g WHERE g.groupId=:groupId AND g.deleted=:deleted"); + checkGroupQuery.setParameter("groupId", groupId); + checkGroupQuery.setParameter("deleted", false); + List checkGroupQueryList; + try{ + checkGroupQueryList = checkGroupQuery.getResultList(); + } catch(Exception e){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Caught Exception on checkGroupQuery.getResultList()",e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Caught Exception on checkGroupQuery.getResultList()"); + throw new PersistenceException("Query failed trying to check for existing group"); + } + if(checkGroupQueryList.size() > 0){ + //TODO:EELF Cleanup - Remove logger + //logger.error("The group being added already exists with id "+groupId); + PolicyLogger.error("The group being added already exists with id "+groupId); + throw new PersistenceException("The group being added already exists with id "+groupId); + } + //em.getTransaction().begin(); + GroupEntity newGroup = new GroupEntity(); + em.persist(newGroup); + newGroup.setCreatedBy(username); + newGroup.setModifiedBy(username); + newGroup.setGroupName(groupName); + newGroup.setGroupId(groupId); + newGroup.setDescription(groupDescription); + + em.flush(); + this.groupId = newGroup.getGroupKey(); + } + } + + @Override + public void updateGroup(EcompPDPGroup group, String username){ + logger.debug("updateGroup(PDPGroup group) as updateGroup("+group+","+username+") called"); +// if(isTransactionOpen()){ +// logger.error("A transaction is already open which has not been committed"); +// throw new IllegalStateException("A transaction is already open which has not been committed"); +// } + + //parameter check + if(group == null){ + throw new IllegalArgumentException("PDPGroup group must not be null"); + } + if(isNullOrEmpty(group.getId(), username)){ + throw new IllegalArgumentException("group.getId() and username must not be null or empty"); + } + + synchronized(emLock){ + checkBeforeOperationRun(); + Query getGroupQuery = em.createQuery("SELECT g FROM GroupEntity g WHERE g.groupId=:groupId AND g.deleted=:deleted"); + getGroupQuery.setParameter("groupId", group.getId()); + getGroupQuery.setParameter("deleted", false); + List getGroupQueryList; + try{ + getGroupQueryList = getGroupQuery.getResultList(); + } catch(Exception e){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Caught Exception on getGroupQuery.getResultList()",e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Caught Exception on getGroupQuery.getResultList()"); + throw new PersistenceException("Query failed trying to get group "+group.getId()+" for editing"); + } + if(getGroupQueryList.size() < 1){ + //TODO:EELF Cleanup - Remove logger + //logger.error("The group cannot be found to update with id "+group.getId()); + PolicyLogger.error("The group cannot be found to update with id "+group.getId()); + throw new PersistenceException("The group cannot be found to update with id "+group.getId()); + } else if(getGroupQueryList.size() > 1){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Somehow, more than one group with the same id "+group.getId()+" and deleted status were found in the database"); + PolicyLogger.error("Somehow, more than one group with the same id "+group.getId()+" and deleted status were found in the database"); + throw new PersistenceException("Somehow, more than one group with the same id "+group.getId()+" and deleted status were found in the database"); + } + //em.getTransaction().begin(); + GroupEntity groupToUpdate = (GroupEntity)getGroupQueryList.get(0); + if(!stringEquals(groupToUpdate.getModifiedBy(), username)){ + groupToUpdate.setModifiedBy(username); + } + if(group.getDescription() != null && !stringEquals(group.getDescription(),groupToUpdate.getDescription())){ + groupToUpdate.setDescription(group.getDescription()); + } + //let's find out what policies have been deleted + StdPDPGroup oldGroup = null; + try { + oldGroup = (StdPDPGroup) papEngine.getGroup(group.getId()); + } catch (PAPException e1) { + //TODO:EELF Cleanup - Remove logger + //logger.error("We cannot get the group from the papEngine to delete policies",e1); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e1, "PolicyDBDao", "We cannot get the group from the papEngine to delete policies"); + } + if(oldGroup == null){ + //TODO:EELF Cleanup - Remove logger + //logger.error("We cannot get the group from the papEngine to delete policies"); + PolicyLogger.error("We cannot get the group from the papEngine to delete policies"); + } else { + + Set newPolicySet = new HashSet(group.getPolicies().size()); + //a multiple of n runtime is faster than n^2, so I am using a hashset to do the comparison + for(PDPPolicy pol: group.getPolicies()){ + newPolicySet.add(pol.getId()); + } + for(PDPPolicy pol : oldGroup.getPolicies()){ + //should be fast since getPolicies uses a HashSet in StdPDPGroup + if(!newPolicySet.contains(pol.getId())){ + String[] scopeAndName = getNameScopeAndVersionFromPdpPolicy(pol.getId()); + PolicyEntity policyToDelete; + try{ + policyToDelete = getPolicy(scopeAndName[0],scopeAndName[1]); + }catch(Exception e){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Could not get policy to remove: "+pol.getId(),e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Could not get policy to remove: "+pol.getId()); + throw new PersistenceException("Could not get policy to remove: "+pol.getId()); + } + groupToUpdate.getPolicies().remove(policyToDelete); + + } + } + } + if(group.getName() != null && !stringEquals(group.getName(),groupToUpdate.getgroupName())){ + //we need to check if the new id exists in the database + String newGroupId = createNewPDPGroupId(group.getName()); + Query checkGroupQuery = em.createQuery("SELECT g FROM GroupEntity g WHERE g.groupId=:groupId AND g.deleted=:deleted"); + checkGroupQuery.setParameter("groupId", newGroupId); + checkGroupQuery.setParameter("deleted", false); + List checkGroupQueryList; + try{ + checkGroupQueryList = checkGroupQuery.getResultList(); + } catch(Exception e){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Caught Exception on checkGroupQuery.getResultList()",e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Caught Exception on checkGroupQuery.getResultList()"); + throw new PersistenceException("Query failed trying to check for existing group"); + } + if(checkGroupQueryList.size() != 0){ + //TODO:EELF Cleanup - Remove logger + //logger.error("The new group name already exists, group id "+newGroupId); + PolicyLogger.error("The new group name already exists, group id "+newGroupId); + throw new PersistenceException("The new group name already exists, group id "+newGroupId); + } + groupToUpdate.setGroupId(newGroupId); + groupToUpdate.setGroupName(group.getName()); + this.newGroupId = group.getId(); + } + + em.flush(); + this.groupId = groupToUpdate.getGroupKey(); + } + } + + @Override + public void addPdpToGroup(String pdpID, String groupID, String pdpName, String pdpDescription, int pdpJmxPort, String username) { + logger.debug("addPdpToGroup(String pdpID, String groupID, String pdpName, String pdpDescription, int pdpJmxPort, String username) as addPdpToGroup("+pdpID+", "+groupID+", "+pdpName+", "+pdpDescription+", "+pdpJmxPort+", "+username+") called"); + if(isNullOrEmpty(pdpID, groupID,pdpName,username)){ + throw new IllegalArgumentException("pdpID, groupID, pdpName, and username must not be null or empty"); + } + if(!(pdpDescription instanceof String)){ + pdpDescription = ""; + } +// if(isTransactionOpen()){ +// logger.error("A transaction is already open which has not been committed"); +// throw new IllegalStateException("A transaction is already open which has not been committed"); +// } + + synchronized(emLock){ + checkBeforeOperationRun(); + Query checkGroupQuery = em.createQuery("SELECT g FROM GroupEntity g WHERE g.groupId=:groupId AND g.deleted=:deleted"); + checkGroupQuery.setParameter("groupId", groupID); + checkGroupQuery.setParameter("deleted", false); + List checkGroupQueryList; + try{ + checkGroupQueryList = checkGroupQuery.getResultList(); + } catch(Exception e){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Caught Exception trying to check for existing group on checkGroupQuery.getResultList()",e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Caught Exception trying to check for existing group on checkGroupQuery.getResultList()"); + throw new PersistenceException("Query failed trying to check for existing group"); + } + if(checkGroupQueryList.size() != 1){ + //TODO:EELF Cleanup - Remove logger + //logger.error("The group does not exist"); + PolicyLogger.error("The group does not exist"); + throw new PersistenceException("The group does not exist"); + } + Query checkDuplicateQuery = em.createQuery("SELECT p FROM PdpEntity p WHERE p.pdpId=:pdpId AND p.deleted=:deleted"); + checkDuplicateQuery.setParameter("pdpId", pdpID); + checkDuplicateQuery.setParameter("deleted", false); + List checkDuplicateList; + try{ + checkDuplicateList = checkDuplicateQuery.getResultList(); + } catch(Exception e){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Caught Exception trying to check for duplicate PDP "+pdpID+" on checkDuplicateQuery.getResultList()",e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Caught Exception trying to check for duplicate PDP "+pdpID+" on checkDuplicateQuery.getResultList()"); + throw new PersistenceException("Query failed trying to check for duplicate PDP "+pdpID); + } + PdpEntity newPdp; + if(checkDuplicateList.size() > 0){ + logger.warn("PDP already exists with id "+pdpID); + newPdp = (PdpEntity)checkDuplicateList.get(0); + } else { + newPdp = new PdpEntity(); + em.persist(newPdp); + } + + newPdp.setCreatedBy(username); + newPdp.setDeleted(false); + newPdp.setDescription(pdpDescription); + newPdp.setGroup((GroupEntity)checkGroupQueryList.get(0)); + newPdp.setJmxPort(pdpJmxPort); + newPdp.setModifiedBy(username); + newPdp.setPdpId(pdpID); + newPdp.setPdpName(pdpName); + + em.flush(); + this.pdpId = newPdp.getPdpKey(); + + } + } + + + @Override + public void updatePdp(EcompPDP pdp, String username){ + logger.debug("updatePdp(PDP pdp, String username) as updatePdp("+pdp+","+username+") called"); +// if(isTransactionOpen()){ +// logger.error("A transaction is already open which has not been committed"); +// throw new IllegalStateException("A transaction is already open which has not been committed"); +// } + //parameter check + if(pdp == null){ + throw new IllegalArgumentException("PDP pdp must not be null"); + } + if(isNullOrEmpty(pdp.getId(),username)){ + throw new IllegalArgumentException("pdp.getId() and username must not be null or empty"); + } + + synchronized(emLock){ + checkBeforeOperationRun(); + Query getPdpQuery = em.createQuery("SELECT p FROM PdpEntity p WHERE p.pdpId=:pdpId AND p.deleted=:deleted"); + getPdpQuery.setParameter("pdpId", pdp.getId()); + getPdpQuery.setParameter("deleted", false); + List getPdpQueryList; + try{ + getPdpQueryList = getPdpQuery.getResultList(); + } catch(Exception e){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Caught Exception on getPdpQuery.getResultList()",e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Caught Exception on getPdpQuery.getResultList()"); + throw new PersistenceException("Query failed trying to get PDP "+pdp.getId()); + } + if(getPdpQueryList.size() < 1){ + //TODO:EELF Cleanup - Remove logger + //logger.error("The pdp cannot be found to update with id "+pdp.getId()); + PolicyLogger.error("The pdp cannot be found to update with id "+pdp.getId()); + throw new PersistenceException("The pdp cannot be found to update with id "+pdp.getId()); + } else if(getPdpQueryList.size() > 1){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Somehow, more than one pdp with the same id "+pdp.getId()+" and deleted status were found in the database"); + PolicyLogger.error("Somehow, more than one pdp with the same id "+pdp.getId()+" and deleted status were found in the database"); + throw new PersistenceException("Somehow, more than one pdp with the same id "+pdp.getId()+" and deleted status were found in the database"); + } + //em.getTransaction().begin(); + PdpEntity pdpToUpdate = (PdpEntity)getPdpQueryList.get(0); + if(!stringEquals(pdpToUpdate.getModifiedBy(), username)){ + pdpToUpdate.setModifiedBy(username); + } + if(pdp.getDescription() != null && !stringEquals(pdp.getDescription(),pdpToUpdate.getDescription())){ + pdpToUpdate.setDescription(pdp.getDescription()); + } + if(pdp.getName() != null && !stringEquals(pdp.getName(),pdpToUpdate.getPdpName())){ + pdpToUpdate.setPdpName(pdp.getName()); + } + if(pdp.getJmxPort() != null && !pdp.getJmxPort().equals(pdpToUpdate.getJmxPort())){ + pdpToUpdate.setJmxPort(pdp.getJmxPort()); + } + + em.flush(); + this.pdpId = pdpToUpdate.getPdpKey(); + } + } + + @Override + public void movePdp(EcompPDP pdp, EcompPDPGroup group, String username){ + logger.debug("movePdp(PDP pdp, PDPGroup group, String username) as movePdp("+pdp+","+group+","+username+") called"); +// if(isTransactionOpen()){ +// logger.error("A transaction is already open which has not been committed"); +// throw new IllegalStateException("A transaction is already open which has not been committed"); +// } + if(pdp == null || group == null){ + throw new IllegalArgumentException("PDP pdp and PDPGroup group must not be null"); + } + if(isNullOrEmpty(username,pdp.getId(),group.getId())){ + throw new IllegalArgumentException("pdp.getId(), group.getId(), and username must not be null or empty"); + } + + synchronized(emLock){ + checkBeforeOperationRun(); + //check if pdp exists + Query getPdpQuery = em.createQuery("SELECT p FROM PdpEntity p WHERE p.pdpId=:pdpId AND p.deleted=:deleted"); + getPdpQuery.setParameter("pdpId", pdp.getId()); + getPdpQuery.setParameter("deleted", false); + List getPdpQueryList; + try{ + getPdpQueryList = getPdpQuery.getResultList(); + } catch(Exception e){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Caught Exception on getPdpQuery.getResultList()",e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Caught Exception on getPdpQuery.getResultList()"); + throw new PersistenceException("Query failed trying to get pdp to move with id "+pdp.getId()); + } + if(getPdpQueryList.size() < 1){ + //TODO:EELF Cleanup - Remove logger + //logger.error("The pdp cannot be found to move with id "+pdp.getId()); + PolicyLogger.error("The pdp cannot be found to move with id "+pdp.getId()); + throw new PersistenceException("The pdp cannot be found to move with id "+pdp.getId()); + } else if(getPdpQueryList.size() > 1){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Somehow, more than one pdp with the same id "+pdp.getId()+" and deleted status were found in the database"); + PolicyLogger.error("Somehow, more than one pdp with the same id "+pdp.getId()+" and deleted status were found in the database"); + throw new PersistenceException("Somehow, more than one pdp with the same id "+pdp.getId()+" and deleted status were found in the database"); + } + + //check if new group exists + Query checkGroupQuery = em.createQuery("SELECT g FROM GroupEntity g WHERE g.groupId=:groupId AND g.deleted=:deleted"); + checkGroupQuery.setParameter("groupId", group.getId()); + checkGroupQuery.setParameter("deleted", false); + List checkGroupQueryList; + try{ + checkGroupQueryList = checkGroupQuery.getResultList(); + } catch(Exception e){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Caught Exception trying to get group on checkGroupQuery.getResultList()",e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Caught Exception trying to get group on checkGroupQuery.getResultList()"); + throw new PersistenceException("Query failed trying to get new group "+group.getId()); + } + if(checkGroupQueryList.size() != 1){ + //TODO:EELF Cleanup - Remove logger + //logger.error("The group "+group.getId()+" does not exist"); + PolicyLogger.error("The group "+group.getId()+" does not exist"); + throw new PersistenceException("The group "+group.getId()+" does not exist"); + } + GroupEntity groupToMoveInto = (GroupEntity)checkGroupQueryList.get(0); + //move it + //em.getTransaction().begin(); + PdpEntity pdpToUpdate = (PdpEntity)getPdpQueryList.get(0); + pdpToUpdate.setGroup(groupToMoveInto); + if(!stringEquals(pdpToUpdate.getModifiedBy(), username)){ + pdpToUpdate.setModifiedBy(username); + } + + em.flush(); + this.pdpId = pdpToUpdate.getPdpKey(); + } + } + + @Override + public void changeDefaultGroup(EcompPDPGroup group, String username){ + logger.debug("changeDefaultGroup(PDPGroup group, String username) as changeDefaultGroup("+group+","+username+") called"); +// if(isTransactionOpen()){ +// logger.error("A transaction is already open which has not been committed"); +// throw new IllegalStateException("A transaction is already open which has not been committed"); +// } + //parameter check + if(group == null){ + throw new IllegalArgumentException("PDPGroup group must not be null"); + } + if(isNullOrEmpty(group.getId(),username)){ + throw new IllegalArgumentException("group.getId() and username must not be null or empty"); + } + + synchronized(emLock){ + checkBeforeOperationRun(); + Query getGroupQuery = em.createQuery("SELECT g FROM GroupEntity g WHERE g.groupId=:groupId AND g.deleted=:deleted"); + getGroupQuery.setParameter("groupId", group.getId()); + getGroupQuery.setParameter("deleted", false); + List getGroupQueryList; + try{ + getGroupQueryList = getGroupQuery.getResultList(); + } catch(Exception e){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Caught Exception on getGroupQuery.getResultList()",e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Caught Exception on getGroupQuery.getResultList()"); + throw new PersistenceException("Query failed trying to get group "+group.getId()); + } + if(getGroupQueryList.size() < 1){ + //TODO:EELF Cleanup - Remove logger + //logger.error("The group cannot be found to set default with id "+group.getId()); + PolicyLogger.error("The group cannot be found to set default with id "+group.getId()); + throw new PersistenceException("The group cannot be found to set default with id "+group.getId()); + } else if(getGroupQueryList.size() > 1){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Somehow, more than one group with the same id "+group.getId()+" and deleted status were found in the database"); + PolicyLogger.error("Somehow, more than one group with the same id "+group.getId()+" and deleted status were found in the database"); + throw new PersistenceException("Somehow, more than one group with the same id "+group.getId()+" and deleted status were found in the database"); + } + //em.getTransaction().begin(); + GroupEntity newDefaultGroup = (GroupEntity)getGroupQueryList.get(0); + newDefaultGroup.setDefaultGroup(true); + if(!stringEquals(newDefaultGroup.getModifiedBy(), username)){ + newDefaultGroup.setModifiedBy(username); + } + + em.flush(); + this.groupId = newDefaultGroup.getGroupKey(); + Query setAllGroupsNotDefault = em.createQuery("UPDATE GroupEntity g SET g.defaultGroup=:defaultGroup WHERE g.deleted=:deleted AND g.groupKey<>:groupKey"); + //not going to set modified by for all groups + setAllGroupsNotDefault.setParameter("defaultGroup", false); + setAllGroupsNotDefault.setParameter("deleted", false); + setAllGroupsNotDefault.setParameter("groupKey", newDefaultGroup.getGroupKey()); + try{ + logger.info("set " + setAllGroupsNotDefault.executeUpdate() + " groups as not default"); + } catch(Exception e){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Caught Exception on setAllGroupsNotDefault.executeUpdate()",e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Caught Exception on setAllGroupsNotDefault.executeUpdate()"); + throw new PersistenceException("Could not set all other groups default to false"); + } + + em.flush(); + } + } + + + @Override + public void deleteGroup(EcompPDPGroup group, EcompPDPGroup moveToGroup, String username) throws PAPException { + logger.debug("deleteGroup(PDPGroup group, PDPGroup moveToGroup, String username) as deleteGroup("+group+", "+moveToGroup+","+username+") called"); +// if(isTransactionOpen()){ +// logger.error("A transaction is already open which has not been committed"); +// throw new IllegalStateException("A transaction is already open which has not been committed"); +// } + if(group == null){ + throw new IllegalArgumentException("PDPGroup group cannot be null"); + } + if(isNullOrEmpty(username,group.getId())){ + throw new IllegalArgumentException("group.getId() and and username must not be null or empty"); + } + + if(group.isDefaultGroup()){ + //TODO:EELF Cleanup - Remove logger + //logger.error("The default group "+group.getId()+" was attempted to be deleted. It cannot be."); + PolicyLogger.error("The default group "+group.getId()+" was attempted to be deleted. It cannot be."); + throw new PAPException("You cannot delete the default group."); + } + synchronized(emLock){ + checkBeforeOperationRun(); + Query deleteGroupQuery = em.createQuery("SELECT g FROM GroupEntity g WHERE g.groupId=:groupId AND g.deleted=:deleted"); + deleteGroupQuery.setParameter("groupId", group.getId()); + deleteGroupQuery.setParameter("deleted", false); + List deleteGroupQueryList; + try{ + deleteGroupQueryList = deleteGroupQuery.getResultList(); + } catch(Exception e){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Caught Exception trying to check if group exists deleteGroupQuery.getResultList()",e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Caught Exception trying to check if group exists deleteGroupQuery.getResultList()"); + throw new PersistenceException("Query failed trying to check if group exists"); + } + if(deleteGroupQueryList.size() < 1){ + logger.warn("The group could not be found with id " + group.getId()); + return; + } else if(deleteGroupQueryList.size() > 1){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Somehow, more than one group with the id "+group.getId()+" were found in the database that are not deleted"); + PolicyLogger.error("Somehow, more than one group with the id "+group.getId()+" were found in the database that are not deleted"); + throw new PersistenceException("Somehow, more than one group with the id "+group.getId()+" were found in the database that are not deleted"); + } + + Query pdpsInGroupQuery = em.createQuery("SELECT p FROM PdpEntity p WHERE p.groupEntity=:group and p.deleted=:deleted"); + pdpsInGroupQuery.setParameter("group", ((GroupEntity)deleteGroupQueryList.get(0))); + pdpsInGroupQuery.setParameter("deleted", false); + List pdpsInGroupList; + try{ + pdpsInGroupList = pdpsInGroupQuery.getResultList(); + } catch(Exception e){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Caught Exception trying to get PDPs in group on pdpsInGroupQuery.getResultList()",e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Caught Exception trying to get PDPs in group on pdpsInGroupQuery.getResultList()"); + throw new PersistenceException("Query failed trying to get PDPs in group"); + } + //em.getTransaction().begin(); + if(pdpsInGroupList.size() > 0){ + if(moveToGroup != null){ + Query checkMoveToGroupQuery = em.createQuery("SELECT o FROM GroupEntity o WHERE o.groupId=:groupId AND o.deleted=:deleted"); + checkMoveToGroupQuery.setParameter("groupId", moveToGroup.getId()); + checkMoveToGroupQuery.setParameter("deleted", false); + List checkMoveToGroupList; + try{ + checkMoveToGroupList = checkMoveToGroupQuery.getResultList(); + } catch(Exception e){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Caught Exception trying to check if group exists checkMoveToGroupQuery.getResultList()",e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Caught Exception trying to check if group exists checkMoveToGroupQuery.getResultList()"); + throw new PersistenceException("Query failed trying to check if group exists"); + } + if(checkMoveToGroupList.size() < 1){ + //TODO:EELF Cleanup - Remove logger + //logger.error("The group could not be found with id " + moveToGroup.getId()); + PolicyLogger.error("The group could not be found with id " + moveToGroup.getId()); + throw new PersistenceException("The group could not be found with id " + moveToGroup.getId()); + } else if(checkMoveToGroupList.size() > 1){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Somehow, more than one group with the id "+moveToGroup.getId()+" were found in the database that are not deleted"); + PolicyLogger.error("Somehow, more than one group with the id "+moveToGroup.getId()+" were found in the database that are not deleted"); + throw new PersistenceException("Somehow, more than one group with the id "+moveToGroup.getId()+" were found in the database that are not deleted"); + } else { + GroupEntity newGroup = (GroupEntity)checkMoveToGroupList.get(0); + for(Object pdpObject : pdpsInGroupList){ + PdpEntity pdp = (PdpEntity)pdpObject; + pdp.setGroup(newGroup); + if(!stringEquals(pdp.getModifiedBy(),username)){ + pdp.setModifiedBy(username); + } + try{ + + em.flush(); + this.newGroupId = newGroup.getGroupId(); + } catch(PersistenceException e){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Caught PersistenceException trying to set pdp group to null on em.flush()",e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Caught PersistenceException trying to set pdp group to null on em.flush()"); + throw new PersistenceException("Query failed trying to set pdp group to "); + } + } + } + } else { + //TODO:EELF Cleanup - Remove logger + //logger.error("Group "+group.getId()+" is trying to be delted with PDPs. No group was provided to move them to"); + PolicyLogger.error("Group "+group.getId()+" is trying to be delted with PDPs. No group was provided to move them to"); + throw new PAPException("Group has PDPs. Must provide a group for them to move to"); + } + } + + //delete group here + + GroupEntity groupToDelete = (GroupEntity)deleteGroupQueryList.get(0); + groupToDelete.setDeleted(true); + if(!stringEquals(groupToDelete.getModifiedBy(), username)){ + groupToDelete.setModifiedBy(username); + } + + //try{ + + em.flush(); + this.groupId = groupToDelete.getGroupKey(); + //return; + //} catch(PersistenceException pe){ + //logger.error("Database error while marking policy or config as deleted"); + //throw new PersistenceException("Database error while marking policy or config as deleted"); + //} + } + } + + @Override + public void addPolicyToGroup(String groupID, String policyID, String username) { + logger.debug("addPolicyToGroup(String groupID, String policyID, String username) as addPolicyToGroup("+groupID+", "+policyID+","+username+") called"); +// if(isTransactionOpen()){ +// logger.error("A transaction is already open which has not been committed"); +// throw new IllegalStateException("A transaction is already open which has not been committed"); +// } + if(isNullOrEmpty(groupID, policyID, username)){ + throw new IllegalArgumentException("groupID, policyID, and username must not be null or empty"); + } + synchronized(emLock){ + checkBeforeOperationRun(); + //check if group exists + Query groupQuery = em.createQuery("SELECT g FROM GroupEntity g WHERE g.groupId=:groupId AND g.deleted=:deleted"); + groupQuery.setParameter("groupId", groupID); + groupQuery.setParameter("deleted", false); + List groupQueryList; + try{ + groupQueryList = groupQuery.getResultList(); + }catch(Exception e){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Caught Exception trying to check if group exists groupQuery.getResultList()",e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Caught Exception trying to check if group exists groupQuery.getResultList()"); + throw new PersistenceException("Query failed trying to check if group "+groupID+" exists"); + } + if(groupQueryList.size() < 1){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Group policy is being added to does not exist with id "+groupID); + PolicyLogger.error("Group policy is being added to does not exist with id "+groupID); + throw new PersistenceException("Group policy is being added to does not exist with id "+groupID); + } else if(groupQueryList.size() > 1){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Somehow, more than one group with the id "+groupID+" were found in the database that are not deleted"); + PolicyLogger.error("Somehow, more than one group with the id "+groupID+" were found in the database that are not deleted"); + throw new PersistenceException("Somehow, more than one group with the id "+groupID+" were found in the database that are not deleted"); + } + //we need to convert the form of the policy id that is used groups into the form that is used + //for the database. (com.Config_mypol.1.xml) to (Config_mypol.xml) + String[] policyNameScopeAndVersion = getNameScopeAndVersionFromPdpPolicy(policyID); + Query policyQuery = em.createQuery("SELECT p FROM PolicyEntity p WHERE p.policyName=:policyName AND p.scope=:scope AND p.deleted=:deleted"); + policyQuery.setParameter("policyName", policyNameScopeAndVersion[0]); + policyQuery.setParameter("scope", policyNameScopeAndVersion[1]); + policyQuery.setParameter("deleted", false); + List policyQueryList; + try{ + policyQueryList = policyQuery.getResultList(); + } catch(Exception e){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Caught Exception trying to check if policy exists policyQuery.getResultList()",e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Caught Exception trying to check if policy exists policyQuery.getResultList()"); + throw new PersistenceException("Query failed trying to check if policy "+policyNameScopeAndVersion[0]+" exists"); + } + if(policyQueryList.size() < 1){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Policy being added to the group does not exist with policy id "+policyNameScopeAndVersion[0]); + PolicyLogger.error("Policy being added to the group does not exist with policy id "+policyNameScopeAndVersion[0]); + throw new PersistenceException("Policy being added to the group does not exist with policy id "+policyNameScopeAndVersion[0]); + } else if(policyQueryList.size() > 1){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Somehow, more than one policy with the id "+policyNameScopeAndVersion[0]+" were found in the database that are not deleted"); + PolicyLogger.error("Somehow, more than one policy with the id "+policyNameScopeAndVersion[0]+" were found in the database that are not deleted"); + throw new PersistenceException("Somehow, more than one group with the id "+policyNameScopeAndVersion[0]+" were found in the database that are not deleted"); + } + //em.getTransaction().begin(); + GroupEntity group = (GroupEntity)groupQueryList.get(0); + PolicyEntity policy = (PolicyEntity)policyQueryList.get(0); + group.addPolicyToGroup(policy); + em.flush(); + } + } + + //this means delete pdp not just remove from group + @Override + public void removePdpFromGroup(String pdpID, String username) { + logger.debug("removePdpFromGroup(String pdpID, String username) as removePdpFromGroup("+pdpID+","+username+") called"); +// if(isTransactionOpen()){ +// logger.error("A transaction is already open which has not been committed"); +// throw new IllegalStateException("A transaction is already open which has not been committed"); +// } + if(isNullOrEmpty(pdpID,username)){ + throw new IllegalArgumentException("pdpID and username must not be null or empty"); + } + synchronized(emLock){ + checkBeforeOperationRun(); + Query pdpQuery = em.createQuery("SELECT p FROM PdpEntity p WHERE p.pdpId=:pdpId AND p.deleted=:deleted"); + pdpQuery.setParameter("pdpId", pdpID); + pdpQuery.setParameter("deleted", false); + List pdpList; + try{ + pdpList = pdpQuery.getResultList(); + } catch(Exception e){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Caught Exception trying to check if pdp exists pdpQuery.getResultList()",e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Caught Exception trying to check if pdp exists pdpQuery.getResultList()"); + throw new PersistenceException("Query failed trying to check if pdp "+pdpID+" exists"); + } + if(pdpList.size() > 1){ + //TODO:EELF Cleanup - Remove logger + //logger.error("Somehow, more than one pdp with the id "+pdpID+" were found in the database that are not deleted"); + PolicyLogger.error("Somehow, more than one pdp with the id "+pdpID+" were found in the database that are not deleted"); + throw new PersistenceException("Somehow, more than one pdp with the id "+pdpID+" were found in the database that are not deleted"); + } else if(pdpList.size() < 1){ + //logger.warn("Pdp being removed does not exist with id "+pdpID); + PolicyLogger.error("Pdp being removed does not exist with id "+pdpID); + return; + } + //em.getTransaction().begin(); + PdpEntity pdp = (PdpEntity)pdpList.get(0); + pdp.setGroup(null); + if(!stringEquals(pdp.getModifiedBy(),username)){ + pdp.setModifiedBy(username); + } + pdp.setDeleted(true); + + em.flush(); + this.pdpId = pdp.getPdpKey(); + } + } + } + + + + private static String getDefaultWorkspace(){ + return "admin"; + } + + private PolicyDBDao(){ + + } + public static PolicyDBDaoTestClass getPolicyDBDaoTestClass(){ + return new PolicyDBDao().new PolicyDBDaoTestClass(); + } + final class PolicyDBDaoTestClass { + String[] getScopeAndNameAndType(final String path){ + return PolicyDBDao.getScopeAndNameAndType(path); + } + String getGitPath(){ + return PolicyDBDao.getGitPath(); + } + String getConfigFile(String filename, String scope, PolicyRestAdapter policy){ + return PolicyDBDao.this.getConfigFile(filename, scope, policy); + } + String computeScope(String fullPath, String pathToExclude){ + return PolicyDBDao.computeScope(fullPath, pathToExclude); + } + String encryptPassword(String password) throws Exception{ + return PolicyDBDao.encryptPassword(password); + } + String decryptPassword(String password) throws Exception{ + return PolicyDBDao.decryptPassword(password); + } + String getDescriptionFromXacml(String xacmlData){ + return PolicyDBDao.getDescriptionFromXacml(xacmlData); + } + + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/PolicyDBDaoTransaction.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/PolicyDBDaoTransaction.java new file mode 100644 index 000000000..4e9ddb489 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/PolicyDBDaoTransaction.java @@ -0,0 +1,202 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.components; + +import java.util.List; +import java.util.Set; + +import javax.persistence.PersistenceException; + +import org.openecomp.policy.pap.xacml.rest.adapters.PolicyRestAdapter; +import org.openecomp.policy.rest.jpa.GroupEntity; +import org.openecomp.policy.rest.jpa.PdpEntity; +import org.openecomp.policy.xacml.api.pap.EcompPDP; +import org.openecomp.policy.xacml.api.pap.EcompPDPGroup; + +import com.att.research.xacml.api.pap.PAPException; +//import com.att.research.xacml.api.pap.PDP; +//import com.att.research.xacml.api.pap.PDPGroup; + +public interface PolicyDBDaoTransaction { + + /** + * Commits (makes permanent) the current transaction. Also, notifies other PolicyDBDao instances on other PAP servers of the update. + * @throws IllegalStateException if the PolicyDBDao transaction has not been used or has been committed already. + * @throws PersistenceException if the commit fails for some reason + */ + public void commitTransaction(); + + /** + * Create or update a policy + * @param policy A Policy object representing the policy to store or update + * @param username A string of the username you want to be stored for doing this operation + * @throws IllegalStateException If a transaction is open that has not yet been committed + * @throws PersistenceException If a database error occurs + * @throws IllegalArgumentException If the Policy's PolicyRestAdapter contains incorrect data. + */ + public void createPolicy(Policy policy, String username) throws IllegalStateException, PersistenceException, IllegalArgumentException; + + /** + * Create or update a policy + * @param filePath The file path of the policy xml file + * @param username A string of the username you want to be stored for doing this operation + * @throws IllegalStateException If a transaction is open that has not yet been committed + * @throws PersistenceException If a database error occurs + * @throws IllegalArgumentException If the file path is incorrect, or if it refers to a Config policy + */ + public void createPolicy(String filePath, String username) throws IllegalStateException, PersistenceException, IllegalArgumentException; + + /** + * Check if the PolicyDBDaoTransaction is currently open + * @return False if the PolicyDBDao transaction has not been used or has been committed already, true if it is open. + */ + public boolean isTransactionOpen(); + + + + /** + * Delete an existing policy + * @param policyToDelete The file path of the policy to delete + * @throws IllegalArgumentException If the file path given can not be parsed + * @throws IllegalStateException If a transaction is open that has not yet been committed + * @throws PersistenceException If a database error occurs + */ + public void deletePolicy(String policyToDelete) throws IllegalStateException, PersistenceException, IllegalArgumentException; + + /** + * Rollback (undo) the current transaction. + */ + public void rollbackTransaction(); + + /** + * Close the PolicyDBDaoTransaction without rolling back or doing anything. Just used to close the EntityManager + */ + public void close(); + + + /** + * Create a new PDP group in the database + * @param groupID The ID to name the new group (use PolicyDBDao.createNewPDPGroupId) + * @param groupName The name to use for the new group + * @param groupDescription Description of the new group (optional) + * @param username Username of the user performing the operation + * @throws IllegalArgumentException If non-optional parameters are null or empty strings + * @throws IllegalStateException If a transaction is already open + * @throws PersistenceException If a database error occurs + */ + public void createGroup(String groupID, String groupName, String groupDescription, String username) throws IllegalArgumentException, IllegalStateException, PersistenceException; + + /** + * Updates a group in the database with a new name of description + * @param group The group with updated information. The id must match an existing group, but the name and description can be changed. + * @param username Username of the user performing the operation + * @throws IllegalArgumentException If non-optional parameters are null or empty strings + * @throws IllegalStateException If a transaction is already open + * @throws PersistenceException If a database error occurs or if the group can not be found + */ + public void updateGroup(EcompPDPGroup group, String username) throws IllegalArgumentException, IllegalStateException, PersistenceException; + + /** + * Updates a PDP in the database with new information + * @param pdp The PDP to update + * @param username Username of the user performing the operation + * @throws IllegalArgumentException If non-optional parameters are null or empty strings + * @throws IllegalStateException If a transaction is already open + * @throws PersistenceException If a database error occurs or if the pdp can not be found + */ + public void updatePdp(EcompPDP pdp, String username) throws IllegalArgumentException, IllegalStateException, PersistenceException; + + /** + * Change the default group in the database to the group provided. + * @param group The new group which should be set as default in the database + * @param username Username of the user performing the operation + * @throws IllegalArgumentException If non-optional parameters are null or empty strings + * @throws IllegalStateException If a transaction is already open + * @throws PersistenceException If a database error occurs + */ + public void changeDefaultGroup(EcompPDPGroup group, String username) throws IllegalArgumentException, IllegalStateException, PersistenceException; + + /** + * Moves a PDP to a new group. + * @param pdp The PDP which is to be moved to a new group + * @param group The new group which the PDP should be added to + * @param username Username of the user performing the operation + * @throws IllegalArgumentException If non-optional parameters are null or empty strings + * @throws IllegalStateException If a transaction is already open + * @throws PersistenceException If a database error occurs + */ + public void movePdp(EcompPDP pdp, EcompPDPGroup group, String username) throws IllegalArgumentException, IllegalStateException, PersistenceException; + + /** + * Add a new PDP to an existing group + * @param pdpID The ID to name the new PDP + * @param groupID The ID of the existing group to add the PDP to + * @param pdpName The name to use for the new PDP + * @param pdpDescription Description of the new PDP (optional) + * @param pdpJmxPort + * @param username Username of the user performing the operation + * @throws IllegalArgumentException If non-optional parameters are null or empty strings + * @throws IllegalStateException If a transaction is already open + * @throws PersistenceException If a database error occurs + */ + public void addPdpToGroup(String pdpID, String groupID, String pdpName, String pdpDescription, int pdpJmxPort, String username) throws IllegalArgumentException, IllegalStateException, PersistenceException; + + /** + * Add an existing policy to an existing group + * @param group The ID of the existing group to add the policy to + * @param policyID The ID of an existing policy + * @throws IllegalArgumentException If non-optional parameters are null or empty strings + * @throws IllegalStateException If a transaction is already open + * @throws PersistenceException If a database error occurs + */ + public void addPolicyToGroup(String group, String policyID, String username) throws IllegalArgumentException, IllegalStateException, PersistenceException; + + + /** + * Delete an existing PDP group + * @param group A PDPGroup object representing the group to delete + * @param moveToGroup A PDPGroup object representing another existing group which PDPs in the group being deleted should be moved to + * @throws IllegalArgumentException If non-optional parameters are null or empty strings + * @throws IllegalStateException If a transaction is already open + * @throws PersistenceException If a database error occurs + * @throws PAPException If an error relating to how groups are handled occurs + */ + public void deleteGroup(EcompPDPGroup group, EcompPDPGroup moveToGroup, String username)throws IllegalArgumentException, IllegalStateException, PersistenceException, PAPException; + + /** + * Removes an existing PDP from its group and deletes it. + * @param pdpID The ID of the existing PDP which should be deleted + * @throws IllegalArgumentException If non-optional parameters are null or empty strings + * @throws IllegalStateException If a transaction is already open + * @throws PersistenceException If a database error occurs + */ + public void removePdpFromGroup(String pdpID, String username) throws IllegalArgumentException, IllegalStateException, PersistenceException; + + public GroupEntity getGroup(long groupKey); + public GroupEntity getGroup(String groupId); + public List getPdpsInGroup(long groupKey); + public PdpEntity getPdp(long pdpKey); + + void renamePolicy(String oldPath, String newPath,String username); + + void clonePolicy(String oldPolicyPath, String newPolicyPath, String username); + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/package-info.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/package-info.java new file mode 100644 index 000000000..98e1bd985 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/package-info.java @@ -0,0 +1,27 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + * + */ +/** + * + */ +package org.openecomp.policy.pap.xacml.rest.components; diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/ActionPolicyDictionaryController.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/ActionPolicyDictionaryController.java new file mode 100644 index 000000000..fa00fc1cc --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/ActionPolicyDictionaryController.java @@ -0,0 +1,201 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.controller; + +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.json.JSONObject; +import org.openecomp.policy.pap.xacml.rest.util.JsonMessage; +import org.openecomp.policy.rest.dao.ActionPolicyDictDao; +import org.openecomp.policy.rest.dao.UserInfoDao; +import org.openecomp.policy.rest.jpa.ActionPolicyDict; +import org.openecomp.policy.rest.jpa.UserInfo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +@Controller +public class ActionPolicyDictionaryController { + + @Autowired + ActionPolicyDictDao actionPolicyDictDao; + + @Autowired + UserInfoDao userInfoDao; + + public UserInfo getUserInfo(String loginId){ + UserInfo name = userInfoDao.getUserInfoByLoginId(loginId); + return name; + } + + @RequestMapping(value={"/get_ActionPolicyDictDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getActionEntitybyName(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("actionPolicyDictionaryDatas", mapper.writeValueAsString(actionPolicyDictDao.getActionDictDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_ActionPolicyDictData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getActionPolicyDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("actionPolicyDictionaryDatas", mapper.writeValueAsString(actionPolicyDictDao.getActionDictData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/action_dictionary/save_ActionDict.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveActionPolicyDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + ActionPolicyDict actionPolicyDict = (ActionPolicyDict)mapper.readValue(root.get("actionPolicyDictionaryData").toString(), ActionPolicyDict.class); + ActionAdapter adapter = mapper.readValue(root.get("actionPolicyDictionaryData").toString(), ActionAdapter.class); + String userId = root.get("loginId").textValue(); + String header = ""; + int counter = 0; + if(adapter.getHeaders().size() > 0){ + for(Object attribute : adapter.getHeaders()){ + if(attribute instanceof LinkedHashMap){ + String key = ((LinkedHashMap) attribute).get("option").toString(); + String value = ((LinkedHashMap) attribute).get("number").toString(); + if(counter>0){ + header = header + ":"; + } + header = header + key + "="; + header = header + value; + counter ++; + } + } + } + actionPolicyDict.setHeader(header); + if(actionPolicyDict.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(actionPolicyDict.getAttributeName(), "attributeName", ActionPolicyDict.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + actionPolicyDict.setUserCreatedBy(this.getUserInfo(userId)); + actionPolicyDict.setUserModifiedBy(this.getUserInfo(userId)); + actionPolicyDictDao.Save(actionPolicyDict); + } + }else{ + actionPolicyDict.setUserModifiedBy(this.getUserInfo(userId)); + actionPolicyDictDao.update(actionPolicyDict); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.actionPolicyDictDao.getActionDictData()); + } + JSONObject j = new JSONObject("{actionPolicyDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/action_dictionary/remove_actionPolicyDict.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removeActionPolicyDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + ActionPolicyDict actionPolicyDict = (ActionPolicyDict)mapper.readValue(root.get("data").toString(), ActionPolicyDict.class); + actionPolicyDictDao.delete(actionPolicyDict); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.actionPolicyDictDao.getActionDictData()); + JSONObject j = new JSONObject("{actionPolicyDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } +} + +class ActionAdapter{ + private ArrayList headers; + + public ArrayList getHeaders() { + return headers; + } + + public void setHeaders(ArrayList headers) { + this.headers = headers; + } +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/BRMSDictionaryController.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/BRMSDictionaryController.java new file mode 100644 index 000000000..bdf4d2c01 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/BRMSDictionaryController.java @@ -0,0 +1,183 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.controller; + +import java.io.PrintWriter; +import java.io.StringWriter; +import java.nio.charset.StandardCharsets; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.io.IOUtils; +import org.json.JSONObject; +import org.openecomp.policy.pap.xacml.rest.util.JsonMessage; +import org.openecomp.policy.rest.dao.BRMSParamTemplateDao; +import org.openecomp.policy.rest.dao.UserInfoDao; +import org.openecomp.policy.rest.jpa.BRMSParamTemplate; +import org.openecomp.policy.rest.jpa.UserInfo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + + +@Controller +public class BRMSDictionaryController{ + + @Autowired + BRMSParamTemplateDao brmsParamTemplateDao; + + @Autowired + UserInfoDao userInfoDao; + + private String rule; + + public UserInfo getUserInfo(String loginId){ + UserInfo name = userInfoDao.getUserInfoByLoginId(loginId); + return name; + } + + @RequestMapping(value={"/get_BRMSParamDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getBRMSParamDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("brmsParamDictionaryDatas", mapper.writeValueAsString(brmsParamTemplateDao.getBRMSParamDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_BRMSParamData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getBRMSParamDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("brmsParamDictionaryDatas", mapper.writeValueAsString(brmsParamTemplateDao.getBRMSParamTemplateData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/brms_dictionary/set_BRMSParamData.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public void SetRuleData(HttpServletRequest request, HttpServletResponse response) throws Exception{ + StringWriter writer = new StringWriter(); + IOUtils.copy(request.getInputStream() , writer, StandardCharsets.UTF_8); + String cleanStreamBoundary = writer.toString().replaceFirst("------(.*)(?s).*octet-stream", ""); + rule = cleanStreamBoundary.substring(0, cleanStreamBoundary.lastIndexOf("end")+4); + } + + @RequestMapping(value={"/brms_dictionary/save_BRMSParam.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveBRMSParamDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + BRMSParamTemplate bRMSParamTemplateData = (BRMSParamTemplate)mapper.readValue(root.get("brmsParamDictionaryData").toString(), BRMSParamTemplate.class); + String userId = root.get("loginId").textValue(); + bRMSParamTemplateData.setRule(rule); + if(bRMSParamTemplateData.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(bRMSParamTemplateData.getRuleName(), "ruleName", BRMSParamTemplate.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + bRMSParamTemplateData.setUserCreatedBy(this.getUserInfo(userId)); + brmsParamTemplateDao.Save(bRMSParamTemplateData); + } + }else{ + brmsParamTemplateDao.update(bRMSParamTemplateData); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.brmsParamTemplateDao.getBRMSParamTemplateData()); + } + JSONObject j = new JSONObject("{brmsParamDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/brms_dictionary/remove_brmsParam.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removeBRMSParamDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + BRMSParamTemplate bRMSParamTemplateData = (BRMSParamTemplate)mapper.readValue(root.get("data").toString(), BRMSParamTemplate.class); + brmsParamTemplateDao.delete(bRMSParamTemplateData); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.brmsParamTemplateDao.getBRMSParamTemplateData()); + JSONObject j = new JSONObject("{brmsParamDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/CheckDictionaryDuplicateEntries.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/CheckDictionaryDuplicateEntries.java new file mode 100644 index 000000000..e044340a9 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/CheckDictionaryDuplicateEntries.java @@ -0,0 +1,65 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.controller; + +/* + * + * + * + * */ +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.Transaction; +import org.hibernate.criterion.Restrictions; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +public class CheckDictionaryDuplicateEntries { + + private static final Log logger = LogFactory.getLog(CheckDictionaryDuplicateEntries.class); + + @SuppressWarnings({ "unchecked", "rawtypes" }) + public List CheckDuplicateEntry(String value, String columnName, Class class1) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = null; + try { + Criteria cr = session.createCriteria(class1); + cr.add(Restrictions.eq(columnName,value)); + data = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying for Duplicate Entries for Table"+e + class1); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/ClosedLoopDictionaryController.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/ClosedLoopDictionaryController.java new file mode 100644 index 000000000..d70661f88 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/ClosedLoopDictionaryController.java @@ -0,0 +1,764 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.controller; + +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.json.JSONObject; +import org.openecomp.policy.pap.xacml.rest.adapters.GridData; +import org.openecomp.policy.pap.xacml.rest.util.JsonMessage; +import org.openecomp.policy.rest.dao.PEPOptionsDao; +import org.openecomp.policy.rest.dao.ServiceDictionaryDao; +import org.openecomp.policy.rest.dao.SiteDictionaryDao; +import org.openecomp.policy.rest.dao.UserInfoDao; +import org.openecomp.policy.rest.dao.VNFTypeDao; +import org.openecomp.policy.rest.dao.VSCLActionDao; +import org.openecomp.policy.rest.dao.VarbindDictionaryDao; +import org.openecomp.policy.rest.jpa.ClosedLoopD2Services; +import org.openecomp.policy.rest.jpa.ClosedLoopSite; +import org.openecomp.policy.rest.jpa.PEPOptions; +import org.openecomp.policy.rest.jpa.UserInfo; +import org.openecomp.policy.rest.jpa.VNFType; +import org.openecomp.policy.rest.jpa.VSCLAction; +import org.openecomp.policy.rest.jpa.VarbindDictionary; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +@Controller +public class ClosedLoopDictionaryController{ + + @Autowired + VSCLActionDao vsclActionDao; + + @Autowired + VNFTypeDao vnfTypeDao; + + @Autowired + PEPOptionsDao pepOptionsDao; + + @Autowired + VarbindDictionaryDao varbindDao; + + @Autowired + ServiceDictionaryDao closedLoopServiceDao; + + @Autowired + SiteDictionaryDao closedLoopSiteDao; + + @Autowired + UserInfoDao userInfoDao; + + public UserInfo getUserInfo(String loginId){ + UserInfo name = userInfoDao.getUserInfoByLoginId(loginId); + return name; + } + + + @RequestMapping(value={"/get_VSCLActionDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getVSCLActionDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("vsclActionDictionaryDatas", mapper.writeValueAsString(vsclActionDao.getVsclActionDataByName())); + org.openecomp.policy.pap.xacml.rest.util.JsonMessage msg = new org.openecomp.policy.pap.xacml.rest.util.JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + + @RequestMapping(value={"/get_VSCLActionData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getVSCLActionDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("vsclActionDictionaryDatas", mapper.writeValueAsString(vsclActionDao.getVSCLActionData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_VNFTypeDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getVNFTypeDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("vnfTypeDictionaryDatas", mapper.writeValueAsString(vnfTypeDao.getVNFTypeDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_VNFTypeData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getVNFTypeDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("vnfTypeDictionaryDatas", mapper.writeValueAsString(vnfTypeDao.getVNFTypeData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_PEPOptionsDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getPEPOptionsDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("pepOptionsDictionaryDatas", mapper.writeValueAsString(pepOptionsDao.getPEPOptionsDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_PEPOptionsData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getPEPOptionsDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("pepOptionsDictionaryDatas", mapper.writeValueAsString(pepOptionsDao.getPEPOptionsData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_VarbindDictionaryDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getVarbindDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("varbindDictionaryDatas", mapper.writeValueAsString(varbindDao.getVarbindDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_VarbindDictionaryData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getVarbindDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("varbindDictionaryDatas", mapper.writeValueAsString(varbindDao.getVarbindDictionaryData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_ClosedLoopServicesDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getClosedLoopServiceDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("closedLoopServiceDictionaryDatas", mapper.writeValueAsString(closedLoopServiceDao.getCLServiceDictDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_ClosedLoopServicesData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getClosedLoopServiceDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("closedLoopServiceDictionaryDatas", mapper.writeValueAsString(closedLoopServiceDao.getClosedLoopD2ServicesData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_ClosedLoopSiteDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getClosedLoopSiteDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("closedLoopSiteDictionaryDatas", mapper.writeValueAsString(closedLoopSiteDao.getCLSiteDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_ClosedLoopSiteData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getClosedLoopSiteDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("closedLoopSiteDictionaryDatas", mapper.writeValueAsString(closedLoopSiteDao.getClosedLoopSiteData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/cl_dictionary/save_vsclAction.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveVSCLAction(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + VSCLAction vSCLAction = (VSCLAction)mapper.readValue(root.get("vsclActionDictionaryData").toString(), VSCLAction.class); + String userId = root.get("loginId").textValue(); + if(vSCLAction.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(vSCLAction.getVsclaction(), "vsclaction", VSCLAction.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + vSCLAction.setUserCreatedBy(this.getUserInfo(userId)); + vSCLAction.setUserModifiedBy(this.getUserInfo(userId)); + vsclActionDao.Save(vSCLAction); + } + }else{ + vSCLAction.setUserModifiedBy(this.getUserInfo(userId)); + vsclActionDao.update(vSCLAction); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.vsclActionDao.getVSCLActionData()); + } + JSONObject j = new JSONObject("{vsclActionDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/cl_dictionary/remove_VsclAction.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removeVSCLAction(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + VSCLAction vSCLAction = (VSCLAction)mapper.readValue(root.get("data").toString(), VSCLAction.class); + vsclActionDao.delete(vSCLAction); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.vsclActionDao.getVSCLActionData()); + JSONObject j = new JSONObject("{vsclActionDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/cl_dictionary/save_vnfType.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveVnfType(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + VNFType vNFType = (VNFType)mapper.readValue(root.get("vnfTypeDictionaryData").toString(), VNFType.class); + String userId = root.get("loginId").textValue(); + if(vNFType.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(vNFType.getVnftype(), "vnftype", VNFType.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + vNFType.setUserCreatedBy(this.getUserInfo(userId)); + vNFType.setUserModifiedBy(this.getUserInfo(userId)); + vnfTypeDao.Save(vNFType); + } + }else{ + vNFType.setUserModifiedBy(this.getUserInfo(userId)); + vnfTypeDao.update(vNFType); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.vnfTypeDao.getVNFTypeData()); + } + JSONObject j = new JSONObject("{vnfTypeDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/cl_dictionary/remove_vnfType.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removeVnfType(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + VNFType vNFType = (VNFType)mapper.readValue(root.get("data").toString(), VNFType.class); + vnfTypeDao.delete(vNFType); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.vnfTypeDao.getVNFTypeData()); + JSONObject j = new JSONObject("{vnfTypeDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/cl_dictionary/save_pepOptions.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView savePEPOptions(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + PEPOptions pEPOptions = (PEPOptions)mapper.readValue(root.get("pepOptionsDictionaryData").toString(), PEPOptions.class); + GridData gridData = (GridData)mapper.readValue(root.get("pepOptionsDictionaryData").toString(), GridData.class); + String userId = root.get("loginId").textValue(); + String actions = ""; + int counter = 0; + if(gridData.getAttributes().size() > 0){ + for(Object attribute : gridData.getAttributes()){ + if(attribute instanceof LinkedHashMap){ + String key = ((LinkedHashMap) attribute).get("option").toString(); + String value = ((LinkedHashMap) attribute).get("number").toString(); + if(counter>0){ + actions = actions + ":#@"; + } + actions = actions + key + "=#@"; + actions = actions + value; + counter ++; + } + } + } + pEPOptions.setActions(actions); + if(pEPOptions.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(pEPOptions.getPepName(), "pepName", PEPOptions.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + pEPOptions.setUserCreatedBy(this.getUserInfo(userId)); + pEPOptions.setUserModifiedBy(this.getUserInfo(userId)); + pepOptionsDao.Save(pEPOptions); + } + }else{ + pEPOptions.setUserModifiedBy(this.getUserInfo(userId)); + pepOptionsDao.update(pEPOptions); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.pepOptionsDao.getPEPOptionsData()); + } + JSONObject j = new JSONObject("{pepOptionsDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/cl_dictionary/remove_pepOptions.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removePEPOptions(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + PEPOptions pEPOptions = (PEPOptions)mapper.readValue(root.get("data").toString(), PEPOptions.class); + pepOptionsDao.delete(pEPOptions); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.pepOptionsDao.getPEPOptionsData()); + JSONObject j = new JSONObject("{pepOptionsDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/cl_dictionary/save_service.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveServiceType(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + ClosedLoopD2Services serviceData = (ClosedLoopD2Services)mapper.readValue(root.get("closedLoopServiceDictionaryData").toString(), ClosedLoopD2Services.class); + String userId = root.get("loginId").textValue(); + if(serviceData.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(serviceData.getServiceName(), "serviceName", ClosedLoopD2Services.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + serviceData.setUserCreatedBy(this.getUserInfo(userId)); + serviceData.setUserModifiedBy(this.getUserInfo(userId)); + closedLoopServiceDao.Save(serviceData); + } + }else{ + serviceData.setUserModifiedBy(this.getUserInfo(userId)); + closedLoopServiceDao.update(serviceData); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.closedLoopServiceDao.getClosedLoopD2ServicesData()); + } + JSONObject j = new JSONObject("{closedLoopServiceDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/cl_dictionary/remove_Service.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removeServiceType(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + ClosedLoopD2Services closedLoopD2Services = (ClosedLoopD2Services)mapper.readValue(root.get("data").toString(), ClosedLoopD2Services.class); + closedLoopServiceDao.delete(closedLoopD2Services); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.closedLoopServiceDao.getClosedLoopD2ServicesData()); + JSONObject j = new JSONObject("{closedLoopServiceDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/cl_dictionary/save_siteName.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveSiteType(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + ClosedLoopSite siteData = (ClosedLoopSite)mapper.readValue(root.get("closedLoopSiteDictionaryData").toString(), ClosedLoopSite.class); + String userId = root.get("loginId").textValue(); + if(siteData.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(siteData.getSiteName(), "siteName", ClosedLoopSite.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + siteData.setUserCreatedBy(this.getUserInfo(userId)); + siteData.setUserModifiedBy(this.getUserInfo(userId)); + closedLoopSiteDao.Save(siteData); + } + }else{ + siteData.setUserModifiedBy(this.getUserInfo(userId)); + closedLoopSiteDao.update(siteData); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.closedLoopSiteDao.getClosedLoopSiteData()); + } + JSONObject j = new JSONObject("{closedLoopSiteDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/cl_dictionary/remove_site.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removeSiteType(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + ClosedLoopSite closedLoopSite = (ClosedLoopSite)mapper.readValue(root.get("data").toString(), ClosedLoopSite.class); + closedLoopSiteDao.delete(closedLoopSite); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.closedLoopSiteDao.getClosedLoopSiteData()); + JSONObject j = new JSONObject("{closedLoopSiteDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/cl_dictionary/save_varbind.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveVarbind(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + VarbindDictionary varbindDictionary = (VarbindDictionary)mapper.readValue(root.get("varbindDictionaryData").toString(), VarbindDictionary.class); + String userId = root.get("loginId").textValue(); + if(varbindDictionary.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(varbindDictionary.getVarbindName(), "varbindName", VarbindDictionary.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + varbindDictionary.setUserCreatedBy(this.getUserInfo(userId)); + varbindDictionary.setUserModifiedBy(this.getUserInfo(userId)); + varbindDao.Save(varbindDictionary); + } + }else{ + varbindDictionary.setUserModifiedBy(this.getUserInfo(userId)); + varbindDao.update(varbindDictionary); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.varbindDao.getVarbindDictionaryData()); + } + JSONObject j = new JSONObject("{varbindDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/cl_dictionary/remove_varbindDict.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removeVarbind(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + VarbindDictionary varbindDictionary = (VarbindDictionary)mapper.readValue(root.get("data").toString(), VarbindDictionary.class); + varbindDao.delete(varbindDictionary); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.varbindDao.getVarbindDictionaryData()); + JSONObject j = new JSONObject("{varbindDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + +} + diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/DecisionPolicyDictionaryController.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/DecisionPolicyDictionaryController.java new file mode 100644 index 000000000..3308a990f --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/DecisionPolicyDictionaryController.java @@ -0,0 +1,188 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.controller; + +import java.io.PrintWriter; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.json.JSONObject; +import org.openecomp.policy.pap.xacml.rest.util.JsonMessage; +import org.openecomp.policy.rest.dao.DecisionPolicyDao; +import org.openecomp.policy.rest.dao.UserInfoDao; +import org.openecomp.policy.rest.jpa.Datatype; +import org.openecomp.policy.rest.jpa.DecisionSettings; +import org.openecomp.policy.rest.jpa.UserInfo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +@Controller +public class DecisionPolicyDictionaryController { + + @Autowired + DecisionPolicyDao decisionPolicyDao; + + @Autowired + UserInfoDao userInfoDao; + + public UserInfo getUserInfo(String loginId){ + UserInfo name = userInfoDao.getUserInfoByLoginId(loginId); + return name; + } + + @RequestMapping(value={"/get_SettingsDictionaryDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getSettingsDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("settingsDictionaryDatas", mapper.writeValueAsString(decisionPolicyDao.getDecisionDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + + @RequestMapping(value={"/get_SettingsDictionaryData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getSettingsDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("settingsDictionaryDatas", mapper.writeValueAsString(decisionPolicyDao.getDecisionSettingsData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/decision_dictionary/save_Settings.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveSettingsDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + DecisionSettings decisionSettings = (DecisionSettings)mapper.readValue(root.get("settingsDictionaryData").toString(), DecisionSettings.class); + String userId = root.get("loginId").textValue(); + if(decisionSettings.getDatatypeBean().getShortName() != null){ + String datatype = decisionSettings.getDatatypeBean().getShortName(); + Datatype a = new Datatype(); + if(datatype.equalsIgnoreCase("string")){ + a.setId(26); + }else if(datatype.equalsIgnoreCase("integer")){ + a.setId(12); + }else if(datatype.equalsIgnoreCase("boolean")){ + a.setId(18); + }else if(datatype.equalsIgnoreCase("double")){ + a.setId(25); + }else if(datatype.equalsIgnoreCase("user")){ + a.setId(29); + } + decisionSettings.setDatatypeBean(a); + } + if(decisionSettings.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(decisionSettings.getXacmlId(), "xacmlId", DecisionSettings.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + decisionSettings.setUserCreatedBy(this.getUserInfo(userId)); + decisionSettings.setUserModifiedBy(this.getUserInfo(userId)); + decisionPolicyDao.Save(decisionSettings); + } + }else{ + decisionSettings.setUserModifiedBy(this.getUserInfo(userId)); + decisionPolicyDao.update(decisionSettings); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.decisionPolicyDao.getDecisionSettingsData()); + } + JSONObject j = new JSONObject("{settingsDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/settings_dictionary/remove_settings.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removeSettingsDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + DecisionSettings decisionSettings = (DecisionSettings)mapper.readValue(root.get("data").toString(), DecisionSettings.class); + decisionPolicyDao.delete(decisionSettings); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.decisionPolicyDao.getDecisionSettingsData()); + JSONObject j = new JSONObject("{settingsDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/DescriptiveDictionaryController.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/DescriptiveDictionaryController.java new file mode 100644 index 000000000..c184464fb --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/DescriptiveDictionaryController.java @@ -0,0 +1,190 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.controller; + +import java.io.PrintWriter; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.json.JSONObject; +import org.openecomp.policy.pap.xacml.rest.adapters.GridData; +import org.openecomp.policy.pap.xacml.rest.util.JsonMessage; +import org.openecomp.policy.rest.dao.DescriptiveScopeDao; +import org.openecomp.policy.rest.dao.UserInfoDao; +import org.openecomp.policy.rest.jpa.DescriptiveScope; +import org.openecomp.policy.rest.jpa.UserInfo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +@Controller +public class DescriptiveDictionaryController { + + @Autowired + DescriptiveScopeDao descriptiveScopeDao; + + @Autowired + UserInfoDao userInfoDao; + + public UserInfo getUserInfo(String loginId){ + UserInfo name = userInfoDao.getUserInfoByLoginId(loginId); + return name; + } + + @RequestMapping(value={"/get_DescriptiveScopeByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getDescriptiveDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("descriptiveScopeDictionaryDatas", mapper.writeValueAsString(descriptiveScopeDao.getDescriptiveScopeDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_DescriptiveScope"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getDescriptiveDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("descriptiveScopeDictionaryDatas", mapper.writeValueAsString(descriptiveScopeDao.getDescriptiveScope())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/descriptive_dictionary/save_descriptive.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveDescriptiveDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + DescriptiveScope descriptiveScope = (DescriptiveScope)mapper.readValue(root.get("descriptiveScopeDictionaryData").toString(), DescriptiveScope.class); + GridData data = (GridData)mapper.readValue(root.get("descriptiveScopeDictionaryData").toString(), GridData.class); + String userId = root.get("loginId").textValue(); + String header = ""; + int counter = 0; + if(data.getAttributes().size() > 0){ + for(Object attribute : data.getAttributes()){ + if(attribute instanceof LinkedHashMap){ + String key = ((LinkedHashMap) attribute).get("option").toString(); + String value = ((LinkedHashMap) attribute).get("number").toString(); + if(counter>0){ + header = header + "AND"; + } + header = header + key + ":"; + header = header + value; + counter ++; + } + } + } + descriptiveScope.setSearch(header); + if(descriptiveScope.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(descriptiveScope.getScopeName(), "descriptiveScopeName", DescriptiveScope.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + descriptiveScope.setUserCreatedBy(this.getUserInfo(userId)); + descriptiveScope.setUserModifiedBy(this.getUserInfo(userId)); + descriptiveScopeDao.Save(descriptiveScope); + } + }else{ + descriptiveScope.setUserModifiedBy(this.getUserInfo(userId)); + descriptiveScopeDao.update(descriptiveScope); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.descriptiveScopeDao.getDescriptiveScope()); + } + JSONObject j = new JSONObject("{descriptiveScopeDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/descriptive_dictionary/remove_descriptiveScope.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removeDescriptiveDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + DescriptiveScope descriptiveScope = (DescriptiveScope)mapper.readValue(root.get("data").toString(), DescriptiveScope.class); + descriptiveScopeDao.delete(descriptiveScope); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.descriptiveScopeDao.getDescriptiveScope()); + JSONObject j = new JSONObject("{descriptiveScopeDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } +} + diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/DictionaryController.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/DictionaryController.java new file mode 100644 index 000000000..aa2fb4acd --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/DictionaryController.java @@ -0,0 +1,366 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.controller; + +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.json.JSONObject; +import org.openecomp.policy.pap.xacml.rest.util.JsonMessage; +import org.openecomp.policy.rest.dao.AttributeDao; +import org.openecomp.policy.rest.dao.CategoryDao; +import org.openecomp.policy.rest.dao.EcompNameDao; +import org.openecomp.policy.rest.dao.UserInfoDao; +import org.openecomp.policy.rest.jpa.Attribute; +import org.openecomp.policy.rest.jpa.Category; +import org.openecomp.policy.rest.jpa.Datatype; +import org.openecomp.policy.rest.jpa.EcompName; +import org.openecomp.policy.rest.jpa.UserInfo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.servlet.ModelAndView; + +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +@Controller +public class DictionaryController { + + private static final Log logger = LogFactory.getLog(DictionaryController.class); + + @Autowired + AttributeDao attributeDao; + + @Autowired + EcompNameDao ecompNameDao; + + @Autowired + UserInfoDao userInfoDao; + + @Autowired + CategoryDao categoryDao; + + + public Category getCategory(){ + for (int i = 0; i < categoryDao.getCategoryListData().size() ; i++) { + Category value = categoryDao.getCategoryListData().get(i); + if (value.getShortName().equals("resource")) { + return value; + } + } + return null; + } + + + public UserInfo getUserInfo(String loginId){ + UserInfo name = userInfoDao.getUserInfoByLoginId(loginId); + return name; + } + + @RequestMapping(value={"/get_AttributeDatabyAttributeName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getAttributeDictionaryEntityDatabyAttributeName(HttpServletRequest request, HttpServletResponse response){ + try{ + System.out.println(); + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("attributeDictionaryDatas", mapper.writeValueAsString(attributeDao.getAttributeData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + //Attribute Dictionary + @RequestMapping(value="/get_AttributeData", method= RequestMethod.GET , produces=MediaType.APPLICATION_JSON_VALUE) + public void getAttributeDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + System.out.println(); + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("attributeDictionaryDatas", mapper.writeValueAsString(attributeDao.getData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/attribute_dictionary/save_attribute.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveAttributeDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + Attribute attributeData = (Attribute)mapper.readValue(root.get("attributeDictionaryData").toString(), Attribute.class); + AttributeValues attributeValueData = (AttributeValues)mapper.readValue(root.get("attributeDictionaryData").toString(), AttributeValues.class); + String userId = root.get("loginId").textValue(); + String userValue = ""; + int counter = 0; + if(attributeValueData.getUserDataTypeValues().size() > 0){ + for(Object attribute : attributeValueData.getUserDataTypeValues()){ + if(attribute instanceof LinkedHashMap){ + String key = ((LinkedHashMap) attribute).get("attributeValues").toString(); + if(counter>0){ + userValue = userValue + ","; + } + userValue = userValue + key ; + counter ++; + } + } + } + attributeData.setAttributeValue(userValue); + if(attributeData.getDatatypeBean().getShortName() != null){ + String datatype = attributeData.getDatatypeBean().getShortName(); + Datatype a = new Datatype(); + if(datatype.equalsIgnoreCase("string")){ + a.setId(26); + }else if(datatype.equalsIgnoreCase("integer")){ + a.setId(12); + }else if(datatype.equalsIgnoreCase("boolean")){ + a.setId(18); + }else if(datatype.equalsIgnoreCase("double")){ + a.setId(25); + }else if(datatype.equalsIgnoreCase("user")){ + a.setId(29); + } + attributeData.setDatatypeBean(a); + } + if(attributeData.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(attributeData.getXacmlId(), "xacmlId", Attribute.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + attributeData.setCategoryBean(this.getCategory()); + attributeData.setUserCreatedBy(this.getUserInfo(userId)); + attributeData.setUserModifiedBy(this.getUserInfo(userId)); + attributeDao.Save(attributeData); + } + }else{ + attributeData.setUserModifiedBy(this.getUserInfo(userId)); + attributeDao.update(attributeData); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.attributeDao.getData()); + } + JSONObject j = new JSONObject("{attributeDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/attribute_dictionary/remove_attribute.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removeAttributeDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + Attribute attributeData = (Attribute)mapper.readValue(root.get("data").toString(), Attribute.class); + attributeDao.delete(attributeData); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.attributeDao.getData()); + JSONObject j = new JSONObject("{attributeDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + //EcompName Dictionary + @RequestMapping(value={"/get_EcompNameDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getEcompNameDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){ + logger.info("get_EcompNameDataByName is called"); + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("ecompNameDictionaryDatas", mapper.writeValueAsString(ecompNameDao.getEcompNameDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_EcompNameData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getEcompNameDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + logger.info("get_EcompNameData is called"); + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("ecompNameDictionaryDatas", mapper.writeValueAsString(ecompNameDao.getEcompName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + logger.error("ERROR While callinge DAO: " + e.getMessage()); + } + } + + @RequestMapping(value={"/ecomp_dictionary/save_ecompName.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveEcompDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + System.out.println("DictionaryController: saveEcompDictionary() is called"); + logger.debug("DictionaryController: saveEcompDictionary() is called"); + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + EcompName ecompData = (EcompName)mapper.readValue(root.get("ecompNameDictionaryData").toString(), EcompName.class); + String userId = root.get("loginId").textValue(); + System.out.println("the userId from the ecomp portal is: " + userId); + if(ecompData.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(ecompData.getEcompName(), "ecompName", EcompName.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + ecompData.setUserCreatedBy(getUserInfo(userId)); + ecompData.setUserModifiedBy(getUserInfo(userId)); + System.out.println("DictionaryController: got the user info now about to call Save() method on ecompNamedao"); + ecompNameDao.Save(ecompData); + } + }else{ + ecompData.setUserModifiedBy(this.getUserInfo(userId)); + ecompNameDao.update(ecompData); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.ecompNameDao.getEcompName()); + } + JSONObject j = new JSONObject("{ecompNameDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/ecomp_dictionary/remove_ecomp.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removeEcompDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + EcompName ecompData = (EcompName)mapper.readValue(root.get("data").toString(), EcompName.class); + ecompNameDao.delete(ecompData); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.ecompNameDao.getEcompName()); + JSONObject j = new JSONObject("{ecompNameDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + +} + +class AttributeValues{ + private ArrayList userDataTypeValues; + + public ArrayList getUserDataTypeValues() { + return userDataTypeValues; + } + + public void setUserDataTypeValues(ArrayList userDataTypeValues) { + this.userDataTypeValues = userDataTypeValues; + } +} + diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/DictionaryImportController.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/DictionaryImportController.java new file mode 100644 index 000000000..3ed8f5d1c --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/DictionaryImportController.java @@ -0,0 +1,617 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.controller; + /* + * + * + * */ +import java.io.File; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.OutputStream; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.compress.utils.IOUtils; +import org.apache.commons.fileupload.FileItem; +import org.apache.commons.fileupload.disk.DiskFileItemFactory; +import org.apache.commons.fileupload.servlet.ServletFileUpload; +import org.openecomp.policy.rest.dao.ActionListDao; +import org.openecomp.policy.rest.dao.ActionPolicyDictDao; +import org.openecomp.policy.rest.dao.AddressGroupDao; +import org.openecomp.policy.rest.dao.AttributeDao; +import org.openecomp.policy.rest.dao.BRMSParamTemplateDao; +import org.openecomp.policy.rest.dao.DecisionPolicyDao; +import org.openecomp.policy.rest.dao.DescriptiveScopeDao; +import org.openecomp.policy.rest.dao.EcompNameDao; +import org.openecomp.policy.rest.dao.PEPOptionsDao; +import org.openecomp.policy.rest.dao.PortListDao; +import org.openecomp.policy.rest.dao.PrefixListDao; +import org.openecomp.policy.rest.dao.ProtocolListDao; +import org.openecomp.policy.rest.dao.SecurityZoneDao; +import org.openecomp.policy.rest.dao.ServiceDictionaryDao; +import org.openecomp.policy.rest.dao.ServiceGroupDao; +import org.openecomp.policy.rest.dao.ServiceListDao; +import org.openecomp.policy.rest.dao.SiteDictionaryDao; +import org.openecomp.policy.rest.dao.TermListDao; +import org.openecomp.policy.rest.dao.VNFTypeDao; +import org.openecomp.policy.rest.dao.VSCLActionDao; +import org.openecomp.policy.rest.dao.VarbindDictionaryDao; +import org.openecomp.policy.rest.dao.ZoneDao; +import org.openecomp.policy.rest.jpa.ActionList; +import org.openecomp.policy.rest.jpa.ActionPolicyDict; +import org.openecomp.policy.rest.jpa.AddressGroup; +import org.openecomp.policy.rest.jpa.Attribute; +import org.openecomp.policy.rest.jpa.BRMSParamTemplate; +import org.openecomp.policy.rest.jpa.Category; +import org.openecomp.policy.rest.jpa.Datatype; +import org.openecomp.policy.rest.jpa.DecisionSettings; +import org.openecomp.policy.rest.jpa.DescriptiveScope; +import org.openecomp.policy.rest.jpa.EcompName; +import org.openecomp.policy.rest.jpa.GroupServiceList; +import org.openecomp.policy.rest.jpa.PEPOptions; +import org.openecomp.policy.rest.jpa.PREFIXLIST; +import org.openecomp.policy.rest.jpa.ProtocolList; +import org.openecomp.policy.rest.jpa.SecurityZone; +import org.openecomp.policy.rest.jpa.ServiceList; +import org.openecomp.policy.rest.jpa.TermList; +import org.openecomp.policy.rest.jpa.UserInfo; +import org.openecomp.policy.rest.jpa.VNFType; +import org.openecomp.policy.rest.jpa.VSCLAction; +import org.openecomp.policy.rest.jpa.VarbindDictionary; +import org.openecomp.policy.rest.jpa.Zone; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; + +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; + +import au.com.bytecode.opencsv.CSVReader; + + +@Controller +public class DictionaryImportController { + private String newFile; + + @Autowired + AttributeDao attributeDao; + + @Autowired + ActionPolicyDictDao actionPolicyDictDao; + + @Autowired + EcompNameDao ecompNameDao; + + @Autowired + VNFTypeDao vnfTypeDao; + + @Autowired + VSCLActionDao vsclActionDao; + + @Autowired + PEPOptionsDao pepOptionsDao; + + @Autowired + VarbindDictionaryDao varbindDao; + + @Autowired + ServiceDictionaryDao closedLoopServiceDao; + + @Autowired + SiteDictionaryDao closedLoopSiteDao; + + @Autowired + DescriptiveScopeDao descriptiveScopeDao; + + @Autowired + PrefixListDao prefixListDao; + + @Autowired + PortListDao portListDao; + + @Autowired + ProtocolListDao protocolListDao; + + @Autowired + AddressGroupDao addressGroupDao; + + @Autowired + ActionListDao actionListDao; + + @Autowired + SecurityZoneDao securityZoneDao; + + @Autowired + ServiceGroupDao serviceGroupDao; + + @Autowired + ServiceListDao serviceListDao; + + @Autowired + TermListDao termListDao; + + @Autowired + ZoneDao zoneDao; + + @Autowired + DecisionPolicyDao decisionSettingsDao; + + @Autowired + BRMSParamTemplateDao brmsParamTemplateDao; + + @RequestMapping(value={"/dictionary/import_dictionary.htm/*"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public void ImportDictionaryData(HttpServletRequest request, HttpServletResponse response) throws Exception{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + //JsonNode root = mapper.readTree(request.getReader()); + String userId = request.getPathInfo().substring(request.getPathInfo().lastIndexOf("/")+1); + List items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request); + for (FileItem item : items) { + File file = new File(item.getName()); + OutputStream outputStream = new FileOutputStream(file); + IOUtils.copy(item.getInputStream(), outputStream); + outputStream.close(); + this.newFile = file.toString(); + CSVReader csvReader = new CSVReader(new FileReader(this.newFile)); + List dictSheet = csvReader.readAll(); + if(item.getName().startsWith("Attribute")){ + for(int i = 1; i< dictSheet.size(); i++){ + Attribute attribute = new Attribute("", userId); + UserInfo userinfo = new UserInfo(); + userinfo.setUserLoginId(userId); + attribute.setUserCreatedBy(userinfo); + attribute.setUserModifiedBy(userinfo); + String[] rows = dictSheet.get(i); + for (int j=0 ; j model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("enforcerDictionaryDatas", mapper.writeValueAsString(enforcerPolicyDao.getEnforcingTypeData())); + org.openecomp.policy.pap.xacml.rest.util.JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/enforcer_dictionary/save_enforcerType.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveEnforcerDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + EnforcingType enforcingType = (EnforcingType)mapper.readValue(root.get("enforcerDictionaryData").toString(), EnforcingType.class); + if(enforcingType.getId() == 0){ + enforcerPolicyDao.Save(enforcingType); + }else{ + enforcerPolicyDao.update(enforcingType); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = mapper.writeValueAsString(this.enforcerPolicyDao.getEnforcingTypeData()); + JSONObject j = new JSONObject("{enforcerDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/enforcer_dictionary/remove_enforcer.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removeEnforcerDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + EnforcingType enforcingType = (EnforcingType)mapper.readValue(root.get("data").toString(), EnforcingType.class); + enforcerPolicyDao.delete(enforcingType); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.enforcerPolicyDao.getEnforcingTypeData()); + JSONObject j = new JSONObject("{enforcerDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/FirewallDictionaryController.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/FirewallDictionaryController.java new file mode 100644 index 000000000..d2c371509 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/FirewallDictionaryController.java @@ -0,0 +1,1578 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.controller; + +import java.io.PrintWriter; +import java.net.UnknownHostException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.jboss.netty.handler.ipfilter.CIDR; +import org.json.JSONObject; +import org.openecomp.policy.pap.xacml.rest.adapters.GridData; +import org.openecomp.policy.pap.xacml.rest.util.JsonMessage; +import org.openecomp.policy.rest.dao.ActionListDao; +import org.openecomp.policy.rest.dao.AddressGroupDao; +import org.openecomp.policy.rest.dao.FirewallDictionaryListDao; +import org.openecomp.policy.rest.dao.PortListDao; +import org.openecomp.policy.rest.dao.PrefixListDao; +import org.openecomp.policy.rest.dao.ProtocolListDao; +import org.openecomp.policy.rest.dao.SecurityZoneDao; +import org.openecomp.policy.rest.dao.ServiceGroupDao; +import org.openecomp.policy.rest.dao.ServiceListDao; +import org.openecomp.policy.rest.dao.TermListDao; +import org.openecomp.policy.rest.dao.UserInfoDao; +import org.openecomp.policy.rest.dao.ZoneDao; +import org.openecomp.policy.rest.jpa.ActionList; +import org.openecomp.policy.rest.jpa.AddressGroup; +import org.openecomp.policy.rest.jpa.FirewallDictionaryList; +import org.openecomp.policy.rest.jpa.GroupServiceList; +import org.openecomp.policy.rest.jpa.PREFIXLIST; +import org.openecomp.policy.rest.jpa.PortList; +import org.openecomp.policy.rest.jpa.ProtocolList; +import org.openecomp.policy.rest.jpa.SecurityZone; +import org.openecomp.policy.rest.jpa.ServiceList; +import org.openecomp.policy.rest.jpa.TermList; +import org.openecomp.policy.rest.jpa.UserInfo; +import org.openecomp.policy.rest.jpa.Zone; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + + +@Controller +public class FirewallDictionaryController { + + @Autowired + PrefixListDao prefixListDao; + + @Autowired + PortListDao portListDao; + + @Autowired + ProtocolListDao protocolListDao; + + @Autowired + AddressGroupDao addressGroupDao; + + @Autowired + ActionListDao actionListDao; + + @Autowired + SecurityZoneDao securityZoneDao; + + @Autowired + ServiceGroupDao serviceGroupDao; + + @Autowired + ServiceListDao serviceListDao; + + @Autowired + TermListDao termListDao; + + @Autowired + ZoneDao zoneDao; + + @Autowired + UserInfoDao userInfoDao; + + @Autowired + FirewallDictionaryListDao fwDictionaryListDao; + + + + public UserInfo getUserInfo(String loginId){ + UserInfo name = userInfoDao.getUserInfoByLoginId(loginId); + return name; + } + + @RequestMapping(value={"/get_PrefixListDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getPrefixListDictionaryEntityDataByName(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("prefixListDictionaryDatas", mapper.writeValueAsString(prefixListDao.getPrefixListDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_PrefixListData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getPrefixListDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("prefixListDictionaryDatas", mapper.writeValueAsString(prefixListDao.getPREFIXLISTData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/fw_dictionary/save_prefixList.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView savePrefixListDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + PREFIXLIST prefixList = (PREFIXLIST)mapper.readValue(root.get("prefixListDictionaryData").toString(), PREFIXLIST.class); + if(prefixList.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(prefixList.getPrefixListName(), "prefixListName", PREFIXLIST.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + prefixListDao.Save(prefixList); + } + }else{ + prefixListDao.update(prefixList); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.prefixListDao.getPREFIXLISTData()); + } + JSONObject j = new JSONObject("{prefixListDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/fw_dictionary/remove_PrefixList.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removePrefixListDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + PREFIXLIST prefixList = (PREFIXLIST)mapper.readValue(root.get("data").toString(), PREFIXLIST.class); + prefixListDao.delete(prefixList); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.prefixListDao.getPREFIXLISTData()); + JSONObject j = new JSONObject("{prefixListDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/fw_dictionary/validate_prefixList.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView validatePrefixListDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + PREFIXLIST prefixList = (PREFIXLIST)mapper.readValue(root.get("prefixListDictionaryData").toString(), PREFIXLIST.class); + String responseValidation = "success"; + try{ + CIDR.newCIDR(prefixList.getPrefixListValue()); + }catch(UnknownHostException e){ + responseValidation = "error"; + //AdminNotification.warn("IP not according to CIDR notation"); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + JSONObject j = new JSONObject("{result: " + responseValidation + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/get_PortListData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getPortListDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("portListDictionaryDatas", mapper.writeValueAsString(portListDao.getPortListData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/fw_dictionary/save_portName.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView savePortListDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + PortList portList = (PortList)mapper.readValue(root.get("portListDictionaryData").toString(), PortList.class); + if(portList.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(portList.getPortName(), "portName", PortList.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + portListDao.Save(portList); + } + }else{ + portListDao.update(portList); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.portListDao.getPortListData()); + } + JSONObject j = new JSONObject("{portListDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/fw_dictionary/remove_PortList.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removePortListDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + PortList portList = (PortList)mapper.readValue(root.get("data").toString(), PortList.class); + portListDao.delete(portList); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.portListDao.getPortListData()); + JSONObject j = new JSONObject("{portListDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/get_ProtocolListData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getProtocolListDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("protocolListDictionaryDatas", mapper.writeValueAsString(protocolListDao.getProtocolListData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_ProtocolListDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getProtocolListDictionaryEntityDataByName(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("protocolListDictionaryDatas", mapper.writeValueAsString(protocolListDao.getProtocolListDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/fw_dictionary/save_protocolList.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveProtocolListDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + ProtocolList protocolList = (ProtocolList)mapper.readValue(root.get("protocolListDictionaryData").toString(), ProtocolList.class); + if(protocolList.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(protocolList.getProtocolName(), "protocolName", ProtocolList.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + protocolListDao.Save(protocolList); + } + }else{ + protocolListDao.update(protocolList); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.protocolListDao.getProtocolListData()); + } + JSONObject j = new JSONObject("{protocolListDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/fw_dictionary/remove_protocol.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removeProtocolListDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + ProtocolList protocolList = (ProtocolList)mapper.readValue(root.get("data").toString(), ProtocolList.class); + protocolListDao.delete(protocolList); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.protocolListDao.getProtocolListData()); + JSONObject j = new JSONObject("{protocolListDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/get_AddressGroupDictionaryDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getAddressGroupDictionaryEntityDataByName(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("addressGroupDictionaryDatas", mapper.writeValueAsString(addressGroupDao.getAddressGroupDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_AddressGroupData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getAddressGroupDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("addressGroupDictionaryDatas", mapper.writeValueAsString(addressGroupDao.getAddressGroupData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/fw_dictionary/save_addressGroup.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveAddressGroupDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + AddressGroup addressGroup = (AddressGroup)mapper.readValue(root.get("addressGroupDictionaryData").toString(), AddressGroup.class); + GridData gridData = (GridData)mapper.readValue(root.get("addressGroupDictionaryData").toString(), GridData.class); + if(!addressGroup.getGroupName().startsWith("Group_")){ + String groupName = "Group_"+addressGroup.getGroupName(); + addressGroup.setGroupName(groupName); + } + String userValue = ""; + int counter = 0; + if(gridData.getAttributes().size() > 0){ + for(Object attribute : gridData.getAttributes()){ + if(attribute instanceof LinkedHashMap){ + String key = ((LinkedHashMap) attribute).get("option").toString(); + if(counter>0){ + userValue = userValue + ","; + } + userValue = userValue + key ; + counter ++; + } + } + } + addressGroup.setServiceList(userValue); + if(addressGroup.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(addressGroup.getGroupName(), "name", AddressGroup.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + addressGroupDao.Save(addressGroup); + } + }else{ + addressGroupDao.update(addressGroup); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.addressGroupDao.getAddressGroupData()); + } + JSONObject j = new JSONObject("{addressGroupDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/fw_dictionary/remove_AddressGroup.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removeAddressGroupDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + AddressGroup addressGroup = (AddressGroup)mapper.readValue(root.get("data").toString(), AddressGroup.class); + addressGroupDao.delete(addressGroup); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.addressGroupDao.getAddressGroupData()); + JSONObject j = new JSONObject("{addressGroupDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/get_ActionListDictionaryDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getActionListDictionaryEntityDataByName(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("actionListDictionaryDatas", mapper.writeValueAsString(actionListDao.getActionListDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_ActionListData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getActionListDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("actionListDictionaryDatas", mapper.writeValueAsString(actionListDao.getActionListData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/fw_dictionary/save_ActionList.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveActionListDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + ActionList actionList = (ActionList)mapper.readValue(root.get("actionListDictionaryData").toString(), ActionList.class); + if(actionList.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(actionList.getActionName(), "actionName", ActionList.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + actionListDao.Save(actionList); + } + }else{ + actionListDao.update(actionList); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.actionListDao.getActionListData()); + } + JSONObject j = new JSONObject("{actionListDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/fw_dictionary/remove_ActionList.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removeActionListDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + ActionList actionList = (ActionList)mapper.readValue(root.get("data").toString(), ActionList.class); + actionListDao.delete(actionList); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.actionListDao.getActionListData()); + JSONObject j = new JSONObject("{actionListDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/get_ServiceGroupData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getServiceGroupDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("serviceGroupDictionaryDatas", mapper.writeValueAsString(serviceGroupDao.getGroupServiceListData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_ServiceGroupDictionaryDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getServiceGroupDictionaryEntityDataByName(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("serviceGroupDictionaryDatas", mapper.writeValueAsString(serviceGroupDao.getGroupServiceDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/fw_dictionary/save_serviceGroup.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveServiceGroupDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + GroupServiceList groupServiceList = (GroupServiceList)mapper.readValue(root.get("serviceGroupDictionaryData").toString(), GroupServiceList.class); + GridData gridData = (GridData)mapper.readValue(root.get("serviceGroupDictionaryData").toString(), GridData.class); + if(!groupServiceList.getGroupName().startsWith("Group_")){ + String groupName = "Group_"+groupServiceList.getGroupName(); + groupServiceList.setGroupName(groupName); + } + String userValue = ""; + int counter = 0; + if(gridData.getAttributes().size() > 0){ + for(Object attribute : gridData.getAttributes()){ + if(attribute instanceof LinkedHashMap){ + String key = ((LinkedHashMap) attribute).get("option").toString(); + if(counter>0){ + userValue = userValue + ","; + } + userValue = userValue + key ; + counter ++; + } + } + } + groupServiceList.setServiceList(userValue); + if(groupServiceList.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(groupServiceList.getGroupName(), "name", GroupServiceList.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + serviceGroupDao.Save(groupServiceList); + } + }else{ + serviceGroupDao.update(groupServiceList); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.serviceGroupDao.getGroupServiceListData()); + } + JSONObject j = new JSONObject("{serviceGroupDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/fw_dictionary/remove_serviceGroup.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removeServiceGroupDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + GroupServiceList groupServiceList = (GroupServiceList)mapper.readValue(root.get("data").toString(), GroupServiceList.class); + serviceGroupDao.delete(groupServiceList); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.serviceGroupDao.getGroupServiceListData()); + JSONObject j = new JSONObject("{serviceGroupDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/get_SecurityZoneDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getSecurityZoneDictionaryEntityDataByName(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("securityZoneDictionaryDatas", mapper.writeValueAsString(securityZoneDao.getSecurityZoneDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_SecurityZoneData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getSecurityZoneDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("securityZoneDictionaryDatas", mapper.writeValueAsString(securityZoneDao.getSecurityZoneData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/fw_dictionary/save_securityZone.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveSecurityZoneDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + SecurityZone securityZone = (SecurityZone)mapper.readValue(root.get("securityZoneDictionaryData").toString(), SecurityZone.class); + if(securityZone.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(securityZone.getZoneName(), "zoneName", SecurityZone.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + securityZoneDao.Save(securityZone); + } + }else{ + securityZoneDao.update(securityZone); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.securityZoneDao.getSecurityZoneData()); + } + JSONObject j = new JSONObject("{securityZoneDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/fw_dictionary/remove_securityZone.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removeSecurityZoneDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + SecurityZone securityZone = (SecurityZone)mapper.readValue(root.get("data").toString(), SecurityZone.class); + securityZoneDao.delete(securityZone); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.securityZoneDao.getSecurityZoneData()); + JSONObject j = new JSONObject("{securityZoneDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + + @RequestMapping(value={"/get_ServiceListData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getServiceListDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("serviceListDictionaryDatas", mapper.writeValueAsString(serviceListDao.getServiceListData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_ServiceListDictionaryDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getServiceListDictionaryEntityDataByName(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("serviceListDictionaryDatas", mapper.writeValueAsString(serviceListDao.getServiceListDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/fw_dictionary/save_serviceList.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveServiceListDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + ServiceList serviceList = (ServiceList)mapper.readValue(root.get("serviceListDictionaryData").toString(), ServiceList.class); + GridData serviceListGridData = (GridData)mapper.readValue(root.get("serviceListDictionaryData").toString(), GridData.class); + String tcpValue = ""; + int counter = 0; + if(serviceListGridData.getTransportProtocols().size() > 0){ + for(Object attribute : serviceListGridData.getTransportProtocols()){ + if(attribute instanceof LinkedHashMap){ + String key = ((LinkedHashMap) attribute).get("option").toString(); + if(counter>0){ + tcpValue = tcpValue + ","; + } + tcpValue = tcpValue + key ; + counter ++; + } + } + } + serviceList.setServiceTransProtocol(tcpValue); + String appValue = ""; + int counter1 = 0; + if(serviceListGridData.getAppProtocols().size() > 0){ + for(Object attribute : serviceListGridData.getAppProtocols()){ + if(attribute instanceof LinkedHashMap){ + String key = ((LinkedHashMap) attribute).get("option").toString(); + if(counter1>0){ + appValue = appValue + ","; + } + appValue = appValue + key ; + counter1 ++; + } + } + } + serviceList.setServiceAppProtocol(appValue); + serviceList.setServiceType("SERVICE"); + if(serviceList.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(serviceList.getServiceName(), "serviceName", ServiceList.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + serviceListDao.Save(serviceList); + } + + }else{ + serviceListDao.update(serviceList); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.serviceListDao.getServiceListData()); + } + JSONObject j = new JSONObject("{serviceListDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/fw_dictionary/remove_serviceList.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removeServiceListDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + ServiceList serviceList = (ServiceList)mapper.readValue(root.get("data").toString(), ServiceList.class); + serviceListDao.delete(serviceList); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.serviceListDao.getServiceListData()); + JSONObject j = new JSONObject("{serviceListDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/get_ZoneData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getZoneDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("zoneDictionaryDatas", mapper.writeValueAsString(zoneDao.getZoneData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_ZoneDictionaryDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getZoneDictionaryEntityDataByName(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("zoneDictionaryDatas", mapper.writeValueAsString(zoneDao.getZoneDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/fw_dictionary/save_zoneName.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveZoneDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + Zone zone = (Zone)mapper.readValue(root.get("zoneDictionaryData").toString(), Zone.class); + if(zone.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(zone.getZoneName(), "zoneName", Zone.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + zoneDao.Save(zone); + } + }else{ + zoneDao.update(zone); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.zoneDao.getZoneData()); + } + JSONObject j = new JSONObject("{zoneDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/fw_dictionary/remove_zone.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removeZoneDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + Zone zone = (Zone)mapper.readValue(root.get("data").toString(), Zone.class); + zoneDao.delete(zone); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.zoneDao.getZoneData()); + JSONObject j = new JSONObject("{zoneDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/get_TermListDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getTermListDictionaryEntityDataByName(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("termListDictionaryDatas", mapper.writeValueAsString(termListDao.getTermListDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_TermListData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getTermListDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("termListDictionaryDatas", mapper.writeValueAsString(termListDao.getTermListData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/fw_dictionary/save_termList.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveTermListDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + TermList termList = (TermList)mapper.readValue(root.get("termListDictionaryData").toString(), TermList.class); + TermListData termListDatas = (TermListData)mapper.readValue(root.get("termListDictionaryData").toString(), TermListData.class); + String userId = root.get("loginId").textValue(); + String fromZoneValue = ""; + int counter = 0; + if(termListDatas.getFromZoneDatas().size() > 0){ + for(Object fromZone : termListDatas.getFromZoneDatas()){ + if(fromZone instanceof LinkedHashMap){ + String key = ((LinkedHashMap) fromZone).get("option").toString(); + if(counter>0){ + fromZoneValue = fromZoneValue + ","; + } + fromZoneValue = fromZoneValue + key ; + counter ++; + } + } + } + termList.setFromZones(fromZoneValue); + + String toZoneValue = ""; + int toZonecounter = 0; + if(termListDatas.getToZoneDatas().size() > 0){ + for(Object toZone : termListDatas.getToZoneDatas()){ + if(toZone instanceof LinkedHashMap){ + String key = ((LinkedHashMap) toZone).get("option").toString(); + if(toZonecounter>0){ + toZoneValue = toZoneValue + ","; + } + toZoneValue = toZoneValue + key ; + toZonecounter ++; + } + } + } + termList.setToZones(toZoneValue); + + String srcListValues = ""; + int srcListcounter = 0; + if(termListDatas.getSourceListDatas().size() > 0){ + for(Object srcList : termListDatas.getSourceListDatas()){ + if(srcList instanceof LinkedHashMap){ + String key = ((LinkedHashMap) srcList).get("option").toString(); + if(srcListcounter>0){ + srcListValues = srcListValues + ","; + } + srcListValues = srcListValues + key ; + srcListcounter ++; + } + } + } + termList.setSrcIPList(srcListValues); + + String desListValues = ""; + int destListcounter = 0; + if(termListDatas.getDestinationListDatas().size() > 0){ + for(Object desList : termListDatas.getDestinationListDatas()){ + if(desList instanceof LinkedHashMap){ + String key = ((LinkedHashMap) desList).get("option").toString(); + if(destListcounter>0){ + desListValues = desListValues + ","; + } + desListValues = desListValues + key ; + destListcounter ++; + } + } + } + termList.setDestIPList(desListValues); + + String srcSerValue = ""; + int srcSercounter = 0; + if(termListDatas.getSourceServiceDatas().size() > 0){ + for(Object srcSrc : termListDatas.getSourceServiceDatas()){ + if(srcSrc instanceof LinkedHashMap){ + String key = ((LinkedHashMap) srcSrc).get("option").toString(); + if(srcSercounter>0){ + srcSerValue = srcSerValue + ","; + } + srcSerValue = srcSerValue + key ; + srcSercounter ++; + } + } + } + termList.setSrcPortList(srcSerValue); + + String desSrcValue = ""; + int desSrccounter = 0; + if(termListDatas.getDestinationServiceDatas().size() > 0){ + for(Object desSrc : termListDatas.getDestinationServiceDatas()){ + if(desSrc instanceof LinkedHashMap){ + String key = ((LinkedHashMap) desSrc).get("option").toString(); + if(desSrccounter>0){ + desSrcValue = desSrcValue + ","; + } + desSrcValue = desSrcValue + key ; + desSrccounter ++; + } + } + } + termList.setDestPortList(desSrcValue); + + String actionValue = ""; + int actioncounter = 0; + if(termListDatas.getActionListDatas().size() > 0){ + for(Object actionList : termListDatas.getActionListDatas()){ + if(actionList instanceof LinkedHashMap){ + String key = ((LinkedHashMap) actionList).get("option").toString(); + if(actioncounter>0){ + actionValue = actionValue + ","; + } + actionValue = actionValue + key ; + actioncounter ++; + } + } + } + termList.setAction(actionValue); + + if(termList.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(termList.getTermName(), "termName", TermList.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + termList.setUserCreatedBy(this.getUserInfo(userId)); + termList.setUserModifiedBy(this.getUserInfo(userId)); + termListDao.Save(termList); + } + }else{ + termList.setUserModifiedBy(this.getUserInfo(userId)); + termListDao.update(termList); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.termListDao.getTermListData()); + } + JSONObject j = new JSONObject("{termListDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/fw_dictionary/remove_termList.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removeTermListDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + TermList termList = (TermList)mapper.readValue(root.get("data").toString(), TermList.class); + termListDao.delete(termList); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.termListDao.getTermListData()); + JSONObject j = new JSONObject("{termListDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + //ParentList Dictionary Data + @RequestMapping(value={"/get_FWDictionaryListDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getFWDictListDictionaryEntityDataByName(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("fwDictListDictionaryDatas", mapper.writeValueAsString(fwDictionaryListDao.getFWDictionaryListDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_FWDictionaryListData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getFWDictionaryListEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("fwDictListDictionaryDatas", mapper.writeValueAsString(fwDictionaryListDao.getFWDictionaryListData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/fw_dictionary/save_FWDictionaryList.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveFWDictionaryList(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + FirewallDictionaryList fwDictList = (FirewallDictionaryList)mapper.readValue(root.get("fwDictListDictionaryData").toString(), FirewallDictionaryList.class); + GridData gridData = (GridData)mapper.readValue(root.get("fwDictListDictionaryData").toString(), GridData.class); + String userSLValue = ""; + int slcounter = 0; + if(gridData.getAttributes().size() > 0){ + for(Object attribute : gridData.getAttributes()){ + if(attribute instanceof LinkedHashMap){ + String key = ((LinkedHashMap) attribute).get("option").toString(); + if(slcounter>0){ + userSLValue = userSLValue + ","; + } + userSLValue = userSLValue + key ; + slcounter ++; + } + } + } + fwDictList.setServiceList(userSLValue); + String userALValue = ""; + int alcounter = 0; + if(gridData.getAlAttributes().size() > 0){ + for(Object attribute : gridData.getAlAttributes()){ + if(attribute instanceof LinkedHashMap){ + String key = ((LinkedHashMap) attribute).get("option").toString(); + if(alcounter>0){ + userALValue = userALValue + ","; + } + userALValue = userALValue + key ; + alcounter ++; + } + } + } + fwDictList.setAddressList(userALValue); + if(fwDictList.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(fwDictList.getParentItemName(), "parentItemName", FirewallDictionaryList.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + fwDictionaryListDao.Save(fwDictList); + } + }else{ + fwDictionaryListDao.update(fwDictList); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.fwDictionaryListDao.getFWDictionaryListData()); + } + JSONObject j = new JSONObject("{fwDictListDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/fw_dictionary/remove_FWDictionaryList.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removeFWDictionaryListy(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + FirewallDictionaryList fwDictList = (FirewallDictionaryList)mapper.readValue(root.get("data").toString(), FirewallDictionaryList.class); + fwDictionaryListDao.delete(fwDictList); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.fwDictionaryListDao.getFWDictionaryListData()); + JSONObject j = new JSONObject("{fwDictListDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } +} + +class AGGridData{ + private ArrayList attributes; + + public ArrayList getAttributes() { + return attributes; + } + + public void setAttributes(ArrayList attributes) { + this.attributes = attributes; + } +} + +class TermListData{ + private ArrayList fromZoneDatas; + private ArrayList toZoneDatas; + private ArrayList sourceListDatas; + private ArrayList destinationListDatas; + private ArrayList sourceServiceDatas; + private ArrayList destinationServiceDatas; + private ArrayList actionListDatas; + public ArrayList getFromZoneDatas() { + return fromZoneDatas; + } + public void setFromZoneDatas(ArrayList fromZoneDatas) { + this.fromZoneDatas = fromZoneDatas; + } + public ArrayList getToZoneDatas() { + return toZoneDatas; + } + public void setToZoneDatas(ArrayList toZoneDatas) { + this.toZoneDatas = toZoneDatas; + } + public ArrayList getSourceListDatas() { + return sourceListDatas; + } + public void setSourceListDatas(ArrayList sourceListDatas) { + this.sourceListDatas = sourceListDatas; + } + public ArrayList getDestinationListDatas() { + return destinationListDatas; + } + public void setDestinationListDatas(ArrayList destinationListDatas) { + this.destinationListDatas = destinationListDatas; + } + public ArrayList getSourceServiceDatas() { + return sourceServiceDatas; + } + public void setSourceServiceDatas(ArrayList sourceServiceDatas) { + this.sourceServiceDatas = sourceServiceDatas; + } + public ArrayList getDestinationServiceDatas() { + return destinationServiceDatas; + } + public void setDestinationServiceDatas(ArrayList destinationServiceDatas) { + this.destinationServiceDatas = destinationServiceDatas; + } + public ArrayList getActionListDatas() { + return actionListDatas; + } + public void setActionListDatas(ArrayList actionListDatas) { + this.actionListDatas = actionListDatas; + } +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/MicroServiceDictionaryController.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/MicroServiceDictionaryController.java new file mode 100644 index 000000000..c3329db14 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/MicroServiceDictionaryController.java @@ -0,0 +1,718 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.controller; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.compress.utils.IOUtils; +import org.apache.commons.fileupload.FileItem; +import org.apache.commons.fileupload.disk.DiskFileItemFactory; +import org.apache.commons.fileupload.servlet.ServletFileUpload; +import org.apache.commons.lang.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.json.JSONObject; +import org.openecomp.policy.pap.xacml.rest.util.JsonMessage; +import org.openecomp.policy.rest.dao.DCAEUUIDDao; +import org.openecomp.policy.rest.dao.MicroServiceConfigNameDao; +import org.openecomp.policy.rest.dao.MicroServiceLocationDao; +import org.openecomp.policy.rest.dao.MicroServiceModelsDao; +import org.openecomp.policy.rest.dao.UserInfoDao; +import org.openecomp.policy.rest.jpa.DCAEuuid; +import org.openecomp.policy.rest.jpa.MicroServiceConfigName; +import org.openecomp.policy.rest.jpa.MicroServiceLocation; +import org.openecomp.policy.rest.jpa.MicroServiceModels; +import org.openecomp.policy.rest.jpa.UserInfo; +import org.openecomp.policy.rest.util.MSAttributeObject; +import org.openecomp.policy.rest.util.MSModelUtitils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +@Controller +public class MicroServiceDictionaryController { + private static final Log logger = LogFactory.getLog(MicroServiceDictionaryController.class); + + @Autowired + MicroServiceConfigNameDao microServiceConfigNameDao; + + @Autowired + MicroServiceLocationDao microServiceLocationDao; + + @Autowired + MicroServiceModelsDao microServiceModelsDao; + + @Autowired + DCAEUUIDDao dcaeUUIDDao; + + @Autowired + UserInfoDao userInfoDao; + + + private String newFile; + private String directory; + private List dirDependencyList = new ArrayList(); + private HashMap classMap = new HashMap(); + MSModelUtitils utils = new MSModelUtitils(); + private MicroServiceModels newModel; + + public UserInfo getUserInfo(String loginId){ + UserInfo name = userInfoDao.getUserInfoByLoginId(loginId); + return name; + } + + @RequestMapping(value={"/get_DCAEUUIDDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getDCAEUUIDDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("dcaeUUIDDictionaryDatas", mapper.writeValueAsString(dcaeUUIDDao.getDCAEuuidDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_DCAEUUIDData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getDCAEUUIDDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("dcaeUUIDDictionaryDatas", mapper.writeValueAsString(dcaeUUIDDao.getDCAEuuidData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/ms_dictionary/save_dcaeUUID.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveDCAEUUIDDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + DCAEuuid dCAEuuid = (DCAEuuid)mapper.readValue(root.get("dcaeUUIDDictionaryData").toString(), DCAEuuid.class); + if(dCAEuuid.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(dCAEuuid.getName(), "name", DCAEuuid.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + dcaeUUIDDao.Save(dCAEuuid); + } + }else{ + dcaeUUIDDao.update(dCAEuuid); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.dcaeUUIDDao.getDCAEuuidData()); + } + JSONObject j = new JSONObject("{dcaeUUIDDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/ms_dictionary/remove_dcaeuuid.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removeDCAEUUIDDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + DCAEuuid dCAEuuid = (DCAEuuid)mapper.readValue(root.get("data").toString(), DCAEuuid.class); + dcaeUUIDDao.delete(dCAEuuid); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.dcaeUUIDDao.getDCAEuuidData()); + JSONObject j = new JSONObject("{dcaeUUIDDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + + @RequestMapping(value={"/get_MicroServiceConfigNameDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getMicroServiceConfigNameByNameDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("microServiceCongigNameDictionaryDatas", mapper.writeValueAsString(microServiceConfigNameDao.getMSConfigDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + + + @RequestMapping(value={"/get_MicroServiceConfigNameData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getMicroServiceConfigNameDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("microServiceCongigNameDictionaryDatas", mapper.writeValueAsString(microServiceConfigNameDao.getMicroServiceConfigNameData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/ms_dictionary/save_configName.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveMicroServiceConfigNameDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + MicroServiceConfigName microServiceConfigName = (MicroServiceConfigName)mapper.readValue(root.get("microServiceCongigNameDictionaryData").toString(), MicroServiceConfigName.class); + if(microServiceConfigName.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(microServiceConfigName.getName(), "name", MicroServiceConfigName.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + microServiceConfigNameDao.Save(microServiceConfigName); + } + }else{ + microServiceConfigNameDao.update(microServiceConfigName); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.microServiceConfigNameDao.getMicroServiceConfigNameData()); + } + JSONObject j = new JSONObject("{microServiceCongigNameDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/ms_dictionary/remove_msConfigName.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removeMicroServiceConfigNameDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + MicroServiceConfigName microServiceConfigName = (MicroServiceConfigName)mapper.readValue(root.get("data").toString(), MicroServiceConfigName.class); + microServiceConfigNameDao.delete(microServiceConfigName); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.microServiceConfigNameDao.getMicroServiceConfigNameData()); + JSONObject j = new JSONObject("{microServiceCongigNameDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/get_MicroServiceLocationDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getMicroServiceLocationByNameDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("microServiceLocationDictionaryDatas", mapper.writeValueAsString(microServiceLocationDao.getMSLocationDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_MicroServiceLocationData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getMicroServiceLocationDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("microServiceLocationDictionaryDatas", mapper.writeValueAsString(microServiceLocationDao.getMicroServiceLocationData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/ms_dictionary/save_location.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveMicroServiceLocationDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + MicroServiceLocation microServiceLocation = (MicroServiceLocation)mapper.readValue(root.get("microServiceLocationDictionaryData").toString(), MicroServiceLocation.class); + if(microServiceLocation.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(microServiceLocation.getName(), "name", MicroServiceLocation.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + microServiceLocationDao.Save(microServiceLocation); + } + }else{ + microServiceLocationDao.update(microServiceLocation); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.microServiceLocationDao.getMicroServiceLocationData()); + } + JSONObject j = new JSONObject("{microServiceLocationDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/ms_dictionary/remove_msLocation.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removeMicroServiceLocationDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + MicroServiceLocation microServiceLocation = (MicroServiceLocation)mapper.readValue(root.get("data").toString(), MicroServiceLocation.class); + microServiceLocationDao.delete(microServiceLocation); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.microServiceLocationDao.getMicroServiceLocationData()); + JSONObject j = new JSONObject("{microServiceLocationDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/get_MicroServiceModelsDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getMicroServiceModelsDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("microServiceModelsDictionaryDatas", mapper.writeValueAsString(microServiceModelsDao.getMSModelsDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_MicroServiceModelsData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getMicroServiceModelsDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("microServiceModelsDictionaryDatas", mapper.writeValueAsString(microServiceModelsDao.getMicroServiceModelsData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/ms_dictionary/save_model.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveMicroServiceModelsDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + MicroServiceModels microServiceModels = (MicroServiceModels)mapper.readValue(root.get("microServiceModelsDictionaryData").toString(), MicroServiceModels.class); + String userId = root.get("loginId").textValue(); + microServiceModels.setAttributes(this.newModel.getAttributes()); + microServiceModels.setRef_attributes(this.newModel.getRef_attributes()); + microServiceModels.setDependency(this.newModel.getDependency()); + microServiceModels.setModelName(this.newModel.getModelName()); + microServiceModels.setSub_attributes(this.newModel.getSub_attributes()); + microServiceModels.setVersion(this.newModel.getVersion()); + if(microServiceModels.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(microServiceModels.getModelName(), "modelName", MicroServiceModels.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + microServiceModels.setUserCreatedBy(this.getUserInfo(userId)); + microServiceModelsDao.Save(microServiceModels); + } + }else{ + microServiceModelsDao.update(microServiceModels); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.microServiceModelsDao.getMicroServiceModelsData()); + } + JSONObject j = new JSONObject("{microServiceModelsDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/ms_dictionary/remove_msModel.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removeMicroServiceModelsDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + MicroServiceModels microServiceModels = (MicroServiceModels)mapper.readValue(root.get("data").toString(), MicroServiceModels.class); + microServiceModelsDao.delete(microServiceModels); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.microServiceModelsDao.getMicroServiceModelsData()); + JSONObject j = new JSONObject("{microServiceModelsDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/ms_dictionary/set_MSModelData.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public void SetRuleData(HttpServletRequest request, HttpServletResponse response) throws Exception{ + List items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request); + for (FileItem item : items) { + if(item.getName().endsWith(".zip")){ + this.newModel = new MicroServiceModels(); + try{ + File file = new File(item.getName()); + OutputStream outputStream = new FileOutputStream(file); + IOUtils.copy(item.getInputStream(), outputStream); + outputStream.close(); + this.newFile = file.toString(); + this.newModel.setModelName(this.newFile.toString().split("-v")[0]); + if (this.newFile.toString().contains("-v")){ + this.newModel.setVersion(this.newFile.toString().split("-v")[1].replace(".zip", "")); + } + }catch(Exception e){ + logger.error("Upload error : " + e); + } + } + } + extractFolder(this.newFile); + List fileList = listModelFiles(this.directory); + + File folder = new File(this.directory); + File[] test = folder.listFiles(); + + //Process Main Model file first + String ignoreFile = null; + for (File file : test) { + if(!file.isDirectory() && file.getName().endsWith(".xmi")){ + retreiveDependency(file.toString(), true); + ignoreFile = file.toString(); + } + } + + for(File tempFile: fileList){ + if (!tempFile.toString().contains(ignoreFile)){ + retreiveDependency(tempFile.toString(), false); + } + } + + addValuesToNewModel(); + + File deleteFile = new File(this.newFile); + deleteFile.delete(); + } + + private void addValuesToNewModel() { + //Loop through the classmap and pull out the required info for the new file. + MSAttributeObject mainClass = null; + ArrayList dependency = null; + String subAttribute = null; + + mainClass = classMap.get(this.newModel.getModelName()); + + if (mainClass !=null){ + String dependTemp = StringUtils.replaceEach(mainClass.getDependency(), new String[]{"[", "]", " "}, new String[]{"", "", ""}); + dependency = new ArrayList(Arrays.asList(dependTemp.split(","))); + dependency = getFullDependencyList(dependency); + for (String element : dependency){ + MSAttributeObject temp = new MSAttributeObject(); + temp = classMap.get(element); + if (temp!=null){ + mainClass.addAllRefAttribute(temp.getRefAttribute()); + mainClass.addAllAttribute(temp.getAttribute()); + } + } + subAttribute = utils.createSubAttributes(dependency, classMap, this.newModel.getModelName()); + }else{ + subAttribute = "{}"; + this.newModel.setDependency(""); + } + + if (mainClass.getDependency()==null){ + mainClass.setDependency(""); + } + + this.newModel.setDependency(mainClass.getDependency()); + this.newModel.setSub_attributes(subAttribute.toString()); + this.newModel.setAttributes(mainClass.getAttribute().toString().replace("{", "").replace("}", "")); + this.newModel.setRef_attributes(mainClass.getRefAttribute().toString().replace("{", "").replace("}", "")); + + } + + private ArrayList getFullDependencyList(ArrayList dependency) { + ArrayList returnList = new ArrayList(); + ArrayList workingList = new ArrayList(); + returnList.addAll(dependency); + for (String element : dependency ){ + if (classMap.containsKey(element)){ + MSAttributeObject value = classMap.get(element); + String rawValue = StringUtils.replaceEach(value.getDependency(), new String[]{"[", "]"}, new String[]{"", ""}); + workingList = new ArrayList(Arrays.asList(rawValue.split(","))); + for(String depend : workingList){ + if (!returnList.contains(depend) && !depend.isEmpty()){ + returnList.add(depend.trim()); + //getFullDepedency(workingList) + } + } + } + } + + return returnList; + } + + + /* + * Unzip file and store in the model directory for processing + */ + @SuppressWarnings("rawtypes") + private void extractFolder(String zipFile ) { + int BUFFER = 2048; + File file = new File(zipFile); + + ZipFile zip; + try { + zip = new ZipFile(file); + String newPath = "model" + File.separator + zipFile.substring(0, zipFile.length() - 4); + this.directory = "model" + File.separator + zipFile.substring(0, zipFile.length() - 4); + new File(newPath).mkdir(); + Enumeration zipFileEntries = zip.entries(); + + // Process each entry + while (zipFileEntries.hasMoreElements()){ + // grab a zip file entry + ZipEntry entry = (ZipEntry) zipFileEntries.nextElement(); + String currentEntry = entry.getName(); + File destFile = new File("model" + File.separator + currentEntry); + File destinationParent = destFile.getParentFile(); + + destinationParent.mkdirs(); + + if (!entry.isDirectory()){ + BufferedInputStream is = new BufferedInputStream(zip.getInputStream(entry)); + int currentByte; + byte data[] = new byte[BUFFER]; + FileOutputStream fos = new FileOutputStream(destFile); + BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER); + while ((currentByte = is.read(data, 0, BUFFER)) != -1) { + dest.write(data, 0, currentByte); + } + dest.flush(); + dest.close(); + is.close(); + } + + if (currentEntry.endsWith(".zip")){ + extractFolder(destFile.getAbsolutePath()); + } + } + } catch (IOException e) { + logger.error("Failed to unzip model file " + zipFile); + } + } + + private void retreiveDependency(String workingFile, Boolean modelClass) { + + MSModelUtitils utils = new MSModelUtitils(); + HashMap tempMap = new HashMap(); + + tempMap = utils.processEpackage(workingFile); + + classMap.putAll(tempMap); + System.out.println(tempMap); + + return; } + + private List listModelFiles(String directoryName) { + File directory = new File(directoryName); + List resultList = new ArrayList(); + File[] fList = directory.listFiles(); + for (File file : fList) { + if (file.isFile()) { + resultList.add(file); + } else if (file.isDirectory()) { + dirDependencyList.add(file.getName()); + resultList.addAll(listModelFiles(file.getAbsolutePath())); + } + } + return resultList; + } +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/PolicyScopeDictionaryController.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/PolicyScopeDictionaryController.java new file mode 100644 index 000000000..b8803d738 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/PolicyScopeDictionaryController.java @@ -0,0 +1,667 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.controller; + +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.lang.StringUtils; +import org.json.JSONObject; +import org.openecomp.policy.pap.xacml.rest.util.JsonMessage; +import org.openecomp.policy.rest.dao.GroupPolicyScopeListDao; +import org.openecomp.policy.rest.dao.PolicyScopeClosedLoopDao; +import org.openecomp.policy.rest.dao.PolicyScopeResourceDao; +import org.openecomp.policy.rest.dao.PolicyScopeServiceDao; +import org.openecomp.policy.rest.dao.PolicyScopeTypeDao; +import org.openecomp.policy.rest.dao.UserInfoDao; +import org.openecomp.policy.rest.jpa.GroupPolicyScopeList; +import org.openecomp.policy.rest.jpa.PolicyScopeClosedLoop; +import org.openecomp.policy.rest.jpa.PolicyScopeResource; +import org.openecomp.policy.rest.jpa.PolicyScopeService; +import org.openecomp.policy.rest.jpa.PolicyScopeType; +import org.openecomp.policy.rest.jpa.UserInfo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +@Controller +public class PolicyScopeDictionaryController { + + @Autowired + GroupPolicyScopeListDao groupPolicyScopeListDao; + + @Autowired + PolicyScopeClosedLoopDao policyScopeClosedLoopDao; + + @Autowired + PolicyScopeResourceDao PolicyScopeResourceDao; + + @Autowired + PolicyScopeTypeDao policyScopeTypeDao; + + @Autowired + PolicyScopeServiceDao policyScopeServiceDao; + + + @Autowired + UserInfoDao userInfoDao; + + public UserInfo getUserInfo(String loginId){ + UserInfo name = userInfoDao.getUserInfoByLoginId(loginId); + return name; + } + + @RequestMapping(value={"/get_GroupPolicyScopeDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getGroupPolicyScopeEntityDataByName(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("groupPolicyScopeListDatas", mapper.writeValueAsString(groupPolicyScopeListDao.getGroupPolicyScopeListDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_GroupPolicyScopeData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getGroupPolicyScopeEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("groupPolicyScopeListDatas", mapper.writeValueAsString(groupPolicyScopeListDao.getGroupPolicyScopeListData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/ps_dictionary/save_psGroupPolicyScope.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView savePSGroupScopeDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + GroupPolicyScopeList ecompData = (GroupPolicyScopeList)mapper.readValue(root.get("groupPolicyScopeListData").toString(), GroupPolicyScopeList.class); + GroupPolicyScope groupData = null; + try{ + groupData = (GroupPolicyScope)mapper.readValue(root.get("groupPolicyScopeListData1").toString(), GroupPolicyScope.class); + }catch(Exception e){ + groupData = new GroupPolicyScope(); + groupData.setResource(root.get("groupPolicyScopeListData1").get("resource").toString().replace("\"", "")); + groupData.setClosedloop(root.get("groupPolicyScopeListData1").get("closedloop").toString().replace("\"", "")); + groupData.setService(root.get("groupPolicyScopeListData1").get("service").toString().replace("\"", "")); + groupData.setType(root.get("groupPolicyScopeListData1").get("type").toString().replace("\"", "")); + } + + ArrayList valueList = new ArrayList(); + String list = null; + String resourceValue = groupData.getResource(); + String typeValue = groupData.getType(); + String serviceValue = groupData.getService(); + String closedLoopValue = groupData.getClosedloop(); + valueList.add("resource=" + resourceValue); + valueList.add("service=" + serviceValue); + valueList.add("type=" + typeValue); + valueList.add("closedLoopControlName=" + closedLoopValue); + list = StringUtils.replaceEach(valueList.toString(), new String[]{"[", "]", " "}, new String[]{"", "", ""}); + ecompData.setGroupList(list); + if(!ecompData.getGroupName().startsWith("PolicyScope")){ + String name = "PolicyScope_" + ecompData.getGroupName(); + ecompData.setGroupName(name); + } + if(ecompData.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(ecompData.getGroupName(), "name", GroupPolicyScopeList.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + groupPolicyScopeListDao.Save(ecompData); + } + }else{ + groupPolicyScopeListDao.update(ecompData); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.groupPolicyScopeListDao.getGroupPolicyScopeListData()); + } + JSONObject j = new JSONObject("{groupPolicyScopeListDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/ps_dictionary/remove_GroupPolicyScope.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removePSGroupScopeDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + GroupPolicyScopeList ecompData = (GroupPolicyScopeList)mapper.readValue(root.get("data").toString(), GroupPolicyScopeList.class); + groupPolicyScopeListDao.delete(ecompData); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.groupPolicyScopeListDao.getGroupPolicyScopeListData()); + JSONObject j = new JSONObject("{groupPolicyScopeListDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/get_PSClosedLoopDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getPSClosedLoopEntityDataByName(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("psClosedLoopDictionaryDatas", mapper.writeValueAsString(policyScopeClosedLoopDao.getPolicyScopeClosedLoopDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_PSClosedLoopData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getPSClosedLoopEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("psClosedLoopDictionaryDatas", mapper.writeValueAsString(policyScopeClosedLoopDao.getPolicyScopeClosedLoopData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/ps_dictionary/save_psClosedLoop.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView savePSClosedLoopDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + PolicyScopeClosedLoop ecompData = (PolicyScopeClosedLoop)mapper.readValue(root.get("psClosedLoopDictionaryData").toString(), PolicyScopeClosedLoop.class); + if(ecompData.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(ecompData.getName(), "name", PolicyScopeClosedLoop.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + policyScopeClosedLoopDao.Save(ecompData); + } + }else{ + policyScopeClosedLoopDao.update(ecompData); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.policyScopeClosedLoopDao.getPolicyScopeClosedLoopData()); + } + JSONObject j = new JSONObject("{psClosedLoopDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/ps_dictionary/remove_PSClosedLoop.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removePSClosedLoopDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + PolicyScopeClosedLoop ecompData = (PolicyScopeClosedLoop)mapper.readValue(root.get("data").toString(), PolicyScopeClosedLoop.class); + policyScopeClosedLoopDao.delete(ecompData); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.policyScopeClosedLoopDao.getPolicyScopeClosedLoopData()); + JSONObject j = new JSONObject("{psClosedLoopDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/get_PSServiceDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getPSServiceEntityDataByName(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("psServiceDictionaryDatas", mapper.writeValueAsString(policyScopeServiceDao.getPolicyScopeServiceDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_PSServiceData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getPSServiceEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("psServiceDictionaryDatas", mapper.writeValueAsString(policyScopeServiceDao.getPolicyScopeServiceData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/ps_dictionary/save_psService.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView savePSServiceDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + PolicyScopeService ecompData = (PolicyScopeService)mapper.readValue(root.get("psServiceDictionaryData").toString(), PolicyScopeService.class); + if(ecompData.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(ecompData.getName(), "name", PolicyScopeService.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + policyScopeServiceDao.Save(ecompData); + } + }else{ + policyScopeServiceDao.update(ecompData); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.policyScopeServiceDao.getPolicyScopeServiceData()); + } + JSONObject j = new JSONObject("{psServiceDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/ps_dictionary/remove_PSService.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removePSServiceDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + PolicyScopeService ecompData = (PolicyScopeService)mapper.readValue(root.get("data").toString(), PolicyScopeService.class); + policyScopeServiceDao.delete(ecompData); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.policyScopeServiceDao.getPolicyScopeServiceData()); + JSONObject j = new JSONObject("{psServiceDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/get_PSTypeDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getPSTypeEntityDataByName(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("psTypeDictionaryDatas", mapper.writeValueAsString(policyScopeTypeDao.getPolicyScopeTypeDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_PSTypeData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getPSTypeEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("psTypeDictionaryDatas", mapper.writeValueAsString(policyScopeTypeDao.getPolicyScopeTypeData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/ps_dictionary/save_psType.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView savePSTypeDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + PolicyScopeType ecompData = (PolicyScopeType)mapper.readValue(root.get("psTypeDictionaryData").toString(), PolicyScopeType.class); + if(ecompData.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(ecompData.getName(), "name", PolicyScopeType.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + policyScopeTypeDao.Save(ecompData); + } + }else{ + policyScopeTypeDao.update(ecompData); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.policyScopeTypeDao.getPolicyScopeTypeData()); + } + JSONObject j = new JSONObject("{psTypeDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/ps_dictionary/remove_PSType.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removePSTypeDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + PolicyScopeType ecompData = (PolicyScopeType)mapper.readValue(root.get("data").toString(), PolicyScopeType.class); + policyScopeTypeDao.delete(ecompData); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.policyScopeTypeDao.getPolicyScopeTypeData()); + JSONObject j = new JSONObject("{psTypeDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/get_PSResourceDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getPSResourceEntityDataByName(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("psResourceDictionaryDatas", mapper.writeValueAsString(PolicyScopeResourceDao.getPolicyScopeResourceDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_PSResourceData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getPSResourceEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("psResourceDictionaryDatas", mapper.writeValueAsString(PolicyScopeResourceDao.getPolicyScopeResourceData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/ps_dictionary/save_psResource.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView savePSResourceDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + PolicyScopeResource ecompData = (PolicyScopeResource)mapper.readValue(root.get("psResourceDictionaryData").toString(), PolicyScopeResource.class); + if(ecompData.getId() == 0){ + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(ecompData.getName(), "name", PolicyScopeResource.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + PolicyScopeResourceDao.Save(ecompData); + } + }else{ + PolicyScopeResourceDao.update(ecompData); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.PolicyScopeResourceDao.getPolicyScopeResourceData()); + } + JSONObject j = new JSONObject("{psResourceDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/ps_dictionary/remove_PSResource.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removePSResourceDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + PolicyScopeResource ecompData = (PolicyScopeResource)mapper.readValue(root.get("data").toString(), PolicyScopeResource.class); + PolicyScopeResourceDao.delete(ecompData); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.PolicyScopeResourceDao.getPolicyScopeResourceData()); + JSONObject j = new JSONObject("{psResourceDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } +} + + class GroupPolicyScope{ + String resource; + String type; + String service; + String closedloop; + public String getResource() { + return resource; + } + public void setResource(String resource) { + this.resource = resource; + } + public String getType() { + return type; + } + public void setType(String type) { + this.type = type; + } + public String getService() { + return service; + } + public void setService(String service) { + this.service = service; + } + public String getClosedloop() { + return closedloop; + } + public void setClosedloop(String closedloop) { + this.closedloop = closedloop; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/SafePolicyController.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/SafePolicyController.java new file mode 100644 index 000000000..5ee72f4f0 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/SafePolicyController.java @@ -0,0 +1,319 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.controller; + +import java.io.PrintWriter; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.json.JSONObject; +import org.openecomp.policy.pap.xacml.rest.util.JsonMessage; +import org.openecomp.policy.rest.dao.CategoryDao; +import org.openecomp.policy.rest.dao.RiskTypeDao; +import org.openecomp.policy.rest.dao.SafePolicyWarningDao; +import org.openecomp.policy.rest.dao.UserInfoDao; +import org.openecomp.policy.rest.jpa.Category; +import org.openecomp.policy.rest.jpa.RiskType; +import org.openecomp.policy.rest.jpa.SafePolicyWarning; +import org.openecomp.policy.rest.jpa.UserInfo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +@Controller +public class SafePolicyController { + + private static final Log logger = LogFactory.getLog(SafePolicyController.class); + + @Autowired + SafePolicyWarningDao safePolicyWarningDao; + + @Autowired + RiskTypeDao riskTypeDao; + + @Autowired + UserInfoDao userInfoDao; + + @Autowired + CategoryDao categoryDao; + + + public Category getCategory() { + for (int i = 0; i < categoryDao.getCategoryListData().size(); i++) { + Category value = categoryDao.getCategoryListData().get(i); + if (value.getShortName().equals("resource")) { + return value; + } + } + return null; + } + + public UserInfo getUserInfo(String loginId) { + UserInfo name = userInfoDao.getUserInfoByLoginId(loginId); + return name; + } + + // EcompName Dictionary + @RequestMapping(value = { "/get_RiskTypeDataByName" }, method = { + org.springframework.web.bind.annotation.RequestMethod.GET }, produces = MediaType.APPLICATION_JSON_VALUE) + public void getRiskTypeDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response) { + logger.info("get_RiskTypeDataByName is called"); + try { + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("riskTypeDictionaryDatas", mapper.writeValueAsString(riskTypeDao.getRiskTypeDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @RequestMapping(value = { "/get_RiskTypeData" }, method = { + org.springframework.web.bind.annotation.RequestMethod.GET }, produces = MediaType.APPLICATION_JSON_VALUE) + public void getEcompNameDictionaryEntityData(HttpServletRequest request, HttpServletResponse response) { + logger.info("get_RiskTypeData is called"); + try { + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("riskTypeDictionaryDatas", mapper.writeValueAsString(riskTypeDao.getRiskName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } catch (Exception e) { + e.printStackTrace(); + logger.error("ERROR While callinge DAO: " + e.getMessage()); + } + } + + @RequestMapping(value = { "/sp_dictionary/save_riskType.htm" }, method = { + org.springframework.web.bind.annotation.RequestMethod.POST }) + public ModelAndView saveRiskTypeDictionary(HttpServletRequest request, HttpServletResponse response) + throws Exception { + try { + boolean duplicateflag = false; + System.out.println("SafePolicyController: saveRiskTypeDictionary() is called"); + logger.debug("SafePolicyController: saveRiskTypeDictionary() is called"); + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + RiskType riskTypeData = (RiskType) mapper.readValue(root.get("riskTypeDictionaryData").toString(), + RiskType.class); + String userId = root.get("loginId").textValue(); + System.out.println("the userId from the ecomp portal is: " + userId); + if (riskTypeData.getId() == 0) { + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(riskTypeData.getRiskName(), "name", RiskType.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + riskTypeData.setUserCreatedBy(getUserInfo(userId)); + riskTypeData.setUserModifiedBy(getUserInfo(userId)); + System.out.println( + "SafePolicyController: got the user info now about to call Save() method on riskTypedao"); + riskTypeDao.Save(riskTypeData); + } + } else { + riskTypeData.setUserModifiedBy(this.getUserInfo(userId)); + riskTypeDao.update(riskTypeData); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.riskTypeDao.getRiskName()); + } + JSONObject j = new JSONObject("{riskTypeDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } catch (Exception e) { + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value = { "/sp_dictionary/remove_riskType.htm" }, method = { + org.springframework.web.bind.annotation.RequestMethod.POST }) + public ModelAndView removeEcompDictionary(HttpServletRequest request, HttpServletResponse response) + throws Exception { + try { + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + RiskType ecompData = (RiskType) mapper.readValue(root.get("data").toString(), RiskType.class); + riskTypeDao.delete(ecompData); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.riskTypeDao.getRiskName()); + JSONObject j = new JSONObject("{riskTypeDictionaryDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } catch (Exception e) { + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value = { "/get_SafePolicyWarningDataByName" }, method = { + org.springframework.web.bind.annotation.RequestMethod.GET }, produces = MediaType.APPLICATION_JSON_VALUE) + public void getSafePolicyWarningEntityDataByName(HttpServletRequest request, HttpServletResponse response) { + try { + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("safePolicyWarningDatas", + mapper.writeValueAsString(safePolicyWarningDao.getSafePolicyWarningDataByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @RequestMapping(value = { "/get_SafePolicyWarningData" }, method = { + org.springframework.web.bind.annotation.RequestMethod.GET }, produces = MediaType.APPLICATION_JSON_VALUE) + public void getSafePolicyWarningeEntityData(HttpServletRequest request, HttpServletResponse response) { + try { + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("safePolicyWarningDatas", + mapper.writeValueAsString(safePolicyWarningDao.getSafePolicyWarningData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @RequestMapping(value = { "/sp_dictionary/save_safePolicyWarning.htm" }, method = { + org.springframework.web.bind.annotation.RequestMethod.POST }) + public ModelAndView saveSafePolicyWarningDictionary(HttpServletRequest request, HttpServletResponse response) + throws Exception { + try { + boolean duplicateflag = false; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + SafePolicyWarning safePolicyWarning = (SafePolicyWarning) mapper + .readValue(root.get("safePolicyWarningData").toString(), SafePolicyWarning.class); + + if (safePolicyWarning.getId() == 0) { + CheckDictionaryDuplicateEntries entry = new CheckDictionaryDuplicateEntries(); + List duplicateData = entry.CheckDuplicateEntry(safePolicyWarning.getName(), "name", SafePolicyWarning.class); + if(!duplicateData.isEmpty()){ + duplicateflag = true; + }else{ + safePolicyWarningDao.Save(safePolicyWarning); + } + } else { + safePolicyWarningDao.update(safePolicyWarning); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = ""; + if(duplicateflag){ + responseString = "Duplicate"; + }else{ + responseString = mapper.writeValueAsString(this.safePolicyWarningDao.getSafePolicyWarningData()); + } + JSONObject j = new JSONObject("{safePolicyWarningDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } catch (Exception e) { + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value = { "/sp_dictionary/remove_SafePolicyWarning.htm" }, method = { + org.springframework.web.bind.annotation.RequestMethod.POST }) + public ModelAndView removeSafePolicyWarningDictionary(HttpServletRequest request, HttpServletResponse response) + throws Exception { + try { + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + SafePolicyWarning safePolicyWarningData = (SafePolicyWarning) mapper.readValue(root.get("data").toString(), + SafePolicyWarning.class); + safePolicyWarningDao.delete(safePolicyWarningData); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + String responseString = mapper.writeValueAsString(this.safePolicyWarningDao.getSafePolicyWarningData()); + JSONObject j = new JSONObject("{groupPolicyScopeListDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } catch (Exception e) { + System.out.println(e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/package-info.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/package-info.java new file mode 100644 index 000000000..df0e40a56 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/controller/package-info.java @@ -0,0 +1,27 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + * + */ +/** + * + */ +package org.openecomp.policy.pap.xacml.rest.controller; diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/ActionListDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/ActionListDaoImpl.java new file mode 100644 index 000000000..ba6c2c41e --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/ActionListDaoImpl.java @@ -0,0 +1,158 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.ActionListDao; +import org.openecomp.policy.rest.jpa.ActionList; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("ActionListDao") +public class ActionListDaoImpl implements ActionListDao{ + + private static final Log logger = LogFactory.getLog(ActionListDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getActionListData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List actionListData = null; + try { + Criteria cr = session.createCriteria(ActionList.class); + actionListData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying ActionList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return actionListData; + + } + + @Override + public void Save(ActionList actionList) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(actionList); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving ActionList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(ActionList actionList) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(actionList); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting ActionList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(ActionList actionList) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(actionList); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating ActionList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getActionListDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(ActionList.class); + List actionListData = cr.list(); + for(int i = 0; i < actionListData.size(); i++){ + data.add(actionListData.get(i).getActionName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying ActionList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/ActionPolicyDictDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/ActionPolicyDictDaoImpl.java new file mode 100644 index 000000000..50d41fd02 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/ActionPolicyDictDaoImpl.java @@ -0,0 +1,185 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.hibernate.criterion.Restrictions; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.ActionPolicyDictDao; +import org.openecomp.policy.rest.jpa.ActionPolicyDict; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + + +@Service("ActionPolicyDictDao") +public class ActionPolicyDictDaoImpl implements ActionPolicyDictDao { + private static final Log logger = LogFactory.getLog(ActionPolicyDictDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + + @SuppressWarnings("unchecked") + @Override + public List getActionDictData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + + List actionDictData = null; + try { + Criteria cr = session.createCriteria(ActionPolicyDict.class); + actionDictData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying ActionDictionary Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return actionDictData; + } + + @Override + public void Save(ActionPolicyDict action) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(action); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving ActionDictionary Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void delete(ActionPolicyDict action) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(action); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting ActionDictionary Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(ActionPolicyDict action) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(action); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating ActionDictionary Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getActionDictDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(ActionPolicyDict.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getAttributeName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying ActionDictionary Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + + @SuppressWarnings("unchecked") + @Override + public ActionPolicyDict getActionEntityDatabyId(String action) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + ActionPolicyDict data = null; + try { + Criteria cr = session.createCriteria(ActionPolicyDict.class); + List attributeData = cr.add(Restrictions.eq("attributeName", action)).list(); + for(Object entity : attributeData){ + data = (ActionPolicyDict) entity; + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying ActionDictionary Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/AddressGroupDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/AddressGroupDaoImpl.java new file mode 100644 index 000000000..951a38a28 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/AddressGroupDaoImpl.java @@ -0,0 +1,157 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.AddressGroupDao; +import org.openecomp.policy.rest.jpa.AddressGroup; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("AddressGroupDao") +public class AddressGroupDaoImpl implements AddressGroupDao{ + private static final Log logger = LogFactory.getLog(AddressGroupDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getAddressGroupData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List attributeData = null; + try { + Criteria cr = session.createCriteria(AddressGroup.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying AddressGroup Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + + } + + @Override + public void Save(AddressGroup attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving AddressGroup Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(AddressGroup attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting AddressGroup Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(AddressGroup attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating AddressGroup Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getAddressGroupDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(AddressGroup.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getGroupName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying AddressGroup Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/AttributeDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/AttributeDaoImpl.java new file mode 100644 index 000000000..7eb51d3f4 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/AttributeDaoImpl.java @@ -0,0 +1,157 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.AttributeDao; +import org.openecomp.policy.rest.jpa.Attribute; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("AttributeDao") +public class AttributeDaoImpl implements AttributeDao { + private static final Log logger = LogFactory.getLog(AttributeDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List attributeData = null; + try { + Criteria cr = session.createCriteria(Attribute.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying Attribute Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + + } + + @Override + public void Save(Attribute attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving Attribute Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(Attribute attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting Attribute Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(Attribute attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating Attribute Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @SuppressWarnings("unchecked") + @Override + public List getAttributeData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(Attribute.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getXacmlId()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying Attribute Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/BRMSParamTemplateDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/BRMSParamTemplateDaoImpl.java new file mode 100644 index 000000000..4f8478da6 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/BRMSParamTemplateDaoImpl.java @@ -0,0 +1,157 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.BRMSParamTemplateDao; +import org.openecomp.policy.rest.jpa.BRMSParamTemplate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("BRMSParamTemplateDao") +public class BRMSParamTemplateDaoImpl implements BRMSParamTemplateDao{ + private static final Log logger = LogFactory.getLog(BRMSParamTemplateDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getBRMSParamTemplateData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List attributeData =null; + try { + Criteria cr = session.createCriteria(BRMSParamTemplate.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying BRMSParamTemplate Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + + } + + @Override + public void Save(BRMSParamTemplate attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving BRMSParamTemplate Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(BRMSParamTemplate attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting BRMSParamTemplate Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(BRMSParamTemplate attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating BRMSParamTemplate Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getBRMSParamDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(BRMSParamTemplate.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getRuleName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying BRMSParamTemplate Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/CategoryDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/CategoryDaoImpl.java new file mode 100644 index 000000000..f3fcbf152 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/CategoryDaoImpl.java @@ -0,0 +1,76 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.CategoryDao; +import org.openecomp.policy.rest.jpa.Category; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("CategoryDao") +public class CategoryDaoImpl implements CategoryDao { + private static final Log logger = LogFactory.getLog(CategoryDaoImpl.class); + + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getCategoryListData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List categoryListData = null; + try { + Criteria cr = session.createCriteria(Category.class); + categoryListData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying Category Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return categoryListData; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/DCAEUUIDDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/DCAEUUIDDaoImpl.java new file mode 100644 index 000000000..ddd4606f9 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/DCAEUUIDDaoImpl.java @@ -0,0 +1,157 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.DCAEUUIDDao; +import org.openecomp.policy.rest.jpa.DCAEuuid; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("DCAEUUIDDao") +public class DCAEUUIDDaoImpl implements DCAEUUIDDao{ + private static final Log logger = LogFactory.getLog(DCAEUUIDDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getDCAEuuidData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List attributeData = null; + try { + Criteria cr = session.createCriteria(DCAEuuid.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying DCAEUUID Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + + } + + @Override + public void Save(DCAEuuid attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving DCAEUUID Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(DCAEuuid attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting DCAEUUID Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(DCAEuuid attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating DCAEUUID Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getDCAEuuidDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(DCAEuuid.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying DCAEUUID Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/DecisionPolicyDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/DecisionPolicyDaoImpl.java new file mode 100644 index 000000000..9762e1d34 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/DecisionPolicyDaoImpl.java @@ -0,0 +1,158 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.DecisionPolicyDao; +import org.openecomp.policy.rest.jpa.DecisionSettings; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("DecisionSettingsDao") +public class DecisionPolicyDaoImpl implements DecisionPolicyDao{ + private static final Log logger = LogFactory.getLog(DecisionPolicyDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getDecisionSettingsData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List decisionSettingsData = null; + try { + Criteria cr = session.createCriteria(DecisionSettings.class); + decisionSettingsData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying DecisionSettings Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return decisionSettingsData; + + } + + @Override + public void Save(DecisionSettings decisionSettings) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(decisionSettings); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving DecisionSettings Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(DecisionSettings decisionSettings) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(decisionSettings); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting DecisionSettings Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(DecisionSettings decisionSettings) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(decisionSettings); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating DecisionSettings Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @SuppressWarnings("unchecked") + @Override + public List getDecisionDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(DecisionSettings.class); + List decisionSettingsData = cr.list(); + for(int i = 0; i < decisionSettingsData.size(); i++){ + data.add(decisionSettingsData.get(i).getXacmlId()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying DecisionSettings Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/DescriptiveScopeDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/DescriptiveScopeDaoImpl.java new file mode 100644 index 000000000..8d286859c --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/DescriptiveScopeDaoImpl.java @@ -0,0 +1,182 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.hibernate.criterion.Restrictions; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.DescriptiveScopeDao; +import org.openecomp.policy.rest.jpa.DescriptiveScope; +import org.openecomp.policy.rest.jpa.PolicyVersion; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("DescriptiveScopeDao") +public class DescriptiveScopeDaoImpl implements DescriptiveScopeDao{ + private static final Log logger = LogFactory.getLog(DescriptiveScopeDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getDescriptiveScope() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List descriptiveScopeData = null; + try { + Criteria cr = session.createCriteria(DescriptiveScope.class); + descriptiveScopeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying DescriptiveScope Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return descriptiveScopeData; + } + + @Override + public void Save(DescriptiveScope descriptiveScope) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(descriptiveScope); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving DescriptiveScope Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(DescriptiveScope descriptiveScope) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(descriptiveScope); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting DescriptiveScope Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void update(DescriptiveScope descriptiveScope) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(descriptiveScope); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating DescriptiveScope Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getDescriptiveScopeDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(DescriptiveScope.class); + List descriptiveScopeData = cr.list(); + for(int i = 0; i < descriptiveScopeData.size(); i++){ + data.add(descriptiveScopeData.get(i).getScopeName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying DescriptiveScope Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + + @Override + public DescriptiveScope getDescriptiveScopeById(String name) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + DescriptiveScope data = null; + try { + Criteria cr = session.createCriteria(DescriptiveScope.class); + cr.add(Restrictions.eq("scopename",name)); + data = (DescriptiveScope) cr.list().get(0); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying DescriptiveScope Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/EcompNameDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/EcompNameDaoImpl.java new file mode 100644 index 000000000..9bafc3a5c --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/EcompNameDaoImpl.java @@ -0,0 +1,167 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.EcompNameDao; +import org.openecomp.policy.rest.jpa.EcompName; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("EcompNameDao") +public class EcompNameDaoImpl implements EcompNameDao { + private static final Log logger = LogFactory.getLog(EcompNameDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getEcompName() { + System.out.println("EcompNameDaoImpl: getEcompName() is called"); + logger.debug("EcompNameDaoImpl: getEcompName() is called"); + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List ecompNameData = null; + try { + Criteria cr = session.createCriteria(EcompName.class); + ecompNameData = cr.list(); + System.out.println("Data returned from ecompname table"+ecompNameData.toString()); + logger.debug("Data returned from ecompname table: " + ecompNameData.toString()); + tx.commit(); + } catch (Exception e) { + System.out.println("Exception Occured while Querying ecompname"+e); + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying EcompName Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return ecompNameData; + } + + @Override + public void Save(EcompName ecompName) { + System.out.println("EcompNameDaoImpl: Save() is called"); + logger.debug("EcompNameDaoImpl: Save() is called"); + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(ecompName); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving EcompName Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(EcompName ecompName) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(ecompName); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting EcompName Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void update(EcompName ecompName) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(ecompName); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating EcompName Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getEcompNameDataByName() { + logger.info("getEcompNameDataByName is call from the DAO implementation class."); + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(EcompName.class); + List ecompNameData = cr.list(); + for(int i = 0; i < ecompNameData.size(); i++){ + data.add(ecompNameData.get(i).getEcompName()); + } + logger.info("data retrieved: " + data.toString()); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying EcompName Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/EnforcerPolicyDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/EnforcerPolicyDaoImpl.java new file mode 100644 index 000000000..ba621ab17 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/EnforcerPolicyDaoImpl.java @@ -0,0 +1,132 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.EnforcerPolicyDao; +import org.openecomp.policy.rest.jpa.EnforcingType; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("EnforcerPolicyDao") +public class EnforcerPolicyDaoImpl implements EnforcerPolicyDao { + private static final Log logger = LogFactory.getLog(EnforcerPolicyDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getEnforcingTypeData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List enforcingTypeData = null; + try { + Criteria cr = session.createCriteria(EnforcingType.class); + enforcingTypeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying EnforcingType Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return enforcingTypeData; + + } + + @Override + public void Save(EnforcingType enforcingType) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(enforcingType); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving EnforcingType Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(EnforcingType enforcingType) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(enforcingType); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting EnforcingType Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(EnforcingType enforcingType) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(enforcingType); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating EnforcingType Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/FirewallDictionaryListDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/FirewallDictionaryListDaoImpl.java new file mode 100644 index 000000000..b19a58b93 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/FirewallDictionaryListDaoImpl.java @@ -0,0 +1,202 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.hibernate.Criteria; +import org.hibernate.Query; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.hibernate.criterion.Restrictions; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.FirewallDictionaryListDao; +import org.openecomp.policy.rest.jpa.FirewallDictionaryList; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +@Service("FirewallDictionaryListDao") +public class FirewallDictionaryListDaoImpl implements FirewallDictionaryListDao { + private static final Log logger = LogFactory.getLog(FirewallDictionaryListDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @Override + public List getFWDictionaryListData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List attributeData = null; + try { + Criteria cr = session.createCriteria(FirewallDictionaryList.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying FirewallDictionaryList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + + } + + @Override + public List getFWDictionaryListDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(FirewallDictionaryList.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getParentItemName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying FirewallDictionaryList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + + @Override + public void Save(FirewallDictionaryList firewallDictionaryList) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(firewallDictionaryList); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving FirewallDictionaryList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(FirewallDictionaryList firewallDictionaryList) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(firewallDictionaryList); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting FirewallDictionaryList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void update(FirewallDictionaryList firewallDictionaryList) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(firewallDictionaryList); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating FirewallDictionaryList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void updateQuery(String query) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + Query hbquery = session.createQuery(query); + hbquery.executeUpdate(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating FirewallDictionaryList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public FirewallDictionaryList getFWDictionaryDataById(String value) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + FirewallDictionaryList data = null; + try { + Criteria cr = session.createCriteria(FirewallDictionaryList.class); + cr = cr.add(Restrictions.eq("parentItemName",value)); + data = (FirewallDictionaryList) cr.list().get(0); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying FirewallDictionaryList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/GroupPolicyScopeListDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/GroupPolicyScopeListDaoImpl.java new file mode 100644 index 000000000..edc147fc2 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/GroupPolicyScopeListDaoImpl.java @@ -0,0 +1,182 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.hibernate.criterion.Restrictions; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.GroupPolicyScopeListDao; +import org.openecomp.policy.rest.jpa.GroupPolicyScopeList; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("GroupPolicyScopeListDao") +public class GroupPolicyScopeListDaoImpl implements GroupPolicyScopeListDao { + private static final Log logger = LogFactory.getLog(GroupPolicyScopeListDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getGroupPolicyScopeListData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List attributeData = null; + try { + Criteria cr = session.createCriteria(GroupPolicyScopeList.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying GroupPolicyScopeList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + } + + @SuppressWarnings("unchecked") + @Override + public List getGroupPolicyScopeListDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(GroupPolicyScopeList.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getGroupName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying GroupPolicyScopeList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + + @Override + public void Save(GroupPolicyScopeList attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving GroupPolicyScopeList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(GroupPolicyScopeList attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting Attribute Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void update(GroupPolicyScopeList attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating Attribute Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List CheckDuplicateEntry(String value) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = null; + try { + Criteria cr = session.createCriteria(GroupPolicyScopeList.class); + cr.add(Restrictions.eq("name",value)); + data = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying GroupPolicyScopeList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/MicroServiceConfigNameDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/MicroServiceConfigNameDaoImpl.java new file mode 100644 index 000000000..fdee32cc9 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/MicroServiceConfigNameDaoImpl.java @@ -0,0 +1,158 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.MicroServiceConfigNameDao; +import org.openecomp.policy.rest.jpa.MicroServiceConfigName; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("MicroServiceConfigNameDao") +public class MicroServiceConfigNameDaoImpl implements MicroServiceConfigNameDao{ + private static final Log logger = LogFactory.getLog(MicroServiceConfigNameDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getMicroServiceConfigNameData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List attributeData = null; + try { + Criteria cr = session.createCriteria(MicroServiceConfigName.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying MicroServiceConfigName Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + + } + + @Override + public void Save(MicroServiceConfigName attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving MicroServiceConfigName Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(MicroServiceConfigName attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting MicroServiceConfigName Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(MicroServiceConfigName attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating MicroServiceConfigName Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getMSConfigDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(MicroServiceConfigName.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying MicroServiceConfigName Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/MicroServiceLocationDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/MicroServiceLocationDaoImpl.java new file mode 100644 index 000000000..91a2f42cf --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/MicroServiceLocationDaoImpl.java @@ -0,0 +1,158 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.MicroServiceLocationDao; +import org.openecomp.policy.rest.jpa.MicroServiceLocation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("MicroServiceLocationDao") +public class MicroServiceLocationDaoImpl implements MicroServiceLocationDao{ + private static final Log logger = LogFactory.getLog(MicroServiceLocationDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getMicroServiceLocationData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List attributeData = null; + try { + Criteria cr = session.createCriteria(MicroServiceLocation.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying MicroServiceLocation Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + + } + + @Override + public void Save(MicroServiceLocation attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving MicroServiceLocation Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(MicroServiceLocation attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting MicroServiceLocation Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(MicroServiceLocation attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating MicroServiceLocation Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getMSLocationDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(MicroServiceLocation.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying MicroServiceLocation Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/MicroServiceModelsDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/MicroServiceModelsDaoImpl.java new file mode 100644 index 000000000..c4e66b5a3 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/MicroServiceModelsDaoImpl.java @@ -0,0 +1,161 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.MicroServiceModelsDao; +import org.openecomp.policy.rest.jpa.MicroServiceModels; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("MicroServiceModelsDao") +public class MicroServiceModelsDaoImpl implements MicroServiceModelsDao{ + private static final Log logger = LogFactory.getLog(MicroServiceModelsDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getMicroServiceModelsData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List attributeData = null; + try { + Criteria cr = session.createCriteria(MicroServiceModels.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying MicroServiceModels Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + + } + + @Override + public void Save(MicroServiceModels attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving MicroServiceModels Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(MicroServiceModels attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting MicroServiceModels Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(MicroServiceModels attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating MicroServiceModels Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getMSModelsDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(MicroServiceModels.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + if(attributeData.get(i).getVersion() == null || attributeData.get(i).getVersion().equals("")){ + data.add(attributeData.get(i).getModelName()); + }else{ + data.add(attributeData.get(i).getModelName() + "-v" + attributeData.get(i).getVersion()); + } + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying MicroServiceModels Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/PEPOptionsDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/PEPOptionsDaoImpl.java new file mode 100644 index 000000000..92b89e9e3 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/PEPOptionsDaoImpl.java @@ -0,0 +1,159 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.PEPOptionsDao; +import org.openecomp.policy.rest.jpa.PEPOptions; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("PEPOptionsDao") +public class PEPOptionsDaoImpl implements PEPOptionsDao{ + private static final Log logger = LogFactory.getLog(PEPOptionsDaoImpl.class); + + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getPEPOptionsData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List pepOptionsData = null; + try { + Criteria cr = session.createCriteria(PEPOptions.class); + pepOptionsData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying PEPOptions Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return pepOptionsData; + + } + + @Override + public void Save(PEPOptions pepOptions) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(pepOptions); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving PEPOptions Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(PEPOptions pepOptions) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(pepOptions); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting PEPOptions Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(PEPOptions pepOptions) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(pepOptions); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating PEPOptions Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getPEPOptionsDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(PEPOptions.class); + List pepOptionsData = cr.list(); + for(int i = 0; i < pepOptionsData.size(); i++){ + data.add(pepOptionsData.get(i).getPepName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying PEPOptions Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/PolicyScopeClosedLoopDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/PolicyScopeClosedLoopDaoImpl.java new file mode 100644 index 000000000..6ac3e5bc9 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/PolicyScopeClosedLoopDaoImpl.java @@ -0,0 +1,181 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.hibernate.criterion.Restrictions; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.PolicyScopeClosedLoopDao; +import org.openecomp.policy.rest.jpa.PolicyScopeClosedLoop; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("PolicyScopeClosedLoopDao") +public class PolicyScopeClosedLoopDaoImpl implements PolicyScopeClosedLoopDao{ + private static final Log logger = LogFactory.getLog(PolicyScopeClosedLoopDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getPolicyScopeClosedLoopData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List attributeData = null; + try { + Criteria cr = session.createCriteria(PolicyScopeClosedLoop.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying PolicyScopeClosedLoop Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + } + + @SuppressWarnings("unchecked") + @Override + public List getPolicyScopeClosedLoopDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(PolicyScopeClosedLoop.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying PolicyScopeClosedLoop Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + + @Override + public void Save(PolicyScopeClosedLoop attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving PolicyScopeClosedLoop Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(PolicyScopeClosedLoop attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting PolicyScopeClosedLoop Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(PolicyScopeClosedLoop attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating PolicyScopeClosedLoop Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List CheckDuplicateEntry(String value) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = null; + try { + Criteria cr = session.createCriteria(PolicyScopeClosedLoop.class); + cr.add(Restrictions.eq("name",value)); + data = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying PolicyScopeClosedLoop Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/PolicyScopeResourceDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/PolicyScopeResourceDaoImpl.java new file mode 100644 index 000000000..6fe91b112 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/PolicyScopeResourceDaoImpl.java @@ -0,0 +1,181 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.hibernate.criterion.Restrictions; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.PolicyScopeResourceDao; +import org.openecomp.policy.rest.jpa.PolicyScopeResource; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("PolicyScopeResourceDao") +public class PolicyScopeResourceDaoImpl implements PolicyScopeResourceDao{ + private static final Log logger = LogFactory.getLog(PolicyScopeResourceDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getPolicyScopeResourceData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List attributeData = null; + try { + Criteria cr = session.createCriteria(PolicyScopeResource.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying PolicyScopeResource Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + } + + @SuppressWarnings("unchecked") + @Override + public List getPolicyScopeResourceDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(PolicyScopeResource.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying PolicyScopeResource Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + + @Override + public void Save(PolicyScopeResource attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving PolicyScopeResource Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void delete(PolicyScopeResource attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting PolicyScopeResource Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void update(PolicyScopeResource attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating PolicyScopeResource Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List CheckDuplicateEntry(String value) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = null; + try { + Criteria cr = session.createCriteria(PolicyScopeResource.class); + cr.add(Restrictions.eq("name",value)); + data = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying PolicyScopeResource Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/PolicyScopeServiceDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/PolicyScopeServiceDaoImpl.java new file mode 100644 index 000000000..d90d5a014 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/PolicyScopeServiceDaoImpl.java @@ -0,0 +1,182 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.hibernate.criterion.Restrictions; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.PolicyScopeServiceDao; +import org.openecomp.policy.rest.jpa.PolicyScopeService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("PolicyScopeServiceDao") +public class PolicyScopeServiceDaoImpl implements PolicyScopeServiceDao{ + private static final Log logger = LogFactory.getLog(PolicyScopeServiceDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getPolicyScopeServiceData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List attributeData = null; + try { + Criteria cr = session.createCriteria(PolicyScopeService.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying PolicyScopeService Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + } + + @SuppressWarnings("unchecked") + @Override + public List getPolicyScopeServiceDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(PolicyScopeService.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying PolicyScopeService Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + + @Override + public void Save(PolicyScopeService attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving PolicyScopeService Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(PolicyScopeService attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting PolicyScopeService Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void update(PolicyScopeService attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating PolicyScopeService Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List CheckDuplicateEntry(String value) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = null; + try { + Criteria cr = session.createCriteria(PolicyScopeService.class); + cr.add(Restrictions.eq("name",value)); + data = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying PolicyScopeService Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/PolicyScopeTypeDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/PolicyScopeTypeDaoImpl.java new file mode 100644 index 000000000..66317a4d0 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/PolicyScopeTypeDaoImpl.java @@ -0,0 +1,182 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.hibernate.criterion.Restrictions; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.PolicyScopeTypeDao; +import org.openecomp.policy.rest.jpa.PolicyScopeType; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("PolicyScopeTypeDao") +public class PolicyScopeTypeDaoImpl implements PolicyScopeTypeDao{ + private static final Log logger = LogFactory.getLog(PolicyScopeTypeDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getPolicyScopeTypeData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List attributeData = null; + try { + Criteria cr = session.createCriteria(PolicyScopeType.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying PolicyScopeType Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + } + + @SuppressWarnings("unchecked") + @Override + public List getPolicyScopeTypeDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(PolicyScopeType.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying PolicyScopeType Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + + @Override + public void Save(PolicyScopeType attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving PolicyScopeType Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(PolicyScopeType attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting PolicyScopeType Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void update(PolicyScopeType attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating PolicyScopeType Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List CheckDuplicateEntry(String value) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = null; + try { + Criteria cr = session.createCriteria(PolicyScopeType.class); + cr.add(Restrictions.eq("name",value)); + data = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying PolicyScopeType Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/PortListDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/PortListDaoImpl.java new file mode 100644 index 000000000..a3139b2c6 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/PortListDaoImpl.java @@ -0,0 +1,158 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.PortListDao; +import org.openecomp.policy.rest.jpa.PortList; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("PortListDao") +public class PortListDaoImpl implements PortListDao { + private static final Log logger = LogFactory.getLog(PortListDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getPortListData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List attributeData = null; + try { + Criteria cr = session.createCriteria(PortList.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying PortList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + + } + + @Override + public void Save(PortList attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving PortList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(PortList attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting PortList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(PortList attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating PortList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getPortListDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(PortList.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getPortName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying PortList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/PrefixListDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/PrefixListDaoImpl.java new file mode 100644 index 000000000..2fecc7d88 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/PrefixListDaoImpl.java @@ -0,0 +1,158 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.PrefixListDao; +import org.openecomp.policy.rest.jpa.PREFIXLIST; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("PrefixListDao") +public class PrefixListDaoImpl implements PrefixListDao{ + private static final Log logger = LogFactory.getLog(PrefixListDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getPREFIXLISTData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List attributeData = null; + try { + Criteria cr = session.createCriteria(PREFIXLIST.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying PREFIXLIST Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + + } + + @Override + public void Save(PREFIXLIST attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving PREFIXLIST Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(PREFIXLIST attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting PREFIXLIST Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(PREFIXLIST attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating PREFIXLIST Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getPrefixListDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(PREFIXLIST.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getPrefixListName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying PREFIXLIST Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/ProtocolListDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/ProtocolListDaoImpl.java new file mode 100644 index 000000000..7d78d387a --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/ProtocolListDaoImpl.java @@ -0,0 +1,158 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.ProtocolListDao; +import org.openecomp.policy.rest.jpa.ProtocolList; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("ProtocolListDao") +public class ProtocolListDaoImpl implements ProtocolListDao { + private static final Log logger = LogFactory.getLog(ProtocolListDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getProtocolListData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List attributeData = null; + try { + Criteria cr = session.createCriteria(ProtocolList.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying ProtocolList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + + } + + @Override + public void Save(ProtocolList attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving ProtocolList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(ProtocolList attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting ProtocolList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(ProtocolList attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating ProtocolList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getProtocolListDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(ProtocolList.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getProtocolName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying ProtocolList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/RiskTypeDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/RiskTypeDaoImpl.java new file mode 100644 index 000000000..1318f82fa --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/RiskTypeDaoImpl.java @@ -0,0 +1,167 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.EcompNameDao; +import org.openecomp.policy.rest.dao.RiskTypeDao; +import org.openecomp.policy.rest.jpa.EcompName; +import org.openecomp.policy.rest.jpa.RiskType; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("RiskTypeDao") +public class RiskTypeDaoImpl implements RiskTypeDao { + private static final Log logger = LogFactory.getLog(RiskTypeDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getRiskName() { + System.out.println("RiskTypeDaoImpl: getRiskName() is called"); + logger.debug("RiskTypeDaoImpl: getRiskName() is called"); + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List riskTypeData = null; + try { + Criteria cr = session.createCriteria(RiskType.class); + riskTypeData = cr.list(); + logger.debug("Data returned from RiskType table: " + riskTypeData.toString()); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying RiskType Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return riskTypeData; + } + + @Override + public void Save(RiskType riskName) { + System.out.println("RiskTypeDaoImpl: Save() is called"); + logger.debug("RiskTypeDaoImpl: Save() is called"); + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(riskName); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving RiskType Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(RiskType riskName) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(riskName); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting RiskType Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void update(RiskType riskName) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(riskName); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating RiskType Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getRiskTypeDataByName() { + logger.info("getRiskTypeDataByName is call from the DAO implementation class."); + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(RiskType.class); + List riskTypeData = cr.list(); + for(int i = 0; i < riskTypeData.size(); i++){ + data.add(riskTypeData.get(i).getRiskName()); + } + logger.info("data retrieved: " + data.toString()); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying RiskType Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/SafePolicyWarningDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/SafePolicyWarningDaoImpl.java new file mode 100644 index 000000000..37a77f9b5 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/SafePolicyWarningDaoImpl.java @@ -0,0 +1,181 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.hibernate.criterion.Restrictions; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.SafePolicyWarningDao; +import org.openecomp.policy.rest.jpa.SafePolicyWarning; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("SafePolicyWarningDao") +public class SafePolicyWarningDaoImpl implements SafePolicyWarningDao { + private static final Log logger = LogFactory.getLog(SafePolicyWarningDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getSafePolicyWarningData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List attributeData = null; + try { + Criteria cr = session.createCriteria(SafePolicyWarning.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying SafePolicyWarning Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + } + + @SuppressWarnings("unchecked") + @Override + public List getSafePolicyWarningDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(SafePolicyWarning.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying SafePolicyWarning Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + + @Override + public void Save(SafePolicyWarning attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving SafePolicyWarning Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(SafePolicyWarning attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting Attribute Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void update(SafePolicyWarning attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating Attribute Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public SafePolicyWarning getSafePolicyWarningDataById(String riskType) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + SafePolicyWarning data = null; + try { + Criteria cr = session.createCriteria(SafePolicyWarning.class); + cr.add(Restrictions.eq("name",riskType)); + data = (SafePolicyWarning) cr.list().get(0); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying SafePolicyWarning Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/SecurityZoneDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/SecurityZoneDaoImpl.java new file mode 100644 index 000000000..9c79773dd --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/SecurityZoneDaoImpl.java @@ -0,0 +1,157 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.SecurityZoneDao; +import org.openecomp.policy.rest.jpa.SecurityZone; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("SecurityZoneDao") +public class SecurityZoneDaoImpl implements SecurityZoneDao{ + private static final Log logger = LogFactory.getLog(SecurityZoneDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getSecurityZoneData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List attributeData = null; + try { + Criteria cr = session.createCriteria(SecurityZone.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying SecurityZone Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + + } + + @Override + public void Save(SecurityZone attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving SecurityZone Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void delete(SecurityZone attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting SecurityZone Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(SecurityZone attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating SecurityZone Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getSecurityZoneDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(SecurityZone.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getZoneName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying SecurityZone Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/ServiceDictionaryDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/ServiceDictionaryDaoImpl.java new file mode 100644 index 000000000..226c50060 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/ServiceDictionaryDaoImpl.java @@ -0,0 +1,157 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.ServiceDictionaryDao; +import org.openecomp.policy.rest.jpa.ClosedLoopD2Services; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("ServiceDictionaryDao") +public class ServiceDictionaryDaoImpl implements ServiceDictionaryDao { + private static final Log logger = LogFactory.getLog(ServiceDictionaryDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getClosedLoopD2ServicesData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List closedLoopD2ServicesData = null; + try { + Criteria cr = session.createCriteria(ClosedLoopD2Services.class); + closedLoopD2ServicesData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying ClosedLoopD2Services Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return closedLoopD2ServicesData; + + } + + @Override + public void Save(ClosedLoopD2Services closedLoopD2Services) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(closedLoopD2Services); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving ClosedLoopD2Services Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(ClosedLoopD2Services closedLoopD2Services) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(closedLoopD2Services); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting ClosedLoopD2Services Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(ClosedLoopD2Services closedLoopD2Services) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(closedLoopD2Services); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating ClosedLoopD2Services Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @SuppressWarnings("unchecked") + @Override + public List getCLServiceDictDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(ClosedLoopD2Services.class); + List closedLoopD2ServicesData = cr.list(); + for(int i = 0; i < closedLoopD2ServicesData.size(); i++){ + data.add(closedLoopD2ServicesData.get(i).getServiceName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying ClosedLoopD2Services Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/ServiceGroupDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/ServiceGroupDaoImpl.java new file mode 100644 index 000000000..725631306 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/ServiceGroupDaoImpl.java @@ -0,0 +1,158 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.ServiceGroupDao; +import org.openecomp.policy.rest.jpa.GroupServiceList; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("ServiceGroupDao") +public class ServiceGroupDaoImpl implements ServiceGroupDao{ + private static final Log logger = LogFactory.getLog(ServiceGroupDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getGroupServiceListData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List attributeData = null; + try { + Criteria cr = session.createCriteria(GroupServiceList.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying GroupServiceList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + + } + + @Override + public void Save(GroupServiceList attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving GroupServiceList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(GroupServiceList attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting GroupServiceList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(GroupServiceList attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating GroupServiceList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getGroupServiceDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(GroupServiceList.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getGroupName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying GroupServiceList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/ServiceListDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/ServiceListDaoImpl.java new file mode 100644 index 000000000..01ff3e4fc --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/ServiceListDaoImpl.java @@ -0,0 +1,159 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.ServiceListDao; +import org.openecomp.policy.rest.jpa.ServiceList; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("ServiceListDao") +public class ServiceListDaoImpl implements ServiceListDao { + private static final Log logger = LogFactory.getLog(ServiceListDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getServiceListData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List attributeData = null; + try { + Criteria cr = session.createCriteria(ServiceList.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying ServiceList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + + } + + @Override + public void Save(ServiceList attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving ServiceList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(ServiceList attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting ServiceList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(ServiceList attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating ServiceList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getServiceListDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(ServiceList.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getServiceName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying ServiceList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/SiteDictionaryDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/SiteDictionaryDaoImpl.java new file mode 100644 index 000000000..3b2a75176 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/SiteDictionaryDaoImpl.java @@ -0,0 +1,159 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.SiteDictionaryDao; +import org.openecomp.policy.rest.jpa.ClosedLoopSite; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + + +@Service("SiteDictionaryDao") +public class SiteDictionaryDaoImpl implements SiteDictionaryDao { + private static final Log logger = LogFactory.getLog(SiteDictionaryDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getClosedLoopSiteData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List closedLoopSiteData = null; + try { + Criteria cr = session.createCriteria(ClosedLoopSite.class); + closedLoopSiteData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying ClosedLoopSite Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return closedLoopSiteData; + + } + + @Override + public void Save(ClosedLoopSite closedLoopSite) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(closedLoopSite); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving ClosedLoopSite Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(ClosedLoopSite closedLoopSite) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(closedLoopSite); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting ClosedLoopSite Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(ClosedLoopSite closedLoopSite) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(closedLoopSite); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating ClosedLoopSite Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getCLSiteDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(ClosedLoopSite.class); + List closedLoopSiteData = cr.list(); + for(int i = 0; i < closedLoopSiteData.size(); i++){ + data.add(closedLoopSiteData.get(i).getSiteName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying ClosedLoopSite Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/TermListDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/TermListDaoImpl.java new file mode 100644 index 000000000..7568d60b0 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/TermListDaoImpl.java @@ -0,0 +1,181 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.hibernate.criterion.Restrictions; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.TermListDao; +import org.openecomp.policy.rest.jpa.TermList; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("TermListDao") +public class TermListDaoImpl implements TermListDao{ + private static final Log logger = LogFactory.getLog(TermListDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getTermListData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List attributeData = null; + try { + Criteria cr = session.createCriteria(TermList.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying TermList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + + } + + @Override + public void Save(TermList attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving TermList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(TermList attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting TermList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(TermList attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating TermList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getTermListDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(TermList.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getTermName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying TermList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + + @Override + public TermList getTermListValueByName(String name) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + TermList data = null; + try { + Criteria cr = session.createCriteria(TermList.class); + cr.add(Restrictions.eq("termName",name)); + data = (TermList) cr.list().get(0); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying TermList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/UserInfoDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/UserInfoDaoImpl.java new file mode 100644 index 000000000..04ad69c1a --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/UserInfoDaoImpl.java @@ -0,0 +1,138 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.hibernate.criterion.Restrictions; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.UserInfoDao; +import org.openecomp.policy.rest.jpa.UserInfo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + + +@Service("UserInfoDao") +public class UserInfoDaoImpl implements UserInfoDao{ + private static final Log logger = LogFactory.getLog(UserInfoDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @Override + public void save(UserInfo userInfo) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(userInfo); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving UserInfo Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @SuppressWarnings("unchecked") + @Override + public List getUserInfo() { + System.out.println("UserInfoDaoImpl: getUserInfo().. getting user info before save()"); + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List userData = null; + try { + Criteria cr = session.createCriteria(UserInfo.class); + userData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying UserInfo Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return userData; + } + + @Override + public String getUserName(String loginid) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + UserInfo user = null; + try { + user = (UserInfo) session.get(UserInfo.class, loginid); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying UserInfo Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return user.getUserName().toString(); + } + + @Override + public UserInfo getUserInfoByLoginId(String loginid) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + UserInfo userData = null; + try { + Criteria cr = session.createCriteria(UserInfo.class); + cr.add(Restrictions.eq("userLoginId", loginid)); + userData = (UserInfo) cr.list().get(0); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying UserInfo Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return userData; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/VNFTypeDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/VNFTypeDaoImpl.java new file mode 100644 index 000000000..4d424fa9f --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/VNFTypeDaoImpl.java @@ -0,0 +1,158 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.VNFTypeDao; +import org.openecomp.policy.rest.jpa.VNFType; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("VNFTypeDao") +public class VNFTypeDaoImpl implements VNFTypeDao { + private static final Log logger = LogFactory.getLog(VNFTypeDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getVNFTypeData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List vnfTypeData = null; + try { + Criteria cr = session.createCriteria(VNFType.class); + vnfTypeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying VNFType Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return vnfTypeData; + + } + + @Override + public void Save(VNFType vnfType) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(vnfType); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving VNFType Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(VNFType vnfType) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(vnfType); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting VNFType Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(VNFType vnfType) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(vnfType); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating VNFType Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getVNFTypeDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(VNFType.class); + List vnfTypeData = cr.list(); + for(int i = 0; i < vnfTypeData.size(); i++){ + data.add(vnfTypeData.get(i).getVnftype()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying VNFType Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + + } +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/VSCLActionDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/VSCLActionDaoImpl.java new file mode 100644 index 000000000..8ab6bfd19 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/VSCLActionDaoImpl.java @@ -0,0 +1,158 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.VSCLActionDao; +import org.openecomp.policy.rest.jpa.VSCLAction; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("VSCLActionDao") +public class VSCLActionDaoImpl implements VSCLActionDao{ + private static final Log logger = LogFactory.getLog(VSCLActionDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getVSCLActionData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List vSCLActionData = null; + try { + Criteria cr = session.createCriteria(VSCLAction.class); + vSCLActionData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying VSCLAction Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return vSCLActionData; + + } + + @Override + public void Save(VSCLAction vSCLAction) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(vSCLAction); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving VSCLAction Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(VSCLAction vSCLAction) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(vSCLAction); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting VSCLAction Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(VSCLAction vSCLAction) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(vSCLAction); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating VSCLAction Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getVsclActionDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(VSCLAction.class); + List vSCLActionData = cr.list(); + for(int i = 0; i < vSCLActionData.size(); i++){ + data.add(vSCLActionData.get(i).getVsclaction()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying VSCLAction Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/VarbindDictionaryDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/VarbindDictionaryDaoImpl.java new file mode 100644 index 000000000..dba3a0d57 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/VarbindDictionaryDaoImpl.java @@ -0,0 +1,181 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.hibernate.criterion.Restrictions; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.VarbindDictionaryDao; +import org.openecomp.policy.rest.jpa.VarbindDictionary; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("VarbindDictionaryDao") +public class VarbindDictionaryDaoImpl implements VarbindDictionaryDao { + private static final Log logger = LogFactory.getLog(VarbindDictionaryDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getVarbindDictionaryData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List varbindDictionaryData = null; + try { + Criteria cr = session.createCriteria(VarbindDictionary.class); + varbindDictionaryData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying VarbindDictionary Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return varbindDictionaryData; + + } + + @Override + public void Save(VarbindDictionary varbindDictionary) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(varbindDictionary); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving VarbindDictionary Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(VarbindDictionary varbindDictionary) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(varbindDictionary); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting VarbindDictionary Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(VarbindDictionary varbindDictionary) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(varbindDictionary); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating VarbindDictionary Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getVarbindDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(VarbindDictionary.class); + List varbindDictionaryData = cr.list(); + for(int i = 0; i < varbindDictionaryData.size(); i++){ + data.add(varbindDictionaryData.get(i).getVarbindName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying VarbindDictionary Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + + @Override + public List getVarbindEntityByName(String value) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = null; + try { + Criteria cr = session.createCriteria(VarbindDictionary.class); + cr.add(Restrictions.eq("varbindName",value)); + data = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying VarbindDictionary Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/ZoneDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/ZoneDaoImpl.java new file mode 100644 index 000000000..865a08516 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/ZoneDaoImpl.java @@ -0,0 +1,159 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.ZoneDao; +import org.openecomp.policy.rest.jpa.Zone; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("ZoneDao") +public class ZoneDaoImpl implements ZoneDao{ + private static final Log logger = LogFactory.getLog(ZoneDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getZoneData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List attributeData = null; + try { + Criteria cr = session.createCriteria(Zone.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying Zone Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + + } + + @Override + public void Save(Zone attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving Zone Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(Zone attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting Zone Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(Zone attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating Zone Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getZoneDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(Zone.class); + List attributeData = cr.list(); + + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getZoneName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying Zone Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/model/PDPPolicyContainer.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/model/PDPPolicyContainer.java new file mode 100644 index 000000000..e91c79a40 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/model/PDPPolicyContainer.java @@ -0,0 +1,349 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.model; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Set; + +import org.openecomp.policy.pap.xacml.rest.util.PolicyContainer; +import org.openecomp.policy.pap.xacml.rest.util.PolicyItemSetChangeNotifier; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; +import com.att.research.xacml.api.pap.PDP; +import com.att.research.xacml.api.pap.PDPGroup; +import com.att.research.xacml.api.pap.PDPPolicy; +import org.openecomp.policy.xacml.std.pap.StdPDPPolicy; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class PDPPolicyContainer extends PolicyItemSetChangeNotifier implements PolicyContainer.Indexed { + private static final long serialVersionUID = 1L; + private static Logger logger = FlexLogger.getLogger(PDPPolicyContainer.class); + + /** + * String identifier of a file's "Id" property. + */ + public static String PROPERTY_ID = "Id"; + + /** + * String identifier of a file's "name" property. + */ + public static String PROPERTY_NAME = "Name"; + + /** + * String identifier of a file's "name" property. + */ + public static String PROPERTY_VERSION = "Version"; + + /** + * String identifier of a file's "Description" property. + */ + public static String PROPERTY_DESCRIPTION = "Description"; + + /** + * String identifier of a file's "IsRoot" property. + */ + public static String PROPERTY_ISROOT = "Root"; + + /** + * List of the string identifiers for the available properties. + */ + public static Collection PDPPOLICY_PROPERTIES; + + private final Object data; + private List policies; + + @SuppressWarnings("unchecked") + public PDPPolicyContainer(Object data) { + super(); + this.data = data; + if (this.data instanceof PDPGroup) { + policies = new ArrayList (((PDPGroup) this.data).getPolicies()); + } + if (this.data instanceof PDP) { + policies = new ArrayList (((PDP) this.data).getPolicies()); + } + if (this.data instanceof Set) { + policies = new ArrayList ((Set)data); + } + if (this.policies == null) { + logger.info("NULL policies"); + throw new NullPointerException("PDPPolicyContainer created with unexpected Object type '" + data.getClass().getName() + "'"); + } + this.setContainer(this); + } + + @Override + public Object nextItemId(Object itemId) { + if (logger.isTraceEnabled()) { + logger.trace("nextItemId: " + itemId); + } + int index = this.policies.indexOf(itemId); + if (index == -1 || ((index + 1) >= this.policies.size())) { + return null; + } + return new PDPPolicyItem(this.policies.get(index + 1)); + } + + @Override + public Object prevItemId(Object itemId) { + if (logger.isTraceEnabled()) { + logger.trace("prevItemId: " + itemId); + } + int index = this.policies.indexOf(itemId); + if (index <= 0) { + return null; + } + return new PDPPolicyItem(this.policies.get(index - 1)); + } + + @Override + public Object firstItemId() { + if (logger.isTraceEnabled()) { + logger.trace("firstItemId: "); + } + if (this.policies.isEmpty()) { + return null; + } + return new PDPPolicyItem(this.policies.get(0)); + } + + @Override + public Object lastItemId() { + if (logger.isTraceEnabled()) { + logger.trace("lastItemid: "); + } + if (this.policies.isEmpty()) { + return null; + } + return new PDPPolicyItem(this.policies.get(this.policies.size() - 1)); + } + + @Override + public boolean isFirstId(Object itemId) { + if (logger.isTraceEnabled()) { + logger.trace("isFirstId: " + itemId); + } + if (this.policies.isEmpty()) { + return false; + } + return (itemId.equals(this.policies.get(0))); + } + + @Override + public boolean isLastId(Object itemId) { + if (logger.isTraceEnabled()) { + logger.trace("isLastId: " + itemId); + } + if (this.policies.isEmpty()) { + return false; + } + return (itemId.equals(this.policies.get(this.policies.size() - 1))); + } + + @Override + public Object addItemAfter(Object previousItemId) + throws UnsupportedOperationException { + return null; + } + + @Override + public Collection getContainerPropertyIds() { + return PDPPOLICY_PROPERTIES; + } + + @Override + public Collection getItemIds() { + final Collection items = new ArrayList(); + items.addAll(this.policies); + return Collections.unmodifiableCollection(items); + } + + + @Override + public Class getType(Object propertyId) { + if (propertyId.equals(PROPERTY_ID)) { + return String.class; + } + if (propertyId.equals(PROPERTY_NAME)) { + return String.class; + } + if (propertyId.equals(PROPERTY_VERSION)) { + return String.class; + } + if (propertyId.equals(PROPERTY_DESCRIPTION)) { + return String.class; + } + if (propertyId.equals(PROPERTY_ISROOT)) { + return Boolean.class; + } + return null; + } + + @Override + public int size() { + if (logger.isTraceEnabled()) { + logger.trace("size: " + this.policies.size()); + } + return this.policies.size(); + } + + @Override + public boolean containsId(Object itemId) { + if (logger.isTraceEnabled()) { + logger.trace("containsId: " + itemId); + } + return this.policies.contains(itemId); + } + + @Override + public Object addItem() throws UnsupportedOperationException { + throw new UnsupportedOperationException("Cannot add an empty policy."); + } + + @Override + public boolean removeItem(Object itemId) + throws UnsupportedOperationException { + if (logger.isTraceEnabled()) { + logger.trace("removeItem: " + itemId); + } + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + StdPDPPolicy pdpPolicy = null; + try { + pdpPolicy = mapper.readValue(itemId.toString() , StdPDPPolicy.class); + for(int i = 0; i< policies.size(); i++){ + if(policies.get(i).getId().equalsIgnoreCase(pdpPolicy.getId())){ + return this.policies.remove(this.policies.get(i)); + } + } + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Exception Occured While Mapping the Removing Policy from PDP Group to Std Policy"+e); + } + return this.policies.remove(itemId); + } + + @Override + public boolean addContainerProperty(Object propertyId, Class type, + Object defaultValue) throws UnsupportedOperationException { + return false; + } + + @Override + public boolean removeContainerProperty(Object propertyId) + throws UnsupportedOperationException { + return false; + } + + @Override + public boolean removeAllItems() throws UnsupportedOperationException { + return false; + } + + @Override + public int indexOfId(Object itemId) { + if (logger.isTraceEnabled()) { + logger.trace("indexOfId: " + itemId); + } + return this.policies.indexOf(itemId); + } + + @Override + public Object getIdByIndex(int index) { + if (logger.isTraceEnabled()) { + logger.trace("getIdByIndex: " + index); + } + return this.policies.get(index); + } + + @Override + public List getItemIds(int startIndex, int numberOfItems) { + if (logger.isTraceEnabled()) { + logger.trace("getItemIds: " + startIndex + " " + numberOfItems); + } + if (numberOfItems < 0) { + throw new IllegalArgumentException(); + } + return this.policies.subList(startIndex, startIndex + numberOfItems); + } + + @Override + public Object addItemAt(int index) throws UnsupportedOperationException { + if (logger.isTraceEnabled()) { + logger.trace("addItemAt: " + index); + } + return null; + } + + public class PDPPolicyItem { + private final PDPPolicy policy; + + public PDPPolicyItem(PDPPolicy itemId) { + this.policy = itemId; + } + + public String getId() { + if (logger.isTraceEnabled()) { + logger.trace("getId: " + this.policy); + } + return this.policy.getId(); + } + + public String getName() { + if (logger.isTraceEnabled()) { + logger.trace("getName: " + this.policy); + } + return this.policy.getName(); + } + + public String getVersion() { + if (logger.isTraceEnabled()) { + logger.trace("getVersion: " + this.policy); + } + return this.policy.getVersion(); + } + + public String getDescription() { + if (logger.isTraceEnabled()) { + logger.trace("getDescription: " + this.policy); + } + return this.policy.getDescription(); + } + + public boolean getRoot() { + if (logger.isTraceEnabled()) { + logger.trace("isRoot: " + this.policy); + } + return this.policy.isRoot(); + } + + public void setRoot(Boolean root) { + ((StdPDPPolicy)this.policy).setRoot(root); + } + + } +} \ No newline at end of file diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/model/RemoveGroupPolicy.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/model/RemoveGroupPolicy.java new file mode 100644 index 000000000..bb6e118ff --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/model/RemoveGroupPolicy.java @@ -0,0 +1,105 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.model; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + +import org.openecomp.policy.pap.xacml.rest.model.PDPPolicyContainer; + +import com.att.research.xacml.api.pap.PDPGroup; +import com.att.research.xacml.api.pap.PDPPolicy; + +import org.openecomp.policy.xacml.api.pap.EcompPDPGroup; +import org.openecomp.policy.xacml.std.pap.StdPDPGroup; + +public class RemoveGroupPolicy { + + + //Container from where we are fetching the policies + private static PDPPolicyContainer policyContainer; + + private final RemoveGroupPolicy self = this; + private StdPDPGroup updatedObject; + private final StdPDPGroup group; + private boolean isSaved = false; + + public RemoveGroupPolicy(StdPDPGroup group) { + + this.group = group; + + } + + public void prepareToRemove(PDPPolicy policy) { + + if (this.group == null) { + return; + } + + RemoveGroupPolicy.policyContainer = new PDPPolicyContainer(group); + + RemoveGroupPolicy.policyContainer.removeItem(policy); + + self.doSave(); + + self.isSaved = true; + + } + + @SuppressWarnings("unchecked") + protected void doSave() { + if (this.group == null) { + return; + } + + //StdPDPGroup pdpGroup = (StdPDPGroup) group; + StdPDPGroup updatedGroupObject = new StdPDPGroup( + group.getId(), + group.isDefaultGroup(), + group.getName(), + group.getDescription(), + null); + + // replace the original set of Policies with the set from the container (possibly modified by the user) + Set changedPolicies = new HashSet(); + changedPolicies.addAll((Collection) RemoveGroupPolicy.policyContainer.getItemIds()); + updatedGroupObject.setPolicies(changedPolicies); + updatedGroupObject.setEcompPdps(this.group.getEcompPdps()); + + // replace the original set of PIP Configs with the set from the container + updatedGroupObject.setPipConfigs(this.group.getPipConfigs()); + + // copy those things that the user cannot change from the original to the new object + updatedGroupObject.setStatus(this.group.getStatus()); + + this.updatedObject = updatedGroupObject; + } + + public boolean isRemoved() { + return this.isSaved; + } + + public EcompPDPGroup getUpdatedObject() { + return this.updatedObject; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/model/package-info.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/model/package-info.java new file mode 100644 index 000000000..4f7d76ad7 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/model/package-info.java @@ -0,0 +1,27 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + * + */ +/** + * + */ +package org.openecomp.policy.pap.xacml.rest.model; diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/util/JPAUtils.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/util/JPAUtils.java new file mode 100644 index 000000000..5326cb2c7 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/util/JPAUtils.java @@ -0,0 +1,242 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.util; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.Query; +import javax.servlet.ServletException; + +import org.openecomp.policy.rest.XacmlAdminAuthorization; +import org.openecomp.policy.rest.jpa.Attribute; +import org.openecomp.policy.rest.jpa.Datatype; +import org.openecomp.policy.rest.jpa.FunctionDefinition; +import org.openecomp.policy.rest.jpa.GlobalRoleSettings; + +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeSelectorType; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +public class JPAUtils { + private static Logger logger = FlexLogger.getLogger(JPAUtils.class); + + private EntityManagerFactory emf; + private static final Object mapAccess = new Object(); + private static Map> mapDatatype2Function = null; + private static Map mapID2Function = null; + private static JPAUtils currentInstance = null; + + //private static List lockdownListeners = new ArrayList(); + + /** + * Get an instance of a JPAUtils. It creates one if it does not exist. + * Only one instance is allowed to be created per server. + * @param emf The EntityFactoryManager to be used for database connections + * @return The new instance of JPAUtils or throw exception if the given emf is null. + * @throws IllegalStateException if a JPAUtils has already been constructed. Call getJPAUtilsInstance() to get this. + */ + public static JPAUtils getJPAUtilsInstance(EntityManagerFactory emf) throws Exception{ + logger.debug("getJPAUtilsInstance(EntityManagerFactory emf) as getJPAUtilsInstance("+emf+") called"); + if(currentInstance == null){ + if(emf != null){ + currentInstance = new JPAUtils(emf); + return currentInstance; + } + throw new IllegalStateException("The EntityManagerFactory is Null"); + } + return currentInstance; + } + + private JPAUtils(EntityManagerFactory emf){ + logger.debug("JPAUtils(EntityManagerFactory emf) as JPAUtils("+emf+") called"); + this.emf = emf; + } + + /** + * Gets the current instance of JPAUtils. + * @return The instance of JPAUtils or throws exception if the given instance is null. + * @throws IllegalStateException if a JPAUtils instance is null. Call getJPAUtilsInstance(EntityManagerFactory emf) to get this. + */ + public static JPAUtils getJPAUtilsInstance() throws Exception{ + logger.debug("getJPAUtilsInstance() as getJPAUtilsInstance() called"); + if(currentInstance != null){ + return currentInstance; + } + throw new IllegalStateException("The JPAUtils.currentInstance is Null. Use getJPAUtilsInstance(EntityManagerFactory emf)"); + } + + public static AttributeDesignatorType createDesignator(Attribute attribute) { + AttributeDesignatorType designator = new AttributeDesignatorType(); + designator.setAttributeId(attribute.getXacmlId()); + if (attribute.getCategoryBean() != null) { + designator.setCategory(attribute.getCategoryBean().getXacmlId()); + } else { + logger.warn("No category bean"); + } + if (attribute.getDatatypeBean() != null) { + designator.setDataType(attribute.getDatatypeBean().getXacmlId()); + } else { + logger.warn("No datatype bean"); + } + designator.setIssuer(attribute.getIssuer()); + designator.setMustBePresent(attribute.isMustBePresent()); + return designator; + } + + public static AttributeSelectorType createSelector(Attribute attribute) { + AttributeSelectorType selector = new AttributeSelectorType(); + selector.setContextSelectorId(attribute.getXacmlId()); + selector.setPath(attribute.getSelectorPath()); + if (attribute.getCategoryBean() != null) { + selector.setCategory(attribute.getCategoryBean().getXacmlId()); + } else { + logger.warn("No category bean"); + } + if (attribute.getDatatypeBean() != null) { + selector.setDataType(attribute.getDatatypeBean().getXacmlId()); + } else { + logger.warn("No datatype bean"); + } + selector.setMustBePresent(attribute.isMustBePresent()); + return selector; + } + + /** + * Builds a map in memory of a functions return datatype to function definition. Useful in limiting the number + * of SQL calls to DB especially when we don't expect these to change much. + * + * @return - A HashMap of Datatype JPA Container ID's to FunctionDefinition objects + */ + public Map> getFunctionDatatypeMap() { + + synchronized(mapAccess) { + if (mapDatatype2Function == null||mapDatatype2Function.isEmpty()) { + try { + buildFunctionMaps(); + } catch (ServletException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + return mapDatatype2Function; + } + + public Map getFunctionIDMap() { + synchronized(mapAccess) { + if (mapID2Function == null||mapID2Function.equals("{}")) { + try { + buildFunctionMaps(); + } catch (ServletException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + return mapID2Function; + } + + private void buildFunctionMaps() throws ServletException { + mapDatatype2Function = new HashMap>(); + mapID2Function = new HashMap(); + + EntityManager em = emf.createEntityManager(); + Query getFunctionDefinitions = em.createNamedQuery("FunctionDefinition.findAll"); + List functionList = getFunctionDefinitions.getResultList(); + + for (Object id : functionList) { + FunctionDefinition value = (FunctionDefinition)id; + mapID2Function.put(value.getXacmlid(), value); + if (mapDatatype2Function.containsKey(value.getDatatypeBean()) == false) { + mapDatatype2Function.put(value.getDatatypeBean(), new ArrayList()); + } + mapDatatype2Function.get(value.getDatatypeBean()).add(value); + } + + em.close(); + + } + + /** + * Returns the lockdown value, in case of exception it is assumed that lockdown functionality + * is not supported and returns false. + * + * + * @throws ReadOnlyException + * @throws ConversionException + */ + public boolean dbLockdownIgnoreErrors() { + if (logger.isTraceEnabled()) + logger.trace("ENTER"); + + boolean lockdown = false; + try { + lockdown = dbLockdown(); + } catch (Exception e) { + logger.warn("Cannot access DB lockdown value", e); + } + return lockdown; + } + + /** + * Returns the lockdown value from the database. + * + * @throws ReadOnlyException + * @throws ConversionException + */ + public boolean dbLockdown() + throws IllegalAccessException { + if (logger.isTraceEnabled()) + logger.trace("ENTER"); + + EntityManager em = emf.createEntityManager(); + Query globalRoleSettingsJPA = em.createNamedQuery("GlobalRoleSettings.findAll"); + + GlobalRoleSettings globalRoleSettings = (GlobalRoleSettings) globalRoleSettingsJPA.getSingleResult(); + + if (globalRoleSettings == null) { + // this should not happen + String msg = "NO GlobalSetttings for " + XacmlAdminAuthorization.Role.ROLE_SUPERADMIN.toString(); + if (logger.isErrorEnabled()) + logger.error(msg); + throw new IllegalAccessException(msg); + } + + if (!globalRoleSettings.getRole().equals(XacmlAdminAuthorization.Role.ROLE_SUPERADMIN.toString())) { + String msg = "NOT FOUND db data for " + XacmlAdminAuthorization.Role.ROLE_SUPERADMIN.toString(); + if (logger.isErrorEnabled()) + logger.error(msg); + throw new IllegalAccessException(msg); + } + + return globalRoleSettings.isLockdown(); + } + + + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/util/JsonMessage.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/util/JsonMessage.java new file mode 100644 index 000000000..3e9351044 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/util/JsonMessage.java @@ -0,0 +1,67 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.util; + +public class JsonMessage { + + private String data; + private String data2; + private String data3; + public JsonMessage(String data) { + super(); + this.data = data; + } + public JsonMessage(String data,String data2) { + super(); + this.data = data; + this.data2 = data2; + } + + public JsonMessage(String data,String data2,String data3) { + super(); + this.data = data; + this.data2 = data2; + this.data3 = data3; + } + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } + public String getData2() { + return data2; + } + public void setData2(String data2) { + this.data2 = data2; + } + public String getData3() { + return data3; + } + public void setData3(String data3) { + this.data3 = data3; + } + + +} + diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/util/PolicyContainer.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/util/PolicyContainer.java new file mode 100644 index 000000000..3741dbda9 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/util/PolicyContainer.java @@ -0,0 +1,121 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.util; + +import java.io.Serializable; +import java.util.Collection; +import java.util.List; + + +public interface PolicyContainer extends Serializable{ + + public Collection getContainerPropertyIds(); + + public Collection getItemIds(); + + public Class getType(Object propertyId); + + public int size(); + + public boolean containsId(Object itemId); + + public Object addItem() throws UnsupportedOperationException; + + public boolean removeItem(Object itemId) + throws UnsupportedOperationException; + + public boolean addContainerProperty(Object propertyId, Class type, + Object defaultValue) throws UnsupportedOperationException; + + public boolean removeContainerProperty(Object propertyId) + throws UnsupportedOperationException; + + public boolean removeAllItems() throws UnsupportedOperationException; + + public interface Ordered extends PolicyContainer { + + public Object nextItemId(Object itemId); + + public Object prevItemId(Object itemId); + + public Object firstItemId(); + + public Object lastItemId(); + + public boolean isFirstId(Object itemId); + + public boolean isLastId(Object itemId); + + public Object addItemAfter(Object previousItemId) + throws UnsupportedOperationException; + + } + + + public interface Indexed extends Ordered { + + public int indexOfId(Object itemId); + + public Object getIdByIndex(int index); + + public List getItemIds(int startIndex, int numberOfItems); + + public Object addItemAt(int index) throws UnsupportedOperationException; + + public interface ItemAddEvent extends ItemSetChangeEvent { + + public Object getFirstItemId(); + + public int getFirstIndex(); + + public int getAddedItemsCount(); + } + + + public interface ItemRemoveEvent extends ItemSetChangeEvent { + + public Object getFirstItemId(); + + public int getFirstIndex(); + + public int getRemovedItemsCount(); + } + } + + public interface ItemSetChangeEvent extends Serializable { + + public PolicyContainer getContainer(); + } + + public interface ItemSetChangeListener extends Serializable { + + public void containerItemSetChange(PolicyContainer.ItemSetChangeEvent event); + } + + public interface ItemSetChangeNotifier extends Serializable { + + public void addItemSetChangeListener( + PolicyContainer.ItemSetChangeListener listener); + + public void removeItemSetChangeListener( + PolicyContainer.ItemSetChangeListener listener); + } +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/util/PolicyItemSetChangeNotifier.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/util/PolicyItemSetChangeNotifier.java new file mode 100644 index 000000000..da9278435 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/util/PolicyItemSetChangeNotifier.java @@ -0,0 +1,96 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.util; + + +import java.io.Serializable; +import java.util.Collection; +import java.util.EventObject; +import java.util.LinkedList; + +import org.openecomp.policy.pap.xacml.rest.util.PolicyContainer.ItemSetChangeEvent; +import org.openecomp.policy.pap.xacml.rest.util.PolicyContainer.ItemSetChangeListener; + + + + +public class PolicyItemSetChangeNotifier implements PolicyContainer.ItemSetChangeNotifier { + private static final long serialVersionUID = 1L; + private Collection itemSetChangeListeners = null; + private PolicyContainer container = null; + + public PolicyItemSetChangeNotifier() { + } + + protected void setContainer(PolicyContainer c) { + this.container = c; + } + + @Override + public void addItemSetChangeListener(ItemSetChangeListener listener) { + if (getItemSetChangeListeners() == null) { + setItemSetChangeListeners(new LinkedList()); + } + getItemSetChangeListeners().add(listener); } + + @Override + public void removeItemSetChangeListener(ItemSetChangeListener listener) { + if (getItemSetChangeListeners() != null) { + getItemSetChangeListeners().remove(listener); + } + } + + protected static class BaseItemSetChangeEvent extends EventObject implements + PolicyContainer.ItemSetChangeEvent, Serializable { + private static final long serialVersionUID = 1L; + + protected BaseItemSetChangeEvent(PolicyContainer source) { + super(source); + } + + @Override + public PolicyContainer getContainer() { + return (PolicyContainer) getSource(); + } + } + + protected void setItemSetChangeListeners( + Collection itemSetChangeListeners) { + this.itemSetChangeListeners = itemSetChangeListeners; + } + protected Collection getItemSetChangeListeners() { + return itemSetChangeListeners; + } + + protected void fireItemSetChange() { + fireItemSetChange(new BaseItemSetChangeEvent(this.container)); + } + + protected void fireItemSetChange(ItemSetChangeEvent event) { + if (getItemSetChangeListeners() != null) { + final Object[] l = getItemSetChangeListeners().toArray(); + for (int i = 0; i < l.length; i++) { + ((PolicyContainer.ItemSetChangeListener) l[i]) + .containerItemSetChange(event); + } + } + } +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/restAuth/AuthenticationService.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/restAuth/AuthenticationService.java new file mode 100644 index 000000000..003585b71 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/restAuth/AuthenticationService.java @@ -0,0 +1,74 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.restAuth; + +import java.util.Base64; +import java.util.StringTokenizer; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openecomp.policy.rest.XACMLRestProperties; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; +import com.att.research.xacml.util.XACMLProperties; + +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.eelf.PolicyLogger; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +public class AuthenticationService { + private String papID = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_USERID); + private String papPass = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_PASS); + private static final Logger logger = FlexLogger.getLogger(AuthenticationService.class); + + public boolean authenticate(String authCredentials) { + + if (null == authCredentials) + return false; + // header value format will be "Basic encodedstring" for Basic authentication. + final String encodedUserPassword = authCredentials.replaceFirst("Basic" + " ", ""); + String usernameAndPassword = null; + try { + byte[] decodedBytes = Base64.getDecoder().decode(encodedUserPassword); + usernameAndPassword = new String(decodedBytes, "UTF-8"); + } catch (Exception e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e); + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "AuthenticationService", "Exception decoding username and password"); + return false; + } + try { + final StringTokenizer tokenizer = new StringTokenizer(usernameAndPassword, ":"); + final String username = tokenizer.nextToken(); + final String password = tokenizer.nextToken(); + + boolean authenticationStatus = papID.equals(username) && papPass.equals(password); + return authenticationStatus; + } catch (Exception e){ + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e); + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "AuthenticationService", "Exception authenticating user"); + return false; + } + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/restAuth/CheckPDP.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/restAuth/CheckPDP.java new file mode 100644 index 000000000..ce35a7089 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/restAuth/CheckPDP.java @@ -0,0 +1,203 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.restAuth; + +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.eelf.PolicyLogger; + +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Base64; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Properties; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openecomp.policy.pap.xacml.rest.XACMLPapServlet; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +public class CheckPDP { + + private static Path pdpPath = null; + private static Properties pdpProp = null; + private static Long oldModified = null; + private static Long newModified = null; + private static HashMap pdpMap = null; + private static final Logger logger = FlexLogger.getLogger(CheckPDP.class); + + public static boolean validateID(String id) { + // ReadFile + try { + readFile(); + } catch (Exception e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e); + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "CheckPDP", "Exception reading file"); + return false; + } + // Check ID + if (pdpMap.containsKey(id)) { + return true; + } + return false; + } + + private static void readFile() throws Exception { + String pdpFile = XACMLPapServlet.getPDPFile(); + if (pdpFile == null) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "PDP File name not Valid : " + pdpFile); + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + "PDP File name is undefined"); + throw new Exception(XACMLErrorConstants.ERROR_SYSTEM_ERROR +"PDP File name not Valid : " + pdpFile); + } + if (pdpPath == null) { + pdpPath = Paths.get(pdpFile); + if (Files.notExists(pdpPath)) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "File doesn't exist in the specified Path : " + pdpPath.toString()); + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + "File doesn't exist in the specified Path"); + throw new Exception(XACMLErrorConstants.ERROR_SYSTEM_ERROR +"File doesn't exist in the specified Path : "+ pdpPath.toString()); + } + if (pdpPath.toString().endsWith(".properties")) { + readProps(); + } else { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Not a .properties file " + pdpFile); + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + "Not a .properties file"); + throw new Exception(XACMLErrorConstants.ERROR_SYSTEM_ERROR +"Not a .properties file"); + } + } + // Check if File is updated recently + else { + newModified = pdpPath.toFile().lastModified(); + if (newModified != oldModified) { + // File has been updated. + readProps(); + } + } + } + + private static void readProps() throws Exception { + InputStream in; + pdpProp = new Properties(); + try { + in = new FileInputStream(pdpPath.toFile()); + oldModified = pdpPath.toFile().lastModified(); + pdpProp.load(in); + } catch (IOException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e); + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "CheckPDP", "Cannot load the Properties file"); + throw new Exception("Cannot Load the Properties file", e); + } + // Read the Properties and Load the PDPs and encoding. + pdpMap = new HashMap(); + // Check the Keys for PDP_URLs + Collection unsorted = pdpProp.keySet(); + List sorted = new ArrayList(unsorted); + Collections.sort(sorted); + for (String propKey : sorted) { + if (propKey.startsWith("PDP_URL")) { + String check_val = pdpProp.getProperty(propKey); + if (check_val == null) { + throw new Exception("Properties file doesn't have the PDP_URL parameter"); + } + if (check_val.contains(";")) { + List pdp_default = new ArrayList(Arrays.asList(check_val.split("\\s*;\\s*"))); + int pdpCount = 0; + while (pdpCount < pdp_default.size()) { + String pdpVal = pdp_default.get(pdpCount); + readPDPParam(pdpVal); + pdpCount++; + } + } else { + readPDPParam(check_val); + } + } + } + if (pdpMap == null || pdpMap.isEmpty()) { + logger.debug(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Cannot Proceed without PDP_URLs"); + throw new Exception(XACMLErrorConstants.ERROR_SYSTEM_ERROR +"Cannot Proceed without PDP_URLs"); + } + } + + private static void readPDPParam(String pdpVal) throws Exception{ + if(pdpVal.contains(",")){ + List pdpValues = new ArrayList(Arrays.asList(pdpVal.split("\\s*,\\s*"))); + if(pdpValues.size()==3){ + // 1:2 will be UserID:Password + String userID = pdpValues.get(1); + String pass = pdpValues.get(2); + Base64.Encoder encoder = Base64.getEncoder(); + // 0 - PDPURL + pdpMap.put(pdpValues.get(0), encoder.encodeToString((userID+":"+pass).getBytes(StandardCharsets.UTF_8))); + }else{ + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_PERMISSIONS + "No Credentials to send Request: " + pdpValues); + PolicyLogger.error(MessageCodes.ERROR_PERMISSIONS + "No Credentials to send Request"); + throw new Exception(XACMLErrorConstants.ERROR_PERMISSIONS + "No enough Credentials to send Request. " + pdpValues); + } + }else{ + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_PERMISSIONS + "No Credentials to send Request: " + pdpVal); + PolicyLogger.error(MessageCodes.ERROR_PERMISSIONS + "No Credentials to send Request: " + pdpVal); + throw new Exception(XACMLErrorConstants.ERROR_PERMISSIONS +"No enough Credentials to send Request."); + } + } + + public static String getEncoding(String pdpID){ + try { + readFile(); + } catch (Exception e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e); + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "CheckPDP", "Exeption reading Properties file"); + } + String encoding = null; + if(pdpMap!=null && (!pdpMap.isEmpty())){ + try{ + encoding = pdpMap.get(pdpID); + } catch(Exception e){ + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e); + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "CheckPDP", "Exception encoding"); + } + return encoding; + }else{ + return null; + } + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/restAuth/PAPAuthenticationFilter.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/restAuth/PAPAuthenticationFilter.java new file mode 100644 index 000000000..817629420 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/restAuth/PAPAuthenticationFilter.java @@ -0,0 +1,130 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.restAuth; + +import java.io.IOException; + +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.annotation.WebFilter; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openecomp.policy.pap.xacml.rest.XACMLPapServlet; + +/** + * Servlet Filter implementation class PAPAuthenticationFilter + */ +@WebFilter("/*") +public class PAPAuthenticationFilter implements Filter { + + private static final Log logger = LogFactory.getLog(PAPAuthenticationFilter.class); + public static final String AUTHENTICATION_HEADER = "Authorization"; + + @Override + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain filter) throws IOException, ServletException { + + + if (request instanceof HttpServletRequest) { + HttpServletRequest httpServletRequest = (HttpServletRequest) request; + + String authCredentials = null; + String url = httpServletRequest.getRequestURI(); + + logger.info("Request URI: " + url); + System.out.println("Request URI: " + url); + + //getting authentication credentials + if(url.contains("@Auth@")){ + int authIndex = url.lastIndexOf("@"); + int endAuthIndex = url.indexOf("/ecomp"); + authCredentials = "Basic " + url.substring(authIndex+1, endAuthIndex); + + //parse the url for /pap/ecomp/ + String url1 = url.substring(0, 4); + String url2 = url.substring(endAuthIndex, url.length()); + url = url1 + url2; + + } else { + authCredentials = httpServletRequest.getHeader(AUTHENTICATION_HEADER); + } + + // Check Authentication credentials + AuthenticationService authenticationService = new AuthenticationService(); + boolean authenticationStatus = authenticationService.authenticate(authCredentials); + + if (authenticationStatus) { + //indicates the request comes from Traditional Admin Console or PolicyEngineAPI + if (url.equals("/pap/")){ + logger.info("Request comes from Traditional Admin Console or PolicyEngineAPI"); + + //forward request to the XACMLPAPServlet if authenticated + request.getRequestDispatcher("/pap/pap/").forward(request, response); + + }else if (url.startsWith("/pap/ecomp/")){ + + //indicates the request comes from the ECOMP Portal ecomp-sdk-app + if(response instanceof HttpServletResponse) { + HttpServletResponse alteredResponse = ((HttpServletResponse)response); + addCorsHeader(alteredResponse); + logger.info("Request comes from Ecomp Portal"); + //Spring dispatcher servlet is at the end of the filter chain at /pap/ecomp/ path + System.out.println("New Request URI: " + url); + //request.getRequestDispatcher(url).forward(request, alteredResponse); + filter.doFilter(request, response); + } + + } + + } else { + if (response instanceof HttpServletResponse) { + HttpServletResponse httpServletResponse = (HttpServletResponse) response; + httpServletResponse.setStatus(HttpServletResponse.SC_UNAUTHORIZED); + } + } + + } + } + + //method to add CorsHeaders for ecomp portal rest call + private void addCorsHeader(HttpServletResponse response) { + logger.info("Adding Cors Response Headers!!!"); + response.addHeader("Access-Control-Allow-Origin", "*"); + response.addHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE, HEAD"); + response.addHeader("Access-Control-Allow-Headers", "X-PINGOTHER, Origin, X-Requested-With, Content-Type, Accept"); + response.addHeader("Access-Control-Max-Age", "1728000"); + } + + @Override + public void destroy() { + } + + @Override + public void init(FilterConfig arg0) throws ServletException { + } +} diff --git a/ECOMP-PAP-REST/src/main/resources/META-INF/drop.ddl b/ECOMP-PAP-REST/src/main/resources/META-INF/drop.ddl new file mode 100644 index 000000000..f7138ad52 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/resources/META-INF/drop.ddl @@ -0,0 +1,7 @@ +DROP TABLE IF EXISTS ConfigurationDataEntity +DROP TABLE IF EXISTS PolicyEntity +DROP TABLE IF EXISTS PolicyDBDaoEntity +DROP TABLE IF EXISTS ActionBodyEntity +DROP SEQUENCE IF EXISTS seqPolicy +DROP SEQUENCE IF EXISTS seqConfig +DROP SEQUENCE IF EXISTS seqActBody diff --git a/ECOMP-PAP-REST/src/main/resources/META-INF/persistence.xml b/ECOMP-PAP-REST/src/main/resources/META-INF/persistence.xml new file mode 100644 index 000000000..1d7692a3d --- /dev/null +++ b/ECOMP-PAP-REST/src/main/resources/META-INF/persistence.xml @@ -0,0 +1,201 @@ + + + + + org.openecomp.policy.rest.jpa.PolicyEntity + org.openecomp.policy.rest.jpa.ConfigurationDataEntity + org.openecomp.policy.rest.jpa.PolicyDBDaoEntity + org.openecomp.policy.rest.jpa.GroupEntity + org.openecomp.policy.rest.jpa.PdpEntity + org.openecomp.policy.rest.jpa.ActionBodyEntity + org.openecomp.policy.rest.jpa.DatabaseLockEntity + org.openecomp.policy.rest.jpa.PolicyVersion + org.openecomp.policy.rest.jpa.PolicyScore + org.openecomp.policy.rest.jpa.FunctionDefinition + org.openecomp.policy.rest.jpa.Attribute + org.openecomp.policy.rest.jpa.Category + org.openecomp.policy.rest.jpa.ConstraintType + org.openecomp.policy.rest.jpa.ConstraintValue + org.openecomp.policy.rest.jpa.Datatype + org.openecomp.policy.rest.jpa.FunctionArgument + org.openecomp.policy.rest.jpa.UserInfo + org.openecomp.policy.rest.jpa.ActionPolicyDict + org.openecomp.policy.rest.jpa.DecisionSettings + org.openecomp.policy.rest.jpa.MicroServiceModels + org.openecomp.policy.rest.jpa.BRMSParamTemplate + org.openecomp.policy.rest.jpa.PolicyEditorScopes + + org.openecomp.policy.jpa.BackUpMonitorEntity + + org.openecomp.policy.common.im.jpa.StateManagementEntity + org.openecomp.policy.common.im.jpa.ForwardProgressEntity + org.openecomp.policy.common.im.jpa.ResourceRegistrationEntity + + org.openecomp.policy.common.ia.jpa.IntegrityAuditEntity + false + NONE + + + + + + + + + + + + + + + org.openecomp.policy.jpa.BackUpMonitorEntity + + org.openecomp.policy.common.im.jpa.StateManagementEntity + org.openecomp.policy.common.im.jpa.ForwardProgressEntity + org.openecomp.policy.common.im.jpa.ResourceRegistrationEntity + + org.openecomp.policy.common.ia.jpa.IntegrityAuditEntity + true + NONE + + + + + + org.eclipse.persistence.jpa.PersistenceProvider + org.openecomp.policy.rest.jpa.PolicyEntity + org.openecomp.policy.rest.jpa.ConfigurationDataEntity + org.openecomp.policy.rest.jpa.PolicyDBDaoEntity + org.openecomp.policy.rest.jpa.GroupEntity + org.openecomp.policy.rest.jpa.PdpEntity + org.openecomp.policy.rest.jpa.ActionBodyEntity + org.openecomp.policy.rest.jpa.DatabaseLockEntity + org.openecomp.policy.rest.jpa.PolicyVersion + org.openecomp.policy.rest.jpa.PolicyScore + org.openecomp.policy.rest.jpa.FunctionDefinition + org.openecomp.policy.rest.jpa.Attribute + org.openecomp.policy.rest.jpa.Category + org.openecomp.policy.rest.jpa.ConstraintType + org.openecomp.policy.rest.jpa.ConstraintValue + org.openecomp.policy.rest.jpa.Datatype + org.openecomp.policy.rest.jpa.FunctionArgument + org.openecomp.policy.rest.jpa.UserInfo + org.openecomp.policy.rest.jpa.ActionPolicyDict + org.openecomp.policy.rest.jpa.DecisionSettings + org.openecomp.policy.rest.jpa.MicroServiceModels + + org.openecomp.policy.rest.jpa.ActionList + org.openecomp.policy.rest.jpa.AddressGroup + org.openecomp.policy.rest.jpa.AttributeAssignment + org.openecomp.policy.rest.jpa.BRMSParamTemplate + org.openecomp.policy.rest.jpa.ClosedLoopD2Services + org.openecomp.policy.rest.jpa.ClosedLoopSite + org.openecomp.policy.rest.jpa.DCAEUsers + org.openecomp.policy.rest.jpa.DCAEuuid + org.openecomp.policy.rest.jpa.DescriptiveScope + org.openecomp.policy.rest.jpa.EcompName + org.openecomp.policy.rest.jpa.EnforcingType + org.openecomp.policy.rest.jpa.GlobalRoleSettings + org.openecomp.policy.rest.jpa.GroupPolicyScopeList + org.openecomp.policy.rest.jpa.GroupServiceList + org.openecomp.policy.rest.jpa.MicroServiceConfigName + org.openecomp.policy.rest.jpa.MicroServiceLocation + org.openecomp.policy.rest.jpa.Obadvice + org.openecomp.policy.rest.jpa.ObadviceExpression + org.openecomp.policy.rest.jpa.PEPOptions + org.openecomp.policy.rest.jpa.PIPConfigParam + org.openecomp.policy.rest.jpa.PIPConfiguration + org.openecomp.policy.rest.jpa.PIPResolver + org.openecomp.policy.rest.jpa.PIPResolverParam + org.openecomp.policy.rest.jpa.PIPType + org.openecomp.policy.rest.jpa.PolicyAlgorithms + org.openecomp.policy.rest.jpa.PolicyManagement + org.openecomp.policy.rest.jpa.PolicyScopeService + org.openecomp.policy.rest.jpa.PolicyScopeType + org.openecomp.policy.rest.jpa.PolicyScopeResource + org.openecomp.policy.rest.jpa.PolicyScopeClosedLoop + org.openecomp.policy.rest.jpa.PortList + org.openecomp.policy.rest.jpa.PREFIXLIST + org.openecomp.policy.rest.jpa.ProtocolList + org.openecomp.policy.rest.jpa.RemoteCatalogValues + org.openecomp.policy.rest.jpa.PolicyRoles + org.openecomp.policy.rest.jpa.RuleAlgorithms + org.openecomp.policy.rest.jpa.SecurityZone + org.openecomp.policy.rest.jpa.ServiceList + org.openecomp.policy.rest.jpa.SystemLogDB + org.openecomp.policy.rest.jpa.TermList + org.openecomp.policy.rest.jpa.VarbindDictionary + org.openecomp.policy.rest.jpa.VMType + org.openecomp.policy.rest.jpa.VNFType + org.openecomp.policy.rest.jpa.VSCLAction + org.openecomp.policy.rest.jpa.Zone + + org.openecomp.policy.jpa.BackUpMonitorEntity + + org.openecomp.policy.common.im.jpa.StateManagementEntity + org.openecomp.policy.common.im.jpa.ForwardProgressEntity + org.openecomp.policy.common.im.jpa.ResourceRegistrationEntity + + org.openecomp.policy.common.ia.jpa.IntegrityAuditEntity + + false + NONE + + + + + + + + + + + + + + + diff --git a/ECOMP-PAP-REST/src/main/resources/log4j.properties b/ECOMP-PAP-REST/src/main/resources/log4j.properties new file mode 100644 index 000000000..80f85e945 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/resources/log4j.properties @@ -0,0 +1,71 @@ +### +# ============LICENSE_START======================================================= +# ECOMP-PAP-REST +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +# +# Use this properties for deployments. +# +# +# Set root logger level to DEBUG and its only appender to FILE. +#log4j.rootLogger=DEBUG, FILE, CONSOLE +log4j.rootLogger=INFO, FILE + +# FILE appender +log4j.appender.FILE=org.apache.log4j.DailyRollingFileAppender +log4j.appender.FILE.File=${catalina.base}/logs/pap-rest.log +log4j.appender.FILE.ImmediateFlush=true +log4j.appender.FILE.Threshold=debug +log4j.appender.FILE.append=true +log4j.appender.FILE.DatePattern='.'yyyy-MM-dd +log4j.appender.FILE.layout=org.apache.log4j.PatternLayout +log4j.appender.FILE.layout.ConversionPattern=%d{yyyy-MM-dd'T'HH:mm:ss}{GMT+0}+00:00|%X{requestId}|%X{serviceInstanceId}|%t|%X{serverName}|%X{serviceName}|%X{instanceUuid}|%p|%X{severity}|%X{serverIpAddress}|%X{server}|%X{clientIpAddress}|%l||%m%n + +# for Developments and Debugging +#log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender +#log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout +#log4j.appender.CONSOLE.layout.ConversionPattern=%d{yyyy_MM_dd_HH_mm_ss_SSS} [%t] %-5p %l- %m%n + +# +# This is specifically for Xacml request/response logging +# +log4j.logger.xacml.request=INFO, REQUEST_LOG + +log4j.appender.REQUEST_LOG=org.apache.log4j.DailyRollingFileAppender +log4j.appender.REQUEST_LOG.File=${catalina.base}/logs/pap-rest-reqres.log +log4j.appender.REQUEST_LOG.ImmediateFlush=true +log4j.appender.REQUEST_LOG.Threshold=debug +log4j.appender.REQUEST_LOG.append=true +log4j.appender.REQUEST_LOG.DatePattern='.'yyyy-MM-dd + +log4j.appender.REQUEST_LOG.layout=org.apache.log4j.PatternLayout +log4j.appender.REQUEST_LOG.layout.ConversionPattern=%d{yyyy_MM_dd_HH_mm_ss_SSS} %m%n + +# +# audit (transaction) logging +# +log4j.logger.auditLogger=INFO,AUDIT_LOG +log4j.additivity.auditLogger=false + +log4j.appender.AUDIT_LOG=org.apache.log4j.DailyRollingFileAppender +log4j.appender.AUDIT_LOG.File=${catalina.base}/logs/audit.log +log4j.appender.AUDIT_LOG.Append=true +log4j.appender.AUDIT_LOG.DatePattern='.'yyyy-MM-dd +log4j.appender.AUDIT_LOG.threshold=INFO +log4j.appender.AUDIT_LOG.layout=org.apache.log4j.EnhancedPatternLayout +log4j.appender.AUDIT_LOG.layout.ConversionPattern=%d{yyyy-MM-dd'T'HH:mm:ss}{GMT+0}+00:00|%X{requestId}|%X{serviceInstanceId}|%t|%X{serverName}|%X{serviceName}|%X{instanceUuid}|%p|%X{severity}|%X{serverIpAddress}|%X{server}|%X{clientIpAddress}|%X{className}|%X{timer}|%m%n diff --git a/ECOMP-PAP-REST/src/main/resources/logback.xml b/ECOMP-PAP-REST/src/main/resources/logback.xml new file mode 100644 index 000000000..7c328c573 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/resources/logback.xml @@ -0,0 +1,253 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --> + + + + + + + + + + + + + + + + + + + + ${defaultPattern} + + + + + + + + + + + + + ${logDirectory}/${auditLogName}.log + + ${logDirectory}/${auditLogName}.%i.log.zip + + 1 + 9 + + + 5MB + + + ${defaultAuditPattern} + + + + + 256 + + + + + + + + ${logDirectory}/${metricsLogName}.log + + ${logDirectory}/${metricsLogName}.%i.log.zip + + 1 + 9 + + + 5MB + + + + ${defaultMetricPattern} + + + + + 256 + + + + + + + + ${logDirectory}/${errorLogName}.log + + ${logDirectory}/${errorLogName}.%i.log.zip + + 1 + 9 + + + ERROR + + + 5MB + + + ${defaultErrorPattern} + + + + + 256 + + + + + + + ${debugLogDirectory}/${debugLogName}.log + + ${debugLogDirectory}/${debugLogName}.%i.log.zip + + 1 + 9 + + + INFO + + + 5MB + + + ${debugLoggerPattern} + + + + + 256 + + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ECOMP-PAP-REST/src/main/resources/spring.xml b/ECOMP-PAP-REST/src/main/resources/spring.xml new file mode 100644 index 000000000..20414fabe --- /dev/null +++ b/ECOMP-PAP-REST/src/main/resources/spring.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + classpath:hibernate.cfg.xml + + + + org.hibernate.dialect.MySQLDialect + thread + false + + + + diff --git a/ECOMP-PAP-REST/src/test/java/org/openecomp/policy/pap/ia/DbAuditCompareEntriesTest.java b/ECOMP-PAP-REST/src/test/java/org/openecomp/policy/pap/ia/DbAuditCompareEntriesTest.java new file mode 100644 index 000000000..c5fa37925 --- /dev/null +++ b/ECOMP-PAP-REST/src/test/java/org/openecomp/policy/pap/ia/DbAuditCompareEntriesTest.java @@ -0,0 +1,519 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.ia; + +import static org.junit.Assert.*; + +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Properties; + +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.EntityTransaction; +import javax.persistence.Persistence; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.After; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import org.openecomp.policy.jpa.BackUpMonitorEntity; +import org.openecomp.policy.rest.jpa.ActionBodyEntity; +import org.openecomp.policy.rest.jpa.ActionList; +import org.openecomp.policy.rest.jpa.ActionPolicyDict; +import org.openecomp.policy.rest.jpa.AddressGroup; +import org.openecomp.policy.rest.jpa.Attribute; +import org.openecomp.policy.rest.jpa.AttributeAssignment; +import org.openecomp.policy.rest.jpa.BRMSParamTemplate; +import org.openecomp.policy.rest.jpa.Category; +import org.openecomp.policy.rest.jpa.ClosedLoopD2Services; +import org.openecomp.policy.rest.jpa.ClosedLoopSite; +import org.openecomp.policy.rest.jpa.ConfigurationDataEntity; +import org.openecomp.policy.rest.jpa.ConstraintType; +import org.openecomp.policy.rest.jpa.ConstraintValue; +import org.openecomp.policy.rest.jpa.DCAEUsers; +import org.openecomp.policy.rest.jpa.DCAEuuid; +import org.openecomp.policy.rest.jpa.DatabaseLockEntity; +import org.openecomp.policy.rest.jpa.Datatype; +import org.openecomp.policy.rest.jpa.DecisionSettings; +import org.openecomp.policy.rest.jpa.DescriptiveScope; +import org.openecomp.policy.rest.jpa.EcompName; +import org.openecomp.policy.rest.jpa.EnforcingType; +import org.openecomp.policy.rest.jpa.FunctionArgument; +import org.openecomp.policy.rest.jpa.FunctionDefinition; +import org.openecomp.policy.rest.jpa.GlobalRoleSettings; +import org.openecomp.policy.rest.jpa.GroupEntity; +import org.openecomp.policy.rest.jpa.GroupPolicyScopeList; +import org.openecomp.policy.rest.jpa.GroupServiceList; +import org.openecomp.policy.rest.jpa.MicroServiceConfigName; +import org.openecomp.policy.rest.jpa.MicroServiceLocation; +import org.openecomp.policy.rest.jpa.MicroServiceModels; +import org.openecomp.policy.rest.jpa.Obadvice; +import org.openecomp.policy.rest.jpa.ObadviceExpression; +import org.openecomp.policy.rest.jpa.PEPOptions; +import org.openecomp.policy.rest.jpa.PIPConfigParam; +import org.openecomp.policy.rest.jpa.PIPConfiguration; +import org.openecomp.policy.rest.jpa.PIPResolver; +import org.openecomp.policy.rest.jpa.PIPResolverParam; +import org.openecomp.policy.rest.jpa.PIPType; +import org.openecomp.policy.rest.jpa.PREFIXLIST; +import org.openecomp.policy.rest.jpa.PdpEntity; +import org.openecomp.policy.rest.jpa.PolicyAlgorithms; +import org.openecomp.policy.rest.jpa.PolicyDBDaoEntity; +import org.openecomp.policy.rest.jpa.PolicyEntity; +import org.openecomp.policy.rest.jpa.PolicyManagement; +import org.openecomp.policy.rest.jpa.PolicyRoles; +import org.openecomp.policy.rest.jpa.PolicyScopeClosedLoop; +import org.openecomp.policy.rest.jpa.PolicyScopeResource; +import org.openecomp.policy.rest.jpa.PolicyScopeService; +import org.openecomp.policy.rest.jpa.PolicyScopeType; +import org.openecomp.policy.rest.jpa.PolicyScore; +import org.openecomp.policy.rest.jpa.PolicyVersion; +import org.openecomp.policy.rest.jpa.PortList; +import org.openecomp.policy.rest.jpa.ProtocolList; +import org.openecomp.policy.rest.jpa.RemoteCatalogValues; +import org.openecomp.policy.rest.jpa.RuleAlgorithms; +import org.openecomp.policy.rest.jpa.SecurityZone; +import org.openecomp.policy.rest.jpa.ServiceList; +import org.openecomp.policy.rest.jpa.SystemLogDB; +import org.openecomp.policy.rest.jpa.TermList; +import org.openecomp.policy.rest.jpa.UserInfo; +import org.openecomp.policy.rest.jpa.VMType; +import org.openecomp.policy.rest.jpa.VNFType; +import org.openecomp.policy.rest.jpa.VSCLAction; +import org.openecomp.policy.rest.jpa.VarbindDictionary; +import org.openecomp.policy.rest.jpa.Zone; + +import org.openecomp.policy.common.ia.DbAudit; +import org.openecomp.policy.common.ia.DbDAO; +import org.openecomp.policy.common.ia.IntegrityAuditProperties; +import org.openecomp.policy.common.ia.jpa.IntegrityAuditEntity; +import org.openecomp.policy.common.im.jpa.ForwardProgressEntity; +import org.openecomp.policy.common.im.jpa.ResourceRegistrationEntity; +import org.openecomp.policy.common.im.jpa.StateManagementEntity; + +import org.apache.commons.lang3.SerializationUtils; + +@Ignore +public class DbAuditCompareEntriesTest { + + private static Log logger = LogFactory.getLog(DbAuditCompareEntriesTest.class); + private DbDAO dbDAO; + private String persistenceUnit; + private Properties properties; + private String resourceName; + private String dbDriver; + private String dbUrl; + private String dbUser; + private String dbPwd; + private String siteName; + private String nodeType; + + @Before + public void setUp() throws Exception { + logger.info("setUp: Entering"); + + properties = new Properties(); + properties.put(IntegrityAuditProperties.DB_DRIVER, IntegrityAuditProperties.DEFAULT_DB_DRIVER); + properties.put(IntegrityAuditProperties.DB_URL, "jdbc:h2:file:./sql/xacmlTest"); + properties.put(IntegrityAuditProperties.DB_USER, IntegrityAuditProperties.DEFAULT_DB_USER); + properties.put(IntegrityAuditProperties.DB_PWD, IntegrityAuditProperties.DEFAULT_DB_PWD); + properties.put(IntegrityAuditProperties.SITE_NAME, "SiteA"); + properties.put(IntegrityAuditProperties.NODE_TYPE, "pap"); + + dbDriver = IntegrityAuditProperties.DEFAULT_DB_DRIVER; + dbUrl = "jdbc:h2:file:./sql/xacmlTest"; + dbUser = IntegrityAuditProperties.DEFAULT_DB_USER; + dbPwd = IntegrityAuditProperties.DEFAULT_DB_PWD; + siteName = "SiteA"; + nodeType = "pap"; + persistenceUnit = "testPapPU"; + resourceName = "siteA.pap1"; + + //Clean the iaTest DB table for IntegrityAuditEntity entries + cleanDb(persistenceUnit, properties); + + logger.info("setUp: Exiting"); + } + + @After + public void tearDown() throws Exception { + logger.info("tearDown: Entering"); + //nothing to do + logger.info("tearDown: Exiting"); + } + + public void cleanDb(String persistenceUnit, Properties properties){ + logger.debug("cleanDb: enter"); + + EntityManagerFactory emf = Persistence.createEntityManagerFactory(persistenceUnit, properties); + + EntityManager em = emf.createEntityManager(); + // Start a transaction + EntityTransaction et = em.getTransaction(); + + et.begin(); + + // Clean up the DB + em.createQuery("Delete from IntegrityAuditEntity").executeUpdate(); + + // commit transaction + et.commit(); + em.close(); + logger.debug("cleanDb: exit"); + } + + + /* + * Tests that a comparison between hashsets is successful if + * the entries match + */ + //@Ignore + @Test + public void runAllTests() throws Exception { + logger.info("runAllTests: Entering"); + + + testIntegrityAuditEntity(); + testBackupMonitorEntity(); + testStateManagementEntity(); + testForwardProgressEntity(); + testResourceRegistrationEntity(); + + //clean up the IntegrityAuditEntity table + cleanDb(persistenceUnit, properties); + + logger.info("runAllTests: Exit"); + } + + + public void testIntegrityAuditEntity() throws Exception { + logger.info("testIntegrityAuditEntity: Entering"); + + dbDAO = new DbDAO(resourceName, persistenceUnit, properties); + DbAudit dbAudit = new DbAudit(dbDAO); + + String className = null; + //There is only one entry IntegrityAuditEntity, but we will check anyway + HashSet classNameSet = dbDAO.getPersistenceClassNames(); + for(String c : classNameSet){ + if (c.equals("org.openecomp.policy.common.ia.IntegrityAuditEntity")){ + className = c; + } + } + String resourceName1 = resourceName; + String resourceName2 = resourceName; + + IntegrityAuditEntity entry1 = new IntegrityAuditEntity(); + IntegrityAuditEntity entry2 = new IntegrityAuditEntity(); + Date date = new Date(); + + /* + * Two entries with the same field values + */ + entry1.setDesignated(false); + entry1.setJdbcDriver(dbDriver); + entry1.setJdbcPassword(dbPwd); + entry1.setJdbcUrl(dbUrl); + entry1.setJdbcUser(dbUser); + entry1.setLastUpdated(date); + entry1.setNodeType(nodeType); + entry1.setPersistenceUnit(persistenceUnit); + entry1.setResourceName(resourceName1); + entry1.setSite(siteName); + + entry2 = SerializationUtils.clone(entry1); + + dbAudit.writeAuditDebugLog(className, resourceName1, resourceName2, entry1, entry2); + + HashMap myEntries = new HashMap(); + HashMap theirEntries = new HashMap(); + + myEntries.put("pdp1", entry1); + theirEntries.put("pdp1", entry2); + + HashSet result = dbAudit.compareEntries(myEntries, theirEntries); + + /* + * Assert that there are no mismatches returned + */ + assertTrue(result.isEmpty()); + + /* + * ************************************ + * Now test with a mis-matched entry + * ************************************ + */ + + /* + * Change the entry2 to different designated value + */ + entry2.setDesignated(true); + + myEntries = new HashMap(); + theirEntries = new HashMap(); + + myEntries.put("pdp1", entry1); + theirEntries.put("pdp1", entry2); + + result = dbAudit.compareEntries(myEntries, theirEntries); + + /* + * Assert that there was one mismatch + */ + assertEquals(1, result.size()); + logger.info("testIntegrityAuditEntity: Exit"); + } + + void testBackupMonitorEntity() throws Exception { + logger.info("testBackupMonitorEntity: Entering"); + + dbDAO = new DbDAO(resourceName, persistenceUnit, properties); + DbAudit dbAudit = new DbAudit(dbDAO); + + BackUpMonitorEntity entry1 = new BackUpMonitorEntity(); + BackUpMonitorEntity entry2 = new BackUpMonitorEntity(); + + // Two entries with the same field values + + + entry1.setFlag("flag1"); + entry1.setResoruceNodeName("node1"); + entry1.setResourceName("resourceName"); + entry1.setTimeStamp(new Date()); + + // Clone the first entry + entry2 = SerializationUtils.clone(entry1); + + HashMap myEntries = new HashMap(); + HashMap theirEntries = new HashMap(); + + myEntries.put("pdp1", entry1); + theirEntries.put("pdp1", entry2); + + HashSet result = dbAudit.compareEntries(myEntries, theirEntries); + + + // Assert that there are no mismatches returned + + assertTrue(result.isEmpty()); + + + /* ************************************ + * Now test with a mis-matched entry + * ************************************/ + + + + // Change a field on entry2 + + entry2.setFlag("flag2"); + + myEntries = new HashMap(); + theirEntries = new HashMap(); + + myEntries.put("pdp1", entry1); + theirEntries.put("pdp1", entry2); + + result = dbAudit.compareEntries(myEntries, theirEntries); + + + //Assert that there was one mismatch + + assertEquals(1, result.size()); + logger.info("testBackupMonitorEntity: Exit"); + } + + void testStateManagementEntity() throws Exception { + logger.info("testStateManagementEntity: Entering"); + + dbDAO = new DbDAO(resourceName, persistenceUnit, properties); + DbAudit dbAudit = new DbAudit(dbDAO); + + StateManagementEntity entry1 = new StateManagementEntity(); + StateManagementEntity entry2 = new StateManagementEntity(); + + // Two entries with the same field values + + entry1.setAdminState("locked"); + entry1.setAvailStatus("null"); + entry1.setModifiedDate(new Date()); + entry1.setOpState("enabled"); + entry1.setResourceName("myResource"); + entry1.setStandbyStatus("coldstandby"); + + // Clone the first entry + entry2 = SerializationUtils.clone(entry1); + + HashMap myEntries = new HashMap(); + HashMap theirEntries = new HashMap(); + + myEntries.put("pdp1", entry1); + theirEntries.put("pdp1", entry2); + + HashSet result = dbAudit.compareEntries(myEntries, theirEntries); + + + // Assert that there are no mismatches returned + + assertTrue(result.isEmpty()); + + + /* ************************************ + * Now test with a mis-matched entry + * ************************************/ + + + + // Change a field on entry2 + + entry2.setAdminState("unlocked"); + + myEntries = new HashMap(); + theirEntries = new HashMap(); + + myEntries.put("pdp1", entry1); + theirEntries.put("pdp1", entry2); + + result = dbAudit.compareEntries(myEntries, theirEntries); + + + //Assert that there was one mismatch + + assertEquals(1, result.size()); + logger.info("testStateManagementEntity: Exit"); + } + + void testForwardProgressEntity() throws Exception { + logger.info("testForwardProgressEntity: Entering"); + + dbDAO = new DbDAO(resourceName, persistenceUnit, properties); + DbAudit dbAudit = new DbAudit(dbDAO); + + ForwardProgressEntity entry1 = new ForwardProgressEntity(); + ForwardProgressEntity entry2 = new ForwardProgressEntity(); + + // Two entries with the same field values + + entry1.setFpcCount(123L); + entry1.setLastUpdated(new Date()); + entry1.setResourceName("myResource"); + + // Clone the first entry + entry2 = SerializationUtils.clone(entry1); + + HashMap myEntries = new HashMap(); + HashMap theirEntries = new HashMap(); + + myEntries.put("pdp1", entry1); + theirEntries.put("pdp1", entry2); + + HashSet result = dbAudit.compareEntries(myEntries, theirEntries); + + + // Assert that there are no mismatches returned + + assertTrue(result.isEmpty()); + + + /* ************************************ + * Now test with a mis-matched entry + * ************************************/ + + // Change a field on entry2 + + entry2.setFpcCount(321L); + + myEntries = new HashMap(); + theirEntries = new HashMap(); + + myEntries.put("pdp1", entry1); + theirEntries.put("pdp1", entry2); + + result = dbAudit.compareEntries(myEntries, theirEntries); + + + //Assert that there was one mismatch + + assertEquals(1, result.size()); + logger.info("testForwardProgressEntity: Exit"); + } + + void testResourceRegistrationEntity() throws Exception { + logger.info("testResourceRegistrationEntity: Entering"); + + dbDAO = new DbDAO(resourceName, persistenceUnit, properties); + DbAudit dbAudit = new DbAudit(dbDAO); + + ResourceRegistrationEntity entry1 = new ResourceRegistrationEntity(); + ResourceRegistrationEntity entry2 = new ResourceRegistrationEntity(); + + // Two entries with the same field values + + entry1.setNodeType("pap"); + entry1.setLastUpdated(new Date()); + entry1.setResourceName("myResource"); + entry1.setResourceUrl("http://nowhere.com"); + entry1.setSite("site_1"); + + // Clone the first entry + entry2 = SerializationUtils.clone(entry1); + + HashMap myEntries = new HashMap(); + HashMap theirEntries = new HashMap(); + + myEntries.put("pdp1", entry1); + theirEntries.put("pdp1", entry2); + + HashSet result = dbAudit.compareEntries(myEntries, theirEntries); + + + // Assert that there are no mismatches returned + + assertTrue(result.isEmpty()); + + + /* ************************************ + * Now test with a mis-matched entry + * ************************************/ + + // Change a field on entry2 + + entry2.setSite("site_1a"); + + myEntries = new HashMap(); + theirEntries = new HashMap(); + + myEntries.put("pdp1", entry1); + theirEntries.put("pdp1", entry2); + + result = dbAudit.compareEntries(myEntries, theirEntries); + + + //Assert that there was one mismatch + + assertEquals(1, result.size()); + logger.info("testResourceRegistrationEntity: Exit"); + } +} diff --git a/ECOMP-PAP-REST/src/test/java/org/openecomp/policy/pap/xacml/rest/XACMLPapServletTest.java b/ECOMP-PAP-REST/src/test/java/org/openecomp/policy/pap/xacml/rest/XACMLPapServletTest.java new file mode 100644 index 000000000..da11d72ce --- /dev/null +++ b/ECOMP-PAP-REST/src/test/java/org/openecomp/policy/pap/xacml/rest/XACMLPapServletTest.java @@ -0,0 +1,368 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Properties; + +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.EntityTransaction; +import javax.persistence.Persistence; +import javax.servlet.ServletConfig; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import junit.framework.TestCase; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.openecomp.policy.pap.xacml.rest.XACMLPapServlet; +import org.openecomp.policy.rest.XACMLRestProperties; +import org.springframework.mock.web.MockHttpServletResponse; +import org.springframework.mock.web.MockServletConfig; + +import org.openecomp.policy.common.ia.IntegrityAudit; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +public class XACMLPapServletTest extends TestCase{ + private static Logger logger = FlexLogger.getLogger(XACMLPapServletTest.class); + + private List headers = new ArrayList(); + + private HttpServletRequest httpServletRequest; + private HttpServletResponse httpServletResponse; + private ServletOutputStream mockOutput; + private ServletConfig servletConfig; + private XACMLPapServlet papServlet; + + + @Before + + public void setUp() throws IOException { + httpServletRequest = Mockito.mock(HttpServletRequest.class); + Mockito.when(httpServletRequest.getMethod()).thenReturn("POST"); + Mockito.when(httpServletRequest.getParameter("groupId")).thenReturn(null); + Mockito.when(httpServletRequest.getHeaderNames()).thenReturn(Collections.enumeration(headers)); + Mockito.when(httpServletRequest.getAttributeNames()).thenReturn(Collections.enumeration(headers)); + + + mockOutput = Mockito.mock(ServletOutputStream.class); + + //when(httpServletRequest.getPathInfo()).thenReturn("/lineup/world.xml"); + //HttpServletResponse httpResponse = new HttpServletResponse(); + httpServletResponse = Mockito.mock(MockHttpServletResponse.class); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(mockOutput); + + + //when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + servletConfig = Mockito.mock(MockServletConfig.class); + //Mockito.when(servletConfig.getInitParameterNames()).thenReturn(Collections.enumeration(headers)); + //servletConfig + Mockito.when(servletConfig.getInitParameterNames()).thenReturn(Collections.enumeration(headers)); + papServlet = new XACMLPapServlet(); + + Mockito.when(servletConfig.getInitParameter("XACML_PROPERTIES_NAME")).thenReturn("xacml.pap.test.properties"); + + System.setProperty("xacml.PAP.papEngineFactory", "org.openecomp.policy.xacml.std.pap.StdEngineFactory"); + System.setProperty("xacml.pap.pdps", "pdps"); + System.setProperty("xacml.rest.pap.url", "http://localhost:8070/pap/"); + System.setProperty("xacml.rest.pap.initiate.pdp", "false"); + System.setProperty("xacml.rest.pdp.idfile", "testpdp.properties"); + System.setProperty("xacml.rest.pep.idfile", "client.properties"); + System.setProperty("javax.persistence.jdbc.driver", "org.h2.Driver"); + System.setProperty("javax.persistence.jdbc.url", "jdbc:h2:file:./sql/xacmlTest"); + System.setProperty("javax.persistence.jdbc.user", "sa"); + System.setProperty("javax.persistence.jdbc.password", ""); + System.setProperty("xacml.rest.pap.jmx.url", "service:jmx:rmi:///jndi/rmi://localhost:9990/jmxrmi"); + System.setProperty("xacml.rest.pap.resource.name", "site_1.pap_1"); + System.setProperty("fp_monitor_interval", "30"); + System.setProperty("failed_counter_threshold", "3"); + System.setProperty("test_trans_interval", "10"); + System.setProperty("write_fpc_interval", "5"); + System.setProperty("com.sun.management.jmxremote.port", "9999"); + System.setProperty("dependency_groups", "site_1.logparser_1;site_1.adminconsole_1;site_1.elk_1"); + System.setProperty("site_name", "site_1"); + System.setProperty("node_type", "pap"); + } + + /* + * This method initializes and cleans the DB so the XACMLPapServlet will be able to instantiate an + * IntegrityAudit object which will use the DB. + */ + public void initializeDb(){ + logger.debug("initializeDb: enter"); + Properties cleanProperties = new Properties(); + cleanProperties.put(XACMLRestProperties.PROP_PAP_DB_DRIVER,"org.h2.Driver"); + cleanProperties.put(XACMLRestProperties.PROP_PAP_DB_URL, "jdbc:h2:file:./sql/xacmlTest"); + cleanProperties.put(XACMLRestProperties.PROP_PAP_DB_USER, "sa"); + cleanProperties.put(XACMLRestProperties.PROP_PAP_DB_PASSWORD, ""); + EntityManagerFactory emf = Persistence.createEntityManagerFactory("testPapPU", cleanProperties); + + EntityManager em = emf.createEntityManager(); + // Start a transaction + EntityTransaction et = em.getTransaction(); + + et.begin(); + + // Clean up the DB + em.createQuery("Delete from IntegrityAuditEntity").executeUpdate(); + + // commit transaction + et.commit(); + em.close(); + logger.debug("initializeDb: exit"); + } + + @Test + public void testInit() throws Exception{ + System.setProperty("integrity_audit_period_seconds", "0"); + initializeDb(); + try { + papServlet.init(servletConfig); + IntegrityAudit ia = papServlet.getIa(); + if(ia.isThreadInitialized()){ + assertTrue(true); + }else{ + fail(); + } + ia.stopAuditThread(); + // Allow time for the thread to stop + Thread.sleep(1000); + if(!ia.isThreadInitialized()){ + assertTrue(true); + }else{ + fail(); + } + } catch (Exception e) { + // TODO Auto-generated catch block + fail(); + } + } + +/* public void testDoGetPapTest(){ + try{ + Mockito.when(httpServletRequest.getRequestURI()).thenReturn("/pap/test"); + papServlet.init(servletConfig); + IntegrityAudit ia = papServlet.getIa(); + ia.stopAuditThread(); + papServlet.doGet(httpServletRequest, httpServletResponse); + logger.info(httpServletResponse.getStatus()); + + //Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK); + }catch (Exception e){ + logger.info("testDoGetPapTest failed with message: " + e.getMessage()); + fail(); + } + assertTrue(true); + }*/ + +/* + * Need to figure a way to get it to match any message string + * public void testDoGetPapTestFpcFailure(){ + try{ + Mockito.when(httpServletRequest.getRequestURI()).thenReturn("/pap/test"); + Mockito.when(httpServletRequest.getHeader("THIS-IS-A-TEST")).thenReturn("FPC"); + papServlet.init(servletConfig); + IntegrityAudit ia = papServlet.getIa(); + ia.stopAuditThread(); + papServlet.doGet(httpServletRequest, httpServletResponse); + Mockito.verify(httpServletResponse).sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, Mockito.anyString()); + }catch (Exception e){ + logger.info("testDoGetPapTestFpcFailure failed with message: " + e.getMessage()); + fail(); + } + assertTrue(true); + }*/ + + public void testDoGetLocal(){ + try{ + Mockito.when(httpServletRequest.getRemoteHost()).thenReturn("localhost"); + papServlet.init(servletConfig); + IntegrityAudit ia = papServlet.getIa(); + ia.stopAuditThread(); + papServlet.doGet(httpServletRequest, httpServletResponse); + + logger.info(httpServletResponse.getStatus()); + Mockito.verify(httpServletResponse).setHeader("content-type", "application/json"); + Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK); + }catch (Exception e){ + fail(); + } + + assertTrue(true); + } + + public void testDoGetNonLocal(){ + //return non-local host remote address, which is invalid + Mockito.when(httpServletRequest.getRemoteHost()).thenReturn("0.0.0.0"); + try{ + papServlet.init(servletConfig); + IntegrityAudit ia = papServlet.getIa(); + ia.stopAuditThread(); + papServlet.doGet(httpServletRequest, httpServletResponse); + logger.info(httpServletResponse.getStatus()); + String message = "Unknown PDP: from 0.0.0.0 us: null"; + + Mockito.verify(httpServletResponse).sendError(401, message); + + }catch (Exception e){ + fail(); + } + } + + public void testDoGetWithGroup() throws Exception{ + Mockito.when(httpServletRequest.getParameter("groupId")).thenReturn("default"); + //Mockito.when(httpServletRequest.getHeader("X-XACML-PDP-ID")).thenReturn("default"); + papServlet.init(servletConfig); + IntegrityAudit ia = papServlet.getIa(); + ia.stopAuditThread(); + papServlet.doGet(httpServletRequest, httpServletResponse); + Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK); + } + + public void testDoPostWithGroup(){ + Mockito.when(httpServletRequest.getParameter("groupId")).thenReturn("default"); + Mockito.when(httpServletRequest.getParameter("policyId")).thenReturn("default"); + try{ + papServlet.init(servletConfig); + IntegrityAudit ia = papServlet.getIa(); + ia.stopAuditThread(); + papServlet.doPost(httpServletRequest, httpServletResponse); + //Mockito.verify(httpServletResponse).sendError(500, "Policy 'default' not copied to group 'default': java.lang.NullPointerException"); + //Mockito.verify(httpServletResponse).sendError(500, "Policy 'default' not copied to group 'default': javax.persistence.PersistenceException: Group policy is being added to does not exist with id default"); + + }catch (Exception e){ + fail(); + } + } + //why is this test trying to send no pdp id and expecting a 200 response? + /* + public void testDoPost(){ + final ByteArrayOutputStream os = new ByteArrayOutputStream (); + ByteArrayOutputStream multiPartResponse = new ByteArrayOutputStream(); + Mockito.when(httpServletRequest.getHeader("X-XACML-PDP-JMX-PORT")).thenReturn("0"); + + try{ + multiPartResponse.writeTo(os); + final ByteArrayInputStream is = new ByteArrayInputStream (os.toByteArray ()); + Mockito.when(httpServletRequest.getInputStream()).thenReturn(new ServletInputStream() { + @Override + public int read() throws IOException { + return is.read(); + } + }); + + papServlet.init(servletConfig); + IntegrityAudit ia = papServlet.getIa(); + ia.stopAuditThread(); + papServlet.doPost(httpServletRequest, httpServletResponse); + Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK); + }catch (Exception e){ + fail(); + } + } + */ + + public void testDoPostPDPId(){ + String groupId = "newPDP"; + Mockito.when(httpServletRequest.getParameter("groupId")).thenReturn(groupId); + Mockito.when(httpServletRequest.getHeader("X-XACML-PDP-ID")).thenReturn(groupId); + try{ + papServlet.init(servletConfig); + IntegrityAudit ia = papServlet.getIa(); + ia.stopAuditThread(); + papServlet.doPut(httpServletRequest, httpServletResponse); + Mockito.verify(httpServletResponse).sendError(HttpServletResponse.SC_NOT_FOUND, "Unknown groupId '" + groupId +"'"); + }catch(Exception e){ + fail(); + } + } + + public void testDoPutInvalidAdminConsoleURL(){ + Mockito.when(httpServletRequest.getParameter("adminConsoleURL")).thenReturn("wwww.adminConsole.com"); + //204 + try{ + papServlet.init(servletConfig); + IntegrityAudit ia = papServlet.getIa(); + ia.stopAuditThread(); + papServlet.doPut(httpServletRequest, httpServletResponse); + Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_NO_CONTENT); + }catch (Exception e){ + fail(); + } + } + + public void testDoPutWithGroupIdAndUnimplimentedPipId(){ + Mockito.when(httpServletRequest.getParameter("groupId")).thenReturn("default"); + Mockito.when(httpServletRequest.getParameter("pipId")).thenReturn("default"); + try{ + papServlet.init(servletConfig); + IntegrityAudit ia = papServlet.getIa(); + ia.stopAuditThread(); + papServlet.doPut(httpServletRequest, httpServletResponse); + Mockito.verify(httpServletResponse).sendError(HttpServletResponse.SC_BAD_REQUEST, "UNIMPLEMENTED"); + }catch (Exception e){ + fail(); + } + } + + public void testDoDeleteNoGroup(){ + Mockito.when(httpServletRequest.getParameter("groupdId")).thenReturn(null); + + try{ + papServlet.init(servletConfig); + IntegrityAudit ia = papServlet.getIa(); + ia.stopAuditThread(); + papServlet.doDelete(httpServletRequest, httpServletResponse); + Mockito.verify(httpServletResponse).sendError(HttpServletResponse.SC_BAD_REQUEST, "Request does not have groupId"); + }catch (Exception e){ + fail(); + } + } + + public void testDoDeleteWithDefaultGroup(){ + Mockito.when(httpServletRequest.getParameter("groupId")).thenReturn("default"); + + try{ + papServlet.init(servletConfig); + IntegrityAudit ia = papServlet.getIa(); + ia.stopAuditThread(); + papServlet.doDelete(httpServletRequest, httpServletResponse); + Mockito.verify(httpServletResponse).sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,"You cannot delete the default group."); + }catch(Exception e){ + fail(); + } + } +} diff --git a/ECOMP-PAP-REST/src/test/java/org/openecomp/policy/pap/xacml/rest/components/PolicyDBDaoTest.java b/ECOMP-PAP-REST/src/test/java/org/openecomp/policy/pap/xacml/rest/components/PolicyDBDaoTest.java new file mode 100644 index 000000000..81f33c99b --- /dev/null +++ b/ECOMP-PAP-REST/src/test/java/org/openecomp/policy/pap/xacml/rest/components/PolicyDBDaoTest.java @@ -0,0 +1,823 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.components; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.nio.file.Paths; +import java.util.Date; +import java.util.List; + +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.Persistence; +import javax.persistence.PersistenceException; +import javax.persistence.Query; + +import org.junit.Test; +import org.openecomp.policy.pap.xacml.rest.adapters.PolicyRestAdapter; +import org.openecomp.policy.pap.xacml.rest.components.ConfigPolicy; +import org.openecomp.policy.pap.xacml.rest.components.Policy; +import org.openecomp.policy.pap.xacml.rest.components.PolicyDBDao; +import org.openecomp.policy.pap.xacml.rest.components.PolicyDBDaoTransaction; +import org.openecomp.policy.pap.xacml.rest.components.PolicyDBDao.PolicyDBDaoTestClass; +import org.openecomp.policy.rest.XACMLRestProperties; +import org.openecomp.policy.rest.jpa.ActionBodyEntity; +import org.openecomp.policy.rest.jpa.GroupEntity; +import org.openecomp.policy.rest.jpa.PdpEntity; +import org.openecomp.policy.rest.jpa.PolicyEntity; +import org.openecomp.policy.rest.util.Webapps; + +import com.att.research.xacml.api.pap.PAPException; + +import org.openecomp.policy.xacml.api.pap.EcompPDPGroup; +import org.openecomp.policy.xacml.std.pap.StdPDPGroup; +import org.openecomp.policy.xacml.util.XACMLPolicyWriter; +import com.att.research.xacml.util.XACMLProperties; + +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.IOUtils; +//import org.apache.commons.logging.Log; +//import org.apache.commons.logging.LogFactory; +import org.junit.Before; +import org.junit.After; +import org.junit.Ignore; + +import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType; + +import org.junit.Assert; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +@Ignore //only run locally as timing sometimes causes failures on Jenkins +public class PolicyDBDaoTest { + + private static Logger logger = FlexLogger.getLogger(PolicyDBDaoTest.class); + + PolicyDBDaoTestClass d; + PolicyDBDao dbd; + PolicyDBDao dbd2; + EntityManagerFactory emf; + @Before + public void init(){ + System.setProperty(XACMLProperties.XACML_PROPERTIES_NAME,"xacml.pap.properties"); + emf = Persistence.createEntityManagerFactory("testPapPU"); + EntityManager em = emf.createEntityManager(); + em.getTransaction().begin(); + try{ + em.createQuery("DELETE FROM PolicyDBDaoEntity").executeUpdate(); + em.createQuery("DELETE FROM PolicyEntity").executeUpdate(); + em.createQuery("DELETE FROM ConfigurationDataEntity").executeUpdate(); + em.createQuery("DELETE FROM ActionBodyEntity").executeUpdate(); + em.createQuery("DELETE FROM PdpEntity").executeUpdate(); + em.createQuery("DELETE FROM GroupEntity").executeUpdate(); + + em.getTransaction().commit(); + } catch(Exception e){ + e.printStackTrace(); + em.getTransaction().rollback(); + } + em.close(); + try { + dbd = PolicyDBDao.getPolicyDBDaoInstance(emf); + dbd2 = PolicyDBDao.getPolicyDBDaoInstance(emf); + } catch (Exception e) { + //e.printStackTrace(); + Assert.fail(); + } + + d = PolicyDBDao.getPolicyDBDaoTestClass(); + } + + @After + public void cleanUp(){ + EntityManager em = emf.createEntityManager(); + em.getTransaction().begin(); + try{ + em.createQuery("DELETE FROM PolicyDBDaoEntity").executeUpdate(); + em.createQuery("DELETE FROM PolicyEntity").executeUpdate(); + em.createQuery("DELETE FROM ConfigurationDataEntity").executeUpdate(); + em.createQuery("DELETE FROM ActionBodyEntity").executeUpdate(); + em.createQuery("DELETE FROM PdpEntity").executeUpdate(); + em.createQuery("DELETE FROM GroupEntity").executeUpdate(); + + em.getTransaction().commit(); + } catch(Exception e){ + em.getTransaction().rollback(); + } + em.close(); + try { + FileUtils.forceDelete(new File("src/test/resources/junitTestCreatedDirectory")); + } catch (IOException e) { + //could not delete + } + + } + + @Test + public void getScopeAndNameAndTypeTest(){ + + String s = d.getGitPath(); + String pathIwantToUse; + if(s.contains("/")){ + pathIwantToUse = "/root/users/" + s + "/org/openecomp/Config_mypolicy.xml"; + } else { + pathIwantToUse = "C:\\root\\users\\" + s + "\\org\\openecomp\\Config_mypolicy.xml"; + } + String[] snt = d.getScopeAndNameAndType(pathIwantToUse); + Assert.assertEquals("Scope was parsed wrong","org.openecomp", snt[0]); + Assert.assertEquals("Policy name was parsed wrong","Config_mypolicy.xml", snt[1]); + Assert.assertEquals("Policy type was parsed wrong","Config", snt[2]); + } + @Test + public void computeScopeTest(){ + Assert.assertEquals("com",d.computeScope("C:\\Users\\testuser\\admin\\repo\\com\\", "C:\\Users\\testuser\\admin\\repo")); + Assert.assertEquals("org.openecomp.policy",d.computeScope("/Users/testuser/admin/repo/org/openecomp/policy", "/Users/testuser/admin/repo")); + } + @Test + public void getConfigFileTest(){ + PolicyRestAdapter pra = new PolicyRestAdapter(); + pra.setConfigType(ConfigPolicy.JSON_CONFIG); + String configFile = d.getConfigFile("Config_mypolicy.xml", "org.openecomp", pra); + Assert.assertEquals("org.openecomp.Config_mypolicy.json", configFile); + //yes, we can do action files too even though they don't have configs + configFile = d.getConfigFile("Action_mypolicy.xml", "org.openecomp", pra); + Assert.assertEquals("org.openecomp.Action_mypolicy.json", configFile); + } + + @Test + public void transactionTests(){ + + +// try{ +// transac.commitTransaction(); +// Assert.fail(); +// } catch(IllegalStateException e){ +// //worked +// } catch(Exception e2){ +// Assert.fail(); +// } + String filePath = null; + String xmlFile = "\n\n \n \n \n \n \n 99\n \n \n \n \n \n \n \n \n \n \n PDPAction\n \n \n REST\n \n \n http://localhost:8056/pcd\n \n \n GET\n \n \n $URLaction/com.Action_patbaction7.json\n \n \n \n \n\n"; + String jsonFile = "{\"actionAttribute\":\"Memory\"}"; + + try{ + //policy file + InputStream in = new ByteArrayInputStream(xmlFile.getBytes()); + String workspaceDir = "src/test/resources/junitTestCreatedDirectory/"+XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_WORKSPACE)+"/admin/"+XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_REPOSITORY); + FileUtils.forceMkdir(new File(workspaceDir+"/org/openecomp")); + File outFile = new File(workspaceDir+"/org/openecomp/Action_mypol.xml"); + OutputStream out = new FileOutputStream(outFile); + IOUtils.copy(in, out); + filePath = outFile.getAbsolutePath(); + out.close(); + + //action body file + InputStream actionIn = new ByteArrayInputStream(jsonFile.getBytes()); + String webappDir = "src/test/resources/junitTestCreatedDirectory/"+XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_WORKSPACE); + XACMLProperties.setProperty(XACMLRestProperties.PROP_PAP_WEBAPPS, webappDir); + String actionDir = Webapps.getActionHome(); + FileUtils.forceMkdir(new File(actionDir)); + File actionOutFile = new File(actionDir+"/org.openecomp.Action_mypol.json"); + OutputStream actionOut = new FileOutputStream(actionOutFile); + IOUtils.copy(actionIn, actionOut); + actionOut.close(); + + }catch(Exception e){ + //could not run test + } + PolicyDBDaoTransaction transac = dbd.getNewTransaction(); + if(filePath != null){ + try{ + transac.createPolicy(filePath, "tester"); + transac.commitTransaction(); + } catch(Exception e){ + Assert.fail(); + } + EntityManager getData = emf.createEntityManager(); + Query getDataQuery = getData.createQuery("SELECT p FROM PolicyEntity p WHERE p.scope=:scope AND p.policyName=:name"); + getDataQuery.setParameter("scope", "org.openecomp"); + getDataQuery.setParameter("name","Action_mypol.xml"); + PolicyEntity result = null; + try{ + result = (PolicyEntity)getDataQuery.getSingleResult(); + } catch(Exception e){ + e.printStackTrace(); + Assert.fail(); + } + Assert.assertEquals(xmlFile, result.getPolicyData()); + getData.close(); + result = null; + xmlFile = null; + try{ + transac = dbd.getNewTransaction(); + transac.deletePolicy(filePath); + } catch(Exception e){ + e.printStackTrace(); + Assert.fail(); + } + Assert.assertTrue(transac.isTransactionOpen()); + try{ + transac.deletePolicy(filePath); + Assert.fail(); + } catch(IllegalStateException e){ + //pass + } catch(Exception e){ + Assert.fail(); + } + transac.commitTransaction(); + //Assert.assertFalse(transac.isTransactionOpen()); + try{ + transac = dbd.getNewTransaction(); + transac.deletePolicy(filePath); + } catch(Exception e){ + e.printStackTrace(); + Assert.fail(); + } + transac.commitTransaction(); + //Assert.assertFalse(transac.isTransactionOpen()); + String workspaceDir = "src/test/resources/junitTestCreatedDirectory/"+XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_WORKSPACE)+"/admin/"+XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_REPOSITORY); + PolicyDBDaoTransaction willFail = dbd.getNewTransaction(); + File fakeFile = new File("directorythatdoesnotexist/"+workspaceDir); + try{ + willFail.createPolicy(fakeFile.getAbsolutePath(), "user1"); + Assert.fail(); + } catch(IllegalArgumentException e){ + if(!e.getMessage().equals("The file path could not be parsed")){ + Assert.fail(); + } + } + willFail.close(); + + fakeFile = new File("directorythatdoesnotexist/"+workspaceDir+"/Action_mypol2.xml"); + willFail = dbd.getNewTransaction(); + try{ + willFail.createPolicy(fakeFile.getAbsolutePath(), "user1"); + Assert.fail(); + } catch(IllegalArgumentException e){ + if(!e.getMessage().equals("The file path could not be parsed")){ + Assert.fail(); + } + } + willFail.close(); + + fakeFile = new File("directorythatdoesnotexist/"+workspaceDir+"org/openecomp/Action_mypol2.xml"); + willFail = dbd.getNewTransaction(); + try{ + willFail.createPolicy(fakeFile.getAbsolutePath(), "user1"); + Assert.fail(); + } catch(IllegalArgumentException e){ + if(!e.getMessage().equals("The file path does not exist")){ + Assert.fail(); + } + } + willFail.close(); + + emf = Persistence.createEntityManagerFactory("testPU"); + EntityManager aem = emf.createEntityManager(); + Query actionQuery = aem.createQuery("SELECT a FROM ActionBodyEntity a WHERE a.actionBodyName=:actionBodyName"); + actionQuery.setParameter("actionBodyName", "org.openecomp.Action_mypol.json"); + List actionQueryList = actionQuery.getResultList(); + if(actionQueryList.size() < 1){ + Assert.fail("ActionBodyEntity not found with actionBodyName=: org.openecomp.Action_mypol.json" ); + } else if(actionQueryList.size() > 1){ + //something went wrong + Assert.fail("Somehow, more than one ActionBodyEntity with the actionBodyName = org.openecomp.Action_mypol.json"); + } else { + ActionBodyEntity abe = (ActionBodyEntity)actionQueryList.get(0); + logger.debug("\n\nPolicyDBDaoTest.transactionTests() Assert.assertEquals" + + "\n abe.getActionBody() = " + abe.getActionBody() + + "\n jsonFile = " + jsonFile + + "\n\n"); + Assert.assertEquals(abe.getActionBody(),jsonFile); + } + } + } + + @Test + public void createFromPolicyObject(){ + String workspaceDir = "src/test/resources/junitTestCreatedDirectory/"+XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_WORKSPACE)+"/admin/"+XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_REPOSITORY); + File parentPath = new File(workspaceDir+"/org/openecomp"); + File scope = new File(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_WORKSPACE)+"/admin/"+XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_REPOSITORY)); + Policy policyObject = new ConfigPolicy(); + policyObject.policyAdapter = new PolicyRestAdapter(); + policyObject.policyAdapter.setConfigName("testpolicy1"); + policyObject.policyAdapter.setParentPath(parentPath.getAbsolutePath()); + policyObject.policyAdapter.setUserGitPath(scope.getPath()); + policyObject.policyAdapter.setPolicyDescription("my description"); + policyObject.policyAdapter.setConfigBodyData("this is my test config file"); + policyObject.policyAdapter.setPolicyName("testpolicy1"); + policyObject.policyAdapter.setConfigType(ConfigPolicy.OTHER_CONFIG); + policyObject.policyAdapter.setPolicyType("Config"); + PolicyType policyTypeObject = new PolicyType(); + policyObject.policyAdapter.setPolicyData(policyTypeObject); + PolicyDBDaoTransaction transaction = dbd.getNewTransaction(); + try{ + transaction.createPolicy(policyObject, "testuser1"); + transaction.commitTransaction(); + } catch(Exception e){ + transaction.rollbackTransaction(); + Assert.fail(); + } + + EntityManager getData = emf.createEntityManager(); + Query getDataQuery = getData.createQuery("SELECT p FROM PolicyEntity p WHERE p.scope=:scope AND p.policyName=:name"); + getDataQuery.setParameter("scope", "org.openecomp"); + getDataQuery.setParameter("name","Config_testpolicy1.xml"); + PolicyEntity result = null; + try{ + result = (PolicyEntity)getDataQuery.getSingleResult(); + } catch(Exception e){ + e.printStackTrace(); + Assert.fail(); + } + String expectedData; + try { + expectedData = IOUtils.toString(XACMLPolicyWriter.getXmlAsInputStream(policyTypeObject)); + } catch (IOException e1) { + expectedData = ""; + } + Assert.assertEquals(expectedData, result.getPolicyData()); + getData.close(); + result = null; + File policyFile = new File(workspaceDir+"/org/openecomp/Config_testpolicy1.xml"); + try{ + transaction = dbd.getNewTransaction(); + transaction.deletePolicy(policyFile.getAbsolutePath()); + } catch(Exception e){ + e.printStackTrace(); + Assert.fail(); + } + Assert.assertTrue(transaction.isTransactionOpen()); + try{ + transaction.deletePolicy(policyFile.getAbsolutePath()); + Assert.fail(); + } catch(IllegalStateException e){ + //pass + } catch(Exception e){ + Assert.fail(); + } + transaction.commitTransaction(); + Assert.assertFalse(transaction.isTransactionOpen()); + try{ + transaction = dbd.getNewTransaction(); + transaction.deletePolicy(policyFile.getAbsolutePath()); + } catch(Exception e){ + e.printStackTrace(); + Assert.fail(); + } + //Assert.assertFalse(transaction.isTransactionOpen()); + transaction.commitTransaction(); + } + + @Test + public void groupTransactions(){ + PolicyDBDaoTransaction group = dbd.getNewTransaction(); + String groupName = "test group 1"; + try{ + group.createGroup(PolicyDBDao.createNewPDPGroupId(groupName), groupName, "this is a test group","testuser"); + group.commitTransaction(); + } catch(Exception e){ + group.rollbackTransaction(); + e.printStackTrace(); + Assert.fail(); + } + EntityManager em = emf.createEntityManager(); + Query getGroup = em.createQuery("SELECT g FROM GroupEntity g WHERE g.groupId=:groupId AND g.deleted=:deleted"); + getGroup.setParameter("groupId", PolicyDBDao.createNewPDPGroupId(groupName)); + getGroup.setParameter("deleted", false); + List groups = getGroup.getResultList(); + if(groups.size() != 1){ + Assert.fail(); + } + GroupEntity groupEntity = (GroupEntity)groups.get(0); + em.close(); + Assert.assertEquals(groupName, groupEntity.getgroupName()); + Assert.assertEquals("this is a test group", groupEntity.getDescription()); + group = dbd.getNewTransaction(); + try{ + EcompPDPGroup groupToDelete = new StdPDPGroup(PolicyDBDao.createNewPDPGroupId(groupName),Paths.get("/")); + group.deleteGroup(groupToDelete, null,"testuser"); + group.commitTransaction(); + } catch(Exception e){ + group.rollbackTransaction(); + e.printStackTrace(); + Assert.fail(); + } + em = emf.createEntityManager(); + getGroup = em.createQuery("SELECT g FROM GroupEntity g WHERE g.groupId=:groupId AND g.deleted=:deleted"); + getGroup.setParameter("groupId", PolicyDBDao.createNewPDPGroupId(groupName)); + getGroup.setParameter("deleted", false); + groups = getGroup.getResultList(); + if(groups.size() != 0){ + System.out.println("Group size: "+groups.size()); + Assert.fail(); + } + em.close(); + //add a pdp to a group + group = dbd.getNewTransaction(); + try{ + group.createGroup(PolicyDBDao.createNewPDPGroupId(groupName), groupName, "test group", "testuser"); + group.commitTransaction(); + } catch(Exception e){ + group.rollbackTransaction(); + e.printStackTrace(); + Assert.fail(); + } + group = dbd.getNewTransaction(); + try{ + group.addPdpToGroup("http://localhost:4344/pdp/", PolicyDBDao.createNewPDPGroupId(groupName), "primary", "the main pdp", 3232, "testuser"); + group.commitTransaction(); + } catch(Exception e){ + group.rollbackTransaction(); + e.printStackTrace(); + Assert.fail(); + } + em = emf.createEntityManager(); + Query getPdp = em.createQuery("SELECT p FROM PdpEntity p WHERE p.pdpId=:pdpId AND p.deleted=:deleted"); + getPdp.setParameter("pdpId", "http://localhost:4344/pdp/"); + getPdp.setParameter("deleted", false); + List pdps = getPdp.getResultList(); + if(pdps.size() != 1){ + System.out.println("Group size: "+pdps.size()); + Assert.fail(); + } + PdpEntity pdp = (PdpEntity)pdps.get(0); + Assert.assertEquals(groupName, pdp.getGroup().getgroupName()); + Assert.assertEquals(pdp.getPdpName(), "primary"); + em.close(); + group = dbd.getNewTransaction(); + try{ + group.removePdpFromGroup("http://localhost:4344/pdp/","testuser"); + group.commitTransaction(); + } catch(Exception e){ + group.rollbackTransaction(); + e.printStackTrace(); + Assert.fail(); + } + em = emf.createEntityManager(); + getPdp = em.createQuery("SELECT p FROM PdpEntity p WHERE p.pdpId=:pdpId AND p.deleted=:deleted"); + getPdp.setParameter("pdpId", "http://localhost:4344/pdp/"); + getPdp.setParameter("deleted", false); + pdps = getPdp.getResultList(); + if(pdps.size() != 0){ + System.out.println("Group size: "+pdps.size()); + Assert.fail(); + } + em.close(); + + //add some pdps to groups + group = dbd.getNewTransaction(); + try{ + group.createGroup(PolicyDBDao.createNewPDPGroupId("testgroup1"), "testgroup1", "test group", "testuser"); + group.commitTransaction(); + } catch(Exception e){ + group.rollbackTransaction(); + e.printStackTrace(); + Assert.fail(); + } + group = dbd.getNewTransaction(); + try{ + group.createGroup(PolicyDBDao.createNewPDPGroupId("testgroup2"), "testgroup2", "test group", "testuser"); + group.commitTransaction(); + } catch(Exception e){ + group.rollbackTransaction(); + e.printStackTrace(); + Assert.fail(); + } + + group = dbd.getNewTransaction(); + try{ + group.addPdpToGroup("http://localhost:4344/pdp/", PolicyDBDao.createNewPDPGroupId("testgroup1"), "primary", "the main pdp", 3232, "testuser"); + group.commitTransaction(); + } catch(Exception e){ + group.rollbackTransaction(); + e.printStackTrace(); + Assert.fail(); + } + group = dbd.getNewTransaction(); + try{ + group.addPdpToGroup("http://localhost:4345/pdp/", PolicyDBDao.createNewPDPGroupId("testgroup1"), "secondary", "the second pdp", 3233, "testuser"); + group.commitTransaction(); + } catch(Exception e){ + group.rollbackTransaction(); + e.printStackTrace(); + Assert.fail(); + } + em = emf.createEntityManager(); + getPdp = em.createQuery("SELECT p FROM PdpEntity p WHERE p.deleted=:deleted"); + getPdp.setParameter("deleted", false); + pdps = getPdp.getResultList(); + for(Object o : pdps){ + Assert.assertEquals("testgroup1",((PdpEntity)o).getGroup().getgroupName()); + } + em.close(); + + group = dbd.getNewTransaction(); + try{ + EcompPDPGroup groupToDelete = new StdPDPGroup(PolicyDBDao.createNewPDPGroupId("testgroup1"),Paths.get("/")); + EcompPDPGroup groupToMoveTo = new StdPDPGroup(PolicyDBDao.createNewPDPGroupId("testgroup2"),Paths.get("/")); + group.deleteGroup(groupToDelete, groupToMoveTo,"testuser"); + group.commitTransaction(); + } catch(Exception e){ + group.rollbackTransaction(); + e.printStackTrace(); + Assert.fail(); + } + em = emf.createEntityManager(); + getGroup = em.createQuery("SELECT g FROM GroupEntity g WHERE g.groupId=:groupId AND g.deleted=:deleted"); + getGroup.setParameter("groupId", "testgroup1"); + getGroup.setParameter("deleted", false); + groups = getGroup.getResultList(); + if(groups.size() != 0){ + System.out.println("Group size: "+groups.size()); + Assert.fail(); + } + em.close(); + + em = emf.createEntityManager(); + getPdp = em.createQuery("SELECT p FROM PdpEntity p WHERE p.deleted=:deleted"); + getPdp.setParameter("deleted", false); + pdps = getPdp.getResultList(); + for(Object o : pdps){ + Assert.assertEquals("testgroup2",((PdpEntity)o).getGroup().getgroupName()); + } + em.close(); + + group = dbd.getNewTransaction(); + try{ + EcompPDPGroup groupToDelete = new StdPDPGroup(PolicyDBDao.createNewPDPGroupId("testgroup2"),Paths.get("/")); + EcompPDPGroup groupToMoveTo = null; + group.deleteGroup(groupToDelete, groupToMoveTo,"testuser"); + group.commitTransaction(); + Assert.fail(); + } catch(PAPException pe){ + //good, can't delete group with pdps + group.rollbackTransaction(); + } catch(Exception e){ + group.rollbackTransaction(); + e.printStackTrace(); + Assert.fail(); + } + + + //add policy to group + + //update group + EcompPDPGroup pdpGroup = new StdPDPGroup("testgroup2", false, "newtestgroup2", "this is my new description", Paths.get("/")); + group = dbd.getNewTransaction(); + try{ + group.updateGroup(pdpGroup, "testuser"); + group.commitTransaction(); + }catch (Exception e){ + e.printStackTrace(); + group.rollbackTransaction(); + Assert.fail(); + } + em = emf.createEntityManager(); + getGroup = em.createQuery("SELECT g FROM GroupEntity g WHERE g.groupId=:groupId AND g.deleted=:deleted"); + getGroup.setParameter("groupId", "newtestgroup2"); + getGroup.setParameter("deleted", false); + groups = getGroup.getResultList(); + if(groups.size() != 1){ + System.out.println("Group size: "+groups.size()); + Assert.fail(); + } + em.close(); + em = emf.createEntityManager(); + getGroup = em.createQuery("SELECT g FROM GroupEntity g WHERE g.groupId=:groupId AND g.deleted=:deleted"); + getGroup.setParameter("groupId", "testgroup2"); + getGroup.setParameter("deleted", false); + groups = getGroup.getResultList(); + if(groups.size() != 0){ + System.out.println("Group size: "+groups.size()); + Assert.fail(); + } + em.close(); + //update pdp + + //set group as default + + //move pdp to new group + + + } + + @Test + public void encryptionTest(){ + try { + String encr = d.encryptPassword("testpassword"); + System.out.println("original password: "+"testpassword"); + System.out.println("Encrypted password: "+encr); + String decr = d.decryptPassword(encr); + System.out.println("Decrypted password: "+decr); + Assert.assertEquals("testpassword", decr); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + Assert.fail(); + } + + } + @Test + public void getDescriptionFromXacmlTest(){ + String myTestDesc = "hello this is a test"; + String desc = d.getDescriptionFromXacml(""+myTestDesc+""); + Assert.assertEquals(myTestDesc, desc); + } + + @Test + public void threadingStabilityTest(){ + if(logger.isDebugEnabled()){ + logger.debug("\n\n****************************" + + "threadingStabilityTest() entry" + + "******************************\n\n"); + } + + PolicyDBDaoTransaction t = dbd.getNewTransaction(); + Assert.assertTrue(t.isTransactionOpen()); + try { + //Add 1000 ms to the timeout just to be sure it actually times out + int sleepTime = Integer.parseInt(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_TRANS_TIMEOUT)) + 1000; + if(logger.isDebugEnabled()){ + Date date= new java.util.Date(); + logger.debug("\n\nPolicyDBDaoTest.threadingStabilityTest() " + + "\n sleepTime = " + sleepTime + + "\n TimeStamp = " + date.getTime() + + "\n\n"); + } + Thread.sleep(sleepTime); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + if(logger.isDebugEnabled()){ + Date date= new java.util.Date(); + logger.debug("\n\nPolicyDBDaoTest.threadingStabilityTest() " + + "\n Assert.assertFalse(t.isTransactionOpen() = " + t.isTransactionOpen() + ")" + + "\n TimeStamp = " + date.getTime() + + "\n\n"); + } + Assert.assertFalse(t.isTransactionOpen()); + + + if(logger.isDebugEnabled()){ + Date date= new java.util.Date(); + logger.debug("\n\nPolicyDBDaoTest.threadingStabilityTest() " + + "\n a = dbd.getNewTransaction() " + + "\n TimeStamp = " + date.getTime() + + "\n\n"); + } + PolicyDBDaoTransaction a = dbd.getNewTransaction(); + if(logger.isDebugEnabled()){ + Date date= new java.util.Date(); + logger.debug("\n\nPolicyDBDaoTest.threadingStabilityTest() " + + "\n Assert.assertTrue(a.isTransactionOpen() = " + a.isTransactionOpen() + ")" + + "\n TimeStamp = " + date.getTime() + + "\n\n"); + } + Assert.assertTrue(a.isTransactionOpen()); + + try { + //Add 1000 ms to the timeout just to be sure it actually times out + int sleepTime = Integer.parseInt(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_TRANS_TIMEOUT)) + 1000; + if(logger.isDebugEnabled()){ + Date date= new java.util.Date(); + logger.debug("\n\nPolicyDBDaoTest.threadingStabilityTest() " + + "\n sleepTime = " + sleepTime + + "\n TimeStamp = " + date.getTime() + + "\n\n"); + } + Thread.sleep(sleepTime); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + if(logger.isDebugEnabled()){ + Date date= new java.util.Date(); + logger.debug("\n\nPolicyDBDaoTest.threadingStabilityTest() " + + "\n b = dbd.getNewTransaction() " + + "\n TimeStamp = " + date.getTime() + + "\n\n"); + } + PolicyDBDaoTransaction b = dbd.getNewTransaction(); + if(logger.isDebugEnabled()){ + Date date= new java.util.Date(); + logger.debug("\n\nPolicyDBDaoTest.threadingStabilityTest() " + + "\n Assert.assertFalse(a.isTransactionOpen() = " + a.isTransactionOpen() + ")" + + "\n TimeStamp = " + date.getTime() + + "\n\n"); + } + Assert.assertFalse(a.isTransactionOpen()); + if(logger.isDebugEnabled()){ + Date date= new java.util.Date(); + logger.debug("\n\nPolicyDBDaoTest.threadingStabilityTest() " + + "\n Assert.assertTrue(b.isTransactionOpen() = " + b.isTransactionOpen() + ")" + + "\n TimeStamp = " + date.getTime() + + "\n\n"); + } + Assert.assertTrue(b.isTransactionOpen()); + b.close(); + + + + //Now let's test the transaction wait time timeout. Shorten the wait time to 1000 ms + System.setProperty(XACMLRestProperties.PROP_PAP_TRANS_WAIT,"1000"); + //And let's lengthen the transaction timeout to 5000 ms + System.setProperty(XACMLRestProperties.PROP_PAP_TRANS_TIMEOUT,"5000"); + //get a transacton + PolicyDBDaoTransaction t1 = dbd.getNewTransaction(); + if(logger.isDebugEnabled()){ + Date date= new java.util.Date(); + logger.debug("\n\nPolicyDBDaoTest.threadingStabilityTest() " + + "\n Assert.assertTrue(t1.isTransactionOpen() = " + t1.isTransactionOpen() + ")" + + "\n TimeStamp = " + date.getTime() + + "\n\n"); + } + Assert.assertTrue(t1.isTransactionOpen()); + //while it is open, get another from a different DB Dao so it will not collide on the synchronized code segment + //but will collide at the DB. Remember that the wait time is only 1000 ms + try { + //Now the 2nd transaction has a wait timeout in 1000 ms + PolicyDBDaoTransaction t2 = dbd2.getNewTransaction(); + /* + * Give it plenty of time to time out the second transaction + * It will actually hang right here until it either gets the lock from the DB or the + * request for the DB lock times out. The timers are very sloppy so, I have given + * this plenty of leeway. + */ + + if(logger.isDebugEnabled()){ + Date date= new java.util.Date(); + logger.debug("\n\nPolicyDBDaoTest.threadingStabilityTest() " + + "\n Thread.sleep(3000)" + + "\n TimeStamp = " + date.getTime() + + "\n\n"); + } + Thread.sleep(3000); + if(logger.isDebugEnabled()){ + Date date= new java.util.Date(); + logger.debug("\n\nPolicyDBDaoTest.threadingStabilityTest() " + + "\n Assert.assertTrue(t1.isTransactionOpen() = " + t1.isTransactionOpen() + ")" + + "\n Assert.assertFalse(t2.isTransactionOpen() = " + t2.isTransactionOpen() + ")" + + "\n TimeStamp = " + date.getTime() + + "\n\n"); + } + //Assert.assertTrue(t1.isTransactionOpen()); + //Assert.assertFalse(t2.isTransactionOpen()); + + Assert.fail("\n\nTransaction timeout of 1000 ms exceeded without a PersistenceException\n\n"); + } catch (PersistenceException e) { + //success + if(logger.isDebugEnabled()){ + Date date= new java.util.Date(); + logger.debug("\n\nPolicyDBDaoTest.threadingStabilityTest() " + + "\n SUCCESS! Transaction Wait Timeout worked!" + + "\n Caught PersistenceException = " + e + + "\n TimeStamp = " + date.getTime() + + "\n\n"); + } + } catch (Exception e) { + // failure due to some other reason + if(logger.isDebugEnabled()){ + Date date= new java.util.Date(); + logger.debug("\n\nPolicyDBDaoTest.threadingStabilityTest() FAILURE" + + "\n Caught Exception = " + e + + "\n TimeStamp = " + date.getTime() + + "\n\n"); + } + e.printStackTrace(); + Assert.fail(); + } + + if(logger.isDebugEnabled()){ + Date date= new java.util.Date(); + logger.debug("\n\nthreadingStabilityTest() exit" + + "\n TimeStamp = " + date.getTime() + + "\n\n"); + } + } + +} diff --git a/ECOMP-PAP-REST/src/test/java/org/openecomp/policy/pap/xacml/rest/jpa/PolicyEntityTest.java b/ECOMP-PAP-REST/src/test/java/org/openecomp/policy/pap/xacml/rest/jpa/PolicyEntityTest.java new file mode 100644 index 000000000..f71026c39 --- /dev/null +++ b/ECOMP-PAP-REST/src/test/java/org/openecomp/policy/pap/xacml/rest/jpa/PolicyEntityTest.java @@ -0,0 +1,802 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.jpa; + +import static org.junit.Assert.*; + +//import org.apache.commons.logging.Log; +//import org.apache.commons.logging.LogFactory; +import org.junit.*; +import org.openecomp.policy.rest.XACMLRestProperties; +import org.openecomp.policy.rest.jpa.ActionBodyEntity; +import org.openecomp.policy.rest.jpa.ConfigurationDataEntity; +import org.openecomp.policy.rest.jpa.PolicyDBDaoEntity; +import org.openecomp.policy.rest.jpa.PolicyEntity; + +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.EntityTransaction; +import javax.persistence.Persistence; +import javax.persistence.Query; + +import java.util.Date; +import java.util.List; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +import java.util.Properties; + +public class PolicyEntityTest { + + private static Logger logger = FlexLogger.getLogger(PolicyEntityTest.class); + +// @Ignore + @Test + public void testAllOps(){ + Properties properties = new Properties(); + properties.put(XACMLRestProperties.PROP_PAP_DB_DRIVER,"org.h2.Driver"); + properties.put(XACMLRestProperties.PROP_PAP_DB_URL, "jdbc:h2:file:./sql/xacmlTest"); + properties.put(XACMLRestProperties.PROP_PAP_DB_USER, "sa"); + properties.put(XACMLRestProperties.PROP_PAP_DB_PASSWORD, ""); + EntityManagerFactory emf = Persistence.createEntityManagerFactory("testPapPU", properties); + EntityManager em = emf.createEntityManager(); + // Start a transaction + EntityTransaction et = em.getTransaction(); + + et.begin(); + //Make sure the DB is clean + em.createQuery("DELETE FROM PolicyDBDaoEntity").executeUpdate(); + em.createQuery("DELETE FROM PolicyEntity").executeUpdate(); + em.createQuery("DELETE FROM ConfigurationDataEntity").executeUpdate(); + em.createQuery("DELETE FROM ActionBodyEntity").executeUpdate(); + + //Create a policy object + PolicyEntity p1 = new PolicyEntity(); + + //persist the policy + em.persist(p1); + + long policyId1 = p1.getPolicyId(); + + String policyName1 = p1.getPolicyName(); + + int version1 = p1.getVersion(); + + String policyData1 = p1.getPolicyData(); + + ConfigurationDataEntity configData1 = p1.getConfigurationData(); + String configDataStr1 = (configData1!=null ? "configurationDataId = " + configData1.getConfigurationDataId() : "configurationData is null"); + + ActionBodyEntity actionBody1 = p1.getActionBodyEntity(); + String actionBodyStr1 = (actionBody1!=null ? "actionBodyId = " + actionBody1.getActionBodyId() : "actionBody is null"); + + String createdBy1 = p1.getCreatedBy(); + + Date createdDate1 = p1.getCreatedDate(); + String createdDateStr1 = (createdDate1 != null ? createdDate1.toString() : "createdDate is null"); + + String description = p1.getDescription(); + + String modifiedBy1 = p1.getModifiedBy(); + + Date modifiedDate1 = p1.getModifiedDate(); + String modifiedDateStr1 = (modifiedDate1 != null ? modifiedDate1.toString() : "modifiedDate is null"); + + + logger.debug("\n\n********PolicyEntityTest: Local PolicyEntity and Configuration objects before persist*********" + + "\npolicyId1 = " + policyId1 + + "\npolicyName1 = " + policyName1 + + "\nversion1 = " + version1 + + "\npolicyData1 = " + policyData1 + + "\nconfigDataStr1 = " + configDataStr1 + + "\nactionBodyStr1 = " + actionBodyStr1 + + "\nscope = " + p1.getScope() + + "\ncreatedBy1 = " + createdBy1 + + "\ncreatedDateStr1 = " + createdDateStr1 + + "\ndescription = " + description + + "\nmodifiedBy1 = " + modifiedBy1 + + "\nmodifiedDateStr1 = " + modifiedDateStr1 + + "\ndeleted = " + p1.isDeleted()); + + //Set policyID + p1.setPolicyName("testPID2"); + + //Set policyData + p1.setPolicyData("PolicyData"); + + //We will NOT set the ConfigurationDataEntity or ActionBodyEntity object just to test that it is optional + + //set createdBy + p1.setCreatedBy("super-admin"); + + //createdDate will be set when it is persisted + + //set scope + p1.setScope("com.test"); + + //set description + p1.setDescription("PolicyEntity Description"); + + //set modifiedBy + p1.setModifiedBy("super-admin"); + + //modifiedDate will be set when it is persisted + + //Flush to the DB + em.flush(); + + //Now lets get some attribute values + + policyId1 = p1.getPolicyId(); + + policyName1 = p1.getPolicyName(); + + version1 = p1.getVersion(); + + policyData1 = p1.getPolicyData(); + + configData1 = p1.getConfigurationData(); + configDataStr1 = (configData1!=null ? "configurationDataId = " + configData1.getConfigurationDataId() : "configurationData is null"); + + actionBody1 = p1.getActionBodyEntity(); + actionBodyStr1 = (actionBody1!=null ? "actionBodyId = " + actionBody1.getActionBodyId() : "actionBody is null"); + + createdBy1 = p1.getCreatedBy(); + + createdDate1 = p1.getCreatedDate(); + createdDateStr1 = (createdDate1 != null ? createdDate1.toString() : "createdDate is null"); + + description = p1.getDescription(); + + modifiedBy1 = p1.getModifiedBy(); + + modifiedDate1 = p1.getModifiedDate(); + modifiedDateStr1 = (modifiedDate1 != null ? modifiedDate1.toString() : "modifiedDate is null"); + + logger.debug("\n\n********PolicyEntityTest: Local PolicyEntity and Configuration objects after persist*********" + + "\npolicyId1 = " + policyId1 + + "\npolicyName1 = " + policyName1 + + "\nversion1 = " + version1 + + "\npolicyData1 = " + policyData1 + + "\nconfigDataStr1 = " + configDataStr1 + + "\nactionBodyStr1 = " + actionBodyStr1 + + "\nscopeId = " + p1.getScope() + + "\ncreatedBy1 = " + createdBy1 + + "\ncreatedDateStr1 = " + createdDateStr1 + + "\ndescription = " + description + + "\nmodifiedBy1 = " + modifiedBy1 + + "\nmodifiedDateStr1 = " + modifiedDateStr1 + + "\ndeleted = " + p1.isDeleted()); + + //Now lets fully configure the configurationData and actionBody + + //Create a ConfigurationDataEntity object and set ID + ConfigurationDataEntity c1 = new ConfigurationDataEntity(); + + ActionBodyEntity a1 = new ActionBodyEntity(); + + //persist the configuration Data + em.persist(c1); + + c1.setConfigType("OTHER"); + + c1.setConfigBody("ABC"); + + c1.setDescription("ConfigurationDataEntity Description"); + + c1.setCreatedBy("super-admin"); + + c1.setDeleted(true); + + //persist the action Body + + em.persist(a1); + + a1.setActionBody("myActionBody"); + + a1.setActionBodyName("myActionBodyName"); + + a1.setCreatedBy("super-admin"); + + a1.setModifiedBy("super-admin"); + + a1.setDeleted(false); + + + long configurationDataId = c1.getConfigurationDataId(); + + int cdVersion = c1.getVersion(); + + String cdConfigType = c1.getConfigType(); + + String cdConfigBody = c1.getConfigBody(); + + String cdCreatedBy = c1.getCreatedBy(); + + Date cdCreatedDate = c1.getCreatedDate(); + + String cdDescription = c1.getDescription(); + + String cdModifiedBy = c1.getModifiedBy(); + + Date cdModifiedDate = c1.getModifiedDate(); + + logger.debug("\n\n********PolicyEntityTest: Local Configuration object after setting values *********" + + "\nconfigurationDataId = " + configurationDataId + + "\ncdVersion = " + cdVersion + + "\ncdConfigType = " + cdConfigType + + "\ncdConfigBody = " + cdConfigBody + + "\ncdCreatedBy = " + cdCreatedBy + + "\ncdCreatedDate = " + cdCreatedDate + + "\ncdDescription = " + cdDescription + + "\ncdModifiedBy = " + cdModifiedBy + + "\ncdModifiedDate = " + cdModifiedDate + + "\ndeleted = " + c1.isDeleted()); + + + + logger.debug("\n\n********PolicyEntityTest: Local Action Body object after setting values *********" + + "\nactionBodyId = " + a1.getActionBodyId() + + "\nactionBodyVersion = " + a1.getVersion() + + "\nactionBody = " + a1.getActionBody() + + "\nactionBodyCeatedBy = " + a1.getCreatedBy() + + "\nactionBodyCreatedDate = " + a1.getCreatedDate() + + "\nactionBodyModifiedBy = " + a1.getModifiedBy() + + "\nactionBodyModifiedDate = " + a1.getModifiedDate() + + "\nactionBodyDeleted = " + a1.isDeleted()); + + p1.setScope("mckiou.kevin.kim"); + + //flush to the db + em.flush(); + + //Perform policy selects + + Query query = em.createQuery("Select p from PolicyEntity p where p.policyId=:pid"); + Query queryscope = em.createQuery("Select p from PolicyEntity p where p.scope=:s"); + + query.setParameter("pid", p1.getPolicyId()); + queryscope.setParameter("s", "com.user"); + + //Just test that we are retrieving the right object + @SuppressWarnings("rawtypes") + List psList = queryscope.getResultList(); + PolicyEntity px = null; + if(!psList.isEmpty()){ + //ignores multiple results + px = (PolicyEntity) psList.get(0); + }else{ + fail("\nPolicyEntityTest: No PolicyEntity using scope DB entry found"); + } + + //The scope object on the retrieved policy object should be same as the one we used to find it + assertSame(p1,px); + + + //Because getSingleResult() throws an unchecked exception which is an indication of a + //programming error, we are not going to use it. + @SuppressWarnings("rawtypes") + List resultList = query.getResultList(); + PolicyEntity p2 = null; + if(!resultList.isEmpty()){ + // ignores multiple results + p2 = (PolicyEntity) resultList.get(0); + }else{ + fail("\nPolicyEntityTest: No PolicyEntity DB entry found"); + } + + logger.debug("\n\n********PolicyEntityTest: PolicyEntity object after retrieving from DB BEFORE assigning configurationData*********" + + "\npolicyId2 = " + p2.getPolicyId() + + "\npolicyName2 = " + p2.getPolicyName() + + "\nversion2 = " + p2.getVersion() + + "\npolicyData2 = " + p2.getPolicyData() + + "\nconfigurationData2 = " + (p2.getConfigurationData()!=null ? "configurationDataId = " + p2.getConfigurationData().getConfigurationDataId() : "configurationData is null") + + "\nactionBody2 = " + (p2.getActionBodyEntity()!=null ? "actionBodyId = " + p2.getActionBodyEntity().getActionBodyId() : "actionBody is null") + + "\nscope2 = " + p2.getScope() + + "\ncreatedBy2 = " + p2.getCreatedBy() + + "\ncreatedDate2 = " + p2.getCreatedDate() + + "\ndescription2 = " + p2.getDescription() + + "\nmodifiedBy2 = " + p2.getModifiedBy() + + "\nmodifiedDate2 = " + p2.getModifiedDate() + + "\ndeleted2 = " + p2.isDeleted()); + + //Confirm that the retrieved policy object is the same as the persisted object + assertSame(p1,p2); + + //Perform configurationData selects + Query query2 = em.createQuery("Select c from ConfigurationDataEntity c where c.configurationDataId=:cid"); + + query2.setParameter("cid", c1.getConfigurationDataId()); + + //Get the database version of the Configuration Data + resultList = query2.getResultList(); + ConfigurationDataEntity c2 = null; + if(!resultList.isEmpty()){ + // ignores multiple results + c2 = (ConfigurationDataEntity) resultList.get(0); + }else{ + fail("\nPolicyEntityTest: No ConfigurationDataEntity DB entry found"); + } + + logger.debug("\n\n********PolicyEntityTest: Configuration object after retrieving from DB BEFORE assigning to policy*********" + + "\nconfigurationDataId2 = " + c2.getConfigurationDataId() + + "\nversion2 = " + c2.getVersion() + + "\nconfigType2 = " + c2.getConfigType() + + "\nconfigBody2 = " + c2.getConfigBody() + + "\ncreatedBy2 = " + c2.getCreatedBy() + + "\ncreatedDate2 = " + c2.getCreatedDate() + + "\ndescription2 = " + c2.getDescription() + + "\nmodifiedBy2 = " + c2.getModifiedBy() + + "\nmodifiedDate2 = " + c2.getModifiedDate() + + "\ndeleted2 = " + c2.isDeleted()); + + //Confirm the retrieved ConfigurationDataEntity object is the same as the persisted + assertSame(c1,c2); + + //Now assign the configurationData to the policy + p1.setConfigurationData(c1); + + //Perform actionBody selects + Query querya2 = em.createQuery("Select a from ActionBodyEntity a where a.actionBodyId=:aid"); + + querya2.setParameter("aid", a1.getActionBodyId()); + + //Get the database version of the Action Body + resultList = querya2.getResultList(); + ActionBodyEntity a2 = null; + if(!resultList.isEmpty()){ + // ignores multiple results + a2 = (ActionBodyEntity) resultList.get(0); + }else{ + fail("\nPolicyEntityTest: No ActionBodyEntity DB entry found"); + } + + + logger.debug("\n\n********PolicyEntityTest: Local Action Body object after retrieving from DB BEFORE assigning to policy *********" + + "\nactionBodyId2 = " + a2.getActionBodyId() + + "\nactionBodyVersion2 = " + a2.getVersion() + + "\nactionBody2 = " + a2.getActionBody() + + "\nactionBodyCeatedBy2 = " + a2.getCreatedBy() + + "\nactionBodyCreatedDate2 = " + a2.getCreatedDate() + + "\nactionBodyModifiedBy2 = " + a2.getModifiedBy() + + "\nactionBodyModifiedDate2 = " + a2.getModifiedDate() + + "\nactionBodyDeleted2 = " + a2.isDeleted()); + + + //Confirm the retrieved ActionBodyEntity object is the same as the persisted + assertSame(a1,a2); + + //Now assign the ActionBodyEntity to the policy + p1.setActionBodyEntity(a1); + + em.flush(); + + //Let's retrieve the policy, configurationData and actionBody from the DB and look at them + //Here is the policy object + resultList = query.getResultList(); + p2 = null; + if(!resultList.isEmpty()){ + // ignores multiple results + p2 = (PolicyEntity) resultList.get(0); + }else{ + fail("PolicyEntityTest: No PolicyEntity DB entry found"); + } + + logger.debug("\n\n********PolicyEntityTest: PolicyEntity object after retrieving from DB AFTER assigning configurationData*********" + + "\npolicyId2 = " + p2.getPolicyId() + + "\npolicyName2 = " + p2.getPolicyName() + + "\nversion2 = " + p2.getVersion() + + "\npolicyData2 = " + p2.getPolicyData() + + "\nconfigurationData2 = " + (p2.getConfigurationData()!=null ? "configurationDataId = " + p2.getConfigurationData().getConfigurationDataId() : "configurationData is null") + + "\nactionBody2 = " + (p2.getActionBodyEntity()!=null ? "actionBodyId = " + p2.getActionBodyEntity().getActionBodyId() : "actionBody is null") + + "\nscope2 = " + p2.getScope() + + "\ncreatedBy2 = " + p2.getCreatedBy() + + "\ncreatedDate2 = " + p2.getCreatedDate() + + "\ndescription2 = " + p2.getDescription() + + "\nmodifiedBy2 = " + p2.getModifiedBy() + + "\nmodifiedDate2 = " + p2.getModifiedDate() + + "\ndeleted2 = " + p2.isDeleted()); + + //And now the ConfigurationDataEntity object + resultList = query2.getResultList(); + c2 = null; + if(!resultList.isEmpty()){ + // ignores multiple results + c2 = (ConfigurationDataEntity) resultList.get(0); + }else{ + fail("\nPolicyEntityTest: No ConfigurationDataEntity DB entry found"); + } + + logger.debug("\n\n********PolicyEntityTest: Configuration object after retrieving from DB AFTER assigning to policy*********" + + "\nconfigurationDataId2 = " + c2.getConfigurationDataId() + + "\nversion2 = " + c2.getVersion() + + "\nconfigType2 = " + c2.getConfigType() + + "\nconfigBody2 = " + c2.getConfigBody() + + "\ncreatedBy2 = " + c2.getCreatedBy() + + "\ncreatedDate2 = " + c2.getCreatedDate() + + "\ndescription2 = " + c2.getDescription() + + "\nmodifiedBy = " + c2.getModifiedBy() + + "\nmodifiedDate = " + c2.getModifiedDate() + + "\ndeleted2 = " + c2.isDeleted()); + + + //Get the database version of the Action Body + resultList = querya2.getResultList(); + a2 = null; + if(!resultList.isEmpty()){ + // ignores multiple results + a2 = (ActionBodyEntity) resultList.get(0); + }else{ + fail("\nPolicyEntityTest: No ActionBodyEntity DB entry found"); + } + + + logger.debug("\n\n********PolicyEntityTest: Local Action Body object after retrieving from DB AFTER assigning to policy *********" + + "\nactionBodyId2 = " + a2.getActionBodyId() + + "\nactionBodyVersion2 = " + a2.getVersion() + + "\nactionBody2 = " + a2.getActionBody() + + "\nactionBodyCeatedBy2 = " + a2.getCreatedBy() + + "\nactionBodyCreatedDate2 = " + a2.getCreatedDate() + + "\nactionBodyModifiedBy2 = " + a2.getModifiedBy() + + "\nactionBodyModifiedDate2 = " + a2.getModifiedDate() + + "\nactionBodyDeleted2 = " + a2.isDeleted()); + + + //****Now lets see if the orphanRemoval=true does anything useful*** + //Remove the configurationData from the policy relationship + + p1.setConfigurationData(null); + + p1.setActionBodyEntity(null); + + //flush the update to the DB + em.flush(); + + //Attempt to retrieve the configuration data object from the db. It should not be there + //Reusing the previous query + resultList = query2.getResultList(); + c2 = null; + if(resultList.isEmpty()){ + logger.debug("\n\n********PolicyEntityTest: orphanRemoval=true******" + + "\n Success!! No ConfigurationDataEntity DB entry found"); + + }else{ + c2 = (ConfigurationDataEntity) resultList.get(0); + fail("\nPolicyEntityTest: ConfigurationDataEntity DB entry found - and none should exist" + + "\nconfigurationDataId = " + c2.getConfigurationDataId()); + } + + //Attempt to retrieve the actionBody data object from the db. It should not be there + //Reusing the previous query + resultList = querya2.getResultList(); + a2 = null; + if(resultList.isEmpty()){ + logger.debug("\n\n********PolicyEntityTest: orphanRemoval=true******" + + "\n Success!! No ActionBodyEntity DB entry found"); + + }else{ + a2 = (ActionBodyEntity) resultList.get(0); + fail("\nPolicyEntityTest: ActionBodyEntity DB entry found - and none should exist" + + "\nactionBodyId = " + a2.getActionBodyId()); + } + + //Now lets put the configurationData and actionBody back into the policy object and see what appears + //in the DB after a flush + + //put c1 back into the persistence context since the orphanRemoval removed it. + em.persist(c1); + p1.setConfigurationData(c1); + + em.persist(a1); + p1.setActionBodyEntity(a1); + + em.flush(); + + //retrieve the policy object + resultList = query.getResultList(); + p2 = null; + if(!resultList.isEmpty()){ + // ignores multiple results + p2 = (PolicyEntity) resultList.get(0); + }else{ + fail("\nPolicyEntityTest: No PolicyEntity DB entry found"); + } + + //output what we policy object found + logger.debug("\n\n********PolicyEntityTest: PolicyEntity object after again adding ConfigurationDataEntity and retrieving from DB*********" + + "\npolicyId2 = " + p2.getPolicyId() + + "\npolicyName2 = " + p2.getPolicyName() + + "\nversion2 = " + p2.getVersion() + + "\npolicyData2 = " + p2.getPolicyData() + + "\nconfigurationData2 = " + (p2.getConfigurationData()!=null ? "configurationDataId = " + p2.getConfigurationData().getConfigurationDataId() : "configurationData is null") + + "\nactionBody2 = " + (p2.getActionBodyEntity()!=null ? "actionBodyId = " + p2.getActionBodyEntity().getActionBodyId() : "actionBody is null") + + "\nscope2 = " + p2.getScope() + + "\ncreatedBy2 = " + p2.getCreatedBy() + + "\ncreatedDate2 = " + p2.getCreatedDate() + + "\ndescription2 = " + p2.getDescription() + + "\nmodifiedBy2 = " + p2.getModifiedBy() + + "\nmodifiedDate2 = " + p2.getModifiedDate() + + "\ndeleted2 = " + p2.isDeleted()); + + + //now lets see if it put the configurationData c1 back into the table + resultList = query2.getResultList(); + c2 = null; + if(!resultList.isEmpty()){ + // ignores multiple results + c2 = (ConfigurationDataEntity) resultList.get(0); + }else{ + fail("\nPolicyEntityTest - Check re-entry of configurationData into DB" + + "No ConfigurationDataEntity DB entry found"); + } + + //output what configurationData object we found + logger.debug("\n\n********PolicyEntityTest: Configuration object after re-enter into policy object and retrieving from DB *********" + + "\nconfigurationDataId2 = " + c2.getConfigurationDataId() + + "\nversion2 = " + c2.getVersion() + + "\nconfigType2 = " + c2.getConfigType() + + "\nconfigBody2 = " + c2.getConfigBody() + + "\ncreatedBy2 = " + c2.getCreatedBy() + + "\ncreatedDate2 = " + c2.getCreatedDate() + + "\ndescription2 = " + c2.getDescription() + + "\nmodifiedBy = " + c2.getModifiedBy() + + "\nmodifiedDate = " + c2.getModifiedDate() + + "\ndeleted2 = " + c2.isDeleted()); + + //now lets see if it put the actionBody a1 back into the table + //Get the database version of the Action Body + resultList = querya2.getResultList(); + a2 = null; + if(!resultList.isEmpty()){ + // ignores multiple results + a2 = (ActionBodyEntity) resultList.get(0); + }else{ + fail("\nPolicyEntityTest - Check re-entry of actionBody into DB" + + "No ActionBodyEntity DB entry found"); + } + + logger.debug("\n\n********PolicyEntityTest: Local Action Body object after re-enter into policy object and retrieving from DB *********" + + "\nactionBodyId2 = " + a2.getActionBodyId() + + "\nactionBodyVersion2 = " + a2.getVersion() + + "\nactionBody2 = " + a2.getActionBody() + + "\nactionBodyCeatedBy2 = " + a2.getCreatedBy() + + "\nactionBodyCreatedDate2 = " + a2.getCreatedDate() + + "\nactionBodyModifiedBy2 = " + a2.getModifiedBy() + + "\nactionBodyModifiedDate2 = " + a2.getModifiedDate() + + "\nactionBodyDeleted2 = " + a2.isDeleted()); + + //I want to save all the above in the DB + try{ + et.commit(); + logger.debug("\n\n***********PolicyEntityTest: et.commit Succeeded********"); + }catch(Exception e){ + logger.debug("\n\n***********PolicyEntityTest: et.commit Failed********" + + "\nTRANSACTION ROLLBACK " + + "\n with exception: " + e); + } + + // Start a new transaction + EntityTransaction et2 = em.getTransaction(); + + et2.begin(); + + //Let's test if the PolicyEntity uniqueConstraint for policyName and scopeId hold + PolicyEntity p3 = new PolicyEntity(); + em.persist(p3); + + + //first let's assure that you can save with the same name but a different scope + p3.setPolicyName(p1.getPolicyName()); + p3.setScope("mckiou.kevin.kory"); + em.flush(); + logger.debug("\n\n***********PolicyEntityTest: PolicyEntity Unique test for policyName and scope********" + + "\nSuccess! PolicyEntity uniqueness constraint allowed " + + "\n policyId1 " + p1.getPolicyId() + + "\n policyName1 " + p1.getPolicyName() + + "\n scope1 = " + p1.getScope() + + "\n policyId3 " + p3.getPolicyId() + + "\n policyName3 " + p3.getPolicyName() + + "\n scope3 = " + p3.getScope()); + + //Assert that the policyIds are NOT the same to show that the automatic sequencing is working + assert(p1.getPolicyId() != p3.getPolicyId()); + + try{ + //Now set the scope the same to verify the uniqueness constraint will be enforced + p3.setScope(p1.getScope()); + + em.flush(); + fail("\n\n***********PolicyEntityTest: PolicyEntity Unique test for policyName and scope********" + + "\nFailed! PolicyEntity Uniqueness constraint FAILED and DID allow " + + "\n policyId1 " + p1.getPolicyId() + + "\n policyName1 " + p1.getPolicyName() + + "\n scope1 = " + p1.getScope() + + "\n policyId3 " + p3.getPolicyId() + + "\n policyName3 " + p3.getPolicyName() + + "\n scope3 = " + p3.getScope());; + } + catch(Exception e){ + //Success + logger.debug("\n\n***********PolicyEntityTest: PolicyEntity Unique test for policyName and scope********" + + "\nSuccess! PolicyEntity Uniqueness constraint SUCCEEDED and did NOT allow " + + "\n policyId1 " + p1.getPolicyId() + + "\n policyName1 " + p1.getPolicyName() + + "\n scope1 = " + p1.getScope() + + "\n policyId3 " + p3.getPolicyId() + + "\n policyName3 " + p3.getPolicyName() + + "\n scope3 = " + p3.getScope() + + "\n with excpetion: " + e); + } + + + try{ + et2.commit(); + logger.debug("\n\n***********PolicyEntityTest: et2.commit Succeeded********"); + }catch(Exception e){ + logger.debug("\n\n***********PolicyEntityTest: et2.commit Failed********" + + "\nTRANSACTION ROLLBACK " + + "\n with exception: " + e); + } + + //****************Test the PolicyDBDaoEntity************************ + + //Create a transaction + EntityTransaction et3 = em.getTransaction(); + + et3.begin(); + + //create one + PolicyDBDaoEntity pe1 = new PolicyDBDaoEntity(); + em.persist(pe1); + + pe1.setDescription("This is pe1"); + + pe1.setPolicyDBDaoUrl("http://10.11.12.13:2345"); + + //push it to the DB + em.flush(); + + //create another + PolicyDBDaoEntity pe2 = new PolicyDBDaoEntity(); + em.persist(pe2); + + pe2.setDescription("This is pe2"); + + pe2.setPolicyDBDaoUrl("http://10.11.12.13:2345"); + + //Print them to the log before flushing + logger.debug("\n\n***********PolicyEntityTest: PolicyDBDaoEntity objects before flush********" + + "\n policyDBDaoUrl-1 = " + pe1.getPolicyDBDaoUrl() + + "\n description-1 = " + pe1.getDescription() + + "\n createdDate-1 = " + pe1.getCreatedDate() + + "\n modifiedDate-1 " + pe1.getModifiedDate() + + "\n*****************************************" + + "\n policyDBDaoUrl-2 = " + pe2.getPolicyDBDaoUrl() + + "\n description-2 = " + pe2.getDescription() + + "\n createdDate-2 = " + pe2.getCreatedDate() + + "\n modifiedDate-2 " + pe2.getModifiedDate() + ); + + //push it to the DB + em.flush(); + + //Now let's retrieve them from the DB using the named query + + resultList = em.createNamedQuery("PolicyDBDaoEntity.findAll").getResultList(); + + PolicyDBDaoEntity pex = null; + PolicyDBDaoEntity pey = null; + + if(!resultList.isEmpty()){ + if (resultList.size() != 2){ + fail("\nPolicyEntityTest: Number of PolicyDBDaoEntity entries = " + resultList.size() + " instead of 2"); + } + for(Object policyDBDaoEntity: resultList){ + PolicyDBDaoEntity pdbdao = (PolicyDBDaoEntity)policyDBDaoEntity; + if(pdbdao.getPolicyDBDaoUrl().equals("http://10.11.12.13:2345")){ + pex = pdbdao; + }else if(pdbdao.getPolicyDBDaoUrl().equals("http://10.11.12.13:2345")){ + pey = pdbdao; + } + } + + //Print them to the log before flushing + logger.debug("\n\n***********PolicyEntityTest: PolicyDBDaoEntity objects retrieved from DB********" + + "\n policyDBDaoUrl-x = " + pex.getPolicyDBDaoUrl() + + "\n description-x = " + pex.getDescription() + + "\n createdDate-x = " + pex.getCreatedDate() + + "\n modifiedDate-x " + pex.getModifiedDate() + + "\n*****************************************" + + "\n policyDBDaoUrl-y = " + pey.getPolicyDBDaoUrl() + + "\n description-y = " + pey.getDescription() + + "\n createdDate-y = " + pey.getCreatedDate() + + "\n modifiedDate-y " + pey.getModifiedDate() + ); + //Verify the retrieved objects are the same as the ones we stored in the DB + if(pex.getPolicyDBDaoUrl().equals("http://10.11.12.13:2345")){ + assertSame(pe1,pex); + assertSame(pe2,pey); + }else{ + assertSame(pe2,pex); + assertSame(pe1,pey); + } + + }else{ + fail("\nPolicyEntityTest: No PolicyDBDaoEntity DB entry found"); + } + + //Now let's see if we can do an update on the PolicyDBDaoEntity which we retrieved. + //em.persist(pex); + pex.setDescription("This is pex"); + em.flush(); + + //retrieve it + Query createPolicyQuery = em.createQuery("SELECT p FROM PolicyDBDaoEntity p WHERE p.description=:desc"); + resultList = createPolicyQuery.setParameter("desc", "This is pex").getResultList(); + + PolicyDBDaoEntity pez = null; + + if(!resultList.isEmpty()){ + if (resultList.size() != 1){ + fail("\nPolicyEntityTest: Update Test - Number of PolicyDBDaoEntity entries = " + resultList.size() + " instead of 1"); + } + pez = (PolicyDBDaoEntity) resultList.get(0); + + //Print them to the log before flushing + logger.debug("\n\n***********PolicyEntityTest: Update Test - PolicyDBDaoEntity objects retrieved from DB********" + + "\n policyDBDaoUrl-x = " + pex.getPolicyDBDaoUrl() + + "\n description-x = " + pex.getDescription() + + "\n createdDate-x = " + pex.getCreatedDate() + + "\n modifiedDate-x " + pex.getModifiedDate() + + "\n*****************************************" + + "\n policyDBDaoUrl-z = " + pez.getPolicyDBDaoUrl() + + "\n description-z = " + pez.getDescription() + + "\n createdDate-z = " + pez.getCreatedDate() + + "\n modifiedDate-z " + pez.getModifiedDate() + ); + //Verify the retrieved objects are the same as the ones we stored in the DB + assertSame(pex,pez); + }else{ + fail("\nPolicyEntityTest: Update Test - No PolicyDBDaoEntity DB updated entry found"); + } + + //Clean up the DB + em.createQuery("DELETE FROM PolicyDBDaoEntity").executeUpdate(); + em.createQuery("DELETE FROM PolicyEntity").executeUpdate(); + em.createQuery("DELETE FROM ConfigurationDataEntity").executeUpdate(); + em.createQuery("DELETE FROM ActionBodyEntity").executeUpdate(); + + //Wrap up the transaction + try{ + et3.commit(); + logger.debug("\n\n***********PolicyEntityTest: et3.commit Succeeded********"); + }catch(Exception e){ + logger.debug("\n\n***********PolicyEntityTest: et3.commit Failed********" + + "\nTRANSACTION ROLLBACK " + + "\n with exception: " + e); + } + + + //Tidy up + em.close(); + } + +} diff --git a/ECOMP-PAP-REST/test.properties b/ECOMP-PAP-REST/test.properties new file mode 100644 index 000000000..a459f3e25 --- /dev/null +++ b/ECOMP-PAP-REST/test.properties @@ -0,0 +1,22 @@ +### +# ============LICENSE_START======================================================= +# ECOMP-PAP-REST +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +PDP_URL=http://localhost:9091/pdp/, testpdp, alpha456 +#PAP_URL=http://localhost:8070/pap/, testpap, alpha123 diff --git a/ECOMP-PAP-REST/xacml.pap.properties b/ECOMP-PAP-REST/xacml.pap.properties new file mode 100644 index 000000000..91e393de5 --- /dev/null +++ b/ECOMP-PAP-REST/xacml.pap.properties @@ -0,0 +1,155 @@ +### +# ============LICENSE_START======================================================= +# ECOMP-PAP-REST +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +# +# This is our factory that will create our engine +# +xacml.PAP.papEngineFactory=org.openecomp.policy.xacml.std.pap.StdEngineFactory + +# +# Where we store our PAP PDP Group/Node information +# +xacml.pap.pdps=pdps +# +# Need the PAP's url (how PDPs will reach it) configured here +# because we need it to generate the URLs of the Policy Files +# sent to the PDPs in the configuration when the PAP is first brought up. +# (In other cases, such as the PDP calling the PAP, we could generate this URL, +# but for startup there is no other way to get it.) +# +# + +xacml.rest.pap.url=http://localhost:8070/pap/ + +# +# Upon startup, have the PAP servlet send latest configuration information to all +# the PDP nodes it knows about. +# +xacml.rest.pap.initiate.pdp=true +# +# Heartbeat from PAP to PDPs +# +# How much time (in milliseconds) between heartbeats +# (i.e. the time between completing the heartbeat with all PDPs and starting the next cycle) +# +xacml.rest.pap.heartbeat.interval=100000 +# +# Heartbeat connection timeout (in milliseconds) +# +xacml.rest.pap.heartbeat.timeout=100000 + +################################################################################################ +# Adding properties for getting properties previously used by PAP-ADMIN for creating Policies +# THis is part of the Policy Creation API project +################################################################################################ + +# Set your domain here: +xacml.rest.pap.domain=com + +# Location where all the user workspaces are located. +xacml.rest.pap.workspace=workspace + +# Location where the GIT repository is located +xacml.rest.pap.repository=repository + +# new Property Please mention your PAP-REST webapps Location here. +xacml.rest.config.webapps=C:\\Second Tomcat\\apache-tomcat-8.0.23\\webapps\\ConfigPAP\\ + +#Turn the audit on to synchronize the DB/file system +#xacml.rest.pap.run.audit.flag=true +#Turn the audit off to not synchronize the DB/file system +#xacml.rest.pap.run.audit.flag=false +xacml.rest.pap.run.audit.flag=false + +#Audit will synchronize the file system to match the contents of the DB +#xacml.rest.pap.filesystem.audit=true +#Audit will synchronize the DB to match the contents of the file system +#xacml.rest.pap.filesystem.audit=false +xacml.rest.pap.filesystem.audit=false +xacm.xcor.required.pattern=1,1 +# id +xacml.rest.pap.userid=testpap +# pass +xacml.rest.pap.password=alpha123 +# pdps file +xacml.rest.pdp.idfile=test.properties + + +#properties for MySql xacml database: PLEASE DO NOT REMOVE... NEEDED FOR APIs +javax.persistence.jdbc.driver=com.mysql.jdbc.Driver +javax.persistence.jdbc.url=jdbc:mysql://localhost:3306/ecomp_sdk +javax.persistence.jdbc.user=root +javax.persistence.jdbc.password= + +#Time in ms which a Policy DB transaction will wait to get the transaction lock object +xacml.rest.pap.transaction.waitms=500000 + +#Policy DB transaction timeout in ms after it has obtained the transaction lock object +xacml.rest.pap.transaction.timeoutms=500000 + +#Policy Audit timeout in ms after it has obtained the transaction lock object +xacml.rest.pap.audit.timeoutms=500000 + +#controls how long the pap will wait before giving up when sending notifications to other paps +xacml.rest.pap.notify.timeoutms=10000 + +#AutoPush Policy Flag +xacml.rest.pap.autopush.flag=false +#AutoPush Policy +xacml.rest.pap.autopush.file=autopush.properties + +#***Properties for IntegrityMonitor integration defined in XACMLRestProperties.java*** + +#The name of the PAP. Must be unique across the system +xacml.rest.pap.resource.name=site_1.pap_1 + +#***Properties for IntegrityMonitor integration defined in IntegrityMonitorProperties.java*** + +#Interval between forward progress counter updates in seconds +fp_monitor_interval=30 + +#Number of forward progress counter failures before failover +failed_counter_threshold=3 + +#Interval in seconds between test transactions if there is no other traffic +test_trans_interval=10 + +#Interval in seconds between updates of the forward progress counter in the DB +write_fpc_interval=5 + +#Name of the site +site_name=site_1 + +#Node type. Can take values of: pdp-xacml, pdp-drools, pap, pap-admin, logparser, brms-gateway, +#astra-gateway, elk-server and pypdp +node_type=pap + +#Dependency groups are groups of resources upon which a node operational state is dependent upon (dependency_groups). +#Each group is a comma-separated list of resource names and groups are separated by a semicolon. A group may contain +#one or more members. +dependency_groups=site_1.logparser_1;site_1.adminconsole_1;site_1.elk_1 + +# The (optional) period of time in seconds between executions of the integrity audit. +# Value < 0 : Audit does not run (default value if property is not present = -1) +# Value = 0 : Audit runs continuously +# Value > 0 : The period of time in seconds between execution of the audit on a particular node +integrity_audit_period_seconds=-1 + +ENVIRONMENT=DEVL diff --git a/ECOMP-PAP-REST/xacml.pap.test.properties b/ECOMP-PAP-REST/xacml.pap.test.properties new file mode 100644 index 000000000..78a2c4031 --- /dev/null +++ b/ECOMP-PAP-REST/xacml.pap.test.properties @@ -0,0 +1,151 @@ +### +# ============LICENSE_START======================================================= +# ECOMP-PAP-REST +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +# +# This is our factory that will create our engine +# +xacml.PAP.papEngineFactory=org.openecomp.policy.xacml.std.pap.StdEngineFactory + +# +# Where we store our PAP PDP Group/Node information +# +xacml.pap.pdps=pdps +# +# Need the PAP's url (how PDPs will reach it) configured here +# because we need it to generate the URLs of the Policy Files +# sent to the PDPs in the configuration when the PAP is first brought up. +# (In other cases, such as the PDP calling the PAP, we could generate this URL, +# but for startup there is no other way to get it.) +# +# + +xacml.rest.pap.url=http://localhost:8070/pap/ + +# +# Upon startup, have the PAP servlet send latest configuration information to all +# the PDP nodes it knows about. +# +xacml.rest.pap.initiate.pdp=true +# +# Heartbeat from PAP to PDPs +# +# How much time (in milliseconds) between heartbeats +# (i.e. the time between completing the heartbeat with all PDPs and starting the next cycle) +# +xacml.rest.pap.heartbeat.interval=10000 +# +# Heartbeat connection timeout (in milliseconds) +# +xacml.rest.pap.heartbeat.timeout=10000 + +################################################################################################ +# Adding properties for getting properties previously used by PAP-ADMIN for creating Policies +# THis is part of the Policy Creation API project +################################################################################################ + +# Set your domain here: +xacml.rest.pap.domain=com + +# Location where all the user workspaces are located. +xacml.rest.pap.workspace=workspace + +# Location where the GIT repository is located +xacml.rest.pap.repository=repository + +# new Property Please mention your PAP-REST webapps Location here. +xacml.rest.config.webapps=C:\\Second Tomcat\\apache-tomcat-8.0.23\\webapps\\ConfigPAP\\ + +#Turn the audit on to synchronize the DB/file system +#xacml.rest.pap.run.audit.flag=true +#Turn the audit off to not synchronize the DB/file system +#xacml.rest.pap.run.audit.flag=false +xacml.rest.pap.run.audit.flag=false + +#Audit will synchronize the file system to match the contents of the DB +#xacml.rest.pap.filesystem.audit=true +#Audit will synchronize the DB to match the contents of the file system +#xacml.rest.pap.filesystem.audit=false +xacml.rest.pap.filesystem.audit=false + +# id +xacml.rest.pap.userid=testpap +# pass +xacml.rest.pap.password=alpha123 +# pdps file +xacml.rest.pdp.idfile=test.properties + +#Properties for db access +javax.persistence.jdbc.driver=org.h2.Driver +#javax.persistence.jdbc.url=jdbc:h2:tcp://localhost/xacmlpolicy +javax.persistence.jdbc.url=jdbc:h2:file:./sql/xacmlTest +javax.persistence.jdbc.user=sa +javax.persistence.jdbc.password= + +#Time in ms which a Policy DB transaction will wait to get the transaction lock object +xacml.rest.pap.transaction.waitms=1000 + +#Policy DB transaction timeout in ms after it has obtained the transaction lock object +xacml.rest.pap.transaction.timeoutms=500 + +#Policy Audit timeout in ms after it has obtained the transaction lock object +xacml.rest.pap.audit.timeoutms=5000 + +#***Properties for IntegrityMonitor integration defined in IntegrityMonitorProperties.java*** + +#JMX URL for the PAP-REST. Need to update to real IP and port +xacml.rest.pap.jmx.url=service:jmx:rmi:///jndi/rmi://localhost:9990/jmxrmi + +#The name of the PAP. Must be unique across the system +xacml.rest.pap.resource.name=site_1.pap_1 + +#***Properties for IntegrityMonitor integration defined in IntegrityMonitorProperties.java*** + +#Interval between forward progress counter updates in seconds +fp_monitor_interval=30 + +#Number of forward progress counter failures before failover +failed_counter_threshold=3 + +#Interval in seconds between test transactions if there is no other traffic +test_trans_interval=10 + +#Interval in seconds between updates of the forward progress counter in the DB +write_fpc_interval=5 + +#Name of the site +site_name=site_1 + +#Node type. Can take values of: pdp-xacml, pdp-drools, pap, pap-admin, logparser, brms-gateway, +#astra-gateway, elk-server and pypdp +node_type=pap + +#Dependency groups are groups of resources upon which a node operational state is dependent upon (dependency_groups). +#Each group is a comma-separated list of resource names and groups are separated by a semicolon. A group may contain +#one or more members. +dependency_groups=site_1.logparser_1;site_1.adminconsole_1;site_1.elk_1 + +# The (optional) period of time in seconds between executions of the integrity audit. +# Value < 0 : Audit does not run (default value if property is not present = -1) +# Value = 0 : Audit runs continuously +# Value > 0 : The period of time in seconds between execution of the audit on a particular node +#integrity_audit_period_seconds=-1 +integrity_audit_period_seconds=0 + +ENVIRONMENT=DEVL diff --git a/ECOMP-PDP-REST/.gitignore b/ECOMP-PDP-REST/.gitignore new file mode 100644 index 000000000..b49c56399 --- /dev/null +++ b/ECOMP-PDP-REST/.gitignore @@ -0,0 +1,4 @@ +/target/ +/target/ +/target/ +/target/ diff --git a/ECOMP-PDP-REST/WebContent/META-INF/MANIFEST.MF b/ECOMP-PDP-REST/WebContent/META-INF/MANIFEST.MF new file mode 100644 index 000000000..59499bce4 --- /dev/null +++ b/ECOMP-PDP-REST/WebContent/META-INF/MANIFEST.MF @@ -0,0 +1,2 @@ +Manifest-Version: 1.0 + diff --git a/ECOMP-PDP-REST/WebContent/WEB-INF/.gitignore b/ECOMP-PDP-REST/WebContent/WEB-INF/.gitignore new file mode 100644 index 000000000..840e7d312 --- /dev/null +++ b/ECOMP-PDP-REST/WebContent/WEB-INF/.gitignore @@ -0,0 +1 @@ +/classes/ diff --git a/ECOMP-PDP-REST/config_testing/xacml.pip.properties b/ECOMP-PDP-REST/config_testing/xacml.pip.properties new file mode 100644 index 000000000..32fe6de0d --- /dev/null +++ b/ECOMP-PDP-REST/config_testing/xacml.pip.properties @@ -0,0 +1,23 @@ +### +# ============LICENSE_START======================================================= +# ECOMP-PDP-REST +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +# PIP Engine Definition +# +xacml.pip.engines= diff --git a/ECOMP-PDP-REST/config_testing/xacml.policy.properties b/ECOMP-PDP-REST/config_testing/xacml.policy.properties new file mode 100644 index 000000000..c8418b3f8 --- /dev/null +++ b/ECOMP-PDP-REST/config_testing/xacml.policy.properties @@ -0,0 +1,24 @@ +### +# ============LICENSE_START======================================================= +# ECOMP-PDP-REST +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +# Policies to load +# +xacml.rootPolicies=useCase +useCase.file=config_testing\\test_PolicyEngine.xml diff --git a/ECOMP-PDP-REST/policyLogger.properties b/ECOMP-PDP-REST/policyLogger.properties new file mode 100644 index 000000000..d4e9525b8 --- /dev/null +++ b/ECOMP-PDP-REST/policyLogger.properties @@ -0,0 +1,44 @@ +### +# ============LICENSE_START======================================================= +# ECOMP-PDP-REST +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +################################### Set concurrentHashMap and timer info ####################### +#Timer initial delay and the delay between in milliseconds before task is to be execute. +timer.delay.time=1000 +#Timer scheduleAtFixedRate period - time in milliseconds between successive task executions. +check.interval= 30000 +#Longest time an event info can be stored in the concurrentHashMap for logging - in seconds. +event.expired.time=86400 +#Size of the concurrentHashMap which stores the event starting time, etc - when its size reaches this limit, the Timer gets executed +#to remove all expired records from this concurrentHashMap. +concurrentHashMap.limit=5000 +#Size of the concurrentHashMap - when its size drops to this point, stop the Timer +stop.check.point=2500 +################################### Set logging format ############################################# +# set EELF for EELF logging format, set LOG4J for using log4j, set SYSTEMOUT for using system.out.println +logger.type=EELF +#################################### Set level for EELF or SYSTEMOUT logging ################################## +# Set level for debug file. Set DEBUG to enable .info, .warn and .debug; set INFO for enable .info and .warn; set OFF to disable all +debugLogger.level=INFO +# Set level for metrics file. Set OFF to disable; set ON to enable +metricsLogger.level=ON +# Set level for error file. Set OFF to disable; set ON to enable +error.level=ON +# Set level for audit file. Set OFF to disable; set ON to enable +audit.level=ON diff --git a/ECOMP-PDP-REST/pom.xml b/ECOMP-PDP-REST/pom.xml new file mode 100644 index 000000000..b029df22f --- /dev/null +++ b/ECOMP-PDP-REST/pom.xml @@ -0,0 +1,206 @@ + + + + + + + 4.0.0 + + + org.openecomp.policy.engine + PolicyEngineSuite + 1.0.0-SNAPSHOT + + + org.openecomp.policy.engine + ECOMP-PDP-REST + + ECOMP PDP REST + + war + + + + maven-war-plugin + 2.1 + + true + + + + + + + + org.openecomp.policy.engine + ECOMP-PDP + ${project.version} + + + org.openecomp.policy.common + ECOMP-Logging + ${common-modules.version} + + + javax.servlet + javax.servlet-api + 3.1.0 + + + commons-logging + commons-logging + 1.1.3 + + + javax.servlet + servlet-api + + + + + log4j + apache-log4j-extras + 1.2.17 + + + commons-io + commons-io + 2.4 + + + org.apache.httpcomponents + httpclient + 4.3.1 + + + com.google.guava + guava + 14.0.1 + + + com.fasterxml.jackson.core + jackson-databind + 2.3.0-rc1 + + + mysql + mysql-connector-java + 5.1.30 + + + org.mariadb.jdbc + mariadb-java-client + 1.2.3 + + + postgresql + postgresql + 9.1-901.jdbc4 + + + org.hsqldb + hsqldb + 2.3.2 + + + com.sun.jersey + jersey-client + 1.18 + + + com.sun.jersey + jersey-core + 1.18 + + + javax.websocket + javax.websocket-api + 1.1 + provided + + + + com.att.nsa + cambriaClient + 0.0.1 + + + slf4j-log4j12 + org.slf4j + + + + + org.mockito + mockito-core + 1.9.5 + + + org.springframework + spring-mock + 2.0.8 + + + com.mockrunner + mockrunner + 0.3.1 + + + javax.servlet + javax.servlet-api + 3.0.1 + provided + + + junit + junit + 4.11 + test + + + org.powermock + powermock-api-mockito + 1.5.6 + + + org.powermock + powermock-module-junit4 + 1.5.6 + + + diff --git a/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/PapUrlResolver.java b/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/PapUrlResolver.java new file mode 100644 index 000000000..d9a3688b4 --- /dev/null +++ b/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/PapUrlResolver.java @@ -0,0 +1,387 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.rest; + +import java.net.URI; +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.NoSuchElementException; +import java.util.Properties; + +import org.openecomp.policy.rest.XACMLRestProperties; + +import com.att.research.xacml.util.XACMLProperties; + +import org.openecomp.policy.common.logging.flexlogger.*; + +public class PapUrlResolver { + private static final Logger logger = FlexLogger.getLogger(PapUrlResolver.class); + //how long to keep a pap failed before making it un-failed, in milli-seconds + private static final long FAIL_TIMEOUT = 18000000; + + //thread locks + public static Object propertyLock = new Object(); + + public static void setPapUrls(String[] papUrls){ + + } + //keeping this here for backward compatibility + public static String extractIdFromUrl(String url){ + return extractQuery(url); + } + public static String extractQuery(String url){ + try{ + return URI.create(url).getQuery(); + } catch(Exception e){ + return ""; + } + } + public static String modifyUrl(String idUrl, String serverUrl){ + URI one = URI.create(idUrl); + String host = one.getPath()+one.getQuery(); + URI two = URI.create(serverUrl); + two.resolve(host); + return two.toString(); + } + + //get an instance of a new PapUrlResolver, using XACMLProperties to get the url lists + public static PapUrlResolver getInstance(){ + return new PapUrlResolver(null,null,null,true); + } + + //get an instance of a new PapUrlResolver, using the provides strings for the url lists + public static PapUrlResolver getInstance(String urlList, String failedList, String succeededList){ + return new PapUrlResolver(urlList, failedList, succeededList,false); + } + + //keeps track of our current location in the list of urls, allows for iterating + private int pointer; + + //should the XACML property lists be updated after anything changes or should we wait for the update + //method to be called. + private boolean autoUpdateProperties; + + //this list keeps the sorted, priority of PAP URLs + private PapUrlNode[] sortedUrlNodes; + //this list keeps the original list of nodes so that they can be entered into the property list correctly + private PapUrlNode[] originalUrlNodes; + + //private constructor to make an instance of a PapUrlResolver, called by static method getInstance. + //If the list property strings are not defined, we get the values from XACMLProperties. + //The instance acts as an iterator, with hasNext and next methods, but does not implement Iterable, + //because it is used for a difference purpose. + private PapUrlResolver(String urlList, String failedList, String succeededList, boolean autoUpdateProperties){ + this.autoUpdateProperties = autoUpdateProperties; + //synchronized(propertyLock){ + if(urlList == null){ + urlList = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_URLS); + if(urlList == null){ + urlList = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_URL); + } + failedList = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_FAILED_URLS); + succeededList = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_SUCCEEDED_URLS); + } + //} + String[] urls = urlList.split(","); + if(urls.length == 0){ + //log error + } + String[] failed = emptyOrSplit(failedList,urls.length); + String[] succeeded = emptyOrSplit(succeededList,urls.length); + + sortedUrlNodes = new PapUrlNode[urls.length]; + for(int i=0;i { + private String papUrl; + private Date failedTime; + private Date succeededTime; + private String userId; + private String pass; + + public PapUrlNode(String url){ + this.papUrl = url; + failedTime = null; + this.succeededTime = null; + this.userId = ""; + this.pass = ""; + + } + public PapUrlNode(String url,String userId,String pass){ + this.papUrl = url; + failedTime = null; + this.succeededTime = null; + this.userId = userId; + this.pass = pass; + + } + public String getUserId(){ + return this.userId; + } + public String getPass(){ + return this.pass; + } + + public void setFailedTime(Object time){ + Date failedTimeAsDate = setHandler(time); + if(failedTimeAsDate == null){ + this.failedTime = null; + } else { + long timeDifference = new Date().getTime() - failedTimeAsDate.getTime(); + if(timeDifference < FAIL_TIMEOUT){ + this.failedTime = failedTimeAsDate; + } else { + this.failedTime = null; + } + } + } + + //set the time that this url succeeded at + public void setSucceededTime(Object time){ + this.succeededTime = setHandler(time); + } + + //parses string into a date or a null date, if the url never failed/succeeded (since -1 will be in the property) + private Date setHandler(Object time){ + if(time instanceof String){ + if(((String)time).equals("-1")){ + return null; + } + try { + DateFormat df = new SimpleDateFormat(); + Date parsedTime = df.parse((String)time); + return parsedTime; + } catch (ParseException e) { + return null; + } + } + if(time instanceof Date){ + return (Date)time; + } + return null; + } + + + public String getFailedTime(){ + return formatTime(this.failedTime); + } + + public String getSucceededTime(){ + return formatTime(this.succeededTime); + } + + //formats a Date into a string or a -1 if there is not date (-1 is used in properties for no date) + private String formatTime(Date d){ + if(d == null){ + return "-1"; + } + DateFormat df = new SimpleDateFormat(); + return df.format(d); + } + + public String getUrl(){ + return papUrl; + } + + public int compareTo(PapUrlNode other){ + if(this.failedTime == null && other.failedTime != null){ + return -1; + } + if(this.failedTime != null && other.failedTime == null){ + return 1; + } + if(this.failedTime != null){ + return this.failedTime.compareTo(other.failedTime); + } + return 0; + } + } +} diff --git a/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/XACMLPdpLoader.java b/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/XACMLPdpLoader.java new file mode 100644 index 000000000..9c5b120c3 --- /dev/null +++ b/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/XACMLPdpLoader.java @@ -0,0 +1,695 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.rest; + +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URL; +import java.net.URLConnection; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Base64; +import java.util.ConcurrentModificationException; +import java.util.HashMap; +import java.util.Properties; +import java.util.Set; + +import org.apache.commons.io.IOUtils; +import org.openecomp.policy.pdp.rest.notifications.NotificationController; +import org.openecomp.policy.rest.XACMLRest; +import org.openecomp.policy.rest.XACMLRestProperties; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; +import com.att.research.xacml.api.pap.PAPException; +import com.att.research.xacml.api.pap.PDPStatus; +import com.att.research.xacml.api.pap.PDPStatus.Status; +import com.att.research.xacml.api.pdp.PDPEngine; +import com.att.research.xacml.api.pdp.PDPEngineFactory; +import com.att.research.xacml.api.pip.PIPEngine; +import com.att.research.xacml.api.pip.PIPException; +import com.att.research.xacml.api.pip.PIPFinder; +import com.att.research.xacml.api.pip.PIPFinderFactory; +import org.openecomp.policy.xacml.std.pap.StdPDPPIPConfig; +import org.openecomp.policy.xacml.std.pap.StdPDPPolicy; +import org.openecomp.policy.xacml.std.pap.StdPDPStatus; +import com.att.research.xacml.util.FactoryException; +import com.att.research.xacml.util.XACMLProperties; +import com.att.research.xacmlatt.pdp.policy.PolicyDef; +import com.att.research.xacmlatt.pdp.policy.dom.DOMPolicyDef; +import com.att.research.xacmlatt.pdp.std.StdPolicyFinderFactory; +import com.google.common.base.Splitter; + +/** + * Does the work for loading policy and PIP configurations sent from the PAP + * servlet. + * + * + * + */ +public class XACMLPdpLoader { + private static final Logger logger = FlexLogger.getLogger(XACMLPdpLoader.class); + private static NotificationController notificationController = new NotificationController(); + private static final Long notifyDelay = (long) XACMLPdpServlet.getNotificationDelay(); + + + public static synchronized PDPEngine loadEngine(StdPDPStatus status, + Properties policyProperties, Properties pipProperties) { + logger.info("loadEngine: " + policyProperties + " " + pipProperties); + // + // First load our policies + // + try { + // + // Were we given some properties? + // + if (policyProperties == null) { + // + // On init we have no incoming configuration, so just + // Load our current saved configuration + // + policyProperties = new Properties(); + try (InputStream is = Files.newInputStream(getPDPPolicyCache())) { + policyProperties.load(is); + } + } + + // + // Get our policy cache up-to-date + // + // Side effects of this include: + // - downloading of policies from remote locations, and + // - creating new ".file" properties for files existing + // local + // + XACMLPdpLoader.cachePolicies(policyProperties); + // + // Validate the policies + // + XACMLPdpLoader.validatePolicies(policyProperties, status); + if (logger.isDebugEnabled()) { + logger.debug("Status: " + status); + } + } catch (ConcurrentModificationException e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e.getMessage()); + // TODO:EELF Cleanup - Remove logger + //PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, ""); + } catch (Exception e) { + String error = "Failed to load Policy Cache properties file: " + + e.getMessage(); + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + error, e); + // TODO:EELF Cleanup - Remove logger + //PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, error); + status.addLoadError(error); + status.setStatus(PDPStatus.Status.LOAD_ERRORS); + } + // + // Load our PIP configuration + // + try { + // + // Were we given some properties to use? + // + if (pipProperties == null) { + // + // Load our current saved configuration + // + pipProperties = new Properties(); + try (InputStream is = Files.newInputStream(getPIPConfig())) { + pipProperties.load(is); + } + } + // + // Validate our PIP configurations + // + XACMLPdpLoader.validatePipConfiguration(pipProperties, status); + if (logger.isDebugEnabled()) { + logger.debug("Status: " + status); + } + } catch (Exception e) { + String error = "Failed to load/validate Pip Config properties file: " + + e.getMessage(); + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + error, e); + // TODO:EELF Cleanup - Remove logger + //PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, error); + status.addLoadError(XACMLErrorConstants.ERROR_PROCESS_FLOW + error); + status.setStatus(PDPStatus.Status.LOAD_ERRORS); + } + // + // Were they validated? + // + if (status.getStatus() == Status.LOAD_ERRORS) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW +"there were load errors"); + // TODO:EELF Cleanup - Remove logger + //PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE,"there were load errors"); + return null; + } + // + // Reset our official properties the PDP factory + // uses to configure the PDP engine. + // + XACMLRest.loadXacmlProperties(policyProperties, pipProperties); + // + // Dump ALL our properties that we are trying to load + // + try { + logger.info(XACMLProperties.getProperties().toString()); + } catch (IOException e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Failed to get XACML Properties", e); + // TODO:EELF Cleanup - Remove logger + //PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "Failed to get XACML Properties"); + } + // + // Now load the PDP engine + // + PDPEngineFactory factory = null; + PDPEngine engine = null; + try { + factory = PDPEngineFactory.newInstance(); + engine = factory.newEngine(); + logger.info("Loaded new PDP engine."); + status.setStatus(Status.UP_TO_DATE); + } catch (FactoryException e) { + String error = "Failed to create new PDP Engine"; + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR +error, e); + // TODO:EELF Cleanup - Remove logger + //PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, error); + status.addLoadError(error); + } + // Notification will be Sent Here. + sendNotification(); + return engine; + } + + private static HashMap policyContainer = null; + + private static void sendNotification(){ + Thread notify = new Thread(){ + public void run(){ + try{ + Thread.sleep(notifyDelay); + NotificationController.sendNotification(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_UNKNOWN + e); + // TODO:EELF Cleanup - Remove logger + //PolicyLogger.error(MessageCodes.ERROR_UNKNOWN, e, ""); + } + } + }; + notify.start(); + } + + public static synchronized void validatePolicies(Properties properties, + StdPDPStatus status) throws PAPException { + Set rootPolicies = XACMLProperties.getRootPolicyIDs(properties); + Set refPolicies = XACMLProperties + .getReferencedPolicyIDs(properties); + policyContainer = new HashMap(); + + for (String id : rootPolicies) { + loadPolicy(properties, status, id, true); + } + // remember which policies were root policies + status.addAllLoadedRootPolicies(status.getLoadedPolicies()); + + for (String id : refPolicies) { + loadPolicy(properties, status, id, false); + } + logger.info("Loaded " + status.getLoadedPolicies().size() + + " policies, failed to load " + + status.getFailedPolicies().size() + " policies, " + + status.getLoadedRootPolicies().size() + " root policies"); + // TODO Notification Controller is here.. + notificationController.check(status, policyContainer); + if (status.getLoadedRootPolicies().size() == 0) { + logger.warn(XACMLErrorConstants.ERROR_PROCESS_FLOW +"NO ROOT POLICIES LOADED!!! Cannot serve PEP Requests."); + status.addLoadWarning("NO ROOT POLICIES LOADED!!! Cannot serve PEP Requests."); + } + policyContainer.clear(); + } + + + public static synchronized void loadPolicy(Properties properties, + StdPDPStatus status, String id, boolean isRoot) throws PAPException { + PolicyDef policy = null; + String location = null; + URI locationURI = null; + boolean isFile = false; + boolean rougeFile = false; + try { + location = properties.getProperty(id + ".file"); + if(location != null){ + isFile = true; + locationURI = Paths.get(location).toUri(); + try (InputStream is = Files.newInputStream(Paths.get(location))) { + policy = DOMPolicyDef.load(is); + } catch (Exception e){ + // This Happens if a any issue with the error policyFile. Lets remove it. + try { + logger.error("Corrupted policy file, deleting: " + location); + Files.delete(Paths.get(location)); + properties.remove(id + ".file"); + rougeFile = true; + } catch (IOException e1) { + logger.error(e1); + } + } + } + if(location==null || rougeFile){ + if(rougeFile){ + rougeFile = false; + } + location = properties.getProperty(id + ".url"); + if (location != null) { + // + // Construct the URL + // + int errorCount=0; + boolean error= false; + do{ + error=false; + PapUrlResolver papUrls = PapUrlResolver.getInstance(); + while(papUrls.hasMoreUrls()){ + String papID = papUrls.getUserId(); + String papPass = papUrls.getPass(); + Base64.Encoder encoder = Base64.getEncoder(); + String encoding = encoder.encodeToString((papID+":"+papPass).getBytes(StandardCharsets.UTF_8)); + locationURI = URI.create(papUrls.getUrl(PapUrlResolver.extractIdFromUrl(location))); + URL url = locationURI.toURL(); + //FIXME: modify me + URLConnection urlConnection = null; + try{ + urlConnection = url.openConnection(); + } catch (IOException e){ + papUrls.failed(); + papUrls.getNext(); + break; + } + urlConnection.setRequestProperty(XACMLRestProperties.PROP_PDP_HTTP_HEADER_ID, + XACMLProperties.getProperty(XACMLRestProperties.PROP_PDP_ID)); + urlConnection.setRequestProperty("Authorization", "Basic " + encoding); + // + // Now construct the output file name + // + Path outFile = Paths.get(getPDPConfig().toAbsolutePath() + .toString(), id); + // + // Copy it to disk + // + try (FileOutputStream fos = new FileOutputStream( + outFile.toFile())) { + IOUtils.copy(urlConnection.getInputStream(), fos); + } catch(IOException e){ + papUrls.failed(); + papUrls.getNext(); + break; + } + // + // Now try to load + // + isFile = true; + try (InputStream fis = Files.newInputStream(outFile)) { + policy = DOMPolicyDef.load(fis); + }catch(Exception e){ + try { + logger.error("Corrupted policy file, deleting: " + location); + Files.delete(outFile); + error = true; + errorCount++; + break; + } catch (IOException e1) { + logger.error(e1); + } + } + // + // Save it + // + properties.setProperty(id + ".file", outFile + .toAbsolutePath().toString()); + error = false; + break; + } + }while(error && errorCount>2); + } + } + if (policy != null) { + status.addLoadedPolicy(new StdPDPPolicy(id, isRoot, + locationURI, properties)); + logger.info("Loaded policy: " + policy.getIdentifier() + + " version: " + policy.getVersion().stringValue()); + // Sending the policy objects to the Notification Controller. + policyContainer.put(id, policy); + } else { + String error = "Failed to load policy " + location; + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + error); + // TODO:EELF Cleanup - Remove logger + //PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, error); + status.setStatus(PDPStatus.Status.LOAD_ERRORS); + status.addLoadError(error); + status.addFailedPolicy(new StdPDPPolicy(id, isRoot)); + } + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW +"Failed to load policy '" + id + "' from location '" + + location + "'", e); + // TODO:EELF Cleanup - Remove logger + //PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "Failed to load policy '" + id + "' from location '" + // + location + "'"); + status.setStatus(PDPStatus.Status.LOAD_ERRORS); + status.addFailedPolicy(new StdPDPPolicy(id, isRoot)); + // + // Is it a file? + // + if (isFile) { + // + // Let's remove it + // + try { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Corrupted policy file, deleting: " + location); + // TODO:EELF Cleanup - Remove logger + //PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, "Corrupted policy file, deleting: " + location); + Files.delete(Paths.get(location)); + + } catch (IOException e1) { + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e1); + // TODO:EELF Cleanup - Remove logger + //PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e1, ""); + } + } + //throw new PAPException("Failed to load policy '" + id + "' from location '" + location + "'"); + } + } + + public static synchronized void validatePipConfiguration( + Properties properties, StdPDPStatus status) throws PAPException { + try { + PIPFinderFactory factory = PIPFinderFactory.newInstance(properties); + if (factory == null) { + throw new FactoryException( + "Could not create PIP Finder Factory: " + + properties + .getProperty(XACMLProperties.PROP_PIPFINDERFACTORY)); + } + PIPFinder finder = factory.getFinder(properties); + // + // Check for this, although it should always return something + // + if (finder == null) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "pip finder factory returned a null engine."); + // TODO:EELF Cleanup - Remove logger + //PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, "pip finder factory returned a null engine."); + throw new PIPException("Could not create PIP Finder"); + } else { + logger.info("Loaded PIP finder"); + } + for (PIPEngine engine : finder.getPIPEngines()) { + logger.info("Configured PIP Engine: " + engine.getName()); + StdPDPPIPConfig config = new StdPDPPIPConfig(); + config.setName(engine.getName()); + status.addLoadedPipConfig(config); + } + } catch (FactoryException | PIPException e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "validate PIP configuration failed: " + + e.getLocalizedMessage()); + // TODO:EELF Cleanup - Remove logger + //PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e.getLocalizedMessage(), "validate PIP configuration failed"); + status.addLoadError(e.getLocalizedMessage()); + status.setStatus(Status.LOAD_ERRORS); + throw new PAPException(e); + } + } + + /** + * Iterates the policies defined in the props object to ensure they are + * loaded locally. Policies are searched for in the following order: - see + * if the current properties has a "<PolicyID>.file" entry and that + * file exists in the local directory - if not, see if the file exists in + * the local directory; if so create a ".file" property for it. - if not, + * get the "<PolicyID>.url" property and try to GET the policy from + * that location (and set the ".file" property) + * + * If the ".file" property is created, then true is returned to tell the + * caller that the props object changed. + * + * @param props + * @return true/false if anything was changed in the props object + * @throws PAPException + */ + public static synchronized boolean cachePolicies(Properties props) + throws PAPException { + boolean changed = false; + String[] lists = new String[2]; + lists[0] = props.getProperty(XACMLProperties.PROP_ROOTPOLICIES); + lists[1] = props.getProperty(XACMLProperties.PROP_REFERENCEDPOLICIES); + for (String list : lists) { + // + // Check for a null or empty parameter + // + if (list == null || list.length() == 0) { + continue; + } + Iterable policies = Splitter.on(',').trimResults() + .omitEmptyStrings().split(list); + for (String policy : policies) { + boolean policyExists = false; + + // First look for ".file" property and verify the file exists + String propLocation = props.getProperty(policy + + StdPolicyFinderFactory.PROP_FILE); + if (propLocation != null) { + // + // Does it exist? + // + policyExists = Files.exists(Paths.get(propLocation)); + if (policyExists == false) { + logger.warn(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Policy file " + policy + " expected at " + + propLocation + " does NOT exist."); + } + } + + // If ".file" property does not exist, try looking for the local + // file anyway + // (it might exist without having a ".file" property set for it) + if (policyExists == false) { + // + // Now construct the output file name + // + Path outFile = Paths.get(getPDPConfig().toAbsolutePath() + .toString(), policy); + // + // Double check to see if we pulled it at some point + // + policyExists = Files.exists(outFile); + if (policyExists) { + // + // Set the property so the PDP engine doesn't have + // to pull it from the URL but rather the FILE. + // + logger.info("Policy does exist: " + + outFile.toAbsolutePath().toString()); + props.setProperty(policy + + StdPolicyFinderFactory.PROP_FILE, outFile + .toAbsolutePath().toString()); + // + // Indicate that there were changes made to the + // properties + // + changed = true; + } else { + + // File does not exist locally, so we need to get it + // from the location given in the ".url" property (which + // MUST exist) + + // + // There better be a URL to retrieve it + // + propLocation = props.getProperty(policy + + StdPolicyFinderFactory.PROP_URL); + if (propLocation != null) { + // + // Get it + // + PapUrlResolver papUrls = PapUrlResolver.getInstance(); + while(papUrls.hasMoreUrls()){ + String papID = papUrls.getUserId(); + String papPass = papUrls.getPass(); + Base64.Encoder encoder = Base64.getEncoder(); + String encoding = encoder.encodeToString((papID+":"+papPass).getBytes(StandardCharsets.UTF_8)); + URL url = null; + try { + // + // Create the URL + // + url = new URL(papUrls.getUrl(PapUrlResolver.extractIdFromUrl(propLocation))); + logger.info("Pulling " + url.toString()); + // + // Open the connection + // + URLConnection urlConnection = url.openConnection(); + urlConnection.setRequestProperty(XACMLRestProperties.PROP_PDP_HTTP_HEADER_ID, + XACMLProperties.getProperty(XACMLRestProperties.PROP_PDP_ID)); + urlConnection.setRequestProperty("Authorization", "Basic " + encoding); + // + // Copy it to disk + // + try (InputStream is = urlConnection + .getInputStream(); + OutputStream os = new FileOutputStream( + outFile.toFile())) { + IOUtils.copy(is, os); + } + // + // Now save it in the properties as a .file + // + logger.info("Pulled policy: " + + outFile.toAbsolutePath().toString()); + props.setProperty(policy + + StdPolicyFinderFactory.PROP_FILE, + outFile.toAbsolutePath().toString()); + papUrls.succeeded(); + // + // Indicate that there were changes made to the + // properties + // + changed = true; + } catch (Exception e) { + papUrls.failed(); + if (e instanceof MalformedURLException) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Policy '" + + policy + + "' had bad URL in new configuration, URL='" + + propLocation + "'"); + // TODO:EELF Cleanup - Remove logger + //PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, "Policy '" + // + policy + // + "' had bad URL in new configuration, URL='" + // + propLocation + "'"); + + } else { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error while retrieving policy " + + policy + + " from URL " + + url.toString() + ", e=" + e); + // TODO:EELF Cleanup - Remove logger + //PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "Error while retrieving policy " + // + policy + // + " from URL " + // + url.toString()); + } + } + papUrls.getNext(); + } + } else { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Policy " + policy + + " does NOT exist and does NOT have a URL"); + // TODO:EELF Cleanup - Remove logger + //PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, "Policy " + policy + // + " does NOT exist and does NOT have a URL"); + } + } + } + } + } + return changed; + } + + public static synchronized Path getPDPPolicyCache() throws PAPException { + Path config = getPDPConfig(); + Path policyProperties = Paths.get(config.toAbsolutePath().toString(), + "xacml.policy.properties"); + if (Files.notExists(policyProperties)) { + logger.warn(XACMLErrorConstants.ERROR_PROCESS_FLOW + policyProperties.toAbsolutePath().toString() + + " does NOT exist."); + // + // Try to create the file + // + try { + Files.createFile(policyProperties); + } catch (IOException e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Failed to create policy properties file: " + + policyProperties.toAbsolutePath().toString()); + // TODO:EELF Cleanup - Remove logger + //PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, "Failed to create policy properties file: " + // + policyProperties.toAbsolutePath().toString()); + throw new PAPException( + "Failed to create policy properties file: " + + policyProperties.toAbsolutePath().toString()); + } + } + return policyProperties; + } + + public static synchronized Path getPIPConfig() throws PAPException { + Path config = getPDPConfig(); + Path pipConfigProperties = Paths.get( + config.toAbsolutePath().toString(), "xacml.pip.properties"); + if (Files.notExists(pipConfigProperties)) { + logger.warn(XACMLErrorConstants.ERROR_PROCESS_FLOW + pipConfigProperties.toAbsolutePath().toString() + + " does NOT exist."); + // + // Try to create the file + // + try { + Files.createFile(pipConfigProperties); + } catch (IOException e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Failed to create pip properties file: " + + pipConfigProperties.toAbsolutePath().toString()); + // TODO:EELF Cleanup - Remove logger + //PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, "Failed to create pip properties file: " + //+ pipConfigProperties.toAbsolutePath().toString()); + throw new PAPException("Failed to create pip properties file: " + + pipConfigProperties.toAbsolutePath().toString()); + } + } + return pipConfigProperties; + } + + public static synchronized Path getPDPConfig() throws PAPException { + Path config = Paths.get(XACMLProperties + .getProperty(XACMLRestProperties.PROP_PDP_CONFIG)); + if (Files.notExists(config)) { + logger.warn(XACMLErrorConstants.ERROR_PROCESS_FLOW + config.toAbsolutePath().toString() + " does NOT exist."); + // + // Try to create the directory + // + try { + Files.createDirectories(config); + } catch (IOException e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Failed to create config directory: " + + config.toAbsolutePath().toString(), e); + // TODO:EELF Cleanup - Remove logger + //PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "Failed to create config directory: " + //+ config.toAbsolutePath().toString()); + throw new PAPException("Failed to create config directory: " + + config.toAbsolutePath().toString()); + } + } + return config; + } + +} diff --git a/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/XACMLPdpRegisterThread.java b/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/XACMLPdpRegisterThread.java new file mode 100644 index 000000000..83b9f3cf7 --- /dev/null +++ b/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/XACMLPdpRegisterThread.java @@ -0,0 +1,333 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + + +package org.openecomp.policy.pdp.rest; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.HttpURLConnection; +import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.util.Base64; +import java.util.Properties; +import java.util.UUID; + +import org.apache.commons.io.IOUtils; +import org.openecomp.policy.pdp.rest.XACMLPdpServlet.PutRequest; +import org.openecomp.policy.rest.XACMLRestProperties; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; +import com.att.research.xacml.util.XACMLProperties; + +import org.openecomp.policy.common.logging.ECOMPLoggingContext; +import org.openecomp.policy.common.logging.eelf.PolicyLogger; +import org.openecomp.policy.common.logging.flexlogger.*; + +public class XACMLPdpRegisterThread implements Runnable { + private static final Logger logger = FlexLogger.getLogger(XACMLPdpRegisterThread.class); + private static final Logger auditLogger = FlexLogger.getLogger("auditLogger"); + private ECOMPLoggingContext baseLoggingContext = null; + + + + public volatile boolean isRunning = false; + + public XACMLPdpRegisterThread(ECOMPLoggingContext baseLoggingContext) { + this.baseLoggingContext = baseLoggingContext; + } + + public synchronized boolean isRunning() { + return this.isRunning; + } + + public synchronized void terminate() { + this.isRunning = false; + } + + /** + * + * This is our thread that runs on startup to tell the PAP server we are up-and-running. + * + */ + @Override + public void run() { + synchronized(this) { + this.isRunning = true; + } + // get a new logging context for the thread + ECOMPLoggingContext loggingContext = new ECOMPLoggingContext(baseLoggingContext); + loggingContext.setServiceName("PDP:PAP.register"); + //are we registered with at least one + boolean registered = false; + boolean interrupted = false; + /* + int seconds; + try { + seconds = Integer.parseInt(XACMLProperties.getProperty(XACMLRestProperties.PROP_PDP_REGISTER_SLEEP)); + } catch (NumberFormatException e) { + logger.error( XACMLErrorConstants.ERROR_SYSTEM_ERROR +"REGISTER_SLEEP: ", e); + seconds = 5; + } + if (seconds < 5) { + seconds = 5; + } + int retries; + try { + retries = Integer.parseInt(XACMLProperties.getProperty(XACMLRestProperties.PROP_PDP_REGISTER_RETRIES)); + } catch (NumberFormatException e) { + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR +" REGISTER_SLEEP: ", e); + retries = -1; + } + */ + PapUrlResolver papUrls = PapUrlResolver.getInstance(); + //while (! registered && ! interrupted && this.isRunning()) { + String tempRootPoliciesProperty = XACMLProperties.getProperty(XACMLProperties.PROP_ROOTPOLICIES); + String tempReferencedPoliciesProperty = XACMLProperties.getProperty(XACMLProperties.PROP_REFERENCEDPOLICIES); + Properties tempPipConfigProperties = new Properties(); + try(InputStream pipFile = Files.newInputStream(XACMLPdpLoader.getPIPConfig())){ + tempPipConfigProperties.load(pipFile); + } catch(Exception e){ + logger.error("Failed to open PIP property file", e); + // TODO:EELF Cleanup - Remove logger + //PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "XACMLPdpRegisterThread", "Failed to open PIP property file"); + } + while(papUrls.hasMoreUrls()){ + String papID = papUrls.getUserId(); + String papPass = papUrls.getPass(); + Base64.Encoder encoder = Base64.getEncoder(); + String encoding = encoder.encodeToString((papID+":"+papPass).getBytes(StandardCharsets.UTF_8)); + HttpURLConnection connection = null; + try { + // get a new transaction (request) ID and update the logging context. + // each time through the outer loop is considered a new transaction. + // each time through the inner loop (which handles redirects) is a + // continuation of the same transaction. + UUID requestID = UUID.randomUUID(); + loggingContext.setRequestID(requestID.toString()); + //PolicyLogger.info("Request Id generated in XACMLPdpRegisterThread under XACML-PDP-REST"); + loggingContext.transactionStarted(); + // + // Get the list of PAP Servlet URLs from the property file + // + //String papUrlList = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_URL); + //String[] papUrls = papUrlList.split(","); + //PapUrlResolver.setPapUrls(papUrls); + URL url = new URL(papUrls.getUrl()); + logger.info("Registering with " + url.toString()); + //PolicyLogger.info("new transaction (request) ID and update to logging context in XACMLPdpRegisterThread"); + boolean finished = false; + while (! finished) { + // + // Open up the connection + // + connection = (HttpURLConnection)url.openConnection(); + // + // Setup our method and headers + // + connection.setRequestMethod("POST"); + connection.setRequestProperty("Authorization", "Basic " + encoding); + connection.setRequestProperty("Accept", "text/x-java-properties"); + connection.setRequestProperty("Content-Type", "text/x-java-properties"); + connection.setRequestProperty(XACMLRestProperties.PROP_PDP_HTTP_HEADER_ID, XACMLProperties.getProperty(XACMLRestProperties.PROP_PDP_ID)); + connection.setRequestProperty(XACMLRestProperties.PROP_PDP_HTTP_HEADER_JMX_PORT, XACMLProperties.getProperty(XACMLRestProperties.PROP_PDP_JMX_PORT)); + connection.setRequestProperty("X-ECOMP-RequestID", requestID.toString()); + connection.setUseCaches(false); + // + // Adding this in. It seems the HttpUrlConnection class does NOT + // properly forward our headers for POST re-direction. It does so + // for a GET re-direction. + // + // So we need to handle this ourselves. + // + connection.setInstanceFollowRedirects(false); + connection.setDoOutput(true); + connection.setDoInput(true); + try { + // + // Send our current policy configuration + // + String lists = XACMLProperties.PROP_ROOTPOLICIES + "=" + tempRootPoliciesProperty; + lists = lists + "\n" + XACMLProperties.PROP_REFERENCEDPOLICIES + "=" + tempReferencedPoliciesProperty + "\n"; + try (InputStream listsInputStream = new ByteArrayInputStream(lists.getBytes()); + OutputStream os = connection.getOutputStream()) { + IOUtils.copy(listsInputStream, os); + + // + // Send our current PIP configuration + // + //IOUtils.copy(pipInputStream, os); + tempPipConfigProperties.store(os, ""); + } + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR +"Failed to send property file", e); + // TODO:EELF Cleanup - Remove logger + //PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "Failed to send property file"); + } + // + // Do the connect + // + connection.connect(); + if (connection.getResponseCode() == 204) { + logger.info("Success. We are configured correctly."); + // TODO:EELF Cleanup - Remove logger + //PolicyLogger.info("Success. We are configured correctly."); + loggingContext.transactionEnded(); + // auditLogger.info("Success. We are configured correctly."); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.audit("Success. We are configured correctly."); + papUrls.registered(); + finished = true; + registered = true; + } else if (connection.getResponseCode() == 200) { + logger.info("Success. We have a new configuration."); + // TODO:EELF Cleanup - Remove logger + //PolicyLogger.info("Success. We have a new configuration."); + loggingContext.transactionEnded(); + // TODO:EELF Cleanup - Remove logger + //auditLogger.info("Success. We have a new configuration."); + PolicyLogger.audit("Success. We have a new configuration."); + papUrls.registered(); + Properties properties = new Properties(); + properties.load(connection.getInputStream()); + logger.info("New properties: " + properties.toString()); + // + // Queue it + // + // The incoming properties does NOT include urls + //FIXME: problem here is that we need the properties to be filled in BEFORE this thread continues and registers with another pap + Properties returnedPolicyProperties = XACMLProperties.getPolicyProperties(properties, false); + tempRootPoliciesProperty = new String(returnedPolicyProperties.getProperty(XACMLProperties.PROP_ROOTPOLICIES)); + tempReferencedPoliciesProperty = new String(returnedPolicyProperties.getProperty(XACMLProperties.PROP_REFERENCEDPOLICIES)); + Properties returnedPipProperties = XACMLProperties.getPipProperties(properties); + Properties threadSafeReturnedPipProperties = new Properties(); + ByteArrayOutputStream threadSafeReturnedPipPropertiesOs = new ByteArrayOutputStream(); + returnedPipProperties.store(threadSafeReturnedPipPropertiesOs, ""); + InputStream threadSafeReturnedPipPropertiesIs = new ByteArrayInputStream(threadSafeReturnedPipPropertiesOs.toByteArray()); + threadSafeReturnedPipProperties.load(threadSafeReturnedPipPropertiesIs); + tempPipConfigProperties = threadSafeReturnedPipProperties; + //FIXME: how will pipproperties respond to threading? + + PutRequest req = new PutRequest(returnedPolicyProperties,returnedPipProperties); + XACMLPdpServlet.queue.offer(req); + // + // We are now registered + // + finished = true; + registered=true; + } else if (connection.getResponseCode() >= 300 && connection.getResponseCode() <= 399) { + // + // Re-direction + // + String newLocation = connection.getHeaderField("Location"); + if (newLocation == null || newLocation.isEmpty()) { + logger.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR +"Did not receive a valid re-direction location"); + // TODO:EELF Cleanup - Remove logger + //PolicyLogger.warn(MessageCodes.ERROR_SYSTEM_ERROR, "Did not receive a valid re-direction location"); + loggingContext.transactionEnded(); + auditLogger.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR +"Did not receive a valid re-direction location"); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.audit("Transaction Failed - See Error.log"); + finished = true; + } else { + //FIXME: how to handle this + logger.info("New Location: " + newLocation); + // TODO:EELF Cleanup - Remove logger + //PolicyLogger.info("New Location: " + newLocation); + url = new URL(newLocation); + } + } else { + logger.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Failed: " + connection.getResponseCode() + " message: " + connection.getResponseMessage()); + // TODO:EELF Cleanup - Remove logger + //PolicyLogger.warn(MessageCodes.ERROR_SYSTEM_ERROR, "Failed: " + connection.getResponseCode() + " message: " + connection.getResponseMessage()); + loggingContext.transactionEnded(); + auditLogger.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Failed: " + connection.getResponseCode() + " message: " + connection.getResponseMessage()); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.audit("Transaction Failed - See Error.log"); + finished = true; + papUrls.failed(); + } + } + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e); + // TODO:EELF Cleanup - Remove logger + //PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, ""); + PolicyLogger.audit("Transaction Failed - See Error.log"); + loggingContext.transactionEnded(); + // TODO:EELF look at this error going to audit. decide what to do. + //auditLogger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e); + // TODO:EELF Cleanup - Remove logger + papUrls.failed(); + } finally { + // cleanup the connection + if (connection != null) { + try { + // For some reason trying to get the inputStream from the connection + // throws an exception rather than returning null when the InputStream does not exist. + InputStream is = null; + try { + is = connection.getInputStream(); + } catch (Exception e1) { + // ignore this + } + if (is != null) { + is.close(); + } + + } catch (IOException ex) { + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Failed to close connection: " + ex, ex); + // TODO:EELF Cleanup - Remove logger + //PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, ex, "Failed to close connection"); + } + connection.disconnect(); + } + } + // + // Wait a little while to try again + // + /* + try { + if (registered == false) { + if (retries > 0) { + retries--; + } else if (retries == 0) { + break; + } + Thread.sleep(seconds * 1000); + } + } catch (InterruptedException e) { + interrupted = true; + this.terminate(); + } + */ + //end of hasMoreUrls while loop + papUrls.getNext(); + } + synchronized(this) { + this.isRunning = false; + } + logger.info("Thread exiting...(registered=" + registered + ", interrupted=" + interrupted + ", isRunning=" + this.isRunning() + ", retries=" + "0" + ")"); + } + +} diff --git a/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/XACMLPdpServlet.java b/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/XACMLPdpServlet.java new file mode 100644 index 000000000..963fcd127 --- /dev/null +++ b/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/XACMLPdpServlet.java @@ -0,0 +1,1138 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.rest; + +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.nio.file.Files; +import java.util.Properties; +import java.util.UUID; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.LinkedBlockingQueue; + +import javax.servlet.Servlet; +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebInitParam; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.io.IOUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.http.entity.ContentType; +import org.openecomp.policy.pdp.rest.jmx.PdpRestMonitor; +import org.openecomp.policy.rest.XACMLRest; +import org.openecomp.policy.rest.XACMLRestProperties; +import org.openecomp.policy.common.logging.ECOMPLoggingContext; +import org.openecomp.policy.common.logging.ECOMPLoggingUtils; +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.eelf.PolicyLogger; +import org.openecomp.policy.common.im.AdministrativeStateException; +import org.openecomp.policy.common.im.ForwardProgressException; +import org.openecomp.policy.common.im.IntegrityMonitor; +import org.openecomp.policy.common.im.IntegrityMonitorProperties; +import org.openecomp.policy.common.im.StandbyStatusException; + +import com.att.research.xacml.api.Request; +import com.att.research.xacml.api.Response; +import org.openecomp.policy.xacml.api.XACMLErrorConstants; +import com.att.research.xacml.api.pap.PDPStatus.Status; +import com.att.research.xacml.api.pdp.PDPEngine; +import com.att.research.xacml.api.pdp.PDPException; +import com.att.research.xacml.std.dom.DOMRequest; +import com.att.research.xacml.std.dom.DOMResponse; +import com.att.research.xacml.std.json.JSONRequest; +import com.att.research.xacml.std.json.JSONResponse; +import com.att.research.xacml.util.XACMLProperties; +import org.openecomp.policy.xacml.pdp.std.functions.PolicyList; +import org.openecomp.policy.xacml.std.pap.StdPDPStatus; +import com.fasterxml.jackson.databind.ObjectMapper; + +/** + * Servlet implementation class XacmlPdpServlet + * + * This is an implementation of the XACML 3.0 RESTful Interface with added features to support + * simple PAP RESTful API for policy publishing and PIP configuration changes. + * + * If you are running this the first time, then we recommend you look at the xacml.pdp.properties file. + * This properties file has all the default parameter settings. If you are running the servlet as is, + * then we recommend setting up you're container to run it on port 8080 with context "/pdp". Wherever + * the default working directory is set to, a "config" directory will be created that holds the policy + * and pip cache. This setting is located in the xacml.pdp.properties file. + * + * When you are ready to customize, you can create a separate xacml.pdp.properties on you're local file + * system and setup the parameters as you wish. Just set the Java VM System variable to point to that file: + * + * -Dxacml.properties=/opt/app/xacml/etc/xacml.pdp.properties + * + * Or if you only want to change one or two properties, simply set the Java VM System variable for that property. + * + * -Dxacml.rest.pdp.register=false + * + * + */ +@WebServlet( + description = "Implements the XACML PDP RESTful API and client PAP API.", + urlPatterns = { "/" }, + loadOnStartup=1, + initParams = { + @WebInitParam(name = "XACML_PROPERTIES_NAME", value = "xacml.pdp.properties", description = "The location of the PDP xacml.pdp.properties file holding configuration information.") + }) +public class XACMLPdpServlet extends HttpServlet implements Runnable { + private static final long serialVersionUID = 1L; + private static final String DEFAULT_MAX_CONTENT_LENGTH = "999999999"; //32767 + // + // Our application debug log + // + private static final Log logger = LogFactory.getLog(XACMLPdpServlet.class); + // + // This logger is specifically only for Xacml requests and their corresponding response. + // It's output ideally should be sent to a separate file from the application logger. + // + private static final Log requestLogger = LogFactory.getLog("xacml.request"); + // + // audit logger + private static final Log auditLogger = LogFactory.getLog("auditLogger"); + + private static final PdpRestMonitor monitor = PdpRestMonitor.singleton; + + // + // This thread may getting invoked on startup, to let the PAP know + // that we are up and running. + // + private Thread registerThread = null; + private XACMLPdpRegisterThread registerRunnable = null; + // + // This is our PDP engine pointer. There is a synchronized lock used + // for access to the pointer. In case we are servicing PEP requests while + // an update is occurring from the PAP. + // + private PDPEngine pdpEngine = null; + private static final Object pdpEngineLock = new Object(); + // + // This is our PDP's status. What policies are loaded (or not) and + // what PIP configurations are loaded (or not). + // There is a synchronized lock used for access to the object. + // + private static volatile StdPDPStatus status = new StdPDPStatus(); + private static final Object pdpStatusLock = new Object(); + + private static final String ENVIORNMENT_HEADER = "Environment"; + private static String environment = null; + // + // Queue of PUT requests + // + public static class PutRequest { + public Properties policyProperties = null; + public Properties pipConfigProperties = null; + + PutRequest(Properties policies, Properties pips) { + this.policyProperties = policies; + this.pipConfigProperties = pips; + } + } + public static volatile BlockingQueue queue = null; + // For notification Delay. + private static int notificationDelay = 0; + public static int getNotificationDelay(){ + return XACMLPdpServlet.notificationDelay; + } + + private static String pdpResourceName; + private static String dependencyGroups = null; + private static String[] dependencyNodes = null; + + // + // This is our configuration thread that attempts to load + // a new configuration request. + // + private Thread configThread = null; + private volatile boolean configThreadTerminate = false; + private ECOMPLoggingContext baseLoggingContext = null; + private IntegrityMonitor im; + /** + * Default constructor. + */ + public XACMLPdpServlet() { + } + + /** + * @see Servlet#init(ServletConfig) + */ + public void init(ServletConfig config) throws ServletException { + // + // Initialize + // + XACMLRest.xacmlInit(config); + // Load the Notification Delay. + try{ + XACMLPdpServlet.notificationDelay = Integer.parseInt(XACMLProperties.getProperty(XACMLRestProperties.PROP_NOTIFICATION_DELAY)); + }catch(Exception e){ + logger.info("Notification Delay Not set. Keeping it 0 as default."); + } + // Load Queue size. + int queueSize = 5; // Set default Queue Size here. + queueSize = Integer.parseInt(XACMLProperties.getProperty("REQUEST_BUFFER_SIZE",String.valueOf(queueSize))); + queue = new LinkedBlockingQueue(queueSize); + // Load our engine - this will use the latest configuration + // that was saved to disk and set our initial status object. + // + PDPEngine engine = XACMLPdpLoader.loadEngine(XACMLPdpServlet.status, null, null); + if (engine != null) { + synchronized(pdpEngineLock) { + pdpEngine = engine; + } + } + // + // Logging stuff.... + // + baseLoggingContext = new ECOMPLoggingContext(); + // fixed data that will be the same in all logging output goes here + try { + String hostname = InetAddress.getLocalHost().getCanonicalHostName(); + baseLoggingContext.setServer(hostname); + } catch (UnknownHostException e) { + logger.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Unable to get hostname for logging"); + } + + Properties properties; + try { + properties = XACMLProperties.getProperties(); + } catch (IOException e) { + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, + "Error loading properties with: XACMLProperties.getProperties()"); + throw new ServletException(e.getMessage(), e.getCause()); + } + + pdpResourceName = properties.getProperty(XACMLRestProperties.PDP_RESOURCE_NAME); + if(pdpResourceName == null){ + PolicyLogger.error(MessageCodes.MISS_PROPERTY_ERROR, XACMLRestProperties.PDP_RESOURCE_NAME, "xacml.pdp"); + throw new ServletException("pdpResourceName is null"); + } + + dependencyGroups = properties.getProperty(IntegrityMonitorProperties.DEPENDENCY_GROUPS); + if(dependencyGroups == null){ + PolicyLogger.error(MessageCodes.MISS_PROPERTY_ERROR, IntegrityMonitorProperties.DEPENDENCY_GROUPS, "xacml.pdp"); + throw new ServletException("dependency_groups is null"); + } + // dependency_groups is a semicolon-delimited list of groups, and + // each group is a comma-separated list of nodes. For our purposes + // we just need a list of dependencies without regard to grouping, + // so split the list into nodes separated by either comma or semicolon. + dependencyNodes = dependencyGroups.split("[;,]"); + for (int i = 0 ; i < dependencyNodes.length ; i++){ + dependencyNodes[i] = dependencyNodes[i].trim(); + } + + + // Create an IntegrityMonitor + try { + logger.info("Creating IntegrityMonitor"); + im = IntegrityMonitor.getInstance(pdpResourceName, properties); + } catch (Exception e) { + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "Failed to create IntegrityMonitor"); + throw new ServletException(e); + } + + environment = XACMLProperties.getProperty("ENVIRONMENT", "DEVL"); + // + // Kick off our thread to register with the PAP servlet. + // + if (Boolean.parseBoolean(XACMLProperties.getProperty(XACMLRestProperties.PROP_PDP_REGISTER))) { + this.registerRunnable = new XACMLPdpRegisterThread(baseLoggingContext); + this.registerThread = new Thread(this.registerRunnable); + this.registerThread.start(); + } + // + // This is our thread that manages incoming configuration + // changes. + // + this.configThread = new Thread(this); + this.configThread.start(); + } + + /** + * @see Servlet#destroy() + */ + public void destroy() { + super.destroy(); + logger.info("Destroying...."); + // + // Make sure the register thread is not running + // + if (this.registerRunnable != null) { + try { + this.registerRunnable.terminate(); + if (this.registerThread != null) { + this.registerThread.interrupt(); + this.registerThread.join(); + } + } catch (InterruptedException e) { + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e); + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, ""); + } + } + // + // Make sure the configure thread is not running + // + this.configThreadTerminate = true; + try { + this.configThread.interrupt(); + this.configThread.join(); + } catch (InterruptedException e) { + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e); + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, ""); + } + logger.info("Destroyed."); + } + + /** + * PUT - The PAP engine sends configuration information using HTTP PUT request. + * + * One parameter is expected: + * + * config=[policy|pip|all] + * + * policy - Expect a properties file that contains updated lists of the root and referenced policies that the PDP should + * be using for PEP requests. + * + * Specifically should AT LEAST contain the following properties: + * xacml.rootPolicies + * xacml.referencedPolicies + * + * In addition, any relevant information needed by the PDP to load or retrieve the policies to store in its cache. + * + * EXAMPLE: + * xacml.rootPolicies=PolicyA.1, PolicyB.1 + * + * PolicyA.1.url=http://localhost:9090/PAP?id=b2d7b86d-d8f1-4adf-ba9d-b68b2a90bee1&version=1 + * PolicyB.1.url=http://localhost:9090/PAP/id=be962404-27f6-41d8-9521-5acb7f0238be&version=1 + * + * xacml.referencedPolicies=RefPolicyC.1, RefPolicyD.1 + * + * RefPolicyC.1.url=http://localhost:9090/PAP?id=foobar&version=1 + * RefPolicyD.1.url=http://localhost:9090/PAP/id=example&version=1 + * + * pip - Expect a properties file that contain PIP engine configuration properties. + * + * Specifically should AT LEAST the following property: + * xacml.pip.engines + * + * In addition, any relevant information needed by the PDP to load and configure the PIPs. + * + * EXAMPLE: + * xacml.pip.engines=foo,bar + * + * foo.classname=com.foo + * foo.sample=abc + * foo.example=xyz + * ...... + * + * bar.classname=com.bar + * ...... + * + * all - Expect ALL new configuration properties for the PDP + * + * @see HttpServlet#doPut(HttpServletRequest request, HttpServletResponse response) + */ + protected void doPut(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + ECOMPLoggingContext loggingContext = ECOMPLoggingUtils.getLoggingContextForRequest(request, baseLoggingContext); + loggingContext.transactionStarted(); + if ((loggingContext.getRequestID() == null) || (loggingContext.getRequestID() == "")){ + UUID requestID = UUID.randomUUID(); + loggingContext.setRequestID(requestID.toString()); + PolicyLogger.info("requestID not provided in call to XACMLPdpSrvlet (doPut) so we generated one"); + } else { + PolicyLogger.info("requestID was provided in call to XACMLPdpSrvlet (doPut)"); + } + loggingContext.metricStarted(); + loggingContext.metricEnded(); + PolicyLogger.metrics("Metric example posted here - 1 of 2"); + loggingContext.metricStarted(); + loggingContext.metricEnded(); + PolicyLogger.metrics("Metric example posted here - 2 of 2"); + // + // Dump our request out + // + if (logger.isDebugEnabled()) { + XACMLRest.dumpRequest(request); + } + + try { + im.startTransaction(); + } + catch (AdministrativeStateException | StandbyStatusException e) { + String message = e.toString(); + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, message); + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message); + return; + } + // + // What is being PUT? + // + String cache = request.getParameter("cache"); + // + // Should be a list of policy and pip configurations in Java properties format + // + if (cache != null && request.getContentType().equals("text/x-java-properties")) { + loggingContext.setServiceName("PDP.putConfig"); + if (request.getContentLength() > Integer.parseInt(XACMLProperties.getProperty("MAX_CONTENT_LENGTH", DEFAULT_MAX_CONTENT_LENGTH))) { + String message = "Content-Length larger than server will accept."; + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + message); + loggingContext.transactionEnded(); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, message); + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(HttpServletResponse.SC_BAD_REQUEST, message); + im.endTransaction(); + return; + } + this.doPutConfig(cache, request, response, loggingContext); + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction ended"); + + im.endTransaction(); + } else { + String message = "Invalid cache: '" + cache + "' or content-type: '" + request.getContentType() + "'"; + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + message); + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, message); + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(HttpServletResponse.SC_BAD_REQUEST, message); + im.endTransaction(); + return; + } + } + + protected void doPutConfig(String config, HttpServletRequest request, HttpServletResponse response, ECOMPLoggingContext loggingContext) throws ServletException, IOException { + try { + // prevent multiple configuration changes from stacking up + if (XACMLPdpServlet.queue.remainingCapacity() <= 0) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Queue capacity reached"); + PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, "Queue capacity reached"); + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(HttpServletResponse.SC_CONFLICT, "Multiple configuration changes waiting processing."); + return; + } + // + // Read the properties data into an object. + // + Properties newProperties = new Properties(); + newProperties.load(request.getInputStream()); + // should have something in the request + if (newProperties.size() == 0) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No properties in PUT"); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "No properties in PUT"); + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(HttpServletResponse.SC_BAD_REQUEST, "PUT must contain at least one property"); + return; + } + // + // Which set of properties are they sending us? Whatever they send gets + // put on the queue (if there is room). + // For audit logging purposes, we consider the transaction done once the + // the request gets put on the queue. + // + if (config.equals("policies")) { + newProperties = XACMLProperties.getPolicyProperties(newProperties, true); + if (newProperties.size() == 0) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No policy properties in PUT"); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "No policy properties in PUT"); + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(HttpServletResponse.SC_BAD_REQUEST, "PUT with cache=policies must contain at least one policy property"); + return; + } + XACMLPdpServlet.queue.offer(new PutRequest(newProperties, null)); + loggingContext.transactionEnded(); + auditLogger.info("Success"); + PolicyLogger.audit("Success"); + } else if (config.equals("pips")) { + newProperties = XACMLProperties.getPipProperties(newProperties); + if (newProperties.size() == 0) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No pips properties in PUT"); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "No pips properties in PUT"); + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(HttpServletResponse.SC_BAD_REQUEST, "PUT with cache=pips must contain at least one pip property"); + return; + } + XACMLPdpServlet.queue.offer(new PutRequest(null, newProperties)); + loggingContext.transactionEnded(); + auditLogger.info("Success"); + PolicyLogger.audit("Success"); + } else if (config.equals("all")) { + Properties newPolicyProperties = XACMLProperties.getPolicyProperties(newProperties, true); + if (newPolicyProperties.size() == 0) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No policy properties in PUT"); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "No policy properties in PUT"); + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(HttpServletResponse.SC_BAD_REQUEST, "PUT with cache=all must contain at least one policy property"); + return; + } + Properties newPipProperties = XACMLProperties.getPipProperties(newProperties); + if (newPipProperties.size() == 0) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No pips properties in PUT"); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "No pips properties in PUT"); + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(HttpServletResponse.SC_BAD_REQUEST, "PUT with cache=all must contain at least one pip property"); + return; + } + XACMLPdpServlet.queue.offer(new PutRequest(newPolicyProperties, newPipProperties)); + loggingContext.transactionEnded(); + auditLogger.info("Success"); + PolicyLogger.audit("Success"); + } else { + // + // Invalid value + // + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Invalid config value: " + config); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "Invalid config value: " + config); + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Config must be one of 'policies', 'pips', 'all'"); + return; + } + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Failed to process new configuration.", e); + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "Failed to process new configuration"); + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); + return; + } + + } + + /** + * Parameters: type=hb|config|Status + * + * 1. HeartBeat Status + * HeartBeat + * OK - All Policies are Loaded, All PIPs are Loaded + * LOADING_IN_PROGRESS - Currently loading a new policy set/pip configuration + * LAST_UPDATE_FAILED - Need to track the items that failed during last update + * LOAD_FAILURE - ??? Need to determine what information is sent and how + * 2. Configuration + * 3. Status + * return the StdPDPStatus object in the Response content + * + * + * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) + */ + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + ECOMPLoggingContext loggingContext = ECOMPLoggingUtils.getLoggingContextForRequest(request, baseLoggingContext); + loggingContext.transactionStarted(); + if ((loggingContext.getRequestID() == null) || (loggingContext.getRequestID() == "")){ + UUID requestID = UUID.randomUUID(); + loggingContext.setRequestID(requestID.toString()); + PolicyLogger.info("requestID not provided in call to XACMLPdpSrvlet (doGet) so we generated one"); + } else { + PolicyLogger.info("requestID was provided in call to XACMLPdpSrvlet (doGet)"); + } + loggingContext.metricStarted(); + loggingContext.metricEnded(); + PolicyLogger.metrics("Metric example posted here - 1 of 2"); + loggingContext.metricStarted(); + loggingContext.metricEnded(); + PolicyLogger.metrics("Metric example posted here - 2 of 2"); + + XACMLRest.dumpRequest(request); + + String pathInfo = request.getRequestURI(); + if (pathInfo != null){ + // health check from Global Site Selector (iDNS). + // DO NOT do a im.startTransaction for the test request + if (pathInfo.equals("/pdp/test")) { + loggingContext.setServiceName("iDNS:PDP.test"); + try { + im.evaluateSanity(); + //If we make it this far, all is well + String message = "GET:/pdp/test called and PDP " + pdpResourceName + " is OK"; + PolicyLogger.debug(message); + loggingContext.transactionEnded(); + PolicyLogger.audit("Success"); + response.setStatus(HttpServletResponse.SC_OK); + return; + } catch (ForwardProgressException fpe){ + //No forward progress is being made + String message = "GET:/pdp/test called and PDP " + pdpResourceName + " is not making forward progress." + + " Exception Message: " + fpe.getMessage(); + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, message ); + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Failed - See Error.log"); + // PolicyLogger.audit(MessageCodes.ERROR_SYSTEM_ERROR, message ); + response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message); + return; + }catch (AdministrativeStateException ase){ + //Administrative State is locked + String message = "GET:/pdp/test called and PDP " + pdpResourceName + " Administrative State is LOCKED " + + " Exception Message: " + ase.getMessage(); + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, message ); + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message); + return; + }catch (StandbyStatusException sse){ + //Administrative State is locked + String message = "GET:/pdp/test called and PDP " + pdpResourceName + " Standby Status is NOT PROVIDING SERVICE " + + " Exception Message: " + sse.getMessage(); + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, message ); + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message); + return; + } catch (Exception e) { + //A subsystem is not making progress or is not responding + String eMsg = e.getMessage(); + if(eMsg == null){ + eMsg = "No Exception Message"; + } + String message = "GET:/pdp/test called and PDP " + pdpResourceName + " has had a subsystem failure." + + " Exception Message: " + eMsg; + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, message ); + //Get the specific list of subsystems that failed + String failedNodeList = null; + for(String node : dependencyNodes){ + if(eMsg.contains(node)){ + if(failedNodeList == null){ + failedNodeList = node; + }else{ + failedNodeList = failedNodeList.concat(","+node); + } + } + } + if(failedNodeList == null){ + failedNodeList = "UnknownSubSystem"; + } + response.addHeader("X-ECOMP-SubsystemFailure", failedNodeList); + response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message); + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Failed - See Error.log"); + return; + } + } + } + + try { + im.startTransaction(); + } + catch (AdministrativeStateException | StandbyStatusException e) { + String message = e.toString(); + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, message); + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message); + return; + } + // + // What are they requesting? + // + boolean returnHB = false; + response.setHeader("Cache-Control", "no-cache"); + String type = request.getParameter("type"); + // type might be null, so use equals on string constants + if ("config".equals(type)) { + loggingContext.setServiceName("PDP.getConfig"); + response.setContentType("text/x-java-properties"); + try { + String lists = XACMLProperties.PROP_ROOTPOLICIES + "=" + XACMLProperties.getProperty(XACMLProperties.PROP_ROOTPOLICIES, ""); + lists = lists + "\n" + XACMLProperties.PROP_REFERENCEDPOLICIES + "=" + XACMLProperties.getProperty(XACMLProperties.PROP_REFERENCEDPOLICIES, "") + "\n"; + try (InputStream listInputStream = new ByteArrayInputStream(lists.getBytes()); + InputStream pipInputStream = Files.newInputStream(XACMLPdpLoader.getPIPConfig()); + OutputStream os = response.getOutputStream()) { + IOUtils.copy(listInputStream, os); + IOUtils.copy(pipInputStream, os); + } + loggingContext.transactionEnded(); + auditLogger.info("Success"); + PolicyLogger.audit("Success"); + response.setStatus(HttpServletResponse.SC_OK); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Failed to copy property file", e); + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "Failed to copy property file"); + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(400, "Failed to copy Property file"); + } + + } else if ("hb".equals(type)) { + returnHB = true; + response.setStatus(HttpServletResponse.SC_NO_CONTENT); + + } else if ("Status".equals(type)) { + loggingContext.setServiceName("PDP.getStatus"); + // convert response object to JSON and include in the response + synchronized(pdpStatusLock) { + ObjectMapper mapper = new ObjectMapper(); + mapper.writeValue(response.getOutputStream(), status); + } + response.setStatus(HttpServletResponse.SC_OK); + loggingContext.transactionEnded(); + auditLogger.info("Success"); + PolicyLogger.audit("Success"); + + } else { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Invalid type value: " + type); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "Invalid type value: " + type); + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(HttpServletResponse.SC_BAD_REQUEST, "type not 'config' or 'hb'"); + } + if (returnHB) { + synchronized(pdpStatusLock) { + response.addHeader(XACMLRestProperties.PROP_PDP_HTTP_HEADER_HB, status.getStatus().toString()); + } + } + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Ended"); + im.endTransaction(); + + } + + /** + * POST - We expect XACML requests to be posted by PEP applications. They can be in the form of XML or JSON according + * to the XACML 3.0 Specifications for both. + * + * + * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) + */ + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + ECOMPLoggingContext loggingContext = ECOMPLoggingUtils.getLoggingContextForRequest(request, baseLoggingContext); + loggingContext.transactionStarted(); + loggingContext.setServiceName("PDP.decide"); + if ((loggingContext.getRequestID() == null) || (loggingContext.getRequestID() == "")){ + UUID requestID = UUID.randomUUID(); + loggingContext.setRequestID(requestID.toString()); + PolicyLogger.info("requestID not provided in call to XACMLPdpSrvlet (doPost) so we generated one"); + } else { + PolicyLogger.info("requestID was provided in call to XACMLPdpSrvlet (doPost)"); + } + loggingContext.metricStarted(); + loggingContext.metricEnded(); + PolicyLogger.metrics("Metric example posted here - 1 of 2"); + loggingContext.metricStarted(); + loggingContext.metricEnded(); + PolicyLogger.metrics("Metric example posted here - 2 of 2"); + monitor.pdpEvaluationAttempts(); + + try { + im.startTransaction(); + } + catch (AdministrativeStateException | StandbyStatusException e) { + String message = e.toString(); + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, message); + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message); + return; + } + // + // no point in doing any work if we know from the get-go that we cannot do anything with the request + // + if (status.getLoadedRootPolicies().size() == 0) { + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Request from PEP at " + request.getRequestURI() + " for service when PDP has No Root Policies loaded"); + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, "Request from PEP at " + request.getRequestURI() + " for service when PDP has No Root Policies loaded"); + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE); + im.endTransaction(); + return; + } + + XACMLRest.dumpRequest(request); + // + // Set our no-cache header + // + response.setHeader("Cache-Control", "no-cache"); + // + // They must send a Content-Type + // + if (request.getContentType() == null) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Must specify a Content-Type"); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "Must specify a Content-Type"); + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(HttpServletResponse.SC_BAD_REQUEST, "no content-type given"); + im.endTransaction(); + return; + } + // + // Limit the Content-Length to something reasonable + // + if (request.getContentLength() > Integer.parseInt(XACMLProperties.getProperty("MAX_CONTENT_LENGTH", "32767"))) { + String message = "Content-Length larger than server will accept."; + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + message); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, message); + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(HttpServletResponse.SC_BAD_REQUEST, message); + im.endTransaction(); + return; + } + if (request.getContentLength() <= 0) { + String message = "Content-Length is negative"; + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + message); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, message); + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(HttpServletResponse.SC_BAD_REQUEST, message); + im.endTransaction(); + return; + } + ContentType contentType = null; + try { + contentType = ContentType.parse(request.getContentType()); + } + catch (Exception e) { + String message = "Parsing Content-Type: " + request.getContentType() + ", error=" + e.getMessage(); + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + message, e); + loggingContext.transactionEnded(); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, message); + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(HttpServletResponse.SC_BAD_REQUEST, message); + im.endTransaction(); + return; + } + // + // What exactly did they send us? + // + String incomingRequestString = null; + Request pdpRequest = null; + if (contentType.getMimeType().equalsIgnoreCase(ContentType.APPLICATION_JSON.getMimeType()) || + contentType.getMimeType().equalsIgnoreCase(ContentType.APPLICATION_XML.getMimeType()) || + contentType.getMimeType().equalsIgnoreCase("application/xacml+xml") ) { + // + // Read in the string + // + StringBuilder buffer = new StringBuilder(); + BufferedReader reader = new BufferedReader(new InputStreamReader(request.getInputStream())); + String line; + while((line = reader.readLine()) != null){ + buffer.append(line); + } + incomingRequestString = buffer.toString(); + logger.info(incomingRequestString); + // + // Parse into a request + // + try { + if (contentType.getMimeType().equalsIgnoreCase(ContentType.APPLICATION_JSON.getMimeType())) { + pdpRequest = JSONRequest.load(incomingRequestString); + } else if ( contentType.getMimeType().equalsIgnoreCase(ContentType.APPLICATION_XML.getMimeType()) || + contentType.getMimeType().equalsIgnoreCase("application/xacml+xml")) { + pdpRequest = DOMRequest.load(incomingRequestString); + } + } + catch(Exception e) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Could not parse request", e); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "Could not parse request"); + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(HttpServletResponse.SC_BAD_REQUEST, e.getMessage()); + im.endTransaction(); + return; + } + } else { + String message = "unsupported content type" + request.getContentType(); + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + message); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, message); + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(HttpServletResponse.SC_BAD_REQUEST, message); + im.endTransaction(); + return; + } + // + // Did we successfully get and parse a request? + // + if (pdpRequest == null || pdpRequest.getRequestAttributes() == null || pdpRequest.getRequestAttributes().size() <= 0) { + String message = "Zero Attributes found in the request"; + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + message); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, message); + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(HttpServletResponse.SC_BAD_REQUEST, message); + im.endTransaction(); + return; + } + // + // Run it + // + try { + // + // Authenticating the Request here. + // + if(!authorizeRequest(request, pdpRequest)){ + String message = "PEP not Authorized for making this Request!! \n Contact Administrator for this Scope. "; + logger.error(XACMLErrorConstants.ERROR_PERMISSIONS + message ); + PolicyLogger.error(MessageCodes.ERROR_PERMISSIONS, message); + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(HttpServletResponse.SC_FORBIDDEN, message); + im.endTransaction(); + return; + } + // + // Get the pointer to the PDP Engine + // + PDPEngine myEngine = null; + synchronized(pdpEngineLock) { + myEngine = this.pdpEngine; + } + if (myEngine == null) { + String message = "No engine loaded."; + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + message); + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, message); + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message); + im.endTransaction(); + return; + } + // + // Send the request and save the response + // + long lTimeStart, lTimeEnd; + Response pdpResponse = null; + +//TODO - Make this unnecessary +//TODO It seems that the PDP Engine is not thread-safe, so when a configuration change occurs in the middle of processing +//TODO a PEP Request, that Request fails (it throws a NullPointerException in the decide() method). +//TODO Using synchronize will slow down processing of PEP requests, possibly by a significant amount. +//TODO Since configuration changes are rare, it would be A Very Good Thing if we could eliminate this sychronized block. +//TODO +//TODO This problem was found by starting one PDP then +//TODO RestLoadTest switching between 2 configurations, 1 second apart +//TODO both configurations contain the datarouter policy +//TODO both configurations already have all policies cached in the PDPs config directory +//TODO RestLoadTest started with the Datarouter test requests, 5 threads, no interval +//TODO With that configuration this code (without the synchronized) throws a NullPointerException +//TODO within a few seconds. +// +synchronized(pdpEngineLock) { + myEngine = this.pdpEngine; + try { + PolicyList.clearPolicyList(); + lTimeStart = System.currentTimeMillis(); + pdpResponse = myEngine.decide(pdpRequest); + lTimeEnd = System.currentTimeMillis(); + } catch (PDPException e) { + String message = "Exception during decide: " + e.getMessage(); + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + message); + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, message); + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message); + im.endTransaction(); + return; + } +} + monitor.computeLatency(lTimeEnd - lTimeStart); + requestLogger.info(lTimeStart + "=" + incomingRequestString); + for(String policy : PolicyList.getpolicyList()){ + monitor.policyCountAdd(policy, 1); + } + + + logger.info("PolicyID triggered in Request: " + PolicyList.getpolicyList()); + + //need to go through the list and find out if the value is unique and then add it other wise +// monitor.policyCountAdd(PolicyList.getpolicyList(), 1); + + if (logger.isDebugEnabled()) { + logger.debug("Request time: " + (lTimeEnd - lTimeStart) + "ms"); + } + // + // Convert Response to appropriate Content-Type + // + if (pdpResponse == null) { + requestLogger.info(lTimeStart + "=" + "{}"); + throw new Exception("Failed to get response from PDP engine."); + } + // + // Set our content-type + // + response.setContentType(contentType.getMimeType()); + // + // Convert the PDP response object to a String to + // return to our caller as well as dump to our loggers. + // + String outgoingResponseString = ""; + if (contentType.getMimeType().equalsIgnoreCase(ContentType.APPLICATION_JSON.getMimeType())) { + // + // Get it as a String. This is not very efficient but we need to log our + // results for auditing. + // + outgoingResponseString = JSONResponse.toString(pdpResponse, logger.isDebugEnabled()); + if (logger.isDebugEnabled()) { + logger.debug(outgoingResponseString); + // + // Get rid of whitespace + // + outgoingResponseString = JSONResponse.toString(pdpResponse, false); + } + } else if ( contentType.getMimeType().equalsIgnoreCase(ContentType.APPLICATION_XML.getMimeType()) || + contentType.getMimeType().equalsIgnoreCase("application/xacml+xml")) { + // + // Get it as a String. This is not very efficient but we need to log our + // results for auditing. + // + outgoingResponseString = DOMResponse.toString(pdpResponse, logger.isDebugEnabled()); + if (logger.isDebugEnabled()) { + logger.debug(outgoingResponseString); + // + // Get rid of whitespace + // + outgoingResponseString = DOMResponse.toString(pdpResponse, false); + } + } + // adding the jmx values for NA, Permit and Deny + // + if (outgoingResponseString.contains("NotApplicable") || outgoingResponseString.contains("Decision not a Permit")){ + monitor.pdpEvaluationNA(); + } + + if (outgoingResponseString.contains("Permit") && !outgoingResponseString.contains("Decision not a Permit")){ + monitor.pdpEvaluationPermit(); + } + + if (outgoingResponseString.contains("Deny")){ + monitor.pdpEvaluationDeny(); + } + // + // lTimeStart is used as an ID within the requestLogger to match up + // request's with responses. + // + requestLogger.info(lTimeStart + "=" + outgoingResponseString); + response.getWriter().print(outgoingResponseString); + } + catch (Exception e) { + String message = "Exception executing request: " + e; + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + message, e); + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, message); + loggingContext.transactionEnded(); + PolicyLogger.audit("Transaction Failed - See Error.log"); + response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message); + return; + } + + monitor.pdpEvaluationSuccess(); + response.setStatus(HttpServletResponse.SC_OK); + + loggingContext.transactionEnded(); + auditLogger.info("Success"); + PolicyLogger.audit("Success"); + +} + + /* + * Added for Authorizing the PEP Requests for Environment check. + */ + private boolean authorizeRequest(HttpServletRequest request, Request pepRequest) { + if(request instanceof HttpServletRequest) { + // Get the client Credentials from the Request header. + HttpServletRequest httpServletRequest = (HttpServletRequest) request; + String clientCredentials = httpServletRequest.getHeader(ENVIORNMENT_HEADER); + if(clientCredentials!=null && clientCredentials.equalsIgnoreCase(environment)){ + return true; + }else{ + return false; + } + }else{ + return false; + } + } + + @Override + public void run() { + // + // Keep running until we are told to terminate + // + try { + // variable not used, but constructor has needed side-effects so don't remove: + ECOMPLoggingContext loggingContext = new ECOMPLoggingContext(baseLoggingContext); + while (! this.configThreadTerminate) { + PutRequest request = XACMLPdpServlet.queue.take(); + StdPDPStatus newStatus = new StdPDPStatus(); + +//TODO - This is related to the problem discussed in the doPost() method about the PDPEngine not being thread-safe. +//TODO See that discussion, and when the PDPEngine is made thread-safe it should be ok to move the loadEngine out of +//TODO the synchronized block. +//TODO However, since configuration changes should be rare we may not care about changing this. +PDPEngine newEngine = null; + synchronized(pdpStatusLock) { + XACMLPdpServlet.status.setStatus(Status.UPDATING_CONFIGURATION); +newEngine = XACMLPdpLoader.loadEngine(newStatus, request.policyProperties, request.pipConfigProperties); + } +// PDPEngine newEngine = XACMLPdpLoader.loadEngine(newStatus, request.policyProperties, request.pipConfigProperties); + if (newEngine != null) { + synchronized(XACMLPdpServlet.pdpEngineLock) { + this.pdpEngine = newEngine; + try { + logger.info("Saving configuration."); + if (request.policyProperties != null) { + try (OutputStream os = Files.newOutputStream(XACMLPdpLoader.getPDPPolicyCache())) { + request.policyProperties.store(os, ""); + } + } + if (request.pipConfigProperties != null) { + try (OutputStream os = Files.newOutputStream(XACMLPdpLoader.getPIPConfig())) { + request.pipConfigProperties.store(os, ""); + } + } + newStatus.setStatus(Status.UP_TO_DATE); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Failed to store new properties."); + PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, "Failed to store new properties"); + newStatus.setStatus(Status.LOAD_ERRORS); + newStatus.addLoadWarning("Unable to save configuration: " + e.getMessage()); + } + } + } else { + newStatus.setStatus(Status.LAST_UPDATE_FAILED); + } + synchronized(pdpStatusLock) { + XACMLPdpServlet.status.set(newStatus); + } + } + } catch (InterruptedException e) { + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "interrupted"); + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, "interrupted"); + } + } + +} diff --git a/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/impl/XACMLPdpPIPFinderFactory.java b/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/impl/XACMLPdpPIPFinderFactory.java new file mode 100644 index 000000000..3c8b67f31 --- /dev/null +++ b/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/impl/XACMLPdpPIPFinderFactory.java @@ -0,0 +1,88 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.openecomp.policy.pdp.rest.impl; + +import java.util.Properties; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.eelf.PolicyLogger; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; +import com.att.research.xacml.api.pip.PIPException; +import com.att.research.xacml.api.pip.PIPFinder; +import com.att.research.xacml.api.pip.PIPFinderFactory; +import com.att.research.xacml.std.pip.finders.ConfigurableEngineFinder; +import com.att.research.xacml.util.XACMLProperties; + +public class XACMLPdpPIPFinderFactory extends PIPFinderFactory { + private ConfigurableEngineFinder pipFinder; + + private static Log logger = LogFactory.getLog(XACMLPdpPIPFinderFactory.class); + + public XACMLPdpPIPFinderFactory() { + } + + public XACMLPdpPIPFinderFactory(Properties properties) { + } + + @Override + public PIPFinder getFinder() throws PIPException { + if (pipFinder == null) { + synchronized(this) { + if (pipFinder == null) { + if (logger.isDebugEnabled()) { + logger.debug("Creating default configurable engine finder"); + } + pipFinder = new ConfigurableEngineFinder(); + Properties xacmlProperties = null; + try { + xacmlProperties = XACMLProperties.getProperties(); + } catch (Exception ex) { + logger.error( XACMLErrorConstants.ERROR_SYSTEM_ERROR+ "Exception getting XACML properties: " + ex.getMessage(), ex); + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, ex, "Exception getting XACML properties"); + return null; + } + if (xacmlProperties != null) { + ((ConfigurableEngineFinder)pipFinder).configure(xacmlProperties); + } + } + } + } + return pipFinder; + } + + @Override + public PIPFinder getFinder(Properties properties) throws PIPException { + if (pipFinder == null) { + synchronized(this) { + if (pipFinder == null) { + if (logger.isDebugEnabled()) { + logger.debug("Creating configurable engine finder using: " + properties); + } + pipFinder = new ConfigurableEngineFinder(); + ((ConfigurableEngineFinder)pipFinder).configure(properties); + } + } + } + return this.pipFinder; + } +} diff --git a/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/impl/XACMLPdpPolicyFinderFactory.java b/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/impl/XACMLPdpPolicyFinderFactory.java new file mode 100644 index 000000000..9335bef6c --- /dev/null +++ b/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/impl/XACMLPdpPolicyFinderFactory.java @@ -0,0 +1,208 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.rest.impl; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; +import com.att.research.xacml.std.StdStatusCode; +import com.att.research.xacml.std.dom.DOMStructureException; +import com.att.research.xacml.util.FactoryException; +import com.att.research.xacml.util.XACMLProperties; +import com.att.research.xacmlatt.pdp.policy.Policy; +import com.att.research.xacmlatt.pdp.policy.PolicyDef; +import com.att.research.xacmlatt.pdp.policy.PolicyFinder; +import com.att.research.xacmlatt.pdp.policy.PolicyFinderFactory; +import com.att.research.xacmlatt.pdp.policy.dom.DOMPolicyDef; +import com.att.research.xacmlatt.pdp.std.StdPolicyFinder; +import com.google.common.base.Splitter; + +public class XACMLPdpPolicyFinderFactory extends PolicyFinderFactory { + public static final String PROP_FILE = ".file"; + public static final String PROP_URL = ".url"; + + private static Log logger = LogFactory.getLog(XACMLPdpPolicyFinderFactory.class); + private List rootPolicies; + private List referencedPolicies; + private boolean needsInit = true; + + private Properties properties = null; + + public XACMLPdpPolicyFinderFactory() { + // + // Here we differ from the StdPolicyFinderFactory in that we initialize right away. + // We do not wait for a policy request to happen to look for and load policies. + // + this.init(); + } + + public XACMLPdpPolicyFinderFactory(Properties properties) { + // + // Save our properties + // + this.properties = properties; + // + // Here we differ from the StdPolicyFinderFactory in that we initialize right away. + // We do not wait for a policy request to happen to look for and load policies. + // + this.init(); + } + + /** + * Loads the PolicyDef for the given String identifier by looking first + * for a ".file" property associated with the ID and using that to load from a File and + * looking for a ".url" property associated with the ID and using that to load from a URL. + * + * @param policyId the String identifier for the policy + * @return a PolicyDef loaded from the given identifier + */ + protected PolicyDef loadPolicyDef(String policyId) { + String propLocation = null; + if (this.properties == null) { + propLocation = XACMLProperties.getProperty(policyId + PROP_FILE); + } else { + propLocation = this.properties.getProperty(policyId + PROP_FILE); + } + if (propLocation != null) { + File fileLocation = new File(propLocation); + if (!fileLocation.exists()) { + XACMLPdpPolicyFinderFactory.logger.error("Policy file " + fileLocation.getAbsolutePath() + " does not exist."); + } else if (!fileLocation.canRead()) { + XACMLPdpPolicyFinderFactory.logger.error("Policy file " + fileLocation.getAbsolutePath() + " cannot be read."); + } else { + try { + XACMLPdpPolicyFinderFactory.logger.info("Loading policy file " + fileLocation); + PolicyDef policyDef = DOMPolicyDef.load(fileLocation); + if (policyDef != null) { + return policyDef; + } + } catch (DOMStructureException ex) { + XACMLPdpPolicyFinderFactory.logger.error( XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Error loading policy file " + fileLocation.getAbsolutePath() + ": " + ex.getMessage(), ex); + return new Policy(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, ex.getMessage()); + } + } + } + if (this.properties == null) { + propLocation = XACMLProperties.getProperty(policyId + PROP_URL); + } else { + propLocation = this.properties.getProperty(policyId + PROP_URL); + } + if (propLocation != null) { + InputStream is = null; + try { + URL url = new URL(propLocation); + URLConnection urlConnection = url.openConnection(); + XACMLPdpPolicyFinderFactory.logger.info("Loading policy file " + url.toString()); + is = urlConnection.getInputStream(); + PolicyDef policyDef = DOMPolicyDef.load(is); + if (policyDef != null) { + return policyDef; + } + } catch (MalformedURLException ex) { + XACMLPdpPolicyFinderFactory.logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Invalid URL " + propLocation + ": " + ex.getMessage(), ex); + } catch (IOException ex) { + XACMLPdpPolicyFinderFactory.logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "IOException opening URL " + propLocation + ": " + ex.getMessage(), ex); + } catch (DOMStructureException ex) { + XACMLPdpPolicyFinderFactory.logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Invalid Policy " + propLocation + ": " + ex.getMessage(), ex); + return new Policy(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, ex.getMessage()); + } finally { + if (is != null) { + try { + is.close(); + } catch (IOException e) { + XACMLPdpPolicyFinderFactory.logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Exception closing InputStream for GET of url " + propLocation + " : " + e.getMessage() + " (May be memory leak)", e); + } + } + } + } + + XACMLPdpPolicyFinderFactory.logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR +"No known location for Policy " + policyId); + return null; + } + + /** + * Finds the identifiers for all of the policies referenced by the given property name in the + * XACMLProperties and loads them using the requested loading method. + * + * @param propertyName the String name of the property containing the list of policy identifiers + * @return a List of PolicyDefs loaded from the given property name + */ + protected List getPolicyDefs(String propertyName) { + String policyIds = XACMLProperties.getProperty(propertyName); + if (policyIds == null || policyIds.length() == 0) { + return null; + } + + Iterable policyIdArray = Splitter.on(',').trimResults().omitEmptyStrings().split(policyIds); + if (policyIdArray == null) { + return null; + } + + List listPolicyDefs = new ArrayList(); + for (String policyId : policyIdArray) { + PolicyDef policyDef = this.loadPolicyDef(policyId); + if (policyDef != null) { + listPolicyDefs.add(policyDef); + } + } + return listPolicyDefs; + } + + protected synchronized void init() { + if (this.needsInit) { + if (XACMLPdpPolicyFinderFactory.logger.isDebugEnabled()) { + XACMLPdpPolicyFinderFactory.logger.debug("Initializing"); + } + this.rootPolicies = this.getPolicyDefs(XACMLProperties.PROP_ROOTPOLICIES); + this.referencedPolicies = this.getPolicyDefs(XACMLProperties.PROP_REFERENCEDPOLICIES); + if (XACMLPdpPolicyFinderFactory.logger.isDebugEnabled()) { + XACMLPdpPolicyFinderFactory.logger.debug("Root Policies: " + this.rootPolicies); + XACMLPdpPolicyFinderFactory.logger.debug("Referenced Policies: " + this.referencedPolicies); + } + this.needsInit = false; + } + } + + @Override + public PolicyFinder getPolicyFinder() throws FactoryException { + // + // Force using any properties that were passed upon construction + // + return new StdPolicyFinder(this.rootPolicies, this.referencedPolicies, this.properties); + } + + @Override + public PolicyFinder getPolicyFinder(Properties properties) throws FactoryException { + return new StdPolicyFinder(this.rootPolicies, this.referencedPolicies, properties); + } + +} diff --git a/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/jmx/PdpRestMBeanListener.java b/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/jmx/PdpRestMBeanListener.java new file mode 100644 index 000000000..309bd1502 --- /dev/null +++ b/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/jmx/PdpRestMBeanListener.java @@ -0,0 +1,87 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.rest.jmx; + +import java.lang.management.ManagementFactory; + +import javax.management.MBeanServer; +import javax.management.ObjectName; +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; +import javax.servlet.annotation.WebListener; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openecomp.policy.common.logging.flexlogger.*; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; +/** + * + * + */ + +@WebListener +public class PdpRestMBeanListener implements ServletContextListener { + private static final String JMX_OBJECT_NAME = "PdpRest:type=PdpRestMonitor"; + private static final Logger logger = FlexLogger.getLogger(PdpRestMBeanListener.class); + + private ObjectName objectName; + + @Override + public void contextInitialized(ServletContextEvent contextEvent) { + if (logger.isInfoEnabled()) + logger.info("Registering."); + + final MBeanServer server = ManagementFactory.getPlatformMBeanServer(); + try { + objectName = new ObjectName(JMX_OBJECT_NAME); + server.registerMBean(PdpRestMonitor.singleton, objectName); + logger.info("MBean registered: " + objectName); + } catch (Exception e) { + + logger.warn(e.getMessage(), e); + + logger.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Unable to Register " +e.getMessage(), e); + + } + } + // mark + @Override + public void contextDestroyed(ServletContextEvent contextEvent) { + if (logger.isInfoEnabled()) + logger.info("Unregistering"); + final MBeanServer server = ManagementFactory.getPlatformMBeanServer(); + try { + objectName = new ObjectName(JMX_OBJECT_NAME); + server.unregisterMBean(objectName); + if (logger.isInfoEnabled()) + logger.info("MBean unregistered: " + objectName); + } catch (Exception e) { + + logger.warn(e.getMessage(), e); + + logger.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Unable to Destroy Context" +e.getMessage(), e); + + } + } + +} + diff --git a/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/jmx/PdpRestMonitor.java b/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/jmx/PdpRestMonitor.java new file mode 100644 index 000000000..93dfbe6a0 --- /dev/null +++ b/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/jmx/PdpRestMonitor.java @@ -0,0 +1,161 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.rest.jmx; + +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.concurrent.atomic.AtomicLong; +import java.util.concurrent.atomic.AtomicReference; +import java.util.function.BinaryOperator; + +import org.openecomp.policy.xacml.util.MetricsUtil.AvgLatency; +import org.openecomp.policy.xacml.util.MetricsUtil.MaxLatency; +import org.openecomp.policy.xacml.util.MetricsUtil.MinLatency; + +public class PdpRestMonitor implements PdpRestMonitorMBean { + public static PdpRestMonitor singleton = new PdpRestMonitor(); + + private final AtomicLong pdpEvaluationAttempts = new AtomicLong(); + private final AtomicLong pdpEvaluationSuccesses = new AtomicLong(); + private final AtomicLong pdpEvaluationNA = new AtomicLong(); + private final AtomicLong pdpEvaluationPermit = new AtomicLong(); + private final AtomicLong pdpEvaluationDeny = new AtomicLong(); + private final Map policyCount = new HashMap<>(); + + private final MinLatency pdpEngineDecisionMinLatency = new MinLatency(); + private final MaxLatency pdpEngineDecisionMaxLatency = new MaxLatency(); + private final AvgLatency pdpEngineDecisionAvgLatency = new AvgLatency(); + + private volatile long lastDecisionLatency = 0; + + @Override + public long getPdpEvaluationAttempts() { + return pdpEvaluationAttempts.longValue(); + } + @Override + public long getPdpEvaluationPermit() { + return pdpEvaluationPermit.longValue(); + } + @Override + public long getPdpEvaluationDeny() { + return pdpEvaluationDeny.longValue(); + } + @Override + public long getPdpEvaluationSuccesses() { + return pdpEvaluationSuccesses.longValue(); + } + + @Override + public long getpdpEvaluationNA() { + return pdpEvaluationNA.longValue(); + } + @Override + public long getLastDecisionLatency() { + return lastDecisionLatency; + } + + /** + * @return the pdpEngineDecisionMinLatency + */ + @Override + public long getPdpEngineDecisionMinLatency() { + return pdpEngineDecisionMinLatency.min(); + } + + /** + * @return the pdpEngineDecisionMaxLatency + */ + @Override + public long getPdpEngineDecisionMaxLatency() { + return pdpEngineDecisionMaxLatency.max(); + } + + /** + * @return the pdpEngineDecisionAvgLatency + */ + @Override + public long getPdpEngineDecisionAvgLatency() { + return pdpEngineDecisionAvgLatency.avg(); + } + + @Override + public synchronized void resetLatency() { + this.lastDecisionLatency = 0; + this.pdpEngineDecisionMinLatency.reset(); + this.pdpEngineDecisionMaxLatency.reset(); + this.pdpEngineDecisionAvgLatency.reset(); + } + + @Override + public synchronized void resetCounters() { + this.pdpEvaluationAttempts.set(0); + this.pdpEvaluationSuccesses.set(0); + this.pdpEvaluationNA.set(0); + this.policyCount.clear(); + } + + public void pdpEvaluationAttempts() { + pdpEvaluationAttempts.incrementAndGet(); + } + + public void pdpEvaluationSuccess() { + pdpEvaluationSuccesses.incrementAndGet(); + } + + public void pdpEvaluationNA(){ + pdpEvaluationNA.incrementAndGet(); + } + public void pdpEvaluationPermit(){ + pdpEvaluationPermit.incrementAndGet(); + } + public void pdpEvaluationDeny(){ + pdpEvaluationDeny.incrementAndGet(); + } + + public synchronized void computeLatency(long latency) { + this.lastDecisionLatency = latency; + this.pdpEngineDecisionMinLatency.compute(latency); + this.pdpEngineDecisionMaxLatency.compute(latency); + this.pdpEngineDecisionAvgLatency.compute(latency); + } + + public void policyCountAdd(String policyID, Integer count){ + if (policyCount.containsKey(policyID)){ + count = count + policyCount.get(policyID); + } + policyCount.put(policyID, count); + } + public Map getpolicyMap() { + return policyCount; + } + public Integer getpolicyCount(String policyID) { + // TODO Auto-generated method stub + if (policyCount.containsKey(policyID)){ + return policyCount.get(policyID); + } + return null; + } + + + +} diff --git a/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/jmx/PdpRestMonitorMBean.java b/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/jmx/PdpRestMonitorMBean.java new file mode 100644 index 000000000..e7db09d24 --- /dev/null +++ b/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/jmx/PdpRestMonitorMBean.java @@ -0,0 +1,40 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.rest.jmx; + +import java.util.Map; + +public interface PdpRestMonitorMBean { + public long getPdpEvaluationAttempts(); + public long getPdpEvaluationSuccesses(); + public long getLastDecisionLatency(); + public long getPdpEngineDecisionMinLatency(); + public long getPdpEngineDecisionMaxLatency(); + public long getPdpEngineDecisionAvgLatency(); + public Integer getpolicyCount(String policyID); + + public void resetLatency(); + public void resetCounters(); + public long getpdpEvaluationNA(); + public long getPdpEvaluationPermit(); + public long getPdpEvaluationDeny(); + public Map getpolicyMap(); +} diff --git a/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/notifications/ManualNotificationUpdateThread.java b/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/notifications/ManualNotificationUpdateThread.java new file mode 100644 index 000000000..6b8857273 --- /dev/null +++ b/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/notifications/ManualNotificationUpdateThread.java @@ -0,0 +1,151 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.rest.notifications; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.security.GeneralSecurityException; +import java.util.LinkedList; +import java.util.UUID; + +import org.openecomp.policy.rest.XACMLRestProperties; + +import com.att.nsa.cambria.client.CambriaClientFactory; +import com.att.nsa.cambria.client.CambriaConsumer; +import com.att.nsa.cambria.client.CambriaPublisher; +import org.openecomp.policy.xacml.api.XACMLErrorConstants; +import com.att.research.xacml.util.XACMLProperties; + +import org.openecomp.policy.common.logging.flexlogger.*; + +public class ManualNotificationUpdateThread implements Runnable { + private static final Logger logger = FlexLogger.getLogger(ManualNotificationUpdateThread.class); +// private static List uebURLList = null; + private static String topic = null; + private static CambriaConsumer CConsumer = null; +// private static Collection clusterList = null; + private static String clusterList = null; +// private Collection urlList = null; + private static String update = null; + + public volatile boolean isRunning = false; + + public synchronized boolean isRunning() { + return this.isRunning; + } + + public synchronized void terminate() { + this.isRunning = false; + } + + /** + * + * This is our thread that runs on startup if the system is configured to UEB to accept manual update requests + * + */ + @Override + public void run() { + synchronized(this) { + this.isRunning = true; + } + URL aURL = null; + String group = UUID.randomUUID ().toString (); + String id = "0"; + String returnTopic = null; + try { + ManualNotificationUpdateThread.clusterList = XACMLProperties.getProperty(XACMLRestProperties.PROP_NOTIFICATION_UEB_CLUSTER); + String url = XACMLProperties.getProperty(XACMLRestProperties.PROP_PDP_ID); + aURL = new URL(url); + topic = aURL.getHost() + aURL.getPort(); + } catch (NumberFormatException e) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Unable to get UEB cluster list or pdp url: ", e); + this.isRunning = false; + } catch (MalformedURLException e) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Error in processing URL to create topic for Notification ", e); + } + String consumerTopic = aURL.getHost() + aURL.getPort() + "UpdateRequest"; + SendMessage(consumerTopic, "Starting-Topic"); + final LinkedList urlList = new LinkedList (); + for ( String u : clusterList.split ( "," ) ){ + urlList.add ( u ); + } + + try { + CConsumer = CambriaClientFactory.createConsumer ( null, urlList, consumerTopic , group, id, 20*1000, 1000 ); + } catch (MalformedURLException | GeneralSecurityException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + + while (this.isRunning()) { + logger.debug("While loop test _ take out "); + try { + for ( String msg : CConsumer.fetch () ){ + logger.debug("Manual Notification Recieved Message " + msg + " from UEB cluster : "); + returnTopic = processMessage(msg); + if(returnTopic != null){ + SendMessage(returnTopic, update); + } + } + } catch (IOException e) { + logger.debug(XACMLErrorConstants.ERROR_DATA_ISSUE + "Error in processing UEB message"); + } + } + logger.debug("Stopping UEB Consuer loop will not logger fetch messages from the cluser"); + + } + + private void SendMessage( String topic, String message) { + CambriaPublisher pub = null; + try { + pub = CambriaClientFactory.createSimplePublisher (null, clusterList, topic ); + } catch (MalformedURLException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } catch (GeneralSecurityException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + try { + pub.send( "pdpReturnMessage", message ); + logger.debug("Sending to Message to tpoic" + topic); + } catch (IOException e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW+ "Error sending notification update"); + } + pub.close(); + } + + private String processMessage(String msg) { + logger.debug("notification message: " + msg); + String[] UID = msg.split("=")[1].split("\""); + String returnTopic = topic + UID[0]; + if(msg.contains("Starting-Topic")){ + return null; + } + return returnTopic; + } + public static void setUpdate(String update) { + ManualNotificationUpdateThread.update = update; + } + +} diff --git a/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/notifications/Notification.java b/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/notifications/Notification.java new file mode 100644 index 000000000..5ab165b0a --- /dev/null +++ b/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/notifications/Notification.java @@ -0,0 +1,52 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.rest.notifications; + +import java.util.Collection; + +/** + * Notification is the POJO which will be used to send the Notifications to the Server. + * Notification must contain the Removal and Updated policies. + * + * @version 0.1 + * + */ +public class Notification { + private Collection removedPolicies = null; + private Collection loadedPolicies = null; + + public Collection getRemovedPolicies() { + return removedPolicies; + } + + public void setRemovedPolicies(Collection removedPolicies) { + this.removedPolicies = removedPolicies; + } + + public Collection getLoadedPolicies() { + return loadedPolicies; + } + + public void setLoadedPolicies(Collection loadedPolicies) { + this.loadedPolicies = loadedPolicies; + } + +} diff --git a/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/notifications/NotificationController.java b/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/notifications/NotificationController.java new file mode 100644 index 000000000..1dfd07422 --- /dev/null +++ b/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/notifications/NotificationController.java @@ -0,0 +1,391 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.rest.notifications; + +import java.io.File; +import java.io.FileFilter; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; + +import org.apache.commons.io.IOUtils; +import org.apache.commons.io.filefilter.WildcardFileFilter; +import org.openecomp.policy.pdp.rest.PapUrlResolver; +import org.openecomp.policy.rest.XACMLRestProperties; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; +import com.att.research.xacml.api.pap.PDPPolicy; +import com.att.research.xacml.api.pap.PDPStatus; +import com.att.research.xacml.util.XACMLProperties; +import com.att.research.xacmlatt.pdp.policy.AllOf; +import com.att.research.xacmlatt.pdp.policy.AnyOf; +import com.att.research.xacmlatt.pdp.policy.Match; +import com.att.research.xacmlatt.pdp.policy.PolicyDef; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; + +/** + * NotificationController Checks for the Updated and Removed policies. It + * notifies the Server to send Notifications to the Client. + * + * @version 0.2 + * + */ +public class NotificationController { + private static final Logger logger = FlexLogger.getLogger(NotificationController.class); + private static Notification record = new Notification(); + private PDPStatus oldStatus = null; + private Removed removed = null; + private Updated updated = null; + private ManualNotificationUpdateThread registerMaunualNotificationRunnable = null; + private Thread manualNotificationThread = null; + private boolean manualThreadStarted = false; + + private static String notificationJSON = null; + private static String propNotificationType = null; + private static String pdpURL = null; + private static Boolean notificationFlag = false; + + public void check(PDPStatus newStatus,HashMap policyContainer) { + boolean updated = false; + boolean removed = false; + Notification notification = new Notification(); + HashSet removedPolicies = new HashSet(); + HashSet updatedPolicies = new HashSet(); + + if (oldStatus == null) { + oldStatus = newStatus; + } + // Debugging purpose only. + logger.debug("old config Status :" + oldStatus.getStatus()); + logger.debug("new config Status :" + newStatus.getStatus()); + + // Depending on the above condition taking the Change as an Update. + if (oldStatus.getStatus().toString() != newStatus.getStatus().toString()) { + logger.info("There is an Update to the PDP"); + logger.debug(oldStatus.getLoadedPolicies()); + logger.debug(newStatus.getLoadedPolicies()); + // Check if there is an Update/additions in the policy. + for (PDPPolicy newPolicy : newStatus.getLoadedPolicies()) { + boolean change = true; + for (PDPPolicy oldPolicy : oldStatus.getLoadedPolicies()) { + // Check if there are same policies. + if (oldPolicy.getId().equals(newPolicy.getId())) { + // Check if they have same version. + if (oldPolicy.getVersion().equals(newPolicy.getVersion())) { + change = false; + } + } + } + // if there is a change Send the notifications to the Client. + if (change) { + sendUpdate(newPolicy, policyContainer); + updated = true; + updatedPolicies.add(this.updated); + } + } + // Check if there is any removal of policy. + for (PDPPolicy oldPolicy : oldStatus.getLoadedPolicies()) { + boolean change = true; + for (PDPPolicy newPolicy : newStatus.getLoadedPolicies()) { + // Check if there are same policies. + if (oldPolicy.getId().equals(newPolicy.getId())) { + // Check if they have same version. + if (oldPolicy.getVersion().equals(newPolicy.getVersion())) { + change = false; + } + } + } + // if there is a change Send the notifications to the Client. + if (change) { + sendremove(oldPolicy); + removed = true; + removedPolicies.add(this.removed); + } + } + } + // At the end the oldStatus must be updated with the newStatus. + oldStatus = newStatus; + // Sending Notification to the Server to pass over to the clients + if (updated || removed) { + // Call the Notification Server.. + notification.setRemovedPolicies(removedPolicies); + notification.setLoadedPolicies(updatedPolicies); + ObjectWriter om = new ObjectMapper().writer(); + try { + notificationJSON = om.writeValueAsString(notification); + logger.info(notificationJSON); + // NotificationServer Method here. + propNotificationType = XACMLProperties.getProperty(XACMLRestProperties.PROP_NOTIFICATION_TYPE); + pdpURL = XACMLProperties.getProperty(XACMLRestProperties.PROP_PDP_ID); + if (propNotificationType!=null && propNotificationType.equals("ueb") && !manualThreadStarted) { + logger.debug("Starting Thread to accept UEB notfications."); + this.registerMaunualNotificationRunnable = new ManualNotificationUpdateThread(); + this.manualNotificationThread = new Thread(this.registerMaunualNotificationRunnable); + this.manualNotificationThread.start(); + manualThreadStarted = true; + } + String notificationJSON= null; + notificationFlag = true; + try{ + notificationJSON= record(notification); + }catch(Exception e){ + logger.error(e); + // TODO:EELF Cleanup - Remove logger + //PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, ""); + } + NotificationServer.setUpdate(notificationJSON); + ManualNotificationUpdateThread.setUpdate(notificationJSON); + } catch (JsonProcessingException e) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e.getMessage()); + // TODO:EELF Cleanup - Remove logger + //PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, ""); + } + } + } + + public static void sendNotification(){ + if(notificationFlag){ + NotificationServer.sendNotification(notificationJSON, propNotificationType, pdpURL); + notificationFlag = false; + } + } + + private void sendremove(PDPPolicy oldPolicy) { + removed = new Removed(); + // Want to know what is removed ? + // logger.info("The Policy removed is: " + oldPolicy.getId()); + // logger.info("The version no. is: " + oldPolicy.getVersion()); + logger.info("Policy removed: " + oldPolicy.getId()+ " with version number: " + oldPolicy.getVersion()); + removed.setPolicyName(oldPolicy.getId()); + removed.setVersionNo(oldPolicy.getVersion()); + removeFile(oldPolicy); + } + + private void sendUpdate(PDPPolicy newPolicy,HashMap policyContainer) { + updated = new Updated(); + // Want to know what is new ? + logger.info("The new Policy is: " + newPolicy.getId()); + logger.info("The version no. is: " + newPolicy.getVersion()); + updated.setPolicyName(newPolicy.getId()); + updated.setVersionNo(newPolicy.getVersion()); + // If the policy is of Config type then retrieve its matches. + if (newPolicy.getName().startsWith("Config")) { + // Take a Configuration copy to PDP webapps. + final String urlStart = "attributeId=URLID,expression"; + final String urlEnd = "}}},{"; + String policy = policyContainer.get(newPolicy.getId()).toString(); + if(policy.contains(urlStart)){ + String urlFinePartOne = policy.substring(policy.indexOf(urlStart)+urlStart.length()); + String urlFinePart = urlFinePartOne.substring(0,urlFinePartOne.indexOf(urlEnd)); + String urlString = urlFinePart.substring(urlFinePart.indexOf("value=$URL")+6); + callPap(urlString, "Config"); + } + Iterator anyOfs = policyContainer.get(newPolicy.getId()).getTarget().getAnyOfs(); + while (anyOfs.hasNext()) { + AnyOf anyOf = anyOfs.next(); + Iterator allOfs = anyOf.getAllOfs(); + while (allOfs.hasNext()) { + AllOf allOf = allOfs.next(); + Iterator matches = allOf.getMatches(); + HashMap matchValues = new HashMap(); + while (matches.hasNext()) { + Match match = matches.next(); + logger.info("Attribute Value is: "+ match.getAttributeValue().getValue().toString()); + String[] result = match.getAttributeRetrievalBase().toString().split("attributeId="); + result[1] = result[1].replaceAll("}", ""); + if (!result[1].equals("urn:oasis:names:tc:xacml:1.0:subject:subject-id")) { + logger.info("Attribute id is: " + result[1]); + } + matchValues.put(result[1], match.getAttributeValue().getValue().toString()); + logger.info("Match is : "+ result[1]+ " , " + match.getAttributeValue().getValue().toString()); + } + updated.setMatches(matchValues); + } + } + }else if(newPolicy.getName().startsWith("Action")){ + // Take Configuration copy to PDP Webapps. + // Action policies have .json as extension. + String urlString = "$URL/Action/" + newPolicy.getId().substring(0, newPolicy.getId().lastIndexOf(".")) + ".json"; + callPap(urlString, "Action"); + } + } + + // Adding this for Recording the changes to serve Polling requests.. + public static String record(Notification notification) throws Exception { + // Initialization with updates. + if (record.getRemovedPolicies() == null || record.getLoadedPolicies() == null) { + record.setRemovedPolicies(notification.getRemovedPolicies()); + record.setLoadedPolicies(notification.getLoadedPolicies()); + } else { + // Check if there is anything new and update the record.. + if (record.getLoadedPolicies() != null || record.getRemovedPolicies() != null) { + HashSet removedPolicies = (HashSet) record.getRemovedPolicies(); + HashSet updatedPolicies = (HashSet) record.getLoadedPolicies(); + + // Checking with New updated policies. + if (notification.getLoadedPolicies() != null && !notification.getLoadedPolicies().isEmpty()) { + for (Updated newUpdatedPolicy : notification.getLoadedPolicies()) { + // If it was removed earlier then we need to remove from our record + Iterator oldRemovedPolicy = removedPolicies.iterator(); + while (oldRemovedPolicy.hasNext()) { + Removed policy = oldRemovedPolicy.next(); + if (newUpdatedPolicy.getPolicyName().equals(policy.getPolicyName())) { + if (newUpdatedPolicy.getVersionNo().equals(policy.getVersionNo())) { + oldRemovedPolicy.remove(); + } + } + } + // If it was previously updated need to Overwrite it to the record. + Iterator oldUpdatedPolicy = updatedPolicies.iterator(); + while (oldUpdatedPolicy.hasNext()) { + Updated policy = oldUpdatedPolicy.next(); + if (newUpdatedPolicy.getPolicyName().equals(policy.getPolicyName())) { + if (newUpdatedPolicy.getVersionNo().equals(policy.getVersionNo())) { + oldUpdatedPolicy.remove(); + } + } + } + updatedPolicies.add(newUpdatedPolicy); + } + } + // Checking with New Removed policies. + if (notification.getRemovedPolicies() != null && !notification.getRemovedPolicies().isEmpty()) { + for (Removed newRemovedPolicy : notification.getRemovedPolicies()) { + // If it was previously removed Overwrite it to the record. + Iterator oldRemovedPolicy = removedPolicies.iterator(); + while (oldRemovedPolicy.hasNext()) { + Removed policy = oldRemovedPolicy.next(); + if (newRemovedPolicy.getPolicyName().equals(policy.getPolicyName())) { + if (newRemovedPolicy.getVersionNo().equals(policy.getVersionNo())) { + oldRemovedPolicy.remove(); + } + } + } + // If it was added earlier then we need to remove from our record. + Iterator oldUpdatedPolicy = updatedPolicies.iterator(); + while (oldUpdatedPolicy.hasNext()) { + Updated policy = oldUpdatedPolicy.next(); + if (newRemovedPolicy.getPolicyName().equals(policy.getPolicyName())) { + if (newRemovedPolicy.getVersionNo().equals(policy.getVersionNo())) { + oldUpdatedPolicy.remove(); + } + } + } + removedPolicies.add(newRemovedPolicy); + } + } + record.setRemovedPolicies(removedPolicies); + record.setLoadedPolicies(updatedPolicies); + } + } + // Send the Result to the caller. + ObjectWriter om = new ObjectMapper().writer(); + String json = null; + try { + json = om.writeValueAsString(record); + } catch (JsonProcessingException e) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e.getMessage()); + // TODO:EELF Cleanup - Remove logger + //PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, ""); + } + logger.info(json); + return json; + } + + private void removeFile(PDPPolicy oldPolicy) { + try{ + Path removedPolicyFile = Paths.get(XACMLProperties.getProperty(XACMLRestProperties.PROP_PDP_CONFIG)+File.separator+oldPolicy.getId()); + Files.deleteIfExists(removedPolicyFile); + boolean delete=false; + File dir= null; + if(oldPolicy.getName().startsWith("Config")){ + delete = true; + dir = new File(XACMLProperties.getProperty(XACMLRestProperties.PROP_PDP_WEBAPPS)+File.separator+"Config"); + }else if(oldPolicy.getName().startsWith("Action")){ + delete = true; + dir = new File(XACMLProperties.getProperty(XACMLRestProperties.PROP_PDP_WEBAPPS)+File.separator+"Action"); + } + if(delete && dir!=null){ + FileFilter fileFilter = new WildcardFileFilter(oldPolicy.getId().substring(0, oldPolicy.getId().lastIndexOf("."))+".*"); + File[] configFile = dir.listFiles(fileFilter); + if(configFile.length==1){ + Files.deleteIfExists(configFile[0].toPath()); + } + } + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Couldn't remove the policy/config file " + oldPolicy.getName()); + // TODO:EELF Cleanup - Remove logger + //PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "Couldn't remove the policy file " + oldPolicy.getName()); + } + } + + private void callPap(String urlString, String type) { + Path configLocation = Paths.get(XACMLProperties.getProperty(XACMLRestProperties.PROP_PDP_WEBAPPS)+File.separator+type); + if(Files.notExists(configLocation)){ + try { + Files.createDirectories(configLocation); + } catch (IOException e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW +"Failed to create config directory: " + configLocation.toAbsolutePath().toString(), e); + } + } + PapUrlResolver papUrls = PapUrlResolver.getInstance(); + while(papUrls.hasMoreUrls()){ + String papPath = papUrls.getUrl(); + papPath = papPath.substring(0, papPath.lastIndexOf("/pap")); + String papAddress= urlString.replace("$URL", papPath); + String fileName = papAddress.substring(papAddress.lastIndexOf("/")+1); + String fileLocation = configLocation.toString() + File.separator + fileName; + try { + URL papURL = new URL(papAddress); + logger.info("Calling " +papAddress + " for Configuration Copy."); + URLConnection urlConnection = papURL.openConnection(); + File file= new File(fileLocation); + try (InputStream is = urlConnection.getInputStream(); + OutputStream os = new FileOutputStream(file)) { + IOUtils.copy(is, os); + break; + } + } catch (MalformedURLException e) { + logger.error(e + e.getMessage()); + } catch(FileNotFoundException e){ + logger.error(e + e.getMessage()); + } catch (IOException e) { + logger.error(e + e.getMessage()); + } + papUrls.getNext(); + } + } +} diff --git a/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/notifications/NotificationServer.java b/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/notifications/NotificationServer.java new file mode 100644 index 000000000..d6cda7491 --- /dev/null +++ b/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/notifications/NotificationServer.java @@ -0,0 +1,141 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.rest.notifications; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.security.GeneralSecurityException; +import java.util.Queue; +import java.util.concurrent.ConcurrentLinkedQueue; + +import javax.websocket.OnClose; +import javax.websocket.OnError; +import javax.websocket.OnMessage; +import javax.websocket.OnOpen; +import javax.websocket.Session; +import javax.websocket.server.ServerEndpoint; + +import org.openecomp.policy.rest.XACMLRestProperties; +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.eelf.PolicyLogger; +import com.att.nsa.cambria.client.CambriaClientFactory; +import com.att.nsa.cambria.client.CambriaPublisher; +import org.openecomp.policy.xacml.api.XACMLErrorConstants; +import com.att.research.xacml.util.XACMLProperties; + +import org.openecomp.policy.common.logging.flexlogger.*; + + +/** + * The NotificationServer sends the Server Notifications to the Clients once there is any Event. + * WebSockets is being used as a medium for sending Notifications. + * UEB is being used as a medium for sending Notifications. + * + * @version 0.1 + * + **/ +@ServerEndpoint(value = "/notifications") +public class NotificationServer { + private static final Logger logger = FlexLogger.getLogger(NotificationServer.class); + private static Queue queue = new ConcurrentLinkedQueue(); + private static String update = null; + private static String hosts = null; + private static URL aURL = null; + + @OnOpen + public void openConnection(Session session) { + logger.info("Session Connected: " + session.getId()); + queue.add(session); + } + + @OnClose + public void closeConnection(Session session) { + queue.remove(session); + } + + @OnError + public void error(Session session, Throwable t) { + queue.remove(session); + logger.info(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Session Error for : " + session.getId() + " Error: " + t.getMessage()); + + } + + @OnMessage + public void Message(String message, Session session) { + + if(message.equalsIgnoreCase("Manual")) { + try { + session.getBasicRemote().sendText(update); + session.close(); + } catch (IOException e) { + logger.info(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error in sending the Event Notification: "+ e.getMessage()); + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error sending Message update"); + } + } + } + + public static void sendNotification(String notification, String propNotificationType, String pdpURL){ + + logger.debug("Notification set to " + propNotificationType); + if (propNotificationType.equals("ueb")){ + String topic = null; + try { + aURL = new URL(pdpURL); + topic = aURL.getHost() + aURL.getPort(); + } catch (MalformedURLException e1) { + pdpURL = pdpURL.replace("/", ""); + topic = pdpURL.replace(":", ""); + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error in parsing out pdpURL for UEB notfication "); + PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e1, "Error in parsing out pdpURL for UEB notfication "); + } + hosts = XACMLProperties.getProperty(XACMLRestProperties.PROP_NOTIFICATION_UEB_CLUSTER); + logger.debug("Creating Publisher for host: " + hosts + " with topic: " + topic); + CambriaPublisher pub = null; + try { + pub = CambriaClientFactory.createSimplePublisher (null, hosts, topic ); + } catch (MalformedURLException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } catch (GeneralSecurityException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + try { + pub.send( "MyPartitionKey", notification ); + } catch (IOException e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error sending notification update"); + } + pub.close(); + } + for(Session session: queue) { + try { + session.getBasicRemote().sendText(notification); + } catch (IOException e) { + logger.info(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error in sending the Event Notification: "+ e.getMessage()); + } + } + } + + public static void setUpdate(String update) { + NotificationServer.update = update; + } +} diff --git a/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/notifications/Removed.java b/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/notifications/Removed.java new file mode 100644 index 000000000..6ba073815 --- /dev/null +++ b/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/notifications/Removed.java @@ -0,0 +1,52 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.rest.notifications; + + +/** + * Removal is the POJO for removal updates of the Policy. + * It must have the Policy removed and its Version number. + * + * @version 0.1 + * + */ +public class Removed { + + private String policyName = null; + private String versionNo = null; + + public String getVersionNo() { + return versionNo; + } + + public void setVersionNo(String versionNo) { + this.versionNo = versionNo; + } + + public String getPolicyName() { + return policyName; + } + + public void setPolicyName(String policyName) { + this.policyName = policyName; + } + +} diff --git a/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/notifications/Updated.java b/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/notifications/Updated.java new file mode 100644 index 000000000..39236bada --- /dev/null +++ b/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/notifications/Updated.java @@ -0,0 +1,61 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.rest.notifications; + +import java.util.HashMap; + +/** + * Updated is the POJO which consists of any new or Updated Policy information. + * It must hold the Policy Name, version Number, Matches. + * + * @version 0.1 + * + */ +public class Updated { + private String policyName = null; + private String versionNo = null; + private HashMap matches = null; + + public String getPolicyName() { + return policyName; + } + + public void setPolicyName(String policyName) { + this.policyName = policyName; + } + + public String getVersionNo() { + return versionNo; + } + + public void setVersionNo(String versionNo) { + this.versionNo = versionNo; + } + + public HashMap getMatches() { + return matches; + } + + public void setMatches(HashMap matches) { + this.matches = matches; + } + +} diff --git a/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/notifications/package-info.java b/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/notifications/package-info.java new file mode 100644 index 000000000..7d3995ec6 --- /dev/null +++ b/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/notifications/package-info.java @@ -0,0 +1,28 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + * This is the new Addition to the PDP Server added for sending Notifications to the Clients + * about the policy Updates/ Removals. + * + * @version 0.1 + * + */ +package org.openecomp.policy.pdp.rest.notifications; diff --git a/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/restAuth/AuthenticationService.java b/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/restAuth/AuthenticationService.java new file mode 100644 index 000000000..c426b6002 --- /dev/null +++ b/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/restAuth/AuthenticationService.java @@ -0,0 +1,72 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.rest.restAuth; + +import java.util.Base64; +import java.util.StringTokenizer; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openecomp.policy.rest.XACMLRestProperties; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; +import com.att.research.xacml.util.XACMLProperties; + +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.eelf.PolicyLogger; + +public class AuthenticationService { + private String pdpID = XACMLProperties.getProperty(XACMLRestProperties.PROP_PDP_USERID); + private String pdpPass = XACMLProperties.getProperty(XACMLRestProperties.PROP_PDP_PASS); + private static final Log logger = LogFactory.getLog(AuthenticationService.class); + + public boolean authenticate(String authCredentials) { + + if (null == authCredentials) + return false; + // header value format will be "Basic encodedstring" for Basic authentication. + final String encodedUserPassword = authCredentials.replaceFirst("Basic" + " ", ""); + String usernameAndPassword = null; + try { + byte[] decodedBytes = Base64.getDecoder().decode(encodedUserPassword); + usernameAndPassword = new String(decodedBytes, "UTF-8"); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, ""); + return false; + } + try { + final StringTokenizer tokenizer = new StringTokenizer(usernameAndPassword, ":"); + final String username = tokenizer.nextToken(); + final String password = tokenizer.nextToken(); + + boolean authenticationStatus = pdpID.equals(username) && pdpPass.equals(password); + return authenticationStatus; + }catch (Exception e){ + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, ""); + return false; + } + } + +} diff --git a/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/restAuth/PDPAuthenticationFilter.java b/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/restAuth/PDPAuthenticationFilter.java new file mode 100644 index 000000000..b3b931eaa --- /dev/null +++ b/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/restAuth/PDPAuthenticationFilter.java @@ -0,0 +1,78 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.rest.restAuth; + +import java.io.IOException; + +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.annotation.WebFilter; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.openecomp.policy.pdp.rest.restAuth.AuthenticationService; + +/** + * Servlet Filter implementation class PDPAuthenticationFilter + */ +@WebFilter("/*") +public class PDPAuthenticationFilter implements Filter { + + public static final String AUTHENTICATION_HEADER = "Authorization"; + + @Override + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain filter) throws IOException, ServletException { + if (request instanceof HttpServletRequest) { + HttpServletRequest httpServletRequest = (HttpServletRequest) request; + String authCredentials = httpServletRequest.getHeader(AUTHENTICATION_HEADER); + String path = ((HttpServletRequest) request).getRequestURI(); + // better injected + AuthenticationService authenticationService = new AuthenticationService(); + + boolean authenticationStatus = authenticationService.authenticate(authCredentials); + + if (authenticationStatus) { + filter.doFilter(request, response); + } else if(path.contains("notifications")){ + filter.doFilter(request, response); + } else { + if (response instanceof HttpServletResponse) { + HttpServletResponse httpServletResponse = (HttpServletResponse) response; + httpServletResponse.setStatus(HttpServletResponse.SC_UNAUTHORIZED); + } + } + } + } + + @Override + public void destroy() { + } + + @Override + public void init(FilterConfig arg0) throws ServletException { + } + +} diff --git a/ECOMP-PDP-REST/src/main/resources/log4j.properties b/ECOMP-PDP-REST/src/main/resources/log4j.properties new file mode 100644 index 000000000..3b31771c4 --- /dev/null +++ b/ECOMP-PDP-REST/src/main/resources/log4j.properties @@ -0,0 +1,71 @@ +### +# ============LICENSE_START======================================================= +# ECOMP-PDP-REST +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +# +# Use this properties for Deployments. +# +# +# Set root logger level to DEBUG and its only appender to FILE. +#log4j.rootLogger=DEBUG, FILE, CONSOLE +log4j.rootLogger=INFO, FILE + +# FILE appender +log4j.appender.FILE=org.apache.log4j.DailyRollingFileAppender +log4j.appender.FILE.File=${catalina.base}/logs/pdp-rest.log +log4j.appender.FILE.ImmediateFlush=true +log4j.appender.FILE.Threshold=debug +log4j.appender.FILE.append=true +log4j.appender.FILE.DatePattern='.'yyyy-MM-dd +log4j.appender.FILE.layout=org.apache.log4j.PatternLayout +log4j.appender.FILE.layout.ConversionPattern=%d{yyyy-MM-dd'T'HH:mm:ss}{GMT+0}+00:00|%X{requestId}|%X{serviceInstanceId}|%t|%X{serverName}|%X{serviceName}|%X{instanceUuid}|%p|%X{severity}|%X{serverIpAddress}|%X{server}|%X{clientIpAddress}|%l||%m%n + +# for Developments and Debugging +#log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender +#log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout +#log4j.appender.CONSOLE.layout.ConversionPattern=%d{yyyy_MM_dd_HH_mm_ss_SSS} [%t] %-5p %l- %m%n + +# +# This is specifically for Xacml request/response logging +# +log4j.logger.xacml.request=INFO, REQUEST_LOG + +log4j.appender.REQUEST_LOG=org.apache.log4j.DailyRollingFileAppender +log4j.appender.REQUEST_LOG.File=${catalina.base}/logs/pdp-rest-reqres.log +log4j.appender.REQUEST_LOG.ImmediateFlush=true +log4j.appender.REQUEST_LOG.Threshold=debug +log4j.appender.REQUEST_LOG.append=true +log4j.appender.REQUEST_LOG.DatePattern='.'yyyy-MM-dd + +log4j.appender.REQUEST_LOG.layout=org.apache.log4j.PatternLayout +log4j.appender.REQUEST_LOG.layout.ConversionPattern=%d{yyyy_MM_dd_HH_mm_ss_SSS} %m%n + +# +# audit (transaction) logging +# +log4j.logger.auditLogger=INFO,AUDIT_LOG +log4j.additivity.auditLogger=false + +log4j.appender.AUDIT_LOG=org.apache.log4j.DailyRollingFileAppender +log4j.appender.AUDIT_LOG.File=${catalina.base}/logs/audit.log +log4j.appender.AUDIT_LOG.Append=true +log4j.appender.AUDIT_LOG.DatePattern='.'yyyy-MM-dd +log4j.appender.AUDIT_LOG.threshold=INFO +log4j.appender.AUDIT_LOG.layout=org.apache.log4j.EnhancedPatternLayout +log4j.appender.AUDIT_LOG.layout.ConversionPattern=%d{yyyy-MM-dd'T'HH:mm:ss}{GMT+0}+00:00|%X{requestId}|%X{serviceInstanceId}|%t|%X{serverName}|%X{serviceName}|%X{instanceUuid}|%p|%X{severity}|%X{serverIpAddress}|%X{server}|%X{clientIpAddress}|%X{className}|%X{timer}|%m%n diff --git a/ECOMP-PDP-REST/src/main/resources/logback.xml b/ECOMP-PDP-REST/src/main/resources/logback.xml new file mode 100644 index 000000000..6958fa693 --- /dev/null +++ b/ECOMP-PDP-REST/src/main/resources/logback.xml @@ -0,0 +1,253 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --> + + + + + + + + + + + + + + + + + + + + ${defaultPattern} + + + + + + + + + + + + + ${logDirectory}/${auditLogName}.log + + ${logDirectory}/${auditLogName}.%i.log.zip + + 1 + 9 + + + 5MB + + + ${defaultAuditPattern} + + + + + 256 + + + + + + + + ${logDirectory}/${metricsLogName}.log + + ${logDirectory}/${metricsLogName}.%i.log.zip + + 1 + 9 + + + 5MB + + + + ${defaultMetricPattern} + + + + + 256 + + + + + + + + ${logDirectory}/${errorLogName}.log + + ${logDirectory}/${errorLogName}.%i.log.zip + + 1 + 9 + + + ERROR + + + 5MB + + + ${defaultErrorPattern} + + + + + 256 + + + + + + + ${debugLogDirectory}/${debugLogName}.log + + ${debugLogDirectory}/${debugLogName}.%i.log.zip + + 1 + 9 + + + INFO + + + 5MB + + + ${debugLoggerPattern} + + + + + 256 + + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ECOMP-PDP-REST/src/test/java/org/openecomp/policy/pdp/rest/PapUrlResolverTest.java b/ECOMP-PDP-REST/src/test/java/org/openecomp/policy/pdp/rest/PapUrlResolverTest.java new file mode 100644 index 000000000..7a8060114 --- /dev/null +++ b/ECOMP-PDP-REST/src/test/java/org/openecomp/policy/pdp/rest/PapUrlResolverTest.java @@ -0,0 +1,355 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.rest; +import org.junit.Before; +import org.junit.Test; +import org.openecomp.policy.pdp.rest.PapUrlResolver; +import org.openecomp.policy.rest.XACMLRestProperties; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Properties; + +import org.junit.Assert; + +public class PapUrlResolverTest { + + + @Test + public void testPropertyModifications(){ + long currentTime = new Date().getTime(); + DateFormat df = new SimpleDateFormat(); + //first sort order + String urls = "http://one.localhost.com,http://two.localhost.com,http://three.localhost.com,http://four.localhost.com"; + String failed = "-1,-1,-1,-1"; + String succeeded = "-1,-1,-1,-1"; + PapUrlResolver rs = PapUrlResolver.getInstance(urls, failed, succeeded); + Assert.assertEquals(rs.getProperties().getProperty(XACMLRestProperties.PROP_PAP_URLS),urls); + + rs.failed(); + rs.getNext(); + Assert.assertTrue(rs.hasMoreUrls()); + rs.succeeded(); + Assert.assertFalse(rs.hasMoreUrls()); + Properties prop = rs.getProperties(); + Assert.assertEquals(df.format(new Date())+",-1,-1,-1",prop.getProperty(XACMLRestProperties.PROP_PAP_FAILED_URLS)); + Assert.assertEquals("-1,"+df.format(new Date())+",-1,-1",prop.getProperty(XACMLRestProperties.PROP_PAP_SUCCEEDED_URLS)); + + failed = prop.getProperty(XACMLRestProperties.PROP_PAP_FAILED_URLS); + succeeded = prop.getProperty(XACMLRestProperties.PROP_PAP_SUCCEEDED_URLS); + rs = PapUrlResolver.getInstance(urls, failed, succeeded); + Assert.assertTrue(rs.hasMoreUrls()); + Assert.assertEquals("http://two.localhost.com", rs.getUrl()); + rs.getNext(); + Assert.assertTrue(rs.hasMoreUrls()); + Assert.assertEquals("http://three.localhost.com", rs.getUrl()); + rs.getNext(); + Assert.assertTrue(rs.hasMoreUrls()); + Assert.assertEquals("http://four.localhost.com", rs.getUrl()); + rs.getNext(); + Assert.assertTrue(rs.hasMoreUrls()); + Assert.assertEquals("http://one.localhost.com", rs.getUrl()); + rs.succeeded(); + rs.getNext(); + Assert.assertFalse(rs.hasMoreUrls()); + prop = rs.getProperties(); + Assert.assertEquals("-1,-1,-1,-1",prop.getProperty(XACMLRestProperties.PROP_PAP_FAILED_URLS)); + + failed = prop.getProperty(XACMLRestProperties.PROP_PAP_FAILED_URLS); + succeeded = prop.getProperty(XACMLRestProperties.PROP_PAP_SUCCEEDED_URLS); + rs = PapUrlResolver.getInstance(urls, failed, succeeded); + Assert.assertTrue(rs.hasMoreUrls()); + Assert.assertEquals("http://one.localhost.com", rs.getUrl()); + rs.succeeded(); + rs.getNext(); + Assert.assertFalse(rs.hasMoreUrls()); + prop = rs.getProperties(); + failed = prop.getProperty(XACMLRestProperties.PROP_PAP_FAILED_URLS); + succeeded = prop.getProperty(XACMLRestProperties.PROP_PAP_SUCCEEDED_URLS); + rs = PapUrlResolver.getInstance(urls, failed, succeeded); + Assert.assertTrue(rs.hasMoreUrls()); + Assert.assertEquals("http://one.localhost.com", rs.getUrl()); + rs.succeeded(); + rs.getNext(); + Assert.assertFalse(rs.hasMoreUrls()); + prop = rs.getProperties(); + failed = prop.getProperty(XACMLRestProperties.PROP_PAP_FAILED_URLS); + succeeded = prop.getProperty(XACMLRestProperties.PROP_PAP_SUCCEEDED_URLS); + rs = PapUrlResolver.getInstance(urls, failed, succeeded); + Assert.assertTrue(rs.hasMoreUrls()); + Assert.assertEquals("http://one.localhost.com", rs.getUrl()); + rs.succeeded(); + rs.getNext(); + Assert.assertFalse(rs.hasMoreUrls()); + + + prop = rs.getProperties(); + succeeded = prop.getProperty(XACMLRestProperties.PROP_PAP_SUCCEEDED_URLS); + System.out.println(succeeded); + //can't test this in a timely manner since it will need to wait a minute, since they all succeeded at the same time + /* + prop = rs.getProperties(); + failed = prop.getProperty(XACMLRestProperties.PROP_PAP_FAILED_URLS); + succeeded = prop.getProperty(XACMLRestProperties.PROP_PAP_SUCCEEDED_URLS); + rs = PapUrlResolver.getInstance(urls, failed, succeeded); + Assert.assertTrue(rs.hasMoreUrls()); + Assert.assertEquals("http://two.localhost.com", rs.getUrl()); + rs.succeeded(); + rs.getNext(); + Assert.assertFalse(rs.hasMoreUrls()); + */ + } + @Test + public void testModifyUrl(){ + String newUrl = PapUrlResolver.modifyUrl("http://mypap1.com/pap?id=987654", "http://mypap2.com:45/pap/"); + int u = 8; + } + + @Test + public void testSorts(){ + long currentTime = new Date().getTime(); + DateFormat df = new SimpleDateFormat(); + //first sort order + String urls = "http://one.localhost.com,http://two.localhost.com,http://three.localhost.com,http://four.localhost.com"; + String failed = df.format(new Date(currentTime-3600000))+",-1,-1,"+df.format(new Date(currentTime-3200000)); + String succeeded = "-1,8/13/15 5:41 PM,8/13/15 4:41 PM,-1"; + PapUrlResolver rs = PapUrlResolver.getInstance(urls, failed, succeeded); + Assert.assertTrue(rs.hasMoreUrls()); + Assert.assertEquals("http://two.localhost.com", rs.getUrl()); + rs.getNext(); + Assert.assertTrue(rs.hasMoreUrls()); + Assert.assertEquals("http://three.localhost.com", rs.getUrl()); + rs.getNext(); + Assert.assertTrue(rs.hasMoreUrls()); + Assert.assertEquals("http://one.localhost.com", rs.getUrl()); + rs.getNext(); + Assert.assertTrue(rs.hasMoreUrls()); + Assert.assertEquals("http://four.localhost.com", rs.getUrl()); + rs.getNext(); + Assert.assertFalse(rs.hasMoreUrls()); + + urls = "http://one.localhost.com,http://two.localhost.com,http://three.localhost.com,http://four.localhost.com"; + failed = "-1,-1,-1,-1"; + succeeded = "-1,"+df.format(new Date(currentTime-3600000))+","+df.format(new Date(currentTime-6600000))+",-1"; + rs = PapUrlResolver.getInstance(urls, failed, succeeded); + Assert.assertTrue(rs.hasMoreUrls()); + Assert.assertEquals("http://one.localhost.com", rs.getUrl()); + rs.getNext(); + Assert.assertTrue(rs.hasMoreUrls()); + Assert.assertEquals("http://two.localhost.com", rs.getUrl()); + rs.getNext(); + Assert.assertTrue(rs.hasMoreUrls()); + Assert.assertEquals("http://three.localhost.com", rs.getUrl()); + rs.getNext(); + Assert.assertTrue(rs.hasMoreUrls()); + Assert.assertEquals("http://four.localhost.com", rs.getUrl()); + rs.getNext(); + Assert.assertFalse(rs.hasMoreUrls()); + + urls = "http://one.localhost.com,http://two.localhost.com,http://three.localhost.com,http://four.localhost.com"; + failed = "-1,-1,-1,-1"; + succeeded = "-1,-1,-1,-1"; + rs = PapUrlResolver.getInstance(urls, failed, succeeded); + Assert.assertTrue(rs.hasMoreUrls()); + Assert.assertEquals("http://one.localhost.com", rs.getUrl()); + rs.getNext(); + Assert.assertTrue(rs.hasMoreUrls()); + Assert.assertEquals("http://two.localhost.com", rs.getUrl()); + rs.getNext(); + Assert.assertTrue(rs.hasMoreUrls()); + Assert.assertEquals("http://three.localhost.com", rs.getUrl()); + rs.getNext(); + Assert.assertTrue(rs.hasMoreUrls()); + Assert.assertEquals("http://four.localhost.com", rs.getUrl()); + rs.getNext(); + Assert.assertFalse(rs.hasMoreUrls()); + + urls = "http://one.localhost.com,http://two.localhost.com,http://three.localhost.com,http://four.localhost.com"; + failed = df.format(new Date(currentTime-3900000))+","+df.format(new Date(currentTime-5600000))+","+df.format(new Date(currentTime-4600000))+","+df.format(new Date(currentTime-3600000)); + succeeded = "-1,-1,-1,-1"; + rs = PapUrlResolver.getInstance(urls, failed, succeeded); + Assert.assertTrue(rs.hasMoreUrls()); + Assert.assertEquals("http://two.localhost.com", rs.getUrl()); + rs.getNext(); + Assert.assertTrue(rs.hasMoreUrls()); + Assert.assertEquals("http://three.localhost.com", rs.getUrl()); + rs.getNext(); + Assert.assertTrue(rs.hasMoreUrls()); + Assert.assertEquals("http://one.localhost.com", rs.getUrl()); + rs.getNext(); + Assert.assertTrue(rs.hasMoreUrls()); + Assert.assertEquals("http://four.localhost.com", rs.getUrl()); + rs.getNext(); + Assert.assertFalse(rs.hasMoreUrls()); + + urls = "http://one.localhost.com,http://two.localhost.com,http://three.localhost.com,http://four.localhost.com"; + failed = df.format(new Date(currentTime-(3600000*4)))+",-1,-1,-1"; + succeeded = "-1,-1,-1,-1"; + rs = PapUrlResolver.getInstance(urls, failed, succeeded); + Assert.assertTrue(rs.hasMoreUrls()); + Assert.assertEquals("http://two.localhost.com", rs.getUrl()); + rs.getNext(); + Assert.assertTrue(rs.hasMoreUrls()); + Assert.assertEquals("http://three.localhost.com", rs.getUrl()); + rs.getNext(); + Assert.assertTrue(rs.hasMoreUrls()); + Assert.assertEquals("http://four.localhost.com", rs.getUrl()); + rs.getNext(); + Assert.assertTrue(rs.hasMoreUrls()); + Assert.assertEquals("http://one.localhost.com", rs.getUrl()); + rs.getNext(); + Assert.assertFalse(rs.hasMoreUrls()); + + urls = "http://one.localhost.com,http://two.localhost.com,http://three.localhost.com,http://four.localhost.com"; + failed = df.format(new Date(currentTime-(3600000*6)))+",-1,-1,-1"; + succeeded = "-1,-1,-1,-1"; + rs = PapUrlResolver.getInstance(urls, failed, succeeded); + Assert.assertTrue(rs.hasMoreUrls()); + Assert.assertEquals("http://one.localhost.com", rs.getUrl()); + rs.getNext(); + Assert.assertTrue(rs.hasMoreUrls()); + Assert.assertEquals("http://two.localhost.com", rs.getUrl()); + rs.getNext(); + Assert.assertTrue(rs.hasMoreUrls()); + Assert.assertEquals("http://three.localhost.com", rs.getUrl()); + rs.getNext(); + Assert.assertTrue(rs.hasMoreUrls()); + Assert.assertEquals("http://four.localhost.com", rs.getUrl()); + rs.getNext(); + Assert.assertFalse(rs.hasMoreUrls()); + + + + + //not used because we are no longer sorting based on success time, only failed time. Modified above. + /* + //first sort order + String urls = "http://one.localhost.com,http://two.localhost.com,http://three.localhost.com,http://four.localhost.com"; + String failed = df.format(new Date(currentTime-3600000))+",-1,-1,"+df.format(new Date(currentTime-3200000)); + String succeeded = "-1,8/13/15 5:41 PM,8/13/15 4:41 PM,-1"; + PapUrlResolver rs = PapUrlResolver.getInstance(urls, failed, succeeded); + Assert.assertTrue(rs.hasMoreUrls()); + Assert.assertEquals("http://three.localhost.com", rs.getUrl()); + rs.getNext(); + Assert.assertTrue(rs.hasMoreUrls()); + Assert.assertEquals("http://two.localhost.com", rs.getUrl()); + rs.getNext(); + Assert.assertTrue(rs.hasMoreUrls()); + Assert.assertEquals("http://one.localhost.com", rs.getUrl()); + rs.getNext(); + Assert.assertTrue(rs.hasMoreUrls()); + Assert.assertEquals("http://four.localhost.com", rs.getUrl()); + rs.getNext(); + Assert.assertFalse(rs.hasMoreUrls()); + + urls = "http://one.localhost.com,http://two.localhost.com,http://three.localhost.com,http://four.localhost.com"; + failed = "-1,-1,-1,-1"; + succeeded = "-1,"+df.format(new Date(currentTime-3600000))+","+df.format(new Date(currentTime-6600000))+",-1"; + rs = PapUrlResolver.getInstance(urls, failed, succeeded); + Assert.assertTrue(rs.hasMoreUrls()); + Assert.assertEquals("http://one.localhost.com", rs.getUrl()); + rs.getNext(); + Assert.assertTrue(rs.hasMoreUrls()); + Assert.assertEquals("http://four.localhost.com", rs.getUrl()); + rs.getNext(); + Assert.assertTrue(rs.hasMoreUrls()); + Assert.assertEquals("http://three.localhost.com", rs.getUrl()); + rs.getNext(); + Assert.assertTrue(rs.hasMoreUrls()); + Assert.assertEquals("http://two.localhost.com", rs.getUrl()); + rs.getNext(); + Assert.assertFalse(rs.hasMoreUrls()); + + urls = "http://one.localhost.com,http://two.localhost.com,http://three.localhost.com,http://four.localhost.com"; + failed = "-1,-1,-1,-1"; + succeeded = "-1,-1,-1,-1"; + rs = PapUrlResolver.getInstance(urls, failed, succeeded); + Assert.assertTrue(rs.hasMoreUrls()); + Assert.assertEquals("http://one.localhost.com", rs.getUrl()); + rs.getNext(); + Assert.assertTrue(rs.hasMoreUrls()); + Assert.assertEquals("http://two.localhost.com", rs.getUrl()); + rs.getNext(); + Assert.assertTrue(rs.hasMoreUrls()); + Assert.assertEquals("http://three.localhost.com", rs.getUrl()); + rs.getNext(); + Assert.assertTrue(rs.hasMoreUrls()); + Assert.assertEquals("http://four.localhost.com", rs.getUrl()); + rs.getNext(); + Assert.assertFalse(rs.hasMoreUrls()); + + urls = "http://one.localhost.com,http://two.localhost.com,http://three.localhost.com,http://four.localhost.com"; + failed = df.format(new Date(currentTime-3900000))+","+df.format(new Date(currentTime-5600000))+","+df.format(new Date(currentTime-4600000))+","+df.format(new Date(currentTime-3600000)); + succeeded = "-1,-1,-1,-1"; + rs = PapUrlResolver.getInstance(urls, failed, succeeded); + Assert.assertTrue(rs.hasMoreUrls()); + Assert.assertEquals("http://two.localhost.com", rs.getUrl()); + rs.getNext(); + Assert.assertTrue(rs.hasMoreUrls()); + Assert.assertEquals("http://three.localhost.com", rs.getUrl()); + rs.getNext(); + Assert.assertTrue(rs.hasMoreUrls()); + Assert.assertEquals("http://one.localhost.com", rs.getUrl()); + rs.getNext(); + Assert.assertTrue(rs.hasMoreUrls()); + Assert.assertEquals("http://four.localhost.com", rs.getUrl()); + rs.getNext(); + Assert.assertFalse(rs.hasMoreUrls()); + + urls = "http://one.localhost.com,http://two.localhost.com,http://three.localhost.com,http://four.localhost.com"; + failed = df.format(new Date(currentTime-(3600000*4)))+",-1,-1,-1"; + succeeded = "-1,-1,-1,-1"; + rs = PapUrlResolver.getInstance(urls, failed, succeeded); + Assert.assertTrue(rs.hasMoreUrls()); + Assert.assertEquals("http://two.localhost.com", rs.getUrl()); + rs.getNext(); + Assert.assertTrue(rs.hasMoreUrls()); + Assert.assertEquals("http://three.localhost.com", rs.getUrl()); + rs.getNext(); + Assert.assertTrue(rs.hasMoreUrls()); + Assert.assertEquals("http://four.localhost.com", rs.getUrl()); + rs.getNext(); + Assert.assertTrue(rs.hasMoreUrls()); + Assert.assertEquals("http://one.localhost.com", rs.getUrl()); + rs.getNext(); + Assert.assertFalse(rs.hasMoreUrls()); + + urls = "http://one.localhost.com,http://two.localhost.com,http://three.localhost.com,http://four.localhost.com"; + failed = df.format(new Date(currentTime-(3600000*6)))+",-1,-1,-1"; + succeeded = "-1,-1,-1,-1"; + rs = PapUrlResolver.getInstance(urls, failed, succeeded); + Assert.assertTrue(rs.hasMoreUrls()); + Assert.assertEquals("http://one.localhost.com", rs.getUrl()); + rs.getNext(); + Assert.assertTrue(rs.hasMoreUrls()); + Assert.assertEquals("http://two.localhost.com", rs.getUrl()); + rs.getNext(); + Assert.assertTrue(rs.hasMoreUrls()); + Assert.assertEquals("http://three.localhost.com", rs.getUrl()); + rs.getNext(); + Assert.assertTrue(rs.hasMoreUrls()); + Assert.assertEquals("http://four.localhost.com", rs.getUrl()); + rs.getNext(); + Assert.assertFalse(rs.hasMoreUrls()); + */ + } +} diff --git a/ECOMP-PDP-REST/src/test/java/org/openecomp/policy/pdp/rest/XACMLPdpServletTest.java b/ECOMP-PDP-REST/src/test/java/org/openecomp/policy/pdp/rest/XACMLPdpServletTest.java new file mode 100644 index 000000000..95cb0293c --- /dev/null +++ b/ECOMP-PDP-REST/src/test/java/org/openecomp/policy/pdp/rest/XACMLPdpServletTest.java @@ -0,0 +1,395 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.rest; + +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Properties; +import java.util.Random; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletInputStream; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import junit.framework.TestCase; + +import org.apache.commons.lang.math.RandomUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.Before; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.openecomp.policy.pdp.rest.XACMLPdpServlet; +import org.springframework.mock.web.MockHttpServletResponse; +import org.springframework.mock.web.MockServletConfig; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import org.openecomp.policy.common.im.AdministrativeStateException; +import org.openecomp.policy.common.im.IntegrityMonitor; +import org.openecomp.policy.common.im.StandbyStatusException; + +import com.att.research.xacml.util.XACMLProperties; +import com.mockrunner.mock.web.MockServletInputStream; +import org.openecomp.policy.common.logging.flexlogger.*; + +@RunWith(PowerMockRunner.class) +@PrepareForTest(IntegrityMonitor.class) // so PowerMock can mock static method of IntegrityMonitor +public class XACMLPdpServletTest extends TestCase{ + private static Logger logger = FlexLogger.getLogger(XACMLPdpServletTest.class); + + private List headers = new ArrayList(); + + private HttpServletRequest httpServletRequest; + private HttpServletResponse httpServletResponse; + private ServletOutputStream mockOutput; + private ServletInputStream mockInput; + private ServletConfig servletConfig; + private XACMLPdpServlet pdpServlet; + private IntegrityMonitor im; + + + + @Before + public void setUp(){ + httpServletRequest = Mockito.mock(HttpServletRequest.class); + Mockito.when(httpServletRequest.getMethod()).thenReturn("POST"); + Mockito.when(httpServletRequest.getHeaderNames()).thenReturn(Collections.enumeration(headers)); + Mockito.when(httpServletRequest.getAttributeNames()).thenReturn(Collections.enumeration(headers)); + + + mockOutput = Mockito.mock(ServletOutputStream.class); + + httpServletResponse = Mockito.mock(MockHttpServletResponse.class); + + try { + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(mockOutput); + } catch (IOException e) { + // TODO Auto-generated catch block + fail(); + } + + + //when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + servletConfig = Mockito.mock(MockServletConfig.class); + //Mockito.when(servletConfig.getInitParameterNames()).thenReturn(Collections.enumeration(headers)); + //servletConfig + Mockito.when(servletConfig.getInitParameterNames()).thenReturn(Collections.enumeration(headers)); + pdpServlet = new XACMLPdpServlet(); + + Mockito.when(servletConfig.getInitParameter("XACML_PROPERTIES_NAME")).thenReturn("xacml.pdp.properties"); + + System.setProperty("xacml.properties", "xacml.pdp.properties"); + System.setProperty("xacml.rest.pdp.config", "config_testing"); + System.setProperty("xacml.rest.pep.idfile", "testclient.properties"); + System.setProperty("xacml.rest.pdp.webapps", "/webapps"); + System.setProperty("xacml.rootPolicies", "test_PolicyEngine.xml"); + System.setProperty("xacml.referencedPolicies", "test_PolicyEngine.xml"); + System.setProperty("test_PolicyEngine.xml.file", "config_testing\\test_PolicyEngine.xml"); + System.setProperty("xacml.rest.pdp.register", "false"); + System.setProperty("com.sun.management.jmxremote.port", "9999"); + + im = Mockito.mock(IntegrityMonitor.class); + // Need PowerMockito for mocking static method getInstance(...) + PowerMockito.mockStatic(IntegrityMonitor.class); + try { + // when IntegrityMonitor.getInstance is called, return the mock object + PowerMockito.when(IntegrityMonitor.getInstance(Mockito.anyString(), Mockito.any(Properties.class))).thenReturn(im); + } catch (Exception e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + try { + Mockito.doNothing().when(im).startTransaction(); + } catch (StandbyStatusException | AdministrativeStateException e) { + fail(); + } + Mockito.doNothing().when(im).endTransaction(); + } + + public void testInit(){ + logger.info("XACMLPdpServletTest - testInit"); + try { + pdpServlet.init(servletConfig); + assertTrue(true); + } catch (Exception e) { + // TODO Auto-generated catch block + System.out.println("Unexpected exception in testInit"); + e.printStackTrace(); + fail(); + + } + + } + + public void testDoGetNoTypeError(){ + logger.info("XACMLPdpServletTest - testDoGetNoTypeError"); + try{ + pdpServlet.init(servletConfig); + pdpServlet.doGet(httpServletRequest, httpServletResponse); + Mockito.verify(httpServletResponse).sendError(HttpServletResponse.SC_BAD_REQUEST, "type not 'config' or 'hb'"); + assertTrue(true); + }catch(Exception e){ + System.out.println("Unexpected exception in testDoGetNoTypeError"); + e.printStackTrace(); + fail(); + } + } + + public void testDoGetConfigType(){ + logger.info("XACMLPdpServletTest - testDoGetConfigType"); + Mockito.when(httpServletRequest.getParameter("type")).thenReturn("config"); + + try{ + pdpServlet.init(servletConfig); + pdpServlet.doGet(httpServletRequest, httpServletResponse); + Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK); + //Mockito.verify(httpServletResponse).sendError(400, "Failed to copy Property file"); + assertTrue(true); + }catch (Exception e){ + System.out.println("Unexpected exception in testDoGetConfigType"); + e.printStackTrace(); + fail(); + } + + } + + + public void testDoGetTypeHb(){ + logger.info("XACMLPdpServletTest - testDoGetTypeHb"); + try{ + Mockito.when(httpServletRequest.getParameter("type")).thenReturn("hb"); + pdpServlet.init(servletConfig); + pdpServlet.doGet(httpServletRequest, httpServletResponse); + Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_NO_CONTENT); + assertTrue(true); + }catch(Exception e){ + System.out.println("Unexpected exception in testDoGetTypeHb"); + e.printStackTrace(); + fail(); + } + } + public void testDoGetTypeStatus(){ + logger.info("XACMLPdpServletTest - testDoGetTypeStatus"); + try{ + Mockito.when(httpServletRequest.getParameter("type")).thenReturn("Status"); + pdpServlet.init(servletConfig); + pdpServlet.doGet(httpServletRequest, httpServletResponse); + Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK); + assertTrue(true); + }catch(Exception e){ + System.out.println("Unexpected exception in testDoGetTypeStatus"); + e.printStackTrace(); + fail(); + } + } + + public void testDoPost(){ + logger.info("XACMLPdpServletTest - testDoPost"); + try{ + pdpServlet.init(servletConfig); + pdpServlet.doPost(httpServletRequest, httpServletResponse); + //response.sendError(HttpServletResponse.SC_BAD_REQUEST, "no content-type given"); + //Mockito.verify(httpServletResponse).sendError(HttpServletResponse.SC_BAD_REQUEST, "no content-type given"); + assertTrue(true); + }catch (Exception e){ + System.out.println("Unexpected exception in testDoPost"); + e.printStackTrace(); + fail(); + } + } + + public void testDoPostToLong(){ + logger.info("XACMLPdpServletTest - testDoPostToLong"); + try{ + Mockito.when(httpServletRequest.getContentType()).thenReturn("stuff"); + Mockito.when(httpServletRequest.getContentLength()).thenReturn(32768); + + pdpServlet.init(servletConfig); + pdpServlet.doPost(httpServletRequest, httpServletResponse); + //response.sendError(HttpServletResponse.SC_BAD_REQUEST, "no content-type given"); + //Mockito.verify(httpServletResponse).sendError(HttpServletResponse.SC_BAD_REQUEST, "Content-Length larger than server will accept."); + assertTrue(true); + }catch (Exception e){ + System.out.println("Unexpected exception in testDoPostToLong"); + e.printStackTrace(); + fail(); + } + } + + public void testDoPostContentLengthNegative(){ + logger.info("XACMLPdpServletTest - testDoPostToLong"); + try{ + Mockito.when(httpServletRequest.getContentType()).thenReturn("stuff"); + Mockito.when(httpServletRequest.getContentLength()).thenReturn(-1); + + pdpServlet.init(servletConfig); + pdpServlet.doPost(httpServletRequest, httpServletResponse); + //response.sendError(HttpServletResponse.SC_BAD_REQUEST, "no content-type given"); + //Mockito.verify(httpServletResponse).sendError(HttpServletResponse.SC_BAD_REQUEST, "Content-Length is negative"); + assertTrue(true); + }catch (Exception e){ + System.out.println("Unexpected exception in testDoPostContentLengthNegative"); + e.printStackTrace(); + fail(); + } + } + + public void testDoPostContentTypeNonValid(){ + logger.info("XACMLPdpServletTest - testDoPostToLong"); + try{ + Mockito.when(httpServletRequest.getContentType()).thenReturn(";"); + Mockito.when(httpServletRequest.getContentLength()).thenReturn(30768); + + pdpServlet.init(servletConfig); + pdpServlet.doPost(httpServletRequest, httpServletResponse); + //response.sendError(HttpServletResponse.SC_BAD_REQUEST, "no content-type given"); + //Mockito.verify(httpServletResponse).sendError(HttpServletResponse.SC_BAD_REQUEST, "Parsing Content-Type: ;, error=Invalid content type: ;"); + assertTrue(true); + }catch (Exception e){ + System.out.println("Unexpected exception in testDoPostContentTypeNonValid"); + e.printStackTrace(); + fail(); + } + } + + public void testDoPostContentTypeConfigurationError(){ + logger.info("XACMLPdpServletTest - testDoPostToLong"); + try{ + Mockito.when(httpServletRequest.getContentType()).thenReturn("stuff"); + Mockito.when(httpServletRequest.getContentLength()).thenReturn(30768); + + pdpServlet.init(servletConfig); + pdpServlet.doPost(httpServletRequest, httpServletResponse); + //response.sendError(HttpServletResponse.SC_BAD_REQUEST, "no content-type given"); + //Mockito.verify(httpServletResponse).sendError(HttpServletResponse.SC_BAD_REQUEST, "unsupported content typestuff"); + assertTrue(true); + }catch (Exception e){ + System.out.println("Unexpected exception in testDoPostContentTypeConfigurationError"); + e.printStackTrace(); + fail(); + } + } + + public void testDoPutCacheEmpty(){ + logger.info("XACMLPdpServletTest - testDoPutCacheEmpty"); + mockInput = Mockito.mock(ServletInputStream.class); + + try{ + Mockito.when(httpServletRequest.getParameter("cache")).thenReturn("cache"); + Mockito.when(httpServletRequest.getContentType()).thenReturn("text/x-java-properties"); + Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput); + pdpServlet.init(servletConfig); + pdpServlet.doPut(httpServletRequest, httpServletResponse); + Mockito.verify(httpServletResponse).sendError(HttpServletResponse.SC_BAD_REQUEST, "PUT must contain at least one property"); + assertTrue(true); + }catch (Exception e){ + System.out.println("Unexpected exception in testDoPutCacheEmpty"); + e.printStackTrace(); + fail(); + } + } + + public void testDoPutConfigPolicies(){ + logger.info("XACMLPdpServletTest - testDoPutConfigPolicies"); + byte[] b = new byte[20]; + new Random().nextBytes(b); + + mockInput = new MockServletInputStream(b); + + try{ + Mockito.when(httpServletRequest.getParameter("cache")).thenReturn("policies"); + Mockito.when(httpServletRequest.getContentType()).thenReturn("text/x-java-properties"); + Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput); + pdpServlet.init(servletConfig); + pdpServlet.doPut(httpServletRequest, httpServletResponse); + /* + * Started failing 8/17/16 + * Mockito.verify(httpServletResponse).sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Missing property: xacml.rootPolicies"); + */ + assertTrue(true); + }catch (Exception e){ + System.out.println("Unexpected exception in testDoPutConfigPolicies"); + e.printStackTrace(); + fail(); + } + } + + public void testDoPutToLong(){ + logger.info("XACMLPdpServletTest - testDoPutToLong"); + try{ + Mockito.when(httpServletRequest.getParameter("cache")).thenReturn("policies"); + + Mockito.when(httpServletRequest.getContentType()).thenReturn("text/x-java-properties"); + Mockito.when(httpServletRequest.getContentLength()).thenReturn(1000000000); + + pdpServlet.init(servletConfig); + pdpServlet.doPut(httpServletRequest, httpServletResponse); + //response.sendError(HttpServletResponse.SC_BAD_REQUEST, "no content-type given"); + Mockito.verify(httpServletResponse).sendError(HttpServletResponse.SC_BAD_REQUEST, "Content-Length larger than server will accept."); + assertTrue(true); + }catch (Exception e){ + System.out.println("Unexpected exception in testDoPutToLong"); + e.printStackTrace(); + fail(); + } + } + + public void testDoPutInvalidContentType(){ + logger.info("XACMLPdpServletTest - testDoPutToLong"); + try{ + Mockito.when(httpServletRequest.getParameter("cache")).thenReturn("policies"); + + Mockito.when(httpServletRequest.getContentType()).thenReturn("text/json"); + Mockito.when(httpServletRequest.getContentLength()).thenReturn(32768); + + pdpServlet.init(servletConfig); + pdpServlet.doPut(httpServletRequest, httpServletResponse); + //response.sendError(HttpServletResponse.SC_BAD_REQUEST, "no content-type given"); + Mockito.verify(httpServletResponse).sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid cache: 'policies' or content-type: 'text/json'"); + assertTrue(true); + }catch (Exception e){ + System.out.println("Unexpected exception in testDoPutInvalidContentType"); + e.printStackTrace(); + fail(); + } + } + + public void testDestroy(){ + logger.info("XACMLPdpServletTest - testDestroy"); + + try{ + pdpServlet.init(servletConfig); + pdpServlet.destroy(); + }catch(Exception e){ + System.out.println("Unexpected exception in testDestroy"); + e.printStackTrace(); + fail(); + } + } +} diff --git a/ECOMP-PDP-REST/xacml.pdp.properties b/ECOMP-PDP-REST/xacml.pdp.properties new file mode 100644 index 000000000..7f25db1f7 --- /dev/null +++ b/ECOMP-PDP-REST/xacml.pdp.properties @@ -0,0 +1,152 @@ +### +# ============LICENSE_START======================================================= +# ECOMP-PDP-REST +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +# Default XACML Properties File for PDP RESTful servlet +# +# Standard API Factories +# +xacml.dataTypeFactory=com.att.research.xacml.std.StdDataTypeFactory +xacml.pdpEngineFactory=com.att.research.xacmlatt.pdp.ATTPDPEngineFactory +xacml.pepEngineFactory=com.att.research.xacml.std.pep.StdEngineFactory +# NOT USED SEE BELOW xacml.pipFinderFactory=org.openecomp.policy.xacml.std.pip.StdPIPFinderFactory +xacml.traceEngineFactory=com.att.research.xacml.std.trace.LoggingTraceEngineFactory +# +# AT&T PDP Implementation Factories +# +xacml.att.evaluationContextFactory=com.att.research.xacmlatt.pdp.std.StdEvaluationContextFactory +xacml.att.combiningAlgorithmFactory=com.att.research.xacmlatt.pdp.std.StdCombiningAlgorithmFactory +xacml.att.functionDefinitionFactory=org.openecomp.policy.xacml.custom.EcompFunctionDefinitionFactory +# NOT USED SEE BELOW xacml.att.policyFinderFactory=org.openecomp.policy.pdp.std.StdPolicyFinderFactory + +# +# AT&T RESTful PDP Implementation Factories +# +xacml.pipFinderFactory=org.openecomp.policy.pdp.rest.impl.XACMLPdpPIPFinderFactory +xacml.att.policyFinderFactory=org.openecomp.policy.pdp.rest.XACMLPdpPolicyFinderFactory +# +# When set to true, this flag tells the StdPolicyFinderFactory to combined all the root policy files into +# into one PolicySet and use the given Policy Algorithm. +# +xacml.att.policyFinderFactory.combineRootPolicies=urn:com:att:xacml:3.0:policy-combining-algorithm:combined-deny-overrides +# +# PDP RESTful API properties +# +# Set this to the address where the XACML-PAP-REST servlet is running +xacml.rest.pap.url=http://localhost:8070/pap/ + +#if multiple paps exist, the xacml.rest.pap.url can be removed and they can be defined like this: +#xacml.rest.pap.urls=http://localhost:9090/pap/,http://localhost:9091/pap/ + +# +# Give the running PDP an ID for the PAP. The url that its running as is a good choice. +# The PAP identifies PDP's using the URL of the PDP. +# +xacml.rest.pdp.id=http://localhost:9091/pdp/ + +# Give the port number used for the PDP + +xacml.jmx.port=0 + +# Notifcation type: websocket or ueb + +xacml.notification.type=websocket +xacml.ueb.cluster=localhost.com,localhost1.com +# +# Set the directory where the PDP holds its Policy Cache and PIP Configuration +# +xacml.rest.pdp.config=config + +xacml.rest.pdp.webapps=/webapps +# +# Initialize register with PAP servlet +# +xacml.rest.pdp.register=true +# +# Sleep period in seconds between register attempts +# +xacml.rest.pdp.register.sleep=15 +# +# number of attempts to register. -1 means keep trying forever. +# +xacml.rest.pdp.register.retries=-1 +# +# max number of bytes in a POST of a XML/JSON request +# old value #32767 +xacml.rest.pdp.maxcontent=99999999 +# +# Set UserID here +xacml.rest.pdp.userid=testpdp +# Set Password here +xacml.rest.pdp.password=alpha456 + +# id PAP +xacml.rest.pap.userid=testpap +#if multiple paps have different logins, they can be defined like this: +#http\://localhost\:9090/pap/.xacml.rest.pap.userid=testpap + +# pass PAP +xacml.rest.pap.password=alpha123 +#http\://localhost\:9090/pap/.xacml.rest.pap.password=alpha123 + +# Delay for Notifications Don't change this. Value in milliSec. +xacml.rest.notification.delay=30 +# Buffer Size. +REQUEST_BUFFER_SIZE=15 + +#properties for MySql xacml database: PLEASE DO NOT REMOVE... NEEDED FOR APIs +javax.persistence.jdbc.driver=com.mysql.jdbc.Driver +javax.persistence.jdbc.url=jdbc:mysql://localhost:3306/xacml +javax.persistence.jdbc.user=policy_user +javax.persistence.jdbc.password=password + + +#***Properties for IntegrityMonitor integration defined in XACMLRestProperties.java*** + +#The name of the PDP. Must be unique across the system +xacml.rest.pdp.resource.name=site_1.pdp_1 + +#***Properties for IntegrityMonitor integration defined in IntegrityMonitorProperties.java*** + +#Interval between forward progress counter updates in seconds +fp_monitor_interval=30 + +#Number of forward progress counter failures before failover +failed_counter_threshold=3 + +#Interval in seconds between test transactions if there is no other traffic +test_trans_interval=10 + +#Interval in seconds between updates of the forward progress counter in the DB +write_fpc_interval=5 + +#Name of the site +site_name=site_1 + +#Node type +node_type=pdp_xacml + +#Dependency groups are groups of resources upon which a node operational state is dependent upon). +#Each group is a comma-separated list of resource names and groups are separated by a semicolon. +#A group may contain one or more members. Resource names must match the resource names defined +#in the respective servers' properties files +dependency_groups=site_1.pdplp_1;site_1.pypdp_1;site_1.astragw_1;site_1.brmsgw_1 + +# this can be DEVL, TEST, PROD +ENVIRONMENT=DEVL diff --git a/ECOMP-PDP/.gitignore b/ECOMP-PDP/.gitignore new file mode 100644 index 000000000..74a25dfd0 --- /dev/null +++ b/ECOMP-PDP/.gitignore @@ -0,0 +1,13 @@ +/bin +/target/ +/target/ +/target/ +/target/ +/target/ +/target/ +/target/ +/target/ +/target/ +/target/ +/target/ +/target/ diff --git a/ECOMP-PDP/logging.properties b/ECOMP-PDP/logging.properties new file mode 100644 index 000000000..747d39b30 --- /dev/null +++ b/ECOMP-PDP/logging.properties @@ -0,0 +1,29 @@ +### +# ============LICENSE_START======================================================= +# ECOMP-PDP +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +handlers = java.util.logging.ConsoleHandler, java.util.logging.FileHandler + +.level = ALL + +java.util.logging.ConsoleHandler.level = INFO +java.util.logging.FileHandler.level = INFO +java.util.logging.FileHandler.pattern=%h/xacml_log%u.log +java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter +java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter diff --git a/ECOMP-PDP/policyLogger.properties b/ECOMP-PDP/policyLogger.properties new file mode 100644 index 000000000..0e9957442 --- /dev/null +++ b/ECOMP-PDP/policyLogger.properties @@ -0,0 +1,44 @@ +### +# ============LICENSE_START======================================================= +# ECOMP-PDP +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +################################### Set concurrentHashMap and timer info ####################### +#Timer initial delay and the delay between in milliseconds before task is to be execute. +timer.delay.time=1000 +#Timer scheduleAtFixedRate period - time in milliseconds between successive task executions. +check.interval= 30000 +#Longest time an event info can be stored in the concurrentHashMap for logging - in seconds. +event.expired.time=86400 +#Size of the concurrentHashMap which stores the event starting time, etc - when its size reaches this limit, the Timer gets executed +#to remove all expired records from this concurrentHashMap. +concurrentHashMap.limit=5000 +#Size of the concurrentHashMap - when its size drops to this point, stop the Timer +stop.check.point=2500 +################################### Set logging format ############################################# +# set EELF for EELF logging format, set LOG4J for using log4j, set SYSTEMOUT for using system.out.println +logger.type=EELF +#################################### Set level for EELF or SYSTEMOUT logging ################################## +# Set level for debug file. Set DEBUG to enable .info, .warn and .debug; set INFO for enable .info and .warn; set OFF to disable all +debugLogger.level=INFO +# Set level for metrics file. Set OFF to disable; set ON to enable +metricsLogger.level=ON +# Set level for error file. Set OFF to disable; set ON to enable +error.level=ON +# Set level for audit file. Set OFF to disable; set ON to enable +audit.level=ON diff --git a/ECOMP-PDP/pom.xml b/ECOMP-PDP/pom.xml new file mode 100644 index 000000000..9856ee20f --- /dev/null +++ b/ECOMP-PDP/pom.xml @@ -0,0 +1,114 @@ + + + + + + + 4.0.0 + org.openecomp.policy.engine + ECOMP-PDP + ECOMP-PDP + jar + + org.openecomp.policy.engine + PolicyEngineSuite + 1.0.0-SNAPSHOT + + + + org.apache.httpcomponents + httpcore + 4.2.4 + + + org.apache.httpcomponents + httpclient + 4.2.4 + + + org.openecomp.policy.engine + ${project.version} + ECOMP-REST + + + commons-codec + commons-codec + 1.5 + + + commons-logging + commons-logging + 1.1.3 + + + javax.servlet + servlet-api + + + + + com.google.guava + guava + 14.0.1 + + + org.apache.httpcomponents + httpclient + 4.3.1 + + + org.apache.httpcomponents + httpcore + 4.3.1 + + + commons-io + commons-io + 2.4 + + + org.glassfish + javax.json + 1.0.4 + + + com.sun.jersey + jersey-client + 1.18 + + + com.sun.jersey + jersey-core + 1.18 + + + com.att.research.xacml + xacml-pdp + 1.0.0 + + + junit + junit + 4.11 + + + diff --git a/ECOMP-PDP/sql/xacmlTest.mv.db b/ECOMP-PDP/sql/xacmlTest.mv.db new file mode 100644 index 0000000000000000000000000000000000000000..81e99a969e0e4e22295dab052ba185b7f7e79366 GIT binary patch literal 143360 zcmeFa2YejG**|`}cMruzV9C9~$p%|Cl6+N-Doe60BTKT1jcMj2oosBn3TYz1STagDS=4| zOiEx<0+SM$l)$6}CM7T_fk_Gc7f4`@9`|d1a{T{app{7$CM7T_fk_EWN?=j~lM^{!E;?5wh6>y>DpLd<@nHcY#T@q#53vGK*F{wAo@Cfyno=T(1phtAzBbB zJ?N~h9ybfa9Ze$%wVFkd-ce!)|E}WSFNdyH#eWRW4Q5z6HXb=j*SC5xL9s% zJKhMDnm#OmMgARbELv%V;-ONb98ZrK{|X&yghF%nghE%(2!+f&A>-m{c(ErGf3-{a ziJM;%e)5De>Hnlh_^J2E=XA#ncz!Ij{MYb-$GEU;YDrmH+3Y3r=N)wr6jdEh2`>>7 zUNSDcR6=;^WXW)5d$xLLcp$s0I-Zy*otJ@-H0+KaI)%-p2kbT(kH!16RmQbd)=9HuqfEwQb=agLj51N5 z+oY0EM3ZXIOFS;9_E}W>YZG>=^$x22eOXPkUlFYzltlYMG*O?8X`-og(kcVV-7=@? ztfty8sDif2YZAL{a#;;n`f63_tI;$EYLkg>LCa!Zk zsB)Xu1)qyOq+FL$G8Uv$HOb1I!#l^sPN9N|Af}{H6W6Q^24@A5m32@esaQ#AR#JkM zM8+Y7n%bNcYT`Sk5HgA|YuF)!v_t#}yP@@K86+$-lY|pe`pMclC4y8uolGXumhdy8 zq&4K1w1r&$8f0liX5`kY4QdZnT)x%i(C=*$`?JKhELYfM0cKP^k%O-f9Tn1rTls0_ z*C<~X{yOzMaFD1B67n&TQhr)SC*@;OK_wMbvR=h!l;5ZPe&r8JKcLnsj>r(^Pc zI<9>6KCSSl6~1)8WTRGkebQ5riu1uKtf@p_tS_EW!Txl8N(TGu)AfldTzF%t`qV&N z2K!>Mfusl~(7vQN70BWjYODY~>sd#OwPv)bhE`fZAjMgUmtYCj4 zmX)z}@pN4h&B)|$QUa3_n3TYz1STagDS`h238?67 zpi?A$OHoV+_($w{N%+&k%D-O5mo8KOHzZuy z3HwC4vfq^nfBJp${fw0|eum;_=F9SV))wXeR>IHD$mcl+l?nJcS4)5HQ7?(-xu2Eq z=bhUnp6Ab(@$;WA6VD5>(qE|LweTVN{>U!nzuGR+9o5JaGGz%NZx=m?rYb7%pT(-K-v)fA@`)zWcv z5;f6kYNPekOPlCS%21Zhp%EIR3+Q6nW6|n>S}51Y1zE8x3#S~8n2I)MixaEm0V`X_-Jo;OINgYRkXdMC)#pqYj;m~ zw7U`i+j^o)vvqxg1Bql!ELPW-tf?7T8eP-ay(YRemFcfb*J83_Af1d2)W>VGnZbc% z?O>+9zXo63#FB}@bSzs_lTG(!6N3ZwnM8kTpg%JZOZO)S(<$I-Y+l#eUK&{(jg~wc zR-807HmzxCj`lRJY-@>j_O5JeZK`hU>FH`++1t}nF@+0bYjd=Rj`kdiSgLNBeBIi;87W#S25bVZqP9`1D=&8@3iTZ*w@C3EtShpe-! zwWF)G$I6W4p}VE6r3vIWcQ*E{abxn-#-?>`n;}6Zn>?&d$oA@vu1#9NN^~9V-9256 z5c=kxO`R>ym*BF|9y?`OY2@f=dC4i-wAx$OLl>>>%`K;Dg*N37iulcqQOLAF+nU*B zuuQeX2x;uO7!d6hyj56qig8&QS%RFM zq;duotZRg016}%x2!3@} zM{j3q`)XZ=D{4~t)fnm`R9x-Nja?`Mg*8$4nvSlX&FzirtUA&Khb|Qs8Ao-=`l^J! z)=s3DCv94@GOOtTVHK1!;-Va#wzx);6D`xp(nvM3abhsDbIpLXwOxn2%C>d{O`}pO zqv^1<70AvxuP;0C;1-6QM5e*SZt*oStLEi8yNIFL>Pk_=t2V>MR$QA#d+W;P5-EkC zn}Z2@mEBUDJc}AMQs!kUj>N?cW>s(juR<24L%`Pt6R_xmbQckEXIDpOOILm~?$Uk9 z^=<5RW+-HQ^RSoE-9yiFCe5PRu)4?$hus{PvSL++Xua+@?2WA1IW(8%(R|kI91o+{ z;Kg-NKhgTJ9%SbRuOMABB@JnwM{PI(=Ieu75c54B7WAU2N`hObNB2XDSdhd}tlzFv zAwRaELtf9vwW7?8Ay)Oat!iy++nnn;RU{K?d|{0X{6{cWGG9LI^?4qP+62AYeOTsk z(?7v&-2z%jN77LgW!qd3+(;5O%ePb@jbtH=WXPqq(aDNicp|usB*6BOu#wyRY8g#A z*QqU5r~AlOBeQjUWtZ8#dIx_;*{T&=hu>|$k!W&}tDS8r;wVIXzK@7)5CNp!Gy!op zahJUGB{rRMT11QKXgY>XryM%?pq~ypJ1`Bfsj&@1)7G9f>xwDhf2qb_1l4q@+C`2e zokK8N_eqX&?fNOmk}h`KQCbWYUErdke4yg`X_{z#-vshJd=J=x@XeC6Hy){v9+=Ev zMkqJt_8;@Y){LLeeu5j&CA5?(Xc=4D5?I;;ewNnN+t%{mW@k&Gj?RhL*-BeIke4C5 zl~q77J6#mx1SxJ~D<^7WE1?M<>jxYQ_+$qbhB{^Dyn|WK%jsCEq$<`kkMiAShbEl0 z3A84hD<0xM>}OxAdfS_L0#4L^V|NXTQ#%W~#YmRcm`IE2&7gkag3x(nI$Ave)b7nvTs*VA%;!(K#?H znzIg;HnfP@92qTDzqzZWr?;!!gA1ft)4F<1OV{R(u4bO%cbzvs0MkK|CCSTXZFicS zu&ouat$>qzb!ivdvZ+NHSIndOD%4|f>jK5V)>W5A)AG56tJ%8Zl%OPAR~**$6TgDr z+1iQzz^c~OosC_MMSCzJ5tb8HHTGf&M$fw>asvgKz%hdtk0lD`0cA4BbV7x|l2=o7 zwXE-L?ZUc?%VZ%q&#xyE&}GmLf}@9!Cj_a;Boyh|L2#xnuEnMabVi%FGkW8KZ?YCs zl%^WiVhUP(&~GKm(qeB{V}Kf>sSUHq4kft>Uk@Dp$8|cD@35}O@UpeLyBD>9wkKgR zvgBH$Mt>%(WWHQDb8Mdm)YU{|GlsZro7~JznPN98w(gF$4Pe*BCdClTwsH_j2e-&( zTjf%qPic`gut>K#ul(f2O|m(7z0!=`>zfu|$~~D{s-t>pV3VwcNnTsTB(R@UsgLRS`V@_MM6eZ299%eS|(g6oiowB%vfkxn_s}bw|kp@`Q zuZlEPn*9HBja6%NuHLZf2ejAM9PaLDMv|1D)V?K z)2**tkiNJ|K`*dM>v$6D1gP{3Ws+|5oZx|L%p&!Jecq}fW!oAd`fn#fUIACh>f=tc z7qlTI=;6hqhgc6M(aF?ED_IXGL2hn~WQynF(gL->(yEVx;>nQKKEDFc)zQ{cbYRxg z)0^8y;SiT<Qk7IO8&55ynql*A{JR>sVr_fi_~~7 zrr_A*Ad9L_wMZ#Mh>eturp2E{$dzRh8Q|qf~4Ykr*I)zK)YAAl4 z%z&Du!=T)6CzieH&WSOX51yW01LeC7*sS!$bspDqhBnN_I0NNYWGCSEEBA~@>s^Zs zxb451NCqY_W5A8hDX`gZ`ZYQ&?W;Pvny{@WKue7pu^s#TFhzx}b=ZNX2XrpR>p-g$ z<{6>f)~H{)^^wI4f)6cWe@j<~ip4;do**Tn8;) z`kzdU{}_s(ZvSmfaM#qHP^br!;qLY>%$&K*Gj$ zVJ0-M+PJC^B%F1X zdM&nnHnBXrAK(hhI$_e|VuU$MS9BAC$mpp^5rk6I*Mmm+PrWY!98$H`#i|ZCt z?YadmZ_Osspt=E?eble-(cIG1%3EKt>)uvSa+|g+0XaJt{_Vdkn$4njo9oyH>Vh1g z9)_d^S-I>w*NckUM)I-<3oh6p9@z-Xn9$<6y<1u!W6c2<{ZnBVyIiW#e4ygSk(%%h zab9?Orsj0E)J=36ola-4rEWrAR|jh)Kr*)zKA&UNPMn4ey3I7?Cl8Xr3Cx(M8j+RL zVgCF4Mt6;(TOx-6&8Wk<8s$N66>HES>_*wWRlEm~4t*V415!|T(D z16s~pYgEZZZ&#b<$`X^PYtIO7WeIy>D$tmyaE(9I+{|WtCY?o_>1;ORGhugb{gZqI z#qAFCgV(w|;yVjwcaL9tiV4$It*5r(%cWw?Y2imamKaqX*X9_}7ru2Yr&+Is4mLvv zjloKKlVcqs$G+?fo()-Vcd5j3`7ADFPzWsLCagY~?>g?^tnv)?Q9li^$}^Dr8+`hO z*uLD;(bUnle}Y%?RybTM03p>rNVO@LRO{_K^c~zux%NY@ZeJMKlNOgOs05a5J@3mO zfE=Ij>owpzrgcRuR~9o}_NDC5|LbY(Wa$^icj6n5!Z)kBI@X=m(Qftllnz|eI)tKn zh%$XQMyf7k5$#UZrJpJhalTy@uU>c9c@@KlgX;gvqs%M~(iYlELu{s57)Zcr(}aD1 zDWon9V-SY1#ihV;lHvvdtbq+8!2`!FFo+9%3YJuMfMO*R`iRg)^rBF04PI5%*>_;s zIFpha@~EnE35&}Q6aveyZY8R!!;UXuD>#SFrERpGhS>_vflSZ$k*PM#BIV3QV7Wr# zDrh0kb0N=w>m&A&j>VJ|<~9h^ZU3`QR$P=57|`%|W;=wo!$)Y{Els`rohg^YB7$?3 zjTD`u$rR!m4qm6PwD*Y}{6J=~h2<-kaJ zmS6GfrQj=T{_IhFz*j_=jh&sk`Yov1^S?rtGWHQaTTfnJ7T@!>cXPZu6?+F%=<7V_ zE8u?3#+ZHC+mUB!5y8s`ST&b8~l1U8@jRYL<|axSiF>sV|mMEzDlQZPK(JB;8JtT-EQ*r0Ue=n zwl>RrX(ii+0@6( zC~gEGr9OwZBX_F5a1NY5v)YYZ1swEvF7a|*OGkO!t#soeRsAcvqf(7sOwcz$u zTpj-3GT-)9@+=3{t#{b2am%XLxSqV2E}=Kj8`*L%hK?unsduWyHj%YKNf5rE$~Jom zlu%Ms~R--Lqt*I8!eFJh5u%G6d2WhHr1ov($h!fy`0z-yW3o4Ws);92F zRU8*{sX>?FY~M&^j{)2Lf!}nTtjh7B0lIL~fMpEkqgS@B#ttb<@v@H8)$8k-j&5t| z!A@eeu_nR zT%lx>!84kc3Y6rTiA-|#}wZ(u5Izj} zZP9Ma4$dZHLOt@lQeaj0P9%A$I`K8dMtsPmJKT~!pIv6ReqjaIvK8o!CpPi9SwXzU z)>W}(SxLec10itTu$Ps*$4$w$v_aJi>Nfr=Y#5lDcP$#Pfe~KXeJ%G1-ek~q2EAEW z;G0<4xB69FV*0_ZW)Z=sSpCPk1mZg;LB_LRa3FdOf&yyV{7$Vj6!F$>DQ=ajWr_Yh zAS;=#!MfE?*Rf>=+<4w(pLiAQE47I*G{)BWX0}GR^}F^Y@HW6E%)^GC z>s-mTAkHm(i$OOSbfd7r>)8gc_p`yy=1#i>;_*Lfe+R<2)~-91=gS}vx3dQ=gE$a& z199Z6*v(3jpqL?R4XQ#dYQ?v(?KK5!8|~w_oVKK**z9g#vvV7*TZxMsopY$JaC=)E z58rNN)ABvkCD+5YTUajEt0$IAVH+jnB8$oUKi$DPpaxb@F`+G4)4PBttZ@G5O$Oa; z&@BetDoXP{wwm?9tftvMZmZn?H)Dr z6z0urQhtkZqA01!=>SV|c1y|Y!Pt=KMoJXSTUf*aw+OAY?`$q$O$zo_7OdM|jr{b* z1q*U^!TO4GWgK?2`1D8Fj&O+W?FPNopgRn@Q`pgMqE+zghT_Ohe0kO_m@G2g<}#5W zTX`Sp+crmBxOXIBdTtt@!A4F>kC6&E_l1QvQd+wdJM+jdn(-FEQu zfM#VQ&WFX8TzkF9&pawGXx4;i?qtzuv^I|1y3zJtvC+D4Uc+4mz0IJz z4Z26z$6YKtx5bP?Y{ez$>{VODy&IPrNbzkfMZeY10IQ&!#K#8tb>V90-7M#zI~eRH zC>WBacMprtZ3_dZDK4(=CtYzXK0)JT#6QP8}x2rk?&-2ZVJ|YX-lq~*+TA*ALWwNn4tm#_`s*!=ez^ge^$FKpmF zERhan1CDv&Ri|vuoxP{e8CLl06|I%1LMLL)zn3NOVK)g_={>UVN;is6z*=znHXkXT zqvOoIE1<zmFwyW^svFr@V@VJBvz9ucvr|mYcX=~rPH8!lTA6VXnw3(l{BoyPi4G=q(V*zPJYdiV z4Emr!9}*_^Krj>Iz6|5Eh`UKrCt?wP;J}!eM(L29j`S0nPGd1#C@q~N&%{2+5*aFH zV!89yH``9fRMhO7H7!HSK~&fvSXLimS$*Bt+;YGH3T7^`oi~RF?HqU)RCh#HCJRNX z(b`1{)BEVaDO|hZI*JEoxh`MmIz0u20Ut!4| zr$DigA7mlFFw=wk*w zY|zJr$v(t_KG(x!H6}X`md3z!KuOy{*l<6_qW+ef;kpoMhWMq;{?x($pzk zEmyy^DB95|N!CUSC8^<@2MpTU`^SeLU<=0WOOF`zNrOHmEcg=>6SQt4g9_S~o^AIL z7W9|hY*({yWqTrmwo!2i+7@4EwFMNd10U^~D-^UwnrE?}WI>L2R0Wz=PC4qpOB+o- z&%)7!6#`Y{olMCh{S=Gz`+g$L5iKs$T-tmF9fHm0qoDpRp*0y(;aD%mx;$j$=LM?2a&{m9K{Sz5itq@`f(VMJUpXo5DC2d2c-=q@H%g0!xk_Vffx#;eb6%d|XW zj?11!y0Fh)kRDa6m7eAGB+Kio9`>aXOHzTPR>+mZ(CpOR?9EBhHFJf{hb@!#76kR% zljnb#ZSN_Ao;K)n20bHe?Oe%cCM&9Y>lX30M7CfR&2Z^7oL zw3u-S)uLJ;QBQbfo+%ge)Y$BzM0P&MLi6gEJEjaB#?9EQe!1r)q6-L%@EI22-`qrK zC+ICcd#cSYG#pZNd0*JWDTYzWHR&SP0{m(MwIJSB9l(TljlY*o7`J+U!JuaidQO<| z=lx9B!K8h?+u|-awPa6QVNc8Q{{qY3b=JfV7Eu0nNyLz$b)9KGl`UaWuKpf4Kqf}_l_;JWoVr1Lcj|>&c)?PYtdC~(%*vAW;x4T{K zBcI`kG_J%@f6x-VEU|9QKec@kt%PMXze#xM(2wVFyFBSGHOm3SOG*5E17*Eb6 z)O0NW{!32M)X~eIx8RzMuGXfCWZg2cxcU;?b-^UFepUuA8a;H?dzce@JHF;GByK7cif zHS{zu+P=(K^gaZgW4k3ZclzT1XHA!UFKmS9Yl5w>6)`Q@EZT8m3sK~y-El_ob%EmR zY#pCERAr41NyOn5tt}fhTk9Hon$}ozJ>BTgV2P41IF+lF;%F$2%Nu%EMjaPuR7Np@ zg6lk_-z)w2=GJapuOi~&RskkQD=I&ef|t{y9Znl&0axm>@51iBS^?I+e^Xzg9U{bodEZkf?Y_Lc}-5 zt0h|XLW@Sf)cr|x=B*SuPGLwmF=z=&42f!;I)@=A*C~8#NmPBnCNBjqoG6Jl3sihX z_=@G)IEt|9M=uI*^G?yJ`5AvbxYPqZ=a z&xn=MVvUDDa#&Z}5Y-4-5GO>12`LUZYv|NfKpCth*@}V1Wfnc$`72%*;*e>A=OJO? zbQR|7&qKnIheUoJ64h>bSTK*9oJ~z5H;F2xJJ8wif4^x zWqef|rukdiTe|WqwY)4A)MXHj{obDgQ@IH&Nn5>_JaF}1UWT{|$&1p}RrLiSwp2-vTHdNW(H)$!_szSw@_a>9p09A_ z`G*;vm8Y!t1Uz4jX9>TcW0+sRkHjY68`>n5GPQF7PbQDOv)O-6Zeuy0PtvjOp z3b)hQXWeWy>_TklVA;kDTsZQ_4KmJm>>!imDcQ3fRYdIL0@X%xnUPqe46Ky)4uxlX zDpO0Pb0WL?bMFd=7yQn5h@lc_MdtS)USKNH z-f|k-;DsOaj3L*c+6FM3ZpE?3T4`V3D5kYLdQv=k?6Gnj!?=UD5V^68H&4*=1e-cL zFO1iJRKqEXjchng@Lc6aHw@=4=>wE2&sLl%%UrpSb@)C1g6AsNnls#gG*_POI#c#* z+xflh1r&_r*i38kdI)MX#&@FPZQA`U-@=NwslvB;&6G%%-wAOUGKvC|hYfYIqq^iY z7zpxEkMor4u{3b4rYiL}oCCEQl5(QfG92b4ks$I1-aW8Ly+e_xnAM~3W4 zD+<%9+z7TDa3ZHR;6hMGa-rm9_;4+B&%U1>e5irIp3u>sTO<9St`+_DM4g}a+}!+o=X!ye${ z!>jw)$Ii-+39fFs^WYhwQnNf>YA#BYnv0XA=FzEA^O$t0xumAlTv}UdR?s1(<}y08 z)Lc$eO3h^z{ zC4#=n#4MVH^s{L;+&MG{?p&G+cOK1yJD=vmT|f)qE~JHUkEA2v9z{pNjZzeDIhDg* zM2p}qrp0iNrla8=LoBK#v;^)_S_-#J3cDNnX0k;!(^LYGjz2!@iD`|9H)P?lj)D5?X zdf@g_FWe2Z0q#cH2=`Pv749b51ot#L4esf5I@~kp47g{~nQ+gdv*2!~&2Z1Av*Bha z1GkU*;Pz8L+yNXp?(w_zmaODT7J@+V z;SSR<+z}dqyMuPXJ&(?VJ4&N)$7l@hIE};INju@5Pv^tEfG&W$i*|W175eb4X~~r= zlo!&4NPiJs1ovXP815x>3EVf(8{oc?-UxS(f%DtoU&@EL!M}`8a)Xa!ur6mGXJK8z zJ`TjXlKrdrU@Z7JW$0@5an#T??Bl$lYuVq+=MKTg0Wfc3|2jSh#*5$2-u5QRudY6D zYRB~qg`+#(!amOLxPko}`5X`UI0|4N`#2BaCiZbCz|HLAWPn@Pzm-o2fR9hTZ(|?d zd*9AJKKgzu`}p$v4)*WlFTmmBd*8d*$49?!V;^7s-p&3!`~@)ldkuU|>dk$tBe~7>EfscVZg@@_lLZ=H#WZY zrw1Q{npsxW@UavAVTSrR?}&$w-Nm0^A6twcVITX9Kgs^5c)u}xY~K7d``E$x8TPS_ z^Rw(f%G){NKW1R>9sI|610H;A!Fz)JCwVI#d~A+-ihb;mdYXM~llmO{&+v9B_}F>! zdG@jW~3EY|S z@zJ5ao#WXYc8#T!me?3?>mM1&_GQMhB{iN1U76KzrL=Tyrhj~BWEkwJkPj{o<|Kwv zs<5%vmFe%#j*VH;Jbq#fI-yHxSx0vG{Grj2;qBRBR+;^=*BeH& z=k3gnjSmfPsoI|D-#Rp$Ejif}yQ^pmF_hA=HWIy~+5Vv&L&%0Do0BF=ArAqzhRwVC zwZjfU)lu@gSwMI1by+3% zy!XG7z|oo3&uG89xg;ElCz7GkaCvK2W_U}sWJ`B;JerA)@hu@@eHH1Fjv}*`C>5JUb9-#l06FVRF;6 zCsc9N_0m7@1?fM21JS`$O0%$msrA0}5!ftwa%dPWR7q7)V0-e? zNHs9D?MlaD?P$kJR`}L71DWwm)%flm*#-?z8d(AO?t#qio}um8=ABBuv7$`mL15?5 zG$2|t4lE_d6ouww5adbs{*47$N@X;iX3$JN(YO?7P8k>;6WOWu%uWJLX)Ze|J;2Kt zyl-S=TQ)NsKoKe>0H*`64H&a5h>~SRv!Ig#bOu1%M+f`s5(&X|+>>jrWOH2SK!9W> zkgQ>(0mR42Aih`L{+%NZ4$&-{O><~2&7=9WfJHb9sMZbbXdD>eLRk{?WXCB)3j!!+ z14ZxdY-V)b$nf}9%PtZ{#ZmwRWOJCGt=V15!j~6CVxbwIegW)m9UFciXsm$(cbO9L`i6eD|lO zm2!h$Jj0R&o=BNs&B1d$!3zk_{sc5kp1qnt`QaI*k_p#0JUu=n z0YsxJah^E~z=||6p7#nMN3I`v@~vb)3LHF zBo^tgd6p>Dif+G!?>TL{A)EWV09Ys;DRTrX+ zpEfc&kR8nqR1IW@cUO&^pB)_?8pw{7w0l;uT-0UHsj7cud*9G7k3KTnFsd9H-@3iQ z9UrJ2DX0xs?ZDV|XuK-3W5+g(UbFop!vn8_nkzm~I||gg^76E5fAi$T1ME>?-=H$G zb9ft%963$N+Wn3^W}Tkd30RKuF~Tl>`N5}V9LkO90m}w2KparX^SVaK0V;32 zc5)!?o7Z0sbdAHSJg)<%YaPt%MjWdVo;! zqH@WBlK`(&mmCm_r;4Jrnx|?CZH-scOAe?-@ydLW_Q8`sZKL@$5pSnBP_+^7H`w2@ zT3C0|5?du68hYr%a}JTClB)I7@Mce_>OnaPS$)Le;<#a$!qdFj z(W>#Snc=FD(JCyRWVV$w`4;EFox@_eNi3IPj@cbaq^xx6B1Nu8lf#PJ_$a2=eTH~k znhPjsxXRM0i_0-?Ll%1FpucK-q)K5gsSU<<0U)p*t+0w^M9!1wfDaGA-?qD?AsAwv zOFL{O2AMlQ{$Z#O+F<6~79VANb>?Ia()4Kh*& zq3?QR6@)I=is>-OeVH~!&Cl?FBIIp1j(kM(0XYN97p>${9F6K6VCc^4$-_Lw>%BzG zQ?mIvut7%Vl}rCcbf9(tjm(4G zFZ{&wEO%?oWNMWrri;gZc0%hT^P^dSkl4j@GTdNKM6+&_m zjZD*+?M%zGKKA0kTnH&7f6ga`#j9l&SbU^Z(dyxeMu+|QPg+}+nGYA42CQWotDO%{ z=~JtF^3QNA@W^zHl~+CXhu3_#$V_0Jp|RR|<&^uwE5iv%U-p?fY~wTKnhZ;NrlNBy zr|HR;ws-sCkc%5^WIC|V(%AEJ!IXSjCkJ*nSRwh@3i}4R$l#EDKwB?_jLZk$b2Mf< zZJBm|Y+XVM4SeCzFS7=$)v&3Nxr)~2yd_IVb{d1VSUxCLAY1b^DSNi^U`hg#@g2xt0{2>j?4o7MH;`ID=T@CJvbJA zS74zPJ!06XwhuVC577&aE3qxT5}VR1 zv9GF9?%l^E=nApJewx^|Un+LYm+>a{GVI}slwt1@w(?^q7+h>af{X1`*w&9VTWssc z)G;>hV?j1Di>H0DaUbi-k-2Gh#1{ecc;6Iu?_i?>GeskUwQ-5%SvxhP)(d8cxZ@M_H7&KKer)Kxh*@4r)@*$XV+zRHN-@y zGqVMoWMh@!v!Mp=u7-Gjta3QJYrG*@xkJ26RE~~}j5nlW{7c7U{gvE>YpCt7#4;&w z4Qq%C*)-(KW+6)qa|SHGM6yzBFw1VxF!HUIoZs7I%=fJaW=S`h@`bH)f2&~Y-QP-{ zQyz5H+Ztb3U(D%*A8b19`_>~zlB=4yA8d`UtZHiWVGk4f-8nok(l)XMrhn_x%R*%# zVS}nfC8V(@q_HQYu_vUlC#10_q_HQYu_vUlC#10_q_HQYu_vUlC#10_q_HQYu}jR! znBAyqJw-KvUl(M``MRK}NVAi)V~(`(f`S99yzleB)mEu0_@p$)q%s<5j!9{b zNokHrX^u&0j!9{bNokHrX^u&0j!9{bNokHrX^s+QO4j(PxRc2O(~_^H660}yal{MC zw-dTRS`ONUwXg#^QD6m5Xn)$t0t<5>PZlW0fjsGNB}oslD5)j=Ei~ybmXtqhsRE5n z73RNfq;Fkjha(p$4-u)7k}ePt8|VugwSlUxM@m{|N|}+g%#^gul(fv0w9J&W%#^gu zl(fv0w9J&W%#^gul(bBVD=jTEEvx5r!jXrxzZInYMP1`x8Ps^FS?RH`33Av_jlUJt zct~F%FKiGT$ZI{UKtp?oMZflEt=6Bl!ZyRfT3rEamIZcY2c1d%*(_{AoX`bqV%O@_ z=kE&5mhF04T4q{WW?EU3w9K@$%(S%3w6x5$w9K@$%yhr#n$`%nR=9P-tru=axP8Kv zDF;M2E8Ia*@vHuL>~JoEx^o_{aX!{NGF9(kl1g*+1;TYg`wO(*U+?t=0<|N@*8};T zD(7oo))Fxf)?{syh9VgQkq?9iuoq`f=hb-XG4p|@@ zdxs@nP*=*gN^1p@aljTR#qqX4F7~&H0?bCOnM{~iP7RrNzj%CTNys@cbeLWu<#FH0qiG zx>|`u6%|n#SIh2z6-LEu^qa{VGg)UQ>&;}pnW`~UwPvc$Ox2sIjG5{)Q-~ZeQ&}@L zXr^OkI&P*DW;$u6Q)W7CrfbY}t(mSf)AeRLW2XDfc+8Ba%y^AaZzkeqB55YlW}?oh zF;WITA2WXW)vtx-hukMBB*U`AD#^+Rbl;^Y^<&ccsFbAN)=R0VM`hmnN$E&GrX85# zO26uD!bvCLe4BK>O**+q);ln#oODx8x+y2-w3FwwG9<-Sy4I0DC)paOq-vCzDNqMb zsC?~+5(y)2KwbT2V!%vf&BUP5XC`B2GHxc5W-@IiQO9J=Bq9gQWY$a$nyHwXikqo~ znMxY4k(8NA8(A~mXAGhq`qaxehALD&B*`a~Ny;Y&XGv8!)GOz^Iy;*w$Gem&0TM3d z$WS_AhfAj&PY#?ls^my4HLAp^Cx^6a9emcN?I!C$S?5St=U}?d!F0WYc)f#oy^@%k zz&My^xvJwas9PPvZlY@h>6s|lCDpRU^3P>Sl6$D zg9H6CK{6gorerXYs?XN-Ng_3M35~8c*=Gg&6S1sJP!~_vB{3a4`J0r$qy#1X&X#cXY{yw=pl}hI_kbE87PC;+$8gpT|RxUY)p4kVr?Fku| z$R$N{N|$&x-zEKUQ>S%dSzDCR5bM8e@PZ=dF%@+g9su#OSYoXj)~ zBb>(JLr35ggE_PSnFR^Ccd-@r!C=N zC7h*%}d zq!*0nfB$7pd|3JsH%}gxjw>@J4@-AHnmqr!Z1+@?hov|2CAYbQ!1GW4Z4?)ZOdghQ zm(k>5>AAC>xik46J%HQu3Mi&558#fwUarCK`4{|H@!Xlz4EG<+)#PF6?YV2eqd;UG^t%kns07{p&hN*!cPMPt301$(zSQbol3`zmyO7$8!@O*bjf;5b0mR zlL&Zz=QYxQQu#lU{y|~oFH(M^gg>ZX`PWMLgFdMIuk00g4*IKnKKMxad~maR-m0Fj zSI-}PR-`}pTWf`Xh@t!n`Tmej>h4@HdU7;%m91a9T-{PQVn&dQ6UN!HMTMh8!n{ z^YjM};l`{74ztE|2BtZ_Z_qCd`lCVr!a?XJ?K9~vliqF8gC>2-q^C{#l1ZfFy?BxIm-F*dP#B%@D^NhjtOG*z36~&r zET>*tN|l_tqLixm8GbcCFDs=L{0twTgCejTfl>|}i$ECyWt9j_=a?!4W`NIXP`q^J zo0+2e>`;IF#@|kXB0fPx@)ZcoLSQbw)TGF4j>2~;gfH=;k!kq!m++k&$4y6Q9zrwm zRS`wzi@2ExEkI~GzRDqdhQ;Y-BXlG}^CNS>z@C}YnE{-XhN&-g{+2w4h8Z|YK+Hub zS{_}2Pj3jH4l$DX2rWWrc4PrUkUHWPB6M_lv^sJm0xbG@k)se=g3yde6rrUe4$6wK z24+S0;DXC$-N^Kb2$+>WauQs&5Tqd?qtNtP$S}|Mc7VOB2I>y5H~#% zLtHcBWT=I87)R8qMH~?HOE~YVX$`f~S~>+2o$IKbI&jGZlC1`g*^vZ7Yk)(BS`jxt zl0@8E#L3Vptn?J3+7_w6I;5HrNh7Kqsbr`FadRRyi0ecgLM;0^=P~{D)J5IYgDKVx zm}EVTPNy@N{`&H0RiqYyu0<-)%@V9bOb<(t1HHgHH&Tz#24Iz;O(L!Vai@tm4xP@B z$02YALmmg(m(2Mi(>{~VqRn(RCU*O%p9V0!JIJ)p6gZAY=q!PQLz@}L2?(6cI5?0I zsZKRVL-&Z5%r@ z(uLsdGM0mHm9gC+TtqXkig`lIh8r<3!;gC~a0Lc#zqr@HJwCY20vA~@Pj^V@ZUpaS z=y{PI1n=Tl8GM_J?M3X}GM0n)$k+`C-Ya7{c%O{jh~V30EC=7gvC|@_hQQVQZ!uSB zY;kkO{d`#lFFN3s3|x?byD=W%>oAzBcQQ0U5PX+}-h|-&GM0nyma(TH_#PR{!S~A8 z(-C~1jOF0_W$YOUJ|JT`_yLZc9yv3_T!~VR_8<3eVEN-gzHI{+ZSXn>t~+{|ugzet zKFH7jLGVKo`YZ%LEMqzNpp4y&;74RE2R|xf&qnYe8Oy;QtF zma!cCjDg<8yhs+o&&uE+f{${7d66v$K4vW91RQ)^#%>LTLi-k8%3PtBgxfxz;tM`- zw+F8E;6)0i2bQApk!K;L6B32t5UiGW4{FI~Q@EW7=~g+Yo$)smzUR zNAUAZTL!-%V}}v@ET=7tj3D@&4DJX)P77<9BfSQND?)HP2(MP*S`gd_f;Fp`1xL>_ zqO!<&fc_$*m%$fg>?mTt#5ku##t?i_2FDTnGAEc8*@@sw3?_qLk+J6^_N$zBX5<0{ zUzWjLp-||yBOhR{(2vAmL9dw6w+#BWVH>3q297{KGqM}dUuX0(_zf9*A!1))oYNy0 zA^1%hycof6af0cQOA!1vgUR4`Wb7Ld`&~{uKk`NdzbAuxc*t@0kzLFd`nEqX=!XXV z$e=AYS7ON`nf^B5W@OCW15c&8t^}00xJAN8IOyEDDor5J12t6gedZ38NPzU zKjAcUP-!FlQ-)RHpUHS!GDMM|BYhR>W(0pBg4Zy2w;%NybBAvC{}}WugMMw$Zwz|X zpx+wwJA;02&>sYMzXYZ#TucP${{aCN{FR8s9YqxRHE^y#b&lX~MDRKezKR4ZP@NpmH&wO!vN}9llGeQCX=o+>CGlxZ_-;#y1}Fy1%KBtu2QrhfWMY$ zsPJAH|8|al6Nl%aJwf<7Q?yVb{AL;dPL98x;G z@GUYPH$S1RMtn8eCIoL|am+*Ggz)X0H5GoVjK{@LXoh9H2;V8=-_PvbvFNAF9!8#T zGwE)V?lI|JlkPL=?Iyj`q<5KgzhLh!34=?eDDpOmON8&1@wj9PZMKXT;d>FTM1zLt z`;bHh-!6i}Mnoz`lnBzIj^hv?qgAyM1Vxi5J z@FM(C8IOCi&}z#t?#e>5Ez^kb!!jOsXHn$iGG2r~!Qp9WcM<;xr%~Zg%J8QJe@FkF z`NK@Yr%n2dNuM?8QIj4s>2Z^uFzHE?o)Y|hO5(zOTxh)|JnrN|^DV=;mkaH;Oe4aN z%6Qz4$>9S0t`4GW<6sJnlL}125x6_}d&m z2mKSoe~05$_`5P5ccGz?m+>O}eHo9t(a?CyFz!dA$PZi(~&Fg5T!gA4LKY{F8{q z>@Y=M6S3c6uI{P0gSo;i-(O7nt4V(|=^rNj)1-fy^ly{)gz3^Sx3Yf*G#Y(ODx-A= zxDNkS#$)mr?YoQ@;eW{Z?{oY=W%vgi{+CQ6!vB`xA9DPju)r_Emm*vp`H@g&#fi)w zW*{#Q(-mR5GE7&6>FO|D6Q*m!v^Pv|66{?T=B~w$7}Mnf`o|o+Ld1&Tl_K^h9D9`r z{*;4Piv%Kgjfnjj$6hO9MQ|@-(Fp#Wqu+#R5r)|AUUo0@g=x_@hw1t-y(LUHgz3gG z?F-XQVY)d?w+OzjlkmS__%};<5x!o=|B~b1BE$c~;TvQc5x!Bz|BB=H$#@aIDa<{p zUvu=$VQz~>@D{|P{rwF~?QP3im^;ka-WI0Y!}QiL-4Uic!*o}e-WI02!*q|}?pA;! zN55fIw}DzEI+6(94q__!R_0+YI+cjNgLzQlJDFNp zGJKCr@<(Rwj^#gK<}jChUzpw=rgwztond-cnC=hLyTkOJFg+-kyH~>eiE-TrTp@Hk z5qx`iak&bdqfHmd{CzN3v>3nW4}Lp zS_o6z^wBUq6sC`b>ESSaJWQVm(<5Q}WSAZe(_>+JJWNl7>B%rX6{e>JuOAV(|H8OG zDsYS7LlXC2Ir?KFg$O<@Qi$NkWs1LXicg3XBKU|%A%dSoicsY5oZwNBKm;FSxCQ7s zBl>X}{wIf@V3{vKHyYt5W&FQ5{FICr;itokdDwRbHrsx)`kQl3Bp?dzx;o|+_%VhlF7hNx(pPMH9BUaoX{ad9! zZK}jS?Gp9;qiN!OX_I^|{h)j5n?=dgf?{ z8mnT$dK(mLKAgaMtg?#r`dDRoT6)q`#*VYh9Y8|Dl^UNu-grXz96&<4s}kq1bgSgD zC`-3WQRq~M5laFA4+OWv2!5*-wstlQg=cLsb^Bxveeb0I!isRX!PWcH&s-; zYf6XB<--ZiYZTUQ>+(s3)Vrp1Ak704IBONo4fZQr6+yW5a0gPIe+`EN=!47NpwO!h&p6$Sn&6?g?6G- zp*l=RBo^>Z8h&uw$jE3=c#&AZH!JwlR5u5gXl&1H8@e!CHMS$upY=Jn*};%Iv^ckU zU&Ciude{xbJ9JojEsCbjMP2Wgd}*sDz#Nu>1! zy_=-~P)KjJvRCVNmMykxYkW@acJQxJ+hIi|yGCKRxE5De@{KqX<=O%iP1;>2l(RiFw^wLAo8?UQPP*p*fZ^Od5A+`s@|}J3f!kC+-JKa$mL^Y zuzdL85Y*ZfwH}qy5?Ro8ARkWX<|`-dW!+f&*QQ3+DLQB7r_W{SqzProV$?z)^3!ff zPu~=QRb|<*5I0A3C~AF~;}$~}xS(-{nuJ;}XbcTk;i7;o*%I$wyW>(Y z2awRf`9cN9cUE-{%jH2Gl z)EyTl1}&8ZfFf6Y3a@Ns+_e+13>FZu?0}A8m&UY5s zl7MB<16*k0wAT5o3GCD7?enaOtQw=}mTP~mUsN@)9aM~e1{H2S4d0j9QZpi)oB0PHX#`@=f>dP;?JKd~tl zK!`#4h|2w`dSSy}9D)wY-CzZyJG3$B6qaxU&i>}Zv2-`ABbM%YG>Rjc##y@OY4g&_ zCuCj@Ai?&imT!lC#{!OfcDxub^5qDZI!FmXrgogDJ!sjAcCB`6SEu(%iR+EapoMC1<_zD5V^* z2cyX3WPF*Sh1{NFA!rMhgAhWvTnpi}+^U{K$lmugI;`0pIx+{jze1DPkV~Xx7IZ*U z2+7jEvg;0(Hg+gorM|~xX3tud-ymKKGg}J7A0901{%kT8rgO z$HJ#W_yK1_JP}ku9M@<%n;gk34Fnt^y8^Qk?&>{}m2hqDLs(YAwOR?z1!1X&{aFys zsba6Cik^I?g7&iW;aE=i_O@IsjGmo05$&j;eP-D5<|}t|1&np2%s4Itbl~9obFb6X z&d8@`DJJ06@?P+)n+G?(g>{3?d*Z`nd?C!bd9&6{!DbGr9&d~A&0( zz3q!1f?>(wyJxAVzJl3Zhm?J0WE^Dtv4{(SZ_p&qDokvt%X^BU2sw>`6?V&pU92!{ zwZze=;xlem*o|6YF1ur-%DkruiV)8!ZJ(vIO|H50>DLsYfeZ>U;`4H;xlPvQ7e{U9 zZFi2Q#ub<^HojTo@3oR>*#_<6767tRcAxrJRth%1-m1Q*XQkYtmC|JaNnHf&JUO96 z=jm2U1)bJgxdw`4Em~YoaHri5IV)wrO*NcD# zWx>DU^h;Ur*mA6o5n#c;RSVv}D@uw!;JDbvY0m!du!P@bd(Ywzs8A=A5YC-iIHy^6 zIXmkp@7|STBHSHX+#G$ECb1!xNXyWtcjbXzL$dTo&z#EAw;kNT(tn$les_+Z6ux)w z%7a)=_IF#dU!TLuqWA7ydEf+)5DU(SkhXuS-c9W=eD5pN9eCYf#huspYV#@nT$v z;vJejJ)1n5-ICq4qiTBw2ju&-^^OWaO|05M1*)sV*yDkjG7 zKI?NVZhXjazd8wo#r-Z#(pF~epg#MQ98`0LY=;)P!Z{)`SC(}gK2Nv47GV?~(&U zvl8%?k3O7+mGA*grdN~6j?2BiV?jGw1%N^xIN(O|-=|kCJTwq+zn(u9LGnYE3asT7 zsRQro)gd!YLIClK2#({Cd9b#=DkTK$MredKEnJ?xg0+ATt@N=#tc3?Pp$!&DP7MKv z*oBZnC^$Sw6$G_<;-Q9s1;H1IAox*B3;HvS2^9oIKo*3#kPXf`QUyW1npi<_0EvQd z)4*(20X}qlm``KEsYtAXk7+W!8X~8Gpi{MS8#zj;DnUXXIFX6@FOOO)OROoYp7ZX$ zIBZidrr2Qx`j2bA`*acy1qUo={#XP_oD!v~I_uM+36(QVLh85-y`{Z_H?d0a;h{d9 zidBLms8sRO5ECnYPAI|pCpF3q)=NuUK3!~ARpjXzM`KAn%k?e0qJq|>Ep45zYh!+#nqzyzch6CMXVegi2 zER_V_e!#l2mq`fxmUDj00)IMpupA5gX|3Pfs-L~k`Sf=kro(*p6qMNMAn-Yz7qN#` zq;XeCiT55>cT(vUyf(T#r2+`VKg=r5EpPt+!Zrdrotn zQ7PP&6m+QJi$vt+c}vrJ5mM?o;7~&mkXoLPQgY{r_(T-n`M+SuBM(_2IM`6?e!T)v znh)5Sb^r;sU(g79^}Add57@&h02GM7q_t~X_;e`Pduq;6%5n>Pc4)D}_oC*#B$`X* zq32b>TH<1OL|NH;-Y2=Nd^vXlC9CGkmI2t-MWqb{ESEXr(hPWU7e`V`h4~C2{Qm{rW?ZkVn&X=SB=1k(ySZOM!<#VO1#k>0T zB_N@NE`K=wE!HJYpZP9d$wJ>3U54*y!q_hET%x!290IQ8dSehm{H`_|mz8R}()WL* z+Kxpmv3^hIuB4)H5!b_d+Jjk7P<$fm-?!|?WyxAvkauZyD7cWU0FTT@_4@ev-(?Ns za3Ot?FqhUJXc?SQ2&;@M;MNK+c#*{)YBFcLB+FGw0l#AO!y(B1NE=gbzTK|l3pIL!Fv5Y6Tv@UHX;Go1JEuc7e zI0jl)H{I4dWeNfNK6zk5B|p zGf;rue$hWz{y3LQA9>C4|Ao$1Nx2Q!!y3H5U-ja`9g)cNFD=d6*Y>6E19m5E9LtJg z26BW$x~2MiZLgI91RO;a01AeGr4etkzt0(gcQffFom?vI5XiEK8$Em%LZ8==oqr$at&u)NlSQ`A|n zSPfM3?+)YvOP~v=IMk%%;&B!|j;j;rzT@vTwrvwZBT@@Af40!XqUF3b z8fdEE`D~4L;fNswy1y8U7cW{QveupvREi*Ts5}QDv=UcP#JW`~d2I7Er0oHM>OK3}mbNas14<&o&tcqI@_m_5ZZ0D%)Fmn3s1|<%LziiOl}X4Q;U+&{}Nu?v~z5HWIOQ9yX=sojZhpII>vT#lFY#Nq2ZIoo5V3NC`UYBS`{)@T^{O~ zZXonnDEhk6srREBn34tu8WpJzL1h}=d z9_~uo0=FG|n&F*_y;AV{ur3SlJWLP6!&ewM*xJPQS=8O|v9IbH6FzSFxr==)<37kf z)>WQnA9ItygwQuB7qSQWw(KQMYh=;MP;GaJlq1&?e!Y z2KP8RUASk!J)X`K?pbh8pv}TP8}5me5pEyclc-;~18`5KEZjz1(B|>G|Ej-8u4G|q zqOC~ZOqalIp*O%?g%8Ext;QEk!n=&UHFUZ3u3)bf-`@!DD)!dW)zZ6$y;Ja6i17BZ z*M@u2gm)c#>+o5E@UCaCo$pQa_`UDy_em~QVei2Hcz|?Zk376i?2{MX&FrnmHf`bE z%3c?)KNH^V>~&)&vGDF-uLl>C3GXiUda=({cz3h60T-1C?_Tyc(tZD5d)ERcS5c*J z_s#{$11HtfndzPoLnH~{ou0n8`}Sj2{KCt1Q9dT_2_e8j z2+xoJ2Et2ljYQZXx`K<3Pd4kqiYutd!w8S($z&!(Sni$gtN+%0 zRdwCDRp&qFR2_lM1fQ}IxU9i;-$m0-h@yuu{n4l4T!`GK;a~{(jJ-wRHiDDk+QxvG zE8(WkBK#P`odOS2$8!oCuNdwo_#C2xF?@yK^Kb`ZKs1wZ)88Xn7z1LJgqsTRQ(@Rf zP^9Q#jkc{9zb0*~yUr5)DR55-J{5p6f_^bPNKk==AJBsUV1W4u0>-d|U;zx&fQ2wp z1HND*?gqiP2~LGA6|e|_x&WskSQi7rV1%0%!=wl3g;@`?H%p5b*~QT_B8EMTl1g zTuVW#1Q8P;jIe>AF~D`iWq^njh(J~iwt>|@l-iqd6Noka!-y0J;U9>3DOi+0jQJLb zLIuRc2rQG&h{f>32os2)RKTk#G8J$Gg{K0-j~`3hGya(nPW>xsoJD}Za|jV7@LWQ8 zoS&!hd_u$xynqnF11}`J36uT84JvO9tXV6yH={jp72UNN6VwQAMz}_emk=Tr;98BB z65fgsjv6l`gm3WW8m}PSf{8gAuOvkLz^gQ_C%heVL^N(7+=?~RHC{`IFoTHb)Lv+(HNk!rL_7PKY3b zTL}?q@D7c462j5#E{%5+!t3oGjR>pMU>mq(iqzgnR>1q{uKN+qkPyCF|E%$AgmB#2 zrt#~92r+oS#_fcNH~0;W4-mq`=s`k6Ap94N1B3`i_>jgOggdYjy~b}5eiP9GH6p4} zgKc2#6Hg(sTvV|8f*iXo-DODvNtSnFVkJX-w?ta_dgncONc;*uMi@d;qNrQN(gJu?=`+g z2-DB&8s8v<9q11l|48^V^ihOAM<1o}O~PLwo}I>(G!#FBK8iTNu-m}8nA9FuF=IeT z!}I7a;Q55lh7b}5_#ApLjTaF<4@RPK6(PbOuGYAQ@K=Z{t8pzMw6vEJzKA|b<7I@u zMjxf|3c{DrM`^s0@MZK-jcOk{_VPnccs~g(xN1FJjd+JwYurGH;D^^}yq55{=)nk~ z7Q3GCcj%)u-bjcrg&PT>EV@bKCXJg3p+UM?<1HF*C43!ymBuX^ZzFsIJWb<$8ox^T z2lOTyzou~;;UD3ltMPt~+X)dV@f#W+B1G849fW^EZ=vy9gm0p^(D>~}tv2-k;JM3> z>OPQ$)E(9#H-Ajs3tNH#p{W^c+q?xU=51KlC+Vtq0Ss>4#f(}Xk9YiuZg&;SJe58nMf-SD2@wde$ z>Jk;PsFk^3jG1Mes4JKvak#h$cI|cog+6`7yzZI!SFsQjh*El;7UBX?O0N*%_&BB4 zMiF`_rB?;VX-?_&Afha%^hzv#Ar=DmpvvHc4j7>WKIniAI$(j0-9icFh#ES?2_2$@ z%mN+zgR}<@<=CK54lyOi22pZ|8#y+pkwa|AvCF9YD7M@G>5=YM{5)T8Kvr$og!yPOmcCdul!SZ1T!k5xXk_|h!x9&iEHQJ}1 z8rO45y)>@plzM1f&nf9X5~K}C5ZO)G;JOJG_!2DcC0N)?AoM65CqXZPh?SI{gL)^p z159xDm*CDX!Cha1JH7;Bg3&e9=_L>uj8f{T5(vdb|Ee=60SoU$Joiy=Pha(B_d#e3 z`A_de=xf?1dAO6M;ZBx?I}yW`j*uLTb4ue1j&n+5N+*vforv~E`!t$#BIX-D zg=SW@G}}k={!yIXjK|@`EdtE;nuYB(3)^c(fN8#j*>UfUNZtt@AhYIU;jY& zRQx=Y!W5@jC{D9boMuEB=5tJOnniqSMtDg+$ih=If;@7LMW<$woSG5vkq@%m)NHfZ z)QmV;I5>qBIa5T~o&s5$k6kRVN?^6X6%9vp%X)SF@!iv@;?n6TR^lj|lsHQ0o&w$D z-1h~T&?zBwO5{z2D4u-Dy#g#wDv>6Y2$KqdHTjZl0xU@?8KRVoPzu4+_!1tMlnhHs zMj<7Gj*>A3&y*{91c|T`En**ynO_Xsepj|i=gV5SeBV_F|UAaKqxJB5$_JUav>}u!=a{y%32SMynY7@Ua*ioWjMU1p?CxK%xgs?4+LO9x zQNxKq6l1$Xj8(}oR@BC9Qq;y+Q5&;KQ5$3BY|JL*Y|JijTI95cQ?gdXSiu?-9cj$I zn0{hRbfhtRwdB?aTq3Ym;8KA{1XzI=xHwKe?NXA-G9|MHo7;KZ#SAIu}4)TSZCXQSW2$FJY`TiG^wQA$3^Jq}9 zSeCA1Kx8tkr8_WwI%LRlXvlMH^ec|Nkdjj=SwzVaO8O~TPRZGnti(GptmWc{|Cpi3 zrZeXesc>xiDGu{Shoxx{6Fx%U21pI3B(yjzSvx%VcW|fH!M#`qQ_2n=78CSAL(0eH z;0c_P>N~;Rd?$VRoop8B#1d7sPa;mIh&IjKUo_i&c+<`H8Jw~`0x~SFf}Bb{!xZ^C zr^xrH$g-&Dzf_U^P;tMe$R3M*>Y|iA3ynU?ZT+Sf=5Z%y-Ya!Kiic*!c230{S+Si{ z@rRTGcaY{p!vQOglQ=F1rQSor4*siFEF5?K<6%`L%itUPu$TN-FJy<<#ZXRD>x;4qY@LN5^JK8K~af~P>B?+M0{2v z<0U1Q&YCFDbc|wv8pMtswpw2DG>vd z*wLzts-8+cCM7aeRALQNBD*RPT9w$plu!#LoI(kwQ0UtmG-+t&tq;vR1bqe?p1XV{ zUA_`oPKgkw#F(YThNW0Jfg64;m3m3wWdSx*DX~&1kw2AqZzwTBDUm;wn4pwcpp+P( z6e}h0Xf`(~p&=3WABnK8E5c%DgvHJXdyz!!vrzj8%K#CvQ%1x<*}^hNi&&6bumTmX zYY}r?3$!c^T4d;9m}4H9M=CS$6q0+QZ1|6|;Xi7Bk&m3o=?*FYbb(;1eK4ojNrt76 zR+f)iMRiw|-k+i?TE)+$jrCKIr!S;~ZK5t{6Fq^5z$}c#n25)ih{s5U1`(8eBx0=C zh}lQ+{?VM0FGS2<%qdgR7^_hrAc@d7Y3T1AK0ol~ z8=c!}GU-U$SGFXr_s}Iftivb$2)NR6e{&+EcjZpT)DcSX*-tR0ZJqp!e= z-So*d{e|M9O2W(TzqGfvKjEe=>#xqc5icY#kUAXJ&(la?JK8M0n zZZcOYO7ULatrjZps%z-GI*8t2m%L9e<&-#f+b2y$<*a#=Bb`kpM?Bl$$x?1AJ>tE& z;m_)O^TVH&I;R_ytIuXeym!PW``$?R`u>P#8~h@vRmL6Z-pq(?mB|jhcM`u}gjMYQ zSnqr|Tz+$FzZJLYzfis=A*JgNTxXKC7pCgZ&~S!b?5T6Ip3?x`E|LvXJ*{m zbD4BqE?b++*3~oX*Z!coN9O7-%+*yoS6AtLUE%q?OmV7b=9kblA&;y=>UahdpGAA#VbG%U(W} zEvIF-;JRt}%!Yn^=Uvux%XF$5eT^B7rqj*oe0e|aggwc6X^p-dPDwVU?@H;rQh9y6 zps}d2q_IaZt?x_gysulrcjdgV&-?nhzJ88hlH#)hMFD+K*SJT1d@)&cb(0iJeqJ|8 zDevdK2_@=s)A@ASmEB@8Sx)h;m&_*9nNU(^a_Mw+w@{K@w6UL0g_8Au`i8ul?vdSe zCSNMcZno^Ei*z~HES2mj<59ZfP3Z!XX*ZiLO4Tzt50&J%nN1a|yCpAKk)t`+&!u_` zeGB`#=v(dU>MwOIFO*JO)I~1bOP4Jo$Mn;%?%2Y`^E(QQ=JzgL*uOvqkdz)kFc6rr zCFS%is$hJnEbVeLrEET(Db3jX+XN}!ub2vy^uS3&q#mep7{qvtbjxO#l2OXdQfpwC z%$RYioK1O^WF}Mn6@FzLbtbjQh1Riu9kT3pYs!9~ThQOXq^q+N1AJl8g5JLVt{na^ zI+qldbWVKg%@1wgcu%`E`OxkoyJz%OmZBMF6#8e3aLbxMe`xy++m!X$LXX$|@xSR^ z{v+NBb*%{dhWRad_yY50c;e2vtB8X*)1<5GL=ycRqA5 zayvo~Tcj0gU5Q@;xh}lY3Z31I6JwO`@SMgG;*G& z<-F8;_@5@>7tBt{?3DE-h24vSe-Y717h3bVk(gMl3T&mUS1YjP>jbt^v0^@ilKv3# zJ@O?`*X89aN%I}l3W=%Z`Wq`WkWEv`+A`f*8L{!Fml^u$74q3aw&K=&dWBUXU2@5k z41u^#EFPigf~$Y5=jk8oo3EZf`eZ7X*3u~zo%7th5s`H-kRI#>N-K0t%BChm1@sYW zf_9bu2V$)V>1k6F5!1bbX?Lzk+N}(hT-L;(+W2Vex+d`JTHmW}{Zh3Fs`9xM>`CLN zvN_!XY1dDsJil6Of%(+iMn*@+)3pCX*8ARG(uNjd{{KiFlgxnVWz&UfCY>vJp=34d zL$;_&GW$?4!JrdtK??*e5VSzh0znG|E%5ee0WBBT@Nc6404J|%0E%uoo6Pm($3dot zzg6@9OqCIpcjf?p zNuz*+^{9@Yj!>8Chw1hVq3FU-YbZKX@-#m4y1FFGUX`+DlGVBxBN`q%>bf*0>A9gK zo$HdxX6oxw*J-#~Uyw1DwO!N&J+(TMR4r?7{DyK`XOc~7+AeRTt`&?S@!hU3cyH5+ zKwki*-X2>iCb@c4^s+gzX?V%q8!T{_{BzKqj>VSs$U<+CxXn~*w zf))r`;2qxr!vAaex8eUdR^|UCH`|je=KWEz<~_N{@c&)tM~(e|EHtC~Ba(Ykn<3W@ zrT=q<{?8qr{?DcVg{ZZCkp9ml1pyB3F!Ue$3qH9Q=s&!7ZrM3`pV9wU?36XRA^ji5 z3UAEuMl;~|1a^6Ldo}mgM**>M*O#vp}y)fu&*rj z4O^vbdl~`2YBD#{U*p8DQ$YHGePo{?ioxSJb}q{XfxuWEkIn zP5#pwGa9oRa~ku(Jp8JeJ#~(@_ovMq^gS^5=ZDVx&*&-WVr|2uUhPtzN#--viSRTn z+{J=Q=95mJtE-UNtA=GU(50$w?U`iR&l&G})WPdX4f4;7sYBM(VGm{;R8@i183$%6 zzSy?CyqO7foT-9Yb);%v$I4i=FAH|nx%U^Uufj}v(67QXufi+_ zF!Yz_bg6k$>K;sQsPb;C4Uk25dL4ozYSL?46^@9t|wVa<@f&V{~0rk{lChI%nD&O z3V=b`cj!uBd9xCjk@{sqZMrS$3!$Cl>XCUbu0deN`d|%$w@elc9vrkl&;mgV1TFCHX#p){ z*6?qm06>6{s{cQh{&UN@e0ErtJf4Gw|NGh|hQ+=`$gSc3Rioc7>u=|^8y})NNSqpx zqci0}l9d_Hnguce;P-VC01gl)Ki9HOo;v;s05MDe7}$ps0M<60Kf(lnQ89T#>5c6_ zp!9?PZNb`ph)^{QnGM$VL$t1px5l_%?6TZx)$yP%8bDnvhCwyx9&q})`#DS!7!zrimJS|DhF fpatH&Eui^-4gaq4e}9nwBR*oeoPP^E04Dq&;GxU{ literal 0 HcmV?d00001 diff --git a/ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/action/FindAction.java b/ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/action/FindAction.java new file mode 100644 index 000000000..2c06f646c --- /dev/null +++ b/ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/action/FindAction.java @@ -0,0 +1,377 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.openecomp.policy.xacml.action; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.URL; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.logging.Logger; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import javax.json.Json; +import javax.json.JsonReader; + +import org.apache.http.HttpResponse; +import org.apache.http.client.ClientProtocolException; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.client.methods.HttpPut; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.DefaultHttpClient; +import org.openecomp.policy.rest.XACMLRestProperties; + +import com.att.research.xacml.api.Advice; +import com.att.research.xacml.api.Attribute; +import com.att.research.xacml.api.AttributeAssignment; +import com.att.research.xacml.api.AttributeValue; +import com.att.research.xacml.api.Identifier; +import com.att.research.xacml.api.Obligation; +import com.att.research.xacml.api.Request; +import com.att.research.xacml.api.RequestAttributes; +import com.att.research.xacml.api.Result; +import com.att.research.xacml.std.IdentifierImpl; +import com.att.research.xacml.std.StdAdvice; +import com.att.research.xacml.std.StdAttributeAssignment; +import com.att.research.xacml.std.StdAttributeValue; +import com.att.research.xacml.std.StdMutableResponse; +import com.att.research.xacml.std.StdMutableResult; +import com.att.research.xacml.std.StdObligation; +import com.att.research.xacml.util.XACMLProperties; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; + +public class FindAction { + private Logger logger = (Logger) FlexLogger.getLogger(this.getClass()); + private Boolean changeIt = false; + private String configURL = null; + private StdMutableResponse newResponse = new StdMutableResponse(); + private StdMutableResult addResult = new StdMutableResult(); + + public StdMutableResponse run(StdMutableResponse stdResponse, Request pepRequest) { + int count = 0; + boolean config = false; + boolean decide = false; + Collection requestAttributes = pepRequest.getRequestAttributes(); + for(RequestAttributes requestAttribute : requestAttributes){ + Collection attributes = requestAttribute.getAttributes(); + for(Attribute attribute : attributes){ + if(attribute.getAttributeId().stringValue().equals("urn:oasis:names:tc:xacml:1.0:action:action-id")){ + for(AttributeValue attributeValue : attribute.getValues()){ + if(attributeValue.getValue().toString().equalsIgnoreCase("ACCESS")){ + count++; + } + if(attributeValue.getValue().toString().equalsIgnoreCase("DECIDE")){ + decide = true; + } + } + } + if(attribute.getAttributeId().stringValue().equals("urn:oasis:names:tc:xacml:1.0:resource:resource-id")){ + for(AttributeValue attributeValue : attribute.getValues()){ + if(attributeValue.getValue().toString().equalsIgnoreCase("Config")){ + count++; + } + } + } + } + } + if(count==2){ + config = true; + } + if(!config){ + search(stdResponse); + } + addResults(stdResponse, config , decide); + logger.info("Original Result is " + stdResponse.toString()); + logger.info("Generated Result is " + addResult.toString()); + return newResponse; + } + + private Collection obligations = new ArrayList(); + private Map matchValues = new HashMap(); + private Map headers = new HashMap(); + private boolean header = false; + + private void search(StdMutableResponse stdResponse) { + for (Result result : stdResponse.getResults()) { + if (!result.getObligations().isEmpty()) { + System.out.println("Obligation Received"); + // Is there any action that PDP needs to take + for (Obligation obligation : result.getObligations()) { + int count = 0, uri = 0, PEP = 0; + header = false; + changeIt = false; + Collection afterRemoveAssignments = new ArrayList(); + Identifier oblId = new IdentifierImpl(obligation.getId().stringValue()); + StdAttributeAssignment attributeURI = null; + for (AttributeAssignment attribute : obligation.getAttributeAssignments()) { + matchValues.put(attribute.getAttributeId().stringValue(), attribute.getAttributeValue().getValue().toString()); + if (attribute.getAttributeId().stringValue().equalsIgnoreCase("performer")) { + if (attribute.getAttributeValue().getValue().toString().equalsIgnoreCase("PEPACTION")) { + PEP++; + } else if (attribute.getAttributeValue().getValue().toString().equalsIgnoreCase("PDPACTION")) { + count++; + } + } else if (attribute.getAttributeId().stringValue().equalsIgnoreCase("URL")) { + uri++; + if (uri == 1) { + configURL = attribute.getAttributeValue().getValue().toString(); + attributeURI = new StdAttributeAssignment(attribute); + } + } else if (attribute.getAttributeId().stringValue().startsWith("headers")) { + logger.info("Headers are : "+ attribute.getAttributeValue().getValue().toString()); + header = true; + headers.put(attribute.getAttributeId().stringValue().replaceFirst("(headers).", ""), + attribute.getAttributeValue().getValue().toString()); + afterRemoveAssignments.add(attribute); + } else if (attribute.getAttributeId().stringValue().equalsIgnoreCase("body")) { + String papPath = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_URL); + papPath= papPath.replace("/pap", ""); + matchValues.put("body",attribute.getAttributeValue().getValue().toString().replace("$URL", papPath)); + } /* + * else if (attribute.getAttributeId().stringValue(). + * equalsIgnoreCase("type")){ requestAction.put("Type", + * attribute.getAttributeValue().getValue().toString()); + * afterRemoveAssignments.add(attribute); } else + * if(attribute + * .getAttributeId().stringValue().equalsIgnoreCase + * ("method")) { requestAction.put("Method", + * attribute.getAttributeValue().getValue().toString()); + * afterRemoveAssignments.add(attribute); } else + * if(attribute + * .getAttributeId().stringValue().equalsIgnoreCase + * ("body")) { requestAction.put("Body", + * attribute.getAttributeValue().getValue().toString()); + * afterRemoveAssignments.add(attribute); } + */else { + StdAttributeAssignment attributeObligation = new StdAttributeAssignment(attribute); + afterRemoveAssignments.add(attributeObligation); + } + } + if (count == 1 && uri == 1 && PEP == 0) { + // Remove Obligation and add Advice + changeIt = true; + TakeAction(stdResponse, oblId, afterRemoveAssignments); + } else if (PEP == 1 && count == 0) { + // Strip the PEPACTION if available + if (uri == 1) { + afterRemoveAssignments.add(attributeURI); + } + Obligation afterRemoveObligation = new StdObligation( + oblId, afterRemoveAssignments); + obligations.add(afterRemoveObligation); + } else { + obligations.add(obligation); + } + } + } + } + } + + private void TakeAction(StdMutableResponse stdResponse, Identifier advId, + Collection afterRemoveAssignments) { + if (changeIt) { + logger.info("the URL is :" + configURL); + // Calling Rest URL.. + callRest(); + // Including the Results in an Advice + Identifier id = new IdentifierImpl( + "com:att:labs:ecomp:policy:pdp:reply"); + Identifier statId = new IdentifierImpl( + "com:att:labs:ecomp:policy:pdp:reply:status"); + Identifier statCategory = new IdentifierImpl( + "urn:oasis:names:tc:xacml:1.0:subject-category:recipient-subject"); + Identifier strId = new IdentifierImpl( + "http://www.w3.org/2001/XMLSchema#string"); + Identifier resId = new IdentifierImpl( + "com:att:labs:ecomp:policy:pdp:reply:resource"); + Identifier resCategory = new IdentifierImpl( + "urn:oasis:names:tc:xacml:3.0:attribute-category:resource"); + Identifier urlId = new IdentifierImpl( + "http://www.w3.org/2001/XMLSchema#anyURI"); + // Collection attributes = new + // ArrayList(); + AttributeValue attributeStatusValue = new StdAttributeValue( + strId, status + response); + AttributeValue attributeResourceValue = new StdAttributeValue( + urlId, configURL); + StdAttributeAssignment attributeStatus = new StdAttributeAssignment( + statCategory, statId, "PDP", attributeStatusValue); + StdAttributeAssignment attributeResouce = new StdAttributeAssignment( + resCategory, resId, "PDP", attributeResourceValue); + afterRemoveAssignments.add(attributeStatus); + afterRemoveAssignments.add(attributeResouce); + Advice advice = new StdAdvice(id, afterRemoveAssignments); + addResult.addAdvice(advice); + } + } + + private void addResults(StdMutableResponse stdResponse, boolean config, boolean decide) { + if(decide){ + newResponse = stdResponse; + return; + } + for (Result result : stdResponse.getResults()) { + if(config){ + addResult.addAdvice(result.getAssociatedAdvice()); + } + addResult.addAttributeCategories(result.getAttributes()); + addResult.addPolicyIdentifiers(result.getPolicyIdentifiers()); + addResult.addPolicySetIdentifiers(result.getPolicySetIdentifiers()); + addResult.setStatus(result.getStatus()); + addResult.setDecision(result.getDecision()); + if(!config){ + addResult.addObligations(obligations); + } + } + newResponse.add(addResult); + } + + private int status; + private String response; + + private void callRest() { + // Finding the Macros in the URL.. + Pattern pattern = Pattern.compile("\\$([a-zA-Z0-9.:]*)"); + Matcher match = pattern.matcher(configURL); + StringBuffer sb = new StringBuffer(); + while (match.find()) { + logger.info("Found Macro : " + match.group(1)); + String replaceValue = matchValues.get(match.group(1)); + logger.info("Replacing with :" + replaceValue); + match.appendReplacement(sb, replaceValue); + } + match.appendTail(sb); + logger.info("URL is : " + sb.toString()); + configURL = sb.toString(); + // Calling the Requested service. + if (matchValues.get("method").equalsIgnoreCase("GET")) { + DefaultHttpClient httpClient = new DefaultHttpClient(); + try { + HttpGet getRequest = new HttpGet(configURL); + // Adding Headers here + if (header) { + for (String key : headers.keySet()) { + getRequest.addHeader(key, headers.get(key)); + } + } + HttpResponse result = httpClient.execute(getRequest); + status = result.getStatusLine().getStatusCode(); + BufferedReader br = new BufferedReader(new InputStreamReader( + (result.getEntity().getContent()))); + String output = " "; + String out; + while ((out = br.readLine()) != null) { + output = output + out; + } + response = output; + } catch (ClientProtocolException e) { + response = e.getMessage(); + } catch (IOException e) { + response = e.getMessage(); + } finally { + httpClient.getConnectionManager().shutdown(); + } + } else if(matchValues.get("method").equalsIgnoreCase("POST")) { + DefaultHttpClient httpClient = new DefaultHttpClient(); + try { + HttpPost postRequest = new HttpPost(configURL); + // Adding Headers here + if (header) { + for (String key : headers.keySet()) { + postRequest.addHeader(key, headers.get(key)); + } + } + // Adding the Body. + URL configURL = new URL(matchValues.get("body")); + URLConnection connection = null; + connection = configURL.openConnection(); + // InputStream in = connection.getInputStrem(); + // logger.info("The Body Content is : " + IOUtils.toString(in)); + JsonReader jsonReader = Json.createReader(connection.getInputStream()); + StringEntity input = new StringEntity(jsonReader.readObject().toString()); + input.setContentType("application/json"); + postRequest.setEntity(input); + // Executing the Request. + HttpResponse result = httpClient.execute(postRequest); + logger.info("Result Headers are : " + result.getAllHeaders()); + status = result.getStatusLine().getStatusCode(); + BufferedReader br = new BufferedReader(new InputStreamReader( + (result.getEntity().getContent()))); + String output = " "; + String out; + while ((out = br.readLine()) != null) { + output = output + out; + } + response = output; + } catch (ClientProtocolException e) { + response = e.getMessage(); + } catch (IOException e) { + response = e.getMessage(); + } finally { + httpClient.getConnectionManager().shutdown(); + } + } else if(matchValues.get("method").equalsIgnoreCase("PUT")) { + DefaultHttpClient httpClient = new DefaultHttpClient(); + try { + HttpPut putRequest = new HttpPut(configURL); + // Adding Headers here + if (header) { + for (String key : headers.keySet()) { + putRequest.addHeader(key, headers.get(key)); + } + } + // Adding the Body. + URL configURL = new URL(matchValues.get("body")); + URLConnection connection = null; + connection = configURL.openConnection(); + //InputStream in = connection.getInputStream(); + //logger.info("The Body Content is : " + IOUtils.toString(in)); + JsonReader jsonReader = Json.createReader(connection.getInputStream()); + StringEntity input = new StringEntity(jsonReader.readObject().toString()); + input.setContentType("application/json"); + putRequest.setEntity(input); + // Executing the Request. + HttpResponse result = httpClient.execute(putRequest); + status = result.getStatusLine().getStatusCode(); + BufferedReader br = new BufferedReader(new InputStreamReader( + (result.getEntity().getContent()))); + String output = " "; + String out; + while ((out = br.readLine()) != null) { + output = output + out; + } + response = output; + } catch (ClientProtocolException e) { + response = e.getMessage(); + } catch (IOException e) { + response = e.getMessage(); + } finally { + httpClient.getConnectionManager().shutdown(); + } + } + } +} diff --git a/ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/action/package-info.java b/ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/action/package-info.java new file mode 100644 index 000000000..88ecc78c2 --- /dev/null +++ b/ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/action/package-info.java @@ -0,0 +1,30 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.xacml.action; + +/** + * org.openecomp.policy.xacml.action contains the implementation of the PDP Actions. + * Changes: + * Now PDP supports actions based on PUT, GET, POST methods + * + * @version 0.2 + * + */ diff --git a/ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/custom/EcompFunctionDefinitionFactory.java b/ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/custom/EcompFunctionDefinitionFactory.java new file mode 100644 index 000000000..d6d664ab6 --- /dev/null +++ b/ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/custom/EcompFunctionDefinitionFactory.java @@ -0,0 +1,85 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.openecomp.policy.xacml.custom; + +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.util.HashMap; +import java.util.Map; + +import org.openecomp.policy.xacml.pdp.std.functions.FunctionDefinitionCustomRegexpMatch; + +import com.att.research.xacml.api.Identifier; +import com.att.research.xacml.std.IdentifierImpl; +import com.att.research.xacml.std.datatypes.DataTypes; +import com.att.research.xacmlatt.pdp.policy.FunctionDefinition; +import com.att.research.xacmlatt.pdp.policy.FunctionDefinitionFactory; +import com.att.research.xacmlatt.pdp.std.StdFunctions; + +public class EcompFunctionDefinitionFactory extends FunctionDefinitionFactory { + private static Map mapFunctionDefinitions = new HashMap(); + private static boolean needMapInit = true; + + public static final Identifier ID_FUNCTION_CUSTOM_REGEXP_MATCH = new IdentifierImpl("org.openecomp.function.regex-match"); + + private static final FunctionDefinition FD_CUSTOM_REGEXP_MATCH = new FunctionDefinitionCustomRegexpMatch(ID_FUNCTION_CUSTOM_REGEXP_MATCH, DataTypes.DT_STRING); + + private static void register(FunctionDefinition functionDefinition) { + mapFunctionDefinitions.put(functionDefinition.getId(), functionDefinition); + } + + private static void initMap() { + if (needMapInit) { + synchronized(mapFunctionDefinitions) { + if (needMapInit) { + needMapInit = false; + Field[] declaredFields = StdFunctions.class.getDeclaredFields(); + for (Field field : declaredFields) { + if (Modifier.isStatic(field.getModifiers()) && + field.getName().startsWith(StdFunctions.FD_PREFIX) && + FunctionDefinition.class.isAssignableFrom(field.getType()) && + Modifier.isPublic(field.getModifiers()) + ) { + try { + register((FunctionDefinition)(field.get(null))); + } catch (IllegalAccessException ex) { + + } + } + } + // + // Our custom function + // + //register(FunctionDefinitionCustomRegexpMatch); + register(FD_CUSTOM_REGEXP_MATCH); + } + } + } + } + + public EcompFunctionDefinitionFactory() { + initMap(); + } + + @Override + public FunctionDefinition getFunctionDefinition(Identifier functionId) { + return mapFunctionDefinitions.get(functionId); + } +} diff --git a/ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/pdp/ECOMPPDPEngine.java b/ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/pdp/ECOMPPDPEngine.java new file mode 100644 index 000000000..d1d6ebc90 --- /dev/null +++ b/ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/pdp/ECOMPPDPEngine.java @@ -0,0 +1,64 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.openecomp.policy.xacml.pdp; + +import java.util.Properties; + +import org.openecomp.policy.xacml.action.FindAction; + +import com.att.research.xacml.api.Decision; +import com.att.research.xacml.api.Request; +import com.att.research.xacml.api.Response; +import com.att.research.xacml.api.pdp.PDPException; +import com.att.research.xacml.api.pdp.ScopeResolver; +import com.att.research.xacml.std.StdMutableResponse; +import com.att.research.xacmlatt.pdp.ATTPDPEngine; +import com.att.research.xacmlatt.pdp.eval.EvaluationContextFactory; + +public class ECOMPPDPEngine extends ATTPDPEngine { + + public ECOMPPDPEngine(EvaluationContextFactory evaluationContextFactoryIn, Decision defaultDecisionIn, + ScopeResolver scopeResolverIn, Properties properties) { + super(evaluationContextFactoryIn, defaultDecisionIn, scopeResolverIn, properties); + // TODO Auto-generated constructor stub + } + + public ECOMPPDPEngine(EvaluationContextFactory evaluationContextFactoryIn, Decision defaultDecisionIn, + ScopeResolver scopeResolverIn) { + super(evaluationContextFactoryIn, defaultDecisionIn, scopeResolverIn); + // TODO Auto-generated constructor stub + } + + public ECOMPPDPEngine(EvaluationContextFactory evaluationContextFactoryIn, ScopeResolver scopeResolverIn) { + super(evaluationContextFactoryIn, scopeResolverIn); + // TODO Auto-generated constructor stub + } + + @Override + public Response decide(Request pepRequest) throws PDPException { + // TODO Auto-generated method stub + Response response = super.decide(pepRequest); + + FindAction findAction = new FindAction(); + return findAction.run((StdMutableResponse) response, pepRequest); + } + + +} diff --git a/ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/pdp/ECOMPPDPEngineFactory.java b/ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/pdp/ECOMPPDPEngineFactory.java new file mode 100644 index 000000000..437eb69b5 --- /dev/null +++ b/ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/pdp/ECOMPPDPEngineFactory.java @@ -0,0 +1,54 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.openecomp.policy.xacml.pdp; + +import java.util.Properties; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; +import com.att.research.xacml.api.pdp.PDPEngine; +import com.att.research.xacml.api.pdp.PDPEngineFactory; +import com.att.research.xacml.util.FactoryException; +import com.att.research.xacmlatt.pdp.eval.EvaluationContextFactory; + +public class ECOMPPDPEngineFactory extends PDPEngineFactory { + private Logger logger = FlexLogger.getLogger(this.getClass()); + + @Override + public PDPEngine newEngine() throws FactoryException { + EvaluationContextFactory evaluationContextFactory = EvaluationContextFactory.newInstance(); + if (evaluationContextFactory == null) { + this.logger.error("Null EvaluationContextFactory"); + throw new FactoryException("Null EvaluationContextFactory"); + } + return new ECOMPPDPEngine(evaluationContextFactory, this.getDefaultBehavior(), this.getScopeResolver()); + } + + @Override + public PDPEngine newEngine(Properties properties) throws FactoryException { + EvaluationContextFactory evaluationContextFactory = EvaluationContextFactory.newInstance(properties); + if (evaluationContextFactory == null) { + this.logger.error("Null EvaluationContextFactory"); + throw new FactoryException("Null EvaluationContextFactory"); + } + return new ECOMPPDPEngine(evaluationContextFactory, this.getDefaultBehavior(), this.getScopeResolver(), properties); + } + +} diff --git a/ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/pdp/std/functions/FunctionDefinitionCustomRegexpMatch.java b/ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/pdp/std/functions/FunctionDefinitionCustomRegexpMatch.java new file mode 100644 index 000000000..9e63052a4 --- /dev/null +++ b/ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/pdp/std/functions/FunctionDefinitionCustomRegexpMatch.java @@ -0,0 +1,123 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.openecomp.policy.xacml.pdp.std.functions; + + +import java.util.List; + +import com.att.research.xacml.api.DataType; +import com.att.research.xacml.api.DataTypeException; +import com.att.research.xacml.api.Identifier; +import com.att.research.xacml.std.StdStatus; +import com.att.research.xacml.std.StdStatusCode; +import com.att.research.xacml.std.datatypes.DataTypes; +import com.att.research.xacmlatt.pdp.eval.EvaluationContext; +import com.att.research.xacmlatt.pdp.policy.ExpressionResult; +import com.att.research.xacmlatt.pdp.policy.FunctionArgument; +import com.att.research.xacmlatt.pdp.std.functions.ConvertedArgument; +import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionBase; + +/** + * FunctionDefinitionCustomRegexMatch implements {@link com.att.research.xacmlatt.pdp.policy.FunctionDefinition} to + * implement the custom 'type'-regex-match predicates as functions taking two arguments, the first of String, + * and the second of the type for that specific predicate as a regular expression, + * and returning a Boolean for whether the regular expression matches the string representation of the first argument. + * + * + * @version $Revision: 0.1 $ + * + * @param the java class for the data type of the function Input arguments + */ +public class FunctionDefinitionCustomRegexpMatch extends FunctionDefinitionBase { + + + /** + * Constructor - need dataTypeArgs input because of java Generic type-erasure during compilation. + * + * @param idIn + * @param dataTypeArgsIn + */ + public FunctionDefinitionCustomRegexpMatch(Identifier idIn, DataType dataTypeArgsIn) { + super(idIn, DataTypes.DT_BOOLEAN, dataTypeArgsIn, false); + } + + + @Override + public ExpressionResult evaluate(EvaluationContext evaluationContext, List arguments) { + + if (arguments == null || arguments.size() != 2) { + return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Expected 2 arguments, got " + + ((arguments == null) ? "null" : arguments.size()) )); + } + + // get the regular expression + FunctionArgument regexpArgument = arguments.get(0); + + ConvertedArgument convertedArgument = new ConvertedArgument(regexpArgument, DataTypes.DT_STRING, false); + if ( ! convertedArgument.isOk()) { + return ExpressionResult.newError(getFunctionStatus(convertedArgument.getStatus())); + } + + // String regexpValue = (String)regexpArgument.getValue().getValue(); + String regexpValue = convertedArgument.getValue(); + + + // now get the element to match + FunctionArgument elementArgument = arguments.get(1); + + ConvertedArgument convertedElement = new ConvertedArgument(elementArgument, this.getDataTypeArgs(), false); + if ( ! convertedElement.isOk()) { + return ExpressionResult.newError(getFunctionStatus(convertedElement.getStatus())); + } + + I elementValueObject = convertedElement.getValue(); + + String elementValueString; + try { + elementValueString = this.getDataTypeArgs().toStringValue(elementValueObject); + } catch (DataTypeException e) { + String message = e.getMessage(); + if (e.getCause() != null) { + message = e.getCause().getMessage(); + } + return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " " + message)); + } + + // ConvertedArgument checks for null value, so do not need to do again here + + // Adding this code will Change the Functionality which allows to retrieve Multiple-policy using single request. + elementValueString = elementValueString + regexpValue ; + regexpValue = elementValueString.substring(0,(elementValueString.length()- regexpValue.length())); + elementValueString = elementValueString.substring(regexpValue.length(),(elementValueString.length())); + // + + if (elementValueString.matches(regexpValue)) { + return ER_TRUE; + } else { + return ER_FALSE; + } + + } + + + + + +} diff --git a/ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/pdp/std/functions/PolicyList.java b/ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/pdp/std/functions/PolicyList.java new file mode 100644 index 000000000..24ef2f72e --- /dev/null +++ b/ECOMP-PDP/src/main/java/org/openecomp/policy/xacml/pdp/std/functions/PolicyList.java @@ -0,0 +1,60 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.openecomp.policy.xacml.pdp.std.functions; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; +/** + * Creates a list of policy ids. + * + * @version $Revision: 1.3 $ + */ +public class PolicyList { + +// private static Map policyMap = new HashMap<>(); + private static List policyList = new ArrayList(); + private Logger logger = FlexLogger.getLogger(this.getClass()); + + + public static List getpolicyList(){ + return policyList; + } + + public static void addPolicyID(String policyID){ + if (!policyList.contains(policyID)){ + policyList.add(policyID); + } + // policyMap.put(policyID, count); + } + + public static void clearPolicyList(){ + // policyMap.clear(); + if (!policyList.isEmpty()){ + policyList.clear(); + } + } +} diff --git a/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionAccessPermittedTest.java b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionAccessPermittedTest.java new file mode 100644 index 000000000..050b833ac --- /dev/null +++ b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionAccessPermittedTest.java @@ -0,0 +1,522 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import javax.xml.namespace.NamespaceContext; + +import org.junit.Ignore; +import org.junit.Test; + +import com.att.research.xacml.api.Request; +import com.att.research.xacml.api.XACML3; +import com.att.research.xacml.std.StdMutableRequest; +import com.att.research.xacml.std.datatypes.DataTypes; +import com.att.research.xacml.std.dom.DOMRequest; +import com.att.research.xacmlatt.pdp.policy.ExpressionResult; +import com.att.research.xacmlatt.pdp.policy.FunctionArgument; +import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; +import com.att.research.xacmlatt.pdp.std.StdEvaluationContext; +import com.att.research.xacmlatt.pdp.std.StdFunctions; +import com.att.research.xacmlatt.pdp.std.functions.*; + +/** + * Test of PDP Functions (See XACML core spec section A.3) + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * NOT IMPLEMENTED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * This function is not yet implemented so these tests intentionally fail. + * + * + */ +public class FunctionDefinitionAccessPermittedTest { + + // + // Strings for the Request contents + // + + String reqStrMainStart = "" + + "" + + " " + + " " + + " Julius Hibbert" + + " " + + " " + + " This is IT! " + + " " + + " " + + " This is IT! " + + " " + + ""; + + String reqStrResourceStart = ""; + + String reqStrMdRecordSimpson = + "" + + "" + + "ABC Hospital" + + "Surgery" + + "" + + "" + + "Bart Simpson" + + "60" + + "male" + + "123456" + + "" + + "" + + "" + + "Gastric Cancer" + + "Hyper tension" + + "" + + "" + + "" + + "Well differentiated adeno carcinoma" + + "" + + "2000-10-05" + + "" + + "" + + "" + + " "; + String reqStrContentMdRecordSimpson = "" + reqStrMdRecordSimpson + ""; + String reqStrMalformedContent = + " " + + "" + + "" + + "ABC Hospital" + + "" + + ""; + String reqStrMdRecordSpringer = + "" + + "" + + "XYZ Hospital" + + "Surgery" + + "" + + "" + + "Jerry Springer" + + "65" + + "male" + + "765432" + + "" + + "" + + "" + + "Hyatal Hernia" + + "Diabetes" + + "Neuronal Collapse" + + "" + + "" + + "" + + "We have no idea" + + "" + + "2012-07-22" + + "" + + "" + + "" + + " "; + String reqStrContentMdRecordSpringer = + "" + reqStrMdRecordSpringer + ""; + + String reqStrResourceEnd = " " + + " http://medico.com/record/patient/BartSimpson" + + " " + + " "; + String reqStrActionStart = ""; + + String reqStrActionEnd = "" + + "read" + + "" + + " "; + String reqStrEnvironmentStartEnd = " "; + String reqStrMainEnd = " "; + + + // combined strings for convenience + String reqStrMainResourceStart = reqStrMainStart + reqStrResourceStart; + String reqStrResourceAllEnd = reqStrResourceEnd + reqStrActionStart + reqStrActionEnd + reqStrEnvironmentStartEnd + reqStrMainEnd; + + + /* + * variables useful in the following tests + */ + List arguments = new ArrayList(); + + + + // Name Spaces used in the XML as part of these examples - needed for compiling XPaths + NamespaceContext nameSpaceContext = new NamespaceContext() { + @Override + public Iterator getPrefixes(String arg0) { return null;} + + @Override + public String getPrefix(String arg0) {return null;} + + @Override + public String getNamespaceURI(String arg0) { + if("md".equals(arg0)) { + return "http://www.medico.com/schemas/record"; + } else if ("xacml-context".equals(arg0)) { + return "urn:oasis:names:tc:xacml:3.0:context:schema:os"; + } else if ("xsi".equals(arg0)) { + return "http://www.w3.org/2001/XMLSchema-instance"; + } + return null; + } + }; + + + + // + // URIs for attribute categroies + // + + FunctionArgumentAttributeValue attrUriNull = null; + FunctionArgumentAttributeValue attrUriEmpty = null; + FunctionArgumentAttributeValue attrUriResources = null; + FunctionArgumentAttributeValue attrUriAction = null; + FunctionArgumentAttributeValue attrUriNotInRequest = null; + FunctionArgumentAttributeValue attrUriNotCategory = null; + + + + // + // XML Contents + // + + FunctionArgumentAttributeValue attrXnull = null; + FunctionArgumentAttributeValue attrXEmpty = null; + FunctionArgumentAttributeValue attrXSimpson = null; + FunctionArgumentAttributeValue attrXSpringer = null; + FunctionArgumentAttributeValue attrXContentSimpson = null; + FunctionArgumentAttributeValue attrXContentSpringer = null; + FunctionArgumentAttributeValue attrXBadXML = null; + + + + + + + // + // REQUEST objects available for use in tests + // + Request requestEmpty = new StdMutableRequest(); + Request requestMdRecord = null; + Request requestDoubleResources = null; + Request requestDoubleContent = null; + Request requestResourceActionContent = null; + Request requestContentInAction = null; + + + + + /** + * Set up all variables in one place because it is complicated (lots of steps needed for each attribute) + */ + public FunctionDefinitionAccessPermittedTest() { + try { + + + // create Function Attributes for URIs + attrUriNull = null; + attrUriEmpty = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue("")); + attrUriResources = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue("urn:oasis:names:tc:xacml:3.0:attribute-category:resource")); + attrUriAction = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue("urn:oasis:names:tc:xacml:3.0:attribute-category:action")); + attrUriNotInRequest = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue("NoSuchURI")); + attrUriNotCategory = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue("urn:oasis:names:tc:xacml:1.0:resource:resource-id")); + + // create Function Attributes for XML Strings + attrXnull = new FunctionArgumentAttributeValue(null); + attrXEmpty = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("")); + attrXSimpson = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(reqStrMdRecordSimpson)); + attrXSpringer = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(reqStrMdRecordSpringer)); + attrXContentSimpson = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(reqStrContentMdRecordSimpson)); + attrXContentSpringer = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(reqStrContentMdRecordSpringer)); + attrXBadXML = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(reqStrMalformedContent)); + + + + // Request objects + // to create a Request object the easiest way is to put the xml into a file and use the DOMRequest to load it. + + // single Content in the Resources section (normal valid request) + String reqString = reqStrMainResourceStart + reqStrContentMdRecordSimpson + reqStrResourceAllEnd; + File tFile = File.createTempFile("functionJunit", "request"); + BufferedWriter bw = new BufferedWriter(new FileWriter(tFile)); + bw.append(reqString); + bw.flush(); + bw.close(); + requestMdRecord = DOMRequest.load(tFile); + tFile.delete(); + + // Resources included twice + reqString = reqStrMainResourceStart + reqStrContentMdRecordSimpson + reqStrResourceEnd + reqStrResourceStart + reqStrContentMdRecordSimpson +reqStrResourceAllEnd; + tFile = File.createTempFile("functionJunit", "request"); + bw = new BufferedWriter(new FileWriter(tFile)); + bw.append(reqString); + bw.flush(); + bw.close(); + requestDoubleResources = DOMRequest.load(tFile); + tFile.delete(); + + // Content included twice - error + reqString = reqStrMainResourceStart + reqStrContentMdRecordSimpson + reqStrContentMdRecordSimpson +reqStrResourceAllEnd; + tFile = File.createTempFile("functionJunit", "request"); + bw = new BufferedWriter(new FileWriter(tFile)); + bw.append(reqString); + bw.flush(); + bw.close(); + try { + requestDoubleContent = DOMRequest.load(tFile); + tFile.delete(); + } catch (com.att.research.xacml.std.dom.DOMStructureException e) { + // this is what it should do, so just continue + } catch (Exception e) { + fail("Unexpected exception for bad XML, e="+e); + } + + // content included in both Resource and Action - ok + reqString = reqStrMainResourceStart + reqStrContentMdRecordSimpson + reqStrResourceEnd + reqStrActionStart + reqStrContentMdRecordSimpson + reqStrActionEnd + reqStrMainEnd; + tFile = File.createTempFile("functionJunit", "request"); + bw = new BufferedWriter(new FileWriter(tFile)); + bw.append(reqString); + bw.flush(); + bw.close(); + requestResourceActionContent = DOMRequest.load(tFile); + tFile.delete(); + + // Content included only in Action - missing content produces non-error result according to spec + reqString = reqStrMainResourceStart + reqStrResourceEnd + reqStrActionStart + reqStrContentMdRecordSimpson + reqStrActionEnd + reqStrMainEnd; + tFile = File.createTempFile("functionJunit", "request"); + bw = new BufferedWriter(new FileWriter(tFile)); + bw.append(reqString); + bw.flush(); + bw.close(); + requestContentInAction = DOMRequest.load(tFile); + tFile.delete(); + + + + // Test that Bad XML is caught + @SuppressWarnings("unused") + Request requestContentMisplaced = null; + @SuppressWarnings("unused") + Request requestMalformedContent = null; + + + // Bad XML - Content not under a Category + reqString = reqStrMainStart + reqStrContentMdRecordSimpson + reqStrResourceStart + reqStrResourceEnd + reqStrActionStart + reqStrActionEnd + reqStrMainEnd; + tFile = File.createTempFile("functionJunit", "request"); + bw = new BufferedWriter(new FileWriter(tFile)); + bw.append(reqString); + bw.flush(); + bw.close(); + try { + requestContentMisplaced = DOMRequest.load(tFile); + tFile.delete(); + } catch (com.att.research.xacml.std.dom.DOMStructureException e) { + // this is what it should do, so just continue + } catch (Exception e) { + fail("Unexpected exception for bad XML, e="+e); + } + + // Bad XML - Content is not valid XML + reqString = reqStrMainResourceStart + reqStrMalformedContent + reqStrResourceAllEnd; + tFile = File.createTempFile("functionJunit", "request"); + bw = new BufferedWriter(new FileWriter(tFile)); + bw.append(reqString); + bw.flush(); + bw.close(); + try { + requestMalformedContent = DOMRequest.load(tFile); + tFile.delete(); + } catch (com.att.research.xacml.std.dom.DOMStructureException e) { + // this is what it should do, so just continue + } catch (Exception e) { + fail("Unexpected exception for bad XML, e="+e); + } + + } catch (Exception e) { + fail("Constructor initializing variables, e="+ e + " cause="+e.getCause()); + } + + } + + + + + + + + + @Ignore //@Test + public void testAccess_permitted() { + + ExpressionResult res = null; + Boolean resValue = null; + + FunctionDefinitionAccessPermitted fd = (FunctionDefinitionAccessPermitted) StdFunctions.FD_ACCESS_PERMITTED; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_ACCESS_PERMITTED, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + + + // successful invoke returns true + arguments.clear(); + arguments.add(attrUriResources); + arguments.add(attrXEmpty); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + + + // successful invoke returns false + + + // URI not in Request (ok - evaluate anyway) + + // test for infinite loop + + // second arg ok both with and without tag + arguments.clear(); + arguments.add(attrUriResources); + arguments.add(attrXContentSpringer); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + arguments.clear(); + arguments.add(attrUriResources); + arguments.add(attrXSpringer); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // second arg not valid XML + arguments.clear(); + arguments.add(attrUriResources); + arguments.add(attrXBadXML); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:access-permitted Parsing of XML string failed. Cause='The element type \"md:hospital_info\" must be terminated by the matching end-tag \"\".'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null Evaluation Context + arguments.clear(); + arguments.add(attrUriNotCategory); + arguments.add(attrXContentSimpson); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:access-permitted First argument must be a urn for an attribute-category, not 'urn:oasis:names:tc:xacml:1.0:resource:resource-id", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null Request + arguments.clear(); + arguments.add(attrUriAction); + arguments.add(attrXContentSimpson); + res = fd.evaluate(new StdEvaluationContext(null, null, null), arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:access-permitted Got null Request in EvaluationContext", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // first arg not uri + arguments.clear(); + arguments.add(attrUriNotCategory); + arguments.add(attrXContentSimpson); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:access-permitted First argument must be a urn for an attribute-category, not 'urn:oasis:names:tc:xacml:1.0:resource:resource-id", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // first arg not attribute-category urn + arguments.clear(); + arguments.add(attrXContentSimpson); + arguments.add(attrXContentSimpson); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:access-permitted Expected data type 'anyURI' saw 'string'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // second arg not string + arguments.clear(); + arguments.add(attrUriAction); + arguments.add(attrUriAction); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:access-permitted Expected data type 'string' saw 'anyURI'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // too few args + arguments.clear(); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:access-permitted Expected 2 arguments, got 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + arguments.add(attrXContentSimpson); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:access-permitted Expected 2 arguments, got 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // too many args + arguments.clear(); + arguments.add(attrUriEmpty); + arguments.add(attrXContentSimpson); + arguments.add(attrXContentSimpson); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:access-permitted Expected 2 arguments, got 3", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + } + +} diff --git a/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionArithmeticTest.java b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionArithmeticTest.java new file mode 100644 index 000000000..79e4ea9ee --- /dev/null +++ b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionArithmeticTest.java @@ -0,0 +1,717 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +import com.att.research.xacml.api.XACML3; +import com.att.research.xacml.std.datatypes.DataTypes; +import com.att.research.xacmlatt.pdp.policy.ExpressionResult; +import com.att.research.xacmlatt.pdp.policy.FunctionArgument; +import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; +import com.att.research.xacmlatt.pdp.std.StdFunctions; +import com.att.research.xacmlatt.pdp.std.functions.*; + +/** + * Test of PDP Functions (See XACML core spec section A.3) + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * + */ +public class FunctionDefinitionArithmeticTest { + + /* + * variables useful in the following tests + */ + List arguments = new ArrayList(); + + @Test + public void testInteger_add() { + + FunctionArgumentAttributeValue attr1 = null; + FunctionArgumentAttributeValue attr2 = null; + FunctionArgumentAttributeValue attrBadType = null; + try { + attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1)); + attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1)); + attrBadType = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.1)); + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + FunctionDefinitionArithmetic fd = (FunctionDefinitionArithmetic) StdFunctions.FD_INTEGER_ADD; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_INTEGER_ADD, fd.getId()); + assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + + // test normal add + arguments.add(attr1); + arguments.add(attr2); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + BigInteger resValue = (BigInteger)res.getValue().getValue(); + assertEquals(new BigInteger("2"), resValue); + + arguments.clear(); + arguments.add(attr1); + arguments.add(attrBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:integer-add Expected data type 'integer' saw 'double' at arg index 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + @Test + public void testDouble_add() { + + FunctionArgumentAttributeValue attr1 = null; + FunctionArgumentAttributeValue attr2 = null; + + try { + attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.5)); + attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(2.5)); + } catch (Exception e) { + fail("creating attributes e="+e); + } + + FunctionDefinitionArithmetic fd = (FunctionDefinitionArithmetic) StdFunctions.FD_DOUBLE_ADD; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DOUBLE_ADD, fd.getId()); + assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + + // test normal add + arguments.add(attr1); + arguments.add(attr2); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Double resValue = (Double)res.getValue().getValue(); + assertEquals(new Double(4.0), resValue); + + } + + + @Test + public void testInteger_subtract() { + + FunctionArgumentAttributeValue attr1 = null; + FunctionArgumentAttributeValue attr2 = null; + try { + attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(6)); + attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1)); + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + FunctionDefinitionArithmetic fd = (FunctionDefinitionArithmetic) StdFunctions.FD_INTEGER_SUBTRACT; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_INTEGER_SUBTRACT, fd.getId()); + assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + + // test normal + arguments.add(attr1); + arguments.add(attr2); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + BigInteger resValue = (BigInteger)res.getValue().getValue(); + assertEquals(new BigInteger("5"), resValue); + + } + + + @Test + public void testDouble_subtract() { + + FunctionArgumentAttributeValue attr1 = null; + FunctionArgumentAttributeValue attr2 = null; + + try { + attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(8.5)); + attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(2.3)); + } catch (Exception e) { + fail("creating attributes e="+e); + } + + FunctionDefinitionArithmetic fd = (FunctionDefinitionArithmetic) StdFunctions.FD_DOUBLE_SUBTRACT; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DOUBLE_SUBTRACT, fd.getId()); + assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + + // test normal + arguments.add(attr1); + arguments.add(attr2); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Double resValue = (Double)res.getValue().getValue(); + assertEquals(new Double(6.2), resValue); + + } + + + @Test + public void testInteger_multiply() { + + FunctionArgumentAttributeValue attr0 = null; + FunctionArgumentAttributeValue attr1 = null; + FunctionArgumentAttributeValue attr2 = null; + try { + attr0 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(0)); + attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(5)); + attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(2)); + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + FunctionDefinitionArithmetic fd = (FunctionDefinitionArithmetic) StdFunctions.FD_INTEGER_MULTIPLY; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_INTEGER_MULTIPLY, fd.getId()); + assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + + // test normal + arguments.add(attr1); + arguments.add(attr2); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + BigInteger resValue = (BigInteger)res.getValue().getValue(); + assertEquals(new BigInteger("10"), resValue); + + + // test 0 + arguments.clear(); + arguments.add(attr1); + arguments.add(attr0); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (BigInteger)res.getValue().getValue(); + assertEquals(new BigInteger("0"), resValue); + } + + + @Test + public void testDouble_multiply() { + + FunctionArgumentAttributeValue attr0 = null; + FunctionArgumentAttributeValue attr1 = null; + FunctionArgumentAttributeValue attr2 = null; + + try { + attr0 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(0)); + attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.5)); + attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(2.5)); + } catch (Exception e) { + fail("creating attributes e="+e); + } + + FunctionDefinitionArithmetic fd = (FunctionDefinitionArithmetic) StdFunctions.FD_DOUBLE_MULTIPLY; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DOUBLE_MULTIPLY, fd.getId()); + assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + + // test normal add + arguments.add(attr1); + arguments.add(attr2); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Double resValue = (Double)res.getValue().getValue(); + assertEquals(new Double(3.75), resValue); + + // test multiply by 0 + arguments.clear(); + arguments.add(attr1); + arguments.add(attr0); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Double)res.getValue().getValue(); + assertEquals(new Double(0), resValue); + } + + + @Test + public void testInteger_divide() { + + FunctionArgumentAttributeValue attr0 = null; + FunctionArgumentAttributeValue attr1 = null; + FunctionArgumentAttributeValue attr2 = null; + try { + attr0 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(0)); + attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(5)); + attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(2)); + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + FunctionDefinitionArithmetic fd = (FunctionDefinitionArithmetic) StdFunctions.FD_INTEGER_DIVIDE; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_INTEGER_DIVIDE, fd.getId()); + assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + + // test normal + arguments.add(attr1); + arguments.add(attr2); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + BigInteger resValue = (BigInteger)res.getValue().getValue(); + assertEquals(new BigInteger("2"), resValue); + + + // test 0 + arguments.clear(); + arguments.add(attr1); + arguments.add(attr0); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:integer-divide Divide by 0 error: 5, 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + @Test + public void testDouble_divide() { + + FunctionArgumentAttributeValue attr0 = null; + FunctionArgumentAttributeValue attr1 = null; + FunctionArgumentAttributeValue attr2 = null; + + try { + attr0 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(0)); + attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.5)); + attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(2.5)); + + } catch (Exception e) { + fail("creating attributes e="+e); + } + FunctionDefinitionArithmetic fd = (FunctionDefinitionArithmetic) StdFunctions.FD_DOUBLE_DIVIDE; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DOUBLE_DIVIDE, fd.getId()); + assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + + // test normal + arguments.add(attr1); + arguments.add(attr2); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Double resValue = (Double)res.getValue().getValue(); + assertEquals(new Double(0.6), resValue); + + // test multiply by 0 + arguments.clear(); + arguments.add(attr1); + arguments.add(attr0); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:double-divide Divide by 0 error: 1.5, 0.0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + + + + + @Test + public void testInteger_mod() { + + FunctionArgumentAttributeValue attr0 = null; + FunctionArgumentAttributeValue attr1 = null; + FunctionArgumentAttributeValue attr2 = null; + try { + attr0 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(0)); + attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(28)); + attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(5)); + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + FunctionDefinitionArithmetic fd = (FunctionDefinitionArithmetic) StdFunctions.FD_INTEGER_MOD; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_INTEGER_MOD, fd.getId()); + assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + + // test normal + arguments.add(attr1); + arguments.add(attr2); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + BigInteger resValue = (BigInteger)res.getValue().getValue(); + assertEquals(new BigInteger("3"), resValue); + + + // test 0 + arguments.clear(); + arguments.add(attr1); + arguments.add(attr0); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:integer-mod Divide by 0 error: 28, 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + @Test + public void testInteger_abs() { + + FunctionArgumentAttributeValue attr0 = null; + FunctionArgumentAttributeValue attr1 = null; + FunctionArgumentAttributeValue attrM1 = null; + try { + attr0 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(0)); + attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(5)); + attrM1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(-7)); + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + FunctionDefinitionArithmetic fd = (FunctionDefinitionArithmetic) StdFunctions.FD_INTEGER_ABS; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_INTEGER_ABS, fd.getId()); + assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + + // test normal + arguments.add(attr1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + BigInteger resValue = (BigInteger)res.getValue().getValue(); + assertEquals(new BigInteger("5"), resValue); + + arguments.clear(); + arguments.add(attrM1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (BigInteger)res.getValue().getValue(); + assertEquals(new BigInteger("7"), resValue); + + arguments.clear(); + arguments.add(attr0); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (BigInteger)res.getValue().getValue(); + assertEquals(new BigInteger("0"), resValue); + } + + + @Test + public void testDouble_abs() { + + FunctionArgumentAttributeValue attr0 = null; + FunctionArgumentAttributeValue attr1 = null; + FunctionArgumentAttributeValue attr2 = null; + + try { + attr0 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(0)); + attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.5)); + attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(-2.5)); + + } catch (Exception e) { + fail("creating attributes e="+e); + } + + FunctionDefinitionArithmetic fd = (FunctionDefinitionArithmetic) StdFunctions.FD_DOUBLE_ABS; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DOUBLE_ABS, fd.getId()); + assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + + // test normal + arguments.add(attr1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Double resValue = (Double)res.getValue().getValue(); + assertEquals(new Double(1.5), resValue); + + arguments.clear(); + arguments.add(attr2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Double)res.getValue().getValue(); + assertEquals(new Double(2.5), resValue); + + arguments.clear(); + arguments.add(attr0); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Double)res.getValue().getValue(); + assertEquals(new Double(0), resValue); + + } + + + @Test + public void testDouble_round() { + + FunctionArgumentAttributeValue attr0 = null; + FunctionArgumentAttributeValue attr1 = null; + FunctionArgumentAttributeValue attr2 = null; + FunctionArgumentAttributeValue attr3 = null; + FunctionArgumentAttributeValue attr4 = null; + FunctionArgumentAttributeValue attr5 = null; + FunctionArgumentAttributeValue attr6 = null; + try { + attr0 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(0)); + attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.5)); + attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.49)); + attr3 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.51)); + attr4 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(-2.5)); + attr5 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(-2.49)); + attr6 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(-2.51)); + } catch (Exception e) { + fail("creating attributes e="+e); + } + + + + FunctionDefinitionArithmetic fd = (FunctionDefinitionArithmetic) StdFunctions.FD_ROUND; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_ROUND, fd.getId()); + assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + + // test normal + arguments.add(attr0); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Double resValue = (Double)res.getValue().getValue(); + assertEquals(new Double(0), resValue); + + arguments.clear(); + arguments.add(attr1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Double)res.getValue().getValue(); + assertEquals(new Double(2), resValue); + + arguments.clear(); + arguments.add(attr2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Double)res.getValue().getValue(); + assertEquals(new Double(1), resValue); + + arguments.clear(); + arguments.add(attr3); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Double)res.getValue().getValue(); + assertEquals(new Double(2), resValue); + + arguments.clear(); + arguments.add(attr4); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Double)res.getValue().getValue(); + assertEquals(new Double(-2), resValue); + + arguments.clear(); + arguments.add(attr5); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Double)res.getValue().getValue(); + assertEquals(new Double(-2), resValue); + + arguments.clear(); + arguments.add(attr6); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Double)res.getValue().getValue(); + assertEquals(new Double(-3), resValue); + } + + + @Test + public void testDouble_floor() { + FunctionArgumentAttributeValue attr0 = null; + FunctionArgumentAttributeValue attr1 = null; + FunctionArgumentAttributeValue attr2 = null; + FunctionArgumentAttributeValue attr3 = null; + FunctionArgumentAttributeValue attr4 = null; + FunctionArgumentAttributeValue attr5 = null; + FunctionArgumentAttributeValue attr6 = null; + try { + attr0 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(0)); + attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.5)); + attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.49)); + attr3 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.51)); + attr4 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(-2.5)); + attr5 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(-2.49)); + attr6 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(-2.51)); + } catch (Exception e) { + fail("creating attributes e="+e); + } + + FunctionDefinitionArithmetic fd = (FunctionDefinitionArithmetic) StdFunctions.FD_FLOOR; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_FLOOR, fd.getId()); + assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + + // test normal + arguments.add(attr0); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Double resValue = (Double)res.getValue().getValue(); + assertEquals(new Double(0), resValue); + + arguments.clear(); + arguments.add(attr1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Double)res.getValue().getValue(); + assertEquals(new Double(1), resValue); + + arguments.clear(); + arguments.add(attr2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Double)res.getValue().getValue(); + assertEquals(new Double(1), resValue); + + arguments.clear(); + arguments.add(attr3); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Double)res.getValue().getValue(); + assertEquals(new Double(1), resValue); + + arguments.clear(); + arguments.add(attr4); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Double)res.getValue().getValue(); + assertEquals(new Double(-3), resValue); + + arguments.clear(); + arguments.add(attr5); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Double)res.getValue().getValue(); + assertEquals(new Double(-3), resValue); + + arguments.clear(); + arguments.add(attr6); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Double)res.getValue().getValue(); + assertEquals(new Double(-3), resValue); + } + +} diff --git a/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionBagIsInTest.java b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionBagIsInTest.java new file mode 100644 index 000000000..8024b9e36 --- /dev/null +++ b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionBagIsInTest.java @@ -0,0 +1,221 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +import com.att.research.xacml.api.XACML3; +import com.att.research.xacml.std.StdAttributeValue; +import com.att.research.xacml.std.datatypes.DataTypes; +import com.att.research.xacmlatt.pdp.policy.Bag; +import com.att.research.xacmlatt.pdp.policy.ExpressionResult; +import com.att.research.xacmlatt.pdp.policy.FunctionArgument; +import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; +import com.att.research.xacmlatt.pdp.policy.FunctionArgumentBag; +import com.att.research.xacmlatt.pdp.std.StdFunctions; +import com.att.research.xacmlatt.pdp.std.functions.*; + +/** + * Test of PDP Functions (See XACML core spec section A.3) + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * + */ +public class FunctionDefinitionBagIsInTest { + + + /* + * variables useful in the following tests + */ + List arguments = new ArrayList(); + + + @Test + public void testString() { + String v1 = new String("abc"); + String v2 = new String("def"); + String notInBag = new String("lmnop"); + String sameValueV1 = new String("abc"); + Integer vOtherType = new Integer(11); + + + FunctionArgumentAttributeValue attrV1 = null; + FunctionArgumentAttributeValue attrV2 = null; + FunctionArgumentAttributeValue attrNotInBag = null; + FunctionArgumentAttributeValue attrSameValueV1 = null; + FunctionArgumentAttributeValue attrOtherType = null; + try { + attrV1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(v1)); + attrV2 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(v2)); + attrNotInBag = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(notInBag)); + attrSameValueV1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(sameValueV1)); + attrOtherType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(vOtherType)); + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + Bag bag0 = new Bag(); + Bag bag1 = new Bag(); + bag1.add(new StdAttributeValue(DataTypes.DT_STRING.getId(), v1)); + Bag bag2 = new Bag(); + bag2.add(new StdAttributeValue(DataTypes.DT_STRING.getId(), v1)); + bag2.add(new StdAttributeValue(DataTypes.DT_STRING.getId(), v2));; + + + + FunctionArgumentBag attrBag0 = new FunctionArgumentBag(bag0); + FunctionArgumentBag attrBag1 = new FunctionArgumentBag(bag1); + FunctionArgumentBag attrBag2 = new FunctionArgumentBag(bag2); + + + + FunctionDefinitionBagIsIn fd = (FunctionDefinitionBagIsIn) StdFunctions.FD_STRING_IS_IN; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_IS_IN, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + + // element is in bag + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrBag2); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertEquals(true, resValue); + + // element not in bag + arguments.clear(); + arguments.add(attrNotInBag); + arguments.add(attrBag2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // different element with the same value is in bag + arguments.clear(); + arguments.add(attrSameValueV1); + arguments.add(attrBag2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(true, resValue); + + // empty bag + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrBag0); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // missing arg + arguments.clear(); + arguments.add(attrSameValueV1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-is-in Expected 2 arguments, got 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // 1st arg is bag + arguments.clear(); + arguments.add(attrBag1); + arguments.add(attrBag2); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-is-in Expected a simple value, saw a bag", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // 2nd arg not bag + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrV2); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-is-in Expected a bag, saw a simple value", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // first arg null + arguments.clear(); + arguments.add(null); + arguments.add(attrBag2); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-is-in Got null argument", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // 2nd arg null + arguments.clear(); + arguments.add(attrV1); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-is-in Got null argument", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // first arg type does not match bag elements + arguments.clear(); + arguments.add(attrOtherType); + arguments.add(attrBag2); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-is-in Expected data type 'string' saw 'integer'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bag has mixed element types +// behavior not specified for this case in spec. It ASSUMES that all elements in bag are same type. + + } + + + + + // + // + // REST OF DATA TYPES OMITTED + // because they "should" all work the same + // + // + + + + +} diff --git a/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionBagOneAndOnlyTest.java b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionBagOneAndOnlyTest.java new file mode 100644 index 000000000..8c129f843 --- /dev/null +++ b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionBagOneAndOnlyTest.java @@ -0,0 +1,224 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.List; +import java.math.BigInteger; + +import org.junit.Test; + +import com.att.research.xacml.api.XACML3; +import com.att.research.xacml.std.StdAttributeValue; +import com.att.research.xacml.std.datatypes.DataTypes; +import com.att.research.xacmlatt.pdp.policy.Bag; +import com.att.research.xacmlatt.pdp.policy.ExpressionResult; +import com.att.research.xacmlatt.pdp.policy.FunctionArgument; +import com.att.research.xacmlatt.pdp.policy.FunctionArgumentBag; +import com.att.research.xacmlatt.pdp.std.StdFunctions; +import com.att.research.xacmlatt.pdp.std.functions.*; + +/** + * Test of PDP Functions (See XACML core spec section A.3) + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * + */ +public class FunctionDefinitionBagOneAndOnlyTest { + + + /* + * variables useful in the following tests + */ + List arguments = new ArrayList(); + + + @Test + public void testString() { + String v1 = new String("abc"); + String v2 = new String("def"); + BigInteger vOtherType = BigInteger.valueOf(11); + + Bag bag0 = new Bag(); + Bag bag1 = new Bag(); + bag1.add(new StdAttributeValue(DataTypes.DT_STRING.getId(), v1)); + Bag bag2 = new Bag(); + bag2.add(new StdAttributeValue(DataTypes.DT_STRING.getId(), v1)); + bag2.add(new StdAttributeValue(DataTypes.DT_STRING.getId(), v2)); + Bag bagOtherType = new Bag(); + bagOtherType.add(new StdAttributeValue(DataTypes.DT_INTEGER.getId(), vOtherType)); + + FunctionArgumentBag attrBag0 = new FunctionArgumentBag(bag0); + FunctionArgumentBag attrBag1 = new FunctionArgumentBag(bag1); + FunctionArgumentBag attrBag2 = new FunctionArgumentBag(bag2); + FunctionArgumentBag attrBagOtherType = new FunctionArgumentBag(bagOtherType); + + + FunctionDefinitionBagOneAndOnly fd = (FunctionDefinitionBagOneAndOnly) StdFunctions.FD_STRING_ONE_AND_ONLY; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_ONE_AND_ONLY, fd.getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + + + + // bag with only one + arguments.clear(); + arguments.add(attrBag1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.String.class, res.getValue().getValue().getClass()); + String resValue = (String)res.getValue().getValue(); + assertEquals(v1, resValue); + + // null bag + arguments.clear(); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-one-and-only Got null argument", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bag with exactly one but of other type in it + arguments.clear(); + arguments.add(attrBagOtherType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-one-and-only Element in bag of wrong type. Expected string got integer", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bag with none + arguments.clear(); + arguments.add(attrBag0); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-one-and-only Expected 1 but Bag has 0 elements", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bag with multiple + arguments.clear(); + arguments.add(attrBag2); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-one-and-only Expected 1 but Bag has 2 elements", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + + + @Test + public void testBoolean() { + Boolean v1 = new Boolean(true); + Boolean v2 = new Boolean(false); + BigInteger vOtherType = BigInteger.valueOf(11); + + Bag bag0 = new Bag(); + Bag bag1 = new Bag(); + bag1.add(new StdAttributeValue(DataTypes.DT_BOOLEAN.getId(), v1)); + Bag bag2 = new Bag(); + bag2.add(new StdAttributeValue(DataTypes.DT_BOOLEAN.getId(), v1)); + bag2.add(new StdAttributeValue(DataTypes.DT_BOOLEAN.getId(), v2)); + Bag bagOtherType = new Bag(); + bagOtherType.add(new StdAttributeValue(DataTypes.DT_STRING.getId(), vOtherType)); + + + FunctionArgumentBag attrBag0 = new FunctionArgumentBag(bag0); + FunctionArgumentBag attrBag1 = new FunctionArgumentBag(bag1); + FunctionArgumentBag attrBag2 = new FunctionArgumentBag(bag2); + FunctionArgumentBag attrBagOtherType = new FunctionArgumentBag(bagOtherType); + + + FunctionDefinitionBagOneAndOnly fd = (FunctionDefinitionBagOneAndOnly) StdFunctions.FD_BOOLEAN_ONE_AND_ONLY; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_BOOLEAN_ONE_AND_ONLY, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + + + + // bag with only one + arguments.clear(); + arguments.add(attrBag1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertEquals(new Boolean(true), resValue); + + // null bag + arguments.clear(); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:boolean-one-and-only Got null argument", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bag with exactly one but of other type in it + arguments.clear(); + arguments.add(attrBagOtherType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:boolean-one-and-only Element in bag of wrong type. Expected boolean got string", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bag with none + arguments.clear(); + arguments.add(attrBag0); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:boolean-one-and-only Expected 1 but Bag has 0 elements", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bag with multiple + arguments.clear(); + arguments.add(attrBag2); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:boolean-one-and-only Expected 1 but Bag has 2 elements", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + + // + // + // REST OF DATA TYPES OMITTED + // because they "should" all work the same + // + // + + + + +} diff --git a/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionBagSizeTest.java b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionBagSizeTest.java new file mode 100644 index 000000000..4a536bced --- /dev/null +++ b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionBagSizeTest.java @@ -0,0 +1,158 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +import com.att.research.xacml.api.XACML3; +import com.att.research.xacml.std.StdAttributeValue; +import com.att.research.xacml.std.datatypes.DataTypes; +import com.att.research.xacmlatt.pdp.policy.Bag; +import com.att.research.xacmlatt.pdp.policy.ExpressionResult; +import com.att.research.xacmlatt.pdp.policy.FunctionArgument; +import com.att.research.xacmlatt.pdp.policy.FunctionArgumentBag; +import com.att.research.xacmlatt.pdp.std.StdFunctions; +import com.att.research.xacmlatt.pdp.std.functions.*; + +/** + * Test of PDP Functions (See XACML core spec section A.3) + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * + */ +public class FunctionDefinitionBagSizeTest { + + + /* + * variables useful in the following tests + */ + List arguments = new ArrayList(); + + + @Test + public void testString() { + String v1 = new String("abc"); + String v2 = new String("def"); + Integer vOtherType = new Integer(11); + + + + Bag bag0 = new Bag(); + Bag bag1 = new Bag(); + bag1.add(new StdAttributeValue(DataTypes.DT_STRING.getId(), v1)); + Bag bag2 = new Bag(); + bag2.add(new StdAttributeValue(DataTypes.DT_STRING.getId(), v1)); + bag2.add(new StdAttributeValue(DataTypes.DT_STRING.getId(), v2)); + Bag bagOtherType = new Bag(); + bagOtherType.add(new StdAttributeValue(DataTypes.DT_INTEGER.getId(), vOtherType)); + + + FunctionArgumentBag attrBag0 = new FunctionArgumentBag(bag0); + FunctionArgumentBag attrBag1 = new FunctionArgumentBag(bag1); + FunctionArgumentBag attrBag2 = new FunctionArgumentBag(bag2); + FunctionArgumentBag attrBagOtherType = new FunctionArgumentBag(bagOtherType); + + + FunctionDefinitionBagSize fd = (FunctionDefinitionBagSize) StdFunctions.FD_STRING_BAG_SIZE; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_BAG_SIZE, fd.getId()); + assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + + + + // bag with only one + arguments.clear(); + arguments.add(attrBag1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.math.BigInteger.class, res.getValue().getValue().getClass()); + BigInteger resValue = (BigInteger)res.getValue().getValue(); + assertEquals(BigInteger.valueOf(1), resValue); + + // null bag + arguments.clear(); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-bag-size Got null argument", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bag with exactly one but of other type in it + arguments.clear(); + arguments.add(attrBagOtherType); + res = fd.evaluate(null, arguments); + // NOTE: Size does not care about content type! + assertTrue(res.isOk()); + assertEquals(java.math.BigInteger.class, res.getValue().getValue().getClass()); + resValue = (BigInteger)res.getValue().getValue(); + assertEquals(BigInteger.valueOf(1), resValue); + + // bag with none + arguments.clear(); + arguments.add(attrBag0); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.math.BigInteger.class, res.getValue().getValue().getClass()); + resValue = (BigInteger)res.getValue().getValue(); + assertEquals(BigInteger.valueOf(0), resValue); + + // bag with multiple + arguments.clear(); + arguments.add(attrBag2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.math.BigInteger.class, res.getValue().getValue().getClass()); + resValue = (BigInteger)res.getValue().getValue(); + assertEquals(BigInteger.valueOf(2), resValue); + } + + + + + + + + // + // + // REST OF DATA TYPES OMITTED + // because they "should" all work the same + // + // + + + + +} diff --git a/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionBagTest.java b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionBagTest.java new file mode 100644 index 000000000..5b99395a5 --- /dev/null +++ b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionBagTest.java @@ -0,0 +1,547 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.junit.Test; + +import com.att.research.xacml.api.AttributeValue; +import com.att.research.xacml.api.XACML3; +import com.att.research.xacml.std.datatypes.DataTypes; +import com.att.research.xacmlatt.pdp.policy.Bag; +import com.att.research.xacmlatt.pdp.policy.ExpressionResult; +import com.att.research.xacmlatt.pdp.policy.FunctionArgument; +import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; +import com.att.research.xacmlatt.pdp.std.StdFunctions; +import com.att.research.xacmlatt.pdp.std.functions.*; + +/** + * Test of PDP Functions (See XACML core spec section A.3) + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * + */ +public class FunctionDefinitionBagTest { + + + /* + * variables useful in the following tests + */ + List arguments = new ArrayList(); + + + FunctionArgumentAttributeValue attrInteger = null; + FunctionArgumentAttributeValue attrString = null; + + public FunctionDefinitionBagTest() { + try { + attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1111111111)); + attrString = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("a string value")); + } catch (Exception e) { + fail("creating attributes e="+e); + } + } + + @Test + public void testString() { + + String s1 = "abc"; + String s2 = "def"; + FunctionArgumentAttributeValue attr1 = null; + FunctionArgumentAttributeValue attr2 = null; + try { + attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(s1)); + attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(s2)); + } catch (Exception e) { + fail("creating attributes e="+e); + } + + FunctionDefinitionBag fd = (FunctionDefinitionBag) StdFunctions.FD_STRING_BAG; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_BAG, fd.getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertTrue(fd.returnsBag()); + + // bag with only one + arguments.clear(); + arguments.add(attr1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Bag bag = res.getBag(); + assertNotNull(bag); + Iterator> it = bag.getAttributeValues(); + assertEquals(1, bag.size()); + AttributeValue attrValueObject = it.next(); + assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); + assertEquals(s1, attrValueObject.getValue()); + + // zero args => empty bag + arguments.clear(); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + assertEquals(0, bag.size()); + + + // null argument + arguments.clear(); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-bag Got null argument", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // argument of other type + arguments.clear(); + arguments.add(attrInteger); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-bag Expected data type 'string' saw 'integer'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // 2 args (check response is correct) + arguments.clear(); + arguments.add(attr1); + arguments.add(attr2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(2, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); + assertEquals(s1, attrValueObject.getValue()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); + assertEquals(s2, attrValueObject.getValue()); + + // duplicate args (verify return) + arguments.clear(); + arguments.add(attr1); + arguments.add(attr2); + arguments.add(attr1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(3, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); + assertEquals(s1, attrValueObject.getValue()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); + assertEquals(s2, attrValueObject.getValue()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); + assertEquals(s1, attrValueObject.getValue()); + + // lots of args + arguments.clear(); + for (int i = 0; i < 1000; i++) { + arguments.add(attr1); + } + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(1000, bag.size()); + + } + + + @Test + public void testBoolean() { + + Boolean s1 = true; + Boolean s2 = false; + FunctionArgumentAttributeValue attr1 = null; + FunctionArgumentAttributeValue attr2 = null; + try { + attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_BOOLEAN.createAttributeValue(s1)); + attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_BOOLEAN.createAttributeValue(s2)); + } catch (Exception e) { + fail("creating attributes e="+e); + } + + FunctionDefinitionBag fd = (FunctionDefinitionBag) StdFunctions.FD_BOOLEAN_BAG; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_BOOLEAN_BAG, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertTrue(fd.returnsBag()); + + // bag with only one + arguments.clear(); + arguments.add(attr1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Bag bag = res.getBag(); + assertNotNull(bag); + Iterator> it = bag.getAttributeValues(); + assertEquals(1, bag.size()); + AttributeValue attrValueObject = it.next(); + assertEquals(DataTypes.DT_BOOLEAN.getId(), attrValueObject.getDataTypeId()); + assertEquals(s1, attrValueObject.getValue()); + + // zero args => empty bag + arguments.clear(); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + assertEquals(0, bag.size()); + + + // null argument + arguments.clear(); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:boolean-bag Got null argument", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // argument of other type + arguments.clear(); + arguments.add(attrInteger); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:boolean-bag Expected data type 'boolean' saw 'integer'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // 2 args (check response is correct) + arguments.clear(); + arguments.add(attr1); + arguments.add(attr2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(2, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_BOOLEAN.getId(), attrValueObject.getDataTypeId()); + assertEquals(s1, attrValueObject.getValue()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_BOOLEAN.getId(), attrValueObject.getDataTypeId()); + assertEquals(s2, attrValueObject.getValue()); + + // duplicate args (verify return) + arguments.clear(); + arguments.add(attr1); + arguments.add(attr2); + arguments.add(attr1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(3, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_BOOLEAN.getId(), attrValueObject.getDataTypeId()); + assertEquals(s1, attrValueObject.getValue()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_BOOLEAN.getId(), attrValueObject.getDataTypeId()); + assertEquals(s2, attrValueObject.getValue()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_BOOLEAN.getId(), attrValueObject.getDataTypeId()); + assertEquals(s1, attrValueObject.getValue()); + + // lots of args + arguments.clear(); + for (int i = 0; i < 1000; i++) { + arguments.add(attr1); + } + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(1000, bag.size()); + + } + + + + @Test + public void testInteger() { + + BigInteger s1 = new BigInteger("123"); + BigInteger s2 = new BigInteger("456"); + FunctionArgumentAttributeValue attr1 = null; + FunctionArgumentAttributeValue attr2 = null; + try { + attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(s1)); + attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(s2)); + } catch (Exception e) { + fail("creating attributes e="+e); + } + + FunctionDefinitionBag fd = (FunctionDefinitionBag) StdFunctions.FD_INTEGER_BAG; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_INTEGER_BAG, fd.getId()); + assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertTrue(fd.returnsBag()); + + // bag with only one + arguments.clear(); + arguments.add(attr1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Bag bag = res.getBag(); + assertNotNull(bag); + Iterator> it = bag.getAttributeValues(); + assertEquals(1, bag.size()); + AttributeValue attrValueObject = it.next(); + assertEquals(DataTypes.DT_INTEGER.getId(), attrValueObject.getDataTypeId()); + assertEquals(s1, attrValueObject.getValue()); + + // zero args => empty bag + arguments.clear(); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + assertEquals(0, bag.size()); + + + // null argument + arguments.clear(); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:integer-bag Got null argument", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // argument of other type + arguments.clear(); + arguments.add(attrString); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:integer-bag Expected data type 'integer' saw 'string'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // 2 args (check response is correct) + arguments.clear(); + arguments.add(attr1); + arguments.add(attr2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(2, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_INTEGER.getId(), attrValueObject.getDataTypeId()); + assertEquals(s1, attrValueObject.getValue()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_INTEGER.getId(), attrValueObject.getDataTypeId()); + assertEquals(s2, attrValueObject.getValue()); + + // duplicate args (verify return) + arguments.clear(); + arguments.add(attr1); + arguments.add(attr2); + arguments.add(attr1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(3, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_INTEGER.getId(), attrValueObject.getDataTypeId()); + assertEquals(s1, attrValueObject.getValue()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_INTEGER.getId(), attrValueObject.getDataTypeId()); + assertEquals(s2, attrValueObject.getValue()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_INTEGER.getId(), attrValueObject.getDataTypeId()); + assertEquals(s1, attrValueObject.getValue()); + + // lots of args + arguments.clear(); + for (int i = 0; i < 1000; i++) { + arguments.add(attr1); + } + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(1000, bag.size()); + + } + + + + + @Test + public void testDouble() { + + Double s1 = 123.45; + Double s2 = 678.901; + FunctionArgumentAttributeValue attr1 = null; + FunctionArgumentAttributeValue attr2 = null; + try { + attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(s1)); + attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(s2)); + } catch (Exception e) { + fail("creating attributes e="+e); + } + + FunctionDefinitionBag fd = (FunctionDefinitionBag) StdFunctions.FD_DOUBLE_BAG; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DOUBLE_BAG, fd.getId()); + assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertTrue(fd.returnsBag()); + + // bag with only one + arguments.clear(); + arguments.add(attr1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Bag bag = res.getBag(); + assertNotNull(bag); + Iterator> it = bag.getAttributeValues(); + assertEquals(1, bag.size()); + AttributeValue attrValueObject = it.next(); + assertEquals(DataTypes.DT_DOUBLE.getId(), attrValueObject.getDataTypeId()); + assertEquals(s1, attrValueObject.getValue()); + + // zero args => empty bag + arguments.clear(); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + assertEquals(0, bag.size()); + + + // null argument + arguments.clear(); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:double-bag Got null argument", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // argument of other type + arguments.clear(); + arguments.add(attrInteger); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:double-bag Expected data type 'double' saw 'integer'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // 2 args (check response is correct) + arguments.clear(); + arguments.add(attr1); + arguments.add(attr2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(2, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_DOUBLE.getId(), attrValueObject.getDataTypeId()); + assertEquals(s1, attrValueObject.getValue()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_DOUBLE.getId(), attrValueObject.getDataTypeId()); + assertEquals(s2, attrValueObject.getValue()); + + // duplicate args (verify return) + arguments.clear(); + arguments.add(attr1); + arguments.add(attr2); + arguments.add(attr1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(3, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_DOUBLE.getId(), attrValueObject.getDataTypeId()); + assertEquals(s1, attrValueObject.getValue()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_DOUBLE.getId(), attrValueObject.getDataTypeId()); + assertEquals(s2, attrValueObject.getValue()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_DOUBLE.getId(), attrValueObject.getDataTypeId()); + assertEquals(s1, attrValueObject.getValue()); + + // lots of args + arguments.clear(); + for (int i = 0; i < 1000; i++) { + arguments.add(attr1); + } + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(1000, bag.size()); + + } + + + + + + // + // + // REST OF DATA TYPES OMITTED + // because they "should" all work the same + // + // + + + + +} diff --git a/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionBaseTest.java b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionBaseTest.java new file mode 100644 index 000000000..10975f469 --- /dev/null +++ b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionBaseTest.java @@ -0,0 +1,131 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test; + + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +import com.att.research.xacml.api.Identifier; +import com.att.research.xacml.api.XACML3; +import com.att.research.xacmlatt.pdp.policy.FunctionDefinition; +import com.att.research.xacmlatt.pdp.std.StdFunctions; +import com.att.research.xacmlatt.pdp.std.functions.*; + +/** + * Test functions in the abstract FunctionDefinitionSimpleTest class. + * Functions are tested by creating instances of other classes that should have appropriate properties to verify all variations of the responses expected. + * + * Note: we do not test getDataTypeId() because all it does is get the String out of the Identity object and we assume that the Data Type Identity objects + * are tested enough in everything else that any errors in them will be found and fixed quickly. + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * + */ +public class FunctionDefinitionBaseTest { + /** + * getId() is pretty trivial, so verifying one should be enough to check that the mechanism is working ok + */ + @Test + public void testGetId() { + FunctionDefinition fd = StdFunctions.FD_STRING_EQUAL; + Identifier id = fd.getId(); + assertTrue(XACML3.ID_FUNCTION_STRING_EQUAL.stringValue().equals(id.stringValue()) ); + } + + /** + * check an instance of every result type that we can deal with + */ + @Test + public void testGetDataType() { + +//?? Need functions that return each of these data types except for Boolean which is returned by any of the EQUAL functions + FunctionDefinition fdstring = StdFunctions.FD_STRING_NORMALIZE_SPACE; + assertEquals(XACML3.ID_DATATYPE_STRING, fdstring.getDataTypeId()); + + FunctionDefinition fdboolean = StdFunctions.FD_STRING_EQUAL; + assertEquals(XACML3.ID_DATATYPE_BOOLEAN, fdboolean.getDataTypeId()); + + FunctionDefinition fdinteger = StdFunctions.FD_INTEGER_ADD; + assertEquals(XACML3.ID_DATATYPE_INTEGER, fdinteger.getDataTypeId()); + + FunctionDefinition fddouble = StdFunctions.FD_DOUBLE_ADD; + assertEquals(XACML3.ID_DATATYPE_DOUBLE, fddouble.getDataTypeId()); + + FunctionDefinition fddate = StdFunctions.FD_DATE_BAG; + assertEquals(XACML3.ID_DATATYPE_DATE, fddate.getDataTypeId()); + + FunctionDefinition fdtime = StdFunctions.FD_TIME_BAG; + assertEquals(XACML3.ID_DATATYPE_TIME, fdtime.getDataTypeId()); + + FunctionDefinition fddateTime = StdFunctions.FD_DATETIME_BAG; + assertEquals(XACML3.ID_DATATYPE_DATETIME, fddateTime.getDataTypeId()); + + FunctionDefinition fddayTimeDuration = StdFunctions.FD_DAYTIMEDURATION_FROM_STRING; + assertEquals(XACML3.ID_DATATYPE_DAYTIMEDURATION, fddayTimeDuration.getDataTypeId()); + + FunctionDefinition fdyearMonthDuration = StdFunctions.FD_YEARMONTHDURATION_FROM_STRING; + assertEquals(XACML3.ID_DATATYPE_YEARMONTHDURATION, fdyearMonthDuration.getDataTypeId()); + + FunctionDefinition fdanyURI = StdFunctions.FD_ANYURI_FROM_STRING; + assertEquals(XACML3.ID_DATATYPE_ANYURI, fdanyURI.getDataTypeId()); + + FunctionDefinition fdhexBinary = StdFunctions.FD_HEXBINARY_UNION; + assertEquals(XACML3.ID_DATATYPE_HEXBINARY, fdhexBinary.getDataTypeId()); + + FunctionDefinition fdbase64Binary = StdFunctions.FD_BASE64BINARY_UNION; + assertEquals(XACML3.ID_DATATYPE_BASE64BINARY, fdbase64Binary.getDataTypeId()); + + FunctionDefinition fdrfc822Name = StdFunctions.FD_RFC822NAME_FROM_STRING; + assertEquals(XACML3.ID_DATATYPE_RFC822NAME, fdrfc822Name.getDataTypeId()); + + FunctionDefinition fdx500Name = StdFunctions.FD_X500NAME_FROM_STRING; + assertEquals(XACML3.ID_DATATYPE_X500NAME, fdx500Name.getDataTypeId()); + +//TODO - There are currently no functions that return XPathExpression objects +// FunctionDefinition fdxpathExpression = StdFunctions.FD_XPATHEXPRESSION_FROM_STRING; +// assertEquals(XACML3.ID_DATATYPE_XPATHEXPRESSION, fdxpathExpression.getDataTypeId()); + + FunctionDefinition fdipAddress = StdFunctions.FD_IPADDRESS_FROM_STRING; + assertEquals(XACML3.ID_DATATYPE_IPADDRESS, fdipAddress.getDataTypeId()); + + FunctionDefinition fddnsName = StdFunctions.FD_DNSNAME_FROM_STRING; + assertEquals(XACML3.ID_DATATYPE_DNSNAME, fddnsName.getDataTypeId()); + } + + /** + * check the type of return, single vs multiple values + */ + @Test + public void testReturnsBag() { + FunctionDefinition fdNotBag = StdFunctions.FD_BOOLEAN_EQUAL; + assertFalse(fdNotBag.returnsBag()); + + FunctionDefinitionBag fdBag = (FunctionDefinitionBag) StdFunctions.FD_STRING_BAG; + assertTrue(fdBag.returnsBag()); + } + +} diff --git a/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionComparisonTest.java b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionComparisonTest.java new file mode 100644 index 000000000..0ea1a2c9d --- /dev/null +++ b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionComparisonTest.java @@ -0,0 +1,1366 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.List; + +import org.junit.Test; + +import com.att.research.xacml.api.XACML3; +import com.att.research.xacml.std.datatypes.DataTypes; +import com.att.research.xacml.std.datatypes.ISO8601Date; +import com.att.research.xacml.std.datatypes.ISO8601DateTime; +import com.att.research.xacml.std.datatypes.ISO8601Time; +import com.att.research.xacmlatt.pdp.policy.ExpressionResult; +import com.att.research.xacmlatt.pdp.policy.FunctionArgument; +import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; +import com.att.research.xacmlatt.pdp.std.StdFunctions; +import com.att.research.xacmlatt.pdp.std.functions.*; + +/** + * Test FunctionDefinitionComparison + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * + */ +public class FunctionDefinitionComparisonTest { + + /* + * variables useful in the following tests + */ + List arguments = new ArrayList(); + + FunctionArgumentAttributeValue stringAttr1 = null; + FunctionArgumentAttributeValue stringAttr1a = null; + FunctionArgumentAttributeValue stringAttr2 = null; + FunctionArgumentAttributeValue stringAttrNeg1 = null; + + + FunctionArgumentAttributeValue intAttr1 = null; + FunctionArgumentAttributeValue intAttr1a = null; + FunctionArgumentAttributeValue intAttr2 = null; + FunctionArgumentAttributeValue intAttr0 = null; + FunctionArgumentAttributeValue intAttrNeg1 = null; + + FunctionArgumentAttributeValue attr1 = null; + FunctionArgumentAttributeValue attr1a = null; + FunctionArgumentAttributeValue attr2 = null; + FunctionArgumentAttributeValue attrNeg1 = null; + + FunctionArgumentAttributeValue attrDateToday = null; + FunctionArgumentAttributeValue attrDateSameDay = null; + FunctionArgumentAttributeValue attrDateTommorrow = null; + FunctionArgumentAttributeValue attrDateYesterday = null; + FunctionArgumentAttributeValue attrDateWithTimeZone = null; + FunctionArgumentAttributeValue attrDateNoTimeZone = null; + + + FunctionArgumentAttributeValue attrTimeToday = null; + FunctionArgumentAttributeValue attrTimeSameDay = null; + FunctionArgumentAttributeValue attrTimeTommorrow = null; + FunctionArgumentAttributeValue attrTimeYesterday = null; + FunctionArgumentAttributeValue attrTimeWithTimeZone = null; + FunctionArgumentAttributeValue attrTimeNoTimeZone = null; + + FunctionArgumentAttributeValue attrDateTimeToday = null; + FunctionArgumentAttributeValue attrDateTimeSameDay = null; + FunctionArgumentAttributeValue attrDateTimeTommorrow = null; + FunctionArgumentAttributeValue attrDateTimeYesterday = null; + FunctionArgumentAttributeValue attrDateTimeWithTimeZone = null; + FunctionArgumentAttributeValue attrDateTimeNoTimeZone = null; + + /** + * Set up some common variables on startup + */ + public FunctionDefinitionComparisonTest() { + try { + stringAttr1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("abc")); + stringAttr1a = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("abc")); + stringAttr2 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("def")); + stringAttrNeg1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("AAA")); + + + intAttr1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1)); + intAttr1a = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1)); + intAttr2 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(2)); + intAttr0 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(0)); + intAttrNeg1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(-1)); + + attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.0)); + attr1a = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.0)); + attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(2.4)); + attrNeg1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(-1.0)); + + // create dates + Calendar calendar = Calendar.getInstance(); + Date today = calendar.getTime(); + Date longAgo = new Date(1234); + // create a date that is different than "today" but within the same day (i.e. has a different hour) + if (calendar.get(Calendar.HOUR_OF_DAY) > 3) { + calendar.set(Calendar.HOUR_OF_DAY, 3); + } else { + calendar.set(Calendar.HOUR_OF_DAY, 5); + } + Date todayPlus = calendar.getTime(); + calendar.add(Calendar.DATE, 1); + Date tommorrow = calendar.getTime(); + attrDateToday = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(today)); + attrDateSameDay = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(todayPlus)); + attrDateTommorrow = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(tommorrow)); + attrDateYesterday = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(longAgo)); + ISO8601Date isoDate = new ISO8601Date(1920, 5, 8); + attrDateNoTimeZone = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(isoDate)); + isoDate = new ISO8601Date("GMT+00:02", 1920, 5, 8); + attrDateWithTimeZone = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(isoDate)); + + // create Times + ISO8601Time isoTime = new ISO8601Time(14, 43, 12, 145); + attrTimeToday = new FunctionArgumentAttributeValue(DataTypes.DT_TIME.createAttributeValue(isoTime)); + attrTimeSameDay = new FunctionArgumentAttributeValue(DataTypes.DT_TIME.createAttributeValue(isoTime)); + isoTime = new ISO8601Time(18, 53, 34, 423); + attrTimeTommorrow = new FunctionArgumentAttributeValue(DataTypes.DT_TIME.createAttributeValue(isoTime)); + isoTime = new ISO8601Time(7, 34, 6,543); + attrTimeYesterday = new FunctionArgumentAttributeValue(DataTypes.DT_TIME.createAttributeValue(isoTime)); + isoTime = new ISO8601Time(12, 12, 12, 12); + attrTimeNoTimeZone = new FunctionArgumentAttributeValue(DataTypes.DT_TIME.createAttributeValue(isoTime)); + isoTime = new ISO8601Time("GMT:+00:03", 12, 12, 12, 12); + attrTimeWithTimeZone = new FunctionArgumentAttributeValue(DataTypes.DT_TIME.createAttributeValue(isoTime)); + + // create DateTimes + isoDate = new ISO8601Date(1920, 5, 8); + isoTime = new ISO8601Time( 18, 53, 34, 423); + ISO8601DateTime isoDateTime = new ISO8601DateTime((String)null, 1920, 5, 8, 18, 53, 34, 423); + attrDateTimeToday = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(isoDateTime)); + attrDateTimeSameDay = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(isoDateTime)); + isoTime = new ISO8601Time(20, 53, 34, 423); + isoDateTime = new ISO8601DateTime((String)null, 1920, 5, 8, 20, 53, 34, 423); + attrDateTimeTommorrow = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(isoDateTime)); + isoTime = new ISO8601Time(7, 34, 6,543); + isoDateTime = new ISO8601DateTime((String)null, 1920, 5, 8, 7, 34, 6, 543); + attrDateTimeYesterday = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(isoDateTime)); + isoTime = new ISO8601Time(12, 12, 12, 12); + isoDateTime = new ISO8601DateTime((String)null, 1920, 5, 8, 12, 12, 12, 12); + attrDateTimeNoTimeZone = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(isoDateTime)); + isoTime = new ISO8601Time("GMT:+00:03", 12, 12, 12, 12); + isoDate = new ISO8601Date("GMT:+00:03", 1920, 5, 8); + isoDateTime = new ISO8601DateTime("GMT:+00:03", 1920, 5, 8, 12, 12, 12, 12); + attrDateTimeWithTimeZone = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(isoDateTime)); + + + + + } catch (Exception e) { + fail("Error creating values e="+ e); + } + } + + /** + * String + */ + @Test + public void testString_GT() { + + FunctionDefinitionComparison fd = (FunctionDefinitionComparison) StdFunctions.FD_STRING_GREATER_THAN; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_GREATER_THAN, fd.getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // first == second + arguments.add(stringAttr1); + arguments.add(stringAttr1a); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // check first < second + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(stringAttr2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first > second + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(stringAttrNeg1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // test bad args data types? Not needed? + arguments.clear(); + arguments.add(intAttr1); + arguments.add(stringAttr1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + } + + @Test + public void testString_GTE() { + + FunctionDefinitionComparison fd = (FunctionDefinitionComparison) StdFunctions.FD_STRING_GREATER_THAN_OR_EQUAL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_GREATER_THAN_OR_EQUAL, fd.getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // first == second + arguments.add(stringAttr1); + arguments.add(stringAttr1a); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // check first < second + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(stringAttr2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first > second + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(stringAttrNeg1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + } + + @Test + public void testString_LT() { + + FunctionDefinitionComparison fd = (FunctionDefinitionComparison) StdFunctions.FD_STRING_LESS_THAN; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_LESS_THAN, fd.getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // first == second + arguments.add(stringAttr1); + arguments.add(stringAttr1a); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // check first < second + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(stringAttr2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // first > second + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(stringAttrNeg1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + } + + @Test + public void testString_LTE() { + + FunctionDefinitionComparison fd = (FunctionDefinitionComparison) StdFunctions.FD_STRING_LESS_THAN_OR_EQUAL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_LESS_THAN_OR_EQUAL, fd.getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // first == second + arguments.add(stringAttr1); + arguments.add(stringAttr1a); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // check first < second + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(stringAttr2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // first > second + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(stringAttrNeg1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + } + + + + /** + * Integer + */ + @Test + public void testInteger_GT() { + + FunctionDefinitionComparison fd = (FunctionDefinitionComparison) StdFunctions.FD_INTEGER_GREATER_THAN; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_INTEGER_GREATER_THAN, fd.getId()); + assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // first == second + arguments.add(intAttr1); + arguments.add(intAttr1a); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // check first < second + arguments.clear(); + arguments.add(intAttr1); + arguments.add(intAttr2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first > second + arguments.clear(); + arguments.add(intAttr1); + arguments.add(intAttrNeg1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // test bad args data types? Not needed? + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(intAttr1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + } + + @Test + public void testInteger_GTE() { + + FunctionDefinitionComparison fd = (FunctionDefinitionComparison) StdFunctions.FD_INTEGER_GREATER_THAN_OR_EQUAL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_INTEGER_GREATER_THAN_OR_EQUAL, fd.getId()); + assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // first == second + arguments.add(intAttr1); + arguments.add(intAttr1a); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // check first < second + arguments.clear(); + arguments.add(intAttr1); + arguments.add(intAttr2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first > second + arguments.clear(); + arguments.add(intAttr1); + arguments.add(intAttrNeg1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + } + + @Test + public void testInteger_LT() { + + FunctionDefinitionComparison fd = (FunctionDefinitionComparison) StdFunctions.FD_INTEGER_LESS_THAN; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_INTEGER_LESS_THAN, fd.getId()); + assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // first == second + arguments.add(intAttr1); + arguments.add(intAttr1a); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // check first < second + arguments.clear(); + arguments.add(intAttr1); + arguments.add(intAttr2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // first > second + arguments.clear(); + arguments.add(intAttr1); + arguments.add(intAttrNeg1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + } + + @Test + public void testInteger_LTE() { + + FunctionDefinitionComparison fd = (FunctionDefinitionComparison) StdFunctions.FD_INTEGER_LESS_THAN_OR_EQUAL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_INTEGER_LESS_THAN_OR_EQUAL, fd.getId()); + assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // first == second + arguments.add(intAttr1); + arguments.add(intAttr1a); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // check first < second + arguments.clear(); + arguments.add(intAttr1); + arguments.add(intAttr2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // first > second + arguments.clear(); + arguments.add(intAttr1); + arguments.add(intAttrNeg1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + } + + + + + /** + * Double + */ + @Test + public void testDouble_GT() { + + FunctionDefinitionComparison fd = (FunctionDefinitionComparison) StdFunctions.FD_DOUBLE_GREATER_THAN; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DOUBLE_GREATER_THAN, fd.getId()); + assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // first == second + arguments.add(attr1); + arguments.add(attr1a); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first < second + arguments.clear(); + arguments.add(attr1); + arguments.add(attr2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first > second + arguments.clear(); + arguments.add(attr1); + arguments.add(attrNeg1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // test bad args data types? Not needed? + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(intAttr1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + + } + + @Test + public void testDouble_GTE() { + + FunctionDefinitionComparison fd = (FunctionDefinitionComparison) StdFunctions.FD_DOUBLE_GREATER_THAN_OR_EQUAL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DOUBLE_GREATER_THAN_OR_EQUAL, fd.getId()); + assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // first == second + arguments.add(attr1); + arguments.add(attr1a); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // first < second + arguments.clear(); + arguments.add(attr1); + arguments.add(attr2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first > second + arguments.clear(); + arguments.add(attr1); + arguments.add(attrNeg1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + } + + @Test + public void testDouble_LT() { + + FunctionDefinitionComparison fd = (FunctionDefinitionComparison) StdFunctions.FD_DOUBLE_LESS_THAN; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DOUBLE_LESS_THAN, fd.getId()); + assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // first == second + arguments.add(attr1); + arguments.add(attr1a); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first < second + arguments.clear(); + arguments.add(attr1); + arguments.add(attr2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // first > second + arguments.clear(); + arguments.add(attr1); + arguments.add(attrNeg1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + } + + @Test + public void testDouble_LTE() { + + FunctionDefinitionComparison fd = (FunctionDefinitionComparison) StdFunctions.FD_DOUBLE_LESS_THAN_OR_EQUAL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DOUBLE_LESS_THAN_OR_EQUAL, fd.getId()); + assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // first == second + arguments.add(attr1); + arguments.add(attr1a); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // first < second + arguments.clear(); + arguments.add(attr1); + arguments.add(attr2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // first > second + arguments.clear(); + arguments.add(attr1); + arguments.add(attrNeg1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + } + + + + /** + * Date + */ + + @Test + public void testDate_GT() { + + FunctionDefinitionComparison fd = (FunctionDefinitionComparison) StdFunctions.FD_DATE_GREATER_THAN; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DATE_GREATER_THAN, fd.getId()); + assertEquals(DataTypes.DT_DATE.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // first == second + arguments.add(attrDateToday); + arguments.add(attrDateSameDay); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first < second + arguments.clear(); + arguments.add(attrDateToday); + arguments.add(attrDateTommorrow); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first > second + arguments.clear(); + arguments.add(attrDateToday); + arguments.add(attrDateYesterday); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // test bad args data types? One with TimeZone and one without + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(intAttr1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + + // test with TimeZone vs without + arguments.clear(); + arguments.add(attrDateWithTimeZone); + arguments.add(attrDateNoTimeZone); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:date-greater-than Cannot compare this ISO8601DateTime with non-time-zoned ISO8601DateTime", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + } + + @Test + public void testDate_GTE() { + + FunctionDefinitionComparison fd = (FunctionDefinitionComparison) StdFunctions.FD_DATE_GREATER_THAN_OR_EQUAL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DATE_GREATER_THAN_OR_EQUAL, fd.getId()); + assertEquals(DataTypes.DT_DATE.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // first == second + arguments.add(attrDateToday); + arguments.add(attrDateSameDay); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // first < second + arguments.clear(); + arguments.add(attrDateToday); + arguments.add(attrDateTommorrow); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first > second + arguments.clear(); + arguments.add(attrDateToday); + arguments.add(attrDateYesterday); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + } + + @Test + public void testDate_LT() { + + FunctionDefinitionComparison fd = (FunctionDefinitionComparison) StdFunctions.FD_DATE_LESS_THAN; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DATE_LESS_THAN, fd.getId()); + assertEquals(DataTypes.DT_DATE.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // first == second + arguments.add(attrDateToday); + arguments.add(attrDateSameDay); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first < second + arguments.clear(); + arguments.add(attrDateToday); + arguments.add(attrDateTommorrow); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // first > second + arguments.clear(); + arguments.add(attrDateToday); + arguments.add(attrDateYesterday); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + } + + @Test + public void testDate_LTE() { + + FunctionDefinitionComparison fd = (FunctionDefinitionComparison) StdFunctions.FD_DATE_LESS_THAN_OR_EQUAL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DATE_LESS_THAN_OR_EQUAL, fd.getId()); + assertEquals(DataTypes.DT_DATE.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // first == second + arguments.add(attrDateToday); + arguments.add(attrDateSameDay); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // first < second + arguments.clear(); + arguments.add(attrDateToday); + arguments.add(attrDateTommorrow); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // first > second + arguments.clear(); + arguments.add(attrDateToday); + arguments.add(attrDateYesterday); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + } + + + + + + + + /** + * Time + */ + + @Test + public void testTime_GT() { + + FunctionDefinitionComparison fd = (FunctionDefinitionComparison) StdFunctions.FD_TIME_GREATER_THAN; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_TIME_GREATER_THAN, fd.getId()); + assertEquals(DataTypes.DT_TIME.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // first == second + arguments.add(attrTimeToday); + arguments.add(attrTimeSameDay); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first < second + arguments.clear(); + arguments.add(attrTimeToday); + arguments.add(attrTimeTommorrow); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first > second + arguments.clear(); + arguments.add(attrTimeToday); + arguments.add(attrTimeYesterday); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // test bad args data types? One with TimeZone and one without + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(intAttr1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + + // test with TimeZone vs without + arguments.clear(); + arguments.add(attrTimeWithTimeZone); + arguments.add(attrTimeNoTimeZone); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:time-greater-than Cannot compare this ISO8601DateTime with non-time-zoned ISO8601DateTime", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + } + + @Test + public void testTime_GTE() { + + FunctionDefinitionComparison fd = (FunctionDefinitionComparison) StdFunctions.FD_TIME_GREATER_THAN_OR_EQUAL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_TIME_GREATER_THAN_OR_EQUAL, fd.getId()); + assertEquals(DataTypes.DT_TIME.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // first == second + arguments.add(attrTimeToday); + arguments.add(attrTimeSameDay); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // first < second + arguments.clear(); + arguments.add(attrTimeToday); + arguments.add(attrTimeTommorrow); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first > second + arguments.clear(); + arguments.add(attrTimeToday); + arguments.add(attrTimeYesterday); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + } + + @Test + public void testTime_LT() { + + FunctionDefinitionComparison fd = (FunctionDefinitionComparison) StdFunctions.FD_TIME_LESS_THAN; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_TIME_LESS_THAN, fd.getId()); + assertEquals(DataTypes.DT_TIME.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // first == second + arguments.add(attrTimeToday); + arguments.add(attrTimeSameDay); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first < second + arguments.clear(); + arguments.add(attrTimeToday); + arguments.add(attrTimeTommorrow); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // first > second + arguments.clear(); + arguments.add(attrTimeToday); + arguments.add(attrTimeYesterday); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + } + + @Test + public void testTime_LTE() { + + FunctionDefinitionComparison fd = (FunctionDefinitionComparison) StdFunctions.FD_TIME_LESS_THAN_OR_EQUAL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_TIME_LESS_THAN_OR_EQUAL, fd.getId()); + assertEquals(DataTypes.DT_TIME.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // first == second + arguments.add(attrTimeToday); + arguments.add(attrTimeSameDay); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // first < second + arguments.clear(); + arguments.add(attrTimeToday); + arguments.add(attrTimeTommorrow); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // first > second + arguments.clear(); + arguments.add(attrTimeToday); + arguments.add(attrTimeYesterday); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + } + + + + + + /** + * Time-in-range + */ + @Test + public void testTime_in_range() { + + FunctionDefinitionTimeInRange fd = (FunctionDefinitionTimeInRange) StdFunctions.FD_TIME_IN_RANGE; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_TIME_IN_RANGE, fd.getId()); + assertEquals(DataTypes.DT_TIME.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(3), fd.getNumArgs()); + + // arg 0 in range of others + arguments.add(attrTimeToday); + arguments.add(attrTimeYesterday); + arguments.add(attrTimeTommorrow); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // below range + arguments.clear(); + arguments.add(attrTimeYesterday); + arguments.add(attrTimeToday); + arguments.add(attrTimeTommorrow); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // above range + arguments.clear(); + arguments.add(attrTimeTommorrow); + arguments.add(attrTimeYesterday); + arguments.add(attrTimeToday); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // range bad + arguments.clear(); + arguments.add(attrTimeToday); + arguments.add(attrTimeTommorrow); + arguments.add(attrTimeYesterday); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // bad types + arguments.clear(); + arguments.add(attrDateTimeWithTimeZone); + arguments.add(attrDateTimeNoTimeZone); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:time-in-range Expected 3 arguments, got 2", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + arguments.add(attrDateTimeWithTimeZone); + arguments.add(attrDateTimeNoTimeZone); + arguments.add(intAttr1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:time-in-range Expected data type 'time' saw 'dateTime' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + + + + + /** + * DateTime + */ + + @Test + public void testDateTime_GT() { + + FunctionDefinitionComparison fd = (FunctionDefinitionComparison) StdFunctions.FD_DATETIME_GREATER_THAN; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DATETIME_GREATER_THAN, fd.getId()); + assertEquals(DataTypes.DT_DATETIME.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // first == second + arguments.add(attrDateTimeToday); + arguments.add(attrDateTimeSameDay); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first < second + arguments.clear(); + arguments.add(attrDateTimeToday); + arguments.add(attrDateTimeTommorrow); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first > second + arguments.clear(); + arguments.add(attrDateTimeToday); + arguments.add(attrDateTimeYesterday); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // test bad args data types? One with TimeZone and one without + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(intAttr1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + + // test with TimeZone vs without + arguments.clear(); + arguments.add(attrDateTimeWithTimeZone); + arguments.add(attrDateTimeNoTimeZone); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-greater-than Cannot compare this ISO8601DateTime with non-time-zoned ISO8601DateTime", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + } + + @Test + public void testDateTime_GTE() { + + FunctionDefinitionComparison fd = (FunctionDefinitionComparison) StdFunctions.FD_DATETIME_GREATER_THAN_OR_EQUAL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DATETIME_GREATER_THAN_OR_EQUAL, fd.getId()); + assertEquals(DataTypes.DT_DATETIME.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // first == second + arguments.add(attrDateTimeToday); + arguments.add(attrDateTimeSameDay); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // first < second + arguments.clear(); + arguments.add(attrDateTimeToday); + arguments.add(attrDateTimeTommorrow); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first > second + arguments.clear(); + arguments.add(attrDateTimeToday); + arguments.add(attrDateTimeYesterday); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + } + + @Test + public void testDateTime_LT() { + + FunctionDefinitionComparison fd = (FunctionDefinitionComparison) StdFunctions.FD_DATETIME_LESS_THAN; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DATETIME_LESS_THAN, fd.getId()); + assertEquals(DataTypes.DT_DATETIME.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // first == second + arguments.add(attrDateTimeToday); + arguments.add(attrDateTimeSameDay); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first < second + arguments.clear(); + arguments.add(attrDateTimeToday); + arguments.add(attrDateTimeTommorrow); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // first > second + arguments.clear(); + arguments.add(attrDateTimeToday); + arguments.add(attrDateTimeYesterday); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + } + + @Test + public void testDateTime_LTE() { + + FunctionDefinitionComparison fd = (FunctionDefinitionComparison) StdFunctions.FD_DATETIME_LESS_THAN_OR_EQUAL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DATETIME_LESS_THAN_OR_EQUAL, fd.getId()); + assertEquals(DataTypes.DT_DATETIME.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // first == second + arguments.add(attrDateTimeToday); + arguments.add(attrDateTimeSameDay); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // first < second + arguments.clear(); + arguments.add(attrDateTimeToday); + arguments.add(attrDateTimeTommorrow); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // first > second + arguments.clear(); + arguments.add(attrDateTimeToday); + arguments.add(attrDateTimeYesterday); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + } + + + +} diff --git a/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionDateTimeArithmeticTest.java b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionDateTimeArithmeticTest.java new file mode 100644 index 000000000..af3d7afa8 --- /dev/null +++ b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionDateTimeArithmeticTest.java @@ -0,0 +1,1602 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +import com.att.research.xacml.api.XACML3; +import com.att.research.xacml.std.datatypes.DataTypes; +import com.att.research.xacml.std.datatypes.ISO8601Date; +import com.att.research.xacml.std.datatypes.ISO8601DateTime; +import com.att.research.xacml.std.datatypes.ISO8601Time; +import com.att.research.xacml.std.datatypes.ISO8601TimeZone; +import com.att.research.xacml.std.datatypes.XPathDayTimeDuration; +import com.att.research.xacml.std.datatypes.XPathYearMonthDuration; +import com.att.research.xacmlatt.pdp.policy.ExpressionResult; +import com.att.research.xacmlatt.pdp.policy.FunctionArgument; +import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; +import com.att.research.xacmlatt.pdp.std.StdFunctions; +import com.att.research.xacmlatt.pdp.std.functions.*; + +/** + * Test of PDP Functions (See XACML core spec section A.3) + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * + */ +public class FunctionDefinitionDateTimeArithmeticTest { + + + /* + * variables useful in the following tests + */ + List arguments = new ArrayList(); + + ExpressionResult res; + + + @Test + public void testDateTime_add_dayTimeDuration() { + // Date objects to be adjusted + ISO8601DateTime dateTimeStdExample1 = new ISO8601DateTime(null, + new ISO8601Date(2000, 1, 12), + new ISO8601Time(12, 13, 14, 0)); + ISO8601DateTime dateTimeMsecs = new ISO8601DateTime(null, + new ISO8601Date(2000, 1, 12), + new ISO8601Time(12, 13, 14, 777)); + ISO8601DateTime dateTimeCrossover = new ISO8601DateTime(null, + new ISO8601Date(2000, 12, 31), + new ISO8601Time(23, 59, 30, 1)); + ISO8601DateTime dateTimeBC = new ISO8601DateTime(null, + new ISO8601Date(-2000, 1, 12), + new ISO8601Time(12, 13, 14, 0)); + ISO8601TimeZone timeZone0 = new ISO8601TimeZone(0); + ISO8601TimeZone timeZone5 = new ISO8601TimeZone(5 * 60); + ISO8601DateTime dateTimeTimeZone0 = new ISO8601DateTime(timeZone0, + new ISO8601Date(timeZone0, 2000, 1, 12), + new ISO8601Time(timeZone0, 12, 13, 14, 0)); + ISO8601DateTime dateTimeTimeZone5 = new ISO8601DateTime(timeZone5, + new ISO8601Date(timeZone5, 2000, 1, 12), + new ISO8601Time(timeZone5, 12, 13, 14, 0)); + ISO8601DateTime dateTimeIIC102Result = null; + + // Durations + XPathDayTimeDuration duration0 = new XPathDayTimeDuration(1, 0, 0, 0, 0); + XPathDayTimeDuration durationStdExample1 = new XPathDayTimeDuration(1, 5, 7, 10, 3.3); + XPathDayTimeDuration durationNStdExample1 = new XPathDayTimeDuration(-1, 5, 7, 10, 3.3); + XPathDayTimeDuration durationMsecs = new XPathDayTimeDuration(1, 5, 7, 10, 3.223); + XPathDayTimeDuration durationCrossover = new XPathDayTimeDuration(1, 0, 0, 0, 29.999); + + // ARGS declarations + // Dates + FunctionArgumentAttributeValue attrDateTimeStdExample1 = null; + FunctionArgumentAttributeValue attrDateTimeMsecs = null; + FunctionArgumentAttributeValue attrDateTimeCrossover = null; + FunctionArgumentAttributeValue attrDateTimeBC = null; + FunctionArgumentAttributeValue attrDateTimeTimeZone0 = null; + FunctionArgumentAttributeValue attrDateTimeTimeZone5 = null; + FunctionArgumentAttributeValue attrDateTimeIIC102 = null; + + // Durations + FunctionArgumentAttributeValue attrDuration0 = null; + FunctionArgumentAttributeValue attrDurationStdExample1 = null; + FunctionArgumentAttributeValue attrDurationNStdExample1 = null; + FunctionArgumentAttributeValue attrDurationMsecs = null; + FunctionArgumentAttributeValue attrDurationCrossover = null; + FunctionArgumentAttributeValue attrDurationIIC102 = null; + + // misc bad + FunctionArgumentAttributeValue attrNull = null; + FunctionArgumentAttributeValue attrBlank = null; + FunctionArgumentAttributeValue attrInteger = null; + // set values + try { + // Date attrs + attrDateTimeStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeStdExample1)); + attrDateTimeMsecs = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeMsecs)); + attrDateTimeCrossover = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeCrossover)); + attrDateTimeBC = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeBC)); + attrDateTimeTimeZone0 = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeTimeZone0)); + attrDateTimeTimeZone5 = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeTimeZone5)); + attrDateTimeIIC102 = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(DataTypes.DT_DATETIME.convert("2002-03-22T08:23:47-05:00"))); + + dateTimeIIC102Result = DataTypes.DT_DATETIME.convert("2002-03-27T10:23:47-05:00"); + + // Duration attrs + attrDuration0 = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(duration0)); + attrDurationStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(durationStdExample1)); + attrDurationNStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(durationNStdExample1)); + attrDurationMsecs = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(durationMsecs)); + attrDurationCrossover = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(durationCrossover)); + attrDurationIIC102 = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue("P5DT2H0M0S")); + + // misc bad + attrBlank = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue("")); + attrNull = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(null)); + attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234)); + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + FunctionDefinitionDateTimeArithmetic fd = (FunctionDefinitionDateTimeArithmetic) StdFunctions.FD_DATETIME_ADD_DAYTIMEDURATION; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DATETIME_ADD_DAYTIMEDURATION, fd.getId()); + assertEquals(DataTypes.DT_DATETIME.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + // Duration = 0 => same as original + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrDuration0); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + ISO8601DateTime resValue = (ISO8601DateTime)res.getValue().getValue(); + assertEquals(dateTimeStdExample1, resValue); + + + // simple positive operation + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + ISO8601DateTime testResponse = new ISO8601DateTime( + null, + new ISO8601Date(2000, 1, 17), + new ISO8601Time(19, 23, 17, 300) ); + assertEquals(testResponse, resValue); + + // negative operation + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrDurationNStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + testResponse = new ISO8601DateTime( + null, + new ISO8601Date(2000, 1, 7), + new ISO8601Time(5, 3, 10, 700) ); + assertEquals(testResponse, resValue); + + // millisecs work correctly + arguments.clear(); + arguments.add(attrDateTimeMsecs); + arguments.add(attrDurationMsecs); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + testResponse = new ISO8601DateTime( + null, + new ISO8601Date(2000, 1, 17), + new ISO8601Time(19, 23, 18, 0) ); + assertEquals(testResponse, resValue); + + // cross minute => cross day => cross month => cross year + arguments.clear(); + arguments.add(attrDateTimeCrossover); + arguments.add(attrDurationCrossover); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + testResponse = new ISO8601DateTime( + null, + new ISO8601Date(2001, 1, 1), + new ISO8601Time(0, 0, 0, 0) ); + assertEquals(testResponse, resValue); + + // negative (BC) original date add goes the right direction + arguments.clear(); + arguments.add(attrDateTimeBC); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + testResponse = new ISO8601DateTime( + null, + new ISO8601Date(-2000, 1, 17), + new ISO8601Time(19, 23, 17, 300) ); + assertEquals(testResponse, resValue); + + // non-null timezone not changed + // original has timezone offset = 0 + arguments.clear(); + arguments.add(attrDateTimeTimeZone0); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + testResponse = new ISO8601DateTime( + timeZone0, + new ISO8601Date(timeZone0, 2000, 1, 17), + new ISO8601Time(timeZone0, 19, 23, 17, 300) ); + assertEquals(testResponse, resValue); + + // original has timezone offset not 0 + arguments.clear(); + arguments.add(attrDateTimeTimeZone5); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + testResponse = new ISO8601DateTime( + timeZone5, + new ISO8601Date(timeZone5, 2000, 1, 17), + new ISO8601Time(timeZone5, 19, 23, 17, 300) ); + assertEquals(testResponse, resValue); + + // conformance test IIC102 + arguments.clear(); + arguments.add(attrDateTimeIIC102); + arguments.add(attrDurationIIC102); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + assertEquals(dateTimeIIC102Result, resValue); + + // empty non-null first arg + arguments.clear(); + arguments.add(attrBlank); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-add-dayTimeDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // empty non-null second arg + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-add-dayTimeDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // two blanks + arguments.clear(); + arguments.add(attrBlank); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-add-dayTimeDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null firat arg + arguments.clear(); + arguments.add(attrNull); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-add-dayTimeDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null second arg + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrNull); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-add-dayTimeDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrInteger); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-add-dayTimeDuration Expected data type 'dateTime' saw 'integer'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null second arg + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrNull); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-add-dayTimeDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + + + @Test + public void testDateTime_subtract_dayTimeDuration() { + // Date objects to be adjusted + ISO8601DateTime dateTimeStdExample1 = new ISO8601DateTime(null, + new ISO8601Date(2000, 1, 12), + new ISO8601Time(12, 13, 14, 0)); + ISO8601DateTime dateTimeMsecs = new ISO8601DateTime(null, + new ISO8601Date(2000, 1, 12), + new ISO8601Time(12, 13, 14, 777)); + ISO8601DateTime dateTimeCrossover = new ISO8601DateTime(null, + new ISO8601Date(2001, 1, 1), + new ISO8601Time(0, 0, 0, 0) ); + ISO8601DateTime dateTimeBC = new ISO8601DateTime(null, + new ISO8601Date(-2000, 1, 12), + new ISO8601Time(12, 13, 14, 0)); + ISO8601TimeZone timeZone0 = new ISO8601TimeZone(0); + ISO8601TimeZone timeZone5 = new ISO8601TimeZone(5 * 60); + ISO8601DateTime dateTimeTimeZone0 = new ISO8601DateTime(timeZone0, + new ISO8601Date(timeZone0, 2000, 1, 12), + new ISO8601Time(timeZone0, 12, 13, 14, 0)); + ISO8601DateTime dateTimeTimeZone5 = new ISO8601DateTime(timeZone5, + new ISO8601Date(timeZone5, 2000, 1, 12), + new ISO8601Time(timeZone5, 12, 13, 14, 0)); + + // Durations + XPathDayTimeDuration duration0 = new XPathDayTimeDuration(1, 0, 0, 0, 0); + XPathDayTimeDuration durationStdExample1 = new XPathDayTimeDuration(1, 5, 7, 10, 3.3); + XPathDayTimeDuration durationNStdExample1 = new XPathDayTimeDuration(-1, 5, 7, 10, 3.3); + XPathDayTimeDuration durationMsecs = new XPathDayTimeDuration(1, 5, 7, 10, 14.778); + XPathDayTimeDuration durationCrossover = new XPathDayTimeDuration(1, 0, 0, 0, 29.999); + + // ARGS declarations + // Dates + FunctionArgumentAttributeValue attrDateTimeStdExample1 = null; + FunctionArgumentAttributeValue attrDateTimeMsecs = null; + FunctionArgumentAttributeValue attrDateTimeCrossover = null; + FunctionArgumentAttributeValue attrDateTimeBC = null; + FunctionArgumentAttributeValue attrDateTimeTimeZone0 = null; + FunctionArgumentAttributeValue attrDateTimeTimeZone5 = null; + + // Durations + FunctionArgumentAttributeValue attrDuration0 = null; + FunctionArgumentAttributeValue attrDurationStdExample1 = null; + FunctionArgumentAttributeValue attrDurationNStdExample1 = null; + FunctionArgumentAttributeValue attrDurationMsecs = null; + FunctionArgumentAttributeValue attrDurationCrossover = null; + + // misc bad + FunctionArgumentAttributeValue attrNull = null; + FunctionArgumentAttributeValue attrBlank = null; + FunctionArgumentAttributeValue attrInteger = null; + // set values + try { + // Date attrs + attrDateTimeStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeStdExample1)); + attrDateTimeMsecs = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeMsecs)); + attrDateTimeCrossover = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeCrossover)); + attrDateTimeBC = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeBC)); + attrDateTimeTimeZone0 = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeTimeZone0)); + attrDateTimeTimeZone5 = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeTimeZone5)); + + // Duration attrs + attrDuration0 = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(duration0)); + attrDurationStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(durationStdExample1)); + attrDurationNStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(durationNStdExample1)); + attrDurationMsecs = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(durationMsecs)); + attrDurationCrossover = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(durationCrossover)); + + // misc bad + attrBlank = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue("")); + attrNull = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(null)); + attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234)); + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + FunctionDefinitionDateTimeArithmetic fd = (FunctionDefinitionDateTimeArithmetic) StdFunctions.FD_DATETIME_SUBTRACT_DAYTIMEDURATION; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DATETIME_SUBTRACT_DAYTIMEDURATION, fd.getId()); + assertEquals(DataTypes.DT_DATETIME.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + // Duration = 0 => same as original + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrDuration0); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + ISO8601DateTime resValue = (ISO8601DateTime)res.getValue().getValue(); + assertEquals(dateTimeStdExample1, resValue); + + + // simple positive operation + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + ISO8601DateTime testResponse = new ISO8601DateTime( + null, + new ISO8601Date(2000, 1, 7), + new ISO8601Time(5, 3, 10, 700) ); + assertEquals(testResponse, resValue); + + + // negative operation + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrDurationNStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + testResponse = new ISO8601DateTime( + null, + new ISO8601Date(2000, 1, 17), + new ISO8601Time(19, 23, 17, 300) ); + assertEquals(testResponse, resValue); + + // millisecs work correctly + arguments.clear(); + arguments.add(attrDateTimeMsecs); + arguments.add(attrDurationMsecs); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + testResponse = new ISO8601DateTime( + null, + new ISO8601Date(2000, 1, 7), + new ISO8601Time(5, 2, 59, 999) ); + assertEquals(testResponse, resValue); + + // cross minute => cross day => cross month => cross year + arguments.clear(); + arguments.add(attrDateTimeCrossover); + arguments.add(attrDurationCrossover); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + testResponse = new ISO8601DateTime( + null, + new ISO8601Date(2000, 12, 31), + new ISO8601Time(23, 59, 30, 1)); + assertEquals(testResponse, resValue); + + // negative (BC) original date add goes the right direction + arguments.clear(); + arguments.add(attrDateTimeBC); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + testResponse = new ISO8601DateTime( + null, + new ISO8601Date(-2000, 1, 7), + new ISO8601Time(5, 3, 10, 700) ); + assertEquals(testResponse, resValue); + + // non-null timezone not changed + // original has timezone offset = 0 + arguments.clear(); + arguments.add(attrDateTimeTimeZone0); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + testResponse = new ISO8601DateTime( + timeZone0, + new ISO8601Date(timeZone0, 2000, 1, 7), + new ISO8601Time(timeZone0, 5, 3, 10, 700) ); + assertEquals(testResponse, resValue); + + // original has timezone offset not 0 + arguments.clear(); + arguments.add(attrDateTimeTimeZone5); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + testResponse = new ISO8601DateTime( + timeZone5, + new ISO8601Date(timeZone5, 2000, 1, 7), + new ISO8601Time(timeZone5, 5, 3, 10, 700) ); + assertEquals(testResponse, resValue); + + // empty non-null first arg + arguments.clear(); + arguments.add(attrBlank); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-subtract-dayTimeDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // empty non-null second arg + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-subtract-dayTimeDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // two blanks + arguments.clear(); + arguments.add(attrBlank); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-subtract-dayTimeDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null firat arg + arguments.clear(); + arguments.add(attrNull); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-subtract-dayTimeDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null second arg + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrNull); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-subtract-dayTimeDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrInteger); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-subtract-dayTimeDuration Expected data type 'dateTime' saw 'integer'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null second arg + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrNull); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-subtract-dayTimeDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + + + + + + + + + @Test + public void testDateTime_add_yearMonthDuration() { + // Date objects to be adjusted + ISO8601DateTime dateTimeStdExample1 = new ISO8601DateTime(null, + new ISO8601Date(2000, 1, 12), + new ISO8601Time(12, 13, 14, 0)); + ISO8601DateTime dateTimeMsecs = new ISO8601DateTime(null, + new ISO8601Date(2000, 1, 12), + new ISO8601Time(12, 13, 14, 777)); + ISO8601DateTime dateTimeCrossover = new ISO8601DateTime(null, + new ISO8601Date(2000, 12, 31), + new ISO8601Time(23, 59, 30, 1)); + ISO8601DateTime dateTimeBC = new ISO8601DateTime(null, + new ISO8601Date(-2000, 1, 12), + new ISO8601Time(12, 13, 14, 0)); + ISO8601TimeZone timeZone0 = new ISO8601TimeZone(0); + ISO8601TimeZone timeZone5 = new ISO8601TimeZone(5 * 60); + ISO8601DateTime dateTimeTimeZone0 = new ISO8601DateTime(timeZone0, + new ISO8601Date(timeZone0, 2000, 1, 12), + new ISO8601Time(timeZone0, 12, 13, 14, 0)); + ISO8601DateTime dateTimeTimeZone5 = new ISO8601DateTime(timeZone5, + new ISO8601Date(timeZone5, 2000, 1, 12), + new ISO8601Time(timeZone5, 12, 13, 14, 0)); + + // Durations + XPathYearMonthDuration duration0 = new XPathYearMonthDuration(1, 0, 0); + XPathYearMonthDuration durationStdExample1 = new XPathYearMonthDuration(1, 5, 7); + XPathYearMonthDuration durationNStdExample1 = new XPathYearMonthDuration(-1, 5, 7); + XPathYearMonthDuration durationMsecs = new XPathYearMonthDuration(1, 5, 7); + XPathYearMonthDuration durationCrossover = new XPathYearMonthDuration(1, 0, 1); + + // ARGS declarations + // Dates + FunctionArgumentAttributeValue attrDateTimeStdExample1 = null; + FunctionArgumentAttributeValue attrDateTimeMsecs = null; + FunctionArgumentAttributeValue attrDateTimeCrossover = null; + FunctionArgumentAttributeValue attrDateTimeBC = null; + FunctionArgumentAttributeValue attrDateTimeTimeZone0 = null; + FunctionArgumentAttributeValue attrDateTimeTimeZone5 = null; + + // Durations + FunctionArgumentAttributeValue attrDuration0 = null; + FunctionArgumentAttributeValue attrDurationStdExample1 = null; + FunctionArgumentAttributeValue attrDurationNStdExample1 = null; + FunctionArgumentAttributeValue attrDurationMsecs = null; + FunctionArgumentAttributeValue attrDurationCrossover = null; + + // misc bad + FunctionArgumentAttributeValue attrNull = null; + FunctionArgumentAttributeValue attrBlank = null; + FunctionArgumentAttributeValue attrInteger = null; + // set values + try { + // Date attrs + attrDateTimeStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeStdExample1)); + attrDateTimeMsecs = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeMsecs)); + attrDateTimeCrossover = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeCrossover)); + attrDateTimeBC = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeBC)); + attrDateTimeTimeZone0 = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeTimeZone0)); + attrDateTimeTimeZone5 = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeTimeZone5)); + + // Duration attrs + attrDuration0 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(duration0)); + attrDurationStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(durationStdExample1)); + attrDurationNStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(durationNStdExample1)); + attrDurationMsecs = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(durationMsecs)); + attrDurationCrossover = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(durationCrossover)); + + // misc bad + attrBlank = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue("")); + attrNull = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(null)); + attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234)); + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + FunctionDefinitionDateTimeArithmetic fd = (FunctionDefinitionDateTimeArithmetic) StdFunctions.FD_DATETIME_ADD_YEARMONTHDURATION; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DATETIME_ADD_YEARMONTHDURATION, fd.getId()); + assertEquals(DataTypes.DT_DATETIME.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + // Duration = 0 => same as original + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrDuration0); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + ISO8601DateTime resValue = (ISO8601DateTime)res.getValue().getValue(); + assertEquals(dateTimeStdExample1, resValue); + + + // simple positive operation + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + ISO8601DateTime testResponse = new ISO8601DateTime( + null, + new ISO8601Date(2005, 8, 12), + new ISO8601Time(12, 13, 14, 0) ); + assertEquals(testResponse, resValue); + + // negative operation + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrDurationNStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + testResponse = new ISO8601DateTime( + null, + new ISO8601Date(1994, 6, 12), + new ISO8601Time(12, 13, 14, 0) ); + assertEquals(testResponse, resValue); + + // millisecs work correctly (not relevant to YearMonth, but should not break + arguments.clear(); + arguments.add(attrDateTimeMsecs); + arguments.add(attrDurationMsecs); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + testResponse = new ISO8601DateTime( + null, + new ISO8601Date(2005, 8, 12), + new ISO8601Time(12, 13, 14, 777) ); + assertEquals(testResponse, resValue); + + // cross minute => cross day => cross month => cross year + arguments.clear(); + arguments.add(attrDateTimeCrossover); + arguments.add(attrDurationCrossover); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + testResponse = new ISO8601DateTime( + null, + new ISO8601Date(2001, 1, 31), + new ISO8601Time(23, 59, 30, 1) ); + assertEquals(testResponse, resValue); + + // negative (BC) original date add goes the right direction + arguments.clear(); + arguments.add(attrDateTimeBC); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + testResponse = new ISO8601DateTime( + null, + new ISO8601Date(-1995, 8, 12), + new ISO8601Time(12, 13, 14, 0) ); + assertEquals(testResponse, resValue); + + // non-null timezone not changed + // original has timezone offset = 0 + arguments.clear(); + arguments.add(attrDateTimeTimeZone0); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + testResponse = new ISO8601DateTime( + timeZone0, + new ISO8601Date(timeZone0, 2005, 8, 12), + new ISO8601Time(timeZone0, 12, 13, 14, 0) ); + assertEquals(testResponse, resValue); + + // original has timezone offset not 0 + arguments.clear(); + arguments.add(attrDateTimeTimeZone5); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + testResponse = new ISO8601DateTime( + timeZone5, + new ISO8601Date(timeZone5, 2005, 8, 12), + new ISO8601Time(timeZone5, 12, 13, 14, 0) ); + assertEquals(testResponse, resValue); + + // empty non-null first arg + arguments.clear(); + arguments.add(attrBlank); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-add-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // empty non-null second arg + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-add-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // two blanks + arguments.clear(); + arguments.add(attrBlank); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-add-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null firat arg + arguments.clear(); + arguments.add(attrNull); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-add-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null second arg + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrNull); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-add-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrInteger); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-add-yearMonthDuration Expected data type 'dateTime' saw 'integer'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null second arg + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrNull); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-add-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + + + + @Test + public void testDateTime_subtract_yearMonthDuration() { + // Date objects to be adjusted + ISO8601DateTime dateTimeStdExample1 = new ISO8601DateTime(null, + new ISO8601Date(2000, 1, 12), + new ISO8601Time(12, 13, 14, 0)); + ISO8601DateTime dateTimeMsecs = new ISO8601DateTime(null, + new ISO8601Date(2000, 1, 12), + new ISO8601Time(12, 13, 14, 777)); + ISO8601DateTime dateTimeCrossover = new ISO8601DateTime(null, + new ISO8601Date(2000, 1, 1), + new ISO8601Time(23, 59, 30, 1)); + ISO8601DateTime dateTimeBC = new ISO8601DateTime(null, + new ISO8601Date(-2000, 1, 12), + new ISO8601Time(12, 13, 14, 0)); + ISO8601TimeZone timeZone0 = new ISO8601TimeZone(0); + ISO8601TimeZone timeZone5 = new ISO8601TimeZone(5 * 60); + ISO8601DateTime dateTimeTimeZone0 = new ISO8601DateTime(timeZone0, + new ISO8601Date(timeZone0, 2000, 1, 12), + new ISO8601Time(timeZone0, 12, 13, 14, 0)); + ISO8601DateTime dateTimeTimeZone5 = new ISO8601DateTime(timeZone5, + new ISO8601Date(timeZone5, 2000, 1, 12), + new ISO8601Time(timeZone5, 12, 13, 14, 0)); + + // Durations + XPathYearMonthDuration duration0 = new XPathYearMonthDuration(1, 0, 0); + XPathYearMonthDuration durationStdExample1 = new XPathYearMonthDuration(1, 5, 7); + XPathYearMonthDuration durationNStdExample1 = new XPathYearMonthDuration(-1, 5, 7); + XPathYearMonthDuration durationMsecs = new XPathYearMonthDuration(1, 5, 7); + XPathYearMonthDuration durationCrossover = new XPathYearMonthDuration(1, 0, 1); + + // ARGS declarations + // Dates + FunctionArgumentAttributeValue attrDateTimeStdExample1 = null; + FunctionArgumentAttributeValue attrDateTimeMsecs = null; + FunctionArgumentAttributeValue attrDateTimeCrossover = null; + FunctionArgumentAttributeValue attrDateTimeBC = null; + FunctionArgumentAttributeValue attrDateTimeTimeZone0 = null; + FunctionArgumentAttributeValue attrDateTimeTimeZone5 = null; + + // Durations + FunctionArgumentAttributeValue attrDuration0 = null; + FunctionArgumentAttributeValue attrDurationStdExample1 = null; + FunctionArgumentAttributeValue attrDurationNStdExample1 = null; + FunctionArgumentAttributeValue attrDurationMsecs = null; + FunctionArgumentAttributeValue attrDurationCrossover = null; + + // misc bad + FunctionArgumentAttributeValue attrNull = null; + FunctionArgumentAttributeValue attrBlank = null; + FunctionArgumentAttributeValue attrInteger = null; + // set values + try { + // Date attrs + attrDateTimeStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeStdExample1)); + attrDateTimeMsecs = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeMsecs)); + attrDateTimeCrossover = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeCrossover)); + attrDateTimeBC = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeBC)); + attrDateTimeTimeZone0 = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeTimeZone0)); + attrDateTimeTimeZone5 = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeTimeZone5)); + + // Duration attrs + attrDuration0 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(duration0)); + attrDurationStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(durationStdExample1)); + attrDurationNStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(durationNStdExample1)); + attrDurationMsecs = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(durationMsecs)); + attrDurationCrossover = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(durationCrossover)); + + // misc bad + attrBlank = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue("")); + attrNull = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(null)); + attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234)); + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + FunctionDefinitionDateTimeArithmetic fd = (FunctionDefinitionDateTimeArithmetic) StdFunctions.FD_DATETIME_SUBTRACT_YEARMONTHDURATION; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DATETIME_SUBTRACT_YEARMONTHDURATION, fd.getId()); + assertEquals(DataTypes.DT_DATETIME.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + // Duration = 0 => same as original + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrDuration0); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + ISO8601DateTime resValue = (ISO8601DateTime)res.getValue().getValue(); + assertEquals(dateTimeStdExample1, resValue); + + + // simple positive operation + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + ISO8601DateTime testResponse = new ISO8601DateTime( + null, + new ISO8601Date(1994, 6, 12), + new ISO8601Time(12, 13, 14, 0) ); + assertEquals(testResponse, resValue); + + // negative operation + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrDurationNStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + testResponse = new ISO8601DateTime( + null, + new ISO8601Date(2005, 8, 12), + new ISO8601Time(12, 13, 14, 0) ); + assertEquals(testResponse, resValue); + + // millisecs work correctly (not relevant to YearMonth, but should not break + arguments.clear(); + arguments.add(attrDateTimeMsecs); + arguments.add(attrDurationMsecs); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + testResponse = new ISO8601DateTime( + null, + new ISO8601Date(1994, 6, 12), + new ISO8601Time(12, 13, 14, 777) ); + assertEquals(testResponse, resValue); + + // cross minute => cross day => cross month => cross year + arguments.clear(); + arguments.add(attrDateTimeCrossover); + arguments.add(attrDurationCrossover); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + testResponse = new ISO8601DateTime( + null, + new ISO8601Date(1999, 12, 1), + new ISO8601Time(23, 59, 30, 1) ); + assertEquals(testResponse, resValue); + + // negative (BC) original date add goes the right direction + arguments.clear(); + arguments.add(attrDateTimeBC); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + testResponse = new ISO8601DateTime( + null, + new ISO8601Date(-2006, 6, 12), + new ISO8601Time(12, 13, 14, 0) ); + assertEquals(testResponse, resValue); + + // non-null timezone not changed + // original has timezone offset = 0 + arguments.clear(); + arguments.add(attrDateTimeTimeZone0); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + testResponse = new ISO8601DateTime( + timeZone0, + new ISO8601Date(timeZone0, 1994, 6, 12), + new ISO8601Time(timeZone0, 12, 13, 14, 0) ); + assertEquals(testResponse, resValue); + + // original has timezone offset not 0 + arguments.clear(); + arguments.add(attrDateTimeTimeZone5); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + testResponse = new ISO8601DateTime( + timeZone5, + new ISO8601Date(timeZone5, 1994, 6, 12), + new ISO8601Time(timeZone5, 12, 13, 14, 0) ); + assertEquals(testResponse, resValue); + + // empty non-null first arg + arguments.clear(); + arguments.add(attrBlank); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-subtract-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // empty non-null second arg + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-subtract-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // two blanks + arguments.clear(); + arguments.add(attrBlank); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-subtract-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null firat arg + arguments.clear(); + arguments.add(attrNull); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-subtract-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null second arg + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrNull); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-subtract-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrInteger); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-subtract-yearMonthDuration Expected data type 'dateTime' saw 'integer'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null second arg + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrNull); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-subtract-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + + + + + + + + + + + @Test + public void testDate_add_yearMonthDuration() { + // Date objects to be adjusted + ISO8601Date dateTimeStdExample1 = new ISO8601Date(2000, 1, 12); + ISO8601Date dateTimeMsecs =new ISO8601Date(2000, 1, 12); + ISO8601Date dateTimeCrossover = new ISO8601Date(2000, 12, 31); + ISO8601Date dateTimeBC = new ISO8601Date(-2000, 1, 12); + ISO8601TimeZone timeZone0 = new ISO8601TimeZone(0); + ISO8601TimeZone timeZone5 = new ISO8601TimeZone(5 * 60); + ISO8601Date dateTimeTimeZone0 = new ISO8601Date(timeZone0, 2000, 1, 12); + ISO8601Date dateTimeTimeZone5 = new ISO8601Date(timeZone5, 2000, 1, 12); + + // Durations + XPathYearMonthDuration duration0 = new XPathYearMonthDuration(1, 0, 0); + XPathYearMonthDuration durationStdExample1 = new XPathYearMonthDuration(1, 5, 7); + XPathYearMonthDuration durationNStdExample1 = new XPathYearMonthDuration(-1, 5, 7); + XPathYearMonthDuration durationMsecs = new XPathYearMonthDuration(1, 5, 7); + XPathYearMonthDuration durationCrossover = new XPathYearMonthDuration(1, 0, 1); + + // ARGS declarations + // Dates + FunctionArgumentAttributeValue attrDateTimeStdExample1 = null; + FunctionArgumentAttributeValue attrDateTimeMsecs = null; + FunctionArgumentAttributeValue attrDateTimeCrossover = null; + FunctionArgumentAttributeValue attrDateTimeBC = null; + FunctionArgumentAttributeValue attrDateTimeTimeZone0 = null; + FunctionArgumentAttributeValue attrDateTimeTimeZone5 = null; + + // Durations + FunctionArgumentAttributeValue attrDuration0 = null; + FunctionArgumentAttributeValue attrDurationStdExample1 = null; + FunctionArgumentAttributeValue attrDurationNStdExample1 = null; + FunctionArgumentAttributeValue attrDurationMsecs = null; + FunctionArgumentAttributeValue attrDurationCrossover = null; + + // misc bad + FunctionArgumentAttributeValue attrNull = null; + FunctionArgumentAttributeValue attrBlank = null; + FunctionArgumentAttributeValue attrInteger = null; + // set values + try { + // Date attrs + attrDateTimeStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(dateTimeStdExample1)); + attrDateTimeMsecs = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(dateTimeMsecs)); + attrDateTimeCrossover = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(dateTimeCrossover)); + attrDateTimeBC = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(dateTimeBC)); + attrDateTimeTimeZone0 = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(dateTimeTimeZone0)); + attrDateTimeTimeZone5 = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(dateTimeTimeZone5)); + + // Duration attrs + attrDuration0 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(duration0)); + attrDurationStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(durationStdExample1)); + attrDurationNStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(durationNStdExample1)); + attrDurationMsecs = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(durationMsecs)); + attrDurationCrossover = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(durationCrossover)); + + // misc bad + attrBlank = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue("")); + attrNull = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(null)); + attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234)); + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + FunctionDefinitionDateTimeArithmetic fd = (FunctionDefinitionDateTimeArithmetic) StdFunctions.FD_DATE_ADD_YEARMONTHDURATION; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DATE_ADD_YEARMONTHDURATION, fd.getId()); + assertEquals(DataTypes.DT_DATE.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + // Duration = 0 => same as original + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrDuration0); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601Date.class, res.getValue().getValue().getClass()); + ISO8601Date resValue = (ISO8601Date)res.getValue().getValue(); + assertEquals(dateTimeStdExample1, resValue); + + + // simple positive operation + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601Date.class, res.getValue().getValue().getClass()); + resValue = (ISO8601Date)res.getValue().getValue(); + ISO8601Date testResponse = new ISO8601Date(2005, 8, 12); + assertEquals(testResponse, resValue); + + // negative operation + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrDurationNStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601Date.class, res.getValue().getValue().getClass()); + resValue = (ISO8601Date)res.getValue().getValue(); + testResponse = new ISO8601Date(1994, 6, 12); + assertEquals(testResponse, resValue); + + // millisecs work correctly (not relevant to YearMonth, but should not break + arguments.clear(); + arguments.add(attrDateTimeMsecs); + arguments.add(attrDurationMsecs); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601Date.class, res.getValue().getValue().getClass()); + resValue = (ISO8601Date)res.getValue().getValue(); + testResponse = new ISO8601Date(2005, 8, 12); + assertEquals(testResponse, resValue); + + // cross minute => cross day => cross month => cross year + arguments.clear(); + arguments.add(attrDateTimeCrossover); + arguments.add(attrDurationCrossover); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601Date.class, res.getValue().getValue().getClass()); + resValue = (ISO8601Date)res.getValue().getValue(); + testResponse = new ISO8601Date(2001, 1, 31); + assertEquals(testResponse, resValue); + + // negative (BC) original date add goes the right direction + arguments.clear(); + arguments.add(attrDateTimeBC); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601Date.class, res.getValue().getValue().getClass()); + resValue = (ISO8601Date)res.getValue().getValue(); + testResponse = new ISO8601Date(-1995, 8, 12); + assertEquals(testResponse, resValue); + + // non-null timezone not changed + // original has timezone offset = 0 + arguments.clear(); + arguments.add(attrDateTimeTimeZone0); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601Date.class, res.getValue().getValue().getClass()); + resValue = (ISO8601Date)res.getValue().getValue(); + testResponse = new ISO8601Date(timeZone0, 2005, 8, 12); + assertEquals(testResponse, resValue); + + // original has timezone offset not 0 + arguments.clear(); + arguments.add(attrDateTimeTimeZone5); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601Date.class, res.getValue().getValue().getClass()); + resValue = (ISO8601Date)res.getValue().getValue(); + testResponse = new ISO8601Date(timeZone5, 2005, 8, 12); + assertEquals(testResponse, resValue); + + // empty non-null first arg + arguments.clear(); + arguments.add(attrBlank); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:date-add-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // empty non-null second arg + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:date-add-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // two blanks + arguments.clear(); + arguments.add(attrBlank); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:date-add-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null firat arg + arguments.clear(); + arguments.add(attrNull); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:date-add-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null second arg + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrNull); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:date-add-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrInteger); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:date-add-yearMonthDuration Expected data type 'date' saw 'integer'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null second arg + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrNull); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:date-add-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + + + + + + @Test + public void testDate_subtract_yearMonthDuration() { + // Date objects to be adjusted + ISO8601Date dateTimeStdExample1 =new ISO8601Date(2000, 1, 12); + ISO8601Date dateTimeMsecs = new ISO8601Date(2000, 1, 12); + ISO8601Date dateTimeCrossover = new ISO8601Date(2000, 1, 1); + ISO8601Date dateTimeBC = new ISO8601Date(-2000, 1, 12); + ISO8601TimeZone timeZone0 = new ISO8601TimeZone(0); + ISO8601TimeZone timeZone5 = new ISO8601TimeZone(5 * 60); + ISO8601Date dateTimeTimeZone0 = new ISO8601Date(timeZone0, 2000, 1, 12); + ISO8601Date dateTimeTimeZone5 = new ISO8601Date(timeZone5, 2000, 1, 12); + + // Durations + XPathYearMonthDuration duration0 = new XPathYearMonthDuration(1, 0, 0); + XPathYearMonthDuration durationStdExample1 = new XPathYearMonthDuration(1, 5, 7); + XPathYearMonthDuration durationNStdExample1 = new XPathYearMonthDuration(-1, 5, 7); + XPathYearMonthDuration durationMsecs = new XPathYearMonthDuration(1, 5, 7); + XPathYearMonthDuration durationCrossover = new XPathYearMonthDuration(1, 0, 1); + + // ARGS declarations + // Dates + FunctionArgumentAttributeValue attrDateTimeStdExample1 = null; + FunctionArgumentAttributeValue attrDateTimeMsecs = null; + FunctionArgumentAttributeValue attrDateTimeCrossover = null; + FunctionArgumentAttributeValue attrDateTimeBC = null; + FunctionArgumentAttributeValue attrDateTimeTimeZone0 = null; + FunctionArgumentAttributeValue attrDateTimeTimeZone5 = null; + + // Durations + FunctionArgumentAttributeValue attrDuration0 = null; + FunctionArgumentAttributeValue attrDurationStdExample1 = null; + FunctionArgumentAttributeValue attrDurationNStdExample1 = null; + FunctionArgumentAttributeValue attrDurationMsecs = null; + FunctionArgumentAttributeValue attrDurationCrossover = null; + + // misc bad + FunctionArgumentAttributeValue attrNull = null; + FunctionArgumentAttributeValue attrBlank = null; + FunctionArgumentAttributeValue attrInteger = null; + // set values + try { + // Date attrs + attrDateTimeStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(dateTimeStdExample1)); + attrDateTimeMsecs = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(dateTimeMsecs)); + attrDateTimeCrossover = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(dateTimeCrossover)); + attrDateTimeBC = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(dateTimeBC)); + attrDateTimeTimeZone0 = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(dateTimeTimeZone0)); + attrDateTimeTimeZone5 = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(dateTimeTimeZone5)); + + // Duration attrs + attrDuration0 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(duration0)); + attrDurationStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(durationStdExample1)); + attrDurationNStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(durationNStdExample1)); + attrDurationMsecs = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(durationMsecs)); + attrDurationCrossover = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(durationCrossover)); + + // misc bad + attrBlank = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue("")); + attrNull = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(null)); + attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234)); + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + FunctionDefinitionDateTimeArithmetic fd = (FunctionDefinitionDateTimeArithmetic) StdFunctions.FD_DATE_SUBTRACT_YEARMONTHDURATION; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DATE_SUBTRACT_YEARMONTHDURATION, fd.getId()); + assertEquals(DataTypes.DT_DATE.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + // Duration = 0 => same as original + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrDuration0); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601Date.class, res.getValue().getValue().getClass()); + ISO8601Date resValue = (ISO8601Date)res.getValue().getValue(); + assertEquals(dateTimeStdExample1, resValue); + + + // simple positive operation + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601Date.class, res.getValue().getValue().getClass()); + resValue = (ISO8601Date)res.getValue().getValue(); + ISO8601Date testResponse = new ISO8601Date(1994, 6, 12); + assertEquals(testResponse, resValue); + + // negative operation + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrDurationNStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601Date.class, res.getValue().getValue().getClass()); + resValue = (ISO8601Date)res.getValue().getValue(); + testResponse = new ISO8601Date(2005, 8, 12); + assertEquals(testResponse, resValue); + + // millisecs work correctly (not relevant to YearMonth, but should not break + arguments.clear(); + arguments.add(attrDateTimeMsecs); + arguments.add(attrDurationMsecs); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601Date.class, res.getValue().getValue().getClass()); + resValue = (ISO8601Date)res.getValue().getValue(); + testResponse = new ISO8601Date(1994, 6, 12); + assertEquals(testResponse, resValue); + + // cross minute => cross day => cross month => cross year + arguments.clear(); + arguments.add(attrDateTimeCrossover); + arguments.add(attrDurationCrossover); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601Date.class, res.getValue().getValue().getClass()); + resValue = (ISO8601Date)res.getValue().getValue(); + testResponse = new ISO8601Date(1999, 12, 1); + assertEquals(testResponse, resValue); + + // negative (BC) original date add goes the right direction + arguments.clear(); + arguments.add(attrDateTimeBC); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601Date.class, res.getValue().getValue().getClass()); + resValue = (ISO8601Date)res.getValue().getValue(); + testResponse = new ISO8601Date(-2006, 6, 12); + assertEquals(testResponse, resValue); + + // non-null timezone not changed + // original has timezone offset = 0 + arguments.clear(); + arguments.add(attrDateTimeTimeZone0); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601Date.class, res.getValue().getValue().getClass()); + resValue = (ISO8601Date)res.getValue().getValue(); + testResponse = new ISO8601Date(timeZone0, 1994, 6, 12); + assertEquals(testResponse, resValue); + + // original has timezone offset not 0 + arguments.clear(); + arguments.add(attrDateTimeTimeZone5); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601Date.class, res.getValue().getValue().getClass()); + resValue = (ISO8601Date)res.getValue().getValue(); + testResponse = new ISO8601Date(timeZone5, 1994, 6, 12); + assertEquals(testResponse, resValue); + + // empty non-null first arg + arguments.clear(); + arguments.add(attrBlank); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:date-subtract-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // empty non-null second arg + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:date-subtract-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // two blanks + arguments.clear(); + arguments.add(attrBlank); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:date-subtract-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null firat arg + arguments.clear(); + arguments.add(attrNull); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:date-subtract-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null second arg + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrNull); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:date-subtract-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrInteger); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:date-subtract-yearMonthDuration Expected data type 'date' saw 'integer'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null second arg + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrNull); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:date-subtract-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + + +} diff --git a/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionEqualityTest.java b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionEqualityTest.java new file mode 100644 index 000000000..86bfcd5c4 --- /dev/null +++ b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionEqualityTest.java @@ -0,0 +1,1192 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.net.URI; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.List; + +import javax.security.auth.x500.X500Principal; + +import org.junit.Test; + +import com.att.research.xacml.api.XACML1; +import com.att.research.xacml.api.XACML3; +import com.att.research.xacml.std.datatypes.Base64Binary; +import com.att.research.xacml.std.datatypes.DataTypeRFC822Name; +import com.att.research.xacml.std.datatypes.DataTypes; +import com.att.research.xacml.std.datatypes.HexBinary; +import com.att.research.xacml.std.datatypes.RFC822Name; +import com.att.research.xacml.std.datatypes.XPathDayTimeDuration; +import com.att.research.xacml.std.datatypes.XPathYearMonthDuration; +import com.att.research.xacmlatt.pdp.policy.ExpressionResult; +import com.att.research.xacmlatt.pdp.policy.FunctionArgument; +import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; +import com.att.research.xacmlatt.pdp.std.StdFunctions; +import com.att.research.xacmlatt.pdp.std.functions.*; + +/** + * Test FunctionDefinitionEquality, all of its super-classes, and all XACML functions supported by that class. + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * In the first implementation of XACML we had separate files for each XACML Function. + * This release combines multiple Functions in fewer files to minimize code duplication. + * This file supports the following XACML codes: + * string-equal + * boolean-equal + * integer-equal + * double-equal + * date-equal + * time-equal + * dateTime-equal + * dayTimeDuration-equal + * yearMonthDuration-equal + * + * Each of these is put into a separate test method just to keep things organized. + * + * + */ +public class FunctionDefinitionEqualityTest { + + /* + * variables useful in the following tests + */ + List arguments = new ArrayList(); + + FunctionArgumentAttributeValue stringAttr1 = null; + FunctionArgumentAttributeValue stringAttr2 = null; + FunctionArgumentAttributeValue stringAttr3 = null; + FunctionArgumentAttributeValue stringAttr4 = null; + + FunctionArgumentAttributeValue booleanAttrT1 = null; + FunctionArgumentAttributeValue booleanAttrT2 = null; + FunctionArgumentAttributeValue booleanAttrF1 = null; + FunctionArgumentAttributeValue booleanAttrF2 = null; + + FunctionArgumentAttributeValue intAttr1 = null; + FunctionArgumentAttributeValue intAttr1a = null; + FunctionArgumentAttributeValue intAttr2 = null; + FunctionArgumentAttributeValue intAttr0 = null; + FunctionArgumentAttributeValue intAttrNeg1 = null; + + public FunctionDefinitionEqualityTest() { + try { + stringAttr1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("abc")); + stringAttr2 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("abc")); + stringAttr3 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("ABC")); + stringAttr4 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("def")); + + booleanAttrT1 = new FunctionArgumentAttributeValue(DataTypes.DT_BOOLEAN.createAttributeValue(true)); + booleanAttrT2 = new FunctionArgumentAttributeValue(DataTypes.DT_BOOLEAN.createAttributeValue(true)); + booleanAttrF1 = new FunctionArgumentAttributeValue(DataTypes.DT_BOOLEAN.createAttributeValue(false)); + booleanAttrF2 = new FunctionArgumentAttributeValue(DataTypes.DT_BOOLEAN.createAttributeValue(false)); + + intAttr1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1)); + intAttr1a = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1)); + intAttr2 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(2)); + intAttr0 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(0)); + intAttrNeg1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(-1)); + } catch (Exception e) { + fail("creating attribute e="+ e); + } + } + + + + + /** + * String (matching case) + */ + @Test + public void testString_Equal() { + + // String exact match + FunctionDefinitionEquality fd = (FunctionDefinitionEquality) StdFunctions.FD_STRING_EQUAL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_EQUAL, fd.getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // test normal equals and non-equals + // check "abc" with "abc" - separate string objects with same value + arguments.add(stringAttr1); + arguments.add(stringAttr2); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // check "abc" with "ABC" (not same) + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(stringAttr3); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // test bad args data types? Not needed? + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(intAttr1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + + } + + + + /** + * Boolean + */ + @Test + public void testBoolean_Equal() { + + // String exact match + FunctionDefinitionEquality fd = (FunctionDefinitionEquality) StdFunctions.FD_BOOLEAN_EQUAL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_BOOLEAN_EQUAL, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // test normal equals and non-equals + // check separate objects with same value + arguments.add(booleanAttrT1); + arguments.add(booleanAttrT2); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // check different values + arguments.clear(); + arguments.add(booleanAttrT1); + arguments.add(booleanAttrF1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // test bad args data types? Not needed? + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(intAttr1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + + } + + + /** + * Integer + */ + @Test + public void testInteger_Equal() { + + // String exact match + FunctionDefinitionEquality fd = (FunctionDefinitionEquality) StdFunctions.FD_INTEGER_EQUAL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_INTEGER_EQUAL, fd.getId()); + assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // test normal equals and non-equals + // check separate objects with same value + arguments.add(intAttr1); + arguments.add(intAttr1a); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // check not same + arguments.clear(); + arguments.add(intAttr1); + arguments.add(intAttr2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + arguments.clear(); + arguments.add(intAttr1); + arguments.add(intAttrNeg1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + + // test bad args data types? Not needed? + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(intAttr1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + + } + + + + /** + * Double + */ + @Test + public void testDouble_Equal() { + FunctionArgumentAttributeValue attr1 = null; + FunctionArgumentAttributeValue attr1a = null; + FunctionArgumentAttributeValue attr2 = null; + FunctionArgumentAttributeValue attrNeg1 = null; + try { + attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.0)); + attr1a = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.0)); + attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(2.4)); + attrNeg1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(-1.0)); + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + // String exact match + FunctionDefinitionEquality fd = (FunctionDefinitionEquality) StdFunctions.FD_DOUBLE_EQUAL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DOUBLE_EQUAL, fd.getId()); + assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // test normal equals and non-equals + // check separate objects with the same value + arguments.add(attr1); + arguments.add(attr1a); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // check not same + arguments.clear(); + arguments.add(attr1); + arguments.add(attr2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + arguments.clear(); + arguments.add(attr1); + arguments.add(attrNeg1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + + // test bad args data types? Not needed? + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(intAttr1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + + } + + + + + + /** + * Date + */ + @Test + public void testDate_Equal() { + Calendar calendar = Calendar.getInstance(); + Date today = calendar.getTime(); + Date longAgo = new Date(1234); + // create a date that is different than "today" but within the same day (i.e. has a different hour) + if (calendar.get(Calendar.HOUR_OF_DAY) > 3) { + calendar.set(Calendar.HOUR_OF_DAY, 3); + } else { + calendar.set(Calendar.HOUR_OF_DAY, 5); + } + Date todayPlus = calendar.getTime(); + + + FunctionArgumentAttributeValue attrToday = null; + FunctionArgumentAttributeValue attrToday2 = null; + FunctionArgumentAttributeValue attrLaterToday = null; + FunctionArgumentAttributeValue attrYesterday = null; + try { + attrToday = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(today)); + attrToday2 = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(today)); + attrLaterToday = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(todayPlus)); + attrYesterday = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(longAgo)); + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + // String exact match + FunctionDefinitionEquality fd = (FunctionDefinitionEquality) StdFunctions.FD_DATE_EQUAL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DATE_EQUAL, fd.getId()); + assertEquals(DataTypes.DT_DATE.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // test normal equals and non-equals + // check separate objects with the same value + arguments.add(attrToday); + arguments.add(attrToday2); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // check not same + arguments.clear(); + arguments.add(attrToday); + arguments.add(attrYesterday); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // Date objects with different times but within the same day should match + arguments.clear(); + arguments.add(attrToday); + arguments.add(attrLaterToday); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // test bad args data types? Not needed? + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(intAttr1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + + } + + + + + /** + * Time + */ + @Test + public void testTime_Equal() { + + Date now = new Date(); + Date now2 = new Date(now.getTime()); + Date notNow = new Date(now.getTime() - 100000); + + FunctionArgumentAttributeValue attrNow = null; + FunctionArgumentAttributeValue attrNow2 = null; + FunctionArgumentAttributeValue attrNotNow = null; + try { + attrNow = new FunctionArgumentAttributeValue(DataTypes.DT_TIME.createAttributeValue(now)); + attrNow2 = new FunctionArgumentAttributeValue(DataTypes.DT_TIME.createAttributeValue(now2)); + attrNotNow = new FunctionArgumentAttributeValue(DataTypes.DT_TIME.createAttributeValue(notNow)); + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + // String exact match + FunctionDefinitionEquality fd = (FunctionDefinitionEquality) StdFunctions.FD_TIME_EQUAL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_TIME_EQUAL, fd.getId()); + assertEquals(DataTypes.DT_TIME.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // test normal equals and non-equals + // check separate objects with the same value + arguments.add(attrNow); + arguments.add(attrNow2); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // check not same + arguments.clear(); + arguments.add(attrNow); + arguments.add(attrNotNow); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // test bad args data types? Not needed? + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(intAttr1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + + } + + + + + /** + * DateTime + */ + @Test + public void testDateTime_Equal() { + Calendar calendar = Calendar.getInstance(); + Date today = calendar.getTime(); + Date longAgo = new Date(1234); + // create a dateTime that is different than "today" changing only the Timezone + if (calendar.get(Calendar.ZONE_OFFSET) > 3) { + calendar.set(Calendar.ZONE_OFFSET, 3); + } else { + calendar.set(Calendar.ZONE_OFFSET, 5); + } + Date todayPlus = calendar.getTime(); + + + FunctionArgumentAttributeValue attrToday = null; + FunctionArgumentAttributeValue attrToday2 = null; + FunctionArgumentAttributeValue attrLaterToday = null; + FunctionArgumentAttributeValue attrYesterday = null; + try { + attrToday = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(today)); + attrToday2 = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(today)); + attrLaterToday = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(todayPlus)); + attrYesterday = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(longAgo)); + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + // String exact match + FunctionDefinitionEquality fd = (FunctionDefinitionEquality) StdFunctions.FD_DATETIME_EQUAL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DATETIME_EQUAL, fd.getId()); + assertEquals(DataTypes.DT_DATETIME.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // test normal equals and non-equals + // check separate objects with the same value + arguments.add(attrToday); + arguments.add(attrToday2); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // check not same + arguments.clear(); + arguments.add(attrToday); + arguments.add(attrYesterday); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // DateTime with different Zones should not match + arguments.clear(); + arguments.add(attrToday); + arguments.add(attrLaterToday); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // test bad args data types? Not needed? + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(intAttr1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + + } + + + /** + * dayTimeDuration - Version1 + */ + @Test + public void testDayTimeDuration_Equal_V1() { + + XPathDayTimeDuration dur1 = new XPathDayTimeDuration(1, 3, 5, 12, 38); + XPathDayTimeDuration dur2 = new XPathDayTimeDuration(1, 3, 5, 12, 38); + XPathDayTimeDuration differentDur = new XPathDayTimeDuration(-1, 4, 7, 5, 33); + + FunctionArgumentAttributeValue attrDur1 = null; + FunctionArgumentAttributeValue attrDur2 = null; + FunctionArgumentAttributeValue attrDifferentDur = null; + try { + attrDur1 = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(dur1)); + attrDur2 = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(dur2)); + attrDifferentDur = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(differentDur)); + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionEquality fd = (FunctionDefinitionEquality) StdFunctions.FD_DAYTIMEDURATION_EQUAL_VERSION1; + + // check identity and type of the thing created + assertEquals(XACML1.ID_FUNCTION_DAYTIMEDURATION_EQUAL, fd.getId()); + assertEquals(DataTypes.DT_DAYTIMEDURATION.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // test normal equals and non-equals + // check separate objects with the same value + arguments.add(attrDur1); + arguments.add(attrDur2); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // check not same + arguments.clear(); + arguments.add(attrDur1); + arguments.add(attrDifferentDur); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // test bad args data types? Not needed? + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(intAttr1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + + } + + + /** + * dayTimeDuration - Current version + */ + @Test + public void testDayTimeDuration_Equal() { + + XPathDayTimeDuration dur1 = new XPathDayTimeDuration(1, 3, 5, 12, 38); + XPathDayTimeDuration dur2 = new XPathDayTimeDuration(1, 3, 5, 12, 38); + XPathDayTimeDuration differentDur = new XPathDayTimeDuration(-1, 4, 7, 5, 33); + + FunctionArgumentAttributeValue attrDur1 = null; + FunctionArgumentAttributeValue attrDur2 = null; + FunctionArgumentAttributeValue attrDifferentDur = null; + try { + attrDur1 = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(dur1)); + attrDur2 = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(dur2)); + attrDifferentDur = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(differentDur)); + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionEquality fd = (FunctionDefinitionEquality) StdFunctions.FD_DAYTIMEDURATION_EQUAL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DAYTIMEDURATION_EQUAL, fd.getId()); + assertEquals(DataTypes.DT_DAYTIMEDURATION.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // test normal equals and non-equals + // check separate objects with the same value + arguments.add(attrDur1); + arguments.add(attrDur2); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // check not same + arguments.clear(); + arguments.add(attrDur1); + arguments.add(attrDifferentDur); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // test bad args data types? Not needed? + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(intAttr1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + + } + + + + /** + * dayTimeDuration - Version1 + */ + @Test + public void testYearMonthDuration_Equal_V1() { + + XPathYearMonthDuration dur1 = new XPathYearMonthDuration(1, 3, 5); + XPathYearMonthDuration dur2 = new XPathYearMonthDuration(1, 3, 5); + XPathYearMonthDuration differentDur = new XPathYearMonthDuration(-1, 4, 7); + + FunctionArgumentAttributeValue attrDur1 = null; + FunctionArgumentAttributeValue attrDur2 = null; + FunctionArgumentAttributeValue attrDifferentDur = null; + try { + attrDur1 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(dur1)); + attrDur2 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(dur2)); + attrDifferentDur = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(differentDur)); + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionEquality fd = (FunctionDefinitionEquality) StdFunctions.FD_YEARMONTHDURATION_EQUAL_VERSION1; + + // check identity and type of the thing created + assertEquals(XACML1.ID_FUNCTION_YEARMONTHDURATION_EQUAL, fd.getId()); + assertEquals(DataTypes.DT_YEARMONTHDURATION.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // test normal equals and non-equals + // check separate objects with the same value + arguments.add(attrDur1); + arguments.add(attrDur2); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // check not same + arguments.clear(); + arguments.add(attrDur1); + arguments.add(attrDifferentDur); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // test bad args data types? Not needed? + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(intAttr1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + + } + + + + + /** + * dayTimeDuration - Current version + */ + @Test + public void testYearMonthDuration_Equal() { + + XPathYearMonthDuration dur1 = new XPathYearMonthDuration(1, 3, 5); + XPathYearMonthDuration dur2 = new XPathYearMonthDuration(1, 3, 5); + XPathYearMonthDuration differentDur = new XPathYearMonthDuration(-1, 4, 7); + + FunctionArgumentAttributeValue attrDur1 = null; + FunctionArgumentAttributeValue attrDur2 = null; + FunctionArgumentAttributeValue attrDifferentDur = null; + try { + attrDur1 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(dur1)); + attrDur2 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(dur2)); + attrDifferentDur = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(differentDur)); + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionEquality fd = (FunctionDefinitionEquality) StdFunctions.FD_YEARMONTHDURATION_EQUAL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_YEARMONTHDURATION_EQUAL, fd.getId()); + assertEquals(DataTypes.DT_YEARMONTHDURATION.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // test normal equals and non-equals + // check separate objects with the same value + arguments.add(attrDur1); + arguments.add(attrDur2); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // check not same + arguments.clear(); + arguments.add(attrDur1); + arguments.add(attrDifferentDur); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // test bad args data types? Not needed? + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(intAttr1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + + } + + + /** + * URI + */ + @Test + public void testAnyURI_Equal() { + + URI uri1 = null; + URI uri2 = null; + URI uriNotThere = null; + try { + uri1 = new URI("http://someplace.com/gothere"); + uri2 = new URI("http://someplace.com/gothere"); + uriNotThere = new URI("http://someplace.com/notGoingThere"); + } catch (Exception e) { + fail(e.toString()); + } + + FunctionArgumentAttributeValue attrUri1 = null; + FunctionArgumentAttributeValue attrUri2 = null; + FunctionArgumentAttributeValue attrUriNotThere = null; + try { + attrUri1 = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(uri1)); + attrUri2 = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(uri2)); + attrUriNotThere = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(uriNotThere)); + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionEquality fd = (FunctionDefinitionEquality) StdFunctions.FD_ANYURI_EQUAL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_ANYURI_EQUAL, fd.getId()); + assertEquals(DataTypes.DT_ANYURI.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // test normal equals and non-equals + // check separate objects with the same value + arguments.add(attrUri1); + arguments.add(attrUri2); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // check not same + arguments.clear(); + arguments.add(attrUri1); + arguments.add(attrUriNotThere); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // test bad args data types? Not needed? + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(intAttr1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + + } + + + /** + * X500Name + */ + @Test + public void testX500Name_Equal() { + + X500Principal name1 = new X500Principal("CN=Duke, OU=JavaSoft, O=Sun Microsystems, C=US"); + X500Principal name2 = new X500Principal("CN=Duke, OU=JavaSoft, O=Sun Microsystems, C=US"); + X500Principal name3 = new X500Principal("CN=NotDuke, OU=NotThere, O=Oracle, C=US"); + + + FunctionArgumentAttributeValue attrName1 = null; + FunctionArgumentAttributeValue attrName1a = null; + FunctionArgumentAttributeValue attrNotSameName = null; + try { + attrName1 = new FunctionArgumentAttributeValue(DataTypes.DT_X500NAME.createAttributeValue(name1)); + attrName1a = new FunctionArgumentAttributeValue(DataTypes.DT_X500NAME.createAttributeValue(name2)); + attrNotSameName = new FunctionArgumentAttributeValue(DataTypes.DT_X500NAME.createAttributeValue(name3)); + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionEquality fd = (FunctionDefinitionEquality) StdFunctions.FD_X500NAME_EQUAL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_X500NAME_EQUAL, fd.getId()); + assertEquals(DataTypes.DT_X500NAME.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // test normal equals and non-equals + // check separate objects with the same value + arguments.add(attrName1); + arguments.add(attrName1a); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // check not same + arguments.clear(); + arguments.add(attrName1); + arguments.add(attrNotSameName); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // test bad args data types? Not needed? + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(intAttr1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + + } + + + + /** + * RFC822Name + */ + @Test + public void testRfc822Name_Equal() { + + RFC822Name name1 = null; + RFC822Name name1a = null; + RFC822Name differentLocalName = null; + RFC822Name differentDomainName = null; + RFC822Name localCaseName = null; + RFC822Name domainCaseName = null; + @SuppressWarnings("unused") + RFC822Name noAtName = null; + + try { + name1 = RFC822Name.newInstance("localPart@DomainPart"); + name1a = RFC822Name.newInstance("localPart@DomainPart"); + differentLocalName = RFC822Name.newInstance("differentlocalPart@DomainPart"); + differentDomainName = RFC822Name.newInstance("localPart@differentDomainPart"); + localCaseName = RFC822Name.newInstance("LOCALPart@DomainPart"); + domainCaseName = RFC822Name.newInstance("localPart@DOMAINPart"); + + + } catch (Exception e) { + fail(e.toString()); + } + + // should not be able to create a name without an @. If you try, newInstance returns null + Exception exSeen = null; + try { + noAtName = RFC822Name.newInstance("nameWithoutAnAtSign"); + } catch (Exception e) { + exSeen = e; + } + assertNotNull(exSeen); + + + FunctionArgumentAttributeValue attrName1 = null; + FunctionArgumentAttributeValue attrName1a = null; + FunctionArgumentAttributeValue attrDifferentLocalName = null; + FunctionArgumentAttributeValue attrDifferentDomainName = null; + FunctionArgumentAttributeValue attrLocalCaseName = null; + FunctionArgumentAttributeValue attrDomainCaseName = null; + try { + attrName1 = new FunctionArgumentAttributeValue(DataTypes.DT_RFC822NAME.createAttributeValue(name1)); + attrName1a = new FunctionArgumentAttributeValue(DataTypes.DT_RFC822NAME.createAttributeValue(name1a)); + attrDifferentLocalName = new FunctionArgumentAttributeValue(DataTypes.DT_RFC822NAME.createAttributeValue(differentLocalName)); + attrDifferentDomainName = new FunctionArgumentAttributeValue(DataTypes.DT_RFC822NAME.createAttributeValue(differentDomainName)); + attrLocalCaseName = new FunctionArgumentAttributeValue(DataTypes.DT_RFC822NAME.createAttributeValue(localCaseName)); + attrDomainCaseName = new FunctionArgumentAttributeValue(DataTypes.DT_RFC822NAME.createAttributeValue(domainCaseName)); + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionEquality fd = (FunctionDefinitionEquality) StdFunctions.FD_RFC822NAME_EQUAL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_RFC822NAME_EQUAL, fd.getId()); + assertEquals(DataTypeRFC822Name.newInstance().getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // test normal equals and non-equals + // check separate objects with the same value + arguments.add(attrName1); + arguments.add(attrName1a); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // check not same Local + arguments.clear(); + arguments.add(attrName1); + arguments.add(attrDifferentLocalName); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // check not same Domain + arguments.clear(); + arguments.add(attrName1); + arguments.add(attrDifferentDomainName); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // test case-sensitivity in local part + arguments.clear(); + arguments.add(attrName1); + arguments.add(attrLocalCaseName); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // test non-case-sensitivity in Domain part + arguments.clear(); + arguments.add(attrName1); + arguments.add(attrDomainCaseName); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // test bad args data types? Not needed? + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(intAttr1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + + } + + + /** + * Hex Binary + */ + @Test + public void testHexBinary_Equal() { + HexBinary binary = null; + HexBinary sameBinary = null; + HexBinary differentBinary = null; + try { + binary = HexBinary.newInstance("e04fd020ea3a6910a2d808002b30309d"); + sameBinary = HexBinary.newInstance("e04fd020ea3a6910a2d808002b30309d"); + differentBinary = HexBinary.newInstance("f123a890ee3d"); + } catch (Exception e) { + fail(e.toString()); + } + + FunctionArgumentAttributeValue attrBinary = null; + FunctionArgumentAttributeValue attrSameBinary = null; + FunctionArgumentAttributeValue attrDifferentBinary = null;; + try { + attrBinary = new FunctionArgumentAttributeValue(DataTypes.DT_HEXBINARY.createAttributeValue(binary)); + attrSameBinary = new FunctionArgumentAttributeValue(DataTypes.DT_HEXBINARY.createAttributeValue(sameBinary)); + attrDifferentBinary = new FunctionArgumentAttributeValue(DataTypes.DT_HEXBINARY.createAttributeValue(differentBinary)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionEquality fd = (FunctionDefinitionEquality) StdFunctions.FD_HEXBINARY_EQUAL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_HEXBINARY_EQUAL, fd.getId()); + assertEquals(DataTypes.DT_HEXBINARY.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // test normal equals and non-equals + // check separate objects with the same value + arguments.add(attrBinary); + arguments.add(attrSameBinary); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // check not same + arguments.clear(); + arguments.add(attrBinary); + arguments.add(attrDifferentBinary); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // test bad args data types? Not needed? + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(intAttr1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + + } + + + /** + * Base64 Binary + */ + @Test + public void testBase64Binary_Equal() { + Base64Binary binary = null; + Base64Binary sameBinary = null; + Base64Binary differentBinary = null; + try { + binary = Base64Binary.newInstance("TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz"); + sameBinary = Base64Binary.newInstance("TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz"); + differentBinary = Base64Binary.newInstance("f123a890ee3d"); + } catch (Exception e) { + fail(e.toString()); + } + + FunctionArgumentAttributeValue attrBinary = null; + FunctionArgumentAttributeValue attrSameBinary = null; + FunctionArgumentAttributeValue attrDifferentBinary = null; + try { + attrBinary = new FunctionArgumentAttributeValue(DataTypes.DT_BASE64BINARY.createAttributeValue(binary)); + attrSameBinary = new FunctionArgumentAttributeValue(DataTypes.DT_BASE64BINARY.createAttributeValue(sameBinary)); + attrDifferentBinary = new FunctionArgumentAttributeValue(DataTypes.DT_BASE64BINARY.createAttributeValue(differentBinary)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionEquality fd = (FunctionDefinitionEquality) StdFunctions.FD_BASE64BINARY_EQUAL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_BASE64BINARY_EQUAL, fd.getId()); + assertEquals(DataTypes.DT_BASE64BINARY.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // test normal equals and non-equals + // check separate objects with the same value + arguments.add(attrBinary); + arguments.add(attrSameBinary); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // check not same + arguments.clear(); + arguments.add(attrBinary); + arguments.add(attrDifferentBinary); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // test bad args data types? Not needed? + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(intAttr1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + + } +} diff --git a/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionHigherOrderBagTest.java b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionHigherOrderBagTest.java new file mode 100644 index 000000000..607259ab9 --- /dev/null +++ b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionHigherOrderBagTest.java @@ -0,0 +1,2193 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +import com.att.research.xacml.api.AttributeValue; +import com.att.research.xacml.api.XACML3; +import com.att.research.xacml.std.datatypes.DataTypes; +import com.att.research.xacmlatt.pdp.policy.Bag; +import com.att.research.xacmlatt.pdp.policy.ExpressionResult; +import com.att.research.xacmlatt.pdp.policy.FunctionArgument; +import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; +import com.att.research.xacmlatt.pdp.policy.FunctionArgumentBag; +import com.att.research.xacmlatt.pdp.std.StdFunctions; +import com.att.research.xacmlatt.pdp.std.functions.*; + +/** + * Test of PDP Functions (See XACML core spec section A.3) + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * + */ +public class FunctionDefinitionHigherOrderBagTest { + + + /* + * variables useful in the following tests + */ + List arguments = new ArrayList(); + + + + // + // ANY-OF tests + // + + + @Test + public void testAny_of() { + String a = "a"; + String b = "b"; + String c = "c"; + String d = "d"; + String e = "e"; + String f = "f"; + String g = "g"; + String h = "h"; + String j = "j"; + + + Bag bagabcdefg = null; + Bag bagbdfhj = null; + Bag bagace = null; + Bag bagb = null; + Bag bagaaacccef = null; + Bag bagInt = null; + Bag bagStringInt = null; + Bag bagEmpty = null; + Bag bagStringBooleansTrue = null; + Bag bagStringBooleansFalse = null; + + + // primitive attrs + FunctionArgumentAttributeValue attra = null; + FunctionArgumentAttributeValue attrb = null; + FunctionArgumentAttributeValue attrh = null; + + + // predicates passed as arguments + FunctionArgumentAttributeValue attrPredicateStringEqual = null; + FunctionArgumentAttributeValue attrPredicateStringIntersection = null; + FunctionArgumentAttributeValue attrPredicateBooleanFromString = null; + + try { + + // Create Bag contents + bagabcdefg = new Bag(); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(d)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(g)); + bagbdfhj = new Bag(); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(d)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(h)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(j)); + bagace = new Bag(); + bagace.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagace.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagace.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagb = new Bag(); + bagb.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagaaacccef = new Bag(); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagInt = new Bag(); + bagInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); + bagStringInt = new Bag(); + bagStringInt.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagStringInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); + bagEmpty = new Bag(); + bagStringBooleansTrue = new Bag(); + bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("false")); + bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("false")); + bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("true")); + bagStringBooleansFalse = new Bag(); + bagStringBooleansFalse.add(DataTypes.DT_STRING.createAttributeValue("false")); + bagStringBooleansFalse.add(DataTypes.DT_STRING.createAttributeValue("false")); + + + // create primitive attrs + attra = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(a)); + attrb = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(b)); + attrh = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(h)); + + + // predicates passed as function arguments + attrPredicateStringEqual = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_EQUAL)); + attrPredicateStringIntersection = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_INTERSECTION)); + attrPredicateBooleanFromString = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_BOOLEAN_FROM_STRING)); + + } catch (Exception ex) { + fail("creating attribute e="+ ex); + } + + // make into attributes + FunctionArgumentBag attrBagabcdefg = new FunctionArgumentBag(bagabcdefg); + FunctionArgumentBag attrBagbdfhj = new FunctionArgumentBag(bagbdfhj); + FunctionArgumentBag attrBagace = new FunctionArgumentBag(bagace); + FunctionArgumentBag attrBagStringInt = new FunctionArgumentBag(bagStringInt); + FunctionArgumentBag attrBagEmpty = new FunctionArgumentBag(bagEmpty); + FunctionArgumentBag attrBagStringBooleansTrue = new FunctionArgumentBag(bagStringBooleansTrue); + FunctionArgumentBag attrBagStringBooleansFalse = new FunctionArgumentBag(bagStringBooleansFalse); + + FunctionDefinitionHigherOrderBag fd = (FunctionDefinitionHigherOrderBag) StdFunctions.FD_ANY_OF; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_ANY_OF, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + // normal match + arguments.clear(); + arguments.add(attrPredicateStringEqual); + arguments.add(attra); + arguments.add(attrBagabcdefg); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // bag in first position - match + arguments.clear(); + arguments.add(attrPredicateStringEqual); + arguments.add(attrBagabcdefg); + arguments.add(attra); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // normal no-match + arguments.clear(); + arguments.add(attrPredicateStringEqual); + arguments.add(attra); + arguments.add(attrBagbdfhj); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // multiple primitives + arguments.clear(); + arguments.add(attrPredicateStringEqual); + arguments.add(attrh); + arguments.add(attrb); + arguments.add(attrBagace); + arguments.add(attra); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of Predicate error: function:string-equal Expected 2 arguments, got 4", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // no primitives - predicate function expects 2 + arguments.clear(); + arguments.add(attrPredicateStringEqual); + arguments.add(attrBagace); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of Predicate error: function:string-equal Expected 2 arguments, got 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // no primitives - predicate expects only 1 arg + arguments.clear(); + arguments.add(attrPredicateBooleanFromString); + arguments.add(attrBagStringBooleansTrue); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + arguments.clear(); + arguments.add(attrPredicateBooleanFromString); + arguments.add(attrBagStringBooleansFalse); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // bag is empty + arguments.clear(); + arguments.add(attrPredicateStringEqual); + arguments.add(attrh); + arguments.add(attrBagEmpty); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // no bag + arguments.clear(); + arguments.add(attrPredicateStringEqual); + arguments.add(attrh); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of Did not get any Bag argument; must have at least 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // extra bag + arguments.clear(); + arguments.add(attrPredicateStringEqual); + arguments.add(attrh); + arguments.add(attrBagStringBooleansTrue); + arguments.add(attrh); + arguments.add(attrBagStringBooleansTrue); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of must have only 1 bag; found one at index 2 and another at 4", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // bad predicate + arguments.clear(); + arguments.add(attrh); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of First argument expected URI, got http://www.w3.org/2001/XMLSchema#string", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // non-boolean predicate + arguments.clear(); + arguments.add(attrPredicateStringIntersection); + arguments.add(attrh); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of Predicate Function must return boolean, but 'urn:oasis:names:tc:xacml:1.0:function:string-intersection' returns 'string", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // predicate after first arg + arguments.clear(); + arguments.add(attrPredicateStringEqual); + arguments.add(attrPredicateStringIntersection); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of Predicate error: function:string-equal Expected data type 'string' saw 'anyURI' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bags of different types + arguments.clear(); + arguments.add(attrPredicateStringEqual); + arguments.add(attrh); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + + // first null + arguments.clear(); + arguments.add(null); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of Predicate Function (first argument) was null", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // second null + arguments.clear(); + arguments.add(attrPredicateStringEqual); + arguments.add(attrBagabcdefg); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of Got null argument at index 2", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + + + + @Test + public void testAll_of() { + String a = "a"; + String b = "b"; + String c = "c"; + String d = "d"; + String e = "e"; + String f = "f"; + String g = "g"; + String h = "h"; + String j = "j"; + + String w = "w"; + + + Bag bagabcdefg = null; + Bag bagbdfhj = null; + Bag bagace = null; + Bag bagb = null; + Bag bagaaacccef = null; + Bag bagInt = null; + Bag bagStringInt = null; + Bag bagEmpty = null; + Bag bagStringBooleansFalse = null; + Bag bagStringBooleansTrue = null; + + + // primitive attrs + FunctionArgumentAttributeValue attra = null; + FunctionArgumentAttributeValue attrh = null; + FunctionArgumentAttributeValue attrw = null; + + + + // predicates passed as arguments + FunctionArgumentAttributeValue attrPredicateStringEqual = null; + FunctionArgumentAttributeValue attrPredicateStringIntersection = null; + FunctionArgumentAttributeValue attrPredicateStringGreaterThan = null; + FunctionArgumentAttributeValue attrPredicateBooleanFromString = null; + + try { + + // Create Bag contents + bagabcdefg = new Bag(); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(d)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(g)); + bagbdfhj = new Bag(); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(d)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(h)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(j)); + bagace = new Bag(); + bagace.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagace.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagace.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagb = new Bag(); + bagb.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagaaacccef = new Bag(); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagInt = new Bag(); + bagInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); + bagStringInt = new Bag(); + bagStringInt.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagStringInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); + bagEmpty = new Bag(); + bagStringBooleansTrue = new Bag(); + bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("true")); + bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("true")); + bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("true")); + bagStringBooleansFalse = new Bag(); + bagStringBooleansFalse.add(DataTypes.DT_STRING.createAttributeValue("false")); + bagStringBooleansFalse.add(DataTypes.DT_STRING.createAttributeValue("false")); + + + + // create primitive attrs + attra = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(a)); + attrh = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(h)); + attrw = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(w)); + + + // predicates passed as function arguments + attrPredicateStringEqual = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_EQUAL)); + attrPredicateStringIntersection = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_INTERSECTION)); + attrPredicateStringGreaterThan = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_GREATER_THAN)); + attrPredicateBooleanFromString = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_BOOLEAN_FROM_STRING)); + + } catch (Exception ex) { + fail("creating attribute e="+ ex); + } + + // make into attributes + FunctionArgumentBag attrBagabcdefg = new FunctionArgumentBag(bagabcdefg); + FunctionArgumentBag attrBagbdfhj = new FunctionArgumentBag(bagbdfhj); + FunctionArgumentBag attrBagace = new FunctionArgumentBag(bagace); + FunctionArgumentBag attrBagStringInt = new FunctionArgumentBag(bagStringInt); + FunctionArgumentBag attrBagEmpty = new FunctionArgumentBag(bagEmpty); + FunctionArgumentBag attrBagStringBooleansTrue = new FunctionArgumentBag(bagStringBooleansTrue); + FunctionArgumentBag attrBagStringBooleansFalse = new FunctionArgumentBag(bagStringBooleansFalse); + + FunctionDefinitionHigherOrderBag fd = (FunctionDefinitionHigherOrderBag) StdFunctions.FD_ALL_OF; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_ALL_OF, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + // normal match + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrw); + arguments.add(attrBagace); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // normal no-match + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attra); + arguments.add(attrBagbdfhj); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // no primitives - predicate function expects 2 + arguments.clear(); + arguments.add(attrPredicateStringEqual); + arguments.add(attrBagace); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of Predicate error: function:string-equal Expected 2 arguments, got 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // no primitives - predicate expects only 1 arg + arguments.clear(); + arguments.add(attrPredicateBooleanFromString); + arguments.add(attrBagStringBooleansTrue); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + arguments.clear(); + arguments.add(attrPredicateBooleanFromString); + arguments.add(attrBagStringBooleansFalse); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // bag is empty + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrh); + arguments.add(attrBagEmpty); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // no bag + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrh); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of Did not get any Bag argument; must have at least 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // extra bag + arguments.clear(); + arguments.add(attrPredicateStringEqual); + arguments.add(attrh); + arguments.add(attrBagStringBooleansTrue); + arguments.add(attrh); + arguments.add(attrBagStringBooleansTrue); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of must have only 1 bag; found one at index 2 and another at 4", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // bad predicate + arguments.clear(); + arguments.add(attrh); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of First argument expected URI, got http://www.w3.org/2001/XMLSchema#string", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // non-boolean predicate + arguments.clear(); + arguments.add(attrPredicateStringIntersection); + arguments.add(attrh); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of Predicate Function must return boolean, but 'urn:oasis:names:tc:xacml:1.0:function:string-intersection' returns 'string", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // predicate after first arg + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrPredicateStringIntersection); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of Predicate error: function:string-greater-than Expected data type 'string' saw 'anyURI' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bags of different types + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrh); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + + // first null + arguments.clear(); + arguments.add(null); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of Predicate Function (first argument) was null", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // second null + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrBagabcdefg); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of Got null argument at index 2", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + + + + + + + + + + + + @Test + public void testAny_of_any() { + String a = "a"; + String b = "b"; + String c = "c"; + String d = "d"; + String e = "e"; + String f = "f"; + String g = "g"; + String h = "h"; + String j = "j"; + + String w = "w"; + + + Bag bagabcdefg = null; + Bag bagbdfhj = null; + Bag bagace = null; + Bag bagb = null; + Bag bagaaacccef = null; + Bag bagInt = null; + Bag bagStringInt = null; + Bag bagEmpty = null; + Bag bagStringBooleansFalse = null; + Bag bagStringBooleansTrue = null; + Bag bagBooleansFalse = null; + Bag bagBooleansTrue = null; + + + // primitive attrs + FunctionArgumentAttributeValue attra = null; + FunctionArgumentAttributeValue attrh = null; + FunctionArgumentAttributeValue attrw = null; + + + FunctionArgumentAttributeValue attrInt4 = null; + + + // predicates passed as arguments + FunctionArgumentAttributeValue attrPredicateStringEqual = null; + FunctionArgumentAttributeValue attrPredicateStringIntersection = null; + FunctionArgumentAttributeValue attrPredicateStringGreaterThan = null; + FunctionArgumentAttributeValue attrPredicateBooleanFromString = null; + FunctionArgumentAttributeValue attrPredicateNof = null; + + try { + + // Create Bag contents + bagabcdefg = new Bag(); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(d)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(g)); + bagbdfhj = new Bag(); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(d)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(h)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(j)); + bagace = new Bag(); + bagace.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagace.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagace.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagb = new Bag(); + bagb.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagaaacccef = new Bag(); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagInt = new Bag(); + bagInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); + bagStringInt = new Bag(); + bagStringInt.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagStringInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); + bagEmpty = new Bag(); + bagStringBooleansTrue = new Bag(); + bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("true")); + bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("false")); + bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("true")); + bagStringBooleansFalse = new Bag(); + bagStringBooleansFalse.add(DataTypes.DT_STRING.createAttributeValue("false")); + bagStringBooleansFalse.add(DataTypes.DT_STRING.createAttributeValue("false")); + bagBooleansTrue = new Bag(); + bagBooleansTrue.add(DataTypes.DT_BOOLEAN.createAttributeValue(false)); + bagBooleansTrue.add(DataTypes.DT_BOOLEAN.createAttributeValue(false)); + bagBooleansTrue.add(DataTypes.DT_BOOLEAN.createAttributeValue(true)); + bagBooleansFalse = new Bag(); + bagBooleansFalse.add(DataTypes.DT_BOOLEAN.createAttributeValue(false)); + bagBooleansFalse.add(DataTypes.DT_BOOLEAN.createAttributeValue(false)); + + + // create primitive attrs + attra = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(a)); + attrh = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(h)); + attrw = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(w)); + + attrInt4 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(4)); + + + // predicates passed as function arguments + attrPredicateStringEqual = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_EQUAL)); + attrPredicateStringIntersection = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_INTERSECTION)); + attrPredicateStringGreaterThan = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_GREATER_THAN)); + attrPredicateBooleanFromString = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_BOOLEAN_FROM_STRING)); + attrPredicateNof = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_N_OF)); + + } catch (Exception ex) { + fail("creating attribute e="+ ex); + } + + // make into attributes + FunctionArgumentBag attrBagabcdefg = new FunctionArgumentBag(bagabcdefg); + FunctionArgumentBag attrBagbdfhj = new FunctionArgumentBag(bagbdfhj); + FunctionArgumentBag attrBagace = new FunctionArgumentBag(bagace); + FunctionArgumentBag attrBagStringInt = new FunctionArgumentBag(bagStringInt); + FunctionArgumentBag attrBagEmpty = new FunctionArgumentBag(bagEmpty); + FunctionArgumentBag attrBagStringBooleansTrue = new FunctionArgumentBag(bagStringBooleansTrue); + FunctionArgumentBag attrBagStringBooleansFalse = new FunctionArgumentBag(bagStringBooleansFalse); + FunctionArgumentBag attrBagBooleansTrue = new FunctionArgumentBag(bagBooleansTrue); + FunctionArgumentBag attrBagBooleansFalse = new FunctionArgumentBag(bagBooleansFalse); + + FunctionDefinitionHigherOrderBag fd = (FunctionDefinitionHigherOrderBag) StdFunctions.FD_ANY_OF_ANY; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_ANY_OF_ANY, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + // normal match + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrw); + arguments.add(attrBagace); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // normal no-match + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attra); + arguments.add(attrBagbdfhj); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // no primitives - predicate function expects 2 + arguments.clear(); + arguments.add(attrPredicateStringEqual); + arguments.add(attrBagace); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of-any Predicate error: function:string-equal Expected 2 arguments, got 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + arguments.add(attrPredicateStringEqual); + arguments.add(attrBagace); + arguments.add(attrBagace); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // no primitives - predicate expects only 1 arg + arguments.clear(); + arguments.add(attrPredicateBooleanFromString); + arguments.add(attrBagStringBooleansTrue); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + arguments.clear(); + arguments.add(attrPredicateBooleanFromString); + arguments.add(attrBagStringBooleansFalse); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // n-of with lots of bags - success + arguments.clear(); + arguments.add(attrPredicateNof); + arguments.add(attrInt4); + arguments.add(attrBagBooleansTrue); + arguments.add(attrBagBooleansTrue); + arguments.add(attrBagBooleansTrue); + arguments.add(attrBagBooleansTrue); + arguments.add(attrBagBooleansTrue); + arguments.add(attrBagBooleansTrue); + arguments.add(attrBagBooleansTrue); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // n-of with lots of bags - fail + arguments.clear(); + arguments.add(attrPredicateNof); + arguments.add(attrInt4); + arguments.add(attrBagBooleansFalse); + arguments.add(attrBagBooleansFalse); + arguments.add(attrBagBooleansTrue); + arguments.add(attrBagBooleansTrue); + arguments.add(attrBagBooleansFalse); + arguments.add(attrBagBooleansFalse); + arguments.add(attrBagBooleansFalse); + arguments.add(attrBagBooleansFalse); + arguments.add(attrBagBooleansFalse); + arguments.add(attrBagBooleansFalse); + arguments.add(attrBagBooleansFalse); + arguments.add(attrBagBooleansFalse); + arguments.add(attrBagBooleansFalse); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + + // bag is empty + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrh); + arguments.add(attrBagEmpty); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of-any Bag is empty at index 2", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // no bag + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrh); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of-any Predicate error: function:string-greater-than Expected 2 arguments, got 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrh); + arguments.add(attrh); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // bad predicate + arguments.clear(); + arguments.add(attrh); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of-any First argument expected URI, got http://www.w3.org/2001/XMLSchema#string", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // non-boolean predicate + arguments.clear(); + arguments.add(attrPredicateStringIntersection); + arguments.add(attrh); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of-any Predicate Function must return boolean, but 'urn:oasis:names:tc:xacml:1.0:function:string-intersection' returns 'string", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // predicate after first arg + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrPredicateStringIntersection); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of-any Predicate error: function:string-greater-than Expected data type 'string' saw 'anyURI' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bags of different types + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrh); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // first null + arguments.clear(); + arguments.add(null); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of-any Predicate Function (first argument) was null", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // second null + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrBagabcdefg); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of-any Got null argument at index 2", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + + + + + + + + + + + + + + @Test + public void testAll_of_any() { + String a = "a"; + String b = "b"; + String c = "c"; + String d = "d"; + String e = "e"; + String f = "f"; + String g = "g"; + String h = "h"; + String j = "j"; + + String w = "w"; + String x = "x"; + + + Bag bagabcdefg = null; + Bag bagbdfhj = null; + Bag bagace = null; + Bag bagb = null; + Bag bagaaacccef = null; + Bag bagawx = null; + Bag bagInt = null; + Bag bagStringInt = null; + Bag bagEmpty = null; + Bag bagStringBooleansFalse = null; + Bag bagStringBooleansTrue = null; + Bag bagBooleansFalse = null; + Bag bagBooleansTrue = null; + + + // primitive attrs + FunctionArgumentAttributeValue attra = null; + FunctionArgumentAttributeValue attrh = null; + + + + + // predicates passed as arguments + FunctionArgumentAttributeValue attrPredicateStringEqual = null; + FunctionArgumentAttributeValue attrPredicateStringIntersection = null; + FunctionArgumentAttributeValue attrPredicateStringLessThan = null; + FunctionArgumentAttributeValue attrPredicateStringGreaterThan = null; + FunctionArgumentAttributeValue attrPredicateBooleanFromString = null; + + try { + + // Create Bag contents + bagabcdefg = new Bag(); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(d)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(g)); + bagbdfhj = new Bag(); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(d)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(h)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(j)); + bagace = new Bag(); + bagace.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagace.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagace.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagb = new Bag(); + bagb.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagaaacccef = new Bag(); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagawx = new Bag(); + bagawx.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagawx.add(DataTypes.DT_STRING.createAttributeValue(w)); + bagawx.add(DataTypes.DT_STRING.createAttributeValue(x)); + bagInt = new Bag(); + bagInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); + bagStringInt = new Bag(); + bagStringInt.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagStringInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); + bagEmpty = new Bag(); + bagStringBooleansTrue = new Bag(); + bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("true")); + bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("false")); + bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("true")); + bagStringBooleansFalse = new Bag(); + bagStringBooleansFalse.add(DataTypes.DT_STRING.createAttributeValue("false")); + bagStringBooleansFalse.add(DataTypes.DT_STRING.createAttributeValue("false")); + bagBooleansTrue = new Bag(); + bagBooleansTrue.add(DataTypes.DT_BOOLEAN.createAttributeValue(false)); + bagBooleansTrue.add(DataTypes.DT_BOOLEAN.createAttributeValue(false)); + bagBooleansTrue.add(DataTypes.DT_BOOLEAN.createAttributeValue(true)); + bagBooleansFalse = new Bag(); + bagBooleansFalse.add(DataTypes.DT_BOOLEAN.createAttributeValue(false)); + bagBooleansFalse.add(DataTypes.DT_BOOLEAN.createAttributeValue(false)); + + + // create primitive attrs + attra = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(a)); + attrh = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(h)); + + + + // predicates passed as function arguments + attrPredicateStringEqual = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_EQUAL)); + attrPredicateStringIntersection = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_INTERSECTION)); + attrPredicateStringLessThan = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_LESS_THAN)); + attrPredicateStringGreaterThan = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_GREATER_THAN)); + attrPredicateBooleanFromString = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_BOOLEAN_FROM_STRING)); + + } catch (Exception ex) { + fail("creating attribute e="+ ex); + } + + // make into attributes + FunctionArgumentBag attrBagabcdefg = new FunctionArgumentBag(bagabcdefg); + FunctionArgumentBag attrBagace = new FunctionArgumentBag(bagace); + FunctionArgumentBag attrBagawx = new FunctionArgumentBag(bagawx); + FunctionArgumentBag attrBagStringInt = new FunctionArgumentBag(bagStringInt); + FunctionArgumentBag attrBagEmpty = new FunctionArgumentBag(bagEmpty); + FunctionArgumentBag attrBagStringBooleansTrue = new FunctionArgumentBag(bagStringBooleansTrue); + + FunctionDefinitionHigherOrderBag fd = (FunctionDefinitionHigherOrderBag) StdFunctions.FD_ALL_OF_ANY; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_ALL_OF_ANY, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + // normal match + arguments.clear(); + arguments.add(attrPredicateStringLessThan); + arguments.add(attrBagabcdefg); + arguments.add(attrBagawx); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // normal no-match + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrBagace); + arguments.add(attrBagawx); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // primitive instead of bag + arguments.clear(); + arguments.add(attrPredicateStringEqual); + arguments.add(attra); + arguments.add(attrBagace); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of-any 2nd argument must be bag, got 'string'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + arguments.add(attrPredicateStringEqual); + arguments.add(attrBagace); + arguments.add(attra); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of-any 3rd argument must be bag, got 'string'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // no primitives - predicate expects only 1 arg + arguments.clear(); + arguments.add(attrPredicateBooleanFromString); + arguments.add(attrBagStringBooleansTrue); + arguments.add(attrBagStringBooleansTrue); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of-any Predicate error: function:boolean-from-string Expected 1 arguments, got 2", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + + // bag is empty + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrBagace); + arguments.add(attrBagEmpty); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrBagEmpty); + arguments.add(attrBagace); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // no bag + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrh); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of-any Expected 3 arguments, got 2", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // bad predicate + arguments.clear(); + arguments.add(attrh); + arguments.add(attrBagStringInt); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of-any First argument expected URI, got http://www.w3.org/2001/XMLSchema#string", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // non-boolean predicate + arguments.clear(); + arguments.add(attrPredicateStringIntersection); + arguments.add(attrBagStringInt); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of-any Predicate Function must return boolean, but 'urn:oasis:names:tc:xacml:1.0:function:string-intersection' returns 'string", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // predicate after first arg + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrPredicateStringIntersection); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of-any 2nd argument must be bag, got 'anyURI'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bags of different types + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrBagace); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of-any Predicate error: function:string-greater-than Expected data type 'string' saw 'integer' at arg index 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // no args + arguments.clear(); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of-any Expected at least 2 arguments, got 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // one arg + arguments.clear(); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of-any Expected at least 2 arguments, got 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // too many args + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBagabcdefg); + arguments.add(attrBagabcdefg); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of-any Expected 3 arguments, got 4", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // first null + arguments.clear(); + arguments.add(null); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of-any Expected 3 arguments, got 2", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // second null + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrBagabcdefg); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of-any 3rd argument must be bag, got 'null'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + + + + + + + + + + + @Test + public void testAny_of_all() { + String a = "a"; + String b = "b"; + String c = "c"; + String d = "d"; + String e = "e"; + String f = "f"; + String g = "g"; + String h = "h"; + String j = "j"; + + String w = "w"; + String x = "x"; + + + Bag bagabcdefg = null; + Bag bagbdfhj = null; + Bag bagace = null; + Bag bagb = null; + Bag bagaaacccef = null; + Bag bagewx = null; + Bag bagInt = null; + Bag bagStringInt = null; + Bag bagEmpty = null; + Bag bagStringBooleansFalse = null; + Bag bagStringBooleansTrue = null; + Bag bagBooleansFalse = null; + Bag bagBooleansTrue = null; + + + // primitive attrs + FunctionArgumentAttributeValue attra = null; + FunctionArgumentAttributeValue attrh = null; + + + + + // predicates passed as arguments + FunctionArgumentAttributeValue attrPredicateStringEqual = null; + FunctionArgumentAttributeValue attrPredicateStringIntersection = null; + FunctionArgumentAttributeValue attrPredicateStringGreaterThanOrEqual = null; + FunctionArgumentAttributeValue attrPredicateStringGreaterThan = null; + FunctionArgumentAttributeValue attrPredicateBooleanFromString = null; + + try { + + // Create Bag contents + bagabcdefg = new Bag(); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(d)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(g)); + bagbdfhj = new Bag(); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(d)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(h)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(j)); + bagace = new Bag(); + bagace.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagace.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagace.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagb = new Bag(); + bagb.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagaaacccef = new Bag(); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagewx = new Bag(); + bagewx.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagewx.add(DataTypes.DT_STRING.createAttributeValue(w)); + bagewx.add(DataTypes.DT_STRING.createAttributeValue(x)); + bagInt = new Bag(); + bagInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); + bagStringInt = new Bag(); + bagStringInt.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagStringInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); + bagEmpty = new Bag(); + bagStringBooleansTrue = new Bag(); + bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("true")); + bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("false")); + bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("true")); + bagStringBooleansFalse = new Bag(); + bagStringBooleansFalse.add(DataTypes.DT_STRING.createAttributeValue("false")); + bagStringBooleansFalse.add(DataTypes.DT_STRING.createAttributeValue("false")); + bagBooleansTrue = new Bag(); + bagBooleansTrue.add(DataTypes.DT_BOOLEAN.createAttributeValue(false)); + bagBooleansTrue.add(DataTypes.DT_BOOLEAN.createAttributeValue(false)); + bagBooleansTrue.add(DataTypes.DT_BOOLEAN.createAttributeValue(true)); + bagBooleansFalse = new Bag(); + bagBooleansFalse.add(DataTypes.DT_BOOLEAN.createAttributeValue(false)); + bagBooleansFalse.add(DataTypes.DT_BOOLEAN.createAttributeValue(false)); + + + // create primitive attrs + attra = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(a)); + attrh = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(h)); + + + + // predicates passed as function arguments + attrPredicateStringEqual = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_EQUAL)); + attrPredicateStringIntersection = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_INTERSECTION)); + attrPredicateStringGreaterThanOrEqual = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_GREATER_THAN_OR_EQUAL)); + attrPredicateStringGreaterThan = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_GREATER_THAN)); + attrPredicateBooleanFromString = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_BOOLEAN_FROM_STRING)); + + } catch (Exception ex) { + fail("creating attribute e="+ ex); + } + + // make into attributes + FunctionArgumentBag attrBagabcdefg = new FunctionArgumentBag(bagabcdefg); + FunctionArgumentBag attrBagace = new FunctionArgumentBag(bagace); + FunctionArgumentBag attrBagewx = new FunctionArgumentBag(bagewx); + FunctionArgumentBag attrBagStringInt = new FunctionArgumentBag(bagStringInt); + FunctionArgumentBag attrBagEmpty = new FunctionArgumentBag(bagEmpty); + FunctionArgumentBag attrBagStringBooleansTrue = new FunctionArgumentBag(bagStringBooleansTrue); + + FunctionDefinitionHigherOrderBag fd = (FunctionDefinitionHigherOrderBag) StdFunctions.FD_ANY_OF_ALL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_ANY_OF_ALL, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + // normal match + arguments.clear(); + arguments.add(attrPredicateStringGreaterThanOrEqual); + arguments.add(attrBagewx); + arguments.add(attrBagace); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // normal no-match + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrBagace); + arguments.add(attrBagewx); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // primitive instead of bag + arguments.clear(); + arguments.add(attrPredicateStringEqual); + arguments.add(attra); + arguments.add(attrBagace); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of-all 2nd argument must be bag, got 'string'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + arguments.add(attrPredicateStringEqual); + arguments.add(attrBagace); + arguments.add(attra); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of-all 3rd argument must be bag, got 'string'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // no primitives - predicate expects only 1 arg + arguments.clear(); + arguments.add(attrPredicateBooleanFromString); + arguments.add(attrBagStringBooleansTrue); + arguments.add(attrBagStringBooleansTrue); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of-all Predicate error: function:boolean-from-string Expected 1 arguments, got 2", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bag is empty + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrBagace); + arguments.add(attrBagEmpty); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrBagEmpty); + arguments.add(attrBagace); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // no bag + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrh); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of-all Expected 3 arguments, got 2", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // bad predicate + arguments.clear(); + arguments.add(attrh); + arguments.add(attrBagStringInt); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of-all First argument expected URI, got http://www.w3.org/2001/XMLSchema#string", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // non-boolean predicate + arguments.clear(); + arguments.add(attrPredicateStringIntersection); + arguments.add(attrBagStringInt); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of-all Predicate Function must return boolean, but 'urn:oasis:names:tc:xacml:1.0:function:string-intersection' returns 'string", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // predicate after first arg + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrPredicateStringIntersection); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of-all 2nd argument must be bag, got 'anyURI'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bags of different types + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrBagace); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of-all Predicate error: function:string-greater-than Expected data type 'string' saw 'integer' at arg index 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // no args + arguments.clear(); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of-all Expected at least 2 arguments, got 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // one arg + arguments.clear(); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of-all Expected at least 2 arguments, got 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // too many args + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBagabcdefg); + arguments.add(attrBagabcdefg); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of-all Expected 3 arguments, got 4", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // first null + arguments.clear(); + arguments.add(null); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of-all Expected 3 arguments, got 2", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // second null + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrBagabcdefg); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of-all 3rd argument must be bag, got 'null'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + + + + + @Test + public void testAll_of_all() { + String a = "a"; + String b = "b"; + String c = "c"; + String d = "d"; + String e = "e"; + String f = "f"; + String g = "g"; + String h = "h"; + String j = "j"; + + String w = "w"; + String x = "x"; + + + Bag bagabcdefg = null; + Bag bagbdfhj = null; + Bag bagace = null; + Bag bagb = null; + Bag bagaaacccef = null; + Bag bagawx = null; + Bag bagwx = null; + Bag bagInt = null; + Bag bagStringInt = null; + Bag bagEmpty = null; + Bag bagStringBooleansFalse = null; + Bag bagStringBooleansTrue = null; + Bag bagBooleansFalse = null; + Bag bagBooleansTrue = null; + + + // primitive attrs + FunctionArgumentAttributeValue attra = null; + FunctionArgumentAttributeValue attrh = null; + + + + + // predicates passed as arguments + FunctionArgumentAttributeValue attrPredicateStringEqual = null; + FunctionArgumentAttributeValue attrPredicateStringIntersection = null; + FunctionArgumentAttributeValue attrPredicateStringGreaterThan = null; + FunctionArgumentAttributeValue attrPredicateBooleanFromString = null; + + try { + + // Create Bag contents + bagabcdefg = new Bag(); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(d)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(g)); + bagbdfhj = new Bag(); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(d)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(h)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(j)); + bagace = new Bag(); + bagace.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagace.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagace.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagb = new Bag(); + bagb.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagaaacccef = new Bag(); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagawx = new Bag(); + bagawx.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagawx.add(DataTypes.DT_STRING.createAttributeValue(w)); + bagawx.add(DataTypes.DT_STRING.createAttributeValue(x)); + bagwx = new Bag(); + bagwx.add(DataTypes.DT_STRING.createAttributeValue(w)); + bagwx.add(DataTypes.DT_STRING.createAttributeValue(x)); + bagInt = new Bag(); + bagInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); + bagStringInt = new Bag(); + bagStringInt.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagStringInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); + bagEmpty = new Bag(); + bagStringBooleansTrue = new Bag(); + bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("true")); + bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("false")); + bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("true")); + bagStringBooleansFalse = new Bag(); + bagStringBooleansFalse.add(DataTypes.DT_STRING.createAttributeValue("false")); + bagStringBooleansFalse.add(DataTypes.DT_STRING.createAttributeValue("false")); + bagBooleansTrue = new Bag(); + bagBooleansTrue.add(DataTypes.DT_BOOLEAN.createAttributeValue(false)); + bagBooleansTrue.add(DataTypes.DT_BOOLEAN.createAttributeValue(false)); + bagBooleansTrue.add(DataTypes.DT_BOOLEAN.createAttributeValue(true)); + bagBooleansFalse = new Bag(); + bagBooleansFalse.add(DataTypes.DT_BOOLEAN.createAttributeValue(false)); + bagBooleansFalse.add(DataTypes.DT_BOOLEAN.createAttributeValue(false)); + + + // create primitive attrs + attra = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(a)); + attrh = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(h)); + + + + // predicates passed as function arguments + attrPredicateStringEqual = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_EQUAL)); + attrPredicateStringIntersection = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_INTERSECTION)); + attrPredicateStringGreaterThan = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_GREATER_THAN)); + attrPredicateBooleanFromString = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_BOOLEAN_FROM_STRING)); + + } catch (Exception ex) { + fail("creating attribute e="+ ex); + } + + // make into attributes + FunctionArgumentBag attrBagabcdefg = new FunctionArgumentBag(bagabcdefg); + FunctionArgumentBag attrBagace = new FunctionArgumentBag(bagace); + FunctionArgumentBag attrBagawx = new FunctionArgumentBag(bagawx); + FunctionArgumentBag attrBagwx = new FunctionArgumentBag(bagwx); + FunctionArgumentBag attrBagStringInt = new FunctionArgumentBag(bagStringInt); + FunctionArgumentBag attrBagEmpty = new FunctionArgumentBag(bagEmpty); + FunctionArgumentBag attrBagStringBooleansTrue = new FunctionArgumentBag(bagStringBooleansTrue); + + FunctionDefinitionHigherOrderBag fd = (FunctionDefinitionHigherOrderBag) StdFunctions.FD_ALL_OF_ALL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_ALL_OF_ALL, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + // normal match + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrBagwx); + arguments.add(attrBagace); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // normal no-match + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrBagawx); + arguments.add(attrBagace); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrBagace); + arguments.add(attrBagwx); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // primitive instead of bag + arguments.clear(); + arguments.add(attrPredicateStringEqual); + arguments.add(attra); + arguments.add(attrBagace); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of-all 2nd argument must be bag, got 'string'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + arguments.add(attrPredicateStringEqual); + arguments.add(attrBagace); + arguments.add(attra); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of-all 3rd argument must be bag, got 'string'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // no primitives - predicate expects only 1 arg + arguments.clear(); + arguments.add(attrPredicateBooleanFromString); + arguments.add(attrBagStringBooleansTrue); + arguments.add(attrBagStringBooleansTrue); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of-all Predicate error: function:boolean-from-string Expected 1 arguments, got 2", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bag is empty + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrBagace); + arguments.add(attrBagEmpty); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrBagEmpty); + arguments.add(attrBagace); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // no bag + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrh); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of-all Expected 3 arguments, got 2", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // bad predicate + arguments.clear(); + arguments.add(attrh); + arguments.add(attrBagStringInt); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of-all First argument expected URI, got http://www.w3.org/2001/XMLSchema#string", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // non-boolean predicate + arguments.clear(); + arguments.add(attrPredicateStringIntersection); + arguments.add(attrBagStringInt); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of-all Predicate Function must return boolean, but 'urn:oasis:names:tc:xacml:1.0:function:string-intersection' returns 'string", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // predicate after first arg + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrPredicateStringIntersection); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of-all 2nd argument must be bag, got 'anyURI'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bags of different types + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrBagwx); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of-all Predicate error: function:string-greater-than Expected data type 'string' saw 'integer' at arg index 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // no args + arguments.clear(); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of-all Expected at least 2 arguments, got 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // one arg + arguments.clear(); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of-all Expected at least 2 arguments, got 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // too many args + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBagabcdefg); + arguments.add(attrBagabcdefg); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of-all Expected 3 arguments, got 4", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // first null + arguments.clear(); + arguments.add(null); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of-all Expected 3 arguments, got 2", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // second null + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrBagabcdefg); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of-all 3rd argument must be bag, got 'null'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + + + + + + + + + @Test + public void testMap() { + String a = "a"; + String b = "b"; + String c = "c"; + String d = "d"; + String e = "e"; + String f = "f"; + String g = "g"; + String h = "h"; + String j = "j"; + + + Bag bagabcdefg = null; + Bag bagbdfhj = null; + Bag bagace = null; + Bag bagb = null; + Bag bagaaacccef = null; + Bag bagInt = null; + Bag bagStringInt = null; + Bag bagEmpty = null; + Bag bagStringBooleansFalse = null; + Bag bagStringBooleansTrue = null; + Bag bagInt123 = null; + Bag bagInt789 = null; + + + // primitive attrs + FunctionArgumentAttributeValue attrh = null; + FunctionArgumentAttributeValue attrInt7 = null; + + + + // predicates passed as arguments + FunctionArgumentAttributeValue attrPredicateStringNormalizeToLowerCase = null; + FunctionArgumentAttributeValue attrPredicateIntegerEqual = null; + FunctionArgumentAttributeValue attrPredicateIntegerAdd = null; + + try { + + // Create Bag contents + bagabcdefg = new Bag(); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(d)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(g)); + bagbdfhj = new Bag(); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(d)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(h)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(j)); + bagace = new Bag(); + bagace.add(DataTypes.DT_STRING.createAttributeValue("A")); + bagace.add(DataTypes.DT_STRING.createAttributeValue("C")); + bagace.add(DataTypes.DT_STRING.createAttributeValue("E")); + bagb = new Bag(); + bagb.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagaaacccef = new Bag(); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagInt = new Bag(); + bagInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); + bagStringInt = new Bag(); + bagStringInt.add(DataTypes.DT_STRING.createAttributeValue(a)); + + bagStringInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); + bagEmpty = new Bag(); + bagStringBooleansTrue = new Bag(); + bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("true")); + bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("true")); + bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("true")); + bagStringBooleansFalse = new Bag(); + bagStringBooleansFalse.add(DataTypes.DT_STRING.createAttributeValue("false")); + bagStringBooleansFalse.add(DataTypes.DT_STRING.createAttributeValue("false")); + bagInt123 = new Bag(); + bagInt123.add(DataTypes.DT_INTEGER.createAttributeValue(1)); + bagInt123.add(DataTypes.DT_INTEGER.createAttributeValue(2)); + bagInt123.add(DataTypes.DT_INTEGER.createAttributeValue(3)); + bagInt789 = new Bag(); + bagInt789.add(DataTypes.DT_INTEGER.createAttributeValue(7)); + bagInt789.add(DataTypes.DT_INTEGER.createAttributeValue(8)); + bagInt789.add(DataTypes.DT_INTEGER.createAttributeValue(9)); + + + + // create primitive attrs + attrh = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(h)); + attrInt7 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(7)); + + + // predicates passed as function arguments + attrPredicateStringNormalizeToLowerCase = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_NORMALIZE_TO_LOWER_CASE)); + attrPredicateIntegerEqual = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_INTEGER_EQUAL)); + attrPredicateIntegerAdd = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_INTEGER_ADD)); + + } catch (Exception ex) { + fail("creating attribute e="+ ex); + } + + // make into attributes + FunctionArgumentBag attrBagabcdefg = new FunctionArgumentBag(bagabcdefg); + FunctionArgumentBag attrBagace = new FunctionArgumentBag(bagace); + FunctionArgumentBag attrBagStringInt = new FunctionArgumentBag(bagStringInt); + FunctionArgumentBag attrBagEmpty = new FunctionArgumentBag(bagEmpty); + FunctionArgumentBag attrBagStringBooleansTrue = new FunctionArgumentBag(bagStringBooleansTrue); + FunctionArgumentBag attrBagInt789 = new FunctionArgumentBag(bagInt789); + + FunctionDefinitionHigherOrderBag fd = (FunctionDefinitionHigherOrderBag) StdFunctions.FD_MAP; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_MAP, fd.getId()); + assertNull( fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertTrue(fd.returnsBag()); + + // normal match + arguments.clear(); + arguments.add(attrPredicateStringNormalizeToLowerCase); + arguments.add(attrBagace); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertTrue(res.isBag()); + Bag bag = res.getBag(); + assertEquals(3, bag.size()); + List> bagAttributes = bag.getAttributeValueList(); + try { + assertTrue(bagAttributes.contains(DataTypes.DT_STRING.createAttributeValue("a"))); + assertFalse(bagAttributes.contains(DataTypes.DT_STRING.createAttributeValue("A"))); + assertTrue(bagAttributes.contains(DataTypes.DT_STRING.createAttributeValue("c"))); + assertFalse(bagAttributes.contains(DataTypes.DT_STRING.createAttributeValue("C"))); + assertTrue(bagAttributes.contains(DataTypes.DT_STRING.createAttributeValue("e"))); + assertFalse(bagAttributes.contains(DataTypes.DT_STRING.createAttributeValue("E"))); + } catch (Exception ex) { + fail("checking result e="+ex); + } + + // 2-input predicate + arguments.clear(); + arguments.add(attrPredicateIntegerAdd); + arguments.add(attrInt7); + arguments.add(attrBagInt789); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertTrue(res.isBag()); + bag = res.getBag(); + assertEquals(3, bag.size()); + bagAttributes = bag.getAttributeValueList(); + try { + assertTrue(bagAttributes.contains(DataTypes.DT_INTEGER.createAttributeValue("14"))); + assertTrue(bagAttributes.contains(DataTypes.DT_INTEGER.createAttributeValue("15"))); + assertTrue(bagAttributes.contains(DataTypes.DT_INTEGER.createAttributeValue("16"))); + } catch (Exception ex) { + fail("checking result e="+ex); + } + + + // predicate returns booleans + arguments.clear(); + arguments.add(attrPredicateIntegerEqual); + arguments.add(attrInt7); + arguments.add(attrBagInt789); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertTrue(res.isBag()); + bag = res.getBag(); + assertEquals(3, bag.size()); + bagAttributes = bag.getAttributeValueList(); + try { + assertEquals(bagAttributes.get(0), (DataTypes.DT_BOOLEAN.createAttributeValue(true))); + assertEquals(bagAttributes.get(1), (DataTypes.DT_BOOLEAN.createAttributeValue(false))); + assertEquals(bagAttributes.get(2), (DataTypes.DT_BOOLEAN.createAttributeValue(false))); + } catch (Exception ex) { + fail("checking result e="+ex); + } + + // predicate returns bag + + + + // no primitives - predicate function expects 2 + arguments.clear(); + arguments.add(attrPredicateIntegerAdd); + arguments.add(attrBagace); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:map Predicate error: function:integer-add Expected 2 arguments, got 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bag is empty + arguments.clear(); + arguments.add(attrPredicateStringNormalizeToLowerCase); + arguments.add(attrh); + arguments.add(attrBagEmpty); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertTrue(res.isBag()); + bag = res.getBag(); + assertEquals(0, bag.size());; + + // no bag + arguments.clear(); + arguments.add(attrPredicateStringNormalizeToLowerCase); + arguments.add(attrh); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:map Did not get any Bag argument; must have at least 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // extra bag + arguments.clear(); + arguments.add(attrPredicateStringNormalizeToLowerCase); + arguments.add(attrh); + arguments.add(attrBagStringBooleansTrue); + arguments.add(attrh); + arguments.add(attrBagStringBooleansTrue); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:map must have only 1 bag; found one at index 2 and another at 4", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // bad predicate + arguments.clear(); + arguments.add(attrh); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:map First argument expected URI, got http://www.w3.org/2001/XMLSchema#string", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // predicate gets unexpected number of args + arguments.clear(); + arguments.add(attrPredicateStringNormalizeToLowerCase); + arguments.add(attrh); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:map Predicate error: function:string-normalize-to-lower-case Expected 1 arguments, got 2", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // predicate gets bad primitive type + arguments.clear(); + arguments.add(attrPredicateStringNormalizeToLowerCase); + arguments.add(attrPredicateStringNormalizeToLowerCase); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:map Predicate error: function:string-normalize-to-lower-case Expected 1 arguments, got 2", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bags of different types + arguments.clear(); + arguments.add(attrPredicateStringNormalizeToLowerCase); + arguments.add(attrh); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + + // first null + arguments.clear(); + arguments.add(null); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:map Predicate Function (first argument) was null", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // second null + arguments.clear(); + arguments.add(attrPredicateStringNormalizeToLowerCase); + arguments.add(attrBagabcdefg); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:map Got null argument at index 2", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + + +} diff --git a/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionHomogeneousSimpleTest.java b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionHomogeneousSimpleTest.java new file mode 100644 index 000000000..6aee3383b --- /dev/null +++ b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionHomogeneousSimpleTest.java @@ -0,0 +1,151 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + + +package org.openecomp.policy.pdp.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +import com.att.research.xacml.api.Status; +import com.att.research.xacml.api.XACML3; +import com.att.research.xacml.std.datatypes.DataTypes; +import com.att.research.xacmlatt.pdp.policy.Bag; +import com.att.research.xacmlatt.pdp.policy.FunctionArgument; +import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; +import com.att.research.xacmlatt.pdp.policy.FunctionArgumentBag; +import com.att.research.xacmlatt.pdp.std.functions.*; + +/** + * FunctionDefinitionHomogeneousSimple is an abstract class, so we have to test it by creating a sub-class. + * The constructor is tested by default when an instance of the sub-class is created for other tests. + * + * Each of these functions needs to be tested for each type of function to be sure the values are correct, + * so this is just a simple test to see that the mechanism works. + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * + */ +public class FunctionDefinitionHomogeneousSimpleTest { + + + + @Test + public void testGetDataTypeArgs() { + + // test a simple instance using the Equality class + FunctionDefinitionEquality fd = new FunctionDefinitionEquality(XACML3.ID_FUNCTION_STRING_EQUAL, DataTypes.DT_STRING); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); + } + + @Test + public void testGetNumArgs() { + // test a simple instance using the Equality class + FunctionDefinitionEquality fd = new FunctionDefinitionEquality(XACML3.ID_FUNCTION_STRING_EQUAL, DataTypes.DT_STRING); + assertEquals(new Integer(2), fd.getNumArgs()); + } + + @Test + public void testValidateArguments() { + // create some arguments to use later + FunctionArgumentAttributeValue stringAttr1 = null; + FunctionArgumentAttributeValue stringAttr2 = null; + FunctionArgumentAttributeValue stringAttr3 = null; + FunctionArgumentAttributeValue intAttr = null; + try { + stringAttr1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("abc")); + stringAttr2 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("def")); + stringAttr3 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("ghi")); + intAttr = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1)); + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionEquality fd = new FunctionDefinitionEquality(XACML3.ID_FUNCTION_STRING_EQUAL, DataTypes.DT_STRING); + List convertedValues = new ArrayList(); + List listFunctionArguments = new ArrayList(); + + // test correct # of args, both of them strings + listFunctionArguments.add(stringAttr1); + listFunctionArguments.add(stringAttr2); + Status status = fd.validateArguments(listFunctionArguments, convertedValues); + assertTrue(status.isOk()); + assertEquals(convertedValues.size(),2); + + // test too few args + listFunctionArguments.remove(1); + status = fd.validateArguments(listFunctionArguments, convertedValues); + assertFalse(status.isOk()); + assertEquals("Expected 2 arguments, got 1", status.getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", status.getStatusCode().getStatusCodeValue().stringValue()); + + // test too many args + listFunctionArguments.add(stringAttr2); + listFunctionArguments.add(stringAttr3); + status = fd.validateArguments(listFunctionArguments, convertedValues); + assertFalse(status.isOk()); + assertEquals("Expected 2 arguments, got 3", status.getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", status.getStatusCode().getStatusCodeValue().stringValue()); + + // test with null arg + listFunctionArguments.clear(); + listFunctionArguments.add(null); + listFunctionArguments.add(stringAttr1); + status = fd.validateArguments(listFunctionArguments, convertedValues); + assertFalse(status.isOk()); + assertEquals("Got null argument at arg index 0", status.getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", status.getStatusCode().getStatusCodeValue().stringValue()); + + // test function that takes 0 args +//TODO test with func that specifies 0 args? ASSUME for now that there are no such functions since a function needs to operate on something +// fail("need to test function with 0 args and various inputs - see validateArguments code"); + + + // test with one is a bag + listFunctionArguments.clear(); + listFunctionArguments.add(stringAttr1); + Bag bag = new Bag(); + FunctionArgument bagArg = new FunctionArgumentBag(bag); + listFunctionArguments.add(bagArg); + status = fd.validateArguments(listFunctionArguments, convertedValues); + assertFalse(status.isOk()); + assertEquals("Expected a simple value, saw a bag at arg index 1", status.getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", status.getStatusCode().getStatusCodeValue().stringValue()); + + // test with string and int + listFunctionArguments.clear(); + listFunctionArguments.add(stringAttr1); + listFunctionArguments.add(intAttr); + status = fd.validateArguments(listFunctionArguments, convertedValues); + assertFalse(status.isOk()); + assertEquals("Expected data type 'string' saw 'integer' at arg index 1", status.getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", status.getStatusCode().getStatusCodeValue().stringValue()); + } + +} diff --git a/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionLogicalTest.java b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionLogicalTest.java new file mode 100644 index 000000000..615a8ecf1 --- /dev/null +++ b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionLogicalTest.java @@ -0,0 +1,422 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +import com.att.research.xacml.api.XACML3; +import com.att.research.xacml.std.datatypes.DataTypes; +import com.att.research.xacmlatt.pdp.policy.ExpressionResult; +import com.att.research.xacmlatt.pdp.policy.FunctionArgument; +import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; +import com.att.research.xacmlatt.pdp.std.StdFunctions; +import com.att.research.xacmlatt.pdp.std.functions.*; + +/** + * Test of PDP Functions (See XACML core spec section A.3) + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * + */ +public class FunctionDefinitionLogicalTest { + + /* + * variables useful in the following tests + */ + List arguments = new ArrayList(); + + // use the same args for each test + FunctionArgumentAttributeValue attrT = null; + FunctionArgumentAttributeValue attrF = null; + public FunctionDefinitionLogicalTest () { + try { + attrT = new FunctionArgumentAttributeValue(DataTypes.DT_BOOLEAN.createAttributeValue(true)); + attrF = new FunctionArgumentAttributeValue(DataTypes.DT_BOOLEAN.createAttributeValue(false)); + } catch (Exception e) { + fail("creating attribute e="+ e); + } + } + + + @Test + public void testOR() { + FunctionArgumentAttributeValue attr5 = null; + try { + attr5 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(5)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionLogical fd = (FunctionDefinitionLogical) StdFunctions.FD_OR; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_OR, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + + // test normal + arguments.add(attrT); + arguments.add(attrF); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertEquals(new Boolean(true), resValue); + + arguments.clear(); + arguments.add(attrF); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(new Boolean(false), resValue); + + // test no args + arguments.clear(); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(new Boolean(false), resValue); + + // first true, second error + arguments.clear(); + arguments.add(attrT); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(new Boolean(true), resValue); + + // first false, second error + arguments.clear(); + arguments.add(attrF); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:or Got null argument", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // multiple false + arguments.clear(); + arguments.add(attrF); + arguments.add(attrF); + arguments.add(attrF); + arguments.add(attrF); + arguments.add(attrF); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(new Boolean(false), resValue); + + // non-boolean + arguments.clear(); + arguments.add(attrF); + arguments.add(attr5); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:or Expected data type 'boolean' saw 'integer'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // first arg error + arguments.clear(); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:or Got null argument", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + @Test + public void testAND() { + FunctionArgumentAttributeValue attr5 = null; + try { + attr5 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(5)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + + FunctionDefinitionLogical fd = (FunctionDefinitionLogical) StdFunctions.FD_AND; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_AND, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + + // test normal + arguments.add(attrT); + arguments.add(attrF); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertEquals(new Boolean(false), resValue); + + arguments.clear(); + arguments.add(attrF); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(new Boolean(false), resValue); + + // test no args + arguments.clear(); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(new Boolean(true), resValue); + + // first true, second error + arguments.clear(); + arguments.add(attrT); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:and Got null argument", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // first false, second error + arguments.clear(); + arguments.add(attrF); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(new Boolean(false), resValue); + + // multiple true + arguments.clear(); + arguments.add(attrT); + arguments.add(attrT); + arguments.add(attrT); + arguments.add(attrT); + arguments.add(attrT); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(new Boolean(true), resValue); + + // non-boolean + arguments.clear(); + arguments.add(attrT); + arguments.add(attr5); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals("function:and Expected data type 'boolean' saw 'integer'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // first arg error + arguments.clear(); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals("function:and Got null argument", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + + + @Test + public void testN_of() { + FunctionArgumentAttributeValue attr0 = null; + FunctionArgumentAttributeValue attr2 = null; + try { + attr0 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(0)); + attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(2)); + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + + FunctionDefinitionLogical fd = (FunctionDefinitionLogical) StdFunctions.FD_N_OF; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_N_OF, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + + // test normal + arguments.add(attr2); + arguments.add(attrT); + arguments.add(attrF); + arguments.add(attrT); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertEquals(new Boolean(true), resValue); + + // normal fail + arguments.clear(); + arguments.add(attr2); + arguments.add(attrT); + arguments.add(attrF); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(new Boolean(false), resValue); + + + // null count + arguments.clear(); + arguments.add(null); + arguments.add(attrT); + arguments.add(attrF); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(new Boolean(true), resValue); + + // 0 count + arguments.clear(); + arguments.add(attr0); + arguments.add(attrT); + arguments.add(attrF); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(new Boolean(true), resValue); + + // bad object type for count + arguments.clear(); + arguments.add(attrT); + arguments.add(attrT); + arguments.add(attrF); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:n-of For input string: \"true\"", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // count larger than list + arguments.clear(); + arguments.add(attr2); + arguments.add(attrT); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:n-of Expected 2 arguments but only 1 arguments in list after the count", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // aborts after find ok + arguments.clear(); + arguments.add(attr2); + arguments.add(attrT); + arguments.add(attrT); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(new Boolean(true), resValue); + + // error before find ok + arguments.clear(); + arguments.add(attr2); + arguments.add(null); + arguments.add(attrT); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:n-of Got null argument", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // non-boolean in list + arguments.clear(); + arguments.add(attr2); + arguments.add(attrT); + arguments.add(attr0); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:n-of Expected data type 'boolean' saw 'integer'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + @Test + public void testNot() { + + FunctionDefinitionLogical fd = (FunctionDefinitionLogical) StdFunctions.FD_NOT; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_NOT, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + + // test normal + arguments.clear(); + arguments.add(attrT); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertEquals(new Boolean(false), resValue); + + arguments.clear(); + arguments.add(attrF); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(new Boolean(true), resValue); + + + // test null/0 args + arguments.clear(); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:not Expected 1 argument, got 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // test 2 args + arguments.clear(); + arguments.add(attrT); + arguments.add(attrF); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:not Expected 1 argument, got 2", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } +} diff --git a/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionNumberTypeConversionTest.java b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionNumberTypeConversionTest.java new file mode 100644 index 000000000..2b7dbf4e2 --- /dev/null +++ b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionNumberTypeConversionTest.java @@ -0,0 +1,119 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +import com.att.research.xacml.api.XACML3; +import com.att.research.xacml.std.datatypes.DataTypes; +import com.att.research.xacmlatt.pdp.policy.ExpressionResult; +import com.att.research.xacmlatt.pdp.policy.FunctionArgument; +import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; +import com.att.research.xacmlatt.pdp.std.StdFunctions; +import com.att.research.xacmlatt.pdp.std.functions.*; + +/** + * Tests for various classes containing only one function. + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * + */ +public class FunctionDefinitionNumberTypeConversionTest { + + /* + * variables useful in the following tests + */ + List arguments = new ArrayList(); + + @Test + public void testDouble_to_integer() { + FunctionArgumentAttributeValue attr1 = null; + try { + attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(5.432)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionNumberTypeConversion fd = (FunctionDefinitionNumberTypeConversion) StdFunctions.FD_DOUBLE_TO_INTEGER; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DOUBLE_TO_INTEGER, fd.getId()); + assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + + // test normal add + arguments.add(attr1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + BigInteger resValue = (BigInteger)res.getValue().getValue(); + assertEquals(BigInteger.valueOf(5), resValue); + } + + + @Test + public void testInteger_to_double() { + FunctionArgumentAttributeValue attr1 = null; + try { + attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(5)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionNumberTypeConversion fd = (FunctionDefinitionNumberTypeConversion) StdFunctions.FD_INTEGER_TO_DOUBLE; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_INTEGER_TO_DOUBLE, fd.getId()); + assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + + // test normal add + arguments.add(attr1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Double resValue = (Double)res.getValue().getValue(); + assertEquals(new Double(5.0), resValue); + } + + +} diff --git a/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionRegexpMatchTest.java b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionRegexpMatchTest.java new file mode 100644 index 000000000..631dca910 --- /dev/null +++ b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionRegexpMatchTest.java @@ -0,0 +1,511 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.net.URI; +import java.util.ArrayList; +import java.util.List; + +import javax.security.auth.x500.X500Principal; + +import org.junit.Test; + +import com.att.research.xacml.api.XACML3; +import com.att.research.xacml.std.datatypes.DataTypes; +import com.att.research.xacml.std.datatypes.IPAddress; +import com.att.research.xacml.std.datatypes.RFC2396DomainName; +import com.att.research.xacml.std.datatypes.RFC822Name; +import com.att.research.xacmlatt.pdp.policy.ExpressionResult; +import com.att.research.xacmlatt.pdp.policy.FunctionArgument; +import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; +import com.att.research.xacmlatt.pdp.std.StdFunctions; +import com.att.research.xacmlatt.pdp.std.functions.*; + +/** + * Test of PDP Functions (See XACML core spec section A.3) + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * + */ +public class FunctionDefinitionRegexpMatchTest { + + + /* + * variables useful in the following tests + */ + List arguments = new ArrayList(); + + + @Test + public void testString() { + String v1 = new String("abc"); + String v2 = new String("def"); + + + FunctionArgumentAttributeValue attrV1 = null; + FunctionArgumentAttributeValue attrV2 = null; + FunctionArgumentAttributeValue attrNull = null; + FunctionArgumentAttributeValue attrInteger = null; + try { + attrV1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(v1)); + attrV2 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(v2)); + attrNull = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(null)); + attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234)); + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + FunctionDefinitionRegexpMatch fd = (FunctionDefinitionRegexpMatch) StdFunctions.FD_STRING_REGEXP_MATCH; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_REGEXP_MATCH, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + + // match + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrV1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertEquals(true, resValue); + + // no match + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrV2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // null regex + arguments.clear(); + arguments.add(null); + arguments.add(attrV2); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-regexp-match Got null argument", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + arguments.clear(); + arguments.add(attrNull); + arguments.add(attrV2); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-regexp-match Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null object to match + arguments.clear(); + arguments.add(attrV1); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-regexp-match Got null argument", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrNull); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-regexp-match Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // regex not string + arguments.clear(); + arguments.add(attrInteger); + arguments.add(attrV2); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-regexp-match Expected data type 'string' saw 'integer'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // object to match not correct type + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrInteger); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-regexp-match Expected data type 'string' saw 'integer'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + @Test + public void testAnyURI() { + String regexp = new String("abc"); + URI uri1 = null; + URI uri2 = null; + try { + uri1 = new URI("abc"); + uri2 = new URI("def"); + } catch (Exception e) { + fail("Unable to create URIs, e="+e); + } + + + FunctionArgumentAttributeValue attrRegexp = null; + FunctionArgumentAttributeValue attrUri1 = null; + FunctionArgumentAttributeValue attrUri2 = null; + FunctionArgumentAttributeValue attrInteger = null; + try { + attrRegexp = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(regexp)); + attrUri1 = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(uri1)); + attrUri2 = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(uri2)); + attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234)); + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + FunctionDefinitionRegexpMatch fd = (FunctionDefinitionRegexpMatch) StdFunctions.FD_ANYURI_REGEXP_MATCH; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_ANYURI_REGEXP_MATCH, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + + // match + arguments.clear(); + arguments.add(attrRegexp); + arguments.add(attrUri1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertEquals(true, resValue); + + // no match + arguments.clear(); + arguments.add(attrRegexp); + arguments.add(attrUri2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // object to match not correct type + arguments.clear(); + arguments.add(attrRegexp); + arguments.add(attrInteger); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:anyURI-regexp-match Expected data type 'anyURI' saw 'integer'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + @Test + public void testIpAddress() { + String regexp = new String(".*123.*"); + IPAddress addr1 = null; + IPAddress addr2 = null; + try { + addr1 = IPAddress.newInstance("10.123.45.67"); + addr2 = IPAddress.newInstance("10.12.13.14"); + } catch (Exception e) { + fail("Unable to create IPAddresses, e="+e); + } + + + FunctionArgumentAttributeValue attrRegexp = null; + FunctionArgumentAttributeValue attrAddr1 = null; + FunctionArgumentAttributeValue attrAddr2 = null; + FunctionArgumentAttributeValue attrInteger = null; + try { + attrRegexp = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(regexp)); + attrAddr1 = new FunctionArgumentAttributeValue(DataTypes.DT_IPADDRESS.createAttributeValue(addr1)); + attrAddr2 = new FunctionArgumentAttributeValue(DataTypes.DT_IPADDRESS.createAttributeValue(addr2)); + attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234)); + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + FunctionDefinitionRegexpMatch fd = (FunctionDefinitionRegexpMatch) StdFunctions.FD_IPADDRESS_REGEXP_MATCH; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_IPADDRESS_REGEXP_MATCH, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + + // match + arguments.clear(); + arguments.add(attrRegexp); + arguments.add(attrAddr1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertEquals(true, resValue); + + // no match + arguments.clear(); + arguments.add(attrRegexp); + arguments.add(attrAddr2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // object to match not correct type + arguments.clear(); + arguments.add(attrRegexp); + arguments.add(attrInteger); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:ipAddress-regexp-match Expected data type 'ipAddress' saw 'integer'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + @Test + public void testDnsName() { + String regexp = new String("abc"); + RFC2396DomainName addr1 = null; + RFC2396DomainName addr2 = null; + try { + addr1 = RFC2396DomainName.newInstance("abc"); + addr2 = RFC2396DomainName.newInstance("def"); + } catch (Exception e) { + fail("Unable to create DNSNames, e="+e); + } + + + FunctionArgumentAttributeValue attrRegexp = null; + FunctionArgumentAttributeValue attrAddr1 = null; + FunctionArgumentAttributeValue attrAddr2 = null; + FunctionArgumentAttributeValue attrInteger = null; + try { + attrRegexp = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(regexp)); + attrAddr1 = new FunctionArgumentAttributeValue(DataTypes.DT_DNSNAME.createAttributeValue(addr1)); + attrAddr2 = new FunctionArgumentAttributeValue(DataTypes.DT_DNSNAME.createAttributeValue(addr2)); + attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234)); + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + FunctionDefinitionRegexpMatch fd = (FunctionDefinitionRegexpMatch) StdFunctions.FD_DNSNAME_REGEXP_MATCH; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DNSNAME_REGEXP_MATCH, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + + // match + arguments.clear(); + arguments.add(attrRegexp); + arguments.add(attrAddr1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertEquals(true, resValue); + + // no match + arguments.clear(); + arguments.add(attrRegexp); + arguments.add(attrAddr2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // object to match not correct type + arguments.clear(); + arguments.add(attrRegexp); + arguments.add(attrInteger); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dnsName-regexp-match Expected data type 'dnsName' saw 'integer'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + @Test + public void testRfc822Name() { + String regexp = new String(".*abc.*"); + RFC822Name addr1 = null; + RFC822Name addr2 = null; + try { + addr1 = RFC822Name.newInstance("abc@somewhere"); + addr2 = RFC822Name.newInstance("def@somewhere"); + } catch (Exception e) { + fail("Unable to create RFC822Names, e="+e); + } + + + FunctionArgumentAttributeValue attrRegexp = null; + FunctionArgumentAttributeValue attrAddr1 = null; + FunctionArgumentAttributeValue attrAddr2 = null; + FunctionArgumentAttributeValue attrInteger = null; + try { + attrRegexp = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(regexp)); + attrAddr1 = new FunctionArgumentAttributeValue(DataTypes.DT_RFC822NAME.createAttributeValue(addr1)); + attrAddr2 = new FunctionArgumentAttributeValue(DataTypes.DT_RFC822NAME.createAttributeValue(addr2)); + attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234)); + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + FunctionDefinitionRegexpMatch fd = (FunctionDefinitionRegexpMatch) StdFunctions.FD_RFC822NAME_REGEXP_MATCH; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_RFC822NAME_REGEXP_MATCH, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + + // match + arguments.clear(); + arguments.add(attrRegexp); + arguments.add(attrAddr1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertEquals(true, resValue); + + // no match + arguments.clear(); + arguments.add(attrRegexp); + arguments.add(attrAddr2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // object to match not correct type + arguments.clear(); + arguments.add(attrRegexp); + arguments.add(attrInteger); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:rfc822Name-regexp-match Expected data type 'rfc822Name' saw 'integer'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + @Test + public void testX500Name() { + String regexp = new String(".*Duke.*"); + X500Principal addr1 = null; + X500Principal addr2 = null; + try { + addr1 = new X500Principal("CN=Duke, OU=JavaSoft, O=Sun Microsystems, C=US"); + addr2 = new X500Principal("CN=Policy Engine, OU=Research, O=ATT, C=US"); + } catch (Exception e) { + fail("Unable to create X500Name, e="+e); + } + + + FunctionArgumentAttributeValue attrRegexp = null; + FunctionArgumentAttributeValue attrAddr1 = null; + FunctionArgumentAttributeValue attrAddr2 = null; + FunctionArgumentAttributeValue attrInteger = null; + try { + attrRegexp = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(regexp)); + attrAddr1 = new FunctionArgumentAttributeValue(DataTypes.DT_X500NAME.createAttributeValue(addr1)); + attrAddr2 = new FunctionArgumentAttributeValue(DataTypes.DT_X500NAME.createAttributeValue(addr2)); + attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234)); + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + FunctionDefinitionRegexpMatch fd = (FunctionDefinitionRegexpMatch) StdFunctions.FD_X500NAME_REGEXP_MATCH; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_X500NAME_REGEXP_MATCH, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + + // match + arguments.clear(); + arguments.add(attrRegexp); + arguments.add(attrAddr1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertEquals(true, resValue); + + // no match + arguments.clear(); + arguments.add(attrRegexp); + arguments.add(attrAddr2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // object to match not correct type + arguments.clear(); + arguments.add(attrRegexp); + arguments.add(attrInteger); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:x500Name-regexp-match Expected data type 'x500Name' saw 'integer'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + + +} diff --git a/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionSetTest.java b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionSetTest.java new file mode 100644 index 000000000..cbc71e78d --- /dev/null +++ b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionSetTest.java @@ -0,0 +1,1903 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.junit.Test; + +import com.att.research.xacml.api.AttributeValue; +import com.att.research.xacml.api.XACML3; +import com.att.research.xacml.std.datatypes.DataTypes; +import com.att.research.xacmlatt.pdp.policy.Bag; +import com.att.research.xacmlatt.pdp.policy.ExpressionResult; +import com.att.research.xacmlatt.pdp.policy.FunctionArgument; +import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; +import com.att.research.xacmlatt.pdp.policy.FunctionArgumentBag; +import com.att.research.xacmlatt.pdp.std.StdFunctions; +import com.att.research.xacmlatt.pdp.std.functions.*; + +/** + * Test of PDP Functions (See XACML core spec section A.3) + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * + */ +public class FunctionDefinitionSetTest { + + + /* + * variables useful in the following tests + */ + List arguments = new ArrayList(); + + + + // + // INTERSECTION tests + // + + + @Test + public void testString_intersection() { + String a = "a"; + String b = "b"; + String c = "c"; + String d = "d"; + String e = "e"; + String f = "f"; + String g = "g"; + String h = "h"; + String j = "j"; + + + Bag bagabcdefg = null; + Bag bagbdfhj = null; + Bag bagace = null; + Bag bagb = null; + Bag bagaaacccef = null; + Bag bagInt = null; + Bag bagStringInt = null; + Bag bagEmpty = null; + + FunctionArgumentAttributeValue attrBadType = null; + + try { + bagabcdefg = new Bag(); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(d)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(g)); + bagbdfhj = new Bag(); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(d)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(h)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(j)); + bagace = new Bag(); + bagace.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagace.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagace.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagb = new Bag(); + bagb.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagaaacccef = new Bag(); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagInt = new Bag(); + bagInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); + bagStringInt = new Bag(); + bagStringInt.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagStringInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); + bagEmpty = new Bag(); + + attrBadType = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.1)); + } catch (Exception ex) { + fail("creating attribute e="+ ex); + } + + // make into attributes + FunctionArgumentBag attrBagabcdefg = new FunctionArgumentBag(bagabcdefg); + FunctionArgumentBag attrBagbdfhj = new FunctionArgumentBag(bagbdfhj); + FunctionArgumentBag attrBagace = new FunctionArgumentBag(bagace); + FunctionArgumentBag attrBagb = new FunctionArgumentBag(bagb); + FunctionArgumentBag attrBagaaacccef = new FunctionArgumentBag(bagaaacccef); + FunctionArgumentBag attrBagInt = new FunctionArgumentBag(bagInt); + FunctionArgumentBag attrBagStringInt = new FunctionArgumentBag(bagStringInt); + FunctionArgumentBag attrBagEmpty = new FunctionArgumentBag(bagEmpty); + + FunctionDefinitionSet fd = (FunctionDefinitionSet) StdFunctions.FD_STRING_INTERSECTION; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_INTERSECTION, fd.getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertTrue(fd.returnsBag()); + + // normal intersection (everything in both bags, no duplicates) + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBagabcdefg); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Bag bag = res.getBag(); + assertNotNull(bag); + Iterator> it = bag.getAttributeValues(); + assertEquals(7, bag.size()); + AttributeValue attrValueObject = it.next(); + assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); + assertEquals(a, attrValueObject.getValue() ); + + // several but not all intersection + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBagbdfhj); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(3, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); + assertEquals(b, attrValueObject.getValue() ); + + // no intersection + arguments.clear(); + arguments.add(attrBagace); + arguments.add(attrBagbdfhj); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(0, bag.size()); + + // one intersection + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBagb); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(1, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); + assertEquals(b, attrValueObject.getValue() ); + + // bag one has duplicates that do not intersect + arguments.clear(); + arguments.add(attrBagaaacccef); + arguments.add(attrBagbdfhj); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(1, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); + assertEquals(f, attrValueObject.getValue() ); + + // bag one has duplicates that do intersect + arguments.clear(); + arguments.add(attrBagaaacccef); + arguments.add(attrBagace); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(3, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); + assertEquals(a, attrValueObject.getValue() ); + attrValueObject = it.next(); + assertEquals(c, attrValueObject.getValue() ); + attrValueObject = it.next(); + assertEquals(e, attrValueObject.getValue() ); + + // bag 2 has duplicates that do not intersect + arguments.clear(); + arguments.add(attrBagbdfhj); + arguments.add(attrBagaaacccef); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(1, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); + assertEquals(f, attrValueObject.getValue() ); + + // bag 2 has duplicates that intersect + arguments.clear(); + arguments.add(attrBagace); + arguments.add(attrBagaaacccef); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(3, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); + assertEquals(a, attrValueObject.getValue() ); + attrValueObject = it.next(); + assertEquals(c, attrValueObject.getValue() ); + attrValueObject = it.next(); + assertEquals(e, attrValueObject.getValue() ); + + // first bag is empty + arguments.clear(); + arguments.add(attrBagEmpty); + arguments.add(attrBagaaacccef); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(0, bag.size()); + + // second bag is empty + arguments.clear(); + arguments.add(attrBagace); + arguments.add(attrBagEmpty); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(0, bag.size()); + + // bags of different types + arguments.clear(); + arguments.add(attrBagace); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(1, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); + assertEquals(a, attrValueObject.getValue() ); + + arguments.clear(); + arguments.add(attrBagace); + arguments.add(attrBagInt); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(0, bag.size()); + + // first not a bag + arguments.clear(); + arguments.add(attrBadType); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-intersection Expected a bag, saw a simple value", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // second not a bag + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-intersection Expected a bag, saw a simple value", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // first null + arguments.clear(); + arguments.add(null); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-intersection Got null argument", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // second null + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-intersection Got null argument", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // too few args + arguments.clear(); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-intersection Expected 2 arguments, got 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-intersection Expected 2 arguments, got 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // too many args + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBagabcdefg); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-intersection Expected 2 arguments, got 3", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + + @Test + public void testInteger_intersection() { + BigInteger a = new BigInteger("1"); + BigInteger b = new BigInteger("2"); + BigInteger c = new BigInteger("3"); + BigInteger d = new BigInteger("4"); + BigInteger e = new BigInteger("5"); + BigInteger f = new BigInteger("6"); + BigInteger g = new BigInteger("7"); + BigInteger h = new BigInteger("8"); + BigInteger j = new BigInteger("9"); + + + Bag bagabcdefg = null; + Bag bagbdfhj = null; + Bag bagace = null; + Bag bagb = null; + Bag bagaaacccef = null; + Bag bagInt = null; + Bag bagStringInt = null; + Bag bagEmpty = null; + + FunctionArgumentAttributeValue attrBadType = null; + + try { + bagabcdefg = new Bag(); + bagabcdefg.add(DataTypes.DT_INTEGER.createAttributeValue(a)); + bagabcdefg.add(DataTypes.DT_INTEGER.createAttributeValue(b)); + bagabcdefg.add(DataTypes.DT_INTEGER.createAttributeValue(c)); + bagabcdefg.add(DataTypes.DT_INTEGER.createAttributeValue(d)); + bagabcdefg.add(DataTypes.DT_INTEGER.createAttributeValue(e)); + bagabcdefg.add(DataTypes.DT_INTEGER.createAttributeValue(f)); + bagabcdefg.add(DataTypes.DT_INTEGER.createAttributeValue(g)); + bagbdfhj = new Bag(); + bagbdfhj.add(DataTypes.DT_INTEGER.createAttributeValue(b)); + bagbdfhj.add(DataTypes.DT_INTEGER.createAttributeValue(d)); + bagbdfhj.add(DataTypes.DT_INTEGER.createAttributeValue(f)); + bagbdfhj.add(DataTypes.DT_INTEGER.createAttributeValue(h)); + bagbdfhj.add(DataTypes.DT_INTEGER.createAttributeValue(j)); + bagace = new Bag(); + bagace.add(DataTypes.DT_INTEGER.createAttributeValue(a)); + bagace.add(DataTypes.DT_INTEGER.createAttributeValue(c)); + bagace.add(DataTypes.DT_INTEGER.createAttributeValue(e)); + bagb = new Bag(); + bagb.add(DataTypes.DT_INTEGER.createAttributeValue(b)); + bagaaacccef = new Bag(); + bagaaacccef.add(DataTypes.DT_INTEGER.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_INTEGER.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_INTEGER.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_INTEGER.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_INTEGER.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_INTEGER.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_INTEGER.createAttributeValue(e)); + bagaaacccef.add(DataTypes.DT_INTEGER.createAttributeValue(f)); + bagInt = new Bag(); + bagInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); + bagStringInt = new Bag(); + bagStringInt.add(DataTypes.DT_STRING.createAttributeValue("abc")); + bagStringInt.add(DataTypes.DT_INTEGER.createAttributeValue(1)); + bagEmpty = new Bag(); + + attrBadType = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.1)); + } catch (Exception ex) { + fail("creating attribute e="+ ex); + } + + // make into attributes + FunctionArgumentBag attrBagabcdefg = new FunctionArgumentBag(bagabcdefg); + FunctionArgumentBag attrBagbdfhj = new FunctionArgumentBag(bagbdfhj); + FunctionArgumentBag attrBagace = new FunctionArgumentBag(bagace); + FunctionArgumentBag attrBagb = new FunctionArgumentBag(bagb); + FunctionArgumentBag attrBagaaacccef = new FunctionArgumentBag(bagaaacccef); + FunctionArgumentBag attrBagInt = new FunctionArgumentBag(bagInt); + FunctionArgumentBag attrBagStringInt = new FunctionArgumentBag(bagStringInt); + FunctionArgumentBag attrBagEmpty = new FunctionArgumentBag(bagEmpty); + + FunctionDefinitionSet fd = (FunctionDefinitionSet) StdFunctions.FD_INTEGER_INTERSECTION; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_INTEGER_INTERSECTION, fd.getId()); + assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertTrue(fd.returnsBag()); + + // normal intersection (everything in both bags, no duplicates) + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBagabcdefg); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Bag bag = res.getBag(); + assertNotNull(bag); + Iterator> it = bag.getAttributeValues(); + assertEquals(7, bag.size()); + AttributeValue attrValueObject = it.next(); + assertEquals(DataTypes.DT_INTEGER.getId(), attrValueObject.getDataTypeId()); + assertEquals(a, attrValueObject.getValue() ); + + // several but not all intersection + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBagbdfhj); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(3, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_INTEGER.getId(), attrValueObject.getDataTypeId()); + assertEquals(b, attrValueObject.getValue() ); + + // no intersection + arguments.clear(); + arguments.add(attrBagace); + arguments.add(attrBagbdfhj); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(0, bag.size()); + + // one intersection + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBagb); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(1, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_INTEGER.getId(), attrValueObject.getDataTypeId()); + assertEquals(b, attrValueObject.getValue() ); + + // bag one has duplicates that do not intersect + arguments.clear(); + arguments.add(attrBagaaacccef); + arguments.add(attrBagbdfhj); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(1, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_INTEGER.getId(), attrValueObject.getDataTypeId()); + assertEquals(f, attrValueObject.getValue() ); + + // bag one has duplicates that do intersect + arguments.clear(); + arguments.add(attrBagaaacccef); + arguments.add(attrBagace); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(3, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_INTEGER.getId(), attrValueObject.getDataTypeId()); + assertEquals(a, attrValueObject.getValue() ); + attrValueObject = it.next(); + assertEquals(c, attrValueObject.getValue() ); + attrValueObject = it.next(); + assertEquals(e, attrValueObject.getValue() ); + + // bag 2 has duplicates that do not intersect + arguments.clear(); + arguments.add(attrBagbdfhj); + arguments.add(attrBagaaacccef); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(1, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_INTEGER.getId(), attrValueObject.getDataTypeId()); + assertEquals(f, attrValueObject.getValue() ); + + // bag 2 has duplicates that intersect + arguments.clear(); + arguments.add(attrBagace); + arguments.add(attrBagaaacccef); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(3, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_INTEGER.getId(), attrValueObject.getDataTypeId()); + assertEquals(a, attrValueObject.getValue() ); + attrValueObject = it.next(); + assertEquals(c, attrValueObject.getValue() ); + attrValueObject = it.next(); + assertEquals(e, attrValueObject.getValue() ); + + // first bag is empty + arguments.clear(); + arguments.add(attrBagEmpty); + arguments.add(attrBagaaacccef); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(0, bag.size()); + + // second bag is empty + arguments.clear(); + arguments.add(attrBagbdfhj); + arguments.add(attrBagEmpty); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(0, bag.size()); + + // bags of different types + arguments.clear(); + arguments.add(attrBagace); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(1, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_INTEGER.getId(), attrValueObject.getDataTypeId()); + assertEquals(a, attrValueObject.getValue() ); + + arguments.clear(); + arguments.add(attrBagace); + arguments.add(attrBagInt); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(1, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_INTEGER.getId(), attrValueObject.getDataTypeId()); + assertEquals(a, attrValueObject.getValue() ); + + + // first not a bag + arguments.clear(); + arguments.add(attrBadType); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:integer-intersection Expected a bag, saw a simple value", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // second not a bag + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:integer-intersection Expected a bag, saw a simple value", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // first null + arguments.clear(); + arguments.add(null); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:integer-intersection Got null argument", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // second null + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:integer-intersection Got null argument", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // too few args + arguments.clear(); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:integer-intersection Expected 2 arguments, got 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:integer-intersection Expected 2 arguments, got 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // too many args + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBagabcdefg); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:integer-intersection Expected 2 arguments, got 3", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + + + + + + + + + + + + // + // AT_LEAST_ONE_MEMBER_OF tests + // + + @Test + public void testString_at_least_one_member_of() { + String a = "a"; + String b = "b"; + String c = "c"; + String d = "d"; + String e = "e"; + String f = "f"; + String g = "g"; + String h = "h"; + String j = "j"; + + + Bag bagabcdefg = null; + Bag bagbdfhj = null; + Bag bagace = null; + Bag bagb = null; + Bag bagaaaccce = null; + Bag bagInt = null; + Bag bagStringInt = null; + Bag bagEmpty = null; + + FunctionArgumentAttributeValue attrBadType = null; + + try { + bagabcdefg = new Bag(); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(d)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(g)); + bagbdfhj = new Bag(); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(d)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(h)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(j)); + bagace = new Bag(); + bagace.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagace.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagace.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagb = new Bag(); + bagb.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagaaaccce = new Bag(); + bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagInt = new Bag(); + bagInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); + bagStringInt = new Bag(); + bagStringInt.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagStringInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); + bagEmpty = new Bag(); + + attrBadType = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.1)); + } catch (Exception ex) { + fail("creating attribute e="+ ex); + } + + // make into attributes + FunctionArgumentBag attrBagabcdefg = new FunctionArgumentBag(bagabcdefg); + FunctionArgumentBag attrBagbdfhj = new FunctionArgumentBag(bagbdfhj); + FunctionArgumentBag attrBagace = new FunctionArgumentBag(bagace); + FunctionArgumentBag attrBagb = new FunctionArgumentBag(bagb); + FunctionArgumentBag attrBagaaaccce = new FunctionArgumentBag(bagaaaccce); + FunctionArgumentBag attrBagInt = new FunctionArgumentBag(bagInt); + FunctionArgumentBag attrBagStringInt = new FunctionArgumentBag(bagStringInt); + FunctionArgumentBag attrBagEmpty = new FunctionArgumentBag(bagEmpty); + + FunctionDefinitionSet fd = (FunctionDefinitionSet) StdFunctions.FD_STRING_AT_LEAST_ONE_MEMBER_OF; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_AT_LEAST_ONE_MEMBER_OF, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + // normal intersection (everything in both bags, no duplicates) + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBagabcdefg); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + + // several but not all intersection + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBagbdfhj); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // no intersection + arguments.clear(); + arguments.add(attrBagace); + arguments.add(attrBagbdfhj); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // one intersection + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBagb); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // bag one has duplicates that do not intersect + arguments.clear(); + arguments.add(attrBagaaaccce); + arguments.add(attrBagbdfhj); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // bag one has duplicates that do intersect + arguments.clear(); + arguments.add(attrBagaaaccce); + arguments.add(attrBagace); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // bag 2 has duplicates that do not intersect + arguments.clear(); + arguments.add(attrBagbdfhj); + arguments.add(attrBagaaaccce); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // bag 2 has duplicates that intersect + arguments.clear(); + arguments.add(attrBagace); + arguments.add(attrBagaaaccce); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // 2 empty bags + arguments.clear(); + arguments.add(attrBagEmpty); + arguments.add(attrBagEmpty); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first non-empty, 2nd empty + arguments.clear(); + arguments.add(attrBagaaaccce); + arguments.add(attrBagEmpty); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first empty, 2nd not empty + arguments.clear(); + arguments.add(attrBagEmpty); + arguments.add(attrBagaaaccce); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // bags of different types + arguments.clear(); + arguments.add(attrBagace); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + arguments.clear(); + arguments.add(attrBagace); + arguments.add(attrBagInt); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + arguments.clear(); + arguments.add(attrBagace); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // first not a bag + arguments.clear(); + arguments.add(attrBadType); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-at-least-one-member-of Expected a bag, saw a simple value", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // second not a bag + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-at-least-one-member-of Expected a bag, saw a simple value", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // first null + arguments.clear(); + arguments.add(null); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-at-least-one-member-of Got null argument", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // second null + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-at-least-one-member-of Got null argument", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // too few args + arguments.clear(); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-at-least-one-member-of Expected 2 arguments, got 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-at-least-one-member-of Expected 2 arguments, got 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // too many args + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBagabcdefg); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-at-least-one-member-of Expected 2 arguments, got 3", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + + + + + + + + + + + + // + // UNION tests + // + + + + + + @Test + public void testString_union() { + String a = "a"; + String b = "b"; + String c = "c"; + String d = "d"; + String e = "e"; + String f = "f"; + String g = "g"; + String h = "h"; + String j = "j"; + + + Bag bagabcdefg = null; + Bag bagbdfhj = null; + Bag bagace = null; + Bag bagaaacccef = null; + Bag bagInt = null; + Bag bagStringInt = null; + Bag bagEmpty = null; + + FunctionArgumentAttributeValue attrBadType = null; + + try { + bagabcdefg = new Bag(); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(d)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(g)); + bagbdfhj = new Bag(); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(d)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(h)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(j)); + bagace = new Bag(); + bagace.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagace.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagace.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagaaacccef = new Bag(); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagInt = new Bag(); + bagInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); + bagStringInt = new Bag(); + bagStringInt.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagStringInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); + bagEmpty = new Bag(); + + attrBadType = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.1)); + } catch (Exception ex) { + fail("creating attribute e="+ ex); + } + + // make into attributes + FunctionArgumentBag attrBagabcdefg = new FunctionArgumentBag(bagabcdefg); + FunctionArgumentBag attrBagbdfhj = new FunctionArgumentBag(bagbdfhj); + FunctionArgumentBag attrBagace = new FunctionArgumentBag(bagace); + FunctionArgumentBag attrBagaaacccef = new FunctionArgumentBag(bagaaacccef); + FunctionArgumentBag attrBagInt = new FunctionArgumentBag(bagInt); + FunctionArgumentBag attrBagStringInt = new FunctionArgumentBag(bagStringInt); + FunctionArgumentBag attrBagEmpty = new FunctionArgumentBag(bagEmpty); + + FunctionDefinitionSet fd = (FunctionDefinitionSet) StdFunctions.FD_STRING_UNION; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_UNION, fd.getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertTrue(fd.returnsBag()); + + // normal intersection (everything in both bags, no duplicates) + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBagabcdefg); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Bag bag = res.getBag(); + assertNotNull(bag); + Iterator> it = bag.getAttributeValues(); + assertEquals(7, bag.size()); + AttributeValue attrValueObject = it.next(); + assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); + assertEquals(a, attrValueObject.getValue() ); + + // several but not all union + arguments.clear(); + arguments.add(attrBagace); + arguments.add(attrBagbdfhj); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(8, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); + assertEquals(a, attrValueObject.getValue() ); + + // bag one has duplicates that do not match first bag + arguments.clear(); + arguments.add(attrBagaaacccef); + arguments.add(attrBagbdfhj); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(8, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); + assertEquals(a, attrValueObject.getValue() ); + + // bag one has duplicates that do match first bag + arguments.clear(); + arguments.add(attrBagaaacccef); + arguments.add(attrBagace); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(4, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); + assertEquals(a, attrValueObject.getValue() ); + attrValueObject = it.next(); + assertEquals(c, attrValueObject.getValue() ); + attrValueObject = it.next(); + assertEquals(e, attrValueObject.getValue() ); + + // bag 2 has duplicates that do not match first bag + arguments.clear(); + arguments.add(attrBagbdfhj); + arguments.add(attrBagaaacccef); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(8, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); + assertEquals(b, attrValueObject.getValue() ); + + // bag 2 has duplicates that do match first bag + arguments.clear(); + arguments.add(attrBagace); + arguments.add(attrBagaaacccef); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(4, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); + assertEquals(a, attrValueObject.getValue() ); + attrValueObject = it.next(); + assertEquals(c, attrValueObject.getValue() ); + attrValueObject = it.next(); + assertEquals(e, attrValueObject.getValue() ); + + // two empty bags + arguments.clear(); + arguments.add(attrBagEmpty); + arguments.add(attrBagEmpty); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(0, bag.size()); + + // first bag empty, 2nd not empty + arguments.clear(); + arguments.add(attrBagEmpty); + arguments.add(attrBagaaacccef); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(4, bag.size()); + + // first bag not empty, 2nd empty + arguments.clear(); + arguments.add(attrBagaaacccef); + arguments.add(attrBagEmpty); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(4, bag.size()); + + // bags of different types + arguments.clear(); + arguments.add(attrBagace); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(4, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); + assertEquals(a, attrValueObject.getValue() ); + + arguments.clear(); + arguments.add(attrBagace); + arguments.add(attrBagInt); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(4, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); + assertEquals(a, attrValueObject.getValue() ); + + // first not a bag + arguments.clear(); + arguments.add(attrBadType); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-union Expected a bag, saw a simple value", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // second not a bag + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-union Expected a bag, saw a simple value", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // first null + arguments.clear(); + arguments.add(null); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-union Got null argument", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // second null + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-union Got null argument", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // too few args + arguments.clear(); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-union Expected 2 arguments, got 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-union Expected 2 arguments, got 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // too many args + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBagabcdefg); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-union Expected 2 arguments, got 3", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + + + + + + + + + // + // SUBSET tests + // + + @Test + public void testString_subset() { + String a = "a"; + String b = "b"; + String c = "c"; + String d = "d"; + String e = "e"; + String f = "f"; + String g = "g"; + String h = "h"; + String j = "j"; + + + Bag bagabcdefg = null; + Bag bagbdfhj = null; + Bag bagace = null; + Bag bagb = null; + Bag bagaaaccce = null; + Bag bagInt = null; + Bag bagStringInt = null; + Bag bagEmpty = null; + + FunctionArgumentAttributeValue attrBadType = null; + + try { + bagabcdefg = new Bag(); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(d)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(g)); + bagbdfhj = new Bag(); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(d)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(h)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(j)); + bagace = new Bag(); + bagace.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagace.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagace.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagb = new Bag(); + bagb.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagaaaccce = new Bag(); + bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagInt = new Bag(); + bagInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); + bagStringInt = new Bag(); + bagStringInt.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagStringInt.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagStringInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); + bagEmpty = new Bag(); + + attrBadType = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.1)); + } catch (Exception ex) { + fail("creating attribute e="+ ex); + } + + // make into attributes + FunctionArgumentBag attrBagabcdefg = new FunctionArgumentBag(bagabcdefg); + FunctionArgumentBag attrBagbdfhj = new FunctionArgumentBag(bagbdfhj); + FunctionArgumentBag attrBagace = new FunctionArgumentBag(bagace); + FunctionArgumentBag attrBagb = new FunctionArgumentBag(bagb); + FunctionArgumentBag attrBagaaaccce = new FunctionArgumentBag(bagaaaccce); + FunctionArgumentBag attrBagInt = new FunctionArgumentBag(bagInt); + FunctionArgumentBag attrBagStringInt = new FunctionArgumentBag(bagStringInt); + FunctionArgumentBag attrBagEmpty = new FunctionArgumentBag(bagEmpty); + + FunctionDefinitionSet fd = (FunctionDefinitionSet) StdFunctions.FD_STRING_SUBSET; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_SUBSET, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + // normal intersection (everything in both bags, no duplicates) + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBagabcdefg); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + + // not subset + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBagbdfhj); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // subset + arguments.clear(); + arguments.add(attrBagace); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + + // no intersection + arguments.clear(); + arguments.add(attrBagace); + arguments.add(attrBagbdfhj); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // Not + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBagb); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // Subset + arguments.clear(); + arguments.add(attrBagb); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // bag one has duplicates that do not intersect + arguments.clear(); + arguments.add(attrBagaaaccce); + arguments.add(attrBagbdfhj); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // bag one has duplicates that do intersect + arguments.clear(); + arguments.add(attrBagaaaccce); + arguments.add(attrBagace); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // bag 2 has duplicates that do not intersect + arguments.clear(); + arguments.add(attrBagbdfhj); + arguments.add(attrBagaaaccce); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // bag 2 has duplicates that intersect + arguments.clear(); + arguments.add(attrBagace); + arguments.add(attrBagaaaccce); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // 2 empty bags + arguments.clear(); + arguments.add(attrBagEmpty); + arguments.add(attrBagEmpty); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // first non-empty, 2nd empty + arguments.clear(); + arguments.add(attrBagaaaccce); + arguments.add(attrBagEmpty); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first empty, 2nd not empty + arguments.clear(); + arguments.add(attrBagEmpty); + arguments.add(attrBagaaaccce); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // bags of different types + arguments.clear(); + arguments.add(attrBagace); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + arguments.clear(); + arguments.add(attrBagb); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + arguments.clear(); + arguments.add(attrBagace); + arguments.add(attrBagInt); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first not a bag + arguments.clear(); + arguments.add(attrBadType); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-subset Expected a bag, saw a simple value", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // second not a bag + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-subset Expected a bag, saw a simple value", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // first null + arguments.clear(); + arguments.add(null); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-subset Got null argument", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // second null + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-subset Got null argument", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // too few args + arguments.clear(); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-subset Expected 2 arguments, got 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-subset Expected 2 arguments, got 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // too many args + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBagabcdefg); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-subset Expected 2 arguments, got 3", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + + + + + + + + + + // + // SET_EQUALS tests + // + + @Test + public void testString_set_equals() { + String a = "a"; + String b = "b"; + String c = "c"; + String d = "d"; + String e = "e"; + String f = "f"; + String g = "g"; + String h = "h"; + String j = "j"; + + + Bag bagabcdefg = null; + Bag bagbdfhj = null; + Bag bagace = null; + Bag bagb = null; + Bag bagaaaccce = null; + Bag bagInt = null; + Bag bagStringInt = null; + Bag bagEmpty = null; + + FunctionArgumentAttributeValue attrBadType = null; + + try { + bagabcdefg = new Bag(); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(d)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(g)); + bagbdfhj = new Bag(); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(d)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(h)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(j)); + bagace = new Bag(); + bagace.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagace.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagace.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagb = new Bag(); + bagb.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagaaaccce = new Bag(); + bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagInt = new Bag(); + bagInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); + bagStringInt = new Bag(); + bagStringInt.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagStringInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); + bagEmpty = new Bag(); + + attrBadType = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.1)); + } catch (Exception ex) { + fail("creating attribute e="+ ex); + } + + // make into attributes + FunctionArgumentBag attrBagabcdefg = new FunctionArgumentBag(bagabcdefg); + FunctionArgumentBag attrBagbdfhj = new FunctionArgumentBag(bagbdfhj); + FunctionArgumentBag attrBagace = new FunctionArgumentBag(bagace); + FunctionArgumentBag attrBagb = new FunctionArgumentBag(bagb); + FunctionArgumentBag attrBagaaaccce = new FunctionArgumentBag(bagaaaccce); + FunctionArgumentBag attrBagInt = new FunctionArgumentBag(bagInt); + FunctionArgumentBag attrBagStringInt = new FunctionArgumentBag(bagStringInt); + FunctionArgumentBag attrBagEmpty = new FunctionArgumentBag(bagEmpty); + + FunctionDefinitionSet fd = (FunctionDefinitionSet) StdFunctions.FD_STRING_SET_EQUALS; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_SET_EQUALS, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + // normal intersection (everything in both bags, no duplicates) + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBagabcdefg); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + + // several but not all intersection + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBagbdfhj); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // no intersection + arguments.clear(); + arguments.add(attrBagace); + arguments.add(attrBagbdfhj); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // one intersection + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBagb); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // bag one has duplicates that do not intersect + arguments.clear(); + arguments.add(attrBagaaaccce); + arguments.add(attrBagbdfhj); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // bag one has duplicates that do intersect + arguments.clear(); + arguments.add(attrBagaaaccce); + arguments.add(attrBagace); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // bag 2 has duplicates that do not intersect + arguments.clear(); + arguments.add(attrBagbdfhj); + arguments.add(attrBagaaaccce); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // bag 2 has duplicates that intersect + arguments.clear(); + arguments.add(attrBagace); + arguments.add(attrBagaaaccce); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // 2 empty bags + arguments.clear(); + arguments.add(attrBagEmpty); + arguments.add(attrBagEmpty); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // first non-empty, 2nd empty + arguments.clear(); + arguments.add(attrBagaaaccce); + arguments.add(attrBagEmpty); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first empty, 2nd not empty + arguments.clear(); + arguments.add(attrBagEmpty); + arguments.add(attrBagaaaccce); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // bags of different types + arguments.clear(); + arguments.add(attrBagace); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + arguments.clear(); + arguments.add(attrBagace); + arguments.add(attrBagInt); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first not a bag + arguments.clear(); + arguments.add(attrBadType); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-set-equals Expected a bag, saw a simple value", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // second not a bag + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-set-equals Expected a bag, saw a simple value", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // first null + arguments.clear(); + arguments.add(null); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-set-equals Got null argument", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // second null + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-set-equals Got null argument", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // too few args + arguments.clear(); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-set-equals Expected 2 arguments, got 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-set-equals Expected 2 arguments, got 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // too many args + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBagabcdefg); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-set-equals Expected 2 arguments, got 3", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + + + + + + + + + // + // + // REST OF DATA TYPES OMITTED + // because they "should" all work the same + // + // + + + + +} diff --git a/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionSpecialMatchTest.java b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionSpecialMatchTest.java new file mode 100644 index 000000000..19d673624 --- /dev/null +++ b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionSpecialMatchTest.java @@ -0,0 +1,487 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.util.ArrayList; +import java.util.List; + +import javax.security.auth.x500.X500Principal; + +import org.junit.Test; + +import com.att.research.xacml.api.XACML3; +import com.att.research.xacml.std.datatypes.DataTypes; +import com.att.research.xacmlatt.pdp.policy.Bag; +import com.att.research.xacmlatt.pdp.policy.ExpressionResult; +import com.att.research.xacmlatt.pdp.policy.FunctionArgument; +import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; +import com.att.research.xacmlatt.pdp.policy.FunctionArgumentBag; +import com.att.research.xacmlatt.pdp.std.StdFunctions; +import com.att.research.xacmlatt.pdp.std.functions.*; + +/** + * Test of PDP Functions (See XACML core spec section A.3) + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * + */ +public class FunctionDefinitionSpecialMatchTest { + + /* + * variables useful in the following tests + */ + List arguments = new ArrayList(); + + @Test + public void testX500NameMatch() { + // assume that the contents of the name components are not significant and we can treat them as simple blocks of "=" + String A = "cn=Some person"; + String B = "O=Medico Corp"; + String C = "C=US"; + String D = "DNQUALIFIER=d string"; + String E = "SURNAME=some name"; + String F = "INITIALS=inits"; + + + X500Principal abc = new X500Principal(A + "," + B + "," + C); + X500Principal dabc = new X500Principal(D + "," + A + "," + B + "," + C); + X500Principal abcd = new X500Principal(A + "," + B + "," + C + "," + D); + X500Principal adbc = new X500Principal(A + "," + D + "," + B + "," + C); + X500Principal dcab = new X500Principal(D + "," + C + "," + A + "," + B) ; + X500Principal def = new X500Principal(D + "," + E + "," + F) ; + + + FunctionArgumentAttributeValue attrABC = null; + FunctionArgumentAttributeValue attrDABC = null; + FunctionArgumentAttributeValue attrABCD = null; + FunctionArgumentAttributeValue attrADBC = null; + FunctionArgumentAttributeValue attrDCAB = null; + FunctionArgumentAttributeValue attrDEF = null; + + FunctionArgumentAttributeValue attrBad = null; + FunctionArgumentBag attrBag = new FunctionArgumentBag(new Bag()); + + + try { + attrABC = new FunctionArgumentAttributeValue(DataTypes.DT_X500NAME.createAttributeValue(abc)); + attrDABC = new FunctionArgumentAttributeValue(DataTypes.DT_X500NAME.createAttributeValue(dabc)); + attrABCD = new FunctionArgumentAttributeValue(DataTypes.DT_X500NAME.createAttributeValue(abcd)); + attrADBC = new FunctionArgumentAttributeValue(DataTypes.DT_X500NAME.createAttributeValue(adbc)); + attrDCAB = new FunctionArgumentAttributeValue(DataTypes.DT_X500NAME.createAttributeValue(dcab)); + attrDEF = new FunctionArgumentAttributeValue(DataTypes.DT_X500NAME.createAttributeValue(def)); + + attrBad = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionX500NameMatch fd = (FunctionDefinitionX500NameMatch) StdFunctions.FD_X500NAME_MATCH; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_X500NAME_MATCH, fd.getId()); + assertEquals(DataTypes.DT_X500NAME.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + + // test normal, first exact match for second + arguments.clear(); + arguments.add(attrABC); + arguments.add(attrABC); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // test first is end of second + arguments.clear(); + arguments.add(attrABC); + arguments.add(attrDABC); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // first exact match for sub-section but not end of second + arguments.clear(); + arguments.add(attrABC); + arguments.add(attrABCD); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // components of first match components in second but not contiguous + arguments.clear(); + arguments.add(attrABC); + arguments.add(attrADBC); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // components of first match components in second but not in order + arguments.clear(); + arguments.add(attrABC); + arguments.add(attrDCAB); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first does not match second at all + arguments.clear(); + arguments.add(attrABC); + arguments.add(attrDEF); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first arg larger than 2nd arg + arguments.clear(); + arguments.add(attrABCD); + arguments.add(attrABC); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // bad arg types + arguments.clear(); + arguments.add(attrABC); + arguments.add(attrBad); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:x500Name-match Expected data type 'x500Name' saw 'integer' at arg index 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // too many args + arguments.clear(); + arguments.add(attrABC); + arguments.add(attrABC); + arguments.add(attrABC); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:x500Name-match Expected 2 arguments, got 3", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // too few args + arguments.clear(); + arguments.add(attrABC); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:x500Name-match Expected 2 arguments, got 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:x500Name-match Expected 2 arguments, got 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // one arg is bag + arguments.clear(); + arguments.add(attrABC); + arguments.add(attrBag); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:x500Name-match Expected a simple value, saw a bag at arg index 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null arg + arguments.clear(); + arguments.add(null); + arguments.add(attrBag); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:x500Name-match Got null argument at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + @Test + public void testRfc822NameMatch() { + + + + + FunctionArgumentAttributeValue attrStringabcxyz = null; + FunctionArgumentAttributeValue attrStringABCxyz = null; + FunctionArgumentAttributeValue attrStringabcXYZ = null; + FunctionArgumentAttributeValue attrStringcx = null; + FunctionArgumentAttributeValue attrStringwholedomainpart = null; + FunctionArgumentAttributeValue attrStringWholeDomainPart = null; + FunctionArgumentAttributeValue attrStringWholeDomain = null; + FunctionArgumentAttributeValue attrStringdomainpart = null; + FunctionArgumentAttributeValue attrStringDomainPart = null; + FunctionArgumentAttributeValue attrStringdotWholeDomain = null; + FunctionArgumentAttributeValue attrStringdomain = null; + + FunctionArgumentAttributeValue attrStringNoMatch = null; + FunctionArgumentAttributeValue attrStringMultipleAt = null; + FunctionArgumentAttributeValue attrStringMissingLocal = null; + FunctionArgumentAttributeValue attrStringMissingDomain = null; + + + FunctionArgumentAttributeValue attrRfcabcxyz = null; + FunctionArgumentAttributeValue attrRfcwholedomainpart = null; + FunctionArgumentAttributeValue attrRfcWholeDomainPart = null; + + FunctionArgumentBag attrBag = new FunctionArgumentBag(new Bag()); + + try { + attrStringabcxyz = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("abc@xyz")); + attrStringABCxyz = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("ABC@xyz")); + attrStringabcXYZ = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("abc@XYZ")); + attrStringcx = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("c@x")); + attrStringwholedomainpart = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("whole.domain.part")); + attrStringWholeDomainPart = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("Whole.Domain.Part")); + attrStringWholeDomain = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("Whole.Domain")); + attrStringdomainpart = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(".domain.part")); + attrStringDomainPart = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(".Domain.Part")); + attrStringdotWholeDomain = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(".Whole.Domain")); + attrStringdomain = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(".domain.")); + + attrStringNoMatch = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("no match to any legal name")); + attrStringMultipleAt = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("name@with@multipleAts")); + attrStringMissingLocal = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("@multipleAts")); + attrStringMissingDomain = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("localpart@")); + + attrRfcabcxyz = new FunctionArgumentAttributeValue(DataTypes.DT_RFC822NAME.createAttributeValue("abc@xyz")); + attrRfcwholedomainpart = new FunctionArgumentAttributeValue(DataTypes.DT_RFC822NAME.createAttributeValue("abc@whole.domain.part")); + attrRfcWholeDomainPart = new FunctionArgumentAttributeValue(DataTypes.DT_RFC822NAME.createAttributeValue("abc@Whole.Domain.Part")); + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionRFC822NameMatch fd = (FunctionDefinitionRFC822NameMatch) StdFunctions.FD_RFC822NAME_MATCH; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_RFC822NAME_MATCH, fd.getId()); + assertEquals(DataTypes.DT_RFC822NAME.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + + // string identical to name - exact match on whole search term + arguments.clear(); + arguments.add(attrStringabcxyz); + arguments.add(attrRfcabcxyz); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.getStatus().isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // no match local case different + arguments.clear(); + arguments.add(attrStringABCxyz); + arguments.add(attrRfcabcxyz); + res = fd.evaluate(null, arguments); + assertTrue(res.getStatus().isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // match domain case different + arguments.clear(); + arguments.add(attrStringabcXYZ); + arguments.add(attrRfcabcxyz); + res = fd.evaluate(null, arguments); + assertTrue(res.getStatus().isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + + // partial local + partial domain + arguments.clear(); + arguments.add(attrStringcx); + arguments.add(attrRfcabcxyz); + res = fd.evaluate(null, arguments); + assertTrue(res.getStatus().isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // whole domain + arguments.clear(); + arguments.add(attrStringwholedomainpart); + arguments.add(attrRfcwholedomainpart); + res = fd.evaluate(null, arguments); + assertTrue(res.getStatus().isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // whole domain different case + arguments.clear(); + arguments.add(attrStringWholeDomainPart); + arguments.add(attrRfcwholedomainpart); + res = fd.evaluate(null, arguments); + assertTrue(res.getStatus().isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + arguments.clear(); + arguments.add(attrStringwholedomainpart); + arguments.add(attrRfcWholeDomainPart); + res = fd.evaluate(null, arguments); + assertTrue(res.getStatus().isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // whole domain fail + arguments.clear(); + arguments.add(attrStringWholeDomain); + arguments.add(attrRfcWholeDomainPart); + res = fd.evaluate(null, arguments); + assertTrue(res.getStatus().isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // partial domain match + arguments.clear(); + arguments.add(attrStringDomainPart); + arguments.add(attrRfcWholeDomainPart); + res = fd.evaluate(null, arguments); + assertTrue(res.getStatus().isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // partial domain different case + arguments.clear(); + arguments.add(attrStringdomainpart); + arguments.add(attrRfcWholeDomainPart); + res = fd.evaluate(null, arguments); + assertTrue(res.getStatus().isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // partial domain fail + arguments.clear(); + arguments.add(attrStringdotWholeDomain); + arguments.add(attrRfcWholeDomainPart); + res = fd.evaluate(null, arguments); + assertTrue(res.getStatus().isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + arguments.clear(); + arguments.add(attrStringdomain); + arguments.add(attrRfcWholeDomainPart); + res = fd.evaluate(null, arguments); + assertTrue(res.getStatus().isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // search term contains more than 1 @ + arguments.clear(); + arguments.add(attrStringMultipleAt); + arguments.add(attrRfcabcxyz); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:rfc822Name-match String contained more than 1 '@' in 'name@with@multipleAts'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // search term missing local part + arguments.clear(); + arguments.add(attrStringMissingLocal); + arguments.add(attrRfcabcxyz); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:rfc822Name-match String missing local part in '@multipleAts'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // search term missing domain part + arguments.clear(); + arguments.add(attrStringMissingDomain); + arguments.add(attrRfcabcxyz); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:rfc822Name-match String missing domain part in 'localpart@'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad arg types + arguments.clear(); + arguments.add(attrRfcabcxyz); + arguments.add(attrStringNoMatch); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:rfc822Name-match Expected data type 'string' saw 'rfc822Name' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // too many args + arguments.clear(); + arguments.add(attrStringNoMatch); + arguments.add(attrStringNoMatch); + arguments.add(attrStringNoMatch); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:rfc822Name-match Expected 2 arguments, got 3", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // too few args + arguments.clear(); + arguments.add(attrStringNoMatch); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:rfc822Name-match Expected 2 arguments, got 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:rfc822Name-match Expected 2 arguments, got 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // one arg is bag + arguments.clear(); + arguments.add(attrStringNoMatch); + arguments.add(attrBag); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:rfc822Name-match Expected a simple value, saw a bag at arg index 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null arg + arguments.clear(); + arguments.add(null); + arguments.add(attrStringNoMatch); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:rfc822Name-match Got null argument at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + + } + +} diff --git a/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionStringConversionTest.java b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionStringConversionTest.java new file mode 100644 index 000000000..ae887cc60 --- /dev/null +++ b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionStringConversionTest.java @@ -0,0 +1,2504 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.math.BigInteger; +import java.net.URI; +import java.net.URISyntaxException; +import java.text.ParseException; +import java.util.ArrayList; +import java.util.List; + +import javax.security.auth.x500.X500Principal; + +import org.junit.Test; + +import com.att.research.xacml.api.XACML3; +import com.att.research.xacml.std.datatypes.DataTypes; +import com.att.research.xacml.std.datatypes.IPAddress; +import com.att.research.xacml.std.datatypes.IPv4Address; +import com.att.research.xacml.std.datatypes.IPv6Address; +import com.att.research.xacml.std.datatypes.ISO8601Date; +import com.att.research.xacml.std.datatypes.ISO8601DateTime; +import com.att.research.xacml.std.datatypes.ISO8601Time; +import com.att.research.xacml.std.datatypes.ISO8601TimeZone; +import com.att.research.xacml.std.datatypes.PortRange; +import com.att.research.xacml.std.datatypes.RFC2396DomainName; +import com.att.research.xacml.std.datatypes.RFC822Name; +import com.att.research.xacml.std.datatypes.XPathDayTimeDuration; +import com.att.research.xacml.std.datatypes.XPathYearMonthDuration; +import com.att.research.xacmlatt.pdp.policy.ExpressionResult; +import com.att.research.xacmlatt.pdp.policy.FunctionArgument; +import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; +import com.att.research.xacmlatt.pdp.std.StdFunctions; +import com.att.research.xacmlatt.pdp.std.functions.*; + +/** + * Tests for converting objects to/from Strings. + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * + */ +public class FunctionDefinitionStringConversionTest { + + /* + * variables useful in the following tests + */ + List arguments = new ArrayList(); + + + /** + * Boolean + */ + @Test + public void testBoolean_from_string() { + FunctionArgumentAttributeValue attrString1 = null; + FunctionArgumentAttributeValue attrStringBadValue = null; + FunctionArgumentAttributeValue attrStringBadType = null; + try { + attrString1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("true")); + attrStringBadValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("not valid obj value")); + attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionStringConversion fd = (FunctionDefinitionStringConversion) StdFunctions.FD_BOOLEAN_FROM_STRING; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_BOOLEAN_FROM_STRING, fd.getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + // test normal + arguments.clear(); + arguments.add(attrString1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertEquals(new Boolean(true), resValue); + + // bad value + arguments.clear(); + arguments.add(attrStringBadValue); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:boolean-from-string Cannot convert from \"java.lang.String\" with value \"not valid obj value\" to boolean", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrStringBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:boolean-from-string Expected data type 'string' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + @Test + public void testString_from_boolean() { + FunctionArgumentAttributeValue attrObj1 = null; + FunctionArgumentAttributeValue attrStringBadType = null; + String objValueString = "false"; + try { + attrObj1 = new FunctionArgumentAttributeValue(DataTypes.DT_BOOLEAN.createAttributeValue(objValueString)); + attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionStringConversion fd = (FunctionDefinitionStringConversion) StdFunctions.FD_STRING_FROM_BOOLEAN; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_FROM_BOOLEAN, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + // test normal + arguments.clear(); + arguments.add(attrObj1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(objValueString, res.getValue().getValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrStringBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-from-boolean Expected data type 'boolean' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + + + + /** + * Integer + */ + @Test + public void testInteger_from_string() { + FunctionArgumentAttributeValue attrString1 = null; + FunctionArgumentAttributeValue attrStringBadValue = null; + FunctionArgumentAttributeValue attrStringBadType = null; + try { + attrString1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("123456")); + attrStringBadValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("not valid obj value")); + attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionStringConversion fd = (FunctionDefinitionStringConversion) StdFunctions.FD_INTEGER_FROM_STRING; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_INTEGER_FROM_STRING, fd.getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + // test normal + arguments.clear(); + arguments.add(attrString1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + BigInteger resValue = (BigInteger)res.getValue().getValue(); + assertEquals(new BigInteger("123456"), resValue); + + // bad value + arguments.clear(); + arguments.add(attrStringBadValue); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:integer-from-string For input string: \"n\"", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrStringBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:integer-from-string Expected data type 'string' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + @Test + public void testString_from_integer() { + FunctionArgumentAttributeValue attrObj1 = null; + FunctionArgumentAttributeValue attrStringBadType = null; + String objValueString = "1234"; + try { + attrObj1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(objValueString)); + attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(123)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionStringConversion fd = (FunctionDefinitionStringConversion) StdFunctions.FD_STRING_FROM_INTEGER; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_FROM_INTEGER, fd.getId()); + assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + // test normal + arguments.clear(); + arguments.add(attrObj1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(objValueString, res.getValue().getValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrStringBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-from-integer Expected data type 'integer' saw 'double' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + + + /** + * Double + */ + @Test + public void testDouble_from_string() { + FunctionArgumentAttributeValue attrString1 = null; + FunctionArgumentAttributeValue attrStringBadValue = null; + FunctionArgumentAttributeValue attrStringBadType = null; + try { + attrString1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("5.432")); + attrStringBadValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("not valid obj value")); + attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionStringConversion fd = (FunctionDefinitionStringConversion) StdFunctions.FD_DOUBLE_FROM_STRING; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DOUBLE_FROM_STRING, fd.getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + // test normal + arguments.clear(); + arguments.add(attrString1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Double resValue = (Double)res.getValue().getValue(); + assertEquals(new Double(5.432), resValue); + + // bad value + arguments.clear(); + arguments.add(attrStringBadValue); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:double-from-string For input string: \"not valid obj value\"", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrStringBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:double-from-string Expected data type 'string' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + @Test + public void testString_from_double() { + FunctionArgumentAttributeValue attrObj1 = null; + FunctionArgumentAttributeValue attrObjBig = null; + FunctionArgumentAttributeValue attrStringBadType = null; + String objValueString = "5.432"; + String objValueStringBig = "55555555555555555555.123455"; + try { + attrObj1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(objValueString)); + attrObjBig = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(objValueStringBig)); + attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionStringConversion fd = (FunctionDefinitionStringConversion) StdFunctions.FD_STRING_FROM_DOUBLE; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_FROM_DOUBLE, fd.getId()); + assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + // test normal + arguments.clear(); + arguments.add(attrObj1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(objValueString, res.getValue().getValue()); + + arguments.clear(); + arguments.add(attrObjBig); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals("5.555555555555556E19", res.getValue().getValue()); + + + // bad arg type + arguments.clear(); + arguments.add(attrStringBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-from-double Expected data type 'double' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + + + + + /** + * Time + */ + @Test + public void testTime_from_string() { + FunctionArgumentAttributeValue attrString1 = null; + FunctionArgumentAttributeValue attrString2 = null; + FunctionArgumentAttributeValue attrString3 = null; + FunctionArgumentAttributeValue attrString4 = null; + FunctionArgumentAttributeValue attrStringTimeZone = null; + FunctionArgumentAttributeValue attrStringBadValue = null; + FunctionArgumentAttributeValue attrStringBadType = null; + try { + attrString1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("05:12:34.323")); + attrString2 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("5:12:34.323")); + attrString3 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("05:12")); + attrString4 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("05:12:34")); + attrStringTimeZone = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("05:12:34.323+03:00")); + attrStringBadValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("not valid obj value")); + attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionStringConversion fd = (FunctionDefinitionStringConversion) StdFunctions.FD_TIME_FROM_STRING; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_TIME_FROM_STRING, fd.getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_TIME.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + // test normal + arguments.clear(); + arguments.add(attrString1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + ISO8601Time resValue = (ISO8601Time)res.getValue().getValue(); + assertEquals(new ISO8601Time(5, 12, 34, 323), resValue); + + // check missing 0 in front + arguments.clear(); + arguments.add(attrString2); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:time-from-string Invalid hour of day", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // check missing seconds/msecs + arguments.clear(); + arguments.add(attrString3); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:time-from-string Time string too short", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // check missing just msecs + arguments.clear(); + arguments.add(attrString4); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (ISO8601Time)res.getValue().getValue(); + assertEquals(new ISO8601Time(5, 12, 34, 0), resValue); + + // check TimeZone + arguments.clear(); + arguments.add(attrStringTimeZone); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (ISO8601Time)res.getValue().getValue(); + assertEquals(new ISO8601Time(new ISO8601TimeZone(180), 5, 12, 34, 323), resValue); + + // bad value + arguments.clear(); + arguments.add(attrStringBadValue); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:time-from-string Invalid hour of day", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrStringBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:time-from-string Expected data type 'string' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + @Test + public void testString_from_time() { + FunctionArgumentAttributeValue attrObj1 = null; + FunctionArgumentAttributeValue attrObj2 = null; + FunctionArgumentAttributeValue attrObjTimeZone = null; + FunctionArgumentAttributeValue attrStringBadType = null; + try { + attrObj1 = new FunctionArgumentAttributeValue(DataTypes.DT_TIME.createAttributeValue("05:12:34.323")); + attrObj2 = new FunctionArgumentAttributeValue(DataTypes.DT_TIME.createAttributeValue("05:01:02.323")); + attrObjTimeZone = new FunctionArgumentAttributeValue(DataTypes.DT_TIME.createAttributeValue("05:12:34.323+03:00")); + attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionStringConversion fd = (FunctionDefinitionStringConversion) StdFunctions.FD_STRING_FROM_TIME; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_FROM_TIME, fd.getId()); + assertEquals(DataTypes.DT_TIME.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + // test normal + arguments.clear(); + arguments.add(attrObj1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals("05:12:34.323", res.getValue().getValue()); + + // missing digits in string value? + arguments.clear(); + arguments.add(attrObj2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals("05:01:02.323", res.getValue().getValue()); + + // include TimeZone + arguments.clear(); + arguments.add(attrObjTimeZone); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals("05:12:34.323+03:00", res.getValue().getValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrStringBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-from-time Expected data type 'time' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + + + + + /** + * Date + */ + @Test + public void testDate_from_string() { + FunctionArgumentAttributeValue attrString1 = null; + FunctionArgumentAttributeValue attrString2 = null; + FunctionArgumentAttributeValue attrString3 = null; + FunctionArgumentAttributeValue attrString4 = null; + FunctionArgumentAttributeValue attrString5 = null; + FunctionArgumentAttributeValue attrString6 = null; + FunctionArgumentAttributeValue attrString7 = null; + FunctionArgumentAttributeValue attrString8 = null; + FunctionArgumentAttributeValue attrString9 = null; + FunctionArgumentAttributeValue attrStringDateZone = null; + FunctionArgumentAttributeValue attrStringBadValue = null; + FunctionArgumentAttributeValue attrStringBadType = null; + try { + attrString1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("2013-05-12")); + attrString2 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("-2013-05-12")); + attrString3 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("1232013-05-12")); + attrString4 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("-1232013-05-12")); + attrString5 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("213-05-12")); + attrString6 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("2013-5-12")); + attrString7 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("2013-05-2")); + attrString8 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("2013-32-12")); + attrString9 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("2013-05-45")); + attrStringDateZone = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("2013-05-12+03:00")); + attrStringBadValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("not valid obj value")); + attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionStringConversion fd = (FunctionDefinitionStringConversion) StdFunctions.FD_DATE_FROM_STRING; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DATE_FROM_STRING, fd.getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_DATE.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + // test normal + arguments.clear(); + arguments.add(attrString1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + ISO8601Date resValue = (ISO8601Date)res.getValue().getValue(); + assertEquals(new ISO8601Date(2013, 5, 12), resValue); + + // check negative + arguments.clear(); + arguments.add(attrString2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (ISO8601Date)res.getValue().getValue(); + assertEquals(new ISO8601Date(-2013, 5, 12), resValue); + + // check big + arguments.clear(); + arguments.add(attrString3); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (ISO8601Date)res.getValue().getValue(); + assertEquals(new ISO8601Date(1232013, 5, 12), resValue); + + // check big negative + arguments.clear(); + arguments.add(attrString4); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (ISO8601Date)res.getValue().getValue(); + assertEquals(new ISO8601Date(-1232013, 5, 12), resValue); + + // bad year + arguments.clear(); + arguments.add(attrString5); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:date-from-string Invalid year (must be at least 4 digits)", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad month + arguments.clear(); + arguments.add(attrString6); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:date-from-string Invalid month", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad day format + arguments.clear(); + arguments.add(attrString7); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:date-from-string Invalid day", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // month out of range + arguments.clear(); + arguments.add(attrString8); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:date-from-string Invalid month", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // day out of range + arguments.clear(); + arguments.add(attrString9); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:date-from-string Invalid day", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // check TimeZone + arguments.clear(); + arguments.add(attrStringDateZone); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (ISO8601Date)res.getValue().getValue(); + assertEquals(new ISO8601Date(new ISO8601TimeZone(180), 2013, 5, 12), resValue); + + // bad value + arguments.clear(); + arguments.add(attrStringBadValue); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:date-from-string Invalid year", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrStringBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:date-from-string Expected data type 'string' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + @Test + public void testString_from_date() { + FunctionArgumentAttributeValue attrObj1 = null; + FunctionArgumentAttributeValue attrObj2 = null; + FunctionArgumentAttributeValue attrObjDateZone = null; + FunctionArgumentAttributeValue attrStringBadType = null; + try { + attrObj1 = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue("2013-05-12")); + attrObj2 = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue("0001-01-01")); + attrObjDateZone = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue("2013-05-12+03:00")); + attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionStringConversion fd = (FunctionDefinitionStringConversion) StdFunctions.FD_STRING_FROM_DATE; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_FROM_DATE, fd.getId()); + assertEquals(DataTypes.DT_DATE.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + // test normal + arguments.clear(); + arguments.add(attrObj1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals("2013-05-12", res.getValue().getValue()); + + // missing digits in string value? + arguments.clear(); + arguments.add(attrObj2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals("1-01-01", res.getValue().getValue()); + + // include DateZone + arguments.clear(); + arguments.add(attrObjDateZone); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals("2013-05-12+03:00", res.getValue().getValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrStringBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-from-date Expected data type 'date' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + + + + + + /** + * DateTime + */ + @Test + public void testDateTime_from_string() { + FunctionArgumentAttributeValue attrString1 = null; + FunctionArgumentAttributeValue attrString2 = null; + FunctionArgumentAttributeValue attrString3 = null; + FunctionArgumentAttributeValue attrString4 = null; + FunctionArgumentAttributeValue attrString5 = null; + FunctionArgumentAttributeValue attrString6 = null; + FunctionArgumentAttributeValue attrString7 = null; + FunctionArgumentAttributeValue attrString8 = null; + FunctionArgumentAttributeValue attrString9 = null; + FunctionArgumentAttributeValue attrStringDateTimeZone = null; + FunctionArgumentAttributeValue attrStringBadValue = null; + FunctionArgumentAttributeValue attrStringBadType = null; + try { + attrString1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("2013-05-12T12:14:15.323")); + attrString2 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("-2013-05-12T12:14:15.323")); + attrString3 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("1232013-05-12T12:14:15.323")); + attrString4 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("-1232013-05-12T12:14:15.323")); + attrString5 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("213-05-12T12:14:15.323")); + attrString6 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("2013-5-12T12:14:15.323")); + attrString7 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("2013-05-2T12:14:15.323")); + attrString8 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("2013-32-12T12:14:15.323")); + attrString9 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("2013-05-45T12:14:15.323")); + attrStringDateTimeZone = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("2013-05-12T12:14:15.323+03:00")); + attrStringBadValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("not valid obj value")); + attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionStringConversion fd = (FunctionDefinitionStringConversion) StdFunctions.FD_DATETIME_FROM_STRING; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DATETIME_FROM_STRING, fd.getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_DATETIME.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + // test normal + arguments.clear(); + arguments.add(attrString1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + ISO8601DateTime resValue = (ISO8601DateTime)res.getValue().getValue(); + assertEquals(new ISO8601DateTime(null, new ISO8601Date(2013, 5, 12), new ISO8601Time(12, 14, 15, 323)), resValue); + + // check negative + arguments.clear(); + arguments.add(attrString2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + assertEquals(new ISO8601DateTime(null, new ISO8601Date(-2013, 5, 12), new ISO8601Time(12, 14, 15, 323)), resValue); + + + // check big + arguments.clear(); + arguments.add(attrString3); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + assertEquals(new ISO8601DateTime(null, new ISO8601Date(1232013, 5, 12), new ISO8601Time(12, 14, 15, 323)), resValue); + + // check big negative + arguments.clear(); + arguments.add(attrString4); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + assertEquals(new ISO8601DateTime(null, new ISO8601Date(-1232013, 5, 12), new ISO8601Time(12, 14, 15, 323)), resValue); + + // bad year + arguments.clear(); + arguments.add(attrString5); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-from-string Invalid year (must be at least 4 digits)", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad month + arguments.clear(); + arguments.add(attrString6); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-from-string Invalid month", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad day format + arguments.clear(); + arguments.add(attrString7); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-from-string Invalid day", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // month out of range + arguments.clear(); + arguments.add(attrString8); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-from-string Invalid month", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // day out of range + arguments.clear(); + arguments.add(attrString9); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-from-string Invalid day", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // check TimeZone + arguments.clear(); + arguments.add(attrStringDateTimeZone); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + assertEquals(new ISO8601DateTime(new ISO8601TimeZone(180), new ISO8601Date(new ISO8601TimeZone(180), 2013, 5, 12), new ISO8601Time(new ISO8601TimeZone(180),12, 14, 15, 323)), resValue); + + // bad value + arguments.clear(); + arguments.add(attrStringBadValue); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-from-string Invalid year", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrStringBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-from-string Expected data type 'string' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + @Test + public void testString_from_dateTime() { + FunctionArgumentAttributeValue attrObj1 = null; + FunctionArgumentAttributeValue attrObj2 = null; + FunctionArgumentAttributeValue attrObjDateTimeZone = null; + FunctionArgumentAttributeValue attrStringBadType = null; + try { + attrObj1 = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue("2013-05-12T12:14:15.323")); + attrObj2 = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue("0001-01-01T12:14:15.323")); + attrObjDateTimeZone = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue("2013-05-12T12:14:15.323+03:00")); + attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionStringConversion fd = (FunctionDefinitionStringConversion) StdFunctions.FD_STRING_FROM_DATETIME; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_FROM_DATETIME, fd.getId()); + assertEquals(DataTypes.DT_DATETIME.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + // test normal + arguments.clear(); + arguments.add(attrObj1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals("2013-05-12T12:14:15.323", res.getValue().getValue()); + + // missing digits in string value? + arguments.clear(); + arguments.add(attrObj2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals("1-01-01T12:14:15.323", res.getValue().getValue()); + + // include DateTimeZone + arguments.clear(); + arguments.add(attrObjDateTimeZone); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals("2013-05-12T12:14:15.323+03:00", res.getValue().getValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrStringBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-from-dateTime Expected data type 'dateTime' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + + + + + /** + * URI + */ + @Test + public void testURI_from_string() { + FunctionArgumentAttributeValue attrString1 = null; + FunctionArgumentAttributeValue attrStringBadValue = null; + FunctionArgumentAttributeValue attrStringBadType = null; + try { + attrString1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("http://someMachine.com/subdir")); + attrStringBadValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("not valid obj value")); + attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionStringConversion fd = (FunctionDefinitionStringConversion) StdFunctions.FD_ANYURI_FROM_STRING; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_ANYURI_FROM_STRING, fd.getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_ANYURI.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + // test normal + arguments.clear(); + arguments.add(attrString1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + URI resValue = (URI)res.getValue().getValue(); + try { + assertEquals(new URI("http://someMachine.com/subdir"), resValue); + } catch (URISyntaxException e) { + fail("uri generation e="+e); + } + + // bad value + arguments.clear(); + arguments.add(attrStringBadValue); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:anyURI-from-string Illegal character in path at index 3: not valid obj value", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrStringBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:anyURI-from-string Expected data type 'string' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + @Test + public void testString_from_anyURI() { + FunctionArgumentAttributeValue attrObj1 = null; + FunctionArgumentAttributeValue attrStringBadType = null; + String objValueString = "http://aMachine.com:8080/aRef"; + try { + attrObj1 = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(objValueString)); + attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionStringConversion fd = (FunctionDefinitionStringConversion) StdFunctions.FD_STRING_FROM_ANYURI; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_FROM_ANYURI, fd.getId()); + assertEquals(DataTypes.DT_ANYURI.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + // test normal + arguments.clear(); + arguments.add(attrObj1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(objValueString, res.getValue().getValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrStringBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-from-anyURI Expected data type 'anyURI' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + + + /** + * XPathDayTimeDuration + */ + @Test + public void testXPathDayTimeDuration_from_string() { + FunctionArgumentAttributeValue attrString1 = null; + FunctionArgumentAttributeValue attrStringNeg1 = null; + FunctionArgumentAttributeValue attrStringNeg2 = null; + FunctionArgumentAttributeValue attrStringNoDay = null; + FunctionArgumentAttributeValue attrStringNoHour = null; + FunctionArgumentAttributeValue attrStringNoMin = null; + FunctionArgumentAttributeValue attrStringNoSec = null; + FunctionArgumentAttributeValue attrStringNoP = null; + FunctionArgumentAttributeValue attrStringSecondsDot = null; + FunctionArgumentAttributeValue attrStringMissingTOk = null; + FunctionArgumentAttributeValue attrStringMissingTBad = null; + FunctionArgumentAttributeValue attrStringBadValue = null; + FunctionArgumentAttributeValue attrStringBadType = null; + try { + attrString1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("P3DT10H30M23S")); + attrStringNeg1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("-P3DT10H30M23S")); + attrStringNeg2 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("P-3DT10H30M23S")); + attrStringNoDay = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("PT10H30M23S")); + attrStringNoHour = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("P3DT30M23S")); + attrStringNoMin = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("P3DT10H23S")); + attrStringNoSec = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("P3DT10H30M")); + attrStringNoP = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("3DT10H30M")); + attrStringSecondsDot = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("P3DT10H30M23.456S")); + attrStringMissingTOk = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("P3D")); + attrStringMissingTBad = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("P3D10H30M23S")); + + attrStringBadValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("not valid obj value")); + attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionStringConversion fd = (FunctionDefinitionStringConversion) StdFunctions.FD_DAYTIMEDURATION_FROM_STRING; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DAYTIMEDURATION_FROM_STRING, fd.getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_DAYTIMEDURATION.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + // test normal + arguments.clear(); + arguments.add(attrString1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + XPathDayTimeDuration resValue = (XPathDayTimeDuration)res.getValue().getValue(); + assertEquals(new XPathDayTimeDuration(1, 3, 10, 30, 23), resValue); + + + // negative values in front is allowed + arguments.clear(); + arguments.add(attrStringNeg1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (XPathDayTimeDuration)res.getValue().getValue(); + assertEquals(new XPathDayTimeDuration(-1, 3, 10, 30, 23), resValue); + + // negative in middle of string not ok + arguments.clear(); + arguments.add(attrStringNeg2); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dayTimeDuration-from-string Invalid chunk \"P-3DT10H30M23S\" at position 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // omit parts that are 0 + arguments.clear(); + arguments.add(attrStringNoDay); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (XPathDayTimeDuration)res.getValue().getValue(); + assertEquals(new XPathDayTimeDuration(1, 0, 10, 30, 23), resValue); + + arguments.clear(); + arguments.add(attrStringNoHour); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (XPathDayTimeDuration)res.getValue().getValue(); + assertEquals(new XPathDayTimeDuration(1, 3, 0, 30, 23), resValue); + + arguments.clear(); + arguments.add(attrStringNoMin); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (XPathDayTimeDuration)res.getValue().getValue(); + assertEquals(new XPathDayTimeDuration(1, 3, 10, 0, 23), resValue); + + arguments.clear(); + arguments.add(attrStringNoSec); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (XPathDayTimeDuration)res.getValue().getValue(); + assertEquals(new XPathDayTimeDuration(1, 3, 10, 30, 0), resValue); + + // P must always be present + arguments.clear(); + arguments.add(attrStringNoP); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dayTimeDuration-from-string Invalid ISO8601 duration string \"3DT10H30M\" at position 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // seconds may contain decimal + arguments.clear(); + arguments.add(attrStringSecondsDot); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (XPathDayTimeDuration)res.getValue().getValue(); + assertEquals(new XPathDayTimeDuration(1, 3, 10, 30, 23.456), resValue); + + // T must be absent iff all time items are absent + arguments.clear(); + arguments.add(attrStringMissingTOk); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (XPathDayTimeDuration)res.getValue().getValue(); + assertEquals(new XPathDayTimeDuration(1, 3, 0, 0, 0), resValue); + + // negative in middle of string not ok + arguments.clear(); + arguments.add(attrStringMissingTBad); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dayTimeDuration-from-string Invalid ISO8601 duration string \"P3D10H30M23S\" at position 6: out of order component", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // bad value + arguments.clear(); + arguments.add(attrStringBadValue); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dayTimeDuration-from-string Invalid ISO8601 duration string \"not valid obj value\" at position 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrStringBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dayTimeDuration-from-string Expected data type 'string' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + @Test + public void testString_from_dayTimeDuration() { + FunctionArgumentAttributeValue attrObj1 = null; + FunctionArgumentAttributeValue attrStringBadType = null; + String objValueString = "P3DT10H30M23S"; + try { + attrObj1 = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(objValueString)); + attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionStringConversion fd = (FunctionDefinitionStringConversion) StdFunctions.FD_STRING_FROM_DAYTIMEDURATION; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_FROM_DAYTIMEDURATION, fd.getId()); + assertEquals(DataTypes.DT_DAYTIMEDURATION.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + // test normal + arguments.clear(); + arguments.add(attrObj1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(objValueString, res.getValue().getValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrStringBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-from-dayTimeDuration Expected data type 'dayTimeDuration' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + + + + + + + + + /** + * XPathYearMonthDuration + */ + @Test + public void testXPathYearMonthDuration_from_string() { + FunctionArgumentAttributeValue attrString1 = null; + FunctionArgumentAttributeValue attrStringNeg1 = null; + FunctionArgumentAttributeValue attrStringNeg2 = null; + FunctionArgumentAttributeValue attrStringNoYear1 = null; + FunctionArgumentAttributeValue attrStringNoYear2 = null; + FunctionArgumentAttributeValue attrStringNoMonth1 = null; + FunctionArgumentAttributeValue attrStringNoMonth2 = null; + FunctionArgumentAttributeValue attrStringNoValue = null; + FunctionArgumentAttributeValue attrStringNoP = null; + FunctionArgumentAttributeValue attrStringBigMonths = null; + FunctionArgumentAttributeValue attrStringMissingTOk = null; + FunctionArgumentAttributeValue attrStringMissingTBad = null; + FunctionArgumentAttributeValue attrStringZeroMonths = null; + FunctionArgumentAttributeValue attrStringBadValue = null; + FunctionArgumentAttributeValue attrStringBadType = null; + try { + attrString1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("P1Y2M")); + attrStringNeg1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("-P1Y2M")); + attrStringNeg2 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("P-1Y2M")); + attrStringNoYear1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("P2M")); + attrStringNoYear2 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("PY2M")); + attrStringNoMonth1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("P1Y")); + attrStringNoMonth2 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("P1YM")); + attrStringNoValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("P")); + attrStringNoP = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("1Y2M")); + attrStringBigMonths = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("P1Y12M")); + attrStringMissingTOk = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("P3D")); + attrStringMissingTBad = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("P3D10H30M23S")); + attrStringZeroMonths = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("P0M")); + + attrStringBadValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("not valid obj value")); + attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionStringConversion fd = (FunctionDefinitionStringConversion) StdFunctions.FD_YEARMONTHDURATION_FROM_STRING; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_YEARMONTHDURATION_FROM_STRING, fd.getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_YEARMONTHDURATION.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + // test normal + arguments.clear(); + arguments.add(attrString1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + XPathYearMonthDuration resValue = (XPathYearMonthDuration)res.getValue().getValue(); + assertEquals(new XPathYearMonthDuration(1,1, 2), resValue); + + + // negative values in front is allowed + arguments.clear(); + arguments.add(attrStringNeg1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (XPathYearMonthDuration)res.getValue().getValue(); + assertEquals(new XPathYearMonthDuration(-1, 1, 2), resValue); + + // negative in middle of string not ok + arguments.clear(); + arguments.add(attrStringNeg2); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:yearMonthDuration-from-string Invalid chunk \"P-1Y2M\" at position 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // omit parts that are 0 + arguments.clear(); + arguments.add(attrStringNoYear1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (XPathYearMonthDuration)res.getValue().getValue(); + assertEquals(new XPathYearMonthDuration(1, 0, 2), resValue); + + arguments.clear(); + arguments.add(attrStringNoYear2); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:yearMonthDuration-from-string Invalid chunk \"PY2M\" at position 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + arguments.clear(); + arguments.add(attrStringNoMonth1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (XPathYearMonthDuration)res.getValue().getValue(); + assertEquals(new XPathYearMonthDuration(1, 1, 0), resValue); + + arguments.clear(); + arguments.add(attrStringNoMonth2); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:yearMonthDuration-from-string Invalid chunk \"P1YM\" at position 3", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // No field with a value + arguments.clear(); + arguments.add(attrStringNoValue); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:yearMonthDuration-from-string Invalid ISO8601 duration string \"P\": No duration components following P", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // P must always be present + arguments.clear(); + arguments.add(attrStringNoP); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:yearMonthDuration-from-string Invalid ISO8601 duration string \"1Y2M\" at position 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // Canonical Form of output may not have more than 12 months, but input as string is ok? + arguments.clear(); + arguments.add(attrStringBigMonths); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (XPathYearMonthDuration)res.getValue().getValue(); + assertEquals(new XPathYearMonthDuration(1, 1, 12), resValue); + + // Canonical representation of 0 Months + arguments.clear(); + arguments.add(attrStringZeroMonths); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (XPathYearMonthDuration)res.getValue().getValue(); + assertEquals(new XPathYearMonthDuration(1, 0, 0), resValue); + + // T must be absent iff all time items are absent + arguments.clear(); + arguments.add(attrStringMissingTOk); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:yearMonthDuration-from-string Invalid XPath yearMonthDuraiton \"{durationSign=1years=0months=0days=3hours=0minutes=0seconds=0millis=0}\": includes days, hours, minutes, or seconds", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // negative in middle of string not ok + arguments.clear(); + arguments.add(attrStringMissingTBad); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:yearMonthDuration-from-string Invalid ISO8601 duration string \"P3D10H30M23S\" at position 6: out of order component", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // bad value + arguments.clear(); + arguments.add(attrStringBadValue); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:yearMonthDuration-from-string Invalid ISO8601 duration string \"not valid obj value\" at position 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrStringBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:yearMonthDuration-from-string Expected data type 'string' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + @Test + public void testString_from_yearMonthDuration() { + FunctionArgumentAttributeValue attrObj1 = null; + FunctionArgumentAttributeValue attrStringBadType = null; + String objValueString = "P1Y2M"; + try { + attrObj1 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(objValueString)); + attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionStringConversion fd = (FunctionDefinitionStringConversion) StdFunctions.FD_STRING_FROM_YEARMONTHDURATION; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_FROM_YEARMONTHDURATION, fd.getId()); + assertEquals(DataTypes.DT_YEARMONTHDURATION.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + // test normal + arguments.clear(); + arguments.add(attrObj1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(objValueString, res.getValue().getValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrStringBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-from-yearMonthDuration Expected data type 'yearMonthDuration' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + + + + + + /** + * X500Principal + * + * See http://www.ietf.org/rfc/rfc2253.txt and http://www.ietf.org/rfc/rfc2251.txt + */ + @Test + public void testX500Principal_from_string() { + FunctionArgumentAttributeValue attrString1 = null; + FunctionArgumentAttributeValue attrStringNoComma = null; + FunctionArgumentAttributeValue attrStringEmpty = null; + FunctionArgumentAttributeValue attrStringNoValue = null; + FunctionArgumentAttributeValue attrStringOrder = null; + FunctionArgumentAttributeValue attrStringDottedDecimalOID = null; + FunctionArgumentAttributeValue attrStringBadValue = null; + FunctionArgumentAttributeValue attrStringBadType = null; + try { + attrString1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("CN=Name, L=local, ST=NJ, O=ATT, C=USA")); + attrStringNoComma = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("CN=Name, L=local ST=NJ, O=ATT, C=USA")); + attrStringEmpty = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("")); + attrStringNoValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("CN=Name, L=, ST=NJ, O=ATT, C=USA")); + attrStringOrder = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("L=local, ST=NJ, O=ATT, CN=Name, C=USA")); + attrStringDottedDecimalOID = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("2.5.4.3=A. N. Other")); + + attrStringBadValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("not valid obj value")); + attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + + FunctionDefinitionStringConversion fd = (FunctionDefinitionStringConversion) StdFunctions.FD_X500NAME_FROM_STRING; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_X500NAME_FROM_STRING, fd.getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_X500NAME.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + // test normal + arguments.clear(); + arguments.add(attrString1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + X500Principal resValue = (X500Principal)res.getValue().getValue(); + assertEquals(new X500Principal("CN=Name, L=local, ST=NJ, O=ATT, C=USA"), resValue); + + // no comma between components => next attribute/value is included as part of first value + arguments.clear(); + arguments.add(attrStringNoComma); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (X500Principal)res.getValue().getValue(); + assertEquals(new X500Principal("CN=Name, L=local ST=NJ, O=ATT, C=USA"), resValue); + + // nothing in name (fail) + arguments.clear(); + arguments.add(attrStringEmpty); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (X500Principal)res.getValue().getValue(); + assertEquals(new X500Principal(""), resValue); + + // type value with no = + arguments.clear(); + arguments.add(attrStringNoValue); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (X500Principal)res.getValue().getValue(); + assertEquals(new X500Principal("CN=Name, L=, ST=NJ, O=ATT, C=USA"), resValue); + + // different order + arguments.clear(); + arguments.add(attrStringOrder); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (X500Principal)res.getValue().getValue(); + assertNotEquals(new X500Principal("CN=Name, L=local, ST=NJ, O=ATT, C=USA"), resValue); + + // dotted-decimal name with numbers + arguments.clear(); + arguments.add(attrStringDottedDecimalOID); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (X500Principal)res.getValue().getValue(); + assertEquals(new X500Principal("2.5.4.3=A. N. Other"), resValue); + + + + // bad value + arguments.clear(); + arguments.add(attrStringBadValue); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:x500Name-from-string improperly specified input name: not valid obj value", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrStringBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:x500Name-from-string Expected data type 'string' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + @Test + public void testString_from_x500Name() { + FunctionArgumentAttributeValue attrObj1 = null; + FunctionArgumentAttributeValue attrStringBadType = null; + String objValueString = "CN=Name, L=local, ST=NJ, O=ATT, C=USA"; + try { + attrObj1 = new FunctionArgumentAttributeValue(DataTypes.DT_X500NAME.createAttributeValue(objValueString)); + attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionStringConversion fd = (FunctionDefinitionStringConversion) StdFunctions.FD_STRING_FROM_X500NAME; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_FROM_X500NAME, fd.getId()); + assertEquals(DataTypes.DT_X500NAME.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + // test normal + arguments.clear(); + arguments.add(attrObj1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(objValueString, res.getValue().getValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrStringBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-from-x500Name Expected data type 'x500Name' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + + + + /** + * RFC822Name + */ + @Test + public void testRFC822Name_from_string() { + FunctionArgumentAttributeValue attrString1 = null; + FunctionArgumentAttributeValue attrStringCapsDomain = null; + FunctionArgumentAttributeValue attrStringCapsLocal = null; + FunctionArgumentAttributeValue attrStringMissingAt = null; + FunctionArgumentAttributeValue attrStringMissingLocal = null; + FunctionArgumentAttributeValue attrStringMissingDomain = null; + FunctionArgumentAttributeValue attrStringEmpty = null; + FunctionArgumentAttributeValue attrStringBadValue = null; + FunctionArgumentAttributeValue attrStringBadType = null; + try { + attrString1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("local@Domain")); + attrStringCapsDomain = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("local@DOMAIN")); + attrStringCapsLocal = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("LOCAL@Domain")); + attrStringMissingAt = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("localDomain")); + attrStringMissingLocal = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("@Domain")); + attrStringMissingDomain = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("local@")); + attrStringEmpty = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("")); + + attrStringBadValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("not valid obj value")); + attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionStringConversion fd = (FunctionDefinitionStringConversion) StdFunctions.FD_RFC822NAME_FROM_STRING; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_RFC822NAME_FROM_STRING, fd.getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_RFC822NAME.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + // test normal + arguments.clear(); + arguments.add(attrString1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + RFC822Name resValue = (RFC822Name)res.getValue().getValue(); + assertEquals(new RFC822Name("local", "domain"), resValue); + + // caps domain + arguments.clear(); + arguments.add(attrStringCapsDomain); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (RFC822Name)res.getValue().getValue(); + assertEquals(new RFC822Name("local", "domain"), resValue); + + // caps local + arguments.clear(); + arguments.add(attrStringCapsLocal); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (RFC822Name)res.getValue().getValue(); + assertNotEquals(new RFC822Name("local", "domain"), resValue); + + // missing at + arguments.clear(); + arguments.add(attrStringMissingAt); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:rfc822Name-from-string Invalid RFC822Name \"localDomain\": missing local part", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // missing local + arguments.clear(); + arguments.add(attrStringMissingLocal); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:rfc822Name-from-string Invalid RFC822Name \"@Domain\": empty parts", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // missing domain + arguments.clear(); + arguments.add(attrStringMissingDomain); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:rfc822Name-from-string Invalid RFC822Name \"local@\": empty parts", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // empty + arguments.clear(); + arguments.add(attrStringEmpty); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:rfc822Name-from-string Invalid RFC822Name \"\": missing local part", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // bad value + arguments.clear(); + arguments.add(attrStringBadValue); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:rfc822Name-from-string Invalid RFC822Name \"not valid obj value\": missing local part", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrStringBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:rfc822Name-from-string Expected data type 'string' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + @Test + public void testString_from_rfc822Name() { + FunctionArgumentAttributeValue attrObj1 = null; + FunctionArgumentAttributeValue attrStringBadType = null; + String objValueString = "local@DOMAIN"; + try { + attrObj1 = new FunctionArgumentAttributeValue(DataTypes.DT_RFC822NAME.createAttributeValue(objValueString)); + attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionStringConversion fd = (FunctionDefinitionStringConversion) StdFunctions.FD_STRING_FROM_RFC822NAME; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_FROM_RFC822NAME, fd.getId()); + assertEquals(DataTypes.DT_RFC822NAME.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + // test normal + arguments.clear(); + arguments.add(attrObj1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals("local@domain", res.getValue().getValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrStringBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-from-rfc822Name Expected data type 'rfc822Name' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + + + + /** + * IPAddress + */ + @Test + public void testIPAddress_from_string() { + FunctionArgumentAttributeValue attrString1 = null; + FunctionArgumentAttributeValue attrStringFull = null; + FunctionArgumentAttributeValue attrStringMissingElement = null; + FunctionArgumentAttributeValue attrStringTooManyElement = null; + FunctionArgumentAttributeValue attrStringIllegalElement = null; + FunctionArgumentAttributeValue attrStringOutOfOrder = null; + + FunctionArgumentAttributeValue attrStringMask = null; + FunctionArgumentAttributeValue attrStringMissingMaskElement = null; + FunctionArgumentAttributeValue attrStringTooManyMaskElement = null; + FunctionArgumentAttributeValue attrStringIllegalMaskElement = null; + FunctionArgumentAttributeValue attrStringMaskNoValue = null; + + FunctionArgumentAttributeValue attrStringMinusPort = null; + FunctionArgumentAttributeValue attrStringPortMinus = null; + FunctionArgumentAttributeValue attrStringPortPort = null; + FunctionArgumentAttributeValue attrStringNoPort = null; + FunctionArgumentAttributeValue attrStringBadPort = null; + FunctionArgumentAttributeValue attrStringTooManyPorts = null; + FunctionArgumentAttributeValue attrStringBadValue = null; + FunctionArgumentAttributeValue attrStringBadType = null; + + // set up for v4 address tests - this setup and the tests are repeated for V6 + short[] addrShorts= {123, 134, 156, 255 }; + short[] addrMaskShorts= {255, 255, 255, 255 }; + try { + attrString1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("10.11.12.123")); + attrStringFull = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("10.11.12.123/10.11.121.123:123-456")); + attrStringMissingElement = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("10.11.12.123")); + attrStringTooManyElement = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("10.11.12.123.222")); + attrStringIllegalElement = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("10.11.12.123")); + attrStringOutOfOrder = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("10.11.12.123:123-456/10.11.12.123")); + + attrStringMask = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("10.11.12.123/10.11.12.123")); + attrStringMissingMaskElement = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("10.11.12.123/10.11.12.123")); + attrStringTooManyMaskElement = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("10.11.12.123/10.11.12.123.222")); + attrStringIllegalMaskElement = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("10.11.12.255/10.11.123.255")); + attrStringMaskNoValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("10.11.12.156/")); + // optional mask + // "/" with no mask (fail) + + attrStringMinusPort = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("10.11.12.123:-123")); + attrStringPortMinus = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("10.11.12.123:123-")); + attrStringPortPort = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("10.11.12.123:1234567-432")); + attrStringNoPort = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("10.11.12.123:")); + attrStringBadPort = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("10.11.12.123:12.34")); + attrStringTooManyPorts = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("10.11.12.123:-123-456")); + + + + attrStringBadValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("not valid obj value")); + attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionStringConversion fd = (FunctionDefinitionStringConversion) StdFunctions.FD_IPADDRESS_FROM_STRING; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_IPADDRESS_FROM_STRING, fd.getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_IPADDRESS.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + // test normal + arguments.clear(); + arguments.add(attrString1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + IPAddress resValue = (IPAddress)res.getValue().getValue(); + assertEquals(new IPv4Address(addrShorts, null, null), resValue); + + // fully-loaded address + arguments.clear(); + arguments.add(attrStringFull); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (IPAddress)res.getValue().getValue(); + try { + assertEquals(new IPv4Address(addrShorts, addrMaskShorts, PortRange.newInstance("123-456")), resValue); + } catch (Exception e) { + fail("port error e="+e); + } + + // missing element + arguments.clear(); + arguments.add(attrStringMissingElement); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:ipAddress-from-string Invalid IPv4 address string \"10.11.12.123\": invalid address", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // too many elements + arguments.clear(); + arguments.add(attrStringTooManyElement); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:ipAddress-from-string Invalid IPv4 address string \"10.11.12.123.222\": invalid address", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // illegal element + arguments.clear(); + arguments.add(attrStringIllegalElement); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:ipAddress-from-string Invalid IPv4 address string \"10.11.123.255\": invalid octet: \"256", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // Out of order + arguments.clear(); + arguments.add(attrStringOutOfOrder); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:ipAddress-from-string Invalid IPv4 address string \"10.11.12.123:123-456/10.11.12.123\": out of order components", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // simple mask + arguments.clear(); + arguments.add(attrStringMask); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (IPAddress)res.getValue().getValue(); + try { + assertEquals(new IPv4Address(addrShorts, addrMaskShorts, null), resValue); + } catch (Exception e) { + fail("port error e="+e); + } + + // missing mask element + arguments.clear(); + arguments.add(attrStringMissingMaskElement); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:ipAddress-from-string Invalid IPv4 address string \"10.11.12.123\": invalid address", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // too many mask elements + arguments.clear(); + arguments.add(attrStringTooManyMaskElement); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:ipAddress-from-string Invalid IPv4 address string \"10.11.12.123.222\": invalid address", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // illegal Mask element + arguments.clear(); + arguments.add(attrStringIllegalMaskElement); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:ipAddress-from-string Invalid IPv4 address string \"10.11.12.123\": invalid octet: \"256", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + //mask indicator without value + arguments.clear(); + arguments.add(attrStringMaskNoValue); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:ipAddress-from-string Invalid IPv4 address string \"\": invalid address", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // portrange (-port, port-, port-port) + arguments.clear(); + arguments.add(attrStringMinusPort); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (IPAddress)res.getValue().getValue(); + try { + assertEquals(new IPv4Address(addrShorts, null, PortRange.newInstance("-123")), resValue); + } catch (ParseException e) { + fail("port error e="+e); + } + + arguments.clear(); + arguments.add(attrStringPortMinus); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (IPAddress)res.getValue().getValue(); + try { + assertEquals(new IPv4Address(addrShorts, null, PortRange.newInstance("123-")), resValue); + } catch (ParseException e) { + fail("port error e="+e); + } + + arguments.clear(); + arguments.add(attrStringPortPort); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (IPAddress)res.getValue().getValue(); + try { + assertEquals(new IPv4Address(addrShorts, null, PortRange.newInstance("1234567-432")), resValue); + } catch (ParseException e) { + fail("port error e="+e); + } + + // ":" without port + arguments.clear(); + arguments.add(attrStringNoPort); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:ipAddress-from-string Invalid IPv4 address string \"10.11.12.123:\": no portrange given after ':'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // bad port number + arguments.clear(); + arguments.add(attrStringBadPort); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:ipAddress-from-string Invalid PortRange \"12.34\": invalid port number", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad port range + arguments.clear(); + arguments.add(attrStringTooManyPorts); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:ipAddress-from-string Invalid PortRange \"-123-456\": too many ranges", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // bad value + arguments.clear(); + arguments.add(attrStringBadValue); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:ipAddress-from-string Unknown IPAddress type for \"not valid obj value\"", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrStringBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:ipAddress-from-string Expected data type 'string' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // + // V6 IP Addresses + // + + // reset the variable for IPv6 tests + FunctionArgumentAttributeValue attrStringAlternateFull = null; + FunctionArgumentAttributeValue attrStringEmptyElement = null; + FunctionArgumentAttributeValue attrString2xEmptyElement = null; + FunctionArgumentAttributeValue attrStringNoStartBracket = null; + FunctionArgumentAttributeValue attrStringNoEndBracket = null; + short[] addrv6Shorts = {(short)0x2001, (short)0xdb8, (short)0x85a3, (short)0x0, (short)0x0, (short)0x8a2e, (short)0x370, (short)0x1}; + Short prefix = new Short((short) 121); + try { + attrString1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3:0:0:8a2e:370:1]")); + attrStringFull = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3:0:0:8a2e:370:1/121]:123-456")); + attrStringAlternateFull = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3:0:0:8a2e:370:1]/121:123-456")); + attrStringEmptyElement = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3::8a2e:370:1]")); + attrString2xEmptyElement = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3::8a2e::1]")); + attrStringNoStartBracket = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("2002:db8:85a3::8a2e::1]")); + attrStringNoEndBracket = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3::8a2e::1")); + + attrStringMissingElement = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3:0:0:8a2e:1]")); + attrStringTooManyElement = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3:0:0:8a2e:370:1:123]")); + attrStringIllegalElement = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:mnop:85a3:0:0:8a2e:370:1]")); + attrStringOutOfOrder = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:mnop:85a3:0:0:8a2e:370:1:123-456/121]")); + + attrStringMask = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3:0:0:8a2e:370:1/21]")); + attrStringIllegalMaskElement = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3:0:0:8a2e:370:1/130]")); + attrStringMaskNoValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3:0:0:8a2e:370:1/]")); + + attrStringMinusPort = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3:0:0:8a2e:370:1]:-123")); + attrStringPortMinus = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3:0:0:8a2e:370:1]:123-")); + attrStringPortPort = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3:0:0:8a2e:370:1]:1234567-432")); + attrStringNoPort = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3:0:0:8a2e:370:1]:")); + attrStringBadPort = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3:0:0:8a2e:370:1]:12.34")); + attrStringTooManyPorts = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3:0:0:8a2e:370:1]:-123-456")); + + attrStringBadValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("not valid obj value")); + attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + + // test normal + arguments.clear(); + arguments.add(attrString1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (IPAddress)res.getValue().getValue(); + assertEquals(new IPv6Address(addrv6Shorts, null, null), resValue); + + // fully-loaded address - "prefix" is inside the brackets (not clear if this is correct) + arguments.clear(); + arguments.add(attrStringFull); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (IPAddress)res.getValue().getValue(); + try { + assertEquals(new IPv6Address(addrv6Shorts, new Short(prefix), PortRange.newInstance("123-456")), resValue); + } catch (Exception e) { + fail("port error e="+e); + } + + // Alternate way of identifying "prefix" - outside the brackets + arguments.clear(); + arguments.add(attrStringAlternateFull); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (IPAddress)res.getValue().getValue(); + try { + assertEquals(new IPv6Address(addrv6Shorts, prefix, PortRange.newInstance("123-456")), resValue); + } catch (Exception e) { + fail("port error e="+e); + } + + + // consecutive zero elements removed + arguments.clear(); + arguments.add(attrStringEmptyElement); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (IPAddress)res.getValue().getValue(); + try { + assertEquals(new IPv6Address(addrv6Shorts, prefix, null), resValue); + } catch (Exception e) { + fail("port error e="+e); + } + + // consecutive zero elements removed in two locations (no-no) + arguments.clear(); + arguments.add(attrString2xEmptyElement); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:ipAddress-from-string Invalid IPv6Address string \"2001:db8:85a3::8a2e::1\": multiple zero runs", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // address must have [] on it + arguments.clear(); + arguments.add(attrStringNoStartBracket); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:ipAddress-from-string Invalid IPv6Address string \"2002:db8:85a3::8a2e::1]\": missing opening bracket", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + arguments.add(attrStringNoEndBracket); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:ipAddress-from-string Invalid IPv6Address string \"[2001:db8:85a3::8a2e::1\": missing closing bracket", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // missing element + arguments.clear(); + arguments.add(attrStringMissingElement); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:ipAddress-from-string Invalid IPv6Address string \"2001:db8:85a3:0:0:8a2e:1\": not enough address fields", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // too many elements + arguments.clear(); + arguments.add(attrStringTooManyElement); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:ipAddress-from-string Invalid IPv6Address string \"2001:db8:85a3:0:0:8a2e:370:1:123\"", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // illegal element + arguments.clear(); + arguments.add(attrStringIllegalElement); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:ipAddress-from-string Invalid IPv6Address component \"mnop\": invalid hex", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // Out of order + arguments.clear(); + arguments.add(attrStringOutOfOrder); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:ipAddress-from-string Invalid IPv6Address string \"2001:mnop:85a3:0:0:8a2e:370:1:123-456\"", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // simple mask + arguments.clear(); + arguments.add(attrStringMask); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (IPAddress)res.getValue().getValue(); + try { + assertEquals(new IPv6Address(addrv6Shorts, prefix, null), resValue); + } catch (Exception e) { + fail("port error e="+e); + } + + // illegal Mask element + arguments.clear(); + arguments.add(attrStringIllegalMaskElement); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:ipAddress-from-string Invalid Ipv6Address string \"[2001:db8:85a3:0:0:8a2e:370:1/130]\": prefix is larger than 128", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + //mask indicator without value + arguments.clear(); + arguments.add(attrStringMaskNoValue); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:ipAddress-from-string Invalid Ipv6Address string \"[2001:db8:85a3:0:0:8a2e:370:1/]\": prefix designation without value", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // portrange (-port, port-, port-port) + arguments.clear(); + arguments.add(attrStringMinusPort); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (IPAddress)res.getValue().getValue(); + try { + assertEquals(new IPv6Address(addrv6Shorts, null, PortRange.newInstance("-123")), resValue); + } catch (ParseException e) { + fail("port error e="+e); + } + + arguments.clear(); + arguments.add(attrStringPortMinus); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (IPAddress)res.getValue().getValue(); + try { + assertEquals(new IPv6Address(addrv6Shorts, null, PortRange.newInstance("123-")), resValue); + } catch (ParseException e) { + fail("port error e="+e); + } + + arguments.clear(); + arguments.add(attrStringPortPort); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (IPAddress)res.getValue().getValue(); + try { + assertEquals(new IPv6Address(addrv6Shorts, null, PortRange.newInstance("1234567-432")), resValue); + } catch (ParseException e) { + fail("port error e="+e); + } + + // ":" without port + arguments.clear(); + arguments.add(attrStringNoPort); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:ipAddress-from-string Invalid IPv6 address string \"[2001:db8:85a3:0:0:8a2e:370:1]:\": no portrange given after ':'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // bad port number + arguments.clear(); + arguments.add(attrStringBadPort); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:ipAddress-from-string Invalid PortRange \"12.34\": invalid port number", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad port range + arguments.clear(); + arguments.add(attrStringTooManyPorts); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:ipAddress-from-string Invalid PortRange \"-123-456\": too many ranges", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + + + + } + + @Test + public void testString_from_ipAddress() { + FunctionArgumentAttributeValue attrObj1 = null; + FunctionArgumentAttributeValue attrObjV6 = null; + FunctionArgumentAttributeValue attrStringBadType = null; + String objValueString = "10.11.12.123"; + String objValueStringV6 = "[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]"; + try { + attrObj1 = new FunctionArgumentAttributeValue(DataTypes.DT_IPADDRESS.createAttributeValue(objValueString)); + attrObjV6 = new FunctionArgumentAttributeValue(DataTypes.DT_IPADDRESS.createAttributeValue(objValueStringV6)); + + attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionStringConversion fd = (FunctionDefinitionStringConversion) StdFunctions.FD_STRING_FROM_IPADDRESS; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_FROM_IPADDRESS, fd.getId()); + assertEquals(DataTypes.DT_IPADDRESS.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + // test normal V4 + arguments.clear(); + arguments.add(attrObj1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(objValueString, res.getValue().getValue()); + + // test normal V6 + arguments.clear(); + arguments.add(attrObjV6); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(objValueStringV6.toLowerCase(), res.getValue().getValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrStringBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-from-ipAddress Expected data type 'ipAddress' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + + + + + + + + + + /** + * RFC2396DomainName + */ + @Test + public void testRFC2396DomainName_from_string() { + FunctionArgumentAttributeValue attrString1 = null; + FunctionArgumentAttributeValue attrString2 = null; + FunctionArgumentAttributeValue attrStringMinusPort = null; + FunctionArgumentAttributeValue attrStringPortMinus = null; + FunctionArgumentAttributeValue attrStringPortPort = null; + FunctionArgumentAttributeValue attrStringNoPort = null; + FunctionArgumentAttributeValue attrStringBadPort = null; + FunctionArgumentAttributeValue attrStringTooManyPorts = null; + + FunctionArgumentAttributeValue attrStringBadValue = null; + FunctionArgumentAttributeValue attrStringBadType = null; + try { + attrString1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("host")); + attrString2 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("host.host")); + + attrStringMinusPort = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("host.host:-123")); + attrStringPortMinus = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("host.host:123-")); + attrStringPortPort = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("host.host:1234567-432")); + attrStringNoPort = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("host.host:")); + attrStringBadPort = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("host.host:12.34")); + attrStringTooManyPorts = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("host.host:-123-456")); + + attrStringBadValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("not valid obj value")); + attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionStringConversion fd = (FunctionDefinitionStringConversion) StdFunctions.FD_DNSNAME_FROM_STRING; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DNSNAME_FROM_STRING, fd.getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_DNSNAME.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + // test normal + arguments.clear(); + arguments.add(attrString1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + RFC2396DomainName resValue = (RFC2396DomainName)res.getValue().getValue(); + assertEquals(new RFC2396DomainName("host", null), resValue); + + arguments.clear(); + arguments.add(attrString2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (RFC2396DomainName)res.getValue().getValue(); + assertEquals(new RFC2396DomainName("host.host", null), resValue); + + + // portrange (-port, port-, port-port) + arguments.clear(); + arguments.add(attrStringMinusPort); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (RFC2396DomainName)res.getValue().getValue(); + try { + assertEquals(new RFC2396DomainName("host.host", PortRange.newInstance("-123")), resValue); + } catch (ParseException e) { + fail("port error e="+e); + } + + arguments.clear(); + arguments.add(attrStringPortMinus); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (RFC2396DomainName)res.getValue().getValue(); + try { + assertEquals(new RFC2396DomainName("host.host", PortRange.newInstance("123-")), resValue); + } catch (ParseException e) { + fail("port error e="+e); + } + + arguments.clear(); + arguments.add(attrStringPortPort); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (RFC2396DomainName)res.getValue().getValue(); + try { + assertEquals(new RFC2396DomainName("host.host", PortRange.newInstance("1234567-432")), resValue); + } catch (ParseException e) { + fail("port error e="+e); + } + + // ":" without port + arguments.clear(); + arguments.add(attrStringNoPort); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dnsName-from-string Invalid RFC 2396 port range \"host.host:\": no port numbers", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad port number + arguments.clear(); + arguments.add(attrStringBadPort); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dnsName-from-string Invalid RFC 2396 port range \"12.34\"", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad port range + arguments.clear(); + arguments.add(attrStringTooManyPorts); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dnsName-from-string Invalid RFC 2396 port range \"-123-456\"", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad value + arguments.clear(); + arguments.add(attrStringBadValue); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dnsName-from-string Invalid RFC 2396 host name \"not valid obj value\"", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrStringBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dnsName-from-string Expected data type 'string' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + @Test + public void testString_from_dnsName() { + FunctionArgumentAttributeValue attrObj1 = null; + FunctionArgumentAttributeValue attrStringBadType = null; + String objValueString = "someName.com"; + try { + attrObj1 = new FunctionArgumentAttributeValue(DataTypes.DT_DNSNAME.createAttributeValue(objValueString)); + attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionStringConversion fd = (FunctionDefinitionStringConversion) StdFunctions.FD_STRING_FROM_DNSNAME; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_FROM_DNSNAME, fd.getId()); + assertEquals(DataTypes.DT_DNSNAME.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + // test normal + arguments.clear(); + arguments.add(attrObj1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(objValueString, res.getValue().getValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrStringBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-from-dnsName Expected data type 'dnsName' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + + + + + + +} diff --git a/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionStringEqualIgnoreCaseTest.java b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionStringEqualIgnoreCaseTest.java new file mode 100644 index 000000000..6475e8d4a --- /dev/null +++ b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionStringEqualIgnoreCaseTest.java @@ -0,0 +1,129 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +import com.att.research.xacml.api.XACML3; +import com.att.research.xacml.std.datatypes.DataTypes; +import com.att.research.xacmlatt.pdp.policy.ExpressionResult; +import com.att.research.xacmlatt.pdp.policy.FunctionArgument; +import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; +import com.att.research.xacmlatt.pdp.std.StdFunctions; +import com.att.research.xacmlatt.pdp.std.functions.*; + +/** + * Only one function to test here. Code copy/pasted from FunctionDefinitionEqualityTest + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * In the first implementation of XACML we had separate files for each XACML Function. + * This release combines multiple Functions in fewer files to minimize code duplication. + * This file supports the following XACML codes: + * string-equal-ignore-case + * + * + */ +public class FunctionDefinitionStringEqualIgnoreCaseTest { + + /* + * variables useful in the following tests + */ + List arguments = new ArrayList(); + + FunctionArgumentAttributeValue stringAttr1 = null; + FunctionArgumentAttributeValue stringAttr2 = null; + FunctionArgumentAttributeValue stringAttr3 = null; + FunctionArgumentAttributeValue stringAttr4 = null; + + FunctionArgumentAttributeValue intAttr1 = null; + + public FunctionDefinitionStringEqualIgnoreCaseTest() { + try { + stringAttr1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("abc")); + stringAttr2 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("abc")); + stringAttr3 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("ABC")); + stringAttr4 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("def")); + intAttr1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1)); + } catch (Exception e) { + fail("creating attribute e="+ e); + } + } + + + /** + * String match even when Case is different + */ + @Test + public void testFunctionDefinitionStringEqualIgnoreCase() { + + FunctionDefinitionEquality fd = (FunctionDefinitionEquality) StdFunctions.FD_STRING_EQUAL_IGNORE_CASE; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_EQUAL_IGNORE_CASE, fd.getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + + + // test normal equals and non-equals + // check "abc" with "abc" + arguments.add(stringAttr1); + arguments.add(stringAttr2); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // check "abc" with "ABC" (should be same) + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(stringAttr3); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // test bad args data types? Not needed? + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(intAttr1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + + +//TODO - null in either first or 2nd arg => NullPointerException + } + +} diff --git a/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionStringFunctionsTest.java b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionStringFunctionsTest.java new file mode 100644 index 000000000..e80fb685d --- /dev/null +++ b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionStringFunctionsTest.java @@ -0,0 +1,1497 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.net.URI; +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +import com.att.research.xacml.api.XACML3; +import com.att.research.xacml.std.datatypes.DataTypes; +import com.att.research.xacmlatt.pdp.policy.ExpressionResult; +import com.att.research.xacmlatt.pdp.policy.FunctionArgument; +import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; +import com.att.research.xacmlatt.pdp.std.StdFunctions; +import com.att.research.xacmlatt.pdp.std.functions.*; + +/** + * Test of PDP Functions (See XACML core spec section A.3) + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * + */ +public class FunctionDefinitionStringFunctionsTest { + + + /* + * variables useful in the following tests + */ + List arguments = new ArrayList(); + + ExpressionResult res; + + + @Test + public void testConcatenate() { + String v1 = new String("abc"); + String v2 = new String("def"); + + FunctionArgumentAttributeValue attrV1 = null; + FunctionArgumentAttributeValue attrV2 = null; + FunctionArgumentAttributeValue attrNull = null; + FunctionArgumentAttributeValue attrBlank = null; + FunctionArgumentAttributeValue attrInteger = null; + try { + attrV1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(v1)); + attrV2 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(v2)); + attrBlank = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("")); + attrNull = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(null)); + attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234)); + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + FunctionDefinitionStringFunctions fd = (FunctionDefinitionStringFunctions) StdFunctions.FD_STRING_CONCATENATE; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_CONCATENATE, fd.getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + + // match + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrV2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.String.class, res.getValue().getValue().getClass()); + String resValue = (String)res.getValue().getValue(); + assertEquals(v1 + v2, resValue); + + // empty non-null first arg + arguments.clear(); + arguments.add(attrBlank); + arguments.add(attrV2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.String.class, res.getValue().getValue().getClass()); + resValue = (String)res.getValue().getValue(); + assertEquals(v2, resValue); + + // empty non-null second arg + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.String.class, res.getValue().getValue().getClass()); + resValue = (String)res.getValue().getValue(); + assertEquals(v1, resValue); + + // two blanks + arguments.clear(); + arguments.add(attrBlank); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.String.class, res.getValue().getValue().getClass()); + resValue = (String)res.getValue().getValue(); + assertEquals("", resValue); + + // null firat arg + arguments.clear(); + arguments.add(attrNull); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-concatenate Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // null second arg + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrNull); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-concatenate Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrInteger); + arguments.add(attrV2); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-concatenate Expected data type 'string' saw 'integer'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null second arg + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrNull); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-concatenate Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + + @Test + public void testStringStartsWith() { + String v1 = new String("abc"); + String bigger = new String("abc some string"); + String biggerNoMatch = new String(" abc some string"); + String caps = new String("AbC"); + + FunctionArgumentAttributeValue attrV1 = null; + FunctionArgumentAttributeValue attrBigger = null; + FunctionArgumentAttributeValue attrBiggerNoMatch = null; + FunctionArgumentAttributeValue attrCaps = null; + FunctionArgumentAttributeValue attrNull = null; + FunctionArgumentAttributeValue attrBlank = null; + FunctionArgumentAttributeValue attrInteger = null; + try { + attrV1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(v1)); + attrBigger = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(bigger)); + attrBiggerNoMatch = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(biggerNoMatch)); + attrCaps = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(caps)); + attrBlank = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("")); + attrNull = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(null)); + attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234)); + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + FunctionDefinitionStringFunctions fd = (FunctionDefinitionStringFunctions) StdFunctions.FD_STRING_STARTS_WITH; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_STARTS_WITH, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + + // match + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrBigger); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertEquals(true, resValue); + + // no match + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrBiggerNoMatch); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // caps no match + arguments.clear(); + arguments.add(attrCaps); + arguments.add(attrBigger); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // bigger on the inside + arguments.clear(); + arguments.add(attrBigger); + arguments.add(attrV1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // empty non-null first arg + arguments.clear(); + arguments.add(attrBlank); + arguments.add(attrBigger); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(true, resValue); + + // empty non-null second arg + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // two blanks + arguments.clear(); + arguments.add(attrBlank); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(true, resValue); + + // null firat arg + arguments.clear(); + arguments.add(attrNull); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-starts-with Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null second arg + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrNull); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-starts-with Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // illegal arg type + arguments.clear(); + arguments.add(attrInteger); + arguments.add(attrBigger); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-starts-with Expected data type 'string' saw 'integer'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + @Test + public void testAnyuriStartsWith() { + + + FunctionArgumentAttributeValue attrV1 = null; + FunctionArgumentAttributeValue attrBigger = null; + FunctionArgumentAttributeValue attrBiggerNoMatch = null; + FunctionArgumentAttributeValue attrCaps = null; + FunctionArgumentAttributeValue attrBigString = null; + FunctionArgumentAttributeValue attrNull = null; + FunctionArgumentAttributeValue attrBlankString = null; + FunctionArgumentAttributeValue attrBlankURI = null; + FunctionArgumentAttributeValue attrInteger = null; + try { + String v1 = new String("abc"); + URI bigger = new URI("abc.some.string"); + URI biggerNoMatch = new URI("Zabc.some.string"); + String caps = new String("AbC"); + String bigString = "thisIsSomeReallyBigStringToMatch"; + + attrV1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(v1)); + attrBigger = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(bigger)); + attrBiggerNoMatch = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(biggerNoMatch)); + attrCaps = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(caps)); + attrBigString = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(bigString)); + attrBlankString = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("")); + attrBlankURI = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue("")); + attrNull = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(null)); + attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234)); + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + FunctionDefinitionStringFunctions fd = (FunctionDefinitionStringFunctions) StdFunctions.FD_ANYURI_STARTS_WITH; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_ANYURI_STARTS_WITH, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + + // match + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrBigger); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertEquals(true, resValue); + + // no match + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrBiggerNoMatch); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // caps no match + arguments.clear(); + arguments.add(attrCaps); + arguments.add(attrBigger); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // bigger on the inside + arguments.clear(); + arguments.add(attrBigString); + arguments.add(attrBigger); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // empty non-null first arg + arguments.clear(); + arguments.add(attrBlankString); + arguments.add(attrBigger); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(true, resValue); + + // empty non-null second arg + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrBlankURI); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + + // two blanks + arguments.clear(); + arguments.add(attrBlankString); + arguments.add(attrBlankURI); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(true, resValue); + + // arguments reversed + arguments.clear(); + arguments.add(attrBigger); + arguments.add(attrV1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:anyURI-starts-with Expected data type 'string' saw 'anyURI'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // null firat arg + arguments.clear(); + arguments.add(attrNull); + arguments.add(attrBlankURI); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:anyURI-starts-with Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null second arg + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrNull); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:anyURI-starts-with Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // illegal arg type + arguments.clear(); + arguments.add(attrInteger); + arguments.add(attrBigger); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:anyURI-starts-with Expected data type 'string' saw 'integer'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + + + @Test + public void testStringEndsWith() { + String v1 = new String("abc"); + String bigger = new String("abc some string abc"); + String biggerNoMatch = new String(" abc some string abc "); + String caps = new String("AbC"); + + FunctionArgumentAttributeValue attrV1 = null; + FunctionArgumentAttributeValue attrBigger = null; + FunctionArgumentAttributeValue attrBiggerNoMatch = null; + FunctionArgumentAttributeValue attrCaps = null; + FunctionArgumentAttributeValue attrNull = null; + FunctionArgumentAttributeValue attrBlank = null; + FunctionArgumentAttributeValue attrInteger = null; + try { + attrV1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(v1)); + attrBigger = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(bigger)); + attrBiggerNoMatch = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(biggerNoMatch)); + attrCaps = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(caps)); + attrBlank = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("")); + attrNull = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(null)); + attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234)); + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + FunctionDefinitionStringFunctions fd = (FunctionDefinitionStringFunctions) StdFunctions.FD_STRING_ENDS_WITH; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_ENDS_WITH, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + + // match + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrBigger); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertEquals(true, resValue); + + // no match + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrBiggerNoMatch); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // caps no match + arguments.clear(); + arguments.add(attrCaps); + arguments.add(attrBigger); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // bigger on the inside + arguments.clear(); + arguments.add(attrBigger); + arguments.add(attrV1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // empty non-null first arg + arguments.clear(); + arguments.add(attrBlank); + arguments.add(attrBigger); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(true, resValue); + + // empty non-null second arg + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // two blanks + arguments.clear(); + arguments.add(attrBlank); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(true, resValue); + + // null firat arg + arguments.clear(); + arguments.add(attrNull); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-ends-with Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null second arg + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrNull); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-ends-with Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // illegal arg type + arguments.clear(); + arguments.add(attrInteger); + arguments.add(attrBigger); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-ends-with Expected data type 'string' saw 'integer'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + @Test + public void testAnyuriEndsWith() { + + + FunctionArgumentAttributeValue attrV1 = null; + FunctionArgumentAttributeValue attrBigger = null; + FunctionArgumentAttributeValue attrBiggerNoMatch = null; + FunctionArgumentAttributeValue attrCaps = null; + FunctionArgumentAttributeValue attrBigString = null; + FunctionArgumentAttributeValue attrNull = null; + FunctionArgumentAttributeValue attrBlankString = null; + FunctionArgumentAttributeValue attrBlankURI = null; + FunctionArgumentAttributeValue attrInteger = null; + try { + String v1 = new String("abc"); + URI bigger = new URI("abc.some.stringabc"); + URI biggerNoMatch = new URI("Zabc.some.stringabcZ"); + String caps = new String("AbC"); + String bigString = "thisIsSomeReallyBigStringToMatch"; + + attrV1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(v1)); + attrBigger = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(bigger)); + attrBiggerNoMatch = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(biggerNoMatch)); + attrCaps = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(caps)); + attrBigString = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(bigString)); + attrBlankString = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("")); + attrBlankURI = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue("")); + attrNull = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(null)); + attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234)); + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + FunctionDefinitionStringFunctions fd = (FunctionDefinitionStringFunctions) StdFunctions.FD_ANYURI_ENDS_WITH; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_ANYURI_ENDS_WITH, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + + // match + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrBigger); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertEquals(true, resValue); + + // no match + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrBiggerNoMatch); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // caps no match + arguments.clear(); + arguments.add(attrCaps); + arguments.add(attrBigger); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // bigger on the inside + arguments.clear(); + arguments.add(attrBigString); + arguments.add(attrBigger); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // empty non-null first arg + arguments.clear(); + arguments.add(attrBlankString); + arguments.add(attrBigger); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(true, resValue); + + // empty non-null second arg + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrBlankURI); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + + // two blanks + arguments.clear(); + arguments.add(attrBlankString); + arguments.add(attrBlankURI); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(true, resValue); + + // arguments reversed + arguments.clear(); + arguments.add(attrBigger); + arguments.add(attrV1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:anyURI-ends-with Expected data type 'string' saw 'anyURI'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // null firat arg + arguments.clear(); + arguments.add(attrNull); + arguments.add(attrBlankURI); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:anyURI-ends-with Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null second arg + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrNull); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:anyURI-ends-with Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // illegal arg type + arguments.clear(); + arguments.add(attrInteger); + arguments.add(attrBigger); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:anyURI-ends-with Expected data type 'string' saw 'integer'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + + + @Test + public void testStringSubstring() { + String bigString = new String("abc some string abc"); + + FunctionArgumentAttributeValue attrBigString = null; + FunctionArgumentAttributeValue attrNull = null; + FunctionArgumentAttributeValue attrBlank = null; + FunctionArgumentAttributeValue attrDouble = null; + + FunctionArgumentAttributeValue attrInteger0 = null; + FunctionArgumentAttributeValue attrInteger1 = null; + FunctionArgumentAttributeValue attrIntegerM1 = null; + FunctionArgumentAttributeValue attrInteger8 = null; + FunctionArgumentAttributeValue attrInteger19 = null; + FunctionArgumentAttributeValue attrInteger20 = null; + + + + try { + attrBigString = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(bigString)); + attrBlank = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("")); + attrNull = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(null)); + attrInteger0 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(0)); + attrInteger1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1)); + attrIntegerM1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(-1)); + attrInteger8 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(8)); + attrInteger19 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(19)); + attrInteger20 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(20)); + attrDouble = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(123.4)); + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + FunctionDefinitionStringFunctions fd = (FunctionDefinitionStringFunctions) StdFunctions.FD_STRING_SUBSTRING; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_SUBSTRING, fd.getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + + // match + arguments.clear(); + arguments.add(attrBigString); + arguments.add(attrInteger1); + arguments.add(attrInteger8); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.String.class, res.getValue().getValue().getClass()); + String resValue = (String)res.getValue().getValue(); + assertEquals("bc some", resValue); + + // edge: start + arguments.clear(); + arguments.add(attrBigString); + arguments.add(attrInteger0); + arguments.add(attrInteger8); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.String.class, res.getValue().getValue().getClass()); + resValue = (String)res.getValue().getValue(); + assertEquals("abc some", resValue); + + // edge: end + arguments.clear(); + arguments.add(attrBigString); + arguments.add(attrInteger8); + arguments.add(attrInteger19); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.String.class, res.getValue().getValue().getClass()); + resValue = (String)res.getValue().getValue(); + assertEquals(" string abc", resValue); + + // from index to end of string + arguments.clear(); + arguments.add(attrBigString); + arguments.add(attrInteger8); + arguments.add(attrIntegerM1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.String.class, res.getValue().getValue().getClass()); + resValue = (String)res.getValue().getValue(); + assertEquals(" string abc", resValue); + + // first index too low + arguments.clear(); + arguments.add(attrBigString); + arguments.add(attrIntegerM1); + arguments.add(attrInteger8); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-substring Start point '-1' out of range 0-19 for string='abc some string abc'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // second index too big + arguments.clear(); + arguments.add(attrBigString); + arguments.add(attrInteger8); + arguments.add(attrInteger20); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-substring End point '20' out of range 0-19 for string='abc some string abc'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // indexes reversed + arguments.clear(); + arguments.add(attrBigString); + arguments.add(attrInteger8); + arguments.add(attrInteger1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-substring End point '1' less than start point 'null' for string='abc some string abc'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // indexes the same + arguments.clear(); + arguments.add(attrBigString); + arguments.add(attrInteger8); + arguments.add(attrInteger8); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.String.class, res.getValue().getValue().getClass()); + resValue = (String)res.getValue().getValue(); + assertEquals("", resValue); + + // blank string with indexes both 0 + arguments.clear(); + arguments.add(attrBlank); + arguments.add(attrInteger0); + arguments.add(attrInteger0); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.String.class, res.getValue().getValue().getClass()); + resValue = (String)res.getValue().getValue(); + assertEquals("", resValue); + + // non-string first attribute + arguments.clear(); + arguments.add(attrDouble); + arguments.add(attrInteger8); + arguments.add(attrInteger1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-substring Expected data type 'string' saw 'double'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // non-integer 2nd attr + arguments.clear(); + arguments.add(attrBigString); + arguments.add(attrDouble); + arguments.add(attrInteger1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-substring Expected data type 'integer' saw 'double'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // non-integer 3rd attr + arguments.clear(); + arguments.add(attrBigString); + arguments.add(attrInteger8); + arguments.add(attrDouble); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-substring Expected data type 'integer' saw 'double'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // 4 args + arguments.clear(); + arguments.add(attrBigString); + arguments.add(attrInteger8); + arguments.add(attrInteger1); + arguments.add(attrInteger1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-substring Expected 3 arguments, got 4", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // 2 args + arguments.clear(); + arguments.add(attrBigString); + arguments.add(attrInteger8); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-substring Expected 3 arguments, got 2", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null 1st arg + arguments.clear(); + arguments.add(attrNull); + arguments.add(attrInteger8); + arguments.add(attrInteger1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-substring Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // null 2nd arg + arguments.clear(); + arguments.add(attrBigString); + arguments.add(attrNull); + arguments.add(attrInteger1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-substring Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + } + + + + + @Test + public void testAnyURISubstring() { + String bigString = new String("http://company.com:8080/this/is/some/long/uri"); + + FunctionArgumentAttributeValue attrURI = null; + FunctionArgumentAttributeValue attrNull = null; + FunctionArgumentAttributeValue attrBlank = null; + FunctionArgumentAttributeValue attrDouble = null; + + FunctionArgumentAttributeValue attrInteger0 = null; + FunctionArgumentAttributeValue attrInteger1 = null; + FunctionArgumentAttributeValue attrIntegerM1 = null; + FunctionArgumentAttributeValue attrInteger8 = null; + FunctionArgumentAttributeValue attrInteger45 = null; + FunctionArgumentAttributeValue attrInteger46 = null; + + + + try { + attrURI = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(bigString)); + attrBlank = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue("")); + attrNull = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(null)); + attrInteger0 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(0)); + attrInteger1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1)); + attrIntegerM1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(-1)); + attrInteger8 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(8)); + attrInteger45 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(45)); + attrInteger46 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(46)); + attrDouble = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(123.4)); + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + FunctionDefinitionStringFunctions fd = (FunctionDefinitionStringFunctions) StdFunctions.FD_ANYURI_SUBSTRING; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_ANYURI_SUBSTRING, fd.getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + + // match + arguments.clear(); + arguments.add(attrURI); + arguments.add(attrInteger1); + arguments.add(attrInteger8); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.String.class, res.getValue().getValue().getClass()); + String resValue = (String)res.getValue().getValue(); + assertEquals("ttp://c", resValue); + + // edge: start + arguments.clear(); + arguments.add(attrURI); + arguments.add(attrInteger0); + arguments.add(attrInteger8); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.String.class, res.getValue().getValue().getClass()); + resValue = (String)res.getValue().getValue(); + assertEquals("http://c", resValue); + + // edge: end + arguments.clear(); + arguments.add(attrURI); + arguments.add(attrInteger8); + arguments.add(attrInteger45); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.String.class, res.getValue().getValue().getClass()); + resValue = (String)res.getValue().getValue(); + assertEquals("ompany.com:8080/this/is/some/long/uri", resValue); + + // from index to end of string + arguments.clear(); + arguments.add(attrURI); + arguments.add(attrInteger8); + arguments.add(attrIntegerM1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.String.class, res.getValue().getValue().getClass()); + resValue = (String)res.getValue().getValue(); + assertEquals("ompany.com:8080/this/is/some/long/uri", resValue); + + // first index too low + arguments.clear(); + arguments.add(attrURI); + arguments.add(attrIntegerM1); + arguments.add(attrInteger8); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:anyURI-substring Start point '-1' out of range 0-45 for string='http://company.com:8080/this/is/some/long/uri'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // second index too big + arguments.clear(); + arguments.add(attrURI); + arguments.add(attrInteger8); + arguments.add(attrInteger46); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:anyURI-substring End point '46' out of range 0-45 for string='http://company.com:8080/this/is/some/long/uri'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // indexes reversed + arguments.clear(); + arguments.add(attrURI); + arguments.add(attrInteger8); + arguments.add(attrInteger1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:anyURI-substring End point '1' less than start point 'null' for string='http://company.com:8080/this/is/some/long/uri'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // indexes the same + arguments.clear(); + arguments.add(attrURI); + arguments.add(attrInteger8); + arguments.add(attrInteger8); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.String.class, res.getValue().getValue().getClass()); + resValue = (String)res.getValue().getValue(); + assertEquals("", resValue); + + // blank string with indexes both 0 + arguments.clear(); + arguments.add(attrBlank); + arguments.add(attrInteger0); + arguments.add(attrInteger0); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.String.class, res.getValue().getValue().getClass()); + resValue = (String)res.getValue().getValue(); + assertEquals("", resValue); + + // non-string first attribute + arguments.clear(); + arguments.add(attrDouble); + arguments.add(attrInteger8); + arguments.add(attrInteger1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:anyURI-substring Expected data type 'anyURI' saw 'double'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // non-integer 2nd attr + arguments.clear(); + arguments.add(attrURI); + arguments.add(attrDouble); + arguments.add(attrInteger1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:anyURI-substring Expected data type 'integer' saw 'double'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // non-integer 3rd attr + arguments.clear(); + arguments.add(attrURI); + arguments.add(attrInteger8); + arguments.add(attrDouble); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:anyURI-substring Expected data type 'integer' saw 'double'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // 4 args + arguments.clear(); + arguments.add(attrURI); + arguments.add(attrInteger8); + arguments.add(attrInteger1); + arguments.add(attrInteger1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:anyURI-substring Expected 3 arguments, got 4", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // 2 args + arguments.clear(); + arguments.add(attrURI); + arguments.add(attrInteger8); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:anyURI-substring Expected 3 arguments, got 2", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null 1st arg + arguments.clear(); + arguments.add(attrNull); + arguments.add(attrInteger8); + arguments.add(attrInteger1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:anyURI-substring Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // null 2nd arg + arguments.clear(); + arguments.add(attrURI); + arguments.add(attrNull); + arguments.add(attrInteger1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:anyURI-substring Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + + + + + + + + + + + + + + + + + + + + @Test + public void testStringContains() { + String v1 = new String("abc"); + String bigger = new String("abc some string abc"); + String biggerNoMatch = new String(" abc some string abc "); + String caps = new String("AbC"); + + FunctionArgumentAttributeValue attrV1 = null; + FunctionArgumentAttributeValue attrBigger = null; + FunctionArgumentAttributeValue attrBiggerNoMatch = null; + FunctionArgumentAttributeValue attrCaps = null; + FunctionArgumentAttributeValue attrNull = null; + FunctionArgumentAttributeValue attrBlank = null; + FunctionArgumentAttributeValue attrInteger = null; + try { + attrV1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(v1)); + attrBigger = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(bigger)); + attrBiggerNoMatch = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(biggerNoMatch)); + attrCaps = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(caps)); + attrBlank = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("")); + attrNull = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(null)); + attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234)); + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + FunctionDefinitionStringFunctions fd = (FunctionDefinitionStringFunctions) StdFunctions.FD_STRING_CONTAINS; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_CONTAINS, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + + // match + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrBigger); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertEquals(true, resValue); + + // no match + arguments.clear(); + arguments.add(attrBiggerNoMatch); + arguments.add(attrV1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // caps no match + arguments.clear(); + arguments.add(attrCaps); + arguments.add(attrBigger); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // bigger on the inside + arguments.clear(); + arguments.add(attrBigger); + arguments.add(attrV1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // empty non-null first arg + arguments.clear(); + arguments.add(attrBlank); + arguments.add(attrBigger); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(true, resValue); + + // empty non-null second arg + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // two blanks + arguments.clear(); + arguments.add(attrBlank); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(true, resValue); + + // null firat arg + arguments.clear(); + arguments.add(attrNull); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-contains Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null second arg + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrNull); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-contains Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // illegal arg type + arguments.clear(); + arguments.add(attrInteger); + arguments.add(attrBigger); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-contains Expected data type 'string' saw 'integer'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + @Test + public void testAnyuriContains() { + + + FunctionArgumentAttributeValue attrV1 = null; + FunctionArgumentAttributeValue attrBigger = null; + FunctionArgumentAttributeValue attrBiggerNoMatch = null; + FunctionArgumentAttributeValue attrCaps = null; + FunctionArgumentAttributeValue attrBigString = null; + FunctionArgumentAttributeValue attrNull = null; + FunctionArgumentAttributeValue attrBlankString = null; + FunctionArgumentAttributeValue attrBlankURI = null; + FunctionArgumentAttributeValue attrInteger = null; + try { + String v1 = new String("abc"); + URI bigger = new URI("abc.some.stringabc"); + URI biggerNoMatch = new URI("Zabc.some.stringabcZ"); + String caps = new String("AbC"); + String bigString = "thisIsSomeReallyBigStringToMatch"; + + attrV1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(v1)); + attrBigger = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(bigger)); + attrBiggerNoMatch = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(biggerNoMatch)); + attrCaps = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(caps)); + attrBigString = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(bigString)); + attrBlankString = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("")); + attrBlankURI = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue("")); + attrNull = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(null)); + attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234)); + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + FunctionDefinitionStringFunctions fd = (FunctionDefinitionStringFunctions) StdFunctions.FD_ANYURI_CONTAINS; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_ANYURI_CONTAINS, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + + // match + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrBigger); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertEquals(true, resValue); + + // no match + arguments.clear(); + arguments.add(attrBigString); + arguments.add(attrBiggerNoMatch); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // caps no match + arguments.clear(); + arguments.add(attrCaps); + arguments.add(attrBigger); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // bigger on the inside + arguments.clear(); + arguments.add(attrBigString); + arguments.add(attrBigger); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // empty non-null first arg + arguments.clear(); + arguments.add(attrBlankString); + arguments.add(attrBigger); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(true, resValue); + + // empty non-null second arg + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrBlankURI); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + + // two blanks + arguments.clear(); + arguments.add(attrBlankString); + arguments.add(attrBlankURI); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(true, resValue); + + // arguments reversed + arguments.clear(); + arguments.add(attrBigger); + arguments.add(attrV1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:anyURI-contains Expected data type 'string' saw 'anyURI'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // null firat arg + arguments.clear(); + arguments.add(attrNull); + arguments.add(attrBlankURI); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:anyURI-contains Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null second arg + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrNull); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:anyURI-contains Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // illegal arg type + arguments.clear(); + arguments.add(attrInteger); + arguments.add(attrBigger); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:anyURI-contains Expected data type 'string' saw 'integer'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + +} diff --git a/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionStringNormalizeTest.java b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionStringNormalizeTest.java new file mode 100644 index 000000000..61848f7ff --- /dev/null +++ b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionStringNormalizeTest.java @@ -0,0 +1,118 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +import com.att.research.xacml.api.XACML3; +import com.att.research.xacml.std.datatypes.DataTypes; +import com.att.research.xacmlatt.pdp.policy.ExpressionResult; +import com.att.research.xacmlatt.pdp.policy.FunctionArgument; +import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; +import com.att.research.xacmlatt.pdp.std.StdFunctions; +import com.att.research.xacmlatt.pdp.std.functions.*; + +/** + * Test of PDP Functions (See XACML core spec section A.3) + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * + */ +public class FunctionDefinitionStringNormalizeTest { + + /* + * variables useful in the following tests + */ + List arguments = new ArrayList(); + + @Test + public void testString_normalize_space() { + String initialString = " First and last are whitespace "; + FunctionArgumentAttributeValue attr1 = null; + try { + attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(initialString)); + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionStringNormalize fd = (FunctionDefinitionStringNormalize) StdFunctions.FD_STRING_NORMALIZE_SPACE; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_NORMALIZE_SPACE, fd.getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + + // test normal add + arguments.add(attr1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + String resValue = (String)res.getValue().getValue(); + assertEquals(initialString.length() - 4, resValue.length()); + assertTrue(initialString.trim().equals(resValue)); + } + + + @Test + public void testString_normalize_to_lower_case() { + String initialString = " First and last are whitespace "; + FunctionArgumentAttributeValue attr1 = null; + try { + attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(initialString)); + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionStringNormalize fd = (FunctionDefinitionStringNormalize) StdFunctions.FD_STRING_NORMALIZE_TO_LOWER_CASE; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_NORMALIZE_TO_LOWER_CASE, fd.getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + + // test normal add + arguments.add(attr1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + String resValue = (String)res.getValue().getValue(); + assertTrue(initialString.toLowerCase().equals(resValue)); + } + +} diff --git a/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionURIStringConcatenateTest.java b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionURIStringConcatenateTest.java new file mode 100644 index 000000000..50a0fd315 --- /dev/null +++ b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionURIStringConcatenateTest.java @@ -0,0 +1,185 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.net.URI; +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +import com.att.research.xacml.api.XACML2; +import com.att.research.xacml.std.datatypes.DataTypes; +import com.att.research.xacmlatt.pdp.policy.ExpressionResult; +import com.att.research.xacmlatt.pdp.policy.FunctionArgument; +import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; +import com.att.research.xacmlatt.pdp.std.StdFunctions; +import com.att.research.xacmlatt.pdp.std.functions.*; + +/** + * Test of PDP Functions (See XACML core spec section A.3) + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * + */ +public class FunctionDefinitionURIStringConcatenateTest { + + /* + * THE FUNCTION BEING TESTED BY THIS CLASS IS DEPRECATED + * uri-string-concatenate has been deprecated in XACML 3.0 + */ + + /* + * variables useful in the following tests + */ + List arguments = new ArrayList(); + + + @SuppressWarnings("deprecation") + @Test + public void testURI_string_concatenate() { + + // URI args + FunctionArgumentAttributeValue attrURI1 = null; + + + FunctionArgumentAttributeValue attrStrAbc = null; + FunctionArgumentAttributeValue attrStrSlashMno = null; + FunctionArgumentAttributeValue attrStrSlashInMiddle = null; + FunctionArgumentAttributeValue attrStrWithSpace = null; + + + try { + attrURI1 = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue("http://someplace")); + + + attrStrAbc = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("Abc")); + attrStrSlashMno = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("/Mno")); + attrStrSlashInMiddle = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("hij/pqr")); + attrStrWithSpace = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("x y z")); + + + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + // deprecation marking in the following line is correct - this function IS deprecated but still valid for XACML 3.0 + FunctionDefinitionURIStringConcatenate fd = (FunctionDefinitionURIStringConcatenate) StdFunctions.FD_URI_STRING_CONCATENATE; + + // check identity and type of the thing created + assertEquals(XACML2.ID_FUNCTION_URI_STRING_CONCATENATE, fd.getId()); + assertEquals(DataTypes.DT_ANYURI.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + + // add one string to uri + arguments.clear(); + arguments.add(attrURI1); + arguments.add(attrStrAbc); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.net.URI.class, res.getValue().getValue().getClass()); + URI resValue = (URI)res.getValue().getValue(); + assertEquals("http://someplaceAbc", resValue.toString()); + + + // add 2 strings to uri + arguments.clear(); + arguments.add(attrURI1); + arguments.add(attrStrAbc); + arguments.add(attrStrSlashMno); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.net.URI.class, res.getValue().getValue().getClass()); + resValue = (URI)res.getValue().getValue(); + assertEquals("http://someplaceAbc/Mno", resValue.toString()); + + // slash in middle of string + arguments.clear(); + arguments.add(attrURI1); + arguments.add(attrStrSlashInMiddle); + arguments.add(attrStrSlashMno); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.net.URI.class, res.getValue().getValue().getClass()); + resValue = (URI)res.getValue().getValue(); + assertEquals("http://someplacehij/pqr/Mno", resValue.toString()); + + // create bad uri + arguments.clear(); + arguments.add(attrURI1); + arguments.add(attrStrWithSpace); + arguments.add(attrStrSlashMno); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:uri-string-concatenate Final string 'http://someplacex y z/Mno' not URI, Illegal character in authority at index 7: http://someplacex y z/Mno", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // no args + arguments.clear(); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:uri-string-concatenate Expected 2 or more arguments, got 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // one arg + arguments.clear(); + arguments.add(attrURI1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:uri-string-concatenate Expected 2 or more arguments, got 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // first arg not uri + arguments.clear(); + arguments.add(attrStrAbc); + arguments.add(attrURI1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:uri-string-concatenate Expected data type 'anyURI' saw 'string' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // 2nd arg not string + arguments.clear(); + arguments.add(attrURI1); + arguments.add(attrURI1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:uri-string-concatenate Expected data type 'string' saw 'anyURI' at arg index 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + + +} diff --git a/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionXPathTest.java b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionXPathTest.java new file mode 100644 index 000000000..3a7d12869 --- /dev/null +++ b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionXPathTest.java @@ -0,0 +1,1127 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import javax.xml.namespace.NamespaceContext; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathFactory; + +import org.junit.Test; + +import com.att.research.xacml.api.Request; +import com.att.research.xacml.api.XACML3; +import com.att.research.xacml.std.IdentifierImpl; +import com.att.research.xacml.std.StdRequest; +import com.att.research.xacml.std.StdStatus; +import com.att.research.xacml.std.datatypes.DataTypes; +import com.att.research.xacml.std.datatypes.XPathExpressionWrapper; +import com.att.research.xacml.std.dom.DOMRequest; +import com.att.research.xacmlatt.pdp.policy.ExpressionResult; +import com.att.research.xacmlatt.pdp.policy.FunctionArgument; +import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; +import com.att.research.xacmlatt.pdp.std.StdEvaluationContext; +import com.att.research.xacmlatt.pdp.std.StdFunctions; +import com.att.research.xacmlatt.pdp.std.functions.*; + +/** + * Test of PDP Functions (See XACML core spec section A.3) + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * + */ +public class FunctionDefinitionXPathTest { + + // + // Strings for the Request contents + // + + String reqStrMainStart = "" + + "" + + " " + + " " + + " Julius Hibbert" + + " " + + " " + + " This is IT! " + + " " + + " " + + " This is IT! " + + " " + + ""; + + String reqStrResourceStart = ""; + + String reqStrContentMdRecord = + " " + + "" + + "" + + "ABC Hospital" + + "Surgery" + + "" + + "" + + "Bart Simpson" + + "60" + + "male" + + "123456" + + "" + + "" + + "" + + "Gastric Cancer" + + "Hyper tension" + + "" + + "" + + "" + + "Well differentiated adeno carcinoma" + + "" + + "2000-10-05" + + "" + + "" + + " " + + " " + + ""; + String reqStrMalformedContent = + " " + + "" + + "" + + "ABC Hospital" + + "" + + ""; + String reqStrResourceEnd = " " + + " http://medico.com/record/patient/BartSimpson" + + " " + + " "; + String reqStrActionStart = ""; + + String reqStrActionEnd = "" + + "read" + + "" + + " "; + String reqStrEnvironmentStartEnd = " "; + String reqStrMainEnd = " "; + + + // combined strings for convenience + String reqStrMainResourceStart = reqStrMainStart + reqStrResourceStart; + String reqStrResourceAllEnd = reqStrResourceEnd + reqStrActionStart + reqStrActionEnd + reqStrEnvironmentStartEnd + reqStrMainEnd; + + + /* + * variables useful in the following tests + */ + List arguments = new ArrayList(); + + + + // Name Spaces used in the XML as part of these examples (copied from the Conformance tests) - needed for compiling XPaths + NamespaceContext nameSpaceContext = new NamespaceContext() { + @Override + public Iterator getPrefixes(String arg0) { return null;} + + @Override + public String getPrefix(String arg0) {return null;} + + @Override + public String getNamespaceURI(String arg0) { + if("md".equals(arg0)) { + return "http://www.medico.com/schemas/record"; + } else if ("xacml-context".equals(arg0)) { + return "urn:oasis:names:tc:xacml:3.0:context:schema:os"; + } else if ("xsi".equals(arg0)) { + return "http://www.w3.org/2001/XMLSchema-instance"; + } + return null; + } + }; + + + + // + // XPath Function Attributes available for use in tests (representing appropriate fragment of Policy) + // + + FunctionArgumentAttributeValue attrXnull = null; + FunctionArgumentAttributeValue attrXEmpty = null; + FunctionArgumentAttributeValue attrXNoCategory = null; + FunctionArgumentAttributeValue attrXNoValue = null; + FunctionArgumentAttributeValue attrXSlashSlashMdRecord = null; + FunctionArgumentAttributeValue attrXSlashSlashStar = null; + FunctionArgumentAttributeValue attrXSlashSlashMdName = null; + FunctionArgumentAttributeValue attrXSlashSlashMdMalignancy = null; + FunctionArgumentAttributeValue attrXNotInRequest = null; + FunctionArgumentAttributeValue attrXSlashSlashMdRecordSlashStar = null; + FunctionArgumentAttributeValue attrXMdPatientInfo = null; + + FunctionArgumentAttributeValue attrBadType = null; + + // String version of attrs for use in Deprecated functions + FunctionArgumentAttributeValue attrStrnull = null; + FunctionArgumentAttributeValue attrStrEmpty = null; + FunctionArgumentAttributeValue attrStrNoCategory = null; + FunctionArgumentAttributeValue attrStrNoValue = null; + FunctionArgumentAttributeValue attrStrSlashSlashMdRecord = null; + FunctionArgumentAttributeValue attrStrSlashSlashStar = null; + FunctionArgumentAttributeValue attrStrSlashSlashMdName = null; + FunctionArgumentAttributeValue attrStrSlashSlashMdMalignancy = null; + FunctionArgumentAttributeValue attrStrNotInRequest = null; + FunctionArgumentAttributeValue attrStrSlashSlashMdRecordSlashStar = null; + FunctionArgumentAttributeValue attrStrMdPatientInfo = null; + + + // + // REQUEST objects available for use in tests + // + Request requestEmpty = new StdRequest(StdStatus.STATUS_OK); + Request requestMdRecord = null; + Request requestDoubleResources = null; + Request requestResourceActionContent = null; + Request requestContentInAction = null; + + + + + /** + * Set up all variables in one place because it is complicated (lots of steps needed for each attribute) + */ + public FunctionDefinitionXPathTest() { + try { + XPathFactory xPathFactory = XPathFactory.newInstance(); + XPath xpath = xPathFactory.newXPath(); + xpath.setNamespaceContext(nameSpaceContext); + + // Create XPaths to use in expressions + XPathExpressionWrapper xEmpty = new XPathExpressionWrapper(""); + XPathExpressionWrapper xSlashSlashMdRecord = new XPathExpressionWrapper(xpath.compile("//md:record")); + XPathExpressionWrapper xSlashSlashStar = new XPathExpressionWrapper(xpath.compile("//*")); + XPathExpressionWrapper xSlashSlashMdName = new XPathExpressionWrapper(xpath.compile("//md:name")); + XPathExpressionWrapper xSlashSlashMdMalignancy = new XPathExpressionWrapper(xpath.compile("//md:malignancy")); + XPathExpressionWrapper xNotInRequest = new XPathExpressionWrapper(xpath.compile("value_Not_in_request")); + XPathExpressionWrapper xSlashSlashMdRecordSlashStar = new XPathExpressionWrapper(xpath.compile("//md:record/*")); + XPathExpressionWrapper xMdPatientInfo = new XPathExpressionWrapper(xpath.compile("md:patient_info")); + + + + // create Function Attributes out of the XPathExpressions + attrXnull = new FunctionArgumentAttributeValue(null); + attrXEmpty = new FunctionArgumentAttributeValue(DataTypes.DT_XPATHEXPRESSION.createAttributeValue(xEmpty)); + attrXNoCategory = new FunctionArgumentAttributeValue(DataTypes.DT_XPATHEXPRESSION.createAttributeValue(xSlashSlashMdRecord)); + attrXNoValue = new FunctionArgumentAttributeValue(DataTypes.DT_XPATHEXPRESSION.createAttributeValue(xEmpty, + new IdentifierImpl("urn:oasis:names:tc:xacml:3.0:attribute-category:resource" ))); + attrXSlashSlashMdRecord = new FunctionArgumentAttributeValue(DataTypes.DT_XPATHEXPRESSION.createAttributeValue(xSlashSlashMdRecord, + new IdentifierImpl("urn:oasis:names:tc:xacml:3.0:attribute-category:resource" ))); + attrXSlashSlashStar = new FunctionArgumentAttributeValue(DataTypes.DT_XPATHEXPRESSION.createAttributeValue(xSlashSlashStar, + new IdentifierImpl("urn:oasis:names:tc:xacml:3.0:attribute-category:resource" ))); + attrXSlashSlashMdName = new FunctionArgumentAttributeValue(DataTypes.DT_XPATHEXPRESSION.createAttributeValue(xSlashSlashMdName, + new IdentifierImpl("urn:oasis:names:tc:xacml:3.0:attribute-category:resource" ))); + attrXSlashSlashMdMalignancy = new FunctionArgumentAttributeValue(DataTypes.DT_XPATHEXPRESSION.createAttributeValue(xSlashSlashMdMalignancy, + new IdentifierImpl("urn:oasis:names:tc:xacml:3.0:attribute-category:resource" ))); + attrXNotInRequest = new FunctionArgumentAttributeValue(DataTypes.DT_XPATHEXPRESSION.createAttributeValue(xNotInRequest, + new IdentifierImpl("urn:oasis:names:tc:xacml:3.0:attribute-category:resource" ))); + + attrXSlashSlashMdRecordSlashStar = new FunctionArgumentAttributeValue(DataTypes.DT_XPATHEXPRESSION.createAttributeValue(xSlashSlashMdRecordSlashStar, + new IdentifierImpl("urn:oasis:names:tc:xacml:3.0:attribute-category:resource" ))); + attrXMdPatientInfo = new FunctionArgumentAttributeValue(DataTypes.DT_XPATHEXPRESSION.createAttributeValue(xMdPatientInfo, + new IdentifierImpl("urn:oasis:names:tc:xacml:3.0:attribute-category:resource" ))); + + + // Deprecated versions of args + attrStrnull = new FunctionArgumentAttributeValue(null); + attrStrEmpty = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("")); + attrStrNoCategory = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("//md:record")); + attrStrNoValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("", + new IdentifierImpl("urn:oasis:names:tc:xacml:3.0:attribute-category:resource" ))); + attrStrSlashSlashMdRecord = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("//md:record", + new IdentifierImpl("urn:oasis:names:tc:xacml:3.0:attribute-category:resource" ))); + attrStrSlashSlashStar = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("//*", + new IdentifierImpl("urn:oasis:names:tc:xacml:3.0:attribute-category:resource" ))); + attrStrSlashSlashMdName = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("//md:name", + new IdentifierImpl("urn:oasis:names:tc:xacml:3.0:attribute-category:resource" ))); + attrStrSlashSlashMdMalignancy = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("//md:malignancy", + new IdentifierImpl("urn:oasis:names:tc:xacml:3.0:attribute-category:resource" ))); + attrStrNotInRequest = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("value_Not_in_request", + new IdentifierImpl("urn:oasis:names:tc:xacml:3.0:attribute-category:resource" ))); + + attrStrSlashSlashMdRecordSlashStar = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("//md:record/*", + new IdentifierImpl("urn:oasis:names:tc:xacml:3.0:attribute-category:resource" ))); + attrStrMdPatientInfo = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("md:patient_info", + new IdentifierImpl("urn:oasis:names:tc:xacml:3.0:attribute-category:resource" ))); + + + + + attrBadType = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("some string")); + + + + // Request objects + // to create a Request object the easiest way is to put the xml into a file and use the DOMRequest to load it. + + // single Content in the Resources section (normal valid request) + String reqString = reqStrMainResourceStart + reqStrContentMdRecord + reqStrResourceAllEnd; + File tFile = File.createTempFile("functionJunit", "request"); + BufferedWriter bw = new BufferedWriter(new FileWriter(tFile)); + bw.append(reqString); + bw.flush(); + bw.close(); + requestMdRecord = DOMRequest.load(tFile); + tFile.delete(); + + // Resources included twice + reqString = reqStrMainResourceStart + reqStrContentMdRecord + reqStrResourceEnd + reqStrResourceStart + reqStrContentMdRecord +reqStrResourceAllEnd; + tFile = File.createTempFile("functionJunit", "request"); + bw = new BufferedWriter(new FileWriter(tFile)); + bw.append(reqString); + bw.flush(); + bw.close(); + requestDoubleResources = DOMRequest.load(tFile); + tFile.delete(); + + + // content included in both Resource and Action - ok + reqString = reqStrMainResourceStart + reqStrContentMdRecord + reqStrResourceEnd + reqStrActionStart + reqStrContentMdRecord + reqStrActionEnd + reqStrMainEnd; + tFile = File.createTempFile("functionJunit", "request"); + bw = new BufferedWriter(new FileWriter(tFile)); + bw.append(reqString); + bw.flush(); + bw.close(); + requestResourceActionContent = DOMRequest.load(tFile); + tFile.delete(); + + // Content included only in Action - missing content produces non-error result according to spec + reqString = reqStrMainResourceStart + reqStrResourceEnd + reqStrActionStart + reqStrContentMdRecord + reqStrActionEnd + reqStrMainEnd; + tFile = File.createTempFile("functionJunit", "request"); + bw = new BufferedWriter(new FileWriter(tFile)); + bw.append(reqString); + bw.flush(); + bw.close(); + requestContentInAction = DOMRequest.load(tFile); + tFile.delete(); + + + + // Test that Bad XML is caught + @SuppressWarnings("unused") + Request requestContentMisplaced = null; + @SuppressWarnings("unused") + Request requestMalformedContent = null; + @SuppressWarnings("unused") + Request requestDoubleContent = null; + + + // Content included twice - error + reqString = reqStrMainResourceStart + reqStrContentMdRecord + reqStrContentMdRecord +reqStrResourceAllEnd; + tFile = File.createTempFile("functionJunit", "request"); + bw = new BufferedWriter(new FileWriter(tFile)); + bw.append(reqString); + bw.flush(); + bw.close(); + try { + requestDoubleContent = DOMRequest.load(tFile); + tFile.delete(); + } catch (com.att.research.xacml.std.dom.DOMStructureException e) { + // this is what it should do, so just continue + } catch (Exception e) { + fail("Unexpected exception for bad XML, e="+e); + } + + // Bad XML - Content not under a Category + reqString = reqStrMainStart + reqStrContentMdRecord + reqStrResourceStart + reqStrResourceEnd + reqStrActionStart + reqStrActionEnd + reqStrMainEnd; + tFile = File.createTempFile("functionJunit", "request"); + bw = new BufferedWriter(new FileWriter(tFile)); + bw.append(reqString); + bw.flush(); + bw.close(); + try { + requestContentMisplaced = DOMRequest.load(tFile); + tFile.delete(); + } catch (com.att.research.xacml.std.dom.DOMStructureException e) { + // this is what it should do, so just continue + } catch (Exception e) { + fail("Unexpected exception for bad XML, e="+e); + } + + // Bad XML - Content is not valid XML + reqString = reqStrMainResourceStart + reqStrMalformedContent + reqStrResourceAllEnd; + tFile = File.createTempFile("functionJunit", "request"); + bw = new BufferedWriter(new FileWriter(tFile)); + bw.append(reqString); + bw.flush(); + bw.close(); + try { + requestMalformedContent = DOMRequest.load(tFile); + tFile.delete(); + } catch (com.att.research.xacml.std.dom.DOMStructureException e) { + // this is what it should do, so just continue + } catch (Exception e) { + fail("Unexpected exception for bad XML, e="+e); + } + + } catch (Exception e) { + fail("Constructor initializing variables, e="+ e + " cause="+e.getCause()); + } + + } + + + + + + + + + @Test + public void testXpath_node_count() { + + + + FunctionDefinitionXPath fd = (FunctionDefinitionXPath) StdFunctions.FD_XPATH_NODE_COUNT; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_XPATH_NODE_COUNT, fd.getId()); + assertEquals(DataTypes.DT_XPATHEXPRESSION.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + + // match all elements within context + arguments.clear(); + arguments.add(attrXSlashSlashStar); + ExpressionResult res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertTrue(res.isOk()); + BigInteger resValue = (BigInteger)res.getValue().getValue(); + assertEquals(new BigInteger("18"), resValue); + + // match exactly 1 element + arguments.clear(); + arguments.add(attrXSlashSlashMdMalignancy); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertTrue(res.isOk()); + resValue = (BigInteger)res.getValue().getValue(); + assertEquals(new BigInteger("1"), resValue); + + // match a few but not all + arguments.clear(); + arguments.add(attrXSlashSlashMdName); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertTrue(res.isOk()); + resValue = (BigInteger)res.getValue().getValue(); + assertEquals(new BigInteger("2"), resValue); + + + // verify variables using in other tests: count nodes immediately under md:record + arguments.clear(); + arguments.add(attrXSlashSlashMdRecordSlashStar); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertTrue(res.isOk()); + resValue = (BigInteger)res.getValue().getValue(); + assertEquals(new BigInteger("3"), resValue); + + // verify variables using in other tests: count number of records containing patient_info + arguments.clear(); + arguments.add(attrXMdPatientInfo); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertTrue(res.isOk()); + resValue = (BigInteger)res.getValue().getValue(); + assertEquals(new BigInteger("1"), resValue); + + // verify variables using in other tests: count number of records containing md:name + arguments.clear(); + arguments.add(attrXSlashSlashMdName); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertTrue(res.isOk()); + resValue = (BigInteger)res.getValue().getValue(); + assertEquals(new BigInteger("2"), resValue); + + // verify variables using in other tests: count number of records containing md:malignancy + arguments.clear(); + arguments.add(attrXSlashSlashMdMalignancy); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertTrue(res.isOk()); + resValue = (BigInteger)res.getValue().getValue(); + assertEquals(new BigInteger("1"), resValue); + + + + + // match no element + arguments.clear(); + arguments.add(attrXNotInRequest); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertTrue(res.isOk()); + resValue = (BigInteger)res.getValue().getValue(); + assertEquals(new BigInteger("0"), resValue); + + // Resources included twice + arguments.clear(); + arguments.add(attrXSlashSlashMdName); + res = fd.evaluate(new StdEvaluationContext(requestDoubleResources, null, null), arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-count More than one Content section for id 'urn:oasis:names:tc:xacml:3.0:attribute-category:resource'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // Content in both Resource and Action categories (ok) + arguments.clear(); + arguments.add(attrXSlashSlashMdName); + res = fd.evaluate(new StdEvaluationContext(requestResourceActionContent, null, null), arguments); + assertTrue(res.isOk()); + resValue = (BigInteger)res.getValue().getValue(); + assertEquals(new BigInteger("2"), resValue); + + // Content only in Action category (missing in Resources -> 0 according to spec) + arguments.clear(); + arguments.add(attrXSlashSlashMdName); + res = fd.evaluate(new StdEvaluationContext(requestContentInAction, null, null), arguments); + assertTrue(res.isOk()); + resValue = (BigInteger)res.getValue().getValue(); + assertEquals(new BigInteger("0"), resValue); + + + + +//TODO - any other tests???? + + // null Evaluation Context + arguments.clear(); + arguments.add(attrXEmpty); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-count Got null EvaluationContext", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null Request + arguments.clear(); + arguments.add(attrXSlashSlashMdRecord); + res = fd.evaluate(new StdEvaluationContext(null, null, null), arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-count Got null Request in EvaluationContext", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null attribute + arguments.clear(); + arguments.add(attrXnull); + res = fd.evaluate(new StdEvaluationContext(requestEmpty, null, null), arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-count Got null attribute at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // no value + arguments.clear(); + arguments.add(attrXNoValue); + res = fd.evaluate(new StdEvaluationContext(requestEmpty, null, null), arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-count XPathExpression returned null at index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // no category + arguments.clear(); + arguments.add(attrXNoCategory); + res = fd.evaluate(new StdEvaluationContext(requestEmpty, null, null), arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-count Got null Category at index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // too many args + arguments.clear(); + arguments.add(attrXEmpty); + arguments.add(attrXEmpty); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-count Expected 1 arguments, got 2", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // too few args + arguments.clear(); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-count Expected 1 arguments, got 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-count Expected data type 'xpathExpression' saw 'string' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null args + arguments.clear(); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-count Got null argument at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + @Test + public void testXpath_node_equal() { + + + FunctionDefinitionXPath fd = (FunctionDefinitionXPath) StdFunctions.FD_XPATH_NODE_EQUAL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_XPATH_NODE_EQUAL, fd.getId()); + assertEquals(DataTypes.DT_XPATHEXPRESSION.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + + // test normal success - exactly the same set + arguments.clear(); + arguments.add(attrXSlashSlashMdName); + arguments.add(attrXSlashSlashMdName); + ExpressionResult res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // success - second list is subset of first list + arguments.clear(); + arguments.add(attrXSlashSlashMdRecordSlashStar); + arguments.add(attrXMdPatientInfo); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // success - first list is subset of second list + arguments.clear(); + arguments.add(attrXMdPatientInfo); + arguments.add(attrXSlashSlashMdRecordSlashStar); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // success - second list contains children of first list + arguments.clear(); + arguments.add(attrXSlashSlashMdRecord); + arguments.add(attrXSlashSlashMdName); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // success - first list contains children of second list + arguments.clear(); + arguments.add(attrXSlashSlashMdName); + arguments.add(attrXSlashSlashMdRecord); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + + + // two non-overlapping sets + arguments.clear(); + arguments.add(attrXSlashSlashMdMalignancy); + arguments.add(attrXSlashSlashMdName); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first list contains nothing + arguments.clear(); + arguments.add(attrXNotInRequest); + arguments.add(attrXSlashSlashMdName); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // second list contains nothing + arguments.clear(); + arguments.add(attrXSlashSlashMdName); + arguments.add(attrXNotInRequest); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + + +//TODO + //????? + ///??????? add real tests + ////// + + + // Resources included twice + arguments.clear(); + arguments.add(attrXSlashSlashMdName); + arguments.add(attrXSlashSlashMdName); + res = fd.evaluate(new StdEvaluationContext(requestDoubleResources, null, null), arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-equal More than one Content section for id 'urn:oasis:names:tc:xacml:3.0:attribute-category:resource'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + + // Content in both Resource and Action categories (ok) + arguments.clear(); + arguments.add(attrXSlashSlashMdName); + arguments.add(attrXSlashSlashMdName); + res = fd.evaluate(new StdEvaluationContext(requestResourceActionContent, null, null), arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // Content only in Action category (missing in Resources -> 0 according to spec) + arguments.clear(); + arguments.add(attrXSlashSlashMdName); + arguments.add(attrXSlashSlashMdName); + res = fd.evaluate(new StdEvaluationContext(requestContentInAction, null, null), arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + + // null Evaluation Context + arguments.clear(); + arguments.add(attrXSlashSlashMdRecord); + arguments.add(attrXSlashSlashMdRecord); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-equal Got null EvaluationContext", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null Request + arguments.clear(); + arguments.add(attrXSlashSlashMdRecord); + arguments.add(attrXSlashSlashMdRecord); + res = fd.evaluate(new StdEvaluationContext(null, null, null), arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-equal Got null Request in EvaluationContext", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null attribute + arguments.clear(); + arguments.add(attrXnull); + arguments.add(attrXSlashSlashMdRecord); + res = fd.evaluate(new StdEvaluationContext(requestEmpty, null, null), arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-equal Got null attribute at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + arguments.add(attrXSlashSlashMdRecord); + arguments.add(attrXnull); + res = fd.evaluate(new StdEvaluationContext(requestEmpty, null, null), arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-equal Got null attribute at arg index 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // no value + arguments.clear(); + arguments.add(attrXNoValue); + arguments.add(attrXSlashSlashMdRecord); + res = fd.evaluate(new StdEvaluationContext(requestEmpty, null, null), arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-equal XPathExpression returned null at index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + arguments.add(attrXSlashSlashMdRecord); + arguments.add(attrXNoValue); + res = fd.evaluate(new StdEvaluationContext(requestEmpty, null, null), arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-equal XPathExpression returned null at index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // no category + arguments.clear(); + arguments.add(attrXNoCategory); + arguments.add(attrXSlashSlashMdRecord); + res = fd.evaluate(new StdEvaluationContext(requestEmpty, null, null), arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-equal Got null Category at index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + arguments.add(attrXSlashSlashMdRecord); + arguments.add(attrXNoCategory); + res = fd.evaluate(new StdEvaluationContext(requestEmpty, null, null), arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-equal XPathExpression returned null at index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // too many args + arguments.clear(); + arguments.add(attrXEmpty); + arguments.add(attrXEmpty); + arguments.add(attrXEmpty); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-equal Expected 2 arguments, got 3", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // too few args + arguments.clear(); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-equal Expected 2 arguments, got 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + arguments.add(attrXEmpty); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-equal Expected 2 arguments, got 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrBadType); + arguments.add(attrXEmpty); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-equal Expected data type 'xpathExpression' saw 'string' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + arguments.add(attrXEmpty); + arguments.add(attrBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-equal Expected data type 'xpathExpression' saw 'string' at arg index 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null args + arguments.clear(); + arguments.add(attrXEmpty); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-equal Got null argument at arg index 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + arguments.add(null); + arguments.add(attrXEmpty); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-equal Got null argument at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + + + @Test + public void testXpath_node_match() { + + + FunctionDefinitionXPath fd = (FunctionDefinitionXPath) StdFunctions.FD_XPATH_NODE_MATCH; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_XPATH_NODE_MATCH, fd.getId()); + assertEquals(DataTypes.DT_XPATHEXPRESSION.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + + // test normal success - exactly the same set + arguments.clear(); + arguments.add(attrXSlashSlashMdName); + arguments.add(attrXSlashSlashMdName); + ExpressionResult res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // success - second list is subset of first list + arguments.clear(); + arguments.add(attrXSlashSlashMdRecordSlashStar); + arguments.add(attrXMdPatientInfo); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // success - first list is subset of second list + arguments.clear(); + arguments.add(attrXMdPatientInfo); + arguments.add(attrXSlashSlashMdRecordSlashStar); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // success - second list contains children of first list + arguments.clear(); + arguments.add(attrXSlashSlashMdRecord); + arguments.add(attrXSlashSlashMdName); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // success - first list contains children of second list + arguments.clear(); + arguments.add(attrXSlashSlashMdName); + arguments.add(attrXSlashSlashMdRecord); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + + + // two non-overlapping sets + arguments.clear(); + arguments.add(attrXSlashSlashMdMalignancy); + arguments.add(attrXSlashSlashMdName); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first list contains nothing + arguments.clear(); + arguments.add(attrXNotInRequest); + arguments.add(attrXSlashSlashMdName); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // second list contains nothing + arguments.clear(); + arguments.add(attrXSlashSlashMdName); + arguments.add(attrXNotInRequest); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + +//TODO + //????? + ///??????? add real tests + ////// + + + // Resources included twice + arguments.clear(); + arguments.add(attrXSlashSlashMdName); + arguments.add(attrXSlashSlashMdName); + res = fd.evaluate(new StdEvaluationContext(requestDoubleResources, null, null), arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-match More than one Content section for id 'urn:oasis:names:tc:xacml:3.0:attribute-category:resource'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // Content in both Resource and Action categories (ok) + arguments.clear(); + arguments.add(attrXSlashSlashMdName); + arguments.add(attrXSlashSlashMdName); + res = fd.evaluate(new StdEvaluationContext(requestResourceActionContent, null, null), arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // Content only in Action category (missing in Resources -> 0 according to spec) + arguments.clear(); + arguments.add(attrXSlashSlashMdName); + arguments.add(attrXSlashSlashMdName); + res = fd.evaluate(new StdEvaluationContext(requestContentInAction, null, null), arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + + // null Evaluation Context + arguments.clear(); + arguments.add(attrXSlashSlashMdRecord); + arguments.add(attrXSlashSlashMdRecord); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-match Got null EvaluationContext", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null Request + arguments.clear(); + arguments.add(attrXSlashSlashMdRecord); + arguments.add(attrXSlashSlashMdRecord); + res = fd.evaluate(new StdEvaluationContext(null, null, null), arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-match Got null Request in EvaluationContext", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null attribute + arguments.clear(); + arguments.add(attrXnull); + arguments.add(attrXSlashSlashMdRecord); + res = fd.evaluate(new StdEvaluationContext(requestEmpty, null, null), arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-match Got null attribute at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + arguments.add(attrXSlashSlashMdRecord); + arguments.add(attrXnull); + res = fd.evaluate(new StdEvaluationContext(requestEmpty, null, null), arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-match Got null attribute at arg index 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // no value + arguments.clear(); + arguments.add(attrXNoValue); + arguments.add(attrXSlashSlashMdRecord); + res = fd.evaluate(new StdEvaluationContext(requestEmpty, null, null), arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-match XPathExpression returned null at index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + arguments.add(attrXSlashSlashMdRecord); + arguments.add(attrXNoValue); + res = fd.evaluate(new StdEvaluationContext(requestEmpty, null, null), arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-match XPathExpression returned null at index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // no category + arguments.clear(); + arguments.add(attrXNoCategory); + arguments.add(attrXSlashSlashMdRecord); + res = fd.evaluate(new StdEvaluationContext(requestEmpty, null, null), arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-match Got null Category at index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + arguments.add(attrXSlashSlashMdRecord); + arguments.add(attrXNoCategory); + res = fd.evaluate(new StdEvaluationContext(requestEmpty, null, null), arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-match XPathExpression returned null at index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // too many args + arguments.clear(); + arguments.add(attrXEmpty); + arguments.add(attrXEmpty); + arguments.add(attrXEmpty); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-match Expected 2 arguments, got 3", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // too few args + arguments.clear(); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-match Expected 2 arguments, got 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + arguments.add(attrXEmpty); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-match Expected 2 arguments, got 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrBadType); + arguments.add(attrXEmpty); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-match Expected data type 'xpathExpression' saw 'string' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + arguments.add(attrXEmpty); + arguments.add(attrBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-match Expected data type 'xpathExpression' saw 'string' at arg index 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null args + arguments.clear(); + arguments.add(attrXEmpty); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-match Got null argument at arg index 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + arguments.add(null); + arguments.add(attrXEmpty); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-match Got null argument at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + + } + + + + // + // DEPRECATED versions that use String arguments rather than XPATHEXPRESSIONs + // are NOT supported due to ambiguity in the semantics between 2.0 ( is root and has only one in resources) + // and 3.0 ( is root and there are multiple sections in any category) + // + + + +} diff --git a/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/PDPTest.java b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/PDPTest.java new file mode 100644 index 000000000..3b3e0b7bb --- /dev/null +++ b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/PDPTest.java @@ -0,0 +1,42 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test; + +//import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +//import static org.junit.Assert.fail; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.Test; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +public class PDPTest { + + private static final Logger logger = FlexLogger.getLogger(PDPTest.class); + + @Test + public void testDummy() { + assertNull(null); + } + +} diff --git a/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/TestRunner.java b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/TestRunner.java new file mode 100644 index 000000000..5886f836a --- /dev/null +++ b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/TestRunner.java @@ -0,0 +1,44 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test; + +import org.junit.runner.JUnitCore; +import org.junit.runner.Result; +import org.junit.runner.notification.Failure; + +public class TestRunner { + public static void main(String[] args) { + Result result = JUnitCore.runClasses(PDPTest.class); + for(Failure failure: result.getFailures()) { + System.out.println("Failed Test: " + failure.toString()); + } + Result results = null; + if(result.wasSuccessful()) { + System.out.println("Test Results... "); + System.out.println("Stats: \nRun Time: " + (results.getRunTime()+result.getRunTime()) + "\nTotal Tests:" + results.getRunCount()+ result.getRunCount() + + "\nFailures: " + results.getFailureCount()+ result.getFailureCount()); + System.exit(1); + } + System.out.println("Tests Failed..."); + System.out.println("Stats: \nRun Time: " + result.getRunTime() + "\nTests:" + result.getRunCount() + + "\nFailures: " + result.getFailureCount()); + } +} diff --git a/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/conformance/Conformance.java b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/conformance/Conformance.java new file mode 100644 index 000000000..fb0d6922a --- /dev/null +++ b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/conformance/Conformance.java @@ -0,0 +1,634 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.conformance; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.PrintWriter; +import java.net.URI; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; + +import com.att.research.xacml.api.Advice; +import com.att.research.xacml.api.Attribute; +import com.att.research.xacml.api.AttributeAssignment; +import com.att.research.xacml.api.AttributeCategory; +import com.att.research.xacml.api.AttributeValue; +import com.att.research.xacml.api.IdReference; +import com.att.research.xacml.api.Obligation; +import com.att.research.xacml.api.Response; +import com.att.research.xacml.api.Result; + +/** + * Conformance is an application that runs a ConformanceTestSet and dumps results comparing the actual and + * expected results. + * + * TO RUN in Eclipse: + * This is run as a Java Application. + * You must first create a Run/Debug Configuration: + * Under the Argument tab, in Program Arguments you must set the -i or --input command line argument. + * You should also direct the output to a file using -o or --output. (default is Console) + * See the init() method in this file for other useful arguments. + * Example for a Windows machine: + * -i testsets/conformance/xacml3.0-ct-v.0.4 + * -o \Users\yourLogin\Downloads\conformance.txt + * You must also set the VM arguments: + * -Dxacml.properties=testsets/conformance/xacml.properties . + * -Dlog4j.configuration=.\logging.properties + * + * @version $Revision: 1.2 $ + */ +public class Conformance { + private ConformanceScopeResolver scopeResolver; + private ConformanceTestEngine testEngine; + private ConformanceTestSet testSet = new ConformanceTestSet(); + private File outputFile; + private PrintWriter outputFileWriter; + + private List testNamesToRun = new ArrayList(); + + private boolean verbose; + private boolean failuresOnly; + private boolean strict; + private boolean stopOnFirstError; + + private int testsRun; + private int decisionsMatch; + private int statusCodesMatch; + private int attributesMatch; + private int policyIdsMatch; + private int policySetIdsMatch; + private int associatedAdviceMatch; + private int obligationsMatch; + private int unknownFunctions; + + + + + protected synchronized ConformanceScopeResolver getScopeResolver() { + if (this.scopeResolver == null) { + this.scopeResolver = new ConformanceScopeResolver(); + + /* + * TODO: + * Add the known scopes for the 2.0 conformance test. This could be made more general by allowing loading + * from a properties file eventually. + */ + try { + URI ID_SCOPE_ROOT = new URI("urn:root"); + URI ID_SCOPE_CHILD1 = new URI("urn:root:child1"); + URI ID_SCOPE_CHILD2 = new URI("urn:root:child2"); + URI ID_SCOPE_C1D1 = new URI("urn:root:child1:descendant1"); + URI ID_SCOPE_C1D2 = new URI("urn:root:child1:descendant2"); + URI ID_SCOPE_C2D1 = new URI("urn:root:child2:descendant1"); + URI ID_SCOPE_C2D2 = new URI("urn:root:child2:descendant2"); + + this.scopeResolver.add(ID_SCOPE_ROOT, ID_SCOPE_CHILD1); + this.scopeResolver.add(ID_SCOPE_CHILD1, ID_SCOPE_C1D1); + this.scopeResolver.add(ID_SCOPE_CHILD1, ID_SCOPE_C1D2); + this.scopeResolver.add(ID_SCOPE_ROOT, ID_SCOPE_CHILD2); + this.scopeResolver.add(ID_SCOPE_CHILD2, ID_SCOPE_C2D1); + this.scopeResolver.add(ID_SCOPE_CHILD2, ID_SCOPE_C2D2); + } catch (Exception ex) { + ex.printStackTrace(System.err); + } + + } + return this.scopeResolver; + } + + private void close() throws IOException { + if (this.outputFileWriter != null) { + this.outputFileWriter.close(); + } + } + + private boolean init(String[] args) { + boolean lenientRequests = true; + boolean lenientPolicies = false; + // default is to not run any non-first-time iterations + int iterations = -1; + String testSetDirectoryNames = ""; + for (int i = 0 ; i < args.length ; ) { + + if (args[i].equals("-h") || args[i].equals("--help") || args[i].equals("-help")) { + printHelp(); + return false; + } + + + // where the XML Request/Response files are located + if (args[i].equals("-i") || args[i].equals("--input")) { + i++; + while (i < args.length && !args[i].startsWith("-")) { + testSetDirectoryNames += " " + args[i]; + try { + testSet.addConformanceTestSet(ConformanceTestSet.loadDirectory(new File(args[i]))); + } catch (Exception ex) { + ex.printStackTrace(System.err); + return false; + } + i++; + } + + // File path name where output will be put - default is stdout == Console + } else if (args[i].equals("-o") || args[i].equals("--output")) { + if (i+1 < args.length) { + this.outputFile = new File(args[i+1]); + i += 2; + } else { + System.err.println("Missing argument to " + args[i] + " command line option"); + return false; + } + // A list of specific test names (e.g.: -t IIA001 IIA007 IIIE301) - default is to run all tests + } else if (args[i].equals("-t") || args[i].equals("--tests")) { + i++; + while (i < args.length && !args[i].startsWith("-")) { + testNamesToRun.add(args[i]); + i++; + } + if (testNamesToRun.size() == 0) { + System.err.println("Missing test names after -t or --tests argument"); + return false; + } + // Include full details in the response, both the expected reqsponse (from file) and the actual response + } else if (args[i].equals("-v") || args[i].equals("--verbose")) { + this.verbose = true; + i++; + // Report only failures (success is silent) + } else if (args[i].equals("-f") || args[i].equals("--failures")) { + this.failuresOnly = true; + i++; + // When set, the XML must not contain extra attibutes/elements. Default is "lenient" where unexpected entries are ignored + } else if (args[i].equals("-s") || args[i].equals("--strict")) { + this.strict = true; + i++; + // (self explanatory) + } else if (args[i].equals("--stop-on-error")) { + this.stopOnFirstError = true; + i++; + } else if (args[i].equals("--lenient")) { + lenientPolicies = true; + lenientRequests = true; + i++; + } else if (args[i].equals("--lenient-policies")) { + lenientPolicies = true; + i++; + } else if (args[i].equals("--lenient-requests")) { + lenientRequests = true; + i++; + } else if (args[i].equals("--strict-policies")) { + lenientPolicies = false; + i++; + } else if (args[i].equals("--strict-requests")) { + lenientRequests = false; + i++; + } else if (args[i].equals("--iterations")) { + // this is a count of how many ADDITIONAL times the decide() should be called. + // The first time decide() is called it takes a long time to set up, + // so to get an accurate number for how fast a single Request is handled we need to ignore the time for the first run + // and timings for 1 or more non-first-time calls to decide(). + if (i+1 < args.length) { + try { + iterations = Integer.parseInt(args[i+1]); + i += 2; + } catch (NumberFormatException ex) { + System.err.println("Invalid iteration count '" + args[i+1] + "'"); + return false; + } + } else { + System.err.println("Missing argument to " + args[i] + " command line option"); + return false; + } + if (iterations < 1) { + System.err.println("Cannot use --iterations " + iterations + ". Must use an integer greater than 0"); + return false; + } + } else { + System.err.println("Unknown command line option " + args[i]); + return false; + } + } + + this.testEngine = new ConformanceTestEngine(this.getScopeResolver(), lenientRequests, lenientPolicies, iterations); + + if (testSetDirectoryNames.length() == 0) { + System.err.println("No test set directory given (need -i or --iniput command line option)"); + return false; + } + if (testSet.getListConformanceTests().size() == 0) { + System.err.println("No tests in given directories: " + testSetDirectoryNames); + } + + if (testNamesToRun.size() > 0) { + String s = ""; + for (String name : testNamesToRun) { + s += ", " + name; + } + System.out.println("Tests limited to: " + s.substring(1)); + } + + if (this.outputFile == null) { + this.outputFileWriter = new PrintWriter(System.out); + } else { + try { + this.outputFileWriter = new PrintWriter(new FileOutputStream(this.outputFile)); + } catch (IOException ex) { + System.err.println("Cannot open " + this.outputFile.getAbsolutePath() + " for writing."); + return false; + } + } + + return true; + } + + private void printHelp() { + System.out.println("usage: Conformance --input OPTIONS"); + System.out.println(""); + System.out.println(" -f, --failures Only include failed tests in the output. \n"+ + " Default is to include all test's results in the output file."); + System.out.println(""); + System.out.println(" -h, --help Prints help."); + + System.out.println(""); + System.out.println(" -i, --input Directory containing the XML Request/Response files. \n"+ + " This may be multiple space-separated directory paths. REQUIRED"); + + System.out.println(""); + System.out.println(" --iterations The number of times to run through the set of tests in the input directory."); + + System.out.println(""); + System.out.println(" --lenient Allow both Requests and Policies to have unexpected elements, no data in , etc. \n"+ + " Default is to not allow anything that is not explicitly listed in the XACML spec."); + + System.out.println(""); + System.out.println(" --lenient-policies Allow Policies to have unexpected elements, no data in , etc. \n" + + " Default is to not allow anything that is not explicitly listed in the XACML spec."); + + System.out.println(""); + System.out.println(" --lenient-requests Allow Requests to have unexpected elements, no data in , etc. \n" + + " Default is to not allow anything that is not explicitly listed in the XACML spec."); + + System.out.println(""); + System.out.println(" -o, --output Directory where the output results file will be put."); + + System.out.println(""); + System.out.println(" -s, --strict Check both the Decision and all other parts of the Response (Attributes, Obligations and Advice). \n "+ + " Default is to check just the Decision."); + + System.out.println(""); + System.out.println(" --stop-on-error Stop running conformance tests the first time one fails. Default is to continue through all tests."); + + System.out.println(""); + System.out.println(" --strict-policies Require Policies to have no unexpected elements, data in , etc. \n" + + " This is the default, but can be used to override Policies when option --lenient is used."); + + System.out.println(""); + System.out.println(" --strict-requests Require Requests to have no unexpected elements, data in , etc. \n" + + " This is the default, but can be used to override Requests when option --lenient is used."); + + System.out.println(""); + System.out.println(" -t, --tests A space-separated list of specific tests to be run. \n" + + " These are just the names of the tests as in 'IIA001 IIC178'. \n" + + " Default is to run all tests in the input directory."); + + System.out.println(""); + System.out.println(" -v, --verbose The entire expected and actual Response objects in the output. \n"+ + " Default is just a summary line."); + + } + + private boolean failed(ConformanceTestResult conformanceTestResult) { + ResponseMatchResult responseMatchResult = conformanceTestResult.getResponseMatchResult(); + if (responseMatchResult == null) { + return true; + } + if (!responseMatchResult.decisionsMatch() || !responseMatchResult.statusCodesMatch()) { + return true; + } else if (this.strict) { + if (!responseMatchResult.associatedAdviceMatches() || + !responseMatchResult.attributesMatch() || + !responseMatchResult.obligationsMatch() || + !responseMatchResult.policyIdentifiersMatch() || + !responseMatchResult.policySetIdentifiersMatch() + ) { + return true; + } + } + return false; + } + + private void dump(AttributeAssignment attributeAssignment) { + this.outputFileWriter.println("\t\t\t\tAttributeAssignment:"); + if (attributeAssignment.getCategory() != null) { + this.outputFileWriter.println("\t\t\t\t\tCategory: " + attributeAssignment.getCategory().stringValue()); + } + if (attributeAssignment.getAttributeId() != null) { + this.outputFileWriter.println("\t\t\t\t\tAttributeId: " + attributeAssignment.getAttributeId().stringValue()); + } + if (attributeAssignment.getDataTypeId() != null) { + this.outputFileWriter.println("\t\t\t\t\tDataType: " + attributeAssignment.getDataTypeId().stringValue()); + } + if (attributeAssignment.getIssuer() != null) { + this.outputFileWriter.println("\t\t\t\t\tIssuer: " + attributeAssignment.getIssuer()); + } + if (attributeAssignment.getAttributeValue() != null && attributeAssignment.getAttributeValue().getValue() != null) { + this.outputFileWriter.println("\t\t\t\t\tValue: " + attributeAssignment.getAttributeValue().getValue().toString()); + } + } + + private void dump(Attribute attribute) { + this.outputFileWriter.println("\t\t\t\t\tAttribute: " + (attribute.getAttributeId() == null ? "" : attribute.getAttributeId().stringValue())); + if (attribute.getIssuer() != null) { + this.outputFileWriter.println("\t\t\t\t\t\tIssuer: " + attribute.getIssuer()); + } + Iterator> iterAttributeValues = attribute.getValues().iterator(); + if (iterAttributeValues.hasNext()) { + this.outputFileWriter.println("\t\t\t\t\t\tValues: "); + while (iterAttributeValues.hasNext()) { + this.outputFileWriter.print("\t\t\t\t\t\t\t"); + AttributeValue attributeValue = iterAttributeValues.next(); + if (attributeValue.getDataTypeId() != null) { + this.outputFileWriter.print("DataType: " + attributeValue.getDataTypeId().stringValue() + " "); + } + if (attributeValue.getValue() != null) { + this.outputFileWriter.print("Value: " + attributeValue.getValue().toString()); + } + this.outputFileWriter.println(); + } + } + } + + private void dump(AttributeCategory attributeCategory) { + this.outputFileWriter.println("\t\t\tAttributeCategory: " + (attributeCategory.getCategory() == null ? "" : attributeCategory.getCategory().stringValue())); + Collection listAttributes = attributeCategory.getAttributes(); + if (listAttributes.size() > 0) { + this.outputFileWriter.println("\t\t\t\tAttributes:"); + for (Attribute attribute: listAttributes) { + this.dump(attribute); + } + } + } + + private void dump(Result result) { + this.outputFileWriter.println("\t\t======== Result =========="); + this.outputFileWriter.println("\t\tDecision: " + (result.getDecision() == null ? "null" : result.getDecision().name())); + if (result.getStatus() == null) { + this.outputFileWriter.println("\t\tStatus: null"); + } else { + this.outputFileWriter.println("\t\tStatus:"); + if (result.getStatus().getStatusCode() != null) { + this.outputFileWriter.println("\t\t\tStatusCode: " + result.getStatus().getStatusCode().toString()); + } + if (result.getStatus().getStatusMessage() != null) { + this.outputFileWriter.println("\t\t\tStatusMessage: " + result.getStatus().getStatusMessage()); + } + if (result.getStatus().getStatusDetail() != null) { + this.outputFileWriter.println("\t\t\tStatusDetail: " + result.getStatus().getStatusDetail().toString()); + } + } + Collection listAdvice = result.getAssociatedAdvice(); + if (listAdvice.size() > 0) { + this.outputFileWriter.println("\t\tAdvice:"); + for (Advice advice : listAdvice) { + if (advice.getId() != null) { + this.outputFileWriter.println("\t\t\tId: " + advice.getId().stringValue()); + } + Collection attributeAssignments = advice.getAttributeAssignments(); + if (attributeAssignments.size() > 0) { + this.outputFileWriter.println("\t\t\tAttributeAssignments:"); + for (AttributeAssignment attributeAssignment: attributeAssignments) { + this.dump(attributeAssignment); + } + } + } + } + Collection listObligations = result.getObligations(); + if (listObligations.size() > 0) { + for (Obligation obligation: listObligations) { + if (obligation.getId() != null) { + this.outputFileWriter.println("\t\t\tId: " + obligation.getId().stringValue()); + } + Collection attributeAssignments = obligation.getAttributeAssignments(); + if (attributeAssignments.size() > 0) { + this.outputFileWriter.println("\t\t\tAttributeAssignments:"); + for (AttributeAssignment attributeAssignment : attributeAssignments) { + this.dump(attributeAssignment); + } + } + } + } + Collection listAttributeCategories = result.getAttributes(); + if (listAttributeCategories.size() > 0) { + this.outputFileWriter.println("\t\tAttributes:"); + for (AttributeCategory attributeCategory : listAttributeCategories) { + this.dump(attributeCategory); + } + } + Collection listIdReferences; + if ((listIdReferences = result.getPolicyIdentifiers()).size() > 0) { + this.outputFileWriter.println("\t\tPolicyIds:"); + for (IdReference idReference : listIdReferences) { + this.outputFileWriter.println("\t\t\t" + idReference.toString()); + } + } + if ((listIdReferences = result.getPolicySetIdentifiers()).size() > 0) { + this.outputFileWriter.println("\t\tPolicySetIds:"); + for (IdReference idReference : listIdReferences) { + this.outputFileWriter.println("\t\t\t" + idReference.toString()); + } + } + } + + private void dump(String label, Response response) { + this.outputFileWriter.println("\t========== " + label + "=========="); + if (response == null) { + this.outputFileWriter.println("null"); + return; + } + + for (Result result : response.getResults()) { + this.dump(result); + } + } + + private void dump(ConformanceTestResult conformanceTestResult) { + + ResponseMatchResult responseMatchResult = conformanceTestResult.getResponseMatchResult(); + if (this.verbose) { + this.outputFileWriter.println("========== Test " + conformanceTestResult.getConformanceTest().getTestName() + " =========="); + this.dump("Expected Response", conformanceTestResult.getExpectedResponse()); + this.dump("Actual Response", conformanceTestResult.getActualResponse()); + if (responseMatchResult != null) { + this.outputFileWriter.println("\t========== Matching =========="); + this.outputFileWriter.println("\tDecisions Match? " + responseMatchResult.decisionsMatch()); + this.outputFileWriter.println("\tStatus Codes Match? " + responseMatchResult.statusCodesMatch()); + this.outputFileWriter.println("\tAttributes Match? " + responseMatchResult.attributesMatch()); + this.outputFileWriter.println("\tPolicyIds Match? " + responseMatchResult.policyIdentifiersMatch()); + this.outputFileWriter.println("\tPolicySetIds Match? " + responseMatchResult.policySetIdentifiersMatch()); + this.outputFileWriter.println("\tAssociated Advice Match? " + responseMatchResult.associatedAdviceMatches()); + this.outputFileWriter.println("\tObligations Match? " + responseMatchResult.obligationsMatch()); + this.outputFileWriter.println("========== End =========="); + } + } else { + String testName = conformanceTestResult.getConformanceTest().getTestName(); + if (responseMatchResult != null) { + Iterator iterResultMatches = responseMatchResult.getResultMatchResults(); + if (iterResultMatches == null || !iterResultMatches.hasNext()) { + this.outputFileWriter.println(testName); + } else { + while (iterResultMatches.hasNext()) { + ResultMatchResult resultMatchResult = iterResultMatches.next(); + this.outputFileWriter.printf("%s,%s,%s,%s,%s,%s,%s,%s,%d,%d\n", + testName, + resultMatchResult.decisionsMatch(), + resultMatchResult.statusCodesMatch(), + resultMatchResult.attributesMatch(), + resultMatchResult.policyIdentifiersMatch(), + resultMatchResult.policySetIdentifiersMatch(), + resultMatchResult.associatedAdviceMatches(), + resultMatchResult.obligationsMatch(), + conformanceTestResult.getFirstCallTime(), + conformanceTestResult.getAverageTotalLoopTime() + ); + } + } + } + } + this.outputFileWriter.flush(); + } + + private boolean run(ConformanceTest conformanceTest) throws Exception { + this.testsRun++; + ConformanceTestResult conformanceTestResult = this.testEngine.run(conformanceTest); + boolean bFailed = true; + if (conformanceTestResult != null) { + ResponseMatchResult responseMatchResult = conformanceTestResult.getResponseMatchResult(); + if (responseMatchResult != null) { + if (responseMatchResult.decisionsMatch()) { + this.decisionsMatch++; + this.statusCodesMatch += (responseMatchResult.statusCodesMatch() ? 1 : 0); + this.attributesMatch += (responseMatchResult.attributesMatch() ? 1 : 0); + this.policyIdsMatch += (responseMatchResult.policyIdentifiersMatch() ? 1 : 0); + this.policySetIdsMatch += (responseMatchResult.policySetIdentifiersMatch() ? 1 : 0); + this.associatedAdviceMatch += (responseMatchResult.associatedAdviceMatches() ? 1 : 0); + this.obligationsMatch += (responseMatchResult.obligationsMatch() ? 1 : 0); + } + this.unknownFunctions += (responseMatchResult.unknownFunction() ? 1 : 0); + bFailed = this.failed(conformanceTestResult); + if (bFailed || !this.failuresOnly) { + this.dump(conformanceTestResult); + } + } else if (conformanceTestResult.getError() != null) { + this.outputFileWriter.println(conformanceTestResult.getError()); + } + } + return (!bFailed || !this.stopOnFirstError); + } + + private void run() throws Exception { + long tStart = System.currentTimeMillis(); + + if (!this.verbose) { + this.outputFileWriter.println("Test,Decision,Status,Attributes,PolicyIds,PolicySetIds,Advice,Obligations"); + } + Iterator iterConformanceTests = this.testSet.getConformanceTests(); + boolean bContinue = true; + while (bContinue && iterConformanceTests.hasNext()) { +// bContinue = this.run(iterConformanceTests.next()); + ConformanceTest test = iterConformanceTests.next(); + if (testNamesToRun.size() > 0) { + if ( ! testNamesToRun.contains(test.getTestName())) { + continue; + } + } + bContinue = this.run(test); + } + + long tElapsed = System.currentTimeMillis() - tStart; + + if (this.verbose) { + this.outputFileWriter.println("Tests run = " + this.testsRun); + this.outputFileWriter.println("Decisions match = " + this.decisionsMatch); + this.outputFileWriter.println("Status Codes match = " + this.statusCodesMatch); + this.outputFileWriter.println("Attributes match = " + this.attributesMatch); + this.outputFileWriter.println("PolicyIds match = " + this.policyIdsMatch); + this.outputFileWriter.println("PolicySetIds match = " + this.policySetIdsMatch); + this.outputFileWriter.println("Associated Advice match = " + this.associatedAdviceMatch); + this.outputFileWriter.println("Obligations match = " + this.obligationsMatch); + this.outputFileWriter.println("Unknown functions = " + this.unknownFunctions); + } else { + this.outputFileWriter.printf("Total (%d),%d,%d,%d,%d,%d,%d,%d,%d\n", + this.testsRun, + this.decisionsMatch, + this.statusCodesMatch, + this.attributesMatch, + this.policyIdsMatch, + this.policySetIdsMatch, + this.associatedAdviceMatch, + this.obligationsMatch, + this.unknownFunctions); + } + + if (tElapsed > 0) { + long tHours = tElapsed / (60*60*1000); + tElapsed = tElapsed - tHours * 60 * 60 *1000; + long tMinutes = tElapsed / (60*1000); + tElapsed = tElapsed - tMinutes * 60 * 1000; + long tSeconds = tElapsed / 1000; + tElapsed = tElapsed - tSeconds * 1000; + + this.outputFileWriter.printf("Elapsed time = %02d:%02d:%02d.%03d\n", tHours, tMinutes, tSeconds, tElapsed); + this.outputFileWriter.printf("First decide time in nano-seconds %d\n", this.testEngine.getFirstDecideTime()); + this.outputFileWriter.printf("Total Multiple decide time in nano-seconds %d\n", this.testEngine.getDecideTimeMultiple()); + + this.outputFileWriter.printf("\nAverage First decide time in nano-seconds %d\n", this.testEngine.getAvgFirstDecideTime()); + this.outputFileWriter.printf("Average decide time after first call in nano-seconds %d\n", this.testEngine.getAvgDecideTimeMultiple()); + } + } + + public Conformance() { + } + + public static void main(String[] args) { + Conformance conformance = new Conformance(); + try { + if (conformance.init(args)) { + conformance.run(); + } + + } catch (Exception ex) { + ex.printStackTrace(System.err); + System.exit(1); + } finally { + try { + conformance.close(); + } catch (IOException ex) { + ex.printStackTrace(System.err); + } + } + System.exit(0); + } + +} diff --git a/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/conformance/ConformancePIPEngine.java b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/conformance/ConformancePIPEngine.java new file mode 100644 index 000000000..5ba399528 --- /dev/null +++ b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/conformance/ConformancePIPEngine.java @@ -0,0 +1,244 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.conformance; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStreamReader; +import java.text.ParseException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +import com.att.research.xacml.api.Attribute; +import com.att.research.xacml.api.AttributeValue; +import com.att.research.xacml.api.DataType; +import com.att.research.xacml.api.DataTypeException; +import com.att.research.xacml.api.DataTypeFactory; +import com.att.research.xacml.api.Identifier; +import com.att.research.xacml.api.pip.PIPException; +import com.att.research.xacml.api.pip.PIPFinder; +import com.att.research.xacml.api.pip.PIPRequest; +import com.att.research.xacml.api.pip.PIPResponse; +import com.att.research.xacml.std.IdentifierImpl; +import com.att.research.xacml.std.StdMutableAttribute; +import com.att.research.xacml.std.pip.StdPIPResponse; +import com.att.research.xacml.std.pip.engines.ConfigurableEngine; +import com.att.research.xacml.util.FactoryException; + +/** + * ConformancePIPEngine implements the {@link com.att.research.xacml.api.pip.PIPFinder} interface to find attributes + * loaded from a text file containing the following fields: + * category-id,attribute-id,datatype-id,issuer,value + * + * @version $Revision: 1.1 $ + */ +public class ConformancePIPEngine implements ConfigurableEngine { + public static final String PROP_DESCRIPTION = ".description"; + public static final String PROP_FILE = ".file"; + + private static final Logger logger = FlexLogger.getLogger(ConformancePIPEngine.class); + + private String name; + private String description; + private Map cache = new HashMap(); + private List listAttributes = new ArrayList(); + private DataTypeFactory dataTypeFactory; + + public ConformancePIPEngine() { + + } + + protected DataTypeFactory getDataTypeFactory() throws FactoryException { + if (this.dataTypeFactory == null) { + this.dataTypeFactory = DataTypeFactory.newInstance(); + } + return this.dataTypeFactory; + } + + protected static String generateKey(PIPRequest pipRequest) { + StringBuilder stringBuilder = new StringBuilder(pipRequest.getCategory().toString()); + stringBuilder.append('+'); + stringBuilder.append(pipRequest.getAttributeId().toString()); + stringBuilder.append('+'); + stringBuilder.append(pipRequest.getDataTypeId().toString()); + String issuer = pipRequest.getIssuer(); + if (issuer != null) { + stringBuilder.append('+'); + stringBuilder.append(issuer); + } + return stringBuilder.toString(); + } + + protected void store(String[] fields) throws FactoryException { + DataTypeFactory thisDataTypeFactory = this.getDataTypeFactory(); + Identifier identifierCategory = new IdentifierImpl(fields[0]); + Identifier identifierAttribute = new IdentifierImpl(fields[1]); + Identifier identifierDataType = new IdentifierImpl(fields[2]); + String issuer = (fields.length == 5 ? fields[3] : null); + String value = fields[fields.length - 1]; + + DataType dataType = thisDataTypeFactory.getDataType(identifierDataType); + if (dataType == null) { + logger.error("Unknown data type " + identifierDataType.stringValue()); + return; + } + + AttributeValue attributeValue = null; + try { + attributeValue = dataType.createAttributeValue(value); + } catch (DataTypeException ex) { + throw new FactoryException("DataTypeException creating AttributeValue", ex); + } + Attribute attribute = new StdMutableAttribute(identifierCategory, identifierAttribute, attributeValue, issuer, false); + this.listAttributes.add(attribute); + } + + public void loadAttributes(File fileAttributes) throws IOException, ParseException, FactoryException { + if (fileAttributes != null) { + if (!fileAttributes.exists()) { + throw new FileNotFoundException("Attributes file " + fileAttributes.getAbsolutePath() + " not found."); + } else if (!fileAttributes.canRead()) { + throw new IOException("Attributes file " + fileAttributes.getAbsolutePath() + " is not readable."); + } + + BufferedReader bufferedReader = null; + try { + bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(fileAttributes))); + String line; + while ((line = bufferedReader.readLine()) != null) { + if (line.length() > 0) { + String[] fields = line.split("[|]",-1); + if (fields.length < 4) { + logger.warn("Not enough fields in record \"" + line + "\""); + continue; + } + this.store(fields); + + } + } + } finally { + if (bufferedReader != null) { + bufferedReader.close(); + } + } + } + } + + protected Attribute findAttribute(PIPRequest pipRequest) { + Attribute attributeResult = null; + Iterator iterAttributes = this.listAttributes.iterator(); + while ((attributeResult == null) && iterAttributes.hasNext()) { + Attribute attributeTest = iterAttributes.next(); + if (pipRequest.getCategory().equals(attributeTest.getCategory()) && + pipRequest.getAttributeId().equals(attributeTest.getAttributeId()) && + (pipRequest.getIssuer() == null || pipRequest.getIssuer().equals(attributeTest.getIssuer()))) { + attributeResult = attributeTest; + } + } + return attributeResult; + } + + @Override + public PIPResponse getAttributes(PIPRequest pipRequest, PIPFinder pipFinder) throws PIPException { + String pipRequestKey = generateKey(pipRequest); + PIPResponse pipResponse = this.cache.get(pipRequestKey); + if (pipResponse != null) { + return pipResponse; + } + Attribute attributeMatch = this.findAttribute(pipRequest); + if (attributeMatch == null) { + return StdPIPResponse.PIP_RESPONSE_EMPTY; + } + /* + * Iterate through the values and only return the ones that match the requested data type + */ + List> matchingValues = new ArrayList>(); + Iterator> iterAttributeValues = attributeMatch.getValues().iterator(); + while (iterAttributeValues.hasNext()) { + AttributeValue attributeValue = iterAttributeValues.next(); + if (pipRequest.getDataTypeId().equals(attributeValue.getDataTypeId())) { + matchingValues.add(attributeValue); + } + } + if (matchingValues.size() > 0) { + Attribute attributeResponse = new StdMutableAttribute(attributeMatch.getCategory(), attributeMatch.getAttributeId(), matchingValues, attributeMatch.getIssuer(), false); + pipResponse = new StdPIPResponse(attributeResponse); + this.cache.put(pipRequestKey, pipResponse); + } + return pipResponse; + } + + @Override + public String getName() { + return this.name; + } + + @Override + public String getDescription() { + return this.description; + } + + @Override + public void configure(String id, Properties properties) throws PIPException { + this.name = id; + this.description = properties.getProperty(id + PROP_DESCRIPTION); + if (this.description == null) { + this.description = "PIPEngine for the Conformance tests that loads attributes from a CSV file"; + } + String pipFile = properties.getProperty(id + PROP_FILE); + if (pipFile != null) { + try { + this.loadAttributes(new File(pipFile)); + } catch (Exception ex) { + logger.error("Exception loading PIP file " + pipFile, ex); + throw new PIPException("Exception loading PIP file " + pipFile, ex); + } + } + } + + @Override + public Collection attributesRequired() { + return Collections.emptyList(); + } + + @Override + public Collection attributesProvided() { + // + // We could return everything in our list + // + return Collections.emptyList(); + } + +} diff --git a/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/conformance/ConformanceRepository.java b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/conformance/ConformanceRepository.java new file mode 100644 index 000000000..f58ca4e9a --- /dev/null +++ b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/conformance/ConformanceRepository.java @@ -0,0 +1,127 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.conformance; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Properties; + +import com.att.research.xacml.util.StringUtils; +import com.att.research.xacml.util.XACMLProperties; +import com.att.research.xacmlatt.pdp.std.StdPolicyFinderFactory; + +/** + * ConformanceRepository represents one or more policies for a single policy test, which will include one or more root policies, and + * zero or more referenced policies. + * + * @version $Revision$ + */ +public class ConformanceRepository { + private List rootPolicies = new ArrayList(); + private List referencedPolicies = new ArrayList(); + + private void setXACMLProperty(String propertyName, List listFiles) { + Iterator iterFiles = listFiles.iterator(); + StringBuilder stringBuilderIdList = new StringBuilder(); + while (iterFiles.hasNext()) { + File file = iterFiles.next(); + if (stringBuilderIdList.length() > 0) { + stringBuilderIdList.append(','); + } + stringBuilderIdList.append(file.getName()); + + XACMLProperties.setProperty(file.getName() + StdPolicyFinderFactory.PROP_FILE, file.getAbsolutePath()); + } + XACMLProperties.setProperty(propertyName, stringBuilderIdList.toString()); + } + + public ConformanceRepository() { + } + + public void setXACMLProperties() { + if (this.rootPolicies.size() > 0) { + this.setXACMLProperty(XACMLProperties.PROP_ROOTPOLICIES, this.rootPolicies); + } + if (this.referencedPolicies.size() > 0) { + this.setXACMLProperty(XACMLProperties.PROP_REFERENCEDPOLICIES, this.referencedPolicies); + } + } + + private void loadProperty(File fileDir, Properties properties, String propertyName, List listFiles) { + String fileNameList = properties.getProperty(propertyName); + if (fileNameList != null) { + String[] fileNameArray = fileNameList.split("[,]",0); + if (fileNameArray != null && fileNameArray.length > 0) { + for (String fileName : fileNameArray) { + File file = new File(fileDir, fileName); + if (file.exists() && file.canRead()) { + listFiles.add(file); + } + } + } + } + } + + public void load(File fileRepository) throws IOException { + Properties propertiesRepository = new Properties(); + try (InputStream is = new FileInputStream(fileRepository)) { + propertiesRepository.load(is); + } + this.loadProperty(fileRepository.getParentFile(), propertiesRepository, XACMLProperties.PROP_ROOTPOLICIES, this.rootPolicies); + this.loadProperty(fileRepository.getParentFile(), propertiesRepository, XACMLProperties.PROP_REFERENCEDPOLICIES, this.referencedPolicies); + } + + public void addRootPolicy(File filePolicy) { + this.rootPolicies.add(filePolicy); + } + + public boolean hasRootPolicy() { + return (this.rootPolicies.size() > 0); + } + + @Override + public String toString() { + StringBuilder stringBuilder = new StringBuilder("{"); + boolean needComma = false; + + if (this.rootPolicies != null && this.rootPolicies.size() > 0) { + stringBuilder.append("rootPolicies="); + stringBuilder.append(StringUtils.toString(this.rootPolicies.iterator())); + needComma = true; + } + if (this.referencedPolicies != null && this.referencedPolicies.size() > 0) { + if (needComma) { + stringBuilder.append(','); + } + stringBuilder.append("referencedPolicies="); + stringBuilder.append(StringUtils.toString(this.referencedPolicies.iterator())); + needComma = true; + } + stringBuilder.append('}'); + return stringBuilder.toString(); + } + +} diff --git a/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/conformance/ConformanceScopeResolver.java b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/conformance/ConformanceScopeResolver.java new file mode 100644 index 000000000..f9284ff84 --- /dev/null +++ b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/conformance/ConformanceScopeResolver.java @@ -0,0 +1,123 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.conformance; + +import java.net.URI; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +import com.att.research.xacml.api.Attribute; +import com.att.research.xacml.api.AttributeValue; +import com.att.research.xacml.api.pdp.ScopeQualifier; +import com.att.research.xacml.api.pdp.ScopeResolver; +import com.att.research.xacml.api.pdp.ScopeResolverException; +import com.att.research.xacml.api.pdp.ScopeResolverResult; +import com.att.research.xacml.std.StdMutableAttribute; +import com.att.research.xacml.std.StdScopeResolverResult; +import com.att.research.xacml.std.StdStatus; +import com.att.research.xacml.std.StdStatusCode; +import com.att.research.xacml.std.datatypes.DataTypes; + +/** + * ConformanceScopeResolver implements {@link com.att.research.xacml.pdp.ScopeResolver} for the conformance tests + * using a fixed set of hierarchical resources defined in a map. + * + * @version $Revision$ + */ +public class ConformanceScopeResolver implements ScopeResolver { + private Logger logger = FlexLogger.getLogger(ConformanceScopeResolver.class); + private Map> mapIdentifierToChildren = new HashMap>(); + + public ConformanceScopeResolver() { + } + + public void add(URI identifierRoot, URI identifierChild) { + List listChildrenRoot = this.mapIdentifierToChildren.get(identifierRoot); + if (listChildrenRoot == null) { + listChildrenRoot = new ArrayList(); + this.mapIdentifierToChildren.put(identifierRoot, listChildrenRoot); + } + listChildrenRoot.add(identifierChild); + } + + private void addChildren(Attribute attributeResourceId, URI urnResourceIdValue, boolean bDescendants, List listAttributes) { + List listChildren = this.mapIdentifierToChildren.get(urnResourceIdValue); + if (listChildren != null) { + for (URI uriChild : listChildren) { + AttributeValue attributeValueURI = null; + try { + attributeValueURI = DataTypes.DT_ANYURI.createAttributeValue(uriChild); + if (attributeValueURI != null) { + listAttributes.add(new StdMutableAttribute(attributeResourceId.getCategory(), attributeResourceId.getAttributeId(), attributeValueURI, attributeResourceId.getIssuer(), attributeResourceId.getIncludeInResults())); + } + } catch (Exception ex) { + this.logger.error("Exception converting URI to an AttributeValue"); + } + if (bDescendants) { + this.addChildren(attributeResourceId, uriChild, bDescendants, listAttributes); + } + } + } + } + + private void addChildren(Attribute attributeResourceId, boolean bDescendants, List listAttributes) { + /* + * Iterate over the values that are URNs + */ + Iterator> iterAttributeValueURNs = attributeResourceId.findValues(DataTypes.DT_ANYURI); + if (iterAttributeValueURNs != null) { + while (iterAttributeValueURNs.hasNext()) { + this.addChildren(attributeResourceId, iterAttributeValueURNs.next().getValue(), bDescendants, listAttributes); + } + } + } + + @Override + public ScopeResolverResult resolveScope(Attribute attributeResourceId, ScopeQualifier scopeQualifier) throws ScopeResolverException { + List listAttributes = new ArrayList(); + switch(scopeQualifier) { + case CHILDREN: + listAttributes.add(attributeResourceId); + this.addChildren(attributeResourceId, false, listAttributes); + break; + case DESCENDANTS: + listAttributes.add(attributeResourceId); + this.addChildren(attributeResourceId, true, listAttributes); + break; + case IMMEDIATE: + listAttributes.add(attributeResourceId); + break; + default: + this.logger.error("Unknown ScopeQualifier: " + scopeQualifier.name()); + return new StdScopeResolverResult(new StdStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, "Unknown ScopeQualifier " + scopeQualifier.name())); + } + return new StdScopeResolverResult(listAttributes); + } + +} diff --git a/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/conformance/ConformanceTest.java b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/conformance/ConformanceTest.java new file mode 100644 index 000000000..bb985ad7a --- /dev/null +++ b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/conformance/ConformanceTest.java @@ -0,0 +1,104 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.conformance; + +import java.io.File; + +/** + * ConformanceTest represents a collection of XACML files with a root Policy document, optional referenced Policy documents, a Request, and a Response. + * + * @version $Revision: 1.2 $ + */ +public class ConformanceTest { + private String testName; + private File request; + private File response; + private ConformanceRepository repository; + + public ConformanceTest(String name, ConformanceRepository conformanceRepository, File fileRequest, File fileResponse) { + this.testName = name; + this.request = fileRequest; + this.response = fileResponse; + this.repository = conformanceRepository; + } + + public ConformanceTest(String name) { + this.testName = name; + } + + public String getTestName() { + return this.testName; + } + public void setTestName(String s) { + this.testName = s; + } + public ConformanceRepository getRepository() { + if (this.repository == null) { + this.repository = new ConformanceRepository(); + } + return this.repository; + } + public File getRequest() { + return this.request; + } + public void setRequest(File f) { + this.request = f; + } + public File getResponse() { + return this.response; + } + public void setResponse(File f) { + this.response = f; + } + + public boolean isComplete() { + return this.getTestName() != null && this.getRepository() != null && this.getRepository().hasRootPolicy() && this.getRequest() != null && this.getResponse() != null; + } + + @Override + public String toString() { + StringBuilder stringBuilder = new StringBuilder(); + boolean needColon = false; + if (this.getTestName() != null) { + stringBuilder.append(this.getTestName()); + needColon = true; + } + if (this.getRepository() != null) { + + } + if (this.getRequest() != null) { + if (needColon) { + stringBuilder.append(':'); + } + stringBuilder.append(this.getRequest().getName()); + needColon = true; + } + if (this.getResponse() != null) { + if (needColon) { + stringBuilder.append(':'); + } + stringBuilder.append(this.getResponse().getName()); + needColon = true; + } + return stringBuilder.toString(); + } + +} diff --git a/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/conformance/ConformanceTestEngine.java b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/conformance/ConformanceTestEngine.java new file mode 100644 index 000000000..2b37cd3e7 --- /dev/null +++ b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/conformance/ConformanceTestEngine.java @@ -0,0 +1,221 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.conformance; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +import com.att.research.xacml.api.Request; +import com.att.research.xacml.api.Response; +import com.att.research.xacml.api.pdp.PDPEngine; +import com.att.research.xacml.api.pdp.PDPEngineFactory; +import com.att.research.xacml.api.pdp.ScopeResolver; +import com.att.research.xacml.std.dom.DOMProperties; +import com.att.research.xacml.std.dom.DOMRequest; +import com.att.research.xacml.std.dom.DOMResponse; +import com.att.research.xacml.util.FactoryException; + +/** + * ConformanceTestEngine handles the creation of the PDPEngine for a ConformanceTest instance. + * + * @version $Revision: 1.2 $ + */ +public class ConformanceTestEngine { + private Logger logger = FlexLogger.getLogger(ConformanceTestEngine.class); + + private PDPEngineFactory pdpEngineFactory; + private ScopeResolver scopeResolver; + private boolean lenientRequests; + private boolean lenientPolicies; + private int iterations = 1; + + // total of all first calls to decide() + private long firstDecideTime; + private int numberOfFirstDecides = 0; + + // total of all non-first-calls to decide() + private long decideTimeMultiple; + + // total of average time each test case uses for a Request + // (sum of : for each test case, average of all non-first-call calls to decide() ) + private long avgDecideTimeMultiple = 0; + + protected PDPEngineFactory getPDPEngineFactory() throws FactoryException { + if (this.pdpEngineFactory == null) { + this.pdpEngineFactory = PDPEngineFactory.newInstance(); + this.pdpEngineFactory.setScopeResolver(this.scopeResolver); + } + return this.pdpEngineFactory; + } + + public ConformanceTestEngine(ScopeResolver scopeResolverIn, boolean lenientRequestsIn, boolean lenientPoliciesIn, int iterationsIn) { + this.scopeResolver = scopeResolverIn; + this.lenientRequests = lenientRequestsIn; + this.lenientPolicies = lenientPoliciesIn; + this.iterations = iterationsIn; + } + + public ConformanceTestResult run(ConformanceTest conformanceTest) { + if (conformanceTest.getRequest() == null || conformanceTest.getResponse() == null || conformanceTest.getRepository() == null) { + logger.error("Incomplete Conformance Test: " + conformanceTest.getTestName()); + } + PDPEngineFactory thisPDPEngineFactory = null; + try { + thisPDPEngineFactory = this.getPDPEngineFactory(); + } catch (FactoryException ex) { + return new ConformanceTestResult(conformanceTest, ex); + } + + ConformanceTestResult conformanceTestResult = new ConformanceTestResult(conformanceTest, iterations); + + /* + * Load the request + */ + Request request = null; + boolean isLenient = DOMProperties.isLenient(); + try { + DOMProperties.setLenient(this.lenientRequests); + try { + request = DOMRequest.load(conformanceTest.getRequest()); + conformanceTestResult.setRequest(request); + } catch (Exception ex) { + logger.error("Exception loading Request file " + conformanceTest.getRequest().getAbsolutePath(), ex); + conformanceTestResult.setError(ex); + return conformanceTestResult; + + } + + /* + * Load the expected response + */ + Response response = null; + try { + response = DOMResponse.load(conformanceTest.getResponse()); + conformanceTestResult.setExpectedResponse(response); + } catch (Exception ex) { + logger.error("Exception loading Response file " + conformanceTest.getResponse().getAbsolutePath(), ex); + conformanceTestResult.setError(ex); + return conformanceTestResult; + } + + /* + * Set up the configuration for the policy finder + */ + conformanceTest.getRepository().setXACMLProperties(); + DOMProperties.setLenient(this.lenientPolicies); + + /* + * Create the engine + */ + PDPEngine pdpEngine = null; + try { + // pdpEngine = thisPDPEngineFactory.newEngine(conformanceTest.getRootPolicy(), conformanceTest.getReferencedPolicies(), pipFinderEngine); + pdpEngine = thisPDPEngineFactory.newEngine(); + } catch (Exception ex) { + logger.error("Exception getting PDP engine instance", ex); + conformanceTestResult.setError(ex); + return conformanceTestResult; + } + if (pdpEngine == null) { + logger.error("Null PDP engine"); + conformanceTestResult.setError(new NullPointerException("Null engine")); + return conformanceTestResult; + } + + /* + * Run the request + */ + long startTime, endTime; + long curDecideTime = this.firstDecideTime; + try { + startTime = System.nanoTime(); + response = pdpEngine.decide(request); + endTime = System.nanoTime(); +//System.out.println(endTime - startTime); + // add to total + this.firstDecideTime += endTime - startTime; + this.numberOfFirstDecides++; + // remember just this test + conformanceTestResult.setFirstCallTime(endTime - startTime); + conformanceTestResult.setActualResponse(response); + } catch (Exception ex) { + logger.error("Exception in decide", ex); + conformanceTestResult.setError(ex); + return conformanceTestResult; + } + if (response == null) { + logger.error("Null Response"); + conformanceTestResult.setError(new NullPointerException("Null Response")); + return conformanceTestResult; + } + + long localLoopTime = 0; + try { + // if user requested non-first-call calls to decide() to get performance info, run them now. + // We can ignore the result since we are only interested in how long they take to process the Request. + for (int i = 0 ; i < this.iterations ; i++) { + startTime = System.nanoTime(); + pdpEngine.decide(request); + endTime = System.nanoTime(); +//System.out.println(endTime - startTime); + // add to the global total for all tests + this.decideTimeMultiple += (endTime - startTime); + // remember just this one test's info + localLoopTime += (endTime - startTime); + } + } catch (Exception ex) { + logger.error("Exception in iterated decide", ex); + return conformanceTestResult; + } + + // add to total average for non-first-call times for all test cases + avgDecideTimeMultiple += (localLoopTime / iterations); +//System.out.println("localLoop="+localLoopTime + " it="+iterations + " avg=" + (localLoopTime / iterations) ); + // remember average time for just this test + conformanceTestResult.setAverageTotalLoopTime(localLoopTime/iterations); + + long elapsedDecideTime = this.firstDecideTime - curDecideTime; + logger.info("Decide Time: " + elapsedDecideTime + "ns"); + + return conformanceTestResult; + } finally { + DOMProperties.setLenient(isLenient); + } + } + + public long getFirstDecideTime() { + return this.firstDecideTime; + } + + public long getDecideTimeMultiple() { + return this.decideTimeMultiple; + } + + + public long getAvgFirstDecideTime() { + return this.firstDecideTime / numberOfFirstDecides; + } + public long getAvgDecideTimeMultiple() { + return this.avgDecideTimeMultiple / numberOfFirstDecides; + } +} diff --git a/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/conformance/ConformanceTestResult.java b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/conformance/ConformanceTestResult.java new file mode 100644 index 000000000..a6b789679 --- /dev/null +++ b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/conformance/ConformanceTestResult.java @@ -0,0 +1,122 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.conformance; + +import com.att.research.xacml.api.Request; +import com.att.research.xacml.api.Response; + +/** + * ConformanceTestResult holds all of the objects for a single conformance test run. + * + * @version $Revision: 1.1 $ + */ +public class ConformanceTestResult { + private ConformanceTest conformanceTest; + private Request request; + private Response expectedResponse; + private Response actualResponse; + private ResponseMatchResult responseMatchResult; + private Exception error; + + // performance timings + private long firstCallTime; + private long averageTotalLoopTime; + + // how many non-first-call times the decide() was called + private int iterations; + + public ConformanceTestResult(ConformanceTest conformanceTestIn, int iterations) { + this.conformanceTest = conformanceTestIn; + this.iterations = iterations; + } + + public ConformanceTestResult(ConformanceTest conformanceTestIn, Exception errorIn) { + this.conformanceTest = conformanceTestIn; + this.error = errorIn; + } + + public int getIterations() { + return this.iterations; + } + + public ConformanceTest getConformanceTest() { + return this.conformanceTest; + } + public void setConformanceTest(ConformanceTest conformanceTestIn) { + this.conformanceTest = conformanceTestIn; + } + + public Request getRequest() { + return this.request; + } + public void setRequest(Request requestIn) { + this.request = requestIn; + } + + public Response getExpectedResponse() { + return this.expectedResponse; + } + public void setExpectedResponse(Response response) { + this.expectedResponse = response; + this.responseMatchResult = null; + } + + public Response getActualResponse() { + return this.actualResponse; + } + public void setActualResponse(Response response) { + this.actualResponse = response; + this.responseMatchResult = null; + } + + public ResponseMatchResult getResponseMatchResult() { + if (this.responseMatchResult == null && (this.actualResponse != null && this.expectedResponse != null)) { + this.computeResponseMatchResult(); + } + return this.responseMatchResult; + } + public void computeResponseMatchResult() { + if (this.expectedResponse != null && this.actualResponse != null) { + this.responseMatchResult = ResponseMatchResult.newInstance(this.expectedResponse, this.actualResponse); + } + } + public Exception getError() { + return this.error; + } + public void setError(Exception ex) { + this.error = ex; + } + + public long getFirstCallTime() { + return firstCallTime; + } + public void setFirstCallTime(long t) { + firstCallTime = t; + } + public long getAverageTotalLoopTime(){ + return averageTotalLoopTime; + } + public void setAverageTotalLoopTime(long t) { + averageTotalLoopTime = t; + } + + +} diff --git a/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/conformance/ConformanceTestSet.java b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/conformance/ConformanceTestSet.java new file mode 100644 index 000000000..ad5b96219 --- /dev/null +++ b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/conformance/ConformanceTestSet.java @@ -0,0 +1,182 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.conformance; + +import java.io.File; +import java.io.IOException; +import java.nio.file.FileVisitResult; +import java.nio.file.FileVisitor; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +/** + * ConformanceTestSet represents a collection of ConformanceTests ordered by the test name. It has methods for + * scanning a directory to generate an ordered set. + * + * @version $Revision: 1.1 $ + */ +public class ConformanceTestSet { + private static final Logger logger = FlexLogger.getLogger(ConformanceTestSet.class); + private List listConformanceTests = new ArrayList(); + + protected List getListConformanceTests() { + return this.listConformanceTests; + } + + protected ConformanceTestSet() { + + } + + private static String getTestName(String fileName, int itemPos) { + return (itemPos == 0 ? "NULL" : fileName.substring(0, itemPos)); + } + + private static String getTestName(File file) { + String fileName = file.getName(); + int itemPos = fileName.indexOf("Policy"); + if (itemPos >= 0) { + return getTestName(fileName, itemPos); + } else if ((itemPos = fileName.indexOf("Request")) >= 0) { + return getTestName(fileName, itemPos); + } else if ((itemPos = fileName.indexOf("Response")) >= 0) { + return getTestName(fileName, itemPos); + } else if ((itemPos = fileName.indexOf("Repository")) >= 0) { + return getTestName(fileName, itemPos); + } else { + return null; + } + } + + public static ConformanceTestSet loadDirectory(File fileDir) throws IOException { + final Map mapConformanceTests = new HashMap(); + + Files.walkFileTree(fileDir.toPath(), new FileVisitor() { + @Override + public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { + logger.info("Scanning directory " + dir.getFileName()); + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + File fileVisited = file.toFile(); + String fileName = fileVisited.getName(); + if (fileName.endsWith(".xml") || fileName.endsWith(".properties")) { + String testName = getTestName(fileVisited); + if (testName != null) { + ConformanceTest conformanceTest = mapConformanceTests.get(testName); + if (conformanceTest == null) { + logger.info("Added test " + testName); + conformanceTest = new ConformanceTest(testName); + mapConformanceTests.put(testName, conformanceTest); + } + if (fileName.endsWith("Policy.xml")) { + conformanceTest.getRepository().addRootPolicy(fileVisited); + } else if (fileName.endsWith("Repository.properties")) { + conformanceTest.getRepository().load(fileVisited); + } else if (fileName.endsWith("Request.xml")) { + conformanceTest.setRequest(fileVisited); + } else if (fileName.endsWith("Response.xml")) { + conformanceTest.setResponse(fileVisited); + } + } + } + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { + logger.warn("Skipped " + file.getFileName()); + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { + return FileVisitResult.CONTINUE; + } + }); + + /* + * Sort the keyset and pull out the tests that have the required components + */ + List listTestNames = new ArrayList(); + listTestNames.addAll(mapConformanceTests.keySet()); + Collections.sort(listTestNames); + + ConformanceTestSet conformanceTestSet = new ConformanceTestSet(); + Iterator iterTestNames = listTestNames.iterator(); + while (iterTestNames.hasNext()) { + ConformanceTest conformanceTest = mapConformanceTests.get(iterTestNames.next()); + if (conformanceTest.isComplete()) { + conformanceTestSet.addConformanceTest(conformanceTest); + logger.debug("Added conformance test " + conformanceTest.getTestName()); + } else { + logger.warn("Incomplete conformance test " + conformanceTest.getTestName()); + } + } + + return conformanceTestSet; + + } + + public Iterator getConformanceTests() { + return this.listConformanceTests.iterator(); + } + + public void addConformanceTest(ConformanceTest conformanceTest) { + this.listConformanceTests.add(conformanceTest); + } + + public void addConformanceTestSet(ConformanceTestSet conformanceTestSet) { + this.listConformanceTests.addAll(conformanceTestSet.getListConformanceTests()); + } + + public static void main(String[] args) { + for (String dir : args) { + try { + ConformanceTestSet conformanceTestSet = ConformanceTestSet.loadDirectory(new File(dir)); + Iterator iterConformanceTests = conformanceTestSet.getConformanceTests(); + if (iterConformanceTests == null) { + System.out.println("No tests found in " + dir); + } else { + System.out.println("Tests found in " + dir); + while (iterConformanceTests.hasNext()) { + System.out.println(iterConformanceTests.next().toString()); + } + } + } catch (Exception ex) { + ex.printStackTrace(System.err); + } + } + } +} diff --git a/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/conformance/ResponseMatchResult.java b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/conformance/ResponseMatchResult.java new file mode 100644 index 000000000..90e4a9b34 --- /dev/null +++ b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/conformance/ResponseMatchResult.java @@ -0,0 +1,137 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.conformance; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; + +import com.att.research.xacml.api.Response; +import com.att.research.xacml.api.Result; + +/** + * ResponseMatchResult provides information about how a {@link com.att.research.xacml.api.Response} object matches + * another Response object. + * + * @version $Revision: 1.1 $ + */ +public class ResponseMatchResult { + private List resultMatchResults = new ArrayList(); + + private boolean bAssociatedAdviceMatches = true; + private boolean bAttributesMatch = true; + private boolean bDecisionsMatch = true; + private boolean bStatusCodesMatch = true; + private boolean bObligationsMatch = true; + private boolean bPolicyIdentifiersMatch = true; + private boolean bPolicySetIdentifiersMatch = true; + private boolean bNumResultsMatch = true; + private boolean bUnknownFunction; + + protected void addResultMatchResult(ResultMatchResult resultMatchResult) { + this.resultMatchResults.add(resultMatchResult); + this.bAssociatedAdviceMatches = resultMatchResult.associatedAdviceMatches() && this.bAssociatedAdviceMatches; + this.bAttributesMatch = resultMatchResult.attributesMatch() && this.bAttributesMatch; + this.bDecisionsMatch = resultMatchResult.decisionsMatch() && this.bDecisionsMatch; + this.bStatusCodesMatch = resultMatchResult.statusCodesMatch() && this.bStatusCodesMatch; + this.bObligationsMatch = resultMatchResult.obligationsMatch() && this.bObligationsMatch; + this.bPolicyIdentifiersMatch = resultMatchResult.policyIdentifiersMatch() && this.bPolicyIdentifiersMatch; + this.bPolicySetIdentifiersMatch = resultMatchResult.policySetIdentifiersMatch() && this.bPolicySetIdentifiersMatch; + this.bUnknownFunction = resultMatchResult.unknownFunction() || this.bUnknownFunction; + } + + protected void setNumResultsMatch(boolean b) { + this.bNumResultsMatch = b; + } + + public ResponseMatchResult() { + } + + public static ResponseMatchResult newInstance(Response response1, Response response2) { + ResponseMatchResult responseMatchResult = new ResponseMatchResult(); + + Collection listResultsResponse1 = response1.getResults(); + Collection listResultsResponse2 = response2.getResults(); + if (listResultsResponse1.size() == 1 && listResultsResponse2.size() == 1) { + /* + * Just add a single ResultMatchResult comparing the results in the two responses + */ + responseMatchResult.addResultMatchResult(ResultMatchResult.newInstance(listResultsResponse1.iterator().next(), listResultsResponse2.iterator().next())); + } else { + /* + * Iterate over all of the results in the two responses and match them + */ + Iterator iterResponse1Results = listResultsResponse1.iterator(); + Iterator iterResponse2Results = listResultsResponse2.iterator(); + while ((iterResponse1Results != null && iterResponse1Results.hasNext()) || (iterResponse2Results != null && iterResponse2Results.hasNext())) { + Result result1 = (iterResponse1Results != null && iterResponse1Results.hasNext() ? iterResponse1Results.next() : null); + Result result2 = (iterResponse2Results != null && iterResponse2Results.hasNext() ? iterResponse2Results.next() : null); + if ((result1 == null || result2 == null) && responseMatchResult.numResultsMatch()) { + responseMatchResult.setNumResultsMatch(false); + } + responseMatchResult.addResultMatchResult(ResultMatchResult.newInstance(result1, result2)); + } + } + return responseMatchResult; + } + + public Iterator getResultMatchResults() { + return this.resultMatchResults.iterator(); + } + + public boolean numResultsMatch() { + return this.bNumResultsMatch; + } + + public boolean associatedAdviceMatches() { + return this.bAssociatedAdviceMatches; + } + + public boolean attributesMatch() { + return this.bAttributesMatch; + } + + public boolean decisionsMatch() { + return this.bDecisionsMatch; + } + + public boolean obligationsMatch() { + return this.bObligationsMatch; + } + + public boolean policyIdentifiersMatch() { + return this.bPolicyIdentifiersMatch; + } + + public boolean policySetIdentifiersMatch() { + return this.bPolicySetIdentifiersMatch; + } + + public boolean statusCodesMatch() { + return this.bStatusCodesMatch; + } + + public boolean unknownFunction() { + return this.bUnknownFunction; + } + +} diff --git a/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/conformance/ResultMatchResult.java b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/conformance/ResultMatchResult.java new file mode 100644 index 000000000..f612c1a3c --- /dev/null +++ b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/conformance/ResultMatchResult.java @@ -0,0 +1,136 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.conformance; + +import com.att.research.xacml.api.Result; +import com.att.research.xacml.std.StdStatusCode; +import com.att.research.xacml.util.ListUtil; + +/** + * ResultMatchResult provides information about how well a {@link com.att.research.xacml.api.Result} object matches + * another Result object. + * + * @version $Revision: 1.1 $ + */ +public class ResultMatchResult { + private boolean bAssociatedAdviceMatches = true; + private boolean bAttributesMatch = true; + private boolean bDecisionsMatch = true; + private boolean bObligationsMatch = true; + private boolean bPolicyIdentifiersMatch = true; + private boolean bPolicySetIdentifiersMatch = true; + private boolean bStatusCodesMatch = true; + private boolean bUnknownFunction = false; + + protected void setAssociatedAdviceMatches(boolean b) { + this.bAssociatedAdviceMatches = b; + } + protected void setAttributesMatch(boolean b) { + this.bAttributesMatch = b; + } + protected void setDecisionsMatch(boolean b) { + this.bDecisionsMatch = b; + } + protected void setObligationsMatch(boolean b) { + this.bObligationsMatch = b; + } + protected void setPolicyIdentifiersMatch(boolean b) { + this.bPolicyIdentifiersMatch = b; + } + protected void setPolicySetIdentifiersMatch(boolean b) { + this.bPolicySetIdentifiersMatch = b; + } + protected void setStatusCodesMatch(boolean b) { + this.bStatusCodesMatch = b; + } + protected void setUnknownFunction(boolean b) { + this.bUnknownFunction = b; + } + + public ResultMatchResult() { + } + + public static ResultMatchResult newInstance(Result result1, Result result2) { + ResultMatchResult resultMatchResult = new ResultMatchResult(); + if (result2 != null && result2.getStatus() != null && + result2.getStatus().getStatusCode().equals(StdStatusCode.STATUS_CODE_PROCESSING_ERROR) && + result2.getStatus().getStatusMessage() != null && + result2.getStatus().getStatusMessage().contains("Unknown Function") + ) { + resultMatchResult.setUnknownFunction(true); + } + if (result1 == null || result2 == null) { + resultMatchResult.setAssociatedAdviceMatches(false); + resultMatchResult.setAttributesMatch(false); + resultMatchResult.setDecisionsMatch(false); + resultMatchResult.setObligationsMatch(false); + resultMatchResult.setPolicyIdentifiersMatch(false); + resultMatchResult.setPolicySetIdentifiersMatch(false); + resultMatchResult.setStatusCodesMatch(false); + } else { + resultMatchResult.setAssociatedAdviceMatches(ListUtil.equalsAllowNulls(result1.getAssociatedAdvice(), result2.getAssociatedAdvice())); + resultMatchResult.setAttributesMatch(ListUtil.equalsAllowNulls(result1.getAttributes(), result2.getAttributes())); + resultMatchResult.setDecisionsMatch(result1.getDecision() == result2.getDecision()); + resultMatchResult.setObligationsMatch(ListUtil.equalsAllowNulls(result1.getObligations(), result2.getObligations())); + resultMatchResult.setPolicyIdentifiersMatch(ListUtil.equalsAllowNulls(result1.getPolicyIdentifiers(), result2.getPolicyIdentifiers())); + resultMatchResult.setPolicySetIdentifiersMatch(ListUtil.equalsAllowNulls(result1.getPolicySetIdentifiers(), result2.getPolicySetIdentifiers())); + if (result1.getStatus() == null || result1.getStatus().getStatusCode() == null || result2.getStatus() == null || result2.getStatus().getStatusCode() == null) { + resultMatchResult.setStatusCodesMatch(false); + } else { + resultMatchResult.setStatusCodesMatch(result1.getStatus().getStatusCode().equals(result2.getStatus().getStatusCode())); + } + } + return resultMatchResult; + } + + public boolean associatedAdviceMatches() { + return this.bAssociatedAdviceMatches; + } + + public boolean attributesMatch() { + return this.bAttributesMatch; + } + + public boolean decisionsMatch() { + return this.bDecisionsMatch; + } + + public boolean obligationsMatch() { + return this.bObligationsMatch; + } + + public boolean policyIdentifiersMatch() { + return this.bPolicyIdentifiersMatch; + } + + public boolean policySetIdentifiersMatch() { + return this.bPolicySetIdentifiersMatch; + } + + public boolean statusCodesMatch() { + return this.bStatusCodesMatch; + } + + public boolean unknownFunction() { + return this.bUnknownFunction; + } + +} diff --git a/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/custom/CustomDataTypeFactory.java b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/custom/CustomDataTypeFactory.java new file mode 100644 index 000000000..a677fb849 --- /dev/null +++ b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/custom/CustomDataTypeFactory.java @@ -0,0 +1,88 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.custom; + +import java.util.HashMap; +import java.util.Map; + +import com.att.research.xacml.api.DataType; +import com.att.research.xacml.api.DataTypeFactory; +import com.att.research.xacml.api.Identifier; +import com.att.research.xacml.std.datatypes.DataTypes; + +public class CustomDataTypeFactory extends DataTypeFactory { + private static final Map> mapIdentifiersToDataTypes = new HashMap>(); + private static boolean mapNeedsInit = true; + + public static final DataTypePrivateKey DT_PRIVATEKEY = DataTypePrivateKey.newInstance(); + public static final DataTypePublicKey DT_PUBLICKEY = DataTypePublicKey.newInstance(); + + private static void registerDataType(DataType dataType) { + if (dataType != null && dataType.getId() != null) { + mapIdentifiersToDataTypes.put(dataType.getId(), dataType); + } + } + + private static void initMap() { + if (mapNeedsInit) { + synchronized(mapIdentifiersToDataTypes) { + if (mapNeedsInit) { + registerDataType(DataTypes.DT_ANYURI); + registerDataType(DataTypes.DT_BASE64BINARY); + registerDataType(DataTypes.DT_BOOLEAN); + registerDataType(DataTypes.DT_DATE); + registerDataType(DataTypes.DT_DATETIME); + registerDataType(DataTypes.DT_DAYTIMEDURATION); + registerDataType(DataTypes.DT_DNSNAME); + registerDataType(DataTypes.DT_DOUBLE); + registerDataType(DataTypes.DT_HEXBINARY); + registerDataType(DataTypes.DT_INTEGER); + registerDataType(DataTypes.DT_IPADDRESS); + registerDataType(DataTypes.DT_RFC822NAME); + registerDataType(DataTypes.DT_STRING); + registerDataType(DataTypes.DT_TIME); + registerDataType(DataTypes.DT_X500NAME); + registerDataType(DataTypes.DT_XPATHEXPRESSION); + registerDataType(DataTypes.DT_YEARMONTHDURATION); + // + // These are the custom data types! + // + registerDataType(DT_PRIVATEKEY); + registerDataType(DT_PUBLICKEY); + // + // Done + // + mapNeedsInit = false; + } + } + } + } + + public CustomDataTypeFactory() { + initMap(); + } + + @Override + public DataType getDataType(Identifier dataTypeId) { + return mapIdentifiersToDataTypes.get(dataTypeId); + } + +} diff --git a/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/custom/CustomFunctionDefinitionFactory.java b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/custom/CustomFunctionDefinitionFactory.java new file mode 100644 index 000000000..c8f9bb787 --- /dev/null +++ b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/custom/CustomFunctionDefinitionFactory.java @@ -0,0 +1,90 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.custom; + +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.security.PrivateKey; +import java.security.PublicKey; +import java.util.HashMap; +import java.util.Map; + +import com.att.research.xacml.api.Identifier; +import com.att.research.xacml.std.IdentifierImpl; +import com.att.research.xacmlatt.pdp.policy.FunctionDefinition; +import com.att.research.xacmlatt.pdp.policy.FunctionDefinitionFactory; +import com.att.research.xacmlatt.pdp.std.StdFunctions; +import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionBagOneAndOnly; + +public class CustomFunctionDefinitionFactory extends FunctionDefinitionFactory { + private static Map mapFunctionDefinitions = new HashMap(); + private static boolean needMapInit = true; + + public static final Identifier ID_FUNCTION_PRIVATEKEY_ONE_AND_ONLY = new IdentifierImpl("urn:com:att:research:xacml:custom:function:3.0:rsa:privatekey-one-and-only"); + public static final Identifier ID_FUNCTION_PUBLICKEY_ONE_AND_ONLY = new IdentifierImpl("urn:com:att:research:xacml:custom:function:3.0:rsa:publickey-one-and-only"); + + public static final FunctionDefinition FD_PRIVATEKEY_ONE_AND_ONLY = new FunctionDefinitionBagOneAndOnly(ID_FUNCTION_PRIVATEKEY_ONE_AND_ONLY, DataTypePrivateKey.newInstance()); + public static final FunctionDefinition FD_PUBLICKEY_ONE_AND_ONLY = new FunctionDefinitionBagOneAndOnly(ID_FUNCTION_PUBLICKEY_ONE_AND_ONLY, DataTypePublicKey.newInstance()); + + private static void register(FunctionDefinition functionDefinition) { + mapFunctionDefinitions.put(functionDefinition.getId(), functionDefinition); + } + + private static void initMap() { + if (needMapInit) { + synchronized(mapFunctionDefinitions) { + if (needMapInit) { + needMapInit = false; + Field[] declaredFields = StdFunctions.class.getDeclaredFields(); + for (Field field : declaredFields) { + if (Modifier.isStatic(field.getModifiers()) && + field.getName().startsWith(StdFunctions.FD_PREFIX) && + FunctionDefinition.class.isAssignableFrom(field.getType()) && + Modifier.isPublic(field.getModifiers()) + ) { + try { + register((FunctionDefinition)(field.get(null))); + } catch (IllegalAccessException ex) { + + } + } + } + // + // Our custom function + // + register(FunctionDefinitionDecrypt.newInstance()); + register(FD_PRIVATEKEY_ONE_AND_ONLY); + register(FD_PUBLICKEY_ONE_AND_ONLY); + } + } + } + } + + public CustomFunctionDefinitionFactory() { + initMap(); + } + + @Override + public FunctionDefinition getFunctionDefinition(Identifier functionId) { + return mapFunctionDefinitions.get(functionId); + } + +} diff --git a/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/custom/DataTypePrivateKey.java b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/custom/DataTypePrivateKey.java new file mode 100644 index 000000000..b161f9072 --- /dev/null +++ b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/custom/DataTypePrivateKey.java @@ -0,0 +1,54 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.custom; + +import java.security.PrivateKey; + +import com.att.research.xacml.api.DataTypeException; +import com.att.research.xacml.api.Identifier; +import com.att.research.xacml.std.IdentifierImpl; +import com.att.research.xacml.std.datatypes.DataTypeBase; + +public class DataTypePrivateKey extends DataTypeBase { + public static final Identifier DT_PRIVATEKEY = new IdentifierImpl("urn:com:att:research:xacml:custom:3.0:rsa:private"); + private static final DataTypePrivateKey singleInstance = new DataTypePrivateKey(); + + private DataTypePrivateKey() { + super(DT_PRIVATEKEY, PrivateKey.class); + } + + public static DataTypePrivateKey newInstance() { + return singleInstance; + } + + @Override + public PrivateKey convert(Object source) throws DataTypeException { + if (source == null || (source instanceof PrivateKey) ) { + return (PrivateKey) source; + } else if (source instanceof byte[]) { + return (PrivateKey) source; + } else if (source instanceof String) { + return (PrivateKey) (Object) ((String) source).getBytes(); + } + throw new DataTypeException(this, "Failed to convert \"" + source.getClass().getCanonicalName()); + } + +} diff --git a/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/custom/DataTypePublicKey.java b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/custom/DataTypePublicKey.java new file mode 100644 index 000000000..c49caa399 --- /dev/null +++ b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/custom/DataTypePublicKey.java @@ -0,0 +1,54 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.custom; + +import java.security.PublicKey; + +import com.att.research.xacml.api.DataTypeException; +import com.att.research.xacml.api.Identifier; +import com.att.research.xacml.std.IdentifierImpl; +import com.att.research.xacml.std.datatypes.DataTypeBase; + +public class DataTypePublicKey extends DataTypeBase { + public static final Identifier DT_PUBLICKEY = new IdentifierImpl("urn:com:att:research:xacml:custom:3.0:rsa:public"); + private static final DataTypePublicKey singleInstance = new DataTypePublicKey(); + + public DataTypePublicKey() { + super(DT_PUBLICKEY, PublicKey.class); + } + + public static DataTypePublicKey newInstance() { + return singleInstance; + } + + @Override + public PublicKey convert(Object source) throws DataTypeException { + if (source == null || (source instanceof PublicKey) ) { + return (PublicKey) source; + } else if (source instanceof byte[]) { + return (PublicKey) source; + } else if (source instanceof String) { + return (PublicKey) (Object) ((String) source).getBytes(); + } + throw new DataTypeException(this, "Failed to convert \"" + source.getClass().getCanonicalName()); + } + +} diff --git a/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/custom/FunctionDefinitionDecrypt.java b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/custom/FunctionDefinitionDecrypt.java new file mode 100644 index 000000000..ec7aff3b9 --- /dev/null +++ b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/custom/FunctionDefinitionDecrypt.java @@ -0,0 +1,162 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.custom; + +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; +import java.security.PrivateKey; +import java.security.PublicKey; +import java.util.List; + +import javax.crypto.BadPaddingException; +import javax.crypto.Cipher; +import javax.crypto.IllegalBlockSizeException; +import javax.crypto.NoSuchPaddingException; + +import com.att.research.xacml.api.DataType; +import com.att.research.xacml.api.DataTypeException; +import com.att.research.xacml.api.Identifier; +import com.att.research.xacml.api.XACML3; +import com.att.research.xacml.std.IdentifierImpl; +import com.att.research.xacml.std.StdStatus; +import com.att.research.xacml.std.StdStatusCode; +import com.att.research.xacml.std.datatypes.DataTypeHexBinary; +import com.att.research.xacml.std.datatypes.DataTypeString; +import com.att.research.xacml.std.datatypes.HexBinary; +import com.att.research.xacmlatt.pdp.eval.EvaluationContext; +import com.att.research.xacmlatt.pdp.policy.ExpressionResult; +import com.att.research.xacmlatt.pdp.policy.FunctionArgument; +import com.att.research.xacmlatt.pdp.policy.FunctionDefinition; +import com.att.research.xacmlatt.pdp.std.functions.ConvertedArgument; + +public class FunctionDefinitionDecrypt implements FunctionDefinition { + public static final Identifier FD_RSA_DECRYPT = new IdentifierImpl("urn:com:att:research:xacml:custom:function:3.0:rsa:decrypt"); + private static final FunctionDefinitionDecrypt singleInstance = new FunctionDefinitionDecrypt(); + + public static FunctionDefinitionDecrypt newInstance() { + return singleInstance; + } + + @Override + public Identifier getId() { + return FD_RSA_DECRYPT; + } + + @Override + public Identifier getDataTypeId() { + return XACML3.ID_DATATYPE_STRING; + } + + @Override + public boolean returnsBag() { + return false; + } + + @Override + public ExpressionResult evaluate(EvaluationContext evaluationContext, List arguments) { + if (arguments == null || arguments.size() < 2) { + return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, "Decrypt failed, expecting 2 arguments.")); + } + // + // What is the first argument? + // + FunctionArgument arg0 = arguments.get(0); + if (arg0.isBag()) { + // + // We don't support bags right now + // + return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, "Decrypt failed, not expecting a bag for argument 0.")); + } + if (arg0.getValue().getDataTypeId().equals(XACML3.ID_DATATYPE_HEXBINARY) == false) { + // + // Should be a String + // + return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, "Decrypt failed, expected a Hex Binary for argument 0.")); + } + // + // Convert the argument + // + ConvertedArgument data = new ConvertedArgument(arg0, DataTypeHexBinary.newInstance(), false); + if (! data.isOk()) { + return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, "Decrypt failed, argument 0 failed to convert to Hex Binary.")); + } + // + // Ok - check the 2nd argument + // + FunctionArgument arg1 = arguments.get(1); + if (arg1.isBag()) { + // + // We don't support bags right now + // + return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, "Decrypt failed, not expecting a bag for argument 1.")); + } + if (arg1.getValue().getDataTypeId().equals(DataTypePrivateKey.DT_PRIVATEKEY) || + arg1.getValue().getDataTypeId().equals(DataTypePublicKey.DT_PUBLICKEY)) { + // + // Ok - let's try to decrypt + // + Cipher cipher; + try { + cipher = Cipher.getInstance("RSA"); + if (arg1.getValue().getDataTypeId().equals(DataTypePrivateKey.DT_PRIVATEKEY)) { + // + // Using the private key + // + DataType pkDatatype = DataTypePrivateKey.newInstance(); + ConvertedArgument privateKey = new ConvertedArgument(arg1, pkDatatype, false); + if ( ! privateKey.isOk()) { + return ExpressionResult.newError(new StdStatus(privateKey.getStatus().getStatusCode(), "Decrypt: " + privateKey.getStatus().getStatusMessage())); + } + // + // Setup decryption + // + cipher.init(Cipher.DECRYPT_MODE, privateKey.getValue()); + } else if (arg1.getValue().getDataTypeId().equals(DataTypePublicKey.DT_PUBLICKEY)) { + // + // Using the private key + // + DataType pkDatatype = DataTypePublicKey.newInstance(); + ConvertedArgument publicKey = new ConvertedArgument(arg1, pkDatatype, false); + if ( ! publicKey.isOk()) { + return ExpressionResult.newError(new StdStatus(publicKey.getStatus().getStatusCode(), "Decrypt: " + publicKey.getStatus().getStatusMessage())); + } + // + // Setup decryption + // + cipher.init(Cipher.DECRYPT_MODE, publicKey.getValue()); + } + // + // Do the decryption + // + byte[] decryptedData = cipher.doFinal(data.getValue().getData()); + String decryptedString = new String(decryptedData); + // + // All good, return the decrypted string + // + return ExpressionResult.newSingle(DataTypeString.newInstance().createAttributeValue(decryptedString)); + } catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | IllegalBlockSizeException | BadPaddingException | DataTypeException e) { + return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, "Decrypt failed: " + e.getLocalizedMessage())); + } + } + return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, "Decrypt failed, expecting public/private key datatype for argument 1.")); + } + +} diff --git a/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/custom/TestBase.java b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/custom/TestBase.java new file mode 100644 index 000000000..089526d4e --- /dev/null +++ b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/custom/TestBase.java @@ -0,0 +1,1084 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.custom; + +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.URL; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.GnuParser; +import org.apache.commons.cli.HelpFormatter; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.ParseException; +import org.apache.commons.io.IOUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.http.entity.ContentType; + +import com.att.research.xacml.api.AttributeValue; +import com.att.research.xacml.api.DataType; +import com.att.research.xacml.api.DataTypeException; +import com.att.research.xacml.api.DataTypeFactory; +import com.att.research.xacml.api.Decision; +import com.att.research.xacml.api.Identifier; +import com.att.research.xacml.api.Request; +import com.att.research.xacml.api.RequestAttributes; +import com.att.research.xacml.api.Response; +import com.att.research.xacml.api.Result; +import com.att.research.xacml.api.pdp.PDPEngine; +import com.att.research.xacml.api.pdp.PDPEngineFactory; +import com.att.research.xacml.api.pdp.PDPException; +import com.att.research.xacml.api.pep.PEPException; +import com.att.research.xacml.std.IdentifierImpl; +import com.att.research.xacml.std.StdAttributeValue; +import com.att.research.xacml.std.StdMutableAttribute; +import com.att.research.xacml.std.StdMutableRequest; +import com.att.research.xacml.std.StdMutableRequestAttributes; +import com.att.research.xacml.std.dom.DOMRequest; +import com.att.research.xacml.std.dom.DOMResponse; +import com.att.research.xacml.std.dom.DOMStructureException; +import com.att.research.xacml.std.json.JSONRequest; +import com.att.research.xacml.std.json.JSONResponse; +import com.att.research.xacml.std.json.JSONStructureException; +import com.att.research.xacml.util.FactoryException; +import com.att.research.xacml.util.XACMLProperties; +import com.google.common.base.Splitter; +import com.google.common.collect.Lists; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +/** + * This is a base class for setting up a test environment. Using properties files, it contains the + * necessary information for + * 1. defining and providing attributes + * 2. defining and instantiating the PDP engine + * 3. creating PEP requests and calling the PDP engine + * + * + */ +public class TestBase extends SimpleFileVisitor { + private static final Logger logger = FlexLogger.getLogger(TestBase.class); + + public class HelpException extends Exception { + private static final long serialVersionUID = 1L; + + } + + /** + * This private class holds information for properties defined for attribute + * generation. The user can configure the properties file such that attributes + * can be automatically generated and added into each request. + * + * + */ + class Generator { + Path file; + InputStream is; + BufferedReader reader; + List attributes = new ArrayList(); + + public Generator(Path path) { + this.file = path; + } + + /** + * read - reads in the next line of data + * + * @return String - a line from the csv containing attribute data + */ + public String read() { + String str = null; + if (is == null) { + try { + is = Files.newInputStream(file); + } catch (IOException e) { + logger.error(e); + return null; + } + } + if (reader == null) { + reader = new BufferedReader(new InputStreamReader(this.is)); + } + try { + str = reader.readLine(); + if (str == null) { + // + // No more strings, close up + // + this.close(); + } + if (logger.isDebugEnabled()) { + logger.debug(str); + } + } catch (IOException e) { + logger.error(e); + } + return str; + } + + public void close() { + if (this.reader != null) { + try { + this.reader.close(); + } catch (IOException idontcare) { + } finally { + this.reader = null; + this.is = null; + } + } + } + + } + + public static final String PROP_GENERATOR = "xacml.attribute.generator"; + + public static final String OPTION_HELP = "help"; + public static final String OPTION_TESTDIR = "dir"; + public static final String OPTION_TESTREST = "rest"; + public static final String OPTION_TESTURL = "url"; + public static final String OPTION_TESTOUTPUT = "output"; + public static final String OPTION_LOOP = "loop"; + public static final String OPTION_TESTNUMBERS = "testNumbers"; + + public static final String DEFAULT_RESTURL = "https://localhost:8080/pdp/"; // Modified for test purpose. Port no. 8443 to 8080 + + public static Options options = new Options(); + static { + options.addOption(new Option(OPTION_HELP, false, "Prints help.")); + options.addOption(new Option(OPTION_TESTDIR, true, "Directory path where all the test properties and data are located.")); + options.addOption(new Option(OPTION_TESTREST, false, "Test against RESTful PDP.")); + options.addOption(new Option(OPTION_TESTURL, true, "URL to the RESTful PDP. Default is " + DEFAULT_RESTURL)); + options.addOption(new Option(OPTION_TESTOUTPUT, true, "Specify a different location for dumping responses.")); + options.addOption(new Option(OPTION_LOOP, true, "Number of times to loop through the tests. Default is 1. A value of -1 runs indefinitely.")); + options.addOption(new Option(OPTION_TESTNUMBERS, true, "Comma-separated list of numbers found in the names of the test files to be run. Numbers must exactly match the file name, e.g. '02'. Used to limit testing to specific set of tests.")); + } + + protected String directory = null; + protected Path output = null; + protected boolean isREST; + protected URL restURL = null; + protected int loop = 1; + protected PDPEngine engine = null; + protected List generators = new ArrayList(); + protected static DataTypeFactory dataTypeFactory = null; + + private long permits = 0; + private long denies = 0; + private long notapplicables = 0; + private long indeterminates = 0; + + private long expectedPermits = 0; + private long expectedDenies = 0; + private long expectedNotApplicables = 0; + private long expectedIndeterminates = 0; + + private long generatedpermits = 0; + private long generateddenies = 0; + private long generatednotapplicables = 0; + private long generatedindeterminates = 0; + + private long responseMatches = 0; + private long responseNotMatches = 0; + + private String[] testNumbersArray = null; + + protected final Pattern pattern = Pattern.compile("Request[.]\\d+[.](Permit|Deny|NA|Indeterminate|Generate|Unknown)\\.(json|xml)"); + + public static boolean isJSON(Path file) { + return file.toString().endsWith(".json"); + } + + public static boolean isXML(Path file) { + return file.toString().endsWith(".xml"); + } + + public TestBase(String[] args) throws ParseException, MalformedURLException, HelpException { + // + // Finish Initialization + // + this.restURL = new URL(DEFAULT_RESTURL); + // + // Parse arguments + // + this.parseCommands(args); + } + + /** + * Parse in the command line arguments that the following parameters: + * + * @param args - command line arguments + * @throws ParseException + * @throws MalformedURLException + * @throws HelpException + */ + protected void parseCommands(String[] args) throws ParseException, MalformedURLException, HelpException { + // + // Parse the command line options + // + CommandLine cl; + cl = new GnuParser().parse(options, args); + // + // Check for what we have + // + if (cl.hasOption(OPTION_HELP)) { + new HelpFormatter().printHelp("Usage: -dir testdirectory OPTIONS", + options); + throw new HelpException(); + } + if (cl.hasOption(OPTION_TESTDIR)) { + this.directory = cl.getOptionValue(OPTION_TESTDIR); + } else { + throw new IllegalArgumentException("You must specify a test directory. -dir path/to/some/where"); + } + if (cl.hasOption(OPTION_TESTREST)) { + this.isREST = true; + } else { + this.isREST = false; + } + if (cl.hasOption(OPTION_TESTURL)) { + this.restURL = new URL(cl.getOptionValue(OPTION_TESTURL)); + } + if (cl.hasOption(OPTION_TESTOUTPUT)) { + this.output = Paths.get(cl.getOptionValue(OPTION_TESTOUTPUT)); + } else { + this.output = Paths.get(this.directory, "results"); + } + if (cl.hasOption(OPTION_LOOP)) { + this.loop = Integer.parseInt(cl.getOptionValue(OPTION_LOOP)); + } + if (cl.hasOption(OPTION_TESTNUMBERS)) { + String testNumberString = cl.getOptionValue(OPTION_TESTNUMBERS); + testNumbersArray = testNumberString.split(","); + // + // reset strings to include dots so they exactly match pattern in file name + // + for (int i = 0; i < testNumbersArray.length; i++) { + testNumbersArray[i] = "." + testNumbersArray[i] + "."; + } + } + } + + /** + * Using the command line options that were parsed, configures our test instance. + * + * @throws FactoryException + */ + protected void configure() throws FactoryException { + // + // Setup the xacml.properties file + // + if (this.directory == null) { + throw new IllegalArgumentException("Must supply a path to a test directory."); + } + Path pathDir = Paths.get(this.directory, "xacml.properties"); + if (Files.notExists(pathDir)) { + throw new IllegalArgumentException(pathDir.toString() + " does not exist."); + } + // + // Set it as the System variable so the XACML factories know where the properties are + // loaded from. + // + System.setProperty(XACMLProperties.XACML_PROPERTIES_NAME, pathDir.toString()); + // + // Now we can create the data type factory + // + dataTypeFactory = DataTypeFactory.newInstance(); + // + // Load in what generators we are to create + // + String generators = XACMLProperties.getProperty(PROP_GENERATOR); + if (generators != null) { + // + // Parse the generators + // + for (String generator : Splitter.on(',').trimResults().omitEmptyStrings().split(generators)) { + this.configureGenerator(generator); + } + } + // + // If we are embedded, create our engine + // + if (this.isREST == false) { + PDPEngineFactory factory = PDPEngineFactory.newInstance(); + this.engine = factory.newEngine(); + } + // + // Remove all the responses from the results directory + // + this.removeResults(); + } + + /** + * Removes all the Response* files from the results directory. + * + */ + public void removeResults() { + try { + // + // Determine where the results are supposed to be written to + // + Path resultsPath; + if (this.output != null) { + resultsPath = this.output; + } else { + resultsPath = Paths.get(this.directory.toString(), "results"); + } + // + // Walk the files + // + Files.walkFileTree(resultsPath, new SimpleFileVisitor() { + + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + if (file.getFileName().toString().startsWith("Response")) { + Files.delete(file); + } + return super.visitFile(file, attrs); + } + }); + } catch (IOException e) { + logger.error("Failed to removeRequests from " + this.directory + " " + e); + } + } + + /** + * Configure's a specific generator instance from the properties file. + * + * @param generator + */ + protected void configureGenerator(String generator) { + String prefix = PROP_GENERATOR + "." + generator; + String file = XACMLProperties.getProperty(prefix + ".file"); + // + // Create a generator object + // + Generator gen = new Generator(Paths.get(this.directory, file)); + this.generators.add(gen); + // + // Grab attributes + // + String attributes = XACMLProperties.getProperty(prefix + ".attributes"); + for (String attribute : Splitter.on(',').trimResults().omitEmptyStrings().split(attributes)) { + String attributePrefix = prefix + ".attributes." + attribute; + // + // Create an attribute value. It is simply a placeholder for the field within + // the CSV that contains the actual attribute value. It mainly holds the data type + // + Identifier datatype = new IdentifierImpl(XACMLProperties.getProperty(attributePrefix + ".datatype")); + Integer field = Integer.parseInt(XACMLProperties.getProperty(attributePrefix + ".field")); + StdAttributeValue value = new StdAttributeValue<>(datatype, field); + // + // Get the rest of the attribute properties + // + Identifier category = new IdentifierImpl(XACMLProperties.getProperty(attributePrefix + ".category")); + Identifier id = new IdentifierImpl(XACMLProperties.getProperty(attributePrefix + ".id")); + String issuer = XACMLProperties.getProperty(attributePrefix + ".issuer"); + boolean include = Boolean.parseBoolean(XACMLProperties.getProperty(attributePrefix + ".include", "false")); + // + // Now we have a skeleton attribute + // + gen.attributes.add(new StdMutableAttribute(category, id, value, issuer, include)); + } + } + + /** + * This runs() the test instance. It first configure's itself and then walks the + * requests directory issue each request to the PDP engine. + * + * @throws IOException + * @throws FactoryException + * + */ + public void run() throws IOException, FactoryException { + // + // Configure ourselves + // + this.configure(); + // + // Loop and run + // + int runs = 1; + do { + long lTimeStart = System.currentTimeMillis(); + logger.info("Run number: " + runs); + // + // Walk the request directory + // + Files.walkFileTree(Paths.get(this.directory.toString(), "requests"), this); + long lTimeEnd = System.currentTimeMillis(); + logger.info("Run elapsed time: " + (lTimeEnd - lTimeStart) + "ms"); + // + // Dump the stats + // + this.dumpStats(); + this.resetStats(); + // + // Increment + // + runs++; + } while ((this.loop == -1 ? true : runs <= this.loop)); + } + + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + // + // Sanity check the file name + // + Matcher matcher = this.pattern.matcher(file.getFileName().toString()); + if (matcher.matches()) { + // + // if user has limited which files to use, check that here + // + if (testNumbersArray != null) { + String fileNameString = file.getFileName().toString(); + boolean found = false; + for (String numberString : testNumbersArray) { + if (fileNameString.contains(numberString)) { + found = true; + break; + } + } + if (found == false) { + // + // this test is not in the list to be run, so skip it + // + return super.visitFile(file, attrs); + } + } + try { + // + // Pull what this request is supposed to be + // + String group = null; + int count = matcher.groupCount(); + if (count >= 1) { + group = matcher.group(count-1); + } + // + // Send it + // + this.sendRequest(file, group); + } catch (Exception e) { + logger.error(e); + e.printStackTrace(); + } + } + return super.visitFile(file, attrs); + } + + /** + * When a request file is encountered, this method is called send the request to the PDP engine. It will also dump + * the response object. If the group equals "Generate", then it will loop and send the request with generated attributes + * until that list is empty. + * + * @param file - Request file. Eg. Request-01-Permit.json + * @param group - This is the parsed out string of the request file that defines if it is a Permit/Deny/Generate etc. + * @throws Exception + */ + protected void sendRequest(Path file, String group) throws Exception { + logger.info(file.toString()); + int requestCount = 0; + do { + // + // Generate the request + // + Request request = this.generateRequest(file, group); + // + // Was something generated? + // + if (request == null) { + // + // Get out of the loop + // + logger.info("NULL request generated."); + break; + } + logger.info(request); + // + // Call the PDP + // + Response response = this.callPDP(request); + // + // Process the response + // + this.processResponse(file, request, response, group, requestCount); + // + // Is this a generated request? + // + if (group.equals("Generate")) { + // + // Yes, increment counter and move + // on to the next generated request. + // + requestCount++; + } else { + // + // Nope, exit the loop + // + break; + } + } while (group.equals("Generate")); + } + + /** + * Sends the request object to the PDP engine. Either the embedded engine or the RESTful engine. + * + * @param request - XACML request object + * @return Response - returns the XACML response object + */ + protected Response callPDP(Request request) { + // + // Send it to the PDP + // + Response response = null; + if (this.isREST) { + try { + String jsonString = JSONRequest.toString(request, false); + // + // Call RESTful PDP + // + response = this.callRESTfulPDP(new ByteArrayInputStream(jsonString.getBytes())); + } catch (Exception e) { + logger.error("Error in sending RESTful request: " + e, e); + } + } else { + // + // Embedded call to PDP + // + long lTimeStart = System.currentTimeMillis(); + try { + response = this.engine.decide(request); + } catch (PDPException e) { + logger.error(e); + } + long lTimeEnd = System.currentTimeMillis(); + logger.info("Elapsed Time: " + (lTimeEnd - lTimeStart) + "ms"); + } + return response; + } + + /** + * Reads the request file into a Request object based on its type. + * + * If the request has "Generate" in its filename, then this function will add + * generated attributes into the request. + * + * @param file - Request file. Eg. Request-01-Permit.json + * @param group - This is the parsed out string of the request file that defines if it is a Permit/Deny/Generate etc. + * @return + * @throws JSONStructureException + * @throws DOMStructureException + * @throws PEPException + */ + protected Request generateRequest(Path file, String group) throws JSONStructureException, DOMStructureException, PEPException { + // + // Convert to a XACML Request Object + // + Request request = null; + if (TestBase.isJSON(file)) { + request = JSONRequest.load(file.toFile()); + } else if (TestBase.isXML(file)) { + request = DOMRequest.load(file.toFile()); + } + if (request == null) { + throw new PEPException("Invalid Request File: " + file.toString()); + } + // + // Only if this request has "Generate" + // Request.XX.Generate.[json|xml] + // + if (group.equals("Generate")) { + // + // Add attributes to it + // + request = this.onNextRequest(request); + } + // + // Done + // + return request; + } + + /** + * Called to add in generated attributes into the request. + * + * @param request + * @return + */ + protected Request onNextRequest(Request request) { + // + // If we have no generators, just return + // + if (this.generators.isEmpty()) { + return request; + } + // + // Copy the request attributes + // + List attributes = new ArrayList(); + for (RequestAttributes a : request.getRequestAttributes()) { + attributes.add(new StdMutableRequestAttributes(a)); + } + // + // Iterate the generators + // + for (Generator generator : this.generators) { + // + // Read a row in + // + String line = generator.read(); + // + // Was something read? + // + if (line == null) { + // + // No more rows to read, return null + // + return null; + } + // + // Split the line + // + List fields = Lists.newArrayList(Splitter.on(',').trimResults().split(line)); + // + // Now work on the attributes + // + for (StdMutableAttribute attribute : generator.attributes) { + // + // Grab the attribute holder, which holds the datatype and field. There should + // be only ONE object in the collection. + // + AttributeValue value = attribute.getValues().iterator().next(); + Integer field = (Integer) value.getValue(); + // + // Is the field number valid? + // + if (field >= fields.size()) { + logger.error("Not enough fields: " + field + "(" + fields.size() + ")"); + return null; + } + // + // Determine what datatype it is + // + DataType dataTypeExtended = dataTypeFactory.getDataType(value.getDataTypeId()); + if (dataTypeExtended == null) { + logger.error("Failed to determine datatype"); + return null; + } + // + // Create the attribute value + // + try { + AttributeValue attributeValue = dataTypeExtended.createAttributeValue(fields.get(field)); + // + // Create the attribute + // + StdMutableAttribute newAttribute = new StdMutableAttribute(attribute.getCategory(), + attribute.getAttributeId(), + attributeValue, + attribute.getIssuer(), + attribute.getIncludeInResults()); + boolean added = false; + for (StdMutableRequestAttributes a : attributes) { + // + // Does the category exist? + // + if (a.getCategory().equals(attribute.getCategory())) { + // + // Yes - add in the new attribute value + // + a.add(newAttribute); + added = true; + break; + } + } + if (added == false) { + // + // New category - create it and add it in + // + StdMutableRequestAttributes a = new StdMutableRequestAttributes(); + a.setCategory(newAttribute.getCategory()); + a.add(newAttribute); + attributes.add(a); + } + } catch (DataTypeException e) { + logger.error(e); + return null; + } + } + } + // + // Now form our final request + // + StdMutableRequest newRequest = new StdMutableRequest(); + newRequest.setCombinedDecision(request.getCombinedDecision()); + newRequest.setRequestDefaults(request.getRequestDefaults()); + newRequest.setReturnPolicyIdList(request.getReturnPolicyIdList()); + newRequest.setStatus(request.getStatus()); + for (StdMutableRequestAttributes a : attributes) { + newRequest.add(a); + } + return newRequest; + } + + /** + * This makes an HTTP POST call to a running PDP RESTful servlet to get a decision. + * + * @param file + * @return + */ + protected Response callRESTfulPDP(InputStream is) { + Response response = null; + HttpURLConnection connection = null; + try { + + // + // Open up the connection + // + connection = (HttpURLConnection) this.restURL.openConnection(); + connection.setRequestProperty("Content-Type", "application/json"); + // + // Setup our method and headers + // + connection.setRequestMethod("POST"); + connection.setUseCaches(false); + // + // Adding this in. It seems the HttpUrlConnection class does NOT + // properly forward our headers for POST re-direction. It does so + // for a GET re-direction. + // + // So we need to handle this ourselves. + // + connection.setInstanceFollowRedirects(false); + connection.setDoOutput(true); + connection.setDoInput(true); + // + // Send the request + // + try (OutputStream os = connection.getOutputStream()) { + IOUtils.copy(is, os); + } + // + // Do the connect + // + connection.connect(); + if (connection.getResponseCode() == 200) { + // + // Read the response + // + ContentType contentType = null; + try { + contentType = ContentType.parse(connection.getContentType()); + + if (contentType.getMimeType().equalsIgnoreCase(ContentType.APPLICATION_JSON.getMimeType())) { + response = JSONResponse.load(connection.getInputStream()); + } else if (contentType.getMimeType().equalsIgnoreCase(ContentType.APPLICATION_XML.getMimeType()) || + contentType.getMimeType().equalsIgnoreCase("application/xacml+xml") ) { + response = DOMResponse.load(connection.getInputStream()); + } else { + logger.error("unknown content-type: " + contentType); + } + + } catch (Exception e) { + String message = "Parsing Content-Type: " + connection.getContentType() + ", error=" + e.getMessage(); + logger.error(message, e); + } + + } else { + logger.error(connection.getResponseCode() + " " + connection.getResponseMessage()); + } + } catch (Exception e) { + logger.error(e); + } + + return response; + } + + /** + * This processes a response. Saves the response out to disk. If there is a corresponding response file for the request located + * in the "responses" sub-directory, then this method will compare that response file with what the engine returned to see if it + * matched. + * + * @param requestFile + * @param request + * @param response + * @param group + * @param count + * @throws Exception + */ + protected void processResponse(Path requestFile, Request request, Response response, String group, int count) throws Exception { + // + // Construct the output filename + // + Path responseFile = null; + Path resultFile = null; + int num = requestFile.getNameCount(); + if (num < 2) { + logger.error("Too few dir's in request filename."); + throw new Exception("Too few dir's in request filename. Format should be Request.[0-9]+.{Permit|Deny|NA|Indeterminate}.{json|xml}"); + } + String filename = requestFile.getFileName().toString(); + if (group.equals("Generate")) { + // + // Using count variable, construct a filename + // + // i.e. Response.03.Generate.{count}.json + // + filename = "Response" + filename.substring(filename.indexOf('.'), filename.lastIndexOf('.')) + String.format("%03d", count) + filename.substring(filename.lastIndexOf('.')); + } else { + // + // Construct filename + // + filename = "Response" + filename.substring(filename.indexOf('.')); + } + // + // Determine equivalent response file path + // + responseFile = Paths.get(requestFile.subpath(0, num - 2).toString(), "responses"); + if (Files.notExists(responseFile)) { + // + // Create it + // + logger.warn(responseFile.toString() + " does NOT exist, creating..."); + try { + Files.createDirectories(responseFile); + } catch (IOException e) { + logger.error(e); + throw new Exception("Cannot proceed without an output directory."); + } + } + responseFile = Paths.get(responseFile.toString(), filename); + // + // Determine path to write result file + // + if (this.output != null) { + // + // User specified an output path + // + resultFile = this.output; + } else { + // + // Default path + // + resultFile = Paths.get(requestFile.subpath(0, num - 2).toString(), "results"); + } + // + // Check if the path exists + // + if (Files.notExists(resultFile)) { + // + // Create it + // + logger.warn(resultFile.toString() + " does NOT exist, creating..."); + try { + Files.createDirectories(resultFile); + } catch (IOException e) { + logger.error(e); + throw new Exception("Cannot proceed without an output directory."); + } + } + // + // Add the filename to the path + // + resultFile = Paths.get(resultFile.toString(), filename); + // + // Check if there is an equivalent response in the response + // directory. If so, compare our response result with that one. + // + boolean succeeded = true; + if (responseFile != null && Files.exists(responseFile)) { + // + // Do comparison + // + Response expectedResponse = null; + if (TestBase.isJSON(responseFile)) { + expectedResponse = JSONResponse.load(responseFile); + } else if (TestBase.isXML(responseFile)) { + expectedResponse = DOMResponse.load(responseFile); + } + if (expectedResponse != null) { + // + // Do the compare + // + if (response == null) { + logger.error("NULL response returned."); + this.responseNotMatches++; + succeeded = false; + } else { + if (response.equals(expectedResponse)) { + logger.info("Response matches expected response."); + this.responseMatches++; + } else { + logger.error("Response does not match expected response."); + logger.error("Expected: "); + logger.error(expectedResponse.toString()); + this.responseNotMatches++; + succeeded = false; + } + } + } + } + // + // Write the response to the result file + // + logger.info("Request: " + requestFile.getFileName() + " response is: " + (response == null ? "null" : response.toString())); + if (resultFile != null && response != null) { + if (TestBase.isJSON(resultFile)) { + Files.write(resultFile, JSONResponse.toString(response, true).getBytes()); + } else if (TestBase.isXML(resultFile)) { + Files.write(resultFile, DOMResponse.toString(response, true).getBytes()); + } + } + // + // Stats + // + if (group.equals("Permit")) { + this.expectedPermits++; + } else if (group.equals("Deny")) { + this.expectedDenies++; + } else if (group.equals("NA")) { + this.expectedNotApplicables++; + } else if (group.equals("Indeterminate")) { + this.expectedIndeterminates++; + } + if (response != null) { + for (Result result : response.getResults()) { + Decision decision = result.getDecision(); + if (group.equals("Generate")) { + if (decision.equals(Decision.PERMIT)) { + this.generatedpermits++; + } else if (decision.equals(Decision.DENY)) { + this.generateddenies++; + } else if (decision.equals(Decision.NOTAPPLICABLE)) { + this.generatednotapplicables++; + } else if (decision.equals(Decision.INDETERMINATE)) { + this.generatedindeterminates++; + } + continue; + } + if (decision.equals(Decision.PERMIT)) { + this.permits++; + if (group.equals("Permit") == false) { + succeeded = false; + logger.error("Expected " + group + " got " + decision); + } + } else if (decision.equals(Decision.DENY)) { + this.denies++; + if (group.equals("Deny") == false) { + succeeded = false; + logger.error("Expected " + group + " got " + decision); + } + } else if (decision.equals(Decision.NOTAPPLICABLE)) { + this.notapplicables++; + if (group.equals("NA") == false) { + succeeded = false; + logger.error("Expected " + group + " got " + decision); + } + } else if (decision.equals(Decision.INDETERMINATE)) { + this.indeterminates++; + if (group.equals("Indeterminate") == false) { + succeeded = false; + logger.error("Expected " + group + " got " + decision); + } + } + } + } + if (succeeded) { + logger.info("REQUEST SUCCEEDED"); + } else { + logger.info("REQUEST FAILED"); + } + } + + protected void dumpStats() { + StringBuilder dump = new StringBuilder(); + dump.append(System.lineSeparator()); + dump.append("Permits: " + this.permits + " Expected: " + this.expectedPermits); + dump.append(System.lineSeparator()); + dump.append("Denies: " + this.denies + " Expected: " + this.expectedDenies); + dump.append(System.lineSeparator()); + dump.append("NA: " + this.notapplicables + " Expected: " + this.expectedNotApplicables); + dump.append(System.lineSeparator()); + dump.append("Indeterminates: " + this.indeterminates + " Expected: " + this.expectedIndeterminates); + dump.append(System.lineSeparator()); + dump.append("Generated Permits: " + this.generatedpermits); + dump.append(System.lineSeparator()); + dump.append("Generated Denies: " + this.generateddenies); + dump.append(System.lineSeparator()); + dump.append("Generated NA: " + this.generatednotapplicables); + dump.append(System.lineSeparator()); + dump.append("Generated Indeterminates: " + this.generatedindeterminates); + dump.append(System.lineSeparator()); + dump.append("Responses Matched: " + this.responseMatches); + dump.append(System.lineSeparator()); + dump.append("Responses NOT Matched: " + this.responseNotMatches); + + if (this.permits != this.expectedPermits || + this.denies != this.expectedDenies || + this.notapplicables != this.expectedNotApplicables || + this.indeterminates != this.expectedIndeterminates || + this.responseNotMatches > 0) { + logger.error(dump.toString()); + } else { + logger.info(dump.toString()); + } + } + + protected void resetStats() { + this.permits = 0; + this.denies = 0; + this.notapplicables = 0; + this.indeterminates = 0; + this.generatedpermits = 0; + this.generateddenies = 0; + this.generatednotapplicables = 0; + this.generatedindeterminates = 0; + this.responseMatches = 0; + this.responseNotMatches = 0; + } + + public static void main(String[] args) { + try { + new TestBase(args).run(); + } catch (ParseException | IOException | FactoryException e) { + logger.error(e); + } catch (HelpException e) { + } + } +} diff --git a/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/custom/TestCustom.java b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/custom/TestCustom.java new file mode 100644 index 000000000..e6530a186 --- /dev/null +++ b/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/custom/TestCustom.java @@ -0,0 +1,394 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PDP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.custom; + +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.net.MalformedURLException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.security.InvalidKeyException; +import java.security.KeyPair; +import java.security.KeyPairGenerator; +import java.security.NoSuchAlgorithmException; +import java.security.PrivateKey; +import java.security.PublicKey; +import java.util.ArrayList; +import java.util.List; + +import javax.crypto.BadPaddingException; +import javax.crypto.Cipher; +import javax.crypto.IllegalBlockSizeException; +import javax.crypto.NoSuchPaddingException; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.GnuParser; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.ParseException; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +import com.att.research.xacml.api.AttributeValue; +import com.att.research.xacml.api.DataType; +import com.att.research.xacml.api.DataTypeException; +import com.att.research.xacml.api.Request; +import com.att.research.xacml.api.RequestAttributes; +import com.att.research.xacml.api.XACML3; +import com.att.research.xacml.api.pep.PEPException; +import com.att.research.xacml.std.IdentifierImpl; +import com.att.research.xacml.std.StdMutableAttribute; +import com.att.research.xacml.std.StdMutableRequest; +import com.att.research.xacml.std.StdMutableRequestAttributes; +import com.att.research.xacml.std.dom.DOMStructureException; +import com.att.research.xacml.std.json.JSONStructureException; +import com.att.research.xacml.util.FactoryException; + +/** + * TestCustom is an application that tests the extensibility and configurability of the AT&T XACML API. + * + * It creates a custom datatype definition factory that adds in custom data types for RSA + * PublicKey and PrivateKey. + * + * It creates a custom function definition factory that adds in custom decryption function for decrypting data. It + * also derives and loads custom functions for the RSA public/private key datatypes for the bag function: one-and-only. + * + * + */ +public class TestCustom extends TestBase { + private static final Logger logger = FlexLogger.getLogger(TestCustom.class); + + // + // Our public's + // + public static final String ALGORITHM = "RSA"; + public static final String PRIVATEKEY_FILE = "PrivateKey.key"; + public static final String PUBLICKEY_FILE = "PublicKey.key"; + + public static final String DECRYPTION_INPUT_STRING = "This is the SECRET value!"; + + public static final String DECRYPTION_INPUT_ID = "com:att:research:xacml:test:custom:encrypted-data"; + // + // Our keys + // + protected PublicKey publicKey = null; + protected PrivateKey privateKey = null; + // + // Our command line parameters + // + public static final String OPTION_GENERATE = "generate"; + + static { + options.addOption(new Option(OPTION_GENERATE, false, "Generate a private/public key pair.")); + } + + /** + * This function generates the public/private key pair. Should never have to call this again, this was + * called once to generate the keys. They were saved into the testsets/custom/datatype-function sub-directory. + */ + public void generateKeyPair() { + // + // Generate a RSA private/public key pair + // + KeyPairGenerator keyGen; + try { + keyGen = KeyPairGenerator.getInstance(ALGORITHM); + } catch (NoSuchAlgorithmException e) { + logger.error("failed to generate keypair: " + e); + return; + } + keyGen.initialize(1024); + final KeyPair key = keyGen.generateKeyPair(); + // + // Save the keys to disk + // + Path file = Paths.get(this.directory, PRIVATEKEY_FILE); + try (ObjectOutputStream os = new ObjectOutputStream(Files.newOutputStream(file))) { + os.writeObject(key.getPrivate()); + } catch (IOException e) { + e.printStackTrace(); + } + file = Paths.get(this.directory, PUBLICKEY_FILE); + try (ObjectOutputStream os = new ObjectOutputStream(Files.newOutputStream(file))) { + os.writeObject(key.getPublic()); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public TestCustom(String[] args) throws ParseException, MalformedURLException, HelpException { + super(args); + } + + /* (non-Javadoc) + * + * Simply look for command line option: -generate + * This generates the public/private key. Shouldn't need to call it again, the keys have + * already been generated and saved. + * + * @see org.openecomp.policy.pdp.test.TestBase#parseCommands(java.lang.String[]) + */ + @Override + protected void parseCommands(String[] args) throws ParseException, MalformedURLException, HelpException { + // + // Have our parent class parse its options out + // + super.parseCommands(args); + // + // Parse the command line options + // + CommandLine cl; + cl = new GnuParser().parse(options, args); + if (cl.hasOption(OPTION_GENERATE)) { + // + // Really only need to do this once to setup the test. + // + this.generateKeyPair(); + } + } + + /* (non-Javadoc) + * + * After our parent class configure's itself, all this needs to do is read in + * the public/private key's into objects. + * + * @see org.openecomp.policy.pdp.test.TestBase#configure() + */ + @Override + protected void configure() throws FactoryException { + // + // Have our super do its thing + // + super.configure(); + // + // Read in the public key + // + try { + this.publicKey = (PublicKey) new ObjectInputStream(Files.newInputStream(Paths.get(this.directory, PUBLICKEY_FILE))).readObject(); + } catch (ClassNotFoundException | IOException e) { + logger.error(e); + } + // + // Read in the private key + // + try { + this.privateKey = (PrivateKey) new ObjectInputStream(Files.newInputStream(Paths.get(this.directory, PRIVATEKEY_FILE))).readObject(); + } catch (ClassNotFoundException | IOException e) { + logger.error(e); + } + } + + /* (non-Javadoc) + * + * Here we add 2 attributes into the request: 1) the private key, and 2) a String that was encrypted using the public key. + * + * The goal is to have the custom decrypt function use the private key to decrypt that string. + * + * @see org.openecomp.policy.pdp.test.TestBase#generateRequest(java.nio.file.Path, java.lang.String) + */ + @Override + protected Request generateRequest(Path file, String group) throws JSONStructureException, DOMStructureException, PEPException { + // + // Have our super class do its work + // + Request oldRequest = super.generateRequest(file, group); + // + // Copy the request attributes + // + List attributes = new ArrayList(); + for (RequestAttributes a : oldRequest.getRequestAttributes()) { + attributes.add(new StdMutableRequestAttributes(a)); + } + // + // We are supplying the private key as an attribute for the decryption function to use: + // + // (NOTE: Ideally this would be provided by a custom PIP provider, not the PEP) + // + // ID=com:att:research:xacml:test:custom:privatekey + // Issuer=com:att:research:xacml:test:custom + // Category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject + // Datatype=urn:com:att:research:xacml:custom:3.0:rsa:private + // + DataType dtExtended = dataTypeFactory.getDataType(DataTypePrivateKey.DT_PRIVATEKEY); + if (dtExtended == null) { + logger.error("Failed to get private key datatype."); + return null; + } + // + // Create the attribute value + // + try { + AttributeValue attributeValue = dtExtended.createAttributeValue(this.privateKey); + // + // Create the attribute + // + StdMutableAttribute newAttribute = new StdMutableAttribute(XACML3.ID_SUBJECT_CATEGORY_ACCESS_SUBJECT, + new IdentifierImpl("com:att:research:xacml:test:custom:privatekey"), + attributeValue, + "com:att:research:xacml:test:custom", + false); + boolean added = false; + for (StdMutableRequestAttributes a : attributes) { + // + // Does the category exist? + // + if (a.getCategory().equals(XACML3.ID_SUBJECT_CATEGORY_ACCESS_SUBJECT)) { + // + // Yes - add in the new attribute value + // + a.add(newAttribute); + added = true; + break; + } + } + if (added == false) { + // + // New category - create it and add it in + // + StdMutableRequestAttributes a = new StdMutableRequestAttributes(); + a.setCategory(newAttribute.getCategory()); + a.add(newAttribute); + attributes.add(a); + } + } catch (DataTypeException e) { + logger.error(e); + return null; + } + // + // We are also supplying this attribute which is the secret text encrypted with + // the public key. + // + // ID=com:att:research:xacml:test:custom:encrypted-data + // Issuer= + // Category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject + // Datatype=http://www.w3.org/2001/XMLSchema#hexBinary + // + // Encrypt it + // + byte[] encryptedData = null; + try { + Cipher cipher = Cipher.getInstance(ALGORITHM); + cipher.init(Cipher.ENCRYPT_MODE, this.publicKey); + // + // This is just a hack to test a decryption of the wrong value. + // + if (group.equals("Permit")) { + encryptedData = cipher.doFinal(DECRYPTION_INPUT_STRING.getBytes()); + } else { + encryptedData = cipher.doFinal("This is NOT the secret".getBytes()); + } + } catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | IllegalBlockSizeException | BadPaddingException e) { + logger.error(e); + return null; + } + // + // Sanity check (for the Permit request) + // + try { + if (group.equals("Permit")) { + Cipher cipher = Cipher.getInstance(ALGORITHM); + cipher.init(Cipher.DECRYPT_MODE, this.privateKey); + byte[] decryptedData = cipher.doFinal(encryptedData); + if (new String(decryptedData).equals(DECRYPTION_INPUT_STRING)) { + logger.info("Sanity check passed: decrypted the encrypted data."); + } else { + logger.error("Sanity check failed to decrypt the encrypted data."); + return null; + } + } + } catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | IllegalBlockSizeException | BadPaddingException e) { + logger.error(e); + } + // + // Get our datatype factory + // + dtExtended = dataTypeFactory.getDataType(XACML3.ID_DATATYPE_HEXBINARY); + if (dtExtended == null) { + logger.error("Failed to get hex binary datatype."); + return null; + } + // + // Create the attribute value + // + try { + AttributeValue attributeValue = dtExtended.createAttributeValue(encryptedData); + // + // Create the attribute + // + StdMutableAttribute newAttribute = new StdMutableAttribute(XACML3.ID_SUBJECT_CATEGORY_ACCESS_SUBJECT, + new IdentifierImpl("com:att:research:xacml:test:custom:encrypted-data"), + attributeValue, + null, + false); + boolean added = false; + for (StdMutableRequestAttributes a : attributes) { + // + // Does the category exist? + // + if (a.getCategory().equals(XACML3.ID_SUBJECT_CATEGORY_ACCESS_SUBJECT)) { + // + // Yes - add in the new attribute value + // + a.add(newAttribute); + added = true; + break; + } + } + if (added == false) { + // + // New category - create it and add it in + // + StdMutableRequestAttributes a = new StdMutableRequestAttributes(); + a.setCategory(newAttribute.getCategory()); + a.add(newAttribute); + attributes.add(a); + } + } catch (DataTypeException e) { + logger.error(e); + return null; + } + // + // Now form our final request + // + StdMutableRequest newRequest = new StdMutableRequest(); + newRequest.setCombinedDecision(oldRequest.getCombinedDecision()); + newRequest.setRequestDefaults(oldRequest.getRequestDefaults()); + newRequest.setReturnPolicyIdList(oldRequest.getReturnPolicyIdList()); + newRequest.setStatus(oldRequest.getStatus()); + for (StdMutableRequestAttributes a : attributes) { + newRequest.add(a); + } + return newRequest; + } + + public static void main(String[] args) { + try { + new TestCustom(args).run(); + } catch (ParseException | IOException | FactoryException e) { + logger.error(e); + } catch (HelpException e) { + } + } + +} diff --git a/ECOMP-PDP/src/test/resources/log4j.properties b/ECOMP-PDP/src/test/resources/log4j.properties new file mode 100644 index 000000000..d3d3f48b6 --- /dev/null +++ b/ECOMP-PDP/src/test/resources/log4j.properties @@ -0,0 +1,42 @@ +### +# ============LICENSE_START======================================================= +# ECOMP-PDP +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +# +# Use this properties for debugging and development. +# +# +# Set root logger level to DEBUG and its only appender to A1. +log4j.rootLogger=INFO, MAIN_LOG + +# A1 is set to be a ConsoleAppender. +log4j.appender.MAIN_LOG=org.apache.log4j.ConsoleAppender + +# A1 uses PatternLayout. +log4j.appender.MAIN_LOG.layout=org.apache.log4j.PatternLayout +log4j.appender.MAIN_LOG.layout.ConversionPattern=%d{yyyy_MM_dd_HH_mm_ss_SSS} [%t] %-5p %l- %m%n + +# +# This is specifically for Xacml request/response logging +# +log4j.logger.xacml.request=INFO, REQUEST_LOG + +log4j.appender.REQUEST_LOG=org.apache.log4j.ConsoleAppender +log4j.appender.REQUEST_LOG.layout=org.apache.log4j.PatternLayout +log4j.appender.REQUEST_LOG.layout.ConversionPattern=%d{yyyy_MM_dd_HH_mm_ss_SSS} %m%n diff --git a/ECOMP-PDP/src/test/resources/logback.xml b/ECOMP-PDP/src/test/resources/logback.xml new file mode 100644 index 000000000..3cb7a4469 --- /dev/null +++ b/ECOMP-PDP/src/test/resources/logback.xml @@ -0,0 +1,252 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --> + + + + + + + + + + + + + + + + + + + + ${defaultPattern} + + + + + + + + + + + + + ${logDirectory}/${auditLogName}.log + + ${logDirectory}/${auditLogName}.%i.log.zip + + 1 + 9 + + + 5MB + + + ${defaultAuditPattern} + + + + + 256 + + + + + + + + ${logDirectory}/${metricsLogName}.log + + ${logDirectory}/${metricsLogName}.%i.log.zip + + 1 + 9 + + + 5MB + + + + ${defaultMetricPattern} + + + + + 256 + + + + + + + + ${logDirectory}/${errorLogName}.log + + ${logDirectory}/${errorLogName}.%i.log.zip + + 1 + 9 + + + ERROR + + + 5MB + + + ${defaultErrorPattern} + + + + + 256 + + + + + + + ${debugLogDirectory}/${debugLogName}.log + + ${debugLogDirectory}/${debugLogName}.%i.log.zip + + 1 + 9 + + + INFO + + + 5MB + + + ${debugLoggerPattern} + + + + + 256 + + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ECOMP-PDP/src/test/resources/logging.properties b/ECOMP-PDP/src/test/resources/logging.properties new file mode 100644 index 000000000..cd4ad799f --- /dev/null +++ b/ECOMP-PDP/src/test/resources/logging.properties @@ -0,0 +1,32 @@ +### +# ============LICENSE_START======================================================= +# ECOMP-PDP +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +handlers = java.util.logging.ConsoleHandler, java.util.logging.FileHandler + +.level = FINE + +java.util.logging.SimpleFormatter.format=%4$s: %5$s %n + +java.util.logging.ConsoleHandler.level = FINEST +java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter + +java.util.logging.FileHandler.level = SEVERE +java.util.logging.FileHandler.pattern=%h/xacml_log%u.log +java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter diff --git a/ECOMP-PDP/src/test/resources/xacml.pip.properties b/ECOMP-PDP/src/test/resources/xacml.pip.properties new file mode 100644 index 000000000..739504faf --- /dev/null +++ b/ECOMP-PDP/src/test/resources/xacml.pip.properties @@ -0,0 +1,23 @@ +### +# ============LICENSE_START======================================================= +# ECOMP-PDP +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +# +#Fri Mar 06 12:06:30 EST 2015 +xacml.pip.engines= diff --git a/ECOMP-PDP/src/test/resources/xacml.policy.properties b/ECOMP-PDP/src/test/resources/xacml.policy.properties new file mode 100644 index 000000000..889a63ad3 --- /dev/null +++ b/ECOMP-PDP/src/test/resources/xacml.policy.properties @@ -0,0 +1,25 @@ +### +# ============LICENSE_START======================================================= +# ECOMP-PDP +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +# +#Fri Mar 06 12:06:30 EST 2015 +xacml.referencedPolicies= +xacml.rootPolicies= + diff --git a/ECOMP-PDP/testclient.properties b/ECOMP-PDP/testclient.properties new file mode 100644 index 000000000..8e16d2397 --- /dev/null +++ b/ECOMP-PDP/testclient.properties @@ -0,0 +1,21 @@ +### +# ============LICENSE_START======================================================= +# ECOMP-PDP +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +test=test,MASTER diff --git a/ECOMP-PDP/testpdp.properties b/ECOMP-PDP/testpdp.properties new file mode 100644 index 000000000..6ae5501d3 --- /dev/null +++ b/ECOMP-PDP/testpdp.properties @@ -0,0 +1,21 @@ +### +# ============LICENSE_START======================================================= +# ECOMP-PDP +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +PDP_URL= , test, test diff --git a/ECOMP-PDP/xacml.pap.properties b/ECOMP-PDP/xacml.pap.properties new file mode 100644 index 000000000..13aef044f --- /dev/null +++ b/ECOMP-PDP/xacml.pap.properties @@ -0,0 +1,107 @@ +### +# ============LICENSE_START======================================================= +# ECOMP-PDP +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +# +# This is our factory that will create our engine +# +xacml.PAP.papEngineFactory=org.openecomp.policy.xacml.std.pap.StdEngineFactory + +# +# Where we store our PAP PDP Group/Node information +# +xacml.pap.pdps=pdps +# +# Need the PAP's url (how PDPs will reach it) configured here +# because we need it to generate the URLs of the Policy Files +# sent to the PDPs in the configuration when the PAP is first brought up. +# (In other cases, such as the PDP calling the PAP, we could generate this URL, +# but for startup there is no other way to get it.) +# +# + +xacml.rest.pap.url=http://localhost:8070/pap/ + +# +# Upon startup, have the PAP servlet send latest configuration information to all +# the PDP nodes it knows about. +# +xacml.rest.pap.initiate.pdp=true +# +# Heartbeat from PAP to PDPs +# +# How much time (in milliseconds) between heartbeats +# (i.e. the time between completing the heartbeat with all PDPs and starting the next cycle) +# +xacml.rest.pap.heartbeat.interval=10000 +# +# Heartbeat connection timeout (in milliseconds) +# +xacml.rest.pap.heartbeat.timeout=10000 + +################################################################################################ +# Adding properties for getting properties previously used by PAP-ADMIN for creating Policies +# THis is part of the Policy Creation API project +################################################################################################ + +# Set your domain here: +xacml.rest.pap.domain=com + +# Location where all the user workspaces are located. +xacml.rest.pap.workspace=workspace + +# Location where the GIT repository is located +xacml.rest.pap.repository=repository + +# new Property Please mention your PAP-REST webapps Location here. +xacml.rest.config.webapps=C:\\Second Tomcat\\apache-tomcat-8.0.23\\webapps\\ConfigPAP\\ + +#Turn the audit on to synchronize the DB/file system +#xacml.rest.pap.run.audit.flag=true +#Turn the audit off to not synchronize the DB/file system +#xacml.rest.pap.run.audit.flag=false +xacml.rest.pap.run.audit.flag=false + +#Audit will synchronize the file system to match the contents of the DB +#xacml.rest.pap.filesystem.audit=true +#Audit will synchronize the DB to match the contents of the file system +#xacml.rest.pap.filesystem.audit=false +xacml.rest.pap.filesystem.audit=false + +# id +xacml.rest.pap.userid=testpap +# pass +xacml.rest.pap.password=alpha123 +# pdps file +xacml.rest.pdp.idfile=test.properties + +#Properties for db access +javax.persistence.jdbc.driver=org.h2.Driver +javax.persistence.jdbc.url=jdbc:h2:file:./sql/xacmlTest +javax.persistence.jdbc.user=sa +javax.persistence.jdbc.password= + +#Time in ms which a Policy DB transaction will wait to get the transaction lock object +xacml.rest.pap.transaction.waitms=1000 + +#Policy DB transaction timeout in ms after it has obtained the transaction lock object +xacml.rest.pap.transaction.timeoutms=500 + +#Policy Audit timeout in ms after it has obtained the transaction lock object +xacml.rest.pap.audit.timeoutms=5000 diff --git a/ECOMP-PDP/xacml.pdp.properties b/ECOMP-PDP/xacml.pdp.properties new file mode 100644 index 000000000..ba5358d0b --- /dev/null +++ b/ECOMP-PDP/xacml.pdp.properties @@ -0,0 +1,86 @@ +### +# ============LICENSE_START======================================================= +# ECOMP-PDP +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +# Default XACML Properties File for PDP RESTful servlet +# +# Standard API Factories +# +xacml.dataTypeFactory=com.att.research.xacml.std.StdDataTypeFactory +xacml.pdpEngineFactory=com.att.research.xacmlatt.pdp.ATTPDPEngineFactory +xacml.pepEngineFactory=com.att.research.xacml.std.pep.StdEngineFactory +# NOT USED SEE BELOW xacml.pipFinderFactory=com.att.research.xacml.std.pip.StdPIPFinderFactory +xacml.traceEngineFactory=com.att.research.xacml.std.trace.LoggingTraceEngineFactory +# +# AT&T PDP Implementation Factories +# +xacml.att.evaluationContextFactory=com.att.research.xacmlatt.pdp.std.StdEvaluationContextFactory +xacml.att.combiningAlgorithmFactory=com.att.research.xacmlatt.pdp.std.StdCombiningAlgorithmFactory +xacml.att.functionDefinitionFactory=org.openecomp.policy.xacml.custom.EcompFunctionDefinitionFactory +# NOT USED SEE BELOW xacml.att.policyFinderFactory=org.openecomp.policy.pdp.std.StdPolicyFinderFactory + +# +# AT&T RESTful PDP Implementation Factories +# +xacml.pipFinderFactory=org.openecomp.policy.rest.impl.XACMLPdpPIPFinderFactory +xacml.att.policyFinderFactory=org.openecomp.policy.rest.XACMLPdpPolicyFinderFactory +# +# When set to true, this flag tells the StdPolicyFinderFactory to combined all the root policy files into +# into one PolicySet and use the given Policy Algorithm. +# +xacml.att.policyFinderFactory.combineRootPolicies=urn:com:att:xacml:3.0:policy-combining-algorithm:combined-deny-overrides +# +# PDP RESTful API properties +# +# Set this to the address where the XACML-PAP-REST servlet is running +# http://localhost:9090/pap/ +xacml.rest.pap.url=http://localhost:8070/pap/ +# +# Give the running PDP an ID for the PAP. The url that its running as is a good choice. +# The PAP identifies PDP's using the URL of the PDP. +# +xacml.rest.pdp.id=http://localhost:8082/pdp/ +# +# Set the directory where the PDP holds its Policy Cache and PIP Configuration +# +xacml.rest.pdp.config=config_testing + +xacml.rest.pdp.webapps=/webapps + +xacml.rest.pdp.configparams=../webapps/configparams +# +# Initialize register with PAP servlet +# +xacml.rest.pdp.register=true +# +# Sleep period in seconds between register attempts +# +xacml.rest.pdp.register.sleep=15 +# +# number of attempts to register. -1 means keep trying forever. +# +xacml.rest.pdp.register.retries=-1 +# +# max number of bytes in a POST of a XML/JSON request +# +xacml.rest.pdp.maxcontent=32767 +# +# testClient file +# +xacml.rest.pep.idfile = testclient.properties diff --git a/ECOMP-PDP/xacml.properties b/ECOMP-PDP/xacml.properties new file mode 100644 index 000000000..22e8ee093 --- /dev/null +++ b/ECOMP-PDP/xacml.properties @@ -0,0 +1,46 @@ +### +# ============LICENSE_START======================================================= +# ECOMP-PDP +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +# Default XACML Properties File +# Standard API Factories +# +xacml.dataTypeFactory=com.att.research.xacml.std.StdDataTypeFactory +xacml.pdpEngineFactory=com.att.research.xacmlatt.pdp.ATTPDPEngineFactory +xacml.pepEngineFactory=com.att.research.xacml.std.pep.StdEngineFactory +xacml.pipFinderFactory=com.att.research.xacml.std.pip.StdPIPFinderFactory + +# If there is a standard set of PIPEngines: +# xacml.pip.engines=engine1,engine2,...,engineN +# engine1.classname=com.att.research.xacmlpip.OraclePIP +# engine1.prop1=foo +# engine1.prop2=bar +# ... +# engine2.classname=com.att.research.xacmlpip.ActiveDirectoryPIP +# ... + +# AT&T PDP Implementation Factories +# +xacml.att.evaluationContextFactory=com.att.research.xacmlatt.pdp.std.StdEvaluationContextFactory +xacml.att.combiningAlgorithmFactory=com.att.research.xacmlatt.pdp.std.StdCombiningAlgorithmFactory +xacml.att.functionDefinitionFactory=com.att.research.xacmlatt.pdp.std.StdFunctionDefinitionFactory +xacml.att.policyFinderFactory=com.att.research.xacmlatt.pdp.std.StdPolicyFinderFactory + +# If there is a standard policy for the engine: +# xacml.att.stdPolicyFinderFactory.rootPolicyFile=/etc/stdpolicyset.xml diff --git a/ECOMP-REST/.gitignore b/ECOMP-REST/.gitignore new file mode 100644 index 000000000..227059fcf --- /dev/null +++ b/ECOMP-REST/.gitignore @@ -0,0 +1,6 @@ +/bin/ +/target/ +/target/ +/target/ +/target/ +/target/ diff --git a/ECOMP-REST/policyLogger.properties b/ECOMP-REST/policyLogger.properties new file mode 100644 index 000000000..2cd1c4bef --- /dev/null +++ b/ECOMP-REST/policyLogger.properties @@ -0,0 +1,44 @@ +### +# ============LICENSE_START======================================================= +# ECOMP-REST +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +################################### Set concurrentHashMap and timer info ####################### +#Timer initial delay and the delay between in milliseconds before task is to be execute. +timer.delay.time=1000 +#Timer scheduleAtFixedRate period - time in milliseconds between successive task executions. +check.interval= 30000 +#Longest time an event info can be stored in the concurrentHashMap for logging - in seconds. +event.expired.time=86400 +#Size of the concurrentHashMap which stores the event starting time, etc - when its size reaches this limit, the Timer gets executed +#to remove all expired records from this concurrentHashMap. +concurrentHashMap.limit=5000 +#Size of the concurrentHashMap - when its size drops to this point, stop the Timer +stop.check.point=2500 +################################### Set logging format ############################################# +# set EELF for EELF logging format, set LOG4J for using log4j, set SYSTEMOUT for using system.out.println +logger.type=EELF +#################################### Set level for EELF or SYSTEMOUT logging ################################## +# Set level for debug file. Set DEBUG to enable .info, .warn and .debug; set INFO for enable .info and .warn; set OFF to disable all +debugLogger.level=INFO +# Set level for metrics file. Set OFF to disable; set ON to enable +metricsLogger.level=ON +# Set level for error file. Set OFF to disable; set ON to enable +error.level=ON +# Set level for audit file. Set OFF to disable; set ON to enable +audit.level=ON diff --git a/ECOMP-REST/pom.xml b/ECOMP-REST/pom.xml new file mode 100644 index 000000000..892ba8d29 --- /dev/null +++ b/ECOMP-REST/pom.xml @@ -0,0 +1,116 @@ + + + + + + + 4.0.0 + + + org.openecomp.policy.engine + PolicyEngineSuite + 1.0.0-SNAPSHOT + + + org.openecomp.policy.engine + ECOMP-REST + + ECOMP REST + + jar + + + + org.openecomp.policy.engine + ${project.version} + ECOMP-XACML + + + javax.servlet + javax.servlet-api + 3.1.0 + + + commons-logging + commons-logging + 1.1.3 + + + javax.servlet + servlet-api + + + + + com.google.guava + guava + 14.0.1 + + + junit + junit + 4.11 + test + + + org.mockito + mockito-core + 1.9.5 + + + org.springframework + spring-mock + 2.0.8 + + + com.mockrunner + mockrunner + 0.3.1 + + + org.openecomp.policy.common + ECOMP-Logging + ${common-modules.version} + + + org.eclipse.emf + org.eclipse.emf.ecore.xmi + 2.11.0-v20150123-0347 + + + org.eclipse.emf + org.eclipse.emf.ecore + 2.11.0-v20150123-0347 + + + org.eclipse.emf + org.eclipse.emf.common + 2.11.0-v20150123-0347 + + + org.json + json + [20090211,) + + + diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/XACMLRest.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/XACMLRest.java new file mode 100644 index 000000000..7e535cbcf --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/XACMLRest.java @@ -0,0 +1,220 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest; + +import java.io.IOException; +import java.util.Enumeration; +import java.util.Map; +import java.util.Properties; +import java.util.Set; + +import javax.servlet.ServletConfig; +import javax.servlet.http.HttpServletRequest; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.eelf.PolicyLogger; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; +import com.att.research.xacml.util.XACMLProperties; + + +/** + * This static class is used by both the PDP and PAP servlet's. It contains some common + * static functions and objects used by both the servlet's. + * + * + */ +public class XACMLRest { + private static final Log logger = LogFactory.getLog(XACMLRest.class); + private static Properties restProperties = new Properties(); + + /** + * This must be called during servlet initialization. It sets up the xacml.?.properties + * file as a system property. If the System property is already set, then it does not + * do anything. This allows the developer to specify their own xacml.properties file to be + * used. They can 1) modify the default properties that comes with the project, or 2) change + * the WebInitParam annotation, or 3) specify an alternative path in the web.xml, or 4) set + * the Java System property to point to their xacml.properties file. + * + * The recommended way of overriding the default xacml.properties file is using a Java System + * property: + * + * -Dxacml.properties=/opt/app/xacml/etc/xacml.admin.properties + * + * This way one does not change any actual code or files in the project and can leave the + * defaults alone. + * + * @param config - The servlet config file passed from the javax servlet init() function + */ + public static void xacmlInit(ServletConfig config) { + // + // Get the XACML Properties File parameter first + // + String propFile = config.getInitParameter("XACML_PROPERTIES_NAME"); + if (propFile != null) { + // + // Look for system override + // + String xacmlPropertiesName = System.getProperty(XACMLProperties.XACML_PROPERTIES_NAME); + if (xacmlPropertiesName == null) { + // + // Set it to our servlet default + // + if (logger.isDebugEnabled()) { + logger.debug("Using Servlet Config Property for XACML_PROPERTIES_NAME:" + propFile); + } + System.setProperty(XACMLProperties.XACML_PROPERTIES_NAME, propFile); + } else { + if (logger.isDebugEnabled()) { + logger.debug("Using System Property for XACML_PROPERTIES_NAME:" + xacmlPropertiesName); + } + } + } + // + // Setup the remaining properties + // + Enumeration params = config.getInitParameterNames(); + while (params.hasMoreElements()) { + String param = params.nextElement(); + if (! param.equals("XACML_PROPERTIES_NAME")) { + String value = config.getInitParameter(param); + //logger.info(param + "=" + config.getInitParameter(param)); + PolicyLogger.info(param + "=" + config.getInitParameter(param)); + restProperties.setProperty(param, value); + } + } + } + + /** + * Reset's the XACMLProperties internal properties object so we start + * in a fresh environment. Then adds back in our Servlet init properties that were + * passed in the javax Servlet init() call. + * + * This function is primarily used when a new configuration is passed in and the + * PDP servlet needs to load a new PDP engine instance. + * + * @param pipProperties - PIP configuration properties + * @param policyProperties - Policy configuration properties + */ + public static void loadXacmlProperties(Properties policyProperties, Properties pipProperties) { + try { + // + // Start fresh + // + XACMLProperties.reloadProperties(); + // + // Now load our init properties + // + XACMLProperties.getProperties().putAll(XACMLRest.restProperties); + // + // Load our policy properties + // + if (policyProperties != null) { + XACMLProperties.getProperties().putAll(policyProperties); + } + // + // Load our pip config properties + // + if (pipProperties != null) { + XACMLProperties.getProperties().putAll(pipProperties); + } + } catch (IOException e) { + //logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Failed to put init properties into Xacml properties", e); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "Failed to put init properties into Xacml properties"); + } + // + // Dump them + // + if (logger.isDebugEnabled()) { + try { + logger.debug(XACMLProperties.getProperties().toString()); + } catch (IOException e) { + //logger.error( XACMLErrorConstants.ERROR_PROCESS_FLOW + "Cannot dump properties", e); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "Cannot dump properties"); + } + } + } + + /** + * Helper routine to dump the HTTP servlet request being serviced. Primarily for debugging. + * + * @param request - Servlet request (from a POST/GET/PUT/etc.) + */ + public static void dumpRequest(HttpServletRequest request) { + if (logger.isDebugEnabled()) { + // special-case for receiving heartbeat - don't need to repeatedly output all of the information in multiple lines + if (request.getMethod().equals("GET") && "hb".equals(request.getParameter("type")) ) { + //logger.debug("GET type=hb : heartbeat received"); + PolicyLogger.debug("GET type=hb : heartbeat received"); + return; + } + logger.debug(request.getMethod() + ":" + request.getRemoteAddr() + " " + request.getRemoteHost() + " " + request.getRemotePort()); + logger.debug(request.getLocalAddr() + " " + request.getLocalName() + " " + request.getLocalPort()); + Enumeration en = request.getHeaderNames(); + logger.debug("Headers:"); + while (en.hasMoreElements()) { + String element = en.nextElement(); + Enumeration values = request.getHeaders(element); + while (values.hasMoreElements()) { + String value = values.nextElement(); + logger.debug(element + ":" + value); + } + } + logger.debug("Attributes:"); + en = request.getAttributeNames(); + while (en.hasMoreElements()) { + String element = en.nextElement(); + logger.debug(element + ":" + request.getAttribute(element)); + } + logger.debug("ContextPath: " + request.getContextPath()); + if (request.getMethod().equals("PUT") || request.getMethod().equals("POST")) { + // POST and PUT are allowed to have parameters in the content, but in our usage the parameters are always in the Query string. + // More importantly, there are cases where the POST and PUT content is NOT parameters (e.g. it might contain a Policy file). + // Unfortunately the request.getParameterMap method reads the content to see if there are any parameters, + // and once the content is read it cannot be read again. + // Thus for PUT and POST we must avoid reading the content here so that the main code can read it. + logger.debug("Query String:" + request.getQueryString()); + try { + if (request.getInputStream() == null) { + logger.debug("Content: No content inputStream"); + } else { + logger.debug("Content available: " + request.getInputStream().available()); + } + } catch (Exception e) { + logger.debug("Content: inputStream exception: " + e.getMessage() + "; (May not be relevant)"); + } + } else { + logger.debug("Parameters:"); + Map params = request.getParameterMap(); + Set keys = params.keySet(); + for (String key : keys) { + String[] values = params.get(key); + logger.debug(key + "(" + values.length + "): " + (values.length > 0 ? values[0] : "")); + } + } + logger.debug("Request URL:" + request.getRequestURL()); + } + } +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/XACMLRestProperties.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/XACMLRestProperties.java new file mode 100644 index 000000000..bc991aafb --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/XACMLRestProperties.java @@ -0,0 +1,443 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest; + +import com.att.research.xacml.util.XACMLProperties; + +/** + * These are XACML Properties that are relevant to the RESTful API interface for + * the PDP, PAP and AC interfaces. + * + * + */ +public class XACMLRestProperties extends XACMLProperties { + /** + * A unique identifier for the PDP servlet instance. Usually set to the URL + * it is running as in the J2EE container. + * + * Eg. http://localhost:8080/pdp/ + */ + public static final String PROP_PDP_ID = "xacml.rest.pdp.id"; + /** + * A PDP servlet's configuration directory. Holds the pip and policy + * configuration data as well as the local policy cache. + * + * Eg: /opt/app/xacml/config + */ + public static final String PROP_PDP_CONFIG = "xacml.rest.pdp.config"; + // Resilience feature- + public static final String PROP_PDP_WEBAPPS = "xacml.rest.pdp.webapps"; + //Closed Loop JSON table + public static final String PROP_ADMIN_CLOSEDLOOP = "xacml.rest.admin.closedLoopJSON"; + /** + * Set this property to true or false if the PDP servlet should register + * itself upon startup with the PAP servlet. + */ + public static final String PROP_PDP_REGISTER = "xacml.rest.pdp.register"; + /** + * Number of seconds the PDP will sleep while retrying registration with the + * PAP. This value must be greater or equal to 5. + */ + public static final String PROP_PDP_REGISTER_SLEEP = "xacml.rest.pdp.register.sleep"; + /** + * Number of retry attempts at registration with the PAP. A value of -1 + * indicates infinite retries. + */ + public static final String PROP_PDP_REGISTER_RETRIES = "xacml.rest.pdp.register.retries"; + /** + * Max content length accepted for an incoming POST XML/JSON request. + * Default is 32767 bytes. + */ + public static final String PROP_PDP_MAX_CONTENT = "xacml.rest.pdp.maxcontent"; + /** + * Custom HTTP header used by PDP to send the value of the PROP_PDP_ID + */ + public static final String PROP_PDP_HTTP_HEADER_ID = "X-XACML-PDP-ID"; + /** + * Custom HHTP header used by PDP to send its heartbeat value. + */ + public static final String PROP_PDP_HTTP_HEADER_HB = "X-XACML-PDP-HB"; + /* + * Custom HTTP header used by PDP to send the value of the + * X-XACML-PDP-JMX-PORT + */ + public static final String PROP_PDP_HTTP_HEADER_JMX_PORT = "X-XACML-PDP-JMX-PORT"; + /** + * The URL of the PAP servlet. Used by PDP servlet's to communicate. Because + * administrators can set whatever context they want to run the PAP servlet, + * it isn't easy to determine a return URL for the PAP servlet. This is + * especially true upon initialization. + */ + public static final String PROP_PAP_URL = "xacml.rest.pap.url"; + /** + * A comma divided list of urls pointing to avaiable PAP urls. + * If one or more fail, the other servers in the list can + * handle the requests. + */ + public static final String PROP_PAP_URLS = "xacml.rest.pap.urls"; + public static final String PROP_PAP_FAILED_URLS = "xacml.rest.pap.failedUrls"; + public static final String PROP_PAP_SUCCEEDED_URLS = "xacml.rest.pap.succeededUrls"; + //public static final String PROP_PAP_FAILED_URL_TIME = "xacml.rest.pap.failedUrlTime"; + + /** + * Upon startup, have the PAP servlet send latest configuration information + * to all the PDP nodes it knows about. + */ + public static final String PROP_PAP_INITIATE_PDP_CONFIG = "xacml.rest.pap.initiate.pdp"; + /** + * The interval the PAP servlet uses to send heartbeat requests to the PDP + * nodes. + */ + public static final String PROP_PAP_HEARTBEAT_INTERVAL = "xacml.rest.pap.heartbeat.interval"; + /** + * Timeout value used by the PAP servlet when trying to check the heartbeat + * of a PDP node. + */ + public static final String PROP_PAP_HEARTBEAT_TIMEOUT = "xacml.rest.pap.heartbeat.timeout"; + /* + * This is the domain you can setup for your organization, it should be a URI. + * Eg. com:sample:foo + */ + public static final String PROP_PAP_DOMAIN = "xacml.rest.pap.domain"; + + /* + * Local path to where user workspaces exist. The user workspace contains temporary files, the + * user's clone of the GIT repository, anything specific to the user, etc. + */ + public static final String PROP_PAP_WORKSPACE = "xacml.rest.pap.workspace"; + + /* + * Local path to where the GIT repository exists. + * + * Eg. /opt/app/xacml/repository + */ + public static final String PROP_PAP_REPOSITORY = "xacml.rest.pap.repository"; + + /* + * Database driver property + */ + public static final String PROP_PAP_DB_DRIVER = "javax.persistence.jdbc.driver"; + + /* + * Database url + */ + public static final String PROP_PAP_DB_URL = "javax.persistence.jdbc.url"; + + /* + * Database user + */ + public static final String PROP_PAP_DB_USER = "javax.persistence.jdbc.user"; + + /* + * Database password + */ + public static final String PROP_PAP_DB_PASSWORD = "javax.persistence.jdbc.password"; + + /* + * Time in ms which a Policy DB transaction will wait to get the transaction lock object + */ + public static final String PROP_PAP_TRANS_WAIT = "xacml.rest.pap.transaction.waitms"; + + /* + * Policy DB transaction timeout in ms after it has obtained the transaction lock object + */ + public static final String PROP_PAP_TRANS_TIMEOUT = "xacml.rest.pap.transaction.timeoutms"; + + /* + * Policy Audit transaction timeout in ms after it has obtained the transaction lock object + */ + public static final String PROP_PAP_AUDIT_TIMEOUT = "xacml.rest.pap.audit.timeoutms"; + + /* + * Value determines direction of audit. Value=true will synch the file system to contents of the DB. + * Value=false will synch the DB to the contents of the file system. + */ + public static final String PROP_PAP_AUDIT_FLAG = "xacml.rest.pap.filesystem.audit"; + + /* + * Value for enable/disable of audit functionality + */ + public static final String PROP_PAP_RUN_AUDIT_FLAG = "xacml.rest.pap.run.audit.flag"; + + /* + * Controls how long the timeout will be when a pap sends a notification to another pap + */ + public static final String PROP_PAP_NOTIFY_TIMEOUT = "xacml.rest.pap.notify.timeoutms"; + /* + * Value for Enable/Disable of AutoPush Flag. + */ + public static final String PROP_PAP_PUSH_FLAG = "xacml.rest.pap.autopush.flag"; + + /* + * Properties file for the AutoPush Functionality. + */ + public static final String PROP_PAP_PUSH_FILE = "xacml.rest.pap.autopush.file"; + + /* + * Local path to where the GIT repository exists. + * + * Eg. /opt/app/xacml/repository + */ + public static final String PROP_ADMIN_REPOSITORY = "xacml.rest.admin.repository"; + /* + * Local path to where user workspaces exist. The user workspace contains + * temporary files, the user's clone of the GIT repository, anything + * specific to the user, etc. + */ + public static final String PROP_ADMIN_WORKSPACE = "xacml.rest.admin.workspace"; + /* + * This is the domain you can setup for your organization, it should be a + * URI. + * + * Eg. com:sample:foo + */ + public static final String PROP_ADMIN_DOMAIN = "xacml.rest.admin.domain"; + /** + * PROP_ADMIN_USER_NAME is simply a name for the logged in user. + * + * AC authentication is out the scope of the web application itself. It is + * up to the developer to setup authentication as they please in the J2EE + * container used to run the web application. Whatever authentication + * mechanism they use, they should then set the attribute into the + * HttpSession object. The Admin Console will be able to read that value + * (default to "guest") in. + * + * ((HttpServletRequest) + * request).getSession().setAttribute("xacml.rest.admin.user.name", + * "Homer"); + * + */ + public static final String PROP_ADMIN_USER_NAME = "xacml.rest.admin.user.name"; + /** + * + * PROP_ADMIN_USER_ID is an id for the logged in user. + * + * Eg. hs1234 + * + * @see #PROP_ADMIN_USER_NAME for more information. + */ + public static final String PROP_ADMIN_USER_ID = "xacml.rest.admin.user.id"; + /** + * + * PROP_ADMIN_USER_EMAIL is a user's email address. + * + * @see #PROP_ADMIN_USER_NAME for more information. + */ + public static final String PROP_ADMIN_USER_EMAIL = "xacml.rest.admin.user.email"; + /** + * Directory path containing sub-directories where the Subscriber servlet + * puts files sent through data feeds. + */ + public static final String PROP_SUBSCRIBER_INCOMING = "xacml.subscriber.incoming"; + /** + * The specific data feed name for the Subscriber servlet to register for. + */ + public static final String PROP_SUBSCRIBER_FEED = "xacml.subscriber.feed"; + /** + * Value for the log time frame that is to be stored in the database any + * logs after this time frame will be removed. + */ + public static final String PROP_LOG_TIMEFRAME = "xacml.log.timeframe"; + /** + * Value for the DB connections used to store the log files. + */ + public static final String PROP_LOG_DB_DRIVER = "xacml.log.db.driver"; + public static final String PROP_LOG_DB_URL = "xacml.log.db.url"; + public static final String PROP_LOG_DB_USER = "xacml.log.db.user"; + public static final String PROP_LOG_DB_PASSWORD = "xacml.log.db.password"; + /* + * Value for JMX port for the PDP + */ + public static final String PROP_PDP_JMX_PORT = "xacml.jmx.port"; + + /* + * Value for refresh rate + */ + public static final String PROP_REFRESH_RATE = "xacml.refresh.rate"; + + // added for Security between Policy Components. + // 6/26 + /* + * PROP_PAP_USERID is the PAP Unique User ID + */ + public static final String PROP_PAP_USERID = "xacml.rest.pap.userid"; + /* + * PROP_PAP_PASS is the PAP password + */ + public static final String PROP_PAP_PASS = "xacml.rest.pap.password"; + /* + * PROP_PAP_PASS is the PAP password + */ + public static final String PROP_CONFIG_URL = "xacml.rest.config.url"; + /* + * PROP_PDP_USERID is the PDP Unique User ID + */ + public static final String PROP_PDP_USERID = "xacml.rest.pdp.userid"; + /* + * PROP_PDP_PASS is the PDP password + */ + public static final String PROP_PDP_PASS = "xacml.rest.pdp.password"; + /* + * PROP_PDP_IDFILE is the PDP Authentication File + */ + public static final String PROP_PDP_IDFILE = "xacml.rest.pdp.idfile"; + /* + * PROP_PEP_IDFILE is the Client Authentication File + */ + public static final String PROP_PEP_IDFILE = "xacml.rest.pep.idfile"; + /* + * webapps Location of the PAP-REST server + */ + public static final String PROP_PAP_WEBAPPS= "xacml.rest.config.webapps"; + /* + * Value for Notification Option + */ + public static final String PROP_NOTIFICATION_TYPE = "xacml.notification.type"; + + /* + * Value for Notification Servers + */ + public static final String PROP_NOTIFICATION_UEB_CLUSTER = "xacml.ueb.cluster"; + /* + * Value for Notification Delay + */ + public static final String PROP_NOTIFICATION_DELAY= "xacml.rest.notification.delay"; + /* + * Closedloop Fault Policy Template Version + */ + public static final String TemplateVersion_Fault= "xacml.rest.closedLoopFault"; + /* + * Closedloop PM Policy Template Version + */ + public static final String TemplateVersion_PM= "xacml.rest.closedLoopPM"; + /* + * Value for model properties file + */ + public static final String PROP_ADMIN_MICROSERVICE = "xacml.rest.admin.microServiceModel"; + /* + * MicroService Policy Template Version + */ + public static final String TemplateVersion_MS= "xacml.rest.microServices"; + /* + * GOC Policy Template Version + */ + public static final String TemplateVersion_GOC= "xacml.rest.gocPolicy"; + /* + * Firewall Policy Template Version + */ + public static final String TemplateVersion_FW= "xacml.rest.firewallPolicy"; + /* + * Size of SelectList for Users in MS + * + */ + public static final String PROP_USER_SELECTLIST_WINDOW_SIZE= "xacml.user.column.count"; + /* + * Audit function in pap admin to Update userinfo table to syncronize with Roles table + */ + public static final String PROP_ROLES_USERINFO_AUDIT= "xacml.audit.userInfo"; + /* + * test Environment LoginId + */ + public static final String PROP_TEST_ENVIRONMENT_LOGINID= "xacml.testEnvironment.loginId"; + /* + * Size of of the page length for sqlcontainer + * + */ + public static final String PROP_SQLCONTAINER_PAGE_LENGTH= "xacml.sqlcontainer.page.length"; + /* + * add values used to connect to restful api + * + */ + public static final String PROP_RESTFUL_INTERFACE= "xacm.restful.interface.file"; + /* + * add pattern to identify what values are designed as required + * + */ + public static final String PROP_XCORE_REQUIRED_PATTERN= "xacm.xcor.required.pattern"; + /* + * Time before a cache value is evicted + * + */ + public static final String PROP_CACHE_LIVE_TIME= "xacm.cache.live.time"; + /* + * Highest value allowed in priority + * + */ + public static final String PROP_PRIORITY_COUNT= "xacml.max.priority.count"; + /* + * The name of the PAP. Must be unique across the system + */ + public static final String PAP_RESOURCE_NAME="xacml.rest.pap.resource.name"; + /* + * The name of the site in which the PAP resides + */ + public static final String PAP_SITE_NAME="site_name"; + /* + * The node type of the PAP - really a no-op since it's value is pap + */ + public static final String PAP_NODE_TYPE="node_type"; + /* + * A list of the groups of resources/nodes on which the PAP is dependent. The members of a + * group are comma-separated and the groups are separated with semicolons. + */ + public static final String PAP_DEPENDENCY_GROUPS="dependency_groups"; + /* + * The (optional) period of time in seconds between executions of the integrity audit. + * Value < 0 : Audit does not run (default value if property is not present = -1) + * Value = 0 : Audit runs continuously + * Value > 0 : The period of time in seconds between execution of the audit on a particular node + */ + public static final String PAP_INTEGRITY_AUDIT_PERIOD_SECONDS = "integrity_audit_period_seconds"; + /* + * The name of the Admin. Must be unique across the system + */ + public static final String ADMIN_RESOURCE_NAME="xacml.rest.admin.resource.name"; + /* + * The name of the PDP. Must be unique across the system + */ + public static final String PDP_RESOURCE_NAME="xacml.rest.pdp.resource.name"; + /* + * Audit function in pap admin to Update userinfo table to syncronize with Roles table + */ + public static final String PROP_AUTOMATIC_POLICYPUSH= "xacml.automatic.push"; + /* + * Add Limit for Ecomp Portal Dashboard tab data + */ + public static final String PROP_ECOMP_LOGLIMIT = "xacml.ecomp.dashboard.logTableLimit"; + public static final String PROP_ECOMP_SYSTEMALERTLIMIT = "xacml.ecomp.dashboard.systemAlertTableLimit"; + /* + * Diff of the policies for the Firewall Feature. + */ + public static final String PROP_FW_GETURL = "FW_GETURL"; + public static final String PROP_FW_AUTHOURL = "FW_AUTHOURL"; + public static final String PROP_FW_PROXY = "FW_PROXY"; + public static final String PROP_FW_PORT = "FW_PORT"; + + /* + * The number of Risk Levels allowed + */ + public static final String ADMIN_RISK_LEVEL_COUNT="xacml.risk.level.count"; + /* + * The maxium Level displayed on the UI for Micro Services + */ + public static final String PROP_MODEL_LEVEL = "xacml.model.level"; + +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/XacmlAdminAuthorization.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/XacmlAdminAuthorization.java new file mode 100644 index 000000000..f611cf944 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/XacmlAdminAuthorization.java @@ -0,0 +1,223 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openecomp.policy.rest.jpa.UserInfo; + +import com.att.research.xacml.api.DataTypeException; +import com.att.research.xacml.api.Decision; +import com.att.research.xacml.api.Request; +import com.att.research.xacml.api.Response; +import com.att.research.xacml.api.Result; +import org.openecomp.policy.xacml.api.XACMLErrorConstants; +import com.att.research.xacml.api.pdp.PDPEngine; +import com.att.research.xacml.api.pdp.PDPEngineFactory; +import com.att.research.xacml.api.pdp.PDPException; +import com.att.research.xacml.std.annotations.RequestParser; +import com.att.research.xacml.std.annotations.XACMLAction; +import com.att.research.xacml.std.annotations.XACMLRequest; +import com.att.research.xacml.std.annotations.XACMLResource; +import com.att.research.xacml.std.annotations.XACMLSubject; +import com.att.research.xacml.util.FactoryException; + +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.eelf.PolicyLogger; + +public class XacmlAdminAuthorization { + private static Log logger = LogFactory.getLog(XacmlAdminAuthorization.class); + + private static UserInfo userId; + public static UserInfo getUserId() { + return userId; + } + + public void setUserId(UserInfo userId) { + XacmlAdminAuthorization.userId = userId; + } + + public enum AdminAction { + ACTION_ACCESS("access"), + ACTION_READ("read"), + ACTION_WRITE("write"), + ACTION_ADMIN("admin"); + + String action; + AdminAction(String a) { + this.action = a; + } + public String toString() { + return this.action; + } + } + + public enum AdminResource { + RESOURCE_APPLICATION("application"), + RESOURCE_POLICY_WORKSPACE("workspace"), + RESOURCE_POLICY_EDITOR("editor"), + RESOURCE_DICTIONARIES("dictionaries"), + RESOURCE_PDP_ADMIN("pdp_admin"), + RESOURCE_PIP_ADMIN("pip_admin"), + RESOURCE_SCOPES_SUPERADMIN("manage_scopes"); + + String resource; + AdminResource(String r) { + this.resource = r; + } + public String toString() { + return this.resource; + } + } + + public enum Role { + ROLE_GUEST("guest"), + ROLE_ADMIN("admin"), + ROLE_EDITOR("editor"), + ROLE_SUPERGUEST("super-guest"), + ROLE_SUPEREDITOR("super-editor"), + ROLE_SUPERADMIN("super-admin"); + + String userRole; + + Role(String a) { + this.userRole = a; + } + public String toString() { + return this.userRole; + } + } + + @XACMLRequest(ReturnPolicyIdList=true) + public class AuthorizationRequest { + + @XACMLSubject(includeInResults=true) + String userID; + + @XACMLAction() + String action; + + @XACMLResource() + String resource; + + public AuthorizationRequest(String userId, String action, String resource) { + this.userID = userId; + this.action = action; + this.resource = resource; + } + + public String getUserID() { + return userID; + } + + public void setUserID(String userID) { + this.userID = userID; + } + + public String getAction() { + return action; + } + + public void setAction(String action) { + this.action = action; + } + + public String getResource() { + return resource; + } + + public void setResource(String resource) { + this.resource = resource; + } + } + + // + // The PDP Engine + // + protected PDPEngine pdpEngine; + + public XacmlAdminAuthorization() { + PDPEngineFactory pdpEngineFactory = null; + try { + pdpEngineFactory = PDPEngineFactory.newInstance(); + if (pdpEngineFactory == null) { + logger.error("Failed to create PDP Engine Factory"); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.error("Failed to create PDP Engine Factory"); + } + this.pdpEngine = pdpEngineFactory.newEngine(); + } catch (FactoryException e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Exception create PDP Engine: " + e.getLocalizedMessage()); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "XacmlAdminAuthorization", "Exception create PDP Engine"); + } + } + + public boolean isAuthorized(String userid, AdminAction action, AdminResource resource) { + logger.info("authorize: " + userid + " to " + action + " with " + resource); + if (this.pdpEngine == null) { + logger.warn("no pdp engine available to authorize"); + return false; + } + Request request; + try { + request = RequestParser.parseRequest(new AuthorizationRequest(userid, action.toString(), resource.toString())); + } catch (IllegalArgumentException | IllegalAccessException | DataTypeException e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Failed to create request: " + e.getLocalizedMessage()); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "XacmlAdminAuthorization", "Failed to create request"); + return false; + } + if (request == null) { + logger.error("Failed to parse request."); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.error("Failed to parse request"); + return false; + } + logger.info("Request: " + request); + // + // Ask the engine + // + try { + Response response = this.pdpEngine.decide(request); + if (response == null) { + logger.error("Null response from PDP decide"); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.error("Null response from PDP decide"); + } + // + // Should only be one result + // + for (Result result : response.getResults()) { + Decision decision = result.getDecision(); + logger.info("Decision: " + decision); + if (decision.equals(Decision.PERMIT)) { + return true; + } + } + } catch (PDPException e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "PDP Decide failed: " + e.getLocalizedMessage()); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "XacmlAdminAuthorization", "PDP Decide failed"); + } + return false; + } +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/ActionListDao.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/ActionListDao.java new file mode 100644 index 000000000..b8aa2948a --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/ActionListDao.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.dao; + +import java.util.List; + +import org.openecomp.policy.rest.jpa.ActionList; + +public interface ActionListDao { + List getActionListData(); + List getActionListDataByName(); + void Save(ActionList actionList); + void delete(ActionList actionList); + void update(ActionList actionList); +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/ActionPolicyDictDao.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/ActionPolicyDictDao.java new file mode 100644 index 000000000..c4914eb47 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/ActionPolicyDictDao.java @@ -0,0 +1,34 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.dao; + +import java.util.List; + +import org.openecomp.policy.rest.jpa.ActionPolicyDict; + +public interface ActionPolicyDictDao { + List getActionDictData(); + List getActionDictDataByName(); + ActionPolicyDict getActionEntityDatabyId(String action); + void Save(ActionPolicyDict action); + void delete(ActionPolicyDict action); + void update(ActionPolicyDict action); +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/AddressGroupDao.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/AddressGroupDao.java new file mode 100644 index 000000000..c4c7002b3 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/AddressGroupDao.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.dao; + +import java.util.List; + +import org.openecomp.policy.rest.jpa.AddressGroup; + +public interface AddressGroupDao { + List getAddressGroupData(); + List getAddressGroupDataByName(); + void Save(AddressGroup addressGroup); + void delete(AddressGroup addressGroup); + void update(AddressGroup addressGroup); +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/AttributeDao.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/AttributeDao.java new file mode 100644 index 000000000..796157f62 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/AttributeDao.java @@ -0,0 +1,35 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.dao; + +import java.util.List; + +import org.openecomp.policy.rest.jpa.Attribute; + +public interface AttributeDao { + + List getData(); + List getAttributeData(); + void Save(Attribute attribute); + void delete(Attribute attribute); + void update(Attribute attribute); + +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/BRMSParamTemplateDao.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/BRMSParamTemplateDao.java new file mode 100644 index 000000000..2c03192c0 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/BRMSParamTemplateDao.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.dao; + +import java.util.List; + +import org.openecomp.policy.rest.jpa.BRMSParamTemplate; + +public interface BRMSParamTemplateDao { + List getBRMSParamTemplateData(); + List getBRMSParamDataByName(); + void Save(BRMSParamTemplate brmsParam); + void delete(BRMSParamTemplate brmsParam); + void update(BRMSParamTemplate brmsParam); +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/CategoryDao.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/CategoryDao.java new file mode 100644 index 000000000..e90aa1d8b --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/CategoryDao.java @@ -0,0 +1,29 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.dao; + +import java.util.List; + +import org.openecomp.policy.rest.jpa.Category; + +public interface CategoryDao { + List getCategoryListData(); +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/DCAEUUIDDao.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/DCAEUUIDDao.java new file mode 100644 index 000000000..418d77629 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/DCAEUUIDDao.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.dao; + +import java.util.List; + +import org.openecomp.policy.rest.jpa.DCAEuuid; + +public interface DCAEUUIDDao { + List getDCAEuuidData(); + List getDCAEuuidDataByName(); + void Save(DCAEuuid dcaeUUID); + void delete(DCAEuuid dcaeUUID); + void update(DCAEuuid dcaeUUID); +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/DecisionPolicyDao.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/DecisionPolicyDao.java new file mode 100644 index 000000000..372a1fb7c --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/DecisionPolicyDao.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.dao; + +import java.util.List; + +import org.openecomp.policy.rest.jpa.DecisionSettings; + +public interface DecisionPolicyDao { + List getDecisionSettingsData(); + List getDecisionDataByName(); + void Save(DecisionSettings decisionSettings); + void delete(DecisionSettings decisionSettings); + void update(DecisionSettings decisionSettings); +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/DescriptiveScopeDao.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/DescriptiveScopeDao.java new file mode 100644 index 000000000..b0001390e --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/DescriptiveScopeDao.java @@ -0,0 +1,35 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.dao; + +import java.util.List; + +import org.openecomp.policy.rest.jpa.DescriptiveScope; + +public interface DescriptiveScopeDao { + + List getDescriptiveScope(); + List getDescriptiveScopeDataByName(); + void Save(DescriptiveScope descriptiveScope); + void delete(DescriptiveScope descriptiveScope); + void update(DescriptiveScope descriptiveScope); + DescriptiveScope getDescriptiveScopeById(String name); +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/EcompNameDao.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/EcompNameDao.java new file mode 100644 index 000000000..420121883 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/EcompNameDao.java @@ -0,0 +1,34 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.dao; + +import java.util.List; + +import org.openecomp.policy.rest.jpa.EcompName; + +public interface EcompNameDao { + List getEcompName(); + List getEcompNameDataByName(); + void Save(EcompName ecompName); + void delete(EcompName ecompName); + void update(EcompName ecompName); + +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/EnforcerPolicyDao.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/EnforcerPolicyDao.java new file mode 100644 index 000000000..55f4bf599 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/EnforcerPolicyDao.java @@ -0,0 +1,32 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.dao; + +import java.util.List; + +import org.openecomp.policy.rest.jpa.EnforcingType; + +public interface EnforcerPolicyDao { + List getEnforcingTypeData(); + void Save(EnforcingType enforcingType); + void delete(EnforcingType enforcingType); + void update(EnforcingType enforcingType); +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/FirewallDictionaryListDao.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/FirewallDictionaryListDao.java new file mode 100644 index 000000000..76cb1bc1f --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/FirewallDictionaryListDao.java @@ -0,0 +1,37 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.dao; + +import java.util.List; + +import org.openecomp.policy.rest.jpa.FirewallDictionaryList; + + +public interface FirewallDictionaryListDao { + List getFWDictionaryListData(); + List getFWDictionaryListDataByName(); + void Save(FirewallDictionaryList firewallDictionaryList); + void delete(FirewallDictionaryList firewallDictionaryList); + void update(FirewallDictionaryList firewallDictionaryList); + void updateQuery(String query); + FirewallDictionaryList getFWDictionaryDataById(String value); +} + diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/GroupPolicyScopeListDao.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/GroupPolicyScopeListDao.java new file mode 100644 index 000000000..fdab28a0f --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/GroupPolicyScopeListDao.java @@ -0,0 +1,34 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.dao; + +import java.util.List; + +import org.openecomp.policy.rest.jpa.GroupPolicyScopeList; + +public interface GroupPolicyScopeListDao{ + List getGroupPolicyScopeListData(); + List getGroupPolicyScopeListDataByName(); + void Save(GroupPolicyScopeList attribute); + void delete(GroupPolicyScopeList attribute); + void update(GroupPolicyScopeList attribute); + List CheckDuplicateEntry(String value); +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/MicroServiceConfigNameDao.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/MicroServiceConfigNameDao.java new file mode 100644 index 000000000..f0321031c --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/MicroServiceConfigNameDao.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.dao; + +import java.util.List; + +import org.openecomp.policy.rest.jpa.MicroServiceConfigName; + +public interface MicroServiceConfigNameDao { + List getMicroServiceConfigNameData(); + List getMSConfigDataByName(); + void Save(MicroServiceConfigName microServiceConfigName); + void delete(MicroServiceConfigName microServiceConfigName); + void update(MicroServiceConfigName microServiceConfigName); +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/MicroServiceLocationDao.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/MicroServiceLocationDao.java new file mode 100644 index 000000000..fdb9c559e --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/MicroServiceLocationDao.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.dao; + +import java.util.List; + +import org.openecomp.policy.rest.jpa.MicroServiceLocation; + +public interface MicroServiceLocationDao { + List getMicroServiceLocationData(); + List getMSLocationDataByName(); + void Save(MicroServiceLocation microServiceLocation); + void delete(MicroServiceLocation microServiceLocation); + void update(MicroServiceLocation microServiceLocation); +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/MicroServiceModelsDao.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/MicroServiceModelsDao.java new file mode 100644 index 000000000..0a56edd2c --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/MicroServiceModelsDao.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.dao; + +import java.util.List; + +import org.openecomp.policy.rest.jpa.MicroServiceModels; + +public interface MicroServiceModelsDao { + List getMicroServiceModelsData(); + List getMSModelsDataByName(); + void Save(MicroServiceModels microServiceModels); + void delete(MicroServiceModels microServiceModels); + void update(MicroServiceModels microServiceModels); +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/PEPOptionsDao.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/PEPOptionsDao.java new file mode 100644 index 000000000..d1bbf2a1a --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/PEPOptionsDao.java @@ -0,0 +1,35 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.dao; + +import java.util.List; + +import org.openecomp.policy.rest.jpa.PEPOptions; + + + +public interface PEPOptionsDao { + List getPEPOptionsData(); + List getPEPOptionsDataByName(); + void Save(PEPOptions pepOptions); + void delete(PEPOptions pepOptions); + void update(PEPOptions pepOptions); +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/PolicyScopeClosedLoopDao.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/PolicyScopeClosedLoopDao.java new file mode 100644 index 000000000..7730adacb --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/PolicyScopeClosedLoopDao.java @@ -0,0 +1,34 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.dao; + +import java.util.List; + +import org.openecomp.policy.rest.jpa.PolicyScopeClosedLoop; + +public interface PolicyScopeClosedLoopDao { + List getPolicyScopeClosedLoopData(); + List getPolicyScopeClosedLoopDataByName(); + void Save(PolicyScopeClosedLoop attribute); + void delete(PolicyScopeClosedLoop attribute); + void update(PolicyScopeClosedLoop attribute); + List CheckDuplicateEntry(String value); +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/PolicyScopeResourceDao.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/PolicyScopeResourceDao.java new file mode 100644 index 000000000..4ff88fed8 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/PolicyScopeResourceDao.java @@ -0,0 +1,34 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.dao; + +import java.util.List; + +import org.openecomp.policy.rest.jpa.PolicyScopeResource; + +public interface PolicyScopeResourceDao { + List getPolicyScopeResourceData(); + List getPolicyScopeResourceDataByName(); + void Save(PolicyScopeResource attribute); + void delete(PolicyScopeResource attribute); + void update(PolicyScopeResource attribute); + List CheckDuplicateEntry(String value); +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/PolicyScopeServiceDao.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/PolicyScopeServiceDao.java new file mode 100644 index 000000000..2a5c8c565 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/PolicyScopeServiceDao.java @@ -0,0 +1,34 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.dao; + +import java.util.List; + +import org.openecomp.policy.rest.jpa.PolicyScopeService; + +public interface PolicyScopeServiceDao { + List getPolicyScopeServiceData(); + List getPolicyScopeServiceDataByName(); + void Save(PolicyScopeService attribute); + void delete(PolicyScopeService attribute); + void update(PolicyScopeService attribute); + List CheckDuplicateEntry(String value); +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/PolicyScopeTypeDao.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/PolicyScopeTypeDao.java new file mode 100644 index 000000000..e49f84cec --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/PolicyScopeTypeDao.java @@ -0,0 +1,34 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.dao; + +import java.util.List; + +import org.openecomp.policy.rest.jpa.PolicyScopeType; + +public interface PolicyScopeTypeDao { + List getPolicyScopeTypeData(); + List getPolicyScopeTypeDataByName(); + void Save(PolicyScopeType attribute); + void delete(PolicyScopeType attribute); + void update(PolicyScopeType attribute); + List CheckDuplicateEntry(String value); +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/PortListDao.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/PortListDao.java new file mode 100644 index 000000000..461387f4a --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/PortListDao.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.dao; + +import java.util.List; + +import org.openecomp.policy.rest.jpa.PortList; + +public interface PortListDao { + List getPortListData(); + List getPortListDataByName(); + void Save(PortList portList); + void delete(PortList portList); + void update(PortList portList); +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/PrefixListDao.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/PrefixListDao.java new file mode 100644 index 000000000..29571dddb --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/PrefixListDao.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.dao; + +import java.util.List; + +import org.openecomp.policy.rest.jpa.PREFIXLIST; + +public interface PrefixListDao { + List getPREFIXLISTData(); + List getPrefixListDataByName(); + void Save(PREFIXLIST prefixList); + void delete(PREFIXLIST prefixList); + void update(PREFIXLIST prefixList); +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/ProtocolListDao.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/ProtocolListDao.java new file mode 100644 index 000000000..11956ee94 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/ProtocolListDao.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.dao; + +import java.util.List; + +import org.openecomp.policy.rest.jpa.ProtocolList; + +public interface ProtocolListDao { + List getProtocolListData(); + List getProtocolListDataByName(); + void Save(ProtocolList protocolList); + void delete(ProtocolList protocolList); + void update(ProtocolList protocolList); +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/RiskTypeDao.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/RiskTypeDao.java new file mode 100644 index 000000000..6c14928d8 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/RiskTypeDao.java @@ -0,0 +1,34 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.dao; + +import java.util.List; + +import org.openecomp.policy.rest.jpa.RiskType; + +public interface RiskTypeDao { + List getRiskName(); + List getRiskTypeDataByName(); + void Save(RiskType riskName); + void delete(RiskType riskName); + void update(RiskType riskName); + +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/SafePolicyWarningDao.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/SafePolicyWarningDao.java new file mode 100644 index 000000000..3812f9470 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/SafePolicyWarningDao.java @@ -0,0 +1,34 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.dao; + +import java.util.List; + +import org.openecomp.policy.rest.jpa.SafePolicyWarning; + +public interface SafePolicyWarningDao{ + List getSafePolicyWarningData(); + List getSafePolicyWarningDataByName(); + void Save(SafePolicyWarning attribute); + void delete(SafePolicyWarning attribute); + void update(SafePolicyWarning attribute); + SafePolicyWarning getSafePolicyWarningDataById(String riskType); +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/SecurityZoneDao.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/SecurityZoneDao.java new file mode 100644 index 000000000..4367023b5 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/SecurityZoneDao.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.dao; + +import java.util.List; + +import org.openecomp.policy.rest.jpa.SecurityZone; + +public interface SecurityZoneDao { + List getSecurityZoneData(); + List getSecurityZoneDataByName(); + void Save(SecurityZone securityZone); + void delete(SecurityZone securityZone); + void update(SecurityZone securityZone); +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/ServiceDictionaryDao.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/ServiceDictionaryDao.java new file mode 100644 index 000000000..a756f3234 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/ServiceDictionaryDao.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.dao; + +import java.util.List; + +import org.openecomp.policy.rest.jpa.ClosedLoopD2Services; + +public interface ServiceDictionaryDao { + List getClosedLoopD2ServicesData(); + List getCLServiceDictDataByName(); + void Save(ClosedLoopD2Services closedLoopD2Services); + void delete(ClosedLoopD2Services closedLoopD2Services); + void update(ClosedLoopD2Services closedLoopD2Services); +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/ServiceGroupDao.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/ServiceGroupDao.java new file mode 100644 index 000000000..678c6426a --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/ServiceGroupDao.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.dao; + +import java.util.List; + +import org.openecomp.policy.rest.jpa.GroupServiceList; + +public interface ServiceGroupDao { + List getGroupServiceListData(); + List getGroupServiceDataByName(); + void Save(GroupServiceList groupServiceList); + void delete(GroupServiceList groupServiceList); + void update(GroupServiceList groupServiceList); +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/ServiceListDao.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/ServiceListDao.java new file mode 100644 index 000000000..116f9cb17 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/ServiceListDao.java @@ -0,0 +1,34 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.dao; + +import java.util.List; + +import org.openecomp.policy.rest.jpa.ServiceList; + + +public interface ServiceListDao { + List getServiceListData(); + List getServiceListDataByName(); + void Save(ServiceList serviceList); + void delete(ServiceList serviceList); + void update(ServiceList serviceList); +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/SiteDictionaryDao.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/SiteDictionaryDao.java new file mode 100644 index 000000000..21cae69b9 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/SiteDictionaryDao.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.dao; + +import java.util.List; + +import org.openecomp.policy.rest.jpa.ClosedLoopSite; + +public interface SiteDictionaryDao { + List getClosedLoopSiteData(); + List getCLSiteDataByName(); + void Save(ClosedLoopSite closedLoopSite); + void delete(ClosedLoopSite closedLoopSite); + void update(ClosedLoopSite closedLoopSite); +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/TermListDao.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/TermListDao.java new file mode 100644 index 000000000..c2c81cfd8 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/TermListDao.java @@ -0,0 +1,34 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.dao; + +import java.util.List; + +import org.openecomp.policy.rest.jpa.TermList; + +public interface TermListDao { + List getTermListData(); + List getTermListDataByName(); + void Save(TermList termList); + void delete(TermList termList); + void update(TermList termList); + TermList getTermListValueByName(String name); +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/UserInfoDao.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/UserInfoDao.java new file mode 100644 index 000000000..a144a463f --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/UserInfoDao.java @@ -0,0 +1,32 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.dao; + +import java.util.List; + +import org.openecomp.policy.rest.jpa.UserInfo; + +public interface UserInfoDao { + void save(UserInfo userInfo); + List getUserInfo(); + UserInfo getUserInfoByLoginId(String loginid); + String getUserName(String loginid); +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/VNFTypeDao.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/VNFTypeDao.java new file mode 100644 index 000000000..ff68a4065 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/VNFTypeDao.java @@ -0,0 +1,34 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.dao; + +import java.util.List; + +import org.openecomp.policy.rest.jpa.VNFType; + +public interface VNFTypeDao { + List getVNFTypeData(); + List getVNFTypeDataByName(); + void Save(VNFType vnfType); + void delete(VNFType vnfType); + void update(VNFType vnfType); + +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/VSCLActionDao.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/VSCLActionDao.java new file mode 100644 index 000000000..3d0245555 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/VSCLActionDao.java @@ -0,0 +1,35 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.dao; + +import java.util.List; + +import org.openecomp.policy.rest.jpa.VSCLAction; + + + +public interface VSCLActionDao { + List getVSCLActionData(); + List getVsclActionDataByName(); + void Save(VSCLAction vSCLAction); + void delete(VSCLAction vSCLAction); + void update(VSCLAction vSCLAction); +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/VarbindDictionaryDao.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/VarbindDictionaryDao.java new file mode 100644 index 000000000..f3153f6df --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/VarbindDictionaryDao.java @@ -0,0 +1,34 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.dao; + +import java.util.List; + +import org.openecomp.policy.rest.jpa.VarbindDictionary; + +public interface VarbindDictionaryDao { + List getVarbindDictionaryData(); + List getVarbindEntityByName(String value); + List getVarbindDataByName(); + void Save(VarbindDictionary varbindDictionary); + void delete(VarbindDictionary varbindDictionary); + void update(VarbindDictionary varbindDictionary); +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/ZoneDao.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/ZoneDao.java new file mode 100644 index 000000000..df318e167 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/ZoneDao.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.dao; + +import java.util.List; + +import org.openecomp.policy.rest.jpa.Zone; + +public interface ZoneDao { + List getZoneData(); + List getZoneDataByName(); + void Save(Zone zone); + void delete(Zone zone); + void update(Zone zone); +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/package-info.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/package-info.java new file mode 100644 index 000000000..c9f449f4f --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/dao/package-info.java @@ -0,0 +1,27 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + * + */ +/** + * + */ +package org.openecomp.policy.rest.dao; diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/ActionBodyEntity.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/ActionBodyEntity.java new file mode 100644 index 000000000..d12f6b3e1 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/ActionBodyEntity.java @@ -0,0 +1,198 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.openecomp.policy.rest.jpa; +/* + */ +import java.io.Serializable; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Lob; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; +import javax.persistence.SequenceGenerator; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import javax.persistence.Version; +/* + * The Entity class to persist a policy object Action Body + */ + +import com.fasterxml.jackson.annotation.JsonBackReference; + +@Entity +@Table(name="ActionBodyEntity") +@NamedQueries({ + @NamedQuery(name=" ActionBodyEntity.findAll", query="SELECT e FROM ActionBodyEntity e "), + @NamedQuery(name="ActionBodyEntity.deleteAll", query="DELETE FROM ActionBodyEntity WHERE 1=1") +}) +//@SequenceGenerator(name="seqActBody", initialValue=1, allocationSize=1) + +public class ActionBodyEntity implements Serializable { + private static final long serialVersionUID = 1L; + + @Id + //@GeneratedValue(strategy = GenerationType.SEQUENCE, generator="seqActBody") + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name="actionBodyId") + @JsonBackReference + private long actionBodyId; + + @Column(name="actionBodyName", nullable=false, length=255) + private String actionBodyName = ""; + + @Version + @Column(name="version") + private int version; + + @Lob + @Column(name="actionBody", nullable=false, columnDefinition="TEXT") + private String actionBody = "NoBody"; + + @Column(name="created_by", nullable=false, length=255) + private String createdBy = "guest"; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="created_date", updatable=false) + private Date createdDate; + + @Column(name="modified_by", nullable=false, length=255) + private String modifiedBy = "guest"; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="modified_date", nullable=false) + private Date modifiedDate; + + @Column(name="deleted", nullable=false) + private boolean deleted = false; + + public ActionBodyEntity() { + } + + @PrePersist + public void prePersist() { + Date date = new Date(); + this.createdDate = date; + this.modifiedDate = date; + } + + @PreUpdate + public void preUpdate() { + this.modifiedDate = new Date(); + } + /** + * @return the configurationDataId + */ + public long getActionBodyId() { + return actionBodyId; + } + /** + * @param configurationDataId the configurationDataId to set + */ + public void setActionBodyName(String name) { + this.actionBodyName = name; + } + public String getActionBodyName(){ + return this.actionBodyName; + } + + /** + * @return the actionBody + */ + public String getActionBody() { + return actionBody; + } + /** + * @param configBody the configBody to set + */ + public void setActionBody(String body) { + this.actionBody = body; + } + /** + * @return the createdBy + */ + public String getCreatedBy() { + return createdBy; + } + /** + * @param createdBy the createdBy to set + */ + public void setCreatedBy(String createdBy) { + this.createdBy = createdBy; + } + + /** + * @return the modifiedBy + */ + public String getModifiedBy() { + return modifiedBy; + } + /** + * @param modifiedBy the modifiedBy to set + */ + public void setModifiedBy(String modifiedBy) { + this.modifiedBy = modifiedBy; + } + /** + * @return the modifiedDate + */ + public Date getModifiedDate() { + return modifiedDate; + } + /** + * @param modifiedDate the modifiedDate to set + */ + public void setModifiedDate(Date modifiedDate) { + this.modifiedDate = modifiedDate; + } + /** + * @return the version + */ + public int getVersion() { + return version; + } + /** + * @return the createdDate + */ + public Date getCreatedDate() { + return createdDate; + } + + /** + * @return the deleted + */ + public boolean isDeleted() { + return deleted; + } + + /** + * @param deleted the deleted to set + */ + public void setDeleted(boolean deleted) { + this.deleted = deleted; + } +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/ActionList.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/ActionList.java new file mode 100644 index 000000000..0176c17be --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/ActionList.java @@ -0,0 +1,106 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; +/* + */ +import java.io.Serializable; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.NamedQuery; +import javax.persistence.OrderBy; +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +@Entity +@Table(name="actionlist") +@NamedQuery(name="ActionList.findAll", query="SELECT e FROM ActionList e ") +public class ActionList implements Serializable { + private static final long serialVersionUID = 1L; + + private static String domain; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name="id") + private int id; + + @Column(name="actionname", nullable=false) + @OrderBy("asc") + private String actionName; + + @Column(name="description") + private String description; +/* + @Temporal(TemporalType.TIMESTAMP) + @Column(name="modified_date", nullable=false) + private Date modifiedDate;*/ + + public ActionList() { + + } + public ActionList(String string, String userid) { + this(domain); + + } + public ActionList(String domain) { + + } + + @PrePersist + public void prePersist() { + + } + @PreUpdate + public void preUpdate() { + } + public String getActionName() { + return this.actionName; + } + + public void setActionName(String actionName) { + this.actionName = actionName; + + } + + public String getDescription() { + return this.description; + } + + public void setDescription(String description) { + this.description = description; + } + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/ActionPolicyDict.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/ActionPolicyDict.java new file mode 100644 index 000000000..fa7d2af95 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/ActionPolicyDict.java @@ -0,0 +1,215 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/* + */ +package org.openecomp.policy.rest.jpa; +import java.io.Serializable; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.OrderBy; +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openecomp.policy.rest.XacmlAdminAuthorization; + +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.eelf.PolicyLogger; + +@Entity +@Table(name="ActionPolicyDict") +//@NamedQuery(name="ActionPolicyDict.findAll", query="SELECT e FROM ActionPolicyDict e ") +@NamedQueries({ + @NamedQuery(name="ActionPolicyDict.findAll", query="SELECT e FROM ActionPolicyDict e") +}) +public class ActionPolicyDict implements Serializable { + private static final long serialVersionUID = 1L; + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name="id") + private int id; + + @Column(name="ATTRIBUTE_NAME", nullable=false) + @OrderBy("asc") + private String attributeName; + + @Column(name="Type", nullable=false) + @OrderBy("asc") + private String type; + + @Column(name="URL", nullable=false) + @OrderBy("asc") + private String url; + + @Column(name="Method", nullable=false) + @OrderBy("asc") + private String method; + + @Column(name="Headers", nullable=true) + @OrderBy("asc") + private String header; + + @Column(name="Body", nullable=true) + @OrderBy("asc") + private String body; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="created_date", updatable=false) + private Date createdDate; + + @Column(name="description", nullable=true, length=2048) + private String description; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="modified_date", nullable=false) + private Date modifiedDate; + + @ManyToOne(optional = false) + @JoinColumn(name="created_by") + private UserInfo userCreatedBy; + + @ManyToOne(optional = false) + @JoinColumn(name="modified_by") + private UserInfo userModifiedBy; + + public UserInfo getUserCreatedBy() { + return userCreatedBy; + } + + public void setUserCreatedBy(UserInfo userCreatedBy) { + this.userCreatedBy = userCreatedBy; + } + + public UserInfo getUserModifiedBy() { + return userModifiedBy; + } + + public void setUserModifiedBy(UserInfo userModifiedBy) { + this.userModifiedBy = userModifiedBy; + } + + private static Log logger = LogFactory.getLog(ActionPolicyDict.class); + public ActionPolicyDict() { + + } + + public ActionPolicyDict(String string, String userid) { + this(string); + } + + public ActionPolicyDict(String domain) { + this.type = domain; + } + @PrePersist + public void prePersist() { + Date date = new Date(); + this.createdDate = date; + this.modifiedDate = date; + } + @PreUpdate + public void preUpdate() { + this.modifiedDate = new Date(); + try { + this.userModifiedBy =XacmlAdminAuthorization.getUserId();; + } catch (Exception e) { + logger.error("Exception caused While adding Modified by Role"+e); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "ActionPolicyDict", "Exception caused While adding Modified by Role"); + } + } + public int getId() { + return this.id; + } + public void setId(int id) { + this.id = id; + } + + public Date getCreatedDate() { + return this.createdDate; + } + public void setCreatedDate(Date createdDate) { + this.createdDate = createdDate; + } + public String getDescription() { + return this.description; + } + public void setDescription(String description) { + this.description = description; + } + + public Date getModifiedDate() { + return this.modifiedDate; + } + public void setModifiedDate(Date modifiedDate) { + this.modifiedDate = modifiedDate; + } + public String getType() { + return type; + } + public void setType(String type) { + this.type = type; + } + + public String getUrl() { + return url; + } + public void setUrl(String url) { + this.url = url; + } + public String getMethod() { + return method; + } + public void setMethod(String method) { + this.method = method; + } + public String getHeader() { + return header; + } + public void setHeader(String header) { + this.header = header; + } + + public String getBody() { + return body; + } + public void setBody(String body) { + this.body = body; + } + public String getAttributeName() { + return attributeName; + } + public void setAttributeName(String attributeName) { + this.attributeName = attributeName; + } +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/AddressGroup.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/AddressGroup.java new file mode 100644 index 000000000..6418d6bc5 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/AddressGroup.java @@ -0,0 +1,115 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; +/* + */ +import java.io.Serializable; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.NamedQuery; +import javax.persistence.OrderBy; +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; +import javax.persistence.Table; + +@Entity +@Table(name="AddressGroup") +@NamedQuery(name="AddressGroup.findAll", query="SELECT e FROM AddressGroup e ") +public class AddressGroup implements Serializable { + private static final long serialVersionUID = 1L; + + private static String domain; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name="id") + private int id; + + @Column(name="name", nullable=false) + @OrderBy("asc") + private String name; + + @Column(name="prefixlist") + private String prefixList; + + + @Column(name="description") + private String description; + + public AddressGroup() { + + } + public AddressGroup(String string, String userid) { + this(domain); + + } + public AddressGroup(String domain) { + + } + + @PrePersist + public void prePersist() { + + } + @PreUpdate + public void preUpdate() { + } + + + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + public String getGroupName() { + return this.name; + } + + public void setGroupName(String serviceName) { + this.name = serviceName; + + } + + public String getPrefixList() { + return this.prefixList; + } + + public void setServiceList(String prefixList) { + this.prefixList = prefixList; + + } + public String getDescription() { + return this.description; + } + + public void setDescription(String description) { + this.description = description; + + } + +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/Attribute.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/Attribute.java new file mode 100644 index 000000000..e79126ae2 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/Attribute.java @@ -0,0 +1,376 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; + +import java.io.Serializable; +import java.util.Date; +import java.util.HashSet; +import java.util.Set; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.NamedQuery; +import javax.persistence.OneToMany; +import javax.persistence.OrderBy; +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import javax.persistence.Transient; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openecomp.policy.rest.XacmlAdminAuthorization; +import org.openecomp.policy.rest.jpa.UserInfo; + +import com.att.research.xacml.api.Identifier; +import com.att.research.xacml.std.IdentifierImpl; +import com.fasterxml.jackson.annotation.JsonBackReference; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonManagedReference; + +/** + * The persistent class for the Attribute database table. + * + */ +@Entity +@Table(name="Attribute") +@NamedQuery(name="Attribute.findAll", query="SELECT a FROM Attribute a order by a.priority asc, a.xacmlId asc") +public class Attribute implements Serializable { + private static final long serialVersionUID = 1L; + + public static String ATTRIBUTE_DESIGNATOR = "Attribute Designator"; + public static String ATTRIBUTE_SELECTOR = "Attribute Selector"; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name="id") + private int id; + + //bi-directional many-to-one association to Category + @ManyToOne + @JoinColumn(name="constraint_type", nullable=true) + @JsonIgnore + private ConstraintType constraintType; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="created_date", updatable=false) + private Date createdDate; + + @Column(name="description", nullable=true, length=2048) + private String description; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="modified_date", nullable=false) + private Date modifiedDate; + + @Column(name="PRIORITY", nullable=true) + @OrderBy("asc") + private String priority; + + @Column(name="ATTRIBUTE_VALUE", nullable=true) + @OrderBy("asc") + private String attributeValue; + + @Column(name="xacml_id", unique = true, nullable=false) + @OrderBy("asc") + private String xacmlId = "urn"; + + //bi-directional many-to-one association to ConstraintValue + @OneToMany(mappedBy="attribute", orphanRemoval=true, cascade=CascadeType.REMOVE) + @JsonIgnore + private Set constraintValues = new HashSet(); + + //bi-directional many-to-one association to Category + @ManyToOne + @JoinColumn(name="category") + @JsonIgnore + private Category categoryBean; + + //bi-directional many-to-one association to Datatype + @ManyToOne + @JoinColumn(name="datatype") + private Datatype datatypeBean; + + @Column(name="is_designator", nullable=false) + @JsonIgnore + private char isDesignator = '1'; + + @Column(name="selector_path", nullable=true, length=2048) + private String selectorPath; + + + + @Transient + private String issuer = null; + + @Transient + private boolean mustBePresent = false; + + @ManyToOne(optional = false) + @JoinColumn(name="created_by") + private UserInfo userCreatedBy; + + @ManyToOne(optional = false) + @JoinColumn(name="modified_by") + private UserInfo userModifiedBy; + + public UserInfo getUserCreatedBy() { + return userCreatedBy; + } + + public void setUserCreatedBy(UserInfo userCreatedBy) { + this.userCreatedBy = userCreatedBy; + } + + public UserInfo getUserModifiedBy() { + return userModifiedBy; + } + + public void setUserModifiedBy(UserInfo userModifiedBy) { + this.userModifiedBy = userModifiedBy; + } + + private static Log logger = LogFactory.getLog(Attribute.class); + public Attribute() { + } + + public Attribute(String domain) { + this.xacmlId = domain; + } + + public Attribute(String domain, String user) { + this(domain); + } + + public Attribute(Attribute copy, String user) { + this(copy.getXacmlId() + ":(0)", user); + this.constraintType = copy.getConstraintType(); + this.categoryBean = copy.getCategoryBean(); + this.datatypeBean = copy.getDatatypeBean(); + this.description = copy.getDescription(); + for (ConstraintValue value : copy.getConstraintValues()) { + ConstraintValue newValue = new ConstraintValue(value); + newValue.setAttribute(this); + this.addConstraintValue(newValue); + } + } + + @PrePersist + public void prePersist() { + Date date = new Date(); + this.createdDate = date; + this.modifiedDate = date; + } + + @PreUpdate + public void preUpdate() { + this.modifiedDate = new Date(); + try { + this.userModifiedBy = XacmlAdminAuthorization.getUserId(); + } catch (Exception e) { + logger.error("Exception caused While adding Modified by Role"+e); + // TODO:EELF Cleanup - Remove logger + //PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "Attribute", "Exception caused While adding Modified by Role"); + } + } + + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + + public ConstraintType getConstraintType() { + return this.constraintType; + } + + public void setConstraintType(ConstraintType constraintType) { + this.constraintType = constraintType; + } + + public Date getCreatedDate() { + return this.createdDate; + } + + public void setCreatedDate(Date createdDate) { + this.createdDate = createdDate; + } + + public String getDescription() { + return this.description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Date getModifiedDate() { + return this.modifiedDate; + } + + public void setModifiedDate(Date modifiedDate) { + this.modifiedDate = modifiedDate; + } + + public String getXacmlId() { + return this.xacmlId; + } + +/* @Transient + public Identifier getXacmlIdentifier() { + return new IdentifierImpl(this.xacmlId); + }*/ + + public void setXacmlId(String xacmlId) { + this.xacmlId = xacmlId; + } + + public Set getConstraintValues() { + return this.constraintValues; + } + + public void setConstraintValues(Set constraintValues) { + for (ConstraintValue value : this.constraintValues) { + value.setAttribute(this); + } + this.constraintValues = constraintValues; + } + + public ConstraintValue addConstraintValue(ConstraintValue constraintValue) { + if (this.constraintValues == null) { + this.constraintValues = new HashSet(); + } + this.constraintValues.add(constraintValue); + constraintValue.setAttribute(this); + + return constraintValue; + } + + public ConstraintValue removeConstraintValue(ConstraintValue constraintValue) { + this.constraintValues.remove(constraintValue); + constraintValue.setAttribute(null); + + return constraintValue; + } + + public void removeAllConstraintValues() { + if (this.constraintValues == null) { + return; + } + for (ConstraintValue value : this.constraintValues) { + value.setAttribute(null); + } + this.constraintValues.clear(); + } + + public Category getCategoryBean() { + return this.categoryBean; + } + + public void setCategoryBean(Category categoryBean) { + this.categoryBean = categoryBean; + } + + public Datatype getDatatypeBean() { + return this.datatypeBean; + } + + public void setDatatypeBean(Datatype datatypeBean) { + this.datatypeBean = datatypeBean; + } + + public char getIsDesignator() { + return this.isDesignator; + } + + public void setIsDesignator(char is) { + this.isDesignator = is; + } + + public String getSelectorPath() { + return this.selectorPath; + } + + public void setSelectorPath(String path) { + this.selectorPath = path; + } + + @Transient + public String getIssuer() { + return issuer; + } + + @Transient + public void setIssuer(String issuer) { + this.issuer = issuer; + } + + @Transient + public boolean isMustBePresent() { + return mustBePresent; + } + + @Transient + public void setMustBePresent(boolean mustBePresent) { + this.mustBePresent = mustBePresent; + } + + @Transient + public boolean isDesignator() { + return (this.isDesignator == '1'); + } + + @Transient + public void setIsDesignator(boolean is) { + if (is) { + this.isDesignator = '1'; + } else { + this.isDesignator = '0'; + } + } + + public String getPriority() { + return priority; + } + + public void setPriority(String priority) { + this.priority = priority; + } + + public String getAttributeValue() { + return attributeValue; + } + + public void setAttributeValue(String attributeValue) { + this.attributeValue = attributeValue; + } +} + diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/AttributeAssignment.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/AttributeAssignment.java new file mode 100644 index 000000000..1e81213d3 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/AttributeAssignment.java @@ -0,0 +1,93 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.openecomp.policy.rest.jpa; + +import java.io.Serializable; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.ManyToOne; +import javax.persistence.NamedQuery; +import javax.persistence.Table; + + +/** + * The persistent class for the ObadviceExpressions database table. + * + */ +@Entity +@Table(name="AttributeAssignment") +@NamedQuery(name="AttributeAssignment.findAll", query="SELECT a FROM AttributeAssignment a") +public class AttributeAssignment implements Serializable { + private static final long serialVersionUID = 1L; + + public static final String EXPRESSION_APPLY = "Apply"; + public static final String EXPRESSION_SELECTOR = "AttributeSelector"; + public static final String EXPRESSION_VALUE = "AttributeValue"; + public static final String EXPRESSION_FUNCTION = "Function"; + public static final String EXPRESSION_REFERENCE = "VarableReference"; + public static final String EXPRESSION_DESIGNATOR = "AttributeDesignator"; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name="id") + private int id; + + @Column(name="attribute_id") + private int attributeId; + + //bi-directional many-to-one association to Obadvice + @Column(name="expression", nullable=false) + private String expression; + + //bi-directional many-to-one association to Obadvice + @ManyToOne + private Obadvice obadvice; + + public AttributeAssignment() { + } + + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + + public int getAttributeId() { + return this.attributeId; + } + + public void setAttributeId(int attributeId) { + this.attributeId = attributeId; + } + + public String getExpression() { + return expression; + } + + public void setExpression(String expression) { + this.expression = expression; + } +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/BRMSParamTemplate.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/BRMSParamTemplate.java new file mode 100644 index 000000000..54661de0c --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/BRMSParamTemplate.java @@ -0,0 +1,142 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; + +import java.io.Serializable; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.Lob; +import javax.persistence.ManyToOne; +import javax.persistence.NamedQuery; +import javax.persistence.OrderBy; +import javax.persistence.PrePersist; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +import org.openecomp.policy.rest.jpa.UserInfo; + +/* + * JPA for the BRMS Param Template. + * + * @version: 0.1 + */ + + +@Entity +@Table(name="BRMSParamTemplate") +@NamedQuery(name="BRMSParamTemplate.findAll", query="SELECT b FROM BRMSParamTemplate b ") +public class BRMSParamTemplate implements Serializable{ + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name="id") + private int id; + + @Column(name="param_template_name", nullable=false, unique=true) + @OrderBy("asc") + private String ruleName; + + @Lob + @Column(name="rule",nullable=false) + private String rule; + + @Column(name="description", nullable=true, length=2048) + private String description; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="created_date", updatable=false) + private Date createdDate; + + + @ManyToOne(optional = false) + @JoinColumn(name="created_by") + private UserInfo userCreatedBy; + + public UserInfo getUserCreatedBy() { + return userCreatedBy; + } + + public void setUserCreatedBy(UserInfo userCreatedBy) { + this.userCreatedBy = userCreatedBy; + } + + public BRMSParamTemplate(){ + } + + public BRMSParamTemplate(String userid){ + + } + + @PrePersist + public void prePersist() { + Date date = new Date(); + this.createdDate = date; + } + + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + + + public Date getCreatedDate() { + return this.createdDate; + } + + public void setCreatedDate(Date createdDate) { + this.createdDate = createdDate; + } + + public String getDescription() { + return this.description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getRule(){ + return this.rule; + } + + public void setRule(String rule){ + this.rule = rule; + } + + public String getRuleName(){ + return this.ruleName; + } + + public void setRuleName(String ruleName){ + this.ruleName = ruleName; + } +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/Category.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/Category.java new file mode 100644 index 000000000..abc06879d --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/Category.java @@ -0,0 +1,219 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; + +import java.io.Serializable; +import java.util.HashSet; +import java.util.Set; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.NamedQuery; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.persistence.Transient; + +import com.att.research.xacml.api.Identifier; +import com.att.research.xacml.api.XACML3; +import com.att.research.xacml.std.IdentifierImpl; +import com.fasterxml.jackson.annotation.JsonBackReference; +import com.fasterxml.jackson.annotation.JsonIgnore; + + +/** + * The persistent class for the Categories database table. + * + */ +@Entity +@Table(name="Category") +@NamedQuery(name="Category.findAll", query="SELECT c FROM Category c") +public class Category implements Serializable { + private static final long serialVersionUID = 1L; + + public static final char STANDARD = 'S'; + public static final char CUSTOM = 'C'; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name="id") + private int id; + + @Column(name="grouping", nullable=false, length=64) + private String grouping; + + @Column(name="is_standard", nullable=false) + private char isStandard; + + @Column(name="xacml_id", nullable=false, unique=true, length=255) + private String xacmlId; + + @Column(name="short_name", nullable=false, length=64) + private String shortName; + + //bi-directional many-to-one association to Attribute + @OneToMany(mappedBy="categoryBean") + @JsonBackReference + private Set attributes = new HashSet<>(); + + public Category() { + this.xacmlId = XACML3.ID_SUBJECT_CATEGORY_ACCESS_SUBJECT.stringValue(); + this.grouping = "subject"; + this.isStandard = Category.STANDARD; + this.shortName = "subject"; + } + + public Category(Identifier cat, String grouping, char isStandard) { + if (cat != null) { + this.xacmlId = cat.stringValue(); + } + this.isStandard = isStandard; + if (grouping != null) { + this.grouping = grouping; + } else { + this.grouping = Category.extractGrouping(this.xacmlId); + } + } + + public Category(Identifier cat, String grouping) { + this(cat, grouping, Category.STANDARD); + } + + public Category(Identifier cat, char standard) { + this(cat, null, standard); + } + + public Category(Identifier cat) { + this(cat, Category.STANDARD); + } + + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + + public String getGrouping() { + return this.grouping; + } + + public void setGrouping(String grouping) { + this.grouping = grouping; + } + + public char getIsStandard() { + return this.isStandard; + } + + public void setIsStandard(char isStandard) { + this.isStandard = isStandard; + } + + public String getXacmlId() { + return this.xacmlId; + } + + public void setXacmlId(String xacmlId) { + this.xacmlId = xacmlId; + } + + public String getShortName() { + return this.shortName; + } + + public void setShortName(String shortName) { + this.shortName = shortName; + } + + public Set getAttributes() { + return this.attributes; + } + + public void setAttributes(Set attributes) { + this.attributes = attributes; + } + + public Attribute addAttribute(Attribute attribute) { + getAttributes().add(attribute); + attribute.setCategoryBean(this); + + return attribute; + } + + public Attribute removeAttribute(Attribute attribute) { + getAttributes().remove(attribute); + attribute.setCategoryBean(null); + + return attribute; + } + + @Transient + public boolean isStandard() { + return (this.isStandard == Category.STANDARD); + } + + @Transient + public boolean isCustom() { + return (this.isStandard == Category.CUSTOM); + } + + @Transient + public static String extractGrouping(String xacmlId) { + if (xacmlId == null) { + return null; + } + if (xacmlId.matches(".*:attribute\\-category:.*")) { + String[] parts = xacmlId.split("[:]"); + if (parts != null && parts.length > 0) { + return parts[parts.length - 1]; + } + } else if (xacmlId.matches(".*:[a-zA-Z]+[\\-]category:.*")) { + String[] parts = xacmlId.split("[:]"); + if (parts != null && parts.length > 0) { + for (String part : parts) { + int index = part.indexOf("-category"); + if (index > 0) { + return part.substring(0, index); + } + } + } + } + return null; + } + + @Transient + public Identifier getIdentifer() { + return new IdentifierImpl(this.xacmlId); + } + + @Transient + @Override + public String toString() { + return "Category [id=" + id + ", grouping=" + grouping + + ", isStandard=" + isStandard + ", xacmlId=" + xacmlId + + ", attributes=" + attributes + "]"; + } + +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/ClosedLoopD2Services.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/ClosedLoopD2Services.java new file mode 100644 index 000000000..408190ac9 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/ClosedLoopD2Services.java @@ -0,0 +1,177 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; +/* + * + */ +import java.io.Serializable; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.NamedQuery; +import javax.persistence.OrderBy; +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openecomp.policy.rest.XacmlAdminAuthorization; + +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.eelf.PolicyLogger; + + +@Entity +@Table(name = "ClosedLoopD2Services") +@NamedQuery(name="ClosedLoopD2Services.findAll", query="SELECT c FROM ClosedLoopD2Services c ") +public class ClosedLoopD2Services implements Serializable{ + private static final long serialVersionUID = 1L; + + private static String domain; + + + @Id + @Column(name ="id") + @GeneratedValue(strategy = GenerationType.AUTO) + private int id; + + @Column(name="service_Name", nullable=false, unique=true) + @OrderBy("asc") + private String serviceName; + + @Column(name="description", nullable=true, length=2048) + private String description; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="created_date", updatable=false) + private Date createdDate; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="modified_date", nullable=false) + private Date modifiedDate; + + @ManyToOne(optional = false) + @JoinColumn(name="created_by") + private UserInfo userCreatedBy; + + @ManyToOne(optional = false) + @JoinColumn(name="modified_by") + private UserInfo userModifiedBy; + + public UserInfo getUserCreatedBy() { + return userCreatedBy; + } + + public void setUserCreatedBy(UserInfo userCreatedBy) { + this.userCreatedBy = userCreatedBy; + } + + public UserInfo getUserModifiedBy() { + return userModifiedBy; + } + + public void setUserModifiedBy(UserInfo userModifiedBy) { + this.userModifiedBy = userModifiedBy; + } + + private static Log logger = LogFactory.getLog(ClosedLoopD2Services.class); + + public ClosedLoopD2Services(){ + + } + + public ClosedLoopD2Services(String string, String userid) { + this(domain); + } + + public ClosedLoopD2Services(String domain) { + this.serviceName = domain; + } + + @PrePersist + public void prePersist() { + Date date = new Date(); + this.createdDate = date; + this.modifiedDate = date; + } + + @PreUpdate + public void preUpdate() { + this.modifiedDate = new Date(); + try { + this.userModifiedBy = XacmlAdminAuthorization.getUserId();; + } catch (Exception e) { + logger.error("Exception caused While adding Modified by Role"+e); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "ClosedLoopD2Services", "Exception caused While adding Modified by Role"); + } + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getServiceName() { + return serviceName; + } + + public void setServiceName(String serviceName) { + this.serviceName = serviceName; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Date getCreatedDate() { + return createdDate; + } + + public void setCreatedDate(Date createdDate) { + this.createdDate = createdDate; + } + + public Date getModifiedDate() { + return modifiedDate; + } + + public void setModifiedDate(Date modifiedDate) { + this.modifiedDate = modifiedDate; + } + +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/ClosedLoopSite.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/ClosedLoopSite.java new file mode 100644 index 000000000..b32091307 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/ClosedLoopSite.java @@ -0,0 +1,178 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; + +/* + * + */ +import java.io.Serializable; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.NamedQuery; +import javax.persistence.OrderBy; +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openecomp.policy.rest.XacmlAdminAuthorization; + +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.eelf.PolicyLogger; + + +@Entity +@Table(name = "ClosedLoopSite") +@NamedQuery(name="ClosedLoopSite.findAll", query="SELECT c FROM ClosedLoopSite c ") +public class ClosedLoopSite implements Serializable{ + private static final long serialVersionUID = 1L; + + private static String domain; + + + @Id + @Column(name ="id") + @GeneratedValue(strategy = GenerationType.AUTO) + private int id; + + @Column(name="site_Name", nullable=false, unique=true) + @OrderBy("asc") + private String siteName; + + @Column(name="description", nullable=true, length=2048) + private String description; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="created_date", updatable=false) + private Date createdDate; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="modified_date", nullable=false) + private Date modifiedDate; + + @ManyToOne(optional = false) + @JoinColumn(name="created_by") + private UserInfo userCreatedBy; + + @ManyToOne(optional = false) + @JoinColumn(name="modified_by") + private UserInfo userModifiedBy; + + public UserInfo getUserCreatedBy() { + return userCreatedBy; + } + + public void setUserCreatedBy(UserInfo userCreatedBy) { + this.userCreatedBy = userCreatedBy; + } + + public UserInfo getUserModifiedBy() { + return userModifiedBy; + } + + public void setUserModifiedBy(UserInfo userModifiedBy) { + this.userModifiedBy = userModifiedBy; + } + + private static Log logger = LogFactory.getLog(ClosedLoopSite.class); + + public ClosedLoopSite(){ + + } + + public ClosedLoopSite(String string, String userid) { + this(domain); + } + + public ClosedLoopSite(String domain) { + this.siteName = domain; + } + + @PrePersist + public void prePersist() { + Date date = new Date(); + this.createdDate = date; + this.modifiedDate = date; + } + + @PreUpdate + public void preUpdate() { + this.modifiedDate = new Date(); + try { + this.userModifiedBy = XacmlAdminAuthorization.getUserId();; + } catch (Exception e) { + logger.error("Exception caused While adding Modified by Role"+e); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "ClosedLoopSite", "Exception caused While adding Modified by Role"); + } + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getSiteName() { + return siteName; + } + + public void setSiteName(String siteName) { + this.siteName = siteName; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Date getCreatedDate() { + return createdDate; + } + + public void setCreatedDate(Date createdDate) { + this.createdDate = createdDate; + } + + public Date getModifiedDate() { + return modifiedDate; + } + + public void setModifiedDate(Date modifiedDate) { + this.modifiedDate = modifiedDate; + } + +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/ConfigurationDataEntity.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/ConfigurationDataEntity.java new file mode 100644 index 000000000..71a6d6fb7 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/ConfigurationDataEntity.java @@ -0,0 +1,227 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; +/* + */ +import java.io.Serializable; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Lob; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; +import javax.persistence.SequenceGenerator; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import javax.persistence.Version; +/* + * The Entity class to persist a policy object configuration data + */ + +import com.fasterxml.jackson.annotation.JsonBackReference; + +@Entity +@Table(name="ConfigurationDataEntity") +@NamedQueries({ + @NamedQuery(name="ConfigurationDataEntity.findAll", query="SELECT e FROM ConfigurationDataEntity e "), + @NamedQuery(name="ConfigurationDataEntity.deleteAll", query="DELETE FROM ConfigurationDataEntity WHERE 1=1") +}) +//@SequenceGenerator(name="seqConfig", initialValue=1, allocationSize=1) + +public class ConfigurationDataEntity implements Serializable { + private static final long serialVersionUID = 1L; + + @Id + //@GeneratedValue(strategy = GenerationType.SEQUENCE, generator="seqConfig") + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name="configurationDataId") + @JsonBackReference + private long configurationDataId; + + @Column(name="configurationName", nullable=false, length=255) + private String configurationName = ""; + + @Version + @Column(name="version") + private int version; + + @Column(name="configType", nullable=false, length=255) + private String configType = "NoType"; + + @Lob + @Column(name="configBody", nullable=false, columnDefinition="TEXT") + private String configBody = "NoBody"; + + @Column(name="created_by", nullable=false, length=255) + private String createdBy = "guest"; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="created_date", updatable=false) + private Date createdDate; + + @Column(name="description", nullable=false, length=2048) + private String description = "NoDescription"; + + @Column(name="modified_by", nullable=false, length=255) + private String modifiedBy = "guest"; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="modified_date", nullable=false) + private Date modifiedDate; + + @Column(name="deleted", nullable=false) + private boolean deleted = false; + + public ConfigurationDataEntity() { + } + + @PrePersist + public void prePersist() { + Date date = new Date(); + this.createdDate = date; + this.modifiedDate = date; + } + + @PreUpdate + public void preUpdate() { + this.modifiedDate = new Date(); + } + /** + * @return the configurationDataId + */ + public long getConfigurationDataId() { + return configurationDataId; + } + /** + * @param configurationDataId the configurationDataId to set + */ + public void setConfigurationName(String configurationName) { + this.configurationName = configurationName; + } + public String getConfigurationName(){ + return this.configurationName; + } + /** + * @return the configType + */ + public String getConfigType() { + return configType; + } + /** + * @param configType the configType to set + */ + public void setConfigType(String configType) { + this.configType = configType; + } + /** + * @return the configBody + */ + public String getConfigBody() { + return configBody; + } + /** + * @param configBody the configBody to set + */ + public void setConfigBody(String configBody) { + this.configBody = configBody; + } + /** + * @return the createdBy + */ + public String getCreatedBy() { + return createdBy; + } + /** + * @param createdBy the createdBy to set + */ + public void setCreatedBy(String createdBy) { + this.createdBy = createdBy; + } + /** + * @return the description + */ + public String getDescription() { + return description; + } + /** + * @param description the description to set + */ + public void setDescription(String description) { + this.description = description; + } + /** + * @return the modifiedBy + */ + public String getModifiedBy() { + return modifiedBy; + } + /** + * @param modifiedBy the modifiedBy to set + */ + public void setModifiedBy(String modifiedBy) { + this.modifiedBy = modifiedBy; + } + /** + * @return the modifiedDate + */ + public Date getModifiedDate() { + return modifiedDate; + } + /** + * @param modifiedDate the modifiedDate to set + */ + public void setModifiedDate(Date modifiedDate) { + this.modifiedDate = modifiedDate; + } + /** + * @return the version + */ + public int getVersion() { + return version; + } + /** + * @return the createdDate + */ + public Date getCreatedDate() { + return createdDate; + } + + /** + * @return the deleted + */ + public boolean isDeleted() { + return deleted; + } + + /** + * @param deleted the deleted to set + */ + public void setDeleted(boolean deleted) { + this.deleted = deleted; + } +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/ConstraintType.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/ConstraintType.java new file mode 100644 index 000000000..73e053ce7 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/ConstraintType.java @@ -0,0 +1,117 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.NamedQuery; +import javax.persistence.OneToMany; +import javax.persistence.Table; + +@Entity +@Table(name="ConstraintType") +@NamedQuery(name="ConstraintType.findAll", query="SELECT a FROM ConstraintType a") +public class ConstraintType implements Serializable { + private static final long serialVersionUID = 1L; + + public static String ENUMERATION_TYPE = "Enumeration"; + public static String RANGE_TYPE = "Range"; + public static String REGEXP_TYPE = "Regular Expression"; + + public static Map defaults = new HashMap(); + static { + defaults.put(ENUMERATION_TYPE, "Enumerate a set of values that the attribute may be set to during policy creation."); + defaults.put(RANGE_TYPE, "Set a range of min and/or max integer/double values the attribute can be set to during policy creation."); + defaults.put(REGEXP_TYPE, "Define a regular expression the attribute must match against during policy creation."); + } + public static final String[] RANGE_TYPES = {"minExclusive", "minInclusive", "maxExclusive", "maxInclusive"}; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name="id") + private int id; + + @Column(name="constraint_type", nullable=false, length=64) + private String constraintType; + + @Column(name="description", nullable=false, length=255) + private String description; + + //bi-directional many-to-one association to Attribute + @OneToMany(mappedBy="constraintType") + private Set attributes = new HashSet<>(); + + public ConstraintType() { + + } + + public ConstraintType(String constraintType) { + this(); + this.constraintType = constraintType; + } + + public ConstraintType(String constraintType, String description) { + this(constraintType); + this.description = description; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getConstraintType() { + return constraintType; + } + + public void setConstraintType(String constraintType) { + this.constraintType = constraintType; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Set getAttributes() { + return attributes; + } + + public void setAttributes(Set attributes) { + this.attributes = attributes; + } + +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/ConstraintValue.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/ConstraintValue.java new file mode 100644 index 000000000..65eb6586a --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/ConstraintValue.java @@ -0,0 +1,116 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; + +import java.io.Serializable; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.NamedQuery; +import javax.persistence.Table; + + +/** + * The persistent class for the ConstraintValues database table. + * + */ +@Entity +@Table(name="ConstraintValues") +@NamedQuery(name="ConstraintValue.findAll", query="SELECT c FROM ConstraintValue c") +public class ConstraintValue implements Serializable { + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name="id") + private int id; + + @Column(name="property") + private String property; + + @Column(name="value") + private String value; + + //bi-directional many-to-one association to Attribute + @ManyToOne + @JoinColumn(name="attribute_id") + private Attribute attribute; + + public ConstraintValue() { + } + + public ConstraintValue(String property, String value) { + this.property = property; + this.value = value; + } + + public ConstraintValue(ConstraintValue value) { + this.property = value.getProperty(); + this.value = value.getValue(); + } + + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + + public String getProperty() { + return this.property; + } + + public void setProperty(String property) { + this.property = property; + } + + public String getValue() { + return this.value; + } + + public void setValue(String value) { + this.value = value; + } + + public Attribute getAttribute() { + return this.attribute; + } + + public void setAttribute(Attribute attribute) { + this.attribute = attribute; + } + + public ConstraintValue clone() { + ConstraintValue constraint = new ConstraintValue(); + + constraint.property = this.property; + constraint.value = this.value; + constraint.attribute = this.attribute; + + return constraint; + } +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/DCAEUsers.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/DCAEUsers.java new file mode 100644 index 000000000..eb0c4cc1b --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/DCAEUsers.java @@ -0,0 +1,103 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; +/* + */ +import java.io.Serializable; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.NamedQuery; +import javax.persistence.OrderBy; +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; +import javax.persistence.Table; + + +@Entity +@Table(name="DCAEUsers") +@NamedQuery(name="DCAEUsers.findAll", query="SELECT e FROM DCAEUsers e ") +public class DCAEUsers implements Serializable { + private static final long serialVersionUID = 1L; + + private static String domain; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name="id") + private int id; + + @Column(name="name", nullable=false) + @OrderBy("asc") + private String name; + + @Column(name="description ") + private String description ; + + + public DCAEUsers() { + + } + public DCAEUsers(String string, String userid) { + this(domain); + + } + public DCAEUsers(String domain) { + + } + + @PrePersist + public void prePersist() { + + } + @PreUpdate + public void preUpdate() { + } + + + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + + } + public String getDescriptionValue() { + return this.description ; + } + + public void setDescriptionValue(String description ) { + this.description = description ; + } + +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/DCAEuuid.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/DCAEuuid.java new file mode 100644 index 000000000..a71921b5e --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/DCAEuuid.java @@ -0,0 +1,103 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; +/* + */ +import java.io.Serializable; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.NamedQuery; +import javax.persistence.OrderBy; +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; +import javax.persistence.Table; + + +@Entity +@Table(name="DCAEuuid") +@NamedQuery(name="DCAEuuid.findAll", query="SELECT e FROM DCAEuuid e ") +public class DCAEuuid implements Serializable { + private static final long serialVersionUID = 1L; + + private static String domain; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name="id") + private int id; + + @Column(name="name", nullable=false) + @OrderBy("asc") + private String name; + + @Column(name="description") + private String description; + + + public DCAEuuid() { + + } + public DCAEuuid(String string, String userid) { + this(domain); + + } + public DCAEuuid(String domain) { + + } + + @PrePersist + public void prePersist() { + + } + @PreUpdate + public void preUpdate() { + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + + } + +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/DatabaseLockEntity.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/DatabaseLockEntity.java new file mode 100644 index 000000000..c24b13a0e --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/DatabaseLockEntity.java @@ -0,0 +1,47 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; + +import java.io.Serializable; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity +@Table(name="DatabaseLockEntity") +public class DatabaseLockEntity implements Serializable { + private static final long serialVersionUID = 1L; + @Id + @Column(name="lock_key") + private int lock_key = 1; + public DatabaseLockEntity(){ + + } + public int getKey(){ + return lock_key; + } + public void setKey(int key){ + this.lock_key = key; + } + +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/Datatype.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/Datatype.java new file mode 100644 index 000000000..b3922f10b --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/Datatype.java @@ -0,0 +1,245 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; + +import java.io.Serializable; +import java.util.HashSet; +import java.util.Set; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.NamedQuery; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.persistence.Transient; + +import com.att.research.xacml.api.Identifier; +import com.att.research.xacml.api.XACML3; +import com.att.research.xacml.std.IdentifierImpl; +import com.fasterxml.jackson.annotation.JsonBackReference; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonManagedReference; + + +/** + * The persistent class for the Datatype database table. + * + */ +@Entity +@Table(name="Datatype") +@NamedQuery(name="Datatype.findAll", query="SELECT d FROM Datatype d") +public class Datatype implements Serializable { + private static final long serialVersionUID = 1L; + + public static final char STANDARD = 'S'; + public static final char CUSTOM = 'C'; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name="id") + private int id; + + @Column(name="is_standard", nullable=false) + private char isStandard; + + @Column(name="xacml_id", nullable=false, unique=true, length=255) + private String xacmlId; + + @Column(name="short_name", nullable=false, length=64) + private String shortName; + + //bi-directional many-to-one association to Attribute + @OneToMany(mappedBy="datatypeBean") + @JsonBackReference + private Set attributes = new HashSet<>(); + + //bi-directional many-to-one association to Attribute + @OneToMany(mappedBy="datatypeBean") + @JsonIgnore + private Set functions = new HashSet<>(); + + //bi-directional many-to-one association to Attribute + @OneToMany(mappedBy="datatypeBean") + @JsonIgnore + private Set arguments = new HashSet<>(); + + public Datatype() { + this.xacmlId = XACML3.ID_DATATYPE_STRING.stringValue(); + this.isStandard = Datatype.STANDARD; + } + + + public Datatype(int id, Datatype dt) { + this.id = id; + this.isStandard = dt.isStandard; + this.xacmlId = dt.xacmlId; + this.shortName = dt.shortName; + // + // Make a copy? + // + this.attributes = new HashSet<>(); + } + + public Datatype(Identifier identifier, char standard) { + if (identifier != null) { + this.xacmlId = identifier.stringValue(); + + } + this.isStandard = standard; + } + + public Datatype(Identifier identifier) { + this(identifier, Datatype.STANDARD); + } + + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + + public char getIsStandard() { + return this.isStandard; + } + + public void setIsStandard(char isStandard) { + this.isStandard = isStandard; + } + + public String getXacmlId() { + return this.xacmlId; + } + + public void setXacmlId(String xacmlId) { + this.xacmlId = xacmlId; + } + + public String getShortName() { + return shortName; + } + + public void setShortName(String shortName) { + this.shortName = shortName; + } + + public Set getAttributes() { + return this.attributes; + } + + public void setAttributes(Set attributes) { + this.attributes = attributes; + } + + public Attribute addAttribute(Attribute attribute) { + getAttributes().add(attribute); + attribute.setDatatypeBean(this); + + return attribute; + } + + public Attribute removeAttribute(Attribute attribute) { + getAttributes().remove(attribute); + attribute.setDatatypeBean(null); + + return attribute; + } + + public Set getFunctions() { + return this.functions; + } + + public void setFunctions(Set functions) { + this.functions = functions; + } + + public FunctionDefinition addFunction(FunctionDefinition function) { + getFunctions().add(function); + function.setDatatypeBean(this); + + return function; + } + + public FunctionDefinition removeAttribute(FunctionDefinition function) { + getFunctions().remove(function); + function.setDatatypeBean(null); + + return function; + } + + public Set getArguments() { + return this.arguments; + } + + public void setArguments(Set argument) { + this.arguments = argument; + } + + public FunctionArgument addArgument(FunctionArgument argument) { + getArguments().add(argument); + argument.setDatatypeBean(this); + + return argument; + } + + public FunctionArgument removeArgument(FunctionArgument argument) { + getArguments().remove(argument); + argument.setDatatypeBean(null); + + return argument; + } + + @Transient + public Identifier getIdentifer() { + return new IdentifierImpl(this.xacmlId); + } + + @Transient + public Identifier getIdentiferByShortName() { + return new IdentifierImpl(this.shortName); + } + + @Transient + public boolean isStandard() { + return (this.isStandard == Datatype.STANDARD); + } + + @Transient + public boolean isCustom() { + return (this.isStandard == Datatype.CUSTOM); + } + + @Transient + @Override + public String toString() { + return "Datatype [id=" + id + ", isStandard=" + isStandard + + ", xacmlId=" + xacmlId + ", shortName=" + shortName + + ", attributes=" + attributes + ", functions=" + functions + + ", arguments=" + arguments + "]"; + + //return "Datatype [shortName=" + shortName + "]"; + } + +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/DecisionSettings.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/DecisionSettings.java new file mode 100644 index 000000000..1d90af679 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/DecisionSettings.java @@ -0,0 +1,245 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; + +import java.io.Serializable; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.NamedQuery; +import javax.persistence.OrderBy; +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import javax.persistence.Transient; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openecomp.policy.rest.XacmlAdminAuthorization; + +import com.att.research.xacml.api.Identifier; +import com.att.research.xacml.std.IdentifierImpl; +import com.fasterxml.jackson.annotation.JsonManagedReference; + +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.eelf.PolicyLogger; + + +@Entity +@Table(name="DecisionSettings") +@NamedQuery(name="DecisionSettings.findAll", query="SELECT a FROM DecisionSettings a order by a.priority asc, a.xacmlId asc") +public class DecisionSettings implements Serializable { + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name="id") + private int id; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="created_date", updatable=false) + private Date createdDate; + + @Column(name="description", nullable=true, length=2048) + private String description; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="modified_date", nullable=false) + private Date modifiedDate; + + @Column(name="PRIORITY", nullable=true) + @OrderBy("asc") + private String priority; + + @Column(name="xacml_id", unique = true, nullable=false) + @OrderBy("asc") + private String xacmlId = "urn"; + + //bi-directional many-to-one association to Datatype + @ManyToOne + @JoinColumn(name="datatype") + private Datatype datatypeBean; + + @Transient + private String issuer = null; + + @Transient + private boolean mustBePresent = false; + + @ManyToOne(optional = false) + @JoinColumn(name="created_by") + private UserInfo userCreatedBy; + + @ManyToOne(optional = false) + @JoinColumn(name="modified_by") + private UserInfo userModifiedBy; + + public UserInfo getUserCreatedBy() { + return userCreatedBy; + } + + public void setUserCreatedBy(UserInfo userCreatedBy) { + this.userCreatedBy = userCreatedBy; + } + + public UserInfo getUserModifiedBy() { + return userModifiedBy; + } + + public void setUserModifiedBy(UserInfo userModifiedBy) { + this.userModifiedBy = userModifiedBy; + } + + private static Log logger = LogFactory.getLog(DecisionSettings.class); + public DecisionSettings() { + } + + public DecisionSettings(String domain) { + this.xacmlId = domain; + } + + public DecisionSettings(String domain, String user) { + this(domain); + } + public DecisionSettings(DecisionSettings copy, String user) { + this(copy.getXacmlId() + ":(0)", user); + this.datatypeBean = copy.getDatatypeBean(); + this.description = copy.getDescription(); + + } + + public String getDecisionSettings(){ + return this.xacmlId; + } + + public String setDecisionSettings(){ + return this.xacmlId = xacmlId; + } + @PrePersist + public void prePersist() { + Date date = new Date(); + this.createdDate = date; + this.modifiedDate = date; + } + + @PreUpdate + public void preUpdate() { + this.modifiedDate = new Date(); + try { + this.userModifiedBy = XacmlAdminAuthorization.getUserId();; + } catch (Exception e) { + logger.error("Exception caused While adding Modified by Role"+e); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "DecisionSettings", "Exception caused While adding Modified by Role"); + } + } + + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + + + public Date getCreatedDate() { + return this.createdDate; + } + + public void setCreatedDate(Date createdDate) { + this.createdDate = createdDate; + } + + public String getDescription() { + return this.description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Date getModifiedDate() { + return this.modifiedDate; + } + + public void setModifiedDate(Date modifiedDate) { + this.modifiedDate = modifiedDate; + } + + public String getXacmlId() { + return this.xacmlId; + } + +/* @Transient + public Identifier getXacmlIdentifier() { + return new IdentifierImpl(this.xacmlId); + }*/ + + public void setXacmlId(String xacmlId) { + this.xacmlId = xacmlId; + } + + public Datatype getDatatypeBean() { + return this.datatypeBean; + } + + public void setDatatypeBean(Datatype datatypeBean) { + this.datatypeBean = datatypeBean; + } + + @Transient + public String getIssuer() { + return issuer; + } + + @Transient + public void setIssuer(String issuer) { + this.issuer = issuer; + } + + @Transient + public boolean isMustBePresent() { + return mustBePresent; + } + + @Transient + public void setMustBePresent(boolean mustBePresent) { + this.mustBePresent = mustBePresent; + } + + public String getPriority() { + return priority; + } + + public void setPriority(String priority) { + this.priority = priority; + } +} + diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/DescriptiveScope.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/DescriptiveScope.java new file mode 100644 index 000000000..9f751f7c0 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/DescriptiveScope.java @@ -0,0 +1,182 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; + +import java.io.Serializable; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.NamedQuery; +import javax.persistence.OrderBy; +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openecomp.policy.rest.XacmlAdminAuthorization; + +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.eelf.PolicyLogger; + + +@Entity +@Table(name = "DescriptiveScope") +@NamedQuery(name = "DescriptiveScope.findAll", query= "Select p from DescriptiveScope p") +public class DescriptiveScope implements Serializable { + private static final long serialVersionUID = 1L; + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "Id") + private int id; + + @Column(name="scopename", nullable=false) + @OrderBy("asc") + private String descriptiveScopeName; + + @Column(name="description", nullable=true, length=2048) + private String description; + + @Column(name="search", nullable=true) + @OrderBy("asc") + private String search; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="created_date", updatable=false) + private Date createdDate; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="modified_date", nullable=false) + private Date modifiedDate; + + @ManyToOne(optional = false) + @JoinColumn(name="created_by") + private UserInfo userCreatedBy; + + @ManyToOne(optional = false) + @JoinColumn(name="modified_by") + private UserInfo userModifiedBy; + + public UserInfo getUserCreatedBy() { + return userCreatedBy; + } + + public void setUserCreatedBy(UserInfo userCreatedBy) { + this.userCreatedBy = userCreatedBy; + } + + public UserInfo getUserModifiedBy() { + return userModifiedBy; + } + + public void setUserModifiedBy(UserInfo userModifiedBy) { + this.userModifiedBy = userModifiedBy; + } + + private static Log logger = LogFactory.getLog(DescriptiveScope.class); + + public DescriptiveScope(){ + + } + + public DescriptiveScope(String string, String userid) { + this(string); + } + + public DescriptiveScope(String domain) { + this.descriptiveScopeName = domain; + } + + @PrePersist + public void prePersist() { + Date date = new Date(); + this.createdDate = date; + this.modifiedDate = date; + } + + @PreUpdate + public void preUpdate() { + this.modifiedDate = new Date(); + try { + this.userModifiedBy =XacmlAdminAuthorization.getUserId();; + } catch (Exception e) { + logger.error("Exception caused While adding Modified by Role"+e); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "DescriptiveScope", "Exception caused While adding Modified by Role"); + } + } + + public int getId() { + return this.id; + } + public void setId(int id) { + this.id = id; + } + + public String getScopeName() { + return descriptiveScopeName; + } + + public void setScopeName(String descriptiveScopeName) { + this.descriptiveScopeName = descriptiveScopeName; + } + + public String getSearch() { + return search; + } + + public void setSearch(String search) { + this.search = search; + } + + public Date getCreatedDate() { + return this.createdDate; + } + + public void setCreatedDate(Date createdDate) { + this.createdDate = createdDate; + } + + public String getDescription() { + return this.description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Date getModifiedDate() { + return this.modifiedDate; + } + + public void setModifiedDate(Date modifiedDate) { + this.modifiedDate = modifiedDate; + } + +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/EcompName.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/EcompName.java new file mode 100644 index 000000000..599e47818 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/EcompName.java @@ -0,0 +1,178 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; +/* + */ +import java.io.Serializable; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.NamedQuery; +import javax.persistence.OrderBy; +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openecomp.policy.rest.XacmlAdminAuthorization; +import org.openecomp.policy.rest.jpa.UserInfo; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonManagedReference; + +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.eelf.PolicyLogger; + + +@Entity +@Table(name="EcompName") +@NamedQuery(name="EcompName.findAll", query="SELECT e FROM EcompName e ") +public class EcompName implements Serializable { + private static final long serialVersionUID = 1L; + + private static String domain; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name="id") + private int id; + + @Column(name="ecomp_Name", nullable=false, unique=true) + @OrderBy("asc") + private String ecompName; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="created_date", updatable=false) + private Date createdDate; + + @Column(name="description", nullable=true, length=2048) + private String description; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="modified_date", nullable=false) + private Date modifiedDate; + + @ManyToOne(optional = false) + @JoinColumn(name="created_by") + private UserInfo userCreatedBy; + + @ManyToOne(optional = false) + @JoinColumn(name="modified_by") + private UserInfo userModifiedBy; + + public UserInfo getUserCreatedBy() { + return userCreatedBy; + } + + public void setUserCreatedBy(UserInfo userCreatedBy) { + this.userCreatedBy = userCreatedBy; + } + + public UserInfo getUserModifiedBy() { + return userModifiedBy; + } + + public void setUserModifiedBy(UserInfo userModifiedBy) { + this.userModifiedBy = userModifiedBy; + } + + private static Log logger = LogFactory.getLog(EcompName.class); + + public EcompName() { + + } + + public EcompName(String string, String userid) { + this(domain); + } + + public EcompName(String domain) { + this.ecompName = domain; + } + + @PrePersist + public void prePersist() { + Date date = new Date(); + this.createdDate = date; + this.modifiedDate = date; + } + + @PreUpdate + public void preUpdate() { + this.modifiedDate = new Date(); + try { + this.userModifiedBy =XacmlAdminAuthorization.getUserId(); + } catch (Exception e) { + logger.error("Exception caused While adding Modified by Role"+e); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "EcompName", "Exception caused While adding Modified by Role"); + } + } + public String getEcompName() { + return this.ecompName; + } + + public void setEcompName(String ecompName) { + this.ecompName = ecompName; + + } + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + + public Date getCreatedDate() { + return this.createdDate; + } + + public void setCreatedDate(Date createdDate) { + this.createdDate = createdDate; + } + + public String getDescription() { + return this.description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Date getModifiedDate() { + return this.modifiedDate; + } + + public void setModifiedDate(Date modifiedDate) { + this.modifiedDate = modifiedDate; + } + +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/EnforcingType.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/EnforcingType.java new file mode 100644 index 000000000..f293bc0cb --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/EnforcingType.java @@ -0,0 +1,96 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; + +import java.io.Serializable; + +import javax.persistence.*; + +/** + * Entity implementation class for Entity: EnforcingType + * + */ +@Entity +@Table(name="EnforcingType") +@NamedQuery(name="EnforcingType.findAll", query="SELECT e FROM EnforcingType e ") +public class EnforcingType implements Serializable { + + + private static final long serialVersionUID = 1L; + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name="id") + private int id; + @Column(name="enforcingType", nullable=false, unique=true) + @OrderBy("asc") + private String enforcingType; + @Column(name="script", nullable=false, length=255) + private String script; + @Column(name="connectionQuery", nullable=false, length=255) + private String connectionQuery; + @Column(name="valueQuery", nullable=false, length=255) + private String valueQuery; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getEnforcingType() { + return enforcingType; + } + + public void setEnforcingType(String enforcingType) { + this.enforcingType = enforcingType; + } + + public String getScript() { + return script; + } + + public void setScript(String script) { + this.script = script; + } + + public String getConnectionQuery() { + return connectionQuery; + } + + public void setConnectionQuery(String connectionQuery) { + this.connectionQuery = connectionQuery; + } + + public String getValueQuery() { + return valueQuery; + } + + public void setValueQuery(String valueQuery) { + this.valueQuery = valueQuery; + } + + public EnforcingType() { + super(); + } + +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/FirewallDictionaryList.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/FirewallDictionaryList.java new file mode 100644 index 000000000..3c47de817 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/FirewallDictionaryList.java @@ -0,0 +1,185 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; + +import java.io.Serializable; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.NamedQuery; +import javax.persistence.OrderBy; +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openecomp.policy.rest.XacmlAdminAuthorization; + +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.eelf.PolicyLogger; + + +@Entity +@Table(name="parentdictionaryitems") +@NamedQuery(name="FirewallDictionaryList.findAll", query="SELECT e FROM FirewallDictionaryList e") +public class FirewallDictionaryList implements Serializable { + private static final long serialVersionUID = 1L; + + private static String domain; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name="id") + private int id; + + @Column(name="parentItemName", nullable=false) + @OrderBy("asc") + private String parentItemName; + + @Column(name="description") + private String description; + + @Column(name="addressList") + private String addressList; + + @Column(name="serviceList") + private String serviceList; + +/* @Temporal(TemporalType.TIMESTAMP) + @Column(name="created_date", updatable=false) + private Date createdDate; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="modified_date", nullable=false) + private Date modifiedDate; + + @ManyToOne(optional = false) + @JoinColumn(name="created_by") + private UserInfo userCreatedBy; + + @ManyToOne(optional = false) + @JoinColumn(name="modified_by") + private UserInfo userModifiedBy;*/ + + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + + public String getParentItemName() { + return parentItemName; + } + + public String getDescription() { + return description; + } + + public String getAddressList() { + return addressList; + } + + public String getServiceList() { + return serviceList; + } + + public void setParentItemName(String parentItemName) { + this.parentItemName = parentItemName; + } + + public void setDescription(String description) { + this.description = description; + } + + public void setAddressList(String addressList) { + this.addressList = addressList; + } + + public void setServiceList(String serviceList) { + this.serviceList = serviceList; + } + + + /*public UserInfo getUserCreatedBy() { + return userCreatedBy; + } + + public void setUserCreatedBy(UserInfo userCreatedBy) { + this.userCreatedBy = userCreatedBy; + } + + public UserInfo getUserModifiedBy() { + return userModifiedBy; + } + + public void setUserModifiedBy(UserInfo userModifiedBy) { + this.userModifiedBy = userModifiedBy; + }*/ + + private static Log logger = LogFactory.getLog(FirewallDictionaryList.class); + + public FirewallDictionaryList() { + + } + + private static final Log auditLogger = LogFactory + .getLog("auditLogger"); + + public FirewallDictionaryList(String string, String userid) { + this(domain); + } + public FirewallDictionaryList(String domain) { + this.parentItemName = domain; + } + + /*@PrePersist + public void prePersist() { + Date date = new Date(); + this.createdDate = date; + this.modifiedDate = date; + auditLogger.debug("Added New Term Name: "+this.parentItemName+" by "+this.userCreatedBy); + + } + @PreUpdate + public void preUpdate() { + this.modifiedDate = new Date(); + try { + this.userModifiedBy =XacmlAdminAuthorization.getUserId();; + } catch (Exception e) { + logger.error("Exception caused While adding Modified by Role"+e); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "TermList", "Exception caused While adding Modified by Role"); + } + auditLogger.debug("Updated Term Name: "+this.parentItemName+" by "+this.userModifiedBy); + } +*/ +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/FunctionArgument.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/FunctionArgument.java new file mode 100644 index 000000000..c660fde06 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/FunctionArgument.java @@ -0,0 +1,122 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; + +import java.io.Serializable; + +import javax.persistence.*; + + +/** + * The persistent class for the FunctionArguments database table. + * + */ +@Entity +@Table(name="FunctionArguments") +@NamedQuery(name="FunctionArgument.findAll", query="SELECT f FROM FunctionArgument f") +public class FunctionArgument implements Serializable { + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue(strategy=GenerationType.AUTO) + @Column(name="id") + private int id; + + @Column(name="is_bag", nullable=false) + private int isBag; + + //bi-directional many-to-one association to FunctionDefinition + @ManyToOne + @JoinColumn(name="function_id") + private FunctionDefinition functionDefinition; + + @Column(name="arg_index", nullable=false) + private int argIndex; + + //bi-directional many-to-one association to Datatype + @ManyToOne + @JoinColumn(name="datatype_id") + private Datatype datatypeBean; + + public FunctionArgument() { + } + + public FunctionArgument(final FunctionArgument argument) { + this.argIndex = argument.argIndex; + this.datatypeBean = argument.datatypeBean; + this.isBag = argument.isBag; + this.functionDefinition = argument.functionDefinition; + } + + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + + public int getArgIndex() { + return this.argIndex; + } + + public void setArgIndex(int argIndex) { + this.argIndex = argIndex; + } + + public Datatype getDatatypeBean() { + return this.datatypeBean; + } + + public void setDatatypeBean(Datatype datatypeBean) { + this.datatypeBean = datatypeBean; + } + + public FunctionDefinition getFunctionDefinition() { + return this.functionDefinition; + } + + public int getIsBag() { + return isBag; + } + + public void setIsBag(int isBag) { + this.isBag = isBag; + } + + public void setFunctionDefinition(FunctionDefinition functionDefinition) { + this.functionDefinition = functionDefinition; + } + + @Transient + @Override + public String toString() { + return "FunctionArgument [id=" + id + ", argIndex=" + argIndex + + ", datatypeBean=" + datatypeBean + ", isBag=" + isBag + + ", functionDefinition=" + functionDefinition + "]"; + } + + @Transient + public boolean isBag() { + return this.isBag == 1; + } + +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/FunctionDefinition.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/FunctionDefinition.java new file mode 100644 index 000000000..c0ccef99a --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/FunctionDefinition.java @@ -0,0 +1,219 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; + +import java.io.Serializable; + +import javax.persistence.*; + +import java.util.List; + + +/** + * The persistent class for the FunctionDefinition database table. + * + */ +@Entity +@Table(name="FunctionDefinition") +@NamedQueries({ + @NamedQuery(name="FunctionDefinition.findAll", query="SELECT f FROM FunctionDefinition f") +}) +public class FunctionDefinition implements Serializable { + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue(strategy=GenerationType.AUTO) + @Column(name="id") + private int id; + + @Column(name="short_name", nullable=false, length=64) + private String shortname; + + @Column(name="xacml_id", nullable=false, length=255) + private String xacmlid; + + //bi-directional many-to-one association to Datatype + @ManyToOne + @JoinColumn(name="return_datatype", nullable=true) + private Datatype datatypeBean; + + @Column(name="is_bag_return", nullable=false) + private Integer isBagReturn; + + @Column(name="is_higher_order", nullable=false) + private Integer isHigherOrder; + + @Column(name="arg_lb", nullable=false) + private Integer argLb; + + @Column(name="arg_ub", nullable=false) + private Integer argUb; + + @Column(name="ho_arg_lb", nullable=true) + private Integer higherOrderArg_LB; + + @Column(name="ho_arg_ub", nullable=true) + private Integer higherOrderArg_UB; + + @Column(name="ho_primitive", nullable=true) + private Character higherOrderIsPrimitive; + + //bi-directional many-to-one association to FunctionArgument + @OneToMany(mappedBy="functionDefinition") + private List functionArguments; + + public FunctionDefinition() { + } + + public int getId() { + return this.id; + } + + public void setId(Integer id) { + this.id = id; + } + + public int getArgLb() { + return this.argLb; + } + + public void setArgLb(Integer argLb) { + this.argLb = argLb; + } + + public int getArgUb() { + return this.argUb; + } + + public void setArgUb(Integer argUb) { + this.argUb = argUb; + } + + public int getIsBagReturn() { + return isBagReturn; + } + + public void setIsBagReturn(Integer isBagReturn) { + this.isBagReturn = isBagReturn; + } + + public int getIsHigherOrder() { + return isHigherOrder; + } + + public void setIsHigherOrder(Integer isHigherOrder) { + this.isHigherOrder = isHigherOrder; + } + + public Datatype getDatatypeBean() { + return this.datatypeBean; + } + + public void setDatatypeBean(Datatype datatypeBean) { + this.datatypeBean = datatypeBean; + } + + public String getShortname() { + return this.shortname; + } + + public void setShortname(String shortname) { + this.shortname = shortname; + } + + public String getXacmlid() { + return this.xacmlid; + } + + public void setXacmlid(String xacmlid) { + this.xacmlid = xacmlid; + } + + public int getHigherOrderArg_LB() { + return higherOrderArg_LB; + } + + public void setHigherOrderArg_LB(Integer higherOrderArg_LB) { + this.higherOrderArg_LB = higherOrderArg_LB; + } + + public int getHigherOrderArg_UB() { + return higherOrderArg_UB; + } + + public void setHigherOrderArg_UB(Integer higherOrderArg_UB) { + this.higherOrderArg_UB = higherOrderArg_UB; + } + + public Character getHigherOrderIsPrimitive() { + return higherOrderIsPrimitive; + } + + public void setHigherOrderIsPrimitive(Character higherOrderIsPrimitive) { + this.higherOrderIsPrimitive = higherOrderIsPrimitive; + } + + public List getFunctionArguments() { + return this.functionArguments; + } + + public void setFunctionArguments(List functionArguments) { + this.functionArguments = functionArguments; + } + + public FunctionArgument addFunctionArgument(FunctionArgument functionArgument) { + getFunctionArguments().add(functionArgument); + functionArgument.setFunctionDefinition(this); + + return functionArgument; + } + + public FunctionArgument removeFunctionArgument(FunctionArgument functionArgument) { + getFunctionArguments().remove(functionArgument); + functionArgument.setFunctionDefinition(null); + + return functionArgument; + } + + @Transient + @Override + public String toString() { + return "FunctionDefinition [id=" + id + ", argLb=" + argLb + ", argUb=" + + argUb + ", isBagReturn=" + isBagReturn + ", isHigherOrder=" + + isHigherOrder + ", datatypeBean=" + datatypeBean + + ", shortname=" + shortname + ", xacmlid=" + xacmlid + + ", higherOrderArg_LB=" + higherOrderArg_LB + + ", higherOrderArg_UB=" + higherOrderArg_UB + + ", higherOrderIsPrimitive=" + higherOrderIsPrimitive + + ", functionArguments=" + functionArguments + "]"; + } + + @Transient + public boolean isBagReturn() { + return this.isBagReturn == 1; + } + + @Transient + public boolean isHigherOrder() { + return this.isHigherOrder == 1; + } + +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/GlobalRoleSettings.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/GlobalRoleSettings.java new file mode 100644 index 000000000..5b69cab32 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/GlobalRoleSettings.java @@ -0,0 +1,93 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; + +import java.io.Serializable; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.NamedQuery; +import javax.persistence.Table; + + +/** + * Entity implementation class for Entity: Administration + * + */ +@Entity +@Table(name="GlobalRoleSettings") +@NamedQuery(name="GlobalRoleSettings.findAll", query="SELECT g FROM GlobalRoleSettings g") +public class GlobalRoleSettings implements Serializable { + private static final long serialVersionUID = 1L; + + @Id + @Column(name="role", length=45) + private String role; + + @Column(name="lockdown") + private boolean lockdown; + + public GlobalRoleSettings() { + super(); + } + + public GlobalRoleSettings(boolean lockdown) { + this.role = org.openecomp.policy.rest.XacmlAdminAuthorization.Role.ROLE_SUPERADMIN.toString(); + this.lockdown = lockdown; + } + + /** + * return the role + * + * @return the role + */ + public String getRole() { + return role; + } + + /** + * set role + * + * @param role the role to set + */ + public void setRole(String role) { + this.role = role; + } + + /** + * is the system locked down + * + * @return + */ + public boolean isLockdown() { + return lockdown; + } + + /** + * sets lockdown configuration + * + * @param lockdown + */ + public void setLockdown(boolean lockdown) { + this.lockdown = lockdown; + } +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/GroupEntity.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/GroupEntity.java new file mode 100644 index 000000000..b3897d0ee --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/GroupEntity.java @@ -0,0 +1,276 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/* + * AT&T - PROPRIETARY + * THIS FILE CONTAINS PROPRIETARY INFORMATION OF + * AT&T AND IS NOT TO BE DISCLOSED OR USED EXCEPT IN + * ACCORDANCE WITH APPLICABLE AGREEMENTS. + * + * Copyright (c) 2013 AT&T Knowledge Ventures + * Unpublished and Not for Publication + * All Rights Reserved + */ +package org.openecomp.policy.rest.jpa; +/* + */ +import java.io.Serializable; +import java.util.Date; +import java.util.List; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Index; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.Lob; +import javax.persistence.ManyToMany; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.OneToOne; +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; +import javax.persistence.SequenceGenerator; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import javax.persistence.UniqueConstraint; +import javax.persistence.Version; + +import com.fasterxml.jackson.annotation.JsonManagedReference; + +/* + * The Entity class to persist a policy object and its configuration data + */ + +/** + * + */ +@Entity +//Add a non-unique index and a constraint that says the combo of policyName and scopeId must be unique +@Table(name="GroupEntity") + +@NamedQueries({ + @NamedQuery(name="GroupEntity.findAll", query="SELECT e FROM GroupEntity e "), + @NamedQuery(name="GroupEntity.deleteAll", query="DELETE FROM GroupEntity WHERE 1=1") +}) + +public class GroupEntity implements Serializable { + private static final long serialVersionUID = 1L; + + @Id + @Column (name="groupKey", nullable=false) + //@GeneratedValue(strategy = GenerationType.SEQUENCE, generator="seqGroup") + @GeneratedValue(strategy = GenerationType.AUTO) + private long groupKey; + + @Column (name="groupId", nullable=false) + private String groupId; + + @Column(name="groupName", nullable=false, unique=false, length=255) + private String groupName; + + @Version + @Column(name="version") + private int version; + + @ManyToMany + @JoinTable(name="PolicyGroupEntity",joinColumns={@JoinColumn(name="groupKey", referencedColumnName="groupKey")}, + inverseJoinColumns={@JoinColumn(name="policyId",referencedColumnName="policyId")}) + @JsonManagedReference + private List policies; + + @Column(name="created_by", nullable=false, length=255) + private String createdBy = "guest"; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="created_date", updatable=false) + private Date createdDate; + + @Column(name="description", nullable=false, length=2048) + private String description = "NoDescription"; + + @Column(name="modified_by", nullable=false, length=255) + private String modifiedBy = "guest"; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="modified_date", nullable=false) + private Date modifiedDate; + + @Column(name="defaultGroup", nullable=false) + private boolean defaultGroup = false; + @Column(name="deleted", nullable=false) + private boolean deleted = false; + + public GroupEntity() { + super(); + } + + @PrePersist + public void prePersist() { + Date date = new Date(); + this.createdDate = date; + this.modifiedDate = date; + } + + @PreUpdate + public void preUpdate() { + this.modifiedDate = new Date(); + } + + /** + * @return the policyId + */ + public String getGroupId() { + return groupId; + } + public long getGroupKey(){ + return groupKey; + } + + public void setGroupId(String groupId){ + this.groupId = groupId; + } + + /** + * @param policyId cannot be set + */ + + public String getgroupName() { + return groupName; + } + + public void setGroupName(String groupName) { + this.groupName = groupName; + } + + public boolean isDefaultGroup(){ + return defaultGroup; + } + + public void setDefaultGroup(boolean isDefaultGroup){ + this.defaultGroup = isDefaultGroup; + } + + + + /** + * @return the configurationDataEntity + */ + public List getPolicies() { + return policies; + } + + /** + * @param configurationDataEntity the configurationDataEntity to set + */ + public void addPolicyToGroup(PolicyEntity policy) { + if(!this.policies.contains(policy)){ + this.policies.add(policy); + } + } + public void removePolicyFromGroup(PolicyEntity policy){ + this.policies.remove(policy); + } + + + + /** + * @return the createdBy + */ + public String getCreatedBy() { + return createdBy; + } + + /** + * @param createdBy the createdBy to set + */ + public void setCreatedBy(String createdBy) { + this.createdBy = createdBy; + } + + /** + * @return the description + */ + public String getDescription() { + return description; + } + + /** + * @param description the description to set + */ + public void setDescription(String description) { + this.description = description; + } + + /** + * @return the modifiedBy + */ + public String getModifiedBy() { + return modifiedBy; + } + + /** + * @param modifiedBy the modifiedBy to set + */ + public void setModifiedBy(String modifiedBy) { + this.modifiedBy = modifiedBy; + } + + /** + * @return the version + */ + public int getVersion() { + return version; + } + + /** + * @return the createdDate + */ + public Date getCreatedDate() { + return createdDate; + } + + /** + * @return the modifiedDate + */ + public Date getModifiedDate() { + return modifiedDate; + } + + /** + * @return the deleted + */ + public boolean isDeleted() { + return deleted; + } + + /** + * @param deleted the deleted to set + */ + public void setDeleted(boolean deleted) { + this.deleted = deleted; + } + + +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/GroupPolicyScopeList.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/GroupPolicyScopeList.java new file mode 100644 index 000000000..c57d1475a --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/GroupPolicyScopeList.java @@ -0,0 +1,114 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; +/* + */ +import java.io.Serializable; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.NamedQuery; +import javax.persistence.OrderBy; +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + + +@Entity +@Table(name="GroupPolicyScopeList") +@NamedQuery(name="GroupPolicyScopeList.findAll", query="SELECT e FROM GroupPolicyScopeList e ") +public class GroupPolicyScopeList implements Serializable { + private static final long serialVersionUID = 1L; + + private static String domain; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name="id") + private int id; + + @Column(name="name", nullable=false) + @OrderBy("asc") + private String name; + + @Column(name="groupList") + private String groupList; + + @Column(name="description") + private String description; + + public GroupPolicyScopeList() { + + } + public GroupPolicyScopeList(String string, String userid) { + this(domain); + + } + public GroupPolicyScopeList(String domain) { + + } + + @PrePersist + public void prePersist() { + + } + @PreUpdate + public void preUpdate() { + } + + + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + public String getGroupName() { + return this.name; + } + + public void setGroupName(String serviceName) { + this.name = serviceName; + + } + + public String getGroupList() { + return this.groupList; + } + + public void setGroupList(String groupList) { + this.groupList = groupList; + + } + public String getDescription() { + return description; + } + public void setDescription(String description) { + this.description = description; + } +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/GroupServiceList.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/GroupServiceList.java new file mode 100644 index 000000000..b5fbd9355 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/GroupServiceList.java @@ -0,0 +1,107 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; +/* + */ +import java.io.Serializable; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.NamedQuery; +import javax.persistence.OrderBy; +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + + +@Entity +@Table(name="GroupServiceList") +@NamedQuery(name="GroupServiceList.findAll", query="SELECT e FROM GroupServiceList e ") +public class GroupServiceList implements Serializable { + private static final long serialVersionUID = 1L; + + private static String domain; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name="id") + private int id; + + @Column(name="name", nullable=false) + @OrderBy("asc") + private String name; + + @Column(name="serviceList ") + private String serviceList; + + + public GroupServiceList() { + + } + public GroupServiceList(String string, String userid) { + this(domain); + + } + public GroupServiceList(String domain) { + + } + + @PrePersist + public void prePersist() { + + } + @PreUpdate + public void preUpdate() { + } + + + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + public String getGroupName() { + return this.name; + } + + public void setGroupName(String serviceName) { + this.name = serviceName; + + } + + public String getServiceList() { + return this.serviceList; + } + + public void setServiceList(String serviceList) { + this.serviceList = serviceList; + + } + +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/MicroServiceConfigName.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/MicroServiceConfigName.java new file mode 100644 index 000000000..594cacf33 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/MicroServiceConfigName.java @@ -0,0 +1,103 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; +/* + */ +import java.io.Serializable; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.NamedQuery; +import javax.persistence.OrderBy; +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; +import javax.persistence.Table; + + +@Entity +@Table(name="MicroServiceConfigName") +@NamedQuery(name="MicroServiceConfigName.findAll", query="SELECT e FROM MicroServiceConfigName e ") +public class MicroServiceConfigName implements Serializable { + private static final long serialVersionUID = 1L; + + private static String domain; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name="id") + private int id; + + @Column(name="name", nullable=false) + @OrderBy("asc") + private String name; + + @Column(name="description ") + private String description ; + + + public MicroServiceConfigName() { + + } + public MicroServiceConfigName(String string, String userid) { + this(domain); + + } + public MicroServiceConfigName(String domain) { + + } + + @PrePersist + public void prePersist() { + + } + @PreUpdate + public void preUpdate() { + } + + + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + + } + public String getDescriptionValue() { + return this.description ; + } + + public void setDescriptionValue(String description ) { + this.description = description ; + } + +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/MicroServiceLocation.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/MicroServiceLocation.java new file mode 100644 index 000000000..8532f81a1 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/MicroServiceLocation.java @@ -0,0 +1,103 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; +/* + */ +import java.io.Serializable; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.NamedQuery; +import javax.persistence.OrderBy; +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; +import javax.persistence.Table; + + +@Entity +@Table(name="MicroServiceLocation") +@NamedQuery(name="MicroServiceLocation.findAll", query="SELECT e FROM MicroServiceLocation e ") +public class MicroServiceLocation implements Serializable { + private static final long serialVersionUID = 1L; + + private static String domain; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name="id") + private int id; + + @Column(name="name", nullable=false) + @OrderBy("asc") + private String name; + + @Column(name="description ") + private String description ; + + + public MicroServiceLocation() { + + } + public MicroServiceLocation(String string, String userid) { + this(domain); + + } + public MicroServiceLocation(String domain) { + + } + + @PrePersist + public void prePersist() { + + } + @PreUpdate + public void preUpdate() { + } + + + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + + } + public String getDescriptionValue() { + return this.description ; + } + + public void setDescriptionValue(String description ) { + this.description = description ; + } + +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/MicroServiceModels.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/MicroServiceModels.java new file mode 100644 index 000000000..ca7460640 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/MicroServiceModels.java @@ -0,0 +1,172 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/* + * AT&T - PROPRIETARY + * THIS FILE CONTAINS PROPRIETARY INFORMATION OF + * AT&T AND IS NOT TO BE DISCLOSED OR USED EXCEPT IN + * ACCORDANCE WITH APPLICABLE AGREEMENTS. + * + * Copyright (c) 2015 AT&T Knowledge Ventures + * Unpublished and Not for Publication + * All Rights Reserved + */ +package org.openecomp.policy.rest.jpa; + +import java.io.Serializable; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.NamedQuery; +import javax.persistence.OrderBy; +import javax.persistence.Table; +/* + * JPA for the Micro Service Models. + * + * @version: 0.1 + */ +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +import org.openecomp.policy.rest.jpa.UserInfo; + + +@Entity +@Table(name="MicroServiceModels") +@NamedQuery(name="MicroServiceModels.findAll", query="SELECT b FROM MicroServiceModels b ") +public class MicroServiceModels implements Serializable{ + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name="id") + private int id; + + @Column(name="modelName", nullable=false, unique=true) + @OrderBy("asc") + private String modelName; + + @Column(name="description", nullable=true, length=2048) + private String description; + + @Column(name="dependency", nullable=true, length=2048) + private String dependency; + + @Column(name="attributes", nullable=false, length=255) + private String attributes; + + @Column(name="ref_attributes", nullable=false, length=255) + private String ref_attributes; + + @Column (name="sub_attributes", nullable=false, length=2000) + private String sub_attributes; + + @Column (name="version", nullable=false, length=2000) + private String version; + + public String getSub_attributes() { + return sub_attributes; + } + + public void setSub_attributes(String sub_attributes) { + this.sub_attributes = sub_attributes; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + @ManyToOne + @JoinColumn(name="imported_by") + private UserInfo userCreatedBy; + + public UserInfo getUserCreatedBy() { + return userCreatedBy; + } + + public void setUserCreatedBy(UserInfo userCreatedBy) { + this.userCreatedBy = userCreatedBy; + } + + public MicroServiceModels(){ + } + + public MicroServiceModels(String userid){ + + } + + public String getAttributes() { + return attributes; + } + + public void setAttributes(String attributes) { + this.attributes = attributes; + } + + public String getRef_attributes() { + return ref_attributes; + } + + public void setRef_attributes(String ref_attributes) { + this.ref_attributes = ref_attributes; + } + + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + + public String getDescription() { + return this.description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getDependency() { + return dependency; + } + + public void setDependency(String dependency) { + this.dependency = dependency; + } + + public String getModelName(){ + return this.modelName; + } + + public void setModelName(String modelName){ + this.modelName = modelName; + } +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/Obadvice.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/Obadvice.java new file mode 100644 index 000000000..f26fc9d95 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/Obadvice.java @@ -0,0 +1,227 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; + +import java.io.Serializable; +import java.util.Date; +import java.util.HashSet; +import java.util.Set; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.NamedQuery; +import javax.persistence.OneToMany; +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import javax.persistence.Transient; + +import com.att.research.xacml.api.Identifier; + +/** + * The persistent class for the Obadvice database table. + * + */ +@Entity +@Table(name="Obadvice") +@NamedQuery(name="Obadvice.findAll", query="SELECT o FROM Obadvice o") +public class Obadvice implements Serializable { + private static final long serialVersionUID = 1L; + + public static final String OBLIGATION = "Obligation"; + public static final String ADVICE = "Advice"; + public static final String EFFECT_PERMIT = "Permit"; + public static final String EFFECT_DENY = "Deny"; + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name="id") + private int id; + + @Column(name="type", nullable=false) + private String type; + + @Column(name="xacml_id", nullable=false, length=255) + private String xacmlId; + + @Column(name="fulfill_on", nullable=true, length=32) + private String fulfillOn; + + @Column(name="description", nullable=true, length=2048) + private String description; + + //bi-directional one-to-many association to Attribute Assignment + @OneToMany(mappedBy="obadvice", orphanRemoval=true, cascade=CascadeType.REMOVE) + private Set obadviceExpressions = new HashSet(2); + + @Column(name="created_by", nullable=false, length=255) + private String createdBy; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="created_date", nullable=false, updatable=false) + private Date createdDate; + + @Column(name="modified_by", nullable=false, length=255) + private String modifiedBy; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="modified_date", nullable=false) + private Date modifiedDate; + + public Obadvice() { + this.type = Obadvice.OBLIGATION; + this.fulfillOn = Obadvice.EFFECT_PERMIT; + } + + public Obadvice(String domain, String userid) { + this.xacmlId = domain; + this.type = Obadvice.OBLIGATION; + this.fulfillOn = Obadvice.EFFECT_PERMIT; + this.createdBy = userid; + this.modifiedBy = userid; + } + + public Obadvice(Identifier id, String userid) { + this(id.stringValue(), userid); + } + + @PrePersist + public void prePersist() { + Date date = new Date(); + this.createdDate = date; + this.modifiedDate = date; + } + + @PreUpdate + public void preUpdate() { + this.modifiedDate = new Date(); + } + + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + + public String getCreatedBy() { + return this.createdBy; + } + + public void setCreatedBy(String createdBy) { + this.createdBy = createdBy; + } + + public String getDescription() { + return this.description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getFulfillOn() { + return this.fulfillOn; + } + + public void setFulfillOn(String fulfillOn) { + this.fulfillOn = fulfillOn; + } + + public String getModifiedBy() { + return this.modifiedBy; + } + + public void setModifiedBy(String modifiedBy) { + this.modifiedBy = modifiedBy; + } + + public String getType() { + return this.type; + } + + public void setType(String type) { + this.type = type; + } + + public String getXacmlId() { + return this.xacmlId; + } + + public void setXacmlId(String xacmlId) { + this.xacmlId = xacmlId; + } + + public Set getObadviceExpressions() { + return this.obadviceExpressions; + } + + public void setObadviceExpressions(Set obadviceExpressions) { + this.obadviceExpressions = obadviceExpressions; + } + + public ObadviceExpression addObadviceExpression(ObadviceExpression obadviceExpression) { + this.obadviceExpressions.add(obadviceExpression); + obadviceExpression.setObadvice(this); + + return obadviceExpression; + } + + public ObadviceExpression removeObadviceExpression(ObadviceExpression obadviceExpression) { + this.obadviceExpressions.remove(obadviceExpression); + obadviceExpression.setObadvice(null); + + return obadviceExpression; + } + + public void removeAllExpressions() { + if (this.obadviceExpressions == null) { + return; + } + for (ObadviceExpression expression : this.obadviceExpressions) { + expression.setObadvice(null); + } + this.obadviceExpressions.clear(); + } + + @Transient + public Obadvice clone() { + Obadvice obadvice = new Obadvice(); + + obadvice.type = this.type; + obadvice.xacmlId = this.xacmlId; + obadvice.fulfillOn = this.fulfillOn; + obadvice.description = this.description; + obadvice.createdBy = this.createdBy; + obadvice.modifiedBy = this.modifiedBy; + for (ObadviceExpression exp: this.obadviceExpressions) { + obadvice.addObadviceExpression(exp.clone()); + } + + return obadvice; + } +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/ObadviceExpression.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/ObadviceExpression.java new file mode 100644 index 000000000..28957fa85 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/ObadviceExpression.java @@ -0,0 +1,126 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; + +import java.io.Serializable; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.Lob; +import javax.persistence.ManyToOne; +import javax.persistence.NamedQuery; +import javax.persistence.OneToOne; +import javax.persistence.Table; + +import org.openecomp.policy.rest.jpa.Attribute; + + +/** + * The persistent class for the ObadviceExpressions database table. + * + */ +@Entity +@Table(name="ObadviceExpressions") +@NamedQuery(name="ObadviceExpression.findAll", query="SELECT o FROM ObadviceExpression o") +public class ObadviceExpression implements Serializable { + private static final long serialVersionUID = 1L; + + public static final String EXPRESSION_APPLY = "Apply"; + public static final String EXPRESSION_SELECTOR = "Attribute Selector"; + public static final String EXPRESSION_VALUE = "Attribute Value"; + public static final String EXPRESSION_FUNCTION = "Function"; + public static final String EXPRESSION_REFERENCE = "Varable Reference"; + public static final String EXPRESSION_DESIGNATOR = "Attribute Designator"; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name="id") + private int id; + + //unidirectional one-to-one association to Attribute + @OneToOne + @JoinColumn(name="attribute_id") + private Attribute attribute; + + @Column(name="type", nullable=false) + private String type; + + /* + @Lob + @Column(name="expression", nullable=false) + private byte[] expression; + */ + + //bi-directional many-to-one association to Obadvice + @ManyToOne + @JoinColumn(name="obadvice_id") + private Obadvice obadvice; + + public ObadviceExpression() { + type = EXPRESSION_VALUE; + } + + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + + public Attribute getAttribute() { + return this.attribute; + } + + public void setAttribute(Attribute attribute) { + this.attribute = attribute; + } + + public String getType() { + return this.type; + } + + public void setType(String type) { + this.type = type; + } + + public Obadvice getObadvice() { + return this.obadvice; + } + + public void setObadvice(Obadvice obadvice) { + this.obadvice = obadvice; + } + + public ObadviceExpression clone() { + ObadviceExpression expression = new ObadviceExpression(); + + expression.attribute = this.attribute; + expression.type = this.type; + expression.obadvice = this.obadvice; + + return expression; + } +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PEPOptions.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PEPOptions.java new file mode 100644 index 000000000..8b05e8ffc --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PEPOptions.java @@ -0,0 +1,184 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; +/* + * + * */ +import java.io.Serializable; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.NamedQuery; +import javax.persistence.OrderBy; +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openecomp.policy.rest.XacmlAdminAuthorization; + +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.eelf.PolicyLogger; + + +@Entity +@Table(name = "PEPOptions") +@NamedQuery(name = "PEPOptions.findAll", query= "Select p from PEPOptions p") +public class PEPOptions implements Serializable { + private static final long serialVersionUID = 1L; + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "Id") + private int id; + + @Column(name="PEP_NAME", nullable=false) + @OrderBy("asc") + private String pepName; + + @Column(name="description", nullable=true, length=2048) + private String description; + + @Column(name="Actions", nullable=true) + @OrderBy("asc") + private String actions; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="created_date", updatable=false) + private Date createdDate; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="modified_date", nullable=false) + private Date modifiedDate; + + @ManyToOne(optional = false) + @JoinColumn(name="created_by") + private UserInfo userCreatedBy; + + @ManyToOne(optional = false) + @JoinColumn(name="modified_by") + private UserInfo userModifiedBy; + + public UserInfo getUserCreatedBy() { + return userCreatedBy; + } + + public void setUserCreatedBy(UserInfo userCreatedBy) { + this.userCreatedBy = userCreatedBy; + } + + public UserInfo getUserModifiedBy() { + return userModifiedBy; + } + + public void setUserModifiedBy(UserInfo userModifiedBy) { + this.userModifiedBy = userModifiedBy; + } + + private static Log logger = LogFactory.getLog(PEPOptions.class); + + public PEPOptions(){ + + } + + public PEPOptions(String string, String userid) { + this(string); + } + + public PEPOptions(String domain) { + this.pepName = domain; + } + + @PrePersist + public void prePersist() { + Date date = new Date(); + this.createdDate = date; + this.modifiedDate = date; + } + + @PreUpdate + public void preUpdate() { + this.modifiedDate = new Date(); + try { + this.userModifiedBy =XacmlAdminAuthorization.getUserId();; + } catch (Exception e) { + logger.error("Exception caused While adding Modified by Role"+e); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PEPOptions", "Exception caused While adding Modified by Role"); + } + } + + public int getId() { + return this.id; + } + public void setId(int id) { + this.id = id; + } + + public String getPepName() { + return pepName; + } + + public void setPepName(String pepName) { + this.pepName = pepName; + } + + public String getActions() { + return actions; + } + + public void setActions(String actions) { + this.actions = actions; + } + + public Date getCreatedDate() { + return this.createdDate; + } + + public void setCreatedDate(Date createdDate) { + this.createdDate = createdDate; + } + + public String getDescription() { + return this.description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Date getModifiedDate() { + return this.modifiedDate; + } + + public void setModifiedDate(Date modifiedDate) { + this.modifiedDate = modifiedDate; + } + +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PIPConfigParam.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PIPConfigParam.java new file mode 100644 index 000000000..d3724363f --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PIPConfigParam.java @@ -0,0 +1,147 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; + +import java.io.Serializable; + +import javax.persistence.*; + + +/** + * The persistent class for the PIPConfigParams database table. + * + */ +@Entity +@Table(name="PIPConfigParams") +@NamedQuery(name="PIPConfigParam.findAll", query="SELECT p FROM PIPConfigParam p") +public class PIPConfigParam implements Serializable { + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue(strategy=GenerationType.AUTO) + @Column(name="id") + private int id; + + @Column(name="PARAM_NAME", nullable=false, length=1024) + private String paramName; + + @Column(name="PARAM_VALUE", nullable=false, length=2048) + private String paramValue; + + @Column(name="PARAM_DEFAULT", nullable=true, length=2048) + private String paramDefault = null; + + @Column(name="REQUIRED", nullable=false) + private char required = '0'; + + //bi-directional many-to-one association to PIPConfiguration + @ManyToOne + @JoinColumn(name="PIP_ID") + private PIPConfiguration pipconfiguration; + + public PIPConfigParam() { + } + + public PIPConfigParam(String param) { + this.paramName = param; + } + + public PIPConfigParam(String param, String value) { + this(param); + this.paramValue = value; + } + + public PIPConfigParam(PIPConfigParam param) { + this(param.getParamName(), param.getParamValue()); + this.paramDefault = param.getParamDefault(); + this.required = param.required; + } + + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + + public String getParamName() { + return this.paramName; + } + + public void setParamName(String paramName) { + this.paramName = paramName; + } + + public String getParamValue() { + return this.paramValue; + } + + public void setParamValue(String paramValue) { + this.paramValue = paramValue; + } + + public String getParamDefault() { + return paramDefault; + } + + public void setParamDefault(String paramDefault) { + this.paramDefault = paramDefault; + } + + public char getRequired() { + return required; + } + + public void setRequired(char required) { + this.required = required; + } + + public PIPConfiguration getPipconfiguration() { + return this.pipconfiguration; + } + + public void setPipconfiguration(PIPConfiguration pipconfiguration) { + this.pipconfiguration = pipconfiguration; + } + + @Transient + public boolean isRequired() { + return (this.required == '1'); + } + + @Transient + public void setRequired(boolean required) { + if (required) { + this.setRequired('1'); + } else { + this.setRequired('0'); + } + } + + @Transient + @Override + public String toString() { + return "PIPConfigParam [id=" + id + ", paramName=" + paramName + + ", paramValue=" + paramValue + ", required=" + required + "]"; + } + +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PIPConfiguration.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PIPConfiguration.java new file mode 100644 index 000000000..8f75bef89 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PIPConfiguration.java @@ -0,0 +1,572 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Set; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.NamedQuery; +import javax.persistence.OneToMany; +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import javax.persistence.Transient; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; +import com.att.research.xacml.api.pip.PIPException; +import com.att.research.xacml.std.pip.engines.StdConfigurableEngine; +import com.att.research.xacml.std.pip.engines.csv.CSVEngine; +import com.att.research.xacml.std.pip.engines.csv.HyperCSVEngine; +import com.att.research.xacml.std.pip.engines.jdbc.JDBCEngine; +import com.att.research.xacml.std.pip.engines.ldap.LDAPEngine; +import com.att.research.xacml.util.XACMLProperties; +import com.google.common.base.Joiner; +import com.google.common.base.Splitter; + +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.eelf.PolicyLogger; + + +/** + * The persistent class for the PIPConfiguration database table. + * + */ +@Entity +@Table(name="PIPConfiguration") +@NamedQuery(name="PIPConfiguration.findAll", query="SELECT p FROM PIPConfiguration p") +public class PIPConfiguration implements Serializable { + private static final long serialVersionUID = 1L; + private static final Log logger = LogFactory.getLog(PIPConfiguration.class); + + @Id + @GeneratedValue(strategy=GenerationType.AUTO) + @Column(name="id") + private int id; + + @Column(name="DESCRIPTION", nullable=true, length=2048) + private String description; + + @Column(name="NAME", nullable=false, length=255) + private String name; + + @Column(name="CLASSNAME", nullable=false, length=2048) + private String classname; + + @Column(name="ISSUER", nullable=true, length=1024) + private String issuer; + + @Column(name="READ_ONLY", nullable=false) + private char readOnly = '0'; + + @Column(name="REQUIRES_RESOLVER", nullable=false) + private char requiresResolvers; + + @Column(name="CREATED_BY", nullable=false, length=255) + private String createdBy = "guest"; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="CREATED_DATE", nullable=false, updatable=false) + private Date createdDate; + + @Column(name="MODIFIED_BY", nullable=false, length=255) + private String modifiedBy = "guest"; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="MODIFIED_DATE", nullable=false) + private Date modifiedDate; + + //bi-directional many-to-one association to PIPConfigParam + @OneToMany(mappedBy="pipconfiguration", orphanRemoval=true, cascade=CascadeType.REMOVE) + private Set pipconfigParams = new HashSet(); + + //bi-directional many-to-one association to PIPType + @ManyToOne + @JoinColumn(name="TYPE") + private PIPType piptype; + + //bi-directional many-to-one association to PIPResolver + @OneToMany(mappedBy="pipconfiguration", orphanRemoval=true, cascade=CascadeType.REMOVE) + private Set pipresolvers = new HashSet(); + + public PIPConfiguration() { + } + + public PIPConfiguration(PIPConfiguration config, String user) { + this.description = config.description; + this.name = config.name; + this.classname = config.classname; + this.issuer = config.issuer; + this.requiresResolvers = config.requiresResolvers; + this.readOnly = config.readOnly; + this.piptype = config.piptype; + for (PIPConfigParam param : config.pipconfigParams) { + this.addPipconfigParam(new PIPConfigParam(param)); + } + for (PIPResolver resolver : config.pipresolvers) { + this.addPipresolver(new PIPResolver(resolver)); + } + } + + public PIPConfiguration(String id, Properties properties) throws PIPException { + this.readProperties(id, properties); + } + + public PIPConfiguration(String id, Properties properties, String user) throws PIPException { + this.createdBy = user; + this.modifiedBy = user; + this.readProperties(id, properties); + } + + @PrePersist + public void prePersist() { + Date date = new Date(); + this.createdDate = date; + this.modifiedDate = date; + } + + @PreUpdate + public void preUpdate() { + this.modifiedDate = new Date(); + } + + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + + public String getDescription() { + return this.description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } + + public String getClassname() { + return classname; + } + + public void setClassname(String classname) { + this.classname = classname; + } + + public String getIssuer() { + return issuer; + } + + public void setIssuer(String issuer) { + this.issuer = issuer; + } + + public char getReadOnly() { + return readOnly; + } + + public void setReadOnly(char readOnly) { + this.readOnly = readOnly; + } + + public char getRequiresResolvers() { + return requiresResolvers; + } + + public void setRequiresResolvers(char requireResolvers) { + this.requiresResolvers = requireResolvers; + } + + public Set getPipconfigParams() { + return this.pipconfigParams; + } + + public void setPipconfigParams(Set pipconfigParams) { + this.pipconfigParams = pipconfigParams; + } + + public PIPConfigParam addPipconfigParam(PIPConfigParam pipconfigParam) { + getPipconfigParams().add(pipconfigParam); + pipconfigParam.setPipconfiguration(this); + + return pipconfigParam; + } + + public PIPConfigParam removePipconfigParam(PIPConfigParam pipconfigParam) { + if (pipconfigParam == null) { + return pipconfigParam; + } + getPipconfigParams().remove(pipconfigParam); + pipconfigParam.setPipconfiguration(null); + + return pipconfigParam; + } + + @Transient + public void clearConfigParams() { + while (this.pipconfigParams.isEmpty() == false) { + this.removePipconfigParam(this.pipconfigParams.iterator().next()); + } + } + + public PIPType getPiptype() { + return this.piptype; + } + + public void setPiptype(PIPType piptype) { + this.piptype = piptype; + } + + public Set getPipresolvers() { + return this.pipresolvers; + } + + public void setPipresolvers(Set pipresolvers) { + this.pipresolvers = pipresolvers; + } + + public PIPResolver addPipresolver(PIPResolver pipresolver) { + getPipresolvers().add(pipresolver); + pipresolver.setPipconfiguration(this); + + return pipresolver; + } + + public PIPResolver removePipresolver(PIPResolver pipresolver) { + getPipresolvers().remove(pipresolver); + pipresolver.setPipconfiguration(null); + + return pipresolver; + } + + public String getCreatedBy() { + return createdBy; + } + + public void setCreatedBy(String createdBy) { + this.createdBy = createdBy; + } + + public Date getCreatedDate() { + return createdDate; + } + + public void setCreatedDate(Date createdDate) { + this.createdDate = createdDate; + } + + public String getModifiedBy() { + return modifiedBy; + } + + public void setModifiedBy(String modifiedBy) { + this.modifiedBy = modifiedBy; + } + + public Date getModifiedDate() { + return modifiedDate; + } + + public void setModifiedDate(Date modifiedDate) { + this.modifiedDate = modifiedDate; + } + + @Transient + public boolean isReadOnly() { + return (this.readOnly == '1'); + } + + @Transient + public void setReadOnly(boolean readOnly) { + if (readOnly) { + this.readOnly = '1'; + } else { + this.readOnly = '0'; + } + } + + @Transient + public boolean requiresResolvers() { + return (this.requiresResolvers == '1'); + } + + @Transient + public void setRequiresResolvers(boolean requires) { + if (requires) { + this.requiresResolvers = '1'; + } else { + this.requiresResolvers = '0'; + } + } + + @Transient + public static Collection importPIPConfigurations(Properties properties) { + Collection configurations = new ArrayList(); + String engines = properties.getProperty(XACMLProperties.PROP_PIP_ENGINES); + if (engines == null || engines.isEmpty()) { + return configurations; + } + for (String id : Splitter.on(',').trimResults().omitEmptyStrings().split(engines)) { + PIPConfiguration configuration; + try { + String user = "super-admin"; + //TODO + //String user = ((XacmlAdminUI)UI.getCurrent()).getUserid(); + configuration = new PIPConfiguration(id, properties, user); + configuration.setCreatedBy(user); + configuration.setModifiedBy(user); + configurations.add(configuration); + } catch (PIPException e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Import failed: " + e.getLocalizedMessage()); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PIPConfiguration", "Import failed"); + } + } + + return configurations; + } + + @Transient + protected void readProperties(String id, Properties properties) throws PIPException { + // + // Save the id if we don't have one already + // + + if (this.id == 0) { + try { + this.id = Integer.parseInt(id); + } catch (NumberFormatException e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Convert id to integer failed: " + id); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PIPConfiguration", "Convert id to integer failed"); + } + } + // + // Get its classname, this MUST exist. + // + this.classname = properties.getProperty(id + ".classname"); + if (this.classname == null) { + throw new PIPException("PIP Engine defined without a classname"); + } + // + // These classes we know for sure require resolvers. + // + //TODO: Commented out due to JPAUtils class & As of now we are not using PIP. So, it will not impact any Errors + /*if (this.classname.equals(JDBCEngine.class.getCanonicalName())) { + this.setRequiresResolvers(true); + this.setPiptype(JPAUtils.getPIPType(PIPType.TYPE_SQL)); + } else if (this.classname.equals(LDAPEngine.class.getCanonicalName())) { + this.setRequiresResolvers(true); + this.setPiptype(JPAUtils.getPIPType(PIPType.TYPE_LDAP)); + } else if (this.classname.equals(HyperCSVEngine.class.getCanonicalName())) { + this.setRequiresResolvers(true); + this.setPiptype(JPAUtils.getPIPType(PIPType.TYPE_HYPERCSV)); + } else if (this.classname.equals(CSVEngine.class.getCanonicalName())) { + this.setRequiresResolvers(true); + this.setPiptype(JPAUtils.getPIPType(PIPType.TYPE_CSV)); + } else { + // + // Assume it does not require resolvers for now, if we encounter + // one then we will change it. The user can always change it via the gui. + // + this.setRequiresResolvers(false); + this.setPiptype(JPAUtils.getPIPType(PIPType.TYPE_CUSTOM)); + }*/ + // + // Go through each property + // + for (Object name : properties.keySet()) { + if (name.toString().startsWith(id) == false) { + continue; + } + if (name.equals(id + ".classname")) { + // + // We already saved this + // + } else if (name.equals(id + "." + StdConfigurableEngine.PROP_NAME)) { + this.name = properties.getProperty(name.toString()); + } else if (name.equals(id + "." + StdConfigurableEngine.PROP_DESCRIPTION)) { + this.description = properties.getProperty(name.toString()); + } else if (name.equals(id + "." + StdConfigurableEngine.PROP_ISSUER)) { + this.issuer = properties.getProperty(name.toString()); + } else if (name.equals(id + ".resolvers")) { + // + // It has resolvers, make sure this is set to true if + // it has been already. + // + this.setRequiresResolvers(true); + // + // Parse the resolvers + // + Collection resolvers = PIPResolver.importResolvers(id + ".resolver", + properties.getProperty(name.toString()), + properties,"super-admin" + ); + //TODO: replace with UserId + //((XacmlAdminUI)UI.getCurrent()).getUserid() + for (PIPResolver resolver : resolvers) { + this.addPipresolver(resolver); + } + } else if (name.toString().startsWith(id + ".resolver")) { + // + // Ignore, the PIPResolver will parse these values + // + } else { + // + // Config Parameter + // + this.addPipconfigParam(new PIPConfigParam(name.toString().substring(id.length() + 1), + properties.getProperty(name.toString()))); + } + } + // + // Make sure we have a name at least + // + if (this.name == null) { + this.name = id; + } + } + + + @Transient + public Map getConfiguration(String name) { + String prefix; + if (name == null) { + prefix = Integer.toString(this.id); + } else { + prefix = name; + } + if (prefix.endsWith(".") == false) { + prefix = prefix + "."; + } + Map map = new HashMap(); + map.put(prefix + "classname", this.classname); + map.put(prefix + "name", this.name); + if (this.description != null) { + map.put(prefix + "description", this.description); + } + if (this.issuer != null) { + map.put(prefix + "issuer", this.issuer); + } + + for (PIPConfigParam param : this.pipconfigParams) { + map.put(prefix + param.getParamName(), param.getParamValue()); + } + + List ids = new ArrayList(); + Iterator iter = this.pipresolvers.iterator(); + while (iter.hasNext()) { + PIPResolver resolver = iter.next(); + String id = Integer.toString(resolver.getId()); + Map resolverMap = resolver.getConfiguration(prefix + "resolver." + id); + map.putAll(resolverMap); + ids.add(id); + } + if (ids.size() > 0) { + map.put(prefix + "resolvers", Joiner.on(',').join(ids)); + } + return map; + } + + @Transient + public Properties generateProperties(String name) { + String prefix; + if (name == null) { + prefix = Integer.toString(this.id); + } else { + if (name.endsWith(".")) { + prefix = name; + } else { + prefix = name + "."; + } + } + Properties props = new Properties(); + props.setProperty("xacml.pip.engines", name); + props.setProperty(prefix + "classname", this.classname); + props.setProperty(prefix + "name", this.name); + if (this.description != null) { + props.setProperty(prefix + "description", this.description); + } + if (this.issuer != null && this.issuer.isEmpty() == false) { + props.setProperty(prefix + "issuer", this.issuer); + } + + for (PIPConfigParam param : this.pipconfigParams) { + props.setProperty(prefix + param.getParamName(), param.getParamValue()); + } + + List ids = new ArrayList(); + Iterator iter = this.pipresolvers.iterator(); + while (iter.hasNext()) { + PIPResolver resolver = iter.next(); + String id = Integer.toString(resolver.getId()); + resolver.generateProperties(props, prefix + "resolver." + id); + ids.add(id); + } + if (ids.size() > 0) { + props.setProperty(prefix + "resolvers", Joiner.on(',').join(ids)); + } + return props; + } + + @Transient + @Override + public String toString() { + return "PIPConfiguration [id=" + id + ", piptype=" + piptype + + ", classname=" + classname + ", name=" + name + + ", description=" + description + ", issuer=" + issuer + + ", readOnly=" + readOnly + ", requiresResolvers=" + + requiresResolvers + ", createdBy=" + createdBy + + ", createdDate=" + createdDate + ", modifiedBy=" + modifiedBy + + ", modifiedDate=" + modifiedDate + ", pipconfigParams=" + + pipconfigParams + ", pipresolvers=" + pipresolvers + "]"; + } +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PIPResolver.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PIPResolver.java new file mode 100644 index 000000000..634ff3e63 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PIPResolver.java @@ -0,0 +1,365 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Properties; +import java.util.Set; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.NamedQuery; +import javax.persistence.OneToMany; +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import javax.persistence.Transient; + +import com.att.research.xacml.api.pip.PIPException; +import com.att.research.xacml.std.pip.engines.StdConfigurableEngine; +import com.google.common.base.Splitter; + + +/** + * The persistent class for the PIPResolver database table. + * + */ +@Entity +@Table(name="PIPResolver") +@NamedQuery(name="PIPResolver.findAll", query="SELECT p FROM PIPResolver p") +public class PIPResolver implements Serializable { + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue(strategy=GenerationType.AUTO) + @Column(name="id") + private int id; + + @Column(name="DESCRIPTION", nullable=true, length=2048) + private String description; + + @Column(name="NAME", nullable=false, length=255) + private String name; + + @Column(name="ISSUER", nullable=true, length=1024) + private String issuer; + + @Column(name="CLASSNAME", nullable=false, length=2048) + private String classname; + + @Column(name="READ_ONLY", nullable=false) + private char readOnly = '0'; + + @Column(name="CREATED_BY", nullable=false, length=255) + private String createdBy = "guest"; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="CREATED_DATE", nullable=false, updatable=false) + private Date createdDate; + + @Column(name="MODIFIED_BY", nullable=false, length=255) + private String modifiedBy = "guest"; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="MODIFIED_DATE", nullable=false) + private Date modifiedDate; + + //bi-directional many-to-one association to PIPConfiguration + @ManyToOne + @JoinColumn(name="PIP_ID") + private PIPConfiguration pipconfiguration; + + //bi-directional many-to-one association to PIPResolverParam + @OneToMany(mappedBy="pipresolver", orphanRemoval=true, cascade=CascadeType.REMOVE) + private Set pipresolverParams = new HashSet(); + + public PIPResolver() { + } + + public PIPResolver(String prefix, Properties properties, String user) throws PIPException { + this.createdBy = user; + this.modifiedBy = user; + this.readOnly = '0'; + this.readProperties(prefix, properties); + } + + public PIPResolver(PIPResolver resolver) { + this.name = resolver.name; + this.description = resolver.description; + this.issuer = resolver.issuer; + this.classname = resolver.classname; + this.readOnly = resolver.readOnly; + for (PIPResolverParam param : this.pipresolverParams) { + this.addPipresolverParam(new PIPResolverParam(param)); + } + } + + @PrePersist + public void prePersist() { + Date date = new Date(); + this.createdDate = date; + this.modifiedDate = date; + } + + @PreUpdate + public void preUpdate() { + this.modifiedDate = new Date(); + } + + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + + public String getDescription() { + return this.description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } + + public String getIssuer() { + return issuer; + } + + public void setIssuer(String issuer) { + this.issuer = issuer; + } + + public String getClassname() { + return classname; + } + + public void setClassname(String classname) { + this.classname = classname; + } + + public char getReadOnly() { + return readOnly; + } + + public void setReadOnly(char readOnly) { + this.readOnly = readOnly; + } + + public String getCreatedBy() { + return createdBy; + } + + public void setCreatedBy(String createdBy) { + this.createdBy = createdBy; + } + + public Date getCreatedDate() { + return createdDate; + } + + public void setCreatedDate(Date createdDate) { + this.createdDate = createdDate; + } + + public String getModifiedBy() { + return modifiedBy; + } + + public void setModifiedBy(String modifiedBy) { + this.modifiedBy = modifiedBy; + } + + public Date getModifiedDate() { + return modifiedDate; + } + + public void setModifiedDate(Date modifiedDate) { + this.modifiedDate = modifiedDate; + } + + public PIPConfiguration getPipconfiguration() { + return this.pipconfiguration; + } + + public void setPipconfiguration(PIPConfiguration pipconfiguration) { + this.pipconfiguration = pipconfiguration; + } + + public Set getPipresolverParams() { + return this.pipresolverParams; + } + + public void setPipresolverParams(Set pipresolverParams) { + this.pipresolverParams = pipresolverParams; + } + + public PIPResolverParam addPipresolverParam(PIPResolverParam pipresolverParam) { + getPipresolverParams().add(pipresolverParam); + pipresolverParam.setPipresolver(this); + + return pipresolverParam; + } + + public PIPResolverParam removePipresolverParam(PIPResolverParam pipresolverParam) { + if (pipresolverParam == null) { + return pipresolverParam; + } + getPipresolverParams().remove(pipresolverParam); + pipresolverParam.setPipresolver(null); + + return pipresolverParam; + } + + @Transient + public void clearParams() { + while (this.pipresolverParams.isEmpty() == false) { + this.removePipresolverParam(this.pipresolverParams.iterator().next()); + } + } + + @Transient + public boolean isReadOnly() { + return (this.readOnly == '1'); + } + + @Transient + public void setReadOnly(boolean readOnly) { + if (readOnly) { + this.readOnly = '1'; + } else { + this.readOnly = '0'; + } + } + + @Transient + public static Collection importResolvers(String prefix, String list, Properties properties, String user) throws PIPException { + Collection resolvers = new ArrayList(); + for (String id : Splitter.on(',').trimResults().omitEmptyStrings().split(list)) { + resolvers.add(new PIPResolver(prefix + "." + id, properties, user)); + } + return resolvers; + } + + @Transient + protected void readProperties(String prefix, Properties properties) throws PIPException { + // + // Get its classname, this MUST exist. + // + this.classname = properties.getProperty(prefix + ".classname"); + if (this.classname == null) { + throw new PIPException("PIP Engine defined without a classname"); + } + // + // Go through each property + // + for (Object name : properties.keySet()) { + if (name.toString().startsWith(prefix) == false) { + continue; + } + if (name.equals(prefix + ".classname")) { + // + // We already saved this + // + } else if (name.equals(prefix + "." + StdConfigurableEngine.PROP_NAME)) { + this.name = properties.getProperty(name.toString()); + } else if (name.equals(prefix + "." + StdConfigurableEngine.PROP_DESCRIPTION)) { + this.description = properties.getProperty(name.toString()); + } else if (name.equals(prefix + "." + StdConfigurableEngine.PROP_ISSUER)) { + this.issuer = properties.getProperty(name.toString()); + } else { + this.addPipresolverParam(new PIPResolverParam(name.toString().substring(prefix.length() + 1), + properties.getProperty(name.toString()))); + } + } + } + + @Transient + public Map getConfiguration(String prefix) { + Map map = new HashMap(); + if (prefix.endsWith(".") == false) { + prefix = prefix + "."; + } + map.put(prefix + "classname", this.classname); + map.put(prefix + "name", this.name); + if (this.description != null) { + map.put(prefix + "description", this.description); + } + if (this.issuer != null && this.issuer.isEmpty() != false) { + map.put(prefix + "issuer", this.issuer); + } + for (PIPResolverParam param : this.pipresolverParams) { + map.put(prefix + param.getParamName(), param.getParamValue()); + } + return map; + } + + @Transient + public void generateProperties(Properties props, String prefix) { + if (prefix.endsWith(".") == false) { + prefix = prefix + "."; + } + props.setProperty(prefix + "classname", this.classname); + props.setProperty(prefix + "name", this.name); + if (this.description != null) { + props.setProperty(prefix + "description", this.description); + } + if (this.issuer != null && this.issuer.isEmpty() != false) { + props.setProperty(prefix + "issuer", this.issuer); + } + for (PIPResolverParam param : this.pipresolverParams) { + props.setProperty(prefix + param.getParamName(), param.getParamValue()); + } + } + + @Transient + @Override + public String toString() { + return "PIPResolver [id=" + id + ", classname=" + classname + ", name=" + + name + ", description=" + description + ", issuer=" + issuer + + ", readOnly=" + readOnly + ", createdBy=" + createdBy + + ", createdDate=" + createdDate + ", modifiedBy=" + modifiedBy + + ", modifiedDate=" + modifiedDate + ", pipresolverParams=" + + pipresolverParams + "]"; + } +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PIPResolverParam.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PIPResolverParam.java new file mode 100644 index 000000000..957b105d1 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PIPResolverParam.java @@ -0,0 +1,147 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; + +import java.io.Serializable; + +import javax.persistence.*; + + +/** + * The persistent class for the PIPResolverParams database table. + * + */ +@Entity +@Table(name="PIPResolverParams") +@NamedQuery(name="PIPResolverParam.findAll", query="SELECT p FROM PIPResolverParam p") +public class PIPResolverParam implements Serializable { + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue(strategy=GenerationType.AUTO) + @Column(name="id") + private int id; + + @Column(name="PARAM_NAME", nullable=false, length=1024) + private String paramName; + + @Column(name="PARAM_VALUE", nullable=false, length=2048) + private String paramValue; + + @Column(name="PARAM_DEFAULT", nullable=true, length=2048) + private String paramDefault; + + @Column(name="REQUIRED", nullable=false) + private char required = '0'; + + //bi-directional many-to-one association to PIPResolver + @ManyToOne + @JoinColumn(name="ID_RESOLVER") + private PIPResolver pipresolver; + + public PIPResolverParam() { + } + + public PIPResolverParam(String name) { + this.paramName = name; + } + + public PIPResolverParam(String name, String value) { + this(name); + this.paramValue = value; + } + + public PIPResolverParam(PIPResolverParam param) { + this(param.getParamName(), param.getParamValue()); + this.paramDefault = param.getParamDefault(); + this.required = param.required; + } + + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + + public String getParamName() { + return this.paramName; + } + + public void setParamName(String paramName) { + this.paramName = paramName; + } + + public String getParamValue() { + return this.paramValue; + } + + public void setParamValue(String paramValue) { + this.paramValue = paramValue; + } + + public String getParamDefault() { + return paramDefault; + } + + public void setParamDefault(String paramDefault) { + this.paramDefault = paramDefault; + } + + public char getRequired() { + return required; + } + + public void setRequired(char required) { + this.required = required; + } + + public PIPResolver getPipresolver() { + return this.pipresolver; + } + + public void setPipresolver(PIPResolver pipresolver) { + this.pipresolver = pipresolver; + } + + @Transient + public boolean isRequired() { + return this.required == '1'; + } + + @Transient + public void setRequired(boolean required) { + if (required) { + this.required = '1'; + } else { + this.required = '0'; + } + } + + @Transient + @Override + public String toString() { + return "PIPResolverParam [id=" + id + ", paramName=" + paramName + + ", paramValue=" + paramValue + ", required=" + required + "]"; + } + +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PIPType.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PIPType.java new file mode 100644 index 000000000..964a15412 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PIPType.java @@ -0,0 +1,131 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; + +import java.io.Serializable; +import java.util.Set; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.NamedQuery; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.persistence.Transient; + + +/** + * The persistent class for the PIPType database table. + * + */ +@Entity +@Table(name="PIPType") +@NamedQuery(name="PIPType.findAll", query="SELECT p FROM PIPType p") +public class PIPType implements Serializable { + private static final long serialVersionUID = 1L; + + public static final String TYPE_SQL = "SQL"; + public static final String TYPE_LDAP = "LDAP"; + public static final String TYPE_CSV = "CSV"; + public static final String TYPE_HYPERCSV = "Hyper-CSV"; + public static final String TYPE_CUSTOM = "Custom"; + + @Id + @GeneratedValue(strategy=GenerationType.AUTO) + @Column(name="id") + private int id; + + @Column(name="type", nullable=false, length=45) + private String type; + + //bi-directional many-to-one association to PIPConfiguration + @OneToMany(mappedBy="piptype") + private Set pipconfigurations; + + public PIPType() { + } + + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + + public String getType() { + return this.type; + } + + public void setType(String type) { + this.type = type; + } + + public Set getPipconfigurations() { + return this.pipconfigurations; + } + + public void setPipconfigurations(Set pipconfigurations) { + this.pipconfigurations = pipconfigurations; + } + + public PIPConfiguration addPipconfiguration(PIPConfiguration pipconfiguration) { + getPipconfigurations().add(pipconfiguration); + pipconfiguration.setPiptype(this); + + return pipconfiguration; + } + + public PIPConfiguration removePipconfiguration(PIPConfiguration pipconfiguration) { + getPipconfigurations().remove(pipconfiguration); + pipconfiguration.setPiptype(null); + + return pipconfiguration; + } + + @Transient + public boolean isSQL() { + return this.type.equals(TYPE_SQL); + } + + @Transient + public boolean isLDAP() { + return this.type.equals(TYPE_LDAP); + } + + @Transient + public boolean isCSV() { + return this.type.equals(TYPE_CSV); + } + + @Transient + public boolean isHyperCSV() { + return this.type.equals(TYPE_HYPERCSV); + } + + @Transient + public boolean isCustom() { + return this.type.equals(TYPE_CUSTOM); + } + +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PREFIXLIST.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PREFIXLIST.java new file mode 100644 index 000000000..aac04795c --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PREFIXLIST.java @@ -0,0 +1,117 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; +/* + */ +import java.io.Serializable; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.NamedQuery; +import javax.persistence.OrderBy; +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +@Entity +@Table(name="PREFIXLIST") +@NamedQuery(name="PREFIXLIST.findAll", query="SELECT e FROM PREFIXLIST e ") +public class PREFIXLIST implements Serializable { + private static final long serialVersionUID = 1L; + + private static String domain; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name="id") + private int id; + + @Column(name="pl_name", nullable=false) + @OrderBy("asc") + private String prefixListName; + + @Column(name="description", nullable=false) + private String description; + + @Column(name="pl_value", nullable=false) + private String prefixListValue; +/* + @Temporal(TemporalType.TIMESTAMP) + @Column(name="modified_date", nullable=false) + private Date modifiedDate;*/ + + public PREFIXLIST() { + + } + public PREFIXLIST(String string, String userid) { + this(domain); + + } + public PREFIXLIST(String domain) { + + } + + @PrePersist + public void prePersist() { + + } + @PreUpdate + public void preUpdate() { + } + public String getPrefixListName() { + return this.prefixListName; + } + + public void setPrefixListName(String prefixListName) { + this.prefixListName = prefixListName; + + } + + public String getDescription() { + return this.description; + } + + public void setDescription(String description) { + this.description = description; + + } + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + public String getPrefixListValue() { + return this.prefixListValue; + } + + public void setPrefixListValue(String prefixListValue) { + this.prefixListValue = prefixListValue; + } + +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PdpEntity.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PdpEntity.java new file mode 100644 index 000000000..191dfde60 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PdpEntity.java @@ -0,0 +1,247 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; +/* + */ +import java.io.Serializable; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Index; +import javax.persistence.JoinColumn; +import javax.persistence.Lob; +import javax.persistence.ManyToOne; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.OneToOne; +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; +import javax.persistence.SequenceGenerator; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import javax.persistence.UniqueConstraint; +import javax.persistence.Version; + +/* + * The Entity class to persist a policy object and its configuration data + */ + +/** + * + */ +@Entity +//Add a non-unique index and a constraint that says the combo of policyName and scopeId must be unique +@Table(name="PdpEntity") +@NamedQueries({ + @NamedQuery(name="PdpEntity.findAll", query="SELECT e FROM PdpEntity e "), + @NamedQuery(name="PdpEntity.deleteAll", query="DELETE FROM PdpEntity WHERE 1=1") +}) + +public class PdpEntity implements Serializable { + private static final long serialVersionUID = 1L; + + @Id + //@GeneratedValue(strategy = GenerationType.SEQUENCE, generator="seqPdp") + @GeneratedValue(strategy = GenerationType.AUTO) + @Column (name="pdpKey") + private long pdpKey; + + @Column (name="pdpId", nullable=false, unique=false, length=255) + private String pdpId; + + @Column(name="pdpName", nullable=false, unique=false, length=255) + private String pdpName; + + @Column(name="jmxPort", nullable=false, unique=false) + private int jmxPort; + + + @ManyToOne(optional=false) + @JoinColumn(name="groupKey", referencedColumnName="groupKey") + private GroupEntity groupEntity; + + @Column(name="created_by", nullable=false, length=255) + private String createdBy = "guest"; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="created_date", updatable=false) + private Date createdDate; + + @Column(name="description", nullable=false, length=2048) + private String description = "NoDescription"; + + @Column(name="modified_by", nullable=false, length=255) + private String modifiedBy = "guest"; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="modified_date", nullable=false) + private Date modifiedDate; + + @Column(name="deleted", nullable=false) + private boolean deleted = false; + + public PdpEntity() { + super(); + } + + @PrePersist + public void prePersist() { + Date date = new Date(); + this.createdDate = date; + this.modifiedDate = date; + } + + @PreUpdate + public void preUpdate() { + this.modifiedDate = new Date(); + } + + public long getPdpKey(){ + return pdpKey; + } + /** + * @return the policyId + */ + public String getPdpId() { + return pdpId; + } + + public void setPdpId(String id){ + pdpId = id; + } + /** + * @param policyId cannot be set + */ + + public String getPdpName() { + return pdpName; + } + + public void setPdpName(String groupName) { + this.pdpName = groupName; + } + + + + /** + * @return the configurationDataEntity + */ + public GroupEntity getGroup() { + return groupEntity; + } + + /** + * @param configurationDataEntity the configurationDataEntity to set + */ + public void setGroup(GroupEntity group) { + this.groupEntity = group; + } + + + + /** + * @return the createdBy + */ + public String getCreatedBy() { + return createdBy; + } + + /** + * @param createdBy the createdBy to set + */ + public void setCreatedBy(String createdBy) { + this.createdBy = createdBy; + } + + /** + * @return the description + */ + public String getDescription() { + return description; + } + + /** + * @param description the description to set + */ + public void setDescription(String description) { + this.description = description; + } + + /** + * @return the modifiedBy + */ + public String getModifiedBy() { + return modifiedBy; + } + + /** + * @param modifiedBy the modifiedBy to set + */ + public void setModifiedBy(String modifiedBy) { + this.modifiedBy = modifiedBy; + } + + /** + * @return the version + */ + public int getJmxPort() { + return jmxPort; + } + + public void setJmxPort(int jmxPort){ + this.jmxPort = jmxPort; + } + + /** + * @return the createdDate + */ + public Date getCreatedDate() { + return createdDate; + } + + /** + * @return the modifiedDate + */ + public Date getModifiedDate() { + return modifiedDate; + } + + /** + * @return the deleted + */ + public boolean isDeleted() { + return deleted; + } + + /** + * @param deleted the deleted to set + */ + public void setDeleted(boolean deleted) { + this.deleted = deleted; + } + + +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PolicyAlgorithms.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PolicyAlgorithms.java new file mode 100644 index 000000000..eb46ae0dc --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PolicyAlgorithms.java @@ -0,0 +1,116 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; + +import java.io.Serializable; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.NamedQuery; +import javax.persistence.Table; +import javax.persistence.Transient; + +import com.att.research.xacml.api.Identifier; + +@Entity +@Table(name="PolicyAlgorithms") +@NamedQuery(name="PolicyAlgorithms.findAll", query="SELECT d FROM PolicyAlgorithms d") +public class PolicyAlgorithms implements Serializable { + private static final long serialVersionUID = 1L; + + public static final char STANDARD = 'S'; + public static final char CUSTOM = 'C'; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name="id") + private int id; + + @Column(name="is_standard", nullable=false) + private char isStandard; + + @Column(name="xacml_id", nullable=false, unique=true, length=255) + private String xacmlId; + + @Column(name="short_name", nullable=false, length=64) + private String shortName; + + public PolicyAlgorithms(Identifier identifier, char standard) { + this.isStandard = standard; + if (identifier != null) { + this.xacmlId = identifier.stringValue(); + } + } + + public PolicyAlgorithms(Identifier identifier) { + this(identifier, PolicyAlgorithms.STANDARD); + } + + public PolicyAlgorithms() { + this(null, PolicyAlgorithms.STANDARD); + } + + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + + public char getIsStandard() { + return this.isStandard; + } + + public void setIsStandard(char isStandard) { + this.isStandard = isStandard; + } + + @Transient + public boolean isStandard() { + return (this.isStandard == PolicyAlgorithms.STANDARD); + } + + @Transient + public boolean isCustom() { + return (this.isStandard == PolicyAlgorithms.CUSTOM); + } + + public String getXacmlId() { + return this.xacmlId; + } + + public void setXacmlId(String xacmlId) { + this.xacmlId = xacmlId; + } + + public String getShortName() { + return shortName; + } + + public void setShortName(String shortName) { + this.shortName = shortName; + } + +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PolicyDBDaoEntity.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PolicyDBDaoEntity.java new file mode 100644 index 000000000..c395ab49a --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PolicyDBDaoEntity.java @@ -0,0 +1,150 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; +/* + */ +import java.io.Serializable; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +/* + * The Entity class to persist a PolicyDBDaoEntity object for registration of PolicyDBDao + */ + +/** + * + */ +@Entity +@Table(name="PolicyDBDaoEntity") + +@NamedQueries({ + @NamedQuery(name="PolicyDBDaoEntity.findAll", query="SELECT e FROM PolicyDBDaoEntity e "), + @NamedQuery(name="PolicyDBDaoEntity.deleteAll", query="DELETE FROM PolicyDBDaoEntity WHERE 1=1") +}) + +public class PolicyDBDaoEntity implements Serializable { + private static final long serialVersionUID = 1L; + + @Id + @Column(name="policyDBDaoUrl", nullable=false, unique=true) + private String policyDBDaoUrl; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="created_date", updatable=false) + private Date createdDate; + + //username for the pap server that registered this PolicyDBDaoEntity + @Column(name="username") + private String username; + + //AES encrypted password for the pap server that registered this PolicyDBDaoEntity + @Column(name="password") + private String password; + + //A column to allow some descriptive text. For example: Atlanta data center + @Column(name="description", nullable=false, length=2048) + private String description = "NoDescription"; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="modified_date", nullable=false) + private Date modifiedDate; + + public PolicyDBDaoEntity() { + super(); + } + + @PrePersist + public void prePersist() { + Date date = new Date(); + this.createdDate = date; + this.modifiedDate = date; + } + + @PreUpdate + public void preUpdate() { + this.modifiedDate = new Date(); + } + + /** + * @return the policyDBDaoUrl + */ + public String getPolicyDBDaoUrl() { + return policyDBDaoUrl; + } + + /** + * @param url the policyDBDaoUrl to set + */ + public void setPolicyDBDaoUrl(String url) { + this.policyDBDaoUrl = url; + } + + /** + * @return the description + */ + public String getDescription() { + return description; + } + + /** + * @param description the description to set + */ + public void setDescription(String description) { + this.description = description; + } + + /** + * @return the createdDate + */ + public Date getCreatedDate() { + return createdDate; + } + + /** + * @return the modifiedDate + */ + public Date getModifiedDate() { + return modifiedDate; + } + + public String getUsername(){ + return this.username; + } + public void setUsername(String username){ + this.username = username; + } + public String getPassword(){ + return this.password; + } + public void setPassword(String password){ + this.password = password; + } +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PolicyEditorScopes.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PolicyEditorScopes.java new file mode 100644 index 000000000..daf97b3ed --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PolicyEditorScopes.java @@ -0,0 +1,159 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; + +import java.io.Serializable; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.NamedQuery; +import javax.persistence.OrderBy; +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openecomp.policy.rest.XacmlAdminAuthorization; + +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.eelf.PolicyLogger; + +@Entity +@Table(name="PolicyEditorScopes") +@NamedQuery(name="PolicyEditorScopes.findAll", query="SELECT p FROM PolicyEditorScopes p ") +public class PolicyEditorScopes implements Serializable{ + private static final long serialVersionUID = 1L; + private static Log logger = LogFactory.getLog(PolicyEditorScopes.class); + + private static String domain; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name="id") + private int id; + + @Column(name="scopeName", nullable=false, unique=true) + @OrderBy("asc") + private String scopeName; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="created_date", updatable=false) + private Date createdDate; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="modified_date", nullable=false) + private Date modifiedDate; + + @ManyToOne(optional = false) + @JoinColumn(name="created_by") + private UserInfo userCreatedBy; + + @ManyToOne(optional = false) + @JoinColumn(name="modified_by") + private UserInfo userModifiedBy; + + public PolicyEditorScopes() { + } + + public PolicyEditorScopes(String string, String userid) { + this(domain); + } + + public PolicyEditorScopes(String domain) { + this.scopeName = domain; + } + + @PrePersist + public void prePersist() { + Date date = new Date(); + this.createdDate = date; + this.modifiedDate = date; + } + + @PreUpdate + public void preUpdate() { + this.modifiedDate = new Date(); + try { + this.userModifiedBy =XacmlAdminAuthorization.getUserId(); + } catch (Exception e) { + logger.error("Exception caused While adding Modified by Role"+e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyEditorScopes", "Exception caused While adding Modified by Role"); + } + } + + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + + public String getScopeName() { + return scopeName; + } + + public void setScopeName(String scopeName) { + this.scopeName = scopeName; + } + + public Date getCreatedDate() { + return this.createdDate; + } + + public void setCreatedDate(Date createdDate) { + this.createdDate = createdDate; + } + + public Date getModifiedDate() { + return this.modifiedDate; + } + + public void setModifiedDate(Date modifiedDate) { + this.modifiedDate = modifiedDate; + } + + public UserInfo getUserCreatedBy() { + return userCreatedBy; + } + + public void setUserCreatedBy(UserInfo userCreatedBy) { + this.userCreatedBy = userCreatedBy; + } + + public UserInfo getUserModifiedBy() { + return userModifiedBy; + } + + public void setUserModifiedBy(UserInfo userModifiedBy) { + this.userModifiedBy = userModifiedBy; + } + +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PolicyEntity.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PolicyEntity.java new file mode 100644 index 000000000..80869c225 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PolicyEntity.java @@ -0,0 +1,318 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; +/* + */ +import java.io.Serializable; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Index; +import javax.persistence.JoinColumn; +import javax.persistence.Lob; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.OneToOne; +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; +import javax.persistence.SequenceGenerator; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import javax.persistence.UniqueConstraint; +import javax.persistence.Version; + +import com.fasterxml.jackson.annotation.JsonBackReference; +import com.fasterxml.jackson.annotation.JsonManagedReference; + +/* + * The Entity class to persist a policy object and its configuration data + */ + +/** + * + */ +@Entity +//Add a non-unique index and a constraint that says the combo of policyName and scopeId must be unique +@Table(name="PolicyEntity", indexes = {@Index(name="scope", columnList="scope", unique=false), + @Index(name="policyName", columnList="policyName", unique=false)}, + uniqueConstraints=@UniqueConstraint(columnNames={"policyName", "scope"})) + +//Using a sequence generator because the value is available as soon as the +//the object is persisted. That is, you don't have to flush/commit to the DB. +//@SequenceGenerator(name="seqPolicy", initialValue=1, allocationSize=1) + +@NamedQueries({ + @NamedQuery(name="PolicyEntity.findAll", query="SELECT e FROM PolicyEntity e "), + @NamedQuery(name="PolicyEntity.findAllByDeletedFlag", query="SELECT e FROM PolicyEntity e WHERE e.deleted = :deleted"), + @NamedQuery(name="PolicyEntity.FindById", query="SELECT e FROM PolicyEntity e WHERE e.policyId = :id"), + @NamedQuery(name="PolicyEntity.deleteAll", query="DELETE FROM PolicyEntity WHERE 1=1"), + @NamedQuery(name="PolicyEntity.findByNameAndScope", query="SELECT e FROM PolicyEntity e WHERE e.policyName = :name AND e.scope = :scope") +}) + +public class PolicyEntity implements Serializable { + private static final long serialVersionUID = 1L; + + @Id + //@GeneratedValue(strategy = GenerationType.SEQUENCE, generator="seqPolicy") + @GeneratedValue(strategy = GenerationType.AUTO) + @Column (name="policyId") + @JsonBackReference + private long policyId; + + @Column(name="policyName", nullable=false, unique=false, length=255) + private String policyName; + + //The scope is the directory structure in dot notation. For example: org.openecomp.myproject + @Column(name="scope", nullable=false, unique=false, length=255) + private String scope; + + @Version + @Column(name="version") + private int version; + + //not going to be used + @Column(name="policyVersion") + private int policyVersion = 0; + + @Lob + @Column(name="policyData", nullable=false, columnDefinition="TEXT") + private String policyData = "NoData"; + + @OneToOne(optional=true, orphanRemoval=true) + @JoinColumn(name="configurationDataId", referencedColumnName="configurationDataId") + @JsonManagedReference + private ConfigurationDataEntity configurationDataEntity; + + @OneToOne(optional=true, orphanRemoval=true) + @JoinColumn(name="actionBodyId", referencedColumnName="actionBodyId") + @JsonManagedReference + private ActionBodyEntity actionBodyEntity; + + @Column(name="created_by", nullable=false, length=255) + private String createdBy = "guest"; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="created_date", updatable=false) + private Date createdDate; + + @Column(name="description", nullable=false, length=2048) + private String description = "NoDescription"; + + @Column(name="modified_by", nullable=false, length=255) + private String modifiedBy = "guest"; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="modified_date", nullable=false) + private Date modifiedDate; + + @Column(name="deleted", nullable=false) + private boolean deleted = false; + + public PolicyEntity() { + super(); + } + + @PrePersist + public void prePersist() { + Date date = new Date(); + this.createdDate = date; + this.modifiedDate = date; + } + + @PreUpdate + public void preUpdate() { + this.modifiedDate = new Date(); + } + + /* + public void resetPolicyVersion(){ + this.policyVersion = 1; + } + public void advancePolicyVersion(){ + this.policyVersion++; + } + public int getPolicyVersion(){ + return this.policyVersion; + } + public void setPolicyVersion(int polVer){ + this.policyVersion = polVer; + } + */ + + /** + * @return the policyId + */ + public long getPolicyId() { + return policyId; + } + + /** + * @param policyId cannot be set + */ + + public String getPolicyName() { + return policyName; + } + + public void setPolicyName(String policyName) { + this.policyName = policyName; + } + + /** + * @return the policyData + */ + public String getPolicyData() { + return policyData; + } + + /** + * @param policyData the policyData to set + */ + public void setPolicyData(String policyData) { + this.policyData = policyData; + } + + /** + * @return the configurationDataEntity + */ + public ConfigurationDataEntity getConfigurationData() { + return configurationDataEntity; + } + + /** + * @param configurationDataEntity the configurationDataEntity to set + */ + public void setConfigurationData(ConfigurationDataEntity configurationDataEntity) { + this.configurationDataEntity = configurationDataEntity; + } + + /** + * @return the actionBodyEntity + */ + public ActionBodyEntity getActionBodyEntity() { + return actionBodyEntity; + } + + /** + * @param actionBodyEntity the actionBodyEntity to set + */ + public void setActionBodyEntity(ActionBodyEntity actionBodyEntity) { + this.actionBodyEntity = actionBodyEntity; + } + + /** + * @return the scope + */ + public String getScope() { + return scope; + } + + /** + * @param scope the scope to set + */ + public void setScope(String scope) { + this.scope = scope; + } + + /** + * @return the createdBy + */ + public String getCreatedBy() { + return createdBy; + } + + /** + * @param createdBy the createdBy to set + */ + public void setCreatedBy(String createdBy) { + this.createdBy = createdBy; + } + + /** + * @return the description + */ + public String getDescription() { + return description; + } + + /** + * @param description the description to set + */ + public void setDescription(String description) { + this.description = description; + } + + /** + * @return the modifiedBy + */ + public String getModifiedBy() { + return modifiedBy; + } + + /** + * @param modifiedBy the modifiedBy to set + */ + public void setModifiedBy(String modifiedBy) { + this.modifiedBy = modifiedBy; + } + + /** + * @return the version + */ + public int getVersion() { + return version; + } + + /** + * @return the createdDate + */ + public Date getCreatedDate() { + return createdDate; + } + + /** + * @return the modifiedDate + */ + public Date getModifiedDate() { + return modifiedDate; + } + + /** + * @return the deleted + */ + public boolean isDeleted() { + return deleted; + } + + /** + * @param deleted the deleted to set + */ + public void setDeleted(boolean deleted) { + this.deleted = deleted; + } + + +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PolicyManagement.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PolicyManagement.java new file mode 100644 index 000000000..3f036d555 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PolicyManagement.java @@ -0,0 +1,162 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; + +import java.io.Serializable; +import java.sql.Clob; +import java.sql.Timestamp; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.NamedQuery; +import javax.persistence.Table; + + +/** + * The persistent class for the roles database table. + * + */ +@Entity +@Table(name="policy_manangement") +@NamedQuery(name="PolicyManagement.findAll", query="SELECT r FROM PolicyManagement r") +public class PolicyManagement implements Serializable { + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + + @Column(name="id") + private int id; + + @Column(name="POLICY_NAME", nullable=false, length=45) + private String policyName; + + @Column(name="scope", nullable=false, length=45) + private String scope; + + @Column(name="ECOMP_NAME", nullable=false, length=45) + private String ecompName; + + @Column(name="CONFIG_NAME", nullable=false, length=45) + private String configName; + + @Column(name="XML", nullable=false) + private Clob xml; + + @Column(name="CREATE_DATE_TIME", nullable=false) + private Timestamp createDateTime; + + + @Column(name="CREATED_BY", nullable=false, length=45) + private String createdBy; + + @Column(name="UPDATE_DATE_TIME", nullable=false) + private Timestamp updateDateTime; + + @Column(name="UPDATED_BY", nullable=false, length=45) + private String updatedBy; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getPolicyName() { + return policyName; + } + + public void setPolicyName(String policyName) { + this.policyName = policyName; + } + + public String getScope() { + return scope; + } + + public void setScope(String scope) { + this.scope = scope; + } + + public String getEcompName() { + return ecompName; + } + + public void setEcompName(String ecompName) { + this.ecompName = ecompName; + } + + public String getConfigName() { + return configName; + } + + public void setConfigName(String configName) { + this.configName = configName; + } + + public Clob getXml() { + return xml; + } + + public void setXml(Clob xml) { + this.xml = xml; + } + + public Timestamp getCreateDateTime() { + return createDateTime; + } + + public void setCreateDateTime(Timestamp createDateTime) { + this.createDateTime = createDateTime; + } + + public String getCreatedBy() { + return createdBy; + } + + public void setCreatedBy(String createdBy) { + this.createdBy = createdBy; + } + + public Timestamp getUpdateDateTime() { + return updateDateTime; + } + + public void setUpdateDateTime(Timestamp updateDateTime) { + this.updateDateTime = updateDateTime; + } + + public String getUpdatedBy() { + return updatedBy; + } + + public void setUpdatedBy(String updatedBy) { + this.updatedBy = updatedBy; + } + + + +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PolicyRoles.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PolicyRoles.java new file mode 100644 index 000000000..71df02b99 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PolicyRoles.java @@ -0,0 +1,102 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; +/* + */ +import java.io.Serializable; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.NamedQuery; +import javax.persistence.OrderBy; +import javax.persistence.Table; + +import org.openecomp.policy.rest.jpa.UserInfo; + + +/** + * The persistent class for the roles database table. + * + */ +@Entity +@Table(name="roles") +@NamedQuery(name="PolicyRoles.findAll", query="SELECT r FROM PolicyRoles r ") +public class PolicyRoles implements Serializable { + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + + @Column(name="id") + private int id; + + @ManyToOne + @JoinColumn(name="loginid") + @OrderBy("asc") + private UserInfo loginid; + + public UserInfo getLoginId() { + return loginid; + } + + public void setLoginId(UserInfo loginid) { + this.loginid = loginid; + } + + @Column(name="scope", nullable=true, length=45) + private String scope; + + @Column(name="role", nullable=false, length=45) + private String role; + + public PolicyRoles() { + } + + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + + public String getScope() { + return this.scope; + } + + public void setScope(String scope) { + this.scope = scope; + + } + public String getRole() { + return this.role; + } + + public void setRole(String role) { + this.role = role; + } + +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PolicyScopeClosedLoop.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PolicyScopeClosedLoop.java new file mode 100644 index 000000000..484851d7b --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PolicyScopeClosedLoop.java @@ -0,0 +1,101 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; +/* + */ +import java.io.Serializable; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.NamedQuery; +import javax.persistence.OrderBy; +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; +import javax.persistence.Table; + + +@Entity +@Table(name="PolicyScopeClosedLoop") +@NamedQuery(name="PolicyScopeClosedLoop.findAll", query="SELECT e FROM PolicyScopeClosedLoop e ") +public class PolicyScopeClosedLoop implements Serializable { + private static final long serialVersionUID = 1L; + + private static String domain; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name="id") + private int id; + + @Column(name="name", nullable=false) + @OrderBy("asc") + private String name; + + @Column(name="description ") + private String description ; + + public PolicyScopeClosedLoop() { + + } + public PolicyScopeClosedLoop(String string, String userid) { + this(domain); + + } + public PolicyScopeClosedLoop(String domain) { + + } + + @PrePersist + public void prePersist() { + + } + @PreUpdate + public void preUpdate() { + } + + + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + + } + public String getDescriptionValue() { + return this.description ; + } + + public void setDescriptionValue(String description ) { + this.description = description ; + } +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PolicyScopeResource.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PolicyScopeResource.java new file mode 100644 index 000000000..e126c4118 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PolicyScopeResource.java @@ -0,0 +1,101 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; +/* + */ +import java.io.Serializable; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.NamedQuery; +import javax.persistence.OrderBy; +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; +import javax.persistence.Table; + + +@Entity +@Table(name="PolicyScopeResource") +@NamedQuery(name="PolicyScopeResource.findAll", query="SELECT e FROM PolicyScopeResource e ") +public class PolicyScopeResource implements Serializable { + private static final long serialVersionUID = 1L; + + private static String domain; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name="id") + private int id; + + @Column(name="name", nullable=false) + @OrderBy("asc") + private String name; + + @Column(name="description ") + private String description ; + + public PolicyScopeResource() { + + } + public PolicyScopeResource(String string, String userid) { + this(domain); + + } + public PolicyScopeResource(String domain) { + + } + + @PrePersist + public void prePersist() { + + } + @PreUpdate + public void preUpdate() { + } + + + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + + } + public String getDescriptionValue() { + return this.description ; + } + + public void setDescriptionValue(String description ) { + this.description = description ; + } +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PolicyScopeService.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PolicyScopeService.java new file mode 100644 index 000000000..cc8c11383 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PolicyScopeService.java @@ -0,0 +1,101 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; +/* + */ +import java.io.Serializable; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.NamedQuery; +import javax.persistence.OrderBy; +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; +import javax.persistence.Table; + + +@Entity +@Table(name="PolicyScopeService") +@NamedQuery(name="PolicyScopeService.findAll", query="SELECT e FROM PolicyScopeService e ") +public class PolicyScopeService implements Serializable { + private static final long serialVersionUID = 1L; + + private static String domain; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name="id") + private int id; + + @Column(name="name", nullable=false) + @OrderBy("asc") + private String name; + + @Column(name="description ") + private String description ; + + public PolicyScopeService() { + + } + public PolicyScopeService(String string, String userid) { + this(domain); + + } + public PolicyScopeService(String domain) { + + } + + @PrePersist + public void prePersist() { + + } + @PreUpdate + public void preUpdate() { + } + + + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + + } + public String getDescriptionValue() { + return this.description ; + } + + public void setDescriptionValue(String description ) { + this.description = description ; + } +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PolicyScopeType.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PolicyScopeType.java new file mode 100644 index 000000000..d4ade7fe9 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PolicyScopeType.java @@ -0,0 +1,101 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; +/* + */ +import java.io.Serializable; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.NamedQuery; +import javax.persistence.OrderBy; +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; +import javax.persistence.Table; + + +@Entity +@Table(name="PolicyScopeType") +@NamedQuery(name="PolicyScopeType.findAll", query="SELECT e FROM PolicyScopeType e ") +public class PolicyScopeType implements Serializable { + private static final long serialVersionUID = 1L; + + private static String domain; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name="id") + private int id; + + @Column(name="name", nullable=false) + @OrderBy("asc") + private String name; + + @Column(name="description ") + private String description ; + + public PolicyScopeType() { + + } + public PolicyScopeType(String string, String userid) { + this(domain); + + } + public PolicyScopeType(String domain) { + + } + + @PrePersist + public void prePersist() { + + } + @PreUpdate + public void preUpdate() { + } + + + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + + } + public String getDescriptionValue() { + return this.description ; + } + + public void setDescriptionValue(String description ) { + this.description = description ; + } +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PolicyScore.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PolicyScore.java new file mode 100644 index 000000000..cae9cfc6a --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PolicyScore.java @@ -0,0 +1,109 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; +import java.io.Serializable; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.OrderBy; +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + + +@Entity +@Table(name="POLICYSCORE") +@NamedQueries({ + @NamedQuery(name="POLICYSCORE.findAll", query="SELECT p FROM PolicyScore p"), + @NamedQuery(name="POLICYSCORE.deleteAll", query="DELETE FROM PolicyScore WHERE 1=1"), + @NamedQuery(name="POLICYSCORE.findByPolicyName", query="Select p from PolicyScore p where p.PolicyName=:pname") +}) +public class PolicyScore implements Serializable { + + private static final long serialVersionUID = 1L; + + private static String domain; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name="id") + private int id; + + @Column(name="POLICY_NAME", nullable=false) + @OrderBy("asc") + private String PolicyName; + + @Column(name="VERSIONEXTENSION", nullable=false) + @OrderBy("asc") + private String VersionExtension; + + @Column(name="POLICY_SCORE", nullable=true) + private String PolicyScore; + + public PolicyScore() { + + } + + public PolicyScore(String pName, String pScore) { + this(domain); + + } + public PolicyScore(String domain) { + + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + public String getPolicyName() { + return PolicyName; + } + public void setPolicyName(String policyName) { + PolicyName = policyName; + } + public String getVersionExtension() { + return VersionExtension; + } + + public void setVersionExtension(String versionExtension) { + VersionExtension = versionExtension; + } + public String getPolicyScore() { + return PolicyScore; + } + public void setPolicyScore(String policyScore) { + PolicyScore = policyScore; + } + + +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PolicyVersion.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PolicyVersion.java new file mode 100644 index 000000000..73d39ad8e --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PolicyVersion.java @@ -0,0 +1,182 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; + +import java.io.Serializable; +//import java.sql.Clob; +import java.sql.Timestamp; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + + +@Entity +@Table(name="PolicyVersion") +@NamedQueries({ + @NamedQuery(name="PolicyVersion.findAll", query="SELECT p FROM PolicyVersion p"), + @NamedQuery(name="PolicyVersion.deleteAll", query="DELETE FROM PolicyVersion WHERE 1=1"), + @NamedQuery(name="PolicyVersion.findByPolicyName", query="Select p from PolicyVersion p where p.policyName=:pname") +}) +public class PolicyVersion implements Serializable { + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + + @Column(name="id") + private int id; + + @Column(name="POLICY_NAME", nullable=false, length=255) + private String policyName; + + @Column(name="ACTIVE_VERSION") + private int activeVersion; + + @Column(name="HIGHEST_VERSION") + private int higherVersion; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="created_date", nullable=false) + private Date createdDate; + + + public int getActiveVersion() { + return activeVersion; + } + + public void setActiveVersion(int activeVersion) { + this.activeVersion = activeVersion; + } + + public int getHigherVersion() { + return higherVersion; + } + + public void setHigherVersion(int higherVersion) { + this.higherVersion = higherVersion; + } + + @Column(name="CREATED_BY", nullable=false, length=45) + private String createdBy; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="modified_date", nullable=false) + private Date modifiedDate; + + + @Column(name="modified_by", nullable=false, length=45) + private String modifiedBy; + + public PolicyVersion(String domain, String loginUserId) { + this(domain); + this.createdBy = loginUserId; + this.modifiedBy = loginUserId; + } + + public PolicyVersion(String domain) { + this.policyName = domain; + } + + public PolicyVersion(){ + + } + + @PrePersist + public void prePersist() { + Date date = new Date(); + this.createdDate = date; + this.modifiedDate = date; + } + + @PreUpdate + public void preUpdate() { + this.modifiedDate = new Date(); + /* + * The modifiedBy must be set via the setModifiedBy() method since PolicyVersion + * has been moved to XACML-REST module for access from the XACML-PAP-REST module + + String userid = ((XacmlAdminUI) UI.getCurrent()).getLoginUserId(); + this.modifiedBy =userid; + * + */ + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getPolicyName() { + return policyName; + } + + public void setPolicyName(String policyName) { + this.policyName = policyName; + } + + public Date getCreatedDate() { + return createdDate; + } + + public void setCreatedDate(Timestamp createdDate) { + this.createdDate = createdDate; + } + + public String getCreatedBy() { + return createdBy; + } + + public void setCreatedBy(String createdBy) { + this.createdBy = createdBy; + } + + public Date getModifiedDate() { + return modifiedDate; + } + + public void setModifiedDate(Timestamp modifiedDate) { + this.modifiedDate = modifiedDate; + } + + public String getModifiedBy() { + return modifiedBy; + } + + public void setModifiedBy(String modifiedBy) { + this.modifiedBy = modifiedBy; + } + +} + diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PortList.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PortList.java new file mode 100644 index 000000000..88ce58afc --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/PortList.java @@ -0,0 +1,107 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; +/* + */ +import java.io.Serializable; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.NamedQuery; +import javax.persistence.OrderBy; +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +@Entity +@Table(name="portlist") +@NamedQuery(name="PortList.findAll", query="SELECT e FROM PortList e ") +public class PortList implements Serializable { + private static final long serialVersionUID = 1L; + + private static String domain; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name="id") + private int id; + + @Column(name="portname", nullable=false) + @OrderBy("asc") + private String portName; + + @Column(name="description") + private String description; +/* + @Temporal(TemporalType.TIMESTAMP) + @Column(name="modified_date", nullable=false) + private Date modifiedDate;*/ + + public PortList() { + + } + public PortList(String string, String userid) { + this(domain); + + } + public PortList(String domain) { + + } + + @PrePersist + public void prePersist() { + + } + @PreUpdate + public void preUpdate() { + } + + + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + public String getPortName() { + return this.portName; + } + + public void setPortName(String portName) { + this.portName = portName; + + } + public String getDescription() { + return this.description; + } + + public void setDescription(String description) { + this.description = description; + } + +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/ProtocolList.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/ProtocolList.java new file mode 100644 index 000000000..a450c2551 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/ProtocolList.java @@ -0,0 +1,108 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; +/* + */ +import java.io.Serializable; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.NamedQuery; +import javax.persistence.OrderBy; +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +@Entity +@Table(name="protocollist") +@NamedQuery(name="ProtocolList.findAll", query="SELECT e FROM ProtocolList e ") +public class ProtocolList implements Serializable { + private static final long serialVersionUID = 1L; + + private static String domain; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name="id") + private int id; + + @Column(name="protocolname", nullable=false) + @OrderBy("asc") + private String protocolName; + + @Column(name="description") + private String description; +/* + @Temporal(TemporalType.TIMESTAMP) + @Column(name="modified_date", nullable=false) + private Date modifiedDate;*/ + + public ProtocolList() { + + } + public ProtocolList(String string, String userid) { + this(domain); + + } + public ProtocolList(String domain) { + + } + + @PrePersist + public void prePersist() { + + } + @PreUpdate + public void preUpdate() { + } + public String getProtocolName() { + return this.protocolName; + } + + public void setProtocolName(String protocolName) { + this.protocolName = protocolName; + + } + + public String getDescription() { + return this.description; + } + + public void setDescription(String description) { + this.description = description; + + } + + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/RemoteCatalogValues.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/RemoteCatalogValues.java new file mode 100644 index 000000000..c906c79cb --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/RemoteCatalogValues.java @@ -0,0 +1,103 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; +/* + */ +import java.io.Serializable; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.NamedQuery; +import javax.persistence.OrderBy; +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; +import javax.persistence.Table; + + +@Entity +@Table(name="RemoteCatalogValues") +@NamedQuery(name="RemoteCatalogValues.findAll", query="SELECT e FROM RemoteCatalogValues e ") +public class RemoteCatalogValues implements Serializable { + private static final long serialVersionUID = 1L; + + private static String domain; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name="id") + private int id; + + @Column(name="name", nullable=false) + @OrderBy("asc") + private String name; + + @Column(name="value") + private String value; + + + public RemoteCatalogValues() { + + } + public RemoteCatalogValues(String string, String userid) { + this(domain); + + } + public RemoteCatalogValues(String domain) { + + } + + @PrePersist + public void prePersist() { + + } + @PreUpdate + public void preUpdate() { + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + + } + +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/RiskType.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/RiskType.java new file mode 100644 index 000000000..da18c744e --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/RiskType.java @@ -0,0 +1,178 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; +/* + */ +import java.io.Serializable; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.NamedQuery; +import javax.persistence.OrderBy; +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openecomp.policy.rest.XacmlAdminAuthorization; +import org.openecomp.policy.rest.jpa.UserInfo; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonManagedReference; + +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.eelf.PolicyLogger; + + +@Entity +@Table(name="RiskType") +@NamedQuery(name="RiskType.findAll", query="SELECT e FROM RiskType e ") +public class RiskType implements Serializable { + private static final long serialVersionUID = 1L; + + private static String domain; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name="id") + private int id; + + @Column(name="name", nullable=false, unique=true) + @OrderBy("asc") + private String name; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="created_date", updatable=false) + private Date createdDate; + + @Column(name="description", nullable=true, length=2048) + private String description; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="modified_date", nullable=false) + private Date modifiedDate; + + @ManyToOne(optional = false) + @JoinColumn(name="created_by") + private UserInfo userCreatedBy; + + @ManyToOne(optional = false) + @JoinColumn(name="modified_by") + private UserInfo userModifiedBy; + + public UserInfo getUserCreatedBy() { + return userCreatedBy; + } + + public void setUserCreatedBy(UserInfo userCreatedBy) { + this.userCreatedBy = userCreatedBy; + } + + public UserInfo getUserModifiedBy() { + return userModifiedBy; + } + + public void setUserModifiedBy(UserInfo userModifiedBy) { + this.userModifiedBy = userModifiedBy; + } + + private static Log logger = LogFactory.getLog(RiskType.class); + + public RiskType() { + + } + + public RiskType(String string, String userid) { + this(domain); + } + + public RiskType(String domain) { + this.name = domain; + } + + @PrePersist + public void prePersist() { + Date date = new Date(); + this.createdDate = date; + this.modifiedDate = date; + } + + @PreUpdate + public void preUpdate() { + this.modifiedDate = new Date(); + try { + this.userModifiedBy =XacmlAdminAuthorization.getUserId(); + } catch (Exception e) { + logger.error("Exception caused While adding Modified by Role"+e); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "RiskType", "Exception caused While adding Modified by Role"); + } + } + public String getRiskName() { + return this.name; + } + + public void setRiskName(String riskName) { + this.name = riskName; + + } + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + + public Date getCreatedDate() { + return this.createdDate; + } + + public void setCreatedDate(Date createdDate) { + this.createdDate = createdDate; + } + + public String getDescription() { + return this.description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Date getModifiedDate() { + return this.modifiedDate; + } + + public void setModifiedDate(Date modifiedDate) { + this.modifiedDate = modifiedDate; + } + +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/RuleAlgorithms.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/RuleAlgorithms.java new file mode 100644 index 000000000..4ec0dff67 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/RuleAlgorithms.java @@ -0,0 +1,125 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/* + * AT&T - PROPRIETARY + * THIS FILE CONTAINS PROPRIETARY INFORMATION OF + * AT&T AND IS NOT TO BE DISCLOSED OR USED EXCEPT IN + * ACCORDANCE WITH APPLICABLE AGREEMENTS. + * + * Copyright (c) 2014 AT&T Knowledge Ventures + * Unpublished and Not for Publication + * All Rights Reserved + */ +package org.openecomp.policy.rest.jpa; + +import java.io.Serializable; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.NamedQuery; +import javax.persistence.Table; +import javax.persistence.Transient; + +import com.att.research.xacml.api.Identifier; + +@Entity +@Table(name="RuleAlgorithms") +@NamedQuery(name="RuleAlgorithms.findAll", query="SELECT d FROM RuleAlgorithms d") +public class RuleAlgorithms implements Serializable { + private static final long serialVersionUID = 1L; + + public static final char STANDARD = 'S'; + public static final char CUSTOM = 'C'; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name="id") + private int id; + + @Column(name="is_standard", nullable=false) + private char isStandard; + + @Column(name="xacml_id", nullable=false, unique=true, length=255) + private String xacmlId; + + @Column(name="short_name", nullable=false, length=64) + private String shortName; + + public RuleAlgorithms(Identifier id, char standard) { + if (id != null) { + this.xacmlId = id.stringValue(); + } + this.isStandard = standard; + } + public RuleAlgorithms(Identifier id) { + this(id, RuleAlgorithms.STANDARD); + } + + public RuleAlgorithms() { + this(null, RuleAlgorithms.STANDARD); + } + + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + + public char getIsStandard() { + return this.isStandard; + } + + public void setIsStandard(char isStandard) { + this.isStandard = isStandard; + } + + @Transient + public boolean isStandard() { + return (this.isStandard == RuleAlgorithms.STANDARD); + } + + @Transient + public boolean isCustom() { + return (this.isStandard == RuleAlgorithms.CUSTOM); + } + + public String getXacmlId() { + return this.xacmlId; + } + + public void setXacmlId(String xacmlId) { + this.xacmlId = xacmlId; + } + + public String getShortName() { + return shortName; + } + + public void setShortName(String shortName) { + this.shortName = shortName; + } + +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/SafePolicyWarning.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/SafePolicyWarning.java new file mode 100644 index 000000000..8d3a0f277 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/SafePolicyWarning.java @@ -0,0 +1,109 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; +/* + */ +import java.io.Serializable; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.NamedQuery; +import javax.persistence.OrderBy; +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; +import javax.persistence.Table; + + +@Entity +@Table(name="SafePolicyWarning") +@NamedQuery(name="SafePolicyWarning.findAll", query="SELECT e FROM SafePolicyWarning e ") +public class SafePolicyWarning implements Serializable { + private static final long serialVersionUID = 1L; + + private static String domain; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name="id") + private int id; + + @Column(name="name", nullable=false) + @OrderBy("asc") + private String name; + + @Column(name="message") + private String message ; + + @Column(name="riskType") + private String riskType ; + + public String getRiskType() { + return riskType; + } + public void setRiskType(String riskType) { + this.riskType = riskType; + } + public SafePolicyWarning() { + + } + public SafePolicyWarning(String string, String userid) { + this(domain); + + } + public SafePolicyWarning(String domain) { + + } + + @PrePersist + public void prePersist() { + + } + @PreUpdate + public void preUpdate() { + } + + + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + public String getName() { + return this.name; + } + + public String getMessage() { + return message; + } + public void setMessage(String message) { + this.message = message; + } + public void setName(String name) { + this.name = name; + + } + +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/SecurityZone.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/SecurityZone.java new file mode 100644 index 000000000..2fbd4486d --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/SecurityZone.java @@ -0,0 +1,104 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; +/* + */ +import java.io.Serializable; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.NamedQuery; +import javax.persistence.OrderBy; +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +@Entity +@Table(name="securityzone") +@NamedQuery(name="SecurityZone.findAll", query="SELECT e FROM SecurityZone e ") +public class SecurityZone implements Serializable { + private static final long serialVersionUID = 1L; + + private static String domain; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name="id") + private int id; + + @Column(name="name", nullable=false) + @OrderBy("asc") + private String zoneName; + + @Column(name="value") + private String zoneValue; + + + public SecurityZone() { + + } + public SecurityZone(String string, String userid) { + this(domain); + + } + public SecurityZone(String domain) { + + } + + @PrePersist + public void prePersist() { + + } + @PreUpdate + public void preUpdate() { + } + + + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + public String getZoneName() { + return this.zoneName; + } + + public void setZoneName(String zoneName) { + this.zoneName = zoneName; + + } + public String getZoneValue() { + return this.zoneValue; + } + + public void setZoneValue(String zoneValue) { + this.zoneValue = zoneValue; + } + +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/ServiceList.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/ServiceList.java new file mode 100644 index 000000000..9a72916b1 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/ServiceList.java @@ -0,0 +1,157 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; +/* + */ +import java.io.Serializable; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.NamedQuery; +import javax.persistence.OrderBy; +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +@Entity +@Table(name="servicegroup") +@NamedQuery(name="ServiceList.findAll", query="SELECT e FROM ServiceList e ") +public class ServiceList implements Serializable { + private static final long serialVersionUID = 1L; + + private static String domain; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name="id") + private int id; + + @Column(name="name", nullable=false) + @OrderBy("asc") + private String serviceName; + + @Column(name="description") + private String serviceDesc; + + @Column(name="type") + private String serviceType; + + @Column(name="transportprotocol") + private String serviceTrasProtocol; + + @Column(name="appprotocol ") + private String serviceAppProtocol; + + @Column(name="ports") + private String servicePorts; + + + +/* + @Temporal(TemporalType.TIMESTAMP) + @Column(name="modified_date", nullable=false) + private Date modifiedDate;*/ + + public ServiceList() { + + } + public ServiceList(String string, String userid) { + this(domain); + + } + public ServiceList(String domain) { + + } + + @PrePersist + public void prePersist() { + + } + @PreUpdate + public void preUpdate() { + } + + + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + public String getServiceName() { + return this.serviceName; + } + + public void setServiceName(String serviceName) { + this.serviceName = serviceName; + + } + + public String getServiceDescription() { + return this.serviceDesc; + } + + public void setServiceDescription(String serviceDesc) { + this.serviceDesc = serviceDesc; + + } + + public String getServiceType() { + return this.serviceType; + } + + public void setServiceType(String serviceType) { + this.serviceType = serviceType; + } + + public String getServiceTransProtocol() { + return this.serviceTrasProtocol; + } + + public void setServiceTransProtocol(String serviceTrasProtocol) { + this.serviceTrasProtocol = serviceTrasProtocol; + + } + + public String getServiceAppProtocol() { + return this.serviceAppProtocol; + } + + public void setServiceAppProtocol(String serviceAppProtocol) { + this.serviceAppProtocol = serviceAppProtocol; + + } + public String getServicePorts() { + return this.servicePorts; + } + + public void setServicePorts(String servicePorts) { + this.servicePorts = servicePorts; + + } +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/SystemLogDB.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/SystemLogDB.java new file mode 100644 index 000000000..a86857aee --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/SystemLogDB.java @@ -0,0 +1,173 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/* + * AT&T - PROPRIETARY + * THIS FILE CONTAINS PROPRIETARY INFORMATION OF + * AT&T AND IS NOT TO BE DISCLOSED OR USED EXCEPT IN + * ACCORDANCE WITH APPLICABLE AGREEMENTS. + * + * Copyright (c) 2013 AT&T Knowledge Ventures + * Unpublished and Not for Publication + * All Rights Reserved + */ +package org.openecomp.policy.rest.jpa; + +import java.io.Serializable; +import java.util.Date; +import java.util.HashSet; +import java.util.Set; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.NamedQuery; +import javax.persistence.OneToMany; +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import javax.persistence.Transient; + +import com.att.research.xacml.api.Identifier; + +/** + * The persistent class for the system log database table. + * +*/ +@Entity +@Table(name="SystemLogDB") +@NamedQuery(name="SystemLogDB.findAll", query="SELECT o FROM SystemLogDB o") +public class SystemLogDB implements Serializable { + private static final long serialVersionUID = 1L; + + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name="id") + private int id; + + @Column(name="type", nullable=false) + private String type; + + @Column(name="system", nullable=false, length=255) + private String system; + + @Column(name="description", nullable=true, length=2048) + private String description; + + @Column(name="remote", nullable=false, length=255) + private String remote; + + @Column(name="logtype", nullable=false, length=255) + private String logtype; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="date", nullable=false, updatable=false) + private Date date; + + public SystemLogDB() { + super(); + } + + public SystemLogDB(int id, String system, String description, String remote, + String type, String logtype) { + // TODO Auto-generated constructor stub + this.id = id; + this.system = system; + this.description = description; + this.remote = remote; + this.type = type; + this.logtype = logtype; + } + + public void SystemLogB (int id, String system, String description, String remote, String type, Date date, String logtype){ + this.id = id; + this.system = system; + this.description = description; + this.remote = remote; + this.type = type; + this.date = date; + this.logtype = logtype; + + } + + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + + public Date getDate(){ + return this.date; + } + + public void setDate(Date date){ + this.date = date; + } + + public String getDescription() { + return this.description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getType() { + return this.type; + } + + public void setType(String type) { + this.type = type; + + } + + public String getSystem() { + return this.system; + } + + public void setSystem(String system) { + this.system = system; + } + + public String getRemote() { + return this.remote; + } + + public void setRemote(String remote) { + this.remote = remote; + + } + public String getLogtype() { + return this.logtype; + } + + public void setLogtype(String logtype) { + this.logtype = logtype; + + } +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/TermList.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/TermList.java new file mode 100644 index 000000000..ce94fb8d8 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/TermList.java @@ -0,0 +1,262 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; + +import java.io.Serializable; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.NamedQuery; +import javax.persistence.OrderBy; +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openecomp.policy.rest.XacmlAdminAuthorization; + +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.eelf.PolicyLogger; + + +@Entity +@Table(name="TERM") +@NamedQuery(name="TermList.findAll", query="SELECT e FROM TermList e") +public class TermList implements Serializable { + private static final long serialVersionUID = 1L; + + private static String domain; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name="id") + private int id; + + @Column(name="termName", nullable=false) + @OrderBy("asc") + private String termName; + + @Column(name="description") + private String termDescription; + + @Column(name="fromzone") + private String fromZone; + + @Column(name="tozone") + private String toZone; + + @Column(name="srcIPList") + private String srcIPList; + + @Column(name="destIPList") + private String destIPList; + + @Column(name="protocolList") + private String protocolList; + + @Column(name="portList") + private String portList; + + @Column(name="srcPortList") + private String srcPortList; + + @Column(name="destPortList") + private String destPortList; + + @Column(name="action") + private String action; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="created_date", updatable=false) + private Date createdDate; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="modified_date", nullable=false) + private Date modifiedDate; + + @ManyToOne(optional = false) + @JoinColumn(name="created_by") + private UserInfo userCreatedBy; + + @ManyToOne(optional = false) + @JoinColumn(name="modified_by") + private UserInfo userModifiedBy; + + public UserInfo getUserCreatedBy() { + return userCreatedBy; + } + + public void setUserCreatedBy(UserInfo userCreatedBy) { + this.userCreatedBy = userCreatedBy; + } + + public UserInfo getUserModifiedBy() { + return userModifiedBy; + } + + public void setUserModifiedBy(UserInfo userModifiedBy) { + this.userModifiedBy = userModifiedBy; + } + + private static Log logger = LogFactory.getLog(TermList.class); + + public TermList() { + + } + + private static final Log auditLogger = LogFactory + .getLog("auditLogger"); + + public TermList(String string, String userid) { + this(domain); + } + public TermList(String domain) { + this.termName = domain; + } + + @PrePersist + public void prePersist() { + Date date = new Date(); + this.createdDate = date; + this.modifiedDate = date; + auditLogger.debug("Added New Term Name: "+this.termName+" by "+this.userCreatedBy); + + } + @PreUpdate + public void preUpdate() { + this.modifiedDate = new Date(); + try { + this.userModifiedBy =XacmlAdminAuthorization.getUserId();; + } catch (Exception e) { + logger.error("Exception caused While adding Modified by Role"+e); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "TermList", "Exception caused While adding Modified by Role"); + } + auditLogger.debug("Updated Term Name: "+this.termName+" by "+this.userModifiedBy); + } + + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + + public String getTermName() { + return this.termName; + } + + public void setTermName(String termName) { + this.termName = termName; + } + + public String getTermDescription() { + return this.termDescription; + } + + public void setDescription(String termDescription) { + this.termDescription = termDescription; + } + + public String getFromZone() { + return this.fromZone; + } + + public void setFromZones(String fromZone) { + this.fromZone = fromZone; + } + + public String getToZone() { + return this.toZone; + } + + public void setToZones(String toZone) { + this.toZone = toZone; + } + + public String getSrcIPList() { + return this.srcIPList; + } + + public void setSrcIPList(String srcIPList) { + this.srcIPList = srcIPList; + } + + public String getDestIPList() { + return this.destIPList; + } + + public void setDestIPList(String destIPList) { + this.destIPList = destIPList; + } + + public String getProtocolList() { + return this.protocolList; + } + + public void setProtocolList(String protocolList) { + this.protocolList = protocolList; + } + + public String getPortList() { + return this.portList; + } + + public void setPortList(String portList) { + this.portList = portList; + } + + public String getSrcPortList() { + return this.srcPortList; + } + + public void setSrcPortList(String srcPortList) { + this.srcPortList = srcPortList; + } + + public String getDestPortList() { + return this.destPortList; + } + + public void setDestPortList(String destPortList) { + this.destPortList = destPortList; + } + + + public String getAction() { + return this.action; + } + + public void setAction(String action) { + this.action = action; + } + +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/UserInfo.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/UserInfo.java new file mode 100644 index 000000000..6f5982aa8 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/UserInfo.java @@ -0,0 +1,76 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; + +import java.io.Serializable; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.NamedQuery; +import javax.persistence.Table; +import javax.persistence.Transient; + +import com.att.research.xacml.api.Identifier; +import com.att.research.xacml.std.IdentifierImpl; +import com.fasterxml.jackson.annotation.JsonBackReference; + +@Entity +@Table(name = "UserInfo") +@NamedQuery(name="UserInfo.findAll", query="SELECT u FROM UserInfo u ") +public class UserInfo implements Serializable { + private static final long serialVersionUID = 1L; + + @Id + @Column(name="loginId", nullable=false, length=45) + private String userLoginId; + + @Column(name = "name", nullable = false, unique = true) + private String userName; + + public UserInfo(){ + this.userLoginId = userName; + + } + + public String getUserLoginId() { + return userLoginId; + } + + public void setUserLoginId(String loginid) { + this.userLoginId = loginid; + } + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + @Transient + @JsonBackReference + public Identifier getIdentiferByUserId() { + return new IdentifierImpl(this.userName); + } + +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/VMType.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/VMType.java new file mode 100644 index 000000000..a1adcd447 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/VMType.java @@ -0,0 +1,103 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; +/* + */ +import java.io.Serializable; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.NamedQuery; +import javax.persistence.OrderBy; +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; +import javax.persistence.Table; + + +@Entity +@Table(name="VMType") +@NamedQuery(name="VMType.findAll", query="SELECT e FROM VMType e ") +public class VMType implements Serializable { + private static final long serialVersionUID = 1L; + + private static String domain; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name="id") + private int id; + + @Column(name="name", nullable=false) + @OrderBy("asc") + private String name; + + @Column(name="description") + private String description; + + + public VMType() { + + } + public VMType(String string, String userid) { + this(domain); + + } + public VMType(String domain) { + + } + + @PrePersist + public void prePersist() { + + } + @PreUpdate + public void preUpdate() { + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + + } + +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/VNFType.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/VNFType.java new file mode 100644 index 000000000..a2c19da31 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/VNFType.java @@ -0,0 +1,174 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; + +import java.io.Serializable; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.NamedQuery; +import javax.persistence.OrderBy; +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openecomp.policy.rest.XacmlAdminAuthorization; + +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.eelf.PolicyLogger; + + + +@Entity +@Table(name="VNFType") +@NamedQuery(name="VNFType.findAll", query="SELECT v FROM VNFType v ") +public class VNFType implements Serializable { + private static final long serialVersionUID = 1L; + + private static String domain; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name="id") + private int id; + + @Column(name="vnf_type", nullable=false, unique=true) + @OrderBy("asc") + private String vnftype; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="created_date", updatable=false) + private Date createdDate; + + @Column(name="description", nullable=true, length=2048) + private String description; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="modified_date", nullable=false) + private Date modifiedDate; + + @ManyToOne(optional = false) + @JoinColumn(name="created_by") + private UserInfo userCreatedBy; + + @ManyToOne(optional = false) + @JoinColumn(name="modified_by") + private UserInfo userModifiedBy; + + public UserInfo getUserCreatedBy() { + return userCreatedBy; + } + + public void setUserCreatedBy(UserInfo userCreatedBy) { + this.userCreatedBy = userCreatedBy; + } + + public UserInfo getUserModifiedBy() { + return userModifiedBy; + } + + public void setUserModifiedBy(UserInfo userModifiedBy) { + this.userModifiedBy = userModifiedBy; + } + + private static Log logger = LogFactory.getLog(VNFType.class); + + public VNFType() { + + } + + public String getVnftype() { + return vnftype; + } + + public void setVnftype(String vnftype) { + this.vnftype = vnftype; + } + + public VNFType(String string, String userid) { + this(domain); + } + + public VNFType(String domain) { + this.vnftype = domain; + } + + @PrePersist + public void prePersist() { + Date date = new Date(); + this.createdDate = date; + this.modifiedDate = date; + } + + @PreUpdate + public void preUpdate() { + this.modifiedDate = new Date(); + try { + this.userModifiedBy =XacmlAdminAuthorization.getUserId();; + } catch (Exception e) { + logger.error("Exception caused While adding Modified by Role"+e); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "VNFType", "Exception caused While adding Modified by Role"); + } + } + + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + + public Date getCreatedDate() { + return this.createdDate; + } + + public void setCreatedDate(Date createdDate) { + this.createdDate = createdDate; + } + + public String getDescription() { + return this.description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Date getModifiedDate() { + return this.modifiedDate; + } + + public void setModifiedDate(Date modifiedDate) { + this.modifiedDate = modifiedDate; + } +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/VSCLAction.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/VSCLAction.java new file mode 100644 index 000000000..39d671f1d --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/VSCLAction.java @@ -0,0 +1,174 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; + +import java.io.Serializable; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.NamedQuery; +import javax.persistence.OrderBy; +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openecomp.policy.rest.XacmlAdminAuthorization; + +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.eelf.PolicyLogger; + + +@Entity +@Table(name="VSCLAction") +@NamedQuery(name="VSCLAction.findAll", query="SELECT v FROM VSCLAction v ") +public class VSCLAction implements Serializable { + private static final long serialVersionUID = 1L; + + private static String domain; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name="id") + private int id; + + @Column(name="vscl_action", nullable=false, unique=true) + @OrderBy("asc") + private String vsclaction; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="created_date", updatable=false) + private Date createdDate; + + @Column(name="description", nullable=true, length=2048) + private String description; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="modified_date", nullable=false) + private Date modifiedDate; + + @ManyToOne(optional = false) + @JoinColumn(name="created_by") + private UserInfo userCreatedBy; + + @ManyToOne(optional = false) + @JoinColumn(name="modified_by") + private UserInfo userModifiedBy; + + public UserInfo getUserCreatedBy() { + return userCreatedBy; + } + + public void setUserCreatedBy(UserInfo userCreatedBy) { + this.userCreatedBy = userCreatedBy; + } + + public UserInfo getUserModifiedBy() { + return userModifiedBy; + } + + public void setUserModifiedBy(UserInfo userModifiedBy) { + this.userModifiedBy = userModifiedBy; + } + + private static Log logger = LogFactory.getLog(VSCLAction.class); + + public VSCLAction() { + + } + + public VSCLAction(String string, String userid) { + this(domain); + } + + public VSCLAction(String domain) { + this.vsclaction = domain; + } + + @PrePersist + public void prePersist() { + Date date = new Date(); + this.createdDate = date; + this.modifiedDate = date; + } + + @PreUpdate + public void preUpdate() { + this.modifiedDate = new Date(); + try { + this.userModifiedBy =XacmlAdminAuthorization.getUserId();; + } catch (Exception e) { + logger.error("Exception caused While adding Modified by Role"+e); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "VSCLAction", "Exception caused While adding Modified by Role"); + } + } + + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + + public String getVsclaction() { + return vsclaction; + } + + public void setVsclaction(String vsclaction) { + this.vsclaction = vsclaction; + } + + + public Date getCreatedDate() { + return this.createdDate; + } + + public void setCreatedDate(Date createdDate) { + this.createdDate = createdDate; + } + + public String getDescription() { + return this.description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Date getModifiedDate() { + return this.modifiedDate; + } + + public void setModifiedDate(Date modifiedDate) { + this.modifiedDate = modifiedDate; + } +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/VarbindDictionary.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/VarbindDictionary.java new file mode 100644 index 000000000..05e5710d7 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/VarbindDictionary.java @@ -0,0 +1,185 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; + +import java.io.Serializable; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.NamedQuery; +import javax.persistence.OrderBy; +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openecomp.policy.rest.XacmlAdminAuthorization; + +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.eelf.PolicyLogger; + +@Entity +@Table(name="VarbindDictionary") +@NamedQuery(name = "VarbindDictionary.findAll", query = "Select v FROM VarbindDictionary v") +public class VarbindDictionary implements Serializable{ + private static final long serialVersionUID = 1L; + + private static String domain; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "Id") + private int id; + + @Column(name ="varbind_Name", nullable = false, unique = true) + @OrderBy("asc") + private String varbindName; + + @Column(name = "varbind_Description", nullable = true, length = 2048) + private String varbindDescription; + + @Column(name = "varbind_oid", nullable = false) + private String varbindOID; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="created_date", updatable=false) + private Date createdDate; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="modified_date", nullable=false) + private Date modifiedDate; + + @ManyToOne(optional = false) + @JoinColumn(name="created_by") + private UserInfo userCreatedBy; + + @ManyToOne(optional = false) + @JoinColumn(name="modified_by") + private UserInfo userModifiedBy; + + public UserInfo getUserCreatedBy() { + return userCreatedBy; + } + + public void setUserCreatedBy(UserInfo userCreatedBy) { + this.userCreatedBy = userCreatedBy; + } + + public UserInfo getUserModifiedBy() { + return userModifiedBy; + } + + public void setUserModifiedBy(UserInfo userModifiedBy) { + this.userModifiedBy = userModifiedBy; + } + + private static Log logger = LogFactory.getLog(VarbindDictionary.class); + + public VarbindDictionary() { + + } + + public VarbindDictionary(String string, String userid) { + this(domain); + } + + public VarbindDictionary(String domain) { + this.varbindName = domain; + } + + @PrePersist + public void prePersist() { + Date date = new Date(); + this.createdDate = date; + this.modifiedDate = date; + } + + @PreUpdate + public void preUpdate() { + this.modifiedDate = new Date(); + try { + this.userModifiedBy =XacmlAdminAuthorization.getUserId();; + } catch (Exception e) { + logger.error("Exception caused While adding Modified by Role"+e); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "VarbindDictionary", "Exception caused While adding Modified by Role"); + } + } + + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + + public String getVarbindName() { + return varbindName; + } + + public void setVarbindName(String varbindName) { + this.varbindName = varbindName; + } + + public String getVarbindDescription() { + return varbindDescription; + } + + public void setVarbindDescription(String varbindDescription) { + this.varbindDescription = varbindDescription; + } + + public String getVarbindOID() { + return varbindOID; + } + + public void setVarbindOID(String varbindOID) { + this.varbindOID = varbindOID; + } + + public Date getCreatedDate() { + return createdDate; + } + + public void setCreatedDate(Date createdDate) { + this.createdDate = createdDate; + } + + public Date getModifiedDate() { + return modifiedDate; + } + + public void setModifiedDate(Date modifiedDate) { + this.modifiedDate = modifiedDate; + } + + +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/WatchPolicyNotificationTable.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/WatchPolicyNotificationTable.java new file mode 100644 index 000000000..2acc82cce --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/WatchPolicyNotificationTable.java @@ -0,0 +1,80 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; +/* + * + * + * */ + +import java.io.Serializable; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.NamedQuery; +import javax.persistence.OrderBy; +import javax.persistence.Table; + +@Entity +@Table(name = "WatchPolicyNotificationTable") +@NamedQuery(name="WatchPolicyNotificationTable.findAll", query="SELECT e FROM WatchPolicyNotificationTable e ") +public class WatchPolicyNotificationTable implements Serializable{ + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name="id") + private int id; + + @Column(name="policyName", nullable=false, unique=true) + @OrderBy("asc") + private String policyName; + + @Column(name="loginIds", nullable=false, unique=true) + @OrderBy("asc") + private String loginIds; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getPolicyName() { + return policyName; + } + + public void setPolicyName(String policyName) { + this.policyName = policyName; + } + + public String getLoginIds() { + return loginIds; + } + + public void setLoginIds(String loginIds) { + this.loginIds = loginIds; + } +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/Zone.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/Zone.java new file mode 100644 index 000000000..e1db124c3 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/Zone.java @@ -0,0 +1,104 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.jpa; +/* + */ +import java.io.Serializable; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.NamedQuery; +import javax.persistence.OrderBy; +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +@Entity +@Table(name="zone") +@NamedQuery(name="Zone.findAll", query="SELECT e FROM Zone e ") +public class Zone implements Serializable { + private static final long serialVersionUID = 1L; + + private static String domain; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name="id") + private int id; + + @Column(name="zonename", nullable=false) + @OrderBy("asc") + private String zoneName; + + @Column(name="zonevalue") + private String zoneValue; + + + public Zone() { + + } + public Zone(String string, String userid) { + this(domain); + + } + public Zone(String domain) { + + } + + @PrePersist + public void prePersist() { + + } + @PreUpdate + public void preUpdate() { + } + + + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + public String getZoneName() { + return this.zoneName; + } + + public void setZoneName(String zoneName) { + this.zoneName = zoneName; + + } + public String getZoneValue() { + return this.zoneValue; + } + + public void setZoneValue(String zoneValue) { + this.zoneValue = zoneValue; + } + +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/package-info.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/package-info.java new file mode 100644 index 000000000..d5b935077 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/jpa/package-info.java @@ -0,0 +1,27 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + * + */ +/** + * + */ +package org.openecomp.policy.rest.jpa; diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/util/LockdownListener.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/util/LockdownListener.java new file mode 100644 index 000000000..a44ef63d8 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/util/LockdownListener.java @@ -0,0 +1,36 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + * + */ +package org.openecomp.policy.rest.util; + +public interface LockdownListener { + /** + * lockdown has been set in database + */ + public void lockdownSet(); + + /** + * lockdown has been unset in the database + */ + public void lockdownUnset(); +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/util/MSAttributeObject.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/util/MSAttributeObject.java new file mode 100644 index 000000000..45b5aefb8 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/util/MSAttributeObject.java @@ -0,0 +1,88 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.util; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class MSAttributeObject { + + private String className; + private HashMap attribute = new HashMap(); + private HashMap refAttribute = new HashMap(); + private HashMap subClass = new HashMap(); + private String dependency; + private List enumType; + + + public Map getRefAttribute() { + return refAttribute; + } + public void setRefAttribute(HashMap refAttribute) { + this.refAttribute = refAttribute; + } + public String getClassName() { + return className; + } + public void setClassName(String className) { + this.className = className; + } + public Map getAttribute() { + return attribute; + } + public void setAttribute(HashMap attribute) { + this.attribute = attribute; + } + public List getEnumType() { + return enumType; + } + public void setEnumType(List enumType) { + this.enumType = enumType; + } + public void addAttribute(String key, String value){ + this.attribute.put(key, value); + } + public void addRefAttribute(String key, String value){ + this.refAttribute.put(key, value); + } + public void addAllAttribute(Map map){ + this.attribute.putAll(map); + } + public void addAllRefAttribute(Map map){ + this.refAttribute.putAll(map); + } + public HashMap getSubClass() { + return subClass; + } + public void setSubClass(HashMap subClass) { + this.subClass = subClass; + } + public void addAllSubClass(HashMap subClass){ + this.subClass.putAll(subClass); + } + public String getDependency() { + return dependency; + } + public void setDependency(String dependency) { + this.dependency = dependency; + } +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/util/MSAttributeValue.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/util/MSAttributeValue.java new file mode 100644 index 000000000..cce8f7619 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/util/MSAttributeValue.java @@ -0,0 +1,60 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.util; + +public class MSAttributeValue{ + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + public String getType() { + return type; + } + public void setType(String type) { + this.type = type; + } + public Boolean getRequired() { + return required; + } + public void setRequired(Boolean required) { + this.required = required; + } + public Boolean getArrayValue() { + return arrayValue; + } + public void setArrayValue(Boolean arrayValue) { + this.arrayValue = arrayValue; + } + public String getDefaultValue() { + return defaultValue; + } + public void setDefaultValue(String defaultValue) { + this.defaultValue = defaultValue; + } + private String name; + private String type; + private Boolean required; + private Boolean arrayValue; + private String defaultValue; + +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/util/MSModelUtitils.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/util/MSModelUtitils.java new file mode 100644 index 000000000..dd015be68 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/util/MSModelUtitils.java @@ -0,0 +1,450 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.util; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.apache.commons.lang.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.common.util.TreeIterator; +import org.eclipse.emf.ecore.EAnnotation; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EClassifier; +import org.eclipse.emf.ecore.EEnum; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.emf.ecore.EStructuralFeature; + +import org.json.JSONObject; +import org.openecomp.policy.rest.XACMLRestProperties; + +import com.att.research.xacml.util.XACMLProperties; + +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; +import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; + + +public class MSModelUtitils { + + private static final Log logger = LogFactory.getLog(MSModelUtitils.class); + + private HashMap classMap = new HashMap(); + + public HashMap processEpackage(String xmiFile){ + EPackage root = getEpackage(xmiFile); + TreeIterator treeItr = root.eAllContents(); + String className = null; + String returnValue = null; + + // Pulling out dependency from file + while (treeItr.hasNext()) { + EObject obj = (EObject) treeItr.next(); + if (obj instanceof EClassifier) { + EClassifier eClassifier = (EClassifier) obj; + className = eClassifier.getName(); + + if (obj instanceof EEnum) { + // getEEnum(); + returnValue = null; + }else if (obj instanceof EClass) { + String temp = getDependencyList(eClassifier, className).toString(); + returnValue = StringUtils.replaceEach(temp, new String[]{"[", "]"}, new String[]{"", ""}); + getAttributes(className, returnValue, root); + } + } + } + return classMap; + } + + private EPackage getEpackage(String xmiFile) { + ResourceSet resSet = new ResourceSetImpl(); + Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE; + Map m = reg.getExtensionToFactoryMap(); + m.put("xmi", new XMIResourceFactoryImpl()); + Resource resource = resSet.getResource(URI.createFileURI(xmiFile), true); + try { + resource.load(Collections.EMPTY_MAP); + } catch (IOException e) { + logger.error("Error loading Encore Resource for new Model"); + } + + EPackage root = (EPackage) resource.getContents().get(0); + + return root; + } + + private void getEEnum() { + + } + + public void getAttributes(String className, String dependency, EPackage root) { + List dpendList = null; + if (dependency!=null){ + dpendList = new ArrayList(Arrays.asList(dependency.split(","))); + } + MSAttributeObject msAttributeObject = new MSAttributeObject(); + msAttributeObject.setClassName(className); + HashMap returnRefList = getRefAttributeList(root, className); + HashMap returnAttributeList = getAttributeList(root, className); + HashMap returnSubList = getSubAttributeList(root, className); + msAttributeObject.setAttribute(returnAttributeList); + msAttributeObject.setRefAttribute(returnRefList); + msAttributeObject.setSubClass(returnSubList); + msAttributeObject.setDependency(dpendList.toString()); + this.classMap.put(className, msAttributeObject); + } + + private HashMap getSubAttributeList(EPackage root, String className) { + //EPackage root = (EPackage) resource.getContents().get(0); + TreeIterator treeItr = root.eAllContents(); + boolean requiredAttribute = false; + HashMap subAttribute = new HashMap(); + int rollingCount = 0; + int processClass = 0; + boolean annotation = false; + + // Pulling out dependency from file + while (treeItr.hasNext() && rollingCount < 2) { + + EObject obj = treeItr.next(); + if (obj instanceof EClassifier) { + requiredAttribute = isRequiredAttribute(obj, className); + if (requiredAttribute){ + processClass++; + } + rollingCount = rollingCount+processClass; + } + + if (requiredAttribute) { + if (obj instanceof EStructuralFeature) { + EStructuralFeature eStrucClassifier = (EStructuralFeature) obj; + if (eStrucClassifier.getEAnnotations().size() != 0) { + annotation = testAnnotation(eStrucClassifier); + if (annotation && obj instanceof EReference) { + EClass refType = ((EReference) obj).getEReferenceType(); + // String array = arrayCheck(((EStructuralFeature) obj).getUpperBound()); + if(!refType.toString().contains("eProxyURI:")){ + subAttribute.put(eStrucClassifier.getName(), refType.getName()); + } + } + } + } + } + } + return subAttribute; + } + + public String checkDefultValue(String defultValue) { + if (defultValue!=null){ + return ":defaultValue-"+ defultValue; + } + return ":defaultValue-NA"; + + } + + public String checkRequiredPattern(int upper, int lower) { + String pattern = XACMLProperties.getProperty(XACMLRestProperties.PROP_XCORE_REQUIRED_PATTERN); + + if (pattern!=null){ + if (upper == Integer.parseInt(pattern.split(",")[1]) && lower==Integer.parseInt(pattern.split(",")[0])){ + return ":required-true"; + } + } + + return ":required-false"; + } + + public JSONObject buildJavaObject(HashMap map, String attributeType){ + + JSONObject returnValue = new JSONObject(map); + + return returnValue; + + } + + public HashMap getRefAttributeList(EPackage root, String className){ + + TreeIterator treeItr = root.eAllContents(); + boolean requiredAttribute = false; + HashMap refAttribute = new HashMap(); + int rollingCount = 0; + int processClass = 0; + boolean annotation = false; + + // Pulling out dependency from file + while (treeItr.hasNext()) { + EObject obj = treeItr.next(); + if (obj instanceof EClassifier) { + requiredAttribute = isRequiredAttribute(obj, className); + if (requiredAttribute){ + processClass++; + } + rollingCount = rollingCount+processClass; + } + + if (requiredAttribute) { + if (obj instanceof EStructuralFeature) { + EStructuralFeature eStrucClassifier = (EStructuralFeature) obj; + if (eStrucClassifier.getEAnnotations().size() != 0) { + annotation = testAnnotation(eStrucClassifier); + if ( annotation && obj instanceof EReference) { + EClass refType = ((EReference) obj).getEReferenceType(); + if(refType.toString().contains("eProxyURI:")){ + String one = refType.toString().split("eProxyURI:")[1]; + String refValue = StringUtils.replaceEach(one.split("#")[1], new String[]{"//", ")"}, new String[]{"", ""}); + refAttribute.put(eStrucClassifier.getName(), refValue); + } else { + String array = arrayCheck(((EStructuralFeature) obj).getUpperBound()); + if (array.contains("false")){ + array = ""; + } + refAttribute.put(eStrucClassifier.getName(), refType.getName() + array); + } + } + } + } + } + } + return refAttribute; + } + + private boolean testAnnotation(EStructuralFeature eStrucClassifier) { + String annotationType = null; + EAnnotation eAnnotation = null; + String ecompType = null; + + EList value = eStrucClassifier.getEAnnotations(); + + for (int i = 0; i < value.size(); i++){ + annotationType = value.get(i).getSource(); + eAnnotation = eStrucClassifier.getEAnnotations().get(i); + ecompType = eAnnotation.getDetails().get(0).getValue(); + if (annotationType.contains("http://localhost.com") && ecompType.contains("configuration")){ + return true; + } + } + + return false; + } + + public boolean isRequiredAttribute(EObject obj, String className){ + EClassifier eClassifier = (EClassifier) obj; + String workingClass = eClassifier.getName(); + workingClass.trim(); + if (workingClass.equalsIgnoreCase(className)){ + return true; + } + + return false; + } + + public HashMap getAttributeList(EPackage root, String className){ + + TreeIterator treeItr = root.eAllContents(); + boolean reference = false; + boolean requiredAttribute = false; + HashMap refAttribute = new HashMap(); + String workingClass = null; + boolean annotation = false; + + // Pulling out dependency from file + while (treeItr.hasNext()) { + reference = false; + EObject obj = treeItr.next(); + if (obj instanceof EClassifier) { + requiredAttribute = isRequiredAttribute(obj, className ); + } + + if (requiredAttribute){ + if (obj instanceof EStructuralFeature) { + EStructuralFeature eStrucClassifier = (EStructuralFeature) obj; + if (eStrucClassifier.getEAnnotations().size() != 0) { + annotation = testAnnotation(eStrucClassifier); + if (annotation && !(obj instanceof EReference)) { + String name = eStrucClassifier.getName(); + String defaultValue = checkDefultValue(((EStructuralFeature) obj).getDefaultValueLiteral()); + String eType = eStrucClassifier.getEType().getInstanceClassName(); + String array = arrayCheck(((EStructuralFeature) obj).getUpperBound()); + String required = checkRequiredPattern(((EStructuralFeature) obj).getUpperBound(), ((EStructuralFeature) obj).getLowerBound()); + String attributeValue = eType + defaultValue + required + array; + refAttribute.put(name, attributeValue); + } + } + } + } + } + return refAttribute; + + } + + public String arrayCheck(int upperBound) { + + if (upperBound == -1){ + return ":MANY-true"; + } + + return ":MANY-false"; + } + + public List getDependencyList(EClassifier eClassifier, String className){ + List returnValue = new ArrayList<>();; + EList somelist = ((EClass) eClassifier).getEAllSuperTypes(); + if (somelist.isEmpty()){ + return returnValue; + } + for(EClass depend: somelist){ + if (depend.toString().contains("eProxyURI:")){ + String one = depend.toString().split("eProxyURI:")[1]; + String value = StringUtils.replaceEach(one.split("#")[1], new String[]{"//", ")"}, new String[]{"", ""}); + returnValue.add(value); + } + } + + return returnValue; + } + + public String createJson(HashMap subClassAttributes, HashMap classMap, String className) { + String json = ""; + JSONObject jsonObj; + + jsonObj = new JSONObject(); + + Map missingValues = new HashMap(); + Map workingMap = new HashMap(); + + for ( Entry map : classMap.get(className).getRefAttribute().entrySet()){ + String value = map.getValue().split(":")[0]; + if (value!=null){ + workingMap = classMap.get(value).getRefAttribute(); + for ( Entry subMab : workingMap.entrySet()){ + String value2 = subMab.getValue().split(":")[0]; + if (!subClassAttributes.containsValue(value2)){ + missingValues.put(subMab.getKey(), subMab.getValue()); + classMap.get(value).addAttribute(subMab.getKey(), subMab.getValue()); + } + } + + } + } + + if (!missingValues.isEmpty()){ + for (Entry addValue : missingValues.entrySet()){ + subClassAttributes.put(addValue.getKey(), addValue.getValue().split(":")[0]); + } + } + + for ( Map.Entry map : subClassAttributes.entrySet()){ + jsonObj.put(map.getValue().split(":")[0], classMap.get(map.getValue().split(":")[0]).getAttribute()); + } + + if (logger.isDebugEnabled()) { + logger.debug("Json value: " + jsonObj); + } + + return jsonObj.toString(); + } + + public String createSubAttributes(ArrayList dependency, HashMap classMap, String modelName) { + + HashMap workingMap = new HashMap(); + MSAttributeObject tempObject = new MSAttributeObject(); + HashMap refAttribute = new HashMap(); + HashMap workingSubMap = new HashMap(); + Map tempPefAttribute = null; + LinkedList linkedList = new LinkedList(); + String addedValue = null; + + boolean addingValues = false; + + if (dependency!=null){ + if (dependency.size()==0){ + return "{}"; + } + dependency.add(modelName); + for (String element: dependency){ + tempObject = classMap.get(element); + if (tempObject!=null){ + workingMap.putAll(classMap.get(element).getSubClass()); + // workingSubMap = CheckForSecondSubClass(classMap.get(element).getSubClass(), classMap); + // if (workingSubMap!=null){ + // workingMap.putAll(workingSubMap); + // } + } + } + } + + String returnValue = createJson(workingMap, classMap, modelName); + return returnValue; + } + + private HashMap CheckForSecondSubClass(HashMap subClass, HashMap mainMap) { + MSAttributeObject tempObject = new MSAttributeObject(); + HashMap subClassValue = new HashMap(); + + for (Entry classSet : subClass.entrySet()){ + String key = classSet.getKey(); + String value = classSet.getValue(); + tempObject = mainMap.get(value); + subClassValue = tempObject.getSubClass(); + if (subClassValue!=null){ + return subClassValue; + } + } + return null; + + } + + public ArrayList getFullDependencyList(ArrayList dependency, HashMap classMap) { + ArrayList returnList = new ArrayList(); + ArrayList workingList = new ArrayList(); + int i = 0; + MSAttributeObject newDepend = null; + returnList.addAll(dependency); + for (String element : dependency ){ + if (classMap.containsKey(element)){ + MSAttributeObject value = classMap.get(element); + String rawValue = StringUtils.replaceEach(value.getDependency(), new String[]{"[", "]"}, new String[]{"", ""}); + workingList = new ArrayList(Arrays.asList(rawValue.split(","))); + for(String depend : workingList){ + if (!returnList.contains(depend) && !depend.isEmpty()){ + returnList.add(depend.trim()); + } + } + } + } + + return returnList; + } +} diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/util/ModelObject.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/util/ModelObject.java new file mode 100644 index 000000000..bc7fa9f2d --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/util/ModelObject.java @@ -0,0 +1,157 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + + +package org.openecomp.policy.rest.util; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import com.vaadin.ui.TextField; +import com.vaadin.ui.VerticalLayout; + +public class ModelObject { + private String name; + private String parent; + private List attibutes = new ArrayList(); + private List arrays = new ArrayList(); + private List integers = new ArrayList(); + private List subObjects = new ArrayList(); + private HashMap> subObjectList = new HashMap>(); + private HashMap attribute = new HashMap(); + private Map> arrayTextList = new HashMap>(); + private Map textFieldLayout = new HashMap(); + + private boolean many = false; + + public Map> getArrayTextList() { + return arrayTextList; + } + public void setArrayTextList(Map> arrayTextList) { + this.arrayTextList = arrayTextList; + } + public void addArrayTextList(String name, TextField textField ){ + LinkedList list = new LinkedList(); + if (getArrayTextList().get(name) != null){ + list = getArrayTextList().get(name); + } + + list.push(textField); + this.arrayTextList.put(name, list); + } + public void removeLastTextList(String name){ + LinkedList list = getArrayTextList().get(name); + + list.pop(); + this.arrayTextList.put(name, list); + } + public HashMap getAttribute() { + return attribute; + } + public void setAttribute(HashMap attribute) { + this.attribute = attribute; + } + public void addAttribute(String name, TextField textField){ + this.attribute.put(name, textField); + } + public List getAttibutes() { + return attibutes; + } + public void setAttibutes(List attibutes) { + this.attibutes = attibutes; + } + public List getArrays() { + return arrays; + } + public void setArrays(List arrays) { + this.arrays = arrays; + } + public List getIntegers() { + return integers; + } + public void setIntegers(List integers) { + this.integers = integers; + } + public List getSubObjects() { + return subObjects; + } + public void setSubObjects(List subObjects) { + this.subObjects = subObjects; + } + public void addSubObject(ModelObject subObjects ){ + this.subObjects.add(subObjects); + } + public void addAttributes(String attibutes){ + this.attibutes.add(attibutes); + } + public void addArrays(String arrays){ + this.arrays.add(arrays); + } + public void addIntegers(Integer integers){ + this.integers.add(integers); + } + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + public boolean isMany() { + return many; + } + public void setMany(boolean many) { + this.many = many; + } + public String getParent() { + return parent; + } + public void setParent(String parent) { + this.parent = parent; + } + public HashMap> getSubObjectList() { + return subObjectList; + } + public void setSubObjectList(HashMap> subObjectList) { + this.subObjectList = subObjectList; + } + public void addSubObjectList(String name, ModelObject object) { + LinkedList list = new LinkedList(); + if (subObjectList.get(name) != null){ + list = subObjectList.get(name); + } + + list.push(object); + + this.subObjectList.put(name, list); + } + public Map getTextFieldLayout() { + return textFieldLayout; + } + public void setTextFieldLayout(Map textFieldLayout) { + this.textFieldLayout = textFieldLayout; + } + public void addTextFieldLayout(String name, VerticalLayout vLayout){ + this.textFieldLayout.put(name, vLayout); + } + +} +*/ diff --git a/ECOMP-REST/src/main/java/org/openecomp/policy/rest/util/Webapps.java b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/util/Webapps.java new file mode 100644 index 000000000..c2f4ff2c6 --- /dev/null +++ b/ECOMP-REST/src/main/java/org/openecomp/policy/rest/util/Webapps.java @@ -0,0 +1,113 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest.util; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openecomp.policy.rest.XACMLRestProperties; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; +import com.att.research.xacml.util.XACMLProperties; + +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.eelf.PolicyLogger; + +public class Webapps { + private static String actionHome = null; + private static String configHome = null; + private static Log logger = LogFactory.getLog(Webapps.class); + + private Webapps() { + } + + public static String getConfigHome(){ + try { + loadWebapps(); + } catch (Exception e) { + return null; + } + return configHome; + } + + public static String getActionHome(){ + try { + loadWebapps(); + } catch (Exception e) { + return null; + } + return actionHome; + } + + private static void loadWebapps() throws Exception{ + if(actionHome == null || configHome == null){ + Path webappsPath = Paths.get(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_WEBAPPS)); + //Sanity Check + if (webappsPath == null) { + logger.error("Invalid Webapps Path Location property : " + XACMLRestProperties.PROP_PAP_WEBAPPS); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.error("Invalid Webapps Path Location property : " + XACMLRestProperties.PROP_PAP_WEBAPPS); + throw new Exception("Invalid Webapps Path Location property : " + XACMLRestProperties.PROP_PAP_WEBAPPS); + } + Path webappsPathConfig; + Path webappsPathAction; + if(webappsPath.toString().contains("\\")) + { + webappsPathConfig = Paths.get(webappsPath.toString()+"\\Config"); + webappsPathAction = Paths.get(webappsPath.toString()+"\\Action"); + } + else + { + webappsPathConfig = Paths.get(webappsPath.toString()+"/Config"); + webappsPathAction = Paths.get(webappsPath.toString()+"/Action"); + } + if (Files.notExists(webappsPathConfig)) + { + try { + Files.createDirectories(webappsPathConfig); + } catch (IOException e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Failed to create config directory: " + + webappsPathConfig.toAbsolutePath().toString(), e); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "Webapps", "Failed to create config directory"); + } + } + if (Files.notExists(webappsPathAction)) + { + try { + Files.createDirectories(webappsPathAction); + } catch (IOException e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Failed to create config directory: " + + webappsPathAction.toAbsolutePath().toString(), e); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "Webapps", "Failed to create config directory"); + } + } + actionHome = webappsPathAction.toString(); + configHome = webappsPathConfig.toString(); + } + } + +} diff --git a/ECOMP-REST/src/test/java/org/openecomp/policy/rest/XACMLRestTest.java b/ECOMP-REST/src/test/java/org/openecomp/policy/rest/XACMLRestTest.java new file mode 100644 index 000000000..0d9355ad5 --- /dev/null +++ b/ECOMP-REST/src/test/java/org/openecomp/policy/rest/XACMLRestTest.java @@ -0,0 +1,108 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.rest; + +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Properties; +import java.util.Random; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletInputStream; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import junit.framework.TestCase; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.springframework.mock.web.MockHttpServletResponse; +import org.springframework.mock.web.MockServletConfig; + +import com.att.research.xacml.util.XACMLProperties; +import com.mockrunner.mock.web.MockServletInputStream; + +public class XACMLRestTest extends TestCase{ + private static Log logger = LogFactory.getLog(XACMLRestTest.class); + + private List headers = new ArrayList(); + + private HttpServletRequest httpServletRequest; + private HttpServletResponse httpServletResponse; + private ServletOutputStream mockOutput; + private ServletInputStream mockInput; + private ServletConfig servletConfig; + + + @Before + public void setUp(){ + httpServletRequest = Mockito.mock(HttpServletRequest.class); + Mockito.when(httpServletRequest.getMethod()).thenReturn("POST"); + Mockito.when(httpServletRequest.getHeaderNames()).thenReturn(Collections.enumeration(headers)); + Mockito.when(httpServletRequest.getAttributeNames()).thenReturn(Collections.enumeration(headers)); + + mockOutput = Mockito.mock(ServletOutputStream.class); + + httpServletResponse = Mockito.mock(MockHttpServletResponse.class); + + try { + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(mockOutput); + } catch (IOException e) { + // TODO Auto-generated catch block + fail(); + } + + servletConfig = Mockito.mock(MockServletConfig.class); + Mockito.when(servletConfig.getInitParameterNames()).thenReturn(Collections.enumeration(headers)); + //pdpServlet = new XACMLPdpServlet(); + + Mockito.when(servletConfig.getInitParameter("XACML_PROPERTIES_NAME")).thenReturn("xacml.pdp.properties"); + + System.setProperty("xacml.properties", "xacml.pdp.properties"); + System.setProperty("xacml.rest.pdp.config", "config_testing"); + System.setProperty("xacml.rest.pep.idfile", "testclient.properties"); + System.setProperty("xacml.rest.pdp.webapps", "/webapps"); + System.setProperty("xacml.rootPolicies", "test_PolicyEngine.xml"); + System.setProperty("xacml.referencedPolicies", "test_PolicyEngine.xml"); + System.setProperty("test_PolicyEngine.xml.file", "config_testing\\test_PolicyEngine.xml"); + System.setProperty("xacml.rest.pdp.register", "false"); + } + + @Test + public void testDummy(){ + logger.info("XACMLRestTest - testInit"); + try { + assertTrue(true); + } catch (Exception e) { + // TODO Auto-generated catch block + fail(); + + } + + } +} diff --git a/ECOMP-TEST/.gitignore b/ECOMP-TEST/.gitignore new file mode 100644 index 000000000..06ba67215 --- /dev/null +++ b/ECOMP-TEST/.gitignore @@ -0,0 +1,2 @@ +/bin +/target/ diff --git a/ECOMP-TEST/policyLogger.properties b/ECOMP-TEST/policyLogger.properties new file mode 100644 index 000000000..76fcecf56 --- /dev/null +++ b/ECOMP-TEST/policyLogger.properties @@ -0,0 +1,44 @@ +### +# ============LICENSE_START======================================================= +# ECOMP-TEST +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +################################### Set concurrentHashMap and timer info ####################### +#Timer initial delay and the delay between in milliseconds before task is to be execute. +timer.delay.time=1000 +#Timer scheduleAtFixedRate period - time in milliseconds between successive task executions. +check.interval= 30000 +#Longest time an event info can be stored in the concurrentHashMap for logging - in seconds. +event.expired.time=86400 +#Size of the concurrentHashMap which stores the event starting time, etc - when its size reaches this limit, the Timer gets executed +#to remove all expired records from this concurrentHashMap. +concurrentHashMap.limit=5000 +#Size of the concurrentHashMap - when its size drops to this point, stop the Timer +stop.check.point=2500 +################################### Set logging format ############################################# +# set EELF for EELF logging format, set LOG4J for using log4j, set SYSTEMOUT for using system.out.println +logger.type=EELF +#################################### Set level for EELF or SYSTEMOUT logging ################################## +# Set level for debug file. Set DEBUG to enable .info, .warn and .debug; set INFO for enable .info and .warn; set OFF to disable all +debugLogger.level=INFO +# Set level for metrics file. Set OFF to disable; set ON to enable +metricsLogger.level=ON +# Set level for error file. Set OFF to disable; set ON to enable +error.level=ON +# Set level for audit file. Set OFF to disable; set ON to enable +audit.level=ON diff --git a/ECOMP-TEST/pom.xml b/ECOMP-TEST/pom.xml new file mode 100644 index 000000000..7aad0d093 --- /dev/null +++ b/ECOMP-TEST/pom.xml @@ -0,0 +1,157 @@ + + + + + + 4.0.0 + + + org.openecomp.policy.engine + PolicyEngineSuite + 1.0.0-SNAPSHOT + + + org.openecomp.policy.engine + ECOMP-TEST + + ECOMP TEST + + jar + + + + org.apache.httpcomponents + httpclient + 4.2.4 + + + junit + junit + 4.11 + + + commons-codec + commons-codec + 1.5 + + + commons-cli + commons-cli + 1.2 + + + commons-logging + commons-logging + 1.1.3 + + + javax.servlet + servlet-api + + + + + commons-io + commons-io + 2.4 + + + com.fasterxml.jackson.core + jackson-databind + 2.3.0-rc1 + + + com.google.guava + guava + 14.0.1 + + + org.openecomp.policy.engine + ECOMP-PDP-REST + ${project.version} + classes + test + + + org.openecomp.policy.engine + ECOMP-PAP-REST + ${project.version} + classes + test + + + mysql + mysql-connector-java + 5.1.30 + + + org.mariadb.jdbc + mariadb-java-client + 1.2.3 + + + postgresql + postgresql + 9.1-901.jdbc4 + + + org.hsqldb + hsqldb + 2.3.2 + + + org.mockito + mockito-core + 1.9.5 + + + org.springframework + spring-mock + 2.0.8 + + + com.mockrunner + mockrunner + 0.3.1 + + + com.h2database + h2 + [1.4.186,) + + + org.eclipse.persistence + javax.persistence + 2.1.0 + + + javax.persistence + persistence-api + 1.0.2 + + + org.eclipse.persistence + eclipselink + 2.5.2 + + + diff --git a/ECOMP-TEST/sql/xacmlTest.mv.db b/ECOMP-TEST/sql/xacmlTest.mv.db new file mode 100644 index 0000000000000000000000000000000000000000..81e99a969e0e4e22295dab052ba185b7f7e79366 GIT binary patch literal 143360 zcmeFa2YejG**|`}cMruzV9C9~$p%|Cl6+N-Doe60BTKT1jcMj2oosBn3TYz1STagDS=4| zOiEx<0+SM$l)$6}CM7T_fk_Gc7f4`@9`|d1a{T{app{7$CM7T_fk_EWN?=j~lM^{!E;?5wh6>y>DpLd<@nHcY#T@q#53vGK*F{wAo@Cfyno=T(1phtAzBbB zJ?N~h9ybfa9Ze$%wVFkd-ce!)|E}WSFNdyH#eWRW4Q5z6HXb=j*SC5xL9s% zJKhMDnm#OmMgARbELv%V;-ONb98ZrK{|X&yghF%nghE%(2!+f&A>-m{c(ErGf3-{a ziJM;%e)5De>Hnlh_^J2E=XA#ncz!Ij{MYb-$GEU;YDrmH+3Y3r=N)wr6jdEh2`>>7 zUNSDcR6=;^WXW)5d$xLLcp$s0I-Zy*otJ@-H0+KaI)%-p2kbT(kH!16RmQbd)=9HuqfEwQb=agLj51N5 z+oY0EM3ZXIOFS;9_E}W>YZG>=^$x22eOXPkUlFYzltlYMG*O?8X`-og(kcVV-7=@? ztfty8sDif2YZAL{a#;;n`f63_tI;$EYLkg>LCa!Zk zsB)Xu1)qyOq+FL$G8Uv$HOb1I!#l^sPN9N|Af}{H6W6Q^24@A5m32@esaQ#AR#JkM zM8+Y7n%bNcYT`Sk5HgA|YuF)!v_t#}yP@@K86+$-lY|pe`pMclC4y8uolGXumhdy8 zq&4K1w1r&$8f0liX5`kY4QdZnT)x%i(C=*$`?JKhELYfM0cKP^k%O-f9Tn1rTls0_ z*C<~X{yOzMaFD1B67n&TQhr)SC*@;OK_wMbvR=h!l;5ZPe&r8JKcLnsj>r(^Pc zI<9>6KCSSl6~1)8WTRGkebQ5riu1uKtf@p_tS_EW!Txl8N(TGu)AfldTzF%t`qV&N z2K!>Mfusl~(7vQN70BWjYODY~>sd#OwPv)bhE`fZAjMgUmtYCj4 zmX)z}@pN4h&B)|$QUa3_n3TYz1STagDS`h238?67 zpi?A$OHoV+_($w{N%+&k%D-O5mo8KOHzZuy z3HwC4vfq^nfBJp${fw0|eum;_=F9SV))wXeR>IHD$mcl+l?nJcS4)5HQ7?(-xu2Eq z=bhUnp6Ab(@$;WA6VD5>(qE|LweTVN{>U!nzuGR+9o5JaGGz%NZx=m?rYb7%pT(-K-v)fA@`)zWcv z5;f6kYNPekOPlCS%21Zhp%EIR3+Q6nW6|n>S}51Y1zE8x3#S~8n2I)MixaEm0V`X_-Jo;OINgYRkXdMC)#pqYj;m~ zw7U`i+j^o)vvqxg1Bql!ELPW-tf?7T8eP-ay(YRemFcfb*J83_Af1d2)W>VGnZbc% z?O>+9zXo63#FB}@bSzs_lTG(!6N3ZwnM8kTpg%JZOZO)S(<$I-Y+l#eUK&{(jg~wc zR-807HmzxCj`lRJY-@>j_O5JeZK`hU>FH`++1t}nF@+0bYjd=Rj`kdiSgLNBeBIi;87W#S25bVZqP9`1D=&8@3iTZ*w@C3EtShpe-! zwWF)G$I6W4p}VE6r3vIWcQ*E{abxn-#-?>`n;}6Zn>?&d$oA@vu1#9NN^~9V-9256 z5c=kxO`R>ym*BF|9y?`OY2@f=dC4i-wAx$OLl>>>%`K;Dg*N37iulcqQOLAF+nU*B zuuQeX2x;uO7!d6hyj56qig8&QS%RFM zq;duotZRg016}%x2!3@} zM{j3q`)XZ=D{4~t)fnm`R9x-Nja?`Mg*8$4nvSlX&FzirtUA&Khb|Qs8Ao-=`l^J! z)=s3DCv94@GOOtTVHK1!;-Va#wzx);6D`xp(nvM3abhsDbIpLXwOxn2%C>d{O`}pO zqv^1<70AvxuP;0C;1-6QM5e*SZt*oStLEi8yNIFL>Pk_=t2V>MR$QA#d+W;P5-EkC zn}Z2@mEBUDJc}AMQs!kUj>N?cW>s(juR<24L%`Pt6R_xmbQckEXIDpOOILm~?$Uk9 z^=<5RW+-HQ^RSoE-9yiFCe5PRu)4?$hus{PvSL++Xua+@?2WA1IW(8%(R|kI91o+{ z;Kg-NKhgTJ9%SbRuOMABB@JnwM{PI(=Ieu75c54B7WAU2N`hObNB2XDSdhd}tlzFv zAwRaELtf9vwW7?8Ay)Oat!iy++nnn;RU{K?d|{0X{6{cWGG9LI^?4qP+62AYeOTsk z(?7v&-2z%jN77LgW!qd3+(;5O%ePb@jbtH=WXPqq(aDNicp|usB*6BOu#wyRY8g#A z*QqU5r~AlOBeQjUWtZ8#dIx_;*{T&=hu>|$k!W&}tDS8r;wVIXzK@7)5CNp!Gy!op zahJUGB{rRMT11QKXgY>XryM%?pq~ypJ1`Bfsj&@1)7G9f>xwDhf2qb_1l4q@+C`2e zokK8N_eqX&?fNOmk}h`KQCbWYUErdke4yg`X_{z#-vshJd=J=x@XeC6Hy){v9+=Ev zMkqJt_8;@Y){LLeeu5j&CA5?(Xc=4D5?I;;ewNnN+t%{mW@k&Gj?RhL*-BeIke4C5 zl~q77J6#mx1SxJ~D<^7WE1?M<>jxYQ_+$qbhB{^Dyn|WK%jsCEq$<`kkMiAShbEl0 z3A84hD<0xM>}OxAdfS_L0#4L^V|NXTQ#%W~#YmRcm`IE2&7gkag3x(nI$Ave)b7nvTs*VA%;!(K#?H znzIg;HnfP@92qTDzqzZWr?;!!gA1ft)4F<1OV{R(u4bO%cbzvs0MkK|CCSTXZFicS zu&ouat$>qzb!ivdvZ+NHSIndOD%4|f>jK5V)>W5A)AG56tJ%8Zl%OPAR~**$6TgDr z+1iQzz^c~OosC_MMSCzJ5tb8HHTGf&M$fw>asvgKz%hdtk0lD`0cA4BbV7x|l2=o7 zwXE-L?ZUc?%VZ%q&#xyE&}GmLf}@9!Cj_a;Boyh|L2#xnuEnMabVi%FGkW8KZ?YCs zl%^WiVhUP(&~GKm(qeB{V}Kf>sSUHq4kft>Uk@Dp$8|cD@35}O@UpeLyBD>9wkKgR zvgBH$Mt>%(WWHQDb8Mdm)YU{|GlsZro7~JznPN98w(gF$4Pe*BCdClTwsH_j2e-&( zTjf%qPic`gut>K#ul(f2O|m(7z0!=`>zfu|$~~D{s-t>pV3VwcNnTsTB(R@UsgLRS`V@_MM6eZ299%eS|(g6oiowB%vfkxn_s}bw|kp@`Q zuZlEPn*9HBja6%NuHLZf2ejAM9PaLDMv|1D)V?K z)2**tkiNJ|K`*dM>v$6D1gP{3Ws+|5oZx|L%p&!Jecq}fW!oAd`fn#fUIACh>f=tc z7qlTI=;6hqhgc6M(aF?ED_IXGL2hn~WQynF(gL->(yEVx;>nQKKEDFc)zQ{cbYRxg z)0^8y;SiT<Qk7IO8&55ynql*A{JR>sVr_fi_~~7 zrr_A*Ad9L_wMZ#Mh>eturp2E{$dzRh8Q|qf~4Ykr*I)zK)YAAl4 z%z&Du!=T)6CzieH&WSOX51yW01LeC7*sS!$bspDqhBnN_I0NNYWGCSEEBA~@>s^Zs zxb451NCqY_W5A8hDX`gZ`ZYQ&?W;Pvny{@WKue7pu^s#TFhzx}b=ZNX2XrpR>p-g$ z<{6>f)~H{)^^wI4f)6cWe@j<~ip4;do**Tn8;) z`kzdU{}_s(ZvSmfaM#qHP^br!;qLY>%$&K*Gj$ zVJ0-M+PJC^B%F1X zdM&nnHnBXrAK(hhI$_e|VuU$MS9BAC$mpp^5rk6I*Mmm+PrWY!98$H`#i|ZCt z?YadmZ_Osspt=E?eble-(cIG1%3EKt>)uvSa+|g+0XaJt{_Vdkn$4njo9oyH>Vh1g z9)_d^S-I>w*NckUM)I-<3oh6p9@z-Xn9$<6y<1u!W6c2<{ZnBVyIiW#e4ygSk(%%h zab9?Orsj0E)J=36ola-4rEWrAR|jh)Kr*)zKA&UNPMn4ey3I7?Cl8Xr3Cx(M8j+RL zVgCF4Mt6;(TOx-6&8Wk<8s$N66>HES>_*wWRlEm~4t*V415!|T(D z16s~pYgEZZZ&#b<$`X^PYtIO7WeIy>D$tmyaE(9I+{|WtCY?o_>1;ORGhugb{gZqI z#qAFCgV(w|;yVjwcaL9tiV4$It*5r(%cWw?Y2imamKaqX*X9_}7ru2Yr&+Is4mLvv zjloKKlVcqs$G+?fo()-Vcd5j3`7ADFPzWsLCagY~?>g?^tnv)?Q9li^$}^Dr8+`hO z*uLD;(bUnle}Y%?RybTM03p>rNVO@LRO{_K^c~zux%NY@ZeJMKlNOgOs05a5J@3mO zfE=Ij>owpzrgcRuR~9o}_NDC5|LbY(Wa$^icj6n5!Z)kBI@X=m(Qftllnz|eI)tKn zh%$XQMyf7k5$#UZrJpJhalTy@uU>c9c@@KlgX;gvqs%M~(iYlELu{s57)Zcr(}aD1 zDWon9V-SY1#ihV;lHvvdtbq+8!2`!FFo+9%3YJuMfMO*R`iRg)^rBF04PI5%*>_;s zIFpha@~EnE35&}Q6aveyZY8R!!;UXuD>#SFrERpGhS>_vflSZ$k*PM#BIV3QV7Wr# zDrh0kb0N=w>m&A&j>VJ|<~9h^ZU3`QR$P=57|`%|W;=wo!$)Y{Els`rohg^YB7$?3 zjTD`u$rR!m4qm6PwD*Y}{6J=~h2<-kaJ zmS6GfrQj=T{_IhFz*j_=jh&sk`Yov1^S?rtGWHQaTTfnJ7T@!>cXPZu6?+F%=<7V_ zE8u?3#+ZHC+mUB!5y8s`ST&b8~l1U8@jRYL<|axSiF>sV|mMEzDlQZPK(JB;8JtT-EQ*r0Ue=n zwl>RrX(ii+0@6( zC~gEGr9OwZBX_F5a1NY5v)YYZ1swEvF7a|*OGkO!t#soeRsAcvqf(7sOwcz$u zTpj-3GT-)9@+=3{t#{b2am%XLxSqV2E}=Kj8`*L%hK?unsduWyHj%YKNf5rE$~Jom zlu%Ms~R--Lqt*I8!eFJh5u%G6d2WhHr1ov($h!fy`0z-yW3o4Ws);92F zRU8*{sX>?FY~M&^j{)2Lf!}nTtjh7B0lIL~fMpEkqgS@B#ttb<@v@H8)$8k-j&5t| z!A@eeu_nR zT%lx>!84kc3Y6rTiA-|#}wZ(u5Izj} zZP9Ma4$dZHLOt@lQeaj0P9%A$I`K8dMtsPmJKT~!pIv6ReqjaIvK8o!CpPi9SwXzU z)>W}(SxLec10itTu$Ps*$4$w$v_aJi>Nfr=Y#5lDcP$#Pfe~KXeJ%G1-ek~q2EAEW z;G0<4xB69FV*0_ZW)Z=sSpCPk1mZg;LB_LRa3FdOf&yyV{7$Vj6!F$>DQ=ajWr_Yh zAS;=#!MfE?*Rf>=+<4w(pLiAQE47I*G{)BWX0}GR^}F^Y@HW6E%)^GC z>s-mTAkHm(i$OOSbfd7r>)8gc_p`yy=1#i>;_*Lfe+R<2)~-91=gS}vx3dQ=gE$a& z199Z6*v(3jpqL?R4XQ#dYQ?v(?KK5!8|~w_oVKK**z9g#vvV7*TZxMsopY$JaC=)E z58rNN)ABvkCD+5YTUajEt0$IAVH+jnB8$oUKi$DPpaxb@F`+G4)4PBttZ@G5O$Oa; z&@BetDoXP{wwm?9tftvMZmZn?H)Dr z6z0urQhtkZqA01!=>SV|c1y|Y!Pt=KMoJXSTUf*aw+OAY?`$q$O$zo_7OdM|jr{b* z1q*U^!TO4GWgK?2`1D8Fj&O+W?FPNopgRn@Q`pgMqE+zghT_Ohe0kO_m@G2g<}#5W zTX`Sp+crmBxOXIBdTtt@!A4F>kC6&E_l1QvQd+wdJM+jdn(-FEQu zfM#VQ&WFX8TzkF9&pawGXx4;i?qtzuv^I|1y3zJtvC+D4Uc+4mz0IJz z4Z26z$6YKtx5bP?Y{ez$>{VODy&IPrNbzkfMZeY10IQ&!#K#8tb>V90-7M#zI~eRH zC>WBacMprtZ3_dZDK4(=CtYzXK0)JT#6QP8}x2rk?&-2ZVJ|YX-lq~*+TA*ALWwNn4tm#_`s*!=ez^ge^$FKpmF zERhan1CDv&Ri|vuoxP{e8CLl06|I%1LMLL)zn3NOVK)g_={>UVN;is6z*=znHXkXT zqvOoIE1<zmFwyW^svFr@V@VJBvz9ucvr|mYcX=~rPH8!lTA6VXnw3(l{BoyPi4G=q(V*zPJYdiV z4Emr!9}*_^Krj>Iz6|5Eh`UKrCt?wP;J}!eM(L29j`S0nPGd1#C@q~N&%{2+5*aFH zV!89yH``9fRMhO7H7!HSK~&fvSXLimS$*Bt+;YGH3T7^`oi~RF?HqU)RCh#HCJRNX z(b`1{)BEVaDO|hZI*JEoxh`MmIz0u20Ut!4| zr$DigA7mlFFw=wk*w zY|zJr$v(t_KG(x!H6}X`md3z!KuOy{*l<6_qW+ef;kpoMhWMq;{?x($pzk zEmyy^DB95|N!CUSC8^<@2MpTU`^SeLU<=0WOOF`zNrOHmEcg=>6SQt4g9_S~o^AIL z7W9|hY*({yWqTrmwo!2i+7@4EwFMNd10U^~D-^UwnrE?}WI>L2R0Wz=PC4qpOB+o- z&%)7!6#`Y{olMCh{S=Gz`+g$L5iKs$T-tmF9fHm0qoDpRp*0y(;aD%mx;$j$=LM?2a&{m9K{Sz5itq@`f(VMJUpXo5DC2d2c-=q@H%g0!xk_Vffx#;eb6%d|XW zj?11!y0Fh)kRDa6m7eAGB+Kio9`>aXOHzTPR>+mZ(CpOR?9EBhHFJf{hb@!#76kR% zljnb#ZSN_Ao;K)n20bHe?Oe%cCM&9Y>lX30M7CfR&2Z^7oL zw3u-S)uLJ;QBQbfo+%ge)Y$BzM0P&MLi6gEJEjaB#?9EQe!1r)q6-L%@EI22-`qrK zC+ICcd#cSYG#pZNd0*JWDTYzWHR&SP0{m(MwIJSB9l(TljlY*o7`J+U!JuaidQO<| z=lx9B!K8h?+u|-awPa6QVNc8Q{{qY3b=JfV7Eu0nNyLz$b)9KGl`UaWuKpf4Kqf}_l_;JWoVr1Lcj|>&c)?PYtdC~(%*vAW;x4T{K zBcI`kG_J%@f6x-VEU|9QKec@kt%PMXze#xM(2wVFyFBSGHOm3SOG*5E17*Eb6 z)O0NW{!32M)X~eIx8RzMuGXfCWZg2cxcU;?b-^UFepUuA8a;H?dzce@JHF;GByK7cif zHS{zu+P=(K^gaZgW4k3ZclzT1XHA!UFKmS9Yl5w>6)`Q@EZT8m3sK~y-El_ob%EmR zY#pCERAr41NyOn5tt}fhTk9Hon$}ozJ>BTgV2P41IF+lF;%F$2%Nu%EMjaPuR7Np@ zg6lk_-z)w2=GJapuOi~&RskkQD=I&ef|t{y9Znl&0axm>@51iBS^?I+e^Xzg9U{bodEZkf?Y_Lc}-5 zt0h|XLW@Sf)cr|x=B*SuPGLwmF=z=&42f!;I)@=A*C~8#NmPBnCNBjqoG6Jl3sihX z_=@G)IEt|9M=uI*^G?yJ`5AvbxYPqZ=a z&xn=MVvUDDa#&Z}5Y-4-5GO>12`LUZYv|NfKpCth*@}V1Wfnc$`72%*;*e>A=OJO? zbQR|7&qKnIheUoJ64h>bSTK*9oJ~z5H;F2xJJ8wif4^x zWqef|rukdiTe|WqwY)4A)MXHj{obDgQ@IH&Nn5>_JaF}1UWT{|$&1p}RrLiSwp2-vTHdNW(H)$!_szSw@_a>9p09A_ z`G*;vm8Y!t1Uz4jX9>TcW0+sRkHjY68`>n5GPQF7PbQDOv)O-6Zeuy0PtvjOp z3b)hQXWeWy>_TklVA;kDTsZQ_4KmJm>>!imDcQ3fRYdIL0@X%xnUPqe46Ky)4uxlX zDpO0Pb0WL?bMFd=7yQn5h@lc_MdtS)USKNH z-f|k-;DsOaj3L*c+6FM3ZpE?3T4`V3D5kYLdQv=k?6Gnj!?=UD5V^68H&4*=1e-cL zFO1iJRKqEXjchng@Lc6aHw@=4=>wE2&sLl%%UrpSb@)C1g6AsNnls#gG*_POI#c#* z+xflh1r&_r*i38kdI)MX#&@FPZQA`U-@=NwslvB;&6G%%-wAOUGKvC|hYfYIqq^iY z7zpxEkMor4u{3b4rYiL}oCCEQl5(QfG92b4ks$I1-aW8Ly+e_xnAM~3W4 zD+<%9+z7TDa3ZHR;6hMGa-rm9_;4+B&%U1>e5irIp3u>sTO<9St`+_DM4g}a+}!+o=X!ye${ z!>jw)$Ii-+39fFs^WYhwQnNf>YA#BYnv0XA=FzEA^O$t0xumAlTv}UdR?s1(<}y08 z)Lc$eO3h^z{ zC4#=n#4MVH^s{L;+&MG{?p&G+cOK1yJD=vmT|f)qE~JHUkEA2v9z{pNjZzeDIhDg* zM2p}qrp0iNrla8=LoBK#v;^)_S_-#J3cDNnX0k;!(^LYGjz2!@iD`|9H)P?lj)D5?X zdf@g_FWe2Z0q#cH2=`Pv749b51ot#L4esf5I@~kp47g{~nQ+gdv*2!~&2Z1Av*Bha z1GkU*;Pz8L+yNXp?(w_zmaODT7J@+V z;SSR<+z}dqyMuPXJ&(?VJ4&N)$7l@hIE};INju@5Pv^tEfG&W$i*|W175eb4X~~r= zlo!&4NPiJs1ovXP815x>3EVf(8{oc?-UxS(f%DtoU&@EL!M}`8a)Xa!ur6mGXJK8z zJ`TjXlKrdrU@Z7JW$0@5an#T??Bl$lYuVq+=MKTg0Wfc3|2jSh#*5$2-u5QRudY6D zYRB~qg`+#(!amOLxPko}`5X`UI0|4N`#2BaCiZbCz|HLAWPn@Pzm-o2fR9hTZ(|?d zd*9AJKKgzu`}p$v4)*WlFTmmBd*8d*$49?!V;^7s-p&3!`~@)ldkuU|>dk$tBe~7>EfscVZg@@_lLZ=H#WZY zrw1Q{npsxW@UavAVTSrR?}&$w-Nm0^A6twcVITX9Kgs^5c)u}xY~K7d``E$x8TPS_ z^Rw(f%G){NKW1R>9sI|610H;A!Fz)JCwVI#d~A+-ihb;mdYXM~llmO{&+v9B_}F>! zdG@jW~3EY|S z@zJ5ao#WXYc8#T!me?3?>mM1&_GQMhB{iN1U76KzrL=Tyrhj~BWEkwJkPj{o<|Kwv zs<5%vmFe%#j*VH;Jbq#fI-yHxSx0vG{Grj2;qBRBR+;^=*BeH& z=k3gnjSmfPsoI|D-#Rp$Ejif}yQ^pmF_hA=HWIy~+5Vv&L&%0Do0BF=ArAqzhRwVC zwZjfU)lu@gSwMI1by+3% zy!XG7z|oo3&uG89xg;ElCz7GkaCvK2W_U}sWJ`B;JerA)@hu@@eHH1Fjv}*`C>5JUb9-#l06FVRF;6 zCsc9N_0m7@1?fM21JS`$O0%$msrA0}5!ftwa%dPWR7q7)V0-e? zNHs9D?MlaD?P$kJR`}L71DWwm)%flm*#-?z8d(AO?t#qio}um8=ABBuv7$`mL15?5 zG$2|t4lE_d6ouww5adbs{*47$N@X;iX3$JN(YO?7P8k>;6WOWu%uWJLX)Ze|J;2Kt zyl-S=TQ)NsKoKe>0H*`64H&a5h>~SRv!Ig#bOu1%M+f`s5(&X|+>>jrWOH2SK!9W> zkgQ>(0mR42Aih`L{+%NZ4$&-{O><~2&7=9WfJHb9sMZbbXdD>eLRk{?WXCB)3j!!+ z14ZxdY-V)b$nf}9%PtZ{#ZmwRWOJCGt=V15!j~6CVxbwIegW)m9UFciXsm$(cbO9L`i6eD|lO zm2!h$Jj0R&o=BNs&B1d$!3zk_{sc5kp1qnt`QaI*k_p#0JUu=n z0YsxJah^E~z=||6p7#nMN3I`v@~vb)3LHF zBo^tgd6p>Dif+G!?>TL{A)EWV09Ys;DRTrX+ zpEfc&kR8nqR1IW@cUO&^pB)_?8pw{7w0l;uT-0UHsj7cud*9G7k3KTnFsd9H-@3iQ z9UrJ2DX0xs?ZDV|XuK-3W5+g(UbFop!vn8_nkzm~I||gg^76E5fAi$T1ME>?-=H$G zb9ft%963$N+Wn3^W}Tkd30RKuF~Tl>`N5}V9LkO90m}w2KparX^SVaK0V;32 zc5)!?o7Z0sbdAHSJg)<%YaPt%MjWdVo;! zqH@WBlK`(&mmCm_r;4Jrnx|?CZH-scOAe?-@ydLW_Q8`sZKL@$5pSnBP_+^7H`w2@ zT3C0|5?du68hYr%a}JTClB)I7@Mce_>OnaPS$)Le;<#a$!qdFj z(W>#Snc=FD(JCyRWVV$w`4;EFox@_eNi3IPj@cbaq^xx6B1Nu8lf#PJ_$a2=eTH~k znhPjsxXRM0i_0-?Ll%1FpucK-q)K5gsSU<<0U)p*t+0w^M9!1wfDaGA-?qD?AsAwv zOFL{O2AMlQ{$Z#O+F<6~79VANb>?Ia()4Kh*& zq3?QR6@)I=is>-OeVH~!&Cl?FBIIp1j(kM(0XYN97p>${9F6K6VCc^4$-_Lw>%BzG zQ?mIvut7%Vl}rCcbf9(tjm(4G zFZ{&wEO%?oWNMWrri;gZc0%hT^P^dSkl4j@GTdNKM6+&_m zjZD*+?M%zGKKA0kTnH&7f6ga`#j9l&SbU^Z(dyxeMu+|QPg+}+nGYA42CQWotDO%{ z=~JtF^3QNA@W^zHl~+CXhu3_#$V_0Jp|RR|<&^uwE5iv%U-p?fY~wTKnhZ;NrlNBy zr|HR;ws-sCkc%5^WIC|V(%AEJ!IXSjCkJ*nSRwh@3i}4R$l#EDKwB?_jLZk$b2Mf< zZJBm|Y+XVM4SeCzFS7=$)v&3Nxr)~2yd_IVb{d1VSUxCLAY1b^DSNi^U`hg#@g2xt0{2>j?4o7MH;`ID=T@CJvbJA zS74zPJ!06XwhuVC577&aE3qxT5}VR1 zv9GF9?%l^E=nApJewx^|Un+LYm+>a{GVI}slwt1@w(?^q7+h>af{X1`*w&9VTWssc z)G;>hV?j1Di>H0DaUbi-k-2Gh#1{ecc;6Iu?_i?>GeskUwQ-5%SvxhP)(d8cxZ@M_H7&KKer)Kxh*@4r)@*$XV+zRHN-@y zGqVMoWMh@!v!Mp=u7-Gjta3QJYrG*@xkJ26RE~~}j5nlW{7c7U{gvE>YpCt7#4;&w z4Qq%C*)-(KW+6)qa|SHGM6yzBFw1VxF!HUIoZs7I%=fJaW=S`h@`bH)f2&~Y-QP-{ zQyz5H+Ztb3U(D%*A8b19`_>~zlB=4yA8d`UtZHiWVGk4f-8nok(l)XMrhn_x%R*%# zVS}nfC8V(@q_HQYu_vUlC#10_q_HQYu_vUlC#10_q_HQYu_vUlC#10_q_HQYu}jR! znBAyqJw-KvUl(M``MRK}NVAi)V~(`(f`S99yzleB)mEu0_@p$)q%s<5j!9{b zNokHrX^u&0j!9{bNokHrX^u&0j!9{bNokHrX^s+QO4j(PxRc2O(~_^H660}yal{MC zw-dTRS`ONUwXg#^QD6m5Xn)$t0t<5>PZlW0fjsGNB}oslD5)j=Ei~ybmXtqhsRE5n z73RNfq;Fkjha(p$4-u)7k}ePt8|VugwSlUxM@m{|N|}+g%#^gul(fv0w9J&W%#^gu zl(fv0w9J&W%#^gul(bBVD=jTEEvx5r!jXrxzZInYMP1`x8Ps^FS?RH`33Av_jlUJt zct~F%FKiGT$ZI{UKtp?oMZflEt=6Bl!ZyRfT3rEamIZcY2c1d%*(_{AoX`bqV%O@_ z=kE&5mhF04T4q{WW?EU3w9K@$%(S%3w6x5$w9K@$%yhr#n$`%nR=9P-tru=axP8Kv zDF;M2E8Ia*@vHuL>~JoEx^o_{aX!{NGF9(kl1g*+1;TYg`wO(*U+?t=0<|N@*8};T zD(7oo))Fxf)?{syh9VgQkq?9iuoq`f=hb-XG4p|@@ zdxs@nP*=*gN^1p@aljTR#qqX4F7~&H0?bCOnM{~iP7RrNzj%CTNys@cbeLWu<#FH0qiG zx>|`u6%|n#SIh2z6-LEu^qa{VGg)UQ>&;}pnW`~UwPvc$Ox2sIjG5{)Q-~ZeQ&}@L zXr^OkI&P*DW;$u6Q)W7CrfbY}t(mSf)AeRLW2XDfc+8Ba%y^AaZzkeqB55YlW}?oh zF;WITA2WXW)vtx-hukMBB*U`AD#^+Rbl;^Y^<&ccsFbAN)=R0VM`hmnN$E&GrX85# zO26uD!bvCLe4BK>O**+q);ln#oODx8x+y2-w3FwwG9<-Sy4I0DC)paOq-vCzDNqMb zsC?~+5(y)2KwbT2V!%vf&BUP5XC`B2GHxc5W-@IiQO9J=Bq9gQWY$a$nyHwXikqo~ znMxY4k(8NA8(A~mXAGhq`qaxehALD&B*`a~Ny;Y&XGv8!)GOz^Iy;*w$Gem&0TM3d z$WS_AhfAj&PY#?ls^my4HLAp^Cx^6a9emcN?I!C$S?5St=U}?d!F0WYc)f#oy^@%k zz&My^xvJwas9PPvZlY@h>6s|lCDpRU^3P>Sl6$D zg9H6CK{6gorerXYs?XN-Ng_3M35~8c*=Gg&6S1sJP!~_vB{3a4`J0r$qy#1X&X#cXY{yw=pl}hI_kbE87PC;+$8gpT|RxUY)p4kVr?Fku| z$R$N{N|$&x-zEKUQ>S%dSzDCR5bM8e@PZ=dF%@+g9su#OSYoXj)~ zBb>(JLr35ggE_PSnFR^Ccd-@r!C=N zC7h*%}d zq!*0nfB$7pd|3JsH%}gxjw>@J4@-AHnmqr!Z1+@?hov|2CAYbQ!1GW4Z4?)ZOdghQ zm(k>5>AAC>xik46J%HQu3Mi&558#fwUarCK`4{|H@!Xlz4EG<+)#PF6?YV2eqd;UG^t%kns07{p&hN*!cPMPt301$(zSQbol3`zmyO7$8!@O*bjf;5b0mR zlL&Zz=QYxQQu#lU{y|~oFH(M^gg>ZX`PWMLgFdMIuk00g4*IKnKKMxad~maR-m0Fj zSI-}PR-`}pTWf`Xh@t!n`Tmej>h4@HdU7;%m91a9T-{PQVn&dQ6UN!HMTMh8!n{ z^YjM};l`{74ztE|2BtZ_Z_qCd`lCVr!a?XJ?K9~vliqF8gC>2-q^C{#l1ZfFy?BxIm-F*dP#B%@D^NhjtOG*z36~&r zET>*tN|l_tqLixm8GbcCFDs=L{0twTgCejTfl>|}i$ECyWt9j_=a?!4W`NIXP`q^J zo0+2e>`;IF#@|kXB0fPx@)ZcoLSQbw)TGF4j>2~;gfH=;k!kq!m++k&$4y6Q9zrwm zRS`wzi@2ExEkI~GzRDqdhQ;Y-BXlG}^CNS>z@C}YnE{-XhN&-g{+2w4h8Z|YK+Hub zS{_}2Pj3jH4l$DX2rWWrc4PrUkUHWPB6M_lv^sJm0xbG@k)se=g3yde6rrUe4$6wK z24+S0;DXC$-N^Kb2$+>WauQs&5Tqd?qtNtP$S}|Mc7VOB2I>y5H~#% zLtHcBWT=I87)R8qMH~?HOE~YVX$`f~S~>+2o$IKbI&jGZlC1`g*^vZ7Yk)(BS`jxt zl0@8E#L3Vptn?J3+7_w6I;5HrNh7Kqsbr`FadRRyi0ecgLM;0^=P~{D)J5IYgDKVx zm}EVTPNy@N{`&H0RiqYyu0<-)%@V9bOb<(t1HHgHH&Tz#24Iz;O(L!Vai@tm4xP@B z$02YALmmg(m(2Mi(>{~VqRn(RCU*O%p9V0!JIJ)p6gZAY=q!PQLz@}L2?(6cI5?0I zsZKRVL-&Z5%r@ z(uLsdGM0mHm9gC+TtqXkig`lIh8r<3!;gC~a0Lc#zqr@HJwCY20vA~@Pj^V@ZUpaS z=y{PI1n=Tl8GM_J?M3X}GM0n)$k+`C-Ya7{c%O{jh~V30EC=7gvC|@_hQQVQZ!uSB zY;kkO{d`#lFFN3s3|x?byD=W%>oAzBcQQ0U5PX+}-h|-&GM0nyma(TH_#PR{!S~A8 z(-C~1jOF0_W$YOUJ|JT`_yLZc9yv3_T!~VR_8<3eVEN-gzHI{+ZSXn>t~+{|ugzet zKFH7jLGVKo`YZ%LEMqzNpp4y&;74RE2R|xf&qnYe8Oy;QtF zma!cCjDg<8yhs+o&&uE+f{${7d66v$K4vW91RQ)^#%>LTLi-k8%3PtBgxfxz;tM`- zw+F8E;6)0i2bQApk!K;L6B32t5UiGW4{FI~Q@EW7=~g+Yo$)smzUR zNAUAZTL!-%V}}v@ET=7tj3D@&4DJX)P77<9BfSQND?)HP2(MP*S`gd_f;Fp`1xL>_ zqO!<&fc_$*m%$fg>?mTt#5ku##t?i_2FDTnGAEc8*@@sw3?_qLk+J6^_N$zBX5<0{ zUzWjLp-||yBOhR{(2vAmL9dw6w+#BWVH>3q297{KGqM}dUuX0(_zf9*A!1))oYNy0 zA^1%hycof6af0cQOA!1vgUR4`Wb7Ld`&~{uKk`NdzbAuxc*t@0kzLFd`nEqX=!XXV z$e=AYS7ON`nf^B5W@OCW15c&8t^}00xJAN8IOyEDDor5J12t6gedZ38NPzU zKjAcUP-!FlQ-)RHpUHS!GDMM|BYhR>W(0pBg4Zy2w;%NybBAvC{}}WugMMw$Zwz|X zpx+wwJA;02&>sYMzXYZ#TucP${{aCN{FR8s9YqxRHE^y#b&lX~MDRKezKR4ZP@NpmH&wO!vN}9llGeQCX=o+>CGlxZ_-;#y1}Fy1%KBtu2QrhfWMY$ zsPJAH|8|al6Nl%aJwf<7Q?yVb{AL;dPL98x;G z@GUYPH$S1RMtn8eCIoL|am+*Ggz)X0H5GoVjK{@LXoh9H2;V8=-_PvbvFNAF9!8#T zGwE)V?lI|JlkPL=?Iyj`q<5KgzhLh!34=?eDDpOmON8&1@wj9PZMKXT;d>FTM1zLt z`;bHh-!6i}Mnoz`lnBzIj^hv?qgAyM1Vxi5J z@FM(C8IOCi&}z#t?#e>5Ez^kb!!jOsXHn$iGG2r~!Qp9WcM<;xr%~Zg%J8QJe@FkF z`NK@Yr%n2dNuM?8QIj4s>2Z^uFzHE?o)Y|hO5(zOTxh)|JnrN|^DV=;mkaH;Oe4aN z%6Qz4$>9S0t`4GW<6sJnlL}125x6_}d&m z2mKSoe~05$_`5P5ccGz?m+>O}eHo9t(a?CyFz!dA$PZi(~&Fg5T!gA4LKY{F8{q z>@Y=M6S3c6uI{P0gSo;i-(O7nt4V(|=^rNj)1-fy^ly{)gz3^Sx3Yf*G#Y(ODx-A= zxDNkS#$)mr?YoQ@;eW{Z?{oY=W%vgi{+CQ6!vB`xA9DPju)r_Emm*vp`H@g&#fi)w zW*{#Q(-mR5GE7&6>FO|D6Q*m!v^Pv|66{?T=B~w$7}Mnf`o|o+Ld1&Tl_K^h9D9`r z{*;4Piv%Kgjfnjj$6hO9MQ|@-(Fp#Wqu+#R5r)|AUUo0@g=x_@hw1t-y(LUHgz3gG z?F-XQVY)d?w+OzjlkmS__%};<5x!o=|B~b1BE$c~;TvQc5x!Bz|BB=H$#@aIDa<{p zUvu=$VQz~>@D{|P{rwF~?QP3im^;ka-WI0Y!}QiL-4Uic!*o}e-WI02!*q|}?pA;! zN55fIw}DzEI+6(94q__!R_0+YI+cjNgLzQlJDFNp zGJKCr@<(Rwj^#gK<}jChUzpw=rgwztond-cnC=hLyTkOJFg+-kyH~>eiE-TrTp@Hk z5qx`iak&bdqfHmd{CzN3v>3nW4}Lp zS_o6z^wBUq6sC`b>ESSaJWQVm(<5Q}WSAZe(_>+JJWNl7>B%rX6{e>JuOAV(|H8OG zDsYS7LlXC2Ir?KFg$O<@Qi$NkWs1LXicg3XBKU|%A%dSoicsY5oZwNBKm;FSxCQ7s zBl>X}{wIf@V3{vKHyYt5W&FQ5{FICr;itokdDwRbHrsx)`kQl3Bp?dzx;o|+_%VhlF7hNx(pPMH9BUaoX{ad9! zZK}jS?Gp9;qiN!OX_I^|{h)j5n?=dgf?{ z8mnT$dK(mLKAgaMtg?#r`dDRoT6)q`#*VYh9Y8|Dl^UNu-grXz96&<4s}kq1bgSgD zC`-3WQRq~M5laFA4+OWv2!5*-wstlQg=cLsb^Bxveeb0I!isRX!PWcH&s-; zYf6XB<--ZiYZTUQ>+(s3)Vrp1Ak704IBONo4fZQr6+yW5a0gPIe+`EN=!47NpwO!h&p6$Sn&6?g?6G- zp*l=RBo^>Z8h&uw$jE3=c#&AZH!JwlR5u5gXl&1H8@e!CHMS$upY=Jn*};%Iv^ckU zU&Ciude{xbJ9JojEsCbjMP2Wgd}*sDz#Nu>1! zy_=-~P)KjJvRCVNmMykxYkW@acJQxJ+hIi|yGCKRxE5De@{KqX<=O%iP1;>2l(RiFw^wLAo8?UQPP*p*fZ^Od5A+`s@|}J3f!kC+-JKa$mL^Y zuzdL85Y*ZfwH}qy5?Ro8ARkWX<|`-dW!+f&*QQ3+DLQB7r_W{SqzProV$?z)^3!ff zPu~=QRb|<*5I0A3C~AF~;}$~}xS(-{nuJ;}XbcTk;i7;o*%I$wyW>(Y z2awRf`9cN9cUE-{%jH2Gl z)EyTl1}&8ZfFf6Y3a@Ns+_e+13>FZu?0}A8m&UY5s zl7MB<16*k0wAT5o3GCD7?enaOtQw=}mTP~mUsN@)9aM~e1{H2S4d0j9QZpi)oB0PHX#`@=f>dP;?JKd~tl zK!`#4h|2w`dSSy}9D)wY-CzZyJG3$B6qaxU&i>}Zv2-`ABbM%YG>Rjc##y@OY4g&_ zCuCj@Ai?&imT!lC#{!OfcDxub^5qDZI!FmXrgogDJ!sjAcCB`6SEu(%iR+EapoMC1<_zD5V^* z2cyX3WPF*Sh1{NFA!rMhgAhWvTnpi}+^U{K$lmugI;`0pIx+{jze1DPkV~Xx7IZ*U z2+7jEvg;0(Hg+gorM|~xX3tud-ymKKGg}J7A0901{%kT8rgO z$HJ#W_yK1_JP}ku9M@<%n;gk34Fnt^y8^Qk?&>{}m2hqDLs(YAwOR?z1!1X&{aFys zsba6Cik^I?g7&iW;aE=i_O@IsjGmo05$&j;eP-D5<|}t|1&np2%s4Itbl~9obFb6X z&d8@`DJJ06@?P+)n+G?(g>{3?d*Z`nd?C!bd9&6{!DbGr9&d~A&0( zz3q!1f?>(wyJxAVzJl3Zhm?J0WE^Dtv4{(SZ_p&qDokvt%X^BU2sw>`6?V&pU92!{ zwZze=;xlem*o|6YF1ur-%DkruiV)8!ZJ(vIO|H50>DLsYfeZ>U;`4H;xlPvQ7e{U9 zZFi2Q#ub<^HojTo@3oR>*#_<6767tRcAxrJRth%1-m1Q*XQkYtmC|JaNnHf&JUO96 z=jm2U1)bJgxdw`4Em~YoaHri5IV)wrO*NcD# zWx>DU^h;Ur*mA6o5n#c;RSVv}D@uw!;JDbvY0m!du!P@bd(Ywzs8A=A5YC-iIHy^6 zIXmkp@7|STBHSHX+#G$ECb1!xNXyWtcjbXzL$dTo&z#EAw;kNT(tn$les_+Z6ux)w z%7a)=_IF#dU!TLuqWA7ydEf+)5DU(SkhXuS-c9W=eD5pN9eCYf#huspYV#@nT$v z;vJejJ)1n5-ICq4qiTBw2ju&-^^OWaO|05M1*)sV*yDkjG7 zKI?NVZhXjazd8wo#r-Z#(pF~epg#MQ98`0LY=;)P!Z{)`SC(}gK2Nv47GV?~(&U zvl8%?k3O7+mGA*grdN~6j?2BiV?jGw1%N^xIN(O|-=|kCJTwq+zn(u9LGnYE3asT7 zsRQro)gd!YLIClK2#({Cd9b#=DkTK$MredKEnJ?xg0+ATt@N=#tc3?Pp$!&DP7MKv z*oBZnC^$Sw6$G_<;-Q9s1;H1IAox*B3;HvS2^9oIKo*3#kPXf`QUyW1npi<_0EvQd z)4*(20X}qlm``KEsYtAXk7+W!8X~8Gpi{MS8#zj;DnUXXIFX6@FOOO)OROoYp7ZX$ zIBZidrr2Qx`j2bA`*acy1qUo={#XP_oD!v~I_uM+36(QVLh85-y`{Z_H?d0a;h{d9 zidBLms8sRO5ECnYPAI|pCpF3q)=NuUK3!~ARpjXzM`KAn%k?e0qJq|>Ep45zYh!+#nqzyzch6CMXVegi2 zER_V_e!#l2mq`fxmUDj00)IMpupA5gX|3Pfs-L~k`Sf=kro(*p6qMNMAn-Yz7qN#` zq;XeCiT55>cT(vUyf(T#r2+`VKg=r5EpPt+!Zrdrotn zQ7PP&6m+QJi$vt+c}vrJ5mM?o;7~&mkXoLPQgY{r_(T-n`M+SuBM(_2IM`6?e!T)v znh)5Sb^r;sU(g79^}Add57@&h02GM7q_t~X_;e`Pduq;6%5n>Pc4)D}_oC*#B$`X* zq32b>TH<1OL|NH;-Y2=Nd^vXlC9CGkmI2t-MWqb{ESEXr(hPWU7e`V`h4~C2{Qm{rW?ZkVn&X=SB=1k(ySZOM!<#VO1#k>0T zB_N@NE`K=wE!HJYpZP9d$wJ>3U54*y!q_hET%x!290IQ8dSehm{H`_|mz8R}()WL* z+Kxpmv3^hIuB4)H5!b_d+Jjk7P<$fm-?!|?WyxAvkauZyD7cWU0FTT@_4@ev-(?Ns za3Ot?FqhUJXc?SQ2&;@M;MNK+c#*{)YBFcLB+FGw0l#AO!y(B1NE=gbzTK|l3pIL!Fv5Y6Tv@UHX;Go1JEuc7e zI0jl)H{I4dWeNfNK6zk5B|p zGf;rue$hWz{y3LQA9>C4|Ao$1Nx2Q!!y3H5U-ja`9g)cNFD=d6*Y>6E19m5E9LtJg z26BW$x~2MiZLgI91RO;a01AeGr4etkzt0(gcQffFom?vI5XiEK8$Em%LZ8==oqr$at&u)NlSQ`A|n zSPfM3?+)YvOP~v=IMk%%;&B!|j;j;rzT@vTwrvwZBT@@Af40!XqUF3b z8fdEE`D~4L;fNswy1y8U7cW{QveupvREi*Ts5}QDv=UcP#JW`~d2I7Er0oHM>OK3}mbNas14<&o&tcqI@_m_5ZZ0D%)Fmn3s1|<%LziiOl}X4Q;U+&{}Nu?v~z5HWIOQ9yX=sojZhpII>vT#lFY#Nq2ZIoo5V3NC`UYBS`{)@T^{O~ zZXonnDEhk6srREBn34tu8WpJzL1h}=d z9_~uo0=FG|n&F*_y;AV{ur3SlJWLP6!&ewM*xJPQS=8O|v9IbH6FzSFxr==)<37kf z)>WQnA9ItygwQuB7qSQWw(KQMYh=;MP;GaJlq1&?e!Y z2KP8RUASk!J)X`K?pbh8pv}TP8}5me5pEyclc-;~18`5KEZjz1(B|>G|Ej-8u4G|q zqOC~ZOqalIp*O%?g%8Ext;QEk!n=&UHFUZ3u3)bf-`@!DD)!dW)zZ6$y;Ja6i17BZ z*M@u2gm)c#>+o5E@UCaCo$pQa_`UDy_em~QVei2Hcz|?Zk376i?2{MX&FrnmHf`bE z%3c?)KNH^V>~&)&vGDF-uLl>C3GXiUda=({cz3h60T-1C?_Tyc(tZD5d)ERcS5c*J z_s#{$11HtfndzPoLnH~{ou0n8`}Sj2{KCt1Q9dT_2_e8j z2+xoJ2Et2ljYQZXx`K<3Pd4kqiYutd!w8S($z&!(Sni$gtN+%0 zRdwCDRp&qFR2_lM1fQ}IxU9i;-$m0-h@yuu{n4l4T!`GK;a~{(jJ-wRHiDDk+QxvG zE8(WkBK#P`odOS2$8!oCuNdwo_#C2xF?@yK^Kb`ZKs1wZ)88Xn7z1LJgqsTRQ(@Rf zP^9Q#jkc{9zb0*~yUr5)DR55-J{5p6f_^bPNKk==AJBsUV1W4u0>-d|U;zx&fQ2wp z1HND*?gqiP2~LGA6|e|_x&WskSQi7rV1%0%!=wl3g;@`?H%p5b*~QT_B8EMTl1g zTuVW#1Q8P;jIe>AF~D`iWq^njh(J~iwt>|@l-iqd6Noka!-y0J;U9>3DOi+0jQJLb zLIuRc2rQG&h{f>32os2)RKTk#G8J$Gg{K0-j~`3hGya(nPW>xsoJD}Za|jV7@LWQ8 zoS&!hd_u$xynqnF11}`J36uT84JvO9tXV6yH={jp72UNN6VwQAMz}_emk=Tr;98BB z65fgsjv6l`gm3WW8m}PSf{8gAuOvkLz^gQ_C%heVL^N(7+=?~RHC{`IFoTHb)Lv+(HNk!rL_7PKY3b zTL}?q@D7c462j5#E{%5+!t3oGjR>pMU>mq(iqzgnR>1q{uKN+qkPyCF|E%$AgmB#2 zrt#~92r+oS#_fcNH~0;W4-mq`=s`k6Ap94N1B3`i_>jgOggdYjy~b}5eiP9GH6p4} zgKc2#6Hg(sTvV|8f*iXo-DODvNtSnFVkJX-w?ta_dgncONc;*uMi@d;qNrQN(gJu?=`+g z2-DB&8s8v<9q11l|48^V^ihOAM<1o}O~PLwo}I>(G!#FBK8iTNu-m}8nA9FuF=IeT z!}I7a;Q55lh7b}5_#ApLjTaF<4@RPK6(PbOuGYAQ@K=Z{t8pzMw6vEJzKA|b<7I@u zMjxf|3c{DrM`^s0@MZK-jcOk{_VPnccs~g(xN1FJjd+JwYurGH;D^^}yq55{=)nk~ z7Q3GCcj%)u-bjcrg&PT>EV@bKCXJg3p+UM?<1HF*C43!ymBuX^ZzFsIJWb<$8ox^T z2lOTyzou~;;UD3ltMPt~+X)dV@f#W+B1G849fW^EZ=vy9gm0p^(D>~}tv2-k;JM3> z>OPQ$)E(9#H-Ajs3tNH#p{W^c+q?xU=51KlC+Vtq0Ss>4#f(}Xk9YiuZg&;SJe58nMf-SD2@wde$ z>Jk;PsFk^3jG1Mes4JKvak#h$cI|cog+6`7yzZI!SFsQjh*El;7UBX?O0N*%_&BB4 zMiF`_rB?;VX-?_&Afha%^hzv#Ar=DmpvvHc4j7>WKIniAI$(j0-9icFh#ES?2_2$@ z%mN+zgR}<@<=CK54lyOi22pZ|8#y+pkwa|AvCF9YD7M@G>5=YM{5)T8Kvr$og!yPOmcCdul!SZ1T!k5xXk_|h!x9&iEHQJ}1 z8rO45y)>@plzM1f&nf9X5~K}C5ZO)G;JOJG_!2DcC0N)?AoM65CqXZPh?SI{gL)^p z159xDm*CDX!Cha1JH7;Bg3&e9=_L>uj8f{T5(vdb|Ee=60SoU$Joiy=Pha(B_d#e3 z`A_de=xf?1dAO6M;ZBx?I}yW`j*uLTb4ue1j&n+5N+*vforv~E`!t$#BIX-D zg=SW@G}}k={!yIXjK|@`EdtE;nuYB(3)^c(fN8#j*>UfUNZtt@AhYIU;jY& zRQx=Y!W5@jC{D9boMuEB=5tJOnniqSMtDg+$ih=If;@7LMW<$woSG5vkq@%m)NHfZ z)QmV;I5>qBIa5T~o&s5$k6kRVN?^6X6%9vp%X)SF@!iv@;?n6TR^lj|lsHQ0o&w$D z-1h~T&?zBwO5{z2D4u-Dy#g#wDv>6Y2$KqdHTjZl0xU@?8KRVoPzu4+_!1tMlnhHs zMj<7Gj*>A3&y*{91c|T`En**ynO_Xsepj|i=gV5SeBV_F|UAaKqxJB5$_JUav>}u!=a{y%32SMynY7@Ua*ioWjMU1p?CxK%xgs?4+LO9x zQNxKq6l1$Xj8(}oR@BC9Qq;y+Q5&;KQ5$3BY|JL*Y|JijTI95cQ?gdXSiu?-9cj$I zn0{hRbfhtRwdB?aTq3Ym;8KA{1XzI=xHwKe?NXA-G9|MHo7;KZ#SAIu}4)TSZCXQSW2$FJY`TiG^wQA$3^Jq}9 zSeCA1Kx8tkr8_WwI%LRlXvlMH^ec|Nkdjj=SwzVaO8O~TPRZGnti(GptmWc{|Cpi3 zrZeXesc>xiDGu{Shoxx{6Fx%U21pI3B(yjzSvx%VcW|fH!M#`qQ_2n=78CSAL(0eH z;0c_P>N~;Rd?$VRoop8B#1d7sPa;mIh&IjKUo_i&c+<`H8Jw~`0x~SFf}Bb{!xZ^C zr^xrH$g-&Dzf_U^P;tMe$R3M*>Y|iA3ynU?ZT+Sf=5Z%y-Ya!Kiic*!c230{S+Si{ z@rRTGcaY{p!vQOglQ=F1rQSor4*siFEF5?K<6%`L%itUPu$TN-FJy<<#ZXRD>x;4qY@LN5^JK8K~af~P>B?+M0{2v z<0U1Q&YCFDbc|wv8pMtswpw2DG>vd z*wLzts-8+cCM7aeRALQNBD*RPT9w$plu!#LoI(kwQ0UtmG-+t&tq;vR1bqe?p1XV{ zUA_`oPKgkw#F(YThNW0Jfg64;m3m3wWdSx*DX~&1kw2AqZzwTBDUm;wn4pwcpp+P( z6e}h0Xf`(~p&=3WABnK8E5c%DgvHJXdyz!!vrzj8%K#CvQ%1x<*}^hNi&&6bumTmX zYY}r?3$!c^T4d;9m}4H9M=CS$6q0+QZ1|6|;Xi7Bk&m3o=?*FYbb(;1eK4ojNrt76 zR+f)iMRiw|-k+i?TE)+$jrCKIr!S;~ZK5t{6Fq^5z$}c#n25)ih{s5U1`(8eBx0=C zh}lQ+{?VM0FGS2<%qdgR7^_hrAc@d7Y3T1AK0ol~ z8=c!}GU-U$SGFXr_s}Iftivb$2)NR6e{&+EcjZpT)DcSX*-tR0ZJqp!e= z-So*d{e|M9O2W(TzqGfvKjEe=>#xqc5icY#kUAXJ&(la?JK8M0n zZZcOYO7ULatrjZps%z-GI*8t2m%L9e<&-#f+b2y$<*a#=Bb`kpM?Bl$$x?1AJ>tE& z;m_)O^TVH&I;R_ytIuXeym!PW``$?R`u>P#8~h@vRmL6Z-pq(?mB|jhcM`u}gjMYQ zSnqr|Tz+$FzZJLYzfis=A*JgNTxXKC7pCgZ&~S!b?5T6Ip3?x`E|LvXJ*{m zbD4BqE?b++*3~oX*Z!coN9O7-%+*yoS6AtLUE%q?OmV7b=9kblA&;y=>UahdpGAA#VbG%U(W} zEvIF-;JRt}%!Yn^=Uvux%XF$5eT^B7rqj*oe0e|aggwc6X^p-dPDwVU?@H;rQh9y6 zps}d2q_IaZt?x_gysulrcjdgV&-?nhzJ88hlH#)hMFD+K*SJT1d@)&cb(0iJeqJ|8 zDevdK2_@=s)A@ASmEB@8Sx)h;m&_*9nNU(^a_Mw+w@{K@w6UL0g_8Au`i8ul?vdSe zCSNMcZno^Ei*z~HES2mj<59ZfP3Z!XX*ZiLO4Tzt50&J%nN1a|yCpAKk)t`+&!u_` zeGB`#=v(dU>MwOIFO*JO)I~1bOP4Jo$Mn;%?%2Y`^E(QQ=JzgL*uOvqkdz)kFc6rr zCFS%is$hJnEbVeLrEET(Db3jX+XN}!ub2vy^uS3&q#mep7{qvtbjxO#l2OXdQfpwC z%$RYioK1O^WF}Mn6@FzLbtbjQh1Riu9kT3pYs!9~ThQOXq^q+N1AJl8g5JLVt{na^ zI+qldbWVKg%@1wgcu%`E`OxkoyJz%OmZBMF6#8e3aLbxMe`xy++m!X$LXX$|@xSR^ z{v+NBb*%{dhWRad_yY50c;e2vtB8X*)1<5GL=ycRqA5 zayvo~Tcj0gU5Q@;xh}lY3Z31I6JwO`@SMgG;*G& z<-F8;_@5@>7tBt{?3DE-h24vSe-Y717h3bVk(gMl3T&mUS1YjP>jbt^v0^@ilKv3# zJ@O?`*X89aN%I}l3W=%Z`Wq`WkWEv`+A`f*8L{!Fml^u$74q3aw&K=&dWBUXU2@5k z41u^#EFPigf~$Y5=jk8oo3EZf`eZ7X*3u~zo%7th5s`H-kRI#>N-K0t%BChm1@sYW zf_9bu2V$)V>1k6F5!1bbX?Lzk+N}(hT-L;(+W2Vex+d`JTHmW}{Zh3Fs`9xM>`CLN zvN_!XY1dDsJil6Of%(+iMn*@+)3pCX*8ARG(uNjd{{KiFlgxnVWz&UfCY>vJp=34d zL$;_&GW$?4!JrdtK??*e5VSzh0znG|E%5ee0WBBT@Nc6404J|%0E%uoo6Pm($3dot zzg6@9OqCIpcjf?p zNuz*+^{9@Yj!>8Chw1hVq3FU-YbZKX@-#m4y1FFGUX`+DlGVBxBN`q%>bf*0>A9gK zo$HdxX6oxw*J-#~Uyw1DwO!N&J+(TMR4r?7{DyK`XOc~7+AeRTt`&?S@!hU3cyH5+ zKwki*-X2>iCb@c4^s+gzX?V%q8!T{_{BzKqj>VSs$U<+CxXn~*w zf))r`;2qxr!vAaex8eUdR^|UCH`|je=KWEz<~_N{@c&)tM~(e|EHtC~Ba(Ykn<3W@ zrT=q<{?8qr{?DcVg{ZZCkp9ml1pyB3F!Ue$3qH9Q=s&!7ZrM3`pV9wU?36XRA^ji5 z3UAEuMl;~|1a^6Ldo}mgM**>M*O#vp}y)fu&*rj z4O^vbdl~`2YBD#{U*p8DQ$YHGePo{?ioxSJb}q{XfxuWEkIn zP5#pwGa9oRa~ku(Jp8JeJ#~(@_ovMq^gS^5=ZDVx&*&-WVr|2uUhPtzN#--viSRTn z+{J=Q=95mJtE-UNtA=GU(50$w?U`iR&l&G})WPdX4f4;7sYBM(VGm{;R8@i183$%6 zzSy?CyqO7foT-9Yb);%v$I4i=FAH|nx%U^Uufj}v(67QXufi+_ zF!Yz_bg6k$>K;sQsPb;C4Uk25dL4ozYSL?46^@9t|wVa<@f&V{~0rk{lChI%nD&O z3V=b`cj!uBd9xCjk@{sqZMrS$3!$Cl>XCUbu0deN`d|%$w@elc9vrkl&;mgV1TFCHX#p){ z*6?qm06>6{s{cQh{&UN@e0ErtJf4Gw|NGh|hQ+=`$gSc3Rioc7>u=|^8y})NNSqpx zqci0}l9d_Hnguce;P-VC01gl)Ki9HOo;v;s05MDe7}$ps0M<60Kf(lnQ89T#>5c6_ zp!9?PZNb`ph)^{QnGM$VL$t1px5l_%?6TZx)$yP%8bDnvhCwyx9&q})`#DS!7!zrimJS|DhF fpatH&Eui^-4gaq4e}9nwBR*oeoPP^E04Dq&;GxU{ literal 0 HcmV?d00001 diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/TestBase.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/TestBase.java new file mode 100644 index 000000000..1cc25d6aa --- /dev/null +++ b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/TestBase.java @@ -0,0 +1,1082 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-TEST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test; + +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.URL; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.GnuParser; +import org.apache.commons.cli.HelpFormatter; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.ParseException; +import org.apache.commons.io.IOUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.http.entity.ContentType; + +import com.att.research.xacml.api.AttributeValue; +import com.att.research.xacml.api.DataType; +import com.att.research.xacml.api.DataTypeException; +import com.att.research.xacml.api.DataTypeFactory; +import com.att.research.xacml.api.Decision; +import com.att.research.xacml.api.Identifier; +import com.att.research.xacml.api.Request; +import com.att.research.xacml.api.RequestAttributes; +import com.att.research.xacml.api.Response; +import com.att.research.xacml.api.Result; +import com.att.research.xacml.api.pdp.PDPEngine; +import com.att.research.xacml.api.pdp.PDPEngineFactory; +import com.att.research.xacml.api.pdp.PDPException; +import com.att.research.xacml.api.pep.PEPException; +import com.att.research.xacml.std.IdentifierImpl; +import com.att.research.xacml.std.StdAttributeValue; +import com.att.research.xacml.std.StdMutableAttribute; +import com.att.research.xacml.std.StdMutableRequest; +import com.att.research.xacml.std.StdMutableRequestAttributes; +import com.att.research.xacml.std.dom.DOMRequest; +import com.att.research.xacml.std.dom.DOMResponse; +import com.att.research.xacml.std.dom.DOMStructureException; +import com.att.research.xacml.std.json.JSONRequest; +import com.att.research.xacml.std.json.JSONResponse; +import com.att.research.xacml.std.json.JSONStructureException; +import com.att.research.xacml.util.FactoryException; +import com.att.research.xacml.util.XACMLProperties; +import com.google.common.base.Splitter; +import com.google.common.collect.Lists; + +/** + * This is a base class for setting up a test environment. Using properties files, it contains the + * necessary information for + * 1. defining and providing attributes + * 2. defining and instantiating the PDP engine + * 3. creating PEP requests and calling the PDP engine + * + * + */ +public class TestBase extends SimpleFileVisitor { + private static final Log logger = LogFactory.getLog(TestBase.class); + + public class HelpException extends Exception { + private static final long serialVersionUID = 1L; + + } + + /** + * This private class holds information for properties defined for attribute + * generation. The user can configure the properties file such that attributes + * can be automatically generated and added into each request. + * + * + */ + class Generator { + Path file; + InputStream is; + BufferedReader reader; + List attributes = new ArrayList(); + + public Generator(Path path) { + this.file = path; + } + + /** + * read - reads in the next line of data + * + * @return String - a line from the csv containing attribute data + */ + public String read() { + String str = null; + if (is == null) { + try { + is = Files.newInputStream(file); + } catch (IOException e) { + logger.error(e); + return null; + } + } + if (reader == null) { + reader = new BufferedReader(new InputStreamReader(this.is)); + } + try { + str = reader.readLine(); + if (str == null) { + // + // No more strings, close up + // + this.close(); + } + if (logger.isDebugEnabled()) { + logger.debug(str); + } + } catch (IOException e) { + logger.error(e); + } + return str; + } + + public void close() { + if (this.reader != null) { + try { + this.reader.close(); + } catch (IOException idontcare) { + } finally { + this.reader = null; + this.is = null; + } + } + } + + } + + public static final String PROP_GENERATOR = "xacml.attribute.generator"; + + public static final String OPTION_HELP = "help"; + public static final String OPTION_TESTDIR = "dir"; + public static final String OPTION_TESTREST = "rest"; + public static final String OPTION_TESTURL = "url"; + public static final String OPTION_TESTOUTPUT = "output"; + public static final String OPTION_LOOP = "loop"; + public static final String OPTION_TESTNUMBERS = "testNumbers"; + + public static final String DEFAULT_RESTURL = "https://localhost:8080/pdp/"; // Modified for test purpose. Port no. 8443 to 8080 + + public static Options options = new Options(); + static { + options.addOption(new Option(OPTION_HELP, false, "Prints help.")); + options.addOption(new Option(OPTION_TESTDIR, true, "Directory path where all the test properties and data are located.")); + options.addOption(new Option(OPTION_TESTREST, false, "Test against RESTful PDP.")); + options.addOption(new Option(OPTION_TESTURL, true, "URL to the RESTful PDP. Default is " + DEFAULT_RESTURL)); + options.addOption(new Option(OPTION_TESTOUTPUT, true, "Specify a different location for dumping responses.")); + options.addOption(new Option(OPTION_LOOP, true, "Number of times to loop through the tests. Default is 1. A value of -1 runs indefinitely.")); + options.addOption(new Option(OPTION_TESTNUMBERS, true, "Comma-separated list of numbers found in the names of the test files to be run. Numbers must exactly match the file name, e.g. '02'. Used to limit testing to specific set of tests.")); + } + + protected String directory = null; + protected Path output = null; + protected boolean isREST; + protected URL restURL = null; + protected int loop = 1; + protected PDPEngine engine = null; + protected List generators = new ArrayList(); + protected static DataTypeFactory dataTypeFactory = null; + + private long permits = 0; + private long denies = 0; + private long notapplicables = 0; + private long indeterminates = 0; + + private long expectedPermits = 0; + private long expectedDenies = 0; + private long expectedNotApplicables = 0; + private long expectedIndeterminates = 0; + + private long generatedpermits = 0; + private long generateddenies = 0; + private long generatednotapplicables = 0; + private long generatedindeterminates = 0; + + private long responseMatches = 0; + private long responseNotMatches = 0; + + private String[] testNumbersArray = null; + + protected final Pattern pattern = Pattern.compile("Request[.]\\d+[.](Permit|Deny|NA|Indeterminate|Generate|Unknown)\\.(json|xml)"); + + public static boolean isJSON(Path file) { + return file.toString().endsWith(".json"); + } + + public static boolean isXML(Path file) { + return file.toString().endsWith(".xml"); + } + + public TestBase(String[] args) throws ParseException, MalformedURLException, HelpException { + // + // Finish Initialization + // + this.restURL = new URL(DEFAULT_RESTURL); + // + // Parse arguments + // + this.parseCommands(args); + } + + /** + * Parse in the command line arguments that the following parameters: + * + * @param args - command line arguments + * @throws ParseException + * @throws MalformedURLException + * @throws HelpException + */ + protected void parseCommands(String[] args) throws ParseException, MalformedURLException, HelpException { + // + // Parse the command line options + // + CommandLine cl; + cl = new GnuParser().parse(options, args); + // + // Check for what we have + // + if (cl.hasOption(OPTION_HELP)) { + new HelpFormatter().printHelp("Usage: -dir testdirectory OPTIONS", + options); + throw new HelpException(); + } + if (cl.hasOption(OPTION_TESTDIR)) { + this.directory = cl.getOptionValue(OPTION_TESTDIR); + } else { + throw new IllegalArgumentException("You must specify a test directory. -dir path/to/some/where"); + } + if (cl.hasOption(OPTION_TESTREST)) { + this.isREST = true; + } else { + this.isREST = false; + } + if (cl.hasOption(OPTION_TESTURL)) { + this.restURL = new URL(cl.getOptionValue(OPTION_TESTURL)); + } + if (cl.hasOption(OPTION_TESTOUTPUT)) { + this.output = Paths.get(cl.getOptionValue(OPTION_TESTOUTPUT)); + } else { + this.output = Paths.get(this.directory, "results"); + } + if (cl.hasOption(OPTION_LOOP)) { + this.loop = Integer.parseInt(cl.getOptionValue(OPTION_LOOP)); + } + if (cl.hasOption(OPTION_TESTNUMBERS)) { + String testNumberString = cl.getOptionValue(OPTION_TESTNUMBERS); + testNumbersArray = testNumberString.split(","); + // + // reset strings to include dots so they exactly match pattern in file name + // + for (int i = 0; i < testNumbersArray.length; i++) { + testNumbersArray[i] = "." + testNumbersArray[i] + "."; + } + } + } + + /** + * Using the command line options that were parsed, configures our test instance. + * + * @throws FactoryException + */ + protected void configure() throws FactoryException { + // + // Setup the xacml.properties file + // + if (this.directory == null) { + throw new IllegalArgumentException("Must supply a path to a test directory."); + } + Path pathDir = Paths.get(this.directory, "xacml.properties"); + if (Files.notExists(pathDir)) { + throw new IllegalArgumentException(pathDir.toString() + " does not exist."); + } + // + // Set it as the System variable so the XACML factories know where the properties are + // loaded from. + // + System.setProperty(XACMLProperties.XACML_PROPERTIES_NAME, pathDir.toString()); + // + // Now we can create the data type factory + // + dataTypeFactory = DataTypeFactory.newInstance(); + // + // Load in what generators we are to create + // + String generators = XACMLProperties.getProperty(PROP_GENERATOR); + if (generators != null) { + // + // Parse the generators + // + for (String generator : Splitter.on(',').trimResults().omitEmptyStrings().split(generators)) { + this.configureGenerator(generator); + } + } + // + // If we are embedded, create our engine + // + if (this.isREST == false) { + PDPEngineFactory factory = PDPEngineFactory.newInstance(); + this.engine = factory.newEngine(); + } + // + // Remove all the responses from the results directory + // + this.removeResults(); + } + + /** + * Removes all the Response* files from the results directory. + * + */ + public void removeResults() { + try { + // + // Determine where the results are supposed to be written to + // + Path resultsPath; + if (this.output != null) { + resultsPath = this.output; + } else { + resultsPath = Paths.get(this.directory.toString(), "results"); + } + // + // Walk the files + // + Files.walkFileTree(resultsPath, new SimpleFileVisitor() { + + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + if (file.getFileName().toString().startsWith("Response")) { + Files.delete(file); + } + return super.visitFile(file, attrs); + } + }); + } catch (IOException e) { + logger.error("Failed to removeRequests from " + this.directory + " " + e); + } + } + + /** + * Configure's a specific generator instance from the properties file. + * + * @param generator + */ + protected void configureGenerator(String generator) { + String prefix = PROP_GENERATOR + "." + generator; + String file = XACMLProperties.getProperty(prefix + ".file"); + // + // Create a generator object + // + Generator gen = new Generator(Paths.get(this.directory, file)); + this.generators.add(gen); + // + // Grab attributes + // + String attributes = XACMLProperties.getProperty(prefix + ".attributes"); + for (String attribute : Splitter.on(',').trimResults().omitEmptyStrings().split(attributes)) { + String attributePrefix = prefix + ".attributes." + attribute; + // + // Create an attribute value. It is simply a placeholder for the field within + // the CSV that contains the actual attribute value. It mainly holds the data type + // + Identifier datatype = new IdentifierImpl(XACMLProperties.getProperty(attributePrefix + ".datatype")); + Integer field = Integer.parseInt(XACMLProperties.getProperty(attributePrefix + ".field")); + StdAttributeValue value = new StdAttributeValue<>(datatype, field); + // + // Get the rest of the attribute properties + // + Identifier category = new IdentifierImpl(XACMLProperties.getProperty(attributePrefix + ".category")); + Identifier id = new IdentifierImpl(XACMLProperties.getProperty(attributePrefix + ".id")); + String issuer = XACMLProperties.getProperty(attributePrefix + ".issuer"); + boolean include = Boolean.parseBoolean(XACMLProperties.getProperty(attributePrefix + ".include", "false")); + // + // Now we have a skeleton attribute + // + gen.attributes.add(new StdMutableAttribute(category, id, value, issuer, include)); + } + } + + /** + * This runs() the test instance. It first configure's itself and then walks the + * requests directory issue each request to the PDP engine. + * + * @throws IOException + * @throws FactoryException + * + */ + public void run() throws IOException, FactoryException { + // + // Configure ourselves + // + this.configure(); + // + // Loop and run + // + int runs = 1; + do { + long lTimeStart = System.currentTimeMillis(); + logger.info("Run number: " + runs); + // + // Walk the request directory + // + Files.walkFileTree(Paths.get(this.directory.toString(), "requests"), this); + long lTimeEnd = System.currentTimeMillis(); + logger.info("Run elapsed time: " + (lTimeEnd - lTimeStart) + "ms"); + // + // Dump the stats + // + this.dumpStats(); + this.resetStats(); + // + // Increment + // + runs++; + } while ((this.loop == -1 ? true : runs <= this.loop)); + } + + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + // + // Sanity check the file name + // + Matcher matcher = this.pattern.matcher(file.getFileName().toString()); + if (matcher.matches()) { + // + // if user has limited which files to use, check that here + // + if (testNumbersArray != null) { + String fileNameString = file.getFileName().toString(); + boolean found = false; + for (String numberString : testNumbersArray) { + if (fileNameString.contains(numberString)) { + found = true; + break; + } + } + if (found == false) { + // + // this test is not in the list to be run, so skip it + // + return super.visitFile(file, attrs); + } + } + try { + // + // Pull what this request is supposed to be + // + String group = null; + int count = matcher.groupCount(); + if (count >= 1) { + group = matcher.group(count-1); + } + // + // Send it + // + this.sendRequest(file, group); + } catch (Exception e) { + logger.error(e); + e.printStackTrace(); + } + } + return super.visitFile(file, attrs); + } + + /** + * When a request file is encountered, this method is called send the request to the PDP engine. It will also dump + * the response object. If the group equals "Generate", then it will loop and send the request with generated attributes + * until that list is empty. + * + * @param file - Request file. Eg. Request-01-Permit.json + * @param group - This is the parsed out string of the request file that defines if it is a Permit/Deny/Generate etc. + * @throws Exception + */ + protected void sendRequest(Path file, String group) throws Exception { + logger.info(file.toString()); + int requestCount = 0; + do { + // + // Generate the request + // + Request request = this.generateRequest(file, group); + // + // Was something generated? + // + if (request == null) { + // + // Get out of the loop + // + logger.info("NULL request generated."); + break; + } + logger.info(request); + // + // Call the PDP + // + Response response = this.callPDP(request); + // + // Process the response + // + this.processResponse(file, request, response, group, requestCount); + // + // Is this a generated request? + // + if (group.equals("Generate")) { + // + // Yes, increment counter and move + // on to the next generated request. + // + requestCount++; + } else { + // + // Nope, exit the loop + // + break; + } + } while (group.equals("Generate")); + } + + /** + * Sends the request object to the PDP engine. Either the embedded engine or the RESTful engine. + * + * @param request - XACML request object + * @return Response - returns the XACML response object + */ + protected Response callPDP(Request request) { + // + // Send it to the PDP + // + Response response = null; + if (this.isREST) { + try { + String jsonString = JSONRequest.toString(request, false); + // + // Call RESTful PDP + // + response = this.callRESTfulPDP(new ByteArrayInputStream(jsonString.getBytes())); + } catch (Exception e) { + logger.error("Error in sending RESTful request: " + e, e); + } + } else { + // + // Embedded call to PDP + // + long lTimeStart = System.currentTimeMillis(); + try { + response = this.engine.decide(request); + } catch (PDPException e) { + logger.error(e); + } + long lTimeEnd = System.currentTimeMillis(); + logger.info("Elapsed Time: " + (lTimeEnd - lTimeStart) + "ms"); + } + return response; + } + + /** + * Reads the request file into a Request object based on its type. + * + * If the request has "Generate" in its filename, then this function will add + * generated attributes into the request. + * + * @param file - Request file. Eg. Request-01-Permit.json + * @param group - This is the parsed out string of the request file that defines if it is a Permit/Deny/Generate etc. + * @return + * @throws JSONStructureException + * @throws DOMStructureException + * @throws PEPException + */ + protected Request generateRequest(Path file, String group) throws JSONStructureException, DOMStructureException, PEPException { + // + // Convert to a XACML Request Object + // + Request request = null; + if (TestBase.isJSON(file)) { + request = JSONRequest.load(file.toFile()); + } else if (TestBase.isXML(file)) { + request = DOMRequest.load(file.toFile()); + } + if (request == null) { + throw new PEPException("Invalid Request File: " + file.toString()); + } + // + // Only if this request has "Generate" + // Request.XX.Generate.[json|xml] + // + if (group.equals("Generate")) { + // + // Add attributes to it + // + request = this.onNextRequest(request); + } + // + // Done + // + return request; + } + + /** + * Called to add in generated attributes into the request. + * + * @param request + * @return + */ + protected Request onNextRequest(Request request) { + // + // If we have no generators, just return + // + if (this.generators.isEmpty()) { + return request; + } + // + // Copy the request attributes + // + List attributes = new ArrayList(); + for (RequestAttributes a : request.getRequestAttributes()) { + attributes.add(new StdMutableRequestAttributes(a)); + } + // + // Iterate the generators + // + for (Generator generator : this.generators) { + // + // Read a row in + // + String line = generator.read(); + // + // Was something read? + // + if (line == null) { + // + // No more rows to read, return null + // + return null; + } + // + // Split the line + // + List fields = Lists.newArrayList(Splitter.on(',').trimResults().split(line)); + // + // Now work on the attributes + // + for (StdMutableAttribute attribute : generator.attributes) { + // + // Grab the attribute holder, which holds the datatype and field. There should + // be only ONE object in the collection. + // + AttributeValue value = attribute.getValues().iterator().next(); + Integer field = (Integer) value.getValue(); + // + // Is the field number valid? + // + if (field >= fields.size()) { + logger.error("Not enough fields: " + field + "(" + fields.size() + ")"); + return null; + } + // + // Determine what datatype it is + // + DataType dataTypeExtended = dataTypeFactory.getDataType(value.getDataTypeId()); + if (dataTypeExtended == null) { + logger.error("Failed to determine datatype"); + return null; + } + // + // Create the attribute value + // + try { + AttributeValue attributeValue = dataTypeExtended.createAttributeValue(fields.get(field)); + // + // Create the attribute + // + StdMutableAttribute newAttribute = new StdMutableAttribute(attribute.getCategory(), + attribute.getAttributeId(), + attributeValue, + attribute.getIssuer(), + attribute.getIncludeInResults()); + boolean added = false; + for (StdMutableRequestAttributes a : attributes) { + // + // Does the category exist? + // + if (a.getCategory().equals(attribute.getCategory())) { + // + // Yes - add in the new attribute value + // + a.add(newAttribute); + added = true; + break; + } + } + if (added == false) { + // + // New category - create it and add it in + // + StdMutableRequestAttributes a = new StdMutableRequestAttributes(); + a.setCategory(newAttribute.getCategory()); + a.add(newAttribute); + attributes.add(a); + } + } catch (DataTypeException e) { + logger.error(e); + return null; + } + } + } + // + // Now form our final request + // + StdMutableRequest newRequest = new StdMutableRequest(); + newRequest.setCombinedDecision(request.getCombinedDecision()); + newRequest.setRequestDefaults(request.getRequestDefaults()); + newRequest.setReturnPolicyIdList(request.getReturnPolicyIdList()); + newRequest.setStatus(request.getStatus()); + for (StdMutableRequestAttributes a : attributes) { + newRequest.add(a); + } + return newRequest; + } + + /** + * This makes an HTTP POST call to a running PDP RESTful servlet to get a decision. + * + * @param file + * @return + */ + protected Response callRESTfulPDP(InputStream is) { + Response response = null; + HttpURLConnection connection = null; + try { + + // + // Open up the connection + // + connection = (HttpURLConnection) this.restURL.openConnection(); + connection.setRequestProperty("Content-Type", "application/json"); + // + // Setup our method and headers + // + connection.setRequestMethod("POST"); + connection.setUseCaches(false); + // + // Adding this in. It seems the HttpUrlConnection class does NOT + // properly forward our headers for POST re-direction. It does so + // for a GET re-direction. + // + // So we need to handle this ourselves. + // + connection.setInstanceFollowRedirects(false); + connection.setDoOutput(true); + connection.setDoInput(true); + // + // Send the request + // + try (OutputStream os = connection.getOutputStream()) { + IOUtils.copy(is, os); + } + // + // Do the connect + // + connection.connect(); + if (connection.getResponseCode() == 200) { + // + // Read the response + // + ContentType contentType = null; + try { + contentType = ContentType.parse(connection.getContentType()); + + if (contentType.getMimeType().equalsIgnoreCase(ContentType.APPLICATION_JSON.getMimeType())) { + response = JSONResponse.load(connection.getInputStream()); + } else if (contentType.getMimeType().equalsIgnoreCase(ContentType.APPLICATION_XML.getMimeType()) || + contentType.getMimeType().equalsIgnoreCase("application/xacml+xml") ) { + response = DOMResponse.load(connection.getInputStream()); + } else { + logger.error("unknown content-type: " + contentType); + } + + } catch (Exception e) { + String message = "Parsing Content-Type: " + connection.getContentType() + ", error=" + e.getMessage(); + logger.error(message, e); + } + + } else { + logger.error(connection.getResponseCode() + " " + connection.getResponseMessage()); + } + } catch (Exception e) { + logger.error(e); + } + + return response; + } + + /** + * This processes a response. Saves the response out to disk. If there is a corresponding response file for the request located + * in the "responses" sub-directory, then this method will compare that response file with what the engine returned to see if it + * matched. + * + * @param requestFile + * @param request + * @param response + * @param group + * @param count + * @throws Exception + */ + protected void processResponse(Path requestFile, Request request, Response response, String group, int count) throws Exception { + // + // Construct the output filename + // + Path responseFile = null; + Path resultFile = null; + int num = requestFile.getNameCount(); + if (num < 2) { + logger.error("Too few dir's in request filename."); + throw new Exception("Too few dir's in request filename. Format should be Request.[0-9]+.{Permit|Deny|NA|Indeterminate}.{json|xml}"); + } + String filename = requestFile.getFileName().toString(); + if (group.equals("Generate")) { + // + // Using count variable, construct a filename + // + // i.e. Response.03.Generate.{count}.json + // + filename = "Response" + filename.substring(filename.indexOf('.'), filename.lastIndexOf('.')) + String.format("%03d", count) + filename.substring(filename.lastIndexOf('.')); + } else { + // + // Construct filename + // + filename = "Response" + filename.substring(filename.indexOf('.')); + } + // + // Determine equivalent response file path + // + responseFile = Paths.get(requestFile.subpath(0, num - 2).toString(), "responses"); + if (Files.notExists(responseFile)) { + // + // Create it + // + logger.warn(responseFile.toString() + " does NOT exist, creating..."); + try { + Files.createDirectories(responseFile); + } catch (IOException e) { + logger.error(e); + throw new Exception("Cannot proceed without an output directory."); + } + } + responseFile = Paths.get(responseFile.toString(), filename); + // + // Determine path to write result file + // + if (this.output != null) { + // + // User specified an output path + // + resultFile = this.output; + } else { + // + // Default path + // + resultFile = Paths.get(requestFile.subpath(0, num - 2).toString(), "results"); + } + // + // Check if the path exists + // + if (Files.notExists(resultFile)) { + // + // Create it + // + logger.warn(resultFile.toString() + " does NOT exist, creating..."); + try { + Files.createDirectories(resultFile); + } catch (IOException e) { + logger.error(e); + throw new Exception("Cannot proceed without an output directory."); + } + } + // + // Add the filename to the path + // + resultFile = Paths.get(resultFile.toString(), filename); + // + // Check if there is an equivalent response in the response + // directory. If so, compare our response result with that one. + // + boolean succeeded = true; + if (responseFile != null && Files.exists(responseFile)) { + // + // Do comparison + // + Response expectedResponse = null; + if (TestBase.isJSON(responseFile)) { + expectedResponse = JSONResponse.load(responseFile); + } else if (TestBase.isXML(responseFile)) { + expectedResponse = DOMResponse.load(responseFile); + } + if (expectedResponse != null) { + // + // Do the compare + // + if (response == null) { + logger.error("NULL response returned."); + this.responseNotMatches++; + succeeded = false; + } else { + if (response.equals(expectedResponse)) { + logger.info("Response matches expected response."); + this.responseMatches++; + } else { + logger.error("Response does not match expected response."); + logger.error("Expected: "); + logger.error(expectedResponse.toString()); + this.responseNotMatches++; + succeeded = false; + } + } + } + } + // + // Write the response to the result file + // + logger.info("Request: " + requestFile.getFileName() + " response is: " + (response == null ? "null" : response.toString())); + if (resultFile != null && response != null) { + if (TestBase.isJSON(resultFile)) { + Files.write(resultFile, JSONResponse.toString(response, true).getBytes()); + } else if (TestBase.isXML(resultFile)) { + Files.write(resultFile, DOMResponse.toString(response, true).getBytes()); + } + } + // + // Stats + // + if (group.equals("Permit")) { + this.expectedPermits++; + } else if (group.equals("Deny")) { + this.expectedDenies++; + } else if (group.equals("NA")) { + this.expectedNotApplicables++; + } else if (group.equals("Indeterminate")) { + this.expectedIndeterminates++; + } + if (response != null) { + for (Result result : response.getResults()) { + Decision decision = result.getDecision(); + if (group.equals("Generate")) { + if (decision.equals(Decision.PERMIT)) { + this.generatedpermits++; + } else if (decision.equals(Decision.DENY)) { + this.generateddenies++; + } else if (decision.equals(Decision.NOTAPPLICABLE)) { + this.generatednotapplicables++; + } else if (decision.equals(Decision.INDETERMINATE)) { + this.generatedindeterminates++; + } + continue; + } + if (decision.equals(Decision.PERMIT)) { + this.permits++; + if (group.equals("Permit") == false) { + succeeded = false; + logger.error("Expected " + group + " got " + decision); + } + } else if (decision.equals(Decision.DENY)) { + this.denies++; + if (group.equals("Deny") == false) { + succeeded = false; + logger.error("Expected " + group + " got " + decision); + } + } else if (decision.equals(Decision.NOTAPPLICABLE)) { + this.notapplicables++; + if (group.equals("NA") == false) { + succeeded = false; + logger.error("Expected " + group + " got " + decision); + } + } else if (decision.equals(Decision.INDETERMINATE)) { + this.indeterminates++; + if (group.equals("Indeterminate") == false) { + succeeded = false; + logger.error("Expected " + group + " got " + decision); + } + } + } + } + if (succeeded) { + logger.info("REQUEST SUCCEEDED"); + } else { + logger.info("REQUEST FAILED"); + } + } + + protected void dumpStats() { + StringBuilder dump = new StringBuilder(); + dump.append(System.lineSeparator()); + dump.append("Permits: " + this.permits + " Expected: " + this.expectedPermits); + dump.append(System.lineSeparator()); + dump.append("Denies: " + this.denies + " Expected: " + this.expectedDenies); + dump.append(System.lineSeparator()); + dump.append("NA: " + this.notapplicables + " Expected: " + this.expectedNotApplicables); + dump.append(System.lineSeparator()); + dump.append("Indeterminates: " + this.indeterminates + " Expected: " + this.expectedIndeterminates); + dump.append(System.lineSeparator()); + dump.append("Generated Permits: " + this.generatedpermits); + dump.append(System.lineSeparator()); + dump.append("Generated Denies: " + this.generateddenies); + dump.append(System.lineSeparator()); + dump.append("Generated NA: " + this.generatednotapplicables); + dump.append(System.lineSeparator()); + dump.append("Generated Indeterminates: " + this.generatedindeterminates); + dump.append(System.lineSeparator()); + dump.append("Responses Matched: " + this.responseMatches); + dump.append(System.lineSeparator()); + dump.append("Responses NOT Matched: " + this.responseNotMatches); + + if (this.permits != this.expectedPermits || + this.denies != this.expectedDenies || + this.notapplicables != this.expectedNotApplicables || + this.indeterminates != this.expectedIndeterminates || + this.responseNotMatches > 0) { + logger.fatal(dump.toString()); + } else { + logger.info(dump.toString()); + } + } + + protected void resetStats() { + this.permits = 0; + this.denies = 0; + this.notapplicables = 0; + this.indeterminates = 0; + this.generatedpermits = 0; + this.generateddenies = 0; + this.generatednotapplicables = 0; + this.generatedindeterminates = 0; + this.responseMatches = 0; + this.responseNotMatches = 0; + } + + public static void main(String[] args) { + try { + new TestBase(args).run(); + } catch (ParseException | IOException | FactoryException e) { + logger.error(e); + } catch (HelpException e) { + } + } +} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/annotations/TestAnnotation.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/annotations/TestAnnotation.java new file mode 100644 index 000000000..84b3f9292 --- /dev/null +++ b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/annotations/TestAnnotation.java @@ -0,0 +1,240 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-TEST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.annotations; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URI; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Arrays; +import java.util.Calendar; +import java.util.Collection; +import java.util.Date; +import java.util.TimeZone; + +import org.apache.commons.cli.ParseException; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openecomp.policy.pdp.test.TestBase; + +import com.att.research.xacml.api.DataTypeException; +import com.att.research.xacml.api.Response; +import com.att.research.xacml.std.annotations.RequestParser; +import com.att.research.xacml.std.annotations.XACMLAction; +import com.att.research.xacml.std.annotations.XACMLAttribute; +import com.att.research.xacml.std.annotations.XACMLEnvironment; +import com.att.research.xacml.std.annotations.XACMLMultiRequest; +import com.att.research.xacml.std.annotations.XACMLRequest; +import com.att.research.xacml.std.annotations.XACMLRequestReference; +import com.att.research.xacml.std.annotations.XACMLResource; +import com.att.research.xacml.std.annotations.XACMLSubject; +import com.att.research.xacml.std.datatypes.HexBinary; +import com.att.research.xacml.std.datatypes.IPAddress; +import com.att.research.xacml.std.datatypes.IPv4Address; +import com.att.research.xacml.std.datatypes.ISO8601DateTime; +import com.att.research.xacml.std.datatypes.ISO8601Time; +import com.att.research.xacml.util.FactoryException; + +/** + * This example application shows how to use annotations for Java classes to create requests to send to the + * engine. + * + * + */ +public class TestAnnotation extends TestBase { + private static final Log logger = LogFactory.getLog(TestAnnotation.class); + + private int num; + + /** + * This is a sample class that uses annotations. In addition to demonstrating how to use XACML annotations, + * it also demonstrates the various Java objects that can be used and how the request parser will + * resolve each object's datatype. + * + * + */ + @XACMLRequest(ReturnPolicyIdList=true) + public class MyRequestAttributes { + + public MyRequestAttributes(String user, String action, String resource) { + this.userID = user; + this.action = action; + this.resource = resource; + this.today = new Date(); + this.yesterday = Calendar.getInstance(); + this.yesterday.add(Calendar.DAY_OF_MONTH, -1); + } + + @XACMLSubject(includeInResults=true) + String userID; + + @XACMLSubject(attributeId="urn:oasis:names:tc:xacml:1.0:subject:subject-id-qualifier") + boolean admin = false; + + @XACMLSubject(attributeId="urn:oasis:names:tc:xacml:1.0:subject:key-info", issuer="com:foo:security") + HexBinary publicKey = new HexBinary(new byte[] {'1', '0'}); + + @XACMLSubject(attributeId="urn:oasis:names:tc:xacml:1.0:subject:authentication-time") + ISO8601Time authenticationTime = new ISO8601Time(8, 0, 0, 0); + + /** + * Here our base object is "Object", but it is reflected as a Java "String". The parser + * will then use the XACML http://www.w3.org/2001/XMLSchema#string as the datatype. + */ + @XACMLSubject(attributeId="urn:oasis:names:tc:xacml:1.0:subject:authentication-method") + Object authenticationMethod = new String("RSA Public Key"); + + /** + * Here our base object is "String", but we use the annotation for datatype to clarify + * that the real XACML data type is http://www.w3.org/2001/XMLSchema#time. The parser will + * use the data type factory to convert the "String" to a "ISO8601Time" Java object. + */ + @XACMLSubject(attributeId="urn:oasis:names:tc:xacml:1.0:subject:request-time", datatype="http://www.w3.org/2001/XMLSchema#time") + String requestTime = new String("13:20:00-05:00"); + + @XACMLSubject(attributeId="urn:oasis:names:tc:xacml:1.0:subject:session-start-time") + ISO8601DateTime sessionStart = new ISO8601DateTime(TimeZone.getDefault().getID(), 2014, 1, 1, 10, 0, 0, 0); + + @XACMLSubject(attributeId="urn:oasis:names:tc:xacml:3.0:subject:authn-locality:ip-address") + IPAddress ip = new IPv4Address(new short[] {123, 134, 156, 255 }, null, null); + + @XACMLSubject(attributeId="urn:oasis:names:tc:xacml:3.0:subject:authn-locality:dns-name") + String dnsName = "localhost"; + + @XACMLAction() + String action; + + @XACMLAction(attributeId="urn:oasis:names:tc:xacml:1.0:action:implied-action") + long impliedAction; + + @XACMLResource() + String resource; + + @XACMLEnvironment() + Date today; + + @XACMLEnvironment() + Calendar yesterday; + + /** + * This field demonstrates how the parser can detect collections and build a bag of values. + */ + @XACMLAttribute(attributeId="foo:bar:attribute") + Collection fooBar = Arrays.asList(2.5, 3.5); + + /** + * The XACMLAttribute annotation allows one to specify all the + */ + @XACMLAttribute(category="foo:bar:category", attributeId="foo:bar:attribute2") + double fooBar2 = 3.999; + + /** + * This field demonstrates how the parser can detect arrays and build a bag of values. + */ + @XACMLAttribute(category="foo:bar:category", attributeId="foo:bar:attribute:many") + URI[] fooBarMany = new URI[] {URI.create("file://opt/app/test"), URI.create("https://localhost:8443/")}; + + }; + + @XACMLRequest( + Defaults="http://www.w3.org/TR/1999/Rec-xpath-19991116", + multiRequest=@XACMLMultiRequest(values={ + @XACMLRequestReference(values={"subject1", "action", "resource"}), + @XACMLRequestReference(values={"subject2", "action", "resource"})}) + ) + public class MyMultiRequestAttributes { + + @XACMLSubject(id="subject1") + String userID1 = "John"; + + @XACMLSubject(id="subject2") + String userID2 = "Ringo"; + + @XACMLAction(id="action") + String action = "access"; + + @XACMLResource(id="resource") + String resource = "www.mywebsite.com"; + } + + public TestAnnotation(String[] args) throws MalformedURLException, ParseException, HelpException { + super(args); + } + + @Override + public void run() throws IOException, FactoryException { + // + // We are not going to iterate any existing request files. So we will override + // any TestBase code that assumes there are request files present. + // + // + // Configure ourselves + // + this.configure(); + // + // Cycle through creating a few objects + // + this.num = 0; + this.doRequest(new MyRequestAttributes("John", "access", "www.mywebsite.com")); + this.num++; + this.doRequest(new MyRequestAttributes("Ringo", "access", "www.mywebsite.com")); + this.num++; + this.doRequest(new MyMultiRequestAttributes()); + this.num++; + } + + private void doRequest(Object info) { + try { + Response response = this.callPDP(RequestParser.parseRequest(info)); + Path resultFile; + if (this.output != null) { + resultFile = Paths.get(this.output.toString(), "Response." + String.format("%03d", this.num) + ".json"); + } else { + resultFile = Paths.get(this.directory, "results", "Response." + String.format("%03d", this.num) + ".json"); + } + // + // Write the response to the result file + // + logger.info("Response is: " + response.toString()); + if (resultFile != null) { + Files.write(resultFile, response.toString().getBytes()); + } + } catch (IllegalArgumentException | IllegalAccessException | DataTypeException | IOException e) { + logger.error(e); + e.printStackTrace(); + } + } + + public static void main(String[] args) { + try { + new TestAnnotation(args).run(); + } catch (ParseException | IOException | FactoryException e) { + logger.error(e); + } catch (HelpException e) { + // + // ignore this, its thrown just to exit the application + // after dumping help to stdout. + // + } + } +} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/conformance/Conformance.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/conformance/Conformance.java new file mode 100644 index 000000000..ffd867977 --- /dev/null +++ b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/conformance/Conformance.java @@ -0,0 +1,634 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-TEST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.conformance; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.PrintWriter; +import java.net.URI; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; + +import com.att.research.xacml.api.Advice; +import com.att.research.xacml.api.Attribute; +import com.att.research.xacml.api.AttributeAssignment; +import com.att.research.xacml.api.AttributeCategory; +import com.att.research.xacml.api.AttributeValue; +import com.att.research.xacml.api.IdReference; +import com.att.research.xacml.api.Obligation; +import com.att.research.xacml.api.Response; +import com.att.research.xacml.api.Result; + +/** + * Conformance is an application that runs a ConformanceTestSet and dumps results comparing the actual and + * expected results. + * + * TO RUN in Eclipse: + * This is run as a Java Application. + * You must first create a Run/Debug Configuration: + * Under the Argument tab, in Program Arguments you must set the -i or --input command line argument. + * You should also direct the output to a file using -o or --output. (default is Console) + * See the init() method in this file for other useful arguments. + * Example for a Windows machine: + * -i testsets/conformance/xacml3.0-ct-v.0.4 + * -o \Users\yourLogin\Downloads\conformance.txt + * You must also set the VM arguments: + * -Dxacml.properties=testsets/conformance/xacml.properties . + * -Dlog4j.configuration=.\logging.properties + * + * @version $Revision: 1.2 $ + */ +public class Conformance { + private ConformanceScopeResolver scopeResolver; + private ConformanceTestEngine testEngine; + private ConformanceTestSet testSet = new ConformanceTestSet(); + private File outputFile; + private PrintWriter outputFileWriter; + + private List testNamesToRun = new ArrayList(); + + private boolean verbose; + private boolean failuresOnly; + private boolean strict; + private boolean stopOnFirstError; + + private int testsRun; + private int decisionsMatch; + private int statusCodesMatch; + private int attributesMatch; + private int policyIdsMatch; + private int policySetIdsMatch; + private int associatedAdviceMatch; + private int obligationsMatch; + private int unknownFunctions; + + + + + protected synchronized ConformanceScopeResolver getScopeResolver() { + if (this.scopeResolver == null) { + this.scopeResolver = new ConformanceScopeResolver(); + + /* + * TODO: + * Add the known scopes for the 2.0 conformance test. This could be made more general by allowing loading + * from a properties file eventually. + */ + try { + URI ID_SCOPE_ROOT = new URI("urn:root"); + URI ID_SCOPE_CHILD1 = new URI("urn:root:child1"); + URI ID_SCOPE_CHILD2 = new URI("urn:root:child2"); + URI ID_SCOPE_C1D1 = new URI("urn:root:child1:descendant1"); + URI ID_SCOPE_C1D2 = new URI("urn:root:child1:descendant2"); + URI ID_SCOPE_C2D1 = new URI("urn:root:child2:descendant1"); + URI ID_SCOPE_C2D2 = new URI("urn:root:child2:descendant2"); + + this.scopeResolver.add(ID_SCOPE_ROOT, ID_SCOPE_CHILD1); + this.scopeResolver.add(ID_SCOPE_CHILD1, ID_SCOPE_C1D1); + this.scopeResolver.add(ID_SCOPE_CHILD1, ID_SCOPE_C1D2); + this.scopeResolver.add(ID_SCOPE_ROOT, ID_SCOPE_CHILD2); + this.scopeResolver.add(ID_SCOPE_CHILD2, ID_SCOPE_C2D1); + this.scopeResolver.add(ID_SCOPE_CHILD2, ID_SCOPE_C2D2); + } catch (Exception ex) { + ex.printStackTrace(System.err); + } + + } + return this.scopeResolver; + } + + private void close() throws IOException { + if (this.outputFileWriter != null) { + this.outputFileWriter.close(); + } + } + + private boolean init(String[] args) { + boolean lenientRequests = true; + boolean lenientPolicies = false; + // default is to not run any non-first-time iterations + int iterations = -1; + String testSetDirectoryNames = ""; + for (int i = 0 ; i < args.length ; ) { + + if (args[i].equals("-h") || args[i].equals("--help") || args[i].equals("-help")) { + printHelp(); + return false; + } + + + // where the XML Request/Response files are located + if (args[i].equals("-i") || args[i].equals("--input")) { + i++; + while (i < args.length && !args[i].startsWith("-")) { + testSetDirectoryNames += " " + args[i]; + try { + testSet.addConformanceTestSet(ConformanceTestSet.loadDirectory(new File(args[i]))); + } catch (Exception ex) { + ex.printStackTrace(System.err); + return false; + } + i++; + } + + // File path name where output will be put - default is stdout == Console + } else if (args[i].equals("-o") || args[i].equals("--output")) { + if (i+1 < args.length) { + this.outputFile = new File(args[i+1]); + i += 2; + } else { + System.err.println("Missing argument to " + args[i] + " command line option"); + return false; + } + // A list of specific test names (e.g.: -t IIA001 IIA007 IIIE301) - default is to run all tests + } else if (args[i].equals("-t") || args[i].equals("--tests")) { + i++; + while (i < args.length && !args[i].startsWith("-")) { + testNamesToRun.add(args[i]); + i++; + } + if (testNamesToRun.size() == 0) { + System.err.println("Missing test names after -t or --tests argument"); + return false; + } + // Include full details in the response, both the expected reqsponse (from file) and the actual response + } else if (args[i].equals("-v") || args[i].equals("--verbose")) { + this.verbose = true; + i++; + // Report only failures (success is silent) + } else if (args[i].equals("-f") || args[i].equals("--failures")) { + this.failuresOnly = true; + i++; + // When set, the XML must not contain extra attibutes/elements. Default is "lenient" where unexpected entries are ignored + } else if (args[i].equals("-s") || args[i].equals("--strict")) { + this.strict = true; + i++; + // (self explanatory) + } else if (args[i].equals("--stop-on-error")) { + this.stopOnFirstError = true; + i++; + } else if (args[i].equals("--lenient")) { + lenientPolicies = true; + lenientRequests = true; + i++; + } else if (args[i].equals("--lenient-policies")) { + lenientPolicies = true; + i++; + } else if (args[i].equals("--lenient-requests")) { + lenientRequests = true; + i++; + } else if (args[i].equals("--strict-policies")) { + lenientPolicies = false; + i++; + } else if (args[i].equals("--strict-requests")) { + lenientRequests = false; + i++; + } else if (args[i].equals("--iterations")) { + // this is a count of how many ADDITIONAL times the decide() should be called. + // The first time decide() is called it takes a long time to set up, + // so to get an accurate number for how fast a single Request is handled we need to ignore the time for the first run + // and timings for 1 or more non-first-time calls to decide(). + if (i+1 < args.length) { + try { + iterations = Integer.parseInt(args[i+1]); + i += 2; + } catch (NumberFormatException ex) { + System.err.println("Invalid iteration count '" + args[i+1] + "'"); + return false; + } + } else { + System.err.println("Missing argument to " + args[i] + " command line option"); + return false; + } + if (iterations < 1) { + System.err.println("Cannot use --iterations " + iterations + ". Must use an integer greater than 0"); + return false; + } + } else { + System.err.println("Unknown command line option " + args[i]); + return false; + } + } + + this.testEngine = new ConformanceTestEngine(this.getScopeResolver(), lenientRequests, lenientPolicies, iterations); + + if (testSetDirectoryNames.length() == 0) { + System.err.println("No test set directory given (need -i or --iniput command line option)"); + return false; + } + if (testSet.getListConformanceTests().size() == 0) { + System.err.println("No tests in given directories: " + testSetDirectoryNames); + } + + if (testNamesToRun.size() > 0) { + String s = ""; + for (String name : testNamesToRun) { + s += ", " + name; + } + System.out.println("Tests limited to: " + s.substring(1)); + } + + if (this.outputFile == null) { + this.outputFileWriter = new PrintWriter(System.out); + } else { + try { + this.outputFileWriter = new PrintWriter(new FileOutputStream(this.outputFile)); + } catch (IOException ex) { + System.err.println("Cannot open " + this.outputFile.getAbsolutePath() + " for writing."); + return false; + } + } + + return true; + } + + private void printHelp() { + System.out.println("usage: Conformance --input OPTIONS"); + System.out.println(""); + System.out.println(" -f, --failures Only include failed tests in the output. \n"+ + " Default is to include all test's results in the output file."); + System.out.println(""); + System.out.println(" -h, --help Prints help."); + + System.out.println(""); + System.out.println(" -i, --input Directory containing the XML Request/Response files. \n"+ + " This may be multiple space-separated directory paths. REQUIRED"); + + System.out.println(""); + System.out.println(" --iterations The number of times to run through the set of tests in the input directory."); + + System.out.println(""); + System.out.println(" --lenient Allow both Requests and Policies to have unexpected elements, no data in , etc. \n"+ + " Default is to not allow anything that is not explicitly listed in the XACML spec."); + + System.out.println(""); + System.out.println(" --lenient-policies Allow Policies to have unexpected elements, no data in , etc. \n" + + " Default is to not allow anything that is not explicitly listed in the XACML spec."); + + System.out.println(""); + System.out.println(" --lenient-requests Allow Requests to have unexpected elements, no data in , etc. \n" + + " Default is to not allow anything that is not explicitly listed in the XACML spec."); + + System.out.println(""); + System.out.println(" -o, --output Directory where the output results file will be put."); + + System.out.println(""); + System.out.println(" -s, --strict Check both the Decision and all other parts of the Response (Attributes, Obligations and Advice). \n "+ + " Default is to check just the Decision."); + + System.out.println(""); + System.out.println(" --stop-on-error Stop running conformance tests the first time one fails. Default is to continue through all tests."); + + System.out.println(""); + System.out.println(" --strict-policies Require Policies to have no unexpected elements, data in , etc. \n" + + " This is the default, but can be used to override Policies when option --lenient is used."); + + System.out.println(""); + System.out.println(" --strict-requests Require Requests to have no unexpected elements, data in , etc. \n" + + " This is the default, but can be used to override Requests when option --lenient is used."); + + System.out.println(""); + System.out.println(" -t, --tests A space-separated list of specific tests to be run. \n" + + " These are just the names of the tests as in 'IIA001 IIC178'. \n" + + " Default is to run all tests in the input directory."); + + System.out.println(""); + System.out.println(" -v, --verbose The entire expected and actual Response objects in the output. \n"+ + " Default is just a summary line."); + + } + + private boolean failed(ConformanceTestResult conformanceTestResult) { + ResponseMatchResult responseMatchResult = conformanceTestResult.getResponseMatchResult(); + if (responseMatchResult == null) { + return true; + } + if (!responseMatchResult.decisionsMatch() || !responseMatchResult.statusCodesMatch()) { + return true; + } else if (this.strict) { + if (!responseMatchResult.associatedAdviceMatches() || + !responseMatchResult.attributesMatch() || + !responseMatchResult.obligationsMatch() || + !responseMatchResult.policyIdentifiersMatch() || + !responseMatchResult.policySetIdentifiersMatch() + ) { + return true; + } + } + return false; + } + + private void dump(AttributeAssignment attributeAssignment) { + this.outputFileWriter.println("\t\t\t\tAttributeAssignment:"); + if (attributeAssignment.getCategory() != null) { + this.outputFileWriter.println("\t\t\t\t\tCategory: " + attributeAssignment.getCategory().stringValue()); + } + if (attributeAssignment.getAttributeId() != null) { + this.outputFileWriter.println("\t\t\t\t\tAttributeId: " + attributeAssignment.getAttributeId().stringValue()); + } + if (attributeAssignment.getDataTypeId() != null) { + this.outputFileWriter.println("\t\t\t\t\tDataType: " + attributeAssignment.getDataTypeId().stringValue()); + } + if (attributeAssignment.getIssuer() != null) { + this.outputFileWriter.println("\t\t\t\t\tIssuer: " + attributeAssignment.getIssuer()); + } + if (attributeAssignment.getAttributeValue() != null && attributeAssignment.getAttributeValue().getValue() != null) { + this.outputFileWriter.println("\t\t\t\t\tValue: " + attributeAssignment.getAttributeValue().getValue().toString()); + } + } + + private void dump(Attribute attribute) { + this.outputFileWriter.println("\t\t\t\t\tAttribute: " + (attribute.getAttributeId() == null ? "" : attribute.getAttributeId().stringValue())); + if (attribute.getIssuer() != null) { + this.outputFileWriter.println("\t\t\t\t\t\tIssuer: " + attribute.getIssuer()); + } + Iterator> iterAttributeValues = attribute.getValues().iterator(); + if (iterAttributeValues.hasNext()) { + this.outputFileWriter.println("\t\t\t\t\t\tValues: "); + while (iterAttributeValues.hasNext()) { + this.outputFileWriter.print("\t\t\t\t\t\t\t"); + AttributeValue attributeValue = iterAttributeValues.next(); + if (attributeValue.getDataTypeId() != null) { + this.outputFileWriter.print("DataType: " + attributeValue.getDataTypeId().stringValue() + " "); + } + if (attributeValue.getValue() != null) { + this.outputFileWriter.print("Value: " + attributeValue.getValue().toString()); + } + this.outputFileWriter.println(); + } + } + } + + private void dump(AttributeCategory attributeCategory) { + this.outputFileWriter.println("\t\t\tAttributeCategory: " + (attributeCategory.getCategory() == null ? "" : attributeCategory.getCategory().stringValue())); + Collection listAttributes = attributeCategory.getAttributes(); + if (listAttributes.size() > 0) { + this.outputFileWriter.println("\t\t\t\tAttributes:"); + for (Attribute attribute: listAttributes) { + this.dump(attribute); + } + } + } + + private void dump(Result result) { + this.outputFileWriter.println("\t\t======== Result =========="); + this.outputFileWriter.println("\t\tDecision: " + (result.getDecision() == null ? "null" : result.getDecision().name())); + if (result.getStatus() == null) { + this.outputFileWriter.println("\t\tStatus: null"); + } else { + this.outputFileWriter.println("\t\tStatus:"); + if (result.getStatus().getStatusCode() != null) { + this.outputFileWriter.println("\t\t\tStatusCode: " + result.getStatus().getStatusCode().toString()); + } + if (result.getStatus().getStatusMessage() != null) { + this.outputFileWriter.println("\t\t\tStatusMessage: " + result.getStatus().getStatusMessage()); + } + if (result.getStatus().getStatusDetail() != null) { + this.outputFileWriter.println("\t\t\tStatusDetail: " + result.getStatus().getStatusDetail().toString()); + } + } + Collection listAdvice = result.getAssociatedAdvice(); + if (listAdvice.size() > 0) { + this.outputFileWriter.println("\t\tAdvice:"); + for (Advice advice : listAdvice) { + if (advice.getId() != null) { + this.outputFileWriter.println("\t\t\tId: " + advice.getId().stringValue()); + } + Collection attributeAssignments = advice.getAttributeAssignments(); + if (attributeAssignments.size() > 0) { + this.outputFileWriter.println("\t\t\tAttributeAssignments:"); + for (AttributeAssignment attributeAssignment: attributeAssignments) { + this.dump(attributeAssignment); + } + } + } + } + Collection listObligations = result.getObligations(); + if (listObligations.size() > 0) { + for (Obligation obligation: listObligations) { + if (obligation.getId() != null) { + this.outputFileWriter.println("\t\t\tId: " + obligation.getId().stringValue()); + } + Collection attributeAssignments = obligation.getAttributeAssignments(); + if (attributeAssignments.size() > 0) { + this.outputFileWriter.println("\t\t\tAttributeAssignments:"); + for (AttributeAssignment attributeAssignment : attributeAssignments) { + this.dump(attributeAssignment); + } + } + } + } + Collection listAttributeCategories = result.getAttributes(); + if (listAttributeCategories.size() > 0) { + this.outputFileWriter.println("\t\tAttributes:"); + for (AttributeCategory attributeCategory : listAttributeCategories) { + this.dump(attributeCategory); + } + } + Collection listIdReferences; + if ((listIdReferences = result.getPolicyIdentifiers()).size() > 0) { + this.outputFileWriter.println("\t\tPolicyIds:"); + for (IdReference idReference : listIdReferences) { + this.outputFileWriter.println("\t\t\t" + idReference.toString()); + } + } + if ((listIdReferences = result.getPolicySetIdentifiers()).size() > 0) { + this.outputFileWriter.println("\t\tPolicySetIds:"); + for (IdReference idReference : listIdReferences) { + this.outputFileWriter.println("\t\t\t" + idReference.toString()); + } + } + } + + private void dump(String label, Response response) { + this.outputFileWriter.println("\t========== " + label + "=========="); + if (response == null) { + this.outputFileWriter.println("null"); + return; + } + + for (Result result : response.getResults()) { + this.dump(result); + } + } + + private void dump(ConformanceTestResult conformanceTestResult) { + + ResponseMatchResult responseMatchResult = conformanceTestResult.getResponseMatchResult(); + if (this.verbose) { + this.outputFileWriter.println("========== Test " + conformanceTestResult.getConformanceTest().getTestName() + " =========="); + this.dump("Expected Response", conformanceTestResult.getExpectedResponse()); + this.dump("Actual Response", conformanceTestResult.getActualResponse()); + if (responseMatchResult != null) { + this.outputFileWriter.println("\t========== Matching =========="); + this.outputFileWriter.println("\tDecisions Match? " + responseMatchResult.decisionsMatch()); + this.outputFileWriter.println("\tStatus Codes Match? " + responseMatchResult.statusCodesMatch()); + this.outputFileWriter.println("\tAttributes Match? " + responseMatchResult.attributesMatch()); + this.outputFileWriter.println("\tPolicyIds Match? " + responseMatchResult.policyIdentifiersMatch()); + this.outputFileWriter.println("\tPolicySetIds Match? " + responseMatchResult.policySetIdentifiersMatch()); + this.outputFileWriter.println("\tAssociated Advice Match? " + responseMatchResult.associatedAdviceMatches()); + this.outputFileWriter.println("\tObligations Match? " + responseMatchResult.obligationsMatch()); + this.outputFileWriter.println("========== End =========="); + } + } else { + String testName = conformanceTestResult.getConformanceTest().getTestName(); + if (responseMatchResult != null) { + Iterator iterResultMatches = responseMatchResult.getResultMatchResults(); + if (iterResultMatches == null || !iterResultMatches.hasNext()) { + this.outputFileWriter.println(testName); + } else { + while (iterResultMatches.hasNext()) { + ResultMatchResult resultMatchResult = iterResultMatches.next(); + this.outputFileWriter.printf("%s,%s,%s,%s,%s,%s,%s,%s,%d,%d\n", + testName, + resultMatchResult.decisionsMatch(), + resultMatchResult.statusCodesMatch(), + resultMatchResult.attributesMatch(), + resultMatchResult.policyIdentifiersMatch(), + resultMatchResult.policySetIdentifiersMatch(), + resultMatchResult.associatedAdviceMatches(), + resultMatchResult.obligationsMatch(), + conformanceTestResult.getFirstCallTime(), + conformanceTestResult.getAverageTotalLoopTime() + ); + } + } + } + } + this.outputFileWriter.flush(); + } + + private boolean run(ConformanceTest conformanceTest) throws Exception { + this.testsRun++; + ConformanceTestResult conformanceTestResult = this.testEngine.run(conformanceTest); + boolean bFailed = true; + if (conformanceTestResult != null) { + ResponseMatchResult responseMatchResult = conformanceTestResult.getResponseMatchResult(); + if (responseMatchResult != null) { + if (responseMatchResult.decisionsMatch()) { + this.decisionsMatch++; + this.statusCodesMatch += (responseMatchResult.statusCodesMatch() ? 1 : 0); + this.attributesMatch += (responseMatchResult.attributesMatch() ? 1 : 0); + this.policyIdsMatch += (responseMatchResult.policyIdentifiersMatch() ? 1 : 0); + this.policySetIdsMatch += (responseMatchResult.policySetIdentifiersMatch() ? 1 : 0); + this.associatedAdviceMatch += (responseMatchResult.associatedAdviceMatches() ? 1 : 0); + this.obligationsMatch += (responseMatchResult.obligationsMatch() ? 1 : 0); + } + this.unknownFunctions += (responseMatchResult.unknownFunction() ? 1 : 0); + bFailed = this.failed(conformanceTestResult); + if (bFailed || !this.failuresOnly) { + this.dump(conformanceTestResult); + } + } else if (conformanceTestResult.getError() != null) { + this.outputFileWriter.println(conformanceTestResult.getError()); + } + } + return (!bFailed || !this.stopOnFirstError); + } + + private void run() throws Exception { + long tStart = System.currentTimeMillis(); + + if (!this.verbose) { + this.outputFileWriter.println("Test,Decision,Status,Attributes,PolicyIds,PolicySetIds,Advice,Obligations"); + } + Iterator iterConformanceTests = this.testSet.getConformanceTests(); + boolean bContinue = true; + while (bContinue && iterConformanceTests.hasNext()) { +// bContinue = this.run(iterConformanceTests.next()); + ConformanceTest test = iterConformanceTests.next(); + if (testNamesToRun.size() > 0) { + if ( ! testNamesToRun.contains(test.getTestName())) { + continue; + } + } + bContinue = this.run(test); + } + + long tElapsed = System.currentTimeMillis() - tStart; + + if (this.verbose) { + this.outputFileWriter.println("Tests run = " + this.testsRun); + this.outputFileWriter.println("Decisions match = " + this.decisionsMatch); + this.outputFileWriter.println("Status Codes match = " + this.statusCodesMatch); + this.outputFileWriter.println("Attributes match = " + this.attributesMatch); + this.outputFileWriter.println("PolicyIds match = " + this.policyIdsMatch); + this.outputFileWriter.println("PolicySetIds match = " + this.policySetIdsMatch); + this.outputFileWriter.println("Associated Advice match = " + this.associatedAdviceMatch); + this.outputFileWriter.println("Obligations match = " + this.obligationsMatch); + this.outputFileWriter.println("Unknown functions = " + this.unknownFunctions); + } else { + this.outputFileWriter.printf("Total (%d),%d,%d,%d,%d,%d,%d,%d,%d\n", + this.testsRun, + this.decisionsMatch, + this.statusCodesMatch, + this.attributesMatch, + this.policyIdsMatch, + this.policySetIdsMatch, + this.associatedAdviceMatch, + this.obligationsMatch, + this.unknownFunctions); + } + + if (tElapsed > 0) { + long tHours = tElapsed / (60*60*1000); + tElapsed = tElapsed - tHours * 60 * 60 *1000; + long tMinutes = tElapsed / (60*1000); + tElapsed = tElapsed - tMinutes * 60 * 1000; + long tSeconds = tElapsed / 1000; + tElapsed = tElapsed - tSeconds * 1000; + + this.outputFileWriter.printf("Elapsed time = %02d:%02d:%02d.%03d\n", tHours, tMinutes, tSeconds, tElapsed); + this.outputFileWriter.printf("First decide time in nano-seconds %d\n", this.testEngine.getFirstDecideTime()); + this.outputFileWriter.printf("Total Multiple decide time in nano-seconds %d\n", this.testEngine.getDecideTimeMultiple()); + + this.outputFileWriter.printf("\nAverage First decide time in nano-seconds %d\n", this.testEngine.getAvgFirstDecideTime()); + this.outputFileWriter.printf("Average decide time after first call in nano-seconds %d\n", this.testEngine.getAvgDecideTimeMultiple()); + } + } + + public Conformance() { + } + + public static void main(String[] args) { + Conformance conformance = new Conformance(); + try { + if (conformance.init(args)) { + conformance.run(); + } + + } catch (Exception ex) { + ex.printStackTrace(System.err); + System.exit(1); + } finally { + try { + conformance.close(); + } catch (IOException ex) { + ex.printStackTrace(System.err); + } + } + System.exit(0); + } + +} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/conformance/ConformancePIPEngine.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/conformance/ConformancePIPEngine.java new file mode 100644 index 000000000..2a3950189 --- /dev/null +++ b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/conformance/ConformancePIPEngine.java @@ -0,0 +1,242 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-TEST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.conformance; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStreamReader; +import java.text.ParseException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import com.att.research.xacml.api.Attribute; +import com.att.research.xacml.api.AttributeValue; +import com.att.research.xacml.api.DataType; +import com.att.research.xacml.api.DataTypeException; +import com.att.research.xacml.api.DataTypeFactory; +import com.att.research.xacml.api.Identifier; +import com.att.research.xacml.api.pip.PIPException; +import com.att.research.xacml.api.pip.PIPFinder; +import com.att.research.xacml.api.pip.PIPRequest; +import com.att.research.xacml.api.pip.PIPResponse; +import com.att.research.xacml.std.IdentifierImpl; +import com.att.research.xacml.std.StdMutableAttribute; +import com.att.research.xacml.std.pip.StdPIPResponse; +import com.att.research.xacml.std.pip.engines.ConfigurableEngine; +import com.att.research.xacml.util.FactoryException; + +/** + * ConformancePIPEngine implements the {@link com.att.research.xacml.api.pip.PIPFinder} interface to find attributes + * loaded from a text file containing the following fields: + * category-id,attribute-id,datatype-id,issuer,value + * + * @version $Revision: 1.1 $ + */ +public class ConformancePIPEngine implements ConfigurableEngine { + public static final String PROP_DESCRIPTION = ".description"; + public static final String PROP_FILE = ".file"; + + private static final Log logger = LogFactory.getLog(ConformancePIPEngine.class); + + private String name; + private String description; + private Map cache = new HashMap(); + private List listAttributes = new ArrayList(); + private DataTypeFactory dataTypeFactory; + + public ConformancePIPEngine() { + + } + + protected DataTypeFactory getDataTypeFactory() throws FactoryException { + if (this.dataTypeFactory == null) { + this.dataTypeFactory = DataTypeFactory.newInstance(); + } + return this.dataTypeFactory; + } + + protected static String generateKey(PIPRequest pipRequest) { + StringBuilder stringBuilder = new StringBuilder(pipRequest.getCategory().toString()); + stringBuilder.append('+'); + stringBuilder.append(pipRequest.getAttributeId().toString()); + stringBuilder.append('+'); + stringBuilder.append(pipRequest.getDataTypeId().toString()); + String issuer = pipRequest.getIssuer(); + if (issuer != null) { + stringBuilder.append('+'); + stringBuilder.append(issuer); + } + return stringBuilder.toString(); + } + + protected void store(String[] fields) throws FactoryException { + DataTypeFactory thisDataTypeFactory = this.getDataTypeFactory(); + Identifier identifierCategory = new IdentifierImpl(fields[0]); + Identifier identifierAttribute = new IdentifierImpl(fields[1]); + Identifier identifierDataType = new IdentifierImpl(fields[2]); + String issuer = (fields.length == 5 ? fields[3] : null); + String value = fields[fields.length - 1]; + + DataType dataType = thisDataTypeFactory.getDataType(identifierDataType); + if (dataType == null) { + logger.error("Unknown data type " + identifierDataType.stringValue()); + return; + } + + AttributeValue attributeValue = null; + try { + attributeValue = dataType.createAttributeValue(value); + } catch (DataTypeException ex) { + throw new FactoryException("DataTypeException creating AttributeValue", ex); + } + Attribute attribute = new StdMutableAttribute(identifierCategory, identifierAttribute, attributeValue, issuer, false); + this.listAttributes.add(attribute); + } + + public void loadAttributes(File fileAttributes) throws IOException, ParseException, FactoryException { + if (fileAttributes != null) { + if (!fileAttributes.exists()) { + throw new FileNotFoundException("Attributes file " + fileAttributes.getAbsolutePath() + " not found."); + } else if (!fileAttributes.canRead()) { + throw new IOException("Attributes file " + fileAttributes.getAbsolutePath() + " is not readable."); + } + + BufferedReader bufferedReader = null; + try { + bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(fileAttributes))); + String line; + while ((line = bufferedReader.readLine()) != null) { + if (line.length() > 0) { + String[] fields = line.split("[|]",-1); + if (fields.length < 4) { + logger.warn("Not enough fields in record \"" + line + "\""); + continue; + } + this.store(fields); + + } + } + } finally { + if (bufferedReader != null) { + bufferedReader.close(); + } + } + } + } + + protected Attribute findAttribute(PIPRequest pipRequest) { + Attribute attributeResult = null; + Iterator iterAttributes = this.listAttributes.iterator(); + while ((attributeResult == null) && iterAttributes.hasNext()) { + Attribute attributeTest = iterAttributes.next(); + if (pipRequest.getCategory().equals(attributeTest.getCategory()) && + pipRequest.getAttributeId().equals(attributeTest.getAttributeId()) && + (pipRequest.getIssuer() == null || pipRequest.getIssuer().equals(attributeTest.getIssuer()))) { + attributeResult = attributeTest; + } + } + return attributeResult; + } + + @Override + public PIPResponse getAttributes(PIPRequest pipRequest, PIPFinder pipFinder) throws PIPException { + String pipRequestKey = generateKey(pipRequest); + PIPResponse pipResponse = this.cache.get(pipRequestKey); + if (pipResponse != null) { + return pipResponse; + } + Attribute attributeMatch = this.findAttribute(pipRequest); + if (attributeMatch == null) { + return StdPIPResponse.PIP_RESPONSE_EMPTY; + } + /* + * Iterate through the values and only return the ones that match the requested data type + */ + List> matchingValues = new ArrayList>(); + Iterator> iterAttributeValues = attributeMatch.getValues().iterator(); + while (iterAttributeValues.hasNext()) { + AttributeValue attributeValue = iterAttributeValues.next(); + if (pipRequest.getDataTypeId().equals(attributeValue.getDataTypeId())) { + matchingValues.add(attributeValue); + } + } + if (matchingValues.size() > 0) { + Attribute attributeResponse = new StdMutableAttribute(attributeMatch.getCategory(), attributeMatch.getAttributeId(), matchingValues, attributeMatch.getIssuer(), false); + pipResponse = new StdPIPResponse(attributeResponse); + this.cache.put(pipRequestKey, pipResponse); + } + return pipResponse; + } + + @Override + public String getName() { + return this.name; + } + + @Override + public String getDescription() { + return this.description; + } + + @Override + public void configure(String id, Properties properties) throws PIPException { + this.name = id; + this.description = properties.getProperty(id + PROP_DESCRIPTION); + if (this.description == null) { + this.description = "PIPEngine for the Conformance tests that loads attributes from a CSV file"; + } + String pipFile = properties.getProperty(id + PROP_FILE); + if (pipFile != null) { + try { + this.loadAttributes(new File(pipFile)); + } catch (Exception ex) { + logger.error("Exception loading PIP file " + pipFile, ex); + throw new PIPException("Exception loading PIP file " + pipFile, ex); + } + } + } + + @Override + public Collection attributesRequired() { + return Collections.emptyList(); + } + + @Override + public Collection attributesProvided() { + // + // We could return everything in our list + // + return Collections.emptyList(); + } + +} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/conformance/ConformanceRepository.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/conformance/ConformanceRepository.java new file mode 100644 index 000000000..4ef3416ad --- /dev/null +++ b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/conformance/ConformanceRepository.java @@ -0,0 +1,127 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-TEST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.conformance; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Properties; + +import com.att.research.xacml.util.StringUtils; +import com.att.research.xacml.util.XACMLProperties; +import com.att.research.xacmlatt.pdp.std.StdPolicyFinderFactory; + +/** + * ConformanceRepository represents one or more policies for a single policy test, which will include one or more root policies, and + * zero or more referenced policies. + * + * @version $Revision$ + */ +public class ConformanceRepository { + private List rootPolicies = new ArrayList(); + private List referencedPolicies = new ArrayList(); + + private void setXACMLProperty(String propertyName, List listFiles) { + Iterator iterFiles = listFiles.iterator(); + StringBuilder stringBuilderIdList = new StringBuilder(); + while (iterFiles.hasNext()) { + File file = iterFiles.next(); + if (stringBuilderIdList.length() > 0) { + stringBuilderIdList.append(','); + } + stringBuilderIdList.append(file.getName()); + + XACMLProperties.setProperty(file.getName() + StdPolicyFinderFactory.PROP_FILE, file.getAbsolutePath()); + } + XACMLProperties.setProperty(propertyName, stringBuilderIdList.toString()); + } + + public ConformanceRepository() { + } + + public void setXACMLProperties() { + if (this.rootPolicies.size() > 0) { + this.setXACMLProperty(XACMLProperties.PROP_ROOTPOLICIES, this.rootPolicies); + } + if (this.referencedPolicies.size() > 0) { + this.setXACMLProperty(XACMLProperties.PROP_REFERENCEDPOLICIES, this.referencedPolicies); + } + } + + private void loadProperty(File fileDir, Properties properties, String propertyName, List listFiles) { + String fileNameList = properties.getProperty(propertyName); + if (fileNameList != null) { + String[] fileNameArray = fileNameList.split("[,]",0); + if (fileNameArray != null && fileNameArray.length > 0) { + for (String fileName : fileNameArray) { + File file = new File(fileDir, fileName); + if (file.exists() && file.canRead()) { + listFiles.add(file); + } + } + } + } + } + + public void load(File fileRepository) throws IOException { + Properties propertiesRepository = new Properties(); + try (InputStream is = new FileInputStream(fileRepository)) { + propertiesRepository.load(is); + } + this.loadProperty(fileRepository.getParentFile(), propertiesRepository, XACMLProperties.PROP_ROOTPOLICIES, this.rootPolicies); + this.loadProperty(fileRepository.getParentFile(), propertiesRepository, XACMLProperties.PROP_REFERENCEDPOLICIES, this.referencedPolicies); + } + + public void addRootPolicy(File filePolicy) { + this.rootPolicies.add(filePolicy); + } + + public boolean hasRootPolicy() { + return (this.rootPolicies.size() > 0); + } + + @Override + public String toString() { + StringBuilder stringBuilder = new StringBuilder("{"); + boolean needComma = false; + + if (this.rootPolicies != null && this.rootPolicies.size() > 0) { + stringBuilder.append("rootPolicies="); + stringBuilder.append(StringUtils.toString(this.rootPolicies.iterator())); + needComma = true; + } + if (this.referencedPolicies != null && this.referencedPolicies.size() > 0) { + if (needComma) { + stringBuilder.append(','); + } + stringBuilder.append("referencedPolicies="); + stringBuilder.append(StringUtils.toString(this.referencedPolicies.iterator())); + needComma = true; + } + stringBuilder.append('}'); + return stringBuilder.toString(); + } + +} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/conformance/ConformanceScopeResolver.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/conformance/ConformanceScopeResolver.java new file mode 100644 index 000000000..5e2b3ed0f --- /dev/null +++ b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/conformance/ConformanceScopeResolver.java @@ -0,0 +1,121 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-TEST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.conformance; + +import java.net.URI; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import com.att.research.xacml.api.Attribute; +import com.att.research.xacml.api.AttributeValue; +import com.att.research.xacml.api.pdp.ScopeQualifier; +import com.att.research.xacml.api.pdp.ScopeResolver; +import com.att.research.xacml.api.pdp.ScopeResolverException; +import com.att.research.xacml.api.pdp.ScopeResolverResult; +import com.att.research.xacml.std.StdMutableAttribute; +import com.att.research.xacml.std.StdScopeResolverResult; +import com.att.research.xacml.std.StdStatus; +import com.att.research.xacml.std.StdStatusCode; +import com.att.research.xacml.std.datatypes.DataTypes; + +/** + * ConformanceScopeResolver implements {@link com.att.research.xacml.pdp.ScopeResolver} for the conformance tests + * using a fixed set of hierarchical resources defined in a map. + * + * @version $Revision$ + */ +public class ConformanceScopeResolver implements ScopeResolver { + private Log logger = LogFactory.getLog(ConformanceScopeResolver.class); + private Map> mapIdentifierToChildren = new HashMap>(); + + public ConformanceScopeResolver() { + } + + public void add(URI identifierRoot, URI identifierChild) { + List listChildrenRoot = this.mapIdentifierToChildren.get(identifierRoot); + if (listChildrenRoot == null) { + listChildrenRoot = new ArrayList(); + this.mapIdentifierToChildren.put(identifierRoot, listChildrenRoot); + } + listChildrenRoot.add(identifierChild); + } + + private void addChildren(Attribute attributeResourceId, URI urnResourceIdValue, boolean bDescendants, List listAttributes) { + List listChildren = this.mapIdentifierToChildren.get(urnResourceIdValue); + if (listChildren != null) { + for (URI uriChild : listChildren) { + AttributeValue attributeValueURI = null; + try { + attributeValueURI = DataTypes.DT_ANYURI.createAttributeValue(uriChild); + if (attributeValueURI != null) { + listAttributes.add(new StdMutableAttribute(attributeResourceId.getCategory(), attributeResourceId.getAttributeId(), attributeValueURI, attributeResourceId.getIssuer(), attributeResourceId.getIncludeInResults())); + } + } catch (Exception ex) { + this.logger.error("Exception converting URI to an AttributeValue"); + } + if (bDescendants) { + this.addChildren(attributeResourceId, uriChild, bDescendants, listAttributes); + } + } + } + } + + private void addChildren(Attribute attributeResourceId, boolean bDescendants, List listAttributes) { + /* + * Iterate over the values that are URNs + */ + Iterator> iterAttributeValueURNs = attributeResourceId.findValues(DataTypes.DT_ANYURI); + if (iterAttributeValueURNs != null) { + while (iterAttributeValueURNs.hasNext()) { + this.addChildren(attributeResourceId, iterAttributeValueURNs.next().getValue(), bDescendants, listAttributes); + } + } + } + + @Override + public ScopeResolverResult resolveScope(Attribute attributeResourceId, ScopeQualifier scopeQualifier) throws ScopeResolverException { + List listAttributes = new ArrayList(); + switch(scopeQualifier) { + case CHILDREN: + listAttributes.add(attributeResourceId); + this.addChildren(attributeResourceId, false, listAttributes); + break; + case DESCENDANTS: + listAttributes.add(attributeResourceId); + this.addChildren(attributeResourceId, true, listAttributes); + break; + case IMMEDIATE: + listAttributes.add(attributeResourceId); + break; + default: + this.logger.error("Unknown ScopeQualifier: " + scopeQualifier.name()); + return new StdScopeResolverResult(new StdStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, "Unknown ScopeQualifier " + scopeQualifier.name())); + } + return new StdScopeResolverResult(listAttributes); + } + +} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/conformance/ConformanceTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/conformance/ConformanceTest.java new file mode 100644 index 000000000..297a9d0d6 --- /dev/null +++ b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/conformance/ConformanceTest.java @@ -0,0 +1,104 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-TEST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.conformance; + +import java.io.File; + +/** + * ConformanceTest represents a collection of XACML files with a root Policy document, optional referenced Policy documents, a Request, and a Response. + * + * @version $Revision: 1.2 $ + */ +public class ConformanceTest { + private String testName; + private File request; + private File response; + private ConformanceRepository repository; + + public ConformanceTest(String name, ConformanceRepository conformanceRepository, File fileRequest, File fileResponse) { + this.testName = name; + this.request = fileRequest; + this.response = fileResponse; + this.repository = conformanceRepository; + } + + public ConformanceTest(String name) { + this.testName = name; + } + + public String getTestName() { + return this.testName; + } + public void setTestName(String s) { + this.testName = s; + } + public ConformanceRepository getRepository() { + if (this.repository == null) { + this.repository = new ConformanceRepository(); + } + return this.repository; + } + public File getRequest() { + return this.request; + } + public void setRequest(File f) { + this.request = f; + } + public File getResponse() { + return this.response; + } + public void setResponse(File f) { + this.response = f; + } + + public boolean isComplete() { + return this.getTestName() != null && this.getRepository() != null && this.getRepository().hasRootPolicy() && this.getRequest() != null && this.getResponse() != null; + } + + @Override + public String toString() { + StringBuilder stringBuilder = new StringBuilder(); + boolean needColon = false; + if (this.getTestName() != null) { + stringBuilder.append(this.getTestName()); + needColon = true; + } + if (this.getRepository() != null) { + + } + if (this.getRequest() != null) { + if (needColon) { + stringBuilder.append(':'); + } + stringBuilder.append(this.getRequest().getName()); + needColon = true; + } + if (this.getResponse() != null) { + if (needColon) { + stringBuilder.append(':'); + } + stringBuilder.append(this.getResponse().getName()); + needColon = true; + } + return stringBuilder.toString(); + } + +} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/conformance/ConformanceTestEngine.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/conformance/ConformanceTestEngine.java new file mode 100644 index 000000000..c24b5473f --- /dev/null +++ b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/conformance/ConformanceTestEngine.java @@ -0,0 +1,219 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-TEST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.conformance; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import com.att.research.xacml.api.Request; +import com.att.research.xacml.api.Response; +import com.att.research.xacml.api.pdp.PDPEngine; +import com.att.research.xacml.api.pdp.PDPEngineFactory; +import com.att.research.xacml.api.pdp.ScopeResolver; +import com.att.research.xacml.std.dom.DOMProperties; +import com.att.research.xacml.std.dom.DOMRequest; +import com.att.research.xacml.std.dom.DOMResponse; +import com.att.research.xacml.util.FactoryException; + +/** + * ConformanceTestEngine handles the creation of the PDPEngine for a ConformanceTest instance. + * + * @version $Revision: 1.2 $ + */ +public class ConformanceTestEngine { + private Log logger = LogFactory.getLog(ConformanceTestEngine.class); + + private PDPEngineFactory pdpEngineFactory; + private ScopeResolver scopeResolver; + private boolean lenientRequests; + private boolean lenientPolicies; + private int iterations = 1; + + // total of all first calls to decide() + private long firstDecideTime; + private int numberOfFirstDecides = 0; + + // total of all non-first-calls to decide() + private long decideTimeMultiple; + + // total of average time each test case uses for a Request + // (sum of : for each test case, average of all non-first-call calls to decide() ) + private long avgDecideTimeMultiple = 0; + + protected PDPEngineFactory getPDPEngineFactory() throws FactoryException { + if (this.pdpEngineFactory == null) { + this.pdpEngineFactory = PDPEngineFactory.newInstance(); + this.pdpEngineFactory.setScopeResolver(this.scopeResolver); + } + return this.pdpEngineFactory; + } + + public ConformanceTestEngine(ScopeResolver scopeResolverIn, boolean lenientRequestsIn, boolean lenientPoliciesIn, int iterationsIn) { + this.scopeResolver = scopeResolverIn; + this.lenientRequests = lenientRequestsIn; + this.lenientPolicies = lenientPoliciesIn; + this.iterations = iterationsIn; + } + + public ConformanceTestResult run(ConformanceTest conformanceTest) { + if (conformanceTest.getRequest() == null || conformanceTest.getResponse() == null || conformanceTest.getRepository() == null) { + logger.error("Incomplete Conformance Test: " + conformanceTest.getTestName()); + } + PDPEngineFactory thisPDPEngineFactory = null; + try { + thisPDPEngineFactory = this.getPDPEngineFactory(); + } catch (FactoryException ex) { + return new ConformanceTestResult(conformanceTest, ex); + } + + ConformanceTestResult conformanceTestResult = new ConformanceTestResult(conformanceTest, iterations); + + /* + * Load the request + */ + Request request = null; + boolean isLenient = DOMProperties.isLenient(); + try { + DOMProperties.setLenient(this.lenientRequests); + try { + request = DOMRequest.load(conformanceTest.getRequest()); + conformanceTestResult.setRequest(request); + } catch (Exception ex) { + logger.error("Exception loading Request file " + conformanceTest.getRequest().getAbsolutePath(), ex); + conformanceTestResult.setError(ex); + return conformanceTestResult; + + } + + /* + * Load the expected response + */ + Response response = null; + try { + response = DOMResponse.load(conformanceTest.getResponse()); + conformanceTestResult.setExpectedResponse(response); + } catch (Exception ex) { + logger.error("Exception loading Response file " + conformanceTest.getResponse().getAbsolutePath(), ex); + conformanceTestResult.setError(ex); + return conformanceTestResult; + } + + /* + * Set up the configuration for the policy finder + */ + conformanceTest.getRepository().setXACMLProperties(); + DOMProperties.setLenient(this.lenientPolicies); + + /* + * Create the engine + */ + PDPEngine pdpEngine = null; + try { + // pdpEngine = thisPDPEngineFactory.newEngine(conformanceTest.getRootPolicy(), conformanceTest.getReferencedPolicies(), pipFinderEngine); + pdpEngine = thisPDPEngineFactory.newEngine(); + } catch (Exception ex) { + logger.error("Exception getting PDP engine instance", ex); + conformanceTestResult.setError(ex); + return conformanceTestResult; + } + if (pdpEngine == null) { + logger.error("Null PDP engine"); + conformanceTestResult.setError(new NullPointerException("Null engine")); + return conformanceTestResult; + } + + /* + * Run the request + */ + long startTime, endTime; + long curDecideTime = this.firstDecideTime; + try { + startTime = System.nanoTime(); + response = pdpEngine.decide(request); + endTime = System.nanoTime(); +//System.out.println(endTime - startTime); + // add to total + this.firstDecideTime += endTime - startTime; + this.numberOfFirstDecides++; + // remember just this test + conformanceTestResult.setFirstCallTime(endTime - startTime); + conformanceTestResult.setActualResponse(response); + } catch (Exception ex) { + logger.error("Exception in decide", ex); + conformanceTestResult.setError(ex); + return conformanceTestResult; + } + if (response == null) { + logger.error("Null Response"); + conformanceTestResult.setError(new NullPointerException("Null Response")); + return conformanceTestResult; + } + + long localLoopTime = 0; + try { + // if user requested non-first-call calls to decide() to get performance info, run them now. + // We can ignore the result since we are only interested in how long they take to process the Request. + for (int i = 0 ; i < this.iterations ; i++) { + startTime = System.nanoTime(); + pdpEngine.decide(request); + endTime = System.nanoTime(); +//System.out.println(endTime - startTime); + // add to the global total for all tests + this.decideTimeMultiple += (endTime - startTime); + // remember just this one test's info + localLoopTime += (endTime - startTime); + } + } catch (Exception ex) { + logger.error("Exception in iterated decide", ex); + return conformanceTestResult; + } + + // add to total average for non-first-call times for all test cases + avgDecideTimeMultiple += (localLoopTime / iterations); +//System.out.println("localLoop="+localLoopTime + " it="+iterations + " avg=" + (localLoopTime / iterations) ); + // remember average time for just this test + conformanceTestResult.setAverageTotalLoopTime(localLoopTime/iterations); + + long elapsedDecideTime = this.firstDecideTime - curDecideTime; + logger.info("Decide Time: " + elapsedDecideTime + "ns"); + + return conformanceTestResult; + } finally { + DOMProperties.setLenient(isLenient); + } + } + + public long getFirstDecideTime() { + return this.firstDecideTime; + } + + public long getDecideTimeMultiple() { + return this.decideTimeMultiple; + } + + + public long getAvgFirstDecideTime() { + return this.firstDecideTime / numberOfFirstDecides; + } + public long getAvgDecideTimeMultiple() { + return this.avgDecideTimeMultiple / numberOfFirstDecides; + } +} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/conformance/ConformanceTestResult.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/conformance/ConformanceTestResult.java new file mode 100644 index 000000000..feef1144d --- /dev/null +++ b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/conformance/ConformanceTestResult.java @@ -0,0 +1,122 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-TEST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.conformance; + +import com.att.research.xacml.api.Request; +import com.att.research.xacml.api.Response; + +/** + * ConformanceTestResult holds all of the objects for a single conformance test run. + * + * @version $Revision: 1.1 $ + */ +public class ConformanceTestResult { + private ConformanceTest conformanceTest; + private Request request; + private Response expectedResponse; + private Response actualResponse; + private ResponseMatchResult responseMatchResult; + private Exception error; + + // performance timings + private long firstCallTime; + private long averageTotalLoopTime; + + // how many non-first-call times the decide() was called + private int iterations; + + public ConformanceTestResult(ConformanceTest conformanceTestIn, int iterations) { + this.conformanceTest = conformanceTestIn; + this.iterations = iterations; + } + + public ConformanceTestResult(ConformanceTest conformanceTestIn, Exception errorIn) { + this.conformanceTest = conformanceTestIn; + this.error = errorIn; + } + + public int getIterations() { + return this.iterations; + } + + public ConformanceTest getConformanceTest() { + return this.conformanceTest; + } + public void setConformanceTest(ConformanceTest conformanceTestIn) { + this.conformanceTest = conformanceTestIn; + } + + public Request getRequest() { + return this.request; + } + public void setRequest(Request requestIn) { + this.request = requestIn; + } + + public Response getExpectedResponse() { + return this.expectedResponse; + } + public void setExpectedResponse(Response response) { + this.expectedResponse = response; + this.responseMatchResult = null; + } + + public Response getActualResponse() { + return this.actualResponse; + } + public void setActualResponse(Response response) { + this.actualResponse = response; + this.responseMatchResult = null; + } + + public ResponseMatchResult getResponseMatchResult() { + if (this.responseMatchResult == null && (this.actualResponse != null && this.expectedResponse != null)) { + this.computeResponseMatchResult(); + } + return this.responseMatchResult; + } + public void computeResponseMatchResult() { + if (this.expectedResponse != null && this.actualResponse != null) { + this.responseMatchResult = ResponseMatchResult.newInstance(this.expectedResponse, this.actualResponse); + } + } + public Exception getError() { + return this.error; + } + public void setError(Exception ex) { + this.error = ex; + } + + public long getFirstCallTime() { + return firstCallTime; + } + public void setFirstCallTime(long t) { + firstCallTime = t; + } + public long getAverageTotalLoopTime(){ + return averageTotalLoopTime; + } + public void setAverageTotalLoopTime(long t) { + averageTotalLoopTime = t; + } + + +} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/conformance/ConformanceTestSet.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/conformance/ConformanceTestSet.java new file mode 100644 index 000000000..b9ae0873f --- /dev/null +++ b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/conformance/ConformanceTestSet.java @@ -0,0 +1,180 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-TEST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.conformance; + +import java.io.File; +import java.io.IOException; +import java.nio.file.FileVisitResult; +import java.nio.file.FileVisitor; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * ConformanceTestSet represents a collection of ConformanceTests ordered by the test name. It has methods for + * scanning a directory to generate an ordered set. + * + * @version $Revision: 1.1 $ + */ +public class ConformanceTestSet { + private static final Log logger = LogFactory.getLog(ConformanceTestSet.class); + private List listConformanceTests = new ArrayList(); + + protected List getListConformanceTests() { + return this.listConformanceTests; + } + + protected ConformanceTestSet() { + + } + + private static String getTestName(String fileName, int itemPos) { + return (itemPos == 0 ? "NULL" : fileName.substring(0, itemPos)); + } + + private static String getTestName(File file) { + String fileName = file.getName(); + int itemPos = fileName.indexOf("Policy"); + if (itemPos >= 0) { + return getTestName(fileName, itemPos); + } else if ((itemPos = fileName.indexOf("Request")) >= 0) { + return getTestName(fileName, itemPos); + } else if ((itemPos = fileName.indexOf("Response")) >= 0) { + return getTestName(fileName, itemPos); + } else if ((itemPos = fileName.indexOf("Repository")) >= 0) { + return getTestName(fileName, itemPos); + } else { + return null; + } + } + + public static ConformanceTestSet loadDirectory(File fileDir) throws IOException { + final Map mapConformanceTests = new HashMap(); + + Files.walkFileTree(fileDir.toPath(), new FileVisitor() { + @Override + public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { + logger.info("Scanning directory " + dir.getFileName()); + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + File fileVisited = file.toFile(); + String fileName = fileVisited.getName(); + if (fileName.endsWith(".xml") || fileName.endsWith(".properties")) { + String testName = getTestName(fileVisited); + if (testName != null) { + ConformanceTest conformanceTest = mapConformanceTests.get(testName); + if (conformanceTest == null) { + logger.info("Added test " + testName); + conformanceTest = new ConformanceTest(testName); + mapConformanceTests.put(testName, conformanceTest); + } + if (fileName.endsWith("Policy.xml")) { + conformanceTest.getRepository().addRootPolicy(fileVisited); + } else if (fileName.endsWith("Repository.properties")) { + conformanceTest.getRepository().load(fileVisited); + } else if (fileName.endsWith("Request.xml")) { + conformanceTest.setRequest(fileVisited); + } else if (fileName.endsWith("Response.xml")) { + conformanceTest.setResponse(fileVisited); + } + } + } + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { + logger.warn("Skipped " + file.getFileName()); + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { + return FileVisitResult.CONTINUE; + } + }); + + /* + * Sort the keyset and pull out the tests that have the required components + */ + List listTestNames = new ArrayList(); + listTestNames.addAll(mapConformanceTests.keySet()); + Collections.sort(listTestNames); + + ConformanceTestSet conformanceTestSet = new ConformanceTestSet(); + Iterator iterTestNames = listTestNames.iterator(); + while (iterTestNames.hasNext()) { + ConformanceTest conformanceTest = mapConformanceTests.get(iterTestNames.next()); + if (conformanceTest.isComplete()) { + conformanceTestSet.addConformanceTest(conformanceTest); + logger.debug("Added conformance test " + conformanceTest.getTestName()); + } else { + logger.warn("Incomplete conformance test " + conformanceTest.getTestName()); + } + } + + return conformanceTestSet; + + } + + public Iterator getConformanceTests() { + return this.listConformanceTests.iterator(); + } + + public void addConformanceTest(ConformanceTest conformanceTest) { + this.listConformanceTests.add(conformanceTest); + } + + public void addConformanceTestSet(ConformanceTestSet conformanceTestSet) { + this.listConformanceTests.addAll(conformanceTestSet.getListConformanceTests()); + } + + public static void main(String[] args) { + for (String dir : args) { + try { + ConformanceTestSet conformanceTestSet = ConformanceTestSet.loadDirectory(new File(dir)); + Iterator iterConformanceTests = conformanceTestSet.getConformanceTests(); + if (iterConformanceTests == null) { + System.out.println("No tests found in " + dir); + } else { + System.out.println("Tests found in " + dir); + while (iterConformanceTests.hasNext()) { + System.out.println(iterConformanceTests.next().toString()); + } + } + } catch (Exception ex) { + ex.printStackTrace(System.err); + } + } + } +} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/conformance/ResponseMatchResult.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/conformance/ResponseMatchResult.java new file mode 100644 index 000000000..31e6da415 --- /dev/null +++ b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/conformance/ResponseMatchResult.java @@ -0,0 +1,137 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-TEST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.conformance; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; + +import com.att.research.xacml.api.Response; +import com.att.research.xacml.api.Result; + +/** + * ResponseMatchResult provides information about how a {@link com.att.research.xacml.api.Response} object matches + * another Response object. + * + * @version $Revision: 1.1 $ + */ +public class ResponseMatchResult { + private List resultMatchResults = new ArrayList(); + + private boolean bAssociatedAdviceMatches = true; + private boolean bAttributesMatch = true; + private boolean bDecisionsMatch = true; + private boolean bStatusCodesMatch = true; + private boolean bObligationsMatch = true; + private boolean bPolicyIdentifiersMatch = true; + private boolean bPolicySetIdentifiersMatch = true; + private boolean bNumResultsMatch = true; + private boolean bUnknownFunction; + + protected void addResultMatchResult(ResultMatchResult resultMatchResult) { + this.resultMatchResults.add(resultMatchResult); + this.bAssociatedAdviceMatches = resultMatchResult.associatedAdviceMatches() && this.bAssociatedAdviceMatches; + this.bAttributesMatch = resultMatchResult.attributesMatch() && this.bAttributesMatch; + this.bDecisionsMatch = resultMatchResult.decisionsMatch() && this.bDecisionsMatch; + this.bStatusCodesMatch = resultMatchResult.statusCodesMatch() && this.bStatusCodesMatch; + this.bObligationsMatch = resultMatchResult.obligationsMatch() && this.bObligationsMatch; + this.bPolicyIdentifiersMatch = resultMatchResult.policyIdentifiersMatch() && this.bPolicyIdentifiersMatch; + this.bPolicySetIdentifiersMatch = resultMatchResult.policySetIdentifiersMatch() && this.bPolicySetIdentifiersMatch; + this.bUnknownFunction = resultMatchResult.unknownFunction() || this.bUnknownFunction; + } + + protected void setNumResultsMatch(boolean b) { + this.bNumResultsMatch = b; + } + + public ResponseMatchResult() { + } + + public static ResponseMatchResult newInstance(Response response1, Response response2) { + ResponseMatchResult responseMatchResult = new ResponseMatchResult(); + + Collection listResultsResponse1 = response1.getResults(); + Collection listResultsResponse2 = response2.getResults(); + if (listResultsResponse1.size() == 1 && listResultsResponse2.size() == 1) { + /* + * Just add a single ResultMatchResult comparing the results in the two responses + */ + responseMatchResult.addResultMatchResult(ResultMatchResult.newInstance(listResultsResponse1.iterator().next(), listResultsResponse2.iterator().next())); + } else { + /* + * Iterate over all of the results in the two responses and match them + */ + Iterator iterResponse1Results = listResultsResponse1.iterator(); + Iterator iterResponse2Results = listResultsResponse2.iterator(); + while ((iterResponse1Results != null && iterResponse1Results.hasNext()) || (iterResponse2Results != null && iterResponse2Results.hasNext())) { + Result result1 = (iterResponse1Results != null && iterResponse1Results.hasNext() ? iterResponse1Results.next() : null); + Result result2 = (iterResponse2Results != null && iterResponse2Results.hasNext() ? iterResponse2Results.next() : null); + if ((result1 == null || result2 == null) && responseMatchResult.numResultsMatch()) { + responseMatchResult.setNumResultsMatch(false); + } + responseMatchResult.addResultMatchResult(ResultMatchResult.newInstance(result1, result2)); + } + } + return responseMatchResult; + } + + public Iterator getResultMatchResults() { + return this.resultMatchResults.iterator(); + } + + public boolean numResultsMatch() { + return this.bNumResultsMatch; + } + + public boolean associatedAdviceMatches() { + return this.bAssociatedAdviceMatches; + } + + public boolean attributesMatch() { + return this.bAttributesMatch; + } + + public boolean decisionsMatch() { + return this.bDecisionsMatch; + } + + public boolean obligationsMatch() { + return this.bObligationsMatch; + } + + public boolean policyIdentifiersMatch() { + return this.bPolicyIdentifiersMatch; + } + + public boolean policySetIdentifiersMatch() { + return this.bPolicySetIdentifiersMatch; + } + + public boolean statusCodesMatch() { + return this.bStatusCodesMatch; + } + + public boolean unknownFunction() { + return this.bUnknownFunction; + } + +} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/conformance/ResultMatchResult.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/conformance/ResultMatchResult.java new file mode 100644 index 000000000..3da7e1a83 --- /dev/null +++ b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/conformance/ResultMatchResult.java @@ -0,0 +1,136 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-TEST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.conformance; + +import com.att.research.xacml.api.Result; +import com.att.research.xacml.std.StdStatusCode; +import com.att.research.xacml.util.ListUtil; + +/** + * ResultMatchResult provides information about how well a {@link com.att.research.xacml.api.Result} object matches + * another Result object. + * + * @version $Revision: 1.1 $ + */ +public class ResultMatchResult { + private boolean bAssociatedAdviceMatches = true; + private boolean bAttributesMatch = true; + private boolean bDecisionsMatch = true; + private boolean bObligationsMatch = true; + private boolean bPolicyIdentifiersMatch = true; + private boolean bPolicySetIdentifiersMatch = true; + private boolean bStatusCodesMatch = true; + private boolean bUnknownFunction = false; + + protected void setAssociatedAdviceMatches(boolean b) { + this.bAssociatedAdviceMatches = b; + } + protected void setAttributesMatch(boolean b) { + this.bAttributesMatch = b; + } + protected void setDecisionsMatch(boolean b) { + this.bDecisionsMatch = b; + } + protected void setObligationsMatch(boolean b) { + this.bObligationsMatch = b; + } + protected void setPolicyIdentifiersMatch(boolean b) { + this.bPolicyIdentifiersMatch = b; + } + protected void setPolicySetIdentifiersMatch(boolean b) { + this.bPolicySetIdentifiersMatch = b; + } + protected void setStatusCodesMatch(boolean b) { + this.bStatusCodesMatch = b; + } + protected void setUnknownFunction(boolean b) { + this.bUnknownFunction = b; + } + + public ResultMatchResult() { + } + + public static ResultMatchResult newInstance(Result result1, Result result2) { + ResultMatchResult resultMatchResult = new ResultMatchResult(); + if (result2 != null && result2.getStatus() != null && + result2.getStatus().getStatusCode().equals(StdStatusCode.STATUS_CODE_PROCESSING_ERROR) && + result2.getStatus().getStatusMessage() != null && + result2.getStatus().getStatusMessage().contains("Unknown Function") + ) { + resultMatchResult.setUnknownFunction(true); + } + if (result1 == null || result2 == null) { + resultMatchResult.setAssociatedAdviceMatches(false); + resultMatchResult.setAttributesMatch(false); + resultMatchResult.setDecisionsMatch(false); + resultMatchResult.setObligationsMatch(false); + resultMatchResult.setPolicyIdentifiersMatch(false); + resultMatchResult.setPolicySetIdentifiersMatch(false); + resultMatchResult.setStatusCodesMatch(false); + } else { + resultMatchResult.setAssociatedAdviceMatches(ListUtil.equalsAllowNulls(result1.getAssociatedAdvice(), result2.getAssociatedAdvice())); + resultMatchResult.setAttributesMatch(ListUtil.equalsAllowNulls(result1.getAttributes(), result2.getAttributes())); + resultMatchResult.setDecisionsMatch(result1.getDecision() == result2.getDecision()); + resultMatchResult.setObligationsMatch(ListUtil.equalsAllowNulls(result1.getObligations(), result2.getObligations())); + resultMatchResult.setPolicyIdentifiersMatch(ListUtil.equalsAllowNulls(result1.getPolicyIdentifiers(), result2.getPolicyIdentifiers())); + resultMatchResult.setPolicySetIdentifiersMatch(ListUtil.equalsAllowNulls(result1.getPolicySetIdentifiers(), result2.getPolicySetIdentifiers())); + if (result1.getStatus() == null || result1.getStatus().getStatusCode() == null || result2.getStatus() == null || result2.getStatus().getStatusCode() == null) { + resultMatchResult.setStatusCodesMatch(false); + } else { + resultMatchResult.setStatusCodesMatch(result1.getStatus().getStatusCode().equals(result2.getStatus().getStatusCode())); + } + } + return resultMatchResult; + } + + public boolean associatedAdviceMatches() { + return this.bAssociatedAdviceMatches; + } + + public boolean attributesMatch() { + return this.bAttributesMatch; + } + + public boolean decisionsMatch() { + return this.bDecisionsMatch; + } + + public boolean obligationsMatch() { + return this.bObligationsMatch; + } + + public boolean policyIdentifiersMatch() { + return this.bPolicyIdentifiersMatch; + } + + public boolean policySetIdentifiersMatch() { + return this.bPolicySetIdentifiersMatch; + } + + public boolean statusCodesMatch() { + return this.bStatusCodesMatch; + } + + public boolean unknownFunction() { + return this.bUnknownFunction; + } + +} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/custom/CustomDataTypeFactory.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/custom/CustomDataTypeFactory.java new file mode 100644 index 000000000..9e3442ff0 --- /dev/null +++ b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/custom/CustomDataTypeFactory.java @@ -0,0 +1,88 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-TEST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.custom; + +import java.util.HashMap; +import java.util.Map; + +import com.att.research.xacml.api.DataType; +import com.att.research.xacml.api.DataTypeFactory; +import com.att.research.xacml.api.Identifier; +import com.att.research.xacml.std.datatypes.DataTypes; + +public class CustomDataTypeFactory extends DataTypeFactory { + private static final Map> mapIdentifiersToDataTypes = new HashMap>(); + private static boolean mapNeedsInit = true; + + public static final DataTypePrivateKey DT_PRIVATEKEY = DataTypePrivateKey.newInstance(); + public static final DataTypePublicKey DT_PUBLICKEY = DataTypePublicKey.newInstance(); + + private static void registerDataType(DataType dataType) { + if (dataType != null && dataType.getId() != null) { + mapIdentifiersToDataTypes.put(dataType.getId(), dataType); + } + } + + private static void initMap() { + if (mapNeedsInit) { + synchronized(mapIdentifiersToDataTypes) { + if (mapNeedsInit) { + registerDataType(DataTypes.DT_ANYURI); + registerDataType(DataTypes.DT_BASE64BINARY); + registerDataType(DataTypes.DT_BOOLEAN); + registerDataType(DataTypes.DT_DATE); + registerDataType(DataTypes.DT_DATETIME); + registerDataType(DataTypes.DT_DAYTIMEDURATION); + registerDataType(DataTypes.DT_DNSNAME); + registerDataType(DataTypes.DT_DOUBLE); + registerDataType(DataTypes.DT_HEXBINARY); + registerDataType(DataTypes.DT_INTEGER); + registerDataType(DataTypes.DT_IPADDRESS); + registerDataType(DataTypes.DT_RFC822NAME); + registerDataType(DataTypes.DT_STRING); + registerDataType(DataTypes.DT_TIME); + registerDataType(DataTypes.DT_X500NAME); + registerDataType(DataTypes.DT_XPATHEXPRESSION); + registerDataType(DataTypes.DT_YEARMONTHDURATION); + // + // These are the custom data types! + // + registerDataType(DT_PRIVATEKEY); + registerDataType(DT_PUBLICKEY); + // + // Done + // + mapNeedsInit = false; + } + } + } + } + + public CustomDataTypeFactory() { + initMap(); + } + + @Override + public DataType getDataType(Identifier dataTypeId) { + return mapIdentifiersToDataTypes.get(dataTypeId); + } + +} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/custom/CustomFunctionDefinitionFactory.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/custom/CustomFunctionDefinitionFactory.java new file mode 100644 index 000000000..3b86236d4 --- /dev/null +++ b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/custom/CustomFunctionDefinitionFactory.java @@ -0,0 +1,90 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-TEST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.custom; + +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.security.PrivateKey; +import java.security.PublicKey; +import java.util.HashMap; +import java.util.Map; + +import com.att.research.xacml.api.Identifier; +import com.att.research.xacml.std.IdentifierImpl; +import com.att.research.xacmlatt.pdp.policy.FunctionDefinition; +import com.att.research.xacmlatt.pdp.policy.FunctionDefinitionFactory; +import com.att.research.xacmlatt.pdp.std.StdFunctions; +import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionBagOneAndOnly; + +public class CustomFunctionDefinitionFactory extends FunctionDefinitionFactory { + private static Map mapFunctionDefinitions = new HashMap(); + private static boolean needMapInit = true; + + public static final Identifier ID_FUNCTION_PRIVATEKEY_ONE_AND_ONLY = new IdentifierImpl("urn:com:att:research:xacml:custom:function:3.0:rsa:privatekey-one-and-only"); + public static final Identifier ID_FUNCTION_PUBLICKEY_ONE_AND_ONLY = new IdentifierImpl("urn:com:att:research:xacml:custom:function:3.0:rsa:publickey-one-and-only"); + + public static final FunctionDefinition FD_PRIVATEKEY_ONE_AND_ONLY = new FunctionDefinitionBagOneAndOnly(ID_FUNCTION_PRIVATEKEY_ONE_AND_ONLY, DataTypePrivateKey.newInstance()); + public static final FunctionDefinition FD_PUBLICKEY_ONE_AND_ONLY = new FunctionDefinitionBagOneAndOnly(ID_FUNCTION_PUBLICKEY_ONE_AND_ONLY, DataTypePublicKey.newInstance()); + + private static void register(FunctionDefinition functionDefinition) { + mapFunctionDefinitions.put(functionDefinition.getId(), functionDefinition); + } + + private static void initMap() { + if (needMapInit) { + synchronized(mapFunctionDefinitions) { + if (needMapInit) { + needMapInit = false; + Field[] declaredFields = StdFunctions.class.getDeclaredFields(); + for (Field field : declaredFields) { + if (Modifier.isStatic(field.getModifiers()) && + field.getName().startsWith(StdFunctions.FD_PREFIX) && + FunctionDefinition.class.isAssignableFrom(field.getType()) && + Modifier.isPublic(field.getModifiers()) + ) { + try { + register((FunctionDefinition)(field.get(null))); + } catch (IllegalAccessException ex) { + + } + } + } + // + // Our custom function + // + register(FunctionDefinitionDecrypt.newInstance()); + register(FD_PRIVATEKEY_ONE_AND_ONLY); + register(FD_PUBLICKEY_ONE_AND_ONLY); + } + } + } + } + + public CustomFunctionDefinitionFactory() { + initMap(); + } + + @Override + public FunctionDefinition getFunctionDefinition(Identifier functionId) { + return mapFunctionDefinitions.get(functionId); + } + +} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/custom/DataTypePrivateKey.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/custom/DataTypePrivateKey.java new file mode 100644 index 000000000..3f84ef36e --- /dev/null +++ b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/custom/DataTypePrivateKey.java @@ -0,0 +1,54 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-TEST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.custom; + +import java.security.PrivateKey; + +import com.att.research.xacml.api.DataTypeException; +import com.att.research.xacml.api.Identifier; +import com.att.research.xacml.std.IdentifierImpl; +import com.att.research.xacml.std.datatypes.DataTypeBase; + +public class DataTypePrivateKey extends DataTypeBase { + public static final Identifier DT_PRIVATEKEY = new IdentifierImpl("urn:com:att:research:xacml:custom:3.0:rsa:private"); + private static final DataTypePrivateKey singleInstance = new DataTypePrivateKey(); + + private DataTypePrivateKey() { + super(DT_PRIVATEKEY, PrivateKey.class); + } + + public static DataTypePrivateKey newInstance() { + return singleInstance; + } + + @Override + public PrivateKey convert(Object source) throws DataTypeException { + if (source == null || (source instanceof PrivateKey) ) { + return (PrivateKey) source; + } else if (source instanceof byte[]) { + return (PrivateKey) source; + } else if (source instanceof String) { + return (PrivateKey) (Object) ((String) source).getBytes(); + } + throw new DataTypeException(this, "Failed to convert \"" + source.getClass().getCanonicalName()); + } + +} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/custom/DataTypePublicKey.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/custom/DataTypePublicKey.java new file mode 100644 index 000000000..ce28c534a --- /dev/null +++ b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/custom/DataTypePublicKey.java @@ -0,0 +1,54 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-TEST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.custom; + +import java.security.PublicKey; + +import com.att.research.xacml.api.DataTypeException; +import com.att.research.xacml.api.Identifier; +import com.att.research.xacml.std.IdentifierImpl; +import com.att.research.xacml.std.datatypes.DataTypeBase; + +public class DataTypePublicKey extends DataTypeBase { + public static final Identifier DT_PUBLICKEY = new IdentifierImpl("urn:com:att:research:xacml:custom:3.0:rsa:public"); + private static final DataTypePublicKey singleInstance = new DataTypePublicKey(); + + public DataTypePublicKey() { + super(DT_PUBLICKEY, PublicKey.class); + } + + public static DataTypePublicKey newInstance() { + return singleInstance; + } + + @Override + public PublicKey convert(Object source) throws DataTypeException { + if (source == null || (source instanceof PublicKey) ) { + return (PublicKey) source; + } else if (source instanceof byte[]) { + return (PublicKey) source; + } else if (source instanceof String) { + return (PublicKey) (Object) ((String) source).getBytes(); + } + throw new DataTypeException(this, "Failed to convert \"" + source.getClass().getCanonicalName()); + } + +} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/custom/FunctionDefinitionDecrypt.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/custom/FunctionDefinitionDecrypt.java new file mode 100644 index 000000000..fafef2ae8 --- /dev/null +++ b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/custom/FunctionDefinitionDecrypt.java @@ -0,0 +1,162 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-TEST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.custom; + +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; +import java.security.PrivateKey; +import java.security.PublicKey; +import java.util.List; + +import javax.crypto.BadPaddingException; +import javax.crypto.Cipher; +import javax.crypto.IllegalBlockSizeException; +import javax.crypto.NoSuchPaddingException; + +import com.att.research.xacml.api.DataType; +import com.att.research.xacml.api.DataTypeException; +import com.att.research.xacml.api.Identifier; +import com.att.research.xacml.api.XACML3; +import com.att.research.xacml.std.IdentifierImpl; +import com.att.research.xacml.std.StdStatus; +import com.att.research.xacml.std.StdStatusCode; +import com.att.research.xacml.std.datatypes.DataTypeHexBinary; +import com.att.research.xacml.std.datatypes.DataTypeString; +import com.att.research.xacml.std.datatypes.HexBinary; +import com.att.research.xacmlatt.pdp.eval.EvaluationContext; +import com.att.research.xacmlatt.pdp.policy.ExpressionResult; +import com.att.research.xacmlatt.pdp.policy.FunctionArgument; +import com.att.research.xacmlatt.pdp.policy.FunctionDefinition; +import com.att.research.xacmlatt.pdp.std.functions.ConvertedArgument; + +public class FunctionDefinitionDecrypt implements FunctionDefinition { + public static final Identifier FD_RSA_DECRYPT = new IdentifierImpl("urn:com:att:research:xacml:custom:function:3.0:rsa:decrypt"); + private static final FunctionDefinitionDecrypt singleInstance = new FunctionDefinitionDecrypt(); + + public static FunctionDefinitionDecrypt newInstance() { + return singleInstance; + } + + @Override + public Identifier getId() { + return FD_RSA_DECRYPT; + } + + @Override + public Identifier getDataTypeId() { + return XACML3.ID_DATATYPE_STRING; + } + + @Override + public boolean returnsBag() { + return false; + } + + @Override + public ExpressionResult evaluate(EvaluationContext evaluationContext, List arguments) { + if (arguments == null || arguments.size() < 2) { + return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, "Decrypt failed, expecting 2 arguments.")); + } + // + // What is the first argument? + // + FunctionArgument arg0 = arguments.get(0); + if (arg0.isBag()) { + // + // We don't support bags right now + // + return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, "Decrypt failed, not expecting a bag for argument 0.")); + } + if (arg0.getValue().getDataTypeId().equals(XACML3.ID_DATATYPE_HEXBINARY) == false) { + // + // Should be a String + // + return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, "Decrypt failed, expected a Hex Binary for argument 0.")); + } + // + // Convert the argument + // + ConvertedArgument data = new ConvertedArgument(arg0, DataTypeHexBinary.newInstance(), false); + if (! data.isOk()) { + return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, "Decrypt failed, argument 0 failed to convert to Hex Binary.")); + } + // + // Ok - check the 2nd argument + // + FunctionArgument arg1 = arguments.get(1); + if (arg1.isBag()) { + // + // We don't support bags right now + // + return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, "Decrypt failed, not expecting a bag for argument 1.")); + } + if (arg1.getValue().getDataTypeId().equals(DataTypePrivateKey.DT_PRIVATEKEY) || + arg1.getValue().getDataTypeId().equals(DataTypePublicKey.DT_PUBLICKEY)) { + // + // Ok - let's try to decrypt + // + Cipher cipher; + try { + cipher = Cipher.getInstance("RSA"); + if (arg1.getValue().getDataTypeId().equals(DataTypePrivateKey.DT_PRIVATEKEY)) { + // + // Using the private key + // + DataType pkDatatype = DataTypePrivateKey.newInstance(); + ConvertedArgument privateKey = new ConvertedArgument(arg1, pkDatatype, false); + if ( ! privateKey.isOk()) { + return ExpressionResult.newError(new StdStatus(privateKey.getStatus().getStatusCode(), "Decrypt: " + privateKey.getStatus().getStatusMessage())); + } + // + // Setup decryption + // + cipher.init(Cipher.DECRYPT_MODE, privateKey.getValue()); + } else if (arg1.getValue().getDataTypeId().equals(DataTypePublicKey.DT_PUBLICKEY)) { + // + // Using the private key + // + DataType pkDatatype = DataTypePublicKey.newInstance(); + ConvertedArgument publicKey = new ConvertedArgument(arg1, pkDatatype, false); + if ( ! publicKey.isOk()) { + return ExpressionResult.newError(new StdStatus(publicKey.getStatus().getStatusCode(), "Decrypt: " + publicKey.getStatus().getStatusMessage())); + } + // + // Setup decryption + // + cipher.init(Cipher.DECRYPT_MODE, publicKey.getValue()); + } + // + // Do the decryption + // + byte[] decryptedData = cipher.doFinal(data.getValue().getData()); + String decryptedString = new String(decryptedData); + // + // All good, return the decrypted string + // + return ExpressionResult.newSingle(DataTypeString.newInstance().createAttributeValue(decryptedString)); + } catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | IllegalBlockSizeException | BadPaddingException | DataTypeException e) { + return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, "Decrypt failed: " + e.getLocalizedMessage())); + } + } + return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, "Decrypt failed, expecting public/private key datatype for argument 1.")); + } + +} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/custom/TestCustom.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/custom/TestCustom.java new file mode 100644 index 000000000..b3f2455de --- /dev/null +++ b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/custom/TestCustom.java @@ -0,0 +1,393 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-TEST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.custom; + +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.net.MalformedURLException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.security.InvalidKeyException; +import java.security.KeyPair; +import java.security.KeyPairGenerator; +import java.security.NoSuchAlgorithmException; +import java.security.PrivateKey; +import java.security.PublicKey; +import java.util.ArrayList; +import java.util.List; + +import javax.crypto.BadPaddingException; +import javax.crypto.Cipher; +import javax.crypto.IllegalBlockSizeException; +import javax.crypto.NoSuchPaddingException; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.GnuParser; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.ParseException; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openecomp.policy.pdp.test.TestBase; + +import com.att.research.xacml.api.AttributeValue; +import com.att.research.xacml.api.DataType; +import com.att.research.xacml.api.DataTypeException; +import com.att.research.xacml.api.Request; +import com.att.research.xacml.api.RequestAttributes; +import com.att.research.xacml.api.XACML3; +import com.att.research.xacml.api.pep.PEPException; +import com.att.research.xacml.std.IdentifierImpl; +import com.att.research.xacml.std.StdMutableAttribute; +import com.att.research.xacml.std.StdMutableRequest; +import com.att.research.xacml.std.StdMutableRequestAttributes; +import com.att.research.xacml.std.dom.DOMStructureException; +import com.att.research.xacml.std.json.JSONStructureException; +import com.att.research.xacml.util.FactoryException; + +/** + * TestCustom is an application that tests the extensibility and configurability of the AT&T XACML API. + * + * It creates a custom datatype definition factory that adds in custom data types for RSA + * PublicKey and PrivateKey. + * + * It creates a custom function definition factory that adds in custom decryption function for decrypting data. It + * also derives and loads custom functions for the RSA public/private key datatypes for the bag function: one-and-only. + * + * + */ +public class TestCustom extends TestBase { + private static final Log logger = LogFactory.getLog(TestCustom.class); + + // + // Our public's + // + public static final String ALGORITHM = "RSA"; + public static final String PRIVATEKEY_FILE = "PrivateKey.key"; + public static final String PUBLICKEY_FILE = "PublicKey.key"; + + public static final String DECRYPTION_INPUT_STRING = "This is the SECRET value!"; + + public static final String DECRYPTION_INPUT_ID = "com:att:research:xacml:test:custom:encrypted-data"; + // + // Our keys + // + protected PublicKey publicKey = null; + protected PrivateKey privateKey = null; + // + // Our command line parameters + // + public static final String OPTION_GENERATE = "generate"; + + static { + options.addOption(new Option(OPTION_GENERATE, false, "Generate a private/public key pair.")); + } + + /** + * This function generates the public/private key pair. Should never have to call this again, this was + * called once to generate the keys. They were saved into the testsets/custom/datatype-function sub-directory. + */ + public void generateKeyPair() { + // + // Generate a RSA private/public key pair + // + KeyPairGenerator keyGen; + try { + keyGen = KeyPairGenerator.getInstance(ALGORITHM); + } catch (NoSuchAlgorithmException e) { + logger.error("failed to generate keypair: " + e); + return; + } + keyGen.initialize(1024); + final KeyPair key = keyGen.generateKeyPair(); + // + // Save the keys to disk + // + Path file = Paths.get(this.directory, PRIVATEKEY_FILE); + try (ObjectOutputStream os = new ObjectOutputStream(Files.newOutputStream(file))) { + os.writeObject(key.getPrivate()); + } catch (IOException e) { + e.printStackTrace(); + } + file = Paths.get(this.directory, PUBLICKEY_FILE); + try (ObjectOutputStream os = new ObjectOutputStream(Files.newOutputStream(file))) { + os.writeObject(key.getPublic()); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public TestCustom(String[] args) throws ParseException, MalformedURLException, HelpException { + super(args); + } + + /* (non-Javadoc) + * + * Simply look for command line option: -generate + * This generates the public/private key. Shouldn't need to call it again, the keys have + * already been generated and saved. + * + * @see org.openecomp.policy.pdp.test.TestBase#parseCommands(java.lang.String[]) + */ + @Override + protected void parseCommands(String[] args) throws ParseException, MalformedURLException, HelpException { + // + // Have our parent class parse its options out + // + super.parseCommands(args); + // + // Parse the command line options + // + CommandLine cl; + cl = new GnuParser().parse(options, args); + if (cl.hasOption(OPTION_GENERATE)) { + // + // Really only need to do this once to setup the test. + // + this.generateKeyPair(); + } + } + + /* (non-Javadoc) + * + * After our parent class configure's itself, all this needs to do is read in + * the public/private key's into objects. + * + * @see org.openecomp.policy.pdp.test.TestBase#configure() + */ + @Override + protected void configure() throws FactoryException { + // + // Have our super do its thing + // + super.configure(); + // + // Read in the public key + // + try { + this.publicKey = (PublicKey) new ObjectInputStream(Files.newInputStream(Paths.get(this.directory, PUBLICKEY_FILE))).readObject(); + } catch (ClassNotFoundException | IOException e) { + logger.error(e); + } + // + // Read in the private key + // + try { + this.privateKey = (PrivateKey) new ObjectInputStream(Files.newInputStream(Paths.get(this.directory, PRIVATEKEY_FILE))).readObject(); + } catch (ClassNotFoundException | IOException e) { + logger.error(e); + } + } + + /* (non-Javadoc) + * + * Here we add 2 attributes into the request: 1) the private key, and 2) a String that was encrypted using the public key. + * + * The goal is to have the custom decrypt function use the private key to decrypt that string. + * + * @see org.openecomp.policy.pdp.test.TestBase#generateRequest(java.nio.file.Path, java.lang.String) + */ + @Override + protected Request generateRequest(Path file, String group) throws JSONStructureException, DOMStructureException, PEPException { + // + // Have our super class do its work + // + Request oldRequest = super.generateRequest(file, group); + // + // Copy the request attributes + // + List attributes = new ArrayList(); + for (RequestAttributes a : oldRequest.getRequestAttributes()) { + attributes.add(new StdMutableRequestAttributes(a)); + } + // + // We are supplying the private key as an attribute for the decryption function to use: + // + // (NOTE: Ideally this would be provided by a custom PIP provider, not the PEP) + // + // ID=com:att:research:xacml:test:custom:privatekey + // Issuer=com:att:research:xacml:test:custom + // Category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject + // Datatype=urn:com:att:research:xacml:custom:3.0:rsa:private + // + DataType dtExtended = dataTypeFactory.getDataType(DataTypePrivateKey.DT_PRIVATEKEY); + if (dtExtended == null) { + logger.error("Failed to get private key datatype."); + return null; + } + // + // Create the attribute value + // + try { + AttributeValue attributeValue = dtExtended.createAttributeValue(this.privateKey); + // + // Create the attribute + // + StdMutableAttribute newAttribute = new StdMutableAttribute(XACML3.ID_SUBJECT_CATEGORY_ACCESS_SUBJECT, + new IdentifierImpl("com:att:research:xacml:test:custom:privatekey"), + attributeValue, + "com:att:research:xacml:test:custom", + false); + boolean added = false; + for (StdMutableRequestAttributes a : attributes) { + // + // Does the category exist? + // + if (a.getCategory().equals(XACML3.ID_SUBJECT_CATEGORY_ACCESS_SUBJECT)) { + // + // Yes - add in the new attribute value + // + a.add(newAttribute); + added = true; + break; + } + } + if (added == false) { + // + // New category - create it and add it in + // + StdMutableRequestAttributes a = new StdMutableRequestAttributes(); + a.setCategory(newAttribute.getCategory()); + a.add(newAttribute); + attributes.add(a); + } + } catch (DataTypeException e) { + logger.error(e); + return null; + } + // + // We are also supplying this attribute which is the secret text encrypted with + // the public key. + // + // ID=com:att:research:xacml:test:custom:encrypted-data + // Issuer= + // Category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject + // Datatype=http://www.w3.org/2001/XMLSchema#hexBinary + // + // Encrypt it + // + byte[] encryptedData = null; + try { + Cipher cipher = Cipher.getInstance(ALGORITHM); + cipher.init(Cipher.ENCRYPT_MODE, this.publicKey); + // + // This is just a hack to test a decryption of the wrong value. + // + if (group.equals("Permit")) { + encryptedData = cipher.doFinal(DECRYPTION_INPUT_STRING.getBytes()); + } else { + encryptedData = cipher.doFinal("This is NOT the secret".getBytes()); + } + } catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | IllegalBlockSizeException | BadPaddingException e) { + logger.error(e); + return null; + } + // + // Sanity check (for the Permit request) + // + try { + if (group.equals("Permit")) { + Cipher cipher = Cipher.getInstance(ALGORITHM); + cipher.init(Cipher.DECRYPT_MODE, this.privateKey); + byte[] decryptedData = cipher.doFinal(encryptedData); + if (new String(decryptedData).equals(DECRYPTION_INPUT_STRING)) { + logger.info("Sanity check passed: decrypted the encrypted data."); + } else { + logger.error("Sanity check failed to decrypt the encrypted data."); + return null; + } + } + } catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | IllegalBlockSizeException | BadPaddingException e) { + logger.error(e); + } + // + // Get our datatype factory + // + dtExtended = dataTypeFactory.getDataType(XACML3.ID_DATATYPE_HEXBINARY); + if (dtExtended == null) { + logger.error("Failed to get hex binary datatype."); + return null; + } + // + // Create the attribute value + // + try { + AttributeValue attributeValue = dtExtended.createAttributeValue(encryptedData); + // + // Create the attribute + // + StdMutableAttribute newAttribute = new StdMutableAttribute(XACML3.ID_SUBJECT_CATEGORY_ACCESS_SUBJECT, + new IdentifierImpl("com:att:research:xacml:test:custom:encrypted-data"), + attributeValue, + null, + false); + boolean added = false; + for (StdMutableRequestAttributes a : attributes) { + // + // Does the category exist? + // + if (a.getCategory().equals(XACML3.ID_SUBJECT_CATEGORY_ACCESS_SUBJECT)) { + // + // Yes - add in the new attribute value + // + a.add(newAttribute); + added = true; + break; + } + } + if (added == false) { + // + // New category - create it and add it in + // + StdMutableRequestAttributes a = new StdMutableRequestAttributes(); + a.setCategory(newAttribute.getCategory()); + a.add(newAttribute); + attributes.add(a); + } + } catch (DataTypeException e) { + logger.error(e); + return null; + } + // + // Now form our final request + // + StdMutableRequest newRequest = new StdMutableRequest(); + newRequest.setCombinedDecision(oldRequest.getCombinedDecision()); + newRequest.setRequestDefaults(oldRequest.getRequestDefaults()); + newRequest.setReturnPolicyIdList(oldRequest.getReturnPolicyIdList()); + newRequest.setStatus(oldRequest.getStatus()); + for (StdMutableRequestAttributes a : attributes) { + newRequest.add(a); + } + return newRequest; + } + + public static void main(String[] args) { + try { + new TestCustom(args).run(); + } catch (ParseException | IOException | FactoryException e) { + logger.error(e); + } catch (HelpException e) { + } + } + +} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/policy/TestPolicy.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/policy/TestPolicy.java new file mode 100644 index 000000000..f9f5f9026 --- /dev/null +++ b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/policy/TestPolicy.java @@ -0,0 +1,794 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-TEST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.policy; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.regex.Matcher; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBElement; +import javax.xml.bind.Marshaller; + +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributesType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObjectFactory; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicySetType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.RequestType; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.GnuParser; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.ParseException; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openecomp.policy.pdp.test.TestBase; +import org.openecomp.policy.xacml.util.XACMLPolicyScanner; + +import com.att.research.xacml.api.AttributeValue; +import com.att.research.xacml.api.DataType; +import com.att.research.xacml.api.DataTypeException; +import com.att.research.xacml.api.DataTypeFactory; +import com.att.research.xacml.api.Identifier; +import com.att.research.xacml.api.XACML3; +import com.att.research.xacml.std.IdentifierImpl; +import com.att.research.xacml.util.FactoryException; +import com.att.research.xacml.util.XACMLObjectCopy; +import com.att.research.xacml.util.XACMLPolicyAggregator; +import com.att.research.xacml.util.XACMLProperties; + + +/** + * This class reads the policy in and extracts all the attributes and their values that is contained + * in the Policy. It then generates a request every single combination of attributes found. + * + * The attributes mostly come from the Target Match elements, since they have both an attribute designator/selector + * matched with an attribute value. + * + * + */ +public class TestPolicy extends TestBase { + private static Log logger = LogFactory.getLog(TestPolicy.class); + + private boolean skip; + private Path policy; + private XACMLPolicyAggregator aggregator = new XACMLPolicyAggregator(); + private long index; + + // + // Our command line parameters + // + public static final String OPTION_POLICY = "policy"; + public static final String OPTION_SKIP_GENERATE = "skip"; + + static { + options.addOption(new Option(OPTION_POLICY, true, "Path to the policy file.")); + options.addOption(new Option(OPTION_SKIP_GENERATE, false, "Skip generating requests.")); + } + + public class FlattenerObject { + Identifier category; + Identifier datatype; + Identifier attribute; + Set> values; + } + + /** + * This application exercises a policy by producing ALL the possible request combinations for a policy. + * + * -policy Path to a policy file + * + * @param args + * @throws HelpException + * @throws ParseException + * @throws MalformedURLException + */ + + public TestPolicy(String[] args) throws MalformedURLException, ParseException, HelpException { + super(args); + } + + /* + * Look for the -policy command line argument. This application needs a pointer to a specific policy + * in order to run. + * + * + * (non-Javadoc) + * @see org.openecomp.policy.pdp.test.TestBase#parseCommands(java.lang.String[]) + */ + @Override + protected void parseCommands(String[] args) throws ParseException, MalformedURLException, HelpException { + // + // Have our super do its job + // + super.parseCommands(args); + // + // Look for the policy option + // + CommandLine cl; + cl = new GnuParser().parse(options, args); + if (cl.hasOption(OPTION_POLICY)) { + this.policy = Paths.get(cl.getOptionValue(OPTION_POLICY)); + // + // Ensure it exists + // + if (Files.notExists(this.policy)) { + throw new ParseException("Policy file does not exist."); + } + } else { + throw new ParseException("You need to specify the policy file to be used."); + } + if (cl.hasOption(OPTION_SKIP_GENERATE)) { + this.skip = true; + } else { + this.skip = false; + } + } + + /* + * We override this method because here is where we want to scan the policy and aggregate all + * the attributes that are defined within the policy. This routine will then dump all the possible + * requests into the requests sub-directory. Thus, when this method returns the TestBase can proceed + * to iterate each generated request and run it against the PDP engine. + * + * (non-Javadoc) + * @see org.openecomp.policy.pdp.test.TestBase#configure() + */ + @Override + protected void configure() throws FactoryException { + // + // Have our base class do its thing + // + super.configure(); + // + // Setup where the PDP can find the policy + // + System.setProperty(XACMLProperties.PROP_ROOTPOLICIES, "policy"); + System.setProperty("policy.file", this.policy.toString()); + // + // Determine if they want us to skip generation. This helps when a huge number of + // requests will get generated for a policy and can take some time to do so. The user + // can generate the requests once and then start testing a policy against the requests. Thus, + // the attributes never changed but the policy logic did (saves time). + // + if (this.skip) { + return; + } + // + // Now we will scan the policy and get all the attributes. + // + XACMLPolicyScanner scanner = new XACMLPolicyScanner(this.policy, this.aggregator); + // + // The scanner returns us a policy object + // + Object policyObject = scanner.scan(); + // + // Just dump some info + // + if (policyObject instanceof PolicySetType) { + logger.info("Creating requests for policyset: " + ((PolicySetType)policyObject).getDescription()); + } else if (policyObject instanceof PolicyType) { + logger.info("Creating requests for policy: " + ((PolicyType)policyObject).getDescription()); + } + // + // Call the function to create the requests + // + if (policyObject != null) { + this.createRequests(); + } + + logger.info("Completed Generating requests."); + } + + @SuppressWarnings("unchecked") + protected void createRequests() { + // + // Clear out our request directory + // + this.removeRequests(); + // + // Get our map + // + Map>>>> attributeMap = this.aggregator.getAttributeMap(); + // + // We're going to create an initial flat list of requests for each unique attribute ID. Unique being the + // category, datatype and attribute id. + // + // By flattening the list, it makes it easier to then generate all the combinations of possible requests. + // + List attributes = new ArrayList(); + // + // Iterate through all the maps, we are going to flatten it + // out into an array list. + // + for (Map.Entry>>>> categoryEntry : attributeMap.entrySet()) { + String category = categoryEntry.getKey().toString(); + if (logger.isDebugEnabled()) { + logger.debug("Category: " + category); + } + Map>>> datatypeMap = categoryEntry.getValue(); + for (Map.Entry>>> datatypeEntry : datatypeMap.entrySet()) { + String datatype = datatypeEntry.getKey().toString(); + if (logger.isDebugEnabled()) { + logger.debug("\tData Type: " + datatype); + } + Map>> attributeIDMap = datatypeEntry.getValue(); + for (Map.Entry>> attributeIDEntry : attributeIDMap.entrySet()) { + String attributeID = attributeIDEntry.getKey().toString(); + if (logger.isDebugEnabled()) { + logger.debug("\t\tAttribute ID: " + attributeID); + } + Set> attributeValueSet = attributeIDEntry.getValue(); + // + // Sanity check to see if there are any values. Sometimes there isn't if an attribute + // is a designator that is part of a condition or variable. + // + if (attributeValueSet.isEmpty()) { + if (logger.isDebugEnabled()) { + logger.debug("No values for attribute " + attributeIDEntry.getKey().stringValue()); + } + // + // Check for the boolean datatype, in that case we can safely + // assume the true/false are ALL the possible values. + // + if (datatypeEntry.getKey().equals(XACML3.ID_DATATYPE_BOOLEAN) == false) { + // + // Not boolean, so skip it + // + continue; + } + if (logger.isDebugEnabled()) { + logger.debug("No values but its a boolean datatype, we will include it anyway."); + } + } + // + // Create our flattener object + // + FlattenerObject flat = new FlattenerObject(); + flat.category = categoryEntry.getKey(); + flat.datatype = datatypeEntry.getKey(); + flat.attribute = attributeIDEntry.getKey(); + flat.values = new HashSet>(); + if (datatypeEntry.getKey().equals(XACML3.ID_DATATYPE_BOOLEAN)) { + // + // There are only 2 possible values, true or false + // + flat.values.add(this.createAttributeValue(flat.datatype, true)); + flat.values.add(this.createAttributeValue(flat.datatype, false)); + } else { + flat.values.addAll(attributeValueSet); + } + attributes.add(flat); + } + } + } + if (attributes.size() <= 1) { + // + // Only one attribute, why bother + // + logger.info("Not enough attributes in policy: " + attributes.size()); + return; + } + /* + * PLD work more on this later. This combinatorial formula is only accurate if each + * attribute has one value. + * + */ + if (logger.isDebugEnabled()) { + // + // This isn't really accurate, if an attribute has more than one value + // + logger.debug(attributes.size() + " will generate " + computePossibleCombinations(attributes.size())); + } + this.index = 1; + for (int i = 0; i < attributes.size(); i++) { + FlattenerObject flat = attributes.get(i); + for (AttributeValue value : flat.values) { + // + // Create a basic request object for just that attribute value. + // + RequestType request = new RequestType(); + // + AttributesType attrs = new AttributesType(); + attrs.setCategory(flat.category.stringValue()); + request.getAttributes().add(attrs); + // + AttributeType attr = new AttributeType(); + attr.setAttributeId(flat.attribute.stringValue()); + attrs.getAttribute().add(attr); + // + AttributeValueType val = new AttributeValueType(); + val.setDataType(flat.datatype.stringValue()); + if (value.getValue() instanceof Collection) { + val.getContent().addAll((Collection) value.getValue()); + } else { + val.getContent().add(value.getValue().toString()); + } + // + attr.getAttributeValue().add(val); + // + // Dump it out + // + this.writeRequest(request); + // + // Initiate recursive call to add other attributes to the request + // + this.recursivelyGenerateRequests(request, i + 1, attributes); + } + } + } + + protected void recursivelyGenerateRequests(RequestType request, int i, List attributes) { + if (logger.isTraceEnabled()) { + logger.trace("recursiveGenerate index: " + index + " i: " + i); + } + for ( ; i < attributes.size(); i++) { + FlattenerObject flat = attributes.get(i); + for (AttributeValue value : flat.values) { + // + // Make a copy of the request + // + RequestType copyRequest = XACMLObjectCopy.deepCopy(request); + // + // Create the value object + // + AttributeValueType newValue = new AttributeValueType(); + newValue.setDataType(flat.datatype.stringValue()); + if (value.getValue() instanceof Collection) { + for (Object v : (Collection) value.getValue()) { + newValue.getContent().add(v.toString()); + } + } else { + newValue.getContent().add(value.getValue().toString()); + } + // + // Add the value to the request + // + this.addAttribute(copyRequest, flat.category.stringValue(), flat.attribute.stringValue(), newValue); + // + // Now write it out + // + this.writeRequest(copyRequest); + // + // Recursively go through the rest of the attributes + // + this.recursivelyGenerateRequests(copyRequest, i + 1, attributes); + } + } + } + + public static long computePossibleCombinations(long numberOfAttributes) { + long num = 0; + for (long i = numberOfAttributes; i > 0; i--) { + num += computeCombinations(numberOfAttributes, i); + } + return num; + } + + public static long computeFactorial(long n) { + long fact = 1; + for (long i = 1; i <= n; i++) { + fact *= i; + } + return fact; + } + + public static long computePermutationsWithoutRepetition(long n, long r) { + // + // n! + // --------- + // (n - r)! + // + long nPrime = 1; + long n_rPrime = 1; + for (long i = n; i > 1; i--) { + nPrime *= i; + } + + for (long i = (n - r); i > 1; i--) { + n_rPrime *= i; + } + return nPrime / n_rPrime; + } + + public static long computeCombinations(long n, long r) { + // + // n! + // ----------- + // r! * (n-r)! + // + long nPrime = 1; + long rPrime = 1; + long n_rPrime = 1; + + for (long i = n; i > 1; i--) { + nPrime *= i; + } + + for (long i = r; i > 1; i--) { + rPrime *= i; + } + + for (long i = (n - r); i > 1; i--) { + n_rPrime *= i; + } + + return nPrime / (rPrime * n_rPrime); + } + + protected Set> getAttributeValues(RequestType request) { + // + // Get our map + // + Map>>>> attributeMap = this.aggregator.getAttributeMap(); + // + // Find the attribute + // + AttributesType attrs = request.getAttributes().get(0); + Map>>> categoryMap = attributeMap.get(new IdentifierImpl(attrs.getCategory())); + if (categoryMap != null) { + AttributeType a = attrs.getAttribute().get(0); + Map>> datatypeMap = categoryMap.get(new IdentifierImpl(a.getAttributeValue().get(0).getDataType())); + if (datatypeMap != null) { + Set> values = datatypeMap.get(new IdentifierImpl(a.getAttributeId())); + if (values != null) { + return values; + } + } + } + return Collections.emptySet(); + } + + protected AttributeValue createAttributeValue(Identifier datatype, Object value) { + DataTypeFactory dataTypeFactory = null; + try { + dataTypeFactory = DataTypeFactory.newInstance(); + if (dataTypeFactory == null) { + logger.error("Could not create data type factory"); + return null; + } + } catch (FactoryException e) { + logger.error("Can't get Data type Factory: " + e.getLocalizedMessage()); + return null; + } + DataType dataTypeExtended = dataTypeFactory.getDataType(datatype); + if (dataTypeExtended == null) { + logger.error("Unknown datatype: " + datatype); + return null; + } + try { + return dataTypeExtended.createAttributeValue(value); + } catch (DataTypeException e) { + logger.error(e); + } + return null; + } + + protected void removeRequests() { + // + // Delete any existing request files that we generate. i.e. Have the Unknown in the file name. + // + try { + Files.walkFileTree(Paths.get(this.directory.toString(), "requests"), new SimpleFileVisitor() { + + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + // + // Sanity check the file name + // + Matcher matcher = pattern.matcher(file.getFileName().toString()); + if (matcher.matches()) { + try { + // + // Pull what this request is supposed to be + // + String group = null; + int count = matcher.groupCount(); + if (count >= 1) { + group = matcher.group(count-1); + } + // + // Send it + // + if (group.equals("Unknown")) { + // + // Remove the file + // + Files.delete(file); + } + } catch (Exception e) { + logger.error(e); + e.printStackTrace(); + } + } + return super.visitFile(file, attrs); + } + }); + } catch (IOException e) { + logger.error("Failed to removeRequests from " + this.directory + " " + e); + } + } + + protected void addRequests(RequestType request, List requests, int index) { + for (RequestType req : requests) { + // + // There really should only be one attribute + // + for (AttributesType attrs : req.getAttributes()) { + for (AttributeType attr : attrs.getAttribute()) { + for (AttributeValueType value : attr.getAttributeValue()) { + if (this.addAttribute(request, attrs.getCategory(), attr.getAttributeId(), value)) { + this.writeRequest(request); + } + } + } + } + } + } + + /** + * Writes the request into the "requests" sub-directory, relative to the value of the "directory" setup + * during initialization. + * + * Writing the requests out allows one to go back and easily refer to the request when analyzing the responses + * generated after the PDP decide() call. Also, one can then use the generated requests into any test tools + * they wish to build. + * + * @param request - The request to be written. + */ + protected void writeRequest(RequestType request) { + if (logger.isTraceEnabled()) { + logger.trace("writeRequest: " + index); + } + try { + ObjectFactory of = new ObjectFactory(); + JAXBElement requestElement = of.createRequest(request); + JAXBContext context = JAXBContext.newInstance(RequestType.class); + Marshaller m = context.createMarshaller(); + m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); + Path outFile = Paths.get(this.directory, "requests", String.format("Request.%06d.Unknown.xml", this.index)); + m.marshal(requestElement, outFile.toFile()); + } catch (Exception e) { + logger.error("Failed to write request: " + e.getMessage()); + } + this.index++; + } + + protected boolean addAttribute(RequestType request, String category, String id, AttributeValueType value) { + // + // See if the category exists + // + for (AttributesType attrs : request.getAttributes()) { + if (attrs.getCategory().equals(category)) { + // + // It does have the category. But does it have the attribute ID? + // + for (AttributeType attr : attrs.getAttribute()) { + if (attr.getAttributeId().equals(id)) { + // + // Yes, check for the same datatype + // + for (AttributeValueType val : attr.getAttributeValue()) { + if (val.getDataType().equals(value.getDataType())) { + // + // We have something already there + // + return false; + } + } + // + // The ID exists, but not the datatype + // + attr.getAttributeValue().add(value); + return true; + } + } + // + // If we get here, the ID does not exist + // + AttributeType attr = new AttributeType(); + attr.setAttributeId(id); + attr.getAttributeValue().add(value); + attrs.getAttribute().add(attr); + return true; + } + } + // + // If we get here, the category does not exist. So add it in. + // + AttributesType attrs = new AttributesType(); + attrs.setCategory(category); + AttributeType attr = new AttributeType(); + attr.setAttributeId(id); + attr.getAttributeValue().add(value); + attrs.getAttribute().add(attr); + request.getAttributes().add(attrs); + return true; + } + + public static void main(String[] args) { + try { + new TestPolicy(args).run(); + } catch (ParseException | IOException | FactoryException e) { + logger.error(e); + } catch (HelpException e) { + } + } + + /* + // Map>> + @SuppressWarnings("unchecked") + private void generateRequests(Map>>>> categoryMap) { + meta = new ArrayList<>(); + + for (Map.Entry>>>> categoryEntry : categoryMap.entrySet()) { + String category = categoryEntry.getKey().toString(); + logger.debug("Category: " + category); + Map>>> datatypeMap = categoryEntry.getValue(); + for (Map.Entry>>> datatypeEntry : datatypeMap.entrySet()) { + String datatype = datatypeEntry.getKey().toString(); + logger.debug("\tData Type: " + datatype); + Map>> attributeIDMap = datatypeEntry.getValue(); + for (Map.Entry>> attributeIDEntry : attributeIDMap.entrySet()) { + String attributeID = attributeIDEntry.getKey().toString(); + logger.debug("\t\tAttribute ID: " + attributeID); + Set> attributeValueSet = attributeIDEntry.getValue(); + for (AttributeValue value : attributeValueSet) { + logger.debug("\t\t\tAttribute Value: " + value); + } + Iterator> iterator = attributeValueSet.iterator(); + logger.debug("\t\t\t# of Attribute values: " + attributeValueSet.size()); + meta.add(new Object[] {category, datatype, attributeID, iterator.next(), iterator, attributeValueSet}); + } + } + } + + int count = 0; + for (File file : output.toFile().listFiles()) { + file.delete(); + } + + do { + RequestType request = new RequestType(); + request.setCombinedDecision(false); + request.setReturnPolicyIdList(false); + List attributesList = request.getAttributes(); + + Map category2Attribute= new HashMap<>(); + for (int i = 0; i < meta.size(); i++) { + Object[] record = meta.get(i); + + AttributesType attributes = null; + if (category2Attribute.containsKey(record[0].toString())) + attributes = category2Attribute.get(record[0].toString()); + else { + attributes = new AttributesType(); + attributes.setCategory(record[0].toString()); + category2Attribute.put(record[0].toString(), attributes); + attributesList.add(attributes); + } +// attributes.setId(record[2].toString()); + List attrList = attributes.getAttribute(); + + AttributeType attribute = new AttributeType(); + attribute.setAttributeId(record[2].toString()); + List valueList = attribute.getAttributeValue(); + + AttributeValue attributeValue = (AttributeValue) record[3]; + + AttributeValueType value = new AttributeValueType(); + value.setDataType(attributeValue.getDataTypeId().toString()); + List content = value.getContent(); + content.addAll((Collection) attributeValue.getValue()); + valueList.add(value); + + attrList.add(attribute); + } + + try { + ObjectFactory of = new ObjectFactory(); + JAXBElement requestElement = of.createRequest(request); + JAXBContext context = JAXBContext.newInstance(RequestType.class); + Marshaller m = context.createMarshaller(); + m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); + m.marshal(requestElement, output.resolve("request" + count + ".xml").toFile()); + +// if (count == 0) {//Just send the first request to the engine + StringWriter sw = new StringWriter(); + m.marshal(requestElement, sw); + logger.info(sw.toString()); + EngineCaller engine = new LocalEngineCaller(); + if (engine.startEngine("")) { + String response = engine.decide(sw.toString(), "xml"); + FileWriter writer = new FileWriter(output.resolve("response" + count + ".xml").toFile()); + writer.write(response); + writer.close(); + logger.info("Response received: \n" + response); + } +// } + } catch (Exception e) { + e.printStackTrace(); + } + + count++; + } while (hasNextRequest()); + + logger.info("# of requests generated: " + count); + } + + private boolean hasNextRequest() { + int i = meta.size() - 1; + Object[] record = meta.get(i); + + @SuppressWarnings("unchecked") + Iterator> iterator = (Iterator>) record[4]; + if (iterator.hasNext()) { + record[3] = iterator.next(); + } else { + return recycleAttributeValue(i); + } + + return true; + } + + @SuppressWarnings("unchecked") + private boolean recycleAttributeValue(int position) { + boolean rc = true; + + if (position == 0) + return false; + + Object[] record = meta.get(position); + Set> attributeValueSet = (Set>) record[5]; + Iterator> newIt = attributeValueSet.iterator(); + record[4] = newIt; + record[3] = newIt.next(); + int i = position - 1; + Object[] previous = meta.get(i); + Iterator> preIt = (Iterator>) previous[4]; + if (preIt.hasNext()) { + previous[3] = preIt.next(); + } else { + rc = recycleAttributeValue(i); + } + + return rc; + } + + */ + +} + diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/dom/DOMResponseConformanceTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/dom/DOMResponseConformanceTest.java new file mode 100644 index 000000000..e314e1c2b --- /dev/null +++ b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/dom/DOMResponseConformanceTest.java @@ -0,0 +1,196 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-TEST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.std.dom; + +import static org.junit.Assert.fail; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +import com.att.research.xacml.api.Response; +import com.att.research.xacml.std.dom.DOMResponse; + +/** + * Tests for handling the XML version of the XACML Response object. + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * Normally the Response is generated by the PDP and returned through the RESTful interface as JSON. + * Testing of the XML interface is minimal and not complete. + * + * + * + * + */ +public class DOMResponseConformanceTest { + + // where to find the conformance test XML files + private final String CONFORMANCE_DIRECTORY_PATH = "testsets/conformance/xacml3.0-ct-v.0.4"; + + // The request object output from each test conversion from JSON string + Response response; + + + + // Load the Conformance test responses into Response objects, generate the output XML for that Response and compare with the original files. + @Test + public void testDOMResponse() { + List filesInDirectory = null; + + File conformanceDirectory = null; + + File currentFile = null; + + try { + conformanceDirectory = new File(CONFORMANCE_DIRECTORY_PATH); + filesInDirectory = getRequestsInDirectory(conformanceDirectory); + } catch (Exception e) { + fail("Unable to set up Conformance tests for dir '" + conformanceDirectory.getAbsolutePath()+"' e="+ e); + } + + // run through each XML file + // - load the file from XML into an internal Response object + // - generate the XML representation from that Response object + // - reload the file into a String + // - compare the 2 XML strings + Response xmlResponse = null; + try { + for (File f : filesInDirectory) { + currentFile = f; + +//// This is a simple way to select just one file for debugging - comment out when not being used +//if ( ! f.getName().equals("IID302Response.xml")) { continue; } + +// during debugging it is helpful to know what file it is starting to work on +// System.out.println("starting file="+currentFile.getName()); + + + BufferedReader br = new BufferedReader(new FileReader(f)); + StringBuffer sb = new StringBuffer(); + String line; + while ((line = br.readLine()) != null) { + sb.append(line + "\n"); + } + br.close(); + + String xmlFromFile = sb.toString(); + + try { + // load XML into a Response object + xmlResponse = DOMResponse.load(xmlFromFile); + } catch (Exception e) { + // if XML does not load, just note it and continue with next file + System.out.println("XML file did not load: '" + f.getName() + " e=" + e); + continue; + } +//System.out.println(xmlFromFile); + + // create String version from the Response object + String xmlResponseString = DOMResponse.toString(xmlResponse, false); + + // Comparing the string directly to the String from the file is difficult. + // We can minimize the problems with newlines and whitespace, but we have other issues with how various object values are represented. + // For instance, and input double of "23.50" is output as "23.5" which is the same value but not identical strings. + // Therefore we take the XML output and use it to create a new Response object, then compare the two objects. + +//System.out.println(xmlResponseString); + Response reGeneratedResponse = DOMResponse.load(xmlResponseString); + + if ( ! xmlResponse.equals(reGeneratedResponse)) { + String normalizedFromFile = xmlFromFile.replaceAll("\\r|\\n", ""); + normalizedFromFile = normalizedFromFile.replaceAll("\\s+", " "); + normalizedFromFile = normalizedFromFile.replaceAll(">\\s*<", "><"); + System.out.println("File="+normalizedFromFile); + System.out.println("Gend="+ xmlResponseString); + + System.out.println(DOMResponse.toString(xmlResponse, true)); + + fail("Output string did not re-generate eqivilent object."); + } + +// // Normally whitespace is significant in XML. +// // However in this case we are generating an XML string for output and comparing it to a hand-made file. +// // The file may contain extra newlines or fewer spaces then our prettyPrinted output version. +// // Therefore we do the comparison on the un-prettyPrinted generated string. +// // To do this we have to remove the extra whitespace from the version read from the file. +// String normalizedFromFile = xmlFromFile.replaceAll("\\r|\\n", ""); +// normalizedFromFile = normalizedFromFile.replaceAll("\\s+", " "); +// normalizedFromFile = normalizedFromFile.replaceAll(">\\s*<", "><"); +// +// if ( ! xmlResponseString.equals(normalizedFromFile)) { +// System.out.println("file="+normalizedFromFile+"\ngend="+xmlResponseString); +// fail("file not same as generated string: " + f.getName()+ "\nFile="+xmlFromFile + "\nString="+xmlResponseString); +// } + + + } + + } catch (Exception e) { + fail ("Failed test with '" + currentFile.getName() + "', e=" + e); + } + + + } + + + + // + // HELPER to get list of all Request files in the given directory + // + + private List getRequestsInDirectory(File directory) { + List fileList = new ArrayList(); + + File[] fileArray = directory.listFiles(); + for (File f : fileArray) { + if (f.isDirectory()) { + List subDirList = getRequestsInDirectory(f); + fileList.addAll(subDirList); + } + if (f.getName().endsWith("Response.xml")) { + fileList.add(f); + } + } + return fileList; + + } + + +} + + +/* +Place to edit long strings output during tests + + + + + + + + +*/ diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/dom/DOMResponseTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/dom/DOMResponseTest.java new file mode 100644 index 000000000..e4e1e1662 --- /dev/null +++ b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/dom/DOMResponseTest.java @@ -0,0 +1,2316 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-TEST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.std.dom; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import java.text.ParseException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + +import org.junit.Test; + +import com.att.research.xacml.api.Attribute; +import com.att.research.xacml.api.AttributeValue; +import com.att.research.xacml.api.Decision; +import com.att.research.xacml.api.Identifier; +import com.att.research.xacml.api.XACML3; +import com.att.research.xacml.std.IdentifierImpl; +import com.att.research.xacml.std.StdAttribute; +import com.att.research.xacml.std.StdAttributeCategory; +import com.att.research.xacml.std.StdAttributeValue; +import com.att.research.xacml.std.StdIdReference; +import com.att.research.xacml.std.StdMutableAdvice; +import com.att.research.xacml.std.StdMutableAttribute; +import com.att.research.xacml.std.StdMutableAttributeAssignment; +import com.att.research.xacml.std.StdMutableMissingAttributeDetail; +import com.att.research.xacml.std.StdMutableObligation; +import com.att.research.xacml.std.StdMutableResponse; +import com.att.research.xacml.std.StdMutableResult; +import com.att.research.xacml.std.StdMutableStatus; +import com.att.research.xacml.std.StdMutableStatusDetail; +import com.att.research.xacml.std.StdStatusCode; +import com.att.research.xacml.std.StdVersion; +import com.att.research.xacml.std.datatypes.DataTypes; +import com.att.research.xacml.std.datatypes.StringNamespaceContext; +import com.att.research.xacml.std.datatypes.XPathExpressionWrapper; +import com.att.research.xacml.std.dom.DOMResponse; +import com.att.research.xacml.std.dom.DOMStructureException; + +/** + * Test DOM XML Responses + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * This class was copied from the JSON tests. At this time only the first two methods have been revised to work with XML. + * The second method includes multiple instances of all possible fields and has been manually verified. + * The remaining methods have not been converted because: + * - "conversion" consists of replacing the JSON strings with XML + * - the replacement would consist of copying the XML from the JUnit output and doing a String replace + * - there would be little examination of the (long) XML strings, so their validity would be questionable + * so the benefit for the cost of doing that work is not clear. + * + * + */ +public class DOMResponseTest { + + String xmlResponse; + + StdMutableResponse response; + + StdMutableResult result; + + StdMutableStatus status; + + + // Note: Initially test responses without Obligations, Associated Advice, Attributes, or PolicyIdentifier + + + @Test + public void testEmptyAndDecisions() { + // null response + try { + xmlResponse = DOMResponse.toString(null, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + + // empty response (no Result object) + response = new StdMutableResponse(); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + + + // just decision, no status + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Permit", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // just status (empty), no decision + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + result.setStatus(status); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + + // just status (non-empty), no decision + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_OK); + result.setStatus(status); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + + + // test other decisions without Status + + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.DENY); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Deny", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.NOTAPPLICABLE); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("NotApplicable", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Indeterminate", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.INDETERMINATE_DENY); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Indeterminate{D}", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.INDETERMINATE_DENYPERMIT); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Indeterminate{DP}", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.INDETERMINATE_PERMIT); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Indeterminate{P}", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // test Multiple Decisions - success + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + response.add(result); + StdMutableResult result2 = new StdMutableResult(); + result2.setDecision(Decision.DENY); + response.add(result2); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("PermitDeny", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // test Multiple Decisions - one success and one error + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + response.add(result); + result2 = new StdMutableResult(); + result2.setDecision(Decision.INDETERMINATE); + response.add(result2); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("PermitIndeterminate", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + } + + + + + // Test with every field filled in with multiple values where appropriate + @Test + public void testAllFieldsResponse() { + + // fully-loaded multiple response + + StdMutableResponse response = new StdMutableResponse(); + // create a Status object + StdMutableStatus status = new StdMutableStatus(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); + status.setStatusMessage("some status message"); + StdMutableStatusDetail statusDetailIn = new StdMutableStatusDetail(); + StdMutableMissingAttributeDetail mad = new StdMutableMissingAttributeDetail(); + mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_STRING.getId(), "doh")); + mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_INTEGER.getId(), "5432")); + mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_STRING.getId(), "meh")); + mad.setAttributeId(XACML3.ID_ACTION_PURPOSE); + mad.setCategory(XACML3.ID_ATTRIBUTE_CATEGORY_ACTION); + mad.setDataTypeId(XACML3.ID_DATATYPE_STRING); + mad.setIssuer("an Issuer"); + statusDetailIn.addMissingAttributeDetail(mad); + status.setStatusDetail(statusDetailIn); + // create a single result object + StdMutableResult result = new StdMutableResult(status); + // set the decision + result.setDecision(Decision.INDETERMINATE); + // put the Result into the Response + response.add(result); + + + // create a new Result with a different Decision + status = new StdMutableStatus(StdStatusCode.STATUS_CODE_OK); + result = new StdMutableResult(status); + result.setDecision(Decision.DENY); + + StdMutableObligation obligation = new StdMutableObligation(); + obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "obligation-issuer1", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Bart"))); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "obligation-issuer2", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Ned"))); + result.addObligation(obligation); + obligation = new StdMutableObligation(); + obligation.setId(XACML3.ID_SUBJECT_CATEGORY_INTERMEDIARY_SUBJECT); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "obligation-issuer3", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Maggie"))); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "obligation-issuer4", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Homer"))); + result.addObligation(obligation); + + + StdMutableAdvice advice = new StdMutableAdvice(); + advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "advice-issuer1", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu"))); + advice.addAttributeAssignment(new StdMutableAttributeAssignment( + null, + XACML3.ID_SUBJECT, + "advice-issuerNoCategory", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Crusty"))); + result.addAdvice(advice); + + + response.add(result); + + + // create a new Result with a different Decision + // add Child/minor status codes within the main status + StdStatusCode childChildChildStatusCode = new StdStatusCode(new IdentifierImpl("childChildChildStatusCode")); + StdStatusCode childChildStatusCode = new StdStatusCode(new IdentifierImpl("childChildStatusCode"), childChildChildStatusCode); + StdStatusCode child1StatusCode = new StdStatusCode(new IdentifierImpl("child1StatusCode"), childChildStatusCode); + StdStatusCode statusCode = new StdStatusCode(XACML3.ID_STATUS_OK, child1StatusCode); + + status = new StdMutableStatus(statusCode); + + + result = new StdMutableResult(status); + result.setDecision(Decision.PERMIT); + + + + + // add attribute list in result + Identifier categoryIdentifier = new IdentifierImpl("firstCategory"); + Attribute[] attrList = { + new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true), + new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent2"), new StdAttributeValue(DataTypes.DT_YEARMONTHDURATION.getId(), "P10Y4M"), "BIssue", false), + new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent3"), new StdAttributeValue(DataTypes.DT_DOUBLE.getId(), 765.432), "CIssue", true), + new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent4"), new StdAttributeValue(DataTypes.DT_BOOLEAN.getId(), true), "DIssue", true), + new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent5"), new StdAttributeValue(DataTypes.DT_INTEGER.getId(), 4567), "EIssue", true), + new StdAttribute(categoryIdentifier, new IdentifierImpl("attrNoIssuer"), new StdAttributeValue(DataTypes.DT_INTEGER.getId(), 4567), null, true) }; + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, Arrays.asList(attrList))); + categoryIdentifier = new IdentifierImpl("secondCategory"); + Attribute[] secondAttrList = { + new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent12"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu2"), "AIssue2", true), + new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent22"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Abc2"), "BIssue2", false), + new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent32"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Der2"), "CIssue2", true) }; + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, Arrays.asList(secondAttrList))); + + + // add PolicyIdentifierList to result + StdIdReference policyIdentifier1 = null; + StdIdReference policyIdentifier2 = null; + StdIdReference policySetIdentifier1 = null; + StdIdReference policySetIdentifier2 = null; + try { + policyIdentifier1 = new StdIdReference(new IdentifierImpl("idRef1"), StdVersion.newInstance("1.2.3")); + policyIdentifier2 = new StdIdReference(new IdentifierImpl("idRef2_NoVersion")); + policySetIdentifier1 = new StdIdReference(new IdentifierImpl("idSetRef1"), StdVersion.newInstance("4.5.6.7.8.9.0")); + policySetIdentifier2 = new StdIdReference(new IdentifierImpl("idSetRef2_NoVersion")); + } catch (ParseException e1) { + fail("creating policyIds, e="+e1); + } + + result.addPolicyIdentifier(policyIdentifier1); + result.addPolicyIdentifier(policyIdentifier2); + + result.addPolicySetIdentifier(policySetIdentifier1); + result.addPolicySetIdentifier(policySetIdentifier2); + + response.add(result); + + // convert Response to XML + try { + xmlResponse = DOMResponse.toString(response, false); +//System.out.println(xmlResponse); +//System.out.println(DOMResponse.toString(response, true)); + assertEquals("Indeterminatesome status messagedoh5432mehDenyBartNedMaggieHomerApuCrustyPermitApu765.432true45674567Apu2Der2idRef1idRef2_NoVersionidSetRef1idSetRef2_NoVersion", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + } + + + + + // combinations of Status values with Decision values + @Test + public void testDecisionStatusMatch() { + // the tests in this method use different values and do not change structures, so we can re-use the objects + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + result.setStatus(status); + response.add(result); + + // StatusCode = OK + status.setStatusCode(StdStatusCode.STATUS_CODE_OK); + result.setDecision(Decision.PERMIT); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Permit", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + result.setDecision(Decision.DENY); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Deny", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + result.setDecision(Decision.NOTAPPLICABLE); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("NotApplicable", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + result.setDecision(Decision.INDETERMINATE); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + result.setDecision(Decision.INDETERMINATE_DENY); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + result.setDecision(Decision.INDETERMINATE_DENYPERMIT); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + result.setDecision(Decision.INDETERMINATE_PERMIT); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + + + + + + + // StatusCode = SyntaxError + status.setStatusCode(StdStatusCode.STATUS_CODE_SYNTAX_ERROR); + result.setDecision(Decision.PERMIT); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + result.setDecision(Decision.DENY); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + result.setDecision(Decision.NOTAPPLICABLE); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + result.setDecision(Decision.INDETERMINATE); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Indeterminate", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + result.setDecision(Decision.INDETERMINATE_DENY); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Indeterminate{D}", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + result.setDecision(Decision.INDETERMINATE_DENYPERMIT); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Indeterminate{DP}", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + result.setDecision(Decision.INDETERMINATE_PERMIT); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Indeterminate{P}", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // StatusCode = ProcessingError + status.setStatusCode(StdStatusCode.STATUS_CODE_PROCESSING_ERROR); + result.setDecision(Decision.PERMIT); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + result.setDecision(Decision.DENY); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + result.setDecision(Decision.NOTAPPLICABLE); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + result.setDecision(Decision.INDETERMINATE); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Indeterminate", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + result.setDecision(Decision.INDETERMINATE_DENY); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Indeterminate{D}", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + result.setDecision(Decision.INDETERMINATE_DENYPERMIT); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Indeterminate{DP}", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + result.setDecision(Decision.INDETERMINATE_PERMIT); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Indeterminate{P}", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + + // StatusCode = MissingAttribute + status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); + result.setDecision(Decision.PERMIT); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + result.setDecision(Decision.DENY); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + result.setDecision(Decision.NOTAPPLICABLE); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + result.setDecision(Decision.INDETERMINATE); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Indeterminate", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + result.setDecision(Decision.INDETERMINATE_DENY); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Indeterminate{D}", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + result.setDecision(Decision.INDETERMINATE_DENYPERMIT); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Indeterminate{DP}", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + result.setDecision(Decision.INDETERMINATE_PERMIT); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Indeterminate{P}", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + } + + + + + // tests related to Status and its components + @Test + public void testStatus() { + // Status with no StatusCode - error + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + result.setStatus(status); + result.setDecision(Decision.PERMIT); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + + // Status with StatusMessage when OK + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_OK); + status.setStatusMessage("I'm ok, you're ok"); + result.setStatus(status); + result.setDecision(Decision.PERMIT); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("PermitI'm ok, you're ok", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // Status with StatusDetail when OK + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_OK); + StdMutableStatusDetail statusDetail = new StdMutableStatusDetail(); + status.setStatusDetail(statusDetail); + result.setStatus(status); + result.setDecision(Decision.PERMIT); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + + // Status with StatusMessage when SyntaxError + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_SYNTAX_ERROR); + status.setStatusMessage("I'm ok, you're ok"); + result.setStatus(status); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("IndeterminateI'm ok, you're ok", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // Status with empty StatusDetail when SyntaxError + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_SYNTAX_ERROR); + statusDetail = new StdMutableStatusDetail(); + status.setStatusDetail(statusDetail); + result.setStatus(status); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + + + // Status with StatusMessage when ProcessingError + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_PROCESSING_ERROR); + status.setStatusMessage("I'm ok, you're ok"); + result.setStatus(status); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("IndeterminateI'm ok, you're ok", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // Status with empty StatusDetail when ProcessingError + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_PROCESSING_ERROR); + statusDetail = new StdMutableStatusDetail(); + status.setStatusDetail(statusDetail); + result.setStatus(status); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + + + // Status with StatusMessage when MissingAttribute + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); + status.setStatusMessage("I'm ok, you're ok"); + result.setStatus(status); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("IndeterminateI'm ok, you're ok", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // Status with empty StatusDetail when MissingAttribute + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); + statusDetail = new StdMutableStatusDetail(); + status.setStatusDetail(statusDetail); + result.setStatus(status); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Indeterminate", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + + // Status with StatusDetail with empty detail when MissingAttribute + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); + statusDetail = new StdMutableStatusDetail(); + StdMutableMissingAttributeDetail mad = new StdMutableMissingAttributeDetail(); + statusDetail.addMissingAttributeDetail(mad); + status.setStatusDetail(statusDetail); + result.setStatus(status); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + + // Status with StatusDetail with valid detail with no value when MissingAttribute + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); + statusDetail = new StdMutableStatusDetail(); + mad = new StdMutableMissingAttributeDetail(); + mad.setAttributeId(new IdentifierImpl("mad")); + mad.setCategory(XACML3.ID_ACTION); + mad.setDataTypeId(DataTypes.DT_STRING.getId()); + statusDetail.addMissingAttributeDetail(mad); + status.setStatusDetail(statusDetail); + result.setStatus(status); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Indeterminate", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // Status with StatusDetail with valid detail with value when MissingAttribute + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); + statusDetail = new StdMutableStatusDetail(); + mad = new StdMutableMissingAttributeDetail(); + mad.setAttributeId(new IdentifierImpl("mad")); + mad.setCategory(XACML3.ID_ACTION); + mad.setDataTypeId(DataTypes.DT_STRING.getId()); + mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_STRING.getId(), "meh")); + statusDetail.addMissingAttributeDetail(mad); + status.setStatusDetail(statusDetail); + result.setStatus(status); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Indeterminatemeh", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // Status with StatusDetail with array valid detail with value when MissingAttribute + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); + statusDetail = new StdMutableStatusDetail(); + mad = new StdMutableMissingAttributeDetail(); + mad.setAttributeId(new IdentifierImpl("mad")); + mad.setCategory(XACML3.ID_ACTION); + mad.setDataTypeId(DataTypes.DT_STRING.getId()); + mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_STRING.getId(), "meh")); + mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_STRING.getId(), "nu?")); + statusDetail.addMissingAttributeDetail(mad); + status.setStatusDetail(statusDetail); + result.setStatus(status); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Indeterminatemehnu?", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // Status with StatusDetail with valid detail with Integer value when MissingAttribute + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); + statusDetail = new StdMutableStatusDetail(); + mad = new StdMutableMissingAttributeDetail(); + mad.setAttributeId(new IdentifierImpl("mad")); + mad.setCategory(XACML3.ID_ACTION); + mad.setDataTypeId(DataTypes.DT_STRING.getId()); + mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_INTEGER.getId(), 1111)); + statusDetail.addMissingAttributeDetail(mad); + status.setStatusDetail(statusDetail); + result.setStatus(status); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Indeterminate1111", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // Status with StatusDetail with array valid detail with Integer value when MissingAttribute + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); + statusDetail = new StdMutableStatusDetail(); + mad = new StdMutableMissingAttributeDetail(); + mad.setAttributeId(new IdentifierImpl("mad")); + mad.setCategory(XACML3.ID_ACTION); + mad.setDataTypeId(DataTypes.DT_STRING.getId()); + mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_INTEGER.getId(), 1111)); + mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_INTEGER.getId(), 2222)); + statusDetail.addMissingAttributeDetail(mad); + status.setStatusDetail(statusDetail); + result.setStatus(status); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Indeterminate11112222", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + +// StringNamespaceContext snc = new StringNamespaceContext(); +// try { +// snc.add("defaultURI"); +// snc.add("md", "referenceForMD"); +// } catch (Exception e) { +// fail("unable to create NamespaceContext e="+e); +// } +// XPathExpressionWrapper xpathExpressionWrapper = new XPathExpressionWrapper(snc, "//md:record"); +// +//TODO - assume that we will never try to pass back an XPathExpression in a MissingAttributeDetail - it doesn't make sense and is unclear how to put into XML +// // Status with StatusDetail with valid detail with XPathExpression value when MissingAttribute +// response = new StdMutableResponse(); +// result = new StdMutableResult(); +// status = new StdMutableStatus(); +// status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); +// statusDetail = new StdMutableStatusDetail(); +// mad = new StdMutableMissingAttributeDetail(); +// mad.setAttributeId(new IdentifierImpl("mad")); +// mad.setCategory(XACML3.ID_ACTION); +// mad.setDataTypeId(DataTypes.DT_STRING.getId()); +// mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("xpathCategoryId"))); +// statusDetail.addMissingAttributeDetail(mad); +// status.setStatusDetail(statusDetail); +// result.setStatus(status); +// result.setDecision(Decision.INDETERMINATE); +// response.add(result); +// try { +// xmlResponse = DOMResponse.toString(response, false); +// assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"},\"StatusDetail\":\"1111urn:oasis:names:tc:xacml:1.0:actionmadhttp://www.w3.org/2001/XMLSchema#string\"},\"Decision\":\"Indeterminate\"}]}", xmlResponse); +// } catch (Exception e) { +// fail("operation failed, e="+e); +// } +// +// // Status with StatusDetail with array valid detail with XPathExpression value when MissingAttribute +// response = new StdMutableResponse(); +// result = new StdMutableResult(); +// status = new StdMutableStatus(); +// status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); +// statusDetail = new StdMutableStatusDetail(); +// mad = new StdMutableMissingAttributeDetail(); +// mad.setAttributeId(new IdentifierImpl("mad")); +// mad.setCategory(XACML3.ID_ACTION); +// mad.setDataTypeId(DataTypes.DT_STRING.getId()); +// mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("xpathCategoryId1"))); +// mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("xpathCategoryId2"))); +// statusDetail.addMissingAttributeDetail(mad); +// status.setStatusDetail(statusDetail); +// result.setStatus(status); +// result.setDecision(Decision.INDETERMINATE); +// response.add(result); +// try { +// xmlResponse = DOMResponse.toString(response, false); +// assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"},\"StatusDetail\":\"11112222urn:oasis:names:tc:xacml:1.0:actionmadhttp://www.w3.org/2001/XMLSchema#string\"},\"Decision\":\"Indeterminate\"}]}", xmlResponse); +// } catch (Exception e) { +// fail("operation failed, e="+e); +// } + +//TODO - try with other data types, esp XPathExpression + + // Status with StatusDetail with array valid detail with value when SyntaxError + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_SYNTAX_ERROR); + statusDetail = new StdMutableStatusDetail(); + mad = new StdMutableMissingAttributeDetail(); + mad.setAttributeId(new IdentifierImpl("mad")); + mad.setCategory(XACML3.ID_ACTION); + mad.setDataTypeId(DataTypes.DT_STRING.getId()); + mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_STRING.getId(), "meh")); + mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_STRING.getId(), "nu?")); + statusDetail.addMissingAttributeDetail(mad); + status.setStatusDetail(statusDetail); + result.setStatus(status); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + + // Status with StatusDetail with array valid detail with value when ProcessingError + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_PROCESSING_ERROR); + statusDetail = new StdMutableStatusDetail(); + mad = new StdMutableMissingAttributeDetail(); + mad.setAttributeId(new IdentifierImpl("mad")); + mad.setCategory(XACML3.ID_ACTION); + mad.setDataTypeId(DataTypes.DT_STRING.getId()); + mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_STRING.getId(), "meh")); + mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_STRING.getId(), "nu?")); + statusDetail.addMissingAttributeDetail(mad); + status.setStatusDetail(statusDetail); + result.setStatus(status); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + + + + // Status with nested child StatusCodes (child status containing child status containing...) + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + StdStatusCode child1StatusCode = new StdStatusCode(new IdentifierImpl("child1StatusCode")); + StdStatusCode statusCode = new StdStatusCode(XACML3.ID_STATUS_OK, child1StatusCode); + status = new StdMutableStatus(statusCode); + status.setStatusMessage("I'm ok, you're ok"); + result.setStatus(status); + result.setDecision(Decision.PERMIT); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("PermitI'm ok, you're ok", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + StdStatusCode childChildChildStatusCode = new StdStatusCode(new IdentifierImpl("childChildChildStatusCode")); + StdStatusCode childChildStatusCode = new StdStatusCode(new IdentifierImpl("childChildStatusCode"), childChildChildStatusCode); + child1StatusCode = new StdStatusCode(new IdentifierImpl("child1StatusCode"), childChildStatusCode); + statusCode = new StdStatusCode(XACML3.ID_STATUS_OK, child1StatusCode); + status = new StdMutableStatus(statusCode); + status.setStatusMessage("I'm ok, you're ok"); + result.setStatus(status); + result.setDecision(Decision.PERMIT); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("PermitI'm ok, you're ok", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + } + + + + @Test + public void testObligations() { + + // create an XPathExpression for use later + StringNamespaceContext snc = new StringNamespaceContext(); + try { + snc.add("defaultURI"); + snc.add("md", "referenceForMD"); + } catch (Exception e) { + fail("unable to create NamespaceContext e="+e); + } + XPathExpressionWrapper xpathExpressionWrapper = new XPathExpressionWrapper(snc, "//md:record"); + XPathExpressionWrapper xpathExpressionWrapper2 = new XPathExpressionWrapper(snc, "//md:hospital"); + + StdMutableObligation obligation; + + // test Obligation single decision no attributes + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + obligation = new StdMutableObligation(); + obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + result.addObligation(obligation); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Permit", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // obligation missing Id + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + obligation = new StdMutableObligation(); + result.addObligation(obligation); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + + + + // AttributeAssignment - with AttributeId, Value, Category, DataType, Issuer + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + obligation = new StdMutableObligation(); + obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "obligation-issuer1", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Bart"))); + result.addObligation(obligation); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("PermitBart", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // AttributeAssignment - with AttributeId, Value, no Category, DataType, Issuer + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + obligation = new StdMutableObligation(); + obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + null, + XACML3.ID_SUBJECT, + "obligation-issuer1", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Bart"))); + result.addObligation(obligation); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("PermitBart", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // AttributeAssignment - Missing AttributeId + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + obligation = new StdMutableObligation(); + obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + null, + "obligation-issuer1", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Bart"))); + result.addObligation(obligation); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + + // AttributeAssignment - Missing Value + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + obligation = new StdMutableObligation(); + obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "obligation-issuer1", + null)); + result.addObligation(obligation); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + + // AttributeAssignment - missing required DataType (Different than JSON where DataType is optional with default String) + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + obligation = new StdMutableObligation(); + obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "obligation-issuer1", + new StdAttributeValue(null, "Bart"))); + result.addObligation(obligation); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + + // AttributeAssignment - missing issuer + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + obligation = new StdMutableObligation(); + obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + null, + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Bart"))); + result.addObligation(obligation); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("PermitBart", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // AttributeAssignment - Integer type + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + obligation = new StdMutableObligation(); + obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + null, + new StdAttributeValue(DataTypes.DT_INTEGER.getId(), 1111))); + result.addObligation(obligation); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Permit1111", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // AttributeAssignment - XPathExpression type + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + obligation = new StdMutableObligation(); + obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + null, + new StdAttributeValue(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("SimpleXPathCategory")))); + result.addObligation(obligation); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Permit//md:record", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + + + // + // Technically arrays cannot occur in Obligations and Advice elements. The XML spec boils down to the following definition: + // + // value + // value + // : + // may have multiple elements. + // For Obligations and Advice we can simulate an array by having multiple AttributeAssignment elements with the same Category, Id and Issuer. + // + + + // AttributeAssignment - Multiple values with same Category and Id (one way of doing array) + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + obligation = new StdMutableObligation(); + obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "obligation-issuer1", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Bart"))); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "obligation-issuer1", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Lisa"))); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "obligation-issuer1", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Maggie"))); + result.addObligation(obligation); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("PermitBartLisaMaggie", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // AttributeAssignment - Multiple Integer values with same Category and Id (one way of doing array) + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + obligation = new StdMutableObligation(); + obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "obligation-issuer1", + new StdAttributeValue(DataTypes.DT_INTEGER.getId(), 1111))); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "obligation-issuer1", + new StdAttributeValue(DataTypes.DT_INTEGER.getId(), 2222))); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "obligation-issuer1", + new StdAttributeValue(DataTypes.DT_INTEGER.getId(), 3333))); + result.addObligation(obligation); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Permit111122223333", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // Multiple XPathExpression values with same Category and Id (one way of doing array) + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + obligation = new StdMutableObligation(); + obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + null, + new StdAttributeValue(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("SimpleXPathCategory")))); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + null, + new StdAttributeValue(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper2, new IdentifierImpl("SimpleXPathCategory")))); + result.addObligation(obligation); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Permit//md:record//md:hospital", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + } + + + + + @Test + public void testAdvice() { + + // create an XPathExpression for use later + StringNamespaceContext snc = new StringNamespaceContext(); + try { + snc.add("defaultURI"); + snc.add("md", "referenceForMD"); + } catch (Exception e) { + fail("unable to create NamespaceContext e="+e); + } + XPathExpressionWrapper xpathExpressionWrapper = new XPathExpressionWrapper(snc, "//md:record"); + XPathExpressionWrapper xpathExpressionWrapper2 = new XPathExpressionWrapper(snc, "//md:hospital"); + + StdMutableAdvice Advice; + + // test Advice single decision no attributes + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + Advice = new StdMutableAdvice(); + Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + result.addAdvice(Advice); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Permit", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // Advice missing Id + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + Advice = new StdMutableAdvice(); + result.addAdvice(Advice); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + + + + // AttributeAssignment - with AttributeId, Value, Category, DataType, Issuer + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + Advice = new StdMutableAdvice(); + Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "Advice-issuer1", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Bart"))); + result.addAdvice(Advice); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("PermitBart", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // AttributeAssignment - with AttributeId, Value, no Category, DataType, Issuer + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + Advice = new StdMutableAdvice(); + Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + null, + XACML3.ID_SUBJECT, + "Advice-issuer1", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Bart"))); + result.addAdvice(Advice); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("PermitBart", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // AttributeAssignment - Missing AttributeId + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + Advice = new StdMutableAdvice(); + Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + null, + "Advice-issuer1", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Bart"))); + result.addAdvice(Advice); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + + // AttributeAssignment - Missing Value + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + Advice = new StdMutableAdvice(); + Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "Advice-issuer1", + null)); + result.addAdvice(Advice); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + + // AttributeAssignment - missing Required DataType (Different than JSON where DataType is optional with default String) + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + Advice = new StdMutableAdvice(); + Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "Advice-issuer1", + new StdAttributeValue(null, "Bart"))); + result.addAdvice(Advice); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + + // AttributeAssignment - missing issuer + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + Advice = new StdMutableAdvice(); + Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + null, + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Bart"))); + result.addAdvice(Advice); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("PermitBart", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // AttributeAssignment - Integer type + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + Advice = new StdMutableAdvice(); + Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + null, + new StdAttributeValue(DataTypes.DT_INTEGER.getId(), 1111))); + result.addAdvice(Advice); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Permit1111", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // AttributeAssignment - XPathExpression type + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + Advice = new StdMutableAdvice(); + Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + null, + new StdAttributeValue(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("SimpleXPathCategory")))); + result.addAdvice(Advice); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Permit//md:record", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + + + // + // Technically arrays cannot occur in Obligations and Advice elements. The XML spec boils down to the following definition: + // + // value + // value + // : + // may have multiple elements. + // For Obligations and Advice we can simulate an array by having multiple AttributeAssignment elements with the same Category, Id and Issuer. + // + + // AttributeAssignment - Multiple values with same Category and Id (one way of doing array) + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + Advice = new StdMutableAdvice(); + Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "Advice-issuer1", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Bart"))); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "Advice-issuer1", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Lisa"))); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "Advice-issuer1", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Maggie"))); + result.addAdvice(Advice); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("PermitBartLisaMaggie", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // AttributeAssignment - Multiple Integer values with same Category and Id (one way of doing array) + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + Advice = new StdMutableAdvice(); + Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "Advice-issuer1", + new StdAttributeValue(DataTypes.DT_INTEGER.getId(), 1111))); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "Advice-issuer1", + new StdAttributeValue(DataTypes.DT_INTEGER.getId(), 2222))); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "Advice-issuer1", + new StdAttributeValue(DataTypes.DT_INTEGER.getId(), 3333))); + result.addAdvice(Advice); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Permit111122223333", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // Multiple XPathExpression values with same Category and Id (one way of doing array) + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + Advice = new StdMutableAdvice(); + Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + null, + new StdAttributeValue(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("SimpleXPathCategory")))); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + null, + new StdAttributeValue(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper2, new IdentifierImpl("SimpleXPathCategory")))); + result.addAdvice(Advice); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Permit//md:record//md:hospital", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + } + + + + + + + + + + + // Attributes tests + @Test + public void testAttributes() { + + // create an XPathExpression for use later + StringNamespaceContext snc = new StringNamespaceContext(); + try { + snc.add("defaultURI"); + snc.add("md", "referenceForMD"); + } catch (Exception e) { + fail("unable to create NamespaceContext e="+e); + } + XPathExpressionWrapper xpathExpressionWrapper = new XPathExpressionWrapper(snc, "//md:record"); + + + Identifier categoryIdentifier; + List attrList = new ArrayList(); + StdMutableAttribute mutableAttribute; + + // Attr list with no entries + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Permit", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // one Attribute + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true)); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("PermitApu", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // multiple attributes + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent2"), new StdAttributeValue(DataTypes.DT_YEARMONTHDURATION.getId(), "P10Y4M"), "BIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent3"), new StdAttributeValue(DataTypes.DT_DOUBLE.getId(), 765.432), "CIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent4"), new StdAttributeValue(DataTypes.DT_BOOLEAN.getId(), true), "DIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent5"), new StdAttributeValue(DataTypes.DT_INTEGER.getId(), 4567), "EIssue", true)); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("PermitApuP10Y4M765.432true4567", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // IncludeInResult=false/true + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", false)); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Permit", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // Missing AttributeId (mandatory) + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + attrList.add(new StdAttribute(categoryIdentifier, null, new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true)); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + + // Missing mandatory Value + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), null), "AIssue", true)); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + + // Missing optional Issuer + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu"), null, true)); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("PermitApu", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // missing required DataType (different from JSON where DataType is optional and assumed to be String) + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(null, "Apu"), "AIssue", true)); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + + // same id, same type different issuer + // (This is not an array of values because Issuer is different) + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Bart"), "BIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Simpson"), "CIssue", true)); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("PermitApuBartSimpson", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // same id, same type same issuer + // (This is an array of values) + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Bart"), "AIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Simpson"), "AIssue", true)); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("PermitApuBartSimpson", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // same Id, different types, same issuer + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_YEARMONTHDURATION.getId(), "P10Y4M"), "AIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_DOUBLE.getId(), 765.432), "AIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_BOOLEAN.getId(), true), "AIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_INTEGER.getId(), 4567), "AIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_INTEGER.getId(), 4567), "AIssue", true)); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("PermitApuP10Y4M765.432true45674567", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // same Id, different types, different issuer + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_YEARMONTHDURATION.getId(), "P10Y4M"), "BIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_DOUBLE.getId(), 765.432), "CIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_BOOLEAN.getId(), true), "DIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_INTEGER.getId(), 4567), "EIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_INTEGER.getId(), 4567), null, true)); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("PermitApuP10Y4M765.432true45674567", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // different Id, different types, same issuer + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent2"), new StdAttributeValue(DataTypes.DT_YEARMONTHDURATION.getId(), "AIssue"), "BIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent3"), new StdAttributeValue(DataTypes.DT_DOUBLE.getId(), 765.432), "AIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent4"), new StdAttributeValue(DataTypes.DT_BOOLEAN.getId(), true), "AIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent5"), new StdAttributeValue(DataTypes.DT_INTEGER.getId(), 4567), "AIssue", true)); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("PermitApuAIssue765.432true4567", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // one Attribute of type XPathExpression (the only complex data type) + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("xpathCategory")), "AIssue", true)); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Permit//md:record", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // multiple sets of values + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent2"), new StdAttributeValue(DataTypes.DT_YEARMONTHDURATION.getId(), "P10Y4M"), "BIssue", false)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent3"), new StdAttributeValue(DataTypes.DT_DOUBLE.getId(), 765.432), "CIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent4"), new StdAttributeValue(DataTypes.DT_BOOLEAN.getId(), true), "DIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent5"), new StdAttributeValue(DataTypes.DT_INTEGER.getId(), 4567), "EIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrNoIssuer"), new StdAttributeValue(DataTypes.DT_INTEGER.getId(), 4567), null, true)); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + categoryIdentifier = new IdentifierImpl("secondCategory"); + Attribute[] secondAttrList = { + new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent12"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu2"), "AIssue2", true), + new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent22"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Abc2"), "BIssue2", false), + new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent32"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Der2"), "CIssue2", true) }; + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, Arrays.asList(secondAttrList))); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("PermitApu765.432true45674567Apu2Der2", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // array of values - same type + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + attrList.clear(); + categoryIdentifier = new IdentifierImpl("firstCategory"); + mutableAttribute = new StdMutableAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), (Collection>)null, "AIssue", true); + + mutableAttribute.addValue(new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu")); + mutableAttribute.addValue(new StdAttributeValue(DataTypes.DT_STRING.getId(), "Bart")); + mutableAttribute.addValue(new StdAttributeValue(DataTypes.DT_STRING.getId(), "Homer")); + mutableAttribute.addValue(new StdAttributeValue(DataTypes.DT_STRING.getId(), "Ned")); + + attrList.add(mutableAttribute); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("PermitApuBartHomerNed", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // array of values - compatible different types + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + attrList.clear(); + categoryIdentifier = new IdentifierImpl("firstCategory"); + mutableAttribute = new StdMutableAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), (Collection>)null, "AIssue", true); + + mutableAttribute.addValue(new StdAttributeValue(DataTypes.DT_INTEGER.getId(), 4567)); + mutableAttribute.addValue(new StdAttributeValue(DataTypes.DT_DOUBLE.getId(), 765.432)); + mutableAttribute.addValue(new StdAttributeValue(DataTypes.DT_INTEGER.getId(), 4567)); + attrList.add(mutableAttribute); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Permit4567765.4324567", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // array of values - incompatible different types (Different from JSON because these are not part of an array in XML, just separate values) + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + attrList.clear(); + categoryIdentifier = new IdentifierImpl("firstCategory"); + mutableAttribute = new StdMutableAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), (Collection>)null, "AIssue", true); + + mutableAttribute.addValue(new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu")); + mutableAttribute.addValue(new StdAttributeValue(DataTypes.DT_YEARMONTHDURATION.getId(), "P10Y4M")); + mutableAttribute.addValue(new StdAttributeValue(DataTypes.DT_DOUBLE.getId(), 765.432)); + mutableAttribute.addValue(new StdAttributeValue(DataTypes.DT_BOOLEAN.getId(), true)); + mutableAttribute.addValue(new StdAttributeValue(DataTypes.DT_INTEGER.getId(), 4567)); + mutableAttribute.addValue(new StdAttributeValue(DataTypes.DT_INTEGER.getId(), 4567)); + attrList.add(mutableAttribute); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("PermitApuP10Y4M765.432true45674567", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + } + + + + + + // PolicyIdentifier tests + @Test + public void testPolicyIdentifier() { + + StdIdReference policyIdentifier1 = null; + StdIdReference policyIdentifier2 = null; + StdIdReference policySetIdentifier1 = null; + StdIdReference policySetIdentifier2 = null; + + // multiple PolicyIdentifiers of both types + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + try { + policyIdentifier1 = new StdIdReference(new IdentifierImpl("idRef1"), StdVersion.newInstance("1.2.3")); + policyIdentifier2 = new StdIdReference(new IdentifierImpl("idRef2_NoVersion")); + policySetIdentifier1 = new StdIdReference(new IdentifierImpl("idSetRef1"), StdVersion.newInstance("4.5.6.7.8.9.0")); + policySetIdentifier2 = new StdIdReference(new IdentifierImpl("idSetRef2_NoVersion")); + } catch (ParseException e1) { + fail("creating policyIds, e="+e1); + } + result.addPolicyIdentifier(policyIdentifier1); + result.addPolicyIdentifier(policyIdentifier2); + result.addPolicySetIdentifier(policySetIdentifier1); + result.addPolicySetIdentifier(policySetIdentifier2); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("PermitidRef1idRef2_NoVersionidSetRef1idSetRef2_NoVersion", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // PolicyIdentifier exists but has no IdReferences + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + policyIdentifier1 = null; + result.addPolicyIdentifier(policyIdentifier1); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + + // PolicySetIdentifier exists but has not IdReferences + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + policySetIdentifier1 = null; + result.addPolicyIdentifier(policySetIdentifier1); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + + // PolicyIdentifier with PolicyIdReference and no PolicySetIdReference + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + try { + policyIdentifier1 = new StdIdReference(new IdentifierImpl("idRef1"), StdVersion.newInstance("1.2.3")); + } catch (ParseException e1) { + fail("creating policyIds, e="+e1); + } + result.addPolicyIdentifier(policyIdentifier1); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("PermitidRef1", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + + // PolicyIdentifier with no PolicyIdReference and with PolicySetIdReference + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + try { + policySetIdentifier1 = new StdIdReference(new IdentifierImpl("idSetRef1"), StdVersion.newInstance("4.5.6.7.8.9.0")); + } catch (ParseException e1) { + fail("creating policyIds, e="+e1); + } + result.addPolicySetIdentifier(policySetIdentifier1); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("PermitidSetRef1", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // IdReferences without version + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + + policyIdentifier1 = new StdIdReference(new IdentifierImpl("idRef1"), null); + policyIdentifier2 = new StdIdReference(new IdentifierImpl("idRef2_NoVersion")); + policySetIdentifier1 = new StdIdReference(new IdentifierImpl("idSetRef1")); + policySetIdentifier2 = new StdIdReference(new IdentifierImpl("idSetRef2_NoVersion")); + + result.addPolicyIdentifier(policyIdentifier1); + result.addPolicyIdentifier(policyIdentifier2); + result.addPolicySetIdentifier(policySetIdentifier1); + result.addPolicySetIdentifier(policySetIdentifier2); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("PermitidRef1idRef2_NoVersionidSetRef1idSetRef2_NoVersion", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + } + + +//TODO - the XML spec implies that the Result Attributes may include the Content (It is part of the UML) + + + // test indentation??? + + +} + + +/* +Place to edit long strings ouput from tests + + +Expected +Permit +Permit +Actual + + + + */ + + + + + + + + + + + + + diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionAccessPermittedTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionAccessPermittedTest.java new file mode 100644 index 000000000..3e23ebca0 --- /dev/null +++ b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionAccessPermittedTest.java @@ -0,0 +1,522 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-TEST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.std.functions; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import javax.xml.namespace.NamespaceContext; + +import org.junit.Ignore; +import org.junit.Test; + +import com.att.research.xacml.api.Request; +import com.att.research.xacml.api.XACML3; +import com.att.research.xacml.std.StdMutableRequest; +import com.att.research.xacml.std.datatypes.DataTypes; +import com.att.research.xacml.std.dom.DOMRequest; +import com.att.research.xacmlatt.pdp.policy.ExpressionResult; +import com.att.research.xacmlatt.pdp.policy.FunctionArgument; +import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; +import com.att.research.xacmlatt.pdp.std.StdEvaluationContext; +import com.att.research.xacmlatt.pdp.std.StdFunctions; +import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionAccessPermitted; + +/** + * Test of PDP Functions (See XACML core spec section A.3) + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * NOT IMPLEMENTED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * This function is not yet implemented so these tests intentionally fail. + * + * + */ +public class FunctionDefinitionAccessPermittedTest { + + // + // Strings for the Request contents + // + + String reqStrMainStart = "" + + "" + + " " + + " " + + " Julius Hibbert" + + " " + + " " + + " This is IT! " + + " " + + " " + + " This is IT! " + + " " + + ""; + + String reqStrResourceStart = ""; + + String reqStrMdRecordSimpson = + "" + + "" + + "ABC Hospital" + + "Surgery" + + "" + + "" + + "Bart Simpson" + + "60" + + "male" + + "123456" + + "" + + "" + + "" + + "Gastric Cancer" + + "Hyper tension" + + "" + + "" + + "" + + "Well differentiated adeno carcinoma" + + "" + + "2000-10-05" + + "" + + "" + + "" + + " "; + String reqStrContentMdRecordSimpson = "" + reqStrMdRecordSimpson + ""; + String reqStrMalformedContent = + " " + + "" + + "" + + "ABC Hospital" + + "" + + ""; + String reqStrMdRecordSpringer = + "" + + "" + + "XYZ Hospital" + + "Surgery" + + "" + + "" + + "Jerry Springer" + + "65" + + "male" + + "765432" + + "" + + "" + + "" + + "Hyatal Hernia" + + "Diabetes" + + "Neuronal Collapse" + + "" + + "" + + "" + + "We have no idea" + + "" + + "2012-07-22" + + "" + + "" + + "" + + " "; + String reqStrContentMdRecordSpringer = + "" + reqStrMdRecordSpringer + ""; + + String reqStrResourceEnd = " " + + " http://medico.com/record/patient/BartSimpson" + + " " + + " "; + String reqStrActionStart = ""; + + String reqStrActionEnd = "" + + "read" + + "" + + " "; + String reqStrEnvironmentStartEnd = " "; + String reqStrMainEnd = " "; + + + // combined strings for convenience + String reqStrMainResourceStart = reqStrMainStart + reqStrResourceStart; + String reqStrResourceAllEnd = reqStrResourceEnd + reqStrActionStart + reqStrActionEnd + reqStrEnvironmentStartEnd + reqStrMainEnd; + + + /* + * variables useful in the following tests + */ + List arguments = new ArrayList(); + + + + // Name Spaces used in the XML as part of these examples - needed for compiling XPaths + NamespaceContext nameSpaceContext = new NamespaceContext() { + @Override + public Iterator getPrefixes(String arg0) { return null;} + + @Override + public String getPrefix(String arg0) {return null;} + + @Override + public String getNamespaceURI(String arg0) { + if("md".equals(arg0)) { + return "http://www.medico.com/schemas/record"; + } else if ("xacml-context".equals(arg0)) { + return "urn:oasis:names:tc:xacml:3.0:context:schema:os"; + } else if ("xsi".equals(arg0)) { + return "http://www.w3.org/2001/XMLSchema-instance"; + } + return null; + } + }; + + + + // + // URIs for attribute categroies + // + + FunctionArgumentAttributeValue attrUriNull = null; + FunctionArgumentAttributeValue attrUriEmpty = null; + FunctionArgumentAttributeValue attrUriResources = null; + FunctionArgumentAttributeValue attrUriAction = null; + FunctionArgumentAttributeValue attrUriNotInRequest = null; + FunctionArgumentAttributeValue attrUriNotCategory = null; + + + + // + // XML Contents + // + + FunctionArgumentAttributeValue attrXnull = null; + FunctionArgumentAttributeValue attrXEmpty = null; + FunctionArgumentAttributeValue attrXSimpson = null; + FunctionArgumentAttributeValue attrXSpringer = null; + FunctionArgumentAttributeValue attrXContentSimpson = null; + FunctionArgumentAttributeValue attrXContentSpringer = null; + FunctionArgumentAttributeValue attrXBadXML = null; + + + + + + + // + // REQUEST objects available for use in tests + // + Request requestEmpty = new StdMutableRequest(); + Request requestMdRecord = null; + Request requestDoubleResources = null; + Request requestDoubleContent = null; + Request requestResourceActionContent = null; + Request requestContentInAction = null; + + + + + /** + * Set up all variables in one place because it is complicated (lots of steps needed for each attribute) + */ + public FunctionDefinitionAccessPermittedTest() { + try { + + + // create Function Attributes for URIs + attrUriNull = null; + attrUriEmpty = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue("")); + attrUriResources = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue("urn:oasis:names:tc:xacml:3.0:attribute-category:resource")); + attrUriAction = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue("urn:oasis:names:tc:xacml:3.0:attribute-category:action")); + attrUriNotInRequest = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue("NoSuchURI")); + attrUriNotCategory = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue("urn:oasis:names:tc:xacml:1.0:resource:resource-id")); + + // create Function Attributes for XML Strings + attrXnull = new FunctionArgumentAttributeValue(null); + attrXEmpty = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("")); + attrXSimpson = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(reqStrMdRecordSimpson)); + attrXSpringer = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(reqStrMdRecordSpringer)); + attrXContentSimpson = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(reqStrContentMdRecordSimpson)); + attrXContentSpringer = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(reqStrContentMdRecordSpringer)); + attrXBadXML = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(reqStrMalformedContent)); + + + + // Request objects + // to create a Request object the easiest way is to put the xml into a file and use the DOMRequest to load it. + + // single Content in the Resources section (normal valid request) + String reqString = reqStrMainResourceStart + reqStrContentMdRecordSimpson + reqStrResourceAllEnd; + File tFile = File.createTempFile("functionJunit", "request"); + BufferedWriter bw = new BufferedWriter(new FileWriter(tFile)); + bw.append(reqString); + bw.flush(); + bw.close(); + requestMdRecord = DOMRequest.load(tFile); + tFile.delete(); + + // Resources included twice + reqString = reqStrMainResourceStart + reqStrContentMdRecordSimpson + reqStrResourceEnd + reqStrResourceStart + reqStrContentMdRecordSimpson +reqStrResourceAllEnd; + tFile = File.createTempFile("functionJunit", "request"); + bw = new BufferedWriter(new FileWriter(tFile)); + bw.append(reqString); + bw.flush(); + bw.close(); + requestDoubleResources = DOMRequest.load(tFile); + tFile.delete(); + + // Content included twice - error + reqString = reqStrMainResourceStart + reqStrContentMdRecordSimpson + reqStrContentMdRecordSimpson +reqStrResourceAllEnd; + tFile = File.createTempFile("functionJunit", "request"); + bw = new BufferedWriter(new FileWriter(tFile)); + bw.append(reqString); + bw.flush(); + bw.close(); + try { + requestDoubleContent = DOMRequest.load(tFile); + tFile.delete(); + } catch (com.att.research.xacml.std.dom.DOMStructureException e) { + // this is what it should do, so just continue + } catch (Exception e) { + fail("Unexpected exception for bad XML, e="+e); + } + + // content included in both Resource and Action - ok + reqString = reqStrMainResourceStart + reqStrContentMdRecordSimpson + reqStrResourceEnd + reqStrActionStart + reqStrContentMdRecordSimpson + reqStrActionEnd + reqStrMainEnd; + tFile = File.createTempFile("functionJunit", "request"); + bw = new BufferedWriter(new FileWriter(tFile)); + bw.append(reqString); + bw.flush(); + bw.close(); + requestResourceActionContent = DOMRequest.load(tFile); + tFile.delete(); + + // Content included only in Action - missing content produces non-error result according to spec + reqString = reqStrMainResourceStart + reqStrResourceEnd + reqStrActionStart + reqStrContentMdRecordSimpson + reqStrActionEnd + reqStrMainEnd; + tFile = File.createTempFile("functionJunit", "request"); + bw = new BufferedWriter(new FileWriter(tFile)); + bw.append(reqString); + bw.flush(); + bw.close(); + requestContentInAction = DOMRequest.load(tFile); + tFile.delete(); + + + + // Test that Bad XML is caught + @SuppressWarnings("unused") + Request requestContentMisplaced = null; + @SuppressWarnings("unused") + Request requestMalformedContent = null; + + + // Bad XML - Content not under a Category + reqString = reqStrMainStart + reqStrContentMdRecordSimpson + reqStrResourceStart + reqStrResourceEnd + reqStrActionStart + reqStrActionEnd + reqStrMainEnd; + tFile = File.createTempFile("functionJunit", "request"); + bw = new BufferedWriter(new FileWriter(tFile)); + bw.append(reqString); + bw.flush(); + bw.close(); + try { + requestContentMisplaced = DOMRequest.load(tFile); + tFile.delete(); + } catch (com.att.research.xacml.std.dom.DOMStructureException e) { + // this is what it should do, so just continue + } catch (Exception e) { + fail("Unexpected exception for bad XML, e="+e); + } + + // Bad XML - Content is not valid XML + reqString = reqStrMainResourceStart + reqStrMalformedContent + reqStrResourceAllEnd; + tFile = File.createTempFile("functionJunit", "request"); + bw = new BufferedWriter(new FileWriter(tFile)); + bw.append(reqString); + bw.flush(); + bw.close(); + try { + requestMalformedContent = DOMRequest.load(tFile); + tFile.delete(); + } catch (com.att.research.xacml.std.dom.DOMStructureException e) { + // this is what it should do, so just continue + } catch (Exception e) { + fail("Unexpected exception for bad XML, e="+e); + } + + } catch (Exception e) { + fail("Constructor initializing variables, e="+ e + " cause="+e.getCause()); + } + + } + + + + + + + + + @Ignore //@Test + public void testAccess_permitted() { + + ExpressionResult res = null; + Boolean resValue = null; + + FunctionDefinitionAccessPermitted fd = (FunctionDefinitionAccessPermitted) StdFunctions.FD_ACCESS_PERMITTED; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_ACCESS_PERMITTED, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + + + // successful invoke returns true + arguments.clear(); + arguments.add(attrUriResources); + arguments.add(attrXEmpty); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + + + // successful invoke returns false + + + // URI not in Request (ok - evaluate anyway) + + // test for infinite loop + + // second arg ok both with and without tag + arguments.clear(); + arguments.add(attrUriResources); + arguments.add(attrXContentSpringer); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + arguments.clear(); + arguments.add(attrUriResources); + arguments.add(attrXSpringer); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // second arg not valid XML + arguments.clear(); + arguments.add(attrUriResources); + arguments.add(attrXBadXML); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:access-permitted Parsing of XML string failed. Cause='The element type \"md:hospital_info\" must be terminated by the matching end-tag \"\".'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null Evaluation Context + arguments.clear(); + arguments.add(attrUriNotCategory); + arguments.add(attrXContentSimpson); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:access-permitted First argument must be a urn for an attribute-category, not 'urn:oasis:names:tc:xacml:1.0:resource:resource-id", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null Request + arguments.clear(); + arguments.add(attrUriAction); + arguments.add(attrXContentSimpson); + res = fd.evaluate(new StdEvaluationContext(null, null, null), arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:access-permitted Got null Request in EvaluationContext", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // first arg not uri + arguments.clear(); + arguments.add(attrUriNotCategory); + arguments.add(attrXContentSimpson); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:access-permitted First argument must be a urn for an attribute-category, not 'urn:oasis:names:tc:xacml:1.0:resource:resource-id", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // first arg not attribute-category urn + arguments.clear(); + arguments.add(attrXContentSimpson); + arguments.add(attrXContentSimpson); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:access-permitted Expected data type 'anyURI' saw 'string'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // second arg not string + arguments.clear(); + arguments.add(attrUriAction); + arguments.add(attrUriAction); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:access-permitted Expected data type 'string' saw 'anyURI'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // too few args + arguments.clear(); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:access-permitted Expected 2 arguments, got 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + arguments.add(attrXContentSimpson); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:access-permitted Expected 2 arguments, got 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // too many args + arguments.clear(); + arguments.add(attrUriEmpty); + arguments.add(attrXContentSimpson); + arguments.add(attrXContentSimpson); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:access-permitted Expected 2 arguments, got 3", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + } + +} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionArithmeticTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionArithmeticTest.java new file mode 100644 index 000000000..95fcdb2d2 --- /dev/null +++ b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionArithmeticTest.java @@ -0,0 +1,717 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-TEST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.std.functions; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +import com.att.research.xacml.api.XACML3; +import com.att.research.xacml.std.datatypes.DataTypes; +import com.att.research.xacmlatt.pdp.policy.ExpressionResult; +import com.att.research.xacmlatt.pdp.policy.FunctionArgument; +import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; +import com.att.research.xacmlatt.pdp.std.StdFunctions; +import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionArithmetic; + +/** + * Test of PDP Functions (See XACML core spec section A.3) + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * + */ +public class FunctionDefinitionArithmeticTest { + + /* + * variables useful in the following tests + */ + List arguments = new ArrayList(); + + @Test + public void testInteger_add() { + + FunctionArgumentAttributeValue attr1 = null; + FunctionArgumentAttributeValue attr2 = null; + FunctionArgumentAttributeValue attrBadType = null; + try { + attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1)); + attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1)); + attrBadType = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.1)); + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + FunctionDefinitionArithmetic fd = (FunctionDefinitionArithmetic) StdFunctions.FD_INTEGER_ADD; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_INTEGER_ADD, fd.getId()); + assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + + // test normal add + arguments.add(attr1); + arguments.add(attr2); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + BigInteger resValue = (BigInteger)res.getValue().getValue(); + assertEquals(new BigInteger("2"), resValue); + + arguments.clear(); + arguments.add(attr1); + arguments.add(attrBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:integer-add Expected data type 'integer' saw 'double' at arg index 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + @Test + public void testDouble_add() { + + FunctionArgumentAttributeValue attr1 = null; + FunctionArgumentAttributeValue attr2 = null; + + try { + attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.5)); + attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(2.5)); + } catch (Exception e) { + fail("creating attributes e="+e); + } + + FunctionDefinitionArithmetic fd = (FunctionDefinitionArithmetic) StdFunctions.FD_DOUBLE_ADD; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DOUBLE_ADD, fd.getId()); + assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + + // test normal add + arguments.add(attr1); + arguments.add(attr2); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Double resValue = (Double)res.getValue().getValue(); + assertEquals(new Double(4.0), resValue); + + } + + + @Test + public void testInteger_subtract() { + + FunctionArgumentAttributeValue attr1 = null; + FunctionArgumentAttributeValue attr2 = null; + try { + attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(6)); + attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1)); + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + FunctionDefinitionArithmetic fd = (FunctionDefinitionArithmetic) StdFunctions.FD_INTEGER_SUBTRACT; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_INTEGER_SUBTRACT, fd.getId()); + assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + + // test normal + arguments.add(attr1); + arguments.add(attr2); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + BigInteger resValue = (BigInteger)res.getValue().getValue(); + assertEquals(new BigInteger("5"), resValue); + + } + + + @Test + public void testDouble_subtract() { + + FunctionArgumentAttributeValue attr1 = null; + FunctionArgumentAttributeValue attr2 = null; + + try { + attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(8.5)); + attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(2.3)); + } catch (Exception e) { + fail("creating attributes e="+e); + } + + FunctionDefinitionArithmetic fd = (FunctionDefinitionArithmetic) StdFunctions.FD_DOUBLE_SUBTRACT; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DOUBLE_SUBTRACT, fd.getId()); + assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + + // test normal + arguments.add(attr1); + arguments.add(attr2); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Double resValue = (Double)res.getValue().getValue(); + assertEquals(new Double(6.2), resValue); + + } + + + @Test + public void testInteger_multiply() { + + FunctionArgumentAttributeValue attr0 = null; + FunctionArgumentAttributeValue attr1 = null; + FunctionArgumentAttributeValue attr2 = null; + try { + attr0 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(0)); + attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(5)); + attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(2)); + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + FunctionDefinitionArithmetic fd = (FunctionDefinitionArithmetic) StdFunctions.FD_INTEGER_MULTIPLY; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_INTEGER_MULTIPLY, fd.getId()); + assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + + // test normal + arguments.add(attr1); + arguments.add(attr2); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + BigInteger resValue = (BigInteger)res.getValue().getValue(); + assertEquals(new BigInteger("10"), resValue); + + + // test 0 + arguments.clear(); + arguments.add(attr1); + arguments.add(attr0); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (BigInteger)res.getValue().getValue(); + assertEquals(new BigInteger("0"), resValue); + } + + + @Test + public void testDouble_multiply() { + + FunctionArgumentAttributeValue attr0 = null; + FunctionArgumentAttributeValue attr1 = null; + FunctionArgumentAttributeValue attr2 = null; + + try { + attr0 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(0)); + attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.5)); + attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(2.5)); + } catch (Exception e) { + fail("creating attributes e="+e); + } + + FunctionDefinitionArithmetic fd = (FunctionDefinitionArithmetic) StdFunctions.FD_DOUBLE_MULTIPLY; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DOUBLE_MULTIPLY, fd.getId()); + assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + + // test normal add + arguments.add(attr1); + arguments.add(attr2); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Double resValue = (Double)res.getValue().getValue(); + assertEquals(new Double(3.75), resValue); + + // test multiply by 0 + arguments.clear(); + arguments.add(attr1); + arguments.add(attr0); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Double)res.getValue().getValue(); + assertEquals(new Double(0), resValue); + } + + + @Test + public void testInteger_divide() { + + FunctionArgumentAttributeValue attr0 = null; + FunctionArgumentAttributeValue attr1 = null; + FunctionArgumentAttributeValue attr2 = null; + try { + attr0 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(0)); + attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(5)); + attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(2)); + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + FunctionDefinitionArithmetic fd = (FunctionDefinitionArithmetic) StdFunctions.FD_INTEGER_DIVIDE; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_INTEGER_DIVIDE, fd.getId()); + assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + + // test normal + arguments.add(attr1); + arguments.add(attr2); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + BigInteger resValue = (BigInteger)res.getValue().getValue(); + assertEquals(new BigInteger("2"), resValue); + + + // test 0 + arguments.clear(); + arguments.add(attr1); + arguments.add(attr0); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:integer-divide Divide by 0 error: 5, 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + @Test + public void testDouble_divide() { + + FunctionArgumentAttributeValue attr0 = null; + FunctionArgumentAttributeValue attr1 = null; + FunctionArgumentAttributeValue attr2 = null; + + try { + attr0 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(0)); + attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.5)); + attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(2.5)); + + } catch (Exception e) { + fail("creating attributes e="+e); + } + FunctionDefinitionArithmetic fd = (FunctionDefinitionArithmetic) StdFunctions.FD_DOUBLE_DIVIDE; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DOUBLE_DIVIDE, fd.getId()); + assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + + // test normal + arguments.add(attr1); + arguments.add(attr2); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Double resValue = (Double)res.getValue().getValue(); + assertEquals(new Double(0.6), resValue); + + // test multiply by 0 + arguments.clear(); + arguments.add(attr1); + arguments.add(attr0); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:double-divide Divide by 0 error: 1.5, 0.0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + + + + + @Test + public void testInteger_mod() { + + FunctionArgumentAttributeValue attr0 = null; + FunctionArgumentAttributeValue attr1 = null; + FunctionArgumentAttributeValue attr2 = null; + try { + attr0 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(0)); + attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(28)); + attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(5)); + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + FunctionDefinitionArithmetic fd = (FunctionDefinitionArithmetic) StdFunctions.FD_INTEGER_MOD; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_INTEGER_MOD, fd.getId()); + assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + + // test normal + arguments.add(attr1); + arguments.add(attr2); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + BigInteger resValue = (BigInteger)res.getValue().getValue(); + assertEquals(new BigInteger("3"), resValue); + + + // test 0 + arguments.clear(); + arguments.add(attr1); + arguments.add(attr0); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:integer-mod Divide by 0 error: 28, 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + @Test + public void testInteger_abs() { + + FunctionArgumentAttributeValue attr0 = null; + FunctionArgumentAttributeValue attr1 = null; + FunctionArgumentAttributeValue attrM1 = null; + try { + attr0 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(0)); + attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(5)); + attrM1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(-7)); + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + FunctionDefinitionArithmetic fd = (FunctionDefinitionArithmetic) StdFunctions.FD_INTEGER_ABS; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_INTEGER_ABS, fd.getId()); + assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + + // test normal + arguments.add(attr1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + BigInteger resValue = (BigInteger)res.getValue().getValue(); + assertEquals(new BigInteger("5"), resValue); + + arguments.clear(); + arguments.add(attrM1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (BigInteger)res.getValue().getValue(); + assertEquals(new BigInteger("7"), resValue); + + arguments.clear(); + arguments.add(attr0); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (BigInteger)res.getValue().getValue(); + assertEquals(new BigInteger("0"), resValue); + } + + + @Test + public void testDouble_abs() { + + FunctionArgumentAttributeValue attr0 = null; + FunctionArgumentAttributeValue attr1 = null; + FunctionArgumentAttributeValue attr2 = null; + + try { + attr0 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(0)); + attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.5)); + attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(-2.5)); + + } catch (Exception e) { + fail("creating attributes e="+e); + } + + FunctionDefinitionArithmetic fd = (FunctionDefinitionArithmetic) StdFunctions.FD_DOUBLE_ABS; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DOUBLE_ABS, fd.getId()); + assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + + // test normal + arguments.add(attr1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Double resValue = (Double)res.getValue().getValue(); + assertEquals(new Double(1.5), resValue); + + arguments.clear(); + arguments.add(attr2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Double)res.getValue().getValue(); + assertEquals(new Double(2.5), resValue); + + arguments.clear(); + arguments.add(attr0); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Double)res.getValue().getValue(); + assertEquals(new Double(0), resValue); + + } + + + @Test + public void testDouble_round() { + + FunctionArgumentAttributeValue attr0 = null; + FunctionArgumentAttributeValue attr1 = null; + FunctionArgumentAttributeValue attr2 = null; + FunctionArgumentAttributeValue attr3 = null; + FunctionArgumentAttributeValue attr4 = null; + FunctionArgumentAttributeValue attr5 = null; + FunctionArgumentAttributeValue attr6 = null; + try { + attr0 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(0)); + attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.5)); + attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.49)); + attr3 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.51)); + attr4 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(-2.5)); + attr5 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(-2.49)); + attr6 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(-2.51)); + } catch (Exception e) { + fail("creating attributes e="+e); + } + + + + FunctionDefinitionArithmetic fd = (FunctionDefinitionArithmetic) StdFunctions.FD_ROUND; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_ROUND, fd.getId()); + assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + + // test normal + arguments.add(attr0); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Double resValue = (Double)res.getValue().getValue(); + assertEquals(new Double(0), resValue); + + arguments.clear(); + arguments.add(attr1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Double)res.getValue().getValue(); + assertEquals(new Double(2), resValue); + + arguments.clear(); + arguments.add(attr2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Double)res.getValue().getValue(); + assertEquals(new Double(1), resValue); + + arguments.clear(); + arguments.add(attr3); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Double)res.getValue().getValue(); + assertEquals(new Double(2), resValue); + + arguments.clear(); + arguments.add(attr4); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Double)res.getValue().getValue(); + assertEquals(new Double(-2), resValue); + + arguments.clear(); + arguments.add(attr5); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Double)res.getValue().getValue(); + assertEquals(new Double(-2), resValue); + + arguments.clear(); + arguments.add(attr6); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Double)res.getValue().getValue(); + assertEquals(new Double(-3), resValue); + } + + + @Test + public void testDouble_floor() { + FunctionArgumentAttributeValue attr0 = null; + FunctionArgumentAttributeValue attr1 = null; + FunctionArgumentAttributeValue attr2 = null; + FunctionArgumentAttributeValue attr3 = null; + FunctionArgumentAttributeValue attr4 = null; + FunctionArgumentAttributeValue attr5 = null; + FunctionArgumentAttributeValue attr6 = null; + try { + attr0 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(0)); + attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.5)); + attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.49)); + attr3 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.51)); + attr4 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(-2.5)); + attr5 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(-2.49)); + attr6 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(-2.51)); + } catch (Exception e) { + fail("creating attributes e="+e); + } + + FunctionDefinitionArithmetic fd = (FunctionDefinitionArithmetic) StdFunctions.FD_FLOOR; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_FLOOR, fd.getId()); + assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + + // test normal + arguments.add(attr0); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Double resValue = (Double)res.getValue().getValue(); + assertEquals(new Double(0), resValue); + + arguments.clear(); + arguments.add(attr1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Double)res.getValue().getValue(); + assertEquals(new Double(1), resValue); + + arguments.clear(); + arguments.add(attr2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Double)res.getValue().getValue(); + assertEquals(new Double(1), resValue); + + arguments.clear(); + arguments.add(attr3); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Double)res.getValue().getValue(); + assertEquals(new Double(1), resValue); + + arguments.clear(); + arguments.add(attr4); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Double)res.getValue().getValue(); + assertEquals(new Double(-3), resValue); + + arguments.clear(); + arguments.add(attr5); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Double)res.getValue().getValue(); + assertEquals(new Double(-3), resValue); + + arguments.clear(); + arguments.add(attr6); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Double)res.getValue().getValue(); + assertEquals(new Double(-3), resValue); + } + +} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionBagIsInTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionBagIsInTest.java new file mode 100644 index 000000000..f783254a9 --- /dev/null +++ b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionBagIsInTest.java @@ -0,0 +1,221 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-TEST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.std.functions; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +import com.att.research.xacml.api.XACML3; +import com.att.research.xacml.std.StdAttributeValue; +import com.att.research.xacml.std.datatypes.DataTypes; +import com.att.research.xacmlatt.pdp.policy.Bag; +import com.att.research.xacmlatt.pdp.policy.ExpressionResult; +import com.att.research.xacmlatt.pdp.policy.FunctionArgument; +import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; +import com.att.research.xacmlatt.pdp.policy.FunctionArgumentBag; +import com.att.research.xacmlatt.pdp.std.StdFunctions; +import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionBagIsIn; + +/** + * Test of PDP Functions (See XACML core spec section A.3) + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * + */ +public class FunctionDefinitionBagIsInTest { + + + /* + * variables useful in the following tests + */ + List arguments = new ArrayList(); + + + @Test + public void testString() { + String v1 = new String("abc"); + String v2 = new String("def"); + String notInBag = new String("lmnop"); + String sameValueV1 = new String("abc"); + Integer vOtherType = new Integer(11); + + + FunctionArgumentAttributeValue attrV1 = null; + FunctionArgumentAttributeValue attrV2 = null; + FunctionArgumentAttributeValue attrNotInBag = null; + FunctionArgumentAttributeValue attrSameValueV1 = null; + FunctionArgumentAttributeValue attrOtherType = null; + try { + attrV1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(v1)); + attrV2 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(v2)); + attrNotInBag = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(notInBag)); + attrSameValueV1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(sameValueV1)); + attrOtherType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(vOtherType)); + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + Bag bag0 = new Bag(); + Bag bag1 = new Bag(); + bag1.add(new StdAttributeValue(DataTypes.DT_STRING.getId(), v1)); + Bag bag2 = new Bag(); + bag2.add(new StdAttributeValue(DataTypes.DT_STRING.getId(), v1)); + bag2.add(new StdAttributeValue(DataTypes.DT_STRING.getId(), v2));; + + + + FunctionArgumentBag attrBag0 = new FunctionArgumentBag(bag0); + FunctionArgumentBag attrBag1 = new FunctionArgumentBag(bag1); + FunctionArgumentBag attrBag2 = new FunctionArgumentBag(bag2); + + + + FunctionDefinitionBagIsIn fd = (FunctionDefinitionBagIsIn) StdFunctions.FD_STRING_IS_IN; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_IS_IN, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + + // element is in bag + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrBag2); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertEquals(true, resValue); + + // element not in bag + arguments.clear(); + arguments.add(attrNotInBag); + arguments.add(attrBag2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // different element with the same value is in bag + arguments.clear(); + arguments.add(attrSameValueV1); + arguments.add(attrBag2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(true, resValue); + + // empty bag + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrBag0); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // missing arg + arguments.clear(); + arguments.add(attrSameValueV1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-is-in Expected 2 arguments, got 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // 1st arg is bag + arguments.clear(); + arguments.add(attrBag1); + arguments.add(attrBag2); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-is-in Expected a simple value, saw a bag", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // 2nd arg not bag + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrV2); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-is-in Expected a bag, saw a simple value", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // first arg null + arguments.clear(); + arguments.add(null); + arguments.add(attrBag2); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-is-in Got null argument", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // 2nd arg null + arguments.clear(); + arguments.add(attrV1); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-is-in Got null argument", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // first arg type does not match bag elements + arguments.clear(); + arguments.add(attrOtherType); + arguments.add(attrBag2); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-is-in Expected data type 'string' saw 'integer'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bag has mixed element types +// behavior not specified for this case in spec. It ASSUMES that all elements in bag are same type. + + } + + + + + // + // + // REST OF DATA TYPES OMITTED + // because they "should" all work the same + // + // + + + + +} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionBagOneAndOnlyTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionBagOneAndOnlyTest.java new file mode 100644 index 000000000..42a0aed75 --- /dev/null +++ b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionBagOneAndOnlyTest.java @@ -0,0 +1,224 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-TEST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.std.functions; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.List; +import java.math.BigInteger; + +import org.junit.Test; + +import com.att.research.xacml.api.XACML3; +import com.att.research.xacml.std.StdAttributeValue; +import com.att.research.xacml.std.datatypes.DataTypes; +import com.att.research.xacmlatt.pdp.policy.Bag; +import com.att.research.xacmlatt.pdp.policy.ExpressionResult; +import com.att.research.xacmlatt.pdp.policy.FunctionArgument; +import com.att.research.xacmlatt.pdp.policy.FunctionArgumentBag; +import com.att.research.xacmlatt.pdp.std.StdFunctions; +import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionBagOneAndOnly; + +/** + * Test of PDP Functions (See XACML core spec section A.3) + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * + */ +public class FunctionDefinitionBagOneAndOnlyTest { + + + /* + * variables useful in the following tests + */ + List arguments = new ArrayList(); + + + @Test + public void testString() { + String v1 = new String("abc"); + String v2 = new String("def"); + BigInteger vOtherType = BigInteger.valueOf(11); + + Bag bag0 = new Bag(); + Bag bag1 = new Bag(); + bag1.add(new StdAttributeValue(DataTypes.DT_STRING.getId(), v1)); + Bag bag2 = new Bag(); + bag2.add(new StdAttributeValue(DataTypes.DT_STRING.getId(), v1)); + bag2.add(new StdAttributeValue(DataTypes.DT_STRING.getId(), v2)); + Bag bagOtherType = new Bag(); + bagOtherType.add(new StdAttributeValue(DataTypes.DT_INTEGER.getId(), vOtherType)); + + FunctionArgumentBag attrBag0 = new FunctionArgumentBag(bag0); + FunctionArgumentBag attrBag1 = new FunctionArgumentBag(bag1); + FunctionArgumentBag attrBag2 = new FunctionArgumentBag(bag2); + FunctionArgumentBag attrBagOtherType = new FunctionArgumentBag(bagOtherType); + + + FunctionDefinitionBagOneAndOnly fd = (FunctionDefinitionBagOneAndOnly) StdFunctions.FD_STRING_ONE_AND_ONLY; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_ONE_AND_ONLY, fd.getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + + + + // bag with only one + arguments.clear(); + arguments.add(attrBag1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.String.class, res.getValue().getValue().getClass()); + String resValue = (String)res.getValue().getValue(); + assertEquals(v1, resValue); + + // null bag + arguments.clear(); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-one-and-only Got null argument", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bag with exactly one but of other type in it + arguments.clear(); + arguments.add(attrBagOtherType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-one-and-only Element in bag of wrong type. Expected string got integer", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bag with none + arguments.clear(); + arguments.add(attrBag0); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-one-and-only Expected 1 but Bag has 0 elements", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bag with multiple + arguments.clear(); + arguments.add(attrBag2); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-one-and-only Expected 1 but Bag has 2 elements", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + + + @Test + public void testBoolean() { + Boolean v1 = new Boolean(true); + Boolean v2 = new Boolean(false); + BigInteger vOtherType = BigInteger.valueOf(11); + + Bag bag0 = new Bag(); + Bag bag1 = new Bag(); + bag1.add(new StdAttributeValue(DataTypes.DT_BOOLEAN.getId(), v1)); + Bag bag2 = new Bag(); + bag2.add(new StdAttributeValue(DataTypes.DT_BOOLEAN.getId(), v1)); + bag2.add(new StdAttributeValue(DataTypes.DT_BOOLEAN.getId(), v2)); + Bag bagOtherType = new Bag(); + bagOtherType.add(new StdAttributeValue(DataTypes.DT_STRING.getId(), vOtherType)); + + + FunctionArgumentBag attrBag0 = new FunctionArgumentBag(bag0); + FunctionArgumentBag attrBag1 = new FunctionArgumentBag(bag1); + FunctionArgumentBag attrBag2 = new FunctionArgumentBag(bag2); + FunctionArgumentBag attrBagOtherType = new FunctionArgumentBag(bagOtherType); + + + FunctionDefinitionBagOneAndOnly fd = (FunctionDefinitionBagOneAndOnly) StdFunctions.FD_BOOLEAN_ONE_AND_ONLY; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_BOOLEAN_ONE_AND_ONLY, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + + + + // bag with only one + arguments.clear(); + arguments.add(attrBag1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertEquals(new Boolean(true), resValue); + + // null bag + arguments.clear(); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:boolean-one-and-only Got null argument", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bag with exactly one but of other type in it + arguments.clear(); + arguments.add(attrBagOtherType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:boolean-one-and-only Element in bag of wrong type. Expected boolean got string", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bag with none + arguments.clear(); + arguments.add(attrBag0); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:boolean-one-and-only Expected 1 but Bag has 0 elements", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bag with multiple + arguments.clear(); + arguments.add(attrBag2); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:boolean-one-and-only Expected 1 but Bag has 2 elements", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + + // + // + // REST OF DATA TYPES OMITTED + // because they "should" all work the same + // + // + + + + +} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionBagSizeTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionBagSizeTest.java new file mode 100644 index 000000000..cd08234f5 --- /dev/null +++ b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionBagSizeTest.java @@ -0,0 +1,158 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-TEST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.std.functions; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +import com.att.research.xacml.api.XACML3; +import com.att.research.xacml.std.StdAttributeValue; +import com.att.research.xacml.std.datatypes.DataTypes; +import com.att.research.xacmlatt.pdp.policy.Bag; +import com.att.research.xacmlatt.pdp.policy.ExpressionResult; +import com.att.research.xacmlatt.pdp.policy.FunctionArgument; +import com.att.research.xacmlatt.pdp.policy.FunctionArgumentBag; +import com.att.research.xacmlatt.pdp.std.StdFunctions; +import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionBagSize; + +/** + * Test of PDP Functions (See XACML core spec section A.3) + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * + */ +public class FunctionDefinitionBagSizeTest { + + + /* + * variables useful in the following tests + */ + List arguments = new ArrayList(); + + + @Test + public void testString() { + String v1 = new String("abc"); + String v2 = new String("def"); + Integer vOtherType = new Integer(11); + + + + Bag bag0 = new Bag(); + Bag bag1 = new Bag(); + bag1.add(new StdAttributeValue(DataTypes.DT_STRING.getId(), v1)); + Bag bag2 = new Bag(); + bag2.add(new StdAttributeValue(DataTypes.DT_STRING.getId(), v1)); + bag2.add(new StdAttributeValue(DataTypes.DT_STRING.getId(), v2)); + Bag bagOtherType = new Bag(); + bagOtherType.add(new StdAttributeValue(DataTypes.DT_INTEGER.getId(), vOtherType)); + + + FunctionArgumentBag attrBag0 = new FunctionArgumentBag(bag0); + FunctionArgumentBag attrBag1 = new FunctionArgumentBag(bag1); + FunctionArgumentBag attrBag2 = new FunctionArgumentBag(bag2); + FunctionArgumentBag attrBagOtherType = new FunctionArgumentBag(bagOtherType); + + + FunctionDefinitionBagSize fd = (FunctionDefinitionBagSize) StdFunctions.FD_STRING_BAG_SIZE; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_BAG_SIZE, fd.getId()); + assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + + + + // bag with only one + arguments.clear(); + arguments.add(attrBag1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.math.BigInteger.class, res.getValue().getValue().getClass()); + BigInteger resValue = (BigInteger)res.getValue().getValue(); + assertEquals(BigInteger.valueOf(1), resValue); + + // null bag + arguments.clear(); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-bag-size Got null argument", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bag with exactly one but of other type in it + arguments.clear(); + arguments.add(attrBagOtherType); + res = fd.evaluate(null, arguments); + // NOTE: Size does not care about content type! + assertTrue(res.isOk()); + assertEquals(java.math.BigInteger.class, res.getValue().getValue().getClass()); + resValue = (BigInteger)res.getValue().getValue(); + assertEquals(BigInteger.valueOf(1), resValue); + + // bag with none + arguments.clear(); + arguments.add(attrBag0); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.math.BigInteger.class, res.getValue().getValue().getClass()); + resValue = (BigInteger)res.getValue().getValue(); + assertEquals(BigInteger.valueOf(0), resValue); + + // bag with multiple + arguments.clear(); + arguments.add(attrBag2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.math.BigInteger.class, res.getValue().getValue().getClass()); + resValue = (BigInteger)res.getValue().getValue(); + assertEquals(BigInteger.valueOf(2), resValue); + } + + + + + + + + // + // + // REST OF DATA TYPES OMITTED + // because they "should" all work the same + // + // + + + + +} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionBagTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionBagTest.java new file mode 100644 index 000000000..925a09851 --- /dev/null +++ b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionBagTest.java @@ -0,0 +1,547 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-TEST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.std.functions; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.junit.Test; + +import com.att.research.xacml.api.AttributeValue; +import com.att.research.xacml.api.XACML3; +import com.att.research.xacml.std.datatypes.DataTypes; +import com.att.research.xacmlatt.pdp.policy.Bag; +import com.att.research.xacmlatt.pdp.policy.ExpressionResult; +import com.att.research.xacmlatt.pdp.policy.FunctionArgument; +import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; +import com.att.research.xacmlatt.pdp.std.StdFunctions; +import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionBag; + +/** + * Test of PDP Functions (See XACML core spec section A.3) + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * + */ +public class FunctionDefinitionBagTest { + + + /* + * variables useful in the following tests + */ + List arguments = new ArrayList(); + + + FunctionArgumentAttributeValue attrInteger = null; + FunctionArgumentAttributeValue attrString = null; + + public FunctionDefinitionBagTest() { + try { + attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1111111111)); + attrString = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("a string value")); + } catch (Exception e) { + fail("creating attributes e="+e); + } + } + + @Test + public void testString() { + + String s1 = "abc"; + String s2 = "def"; + FunctionArgumentAttributeValue attr1 = null; + FunctionArgumentAttributeValue attr2 = null; + try { + attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(s1)); + attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(s2)); + } catch (Exception e) { + fail("creating attributes e="+e); + } + + FunctionDefinitionBag fd = (FunctionDefinitionBag) StdFunctions.FD_STRING_BAG; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_BAG, fd.getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertTrue(fd.returnsBag()); + + // bag with only one + arguments.clear(); + arguments.add(attr1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Bag bag = res.getBag(); + assertNotNull(bag); + Iterator> it = bag.getAttributeValues(); + assertEquals(1, bag.size()); + AttributeValue attrValueObject = it.next(); + assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); + assertEquals(s1, attrValueObject.getValue()); + + // zero args => empty bag + arguments.clear(); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + assertEquals(0, bag.size()); + + + // null argument + arguments.clear(); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-bag Got null argument", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // argument of other type + arguments.clear(); + arguments.add(attrInteger); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-bag Expected data type 'string' saw 'integer'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // 2 args (check response is correct) + arguments.clear(); + arguments.add(attr1); + arguments.add(attr2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(2, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); + assertEquals(s1, attrValueObject.getValue()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); + assertEquals(s2, attrValueObject.getValue()); + + // duplicate args (verify return) + arguments.clear(); + arguments.add(attr1); + arguments.add(attr2); + arguments.add(attr1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(3, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); + assertEquals(s1, attrValueObject.getValue()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); + assertEquals(s2, attrValueObject.getValue()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); + assertEquals(s1, attrValueObject.getValue()); + + // lots of args + arguments.clear(); + for (int i = 0; i < 1000; i++) { + arguments.add(attr1); + } + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(1000, bag.size()); + + } + + + @Test + public void testBoolean() { + + Boolean s1 = true; + Boolean s2 = false; + FunctionArgumentAttributeValue attr1 = null; + FunctionArgumentAttributeValue attr2 = null; + try { + attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_BOOLEAN.createAttributeValue(s1)); + attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_BOOLEAN.createAttributeValue(s2)); + } catch (Exception e) { + fail("creating attributes e="+e); + } + + FunctionDefinitionBag fd = (FunctionDefinitionBag) StdFunctions.FD_BOOLEAN_BAG; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_BOOLEAN_BAG, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertTrue(fd.returnsBag()); + + // bag with only one + arguments.clear(); + arguments.add(attr1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Bag bag = res.getBag(); + assertNotNull(bag); + Iterator> it = bag.getAttributeValues(); + assertEquals(1, bag.size()); + AttributeValue attrValueObject = it.next(); + assertEquals(DataTypes.DT_BOOLEAN.getId(), attrValueObject.getDataTypeId()); + assertEquals(s1, attrValueObject.getValue()); + + // zero args => empty bag + arguments.clear(); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + assertEquals(0, bag.size()); + + + // null argument + arguments.clear(); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:boolean-bag Got null argument", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // argument of other type + arguments.clear(); + arguments.add(attrInteger); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:boolean-bag Expected data type 'boolean' saw 'integer'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // 2 args (check response is correct) + arguments.clear(); + arguments.add(attr1); + arguments.add(attr2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(2, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_BOOLEAN.getId(), attrValueObject.getDataTypeId()); + assertEquals(s1, attrValueObject.getValue()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_BOOLEAN.getId(), attrValueObject.getDataTypeId()); + assertEquals(s2, attrValueObject.getValue()); + + // duplicate args (verify return) + arguments.clear(); + arguments.add(attr1); + arguments.add(attr2); + arguments.add(attr1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(3, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_BOOLEAN.getId(), attrValueObject.getDataTypeId()); + assertEquals(s1, attrValueObject.getValue()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_BOOLEAN.getId(), attrValueObject.getDataTypeId()); + assertEquals(s2, attrValueObject.getValue()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_BOOLEAN.getId(), attrValueObject.getDataTypeId()); + assertEquals(s1, attrValueObject.getValue()); + + // lots of args + arguments.clear(); + for (int i = 0; i < 1000; i++) { + arguments.add(attr1); + } + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(1000, bag.size()); + + } + + + + @Test + public void testInteger() { + + BigInteger s1 = new BigInteger("123"); + BigInteger s2 = new BigInteger("456"); + FunctionArgumentAttributeValue attr1 = null; + FunctionArgumentAttributeValue attr2 = null; + try { + attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(s1)); + attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(s2)); + } catch (Exception e) { + fail("creating attributes e="+e); + } + + FunctionDefinitionBag fd = (FunctionDefinitionBag) StdFunctions.FD_INTEGER_BAG; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_INTEGER_BAG, fd.getId()); + assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertTrue(fd.returnsBag()); + + // bag with only one + arguments.clear(); + arguments.add(attr1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Bag bag = res.getBag(); + assertNotNull(bag); + Iterator> it = bag.getAttributeValues(); + assertEquals(1, bag.size()); + AttributeValue attrValueObject = it.next(); + assertEquals(DataTypes.DT_INTEGER.getId(), attrValueObject.getDataTypeId()); + assertEquals(s1, attrValueObject.getValue()); + + // zero args => empty bag + arguments.clear(); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + assertEquals(0, bag.size()); + + + // null argument + arguments.clear(); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:integer-bag Got null argument", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // argument of other type + arguments.clear(); + arguments.add(attrString); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:integer-bag Expected data type 'integer' saw 'string'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // 2 args (check response is correct) + arguments.clear(); + arguments.add(attr1); + arguments.add(attr2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(2, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_INTEGER.getId(), attrValueObject.getDataTypeId()); + assertEquals(s1, attrValueObject.getValue()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_INTEGER.getId(), attrValueObject.getDataTypeId()); + assertEquals(s2, attrValueObject.getValue()); + + // duplicate args (verify return) + arguments.clear(); + arguments.add(attr1); + arguments.add(attr2); + arguments.add(attr1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(3, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_INTEGER.getId(), attrValueObject.getDataTypeId()); + assertEquals(s1, attrValueObject.getValue()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_INTEGER.getId(), attrValueObject.getDataTypeId()); + assertEquals(s2, attrValueObject.getValue()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_INTEGER.getId(), attrValueObject.getDataTypeId()); + assertEquals(s1, attrValueObject.getValue()); + + // lots of args + arguments.clear(); + for (int i = 0; i < 1000; i++) { + arguments.add(attr1); + } + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(1000, bag.size()); + + } + + + + + @Test + public void testDouble() { + + Double s1 = 123.45; + Double s2 = 678.901; + FunctionArgumentAttributeValue attr1 = null; + FunctionArgumentAttributeValue attr2 = null; + try { + attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(s1)); + attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(s2)); + } catch (Exception e) { + fail("creating attributes e="+e); + } + + FunctionDefinitionBag fd = (FunctionDefinitionBag) StdFunctions.FD_DOUBLE_BAG; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DOUBLE_BAG, fd.getId()); + assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertTrue(fd.returnsBag()); + + // bag with only one + arguments.clear(); + arguments.add(attr1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Bag bag = res.getBag(); + assertNotNull(bag); + Iterator> it = bag.getAttributeValues(); + assertEquals(1, bag.size()); + AttributeValue attrValueObject = it.next(); + assertEquals(DataTypes.DT_DOUBLE.getId(), attrValueObject.getDataTypeId()); + assertEquals(s1, attrValueObject.getValue()); + + // zero args => empty bag + arguments.clear(); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + assertEquals(0, bag.size()); + + + // null argument + arguments.clear(); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:double-bag Got null argument", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // argument of other type + arguments.clear(); + arguments.add(attrInteger); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:double-bag Expected data type 'double' saw 'integer'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // 2 args (check response is correct) + arguments.clear(); + arguments.add(attr1); + arguments.add(attr2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(2, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_DOUBLE.getId(), attrValueObject.getDataTypeId()); + assertEquals(s1, attrValueObject.getValue()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_DOUBLE.getId(), attrValueObject.getDataTypeId()); + assertEquals(s2, attrValueObject.getValue()); + + // duplicate args (verify return) + arguments.clear(); + arguments.add(attr1); + arguments.add(attr2); + arguments.add(attr1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(3, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_DOUBLE.getId(), attrValueObject.getDataTypeId()); + assertEquals(s1, attrValueObject.getValue()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_DOUBLE.getId(), attrValueObject.getDataTypeId()); + assertEquals(s2, attrValueObject.getValue()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_DOUBLE.getId(), attrValueObject.getDataTypeId()); + assertEquals(s1, attrValueObject.getValue()); + + // lots of args + arguments.clear(); + for (int i = 0; i < 1000; i++) { + arguments.add(attr1); + } + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(1000, bag.size()); + + } + + + + + + // + // + // REST OF DATA TYPES OMITTED + // because they "should" all work the same + // + // + + + + +} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionBaseTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionBaseTest.java new file mode 100644 index 000000000..64881758e --- /dev/null +++ b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionBaseTest.java @@ -0,0 +1,131 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-TEST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.std.functions; + + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +import com.att.research.xacml.api.Identifier; +import com.att.research.xacml.api.XACML3; +import com.att.research.xacmlatt.pdp.policy.FunctionDefinition; +import com.att.research.xacmlatt.pdp.std.StdFunctions; +import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionBag; + +/** + * Test functions in the abstract FunctionDefinitionSimpleTest class. + * Functions are tested by creating instances of other classes that should have appropriate properties to verify all variations of the responses expected. + * + * Note: we do not test getDataTypeId() because all it does is get the String out of the Identity object and we assume that the Data Type Identity objects + * are tested enough in everything else that any errors in them will be found and fixed quickly. + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * + */ +public class FunctionDefinitionBaseTest { + /** + * getId() is pretty trivial, so verifying one should be enough to check that the mechanism is working ok + */ + @Test + public void testGetId() { + FunctionDefinition fd = StdFunctions.FD_STRING_EQUAL; + Identifier id = fd.getId(); + assertTrue(XACML3.ID_FUNCTION_STRING_EQUAL.stringValue().equals(id.stringValue()) ); + } + + /** + * check an instance of every result type that we can deal with + */ + @Test + public void testGetDataType() { + +//?? Need functions that return each of these data types except for Boolean which is returned by any of the EQUAL functions + FunctionDefinition fdstring = StdFunctions.FD_STRING_NORMALIZE_SPACE; + assertEquals(XACML3.ID_DATATYPE_STRING, fdstring.getDataTypeId()); + + FunctionDefinition fdboolean = StdFunctions.FD_STRING_EQUAL; + assertEquals(XACML3.ID_DATATYPE_BOOLEAN, fdboolean.getDataTypeId()); + + FunctionDefinition fdinteger = StdFunctions.FD_INTEGER_ADD; + assertEquals(XACML3.ID_DATATYPE_INTEGER, fdinteger.getDataTypeId()); + + FunctionDefinition fddouble = StdFunctions.FD_DOUBLE_ADD; + assertEquals(XACML3.ID_DATATYPE_DOUBLE, fddouble.getDataTypeId()); + + FunctionDefinition fddate = StdFunctions.FD_DATE_BAG; + assertEquals(XACML3.ID_DATATYPE_DATE, fddate.getDataTypeId()); + + FunctionDefinition fdtime = StdFunctions.FD_TIME_BAG; + assertEquals(XACML3.ID_DATATYPE_TIME, fdtime.getDataTypeId()); + + FunctionDefinition fddateTime = StdFunctions.FD_DATETIME_BAG; + assertEquals(XACML3.ID_DATATYPE_DATETIME, fddateTime.getDataTypeId()); + + FunctionDefinition fddayTimeDuration = StdFunctions.FD_DAYTIMEDURATION_FROM_STRING; + assertEquals(XACML3.ID_DATATYPE_DAYTIMEDURATION, fddayTimeDuration.getDataTypeId()); + + FunctionDefinition fdyearMonthDuration = StdFunctions.FD_YEARMONTHDURATION_FROM_STRING; + assertEquals(XACML3.ID_DATATYPE_YEARMONTHDURATION, fdyearMonthDuration.getDataTypeId()); + + FunctionDefinition fdanyURI = StdFunctions.FD_ANYURI_FROM_STRING; + assertEquals(XACML3.ID_DATATYPE_ANYURI, fdanyURI.getDataTypeId()); + + FunctionDefinition fdhexBinary = StdFunctions.FD_HEXBINARY_UNION; + assertEquals(XACML3.ID_DATATYPE_HEXBINARY, fdhexBinary.getDataTypeId()); + + FunctionDefinition fdbase64Binary = StdFunctions.FD_BASE64BINARY_UNION; + assertEquals(XACML3.ID_DATATYPE_BASE64BINARY, fdbase64Binary.getDataTypeId()); + + FunctionDefinition fdrfc822Name = StdFunctions.FD_RFC822NAME_FROM_STRING; + assertEquals(XACML3.ID_DATATYPE_RFC822NAME, fdrfc822Name.getDataTypeId()); + + FunctionDefinition fdx500Name = StdFunctions.FD_X500NAME_FROM_STRING; + assertEquals(XACML3.ID_DATATYPE_X500NAME, fdx500Name.getDataTypeId()); + +//TODO - There are currently no functions that return XPathExpression objects +// FunctionDefinition fdxpathExpression = StdFunctions.FD_XPATHEXPRESSION_FROM_STRING; +// assertEquals(XACML3.ID_DATATYPE_XPATHEXPRESSION, fdxpathExpression.getDataTypeId()); + + FunctionDefinition fdipAddress = StdFunctions.FD_IPADDRESS_FROM_STRING; + assertEquals(XACML3.ID_DATATYPE_IPADDRESS, fdipAddress.getDataTypeId()); + + FunctionDefinition fddnsName = StdFunctions.FD_DNSNAME_FROM_STRING; + assertEquals(XACML3.ID_DATATYPE_DNSNAME, fddnsName.getDataTypeId()); + } + + /** + * check the type of return, single vs multiple values + */ + @Test + public void testReturnsBag() { + FunctionDefinition fdNotBag = StdFunctions.FD_BOOLEAN_EQUAL; + assertFalse(fdNotBag.returnsBag()); + + FunctionDefinitionBag fdBag = (FunctionDefinitionBag) StdFunctions.FD_STRING_BAG; + assertTrue(fdBag.returnsBag()); + } + +} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionComparisonTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionComparisonTest.java new file mode 100644 index 000000000..b5b9c1453 --- /dev/null +++ b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionComparisonTest.java @@ -0,0 +1,1367 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-TEST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.std.functions; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.List; + +import org.junit.Test; + +import com.att.research.xacml.api.XACML3; +import com.att.research.xacml.std.datatypes.DataTypes; +import com.att.research.xacml.std.datatypes.ISO8601Date; +import com.att.research.xacml.std.datatypes.ISO8601DateTime; +import com.att.research.xacml.std.datatypes.ISO8601Time; +import com.att.research.xacmlatt.pdp.policy.ExpressionResult; +import com.att.research.xacmlatt.pdp.policy.FunctionArgument; +import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; +import com.att.research.xacmlatt.pdp.std.StdFunctions; +import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionComparison; +import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionTimeInRange; + +/** + * Test FunctionDefinitionComparison + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * + */ +public class FunctionDefinitionComparisonTest { + + /* + * variables useful in the following tests + */ + List arguments = new ArrayList(); + + FunctionArgumentAttributeValue stringAttr1 = null; + FunctionArgumentAttributeValue stringAttr1a = null; + FunctionArgumentAttributeValue stringAttr2 = null; + FunctionArgumentAttributeValue stringAttrNeg1 = null; + + + FunctionArgumentAttributeValue intAttr1 = null; + FunctionArgumentAttributeValue intAttr1a = null; + FunctionArgumentAttributeValue intAttr2 = null; + FunctionArgumentAttributeValue intAttr0 = null; + FunctionArgumentAttributeValue intAttrNeg1 = null; + + FunctionArgumentAttributeValue attr1 = null; + FunctionArgumentAttributeValue attr1a = null; + FunctionArgumentAttributeValue attr2 = null; + FunctionArgumentAttributeValue attrNeg1 = null; + + FunctionArgumentAttributeValue attrDateToday = null; + FunctionArgumentAttributeValue attrDateSameDay = null; + FunctionArgumentAttributeValue attrDateTommorrow = null; + FunctionArgumentAttributeValue attrDateYesterday = null; + FunctionArgumentAttributeValue attrDateWithTimeZone = null; + FunctionArgumentAttributeValue attrDateNoTimeZone = null; + + + FunctionArgumentAttributeValue attrTimeToday = null; + FunctionArgumentAttributeValue attrTimeSameDay = null; + FunctionArgumentAttributeValue attrTimeTommorrow = null; + FunctionArgumentAttributeValue attrTimeYesterday = null; + FunctionArgumentAttributeValue attrTimeWithTimeZone = null; + FunctionArgumentAttributeValue attrTimeNoTimeZone = null; + + FunctionArgumentAttributeValue attrDateTimeToday = null; + FunctionArgumentAttributeValue attrDateTimeSameDay = null; + FunctionArgumentAttributeValue attrDateTimeTommorrow = null; + FunctionArgumentAttributeValue attrDateTimeYesterday = null; + FunctionArgumentAttributeValue attrDateTimeWithTimeZone = null; + FunctionArgumentAttributeValue attrDateTimeNoTimeZone = null; + + /** + * Set up some common variables on startup + */ + public FunctionDefinitionComparisonTest() { + try { + stringAttr1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("abc")); + stringAttr1a = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("abc")); + stringAttr2 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("def")); + stringAttrNeg1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("AAA")); + + + intAttr1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1)); + intAttr1a = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1)); + intAttr2 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(2)); + intAttr0 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(0)); + intAttrNeg1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(-1)); + + attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.0)); + attr1a = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.0)); + attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(2.4)); + attrNeg1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(-1.0)); + + // create dates + Calendar calendar = Calendar.getInstance(); + Date today = calendar.getTime(); + Date longAgo = new Date(1234); + // create a date that is different than "today" but within the same day (i.e. has a different hour) + if (calendar.get(Calendar.HOUR_OF_DAY) > 3) { + calendar.set(Calendar.HOUR_OF_DAY, 3); + } else { + calendar.set(Calendar.HOUR_OF_DAY, 5); + } + Date todayPlus = calendar.getTime(); + calendar.add(Calendar.DATE, 1); + Date tommorrow = calendar.getTime(); + attrDateToday = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(today)); + attrDateSameDay = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(todayPlus)); + attrDateTommorrow = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(tommorrow)); + attrDateYesterday = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(longAgo)); + ISO8601Date isoDate = new ISO8601Date(1920, 5, 8); + attrDateNoTimeZone = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(isoDate)); + isoDate = new ISO8601Date("GMT+00:02", 1920, 5, 8); + attrDateWithTimeZone = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(isoDate)); + + // create Times + ISO8601Time isoTime = new ISO8601Time(14, 43, 12, 145); + attrTimeToday = new FunctionArgumentAttributeValue(DataTypes.DT_TIME.createAttributeValue(isoTime)); + attrTimeSameDay = new FunctionArgumentAttributeValue(DataTypes.DT_TIME.createAttributeValue(isoTime)); + isoTime = new ISO8601Time(18, 53, 34, 423); + attrTimeTommorrow = new FunctionArgumentAttributeValue(DataTypes.DT_TIME.createAttributeValue(isoTime)); + isoTime = new ISO8601Time(7, 34, 6,543); + attrTimeYesterday = new FunctionArgumentAttributeValue(DataTypes.DT_TIME.createAttributeValue(isoTime)); + isoTime = new ISO8601Time(12, 12, 12, 12); + attrTimeNoTimeZone = new FunctionArgumentAttributeValue(DataTypes.DT_TIME.createAttributeValue(isoTime)); + isoTime = new ISO8601Time("GMT:+00:03", 12, 12, 12, 12); + attrTimeWithTimeZone = new FunctionArgumentAttributeValue(DataTypes.DT_TIME.createAttributeValue(isoTime)); + + // create DateTimes + isoDate = new ISO8601Date(1920, 5, 8); + isoTime = new ISO8601Time( 18, 53, 34, 423); + ISO8601DateTime isoDateTime = new ISO8601DateTime((String)null, 1920, 5, 8, 18, 53, 34, 423); + attrDateTimeToday = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(isoDateTime)); + attrDateTimeSameDay = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(isoDateTime)); + isoTime = new ISO8601Time(20, 53, 34, 423); + isoDateTime = new ISO8601DateTime((String)null, 1920, 5, 8, 20, 53, 34, 423); + attrDateTimeTommorrow = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(isoDateTime)); + isoTime = new ISO8601Time(7, 34, 6,543); + isoDateTime = new ISO8601DateTime((String)null, 1920, 5, 8, 7, 34, 6, 543); + attrDateTimeYesterday = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(isoDateTime)); + isoTime = new ISO8601Time(12, 12, 12, 12); + isoDateTime = new ISO8601DateTime((String)null, 1920, 5, 8, 12, 12, 12, 12); + attrDateTimeNoTimeZone = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(isoDateTime)); + isoTime = new ISO8601Time("GMT:+00:03", 12, 12, 12, 12); + isoDate = new ISO8601Date("GMT:+00:03", 1920, 5, 8); + isoDateTime = new ISO8601DateTime("GMT:+00:03", 1920, 5, 8, 12, 12, 12, 12); + attrDateTimeWithTimeZone = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(isoDateTime)); + + + + + } catch (Exception e) { + fail("Error creating values e="+ e); + } + } + + /** + * String + */ + @Test + public void testString_GT() { + + FunctionDefinitionComparison fd = (FunctionDefinitionComparison) StdFunctions.FD_STRING_GREATER_THAN; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_GREATER_THAN, fd.getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // first == second + arguments.add(stringAttr1); + arguments.add(stringAttr1a); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // check first < second + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(stringAttr2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first > second + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(stringAttrNeg1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // test bad args data types? Not needed? + arguments.clear(); + arguments.add(intAttr1); + arguments.add(stringAttr1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + } + + @Test + public void testString_GTE() { + + FunctionDefinitionComparison fd = (FunctionDefinitionComparison) StdFunctions.FD_STRING_GREATER_THAN_OR_EQUAL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_GREATER_THAN_OR_EQUAL, fd.getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // first == second + arguments.add(stringAttr1); + arguments.add(stringAttr1a); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // check first < second + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(stringAttr2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first > second + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(stringAttrNeg1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + } + + @Test + public void testString_LT() { + + FunctionDefinitionComparison fd = (FunctionDefinitionComparison) StdFunctions.FD_STRING_LESS_THAN; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_LESS_THAN, fd.getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // first == second + arguments.add(stringAttr1); + arguments.add(stringAttr1a); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // check first < second + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(stringAttr2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // first > second + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(stringAttrNeg1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + } + + @Test + public void testString_LTE() { + + FunctionDefinitionComparison fd = (FunctionDefinitionComparison) StdFunctions.FD_STRING_LESS_THAN_OR_EQUAL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_LESS_THAN_OR_EQUAL, fd.getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // first == second + arguments.add(stringAttr1); + arguments.add(stringAttr1a); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // check first < second + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(stringAttr2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // first > second + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(stringAttrNeg1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + } + + + + /** + * Integer + */ + @Test + public void testInteger_GT() { + + FunctionDefinitionComparison fd = (FunctionDefinitionComparison) StdFunctions.FD_INTEGER_GREATER_THAN; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_INTEGER_GREATER_THAN, fd.getId()); + assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // first == second + arguments.add(intAttr1); + arguments.add(intAttr1a); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // check first < second + arguments.clear(); + arguments.add(intAttr1); + arguments.add(intAttr2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first > second + arguments.clear(); + arguments.add(intAttr1); + arguments.add(intAttrNeg1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // test bad args data types? Not needed? + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(intAttr1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + } + + @Test + public void testInteger_GTE() { + + FunctionDefinitionComparison fd = (FunctionDefinitionComparison) StdFunctions.FD_INTEGER_GREATER_THAN_OR_EQUAL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_INTEGER_GREATER_THAN_OR_EQUAL, fd.getId()); + assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // first == second + arguments.add(intAttr1); + arguments.add(intAttr1a); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // check first < second + arguments.clear(); + arguments.add(intAttr1); + arguments.add(intAttr2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first > second + arguments.clear(); + arguments.add(intAttr1); + arguments.add(intAttrNeg1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + } + + @Test + public void testInteger_LT() { + + FunctionDefinitionComparison fd = (FunctionDefinitionComparison) StdFunctions.FD_INTEGER_LESS_THAN; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_INTEGER_LESS_THAN, fd.getId()); + assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // first == second + arguments.add(intAttr1); + arguments.add(intAttr1a); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // check first < second + arguments.clear(); + arguments.add(intAttr1); + arguments.add(intAttr2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // first > second + arguments.clear(); + arguments.add(intAttr1); + arguments.add(intAttrNeg1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + } + + @Test + public void testInteger_LTE() { + + FunctionDefinitionComparison fd = (FunctionDefinitionComparison) StdFunctions.FD_INTEGER_LESS_THAN_OR_EQUAL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_INTEGER_LESS_THAN_OR_EQUAL, fd.getId()); + assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // first == second + arguments.add(intAttr1); + arguments.add(intAttr1a); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // check first < second + arguments.clear(); + arguments.add(intAttr1); + arguments.add(intAttr2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // first > second + arguments.clear(); + arguments.add(intAttr1); + arguments.add(intAttrNeg1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + } + + + + + /** + * Double + */ + @Test + public void testDouble_GT() { + + FunctionDefinitionComparison fd = (FunctionDefinitionComparison) StdFunctions.FD_DOUBLE_GREATER_THAN; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DOUBLE_GREATER_THAN, fd.getId()); + assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // first == second + arguments.add(attr1); + arguments.add(attr1a); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first < second + arguments.clear(); + arguments.add(attr1); + arguments.add(attr2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first > second + arguments.clear(); + arguments.add(attr1); + arguments.add(attrNeg1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // test bad args data types? Not needed? + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(intAttr1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + + } + + @Test + public void testDouble_GTE() { + + FunctionDefinitionComparison fd = (FunctionDefinitionComparison) StdFunctions.FD_DOUBLE_GREATER_THAN_OR_EQUAL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DOUBLE_GREATER_THAN_OR_EQUAL, fd.getId()); + assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // first == second + arguments.add(attr1); + arguments.add(attr1a); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // first < second + arguments.clear(); + arguments.add(attr1); + arguments.add(attr2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first > second + arguments.clear(); + arguments.add(attr1); + arguments.add(attrNeg1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + } + + @Test + public void testDouble_LT() { + + FunctionDefinitionComparison fd = (FunctionDefinitionComparison) StdFunctions.FD_DOUBLE_LESS_THAN; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DOUBLE_LESS_THAN, fd.getId()); + assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // first == second + arguments.add(attr1); + arguments.add(attr1a); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first < second + arguments.clear(); + arguments.add(attr1); + arguments.add(attr2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // first > second + arguments.clear(); + arguments.add(attr1); + arguments.add(attrNeg1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + } + + @Test + public void testDouble_LTE() { + + FunctionDefinitionComparison fd = (FunctionDefinitionComparison) StdFunctions.FD_DOUBLE_LESS_THAN_OR_EQUAL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DOUBLE_LESS_THAN_OR_EQUAL, fd.getId()); + assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // first == second + arguments.add(attr1); + arguments.add(attr1a); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // first < second + arguments.clear(); + arguments.add(attr1); + arguments.add(attr2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // first > second + arguments.clear(); + arguments.add(attr1); + arguments.add(attrNeg1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + } + + + + /** + * Date + */ + + @Test + public void testDate_GT() { + + FunctionDefinitionComparison fd = (FunctionDefinitionComparison) StdFunctions.FD_DATE_GREATER_THAN; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DATE_GREATER_THAN, fd.getId()); + assertEquals(DataTypes.DT_DATE.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // first == second + arguments.add(attrDateToday); + arguments.add(attrDateSameDay); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first < second + arguments.clear(); + arguments.add(attrDateToday); + arguments.add(attrDateTommorrow); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first > second + arguments.clear(); + arguments.add(attrDateToday); + arguments.add(attrDateYesterday); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // test bad args data types? One with TimeZone and one without + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(intAttr1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + + // test with TimeZone vs without + arguments.clear(); + arguments.add(attrDateWithTimeZone); + arguments.add(attrDateNoTimeZone); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:date-greater-than Cannot compare this ISO8601DateTime with non-time-zoned ISO8601DateTime", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + } + + @Test + public void testDate_GTE() { + + FunctionDefinitionComparison fd = (FunctionDefinitionComparison) StdFunctions.FD_DATE_GREATER_THAN_OR_EQUAL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DATE_GREATER_THAN_OR_EQUAL, fd.getId()); + assertEquals(DataTypes.DT_DATE.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // first == second + arguments.add(attrDateToday); + arguments.add(attrDateSameDay); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // first < second + arguments.clear(); + arguments.add(attrDateToday); + arguments.add(attrDateTommorrow); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first > second + arguments.clear(); + arguments.add(attrDateToday); + arguments.add(attrDateYesterday); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + } + + @Test + public void testDate_LT() { + + FunctionDefinitionComparison fd = (FunctionDefinitionComparison) StdFunctions.FD_DATE_LESS_THAN; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DATE_LESS_THAN, fd.getId()); + assertEquals(DataTypes.DT_DATE.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // first == second + arguments.add(attrDateToday); + arguments.add(attrDateSameDay); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first < second + arguments.clear(); + arguments.add(attrDateToday); + arguments.add(attrDateTommorrow); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // first > second + arguments.clear(); + arguments.add(attrDateToday); + arguments.add(attrDateYesterday); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + } + + @Test + public void testDate_LTE() { + + FunctionDefinitionComparison fd = (FunctionDefinitionComparison) StdFunctions.FD_DATE_LESS_THAN_OR_EQUAL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DATE_LESS_THAN_OR_EQUAL, fd.getId()); + assertEquals(DataTypes.DT_DATE.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // first == second + arguments.add(attrDateToday); + arguments.add(attrDateSameDay); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // first < second + arguments.clear(); + arguments.add(attrDateToday); + arguments.add(attrDateTommorrow); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // first > second + arguments.clear(); + arguments.add(attrDateToday); + arguments.add(attrDateYesterday); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + } + + + + + + + + /** + * Time + */ + + @Test + public void testTime_GT() { + + FunctionDefinitionComparison fd = (FunctionDefinitionComparison) StdFunctions.FD_TIME_GREATER_THAN; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_TIME_GREATER_THAN, fd.getId()); + assertEquals(DataTypes.DT_TIME.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // first == second + arguments.add(attrTimeToday); + arguments.add(attrTimeSameDay); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first < second + arguments.clear(); + arguments.add(attrTimeToday); + arguments.add(attrTimeTommorrow); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first > second + arguments.clear(); + arguments.add(attrTimeToday); + arguments.add(attrTimeYesterday); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // test bad args data types? One with TimeZone and one without + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(intAttr1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + + // test with TimeZone vs without + arguments.clear(); + arguments.add(attrTimeWithTimeZone); + arguments.add(attrTimeNoTimeZone); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:time-greater-than Cannot compare this ISO8601DateTime with non-time-zoned ISO8601DateTime", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + } + + @Test + public void testTime_GTE() { + + FunctionDefinitionComparison fd = (FunctionDefinitionComparison) StdFunctions.FD_TIME_GREATER_THAN_OR_EQUAL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_TIME_GREATER_THAN_OR_EQUAL, fd.getId()); + assertEquals(DataTypes.DT_TIME.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // first == second + arguments.add(attrTimeToday); + arguments.add(attrTimeSameDay); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // first < second + arguments.clear(); + arguments.add(attrTimeToday); + arguments.add(attrTimeTommorrow); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first > second + arguments.clear(); + arguments.add(attrTimeToday); + arguments.add(attrTimeYesterday); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + } + + @Test + public void testTime_LT() { + + FunctionDefinitionComparison fd = (FunctionDefinitionComparison) StdFunctions.FD_TIME_LESS_THAN; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_TIME_LESS_THAN, fd.getId()); + assertEquals(DataTypes.DT_TIME.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // first == second + arguments.add(attrTimeToday); + arguments.add(attrTimeSameDay); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first < second + arguments.clear(); + arguments.add(attrTimeToday); + arguments.add(attrTimeTommorrow); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // first > second + arguments.clear(); + arguments.add(attrTimeToday); + arguments.add(attrTimeYesterday); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + } + + @Test + public void testTime_LTE() { + + FunctionDefinitionComparison fd = (FunctionDefinitionComparison) StdFunctions.FD_TIME_LESS_THAN_OR_EQUAL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_TIME_LESS_THAN_OR_EQUAL, fd.getId()); + assertEquals(DataTypes.DT_TIME.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // first == second + arguments.add(attrTimeToday); + arguments.add(attrTimeSameDay); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // first < second + arguments.clear(); + arguments.add(attrTimeToday); + arguments.add(attrTimeTommorrow); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // first > second + arguments.clear(); + arguments.add(attrTimeToday); + arguments.add(attrTimeYesterday); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + } + + + + + + /** + * Time-in-range + */ + @Test + public void testTime_in_range() { + + FunctionDefinitionTimeInRange fd = (FunctionDefinitionTimeInRange) StdFunctions.FD_TIME_IN_RANGE; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_TIME_IN_RANGE, fd.getId()); + assertEquals(DataTypes.DT_TIME.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(3), fd.getNumArgs()); + + // arg 0 in range of others + arguments.add(attrTimeToday); + arguments.add(attrTimeYesterday); + arguments.add(attrTimeTommorrow); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // below range + arguments.clear(); + arguments.add(attrTimeYesterday); + arguments.add(attrTimeToday); + arguments.add(attrTimeTommorrow); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // above range + arguments.clear(); + arguments.add(attrTimeTommorrow); + arguments.add(attrTimeYesterday); + arguments.add(attrTimeToday); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // range bad + arguments.clear(); + arguments.add(attrTimeToday); + arguments.add(attrTimeTommorrow); + arguments.add(attrTimeYesterday); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // bad types + arguments.clear(); + arguments.add(attrDateTimeWithTimeZone); + arguments.add(attrDateTimeNoTimeZone); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:time-in-range Expected 3 arguments, got 2", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + arguments.add(attrDateTimeWithTimeZone); + arguments.add(attrDateTimeNoTimeZone); + arguments.add(intAttr1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:time-in-range Expected data type 'time' saw 'dateTime' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + + + + + /** + * DateTime + */ + + @Test + public void testDateTime_GT() { + + FunctionDefinitionComparison fd = (FunctionDefinitionComparison) StdFunctions.FD_DATETIME_GREATER_THAN; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DATETIME_GREATER_THAN, fd.getId()); + assertEquals(DataTypes.DT_DATETIME.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // first == second + arguments.add(attrDateTimeToday); + arguments.add(attrDateTimeSameDay); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first < second + arguments.clear(); + arguments.add(attrDateTimeToday); + arguments.add(attrDateTimeTommorrow); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first > second + arguments.clear(); + arguments.add(attrDateTimeToday); + arguments.add(attrDateTimeYesterday); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // test bad args data types? One with TimeZone and one without + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(intAttr1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + + // test with TimeZone vs without + arguments.clear(); + arguments.add(attrDateTimeWithTimeZone); + arguments.add(attrDateTimeNoTimeZone); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-greater-than Cannot compare this ISO8601DateTime with non-time-zoned ISO8601DateTime", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + } + + @Test + public void testDateTime_GTE() { + + FunctionDefinitionComparison fd = (FunctionDefinitionComparison) StdFunctions.FD_DATETIME_GREATER_THAN_OR_EQUAL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DATETIME_GREATER_THAN_OR_EQUAL, fd.getId()); + assertEquals(DataTypes.DT_DATETIME.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // first == second + arguments.add(attrDateTimeToday); + arguments.add(attrDateTimeSameDay); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // first < second + arguments.clear(); + arguments.add(attrDateTimeToday); + arguments.add(attrDateTimeTommorrow); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first > second + arguments.clear(); + arguments.add(attrDateTimeToday); + arguments.add(attrDateTimeYesterday); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + } + + @Test + public void testDateTime_LT() { + + FunctionDefinitionComparison fd = (FunctionDefinitionComparison) StdFunctions.FD_DATETIME_LESS_THAN; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DATETIME_LESS_THAN, fd.getId()); + assertEquals(DataTypes.DT_DATETIME.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // first == second + arguments.add(attrDateTimeToday); + arguments.add(attrDateTimeSameDay); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first < second + arguments.clear(); + arguments.add(attrDateTimeToday); + arguments.add(attrDateTimeTommorrow); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // first > second + arguments.clear(); + arguments.add(attrDateTimeToday); + arguments.add(attrDateTimeYesterday); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + } + + @Test + public void testDateTime_LTE() { + + FunctionDefinitionComparison fd = (FunctionDefinitionComparison) StdFunctions.FD_DATETIME_LESS_THAN_OR_EQUAL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DATETIME_LESS_THAN_OR_EQUAL, fd.getId()); + assertEquals(DataTypes.DT_DATETIME.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // first == second + arguments.add(attrDateTimeToday); + arguments.add(attrDateTimeSameDay); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // first < second + arguments.clear(); + arguments.add(attrDateTimeToday); + arguments.add(attrDateTimeTommorrow); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // first > second + arguments.clear(); + arguments.add(attrDateTimeToday); + arguments.add(attrDateTimeYesterday); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + } + + + +} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionDateTimeArithmeticTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionDateTimeArithmeticTest.java new file mode 100644 index 000000000..e11929e93 --- /dev/null +++ b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionDateTimeArithmeticTest.java @@ -0,0 +1,1602 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-TEST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.std.functions; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +import com.att.research.xacml.api.XACML3; +import com.att.research.xacml.std.datatypes.DataTypes; +import com.att.research.xacml.std.datatypes.ISO8601Date; +import com.att.research.xacml.std.datatypes.ISO8601DateTime; +import com.att.research.xacml.std.datatypes.ISO8601Time; +import com.att.research.xacml.std.datatypes.ISO8601TimeZone; +import com.att.research.xacml.std.datatypes.XPathDayTimeDuration; +import com.att.research.xacml.std.datatypes.XPathYearMonthDuration; +import com.att.research.xacmlatt.pdp.policy.ExpressionResult; +import com.att.research.xacmlatt.pdp.policy.FunctionArgument; +import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; +import com.att.research.xacmlatt.pdp.std.StdFunctions; +import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionDateTimeArithmetic; + +/** + * Test of PDP Functions (See XACML core spec section A.3) + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * + */ +public class FunctionDefinitionDateTimeArithmeticTest { + + + /* + * variables useful in the following tests + */ + List arguments = new ArrayList(); + + ExpressionResult res; + + + @Test + public void testDateTime_add_dayTimeDuration() { + // Date objects to be adjusted + ISO8601DateTime dateTimeStdExample1 = new ISO8601DateTime(null, + new ISO8601Date(2000, 1, 12), + new ISO8601Time(12, 13, 14, 0)); + ISO8601DateTime dateTimeMsecs = new ISO8601DateTime(null, + new ISO8601Date(2000, 1, 12), + new ISO8601Time(12, 13, 14, 777)); + ISO8601DateTime dateTimeCrossover = new ISO8601DateTime(null, + new ISO8601Date(2000, 12, 31), + new ISO8601Time(23, 59, 30, 1)); + ISO8601DateTime dateTimeBC = new ISO8601DateTime(null, + new ISO8601Date(-2000, 1, 12), + new ISO8601Time(12, 13, 14, 0)); + ISO8601TimeZone timeZone0 = new ISO8601TimeZone(0); + ISO8601TimeZone timeZone5 = new ISO8601TimeZone(5 * 60); + ISO8601DateTime dateTimeTimeZone0 = new ISO8601DateTime(timeZone0, + new ISO8601Date(timeZone0, 2000, 1, 12), + new ISO8601Time(timeZone0, 12, 13, 14, 0)); + ISO8601DateTime dateTimeTimeZone5 = new ISO8601DateTime(timeZone5, + new ISO8601Date(timeZone5, 2000, 1, 12), + new ISO8601Time(timeZone5, 12, 13, 14, 0)); + ISO8601DateTime dateTimeIIC102Result = null; + + // Durations + XPathDayTimeDuration duration0 = new XPathDayTimeDuration(1, 0, 0, 0, 0); + XPathDayTimeDuration durationStdExample1 = new XPathDayTimeDuration(1, 5, 7, 10, 3.3); + XPathDayTimeDuration durationNStdExample1 = new XPathDayTimeDuration(-1, 5, 7, 10, 3.3); + XPathDayTimeDuration durationMsecs = new XPathDayTimeDuration(1, 5, 7, 10, 3.223); + XPathDayTimeDuration durationCrossover = new XPathDayTimeDuration(1, 0, 0, 0, 29.999); + + // ARGS declarations + // Dates + FunctionArgumentAttributeValue attrDateTimeStdExample1 = null; + FunctionArgumentAttributeValue attrDateTimeMsecs = null; + FunctionArgumentAttributeValue attrDateTimeCrossover = null; + FunctionArgumentAttributeValue attrDateTimeBC = null; + FunctionArgumentAttributeValue attrDateTimeTimeZone0 = null; + FunctionArgumentAttributeValue attrDateTimeTimeZone5 = null; + FunctionArgumentAttributeValue attrDateTimeIIC102 = null; + + // Durations + FunctionArgumentAttributeValue attrDuration0 = null; + FunctionArgumentAttributeValue attrDurationStdExample1 = null; + FunctionArgumentAttributeValue attrDurationNStdExample1 = null; + FunctionArgumentAttributeValue attrDurationMsecs = null; + FunctionArgumentAttributeValue attrDurationCrossover = null; + FunctionArgumentAttributeValue attrDurationIIC102 = null; + + // misc bad + FunctionArgumentAttributeValue attrNull = null; + FunctionArgumentAttributeValue attrBlank = null; + FunctionArgumentAttributeValue attrInteger = null; + // set values + try { + // Date attrs + attrDateTimeStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeStdExample1)); + attrDateTimeMsecs = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeMsecs)); + attrDateTimeCrossover = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeCrossover)); + attrDateTimeBC = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeBC)); + attrDateTimeTimeZone0 = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeTimeZone0)); + attrDateTimeTimeZone5 = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeTimeZone5)); + attrDateTimeIIC102 = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(DataTypes.DT_DATETIME.convert("2002-03-22T08:23:47-05:00"))); + + dateTimeIIC102Result = DataTypes.DT_DATETIME.convert("2002-03-27T10:23:47-05:00"); + + // Duration attrs + attrDuration0 = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(duration0)); + attrDurationStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(durationStdExample1)); + attrDurationNStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(durationNStdExample1)); + attrDurationMsecs = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(durationMsecs)); + attrDurationCrossover = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(durationCrossover)); + attrDurationIIC102 = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue("P5DT2H0M0S")); + + // misc bad + attrBlank = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue("")); + attrNull = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(null)); + attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234)); + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + FunctionDefinitionDateTimeArithmetic fd = (FunctionDefinitionDateTimeArithmetic) StdFunctions.FD_DATETIME_ADD_DAYTIMEDURATION; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DATETIME_ADD_DAYTIMEDURATION, fd.getId()); + assertEquals(DataTypes.DT_DATETIME.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + // Duration = 0 => same as original + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrDuration0); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + ISO8601DateTime resValue = (ISO8601DateTime)res.getValue().getValue(); + assertEquals(dateTimeStdExample1, resValue); + + + // simple positive operation + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + ISO8601DateTime testResponse = new ISO8601DateTime( + null, + new ISO8601Date(2000, 1, 17), + new ISO8601Time(19, 23, 17, 300) ); + assertEquals(testResponse, resValue); + + // negative operation + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrDurationNStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + testResponse = new ISO8601DateTime( + null, + new ISO8601Date(2000, 1, 7), + new ISO8601Time(5, 3, 10, 700) ); + assertEquals(testResponse, resValue); + + // millisecs work correctly + arguments.clear(); + arguments.add(attrDateTimeMsecs); + arguments.add(attrDurationMsecs); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + testResponse = new ISO8601DateTime( + null, + new ISO8601Date(2000, 1, 17), + new ISO8601Time(19, 23, 18, 0) ); + assertEquals(testResponse, resValue); + + // cross minute => cross day => cross month => cross year + arguments.clear(); + arguments.add(attrDateTimeCrossover); + arguments.add(attrDurationCrossover); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + testResponse = new ISO8601DateTime( + null, + new ISO8601Date(2001, 1, 1), + new ISO8601Time(0, 0, 0, 0) ); + assertEquals(testResponse, resValue); + + // negative (BC) original date add goes the right direction + arguments.clear(); + arguments.add(attrDateTimeBC); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + testResponse = new ISO8601DateTime( + null, + new ISO8601Date(-2000, 1, 17), + new ISO8601Time(19, 23, 17, 300) ); + assertEquals(testResponse, resValue); + + // non-null timezone not changed + // original has timezone offset = 0 + arguments.clear(); + arguments.add(attrDateTimeTimeZone0); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + testResponse = new ISO8601DateTime( + timeZone0, + new ISO8601Date(timeZone0, 2000, 1, 17), + new ISO8601Time(timeZone0, 19, 23, 17, 300) ); + assertEquals(testResponse, resValue); + + // original has timezone offset not 0 + arguments.clear(); + arguments.add(attrDateTimeTimeZone5); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + testResponse = new ISO8601DateTime( + timeZone5, + new ISO8601Date(timeZone5, 2000, 1, 17), + new ISO8601Time(timeZone5, 19, 23, 17, 300) ); + assertEquals(testResponse, resValue); + + // conformance test IIC102 + arguments.clear(); + arguments.add(attrDateTimeIIC102); + arguments.add(attrDurationIIC102); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + assertEquals(dateTimeIIC102Result, resValue); + + // empty non-null first arg + arguments.clear(); + arguments.add(attrBlank); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-add-dayTimeDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // empty non-null second arg + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-add-dayTimeDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // two blanks + arguments.clear(); + arguments.add(attrBlank); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-add-dayTimeDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null firat arg + arguments.clear(); + arguments.add(attrNull); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-add-dayTimeDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null second arg + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrNull); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-add-dayTimeDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrInteger); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-add-dayTimeDuration Expected data type 'dateTime' saw 'integer'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null second arg + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrNull); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-add-dayTimeDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + + + @Test + public void testDateTime_subtract_dayTimeDuration() { + // Date objects to be adjusted + ISO8601DateTime dateTimeStdExample1 = new ISO8601DateTime(null, + new ISO8601Date(2000, 1, 12), + new ISO8601Time(12, 13, 14, 0)); + ISO8601DateTime dateTimeMsecs = new ISO8601DateTime(null, + new ISO8601Date(2000, 1, 12), + new ISO8601Time(12, 13, 14, 777)); + ISO8601DateTime dateTimeCrossover = new ISO8601DateTime(null, + new ISO8601Date(2001, 1, 1), + new ISO8601Time(0, 0, 0, 0) ); + ISO8601DateTime dateTimeBC = new ISO8601DateTime(null, + new ISO8601Date(-2000, 1, 12), + new ISO8601Time(12, 13, 14, 0)); + ISO8601TimeZone timeZone0 = new ISO8601TimeZone(0); + ISO8601TimeZone timeZone5 = new ISO8601TimeZone(5 * 60); + ISO8601DateTime dateTimeTimeZone0 = new ISO8601DateTime(timeZone0, + new ISO8601Date(timeZone0, 2000, 1, 12), + new ISO8601Time(timeZone0, 12, 13, 14, 0)); + ISO8601DateTime dateTimeTimeZone5 = new ISO8601DateTime(timeZone5, + new ISO8601Date(timeZone5, 2000, 1, 12), + new ISO8601Time(timeZone5, 12, 13, 14, 0)); + + // Durations + XPathDayTimeDuration duration0 = new XPathDayTimeDuration(1, 0, 0, 0, 0); + XPathDayTimeDuration durationStdExample1 = new XPathDayTimeDuration(1, 5, 7, 10, 3.3); + XPathDayTimeDuration durationNStdExample1 = new XPathDayTimeDuration(-1, 5, 7, 10, 3.3); + XPathDayTimeDuration durationMsecs = new XPathDayTimeDuration(1, 5, 7, 10, 14.778); + XPathDayTimeDuration durationCrossover = new XPathDayTimeDuration(1, 0, 0, 0, 29.999); + + // ARGS declarations + // Dates + FunctionArgumentAttributeValue attrDateTimeStdExample1 = null; + FunctionArgumentAttributeValue attrDateTimeMsecs = null; + FunctionArgumentAttributeValue attrDateTimeCrossover = null; + FunctionArgumentAttributeValue attrDateTimeBC = null; + FunctionArgumentAttributeValue attrDateTimeTimeZone0 = null; + FunctionArgumentAttributeValue attrDateTimeTimeZone5 = null; + + // Durations + FunctionArgumentAttributeValue attrDuration0 = null; + FunctionArgumentAttributeValue attrDurationStdExample1 = null; + FunctionArgumentAttributeValue attrDurationNStdExample1 = null; + FunctionArgumentAttributeValue attrDurationMsecs = null; + FunctionArgumentAttributeValue attrDurationCrossover = null; + + // misc bad + FunctionArgumentAttributeValue attrNull = null; + FunctionArgumentAttributeValue attrBlank = null; + FunctionArgumentAttributeValue attrInteger = null; + // set values + try { + // Date attrs + attrDateTimeStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeStdExample1)); + attrDateTimeMsecs = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeMsecs)); + attrDateTimeCrossover = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeCrossover)); + attrDateTimeBC = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeBC)); + attrDateTimeTimeZone0 = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeTimeZone0)); + attrDateTimeTimeZone5 = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeTimeZone5)); + + // Duration attrs + attrDuration0 = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(duration0)); + attrDurationStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(durationStdExample1)); + attrDurationNStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(durationNStdExample1)); + attrDurationMsecs = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(durationMsecs)); + attrDurationCrossover = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(durationCrossover)); + + // misc bad + attrBlank = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue("")); + attrNull = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(null)); + attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234)); + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + FunctionDefinitionDateTimeArithmetic fd = (FunctionDefinitionDateTimeArithmetic) StdFunctions.FD_DATETIME_SUBTRACT_DAYTIMEDURATION; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DATETIME_SUBTRACT_DAYTIMEDURATION, fd.getId()); + assertEquals(DataTypes.DT_DATETIME.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + // Duration = 0 => same as original + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrDuration0); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + ISO8601DateTime resValue = (ISO8601DateTime)res.getValue().getValue(); + assertEquals(dateTimeStdExample1, resValue); + + + // simple positive operation + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + ISO8601DateTime testResponse = new ISO8601DateTime( + null, + new ISO8601Date(2000, 1, 7), + new ISO8601Time(5, 3, 10, 700) ); + assertEquals(testResponse, resValue); + + + // negative operation + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrDurationNStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + testResponse = new ISO8601DateTime( + null, + new ISO8601Date(2000, 1, 17), + new ISO8601Time(19, 23, 17, 300) ); + assertEquals(testResponse, resValue); + + // millisecs work correctly + arguments.clear(); + arguments.add(attrDateTimeMsecs); + arguments.add(attrDurationMsecs); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + testResponse = new ISO8601DateTime( + null, + new ISO8601Date(2000, 1, 7), + new ISO8601Time(5, 2, 59, 999) ); + assertEquals(testResponse, resValue); + + // cross minute => cross day => cross month => cross year + arguments.clear(); + arguments.add(attrDateTimeCrossover); + arguments.add(attrDurationCrossover); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + testResponse = new ISO8601DateTime( + null, + new ISO8601Date(2000, 12, 31), + new ISO8601Time(23, 59, 30, 1)); + assertEquals(testResponse, resValue); + + // negative (BC) original date add goes the right direction + arguments.clear(); + arguments.add(attrDateTimeBC); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + testResponse = new ISO8601DateTime( + null, + new ISO8601Date(-2000, 1, 7), + new ISO8601Time(5, 3, 10, 700) ); + assertEquals(testResponse, resValue); + + // non-null timezone not changed + // original has timezone offset = 0 + arguments.clear(); + arguments.add(attrDateTimeTimeZone0); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + testResponse = new ISO8601DateTime( + timeZone0, + new ISO8601Date(timeZone0, 2000, 1, 7), + new ISO8601Time(timeZone0, 5, 3, 10, 700) ); + assertEquals(testResponse, resValue); + + // original has timezone offset not 0 + arguments.clear(); + arguments.add(attrDateTimeTimeZone5); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + testResponse = new ISO8601DateTime( + timeZone5, + new ISO8601Date(timeZone5, 2000, 1, 7), + new ISO8601Time(timeZone5, 5, 3, 10, 700) ); + assertEquals(testResponse, resValue); + + // empty non-null first arg + arguments.clear(); + arguments.add(attrBlank); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-subtract-dayTimeDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // empty non-null second arg + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-subtract-dayTimeDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // two blanks + arguments.clear(); + arguments.add(attrBlank); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-subtract-dayTimeDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null firat arg + arguments.clear(); + arguments.add(attrNull); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-subtract-dayTimeDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null second arg + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrNull); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-subtract-dayTimeDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrInteger); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-subtract-dayTimeDuration Expected data type 'dateTime' saw 'integer'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null second arg + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrNull); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-subtract-dayTimeDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + + + + + + + + + @Test + public void testDateTime_add_yearMonthDuration() { + // Date objects to be adjusted + ISO8601DateTime dateTimeStdExample1 = new ISO8601DateTime(null, + new ISO8601Date(2000, 1, 12), + new ISO8601Time(12, 13, 14, 0)); + ISO8601DateTime dateTimeMsecs = new ISO8601DateTime(null, + new ISO8601Date(2000, 1, 12), + new ISO8601Time(12, 13, 14, 777)); + ISO8601DateTime dateTimeCrossover = new ISO8601DateTime(null, + new ISO8601Date(2000, 12, 31), + new ISO8601Time(23, 59, 30, 1)); + ISO8601DateTime dateTimeBC = new ISO8601DateTime(null, + new ISO8601Date(-2000, 1, 12), + new ISO8601Time(12, 13, 14, 0)); + ISO8601TimeZone timeZone0 = new ISO8601TimeZone(0); + ISO8601TimeZone timeZone5 = new ISO8601TimeZone(5 * 60); + ISO8601DateTime dateTimeTimeZone0 = new ISO8601DateTime(timeZone0, + new ISO8601Date(timeZone0, 2000, 1, 12), + new ISO8601Time(timeZone0, 12, 13, 14, 0)); + ISO8601DateTime dateTimeTimeZone5 = new ISO8601DateTime(timeZone5, + new ISO8601Date(timeZone5, 2000, 1, 12), + new ISO8601Time(timeZone5, 12, 13, 14, 0)); + + // Durations + XPathYearMonthDuration duration0 = new XPathYearMonthDuration(1, 0, 0); + XPathYearMonthDuration durationStdExample1 = new XPathYearMonthDuration(1, 5, 7); + XPathYearMonthDuration durationNStdExample1 = new XPathYearMonthDuration(-1, 5, 7); + XPathYearMonthDuration durationMsecs = new XPathYearMonthDuration(1, 5, 7); + XPathYearMonthDuration durationCrossover = new XPathYearMonthDuration(1, 0, 1); + + // ARGS declarations + // Dates + FunctionArgumentAttributeValue attrDateTimeStdExample1 = null; + FunctionArgumentAttributeValue attrDateTimeMsecs = null; + FunctionArgumentAttributeValue attrDateTimeCrossover = null; + FunctionArgumentAttributeValue attrDateTimeBC = null; + FunctionArgumentAttributeValue attrDateTimeTimeZone0 = null; + FunctionArgumentAttributeValue attrDateTimeTimeZone5 = null; + + // Durations + FunctionArgumentAttributeValue attrDuration0 = null; + FunctionArgumentAttributeValue attrDurationStdExample1 = null; + FunctionArgumentAttributeValue attrDurationNStdExample1 = null; + FunctionArgumentAttributeValue attrDurationMsecs = null; + FunctionArgumentAttributeValue attrDurationCrossover = null; + + // misc bad + FunctionArgumentAttributeValue attrNull = null; + FunctionArgumentAttributeValue attrBlank = null; + FunctionArgumentAttributeValue attrInteger = null; + // set values + try { + // Date attrs + attrDateTimeStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeStdExample1)); + attrDateTimeMsecs = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeMsecs)); + attrDateTimeCrossover = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeCrossover)); + attrDateTimeBC = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeBC)); + attrDateTimeTimeZone0 = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeTimeZone0)); + attrDateTimeTimeZone5 = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeTimeZone5)); + + // Duration attrs + attrDuration0 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(duration0)); + attrDurationStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(durationStdExample1)); + attrDurationNStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(durationNStdExample1)); + attrDurationMsecs = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(durationMsecs)); + attrDurationCrossover = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(durationCrossover)); + + // misc bad + attrBlank = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue("")); + attrNull = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(null)); + attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234)); + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + FunctionDefinitionDateTimeArithmetic fd = (FunctionDefinitionDateTimeArithmetic) StdFunctions.FD_DATETIME_ADD_YEARMONTHDURATION; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DATETIME_ADD_YEARMONTHDURATION, fd.getId()); + assertEquals(DataTypes.DT_DATETIME.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + // Duration = 0 => same as original + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrDuration0); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + ISO8601DateTime resValue = (ISO8601DateTime)res.getValue().getValue(); + assertEquals(dateTimeStdExample1, resValue); + + + // simple positive operation + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + ISO8601DateTime testResponse = new ISO8601DateTime( + null, + new ISO8601Date(2005, 8, 12), + new ISO8601Time(12, 13, 14, 0) ); + assertEquals(testResponse, resValue); + + // negative operation + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrDurationNStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + testResponse = new ISO8601DateTime( + null, + new ISO8601Date(1994, 6, 12), + new ISO8601Time(12, 13, 14, 0) ); + assertEquals(testResponse, resValue); + + // millisecs work correctly (not relevant to YearMonth, but should not break + arguments.clear(); + arguments.add(attrDateTimeMsecs); + arguments.add(attrDurationMsecs); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + testResponse = new ISO8601DateTime( + null, + new ISO8601Date(2005, 8, 12), + new ISO8601Time(12, 13, 14, 777) ); + assertEquals(testResponse, resValue); + + // cross minute => cross day => cross month => cross year + arguments.clear(); + arguments.add(attrDateTimeCrossover); + arguments.add(attrDurationCrossover); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + testResponse = new ISO8601DateTime( + null, + new ISO8601Date(2001, 1, 31), + new ISO8601Time(23, 59, 30, 1) ); + assertEquals(testResponse, resValue); + + // negative (BC) original date add goes the right direction + arguments.clear(); + arguments.add(attrDateTimeBC); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + testResponse = new ISO8601DateTime( + null, + new ISO8601Date(-1995, 8, 12), + new ISO8601Time(12, 13, 14, 0) ); + assertEquals(testResponse, resValue); + + // non-null timezone not changed + // original has timezone offset = 0 + arguments.clear(); + arguments.add(attrDateTimeTimeZone0); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + testResponse = new ISO8601DateTime( + timeZone0, + new ISO8601Date(timeZone0, 2005, 8, 12), + new ISO8601Time(timeZone0, 12, 13, 14, 0) ); + assertEquals(testResponse, resValue); + + // original has timezone offset not 0 + arguments.clear(); + arguments.add(attrDateTimeTimeZone5); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + testResponse = new ISO8601DateTime( + timeZone5, + new ISO8601Date(timeZone5, 2005, 8, 12), + new ISO8601Time(timeZone5, 12, 13, 14, 0) ); + assertEquals(testResponse, resValue); + + // empty non-null first arg + arguments.clear(); + arguments.add(attrBlank); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-add-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // empty non-null second arg + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-add-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // two blanks + arguments.clear(); + arguments.add(attrBlank); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-add-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null firat arg + arguments.clear(); + arguments.add(attrNull); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-add-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null second arg + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrNull); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-add-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrInteger); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-add-yearMonthDuration Expected data type 'dateTime' saw 'integer'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null second arg + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrNull); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-add-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + + + + @Test + public void testDateTime_subtract_yearMonthDuration() { + // Date objects to be adjusted + ISO8601DateTime dateTimeStdExample1 = new ISO8601DateTime(null, + new ISO8601Date(2000, 1, 12), + new ISO8601Time(12, 13, 14, 0)); + ISO8601DateTime dateTimeMsecs = new ISO8601DateTime(null, + new ISO8601Date(2000, 1, 12), + new ISO8601Time(12, 13, 14, 777)); + ISO8601DateTime dateTimeCrossover = new ISO8601DateTime(null, + new ISO8601Date(2000, 1, 1), + new ISO8601Time(23, 59, 30, 1)); + ISO8601DateTime dateTimeBC = new ISO8601DateTime(null, + new ISO8601Date(-2000, 1, 12), + new ISO8601Time(12, 13, 14, 0)); + ISO8601TimeZone timeZone0 = new ISO8601TimeZone(0); + ISO8601TimeZone timeZone5 = new ISO8601TimeZone(5 * 60); + ISO8601DateTime dateTimeTimeZone0 = new ISO8601DateTime(timeZone0, + new ISO8601Date(timeZone0, 2000, 1, 12), + new ISO8601Time(timeZone0, 12, 13, 14, 0)); + ISO8601DateTime dateTimeTimeZone5 = new ISO8601DateTime(timeZone5, + new ISO8601Date(timeZone5, 2000, 1, 12), + new ISO8601Time(timeZone5, 12, 13, 14, 0)); + + // Durations + XPathYearMonthDuration duration0 = new XPathYearMonthDuration(1, 0, 0); + XPathYearMonthDuration durationStdExample1 = new XPathYearMonthDuration(1, 5, 7); + XPathYearMonthDuration durationNStdExample1 = new XPathYearMonthDuration(-1, 5, 7); + XPathYearMonthDuration durationMsecs = new XPathYearMonthDuration(1, 5, 7); + XPathYearMonthDuration durationCrossover = new XPathYearMonthDuration(1, 0, 1); + + // ARGS declarations + // Dates + FunctionArgumentAttributeValue attrDateTimeStdExample1 = null; + FunctionArgumentAttributeValue attrDateTimeMsecs = null; + FunctionArgumentAttributeValue attrDateTimeCrossover = null; + FunctionArgumentAttributeValue attrDateTimeBC = null; + FunctionArgumentAttributeValue attrDateTimeTimeZone0 = null; + FunctionArgumentAttributeValue attrDateTimeTimeZone5 = null; + + // Durations + FunctionArgumentAttributeValue attrDuration0 = null; + FunctionArgumentAttributeValue attrDurationStdExample1 = null; + FunctionArgumentAttributeValue attrDurationNStdExample1 = null; + FunctionArgumentAttributeValue attrDurationMsecs = null; + FunctionArgumentAttributeValue attrDurationCrossover = null; + + // misc bad + FunctionArgumentAttributeValue attrNull = null; + FunctionArgumentAttributeValue attrBlank = null; + FunctionArgumentAttributeValue attrInteger = null; + // set values + try { + // Date attrs + attrDateTimeStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeStdExample1)); + attrDateTimeMsecs = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeMsecs)); + attrDateTimeCrossover = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeCrossover)); + attrDateTimeBC = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeBC)); + attrDateTimeTimeZone0 = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeTimeZone0)); + attrDateTimeTimeZone5 = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeTimeZone5)); + + // Duration attrs + attrDuration0 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(duration0)); + attrDurationStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(durationStdExample1)); + attrDurationNStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(durationNStdExample1)); + attrDurationMsecs = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(durationMsecs)); + attrDurationCrossover = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(durationCrossover)); + + // misc bad + attrBlank = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue("")); + attrNull = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(null)); + attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234)); + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + FunctionDefinitionDateTimeArithmetic fd = (FunctionDefinitionDateTimeArithmetic) StdFunctions.FD_DATETIME_SUBTRACT_YEARMONTHDURATION; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DATETIME_SUBTRACT_YEARMONTHDURATION, fd.getId()); + assertEquals(DataTypes.DT_DATETIME.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + // Duration = 0 => same as original + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrDuration0); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + ISO8601DateTime resValue = (ISO8601DateTime)res.getValue().getValue(); + assertEquals(dateTimeStdExample1, resValue); + + + // simple positive operation + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + ISO8601DateTime testResponse = new ISO8601DateTime( + null, + new ISO8601Date(1994, 6, 12), + new ISO8601Time(12, 13, 14, 0) ); + assertEquals(testResponse, resValue); + + // negative operation + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrDurationNStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + testResponse = new ISO8601DateTime( + null, + new ISO8601Date(2005, 8, 12), + new ISO8601Time(12, 13, 14, 0) ); + assertEquals(testResponse, resValue); + + // millisecs work correctly (not relevant to YearMonth, but should not break + arguments.clear(); + arguments.add(attrDateTimeMsecs); + arguments.add(attrDurationMsecs); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + testResponse = new ISO8601DateTime( + null, + new ISO8601Date(1994, 6, 12), + new ISO8601Time(12, 13, 14, 777) ); + assertEquals(testResponse, resValue); + + // cross minute => cross day => cross month => cross year + arguments.clear(); + arguments.add(attrDateTimeCrossover); + arguments.add(attrDurationCrossover); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + testResponse = new ISO8601DateTime( + null, + new ISO8601Date(1999, 12, 1), + new ISO8601Time(23, 59, 30, 1) ); + assertEquals(testResponse, resValue); + + // negative (BC) original date add goes the right direction + arguments.clear(); + arguments.add(attrDateTimeBC); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + testResponse = new ISO8601DateTime( + null, + new ISO8601Date(-2006, 6, 12), + new ISO8601Time(12, 13, 14, 0) ); + assertEquals(testResponse, resValue); + + // non-null timezone not changed + // original has timezone offset = 0 + arguments.clear(); + arguments.add(attrDateTimeTimeZone0); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + testResponse = new ISO8601DateTime( + timeZone0, + new ISO8601Date(timeZone0, 1994, 6, 12), + new ISO8601Time(timeZone0, 12, 13, 14, 0) ); + assertEquals(testResponse, resValue); + + // original has timezone offset not 0 + arguments.clear(); + arguments.add(attrDateTimeTimeZone5); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + testResponse = new ISO8601DateTime( + timeZone5, + new ISO8601Date(timeZone5, 1994, 6, 12), + new ISO8601Time(timeZone5, 12, 13, 14, 0) ); + assertEquals(testResponse, resValue); + + // empty non-null first arg + arguments.clear(); + arguments.add(attrBlank); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-subtract-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // empty non-null second arg + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-subtract-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // two blanks + arguments.clear(); + arguments.add(attrBlank); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-subtract-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null firat arg + arguments.clear(); + arguments.add(attrNull); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-subtract-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null second arg + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrNull); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-subtract-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrInteger); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-subtract-yearMonthDuration Expected data type 'dateTime' saw 'integer'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null second arg + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrNull); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-subtract-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + + + + + + + + + + + @Test + public void testDate_add_yearMonthDuration() { + // Date objects to be adjusted + ISO8601Date dateTimeStdExample1 = new ISO8601Date(2000, 1, 12); + ISO8601Date dateTimeMsecs =new ISO8601Date(2000, 1, 12); + ISO8601Date dateTimeCrossover = new ISO8601Date(2000, 12, 31); + ISO8601Date dateTimeBC = new ISO8601Date(-2000, 1, 12); + ISO8601TimeZone timeZone0 = new ISO8601TimeZone(0); + ISO8601TimeZone timeZone5 = new ISO8601TimeZone(5 * 60); + ISO8601Date dateTimeTimeZone0 = new ISO8601Date(timeZone0, 2000, 1, 12); + ISO8601Date dateTimeTimeZone5 = new ISO8601Date(timeZone5, 2000, 1, 12); + + // Durations + XPathYearMonthDuration duration0 = new XPathYearMonthDuration(1, 0, 0); + XPathYearMonthDuration durationStdExample1 = new XPathYearMonthDuration(1, 5, 7); + XPathYearMonthDuration durationNStdExample1 = new XPathYearMonthDuration(-1, 5, 7); + XPathYearMonthDuration durationMsecs = new XPathYearMonthDuration(1, 5, 7); + XPathYearMonthDuration durationCrossover = new XPathYearMonthDuration(1, 0, 1); + + // ARGS declarations + // Dates + FunctionArgumentAttributeValue attrDateTimeStdExample1 = null; + FunctionArgumentAttributeValue attrDateTimeMsecs = null; + FunctionArgumentAttributeValue attrDateTimeCrossover = null; + FunctionArgumentAttributeValue attrDateTimeBC = null; + FunctionArgumentAttributeValue attrDateTimeTimeZone0 = null; + FunctionArgumentAttributeValue attrDateTimeTimeZone5 = null; + + // Durations + FunctionArgumentAttributeValue attrDuration0 = null; + FunctionArgumentAttributeValue attrDurationStdExample1 = null; + FunctionArgumentAttributeValue attrDurationNStdExample1 = null; + FunctionArgumentAttributeValue attrDurationMsecs = null; + FunctionArgumentAttributeValue attrDurationCrossover = null; + + // misc bad + FunctionArgumentAttributeValue attrNull = null; + FunctionArgumentAttributeValue attrBlank = null; + FunctionArgumentAttributeValue attrInteger = null; + // set values + try { + // Date attrs + attrDateTimeStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(dateTimeStdExample1)); + attrDateTimeMsecs = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(dateTimeMsecs)); + attrDateTimeCrossover = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(dateTimeCrossover)); + attrDateTimeBC = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(dateTimeBC)); + attrDateTimeTimeZone0 = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(dateTimeTimeZone0)); + attrDateTimeTimeZone5 = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(dateTimeTimeZone5)); + + // Duration attrs + attrDuration0 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(duration0)); + attrDurationStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(durationStdExample1)); + attrDurationNStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(durationNStdExample1)); + attrDurationMsecs = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(durationMsecs)); + attrDurationCrossover = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(durationCrossover)); + + // misc bad + attrBlank = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue("")); + attrNull = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(null)); + attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234)); + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + FunctionDefinitionDateTimeArithmetic fd = (FunctionDefinitionDateTimeArithmetic) StdFunctions.FD_DATE_ADD_YEARMONTHDURATION; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DATE_ADD_YEARMONTHDURATION, fd.getId()); + assertEquals(DataTypes.DT_DATE.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + // Duration = 0 => same as original + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrDuration0); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601Date.class, res.getValue().getValue().getClass()); + ISO8601Date resValue = (ISO8601Date)res.getValue().getValue(); + assertEquals(dateTimeStdExample1, resValue); + + + // simple positive operation + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601Date.class, res.getValue().getValue().getClass()); + resValue = (ISO8601Date)res.getValue().getValue(); + ISO8601Date testResponse = new ISO8601Date(2005, 8, 12); + assertEquals(testResponse, resValue); + + // negative operation + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrDurationNStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601Date.class, res.getValue().getValue().getClass()); + resValue = (ISO8601Date)res.getValue().getValue(); + testResponse = new ISO8601Date(1994, 6, 12); + assertEquals(testResponse, resValue); + + // millisecs work correctly (not relevant to YearMonth, but should not break + arguments.clear(); + arguments.add(attrDateTimeMsecs); + arguments.add(attrDurationMsecs); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601Date.class, res.getValue().getValue().getClass()); + resValue = (ISO8601Date)res.getValue().getValue(); + testResponse = new ISO8601Date(2005, 8, 12); + assertEquals(testResponse, resValue); + + // cross minute => cross day => cross month => cross year + arguments.clear(); + arguments.add(attrDateTimeCrossover); + arguments.add(attrDurationCrossover); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601Date.class, res.getValue().getValue().getClass()); + resValue = (ISO8601Date)res.getValue().getValue(); + testResponse = new ISO8601Date(2001, 1, 31); + assertEquals(testResponse, resValue); + + // negative (BC) original date add goes the right direction + arguments.clear(); + arguments.add(attrDateTimeBC); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601Date.class, res.getValue().getValue().getClass()); + resValue = (ISO8601Date)res.getValue().getValue(); + testResponse = new ISO8601Date(-1995, 8, 12); + assertEquals(testResponse, resValue); + + // non-null timezone not changed + // original has timezone offset = 0 + arguments.clear(); + arguments.add(attrDateTimeTimeZone0); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601Date.class, res.getValue().getValue().getClass()); + resValue = (ISO8601Date)res.getValue().getValue(); + testResponse = new ISO8601Date(timeZone0, 2005, 8, 12); + assertEquals(testResponse, resValue); + + // original has timezone offset not 0 + arguments.clear(); + arguments.add(attrDateTimeTimeZone5); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601Date.class, res.getValue().getValue().getClass()); + resValue = (ISO8601Date)res.getValue().getValue(); + testResponse = new ISO8601Date(timeZone5, 2005, 8, 12); + assertEquals(testResponse, resValue); + + // empty non-null first arg + arguments.clear(); + arguments.add(attrBlank); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:date-add-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // empty non-null second arg + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:date-add-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // two blanks + arguments.clear(); + arguments.add(attrBlank); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:date-add-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null firat arg + arguments.clear(); + arguments.add(attrNull); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:date-add-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null second arg + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrNull); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:date-add-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrInteger); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:date-add-yearMonthDuration Expected data type 'date' saw 'integer'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null second arg + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrNull); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:date-add-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + + + + + + @Test + public void testDate_subtract_yearMonthDuration() { + // Date objects to be adjusted + ISO8601Date dateTimeStdExample1 =new ISO8601Date(2000, 1, 12); + ISO8601Date dateTimeMsecs = new ISO8601Date(2000, 1, 12); + ISO8601Date dateTimeCrossover = new ISO8601Date(2000, 1, 1); + ISO8601Date dateTimeBC = new ISO8601Date(-2000, 1, 12); + ISO8601TimeZone timeZone0 = new ISO8601TimeZone(0); + ISO8601TimeZone timeZone5 = new ISO8601TimeZone(5 * 60); + ISO8601Date dateTimeTimeZone0 = new ISO8601Date(timeZone0, 2000, 1, 12); + ISO8601Date dateTimeTimeZone5 = new ISO8601Date(timeZone5, 2000, 1, 12); + + // Durations + XPathYearMonthDuration duration0 = new XPathYearMonthDuration(1, 0, 0); + XPathYearMonthDuration durationStdExample1 = new XPathYearMonthDuration(1, 5, 7); + XPathYearMonthDuration durationNStdExample1 = new XPathYearMonthDuration(-1, 5, 7); + XPathYearMonthDuration durationMsecs = new XPathYearMonthDuration(1, 5, 7); + XPathYearMonthDuration durationCrossover = new XPathYearMonthDuration(1, 0, 1); + + // ARGS declarations + // Dates + FunctionArgumentAttributeValue attrDateTimeStdExample1 = null; + FunctionArgumentAttributeValue attrDateTimeMsecs = null; + FunctionArgumentAttributeValue attrDateTimeCrossover = null; + FunctionArgumentAttributeValue attrDateTimeBC = null; + FunctionArgumentAttributeValue attrDateTimeTimeZone0 = null; + FunctionArgumentAttributeValue attrDateTimeTimeZone5 = null; + + // Durations + FunctionArgumentAttributeValue attrDuration0 = null; + FunctionArgumentAttributeValue attrDurationStdExample1 = null; + FunctionArgumentAttributeValue attrDurationNStdExample1 = null; + FunctionArgumentAttributeValue attrDurationMsecs = null; + FunctionArgumentAttributeValue attrDurationCrossover = null; + + // misc bad + FunctionArgumentAttributeValue attrNull = null; + FunctionArgumentAttributeValue attrBlank = null; + FunctionArgumentAttributeValue attrInteger = null; + // set values + try { + // Date attrs + attrDateTimeStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(dateTimeStdExample1)); + attrDateTimeMsecs = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(dateTimeMsecs)); + attrDateTimeCrossover = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(dateTimeCrossover)); + attrDateTimeBC = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(dateTimeBC)); + attrDateTimeTimeZone0 = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(dateTimeTimeZone0)); + attrDateTimeTimeZone5 = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(dateTimeTimeZone5)); + + // Duration attrs + attrDuration0 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(duration0)); + attrDurationStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(durationStdExample1)); + attrDurationNStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(durationNStdExample1)); + attrDurationMsecs = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(durationMsecs)); + attrDurationCrossover = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(durationCrossover)); + + // misc bad + attrBlank = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue("")); + attrNull = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(null)); + attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234)); + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + FunctionDefinitionDateTimeArithmetic fd = (FunctionDefinitionDateTimeArithmetic) StdFunctions.FD_DATE_SUBTRACT_YEARMONTHDURATION; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DATE_SUBTRACT_YEARMONTHDURATION, fd.getId()); + assertEquals(DataTypes.DT_DATE.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + // Duration = 0 => same as original + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrDuration0); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601Date.class, res.getValue().getValue().getClass()); + ISO8601Date resValue = (ISO8601Date)res.getValue().getValue(); + assertEquals(dateTimeStdExample1, resValue); + + + // simple positive operation + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601Date.class, res.getValue().getValue().getClass()); + resValue = (ISO8601Date)res.getValue().getValue(); + ISO8601Date testResponse = new ISO8601Date(1994, 6, 12); + assertEquals(testResponse, resValue); + + // negative operation + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrDurationNStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601Date.class, res.getValue().getValue().getClass()); + resValue = (ISO8601Date)res.getValue().getValue(); + testResponse = new ISO8601Date(2005, 8, 12); + assertEquals(testResponse, resValue); + + // millisecs work correctly (not relevant to YearMonth, but should not break + arguments.clear(); + arguments.add(attrDateTimeMsecs); + arguments.add(attrDurationMsecs); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601Date.class, res.getValue().getValue().getClass()); + resValue = (ISO8601Date)res.getValue().getValue(); + testResponse = new ISO8601Date(1994, 6, 12); + assertEquals(testResponse, resValue); + + // cross minute => cross day => cross month => cross year + arguments.clear(); + arguments.add(attrDateTimeCrossover); + arguments.add(attrDurationCrossover); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601Date.class, res.getValue().getValue().getClass()); + resValue = (ISO8601Date)res.getValue().getValue(); + testResponse = new ISO8601Date(1999, 12, 1); + assertEquals(testResponse, resValue); + + // negative (BC) original date add goes the right direction + arguments.clear(); + arguments.add(attrDateTimeBC); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601Date.class, res.getValue().getValue().getClass()); + resValue = (ISO8601Date)res.getValue().getValue(); + testResponse = new ISO8601Date(-2006, 6, 12); + assertEquals(testResponse, resValue); + + // non-null timezone not changed + // original has timezone offset = 0 + arguments.clear(); + arguments.add(attrDateTimeTimeZone0); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601Date.class, res.getValue().getValue().getClass()); + resValue = (ISO8601Date)res.getValue().getValue(); + testResponse = new ISO8601Date(timeZone0, 1994, 6, 12); + assertEquals(testResponse, resValue); + + // original has timezone offset not 0 + arguments.clear(); + arguments.add(attrDateTimeTimeZone5); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(com.att.research.xacml.std.datatypes.ISO8601Date.class, res.getValue().getValue().getClass()); + resValue = (ISO8601Date)res.getValue().getValue(); + testResponse = new ISO8601Date(timeZone5, 1994, 6, 12); + assertEquals(testResponse, resValue); + + // empty non-null first arg + arguments.clear(); + arguments.add(attrBlank); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:date-subtract-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // empty non-null second arg + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:date-subtract-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // two blanks + arguments.clear(); + arguments.add(attrBlank); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:date-subtract-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null firat arg + arguments.clear(); + arguments.add(attrNull); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:date-subtract-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null second arg + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrNull); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:date-subtract-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrInteger); + arguments.add(attrDurationStdExample1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:date-subtract-yearMonthDuration Expected data type 'date' saw 'integer'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null second arg + arguments.clear(); + arguments.add(attrDateTimeStdExample1); + arguments.add(attrNull); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:date-subtract-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + + +} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionEqualityTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionEqualityTest.java new file mode 100644 index 000000000..52f065ff8 --- /dev/null +++ b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionEqualityTest.java @@ -0,0 +1,1192 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-TEST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.std.functions; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.net.URI; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.List; + +import javax.security.auth.x500.X500Principal; + +import org.junit.Test; + +import com.att.research.xacml.api.XACML1; +import com.att.research.xacml.api.XACML3; +import com.att.research.xacml.std.datatypes.Base64Binary; +import com.att.research.xacml.std.datatypes.DataTypeRFC822Name; +import com.att.research.xacml.std.datatypes.DataTypes; +import com.att.research.xacml.std.datatypes.HexBinary; +import com.att.research.xacml.std.datatypes.RFC822Name; +import com.att.research.xacml.std.datatypes.XPathDayTimeDuration; +import com.att.research.xacml.std.datatypes.XPathYearMonthDuration; +import com.att.research.xacmlatt.pdp.policy.ExpressionResult; +import com.att.research.xacmlatt.pdp.policy.FunctionArgument; +import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; +import com.att.research.xacmlatt.pdp.std.StdFunctions; +import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionEquality; + +/** + * Test FunctionDefinitionEquality, all of its super-classes, and all XACML functions supported by that class. + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * In the first implementation of XACML we had separate files for each XACML Function. + * This release combines multiple Functions in fewer files to minimize code duplication. + * This file supports the following XACML codes: + * string-equal + * boolean-equal + * integer-equal + * double-equal + * date-equal + * time-equal + * dateTime-equal + * dayTimeDuration-equal + * yearMonthDuration-equal + * + * Each of these is put into a separate test method just to keep things organized. + * + * + */ +public class FunctionDefinitionEqualityTest { + + /* + * variables useful in the following tests + */ + List arguments = new ArrayList(); + + FunctionArgumentAttributeValue stringAttr1 = null; + FunctionArgumentAttributeValue stringAttr2 = null; + FunctionArgumentAttributeValue stringAttr3 = null; + FunctionArgumentAttributeValue stringAttr4 = null; + + FunctionArgumentAttributeValue booleanAttrT1 = null; + FunctionArgumentAttributeValue booleanAttrT2 = null; + FunctionArgumentAttributeValue booleanAttrF1 = null; + FunctionArgumentAttributeValue booleanAttrF2 = null; + + FunctionArgumentAttributeValue intAttr1 = null; + FunctionArgumentAttributeValue intAttr1a = null; + FunctionArgumentAttributeValue intAttr2 = null; + FunctionArgumentAttributeValue intAttr0 = null; + FunctionArgumentAttributeValue intAttrNeg1 = null; + + public FunctionDefinitionEqualityTest() { + try { + stringAttr1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("abc")); + stringAttr2 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("abc")); + stringAttr3 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("ABC")); + stringAttr4 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("def")); + + booleanAttrT1 = new FunctionArgumentAttributeValue(DataTypes.DT_BOOLEAN.createAttributeValue(true)); + booleanAttrT2 = new FunctionArgumentAttributeValue(DataTypes.DT_BOOLEAN.createAttributeValue(true)); + booleanAttrF1 = new FunctionArgumentAttributeValue(DataTypes.DT_BOOLEAN.createAttributeValue(false)); + booleanAttrF2 = new FunctionArgumentAttributeValue(DataTypes.DT_BOOLEAN.createAttributeValue(false)); + + intAttr1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1)); + intAttr1a = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1)); + intAttr2 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(2)); + intAttr0 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(0)); + intAttrNeg1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(-1)); + } catch (Exception e) { + fail("creating attribute e="+ e); + } + } + + + + + /** + * String (matching case) + */ + @Test + public void testString_Equal() { + + // String exact match + FunctionDefinitionEquality fd = (FunctionDefinitionEquality) StdFunctions.FD_STRING_EQUAL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_EQUAL, fd.getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // test normal equals and non-equals + // check "abc" with "abc" - separate string objects with same value + arguments.add(stringAttr1); + arguments.add(stringAttr2); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // check "abc" with "ABC" (not same) + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(stringAttr3); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // test bad args data types? Not needed? + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(intAttr1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + + } + + + + /** + * Boolean + */ + @Test + public void testBoolean_Equal() { + + // String exact match + FunctionDefinitionEquality fd = (FunctionDefinitionEquality) StdFunctions.FD_BOOLEAN_EQUAL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_BOOLEAN_EQUAL, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // test normal equals and non-equals + // check separate objects with same value + arguments.add(booleanAttrT1); + arguments.add(booleanAttrT2); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // check different values + arguments.clear(); + arguments.add(booleanAttrT1); + arguments.add(booleanAttrF1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // test bad args data types? Not needed? + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(intAttr1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + + } + + + /** + * Integer + */ + @Test + public void testInteger_Equal() { + + // String exact match + FunctionDefinitionEquality fd = (FunctionDefinitionEquality) StdFunctions.FD_INTEGER_EQUAL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_INTEGER_EQUAL, fd.getId()); + assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // test normal equals and non-equals + // check separate objects with same value + arguments.add(intAttr1); + arguments.add(intAttr1a); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // check not same + arguments.clear(); + arguments.add(intAttr1); + arguments.add(intAttr2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + arguments.clear(); + arguments.add(intAttr1); + arguments.add(intAttrNeg1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + + // test bad args data types? Not needed? + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(intAttr1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + + } + + + + /** + * Double + */ + @Test + public void testDouble_Equal() { + FunctionArgumentAttributeValue attr1 = null; + FunctionArgumentAttributeValue attr1a = null; + FunctionArgumentAttributeValue attr2 = null; + FunctionArgumentAttributeValue attrNeg1 = null; + try { + attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.0)); + attr1a = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.0)); + attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(2.4)); + attrNeg1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(-1.0)); + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + // String exact match + FunctionDefinitionEquality fd = (FunctionDefinitionEquality) StdFunctions.FD_DOUBLE_EQUAL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DOUBLE_EQUAL, fd.getId()); + assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // test normal equals and non-equals + // check separate objects with the same value + arguments.add(attr1); + arguments.add(attr1a); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // check not same + arguments.clear(); + arguments.add(attr1); + arguments.add(attr2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + arguments.clear(); + arguments.add(attr1); + arguments.add(attrNeg1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + + // test bad args data types? Not needed? + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(intAttr1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + + } + + + + + + /** + * Date + */ + @Test + public void testDate_Equal() { + Calendar calendar = Calendar.getInstance(); + Date today = calendar.getTime(); + Date longAgo = new Date(1234); + // create a date that is different than "today" but within the same day (i.e. has a different hour) + if (calendar.get(Calendar.HOUR_OF_DAY) > 3) { + calendar.set(Calendar.HOUR_OF_DAY, 3); + } else { + calendar.set(Calendar.HOUR_OF_DAY, 5); + } + Date todayPlus = calendar.getTime(); + + + FunctionArgumentAttributeValue attrToday = null; + FunctionArgumentAttributeValue attrToday2 = null; + FunctionArgumentAttributeValue attrLaterToday = null; + FunctionArgumentAttributeValue attrYesterday = null; + try { + attrToday = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(today)); + attrToday2 = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(today)); + attrLaterToday = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(todayPlus)); + attrYesterday = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(longAgo)); + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + // String exact match + FunctionDefinitionEquality fd = (FunctionDefinitionEquality) StdFunctions.FD_DATE_EQUAL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DATE_EQUAL, fd.getId()); + assertEquals(DataTypes.DT_DATE.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // test normal equals and non-equals + // check separate objects with the same value + arguments.add(attrToday); + arguments.add(attrToday2); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // check not same + arguments.clear(); + arguments.add(attrToday); + arguments.add(attrYesterday); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // Date objects with different times but within the same day should match + arguments.clear(); + arguments.add(attrToday); + arguments.add(attrLaterToday); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // test bad args data types? Not needed? + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(intAttr1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + + } + + + + + /** + * Time + */ + @Test + public void testTime_Equal() { + + Date now = new Date(); + Date now2 = new Date(now.getTime()); + Date notNow = new Date(now.getTime() - 100000); + + FunctionArgumentAttributeValue attrNow = null; + FunctionArgumentAttributeValue attrNow2 = null; + FunctionArgumentAttributeValue attrNotNow = null; + try { + attrNow = new FunctionArgumentAttributeValue(DataTypes.DT_TIME.createAttributeValue(now)); + attrNow2 = new FunctionArgumentAttributeValue(DataTypes.DT_TIME.createAttributeValue(now2)); + attrNotNow = new FunctionArgumentAttributeValue(DataTypes.DT_TIME.createAttributeValue(notNow)); + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + // String exact match + FunctionDefinitionEquality fd = (FunctionDefinitionEquality) StdFunctions.FD_TIME_EQUAL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_TIME_EQUAL, fd.getId()); + assertEquals(DataTypes.DT_TIME.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // test normal equals and non-equals + // check separate objects with the same value + arguments.add(attrNow); + arguments.add(attrNow2); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // check not same + arguments.clear(); + arguments.add(attrNow); + arguments.add(attrNotNow); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // test bad args data types? Not needed? + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(intAttr1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + + } + + + + + /** + * DateTime + */ + @Test + public void testDateTime_Equal() { + Calendar calendar = Calendar.getInstance(); + Date today = calendar.getTime(); + Date longAgo = new Date(1234); + // create a dateTime that is different than "today" changing only the Timezone + if (calendar.get(Calendar.ZONE_OFFSET) > 3) { + calendar.set(Calendar.ZONE_OFFSET, 3); + } else { + calendar.set(Calendar.ZONE_OFFSET, 5); + } + Date todayPlus = calendar.getTime(); + + + FunctionArgumentAttributeValue attrToday = null; + FunctionArgumentAttributeValue attrToday2 = null; + FunctionArgumentAttributeValue attrLaterToday = null; + FunctionArgumentAttributeValue attrYesterday = null; + try { + attrToday = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(today)); + attrToday2 = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(today)); + attrLaterToday = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(todayPlus)); + attrYesterday = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(longAgo)); + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + // String exact match + FunctionDefinitionEquality fd = (FunctionDefinitionEquality) StdFunctions.FD_DATETIME_EQUAL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DATETIME_EQUAL, fd.getId()); + assertEquals(DataTypes.DT_DATETIME.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // test normal equals and non-equals + // check separate objects with the same value + arguments.add(attrToday); + arguments.add(attrToday2); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // check not same + arguments.clear(); + arguments.add(attrToday); + arguments.add(attrYesterday); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // DateTime with different Zones should not match + arguments.clear(); + arguments.add(attrToday); + arguments.add(attrLaterToday); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // test bad args data types? Not needed? + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(intAttr1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + + } + + + /** + * dayTimeDuration - Version1 + */ + @Test + public void testDayTimeDuration_Equal_V1() { + + XPathDayTimeDuration dur1 = new XPathDayTimeDuration(1, 3, 5, 12, 38); + XPathDayTimeDuration dur2 = new XPathDayTimeDuration(1, 3, 5, 12, 38); + XPathDayTimeDuration differentDur = new XPathDayTimeDuration(-1, 4, 7, 5, 33); + + FunctionArgumentAttributeValue attrDur1 = null; + FunctionArgumentAttributeValue attrDur2 = null; + FunctionArgumentAttributeValue attrDifferentDur = null; + try { + attrDur1 = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(dur1)); + attrDur2 = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(dur2)); + attrDifferentDur = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(differentDur)); + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionEquality fd = (FunctionDefinitionEquality) StdFunctions.FD_DAYTIMEDURATION_EQUAL_VERSION1; + + // check identity and type of the thing created + assertEquals(XACML1.ID_FUNCTION_DAYTIMEDURATION_EQUAL, fd.getId()); + assertEquals(DataTypes.DT_DAYTIMEDURATION.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // test normal equals and non-equals + // check separate objects with the same value + arguments.add(attrDur1); + arguments.add(attrDur2); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // check not same + arguments.clear(); + arguments.add(attrDur1); + arguments.add(attrDifferentDur); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // test bad args data types? Not needed? + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(intAttr1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + + } + + + /** + * dayTimeDuration - Current version + */ + @Test + public void testDayTimeDuration_Equal() { + + XPathDayTimeDuration dur1 = new XPathDayTimeDuration(1, 3, 5, 12, 38); + XPathDayTimeDuration dur2 = new XPathDayTimeDuration(1, 3, 5, 12, 38); + XPathDayTimeDuration differentDur = new XPathDayTimeDuration(-1, 4, 7, 5, 33); + + FunctionArgumentAttributeValue attrDur1 = null; + FunctionArgumentAttributeValue attrDur2 = null; + FunctionArgumentAttributeValue attrDifferentDur = null; + try { + attrDur1 = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(dur1)); + attrDur2 = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(dur2)); + attrDifferentDur = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(differentDur)); + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionEquality fd = (FunctionDefinitionEquality) StdFunctions.FD_DAYTIMEDURATION_EQUAL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DAYTIMEDURATION_EQUAL, fd.getId()); + assertEquals(DataTypes.DT_DAYTIMEDURATION.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // test normal equals and non-equals + // check separate objects with the same value + arguments.add(attrDur1); + arguments.add(attrDur2); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // check not same + arguments.clear(); + arguments.add(attrDur1); + arguments.add(attrDifferentDur); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // test bad args data types? Not needed? + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(intAttr1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + + } + + + + /** + * dayTimeDuration - Version1 + */ + @Test + public void testYearMonthDuration_Equal_V1() { + + XPathYearMonthDuration dur1 = new XPathYearMonthDuration(1, 3, 5); + XPathYearMonthDuration dur2 = new XPathYearMonthDuration(1, 3, 5); + XPathYearMonthDuration differentDur = new XPathYearMonthDuration(-1, 4, 7); + + FunctionArgumentAttributeValue attrDur1 = null; + FunctionArgumentAttributeValue attrDur2 = null; + FunctionArgumentAttributeValue attrDifferentDur = null; + try { + attrDur1 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(dur1)); + attrDur2 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(dur2)); + attrDifferentDur = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(differentDur)); + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionEquality fd = (FunctionDefinitionEquality) StdFunctions.FD_YEARMONTHDURATION_EQUAL_VERSION1; + + // check identity and type of the thing created + assertEquals(XACML1.ID_FUNCTION_YEARMONTHDURATION_EQUAL, fd.getId()); + assertEquals(DataTypes.DT_YEARMONTHDURATION.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // test normal equals and non-equals + // check separate objects with the same value + arguments.add(attrDur1); + arguments.add(attrDur2); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // check not same + arguments.clear(); + arguments.add(attrDur1); + arguments.add(attrDifferentDur); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // test bad args data types? Not needed? + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(intAttr1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + + } + + + + + /** + * dayTimeDuration - Current version + */ + @Test + public void testYearMonthDuration_Equal() { + + XPathYearMonthDuration dur1 = new XPathYearMonthDuration(1, 3, 5); + XPathYearMonthDuration dur2 = new XPathYearMonthDuration(1, 3, 5); + XPathYearMonthDuration differentDur = new XPathYearMonthDuration(-1, 4, 7); + + FunctionArgumentAttributeValue attrDur1 = null; + FunctionArgumentAttributeValue attrDur2 = null; + FunctionArgumentAttributeValue attrDifferentDur = null; + try { + attrDur1 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(dur1)); + attrDur2 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(dur2)); + attrDifferentDur = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(differentDur)); + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionEquality fd = (FunctionDefinitionEquality) StdFunctions.FD_YEARMONTHDURATION_EQUAL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_YEARMONTHDURATION_EQUAL, fd.getId()); + assertEquals(DataTypes.DT_YEARMONTHDURATION.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // test normal equals and non-equals + // check separate objects with the same value + arguments.add(attrDur1); + arguments.add(attrDur2); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // check not same + arguments.clear(); + arguments.add(attrDur1); + arguments.add(attrDifferentDur); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // test bad args data types? Not needed? + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(intAttr1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + + } + + + /** + * URI + */ + @Test + public void testAnyURI_Equal() { + + URI uri1 = null; + URI uri2 = null; + URI uriNotThere = null; + try { + uri1 = new URI("http://someplace.com/gothere"); + uri2 = new URI("http://someplace.com/gothere"); + uriNotThere = new URI("http://someplace.com/notGoingThere"); + } catch (Exception e) { + fail(e.toString()); + } + + FunctionArgumentAttributeValue attrUri1 = null; + FunctionArgumentAttributeValue attrUri2 = null; + FunctionArgumentAttributeValue attrUriNotThere = null; + try { + attrUri1 = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(uri1)); + attrUri2 = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(uri2)); + attrUriNotThere = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(uriNotThere)); + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionEquality fd = (FunctionDefinitionEquality) StdFunctions.FD_ANYURI_EQUAL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_ANYURI_EQUAL, fd.getId()); + assertEquals(DataTypes.DT_ANYURI.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // test normal equals and non-equals + // check separate objects with the same value + arguments.add(attrUri1); + arguments.add(attrUri2); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // check not same + arguments.clear(); + arguments.add(attrUri1); + arguments.add(attrUriNotThere); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // test bad args data types? Not needed? + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(intAttr1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + + } + + + /** + * X500Name + */ + @Test + public void testX500Name_Equal() { + + X500Principal name1 = new X500Principal("CN=Duke, OU=JavaSoft, O=Sun Microsystems, C=US"); + X500Principal name2 = new X500Principal("CN=Duke, OU=JavaSoft, O=Sun Microsystems, C=US"); + X500Principal name3 = new X500Principal("CN=NotDuke, OU=NotThere, O=Oracle, C=US"); + + + FunctionArgumentAttributeValue attrName1 = null; + FunctionArgumentAttributeValue attrName1a = null; + FunctionArgumentAttributeValue attrNotSameName = null; + try { + attrName1 = new FunctionArgumentAttributeValue(DataTypes.DT_X500NAME.createAttributeValue(name1)); + attrName1a = new FunctionArgumentAttributeValue(DataTypes.DT_X500NAME.createAttributeValue(name2)); + attrNotSameName = new FunctionArgumentAttributeValue(DataTypes.DT_X500NAME.createAttributeValue(name3)); + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionEquality fd = (FunctionDefinitionEquality) StdFunctions.FD_X500NAME_EQUAL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_X500NAME_EQUAL, fd.getId()); + assertEquals(DataTypes.DT_X500NAME.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // test normal equals and non-equals + // check separate objects with the same value + arguments.add(attrName1); + arguments.add(attrName1a); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // check not same + arguments.clear(); + arguments.add(attrName1); + arguments.add(attrNotSameName); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // test bad args data types? Not needed? + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(intAttr1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + + } + + + + /** + * RFC822Name + */ + @Test + public void testRfc822Name_Equal() { + + RFC822Name name1 = null; + RFC822Name name1a = null; + RFC822Name differentLocalName = null; + RFC822Name differentDomainName = null; + RFC822Name localCaseName = null; + RFC822Name domainCaseName = null; + @SuppressWarnings("unused") + RFC822Name noAtName = null; + + try { + name1 = RFC822Name.newInstance("localPart@DomainPart"); + name1a = RFC822Name.newInstance("localPart@DomainPart"); + differentLocalName = RFC822Name.newInstance("differentlocalPart@DomainPart"); + differentDomainName = RFC822Name.newInstance("localPart@differentDomainPart"); + localCaseName = RFC822Name.newInstance("LOCALPart@DomainPart"); + domainCaseName = RFC822Name.newInstance("localPart@DOMAINPart"); + + + } catch (Exception e) { + fail(e.toString()); + } + + // should not be able to create a name without an @. If you try, newInstance returns null + Exception exSeen = null; + try { + noAtName = RFC822Name.newInstance("nameWithoutAnAtSign"); + } catch (Exception e) { + exSeen = e; + } + assertNotNull(exSeen); + + + FunctionArgumentAttributeValue attrName1 = null; + FunctionArgumentAttributeValue attrName1a = null; + FunctionArgumentAttributeValue attrDifferentLocalName = null; + FunctionArgumentAttributeValue attrDifferentDomainName = null; + FunctionArgumentAttributeValue attrLocalCaseName = null; + FunctionArgumentAttributeValue attrDomainCaseName = null; + try { + attrName1 = new FunctionArgumentAttributeValue(DataTypes.DT_RFC822NAME.createAttributeValue(name1)); + attrName1a = new FunctionArgumentAttributeValue(DataTypes.DT_RFC822NAME.createAttributeValue(name1a)); + attrDifferentLocalName = new FunctionArgumentAttributeValue(DataTypes.DT_RFC822NAME.createAttributeValue(differentLocalName)); + attrDifferentDomainName = new FunctionArgumentAttributeValue(DataTypes.DT_RFC822NAME.createAttributeValue(differentDomainName)); + attrLocalCaseName = new FunctionArgumentAttributeValue(DataTypes.DT_RFC822NAME.createAttributeValue(localCaseName)); + attrDomainCaseName = new FunctionArgumentAttributeValue(DataTypes.DT_RFC822NAME.createAttributeValue(domainCaseName)); + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionEquality fd = (FunctionDefinitionEquality) StdFunctions.FD_RFC822NAME_EQUAL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_RFC822NAME_EQUAL, fd.getId()); + assertEquals(DataTypeRFC822Name.newInstance().getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // test normal equals and non-equals + // check separate objects with the same value + arguments.add(attrName1); + arguments.add(attrName1a); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // check not same Local + arguments.clear(); + arguments.add(attrName1); + arguments.add(attrDifferentLocalName); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // check not same Domain + arguments.clear(); + arguments.add(attrName1); + arguments.add(attrDifferentDomainName); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // test case-sensitivity in local part + arguments.clear(); + arguments.add(attrName1); + arguments.add(attrLocalCaseName); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // test non-case-sensitivity in Domain part + arguments.clear(); + arguments.add(attrName1); + arguments.add(attrDomainCaseName); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // test bad args data types? Not needed? + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(intAttr1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + + } + + + /** + * Hex Binary + */ + @Test + public void testHexBinary_Equal() { + HexBinary binary = null; + HexBinary sameBinary = null; + HexBinary differentBinary = null; + try { + binary = HexBinary.newInstance("e04fd020ea3a6910a2d808002b30309d"); + sameBinary = HexBinary.newInstance("e04fd020ea3a6910a2d808002b30309d"); + differentBinary = HexBinary.newInstance("f123a890ee3d"); + } catch (Exception e) { + fail(e.toString()); + } + + FunctionArgumentAttributeValue attrBinary = null; + FunctionArgumentAttributeValue attrSameBinary = null; + FunctionArgumentAttributeValue attrDifferentBinary = null;; + try { + attrBinary = new FunctionArgumentAttributeValue(DataTypes.DT_HEXBINARY.createAttributeValue(binary)); + attrSameBinary = new FunctionArgumentAttributeValue(DataTypes.DT_HEXBINARY.createAttributeValue(sameBinary)); + attrDifferentBinary = new FunctionArgumentAttributeValue(DataTypes.DT_HEXBINARY.createAttributeValue(differentBinary)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionEquality fd = (FunctionDefinitionEquality) StdFunctions.FD_HEXBINARY_EQUAL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_HEXBINARY_EQUAL, fd.getId()); + assertEquals(DataTypes.DT_HEXBINARY.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // test normal equals and non-equals + // check separate objects with the same value + arguments.add(attrBinary); + arguments.add(attrSameBinary); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // check not same + arguments.clear(); + arguments.add(attrBinary); + arguments.add(attrDifferentBinary); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // test bad args data types? Not needed? + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(intAttr1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + + } + + + /** + * Base64 Binary + */ + @Test + public void testBase64Binary_Equal() { + Base64Binary binary = null; + Base64Binary sameBinary = null; + Base64Binary differentBinary = null; + try { + binary = Base64Binary.newInstance("TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz"); + sameBinary = Base64Binary.newInstance("TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz"); + differentBinary = Base64Binary.newInstance("f123a890ee3d"); + } catch (Exception e) { + fail(e.toString()); + } + + FunctionArgumentAttributeValue attrBinary = null; + FunctionArgumentAttributeValue attrSameBinary = null; + FunctionArgumentAttributeValue attrDifferentBinary = null; + try { + attrBinary = new FunctionArgumentAttributeValue(DataTypes.DT_BASE64BINARY.createAttributeValue(binary)); + attrSameBinary = new FunctionArgumentAttributeValue(DataTypes.DT_BASE64BINARY.createAttributeValue(sameBinary)); + attrDifferentBinary = new FunctionArgumentAttributeValue(DataTypes.DT_BASE64BINARY.createAttributeValue(differentBinary)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionEquality fd = (FunctionDefinitionEquality) StdFunctions.FD_BASE64BINARY_EQUAL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_BASE64BINARY_EQUAL, fd.getId()); + assertEquals(DataTypes.DT_BASE64BINARY.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + // test normal equals and non-equals + // check separate objects with the same value + arguments.add(attrBinary); + arguments.add(attrSameBinary); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // check not same + arguments.clear(); + arguments.add(attrBinary); + arguments.add(attrDifferentBinary); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // test bad args data types? Not needed? + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(intAttr1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + + } +} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionHigherOrderBagTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionHigherOrderBagTest.java new file mode 100644 index 000000000..64364e4b8 --- /dev/null +++ b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionHigherOrderBagTest.java @@ -0,0 +1,2193 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-TEST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.std.functions; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +import com.att.research.xacml.api.AttributeValue; +import com.att.research.xacml.api.XACML3; +import com.att.research.xacml.std.datatypes.DataTypes; +import com.att.research.xacmlatt.pdp.policy.Bag; +import com.att.research.xacmlatt.pdp.policy.ExpressionResult; +import com.att.research.xacmlatt.pdp.policy.FunctionArgument; +import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; +import com.att.research.xacmlatt.pdp.policy.FunctionArgumentBag; +import com.att.research.xacmlatt.pdp.std.StdFunctions; +import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionHigherOrderBag; + +/** + * Test of PDP Functions (See XACML core spec section A.3) + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * + */ +public class FunctionDefinitionHigherOrderBagTest { + + + /* + * variables useful in the following tests + */ + List arguments = new ArrayList(); + + + + // + // ANY-OF tests + // + + + @Test + public void testAny_of() { + String a = "a"; + String b = "b"; + String c = "c"; + String d = "d"; + String e = "e"; + String f = "f"; + String g = "g"; + String h = "h"; + String j = "j"; + + + Bag bagabcdefg = null; + Bag bagbdfhj = null; + Bag bagace = null; + Bag bagb = null; + Bag bagaaacccef = null; + Bag bagInt = null; + Bag bagStringInt = null; + Bag bagEmpty = null; + Bag bagStringBooleansTrue = null; + Bag bagStringBooleansFalse = null; + + + // primitive attrs + FunctionArgumentAttributeValue attra = null; + FunctionArgumentAttributeValue attrb = null; + FunctionArgumentAttributeValue attrh = null; + + + // predicates passed as arguments + FunctionArgumentAttributeValue attrPredicateStringEqual = null; + FunctionArgumentAttributeValue attrPredicateStringIntersection = null; + FunctionArgumentAttributeValue attrPredicateBooleanFromString = null; + + try { + + // Create Bag contents + bagabcdefg = new Bag(); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(d)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(g)); + bagbdfhj = new Bag(); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(d)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(h)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(j)); + bagace = new Bag(); + bagace.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagace.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagace.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagb = new Bag(); + bagb.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagaaacccef = new Bag(); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagInt = new Bag(); + bagInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); + bagStringInt = new Bag(); + bagStringInt.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagStringInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); + bagEmpty = new Bag(); + bagStringBooleansTrue = new Bag(); + bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("false")); + bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("false")); + bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("true")); + bagStringBooleansFalse = new Bag(); + bagStringBooleansFalse.add(DataTypes.DT_STRING.createAttributeValue("false")); + bagStringBooleansFalse.add(DataTypes.DT_STRING.createAttributeValue("false")); + + + // create primitive attrs + attra = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(a)); + attrb = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(b)); + attrh = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(h)); + + + // predicates passed as function arguments + attrPredicateStringEqual = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_EQUAL)); + attrPredicateStringIntersection = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_INTERSECTION)); + attrPredicateBooleanFromString = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_BOOLEAN_FROM_STRING)); + + } catch (Exception ex) { + fail("creating attribute e="+ ex); + } + + // make into attributes + FunctionArgumentBag attrBagabcdefg = new FunctionArgumentBag(bagabcdefg); + FunctionArgumentBag attrBagbdfhj = new FunctionArgumentBag(bagbdfhj); + FunctionArgumentBag attrBagace = new FunctionArgumentBag(bagace); + FunctionArgumentBag attrBagStringInt = new FunctionArgumentBag(bagStringInt); + FunctionArgumentBag attrBagEmpty = new FunctionArgumentBag(bagEmpty); + FunctionArgumentBag attrBagStringBooleansTrue = new FunctionArgumentBag(bagStringBooleansTrue); + FunctionArgumentBag attrBagStringBooleansFalse = new FunctionArgumentBag(bagStringBooleansFalse); + + FunctionDefinitionHigherOrderBag fd = (FunctionDefinitionHigherOrderBag) StdFunctions.FD_ANY_OF; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_ANY_OF, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + // normal match + arguments.clear(); + arguments.add(attrPredicateStringEqual); + arguments.add(attra); + arguments.add(attrBagabcdefg); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // bag in first position - match + arguments.clear(); + arguments.add(attrPredicateStringEqual); + arguments.add(attrBagabcdefg); + arguments.add(attra); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // normal no-match + arguments.clear(); + arguments.add(attrPredicateStringEqual); + arguments.add(attra); + arguments.add(attrBagbdfhj); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // multiple primitives + arguments.clear(); + arguments.add(attrPredicateStringEqual); + arguments.add(attrh); + arguments.add(attrb); + arguments.add(attrBagace); + arguments.add(attra); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of Predicate error: function:string-equal Expected 2 arguments, got 4", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // no primitives - predicate function expects 2 + arguments.clear(); + arguments.add(attrPredicateStringEqual); + arguments.add(attrBagace); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of Predicate error: function:string-equal Expected 2 arguments, got 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // no primitives - predicate expects only 1 arg + arguments.clear(); + arguments.add(attrPredicateBooleanFromString); + arguments.add(attrBagStringBooleansTrue); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + arguments.clear(); + arguments.add(attrPredicateBooleanFromString); + arguments.add(attrBagStringBooleansFalse); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // bag is empty + arguments.clear(); + arguments.add(attrPredicateStringEqual); + arguments.add(attrh); + arguments.add(attrBagEmpty); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // no bag + arguments.clear(); + arguments.add(attrPredicateStringEqual); + arguments.add(attrh); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of Did not get any Bag argument; must have at least 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // extra bag + arguments.clear(); + arguments.add(attrPredicateStringEqual); + arguments.add(attrh); + arguments.add(attrBagStringBooleansTrue); + arguments.add(attrh); + arguments.add(attrBagStringBooleansTrue); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of must have only 1 bag; found one at index 2 and another at 4", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // bad predicate + arguments.clear(); + arguments.add(attrh); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of First argument expected URI, got http://www.w3.org/2001/XMLSchema#string", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // non-boolean predicate + arguments.clear(); + arguments.add(attrPredicateStringIntersection); + arguments.add(attrh); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of Predicate Function must return boolean, but 'urn:oasis:names:tc:xacml:1.0:function:string-intersection' returns 'string", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // predicate after first arg + arguments.clear(); + arguments.add(attrPredicateStringEqual); + arguments.add(attrPredicateStringIntersection); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of Predicate error: function:string-equal Expected data type 'string' saw 'anyURI' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bags of different types + arguments.clear(); + arguments.add(attrPredicateStringEqual); + arguments.add(attrh); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + + // first null + arguments.clear(); + arguments.add(null); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of Predicate Function (first argument) was null", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // second null + arguments.clear(); + arguments.add(attrPredicateStringEqual); + arguments.add(attrBagabcdefg); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of Got null argument at index 2", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + + + + @Test + public void testAll_of() { + String a = "a"; + String b = "b"; + String c = "c"; + String d = "d"; + String e = "e"; + String f = "f"; + String g = "g"; + String h = "h"; + String j = "j"; + + String w = "w"; + + + Bag bagabcdefg = null; + Bag bagbdfhj = null; + Bag bagace = null; + Bag bagb = null; + Bag bagaaacccef = null; + Bag bagInt = null; + Bag bagStringInt = null; + Bag bagEmpty = null; + Bag bagStringBooleansFalse = null; + Bag bagStringBooleansTrue = null; + + + // primitive attrs + FunctionArgumentAttributeValue attra = null; + FunctionArgumentAttributeValue attrh = null; + FunctionArgumentAttributeValue attrw = null; + + + + // predicates passed as arguments + FunctionArgumentAttributeValue attrPredicateStringEqual = null; + FunctionArgumentAttributeValue attrPredicateStringIntersection = null; + FunctionArgumentAttributeValue attrPredicateStringGreaterThan = null; + FunctionArgumentAttributeValue attrPredicateBooleanFromString = null; + + try { + + // Create Bag contents + bagabcdefg = new Bag(); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(d)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(g)); + bagbdfhj = new Bag(); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(d)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(h)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(j)); + bagace = new Bag(); + bagace.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagace.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagace.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagb = new Bag(); + bagb.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagaaacccef = new Bag(); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagInt = new Bag(); + bagInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); + bagStringInt = new Bag(); + bagStringInt.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagStringInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); + bagEmpty = new Bag(); + bagStringBooleansTrue = new Bag(); + bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("true")); + bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("true")); + bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("true")); + bagStringBooleansFalse = new Bag(); + bagStringBooleansFalse.add(DataTypes.DT_STRING.createAttributeValue("false")); + bagStringBooleansFalse.add(DataTypes.DT_STRING.createAttributeValue("false")); + + + + // create primitive attrs + attra = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(a)); + attrh = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(h)); + attrw = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(w)); + + + // predicates passed as function arguments + attrPredicateStringEqual = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_EQUAL)); + attrPredicateStringIntersection = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_INTERSECTION)); + attrPredicateStringGreaterThan = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_GREATER_THAN)); + attrPredicateBooleanFromString = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_BOOLEAN_FROM_STRING)); + + } catch (Exception ex) { + fail("creating attribute e="+ ex); + } + + // make into attributes + FunctionArgumentBag attrBagabcdefg = new FunctionArgumentBag(bagabcdefg); + FunctionArgumentBag attrBagbdfhj = new FunctionArgumentBag(bagbdfhj); + FunctionArgumentBag attrBagace = new FunctionArgumentBag(bagace); + FunctionArgumentBag attrBagStringInt = new FunctionArgumentBag(bagStringInt); + FunctionArgumentBag attrBagEmpty = new FunctionArgumentBag(bagEmpty); + FunctionArgumentBag attrBagStringBooleansTrue = new FunctionArgumentBag(bagStringBooleansTrue); + FunctionArgumentBag attrBagStringBooleansFalse = new FunctionArgumentBag(bagStringBooleansFalse); + + FunctionDefinitionHigherOrderBag fd = (FunctionDefinitionHigherOrderBag) StdFunctions.FD_ALL_OF; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_ALL_OF, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + // normal match + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrw); + arguments.add(attrBagace); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // normal no-match + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attra); + arguments.add(attrBagbdfhj); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // no primitives - predicate function expects 2 + arguments.clear(); + arguments.add(attrPredicateStringEqual); + arguments.add(attrBagace); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of Predicate error: function:string-equal Expected 2 arguments, got 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // no primitives - predicate expects only 1 arg + arguments.clear(); + arguments.add(attrPredicateBooleanFromString); + arguments.add(attrBagStringBooleansTrue); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + arguments.clear(); + arguments.add(attrPredicateBooleanFromString); + arguments.add(attrBagStringBooleansFalse); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // bag is empty + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrh); + arguments.add(attrBagEmpty); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // no bag + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrh); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of Did not get any Bag argument; must have at least 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // extra bag + arguments.clear(); + arguments.add(attrPredicateStringEqual); + arguments.add(attrh); + arguments.add(attrBagStringBooleansTrue); + arguments.add(attrh); + arguments.add(attrBagStringBooleansTrue); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of must have only 1 bag; found one at index 2 and another at 4", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // bad predicate + arguments.clear(); + arguments.add(attrh); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of First argument expected URI, got http://www.w3.org/2001/XMLSchema#string", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // non-boolean predicate + arguments.clear(); + arguments.add(attrPredicateStringIntersection); + arguments.add(attrh); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of Predicate Function must return boolean, but 'urn:oasis:names:tc:xacml:1.0:function:string-intersection' returns 'string", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // predicate after first arg + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrPredicateStringIntersection); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of Predicate error: function:string-greater-than Expected data type 'string' saw 'anyURI' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bags of different types + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrh); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + + // first null + arguments.clear(); + arguments.add(null); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of Predicate Function (first argument) was null", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // second null + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrBagabcdefg); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of Got null argument at index 2", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + + + + + + + + + + + + @Test + public void testAny_of_any() { + String a = "a"; + String b = "b"; + String c = "c"; + String d = "d"; + String e = "e"; + String f = "f"; + String g = "g"; + String h = "h"; + String j = "j"; + + String w = "w"; + + + Bag bagabcdefg = null; + Bag bagbdfhj = null; + Bag bagace = null; + Bag bagb = null; + Bag bagaaacccef = null; + Bag bagInt = null; + Bag bagStringInt = null; + Bag bagEmpty = null; + Bag bagStringBooleansFalse = null; + Bag bagStringBooleansTrue = null; + Bag bagBooleansFalse = null; + Bag bagBooleansTrue = null; + + + // primitive attrs + FunctionArgumentAttributeValue attra = null; + FunctionArgumentAttributeValue attrh = null; + FunctionArgumentAttributeValue attrw = null; + + + FunctionArgumentAttributeValue attrInt4 = null; + + + // predicates passed as arguments + FunctionArgumentAttributeValue attrPredicateStringEqual = null; + FunctionArgumentAttributeValue attrPredicateStringIntersection = null; + FunctionArgumentAttributeValue attrPredicateStringGreaterThan = null; + FunctionArgumentAttributeValue attrPredicateBooleanFromString = null; + FunctionArgumentAttributeValue attrPredicateNof = null; + + try { + + // Create Bag contents + bagabcdefg = new Bag(); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(d)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(g)); + bagbdfhj = new Bag(); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(d)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(h)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(j)); + bagace = new Bag(); + bagace.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagace.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagace.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagb = new Bag(); + bagb.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagaaacccef = new Bag(); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagInt = new Bag(); + bagInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); + bagStringInt = new Bag(); + bagStringInt.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagStringInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); + bagEmpty = new Bag(); + bagStringBooleansTrue = new Bag(); + bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("true")); + bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("false")); + bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("true")); + bagStringBooleansFalse = new Bag(); + bagStringBooleansFalse.add(DataTypes.DT_STRING.createAttributeValue("false")); + bagStringBooleansFalse.add(DataTypes.DT_STRING.createAttributeValue("false")); + bagBooleansTrue = new Bag(); + bagBooleansTrue.add(DataTypes.DT_BOOLEAN.createAttributeValue(false)); + bagBooleansTrue.add(DataTypes.DT_BOOLEAN.createAttributeValue(false)); + bagBooleansTrue.add(DataTypes.DT_BOOLEAN.createAttributeValue(true)); + bagBooleansFalse = new Bag(); + bagBooleansFalse.add(DataTypes.DT_BOOLEAN.createAttributeValue(false)); + bagBooleansFalse.add(DataTypes.DT_BOOLEAN.createAttributeValue(false)); + + + // create primitive attrs + attra = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(a)); + attrh = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(h)); + attrw = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(w)); + + attrInt4 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(4)); + + + // predicates passed as function arguments + attrPredicateStringEqual = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_EQUAL)); + attrPredicateStringIntersection = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_INTERSECTION)); + attrPredicateStringGreaterThan = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_GREATER_THAN)); + attrPredicateBooleanFromString = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_BOOLEAN_FROM_STRING)); + attrPredicateNof = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_N_OF)); + + } catch (Exception ex) { + fail("creating attribute e="+ ex); + } + + // make into attributes + FunctionArgumentBag attrBagabcdefg = new FunctionArgumentBag(bagabcdefg); + FunctionArgumentBag attrBagbdfhj = new FunctionArgumentBag(bagbdfhj); + FunctionArgumentBag attrBagace = new FunctionArgumentBag(bagace); + FunctionArgumentBag attrBagStringInt = new FunctionArgumentBag(bagStringInt); + FunctionArgumentBag attrBagEmpty = new FunctionArgumentBag(bagEmpty); + FunctionArgumentBag attrBagStringBooleansTrue = new FunctionArgumentBag(bagStringBooleansTrue); + FunctionArgumentBag attrBagStringBooleansFalse = new FunctionArgumentBag(bagStringBooleansFalse); + FunctionArgumentBag attrBagBooleansTrue = new FunctionArgumentBag(bagBooleansTrue); + FunctionArgumentBag attrBagBooleansFalse = new FunctionArgumentBag(bagBooleansFalse); + + FunctionDefinitionHigherOrderBag fd = (FunctionDefinitionHigherOrderBag) StdFunctions.FD_ANY_OF_ANY; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_ANY_OF_ANY, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + // normal match + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrw); + arguments.add(attrBagace); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // normal no-match + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attra); + arguments.add(attrBagbdfhj); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // no primitives - predicate function expects 2 + arguments.clear(); + arguments.add(attrPredicateStringEqual); + arguments.add(attrBagace); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of-any Predicate error: function:string-equal Expected 2 arguments, got 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + arguments.add(attrPredicateStringEqual); + arguments.add(attrBagace); + arguments.add(attrBagace); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // no primitives - predicate expects only 1 arg + arguments.clear(); + arguments.add(attrPredicateBooleanFromString); + arguments.add(attrBagStringBooleansTrue); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + arguments.clear(); + arguments.add(attrPredicateBooleanFromString); + arguments.add(attrBagStringBooleansFalse); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // n-of with lots of bags - success + arguments.clear(); + arguments.add(attrPredicateNof); + arguments.add(attrInt4); + arguments.add(attrBagBooleansTrue); + arguments.add(attrBagBooleansTrue); + arguments.add(attrBagBooleansTrue); + arguments.add(attrBagBooleansTrue); + arguments.add(attrBagBooleansTrue); + arguments.add(attrBagBooleansTrue); + arguments.add(attrBagBooleansTrue); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // n-of with lots of bags - fail + arguments.clear(); + arguments.add(attrPredicateNof); + arguments.add(attrInt4); + arguments.add(attrBagBooleansFalse); + arguments.add(attrBagBooleansFalse); + arguments.add(attrBagBooleansTrue); + arguments.add(attrBagBooleansTrue); + arguments.add(attrBagBooleansFalse); + arguments.add(attrBagBooleansFalse); + arguments.add(attrBagBooleansFalse); + arguments.add(attrBagBooleansFalse); + arguments.add(attrBagBooleansFalse); + arguments.add(attrBagBooleansFalse); + arguments.add(attrBagBooleansFalse); + arguments.add(attrBagBooleansFalse); + arguments.add(attrBagBooleansFalse); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + + // bag is empty + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrh); + arguments.add(attrBagEmpty); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of-any Bag is empty at index 2", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // no bag + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrh); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of-any Predicate error: function:string-greater-than Expected 2 arguments, got 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrh); + arguments.add(attrh); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // bad predicate + arguments.clear(); + arguments.add(attrh); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of-any First argument expected URI, got http://www.w3.org/2001/XMLSchema#string", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // non-boolean predicate + arguments.clear(); + arguments.add(attrPredicateStringIntersection); + arguments.add(attrh); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of-any Predicate Function must return boolean, but 'urn:oasis:names:tc:xacml:1.0:function:string-intersection' returns 'string", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // predicate after first arg + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrPredicateStringIntersection); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of-any Predicate error: function:string-greater-than Expected data type 'string' saw 'anyURI' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bags of different types + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrh); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // first null + arguments.clear(); + arguments.add(null); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of-any Predicate Function (first argument) was null", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // second null + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrBagabcdefg); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of-any Got null argument at index 2", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + + + + + + + + + + + + + + @Test + public void testAll_of_any() { + String a = "a"; + String b = "b"; + String c = "c"; + String d = "d"; + String e = "e"; + String f = "f"; + String g = "g"; + String h = "h"; + String j = "j"; + + String w = "w"; + String x = "x"; + + + Bag bagabcdefg = null; + Bag bagbdfhj = null; + Bag bagace = null; + Bag bagb = null; + Bag bagaaacccef = null; + Bag bagawx = null; + Bag bagInt = null; + Bag bagStringInt = null; + Bag bagEmpty = null; + Bag bagStringBooleansFalse = null; + Bag bagStringBooleansTrue = null; + Bag bagBooleansFalse = null; + Bag bagBooleansTrue = null; + + + // primitive attrs + FunctionArgumentAttributeValue attra = null; + FunctionArgumentAttributeValue attrh = null; + + + + + // predicates passed as arguments + FunctionArgumentAttributeValue attrPredicateStringEqual = null; + FunctionArgumentAttributeValue attrPredicateStringIntersection = null; + FunctionArgumentAttributeValue attrPredicateStringLessThan = null; + FunctionArgumentAttributeValue attrPredicateStringGreaterThan = null; + FunctionArgumentAttributeValue attrPredicateBooleanFromString = null; + + try { + + // Create Bag contents + bagabcdefg = new Bag(); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(d)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(g)); + bagbdfhj = new Bag(); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(d)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(h)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(j)); + bagace = new Bag(); + bagace.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagace.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagace.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagb = new Bag(); + bagb.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagaaacccef = new Bag(); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagawx = new Bag(); + bagawx.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagawx.add(DataTypes.DT_STRING.createAttributeValue(w)); + bagawx.add(DataTypes.DT_STRING.createAttributeValue(x)); + bagInt = new Bag(); + bagInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); + bagStringInt = new Bag(); + bagStringInt.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagStringInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); + bagEmpty = new Bag(); + bagStringBooleansTrue = new Bag(); + bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("true")); + bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("false")); + bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("true")); + bagStringBooleansFalse = new Bag(); + bagStringBooleansFalse.add(DataTypes.DT_STRING.createAttributeValue("false")); + bagStringBooleansFalse.add(DataTypes.DT_STRING.createAttributeValue("false")); + bagBooleansTrue = new Bag(); + bagBooleansTrue.add(DataTypes.DT_BOOLEAN.createAttributeValue(false)); + bagBooleansTrue.add(DataTypes.DT_BOOLEAN.createAttributeValue(false)); + bagBooleansTrue.add(DataTypes.DT_BOOLEAN.createAttributeValue(true)); + bagBooleansFalse = new Bag(); + bagBooleansFalse.add(DataTypes.DT_BOOLEAN.createAttributeValue(false)); + bagBooleansFalse.add(DataTypes.DT_BOOLEAN.createAttributeValue(false)); + + + // create primitive attrs + attra = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(a)); + attrh = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(h)); + + + + // predicates passed as function arguments + attrPredicateStringEqual = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_EQUAL)); + attrPredicateStringIntersection = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_INTERSECTION)); + attrPredicateStringLessThan = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_LESS_THAN)); + attrPredicateStringGreaterThan = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_GREATER_THAN)); + attrPredicateBooleanFromString = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_BOOLEAN_FROM_STRING)); + + } catch (Exception ex) { + fail("creating attribute e="+ ex); + } + + // make into attributes + FunctionArgumentBag attrBagabcdefg = new FunctionArgumentBag(bagabcdefg); + FunctionArgumentBag attrBagace = new FunctionArgumentBag(bagace); + FunctionArgumentBag attrBagawx = new FunctionArgumentBag(bagawx); + FunctionArgumentBag attrBagStringInt = new FunctionArgumentBag(bagStringInt); + FunctionArgumentBag attrBagEmpty = new FunctionArgumentBag(bagEmpty); + FunctionArgumentBag attrBagStringBooleansTrue = new FunctionArgumentBag(bagStringBooleansTrue); + + FunctionDefinitionHigherOrderBag fd = (FunctionDefinitionHigherOrderBag) StdFunctions.FD_ALL_OF_ANY; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_ALL_OF_ANY, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + // normal match + arguments.clear(); + arguments.add(attrPredicateStringLessThan); + arguments.add(attrBagabcdefg); + arguments.add(attrBagawx); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // normal no-match + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrBagace); + arguments.add(attrBagawx); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // primitive instead of bag + arguments.clear(); + arguments.add(attrPredicateStringEqual); + arguments.add(attra); + arguments.add(attrBagace); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of-any 2nd argument must be bag, got 'string'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + arguments.add(attrPredicateStringEqual); + arguments.add(attrBagace); + arguments.add(attra); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of-any 3rd argument must be bag, got 'string'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // no primitives - predicate expects only 1 arg + arguments.clear(); + arguments.add(attrPredicateBooleanFromString); + arguments.add(attrBagStringBooleansTrue); + arguments.add(attrBagStringBooleansTrue); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of-any Predicate error: function:boolean-from-string Expected 1 arguments, got 2", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + + // bag is empty + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrBagace); + arguments.add(attrBagEmpty); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrBagEmpty); + arguments.add(attrBagace); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // no bag + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrh); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of-any Expected 3 arguments, got 2", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // bad predicate + arguments.clear(); + arguments.add(attrh); + arguments.add(attrBagStringInt); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of-any First argument expected URI, got http://www.w3.org/2001/XMLSchema#string", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // non-boolean predicate + arguments.clear(); + arguments.add(attrPredicateStringIntersection); + arguments.add(attrBagStringInt); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of-any Predicate Function must return boolean, but 'urn:oasis:names:tc:xacml:1.0:function:string-intersection' returns 'string", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // predicate after first arg + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrPredicateStringIntersection); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of-any 2nd argument must be bag, got 'anyURI'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bags of different types + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrBagace); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of-any Predicate error: function:string-greater-than Expected data type 'string' saw 'integer' at arg index 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // no args + arguments.clear(); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of-any Expected at least 2 arguments, got 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // one arg + arguments.clear(); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of-any Expected at least 2 arguments, got 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // too many args + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBagabcdefg); + arguments.add(attrBagabcdefg); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of-any Expected 3 arguments, got 4", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // first null + arguments.clear(); + arguments.add(null); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of-any Expected 3 arguments, got 2", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // second null + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrBagabcdefg); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of-any 3rd argument must be bag, got 'null'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + + + + + + + + + + + @Test + public void testAny_of_all() { + String a = "a"; + String b = "b"; + String c = "c"; + String d = "d"; + String e = "e"; + String f = "f"; + String g = "g"; + String h = "h"; + String j = "j"; + + String w = "w"; + String x = "x"; + + + Bag bagabcdefg = null; + Bag bagbdfhj = null; + Bag bagace = null; + Bag bagb = null; + Bag bagaaacccef = null; + Bag bagewx = null; + Bag bagInt = null; + Bag bagStringInt = null; + Bag bagEmpty = null; + Bag bagStringBooleansFalse = null; + Bag bagStringBooleansTrue = null; + Bag bagBooleansFalse = null; + Bag bagBooleansTrue = null; + + + // primitive attrs + FunctionArgumentAttributeValue attra = null; + FunctionArgumentAttributeValue attrh = null; + + + + + // predicates passed as arguments + FunctionArgumentAttributeValue attrPredicateStringEqual = null; + FunctionArgumentAttributeValue attrPredicateStringIntersection = null; + FunctionArgumentAttributeValue attrPredicateStringGreaterThanOrEqual = null; + FunctionArgumentAttributeValue attrPredicateStringGreaterThan = null; + FunctionArgumentAttributeValue attrPredicateBooleanFromString = null; + + try { + + // Create Bag contents + bagabcdefg = new Bag(); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(d)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(g)); + bagbdfhj = new Bag(); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(d)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(h)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(j)); + bagace = new Bag(); + bagace.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagace.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagace.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagb = new Bag(); + bagb.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagaaacccef = new Bag(); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagewx = new Bag(); + bagewx.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagewx.add(DataTypes.DT_STRING.createAttributeValue(w)); + bagewx.add(DataTypes.DT_STRING.createAttributeValue(x)); + bagInt = new Bag(); + bagInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); + bagStringInt = new Bag(); + bagStringInt.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagStringInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); + bagEmpty = new Bag(); + bagStringBooleansTrue = new Bag(); + bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("true")); + bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("false")); + bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("true")); + bagStringBooleansFalse = new Bag(); + bagStringBooleansFalse.add(DataTypes.DT_STRING.createAttributeValue("false")); + bagStringBooleansFalse.add(DataTypes.DT_STRING.createAttributeValue("false")); + bagBooleansTrue = new Bag(); + bagBooleansTrue.add(DataTypes.DT_BOOLEAN.createAttributeValue(false)); + bagBooleansTrue.add(DataTypes.DT_BOOLEAN.createAttributeValue(false)); + bagBooleansTrue.add(DataTypes.DT_BOOLEAN.createAttributeValue(true)); + bagBooleansFalse = new Bag(); + bagBooleansFalse.add(DataTypes.DT_BOOLEAN.createAttributeValue(false)); + bagBooleansFalse.add(DataTypes.DT_BOOLEAN.createAttributeValue(false)); + + + // create primitive attrs + attra = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(a)); + attrh = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(h)); + + + + // predicates passed as function arguments + attrPredicateStringEqual = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_EQUAL)); + attrPredicateStringIntersection = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_INTERSECTION)); + attrPredicateStringGreaterThanOrEqual = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_GREATER_THAN_OR_EQUAL)); + attrPredicateStringGreaterThan = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_GREATER_THAN)); + attrPredicateBooleanFromString = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_BOOLEAN_FROM_STRING)); + + } catch (Exception ex) { + fail("creating attribute e="+ ex); + } + + // make into attributes + FunctionArgumentBag attrBagabcdefg = new FunctionArgumentBag(bagabcdefg); + FunctionArgumentBag attrBagace = new FunctionArgumentBag(bagace); + FunctionArgumentBag attrBagewx = new FunctionArgumentBag(bagewx); + FunctionArgumentBag attrBagStringInt = new FunctionArgumentBag(bagStringInt); + FunctionArgumentBag attrBagEmpty = new FunctionArgumentBag(bagEmpty); + FunctionArgumentBag attrBagStringBooleansTrue = new FunctionArgumentBag(bagStringBooleansTrue); + + FunctionDefinitionHigherOrderBag fd = (FunctionDefinitionHigherOrderBag) StdFunctions.FD_ANY_OF_ALL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_ANY_OF_ALL, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + // normal match + arguments.clear(); + arguments.add(attrPredicateStringGreaterThanOrEqual); + arguments.add(attrBagewx); + arguments.add(attrBagace); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // normal no-match + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrBagace); + arguments.add(attrBagewx); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // primitive instead of bag + arguments.clear(); + arguments.add(attrPredicateStringEqual); + arguments.add(attra); + arguments.add(attrBagace); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of-all 2nd argument must be bag, got 'string'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + arguments.add(attrPredicateStringEqual); + arguments.add(attrBagace); + arguments.add(attra); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of-all 3rd argument must be bag, got 'string'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // no primitives - predicate expects only 1 arg + arguments.clear(); + arguments.add(attrPredicateBooleanFromString); + arguments.add(attrBagStringBooleansTrue); + arguments.add(attrBagStringBooleansTrue); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of-all Predicate error: function:boolean-from-string Expected 1 arguments, got 2", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bag is empty + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrBagace); + arguments.add(attrBagEmpty); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrBagEmpty); + arguments.add(attrBagace); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // no bag + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrh); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of-all Expected 3 arguments, got 2", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // bad predicate + arguments.clear(); + arguments.add(attrh); + arguments.add(attrBagStringInt); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of-all First argument expected URI, got http://www.w3.org/2001/XMLSchema#string", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // non-boolean predicate + arguments.clear(); + arguments.add(attrPredicateStringIntersection); + arguments.add(attrBagStringInt); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of-all Predicate Function must return boolean, but 'urn:oasis:names:tc:xacml:1.0:function:string-intersection' returns 'string", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // predicate after first arg + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrPredicateStringIntersection); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of-all 2nd argument must be bag, got 'anyURI'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bags of different types + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrBagace); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of-all Predicate error: function:string-greater-than Expected data type 'string' saw 'integer' at arg index 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // no args + arguments.clear(); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of-all Expected at least 2 arguments, got 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // one arg + arguments.clear(); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of-all Expected at least 2 arguments, got 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // too many args + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBagabcdefg); + arguments.add(attrBagabcdefg); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of-all Expected 3 arguments, got 4", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // first null + arguments.clear(); + arguments.add(null); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of-all Expected 3 arguments, got 2", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // second null + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrBagabcdefg); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:any-of-all 3rd argument must be bag, got 'null'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + + + + + @Test + public void testAll_of_all() { + String a = "a"; + String b = "b"; + String c = "c"; + String d = "d"; + String e = "e"; + String f = "f"; + String g = "g"; + String h = "h"; + String j = "j"; + + String w = "w"; + String x = "x"; + + + Bag bagabcdefg = null; + Bag bagbdfhj = null; + Bag bagace = null; + Bag bagb = null; + Bag bagaaacccef = null; + Bag bagawx = null; + Bag bagwx = null; + Bag bagInt = null; + Bag bagStringInt = null; + Bag bagEmpty = null; + Bag bagStringBooleansFalse = null; + Bag bagStringBooleansTrue = null; + Bag bagBooleansFalse = null; + Bag bagBooleansTrue = null; + + + // primitive attrs + FunctionArgumentAttributeValue attra = null; + FunctionArgumentAttributeValue attrh = null; + + + + + // predicates passed as arguments + FunctionArgumentAttributeValue attrPredicateStringEqual = null; + FunctionArgumentAttributeValue attrPredicateStringIntersection = null; + FunctionArgumentAttributeValue attrPredicateStringGreaterThan = null; + FunctionArgumentAttributeValue attrPredicateBooleanFromString = null; + + try { + + // Create Bag contents + bagabcdefg = new Bag(); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(d)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(g)); + bagbdfhj = new Bag(); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(d)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(h)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(j)); + bagace = new Bag(); + bagace.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagace.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagace.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagb = new Bag(); + bagb.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagaaacccef = new Bag(); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagawx = new Bag(); + bagawx.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagawx.add(DataTypes.DT_STRING.createAttributeValue(w)); + bagawx.add(DataTypes.DT_STRING.createAttributeValue(x)); + bagwx = new Bag(); + bagwx.add(DataTypes.DT_STRING.createAttributeValue(w)); + bagwx.add(DataTypes.DT_STRING.createAttributeValue(x)); + bagInt = new Bag(); + bagInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); + bagStringInt = new Bag(); + bagStringInt.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagStringInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); + bagEmpty = new Bag(); + bagStringBooleansTrue = new Bag(); + bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("true")); + bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("false")); + bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("true")); + bagStringBooleansFalse = new Bag(); + bagStringBooleansFalse.add(DataTypes.DT_STRING.createAttributeValue("false")); + bagStringBooleansFalse.add(DataTypes.DT_STRING.createAttributeValue("false")); + bagBooleansTrue = new Bag(); + bagBooleansTrue.add(DataTypes.DT_BOOLEAN.createAttributeValue(false)); + bagBooleansTrue.add(DataTypes.DT_BOOLEAN.createAttributeValue(false)); + bagBooleansTrue.add(DataTypes.DT_BOOLEAN.createAttributeValue(true)); + bagBooleansFalse = new Bag(); + bagBooleansFalse.add(DataTypes.DT_BOOLEAN.createAttributeValue(false)); + bagBooleansFalse.add(DataTypes.DT_BOOLEAN.createAttributeValue(false)); + + + // create primitive attrs + attra = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(a)); + attrh = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(h)); + + + + // predicates passed as function arguments + attrPredicateStringEqual = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_EQUAL)); + attrPredicateStringIntersection = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_INTERSECTION)); + attrPredicateStringGreaterThan = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_GREATER_THAN)); + attrPredicateBooleanFromString = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_BOOLEAN_FROM_STRING)); + + } catch (Exception ex) { + fail("creating attribute e="+ ex); + } + + // make into attributes + FunctionArgumentBag attrBagabcdefg = new FunctionArgumentBag(bagabcdefg); + FunctionArgumentBag attrBagace = new FunctionArgumentBag(bagace); + FunctionArgumentBag attrBagawx = new FunctionArgumentBag(bagawx); + FunctionArgumentBag attrBagwx = new FunctionArgumentBag(bagwx); + FunctionArgumentBag attrBagStringInt = new FunctionArgumentBag(bagStringInt); + FunctionArgumentBag attrBagEmpty = new FunctionArgumentBag(bagEmpty); + FunctionArgumentBag attrBagStringBooleansTrue = new FunctionArgumentBag(bagStringBooleansTrue); + + FunctionDefinitionHigherOrderBag fd = (FunctionDefinitionHigherOrderBag) StdFunctions.FD_ALL_OF_ALL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_ALL_OF_ALL, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + // normal match + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrBagwx); + arguments.add(attrBagace); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // normal no-match + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrBagawx); + arguments.add(attrBagace); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrBagace); + arguments.add(attrBagwx); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // primitive instead of bag + arguments.clear(); + arguments.add(attrPredicateStringEqual); + arguments.add(attra); + arguments.add(attrBagace); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of-all 2nd argument must be bag, got 'string'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + arguments.add(attrPredicateStringEqual); + arguments.add(attrBagace); + arguments.add(attra); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of-all 3rd argument must be bag, got 'string'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // no primitives - predicate expects only 1 arg + arguments.clear(); + arguments.add(attrPredicateBooleanFromString); + arguments.add(attrBagStringBooleansTrue); + arguments.add(attrBagStringBooleansTrue); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of-all Predicate error: function:boolean-from-string Expected 1 arguments, got 2", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bag is empty + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrBagace); + arguments.add(attrBagEmpty); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrBagEmpty); + arguments.add(attrBagace); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // no bag + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrh); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of-all Expected 3 arguments, got 2", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // bad predicate + arguments.clear(); + arguments.add(attrh); + arguments.add(attrBagStringInt); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of-all First argument expected URI, got http://www.w3.org/2001/XMLSchema#string", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // non-boolean predicate + arguments.clear(); + arguments.add(attrPredicateStringIntersection); + arguments.add(attrBagStringInt); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of-all Predicate Function must return boolean, but 'urn:oasis:names:tc:xacml:1.0:function:string-intersection' returns 'string", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // predicate after first arg + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrPredicateStringIntersection); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of-all 2nd argument must be bag, got 'anyURI'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bags of different types + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrBagwx); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of-all Predicate error: function:string-greater-than Expected data type 'string' saw 'integer' at arg index 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // no args + arguments.clear(); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of-all Expected at least 2 arguments, got 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // one arg + arguments.clear(); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of-all Expected at least 2 arguments, got 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // too many args + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBagabcdefg); + arguments.add(attrBagabcdefg); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of-all Expected 3 arguments, got 4", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // first null + arguments.clear(); + arguments.add(null); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of-all Expected 3 arguments, got 2", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // second null + arguments.clear(); + arguments.add(attrPredicateStringGreaterThan); + arguments.add(attrBagabcdefg); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:all-of-all 3rd argument must be bag, got 'null'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + + + + + + + + + @Test + public void testMap() { + String a = "a"; + String b = "b"; + String c = "c"; + String d = "d"; + String e = "e"; + String f = "f"; + String g = "g"; + String h = "h"; + String j = "j"; + + + Bag bagabcdefg = null; + Bag bagbdfhj = null; + Bag bagace = null; + Bag bagb = null; + Bag bagaaacccef = null; + Bag bagInt = null; + Bag bagStringInt = null; + Bag bagEmpty = null; + Bag bagStringBooleansFalse = null; + Bag bagStringBooleansTrue = null; + Bag bagInt123 = null; + Bag bagInt789 = null; + + + // primitive attrs + FunctionArgumentAttributeValue attrh = null; + FunctionArgumentAttributeValue attrInt7 = null; + + + + // predicates passed as arguments + FunctionArgumentAttributeValue attrPredicateStringNormalizeToLowerCase = null; + FunctionArgumentAttributeValue attrPredicateIntegerEqual = null; + FunctionArgumentAttributeValue attrPredicateIntegerAdd = null; + + try { + + // Create Bag contents + bagabcdefg = new Bag(); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(d)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(g)); + bagbdfhj = new Bag(); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(d)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(h)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(j)); + bagace = new Bag(); + bagace.add(DataTypes.DT_STRING.createAttributeValue("A")); + bagace.add(DataTypes.DT_STRING.createAttributeValue("C")); + bagace.add(DataTypes.DT_STRING.createAttributeValue("E")); + bagb = new Bag(); + bagb.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagaaacccef = new Bag(); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagInt = new Bag(); + bagInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); + bagStringInt = new Bag(); + bagStringInt.add(DataTypes.DT_STRING.createAttributeValue(a)); + + bagStringInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); + bagEmpty = new Bag(); + bagStringBooleansTrue = new Bag(); + bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("true")); + bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("true")); + bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("true")); + bagStringBooleansFalse = new Bag(); + bagStringBooleansFalse.add(DataTypes.DT_STRING.createAttributeValue("false")); + bagStringBooleansFalse.add(DataTypes.DT_STRING.createAttributeValue("false")); + bagInt123 = new Bag(); + bagInt123.add(DataTypes.DT_INTEGER.createAttributeValue(1)); + bagInt123.add(DataTypes.DT_INTEGER.createAttributeValue(2)); + bagInt123.add(DataTypes.DT_INTEGER.createAttributeValue(3)); + bagInt789 = new Bag(); + bagInt789.add(DataTypes.DT_INTEGER.createAttributeValue(7)); + bagInt789.add(DataTypes.DT_INTEGER.createAttributeValue(8)); + bagInt789.add(DataTypes.DT_INTEGER.createAttributeValue(9)); + + + + // create primitive attrs + attrh = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(h)); + attrInt7 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(7)); + + + // predicates passed as function arguments + attrPredicateStringNormalizeToLowerCase = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_NORMALIZE_TO_LOWER_CASE)); + attrPredicateIntegerEqual = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_INTEGER_EQUAL)); + attrPredicateIntegerAdd = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_INTEGER_ADD)); + + } catch (Exception ex) { + fail("creating attribute e="+ ex); + } + + // make into attributes + FunctionArgumentBag attrBagabcdefg = new FunctionArgumentBag(bagabcdefg); + FunctionArgumentBag attrBagace = new FunctionArgumentBag(bagace); + FunctionArgumentBag attrBagStringInt = new FunctionArgumentBag(bagStringInt); + FunctionArgumentBag attrBagEmpty = new FunctionArgumentBag(bagEmpty); + FunctionArgumentBag attrBagStringBooleansTrue = new FunctionArgumentBag(bagStringBooleansTrue); + FunctionArgumentBag attrBagInt789 = new FunctionArgumentBag(bagInt789); + + FunctionDefinitionHigherOrderBag fd = (FunctionDefinitionHigherOrderBag) StdFunctions.FD_MAP; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_MAP, fd.getId()); + assertNull( fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertTrue(fd.returnsBag()); + + // normal match + arguments.clear(); + arguments.add(attrPredicateStringNormalizeToLowerCase); + arguments.add(attrBagace); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertTrue(res.isBag()); + Bag bag = res.getBag(); + assertEquals(3, bag.size()); + List> bagAttributes = bag.getAttributeValueList(); + try { + assertTrue(bagAttributes.contains(DataTypes.DT_STRING.createAttributeValue("a"))); + assertFalse(bagAttributes.contains(DataTypes.DT_STRING.createAttributeValue("A"))); + assertTrue(bagAttributes.contains(DataTypes.DT_STRING.createAttributeValue("c"))); + assertFalse(bagAttributes.contains(DataTypes.DT_STRING.createAttributeValue("C"))); + assertTrue(bagAttributes.contains(DataTypes.DT_STRING.createAttributeValue("e"))); + assertFalse(bagAttributes.contains(DataTypes.DT_STRING.createAttributeValue("E"))); + } catch (Exception ex) { + fail("checking result e="+ex); + } + + // 2-input predicate + arguments.clear(); + arguments.add(attrPredicateIntegerAdd); + arguments.add(attrInt7); + arguments.add(attrBagInt789); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertTrue(res.isBag()); + bag = res.getBag(); + assertEquals(3, bag.size()); + bagAttributes = bag.getAttributeValueList(); + try { + assertTrue(bagAttributes.contains(DataTypes.DT_INTEGER.createAttributeValue("14"))); + assertTrue(bagAttributes.contains(DataTypes.DT_INTEGER.createAttributeValue("15"))); + assertTrue(bagAttributes.contains(DataTypes.DT_INTEGER.createAttributeValue("16"))); + } catch (Exception ex) { + fail("checking result e="+ex); + } + + + // predicate returns booleans + arguments.clear(); + arguments.add(attrPredicateIntegerEqual); + arguments.add(attrInt7); + arguments.add(attrBagInt789); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertTrue(res.isBag()); + bag = res.getBag(); + assertEquals(3, bag.size()); + bagAttributes = bag.getAttributeValueList(); + try { + assertEquals(bagAttributes.get(0), (DataTypes.DT_BOOLEAN.createAttributeValue(true))); + assertEquals(bagAttributes.get(1), (DataTypes.DT_BOOLEAN.createAttributeValue(false))); + assertEquals(bagAttributes.get(2), (DataTypes.DT_BOOLEAN.createAttributeValue(false))); + } catch (Exception ex) { + fail("checking result e="+ex); + } + + // predicate returns bag + + + + // no primitives - predicate function expects 2 + arguments.clear(); + arguments.add(attrPredicateIntegerAdd); + arguments.add(attrBagace); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:map Predicate error: function:integer-add Expected 2 arguments, got 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bag is empty + arguments.clear(); + arguments.add(attrPredicateStringNormalizeToLowerCase); + arguments.add(attrh); + arguments.add(attrBagEmpty); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertTrue(res.isBag()); + bag = res.getBag(); + assertEquals(0, bag.size());; + + // no bag + arguments.clear(); + arguments.add(attrPredicateStringNormalizeToLowerCase); + arguments.add(attrh); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:map Did not get any Bag argument; must have at least 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // extra bag + arguments.clear(); + arguments.add(attrPredicateStringNormalizeToLowerCase); + arguments.add(attrh); + arguments.add(attrBagStringBooleansTrue); + arguments.add(attrh); + arguments.add(attrBagStringBooleansTrue); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:map must have only 1 bag; found one at index 2 and another at 4", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // bad predicate + arguments.clear(); + arguments.add(attrh); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:map First argument expected URI, got http://www.w3.org/2001/XMLSchema#string", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // predicate gets unexpected number of args + arguments.clear(); + arguments.add(attrPredicateStringNormalizeToLowerCase); + arguments.add(attrh); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:map Predicate error: function:string-normalize-to-lower-case Expected 1 arguments, got 2", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // predicate gets bad primitive type + arguments.clear(); + arguments.add(attrPredicateStringNormalizeToLowerCase); + arguments.add(attrPredicateStringNormalizeToLowerCase); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:map Predicate error: function:string-normalize-to-lower-case Expected 1 arguments, got 2", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bags of different types + arguments.clear(); + arguments.add(attrPredicateStringNormalizeToLowerCase); + arguments.add(attrh); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + + // first null + arguments.clear(); + arguments.add(null); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:map Predicate Function (first argument) was null", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // second null + arguments.clear(); + arguments.add(attrPredicateStringNormalizeToLowerCase); + arguments.add(attrBagabcdefg); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:map Got null argument at index 2", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + + +} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionHomogeneousSimpleTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionHomogeneousSimpleTest.java new file mode 100644 index 000000000..8e98793b9 --- /dev/null +++ b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionHomogeneousSimpleTest.java @@ -0,0 +1,150 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-TEST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.std.functions; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +import com.att.research.xacml.api.Status; +import com.att.research.xacml.api.XACML3; +import com.att.research.xacml.std.datatypes.DataTypes; +import com.att.research.xacmlatt.pdp.policy.Bag; +import com.att.research.xacmlatt.pdp.policy.FunctionArgument; +import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; +import com.att.research.xacmlatt.pdp.policy.FunctionArgumentBag; +import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionEquality; + +/** + * FunctionDefinitionHomogeneousSimple is an abstract class, so we have to test it by creating a sub-class. + * The constructor is tested by default when an instance of the sub-class is created for other tests. + * + * Each of these functions needs to be tested for each type of function to be sure the values are correct, + * so this is just a simple test to see that the mechanism works. + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * + */ +public class FunctionDefinitionHomogeneousSimpleTest { + + + + @Test + public void testGetDataTypeArgs() { + + // test a simple instance using the Equality class + FunctionDefinitionEquality fd = new FunctionDefinitionEquality(XACML3.ID_FUNCTION_STRING_EQUAL, DataTypes.DT_STRING); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); + } + + @Test + public void testGetNumArgs() { + // test a simple instance using the Equality class + FunctionDefinitionEquality fd = new FunctionDefinitionEquality(XACML3.ID_FUNCTION_STRING_EQUAL, DataTypes.DT_STRING); + assertEquals(new Integer(2), fd.getNumArgs()); + } + + @Test + public void testValidateArguments() { + // create some arguments to use later + FunctionArgumentAttributeValue stringAttr1 = null; + FunctionArgumentAttributeValue stringAttr2 = null; + FunctionArgumentAttributeValue stringAttr3 = null; + FunctionArgumentAttributeValue intAttr = null; + try { + stringAttr1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("abc")); + stringAttr2 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("def")); + stringAttr3 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("ghi")); + intAttr = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1)); + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionEquality fd = new FunctionDefinitionEquality(XACML3.ID_FUNCTION_STRING_EQUAL, DataTypes.DT_STRING); + List convertedValues = new ArrayList(); + List listFunctionArguments = new ArrayList(); + + // test correct # of args, both of them strings + listFunctionArguments.add(stringAttr1); + listFunctionArguments.add(stringAttr2); + Status status = fd.validateArguments(listFunctionArguments, convertedValues); + assertTrue(status.isOk()); + assertEquals(convertedValues.size(),2); + + // test too few args + listFunctionArguments.remove(1); + status = fd.validateArguments(listFunctionArguments, convertedValues); + assertFalse(status.isOk()); + assertEquals("Expected 2 arguments, got 1", status.getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", status.getStatusCode().getStatusCodeValue().stringValue()); + + // test too many args + listFunctionArguments.add(stringAttr2); + listFunctionArguments.add(stringAttr3); + status = fd.validateArguments(listFunctionArguments, convertedValues); + assertFalse(status.isOk()); + assertEquals("Expected 2 arguments, got 3", status.getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", status.getStatusCode().getStatusCodeValue().stringValue()); + + // test with null arg + listFunctionArguments.clear(); + listFunctionArguments.add(null); + listFunctionArguments.add(stringAttr1); + status = fd.validateArguments(listFunctionArguments, convertedValues); + assertFalse(status.isOk()); + assertEquals("Got null argument at arg index 0", status.getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", status.getStatusCode().getStatusCodeValue().stringValue()); + + // test function that takes 0 args +//TODO test with func that specifies 0 args? ASSUME for now that there are no such functions since a function needs to operate on something +// fail("need to test function with 0 args and various inputs - see validateArguments code"); + + + // test with one is a bag + listFunctionArguments.clear(); + listFunctionArguments.add(stringAttr1); + Bag bag = new Bag(); + FunctionArgument bagArg = new FunctionArgumentBag(bag); + listFunctionArguments.add(bagArg); + status = fd.validateArguments(listFunctionArguments, convertedValues); + assertFalse(status.isOk()); + assertEquals("Expected a simple value, saw a bag at arg index 1", status.getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", status.getStatusCode().getStatusCodeValue().stringValue()); + + // test with string and int + listFunctionArguments.clear(); + listFunctionArguments.add(stringAttr1); + listFunctionArguments.add(intAttr); + status = fd.validateArguments(listFunctionArguments, convertedValues); + assertFalse(status.isOk()); + assertEquals("Expected data type 'string' saw 'integer' at arg index 1", status.getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", status.getStatusCode().getStatusCodeValue().stringValue()); + } + +} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionLogicalTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionLogicalTest.java new file mode 100644 index 000000000..b70ed138c --- /dev/null +++ b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionLogicalTest.java @@ -0,0 +1,422 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-TEST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.std.functions; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +import com.att.research.xacml.api.XACML3; +import com.att.research.xacml.std.datatypes.DataTypes; +import com.att.research.xacmlatt.pdp.policy.ExpressionResult; +import com.att.research.xacmlatt.pdp.policy.FunctionArgument; +import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; +import com.att.research.xacmlatt.pdp.std.StdFunctions; +import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionLogical; + +/** + * Test of PDP Functions (See XACML core spec section A.3) + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * + */ +public class FunctionDefinitionLogicalTest { + + /* + * variables useful in the following tests + */ + List arguments = new ArrayList(); + + // use the same args for each test + FunctionArgumentAttributeValue attrT = null; + FunctionArgumentAttributeValue attrF = null; + public FunctionDefinitionLogicalTest () { + try { + attrT = new FunctionArgumentAttributeValue(DataTypes.DT_BOOLEAN.createAttributeValue(true)); + attrF = new FunctionArgumentAttributeValue(DataTypes.DT_BOOLEAN.createAttributeValue(false)); + } catch (Exception e) { + fail("creating attribute e="+ e); + } + } + + + @Test + public void testOR() { + FunctionArgumentAttributeValue attr5 = null; + try { + attr5 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(5)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionLogical fd = (FunctionDefinitionLogical) StdFunctions.FD_OR; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_OR, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + + // test normal + arguments.add(attrT); + arguments.add(attrF); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertEquals(new Boolean(true), resValue); + + arguments.clear(); + arguments.add(attrF); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(new Boolean(false), resValue); + + // test no args + arguments.clear(); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(new Boolean(false), resValue); + + // first true, second error + arguments.clear(); + arguments.add(attrT); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(new Boolean(true), resValue); + + // first false, second error + arguments.clear(); + arguments.add(attrF); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:or Got null argument", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // multiple false + arguments.clear(); + arguments.add(attrF); + arguments.add(attrF); + arguments.add(attrF); + arguments.add(attrF); + arguments.add(attrF); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(new Boolean(false), resValue); + + // non-boolean + arguments.clear(); + arguments.add(attrF); + arguments.add(attr5); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:or Expected data type 'boolean' saw 'integer'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // first arg error + arguments.clear(); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:or Got null argument", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + @Test + public void testAND() { + FunctionArgumentAttributeValue attr5 = null; + try { + attr5 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(5)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + + FunctionDefinitionLogical fd = (FunctionDefinitionLogical) StdFunctions.FD_AND; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_AND, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + + // test normal + arguments.add(attrT); + arguments.add(attrF); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertEquals(new Boolean(false), resValue); + + arguments.clear(); + arguments.add(attrF); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(new Boolean(false), resValue); + + // test no args + arguments.clear(); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(new Boolean(true), resValue); + + // first true, second error + arguments.clear(); + arguments.add(attrT); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:and Got null argument", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // first false, second error + arguments.clear(); + arguments.add(attrF); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(new Boolean(false), resValue); + + // multiple true + arguments.clear(); + arguments.add(attrT); + arguments.add(attrT); + arguments.add(attrT); + arguments.add(attrT); + arguments.add(attrT); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(new Boolean(true), resValue); + + // non-boolean + arguments.clear(); + arguments.add(attrT); + arguments.add(attr5); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals("function:and Expected data type 'boolean' saw 'integer'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // first arg error + arguments.clear(); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals("function:and Got null argument", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + + + @Test + public void testN_of() { + FunctionArgumentAttributeValue attr0 = null; + FunctionArgumentAttributeValue attr2 = null; + try { + attr0 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(0)); + attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(2)); + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + + FunctionDefinitionLogical fd = (FunctionDefinitionLogical) StdFunctions.FD_N_OF; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_N_OF, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + + // test normal + arguments.add(attr2); + arguments.add(attrT); + arguments.add(attrF); + arguments.add(attrT); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertEquals(new Boolean(true), resValue); + + // normal fail + arguments.clear(); + arguments.add(attr2); + arguments.add(attrT); + arguments.add(attrF); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(new Boolean(false), resValue); + + + // null count + arguments.clear(); + arguments.add(null); + arguments.add(attrT); + arguments.add(attrF); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(new Boolean(true), resValue); + + // 0 count + arguments.clear(); + arguments.add(attr0); + arguments.add(attrT); + arguments.add(attrF); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(new Boolean(true), resValue); + + // bad object type for count + arguments.clear(); + arguments.add(attrT); + arguments.add(attrT); + arguments.add(attrF); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:n-of For input string: \"true\"", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // count larger than list + arguments.clear(); + arguments.add(attr2); + arguments.add(attrT); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:n-of Expected 2 arguments but only 1 arguments in list after the count", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // aborts after find ok + arguments.clear(); + arguments.add(attr2); + arguments.add(attrT); + arguments.add(attrT); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(new Boolean(true), resValue); + + // error before find ok + arguments.clear(); + arguments.add(attr2); + arguments.add(null); + arguments.add(attrT); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:n-of Got null argument", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // non-boolean in list + arguments.clear(); + arguments.add(attr2); + arguments.add(attrT); + arguments.add(attr0); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:n-of Expected data type 'boolean' saw 'integer'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + @Test + public void testNot() { + + FunctionDefinitionLogical fd = (FunctionDefinitionLogical) StdFunctions.FD_NOT; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_NOT, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + + // test normal + arguments.clear(); + arguments.add(attrT); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertEquals(new Boolean(false), resValue); + + arguments.clear(); + arguments.add(attrF); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(new Boolean(true), resValue); + + + // test null/0 args + arguments.clear(); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:not Expected 1 argument, got 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // test 2 args + arguments.clear(); + arguments.add(attrT); + arguments.add(attrF); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:not Expected 1 argument, got 2", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } +} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionNumberTypeConversionTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionNumberTypeConversionTest.java new file mode 100644 index 000000000..17843292c --- /dev/null +++ b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionNumberTypeConversionTest.java @@ -0,0 +1,119 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-TEST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.std.functions; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +import com.att.research.xacml.api.XACML3; +import com.att.research.xacml.std.datatypes.DataTypes; +import com.att.research.xacmlatt.pdp.policy.ExpressionResult; +import com.att.research.xacmlatt.pdp.policy.FunctionArgument; +import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; +import com.att.research.xacmlatt.pdp.std.StdFunctions; +import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionNumberTypeConversion; + +/** + * Tests for various classes containing only one function. + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * + */ +public class FunctionDefinitionNumberTypeConversionTest { + + /* + * variables useful in the following tests + */ + List arguments = new ArrayList(); + + @Test + public void testDouble_to_integer() { + FunctionArgumentAttributeValue attr1 = null; + try { + attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(5.432)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionNumberTypeConversion fd = (FunctionDefinitionNumberTypeConversion) StdFunctions.FD_DOUBLE_TO_INTEGER; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DOUBLE_TO_INTEGER, fd.getId()); + assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + + // test normal add + arguments.add(attr1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + BigInteger resValue = (BigInteger)res.getValue().getValue(); + assertEquals(BigInteger.valueOf(5), resValue); + } + + + @Test + public void testInteger_to_double() { + FunctionArgumentAttributeValue attr1 = null; + try { + attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(5)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionNumberTypeConversion fd = (FunctionDefinitionNumberTypeConversion) StdFunctions.FD_INTEGER_TO_DOUBLE; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_INTEGER_TO_DOUBLE, fd.getId()); + assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + + // test normal add + arguments.add(attr1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Double resValue = (Double)res.getValue().getValue(); + assertEquals(new Double(5.0), resValue); + } + + +} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionRegexpMatchTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionRegexpMatchTest.java new file mode 100644 index 000000000..04fe8255e --- /dev/null +++ b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionRegexpMatchTest.java @@ -0,0 +1,511 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-TEST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.std.functions; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.net.URI; +import java.util.ArrayList; +import java.util.List; + +import javax.security.auth.x500.X500Principal; + +import org.junit.Test; + +import com.att.research.xacml.api.XACML3; +import com.att.research.xacml.std.datatypes.DataTypes; +import com.att.research.xacml.std.datatypes.IPAddress; +import com.att.research.xacml.std.datatypes.RFC2396DomainName; +import com.att.research.xacml.std.datatypes.RFC822Name; +import com.att.research.xacmlatt.pdp.policy.ExpressionResult; +import com.att.research.xacmlatt.pdp.policy.FunctionArgument; +import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; +import com.att.research.xacmlatt.pdp.std.StdFunctions; +import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionRegexpMatch; + +/** + * Test of PDP Functions (See XACML core spec section A.3) + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * + */ +public class FunctionDefinitionRegexpMatchTest { + + + /* + * variables useful in the following tests + */ + List arguments = new ArrayList(); + + + @Test + public void testString() { + String v1 = new String("abc"); + String v2 = new String("def"); + + + FunctionArgumentAttributeValue attrV1 = null; + FunctionArgumentAttributeValue attrV2 = null; + FunctionArgumentAttributeValue attrNull = null; + FunctionArgumentAttributeValue attrInteger = null; + try { + attrV1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(v1)); + attrV2 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(v2)); + attrNull = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(null)); + attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234)); + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + FunctionDefinitionRegexpMatch fd = (FunctionDefinitionRegexpMatch) StdFunctions.FD_STRING_REGEXP_MATCH; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_REGEXP_MATCH, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + + // match + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrV1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertEquals(true, resValue); + + // no match + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrV2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // null regex + arguments.clear(); + arguments.add(null); + arguments.add(attrV2); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-regexp-match Got null argument", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + arguments.clear(); + arguments.add(attrNull); + arguments.add(attrV2); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-regexp-match Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null object to match + arguments.clear(); + arguments.add(attrV1); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-regexp-match Got null argument", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrNull); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-regexp-match Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // regex not string + arguments.clear(); + arguments.add(attrInteger); + arguments.add(attrV2); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-regexp-match Expected data type 'string' saw 'integer'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // object to match not correct type + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrInteger); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-regexp-match Expected data type 'string' saw 'integer'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + @Test + public void testAnyURI() { + String regexp = new String("abc"); + URI uri1 = null; + URI uri2 = null; + try { + uri1 = new URI("abc"); + uri2 = new URI("def"); + } catch (Exception e) { + fail("Unable to create URIs, e="+e); + } + + + FunctionArgumentAttributeValue attrRegexp = null; + FunctionArgumentAttributeValue attrUri1 = null; + FunctionArgumentAttributeValue attrUri2 = null; + FunctionArgumentAttributeValue attrInteger = null; + try { + attrRegexp = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(regexp)); + attrUri1 = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(uri1)); + attrUri2 = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(uri2)); + attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234)); + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + FunctionDefinitionRegexpMatch fd = (FunctionDefinitionRegexpMatch) StdFunctions.FD_ANYURI_REGEXP_MATCH; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_ANYURI_REGEXP_MATCH, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + + // match + arguments.clear(); + arguments.add(attrRegexp); + arguments.add(attrUri1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertEquals(true, resValue); + + // no match + arguments.clear(); + arguments.add(attrRegexp); + arguments.add(attrUri2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // object to match not correct type + arguments.clear(); + arguments.add(attrRegexp); + arguments.add(attrInteger); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:anyURI-regexp-match Expected data type 'anyURI' saw 'integer'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + @Test + public void testIpAddress() { + String regexp = new String(".*123.*"); + IPAddress addr1 = null; + IPAddress addr2 = null; + try { + addr1 = IPAddress.newInstance("10.123.13.14"); + addr2 = IPAddress.newInstance("10.11.12.13"); + } catch (Exception e) { + fail("Unable to create IPAddresses, e="+e); + } + + + FunctionArgumentAttributeValue attrRegexp = null; + FunctionArgumentAttributeValue attrAddr1 = null; + FunctionArgumentAttributeValue attrAddr2 = null; + FunctionArgumentAttributeValue attrInteger = null; + try { + attrRegexp = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(regexp)); + attrAddr1 = new FunctionArgumentAttributeValue(DataTypes.DT_IPADDRESS.createAttributeValue(addr1)); + attrAddr2 = new FunctionArgumentAttributeValue(DataTypes.DT_IPADDRESS.createAttributeValue(addr2)); + attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234)); + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + FunctionDefinitionRegexpMatch fd = (FunctionDefinitionRegexpMatch) StdFunctions.FD_IPADDRESS_REGEXP_MATCH; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_IPADDRESS_REGEXP_MATCH, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + + // match + arguments.clear(); + arguments.add(attrRegexp); + arguments.add(attrAddr1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertEquals(true, resValue); + + // no match + arguments.clear(); + arguments.add(attrRegexp); + arguments.add(attrAddr2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // object to match not correct type + arguments.clear(); + arguments.add(attrRegexp); + arguments.add(attrInteger); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:ipAddress-regexp-match Expected data type 'ipAddress' saw 'integer'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + @Test + public void testDnsName() { + String regexp = new String("abc"); + RFC2396DomainName addr1 = null; + RFC2396DomainName addr2 = null; + try { + addr1 = RFC2396DomainName.newInstance("abc"); + addr2 = RFC2396DomainName.newInstance("def"); + } catch (Exception e) { + fail("Unable to create DNSNames, e="+e); + } + + + FunctionArgumentAttributeValue attrRegexp = null; + FunctionArgumentAttributeValue attrAddr1 = null; + FunctionArgumentAttributeValue attrAddr2 = null; + FunctionArgumentAttributeValue attrInteger = null; + try { + attrRegexp = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(regexp)); + attrAddr1 = new FunctionArgumentAttributeValue(DataTypes.DT_DNSNAME.createAttributeValue(addr1)); + attrAddr2 = new FunctionArgumentAttributeValue(DataTypes.DT_DNSNAME.createAttributeValue(addr2)); + attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234)); + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + FunctionDefinitionRegexpMatch fd = (FunctionDefinitionRegexpMatch) StdFunctions.FD_DNSNAME_REGEXP_MATCH; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DNSNAME_REGEXP_MATCH, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + + // match + arguments.clear(); + arguments.add(attrRegexp); + arguments.add(attrAddr1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertEquals(true, resValue); + + // no match + arguments.clear(); + arguments.add(attrRegexp); + arguments.add(attrAddr2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // object to match not correct type + arguments.clear(); + arguments.add(attrRegexp); + arguments.add(attrInteger); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dnsName-regexp-match Expected data type 'dnsName' saw 'integer'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + @Test + public void testRfc822Name() { + String regexp = new String(".*abc.*"); + RFC822Name addr1 = null; + RFC822Name addr2 = null; + try { + addr1 = RFC822Name.newInstance("abc@somewhere"); + addr2 = RFC822Name.newInstance("def@somewhere"); + } catch (Exception e) { + fail("Unable to create RFC822Names, e="+e); + } + + + FunctionArgumentAttributeValue attrRegexp = null; + FunctionArgumentAttributeValue attrAddr1 = null; + FunctionArgumentAttributeValue attrAddr2 = null; + FunctionArgumentAttributeValue attrInteger = null; + try { + attrRegexp = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(regexp)); + attrAddr1 = new FunctionArgumentAttributeValue(DataTypes.DT_RFC822NAME.createAttributeValue(addr1)); + attrAddr2 = new FunctionArgumentAttributeValue(DataTypes.DT_RFC822NAME.createAttributeValue(addr2)); + attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234)); + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + FunctionDefinitionRegexpMatch fd = (FunctionDefinitionRegexpMatch) StdFunctions.FD_RFC822NAME_REGEXP_MATCH; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_RFC822NAME_REGEXP_MATCH, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + + // match + arguments.clear(); + arguments.add(attrRegexp); + arguments.add(attrAddr1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertEquals(true, resValue); + + // no match + arguments.clear(); + arguments.add(attrRegexp); + arguments.add(attrAddr2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // object to match not correct type + arguments.clear(); + arguments.add(attrRegexp); + arguments.add(attrInteger); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:rfc822Name-regexp-match Expected data type 'rfc822Name' saw 'integer'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + @Test + public void testX500Name() { + String regexp = new String(".*Duke.*"); + X500Principal addr1 = null; + X500Principal addr2 = null; + try { + addr1 = new X500Principal("CN=Duke, OU=JavaSoft, O=Sun Microsystems, C=US"); + addr2 = new X500Principal("CN=Policy Engine, OU=Research, O=ATT, C=US"); + } catch (Exception e) { + fail("Unable to create X500Name, e="+e); + } + + + FunctionArgumentAttributeValue attrRegexp = null; + FunctionArgumentAttributeValue attrAddr1 = null; + FunctionArgumentAttributeValue attrAddr2 = null; + FunctionArgumentAttributeValue attrInteger = null; + try { + attrRegexp = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(regexp)); + attrAddr1 = new FunctionArgumentAttributeValue(DataTypes.DT_X500NAME.createAttributeValue(addr1)); + attrAddr2 = new FunctionArgumentAttributeValue(DataTypes.DT_X500NAME.createAttributeValue(addr2)); + attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234)); + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + FunctionDefinitionRegexpMatch fd = (FunctionDefinitionRegexpMatch) StdFunctions.FD_X500NAME_REGEXP_MATCH; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_X500NAME_REGEXP_MATCH, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + + // match + arguments.clear(); + arguments.add(attrRegexp); + arguments.add(attrAddr1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertEquals(true, resValue); + + // no match + arguments.clear(); + arguments.add(attrRegexp); + arguments.add(attrAddr2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // object to match not correct type + arguments.clear(); + arguments.add(attrRegexp); + arguments.add(attrInteger); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:x500Name-regexp-match Expected data type 'x500Name' saw 'integer'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + + +} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionSetTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionSetTest.java new file mode 100644 index 000000000..99e27910a --- /dev/null +++ b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionSetTest.java @@ -0,0 +1,1903 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-TEST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.std.functions; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.junit.Test; + +import com.att.research.xacml.api.AttributeValue; +import com.att.research.xacml.api.XACML3; +import com.att.research.xacml.std.datatypes.DataTypes; +import com.att.research.xacmlatt.pdp.policy.Bag; +import com.att.research.xacmlatt.pdp.policy.ExpressionResult; +import com.att.research.xacmlatt.pdp.policy.FunctionArgument; +import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; +import com.att.research.xacmlatt.pdp.policy.FunctionArgumentBag; +import com.att.research.xacmlatt.pdp.std.StdFunctions; +import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionSet; + +/** + * Test of PDP Functions (See XACML core spec section A.3) + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * + */ +public class FunctionDefinitionSetTest { + + + /* + * variables useful in the following tests + */ + List arguments = new ArrayList(); + + + + // + // INTERSECTION tests + // + + + @Test + public void testString_intersection() { + String a = "a"; + String b = "b"; + String c = "c"; + String d = "d"; + String e = "e"; + String f = "f"; + String g = "g"; + String h = "h"; + String j = "j"; + + + Bag bagabcdefg = null; + Bag bagbdfhj = null; + Bag bagace = null; + Bag bagb = null; + Bag bagaaacccef = null; + Bag bagInt = null; + Bag bagStringInt = null; + Bag bagEmpty = null; + + FunctionArgumentAttributeValue attrBadType = null; + + try { + bagabcdefg = new Bag(); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(d)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(g)); + bagbdfhj = new Bag(); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(d)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(h)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(j)); + bagace = new Bag(); + bagace.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagace.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagace.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagb = new Bag(); + bagb.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagaaacccef = new Bag(); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagInt = new Bag(); + bagInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); + bagStringInt = new Bag(); + bagStringInt.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagStringInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); + bagEmpty = new Bag(); + + attrBadType = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.1)); + } catch (Exception ex) { + fail("creating attribute e="+ ex); + } + + // make into attributes + FunctionArgumentBag attrBagabcdefg = new FunctionArgumentBag(bagabcdefg); + FunctionArgumentBag attrBagbdfhj = new FunctionArgumentBag(bagbdfhj); + FunctionArgumentBag attrBagace = new FunctionArgumentBag(bagace); + FunctionArgumentBag attrBagb = new FunctionArgumentBag(bagb); + FunctionArgumentBag attrBagaaacccef = new FunctionArgumentBag(bagaaacccef); + FunctionArgumentBag attrBagInt = new FunctionArgumentBag(bagInt); + FunctionArgumentBag attrBagStringInt = new FunctionArgumentBag(bagStringInt); + FunctionArgumentBag attrBagEmpty = new FunctionArgumentBag(bagEmpty); + + FunctionDefinitionSet fd = (FunctionDefinitionSet) StdFunctions.FD_STRING_INTERSECTION; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_INTERSECTION, fd.getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertTrue(fd.returnsBag()); + + // normal intersection (everything in both bags, no duplicates) + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBagabcdefg); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Bag bag = res.getBag(); + assertNotNull(bag); + Iterator> it = bag.getAttributeValues(); + assertEquals(7, bag.size()); + AttributeValue attrValueObject = it.next(); + assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); + assertEquals(a, attrValueObject.getValue() ); + + // several but not all intersection + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBagbdfhj); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(3, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); + assertEquals(b, attrValueObject.getValue() ); + + // no intersection + arguments.clear(); + arguments.add(attrBagace); + arguments.add(attrBagbdfhj); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(0, bag.size()); + + // one intersection + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBagb); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(1, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); + assertEquals(b, attrValueObject.getValue() ); + + // bag one has duplicates that do not intersect + arguments.clear(); + arguments.add(attrBagaaacccef); + arguments.add(attrBagbdfhj); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(1, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); + assertEquals(f, attrValueObject.getValue() ); + + // bag one has duplicates that do intersect + arguments.clear(); + arguments.add(attrBagaaacccef); + arguments.add(attrBagace); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(3, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); + assertEquals(a, attrValueObject.getValue() ); + attrValueObject = it.next(); + assertEquals(c, attrValueObject.getValue() ); + attrValueObject = it.next(); + assertEquals(e, attrValueObject.getValue() ); + + // bag 2 has duplicates that do not intersect + arguments.clear(); + arguments.add(attrBagbdfhj); + arguments.add(attrBagaaacccef); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(1, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); + assertEquals(f, attrValueObject.getValue() ); + + // bag 2 has duplicates that intersect + arguments.clear(); + arguments.add(attrBagace); + arguments.add(attrBagaaacccef); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(3, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); + assertEquals(a, attrValueObject.getValue() ); + attrValueObject = it.next(); + assertEquals(c, attrValueObject.getValue() ); + attrValueObject = it.next(); + assertEquals(e, attrValueObject.getValue() ); + + // first bag is empty + arguments.clear(); + arguments.add(attrBagEmpty); + arguments.add(attrBagaaacccef); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(0, bag.size()); + + // second bag is empty + arguments.clear(); + arguments.add(attrBagace); + arguments.add(attrBagEmpty); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(0, bag.size()); + + // bags of different types + arguments.clear(); + arguments.add(attrBagace); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(1, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); + assertEquals(a, attrValueObject.getValue() ); + + arguments.clear(); + arguments.add(attrBagace); + arguments.add(attrBagInt); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(0, bag.size()); + + // first not a bag + arguments.clear(); + arguments.add(attrBadType); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-intersection Expected a bag, saw a simple value", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // second not a bag + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-intersection Expected a bag, saw a simple value", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // first null + arguments.clear(); + arguments.add(null); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-intersection Got null argument", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // second null + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-intersection Got null argument", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // too few args + arguments.clear(); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-intersection Expected 2 arguments, got 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-intersection Expected 2 arguments, got 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // too many args + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBagabcdefg); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-intersection Expected 2 arguments, got 3", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + + @Test + public void testInteger_intersection() { + BigInteger a = new BigInteger("1"); + BigInteger b = new BigInteger("2"); + BigInteger c = new BigInteger("3"); + BigInteger d = new BigInteger("4"); + BigInteger e = new BigInteger("5"); + BigInteger f = new BigInteger("6"); + BigInteger g = new BigInteger("7"); + BigInteger h = new BigInteger("8"); + BigInteger j = new BigInteger("9"); + + + Bag bagabcdefg = null; + Bag bagbdfhj = null; + Bag bagace = null; + Bag bagb = null; + Bag bagaaacccef = null; + Bag bagInt = null; + Bag bagStringInt = null; + Bag bagEmpty = null; + + FunctionArgumentAttributeValue attrBadType = null; + + try { + bagabcdefg = new Bag(); + bagabcdefg.add(DataTypes.DT_INTEGER.createAttributeValue(a)); + bagabcdefg.add(DataTypes.DT_INTEGER.createAttributeValue(b)); + bagabcdefg.add(DataTypes.DT_INTEGER.createAttributeValue(c)); + bagabcdefg.add(DataTypes.DT_INTEGER.createAttributeValue(d)); + bagabcdefg.add(DataTypes.DT_INTEGER.createAttributeValue(e)); + bagabcdefg.add(DataTypes.DT_INTEGER.createAttributeValue(f)); + bagabcdefg.add(DataTypes.DT_INTEGER.createAttributeValue(g)); + bagbdfhj = new Bag(); + bagbdfhj.add(DataTypes.DT_INTEGER.createAttributeValue(b)); + bagbdfhj.add(DataTypes.DT_INTEGER.createAttributeValue(d)); + bagbdfhj.add(DataTypes.DT_INTEGER.createAttributeValue(f)); + bagbdfhj.add(DataTypes.DT_INTEGER.createAttributeValue(h)); + bagbdfhj.add(DataTypes.DT_INTEGER.createAttributeValue(j)); + bagace = new Bag(); + bagace.add(DataTypes.DT_INTEGER.createAttributeValue(a)); + bagace.add(DataTypes.DT_INTEGER.createAttributeValue(c)); + bagace.add(DataTypes.DT_INTEGER.createAttributeValue(e)); + bagb = new Bag(); + bagb.add(DataTypes.DT_INTEGER.createAttributeValue(b)); + bagaaacccef = new Bag(); + bagaaacccef.add(DataTypes.DT_INTEGER.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_INTEGER.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_INTEGER.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_INTEGER.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_INTEGER.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_INTEGER.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_INTEGER.createAttributeValue(e)); + bagaaacccef.add(DataTypes.DT_INTEGER.createAttributeValue(f)); + bagInt = new Bag(); + bagInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); + bagStringInt = new Bag(); + bagStringInt.add(DataTypes.DT_STRING.createAttributeValue("abc")); + bagStringInt.add(DataTypes.DT_INTEGER.createAttributeValue(1)); + bagEmpty = new Bag(); + + attrBadType = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.1)); + } catch (Exception ex) { + fail("creating attribute e="+ ex); + } + + // make into attributes + FunctionArgumentBag attrBagabcdefg = new FunctionArgumentBag(bagabcdefg); + FunctionArgumentBag attrBagbdfhj = new FunctionArgumentBag(bagbdfhj); + FunctionArgumentBag attrBagace = new FunctionArgumentBag(bagace); + FunctionArgumentBag attrBagb = new FunctionArgumentBag(bagb); + FunctionArgumentBag attrBagaaacccef = new FunctionArgumentBag(bagaaacccef); + FunctionArgumentBag attrBagInt = new FunctionArgumentBag(bagInt); + FunctionArgumentBag attrBagStringInt = new FunctionArgumentBag(bagStringInt); + FunctionArgumentBag attrBagEmpty = new FunctionArgumentBag(bagEmpty); + + FunctionDefinitionSet fd = (FunctionDefinitionSet) StdFunctions.FD_INTEGER_INTERSECTION; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_INTEGER_INTERSECTION, fd.getId()); + assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertTrue(fd.returnsBag()); + + // normal intersection (everything in both bags, no duplicates) + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBagabcdefg); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Bag bag = res.getBag(); + assertNotNull(bag); + Iterator> it = bag.getAttributeValues(); + assertEquals(7, bag.size()); + AttributeValue attrValueObject = it.next(); + assertEquals(DataTypes.DT_INTEGER.getId(), attrValueObject.getDataTypeId()); + assertEquals(a, attrValueObject.getValue() ); + + // several but not all intersection + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBagbdfhj); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(3, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_INTEGER.getId(), attrValueObject.getDataTypeId()); + assertEquals(b, attrValueObject.getValue() ); + + // no intersection + arguments.clear(); + arguments.add(attrBagace); + arguments.add(attrBagbdfhj); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(0, bag.size()); + + // one intersection + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBagb); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(1, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_INTEGER.getId(), attrValueObject.getDataTypeId()); + assertEquals(b, attrValueObject.getValue() ); + + // bag one has duplicates that do not intersect + arguments.clear(); + arguments.add(attrBagaaacccef); + arguments.add(attrBagbdfhj); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(1, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_INTEGER.getId(), attrValueObject.getDataTypeId()); + assertEquals(f, attrValueObject.getValue() ); + + // bag one has duplicates that do intersect + arguments.clear(); + arguments.add(attrBagaaacccef); + arguments.add(attrBagace); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(3, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_INTEGER.getId(), attrValueObject.getDataTypeId()); + assertEquals(a, attrValueObject.getValue() ); + attrValueObject = it.next(); + assertEquals(c, attrValueObject.getValue() ); + attrValueObject = it.next(); + assertEquals(e, attrValueObject.getValue() ); + + // bag 2 has duplicates that do not intersect + arguments.clear(); + arguments.add(attrBagbdfhj); + arguments.add(attrBagaaacccef); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(1, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_INTEGER.getId(), attrValueObject.getDataTypeId()); + assertEquals(f, attrValueObject.getValue() ); + + // bag 2 has duplicates that intersect + arguments.clear(); + arguments.add(attrBagace); + arguments.add(attrBagaaacccef); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(3, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_INTEGER.getId(), attrValueObject.getDataTypeId()); + assertEquals(a, attrValueObject.getValue() ); + attrValueObject = it.next(); + assertEquals(c, attrValueObject.getValue() ); + attrValueObject = it.next(); + assertEquals(e, attrValueObject.getValue() ); + + // first bag is empty + arguments.clear(); + arguments.add(attrBagEmpty); + arguments.add(attrBagaaacccef); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(0, bag.size()); + + // second bag is empty + arguments.clear(); + arguments.add(attrBagbdfhj); + arguments.add(attrBagEmpty); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(0, bag.size()); + + // bags of different types + arguments.clear(); + arguments.add(attrBagace); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(1, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_INTEGER.getId(), attrValueObject.getDataTypeId()); + assertEquals(a, attrValueObject.getValue() ); + + arguments.clear(); + arguments.add(attrBagace); + arguments.add(attrBagInt); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(1, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_INTEGER.getId(), attrValueObject.getDataTypeId()); + assertEquals(a, attrValueObject.getValue() ); + + + // first not a bag + arguments.clear(); + arguments.add(attrBadType); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:integer-intersection Expected a bag, saw a simple value", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // second not a bag + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:integer-intersection Expected a bag, saw a simple value", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // first null + arguments.clear(); + arguments.add(null); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:integer-intersection Got null argument", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // second null + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:integer-intersection Got null argument", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // too few args + arguments.clear(); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:integer-intersection Expected 2 arguments, got 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:integer-intersection Expected 2 arguments, got 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // too many args + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBagabcdefg); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:integer-intersection Expected 2 arguments, got 3", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + + + + + + + + + + + + // + // AT_LEAST_ONE_MEMBER_OF tests + // + + @Test + public void testString_at_least_one_member_of() { + String a = "a"; + String b = "b"; + String c = "c"; + String d = "d"; + String e = "e"; + String f = "f"; + String g = "g"; + String h = "h"; + String j = "j"; + + + Bag bagabcdefg = null; + Bag bagbdfhj = null; + Bag bagace = null; + Bag bagb = null; + Bag bagaaaccce = null; + Bag bagInt = null; + Bag bagStringInt = null; + Bag bagEmpty = null; + + FunctionArgumentAttributeValue attrBadType = null; + + try { + bagabcdefg = new Bag(); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(d)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(g)); + bagbdfhj = new Bag(); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(d)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(h)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(j)); + bagace = new Bag(); + bagace.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagace.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagace.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagb = new Bag(); + bagb.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagaaaccce = new Bag(); + bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagInt = new Bag(); + bagInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); + bagStringInt = new Bag(); + bagStringInt.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagStringInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); + bagEmpty = new Bag(); + + attrBadType = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.1)); + } catch (Exception ex) { + fail("creating attribute e="+ ex); + } + + // make into attributes + FunctionArgumentBag attrBagabcdefg = new FunctionArgumentBag(bagabcdefg); + FunctionArgumentBag attrBagbdfhj = new FunctionArgumentBag(bagbdfhj); + FunctionArgumentBag attrBagace = new FunctionArgumentBag(bagace); + FunctionArgumentBag attrBagb = new FunctionArgumentBag(bagb); + FunctionArgumentBag attrBagaaaccce = new FunctionArgumentBag(bagaaaccce); + FunctionArgumentBag attrBagInt = new FunctionArgumentBag(bagInt); + FunctionArgumentBag attrBagStringInt = new FunctionArgumentBag(bagStringInt); + FunctionArgumentBag attrBagEmpty = new FunctionArgumentBag(bagEmpty); + + FunctionDefinitionSet fd = (FunctionDefinitionSet) StdFunctions.FD_STRING_AT_LEAST_ONE_MEMBER_OF; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_AT_LEAST_ONE_MEMBER_OF, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + // normal intersection (everything in both bags, no duplicates) + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBagabcdefg); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + + // several but not all intersection + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBagbdfhj); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // no intersection + arguments.clear(); + arguments.add(attrBagace); + arguments.add(attrBagbdfhj); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // one intersection + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBagb); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // bag one has duplicates that do not intersect + arguments.clear(); + arguments.add(attrBagaaaccce); + arguments.add(attrBagbdfhj); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // bag one has duplicates that do intersect + arguments.clear(); + arguments.add(attrBagaaaccce); + arguments.add(attrBagace); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // bag 2 has duplicates that do not intersect + arguments.clear(); + arguments.add(attrBagbdfhj); + arguments.add(attrBagaaaccce); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // bag 2 has duplicates that intersect + arguments.clear(); + arguments.add(attrBagace); + arguments.add(attrBagaaaccce); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // 2 empty bags + arguments.clear(); + arguments.add(attrBagEmpty); + arguments.add(attrBagEmpty); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first non-empty, 2nd empty + arguments.clear(); + arguments.add(attrBagaaaccce); + arguments.add(attrBagEmpty); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first empty, 2nd not empty + arguments.clear(); + arguments.add(attrBagEmpty); + arguments.add(attrBagaaaccce); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // bags of different types + arguments.clear(); + arguments.add(attrBagace); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + arguments.clear(); + arguments.add(attrBagace); + arguments.add(attrBagInt); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + arguments.clear(); + arguments.add(attrBagace); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // first not a bag + arguments.clear(); + arguments.add(attrBadType); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-at-least-one-member-of Expected a bag, saw a simple value", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // second not a bag + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-at-least-one-member-of Expected a bag, saw a simple value", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // first null + arguments.clear(); + arguments.add(null); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-at-least-one-member-of Got null argument", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // second null + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-at-least-one-member-of Got null argument", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // too few args + arguments.clear(); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-at-least-one-member-of Expected 2 arguments, got 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-at-least-one-member-of Expected 2 arguments, got 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // too many args + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBagabcdefg); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-at-least-one-member-of Expected 2 arguments, got 3", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + + + + + + + + + + + + // + // UNION tests + // + + + + + + @Test + public void testString_union() { + String a = "a"; + String b = "b"; + String c = "c"; + String d = "d"; + String e = "e"; + String f = "f"; + String g = "g"; + String h = "h"; + String j = "j"; + + + Bag bagabcdefg = null; + Bag bagbdfhj = null; + Bag bagace = null; + Bag bagaaacccef = null; + Bag bagInt = null; + Bag bagStringInt = null; + Bag bagEmpty = null; + + FunctionArgumentAttributeValue attrBadType = null; + + try { + bagabcdefg = new Bag(); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(d)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(g)); + bagbdfhj = new Bag(); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(d)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(h)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(j)); + bagace = new Bag(); + bagace.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagace.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagace.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagaaacccef = new Bag(); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagInt = new Bag(); + bagInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); + bagStringInt = new Bag(); + bagStringInt.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagStringInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); + bagEmpty = new Bag(); + + attrBadType = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.1)); + } catch (Exception ex) { + fail("creating attribute e="+ ex); + } + + // make into attributes + FunctionArgumentBag attrBagabcdefg = new FunctionArgumentBag(bagabcdefg); + FunctionArgumentBag attrBagbdfhj = new FunctionArgumentBag(bagbdfhj); + FunctionArgumentBag attrBagace = new FunctionArgumentBag(bagace); + FunctionArgumentBag attrBagaaacccef = new FunctionArgumentBag(bagaaacccef); + FunctionArgumentBag attrBagInt = new FunctionArgumentBag(bagInt); + FunctionArgumentBag attrBagStringInt = new FunctionArgumentBag(bagStringInt); + FunctionArgumentBag attrBagEmpty = new FunctionArgumentBag(bagEmpty); + + FunctionDefinitionSet fd = (FunctionDefinitionSet) StdFunctions.FD_STRING_UNION; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_UNION, fd.getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertTrue(fd.returnsBag()); + + // normal intersection (everything in both bags, no duplicates) + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBagabcdefg); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Bag bag = res.getBag(); + assertNotNull(bag); + Iterator> it = bag.getAttributeValues(); + assertEquals(7, bag.size()); + AttributeValue attrValueObject = it.next(); + assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); + assertEquals(a, attrValueObject.getValue() ); + + // several but not all union + arguments.clear(); + arguments.add(attrBagace); + arguments.add(attrBagbdfhj); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(8, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); + assertEquals(a, attrValueObject.getValue() ); + + // bag one has duplicates that do not match first bag + arguments.clear(); + arguments.add(attrBagaaacccef); + arguments.add(attrBagbdfhj); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(8, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); + assertEquals(a, attrValueObject.getValue() ); + + // bag one has duplicates that do match first bag + arguments.clear(); + arguments.add(attrBagaaacccef); + arguments.add(attrBagace); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(4, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); + assertEquals(a, attrValueObject.getValue() ); + attrValueObject = it.next(); + assertEquals(c, attrValueObject.getValue() ); + attrValueObject = it.next(); + assertEquals(e, attrValueObject.getValue() ); + + // bag 2 has duplicates that do not match first bag + arguments.clear(); + arguments.add(attrBagbdfhj); + arguments.add(attrBagaaacccef); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(8, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); + assertEquals(b, attrValueObject.getValue() ); + + // bag 2 has duplicates that do match first bag + arguments.clear(); + arguments.add(attrBagace); + arguments.add(attrBagaaacccef); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(4, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); + assertEquals(a, attrValueObject.getValue() ); + attrValueObject = it.next(); + assertEquals(c, attrValueObject.getValue() ); + attrValueObject = it.next(); + assertEquals(e, attrValueObject.getValue() ); + + // two empty bags + arguments.clear(); + arguments.add(attrBagEmpty); + arguments.add(attrBagEmpty); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(0, bag.size()); + + // first bag empty, 2nd not empty + arguments.clear(); + arguments.add(attrBagEmpty); + arguments.add(attrBagaaacccef); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(4, bag.size()); + + // first bag not empty, 2nd empty + arguments.clear(); + arguments.add(attrBagaaacccef); + arguments.add(attrBagEmpty); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(4, bag.size()); + + // bags of different types + arguments.clear(); + arguments.add(attrBagace); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(4, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); + assertEquals(a, attrValueObject.getValue() ); + + arguments.clear(); + arguments.add(attrBagace); + arguments.add(attrBagInt); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + bag = res.getBag(); + assertNotNull(bag); + it = bag.getAttributeValues(); + assertEquals(4, bag.size()); + attrValueObject = it.next(); + assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); + assertEquals(a, attrValueObject.getValue() ); + + // first not a bag + arguments.clear(); + arguments.add(attrBadType); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-union Expected a bag, saw a simple value", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // second not a bag + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-union Expected a bag, saw a simple value", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // first null + arguments.clear(); + arguments.add(null); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-union Got null argument", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // second null + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-union Got null argument", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // too few args + arguments.clear(); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-union Expected 2 arguments, got 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-union Expected 2 arguments, got 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // too many args + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBagabcdefg); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-union Expected 2 arguments, got 3", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + + + + + + + + + // + // SUBSET tests + // + + @Test + public void testString_subset() { + String a = "a"; + String b = "b"; + String c = "c"; + String d = "d"; + String e = "e"; + String f = "f"; + String g = "g"; + String h = "h"; + String j = "j"; + + + Bag bagabcdefg = null; + Bag bagbdfhj = null; + Bag bagace = null; + Bag bagb = null; + Bag bagaaaccce = null; + Bag bagInt = null; + Bag bagStringInt = null; + Bag bagEmpty = null; + + FunctionArgumentAttributeValue attrBadType = null; + + try { + bagabcdefg = new Bag(); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(d)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(g)); + bagbdfhj = new Bag(); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(d)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(h)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(j)); + bagace = new Bag(); + bagace.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagace.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagace.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagb = new Bag(); + bagb.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagaaaccce = new Bag(); + bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagInt = new Bag(); + bagInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); + bagStringInt = new Bag(); + bagStringInt.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagStringInt.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagStringInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); + bagEmpty = new Bag(); + + attrBadType = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.1)); + } catch (Exception ex) { + fail("creating attribute e="+ ex); + } + + // make into attributes + FunctionArgumentBag attrBagabcdefg = new FunctionArgumentBag(bagabcdefg); + FunctionArgumentBag attrBagbdfhj = new FunctionArgumentBag(bagbdfhj); + FunctionArgumentBag attrBagace = new FunctionArgumentBag(bagace); + FunctionArgumentBag attrBagb = new FunctionArgumentBag(bagb); + FunctionArgumentBag attrBagaaaccce = new FunctionArgumentBag(bagaaaccce); + FunctionArgumentBag attrBagInt = new FunctionArgumentBag(bagInt); + FunctionArgumentBag attrBagStringInt = new FunctionArgumentBag(bagStringInt); + FunctionArgumentBag attrBagEmpty = new FunctionArgumentBag(bagEmpty); + + FunctionDefinitionSet fd = (FunctionDefinitionSet) StdFunctions.FD_STRING_SUBSET; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_SUBSET, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + // normal intersection (everything in both bags, no duplicates) + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBagabcdefg); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + + // not subset + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBagbdfhj); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // subset + arguments.clear(); + arguments.add(attrBagace); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + + // no intersection + arguments.clear(); + arguments.add(attrBagace); + arguments.add(attrBagbdfhj); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // Not + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBagb); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // Subset + arguments.clear(); + arguments.add(attrBagb); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // bag one has duplicates that do not intersect + arguments.clear(); + arguments.add(attrBagaaaccce); + arguments.add(attrBagbdfhj); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // bag one has duplicates that do intersect + arguments.clear(); + arguments.add(attrBagaaaccce); + arguments.add(attrBagace); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // bag 2 has duplicates that do not intersect + arguments.clear(); + arguments.add(attrBagbdfhj); + arguments.add(attrBagaaaccce); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // bag 2 has duplicates that intersect + arguments.clear(); + arguments.add(attrBagace); + arguments.add(attrBagaaaccce); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // 2 empty bags + arguments.clear(); + arguments.add(attrBagEmpty); + arguments.add(attrBagEmpty); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // first non-empty, 2nd empty + arguments.clear(); + arguments.add(attrBagaaaccce); + arguments.add(attrBagEmpty); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first empty, 2nd not empty + arguments.clear(); + arguments.add(attrBagEmpty); + arguments.add(attrBagaaaccce); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // bags of different types + arguments.clear(); + arguments.add(attrBagace); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + arguments.clear(); + arguments.add(attrBagb); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + arguments.clear(); + arguments.add(attrBagace); + arguments.add(attrBagInt); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first not a bag + arguments.clear(); + arguments.add(attrBadType); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-subset Expected a bag, saw a simple value", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // second not a bag + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-subset Expected a bag, saw a simple value", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // first null + arguments.clear(); + arguments.add(null); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-subset Got null argument", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // second null + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-subset Got null argument", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // too few args + arguments.clear(); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-subset Expected 2 arguments, got 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-subset Expected 2 arguments, got 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // too many args + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBagabcdefg); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-subset Expected 2 arguments, got 3", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + + + + + + + + + + // + // SET_EQUALS tests + // + + @Test + public void testString_set_equals() { + String a = "a"; + String b = "b"; + String c = "c"; + String d = "d"; + String e = "e"; + String f = "f"; + String g = "g"; + String h = "h"; + String j = "j"; + + + Bag bagabcdefg = null; + Bag bagbdfhj = null; + Bag bagace = null; + Bag bagb = null; + Bag bagaaaccce = null; + Bag bagInt = null; + Bag bagStringInt = null; + Bag bagEmpty = null; + + FunctionArgumentAttributeValue attrBadType = null; + + try { + bagabcdefg = new Bag(); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(d)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(g)); + bagbdfhj = new Bag(); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(d)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(f)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(h)); + bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(j)); + bagace = new Bag(); + bagace.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagace.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagace.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagb = new Bag(); + bagb.add(DataTypes.DT_STRING.createAttributeValue(b)); + bagaaaccce = new Bag(); + bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(c)); + bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(e)); + bagInt = new Bag(); + bagInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); + bagStringInt = new Bag(); + bagStringInt.add(DataTypes.DT_STRING.createAttributeValue(a)); + bagStringInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); + bagEmpty = new Bag(); + + attrBadType = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.1)); + } catch (Exception ex) { + fail("creating attribute e="+ ex); + } + + // make into attributes + FunctionArgumentBag attrBagabcdefg = new FunctionArgumentBag(bagabcdefg); + FunctionArgumentBag attrBagbdfhj = new FunctionArgumentBag(bagbdfhj); + FunctionArgumentBag attrBagace = new FunctionArgumentBag(bagace); + FunctionArgumentBag attrBagb = new FunctionArgumentBag(bagb); + FunctionArgumentBag attrBagaaaccce = new FunctionArgumentBag(bagaaaccce); + FunctionArgumentBag attrBagInt = new FunctionArgumentBag(bagInt); + FunctionArgumentBag attrBagStringInt = new FunctionArgumentBag(bagStringInt); + FunctionArgumentBag attrBagEmpty = new FunctionArgumentBag(bagEmpty); + + FunctionDefinitionSet fd = (FunctionDefinitionSet) StdFunctions.FD_STRING_SET_EQUALS; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_SET_EQUALS, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + // normal intersection (everything in both bags, no duplicates) + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBagabcdefg); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + + // several but not all intersection + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBagbdfhj); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // no intersection + arguments.clear(); + arguments.add(attrBagace); + arguments.add(attrBagbdfhj); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // one intersection + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBagb); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // bag one has duplicates that do not intersect + arguments.clear(); + arguments.add(attrBagaaaccce); + arguments.add(attrBagbdfhj); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // bag one has duplicates that do intersect + arguments.clear(); + arguments.add(attrBagaaaccce); + arguments.add(attrBagace); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // bag 2 has duplicates that do not intersect + arguments.clear(); + arguments.add(attrBagbdfhj); + arguments.add(attrBagaaaccce); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // bag 2 has duplicates that intersect + arguments.clear(); + arguments.add(attrBagace); + arguments.add(attrBagaaaccce); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // 2 empty bags + arguments.clear(); + arguments.add(attrBagEmpty); + arguments.add(attrBagEmpty); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // first non-empty, 2nd empty + arguments.clear(); + arguments.add(attrBagaaaccce); + arguments.add(attrBagEmpty); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first empty, 2nd not empty + arguments.clear(); + arguments.add(attrBagEmpty); + arguments.add(attrBagaaaccce); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // bags of different types + arguments.clear(); + arguments.add(attrBagace); + arguments.add(attrBagStringInt); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + arguments.clear(); + arguments.add(attrBagace); + arguments.add(attrBagInt); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first not a bag + arguments.clear(); + arguments.add(attrBadType); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-set-equals Expected a bag, saw a simple value", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // second not a bag + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-set-equals Expected a bag, saw a simple value", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // first null + arguments.clear(); + arguments.add(null); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-set-equals Got null argument", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // second null + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-set-equals Got null argument", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // too few args + arguments.clear(); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-set-equals Expected 2 arguments, got 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-set-equals Expected 2 arguments, got 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // too many args + arguments.clear(); + arguments.add(attrBagabcdefg); + arguments.add(attrBagabcdefg); + arguments.add(attrBagabcdefg); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-set-equals Expected 2 arguments, got 3", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + + + + + + + + + // + // + // REST OF DATA TYPES OMITTED + // because they "should" all work the same + // + // + + + + +} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionSpecialMatchTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionSpecialMatchTest.java new file mode 100644 index 000000000..3bce2f6cc --- /dev/null +++ b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionSpecialMatchTest.java @@ -0,0 +1,488 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-TEST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.std.functions; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.util.ArrayList; +import java.util.List; + +import javax.security.auth.x500.X500Principal; + +import org.junit.Test; + +import com.att.research.xacml.api.XACML3; +import com.att.research.xacml.std.datatypes.DataTypes; +import com.att.research.xacmlatt.pdp.policy.Bag; +import com.att.research.xacmlatt.pdp.policy.ExpressionResult; +import com.att.research.xacmlatt.pdp.policy.FunctionArgument; +import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; +import com.att.research.xacmlatt.pdp.policy.FunctionArgumentBag; +import com.att.research.xacmlatt.pdp.std.StdFunctions; +import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionRFC822NameMatch; +import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionX500NameMatch; + +/** + * Test of PDP Functions (See XACML core spec section A.3) + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * + */ +public class FunctionDefinitionSpecialMatchTest { + + /* + * variables useful in the following tests + */ + List arguments = new ArrayList(); + + @Test + public void testX500NameMatch() { + // assume that the contents of the name components are not significant and we can treat them as simple blocks of "=" + String A = "cn=Some person"; + String B = "O=Medico Corp"; + String C = "C=US"; + String D = "DNQUALIFIER=d string"; + String E = "SURNAME=some name"; + String F = "INITIALS=inits"; + + + X500Principal abc = new X500Principal(A + "," + B + "," + C); + X500Principal dabc = new X500Principal(D + "," + A + "," + B + "," + C); + X500Principal abcd = new X500Principal(A + "," + B + "," + C + "," + D); + X500Principal adbc = new X500Principal(A + "," + D + "," + B + "," + C); + X500Principal dcab = new X500Principal(D + "," + C + "," + A + "," + B) ; + X500Principal def = new X500Principal(D + "," + E + "," + F) ; + + + FunctionArgumentAttributeValue attrABC = null; + FunctionArgumentAttributeValue attrDABC = null; + FunctionArgumentAttributeValue attrABCD = null; + FunctionArgumentAttributeValue attrADBC = null; + FunctionArgumentAttributeValue attrDCAB = null; + FunctionArgumentAttributeValue attrDEF = null; + + FunctionArgumentAttributeValue attrBad = null; + FunctionArgumentBag attrBag = new FunctionArgumentBag(new Bag()); + + + try { + attrABC = new FunctionArgumentAttributeValue(DataTypes.DT_X500NAME.createAttributeValue(abc)); + attrDABC = new FunctionArgumentAttributeValue(DataTypes.DT_X500NAME.createAttributeValue(dabc)); + attrABCD = new FunctionArgumentAttributeValue(DataTypes.DT_X500NAME.createAttributeValue(abcd)); + attrADBC = new FunctionArgumentAttributeValue(DataTypes.DT_X500NAME.createAttributeValue(adbc)); + attrDCAB = new FunctionArgumentAttributeValue(DataTypes.DT_X500NAME.createAttributeValue(dcab)); + attrDEF = new FunctionArgumentAttributeValue(DataTypes.DT_X500NAME.createAttributeValue(def)); + + attrBad = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionX500NameMatch fd = (FunctionDefinitionX500NameMatch) StdFunctions.FD_X500NAME_MATCH; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_X500NAME_MATCH, fd.getId()); + assertEquals(DataTypes.DT_X500NAME.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + + // test normal, first exact match for second + arguments.clear(); + arguments.add(attrABC); + arguments.add(attrABC); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // test first is end of second + arguments.clear(); + arguments.add(attrABC); + arguments.add(attrDABC); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // first exact match for sub-section but not end of second + arguments.clear(); + arguments.add(attrABC); + arguments.add(attrABCD); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // components of first match components in second but not contiguous + arguments.clear(); + arguments.add(attrABC); + arguments.add(attrADBC); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // components of first match components in second but not in order + arguments.clear(); + arguments.add(attrABC); + arguments.add(attrDCAB); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first does not match second at all + arguments.clear(); + arguments.add(attrABC); + arguments.add(attrDEF); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first arg larger than 2nd arg + arguments.clear(); + arguments.add(attrABCD); + arguments.add(attrABC); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // bad arg types + arguments.clear(); + arguments.add(attrABC); + arguments.add(attrBad); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:x500Name-match Expected data type 'x500Name' saw 'integer' at arg index 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // too many args + arguments.clear(); + arguments.add(attrABC); + arguments.add(attrABC); + arguments.add(attrABC); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:x500Name-match Expected 2 arguments, got 3", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // too few args + arguments.clear(); + arguments.add(attrABC); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:x500Name-match Expected 2 arguments, got 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:x500Name-match Expected 2 arguments, got 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // one arg is bag + arguments.clear(); + arguments.add(attrABC); + arguments.add(attrBag); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:x500Name-match Expected a simple value, saw a bag at arg index 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null arg + arguments.clear(); + arguments.add(null); + arguments.add(attrBag); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:x500Name-match Got null argument at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + @Test + public void testRfc822NameMatch() { + + + + + FunctionArgumentAttributeValue attrStringabcxyz = null; + FunctionArgumentAttributeValue attrStringABCxyz = null; + FunctionArgumentAttributeValue attrStringabcXYZ = null; + FunctionArgumentAttributeValue attrStringcx = null; + FunctionArgumentAttributeValue attrStringwholedomainpart = null; + FunctionArgumentAttributeValue attrStringWholeDomainPart = null; + FunctionArgumentAttributeValue attrStringWholeDomain = null; + FunctionArgumentAttributeValue attrStringdomainpart = null; + FunctionArgumentAttributeValue attrStringDomainPart = null; + FunctionArgumentAttributeValue attrStringdotWholeDomain = null; + FunctionArgumentAttributeValue attrStringdomain = null; + + FunctionArgumentAttributeValue attrStringNoMatch = null; + FunctionArgumentAttributeValue attrStringMultipleAt = null; + FunctionArgumentAttributeValue attrStringMissingLocal = null; + FunctionArgumentAttributeValue attrStringMissingDomain = null; + + + FunctionArgumentAttributeValue attrRfcabcxyz = null; + FunctionArgumentAttributeValue attrRfcwholedomainpart = null; + FunctionArgumentAttributeValue attrRfcWholeDomainPart = null; + + FunctionArgumentBag attrBag = new FunctionArgumentBag(new Bag()); + + try { + attrStringabcxyz = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("abc@xyz")); + attrStringABCxyz = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("ABC@xyz")); + attrStringabcXYZ = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("abc@XYZ")); + attrStringcx = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("c@x")); + attrStringwholedomainpart = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("whole.domain.part")); + attrStringWholeDomainPart = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("Whole.Domain.Part")); + attrStringWholeDomain = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("Whole.Domain")); + attrStringdomainpart = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(".domain.part")); + attrStringDomainPart = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(".Domain.Part")); + attrStringdotWholeDomain = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(".Whole.Domain")); + attrStringdomain = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(".domain.")); + + attrStringNoMatch = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("no match to any legal name")); + attrStringMultipleAt = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("name@with@multipleAts")); + attrStringMissingLocal = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("@multipleAts")); + attrStringMissingDomain = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("localpart@")); + + attrRfcabcxyz = new FunctionArgumentAttributeValue(DataTypes.DT_RFC822NAME.createAttributeValue("abc@xyz")); + attrRfcwholedomainpart = new FunctionArgumentAttributeValue(DataTypes.DT_RFC822NAME.createAttributeValue("abc@whole.domain.part")); + attrRfcWholeDomainPart = new FunctionArgumentAttributeValue(DataTypes.DT_RFC822NAME.createAttributeValue("abc@Whole.Domain.Part")); + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionRFC822NameMatch fd = (FunctionDefinitionRFC822NameMatch) StdFunctions.FD_RFC822NAME_MATCH; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_RFC822NAME_MATCH, fd.getId()); + assertEquals(DataTypes.DT_RFC822NAME.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + + // string identical to name - exact match on whole search term + arguments.clear(); + arguments.add(attrStringabcxyz); + arguments.add(attrRfcabcxyz); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.getStatus().isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // no match local case different + arguments.clear(); + arguments.add(attrStringABCxyz); + arguments.add(attrRfcabcxyz); + res = fd.evaluate(null, arguments); + assertTrue(res.getStatus().isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // match domain case different + arguments.clear(); + arguments.add(attrStringabcXYZ); + arguments.add(attrRfcabcxyz); + res = fd.evaluate(null, arguments); + assertTrue(res.getStatus().isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + + // partial local + partial domain + arguments.clear(); + arguments.add(attrStringcx); + arguments.add(attrRfcabcxyz); + res = fd.evaluate(null, arguments); + assertTrue(res.getStatus().isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // whole domain + arguments.clear(); + arguments.add(attrStringwholedomainpart); + arguments.add(attrRfcwholedomainpart); + res = fd.evaluate(null, arguments); + assertTrue(res.getStatus().isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // whole domain different case + arguments.clear(); + arguments.add(attrStringWholeDomainPart); + arguments.add(attrRfcwholedomainpart); + res = fd.evaluate(null, arguments); + assertTrue(res.getStatus().isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + arguments.clear(); + arguments.add(attrStringwholedomainpart); + arguments.add(attrRfcWholeDomainPart); + res = fd.evaluate(null, arguments); + assertTrue(res.getStatus().isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // whole domain fail + arguments.clear(); + arguments.add(attrStringWholeDomain); + arguments.add(attrRfcWholeDomainPart); + res = fd.evaluate(null, arguments); + assertTrue(res.getStatus().isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // partial domain match + arguments.clear(); + arguments.add(attrStringDomainPart); + arguments.add(attrRfcWholeDomainPart); + res = fd.evaluate(null, arguments); + assertTrue(res.getStatus().isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // partial domain different case + arguments.clear(); + arguments.add(attrStringdomainpart); + arguments.add(attrRfcWholeDomainPart); + res = fd.evaluate(null, arguments); + assertTrue(res.getStatus().isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // partial domain fail + arguments.clear(); + arguments.add(attrStringdotWholeDomain); + arguments.add(attrRfcWholeDomainPart); + res = fd.evaluate(null, arguments); + assertTrue(res.getStatus().isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + arguments.clear(); + arguments.add(attrStringdomain); + arguments.add(attrRfcWholeDomainPart); + res = fd.evaluate(null, arguments); + assertTrue(res.getStatus().isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // search term contains more than 1 @ + arguments.clear(); + arguments.add(attrStringMultipleAt); + arguments.add(attrRfcabcxyz); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:rfc822Name-match String contained more than 1 '@' in 'name@with@multipleAts'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // search term missing local part + arguments.clear(); + arguments.add(attrStringMissingLocal); + arguments.add(attrRfcabcxyz); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:rfc822Name-match String missing local part in '@multipleAts'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // search term missing domain part + arguments.clear(); + arguments.add(attrStringMissingDomain); + arguments.add(attrRfcabcxyz); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:rfc822Name-match String missing domain part in 'localpart@'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad arg types + arguments.clear(); + arguments.add(attrRfcabcxyz); + arguments.add(attrStringNoMatch); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:rfc822Name-match Expected data type 'string' saw 'rfc822Name' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // too many args + arguments.clear(); + arguments.add(attrStringNoMatch); + arguments.add(attrStringNoMatch); + arguments.add(attrStringNoMatch); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:rfc822Name-match Expected 2 arguments, got 3", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // too few args + arguments.clear(); + arguments.add(attrStringNoMatch); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:rfc822Name-match Expected 2 arguments, got 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:rfc822Name-match Expected 2 arguments, got 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // one arg is bag + arguments.clear(); + arguments.add(attrStringNoMatch); + arguments.add(attrBag); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:rfc822Name-match Expected a simple value, saw a bag at arg index 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null arg + arguments.clear(); + arguments.add(null); + arguments.add(attrStringNoMatch); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:rfc822Name-match Got null argument at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + + } + +} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionStringConversionTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionStringConversionTest.java new file mode 100644 index 000000000..341da61d0 --- /dev/null +++ b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionStringConversionTest.java @@ -0,0 +1,2504 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-TEST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.std.functions; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.math.BigInteger; +import java.net.URI; +import java.net.URISyntaxException; +import java.text.ParseException; +import java.util.ArrayList; +import java.util.List; + +import javax.security.auth.x500.X500Principal; + +import org.junit.Test; + +import com.att.research.xacml.api.XACML3; +import com.att.research.xacml.std.datatypes.DataTypes; +import com.att.research.xacml.std.datatypes.IPAddress; +import com.att.research.xacml.std.datatypes.IPv4Address; +import com.att.research.xacml.std.datatypes.IPv6Address; +import com.att.research.xacml.std.datatypes.ISO8601Date; +import com.att.research.xacml.std.datatypes.ISO8601DateTime; +import com.att.research.xacml.std.datatypes.ISO8601Time; +import com.att.research.xacml.std.datatypes.ISO8601TimeZone; +import com.att.research.xacml.std.datatypes.PortRange; +import com.att.research.xacml.std.datatypes.RFC2396DomainName; +import com.att.research.xacml.std.datatypes.RFC822Name; +import com.att.research.xacml.std.datatypes.XPathDayTimeDuration; +import com.att.research.xacml.std.datatypes.XPathYearMonthDuration; +import com.att.research.xacmlatt.pdp.policy.ExpressionResult; +import com.att.research.xacmlatt.pdp.policy.FunctionArgument; +import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; +import com.att.research.xacmlatt.pdp.std.StdFunctions; +import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionStringConversion; + +/** + * Tests for converting objects to/from Strings. + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * + */ +public class FunctionDefinitionStringConversionTest { + + /* + * variables useful in the following tests + */ + List arguments = new ArrayList(); + + + /** + * Boolean + */ + @Test + public void testBoolean_from_string() { + FunctionArgumentAttributeValue attrString1 = null; + FunctionArgumentAttributeValue attrStringBadValue = null; + FunctionArgumentAttributeValue attrStringBadType = null; + try { + attrString1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("true")); + attrStringBadValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("not valid obj value")); + attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionStringConversion fd = (FunctionDefinitionStringConversion) StdFunctions.FD_BOOLEAN_FROM_STRING; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_BOOLEAN_FROM_STRING, fd.getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + // test normal + arguments.clear(); + arguments.add(attrString1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertEquals(new Boolean(true), resValue); + + // bad value + arguments.clear(); + arguments.add(attrStringBadValue); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:boolean-from-string Cannot convert from \"java.lang.String\" with value \"not valid obj value\" to boolean", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrStringBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:boolean-from-string Expected data type 'string' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + @Test + public void testString_from_boolean() { + FunctionArgumentAttributeValue attrObj1 = null; + FunctionArgumentAttributeValue attrStringBadType = null; + String objValueString = "false"; + try { + attrObj1 = new FunctionArgumentAttributeValue(DataTypes.DT_BOOLEAN.createAttributeValue(objValueString)); + attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionStringConversion fd = (FunctionDefinitionStringConversion) StdFunctions.FD_STRING_FROM_BOOLEAN; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_FROM_BOOLEAN, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + // test normal + arguments.clear(); + arguments.add(attrObj1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(objValueString, res.getValue().getValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrStringBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-from-boolean Expected data type 'boolean' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + + + + /** + * Integer + */ + @Test + public void testInteger_from_string() { + FunctionArgumentAttributeValue attrString1 = null; + FunctionArgumentAttributeValue attrStringBadValue = null; + FunctionArgumentAttributeValue attrStringBadType = null; + try { + attrString1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("123456")); + attrStringBadValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("not valid obj value")); + attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionStringConversion fd = (FunctionDefinitionStringConversion) StdFunctions.FD_INTEGER_FROM_STRING; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_INTEGER_FROM_STRING, fd.getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + // test normal + arguments.clear(); + arguments.add(attrString1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + BigInteger resValue = (BigInteger)res.getValue().getValue(); + assertEquals(new BigInteger("123456"), resValue); + + // bad value + arguments.clear(); + arguments.add(attrStringBadValue); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:integer-from-string For input string: \"n\"", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrStringBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:integer-from-string Expected data type 'string' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + @Test + public void testString_from_integer() { + FunctionArgumentAttributeValue attrObj1 = null; + FunctionArgumentAttributeValue attrStringBadType = null; + String objValueString = "1234"; + try { + attrObj1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(objValueString)); + attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(123)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionStringConversion fd = (FunctionDefinitionStringConversion) StdFunctions.FD_STRING_FROM_INTEGER; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_FROM_INTEGER, fd.getId()); + assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + // test normal + arguments.clear(); + arguments.add(attrObj1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(objValueString, res.getValue().getValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrStringBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-from-integer Expected data type 'integer' saw 'double' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + + + /** + * Double + */ + @Test + public void testDouble_from_string() { + FunctionArgumentAttributeValue attrString1 = null; + FunctionArgumentAttributeValue attrStringBadValue = null; + FunctionArgumentAttributeValue attrStringBadType = null; + try { + attrString1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("5.432")); + attrStringBadValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("not valid obj value")); + attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionStringConversion fd = (FunctionDefinitionStringConversion) StdFunctions.FD_DOUBLE_FROM_STRING; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DOUBLE_FROM_STRING, fd.getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + // test normal + arguments.clear(); + arguments.add(attrString1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Double resValue = (Double)res.getValue().getValue(); + assertEquals(new Double(5.432), resValue); + + // bad value + arguments.clear(); + arguments.add(attrStringBadValue); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:double-from-string For input string: \"not valid obj value\"", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrStringBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:double-from-string Expected data type 'string' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + @Test + public void testString_from_double() { + FunctionArgumentAttributeValue attrObj1 = null; + FunctionArgumentAttributeValue attrObjBig = null; + FunctionArgumentAttributeValue attrStringBadType = null; + String objValueString = "5.432"; + String objValueStringBig = "55555555555555555555.123455"; + try { + attrObj1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(objValueString)); + attrObjBig = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(objValueStringBig)); + attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionStringConversion fd = (FunctionDefinitionStringConversion) StdFunctions.FD_STRING_FROM_DOUBLE; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_FROM_DOUBLE, fd.getId()); + assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + // test normal + arguments.clear(); + arguments.add(attrObj1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(objValueString, res.getValue().getValue()); + + arguments.clear(); + arguments.add(attrObjBig); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals("5.555555555555556E19", res.getValue().getValue()); + + + // bad arg type + arguments.clear(); + arguments.add(attrStringBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-from-double Expected data type 'double' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + + + + + /** + * Time + */ + @Test + public void testTime_from_string() { + FunctionArgumentAttributeValue attrString1 = null; + FunctionArgumentAttributeValue attrString2 = null; + FunctionArgumentAttributeValue attrString3 = null; + FunctionArgumentAttributeValue attrString4 = null; + FunctionArgumentAttributeValue attrStringTimeZone = null; + FunctionArgumentAttributeValue attrStringBadValue = null; + FunctionArgumentAttributeValue attrStringBadType = null; + try { + attrString1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("05:12:34.323")); + attrString2 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("5:12:34.323")); + attrString3 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("05:12")); + attrString4 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("05:12:34")); + attrStringTimeZone = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("05:12:34.323+03:00")); + attrStringBadValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("not valid obj value")); + attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionStringConversion fd = (FunctionDefinitionStringConversion) StdFunctions.FD_TIME_FROM_STRING; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_TIME_FROM_STRING, fd.getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_TIME.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + // test normal + arguments.clear(); + arguments.add(attrString1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + ISO8601Time resValue = (ISO8601Time)res.getValue().getValue(); + assertEquals(new ISO8601Time(5, 12, 34, 323), resValue); + + // check missing 0 in front + arguments.clear(); + arguments.add(attrString2); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:time-from-string Invalid hour of day", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // check missing seconds/msecs + arguments.clear(); + arguments.add(attrString3); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:time-from-string Time string too short", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // check missing just msecs + arguments.clear(); + arguments.add(attrString4); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (ISO8601Time)res.getValue().getValue(); + assertEquals(new ISO8601Time(5, 12, 34, 0), resValue); + + // check TimeZone + arguments.clear(); + arguments.add(attrStringTimeZone); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (ISO8601Time)res.getValue().getValue(); + assertEquals(new ISO8601Time(new ISO8601TimeZone(180), 5, 12, 34, 323), resValue); + + // bad value + arguments.clear(); + arguments.add(attrStringBadValue); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:time-from-string Invalid hour of day", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrStringBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:time-from-string Expected data type 'string' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + @Test + public void testString_from_time() { + FunctionArgumentAttributeValue attrObj1 = null; + FunctionArgumentAttributeValue attrObj2 = null; + FunctionArgumentAttributeValue attrObjTimeZone = null; + FunctionArgumentAttributeValue attrStringBadType = null; + try { + attrObj1 = new FunctionArgumentAttributeValue(DataTypes.DT_TIME.createAttributeValue("05:12:34.323")); + attrObj2 = new FunctionArgumentAttributeValue(DataTypes.DT_TIME.createAttributeValue("05:01:02.323")); + attrObjTimeZone = new FunctionArgumentAttributeValue(DataTypes.DT_TIME.createAttributeValue("05:12:34.323+03:00")); + attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionStringConversion fd = (FunctionDefinitionStringConversion) StdFunctions.FD_STRING_FROM_TIME; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_FROM_TIME, fd.getId()); + assertEquals(DataTypes.DT_TIME.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + // test normal + arguments.clear(); + arguments.add(attrObj1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals("05:12:34.323", res.getValue().getValue()); + + // missing digits in string value? + arguments.clear(); + arguments.add(attrObj2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals("05:01:02.323", res.getValue().getValue()); + + // include TimeZone + arguments.clear(); + arguments.add(attrObjTimeZone); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals("05:12:34.323+03:00", res.getValue().getValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrStringBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-from-time Expected data type 'time' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + + + + + /** + * Date + */ + @Test + public void testDate_from_string() { + FunctionArgumentAttributeValue attrString1 = null; + FunctionArgumentAttributeValue attrString2 = null; + FunctionArgumentAttributeValue attrString3 = null; + FunctionArgumentAttributeValue attrString4 = null; + FunctionArgumentAttributeValue attrString5 = null; + FunctionArgumentAttributeValue attrString6 = null; + FunctionArgumentAttributeValue attrString7 = null; + FunctionArgumentAttributeValue attrString8 = null; + FunctionArgumentAttributeValue attrString9 = null; + FunctionArgumentAttributeValue attrStringDateZone = null; + FunctionArgumentAttributeValue attrStringBadValue = null; + FunctionArgumentAttributeValue attrStringBadType = null; + try { + attrString1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("2013-05-12")); + attrString2 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("-2013-05-12")); + attrString3 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("1232013-05-12")); + attrString4 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("-1232013-05-12")); + attrString5 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("213-05-12")); + attrString6 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("2013-5-12")); + attrString7 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("2013-05-2")); + attrString8 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("2013-32-12")); + attrString9 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("2013-05-45")); + attrStringDateZone = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("2013-05-12+03:00")); + attrStringBadValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("not valid obj value")); + attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionStringConversion fd = (FunctionDefinitionStringConversion) StdFunctions.FD_DATE_FROM_STRING; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DATE_FROM_STRING, fd.getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_DATE.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + // test normal + arguments.clear(); + arguments.add(attrString1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + ISO8601Date resValue = (ISO8601Date)res.getValue().getValue(); + assertEquals(new ISO8601Date(2013, 5, 12), resValue); + + // check negative + arguments.clear(); + arguments.add(attrString2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (ISO8601Date)res.getValue().getValue(); + assertEquals(new ISO8601Date(-2013, 5, 12), resValue); + + // check big + arguments.clear(); + arguments.add(attrString3); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (ISO8601Date)res.getValue().getValue(); + assertEquals(new ISO8601Date(1232013, 5, 12), resValue); + + // check big negative + arguments.clear(); + arguments.add(attrString4); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (ISO8601Date)res.getValue().getValue(); + assertEquals(new ISO8601Date(-1232013, 5, 12), resValue); + + // bad year + arguments.clear(); + arguments.add(attrString5); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:date-from-string Invalid year (must be at least 4 digits)", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad month + arguments.clear(); + arguments.add(attrString6); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:date-from-string Invalid month", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad day format + arguments.clear(); + arguments.add(attrString7); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:date-from-string Invalid day", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // month out of range + arguments.clear(); + arguments.add(attrString8); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:date-from-string Invalid month", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // day out of range + arguments.clear(); + arguments.add(attrString9); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:date-from-string Invalid day", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // check TimeZone + arguments.clear(); + arguments.add(attrStringDateZone); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (ISO8601Date)res.getValue().getValue(); + assertEquals(new ISO8601Date(new ISO8601TimeZone(180), 2013, 5, 12), resValue); + + // bad value + arguments.clear(); + arguments.add(attrStringBadValue); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:date-from-string Invalid year", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrStringBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:date-from-string Expected data type 'string' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + @Test + public void testString_from_date() { + FunctionArgumentAttributeValue attrObj1 = null; + FunctionArgumentAttributeValue attrObj2 = null; + FunctionArgumentAttributeValue attrObjDateZone = null; + FunctionArgumentAttributeValue attrStringBadType = null; + try { + attrObj1 = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue("2013-05-12")); + attrObj2 = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue("0001-01-01")); + attrObjDateZone = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue("2013-05-12+03:00")); + attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionStringConversion fd = (FunctionDefinitionStringConversion) StdFunctions.FD_STRING_FROM_DATE; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_FROM_DATE, fd.getId()); + assertEquals(DataTypes.DT_DATE.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + // test normal + arguments.clear(); + arguments.add(attrObj1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals("2013-05-12", res.getValue().getValue()); + + // missing digits in string value? + arguments.clear(); + arguments.add(attrObj2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals("1-01-01", res.getValue().getValue()); + + // include DateZone + arguments.clear(); + arguments.add(attrObjDateZone); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals("2013-05-12+03:00", res.getValue().getValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrStringBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-from-date Expected data type 'date' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + + + + + + /** + * DateTime + */ + @Test + public void testDateTime_from_string() { + FunctionArgumentAttributeValue attrString1 = null; + FunctionArgumentAttributeValue attrString2 = null; + FunctionArgumentAttributeValue attrString3 = null; + FunctionArgumentAttributeValue attrString4 = null; + FunctionArgumentAttributeValue attrString5 = null; + FunctionArgumentAttributeValue attrString6 = null; + FunctionArgumentAttributeValue attrString7 = null; + FunctionArgumentAttributeValue attrString8 = null; + FunctionArgumentAttributeValue attrString9 = null; + FunctionArgumentAttributeValue attrStringDateTimeZone = null; + FunctionArgumentAttributeValue attrStringBadValue = null; + FunctionArgumentAttributeValue attrStringBadType = null; + try { + attrString1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("2013-05-12T12:14:15.323")); + attrString2 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("-2013-05-12T12:14:15.323")); + attrString3 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("1232013-05-12T12:14:15.323")); + attrString4 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("-1232013-05-12T12:14:15.323")); + attrString5 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("213-05-12T12:14:15.323")); + attrString6 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("2013-5-12T12:14:15.323")); + attrString7 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("2013-05-2T12:14:15.323")); + attrString8 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("2013-32-12T12:14:15.323")); + attrString9 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("2013-05-45T12:14:15.323")); + attrStringDateTimeZone = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("2013-05-12T12:14:15.323+03:00")); + attrStringBadValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("not valid obj value")); + attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionStringConversion fd = (FunctionDefinitionStringConversion) StdFunctions.FD_DATETIME_FROM_STRING; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DATETIME_FROM_STRING, fd.getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_DATETIME.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + // test normal + arguments.clear(); + arguments.add(attrString1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + ISO8601DateTime resValue = (ISO8601DateTime)res.getValue().getValue(); + assertEquals(new ISO8601DateTime(null, new ISO8601Date(2013, 5, 12), new ISO8601Time(12, 14, 15, 323)), resValue); + + // check negative + arguments.clear(); + arguments.add(attrString2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + assertEquals(new ISO8601DateTime(null, new ISO8601Date(-2013, 5, 12), new ISO8601Time(12, 14, 15, 323)), resValue); + + + // check big + arguments.clear(); + arguments.add(attrString3); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + assertEquals(new ISO8601DateTime(null, new ISO8601Date(1232013, 5, 12), new ISO8601Time(12, 14, 15, 323)), resValue); + + // check big negative + arguments.clear(); + arguments.add(attrString4); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + assertEquals(new ISO8601DateTime(null, new ISO8601Date(-1232013, 5, 12), new ISO8601Time(12, 14, 15, 323)), resValue); + + // bad year + arguments.clear(); + arguments.add(attrString5); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-from-string Invalid year (must be at least 4 digits)", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad month + arguments.clear(); + arguments.add(attrString6); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-from-string Invalid month", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad day format + arguments.clear(); + arguments.add(attrString7); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-from-string Invalid day", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // month out of range + arguments.clear(); + arguments.add(attrString8); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-from-string Invalid month", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // day out of range + arguments.clear(); + arguments.add(attrString9); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-from-string Invalid day", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // check TimeZone + arguments.clear(); + arguments.add(attrStringDateTimeZone); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (ISO8601DateTime)res.getValue().getValue(); + assertEquals(new ISO8601DateTime(new ISO8601TimeZone(180), new ISO8601Date(new ISO8601TimeZone(180), 2013, 5, 12), new ISO8601Time(new ISO8601TimeZone(180),12, 14, 15, 323)), resValue); + + // bad value + arguments.clear(); + arguments.add(attrStringBadValue); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-from-string Invalid year", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrStringBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dateTime-from-string Expected data type 'string' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + @Test + public void testString_from_dateTime() { + FunctionArgumentAttributeValue attrObj1 = null; + FunctionArgumentAttributeValue attrObj2 = null; + FunctionArgumentAttributeValue attrObjDateTimeZone = null; + FunctionArgumentAttributeValue attrStringBadType = null; + try { + attrObj1 = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue("2013-05-12T12:14:15.323")); + attrObj2 = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue("0001-01-01T12:14:15.323")); + attrObjDateTimeZone = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue("2013-05-12T12:14:15.323+03:00")); + attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionStringConversion fd = (FunctionDefinitionStringConversion) StdFunctions.FD_STRING_FROM_DATETIME; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_FROM_DATETIME, fd.getId()); + assertEquals(DataTypes.DT_DATETIME.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + // test normal + arguments.clear(); + arguments.add(attrObj1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals("2013-05-12T12:14:15.323", res.getValue().getValue()); + + // missing digits in string value? + arguments.clear(); + arguments.add(attrObj2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals("1-01-01T12:14:15.323", res.getValue().getValue()); + + // include DateTimeZone + arguments.clear(); + arguments.add(attrObjDateTimeZone); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals("2013-05-12T12:14:15.323+03:00", res.getValue().getValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrStringBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-from-dateTime Expected data type 'dateTime' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + + + + + /** + * URI + */ + @Test + public void testURI_from_string() { + FunctionArgumentAttributeValue attrString1 = null; + FunctionArgumentAttributeValue attrStringBadValue = null; + FunctionArgumentAttributeValue attrStringBadType = null; + try { + attrString1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("http://someMachine.com/subdir")); + attrStringBadValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("not valid obj value")); + attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionStringConversion fd = (FunctionDefinitionStringConversion) StdFunctions.FD_ANYURI_FROM_STRING; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_ANYURI_FROM_STRING, fd.getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_ANYURI.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + // test normal + arguments.clear(); + arguments.add(attrString1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + URI resValue = (URI)res.getValue().getValue(); + try { + assertEquals(new URI("http://someMachine.com/subdir"), resValue); + } catch (URISyntaxException e) { + fail("uri generation e="+e); + } + + // bad value + arguments.clear(); + arguments.add(attrStringBadValue); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:anyURI-from-string Illegal character in path at index 3: not valid obj value", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrStringBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:anyURI-from-string Expected data type 'string' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + @Test + public void testString_from_anyURI() { + FunctionArgumentAttributeValue attrObj1 = null; + FunctionArgumentAttributeValue attrStringBadType = null; + String objValueString = "http://aMachine.com:8080/aRef"; + try { + attrObj1 = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(objValueString)); + attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionStringConversion fd = (FunctionDefinitionStringConversion) StdFunctions.FD_STRING_FROM_ANYURI; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_FROM_ANYURI, fd.getId()); + assertEquals(DataTypes.DT_ANYURI.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + // test normal + arguments.clear(); + arguments.add(attrObj1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(objValueString, res.getValue().getValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrStringBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-from-anyURI Expected data type 'anyURI' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + + + /** + * XPathDayTimeDuration + */ + @Test + public void testXPathDayTimeDuration_from_string() { + FunctionArgumentAttributeValue attrString1 = null; + FunctionArgumentAttributeValue attrStringNeg1 = null; + FunctionArgumentAttributeValue attrStringNeg2 = null; + FunctionArgumentAttributeValue attrStringNoDay = null; + FunctionArgumentAttributeValue attrStringNoHour = null; + FunctionArgumentAttributeValue attrStringNoMin = null; + FunctionArgumentAttributeValue attrStringNoSec = null; + FunctionArgumentAttributeValue attrStringNoP = null; + FunctionArgumentAttributeValue attrStringSecondsDot = null; + FunctionArgumentAttributeValue attrStringMissingTOk = null; + FunctionArgumentAttributeValue attrStringMissingTBad = null; + FunctionArgumentAttributeValue attrStringBadValue = null; + FunctionArgumentAttributeValue attrStringBadType = null; + try { + attrString1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("P3DT10H30M23S")); + attrStringNeg1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("-P3DT10H30M23S")); + attrStringNeg2 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("P-3DT10H30M23S")); + attrStringNoDay = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("PT10H30M23S")); + attrStringNoHour = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("P3DT30M23S")); + attrStringNoMin = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("P3DT10H23S")); + attrStringNoSec = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("P3DT10H30M")); + attrStringNoP = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("3DT10H30M")); + attrStringSecondsDot = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("P3DT10H30M23.456S")); + attrStringMissingTOk = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("P3D")); + attrStringMissingTBad = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("P3D10H30M23S")); + + attrStringBadValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("not valid obj value")); + attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionStringConversion fd = (FunctionDefinitionStringConversion) StdFunctions.FD_DAYTIMEDURATION_FROM_STRING; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DAYTIMEDURATION_FROM_STRING, fd.getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_DAYTIMEDURATION.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + // test normal + arguments.clear(); + arguments.add(attrString1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + XPathDayTimeDuration resValue = (XPathDayTimeDuration)res.getValue().getValue(); + assertEquals(new XPathDayTimeDuration(1, 3, 10, 30, 23), resValue); + + + // negative values in front is allowed + arguments.clear(); + arguments.add(attrStringNeg1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (XPathDayTimeDuration)res.getValue().getValue(); + assertEquals(new XPathDayTimeDuration(-1, 3, 10, 30, 23), resValue); + + // negative in middle of string not ok + arguments.clear(); + arguments.add(attrStringNeg2); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dayTimeDuration-from-string Invalid chunk \"P-3DT10H30M23S\" at position 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // omit parts that are 0 + arguments.clear(); + arguments.add(attrStringNoDay); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (XPathDayTimeDuration)res.getValue().getValue(); + assertEquals(new XPathDayTimeDuration(1, 0, 10, 30, 23), resValue); + + arguments.clear(); + arguments.add(attrStringNoHour); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (XPathDayTimeDuration)res.getValue().getValue(); + assertEquals(new XPathDayTimeDuration(1, 3, 0, 30, 23), resValue); + + arguments.clear(); + arguments.add(attrStringNoMin); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (XPathDayTimeDuration)res.getValue().getValue(); + assertEquals(new XPathDayTimeDuration(1, 3, 10, 0, 23), resValue); + + arguments.clear(); + arguments.add(attrStringNoSec); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (XPathDayTimeDuration)res.getValue().getValue(); + assertEquals(new XPathDayTimeDuration(1, 3, 10, 30, 0), resValue); + + // P must always be present + arguments.clear(); + arguments.add(attrStringNoP); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dayTimeDuration-from-string Invalid ISO8601 duration string \"3DT10H30M\" at position 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // seconds may contain decimal + arguments.clear(); + arguments.add(attrStringSecondsDot); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (XPathDayTimeDuration)res.getValue().getValue(); + assertEquals(new XPathDayTimeDuration(1, 3, 10, 30, 23.456), resValue); + + // T must be absent iff all time items are absent + arguments.clear(); + arguments.add(attrStringMissingTOk); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (XPathDayTimeDuration)res.getValue().getValue(); + assertEquals(new XPathDayTimeDuration(1, 3, 0, 0, 0), resValue); + + // negative in middle of string not ok + arguments.clear(); + arguments.add(attrStringMissingTBad); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dayTimeDuration-from-string Invalid ISO8601 duration string \"P3D10H30M23S\" at position 6: out of order component", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // bad value + arguments.clear(); + arguments.add(attrStringBadValue); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dayTimeDuration-from-string Invalid ISO8601 duration string \"not valid obj value\" at position 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrStringBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dayTimeDuration-from-string Expected data type 'string' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + @Test + public void testString_from_dayTimeDuration() { + FunctionArgumentAttributeValue attrObj1 = null; + FunctionArgumentAttributeValue attrStringBadType = null; + String objValueString = "P3DT10H30M23S"; + try { + attrObj1 = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(objValueString)); + attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionStringConversion fd = (FunctionDefinitionStringConversion) StdFunctions.FD_STRING_FROM_DAYTIMEDURATION; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_FROM_DAYTIMEDURATION, fd.getId()); + assertEquals(DataTypes.DT_DAYTIMEDURATION.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + // test normal + arguments.clear(); + arguments.add(attrObj1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(objValueString, res.getValue().getValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrStringBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-from-dayTimeDuration Expected data type 'dayTimeDuration' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + + + + + + + + + /** + * XPathYearMonthDuration + */ + @Test + public void testXPathYearMonthDuration_from_string() { + FunctionArgumentAttributeValue attrString1 = null; + FunctionArgumentAttributeValue attrStringNeg1 = null; + FunctionArgumentAttributeValue attrStringNeg2 = null; + FunctionArgumentAttributeValue attrStringNoYear1 = null; + FunctionArgumentAttributeValue attrStringNoYear2 = null; + FunctionArgumentAttributeValue attrStringNoMonth1 = null; + FunctionArgumentAttributeValue attrStringNoMonth2 = null; + FunctionArgumentAttributeValue attrStringNoValue = null; + FunctionArgumentAttributeValue attrStringNoP = null; + FunctionArgumentAttributeValue attrStringBigMonths = null; + FunctionArgumentAttributeValue attrStringMissingTOk = null; + FunctionArgumentAttributeValue attrStringMissingTBad = null; + FunctionArgumentAttributeValue attrStringZeroMonths = null; + FunctionArgumentAttributeValue attrStringBadValue = null; + FunctionArgumentAttributeValue attrStringBadType = null; + try { + attrString1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("P1Y2M")); + attrStringNeg1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("-P1Y2M")); + attrStringNeg2 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("P-1Y2M")); + attrStringNoYear1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("P2M")); + attrStringNoYear2 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("PY2M")); + attrStringNoMonth1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("P1Y")); + attrStringNoMonth2 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("P1YM")); + attrStringNoValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("P")); + attrStringNoP = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("1Y2M")); + attrStringBigMonths = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("P1Y12M")); + attrStringMissingTOk = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("P3D")); + attrStringMissingTBad = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("P3D10H30M23S")); + attrStringZeroMonths = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("P0M")); + + attrStringBadValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("not valid obj value")); + attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionStringConversion fd = (FunctionDefinitionStringConversion) StdFunctions.FD_YEARMONTHDURATION_FROM_STRING; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_YEARMONTHDURATION_FROM_STRING, fd.getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_YEARMONTHDURATION.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + // test normal + arguments.clear(); + arguments.add(attrString1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + XPathYearMonthDuration resValue = (XPathYearMonthDuration)res.getValue().getValue(); + assertEquals(new XPathYearMonthDuration(1,1, 2), resValue); + + + // negative values in front is allowed + arguments.clear(); + arguments.add(attrStringNeg1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (XPathYearMonthDuration)res.getValue().getValue(); + assertEquals(new XPathYearMonthDuration(-1, 1, 2), resValue); + + // negative in middle of string not ok + arguments.clear(); + arguments.add(attrStringNeg2); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:yearMonthDuration-from-string Invalid chunk \"P-1Y2M\" at position 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // omit parts that are 0 + arguments.clear(); + arguments.add(attrStringNoYear1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (XPathYearMonthDuration)res.getValue().getValue(); + assertEquals(new XPathYearMonthDuration(1, 0, 2), resValue); + + arguments.clear(); + arguments.add(attrStringNoYear2); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:yearMonthDuration-from-string Invalid chunk \"PY2M\" at position 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + arguments.clear(); + arguments.add(attrStringNoMonth1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (XPathYearMonthDuration)res.getValue().getValue(); + assertEquals(new XPathYearMonthDuration(1, 1, 0), resValue); + + arguments.clear(); + arguments.add(attrStringNoMonth2); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:yearMonthDuration-from-string Invalid chunk \"P1YM\" at position 3", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // No field with a value + arguments.clear(); + arguments.add(attrStringNoValue); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:yearMonthDuration-from-string Invalid ISO8601 duration string \"P\": No duration components following P", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // P must always be present + arguments.clear(); + arguments.add(attrStringNoP); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:yearMonthDuration-from-string Invalid ISO8601 duration string \"1Y2M\" at position 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // Canonical Form of output may not have more than 12 months, but input as string is ok? + arguments.clear(); + arguments.add(attrStringBigMonths); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (XPathYearMonthDuration)res.getValue().getValue(); + assertEquals(new XPathYearMonthDuration(1, 1, 12), resValue); + + // Canonical representation of 0 Months + arguments.clear(); + arguments.add(attrStringZeroMonths); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (XPathYearMonthDuration)res.getValue().getValue(); + assertEquals(new XPathYearMonthDuration(1, 0, 0), resValue); + + // T must be absent iff all time items are absent + arguments.clear(); + arguments.add(attrStringMissingTOk); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:yearMonthDuration-from-string Invalid XPath yearMonthDuraiton \"{durationSign=1years=0months=0days=3hours=0minutes=0seconds=0millis=0}\": includes days, hours, minutes, or seconds", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // negative in middle of string not ok + arguments.clear(); + arguments.add(attrStringMissingTBad); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:yearMonthDuration-from-string Invalid ISO8601 duration string \"P3D10H30M23S\" at position 6: out of order component", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // bad value + arguments.clear(); + arguments.add(attrStringBadValue); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:yearMonthDuration-from-string Invalid ISO8601 duration string \"not valid obj value\" at position 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrStringBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:yearMonthDuration-from-string Expected data type 'string' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + @Test + public void testString_from_yearMonthDuration() { + FunctionArgumentAttributeValue attrObj1 = null; + FunctionArgumentAttributeValue attrStringBadType = null; + String objValueString = "P1Y2M"; + try { + attrObj1 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(objValueString)); + attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionStringConversion fd = (FunctionDefinitionStringConversion) StdFunctions.FD_STRING_FROM_YEARMONTHDURATION; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_FROM_YEARMONTHDURATION, fd.getId()); + assertEquals(DataTypes.DT_YEARMONTHDURATION.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + // test normal + arguments.clear(); + arguments.add(attrObj1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(objValueString, res.getValue().getValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrStringBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-from-yearMonthDuration Expected data type 'yearMonthDuration' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + + + + + + /** + * X500Principal + * + * See http://www.ietf.org/rfc/rfc2253.txt and http://www.ietf.org/rfc/rfc2251.txt + */ + @Test + public void testX500Principal_from_string() { + FunctionArgumentAttributeValue attrString1 = null; + FunctionArgumentAttributeValue attrStringNoComma = null; + FunctionArgumentAttributeValue attrStringEmpty = null; + FunctionArgumentAttributeValue attrStringNoValue = null; + FunctionArgumentAttributeValue attrStringOrder = null; + FunctionArgumentAttributeValue attrStringDottedDecimalOID = null; + FunctionArgumentAttributeValue attrStringBadValue = null; + FunctionArgumentAttributeValue attrStringBadType = null; + try { + attrString1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("CN=Name, L=local, ST=NJ, O=ATT, C=USA")); + attrStringNoComma = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("CN=Name, L=local ST=NJ, O=ATT, C=USA")); + attrStringEmpty = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("")); + attrStringNoValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("CN=Name, L=, ST=NJ, O=ATT, C=USA")); + attrStringOrder = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("L=local, ST=NJ, O=ATT, CN=Name, C=USA")); + attrStringDottedDecimalOID = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("2.5.4.3=A. N. Other")); + + attrStringBadValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("not valid obj value")); + attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + + FunctionDefinitionStringConversion fd = (FunctionDefinitionStringConversion) StdFunctions.FD_X500NAME_FROM_STRING; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_X500NAME_FROM_STRING, fd.getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_X500NAME.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + // test normal + arguments.clear(); + arguments.add(attrString1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + X500Principal resValue = (X500Principal)res.getValue().getValue(); + assertEquals(new X500Principal("CN=Name, L=local, ST=NJ, O=ATT, C=USA"), resValue); + + // no comma between components => next attribute/value is included as part of first value + arguments.clear(); + arguments.add(attrStringNoComma); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (X500Principal)res.getValue().getValue(); + assertEquals(new X500Principal("CN=Name, L=local ST=NJ, O=ATT, C=USA"), resValue); + + // nothing in name (fail) + arguments.clear(); + arguments.add(attrStringEmpty); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (X500Principal)res.getValue().getValue(); + assertEquals(new X500Principal(""), resValue); + + // type value with no = + arguments.clear(); + arguments.add(attrStringNoValue); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (X500Principal)res.getValue().getValue(); + assertEquals(new X500Principal("CN=Name, L=, ST=NJ, O=ATT, C=USA"), resValue); + + // different order + arguments.clear(); + arguments.add(attrStringOrder); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (X500Principal)res.getValue().getValue(); + assertNotEquals(new X500Principal("CN=Name, L=local, ST=NJ, O=ATT, C=USA"), resValue); + + // dotted-decimal name with numbers + arguments.clear(); + arguments.add(attrStringDottedDecimalOID); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (X500Principal)res.getValue().getValue(); + assertEquals(new X500Principal("2.5.4.3=A. N. Other"), resValue); + + + + // bad value + arguments.clear(); + arguments.add(attrStringBadValue); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:x500Name-from-string improperly specified input name: not valid obj value", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrStringBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:x500Name-from-string Expected data type 'string' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + @Test + public void testString_from_x500Name() { + FunctionArgumentAttributeValue attrObj1 = null; + FunctionArgumentAttributeValue attrStringBadType = null; + String objValueString = "CN=Name, L=local, ST=NJ, O=ATT, C=USA"; + try { + attrObj1 = new FunctionArgumentAttributeValue(DataTypes.DT_X500NAME.createAttributeValue(objValueString)); + attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionStringConversion fd = (FunctionDefinitionStringConversion) StdFunctions.FD_STRING_FROM_X500NAME; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_FROM_X500NAME, fd.getId()); + assertEquals(DataTypes.DT_X500NAME.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + // test normal + arguments.clear(); + arguments.add(attrObj1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(objValueString, res.getValue().getValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrStringBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-from-x500Name Expected data type 'x500Name' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + + + + /** + * RFC822Name + */ + @Test + public void testRFC822Name_from_string() { + FunctionArgumentAttributeValue attrString1 = null; + FunctionArgumentAttributeValue attrStringCapsDomain = null; + FunctionArgumentAttributeValue attrStringCapsLocal = null; + FunctionArgumentAttributeValue attrStringMissingAt = null; + FunctionArgumentAttributeValue attrStringMissingLocal = null; + FunctionArgumentAttributeValue attrStringMissingDomain = null; + FunctionArgumentAttributeValue attrStringEmpty = null; + FunctionArgumentAttributeValue attrStringBadValue = null; + FunctionArgumentAttributeValue attrStringBadType = null; + try { + attrString1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("local@Domain")); + attrStringCapsDomain = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("local@DOMAIN")); + attrStringCapsLocal = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("LOCAL@Domain")); + attrStringMissingAt = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("localDomain")); + attrStringMissingLocal = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("@Domain")); + attrStringMissingDomain = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("local@")); + attrStringEmpty = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("")); + + attrStringBadValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("not valid obj value")); + attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionStringConversion fd = (FunctionDefinitionStringConversion) StdFunctions.FD_RFC822NAME_FROM_STRING; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_RFC822NAME_FROM_STRING, fd.getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_RFC822NAME.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + // test normal + arguments.clear(); + arguments.add(attrString1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + RFC822Name resValue = (RFC822Name)res.getValue().getValue(); + assertEquals(new RFC822Name("local", "domain"), resValue); + + // caps domain + arguments.clear(); + arguments.add(attrStringCapsDomain); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (RFC822Name)res.getValue().getValue(); + assertEquals(new RFC822Name("local", "domain"), resValue); + + // caps local + arguments.clear(); + arguments.add(attrStringCapsLocal); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (RFC822Name)res.getValue().getValue(); + assertNotEquals(new RFC822Name("local", "domain"), resValue); + + // missing at + arguments.clear(); + arguments.add(attrStringMissingAt); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:rfc822Name-from-string Invalid RFC822Name \"localDomain\": missing local part", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // missing local + arguments.clear(); + arguments.add(attrStringMissingLocal); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:rfc822Name-from-string Invalid RFC822Name \"@Domain\": empty parts", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // missing domain + arguments.clear(); + arguments.add(attrStringMissingDomain); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:rfc822Name-from-string Invalid RFC822Name \"local@\": empty parts", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // empty + arguments.clear(); + arguments.add(attrStringEmpty); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:rfc822Name-from-string Invalid RFC822Name \"\": missing local part", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // bad value + arguments.clear(); + arguments.add(attrStringBadValue); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:rfc822Name-from-string Invalid RFC822Name \"not valid obj value\": missing local part", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrStringBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:rfc822Name-from-string Expected data type 'string' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + @Test + public void testString_from_rfc822Name() { + FunctionArgumentAttributeValue attrObj1 = null; + FunctionArgumentAttributeValue attrStringBadType = null; + String objValueString = "local@DOMAIN"; + try { + attrObj1 = new FunctionArgumentAttributeValue(DataTypes.DT_RFC822NAME.createAttributeValue(objValueString)); + attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionStringConversion fd = (FunctionDefinitionStringConversion) StdFunctions.FD_STRING_FROM_RFC822NAME; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_FROM_RFC822NAME, fd.getId()); + assertEquals(DataTypes.DT_RFC822NAME.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + // test normal + arguments.clear(); + arguments.add(attrObj1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals("local@domain", res.getValue().getValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrStringBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-from-rfc822Name Expected data type 'rfc822Name' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + + + + /** + * IPAddress + */ + @Test + public void testIPAddress_from_string() { + FunctionArgumentAttributeValue attrString1 = null; + FunctionArgumentAttributeValue attrStringFull = null; + FunctionArgumentAttributeValue attrStringMissingElement = null; + FunctionArgumentAttributeValue attrStringTooManyElement = null; + FunctionArgumentAttributeValue attrStringIllegalElement = null; + FunctionArgumentAttributeValue attrStringOutOfOrder = null; + + FunctionArgumentAttributeValue attrStringMask = null; + FunctionArgumentAttributeValue attrStringMissingMaskElement = null; + FunctionArgumentAttributeValue attrStringTooManyMaskElement = null; + FunctionArgumentAttributeValue attrStringIllegalMaskElement = null; + FunctionArgumentAttributeValue attrStringMaskNoValue = null; + + FunctionArgumentAttributeValue attrStringMinusPort = null; + FunctionArgumentAttributeValue attrStringPortMinus = null; + FunctionArgumentAttributeValue attrStringPortPort = null; + FunctionArgumentAttributeValue attrStringNoPort = null; + FunctionArgumentAttributeValue attrStringBadPort = null; + FunctionArgumentAttributeValue attrStringTooManyPorts = null; + FunctionArgumentAttributeValue attrStringBadValue = null; + FunctionArgumentAttributeValue attrStringBadType = null; + + // set up for v4 address tests - this setup and the tests are repeated for V6 + short[] addrShorts= {123, 134, 156, 255 }; + short[] addrMaskShorts= {255, 255, 255, 255 }; + try { + attrString1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("10.11.12.123")); + attrStringFull = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("10.11.12.123/10.11.123.255:123-456")); + attrStringMissingElement = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("10.11.255")); + attrStringTooManyElement = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("10.11.12.123.222")); + attrStringIllegalElement = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("10.11.123.255")); + attrStringOutOfOrder = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("10.11.12.123:123-456/10.11.12.255")); + + attrStringMask = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("10.11.12.123/10.11.12.255")); + attrStringMissingMaskElement = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("10.11.12.123/10.11.123")); + attrStringTooManyMaskElement = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("10.11.12.255/10.11.12.123.222")); + attrStringIllegalMaskElement = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("10.11.12.123/10.11.12.255")); + attrStringMaskNoValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("10.11.12.123/")); + // optional mask + // "/" with no mask (fail) + + attrStringMinusPort = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("10.11.12.123:-123")); + attrStringPortMinus = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("10.11.12.123:123-")); + attrStringPortPort = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("10.11.12.123:1234567-432")); + attrStringNoPort = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("10.11.12.123:")); + attrStringBadPort = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("10.11.12.123:12.34")); + attrStringTooManyPorts = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("10.11.12.123:-123-456")); + + + + attrStringBadValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("not valid obj value")); + attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionStringConversion fd = (FunctionDefinitionStringConversion) StdFunctions.FD_IPADDRESS_FROM_STRING; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_IPADDRESS_FROM_STRING, fd.getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_IPADDRESS.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + // test normal + arguments.clear(); + arguments.add(attrString1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + IPAddress resValue = (IPAddress)res.getValue().getValue(); + assertEquals(new IPv4Address(addrShorts, null, null), resValue); + + // fully-loaded address + arguments.clear(); + arguments.add(attrStringFull); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (IPAddress)res.getValue().getValue(); + try { + assertEquals(new IPv4Address(addrShorts, addrMaskShorts, PortRange.newInstance("123-456")), resValue); + } catch (Exception e) { + fail("port error e="+e); + } + + // missing element + arguments.clear(); + arguments.add(attrStringMissingElement); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:ipAddress-from-string Invalid IPv4 address string \"10.11.123\": invalid address", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // too many elements + arguments.clear(); + arguments.add(attrStringTooManyElement); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:ipAddress-from-string Invalid IPv4 address string \"10.11.12.123.222\": invalid address", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // illegal element + arguments.clear(); + arguments.add(attrStringIllegalElement); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:ipAddress-from-string Invalid IPv4 address string \"10.11.12.123\": invalid octet: \"256", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // Out of order + arguments.clear(); + arguments.add(attrStringOutOfOrder); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:ipAddress-from-string Invalid IPv4 address string \"10.11.12.123:123-456/10.11.12.255\": out of order components", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // simple mask + arguments.clear(); + arguments.add(attrStringMask); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (IPAddress)res.getValue().getValue(); + try { + assertEquals(new IPv4Address(addrShorts, addrMaskShorts, null), resValue); + } catch (Exception e) { + fail("port error e="+e); + } + + // missing mask element + arguments.clear(); + arguments.add(attrStringMissingMaskElement); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:ipAddress-from-string Invalid IPv4 address string \"10.11.12.123\": invalid address", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // too many mask elements + arguments.clear(); + arguments.add(attrStringTooManyMaskElement); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:ipAddress-from-string Invalid IPv4 address string \"10.11.12.123.222\": invalid address", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // illegal Mask element + arguments.clear(); + arguments.add(attrStringIllegalMaskElement); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:ipAddress-from-string Invalid IPv4 address string \"10.11.12.123\": invalid octet: \"256", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + //mask indicator without value + arguments.clear(); + arguments.add(attrStringMaskNoValue); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:ipAddress-from-string Invalid IPv4 address string \"\": invalid address", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // portrange (-port, port-, port-port) + arguments.clear(); + arguments.add(attrStringMinusPort); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (IPAddress)res.getValue().getValue(); + try { + assertEquals(new IPv4Address(addrShorts, null, PortRange.newInstance("-123")), resValue); + } catch (ParseException e) { + fail("port error e="+e); + } + + arguments.clear(); + arguments.add(attrStringPortMinus); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (IPAddress)res.getValue().getValue(); + try { + assertEquals(new IPv4Address(addrShorts, null, PortRange.newInstance("123-")), resValue); + } catch (ParseException e) { + fail("port error e="+e); + } + + arguments.clear(); + arguments.add(attrStringPortPort); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (IPAddress)res.getValue().getValue(); + try { + assertEquals(new IPv4Address(addrShorts, null, PortRange.newInstance("1234567-432")), resValue); + } catch (ParseException e) { + fail("port error e="+e); + } + + // ":" without port + arguments.clear(); + arguments.add(attrStringNoPort); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:ipAddress-from-string Invalid IPv4 address string \"10.11.12.123:\": no portrange given after ':'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // bad port number + arguments.clear(); + arguments.add(attrStringBadPort); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:ipAddress-from-string Invalid PortRange \"12.34\": invalid port number", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad port range + arguments.clear(); + arguments.add(attrStringTooManyPorts); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:ipAddress-from-string Invalid PortRange \"-123-456\": too many ranges", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // bad value + arguments.clear(); + arguments.add(attrStringBadValue); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:ipAddress-from-string Unknown IPAddress type for \"not valid obj value\"", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrStringBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:ipAddress-from-string Expected data type 'string' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // + // V6 IP Addresses + // + + // reset the variable for IPv6 tests + FunctionArgumentAttributeValue attrStringAlternateFull = null; + FunctionArgumentAttributeValue attrStringEmptyElement = null; + FunctionArgumentAttributeValue attrString2xEmptyElement = null; + FunctionArgumentAttributeValue attrStringNoStartBracket = null; + FunctionArgumentAttributeValue attrStringNoEndBracket = null; + short[] addrv6Shorts = {(short)0x2001, (short)0xdb8, (short)0x85a3, (short)0x0, (short)0x0, (short)0x8a2e, (short)0x370, (short)0x1}; + Short prefix = new Short((short) 121); + try { + attrString1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3:0:0:8a2e:370:1]")); + attrStringFull = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3:0:0:8a2e:370:1/121]:123-456")); + attrStringAlternateFull = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3:0:0:8a2e:370:1]/121:123-456")); + attrStringEmptyElement = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3::8a2e:370:1]")); + attrString2xEmptyElement = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3::8a2e::1]")); + attrStringNoStartBracket = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("2002:db8:85a3::8a2e::1]")); + attrStringNoEndBracket = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3::8a2e::1")); + + attrStringMissingElement = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3:0:0:8a2e:1]")); + attrStringTooManyElement = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3:0:0:8a2e:370:1:123]")); + attrStringIllegalElement = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:mnop:85a3:0:0:8a2e:370:1]")); + attrStringOutOfOrder = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:mnop:85a3:0:0:8a2e:370:1:123-456/121]")); + + attrStringMask = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3:0:0:8a2e:370:1/21]")); + attrStringIllegalMaskElement = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3:0:0:8a2e:370:1/130]")); + attrStringMaskNoValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3:0:0:8a2e:370:1/]")); + + attrStringMinusPort = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3:0:0:8a2e:370:1]:-123")); + attrStringPortMinus = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3:0:0:8a2e:370:1]:123-")); + attrStringPortPort = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3:0:0:8a2e:370:1]:1234567-432")); + attrStringNoPort = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3:0:0:8a2e:370:1]:")); + attrStringBadPort = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3:0:0:8a2e:370:1]:12.34")); + attrStringTooManyPorts = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3:0:0:8a2e:370:1]:-123-456")); + + attrStringBadValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("not valid obj value")); + attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + + // test normal + arguments.clear(); + arguments.add(attrString1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (IPAddress)res.getValue().getValue(); + assertEquals(new IPv6Address(addrv6Shorts, null, null), resValue); + + // fully-loaded address - "prefix" is inside the brackets (not clear if this is correct) + arguments.clear(); + arguments.add(attrStringFull); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (IPAddress)res.getValue().getValue(); + try { + assertEquals(new IPv6Address(addrv6Shorts, new Short(prefix), PortRange.newInstance("123-456")), resValue); + } catch (Exception e) { + fail("port error e="+e); + } + + // Alternate way of identifying "prefix" - outside the brackets + arguments.clear(); + arguments.add(attrStringAlternateFull); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (IPAddress)res.getValue().getValue(); + try { + assertEquals(new IPv6Address(addrv6Shorts, prefix, PortRange.newInstance("123-456")), resValue); + } catch (Exception e) { + fail("port error e="+e); + } + + + // consecutive zero elements removed + arguments.clear(); + arguments.add(attrStringEmptyElement); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (IPAddress)res.getValue().getValue(); + try { + assertEquals(new IPv6Address(addrv6Shorts, prefix, null), resValue); + } catch (Exception e) { + fail("port error e="+e); + } + + // consecutive zero elements removed in two locations (no-no) + arguments.clear(); + arguments.add(attrString2xEmptyElement); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:ipAddress-from-string Invalid IPv6Address string \"2001:db8:85a3::8a2e::1\": multiple zero runs", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // address must have [] on it + arguments.clear(); + arguments.add(attrStringNoStartBracket); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:ipAddress-from-string Invalid IPv6Address string \"2002:db8:85a3::8a2e::1]\": missing opening bracket", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + arguments.add(attrStringNoEndBracket); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:ipAddress-from-string Invalid IPv6Address string \"[2001:db8:85a3::8a2e::1\": missing closing bracket", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // missing element + arguments.clear(); + arguments.add(attrStringMissingElement); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:ipAddress-from-string Invalid IPv6Address string \"2001:db8:85a3:0:0:8a2e:1\": not enough address fields", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // too many elements + arguments.clear(); + arguments.add(attrStringTooManyElement); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:ipAddress-from-string Invalid IPv6Address string \"2001:db8:85a3:0:0:8a2e:370:1:123\"", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // illegal element + arguments.clear(); + arguments.add(attrStringIllegalElement); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:ipAddress-from-string Invalid IPv6Address component \"mnop\": invalid hex", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // Out of order + arguments.clear(); + arguments.add(attrStringOutOfOrder); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:ipAddress-from-string Invalid IPv6Address string \"2001:mnop:85a3:0:0:8a2e:370:1:123-456\"", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // simple mask + arguments.clear(); + arguments.add(attrStringMask); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (IPAddress)res.getValue().getValue(); + try { + assertEquals(new IPv6Address(addrv6Shorts, prefix, null), resValue); + } catch (Exception e) { + fail("port error e="+e); + } + + // illegal Mask element + arguments.clear(); + arguments.add(attrStringIllegalMaskElement); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:ipAddress-from-string Invalid Ipv6Address string \"[2001:db8:85a3:0:0:8a2e:370:1/130]\": prefix is larger than 128", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + //mask indicator without value + arguments.clear(); + arguments.add(attrStringMaskNoValue); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:ipAddress-from-string Invalid Ipv6Address string \"[2001:db8:85a3:0:0:8a2e:370:1/]\": prefix designation without value", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // portrange (-port, port-, port-port) + arguments.clear(); + arguments.add(attrStringMinusPort); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (IPAddress)res.getValue().getValue(); + try { + assertEquals(new IPv6Address(addrv6Shorts, null, PortRange.newInstance("-123")), resValue); + } catch (ParseException e) { + fail("port error e="+e); + } + + arguments.clear(); + arguments.add(attrStringPortMinus); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (IPAddress)res.getValue().getValue(); + try { + assertEquals(new IPv6Address(addrv6Shorts, null, PortRange.newInstance("123-")), resValue); + } catch (ParseException e) { + fail("port error e="+e); + } + + arguments.clear(); + arguments.add(attrStringPortPort); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (IPAddress)res.getValue().getValue(); + try { + assertEquals(new IPv6Address(addrv6Shorts, null, PortRange.newInstance("1234567-432")), resValue); + } catch (ParseException e) { + fail("port error e="+e); + } + + // ":" without port + arguments.clear(); + arguments.add(attrStringNoPort); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:ipAddress-from-string Invalid IPv6 address string \"[2001:db8:85a3:0:0:8a2e:370:1]:\": no portrange given after ':'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // bad port number + arguments.clear(); + arguments.add(attrStringBadPort); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:ipAddress-from-string Invalid PortRange \"12.34\": invalid port number", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad port range + arguments.clear(); + arguments.add(attrStringTooManyPorts); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:ipAddress-from-string Invalid PortRange \"-123-456\": too many ranges", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + + + + } + + @Test + public void testString_from_ipAddress() { + FunctionArgumentAttributeValue attrObj1 = null; + FunctionArgumentAttributeValue attrObjV6 = null; + FunctionArgumentAttributeValue attrStringBadType = null; + String objValueString = "10.11.12.123"; + String objValueStringV6 = "[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]"; + try { + attrObj1 = new FunctionArgumentAttributeValue(DataTypes.DT_IPADDRESS.createAttributeValue(objValueString)); + attrObjV6 = new FunctionArgumentAttributeValue(DataTypes.DT_IPADDRESS.createAttributeValue(objValueStringV6)); + + attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionStringConversion fd = (FunctionDefinitionStringConversion) StdFunctions.FD_STRING_FROM_IPADDRESS; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_FROM_IPADDRESS, fd.getId()); + assertEquals(DataTypes.DT_IPADDRESS.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + // test normal V4 + arguments.clear(); + arguments.add(attrObj1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(objValueString, res.getValue().getValue()); + + // test normal V6 + arguments.clear(); + arguments.add(attrObjV6); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(objValueStringV6.toLowerCase(), res.getValue().getValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrStringBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-from-ipAddress Expected data type 'ipAddress' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + + + + + + + + + + /** + * RFC2396DomainName + */ + @Test + public void testRFC2396DomainName_from_string() { + FunctionArgumentAttributeValue attrString1 = null; + FunctionArgumentAttributeValue attrString2 = null; + FunctionArgumentAttributeValue attrStringMinusPort = null; + FunctionArgumentAttributeValue attrStringPortMinus = null; + FunctionArgumentAttributeValue attrStringPortPort = null; + FunctionArgumentAttributeValue attrStringNoPort = null; + FunctionArgumentAttributeValue attrStringBadPort = null; + FunctionArgumentAttributeValue attrStringTooManyPorts = null; + + FunctionArgumentAttributeValue attrStringBadValue = null; + FunctionArgumentAttributeValue attrStringBadType = null; + try { + attrString1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("host")); + attrString2 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("host.host")); + + attrStringMinusPort = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("host.host:-123")); + attrStringPortMinus = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("host.host:123-")); + attrStringPortPort = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("host.host:1234567-432")); + attrStringNoPort = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("host.host:")); + attrStringBadPort = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("host.host:12.34")); + attrStringTooManyPorts = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("host.host:-123-456")); + + attrStringBadValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("not valid obj value")); + attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionStringConversion fd = (FunctionDefinitionStringConversion) StdFunctions.FD_DNSNAME_FROM_STRING; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_DNSNAME_FROM_STRING, fd.getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_DNSNAME.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + // test normal + arguments.clear(); + arguments.add(attrString1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + RFC2396DomainName resValue = (RFC2396DomainName)res.getValue().getValue(); + assertEquals(new RFC2396DomainName("host", null), resValue); + + arguments.clear(); + arguments.add(attrString2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (RFC2396DomainName)res.getValue().getValue(); + assertEquals(new RFC2396DomainName("host.host", null), resValue); + + + // portrange (-port, port-, port-port) + arguments.clear(); + arguments.add(attrStringMinusPort); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (RFC2396DomainName)res.getValue().getValue(); + try { + assertEquals(new RFC2396DomainName("host.host", PortRange.newInstance("-123")), resValue); + } catch (ParseException e) { + fail("port error e="+e); + } + + arguments.clear(); + arguments.add(attrStringPortMinus); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (RFC2396DomainName)res.getValue().getValue(); + try { + assertEquals(new RFC2396DomainName("host.host", PortRange.newInstance("123-")), resValue); + } catch (ParseException e) { + fail("port error e="+e); + } + + arguments.clear(); + arguments.add(attrStringPortPort); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (RFC2396DomainName)res.getValue().getValue(); + try { + assertEquals(new RFC2396DomainName("host.host", PortRange.newInstance("1234567-432")), resValue); + } catch (ParseException e) { + fail("port error e="+e); + } + + // ":" without port + arguments.clear(); + arguments.add(attrStringNoPort); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dnsName-from-string Invalid RFC 2396 port range \"host.host:\": no port numbers", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad port number + arguments.clear(); + arguments.add(attrStringBadPort); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dnsName-from-string Invalid RFC 2396 port range \"12.34\"", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad port range + arguments.clear(); + arguments.add(attrStringTooManyPorts); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dnsName-from-string Invalid RFC 2396 port range \"-123-456\"", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad value + arguments.clear(); + arguments.add(attrStringBadValue); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dnsName-from-string Invalid RFC 2396 host name \"not valid obj value\"", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrStringBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:dnsName-from-string Expected data type 'string' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + @Test + public void testString_from_dnsName() { + FunctionArgumentAttributeValue attrObj1 = null; + FunctionArgumentAttributeValue attrStringBadType = null; + String objValueString = "someName.com"; + try { + attrObj1 = new FunctionArgumentAttributeValue(DataTypes.DT_DNSNAME.createAttributeValue(objValueString)); + attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); + + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionStringConversion fd = (FunctionDefinitionStringConversion) StdFunctions.FD_STRING_FROM_DNSNAME; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_FROM_DNSNAME, fd.getId()); + assertEquals(DataTypes.DT_DNSNAME.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + // test normal + arguments.clear(); + arguments.add(attrObj1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(objValueString, res.getValue().getValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrStringBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-from-dnsName Expected data type 'dnsName' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + } + + + + + + + +} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionStringEqualIgnoreCaseTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionStringEqualIgnoreCaseTest.java new file mode 100644 index 000000000..b01c49cc6 --- /dev/null +++ b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionStringEqualIgnoreCaseTest.java @@ -0,0 +1,129 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-TEST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.std.functions; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +import com.att.research.xacml.api.XACML3; +import com.att.research.xacml.std.datatypes.DataTypes; +import com.att.research.xacmlatt.pdp.policy.ExpressionResult; +import com.att.research.xacmlatt.pdp.policy.FunctionArgument; +import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; +import com.att.research.xacmlatt.pdp.std.StdFunctions; +import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionEquality; + +/** + * Only one function to test here. Code copy/pasted from FunctionDefinitionEqualityTest + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * In the first implementation of XACML we had separate files for each XACML Function. + * This release combines multiple Functions in fewer files to minimize code duplication. + * This file supports the following XACML codes: + * string-equal-ignore-case + * + * + */ +public class FunctionDefinitionStringEqualIgnoreCaseTest { + + /* + * variables useful in the following tests + */ + List arguments = new ArrayList(); + + FunctionArgumentAttributeValue stringAttr1 = null; + FunctionArgumentAttributeValue stringAttr2 = null; + FunctionArgumentAttributeValue stringAttr3 = null; + FunctionArgumentAttributeValue stringAttr4 = null; + + FunctionArgumentAttributeValue intAttr1 = null; + + public FunctionDefinitionStringEqualIgnoreCaseTest() { + try { + stringAttr1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("abc")); + stringAttr2 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("abc")); + stringAttr3 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("ABC")); + stringAttr4 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("def")); + intAttr1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1)); + } catch (Exception e) { + fail("creating attribute e="+ e); + } + } + + + /** + * String match even when Case is different + */ + @Test + public void testFunctionDefinitionStringEqualIgnoreCase() { + + FunctionDefinitionEquality fd = (FunctionDefinitionEquality) StdFunctions.FD_STRING_EQUAL_IGNORE_CASE; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_EQUAL_IGNORE_CASE, fd.getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + + + // test normal equals and non-equals + // check "abc" with "abc" + arguments.add(stringAttr1); + arguments.add(stringAttr2); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // check "abc" with "ABC" (should be same) + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(stringAttr3); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // test bad args data types? Not needed? + arguments.clear(); + arguments.add(stringAttr1); + arguments.add(intAttr1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + + +//TODO - null in either first or 2nd arg => NullPointerException + } + +} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionStringFunctionsTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionStringFunctionsTest.java new file mode 100644 index 000000000..736293580 --- /dev/null +++ b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionStringFunctionsTest.java @@ -0,0 +1,1497 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-TEST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.std.functions; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.net.URI; +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +import com.att.research.xacml.api.XACML3; +import com.att.research.xacml.std.datatypes.DataTypes; +import com.att.research.xacmlatt.pdp.policy.ExpressionResult; +import com.att.research.xacmlatt.pdp.policy.FunctionArgument; +import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; +import com.att.research.xacmlatt.pdp.std.StdFunctions; +import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionStringFunctions; + +/** + * Test of PDP Functions (See XACML core spec section A.3) + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * + */ +public class FunctionDefinitionStringFunctionsTest { + + + /* + * variables useful in the following tests + */ + List arguments = new ArrayList(); + + ExpressionResult res; + + + @Test + public void testConcatenate() { + String v1 = new String("abc"); + String v2 = new String("def"); + + FunctionArgumentAttributeValue attrV1 = null; + FunctionArgumentAttributeValue attrV2 = null; + FunctionArgumentAttributeValue attrNull = null; + FunctionArgumentAttributeValue attrBlank = null; + FunctionArgumentAttributeValue attrInteger = null; + try { + attrV1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(v1)); + attrV2 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(v2)); + attrBlank = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("")); + attrNull = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(null)); + attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234)); + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + FunctionDefinitionStringFunctions fd = (FunctionDefinitionStringFunctions) StdFunctions.FD_STRING_CONCATENATE; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_CONCATENATE, fd.getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + + // match + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrV2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.String.class, res.getValue().getValue().getClass()); + String resValue = (String)res.getValue().getValue(); + assertEquals(v1 + v2, resValue); + + // empty non-null first arg + arguments.clear(); + arguments.add(attrBlank); + arguments.add(attrV2); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.String.class, res.getValue().getValue().getClass()); + resValue = (String)res.getValue().getValue(); + assertEquals(v2, resValue); + + // empty non-null second arg + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.String.class, res.getValue().getValue().getClass()); + resValue = (String)res.getValue().getValue(); + assertEquals(v1, resValue); + + // two blanks + arguments.clear(); + arguments.add(attrBlank); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.String.class, res.getValue().getValue().getClass()); + resValue = (String)res.getValue().getValue(); + assertEquals("", resValue); + + // null firat arg + arguments.clear(); + arguments.add(attrNull); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-concatenate Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // null second arg + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrNull); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-concatenate Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrInteger); + arguments.add(attrV2); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-concatenate Expected data type 'string' saw 'integer'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null second arg + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrNull); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-concatenate Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + + @Test + public void testStringStartsWith() { + String v1 = new String("abc"); + String bigger = new String("abc some string"); + String biggerNoMatch = new String(" abc some string"); + String caps = new String("AbC"); + + FunctionArgumentAttributeValue attrV1 = null; + FunctionArgumentAttributeValue attrBigger = null; + FunctionArgumentAttributeValue attrBiggerNoMatch = null; + FunctionArgumentAttributeValue attrCaps = null; + FunctionArgumentAttributeValue attrNull = null; + FunctionArgumentAttributeValue attrBlank = null; + FunctionArgumentAttributeValue attrInteger = null; + try { + attrV1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(v1)); + attrBigger = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(bigger)); + attrBiggerNoMatch = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(biggerNoMatch)); + attrCaps = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(caps)); + attrBlank = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("")); + attrNull = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(null)); + attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234)); + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + FunctionDefinitionStringFunctions fd = (FunctionDefinitionStringFunctions) StdFunctions.FD_STRING_STARTS_WITH; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_STARTS_WITH, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + + // match + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrBigger); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertEquals(true, resValue); + + // no match + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrBiggerNoMatch); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // caps no match + arguments.clear(); + arguments.add(attrCaps); + arguments.add(attrBigger); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // bigger on the inside + arguments.clear(); + arguments.add(attrBigger); + arguments.add(attrV1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // empty non-null first arg + arguments.clear(); + arguments.add(attrBlank); + arguments.add(attrBigger); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(true, resValue); + + // empty non-null second arg + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // two blanks + arguments.clear(); + arguments.add(attrBlank); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(true, resValue); + + // null firat arg + arguments.clear(); + arguments.add(attrNull); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-starts-with Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null second arg + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrNull); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-starts-with Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // illegal arg type + arguments.clear(); + arguments.add(attrInteger); + arguments.add(attrBigger); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-starts-with Expected data type 'string' saw 'integer'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + @Test + public void testAnyuriStartsWith() { + + + FunctionArgumentAttributeValue attrV1 = null; + FunctionArgumentAttributeValue attrBigger = null; + FunctionArgumentAttributeValue attrBiggerNoMatch = null; + FunctionArgumentAttributeValue attrCaps = null; + FunctionArgumentAttributeValue attrBigString = null; + FunctionArgumentAttributeValue attrNull = null; + FunctionArgumentAttributeValue attrBlankString = null; + FunctionArgumentAttributeValue attrBlankURI = null; + FunctionArgumentAttributeValue attrInteger = null; + try { + String v1 = new String("abc"); + URI bigger = new URI("abc.some.string"); + URI biggerNoMatch = new URI("Zabc.some.string"); + String caps = new String("AbC"); + String bigString = "thisIsSomeReallyBigStringToMatch"; + + attrV1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(v1)); + attrBigger = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(bigger)); + attrBiggerNoMatch = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(biggerNoMatch)); + attrCaps = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(caps)); + attrBigString = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(bigString)); + attrBlankString = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("")); + attrBlankURI = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue("")); + attrNull = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(null)); + attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234)); + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + FunctionDefinitionStringFunctions fd = (FunctionDefinitionStringFunctions) StdFunctions.FD_ANYURI_STARTS_WITH; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_ANYURI_STARTS_WITH, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + + // match + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrBigger); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertEquals(true, resValue); + + // no match + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrBiggerNoMatch); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // caps no match + arguments.clear(); + arguments.add(attrCaps); + arguments.add(attrBigger); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // bigger on the inside + arguments.clear(); + arguments.add(attrBigString); + arguments.add(attrBigger); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // empty non-null first arg + arguments.clear(); + arguments.add(attrBlankString); + arguments.add(attrBigger); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(true, resValue); + + // empty non-null second arg + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrBlankURI); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + + // two blanks + arguments.clear(); + arguments.add(attrBlankString); + arguments.add(attrBlankURI); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(true, resValue); + + // arguments reversed + arguments.clear(); + arguments.add(attrBigger); + arguments.add(attrV1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:anyURI-starts-with Expected data type 'string' saw 'anyURI'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // null firat arg + arguments.clear(); + arguments.add(attrNull); + arguments.add(attrBlankURI); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:anyURI-starts-with Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null second arg + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrNull); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:anyURI-starts-with Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // illegal arg type + arguments.clear(); + arguments.add(attrInteger); + arguments.add(attrBigger); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:anyURI-starts-with Expected data type 'string' saw 'integer'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + + + @Test + public void testStringEndsWith() { + String v1 = new String("abc"); + String bigger = new String("abc some string abc"); + String biggerNoMatch = new String(" abc some string abc "); + String caps = new String("AbC"); + + FunctionArgumentAttributeValue attrV1 = null; + FunctionArgumentAttributeValue attrBigger = null; + FunctionArgumentAttributeValue attrBiggerNoMatch = null; + FunctionArgumentAttributeValue attrCaps = null; + FunctionArgumentAttributeValue attrNull = null; + FunctionArgumentAttributeValue attrBlank = null; + FunctionArgumentAttributeValue attrInteger = null; + try { + attrV1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(v1)); + attrBigger = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(bigger)); + attrBiggerNoMatch = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(biggerNoMatch)); + attrCaps = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(caps)); + attrBlank = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("")); + attrNull = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(null)); + attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234)); + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + FunctionDefinitionStringFunctions fd = (FunctionDefinitionStringFunctions) StdFunctions.FD_STRING_ENDS_WITH; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_ENDS_WITH, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + + // match + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrBigger); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertEquals(true, resValue); + + // no match + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrBiggerNoMatch); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // caps no match + arguments.clear(); + arguments.add(attrCaps); + arguments.add(attrBigger); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // bigger on the inside + arguments.clear(); + arguments.add(attrBigger); + arguments.add(attrV1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // empty non-null first arg + arguments.clear(); + arguments.add(attrBlank); + arguments.add(attrBigger); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(true, resValue); + + // empty non-null second arg + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // two blanks + arguments.clear(); + arguments.add(attrBlank); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(true, resValue); + + // null firat arg + arguments.clear(); + arguments.add(attrNull); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-ends-with Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null second arg + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrNull); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-ends-with Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // illegal arg type + arguments.clear(); + arguments.add(attrInteger); + arguments.add(attrBigger); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-ends-with Expected data type 'string' saw 'integer'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + @Test + public void testAnyuriEndsWith() { + + + FunctionArgumentAttributeValue attrV1 = null; + FunctionArgumentAttributeValue attrBigger = null; + FunctionArgumentAttributeValue attrBiggerNoMatch = null; + FunctionArgumentAttributeValue attrCaps = null; + FunctionArgumentAttributeValue attrBigString = null; + FunctionArgumentAttributeValue attrNull = null; + FunctionArgumentAttributeValue attrBlankString = null; + FunctionArgumentAttributeValue attrBlankURI = null; + FunctionArgumentAttributeValue attrInteger = null; + try { + String v1 = new String("abc"); + URI bigger = new URI("abc.some.stringabc"); + URI biggerNoMatch = new URI("Zabc.some.stringabcZ"); + String caps = new String("AbC"); + String bigString = "thisIsSomeReallyBigStringToMatch"; + + attrV1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(v1)); + attrBigger = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(bigger)); + attrBiggerNoMatch = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(biggerNoMatch)); + attrCaps = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(caps)); + attrBigString = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(bigString)); + attrBlankString = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("")); + attrBlankURI = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue("")); + attrNull = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(null)); + attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234)); + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + FunctionDefinitionStringFunctions fd = (FunctionDefinitionStringFunctions) StdFunctions.FD_ANYURI_ENDS_WITH; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_ANYURI_ENDS_WITH, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + + // match + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrBigger); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertEquals(true, resValue); + + // no match + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrBiggerNoMatch); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // caps no match + arguments.clear(); + arguments.add(attrCaps); + arguments.add(attrBigger); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // bigger on the inside + arguments.clear(); + arguments.add(attrBigString); + arguments.add(attrBigger); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // empty non-null first arg + arguments.clear(); + arguments.add(attrBlankString); + arguments.add(attrBigger); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(true, resValue); + + // empty non-null second arg + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrBlankURI); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + + // two blanks + arguments.clear(); + arguments.add(attrBlankString); + arguments.add(attrBlankURI); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(true, resValue); + + // arguments reversed + arguments.clear(); + arguments.add(attrBigger); + arguments.add(attrV1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:anyURI-ends-with Expected data type 'string' saw 'anyURI'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // null firat arg + arguments.clear(); + arguments.add(attrNull); + arguments.add(attrBlankURI); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:anyURI-ends-with Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null second arg + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrNull); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:anyURI-ends-with Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // illegal arg type + arguments.clear(); + arguments.add(attrInteger); + arguments.add(attrBigger); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:anyURI-ends-with Expected data type 'string' saw 'integer'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + + + @Test + public void testStringSubstring() { + String bigString = new String("abc some string abc"); + + FunctionArgumentAttributeValue attrBigString = null; + FunctionArgumentAttributeValue attrNull = null; + FunctionArgumentAttributeValue attrBlank = null; + FunctionArgumentAttributeValue attrDouble = null; + + FunctionArgumentAttributeValue attrInteger0 = null; + FunctionArgumentAttributeValue attrInteger1 = null; + FunctionArgumentAttributeValue attrIntegerM1 = null; + FunctionArgumentAttributeValue attrInteger8 = null; + FunctionArgumentAttributeValue attrInteger19 = null; + FunctionArgumentAttributeValue attrInteger20 = null; + + + + try { + attrBigString = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(bigString)); + attrBlank = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("")); + attrNull = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(null)); + attrInteger0 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(0)); + attrInteger1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1)); + attrIntegerM1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(-1)); + attrInteger8 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(8)); + attrInteger19 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(19)); + attrInteger20 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(20)); + attrDouble = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(123.4)); + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + FunctionDefinitionStringFunctions fd = (FunctionDefinitionStringFunctions) StdFunctions.FD_STRING_SUBSTRING; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_SUBSTRING, fd.getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + + // match + arguments.clear(); + arguments.add(attrBigString); + arguments.add(attrInteger1); + arguments.add(attrInteger8); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.String.class, res.getValue().getValue().getClass()); + String resValue = (String)res.getValue().getValue(); + assertEquals("bc some", resValue); + + // edge: start + arguments.clear(); + arguments.add(attrBigString); + arguments.add(attrInteger0); + arguments.add(attrInteger8); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.String.class, res.getValue().getValue().getClass()); + resValue = (String)res.getValue().getValue(); + assertEquals("abc some", resValue); + + // edge: end + arguments.clear(); + arguments.add(attrBigString); + arguments.add(attrInteger8); + arguments.add(attrInteger19); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.String.class, res.getValue().getValue().getClass()); + resValue = (String)res.getValue().getValue(); + assertEquals(" string abc", resValue); + + // from index to end of string + arguments.clear(); + arguments.add(attrBigString); + arguments.add(attrInteger8); + arguments.add(attrIntegerM1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.String.class, res.getValue().getValue().getClass()); + resValue = (String)res.getValue().getValue(); + assertEquals(" string abc", resValue); + + // first index too low + arguments.clear(); + arguments.add(attrBigString); + arguments.add(attrIntegerM1); + arguments.add(attrInteger8); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-substring Start point '-1' out of range 0-19 for string='abc some string abc'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // second index too big + arguments.clear(); + arguments.add(attrBigString); + arguments.add(attrInteger8); + arguments.add(attrInteger20); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-substring End point '20' out of range 0-19 for string='abc some string abc'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // indexes reversed + arguments.clear(); + arguments.add(attrBigString); + arguments.add(attrInteger8); + arguments.add(attrInteger1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-substring End point '1' less than start point 'null' for string='abc some string abc'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // indexes the same + arguments.clear(); + arguments.add(attrBigString); + arguments.add(attrInteger8); + arguments.add(attrInteger8); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.String.class, res.getValue().getValue().getClass()); + resValue = (String)res.getValue().getValue(); + assertEquals("", resValue); + + // blank string with indexes both 0 + arguments.clear(); + arguments.add(attrBlank); + arguments.add(attrInteger0); + arguments.add(attrInteger0); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.String.class, res.getValue().getValue().getClass()); + resValue = (String)res.getValue().getValue(); + assertEquals("", resValue); + + // non-string first attribute + arguments.clear(); + arguments.add(attrDouble); + arguments.add(attrInteger8); + arguments.add(attrInteger1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-substring Expected data type 'string' saw 'double'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // non-integer 2nd attr + arguments.clear(); + arguments.add(attrBigString); + arguments.add(attrDouble); + arguments.add(attrInteger1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-substring Expected data type 'integer' saw 'double'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // non-integer 3rd attr + arguments.clear(); + arguments.add(attrBigString); + arguments.add(attrInteger8); + arguments.add(attrDouble); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-substring Expected data type 'integer' saw 'double'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // 4 args + arguments.clear(); + arguments.add(attrBigString); + arguments.add(attrInteger8); + arguments.add(attrInteger1); + arguments.add(attrInteger1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-substring Expected 3 arguments, got 4", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // 2 args + arguments.clear(); + arguments.add(attrBigString); + arguments.add(attrInteger8); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-substring Expected 3 arguments, got 2", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null 1st arg + arguments.clear(); + arguments.add(attrNull); + arguments.add(attrInteger8); + arguments.add(attrInteger1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-substring Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // null 2nd arg + arguments.clear(); + arguments.add(attrBigString); + arguments.add(attrNull); + arguments.add(attrInteger1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-substring Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + } + + + + + @Test + public void testAnyURISubstring() { + String bigString = new String("http://company.com:8080/this/is/some/long/uri"); + + FunctionArgumentAttributeValue attrURI = null; + FunctionArgumentAttributeValue attrNull = null; + FunctionArgumentAttributeValue attrBlank = null; + FunctionArgumentAttributeValue attrDouble = null; + + FunctionArgumentAttributeValue attrInteger0 = null; + FunctionArgumentAttributeValue attrInteger1 = null; + FunctionArgumentAttributeValue attrIntegerM1 = null; + FunctionArgumentAttributeValue attrInteger8 = null; + FunctionArgumentAttributeValue attrInteger45 = null; + FunctionArgumentAttributeValue attrInteger46 = null; + + + + try { + attrURI = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(bigString)); + attrBlank = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue("")); + attrNull = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(null)); + attrInteger0 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(0)); + attrInteger1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1)); + attrIntegerM1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(-1)); + attrInteger8 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(8)); + attrInteger45 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(45)); + attrInteger46 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(46)); + attrDouble = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(123.4)); + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + FunctionDefinitionStringFunctions fd = (FunctionDefinitionStringFunctions) StdFunctions.FD_ANYURI_SUBSTRING; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_ANYURI_SUBSTRING, fd.getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + + // match + arguments.clear(); + arguments.add(attrURI); + arguments.add(attrInteger1); + arguments.add(attrInteger8); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.String.class, res.getValue().getValue().getClass()); + String resValue = (String)res.getValue().getValue(); + assertEquals("ttp://c", resValue); + + // edge: start + arguments.clear(); + arguments.add(attrURI); + arguments.add(attrInteger0); + arguments.add(attrInteger8); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.String.class, res.getValue().getValue().getClass()); + resValue = (String)res.getValue().getValue(); + assertEquals("http://c", resValue); + + // edge: end + arguments.clear(); + arguments.add(attrURI); + arguments.add(attrInteger8); + arguments.add(attrInteger45); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.String.class, res.getValue().getValue().getClass()); + resValue = (String)res.getValue().getValue(); + assertEquals("ompany.com:8080/this/is/some/long/uri", resValue); + + // from index to end of string + arguments.clear(); + arguments.add(attrURI); + arguments.add(attrInteger8); + arguments.add(attrIntegerM1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.String.class, res.getValue().getValue().getClass()); + resValue = (String)res.getValue().getValue(); + assertEquals("ompany.com:8080/this/is/some/long/uri", resValue); + + // first index too low + arguments.clear(); + arguments.add(attrURI); + arguments.add(attrIntegerM1); + arguments.add(attrInteger8); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:anyURI-substring Start point '-1' out of range 0-45 for string='http://company.com:8080/this/is/some/long/uri'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // second index too big + arguments.clear(); + arguments.add(attrURI); + arguments.add(attrInteger8); + arguments.add(attrInteger46); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:anyURI-substring End point '46' out of range 0-45 for string='http://company.com:8080/this/is/some/long/uri'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // indexes reversed + arguments.clear(); + arguments.add(attrURI); + arguments.add(attrInteger8); + arguments.add(attrInteger1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:anyURI-substring End point '1' less than start point 'null' for string='http://company.com:8080/this/is/some/long/uri'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // indexes the same + arguments.clear(); + arguments.add(attrURI); + arguments.add(attrInteger8); + arguments.add(attrInteger8); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.String.class, res.getValue().getValue().getClass()); + resValue = (String)res.getValue().getValue(); + assertEquals("", resValue); + + // blank string with indexes both 0 + arguments.clear(); + arguments.add(attrBlank); + arguments.add(attrInteger0); + arguments.add(attrInteger0); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.String.class, res.getValue().getValue().getClass()); + resValue = (String)res.getValue().getValue(); + assertEquals("", resValue); + + // non-string first attribute + arguments.clear(); + arguments.add(attrDouble); + arguments.add(attrInteger8); + arguments.add(attrInteger1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:anyURI-substring Expected data type 'anyURI' saw 'double'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // non-integer 2nd attr + arguments.clear(); + arguments.add(attrURI); + arguments.add(attrDouble); + arguments.add(attrInteger1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:anyURI-substring Expected data type 'integer' saw 'double'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // non-integer 3rd attr + arguments.clear(); + arguments.add(attrURI); + arguments.add(attrInteger8); + arguments.add(attrDouble); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:anyURI-substring Expected data type 'integer' saw 'double'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // 4 args + arguments.clear(); + arguments.add(attrURI); + arguments.add(attrInteger8); + arguments.add(attrInteger1); + arguments.add(attrInteger1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:anyURI-substring Expected 3 arguments, got 4", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // 2 args + arguments.clear(); + arguments.add(attrURI); + arguments.add(attrInteger8); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:anyURI-substring Expected 3 arguments, got 2", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null 1st arg + arguments.clear(); + arguments.add(attrNull); + arguments.add(attrInteger8); + arguments.add(attrInteger1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:anyURI-substring Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // null 2nd arg + arguments.clear(); + arguments.add(attrURI); + arguments.add(attrNull); + arguments.add(attrInteger1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:anyURI-substring Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + + + + + + + + + + + + + + + + + + + + @Test + public void testStringContains() { + String v1 = new String("abc"); + String bigger = new String("abc some string abc"); + String biggerNoMatch = new String(" abc some string abc "); + String caps = new String("AbC"); + + FunctionArgumentAttributeValue attrV1 = null; + FunctionArgumentAttributeValue attrBigger = null; + FunctionArgumentAttributeValue attrBiggerNoMatch = null; + FunctionArgumentAttributeValue attrCaps = null; + FunctionArgumentAttributeValue attrNull = null; + FunctionArgumentAttributeValue attrBlank = null; + FunctionArgumentAttributeValue attrInteger = null; + try { + attrV1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(v1)); + attrBigger = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(bigger)); + attrBiggerNoMatch = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(biggerNoMatch)); + attrCaps = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(caps)); + attrBlank = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("")); + attrNull = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(null)); + attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234)); + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + FunctionDefinitionStringFunctions fd = (FunctionDefinitionStringFunctions) StdFunctions.FD_STRING_CONTAINS; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_CONTAINS, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + + // match + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrBigger); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertEquals(true, resValue); + + // no match + arguments.clear(); + arguments.add(attrBiggerNoMatch); + arguments.add(attrV1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // caps no match + arguments.clear(); + arguments.add(attrCaps); + arguments.add(attrBigger); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // bigger on the inside + arguments.clear(); + arguments.add(attrBigger); + arguments.add(attrV1); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // empty non-null first arg + arguments.clear(); + arguments.add(attrBlank); + arguments.add(attrBigger); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(true, resValue); + + // empty non-null second arg + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // two blanks + arguments.clear(); + arguments.add(attrBlank); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(true, resValue); + + // null firat arg + arguments.clear(); + arguments.add(attrNull); + arguments.add(attrBlank); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-contains Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null second arg + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrNull); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-contains Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // illegal arg type + arguments.clear(); + arguments.add(attrInteger); + arguments.add(attrBigger); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:string-contains Expected data type 'string' saw 'integer'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + @Test + public void testAnyuriContains() { + + + FunctionArgumentAttributeValue attrV1 = null; + FunctionArgumentAttributeValue attrBigger = null; + FunctionArgumentAttributeValue attrBiggerNoMatch = null; + FunctionArgumentAttributeValue attrCaps = null; + FunctionArgumentAttributeValue attrBigString = null; + FunctionArgumentAttributeValue attrNull = null; + FunctionArgumentAttributeValue attrBlankString = null; + FunctionArgumentAttributeValue attrBlankURI = null; + FunctionArgumentAttributeValue attrInteger = null; + try { + String v1 = new String("abc"); + URI bigger = new URI("abc.some.stringabc"); + URI biggerNoMatch = new URI("Zabc.some.stringabcZ"); + String caps = new String("AbC"); + String bigString = "thisIsSomeReallyBigStringToMatch"; + + attrV1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(v1)); + attrBigger = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(bigger)); + attrBiggerNoMatch = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(biggerNoMatch)); + attrCaps = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(caps)); + attrBigString = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(bigString)); + attrBlankString = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("")); + attrBlankURI = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue("")); + attrNull = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(null)); + attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234)); + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + FunctionDefinitionStringFunctions fd = (FunctionDefinitionStringFunctions) StdFunctions.FD_ANYURI_CONTAINS; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_ANYURI_CONTAINS, fd.getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + + // match + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrBigger); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertEquals(true, resValue); + + // no match + arguments.clear(); + arguments.add(attrBigString); + arguments.add(attrBiggerNoMatch); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // caps no match + arguments.clear(); + arguments.add(attrCaps); + arguments.add(attrBigger); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // bigger on the inside + arguments.clear(); + arguments.add(attrBigString); + arguments.add(attrBigger); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + // empty non-null first arg + arguments.clear(); + arguments.add(attrBlankString); + arguments.add(attrBigger); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(true, resValue); + + // empty non-null second arg + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrBlankURI); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(false, resValue); + + + // two blanks + arguments.clear(); + arguments.add(attrBlankString); + arguments.add(attrBlankURI); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); + resValue = (Boolean)res.getValue().getValue(); + assertEquals(true, resValue); + + // arguments reversed + arguments.clear(); + arguments.add(attrBigger); + arguments.add(attrV1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:anyURI-contains Expected data type 'string' saw 'anyURI'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // null firat arg + arguments.clear(); + arguments.add(attrNull); + arguments.add(attrBlankURI); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:anyURI-contains Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null second arg + arguments.clear(); + arguments.add(attrV1); + arguments.add(attrNull); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:anyURI-contains Got null attribute", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // illegal arg type + arguments.clear(); + arguments.add(attrInteger); + arguments.add(attrBigger); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:anyURI-contains Expected data type 'string' saw 'integer'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + +} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionStringNormalizeTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionStringNormalizeTest.java new file mode 100644 index 000000000..0071a7020 --- /dev/null +++ b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionStringNormalizeTest.java @@ -0,0 +1,118 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-TEST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.std.functions; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +import com.att.research.xacml.api.XACML3; +import com.att.research.xacml.std.datatypes.DataTypes; +import com.att.research.xacmlatt.pdp.policy.ExpressionResult; +import com.att.research.xacmlatt.pdp.policy.FunctionArgument; +import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; +import com.att.research.xacmlatt.pdp.std.StdFunctions; +import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionStringNormalize; + +/** + * Test of PDP Functions (See XACML core spec section A.3) + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * + */ +public class FunctionDefinitionStringNormalizeTest { + + /* + * variables useful in the following tests + */ + List arguments = new ArrayList(); + + @Test + public void testString_normalize_space() { + String initialString = " First and last are whitespace "; + FunctionArgumentAttributeValue attr1 = null; + try { + attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(initialString)); + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionStringNormalize fd = (FunctionDefinitionStringNormalize) StdFunctions.FD_STRING_NORMALIZE_SPACE; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_NORMALIZE_SPACE, fd.getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + + // test normal add + arguments.add(attr1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + String resValue = (String)res.getValue().getValue(); + assertEquals(initialString.length() - 4, resValue.length()); + assertTrue(initialString.trim().equals(resValue)); + } + + + @Test + public void testString_normalize_to_lower_case() { + String initialString = " First and last are whitespace "; + FunctionArgumentAttributeValue attr1 = null; + try { + attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(initialString)); + } catch (Exception e) { + fail("creating attribute e="+ e); + } + + FunctionDefinitionStringNormalize fd = (FunctionDefinitionStringNormalize) StdFunctions.FD_STRING_NORMALIZE_TO_LOWER_CASE; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_STRING_NORMALIZE_TO_LOWER_CASE, fd.getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + + // test normal add + arguments.add(attr1); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + String resValue = (String)res.getValue().getValue(); + assertTrue(initialString.toLowerCase().equals(resValue)); + } + +} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionURIStringConcatenateTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionURIStringConcatenateTest.java new file mode 100644 index 000000000..e1e91a79e --- /dev/null +++ b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionURIStringConcatenateTest.java @@ -0,0 +1,185 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-TEST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.std.functions; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.net.URI; +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +import com.att.research.xacml.api.XACML2; +import com.att.research.xacml.std.datatypes.DataTypes; +import com.att.research.xacmlatt.pdp.policy.ExpressionResult; +import com.att.research.xacmlatt.pdp.policy.FunctionArgument; +import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; +import com.att.research.xacmlatt.pdp.std.StdFunctions; +import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionURIStringConcatenate; + +/** + * Test of PDP Functions (See XACML core spec section A.3) + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * + */ +public class FunctionDefinitionURIStringConcatenateTest { + + /* + * THE FUNCTION BEING TESTED BY THIS CLASS IS DEPRECATED + * uri-string-concatenate has been deprecated in XACML 3.0 + */ + + /* + * variables useful in the following tests + */ + List arguments = new ArrayList(); + + + @SuppressWarnings("deprecation") + @Test + public void testURI_string_concatenate() { + + // URI args + FunctionArgumentAttributeValue attrURI1 = null; + + + FunctionArgumentAttributeValue attrStrAbc = null; + FunctionArgumentAttributeValue attrStrSlashMno = null; + FunctionArgumentAttributeValue attrStrSlashInMiddle = null; + FunctionArgumentAttributeValue attrStrWithSpace = null; + + + try { + attrURI1 = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue("http://someplace")); + + + attrStrAbc = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("Abc")); + attrStrSlashMno = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("/Mno")); + attrStrSlashInMiddle = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("hij/pqr")); + attrStrWithSpace = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("x y z")); + + + } catch (Exception e) { + fail("creating attributes e="+ e); + } + + // deprecation marking in the following line is correct - this function IS deprecated but still valid for XACML 3.0 + FunctionDefinitionURIStringConcatenate fd = (FunctionDefinitionURIStringConcatenate) StdFunctions.FD_URI_STRING_CONCATENATE; + + // check identity and type of the thing created + assertEquals(XACML2.ID_FUNCTION_URI_STRING_CONCATENATE, fd.getId()); + assertEquals(DataTypes.DT_ANYURI.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + + + // add one string to uri + arguments.clear(); + arguments.add(attrURI1); + arguments.add(attrStrAbc); + ExpressionResult res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.net.URI.class, res.getValue().getValue().getClass()); + URI resValue = (URI)res.getValue().getValue(); + assertEquals("http://someplaceAbc", resValue.toString()); + + + // add 2 strings to uri + arguments.clear(); + arguments.add(attrURI1); + arguments.add(attrStrAbc); + arguments.add(attrStrSlashMno); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.net.URI.class, res.getValue().getValue().getClass()); + resValue = (URI)res.getValue().getValue(); + assertEquals("http://someplaceAbc/Mno", resValue.toString()); + + // slash in middle of string + arguments.clear(); + arguments.add(attrURI1); + arguments.add(attrStrSlashInMiddle); + arguments.add(attrStrSlashMno); + res = fd.evaluate(null, arguments); + assertTrue(res.isOk()); + assertEquals(java.net.URI.class, res.getValue().getValue().getClass()); + resValue = (URI)res.getValue().getValue(); + assertEquals("http://someplacehij/pqr/Mno", resValue.toString()); + + // create bad uri + arguments.clear(); + arguments.add(attrURI1); + arguments.add(attrStrWithSpace); + arguments.add(attrStrSlashMno); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:uri-string-concatenate Final string 'http://someplacex y z/Mno' not URI, Illegal character in authority at index 7: http://someplacex y z/Mno", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // no args + arguments.clear(); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:uri-string-concatenate Expected 2 or more arguments, got 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // one arg + arguments.clear(); + arguments.add(attrURI1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:uri-string-concatenate Expected 2 or more arguments, got 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // first arg not uri + arguments.clear(); + arguments.add(attrStrAbc); + arguments.add(attrURI1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:uri-string-concatenate Expected data type 'anyURI' saw 'string' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // 2nd arg not string + arguments.clear(); + arguments.add(attrURI1); + arguments.add(attrURI1); + res = fd.evaluate(null, arguments); + assertFalse(res.isOk()); + assertEquals("function:uri-string-concatenate Expected data type 'string' saw 'anyURI' at arg index 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + + +} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionXPathTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionXPathTest.java new file mode 100644 index 000000000..5b6c97de1 --- /dev/null +++ b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionXPathTest.java @@ -0,0 +1,1127 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-TEST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.std.functions; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import javax.xml.namespace.NamespaceContext; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathFactory; + +import org.junit.Test; + +import com.att.research.xacml.api.Request; +import com.att.research.xacml.api.XACML3; +import com.att.research.xacml.std.IdentifierImpl; +import com.att.research.xacml.std.StdRequest; +import com.att.research.xacml.std.StdStatus; +import com.att.research.xacml.std.datatypes.DataTypes; +import com.att.research.xacml.std.datatypes.XPathExpressionWrapper; +import com.att.research.xacml.std.dom.DOMRequest; +import com.att.research.xacmlatt.pdp.policy.ExpressionResult; +import com.att.research.xacmlatt.pdp.policy.FunctionArgument; +import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; +import com.att.research.xacmlatt.pdp.std.StdEvaluationContext; +import com.att.research.xacmlatt.pdp.std.StdFunctions; +import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionXPath; + +/** + * Test of PDP Functions (See XACML core spec section A.3) + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * + */ +public class FunctionDefinitionXPathTest { + + // + // Strings for the Request contents + // + + String reqStrMainStart = "" + + "" + + " " + + " " + + " Julius Hibbert" + + " " + + " " + + " This is IT! " + + " " + + " " + + " This is IT! " + + " " + + ""; + + String reqStrResourceStart = ""; + + String reqStrContentMdRecord = + " " + + "" + + "" + + "ABC Hospital" + + "Surgery" + + "" + + "" + + "Bart Simpson" + + "60" + + "male" + + "123456" + + "" + + "" + + "" + + "Gastric Cancer" + + "Hyper tension" + + "" + + "" + + "" + + "Well differentiated adeno carcinoma" + + "" + + "2000-10-05" + + "" + + "" + + " " + + " " + + ""; + String reqStrMalformedContent = + " " + + "" + + "" + + "ABC Hospital" + + "" + + ""; + String reqStrResourceEnd = " " + + " http://medico.com/record/patient/BartSimpson" + + " " + + " "; + String reqStrActionStart = ""; + + String reqStrActionEnd = "" + + "read" + + "" + + " "; + String reqStrEnvironmentStartEnd = " "; + String reqStrMainEnd = " "; + + + // combined strings for convenience + String reqStrMainResourceStart = reqStrMainStart + reqStrResourceStart; + String reqStrResourceAllEnd = reqStrResourceEnd + reqStrActionStart + reqStrActionEnd + reqStrEnvironmentStartEnd + reqStrMainEnd; + + + /* + * variables useful in the following tests + */ + List arguments = new ArrayList(); + + + + // Name Spaces used in the XML as part of these examples (copied from the Conformance tests) - needed for compiling XPaths + NamespaceContext nameSpaceContext = new NamespaceContext() { + @Override + public Iterator getPrefixes(String arg0) { return null;} + + @Override + public String getPrefix(String arg0) {return null;} + + @Override + public String getNamespaceURI(String arg0) { + if("md".equals(arg0)) { + return "http://www.medico.com/schemas/record"; + } else if ("xacml-context".equals(arg0)) { + return "urn:oasis:names:tc:xacml:3.0:context:schema:os"; + } else if ("xsi".equals(arg0)) { + return "http://www.w3.org/2001/XMLSchema-instance"; + } + return null; + } + }; + + + + // + // XPath Function Attributes available for use in tests (representing appropriate fragment of Policy) + // + + FunctionArgumentAttributeValue attrXnull = null; + FunctionArgumentAttributeValue attrXEmpty = null; + FunctionArgumentAttributeValue attrXNoCategory = null; + FunctionArgumentAttributeValue attrXNoValue = null; + FunctionArgumentAttributeValue attrXSlashSlashMdRecord = null; + FunctionArgumentAttributeValue attrXSlashSlashStar = null; + FunctionArgumentAttributeValue attrXSlashSlashMdName = null; + FunctionArgumentAttributeValue attrXSlashSlashMdMalignancy = null; + FunctionArgumentAttributeValue attrXNotInRequest = null; + FunctionArgumentAttributeValue attrXSlashSlashMdRecordSlashStar = null; + FunctionArgumentAttributeValue attrXMdPatientInfo = null; + + FunctionArgumentAttributeValue attrBadType = null; + + // String version of attrs for use in Deprecated functions + FunctionArgumentAttributeValue attrStrnull = null; + FunctionArgumentAttributeValue attrStrEmpty = null; + FunctionArgumentAttributeValue attrStrNoCategory = null; + FunctionArgumentAttributeValue attrStrNoValue = null; + FunctionArgumentAttributeValue attrStrSlashSlashMdRecord = null; + FunctionArgumentAttributeValue attrStrSlashSlashStar = null; + FunctionArgumentAttributeValue attrStrSlashSlashMdName = null; + FunctionArgumentAttributeValue attrStrSlashSlashMdMalignancy = null; + FunctionArgumentAttributeValue attrStrNotInRequest = null; + FunctionArgumentAttributeValue attrStrSlashSlashMdRecordSlashStar = null; + FunctionArgumentAttributeValue attrStrMdPatientInfo = null; + + + // + // REQUEST objects available for use in tests + // + Request requestEmpty = new StdRequest(StdStatus.STATUS_OK); + Request requestMdRecord = null; + Request requestDoubleResources = null; + Request requestResourceActionContent = null; + Request requestContentInAction = null; + + + + + /** + * Set up all variables in one place because it is complicated (lots of steps needed for each attribute) + */ + public FunctionDefinitionXPathTest() { + try { + XPathFactory xPathFactory = XPathFactory.newInstance(); + XPath xpath = xPathFactory.newXPath(); + xpath.setNamespaceContext(nameSpaceContext); + + // Create XPaths to use in expressions + XPathExpressionWrapper xEmpty = new XPathExpressionWrapper(""); + XPathExpressionWrapper xSlashSlashMdRecord = new XPathExpressionWrapper(xpath.compile("//md:record")); + XPathExpressionWrapper xSlashSlashStar = new XPathExpressionWrapper(xpath.compile("//*")); + XPathExpressionWrapper xSlashSlashMdName = new XPathExpressionWrapper(xpath.compile("//md:name")); + XPathExpressionWrapper xSlashSlashMdMalignancy = new XPathExpressionWrapper(xpath.compile("//md:malignancy")); + XPathExpressionWrapper xNotInRequest = new XPathExpressionWrapper(xpath.compile("value_Not_in_request")); + XPathExpressionWrapper xSlashSlashMdRecordSlashStar = new XPathExpressionWrapper(xpath.compile("//md:record/*")); + XPathExpressionWrapper xMdPatientInfo = new XPathExpressionWrapper(xpath.compile("md:patient_info")); + + + + // create Function Attributes out of the XPathExpressions + attrXnull = new FunctionArgumentAttributeValue(null); + attrXEmpty = new FunctionArgumentAttributeValue(DataTypes.DT_XPATHEXPRESSION.createAttributeValue(xEmpty)); + attrXNoCategory = new FunctionArgumentAttributeValue(DataTypes.DT_XPATHEXPRESSION.createAttributeValue(xSlashSlashMdRecord)); + attrXNoValue = new FunctionArgumentAttributeValue(DataTypes.DT_XPATHEXPRESSION.createAttributeValue(xEmpty, + new IdentifierImpl("urn:oasis:names:tc:xacml:3.0:attribute-category:resource" ))); + attrXSlashSlashMdRecord = new FunctionArgumentAttributeValue(DataTypes.DT_XPATHEXPRESSION.createAttributeValue(xSlashSlashMdRecord, + new IdentifierImpl("urn:oasis:names:tc:xacml:3.0:attribute-category:resource" ))); + attrXSlashSlashStar = new FunctionArgumentAttributeValue(DataTypes.DT_XPATHEXPRESSION.createAttributeValue(xSlashSlashStar, + new IdentifierImpl("urn:oasis:names:tc:xacml:3.0:attribute-category:resource" ))); + attrXSlashSlashMdName = new FunctionArgumentAttributeValue(DataTypes.DT_XPATHEXPRESSION.createAttributeValue(xSlashSlashMdName, + new IdentifierImpl("urn:oasis:names:tc:xacml:3.0:attribute-category:resource" ))); + attrXSlashSlashMdMalignancy = new FunctionArgumentAttributeValue(DataTypes.DT_XPATHEXPRESSION.createAttributeValue(xSlashSlashMdMalignancy, + new IdentifierImpl("urn:oasis:names:tc:xacml:3.0:attribute-category:resource" ))); + attrXNotInRequest = new FunctionArgumentAttributeValue(DataTypes.DT_XPATHEXPRESSION.createAttributeValue(xNotInRequest, + new IdentifierImpl("urn:oasis:names:tc:xacml:3.0:attribute-category:resource" ))); + + attrXSlashSlashMdRecordSlashStar = new FunctionArgumentAttributeValue(DataTypes.DT_XPATHEXPRESSION.createAttributeValue(xSlashSlashMdRecordSlashStar, + new IdentifierImpl("urn:oasis:names:tc:xacml:3.0:attribute-category:resource" ))); + attrXMdPatientInfo = new FunctionArgumentAttributeValue(DataTypes.DT_XPATHEXPRESSION.createAttributeValue(xMdPatientInfo, + new IdentifierImpl("urn:oasis:names:tc:xacml:3.0:attribute-category:resource" ))); + + + // Deprecated versions of args + attrStrnull = new FunctionArgumentAttributeValue(null); + attrStrEmpty = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("")); + attrStrNoCategory = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("//md:record")); + attrStrNoValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("", + new IdentifierImpl("urn:oasis:names:tc:xacml:3.0:attribute-category:resource" ))); + attrStrSlashSlashMdRecord = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("//md:record", + new IdentifierImpl("urn:oasis:names:tc:xacml:3.0:attribute-category:resource" ))); + attrStrSlashSlashStar = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("//*", + new IdentifierImpl("urn:oasis:names:tc:xacml:3.0:attribute-category:resource" ))); + attrStrSlashSlashMdName = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("//md:name", + new IdentifierImpl("urn:oasis:names:tc:xacml:3.0:attribute-category:resource" ))); + attrStrSlashSlashMdMalignancy = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("//md:malignancy", + new IdentifierImpl("urn:oasis:names:tc:xacml:3.0:attribute-category:resource" ))); + attrStrNotInRequest = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("value_Not_in_request", + new IdentifierImpl("urn:oasis:names:tc:xacml:3.0:attribute-category:resource" ))); + + attrStrSlashSlashMdRecordSlashStar = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("//md:record/*", + new IdentifierImpl("urn:oasis:names:tc:xacml:3.0:attribute-category:resource" ))); + attrStrMdPatientInfo = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("md:patient_info", + new IdentifierImpl("urn:oasis:names:tc:xacml:3.0:attribute-category:resource" ))); + + + + + attrBadType = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("some string")); + + + + // Request objects + // to create a Request object the easiest way is to put the xml into a file and use the DOMRequest to load it. + + // single Content in the Resources section (normal valid request) + String reqString = reqStrMainResourceStart + reqStrContentMdRecord + reqStrResourceAllEnd; + File tFile = File.createTempFile("functionJunit", "request"); + BufferedWriter bw = new BufferedWriter(new FileWriter(tFile)); + bw.append(reqString); + bw.flush(); + bw.close(); + requestMdRecord = DOMRequest.load(tFile); + tFile.delete(); + + // Resources included twice + reqString = reqStrMainResourceStart + reqStrContentMdRecord + reqStrResourceEnd + reqStrResourceStart + reqStrContentMdRecord +reqStrResourceAllEnd; + tFile = File.createTempFile("functionJunit", "request"); + bw = new BufferedWriter(new FileWriter(tFile)); + bw.append(reqString); + bw.flush(); + bw.close(); + requestDoubleResources = DOMRequest.load(tFile); + tFile.delete(); + + + // content included in both Resource and Action - ok + reqString = reqStrMainResourceStart + reqStrContentMdRecord + reqStrResourceEnd + reqStrActionStart + reqStrContentMdRecord + reqStrActionEnd + reqStrMainEnd; + tFile = File.createTempFile("functionJunit", "request"); + bw = new BufferedWriter(new FileWriter(tFile)); + bw.append(reqString); + bw.flush(); + bw.close(); + requestResourceActionContent = DOMRequest.load(tFile); + tFile.delete(); + + // Content included only in Action - missing content produces non-error result according to spec + reqString = reqStrMainResourceStart + reqStrResourceEnd + reqStrActionStart + reqStrContentMdRecord + reqStrActionEnd + reqStrMainEnd; + tFile = File.createTempFile("functionJunit", "request"); + bw = new BufferedWriter(new FileWriter(tFile)); + bw.append(reqString); + bw.flush(); + bw.close(); + requestContentInAction = DOMRequest.load(tFile); + tFile.delete(); + + + + // Test that Bad XML is caught + @SuppressWarnings("unused") + Request requestContentMisplaced = null; + @SuppressWarnings("unused") + Request requestMalformedContent = null; + @SuppressWarnings("unused") + Request requestDoubleContent = null; + + + // Content included twice - error + reqString = reqStrMainResourceStart + reqStrContentMdRecord + reqStrContentMdRecord +reqStrResourceAllEnd; + tFile = File.createTempFile("functionJunit", "request"); + bw = new BufferedWriter(new FileWriter(tFile)); + bw.append(reqString); + bw.flush(); + bw.close(); + try { + requestDoubleContent = DOMRequest.load(tFile); + tFile.delete(); + } catch (com.att.research.xacml.std.dom.DOMStructureException e) { + // this is what it should do, so just continue + } catch (Exception e) { + fail("Unexpected exception for bad XML, e="+e); + } + + // Bad XML - Content not under a Category + reqString = reqStrMainStart + reqStrContentMdRecord + reqStrResourceStart + reqStrResourceEnd + reqStrActionStart + reqStrActionEnd + reqStrMainEnd; + tFile = File.createTempFile("functionJunit", "request"); + bw = new BufferedWriter(new FileWriter(tFile)); + bw.append(reqString); + bw.flush(); + bw.close(); + try { + requestContentMisplaced = DOMRequest.load(tFile); + tFile.delete(); + } catch (com.att.research.xacml.std.dom.DOMStructureException e) { + // this is what it should do, so just continue + } catch (Exception e) { + fail("Unexpected exception for bad XML, e="+e); + } + + // Bad XML - Content is not valid XML + reqString = reqStrMainResourceStart + reqStrMalformedContent + reqStrResourceAllEnd; + tFile = File.createTempFile("functionJunit", "request"); + bw = new BufferedWriter(new FileWriter(tFile)); + bw.append(reqString); + bw.flush(); + bw.close(); + try { + requestMalformedContent = DOMRequest.load(tFile); + tFile.delete(); + } catch (com.att.research.xacml.std.dom.DOMStructureException e) { + // this is what it should do, so just continue + } catch (Exception e) { + fail("Unexpected exception for bad XML, e="+e); + } + + } catch (Exception e) { + fail("Constructor initializing variables, e="+ e + " cause="+e.getCause()); + } + + } + + + + + + + + + @Test + public void testXpath_node_count() { + + + + FunctionDefinitionXPath fd = (FunctionDefinitionXPath) StdFunctions.FD_XPATH_NODE_COUNT; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_XPATH_NODE_COUNT, fd.getId()); + assertEquals(DataTypes.DT_XPATHEXPRESSION.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(1), fd.getNumArgs()); + + + // match all elements within context + arguments.clear(); + arguments.add(attrXSlashSlashStar); + ExpressionResult res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertTrue(res.isOk()); + BigInteger resValue = (BigInteger)res.getValue().getValue(); + assertEquals(new BigInteger("18"), resValue); + + // match exactly 1 element + arguments.clear(); + arguments.add(attrXSlashSlashMdMalignancy); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertTrue(res.isOk()); + resValue = (BigInteger)res.getValue().getValue(); + assertEquals(new BigInteger("1"), resValue); + + // match a few but not all + arguments.clear(); + arguments.add(attrXSlashSlashMdName); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertTrue(res.isOk()); + resValue = (BigInteger)res.getValue().getValue(); + assertEquals(new BigInteger("2"), resValue); + + + // verify variables using in other tests: count nodes immediately under md:record + arguments.clear(); + arguments.add(attrXSlashSlashMdRecordSlashStar); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertTrue(res.isOk()); + resValue = (BigInteger)res.getValue().getValue(); + assertEquals(new BigInteger("3"), resValue); + + // verify variables using in other tests: count number of records containing patient_info + arguments.clear(); + arguments.add(attrXMdPatientInfo); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertTrue(res.isOk()); + resValue = (BigInteger)res.getValue().getValue(); + assertEquals(new BigInteger("1"), resValue); + + // verify variables using in other tests: count number of records containing md:name + arguments.clear(); + arguments.add(attrXSlashSlashMdName); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertTrue(res.isOk()); + resValue = (BigInteger)res.getValue().getValue(); + assertEquals(new BigInteger("2"), resValue); + + // verify variables using in other tests: count number of records containing md:malignancy + arguments.clear(); + arguments.add(attrXSlashSlashMdMalignancy); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertTrue(res.isOk()); + resValue = (BigInteger)res.getValue().getValue(); + assertEquals(new BigInteger("1"), resValue); + + + + + // match no element + arguments.clear(); + arguments.add(attrXNotInRequest); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertTrue(res.isOk()); + resValue = (BigInteger)res.getValue().getValue(); + assertEquals(new BigInteger("0"), resValue); + + // Resources included twice + arguments.clear(); + arguments.add(attrXSlashSlashMdName); + res = fd.evaluate(new StdEvaluationContext(requestDoubleResources, null, null), arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-count More than one Content section for id 'urn:oasis:names:tc:xacml:3.0:attribute-category:resource'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // Content in both Resource and Action categories (ok) + arguments.clear(); + arguments.add(attrXSlashSlashMdName); + res = fd.evaluate(new StdEvaluationContext(requestResourceActionContent, null, null), arguments); + assertTrue(res.isOk()); + resValue = (BigInteger)res.getValue().getValue(); + assertEquals(new BigInteger("2"), resValue); + + // Content only in Action category (missing in Resources -> 0 according to spec) + arguments.clear(); + arguments.add(attrXSlashSlashMdName); + res = fd.evaluate(new StdEvaluationContext(requestContentInAction, null, null), arguments); + assertTrue(res.isOk()); + resValue = (BigInteger)res.getValue().getValue(); + assertEquals(new BigInteger("0"), resValue); + + + + +//TODO - any other tests???? + + // null Evaluation Context + arguments.clear(); + arguments.add(attrXEmpty); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-count Got null EvaluationContext", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null Request + arguments.clear(); + arguments.add(attrXSlashSlashMdRecord); + res = fd.evaluate(new StdEvaluationContext(null, null, null), arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-count Got null Request in EvaluationContext", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null attribute + arguments.clear(); + arguments.add(attrXnull); + res = fd.evaluate(new StdEvaluationContext(requestEmpty, null, null), arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-count Got null attribute at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // no value + arguments.clear(); + arguments.add(attrXNoValue); + res = fd.evaluate(new StdEvaluationContext(requestEmpty, null, null), arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-count XPathExpression returned null at index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // no category + arguments.clear(); + arguments.add(attrXNoCategory); + res = fd.evaluate(new StdEvaluationContext(requestEmpty, null, null), arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-count Got null Category at index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // too many args + arguments.clear(); + arguments.add(attrXEmpty); + arguments.add(attrXEmpty); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-count Expected 1 arguments, got 2", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // too few args + arguments.clear(); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-count Expected 1 arguments, got 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-count Expected data type 'xpathExpression' saw 'string' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null args + arguments.clear(); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-count Got null argument at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + @Test + public void testXpath_node_equal() { + + + FunctionDefinitionXPath fd = (FunctionDefinitionXPath) StdFunctions.FD_XPATH_NODE_EQUAL; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_XPATH_NODE_EQUAL, fd.getId()); + assertEquals(DataTypes.DT_XPATHEXPRESSION.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + + // test normal success - exactly the same set + arguments.clear(); + arguments.add(attrXSlashSlashMdName); + arguments.add(attrXSlashSlashMdName); + ExpressionResult res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // success - second list is subset of first list + arguments.clear(); + arguments.add(attrXSlashSlashMdRecordSlashStar); + arguments.add(attrXMdPatientInfo); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // success - first list is subset of second list + arguments.clear(); + arguments.add(attrXMdPatientInfo); + arguments.add(attrXSlashSlashMdRecordSlashStar); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // success - second list contains children of first list + arguments.clear(); + arguments.add(attrXSlashSlashMdRecord); + arguments.add(attrXSlashSlashMdName); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // success - first list contains children of second list + arguments.clear(); + arguments.add(attrXSlashSlashMdName); + arguments.add(attrXSlashSlashMdRecord); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + + + // two non-overlapping sets + arguments.clear(); + arguments.add(attrXSlashSlashMdMalignancy); + arguments.add(attrXSlashSlashMdName); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first list contains nothing + arguments.clear(); + arguments.add(attrXNotInRequest); + arguments.add(attrXSlashSlashMdName); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // second list contains nothing + arguments.clear(); + arguments.add(attrXSlashSlashMdName); + arguments.add(attrXNotInRequest); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + + +//TODO + //????? + ///??????? add real tests + ////// + + + // Resources included twice + arguments.clear(); + arguments.add(attrXSlashSlashMdName); + arguments.add(attrXSlashSlashMdName); + res = fd.evaluate(new StdEvaluationContext(requestDoubleResources, null, null), arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-equal More than one Content section for id 'urn:oasis:names:tc:xacml:3.0:attribute-category:resource'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + + // Content in both Resource and Action categories (ok) + arguments.clear(); + arguments.add(attrXSlashSlashMdName); + arguments.add(attrXSlashSlashMdName); + res = fd.evaluate(new StdEvaluationContext(requestResourceActionContent, null, null), arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // Content only in Action category (missing in Resources -> 0 according to spec) + arguments.clear(); + arguments.add(attrXSlashSlashMdName); + arguments.add(attrXSlashSlashMdName); + res = fd.evaluate(new StdEvaluationContext(requestContentInAction, null, null), arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + + // null Evaluation Context + arguments.clear(); + arguments.add(attrXSlashSlashMdRecord); + arguments.add(attrXSlashSlashMdRecord); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-equal Got null EvaluationContext", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null Request + arguments.clear(); + arguments.add(attrXSlashSlashMdRecord); + arguments.add(attrXSlashSlashMdRecord); + res = fd.evaluate(new StdEvaluationContext(null, null, null), arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-equal Got null Request in EvaluationContext", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null attribute + arguments.clear(); + arguments.add(attrXnull); + arguments.add(attrXSlashSlashMdRecord); + res = fd.evaluate(new StdEvaluationContext(requestEmpty, null, null), arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-equal Got null attribute at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + arguments.add(attrXSlashSlashMdRecord); + arguments.add(attrXnull); + res = fd.evaluate(new StdEvaluationContext(requestEmpty, null, null), arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-equal Got null attribute at arg index 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // no value + arguments.clear(); + arguments.add(attrXNoValue); + arguments.add(attrXSlashSlashMdRecord); + res = fd.evaluate(new StdEvaluationContext(requestEmpty, null, null), arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-equal XPathExpression returned null at index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + arguments.add(attrXSlashSlashMdRecord); + arguments.add(attrXNoValue); + res = fd.evaluate(new StdEvaluationContext(requestEmpty, null, null), arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-equal XPathExpression returned null at index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // no category + arguments.clear(); + arguments.add(attrXNoCategory); + arguments.add(attrXSlashSlashMdRecord); + res = fd.evaluate(new StdEvaluationContext(requestEmpty, null, null), arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-equal Got null Category at index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + arguments.add(attrXSlashSlashMdRecord); + arguments.add(attrXNoCategory); + res = fd.evaluate(new StdEvaluationContext(requestEmpty, null, null), arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-equal XPathExpression returned null at index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // too many args + arguments.clear(); + arguments.add(attrXEmpty); + arguments.add(attrXEmpty); + arguments.add(attrXEmpty); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-equal Expected 2 arguments, got 3", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // too few args + arguments.clear(); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-equal Expected 2 arguments, got 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + arguments.add(attrXEmpty); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-equal Expected 2 arguments, got 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrBadType); + arguments.add(attrXEmpty); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-equal Expected data type 'xpathExpression' saw 'string' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + arguments.add(attrXEmpty); + arguments.add(attrBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-equal Expected data type 'xpathExpression' saw 'string' at arg index 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null args + arguments.clear(); + arguments.add(attrXEmpty); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-equal Got null argument at arg index 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + arguments.add(null); + arguments.add(attrXEmpty); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-equal Got null argument at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + } + + + + + @Test + public void testXpath_node_match() { + + + FunctionDefinitionXPath fd = (FunctionDefinitionXPath) StdFunctions.FD_XPATH_NODE_MATCH; + + // check identity and type of the thing created + assertEquals(XACML3.ID_FUNCTION_XPATH_NODE_MATCH, fd.getId()); + assertEquals(DataTypes.DT_XPATHEXPRESSION.getId(), fd.getDataTypeArgs().getId()); + assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); + + // just to be safe... If tests take too long these can probably be eliminated + assertFalse(fd.returnsBag()); + assertEquals(new Integer(2), fd.getNumArgs()); + + + // test normal success - exactly the same set + arguments.clear(); + arguments.add(attrXSlashSlashMdName); + arguments.add(attrXSlashSlashMdName); + ExpressionResult res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertTrue(res.isOk()); + Boolean resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // success - second list is subset of first list + arguments.clear(); + arguments.add(attrXSlashSlashMdRecordSlashStar); + arguments.add(attrXMdPatientInfo); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // success - first list is subset of second list + arguments.clear(); + arguments.add(attrXMdPatientInfo); + arguments.add(attrXSlashSlashMdRecordSlashStar); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // success - second list contains children of first list + arguments.clear(); + arguments.add(attrXSlashSlashMdRecord); + arguments.add(attrXSlashSlashMdName); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // success - first list contains children of second list + arguments.clear(); + arguments.add(attrXSlashSlashMdName); + arguments.add(attrXSlashSlashMdRecord); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + + + // two non-overlapping sets + arguments.clear(); + arguments.add(attrXSlashSlashMdMalignancy); + arguments.add(attrXSlashSlashMdName); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // first list contains nothing + arguments.clear(); + arguments.add(attrXNotInRequest); + arguments.add(attrXSlashSlashMdName); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + // second list contains nothing + arguments.clear(); + arguments.add(attrXSlashSlashMdName); + arguments.add(attrXNotInRequest); + res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + +//TODO + //????? + ///??????? add real tests + ////// + + + // Resources included twice + arguments.clear(); + arguments.add(attrXSlashSlashMdName); + arguments.add(attrXSlashSlashMdName); + res = fd.evaluate(new StdEvaluationContext(requestDoubleResources, null, null), arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-match More than one Content section for id 'urn:oasis:names:tc:xacml:3.0:attribute-category:resource'", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + // Content in both Resource and Action categories (ok) + arguments.clear(); + arguments.add(attrXSlashSlashMdName); + arguments.add(attrXSlashSlashMdName); + res = fd.evaluate(new StdEvaluationContext(requestResourceActionContent, null, null), arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertTrue(resValue); + + // Content only in Action category (missing in Resources -> 0 according to spec) + arguments.clear(); + arguments.add(attrXSlashSlashMdName); + arguments.add(attrXSlashSlashMdName); + res = fd.evaluate(new StdEvaluationContext(requestContentInAction, null, null), arguments); + assertTrue(res.isOk()); + resValue = (Boolean)res.getValue().getValue(); + assertFalse(resValue); + + + // null Evaluation Context + arguments.clear(); + arguments.add(attrXSlashSlashMdRecord); + arguments.add(attrXSlashSlashMdRecord); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-match Got null EvaluationContext", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null Request + arguments.clear(); + arguments.add(attrXSlashSlashMdRecord); + arguments.add(attrXSlashSlashMdRecord); + res = fd.evaluate(new StdEvaluationContext(null, null, null), arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-match Got null Request in EvaluationContext", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null attribute + arguments.clear(); + arguments.add(attrXnull); + arguments.add(attrXSlashSlashMdRecord); + res = fd.evaluate(new StdEvaluationContext(requestEmpty, null, null), arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-match Got null attribute at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + arguments.add(attrXSlashSlashMdRecord); + arguments.add(attrXnull); + res = fd.evaluate(new StdEvaluationContext(requestEmpty, null, null), arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-match Got null attribute at arg index 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // no value + arguments.clear(); + arguments.add(attrXNoValue); + arguments.add(attrXSlashSlashMdRecord); + res = fd.evaluate(new StdEvaluationContext(requestEmpty, null, null), arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-match XPathExpression returned null at index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + arguments.add(attrXSlashSlashMdRecord); + arguments.add(attrXNoValue); + res = fd.evaluate(new StdEvaluationContext(requestEmpty, null, null), arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-match XPathExpression returned null at index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // no category + arguments.clear(); + arguments.add(attrXNoCategory); + arguments.add(attrXSlashSlashMdRecord); + res = fd.evaluate(new StdEvaluationContext(requestEmpty, null, null), arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-match Got null Category at index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + arguments.add(attrXSlashSlashMdRecord); + arguments.add(attrXNoCategory); + res = fd.evaluate(new StdEvaluationContext(requestEmpty, null, null), arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-match XPathExpression returned null at index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // too many args + arguments.clear(); + arguments.add(attrXEmpty); + arguments.add(attrXEmpty); + arguments.add(attrXEmpty); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-match Expected 2 arguments, got 3", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // too few args + arguments.clear(); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-match Expected 2 arguments, got 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + arguments.add(attrXEmpty); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-match Expected 2 arguments, got 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // bad arg type + arguments.clear(); + arguments.add(attrBadType); + arguments.add(attrXEmpty); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-match Expected data type 'xpathExpression' saw 'string' at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + arguments.add(attrXEmpty); + arguments.add(attrBadType); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-match Expected data type 'xpathExpression' saw 'string' at arg index 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + // null args + arguments.clear(); + arguments.add(attrXEmpty); + arguments.add(null); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-match Got null argument at arg index 1", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + arguments.clear(); + arguments.add(null); + arguments.add(attrXEmpty); + res = fd.evaluate(null, arguments); + assertFalse(res.getStatus().isOk()); + assertEquals( "function:xpath-node-match Got null argument at arg index 0", res.getStatus().getStatusMessage()); + assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); + + + + } + + + + // + // DEPRECATED versions that use String arguments rather than XPATHEXPRESSIONs + // are NOT supported due to ambiguity in the semantics between 2.0 ( is root and has only one in resources) + // and 3.0 ( is root and there are multiple sections in any category) + // + + + +} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/json/RequestCategoryTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/json/RequestCategoryTest.java new file mode 100644 index 000000000..0afde1729 --- /dev/null +++ b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/json/RequestCategoryTest.java @@ -0,0 +1,4174 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-TEST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.std.json; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import org.junit.Test; + +import com.att.research.xacml.api.Request; +import com.att.research.xacml.std.json.JSONRequest; +import com.att.research.xacml.std.json.JSONStructureException; + +/** + * Test JSON Request convert to object - Category sub-component. Does not include "Default" Categories (Subject, Action, Resource, Environment). + * Basic existance/absence of Category is tested in RequestMainTest. + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * NOTE: + * The "correct" way to verify that each JSON string gets translated into our internal Objects correctly is to look explicitly at each of the child objects + * and verify that they are correct. This would involve a lot of coding to get child of child of child and individually verify each property of each element. + * To simplify testing we assume that request.toString() correctly includes a complete text representation of every sub-component of the Request object + * and we compare the resulting String to our expected String. + * This has two possible sources of error: + * - toString might not include some sub-component, and + * - the initial verification of the resulting string is done by hand and may have been incorrect. + * + * + */ +public class RequestCategoryTest { + + // The request object output from each test conversion from JSON string + Request request; + + + /* + * Request that uses all fields with both single and multiple entries + */ + String allFieldsRequest = + "{\"Request\": {" + + "\"ReturnPolicyIdList\" : true ," + + "\"CombinedDecision\" : true ," + + "\"XPathVersion\" : \"http://www.w3.org/TR/1999/REC-xpath-19991116\"," + + "\"MultiRequests\" : {" + + "\"RequestReference\": [" + + "{ " + + "\"ReferenceId\" : [\"foo1\",\"bar1\"]" + + "}," + + "{" + + "\"ReferenceId\" : [\"foo2\",\"bar1\"]" + + "}]" + + "}," + + + "\"Category\": [" + + "{ " + + "\"CategoryId\": \"custom-category\", " + + "\"Id\" : \"customId\", " + + "\"Attribute\" : [" + + "{" + + "\"AttributeId\" : \"document-id\", " + + "\"DataType\" : \"integer\", " + + "\"Value\" : 123 " + + "}, " + + "{" + + "\"AttributeId\" : \"document-url\", " + + "\"DataType\" : \"anyURI\", " + + "\"Value\" : \"http://somewhere.over.the.com/rainbow\" " + + "}, " + + "{" + + "\"AttributeId\" : \"page-list\", " + + "\"Value\" : [1, 2, 3, 4.5, 3, 2, 1] " + + "} " + + "]" + + "}, " + + "{ " + + "\"CategoryId\": \"another-custom-cat\", " + + "\"Id\" : \"anotherXmlId\", " + + "\"Attribute\" : []" + + "} " + + "], " + + + "\"AccessSubject\":{ " + + "\"Content\" : \"" + + "Gambardella, MatthewXML Developer's GuideComputer" + + "44.952000-10-01An in-depth look at creating applications with XML."+ + "\"," + + "\"Attribute\" : []" + + "}, " + + + "\"Resource\" : {" + + "\"Content\" : \"PD94bWwgdmVyc2lvbj0iMS4wIj8+PGNhdGFsb2c+PGJvb2sgaWQ9ImJrMTAxIj48YXV0aG9yPkdhbWJhcmRlbGxhLCBNYXR0aGV3PC9hdXRob3I+PHRpdGxlPlhNT" + + "CBEZXZlbG9wZXIncyBHdWlkZTwvdGl0bGU+PGdlbnJlPkNvbXB1dGVyPC9nZW5yZT48cHJpY2U+NDQuOTU8L3ByaWNlPjxwdWJsaXNoX2RhdGU+MjAwMC0xMC0wMTwvcHVibGlzaF"+ + "9kYXRlPjxkZXNjcmlwdGlvbj5BbiBpbi1kZXB0aCBsb29rIGF0IGNyZWF0aW5nIGFwcGxpY2F0aW9ucyB3aXRoIFhNTC48L2Rlc2NyaXB0aW9uPjwvYm9vaz48L2NhdGFsb2c+\"" + + + + "} " + + + + "}}"; + + /* + * The following example comes directly from the JSON Profile Spec + */ + String exampleFromSpec = "{ " + + "\"Request\" : { " + + "\"AccessSubject\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "}, " + + "\"Action\" : { " + + "\"Attribute\": " + + "{ " + + "\"Id\" : \"action-id\", " + + "\"Value\" : \"http://www.xacml.eu/buy\", " + + "\"DataType\" : \"anyURI\" " + + "} " + + "}, " + + "\"Resource\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"book-title\", " + + "\"Value\" : \"Learn German in 90 days\" " + + "}, " + + "{ " + + "\"Id\" : \"currency\", " + + "\"Value\" : \"SEK\" " + + "}, " + + "{ " + + "\"Id\" : \"price\", " + + "\"Value\" : 123.34 " + + "} " + + "] " + + "} " + + "} " + + "} "; + + + /* + * The following example comes directly from the JSON Profile Spec (modified to include a "" missing from both examples). + * It shows the two ways of handling XPath content, as escaped XML and as Base64 encoding. + */ + String xPathExampleFromSpec = "{ " + + "\"Request\" : { " + + "\"Resource\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"urn:oasis:names:tc:xacml:3.0:content-selector\", " + + "\"DataType\" : \"xpathExpression\", " + + "\"Value\" : { " + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\", " + + "\"Namespaces\" : [{ " + + "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + + "}, " + + "{ " + + "\"Prefix\" : \"md\", " + + "\"Namespace\" : \"urn:example:med:schemas:record\" " + + "} " + + "], " + + "\"XPath\" : \"md:record/md:patient/md:patientDoB\" " + + "} " + + "} " + + "] " + + "} " + + "} " + + "} "; + + + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + // Top-level of Category + @Test + public void testCategoryTopLevel() { + + // empty Category + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Missing value + try { + request = JSONRequest.load("{\"Request\" : {\"Category\" }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\" : }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category without CategoryId + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{}] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category with CategoryId value missing or ="" + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\"] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"\" ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // CategoryId wrong type + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : true } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : 123 } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category with Id + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Id\" : \"customId\" } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category},xmlId=customId}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category with Id - wrong type + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Id\" : true } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Id\" : 123 } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // Category without Id + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\" } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // Category with standard CategoryId + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:access-subject\" } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category with extra unknown field + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", unknown } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"unknown\" : 123 } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category with multiple sub-Category objects using same CategoryId + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"category1\" }, {\"CategoryId\" : \"category1\" } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=category1}}{super={category=category1}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + } + + + + // Tests related to Attributes + @Test + public void testCategoryAttributes() { + + // Category with Attribute but none given ("Attribute" : [] ) + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute with empty attribute (missing both AttributeId and Id) + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute with AttributeId and no Value + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"AttributeId\" : \"document-id\" " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute missing AttributeId but with Id + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"AttributeId\" : \"document-id\", " + + "\"Value\" : 123 " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=123}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute missing AttributeId but with Id + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : 123 " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=123}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute including both AttributeId and Id with same value + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"AttributeId\" : \"document-id\", " + + "\"Id\" : \"document-id\", " + + "\"Value\" : 123 " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute missing both AttributeId and Id + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Value\" : 123 " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute AttributeId not string + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"AttributeId\" : true, " + + "\"Value\" : 123 " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"AttributeId\" : 123, " + + "\"Value\" : 123 " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute Id not string + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : true, " + + "\"Value\" : 123 " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : 123, " + + "\"Value\" : 123 " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // Category Attribute with DataType + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"integer\", " + + "\"Value\" : 123 " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=123}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute with DataType not string (e.g. "DataType" : 55.5 ) + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : true, " + + "\"Value\" : 123 " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute with unknown DataType + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"no such data type\", " + + "\"Value\" : 123 " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : 321, " + + "\"Value\" : 123 " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute with multiple value array + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"dayTimeDuration\", " + + "\"Value\" : [\"P3D\", \"P2DT12H34M\", \"PT15M\"] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#dayTimeDuration,value={super={durationSign=1years=0months=0days=3hours=0minutes=0seconds=0millis=0},factionalSeconds=0.0}}{dataTypeId=http://www.w3.org/2001/XMLSchema#dayTimeDuration,value={super={durationSign=1years=0months=0days=2hours=12minutes=34seconds=0millis=0},factionalSeconds=0.0}}{dataTypeId=http://www.w3.org/2001/XMLSchema#dayTimeDuration,value={super={durationSign=1years=0months=0days=0hours=0minutes=15seconds=0millis=0},factionalSeconds=0.0}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute multiple value with null in array + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"dayTimeDuration\", " + + "\"Value\" : [\"P3D\", , \"P15M\"] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute with array value with no values ("Attribute": [ {"AttributeId" :"a", Value:[] } ] } ) + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"dayTimeDuration\", " + + "\"Value\" : [ ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute with no DataType and array with no values + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute with Issuer + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Issuer\" : \"University Press\", " + + "\"DataType\" : \"integer\", " + + "\"Value\" : 123 " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=123}],issuer=University Press,includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute with Issuer not string + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Issuer\" : true, " + + "\"DataType\" : \"integer\", " + + "\"Value\" : 123 " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Issuer\" : 4.56, " + + "\"DataType\" : \"integer\", " + + "\"Value\" : 123 " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute with includeInResult=true + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : 123, " + + "\"IncludeInResult\" : true " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=123}],includeInResults=true}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute with includeInResult = false + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : 123, " + + "\"IncludeInResult\" : false " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=123}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute with includeInResult not boolean + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : 123, " + + "\"IncludeInResult\" : \"abc\" " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : 123, " + + "\"IncludeInResult\" : 123.45 " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + } + + + + // Tests related to DataTypes within Attributes + @Test + public void testCategoryAttributesDataTypesSimple() { + + // Category Attribute using full Identifier for each data type + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#string\", " + + "\"Value\" : \"abc\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=abc}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#boolean\", " + + "\"Value\" : true " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#boolean,value=true}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#integer\", " + + "\"Value\" : 123 " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=123}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#double\", " + + "\"Value\" : 123.34 " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=123.34}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#time\", " + + "\"Value\" : \"12:00:00Z\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#time,value=12:00:00Z}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#date\", " + + "\"Value\" : \"2002-10-10\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#date,value=2002-10-10}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#dateTime\", " + + "\"Value\" : \"2002-10-10T12:00:00Z\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#dateTime,value=2002-10-10T12:00:00Z}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#dayTimeDuration\", " + + "\"Value\" : \"P23DT7H12M54S\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#dayTimeDuration,value={super={durationSign=1years=0months=0days=23hours=7minutes=12seconds=54millis=0},factionalSeconds=54.0}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#yearMonthDuration\", " + + "\"Value\" : \"P165Y8M\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#yearMonthDuration,value={super={durationSign=1years=165months=8days=0hours=0minutes=0seconds=0millis=0},monthsDuration=1988}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#anyURI\", " + + "\"Value\" : \"aValue\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#hexBinary\", " + + "\"Value\" : \"FA027B7D12CC34DDD20012AEEF\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#hexBinary,value={data=[-6,2,123,125,18,-52,52,-35,-46,0,18,-82,-17]}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#base64Binary\", " + + "\"Value\" : \"lvbj0iMS4wIj8+PGNhdGFsb2c+PGJvb2sgaWQ9ImJrMTAxIj48YXV0aG9y\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#base64Binary,value={data=[-106,-10,-29,-46,35,18,-29,2,35,-13,-29,-58,54,23,70,22,-58,-10,115,-29,-58,38,-10,-10,-78,6,-106,67,-46,38,38,-77,19,3,18,35,-29,-58,23,87,70,-122,-9]}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name\", " + + "\"Value\" : \"someone.else@A.COMPANY.com\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name,value={localName=someone.else,domainName=A.COMPANY.com}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:1.0:data-type:x500Name\", " + + "\"Value\" : \"cn=Julius Hibbert, o=Medi Corporation, c=US\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:1.0:data-type:x500Name,value=CN=Julius Hibbert, O=Medi Corporation, C=US}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:2.0:data-type:ipAddress\", " + + "\"Value\" : \"10.221.43.58:12345\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:ipAddress,value=10.221.43.58:12345-12345}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:2.0:data-type:dnsName\", " + + "\"Value\" : \"aValue\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:dnsName,value={domainName=aValue}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\", " + + "\"Value\" : {" + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + + "\"Namespaces\" : [" + + "{ "+ + "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + + "}," + + "{" + + "\"Prefix\" : \"md\", " + + "\"Namespace\" : \"urn:example:med:schemas:record\" " + + "}], "+ + "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ + "}" + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression,value={path=md:record/md:patient/md:patientDoB,Namespace={[{md,urn:example:med:schemas:record}{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}]},status=null,xpathExpressionWrapped=null},xpathCategory=urn:oasis:names:tc:xacml:3.0:attribute-category:resource}],includeInResults=false}]}}]}", request.toString()); + + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // Category Attribute shorthand notation for each data type + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"string\", " + + "\"Value\" : \"abc\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=abc}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"boolean\", " + + "\"Value\" : true " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#boolean,value=true}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"integer\", " + + "\"Value\" : 123 " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=123}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"double\", " + + "\"Value\" : 123.34 " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=123.34}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"time\", " + + "\"Value\" : \"12:00:00Z\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#time,value=12:00:00Z}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"date\", " + + "\"Value\" : \"2002-10-10\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#date,value=2002-10-10}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"dateTime\", " + + "\"Value\" : \"2002-10-10T12:00:00Z\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#dateTime,value=2002-10-10T12:00:00Z}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"dayTimeDuration\", " + + "\"Value\" : \"P23DT7H12M54S\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#dayTimeDuration,value={super={durationSign=1years=0months=0days=23hours=7minutes=12seconds=54millis=0},factionalSeconds=54.0}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"yearMonthDuration\", " + + "\"Value\" : \"P165Y8M\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#yearMonthDuration,value={super={durationSign=1years=165months=8days=0hours=0minutes=0seconds=0millis=0},monthsDuration=1988}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"anyURI\", " + + "\"Value\" : \"aValue\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"hexBinary\", " + + "\"Value\" : \"FA027B7D12CC34DDD20012AEEF\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#hexBinary,value={data=[-6,2,123,125,18,-52,52,-35,-46,0,18,-82,-17]}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"base64Binary\", " + + "\"Value\" : \"lvbj0iMS4wIj8+PGNhdGFsb2c+PGJvb2sgaWQ9ImJrMTAxIj48YXV0aG9y\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#base64Binary,value={data=[-106,-10,-29,-46,35,18,-29,2,35,-13,-29,-58,54,23,70,22,-58,-10,115,-29,-58,38,-10,-10,-78,6,-106,67,-46,38,38,-77,19,3,18,35,-29,-58,23,87,70,-122,-9]}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"rfc822Name\", " + + "\"Value\" : \"someone.else@A.COMPANY.com\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name,value={localName=someone.else,domainName=A.COMPANY.com}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"x500Name\", " + + "\"Value\" : \"cn=Julius Hibbert, o=Medi Corporation, c=US\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:1.0:data-type:x500Name,value=CN=Julius Hibbert, O=Medi Corporation, C=US}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"ipAddress\", " + + "\"Value\" : \"10.221.43.58:12345\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:ipAddress,value=10.221.43.58:12345-12345}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"dnsName\", " + + "\"Value\" : \"aValue\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:dnsName,value={domainName=aValue}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"xpathExpression\", " + + "\"Value\" : {" + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + + "\"Namespaces\" : [" + + "{ "+ + "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + + "}," + + "{" + + "\"Prefix\" : \"md\", " + + "\"Namespace\" : \"urn:example:med:schemas:record\" " + + "}], "+ + "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ + "}" + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression,value={path=md:record/md:patient/md:patientDoB,Namespace={[{md,urn:example:med:schemas:record}{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}]},status=null,xpathExpressionWrapped=null},xpathCategory=urn:oasis:names:tc:xacml:3.0:attribute-category:resource}],includeInResults=false}]}}]}", request.toString()); + + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + + // infer data type - only integer, boolean and double are distinguishable from strings; everything else is treated as a string + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"abc\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=abc}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : true " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#boolean,value=true}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : 123 " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=123}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : 123.34 " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=123.34}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"12:00:00Z\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=12:00:00Z}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"2002-10-10\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"2002-10-10T12:00:00Z\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10T12:00:00Z}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"P23DT7H12M54S\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P23DT7H12M54S}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"P165Y8M\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P165Y8M}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"aValue\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"FA027B7D12CC34DDD20012AEEF\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=FA027B7D12CC34DDD20012AEEF}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"lvbj0iMS4wIj8+PGNhdGFsb2c+PGJvb2sgaWQ9ImJrMTAxIj48YXV0aG9y\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=lvbj0iMS4wIj8+PGNhdGFsb2c+PGJvb2sgaWQ9ImJrMTAxIj48YXV0aG9y}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"someone.else@A.COMPANY.com\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=someone.else@A.COMPANY.com}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:1.0:data-type:x500Name\", " + + "\"Value\" : \"cn=Julius Hibbert, o=Medi Corporation, c=US\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:1.0:data-type:x500Name,value=CN=Julius Hibbert, O=Medi Corporation, C=US}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"10.221.43.58:12345\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=10.221.43.58:12345}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"aValue\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"aValue\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : {" + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + + "\"Namespaces\" : [" + + "{ "+ + "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + + "}," + + "{" + + "\"Prefix\" : \"md\", " + + "\"Namespace\" : \"urn:example:med:schemas:record\" " + + "}], "+ + "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ + "}" + + "}] } ] }}"); + // gets inferred to a String containing the whole structure under Value as a String + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value={XPathCategory=urn:oasis:names:tc:xacml:3.0:attribute-category:resource, Namespaces=[{Namespace=urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}, {Prefix=md, Namespace=urn:example:med:schemas:record}], XPath=md:record/md:patient/md:patientDoB}}],includeInResults=false}]}}]}", request.toString()); + + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + } + + + + @Test + public void testCategoryAttributesDataTypesNotMatchValue() { + + // Category Attribute with DataType not matching value type (JSON type derived from syntax) + // AUTO-CONVERSION from Boolean to String! + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#string\", " + + "\"Value\" : true " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=true}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // SUCCESSFUL AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#string\", " + + "\"Value\" : 123 " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=123}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // SUCCESSFUL AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#string\", " + + "\"Value\" : 123.34 " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=123.34}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#boolean\", " + + "\"Value\" : \"abc\" " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#boolean\", " + + "\"Value\" : 123 " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#boolean\", " + + "\"Value\" : 123.45 " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // SUCCESSFUL AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#integer\", " + + "\"Value\" : \"123\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=123}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#integer\", " + + "\"Value\" : true " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#integer\", " + + "\"Value\" : 123.45 " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // SUCCESSFUL AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#double\", " + + "\"Value\" : \"123.34\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=123.34}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#double\", " + + "\"Value\" : true " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // allow integer to auto-convert to double when DataType is given + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#double\", " + + "\"Value\" : 123 " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=123.0}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // special JavaScript values not allowed except for -0 (inappropriate requirement in spec - check it anyway) + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#integer\", " + + "\"Value\" : \"NaN\" " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#integer\", " + + "\"Value\" : \"INF\" " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#integer\", " + + "\"Value\" : \"-INF\" " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // JavaScript 0 and -0 are ok + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#integer\", " + + "\"Value\" : 0 " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=0}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#integer\", " + + "\"Value\" : -0 " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=0}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // All other data types are checked when we convert internally, so value must be syntactically correct + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#time\", " + + "\"Value\" : \"syntactically incorrect value\" " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#date\", " + + "\"Value\" : \"syntactically incorrect value\" " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#dateTime\", " + + "\"Value\" : \"syntactically incorrect value\" " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#dayTimeDuration\", " + + "\"Value\" : \"syntactically incorrect value\" " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#yearMonthDuration\", " + + "\"Value\" : \"syntactically incorrect value\" " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#anyURI\", " + + "\"Value\" : \"syntactically incorrect value\" " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#hexBinary\", " + + "\"Value\" : \"syntactically incorrect value\" " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Base64 convert does not throw an exception if the contents are not Base64, so cannot test for this. + // Any problem with the data will have to be discovered later when the data is used. + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name\", " + + "\"Value\" : \"syntactically incorrect value\" " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:1.0:data-type:x500Name\", " + + "\"Value\" : \"syntactically incorrect value\" " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:2.0:data-type:ipAddress\", " + + "\"Value\" : \"syntactically incorrect value\" " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:2.0:data-type:dnsName\", " + + "\"Value\" : \"syntactically incorrect value\" " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // Cannot test XPathExpressions here. The XPathExpression gets converted into a simple String value within the XPathExpression object, + // but it is not evaluated or compiled at that time. Therefore we do not know whether or not the value is valid until it is used in a computation. + + } + + + @Test + public void testArrayDataTypes() { + + // array of size 0 + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#string\", " + + "\"Value\" : [] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // Category Attribute value array DataType given (repeat for all data types) + // Category Attribute using full Identifier for each data type + // Category Attribute shorthand notation for each data type + // Also tests for mixes of different JSON types (trying incorrect strings for XACML data types whenever possible) + // string + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#string\", " + + "\"Value\" : [\"abc\", \"def\", \"hig\", \"lmn\"] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=abc}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=def}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=hig}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=lmn}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"string\", " + + "\"Value\" : [\"abc\", \"def\", \"hig\", \"lmn\"] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=abc}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=def}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=hig}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=lmn}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // SUCCESSFUL AUTO-CONVERT to DataType + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#string\", " + + "\"Value\" : [\"abc\", true, \"hig\", \"lmn\"] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=abc}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=hig}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=lmn}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // SUCCESSFUL AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#string\", " + + "\"Value\" : [\"abc\",123, \"hig\", \"lmn\"] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=abc}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=123}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=hig}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=lmn}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // SUCCESSFUL AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#string\", " + + "\"Value\" : [\"abc\", 34.34, \"hig\", \"lmn\"] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=abc}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=34.34}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=hig}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=lmn}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // boolean + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#boolean\", " + + "\"Value\" : [true, true, false, true, false ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#boolean,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#boolean,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#boolean,value=false}{dataTypeId=http://www.w3.org/2001/XMLSchema#boolean,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#boolean,value=false}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"boolean\", " + + "\"Value\" : [true, true, false, true, false ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#boolean,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#boolean,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#boolean,value=false}{dataTypeId=http://www.w3.org/2001/XMLSchema#boolean,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#boolean,value=false}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#boolean\", " + + "\"Value\" : [true, \"abc\", false, true, false ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#boolean\", " + + "\"Value\" : [true, 123, false, true, false ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#boolean\", " + + "\"Value\" : [true, 12.34, false, true, false ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + + // integer + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#integer\", " + + "\"Value\" : [123, 456, 765, 234] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=123}{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=456}{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=765}{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=234}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"integer\", " + + "\"Value\" : [123, 456, 765, 234] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=123}{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=456}{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=765}{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=234}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#integer\", " + + "\"Value\" : [123, \"abc\", 765, 234] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#integer\", " + + "\"Value\" : [123, true, 765, 234] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#integer\", " + + "\"Value\" : [123, 34.56, 765, 234] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // double + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#double\", " + + "\"Value\" : [ 123.34, 543.54, 3445.455, 4543,543 ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=123.34}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=543.54}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=3445.455}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=4543.0}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=543.0}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"double\", " + + "\"Value\" : [ 123.34, 543.54, 3445.455, 4543,543 ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=123.34}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=543.54}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=3445.455}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=4543.0}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=543.0}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // special case - auto-convert integer to boolean + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#double\", " + + "\"Value\" : [ 123.34, 111122, 3445.455, 4543,543 ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=123.34}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=111122.0}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=3445.455}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=4543.0}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=543.0}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#double\", " + + "\"Value\" : [ 123.34, true, 3445.455, 4543,543 ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#double\", " + + "\"Value\" : [ 123.34, \"abb\", 3445.455, 4543,543 ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // time + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#time\", " + + "\"Value\" : [ \"12:00:00Z\", \"12:00:00Z\", \"12:00:00Z\"] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#time,value=12:00:00Z}{dataTypeId=http://www.w3.org/2001/XMLSchema#time,value=12:00:00Z}{dataTypeId=http://www.w3.org/2001/XMLSchema#time,value=12:00:00Z}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"time\", " + + "\"Value\" : [ \"12:00:00Z\", \"12:00:00Z\", \"12:00:00Z\"] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#time,value=12:00:00Z}{dataTypeId=http://www.w3.org/2001/XMLSchema#time,value=12:00:00Z}{dataTypeId=http://www.w3.org/2001/XMLSchema#time,value=12:00:00Z}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#time\", " + + "\"Value\" : [ \"12:00:00Z\", \"not a time\", \"12:00:00Z\"] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#time\", " + + "\"Value\" : [ \"12:00:00Z\", true, \"12:00:00Z\"] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#time\", " + + "\"Value\" : [ \"12:00:00Z\", 123, \"12:00:00Z\"] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#time\", " + + "\"Value\" : [ \"12:00:00Z\", 12.34, \"12:00:00Z\"] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // date + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#date\", " + + "\"Value\" : [\"2002-10-10\",\"2002-10-10\",\"2002-10-10\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#date,value=2002-10-10}{dataTypeId=http://www.w3.org/2001/XMLSchema#date,value=2002-10-10}{dataTypeId=http://www.w3.org/2001/XMLSchema#date,value=2002-10-10}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"date\", " + + "\"Value\" : [\"2002-10-10\",\"2002-10-10\",\"2002-10-10\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#date,value=2002-10-10}{dataTypeId=http://www.w3.org/2001/XMLSchema#date,value=2002-10-10}{dataTypeId=http://www.w3.org/2001/XMLSchema#date,value=2002-10-10}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#date\", " + + "\"Value\" : [\"2002-10-10\",\"not a date\",\"2002-10-10\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#date\", " + + "\"Value\" : [\"2002-10-10\",true,\"2002-10-10\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#date\", " + + "\"Value\" : [\"2002-10-10\",123,\"2002-10-10\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#date\", " + + "\"Value\" : [\"2002-10-10\",123.45,\"2002-10-10\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // dateTime + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#dateTime\", " + + "\"Value\" : [ \"2002-10-10T12:00:00Z\",\"2002-10-10T12:00:00Z\",\"2002-10-10T12:00:00Z\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#dateTime,value=2002-10-10T12:00:00Z}{dataTypeId=http://www.w3.org/2001/XMLSchema#dateTime,value=2002-10-10T12:00:00Z}{dataTypeId=http://www.w3.org/2001/XMLSchema#dateTime,value=2002-10-10T12:00:00Z}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"dateTime\", " + + "\"Value\" : [ \"2002-10-10T12:00:00Z\",\"2002-10-10T12:00:00Z\",\"2002-10-10T12:00:00Z\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#dateTime,value=2002-10-10T12:00:00Z}{dataTypeId=http://www.w3.org/2001/XMLSchema#dateTime,value=2002-10-10T12:00:00Z}{dataTypeId=http://www.w3.org/2001/XMLSchema#dateTime,value=2002-10-10T12:00:00Z}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#dateTime\", " + + "\"Value\" : [ \"2002-10-10T12:00:00Z\",\"not a dateTime\",\"2002-10-10T12:00:00Z\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#dateTime\", " + + "\"Value\" : [ \"2002-10-10T12:00:00Z\",true,\"2002-10-10T12:00:00Z\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#dateTime\", " + + "\"Value\" : [ \"2002-10-10T12:00:00Z\",123,\"2002-10-10T12:00:00Z\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#dateTime\", " + + "\"Value\" : [ \"2002-10-10T12:00:00Z\",12.34,\"2002-10-10T12:00:00Z\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // dayTimeDuration + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#dayTimeDuration\", " + + "\"Value\" : [ \"P23DT7H12M54S\",\"P23DT7H12M54S\",\"P23DT7H12M54S\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#dayTimeDuration,value={super={durationSign=1years=0months=0days=23hours=7minutes=12seconds=54millis=0},factionalSeconds=54.0}}{dataTypeId=http://www.w3.org/2001/XMLSchema#dayTimeDuration,value={super={durationSign=1years=0months=0days=23hours=7minutes=12seconds=54millis=0},factionalSeconds=54.0}}{dataTypeId=http://www.w3.org/2001/XMLSchema#dayTimeDuration,value={super={durationSign=1years=0months=0days=23hours=7minutes=12seconds=54millis=0},factionalSeconds=54.0}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"dayTimeDuration\", " + + "\"Value\" : [ \"P23DT7H12M54S\",\"P23DT7H12M54S\",\"P23DT7H12M54S\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#dayTimeDuration,value={super={durationSign=1years=0months=0days=23hours=7minutes=12seconds=54millis=0},factionalSeconds=54.0}}{dataTypeId=http://www.w3.org/2001/XMLSchema#dayTimeDuration,value={super={durationSign=1years=0months=0days=23hours=7minutes=12seconds=54millis=0},factionalSeconds=54.0}}{dataTypeId=http://www.w3.org/2001/XMLSchema#dayTimeDuration,value={super={durationSign=1years=0months=0days=23hours=7minutes=12seconds=54millis=0},factionalSeconds=54.0}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#dayTimeDuration\", " + + "\"Value\" : [ \"P23DT7H12M54S\",\"not a duration\",\"P23DT7H12M54S\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#dayTimeDuration\", " + + "\"Value\" : [ \"P23DT7H12M54S\",true,\"P23DT7H12M54S\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#dayTimeDuration\", " + + "\"Value\" : [ \"P23DT7H12M54S\",123,\"P23DT7H12M54S\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#dayTimeDuration\", " + + "\"Value\" : [ \"P23DT7H12M54S\",11.22,\"P23DT7H12M54S\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // yearMonth duration + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#yearMonthDuration\", " + + "\"Value\" : [ \"P165Y8M\",\"P165Y8M\",\"P165Y8M\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#yearMonthDuration,value={super={durationSign=1years=165months=8days=0hours=0minutes=0seconds=0millis=0},monthsDuration=1988}}{dataTypeId=http://www.w3.org/2001/XMLSchema#yearMonthDuration,value={super={durationSign=1years=165months=8days=0hours=0minutes=0seconds=0millis=0},monthsDuration=1988}}{dataTypeId=http://www.w3.org/2001/XMLSchema#yearMonthDuration,value={super={durationSign=1years=165months=8days=0hours=0minutes=0seconds=0millis=0},monthsDuration=1988}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"yearMonthDuration\", " + + "\"Value\" : [ \"P165Y8M\",\"P165Y8M\",\"P165Y8M\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#yearMonthDuration,value={super={durationSign=1years=165months=8days=0hours=0minutes=0seconds=0millis=0},monthsDuration=1988}}{dataTypeId=http://www.w3.org/2001/XMLSchema#yearMonthDuration,value={super={durationSign=1years=165months=8days=0hours=0minutes=0seconds=0millis=0},monthsDuration=1988}}{dataTypeId=http://www.w3.org/2001/XMLSchema#yearMonthDuration,value={super={durationSign=1years=165months=8days=0hours=0minutes=0seconds=0millis=0},monthsDuration=1988}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#yearMonthDuration\", " + + "\"Value\" : [ \"P165Y8M\",\"not a duration\",\"P165Y8M\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#yearMonthDuration\", " + + "\"Value\" : [ \"P165Y8M\",true,\"P165Y8M\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#yearMonthDuration\", " + + "\"Value\" : [ \"P165Y8M\",123,\"P165Y8M\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#yearMonthDuration\", " + + "\"Value\" : [ \"P165Y8M\",11.22,\"P165Y8M\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // anyURI + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#anyURI\", " + + "\"Value\" : [ \"aValue\",\"aValue\",\"aValue\"] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"anyURI\", " + + "\"Value\" : [ \"aValue\",\"aValue\",\"aValue\"] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // SUCCESSFUL AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#anyURI\", " + + "\"Value\" : [ \"aValue\",true,\"aValue\"] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // SUCCESSFUL AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#anyURI\", " + + "\"Value\" : [ \"aValue\",123,\"aValue\"] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=123}{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#anyURI\", " + + "\"Value\" : [ \"aValue\",11.111,\"aValue\"] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=11.111}{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // hexBinary + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#hexBinary\", " + + "\"Value\" : [ \"FA027B7D12CC34DDD20012AEEF\",\"FA027B7D12CC34DDD20012AEEF\",\"FA027B7D12CC34DDD20012AEEF\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#hexBinary,value={data=[-6,2,123,125,18,-52,52,-35,-46,0,18,-82,-17]}}{dataTypeId=http://www.w3.org/2001/XMLSchema#hexBinary,value={data=[-6,2,123,125,18,-52,52,-35,-46,0,18,-82,-17]}}{dataTypeId=http://www.w3.org/2001/XMLSchema#hexBinary,value={data=[-6,2,123,125,18,-52,52,-35,-46,0,18,-82,-17]}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"hexBinary\", " + + "\"Value\" : [ \"FA027B7D12CC34DDD20012AEEF\",\"FA027B7D12CC34DDD20012AEEF\",\"FA027B7D12CC34DDD20012AEEF\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#hexBinary,value={data=[-6,2,123,125,18,-52,52,-35,-46,0,18,-82,-17]}}{dataTypeId=http://www.w3.org/2001/XMLSchema#hexBinary,value={data=[-6,2,123,125,18,-52,52,-35,-46,0,18,-82,-17]}}{dataTypeId=http://www.w3.org/2001/XMLSchema#hexBinary,value={data=[-6,2,123,125,18,-52,52,-35,-46,0,18,-82,-17]}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#hexBinary\", " + + "\"Value\" : [ \"FA027B7D12CC34DDD20012AEEF\",true,\"012AEEF\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#hexBinary\", " + + "\"Value\" : [ \"FA027B7D12CC34DDD20012AEEF\",123,\"012AEEF\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#hexBinary\", " + + "\"Value\" : [ \"FA027B7D12CC34DDD20012AEEF\",11.44,\"012AEEF\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // base64Binary + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#base64Binary\", " + + "\"Value\" : [ \"aG9y\",\"lvbj0iMS4xIj48YXV0aG9y\",\"lvbjIj48YXV0aG9y\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#base64Binary,value={data=[104,111,114]}}{dataTypeId=http://www.w3.org/2001/XMLSchema#base64Binary,value={data=[-106,-10,-29,-46,35,18,-29,18,35,-29,-58,23,87,70,-122,-9]}}{dataTypeId=http://www.w3.org/2001/XMLSchema#base64Binary,value={data=[-106,-10,-29,34,62,60,97,117,116,104,111,114]}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"base64Binary\", " + + "\"Value\" : [ \"aG9y\",\"lvbj0iMS4xIj48YXV0aG9y\",\"lvbjIj48YXV0aG9y\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#base64Binary,value={data=[104,111,114]}}{dataTypeId=http://www.w3.org/2001/XMLSchema#base64Binary,value={data=[-106,-10,-29,-46,35,18,-29,18,35,-29,-58,23,87,70,-122,-9]}}{dataTypeId=http://www.w3.org/2001/XMLSchema#base64Binary,value={data=[-106,-10,-29,34,62,60,97,117,116,104,111,114]}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#base64Binary\", " + + "\"Value\" : [ \"aG9y\",true,\"lvbjIj48YXV0aG9y\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#base64Binary,value={data=[104,111,114]}}{dataTypeId=http://www.w3.org/2001/XMLSchema#base64Binary,value={data=[-74,-69,-98]}}{dataTypeId=http://www.w3.org/2001/XMLSchema#base64Binary,value={data=[-106,-10,-29,34,62,60,97,117,116,104,111,114]}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#base64Binary\", " + + "\"Value\" : [ \"aG9y\",1123,\"lvbjIj48YXV0aG9y\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#base64Binary,value={data=[104,111,114]}}{dataTypeId=http://www.w3.org/2001/XMLSchema#base64Binary,value={data=[-41,93,-73]}}{dataTypeId=http://www.w3.org/2001/XMLSchema#base64Binary,value={data=[-106,-10,-29,34,62,60,97,117,116,104,111,114]}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#base64Binary\", " + + "\"Value\" : [ \"aG9y\",11.22,\"lvbjIj48YXV0aG9y\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#base64Binary,value={data=[104,111,114]}}{dataTypeId=http://www.w3.org/2001/XMLSchema#base64Binary,value={data=[-41,93,-74]}}{dataTypeId=http://www.w3.org/2001/XMLSchema#base64Binary,value={data=[-106,-10,-29,34,62,60,97,117,116,104,111,114]}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // RFC822 name + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name\", " + + "\"Value\" : [ \"sne.else@A.COMPANY.com\",\"one.else@A.COMPANY.com\",\"someone.else@A.CONY.com\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name,value={localName=sne.else,domainName=A.COMPANY.com}}{dataTypeId=urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name,value={localName=one.else,domainName=A.COMPANY.com}}{dataTypeId=urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name,value={localName=someone.else,domainName=A.CONY.com}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"rfc822Name\", " + + "\"Value\" : [ \"sne.else@A.COMPANY.com\",\"one.else@A.COMPANY.com\",\"someone.else@A.CONY.com\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name,value={localName=sne.else,domainName=A.COMPANY.com}}{dataTypeId=urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name,value={localName=one.else,domainName=A.COMPANY.com}}{dataTypeId=urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name,value={localName=someone.else,domainName=A.CONY.com}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name\", " + + "\"Value\" : [ \"sne.else@A.COMPANY.com\",\"not a dns\",\"someone.else@A.CONY.com\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name\", " + + "\"Value\" : [ \"sne.else@A.COMPANY.com\",true,\"someone.else@A.CONY.com\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name\", " + + "\"Value\" : [ \"sne.else@A.COMPANY.com\",111,\"someone.else@A.CONY.com\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name\", " + + "\"Value\" : [ \"sne.else@A.COMPANY.com\",11.22,\"someone.else@A.CONY.com\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // x500 + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:1.0:data-type:x500Name\", " + + "\"Value\" : [ \"cn=Julius Hibbert, o=Medi Corporation, c=US\", \"cn=Julius Hibbert, o=Medi Corporation, c=US\", \"cn=Julius Hibbert, o=Medi Corporation, c=US\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:1.0:data-type:x500Name,value=CN=Julius Hibbert, O=Medi Corporation, C=US}{dataTypeId=urn:oasis:names:tc:xacml:1.0:data-type:x500Name,value=CN=Julius Hibbert, O=Medi Corporation, C=US}{dataTypeId=urn:oasis:names:tc:xacml:1.0:data-type:x500Name,value=CN=Julius Hibbert, O=Medi Corporation, C=US}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"x500Name\", " + + "\"Value\" : [ \"cn=Julius Hibbert, o=Medi Corporation, c=US\", \"cn=Julius Hibbert, o=Medi Corporation, c=US\", \"cn=Julius Hibbert, o=Medi Corporation, c=US\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:1.0:data-type:x500Name,value=CN=Julius Hibbert, O=Medi Corporation, C=US}{dataTypeId=urn:oasis:names:tc:xacml:1.0:data-type:x500Name,value=CN=Julius Hibbert, O=Medi Corporation, C=US}{dataTypeId=urn:oasis:names:tc:xacml:1.0:data-type:x500Name,value=CN=Julius Hibbert, O=Medi Corporation, C=US}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:1.0:data-type:x500Name\", " + + "\"Value\" : [ \"cn=Julius Hibbert, o=Medi Corporation, c=US\", \"non-x500 string\", \"cn=Julius Hibbert, o=Medi Corporation, c=US\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:1.0:data-type:x500Name\", " + + "\"Value\" : [ \"cn=Julius Hibbert, o=Medi Corporation, c=US\", true, \"cn=Julius Hibbert, o=Medi Corporation, c=US\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:1.0:data-type:x500Name\", " + + "\"Value\" : [ \"cn=Julius Hibbert, o=Medi Corporation, c=US\", 1111, \"cn=Julius Hibbert, o=Medi Corporation, c=US\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:1.0:data-type:x500Name\", " + + "\"Value\" : [ \"cn=Julius Hibbert, o=Medi Corporation, c=US\", 11.22, \"cn=Julius Hibbert, o=Medi Corporation, c=US\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // ipAddress + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:2.0:data-type:ipAddress\", " + + "\"Value\" : [ \"10.221.43.58:12345\",\"10.221.43.58:12345\",\"10.221.43.58:12345\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:ipAddress,value=10.221.43.58:12345-12345}{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:ipAddress,value=10.221.43.58:12345-12345}{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:ipAddress,value=10.221.43.58:12345-12345}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"ipAddress\", " + + "\"Value\" : [ \"10.221.43.58:12345\",\"10.221.43.58:12345\",\"10.221.43.58:12345\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:ipAddress,value=10.221.43.58:12345-12345}{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:ipAddress,value=10.221.43.58:12345-12345}{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:ipAddress,value=10.221.43.58:12345-12345}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:2.0:data-type:ipAddress\", " + + "\"Value\" : [ \"10.221.43.58:12345\",\"not an ip address\",\"10.221.43.58:12345\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:2.0:data-type:ipAddress\", " + + "\"Value\" : [ \"10.221.43.58:12345\",true,\"10.221.43.58:12345\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:2.0:data-type:ipAddress\", " + + "\"Value\" : [ \"10.221.43.58:12345\",1111,\"10.221.43.58:12345\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:2.0:data-type:ipAddress\", " + + "\"Value\" : [ \"10.221.43.58:12345\",11.22,\"10.221.43.58:12345\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // dnsName + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:2.0:data-type:dnsName\", " + + "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:dnsName,value={domainName=aValue}}{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:dnsName,value={domainName=aValue}}{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:dnsName,value={domainName=aValue}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"dnsName\", " + + "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:dnsName,value={domainName=aValue}}{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:dnsName,value={domainName=aValue}}{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:dnsName,value={domainName=aValue}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:2.0:data-type:dnsName\", " + + "\"Value\" : [ \"aValue\", true, \"aValue\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:dnsName,value={domainName=aValue}}{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:dnsName,value={domainName=true}}{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:dnsName,value={domainName=aValue}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:2.0:data-type:dnsName\", " + + "\"Value\" : [ \"aValue\", 1111, \"aValue\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:2.0:data-type:dnsName\", " + + "\"Value\" : [ \"aValue\", 11.22, \"aValue\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // xPathExpression + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\", " + + "\"Value\" : [ " + + "{" + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + + "\"Namespaces\" : [" + + "{ "+ + "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + + "}," + + "{" + + "\"Prefix\" : \"md\", " + + "\"Namespace\" : \"urn:example:med:schemas:record\" " + + "}], "+ + "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ + "}," + + "{" + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + + "\"Namespaces\" : [" + + "{ "+ + "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + + "}," + + "{" + + "\"Prefix\" : \"md\", " + + "\"Namespace\" : \"urn:example:med:schemas:record\" " + + "}], "+ + "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ + "}," + + "{" + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + + "\"Namespaces\" : [" + + "{ "+ + "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + + "}," + + "{" + + "\"Prefix\" : \"md\", " + + "\"Namespace\" : \"urn:example:med:schemas:record\" " + + "}], "+ + "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ + "}" + + "] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression,value={path=md:record/md:patient/md:patientDoB,Namespace={[{md,urn:example:med:schemas:record}{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}]},status=null,xpathExpressionWrapped=null},xpathCategory=urn:oasis:names:tc:xacml:3.0:attribute-category:resource}{dataTypeId=urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression,value={path=md:record/md:patient/md:patientDoB,Namespace={[{md,urn:example:med:schemas:record}{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}]},status=null,xpathExpressionWrapped=null},xpathCategory=urn:oasis:names:tc:xacml:3.0:attribute-category:resource}{dataTypeId=urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression,value={path=md:record/md:patient/md:patientDoB,Namespace={[{md,urn:example:med:schemas:record}{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}]},status=null,xpathExpressionWrapped=null},xpathCategory=urn:oasis:names:tc:xacml:3.0:attribute-category:resource}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\", " + + "\"Value\" : [ " + + "{" + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + + "\"Namespaces\" : [" + + "{ "+ + "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + + "}," + + "{" + + "\"Prefix\" : \"md\", " + + "\"Namespace\" : \"urn:example:med:schemas:record\" " + + "}], "+ + "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ + "}," + + "\"simpleString\"," + + "{" + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + + "\"Namespaces\" : [" + + "{ "+ + "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + + "}," + + "{" + + "\"Prefix\" : \"md\", " + + "\"Namespace\" : \"urn:example:med:schemas:record\" " + + "}], "+ + "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ + "}" + + "] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\", " + + "\"Value\" : [ " + + "{" + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + + "\"Namespaces\" : [" + + "{ "+ + "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + + "}," + + "{" + + "\"Prefix\" : \"md\", " + + "\"Namespace\" : \"urn:example:med:schemas:record\" " + + "}], "+ + "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ + "}," + + "true," + + "{" + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + + "\"Namespaces\" : [" + + "{ "+ + "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + + "}," + + "{" + + "\"Prefix\" : \"md\", " + + "\"Namespace\" : \"urn:example:med:schemas:record\" " + + "}], "+ + "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ + "}" + + "] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\", " + + "\"Value\" : [ " + + "{" + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + + "\"Namespaces\" : [" + + "{ "+ + "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + + "}," + + "{" + + "\"Prefix\" : \"md\", " + + "\"Namespace\" : \"urn:example:med:schemas:record\" " + + "}], "+ + "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ + "}," + + "123," + + "{" + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + + "\"Namespaces\" : [" + + "{ "+ + "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + + "}," + + "{" + + "\"Prefix\" : \"md\", " + + "\"Namespace\" : \"urn:example:med:schemas:record\" " + + "}], "+ + "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ + "}" + + "] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\", " + + "\"Value\" : [ " + + "{" + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + + "\"Namespaces\" : [" + + "{ "+ + "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + + "}," + + "{" + + "\"Prefix\" : \"md\", " + + "\"Namespace\" : \"urn:example:med:schemas:record\" " + + "}], "+ + "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ + "}," + + "12.34," + + "{" + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + + "\"Namespaces\" : [" + + "{ "+ + "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + + "}," + + "{" + + "\"Prefix\" : \"md\", " + + "\"Namespace\" : \"urn:example:med:schemas:record\" " + + "}], "+ + "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ + "}" + + "] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + } + + + + + + + + @Test + public void testArrayNoDataTypes() { + + // array of size 0 + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // Category Attribute value array DataType Not given (repeat for all data types) + // Also tests for mixes of different JSON types (trying incorrect strings for XACML data types whenever possible) + // string + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [\"abc\", \"def\", \"hig\", \"lmn\"] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=abc}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=def}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=hig}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=lmn}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // SUCCESSFUL AUTO-CONVERT to DataType + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [\"abc\", true, \"hig\", \"lmn\"] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=abc}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=hig}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=lmn}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // SUCCESSFUL AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [\"abc\",123, \"hig\", \"lmn\"] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=abc}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=123}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=hig}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=lmn}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // SUCCESSFUL AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [\"abc\", 34.34, \"hig\", \"lmn\"] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=abc}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=34.34}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=hig}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=lmn}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // boolean + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [true, true, false, true, false ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#boolean,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#boolean,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#boolean,value=false}{dataTypeId=http://www.w3.org/2001/XMLSchema#boolean,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#boolean,value=false}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [true, \"abc\", false, true, false ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [true, 123, false, true, false ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [true, 12.34, false, true, false ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + + // integer + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [123, 456, 765, 234] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=123}{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=456}{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=765}{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=234}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [123, \"abc\", 765, 234] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [123, true, 765, 234] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + + // double + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ 123.34, 543.54, 3445.455, 4543,543 ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=123.34}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=543.54}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=3445.455}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=4543.0}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=543.0}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // special case - auto-convert integer to boolean + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ 123.34, 111122, 3445.455, 4543,543 ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=123.34}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=111122.0}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=3445.455}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=4543.0}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=543.0}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ 123.34, true, 3445.455, 4543,543 ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ 123.34, \"abb\", 3445.455, 4543,543 ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // time - defaults to String + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"12:00:00Z\", \"12:00:00Z\", \"12:00:00Z\"] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=12:00:00Z}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=12:00:00Z}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=12:00:00Z}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // SUCCESSFUL AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"12:00:00Z\", true, \"12:00:00Z\"] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=12:00:00Z}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=12:00:00Z}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // SUCCESSFUL AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"12:00:00Z\", 123, \"12:00:00Z\"] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=12:00:00Z}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=123}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=12:00:00Z}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"12:00:00Z\", 12.34, \"12:00:00Z\"] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=12:00:00Z}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=12.34}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=12:00:00Z}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // date - defaults to String + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [\"2002-10-10\",\"2002-10-10\",\"2002-10-10\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [\"2002-10-10\",true,\"2002-10-10\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [\"2002-10-10\",123,\"2002-10-10\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=123}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [\"2002-10-10\",123.45,\"2002-10-10\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=123.45}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // dateTime - defaults to String + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"2002-10-10T12:00:00Z\",\"2002-10-10T12:00:00Z\",\"2002-10-10T12:00:00Z\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10T12:00:00Z}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10T12:00:00Z}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10T12:00:00Z}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"2002-10-10T12:00:00Z\",true,\"2002-10-10T12:00:00Z\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10T12:00:00Z}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10T12:00:00Z}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"2002-10-10T12:00:00Z\",123,\"2002-10-10T12:00:00Z\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10T12:00:00Z}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=123}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10T12:00:00Z}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"2002-10-10T12:00:00Z\",12.34,\"2002-10-10T12:00:00Z\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10T12:00:00Z}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=12.34}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10T12:00:00Z}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // dayTimeDuration - defaults to String + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"P23DT7H12M54S\",\"P23DT7H12M54S\",\"P23DT7H12M54S\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P23DT7H12M54S}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P23DT7H12M54S}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P23DT7H12M54S}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + //AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"P23DT7H12M54S\",true,\"P23DT7H12M54S\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P23DT7H12M54S}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P23DT7H12M54S}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"P23DT7H12M54S\",123,\"P23DT7H12M54S\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P23DT7H12M54S}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=123}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P23DT7H12M54S}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"P23DT7H12M54S\",11.22,\"P23DT7H12M54S\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P23DT7H12M54S}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=11.22}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P23DT7H12M54S}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // yearMonth duration - defaults to String + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"P165Y8M\",\"P165Y8M\",\"P165Y8M\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P165Y8M}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P165Y8M}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P165Y8M}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"P165Y8M\",true,\"P165Y8M\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P165Y8M}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P165Y8M}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"P165Y8M\",123,\"P165Y8M\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P165Y8M}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=123}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P165Y8M}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"P165Y8M\",11.22,\"P165Y8M\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P165Y8M}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=11.22}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P165Y8M}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // anyURI - defaults to String + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\",\"aValue\",\"aValue\"] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\",true,\"aValue\"] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\",123,\"aValue\"] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=123}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\",11.111,\"aValue\"] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=11.111}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // hexBinary - defaults to String + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"FA027B7D12CC34DDD20012AEEF\",\"FA027B7D12CC34DDD20012AEEF\",\"FA027B7D12CC34DDD20012AEEF\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=FA027B7D12CC34DDD20012AEEF}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=FA027B7D12CC34DDD20012AEEF}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=FA027B7D12CC34DDD20012AEEF}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"FA027B7D12CC34DDD20012AEEF\",true,\"012AEEF\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=FA027B7D12CC34DDD20012AEEF}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=012AEEF}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"FA027B7D12CC34DDD20012AEEF\",123,\"012AEEF\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=FA027B7D12CC34DDD20012AEEF}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=123}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=012AEEF}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"FA027B7D12CC34DDD20012AEEF\",11.44,\"012AEEF\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=FA027B7D12CC34DDD20012AEEF}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=11.44}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=012AEEF}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // base64Binary - defaults to String + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aG9y\",\"lvbj0iMS4xIj48YXV0aG9y\",\"lvbjIj48YXV0aG9y\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aG9y}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=lvbj0iMS4xIj48YXV0aG9y}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=lvbjIj48YXV0aG9y}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aG9y\",true,\"lvbjIj48YXV0aG9y\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aG9y}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=lvbjIj48YXV0aG9y}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aG9y\",1123,\"lvbjIj48YXV0aG9y\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aG9y}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=1123}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=lvbjIj48YXV0aG9y}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aG9y\",11.22,\"lvbjIj48YXV0aG9y\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aG9y}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=11.22}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=lvbjIj48YXV0aG9y}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // RFC822 name - defaults to String + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"sne.else@A.COMPANY.com\",\"one.else@A.COMPANY.com\",\"someone.else@A.CONY.com\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=sne.else@A.COMPANY.com}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=one.else@A.COMPANY.com}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=someone.else@A.CONY.com}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"sne.else@A.COMPANY.com\",true,\"someone.else@A.CONY.com\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=sne.else@A.COMPANY.com}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=someone.else@A.CONY.com}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"sne.else@A.COMPANY.com\",111,\"someone.else@A.CONY.com\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=sne.else@A.COMPANY.com}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=111}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=someone.else@A.CONY.com}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"sne.else@A.COMPANY.com\",11.22,\"someone.else@A.CONY.com\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=sne.else@A.COMPANY.com}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=11.22}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=someone.else@A.CONY.com}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // x500 - defaults to String + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"cn=Julius Hibbert, o=Medi Corporation, c=US\", \"cn=Julius Hibbert, o=Medi Corporation, c=US\", \"cn=Julius Hibbert, o=Medi Corporation, c=US\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=cn=Julius Hibbert, o=Medi Corporation, c=US}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=cn=Julius Hibbert, o=Medi Corporation, c=US}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=cn=Julius Hibbert, o=Medi Corporation, c=US}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"cn=Julius Hibbert, o=Medi Corporation, c=US\", true, \"cn=Julius Hibbert, o=Medi Corporation, c=US\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=cn=Julius Hibbert, o=Medi Corporation, c=US}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=cn=Julius Hibbert, o=Medi Corporation, c=US}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"cn=Julius Hibbert, o=Medi Corporation, c=US\", 1111, \"cn=Julius Hibbert, o=Medi Corporation, c=US\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=cn=Julius Hibbert, o=Medi Corporation, c=US}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=1111}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=cn=Julius Hibbert, o=Medi Corporation, c=US}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"cn=Julius Hibbert, o=Medi Corporation, c=US\", 11.22, \"cn=Julius Hibbert, o=Medi Corporation, c=US\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=cn=Julius Hibbert, o=Medi Corporation, c=US}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=11.22}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=cn=Julius Hibbert, o=Medi Corporation, c=US}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // ipAddress - defaults to String + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"10.221.43.58:12345\",\"10.221.43.58:12345\",\"10.221.43.58:12345\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=10.221.43.58:12345}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=10.221.43.58:12345}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=10.221.43.58:12345}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"10.221.43.58:12345\",true,\"10.221.43.58:12345\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=10.221.43.58:12345}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=10.221.43.58:12345}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"10.221.43.58:12345\",1111,\"10.221.43.58:12345\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=10.221.43.58:12345}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=1111}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=10.221.43.58:12345}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"10.221.43.58:12345\",11.22,\"10.221.43.58:12345\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=10.221.43.58:12345}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=11.22}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=10.221.43.58:12345}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // dnsName - defaults to String + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\", true, \"aValue\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\", 1111, \"aValue\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=1111}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\", 11.22, \"aValue\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=11.22}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // xPathExpression - defaults to String + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\", true, \"aValue\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\", 1111, \"aValue\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=1111}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\", 11.22, \"aValue\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=11.22}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + } + + + + + @Test + public void testXPathExpression() { + // Category Attribute with XPathExpression including XPathCategory and XPath + // Category Attribute with XPathExpression with Namespaces with/without Prefix + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"xpathExpression\", " + + "\"Value\" : {" + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + + "\"Namespaces\" : [" + + "{ "+ + "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + + "}," + + "{ "+ + "\"Prefix\" : \"lab\", " + + "\"Namespace\" : \"http://somewhere/uri.html\" " + + "}," + + "{" + + "\"Prefix\" : \"md\", " + + "\"Namespace\" : \"urn:example:med:schemas:record\" " + + "}], "+ + "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ + "}" + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression,value={path=md:record/md:patient/md:patientDoB,Namespace={[{md,urn:example:med:schemas:record}{lab,http://somewhere/uri.html}{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}]},status=null,xpathExpressionWrapped=null},xpathCategory=urn:oasis:names:tc:xacml:3.0:attribute-category:resource}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute with XPathExpression missing XPathCategory + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"xpathExpression\", " + + "\"Value\" : {" + + "\"Namespaces\" : [{ "+ + "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + + "}," + + "{" + + "\"Prefix\" : \"md\", " + + "\"Namespace\" : \"urn:example:med:schemas:record\" " + + "}], "+ + "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ + "}" + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute with XPathExpression missing XPath + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"xpathExpression\", " + + "\"Value\" : {" + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + + "\"Namespaces\" : [{ "+ + "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + + "}," + + "{" + + "\"Prefix\" : \"md\", " + + "\"Namespace\" : \"urn:example:med:schemas:record\" " + + "}] "+ + "}" + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute with XPathExpression without Namespaces + // (path does not contain namespace references) + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"xpathExpression\", " + + "\"Value\" : {" + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + + "\"XPath\" : \"record/patient/patientDoB\" "+ + "}" + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression,value={path=record/patient/patientDoB,Namespace=null,status=null,xpathExpressionWrapped=null},xpathCategory=urn:oasis:names:tc:xacml:3.0:attribute-category:resource}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute with XPathExpression with 0 Namespaces + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"xpathExpression\", " + + "\"Value\" : {" + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + + "\"Namespaces\" : [], "+ + "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ + "}" + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression,value={path=md:record/md:patient/md:patientDoB,Namespace=null,status=null,xpathExpressionWrapped=null},xpathCategory=urn:oasis:names:tc:xacml:3.0:attribute-category:resource}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // Category Attribute with XPathExpression with Namespaces without mandatory Namespace + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"xpathExpression\", " + + "\"Value\" : {" + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + + "\"Namespaces\" : [{ "+ + "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + + "}," + + "{" + + "\"Prefix\" : \"md\", " + + "}], "+ + "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ + "}" + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"xpathExpression\", " + + "\"Value\" : {" + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + + "\"Namespaces\" : [{ "+ + "}," + + "{" + + "\"Prefix\" : \"md\", " + + "\"Namespace\" : \"urn:example:med:schemas:record\" " + + "}], "+ + "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ + "}" + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute with XPathExpression with Namespaces with 2 namespaces using same prefix + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"xpathExpression\", " + + "\"Value\" : {" + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + + "\"Namespaces\" : [{ "+ + "\"Prefix\" : \"md\", " + + "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + + "}," + + "{" + + "\"Prefix\" : \"md\", " + + "\"Namespace\" : \"urn:example:med:schemas:record\" " + + "}], "+ + "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ + "}" + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute with XPathExpression without Namespaces which are used within the XPathExpression (NOTE: Error is not syntactic and is not found by converter) + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"xpathExpression\", " + + "\"Value\" : {" + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + + "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ + "}" + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression,value={path=md:record/md:patient/md:patientDoB,Namespace=null,status=null,xpathExpressionWrapped=null},xpathCategory=urn:oasis:names:tc:xacml:3.0:attribute-category:resource}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute with XPathExpression containing simple value (must be object) + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"xpathExpression\", " + + "\"Value\" : \"simple Value\"" + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute with Namespaces containing simple value (must be object) + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"xpathExpression\", " + + "\"Value\" : {" + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + + "\"Namespaces\" : [ \"simpleValue\"," + + "{" + + "\"Prefix\" : \"md\", " + + "\"Namespace\" : \"urn:example:med:schemas:record\" " + + "}], "+ + "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ + "}" + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // Category Attribute with Namespaces non-string Namespace + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"xpathExpression\", " + + "\"Value\" : {" + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + + "\"Namespaces\" : [ {" + + "\"Prefix\" : \"md\", " + + "\"Namespace\" : 123 " + + "}], "+ + "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ + "}" + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute with Namespaces non-string prefix + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"xpathExpression\", " + + "\"Value\" : {" + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + + "\"Namespaces\" : [ {" + + "\"Prefix\" : 123, " + + "\"Namespace\" : \"urn:example:med:schemas:record\" " + + "}], "+ + "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ + "}" + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute with Namespaces non-string XPathCategory + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"xpathExpression\", " + + "\"Value\" : {" + + "\"XPathCategory\" : 123," + + "\"Namespaces\" : [ {" + + "\"Prefix\" : \"md\", " + + "\"Namespace\" : \"urn:example:med:schemas:record\" " + + "}], "+ + "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ + "}" + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute with Namespaces non-string XPath + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"xpathExpression\", " + + "\"Value\" : {" + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + + "\"Namespaces\" : [ {" + + "\"Prefix\" : \"md\", " + + "\"Namespace\" : \"urn:example:med:schemas:record\" " + + "}], "+ + "\"XPath\" : 123 "+ + "}" + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + } + + + + @Test + public void testContent() { + + // Category with Content in XML, escaped properly + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\",\"aValue\",\"aValue\"] " + + "}]," + + "\"Content\" : \"" + + "Gambardella, MatthewXML Developer's GuideComputer" + + "44.952000-10-01An in-depth look at creating applications with XML."+ + "\"" + + "} ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]},contentRoot=[catalog: null]}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category with Content in XML, double quotes and back-slashes NOT escaped properly? + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\",\"aValue\",\"aValue\"] " + + "}]," + + "\"Content\" : \"" + + "Gambardella, MatthewXML Developer's GuideComputer" + + "44.952000-10-01An in-depth look at creating applications with XML."+ + "\"" + + "} ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category with Content in Base64 + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\",\"aValue\",\"aValue\"] " + + "}]," + + "\"Content\" : \"PD94bWwgdmVyc2lvbj0iMS4wIj8+PGNhdGFsb2c+PGJvb2sgaWQ9ImJrMTAxIj48YXV0aG9yPkdhbWJhcmRlbGxhLCBNYXR0aGV3PC9hdXRob3I+PHRpdGxlPlhNT" + + "CBEZXZlbG9wZXIncyBHdWlkZTwvdGl0bGU+PGdlbnJlPkNvbXB1dGVyPC9nZW5yZT48cHJpY2U+NDQuOTU8L3ByaWNlPjxwdWJsaXNoX2RhdGU+MjAwMC0xMC0wMTwvcHVibGlzaF"+ + "9kYXRlPjxkZXNjcmlwdGlvbj5BbiBpbi1kZXB0aCBsb29rIGF0IGNyZWF0aW5nIGFwcGxpY2F0aW9ucyB3aXRoIFhNTC48L2Rlc2NyaXB0aW9uPjwvYm9vaz48L2NhdGFsb2c+\"" + + "} ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]},contentRoot=[catalog: null]}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category with Bad Content in Base64 + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\",\"aValue\",\"aValue\"] " + + "}]," + + "\"Content\" : \"PD94bWwgdmV\"" + + "} ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + } + + + + + @Test + public void testDuplicates() { + // duplicate of same element within Category array is ok + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#string\", " + + "\"Value\" : \"abc\" " + + "}] }, " + + "{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#string\", " + + "\"Value\" : \"abc\" " + + "}] } " + + "] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=abc}],includeInResults=false}]}}{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=abc}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // duplicate Attribute + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [" + + "{\"CategoryId\" : \"custom-category\"," + + " \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#string\", " + + "\"Value\" : \"abc\" " + + "}], " + + " \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#string\", " + + "\"Value\" : \"abc\" " + + "}] " + + "} " + + " }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // dup id + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#string\", " + + "\"Value\" : \"abc\" " + + "}] } " + + "] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // dup DataType + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#string\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#string\", " + + "\"Value\" : \"abc\" " + + "}] } " + + "] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // dup Value + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#string\", " + + "\"Value\" : \"abc\" " + + "\"Value\" : \"abc\" " + + "}] } " + + "] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // duplicate Content + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{" + + "\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\",\"aValue\",\"aValue\"] " + + "}]," + + "\"Content\" : \"" + + "Gambardella, MatthewXML Developer's GuideComputer" + + "44.952000-10-01An in-depth look at creating applications with XML."+ + "\" , " + + "\"Content\" : \"" + + "Gambardella, MatthewXML Developer's GuideComputer" + + "44.952000-10-01An in-depth look at creating applications with XML."+ + "\"" + + "} ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + } + + + +//TODO - Shorthand for CategoryId ???? + + +} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/json/RequestConformanceTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/json/RequestConformanceTest.java new file mode 100644 index 000000000..54f5b26f8 --- /dev/null +++ b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/json/RequestConformanceTest.java @@ -0,0 +1,255 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-TEST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.std.json; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import java.io.File; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; + +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +import org.junit.Test; + +import com.att.research.xacml.api.Request; +import com.att.research.xacml.api.RequestAttributes; +import com.att.research.xacml.api.RequestReference; +import com.att.research.xacml.std.dom.DOMRequest; +import com.att.research.xacml.std.json.JSONRequest; +import com.att.research.xacml.std.json.JSONStructureException; +/** + * Test JSON Request convert to object - Conformance tests + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * NOTE: + * The "correct" way to verify that each JSON string gets translated into our internal Objects correctly is to look explicitly at each of the child objects + * and verify that they are correct. This would involve a lot of coding to get child of child of child and individually verify each property of each element. + * To simplify testing we assume that request.toString() correctly includes a complete text representation of every sub-component of the Request object + * and we compare the resulting String to our expected String. + * This has two possible sources of error: + * - toString might not include some sub-component, and + * - the initial verification of the resulting string is done by hand and may have been incorrect. + * + * + */ +public class RequestConformanceTest { + + // where to find the conformance test XML files + private final String CONFORMANCE_DIRECTORY_PATH = "testsets/conformance/xacml3.0-ct-v.0.4"; + + // The request object output from each test conversion from JSON string + Request request; + + + + + + // test just one of each top-level element. + // For simple elements also test for incorrect type + @Test + public void testConformanceRequests() { + + List filesInDirectory = null; + + File conformanceDirectory = null; + + File currentFile = null; + + try { + conformanceDirectory = new File(CONFORMANCE_DIRECTORY_PATH); + filesInDirectory = getRequestsInDirectory(conformanceDirectory); + } catch (Exception e) { + fail("Unable to set up Conformance tests for dir '" + conformanceDirectory.getAbsolutePath()+"' e="+ e); + } + + // run through each XML file + // - load the file from XML into an internal Request object + // - generate the JSON representation of that Request object + // - load that JSON representation into a new Request object + // - compare the 2 Request objects + Request xmlRequest = null; + Request jsonRequest = null; + try { + for (File f : filesInDirectory) { + currentFile = f; + +//// This is a simple way to select just one file for debugging - comment out when not being used +//if ( ! f.getName().equals("IIA023Request.xml")) { continue; } + +// during debugging it is helpful to know what file it is starting to work on +// System.out.println("starting file="+currentFile.getName()); + + try { + // load XML into a Request object + xmlRequest = DOMRequest.load(f); + xmlRequest.getStatus(); + } catch (Exception e) { + // if XML does not load, just note it and continue with next file + System.out.println("XML file did not load: '" + f.getName() + " e=" + e); + continue; + } + + + + // generate JSON from the Request + String jsonString = JSONRequest.toString(xmlRequest, false); + + + + // load JSON into a Request + jsonRequest = JSONRequest.load(jsonString); + + // compare the two Request objects + + // check simple things first + assertEquals("File '" + currentFile.getName() + "' CombinedDecision", xmlRequest.getCombinedDecision(), jsonRequest.getCombinedDecision()); + assertEquals("File '" + currentFile.getName() + "' getReturnPolicyIdList", xmlRequest.getReturnPolicyIdList(), jsonRequest.getReturnPolicyIdList()); + assertEquals("File '" + currentFile.getName() + "' requestDefaults", xmlRequest.getRequestDefaults(), jsonRequest.getRequestDefaults()); + + // multiRequests (guaranteed to not be null) + // We do NOT care about ordering, so compare the two collections inefficiently + Collection xmlCollection = xmlRequest.getMultiRequests(); + Collection jsonCollection = jsonRequest.getMultiRequests(); + String errorMessage = null; + if (jsonCollection.size() != xmlCollection.size()) { + errorMessage = "File '" + currentFile.getName() + "' MultiRequests not same size. "; + } else if (! jsonCollection.containsAll(xmlCollection)) { + errorMessage = "File '" + currentFile.getName() + "' MultiRequests have different contents. "; + } + if (errorMessage != null) { + String xmlContents = ""; + String jsonContents = ""; + Iterator rrIt = xmlCollection.iterator(); + while (rrIt.hasNext()) { + xmlContents += "\n " + rrIt.next().toString(); + } + rrIt = jsonCollection.iterator(); + while (rrIt.hasNext()) { + jsonContents += "\n " + rrIt.next().toString(); + } + fail(errorMessage + "\nXML(" + xmlCollection.size() + ")='" + xmlContents + + "' \nJSON(" + jsonCollection.size() + ")='" + jsonContents + + "'" + + "\njson='" + jsonString + "'"); + } + + // attributes (guaranteed to not be null) + // We do NOT care about ordering, so compare the two collections inefficiently + Collection xmlAttrCollection = xmlRequest.getRequestAttributes(); + Collection jsonAttrCollection = jsonRequest.getRequestAttributes(); + errorMessage = null; + if (jsonAttrCollection.size() != xmlAttrCollection.size()) { + errorMessage = "File '" + currentFile.getName() + "' RequestAttributes not same size. "; + } else if (! jsonAttrCollection.containsAll(xmlAttrCollection)) { + String attrName = ""; + Iterator rait = xmlAttrCollection.iterator(); + while (rait.hasNext()) { + RequestAttributes ra = rait.next(); + if (jsonAttrCollection.contains(ra) == false) { + attrName = ra.toString(); + } + } + errorMessage = "File '" + currentFile.getName() + "' RequestAttributes have different contents. JSON is missing attr=" + attrName; + } + if (errorMessage != null) { + String xmlContents = ""; + String jsonContents = ""; + Iterator rrIt = xmlAttrCollection.iterator(); + while (rrIt.hasNext()) { + RequestAttributes ras = rrIt.next(); + xmlContents += "\n " + ras.toString(); + if (ras.getContentRoot() != null) { + StringWriter writer = new StringWriter(); + Transformer transformer = null; + try { + transformer = TransformerFactory.newInstance().newTransformer(); + transformer.transform(new DOMSource(ras.getContentRoot()), new StreamResult(writer)); + } catch (Exception e) { + throw new JSONStructureException("Unable to Content node to string; e="+e); + } + + xmlContents += "\n Content: " + writer.toString(); + } + } + rrIt = jsonAttrCollection.iterator(); + while (rrIt.hasNext()) { + RequestAttributes ras = rrIt.next(); + jsonContents += "\n " + ras.toString(); + if (ras.getContentRoot() != null) { + StringWriter writer = new StringWriter(); + Transformer transformer = null; + try { + transformer = TransformerFactory.newInstance().newTransformer(); + transformer.transform(new DOMSource(ras.getContentRoot()), new StreamResult(writer)); + } catch (Exception e) { + throw new JSONStructureException("Unable to Content node to string; e="+e); + } + + jsonContents += "\n Content: " + writer.toString(); + } + } + fail(errorMessage + "\nXML(" + xmlAttrCollection.size() + ")='" + xmlContents + + "' \nJSON(" + jsonAttrCollection.size() + ")='" + jsonContents + + "\njson='" + jsonString + "'"); + } + + + } + + } catch (Exception e) { + fail ("Failed test with '" + currentFile.getName() + "', e=" + e); + } + + + } + + // + // HELPER to get list of all Request files in the given directory + // + + private List getRequestsInDirectory(File directory) { + List fileList = new ArrayList(); + + File[] fileArray = directory.listFiles(); + for (File f : fileArray) { + if (f.isDirectory()) { + List subDirList = getRequestsInDirectory(f); + fileList.addAll(subDirList); + } + if (f.getName().endsWith("Request.xml")) { + fileList.add(f); + } + } + return fileList; + + } + +} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/json/RequestDefaultCategoryTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/json/RequestDefaultCategoryTest.java new file mode 100644 index 000000000..2465b3768 --- /dev/null +++ b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/json/RequestDefaultCategoryTest.java @@ -0,0 +1,1427 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-TEST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.std.json; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import org.junit.Test; + +import com.att.research.xacml.api.Request; +import com.att.research.xacml.std.json.JSONRequest; +import com.att.research.xacml.std.json.JSONStructureException; +/** + * Test JSON Request convert to object - Default Category object tests + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * NOTE: + * The "correct" way to verify that each JSON string gets translated into our internal Objects correctly is to look explicitly at each of the child objects + * and verify that they are correct. This would involve a lot of coding to get child of child of child and individually verify each property of each element. + * To simplify testing we assume that request.toString() correctly includes a complete text representation of every sub-component of the Request object + * and we compare the resulting String to our expected String. + * This has two possible sources of error: + * - toString might not include some sub-component, and + * - the initial verification of the resulting string is done by hand and may have been incorrect. + * + * + */ +public class RequestDefaultCategoryTest { + + // The request object output from each test conversion from JSON string + Request request; + + + /* + * Request that uses all fields with both single and multiple entries + */ + String allFieldsRequest = + "{\"Request\": {" + + "\"ReturnPolicyIdList\" : true ," + + "\"CombinedDecision\" : true ," + + "\"XPathVersion\" : \"http://www.w3.org/TR/1999/REC-xpath-19991116\"," + + "\"MultiRequests\" : {" + + "\"RequestReference\": [" + + "{ " + + "\"ReferenceId\" : [\"foo1\",\"bar1\"]" + + "}," + + "{" + + "\"ReferenceId\" : [\"foo2\",\"bar1\"]" + + "}]" + + "}," + + + "\"Category\": [" + + "{ " + + "\"CategoryId\": \"custom-category\", " + + "\"Id\" : \"customId\", " + + "\"Attribute\" : [" + + "{" + + "\"AttributeId\" : \"document-id\", " + + "\"DataType\" : \"integer\", " + + "\"Value\" : 123 " + + "}, " + + "{" + + "\"AttributeId\" : \"document-url\", " + + "\"DataType\" : \"anyURI\", " + + "\"Value\" : \"http://somewhere.over.the.com/rainbow\" " + + "}, " + + "{" + + "\"AttributeId\" : \"page-list\", " + + "\"Value\" : [1, 2, 3, 4.5, 3, 2, 1] " + + "} " + + "]" + + "}, " + + "{ " + + "\"CategoryId\": \"another-custom-cat\", " + + "\"Id\" : \"anotherXmlId\", " + + "\"Attribute\" : []" + + "} " + + "], " + + + "\"AccessSubject\":{ " + + "\"Content\" : \"" + + "Gambardella, MatthewXML Developer's GuideComputer" + + "44.952000-10-01An in-depth look at creating applications with XML."+ + "\"," + + "\"Attribute\" : []" + + "}, " + + + "\"Resource\" : {" + + "\"Content\" : \"PD94bWwgdmVyc2lvbj0iMS4wIj8+PGNhdGFsb2c+PGJvb2sgaWQ9ImJrMTAxIj48YXV0aG9yPkdhbWJhcmRlbGxhLCBNYXR0aGV3PC9hdXRob3I+PHRpdGxlPlhNT" + + "CBEZXZlbG9wZXIncyBHdWlkZTwvdGl0bGU+PGdlbnJlPkNvbXB1dGVyPC9nZW5yZT48cHJpY2U+NDQuOTU8L3ByaWNlPjxwdWJsaXNoX2RhdGU+MjAwMC0xMC0wMTwvcHVibGlzaF"+ + "9kYXRlPjxkZXNjcmlwdGlvbj5BbiBpbi1kZXB0aCBsb29rIGF0IGNyZWF0aW5nIGFwcGxpY2F0aW9ucyB3aXRoIFhNTC48L2Rlc2NyaXB0aW9uPjwvYm9vaz48L2NhdGFsb2c+\"" + + + + "} " + + + + "}}"; + + /* + * The following example comes directly from the JSON Profile Spec + */ + String exampleFromSpec = "{ " + + "\"Request\" : { " + + "\"AccessSubject\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "}, " + + "\"Action\" : { " + + "\"Attribute\": " + + "{ " + + "\"Id\" : \"action-id\", " + + "\"Value\" : \"http://www.xacml.eu/buy\", " + + "\"DataType\" : \"anyURI\" " + + "} " + + "}, " + + "\"Resource\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"book-title\", " + + "\"Value\" : \"Learn German in 90 days\" " + + "}, " + + "{ " + + "\"Id\" : \"currency\", " + + "\"Value\" : \"SEK\" " + + "}, " + + "{ " + + "\"Id\" : \"price\", " + + "\"Value\" : 123.34 " + + "} " + + "] " + + "} " + + "} " + + "} "; + + + /* + * The following example comes directly from the JSON Profile Spec (modified to include a "" missing from both examples). + * It shows the two ways of handling XPath content, as escaped XML and as Base64 encoding. + */ + String xPathExampleFromSpec = "{ " + + "\"Request\" : { " + + "\"Resource\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"urn:oasis:names:tc:xacml:3.0:content-selector\", " + + "\"DataType\" : \"xpathExpression\", " + + "\"Value\" : { " + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\", " + + "\"Namespaces\" : [{ " + + "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + + "}, " + + "{ " + + "\"Prefix\" : \"md\", " + + "\"Namespace\" : \"urn:example:med:schemas:record\" " + + "} " + + "], " + + "\"XPath\" : \"md:record/md:patient/md:patientDoB\" " + + "} " + + "} " + + "] " + + "} " + + "} " + + "} "; + + + // test Shorthand Category notation for elements not tested in their own section below. + // Categories that are more commonly used are fully tested. + // Given that the functions within the categories are the same irrespective of the name of the category, + // we assume that the contents of the category will work ok once the Shorthand notation is recognized, so all we need to test is the shorthand + // The ones that are tested in their own sections are: + // AccessSubject + // Action + // Resource + // Environment + // test Subject + @Test + public void testCategoryShorthand() { + + // RecipientSubject present both as element within Category and as separate RecipientSubject element at same level as Category + try { + request = JSONRequest.load("{\"Request\" : {" + + "\"Category\": [" + + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:recipient-subject\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + + "}] }, " + + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:recipient-subject\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"aValue\"" + + "}] } " + + "]," + + "\"RecipientSubject\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:recipient-subject,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:recipient-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:recipient-subject,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:recipient-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:recipient-subject,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:recipient-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:1.0:subject-category:recipient-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // IntermediarySubject present both as element within Category and as separate IntermediarySubject element at same level as Category + try { + request = JSONRequest.load("{\"Request\" : {" + + "\"Category\": [" + + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:intermediary-subject\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + + "}] }, " + + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:intermediary-subject\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"aValue\"" + + "}] } " + + "]," + + "\"IntermediarySubject\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:intermediary-subject,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:intermediary-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:intermediary-subject,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:intermediary-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:intermediary-subject,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:intermediary-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:1.0:subject-category:intermediary-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // Codebase present both as element within Category and as separate Codebase element at same level as Category + try { + request = JSONRequest.load("{\"Request\" : {" + + "\"Category\": [" + + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:codebase\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + + "}] }, " + + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:codebase\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"aValue\"" + + "}] } " + + "]," + + "\"Codebase\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:codebase,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:codebase,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:codebase,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:codebase,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:codebase,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:codebase,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:1.0:subject-category:codebase,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + + // RequestingMachine present both as element within Category and as separate RequestingMachine element at same level as Category + try { + request = JSONRequest.load("{\"Request\" : {" + + "\"Category\": [" + + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:requesting-machine\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + + "}] }, " + + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:requesting-machine\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"aValue\"" + + "}] } " + + "]," + + "\"RequestingMachine\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:requesting-machine,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:requesting-machine,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:requesting-machine,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:requesting-machine,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:requesting-machine,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:requesting-machine,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:1.0:subject-category:requesting-machine,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + } + + + + + + + + + + + + + + + + + // test AccessSubject + // Include test for backward compatibility with "Subject" + @Test + public void testAccessSubjectRequest() { + + // AccessSubject absent + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // AccessSubject as normal element under Category (with CategoryId==subject category id) + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:access-subject\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"aValue\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // multiple AccessSubjects under Category + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [" + + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:access-subject\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + + "}] }, " + + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:access-subject\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"aValue\"" + + "}] } " + + "] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // AccessSubject present both as element within Category and as separate AccessSubject element at same level as Category + try { + request = JSONRequest.load("{\"Request\" : {" + + "\"Category\": [" + + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:access-subject\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + + "}] }, " + + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:access-subject\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"aValue\"" + + "}] } " + + "]," + + "\"AccessSubject\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // AccessSubject present, no other Category element + try { + request = JSONRequest.load("{\"Request\" : {" + + + "\"AccessSubject\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // Subject present, no other Category element (Backward Compatibility + try { + request = JSONRequest.load("{\"Request\" : {" + + + "\"Subject\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // AccessSubject present, 1/multiple other Category element also present + try { + request = JSONRequest.load("{\"Request\" : {" + + "\"Category\": [" + + "{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"aValue\"" + + "}] } " + + "]," + + "\"AccessSubject\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // 2 AccessSubjects - duplicates fail + try { + request = JSONRequest.load("{\"Request\" : {" + + + "\"AccessSubject\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + + "\"AccessSubject\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // AccessSubject with correct Category value + try { + request = JSONRequest.load("{\"Request\" : {" + + + "\"AccessSubject\" : { " + + "\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:access-subject\" ," + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // AccessSubject with wrong Category value + try { + request = JSONRequest.load("{\"Request\" : {" + + + "\"AccessSubject\" : { " + + "\"CategoryId\" : \"notthesubject\" ," + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // AccessSubject with array of sub-object AccessSubjects (Multi Decision) + try { + request = JSONRequest.load("{\"Request\" : {" + + + "\"AccessSubject\" : [" + + "{ " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "}, " + + "{ " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Arless\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Somewhere\" " + + "} " + + "] " + + "}, " + + "{ " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Barry\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Elsewhere\" " + + "} " + + "] " + + "} " + + "]" + + " }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Arless}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Somewhere}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Barry}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Elsewhere}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + } + + + + + + + + + + // Action ... duplicate all AccessSubject tests... + // test Action + @Test + public void testActionRequest() { + + // Action absent + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Action as normal element under Category (with CategoryId==subject category id) + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"aValue\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // multiple Actions under Category + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [" + + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + + "}] }, " + + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"aValue\"" + + "}] } " + + "] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Action present both as element within Category and as separate Action element at same level as Category + try { + request = JSONRequest.load("{\"Request\" : {" + + "\"Category\": [" + + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + + "}] }, " + + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"aValue\"" + + "}] } " + + "]," + + "\"Action\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Action present, no other Category element + try { + request = JSONRequest.load("{\"Request\" : {" + + + "\"Action\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Action present, 1/multiple other Category element also present + try { + request = JSONRequest.load("{\"Request\" : {" + + "\"Category\": [" + + "{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"aValue\"" + + "}] } " + + "]," + + "\"Action\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // 2 Actions - duplicates fail + try { + request = JSONRequest.load("{\"Request\" : {" + + + "\"Action\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + + "\"Action\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Action with correct Category value + try { + request = JSONRequest.load("{\"Request\" : {" + + + "\"Action\" : { " + + "\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:action\" ," + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Action with wrong Category value + try { + request = JSONRequest.load("{\"Request\" : {" + + + "\"Action\" : { " + + "\"CategoryId\" : \"notthesubject\" ," + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Action with array of sub-object Actions (Multi Decision) + try { + request = JSONRequest.load("{\"Request\" : {" + + + "\"Action\" : [" + + "{ " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "}, " + + "{ " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Arless\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Somewhere\" " + + "} " + + "] " + + "}, " + + "{ " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Barry\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Elsewhere\" " + + "} " + + "] " + + "} " + + "]" + + " }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Arless}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Somewhere}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Barry}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Elsewhere}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + } + + + + + // Resource ... duplicate all AccessSubject tests... + // test Resource + @Test + public void testResourceRequest() { + + // Resource absent + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Resource as normal element under Category (with CategoryId==subject category id) + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"aValue\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // multiple Resources under Category + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [" + + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + + "}] }, " + + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"aValue\"" + + "}] } " + + "] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Resource present both as element within Category and as separate Resource element at same level as Category + try { + request = JSONRequest.load("{\"Request\" : {" + + "\"Category\": [" + + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + + "}] }, " + + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"aValue\"" + + "}] } " + + "]," + + "\"Resource\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Resource present, no other Category element + try { + request = JSONRequest.load("{\"Request\" : {" + + + "\"Resource\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Resource present, 1/multiple other Category element also present + try { + request = JSONRequest.load("{\"Request\" : {" + + "\"Category\": [" + + "{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"aValue\"" + + "}] } " + + "]," + + "\"Resource\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // 2 Resources - duplicates fail + try { + request = JSONRequest.load("{\"Request\" : {" + + + "\"Resource\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + + "\"Resource\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Resource with correct Category value + try { + request = JSONRequest.load("{\"Request\" : {" + + + "\"Resource\" : { " + + "\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\" ," + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Resource with wrong Category value + try { + request = JSONRequest.load("{\"Request\" : {" + + + "\"Resource\" : { " + + "\"CategoryId\" : \"notthesubject\" ," + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Resource with array of sub-object Resources (Multi Decision) + try { + request = JSONRequest.load("{\"Request\" : {" + + + "\"Resource\" : [" + + "{ " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "}, " + + "{ " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Arless\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Somewhere\" " + + "} " + + "] " + + "}, " + + "{ " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Barry\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Elsewhere\" " + + "} " + + "] " + + "} " + + "]" + + " }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Arless}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Somewhere}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Barry}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Elsewhere}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + } + + + + + + + // Environment ... duplicate all AccessSubject tests ... + // test Environment + @Test + public void testEnvironmentRequest() { + + // Environment absent + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Environment as normal element under Category (with CategoryId==subject category id) + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"aValue\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // multiple Environments under Category + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [" + + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + + "}] }, " + + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"aValue\"" + + "}] } " + + "] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Environment present both as element within Category and as separate Environment element at same level as Category + try { + request = JSONRequest.load("{\"Request\" : {" + + "\"Category\": [" + + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + + "}] }, " + + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"aValue\"" + + "}] } " + + "]," + + "\"Environment\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Environment present, no other Category element + try { + request = JSONRequest.load("{\"Request\" : {" + + + "\"Environment\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Environment present, 1/multiple other Category element also present + try { + request = JSONRequest.load("{\"Request\" : {" + + "\"Category\": [" + + "{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"aValue\"" + + "}] } " + + "]," + + "\"Environment\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // 2 Environments - duplicates fail + try { + request = JSONRequest.load("{\"Request\" : {" + + + "\"Environment\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + + "\"Environment\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Environment with correct Category value + try { + request = JSONRequest.load("{\"Request\" : {" + + + "\"Environment\" : { " + + "\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\" ," + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Environment with wrong Category value + try { + request = JSONRequest.load("{\"Request\" : {" + + + "\"Environment\" : { " + + "\"CategoryId\" : \"notthesubject\" ," + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Environment with array of sub-object Environments (Multi Decision) + try { + request = JSONRequest.load("{\"Request\" : {" + + + "\"Environment\" : [" + + "{ " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "}, " + + "{ " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Arless\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Somewhere\" " + + "} " + + "] " + + "}, " + + "{ " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Barry\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Elsewhere\" " + + "} " + + "] " + + "} " + + "]" + + " }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Arless}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Somewhere}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Barry}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Elsewhere}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + } + + +} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/json/RequestMainTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/json/RequestMainTest.java new file mode 100644 index 000000000..eb19e35a2 --- /dev/null +++ b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/json/RequestMainTest.java @@ -0,0 +1,1076 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-TEST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.std.json; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import org.junit.Test; + +import com.att.research.xacml.api.Request; +import com.att.research.xacml.std.json.JSONRequest; +import com.att.research.xacml.std.json.JSONStructureException; +/** + * Test JSON Request convert to object - High-level Request-as-a-whole tests including test that fills in all fields with multiple values (where appropriate) + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * NOTE: + * The "correct" way to verify that each JSON string gets translated into our internal Objects correctly is to look explicitly at each of the child objects + * and verify that they are correct. This would involve a lot of coding to get child of child of child and individually verify each property of each element. + * To simplify testing we assume that request.toString() correctly includes a complete text representation of every sub-component of the Request object + * and we compare the resulting String to our expected String. + * This has two possible sources of error: + * - toString might not include some sub-component, and + * - the initial verification of the resulting string is done by hand and may have been incorrect. + * + * + */ +public class RequestMainTest { + + // The request object output from each test conversion from JSON string + Request request; + + + /* + * Request that uses all fields with both single and multiple entries + */ + String allFieldsRequest = + "{\"Request\": {" + + "\"ReturnPolicyIdList\" : true ," + + "\"CombinedDecision\" : true ," + + "\"XPathVersion\" : \"http://www.w3.org/TR/1999/REC-xpath-19991116\"," + + "\"MultiRequests\" : {" + + "\"RequestReference\": [" + + "{ " + + "\"ReferenceId\" : [\"foo1\",\"bar1\"]" + + "}," + + "{" + + "\"ReferenceId\" : [\"foo2\",\"bar1\"]" + + "}]" + + "}," + + + "\"Category\": [" + + "{ " + + "\"CategoryId\": \"custom-category\", " + + "\"Id\" : \"customId\", " + + "\"Attribute\" : [" + + "{" + + "\"AttributeId\" : \"document-id\", " + + "\"DataType\" : \"integer\", " + + "\"Value\" : 123 " + + "}, " + + "{" + + "\"AttributeId\" : \"document-url\", " + + "\"DataType\" : \"anyURI\", " + + "\"Value\" : \"http://somewhere.over.the.com/rainbow\" " + + "}, " + + "{" + + "\"AttributeId\" : \"page-list\", " + + "\"Value\" : [1, 2, 3, 4.5, 3, 2, 1] " + + "} " + + "]" + + "}, " + + "{ " + + "\"CategoryId\": \"another-custom-cat\", " + + "\"Id\" : \"anotherXmlId\", " + + "\"Attribute\" : []" + + "} " + + "], " + + + "\"AccessSubject\":{ " + + "\"Content\" : \"" + + "Gambardella, MatthewXML Developer's GuideComputer" + + "44.952000-10-01An in-depth look at creating applications with XML."+ + "\"," + + "\"Attribute\" : []" + + "}, " + + + "\"Resource\" : {" + + "\"Content\" : \"PD94bWwgdmVyc2lvbj0iMS4wIj8+PGNhdGFsb2c+PGJvb2sgaWQ9ImJrMTAxIj48YXV0aG9yPkdhbWJhcmRlbGxhLCBNYXR0aGV3PC9hdXRob3I+PHRpdGxlPlhNT" + + "CBEZXZlbG9wZXIncyBHdWlkZTwvdGl0bGU+PGdlbnJlPkNvbXB1dGVyPC9nZW5yZT48cHJpY2U+NDQuOTU8L3ByaWNlPjxwdWJsaXNoX2RhdGU+MjAwMC0xMC0wMTwvcHVibGlzaF"+ + "9kYXRlPjxkZXNjcmlwdGlvbj5BbiBpbi1kZXB0aCBsb29rIGF0IGNyZWF0aW5nIGFwcGxpY2F0aW9ucyB3aXRoIFhNTC48L2Rlc2NyaXB0aW9uPjwvYm9vaz48L2NhdGFsb2c+\"" + + + + "} " + + + + "}}"; + + /* + * The following example comes directly from the JSON Profile Spec + */ + String exampleFromSpec = "{ " + + "\"Request\" : { " + + "\"AccessSubject\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "}, " + + "\"Action\" : { " + + "\"Attribute\": " + + "{ " + + "\"Id\" : \"action-id\", " + + "\"Value\" : \"http://www.xacml.eu/buy\", " + + "\"DataType\" : \"anyURI\" " + + "} " + + "}, " + + "\"Resource\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"book-title\", " + + "\"Value\" : \"Learn German in 90 days\" " + + "}, " + + "{ " + + "\"Id\" : \"currency\", " + + "\"Value\" : \"SEK\" " + + "}, " + + "{ " + + "\"Id\" : \"price\", " + + "\"Value\" : 123.34 " + + "} " + + "] " + + "} " + + "} " + + "} "; + + + /* + * The following example comes directly from the JSON Profile Spec (modified to include a "" missing from both examples). + * It shows the two ways of handling XPath content, as escaped XML and as Base64 encoding. + */ + String xPathExampleFromSpec = "{ " + + "\"Request\" : { " + + "\"Resource\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"urn:oasis:names:tc:xacml:3.0:content-selector\", " + + "\"DataType\" : \"xpathExpression\", " + + "\"Value\" : { " + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\", " + + "\"Namespaces\" : [{ " + + "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + + "}, " + + "{ " + + "\"Prefix\" : \"md\", " + + "\"Namespace\" : \"urn:example:med:schemas:record\" " + + "} " + + "], " + + "\"XPath\" : \"md:record/md:patient/md:patientDoB\" " + + "} " + + "} " + + "] " + + "} " + + "} " + + "} "; + + + + // test various ways that request might be empty + @Test + public void testEmptyRequest() { + // null request + try { + request = JSONRequest.load((String)null); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // empty request + try { + request = JSONRequest.load((String)""); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load((String)" "); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // empty JSON request + try { + request = JSONRequest.load((String)"{}"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load((String)"{{}}"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // garbage input + try { + request = JSONRequest.load((String)"Some non-JSON string"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load((String)"{something non-JSON}"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // bad syntax (Request with no content) + try { + request = JSONRequest.load((String)"{\"Request\"}"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // bad syntax (no :field after Request) + try { + request = JSONRequest.load((String)"{\"Request\" : }"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // bad syntax (no " around Request) + try { + request = JSONRequest.load((String)"{Request}"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // empty content in Request + try { + request = JSONRequest.load((String)"{\"Request\" : \"\"}"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // content is not an object + try { + request = JSONRequest.load((String)"{\"Request\" : \"CombinedDecision\" : true }"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // too many } at end + // Jackson parser does not treat this as an error + try { + request = JSONRequest.load((String)"{\"Request\" : {\"XPathVersion\" : \"http://www.w3.org/TR/1999/REC-xpath-19991116\"}}}}}"); + assertEquals("{requestDefaults={xpatherVersion=http://www.w3.org/TR/1999/REC-xpath-19991116},returnPolicyIdList=false,combinedDecision=false}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // too few } at end + try { + request = JSONRequest.load((String)"{\"Request\" : {\"XPathVersion\" : \"http://www.w3.org/TR/1999/REC-xpath-19991116\" }"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // misplaced } in middle + try { + request = JSONRequest.load((String)"{\"Request\" : {\"XPathVersion\" : } \"http://www.w3.org/TR/1999/REC-xpath-19991116\"}}}}}"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + } + + + + // Test double braces around request + @Test + public void testDoubleBraces() { + + try { + request = JSONRequest.load((String)"{{\"Request\" }"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load((String)"{{\"Request\" : }"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load((String)"{{\"Request\" : {\"CombinedDecision\" : true }}"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + } + + + + // test elements missing from top-level Request and arrays where single elements should be + @Test + public void testMissingFields() { + + // Request containing empty array + try { + request = JSONRequest.load((String)"{\"Request\" : []}"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // array of one element + try { + request = JSONRequest.load((String)"{\"Request\" : [{\"CombinedDecision\" : true }]}"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // correctly formatted empty request gives request with defaults set + try { + request = JSONRequest.load((String)"{\"Request\" : { }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // space in front of name (inside quotes) + try { + request = JSONRequest.load((String)"{\" Request\" : {\"XPathVersion\" : \"http://some/other/default/uri\" }}"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // space at end of name (inside quotes) + try { + request = JSONRequest.load((String)"{\"Request \" : {\"XPathVersion\" : \"http://some/other/default/uri\" }}"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // space in front of value (inside quotes) - valid String but not valid URI + try { + request = JSONRequest.load((String)"{\"Request\" : {\"XPathVersion\" : \" http://some/other/default/uri\" }}"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // space at end of value (inside quotes) - valid String but not valid URI + try { + request = JSONRequest.load((String)"{\"Request\" : {\"XPathVersion\" : \"http://some/other/default/uri \" }}"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + } + + + + // test just one of each top-level element. + // For simple elements also test for incorrect type + @Test + public void testTopLevelElements() { + + // empty request + try { + request = JSONRequest.load((String)"{\"Request\" : {}}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + + // ReturnPolicyIdList + try { + request = JSONRequest.load((String)"{\"Request\" : {\"ReturnPolicyIdList\" : true }}"); + assertEquals("{returnPolicyIdList=true,combinedDecision=false}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load((String)"{\"Request\" : {\"ReturnPolicyIdList\" : \"abc\" }}"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load((String)"{\"Request\" : {\"ReturnPolicyIdList\" : 123 }}"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // CombinedDecision + try { + request = JSONRequest.load((String)"{\"Request\" : { \"CombinedDecision\" : true }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=true}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load((String)"{\"Request\" : {\"CombinedDecision\" : \"abc\" }}"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load((String)"{\"Request\" : {\"CombinedDecision\" : 123 }}"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // XPathVersion + try { + request = JSONRequest.load((String)"{\"Request\" : {\"XPathVersion\" : \"http://some/other/default/uri\" }}"); + assertEquals("{requestDefaults={xpatherVersion=http://some/other/default/uri},returnPolicyIdList=false,combinedDecision=false}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load((String)"{\"Request\" : {\"XPathVersion\" : true }}"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load((String)"{\"Request\" : {\"XPathVersion\" : 123 }}"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load((String)"{\"Request\" : {\"XPathVersion\" : \"not a uri\" }}"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // Category + try { + request = JSONRequest.load((String)"{\"Request\" : {\"Category\": [{ " + + "\"CategoryId\": \"another-custom-cat\", " + + "\"Id\" : \"anotherXmlId\", " + + "\"Attribute\" : []" + + "} " + + "] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=another-custom-cat},xmlId=anotherXmlId}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // AccessSubject + try { + request = JSONRequest.load((String)"{\"Request\" : { \"AccessSubject\":{ }}}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Action + try { + request = JSONRequest.load((String)"{\"Request\" : { \"Action\":{ }}}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:action}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Resource + try { + request = JSONRequest.load((String)"{\"Request\" : {\"Resource\":{ }}}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Environment + try { + request = JSONRequest.load((String)"{\"Request\" : {\"Environment\":{ } }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // MultiRequests + try { + request = JSONRequest.load((String)"{\"Request\" : {\"MultiRequests\" : {" + + "\"RequestReference\": [" + + "{ " + + "\"ReferenceId\" : [\"foo1\",\"bar1\"]" + + "}," + + "{" + + "\"ReferenceId\" : [\"foo2\",\"bar2\"]" + + "}]" + + "} } }"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,multiRequests=[{requestAttributesReferences=[{referenceId=foo1}{referenceId=bar1}]}{requestAttributesReferences=[{referenceId=foo2}{referenceId=bar2}]}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // MultiRequest with 1 + try { + request = JSONRequest.load((String)"{\"Request\" : {\"MultiRequests\" : {" + + "\"RequestReference\": [" + + "{" + + "\"ReferenceId\" : [\"bar2\"]" + + "}]" + + "} } }"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,multiRequests=[{requestAttributesReferences=[{referenceId=bar2}]}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // MultiRequest with RequestReferences with no ReferenceId + try { + request = JSONRequest.load((String)"{\"Request\" : {\"MultiRequests\" : {" + + "\"RequestReference\": [" + + "{" + + "\"ReferenceId\" : []" + + "}]" + + "} } }"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // MultiRequests with no RequestReference + try { + request = JSONRequest.load((String)"{\"Request\" : {\"MultiRequests\" : {" + + "\"RequestReference\": []" + + "} } }"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // MultiRequests with something other than RequestReference + try { + request = JSONRequest.load((String)"{\"Request\" : {\"MultiRequests\" : {" + + "\"SomeOtherAttribute\": 123" + + "} } }"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // MultiRequests with single RequestReference rather than array + try { + request = JSONRequest.load((String)"{\"Request\" : {\"MultiRequests\" : {" + + "\"RequestReference\": " + + "{" + + "\"ReferenceId\" : []" + + "}" + + "} } }"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // MultiRequests with RequestReference containing single element instead of array + try { + request = JSONRequest.load((String)"{\"Request\" : {\"MultiRequests\" : {" + + "\"RequestReference\": [" + + "{" + + "\"ReferenceId\" : \"foo1\"" + + "}]" + + "} } }"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load((String)"{\"Request\" : {\"MultiRequests\" : {" + + "\"RequestReference\": [" + + "{" + + "\"ReferenceId\" : {\"foo1\"}" + + "}]" + + "} } }"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // MultiRequests with component that is not a RequestReference + try { + request = JSONRequest.load((String)"{\"Request\" : {\"MultiRequests\" : {" + + "\"RequestReference\": [" + + "{ " + + "\"SomeOtherAttribute\" : [\"foo1\",\"bar1\"]" + + "}," + + "{" + + "\"ReferenceId\" : [\"foo2\",\"bar2\"]" + + "}]" + + "} } }"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // MultiRequests with component that is not a RequestReference + try { + request = JSONRequest.load((String)"{\"Request\" : {\"MultiRequests\" : {" + + "\"RequestReference\": [" + + "{ " + + "\"ReferenceId\" : [\"foo2\",\"bar2\"]," + + "\"SomeOtherAttribute\" : [\"foo1\",\"bar1\"]" + + "}," + + "{" + + "\"ReferenceId\" : [\"foo2\",\"bar2\"]" + + "}]" + + "} } }"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // MultiRequest with unknown elements (in addition to RequestReference) + try { + request = JSONRequest.load((String)"{\"Request\" : {\"MultiRequests\" : {" + + "\"SomeOtherAttribute\": 123," + + "\"RequestReference\": [" + + "{ " + + "\"ReferenceId\" : [\"foo1\",\"bar1\"]" + + "}," + + "{" + + "\"ReferenceId\" : [\"foo2\",\"bar2\"]" + + "}]" + + "} } }"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // MultiRequest with RequestReferences with ReferenceId NOT a string + try { + request = JSONRequest.load((String)"{\"Request\" : {\"MultiRequests\" : {" + + "\"RequestReference\": [" + + "{" + + "\"ReferenceId\" : [ true ]" + + "}]" + + "} } }"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load((String)"{\"Request\" : {\"MultiRequests\" : {" + + "\"RequestReference\": [" + + "{" + + "\"ReferenceId\" : [ 123 ]" + + "}]" + + "} } }"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // Cannot test with ReferenceId that is NOT referring to a Category object Id property because we may not have read the Category objects yet. + // Need to leave this up to the PDP. + + + // extra elements in top-level + try { + request = JSONRequest.load((String)"{\"Request\" : {}, \"unknownElement\" : false, \"unk2\" : \"abc\", \"unk3\" : 123 }}"); + fail("Unknown element should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // extra elements in Request + try { + request = JSONRequest.load((String)"{\"Request\" : {\"XPathVersion\" : \"http://www.w3.org/TR/1999/REC-xpath-19991116\", \"unknownElement\" : false }}"); + fail("Unknown element should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + } + + + // Test with every field filled in with multiple values where appropriate + @Test + public void testAllFieldsRequest() { + + // convert Response to JSON + try { + request = JSONRequest.load(allFieldsRequest); + assertEquals("{requestDefaults={xpatherVersion=http://www.w3.org/TR/1999/REC-xpath-19991116},returnPolicyIdList=true,combinedDecision=true,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=123}],includeInResults=false}{attributeId=document-url,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=http://somewhere.over.the.com/rainbow}],includeInResults=false}{attributeId=page-list,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=1.0}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=2.0}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=3.0}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=4.5}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=3.0}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=2.0}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=1.0}],includeInResults=false}]},xmlId=customId}{super={category=another-custom-cat},xmlId=anotherXmlId}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject},contentRoot=[catalog: null]}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource},contentRoot=[catalog: null]}],multiRequests=[{requestAttributesReferences=[{referenceId=foo1}{referenceId=bar1}]}{requestAttributesReferences=[{referenceId=foo2}{referenceId=bar1}]}]}" + , request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // convert example request from spec + try { + request = JSONRequest.load(exampleFromSpec); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,attributes=[{attributeId=action-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=http://www.xacml.eu/buy}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,attributes=[{attributeId=book-title,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Learn German in 90 days}],includeInResults=false}{attributeId=currency,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=SEK}],includeInResults=false}{attributeId=price,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=123.34}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // convert example request from spec containing XPAthExpression + try { + request = JSONRequest.load(xPathExampleFromSpec); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,attributes=[{attributeId=urn:oasis:names:tc:xacml:3.0:content-selector,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression,value={path=md:record/md:patient/md:patientDoB,Namespace={[{md,urn:example:med:schemas:record}{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}]},status=null,xpathExpressionWrapped=null},xpathCategory=urn:oasis:names:tc:xacml:3.0:attribute-category:resource}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + } + + + + // Duplicates - Each element duplicated + @Test + public void testDuplicates() { + // duplicate Request + try { + request = JSONRequest.load((String)"{\"Request\" : {}, \"Request\" : {}}"); + fail("Unknown element should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + try { + request = JSONRequest.load((String)"{\"Request\" : {\"ReturnPolicyIdList\" : true, \"ReturnPolicyIdList\" : true }}"); + fail("Unknown element should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load((String)"{\"Request\" : { \"CombinedDecision\" : true, \"CombinedDecision\" : true }}"); + fail("Unknown element should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + try { + request = JSONRequest.load((String)"{\"Request\" : {\"Category\": [{ " + + "\"CategoryId\": \"another-custom-cat\", " + + "\"Id\" : \"anotherXmlId\", " + + "\"Attribute\" : []" + + "} " + + "]," + + "\"Category\": [{ " + + "\"CategoryId\": \"another-custom-cat\", " + + "\"Id\" : \"anotherXmlId\", " + + "\"Attribute\" : []" + + "} " + + "] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=another-custom-cat},xmlId=anotherXmlId}]}", request.toString()); + fail("Unknown element should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load((String)"{\"Request\" : {\"Category\": [{ " + + "\"CategoryId\": \"another-custom-cat\", " + + "\"CategoryId\": \"another-custom-cat\", " + + "\"Id\" : \"anotherXmlId\", " + + "\"Attribute\" : []" + + "} " + + "] }}"); + fail("Unknown element should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load((String)"{\"Request\" : {\"Category\": [{ " + + "\"CategoryId\": \"another-custom-cat\", " + + "\"Id\" : \"anotherXmlId\", " + + "\"Id\" : \"anotherXmlId\", " + + "\"Attribute\" : []" + + "} " + + "] }}"); + fail("Unknown element should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load((String)"{\"Request\" : {\"Category\": [{ " + + "\"CategoryId\": \"another-custom-cat\", " + + "\"Id\" : \"anotherXmlId\", " + + "\"Attribute\" : []" + + "\"Attribute\" : []" + + "} " + + "] }}"); + fail("Unknown element should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // AccessSubject + try { + request = JSONRequest.load((String)"{\"Request\" : { \"AccessSubject\":{ }, \"AccessSubject\":{ }}}"); + fail("Unknown element should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Action + try { + request = JSONRequest.load((String)"{\"Request\" : { \"Action\":{ }, \"Action\":{ }}}"); + fail("Unknown element should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Resource + try { + request = JSONRequest.load((String)"{\"Request\" : {\"Resource\":{ }, \"Resource\":{ }}}"); + fail("Unknown element should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Environment + try { + request = JSONRequest.load((String)"{\"Request\" : {\"Environment\":{ }, \"Environment\":{ } }}"); + fail("Unknown element should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // MultiRequests + + + try { + request = JSONRequest.load((String)"{\"Request\" : {\"MultiRequests\" : {" + + "\"RequestReference\": [" + + "{ " + + "\"ReferenceId\" : [\"foo1\",\"bar1\"]" + + "}," + + "{" + + "\"ReferenceId\" : [\"foo2\",\"bar2\"]" + + "}]" + + "}," + + "\"MultiRequests\" : {" + + "\"RequestReference\": [" + + "{ " + + "\"ReferenceId\" : [\"foo1\",\"bar1\"]" + + "}," + + "{" + + "\"ReferenceId\" : [\"foo2\",\"bar2\"]" + + "}]" + + "} } }"); + fail("Unknown element should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load((String)"{\"Request\" : {\"MultiRequests\" : {" + + "\"RequestReference\": [" + + "{ " + + "\"ReferenceId\" : [\"foo1\",\"bar1\"]" + + "}," + + "{" + + "\"ReferenceId\" : [\"foo2\",\"bar2\"]" + + "}]," + + "\"RequestReference\": [" + + "{ " + + "\"ReferenceId\" : [\"foo1\",\"bar1\"]" + + "}," + + "{" + + "\"ReferenceId\" : [\"foo2\",\"bar2\"]" + + "}]" + + "} } }"); + fail("Unknown element should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load((String)"{\"Request\" : {\"MultiRequests\" : {" + + "\"RequestReference\": [" + + "{ " + + "\"ReferenceId\" : [\"foo1\",\"bar1\"]" + + "\"ReferenceId\" : [\"foo1\",\"bar1\"]" + + "}," + + "{" + + "\"ReferenceId\" : [\"foo2\",\"bar2\"]" + + "}]" + + "} } }"); + fail("Unknown element should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + } + + +} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/json/ResponseConformanceTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/json/ResponseConformanceTest.java new file mode 100644 index 000000000..adf903022 --- /dev/null +++ b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/json/ResponseConformanceTest.java @@ -0,0 +1,370 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-TEST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.std.json; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import java.io.File; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import org.junit.Test; + +import com.att.research.xacml.api.Advice; +import com.att.research.xacml.api.Attribute; +import com.att.research.xacml.api.AttributeCategory; +import com.att.research.xacml.api.IdReference; +import com.att.research.xacml.api.Obligation; +import com.att.research.xacml.api.Response; +import com.att.research.xacml.api.Result; +import com.att.research.xacml.std.dom.DOMResponse; +import com.att.research.xacml.std.json.JSONResponse; +import com.att.research.xacml.util.ListUtil; +/** + * Test JSON Response convert to object - Conformance tests + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * Note: some of the validation tests comparing the XML-derived Results to the JSON-derived Results are high-level comparisons of Collections. + * When this class was first created that was sufficient to pass all Conformance tests. + * However if this sees a failure in a Conformance test, those validations may need to be upgraded to look at the individual data elements to see what is wrong. + * + * + */ +public class ResponseConformanceTest { + + // where to find the conformance test XML files + private final String CONFORMANCE_DIRECTORY_PATH = "testsets/conformance/xacml3.0-ct-v.0.4"; + + // The request object output from each test conversion from JSON string + Response response; + + + + + + // test just one of each top-level element. + // For simple elements also test for incorrect type + @Test + public void testConformanceResponses() { + + List filesInDirectory = null; + + File conformanceDirectory = null; + + File currentFile = null; + + try { + conformanceDirectory = new File(CONFORMANCE_DIRECTORY_PATH); + filesInDirectory = getRequestsInDirectory(conformanceDirectory); + } catch (Exception e) { + fail("Unable to set up Conformance tests for dir '" + conformanceDirectory.getAbsolutePath()+"' e="+ e); + } + + // run through each XML file + // - load the file from XML into an internal Response object + // - generate the JSON representation of that Response object + // - load that JSON representation into a new Response object + // - compare the 2 Request objects + Response xmlResponse = null; + Response jsonResponse = null; + try { + for (File f : filesInDirectory) { + currentFile = f; + +//// This is a simple way to select just one file for debugging - comment out when not being used +//if ( ! f.getName().equals("IIIA030Response.xml") && ! f.getName().equals("IIIA330Response.xml")) { continue; } + +// during debugging it is helpful to know what file it is starting to work on +// System.out.println("starting file="+currentFile.getName()); + + try { + // load XML into a Response object + xmlResponse = DOMResponse.load(f); + } catch (Exception e) { + // if XML does not load, just note it and continue with next file + System.out.println("XML file did not load: '" + f.getName() + " e=" + e); + continue; + } + + // some tests have JSON response files to load, most do not + String jsonFileName = f.getName().replace(".xml", ".json"); + File jsonFile = new File(conformanceDirectory, jsonFileName); + + if (jsonFile.exists()) { +//System.out.println("found file "+jsonFile.getName()); + // json version exists in file, so load it + jsonResponse = JSONResponse.load(jsonFile); + } else { + // json does not exist in file, so create it from the XML response using a String intermediate version + String jsonResponseString = JSONResponse.toString(xmlResponse, false); +//System.out.println(jsonResponseString); +//System.out.println(JSONResponse.toString(xmlResponse, true)); + + jsonResponse = JSONResponse.load(jsonResponseString); + } + + +//System.out.println(JSONResponse.toString(xmlResponse, true)); + + + + + // compare the two Response objects + + // compare results + assertEquals(xmlResponse.getResults().size(), jsonResponse.getResults().size()); + + if (xmlResponse.getResults().size() == 0) { + fail("neither XML nor JSON response have any Results"); + } + + + // Results are an un-ordered Collection. + // There is no identifying information that is unique to a specific Result. + // If there are more than one we cannot be sure which one corresponds with which. + // The best we can do is say that one or more in the first list do not match any in the second list + if (xmlResponse.getResults().size() > 1) { + for (Result xmlResult : xmlResponse.getResults()) { + boolean found = false; + for (Result jsonResult : jsonResponse.getResults()) { + if (xmlResult.equals(jsonResult)) { + found = true; + break; + } + } + if (found) { + continue; + } + // no match found + System.out.println("No match for XML in " + f.getName()); + System.out.println("XML =" + xmlResult.toString()); + for (Result jsonResult : jsonResponse.getResults()) { + System.out.println("JSON="+ jsonResult.toString()); + } + fail("JSON Response has no match for XML Result: " + xmlResult.toString()); + } + // we've done the best we can for multiple decisions, so go to next file + continue; + } + + // single Result in each + Result xmlResult = xmlResponse.getResults().iterator().next(); + Result jsonResult = jsonResponse.getResults().iterator().next(); + + // The following sections have not given us trouble, so checking is very high-level. + // If we see a problem in one of these elements, the single line will need to be replaced with detailed examination of the objects. + assertEquals(f.getName() + " Decision", xmlResult.getDecision(), jsonResult.getDecision()); + assertEquals(f.getName() + " Status", xmlResult.getStatus(), jsonResult.getStatus()); + + // Obligations + if (xmlResult.getObligations() != jsonResult.getObligations()) { + Collection xmlObligations = xmlResult.getObligations(); + Collection jsonObligations = jsonResult.getObligations(); + // if both are null we do not get here + if (xmlObligations == null || jsonObligations == null) { + fail(f.getName() + " Obligations has null \nXML="+xmlObligations + "\nJSON="+jsonObligations); + } + if (ListUtil.equalsAllowNulls(xmlObligations, jsonObligations) == false) { + // collections are not equal, so need to examine further +fail(f.getName() + " Obligation collections not equal\nXML="+xmlObligations + "\nJSON="+jsonObligations); + } + } + + // AssociatedAdvice + if (xmlResult.getAssociatedAdvice() != jsonResult.getAssociatedAdvice()) { + Collection xmlAdvice = xmlResult.getAssociatedAdvice(); + Collection jsonAdvice = jsonResult.getAssociatedAdvice(); + // if both are null we do not get here + if (xmlAdvice == null || jsonAdvice == null) { + fail(f.getName() + " Advice has null \nXML="+xmlAdvice + "\nJSON="+jsonAdvice); + } + if (ListUtil.equalsAllowNulls(xmlAdvice, jsonAdvice) == false) { + // collections are not equal, so need to examine further +fail(f.getName() + " Advice collections not equal\nXML="+xmlAdvice + "\nJSON="+jsonAdvice); + } + } + + + + // check Attributes in more detail + Collection xmlAttributes = xmlResult.getAttributes(); + Collection jsonAttributes = jsonResult.getAttributes(); + if (xmlAttributes == null && jsonAttributes != null || + xmlAttributes != null && jsonAttributes == null) { + fail(f.getName() + " XML Attributes="+xmlAttributes + " but JSON Attributes=" + jsonAttributes); + } + if (xmlAttributes != null) { + // both are non-null + if (xmlAttributes.size() != jsonAttributes.size()) { + String xmlAttributesString = "XML categorys="; + for (AttributeCategory ac : xmlAttributes) { + xmlAttributesString += " " + ac.getCategory().stringValue(); + } + String jsonAttributesString = "JSON categorys="; + for (AttributeCategory ac : jsonAttributes) { + jsonAttributesString += " " + ac.getCategory().stringValue(); + } + fail(f.getName() + " XML and JSON have different number of Category elements: " + xmlAttributesString + ", " + jsonAttributesString); + } + + // Attribute collections are the same size but may be in different orders. + // for each XML category try to find the corresponding JSON category. + // ASSUME that each category only shows up once!!!! + for (AttributeCategory xmlAttributeCategory : xmlAttributes) { + boolean attributeCategoryFound = false; + for (AttributeCategory jsonAttributeCategory : jsonAttributes) { + if (xmlAttributeCategory.equals(jsonAttributeCategory)) { + attributeCategoryFound = true; + break; + } + // not an exact match, but if same CategoryId then need to check individual Attribute objects + if (xmlAttributeCategory.getCategory().equals(jsonAttributeCategory.getCategory())) { + // same category + if (xmlAttributeCategory.getAttributes().size() != jsonAttributeCategory.getAttributes().size()) { + System.out.println("XML =" + xmlAttributeCategory.getAttributes()); + System.out.println("JSON=" + jsonAttributeCategory.getAttributes()); + fail(f.getName() + " Attributes Category '" + xmlAttributeCategory.getCategory().stringValue() + "' size mismatch; XML="+ + xmlAttributeCategory.getAttributes().size() +", JSON=" + jsonAttributeCategory.getAttributes().size()); + } + for (Attribute xmlAttr : xmlAttributeCategory.getAttributes()) { + boolean attributeFound = false; + for (Attribute jsonAttr : jsonAttributeCategory.getAttributes()) { + if (xmlAttr.equals(jsonAttr)) { + attributeFound = true; + break; + } + } + + if (attributeFound) { + // check next XML attribute + continue; + } + System.out.println("Attribute not found in JSON, Category="+xmlAttributeCategory.getCategory()); + System.out.println("XML Attribute ="+ xmlAttr); + System.out.println("JSON Attributes=" + jsonAttributeCategory.toString()); + fail(f.getName() + " Attribute not found in JSON, Category=" + xmlAttributeCategory.getCategory() + + "/nXML Attribute="+xmlAttr+ + "\nJSON Category Attributes="+jsonAttributeCategory.toString()); + } + + + + } + } + if (attributeCategoryFound) { + continue; + } + fail("XML Category not found in JSON; xml="+xmlAttributeCategory.toString()); + } + + } + + // PolicyIdentifiers + if (xmlResult.getPolicyIdentifiers() != jsonResult.getPolicyIdentifiers()) { + Collection xmlIdReferences = xmlResult.getPolicyIdentifiers(); + Collection jsonIdReferences = jsonResult.getPolicyIdentifiers(); + // if both are null we do not get here + if (xmlIdReferences == null || jsonIdReferences == null) { + fail(f.getName() + " PolicyIdentifiers has null \nXML="+xmlIdReferences + "\nJSON="+jsonIdReferences); + } + if (ListUtil.equalsAllowNulls(xmlIdReferences, jsonIdReferences) == false) { + // collections are not equal, so need to examine further +fail(f.getName() + " PolicyIdentifiers collections not equal\nXML="+xmlIdReferences+ "\nJSON="+jsonIdReferences); + } + } + + // PolicySetIdentifiers + if (xmlResult.getPolicySetIdentifiers() != jsonResult.getPolicySetIdentifiers()) { + Collection xmlIdReferences = xmlResult.getPolicySetIdentifiers(); + Collection jsonIdReferences = jsonResult.getPolicySetIdentifiers(); + // if both are null we do not get here + if (xmlIdReferences == null || jsonIdReferences == null) { + fail(f.getName() + " PolicySetIdentifiers has null \nXML="+xmlIdReferences + "\nJSON="+jsonIdReferences); + } + if (ListUtil.equalsAllowNulls(xmlIdReferences, jsonIdReferences) == false) { + // collections are not equal, so need to examine further +fail(f.getName() + " PolicySetIdentifiers collections not equal\nXML="+xmlIdReferences + "\nJSON="+jsonIdReferences); + } + } + + + } + + } catch (Exception e) { + fail ("Failed test with '" + currentFile.getName() + "', e=" + e); + } + + + } + + // + // HELPER to get list of all Request files in the given directory + // + + private List getRequestsInDirectory(File directory) { + List fileList = new ArrayList(); + + File[] fileArray = directory.listFiles(); + for (File f : fileArray) { + if (f.isDirectory()) { + List subDirList = getRequestsInDirectory(f); + fileList.addAll(subDirList); + } + if (f.getName().endsWith("Response.xml")) { + fileList.add(f); + } + } + return fileList; + + } + +} + + + + + +/* + * +This is a place to copy the really long output from test rigs that need to be manually edited for readability.... + + + +{"Response":[{"Status":{"StatusCode":{"Value":"urn:oasis:names:tc:xacml:1.0:status:ok"}},"Obligations":[{"Id":"urn:oasis:names:tc:xacml:2.0:conformance-test:IIIA030:obligation-1","AttributeAssignment":[ +{"Value":"assignment1","DataType":"string","AttributeId":"urn:oasis:names:tc:xacml:2.0:conformance-test:IIIA030:assignment1"}, +{"Value":{"Namespaces":[{"Namespace":"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17"},{"Namespace":"http://www.w3.org/2001/XMLSchema-instance","Prefix":"xsi"}], + "XPathCategory":"urn:oasis:names:tc:xacml:3.0:attribute-category:resource", + "XPath":"//md:records/md:record"}, + "DataType":"xpathExpression", + "AttributeId":"urn:oasis:names:tc:xacml:2.0:conformance-test:IIIA030:assignment2"}]}],"Decision":"Permit"}]} + + + +*/ + + + + + diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/json/ResponseTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/json/ResponseTest.java new file mode 100644 index 000000000..b2c2fd0f6 --- /dev/null +++ b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/json/ResponseTest.java @@ -0,0 +1,2297 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-TEST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pdp.test.std.json; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import java.text.ParseException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import java.math.BigInteger; + +import org.junit.Ignore; +import org.junit.Test; + +import com.att.research.xacml.api.Attribute; +import com.att.research.xacml.api.AttributeValue; +import com.att.research.xacml.api.Decision; +import com.att.research.xacml.api.Identifier; +import com.att.research.xacml.api.XACML3; +import com.att.research.xacml.std.IdentifierImpl; +import com.att.research.xacml.std.StdAttribute; +import com.att.research.xacml.std.StdAttributeCategory; +import com.att.research.xacml.std.StdAttributeValue; +import com.att.research.xacml.std.StdIdReference; +import com.att.research.xacml.std.StdMutableAdvice; +import com.att.research.xacml.std.StdMutableAttribute; +import com.att.research.xacml.std.StdMutableAttributeAssignment; +import com.att.research.xacml.std.StdMutableMissingAttributeDetail; +import com.att.research.xacml.std.StdMutableObligation; +import com.att.research.xacml.std.StdMutableResponse; +import com.att.research.xacml.std.StdMutableResult; +import com.att.research.xacml.std.StdMutableStatus; +import com.att.research.xacml.std.StdMutableStatusDetail; +import com.att.research.xacml.std.StdStatusCode; +import com.att.research.xacml.std.StdVersion; +import com.att.research.xacml.std.datatypes.DataTypes; +import com.att.research.xacml.std.datatypes.StringNamespaceContext; +import com.att.research.xacml.std.datatypes.XPathExpressionWrapper; +import com.att.research.xacml.std.json.JSONResponse; +import com.att.research.xacml.std.json.JSONStructureException; + +/** + * Test JSON Responses + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * + */ +public class ResponseTest { + + String jsonResponse; + + StdMutableResponse response; + + StdMutableResult result; + + StdMutableStatus status; + + + // Note: Initially test responses without Obligations, Associated Advice, Attributes, or PolicyIdentifier + + + @Test + public void testEmptyAndDecisions() { + // null response + try { + jsonResponse = JSONResponse.toString(null, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // empty response (no Result object) + response = new StdMutableResponse(); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // just decision, no status + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // just status (empty), no decision + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + result.setStatus(status); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // just status (non-empty), no decision + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_OK); + result.setStatus(status); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // test other decisions without Status + + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.DENY); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Decision\":\"Deny\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.NOTAPPLICABLE); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Decision\":\"NotApplicable\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Decision\":\"Indeterminate\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.INDETERMINATE_DENY); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Decision\":\"Indeterminate{D}\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.INDETERMINATE_DENYPERMIT); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Decision\":\"Indeterminate{DP}\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.INDETERMINATE_PERMIT); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Decision\":\"Indeterminate{P}\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // test Multiple Decisions - success + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + response.add(result); + StdMutableResult result2 = new StdMutableResult(); + result2.setDecision(Decision.DENY); + response.add(result2); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Decision\":\"Permit\"},{\"Decision\":\"Deny\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // test Multiple Decisions - one success and one error + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + response.add(result); + result2 = new StdMutableResult(); + result2.setDecision(Decision.INDETERMINATE); + response.add(result2); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Decision\":\"Permit\"},{\"Decision\":\"Indeterminate\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + } + + + + + // Test with every field filled in with multiple values where appropriate + @Ignore //@Test + public void testAllFieldsResponse() { + + // fully-loaded multiple response + + StdMutableResponse response = new StdMutableResponse(); + // create a Status object + StdMutableStatus status = new StdMutableStatus(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); + status.setStatusMessage("some status message"); + StdMutableStatusDetail statusDetailIn = new StdMutableStatusDetail(); + StdMutableMissingAttributeDetail mad = new StdMutableMissingAttributeDetail(); + mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_STRING.getId(), "doh")); + mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_INTEGER.getId(), "5432")); + mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_STRING.getId(), "meh")); + mad.setAttributeId(XACML3.ID_ACTION_PURPOSE); + mad.setCategory(XACML3.ID_ATTRIBUTE_CATEGORY_ACTION); + mad.setDataTypeId(XACML3.ID_DATATYPE_STRING); + mad.setIssuer("an Issuer"); + statusDetailIn.addMissingAttributeDetail(mad); + status.setStatusDetail(statusDetailIn); + // create a single result object + StdMutableResult result = new StdMutableResult(status); + // set the decision + result.setDecision(Decision.INDETERMINATE); + // put the Result into the Response + response.add(result); + + + // create a new Result with a different Decision + status = new StdMutableStatus(StdStatusCode.STATUS_CODE_OK); + result = new StdMutableResult(status); + result.setDecision(Decision.DENY); + + StdMutableObligation obligation = new StdMutableObligation(); + obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "obligation-issuer1", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Bart"))); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "obligation-issuer2", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Ned"))); + result.addObligation(obligation); + obligation = new StdMutableObligation(); + obligation.setId(XACML3.ID_SUBJECT_CATEGORY_INTERMEDIARY_SUBJECT); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "obligation-issuer3", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Maggie"))); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "obligation-issuer4", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Homer"))); + result.addObligation(obligation); + + + StdMutableAdvice advice = new StdMutableAdvice(); + advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "advice-issuer1", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu"))); + advice.addAttributeAssignment(new StdMutableAttributeAssignment( + null, + XACML3.ID_SUBJECT, + "advice-issuerNoCategory", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Crusty"))); + result.addAdvice(advice); + + + response.add(result); + + + // create a new Result with a different Decision + // add Child/minor status codes within the main status + StdStatusCode childChildChildStatusCode = new StdStatusCode(new IdentifierImpl("childChildChildStatusCode")); + StdStatusCode childChildStatusCode = new StdStatusCode(new IdentifierImpl("childChildStatusCode"), childChildChildStatusCode); + StdStatusCode child1StatusCode = new StdStatusCode(new IdentifierImpl("child1StatusCode"), childChildStatusCode); + StdStatusCode statusCode = new StdStatusCode(XACML3.ID_STATUS_OK, child1StatusCode); + + status = new StdMutableStatus(statusCode); + + + result = new StdMutableResult(status); + result.setDecision(Decision.PERMIT); + + + + + // add attribute list in result + Identifier categoryIdentifier = new IdentifierImpl("firstCategory"); + Attribute[] attrList = { + new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true), + new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent2"), new StdAttributeValue(DataTypes.DT_YEARMONTHDURATION.getId(), "P10Y4M"), "BIssue", false), + new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent3"), new StdAttributeValue(DataTypes.DT_DOUBLE.getId(), 765.432), "CIssue", true), + new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent4"), new StdAttributeValue(DataTypes.DT_BOOLEAN.getId(), true), "DIssue", true), + new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent5"), new StdAttributeValue(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(4567)), "EIssue", true), + new StdAttribute(categoryIdentifier, new IdentifierImpl("attrNoIssuer"), new StdAttributeValue(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(4567)), null, true) }; + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, Arrays.asList(attrList))); + categoryIdentifier = new IdentifierImpl("secondCategory"); + Attribute[] secondAttrList = { + new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent12"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu2"), "AIssue2", true), + new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent22"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Abc2"), "BIssue2", false), + new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent32"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Der2"), "CIssue2", true) }; + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, Arrays.asList(secondAttrList))); + + + // add PolicyIdentifierList to result + StdIdReference policyIdentifier1 = null; + StdIdReference policyIdentifier2 = null; + StdIdReference policySetIdentifier1 = null; + StdIdReference policySetIdentifier2 = null; + try { + policyIdentifier1 = new StdIdReference(new IdentifierImpl("idRef1"), StdVersion.newInstance("1.2.3")); + policyIdentifier2 = new StdIdReference(new IdentifierImpl("idRef2_NoVersion")); + policySetIdentifier1 = new StdIdReference(new IdentifierImpl("idSetRef1"), StdVersion.newInstance("4.5.6.7.8.9.0")); + policySetIdentifier2 = new StdIdReference(new IdentifierImpl("idSetRef2_NoVersion")); + } catch (ParseException e1) { + fail("creating policyIds, e="+e1); + } + + result.addPolicyIdentifier(policyIdentifier1); + result.addPolicyIdentifier(policyIdentifier2); + + result.addPolicySetIdentifier(policySetIdentifier1); + result.addPolicySetIdentifier(policySetIdentifier2); + + response.add(result); + + // convert Response to JSON + try { + jsonResponse = JSONResponse.toString(response, false); +System.out.println(jsonResponse); +//System.out.println(JSONResponse.toString(response, true)); + assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"},\"StatusMessage\":\"some status message\",\"StatusDetail\":\"doh5432meh\"},\"Decision\":\"Indeterminate\"},{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:ok\"}},\"Obligations\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Issuer\":\"obligation-issuer1\",\"Value\":\"Bart\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"},{\"Issuer\":\"obligation-issuer2\",\"Value\":\"Ned\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]},{\"Id\":\"urn:oasis:names:tc:xacml:1.0:subject-category:intermediary-subject\",\"AttributeAssignment\":[{\"Issuer\":\"obligation-issuer3\",\"Value\":\"Maggie\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"},{\"Issuer\":\"obligation-issuer4\",\"Value\":\"Homer\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}],\"Decision\":\"Deny\",\"AssociatedAdvice\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Issuer\":\"advice-issuer1\",\"Value\":\"Apu\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"},{\"Issuer\":\"advice-issuerNoCategory\",\"Value\":\"Crusty\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}]},{\"Status\":{\"StatusCode\":{\"StatusCode\":{\"StatusCode\":{\"StatusCode\":{\"Value\":\"childChildChildStatusCode\"},\"Value\":\"childChildStatusCode\"},\"Value\":\"child1StatusCode\"},\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:ok\"}},\"Category\":[{\"CategoryId\":\"firstCategory\",\"Attribute\":[{\"Issuer\":\"AIssue\",\"Value\":\"Apu\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent1\"},{\"Issuer\":\"CIssue\",\"Value\":765.432,\"DataType\":\"http://www.w3.org/2001/XMLSchema#double\",\"AttributeId\":\"attrIdent3\"},{\"Issuer\":\"DIssue\",\"Value\":true,\"DataType\":\"http://www.w3.org/2001/XMLSchema#boolean\",\"AttributeId\":\"attrIdent4\"},{\"Issuer\":\"EIssue\",\"Value\":4567,\"DataType\":\"http://www.w3.org/2001/XMLSchema#integer\",\"AttributeId\":\"attrIdent5\"},{\"Value\":4567,\"DataType\":\"http://www.w3.org/2001/XMLSchema#integer\",\"AttributeId\":\"attrNoIssuer\"}]},{\"CategoryId\":\"secondCategory\",\"Attribute\":[{\"Issuer\":\"AIssue2\",\"Value\":\"Apu2\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent12\"},{\"Issuer\":\"CIssue2\",\"Value\":\"Der2\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent32\"}]}],\"Decision\":\"Permit\",\"PolicyIdentifier\":{\"PolicyIdReference\":[{\"Id\":\"idRef1\",\"Version\":\"1.2.3\"},{\"Id\":\"idRef2_NoVersion\"}],\"PolicySetIdReference\":[{\"Id\":\"idSetRef1\",\"Version\":\"4.5.6.7.8.9.0\"},{\"Id\":\"idSetRef2_NoVersion\"}]}}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + } + + + + + // combinations of Status values with Decision values + @Test + public void testDecisionStatusMatch() { + // the tests in this method use different values and do not change structures, so we can re-use the objects + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + result.setStatus(status); + response.add(result); + + // StatusCode = OK + status.setStatusCode(StdStatusCode.STATUS_CODE_OK); + result.setDecision(Decision.PERMIT); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:ok\"}},\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + result.setDecision(Decision.DENY); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:ok\"}},\"Decision\":\"Deny\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + result.setDecision(Decision.NOTAPPLICABLE); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:ok\"}},\"Decision\":\"NotApplicable\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + result.setDecision(Decision.INDETERMINATE); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + result.setDecision(Decision.INDETERMINATE_DENY); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + result.setDecision(Decision.INDETERMINATE_DENYPERMIT); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + result.setDecision(Decision.INDETERMINATE_PERMIT); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + + + + + // StatusCode = SyntaxError + status.setStatusCode(StdStatusCode.STATUS_CODE_SYNTAX_ERROR); + result.setDecision(Decision.PERMIT); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + result.setDecision(Decision.DENY); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + result.setDecision(Decision.NOTAPPLICABLE); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + result.setDecision(Decision.INDETERMINATE); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:syntax-error\"}},\"Decision\":\"Indeterminate\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + result.setDecision(Decision.INDETERMINATE_DENY); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:syntax-error\"}},\"Decision\":\"Indeterminate{D}\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + result.setDecision(Decision.INDETERMINATE_DENYPERMIT); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:syntax-error\"}},\"Decision\":\"Indeterminate{DP}\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + result.setDecision(Decision.INDETERMINATE_PERMIT); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:syntax-error\"}},\"Decision\":\"Indeterminate{P}\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // StatusCode = ProcessingError + status.setStatusCode(StdStatusCode.STATUS_CODE_PROCESSING_ERROR); + result.setDecision(Decision.PERMIT); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + result.setDecision(Decision.DENY); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + result.setDecision(Decision.NOTAPPLICABLE); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + result.setDecision(Decision.INDETERMINATE); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:processing-error\"}},\"Decision\":\"Indeterminate\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + result.setDecision(Decision.INDETERMINATE_DENY); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:processing-error\"}},\"Decision\":\"Indeterminate{D}\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + result.setDecision(Decision.INDETERMINATE_DENYPERMIT); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:processing-error\"}},\"Decision\":\"Indeterminate{DP}\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + result.setDecision(Decision.INDETERMINATE_PERMIT); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:processing-error\"}},\"Decision\":\"Indeterminate{P}\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + + // StatusCode = MissingAttribute + status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); + result.setDecision(Decision.PERMIT); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + result.setDecision(Decision.DENY); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + result.setDecision(Decision.NOTAPPLICABLE); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + result.setDecision(Decision.INDETERMINATE); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"}},\"Decision\":\"Indeterminate\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + result.setDecision(Decision.INDETERMINATE_DENY); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"}},\"Decision\":\"Indeterminate{D}\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + result.setDecision(Decision.INDETERMINATE_DENYPERMIT); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"}},\"Decision\":\"Indeterminate{DP}\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + result.setDecision(Decision.INDETERMINATE_PERMIT); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"}},\"Decision\":\"Indeterminate{P}\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + } + + + + + // tests related to Status and its components + @Ignore //@Test + public void testStatus() { + // Status with no StatusCode - error + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + result.setStatus(status); + result.setDecision(Decision.PERMIT); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Status with StatusMessage when OK + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_OK); + status.setStatusMessage("I'm ok, you're ok"); + result.setStatus(status); + result.setDecision(Decision.PERMIT); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:ok\"},\"StatusMessage\":\"I'm ok, you're ok\"},\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // Status with StatusDetail when OK + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_OK); + StdMutableStatusDetail statusDetail = new StdMutableStatusDetail(); + status.setStatusDetail(statusDetail); + result.setStatus(status); + result.setDecision(Decision.PERMIT); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Status with StatusMessage when SyntaxError + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_SYNTAX_ERROR); + status.setStatusMessage("I'm ok, you're ok"); + result.setStatus(status); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:syntax-error\"},\"StatusMessage\":\"I'm ok, you're ok\"},\"Decision\":\"Indeterminate\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // Status with empty StatusDetail when SyntaxError + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_SYNTAX_ERROR); + statusDetail = new StdMutableStatusDetail(); + status.setStatusDetail(statusDetail); + result.setStatus(status); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // Status with StatusMessage when ProcessingError + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_PROCESSING_ERROR); + status.setStatusMessage("I'm ok, you're ok"); + result.setStatus(status); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:processing-error\"},\"StatusMessage\":\"I'm ok, you're ok\"},\"Decision\":\"Indeterminate\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // Status with empty StatusDetail when ProcessingError + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_PROCESSING_ERROR); + statusDetail = new StdMutableStatusDetail(); + status.setStatusDetail(statusDetail); + result.setStatus(status); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // Status with StatusMessage when MissingAttribute + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); + status.setStatusMessage("I'm ok, you're ok"); + result.setStatus(status); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"},\"StatusMessage\":\"I'm ok, you're ok\"},\"Decision\":\"Indeterminate\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // Status with empty StatusDetail when MissingAttribute + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); + statusDetail = new StdMutableStatusDetail(); + status.setStatusDetail(statusDetail); + result.setStatus(status); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"}},\"Decision\":\"Indeterminate\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + + // Status with StatusDetail with empty detail when MissingAttribute + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); + statusDetail = new StdMutableStatusDetail(); + StdMutableMissingAttributeDetail mad = new StdMutableMissingAttributeDetail(); + statusDetail.addMissingAttributeDetail(mad); + status.setStatusDetail(statusDetail); + result.setStatus(status); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Status with StatusDetail with valid detail with no value when MissingAttribute + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); + statusDetail = new StdMutableStatusDetail(); + mad = new StdMutableMissingAttributeDetail(); + mad.setAttributeId(new IdentifierImpl("mad")); + mad.setCategory(XACML3.ID_ACTION); + mad.setDataTypeId(DataTypes.DT_STRING.getId()); + statusDetail.addMissingAttributeDetail(mad); + status.setStatusDetail(statusDetail); + result.setStatus(status); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"},\"StatusDetail\":\"\"},\"Decision\":\"Indeterminate\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // Status with StatusDetail with valid detail with value when MissingAttribute + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); + statusDetail = new StdMutableStatusDetail(); + mad = new StdMutableMissingAttributeDetail(); + mad.setAttributeId(new IdentifierImpl("mad")); + mad.setCategory(XACML3.ID_ACTION); + mad.setDataTypeId(DataTypes.DT_STRING.getId()); + mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_STRING.getId(), "meh")); + statusDetail.addMissingAttributeDetail(mad); + status.setStatusDetail(statusDetail); + result.setStatus(status); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"},\"StatusDetail\":\"meh\"},\"Decision\":\"Indeterminate\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // Status with StatusDetail with array valid detail with value when MissingAttribute + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); + statusDetail = new StdMutableStatusDetail(); + mad = new StdMutableMissingAttributeDetail(); + mad.setAttributeId(new IdentifierImpl("mad")); + mad.setCategory(XACML3.ID_ACTION); + mad.setDataTypeId(DataTypes.DT_STRING.getId()); + mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_STRING.getId(), "meh")); + mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_STRING.getId(), "nu?")); + statusDetail.addMissingAttributeDetail(mad); + status.setStatusDetail(statusDetail); + result.setStatus(status); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"},\"StatusDetail\":\"mehnu?\"},\"Decision\":\"Indeterminate\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // Status with StatusDetail with valid detail with Integer value when MissingAttribute + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); + statusDetail = new StdMutableStatusDetail(); + mad = new StdMutableMissingAttributeDetail(); + mad.setAttributeId(new IdentifierImpl("mad")); + mad.setCategory(XACML3.ID_ACTION); + mad.setDataTypeId(DataTypes.DT_INTEGER.getId()); + mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(1111))); + statusDetail.addMissingAttributeDetail(mad); + status.setStatusDetail(statusDetail); + result.setStatus(status); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); +// assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"},\"StatusDetail\":\"1111\"},\"Decision\":\"Indeterminate\"}]}", jsonResponse); + } catch (Exception e) { + java.io.StringWriter sw = new java.io.StringWriter(); + java.io.PrintWriter pw = new java.io.PrintWriter(sw); + e.printStackTrace(pw); + + + fail("operation failed, e="+e + sw.toString()); + } + + // Status with StatusDetail with array valid detail with Integer value when MissingAttribute + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); + statusDetail = new StdMutableStatusDetail(); + mad = new StdMutableMissingAttributeDetail(); + mad.setAttributeId(new IdentifierImpl("mad")); + mad.setCategory(XACML3.ID_ACTION); + mad.setDataTypeId(DataTypes.DT_STRING.getId()); + mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(1111))); + mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(2222))); + statusDetail.addMissingAttributeDetail(mad); + status.setStatusDetail(statusDetail); + result.setStatus(status); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"},\"StatusDetail\":\"11112222\"},\"Decision\":\"Indeterminate\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + +// StringNamespaceContext snc = new StringNamespaceContext(); +// try { +// snc.add("defaultURI"); +// snc.add("md", "referenceForMD"); +// } catch (Exception e) { +// fail("unable to create NamespaceContext e="+e); +// } +// XPathExpressionWrapper xpathExpressionWrapper = new XPathExpressionWrapper(snc, "//md:record"); +// +//TODO - assume that we will never try to pass back an XPathExpression in a MissingAttributeDetail - it doesn't make sense and is unclear how to put into XML +// // Status with StatusDetail with valid detail with XPathExpression value when MissingAttribute +// response = new StdMutableResponse(); +// result = new StdMutableResult(); +// status = new StdMutableStatus(); +// status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); +// statusDetail = new StdMutableStatusDetail(); +// mad = new StdMutableMissingAttributeDetail(); +// mad.setAttributeId(new IdentifierImpl("mad")); +// mad.setCategory(XACML3.ID_ACTION); +// mad.setDataTypeId(DataTypes.DT_STRING.getId()); +// mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("xpathCategoryId"))); +// statusDetail.addMissingAttributeDetail(mad); +// status.setStatusDetail(statusDetail); +// result.setStatus(status); +// result.setDecision(Decision.INDETERMINATE); +// response.add(result); +// try { +// jsonResponse = JSONResponse.toString(response, false); +// assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"},\"StatusDetail\":\"1111urn:oasis:names:tc:xacml:1.0:actionmadhttp://www.w3.org/2001/XMLSchema#string\"},\"Decision\":\"Indeterminate\"}]}", jsonResponse); +// } catch (Exception e) { +// fail("operation failed, e="+e); +// } +// +// // Status with StatusDetail with array valid detail with XPathExpression value when MissingAttribute +// response = new StdMutableResponse(); +// result = new StdMutableResult(); +// status = new StdMutableStatus(); +// status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); +// statusDetail = new StdMutableStatusDetail(); +// mad = new StdMutableMissingAttributeDetail(); +// mad.setAttributeId(new IdentifierImpl("mad")); +// mad.setCategory(XACML3.ID_ACTION); +// mad.setDataTypeId(DataTypes.DT_STRING.getId()); +// mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("xpathCategoryId1"))); +// mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("xpathCategoryId2"))); +// statusDetail.addMissingAttributeDetail(mad); +// status.setStatusDetail(statusDetail); +// result.setStatus(status); +// result.setDecision(Decision.INDETERMINATE); +// response.add(result); +// try { +// jsonResponse = JSONResponse.toString(response, false); +// assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"},\"StatusDetail\":\"11112222urn:oasis:names:tc:xacml:1.0:actionmadhttp://www.w3.org/2001/XMLSchema#string\"},\"Decision\":\"Indeterminate\"}]}", jsonResponse); +// } catch (Exception e) { +// fail("operation failed, e="+e); +// } + +//TODO - try with other data types, esp XPathExpression + + // Status with StatusDetail with array valid detail with value when SyntaxError + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_SYNTAX_ERROR); + statusDetail = new StdMutableStatusDetail(); + mad = new StdMutableMissingAttributeDetail(); + mad.setAttributeId(new IdentifierImpl("mad")); + mad.setCategory(XACML3.ID_ACTION); + mad.setDataTypeId(DataTypes.DT_STRING.getId()); + mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_STRING.getId(), "meh")); + mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_STRING.getId(), "nu?")); + statusDetail.addMissingAttributeDetail(mad); + status.setStatusDetail(statusDetail); + result.setStatus(status); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Status with StatusDetail with array valid detail with value when ProcessingError + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_PROCESSING_ERROR); + statusDetail = new StdMutableStatusDetail(); + mad = new StdMutableMissingAttributeDetail(); + mad.setAttributeId(new IdentifierImpl("mad")); + mad.setCategory(XACML3.ID_ACTION); + mad.setDataTypeId(DataTypes.DT_STRING.getId()); + mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_STRING.getId(), "meh")); + mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_STRING.getId(), "nu?")); + statusDetail.addMissingAttributeDetail(mad); + status.setStatusDetail(statusDetail); + result.setStatus(status); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + + // Status with nested child StatusCodes (child status containing child status containing...) + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + StdStatusCode child1StatusCode = new StdStatusCode(new IdentifierImpl("child1StatusCode")); + StdStatusCode statusCode = new StdStatusCode(XACML3.ID_STATUS_OK, child1StatusCode); + status = new StdMutableStatus(statusCode); + status.setStatusMessage("I'm ok, you're ok"); + result.setStatus(status); + result.setDecision(Decision.PERMIT); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"StatusCode\":{\"Value\":\"child1StatusCode\"},\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:ok\"},\"StatusMessage\":\"I'm ok, you're ok\"},\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + StdStatusCode childChildChildStatusCode = new StdStatusCode(new IdentifierImpl("childChildChildStatusCode")); + StdStatusCode childChildStatusCode = new StdStatusCode(new IdentifierImpl("childChildStatusCode"), childChildChildStatusCode); + child1StatusCode = new StdStatusCode(new IdentifierImpl("child1StatusCode"), childChildStatusCode); + statusCode = new StdStatusCode(XACML3.ID_STATUS_OK, child1StatusCode); + status = new StdMutableStatus(statusCode); + status.setStatusMessage("I'm ok, you're ok"); + result.setStatus(status); + result.setDecision(Decision.PERMIT); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"StatusCode\":{\"StatusCode\":{\"StatusCode\":{\"Value\":\"childChildChildStatusCode\"},\"Value\":\"childChildStatusCode\"},\"Value\":\"child1StatusCode\"},\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:ok\"},\"StatusMessage\":\"I'm ok, you're ok\"},\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + } + + + + @Ignore //@Test + public void testObligations() { + + // create an XPathExpression for use later + StringNamespaceContext snc = new StringNamespaceContext(); + try { + snc.add("defaultURI"); + snc.add("md", "referenceForMD"); + } catch (Exception e) { + fail("unable to create NamespaceContext e="+e); + } + XPathExpressionWrapper xpathExpressionWrapper = new XPathExpressionWrapper(snc, "//md:record"); + XPathExpressionWrapper xpathExpressionWrapper2 = new XPathExpressionWrapper(snc, "//md:hospital"); + + StdMutableObligation obligation; + + // test Obligation single decision no attributes + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + obligation = new StdMutableObligation(); + obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + result.addObligation(obligation); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Obligations\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"}],\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // obligation missing Id + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + obligation = new StdMutableObligation(); + result.addObligation(obligation); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + + // AttributeAssignment - with AttributeId, Value, Category, DataType, Issuer + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + obligation = new StdMutableObligation(); + obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "obligation-issuer1", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Bart"))); + result.addObligation(obligation); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Obligations\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Issuer\":\"obligation-issuer1\",\"Value\":\"Bart\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // AttributeAssignment - with AttributeId, Value, no Category, DataType, Issuer + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + obligation = new StdMutableObligation(); + obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + null, + XACML3.ID_SUBJECT, + "obligation-issuer1", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Bart"))); + result.addObligation(obligation); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Obligations\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Issuer\":\"obligation-issuer1\",\"Value\":\"Bart\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // AttributeAssignment - Missing AttributeId + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + obligation = new StdMutableObligation(); + obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + null, + "obligation-issuer1", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Bart"))); + result.addObligation(obligation); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // AttributeAssignment - Missing Value + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + obligation = new StdMutableObligation(); + obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "obligation-issuer1", + null)); + result.addObligation(obligation); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Obligations\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Issuer\":\"obligation-issuer1\",\"Value\":\"\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // AttributeAssignment - missing DataType + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + obligation = new StdMutableObligation(); + obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "obligation-issuer1", + new StdAttributeValue(null, "Bart"))); + result.addObligation(obligation); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Obligations\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Issuer\":\"obligation-issuer1\",\"Value\":\"Bart\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // AttributeAssignment - missing issuer + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + obligation = new StdMutableObligation(); + obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + null, + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Bart"))); + result.addObligation(obligation); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Obligations\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Value\":\"Bart\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // AttributeAssignment - Integer type + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + obligation = new StdMutableObligation(); + obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + null, + new StdAttributeValue(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(1111)))); + result.addObligation(obligation); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Obligations\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Value\":1111,\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#integer\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // AttributeAssignment - XPathExpression type + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + obligation = new StdMutableObligation(); + obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + null, + new StdAttributeValue(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("SimpleXPathCategory")))); + result.addObligation(obligation); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Obligations\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Value\":{\"Namespaces\":[{\"Namespace\":\"referenceForMD\",\"Prefix\":\"md\"},{\"Namespace\":\"defaultURI\"}],\"XPathCategory\":\"SimpleXPathCategory\",\"XPath\":\"//md:record\"},\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + + + // + // Technically arrays cannot occur in Obligations and Advice elements. The XML spec boils down to the following definition: + // + // value + // value + // : + // may have multiple elements. + // For Obligations and Advice we can simulate an array by having multiple AttributeAssignment elements with the same Category, Id and Issuer. + // + + + // AttributeAssignment - Multiple values with same Category and Id (one way of doing array) + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + obligation = new StdMutableObligation(); + obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "obligation-issuer1", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Bart"))); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "obligation-issuer1", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Lisa"))); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "obligation-issuer1", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Maggie"))); + result.addObligation(obligation); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Obligations\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Issuer\":\"obligation-issuer1\",\"Value\":\"Bart\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"},{\"Issuer\":\"obligation-issuer1\",\"Value\":\"Lisa\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"},{\"Issuer\":\"obligation-issuer1\",\"Value\":\"Maggie\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // AttributeAssignment - Multiple Integer values with same Category and Id (one way of doing array) + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + obligation = new StdMutableObligation(); + obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "obligation-issuer1", + new StdAttributeValue(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(1111)))); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "obligation-issuer1", + new StdAttributeValue(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(2222)))); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "obligation-issuer1", + new StdAttributeValue(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(3333)))); + result.addObligation(obligation); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Obligations\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Issuer\":\"obligation-issuer1\",\"Value\":1111,\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#integer\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"},{\"Issuer\":\"obligation-issuer1\",\"Value\":2222,\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#integer\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"},{\"Issuer\":\"obligation-issuer1\",\"Value\":3333,\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#integer\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // Multiple XPathExpression values with same Category and Id (one way of doing array) + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + obligation = new StdMutableObligation(); + obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + null, + new StdAttributeValue(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("SimpleXPathCategory")))); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + null, + new StdAttributeValue(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper2, new IdentifierImpl("SimpleXPathCategory")))); + result.addObligation(obligation); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Obligations\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Value\":{\"Namespaces\":[{\"Namespace\":\"referenceForMD\",\"Prefix\":\"md\"},{\"Namespace\":\"defaultURI\"}],\"XPathCategory\":\"SimpleXPathCategory\",\"XPath\":\"//md:record\"},\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"},{\"Value\":{\"Namespaces\":[{\"Namespace\":\"referenceForMD\",\"Prefix\":\"md\"},{\"Namespace\":\"defaultURI\"}],\"XPathCategory\":\"SimpleXPathCategory\",\"XPath\":\"//md:hospital\"},\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + } + + + + + @Ignore //@Test + public void testAdvice() { + + // create an XPathExpression for use later + StringNamespaceContext snc = new StringNamespaceContext(); + try { + snc.add("defaultURI"); + snc.add("md", "referenceForMD"); + } catch (Exception e) { + fail("unable to create NamespaceContext e="+e); + } + XPathExpressionWrapper xpathExpressionWrapper = new XPathExpressionWrapper(snc, "//md:record"); + XPathExpressionWrapper xpathExpressionWrapper2 = new XPathExpressionWrapper(snc, "//md:hospital"); + + StdMutableAdvice Advice; + + // test Advice single decision no attributes + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + Advice = new StdMutableAdvice(); + Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + result.addAdvice(Advice); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Decision\":\"Permit\",\"AssociatedAdvice\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"}]}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // Advice missing Id + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + Advice = new StdMutableAdvice(); + result.addAdvice(Advice); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + + // AttributeAssignment - with AttributeId, Value, Category, DataType, Issuer + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + Advice = new StdMutableAdvice(); + Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "Advice-issuer1", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Bart"))); + result.addAdvice(Advice); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Decision\":\"Permit\",\"AssociatedAdvice\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Issuer\":\"Advice-issuer1\",\"Value\":\"Bart\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}]}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // AttributeAssignment - with AttributeId, Value, no Category, DataType, Issuer + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + Advice = new StdMutableAdvice(); + Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + null, + XACML3.ID_SUBJECT, + "Advice-issuer1", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Bart"))); + result.addAdvice(Advice); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Decision\":\"Permit\",\"AssociatedAdvice\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Issuer\":\"Advice-issuer1\",\"Value\":\"Bart\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}]}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // AttributeAssignment - Missing AttributeId + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + Advice = new StdMutableAdvice(); + Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + null, + "Advice-issuer1", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Bart"))); + result.addAdvice(Advice); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // AttributeAssignment - Missing Value + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + Advice = new StdMutableAdvice(); + Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "Advice-issuer1", + null)); + result.addAdvice(Advice); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Decision\":\"Permit\",\"AssociatedAdvice\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Issuer\":\"Advice-issuer1\",\"Value\":\"\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}]}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // AttributeAssignment - missing DataType + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + Advice = new StdMutableAdvice(); + Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "Advice-issuer1", + new StdAttributeValue(null, "Bart"))); + result.addAdvice(Advice); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Decision\":\"Permit\",\"AssociatedAdvice\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Issuer\":\"Advice-issuer1\",\"Value\":\"Bart\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}]}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // AttributeAssignment - missing issuer + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + Advice = new StdMutableAdvice(); + Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + null, + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Bart"))); + result.addAdvice(Advice); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Decision\":\"Permit\",\"AssociatedAdvice\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Value\":\"Bart\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}]}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // AttributeAssignment - Integer type + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + Advice = new StdMutableAdvice(); + Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + null, + new StdAttributeValue(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(1111)))); + result.addAdvice(Advice); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Decision\":\"Permit\",\"AssociatedAdvice\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Value\":1111,\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#integer\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}]}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // AttributeAssignment - XPathExpression type + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + Advice = new StdMutableAdvice(); + Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + null, + new StdAttributeValue(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("SimpleXPathCategory")))); + result.addAdvice(Advice); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Decision\":\"Permit\",\"AssociatedAdvice\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Value\":{\"Namespaces\":[{\"Namespace\":\"referenceForMD\",\"Prefix\":\"md\"},{\"Namespace\":\"defaultURI\"}],\"XPathCategory\":\"SimpleXPathCategory\",\"XPath\":\"//md:record\"},\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}]}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + + + // + // Technically arrays cannot occur in Obligations and Advice elements. The XML spec boils down to the following definition: + // + // value + // value + // : + // may have multiple elements. + // For Obligations and Advice we can simulate an array by having multiple AttributeAssignment elements with the same Category, Id and Issuer. + // + + // AttributeAssignment - Multiple values with same Category and Id (one way of doing array) + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + Advice = new StdMutableAdvice(); + Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "Advice-issuer1", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Bart"))); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "Advice-issuer1", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Lisa"))); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "Advice-issuer1", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Maggie"))); + result.addAdvice(Advice); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Decision\":\"Permit\",\"AssociatedAdvice\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Issuer\":\"Advice-issuer1\",\"Value\":\"Bart\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"},{\"Issuer\":\"Advice-issuer1\",\"Value\":\"Lisa\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"},{\"Issuer\":\"Advice-issuer1\",\"Value\":\"Maggie\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}]}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // AttributeAssignment - Multiple Integer values with same Category and Id (one way of doing array) + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + Advice = new StdMutableAdvice(); + Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "Advice-issuer1", + new StdAttributeValue(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(1111)))); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "Advice-issuer1", + new StdAttributeValue(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(2222)))); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "Advice-issuer1", + new StdAttributeValue(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(3333)))); + result.addAdvice(Advice); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Decision\":\"Permit\",\"AssociatedAdvice\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Issuer\":\"Advice-issuer1\",\"Value\":1111,\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#integer\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"},{\"Issuer\":\"Advice-issuer1\",\"Value\":2222,\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#integer\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"},{\"Issuer\":\"Advice-issuer1\",\"Value\":3333,\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#integer\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}]}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // Multiple XPathExpression values with same Category and Id (one way of doing array) + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + Advice = new StdMutableAdvice(); + Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + null, + new StdAttributeValue(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("SimpleXPathCategory")))); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + null, + new StdAttributeValue(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper2, new IdentifierImpl("SimpleXPathCategory")))); + result.addAdvice(Advice); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Decision\":\"Permit\",\"AssociatedAdvice\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Value\":{\"Namespaces\":[{\"Namespace\":\"referenceForMD\",\"Prefix\":\"md\"},{\"Namespace\":\"defaultURI\"}],\"XPathCategory\":\"SimpleXPathCategory\",\"XPath\":\"//md:record\"},\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"},{\"Value\":{\"Namespaces\":[{\"Namespace\":\"referenceForMD\",\"Prefix\":\"md\"},{\"Namespace\":\"defaultURI\"}],\"XPathCategory\":\"SimpleXPathCategory\",\"XPath\":\"//md:hospital\"},\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}]}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + } + + + + + + + + + + + // Attributes tests + @Ignore //@Test + public void testAttributes() { + + // create an XPathExpression for use later + StringNamespaceContext snc = new StringNamespaceContext(); + try { + snc.add("defaultURI"); + snc.add("md", "referenceForMD"); + } catch (Exception e) { + fail("unable to create NamespaceContext e="+e); + } + XPathExpressionWrapper xpathExpressionWrapper = new XPathExpressionWrapper(snc, "//md:record"); + + + Identifier categoryIdentifier; + List attrList = new ArrayList(); + StdMutableAttribute mutableAttribute; + + // Attr list with no entries + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Category\":[{\"CategoryId\":\"firstCategory\",\"Attribute\":[]}],\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // one Attribute + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true)); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Category\":[{\"CategoryId\":\"firstCategory\",\"Attribute\":[{\"Issuer\":\"AIssue\",\"Value\":\"Apu\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent1\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // multiple attributes + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent2"), new StdAttributeValue(DataTypes.DT_YEARMONTHDURATION.getId(), "P10Y4M"), "BIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent3"), new StdAttributeValue(DataTypes.DT_DOUBLE.getId(), 765.432), "CIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent4"), new StdAttributeValue(DataTypes.DT_BOOLEAN.getId(), true), "DIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent5"), new StdAttributeValue(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(4567)), "EIssue", true)); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Category\":[{\"CategoryId\":\"firstCategory\",\"Attribute\":[{\"Issuer\":\"AIssue\",\"Value\":\"Apu\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent1\"},{\"Issuer\":\"BIssue\",\"Value\":\"P10Y4M\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#yearMonthDuration\",\"AttributeId\":\"attrIdent2\"},{\"Issuer\":\"CIssue\",\"Value\":765.432,\"DataType\":\"http://www.w3.org/2001/XMLSchema#double\",\"AttributeId\":\"attrIdent3\"},{\"Issuer\":\"DIssue\",\"Value\":true,\"DataType\":\"http://www.w3.org/2001/XMLSchema#boolean\",\"AttributeId\":\"attrIdent4\"},{\"Issuer\":\"EIssue\",\"Value\":4567,\"DataType\":\"http://www.w3.org/2001/XMLSchema#integer\",\"AttributeId\":\"attrIdent5\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // IncludeInResult=false/true + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", false)); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Category\":[{\"CategoryId\":\"firstCategory\",\"Attribute\":[]}],\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // Missing AttributeId (mandatory) + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + attrList.add(new StdAttribute(categoryIdentifier, null, new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true)); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Missing mandatory Value + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), null), "AIssue", true)); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Missing optional Issuer + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu"), null, true)); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Category\":[{\"CategoryId\":\"firstCategory\",\"Attribute\":[{\"Value\":\"Apu\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent1\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // missing optional DataType + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(null, "Apu"), "AIssue", true)); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Category\":[{\"CategoryId\":\"firstCategory\",\"Attribute\":[{\"Issuer\":\"AIssue\",\"Value\":\"Apu\",\"AttributeId\":\"attrIdent1\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // same id, same type different issuer + // (This is not an array of values because issuer is different) + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Bart"), "BIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Simpson"), "CIssue", true)); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Category\":[{\"CategoryId\":\"firstCategory\",\"Attribute\":[{\"Issuer\":\"AIssue\",\"Value\":\"Apu\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent1\"},{\"Issuer\":\"BIssue\",\"Value\":\"Bart\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent1\"},{\"Issuer\":\"CIssue\",\"Value\":\"Simpson\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent1\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // same id, same type different issuer + // (This is effectively an array of values, but we return them as separate values to the client) + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Bart"), "AIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Simpson"), "AIssue", true)); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Category\":[{\"CategoryId\":\"firstCategory\",\"Attribute\":[{\"Issuer\":\"AIssue\",\"Value\":\"Apu\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent1\"},{\"Issuer\":\"AIssue\",\"Value\":\"Bart\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent1\"},{\"Issuer\":\"AIssue\",\"Value\":\"Simpson\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent1\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // same Id, different types, same issuer + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_YEARMONTHDURATION.getId(), "P10Y4M"), "AIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_DOUBLE.getId(), 765.432), "AIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_BOOLEAN.getId(), true), "AIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(4567)), "AIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(4567)), "AIssue", true)); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Category\":[{\"CategoryId\":\"firstCategory\",\"Attribute\":[{\"Issuer\":\"AIssue\",\"Value\":\"Apu\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent1\"},{\"Issuer\":\"AIssue\",\"Value\":\"P10Y4M\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#yearMonthDuration\",\"AttributeId\":\"attrIdent1\"},{\"Issuer\":\"AIssue\",\"Value\":765.432,\"DataType\":\"http://www.w3.org/2001/XMLSchema#double\",\"AttributeId\":\"attrIdent1\"},{\"Issuer\":\"AIssue\",\"Value\":true,\"DataType\":\"http://www.w3.org/2001/XMLSchema#boolean\",\"AttributeId\":\"attrIdent1\"},{\"Issuer\":\"AIssue\",\"Value\":4567,\"DataType\":\"http://www.w3.org/2001/XMLSchema#integer\",\"AttributeId\":\"attrIdent1\"},{\"Issuer\":\"AIssue\",\"Value\":4567,\"DataType\":\"http://www.w3.org/2001/XMLSchema#integer\",\"AttributeId\":\"attrIdent1\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // same Id, different types, different issuer + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_YEARMONTHDURATION.getId(), "P10Y4M"), "BIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_DOUBLE.getId(), 765.432), "CIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_BOOLEAN.getId(), true), "DIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(4567)), "EIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(4567)), null, true)); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Category\":[{\"CategoryId\":\"firstCategory\",\"Attribute\":[{\"Issuer\":\"AIssue\",\"Value\":\"Apu\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent1\"},{\"Issuer\":\"BIssue\",\"Value\":\"P10Y4M\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#yearMonthDuration\",\"AttributeId\":\"attrIdent1\"},{\"Issuer\":\"CIssue\",\"Value\":765.432,\"DataType\":\"http://www.w3.org/2001/XMLSchema#double\",\"AttributeId\":\"attrIdent1\"},{\"Issuer\":\"DIssue\",\"Value\":true,\"DataType\":\"http://www.w3.org/2001/XMLSchema#boolean\",\"AttributeId\":\"attrIdent1\"},{\"Issuer\":\"EIssue\",\"Value\":4567,\"DataType\":\"http://www.w3.org/2001/XMLSchema#integer\",\"AttributeId\":\"attrIdent1\"},{\"Value\":4567,\"DataType\":\"http://www.w3.org/2001/XMLSchema#integer\",\"AttributeId\":\"attrIdent1\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // different Id, different types, same issuer + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent2"), new StdAttributeValue(DataTypes.DT_YEARMONTHDURATION.getId(), "AIssue"), "BIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent3"), new StdAttributeValue(DataTypes.DT_DOUBLE.getId(), 765.432), "AIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent4"), new StdAttributeValue(DataTypes.DT_BOOLEAN.getId(), true), "AIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent5"), new StdAttributeValue(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(4567)), "AIssue", true)); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Category\":[{\"CategoryId\":\"firstCategory\",\"Attribute\":[{\"Issuer\":\"AIssue\",\"Value\":\"Apu\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent1\"},{\"Issuer\":\"BIssue\",\"Value\":\"AIssue\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#yearMonthDuration\",\"AttributeId\":\"attrIdent2\"},{\"Issuer\":\"AIssue\",\"Value\":765.432,\"DataType\":\"http://www.w3.org/2001/XMLSchema#double\",\"AttributeId\":\"attrIdent3\"},{\"Issuer\":\"AIssue\",\"Value\":true,\"DataType\":\"http://www.w3.org/2001/XMLSchema#boolean\",\"AttributeId\":\"attrIdent4\"},{\"Issuer\":\"AIssue\",\"Value\":4567,\"DataType\":\"http://www.w3.org/2001/XMLSchema#integer\",\"AttributeId\":\"attrIdent5\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // one Attribute of type XPathExpression (the only complex data type) + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("xpathCategory")), "AIssue", true)); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Category\":[{\"CategoryId\":\"firstCategory\",\"Attribute\":[{\"Issuer\":\"AIssue\",\"Value\":{\"Namespaces\":[{\"Namespace\":\"referenceForMD\",\"Prefix\":\"md\"},{\"Namespace\":\"defaultURI\"}],\"XPathCategory\":\"xpathCategory\",\"XPath\":\"//md:record\"},\"DataType\":\"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\",\"AttributeId\":\"attrIdent1\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // multiple sets of values + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent2"), new StdAttributeValue(DataTypes.DT_YEARMONTHDURATION.getId(), "P10Y4M"), "BIssue", false)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent3"), new StdAttributeValue(DataTypes.DT_DOUBLE.getId(), 765.432), "CIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent4"), new StdAttributeValue(DataTypes.DT_BOOLEAN.getId(), true), "DIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent5"), new StdAttributeValue(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(4567)), "EIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrNoIssuer"), new StdAttributeValue(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(4567)), null, true)); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + categoryIdentifier = new IdentifierImpl("secondCategory"); + Attribute[] secondAttrList = { + new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent12"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu2"), "AIssue2", true), + new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent22"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Abc2"), "BIssue2", false), + new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent32"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Der2"), "CIssue2", true) }; + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, Arrays.asList(secondAttrList))); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Category\":[{\"CategoryId\":\"firstCategory\",\"Attribute\":[{\"Issuer\":\"AIssue\",\"Value\":\"Apu\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent1\"},{\"Issuer\":\"CIssue\",\"Value\":765.432,\"DataType\":\"http://www.w3.org/2001/XMLSchema#double\",\"AttributeId\":\"attrIdent3\"},{\"Issuer\":\"DIssue\",\"Value\":true,\"DataType\":\"http://www.w3.org/2001/XMLSchema#boolean\",\"AttributeId\":\"attrIdent4\"},{\"Issuer\":\"EIssue\",\"Value\":4567,\"DataType\":\"http://www.w3.org/2001/XMLSchema#integer\",\"AttributeId\":\"attrIdent5\"},{\"Value\":4567,\"DataType\":\"http://www.w3.org/2001/XMLSchema#integer\",\"AttributeId\":\"attrNoIssuer\"}]},{\"CategoryId\":\"secondCategory\",\"Attribute\":[{\"Issuer\":\"AIssue2\",\"Value\":\"Apu2\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent12\"},{\"Issuer\":\"CIssue2\",\"Value\":\"Der2\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent32\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // array of values - same type + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + attrList.clear(); + categoryIdentifier = new IdentifierImpl("firstCategory"); + mutableAttribute = new StdMutableAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), (Collection>)null, "AIssue", true); + + mutableAttribute.addValue(new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu")); + mutableAttribute.addValue(new StdAttributeValue(DataTypes.DT_STRING.getId(), "Bart")); + mutableAttribute.addValue(new StdAttributeValue(DataTypes.DT_STRING.getId(), "Homer")); + mutableAttribute.addValue(new StdAttributeValue(DataTypes.DT_STRING.getId(), "Ned")); + + attrList.add(mutableAttribute); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Category\":[{\"CategoryId\":\"firstCategory\",\"Attribute\":[{\"Issuer\":\"AIssue\",\"Value\":[\"Apu\",\"Bart\",\"Homer\",\"Ned\"],\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent1\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // array of values - compatible different types + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + attrList.clear(); + categoryIdentifier = new IdentifierImpl("firstCategory"); + mutableAttribute = new StdMutableAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), (Collection>)null, "AIssue", true); + + mutableAttribute.addValue(new StdAttributeValue(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(4567))); + mutableAttribute.addValue(new StdAttributeValue(DataTypes.DT_DOUBLE.getId(), 765.432)); + mutableAttribute.addValue(new StdAttributeValue(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(4567))); + attrList.add(mutableAttribute); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Category\":[{\"CategoryId\":\"firstCategory\",\"Attribute\":[{\"Issuer\":\"AIssue\",\"Value\":[4567,765.432,4567],\"DataType\":\"http://www.w3.org/2001/XMLSchema#double\",\"AttributeId\":\"attrIdent1\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // array of values - incompatible different types + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + attrList.clear(); + categoryIdentifier = new IdentifierImpl("firstCategory"); + mutableAttribute = new StdMutableAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), (Collection>)null, "AIssue", true); + + mutableAttribute.addValue(new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu")); + mutableAttribute.addValue(new StdAttributeValue(DataTypes.DT_YEARMONTHDURATION.getId(), "P10Y4M")); + mutableAttribute.addValue(new StdAttributeValue(DataTypes.DT_DOUBLE.getId(), 765.432)); + mutableAttribute.addValue(new StdAttributeValue(DataTypes.DT_BOOLEAN.getId(), true)); + mutableAttribute.addValue(new StdAttributeValue(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(4567))); + mutableAttribute.addValue(new StdAttributeValue(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(4567))); + attrList.add(mutableAttribute); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + } + + + + + + // PolicyIdentifier tests + @Ignore //@Test + public void testPolicyIdentifier() { + + StdIdReference policyIdentifier1 = null; + StdIdReference policyIdentifier2 = null; + StdIdReference policySetIdentifier1 = null; + StdIdReference policySetIdentifier2 = null; + + // multiple PolicyIdentifiers of both types + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + try { + policyIdentifier1 = new StdIdReference(new IdentifierImpl("idRef1"), StdVersion.newInstance("1.2.3")); + policyIdentifier2 = new StdIdReference(new IdentifierImpl("idRef2_NoVersion")); + policySetIdentifier1 = new StdIdReference(new IdentifierImpl("idSetRef1"), StdVersion.newInstance("4.5.6.7.8.9.0")); + policySetIdentifier2 = new StdIdReference(new IdentifierImpl("idSetRef2_NoVersion")); + } catch (ParseException e1) { + fail("creating policyIds, e="+e1); + } + result.addPolicyIdentifier(policyIdentifier1); + result.addPolicyIdentifier(policyIdentifier2); + result.addPolicySetIdentifier(policySetIdentifier1); + result.addPolicySetIdentifier(policySetIdentifier2); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Decision\":\"Permit\",\"PolicyIdentifier\":{\"PolicyIdReference\":[{\"Id\":\"idRef1\",\"Version\":\"1.2.3\"},{\"Id\":\"idRef2_NoVersion\"}],\"PolicySetIdReference\":[{\"Id\":\"idSetRef1\",\"Version\":\"4.5.6.7.8.9.0\"},{\"Id\":\"idSetRef2_NoVersion\"}]}}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // PolicyIdentifier exists but has no IdReferences + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + policyIdentifier1 = null; + result.addPolicyIdentifier(policyIdentifier1); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // PolicySetIdentifier exists but has not IdReferences + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + policySetIdentifier1 = null; + result.addPolicyIdentifier(policySetIdentifier1); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // PolicyIdentifier with PolicyIdReference and no PolicySetIdReference + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + try { + policyIdentifier1 = new StdIdReference(new IdentifierImpl("idRef1"), StdVersion.newInstance("1.2.3")); + } catch (ParseException e1) { + fail("creating policyIds, e="+e1); + } + result.addPolicyIdentifier(policyIdentifier1); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Decision\":\"Permit\",\"PolicyIdentifier\":{\"PolicyIdReference\":[{\"Id\":\"idRef1\",\"Version\":\"1.2.3\"}]}}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + + // PolicyIdentifier with no PolicyIdReference and with PolicySetIdReference + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + try { + policySetIdentifier1 = new StdIdReference(new IdentifierImpl("idSetRef1"), StdVersion.newInstance("4.5.6.7.8.9.0")); + } catch (ParseException e1) { + fail("creating policyIds, e="+e1); + } + result.addPolicySetIdentifier(policySetIdentifier1); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Decision\":\"Permit\",\"PolicyIdentifier\":{\"PolicySetIdReference\":[{\"Id\":\"idSetRef1\",\"Version\":\"4.5.6.7.8.9.0\"}]}}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // IdReferences without version + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + + policyIdentifier1 = new StdIdReference(new IdentifierImpl("idRef1"), null); + policyIdentifier2 = new StdIdReference(new IdentifierImpl("idRef2_NoVersion")); + policySetIdentifier1 = new StdIdReference(new IdentifierImpl("idSetRef1")); + policySetIdentifier2 = new StdIdReference(new IdentifierImpl("idSetRef2_NoVersion")); + + result.addPolicyIdentifier(policyIdentifier1); + result.addPolicyIdentifier(policyIdentifier2); + result.addPolicySetIdentifier(policySetIdentifier1); + result.addPolicySetIdentifier(policySetIdentifier2); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Decision\":\"Permit\",\"PolicyIdentifier\":{\"PolicyIdReference\":[{\"Id\":\"idRef1\"},{\"Id\":\"idRef2_NoVersion\"}],\"PolicySetIdReference\":[{\"Id\":\"idSetRef1\"},{\"Id\":\"idSetRef2_NoVersion\"}]}}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + } + + +//TODO - the JSON and XML spec imply that the Result Attributes may include the Content (It is part of the UML) + + + // test indentation??? + + // order does not matter?? + +} + + + + + + + + + + + + + + + + diff --git a/ECOMP-TEST/src/test/resources/log4j.properties b/ECOMP-TEST/src/test/resources/log4j.properties new file mode 100644 index 000000000..f7e787eb8 --- /dev/null +++ b/ECOMP-TEST/src/test/resources/log4j.properties @@ -0,0 +1,42 @@ +### +# ============LICENSE_START======================================================= +# ECOMP-TEST +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +# +# Use this properties for debugging and development. +# +# +# Set root logger level to DEBUG and its only appender to A1. +log4j.rootLogger=INFO, MAIN_LOG + +# A1 is set to be a ConsoleAppender. +log4j.appender.MAIN_LOG=org.apache.log4j.ConsoleAppender + +# A1 uses PatternLayout. +log4j.appender.MAIN_LOG.layout=org.apache.log4j.PatternLayout +log4j.appender.MAIN_LOG.layout.ConversionPattern=%d{yyyy_MM_dd_HH_mm_ss_SSS} [%t] %-5p %l- %m%n + +# +# This is specifically for Xacml request/response logging +# +log4j.logger.xacml.request=INFO, REQUEST_LOG + +log4j.appender.REQUEST_LOG=org.apache.log4j.ConsoleAppender +log4j.appender.REQUEST_LOG.layout=org.apache.log4j.PatternLayout +log4j.appender.REQUEST_LOG.layout.ConversionPattern=%d{yyyy_MM_dd_HH_mm_ss_SSS} %m%n diff --git a/ECOMP-TEST/src/test/resources/logging.properties b/ECOMP-TEST/src/test/resources/logging.properties new file mode 100644 index 000000000..8d4fab09b --- /dev/null +++ b/ECOMP-TEST/src/test/resources/logging.properties @@ -0,0 +1,32 @@ +### +# ============LICENSE_START======================================================= +# ECOMP-TEST +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +handlers = java.util.logging.ConsoleHandler, java.util.logging.FileHandler + +.level = FINE + +java.util.logging.SimpleFormatter.format=%4$s: %5$s %n + +java.util.logging.ConsoleHandler.level = FINEST +java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter + +java.util.logging.FileHandler.level = SEVERE +java.util.logging.FileHandler.pattern=%h/xacml_log%u.log +java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter diff --git a/ECOMP-TEST/src/test/resources/xacml.pip.properties b/ECOMP-TEST/src/test/resources/xacml.pip.properties new file mode 100644 index 000000000..0ca8d27b9 --- /dev/null +++ b/ECOMP-TEST/src/test/resources/xacml.pip.properties @@ -0,0 +1,23 @@ +### +# ============LICENSE_START======================================================= +# ECOMP-TEST +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +# +#Fri Mar 06 12:06:30 EST 2015 +xacml.pip.engines= diff --git a/ECOMP-TEST/src/test/resources/xacml.policy.properties b/ECOMP-TEST/src/test/resources/xacml.policy.properties new file mode 100644 index 000000000..a59a45286 --- /dev/null +++ b/ECOMP-TEST/src/test/resources/xacml.policy.properties @@ -0,0 +1,25 @@ +### +# ============LICENSE_START======================================================= +# ECOMP-TEST +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +# +#Fri Mar 06 12:06:30 EST 2015 +xacml.referencedPolicies= +xacml.rootPolicies= + diff --git a/ECOMP-TEST/testclient.properties b/ECOMP-TEST/testclient.properties new file mode 100644 index 000000000..e54b6b9c7 --- /dev/null +++ b/ECOMP-TEST/testclient.properties @@ -0,0 +1,21 @@ +### +# ============LICENSE_START======================================================= +# ECOMP-TEST +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +test=test,MASTER diff --git a/ECOMP-TEST/testpdp.properties b/ECOMP-TEST/testpdp.properties new file mode 100644 index 000000000..00e6e5ea0 --- /dev/null +++ b/ECOMP-TEST/testpdp.properties @@ -0,0 +1,21 @@ +### +# ============LICENSE_START======================================================= +# ECOMP-TEST +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +PDP_URL= , test, test diff --git a/ECOMP-TEST/xacml.pap.properties b/ECOMP-TEST/xacml.pap.properties new file mode 100644 index 000000000..021efe9cc --- /dev/null +++ b/ECOMP-TEST/xacml.pap.properties @@ -0,0 +1,107 @@ +### +# ============LICENSE_START======================================================= +# ECOMP-TEST +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +# +# This is our factory that will create our engine +# +xacml.PAP.papEngineFactory=org.openecomp.policy.xacml.std.pap.StdEngineFactory + +# +# Where we store our PAP PDP Group/Node information +# +xacml.pap.pdps=pdps +# +# Need the PAP's url (how PDPs will reach it) configured here +# because we need it to generate the URLs of the Policy Files +# sent to the PDPs in the configuration when the PAP is first brought up. +# (In other cases, such as the PDP calling the PAP, we could generate this URL, +# but for startup there is no other way to get it.) +# +# + +xacml.rest.pap.url=http://localhost:8070/pap/ + +# +# Upon startup, have the PAP servlet send latest configuration information to all +# the PDP nodes it knows about. +# +xacml.rest.pap.initiate.pdp=true +# +# Heartbeat from PAP to PDPs +# +# How much time (in milliseconds) between heartbeats +# (i.e. the time between completing the heartbeat with all PDPs and starting the next cycle) +# +xacml.rest.pap.heartbeat.interval=10000 +# +# Heartbeat connection timeout (in milliseconds) +# +xacml.rest.pap.heartbeat.timeout=10000 + +################################################################################################ +# Adding properties for getting properties previously used by PAP-ADMIN for creating Policies +# THis is part of the Policy Creation API project +################################################################################################ + +# Set your domain here: +xacml.rest.pap.domain=com + +# Location where all the user workspaces are located. +xacml.rest.pap.workspace=workspace + +# Location where the GIT repository is located +xacml.rest.pap.repository=repository + +# new Property Please mention your PAP-REST webapps Location here. +xacml.rest.config.webapps=C:\\Second Tomcat\\apache-tomcat-8.0.23\\webapps\\ConfigPAP\\ + +#Turn the audit on to synchronize the DB/file system +#xacml.rest.pap.run.audit.flag=true +#Turn the audit off to not synchronize the DB/file system +#xacml.rest.pap.run.audit.flag=false +xacml.rest.pap.run.audit.flag=false + +#Audit will synchronize the file system to match the contents of the DB +#xacml.rest.pap.filesystem.audit=true +#Audit will synchronize the DB to match the contents of the file system +#xacml.rest.pap.filesystem.audit=false +xacml.rest.pap.filesystem.audit=false + +# id +xacml.rest.pap.userid=testpap +# pass +xacml.rest.pap.password=alpha123 +# pdps file +xacml.rest.pdp.idfile=test.properties + +#Properties for db access +javax.persistence.jdbc.driver=org.h2.Driver +javax.persistence.jdbc.url=jdbc:h2:file:./sql/xacmlTest +javax.persistence.jdbc.user=sa +javax.persistence.jdbc.password= + +#Time in ms which a Policy DB transaction will wait to get the transaction lock object +xacml.rest.pap.transaction.waitms=1000 + +#Policy DB transaction timeout in ms after it has obtained the transaction lock object +xacml.rest.pap.transaction.timeoutms=500 + +#Policy Audit timeout in ms after it has obtained the transaction lock object +xacml.rest.pap.audit.timeoutms=5000 diff --git a/ECOMP-TEST/xacml.pdp.properties b/ECOMP-TEST/xacml.pdp.properties new file mode 100644 index 000000000..feebdadda --- /dev/null +++ b/ECOMP-TEST/xacml.pdp.properties @@ -0,0 +1,86 @@ +### +# ============LICENSE_START======================================================= +# ECOMP-TEST +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +# Default XACML Properties File for PDP RESTful servlet +# +# Standard API Factories +# +xacml.dataTypeFactory=com.att.research.xacml.std.StdDataTypeFactory +xacml.pdpEngineFactory=com.att.research.xacmlatt.pdp.ATTPDPEngineFactory +xacml.pepEngineFactory=com.att.research.xacml.std.pep.StdEngineFactory +# NOT USED SEE BELOW xacml.pipFinderFactory=org.openecomp.policy.xacml.std.pip.StdPIPFinderFactory +xacml.traceEngineFactory=com.att.research.xacml.std.trace.LoggingTraceEngineFactory +# +# AT&T PDP Implementation Factories +# +xacml.att.evaluationContextFactory=com.att.research.xacmlatt.pdp.std.StdEvaluationContextFactory +xacml.att.combiningAlgorithmFactory=com.att.research.xacmlatt.pdp.std.StdCombiningAlgorithmFactory +xacml.att.functionDefinitionFactory=com.att.research.xacmlatt.pdp.std.StdFunctionDefinitionFactory +# NOT USED SEE BELOW xacml.att.policyFinderFactory=org.openecomp.policy.pdp.std.StdPolicyFinderFactory + +# +# AT&T RESTful PDP Implementation Factories +# +xacml.pipFinderFactory=org.openecomp.policy.pap.xacml.rest.impl.XACMLPdpPIPFinderFactory +xacml.att.policyFinderFactory=org.openecomp.policy.pap.xacml.rest.XACMLPdpPolicyFinderFactory +# +# When set to true, this flag tells the StdPolicyFinderFactory to combined all the root policy files into +# into one PolicySet and use the given Policy Algorithm. +# +xacml.att.policyFinderFactory.combineRootPolicies=urn:com:att:xacml:3.0:policy-combining-algorithm:combined-deny-overrides +# +# PDP RESTful API properties +# +# Set this to the address where the XACML-PAP-REST servlet is running +# http://localhost:9090/pap/ +xacml.rest.pap.url=http://localhost:8070/pap/ +# +# Give the running PDP an ID for the PAP. The url that its running as is a good choice. +# The PAP identifies PDP's using the URL of the PDP. +# +xacml.rest.pdp.id=http://localhost:8082/pdp/ +# +# Set the directory where the PDP holds its Policy Cache and PIP Configuration +# +xacml.rest.pdp.config=config_testing + +xacml.rest.pdp.webapps=/webapps + +xacml.rest.pdp.configparams=../webapps/configparams +# +# Initialize register with PAP servlet +# +xacml.rest.pdp.register=true +# +# Sleep period in seconds between register attempts +# +xacml.rest.pdp.register.sleep=15 +# +# number of attempts to register. -1 means keep trying forever. +# +xacml.rest.pdp.register.retries=-1 +# +# max number of bytes in a POST of a XML/JSON request +# +xacml.rest.pdp.maxcontent=32767 +# +# testClient file +# +xacml.rest.pep.idfile = testclient.properties diff --git a/ECOMP-XACML/.gitignore b/ECOMP-XACML/.gitignore new file mode 100644 index 000000000..1baade8f7 --- /dev/null +++ b/ECOMP-XACML/.gitignore @@ -0,0 +1,5 @@ +/bin +/target/ +/target/ +/target/ +/target/ diff --git a/ECOMP-XACML/policyLogger.properties b/ECOMP-XACML/policyLogger.properties new file mode 100644 index 000000000..7fa1b2099 --- /dev/null +++ b/ECOMP-XACML/policyLogger.properties @@ -0,0 +1,44 @@ +### +# ============LICENSE_START======================================================= +# ECOMP-XACML +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +################################### Set concurrentHashMap and timer info ####################### +#Timer initial delay and the delay between in milliseconds before task is to be execute. +timer.delay.time=1000 +#Timer scheduleAtFixedRate period - time in milliseconds between successive task executions. +check.interval= 30000 +#Longest time an event info can be stored in the concurrentHashMap for logging - in seconds. +event.expired.time=86400 +#Size of the concurrentHashMap which stores the event starting time, etc - when its size reaches this limit, the Timer gets executed +#to remove all expired records from this concurrentHashMap. +concurrentHashMap.limit=5000 +#Size of the concurrentHashMap - when its size drops to this point, stop the Timer +stop.check.point=2500 +################################### Set logging format ############################################# +# set EELF for EELF logging format, set LOG4J for using log4j, set SYSTEMOUT for using system.out.println +logger.type=EELF +#################################### Set level for EELF or SYSTEMOUT logging ################################## +# Set level for debug file. Set DEBUG to enable .info, .warn and .debug; set INFO for enable .info and .warn; set OFF to disable all +debugLogger.level=INFO +# Set level for metrics file. Set OFF to disable; set ON to enable +metricsLogger.level=ON +# Set level for error file. Set OFF to disable; set ON to enable +error.level=ON +# Set level for audit file. Set OFF to disable; set ON to enable +audit.level=ON diff --git a/ECOMP-XACML/pom.xml b/ECOMP-XACML/pom.xml new file mode 100644 index 000000000..cb685243a --- /dev/null +++ b/ECOMP-XACML/pom.xml @@ -0,0 +1,150 @@ + + + + + + + 4.0.0 + + org.openecomp.policy.engine + PolicyEngineSuite + 1.0.0-SNAPSHOT + + org.openecomp.policy.engine + ECOMP-XACML + jar + + + org.openecomp.policy.common + integrity-monitor + ${common-modules.version} + + + org.openecomp.policy.engine + ${project.version} + PolicyEngineUtils + + + org.openecomp.policy.common + integrity-audit + ${common-modules.version} + + + org.apache.httpcomponents + httpcore + 4.4.4 + + + org.eclipse.persistence + eclipselink + 2.5.2 + + + commons-codec + commons-codec + 1.5 + + + commons-cli + commons-cli + 1.2 + + + commons-io + commons-io + 2.4 + + + org.apache.commons + commons-lang3 + 3.1 + + + commons-logging + commons-logging + 1.1.3 + + + javax.servlet + servlet-api + + + + + com.google.guava + guava + 14.0.1 + + + com.fasterxml.jackson.core + jackson-databind + 2.3.0-rc1 + + + org.apache.velocity + velocity + 1.7 + + + javax.servlet + servlet-api + + + + + net.sf.opencsv + opencsv + 2.3 + + + junit + junit + 4.11 + test + + + org.mockito + mockito-core + 1.9.5 + + + org.springframework + spring-mock + 2.0.8 + + + com.mockrunner + mockrunner + 0.3.1 + + + org.openecomp.policy.common + ECOMP-Logging + ${common-modules.version} + + + com.att.research.xacml + xacml + 1.0.0 + + + diff --git a/ECOMP-XACML/sql/xacmlTest.mv.db b/ECOMP-XACML/sql/xacmlTest.mv.db new file mode 100644 index 0000000000000000000000000000000000000000..81e99a969e0e4e22295dab052ba185b7f7e79366 GIT binary patch literal 143360 zcmeFa2YejG**|`}cMruzV9C9~$p%|Cl6+N-Doe60BTKT1jcMj2oosBn3TYz1STagDS=4| zOiEx<0+SM$l)$6}CM7T_fk_Gc7f4`@9`|d1a{T{app{7$CM7T_fk_EWN?=j~lM^{!E;?5wh6>y>DpLd<@nHcY#T@q#53vGK*F{wAo@Cfyno=T(1phtAzBbB zJ?N~h9ybfa9Ze$%wVFkd-ce!)|E}WSFNdyH#eWRW4Q5z6HXb=j*SC5xL9s% zJKhMDnm#OmMgARbELv%V;-ONb98ZrK{|X&yghF%nghE%(2!+f&A>-m{c(ErGf3-{a ziJM;%e)5De>Hnlh_^J2E=XA#ncz!Ij{MYb-$GEU;YDrmH+3Y3r=N)wr6jdEh2`>>7 zUNSDcR6=;^WXW)5d$xLLcp$s0I-Zy*otJ@-H0+KaI)%-p2kbT(kH!16RmQbd)=9HuqfEwQb=agLj51N5 z+oY0EM3ZXIOFS;9_E}W>YZG>=^$x22eOXPkUlFYzltlYMG*O?8X`-og(kcVV-7=@? ztfty8sDif2YZAL{a#;;n`f63_tI;$EYLkg>LCa!Zk zsB)Xu1)qyOq+FL$G8Uv$HOb1I!#l^sPN9N|Af}{H6W6Q^24@A5m32@esaQ#AR#JkM zM8+Y7n%bNcYT`Sk5HgA|YuF)!v_t#}yP@@K86+$-lY|pe`pMclC4y8uolGXumhdy8 zq&4K1w1r&$8f0liX5`kY4QdZnT)x%i(C=*$`?JKhELYfM0cKP^k%O-f9Tn1rTls0_ z*C<~X{yOzMaFD1B67n&TQhr)SC*@;OK_wMbvR=h!l;5ZPe&r8JKcLnsj>r(^Pc zI<9>6KCSSl6~1)8WTRGkebQ5riu1uKtf@p_tS_EW!Txl8N(TGu)AfldTzF%t`qV&N z2K!>Mfusl~(7vQN70BWjYODY~>sd#OwPv)bhE`fZAjMgUmtYCj4 zmX)z}@pN4h&B)|$QUa3_n3TYz1STagDS`h238?67 zpi?A$OHoV+_($w{N%+&k%D-O5mo8KOHzZuy z3HwC4vfq^nfBJp${fw0|eum;_=F9SV))wXeR>IHD$mcl+l?nJcS4)5HQ7?(-xu2Eq z=bhUnp6Ab(@$;WA6VD5>(qE|LweTVN{>U!nzuGR+9o5JaGGz%NZx=m?rYb7%pT(-K-v)fA@`)zWcv z5;f6kYNPekOPlCS%21Zhp%EIR3+Q6nW6|n>S}51Y1zE8x3#S~8n2I)MixaEm0V`X_-Jo;OINgYRkXdMC)#pqYj;m~ zw7U`i+j^o)vvqxg1Bql!ELPW-tf?7T8eP-ay(YRemFcfb*J83_Af1d2)W>VGnZbc% z?O>+9zXo63#FB}@bSzs_lTG(!6N3ZwnM8kTpg%JZOZO)S(<$I-Y+l#eUK&{(jg~wc zR-807HmzxCj`lRJY-@>j_O5JeZK`hU>FH`++1t}nF@+0bYjd=Rj`kdiSgLNBeBIi;87W#S25bVZqP9`1D=&8@3iTZ*w@C3EtShpe-! zwWF)G$I6W4p}VE6r3vIWcQ*E{abxn-#-?>`n;}6Zn>?&d$oA@vu1#9NN^~9V-9256 z5c=kxO`R>ym*BF|9y?`OY2@f=dC4i-wAx$OLl>>>%`K;Dg*N37iulcqQOLAF+nU*B zuuQeX2x;uO7!d6hyj56qig8&QS%RFM zq;duotZRg016}%x2!3@} zM{j3q`)XZ=D{4~t)fnm`R9x-Nja?`Mg*8$4nvSlX&FzirtUA&Khb|Qs8Ao-=`l^J! z)=s3DCv94@GOOtTVHK1!;-Va#wzx);6D`xp(nvM3abhsDbIpLXwOxn2%C>d{O`}pO zqv^1<70AvxuP;0C;1-6QM5e*SZt*oStLEi8yNIFL>Pk_=t2V>MR$QA#d+W;P5-EkC zn}Z2@mEBUDJc}AMQs!kUj>N?cW>s(juR<24L%`Pt6R_xmbQckEXIDpOOILm~?$Uk9 z^=<5RW+-HQ^RSoE-9yiFCe5PRu)4?$hus{PvSL++Xua+@?2WA1IW(8%(R|kI91o+{ z;Kg-NKhgTJ9%SbRuOMABB@JnwM{PI(=Ieu75c54B7WAU2N`hObNB2XDSdhd}tlzFv zAwRaELtf9vwW7?8Ay)Oat!iy++nnn;RU{K?d|{0X{6{cWGG9LI^?4qP+62AYeOTsk z(?7v&-2z%jN77LgW!qd3+(;5O%ePb@jbtH=WXPqq(aDNicp|usB*6BOu#wyRY8g#A z*QqU5r~AlOBeQjUWtZ8#dIx_;*{T&=hu>|$k!W&}tDS8r;wVIXzK@7)5CNp!Gy!op zahJUGB{rRMT11QKXgY>XryM%?pq~ypJ1`Bfsj&@1)7G9f>xwDhf2qb_1l4q@+C`2e zokK8N_eqX&?fNOmk}h`KQCbWYUErdke4yg`X_{z#-vshJd=J=x@XeC6Hy){v9+=Ev zMkqJt_8;@Y){LLeeu5j&CA5?(Xc=4D5?I;;ewNnN+t%{mW@k&Gj?RhL*-BeIke4C5 zl~q77J6#mx1SxJ~D<^7WE1?M<>jxYQ_+$qbhB{^Dyn|WK%jsCEq$<`kkMiAShbEl0 z3A84hD<0xM>}OxAdfS_L0#4L^V|NXTQ#%W~#YmRcm`IE2&7gkag3x(nI$Ave)b7nvTs*VA%;!(K#?H znzIg;HnfP@92qTDzqzZWr?;!!gA1ft)4F<1OV{R(u4bO%cbzvs0MkK|CCSTXZFicS zu&ouat$>qzb!ivdvZ+NHSIndOD%4|f>jK5V)>W5A)AG56tJ%8Zl%OPAR~**$6TgDr z+1iQzz^c~OosC_MMSCzJ5tb8HHTGf&M$fw>asvgKz%hdtk0lD`0cA4BbV7x|l2=o7 zwXE-L?ZUc?%VZ%q&#xyE&}GmLf}@9!Cj_a;Boyh|L2#xnuEnMabVi%FGkW8KZ?YCs zl%^WiVhUP(&~GKm(qeB{V}Kf>sSUHq4kft>Uk@Dp$8|cD@35}O@UpeLyBD>9wkKgR zvgBH$Mt>%(WWHQDb8Mdm)YU{|GlsZro7~JznPN98w(gF$4Pe*BCdClTwsH_j2e-&( zTjf%qPic`gut>K#ul(f2O|m(7z0!=`>zfu|$~~D{s-t>pV3VwcNnTsTB(R@UsgLRS`V@_MM6eZ299%eS|(g6oiowB%vfkxn_s}bw|kp@`Q zuZlEPn*9HBja6%NuHLZf2ejAM9PaLDMv|1D)V?K z)2**tkiNJ|K`*dM>v$6D1gP{3Ws+|5oZx|L%p&!Jecq}fW!oAd`fn#fUIACh>f=tc z7qlTI=;6hqhgc6M(aF?ED_IXGL2hn~WQynF(gL->(yEVx;>nQKKEDFc)zQ{cbYRxg z)0^8y;SiT<Qk7IO8&55ynql*A{JR>sVr_fi_~~7 zrr_A*Ad9L_wMZ#Mh>eturp2E{$dzRh8Q|qf~4Ykr*I)zK)YAAl4 z%z&Du!=T)6CzieH&WSOX51yW01LeC7*sS!$bspDqhBnN_I0NNYWGCSEEBA~@>s^Zs zxb451NCqY_W5A8hDX`gZ`ZYQ&?W;Pvny{@WKue7pu^s#TFhzx}b=ZNX2XrpR>p-g$ z<{6>f)~H{)^^wI4f)6cWe@j<~ip4;do**Tn8;) z`kzdU{}_s(ZvSmfaM#qHP^br!;qLY>%$&K*Gj$ zVJ0-M+PJC^B%F1X zdM&nnHnBXrAK(hhI$_e|VuU$MS9BAC$mpp^5rk6I*Mmm+PrWY!98$H`#i|ZCt z?YadmZ_Osspt=E?eble-(cIG1%3EKt>)uvSa+|g+0XaJt{_Vdkn$4njo9oyH>Vh1g z9)_d^S-I>w*NckUM)I-<3oh6p9@z-Xn9$<6y<1u!W6c2<{ZnBVyIiW#e4ygSk(%%h zab9?Orsj0E)J=36ola-4rEWrAR|jh)Kr*)zKA&UNPMn4ey3I7?Cl8Xr3Cx(M8j+RL zVgCF4Mt6;(TOx-6&8Wk<8s$N66>HES>_*wWRlEm~4t*V415!|T(D z16s~pYgEZZZ&#b<$`X^PYtIO7WeIy>D$tmyaE(9I+{|WtCY?o_>1;ORGhugb{gZqI z#qAFCgV(w|;yVjwcaL9tiV4$It*5r(%cWw?Y2imamKaqX*X9_}7ru2Yr&+Is4mLvv zjloKKlVcqs$G+?fo()-Vcd5j3`7ADFPzWsLCagY~?>g?^tnv)?Q9li^$}^Dr8+`hO z*uLD;(bUnle}Y%?RybTM03p>rNVO@LRO{_K^c~zux%NY@ZeJMKlNOgOs05a5J@3mO zfE=Ij>owpzrgcRuR~9o}_NDC5|LbY(Wa$^icj6n5!Z)kBI@X=m(Qftllnz|eI)tKn zh%$XQMyf7k5$#UZrJpJhalTy@uU>c9c@@KlgX;gvqs%M~(iYlELu{s57)Zcr(}aD1 zDWon9V-SY1#ihV;lHvvdtbq+8!2`!FFo+9%3YJuMfMO*R`iRg)^rBF04PI5%*>_;s zIFpha@~EnE35&}Q6aveyZY8R!!;UXuD>#SFrERpGhS>_vflSZ$k*PM#BIV3QV7Wr# zDrh0kb0N=w>m&A&j>VJ|<~9h^ZU3`QR$P=57|`%|W;=wo!$)Y{Els`rohg^YB7$?3 zjTD`u$rR!m4qm6PwD*Y}{6J=~h2<-kaJ zmS6GfrQj=T{_IhFz*j_=jh&sk`Yov1^S?rtGWHQaTTfnJ7T@!>cXPZu6?+F%=<7V_ zE8u?3#+ZHC+mUB!5y8s`ST&b8~l1U8@jRYL<|axSiF>sV|mMEzDlQZPK(JB;8JtT-EQ*r0Ue=n zwl>RrX(ii+0@6( zC~gEGr9OwZBX_F5a1NY5v)YYZ1swEvF7a|*OGkO!t#soeRsAcvqf(7sOwcz$u zTpj-3GT-)9@+=3{t#{b2am%XLxSqV2E}=Kj8`*L%hK?unsduWyHj%YKNf5rE$~Jom zlu%Ms~R--Lqt*I8!eFJh5u%G6d2WhHr1ov($h!fy`0z-yW3o4Ws);92F zRU8*{sX>?FY~M&^j{)2Lf!}nTtjh7B0lIL~fMpEkqgS@B#ttb<@v@H8)$8k-j&5t| z!A@eeu_nR zT%lx>!84kc3Y6rTiA-|#}wZ(u5Izj} zZP9Ma4$dZHLOt@lQeaj0P9%A$I`K8dMtsPmJKT~!pIv6ReqjaIvK8o!CpPi9SwXzU z)>W}(SxLec10itTu$Ps*$4$w$v_aJi>Nfr=Y#5lDcP$#Pfe~KXeJ%G1-ek~q2EAEW z;G0<4xB69FV*0_ZW)Z=sSpCPk1mZg;LB_LRa3FdOf&yyV{7$Vj6!F$>DQ=ajWr_Yh zAS;=#!MfE?*Rf>=+<4w(pLiAQE47I*G{)BWX0}GR^}F^Y@HW6E%)^GC z>s-mTAkHm(i$OOSbfd7r>)8gc_p`yy=1#i>;_*Lfe+R<2)~-91=gS}vx3dQ=gE$a& z199Z6*v(3jpqL?R4XQ#dYQ?v(?KK5!8|~w_oVKK**z9g#vvV7*TZxMsopY$JaC=)E z58rNN)ABvkCD+5YTUajEt0$IAVH+jnB8$oUKi$DPpaxb@F`+G4)4PBttZ@G5O$Oa; z&@BetDoXP{wwm?9tftvMZmZn?H)Dr z6z0urQhtkZqA01!=>SV|c1y|Y!Pt=KMoJXSTUf*aw+OAY?`$q$O$zo_7OdM|jr{b* z1q*U^!TO4GWgK?2`1D8Fj&O+W?FPNopgRn@Q`pgMqE+zghT_Ohe0kO_m@G2g<}#5W zTX`Sp+crmBxOXIBdTtt@!A4F>kC6&E_l1QvQd+wdJM+jdn(-FEQu zfM#VQ&WFX8TzkF9&pawGXx4;i?qtzuv^I|1y3zJtvC+D4Uc+4mz0IJz z4Z26z$6YKtx5bP?Y{ez$>{VODy&IPrNbzkfMZeY10IQ&!#K#8tb>V90-7M#zI~eRH zC>WBacMprtZ3_dZDK4(=CtYzXK0)JT#6QP8}x2rk?&-2ZVJ|YX-lq~*+TA*ALWwNn4tm#_`s*!=ez^ge^$FKpmF zERhan1CDv&Ri|vuoxP{e8CLl06|I%1LMLL)zn3NOVK)g_={>UVN;is6z*=znHXkXT zqvOoIE1<zmFwyW^svFr@V@VJBvz9ucvr|mYcX=~rPH8!lTA6VXnw3(l{BoyPi4G=q(V*zPJYdiV z4Emr!9}*_^Krj>Iz6|5Eh`UKrCt?wP;J}!eM(L29j`S0nPGd1#C@q~N&%{2+5*aFH zV!89yH``9fRMhO7H7!HSK~&fvSXLimS$*Bt+;YGH3T7^`oi~RF?HqU)RCh#HCJRNX z(b`1{)BEVaDO|hZI*JEoxh`MmIz0u20Ut!4| zr$DigA7mlFFw=wk*w zY|zJr$v(t_KG(x!H6}X`md3z!KuOy{*l<6_qW+ef;kpoMhWMq;{?x($pzk zEmyy^DB95|N!CUSC8^<@2MpTU`^SeLU<=0WOOF`zNrOHmEcg=>6SQt4g9_S~o^AIL z7W9|hY*({yWqTrmwo!2i+7@4EwFMNd10U^~D-^UwnrE?}WI>L2R0Wz=PC4qpOB+o- z&%)7!6#`Y{olMCh{S=Gz`+g$L5iKs$T-tmF9fHm0qoDpRp*0y(;aD%mx;$j$=LM?2a&{m9K{Sz5itq@`f(VMJUpXo5DC2d2c-=q@H%g0!xk_Vffx#;eb6%d|XW zj?11!y0Fh)kRDa6m7eAGB+Kio9`>aXOHzTPR>+mZ(CpOR?9EBhHFJf{hb@!#76kR% zljnb#ZSN_Ao;K)n20bHe?Oe%cCM&9Y>lX30M7CfR&2Z^7oL zw3u-S)uLJ;QBQbfo+%ge)Y$BzM0P&MLi6gEJEjaB#?9EQe!1r)q6-L%@EI22-`qrK zC+ICcd#cSYG#pZNd0*JWDTYzWHR&SP0{m(MwIJSB9l(TljlY*o7`J+U!JuaidQO<| z=lx9B!K8h?+u|-awPa6QVNc8Q{{qY3b=JfV7Eu0nNyLz$b)9KGl`UaWuKpf4Kqf}_l_;JWoVr1Lcj|>&c)?PYtdC~(%*vAW;x4T{K zBcI`kG_J%@f6x-VEU|9QKec@kt%PMXze#xM(2wVFyFBSGHOm3SOG*5E17*Eb6 z)O0NW{!32M)X~eIx8RzMuGXfCWZg2cxcU;?b-^UFepUuA8a;H?dzce@JHF;GByK7cif zHS{zu+P=(K^gaZgW4k3ZclzT1XHA!UFKmS9Yl5w>6)`Q@EZT8m3sK~y-El_ob%EmR zY#pCERAr41NyOn5tt}fhTk9Hon$}ozJ>BTgV2P41IF+lF;%F$2%Nu%EMjaPuR7Np@ zg6lk_-z)w2=GJapuOi~&RskkQD=I&ef|t{y9Znl&0axm>@51iBS^?I+e^Xzg9U{bodEZkf?Y_Lc}-5 zt0h|XLW@Sf)cr|x=B*SuPGLwmF=z=&42f!;I)@=A*C~8#NmPBnCNBjqoG6Jl3sihX z_=@G)IEt|9M=uI*^G?yJ`5AvbxYPqZ=a z&xn=MVvUDDa#&Z}5Y-4-5GO>12`LUZYv|NfKpCth*@}V1Wfnc$`72%*;*e>A=OJO? zbQR|7&qKnIheUoJ64h>bSTK*9oJ~z5H;F2xJJ8wif4^x zWqef|rukdiTe|WqwY)4A)MXHj{obDgQ@IH&Nn5>_JaF}1UWT{|$&1p}RrLiSwp2-vTHdNW(H)$!_szSw@_a>9p09A_ z`G*;vm8Y!t1Uz4jX9>TcW0+sRkHjY68`>n5GPQF7PbQDOv)O-6Zeuy0PtvjOp z3b)hQXWeWy>_TklVA;kDTsZQ_4KmJm>>!imDcQ3fRYdIL0@X%xnUPqe46Ky)4uxlX zDpO0Pb0WL?bMFd=7yQn5h@lc_MdtS)USKNH z-f|k-;DsOaj3L*c+6FM3ZpE?3T4`V3D5kYLdQv=k?6Gnj!?=UD5V^68H&4*=1e-cL zFO1iJRKqEXjchng@Lc6aHw@=4=>wE2&sLl%%UrpSb@)C1g6AsNnls#gG*_POI#c#* z+xflh1r&_r*i38kdI)MX#&@FPZQA`U-@=NwslvB;&6G%%-wAOUGKvC|hYfYIqq^iY z7zpxEkMor4u{3b4rYiL}oCCEQl5(QfG92b4ks$I1-aW8Ly+e_xnAM~3W4 zD+<%9+z7TDa3ZHR;6hMGa-rm9_;4+B&%U1>e5irIp3u>sTO<9St`+_DM4g}a+}!+o=X!ye${ z!>jw)$Ii-+39fFs^WYhwQnNf>YA#BYnv0XA=FzEA^O$t0xumAlTv}UdR?s1(<}y08 z)Lc$eO3h^z{ zC4#=n#4MVH^s{L;+&MG{?p&G+cOK1yJD=vmT|f)qE~JHUkEA2v9z{pNjZzeDIhDg* zM2p}qrp0iNrla8=LoBK#v;^)_S_-#J3cDNnX0k;!(^LYGjz2!@iD`|9H)P?lj)D5?X zdf@g_FWe2Z0q#cH2=`Pv749b51ot#L4esf5I@~kp47g{~nQ+gdv*2!~&2Z1Av*Bha z1GkU*;Pz8L+yNXp?(w_zmaODT7J@+V z;SSR<+z}dqyMuPXJ&(?VJ4&N)$7l@hIE};INju@5Pv^tEfG&W$i*|W175eb4X~~r= zlo!&4NPiJs1ovXP815x>3EVf(8{oc?-UxS(f%DtoU&@EL!M}`8a)Xa!ur6mGXJK8z zJ`TjXlKrdrU@Z7JW$0@5an#T??Bl$lYuVq+=MKTg0Wfc3|2jSh#*5$2-u5QRudY6D zYRB~qg`+#(!amOLxPko}`5X`UI0|4N`#2BaCiZbCz|HLAWPn@Pzm-o2fR9hTZ(|?d zd*9AJKKgzu`}p$v4)*WlFTmmBd*8d*$49?!V;^7s-p&3!`~@)ldkuU|>dk$tBe~7>EfscVZg@@_lLZ=H#WZY zrw1Q{npsxW@UavAVTSrR?}&$w-Nm0^A6twcVITX9Kgs^5c)u}xY~K7d``E$x8TPS_ z^Rw(f%G){NKW1R>9sI|610H;A!Fz)JCwVI#d~A+-ihb;mdYXM~llmO{&+v9B_}F>! zdG@jW~3EY|S z@zJ5ao#WXYc8#T!me?3?>mM1&_GQMhB{iN1U76KzrL=Tyrhj~BWEkwJkPj{o<|Kwv zs<5%vmFe%#j*VH;Jbq#fI-yHxSx0vG{Grj2;qBRBR+;^=*BeH& z=k3gnjSmfPsoI|D-#Rp$Ejif}yQ^pmF_hA=HWIy~+5Vv&L&%0Do0BF=ArAqzhRwVC zwZjfU)lu@gSwMI1by+3% zy!XG7z|oo3&uG89xg;ElCz7GkaCvK2W_U}sWJ`B;JerA)@hu@@eHH1Fjv}*`C>5JUb9-#l06FVRF;6 zCsc9N_0m7@1?fM21JS`$O0%$msrA0}5!ftwa%dPWR7q7)V0-e? zNHs9D?MlaD?P$kJR`}L71DWwm)%flm*#-?z8d(AO?t#qio}um8=ABBuv7$`mL15?5 zG$2|t4lE_d6ouww5adbs{*47$N@X;iX3$JN(YO?7P8k>;6WOWu%uWJLX)Ze|J;2Kt zyl-S=TQ)NsKoKe>0H*`64H&a5h>~SRv!Ig#bOu1%M+f`s5(&X|+>>jrWOH2SK!9W> zkgQ>(0mR42Aih`L{+%NZ4$&-{O><~2&7=9WfJHb9sMZbbXdD>eLRk{?WXCB)3j!!+ z14ZxdY-V)b$nf}9%PtZ{#ZmwRWOJCGt=V15!j~6CVxbwIegW)m9UFciXsm$(cbO9L`i6eD|lO zm2!h$Jj0R&o=BNs&B1d$!3zk_{sc5kp1qnt`QaI*k_p#0JUu=n z0YsxJah^E~z=||6p7#nMN3I`v@~vb)3LHF zBo^tgd6p>Dif+G!?>TL{A)EWV09Ys;DRTrX+ zpEfc&kR8nqR1IW@cUO&^pB)_?8pw{7w0l;uT-0UHsj7cud*9G7k3KTnFsd9H-@3iQ z9UrJ2DX0xs?ZDV|XuK-3W5+g(UbFop!vn8_nkzm~I||gg^76E5fAi$T1ME>?-=H$G zb9ft%963$N+Wn3^W}Tkd30RKuF~Tl>`N5}V9LkO90m}w2KparX^SVaK0V;32 zc5)!?o7Z0sbdAHSJg)<%YaPt%MjWdVo;! zqH@WBlK`(&mmCm_r;4Jrnx|?CZH-scOAe?-@ydLW_Q8`sZKL@$5pSnBP_+^7H`w2@ zT3C0|5?du68hYr%a}JTClB)I7@Mce_>OnaPS$)Le;<#a$!qdFj z(W>#Snc=FD(JCyRWVV$w`4;EFox@_eNi3IPj@cbaq^xx6B1Nu8lf#PJ_$a2=eTH~k znhPjsxXRM0i_0-?Ll%1FpucK-q)K5gsSU<<0U)p*t+0w^M9!1wfDaGA-?qD?AsAwv zOFL{O2AMlQ{$Z#O+F<6~79VANb>?Ia()4Kh*& zq3?QR6@)I=is>-OeVH~!&Cl?FBIIp1j(kM(0XYN97p>${9F6K6VCc^4$-_Lw>%BzG zQ?mIvut7%Vl}rCcbf9(tjm(4G zFZ{&wEO%?oWNMWrri;gZc0%hT^P^dSkl4j@GTdNKM6+&_m zjZD*+?M%zGKKA0kTnH&7f6ga`#j9l&SbU^Z(dyxeMu+|QPg+}+nGYA42CQWotDO%{ z=~JtF^3QNA@W^zHl~+CXhu3_#$V_0Jp|RR|<&^uwE5iv%U-p?fY~wTKnhZ;NrlNBy zr|HR;ws-sCkc%5^WIC|V(%AEJ!IXSjCkJ*nSRwh@3i}4R$l#EDKwB?_jLZk$b2Mf< zZJBm|Y+XVM4SeCzFS7=$)v&3Nxr)~2yd_IVb{d1VSUxCLAY1b^DSNi^U`hg#@g2xt0{2>j?4o7MH;`ID=T@CJvbJA zS74zPJ!06XwhuVC577&aE3qxT5}VR1 zv9GF9?%l^E=nApJewx^|Un+LYm+>a{GVI}slwt1@w(?^q7+h>af{X1`*w&9VTWssc z)G;>hV?j1Di>H0DaUbi-k-2Gh#1{ecc;6Iu?_i?>GeskUwQ-5%SvxhP)(d8cxZ@M_H7&KKer)Kxh*@4r)@*$XV+zRHN-@y zGqVMoWMh@!v!Mp=u7-Gjta3QJYrG*@xkJ26RE~~}j5nlW{7c7U{gvE>YpCt7#4;&w z4Qq%C*)-(KW+6)qa|SHGM6yzBFw1VxF!HUIoZs7I%=fJaW=S`h@`bH)f2&~Y-QP-{ zQyz5H+Ztb3U(D%*A8b19`_>~zlB=4yA8d`UtZHiWVGk4f-8nok(l)XMrhn_x%R*%# zVS}nfC8V(@q_HQYu_vUlC#10_q_HQYu_vUlC#10_q_HQYu_vUlC#10_q_HQYu}jR! znBAyqJw-KvUl(M``MRK}NVAi)V~(`(f`S99yzleB)mEu0_@p$)q%s<5j!9{b zNokHrX^u&0j!9{bNokHrX^u&0j!9{bNokHrX^s+QO4j(PxRc2O(~_^H660}yal{MC zw-dTRS`ONUwXg#^QD6m5Xn)$t0t<5>PZlW0fjsGNB}oslD5)j=Ei~ybmXtqhsRE5n z73RNfq;Fkjha(p$4-u)7k}ePt8|VugwSlUxM@m{|N|}+g%#^gul(fv0w9J&W%#^gu zl(fv0w9J&W%#^gul(bBVD=jTEEvx5r!jXrxzZInYMP1`x8Ps^FS?RH`33Av_jlUJt zct~F%FKiGT$ZI{UKtp?oMZflEt=6Bl!ZyRfT3rEamIZcY2c1d%*(_{AoX`bqV%O@_ z=kE&5mhF04T4q{WW?EU3w9K@$%(S%3w6x5$w9K@$%yhr#n$`%nR=9P-tru=axP8Kv zDF;M2E8Ia*@vHuL>~JoEx^o_{aX!{NGF9(kl1g*+1;TYg`wO(*U+?t=0<|N@*8};T zD(7oo))Fxf)?{syh9VgQkq?9iuoq`f=hb-XG4p|@@ zdxs@nP*=*gN^1p@aljTR#qqX4F7~&H0?bCOnM{~iP7RrNzj%CTNys@cbeLWu<#FH0qiG zx>|`u6%|n#SIh2z6-LEu^qa{VGg)UQ>&;}pnW`~UwPvc$Ox2sIjG5{)Q-~ZeQ&}@L zXr^OkI&P*DW;$u6Q)W7CrfbY}t(mSf)AeRLW2XDfc+8Ba%y^AaZzkeqB55YlW}?oh zF;WITA2WXW)vtx-hukMBB*U`AD#^+Rbl;^Y^<&ccsFbAN)=R0VM`hmnN$E&GrX85# zO26uD!bvCLe4BK>O**+q);ln#oODx8x+y2-w3FwwG9<-Sy4I0DC)paOq-vCzDNqMb zsC?~+5(y)2KwbT2V!%vf&BUP5XC`B2GHxc5W-@IiQO9J=Bq9gQWY$a$nyHwXikqo~ znMxY4k(8NA8(A~mXAGhq`qaxehALD&B*`a~Ny;Y&XGv8!)GOz^Iy;*w$Gem&0TM3d z$WS_AhfAj&PY#?ls^my4HLAp^Cx^6a9emcN?I!C$S?5St=U}?d!F0WYc)f#oy^@%k zz&My^xvJwas9PPvZlY@h>6s|lCDpRU^3P>Sl6$D zg9H6CK{6gorerXYs?XN-Ng_3M35~8c*=Gg&6S1sJP!~_vB{3a4`J0r$qy#1X&X#cXY{yw=pl}hI_kbE87PC;+$8gpT|RxUY)p4kVr?Fku| z$R$N{N|$&x-zEKUQ>S%dSzDCR5bM8e@PZ=dF%@+g9su#OSYoXj)~ zBb>(JLr35ggE_PSnFR^Ccd-@r!C=N zC7h*%}d zq!*0nfB$7pd|3JsH%}gxjw>@J4@-AHnmqr!Z1+@?hov|2CAYbQ!1GW4Z4?)ZOdghQ zm(k>5>AAC>xik46J%HQu3Mi&558#fwUarCK`4{|H@!Xlz4EG<+)#PF6?YV2eqd;UG^t%kns07{p&hN*!cPMPt301$(zSQbol3`zmyO7$8!@O*bjf;5b0mR zlL&Zz=QYxQQu#lU{y|~oFH(M^gg>ZX`PWMLgFdMIuk00g4*IKnKKMxad~maR-m0Fj zSI-}PR-`}pTWf`Xh@t!n`Tmej>h4@HdU7;%m91a9T-{PQVn&dQ6UN!HMTMh8!n{ z^YjM};l`{74ztE|2BtZ_Z_qCd`lCVr!a?XJ?K9~vliqF8gC>2-q^C{#l1ZfFy?BxIm-F*dP#B%@D^NhjtOG*z36~&r zET>*tN|l_tqLixm8GbcCFDs=L{0twTgCejTfl>|}i$ECyWt9j_=a?!4W`NIXP`q^J zo0+2e>`;IF#@|kXB0fPx@)ZcoLSQbw)TGF4j>2~;gfH=;k!kq!m++k&$4y6Q9zrwm zRS`wzi@2ExEkI~GzRDqdhQ;Y-BXlG}^CNS>z@C}YnE{-XhN&-g{+2w4h8Z|YK+Hub zS{_}2Pj3jH4l$DX2rWWrc4PrUkUHWPB6M_lv^sJm0xbG@k)se=g3yde6rrUe4$6wK z24+S0;DXC$-N^Kb2$+>WauQs&5Tqd?qtNtP$S}|Mc7VOB2I>y5H~#% zLtHcBWT=I87)R8qMH~?HOE~YVX$`f~S~>+2o$IKbI&jGZlC1`g*^vZ7Yk)(BS`jxt zl0@8E#L3Vptn?J3+7_w6I;5HrNh7Kqsbr`FadRRyi0ecgLM;0^=P~{D)J5IYgDKVx zm}EVTPNy@N{`&H0RiqYyu0<-)%@V9bOb<(t1HHgHH&Tz#24Iz;O(L!Vai@tm4xP@B z$02YALmmg(m(2Mi(>{~VqRn(RCU*O%p9V0!JIJ)p6gZAY=q!PQLz@}L2?(6cI5?0I zsZKRVL-&Z5%r@ z(uLsdGM0mHm9gC+TtqXkig`lIh8r<3!;gC~a0Lc#zqr@HJwCY20vA~@Pj^V@ZUpaS z=y{PI1n=Tl8GM_J?M3X}GM0n)$k+`C-Ya7{c%O{jh~V30EC=7gvC|@_hQQVQZ!uSB zY;kkO{d`#lFFN3s3|x?byD=W%>oAzBcQQ0U5PX+}-h|-&GM0nyma(TH_#PR{!S~A8 z(-C~1jOF0_W$YOUJ|JT`_yLZc9yv3_T!~VR_8<3eVEN-gzHI{+ZSXn>t~+{|ugzet zKFH7jLGVKo`YZ%LEMqzNpp4y&;74RE2R|xf&qnYe8Oy;QtF zma!cCjDg<8yhs+o&&uE+f{${7d66v$K4vW91RQ)^#%>LTLi-k8%3PtBgxfxz;tM`- zw+F8E;6)0i2bQApk!K;L6B32t5UiGW4{FI~Q@EW7=~g+Yo$)smzUR zNAUAZTL!-%V}}v@ET=7tj3D@&4DJX)P77<9BfSQND?)HP2(MP*S`gd_f;Fp`1xL>_ zqO!<&fc_$*m%$fg>?mTt#5ku##t?i_2FDTnGAEc8*@@sw3?_qLk+J6^_N$zBX5<0{ zUzWjLp-||yBOhR{(2vAmL9dw6w+#BWVH>3q297{KGqM}dUuX0(_zf9*A!1))oYNy0 zA^1%hycof6af0cQOA!1vgUR4`Wb7Ld`&~{uKk`NdzbAuxc*t@0kzLFd`nEqX=!XXV z$e=AYS7ON`nf^B5W@OCW15c&8t^}00xJAN8IOyEDDor5J12t6gedZ38NPzU zKjAcUP-!FlQ-)RHpUHS!GDMM|BYhR>W(0pBg4Zy2w;%NybBAvC{}}WugMMw$Zwz|X zpx+wwJA;02&>sYMzXYZ#TucP${{aCN{FR8s9YqxRHE^y#b&lX~MDRKezKR4ZP@NpmH&wO!vN}9llGeQCX=o+>CGlxZ_-;#y1}Fy1%KBtu2QrhfWMY$ zsPJAH|8|al6Nl%aJwf<7Q?yVb{AL;dPL98x;G z@GUYPH$S1RMtn8eCIoL|am+*Ggz)X0H5GoVjK{@LXoh9H2;V8=-_PvbvFNAF9!8#T zGwE)V?lI|JlkPL=?Iyj`q<5KgzhLh!34=?eDDpOmON8&1@wj9PZMKXT;d>FTM1zLt z`;bHh-!6i}Mnoz`lnBzIj^hv?qgAyM1Vxi5J z@FM(C8IOCi&}z#t?#e>5Ez^kb!!jOsXHn$iGG2r~!Qp9WcM<;xr%~Zg%J8QJe@FkF z`NK@Yr%n2dNuM?8QIj4s>2Z^uFzHE?o)Y|hO5(zOTxh)|JnrN|^DV=;mkaH;Oe4aN z%6Qz4$>9S0t`4GW<6sJnlL}125x6_}d&m z2mKSoe~05$_`5P5ccGz?m+>O}eHo9t(a?CyFz!dA$PZi(~&Fg5T!gA4LKY{F8{q z>@Y=M6S3c6uI{P0gSo;i-(O7nt4V(|=^rNj)1-fy^ly{)gz3^Sx3Yf*G#Y(ODx-A= zxDNkS#$)mr?YoQ@;eW{Z?{oY=W%vgi{+CQ6!vB`xA9DPju)r_Emm*vp`H@g&#fi)w zW*{#Q(-mR5GE7&6>FO|D6Q*m!v^Pv|66{?T=B~w$7}Mnf`o|o+Ld1&Tl_K^h9D9`r z{*;4Piv%Kgjfnjj$6hO9MQ|@-(Fp#Wqu+#R5r)|AUUo0@g=x_@hw1t-y(LUHgz3gG z?F-XQVY)d?w+OzjlkmS__%};<5x!o=|B~b1BE$c~;TvQc5x!Bz|BB=H$#@aIDa<{p zUvu=$VQz~>@D{|P{rwF~?QP3im^;ka-WI0Y!}QiL-4Uic!*o}e-WI02!*q|}?pA;! zN55fIw}DzEI+6(94q__!R_0+YI+cjNgLzQlJDFNp zGJKCr@<(Rwj^#gK<}jChUzpw=rgwztond-cnC=hLyTkOJFg+-kyH~>eiE-TrTp@Hk z5qx`iak&bdqfHmd{CzN3v>3nW4}Lp zS_o6z^wBUq6sC`b>ESSaJWQVm(<5Q}WSAZe(_>+JJWNl7>B%rX6{e>JuOAV(|H8OG zDsYS7LlXC2Ir?KFg$O<@Qi$NkWs1LXicg3XBKU|%A%dSoicsY5oZwNBKm;FSxCQ7s zBl>X}{wIf@V3{vKHyYt5W&FQ5{FICr;itokdDwRbHrsx)`kQl3Bp?dzx;o|+_%VhlF7hNx(pPMH9BUaoX{ad9! zZK}jS?Gp9;qiN!OX_I^|{h)j5n?=dgf?{ z8mnT$dK(mLKAgaMtg?#r`dDRoT6)q`#*VYh9Y8|Dl^UNu-grXz96&<4s}kq1bgSgD zC`-3WQRq~M5laFA4+OWv2!5*-wstlQg=cLsb^Bxveeb0I!isRX!PWcH&s-; zYf6XB<--ZiYZTUQ>+(s3)Vrp1Ak704IBONo4fZQr6+yW5a0gPIe+`EN=!47NpwO!h&p6$Sn&6?g?6G- zp*l=RBo^>Z8h&uw$jE3=c#&AZH!JwlR5u5gXl&1H8@e!CHMS$upY=Jn*};%Iv^ckU zU&Ciude{xbJ9JojEsCbjMP2Wgd}*sDz#Nu>1! zy_=-~P)KjJvRCVNmMykxYkW@acJQxJ+hIi|yGCKRxE5De@{KqX<=O%iP1;>2l(RiFw^wLAo8?UQPP*p*fZ^Od5A+`s@|}J3f!kC+-JKa$mL^Y zuzdL85Y*ZfwH}qy5?Ro8ARkWX<|`-dW!+f&*QQ3+DLQB7r_W{SqzProV$?z)^3!ff zPu~=QRb|<*5I0A3C~AF~;}$~}xS(-{nuJ;}XbcTk;i7;o*%I$wyW>(Y z2awRf`9cN9cUE-{%jH2Gl z)EyTl1}&8ZfFf6Y3a@Ns+_e+13>FZu?0}A8m&UY5s zl7MB<16*k0wAT5o3GCD7?enaOtQw=}mTP~mUsN@)9aM~e1{H2S4d0j9QZpi)oB0PHX#`@=f>dP;?JKd~tl zK!`#4h|2w`dSSy}9D)wY-CzZyJG3$B6qaxU&i>}Zv2-`ABbM%YG>Rjc##y@OY4g&_ zCuCj@Ai?&imT!lC#{!OfcDxub^5qDZI!FmXrgogDJ!sjAcCB`6SEu(%iR+EapoMC1<_zD5V^* z2cyX3WPF*Sh1{NFA!rMhgAhWvTnpi}+^U{K$lmugI;`0pIx+{jze1DPkV~Xx7IZ*U z2+7jEvg;0(Hg+gorM|~xX3tud-ymKKGg}J7A0901{%kT8rgO z$HJ#W_yK1_JP}ku9M@<%n;gk34Fnt^y8^Qk?&>{}m2hqDLs(YAwOR?z1!1X&{aFys zsba6Cik^I?g7&iW;aE=i_O@IsjGmo05$&j;eP-D5<|}t|1&np2%s4Itbl~9obFb6X z&d8@`DJJ06@?P+)n+G?(g>{3?d*Z`nd?C!bd9&6{!DbGr9&d~A&0( zz3q!1f?>(wyJxAVzJl3Zhm?J0WE^Dtv4{(SZ_p&qDokvt%X^BU2sw>`6?V&pU92!{ zwZze=;xlem*o|6YF1ur-%DkruiV)8!ZJ(vIO|H50>DLsYfeZ>U;`4H;xlPvQ7e{U9 zZFi2Q#ub<^HojTo@3oR>*#_<6767tRcAxrJRth%1-m1Q*XQkYtmC|JaNnHf&JUO96 z=jm2U1)bJgxdw`4Em~YoaHri5IV)wrO*NcD# zWx>DU^h;Ur*mA6o5n#c;RSVv}D@uw!;JDbvY0m!du!P@bd(Ywzs8A=A5YC-iIHy^6 zIXmkp@7|STBHSHX+#G$ECb1!xNXyWtcjbXzL$dTo&z#EAw;kNT(tn$les_+Z6ux)w z%7a)=_IF#dU!TLuqWA7ydEf+)5DU(SkhXuS-c9W=eD5pN9eCYf#huspYV#@nT$v z;vJejJ)1n5-ICq4qiTBw2ju&-^^OWaO|05M1*)sV*yDkjG7 zKI?NVZhXjazd8wo#r-Z#(pF~epg#MQ98`0LY=;)P!Z{)`SC(}gK2Nv47GV?~(&U zvl8%?k3O7+mGA*grdN~6j?2BiV?jGw1%N^xIN(O|-=|kCJTwq+zn(u9LGnYE3asT7 zsRQro)gd!YLIClK2#({Cd9b#=DkTK$MredKEnJ?xg0+ATt@N=#tc3?Pp$!&DP7MKv z*oBZnC^$Sw6$G_<;-Q9s1;H1IAox*B3;HvS2^9oIKo*3#kPXf`QUyW1npi<_0EvQd z)4*(20X}qlm``KEsYtAXk7+W!8X~8Gpi{MS8#zj;DnUXXIFX6@FOOO)OROoYp7ZX$ zIBZidrr2Qx`j2bA`*acy1qUo={#XP_oD!v~I_uM+36(QVLh85-y`{Z_H?d0a;h{d9 zidBLms8sRO5ECnYPAI|pCpF3q)=NuUK3!~ARpjXzM`KAn%k?e0qJq|>Ep45zYh!+#nqzyzch6CMXVegi2 zER_V_e!#l2mq`fxmUDj00)IMpupA5gX|3Pfs-L~k`Sf=kro(*p6qMNMAn-Yz7qN#` zq;XeCiT55>cT(vUyf(T#r2+`VKg=r5EpPt+!Zrdrotn zQ7PP&6m+QJi$vt+c}vrJ5mM?o;7~&mkXoLPQgY{r_(T-n`M+SuBM(_2IM`6?e!T)v znh)5Sb^r;sU(g79^}Add57@&h02GM7q_t~X_;e`Pduq;6%5n>Pc4)D}_oC*#B$`X* zq32b>TH<1OL|NH;-Y2=Nd^vXlC9CGkmI2t-MWqb{ESEXr(hPWU7e`V`h4~C2{Qm{rW?ZkVn&X=SB=1k(ySZOM!<#VO1#k>0T zB_N@NE`K=wE!HJYpZP9d$wJ>3U54*y!q_hET%x!290IQ8dSehm{H`_|mz8R}()WL* z+Kxpmv3^hIuB4)H5!b_d+Jjk7P<$fm-?!|?WyxAvkauZyD7cWU0FTT@_4@ev-(?Ns za3Ot?FqhUJXc?SQ2&;@M;MNK+c#*{)YBFcLB+FGw0l#AO!y(B1NE=gbzTK|l3pIL!Fv5Y6Tv@UHX;Go1JEuc7e zI0jl)H{I4dWeNfNK6zk5B|p zGf;rue$hWz{y3LQA9>C4|Ao$1Nx2Q!!y3H5U-ja`9g)cNFD=d6*Y>6E19m5E9LtJg z26BW$x~2MiZLgI91RO;a01AeGr4etkzt0(gcQffFom?vI5XiEK8$Em%LZ8==oqr$at&u)NlSQ`A|n zSPfM3?+)YvOP~v=IMk%%;&B!|j;j;rzT@vTwrvwZBT@@Af40!XqUF3b z8fdEE`D~4L;fNswy1y8U7cW{QveupvREi*Ts5}QDv=UcP#JW`~d2I7Er0oHM>OK3}mbNas14<&o&tcqI@_m_5ZZ0D%)Fmn3s1|<%LziiOl}X4Q;U+&{}Nu?v~z5HWIOQ9yX=sojZhpII>vT#lFY#Nq2ZIoo5V3NC`UYBS`{)@T^{O~ zZXonnDEhk6srREBn34tu8WpJzL1h}=d z9_~uo0=FG|n&F*_y;AV{ur3SlJWLP6!&ewM*xJPQS=8O|v9IbH6FzSFxr==)<37kf z)>WQnA9ItygwQuB7qSQWw(KQMYh=;MP;GaJlq1&?e!Y z2KP8RUASk!J)X`K?pbh8pv}TP8}5me5pEyclc-;~18`5KEZjz1(B|>G|Ej-8u4G|q zqOC~ZOqalIp*O%?g%8Ext;QEk!n=&UHFUZ3u3)bf-`@!DD)!dW)zZ6$y;Ja6i17BZ z*M@u2gm)c#>+o5E@UCaCo$pQa_`UDy_em~QVei2Hcz|?Zk376i?2{MX&FrnmHf`bE z%3c?)KNH^V>~&)&vGDF-uLl>C3GXiUda=({cz3h60T-1C?_Tyc(tZD5d)ERcS5c*J z_s#{$11HtfndzPoLnH~{ou0n8`}Sj2{KCt1Q9dT_2_e8j z2+xoJ2Et2ljYQZXx`K<3Pd4kqiYutd!w8S($z&!(Sni$gtN+%0 zRdwCDRp&qFR2_lM1fQ}IxU9i;-$m0-h@yuu{n4l4T!`GK;a~{(jJ-wRHiDDk+QxvG zE8(WkBK#P`odOS2$8!oCuNdwo_#C2xF?@yK^Kb`ZKs1wZ)88Xn7z1LJgqsTRQ(@Rf zP^9Q#jkc{9zb0*~yUr5)DR55-J{5p6f_^bPNKk==AJBsUV1W4u0>-d|U;zx&fQ2wp z1HND*?gqiP2~LGA6|e|_x&WskSQi7rV1%0%!=wl3g;@`?H%p5b*~QT_B8EMTl1g zTuVW#1Q8P;jIe>AF~D`iWq^njh(J~iwt>|@l-iqd6Noka!-y0J;U9>3DOi+0jQJLb zLIuRc2rQG&h{f>32os2)RKTk#G8J$Gg{K0-j~`3hGya(nPW>xsoJD}Za|jV7@LWQ8 zoS&!hd_u$xynqnF11}`J36uT84JvO9tXV6yH={jp72UNN6VwQAMz}_emk=Tr;98BB z65fgsjv6l`gm3WW8m}PSf{8gAuOvkLz^gQ_C%heVL^N(7+=?~RHC{`IFoTHb)Lv+(HNk!rL_7PKY3b zTL}?q@D7c462j5#E{%5+!t3oGjR>pMU>mq(iqzgnR>1q{uKN+qkPyCF|E%$AgmB#2 zrt#~92r+oS#_fcNH~0;W4-mq`=s`k6Ap94N1B3`i_>jgOggdYjy~b}5eiP9GH6p4} zgKc2#6Hg(sTvV|8f*iXo-DODvNtSnFVkJX-w?ta_dgncONc;*uMi@d;qNrQN(gJu?=`+g z2-DB&8s8v<9q11l|48^V^ihOAM<1o}O~PLwo}I>(G!#FBK8iTNu-m}8nA9FuF=IeT z!}I7a;Q55lh7b}5_#ApLjTaF<4@RPK6(PbOuGYAQ@K=Z{t8pzMw6vEJzKA|b<7I@u zMjxf|3c{DrM`^s0@MZK-jcOk{_VPnccs~g(xN1FJjd+JwYurGH;D^^}yq55{=)nk~ z7Q3GCcj%)u-bjcrg&PT>EV@bKCXJg3p+UM?<1HF*C43!ymBuX^ZzFsIJWb<$8ox^T z2lOTyzou~;;UD3ltMPt~+X)dV@f#W+B1G849fW^EZ=vy9gm0p^(D>~}tv2-k;JM3> z>OPQ$)E(9#H-Ajs3tNH#p{W^c+q?xU=51KlC+Vtq0Ss>4#f(}Xk9YiuZg&;SJe58nMf-SD2@wde$ z>Jk;PsFk^3jG1Mes4JKvak#h$cI|cog+6`7yzZI!SFsQjh*El;7UBX?O0N*%_&BB4 zMiF`_rB?;VX-?_&Afha%^hzv#Ar=DmpvvHc4j7>WKIniAI$(j0-9icFh#ES?2_2$@ z%mN+zgR}<@<=CK54lyOi22pZ|8#y+pkwa|AvCF9YD7M@G>5=YM{5)T8Kvr$og!yPOmcCdul!SZ1T!k5xXk_|h!x9&iEHQJ}1 z8rO45y)>@plzM1f&nf9X5~K}C5ZO)G;JOJG_!2DcC0N)?AoM65CqXZPh?SI{gL)^p z159xDm*CDX!Cha1JH7;Bg3&e9=_L>uj8f{T5(vdb|Ee=60SoU$Joiy=Pha(B_d#e3 z`A_de=xf?1dAO6M;ZBx?I}yW`j*uLTb4ue1j&n+5N+*vforv~E`!t$#BIX-D zg=SW@G}}k={!yIXjK|@`EdtE;nuYB(3)^c(fN8#j*>UfUNZtt@AhYIU;jY& zRQx=Y!W5@jC{D9boMuEB=5tJOnniqSMtDg+$ih=If;@7LMW<$woSG5vkq@%m)NHfZ z)QmV;I5>qBIa5T~o&s5$k6kRVN?^6X6%9vp%X)SF@!iv@;?n6TR^lj|lsHQ0o&w$D z-1h~T&?zBwO5{z2D4u-Dy#g#wDv>6Y2$KqdHTjZl0xU@?8KRVoPzu4+_!1tMlnhHs zMj<7Gj*>A3&y*{91c|T`En**ynO_Xsepj|i=gV5SeBV_F|UAaKqxJB5$_JUav>}u!=a{y%32SMynY7@Ua*ioWjMU1p?CxK%xgs?4+LO9x zQNxKq6l1$Xj8(}oR@BC9Qq;y+Q5&;KQ5$3BY|JL*Y|JijTI95cQ?gdXSiu?-9cj$I zn0{hRbfhtRwdB?aTq3Ym;8KA{1XzI=xHwKe?NXA-G9|MHo7;KZ#SAIu}4)TSZCXQSW2$FJY`TiG^wQA$3^Jq}9 zSeCA1Kx8tkr8_WwI%LRlXvlMH^ec|Nkdjj=SwzVaO8O~TPRZGnti(GptmWc{|Cpi3 zrZeXesc>xiDGu{Shoxx{6Fx%U21pI3B(yjzSvx%VcW|fH!M#`qQ_2n=78CSAL(0eH z;0c_P>N~;Rd?$VRoop8B#1d7sPa;mIh&IjKUo_i&c+<`H8Jw~`0x~SFf}Bb{!xZ^C zr^xrH$g-&Dzf_U^P;tMe$R3M*>Y|iA3ynU?ZT+Sf=5Z%y-Ya!Kiic*!c230{S+Si{ z@rRTGcaY{p!vQOglQ=F1rQSor4*siFEF5?K<6%`L%itUPu$TN-FJy<<#ZXRD>x;4qY@LN5^JK8K~af~P>B?+M0{2v z<0U1Q&YCFDbc|wv8pMtswpw2DG>vd z*wLzts-8+cCM7aeRALQNBD*RPT9w$plu!#LoI(kwQ0UtmG-+t&tq;vR1bqe?p1XV{ zUA_`oPKgkw#F(YThNW0Jfg64;m3m3wWdSx*DX~&1kw2AqZzwTBDUm;wn4pwcpp+P( z6e}h0Xf`(~p&=3WABnK8E5c%DgvHJXdyz!!vrzj8%K#CvQ%1x<*}^hNi&&6bumTmX zYY}r?3$!c^T4d;9m}4H9M=CS$6q0+QZ1|6|;Xi7Bk&m3o=?*FYbb(;1eK4ojNrt76 zR+f)iMRiw|-k+i?TE)+$jrCKIr!S;~ZK5t{6Fq^5z$}c#n25)ih{s5U1`(8eBx0=C zh}lQ+{?VM0FGS2<%qdgR7^_hrAc@d7Y3T1AK0ol~ z8=c!}GU-U$SGFXr_s}Iftivb$2)NR6e{&+EcjZpT)DcSX*-tR0ZJqp!e= z-So*d{e|M9O2W(TzqGfvKjEe=>#xqc5icY#kUAXJ&(la?JK8M0n zZZcOYO7ULatrjZps%z-GI*8t2m%L9e<&-#f+b2y$<*a#=Bb`kpM?Bl$$x?1AJ>tE& z;m_)O^TVH&I;R_ytIuXeym!PW``$?R`u>P#8~h@vRmL6Z-pq(?mB|jhcM`u}gjMYQ zSnqr|Tz+$FzZJLYzfis=A*JgNTxXKC7pCgZ&~S!b?5T6Ip3?x`E|LvXJ*{m zbD4BqE?b++*3~oX*Z!coN9O7-%+*yoS6AtLUE%q?OmV7b=9kblA&;y=>UahdpGAA#VbG%U(W} zEvIF-;JRt}%!Yn^=Uvux%XF$5eT^B7rqj*oe0e|aggwc6X^p-dPDwVU?@H;rQh9y6 zps}d2q_IaZt?x_gysulrcjdgV&-?nhzJ88hlH#)hMFD+K*SJT1d@)&cb(0iJeqJ|8 zDevdK2_@=s)A@ASmEB@8Sx)h;m&_*9nNU(^a_Mw+w@{K@w6UL0g_8Au`i8ul?vdSe zCSNMcZno^Ei*z~HES2mj<59ZfP3Z!XX*ZiLO4Tzt50&J%nN1a|yCpAKk)t`+&!u_` zeGB`#=v(dU>MwOIFO*JO)I~1bOP4Jo$Mn;%?%2Y`^E(QQ=JzgL*uOvqkdz)kFc6rr zCFS%is$hJnEbVeLrEET(Db3jX+XN}!ub2vy^uS3&q#mep7{qvtbjxO#l2OXdQfpwC z%$RYioK1O^WF}Mn6@FzLbtbjQh1Riu9kT3pYs!9~ThQOXq^q+N1AJl8g5JLVt{na^ zI+qldbWVKg%@1wgcu%`E`OxkoyJz%OmZBMF6#8e3aLbxMe`xy++m!X$LXX$|@xSR^ z{v+NBb*%{dhWRad_yY50c;e2vtB8X*)1<5GL=ycRqA5 zayvo~Tcj0gU5Q@;xh}lY3Z31I6JwO`@SMgG;*G& z<-F8;_@5@>7tBt{?3DE-h24vSe-Y717h3bVk(gMl3T&mUS1YjP>jbt^v0^@ilKv3# zJ@O?`*X89aN%I}l3W=%Z`Wq`WkWEv`+A`f*8L{!Fml^u$74q3aw&K=&dWBUXU2@5k z41u^#EFPigf~$Y5=jk8oo3EZf`eZ7X*3u~zo%7th5s`H-kRI#>N-K0t%BChm1@sYW zf_9bu2V$)V>1k6F5!1bbX?Lzk+N}(hT-L;(+W2Vex+d`JTHmW}{Zh3Fs`9xM>`CLN zvN_!XY1dDsJil6Of%(+iMn*@+)3pCX*8ARG(uNjd{{KiFlgxnVWz&UfCY>vJp=34d zL$;_&GW$?4!JrdtK??*e5VSzh0znG|E%5ee0WBBT@Nc6404J|%0E%uoo6Pm($3dot zzg6@9OqCIpcjf?p zNuz*+^{9@Yj!>8Chw1hVq3FU-YbZKX@-#m4y1FFGUX`+DlGVBxBN`q%>bf*0>A9gK zo$HdxX6oxw*J-#~Uyw1DwO!N&J+(TMR4r?7{DyK`XOc~7+AeRTt`&?S@!hU3cyH5+ zKwki*-X2>iCb@c4^s+gzX?V%q8!T{_{BzKqj>VSs$U<+CxXn~*w zf))r`;2qxr!vAaex8eUdR^|UCH`|je=KWEz<~_N{@c&)tM~(e|EHtC~Ba(Ykn<3W@ zrT=q<{?8qr{?DcVg{ZZCkp9ml1pyB3F!Ue$3qH9Q=s&!7ZrM3`pV9wU?36XRA^ji5 z3UAEuMl;~|1a^6Ldo}mgM**>M*O#vp}y)fu&*rj z4O^vbdl~`2YBD#{U*p8DQ$YHGePo{?ioxSJb}q{XfxuWEkIn zP5#pwGa9oRa~ku(Jp8JeJ#~(@_ovMq^gS^5=ZDVx&*&-WVr|2uUhPtzN#--viSRTn z+{J=Q=95mJtE-UNtA=GU(50$w?U`iR&l&G})WPdX4f4;7sYBM(VGm{;R8@i183$%6 zzSy?CyqO7foT-9Yb);%v$I4i=FAH|nx%U^Uufj}v(67QXufi+_ zF!Yz_bg6k$>K;sQsPb;C4Uk25dL4ozYSL?46^@9t|wVa<@f&V{~0rk{lChI%nD&O z3V=b`cj!uBd9xCjk@{sqZMrS$3!$Cl>XCUbu0deN`d|%$w@elc9vrkl&;mgV1TFCHX#p){ z*6?qm06>6{s{cQh{&UN@e0ErtJf4Gw|NGh|hQ+=`$gSc3Rioc7>u=|^8y})NNSqpx zqci0}l9d_Hnguce;P-VC01gl)Ki9HOo;v;s05MDe7}$ps0M<60Kf(lnQ89T#>5c6_ zp!9?PZNb`ph)^{QnGM$VL$t1px5l_%?6TZx)$yP%8bDnvhCwyx9&q})`#DS!7!zrimJS|DhF fpatH&Eui^-4gaq4e}9nwBR*oeoPP^E04Dq&;GxU{ literal 0 HcmV?d00001 diff --git a/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/api/XACMLErrorConstants.java b/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/api/XACMLErrorConstants.java new file mode 100644 index 000000000..5a2eac109 --- /dev/null +++ b/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/api/XACMLErrorConstants.java @@ -0,0 +1,56 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-XACML + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.openecomp.policy.xacml.api; + +/** + * List of Error Classifications + * PE100 - Permissions + * PE200 - System Error (such as availability, timeout, configuration, etc...) + * PE300 - Data Issue( such as request for REST/JSON ) + * PE400 - Schema validation + * PE500 - Process Flow issues + * PE900 - Default/Unknown Errors + * + * + */ +public class XACMLErrorConstants { + //Captures all the errors related to Authentication, Authorizations and Permissions in the PolicyEngine Process + public static final String ERROR_PERMISSIONS = "PE100 - Permissions Error: "; + + //Captures all the errors related to availability, timeout configuration variables, etc... in the PolicyEngine + public static final String ERROR_SYSTEM_ERROR = "PE200 - System Error: "; + + /* + * Captures all the errors related to configuration values from properties files and data from the interfacing System + * like REST/JSON values + */ + public static final String ERROR_DATA_ISSUE = "PE300 - Data Issue: "; + + //Captures all the errors related to the XML schemas and/or REST/JSON structures + public static final String ERROR_SCHEMA_INVALID = "PE400 - Schema validation Error: "; + + //Captures all the errors related to the Process, when data from one Process to another Process does not flow + public static final String ERROR_PROCESS_FLOW = "PE500 - Process Flow Issue: "; + + //Captures all the errors that not related to the list of above error codes + public static final String ERROR_UNKNOWN = "PE900 - Unknown Error: "; + + +} diff --git a/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/api/pap/ECOMPPapEngineFactory.java b/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/api/pap/ECOMPPapEngineFactory.java new file mode 100644 index 000000000..d34d03348 --- /dev/null +++ b/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/api/pap/ECOMPPapEngineFactory.java @@ -0,0 +1,38 @@ +package org.openecomp.policy.xacml.api.pap; + +import java.util.Properties; + +import com.att.research.xacml.api.pap.PAPException; +import com.att.research.xacml.util.FactoryException; +import com.att.research.xacml.util.FactoryFinder; + +public abstract class ECOMPPapEngineFactory{ + + /** + * Creates a new PAPEngineFactory instance using the given class name and the default thread class loader. + * + * @param factoryClassName the String name of the factory class to instantiate + * @return an instance of an object that extends ECOMPPapEngineFactory to use in creating PAPPolicyEngine objects. + */ + public static ECOMPPapEngineFactory newInstance(String factoryClassName) throws FactoryException { + return FactoryFinder.newInstance(factoryClassName, ECOMPPapEngineFactory.class, null, true); + } + + /** + * Creates a new PAPPolicyEngine based on the configured ECOMPPapEngineFactory. + * + * @return a new PAPPolicyEngine + * @throws PAPException + */ + public abstract PAPPolicyEngine newEngine() throws FactoryException, PAPException; + + /** + * Creates a new PAPPolicyEngine based on the configured ECOMPPapEngineFactory. + * + * @return a new PAPPolicyEngine + * @throws PAPException + */ + public abstract PAPPolicyEngine newEngine(Properties properties) throws FactoryException, PAPException; + + +} diff --git a/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/api/pap/EcompPAPPolicy.java b/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/api/pap/EcompPAPPolicy.java new file mode 100644 index 000000000..c18ad230f --- /dev/null +++ b/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/api/pap/EcompPAPPolicy.java @@ -0,0 +1,89 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-XACML + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.openecomp.policy.xacml.api.pap; + +import java.net.URI; +import java.util.List; +import java.util.Map; + +import org.openecomp.policy.xacml.std.pap.StdPAPPolicy; + +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonSubTypes.Type; + +/* + * The following allows us to use Jackson to convert sub-types of this type into JSON and back to objects. + */ +@JsonTypeInfo( + use = JsonTypeInfo.Id.NAME, + include = JsonTypeInfo.As.PROPERTY, + property = "PAPPolicyType") +@JsonSubTypes({ + @Type(value = StdPAPPolicy.class, name = "StdPAPPolicy") }) +public interface EcompPAPPolicy { + + public String getPolicyName(); + public String getOldPolicyFileName(); + public String getPolicyDescription(); + public String getEcompName(); + public String getConfigName(); + public Map getDynamicFieldConfigAttributes(); + public Map getDynamicSettingsMap(); + public List getDynamicRuleAlgorithmLabels(); + public List getDynamicRuleAlgorithmCombo(); + public List getDynamicRuleAlgorithmField1(); + public List getDynamicRuleAlgorithmField2(); + public List getDynamicVariableList(); + public List getDataTypeList(); + public String getConfigBodyData(); + public String getPolicyID(); + public String getRuleID(); + public String getConfigType(); + public Boolean isEditPolicy(); + public Boolean isDraft(); + public String getVersion(); + public String getDomainDir(); + public String getConfigPolicyType(); + public String getJsonBody(); + public Integer getHighestVersion(); + public URI getLocation(); + public String getActionPerformer(); + public String getActionAttribute(); + public String getActionBody(); + public Map getDropDownMap(); + public String getActionDictHeader(); + public String getActionDictType(); + public String getActionDictUrl(); + public String getActionDictMethod(); + public String getServiceType(); + public String getUuid(); + public String getMsLocation(); + public String getPriority(); + public String getDeleteCondition(); + public String getDictionaryType(); + public String getDictionary(); + public Map getDictionaryFields(); + + public String getRiskLevel(); + public String getGuard(); + public String getRiskType(); + public String getTTLDate(); +} diff --git a/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/api/pap/EcompPDP.java b/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/api/pap/EcompPDP.java new file mode 100644 index 000000000..f00dd7ac5 --- /dev/null +++ b/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/api/pap/EcompPDP.java @@ -0,0 +1,46 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-XACML + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.openecomp.policy.xacml.api.pap; + +import java.util.Set; + +import org.openecomp.policy.xacml.std.pap.StdPDP; + +import com.att.research.xacml.api.pap.PDP; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonSubTypes.Type; + +/* + * The following allows us to use Jackson to convert sub-types of this type into JSON and back to objects. + */ +@JsonTypeInfo( + use = JsonTypeInfo.Id.NAME, + include = JsonTypeInfo.As.PROPERTY, + property = "PDPType") +@JsonSubTypes({ + @Type(value = StdPDP.class, name = "StdPDP") }) +public interface EcompPDP extends PDP { + + public Integer getJmxPort(); + + public void setJmxPort(Integer jmxport); + +} diff --git a/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/api/pap/EcompPDPGroup.java b/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/api/pap/EcompPDPGroup.java new file mode 100644 index 000000000..a64b4b6dc --- /dev/null +++ b/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/api/pap/EcompPDPGroup.java @@ -0,0 +1,11 @@ +package org.openecomp.policy.xacml.api.pap; + +import java.util.Set; + +import com.att.research.xacml.api.pap.PDPGroup; + +public interface EcompPDPGroup extends PDPGroup { + + public Set getEcompPdps(); + +} diff --git a/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/api/pap/PAPPolicyEngine.java b/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/api/pap/PAPPolicyEngine.java new file mode 100644 index 000000000..0c5c334da --- /dev/null +++ b/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/api/pap/PAPPolicyEngine.java @@ -0,0 +1,66 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-XACML + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.openecomp.policy.xacml.api.pap; + +import java.io.InputStream; +import java.util.Set; + +import com.att.research.xacml.api.pap.PAPException; +import com.att.research.xacml.api.pap.PDPPolicy; +import com.att.research.xacml.api.pap.PDPStatus; + +public interface PAPPolicyEngine{ + + public EcompPDPGroup getDefaultGroup() throws PAPException; + + public void SetDefaultGroup(EcompPDPGroup group) throws PAPException; + + public void newPDP(String id, EcompPDPGroup group, String name, String description, int jmxport) throws PAPException, NullPointerException; + + public void newGroup(String name, String description) throws PAPException, NullPointerException; + + public EcompPDPGroup getGroup(String id) throws PAPException; + + public Set getEcompPDPGroups() throws PAPException; + + public EcompPDPGroup getPDPGroup(EcompPDP pdp) throws PAPException; + + public PDPStatus getStatus(EcompPDP pdp) throws PAPException; + + public void movePDP(EcompPDP pdp, EcompPDPGroup newGroup) throws PAPException; + + public void updatePDP(EcompPDP pdp) throws PAPException; + + public void removePDP(EcompPDP pdp) throws PAPException; + + public EcompPDP getPDP(String pdpId) throws PAPException; + + public void updateGroup(EcompPDPGroup group) throws PAPException; + + public void removeGroup(EcompPDPGroup group, EcompPDPGroup newGroup) throws PAPException, NullPointerException; + +public void publishPolicy(String id, String name, boolean isRoot, InputStream policy, EcompPDPGroup group) throws PAPException; + + // copy the given policy file into the group's directory, but do not include the policy in the group's policy set + public void copyPolicy(PDPPolicy policy, EcompPDPGroup group) throws PAPException; + + public void removePolicy(PDPPolicy policy, EcompPDPGroup group) throws PAPException; + +} diff --git a/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/std/pap/StdEngine.java b/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/std/pap/StdEngine.java new file mode 100644 index 000000000..397f763f2 --- /dev/null +++ b/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/std/pap/StdEngine.java @@ -0,0 +1,1087 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-XACML + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.openecomp.policy.xacml.std.pap; + +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Enumeration; +import java.util.HashSet; +import java.util.List; +import java.util.Properties; +import java.util.Set; +import java.util.TreeSet; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openecomp.policy.xacml.api.pap.EcompPDP; +import org.openecomp.policy.xacml.api.pap.EcompPDPGroup; +import org.openecomp.policy.xacml.api.pap.PAPPolicyEngine; +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.eelf.PolicyLogger; +import com.att.research.xacml.api.pap.PAPException; +import com.att.research.xacml.api.pap.PDP; +import com.att.research.xacml.api.pap.PDPGroup; +import com.att.research.xacml.api.pap.PDPPolicy; +import com.att.research.xacml.api.pap.PDPStatus; +import com.att.research.xacml.util.XACMLProperties; +import com.google.common.base.Joiner; +import com.google.common.base.Splitter; +import com.google.common.collect.Sets; + +/** + * This is a simple PAP engine that uses some property files and a simple directory + * structure in the file system to manage a policy repository and set of PDP nodes. + * + * + */ +public class StdEngine extends StdPDPItemSetChangeNotifier implements PAPPolicyEngine { + private static Log logger = LogFactory.getLog(StdEngine.class); + + public static String PROP_PAP_REPO = "xacml.pap.pdps"; + public static String PROP_PAP_GROUPS = "xacml.pap.groups"; + public static String PROP_PAP_GROUPS_DEFAULT = "xacml.pap.groups.default"; + public static String PROP_PAP_GROUPS_DEFAULT_NAME = "default"; + //this value will be accessed from XacmlPapServlet so that we know if a default group did not exist + //and was just added. This way, we can add the new group to the database. + public boolean wasDefaultGroupJustAdded = false; + + protected final Path repository; + protected Set groups; + + public StdEngine() throws PAPException, IOException { + // + // Get the location in the file system of our repository + // + this.repository = Paths.get(XACMLProperties.getProperty(PROP_PAP_REPO)); + // + // Initialize + // + this.intialize(); + } + + public StdEngine(Properties properties) throws PAPException, IOException { + // + // Get the location in the file system of our repository + // + this.repository = Paths.get(properties.getProperty(PROP_PAP_REPO)); + // + // Initialize + // + this.intialize(); + } + + public StdEngine(Path repository) throws PAPException, IOException { + // + // Save our location + // + this.repository = repository; + // + // Initialize + // + this.intialize(); + } + + private void intialize() throws PAPException, IOException { + // + // Sanity check the repository path + // + if (this.repository == null) { + throw new PAPException ("No repository specified."); + } + if (Files.notExists(this.repository)) { + Files.createDirectory(repository); + } + if (Files.isDirectory(this.repository) == false) { + throw new PAPException ("Repository is NOT a directory: " + this.repository.toAbsolutePath()); + } + if (Files.isWritable(this.repository) == false) { + throw new PAPException ("Repository is NOT writable: " + this.repository.toAbsolutePath()); + } + // + // Load our groups + // + this.loadGroups(); + } + + private void loadGroups() throws PAPException { + // + // Create a properties object + // + Properties properties = new Properties(); + Path file = Paths.get(this.repository.toString(), XACMLProperties.XACML_PROPERTIES_NAME); + try { + // + // Load the properties + // + try (InputStream is = new FileInputStream(file.toFile())) { + properties.load(is); + } + + // + // Parse it + // + this.groups = this.readProperties(this.repository, properties); + } catch (IOException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Failed to load " + file.toAbsolutePath().toString()); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdEngine", "Failed to load properties file"); + this.groups = new HashSet(); + } + // + // Initialize the default group + // + PDPGroup defaultGroup = this.initializeDefaultGroup(file, properties); + logger.info("Default group is: " + defaultGroup.getId() + "=" + defaultGroup.getName()); + } + + private PDPGroup initializeDefaultGroup(Path file, Properties properties) throws PAPException { + wasDefaultGroupJustAdded = false; + // + // Make sure we have the default group + // + PDPGroup group = this.getDefaultGroup(); + if (group != null) { + return group; + } + // + // We don't have the default group, create it + // + String defaultId = properties.getProperty(PROP_PAP_GROUPS_DEFAULT, PROP_PAP_GROUPS_DEFAULT_NAME); + if(defaultId == null){ + defaultId = PROP_PAP_GROUPS_DEFAULT_NAME; + } + if(defaultId.equals("")){ + defaultId = PROP_PAP_GROUPS_DEFAULT_NAME; + } + //we're going to check one more time in case the PROP_PAP_GROUPS_DEFAULT_NAME doesn't exist + if(defaultId == null){ + defaultId = "default"; + } + if(defaultId.equals("")){ + defaultId = "default"; + } + logger.warn("Default group does NOT exist, creating " + defaultId); + Path defaultPath = Paths.get(this.repository.toString(), defaultId); + try { + // + // Does it exist? + // + if (Files.notExists(defaultPath)) { + // + // Create its directory + // + Files.createDirectory(defaultPath); + // + // Create property files + // + { + Properties props = new Properties(); + props.setProperty(XACMLProperties.PROP_REFERENCEDPOLICIES, ""); + props.setProperty(XACMLProperties.PROP_ROOTPOLICIES, ""); + Path policyPath = Paths.get(defaultPath.toAbsolutePath().toString(), "xacml.policy.properties"); + Files.createFile(policyPath); + try (OutputStream os = Files.newOutputStream(policyPath)) { + props.store(os, ""); + } catch (IOException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Failed to write default policy properties", e); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdEngine", "Failed to write default policy properties"); + } + } + { + Properties props = new Properties(); + props = setPIPProperties(props); + Path pipPath = Paths.get(defaultPath.toAbsolutePath().toString(), "xacml.pip.properties"); + Files.createFile(pipPath); + try (OutputStream os = Files.newOutputStream(pipPath)) { + props.store(os, ""); + } catch (IOException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Failed to write default pip properties", e); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdEngine", "Failed to write default pip properties"); + } + } + } + // + // Create the default group + // + StdPDPGroup newDefault = new StdPDPGroup(defaultId, true, "default", "The default group where new PDP's are put.", defaultPath); + // + // Add it to our list + // + this.groups.add(newDefault); + // + // Save our properties out since we have + // a new default group. + // + StdEngine.setGroupProperties(newDefault, properties); + // + // Save it to disk + // + try { + try (OutputStream os = Files.newOutputStream(file)) { + properties.store(os, ""); + } + } catch (IOException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error("Failed to save properties with new default group information.", e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "StdEngine", "Failed to save properties with new default group information."); + } + // + // Return it + // + wasDefaultGroupJustAdded = true; + return newDefault; + } catch (IOException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error("Failed to create default group: " + defaultId, e); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "StdEngine", "Failed to create default group"); + throw new PAPException("Failed to create default group"); + } + } + + + + + @Override + public EcompPDPGroup getDefaultGroup() throws PAPException + { + for (EcompPDPGroup group : this.groups) { + if (group.isDefaultGroup()) { + return group; + } + } + // + // Default group doesn't exist + // + return null; + } + + /*@Override + public void SetDefaultGroup(PDPGroup group) throws PAPException { + + boolean changesMade = false; + for (PDPGroup aGroup : groups) { + if (aGroup.getId().equals(group.getId())) { + if ( ! aGroup.isDefaultGroup()) { +//TODO - since the original code checked for type we do also. + if (aGroup instanceof StdPDPGroup) { + ((StdPDPGroup) aGroup).setDefault(true); + changesMade = true; + } else { + throw new IllegalArgumentException("Group in groups of unknown type '" + aGroup.getClass().getName() + "'"); + } + } + } else { + // not the new default group + if (aGroup.isDefaultGroup()) { +//TODO - since the original code checked for type we do also. + if (aGroup instanceof StdPDPGroup) { + ((StdPDPGroup) aGroup).setDefault(false); + changesMade = true; + } else { + throw new IllegalArgumentException("Group in groups of unknown type '" + aGroup.getClass().getName() + "'"); + } + } + } + } + if (changesMade) { + this.doSave(); + } + + return; + }*/ + + /*@Override + public Set getPDPGroups() throws PAPException { + final Set grps = new HashSet(); + for (PDPGroup g : this.groups) { + grps.add(g); + } + return Collections.unmodifiableSet(grps); + }*/ + + @Override + public EcompPDPGroup getGroup(String id) throws PAPException { + for (EcompPDPGroup g: this.groups) { + if (g.getId().equals(id)) { + return g; + } + } + return null; + } + + @Override + public void newGroup(String name, String description) throws PAPException, NullPointerException + { + // + // Null check + // + if (name == null) { + throw new NullPointerException(); + } + // + // Do we already have this group? + // + for (PDPGroup group : this.groups) { + if (group.getName().equals(name)) { + throw new PAPException("Group with this name=" + name + " already exists."); + } + } + + + // create an Id that can be used as a file name and a properties file key. + // Ids must not contain \/:*?"<>|=,; + // The ID must also be unique within the current set of PDPGroups. + String id = createNewPDPGroupId(name); + + + // + // Construct the directory path + // + Path groupPath = Paths.get(this.repository.toString(), id); + // + // If it exists already + // + if (Files.exists(groupPath)) { + logger.warn("addGroup " + id + " directory exists" + groupPath.toString()); + } else { + try { + // + // Create the directory + // + Files.createDirectory(groupPath); + } catch (IOException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Failed to create " + groupPath); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdEngine", "Failed to create " + groupPath); + throw new PAPException("Failed to create " + id); + } + } + // + // Create the Policies + // + + Path policyProperties = Paths.get(groupPath.toString(), "xacml.policy.properties"); + if (Files.exists(policyProperties)) { + logger.warn("addGroup " + id + " file exists: " + policyProperties.toString()); + } else { + Properties props = new Properties(); + props.setProperty(XACMLProperties.PROP_REFERENCEDPOLICIES, ""); + props.setProperty(XACMLProperties.PROP_ROOTPOLICIES, ""); + try { + Files.createFile(policyProperties); + try (OutputStream os = Files.newOutputStream(policyProperties)) { + props.store(os, ""); + } + } catch (IOException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error("Failed to create " + policyProperties); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "StdEngine", "Failed to create " + policyProperties); + throw new PAPException("Failed to create " + id); + } + } + // + // Create the PIP config + // + Path pipProperties = Paths.get(groupPath.toString(), "xacml.pip.properties"); + if (Files.exists(pipProperties)) { + logger.warn("addGroup " + id + " file exists: " + pipProperties.toString()); + } else { + try { + Properties props = new Properties(); + props = setPIPProperties(props); + Files.createFile(pipProperties); + try (OutputStream os = Files.newOutputStream(pipProperties)) { + props.store(os, ""); + } + } catch (IOException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Failed to create " + pipProperties); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdEngine", "Failed to create " + pipProperties); + throw new PAPException("Failed to create " + id); + } + + } + // + // Ok now add it + // + StdPDPGroup newGroup = new StdPDPGroup(id, name, description, groupPath); + if (this.groups.add(newGroup)) { + // save the new group in our properties and notify any listeners of the change + groupChanged(newGroup); + } + + } + + + + + /** + * Helper to create a new Group ID. + * Use the Name field to create the Id. + * The Name is expected to not be null; if it is then this method throws an exception. + * The name is supposed to be unique within the current set of groups, + * so creating the ID based on the name will create a unique string. + * + * @param name + * @return + */ + private String createNewPDPGroupId(String name) { + String id = name; + // replace "bad" characters with sequences that will be ok for file names and properties keys. + id = id.replace(" ", "_sp_"); + id = id.replace("\t", "_tab_"); + id = id.replace("\\", "_bksl_"); + id = id.replace("/", "_sl_"); + id = id.replace(":", "_col_"); + id = id.replace("*", "_ast_"); + id = id.replace("?", "_q_"); + id = id.replace("\"", "_quo_"); + id = id.replace("<", "_lt_"); + id = id.replace(">", "_gt_"); + id = id.replace("|", "_bar_"); + id = id.replace("=", "_eq_"); + id = id.replace(",", "_com_"); + id = id.replace(";", "_scom_"); + + return id; + } + + + @Override + public EcompPDP getPDP(String pdpId) throws PAPException { + for (EcompPDPGroup group : this.groups) { + for (EcompPDP pdp : group.getEcompPdps()) { + if (pdp.getId().equals(pdpId)) { + return pdp; + } + } + } + return null; + } + + + @Override + public void movePDP(EcompPDP pdp, EcompPDPGroup newGroup) throws PAPException { + if (newGroup == null) { + throw new NullPointerException("You must specify which group the PDP will belong to."); + } + PDPGroup currentGroup = this.getPDPGroup(pdp); + if (currentGroup == null) { + throw new PAPException("PDP must already belong to a group."); + } + if (currentGroup.equals(newGroup)) { + logger.warn("Already in that group."); + return; + } + if (currentGroup instanceof StdPDPGroup && newGroup instanceof StdPDPGroup) { + if (((StdPDPGroup) currentGroup).removePDP(pdp)) { + boolean result = ((StdPDPGroup) newGroup).addPDP(pdp); + if (result) { + // + // Save the configuration + // + this.doSave(); + } else { + //TODO:EELF Cleanup - Remove logger + //logger.error("Failed to add to new group, putting back into original group."); + PolicyLogger.error("Failed to add to new group, putting back into original group."); + if (((StdPDPGroup) currentGroup).removePDP(pdp) == false) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Failed to put PDP back into original group."); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + "Failed to put PDP back into original group."); + } + } + } + } else { + String message = "Unknown PDP group class: " + newGroup.getClass().getCanonicalName() + " and " + currentGroup.getClass().getCanonicalName(); + logger.warn(message); + throw new PAPException(message); + } + } + + + @Override + public void updatePDP(EcompPDP pdp) throws PAPException { + PDP currentPDP = this.getPDP(pdp.getId()); + if (currentPDP == null) { + String message = "Unknown PDP id '" + pdp.getId() + "'"; + logger.warn(message); + throw new PAPException(message); + } + + // the only things that the user can change are name and description + currentPDP.setDescription(pdp.getDescription()); + currentPDP.setName(pdp.getName()); + if (currentPDP instanceof EcompPDP && pdp instanceof EcompPDP) { + ((EcompPDP)currentPDP).setJmxPort(((EcompPDP)pdp).getJmxPort()); + } + this.doSave(); + } + + @Override + public void removePDP(EcompPDP pdp) throws PAPException { + PDPGroup group = this.getPDPGroup(pdp); + if (group == null) { + throw new NullPointerException(); + } + if (group instanceof StdPDPGroup) { + boolean result = ((StdPDPGroup) group).removePDP(pdp); + if (result) { + this.doSave(); + } + return; + } + String message = "Unknown PDP group class: " + group.getClass().getCanonicalName(); + logger.warn(message); + throw new PAPException(message); + } + + + @Override + /** + * Should never be called - Detailed status is held on the PDP, not the PAP + */ + public PDPStatus getStatus(EcompPDP pdp) throws PAPException { + return getPDP(pdp.getId()).getStatus(); + } + + @Override + public void publishPolicy(String id, String name, boolean isRoot, InputStream policy, EcompPDPGroup group) throws PAPException { + if (group == null) { + throw new NullPointerException(); + } + if (group instanceof StdPDPGroup && this.groups.contains(group)) { + ((StdPDPGroup) group).publishPolicy(id, name, isRoot, policy); + return; + } + logger.warn("unknown PDP Group: " + group); + throw new PAPException("Unknown PDP Group: " + group.getId()); + } + + // Currently not used on the PAP side. This is done by ((StdPDPGroup) group).copyPolicyToFile + @Override + public void copyPolicy(PDPPolicy policy, EcompPDPGroup group) + throws PAPException { + } + + + @Override + public void removePolicy(PDPPolicy policy, EcompPDPGroup group) throws PAPException { + if (group == null) { + throw new NullPointerException(); + } + if (group instanceof StdPDPGroup && this.groups.contains(group)) { + ((StdPDPGroup) group).removePolicy(policy); + return; + } + logger.warn("unknown PDP Group: " + group); + throw new PAPException("Unknown PDP Group: " + group.getId()); + } + + + // + // HELPER methods + // + + private Set readProperties(Path repository, Properties properties) throws PAPException { + Set groups = new HashSet(); + // + // See if there is a groups property + // + String groupList = properties.getProperty(PROP_PAP_GROUPS, ""); + if (groupList == null) { + logger.warn("null group list " + PROP_PAP_GROUPS); + groupList = ""; + } + if (logger.isDebugEnabled()) { + logger.debug("group list: " + groupList); + } + // + // Iterate the groups, converting to a set ensures we have unique groups. + // + for (String id : Splitter.on(',').trimResults().omitEmptyStrings().split(groupList)) { + // + // Add our Group Object + // + StdPDPGroup g = new StdPDPGroup(id.trim(), + id.equals(properties.getProperty(PROP_PAP_GROUPS_DEFAULT, PROP_PAP_GROUPS_DEFAULT_NAME)), + properties, + Paths.get(repository.toString(), id)); + + // + // Add it in + // + groups.add(g); + } + // + // Dump what we got + // + if (logger.isDebugEnabled()) { + logger.debug("PDP Group List: " + groups.toString()); + } + return groups; + } + + private void saveConfiguration() throws PAPException, IOException { + // + // Create our properties object + // + Properties properties = new Properties() { + private static final long serialVersionUID = 1L; + // For Debugging it is helpful for the file to be in a sorted order, + // any by returning the keys in the natural Alpha order for strings we get close enough. + // TreeSet is sorted, and this just overrides the normal Properties method to get the keys. + @Override + public synchronized Enumeration keys() { + return Collections.enumeration(new TreeSet(super.keySet())); + } + }; + // + // Iterate our groups + // + List ids = new ArrayList(); + for (PDPGroup group : this.groups) { + ids.add(group.getId()); + properties.setProperty(group.getId() + ".name", (group.getName() == null ? "" : group.getName())); + properties.setProperty(group.getId() + ".description", (group.getDescription() == null ? "" : group.getDescription())); + // + // Iterate its PDPs + // + List pdps = new ArrayList(); + for (PDP pdp : group.getPdps()) { + pdps.add(pdp.getId()); + properties.setProperty(pdp.getId() + ".name", (pdp.getName() == null ? "" : pdp.getName())); + properties.setProperty(pdp.getId() + ".description", (pdp.getDescription() == null ? "" : pdp.getDescription())); + if (pdp instanceof EcompPDP) { + properties.setProperty(pdp.getId() + ".jmxport", (((EcompPDP)pdp).getJmxPort()==0 ? "" : ((EcompPDP)pdp).getJmxPort()).toString()); + } + } + String pdpList = ""; + if (pdps.size() == 1) { + pdpList = pdps.get(0); + } else if (pdps.size() > 1) { + pdpList = Joiner.on(',').skipNulls().join(pdps); + } + if (logger.isDebugEnabled()) { + logger.debug("Group " + group.getId() + " PDPS: " + pdpList); + } + properties.setProperty(group.getId() + ".pdps", pdpList); + } + if (ids.isEmpty()) { + throw new PAPException("Inconsistency - we have NO groups. We should have at least one."); + } + String groupList = ""; + if (ids.size() == 1) { + groupList = ids.get(0); + } else if (ids.size() > 1){ + groupList = Joiner.on(',').skipNulls().join(ids); + } + logger.info("New Group List: " + groupList); + + properties.setProperty(PROP_PAP_GROUPS, groupList); + // + // Get the default group + // + PDPGroup defaultGroup = this.getDefaultGroup(); + if (defaultGroup == null) { + throw new PAPException("Invalid state - no default group."); + } + properties.setProperty(PROP_PAP_GROUPS_DEFAULT, defaultGroup.getId()); + // + // Now we can save the file + // + Path file = Paths.get(this.repository.toString(), "xacml.properties"); + try (OutputStream os = Files.newOutputStream(file)) { + properties.store(os, ""); + } + } + + public static void removeGroupProperties(String id, Properties properties) { + for (Object key : properties.keySet()) { + if (key.toString().startsWith(id + ".")) { + properties.remove(key); + } + } + } + + public static void setGroupProperties(PDPGroup group, Properties properties) { + // + // make sure its in the list of groups + // + Iterable groups = Splitter.on(',').trimResults().omitEmptyStrings().split( properties.getProperty(PROP_PAP_GROUPS, "")); + boolean inList = false; + for (String g : groups) { + if (g.equals(group.getId())) { + inList = true; + } + } + if (inList == false) { + Set grps = Sets.newHashSet(groups); + grps.add(group.getId()); + String newGroupList = "";; + if (grps.size() == 1) { + newGroupList = grps.iterator().next(); + } else if (grps.size() > 1) { + newGroupList = Joiner.on(',').skipNulls().join(grps); + } + logger.info("New Group List: " + newGroupList); + properties.setProperty(PROP_PAP_GROUPS, newGroupList); + } + // + // Set its properties + // + properties.setProperty(group.getId() + ".name", group.getName()); + properties.setProperty(group.getId() + ".description", group.getDescription()); + // + // Set its PDP list + // + if (group.getPdps().size() > 0) { + String pdpList = ""; + if (group.getPdps().size() == 1) { + pdpList = group.getPdps().iterator().next().getId(); + } else if (group.getPdps().size() > 1) { + Set ids = new HashSet(); + for (PDP pdp : group.getPdps()) { + ids.add(pdp.getId()); + } + pdpList = Joiner.on(',').skipNulls().join(ids); + } + properties.setProperty(group.getId() + ".pdps", pdpList); + } else { + properties.setProperty(group.getId() + ".pdps", ""); + } + } + + + public void changed() { + if (logger.isDebugEnabled()) { + logger.debug("changed"); + } + this.doSave(); + this.fireChanged(); + } + + public void groupChanged(EcompPDPGroup group) { + if (logger.isDebugEnabled()) { + logger.debug("groupChanged: " + group); + } + this.doSave(); + this.firePDPGroupChanged(group); + } + + + public void pdpChanged(EcompPDP pdp) { + if (logger.isDebugEnabled()) { + logger.debug("pdpChanged: " + pdp); + } + this.doSave(); + this.firePDPChanged(pdp); + } + + private void doSave() { + try { + // + // Save the configuration + // + this.saveConfiguration(); + } catch (IOException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Failed to save configuration", e); + PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "StdEngine", "Failed to save configuration"); + } catch (PAPException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Failed to save configuration", e); + PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "StdEngine", "Failed to save configuration"); + } + } + + // TODO: Adding Default PIP engine(s) while Loading initially. We don't want + // Programmer intervention with the PIP engines. + private Properties setPIPProperties(Properties props){ + props.setProperty(XACMLProperties.PROP_PIP_ENGINES, "AAF"); + props.setProperty("AAF.name", "AAFEngine"); + props.setProperty("AAF.description", "AAFEngine to communicate with AAF to take decisions"); + props.setProperty("AAF.classname","org.openecomp.policy.xacml.std.pip.engines.aaf.AAFEngine"); + return props; + } + + + @Override + public Set getEcompPDPGroups() throws PAPException { + final Set grps = new HashSet(); + for (EcompPDPGroup g : this.groups) { + grps.add(g); + } + return Collections.unmodifiableSet(grps); + } + + @Override + public EcompPDPGroup getPDPGroup(EcompPDP pdp) throws PAPException { + for (EcompPDPGroup group : this.groups) { + if (group.getPdps().contains(pdp)) { + return group; + } + } + return null; + } + + @Override + public void SetDefaultGroup(EcompPDPGroup group) throws PAPException { + boolean changesMade = false; + for (EcompPDPGroup aGroup : groups) { + if (aGroup.getId().equals(group.getId())) { + if ( ! aGroup.isDefaultGroup()) { +//TODO - since the original code checked for type we do also. + if (aGroup instanceof StdPDPGroup) { + ((StdPDPGroup) aGroup).setDefault(true); + changesMade = true; + } else { + throw new IllegalArgumentException("Group in groups of unknown type '" + aGroup.getClass().getName() + "'"); + } + } + } else { + // not the new default group + if (aGroup.isDefaultGroup()) { +//TODO - since the original code checked for type we do also. + if (aGroup instanceof StdPDPGroup) { + ((StdPDPGroup) aGroup).setDefault(false); + changesMade = true; + } else { + throw new IllegalArgumentException("Group in groups of unknown type '" + aGroup.getClass().getName() + "'"); + } + } + } + } + if (changesMade) { + this.doSave(); + } + + return; + + } + + @Override + public void newPDP(String id, EcompPDPGroup group, String name, String description, int jmxport) + throws PAPException, NullPointerException { + if (group == null) { + throw new PAPException("You must specify which group the PDP will belong to."); + } + if (this.groups.contains(group) == false) { + throw new PAPException("Unknown group, not in our list."); + } + for (EcompPDP p : group.getEcompPdps()) { + if (p.getId().equals(id)) { + throw new PAPException("A PDP with this ID exists."); + } + } + if (group instanceof StdPDPGroup) { + StdPDP pdp = new StdPDP(id, name, description, jmxport); + if (((StdPDPGroup) group).addPDP(pdp)) { + // + // Save the properties and notify any listeners + // + pdpChanged(pdp); + return; + } + } + return; + + } + + @Override + public void updateGroup(EcompPDPGroup group) throws PAPException { + if (group == null || group.getId() == null) { + throw new PAPException("Group or id is null"); + } + if (group.getName() == null || group.getName().trim().length() == 0) { + throw new PAPException("New name for group cannot be null or blank"); + } + StdPDPGroup existingGroup = (StdPDPGroup)getGroup(group.getId()); + if (existingGroup == null) { + throw new PAPException("Update found no existing group with id '" + group.getId() + "'"); + } + + + // We do dramatically different things when the Name changes + // because the Name is essentially the identity of the group (as the User knows it) so when the Identity changes we have to change the group ID. + if (group.getName().equals(existingGroup.getName())) { + + // update the disk + try { + ((StdPDPGroup)group).saveGroupConfiguration(); + } catch (IOException e) { + throw new PAPException("Unable to save new configuration for '" + group.getName() + "': " + e.getMessage()); + } + // update the group in the set by simply replacing the old instance with the new one + this.groups.remove(existingGroup); + this.groups.add((StdPDPGroup)group); + + } else { + // the name/identity of the group has changed + // generate the new id + String newId = createNewPDPGroupId(group.getName()); + + // make sure no other group uses the new id + for (EcompPDPGroup g : groups) { + if (g.getId().equals(newId)) { + throw new PAPException("Replacement name maps to ID '" + newId + "' which is already in use"); + } + } + ((StdPDPGroup)group).setId(newId); + + // rename the existing directory to the new id + Path oldPath = existingGroup.getDirectory(); + Path newPath = Paths.get(oldPath.getParent().toString(), newId); + ((StdPDPGroup)group).setDirectory(newPath); + + try { + boolean success = oldPath.toFile().renameTo(newPath.toFile()); + if ( ! success) { + throw new PAPException("Unable to rename directory; reason unknown"); + } + } catch (Exception e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Move '" + oldPath + "' to '" + newPath + "': " + e.getMessage(), e); + PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "StdEngine", "Unable to rename directory"); + throw new PAPException("Unable to move directory from '" + oldPath + "' to '" + newPath + "': " + e.getMessage()); + } + // update the disk + try { + ((StdPDPGroup)group).saveGroupConfiguration(); + } catch (IOException e) { + throw new PAPException("Unable to save new configuration for '" + group.getName() + "': " + e.getMessage()); + } + + // save the new group into the Set + groups.remove(existingGroup); + groups.add((StdPDPGroup)group); + + } + + // perhaps only the group changed, but if the name/id changed it may look to a listener like more than one group + changed(); + + + } + + @Override + public void removeGroup(EcompPDPGroup group, EcompPDPGroup newGroup) throws PAPException, NullPointerException { + if (group == null) { + throw new NullPointerException(); + } + // + // Does this group exist? + // + if (this.groups.contains(group) == false) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "This group doesn't exist."); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + "This group doesn't exist."); + throw new PAPException("The group '" + group.getId() + "' does not exist"); + } + // + // Is it the default group? + // + if (group.isDefaultGroup()) { + throw new PAPException("You cannot delete the default group."); + } + Set pdps = group.getEcompPdps(); + // + // Are there PDPs? If so, then we need a target group + // + if (pdps.isEmpty() == false && newGroup == null) { + throw new NullPointerException("Group targeted for deletion has PDPs, you must provide a new group for them."); + } + // + // Move the PDPs + // + if (pdps.isEmpty() == false) { + if (! (newGroup instanceof StdPDPGroup)) { + throw new PAPException("Unexpected class for newGroup: " + newGroup.getClass().getCanonicalName()); + } + // The movePDP function will modify the set of PDPs in the group. + // To avoid concurrent modification exceptions we need to duplicate the list before calling that function. + List pdpList = new ArrayList(); + for (EcompPDP pdp : pdps) { + pdpList.add(pdp); + } + // now we can use the PDPs from the list without having ConcurrentAccessExceptions + for (EcompPDP pdp : pdpList) { + this.movePDP(pdp, newGroup); + } + } + // + // remove the directory for the group + // + String id = group.getId(); + Path groupPath = Paths.get(this.repository.toString(), id); + // + // If it exists already + // + if ( ! Files.exists(groupPath)) { + logger.warn("removeGroup " + id + " directory does not exist" + groupPath.toString()); + } else { + try { + Files.walkFileTree(groupPath, new SimpleFileVisitor() { + + @Override + public FileVisitResult visitFile(Path file, + BasicFileAttributes attrs) throws IOException { + Files.delete(file); + return super.visitFile(file, attrs); + } + + }); + // + // delete the directory + // + Files.delete(groupPath); + } catch (IOException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Failed to delete " + groupPath + ": " +e); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdEngine", "Failed to delete " + groupPath); + throw new PAPException("Failed to delete " + id); + } + } + + // remove the group from the set of all groups + groups.remove(group); + + // + // Save changes + // + changed(); + this.doSave(); + return; + + } + +} diff --git a/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/std/pap/StdEngineFactory.java b/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/std/pap/StdEngineFactory.java new file mode 100644 index 000000000..b8ca1f2e9 --- /dev/null +++ b/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/std/pap/StdEngineFactory.java @@ -0,0 +1,57 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-XACML + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.openecomp.policy.xacml.std.pap; + +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.eelf.PolicyLogger; + +import java.io.IOException; +import java.util.Properties; + +import org.openecomp.policy.xacml.api.pap.ECOMPPapEngineFactory; +import org.openecomp.policy.xacml.api.pap.PAPPolicyEngine; + +import com.att.research.xacml.api.pap.PAPException; +import com.att.research.xacml.util.FactoryException; + +public class StdEngineFactory extends ECOMPPapEngineFactory { + + @Override + public PAPPolicyEngine newEngine() throws FactoryException, PAPException { + try { + return (PAPPolicyEngine) new StdEngine(); + } catch (IOException e) { + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "StdEngineFactory", "Failed to create engine"); + return null; + } + } + + @Override + public PAPPolicyEngine newEngine(Properties properties) throws FactoryException, + PAPException { + try { + return (PAPPolicyEngine) new StdEngine(properties); + } catch (IOException e) { + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "StdEngineFactory", "Failed to create engine"); + return null; + } + } + +} diff --git a/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/std/pap/StdPAPPolicy.java b/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/std/pap/StdPAPPolicy.java new file mode 100644 index 000000000..f4817ac8a --- /dev/null +++ b/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/std/pap/StdPAPPolicy.java @@ -0,0 +1,889 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-XACML + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.openecomp.policy.xacml.std.pap; + +import java.io.Serializable; +import java.net.URI; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.openecomp.policy.xacml.api.pap.EcompPAPPolicy; + +public class StdPAPPolicy implements EcompPAPPolicy, Serializable{ + private static final long serialVersionUID = 5260230629397322000L; + + private String policyName = null; + private String oldPolicyFileName = null; + private String policyDescription = null; + private String ecompName = null; + private String configName = null; + private Map dyanamicFieldConfigAttributes = new HashMap(); + private Map dropDownMap = new HashMap(); + private Map dynamicSettingsMap = new HashMap(); + private List dynamicRuleAlgorithmLabels; + private List dynamicRuleAlgorithmCombo; + private List dynamicRuleAlgorithmField1; + private List dynamicRuleAlgorithmField2; + private List dynamicVariableList; + private List dataTypeList; + private String configBodyData = null; + private String policyID = null; + private String ruleID = null; + private String configType = null; + private Boolean editPolicy = false; + private Boolean draft = false; + private String version = null; + private String domain = null; + private String configPolicyType = null; + private String jsonBody = null; + private String serviceType = null; + private Integer highestVersion = null; + private URI location = null; + private String actionPerformer = null; + private String actionAttribute = null; + private String actionBody = null; + private String actionDictHeader = null; + private String actionDictType = null; + private String actionDictUrl = null; + private String actionDictMethod = null; + private String uuid = null; + private String msLocation = null; + private String priority = null; + private Map drlRuleAndUIParams=null; + private String deleteCondition = null; + private String dictionaryType = null; + private String dictionary = null; + private Map dictionaryFields = new HashMap(); + private String providerComboBox = null; + private String riskType = null; + private String guard = null; + private String riskLevel; + private String ttlDate = null; + + + public StdPAPPolicy() { + + } + + //Constructor for sending location when pushing policies + public StdPAPPolicy(URI location) { + this.location = location; + } + + //Constructor for Validating Config Policies + public StdPAPPolicy(String policyName, String body, String configType, String configPolicyType) { + this.policyName = policyName; + this.configBodyData = body; + this.configType = configType; + this.configPolicyType = configPolicyType; + } + + //convenience constructor + public StdPAPPolicy(String configPolicyType, String policyName, String description, String ecompName, String configName, Map attributes, String configType, + String body, Boolean editPolicy, String domain, String riskLevel, String riskType, String guard, String ttlDate){ + this(configPolicyType, policyName, description, ecompName, configName, attributes, configType, + body, editPolicy, domain, 1, riskLevel, riskType, guard, ttlDate); + } + + //Constructor for Create/Update Action Policies from API + public StdPAPPolicy(String policyName, String description, Map attributes, List dynamicRuleAlgorithmLabels, List dynamicRuleAlgorithmCombo, + List dynamicRuleAlgorithmField1, List dynamicRuleAlgorithmField2, String actionPerformer,String actionAttribute, Boolean editPolicy, + String domain, int highestVersion) { + + this.policyName = policyName; + this.policyDescription = description; + this.dyanamicFieldConfigAttributes = attributes; + this.dynamicRuleAlgorithmLabels = dynamicRuleAlgorithmLabels; + this.dynamicRuleAlgorithmCombo = dynamicRuleAlgorithmCombo; + this.dynamicRuleAlgorithmField1 = dynamicRuleAlgorithmField1; + this.dynamicRuleAlgorithmField2 = dynamicRuleAlgorithmField2; + this.actionPerformer = actionPerformer; + this.actionAttribute = actionAttribute; + this.editPolicy = editPolicy; + this.domain = domain; + this.highestVersion = highestVersion; + + } + + //Constructor for Create/Update Decision Policies from Admin Console + public StdPAPPolicy(String policyName, String description, String ecompName, String providerComboBox, Map attributes, Map settings, + List dynamicRuleAlgorithmLabels, List dynamicRuleAlgorithmCombo, List dynamicRuleAlgorithmField1, + List dynamicRuleAlgorithmField2, Map dropDownMap, List dynamicVariableList, + List dataTypeList, Boolean editPolicy, String domain, int highestVersion) { + + this.policyName = policyName; + this.policyDescription = description; + this.ecompName = ecompName; + this.setProviderComboBox(providerComboBox); + this.dyanamicFieldConfigAttributes = attributes; + this.dynamicSettingsMap = settings; + this.dynamicRuleAlgorithmLabels = dynamicRuleAlgorithmLabels; + this.dynamicRuleAlgorithmCombo = dynamicRuleAlgorithmCombo; + this.dynamicRuleAlgorithmField1 = dynamicRuleAlgorithmField1; + this.dynamicRuleAlgorithmField2 = dynamicRuleAlgorithmField2; + this.dynamicVariableList = dynamicVariableList; + this.dataTypeList = dataTypeList; + this.dropDownMap = dropDownMap; + this.editPolicy = editPolicy; + this.domain = domain; + this.highestVersion = highestVersion; + + } + + + //Constructor for Create Config Policies from API and Admin Console + //Constructor for Updating Config Policies from the API + public StdPAPPolicy(String configPolicyType, String policyName, String description, String ecompName, String configName, Map attributes, String configType, + String body, Boolean editPolicy, String domain, int highestVersion, String riskLevel, String riskType, String guard, String ttlDate) { + + this.configPolicyType = configPolicyType; + this.policyName = policyName; + this.policyDescription = description; + this.ecompName = ecompName; + this.configName = configName; + this.dyanamicFieldConfigAttributes = attributes; + this.configType = configType; + this.configBodyData = body; + this.editPolicy = editPolicy; + this.domain = domain; + this.highestVersion = highestVersion; + this.riskLevel = riskLevel; + this.riskType = riskType; + this.guard = guard; + this.ttlDate = ttlDate; + } + + //convenience constructor + public StdPAPPolicy (String configPolicyType, String policyName, String description, String ecompName, String configName, Map attributes, String body, String policyID, + String ruleID, String configType, Boolean editPolicy, String version, String domain, String riskLevel, String riskType, String guard, String ttlDate) { + this (configPolicyType, policyName, description, ecompName, configName, attributes, body, policyID, + ruleID, configType, editPolicy, version, domain, 1, riskLevel, riskType, guard, ttlDate); + } + + //Constructor for Updating Config Policies from Admin Console + public StdPAPPolicy (String configPolicyType, String policyName, String description, String ecompName, String configName, Map attributes, String body, String policyID, + String ruleID, String configType, Boolean editPolicy, String version, String domain, int highestVersion, String riskLevel, String riskType, String guard, String ttlDate) { + + this.configPolicyType = configPolicyType; + this.policyName = policyName; + this.policyDescription = description; + this.ecompName = ecompName; + this.configName = configName; + this.dyanamicFieldConfigAttributes = attributes; + this.configBodyData = body; + this.policyID = policyID; + this.ruleID = ruleID; + this.configType = configType; + this.editPolicy = editPolicy; + this.version = version; + this.domain = domain; + this.highestVersion = highestVersion; + this.riskLevel = riskLevel; + this.riskType = riskType; + this.guard = guard; + this.ttlDate = ttlDate; + } + + + //Constructor for Creating Config Firewall Policies + public StdPAPPolicy (String configPolicyType, String policyName, String description, String configName, + Boolean editPolicy, String domain, String jsonBody, Integer highestVersion, String riskLevel, String riskType, String guard, String ttlDate) { + + this.configPolicyType = configPolicyType; + this.policyName = policyName; + this.policyDescription = description; + this.configName = configName; + this.editPolicy = editPolicy; + this.domain = domain; + this.jsonBody = jsonBody; + this.highestVersion = highestVersion; + this.riskLevel = riskLevel; + this.riskType = riskType; + this.guard = guard; + this.ttlDate = ttlDate; + + } + + //Constructor for Creating Goc Policies + public StdPAPPolicy (String configPolicyType, String policyName, String description, String configName, + Boolean editPolicy, String domain, String jsonBody, Integer highestVersion, String eCompName, String riskLevel, String riskType, String guard, String ttlDate) { + + this.configPolicyType = configPolicyType; + this.policyName = policyName; + this.policyDescription = description; + this.configName = configName; + this.editPolicy = editPolicy; + this.domain = domain; + this.jsonBody = jsonBody; + this.highestVersion = highestVersion; + this.ecompName=eCompName; + this.riskLevel = riskLevel; + this.riskType = riskType; + this.guard = guard; + this.ttlDate = ttlDate; + } + + //Constructor for Creating BRMS Policies from the Admin Console + public StdPAPPolicy (String configPolicyType, String policyName, String description, + String configName, Boolean editPolicy, String domain, + Map dyanamicFieldConfigAttributes, Integer highestVersion, String eCompName, + String configBodyData, String riskLevel, String riskType, String guard, String ttlDate) { + + this.configPolicyType = configPolicyType; + this.policyName = policyName; + this.policyDescription = description; + this.configName = configName; + this.editPolicy = editPolicy; + this.domain = domain; + this.dyanamicFieldConfigAttributes = dyanamicFieldConfigAttributes; + this.highestVersion = highestVersion; + this.ecompName=eCompName; + this.configBodyData=configBodyData; + this.riskLevel = riskLevel; + this.riskType = riskType; + this.guard = guard; + this.ttlDate = ttlDate; + } + + //Constructor for Creating BRMS Param Policies from the Admin Console + public StdPAPPolicy (String configPolicyType, String policyName, String description, + String configName, Boolean editPolicy, String domain, + Map dyanamicFieldConfigAttributes, Integer highestVersion, String eCompName, + String configBodyData,Map drlRuleAndUIParams, String riskLevel, String riskType, String guard, String ttlDate) { + + this.configPolicyType = configPolicyType; + this.policyName = policyName; + this.policyDescription = description; + this.configName = configName; + this.editPolicy = editPolicy; + this.domain = domain; + this.dyanamicFieldConfigAttributes = dyanamicFieldConfigAttributes; + this.highestVersion = highestVersion; + this.ecompName=eCompName; + this.configBodyData=configBodyData; + this.drlRuleAndUIParams=drlRuleAndUIParams; + this.riskLevel = riskLevel; + this.riskType = riskType; + this.guard = guard; + this.ttlDate = ttlDate; + } + + //Constructor for Creating CloseLoop_Fault and Performance Metric Policies + public StdPAPPolicy (String configPolicyType, String policyName, String description, String ecompName, + String jsonBody, Boolean draft, String oldPolicyFileName, String serviceType, Boolean editPolicy, + String domain, Integer highestVersion, String riskLevel, String riskType, String guard, String ttlDate) { + + this.configPolicyType = configPolicyType; + this.policyName = policyName; + this.policyDescription = description; + this.ecompName = ecompName; + this.jsonBody = jsonBody; + this.draft = draft; + this.oldPolicyFileName = oldPolicyFileName; + this.serviceType = serviceType; + this.editPolicy = editPolicy; + this.domain = domain; + this.highestVersion = highestVersion; + this.riskLevel = riskLevel; + this.riskType = riskType; + this.guard = guard; + this.ttlDate = ttlDate; + } + + //Constructor for Updating Config Firewall Policies from the Admin Console + public StdPAPPolicy (String configPolicyType, String policyName, String description, String configName, Boolean editPolicy, String domain, String policyID, + String ruleID, String version, String jsonBody, Integer highestVersion, String riskLevel, String riskType, String guard, String ttlDate) { + + this.configPolicyType = configPolicyType; + this.policyName = policyName; + this.policyDescription = description; + this.configName = configName; + this.editPolicy = editPolicy; + this.domain = domain; + this.policyID = policyID; + this.ruleID = ruleID; + this.version = version; + this.jsonBody = jsonBody; + this.highestVersion = highestVersion; + this.riskLevel = riskLevel; + this.riskType = riskType; + this.guard = guard; + this.ttlDate = ttlDate; + } + + //Constructor for Micro Service Creating/Updating Policies from the Admin Console + public StdPAPPolicy(String configPolicyType, String policyName, String description, String ecompName, String configName, String serviceType, String uuid, + String msLocation, String jsonBody, String priority, String version, Boolean editPolicy, String domain, int highestVersion, String riskLevel, + String riskType, String guard, String ttlDate) { + + this.configPolicyType = configPolicyType; + this.policyName = policyName; + this.policyDescription = description; + this.ecompName = ecompName; + this.configName = configName; + this.serviceType = serviceType; + this.uuid = uuid; + this.msLocation = msLocation; + this.priority = priority; + this.version = version; + this.jsonBody = jsonBody; + this.editPolicy = editPolicy; + this.domain = domain; + this.highestVersion = highestVersion; + this.riskLevel = riskLevel; + this.riskType = riskType; + this.guard = guard; + this.ttlDate = ttlDate; + } + + //Constructor for Updating Goc Policies from the Admin Console + public StdPAPPolicy (String configPolicyType, String policyName, String description, + String configName, Boolean editPolicy, String domain, + String policyID, String ruleID, String version, + String jsonBody, Integer highestVersion, String eCompName,String riskLevel, String riskType, String guard, String ttlDate) { + + this.configPolicyType = configPolicyType; + this.policyName = policyName; + this.policyDescription = description; + this.configName = configName; + this.editPolicy = editPolicy; + this.domain = domain; + this.policyID = policyID; + this.ruleID = ruleID; + this.version = version; + this.jsonBody = jsonBody; + this.highestVersion = highestVersion; + this.ecompName=eCompName; + this.riskLevel = riskLevel; + this.riskType = riskType; + this.guard = guard; + this.ttlDate = ttlDate; + } + + //Constructor for Updating Brms Policies from the Admin Console + public StdPAPPolicy (String configPolicyType, String policyName, String description, + String configName, Boolean editPolicy, String domain, + String policyID, String ruleID, String version, + Map dyanamicFieldConfigAttributes, Integer highestVersion, String eCompName, + String configBodyData , String riskLevel, String riskType, String guard, String ttlDate + ) { + this.configPolicyType = configPolicyType; + this.policyName = policyName; + this.policyDescription = description; + this.configName = configName; + this.editPolicy = editPolicy; + this.domain = domain; + this.policyID = policyID; + this.ruleID = ruleID; + this.version = version; + this.dyanamicFieldConfigAttributes = dyanamicFieldConfigAttributes; + this.highestVersion = highestVersion; + this.ecompName=eCompName; + this.configBodyData=configBodyData; + this.riskLevel = riskLevel; + this.riskType = riskType; + this.guard = guard; + this.ttlDate = ttlDate; + } + + //Constructor for Updating Brms Param Policies from the Admin Console + public StdPAPPolicy (String configPolicyType, String policyName, String description, + String configName, Boolean editPolicy, String domain, + String policyID, String ruleID, String version, + Map dyanamicFieldConfigAttributes, Integer highestVersion, String eCompName, + Map drlRuleAndUIParams, String riskLevel, String riskType, String guard, String ttlDate + ) { + this.configPolicyType = configPolicyType; + this.policyName = policyName; + this.policyDescription = description; + this.configName = configName; + this.editPolicy = editPolicy; + this.domain = domain; + this.policyID = policyID; + this.ruleID = ruleID; + this.version = version; + this.dyanamicFieldConfigAttributes = dyanamicFieldConfigAttributes; + this.highestVersion = highestVersion; + this.ecompName=eCompName; + this.drlRuleAndUIParams=drlRuleAndUIParams; + this.riskLevel = riskLevel; + this.riskType = riskType; + this.guard = guard; + this.ttlDate = ttlDate; + } + + // Constructor for deleting policies from the API + public StdPAPPolicy(String policyName, String deleteCondition) { + this.policyName = policyName; + this.deleteCondition = deleteCondition; + } + + // Constructor for creating dictionary items from the API + public StdPAPPolicy(String dictionaryType, String dictionary, Map dictionaryFields) { + this.dictionaryType = dictionaryType; + this.dictionary = dictionary; + this.dictionaryFields = dictionaryFields; + } + + @Override + public String getPolicyName() { + return policyName; + } + + @Override + public String getPolicyDescription() { + return policyDescription; + } + + @Override + public String getEcompName() { + return ecompName; + } + + @Override + public String getConfigName() { + return configName; + } + + @Override + public Map getDynamicFieldConfigAttributes() { + return dyanamicFieldConfigAttributes; + } + + @Override + public String getConfigBodyData() { + return configBodyData; + } + + @Override + public String getPolicyID() { + return policyID; + } + + @Override + public String getRuleID() { + return ruleID; + } + + @Override + public String getConfigType() { + return configType; + } + + @Override + public Boolean isEditPolicy() { + return editPolicy; + } + + @Override + public Boolean isDraft() { + return draft; + } + + @Override + public String getVersion() { + return version; + } + + @Override + public String getDomainDir() { + return domain; + } + + @Override + public String getConfigPolicyType() { + return configPolicyType; + } + + @Override + public String getJsonBody() { + return jsonBody; + } + + @Override + public Integer getHighestVersion() { + return highestVersion; + } + + @Override + public URI getLocation() { + return location; + } + + @Override + public List getDynamicRuleAlgorithmLabels() { + return dynamicRuleAlgorithmLabels; + } + + @Override + public List getDynamicRuleAlgorithmCombo() { + return dynamicRuleAlgorithmCombo; + } + + @Override + public List getDynamicRuleAlgorithmField1() { + return dynamicRuleAlgorithmField1; + } + + @Override + public List getDynamicRuleAlgorithmField2() { + return dynamicRuleAlgorithmField2; + } + + @Override + public String getActionPerformer() { + return actionPerformer; + } + + @Override + public String getActionAttribute() { + return actionAttribute; + } + + @Override + public String getActionBody() { + return actionBody; + } + + @Override + public Map getDropDownMap() { + return dropDownMap; + } + + @Override + public String getActionDictHeader() { + return actionDictHeader; + } + + @Override + public String getActionDictType() { + return actionDictType; + } + + @Override + public String getActionDictUrl() { + return actionDictUrl; + } + + @Override + public String getActionDictMethod() { + return actionDictMethod; + } + + @Override + public Map getDynamicSettingsMap() { + return dynamicSettingsMap; + } + + @Override + public List getDynamicVariableList() { + return dynamicVariableList; + } + + @Override + public List getDataTypeList() { + return dataTypeList; + } + + @Override + public String getOldPolicyFileName() { + return oldPolicyFileName; + } + + @Override + public String getServiceType() { + return serviceType; + } + + @Override + public String getUuid() { + return uuid; + } + + @Override + public String getMsLocation() { + return msLocation; + } + + @Override + public String getPriority() { + return priority; + } + + @Override + public String getDeleteCondition() { + return deleteCondition; + } + + @Override + public String getDictionaryType() { + return dictionaryType; + } + + @Override + public String getDictionary() { + return dictionary; + } + + @Override + public String getTTLDate(){ + return ttlDate; + } + + @Override + public Map getDictionaryFields() { + return dictionaryFields; + } + + @Override + public String getRiskType() { + return riskType; + } + + @Override + public String getRiskLevel() { + return riskLevel; + } + + @Override + public String getGuard() { + return guard; + } + + @Override + public String toString() { + return "StdPAPPolicy [policyName=" + policyName + ", policyDescription=" + policyDescription + ", ecompName=" + + ecompName + ", configName=" + configName + ", dyanamicFieldConfigAttributes=" + dyanamicFieldConfigAttributes + ", configBodyData=" + configBodyData + + ", policyID=" + policyID + ", ruleID=" + ruleID + ", configType=" + configType + ", editPolicy=" + ", version=" + ", domain=" + domain + + ", configPolicyType=" + configPolicyType + ", jsonBody=" + jsonBody + ", highestVersion=" + highestVersion + ", location=" + location + + ",dynamicRuleAlgorithmLabels=" + dynamicRuleAlgorithmLabels + ",dynamicRuleAlgorithmCombo=" + dynamicRuleAlgorithmCombo + + ",dynamicRuleAlgorithmField1=" + dynamicRuleAlgorithmField1 + ",dynamicRuleAlgorithmField2=" + dynamicRuleAlgorithmField2 + + ",actionPerformer=" + actionPerformer + ",actionAttribute=" + actionAttribute + ",actionBody=" + actionBody + ",dropDownMap=" + dropDownMap + + ",actionDictHeader=" + actionDictHeader + ",actionDictType=" + actionDictType + ",actionDictUrl=" + actionDictUrl + + ",actionDictMethod=" + actionDictMethod + ",dynamicSettingsMap=" + dynamicSettingsMap + ",dynamicVariableList=" + dynamicVariableList + ",providerComboBox=" + providerComboBox + + ",dataTypeList=" + dataTypeList + ",draft=" + ",oldPolicyFileName=" + oldPolicyFileName + ",serviceType=" + serviceType + + ",uuid=" + uuid + ",msLocation=" + msLocation + ",priority=" + priority + ",deleteCondition=" + deleteCondition + ",dictionaryType=" + dictionaryType + + ",dictionary=" + dictionary + ",dictionaryFields=" + dictionaryFields + ",uuid=" + uuid + ",msLocation=" + msLocation + ",priority=" + + priority + ",deleteCondition=" + deleteCondition + ",riskType="+riskType + ",riskLevel="+riskLevel + ",guard="+ guard + ",ttlDate="+ ttlDate + "]"; + } + + // Methods needed for JSON Deserialization + public void setPolicyName(String policyName) { + this.policyName = policyName; + } + + public void setPolicyDescription(String policyDescription) { + this.policyDescription = policyDescription; + } + + public void setEcompName(String ecompName) { + this.ecompName = ecompName; + } + + public void setConfigName(String configName) { + this.configName = configName; + } + + public void setDyanamicFieldConfigAttributes( + Map dyanamicFieldConfigAttributes) { + this.dyanamicFieldConfigAttributes = dyanamicFieldConfigAttributes; + } + + public void setConfigBodyData(String configBodyData) { + this.configBodyData = configBodyData; + } + + public void setPolicyID(String policyID) { + this.policyID = policyID; + } + + public void setRuleID(String ruleID) { + this.ruleID = ruleID; + } + + public void setConfigType(String configType) { + this.configType = configType; + } + + public void setEditPolicy(Boolean editPolicy) { + this.editPolicy = editPolicy; + } + + public void setVersion(String version) { + this.version = version; + } + + public void setDomainDir(String domain) { + this.domain = domain; + } + + public void setConfigPolicyType(String configPolicyType) { + this.configPolicyType = configPolicyType; + } + + public void setJsonBody(String jsonBody) { + this.jsonBody = jsonBody; + } + + public void setHighestVersion(Integer highestVersion) { + this.highestVersion = highestVersion; + } + + public void setLocation (URI location) { + this.location = location; + } + + public void setDynamicRuleAlgorithmLabels( + List dynamicRuleAlgorithmLabels) { + this.dynamicRuleAlgorithmLabels = dynamicRuleAlgorithmLabels; + } + + public void setDynamicRuleAlgorithmCombo(List dynamicRuleAlgorithmCombo) { + this.dynamicRuleAlgorithmCombo = dynamicRuleAlgorithmCombo; + } + + public void setDynamicRuleAlgorithmField1( + List dynamicRuleAlgorithmField1) { + this.dynamicRuleAlgorithmField1 = dynamicRuleAlgorithmField1; + } + + public void setDynamicRuleAlgorithmField2( + List dynamicRuleAlgorithmField2) { + this.dynamicRuleAlgorithmField2 = dynamicRuleAlgorithmField2; + } + + public void setActionPerformer(String actionPerformer) { + this.actionPerformer = actionPerformer; + } + + public void setActionAttribute(String actionAttribute) { + this.actionAttribute = actionAttribute; + } + + public void setActionBody(String actionBody) { + this.actionBody = actionBody; + } + + public void setDropDownMap(Map dropDownMap) { + this.dropDownMap = dropDownMap; + } + + public void setActionDictHeader(String actionDictHeader) { + this.actionDictHeader = actionDictHeader; + } + + public void setActionDictType(String actionDictType) { + this.actionDictType = actionDictType; + } + + public void setActionDictUrl(String actionDictUrl) { + this.actionDictUrl = actionDictUrl; + } + + public void setActionDictMethod(String actionDictMethod) { + this.actionDictMethod = actionDictMethod; + } + + public void setDynamicSettingsMap(Map dynamicSettingsMap) { + this.dynamicSettingsMap = dynamicSettingsMap; + } + + public void setDynamicVariableList(List dynamicVariableList) { + this.dynamicVariableList = dynamicVariableList; + } + + public void setDataTypeList(List dataTypeList) { + this.dataTypeList = dataTypeList; + } + + public void setDraft(Boolean draft) { + this.draft = draft; + } + + public void setOldPolicyFileName(String oldPolicyFileName) { + this.oldPolicyFileName = oldPolicyFileName; + } + + public void setServiceType(String serviceType) { + this.serviceType = serviceType; + } + + + public Map getDrlRuleAndUIParams() { + return drlRuleAndUIParams; + } + + public void setDrlRuleAndUIParams(Map drlRuleAndUIParams) { + this.drlRuleAndUIParams = drlRuleAndUIParams; + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } + + public void setMsLocation(String msLocation) { + this.msLocation = msLocation; + } + + public void setPriority(String priority) { + this.priority = priority; + } + + public void setDeleteCondition(String deleteCondition) { + this.deleteCondition = deleteCondition; + } + + public void setDictionaryType(String dictionaryType) { + this.dictionaryType = dictionaryType; + } + + public void setDictionary(String dictionary) { + this.dictionary = dictionary; + } + + public void setDictionaryFields(Map dictionaryFields) { + this.dictionaryFields = dictionaryFields; + } + + public String getProviderComboBox() { + return providerComboBox; + } + + public void setProviderComboBox(String providerComboBox) { + this.providerComboBox = providerComboBox; + } + + public void setRiskType(String riskType){ + this.riskType = riskType; + } + + public void setRiskLevel(String riskLevel){ + this.riskLevel = riskLevel; + } + + public void setGuard(String guard){ + this.guard = guard; + } + + public void setTTLDate(String ttlDate){ + this.ttlDate = ttlDate; + } +} + diff --git a/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/std/pap/StdPDP.java b/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/std/pap/StdPDP.java new file mode 100644 index 000000000..b8fb59b60 --- /dev/null +++ b/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/std/pap/StdPDP.java @@ -0,0 +1,222 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-XACML + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.openecomp.policy.xacml.std.pap; + +import java.io.Serializable; +import java.util.Collections; +import java.util.HashSet; +import java.util.Properties; +import java.util.Set; + +import org.openecomp.policy.xacml.api.pap.EcompPDP; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; +import com.att.research.xacml.api.pap.PDPPIPConfig; +import com.att.research.xacml.api.pap.PDPPolicy; +import com.att.research.xacml.api.pap.PDPStatus; + +public class StdPDP extends StdPDPItemSetChangeNotifier implements EcompPDP, Comparable, Serializable { + private static final long serialVersionUID = 1L; + private static Logger logger = FlexLogger.getLogger(StdPDP.class); + + private String id; + + private String name; + + private String description; + + private Integer jmxport = 0; + + private PDPStatus status = new StdPDPStatus(); + + private Set policies = new HashSet(); + + private Set pipConfigs = new HashSet(); + + public StdPDP() { + + } + + public StdPDP(String id, Integer jmxport) { + this(id, null, null, jmxport); + } + + public StdPDP(String id, String name, Integer jmxport) { + this(id, name, null, jmxport); + } + + public StdPDP(String id, String name, String description, Integer jmxport) { + this.id = id; + this.name = name; + this.description = description; + if(jmxport != null){ + this.jmxport = jmxport; + } + } + + public StdPDP(String id, Properties properties) { + this(id, 0); + + this.initialize(properties); + } + + public void initialize(Properties properties) { + for (Object key : properties.keySet()) { + if (key.toString().startsWith(this.id + ".")) { + if (logger.isDebugEnabled()) { + logger.debug("Found: " + key); + } + if (key.toString().endsWith(".name")) { + this.name = properties.getProperty(key.toString()); + } else if (key.toString().endsWith(".description")) { + this.description = properties.getProperty(key.toString()); + }else if (key.toString().endsWith(".jmxport")) { + //todo fix this hackjob + if (properties.getProperty(key.toString()) != null && properties.getProperty(key.toString()).trim().length() > 0){ + logger.debug("initialize before: " + this.jmxport); + this.jmxport = Integer.valueOf( properties.getProperty(key.toString())); + logger.debug("initialize after: " + this.jmxport); + }else{ + this.jmxport = 0; + } + } + } + } + } + + @Override + public String getId() { + return this.id; + } + + public void setId(String id) { + this.id=id; + } + + @Override + public String getName() { + return this.name; + } + + @Override + public void setName(String name) { + this.name = name; + this.firePDPChanged(this); + } + + @Override + public String getDescription() { + return this.description; + } + + @Override + public void setDescription(String description) { + this.description = description; + this.firePDPChanged(this); + } + + @Override + public PDPStatus getStatus() { + return this.status; + } + + public void setStatus(PDPStatus status) { + this.status = status; + } + + @Override + public Set getPolicies() { + return Collections.unmodifiableSet(this.policies); + } + + public void setPolicies(Set policies) { + this.policies = policies; + } + + @Override + public Set getPipConfigs() { + return Collections.unmodifiableSet(this.pipConfigs); + } + + public void setPipConfigs(Set pipConfigs) { + this.pipConfigs = pipConfigs; + } + public void setJmxPort(Integer jmxport) { + this.jmxport = jmxport; + } + @Override + public Integer getJmxPort() { + return this.jmxport; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((id == null) ? 0 : id.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + StdPDP other = (StdPDP) obj; + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) + return false; + return true; + } + + @Override + public String toString() { + return "StdPDP [id=" + id + ", name=" + name + ", description=" + + description + ", jmxport=" + jmxport + ", status=" + status + ", policies=" + policies + + ", pipConfigs=" + pipConfigs + "]"; + } + + // + // Comparable interface + // + @Override + public int compareTo(StdPDP o) { + if (o == null) { + return -1; + } + if ( ! (o instanceof StdPDP)) { + return -1; + } + if (((StdPDP)o).name == null) { + return -1; + } + if (name == null) { + return 1; + } + return name.compareTo(((StdPDP)o).name); + } + +} diff --git a/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/std/pap/StdPDPGroup.java b/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/std/pap/StdPDPGroup.java new file mode 100644 index 000000000..ae4a43db6 --- /dev/null +++ b/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/std/pap/StdPDPGroup.java @@ -0,0 +1,1031 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-XACML + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.openecomp.policy.xacml.std.pap; + +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.eelf.PolicyLogger; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.Serializable; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Enumeration; +import java.util.HashSet; +import java.util.List; +import java.util.Properties; +import java.util.Set; +import java.util.TreeSet; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openecomp.policy.xacml.api.pap.EcompPDP; +import org.openecomp.policy.xacml.api.pap.EcompPDPGroup; +import org.openecomp.policy.xacml.std.pap.StdPDPItemSetChangeNotifier.StdItemSetChangeListener; + +import com.att.research.xacml.api.pap.PAPException; +import com.att.research.xacml.api.pap.PDP; +import com.att.research.xacml.api.pap.PDPGroup; +//import com.att.research.xacml.api.pap.PDPGroup; +import com.att.research.xacml.api.pap.PDPGroupStatus; +import com.att.research.xacml.api.pap.PDPGroupStatus.Status; +import com.att.research.xacml.api.pap.PDPPIPConfig; +import com.att.research.xacml.api.pap.PDPPolicy; +import com.att.research.xacml.util.XACMLProperties; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.google.common.base.Joiner; +import com.google.common.base.Splitter; +import com.google.common.io.ByteStreams; + +public class StdPDPGroup extends StdPDPItemSetChangeNotifier implements EcompPDPGroup, StdItemSetChangeListener, Comparable, Serializable { + private static final long serialVersionUID = 1L; + private static Log logger = LogFactory.getLog(StdPDPGroup.class); + + private String id; + + private boolean isDefault = false; + + private String name; + + private String description; + + private StdPDPGroupStatus status = new StdPDPGroupStatus(Status.UNKNOWN); + + private Set pdps = new HashSet(); + + private Set policies = new HashSet(); + + private Set pipConfigs = new HashSet(); + + @JsonIgnore + private Path directory; + + @JsonIgnore + private Integer jmxport; + + + public StdPDPGroup(String id, Path directory) { + this.id = id; + this.directory = directory; + } + + public StdPDPGroup(String id, boolean isDefault, Path directory) { + this(id, directory); + this.isDefault = isDefault; + } + + public StdPDPGroup(String id, boolean isDefault, String name, String description, Path directory) { + this(id, isDefault, directory); + this.name = name; + // force all policies to have a name + if (name == null) { + this.name = id; + } + this.description = description; + } + + public StdPDPGroup(String id, String name, String description, Path directory) { + this(id, false, name, description, directory); + this.resetStatus(); + } + + public StdPDPGroup(String id, boolean isDefault, Properties properties, Path directory) throws PAPException { + this(id, isDefault, directory); + this.initialize(properties, directory); + this.resetStatus(); + } + + private void initialize(Properties properties, Path directory) throws PAPException { + if (this.id == null || this.id.length() == 0) { + logger.warn("Cannot initialize with a null or zero length id"); + return; + } + // + // Pull the group's properties + // + for (Object key : properties.keySet()) { + if (key.toString().startsWith(this.id + ".")) { + if (key.toString().endsWith(".name")) { + this.name = properties.getProperty(key.toString()); + } else if (key.toString().endsWith(".description")) { + this.description = properties.getProperty(key.toString()); + } else if (key.toString().endsWith(".pdps")) { + String pdpList = properties.getProperty(key.toString()); + if (pdpList != null && pdpList.length() > 0) { + for (String id : Splitter.on(',').omitEmptyStrings().trimResults().split(pdpList)) { + StdPDP pdp = new StdPDP(id, properties); + pdp.addItemSetChangeListener(this); + this.pdps.add(pdp); + } + } + } + } + // force all policies to have a name + if (this.name == null) { + this.name = this.id; + } + } + // + // Validate our directory + // + if (Files.notExists(directory)) { + logger.warn("Group directory does NOT exist: " + directory.toString()); + try { + Files.createDirectory(directory); + this.status.addLoadWarning("Group directory does NOT exist"); + } catch (IOException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdPDPGroup", "Group directory does NOT exist"); + this.status.addLoadError("Group directory does NOT exist"); + this.status.setStatus(PDPGroupStatus.Status.LOAD_ERRORS); + } + } + // + // Parse policies + // + this.loadPolicies(Paths.get(directory.toString(), "xacml.policy.properties")); + // + // Parse pip config + // + this.loadPIPConfig(Paths.get(directory.toString(), "xacml.pip.properties")); + } + + public void loadPolicies(Path file) throws PAPException { + // + // Read the Groups Policies + // + Properties policyProperties = new Properties(); + if ( ! file.toFile().exists()) { + // need to create the properties file with default values + policyProperties.setProperty(XACMLProperties.PROP_ROOTPOLICIES, ""); + policyProperties.setProperty(XACMLProperties.PROP_REFERENCEDPOLICIES, ""); + // save properties to file + try (OutputStream os = Files.newOutputStream(file)) { + policyProperties.store(os, ""); + } catch (Exception e) { + throw new PAPException("Failed to create new default policy properties file '" + file +"'"); + } + } else { + // load previously existing file + try { + // + // Load the properties + // + try (InputStream is = Files.newInputStream(file)) { + policyProperties.load(is); + } + // + // Parse the policies + // + this.readPolicyProperties(directory, policyProperties); + } catch (IOException e) { + logger.warn("Failed to load group policy properties file: " + file, e); + this.status.addLoadError("Not policy properties defined"); + this.status.setStatus(Status.LOAD_ERRORS); + throw new PAPException("Failed to load group policy properties file: " + file); + } + } + } + + public void loadPIPConfig(Path file) throws PAPException { + // + // Read the Groups' PIP configuration + // + Properties pipProperties = new Properties(); + if ( ! file.toFile().exists()) { + // need to create the properties file with no values + // TODO: Adding Default PIP engine(s) while Loading initially. We don't want + // Programmer intervention with the PIP engines. + pipProperties = setPIPProperties(pipProperties); + // save properties to file + try { + try (OutputStream os = Files.newOutputStream(file)) { + pipProperties.store(os, ""); + } + } catch (Exception e) { + throw new PAPException("Failed to create new default pip properties file '" + file +"'"); + } + } else { + try { + // + // Load the properties + // + try (InputStream is = Files.newInputStream(file)) { + pipProperties.load(is); + } + // For all old PIP config's modify to the new PIP Configuration. + // If PIP is empty add the new values and save it. + if(pipProperties.get(XACMLProperties.PROP_PIP_ENGINES).toString().trim().equals("")){ + pipProperties = setPIPProperties(pipProperties); + try (OutputStream os = Files.newOutputStream(file)) { + pipProperties.store(os, ""); + } + } + // + // Parse the pips + // + this.readPIPProperties(directory, pipProperties); + } catch (IOException e) { + logger.warn("Failed to open group PIP Config properties file: " + file, e); + this.status.addLoadError("Not PIP config properties defined"); + this.status.setStatus(Status.LOAD_ERRORS); + throw new PAPException("Failed to load group policy properties file: " + file); + + } + } + } + + public void resetStatus() { +// // +// // If we are updating, don't allow reset +// // +// if (this.status.getStatus() == Status.UPDATING_CONFIGURATION) { +// logger.warn("We are updating, chill."); +// return; +// } +// // +// // Load errors take precedence +// // +// if (this.status.getStatus() == Status.LOAD_ERRORS) { +// logger.warn("We had load errors."); +// return; +// } + // + // Reset our status object + // + this.status.reset(); + // + // Determine our status + // + for (PDP pdp : this.pdps) { + switch (pdp.getStatus().getStatus()) { + case OUT_OF_SYNCH: + this.status.addOutOfSynchPDP(pdp); + break; + case LAST_UPDATE_FAILED: + this.status.addLastUpdateFailedPDP(pdp); + break; + case LOAD_ERRORS: + this.status.addFailedPDP(pdp); + break; + case UPDATING_CONFIGURATION: + this.status.addUpdatingPDP(pdp); + break; + case UP_TO_DATE: + this.status.addInSynchPDP(pdp); + break; + case UNKNOWN: + case CANNOT_CONNECT: + case NO_SUCH_HOST: + default: + this.status.addUnknownPDP(pdp); + break; + } + } + + // priority is worst-cast to best case + if (this.status.getUnknownPDPs().size() > 0) { + this.status.setStatus(Status.UNKNOWN); + } else if (this.status.getFailedPDPs().size() > 0 || this.status.getLastUpdateFailedPDPs().size() > 0) { + this.status.setStatus(Status.LOAD_ERRORS); + } else if (this.status.getOutOfSynchPDPs().size() > 0) { + this.status.setStatus(Status.OUT_OF_SYNCH); + } else if (this.status.getUpdatingPDPs().size() > 0) { + this.status.setStatus(Status.UPDATING_CONFIGURATION); + } else { + this.status.setStatus(Status.OK); + } + } + + @Override + public String getId() { + return this.id; + } + + public void setId(String id) { + this.id = id; + } + + @Override + public boolean isDefaultGroup() { + return this.isDefault; + } + + public void setDefaultGroup(boolean isDefault) { + this.isDefault = isDefault; + // + // Cannot fire this because 2 operations have + // to occur: 1) old default=false (don't want to fire) and + // then 2) new default=true (yes fire - but we'll have to do that + // elsewhere. + //this.firePDPGroupChanged(this); + } + + @Override + public String getName() { + return name; + } + + @Override + public void setName(String groupName) { + this.name = groupName; + this.firePDPGroupChanged(this); + } + + @Override + public String getDescription() { + return this.description; + } + + @Override + public void setDescription(String groupDescription) { + this.description = groupDescription; + this.firePDPGroupChanged(this); + } + + public Path getDirectory() { + return this.directory; + } + + public void setDirectory(Path groupDirectory) { + this.directory = groupDirectory; + // this is used only for transmission on the RESTful interface, so no need to fire group changed? + } + + @Override + public PDPGroupStatus getStatus() + { + return this.status; + } + + @Override + public Set getPdps() { + return Collections.unmodifiableSet(pdps); + } + + public void setEcompPdps(Set pdps) { + this.pdps = pdps; + } + + public Set getEcompPdps(){ + return Collections.unmodifiableSet(pdps); + } + + public boolean addPDP(EcompPDP pdp) { + return this.pdps.add(pdp); + } + + public boolean removePDP(PDP pdp) { + return this.pdps.remove(pdp); + } + + @Override + public Set getPolicies() { + return Collections.unmodifiableSet(this.policies); + } + + @Override + public PDPPolicy getPolicy(String id) { + for (PDPPolicy policy : this.policies) { + if (policy.getId().equals(id)) { + return policy; + } + } + return null; + } + + public Properties getPolicyProperties() + { + Properties properties = new Properties(){ + private static final long serialVersionUID = 1L; + // For Debugging it is helpful for the file to be in a sorted order, + // any by returning the keys in the natural Alpha order for strings we get close enough. + // TreeSet is sorted, and this just overrides the normal Properties method to get the keys. + @Override + public synchronized Enumeration keys() { + return Collections.enumeration(new TreeSet(super.keySet())); + } + };; + List roots = new ArrayList(); + List refs = new ArrayList(); + + for (PDPPolicy policy : this.policies) { + // for all policies need to tell PDP the "name", which is the base name for the file id + if (policy.getName() != null) { + properties.setProperty(policy.getId() + ".name", policy.getName()); + } + // put the policy on the correct list + if (policy.isRoot()) { + roots.add(policy.getId()); + } else { + refs.add(policy.getId()); + } + } + + properties.setProperty(XACMLProperties.PROP_ROOTPOLICIES, Joiner.on(',').join(roots)); + properties.setProperty(XACMLProperties.PROP_REFERENCEDPOLICIES, Joiner.on(',').join(refs)); + + return properties; + } + + public PDPPolicy publishPolicy(String id, String name, boolean isRoot, InputStream policy) throws PAPException { + // + // Does it exist already? + // + if (this.getPolicy(id) != null) { + throw new PAPException("Policy with id " + id + " already exists - unpublish it first."); + } + Path tempFile = null; + try { + // + // Copy the policy over + // + tempFile = Files.createFile(Paths.get(this.directory.toAbsolutePath().toString(), id)); + long num; + try (OutputStream os = Files.newOutputStream(tempFile)) { + num = ByteStreams.copy(policy, os); + } + logger.info("Copied " + num + " bytes for policy " + name); + + StdPDPPolicy tempRootPolicy = new StdPDPPolicy(id, isRoot, name, tempFile.toUri()); + if (tempRootPolicy.isValid() == false) { + try { + Files.delete(tempFile); + } catch(Exception ee) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Policy was invalid, could NOT delete it.", ee); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, ee, "StdPDPGroup", "Policy was invalid, could NOT delete it."); + } + throw new PAPException("Policy is invalid"); + } + // + // Add it in + // + this.policies.add(tempRootPolicy); + // + // We are changed + // + this.firePDPGroupChanged(this); + // + // Return our new object. + // + return tempRootPolicy; + } catch (IOException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Failed to publishPolicy: ", e); + PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "StdPDPGroup", "Failed to publishPolicy"); + } + return null; + } + + /** + * Copy one policy file into the Group's directory but do not change the configuration. + * This is one part of a multi-step process of publishing policies. + * There may be multiple changes in the group (adding multiple policies, deleting policies, changine root<->referenced) + * that must be done all at once, so we just copy the file in preparation for a later "update whole group" operation. + * + * @param id + * @param name + * @param isRoot + * @param policy + * @return + * @throws PAPException + */ + public void copyPolicyToFile(String id, InputStream policy) throws PAPException { + try { + // + // Copy the policy over + // + long num; + Path policyFilePath = Paths.get(this.directory.toAbsolutePath().toString(), id); + + // + // THERE IS A WEIRD PROBLEM ON WINDOWS... + // The file is already "in use" when we try to access it. + // Looking at the file externally while this is halted here does not show the file in use, + // so there is no indication what is causing the problem. + // + // As a way to by-pass the issue, I simply check if the input and the existing file are identical + // and generate an exception if they are not. + // + + + +// if (Files.exists(policyFilePath)) { +// // compare the +// String incomingPolicyString = null; +// try (ByteArrayOutputStream os = new ByteArrayOutputStream()) { +// num = ByteStreams.copy(policy, os); +// incomingPolicyString = new String(os.toByteArray(), "UTF-8"); +// } +// String existingPolicyString = null; +// try { +// byte[] bytes = Files.readAllBytes(policyFilePath); +// existingPolicyString = new String(bytes, "UTF-8"); +// } catch (Exception e) { +// //TODO:EELF Cleanup - Remove logger +// logger.error("Unable to read existing file '" + policyFilePath + "': " + e, e); +// PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "StdPDPGroup", "Unable to read existing policy file"); +// throw new PAPException("Unable to read policy file for comparison: " + e); +// } +// if (incomingPolicyString.equals(existingPolicyString)) { +// throw new PAPException("Policy '" + policyFilePath + "' does not match existing policy on server"); +// } +// // input is same as existing file +// return; +// } + + + Path policyFile; + if (Files.exists(policyFilePath)) { + policyFile = policyFilePath; + } else { + policyFile = Files.createFile(policyFilePath); + } + + try (OutputStream os = Files.newOutputStream(policyFile)) { + num = ByteStreams.copy(policy, os); + } + + logger.info("Copied " + num + " bytes for policy " + name); + + for (PDPPolicy p : policies) { + if (p.getId().equals(id)) { + // we just re-copied/refreshed/updated the policy file for a policy that already exists in this group + logger.info("Policy '" + id + "' already exists in group '" + getId() + "'"); + return; + } + } + + // policy is new to this group + StdPDPPolicy tempRootPolicy = new StdPDPPolicy(id, true, name, policyFile.toUri()); + if (tempRootPolicy.isValid() == false) { + try { + Files.delete(policyFile); + } catch(Exception ee) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Policy was invalid, could NOT delete it.", ee); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, ee, "StdPDPGroup", "Policy was invalid, could NOT delete it."); + } + throw new PAPException("Policy is invalid"); + } + // + // Add it in + // + this.policies.add(tempRootPolicy); + // + // We are changed + // + this.firePDPGroupChanged(this); + + + + + } catch (IOException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Failed to copyPolicyToFile: ", e); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdPDPGroup", "Failed to copyPolicyToFile"); + throw new PAPException("Failed to copy policy to file: " + e); + } + return; + } + + public boolean removePolicyFromGroup(PDPPolicy policy) { + StdPDPPolicy currentPolicy = (StdPDPPolicy) this.getPolicy(policy.getId()); + if (currentPolicy == null) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Policy " + policy.getId() + " does not exist."); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + "Policy " + policy.getId() + " does not exist."); + return false; + } + try { + // + // Remove it from our list + // + this.policies.remove(currentPolicy); + // + // We are changed + // + this.firePDPGroupChanged(this); + return true; + } catch (Exception e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Failed to delete policy " + policy); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdPDPGroup", "Failed to delete policy"); + } + return false; + } + + public boolean removePolicy(PDPPolicy policy) { + StdPDPPolicy currentPolicy = (StdPDPPolicy) this.getPolicy(policy.getId()); + if (currentPolicy == null) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Policy " + policy.getId() + " does not exist."); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + "Policy " + policy.getId() + " does not exist."); + return false; + } + try { + // + // Delete it on disk + // + Files.delete(Paths.get(currentPolicy.getLocation())); + // + // Remove it from our list + // + this.policies.remove(currentPolicy); + // + // We are changed + // + this.firePDPGroupChanged(this); + return true; + } catch (Exception e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Failed to delete policy " + policy); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdPDPGroup", "Failed to delete policy " + policy); + } + return false; + } + + @Override + public Set getPipConfigs() { + return Collections.unmodifiableSet(this.pipConfigs); + } + + @Override + public PDPPIPConfig getPipConfig(String id) { + for (PDPPIPConfig config : this.pipConfigs) { + if (config.getId().equals(id)) { + return config; + } + } + return null; + } + + public void setPipConfigs(Set pipConfigs) { + this.pipConfigs = pipConfigs; + this.firePDPGroupChanged(this); + } + + public void removeAllPIPConfigs() { + this.pipConfigs.clear(); + this.firePDPGroupChanged(this); + } + + public Properties getPipConfigProperties() { + Properties properties = new Properties(); + List configs = new ArrayList(); + + for (PDPPIPConfig config : this.pipConfigs) { + configs.add(config.getId()); + properties.putAll(config.getConfiguration()); + } + + properties.setProperty(XACMLProperties.PROP_PIP_ENGINES, Joiner.on(',').join(configs)); + + return properties; + } + + @Override + public void repair() { + // + // Reset the status object + // + this.status.reset(); + // + // Validate our directory + // + boolean fire = false; + if (Files.notExists(directory)) { + logger.warn("Group directory does NOT exist: " + directory.toString()); + try { + Files.createDirectory(directory); + fire = true; + this.status.addLoadWarning("Created missing group directory"); + } catch (IOException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdPDPGroup", "Failed to create missing Group directory."); + this.status.addLoadError("Failed to create missing Group directory."); + this.status.setStatus(PDPGroupStatus.Status.LOAD_ERRORS); + } + } + // + // Validate our PIP config file + // + Path pipPropertiesFile = Paths.get(directory.toString(), "xacml.pip.properties"); + if (Files.notExists(pipPropertiesFile)) { + try { + Files.createFile(pipPropertiesFile); + fire = true; + this.status.addLoadWarning("Created missing PIP properties file"); + } catch (IOException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdPDPGroup", "Failed to create missing PIP properties file"); + this.status.addLoadError("Failed to create missing PIP properties file"); + this.status.setStatus(PDPGroupStatus.Status.LOAD_ERRORS); + } + } + // + // Valid our policy properties file + // + Path policyPropertiesFile = Paths.get(directory.toString(), "xacml.policy.properties"); + if (Files.notExists(policyPropertiesFile)) { + try { + Files.createFile(policyPropertiesFile); + fire = true; + this.status.addLoadWarning("Created missing Policy properties file"); + } catch (IOException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdPDPGroup", "Failed to create missing Policy properties file"); + this.status.addLoadError("Failed to create missing Policy properties file"); + this.status.setStatus(PDPGroupStatus.Status.LOAD_ERRORS); + } + } + this.resetStatus(); + if (fire) { + this.fireChanged(); + } + } + + private void readPolicyProperties(Path directory, Properties properties) { + // + // There are 2 property values that hold policies, root and referenced + // + String[] lists = new String[2]; + lists[0] = properties.getProperty(XACMLProperties.PROP_ROOTPOLICIES); + lists[1] = properties.getProperty(XACMLProperties.PROP_REFERENCEDPOLICIES); + // + // Iterate each policy list + // + boolean isRoot = true; + for (String list : lists) { + // + // Was there actually a property? + // + if (list == null || list.length() == 0) { + isRoot = false; + continue; + } + // + // Parse it out + // + Iterable policyList = Splitter.on(',').trimResults().omitEmptyStrings().split(list); + // + // Was there actually a list + // + if (policyList == null) { + isRoot = false; + continue; + } + for (String id : policyList) { + // + // Construct the policy filename + // + Path policyPath = Paths.get(directory.toString(), id ); + // + // Create the Policy Object + // + StdPDPPolicy policy; + try { + policy = new StdPDPPolicy(id, isRoot, policyPath.toUri(), properties); + } catch (IOException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Failed to create policy object", e); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdPDPGroup", "Failed to create policy object"); + policy = null; + } + // + // Is it valid? + // + if (policy != null && policy.isValid()) { + this.policies.add(policy); + this.status.addLoadedPolicy(policy); + } else { + this.status.addFailedPolicy(policy); + this.status.setStatus(Status.LOAD_ERRORS); + } + // force all policies to have a name + if (policy.getName() == null) { + policy.setName(policy.getId()); + } + } + isRoot = false; + } + } + + private void readPIPProperties(Path directory, Properties properties) { + String list = properties.getProperty(XACMLProperties.PROP_PIP_ENGINES); + if (list == null || list.length() == 0) { + return; + } + for (String id : list.split("[,]")) { + StdPDPPIPConfig config = new StdPDPPIPConfig(id, properties); + if (config.isConfigured()) { + this.pipConfigs.add(config); + this.status.addLoadedPipConfig(config); + } else { + this.status.addFailedPipConfig(config); + this.status.setStatus(Status.LOAD_ERRORS); + } + } + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((id == null) ? 0 : id.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + StdPDPGroup other = (StdPDPGroup) obj; + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) + return false; + return true; + } + + @Override + public String toString() { + return "StdPDPGroup [id=" + id + ", isDefault=" + isDefault + ", name=" + + name + ", description=" + description + ", status=" + status + + ", pdps=" + pdps + ", policies=" + policies + ", pipConfigs=" + + pipConfigs + ", directory=" + directory + "]"; + } + + @Override + public void changed() { + + // save the (changed) properties + try { + saveGroupConfiguration(); + } catch (PAPException | IOException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Unable to save group configuration change"); + PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "StdPDPGroup", "Unable to save group configuration change"); + // don't notify other things of change if we cannot save it??? + return; + } + + this.firePDPGroupChanged(this); + + } + + @Override + public void groupChanged(EcompPDPGroup group) { + this.changed(); + } + + @Override + public void pdpChanged(EcompPDP pdp) { + // + // If one of the group's PDP's changed, then the group changed + // + // TODO Really? + // + this.changed(); + } + + + // + // Methods needed for JSON deserialization + // + public StdPDPGroup() { + + } + + public StdPDPGroup(EcompPDPGroup group) { + this.id = group.getId(); + this.name = group.getName(); + this.description = group.getDescription(); + this.isDefault = group.isDefaultGroup(); + this.pdps = group.getEcompPdps(); + this.policies = group.getPolicies(); + this.pipConfigs = group.getPipConfigs(); + } + + public boolean isDefault() { + return isDefault; + } + public void setDefault(boolean isDefault) { + this.isDefault = isDefault; + } + public void setStatus(PDPGroupStatus status) { + this.status = new StdPDPGroupStatus(status); + } + public void setPolicies(Set policies) { + this.policies = policies; + } + + + + public void saveGroupConfiguration() throws PAPException, IOException { + + // First save the Policy properties + + // save the lists of policies + Properties policyProperties = this.getPolicyProperties(); + + // save info about each policy + for (PDPPolicy policy : this.policies){ + policyProperties.put(policy.getId() + ".name", policy.getName()); + } + + // + // Now we can save the file + // + Path file = Paths.get(this.directory.toString(), "xacml.policy.properties"); + try (OutputStream os = Files.newOutputStream(file)) { + policyProperties.store(os, ""); + } catch (Exception e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Group Policies Config save failed: " + e, e); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "STdPDPGroup", "Group Policies Config save failed"); + throw new PAPException("Failed to save policy properties file '" + file +"'"); + } + + + // Now save the PIP Config properties + Properties pipProperties = this.getPipConfigProperties(); + + // + // Now we can save the file + // + file = Paths.get(this.directory.toString(), "xacml.pip.properties"); + try (OutputStream os = Files.newOutputStream(file)) { + pipProperties.store(os, ""); + } catch (Exception e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Group PIP Config save failed: " + e, e); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdPDPGroup", "Group PIP Config save failed"); + throw new PAPException("Failed to save pip properties file '" + file +"'"); + } + } + + // + // Comparable Interface + // + @Override + public int compareTo(Object arg0) { + if (arg0 == null) { + return -1; + } + if ( ! (arg0 instanceof StdPDPGroup)) { + return -1; + } + if (((StdPDPGroup)arg0).name == null) { + return -1; + } + if (name == null) { + return 1; + } + + return name.compareTo(((StdPDPGroup)arg0).name); + } + + // TODO: Adding Default PIP engine(s) while Loading initially. We don't want + // Programmer intervention with the PIP engines. + private Properties setPIPProperties(Properties props){ + props.setProperty("AAF.name", "AAFEngine"); + props.setProperty("AAF.description", "AAFEngine to communicate with AAF to take decisions"); + props.setProperty("AAF.classname","org.openecomp.policy.xacml.std.pip.engines.aaf.AAFEngine"); + props.setProperty(XACMLProperties.PROP_PIP_ENGINES, "AAF"); + return props; + } + + +} diff --git a/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/std/pap/StdPDPGroupStatus.java b/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/std/pap/StdPDPGroupStatus.java new file mode 100644 index 000000000..dcb1f8fe0 --- /dev/null +++ b/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/std/pap/StdPDPGroupStatus.java @@ -0,0 +1,405 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-XACML + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.openecomp.policy.xacml.std.pap; + +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +import com.att.research.xacml.api.pap.PDP; +import com.att.research.xacml.api.pap.PDPGroupStatus; +import com.att.research.xacml.api.pap.PDPPIPConfig; +import com.att.research.xacml.api.pap.PDPPolicy; +import com.fasterxml.jackson.annotation.JsonIgnore; + +public class StdPDPGroupStatus implements PDPGroupStatus { + + private Status status = Status.UNKNOWN; + + private Set loadErrors = new HashSet(); + + private Set loadWarnings = new HashSet(); + + private Set loadedPolicies = new HashSet(); + + private Set failedPolicies = new HashSet(); + + private Set loadedPIPConfigs = new HashSet(); + + private Set failedPIPConfigs = new HashSet(); + + private Set inSynchPDPs = new HashSet(); + + private Set outOfSynchPDPs = new HashSet(); + + private Set failedPDPs = new HashSet(); + + private Set updatingPDPs = new HashSet(); + + private Set lastUpdateFailedPDPs = new HashSet(); + + private Set unknownPDPs = new HashSet(); + + + // Constructor needed for JSON deserialization + public StdPDPGroupStatus() { + + } + + public StdPDPGroupStatus(Status status) { + this.status = status; + } + + public StdPDPGroupStatus(PDPGroupStatus stat) { + this.status = stat.getStatus(); + this.failedPDPs.clear(); this.failedPDPs.addAll(stat.getFailedPDPs()); + this.failedPIPConfigs.clear(); this.failedPIPConfigs.addAll(stat.getFailedPipConfigs()); + this.failedPolicies.clear(); this.failedPolicies.addAll(stat.getFailedPolicies()); + this.inSynchPDPs.clear(); this.inSynchPDPs.addAll(stat.getInSynchPDPs()); + this.lastUpdateFailedPDPs.clear(); this.lastUpdateFailedPDPs.addAll(stat.getLastUpdateFailedPDPs()); + this.loadedPIPConfigs.clear(); this.loadedPIPConfigs.addAll(stat.getLoadedPipConfigs()); + this.loadedPolicies.clear(); this.loadedPolicies.addAll(stat.getLoadedPolicies()); + this.loadErrors.clear(); this.loadErrors.addAll(stat.getLoadErrors()); + this.loadWarnings.clear(); this.loadWarnings.addAll(stat.getLoadWarnings()); + this.outOfSynchPDPs.clear(); this.outOfSynchPDPs.addAll(stat.getOutOfSynchPDPs()); + this.unknownPDPs.clear(); this.unknownPDPs.addAll(stat.getUpdatingPDPs()); + this.updatingPDPs.clear(); this.updatingPDPs.addAll(stat.getUpdatingPDPs()); + } + + public Set getLoadedPIPConfigs() { + return loadedPIPConfigs; + } + public void setLoadedPIPConfigs(Set loadedPIPConfigs) { + this.loadedPIPConfigs = loadedPIPConfigs; + } + public Set getFailedPIPConfigs() { + return failedPIPConfigs; + } + public void setFailedPIPConfigs(Set failedPIPConfigs) { + this.failedPIPConfigs = failedPIPConfigs; + } + public Set getUnknownPDPs() { + return unknownPDPs; + } + public void setUnknownPDPs(Set unknownPDPs) { + this.unknownPDPs = unknownPDPs; + } + public void setLoadErrors(Set loadErrors) { + this.loadErrors = loadErrors; + } + public void setLoadWarnings(Set loadWarnings) { + this.loadWarnings = loadWarnings; + } + public void setLoadedPolicies(Set loadedPolicies) { + this.loadedPolicies = loadedPolicies; + } + public void setFailedPolicies(Set failedPolicies) { + this.failedPolicies = failedPolicies; + } + public void setInSynchPDPs(Set inSynchPDPs) { + this.inSynchPDPs = inSynchPDPs; + } + public void setOutOfSynchPDPs(Set outOfSynchPDPs) { + this.outOfSynchPDPs = outOfSynchPDPs; + } + public void setFailedPDPs(Set failedPDPs) { + this.failedPDPs = failedPDPs; + } + public void setUpdatingPDPs(Set updatingPDPs) { + this.updatingPDPs = updatingPDPs; + } + public void setLastUpdateFailedPDPs(Set lastUpdateFailedPDPs) { + this.lastUpdateFailedPDPs = lastUpdateFailedPDPs; + } + + + @Override + public Status getStatus() { + return status; + } + + public void setStatus(Status status) { + this.status = status; + } + + @Override + public Set getLoadErrors() { + return Collections.unmodifiableSet(this.loadErrors); + } + + public void addLoadError(String error) { + this.loadErrors.add(error); + } + + @Override + public Set getLoadWarnings() { + return Collections.unmodifiableSet(this.loadWarnings); + } + + public void addLoadWarning(String warning) { + this.loadWarnings.add(warning); + } + + @Override + public Set getLoadedPolicies() { + return Collections.unmodifiableSet(this.loadedPolicies); + } + + public void addLoadedPolicy(PDPPolicy policy) { + this.loadedPolicies.add(policy); + } + + @Override + public Set getFailedPolicies() { + return Collections.unmodifiableSet(this.failedPolicies); + } + + public void addFailedPolicy(PDPPolicy policy) { + this.failedPolicies.add(policy); + } + + @Override + public boolean policiesOK() { + if (this.failedPolicies.size() > 0) { + return false; + } + return true; + } + + @Override + public Set getLoadedPipConfigs() { + return Collections.unmodifiableSet(this.loadedPIPConfigs); + } + + public void addLoadedPipConfig(PDPPIPConfig config) { + this.loadedPIPConfigs.add(config); + } + + @Override + public Set getFailedPipConfigs() { + return Collections.unmodifiableSet(this.failedPIPConfigs); + } + + public void addFailedPipConfig(PDPPIPConfig config) { + this.failedPIPConfigs.add(config); + } + + @Override + public boolean pipConfigOK() { + if (this.failedPIPConfigs.size() > 0) { + return false; + } + return true; + } + + @Override + public Set getInSynchPDPs() { + return Collections.unmodifiableSet(this.inSynchPDPs); + } + + public void addInSynchPDP(PDP pdp) { + this.inSynchPDPs.add(pdp); + } + + @Override + public Set getOutOfSynchPDPs() { + return Collections.unmodifiableSet(this.outOfSynchPDPs); + } + + public void addOutOfSynchPDP(PDP pdp) { + this.outOfSynchPDPs.add(pdp); + } + + @Override + public Set getFailedPDPs() { + return Collections.unmodifiableSet(this.failedPDPs); + } + + public void addFailedPDP(PDP pdp) { + this.failedPDPs.add(pdp); + } + + @Override + public Set getUpdatingPDPs() { + return Collections.unmodifiableSet(this.updatingPDPs); + } + + public void addUpdatingPDP(PDP pdp) { + this.updatingPDPs.add(pdp); + } + + @Override + public Set getLastUpdateFailedPDPs() { + return Collections.unmodifiableSet(this.lastUpdateFailedPDPs); + } + + public void addLastUpdateFailedPDP(PDP pdp) { + this.lastUpdateFailedPDPs.add(pdp); + } + + @Override + @JsonIgnore + public Set getUnknownStatusPDPs() { + return Collections.unmodifiableSet(this.unknownPDPs); + } + + public void addUnknownPDP(PDP pdp) { + this.unknownPDPs.add(pdp); + } + + @Override + public boolean pdpsOK() { + if (this.outOfSynchPDPs.size() > 0) { + return false; + } + if (this.failedPDPs.size() > 0) { + return false; + } + if (this.lastUpdateFailedPDPs.size() > 0) { + return false; + } + if (this.unknownPDPs.size() > 0) { + return false; + } + return true; + } + + @Override + @JsonIgnore + public boolean isGroupOk() { + if (this.policiesOK() == false) { + return false; + } + if (this.pipConfigOK() == false) { + return false; + } + if (this.pdpsOK() == false) { + return false; + } + if (this.loadErrors.isEmpty() == false) { + return false; + } + return (this.status == Status.OK); + } + + public void reset() { + this.status = Status.OK; + + this.loadErrors.clear(); + this.loadWarnings.clear(); + this.loadedPolicies.clear(); + this.failedPolicies.clear(); + this.loadedPIPConfigs.clear(); + this.failedPIPConfigs.clear(); + this.inSynchPDPs.clear(); + this.outOfSynchPDPs.clear(); + this.failedPDPs.clear(); + this.updatingPDPs.clear(); + this.lastUpdateFailedPDPs.clear(); + this.unknownPDPs.clear(); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + + (failedPDPs.hashCode()); + result = prime + * result + + (failedPIPConfigs.hashCode()); + result = prime * result + + (failedPolicies.hashCode()); + result = prime * result + + (inSynchPDPs.hashCode()); + result = prime + * result + + (lastUpdateFailedPDPs.hashCode()); + result = prime * result + + (loadErrors.hashCode()); + result = prime * result + + (loadWarnings.hashCode()); + result = prime + * result + + (loadedPIPConfigs.hashCode()); + result = prime * result + + (loadedPolicies.hashCode()); + result = prime * result + + (outOfSynchPDPs.hashCode()); + result = prime * result + (status.hashCode()); + result = prime * result + + (unknownPDPs.hashCode()); + result = prime * result + + (updatingPDPs.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + StdPDPGroupStatus other = (StdPDPGroupStatus) obj; + if (!failedPDPs.equals(other.failedPDPs)) + return false; + if (!failedPIPConfigs.equals(other.failedPIPConfigs)) + return false; + if (!failedPolicies.equals(other.failedPolicies)) + return false; + if (!inSynchPDPs.equals(other.inSynchPDPs)) + return false; + if (!lastUpdateFailedPDPs.equals(other.lastUpdateFailedPDPs)) + return false; + if (!loadErrors.equals(other.loadErrors)) + return false; + if (!loadWarnings.equals(other.loadWarnings)) + return false; + if (!loadedPIPConfigs.equals(other.loadedPIPConfigs)) + return false; + if (!loadedPolicies.equals(other.loadedPolicies)) + return false; + if (!outOfSynchPDPs.equals(other.outOfSynchPDPs)) + return false; + if (status != other.status) + return false; + if (!unknownPDPs.equals(other.unknownPDPs)) + return false; + if (!updatingPDPs.equals(other.updatingPDPs)) + return false; + return true; + } + + @Override + public String toString() { + return "StdPDPGroupStatus [status=" + status + ", loadErrors=" + + loadErrors + ", loadWarnings=" + loadWarnings + + ", loadedPolicies=" + loadedPolicies + ", failedPolicies=" + + failedPolicies + ", loadedPIPConfigs=" + loadedPIPConfigs + + ", failedPIPConfigs=" + failedPIPConfigs + ", inSynchPDPs=" + + inSynchPDPs + ", outOfSynchPDPs=" + outOfSynchPDPs + + ", failedPDPs=" + failedPDPs + ", updatingPDPs=" + + updatingPDPs + ", lastUpdateFailedPDPs=" + + lastUpdateFailedPDPs + ", unknownPDPs=" + unknownPDPs + "]"; + } + +} diff --git a/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/std/pap/StdPDPItemSetChangeNotifier.java b/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/std/pap/StdPDPItemSetChangeNotifier.java new file mode 100644 index 000000000..38f8a5800 --- /dev/null +++ b/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/std/pap/StdPDPItemSetChangeNotifier.java @@ -0,0 +1,84 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-XACML + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.openecomp.policy.xacml.std.pap; + +import java.util.Collection; +import java.util.LinkedList; + +import org.openecomp.policy.xacml.api.pap.EcompPDP; +import org.openecomp.policy.xacml.api.pap.EcompPDPGroup; + +import com.att.research.xacml.api.pap.PDP; +import com.att.research.xacml.api.pap.PDPGroup; + +public class StdPDPItemSetChangeNotifier { + + private Collection listeners = null; + + public interface StdItemSetChangeListener { + + public void changed(); + + public void groupChanged(EcompPDPGroup group); + + public void pdpChanged(EcompPDP pdp); + + } + + public void addItemSetChangeListener(StdItemSetChangeListener listener) { + if (this.listeners == null) { + this.listeners = new LinkedList(); + } + this.listeners.add(listener); + } + + public void removeItemSetChangeListener(StdItemSetChangeListener listener) { + if (this.listeners != null) { + this.listeners.remove(listener); + } + } + + public void fireChanged() { + if (this.listeners == null) { + return; + } + for (StdItemSetChangeListener l : this.listeners) { + l.changed(); + } + } + + public void firePDPGroupChanged(EcompPDPGroup group) { + if (this.listeners == null) { + return; + } + for (StdItemSetChangeListener l : this.listeners) { + l.groupChanged(group); + } + } + + public void firePDPChanged(EcompPDP pdp) { + if (this.listeners == null) { + return; + } + for (StdItemSetChangeListener l : this.listeners) { + l.pdpChanged(pdp); + } + } +} diff --git a/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/std/pap/StdPDPPIPConfig.java b/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/std/pap/StdPDPPIPConfig.java new file mode 100644 index 000000000..814dbe3af --- /dev/null +++ b/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/std/pap/StdPDPPIPConfig.java @@ -0,0 +1,217 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-XACML + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.openecomp.policy.xacml.std.pap; + +import java.io.Serializable; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; + +import com.att.research.xacml.api.pap.PDPPIPConfig; +import com.fasterxml.jackson.annotation.JsonIgnore; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +public class StdPDPPIPConfig implements PDPPIPConfig, Serializable { + private static final long serialVersionUID = 1L; + private static Logger logger = FlexLogger.getLogger(StdPDPPIPConfig.class); + + private String id; + + private String name; + + private String description; + + private String classname; + + private Map config = new HashMap(); + + public StdPDPPIPConfig() { + + } + + public StdPDPPIPConfig(String id) { + this.id = id; + } + + public StdPDPPIPConfig(String id, String name, String description) { + this(id); + this.name = name; + this.description = description; + } + + public StdPDPPIPConfig(String id, Properties properties) { + this(id); + if ( ! this.initialize(properties) ) { + throw new IllegalArgumentException("PIP Engine '" + id + "' has no classname property in config"); + } + } + + public boolean initialize(Properties properties) { + boolean classnameSeen = false; + for (Object key : properties.keySet()) { + if (key.toString().startsWith(this.id + ".")) { + if (logger.isDebugEnabled()) { + logger.debug("Found: " + key); + } + if (key.toString().equals(this.id + ".name")) { + this.name = properties.getProperty(key.toString()); + } else if (key.toString().equals(this.id + ".description")) { + this.description = properties.getProperty(key.toString()); + } else if (key.toString().equals(this.id + ".classname")) { + this.classname = properties.getProperty(key.toString()); + classnameSeen = true; + } + // all properties, including the special ones located above, are included in the properties list + this.config.put(key.toString(), properties.getProperty(key.toString())); + } + } + return classnameSeen; + } + + @Override + public String getId() { + return this.id; + } + + public void setId(String id) { + this.id = id; + } + + @Override + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public String getDescription() { + return this.description; + } + + public void setDescription(String description) { + this.description = description; + } + + @Override + public String getClassname() { + return classname; + } + + public void setClassname(String classname) { + this.classname = classname; + } + + @Override + @JsonIgnore + public Map getConfiguration() { + return Collections.unmodifiableMap(this.config); + } + + public void setValues(Map config) { + this.config = config; + } + + @Override + @JsonIgnore + public boolean isConfigured() { + // + // TODO + // Also include this in the JSON I/O if it is a data field rather than calculated + // + return true; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + + ((classname == null) ? 0 : classname.hashCode()); + result = prime * result + ((config == null) ? 0 : config.hashCode()); + result = prime * result + + ((description == null) ? 0 : description.hashCode()); + result = prime * result + ((id == null) ? 0 : id.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + StdPDPPIPConfig other = (StdPDPPIPConfig) obj; + if (classname == null) { + if (other.classname != null) + return false; + } else if (!classname.equals(other.classname)) + return false; + if (config == null) { + if (other.config != null) + return false; + } else if (!config.equals(other.config)) + return false; + if (description == null) { + if (other.description != null) + return false; + } else if (!description.equals(other.description)) + return false; + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) + return false; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + return true; + } + + @Override + public String toString() { + return "StdPDPPIPConfig [id=" + id + ", name=" + name + + ", description=" + description + ", classname=" + classname + + ", config=" + config + "]"; + } + + + + // + // Methods needed for JSON serialization/deserialization + // + + public Map getConfig() { + return config; + } + public void setConfig(Map config) { + this.config = config; + } + +} diff --git a/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/std/pap/StdPDPPolicy.java b/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/std/pap/StdPDPPolicy.java new file mode 100644 index 000000000..06c2498f6 --- /dev/null +++ b/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/std/pap/StdPDPPolicy.java @@ -0,0 +1,368 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-XACML + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.openecomp.policy.xacml.std.pap; + +import org.openecomp.policy.common.logging.eelf.PolicyLogger; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.io.Serializable; +import java.net.URI; +import java.net.URL; +import java.util.ArrayList; +import java.util.Properties; + +import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicySetType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openecomp.policy.xacml.util.XACMLPolicyScanner; + +import com.att.research.xacml.api.pap.PAPException; +import com.att.research.xacml.api.pap.PDPPolicy; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.google.common.base.Splitter; +import com.google.common.collect.Lists; + + +public class StdPDPPolicy implements PDPPolicy, Serializable { + private static final long serialVersionUID = 1L; + private static Log logger = LogFactory.getLog(StdPDPPolicy.class); + + private String id = null; + + private String name = null; + + private String policyId = null; + + private String description = null; + + private int[] version = null; + + private boolean isRoot = false; + + private boolean isValid = false; + + private URI location = null; + + + public StdPDPPolicy(String id, boolean isRoot) { + this.id = id; + this.isRoot = isRoot; + } + + public StdPDPPolicy(String id, boolean isRoot, String name) { + this(id, isRoot); + this.name = name; + } + + + public StdPDPPolicy(String id, boolean isRoot, String name, URI location) throws IOException { + this(id, isRoot); + this.name = name; + this.location = location; + + // + // Read the policy data + // + String theID = this.readPolicyData(); + + if (this.id == null) { + logger.debug("id is null so we are calling readPolicyData() to get the policyID"); + this.id = theID; + } + + logger.debug("The final outcome of the constructor returned the following: id = " + id + + ", location = " + location + ", name = " + name); + + } + + public StdPDPPolicy(String id, boolean isRoot, String name, URI location, boolean isValid, String policyId, + String description, String version) throws IOException { + this(id, isRoot); + this.name = name; + this.location = location; + this.policyId = policyId; + this.description = description; + this.version = versionStringToArray(version); + this.isValid = isValid; + + logger.debug("The final outcome of the constructor returned the following: id = " + id + + ", location = " + location + ", name = " + name + ", policyId = " + policyId + + ", description = " + description + ", Version = " + version); + + } + + public StdPDPPolicy(String id, boolean isRoot, String name, URI location, boolean isFromAPI) throws IOException { + this(id, isRoot); + this.name = name; + this.location = location; + this.isValid = isFromAPI; + + logger.debug("The final outcome of the constructor returned the following: id = " + id + + ", location = " + location + ", name = " + name); + + } + + public StdPDPPolicy(String id, boolean isRoot, URI location, Properties properties) throws IOException { + this(id, isRoot); + this.location = location; + // + // Read the policy data + // + this.readPolicyData(); + // + // See if there's a name + // + for (Object key : properties.keySet()) { + if (key.toString().equals(id + ".name")) { + this.name = properties.getProperty(key.toString()); + break; + } + } + } + + + private String readPolicyData() throws IOException { + // + // Extract XACML policy information + // + URL url = this.location.toURL(); + Object rootElement = XACMLPolicyScanner.readPolicy(url.openStream()); + if (rootElement == null || + ( + ! (rootElement instanceof PolicySetType) && + ! (rootElement instanceof PolicyType) + ) ) { + logger.warn("No root policy element in URI: " + this.location.toString() + " : " + rootElement); + this.isValid = false; + } else { + this.version = versionStringToArray(XACMLPolicyScanner.getVersion(rootElement)); + if (rootElement instanceof PolicySetType) { + this.policyId = ((PolicySetType)rootElement).getPolicySetId(); + this.description = ((PolicySetType)rootElement).getDescription(); + this.isValid = true; + this.version = versionStringToArray(((PolicySetType)rootElement).getVersion()); + } else if (rootElement instanceof PolicyType) { + this.policyId = ((PolicyType)rootElement).getPolicyId(); + this.description = ((PolicyType)rootElement).getDescription(); + this.version = versionStringToArray(((PolicyType)rootElement).getVersion()); + this.isValid = true; + } else { + //TODO:EELF Cleanup - Remove logger + //logger.error("Unknown root element: " + rootElement.getClass().getCanonicalName()); + PolicyLogger.error("Unknown root element: " + rootElement.getClass().getCanonicalName()); + } + } + if (this.policyId != null) { + ArrayList foo = Lists.newArrayList(Splitter.on(':').split(this.policyId)); + if (foo.isEmpty() == false) { + return foo.get(foo.size() - 1); + } + } + return null; + } + + @Override + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + @Override + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public String getPolicyId() { + return this.policyId; + } + + @Override + public String getDescription() { + return this.description; + } + + @Override + public String getVersion() { + return versionArrayToString(this.version); + } + + @Override + @JsonIgnore + public int[] getVersionInts() { + return version; + } + + @Override + public boolean isRoot() { + return this.isRoot; + } + + @Override + public boolean isValid() + { + return this.isValid; + } + + @Override + @JsonIgnore + public InputStream getStream() throws PAPException, IOException { + try { + if (this.location != null) { + URL url = this.location.toURL(); + return url.openStream(); + } + return null; + } catch (FileNotFoundException e) { + throw new PAPException(e); + } + } + + @Override + public URI getLocation() throws PAPException { + return this.location; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((id == null) ? 0 : id.hashCode()); + result = prime * result + + ((policyId == null) ? 0 : policyId.hashCode()); + result = prime * result; + if (version != null) { + for (int i = 0; i < version.length; i++) { + result += version[i]; + } + } + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + StdPDPPolicy other = (StdPDPPolicy) obj; + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) + return false; + if (policyId == null) { + if (other.policyId != null) + return false; + } else if (!policyId.equals(other.policyId)) + return false; + if (version != other.version) + return false; + return true; + } + + @Override + public String toString() { + return "StdPDPPolicy [id=" + id + ", name=" + name + ", policyId=" + + policyId + ", description=" + description + ", version=" + + this.getVersion() + ", isRoot=" + isRoot + ", isValid=" + isValid + + ", location=" + location + "]"; + } + + + /** + * Given a version string consisting of integers with dots between them, convert it into an array of ints. + * + * @param version + * @return + * @throws NumberFormatException + */ + public static int[] versionStringToArray(String version) throws NumberFormatException { + if (version == null || version.length() == 0) { + return new int[0]; + } + String[] stringArray = version.split("\\."); + int[] resultArray = new int[stringArray.length]; + for (int i = 0; i < stringArray.length; i++) { + resultArray[i] = Integer.parseInt(stringArray[i]); + } + return resultArray; + } + + /** + * Given an array representing a version, create the corresponding dot-separated string. + * + * @param array + * @return + */ + public static String versionArrayToString(int[] array) { + if (array == null || array.length == 0) { + return ""; + } + String versionString = ""; + if (array.length > 0) { + versionString = "" + array[0]; + for (int i = 1; i < array.length; i++) { + versionString += "." + array[i]; + } + } + return versionString; + } + + + + // + // Methods needed for JSON Deserialization + // + public StdPDPPolicy() {} + + public void setPolicyId(String policyId) { + this.policyId = policyId; + } + public void setDescription(String description) { + this.description = description; + } + public void setVersion(String version) { + this.version = versionStringToArray(version); + } + public void setRoot(boolean isRoot) { + this.isRoot = isRoot; + } + public void setValid(boolean isValid) { + this.isValid = isValid; + } + public void setLocation(URI location) { + this.location = location; + } + +} diff --git a/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/std/pap/StdPDPStatus.java b/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/std/pap/StdPDPStatus.java new file mode 100644 index 000000000..dc297657a --- /dev/null +++ b/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/std/pap/StdPDPStatus.java @@ -0,0 +1,265 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-XACML + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.openecomp.policy.xacml.std.pap; + +import java.io.Serializable; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +import com.att.research.xacml.api.pap.PDPPIPConfig; +import com.att.research.xacml.api.pap.PDPPolicy; +import com.att.research.xacml.api.pap.PDPStatus; +import com.fasterxml.jackson.annotation.JsonIgnore; + +public class StdPDPStatus implements Serializable, PDPStatus { + private static final long serialVersionUID = 1L; + + private Status status = Status.UNKNOWN; + + private Set loadErrors = new HashSet(); + + private Set loadWarnings = new HashSet(); + + private Set loadedPolicies = new HashSet(); + + private Set loadedRootPolicies = new HashSet(); + + private Set failedPolicies = new HashSet(); + + private Set loadedPIPConfigs = new HashSet(); + + private Set failedPIPConfigs = new HashSet(); + + public StdPDPStatus() { + } + + public void set(StdPDPStatus newStatus) { + this.status = newStatus.status; + this.loadErrors.clear(); + this.loadErrors.addAll(newStatus.getLoadErrors()); + this.loadWarnings.clear(); + this.loadWarnings.addAll(newStatus.getLoadWarnings()); + this.loadedPolicies.clear(); + this.loadedPolicies.addAll(newStatus.getLoadedPolicies()); + this.loadedRootPolicies.clear(); + this.loadedRootPolicies.addAll(newStatus.getLoadedRootPolicies()); + this.failedPolicies.clear(); + this.failedPolicies.addAll(newStatus.getFailedPolicies()); + this.loadedPIPConfigs.clear(); + this.loadedPIPConfigs.addAll(newStatus.getLoadedPipConfigs()); + this.failedPIPConfigs.clear(); + this.failedPIPConfigs.addAll(newStatus.getFailedPipConfigs()); + } + + + + @Override + public Status getStatus() { + return this.status; + } + + public void setStatus(Status status) { + this.status = status; + } + + @Override + public Set getLoadErrors() { + return Collections.unmodifiableSet(this.loadErrors); + } + + public void setLoadErrors(Set errors) { + this.loadErrors = errors; + } + + public void addLoadError(String error) { + this.loadErrors.add(error); + } + + @Override + public Set getLoadWarnings() { + return Collections.unmodifiableSet(this.loadWarnings); + } + + public void setLoadWarnings(Set warnings) { + this.loadWarnings = warnings; + } + + public void addLoadWarning(String warning) { + this.loadWarnings.add(warning); + } + + @Override + public Set getLoadedPolicies() { + return Collections.unmodifiableSet(this.loadedPolicies); + } + + public void setLoadedPolicies(Set policies) { + this.loadedPolicies = policies; + } + + public void addLoadedPolicy(PDPPolicy policy) { + this.loadedPolicies.add(policy); + } + + @Override + public Set getLoadedRootPolicies() { + return Collections.unmodifiableSet(this.loadedRootPolicies); + } + + public void setLoadedRootPolicies(Set policies) { + this.loadedRootPolicies = policies; + } + + public void addRootPolicy(PDPPolicy policy) { + this.loadedRootPolicies.add(policy); + } + + public void addAllLoadedRootPolicies(Set policies) { + this.loadedRootPolicies.addAll(policies); + } + + @Override + public Set getFailedPolicies() { + return Collections.unmodifiableSet(this.failedPolicies); + } + + public void setFailedPolicies(Set policies) { + this.failedPolicies = policies; + } + + public void addFailedPolicy(PDPPolicy policy) { + this.failedPolicies.add(policy); + } + + @Override + public boolean policiesOK() { + if (this.failedPolicies.size() > 0) { + return false; + } + return true; + } + + @Override + public Set getLoadedPipConfigs() { + return Collections.unmodifiableSet(this.loadedPIPConfigs); + } + + public void setLoadedPipConfigs(Set configs) { + this.loadedPIPConfigs = configs; + } + + public void addLoadedPipConfig(PDPPIPConfig config) { + this.loadedPIPConfigs.add(config); + } + + @Override + public Set getFailedPipConfigs() { + return Collections.unmodifiableSet(this.failedPIPConfigs); + } + + public void setFailedPipConfigs(Set configs) { + this.failedPIPConfigs = configs; + } + + public void addFailedPipConfig(PDPPIPConfig config) { + this.failedPIPConfigs.add(config); + } + + @Override + public boolean pipConfigOK() { + if (this.failedPIPConfigs.size() > 0) { + return false; + } + return true; + } + + @Override + @JsonIgnore + public boolean isOk() { + if (this.policiesOK() == false) { + return false; + } + if (this.pipConfigOK() == false) { + return false; + } + return (this.status == Status.UP_TO_DATE); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime + * result + + (failedPIPConfigs.hashCode()); + result = prime * result + + (failedPolicies.hashCode()); + result = prime * result + + (loadErrors.hashCode()); + result = prime * result + + (loadWarnings.hashCode()); + result = prime + * result + + (loadedPIPConfigs.hashCode()); + result = prime * result + + (loadedPolicies.hashCode()); + result = prime * result + (status.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + StdPDPStatus other = (StdPDPStatus) obj; + if (!failedPIPConfigs.equals(other.failedPIPConfigs)) + return false; + if (!failedPolicies.equals(other.failedPolicies)) + return false; + if (!loadErrors.equals(other.loadErrors)) + return false; + if (!loadWarnings.equals(other.loadWarnings)) + return false; + if (!loadedPIPConfigs.equals(other.loadedPIPConfigs)) + return false; + if (!loadedPolicies.equals(other.loadedPolicies)) + return false; + if (status != other.status) + return false; + return true; + } + + @Override + public String toString() { + return "StdPDPStatus [status=" + status + ", loadErrors=" + loadErrors + + ", loadWarnings=" + loadWarnings + ", loadedPolicies=" + + loadedPolicies + ", loadedRootPolicies=" + loadedRootPolicies + + ", failedPolicies=" + failedPolicies + + ", loadedPIPConfigs=" + loadedPIPConfigs + + ", failedPIPConfigs=" + failedPIPConfigs + "]"; + } + + +} diff --git a/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/std/pip/engines/aaf/AAFEngine.java b/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/std/pip/engines/aaf/AAFEngine.java new file mode 100644 index 000000000..6dea4c21f --- /dev/null +++ b/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/std/pip/engines/aaf/AAFEngine.java @@ -0,0 +1,276 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-XACML + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.openecomp.policy.xacml.std.pip.engines.aaf; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openecomp.policy.utils.AAFPolicyClient; +import org.openecomp.policy.utils.AAFPolicyException; + +import com.att.research.xacml.api.Attribute; +import com.att.research.xacml.api.AttributeValue; +import com.att.research.xacml.api.Identifier; +import com.att.research.xacml.api.XACML3; +import com.att.research.xacml.api.pip.PIPException; +import com.att.research.xacml.api.pip.PIPFinder; +import com.att.research.xacml.api.pip.PIPRequest; +import com.att.research.xacml.api.pip.PIPResponse; +import com.att.research.xacml.std.IdentifierImpl; +import com.att.research.xacml.std.StdMutableAttribute; +import com.att.research.xacml.std.datatypes.DataTypes; +import com.att.research.xacml.std.pip.StdMutablePIPResponse; +import com.att.research.xacml.std.pip.StdPIPRequest; +import com.att.research.xacml.std.pip.StdPIPResponse; +import com.att.research.xacml.std.pip.engines.StdConfigurableEngine; + +/** + * PIP Engine for Implementing {@link com.att.research.xacml.std.pip.engines.ConfigurableEngine} interface to provide + * attribute retrieval from AT&T AAF interface. + * + * @version $Revision$ + */ +public class AAFEngine extends StdConfigurableEngine { + + public static final String DEFAULT_DESCRIPTION = "PIP for authenticating aaf attributes using the AT&T AAF REST interface"; + public static final String DEFAULT_ISSUER = "att-aaf"; + + private static final String SUCCESS = "Success"; + + public static final String AAF_RESULT= "AAF_RESULT"; + public static final String AAF_RESPONSE= "AAF_RESPONSE"; + // + public static final Identifier AAF_RESPONSE_ID = new IdentifierImpl(AAF_RESPONSE); + public static final Identifier AAF_RESULT_ID = new IdentifierImpl(AAF_RESULT); + + // + private static final PIPRequest PIP_REQUEST_UID = new StdPIPRequest(XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, new IdentifierImpl("AAF_ID"), XACML3.ID_DATATYPE_STRING); + private static final PIPRequest PIP_REQUEST_PASS = new StdPIPRequest(XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, new IdentifierImpl("AAF_PASS"), XACML3.ID_DATATYPE_STRING); + private static final PIPRequest PIP_REQUEST_TYPE = new StdPIPRequest(XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, new IdentifierImpl("AAF_TYPE"), XACML3.ID_DATATYPE_STRING); + private static final PIPRequest PIP_REQUEST_INSTANCE = new StdPIPRequest(XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, new IdentifierImpl("AAF_INSTANCE"), XACML3.ID_DATATYPE_STRING); + private static final PIPRequest PIP_REQUEST_ACTION = new StdPIPRequest(XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, new IdentifierImpl("AAF_ACTION"), XACML3.ID_DATATYPE_STRING); + private static final PIPRequest PIP_REQUEST_ENV = new StdPIPRequest(XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, new IdentifierImpl("AAF_ENVIRONMENT"), XACML3.ID_DATATYPE_STRING); + + private static final List mapRequiredAttributes = new ArrayList(); + static{ + mapRequiredAttributes.add(new StdPIPRequest(PIP_REQUEST_UID)); + mapRequiredAttributes.add(new StdPIPRequest(PIP_REQUEST_PASS)); + mapRequiredAttributes.add(new StdPIPRequest(PIP_REQUEST_TYPE)); + mapRequiredAttributes.add(new StdPIPRequest(PIP_REQUEST_INSTANCE)); + mapRequiredAttributes.add(new StdPIPRequest(PIP_REQUEST_ACTION)); + mapRequiredAttributes.add(new StdPIPRequest(PIP_REQUEST_ENV)); + } + + private static final Map mapSupportedAttributes = new HashMap(); + static{ + mapSupportedAttributes.put(new StdPIPRequest(XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, AAF_RESPONSE_ID, XACML3.ID_DATATYPE_STRING), "response"); + mapSupportedAttributes.put(new StdPIPRequest(XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, AAF_RESULT_ID, XACML3.ID_DATATYPE_BOOLEAN), "result"); + } + + protected Log logger = LogFactory.getLog(this.getClass()); + + public AAFEngine(){ + } + + private PIPResponse getAttribute(PIPRequest pipRequest, PIPFinder pipFinder) { + PIPResponse pipResponse = null; + try { + pipResponse = pipFinder.getMatchingAttributes(pipRequest, this); + if (pipResponse.getStatus() != null && !pipResponse.getStatus().isOk()) { + this.logger.warn("Error retrieving " + pipRequest.getAttributeId().stringValue() + ": " + pipResponse.getStatus().toString()); + pipResponse = null; + } + if (pipResponse.getAttributes().size() == 0) { + this.logger.warn("No value for " + pipRequest.getAttributeId().stringValue()); + pipResponse = null; + } + } catch (PIPException ex) { + this.logger.error("PIPException getting subject-id attribute: " + ex.getMessage(), ex); + } + return pipResponse; + } + + private String getValue(PIPResponse pipResponse){ + String result = null; + Collection listAttributes = pipResponse.getAttributes(); + for(Attribute attribute: listAttributes){ + Iterator> iterAttributeValues = attribute.findValues(DataTypes.DT_STRING); + if(iterAttributeValues!=null) { + while(iterAttributeValues.hasNext()){ + result = iterAttributeValues.next().getValue(); + break; + } + } + } + return result; + } + + private synchronized String getResult(PIPFinder pipFinder) { + PIPResponse pipResponseUID = this.getAttribute(PIP_REQUEST_UID, pipFinder); + PIPResponse pipResponsePass = this.getAttribute(PIP_REQUEST_PASS, pipFinder); + PIPResponse pipResponseType = this.getAttribute(PIP_REQUEST_TYPE, pipFinder); + PIPResponse pipResponseAction = this.getAttribute(PIP_REQUEST_ACTION, pipFinder); + PIPResponse pipResponseInstance = this.getAttribute(PIP_REQUEST_INSTANCE, pipFinder); + PIPResponse pipResponseEnv = this.getAttribute(PIP_REQUEST_ENV, pipFinder); + String response = null; + // Evaluate AAF if we have all the required values. + if(pipResponseUID!=null && pipResponsePass!=null && pipResponseType != null && pipResponseAction!= null && pipResponseInstance!=null && pipResponseEnv!=null){ + // Check the Environment. + String environment = getValue(pipResponseEnv); + if(environment == null){ + response = "Environment Value is not set. "; + } + String userName = getValue(pipResponseUID); + String pass = getValue(pipResponsePass); + AAFPolicyClient aafClient = null; + Properties properties = new Properties(); + if(environment.equalsIgnoreCase("PROD")){ + properties.setProperty("ENVIRONMENT", "PROD"); + }else if(environment.equalsIgnoreCase("TEST")){ + properties.setProperty("ENVIRONMENT", "TEST"); + }else{ + properties.setProperty("ENVIRONMENT", "DEVL"); + } + logger.debug("environment : " + environment); + if(userName!=null && pass!=null){ + try { + aafClient = AAFPolicyClient.getInstance(properties); + } catch (AAFPolicyException e) { + logger.error("AAF configuration failed. " + e.getMessage()); + } + if(aafClient!=null){ + if(aafClient.checkAuth(userName, pass)){ + String type = getValue(pipResponseType); + String instance = getValue(pipResponseInstance); + String action = getValue(pipResponseAction); + if(aafClient.checkPerm(userName, pass, type, instance, action)){ + response = SUCCESS + "Permissions Validated"; + }else{ + response = "No Permissions for "+userName+" to: "+type+", "+instance+", "+action; + } + }else{ + response = "Authentication Failed for the given Values"; + } + } + }else{ + response = "ID and Password are not given"; + } + + }else{ + response = "Insufficient Values to Evaluate AAF"; + } + return response; + } + + private void addStringAttribute(StdMutablePIPResponse stdPIPResponse, Identifier category, Identifier attributeId, String value) { + if (value != null) { + AttributeValue attributeValue = null; + try { + attributeValue = DataTypes.DT_STRING.createAttributeValue(value); + } catch (Exception ex) { + this.logger.error("Failed to convert " + value + " to an AttributeValue", ex); + } + if (attributeValue != null) { + stdPIPResponse.addAttribute(new StdMutableAttribute(category, attributeId, attributeValue, this.getIssuer(), false)); + } + } + } + + private void addBooleanAttribute(StdMutablePIPResponse stdPIPResponse, Identifier category, Identifier attributeId, boolean value) { + AttributeValue attributeValue = null; + try { + attributeValue = DataTypes.DT_BOOLEAN.createAttributeValue(value); + } catch (Exception ex) { + this.logger.error("Failed to convert " + value + " to an AttributeValue", ex); + } + if (attributeValue != null) { + stdPIPResponse.addAttribute(new StdMutableAttribute(category, attributeId, attributeValue, this.getIssuer(), false)); + } + } + + @Override + public PIPResponse getAttributes(PIPRequest pipRequest, PIPFinder pipFinder) throws PIPException { + /* + * First check to see if the issuer is set and then match it + */ + String string; + if ((string = pipRequest.getIssuer()) != null) { + if (!string.equals(this.getIssuer())) { + this.logger.debug("Requested issuer '" + string + "' does not match " + (this.getIssuer() == null ? "null" : "'" + this.getIssuer() + "'")); + return StdPIPResponse.PIP_RESPONSE_EMPTY; + } + } + + /* + * Drop the issuer and see if the request matches any of our supported queries + */ + PIPRequest pipRequestSupported = (pipRequest.getIssuer() == null ? pipRequest : new StdPIPRequest(pipRequest.getCategory(), pipRequest.getAttributeId(), pipRequest.getDataTypeId())); + if (!mapSupportedAttributes.containsKey(pipRequestSupported)) { + this.logger.debug("Requested attribute '" + pipRequest.toString() + "' is not supported"); + return StdPIPResponse.PIP_RESPONSE_EMPTY; + } + StdMutablePIPResponse stdPIPResponse = new StdMutablePIPResponse(); + String response = this.getResult(pipFinder); + boolean result = false; + if(response.contains(SUCCESS)){ + result = true; + } + this.addBooleanAttribute(stdPIPResponse, XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, AAF_RESULT_ID, result); + this.addStringAttribute(stdPIPResponse, XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, AAF_RESPONSE_ID, response); + return new StdPIPResponse(stdPIPResponse); + } + + @Override + public void configure(String id, Properties properties) throws PIPException { + super.configure(id, properties); + if (this.getDescription() == null) { + this.setDescription(DEFAULT_DESCRIPTION); + } + if (this.getIssuer() == null) { + this.setIssuer(DEFAULT_ISSUER); + } + } + + @Override + public Collection attributesRequired() { + List attributes = new ArrayList(); + for (PIPRequest attribute: mapRequiredAttributes) { + attributes.add(new StdPIPRequest(attribute)); + } + return attributes; + } + + @Override + public Collection attributesProvided() { + List attributes = new ArrayList(); + for (PIPRequest attribute : mapSupportedAttributes.keySet()) { + attributes.add(new StdPIPRequest(attribute)); + } + return attributes; + } + +} diff --git a/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/util/MetricsUtil.java b/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/util/MetricsUtil.java new file mode 100644 index 000000000..45a51a191 --- /dev/null +++ b/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/util/MetricsUtil.java @@ -0,0 +1,80 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-XACML + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.openecomp.policy.xacml.util; + +public class MetricsUtil { + + public static class AvgLatency { + private long cumLatency = 0; + private long count = 0; + + public void compute(long latency) { + cumLatency += latency; + count++; + } + + public long avg() { + if (count == 0) + return 0; + + return (cumLatency / count); + } + + public void reset() { + cumLatency = 0; + count = 0; + } + } + + public static class MinLatency { + private long min = Long.MAX_VALUE; + + public synchronized void compute(long ts) { + if (ts < min) + min = ts; + } + + public long min() { + return min; + } + + public void reset() { + min = Long.MAX_VALUE; + } + } + + public static class MaxLatency { + private long max = Long.MIN_VALUE; + + public synchronized void compute(long ts) { + if (ts > max) + max = ts; + } + + public long max() { + return max; + } + + public void reset() { + max = Long.MIN_VALUE; + } + } + +} diff --git a/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/util/XACMLPolicyScanner.java b/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/util/XACMLPolicyScanner.java new file mode 100644 index 000000000..7fa2aa414 --- /dev/null +++ b/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/util/XACMLPolicyScanner.java @@ -0,0 +1,727 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-XACML + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.openecomp.policy.xacml.util; + +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBElement; +import javax.xml.bind.Unmarshaller; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.eelf.PolicyLogger; + +import com.att.research.xacml.api.AttributeAssignment; +import com.att.research.xacml.std.IdentifierImpl; +import com.att.research.xacml.std.StdAttribute; +import com.att.research.xacml.std.StdAttributeAssignment; +import com.att.research.xacml.std.StdAttributeValue; +import com.att.research.xacml.std.StdMutableAdvice; +import com.att.research.xacml.std.StdMutableObligation; +import com.att.research.xacml.util.XACMLPolicyScanner.Callback; +import com.att.research.xacml.util.XACMLPolicyScanner.CallbackResult; + +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionsType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeAssignmentExpressionType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeSelectorType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.ConditionType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.IdReferenceType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObligationExpressionType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObligationExpressionsType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicySetType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.RuleType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.VariableDefinitionType; + +/** + * class XACMLPolicyScanner + * + * This class traverses the hierarchy of a XACML 3.0 policy. You can optionally pass a Callback class + * and override any desired methods to retrieve information from a policy. + * + * + */ +public class XACMLPolicyScanner { + + private static final Log logger = LogFactory.getLog(XACMLPolicyScanner.class); + private Object policyObject = null; + private Callback callback = null; + + public XACMLPolicyScanner(Path filename, Callback callback) { + try (InputStream is = Files.newInputStream(filename)) { + this.policyObject = XACMLPolicyScanner.readPolicy(is); + } catch (IOException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Failed to read policy", e); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "XACMLPolicyScanner", "Failed to read policy"); + } + this.callback = callback; + } + + public XACMLPolicyScanner(PolicySetType policySet, Callback callback) { + this.policyObject = policySet; + this.callback = callback; + } + + public XACMLPolicyScanner(PolicySetType policySet) { + this(policySet, null); + } + + public XACMLPolicyScanner(PolicyType policy, Callback callback) { + this.policyObject = policy; + this.callback = callback; + } + + public XACMLPolicyScanner(PolicyType policy) { + this(policy, null); + } + + /** + * Sets the callback interface to be used. + * + * @param cb + */ + public void setCallback(Callback cb) { + this.callback = cb; + } + + /** + * Saves the given callback object then calls the scan() method. + * + * @param cb + * @return + */ + public Object scan(Callback cb) { + this.callback = cb; + return this.scan(); + } + + /** + * + * This begins the scanning of the contained object. + * + * @return - The PolicySet/Policy that was scanned. + */ + public Object scan() { + if (this.policyObject == null) { + return null; + } + if (this.callback != null) { + if (this.callback.onBeginScan(this.policyObject) == CallbackResult.STOP) { + return this.policyObject; + } + } + if (this.policyObject instanceof PolicyType) { + this.scanPolicy(null, (PolicyType) this.policyObject); + } else if (this.policyObject instanceof PolicySetType) { + this.scanPolicySet(null, (PolicySetType) this.policyObject); + } else { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Unknown class type: " + this.policyObject.getClass().getCanonicalName()); + PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW + "Unknown class type: " + this.policyObject.getClass().getCanonicalName()); + } + if (this.callback != null) { + this.callback.onFinishScan(this.policyObject); + } + return this.policyObject; + } + + /** + * This performs the scan of a PolicySet + * + * @param parent - Its parent PolicySet. Can be null if this is the root. + * @param policySet - The PolicySet object. + * @return CallbackResult - CONTINUE to continue, STOP to terminate scanning. + */ + /** + * @param parent + * @param policySet + * @return + */ + protected CallbackResult scanPolicySet(PolicySetType parent, PolicySetType policySet) { + if (logger.isTraceEnabled()) { + logger.trace("scanning policy set: " + policySet.getPolicySetId() + " " + policySet.getDescription()); + } + if (this.callback != null) { + if (this.callback.onPreVisitPolicySet(parent, policySet) == CallbackResult.STOP) { + return CallbackResult.STOP; + } + } + // + // Scan its info + // + if (this.scanTarget(policySet, policySet.getTarget()) == CallbackResult.STOP) { + return CallbackResult.STOP; + } + if (this.scanObligations(policySet, policySet.getObligationExpressions()) == CallbackResult.STOP) { + return CallbackResult.STOP; + } + if (this.scanAdvice(policySet, policySet.getAdviceExpressions()) == CallbackResult.STOP) { + return CallbackResult.STOP; + } + // + // Iterate the policy sets and/or policies + // + List> list = policySet.getPolicySetOrPolicyOrPolicySetIdReference(); + for (JAXBElement element: list) { + if (element.getName().getLocalPart().equals("PolicySet")) { + if (this.scanPolicySet(policySet, (PolicySetType)element.getValue()) == CallbackResult.STOP) { + return CallbackResult.STOP; + } + } else if (element.getName().getLocalPart().equals("Policy")) { + if (this.scanPolicy(policySet, (PolicyType)element.getValue()) == CallbackResult.STOP) { + return CallbackResult.STOP; + } + } else if (element.getValue() instanceof IdReferenceType) { + if (element.getName().getLocalPart().equals("PolicySetIdReference")) { + + } else if (element.getName().getLocalPart().equals("PolicyIdReference")) { + + } + } else { + logger.warn("generating policy sets found unsupported element: " + element.getName().getNamespaceURI()); + } + } + if (this.callback != null) { + if (this.callback.onPostVisitPolicySet(parent, policySet) == CallbackResult.STOP) { + return CallbackResult.STOP; + } + } + return CallbackResult.CONTINUE; + } + + /** + * + * This performs scanning of the Policy object. + * + * @param parent - The parent PolicySet of the policy. This can be null if this is a root Policy. + * @param policy - The policy being scanned. + * @return CallbackResult - CONTINUE to continue, STOP to terminate scanning. + */ + protected CallbackResult scanPolicy(PolicySetType parent, PolicyType policy) { + if (logger.isTraceEnabled()) { + logger.trace("scanning policy: " + policy.getPolicyId() + " " + policy.getDescription()); + } + if (this.callback != null) { + if (this.callback.onPreVisitPolicy(parent, policy) == CallbackResult.STOP) { + return CallbackResult.STOP; + } + } + // + // Scan its info + // + if (this.scanTarget(policy, policy.getTarget()) == CallbackResult.STOP) { + return CallbackResult.STOP; + } + if (this.scanVariables(policy, policy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition()) == CallbackResult.STOP) { + return CallbackResult.STOP; + } + if (this.scanObligations(policy, policy.getObligationExpressions()) == CallbackResult.STOP) { + return CallbackResult.STOP; + } + if (this.scanAdvice(policy, policy.getAdviceExpressions()) == CallbackResult.STOP) { + return CallbackResult.STOP; + } + // + // Iterate the rules + // + List list = policy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition(); + for (Object o: list) { + if (o instanceof RuleType) { + RuleType rule = (RuleType) o; + if (logger.isTraceEnabled()) { + logger.trace("scanning rule: " + rule.getRuleId() + " " + rule.getDescription()); + } + if (this.callback != null) { + if (this.callback.onPreVisitRule(policy, rule) == CallbackResult.STOP) { + return CallbackResult.STOP; + } + } + if (this.scanTarget(rule, rule.getTarget()) == CallbackResult.STOP) { + return CallbackResult.STOP; + } + if (this.scanConditions(rule, rule.getCondition()) == CallbackResult.STOP) { + return CallbackResult.STOP; + } + if (this.scanObligations(rule, rule.getObligationExpressions()) == CallbackResult.STOP) { + return CallbackResult.STOP; + } + if (this.scanAdvice(rule, rule.getAdviceExpressions()) == CallbackResult.STOP) { + return CallbackResult.STOP; + } + if (this.callback != null) { + if (this.callback.onPostVisitRule(policy, rule) == CallbackResult.STOP) { + return CallbackResult.STOP; + } + } + } else if (o instanceof VariableDefinitionType) { + if (this.callback != null) { + if (this.callback.onVariable(policy, (VariableDefinitionType) o) == CallbackResult.STOP) { + return CallbackResult.STOP; + } + } + } else { + if (logger.isDebugEnabled()) { + logger.debug("scanning policy rules found unsupported object:" + o.toString()); + } + } + } + if (this.callback != null) { + if (this.callback.onPostVisitPolicy(parent, policy) == CallbackResult.STOP) { + return CallbackResult.STOP; + } + } + return CallbackResult.CONTINUE; + } + + /** + * Scans the given target for attributes. Its sole purpose is to return attributes found. + * + * @param parent - The parent PolicySet/Policy/Rule for the target. + * @param target - The target. + * @return CallbackResult - CONTINUE to continue, STOP to terminate scanning. + */ + protected CallbackResult scanTarget(Object parent, TargetType target) { + if (target == null) { + return CallbackResult.CONTINUE; + } + List anyOfList = target.getAnyOf(); + if (anyOfList != null) { + Iterator iterAnyOf = anyOfList.iterator(); + while (iterAnyOf.hasNext()) { + AnyOfType anyOf = iterAnyOf.next(); + List allOfList = anyOf.getAllOf(); + if (allOfList != null) { + Iterator iterAllOf = allOfList.iterator(); + while (iterAllOf.hasNext()) { + AllOfType allOf = iterAllOf.next(); + List matchList = allOf.getMatch(); + if (matchList != null) { + Iterator iterMatch = matchList.iterator(); + while (iterMatch.hasNext()) { + MatchType match = iterMatch.next(); + // + // Finally down to the actual attribute + // + StdAttribute attribute = null; + AttributeValueType value = match.getAttributeValue(); + if (match.getAttributeDesignator() != null && value != null) { + AttributeDesignatorType designator = match.getAttributeDesignator(); + // + // The content may be tricky + // + attribute = new StdAttribute(new IdentifierImpl(designator.getCategory()), + new IdentifierImpl(designator.getAttributeId()), + new StdAttributeValue>(new IdentifierImpl(value.getDataType()), value.getContent()), + designator.getIssuer(), + false); + } else if (match.getAttributeSelector() != null && value != null) { + AttributeSelectorType selector = match.getAttributeSelector(); + attribute = new StdAttribute(new IdentifierImpl(selector.getCategory()), + new IdentifierImpl(selector.getContextSelectorId()), + new StdAttributeValue>(new IdentifierImpl(value.getDataType()), value.getContent()), + null, + false); + } else { + logger.warn("NULL designator/selector or value for match."); + } + if (attribute != null && this.callback != null) { + if (this.callback.onAttribute(parent, target, attribute) == CallbackResult.STOP) { + return CallbackResult.STOP; + } + } + } + } + } + } + } + } + return CallbackResult.CONTINUE; + } + + /** + * Scan the list of obligations. + * + * @param parent - The parent PolicySet/Policy/Rule for the obligation. + * @param obligationExpressionsType - All the obligation expressions. + * @return CallbackResult - CONTINUE to continue, STOP to terminate scanning. + */ + protected CallbackResult scanObligations(Object parent, ObligationExpressionsType obligationExpressionsType) { + if (obligationExpressionsType == null) { + return CallbackResult.CONTINUE; + } + List expressions = obligationExpressionsType.getObligationExpression(); + if (expressions == null || expressions.size() == 0) { + return CallbackResult.CONTINUE; + } + for (ObligationExpressionType expression : expressions) { + StdMutableObligation ob = new StdMutableObligation(new IdentifierImpl(expression.getObligationId())); + List assignments = expression.getAttributeAssignmentExpression(); + if (assignments != null) { + for (AttributeAssignmentExpressionType assignment : assignments) { + // category is optional and may be null + IdentifierImpl categoryId = null; + if (assignment.getCategory() != null) { + categoryId = new IdentifierImpl(assignment.getCategory()); + } + AttributeAssignment attribute = new StdAttributeAssignment( + categoryId, + new IdentifierImpl(assignment.getAttributeId()), + assignment.getIssuer(), + new StdAttributeValue(null, null) + ); + ob.addAttributeAssignment(attribute); + } + } + if (this.callback != null) { + if (this.callback.onObligation(parent, expression, ob) == CallbackResult.STOP) { + return CallbackResult.STOP; + } + } + } + return CallbackResult.CONTINUE; + } + + /** + * + * Scans the list of advice expressions returning each individually. + * + * @param parent - The parent PolicySet/Policy/Rule for the advice. + * @param adviceExpressionstype - The list of advice expressions. + * @return CallbackResult - CONTINUE to continue, STOP to terminate scanning. + */ + protected CallbackResult scanAdvice(Object parent, AdviceExpressionsType adviceExpressionstype) { + if (adviceExpressionstype == null) { + return CallbackResult.CONTINUE; + } + List expressions = adviceExpressionstype.getAdviceExpression(); + if (expressions == null || expressions.size() == 0) { + return CallbackResult.CONTINUE; + } + for (AdviceExpressionType expression : expressions) { + StdMutableAdvice ob = new StdMutableAdvice(new IdentifierImpl(expression.getAdviceId())); + List assignments = expression.getAttributeAssignmentExpression(); + if (assignments != null) { + for (AttributeAssignmentExpressionType assignment : assignments) { + IdentifierImpl categoryId = null; + if (assignment.getCategory() != null) { + categoryId = new IdentifierImpl(assignment.getCategory()); + } + AttributeAssignment attribute = new StdAttributeAssignment( + categoryId, + new IdentifierImpl(assignment.getAttributeId()), + assignment.getIssuer(), + new StdAttributeValue(null, null) + ); + ob.addAttributeAssignment(attribute); + } + } + if (this.callback != null) { + if (this.callback.onAdvice(parent, expression, ob) == CallbackResult.STOP) { + return CallbackResult.STOP; + } + } + } + return CallbackResult.CONTINUE; + } + + /** + * Scans the list of variable definitions. + * + * @param policy - Policy object containing the variable definition. + * @param list - List of variable definitions. + * @return CallbackResult - CONTINUE to continue, STOP to terminate scanning. + */ + protected CallbackResult scanVariables(PolicyType policy, List list) { + if (list == null) { + return CallbackResult.CONTINUE; + } + for (Object o : list) { + if (o instanceof VariableDefinitionType) { + if (this.callback != null) { + if (this.callback.onVariable(policy, (VariableDefinitionType) o) == CallbackResult.STOP) { + return CallbackResult.STOP; + } + } + } + } + + return CallbackResult.CONTINUE; + } + + /** + * Scans the list of conditions. + * + * @param rule + * @param condition + * @return + */ + protected CallbackResult scanConditions(RuleType rule, ConditionType condition) { + if (condition != null) { + if (this.callback != null) { + if (this.callback.onCondition(rule, condition) == CallbackResult.STOP) { + return CallbackResult.STOP; + } + } + } + return CallbackResult.CONTINUE; + } + + /** + * Reads the XACML XML policy file in and returns the version contained in the root Policy/PolicySet element. + * + * @param policy - The policy file. + * @return - The version string from the file (uninterpreted) + * @throws IOException + */ + public static String getVersion(Path policy) throws IOException { + Object data = null; + try (InputStream is = Files.newInputStream(policy)) { + data = XACMLPolicyScanner.readPolicy(is); + } catch (IOException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Failed to read policy", e); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "XACMLPolicyScanner", "Failed to read policy"); + throw e; + } + if (data == null) { + logger.warn("Version is null."); + return null; + } + return getVersion(data); + } + + /** + * Reads the Policy/PolicySet element object and returns its current version. + * + * @param data - Either a PolicySet or Policy XACML type object. + * @return - The integer version value. -1 if it doesn't exist or was un-parsable. + */ + public static String getVersion(Object data) { + String version = null; + try { + if (data instanceof PolicySetType) { + version = ((PolicySetType)data).getVersion(); + } else if (data instanceof PolicyType) { + version = ((PolicyType)data).getVersion(); + } else { + if (data != null) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Expecting a PolicySet/Policy/Rule object. Got: " + data.getClass().getCanonicalName()); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + "Expecting a PolicySet/Policy/Rule object. Got: " + data.getClass().getCanonicalName()); + } + return null; + } + if (version != null && version.length() > 0) { + return version; + } else { + logger.warn("No version set in policy"); + } + } catch (NumberFormatException e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Invalid version contained in policy: " + version); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "XACMLPolicyScanner", "Invalid version contained in policy: " + version); + return null; + } + return null; + } + + /** + * Returns the Policy or PolicySet ID. + * + * @param data - A XACML 3.0 Policy or PolicySet element object. + * @return The policy/policyset's policy ID + */ + public static String getID(Object data) { + if (data instanceof PolicySetType) { + return ((PolicySetType)data).getPolicySetId(); + } else if (data instanceof PolicyType) { + return ((PolicyType)data).getPolicyId(); + } else { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Expecting a PolicySet/Policy/Rule object. Got: " + data.getClass().getCanonicalName()); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + "Expecting a PolicySet/Policy/Rule object. Got: " + data.getClass().getCanonicalName()); + return null; + } + } + + public static List getCreatedByModifiedBy(Path policyPath) throws IOException{ + String createdBy = ""; + String modifiedBy= ""; + String cValue = "@CreatedBy:"; + String mValue = "@ModifiedBy:"; + for(String line: Files.readAllLines(policyPath)){ + line = line.replaceAll("\\s+", ""); + if(line.isEmpty()){ + continue; + } + if(line.contains("") && line.contains(cValue) && line.contains(mValue)){ + createdBy = line.substring(line.indexOf(cValue) + cValue.length(), line.lastIndexOf(cValue)); + modifiedBy = line.substring(line.indexOf(mValue) + mValue.length(), line.lastIndexOf(mValue)); + break; + } + } + return Arrays.asList(createdBy, modifiedBy); + } + + //get the Created Name of the User on reading the Xml file + public static String getCreatedBy(Path policyPath) throws IOException{ + String userId = ""; + String value = "@CreatedBy:"; + for(String line: Files.readAllLines(policyPath)){ + line = line.replaceAll("\\s+", ""); + if(line.isEmpty()){ + continue; + } + if(line.contains("") && line.contains(value)){ + userId = line.substring(line.indexOf(value) + value.length(), line.lastIndexOf(value)); + break; + } + } + return userId; + } + + //get the Modified Name of the User on reading the Xml file + public static String getModifiedBy(Path policyPath) throws IOException{ + String modifiedBy = ""; + String value = "@ModifiedBy:"; + for(String line: Files.readAllLines(policyPath)){ + line = line.replaceAll("\\s+", ""); + if(line.isEmpty()){ + continue; + } + if(line.contains("") && line.contains(value)){ + modifiedBy = line.substring(line.indexOf(value) + value.length(), line.lastIndexOf(value)); + break; + } + } + return modifiedBy; + } + + /** + * readPolicy - does the work to read in policy data from a file. + * + * @param policy - The path to the policy file. + * @return - The policy data object. This *should* be either a PolicySet or a Policy. + */ + public static Object readPolicy(InputStream is) { + try { + // + // Create a DOM parser + // + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setNamespaceAware(true); + DocumentBuilder db = dbf.newDocumentBuilder(); + // + // Parse the policy file + // + Document doc = db.parse(is); + // + // Because there is no root defined in xacml, + // find the first element + // + NodeList nodes = doc.getChildNodes(); + Node node = nodes.item(0); + Element e = null; + if (node.getNodeType() == Node.ELEMENT_NODE) { + e = (Element) node; + // + // Is it a 3.0 policy? + // + if (e.getNamespaceURI().equals("urn:oasis:names:tc:xacml:3.0:core:schema:wd-17")) { + // + // A policyset or policy could be the root + // + if (e.getNodeName().endsWith("Policy")) { + // + // Now we can create the context for the policy set + // and unmarshall the policy into a class. + // + JAXBContext context = JAXBContext.newInstance(PolicyType.class); + Unmarshaller um = context.createUnmarshaller(); + JAXBElement root = um.unmarshal(e, PolicyType.class); + // + // Here is our policy set class + // + return root.getValue(); + } else if (e.getNodeName().endsWith("PolicySet")) { + // + // Now we can create the context for the policy set + // and unmarshall the policy into a class. + // + JAXBContext context = JAXBContext.newInstance(PolicySetType.class); + Unmarshaller um = context.createUnmarshaller(); + JAXBElement root = um.unmarshal(e, PolicySetType.class); + // + // Here is our policy set class + // + return root.getValue(); + } else { + if (logger.isDebugEnabled()) { + logger.debug("Not supported yet: " + e.getNodeName()); + } + } + } else { + logger.warn("unsupported namespace: " + e.getNamespaceURI()); + } + } else { + if (logger.isDebugEnabled()) { + logger.debug("No root element contained in policy " + + " Name: " + node.getNodeName() + " type: " + node.getNodeType() + + " Value: " + node.getNodeValue()); + } + } + } catch (Exception e) { + //TODO:EELF Cleanup - Remove logger + //logger.error(XACMLErrorConstants.ERROR_SCHEMA_INVALID + e.getMessage()); + PolicyLogger.error(MessageCodes.ERROR_SCHEMA_INVALID, e, "XACMLPolicyScanner", "Exception in readPolicy"); + } + return null; + } + + /** + * @return the policyObject + */ + public Object getPolicyObject() { + return policyObject; + } +} diff --git a/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/util/XACMLPolicyWriter.java b/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/util/XACMLPolicyWriter.java new file mode 100644 index 000000000..3706bda3f --- /dev/null +++ b/ECOMP-XACML/src/main/java/org/openecomp/policy/xacml/util/XACMLPolicyWriter.java @@ -0,0 +1,344 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-XACML + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.openecomp.policy.xacml.util; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.InputStream; +import java.io.OutputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Iterator; +import java.util.List; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBElement; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Marshaller; +import javax.xml.bind.Unmarshaller; + +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.eelf.PolicyLogger; + + +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionsType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeAssignmentExpressionType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObjectFactory; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObligationExpressionType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObligationExpressionsType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicySetType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.RuleType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType; + +/** + * Helper static class for policy writing. + * + * + */ +public class XACMLPolicyWriter { + + /** + * Helper static class that does the work to write a policy set to a file on disk. + * + * + */ + public static Path writePolicyFile(Path filename, PolicySetType policySet) { + JAXBElement policySetElement = new ObjectFactory().createPolicySet(policySet); + try { + JAXBContext context = JAXBContext.newInstance(PolicySetType.class); + Marshaller m = context.createMarshaller(); + m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); + m.marshal(policySetElement, filename.toFile()); + + if (Files.exists(filename)) { + return filename; + } else { + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + "File does not exist after marshalling."); + return null; + } + + } catch (JAXBException e) { + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "XACMLPolicyWriter", "writePolicyFile failed"); + return null; + } + } + + /** + * Helper static class that does the work to write a policy set to an output stream. + * + * + */ + public static void writePolicyFile(OutputStream os, PolicySetType policySet) { + JAXBElement policySetElement = new ObjectFactory().createPolicySet(policySet); + try { + JAXBContext context = JAXBContext.newInstance(PolicySetType.class); + Marshaller m = context.createMarshaller(); + m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); + m.marshal(policySetElement, os); + } catch (JAXBException e) { + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "XACMLPolicyWriter", "writePolicyFile failed"); + } + } + + /** + * Helper static class that does the work to write a policy to a file on disk. + * + * + */ + public static Path writePolicyFile(Path filename, PolicyType policy) { + JAXBElement policyElement = new ObjectFactory().createPolicy(policy); + try { + JAXBContext context = JAXBContext.newInstance(PolicyType.class); + Marshaller m = context.createMarshaller(); + m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); + m.marshal(policyElement, filename.toFile()); + + if (Files.exists(filename)) { + return filename; + } else { + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + "File does not exist after marshalling."); + return null; + } + + } catch (JAXBException e) { + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "XACMLPolicyWriter", "writePolicyFile failed"); + return null; + } + } + + + /** + * Helper static class that does the work to write a policy to a file on disk. + * + * + */ + public static InputStream getXmlAsInputStream(PolicyType policy) { + JAXBElement policyElement = new ObjectFactory().createPolicy(policy); + try { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + JAXBContext context = JAXBContext.newInstance(PolicyType.class); + Marshaller m = context.createMarshaller(); + m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); + m.marshal(policyElement, byteArrayOutputStream); + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray()); + + return byteArrayInputStream; + + } catch (JAXBException e) { + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "XACMLPolicyWriter", "writePolicyFile failed"); + return null; + } + } + /** + * Helper static class that does the work to write a policy set to an output stream. + * + * + */ + public static void writePolicyFile(OutputStream os, PolicyType policy) { + JAXBElement policySetElement = new ObjectFactory().createPolicy(policy); + try { + JAXBContext context = JAXBContext.newInstance(PolicyType.class); + Marshaller m = context.createMarshaller(); + m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); + m.marshal(policySetElement, os); + } catch (JAXBException e) { + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "XACMLPolicyWriter", "writePolicyFile failed"); + } + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + public static String changeFileNameInXmlWhenRenamePolicy(Path filename) { + + PolicyType policyType = null; + String extension = ""; + String domain = null; + String repository = "repository"; + if(filename.toString().contains("Config_")){ + domain = filename.toString().substring(filename.toString().indexOf(repository) + (repository.toString().length()+1), filename.toString().indexOf("Config_")); + }else if(filename.toString().contains("Action_")){ + domain = filename.toString().substring(filename.toString().indexOf(repository) + (repository.toString().length()+1), filename.toString().indexOf("Action_")); + }else if(filename.toString().contains("Decision_")){ + domain = filename.toString().substring(filename.toString().indexOf(repository) + (repository.toString().length()+1), filename.toString().indexOf("Decision_")); + } + if(domain.contains(File.separator)){ + domain = domain.replace(File.separator, "."); + } + try { + JAXBContext context = JAXBContext.newInstance(PolicyType.class); + Unmarshaller m = context.createUnmarshaller(); + JAXBElement policyElement = (JAXBElement) m.unmarshal(filename.toFile()); + policyType = policyElement.getValue(); + if (policyType != null) { + TargetType targetType = policyType.getTarget(); + List anyOfTypes = targetType.getAnyOf(); + for( Iterator anyOfIte = anyOfTypes.iterator(); anyOfIte.hasNext(); ){ + AnyOfType anyOfType = (AnyOfType) anyOfIte.next(); + List allOf = anyOfType.getAllOf(); + for( Iterator allOfIte = allOf.iterator(); allOfIte.hasNext(); ){ + AllOfType allOfType = (AllOfType) allOfIte.next(); + List match = allOfType.getMatch(); + for( Iterator matchIte = match.iterator(); matchIte.hasNext();) { + MatchType matchType = (MatchType) matchIte.next(); + if(matchType.getAttributeDesignator().getAttributeId().equals("PolicyName")){ + AttributeValueType attributeValueType = matchType.getAttributeValue(); + List contents = attributeValueType.getContent(); + if (contents != null && contents.size() > 0) { + String value = (String) contents.get(0); + String version = value; + version = version.substring(0, version.lastIndexOf(".")); + version = version.substring(version.lastIndexOf(".")); + if(filename.toString().contains("Config_")){ + value = value.substring(0, value.indexOf("Config_")); + }else{ + value = value.substring(0, value.indexOf("Decision_")); + } + String tmp = filename.getFileName()+""; + String newName = tmp.substring(0, tmp.lastIndexOf(".")); + attributeValueType.getContent().clear(); + attributeValueType.getContent().add(domain + newName + "." + "xml"); + } + } + } + } + } + if(filename.toString().contains("Config_") || filename.toString().contains("Action_")){ + List objects = policyType.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition(); + if (objects != null && objects.size() > 0) { + for (Iterator ite = objects.iterator(); ite.hasNext();) { + + RuleType ruleType = (RuleType ) ite.next(); + AdviceExpressionsType adviceExpressionsType = ruleType.getAdviceExpressions(); + if (adviceExpressionsType != null) { + List adviceExpressionTypes = adviceExpressionsType.getAdviceExpression(); + if (adviceExpressionTypes != null && adviceExpressionTypes.size() > 0) { + for (Iterator iterator = adviceExpressionTypes + .iterator(); iterator.hasNext();) { + AdviceExpressionType adviceExpressionType = (AdviceExpressionType) iterator + .next(); + if (adviceExpressionType.getAdviceId() != null && !adviceExpressionType.getAdviceId().equals("") && (adviceExpressionType.getAdviceId().equals("configID") + || adviceExpressionType.getAdviceId().equals("faultID") || adviceExpressionType.getAdviceId().equals("PMID")||adviceExpressionType.getAdviceId().equals("firewallConfigID") + || adviceExpressionType.getAdviceId().equals("MSID")) || adviceExpressionType.getAdviceId().equals("GocID")||adviceExpressionType.getAdviceId().equals("GocHPID")||adviceExpressionType.getAdviceId().equals("BRMSRAWID") + ||adviceExpressionType.getAdviceId().equals("BRMSPARAMID")|| adviceExpressionType.getAdviceId().equals("HPSuppID") || adviceExpressionType.getAdviceId().equals("HPFlapID") || adviceExpressionType.getAdviceId().equals("HPOverID")) + { + List attributeAssignmentExpressionTypes = adviceExpressionType.getAttributeAssignmentExpression(); + if (attributeAssignmentExpressionTypes != null && attributeAssignmentExpressionTypes.size() > 0) { + for (Iterator iterator2 = attributeAssignmentExpressionTypes + .iterator(); iterator2.hasNext();) { + AttributeAssignmentExpressionType attributeAssignmentExpressionType = (AttributeAssignmentExpressionType) iterator2 + .next(); + if (attributeAssignmentExpressionType.getAttributeId().equals("URLID")) { + JAXBElement attributeValueType = (JAXBElement) attributeAssignmentExpressionType.getExpression(); + AttributeValueType attributeValueType1 = attributeValueType.getValue(); + String configUrl = "$URL"; + String urlVal = (String) attributeValueType1.getContent().get(0); + String origExtension = urlVal.substring(urlVal.lastIndexOf('.')+1).trim(); + extension = origExtension; + attributeValueType1.getContent().clear(); + String txtFileName = filename.getFileName().toString(); + txtFileName = txtFileName.substring(0, txtFileName.lastIndexOf(".")+1) + origExtension; + txtFileName = configUrl+ File.separator + "Config" + File.separator + domain + txtFileName; + attributeValueType1.getContent().add(txtFileName); + } else if (attributeAssignmentExpressionType.getAttributeId().equals("PolicyName")) { + JAXBElement attributeValueType = (JAXBElement) attributeAssignmentExpressionType.getExpression(); + AttributeValueType attributeValueType1 = attributeValueType.getValue(); + List contents = attributeValueType1.getContent(); + if (contents != null && contents.size() > 0) { + String value = (String) contents.get(0); + String version = value; + version = version.substring(0, version.lastIndexOf(".")); + version = version.substring(version.lastIndexOf(".")); + value = value.substring(0, value.indexOf("Config_")); + String tmp = filename.getFileName()+""; + String newName = tmp.substring(0, tmp.lastIndexOf(".")); + attributeValueType1.getContent().clear(); + attributeValueType1.getContent().add(domain + newName + "." + "xml"); + } + + } + + } + } + } + } + } + } + } + if (objects != null && objects.size() > 0) { + for (Iterator ite1 = objects.iterator(); ite1.hasNext();) { + + RuleType ruleType1 = (RuleType ) ite1.next(); + ObligationExpressionsType obligationExpressionsType = ruleType1.getObligationExpressions(); + if (obligationExpressionsType != null) { + List obligationExpressionType = obligationExpressionsType.getObligationExpression(); + if (obligationExpressionType != null && obligationExpressionType.size() > 0) { + for (Iterator iterator = obligationExpressionType + .iterator(); iterator.hasNext();) { + ObligationExpressionType obligationExpressionTypes = (ObligationExpressionType) iterator + .next(); + if (obligationExpressionTypes.getObligationId() != null && !obligationExpressionTypes.getObligationId().equals("")) { + List attributeAssignmentExpressionTypes = obligationExpressionTypes.getAttributeAssignmentExpression(); + if (attributeAssignmentExpressionTypes != null && attributeAssignmentExpressionTypes.size() > 0) { + for (Iterator iterator2 = attributeAssignmentExpressionTypes + .iterator(); iterator2.hasNext();) { + AttributeAssignmentExpressionType attributeAssignmentExpressionType = (AttributeAssignmentExpressionType) iterator2 + .next(); + if (attributeAssignmentExpressionType.getAttributeId().equals("body")) { + JAXBElement attributeValueType = (JAXBElement) attributeAssignmentExpressionType.getExpression(); + AttributeValueType attributeValueType1 = attributeValueType.getValue(); + String configUrl = "$URL"; + String urlVal = (String) attributeValueType1.getContent().get(0); + String origExtension = urlVal.substring(urlVal.lastIndexOf('.')+1).trim(); + extension = "json"; + attributeValueType1.getContent().clear(); + String txtFileName = filename.getFileName().toString(); + txtFileName = txtFileName.substring(0, txtFileName.lastIndexOf(".")+1) + origExtension; + txtFileName = configUrl+ File.separator + "Action" + File.separator + domain + txtFileName; + attributeValueType1.getContent().add(txtFileName); + } + + } + } + + } + + } + } + } + } + } + } + } + writePolicyFile(filename, policyType); + } + }catch (JAXBException e) { + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "XACMLPolicyWriter", "writePolicyFile failed"); + } + + return extension; + } + +} diff --git a/ECOMP-XACML/src/main/resources/xacml.properties b/ECOMP-XACML/src/main/resources/xacml.properties new file mode 100644 index 000000000..9cdf680f2 --- /dev/null +++ b/ECOMP-XACML/src/main/resources/xacml.properties @@ -0,0 +1,46 @@ +### +# ============LICENSE_START======================================================= +# ECOMP-XACML +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +# Default XACML Properties File +# Standard API Factories +# +xacml.dataTypeFactory=org.openecomp.policy.xacml.std.StdDataTypeFactory +xacml.pdpEngineFactory=com.att.research.xacmlatt.pdp.ATTPDPEngineFactory +xacml.pepEngineFactory=org.openecomp.policy.xacml.std.pep.StdEngineFactory +xacml.pipFinderFactory=org.openecomp.policy.xacml.std.pip.StdPIPFinderFactory + +# If there is a standard set of PIPEngines: +# xacml.pip.engines=engine1,engine2,...,engineN +# engine1.classname=com.att.research.xacmlpip.OraclePIP +# engine1.prop1=foo +# engine1.prop2=bar +# ... +# engine2.classname=com.att.research.xacmlpip.ActiveDirectoryPIP +# ... + +# AT&T PDP Implementation Factories +# +xacml.att.evaluationContextFactory=com.att.research.xacmlatt.pdp.std.StdEvaluationContextFactory +xacml.att.combiningAlgorithmFactory=com.att.research.xacmlatt.pdp.std.StdCombiningAlgorithmFactory +xacml.att.functionDefinitionFactory=com.att.research.xacmlatt.pdp.std.StdFunctionDefinitionFactory +xacml.att.policyFinderFactory=com.att.research.xacmlatt.pdp.std.StdPolicyFinderFactory + +# If there is a standard policy for the engine: +# xacml.att.stdPolicyFinderFactory.rootPolicyFile=/etc/stdpolicyset.xml diff --git a/ECOMP-XACML/src/test/java/org/openecomp/policy/xacml/test/DOMResponseConformanceTest.java b/ECOMP-XACML/src/test/java/org/openecomp/policy/xacml/test/DOMResponseConformanceTest.java new file mode 100644 index 000000000..2083577c7 --- /dev/null +++ b/ECOMP-XACML/src/test/java/org/openecomp/policy/xacml/test/DOMResponseConformanceTest.java @@ -0,0 +1,196 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-XACML + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.xacml.test; + +import static org.junit.Assert.fail; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +import com.att.research.xacml.api.Response; +import com.att.research.xacml.std.dom.DOMResponse; + +/** + * Tests for handling the XML version of the XACML Response object. + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * Normally the Response is generated by the PDP and returned through the RESTful interface as JSON. + * Testing of the XML interface is minimal and not complete. + * + * + * + * + */ +public class DOMResponseConformanceTest { + + // where to find the conformance test XML files + private final String CONFORMANCE_DIRECTORY_PATH = "testsets/conformance/xacml3.0-ct-v.0.4"; + + // The request object output from each test conversion from JSON string + Response response; + + + + // Load the Conformance test responses into Response objects, generate the output XML for that Response and compare with the original files. + @Test + public void testDOMResponse() { + List filesInDirectory = null; + + File conformanceDirectory = null; + + File currentFile = null; + + try { + conformanceDirectory = new File(CONFORMANCE_DIRECTORY_PATH); + filesInDirectory = getRequestsInDirectory(conformanceDirectory); + } catch (Exception e) { + fail("Unable to set up Conformance tests for dir '" + conformanceDirectory.getAbsolutePath()+"' e="+ e); + } + + // run through each XML file + // - load the file from XML into an internal Response object + // - generate the XML representation from that Response object + // - reload the file into a String + // - compare the 2 XML strings + Response xmlResponse = null; + try { + for (File f : filesInDirectory) { + currentFile = f; + +//// This is a simple way to select just one file for debugging - comment out when not being used +//if ( ! f.getName().equals("IID302Response.xml")) { continue; } + +// during debugging it is helpful to know what file it is starting to work on +// System.out.println("starting file="+currentFile.getName()); + + + BufferedReader br = new BufferedReader(new FileReader(f)); + StringBuffer sb = new StringBuffer(); + String line; + while ((line = br.readLine()) != null) { + sb.append(line + "\n"); + } + br.close(); + + String xmlFromFile = sb.toString(); + + try { + // load XML into a Response object + xmlResponse = DOMResponse.load(xmlFromFile); + } catch (Exception e) { + // if XML does not load, just note it and continue with next file + System.out.println("XML file did not load: '" + f.getName() + " e=" + e); + continue; + } +//System.out.println(xmlFromFile); + + // create String version from the Response object + String xmlResponseString = DOMResponse.toString(xmlResponse, false); + + // Comparing the string directly to the String from the file is difficult. + // We can minimize the problems with newlines and whitespace, but we have other issues with how various object values are represented. + // For instance, and input double of "23.50" is output as "23.5" which is the same value but not identical strings. + // Therefore we take the XML output and use it to create a new Response object, then compare the two objects. + +//System.out.println(xmlResponseString); + Response reGeneratedResponse = DOMResponse.load(xmlResponseString); + + if ( ! xmlResponse.equals(reGeneratedResponse)) { + String normalizedFromFile = xmlFromFile.replaceAll("\\r|\\n", ""); + normalizedFromFile = normalizedFromFile.replaceAll("\\s+", " "); + normalizedFromFile = normalizedFromFile.replaceAll(">\\s*<", "><"); + System.out.println("File="+normalizedFromFile); + System.out.println("Gend="+ xmlResponseString); + + System.out.println(DOMResponse.toString(xmlResponse, true)); + + fail("Output string did not re-generate eqivilent object."); + } + +// // Normally whitespace is significant in XML. +// // However in this case we are generating an XML string for output and comparing it to a hand-made file. +// // The file may contain extra newlines or fewer spaces then our prettyPrinted output version. +// // Therefore we do the comparison on the un-prettyPrinted generated string. +// // To do this we have to remove the extra whitespace from the version read from the file. +// String normalizedFromFile = xmlFromFile.replaceAll("\\r|\\n", ""); +// normalizedFromFile = normalizedFromFile.replaceAll("\\s+", " "); +// normalizedFromFile = normalizedFromFile.replaceAll(">\\s*<", "><"); +// +// if ( ! xmlResponseString.equals(normalizedFromFile)) { +// System.out.println("file="+normalizedFromFile+"\ngend="+xmlResponseString); +// fail("file not same as generated string: " + f.getName()+ "\nFile="+xmlFromFile + "\nString="+xmlResponseString); +// } + + + } + + } catch (Exception e) { + fail ("Failed test with '" + currentFile.getName() + "', e=" + e); + } + + + } + + + + // + // HELPER to get list of all Request files in the given directory + // + + private List getRequestsInDirectory(File directory) { + List fileList = new ArrayList(); + + File[] fileArray = directory.listFiles(); + for (File f : fileArray) { + if (f.isDirectory()) { + List subDirList = getRequestsInDirectory(f); + fileList.addAll(subDirList); + } + if (f.getName().endsWith("Response.xml")) { + fileList.add(f); + } + } + return fileList; + + } + + +} + + +/* +Place to edit long strings output during tests + + + + + + + + +*/ diff --git a/ECOMP-XACML/src/test/java/org/openecomp/policy/xacml/test/DOMResponseTest.java b/ECOMP-XACML/src/test/java/org/openecomp/policy/xacml/test/DOMResponseTest.java new file mode 100644 index 000000000..5c27018d3 --- /dev/null +++ b/ECOMP-XACML/src/test/java/org/openecomp/policy/xacml/test/DOMResponseTest.java @@ -0,0 +1,2316 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-XACML + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.xacml.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import java.text.ParseException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + +import org.junit.Test; + +import com.att.research.xacml.api.Attribute; +import com.att.research.xacml.api.AttributeValue; +import com.att.research.xacml.api.Decision; +import com.att.research.xacml.api.Identifier; +import com.att.research.xacml.api.XACML3; +import com.att.research.xacml.std.IdentifierImpl; +import com.att.research.xacml.std.StdAttribute; +import com.att.research.xacml.std.StdAttributeCategory; +import com.att.research.xacml.std.StdAttributeValue; +import com.att.research.xacml.std.StdIdReference; +import com.att.research.xacml.std.StdMutableAdvice; +import com.att.research.xacml.std.StdMutableAttribute; +import com.att.research.xacml.std.StdMutableAttributeAssignment; +import com.att.research.xacml.std.StdMutableMissingAttributeDetail; +import com.att.research.xacml.std.StdMutableObligation; +import com.att.research.xacml.std.StdMutableResponse; +import com.att.research.xacml.std.StdMutableResult; +import com.att.research.xacml.std.StdMutableStatus; +import com.att.research.xacml.std.StdMutableStatusDetail; +import com.att.research.xacml.std.StdStatusCode; +import com.att.research.xacml.std.StdVersion; +import com.att.research.xacml.std.datatypes.DataTypes; +import com.att.research.xacml.std.datatypes.StringNamespaceContext; +import com.att.research.xacml.std.datatypes.XPathExpressionWrapper; +import com.att.research.xacml.std.dom.DOMResponse; +import com.att.research.xacml.std.dom.DOMStructureException; + +/** + * Test DOM XML Responses + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * This class was copied from the JSON tests. At this time only the first two methods have been revised to work with XML. + * The second method includes multiple instances of all possible fields and has been manually verified. + * The remaining methods have not been converted because: + * - "conversion" consists of replacing the JSON strings with XML + * - the replacement would consist of copying the XML from the JUnit output and doing a String replace + * - there would be little examination of the (long) XML strings, so their validity would be questionable + * so the benefit for the cost of doing that work is not clear. + * + * + */ +public class DOMResponseTest { + + String xmlResponse; + + StdMutableResponse response; + + StdMutableResult result; + + StdMutableStatus status; + + + // Note: Initially test responses without Obligations, Associated Advice, Attributes, or PolicyIdentifier + + + @Test + public void testEmptyAndDecisions() { + // null response + try { + xmlResponse = DOMResponse.toString(null, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + + // empty response (no Result object) + response = new StdMutableResponse(); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + + + // just decision, no status + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Permit", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // just status (empty), no decision + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + result.setStatus(status); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + + // just status (non-empty), no decision + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_OK); + result.setStatus(status); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + + + // test other decisions without Status + + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.DENY); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Deny", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.NOTAPPLICABLE); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("NotApplicable", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Indeterminate", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.INDETERMINATE_DENY); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Indeterminate{D}", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.INDETERMINATE_DENYPERMIT); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Indeterminate{DP}", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.INDETERMINATE_PERMIT); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Indeterminate{P}", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // test Multiple Decisions - success + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + response.add(result); + StdMutableResult result2 = new StdMutableResult(); + result2.setDecision(Decision.DENY); + response.add(result2); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("PermitDeny", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // test Multiple Decisions - one success and one error + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + response.add(result); + result2 = new StdMutableResult(); + result2.setDecision(Decision.INDETERMINATE); + response.add(result2); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("PermitIndeterminate", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + } + + + + + // Test with every field filled in with multiple values where appropriate + @Test + public void testAllFieldsResponse() { + + // fully-loaded multiple response + + StdMutableResponse response = new StdMutableResponse(); + // create a Status object + StdMutableStatus status = new StdMutableStatus(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); + status.setStatusMessage("some status message"); + StdMutableStatusDetail statusDetailIn = new StdMutableStatusDetail(); + StdMutableMissingAttributeDetail mad = new StdMutableMissingAttributeDetail(); + mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_STRING.getId(), "doh")); + mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_INTEGER.getId(), "5432")); + mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_STRING.getId(), "meh")); + mad.setAttributeId(XACML3.ID_ACTION_PURPOSE); + mad.setCategory(XACML3.ID_ATTRIBUTE_CATEGORY_ACTION); + mad.setDataTypeId(XACML3.ID_DATATYPE_STRING); + mad.setIssuer("an Issuer"); + statusDetailIn.addMissingAttributeDetail(mad); + status.setStatusDetail(statusDetailIn); + // create a single result object + StdMutableResult result = new StdMutableResult(status); + // set the decision + result.setDecision(Decision.INDETERMINATE); + // put the Result into the Response + response.add(result); + + + // create a new Result with a different Decision + status = new StdMutableStatus(StdStatusCode.STATUS_CODE_OK); + result = new StdMutableResult(status); + result.setDecision(Decision.DENY); + + StdMutableObligation obligation = new StdMutableObligation(); + obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "obligation-issuer1", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Bart"))); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "obligation-issuer2", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Ned"))); + result.addObligation(obligation); + obligation = new StdMutableObligation(); + obligation.setId(XACML3.ID_SUBJECT_CATEGORY_INTERMEDIARY_SUBJECT); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "obligation-issuer3", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Maggie"))); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "obligation-issuer4", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Homer"))); + result.addObligation(obligation); + + + StdMutableAdvice advice = new StdMutableAdvice(); + advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "advice-issuer1", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu"))); + advice.addAttributeAssignment(new StdMutableAttributeAssignment( + null, + XACML3.ID_SUBJECT, + "advice-issuerNoCategory", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Crusty"))); + result.addAdvice(advice); + + + response.add(result); + + + // create a new Result with a different Decision + // add Child/minor status codes within the main status + StdStatusCode childChildChildStatusCode = new StdStatusCode(new IdentifierImpl("childChildChildStatusCode")); + StdStatusCode childChildStatusCode = new StdStatusCode(new IdentifierImpl("childChildStatusCode"), childChildChildStatusCode); + StdStatusCode child1StatusCode = new StdStatusCode(new IdentifierImpl("child1StatusCode"), childChildStatusCode); + StdStatusCode statusCode = new StdStatusCode(XACML3.ID_STATUS_OK, child1StatusCode); + + status = new StdMutableStatus(statusCode); + + + result = new StdMutableResult(status); + result.setDecision(Decision.PERMIT); + + + + + // add attribute list in result + Identifier categoryIdentifier = new IdentifierImpl("firstCategory"); + Attribute[] attrList = { + new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true), + new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent2"), new StdAttributeValue(DataTypes.DT_YEARMONTHDURATION.getId(), "P10Y4M"), "BIssue", false), + new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent3"), new StdAttributeValue(DataTypes.DT_DOUBLE.getId(), 765.432), "CIssue", true), + new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent4"), new StdAttributeValue(DataTypes.DT_BOOLEAN.getId(), true), "DIssue", true), + new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent5"), new StdAttributeValue(DataTypes.DT_INTEGER.getId(), 4567), "EIssue", true), + new StdAttribute(categoryIdentifier, new IdentifierImpl("attrNoIssuer"), new StdAttributeValue(DataTypes.DT_INTEGER.getId(), 4567), null, true) }; + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, Arrays.asList(attrList))); + categoryIdentifier = new IdentifierImpl("secondCategory"); + Attribute[] secondAttrList = { + new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent12"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu2"), "AIssue2", true), + new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent22"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Abc2"), "BIssue2", false), + new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent32"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Der2"), "CIssue2", true) }; + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, Arrays.asList(secondAttrList))); + + + // add PolicyIdentifierList to result + StdIdReference policyIdentifier1 = null; + StdIdReference policyIdentifier2 = null; + StdIdReference policySetIdentifier1 = null; + StdIdReference policySetIdentifier2 = null; + try { + policyIdentifier1 = new StdIdReference(new IdentifierImpl("idRef1"), StdVersion.newInstance("1.2.3")); + policyIdentifier2 = new StdIdReference(new IdentifierImpl("idRef2_NoVersion")); + policySetIdentifier1 = new StdIdReference(new IdentifierImpl("idSetRef1"), StdVersion.newInstance("4.5.6.7.8.9.0")); + policySetIdentifier2 = new StdIdReference(new IdentifierImpl("idSetRef2_NoVersion")); + } catch (ParseException e1) { + fail("creating policyIds, e="+e1); + } + + result.addPolicyIdentifier(policyIdentifier1); + result.addPolicyIdentifier(policyIdentifier2); + + result.addPolicySetIdentifier(policySetIdentifier1); + result.addPolicySetIdentifier(policySetIdentifier2); + + response.add(result); + + // convert Response to XML + try { + xmlResponse = DOMResponse.toString(response, false); +//System.out.println(xmlResponse); +//System.out.println(DOMResponse.toString(response, true)); + assertEquals("Indeterminatesome status messagedoh5432mehDenyBartNedMaggieHomerApuCrustyPermitApu765.432true45674567Apu2Der2idRef1idRef2_NoVersionidSetRef1idSetRef2_NoVersion", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + } + + + + + // combinations of Status values with Decision values + @Test + public void testDecisionStatusMatch() { + // the tests in this method use different values and do not change structures, so we can re-use the objects + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + result.setStatus(status); + response.add(result); + + // StatusCode = OK + status.setStatusCode(StdStatusCode.STATUS_CODE_OK); + result.setDecision(Decision.PERMIT); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Permit", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + result.setDecision(Decision.DENY); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Deny", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + result.setDecision(Decision.NOTAPPLICABLE); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("NotApplicable", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + result.setDecision(Decision.INDETERMINATE); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + result.setDecision(Decision.INDETERMINATE_DENY); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + result.setDecision(Decision.INDETERMINATE_DENYPERMIT); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + result.setDecision(Decision.INDETERMINATE_PERMIT); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + + + + + + + // StatusCode = SyntaxError + status.setStatusCode(StdStatusCode.STATUS_CODE_SYNTAX_ERROR); + result.setDecision(Decision.PERMIT); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + result.setDecision(Decision.DENY); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + result.setDecision(Decision.NOTAPPLICABLE); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + result.setDecision(Decision.INDETERMINATE); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Indeterminate", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + result.setDecision(Decision.INDETERMINATE_DENY); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Indeterminate{D}", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + result.setDecision(Decision.INDETERMINATE_DENYPERMIT); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Indeterminate{DP}", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + result.setDecision(Decision.INDETERMINATE_PERMIT); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Indeterminate{P}", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // StatusCode = ProcessingError + status.setStatusCode(StdStatusCode.STATUS_CODE_PROCESSING_ERROR); + result.setDecision(Decision.PERMIT); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + result.setDecision(Decision.DENY); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + result.setDecision(Decision.NOTAPPLICABLE); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + result.setDecision(Decision.INDETERMINATE); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Indeterminate", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + result.setDecision(Decision.INDETERMINATE_DENY); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Indeterminate{D}", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + result.setDecision(Decision.INDETERMINATE_DENYPERMIT); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Indeterminate{DP}", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + result.setDecision(Decision.INDETERMINATE_PERMIT); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Indeterminate{P}", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + + // StatusCode = MissingAttribute + status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); + result.setDecision(Decision.PERMIT); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + result.setDecision(Decision.DENY); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + result.setDecision(Decision.NOTAPPLICABLE); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + result.setDecision(Decision.INDETERMINATE); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Indeterminate", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + result.setDecision(Decision.INDETERMINATE_DENY); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Indeterminate{D}", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + result.setDecision(Decision.INDETERMINATE_DENYPERMIT); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Indeterminate{DP}", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + result.setDecision(Decision.INDETERMINATE_PERMIT); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Indeterminate{P}", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + } + + + + + // tests related to Status and its components + @Test + public void testStatus() { + // Status with no StatusCode - error + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + result.setStatus(status); + result.setDecision(Decision.PERMIT); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + + // Status with StatusMessage when OK + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_OK); + status.setStatusMessage("I'm ok, you're ok"); + result.setStatus(status); + result.setDecision(Decision.PERMIT); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("PermitI'm ok, you're ok", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // Status with StatusDetail when OK + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_OK); + StdMutableStatusDetail statusDetail = new StdMutableStatusDetail(); + status.setStatusDetail(statusDetail); + result.setStatus(status); + result.setDecision(Decision.PERMIT); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + + // Status with StatusMessage when SyntaxError + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_SYNTAX_ERROR); + status.setStatusMessage("I'm ok, you're ok"); + result.setStatus(status); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("IndeterminateI'm ok, you're ok", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // Status with empty StatusDetail when SyntaxError + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_SYNTAX_ERROR); + statusDetail = new StdMutableStatusDetail(); + status.setStatusDetail(statusDetail); + result.setStatus(status); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + + + // Status with StatusMessage when ProcessingError + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_PROCESSING_ERROR); + status.setStatusMessage("I'm ok, you're ok"); + result.setStatus(status); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("IndeterminateI'm ok, you're ok", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // Status with empty StatusDetail when ProcessingError + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_PROCESSING_ERROR); + statusDetail = new StdMutableStatusDetail(); + status.setStatusDetail(statusDetail); + result.setStatus(status); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + + + // Status with StatusMessage when MissingAttribute + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); + status.setStatusMessage("I'm ok, you're ok"); + result.setStatus(status); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("IndeterminateI'm ok, you're ok", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // Status with empty StatusDetail when MissingAttribute + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); + statusDetail = new StdMutableStatusDetail(); + status.setStatusDetail(statusDetail); + result.setStatus(status); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Indeterminate", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + + // Status with StatusDetail with empty detail when MissingAttribute + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); + statusDetail = new StdMutableStatusDetail(); + StdMutableMissingAttributeDetail mad = new StdMutableMissingAttributeDetail(); + statusDetail.addMissingAttributeDetail(mad); + status.setStatusDetail(statusDetail); + result.setStatus(status); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + + // Status with StatusDetail with valid detail with no value when MissingAttribute + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); + statusDetail = new StdMutableStatusDetail(); + mad = new StdMutableMissingAttributeDetail(); + mad.setAttributeId(new IdentifierImpl("mad")); + mad.setCategory(XACML3.ID_ACTION); + mad.setDataTypeId(DataTypes.DT_STRING.getId()); + statusDetail.addMissingAttributeDetail(mad); + status.setStatusDetail(statusDetail); + result.setStatus(status); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Indeterminate", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // Status with StatusDetail with valid detail with value when MissingAttribute + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); + statusDetail = new StdMutableStatusDetail(); + mad = new StdMutableMissingAttributeDetail(); + mad.setAttributeId(new IdentifierImpl("mad")); + mad.setCategory(XACML3.ID_ACTION); + mad.setDataTypeId(DataTypes.DT_STRING.getId()); + mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_STRING.getId(), "meh")); + statusDetail.addMissingAttributeDetail(mad); + status.setStatusDetail(statusDetail); + result.setStatus(status); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Indeterminatemeh", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // Status with StatusDetail with array valid detail with value when MissingAttribute + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); + statusDetail = new StdMutableStatusDetail(); + mad = new StdMutableMissingAttributeDetail(); + mad.setAttributeId(new IdentifierImpl("mad")); + mad.setCategory(XACML3.ID_ACTION); + mad.setDataTypeId(DataTypes.DT_STRING.getId()); + mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_STRING.getId(), "meh")); + mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_STRING.getId(), "nu?")); + statusDetail.addMissingAttributeDetail(mad); + status.setStatusDetail(statusDetail); + result.setStatus(status); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Indeterminatemehnu?", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // Status with StatusDetail with valid detail with Integer value when MissingAttribute + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); + statusDetail = new StdMutableStatusDetail(); + mad = new StdMutableMissingAttributeDetail(); + mad.setAttributeId(new IdentifierImpl("mad")); + mad.setCategory(XACML3.ID_ACTION); + mad.setDataTypeId(DataTypes.DT_STRING.getId()); + mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_INTEGER.getId(), 1111)); + statusDetail.addMissingAttributeDetail(mad); + status.setStatusDetail(statusDetail); + result.setStatus(status); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Indeterminate1111", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // Status with StatusDetail with array valid detail with Integer value when MissingAttribute + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); + statusDetail = new StdMutableStatusDetail(); + mad = new StdMutableMissingAttributeDetail(); + mad.setAttributeId(new IdentifierImpl("mad")); + mad.setCategory(XACML3.ID_ACTION); + mad.setDataTypeId(DataTypes.DT_STRING.getId()); + mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_INTEGER.getId(), 1111)); + mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_INTEGER.getId(), 2222)); + statusDetail.addMissingAttributeDetail(mad); + status.setStatusDetail(statusDetail); + result.setStatus(status); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Indeterminate11112222", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + +// StringNamespaceContext snc = new StringNamespaceContext(); +// try { +// snc.add("defaultURI"); +// snc.add("md", "referenceForMD"); +// } catch (Exception e) { +// fail("unable to create NamespaceContext e="+e); +// } +// XPathExpressionWrapper xpathExpressionWrapper = new XPathExpressionWrapper(snc, "//md:record"); +// +//TODO - assume that we will never try to pass back an XPathExpression in a MissingAttributeDetail - it doesn't make sense and is unclear how to put into XML +// // Status with StatusDetail with valid detail with XPathExpression value when MissingAttribute +// response = new StdMutableResponse(); +// result = new StdMutableResult(); +// status = new StdMutableStatus(); +// status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); +// statusDetail = new StdMutableStatusDetail(); +// mad = new StdMutableMissingAttributeDetail(); +// mad.setAttributeId(new IdentifierImpl("mad")); +// mad.setCategory(XACML3.ID_ACTION); +// mad.setDataTypeId(DataTypes.DT_STRING.getId()); +// mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("xpathCategoryId"))); +// statusDetail.addMissingAttributeDetail(mad); +// status.setStatusDetail(statusDetail); +// result.setStatus(status); +// result.setDecision(Decision.INDETERMINATE); +// response.add(result); +// try { +// xmlResponse = DOMResponse.toString(response, false); +// assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"},\"StatusDetail\":\"1111urn:oasis:names:tc:xacml:1.0:actionmadhttp://www.w3.org/2001/XMLSchema#string\"},\"Decision\":\"Indeterminate\"}]}", xmlResponse); +// } catch (Exception e) { +// fail("operation failed, e="+e); +// } +// +// // Status with StatusDetail with array valid detail with XPathExpression value when MissingAttribute +// response = new StdMutableResponse(); +// result = new StdMutableResult(); +// status = new StdMutableStatus(); +// status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); +// statusDetail = new StdMutableStatusDetail(); +// mad = new StdMutableMissingAttributeDetail(); +// mad.setAttributeId(new IdentifierImpl("mad")); +// mad.setCategory(XACML3.ID_ACTION); +// mad.setDataTypeId(DataTypes.DT_STRING.getId()); +// mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("xpathCategoryId1"))); +// mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("xpathCategoryId2"))); +// statusDetail.addMissingAttributeDetail(mad); +// status.setStatusDetail(statusDetail); +// result.setStatus(status); +// result.setDecision(Decision.INDETERMINATE); +// response.add(result); +// try { +// xmlResponse = DOMResponse.toString(response, false); +// assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"},\"StatusDetail\":\"11112222urn:oasis:names:tc:xacml:1.0:actionmadhttp://www.w3.org/2001/XMLSchema#string\"},\"Decision\":\"Indeterminate\"}]}", xmlResponse); +// } catch (Exception e) { +// fail("operation failed, e="+e); +// } + +//TODO - try with other data types, esp XPathExpression + + // Status with StatusDetail with array valid detail with value when SyntaxError + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_SYNTAX_ERROR); + statusDetail = new StdMutableStatusDetail(); + mad = new StdMutableMissingAttributeDetail(); + mad.setAttributeId(new IdentifierImpl("mad")); + mad.setCategory(XACML3.ID_ACTION); + mad.setDataTypeId(DataTypes.DT_STRING.getId()); + mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_STRING.getId(), "meh")); + mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_STRING.getId(), "nu?")); + statusDetail.addMissingAttributeDetail(mad); + status.setStatusDetail(statusDetail); + result.setStatus(status); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + + // Status with StatusDetail with array valid detail with value when ProcessingError + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_PROCESSING_ERROR); + statusDetail = new StdMutableStatusDetail(); + mad = new StdMutableMissingAttributeDetail(); + mad.setAttributeId(new IdentifierImpl("mad")); + mad.setCategory(XACML3.ID_ACTION); + mad.setDataTypeId(DataTypes.DT_STRING.getId()); + mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_STRING.getId(), "meh")); + mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_STRING.getId(), "nu?")); + statusDetail.addMissingAttributeDetail(mad); + status.setStatusDetail(statusDetail); + result.setStatus(status); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + + + + // Status with nested child StatusCodes (child status containing child status containing...) + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + StdStatusCode child1StatusCode = new StdStatusCode(new IdentifierImpl("child1StatusCode")); + StdStatusCode statusCode = new StdStatusCode(XACML3.ID_STATUS_OK, child1StatusCode); + status = new StdMutableStatus(statusCode); + status.setStatusMessage("I'm ok, you're ok"); + result.setStatus(status); + result.setDecision(Decision.PERMIT); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("PermitI'm ok, you're ok", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + StdStatusCode childChildChildStatusCode = new StdStatusCode(new IdentifierImpl("childChildChildStatusCode")); + StdStatusCode childChildStatusCode = new StdStatusCode(new IdentifierImpl("childChildStatusCode"), childChildChildStatusCode); + child1StatusCode = new StdStatusCode(new IdentifierImpl("child1StatusCode"), childChildStatusCode); + statusCode = new StdStatusCode(XACML3.ID_STATUS_OK, child1StatusCode); + status = new StdMutableStatus(statusCode); + status.setStatusMessage("I'm ok, you're ok"); + result.setStatus(status); + result.setDecision(Decision.PERMIT); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("PermitI'm ok, you're ok", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + } + + + + @Test + public void testObligations() { + + // create an XPathExpression for use later + StringNamespaceContext snc = new StringNamespaceContext(); + try { + snc.add("defaultURI"); + snc.add("md", "referenceForMD"); + } catch (Exception e) { + fail("unable to create NamespaceContext e="+e); + } + XPathExpressionWrapper xpathExpressionWrapper = new XPathExpressionWrapper(snc, "//md:record"); + XPathExpressionWrapper xpathExpressionWrapper2 = new XPathExpressionWrapper(snc, "//md:hospital"); + + StdMutableObligation obligation; + + // test Obligation single decision no attributes + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + obligation = new StdMutableObligation(); + obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + result.addObligation(obligation); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Permit", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // obligation missing Id + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + obligation = new StdMutableObligation(); + result.addObligation(obligation); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + + + + // AttributeAssignment - with AttributeId, Value, Category, DataType, Issuer + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + obligation = new StdMutableObligation(); + obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "obligation-issuer1", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Bart"))); + result.addObligation(obligation); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("PermitBart", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // AttributeAssignment - with AttributeId, Value, no Category, DataType, Issuer + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + obligation = new StdMutableObligation(); + obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + null, + XACML3.ID_SUBJECT, + "obligation-issuer1", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Bart"))); + result.addObligation(obligation); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("PermitBart", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // AttributeAssignment - Missing AttributeId + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + obligation = new StdMutableObligation(); + obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + null, + "obligation-issuer1", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Bart"))); + result.addObligation(obligation); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + + // AttributeAssignment - Missing Value + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + obligation = new StdMutableObligation(); + obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "obligation-issuer1", + null)); + result.addObligation(obligation); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + + // AttributeAssignment - missing required DataType (Different than JSON where DataType is optional with default String) + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + obligation = new StdMutableObligation(); + obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "obligation-issuer1", + new StdAttributeValue(null, "Bart"))); + result.addObligation(obligation); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + + // AttributeAssignment - missing issuer + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + obligation = new StdMutableObligation(); + obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + null, + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Bart"))); + result.addObligation(obligation); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("PermitBart", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // AttributeAssignment - Integer type + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + obligation = new StdMutableObligation(); + obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + null, + new StdAttributeValue(DataTypes.DT_INTEGER.getId(), 1111))); + result.addObligation(obligation); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Permit1111", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // AttributeAssignment - XPathExpression type + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + obligation = new StdMutableObligation(); + obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + null, + new StdAttributeValue(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("SimpleXPathCategory")))); + result.addObligation(obligation); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Permit//md:record", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + + + // + // Technically arrays cannot occur in Obligations and Advice elements. The XML spec boils down to the following definition: + // + // value + // value + // : + // may have multiple elements. + // For Obligations and Advice we can simulate an array by having multiple AttributeAssignment elements with the same Category, Id and Issuer. + // + + + // AttributeAssignment - Multiple values with same Category and Id (one way of doing array) + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + obligation = new StdMutableObligation(); + obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "obligation-issuer1", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Bart"))); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "obligation-issuer1", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Lisa"))); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "obligation-issuer1", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Maggie"))); + result.addObligation(obligation); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("PermitBartLisaMaggie", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // AttributeAssignment - Multiple Integer values with same Category and Id (one way of doing array) + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + obligation = new StdMutableObligation(); + obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "obligation-issuer1", + new StdAttributeValue(DataTypes.DT_INTEGER.getId(), 1111))); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "obligation-issuer1", + new StdAttributeValue(DataTypes.DT_INTEGER.getId(), 2222))); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "obligation-issuer1", + new StdAttributeValue(DataTypes.DT_INTEGER.getId(), 3333))); + result.addObligation(obligation); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Permit111122223333", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // Multiple XPathExpression values with same Category and Id (one way of doing array) + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + obligation = new StdMutableObligation(); + obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + null, + new StdAttributeValue(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("SimpleXPathCategory")))); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + null, + new StdAttributeValue(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper2, new IdentifierImpl("SimpleXPathCategory")))); + result.addObligation(obligation); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Permit//md:record//md:hospital", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + } + + + + + @Test + public void testAdvice() { + + // create an XPathExpression for use later + StringNamespaceContext snc = new StringNamespaceContext(); + try { + snc.add("defaultURI"); + snc.add("md", "referenceForMD"); + } catch (Exception e) { + fail("unable to create NamespaceContext e="+e); + } + XPathExpressionWrapper xpathExpressionWrapper = new XPathExpressionWrapper(snc, "//md:record"); + XPathExpressionWrapper xpathExpressionWrapper2 = new XPathExpressionWrapper(snc, "//md:hospital"); + + StdMutableAdvice Advice; + + // test Advice single decision no attributes + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + Advice = new StdMutableAdvice(); + Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + result.addAdvice(Advice); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Permit", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // Advice missing Id + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + Advice = new StdMutableAdvice(); + result.addAdvice(Advice); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + + + + // AttributeAssignment - with AttributeId, Value, Category, DataType, Issuer + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + Advice = new StdMutableAdvice(); + Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "Advice-issuer1", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Bart"))); + result.addAdvice(Advice); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("PermitBart", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // AttributeAssignment - with AttributeId, Value, no Category, DataType, Issuer + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + Advice = new StdMutableAdvice(); + Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + null, + XACML3.ID_SUBJECT, + "Advice-issuer1", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Bart"))); + result.addAdvice(Advice); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("PermitBart", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // AttributeAssignment - Missing AttributeId + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + Advice = new StdMutableAdvice(); + Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + null, + "Advice-issuer1", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Bart"))); + result.addAdvice(Advice); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + + // AttributeAssignment - Missing Value + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + Advice = new StdMutableAdvice(); + Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "Advice-issuer1", + null)); + result.addAdvice(Advice); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + + // AttributeAssignment - missing Required DataType (Different than JSON where DataType is optional with default String) + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + Advice = new StdMutableAdvice(); + Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "Advice-issuer1", + new StdAttributeValue(null, "Bart"))); + result.addAdvice(Advice); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + + // AttributeAssignment - missing issuer + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + Advice = new StdMutableAdvice(); + Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + null, + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Bart"))); + result.addAdvice(Advice); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("PermitBart", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // AttributeAssignment - Integer type + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + Advice = new StdMutableAdvice(); + Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + null, + new StdAttributeValue(DataTypes.DT_INTEGER.getId(), 1111))); + result.addAdvice(Advice); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Permit1111", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // AttributeAssignment - XPathExpression type + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + Advice = new StdMutableAdvice(); + Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + null, + new StdAttributeValue(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("SimpleXPathCategory")))); + result.addAdvice(Advice); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Permit//md:record", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + + + // + // Technically arrays cannot occur in Obligations and Advice elements. The XML spec boils down to the following definition: + // + // value + // value + // : + // may have multiple elements. + // For Obligations and Advice we can simulate an array by having multiple AttributeAssignment elements with the same Category, Id and Issuer. + // + + // AttributeAssignment - Multiple values with same Category and Id (one way of doing array) + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + Advice = new StdMutableAdvice(); + Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "Advice-issuer1", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Bart"))); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "Advice-issuer1", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Lisa"))); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "Advice-issuer1", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Maggie"))); + result.addAdvice(Advice); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("PermitBartLisaMaggie", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // AttributeAssignment - Multiple Integer values with same Category and Id (one way of doing array) + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + Advice = new StdMutableAdvice(); + Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "Advice-issuer1", + new StdAttributeValue(DataTypes.DT_INTEGER.getId(), 1111))); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "Advice-issuer1", + new StdAttributeValue(DataTypes.DT_INTEGER.getId(), 2222))); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "Advice-issuer1", + new StdAttributeValue(DataTypes.DT_INTEGER.getId(), 3333))); + result.addAdvice(Advice); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Permit111122223333", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // Multiple XPathExpression values with same Category and Id (one way of doing array) + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + Advice = new StdMutableAdvice(); + Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + null, + new StdAttributeValue(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("SimpleXPathCategory")))); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + null, + new StdAttributeValue(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper2, new IdentifierImpl("SimpleXPathCategory")))); + result.addAdvice(Advice); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Permit//md:record//md:hospital", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + } + + + + + + + + + + + // Attributes tests + @Test + public void testAttributes() { + + // create an XPathExpression for use later + StringNamespaceContext snc = new StringNamespaceContext(); + try { + snc.add("defaultURI"); + snc.add("md", "referenceForMD"); + } catch (Exception e) { + fail("unable to create NamespaceContext e="+e); + } + XPathExpressionWrapper xpathExpressionWrapper = new XPathExpressionWrapper(snc, "//md:record"); + + + Identifier categoryIdentifier; + List attrList = new ArrayList(); + StdMutableAttribute mutableAttribute; + + // Attr list with no entries + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Permit", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // one Attribute + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true)); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("PermitApu", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // multiple attributes + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent2"), new StdAttributeValue(DataTypes.DT_YEARMONTHDURATION.getId(), "P10Y4M"), "BIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent3"), new StdAttributeValue(DataTypes.DT_DOUBLE.getId(), 765.432), "CIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent4"), new StdAttributeValue(DataTypes.DT_BOOLEAN.getId(), true), "DIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent5"), new StdAttributeValue(DataTypes.DT_INTEGER.getId(), 4567), "EIssue", true)); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("PermitApuP10Y4M765.432true4567", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // IncludeInResult=false/true + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", false)); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Permit", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // Missing AttributeId (mandatory) + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + attrList.add(new StdAttribute(categoryIdentifier, null, new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true)); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + + // Missing mandatory Value + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), null), "AIssue", true)); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + + // Missing optional Issuer + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu"), null, true)); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("PermitApu", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // missing required DataType (different from JSON where DataType is optional and assumed to be String) + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(null, "Apu"), "AIssue", true)); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + + // same id, same type different issuer + // (This is not an array of values because Issuer is different) + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Bart"), "BIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Simpson"), "CIssue", true)); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("PermitApuBartSimpson", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // same id, same type same issuer + // (This is an array of values) + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Bart"), "AIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Simpson"), "AIssue", true)); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("PermitApuBartSimpson", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // same Id, different types, same issuer + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_YEARMONTHDURATION.getId(), "P10Y4M"), "AIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_DOUBLE.getId(), 765.432), "AIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_BOOLEAN.getId(), true), "AIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_INTEGER.getId(), 4567), "AIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_INTEGER.getId(), 4567), "AIssue", true)); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("PermitApuP10Y4M765.432true45674567", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // same Id, different types, different issuer + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_YEARMONTHDURATION.getId(), "P10Y4M"), "BIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_DOUBLE.getId(), 765.432), "CIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_BOOLEAN.getId(), true), "DIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_INTEGER.getId(), 4567), "EIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_INTEGER.getId(), 4567), null, true)); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("PermitApuP10Y4M765.432true45674567", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // different Id, different types, same issuer + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent2"), new StdAttributeValue(DataTypes.DT_YEARMONTHDURATION.getId(), "AIssue"), "BIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent3"), new StdAttributeValue(DataTypes.DT_DOUBLE.getId(), 765.432), "AIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent4"), new StdAttributeValue(DataTypes.DT_BOOLEAN.getId(), true), "AIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent5"), new StdAttributeValue(DataTypes.DT_INTEGER.getId(), 4567), "AIssue", true)); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("PermitApuAIssue765.432true4567", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // one Attribute of type XPathExpression (the only complex data type) + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("xpathCategory")), "AIssue", true)); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Permit//md:record", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // multiple sets of values + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent2"), new StdAttributeValue(DataTypes.DT_YEARMONTHDURATION.getId(), "P10Y4M"), "BIssue", false)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent3"), new StdAttributeValue(DataTypes.DT_DOUBLE.getId(), 765.432), "CIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent4"), new StdAttributeValue(DataTypes.DT_BOOLEAN.getId(), true), "DIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent5"), new StdAttributeValue(DataTypes.DT_INTEGER.getId(), 4567), "EIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrNoIssuer"), new StdAttributeValue(DataTypes.DT_INTEGER.getId(), 4567), null, true)); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + categoryIdentifier = new IdentifierImpl("secondCategory"); + Attribute[] secondAttrList = { + new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent12"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu2"), "AIssue2", true), + new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent22"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Abc2"), "BIssue2", false), + new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent32"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Der2"), "CIssue2", true) }; + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, Arrays.asList(secondAttrList))); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("PermitApu765.432true45674567Apu2Der2", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // array of values - same type + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + attrList.clear(); + categoryIdentifier = new IdentifierImpl("firstCategory"); + mutableAttribute = new StdMutableAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), (Collection>)null, "AIssue", true); + + mutableAttribute.addValue(new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu")); + mutableAttribute.addValue(new StdAttributeValue(DataTypes.DT_STRING.getId(), "Bart")); + mutableAttribute.addValue(new StdAttributeValue(DataTypes.DT_STRING.getId(), "Homer")); + mutableAttribute.addValue(new StdAttributeValue(DataTypes.DT_STRING.getId(), "Ned")); + + attrList.add(mutableAttribute); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("PermitApuBartHomerNed", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // array of values - compatible different types + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + attrList.clear(); + categoryIdentifier = new IdentifierImpl("firstCategory"); + mutableAttribute = new StdMutableAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), (Collection>)null, "AIssue", true); + + mutableAttribute.addValue(new StdAttributeValue(DataTypes.DT_INTEGER.getId(), 4567)); + mutableAttribute.addValue(new StdAttributeValue(DataTypes.DT_DOUBLE.getId(), 765.432)); + mutableAttribute.addValue(new StdAttributeValue(DataTypes.DT_INTEGER.getId(), 4567)); + attrList.add(mutableAttribute); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("Permit4567765.4324567", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // array of values - incompatible different types (Different from JSON because these are not part of an array in XML, just separate values) + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + attrList.clear(); + categoryIdentifier = new IdentifierImpl("firstCategory"); + mutableAttribute = new StdMutableAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), (Collection>)null, "AIssue", true); + + mutableAttribute.addValue(new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu")); + mutableAttribute.addValue(new StdAttributeValue(DataTypes.DT_YEARMONTHDURATION.getId(), "P10Y4M")); + mutableAttribute.addValue(new StdAttributeValue(DataTypes.DT_DOUBLE.getId(), 765.432)); + mutableAttribute.addValue(new StdAttributeValue(DataTypes.DT_BOOLEAN.getId(), true)); + mutableAttribute.addValue(new StdAttributeValue(DataTypes.DT_INTEGER.getId(), 4567)); + mutableAttribute.addValue(new StdAttributeValue(DataTypes.DT_INTEGER.getId(), 4567)); + attrList.add(mutableAttribute); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("PermitApuP10Y4M765.432true45674567", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + } + + + + + + // PolicyIdentifier tests + @Test + public void testPolicyIdentifier() { + + StdIdReference policyIdentifier1 = null; + StdIdReference policyIdentifier2 = null; + StdIdReference policySetIdentifier1 = null; + StdIdReference policySetIdentifier2 = null; + + // multiple PolicyIdentifiers of both types + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + try { + policyIdentifier1 = new StdIdReference(new IdentifierImpl("idRef1"), StdVersion.newInstance("1.2.3")); + policyIdentifier2 = new StdIdReference(new IdentifierImpl("idRef2_NoVersion")); + policySetIdentifier1 = new StdIdReference(new IdentifierImpl("idSetRef1"), StdVersion.newInstance("4.5.6.7.8.9.0")); + policySetIdentifier2 = new StdIdReference(new IdentifierImpl("idSetRef2_NoVersion")); + } catch (ParseException e1) { + fail("creating policyIds, e="+e1); + } + result.addPolicyIdentifier(policyIdentifier1); + result.addPolicyIdentifier(policyIdentifier2); + result.addPolicySetIdentifier(policySetIdentifier1); + result.addPolicySetIdentifier(policySetIdentifier2); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("PermitidRef1idRef2_NoVersionidSetRef1idSetRef2_NoVersion", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // PolicyIdentifier exists but has no IdReferences + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + policyIdentifier1 = null; + result.addPolicyIdentifier(policyIdentifier1); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + + // PolicySetIdentifier exists but has not IdReferences + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + policySetIdentifier1 = null; + result.addPolicyIdentifier(policySetIdentifier1); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (DOMStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from object to XML: " + e); + } + + // PolicyIdentifier with PolicyIdReference and no PolicySetIdReference + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + try { + policyIdentifier1 = new StdIdReference(new IdentifierImpl("idRef1"), StdVersion.newInstance("1.2.3")); + } catch (ParseException e1) { + fail("creating policyIds, e="+e1); + } + result.addPolicyIdentifier(policyIdentifier1); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("PermitidRef1", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + + // PolicyIdentifier with no PolicyIdReference and with PolicySetIdReference + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + try { + policySetIdentifier1 = new StdIdReference(new IdentifierImpl("idSetRef1"), StdVersion.newInstance("4.5.6.7.8.9.0")); + } catch (ParseException e1) { + fail("creating policyIds, e="+e1); + } + result.addPolicySetIdentifier(policySetIdentifier1); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("PermitidSetRef1", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // IdReferences without version + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + + policyIdentifier1 = new StdIdReference(new IdentifierImpl("idRef1"), null); + policyIdentifier2 = new StdIdReference(new IdentifierImpl("idRef2_NoVersion")); + policySetIdentifier1 = new StdIdReference(new IdentifierImpl("idSetRef1")); + policySetIdentifier2 = new StdIdReference(new IdentifierImpl("idSetRef2_NoVersion")); + + result.addPolicyIdentifier(policyIdentifier1); + result.addPolicyIdentifier(policyIdentifier2); + result.addPolicySetIdentifier(policySetIdentifier1); + result.addPolicySetIdentifier(policySetIdentifier2); + response.add(result); + try { + xmlResponse = DOMResponse.toString(response, false); + assertEquals("PermitidRef1idRef2_NoVersionidSetRef1idSetRef2_NoVersion", xmlResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + } + + +//TODO - the XML spec implies that the Result Attributes may include the Content (It is part of the UML) + + + // test indentation??? + + +} + + +/* +Place to edit long strings ouput from tests + + +Expected +Permit +Permit +Actual + + + + */ + + + + + + + + + + + + + diff --git a/ECOMP-XACML/src/test/java/org/openecomp/policy/xacml/test/TestAnnotation.java b/ECOMP-XACML/src/test/java/org/openecomp/policy/xacml/test/TestAnnotation.java new file mode 100644 index 000000000..c5dda8a91 --- /dev/null +++ b/ECOMP-XACML/src/test/java/org/openecomp/policy/xacml/test/TestAnnotation.java @@ -0,0 +1,239 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-XACML + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.xacml.test; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URI; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Arrays; +import java.util.Calendar; +import java.util.Collection; +import java.util.Date; +import java.util.TimeZone; + +import org.apache.commons.cli.ParseException; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import com.att.research.xacml.api.DataTypeException; +import com.att.research.xacml.api.Response; +import com.att.research.xacml.std.annotations.RequestParser; +import com.att.research.xacml.std.annotations.XACMLAction; +import com.att.research.xacml.std.annotations.XACMLAttribute; +import com.att.research.xacml.std.annotations.XACMLEnvironment; +import com.att.research.xacml.std.annotations.XACMLMultiRequest; +import com.att.research.xacml.std.annotations.XACMLRequest; +import com.att.research.xacml.std.annotations.XACMLRequestReference; +import com.att.research.xacml.std.annotations.XACMLResource; +import com.att.research.xacml.std.annotations.XACMLSubject; +import com.att.research.xacml.std.datatypes.HexBinary; +import com.att.research.xacml.std.datatypes.IPAddress; +import com.att.research.xacml.std.datatypes.IPv4Address; +import com.att.research.xacml.std.datatypes.ISO8601DateTime; +import com.att.research.xacml.std.datatypes.ISO8601Time; +import com.att.research.xacml.util.FactoryException; + +/** + * This example application shows how to use annotations for Java classes to create requests to send to the + * engine. + * + * + */ +public class TestAnnotation extends TestBase { + private static final Log logger = LogFactory.getLog(TestAnnotation.class); + + private int num; + + /** + * This is a sample class that uses annotations. In addition to demonstrating how to use XACML annotations, + * it also demonstrates the various Java objects that can be used and how the request parser will + * resolve each object's datatype. + * + * + */ + @XACMLRequest(ReturnPolicyIdList=true) + public class MyRequestAttributes { + + public MyRequestAttributes(String user, String action, String resource) { + this.userID = user; + this.action = action; + this.resource = resource; + this.today = new Date(); + this.yesterday = Calendar.getInstance(); + this.yesterday.add(Calendar.DAY_OF_MONTH, -1); + } + + @XACMLSubject(includeInResults=true) + String userID; + + @XACMLSubject(attributeId="urn:oasis:names:tc:xacml:1.0:subject:subject-id-qualifier") + boolean admin = false; + + @XACMLSubject(attributeId="urn:oasis:names:tc:xacml:1.0:subject:key-info", issuer="com:foo:security") + HexBinary publicKey = new HexBinary(new byte[] {'1', '0'}); + + @XACMLSubject(attributeId="urn:oasis:names:tc:xacml:1.0:subject:authentication-time") + ISO8601Time authenticationTime = new ISO8601Time(8, 0, 0, 0); + + /** + * Here our base object is "Object", but it is reflected as a Java "String". The parser + * will then use the XACML http://www.w3.org/2001/XMLSchema#string as the datatype. + */ + @XACMLSubject(attributeId="urn:oasis:names:tc:xacml:1.0:subject:authentication-method") + Object authenticationMethod = new String("RSA Public Key"); + + /** + * Here our base object is "String", but we use the annotation for datatype to clarify + * that the real XACML data type is http://www.w3.org/2001/XMLSchema#time. The parser will + * use the data type factory to convert the "String" to a "ISO8601Time" Java object. + */ + @XACMLSubject(attributeId="urn:oasis:names:tc:xacml:1.0:subject:request-time", datatype="http://www.w3.org/2001/XMLSchema#time") + String requestTime = new String("13:20:00-05:00"); + + @XACMLSubject(attributeId="urn:oasis:names:tc:xacml:1.0:subject:session-start-time") + ISO8601DateTime sessionStart = new ISO8601DateTime(TimeZone.getDefault().getID(), 2014, 1, 1, 10, 0, 0, 0); + + @XACMLSubject(attributeId="urn:oasis:names:tc:xacml:3.0:subject:authn-locality:ip-address") + IPAddress ip = new IPv4Address(new short[] {123, 134, 156, 255 }, null, null); + + @XACMLSubject(attributeId="urn:oasis:names:tc:xacml:3.0:subject:authn-locality:dns-name") + String dnsName = "localhost"; + + @XACMLAction() + String action; + + @XACMLAction(attributeId="urn:oasis:names:tc:xacml:1.0:action:implied-action") + long impliedAction; + + @XACMLResource() + String resource; + + @XACMLEnvironment() + Date today; + + @XACMLEnvironment() + Calendar yesterday; + + /** + * This field demonstrates how the parser can detect collections and build a bag of values. + */ + @XACMLAttribute(attributeId="foo:bar:attribute") + Collection fooBar = Arrays.asList(2.5, 3.5); + + /** + * The XACMLAttribute annotation allows one to specify all the + */ + @XACMLAttribute(category="foo:bar:category", attributeId="foo:bar:attribute2") + double fooBar2 = 3.999; + + /** + * This field demonstrates how the parser can detect arrays and build a bag of values. + */ + @XACMLAttribute(category="foo:bar:category", attributeId="foo:bar:attribute:many") + URI[] fooBarMany = new URI[] {URI.create("file://opt/app/test"), URI.create("https://localhost:8443/")}; + + }; + + @XACMLRequest( + Defaults="http://www.w3.org/TR/1999/Rec-xpath-19991116", + multiRequest=@XACMLMultiRequest(values={ + @XACMLRequestReference(values={"subject1", "action", "resource"}), + @XACMLRequestReference(values={"subject2", "action", "resource"})}) + ) + public class MyMultiRequestAttributes { + + @XACMLSubject(id="subject1") + String userID1 = "John"; + + @XACMLSubject(id="subject2") + String userID2 = "Ringo"; + + @XACMLAction(id="action") + String action = "access"; + + @XACMLResource(id="resource") + String resource = "www.mywebsite.com"; + } + + public TestAnnotation(String[] args) throws MalformedURLException, ParseException, HelpException { + super(args); + } + + @Override + public void run() throws IOException, FactoryException { + // + // We are not going to iterate any existing request files. So we will override + // any TestBase code that assumes there are request files present. + // + // + // Configure ourselves + // + this.configure(); + // + // Cycle through creating a few objects + // + this.num = 0; + this.doRequest(new MyRequestAttributes("John", "access", "www.mywebsite.com")); + this.num++; + this.doRequest(new MyRequestAttributes("Ringo", "access", "www.mywebsite.com")); + this.num++; + this.doRequest(new MyMultiRequestAttributes()); + this.num++; + } + + private void doRequest(Object info) { + try { + Response response = this.callPDP(RequestParser.parseRequest(info)); + Path resultFile; + if (this.output != null) { + resultFile = Paths.get(this.output.toString(), "Response." + String.format("%03d", this.num) + ".json"); + } else { + resultFile = Paths.get(this.directory, "results", "Response." + String.format("%03d", this.num) + ".json"); + } + // + // Write the response to the result file + // + logger.info("Response is: " + response.toString()); + if (resultFile != null) { + Files.write(resultFile, response.toString().getBytes()); + } + } catch (IllegalArgumentException | IllegalAccessException | DataTypeException | IOException e) { + logger.error(e); + e.printStackTrace(); + } + } + + public static void main(String[] args) { + try { + new TestAnnotation(args).run(); + } catch (ParseException | IOException | FactoryException e) { + logger.error(e); + } catch (HelpException e) { + // + // ignore this, its thrown just to exit the application + // after dumping help to stdout. + // + } + } +} diff --git a/ECOMP-XACML/src/test/java/org/openecomp/policy/xacml/test/TestBase.java b/ECOMP-XACML/src/test/java/org/openecomp/policy/xacml/test/TestBase.java new file mode 100644 index 000000000..8f757ab59 --- /dev/null +++ b/ECOMP-XACML/src/test/java/org/openecomp/policy/xacml/test/TestBase.java @@ -0,0 +1,1082 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-XACML + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.xacml.test; + +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.URL; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.GnuParser; +import org.apache.commons.cli.HelpFormatter; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.ParseException; +import org.apache.commons.io.IOUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.http.entity.ContentType; + +import com.att.research.xacml.api.AttributeValue; +import com.att.research.xacml.api.DataType; +import com.att.research.xacml.api.DataTypeException; +import com.att.research.xacml.api.DataTypeFactory; +import com.att.research.xacml.api.Decision; +import com.att.research.xacml.api.Identifier; +import com.att.research.xacml.api.Request; +import com.att.research.xacml.api.RequestAttributes; +import com.att.research.xacml.api.Response; +import com.att.research.xacml.api.Result; +import com.att.research.xacml.api.pdp.PDPEngine; +import com.att.research.xacml.api.pdp.PDPEngineFactory; +import com.att.research.xacml.api.pdp.PDPException; +import com.att.research.xacml.api.pep.PEPException; +import com.att.research.xacml.std.IdentifierImpl; +import com.att.research.xacml.std.StdAttributeValue; +import com.att.research.xacml.std.StdMutableAttribute; +import com.att.research.xacml.std.StdMutableRequest; +import com.att.research.xacml.std.StdMutableRequestAttributes; +import com.att.research.xacml.std.dom.DOMRequest; +import com.att.research.xacml.std.dom.DOMResponse; +import com.att.research.xacml.std.dom.DOMStructureException; +import com.att.research.xacml.std.json.JSONRequest; +import com.att.research.xacml.std.json.JSONResponse; +import com.att.research.xacml.std.json.JSONStructureException; +import com.att.research.xacml.util.FactoryException; +import com.att.research.xacml.util.XACMLProperties; +import com.google.common.base.Splitter; +import com.google.common.collect.Lists; + +/** + * This is a base class for setting up a test environment. Using properties files, it contains the + * necessary information for + * 1. defining and providing attributes + * 2. defining and instantiating the PDP engine + * 3. creating PEP requests and calling the PDP engine + * + * + */ +public class TestBase extends SimpleFileVisitor { + private static final Log logger = LogFactory.getLog(TestBase.class); + + public class HelpException extends Exception { + private static final long serialVersionUID = 1L; + + } + + /** + * This private class holds information for properties defined for attribute + * generation. The user can configure the properties file such that attributes + * can be automatically generated and added into each request. + * + * + */ + class Generator { + Path file; + InputStream is; + BufferedReader reader; + List attributes = new ArrayList(); + + public Generator(Path path) { + this.file = path; + } + + /** + * read - reads in the next line of data + * + * @return String - a line from the csv containing attribute data + */ + public String read() { + String str = null; + if (is == null) { + try { + is = Files.newInputStream(file); + } catch (IOException e) { + logger.error(e); + return null; + } + } + if (reader == null) { + reader = new BufferedReader(new InputStreamReader(this.is)); + } + try { + str = reader.readLine(); + if (str == null) { + // + // No more strings, close up + // + this.close(); + } + if (logger.isDebugEnabled()) { + logger.debug(str); + } + } catch (IOException e) { + logger.error(e); + } + return str; + } + + public void close() { + if (this.reader != null) { + try { + this.reader.close(); + } catch (IOException idontcare) { + } finally { + this.reader = null; + this.is = null; + } + } + } + + } + + public static final String PROP_GENERATOR = "xacml.attribute.generator"; + + public static final String OPTION_HELP = "help"; + public static final String OPTION_TESTDIR = "dir"; + public static final String OPTION_TESTREST = "rest"; + public static final String OPTION_TESTURL = "url"; + public static final String OPTION_TESTOUTPUT = "output"; + public static final String OPTION_LOOP = "loop"; + public static final String OPTION_TESTNUMBERS = "testNumbers"; + + public static final String DEFAULT_RESTURL = "https://localhost:8080/pdp/"; // Modified for test purpose. Port no. 8443 to 8080 + + public static Options options = new Options(); + static { + options.addOption(new Option(OPTION_HELP, false, "Prints help.")); + options.addOption(new Option(OPTION_TESTDIR, true, "Directory path where all the test properties and data are located.")); + options.addOption(new Option(OPTION_TESTREST, false, "Test against RESTful PDP.")); + options.addOption(new Option(OPTION_TESTURL, true, "URL to the RESTful PDP. Default is " + DEFAULT_RESTURL)); + options.addOption(new Option(OPTION_TESTOUTPUT, true, "Specify a different location for dumping responses.")); + options.addOption(new Option(OPTION_LOOP, true, "Number of times to loop through the tests. Default is 1. A value of -1 runs indefinitely.")); + options.addOption(new Option(OPTION_TESTNUMBERS, true, "Comma-separated list of numbers found in the names of the test files to be run. Numbers must exactly match the file name, e.g. '02'. Used to limit testing to specific set of tests.")); + } + + protected String directory = null; + protected Path output = null; + protected boolean isREST; + protected URL restURL = null; + protected int loop = 1; + protected PDPEngine engine = null; + protected List generators = new ArrayList(); + protected static DataTypeFactory dataTypeFactory = null; + + private long permits = 0; + private long denies = 0; + private long notapplicables = 0; + private long indeterminates = 0; + + private long expectedPermits = 0; + private long expectedDenies = 0; + private long expectedNotApplicables = 0; + private long expectedIndeterminates = 0; + + private long generatedpermits = 0; + private long generateddenies = 0; + private long generatednotapplicables = 0; + private long generatedindeterminates = 0; + + private long responseMatches = 0; + private long responseNotMatches = 0; + + private String[] testNumbersArray = null; + + protected final Pattern pattern = Pattern.compile("Request[.]\\d+[.](Permit|Deny|NA|Indeterminate|Generate|Unknown)\\.(json|xml)"); + + public static boolean isJSON(Path file) { + return file.toString().endsWith(".json"); + } + + public static boolean isXML(Path file) { + return file.toString().endsWith(".xml"); + } + + public TestBase(String[] args) throws ParseException, MalformedURLException, HelpException { + // + // Finish Initialization + // + this.restURL = new URL(DEFAULT_RESTURL); + // + // Parse arguments + // + this.parseCommands(args); + } + + /** + * Parse in the command line arguments that the following parameters: + * + * @param args - command line arguments + * @throws ParseException + * @throws MalformedURLException + * @throws HelpException + */ + protected void parseCommands(String[] args) throws ParseException, MalformedURLException, HelpException { + // + // Parse the command line options + // + CommandLine cl; + cl = new GnuParser().parse(options, args); + // + // Check for what we have + // + if (cl.hasOption(OPTION_HELP)) { + new HelpFormatter().printHelp("Usage: -dir testdirectory OPTIONS", + options); + throw new HelpException(); + } + if (cl.hasOption(OPTION_TESTDIR)) { + this.directory = cl.getOptionValue(OPTION_TESTDIR); + } else { + throw new IllegalArgumentException("You must specify a test directory. -dir path/to/some/where"); + } + if (cl.hasOption(OPTION_TESTREST)) { + this.isREST = true; + } else { + this.isREST = false; + } + if (cl.hasOption(OPTION_TESTURL)) { + this.restURL = new URL(cl.getOptionValue(OPTION_TESTURL)); + } + if (cl.hasOption(OPTION_TESTOUTPUT)) { + this.output = Paths.get(cl.getOptionValue(OPTION_TESTOUTPUT)); + } else { + this.output = Paths.get(this.directory, "results"); + } + if (cl.hasOption(OPTION_LOOP)) { + this.loop = Integer.parseInt(cl.getOptionValue(OPTION_LOOP)); + } + if (cl.hasOption(OPTION_TESTNUMBERS)) { + String testNumberString = cl.getOptionValue(OPTION_TESTNUMBERS); + testNumbersArray = testNumberString.split(","); + // + // reset strings to include dots so they exactly match pattern in file name + // + for (int i = 0; i < testNumbersArray.length; i++) { + testNumbersArray[i] = "." + testNumbersArray[i] + "."; + } + } + } + + /** + * Using the command line options that were parsed, configures our test instance. + * + * @throws FactoryException + */ + protected void configure() throws FactoryException { + // + // Setup the xacml.properties file + // + if (this.directory == null) { + throw new IllegalArgumentException("Must supply a path to a test directory."); + } + Path pathDir = Paths.get(this.directory, "xacml.properties"); + if (Files.notExists(pathDir)) { + throw new IllegalArgumentException(pathDir.toString() + " does not exist."); + } + // + // Set it as the System variable so the XACML factories know where the properties are + // loaded from. + // + System.setProperty(XACMLProperties.XACML_PROPERTIES_NAME, pathDir.toString()); + // + // Now we can create the data type factory + // + dataTypeFactory = DataTypeFactory.newInstance(); + // + // Load in what generators we are to create + // + String generators = XACMLProperties.getProperty(PROP_GENERATOR); + if (generators != null) { + // + // Parse the generators + // + for (String generator : Splitter.on(',').trimResults().omitEmptyStrings().split(generators)) { + this.configureGenerator(generator); + } + } + // + // If we are embedded, create our engine + // + if (this.isREST == false) { + PDPEngineFactory factory = PDPEngineFactory.newInstance(); + this.engine = factory.newEngine(); + } + // + // Remove all the responses from the results directory + // + this.removeResults(); + } + + /** + * Removes all the Response* files from the results directory. + * + */ + public void removeResults() { + try { + // + // Determine where the results are supposed to be written to + // + Path resultsPath; + if (this.output != null) { + resultsPath = this.output; + } else { + resultsPath = Paths.get(this.directory.toString(), "results"); + } + // + // Walk the files + // + Files.walkFileTree(resultsPath, new SimpleFileVisitor() { + + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + if (file.getFileName().toString().startsWith("Response")) { + Files.delete(file); + } + return super.visitFile(file, attrs); + } + }); + } catch (IOException e) { + logger.error("Failed to removeRequests from " + this.directory + " " + e); + } + } + + /** + * Configure's a specific generator instance from the properties file. + * + * @param generator + */ + protected void configureGenerator(String generator) { + String prefix = PROP_GENERATOR + "." + generator; + String file = XACMLProperties.getProperty(prefix + ".file"); + // + // Create a generator object + // + Generator gen = new Generator(Paths.get(this.directory, file)); + this.generators.add(gen); + // + // Grab attributes + // + String attributes = XACMLProperties.getProperty(prefix + ".attributes"); + for (String attribute : Splitter.on(',').trimResults().omitEmptyStrings().split(attributes)) { + String attributePrefix = prefix + ".attributes." + attribute; + // + // Create an attribute value. It is simply a placeholder for the field within + // the CSV that contains the actual attribute value. It mainly holds the data type + // + Identifier datatype = new IdentifierImpl(XACMLProperties.getProperty(attributePrefix + ".datatype")); + Integer field = Integer.parseInt(XACMLProperties.getProperty(attributePrefix + ".field")); + StdAttributeValue value = new StdAttributeValue<>(datatype, field); + // + // Get the rest of the attribute properties + // + Identifier category = new IdentifierImpl(XACMLProperties.getProperty(attributePrefix + ".category")); + Identifier id = new IdentifierImpl(XACMLProperties.getProperty(attributePrefix + ".id")); + String issuer = XACMLProperties.getProperty(attributePrefix + ".issuer"); + boolean include = Boolean.parseBoolean(XACMLProperties.getProperty(attributePrefix + ".include", "false")); + // + // Now we have a skeleton attribute + // + gen.attributes.add(new StdMutableAttribute(category, id, value, issuer, include)); + } + } + + /** + * This runs() the test instance. It first configure's itself and then walks the + * requests directory issue each request to the PDP engine. + * + * @throws IOException + * @throws FactoryException + * + */ + public void run() throws IOException, FactoryException { + // + // Configure ourselves + // + this.configure(); + // + // Loop and run + // + int runs = 1; + do { + long lTimeStart = System.currentTimeMillis(); + logger.info("Run number: " + runs); + // + // Walk the request directory + // + Files.walkFileTree(Paths.get(this.directory.toString(), "requests"), this); + long lTimeEnd = System.currentTimeMillis(); + logger.info("Run elapsed time: " + (lTimeEnd - lTimeStart) + "ms"); + // + // Dump the stats + // + this.dumpStats(); + this.resetStats(); + // + // Increment + // + runs++; + } while ((this.loop == -1 ? true : runs <= this.loop)); + } + + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + // + // Sanity check the file name + // + Matcher matcher = this.pattern.matcher(file.getFileName().toString()); + if (matcher.matches()) { + // + // if user has limited which files to use, check that here + // + if (testNumbersArray != null) { + String fileNameString = file.getFileName().toString(); + boolean found = false; + for (String numberString : testNumbersArray) { + if (fileNameString.contains(numberString)) { + found = true; + break; + } + } + if (found == false) { + // + // this test is not in the list to be run, so skip it + // + return super.visitFile(file, attrs); + } + } + try { + // + // Pull what this request is supposed to be + // + String group = null; + int count = matcher.groupCount(); + if (count >= 1) { + group = matcher.group(count-1); + } + // + // Send it + // + this.sendRequest(file, group); + } catch (Exception e) { + logger.error(e); + e.printStackTrace(); + } + } + return super.visitFile(file, attrs); + } + + /** + * When a request file is encountered, this method is called send the request to the PDP engine. It will also dump + * the response object. If the group equals "Generate", then it will loop and send the request with generated attributes + * until that list is empty. + * + * @param file - Request file. Eg. Request-01-Permit.json + * @param group - This is the parsed out string of the request file that defines if it is a Permit/Deny/Generate etc. + * @throws Exception + */ + protected void sendRequest(Path file, String group) throws Exception { + logger.info(file.toString()); + int requestCount = 0; + do { + // + // Generate the request + // + Request request = this.generateRequest(file, group); + // + // Was something generated? + // + if (request == null) { + // + // Get out of the loop + // + logger.info("NULL request generated."); + break; + } + logger.info(request); + // + // Call the PDP + // + Response response = this.callPDP(request); + // + // Process the response + // + this.processResponse(file, request, response, group, requestCount); + // + // Is this a generated request? + // + if (group.equals("Generate")) { + // + // Yes, increment counter and move + // on to the next generated request. + // + requestCount++; + } else { + // + // Nope, exit the loop + // + break; + } + } while (group.equals("Generate")); + } + + /** + * Sends the request object to the PDP engine. Either the embedded engine or the RESTful engine. + * + * @param request - XACML request object + * @return Response - returns the XACML response object + */ + protected Response callPDP(Request request) { + // + // Send it to the PDP + // + Response response = null; + if (this.isREST) { + try { + String jsonString = JSONRequest.toString(request, false); + // + // Call RESTful PDP + // + response = this.callRESTfulPDP(new ByteArrayInputStream(jsonString.getBytes())); + } catch (Exception e) { + logger.error("Error in sending RESTful request: " + e, e); + } + } else { + // + // Embedded call to PDP + // + long lTimeStart = System.currentTimeMillis(); + try { + response = this.engine.decide(request); + } catch (PDPException e) { + logger.error(e); + } + long lTimeEnd = System.currentTimeMillis(); + logger.info("Elapsed Time: " + (lTimeEnd - lTimeStart) + "ms"); + } + return response; + } + + /** + * Reads the request file into a Request object based on its type. + * + * If the request has "Generate" in its filename, then this function will add + * generated attributes into the request. + * + * @param file - Request file. Eg. Request-01-Permit.json + * @param group - This is the parsed out string of the request file that defines if it is a Permit/Deny/Generate etc. + * @return + * @throws JSONStructureException + * @throws DOMStructureException + * @throws PEPException + */ + protected Request generateRequest(Path file, String group) throws JSONStructureException, DOMStructureException, PEPException { + // + // Convert to a XACML Request Object + // + Request request = null; + if (TestBase.isJSON(file)) { + request = JSONRequest.load(file.toFile()); + } else if (TestBase.isXML(file)) { + request = DOMRequest.load(file.toFile()); + } + if (request == null) { + throw new PEPException("Invalid Request File: " + file.toString()); + } + // + // Only if this request has "Generate" + // Request.XX.Generate.[json|xml] + // + if (group.equals("Generate")) { + // + // Add attributes to it + // + request = this.onNextRequest(request); + } + // + // Done + // + return request; + } + + /** + * Called to add in generated attributes into the request. + * + * @param request + * @return + */ + protected Request onNextRequest(Request request) { + // + // If we have no generators, just return + // + if (this.generators.isEmpty()) { + return request; + } + // + // Copy the request attributes + // + List attributes = new ArrayList(); + for (RequestAttributes a : request.getRequestAttributes()) { + attributes.add(new StdMutableRequestAttributes(a)); + } + // + // Iterate the generators + // + for (Generator generator : this.generators) { + // + // Read a row in + // + String line = generator.read(); + // + // Was something read? + // + if (line == null) { + // + // No more rows to read, return null + // + return null; + } + // + // Split the line + // + List fields = Lists.newArrayList(Splitter.on(',').trimResults().split(line)); + // + // Now work on the attributes + // + for (StdMutableAttribute attribute : generator.attributes) { + // + // Grab the attribute holder, which holds the datatype and field. There should + // be only ONE object in the collection. + // + AttributeValue value = attribute.getValues().iterator().next(); + Integer field = (Integer) value.getValue(); + // + // Is the field number valid? + // + if (field >= fields.size()) { + logger.error("Not enough fields: " + field + "(" + fields.size() + ")"); + return null; + } + // + // Determine what datatype it is + // + DataType dataTypeExtended = dataTypeFactory.getDataType(value.getDataTypeId()); + if (dataTypeExtended == null) { + logger.error("Failed to determine datatype"); + return null; + } + // + // Create the attribute value + // + try { + AttributeValue attributeValue = dataTypeExtended.createAttributeValue(fields.get(field)); + // + // Create the attribute + // + StdMutableAttribute newAttribute = new StdMutableAttribute(attribute.getCategory(), + attribute.getAttributeId(), + attributeValue, + attribute.getIssuer(), + attribute.getIncludeInResults()); + boolean added = false; + for (StdMutableRequestAttributes a : attributes) { + // + // Does the category exist? + // + if (a.getCategory().equals(attribute.getCategory())) { + // + // Yes - add in the new attribute value + // + a.add(newAttribute); + added = true; + break; + } + } + if (added == false) { + // + // New category - create it and add it in + // + StdMutableRequestAttributes a = new StdMutableRequestAttributes(); + a.setCategory(newAttribute.getCategory()); + a.add(newAttribute); + attributes.add(a); + } + } catch (DataTypeException e) { + logger.error(e); + return null; + } + } + } + // + // Now form our final request + // + StdMutableRequest newRequest = new StdMutableRequest(); + newRequest.setCombinedDecision(request.getCombinedDecision()); + newRequest.setRequestDefaults(request.getRequestDefaults()); + newRequest.setReturnPolicyIdList(request.getReturnPolicyIdList()); + newRequest.setStatus(request.getStatus()); + for (StdMutableRequestAttributes a : attributes) { + newRequest.add(a); + } + return newRequest; + } + + /** + * This makes an HTTP POST call to a running PDP RESTful servlet to get a decision. + * + * @param file + * @return + */ + protected Response callRESTfulPDP(InputStream is) { + Response response = null; + HttpURLConnection connection = null; + try { + + // + // Open up the connection + // + connection = (HttpURLConnection) this.restURL.openConnection(); + connection.setRequestProperty("Content-Type", "application/json"); + // + // Setup our method and headers + // + connection.setRequestMethod("POST"); + connection.setUseCaches(false); + // + // Adding this in. It seems the HttpUrlConnection class does NOT + // properly forward our headers for POST re-direction. It does so + // for a GET re-direction. + // + // So we need to handle this ourselves. + // + connection.setInstanceFollowRedirects(false); + connection.setDoOutput(true); + connection.setDoInput(true); + // + // Send the request + // + try (OutputStream os = connection.getOutputStream()) { + IOUtils.copy(is, os); + } + // + // Do the connect + // + connection.connect(); + if (connection.getResponseCode() == 200) { + // + // Read the response + // + ContentType contentType = null; + try { + contentType = ContentType.parse(connection.getContentType()); + + if (contentType.getMimeType().equalsIgnoreCase(ContentType.APPLICATION_JSON.getMimeType())) { + response = JSONResponse.load(connection.getInputStream()); + } else if (contentType.getMimeType().equalsIgnoreCase(ContentType.APPLICATION_XML.getMimeType()) || + contentType.getMimeType().equalsIgnoreCase("application/xacml+xml") ) { + response = DOMResponse.load(connection.getInputStream()); + } else { + logger.error("unknown content-type: " + contentType); + } + + } catch (Exception e) { + String message = "Parsing Content-Type: " + connection.getContentType() + ", error=" + e.getMessage(); + logger.error(message, e); + } + + } else { + logger.error(connection.getResponseCode() + " " + connection.getResponseMessage()); + } + } catch (Exception e) { + logger.error(e); + } + + return response; + } + + /** + * This processes a response. Saves the response out to disk. If there is a corresponding response file for the request located + * in the "responses" sub-directory, then this method will compare that response file with what the engine returned to see if it + * matched. + * + * @param requestFile + * @param request + * @param response + * @param group + * @param count + * @throws Exception + */ + protected void processResponse(Path requestFile, Request request, Response response, String group, int count) throws Exception { + // + // Construct the output filename + // + Path responseFile = null; + Path resultFile = null; + int num = requestFile.getNameCount(); + if (num < 2) { + logger.error("Too few dir's in request filename."); + throw new Exception("Too few dir's in request filename. Format should be Request.[0-9]+.{Permit|Deny|NA|Indeterminate}.{json|xml}"); + } + String filename = requestFile.getFileName().toString(); + if (group.equals("Generate")) { + // + // Using count variable, construct a filename + // + // i.e. Response.03.Generate.{count}.json + // + filename = "Response" + filename.substring(filename.indexOf('.'), filename.lastIndexOf('.')) + String.format("%03d", count) + filename.substring(filename.lastIndexOf('.')); + } else { + // + // Construct filename + // + filename = "Response" + filename.substring(filename.indexOf('.')); + } + // + // Determine equivalent response file path + // + responseFile = Paths.get(requestFile.subpath(0, num - 2).toString(), "responses"); + if (Files.notExists(responseFile)) { + // + // Create it + // + logger.warn(responseFile.toString() + " does NOT exist, creating..."); + try { + Files.createDirectories(responseFile); + } catch (IOException e) { + logger.error(e); + throw new Exception("Cannot proceed without an output directory."); + } + } + responseFile = Paths.get(responseFile.toString(), filename); + // + // Determine path to write result file + // + if (this.output != null) { + // + // User specified an output path + // + resultFile = this.output; + } else { + // + // Default path + // + resultFile = Paths.get(requestFile.subpath(0, num - 2).toString(), "results"); + } + // + // Check if the path exists + // + if (Files.notExists(resultFile)) { + // + // Create it + // + logger.warn(resultFile.toString() + " does NOT exist, creating..."); + try { + Files.createDirectories(resultFile); + } catch (IOException e) { + logger.error(e); + throw new Exception("Cannot proceed without an output directory."); + } + } + // + // Add the filename to the path + // + resultFile = Paths.get(resultFile.toString(), filename); + // + // Check if there is an equivalent response in the response + // directory. If so, compare our response result with that one. + // + boolean succeeded = true; + if (responseFile != null && Files.exists(responseFile)) { + // + // Do comparison + // + Response expectedResponse = null; + if (TestBase.isJSON(responseFile)) { + expectedResponse = JSONResponse.load(responseFile); + } else if (TestBase.isXML(responseFile)) { + expectedResponse = DOMResponse.load(responseFile); + } + if (expectedResponse != null) { + // + // Do the compare + // + if (response == null) { + logger.error("NULL response returned."); + this.responseNotMatches++; + succeeded = false; + } else { + if (response.equals(expectedResponse)) { + logger.info("Response matches expected response."); + this.responseMatches++; + } else { + logger.error("Response does not match expected response."); + logger.error("Expected: "); + logger.error(expectedResponse.toString()); + this.responseNotMatches++; + succeeded = false; + } + } + } + } + // + // Write the response to the result file + // + logger.info("Request: " + requestFile.getFileName() + " response is: " + (response == null ? "null" : response.toString())); + if (resultFile != null && response != null) { + if (TestBase.isJSON(resultFile)) { + Files.write(resultFile, JSONResponse.toString(response, true).getBytes()); + } else if (TestBase.isXML(resultFile)) { + Files.write(resultFile, DOMResponse.toString(response, true).getBytes()); + } + } + // + // Stats + // + if (group.equals("Permit")) { + this.expectedPermits++; + } else if (group.equals("Deny")) { + this.expectedDenies++; + } else if (group.equals("NA")) { + this.expectedNotApplicables++; + } else if (group.equals("Indeterminate")) { + this.expectedIndeterminates++; + } + if (response != null) { + for (Result result : response.getResults()) { + Decision decision = result.getDecision(); + if (group.equals("Generate")) { + if (decision.equals(Decision.PERMIT)) { + this.generatedpermits++; + } else if (decision.equals(Decision.DENY)) { + this.generateddenies++; + } else if (decision.equals(Decision.NOTAPPLICABLE)) { + this.generatednotapplicables++; + } else if (decision.equals(Decision.INDETERMINATE)) { + this.generatedindeterminates++; + } + continue; + } + if (decision.equals(Decision.PERMIT)) { + this.permits++; + if (group.equals("Permit") == false) { + succeeded = false; + logger.error("Expected " + group + " got " + decision); + } + } else if (decision.equals(Decision.DENY)) { + this.denies++; + if (group.equals("Deny") == false) { + succeeded = false; + logger.error("Expected " + group + " got " + decision); + } + } else if (decision.equals(Decision.NOTAPPLICABLE)) { + this.notapplicables++; + if (group.equals("NA") == false) { + succeeded = false; + logger.error("Expected " + group + " got " + decision); + } + } else if (decision.equals(Decision.INDETERMINATE)) { + this.indeterminates++; + if (group.equals("Indeterminate") == false) { + succeeded = false; + logger.error("Expected " + group + " got " + decision); + } + } + } + } + if (succeeded) { + logger.info("REQUEST SUCCEEDED"); + } else { + logger.info("REQUEST FAILED"); + } + } + + protected void dumpStats() { + StringBuilder dump = new StringBuilder(); + dump.append(System.lineSeparator()); + dump.append("Permits: " + this.permits + " Expected: " + this.expectedPermits); + dump.append(System.lineSeparator()); + dump.append("Denies: " + this.denies + " Expected: " + this.expectedDenies); + dump.append(System.lineSeparator()); + dump.append("NA: " + this.notapplicables + " Expected: " + this.expectedNotApplicables); + dump.append(System.lineSeparator()); + dump.append("Indeterminates: " + this.indeterminates + " Expected: " + this.expectedIndeterminates); + dump.append(System.lineSeparator()); + dump.append("Generated Permits: " + this.generatedpermits); + dump.append(System.lineSeparator()); + dump.append("Generated Denies: " + this.generateddenies); + dump.append(System.lineSeparator()); + dump.append("Generated NA: " + this.generatednotapplicables); + dump.append(System.lineSeparator()); + dump.append("Generated Indeterminates: " + this.generatedindeterminates); + dump.append(System.lineSeparator()); + dump.append("Responses Matched: " + this.responseMatches); + dump.append(System.lineSeparator()); + dump.append("Responses NOT Matched: " + this.responseNotMatches); + + if (this.permits != this.expectedPermits || + this.denies != this.expectedDenies || + this.notapplicables != this.expectedNotApplicables || + this.indeterminates != this.expectedIndeterminates || + this.responseNotMatches > 0) { + logger.fatal(dump.toString()); + } else { + logger.info(dump.toString()); + } + } + + protected void resetStats() { + this.permits = 0; + this.denies = 0; + this.notapplicables = 0; + this.indeterminates = 0; + this.generatedpermits = 0; + this.generateddenies = 0; + this.generatednotapplicables = 0; + this.generatedindeterminates = 0; + this.responseMatches = 0; + this.responseNotMatches = 0; + } + + public static void main(String[] args) { + try { + new TestBase(args).run(); + } catch (ParseException | IOException | FactoryException e) { + logger.error(e); + } catch (HelpException e) { + } + } +} diff --git a/ECOMP-XACML/src/test/java/org/openecomp/policy/xacml/test/TestPolicy.java b/ECOMP-XACML/src/test/java/org/openecomp/policy/xacml/test/TestPolicy.java new file mode 100644 index 000000000..983855900 --- /dev/null +++ b/ECOMP-XACML/src/test/java/org/openecomp/policy/xacml/test/TestPolicy.java @@ -0,0 +1,792 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-XACML + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.xacml.test; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.regex.Matcher; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBElement; +import javax.xml.bind.Marshaller; + +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributesType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObjectFactory; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicySetType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.RequestType; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.GnuParser; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.ParseException; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import com.att.research.xacml.api.AttributeValue; +import com.att.research.xacml.api.DataType; +import com.att.research.xacml.api.DataTypeException; +import com.att.research.xacml.api.DataTypeFactory; +import com.att.research.xacml.api.Identifier; +import com.att.research.xacml.api.XACML3; +import com.att.research.xacml.std.IdentifierImpl; +import com.att.research.xacml.util.FactoryException; +import com.att.research.xacml.util.XACMLObjectCopy; +import com.att.research.xacml.util.XACMLPolicyAggregator; +import com.att.research.xacml.util.XACMLPolicyScanner; +import com.att.research.xacml.util.XACMLProperties; + +/** + * This class reads the policy in and extracts all the attributes and their values that is contained + * in the Policy. It then generates a request every single combination of attributes found. + * + * The attributes mostly come from the Target Match elements, since they have both an attribute designator/selector + * matched with an attribute value. + * + * + */ +public class TestPolicy extends TestBase { + private static Log logger = LogFactory.getLog(TestPolicy.class); + + private boolean skip; + private Path policy; + private XACMLPolicyAggregator aggregator = new XACMLPolicyAggregator(); + private long index; + + // + // Our command line parameters + // + public static final String OPTION_POLICY = "policy"; + public static final String OPTION_SKIP_GENERATE = "skip"; + + static { + options.addOption(new Option(OPTION_POLICY, true, "Path to the policy file.")); + options.addOption(new Option(OPTION_SKIP_GENERATE, false, "Skip generating requests.")); + } + + public class FlattenerObject { + Identifier category; + Identifier datatype; + Identifier attribute; + Set> values; + } + + /** + * This application exercises a policy by producing ALL the possible request combinations for a policy. + * + * -policy Path to a policy file + * + * @param args + * @throws HelpException + * @throws ParseException + * @throws MalformedURLException + */ + + public TestPolicy(String[] args) throws MalformedURLException, ParseException, HelpException { + super(args); + } + + /* + * Look for the -policy command line argument. This application needs a pointer to a specific policy + * in order to run. + * + * + * (non-Javadoc) + * @see com.att.research.xacmlatt.pdp.test.TestBase#parseCommands(java.lang.String[]) + */ + @Override + protected void parseCommands(String[] args) throws ParseException, MalformedURLException, HelpException { + // + // Have our super do its job + // + super.parseCommands(args); + // + // Look for the policy option + // + CommandLine cl; + cl = new GnuParser().parse(options, args); + if (cl.hasOption(OPTION_POLICY)) { + this.policy = Paths.get(cl.getOptionValue(OPTION_POLICY)); + // + // Ensure it exists + // + if (Files.notExists(this.policy)) { + throw new ParseException("Policy file does not exist."); + } + } else { + throw new ParseException("You need to specify the policy file to be used."); + } + if (cl.hasOption(OPTION_SKIP_GENERATE)) { + this.skip = true; + } else { + this.skip = false; + } + } + + /* + * We override this method because here is where we want to scan the policy and aggregate all + * the attributes that are defined within the policy. This routine will then dump all the possible + * requests into the requests sub-directory. Thus, when this method returns the TestBase can proceed + * to iterate each generated request and run it against the PDP engine. + * + * (non-Javadoc) + * @see com.att.research.xacmlatt.pdp.test.TestBase#configure() + */ + @Override + protected void configure() throws FactoryException { + // + // Have our base class do its thing + // + super.configure(); + // + // Setup where the PDP can find the policy + // + System.setProperty(XACMLProperties.PROP_ROOTPOLICIES, "policy"); + System.setProperty("policy.file", this.policy.toString()); + // + // Determine if they want us to skip generation. This helps when a huge number of + // requests will get generated for a policy and can take some time to do so. The user + // can generate the requests once and then start testing a policy against the requests. Thus, + // the attributes never changed but the policy logic did (saves time). + // + if (this.skip) { + return; + } + // + // Now we will scan the policy and get all the attributes. + // + XACMLPolicyScanner scanner = new XACMLPolicyScanner(this.policy, this.aggregator); + // + // The scanner returns us a policy object + // + Object policyObject = scanner.scan(); + // + // Just dump some info + // + if (policyObject instanceof PolicySetType) { + logger.info("Creating requests for policyset: " + ((PolicySetType)policyObject).getDescription()); + } else if (policyObject instanceof PolicyType) { + logger.info("Creating requests for policy: " + ((PolicyType)policyObject).getDescription()); + } + // + // Call the function to create the requests + // + if (policyObject != null) { + this.createRequests(); + } + + logger.info("Completed Generating requests."); + } + + @SuppressWarnings("unchecked") + protected void createRequests() { + // + // Clear out our request directory + // + this.removeRequests(); + // + // Get our map + // + Map>>>> attributeMap = this.aggregator.getAttributeMap(); + // + // We're going to create an initial flat list of requests for each unique attribute ID. Unique being the + // category, datatype and attribute id. + // + // By flattening the list, it makes it easier to then generate all the combinations of possible requests. + // + List attributes = new ArrayList(); + // + // Iterate through all the maps, we are going to flatten it + // out into an array list. + // + for (Map.Entry>>>> categoryEntry : attributeMap.entrySet()) { + String category = categoryEntry.getKey().toString(); + if (logger.isDebugEnabled()) { + logger.debug("Category: " + category); + } + Map>>> datatypeMap = categoryEntry.getValue(); + for (Map.Entry>>> datatypeEntry : datatypeMap.entrySet()) { + String datatype = datatypeEntry.getKey().toString(); + if (logger.isDebugEnabled()) { + logger.debug("\tData Type: " + datatype); + } + Map>> attributeIDMap = datatypeEntry.getValue(); + for (Map.Entry>> attributeIDEntry : attributeIDMap.entrySet()) { + String attributeID = attributeIDEntry.getKey().toString(); + if (logger.isDebugEnabled()) { + logger.debug("\t\tAttribute ID: " + attributeID); + } + Set> attributeValueSet = attributeIDEntry.getValue(); + // + // Sanity check to see if there are any values. Sometimes there isn't if an attribute + // is a designator that is part of a condition or variable. + // + if (attributeValueSet.isEmpty()) { + if (logger.isDebugEnabled()) { + logger.debug("No values for attribute " + attributeIDEntry.getKey().stringValue()); + } + // + // Check for the boolean datatype, in that case we can safely + // assume the true/false are ALL the possible values. + // + if (datatypeEntry.getKey().equals(XACML3.ID_DATATYPE_BOOLEAN) == false) { + // + // Not boolean, so skip it + // + continue; + } + if (logger.isDebugEnabled()) { + logger.debug("No values but its a boolean datatype, we will include it anyway."); + } + } + // + // Create our flattener object + // + FlattenerObject flat = new FlattenerObject(); + flat.category = categoryEntry.getKey(); + flat.datatype = datatypeEntry.getKey(); + flat.attribute = attributeIDEntry.getKey(); + flat.values = new HashSet>(); + if (datatypeEntry.getKey().equals(XACML3.ID_DATATYPE_BOOLEAN)) { + // + // There are only 2 possible values, true or false + // + flat.values.add(this.createAttributeValue(flat.datatype, true)); + flat.values.add(this.createAttributeValue(flat.datatype, false)); + } else { + flat.values.addAll(attributeValueSet); + } + attributes.add(flat); + } + } + } + if (attributes.size() <= 1) { + // + // Only one attribute, why bother + // + logger.info("Not enough attributes in policy: " + attributes.size()); + return; + } + /* + * PLD work more on this later. This combinatorial formula is only accurate if each + * attribute has one value. + * + */ + if (logger.isDebugEnabled()) { + // + // This isn't really accurate, if an attribute has more than one value + // + logger.debug(attributes.size() + " will generate " + computePossibleCombinations(attributes.size())); + } + this.index = 1; + for (int i = 0; i < attributes.size(); i++) { + FlattenerObject flat = attributes.get(i); + for (AttributeValue value : flat.values) { + // + // Create a basic request object for just that attribute value. + // + RequestType request = new RequestType(); + // + AttributesType attrs = new AttributesType(); + attrs.setCategory(flat.category.stringValue()); + request.getAttributes().add(attrs); + // + AttributeType attr = new AttributeType(); + attr.setAttributeId(flat.attribute.stringValue()); + attrs.getAttribute().add(attr); + // + AttributeValueType val = new AttributeValueType(); + val.setDataType(flat.datatype.stringValue()); + if (value.getValue() instanceof Collection) { + val.getContent().addAll((Collection) value.getValue()); + } else { + val.getContent().add(value.getValue().toString()); + } + // + attr.getAttributeValue().add(val); + // + // Dump it out + // + this.writeRequest(request); + // + // Initiate recursive call to add other attributes to the request + // + this.recursivelyGenerateRequests(request, i + 1, attributes); + } + } + } + + protected void recursivelyGenerateRequests(RequestType request, int i, List attributes) { + if (logger.isTraceEnabled()) { + logger.trace("recursiveGenerate index: " + index + " i: " + i); + } + for ( ; i < attributes.size(); i++) { + FlattenerObject flat = attributes.get(i); + for (AttributeValue value : flat.values) { + // + // Make a copy of the request + // + RequestType copyRequest = XACMLObjectCopy.deepCopy(request); + // + // Create the value object + // + AttributeValueType newValue = new AttributeValueType(); + newValue.setDataType(flat.datatype.stringValue()); + if (value.getValue() instanceof Collection) { + for (Object v : (Collection) value.getValue()) { + newValue.getContent().add(v.toString()); + } + } else { + newValue.getContent().add(value.getValue().toString()); + } + // + // Add the value to the request + // + this.addAttribute(copyRequest, flat.category.stringValue(), flat.attribute.stringValue(), newValue); + // + // Now write it out + // + this.writeRequest(copyRequest); + // + // Recursively go through the rest of the attributes + // + this.recursivelyGenerateRequests(copyRequest, i + 1, attributes); + } + } + } + + public static long computePossibleCombinations(long numberOfAttributes) { + long num = 0; + for (long i = numberOfAttributes; i > 0; i--) { + num += computeCombinations(numberOfAttributes, i); + } + return num; + } + + public static long computeFactorial(long n) { + long fact = 1; + for (long i = 1; i <= n; i++) { + fact *= i; + } + return fact; + } + + public static long computePermutationsWithoutRepetition(long n, long r) { + // + // n! + // --------- + // (n - r)! + // + long nPrime = 1; + long n_rPrime = 1; + for (long i = n; i > 1; i--) { + nPrime *= i; + } + + for (long i = (n - r); i > 1; i--) { + n_rPrime *= i; + } + return nPrime / n_rPrime; + } + + public static long computeCombinations(long n, long r) { + // + // n! + // ----------- + // r! * (n-r)! + // + long nPrime = 1; + long rPrime = 1; + long n_rPrime = 1; + + for (long i = n; i > 1; i--) { + nPrime *= i; + } + + for (long i = r; i > 1; i--) { + rPrime *= i; + } + + for (long i = (n - r); i > 1; i--) { + n_rPrime *= i; + } + + return nPrime / (rPrime * n_rPrime); + } + + protected Set> getAttributeValues(RequestType request) { + // + // Get our map + // + Map>>>> attributeMap = this.aggregator.getAttributeMap(); + // + // Find the attribute + // + AttributesType attrs = request.getAttributes().get(0); + Map>>> categoryMap = attributeMap.get(new IdentifierImpl(attrs.getCategory())); + if (categoryMap != null) { + AttributeType a = attrs.getAttribute().get(0); + Map>> datatypeMap = categoryMap.get(new IdentifierImpl(a.getAttributeValue().get(0).getDataType())); + if (datatypeMap != null) { + Set> values = datatypeMap.get(new IdentifierImpl(a.getAttributeId())); + if (values != null) { + return values; + } + } + } + return Collections.emptySet(); + } + + protected AttributeValue createAttributeValue(Identifier datatype, Object value) { + DataTypeFactory dataTypeFactory = null; + try { + dataTypeFactory = DataTypeFactory.newInstance(); + if (dataTypeFactory == null) { + logger.error("Could not create data type factory"); + return null; + } + } catch (FactoryException e) { + logger.error("Can't get Data type Factory: " + e.getLocalizedMessage()); + return null; + } + DataType dataTypeExtended = dataTypeFactory.getDataType(datatype); + if (dataTypeExtended == null) { + logger.error("Unknown datatype: " + datatype); + return null; + } + try { + return dataTypeExtended.createAttributeValue(value); + } catch (DataTypeException e) { + logger.error(e); + } + return null; + } + + protected void removeRequests() { + // + // Delete any existing request files that we generate. i.e. Have the Unknown in the file name. + // + try { + Files.walkFileTree(Paths.get(this.directory.toString(), "requests"), new SimpleFileVisitor() { + + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + // + // Sanity check the file name + // + Matcher matcher = pattern.matcher(file.getFileName().toString()); + if (matcher.matches()) { + try { + // + // Pull what this request is supposed to be + // + String group = null; + int count = matcher.groupCount(); + if (count >= 1) { + group = matcher.group(count-1); + } + // + // Send it + // + if (group.equals("Unknown")) { + // + // Remove the file + // + Files.delete(file); + } + } catch (Exception e) { + logger.error(e); + e.printStackTrace(); + } + } + return super.visitFile(file, attrs); + } + }); + } catch (IOException e) { + logger.error("Failed to removeRequests from " + this.directory + " " + e); + } + } + + protected void addRequests(RequestType request, List requests, int index) { + for (RequestType req : requests) { + // + // There really should only be one attribute + // + for (AttributesType attrs : req.getAttributes()) { + for (AttributeType attr : attrs.getAttribute()) { + for (AttributeValueType value : attr.getAttributeValue()) { + if (this.addAttribute(request, attrs.getCategory(), attr.getAttributeId(), value)) { + this.writeRequest(request); + } + } + } + } + } + } + + /** + * Writes the request into the "requests" sub-directory, relative to the value of the "directory" setup + * during initialization. + * + * Writing the requests out allows one to go back and easily refer to the request when analyzing the responses + * generated after the PDP decide() call. Also, one can then use the generated requests into any test tools + * they wish to build. + * + * @param request - The request to be written. + */ + protected void writeRequest(RequestType request) { + if (logger.isTraceEnabled()) { + logger.trace("writeRequest: " + index); + } + try { + ObjectFactory of = new ObjectFactory(); + JAXBElement requestElement = of.createRequest(request); + JAXBContext context = JAXBContext.newInstance(RequestType.class); + Marshaller m = context.createMarshaller(); + m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); + Path outFile = Paths.get(this.directory, "requests", String.format("Request.%06d.Unknown.xml", this.index)); + m.marshal(requestElement, outFile.toFile()); + } catch (Exception e) { + logger.error("Failed to write request: " + e.getMessage()); + } + this.index++; + } + + protected boolean addAttribute(RequestType request, String category, String id, AttributeValueType value) { + // + // See if the category exists + // + for (AttributesType attrs : request.getAttributes()) { + if (attrs.getCategory().equals(category)) { + // + // It does have the category. But does it have the attribute ID? + // + for (AttributeType attr : attrs.getAttribute()) { + if (attr.getAttributeId().equals(id)) { + // + // Yes, check for the same datatype + // + for (AttributeValueType val : attr.getAttributeValue()) { + if (val.getDataType().equals(value.getDataType())) { + // + // We have something already there + // + return false; + } + } + // + // The ID exists, but not the datatype + // + attr.getAttributeValue().add(value); + return true; + } + } + // + // If we get here, the ID does not exist + // + AttributeType attr = new AttributeType(); + attr.setAttributeId(id); + attr.getAttributeValue().add(value); + attrs.getAttribute().add(attr); + return true; + } + } + // + // If we get here, the category does not exist. So add it in. + // + AttributesType attrs = new AttributesType(); + attrs.setCategory(category); + AttributeType attr = new AttributeType(); + attr.setAttributeId(id); + attr.getAttributeValue().add(value); + attrs.getAttribute().add(attr); + request.getAttributes().add(attrs); + return true; + } + + public static void main(String[] args) { + try { + new TestPolicy(args).run(); + } catch (ParseException | IOException | FactoryException e) { + logger.error(e); + } catch (HelpException e) { + } + } + + /* + // Map>> + @SuppressWarnings("unchecked") + private void generateRequests(Map>>>> categoryMap) { + meta = new ArrayList<>(); + + for (Map.Entry>>>> categoryEntry : categoryMap.entrySet()) { + String category = categoryEntry.getKey().toString(); + logger.debug("Category: " + category); + Map>>> datatypeMap = categoryEntry.getValue(); + for (Map.Entry>>> datatypeEntry : datatypeMap.entrySet()) { + String datatype = datatypeEntry.getKey().toString(); + logger.debug("\tData Type: " + datatype); + Map>> attributeIDMap = datatypeEntry.getValue(); + for (Map.Entry>> attributeIDEntry : attributeIDMap.entrySet()) { + String attributeID = attributeIDEntry.getKey().toString(); + logger.debug("\t\tAttribute ID: " + attributeID); + Set> attributeValueSet = attributeIDEntry.getValue(); + for (AttributeValue value : attributeValueSet) { + logger.debug("\t\t\tAttribute Value: " + value); + } + Iterator> iterator = attributeValueSet.iterator(); + logger.debug("\t\t\t# of Attribute values: " + attributeValueSet.size()); + meta.add(new Object[] {category, datatype, attributeID, iterator.next(), iterator, attributeValueSet}); + } + } + } + + int count = 0; + for (File file : output.toFile().listFiles()) { + file.delete(); + } + + do { + RequestType request = new RequestType(); + request.setCombinedDecision(false); + request.setReturnPolicyIdList(false); + List attributesList = request.getAttributes(); + + Map category2Attribute= new HashMap<>(); + for (int i = 0; i < meta.size(); i++) { + Object[] record = meta.get(i); + + AttributesType attributes = null; + if (category2Attribute.containsKey(record[0].toString())) + attributes = category2Attribute.get(record[0].toString()); + else { + attributes = new AttributesType(); + attributes.setCategory(record[0].toString()); + category2Attribute.put(record[0].toString(), attributes); + attributesList.add(attributes); + } +// attributes.setId(record[2].toString()); + List attrList = attributes.getAttribute(); + + AttributeType attribute = new AttributeType(); + attribute.setAttributeId(record[2].toString()); + List valueList = attribute.getAttributeValue(); + + AttributeValue attributeValue = (AttributeValue) record[3]; + + AttributeValueType value = new AttributeValueType(); + value.setDataType(attributeValue.getDataTypeId().toString()); + List content = value.getContent(); + content.addAll((Collection) attributeValue.getValue()); + valueList.add(value); + + attrList.add(attribute); + } + + try { + ObjectFactory of = new ObjectFactory(); + JAXBElement requestElement = of.createRequest(request); + JAXBContext context = JAXBContext.newInstance(RequestType.class); + Marshaller m = context.createMarshaller(); + m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); + m.marshal(requestElement, output.resolve("request" + count + ".xml").toFile()); + +// if (count == 0) {//Just send the first request to the engine + StringWriter sw = new StringWriter(); + m.marshal(requestElement, sw); + logger.info(sw.toString()); + EngineCaller engine = new LocalEngineCaller(); + if (engine.startEngine("")) { + String response = engine.decide(sw.toString(), "xml"); + FileWriter writer = new FileWriter(output.resolve("response" + count + ".xml").toFile()); + writer.write(response); + writer.close(); + logger.info("Response received: \n" + response); + } +// } + } catch (Exception e) { + e.printStackTrace(); + } + + count++; + } while (hasNextRequest()); + + logger.info("# of requests generated: " + count); + } + + private boolean hasNextRequest() { + int i = meta.size() - 1; + Object[] record = meta.get(i); + + @SuppressWarnings("unchecked") + Iterator> iterator = (Iterator>) record[4]; + if (iterator.hasNext()) { + record[3] = iterator.next(); + } else { + return recycleAttributeValue(i); + } + + return true; + } + + @SuppressWarnings("unchecked") + private boolean recycleAttributeValue(int position) { + boolean rc = true; + + if (position == 0) + return false; + + Object[] record = meta.get(position); + Set> attributeValueSet = (Set>) record[5]; + Iterator> newIt = attributeValueSet.iterator(); + record[4] = newIt; + record[3] = newIt.next(); + int i = position - 1; + Object[] previous = meta.get(i); + Iterator> preIt = (Iterator>) previous[4]; + if (preIt.hasNext()) { + previous[3] = preIt.next(); + } else { + rc = recycleAttributeValue(i); + } + + return rc; + } + + */ + +} + diff --git a/ECOMP-XACML/src/test/java/org/openecomp/policy/xacml/test/XACMLEngineTest.java b/ECOMP-XACML/src/test/java/org/openecomp/policy/xacml/test/XACMLEngineTest.java new file mode 100644 index 000000000..660180b9b --- /dev/null +++ b/ECOMP-XACML/src/test/java/org/openecomp/policy/xacml/test/XACMLEngineTest.java @@ -0,0 +1,84 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-XACML + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.xacml.test; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import junit.framework.TestCase; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.springframework.mock.web.MockHttpServletResponse; +import org.springframework.mock.web.MockServletConfig; + +public class XACMLEngineTest extends TestCase{ + + private List headers = new ArrayList(); + + private HttpServletRequest httpServletRequest; + private HttpServletResponse httpServletResponse; + private ServletOutputStream mockOutput; + private ServletConfig servletConfig; + + @Before + + public void setUp() throws IOException { + httpServletRequest = Mockito.mock(HttpServletRequest.class); + Mockito.when(httpServletRequest.getMethod()).thenReturn("POST"); + Mockito.when(httpServletRequest.getParameter("groupId")).thenReturn(null); + Mockito.when(httpServletRequest.getHeaderNames()).thenReturn(Collections.enumeration(headers)); + Mockito.when(httpServletRequest.getAttributeNames()).thenReturn(Collections.enumeration(headers)); + + + mockOutput = Mockito.mock(ServletOutputStream.class); + + httpServletResponse = Mockito.mock(MockHttpServletResponse.class); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(mockOutput); + + servletConfig = Mockito.mock(MockServletConfig.class); + + Mockito.when(servletConfig.getInitParameterNames()).thenReturn(Collections.enumeration(headers)); + + + + } + + @Test + public void testDummy() throws Exception{ + try { + assertTrue(true); + } catch (Exception e) { + fail(); + } + + } + +} diff --git a/ECOMP-XACML/src/test/java/org/openecomp/policy/xacml/test/components/XACMLPDPPolicyTest.java b/ECOMP-XACML/src/test/java/org/openecomp/policy/xacml/test/components/XACMLPDPPolicyTest.java new file mode 100644 index 000000000..96163b20e --- /dev/null +++ b/ECOMP-XACML/src/test/java/org/openecomp/policy/xacml/test/components/XACMLPDPPolicyTest.java @@ -0,0 +1,49 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-XACML + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.xacml.test.components; + +import org.junit.Test; +import org.junit.Before; +import org.junit.After; + +import org.junit.Assert; + +public class XACMLPDPPolicyTest { + + + @Before + public void init(){ + + } + + @After + public void cleanUp(){ + + } + + @Test + public void testDummy(){ + + Assert.assertTrue(true); + + } + +} diff --git a/ECOMP-XACML/src/test/java/org/openecomp/policy/xacml/test/json/RequestCategoryTest.java b/ECOMP-XACML/src/test/java/org/openecomp/policy/xacml/test/json/RequestCategoryTest.java new file mode 100644 index 000000000..e4ef4bef7 --- /dev/null +++ b/ECOMP-XACML/src/test/java/org/openecomp/policy/xacml/test/json/RequestCategoryTest.java @@ -0,0 +1,4174 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-XACML + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.xacml.test.json; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import org.junit.Test; + +import com.att.research.xacml.api.Request; +import com.att.research.xacml.std.json.JSONRequest; +import com.att.research.xacml.std.json.JSONStructureException; + +/** + * Test JSON Request convert to object - Category sub-component. Does not include "Default" Categories (Subject, Action, Resource, Environment). + * Basic existance/absence of Category is tested in RequestMainTest. + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * NOTE: + * The "correct" way to verify that each JSON string gets translated into our internal Objects correctly is to look explicitly at each of the child objects + * and verify that they are correct. This would involve a lot of coding to get child of child of child and individually verify each property of each element. + * To simplify testing we assume that request.toString() correctly includes a complete text representation of every sub-component of the Request object + * and we compare the resulting String to our expected String. + * This has two possible sources of error: + * - toString might not include some sub-component, and + * - the initial verification of the resulting string is done by hand and may have been incorrect. + * + * + */ +public class RequestCategoryTest { + + // The request object output from each test conversion from JSON string + Request request; + + + /* + * Request that uses all fields with both single and multiple entries + */ + String allFieldsRequest = + "{\"Request\": {" + + "\"ReturnPolicyIdList\" : true ," + + "\"CombinedDecision\" : true ," + + "\"XPathVersion\" : \"http://www.w3.org/TR/1999/REC-xpath-19991116\"," + + "\"MultiRequests\" : {" + + "\"RequestReference\": [" + + "{ " + + "\"ReferenceId\" : [\"foo1\",\"bar1\"]" + + "}," + + "{" + + "\"ReferenceId\" : [\"foo2\",\"bar1\"]" + + "}]" + + "}," + + + "\"Category\": [" + + "{ " + + "\"CategoryId\": \"custom-category\", " + + "\"Id\" : \"customId\", " + + "\"Attribute\" : [" + + "{" + + "\"AttributeId\" : \"document-id\", " + + "\"DataType\" : \"integer\", " + + "\"Value\" : 123 " + + "}, " + + "{" + + "\"AttributeId\" : \"document-url\", " + + "\"DataType\" : \"anyURI\", " + + "\"Value\" : \"http://somewhere.over.the.com/rainbow\" " + + "}, " + + "{" + + "\"AttributeId\" : \"page-list\", " + + "\"Value\" : [1, 2, 3, 4.5, 3, 2, 1] " + + "} " + + "]" + + "}, " + + "{ " + + "\"CategoryId\": \"another-custom-cat\", " + + "\"Id\" : \"anotherXmlId\", " + + "\"Attribute\" : []" + + "} " + + "], " + + + "\"AccessSubject\":{ " + + "\"Content\" : \"" + + "Gambardella, MatthewXML Developer's GuideComputer" + + "44.952000-10-01An in-depth look at creating applications with XML."+ + "\"," + + "\"Attribute\" : []" + + "}, " + + + "\"Resource\" : {" + + "\"Content\" : \"PD94bWwgdmVyc2lvbj0iMS4wIj8+PGNhdGFsb2c+PGJvb2sgaWQ9ImJrMTAxIj48YXV0aG9yPkdhbWJhcmRlbGxhLCBNYXR0aGV3PC9hdXRob3I+PHRpdGxlPlhNT" + + "CBEZXZlbG9wZXIncyBHdWlkZTwvdGl0bGU+PGdlbnJlPkNvbXB1dGVyPC9nZW5yZT48cHJpY2U+NDQuOTU8L3ByaWNlPjxwdWJsaXNoX2RhdGU+MjAwMC0xMC0wMTwvcHVibGlzaF"+ + "9kYXRlPjxkZXNjcmlwdGlvbj5BbiBpbi1kZXB0aCBsb29rIGF0IGNyZWF0aW5nIGFwcGxpY2F0aW9ucyB3aXRoIFhNTC48L2Rlc2NyaXB0aW9uPjwvYm9vaz48L2NhdGFsb2c+\"" + + + + "} " + + + + "}}"; + + /* + * The following example comes directly from the JSON Profile Spec + */ + String exampleFromSpec = "{ " + + "\"Request\" : { " + + "\"AccessSubject\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "}, " + + "\"Action\" : { " + + "\"Attribute\": " + + "{ " + + "\"Id\" : \"action-id\", " + + "\"Value\" : \"http://www.xacml.eu/buy\", " + + "\"DataType\" : \"anyURI\" " + + "} " + + "}, " + + "\"Resource\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"book-title\", " + + "\"Value\" : \"Learn German in 90 days\" " + + "}, " + + "{ " + + "\"Id\" : \"currency\", " + + "\"Value\" : \"SEK\" " + + "}, " + + "{ " + + "\"Id\" : \"price\", " + + "\"Value\" : 123.34 " + + "} " + + "] " + + "} " + + "} " + + "} "; + + + /* + * The following example comes directly from the JSON Profile Spec (modified to include a "" missing from both examples). + * It shows the two ways of handling XPath content, as escaped XML and as Base64 encoding. + */ + String xPathExampleFromSpec = "{ " + + "\"Request\" : { " + + "\"Resource\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"urn:oasis:names:tc:xacml:3.0:content-selector\", " + + "\"DataType\" : \"xpathExpression\", " + + "\"Value\" : { " + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\", " + + "\"Namespaces\" : [{ " + + "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + + "}, " + + "{ " + + "\"Prefix\" : \"md\", " + + "\"Namespace\" : \"urn:example:med:schemas:record\" " + + "} " + + "], " + + "\"XPath\" : \"md:record/md:patient/md:patientDoB\" " + + "} " + + "} " + + "] " + + "} " + + "} " + + "} "; + + + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + // Top-level of Category + @Test + public void testCategoryTopLevel() { + + // empty Category + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Missing value + try { + request = JSONRequest.load("{\"Request\" : {\"Category\" }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\" : }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category without CategoryId + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{}] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category with CategoryId value missing or ="" + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\"] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"\" ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // CategoryId wrong type + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : true } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : 123 } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category with Id + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Id\" : \"customId\" } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category},xmlId=customId}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category with Id - wrong type + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Id\" : true } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Id\" : 123 } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // Category without Id + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\" } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // Category with standard CategoryId + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:access-subject\" } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category with extra unknown field + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", unknown } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"unknown\" : 123 } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category with multiple sub-Category objects using same CategoryId + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"category1\" }, {\"CategoryId\" : \"category1\" } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=category1}}{super={category=category1}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + } + + + + // Tests related to Attributes + @Test + public void testCategoryAttributes() { + + // Category with Attribute but none given ("Attribute" : [] ) + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute with empty attribute (missing both AttributeId and Id) + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute with AttributeId and no Value + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"AttributeId\" : \"document-id\" " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute missing AttributeId but with Id + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"AttributeId\" : \"document-id\", " + + "\"Value\" : 123 " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=123}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute missing AttributeId but with Id + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : 123 " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=123}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute including both AttributeId and Id with same value + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"AttributeId\" : \"document-id\", " + + "\"Id\" : \"document-id\", " + + "\"Value\" : 123 " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute missing both AttributeId and Id + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Value\" : 123 " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute AttributeId not string + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"AttributeId\" : true, " + + "\"Value\" : 123 " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"AttributeId\" : 123, " + + "\"Value\" : 123 " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute Id not string + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : true, " + + "\"Value\" : 123 " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : 123, " + + "\"Value\" : 123 " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // Category Attribute with DataType + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"integer\", " + + "\"Value\" : 123 " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=123}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute with DataType not string (e.g. "DataType" : 55.5 ) + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : true, " + + "\"Value\" : 123 " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute with unknown DataType + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"no such data type\", " + + "\"Value\" : 123 " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : 321, " + + "\"Value\" : 123 " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute with multiple value array + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"dayTimeDuration\", " + + "\"Value\" : [\"P3D\", \"P2DT12H34M\", \"PT15M\"] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#dayTimeDuration,value={super={durationSign=1years=0months=0days=3hours=0minutes=0seconds=0millis=0},factionalSeconds=0.0}}{dataTypeId=http://www.w3.org/2001/XMLSchema#dayTimeDuration,value={super={durationSign=1years=0months=0days=2hours=12minutes=34seconds=0millis=0},factionalSeconds=0.0}}{dataTypeId=http://www.w3.org/2001/XMLSchema#dayTimeDuration,value={super={durationSign=1years=0months=0days=0hours=0minutes=15seconds=0millis=0},factionalSeconds=0.0}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute multiple value with null in array + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"dayTimeDuration\", " + + "\"Value\" : [\"P3D\", , \"P15M\"] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute with array value with no values ("Attribute": [ {"AttributeId" :"a", Value:[] } ] } ) + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"dayTimeDuration\", " + + "\"Value\" : [ ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute with no DataType and array with no values + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute with Issuer + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Issuer\" : \"University Press\", " + + "\"DataType\" : \"integer\", " + + "\"Value\" : 123 " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=123}],issuer=University Press,includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute with Issuer not string + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Issuer\" : true, " + + "\"DataType\" : \"integer\", " + + "\"Value\" : 123 " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Issuer\" : 4.56, " + + "\"DataType\" : \"integer\", " + + "\"Value\" : 123 " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute with includeInResult=true + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : 123, " + + "\"IncludeInResult\" : true " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=123}],includeInResults=true}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute with includeInResult = false + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : 123, " + + "\"IncludeInResult\" : false " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=123}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute with includeInResult not boolean + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : 123, " + + "\"IncludeInResult\" : \"abc\" " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : 123, " + + "\"IncludeInResult\" : 123.45 " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + } + + + + // Tests related to DataTypes within Attributes + @Test + public void testCategoryAttributesDataTypesSimple() { + + // Category Attribute using full Identifier for each data type + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#string\", " + + "\"Value\" : \"abc\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=abc}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#boolean\", " + + "\"Value\" : true " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#boolean,value=true}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#integer\", " + + "\"Value\" : 123 " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=123}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#double\", " + + "\"Value\" : 123.34 " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=123.34}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#time\", " + + "\"Value\" : \"12:00:00Z\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#time,value=12:00:00Z}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#date\", " + + "\"Value\" : \"2002-10-10\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#date,value=2002-10-10}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#dateTime\", " + + "\"Value\" : \"2002-10-10T12:00:00Z\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#dateTime,value=2002-10-10T12:00:00Z}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#dayTimeDuration\", " + + "\"Value\" : \"P23DT7H12M54S\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#dayTimeDuration,value={super={durationSign=1years=0months=0days=23hours=7minutes=12seconds=54millis=0},factionalSeconds=54.0}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#yearMonthDuration\", " + + "\"Value\" : \"P165Y8M\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#yearMonthDuration,value={super={durationSign=1years=165months=8days=0hours=0minutes=0seconds=0millis=0},monthsDuration=1988}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#anyURI\", " + + "\"Value\" : \"aValue\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#hexBinary\", " + + "\"Value\" : \"FA027B7D12CC34DDD20012AEEF\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#hexBinary,value={data=[-6,2,123,125,18,-52,52,-35,-46,0,18,-82,-17]}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#base64Binary\", " + + "\"Value\" : \"lvbj0iMS4wIj8+PGNhdGFsb2c+PGJvb2sgaWQ9ImJrMTAxIj48YXV0aG9y\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#base64Binary,value={data=[-106,-10,-29,-46,35,18,-29,2,35,-13,-29,-58,54,23,70,22,-58,-10,115,-29,-58,38,-10,-10,-78,6,-106,67,-46,38,38,-77,19,3,18,35,-29,-58,23,87,70,-122,-9]}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name\", " + + "\"Value\" : \"someone.else@A.COMPANY.com\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name,value={localName=someone.else,domainName=A.COMPANY.com}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:1.0:data-type:x500Name\", " + + "\"Value\" : \"cn=Julius Hibbert, o=Medi Corporation, c=US\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:1.0:data-type:x500Name,value=CN=Julius Hibbert, O=Medi Corporation, C=US}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:2.0:data-type:ipAddress\", " + + "\"Value\" : \"10.221.43.58:12345\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:ipAddress,value=10.221.43.58:12345-12345}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:2.0:data-type:dnsName\", " + + "\"Value\" : \"aValue\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:dnsName,value={domainName=aValue}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\", " + + "\"Value\" : {" + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + + "\"Namespaces\" : [" + + "{ "+ + "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + + "}," + + "{" + + "\"Prefix\" : \"md\", " + + "\"Namespace\" : \"urn:example:med:schemas:record\" " + + "}], "+ + "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ + "}" + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression,value={path=md:record/md:patient/md:patientDoB,Namespace={[{md,urn:example:med:schemas:record}{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}]},status=null,xpathExpressionWrapped=null},xpathCategory=urn:oasis:names:tc:xacml:3.0:attribute-category:resource}],includeInResults=false}]}}]}", request.toString()); + + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // Category Attribute shorthand notation for each data type + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"string\", " + + "\"Value\" : \"abc\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=abc}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"boolean\", " + + "\"Value\" : true " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#boolean,value=true}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"integer\", " + + "\"Value\" : 123 " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=123}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"double\", " + + "\"Value\" : 123.34 " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=123.34}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"time\", " + + "\"Value\" : \"12:00:00Z\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#time,value=12:00:00Z}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"date\", " + + "\"Value\" : \"2002-10-10\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#date,value=2002-10-10}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"dateTime\", " + + "\"Value\" : \"2002-10-10T12:00:00Z\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#dateTime,value=2002-10-10T12:00:00Z}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"dayTimeDuration\", " + + "\"Value\" : \"P23DT7H12M54S\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#dayTimeDuration,value={super={durationSign=1years=0months=0days=23hours=7minutes=12seconds=54millis=0},factionalSeconds=54.0}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"yearMonthDuration\", " + + "\"Value\" : \"P165Y8M\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#yearMonthDuration,value={super={durationSign=1years=165months=8days=0hours=0minutes=0seconds=0millis=0},monthsDuration=1988}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"anyURI\", " + + "\"Value\" : \"aValue\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"hexBinary\", " + + "\"Value\" : \"FA027B7D12CC34DDD20012AEEF\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#hexBinary,value={data=[-6,2,123,125,18,-52,52,-35,-46,0,18,-82,-17]}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"base64Binary\", " + + "\"Value\" : \"lvbj0iMS4wIj8+PGNhdGFsb2c+PGJvb2sgaWQ9ImJrMTAxIj48YXV0aG9y\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#base64Binary,value={data=[-106,-10,-29,-46,35,18,-29,2,35,-13,-29,-58,54,23,70,22,-58,-10,115,-29,-58,38,-10,-10,-78,6,-106,67,-46,38,38,-77,19,3,18,35,-29,-58,23,87,70,-122,-9]}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"rfc822Name\", " + + "\"Value\" : \"someone.else@A.COMPANY.com\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name,value={localName=someone.else,domainName=A.COMPANY.com}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"x500Name\", " + + "\"Value\" : \"cn=Julius Hibbert, o=Medi Corporation, c=US\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:1.0:data-type:x500Name,value=CN=Julius Hibbert, O=Medi Corporation, C=US}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"ipAddress\", " + + "\"Value\" : \"10.221.43.58:12345\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:ipAddress,value=10.221.43.58:12345-12345}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"dnsName\", " + + "\"Value\" : \"aValue\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:dnsName,value={domainName=aValue}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"xpathExpression\", " + + "\"Value\" : {" + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + + "\"Namespaces\" : [" + + "{ "+ + "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + + "}," + + "{" + + "\"Prefix\" : \"md\", " + + "\"Namespace\" : \"urn:example:med:schemas:record\" " + + "}], "+ + "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ + "}" + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression,value={path=md:record/md:patient/md:patientDoB,Namespace={[{md,urn:example:med:schemas:record}{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}]},status=null,xpathExpressionWrapped=null},xpathCategory=urn:oasis:names:tc:xacml:3.0:attribute-category:resource}],includeInResults=false}]}}]}", request.toString()); + + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + + // infer data type - only integer, boolean and double are distinguishable from strings; everything else is treated as a string + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"abc\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=abc}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : true " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#boolean,value=true}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : 123 " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=123}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : 123.34 " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=123.34}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"12:00:00Z\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=12:00:00Z}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"2002-10-10\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"2002-10-10T12:00:00Z\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10T12:00:00Z}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"P23DT7H12M54S\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P23DT7H12M54S}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"P165Y8M\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P165Y8M}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"aValue\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"FA027B7D12CC34DDD20012AEEF\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=FA027B7D12CC34DDD20012AEEF}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"lvbj0iMS4wIj8+PGNhdGFsb2c+PGJvb2sgaWQ9ImJrMTAxIj48YXV0aG9y\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=lvbj0iMS4wIj8+PGNhdGFsb2c+PGJvb2sgaWQ9ImJrMTAxIj48YXV0aG9y}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"someone.else@A.COMPANY.com\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=someone.else@A.COMPANY.com}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:1.0:data-type:x500Name\", " + + "\"Value\" : \"cn=Julius Hibbert, o=Medi Corporation, c=US\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:1.0:data-type:x500Name,value=CN=Julius Hibbert, O=Medi Corporation, C=US}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"10.221.43.58:12345\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=10.221.43.58:12345}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"aValue\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"aValue\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : {" + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + + "\"Namespaces\" : [" + + "{ "+ + "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + + "}," + + "{" + + "\"Prefix\" : \"md\", " + + "\"Namespace\" : \"urn:example:med:schemas:record\" " + + "}], "+ + "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ + "}" + + "}] } ] }}"); + // gets inferred to a String containing the whole structure under Value as a String + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value={XPathCategory=urn:oasis:names:tc:xacml:3.0:attribute-category:resource, Namespaces=[{Namespace=urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}, {Prefix=md, Namespace=urn:example:med:schemas:record}], XPath=md:record/md:patient/md:patientDoB}}],includeInResults=false}]}}]}", request.toString()); + + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + } + + + + @Test + public void testCategoryAttributesDataTypesNotMatchValue() { + + // Category Attribute with DataType not matching value type (JSON type derived from syntax) + // AUTO-CONVERSION from Boolean to String! + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#string\", " + + "\"Value\" : true " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=true}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // SUCCESSFUL AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#string\", " + + "\"Value\" : 123 " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=123}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // SUCCESSFUL AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#string\", " + + "\"Value\" : 123.34 " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=123.34}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#boolean\", " + + "\"Value\" : \"abc\" " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#boolean\", " + + "\"Value\" : 123 " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#boolean\", " + + "\"Value\" : 123.45 " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // SUCCESSFUL AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#integer\", " + + "\"Value\" : \"123\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=123}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#integer\", " + + "\"Value\" : true " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#integer\", " + + "\"Value\" : 123.45 " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // SUCCESSFUL AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#double\", " + + "\"Value\" : \"123.34\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=123.34}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#double\", " + + "\"Value\" : true " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // allow integer to auto-convert to double when DataType is given + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#double\", " + + "\"Value\" : 123 " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=123.0}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // special JavaScript values not allowed except for -0 (inappropriate requirement in spec - check it anyway) + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#integer\", " + + "\"Value\" : \"NaN\" " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#integer\", " + + "\"Value\" : \"INF\" " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#integer\", " + + "\"Value\" : \"-INF\" " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // JavaScript 0 and -0 are ok + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#integer\", " + + "\"Value\" : 0 " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=0}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#integer\", " + + "\"Value\" : -0 " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=0}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // All other data types are checked when we convert internally, so value must be syntactically correct + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#time\", " + + "\"Value\" : \"syntactically incorrect value\" " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#date\", " + + "\"Value\" : \"syntactically incorrect value\" " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#dateTime\", " + + "\"Value\" : \"syntactically incorrect value\" " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#dayTimeDuration\", " + + "\"Value\" : \"syntactically incorrect value\" " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#yearMonthDuration\", " + + "\"Value\" : \"syntactically incorrect value\" " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#anyURI\", " + + "\"Value\" : \"syntactically incorrect value\" " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#hexBinary\", " + + "\"Value\" : \"syntactically incorrect value\" " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Base64 convert does not throw an exception if the contents are not Base64, so cannot test for this. + // Any problem with the data will have to be discovered later when the data is used. + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name\", " + + "\"Value\" : \"syntactically incorrect value\" " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:1.0:data-type:x500Name\", " + + "\"Value\" : \"syntactically incorrect value\" " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:2.0:data-type:ipAddress\", " + + "\"Value\" : \"syntactically incorrect value\" " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:2.0:data-type:dnsName\", " + + "\"Value\" : \"syntactically incorrect value\" " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // Cannot test XPathExpressions here. The XPathExpression gets converted into a simple String value within the XPathExpression object, + // but it is not evaluated or compiled at that time. Therefore we do not know whether or not the value is valid until it is used in a computation. + + } + + + @Test + public void testArrayDataTypes() { + + // array of size 0 + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#string\", " + + "\"Value\" : [] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // Category Attribute value array DataType given (repeat for all data types) + // Category Attribute using full Identifier for each data type + // Category Attribute shorthand notation for each data type + // Also tests for mixes of different JSON types (trying incorrect strings for XACML data types whenever possible) + // string + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#string\", " + + "\"Value\" : [\"abc\", \"def\", \"hig\", \"lmn\"] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=abc}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=def}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=hig}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=lmn}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"string\", " + + "\"Value\" : [\"abc\", \"def\", \"hig\", \"lmn\"] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=abc}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=def}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=hig}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=lmn}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // SUCCESSFUL AUTO-CONVERT to DataType + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#string\", " + + "\"Value\" : [\"abc\", true, \"hig\", \"lmn\"] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=abc}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=hig}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=lmn}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // SUCCESSFUL AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#string\", " + + "\"Value\" : [\"abc\",123, \"hig\", \"lmn\"] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=abc}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=123}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=hig}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=lmn}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // SUCCESSFUL AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#string\", " + + "\"Value\" : [\"abc\", 34.34, \"hig\", \"lmn\"] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=abc}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=34.34}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=hig}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=lmn}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // boolean + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#boolean\", " + + "\"Value\" : [true, true, false, true, false ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#boolean,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#boolean,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#boolean,value=false}{dataTypeId=http://www.w3.org/2001/XMLSchema#boolean,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#boolean,value=false}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"boolean\", " + + "\"Value\" : [true, true, false, true, false ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#boolean,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#boolean,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#boolean,value=false}{dataTypeId=http://www.w3.org/2001/XMLSchema#boolean,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#boolean,value=false}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#boolean\", " + + "\"Value\" : [true, \"abc\", false, true, false ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#boolean\", " + + "\"Value\" : [true, 123, false, true, false ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#boolean\", " + + "\"Value\" : [true, 12.34, false, true, false ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + + // integer + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#integer\", " + + "\"Value\" : [123, 456, 765, 234] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=123}{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=456}{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=765}{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=234}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"integer\", " + + "\"Value\" : [123, 456, 765, 234] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=123}{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=456}{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=765}{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=234}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#integer\", " + + "\"Value\" : [123, \"abc\", 765, 234] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#integer\", " + + "\"Value\" : [123, true, 765, 234] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#integer\", " + + "\"Value\" : [123, 34.56, 765, 234] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // double + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#double\", " + + "\"Value\" : [ 123.34, 543.54, 3445.455, 4543,543 ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=123.34}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=543.54}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=3445.455}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=4543.0}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=543.0}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"double\", " + + "\"Value\" : [ 123.34, 543.54, 3445.455, 4543,543 ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=123.34}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=543.54}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=3445.455}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=4543.0}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=543.0}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // special case - auto-convert integer to boolean + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#double\", " + + "\"Value\" : [ 123.34, 111122, 3445.455, 4543,543 ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=123.34}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=111122.0}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=3445.455}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=4543.0}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=543.0}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#double\", " + + "\"Value\" : [ 123.34, true, 3445.455, 4543,543 ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#double\", " + + "\"Value\" : [ 123.34, \"abb\", 3445.455, 4543,543 ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // time + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#time\", " + + "\"Value\" : [ \"12:00:00Z\", \"12:00:00Z\", \"12:00:00Z\"] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#time,value=12:00:00Z}{dataTypeId=http://www.w3.org/2001/XMLSchema#time,value=12:00:00Z}{dataTypeId=http://www.w3.org/2001/XMLSchema#time,value=12:00:00Z}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"time\", " + + "\"Value\" : [ \"12:00:00Z\", \"12:00:00Z\", \"12:00:00Z\"] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#time,value=12:00:00Z}{dataTypeId=http://www.w3.org/2001/XMLSchema#time,value=12:00:00Z}{dataTypeId=http://www.w3.org/2001/XMLSchema#time,value=12:00:00Z}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#time\", " + + "\"Value\" : [ \"12:00:00Z\", \"not a time\", \"12:00:00Z\"] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#time\", " + + "\"Value\" : [ \"12:00:00Z\", true, \"12:00:00Z\"] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#time\", " + + "\"Value\" : [ \"12:00:00Z\", 123, \"12:00:00Z\"] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#time\", " + + "\"Value\" : [ \"12:00:00Z\", 12.34, \"12:00:00Z\"] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // date + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#date\", " + + "\"Value\" : [\"2002-10-10\",\"2002-10-10\",\"2002-10-10\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#date,value=2002-10-10}{dataTypeId=http://www.w3.org/2001/XMLSchema#date,value=2002-10-10}{dataTypeId=http://www.w3.org/2001/XMLSchema#date,value=2002-10-10}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"date\", " + + "\"Value\" : [\"2002-10-10\",\"2002-10-10\",\"2002-10-10\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#date,value=2002-10-10}{dataTypeId=http://www.w3.org/2001/XMLSchema#date,value=2002-10-10}{dataTypeId=http://www.w3.org/2001/XMLSchema#date,value=2002-10-10}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#date\", " + + "\"Value\" : [\"2002-10-10\",\"not a date\",\"2002-10-10\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#date\", " + + "\"Value\" : [\"2002-10-10\",true,\"2002-10-10\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#date\", " + + "\"Value\" : [\"2002-10-10\",123,\"2002-10-10\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#date\", " + + "\"Value\" : [\"2002-10-10\",123.45,\"2002-10-10\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // dateTime + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#dateTime\", " + + "\"Value\" : [ \"2002-10-10T12:00:00Z\",\"2002-10-10T12:00:00Z\",\"2002-10-10T12:00:00Z\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#dateTime,value=2002-10-10T12:00:00Z}{dataTypeId=http://www.w3.org/2001/XMLSchema#dateTime,value=2002-10-10T12:00:00Z}{dataTypeId=http://www.w3.org/2001/XMLSchema#dateTime,value=2002-10-10T12:00:00Z}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"dateTime\", " + + "\"Value\" : [ \"2002-10-10T12:00:00Z\",\"2002-10-10T12:00:00Z\",\"2002-10-10T12:00:00Z\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#dateTime,value=2002-10-10T12:00:00Z}{dataTypeId=http://www.w3.org/2001/XMLSchema#dateTime,value=2002-10-10T12:00:00Z}{dataTypeId=http://www.w3.org/2001/XMLSchema#dateTime,value=2002-10-10T12:00:00Z}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#dateTime\", " + + "\"Value\" : [ \"2002-10-10T12:00:00Z\",\"not a dateTime\",\"2002-10-10T12:00:00Z\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#dateTime\", " + + "\"Value\" : [ \"2002-10-10T12:00:00Z\",true,\"2002-10-10T12:00:00Z\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#dateTime\", " + + "\"Value\" : [ \"2002-10-10T12:00:00Z\",123,\"2002-10-10T12:00:00Z\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#dateTime\", " + + "\"Value\" : [ \"2002-10-10T12:00:00Z\",12.34,\"2002-10-10T12:00:00Z\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // dayTimeDuration + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#dayTimeDuration\", " + + "\"Value\" : [ \"P23DT7H12M54S\",\"P23DT7H12M54S\",\"P23DT7H12M54S\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#dayTimeDuration,value={super={durationSign=1years=0months=0days=23hours=7minutes=12seconds=54millis=0},factionalSeconds=54.0}}{dataTypeId=http://www.w3.org/2001/XMLSchema#dayTimeDuration,value={super={durationSign=1years=0months=0days=23hours=7minutes=12seconds=54millis=0},factionalSeconds=54.0}}{dataTypeId=http://www.w3.org/2001/XMLSchema#dayTimeDuration,value={super={durationSign=1years=0months=0days=23hours=7minutes=12seconds=54millis=0},factionalSeconds=54.0}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"dayTimeDuration\", " + + "\"Value\" : [ \"P23DT7H12M54S\",\"P23DT7H12M54S\",\"P23DT7H12M54S\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#dayTimeDuration,value={super={durationSign=1years=0months=0days=23hours=7minutes=12seconds=54millis=0},factionalSeconds=54.0}}{dataTypeId=http://www.w3.org/2001/XMLSchema#dayTimeDuration,value={super={durationSign=1years=0months=0days=23hours=7minutes=12seconds=54millis=0},factionalSeconds=54.0}}{dataTypeId=http://www.w3.org/2001/XMLSchema#dayTimeDuration,value={super={durationSign=1years=0months=0days=23hours=7minutes=12seconds=54millis=0},factionalSeconds=54.0}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#dayTimeDuration\", " + + "\"Value\" : [ \"P23DT7H12M54S\",\"not a duration\",\"P23DT7H12M54S\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#dayTimeDuration\", " + + "\"Value\" : [ \"P23DT7H12M54S\",true,\"P23DT7H12M54S\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#dayTimeDuration\", " + + "\"Value\" : [ \"P23DT7H12M54S\",123,\"P23DT7H12M54S\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#dayTimeDuration\", " + + "\"Value\" : [ \"P23DT7H12M54S\",11.22,\"P23DT7H12M54S\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // yearMonth duration + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#yearMonthDuration\", " + + "\"Value\" : [ \"P165Y8M\",\"P165Y8M\",\"P165Y8M\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#yearMonthDuration,value={super={durationSign=1years=165months=8days=0hours=0minutes=0seconds=0millis=0},monthsDuration=1988}}{dataTypeId=http://www.w3.org/2001/XMLSchema#yearMonthDuration,value={super={durationSign=1years=165months=8days=0hours=0minutes=0seconds=0millis=0},monthsDuration=1988}}{dataTypeId=http://www.w3.org/2001/XMLSchema#yearMonthDuration,value={super={durationSign=1years=165months=8days=0hours=0minutes=0seconds=0millis=0},monthsDuration=1988}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"yearMonthDuration\", " + + "\"Value\" : [ \"P165Y8M\",\"P165Y8M\",\"P165Y8M\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#yearMonthDuration,value={super={durationSign=1years=165months=8days=0hours=0minutes=0seconds=0millis=0},monthsDuration=1988}}{dataTypeId=http://www.w3.org/2001/XMLSchema#yearMonthDuration,value={super={durationSign=1years=165months=8days=0hours=0minutes=0seconds=0millis=0},monthsDuration=1988}}{dataTypeId=http://www.w3.org/2001/XMLSchema#yearMonthDuration,value={super={durationSign=1years=165months=8days=0hours=0minutes=0seconds=0millis=0},monthsDuration=1988}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#yearMonthDuration\", " + + "\"Value\" : [ \"P165Y8M\",\"not a duration\",\"P165Y8M\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#yearMonthDuration\", " + + "\"Value\" : [ \"P165Y8M\",true,\"P165Y8M\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#yearMonthDuration\", " + + "\"Value\" : [ \"P165Y8M\",123,\"P165Y8M\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#yearMonthDuration\", " + + "\"Value\" : [ \"P165Y8M\",11.22,\"P165Y8M\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // anyURI + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#anyURI\", " + + "\"Value\" : [ \"aValue\",\"aValue\",\"aValue\"] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"anyURI\", " + + "\"Value\" : [ \"aValue\",\"aValue\",\"aValue\"] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // SUCCESSFUL AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#anyURI\", " + + "\"Value\" : [ \"aValue\",true,\"aValue\"] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // SUCCESSFUL AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#anyURI\", " + + "\"Value\" : [ \"aValue\",123,\"aValue\"] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=123}{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#anyURI\", " + + "\"Value\" : [ \"aValue\",11.111,\"aValue\"] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=11.111}{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // hexBinary + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#hexBinary\", " + + "\"Value\" : [ \"FA027B7D12CC34DDD20012AEEF\",\"FA027B7D12CC34DDD20012AEEF\",\"FA027B7D12CC34DDD20012AEEF\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#hexBinary,value={data=[-6,2,123,125,18,-52,52,-35,-46,0,18,-82,-17]}}{dataTypeId=http://www.w3.org/2001/XMLSchema#hexBinary,value={data=[-6,2,123,125,18,-52,52,-35,-46,0,18,-82,-17]}}{dataTypeId=http://www.w3.org/2001/XMLSchema#hexBinary,value={data=[-6,2,123,125,18,-52,52,-35,-46,0,18,-82,-17]}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"hexBinary\", " + + "\"Value\" : [ \"FA027B7D12CC34DDD20012AEEF\",\"FA027B7D12CC34DDD20012AEEF\",\"FA027B7D12CC34DDD20012AEEF\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#hexBinary,value={data=[-6,2,123,125,18,-52,52,-35,-46,0,18,-82,-17]}}{dataTypeId=http://www.w3.org/2001/XMLSchema#hexBinary,value={data=[-6,2,123,125,18,-52,52,-35,-46,0,18,-82,-17]}}{dataTypeId=http://www.w3.org/2001/XMLSchema#hexBinary,value={data=[-6,2,123,125,18,-52,52,-35,-46,0,18,-82,-17]}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#hexBinary\", " + + "\"Value\" : [ \"FA027B7D12CC34DDD20012AEEF\",true,\"012AEEF\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#hexBinary\", " + + "\"Value\" : [ \"FA027B7D12CC34DDD20012AEEF\",123,\"012AEEF\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#hexBinary\", " + + "\"Value\" : [ \"FA027B7D12CC34DDD20012AEEF\",11.44,\"012AEEF\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // base64Binary + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#base64Binary\", " + + "\"Value\" : [ \"aG9y\",\"lvbj0iMS4xIj48YXV0aG9y\",\"lvbjIj48YXV0aG9y\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#base64Binary,value={data=[104,111,114]}}{dataTypeId=http://www.w3.org/2001/XMLSchema#base64Binary,value={data=[-106,-10,-29,-46,35,18,-29,18,35,-29,-58,23,87,70,-122,-9]}}{dataTypeId=http://www.w3.org/2001/XMLSchema#base64Binary,value={data=[-106,-10,-29,34,62,60,97,117,116,104,111,114]}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"base64Binary\", " + + "\"Value\" : [ \"aG9y\",\"lvbj0iMS4xIj48YXV0aG9y\",\"lvbjIj48YXV0aG9y\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#base64Binary,value={data=[104,111,114]}}{dataTypeId=http://www.w3.org/2001/XMLSchema#base64Binary,value={data=[-106,-10,-29,-46,35,18,-29,18,35,-29,-58,23,87,70,-122,-9]}}{dataTypeId=http://www.w3.org/2001/XMLSchema#base64Binary,value={data=[-106,-10,-29,34,62,60,97,117,116,104,111,114]}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#base64Binary\", " + + "\"Value\" : [ \"aG9y\",true,\"lvbjIj48YXV0aG9y\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#base64Binary,value={data=[104,111,114]}}{dataTypeId=http://www.w3.org/2001/XMLSchema#base64Binary,value={data=[-74,-69,-98]}}{dataTypeId=http://www.w3.org/2001/XMLSchema#base64Binary,value={data=[-106,-10,-29,34,62,60,97,117,116,104,111,114]}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#base64Binary\", " + + "\"Value\" : [ \"aG9y\",1123,\"lvbjIj48YXV0aG9y\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#base64Binary,value={data=[104,111,114]}}{dataTypeId=http://www.w3.org/2001/XMLSchema#base64Binary,value={data=[-41,93,-73]}}{dataTypeId=http://www.w3.org/2001/XMLSchema#base64Binary,value={data=[-106,-10,-29,34,62,60,97,117,116,104,111,114]}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#base64Binary\", " + + "\"Value\" : [ \"aG9y\",11.22,\"lvbjIj48YXV0aG9y\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#base64Binary,value={data=[104,111,114]}}{dataTypeId=http://www.w3.org/2001/XMLSchema#base64Binary,value={data=[-41,93,-74]}}{dataTypeId=http://www.w3.org/2001/XMLSchema#base64Binary,value={data=[-106,-10,-29,34,62,60,97,117,116,104,111,114]}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // RFC822 name + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name\", " + + "\"Value\" : [ \"sne.else@A.COMPANY.com\",\"one.else@A.COMPANY.com\",\"someone.else@A.CONY.com\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name,value={localName=sne.else,domainName=A.COMPANY.com}}{dataTypeId=urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name,value={localName=one.else,domainName=A.COMPANY.com}}{dataTypeId=urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name,value={localName=someone.else,domainName=A.CONY.com}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"rfc822Name\", " + + "\"Value\" : [ \"sne.else@A.COMPANY.com\",\"one.else@A.COMPANY.com\",\"someone.else@A.CONY.com\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name,value={localName=sne.else,domainName=A.COMPANY.com}}{dataTypeId=urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name,value={localName=one.else,domainName=A.COMPANY.com}}{dataTypeId=urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name,value={localName=someone.else,domainName=A.CONY.com}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name\", " + + "\"Value\" : [ \"sne.else@A.COMPANY.com\",\"not a dns\",\"someone.else@A.CONY.com\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name\", " + + "\"Value\" : [ \"sne.else@A.COMPANY.com\",true,\"someone.else@A.CONY.com\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name\", " + + "\"Value\" : [ \"sne.else@A.COMPANY.com\",111,\"someone.else@A.CONY.com\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name\", " + + "\"Value\" : [ \"sne.else@A.COMPANY.com\",11.22,\"someone.else@A.CONY.com\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // x500 + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:1.0:data-type:x500Name\", " + + "\"Value\" : [ \"cn=Julius Hibbert, o=Medi Corporation, c=US\", \"cn=Julius Hibbert, o=Medi Corporation, c=US\", \"cn=Julius Hibbert, o=Medi Corporation, c=US\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:1.0:data-type:x500Name,value=CN=Julius Hibbert, O=Medi Corporation, C=US}{dataTypeId=urn:oasis:names:tc:xacml:1.0:data-type:x500Name,value=CN=Julius Hibbert, O=Medi Corporation, C=US}{dataTypeId=urn:oasis:names:tc:xacml:1.0:data-type:x500Name,value=CN=Julius Hibbert, O=Medi Corporation, C=US}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"x500Name\", " + + "\"Value\" : [ \"cn=Julius Hibbert, o=Medi Corporation, c=US\", \"cn=Julius Hibbert, o=Medi Corporation, c=US\", \"cn=Julius Hibbert, o=Medi Corporation, c=US\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:1.0:data-type:x500Name,value=CN=Julius Hibbert, O=Medi Corporation, C=US}{dataTypeId=urn:oasis:names:tc:xacml:1.0:data-type:x500Name,value=CN=Julius Hibbert, O=Medi Corporation, C=US}{dataTypeId=urn:oasis:names:tc:xacml:1.0:data-type:x500Name,value=CN=Julius Hibbert, O=Medi Corporation, C=US}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:1.0:data-type:x500Name\", " + + "\"Value\" : [ \"cn=Julius Hibbert, o=Medi Corporation, c=US\", \"non-x500 string\", \"cn=Julius Hibbert, o=Medi Corporation, c=US\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:1.0:data-type:x500Name\", " + + "\"Value\" : [ \"cn=Julius Hibbert, o=Medi Corporation, c=US\", true, \"cn=Julius Hibbert, o=Medi Corporation, c=US\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:1.0:data-type:x500Name\", " + + "\"Value\" : [ \"cn=Julius Hibbert, o=Medi Corporation, c=US\", 1111, \"cn=Julius Hibbert, o=Medi Corporation, c=US\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:1.0:data-type:x500Name\", " + + "\"Value\" : [ \"cn=Julius Hibbert, o=Medi Corporation, c=US\", 11.22, \"cn=Julius Hibbert, o=Medi Corporation, c=US\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // ipAddress + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:2.0:data-type:ipAddress\", " + + "\"Value\" : [ \"10.221.43.58:12345\",\"10.221.43.58:12345\",\"10.221.43.58:12345\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:ipAddress,value=10.221.43.58:12345-12345}{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:ipAddress,value=10.221.43.58:12345-12345}{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:ipAddress,value=10.221.43.58:12345-12345}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"ipAddress\", " + + "\"Value\" : [ \"10.221.43.58:12345\",\"10.221.43.58:12345\",\"10.221.43.58:12345\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:ipAddress,value=10.221.43.58:12345-12345}{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:ipAddress,value=10.221.43.58:12345-12345}{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:ipAddress,value=10.221.43.58:12345-12345}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:2.0:data-type:ipAddress\", " + + "\"Value\" : [ \"10.221.43.58:12345\",\"not an ip address\",\"10.221.43.58:12345\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:2.0:data-type:ipAddress\", " + + "\"Value\" : [ \"10.221.43.58:12345\",true,\"10.221.43.58:12345\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:2.0:data-type:ipAddress\", " + + "\"Value\" : [ \"10.221.43.58:12345\",1111,\"10.221.43.58:12345\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:2.0:data-type:ipAddress\", " + + "\"Value\" : [ \"10.221.43.58:12345\",11.22,\"10.221.43.58:12345\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // dnsName + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:2.0:data-type:dnsName\", " + + "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:dnsName,value={domainName=aValue}}{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:dnsName,value={domainName=aValue}}{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:dnsName,value={domainName=aValue}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"dnsName\", " + + "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:dnsName,value={domainName=aValue}}{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:dnsName,value={domainName=aValue}}{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:dnsName,value={domainName=aValue}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:2.0:data-type:dnsName\", " + + "\"Value\" : [ \"aValue\", true, \"aValue\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:dnsName,value={domainName=aValue}}{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:dnsName,value={domainName=true}}{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:dnsName,value={domainName=aValue}}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:2.0:data-type:dnsName\", " + + "\"Value\" : [ \"aValue\", 1111, \"aValue\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:2.0:data-type:dnsName\", " + + "\"Value\" : [ \"aValue\", 11.22, \"aValue\" ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // xPathExpression + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\", " + + "\"Value\" : [ " + + "{" + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + + "\"Namespaces\" : [" + + "{ "+ + "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + + "}," + + "{" + + "\"Prefix\" : \"md\", " + + "\"Namespace\" : \"urn:example:med:schemas:record\" " + + "}], "+ + "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ + "}," + + "{" + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + + "\"Namespaces\" : [" + + "{ "+ + "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + + "}," + + "{" + + "\"Prefix\" : \"md\", " + + "\"Namespace\" : \"urn:example:med:schemas:record\" " + + "}], "+ + "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ + "}," + + "{" + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + + "\"Namespaces\" : [" + + "{ "+ + "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + + "}," + + "{" + + "\"Prefix\" : \"md\", " + + "\"Namespace\" : \"urn:example:med:schemas:record\" " + + "}], "+ + "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ + "}" + + "] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression,value={path=md:record/md:patient/md:patientDoB,Namespace={[{md,urn:example:med:schemas:record}{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}]},status=null,xpathExpressionWrapped=null},xpathCategory=urn:oasis:names:tc:xacml:3.0:attribute-category:resource}{dataTypeId=urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression,value={path=md:record/md:patient/md:patientDoB,Namespace={[{md,urn:example:med:schemas:record}{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}]},status=null,xpathExpressionWrapped=null},xpathCategory=urn:oasis:names:tc:xacml:3.0:attribute-category:resource}{dataTypeId=urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression,value={path=md:record/md:patient/md:patientDoB,Namespace={[{md,urn:example:med:schemas:record}{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}]},status=null,xpathExpressionWrapped=null},xpathCategory=urn:oasis:names:tc:xacml:3.0:attribute-category:resource}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\", " + + "\"Value\" : [ " + + "{" + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + + "\"Namespaces\" : [" + + "{ "+ + "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + + "}," + + "{" + + "\"Prefix\" : \"md\", " + + "\"Namespace\" : \"urn:example:med:schemas:record\" " + + "}], "+ + "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ + "}," + + "\"simpleString\"," + + "{" + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + + "\"Namespaces\" : [" + + "{ "+ + "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + + "}," + + "{" + + "\"Prefix\" : \"md\", " + + "\"Namespace\" : \"urn:example:med:schemas:record\" " + + "}], "+ + "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ + "}" + + "] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\", " + + "\"Value\" : [ " + + "{" + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + + "\"Namespaces\" : [" + + "{ "+ + "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + + "}," + + "{" + + "\"Prefix\" : \"md\", " + + "\"Namespace\" : \"urn:example:med:schemas:record\" " + + "}], "+ + "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ + "}," + + "true," + + "{" + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + + "\"Namespaces\" : [" + + "{ "+ + "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + + "}," + + "{" + + "\"Prefix\" : \"md\", " + + "\"Namespace\" : \"urn:example:med:schemas:record\" " + + "}], "+ + "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ + "}" + + "] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\", " + + "\"Value\" : [ " + + "{" + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + + "\"Namespaces\" : [" + + "{ "+ + "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + + "}," + + "{" + + "\"Prefix\" : \"md\", " + + "\"Namespace\" : \"urn:example:med:schemas:record\" " + + "}], "+ + "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ + "}," + + "123," + + "{" + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + + "\"Namespaces\" : [" + + "{ "+ + "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + + "}," + + "{" + + "\"Prefix\" : \"md\", " + + "\"Namespace\" : \"urn:example:med:schemas:record\" " + + "}], "+ + "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ + "}" + + "] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\", " + + "\"Value\" : [ " + + "{" + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + + "\"Namespaces\" : [" + + "{ "+ + "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + + "}," + + "{" + + "\"Prefix\" : \"md\", " + + "\"Namespace\" : \"urn:example:med:schemas:record\" " + + "}], "+ + "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ + "}," + + "12.34," + + "{" + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + + "\"Namespaces\" : [" + + "{ "+ + "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + + "}," + + "{" + + "\"Prefix\" : \"md\", " + + "\"Namespace\" : \"urn:example:med:schemas:record\" " + + "}], "+ + "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ + "}" + + "] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + } + + + + + + + + @Test + public void testArrayNoDataTypes() { + + // array of size 0 + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // Category Attribute value array DataType Not given (repeat for all data types) + // Also tests for mixes of different JSON types (trying incorrect strings for XACML data types whenever possible) + // string + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [\"abc\", \"def\", \"hig\", \"lmn\"] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=abc}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=def}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=hig}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=lmn}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // SUCCESSFUL AUTO-CONVERT to DataType + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [\"abc\", true, \"hig\", \"lmn\"] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=abc}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=hig}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=lmn}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // SUCCESSFUL AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [\"abc\",123, \"hig\", \"lmn\"] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=abc}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=123}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=hig}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=lmn}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // SUCCESSFUL AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [\"abc\", 34.34, \"hig\", \"lmn\"] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=abc}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=34.34}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=hig}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=lmn}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // boolean + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [true, true, false, true, false ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#boolean,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#boolean,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#boolean,value=false}{dataTypeId=http://www.w3.org/2001/XMLSchema#boolean,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#boolean,value=false}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [true, \"abc\", false, true, false ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [true, 123, false, true, false ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [true, 12.34, false, true, false ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + + // integer + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [123, 456, 765, 234] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=123}{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=456}{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=765}{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=234}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [123, \"abc\", 765, 234] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [123, true, 765, 234] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + + // double + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ 123.34, 543.54, 3445.455, 4543,543 ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=123.34}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=543.54}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=3445.455}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=4543.0}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=543.0}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // special case - auto-convert integer to boolean + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ 123.34, 111122, 3445.455, 4543,543 ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=123.34}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=111122.0}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=3445.455}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=4543.0}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=543.0}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ 123.34, true, 3445.455, 4543,543 ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ 123.34, \"abb\", 3445.455, 4543,543 ] " + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // time - defaults to String + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"12:00:00Z\", \"12:00:00Z\", \"12:00:00Z\"] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=12:00:00Z}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=12:00:00Z}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=12:00:00Z}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // SUCCESSFUL AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"12:00:00Z\", true, \"12:00:00Z\"] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=12:00:00Z}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=12:00:00Z}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // SUCCESSFUL AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"12:00:00Z\", 123, \"12:00:00Z\"] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=12:00:00Z}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=123}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=12:00:00Z}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"12:00:00Z\", 12.34, \"12:00:00Z\"] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=12:00:00Z}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=12.34}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=12:00:00Z}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // date - defaults to String + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [\"2002-10-10\",\"2002-10-10\",\"2002-10-10\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [\"2002-10-10\",true,\"2002-10-10\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [\"2002-10-10\",123,\"2002-10-10\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=123}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [\"2002-10-10\",123.45,\"2002-10-10\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=123.45}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // dateTime - defaults to String + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"2002-10-10T12:00:00Z\",\"2002-10-10T12:00:00Z\",\"2002-10-10T12:00:00Z\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10T12:00:00Z}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10T12:00:00Z}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10T12:00:00Z}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"2002-10-10T12:00:00Z\",true,\"2002-10-10T12:00:00Z\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10T12:00:00Z}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10T12:00:00Z}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"2002-10-10T12:00:00Z\",123,\"2002-10-10T12:00:00Z\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10T12:00:00Z}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=123}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10T12:00:00Z}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"2002-10-10T12:00:00Z\",12.34,\"2002-10-10T12:00:00Z\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10T12:00:00Z}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=12.34}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10T12:00:00Z}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // dayTimeDuration - defaults to String + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"P23DT7H12M54S\",\"P23DT7H12M54S\",\"P23DT7H12M54S\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P23DT7H12M54S}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P23DT7H12M54S}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P23DT7H12M54S}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + //AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"P23DT7H12M54S\",true,\"P23DT7H12M54S\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P23DT7H12M54S}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P23DT7H12M54S}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"P23DT7H12M54S\",123,\"P23DT7H12M54S\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P23DT7H12M54S}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=123}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P23DT7H12M54S}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"P23DT7H12M54S\",11.22,\"P23DT7H12M54S\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P23DT7H12M54S}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=11.22}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P23DT7H12M54S}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // yearMonth duration - defaults to String + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"P165Y8M\",\"P165Y8M\",\"P165Y8M\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P165Y8M}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P165Y8M}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P165Y8M}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"P165Y8M\",true,\"P165Y8M\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P165Y8M}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P165Y8M}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"P165Y8M\",123,\"P165Y8M\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P165Y8M}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=123}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P165Y8M}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"P165Y8M\",11.22,\"P165Y8M\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P165Y8M}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=11.22}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P165Y8M}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // anyURI - defaults to String + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\",\"aValue\",\"aValue\"] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\",true,\"aValue\"] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\",123,\"aValue\"] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=123}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\",11.111,\"aValue\"] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=11.111}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // hexBinary - defaults to String + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"FA027B7D12CC34DDD20012AEEF\",\"FA027B7D12CC34DDD20012AEEF\",\"FA027B7D12CC34DDD20012AEEF\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=FA027B7D12CC34DDD20012AEEF}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=FA027B7D12CC34DDD20012AEEF}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=FA027B7D12CC34DDD20012AEEF}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"FA027B7D12CC34DDD20012AEEF\",true,\"012AEEF\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=FA027B7D12CC34DDD20012AEEF}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=012AEEF}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"FA027B7D12CC34DDD20012AEEF\",123,\"012AEEF\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=FA027B7D12CC34DDD20012AEEF}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=123}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=012AEEF}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"FA027B7D12CC34DDD20012AEEF\",11.44,\"012AEEF\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=FA027B7D12CC34DDD20012AEEF}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=11.44}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=012AEEF}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // base64Binary - defaults to String + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aG9y\",\"lvbj0iMS4xIj48YXV0aG9y\",\"lvbjIj48YXV0aG9y\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aG9y}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=lvbj0iMS4xIj48YXV0aG9y}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=lvbjIj48YXV0aG9y}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aG9y\",true,\"lvbjIj48YXV0aG9y\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aG9y}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=lvbjIj48YXV0aG9y}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aG9y\",1123,\"lvbjIj48YXV0aG9y\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aG9y}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=1123}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=lvbjIj48YXV0aG9y}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aG9y\",11.22,\"lvbjIj48YXV0aG9y\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aG9y}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=11.22}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=lvbjIj48YXV0aG9y}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // RFC822 name - defaults to String + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"sne.else@A.COMPANY.com\",\"one.else@A.COMPANY.com\",\"someone.else@A.CONY.com\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=sne.else@A.COMPANY.com}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=one.else@A.COMPANY.com}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=someone.else@A.CONY.com}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"sne.else@A.COMPANY.com\",true,\"someone.else@A.CONY.com\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=sne.else@A.COMPANY.com}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=someone.else@A.CONY.com}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"sne.else@A.COMPANY.com\",111,\"someone.else@A.CONY.com\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=sne.else@A.COMPANY.com}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=111}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=someone.else@A.CONY.com}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"sne.else@A.COMPANY.com\",11.22,\"someone.else@A.CONY.com\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=sne.else@A.COMPANY.com}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=11.22}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=someone.else@A.CONY.com}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // x500 - defaults to String + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"cn=Julius Hibbert, o=Medi Corporation, c=US\", \"cn=Julius Hibbert, o=Medi Corporation, c=US\", \"cn=Julius Hibbert, o=Medi Corporation, c=US\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=cn=Julius Hibbert, o=Medi Corporation, c=US}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=cn=Julius Hibbert, o=Medi Corporation, c=US}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=cn=Julius Hibbert, o=Medi Corporation, c=US}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"cn=Julius Hibbert, o=Medi Corporation, c=US\", true, \"cn=Julius Hibbert, o=Medi Corporation, c=US\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=cn=Julius Hibbert, o=Medi Corporation, c=US}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=cn=Julius Hibbert, o=Medi Corporation, c=US}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"cn=Julius Hibbert, o=Medi Corporation, c=US\", 1111, \"cn=Julius Hibbert, o=Medi Corporation, c=US\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=cn=Julius Hibbert, o=Medi Corporation, c=US}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=1111}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=cn=Julius Hibbert, o=Medi Corporation, c=US}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"cn=Julius Hibbert, o=Medi Corporation, c=US\", 11.22, \"cn=Julius Hibbert, o=Medi Corporation, c=US\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=cn=Julius Hibbert, o=Medi Corporation, c=US}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=11.22}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=cn=Julius Hibbert, o=Medi Corporation, c=US}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // ipAddress - defaults to String + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"10.221.43.58:12345\",\"10.221.43.58:12345\",\"10.221.43.58:12345\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=10.221.43.58:12345}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=10.221.43.58:12345}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=10.221.43.58:12345}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"10.221.43.58:12345\",true,\"10.221.43.58:12345\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=10.221.43.58:12345}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=10.221.43.58:12345}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"10.221.43.58:12345\",1111,\"10.221.43.58:12345\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=10.221.43.58:12345}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=1111}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=10.221.43.58:12345}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"10.221.43.58:12345\",11.22,\"10.221.43.58:12345\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=10.221.43.58:12345}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=11.22}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=10.221.43.58:12345}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // dnsName - defaults to String + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\", true, \"aValue\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\", 1111, \"aValue\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=1111}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\", 11.22, \"aValue\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=11.22}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // xPathExpression - defaults to String + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\", true, \"aValue\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\", 1111, \"aValue\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=1111}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + // AUTO-CONVERT + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\", 11.22, \"aValue\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=11.22}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + } + + + + + @Test + public void testXPathExpression() { + // Category Attribute with XPathExpression including XPathCategory and XPath + // Category Attribute with XPathExpression with Namespaces with/without Prefix + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"xpathExpression\", " + + "\"Value\" : {" + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + + "\"Namespaces\" : [" + + "{ "+ + "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + + "}," + + "{ "+ + "\"Prefix\" : \"lab\", " + + "\"Namespace\" : \"http://somewhere/uri.html\" " + + "}," + + "{" + + "\"Prefix\" : \"md\", " + + "\"Namespace\" : \"urn:example:med:schemas:record\" " + + "}], "+ + "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ + "}" + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression,value={path=md:record/md:patient/md:patientDoB,Namespace={[{md,urn:example:med:schemas:record}{lab,http://somewhere/uri.html}{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}]},status=null,xpathExpressionWrapped=null},xpathCategory=urn:oasis:names:tc:xacml:3.0:attribute-category:resource}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute with XPathExpression missing XPathCategory + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"xpathExpression\", " + + "\"Value\" : {" + + "\"Namespaces\" : [{ "+ + "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + + "}," + + "{" + + "\"Prefix\" : \"md\", " + + "\"Namespace\" : \"urn:example:med:schemas:record\" " + + "}], "+ + "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ + "}" + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute with XPathExpression missing XPath + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"xpathExpression\", " + + "\"Value\" : {" + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + + "\"Namespaces\" : [{ "+ + "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + + "}," + + "{" + + "\"Prefix\" : \"md\", " + + "\"Namespace\" : \"urn:example:med:schemas:record\" " + + "}] "+ + "}" + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute with XPathExpression without Namespaces + // (path does not contain namespace references) + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"xpathExpression\", " + + "\"Value\" : {" + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + + "\"XPath\" : \"record/patient/patientDoB\" "+ + "}" + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression,value={path=record/patient/patientDoB,Namespace=null,status=null,xpathExpressionWrapped=null},xpathCategory=urn:oasis:names:tc:xacml:3.0:attribute-category:resource}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute with XPathExpression with 0 Namespaces + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"xpathExpression\", " + + "\"Value\" : {" + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + + "\"Namespaces\" : [], "+ + "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ + "}" + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression,value={path=md:record/md:patient/md:patientDoB,Namespace=null,status=null,xpathExpressionWrapped=null},xpathCategory=urn:oasis:names:tc:xacml:3.0:attribute-category:resource}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // Category Attribute with XPathExpression with Namespaces without mandatory Namespace + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"xpathExpression\", " + + "\"Value\" : {" + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + + "\"Namespaces\" : [{ "+ + "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + + "}," + + "{" + + "\"Prefix\" : \"md\", " + + "}], "+ + "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ + "}" + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"xpathExpression\", " + + "\"Value\" : {" + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + + "\"Namespaces\" : [{ "+ + "}," + + "{" + + "\"Prefix\" : \"md\", " + + "\"Namespace\" : \"urn:example:med:schemas:record\" " + + "}], "+ + "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ + "}" + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute with XPathExpression with Namespaces with 2 namespaces using same prefix + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"xpathExpression\", " + + "\"Value\" : {" + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + + "\"Namespaces\" : [{ "+ + "\"Prefix\" : \"md\", " + + "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + + "}," + + "{" + + "\"Prefix\" : \"md\", " + + "\"Namespace\" : \"urn:example:med:schemas:record\" " + + "}], "+ + "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ + "}" + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute with XPathExpression without Namespaces which are used within the XPathExpression (NOTE: Error is not syntactic and is not found by converter) + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"xpathExpression\", " + + "\"Value\" : {" + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + + "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ + "}" + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression,value={path=md:record/md:patient/md:patientDoB,Namespace=null,status=null,xpathExpressionWrapped=null},xpathCategory=urn:oasis:names:tc:xacml:3.0:attribute-category:resource}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute with XPathExpression containing simple value (must be object) + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"xpathExpression\", " + + "\"Value\" : \"simple Value\"" + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute with Namespaces containing simple value (must be object) + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"xpathExpression\", " + + "\"Value\" : {" + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + + "\"Namespaces\" : [ \"simpleValue\"," + + "{" + + "\"Prefix\" : \"md\", " + + "\"Namespace\" : \"urn:example:med:schemas:record\" " + + "}], "+ + "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ + "}" + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // Category Attribute with Namespaces non-string Namespace + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"xpathExpression\", " + + "\"Value\" : {" + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + + "\"Namespaces\" : [ {" + + "\"Prefix\" : \"md\", " + + "\"Namespace\" : 123 " + + "}], "+ + "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ + "}" + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute with Namespaces non-string prefix + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"xpathExpression\", " + + "\"Value\" : {" + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + + "\"Namespaces\" : [ {" + + "\"Prefix\" : 123, " + + "\"Namespace\" : \"urn:example:med:schemas:record\" " + + "}], "+ + "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ + "}" + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute with Namespaces non-string XPathCategory + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"xpathExpression\", " + + "\"Value\" : {" + + "\"XPathCategory\" : 123," + + "\"Namespaces\" : [ {" + + "\"Prefix\" : \"md\", " + + "\"Namespace\" : \"urn:example:med:schemas:record\" " + + "}], "+ + "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ + "}" + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category Attribute with Namespaces non-string XPath + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"xpathExpression\", " + + "\"Value\" : {" + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + + "\"Namespaces\" : [ {" + + "\"Prefix\" : \"md\", " + + "\"Namespace\" : \"urn:example:med:schemas:record\" " + + "}], "+ + "\"XPath\" : 123 "+ + "}" + + "}] } ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + } + + + + @Test + public void testContent() { + + // Category with Content in XML, escaped properly + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\",\"aValue\",\"aValue\"] " + + "}]," + + "\"Content\" : \"" + + "Gambardella, MatthewXML Developer's GuideComputer" + + "44.952000-10-01An in-depth look at creating applications with XML."+ + "\"" + + "} ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]},contentRoot=[catalog: null]}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category with Content in XML, double quotes and back-slashes NOT escaped properly? + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\",\"aValue\",\"aValue\"] " + + "}]," + + "\"Content\" : \"" + + "Gambardella, MatthewXML Developer's GuideComputer" + + "44.952000-10-01An in-depth look at creating applications with XML."+ + "\"" + + "} ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category with Content in Base64 + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\",\"aValue\",\"aValue\"] " + + "}]," + + "\"Content\" : \"PD94bWwgdmVyc2lvbj0iMS4wIj8+PGNhdGFsb2c+PGJvb2sgaWQ9ImJrMTAxIj48YXV0aG9yPkdhbWJhcmRlbGxhLCBNYXR0aGV3PC9hdXRob3I+PHRpdGxlPlhNT" + + "CBEZXZlbG9wZXIncyBHdWlkZTwvdGl0bGU+PGdlbnJlPkNvbXB1dGVyPC9nZW5yZT48cHJpY2U+NDQuOTU8L3ByaWNlPjxwdWJsaXNoX2RhdGU+MjAwMC0xMC0wMTwvcHVibGlzaF"+ + "9kYXRlPjxkZXNjcmlwdGlvbj5BbiBpbi1kZXB0aCBsb29rIGF0IGNyZWF0aW5nIGFwcGxpY2F0aW9ucyB3aXRoIFhNTC48L2Rlc2NyaXB0aW9uPjwvYm9vaz48L2NhdGFsb2c+\"" + + "} ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]},contentRoot=[catalog: null]}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Category with Bad Content in Base64 + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\",\"aValue\",\"aValue\"] " + + "}]," + + "\"Content\" : \"PD94bWwgdmV\"" + + "} ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + } + + + + + @Test + public void testDuplicates() { + // duplicate of same element within Category array is ok + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#string\", " + + "\"Value\" : \"abc\" " + + "}] }, " + + "{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#string\", " + + "\"Value\" : \"abc\" " + + "}] } " + + "] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=abc}],includeInResults=false}]}}{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=abc}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // duplicate Attribute + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [" + + "{\"CategoryId\" : \"custom-category\"," + + " \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#string\", " + + "\"Value\" : \"abc\" " + + "}], " + + " \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#string\", " + + "\"Value\" : \"abc\" " + + "}] " + + "} " + + " }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // dup id + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#string\", " + + "\"Value\" : \"abc\" " + + "}] } " + + "] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // dup DataType + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#string\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#string\", " + + "\"Value\" : \"abc\" " + + "}] } " + + "] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // dup Value + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#string\", " + + "\"Value\" : \"abc\" " + + "\"Value\" : \"abc\" " + + "}] } " + + "] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // duplicate Content + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{" + + "\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\",\"aValue\",\"aValue\"] " + + "}]," + + "\"Content\" : \"" + + "Gambardella, MatthewXML Developer's GuideComputer" + + "44.952000-10-01An in-depth look at creating applications with XML."+ + "\" , " + + "\"Content\" : \"" + + "Gambardella, MatthewXML Developer's GuideComputer" + + "44.952000-10-01An in-depth look at creating applications with XML."+ + "\"" + + "} ] }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + } + + + +//TODO - Shorthand for CategoryId ???? + + +} diff --git a/ECOMP-XACML/src/test/java/org/openecomp/policy/xacml/test/json/RequestConformanceTest.java b/ECOMP-XACML/src/test/java/org/openecomp/policy/xacml/test/json/RequestConformanceTest.java new file mode 100644 index 000000000..6c30cb481 --- /dev/null +++ b/ECOMP-XACML/src/test/java/org/openecomp/policy/xacml/test/json/RequestConformanceTest.java @@ -0,0 +1,253 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-XACML + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.xacml.test.json; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import java.io.File; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; + +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +import org.junit.Test; + +import com.att.research.xacml.api.Request; +import com.att.research.xacml.api.RequestAttributes; +import com.att.research.xacml.api.RequestReference; +import com.att.research.xacml.std.dom.DOMRequest; +import com.att.research.xacml.std.json.JSONRequest; +import com.att.research.xacml.std.json.JSONStructureException; +/** + * Test JSON Request convert to object - Conformance tests + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * NOTE: + * The "correct" way to verify that each JSON string gets translated into our internal Objects correctly is to look explicitly at each of the child objects + * and verify that they are correct. This would involve a lot of coding to get child of child of child and individually verify each property of each element. + * To simplify testing we assume that request.toString() correctly includes a complete text representation of every sub-component of the Request object + * and we compare the resulting String to our expected String. + * This has two possible sources of error: + * - toString might not include some sub-component, and + * - the initial verification of the resulting string is done by hand and may have been incorrect. + * + * + */ +public class RequestConformanceTest { + + // where to find the conformance test XML files + private final String CONFORMANCE_DIRECTORY_PATH = "testsets/conformance/xacml3.0-ct-v.0.4"; + + // The request object output from each test conversion from JSON string + Request request; + + + + + + // test just one of each top-level element. + // For simple elements also test for incorrect type + @Test + public void testConformanceRequests() { + + List filesInDirectory = null; + + File conformanceDirectory = null; + + File currentFile = null; + + try { + conformanceDirectory = new File(CONFORMANCE_DIRECTORY_PATH); + filesInDirectory = getRequestsInDirectory(conformanceDirectory); + } catch (Exception e) { + fail("Unable to set up Conformance tests for dir '" + conformanceDirectory.getAbsolutePath()+"' e="+ e); + } + + // run through each XML file + // - load the file from XML into an internal Request object + // - generate the JSON representation of that Request object + // - load that JSON representation into a new Request object + // - compare the 2 Request objects + Request xmlRequest = null; + Request jsonRequest = null; + try { + for (File f : filesInDirectory) { + currentFile = f; + +//// This is a simple way to select just one file for debugging - comment out when not being used +//if ( ! f.getName().equals("IIA023Request.xml")) { continue; } + +// during debugging it is helpful to know what file it is starting to work on +// System.out.println("starting file="+currentFile.getName()); + + try { + // load XML into a Request object + xmlRequest = DOMRequest.load(f); + xmlRequest.getStatus(); + } catch (Exception e) { + // if XML does not load, just note it and continue with next file + System.out.println("XML file did not load: '" + f.getName() + " e=" + e); + continue; + } + +//System.out.println(JSONRequest.toString(xmlRequest, false)); + + // generate JSON from the Request + String jsonString = JSONRequest.toString(xmlRequest, false); + + // load JSON into a Request + jsonRequest = JSONRequest.load(jsonString); + + // compare the two Request objects + + // check simple things first + assertEquals("File '" + currentFile.getName() + "' CombinedDecision", xmlRequest.getCombinedDecision(), jsonRequest.getCombinedDecision()); + assertEquals("File '" + currentFile.getName() + "' getReturnPolicyIdList", xmlRequest.getReturnPolicyIdList(), jsonRequest.getReturnPolicyIdList()); + assertEquals("File '" + currentFile.getName() + "' requestDefaults", xmlRequest.getRequestDefaults(), jsonRequest.getRequestDefaults()); + + // multiRequests (guaranteed to not be null) + // We do NOT care about ordering, so compare the two collections inefficiently + Collection xmlCollection = xmlRequest.getMultiRequests(); + Collection jsonCollection = jsonRequest.getMultiRequests(); + String errorMessage = null; + if (jsonCollection.size() != xmlCollection.size()) { + errorMessage = "File '" + currentFile.getName() + "' MultiRequests not same size. "; + } else if (! jsonCollection.containsAll(xmlCollection)) { + errorMessage = "File '" + currentFile.getName() + "' MultiRequests have different contents. "; + } + if (errorMessage != null) { + String xmlContents = ""; + String jsonContents = ""; + Iterator rrIt = xmlCollection.iterator(); + while (rrIt.hasNext()) { + xmlContents += "\n " + rrIt.next().toString(); + } + rrIt = jsonCollection.iterator(); + while (rrIt.hasNext()) { + jsonContents += "\n " + rrIt.next().toString(); + } + fail(errorMessage + "\nXML(" + xmlCollection.size() + ")='" + xmlContents + + "' \nJSON(" + jsonCollection.size() + ")='" + jsonContents + + "'" + + "\njson='" + jsonString + "'"); + } + + // attributes (guaranteed to not be null) + // We do NOT care about ordering, so compare the two collections inefficiently + Collection xmlAttrCollection = xmlRequest.getRequestAttributes(); + Collection jsonAttrCollection = jsonRequest.getRequestAttributes(); + errorMessage = null; + if (jsonAttrCollection.size() != xmlAttrCollection.size()) { + errorMessage = "File '" + currentFile.getName() + "' RequestAttributes not same size. "; + } else if (! jsonAttrCollection.containsAll(xmlAttrCollection)) { + String attrName = ""; + Iterator rait = xmlAttrCollection.iterator(); + while (rait.hasNext()) { + RequestAttributes ra = rait.next(); + if (jsonAttrCollection.contains(ra) == false) { + attrName = ra.toString(); + } + } + errorMessage = "File '" + currentFile.getName() + "' RequestAttributes have different contents. JSON is missing attr=" + attrName; + } + if (errorMessage != null) { + String xmlContents = ""; + String jsonContents = ""; + Iterator rrIt = xmlAttrCollection.iterator(); + while (rrIt.hasNext()) { + RequestAttributes ras = rrIt.next(); + xmlContents += "\n " + ras.toString(); + if (ras.getContentRoot() != null) { + StringWriter writer = new StringWriter(); + Transformer transformer = null; + try { + transformer = TransformerFactory.newInstance().newTransformer(); + transformer.transform(new DOMSource(ras.getContentRoot()), new StreamResult(writer)); + } catch (Exception e) { + throw new JSONStructureException("Unable to Content node to string; e="+e); + } + + xmlContents += "\n Content: " + writer.toString(); + } + } + rrIt = jsonAttrCollection.iterator(); + while (rrIt.hasNext()) { + RequestAttributes ras = rrIt.next(); + jsonContents += "\n " + ras.toString(); + if (ras.getContentRoot() != null) { + StringWriter writer = new StringWriter(); + Transformer transformer = null; + try { + transformer = TransformerFactory.newInstance().newTransformer(); + transformer.transform(new DOMSource(ras.getContentRoot()), new StreamResult(writer)); + } catch (Exception e) { + throw new JSONStructureException("Unable to Content node to string; e="+e); + } + + jsonContents += "\n Content: " + writer.toString(); + } + } + fail(errorMessage + "\nXML(" + xmlAttrCollection.size() + ")='" + xmlContents + + "' \nJSON(" + jsonAttrCollection.size() + ")='" + jsonContents + + "\njson='" + jsonString + "'"); + } + + + } + + } catch (Exception e) { + fail ("Failed test with '" + currentFile.getName() + "', e=" + e); + } + + + } + + // + // HELPER to get list of all Request files in the given directory + // + + private List getRequestsInDirectory(File directory) { + List fileList = new ArrayList(); + + File[] fileArray = directory.listFiles(); + for (File f : fileArray) { + if (f.isDirectory()) { + List subDirList = getRequestsInDirectory(f); + fileList.addAll(subDirList); + } + if (f.getName().endsWith("Request.xml")) { + fileList.add(f); + } + } + return fileList; + + } + +} \ No newline at end of file diff --git a/ECOMP-XACML/src/test/java/org/openecomp/policy/xacml/test/json/RequestDefaultCategoryTest.java b/ECOMP-XACML/src/test/java/org/openecomp/policy/xacml/test/json/RequestDefaultCategoryTest.java new file mode 100644 index 000000000..a5929a4d8 --- /dev/null +++ b/ECOMP-XACML/src/test/java/org/openecomp/policy/xacml/test/json/RequestDefaultCategoryTest.java @@ -0,0 +1,1427 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-XACML + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.xacml.test.json; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import org.junit.Test; + +import com.att.research.xacml.api.Request; +import com.att.research.xacml.std.json.JSONRequest; +import com.att.research.xacml.std.json.JSONStructureException; +/** + * Test JSON Request convert to object - Default Category object tests + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * NOTE: + * The "correct" way to verify that each JSON string gets translated into our internal Objects correctly is to look explicitly at each of the child objects + * and verify that they are correct. This would involve a lot of coding to get child of child of child and individually verify each property of each element. + * To simplify testing we assume that request.toString() correctly includes a complete text representation of every sub-component of the Request object + * and we compare the resulting String to our expected String. + * This has two possible sources of error: + * - toString might not include some sub-component, and + * - the initial verification of the resulting string is done by hand and may have been incorrect. + * + * + */ +public class RequestDefaultCategoryTest { + + // The request object output from each test conversion from JSON string + Request request; + + + /* + * Request that uses all fields with both single and multiple entries + */ + String allFieldsRequest = + "{\"Request\": {" + + "\"ReturnPolicyIdList\" : true ," + + "\"CombinedDecision\" : true ," + + "\"XPathVersion\" : \"http://www.w3.org/TR/1999/REC-xpath-19991116\"," + + "\"MultiRequests\" : {" + + "\"RequestReference\": [" + + "{ " + + "\"ReferenceId\" : [\"foo1\",\"bar1\"]" + + "}," + + "{" + + "\"ReferenceId\" : [\"foo2\",\"bar1\"]" + + "}]" + + "}," + + + "\"Category\": [" + + "{ " + + "\"CategoryId\": \"custom-category\", " + + "\"Id\" : \"customId\", " + + "\"Attribute\" : [" + + "{" + + "\"AttributeId\" : \"document-id\", " + + "\"DataType\" : \"integer\", " + + "\"Value\" : 123 " + + "}, " + + "{" + + "\"AttributeId\" : \"document-url\", " + + "\"DataType\" : \"anyURI\", " + + "\"Value\" : \"http://somewhere.over.the.com/rainbow\" " + + "}, " + + "{" + + "\"AttributeId\" : \"page-list\", " + + "\"Value\" : [1, 2, 3, 4.5, 3, 2, 1] " + + "} " + + "]" + + "}, " + + "{ " + + "\"CategoryId\": \"another-custom-cat\", " + + "\"Id\" : \"anotherXmlId\", " + + "\"Attribute\" : []" + + "} " + + "], " + + + "\"AccessSubject\":{ " + + "\"Content\" : \"" + + "Gambardella, MatthewXML Developer's GuideComputer" + + "44.952000-10-01An in-depth look at creating applications with XML."+ + "\"," + + "\"Attribute\" : []" + + "}, " + + + "\"Resource\" : {" + + "\"Content\" : \"PD94bWwgdmVyc2lvbj0iMS4wIj8+PGNhdGFsb2c+PGJvb2sgaWQ9ImJrMTAxIj48YXV0aG9yPkdhbWJhcmRlbGxhLCBNYXR0aGV3PC9hdXRob3I+PHRpdGxlPlhNT" + + "CBEZXZlbG9wZXIncyBHdWlkZTwvdGl0bGU+PGdlbnJlPkNvbXB1dGVyPC9nZW5yZT48cHJpY2U+NDQuOTU8L3ByaWNlPjxwdWJsaXNoX2RhdGU+MjAwMC0xMC0wMTwvcHVibGlzaF"+ + "9kYXRlPjxkZXNjcmlwdGlvbj5BbiBpbi1kZXB0aCBsb29rIGF0IGNyZWF0aW5nIGFwcGxpY2F0aW9ucyB3aXRoIFhNTC48L2Rlc2NyaXB0aW9uPjwvYm9vaz48L2NhdGFsb2c+\"" + + + + "} " + + + + "}}"; + + /* + * The following example comes directly from the JSON Profile Spec + */ + String exampleFromSpec = "{ " + + "\"Request\" : { " + + "\"AccessSubject\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "}, " + + "\"Action\" : { " + + "\"Attribute\": " + + "{ " + + "\"Id\" : \"action-id\", " + + "\"Value\" : \"http://www.xacml.eu/buy\", " + + "\"DataType\" : \"anyURI\" " + + "} " + + "}, " + + "\"Resource\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"book-title\", " + + "\"Value\" : \"Learn German in 90 days\" " + + "}, " + + "{ " + + "\"Id\" : \"currency\", " + + "\"Value\" : \"SEK\" " + + "}, " + + "{ " + + "\"Id\" : \"price\", " + + "\"Value\" : 123.34 " + + "} " + + "] " + + "} " + + "} " + + "} "; + + + /* + * The following example comes directly from the JSON Profile Spec (modified to include a "" missing from both examples). + * It shows the two ways of handling XPath content, as escaped XML and as Base64 encoding. + */ + String xPathExampleFromSpec = "{ " + + "\"Request\" : { " + + "\"Resource\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"urn:oasis:names:tc:xacml:3.0:content-selector\", " + + "\"DataType\" : \"xpathExpression\", " + + "\"Value\" : { " + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\", " + + "\"Namespaces\" : [{ " + + "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + + "}, " + + "{ " + + "\"Prefix\" : \"md\", " + + "\"Namespace\" : \"urn:example:med:schemas:record\" " + + "} " + + "], " + + "\"XPath\" : \"md:record/md:patient/md:patientDoB\" " + + "} " + + "} " + + "] " + + "} " + + "} " + + "} "; + + + // test Shorthand Category notation for elements not tested in their own section below. + // Categories that are more commonly used are fully tested. + // Given that the functions within the categories are the same irrespective of the name of the category, + // we assume that the contents of the category will work ok once the Shorthand notation is recognized, so all we need to test is the shorthand + // The ones that are tested in their own sections are: + // AccessSubject + // Action + // Resource + // Environment + // test Subject + @Test + public void testCategoryShorthand() { + + // RecipientSubject present both as element within Category and as separate RecipientSubject element at same level as Category + try { + request = JSONRequest.load("{\"Request\" : {" + + "\"Category\": [" + + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:recipient-subject\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + + "}] }, " + + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:recipient-subject\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"aValue\"" + + "}] } " + + "]," + + "\"RecipientSubject\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:recipient-subject,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:recipient-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:recipient-subject,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:recipient-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:recipient-subject,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:recipient-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:1.0:subject-category:recipient-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // IntermediarySubject present both as element within Category and as separate IntermediarySubject element at same level as Category + try { + request = JSONRequest.load("{\"Request\" : {" + + "\"Category\": [" + + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:intermediary-subject\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + + "}] }, " + + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:intermediary-subject\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"aValue\"" + + "}] } " + + "]," + + "\"IntermediarySubject\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:intermediary-subject,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:intermediary-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:intermediary-subject,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:intermediary-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:intermediary-subject,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:intermediary-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:1.0:subject-category:intermediary-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // Codebase present both as element within Category and as separate Codebase element at same level as Category + try { + request = JSONRequest.load("{\"Request\" : {" + + "\"Category\": [" + + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:codebase\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + + "}] }, " + + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:codebase\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"aValue\"" + + "}] } " + + "]," + + "\"Codebase\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:codebase,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:codebase,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:codebase,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:codebase,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:codebase,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:codebase,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:1.0:subject-category:codebase,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + + // RequestingMachine present both as element within Category and as separate RequestingMachine element at same level as Category + try { + request = JSONRequest.load("{\"Request\" : {" + + "\"Category\": [" + + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:requesting-machine\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + + "}] }, " + + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:requesting-machine\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"aValue\"" + + "}] } " + + "]," + + "\"RequestingMachine\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:requesting-machine,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:requesting-machine,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:requesting-machine,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:requesting-machine,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:requesting-machine,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:requesting-machine,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:1.0:subject-category:requesting-machine,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + } + + + + + + + + + + + + + + + + + // test AccessSubject + // Include test for backward compatibility with "Subject" + @Test + public void testAccessSubjectRequest() { + + // AccessSubject absent + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // AccessSubject as normal element under Category (with CategoryId==subject category id) + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:access-subject\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"aValue\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // multiple AccessSubjects under Category + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [" + + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:access-subject\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + + "}] }, " + + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:access-subject\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"aValue\"" + + "}] } " + + "] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // AccessSubject present both as element within Category and as separate AccessSubject element at same level as Category + try { + request = JSONRequest.load("{\"Request\" : {" + + "\"Category\": [" + + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:access-subject\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + + "}] }, " + + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:access-subject\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"aValue\"" + + "}] } " + + "]," + + "\"AccessSubject\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // AccessSubject present, no other Category element + try { + request = JSONRequest.load("{\"Request\" : {" + + + "\"AccessSubject\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // Subject present, no other Category element (Backward Compatibility + try { + request = JSONRequest.load("{\"Request\" : {" + + + "\"Subject\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // AccessSubject present, 1/multiple other Category element also present + try { + request = JSONRequest.load("{\"Request\" : {" + + "\"Category\": [" + + "{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"aValue\"" + + "}] } " + + "]," + + "\"AccessSubject\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // 2 AccessSubjects - duplicates fail + try { + request = JSONRequest.load("{\"Request\" : {" + + + "\"AccessSubject\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + + "\"AccessSubject\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // AccessSubject with correct Category value + try { + request = JSONRequest.load("{\"Request\" : {" + + + "\"AccessSubject\" : { " + + "\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:access-subject\" ," + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // AccessSubject with wrong Category value + try { + request = JSONRequest.load("{\"Request\" : {" + + + "\"AccessSubject\" : { " + + "\"CategoryId\" : \"notthesubject\" ," + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // AccessSubject with array of sub-object AccessSubjects (Multi Decision) + try { + request = JSONRequest.load("{\"Request\" : {" + + + "\"AccessSubject\" : [" + + "{ " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "}, " + + "{ " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Arless\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Somewhere\" " + + "} " + + "] " + + "}, " + + "{ " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Barry\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Elsewhere\" " + + "} " + + "] " + + "} " + + "]" + + " }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Arless}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Somewhere}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Barry}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Elsewhere}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + } + + + + + + + + + + // Action ... duplicate all AccessSubject tests... + // test Action + @Test + public void testActionRequest() { + + // Action absent + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Action as normal element under Category (with CategoryId==subject category id) + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"aValue\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // multiple Actions under Category + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [" + + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + + "}] }, " + + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"aValue\"" + + "}] } " + + "] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Action present both as element within Category and as separate Action element at same level as Category + try { + request = JSONRequest.load("{\"Request\" : {" + + "\"Category\": [" + + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + + "}] }, " + + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"aValue\"" + + "}] } " + + "]," + + "\"Action\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Action present, no other Category element + try { + request = JSONRequest.load("{\"Request\" : {" + + + "\"Action\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Action present, 1/multiple other Category element also present + try { + request = JSONRequest.load("{\"Request\" : {" + + "\"Category\": [" + + "{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"aValue\"" + + "}] } " + + "]," + + "\"Action\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // 2 Actions - duplicates fail + try { + request = JSONRequest.load("{\"Request\" : {" + + + "\"Action\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + + "\"Action\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Action with correct Category value + try { + request = JSONRequest.load("{\"Request\" : {" + + + "\"Action\" : { " + + "\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:action\" ," + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Action with wrong Category value + try { + request = JSONRequest.load("{\"Request\" : {" + + + "\"Action\" : { " + + "\"CategoryId\" : \"notthesubject\" ," + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Action with array of sub-object Actions (Multi Decision) + try { + request = JSONRequest.load("{\"Request\" : {" + + + "\"Action\" : [" + + "{ " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "}, " + + "{ " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Arless\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Somewhere\" " + + "} " + + "] " + + "}, " + + "{ " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Barry\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Elsewhere\" " + + "} " + + "] " + + "} " + + "]" + + " }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Arless}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Somewhere}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Barry}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Elsewhere}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + } + + + + + // Resource ... duplicate all AccessSubject tests... + // test Resource + @Test + public void testResourceRequest() { + + // Resource absent + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Resource as normal element under Category (with CategoryId==subject category id) + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"aValue\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // multiple Resources under Category + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [" + + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + + "}] }, " + + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"aValue\"" + + "}] } " + + "] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Resource present both as element within Category and as separate Resource element at same level as Category + try { + request = JSONRequest.load("{\"Request\" : {" + + "\"Category\": [" + + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + + "}] }, " + + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"aValue\"" + + "}] } " + + "]," + + "\"Resource\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Resource present, no other Category element + try { + request = JSONRequest.load("{\"Request\" : {" + + + "\"Resource\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Resource present, 1/multiple other Category element also present + try { + request = JSONRequest.load("{\"Request\" : {" + + "\"Category\": [" + + "{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"aValue\"" + + "}] } " + + "]," + + "\"Resource\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // 2 Resources - duplicates fail + try { + request = JSONRequest.load("{\"Request\" : {" + + + "\"Resource\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + + "\"Resource\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Resource with correct Category value + try { + request = JSONRequest.load("{\"Request\" : {" + + + "\"Resource\" : { " + + "\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\" ," + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Resource with wrong Category value + try { + request = JSONRequest.load("{\"Request\" : {" + + + "\"Resource\" : { " + + "\"CategoryId\" : \"notthesubject\" ," + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Resource with array of sub-object Resources (Multi Decision) + try { + request = JSONRequest.load("{\"Request\" : {" + + + "\"Resource\" : [" + + "{ " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "}, " + + "{ " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Arless\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Somewhere\" " + + "} " + + "] " + + "}, " + + "{ " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Barry\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Elsewhere\" " + + "} " + + "] " + + "} " + + "]" + + " }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Arless}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Somewhere}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Barry}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Elsewhere}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + } + + + + + + + // Environment ... duplicate all AccessSubject tests ... + // test Environment + @Test + public void testEnvironmentRequest() { + + // Environment absent + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Environment as normal element under Category (with CategoryId==subject category id) + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"aValue\" " + + "}] } ] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // multiple Environments under Category + try { + request = JSONRequest.load("{\"Request\" : {\"Category\": [" + + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + + "}] }, " + + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"aValue\"" + + "}] } " + + "] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Environment present both as element within Category and as separate Environment element at same level as Category + try { + request = JSONRequest.load("{\"Request\" : {" + + "\"Category\": [" + + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + + "}] }, " + + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"aValue\"" + + "}] } " + + "]," + + "\"Environment\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Environment present, no other Category element + try { + request = JSONRequest.load("{\"Request\" : {" + + + "\"Environment\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Environment present, 1/multiple other Category element also present + try { + request = JSONRequest.load("{\"Request\" : {" + + "\"Category\": [" + + "{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + + "\"Id\" : \"document-id\", " + + "\"Value\" : \"aValue\"" + + "}] } " + + "]," + + "\"Environment\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // 2 Environments - duplicates fail + try { + request = JSONRequest.load("{\"Request\" : {" + + + "\"Environment\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + + "\"Environment\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Environment with correct Category value + try { + request = JSONRequest.load("{\"Request\" : {" + + + "\"Environment\" : { " + + "\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\" ," + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Environment with wrong Category value + try { + request = JSONRequest.load("{\"Request\" : {" + + + "\"Environment\" : { " + + "\"CategoryId\" : \"notthesubject\" ," + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "} " + + " }}"); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Environment with array of sub-object Environments (Multi Decision) + try { + request = JSONRequest.load("{\"Request\" : {" + + + "\"Environment\" : [" + + "{ " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "}, " + + "{ " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Arless\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Somewhere\" " + + "} " + + "] " + + "}, " + + "{ " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Barry\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Elsewhere\" " + + "} " + + "] " + + "} " + + "]" + + " }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Arless}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Somewhere}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Barry}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Elsewhere}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + } + + +} diff --git a/ECOMP-XACML/src/test/java/org/openecomp/policy/xacml/test/json/RequestMainTest.java b/ECOMP-XACML/src/test/java/org/openecomp/policy/xacml/test/json/RequestMainTest.java new file mode 100644 index 000000000..198ba3ae6 --- /dev/null +++ b/ECOMP-XACML/src/test/java/org/openecomp/policy/xacml/test/json/RequestMainTest.java @@ -0,0 +1,1076 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-XACML + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.xacml.test.json; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import org.junit.Test; + +import com.att.research.xacml.api.Request; +import com.att.research.xacml.std.json.JSONRequest; +import com.att.research.xacml.std.json.JSONStructureException; +/** + * Test JSON Request convert to object - High-level Request-as-a-whole tests including test that fills in all fields with multiple values (where appropriate) + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * NOTE: + * The "correct" way to verify that each JSON string gets translated into our internal Objects correctly is to look explicitly at each of the child objects + * and verify that they are correct. This would involve a lot of coding to get child of child of child and individually verify each property of each element. + * To simplify testing we assume that request.toString() correctly includes a complete text representation of every sub-component of the Request object + * and we compare the resulting String to our expected String. + * This has two possible sources of error: + * - toString might not include some sub-component, and + * - the initial verification of the resulting string is done by hand and may have been incorrect. + * + * + */ +public class RequestMainTest { + + // The request object output from each test conversion from JSON string + Request request; + + + /* + * Request that uses all fields with both single and multiple entries + */ + String allFieldsRequest = + "{\"Request\": {" + + "\"ReturnPolicyIdList\" : true ," + + "\"CombinedDecision\" : true ," + + "\"XPathVersion\" : \"http://www.w3.org/TR/1999/REC-xpath-19991116\"," + + "\"MultiRequests\" : {" + + "\"RequestReference\": [" + + "{ " + + "\"ReferenceId\" : [\"foo1\",\"bar1\"]" + + "}," + + "{" + + "\"ReferenceId\" : [\"foo2\",\"bar1\"]" + + "}]" + + "}," + + + "\"Category\": [" + + "{ " + + "\"CategoryId\": \"custom-category\", " + + "\"Id\" : \"customId\", " + + "\"Attribute\" : [" + + "{" + + "\"AttributeId\" : \"document-id\", " + + "\"DataType\" : \"integer\", " + + "\"Value\" : 123 " + + "}, " + + "{" + + "\"AttributeId\" : \"document-url\", " + + "\"DataType\" : \"anyURI\", " + + "\"Value\" : \"http://somewhere.over.the.com/rainbow\" " + + "}, " + + "{" + + "\"AttributeId\" : \"page-list\", " + + "\"Value\" : [1, 2, 3, 4.5, 3, 2, 1] " + + "} " + + "]" + + "}, " + + "{ " + + "\"CategoryId\": \"another-custom-cat\", " + + "\"Id\" : \"anotherXmlId\", " + + "\"Attribute\" : []" + + "} " + + "], " + + + "\"AccessSubject\":{ " + + "\"Content\" : \"" + + "Gambardella, MatthewXML Developer's GuideComputer" + + "44.952000-10-01An in-depth look at creating applications with XML."+ + "\"," + + "\"Attribute\" : []" + + "}, " + + + "\"Resource\" : {" + + "\"Content\" : \"PD94bWwgdmVyc2lvbj0iMS4wIj8+PGNhdGFsb2c+PGJvb2sgaWQ9ImJrMTAxIj48YXV0aG9yPkdhbWJhcmRlbGxhLCBNYXR0aGV3PC9hdXRob3I+PHRpdGxlPlhNT" + + "CBEZXZlbG9wZXIncyBHdWlkZTwvdGl0bGU+PGdlbnJlPkNvbXB1dGVyPC9nZW5yZT48cHJpY2U+NDQuOTU8L3ByaWNlPjxwdWJsaXNoX2RhdGU+MjAwMC0xMC0wMTwvcHVibGlzaF"+ + "9kYXRlPjxkZXNjcmlwdGlvbj5BbiBpbi1kZXB0aCBsb29rIGF0IGNyZWF0aW5nIGFwcGxpY2F0aW9ucyB3aXRoIFhNTC48L2Rlc2NyaXB0aW9uPjwvYm9vaz48L2NhdGFsb2c+\"" + + + + "} " + + + + "}}"; + + /* + * The following example comes directly from the JSON Profile Spec + */ + String exampleFromSpec = "{ " + + "\"Request\" : { " + + "\"AccessSubject\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"subject-id\", " + + "\"Value\" : \"Andreas\" " + + "}, " + + "{ " + + "\"Id\" : \"location\", " + + "\"Value\" : \"Gamla Stan\" " + + "} " + + "] " + + "}, " + + "\"Action\" : { " + + "\"Attribute\": " + + "{ " + + "\"Id\" : \"action-id\", " + + "\"Value\" : \"http://www.xacml.eu/buy\", " + + "\"DataType\" : \"anyURI\" " + + "} " + + "}, " + + "\"Resource\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"book-title\", " + + "\"Value\" : \"Learn German in 90 days\" " + + "}, " + + "{ " + + "\"Id\" : \"currency\", " + + "\"Value\" : \"SEK\" " + + "}, " + + "{ " + + "\"Id\" : \"price\", " + + "\"Value\" : 123.34 " + + "} " + + "] " + + "} " + + "} " + + "} "; + + + /* + * The following example comes directly from the JSON Profile Spec (modified to include a "" missing from both examples). + * It shows the two ways of handling XPath content, as escaped XML and as Base64 encoding. + */ + String xPathExampleFromSpec = "{ " + + "\"Request\" : { " + + "\"Resource\" : { " + + "\"Attribute\": [ " + + "{ " + + "\"Id\" : \"urn:oasis:names:tc:xacml:3.0:content-selector\", " + + "\"DataType\" : \"xpathExpression\", " + + "\"Value\" : { " + + "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\", " + + "\"Namespaces\" : [{ " + + "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + + "}, " + + "{ " + + "\"Prefix\" : \"md\", " + + "\"Namespace\" : \"urn:example:med:schemas:record\" " + + "} " + + "], " + + "\"XPath\" : \"md:record/md:patient/md:patientDoB\" " + + "} " + + "} " + + "] " + + "} " + + "} " + + "} "; + + + + // test various ways that request might be empty + @Test + public void testEmptyRequest() { + // null request + try { + request = JSONRequest.load((String)null); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // empty request + try { + request = JSONRequest.load((String)""); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load((String)" "); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // empty JSON request + try { + request = JSONRequest.load((String)"{}"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load((String)"{{}}"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // garbage input + try { + request = JSONRequest.load((String)"Some non-JSON string"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load((String)"{something non-JSON}"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // bad syntax (Request with no content) + try { + request = JSONRequest.load((String)"{\"Request\"}"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // bad syntax (no :field after Request) + try { + request = JSONRequest.load((String)"{\"Request\" : }"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // bad syntax (no " around Request) + try { + request = JSONRequest.load((String)"{Request}"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // empty content in Request + try { + request = JSONRequest.load((String)"{\"Request\" : \"\"}"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // content is not an object + try { + request = JSONRequest.load((String)"{\"Request\" : \"CombinedDecision\" : true }"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // too many } at end + // Jackson parser does not treat this as an error + try { + request = JSONRequest.load((String)"{\"Request\" : {\"XPathVersion\" : \"http://www.w3.org/TR/1999/REC-xpath-19991116\"}}}}}"); + assertEquals("{requestDefaults={xpatherVersion=http://www.w3.org/TR/1999/REC-xpath-19991116},returnPolicyIdList=false,combinedDecision=false}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // too few } at end + try { + request = JSONRequest.load((String)"{\"Request\" : {\"XPathVersion\" : \"http://www.w3.org/TR/1999/REC-xpath-19991116\" }"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // misplaced } in middle + try { + request = JSONRequest.load((String)"{\"Request\" : {\"XPathVersion\" : } \"http://www.w3.org/TR/1999/REC-xpath-19991116\"}}}}}"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + } + + + + // Test double braces around request + @Test + public void testDoubleBraces() { + + try { + request = JSONRequest.load((String)"{{\"Request\" }"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load((String)"{{\"Request\" : }"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load((String)"{{\"Request\" : {\"CombinedDecision\" : true }}"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + } + + + + // test elements missing from top-level Request and arrays where single elements should be + @Test + public void testMissingFields() { + + // Request containing empty array + try { + request = JSONRequest.load((String)"{\"Request\" : []}"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // array of one element + try { + request = JSONRequest.load((String)"{\"Request\" : [{\"CombinedDecision\" : true }]}"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // correctly formatted empty request gives request with defaults set + try { + request = JSONRequest.load((String)"{\"Request\" : { }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // space in front of name (inside quotes) + try { + request = JSONRequest.load((String)"{\" Request\" : {\"XPathVersion\" : \"http://some/other/default/uri\" }}"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // space at end of name (inside quotes) + try { + request = JSONRequest.load((String)"{\"Request \" : {\"XPathVersion\" : \"http://some/other/default/uri\" }}"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // space in front of value (inside quotes) - valid String but not valid URI + try { + request = JSONRequest.load((String)"{\"Request\" : {\"XPathVersion\" : \" http://some/other/default/uri\" }}"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // space at end of value (inside quotes) - valid String but not valid URI + try { + request = JSONRequest.load((String)"{\"Request\" : {\"XPathVersion\" : \"http://some/other/default/uri \" }}"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + } + + + + // test just one of each top-level element. + // For simple elements also test for incorrect type + @Test + public void testTopLevelElements() { + + // empty request + try { + request = JSONRequest.load((String)"{\"Request\" : {}}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + + // ReturnPolicyIdList + try { + request = JSONRequest.load((String)"{\"Request\" : {\"ReturnPolicyIdList\" : true }}"); + assertEquals("{returnPolicyIdList=true,combinedDecision=false}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load((String)"{\"Request\" : {\"ReturnPolicyIdList\" : \"abc\" }}"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load((String)"{\"Request\" : {\"ReturnPolicyIdList\" : 123 }}"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // CombinedDecision + try { + request = JSONRequest.load((String)"{\"Request\" : { \"CombinedDecision\" : true }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=true}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load((String)"{\"Request\" : {\"CombinedDecision\" : \"abc\" }}"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load((String)"{\"Request\" : {\"CombinedDecision\" : 123 }}"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // XPathVersion + try { + request = JSONRequest.load((String)"{\"Request\" : {\"XPathVersion\" : \"http://some/other/default/uri\" }}"); + assertEquals("{requestDefaults={xpatherVersion=http://some/other/default/uri},returnPolicyIdList=false,combinedDecision=false}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load((String)"{\"Request\" : {\"XPathVersion\" : true }}"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load((String)"{\"Request\" : {\"XPathVersion\" : 123 }}"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load((String)"{\"Request\" : {\"XPathVersion\" : \"not a uri\" }}"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // Category + try { + request = JSONRequest.load((String)"{\"Request\" : {\"Category\": [{ " + + "\"CategoryId\": \"another-custom-cat\", " + + "\"Id\" : \"anotherXmlId\", " + + "\"Attribute\" : []" + + "} " + + "] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=another-custom-cat},xmlId=anotherXmlId}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // AccessSubject + try { + request = JSONRequest.load((String)"{\"Request\" : { \"AccessSubject\":{ }}}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Action + try { + request = JSONRequest.load((String)"{\"Request\" : { \"Action\":{ }}}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:action}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Resource + try { + request = JSONRequest.load((String)"{\"Request\" : {\"Resource\":{ }}}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Environment + try { + request = JSONRequest.load((String)"{\"Request\" : {\"Environment\":{ } }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // MultiRequests + try { + request = JSONRequest.load((String)"{\"Request\" : {\"MultiRequests\" : {" + + "\"RequestReference\": [" + + "{ " + + "\"ReferenceId\" : [\"foo1\",\"bar1\"]" + + "}," + + "{" + + "\"ReferenceId\" : [\"foo2\",\"bar2\"]" + + "}]" + + "} } }"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,multiRequests=[{requestAttributesReferences=[{referenceId=foo1}{referenceId=bar1}]}{requestAttributesReferences=[{referenceId=foo2}{referenceId=bar2}]}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // MultiRequest with 1 + try { + request = JSONRequest.load((String)"{\"Request\" : {\"MultiRequests\" : {" + + "\"RequestReference\": [" + + "{" + + "\"ReferenceId\" : [\"bar2\"]" + + "}]" + + "} } }"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,multiRequests=[{requestAttributesReferences=[{referenceId=bar2}]}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // MultiRequest with RequestReferences with no ReferenceId + try { + request = JSONRequest.load((String)"{\"Request\" : {\"MultiRequests\" : {" + + "\"RequestReference\": [" + + "{" + + "\"ReferenceId\" : []" + + "}]" + + "} } }"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // MultiRequests with no RequestReference + try { + request = JSONRequest.load((String)"{\"Request\" : {\"MultiRequests\" : {" + + "\"RequestReference\": []" + + "} } }"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // MultiRequests with something other than RequestReference + try { + request = JSONRequest.load((String)"{\"Request\" : {\"MultiRequests\" : {" + + "\"SomeOtherAttribute\": 123" + + "} } }"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // MultiRequests with single RequestReference rather than array + try { + request = JSONRequest.load((String)"{\"Request\" : {\"MultiRequests\" : {" + + "\"RequestReference\": " + + "{" + + "\"ReferenceId\" : []" + + "}" + + "} } }"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // MultiRequests with RequestReference containing single element instead of array + try { + request = JSONRequest.load((String)"{\"Request\" : {\"MultiRequests\" : {" + + "\"RequestReference\": [" + + "{" + + "\"ReferenceId\" : \"foo1\"" + + "}]" + + "} } }"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + try { + request = JSONRequest.load((String)"{\"Request\" : {\"MultiRequests\" : {" + + "\"RequestReference\": [" + + "{" + + "\"ReferenceId\" : {\"foo1\"}" + + "}]" + + "} } }"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // MultiRequests with component that is not a RequestReference + try { + request = JSONRequest.load((String)"{\"Request\" : {\"MultiRequests\" : {" + + "\"RequestReference\": [" + + "{ " + + "\"SomeOtherAttribute\" : [\"foo1\",\"bar1\"]" + + "}," + + "{" + + "\"ReferenceId\" : [\"foo2\",\"bar2\"]" + + "}]" + + "} } }"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // MultiRequests with component that is not a RequestReference + try { + request = JSONRequest.load((String)"{\"Request\" : {\"MultiRequests\" : {" + + "\"RequestReference\": [" + + "{ " + + "\"ReferenceId\" : [\"foo2\",\"bar2\"]," + + "\"SomeOtherAttribute\" : [\"foo1\",\"bar1\"]" + + "}," + + "{" + + "\"ReferenceId\" : [\"foo2\",\"bar2\"]" + + "}]" + + "} } }"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // MultiRequest with unknown elements (in addition to RequestReference) + try { + request = JSONRequest.load((String)"{\"Request\" : {\"MultiRequests\" : {" + + "\"SomeOtherAttribute\": 123," + + "\"RequestReference\": [" + + "{ " + + "\"ReferenceId\" : [\"foo1\",\"bar1\"]" + + "}," + + "{" + + "\"ReferenceId\" : [\"foo2\",\"bar2\"]" + + "}]" + + "} } }"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // MultiRequest with RequestReferences with ReferenceId NOT a string + try { + request = JSONRequest.load((String)"{\"Request\" : {\"MultiRequests\" : {" + + "\"RequestReference\": [" + + "{" + + "\"ReferenceId\" : [ true ]" + + "}]" + + "} } }"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load((String)"{\"Request\" : {\"MultiRequests\" : {" + + "\"RequestReference\": [" + + "{" + + "\"ReferenceId\" : [ 123 ]" + + "}]" + + "} } }"); + fail("Request should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // Cannot test with ReferenceId that is NOT referring to a Category object Id property because we may not have read the Category objects yet. + // Need to leave this up to the PDP. + + + // extra elements in top-level + try { + request = JSONRequest.load((String)"{\"Request\" : {}, \"unknownElement\" : false, \"unk2\" : \"abc\", \"unk3\" : 123 }}"); + fail("Unknown element should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // extra elements in Request + try { + request = JSONRequest.load((String)"{\"Request\" : {\"XPathVersion\" : \"http://www.w3.org/TR/1999/REC-xpath-19991116\", \"unknownElement\" : false }}"); + fail("Unknown element should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + } + + + // Test with every field filled in with multiple values where appropriate + @Test + public void testAllFieldsRequest() { + + // convert Response to JSON + try { + request = JSONRequest.load(allFieldsRequest); + assertEquals("{requestDefaults={xpatherVersion=http://www.w3.org/TR/1999/REC-xpath-19991116},returnPolicyIdList=true,combinedDecision=true,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=123}],includeInResults=false}{attributeId=document-url,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=http://somewhere.over.the.com/rainbow}],includeInResults=false}{attributeId=page-list,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=1.0}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=2.0}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=3.0}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=4.5}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=3.0}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=2.0}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=1.0}],includeInResults=false}]},xmlId=customId}{super={category=another-custom-cat},xmlId=anotherXmlId}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject},contentRoot=[catalog: null]}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource},contentRoot=[catalog: null]}],multiRequests=[{requestAttributesReferences=[{referenceId=foo1}{referenceId=bar1}]}{requestAttributesReferences=[{referenceId=foo2}{referenceId=bar1}]}]}" + , request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // convert example request from spec + try { + request = JSONRequest.load(exampleFromSpec); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,attributes=[{attributeId=action-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=http://www.xacml.eu/buy}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,attributes=[{attributeId=book-title,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Learn German in 90 days}],includeInResults=false}{attributeId=currency,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=SEK}],includeInResults=false}{attributeId=price,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=123.34}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // convert example request from spec containing XPAthExpression + try { + request = JSONRequest.load(xPathExampleFromSpec); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,attributes=[{attributeId=urn:oasis:names:tc:xacml:3.0:content-selector,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression,value={path=md:record/md:patient/md:patientDoB,Namespace={[{md,urn:example:med:schemas:record}{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}]},status=null,xpathExpressionWrapped=null},xpathCategory=urn:oasis:names:tc:xacml:3.0:attribute-category:resource}],includeInResults=false}]}}]}", request.toString()); + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + } + + + + // Duplicates - Each element duplicated + @Test + public void testDuplicates() { + // duplicate Request + try { + request = JSONRequest.load((String)"{\"Request\" : {}, \"Request\" : {}}"); + fail("Unknown element should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + try { + request = JSONRequest.load((String)"{\"Request\" : {\"ReturnPolicyIdList\" : true, \"ReturnPolicyIdList\" : true }}"); + fail("Unknown element should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load((String)"{\"Request\" : { \"CombinedDecision\" : true, \"CombinedDecision\" : true }}"); + fail("Unknown element should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + try { + request = JSONRequest.load((String)"{\"Request\" : {\"Category\": [{ " + + "\"CategoryId\": \"another-custom-cat\", " + + "\"Id\" : \"anotherXmlId\", " + + "\"Attribute\" : []" + + "} " + + "]," + + "\"Category\": [{ " + + "\"CategoryId\": \"another-custom-cat\", " + + "\"Id\" : \"anotherXmlId\", " + + "\"Attribute\" : []" + + "} " + + "] }}"); + assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=another-custom-cat},xmlId=anotherXmlId}]}", request.toString()); + fail("Unknown element should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load((String)"{\"Request\" : {\"Category\": [{ " + + "\"CategoryId\": \"another-custom-cat\", " + + "\"CategoryId\": \"another-custom-cat\", " + + "\"Id\" : \"anotherXmlId\", " + + "\"Attribute\" : []" + + "} " + + "] }}"); + fail("Unknown element should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load((String)"{\"Request\" : {\"Category\": [{ " + + "\"CategoryId\": \"another-custom-cat\", " + + "\"Id\" : \"anotherXmlId\", " + + "\"Id\" : \"anotherXmlId\", " + + "\"Attribute\" : []" + + "} " + + "] }}"); + fail("Unknown element should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load((String)"{\"Request\" : {\"Category\": [{ " + + "\"CategoryId\": \"another-custom-cat\", " + + "\"Id\" : \"anotherXmlId\", " + + "\"Attribute\" : []" + + "\"Attribute\" : []" + + "} " + + "] }}"); + fail("Unknown element should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // AccessSubject + try { + request = JSONRequest.load((String)"{\"Request\" : { \"AccessSubject\":{ }, \"AccessSubject\":{ }}}"); + fail("Unknown element should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Action + try { + request = JSONRequest.load((String)"{\"Request\" : { \"Action\":{ }, \"Action\":{ }}}"); + fail("Unknown element should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Resource + try { + request = JSONRequest.load((String)"{\"Request\" : {\"Resource\":{ }, \"Resource\":{ }}}"); + fail("Unknown element should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Environment + try { + request = JSONRequest.load((String)"{\"Request\" : {\"Environment\":{ }, \"Environment\":{ } }}"); + fail("Unknown element should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // MultiRequests + + + try { + request = JSONRequest.load((String)"{\"Request\" : {\"MultiRequests\" : {" + + "\"RequestReference\": [" + + "{ " + + "\"ReferenceId\" : [\"foo1\",\"bar1\"]" + + "}," + + "{" + + "\"ReferenceId\" : [\"foo2\",\"bar2\"]" + + "}]" + + "}," + + "\"MultiRequests\" : {" + + "\"RequestReference\": [" + + "{ " + + "\"ReferenceId\" : [\"foo1\",\"bar1\"]" + + "}," + + "{" + + "\"ReferenceId\" : [\"foo2\",\"bar2\"]" + + "}]" + + "} } }"); + fail("Unknown element should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load((String)"{\"Request\" : {\"MultiRequests\" : {" + + "\"RequestReference\": [" + + "{ " + + "\"ReferenceId\" : [\"foo1\",\"bar1\"]" + + "}," + + "{" + + "\"ReferenceId\" : [\"foo2\",\"bar2\"]" + + "}]," + + "\"RequestReference\": [" + + "{ " + + "\"ReferenceId\" : [\"foo1\",\"bar1\"]" + + "}," + + "{" + + "\"ReferenceId\" : [\"foo2\",\"bar2\"]" + + "}]" + + "} } }"); + fail("Unknown element should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + try { + request = JSONRequest.load((String)"{\"Request\" : {\"MultiRequests\" : {" + + "\"RequestReference\": [" + + "{ " + + "\"ReferenceId\" : [\"foo1\",\"bar1\"]" + + "\"ReferenceId\" : [\"foo1\",\"bar1\"]" + + "}," + + "{" + + "\"ReferenceId\" : [\"foo2\",\"bar2\"]" + + "}]" + + "} } }"); + fail("Unknown element should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + } + + +} diff --git a/ECOMP-XACML/src/test/java/org/openecomp/policy/xacml/test/json/ResponseConformanceTest.java b/ECOMP-XACML/src/test/java/org/openecomp/policy/xacml/test/json/ResponseConformanceTest.java new file mode 100644 index 000000000..601a4629b --- /dev/null +++ b/ECOMP-XACML/src/test/java/org/openecomp/policy/xacml/test/json/ResponseConformanceTest.java @@ -0,0 +1,370 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-XACML + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.xacml.test.json; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import java.io.File; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import org.junit.Test; + +import com.att.research.xacml.api.Advice; +import com.att.research.xacml.api.Attribute; +import com.att.research.xacml.api.AttributeCategory; +import com.att.research.xacml.api.IdReference; +import com.att.research.xacml.api.Obligation; +import com.att.research.xacml.api.Response; +import com.att.research.xacml.api.Result; +import com.att.research.xacml.std.dom.DOMResponse; +import com.att.research.xacml.std.json.JSONResponse; +import com.att.research.xacml.util.ListUtil; +/** + * Test JSON Response convert to object - Conformance tests + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * Note: some of the validation tests comparing the XML-derived Results to the JSON-derived Results are high-level comparisons of Collections. + * When this class was first created that was sufficient to pass all Conformance tests. + * However if this sees a failure in a Conformance test, those validations may need to be upgraded to look at the individual data elements to see what is wrong. + * + * + */ +public class ResponseConformanceTest { + + // where to find the conformance test XML files + private final String CONFORMANCE_DIRECTORY_PATH = "testsets/conformance/xacml3.0-ct-v.0.4"; + + // The request object output from each test conversion from JSON string + Response response; + + + + + + // test just one of each top-level element. + // For simple elements also test for incorrect type + @Test + public void testConformanceResponses() { + + List filesInDirectory = null; + + File conformanceDirectory = null; + + File currentFile = null; + + try { + conformanceDirectory = new File(CONFORMANCE_DIRECTORY_PATH); + filesInDirectory = getRequestsInDirectory(conformanceDirectory); + } catch (Exception e) { + fail("Unable to set up Conformance tests for dir '" + conformanceDirectory.getAbsolutePath()+"' e="+ e); + } + + // run through each XML file + // - load the file from XML into an internal Response object + // - generate the JSON representation of that Response object + // - load that JSON representation into a new Response object + // - compare the 2 Request objects + Response xmlResponse = null; + Response jsonResponse = null; + try { + for (File f : filesInDirectory) { + currentFile = f; + +//// This is a simple way to select just one file for debugging - comment out when not being used +//if ( ! f.getName().equals("IIIA030Response.xml") && ! f.getName().equals("IIIA330Response.xml")) { continue; } + +// during debugging it is helpful to know what file it is starting to work on +// System.out.println("starting file="+currentFile.getName()); + + try { + // load XML into a Response object + xmlResponse = DOMResponse.load(f); + } catch (Exception e) { + // if XML does not load, just note it and continue with next file + System.out.println("XML file did not load: '" + f.getName() + " e=" + e); + continue; + } + + // some tests have JSON response files to load, most do not + String jsonFileName = f.getName().replace(".xml", ".json"); + File jsonFile = new File(conformanceDirectory, jsonFileName); + + if (jsonFile.exists()) { +//System.out.println("found file "+jsonFile.getName()); + // json version exists in file, so load it + jsonResponse = JSONResponse.load(jsonFile); + } else { + // json does not exist in file, so create it from the XML response using a String intermediate version + String jsonResponseString = JSONResponse.toString(xmlResponse, false); +//System.out.println(jsonResponseString); +//System.out.println(JSONResponse.toString(xmlResponse, true)); + + jsonResponse = JSONResponse.load(jsonResponseString); + } + + +//System.out.println(JSONResponse.toString(xmlResponse, true)); + + + + + // compare the two Response objects + + // compare results + assertEquals(xmlResponse.getResults().size(), jsonResponse.getResults().size()); + + if (xmlResponse.getResults().size() == 0) { + fail("neither XML nor JSON response have any Results"); + } + + + // Results are an un-ordered Collection. + // There is no identifying information that is unique to a specific Result. + // If there are more than one we cannot be sure which one corresponds with which. + // The best we can do is say that one or more in the first list do not match any in the second list + if (xmlResponse.getResults().size() > 1) { + for (Result xmlResult : xmlResponse.getResults()) { + boolean found = false; + for (Result jsonResult : jsonResponse.getResults()) { + if (xmlResult.equals(jsonResult)) { + found = true; + break; + } + } + if (found) { + continue; + } + // no match found + System.out.println("No match for XML in " + f.getName()); + System.out.println("XML =" + xmlResult.toString()); + for (Result jsonResult : jsonResponse.getResults()) { + System.out.println("JSON="+ jsonResult.toString()); + } + fail("JSON Response has no match for XML Result: " + xmlResult.toString()); + } + // we've done the best we can for multiple decisions, so go to next file + continue; + } + + // single Result in each + Result xmlResult = xmlResponse.getResults().iterator().next(); + Result jsonResult = jsonResponse.getResults().iterator().next(); + + // The following sections have not given us trouble, so checking is very high-level. + // If we see a problem in one of these elements, the single line will need to be replaced with detailed examination of the objects. + assertEquals(f.getName() + " Decision", xmlResult.getDecision(), jsonResult.getDecision()); + assertEquals(f.getName() + " Status", xmlResult.getStatus(), jsonResult.getStatus()); + + // Obligations + if (xmlResult.getObligations() != jsonResult.getObligations()) { + Collection xmlObligations = xmlResult.getObligations(); + Collection jsonObligations = jsonResult.getObligations(); + // if both are null we do not get here + if (xmlObligations == null || jsonObligations == null) { + fail(f.getName() + " Obligations has null \nXML="+xmlObligations + "\nJSON="+jsonObligations); + } + if (ListUtil.equalsAllowNulls(xmlObligations, jsonObligations) == false) { + // collections are not equal, so need to examine further +fail(f.getName() + " Obligation collections not equal\nXML="+xmlObligations + "\nJSON="+jsonObligations); + } + } + + // AssociatedAdvice + if (xmlResult.getAssociatedAdvice() != jsonResult.getAssociatedAdvice()) { + Collection xmlAdvice = xmlResult.getAssociatedAdvice(); + Collection jsonAdvice = jsonResult.getAssociatedAdvice(); + // if both are null we do not get here + if (xmlAdvice == null || jsonAdvice == null) { + fail(f.getName() + " Advice has null \nXML="+xmlAdvice + "\nJSON="+jsonAdvice); + } + if (ListUtil.equalsAllowNulls(xmlAdvice, jsonAdvice) == false) { + // collections are not equal, so need to examine further +fail(f.getName() + " Advice collections not equal\nXML="+xmlAdvice + "\nJSON="+jsonAdvice); + } + } + + + + // check Attributes in more detail + Collection xmlAttributes = xmlResult.getAttributes(); + Collection jsonAttributes = jsonResult.getAttributes(); + if (xmlAttributes == null && jsonAttributes != null || + xmlAttributes != null && jsonAttributes == null) { + fail(f.getName() + " XML Attributes="+xmlAttributes + " but JSON Attributes=" + jsonAttributes); + } + if (xmlAttributes != null) { + // both are non-null + if (xmlAttributes.size() != jsonAttributes.size()) { + String xmlAttributesString = "XML categorys="; + for (AttributeCategory ac : xmlAttributes) { + xmlAttributesString += " " + ac.getCategory().stringValue(); + } + String jsonAttributesString = "JSON categorys="; + for (AttributeCategory ac : jsonAttributes) { + jsonAttributesString += " " + ac.getCategory().stringValue(); + } + fail(f.getName() + " XML and JSON have different number of Category elements: " + xmlAttributesString + ", " + jsonAttributesString); + } + + // Attribute collections are the same size but may be in different orders. + // for each XML category try to find the corresponding JSON category. + // ASSUME that each category only shows up once!!!! + for (AttributeCategory xmlAttributeCategory : xmlAttributes) { + boolean attributeCategoryFound = false; + for (AttributeCategory jsonAttributeCategory : jsonAttributes) { + if (xmlAttributeCategory.equals(jsonAttributeCategory)) { + attributeCategoryFound = true; + break; + } + // not an exact match, but if same CategoryId then need to check individual Attribute objects + if (xmlAttributeCategory.getCategory().equals(jsonAttributeCategory.getCategory())) { + // same category + if (xmlAttributeCategory.getAttributes().size() != jsonAttributeCategory.getAttributes().size()) { + System.out.println("XML =" + xmlAttributeCategory.getAttributes()); + System.out.println("JSON=" + jsonAttributeCategory.getAttributes()); + fail(f.getName() + " Attributes Category '" + xmlAttributeCategory.getCategory().stringValue() + "' size mismatch; XML="+ + xmlAttributeCategory.getAttributes().size() +", JSON=" + jsonAttributeCategory.getAttributes().size()); + } + for (Attribute xmlAttr : xmlAttributeCategory.getAttributes()) { + boolean attributeFound = false; + for (Attribute jsonAttr : jsonAttributeCategory.getAttributes()) { + if (xmlAttr.equals(jsonAttr)) { + attributeFound = true; + break; + } + } + + if (attributeFound) { + // check next XML attribute + continue; + } + System.out.println("Attribute not found in JSON, Category="+xmlAttributeCategory.getCategory()); + System.out.println("XML Attribute ="+ xmlAttr); + System.out.println("JSON Attributes=" + jsonAttributeCategory.toString()); + fail(f.getName() + " Attribute not found in JSON, Category=" + xmlAttributeCategory.getCategory() + + "/nXML Attribute="+xmlAttr+ + "\nJSON Category Attributes="+jsonAttributeCategory.toString()); + } + + + + } + } + if (attributeCategoryFound) { + continue; + } + fail("XML Category not found in JSON; xml="+xmlAttributeCategory.toString()); + } + + } + + // PolicyIdentifiers + if (xmlResult.getPolicyIdentifiers() != jsonResult.getPolicyIdentifiers()) { + Collection xmlIdReferences = xmlResult.getPolicyIdentifiers(); + Collection jsonIdReferences = jsonResult.getPolicyIdentifiers(); + // if both are null we do not get here + if (xmlIdReferences == null || jsonIdReferences == null) { + fail(f.getName() + " PolicyIdentifiers has null \nXML="+xmlIdReferences + "\nJSON="+jsonIdReferences); + } + if (ListUtil.equalsAllowNulls(xmlIdReferences, jsonIdReferences) == false) { + // collections are not equal, so need to examine further +fail(f.getName() + " PolicyIdentifiers collections not equal\nXML="+xmlIdReferences+ "\nJSON="+jsonIdReferences); + } + } + + // PolicySetIdentifiers + if (xmlResult.getPolicySetIdentifiers() != jsonResult.getPolicySetIdentifiers()) { + Collection xmlIdReferences = xmlResult.getPolicySetIdentifiers(); + Collection jsonIdReferences = jsonResult.getPolicySetIdentifiers(); + // if both are null we do not get here + if (xmlIdReferences == null || jsonIdReferences == null) { + fail(f.getName() + " PolicySetIdentifiers has null \nXML="+xmlIdReferences + "\nJSON="+jsonIdReferences); + } + if (ListUtil.equalsAllowNulls(xmlIdReferences, jsonIdReferences) == false) { + // collections are not equal, so need to examine further +fail(f.getName() + " PolicySetIdentifiers collections not equal\nXML="+xmlIdReferences + "\nJSON="+jsonIdReferences); + } + } + + + } + + } catch (Exception e) { + fail ("Failed test with '" + currentFile.getName() + "', e=" + e); + } + + + } + + // + // HELPER to get list of all Request files in the given directory + // + + private List getRequestsInDirectory(File directory) { + List fileList = new ArrayList(); + + File[] fileArray = directory.listFiles(); + for (File f : fileArray) { + if (f.isDirectory()) { + List subDirList = getRequestsInDirectory(f); + fileList.addAll(subDirList); + } + if (f.getName().endsWith("Response.xml")) { + fileList.add(f); + } + } + return fileList; + + } + +} + + + + + +/* + * +This is a place to copy the really long output from test rigs that need to be manually edited for readability.... + + + +{"Response":[{"Status":{"StatusCode":{"Value":"urn:oasis:names:tc:xacml:1.0:status:ok"}},"Obligations":[{"Id":"urn:oasis:names:tc:xacml:2.0:conformance-test:IIIA030:obligation-1","AttributeAssignment":[ +{"Value":"assignment1","DataType":"string","AttributeId":"urn:oasis:names:tc:xacml:2.0:conformance-test:IIIA030:assignment1"}, +{"Value":{"Namespaces":[{"Namespace":"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17"},{"Namespace":"http://www.w3.org/2001/XMLSchema-instance","Prefix":"xsi"}], + "XPathCategory":"urn:oasis:names:tc:xacml:3.0:attribute-category:resource", + "XPath":"//md:records/md:record"}, + "DataType":"xpathExpression", + "AttributeId":"urn:oasis:names:tc:xacml:2.0:conformance-test:IIIA030:assignment2"}]}],"Decision":"Permit"}]} + + + +*/ + + + + + diff --git a/ECOMP-XACML/src/test/java/org/openecomp/policy/xacml/test/json/ResponseTest.java b/ECOMP-XACML/src/test/java/org/openecomp/policy/xacml/test/json/ResponseTest.java new file mode 100644 index 000000000..12da12cbf --- /dev/null +++ b/ECOMP-XACML/src/test/java/org/openecomp/policy/xacml/test/json/ResponseTest.java @@ -0,0 +1,2297 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-XACML + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.xacml.test.json; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import java.text.ParseException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import java.math.BigInteger; + +import org.junit.Ignore; +import org.junit.Test; + +import com.att.research.xacml.api.Attribute; +import com.att.research.xacml.api.AttributeValue; +import com.att.research.xacml.api.Decision; +import com.att.research.xacml.api.Identifier; +import com.att.research.xacml.api.XACML3; +import com.att.research.xacml.std.IdentifierImpl; +import com.att.research.xacml.std.StdAttribute; +import com.att.research.xacml.std.StdAttributeCategory; +import com.att.research.xacml.std.StdAttributeValue; +import com.att.research.xacml.std.StdIdReference; +import com.att.research.xacml.std.StdMutableAdvice; +import com.att.research.xacml.std.StdMutableAttribute; +import com.att.research.xacml.std.StdMutableAttributeAssignment; +import com.att.research.xacml.std.StdMutableMissingAttributeDetail; +import com.att.research.xacml.std.StdMutableObligation; +import com.att.research.xacml.std.StdMutableResponse; +import com.att.research.xacml.std.StdMutableResult; +import com.att.research.xacml.std.StdMutableStatus; +import com.att.research.xacml.std.StdMutableStatusDetail; +import com.att.research.xacml.std.StdStatusCode; +import com.att.research.xacml.std.StdVersion; +import com.att.research.xacml.std.datatypes.DataTypes; +import com.att.research.xacml.std.datatypes.StringNamespaceContext; +import com.att.research.xacml.std.datatypes.XPathExpressionWrapper; +import com.att.research.xacml.std.json.JSONResponse; +import com.att.research.xacml.std.json.JSONStructureException; + +/** + * Test JSON Responses + * + * TO RUN - use jUnit + * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test + * + * + */ +public class ResponseTest { + + String jsonResponse; + + StdMutableResponse response; + + StdMutableResult result; + + StdMutableStatus status; + + + // Note: Initially test responses without Obligations, Associated Advice, Attributes, or PolicyIdentifier + + + @Test + public void testEmptyAndDecisions() { + // null response + try { + jsonResponse = JSONResponse.toString(null, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // empty response (no Result object) + response = new StdMutableResponse(); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // just decision, no status + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // just status (empty), no decision + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + result.setStatus(status); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // just status (non-empty), no decision + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_OK); + result.setStatus(status); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // test other decisions without Status + + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.DENY); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Decision\":\"Deny\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.NOTAPPLICABLE); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Decision\":\"NotApplicable\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Decision\":\"Indeterminate\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.INDETERMINATE_DENY); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Decision\":\"Indeterminate{D}\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.INDETERMINATE_DENYPERMIT); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Decision\":\"Indeterminate{DP}\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.INDETERMINATE_PERMIT); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Decision\":\"Indeterminate{P}\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // test Multiple Decisions - success + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + response.add(result); + StdMutableResult result2 = new StdMutableResult(); + result2.setDecision(Decision.DENY); + response.add(result2); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Decision\":\"Permit\"},{\"Decision\":\"Deny\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // test Multiple Decisions - one success and one error + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + response.add(result); + result2 = new StdMutableResult(); + result2.setDecision(Decision.INDETERMINATE); + response.add(result2); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Decision\":\"Permit\"},{\"Decision\":\"Indeterminate\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + } + + + + + // Test with every field filled in with multiple values where appropriate + @Ignore //@Test + public void testAllFieldsResponse() { + + // fully-loaded multiple response + + StdMutableResponse response = new StdMutableResponse(); + // create a Status object + StdMutableStatus status = new StdMutableStatus(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); + status.setStatusMessage("some status message"); + StdMutableStatusDetail statusDetailIn = new StdMutableStatusDetail(); + StdMutableMissingAttributeDetail mad = new StdMutableMissingAttributeDetail(); + mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_STRING.getId(), "doh")); + mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_INTEGER.getId(), "5432")); + mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_STRING.getId(), "meh")); + mad.setAttributeId(XACML3.ID_ACTION_PURPOSE); + mad.setCategory(XACML3.ID_ATTRIBUTE_CATEGORY_ACTION); + mad.setDataTypeId(XACML3.ID_DATATYPE_STRING); + mad.setIssuer("an Issuer"); + statusDetailIn.addMissingAttributeDetail(mad); + status.setStatusDetail(statusDetailIn); + // create a single result object + StdMutableResult result = new StdMutableResult(status); + // set the decision + result.setDecision(Decision.INDETERMINATE); + // put the Result into the Response + response.add(result); + + + // create a new Result with a different Decision + status = new StdMutableStatus(StdStatusCode.STATUS_CODE_OK); + result = new StdMutableResult(status); + result.setDecision(Decision.DENY); + + StdMutableObligation obligation = new StdMutableObligation(); + obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "obligation-issuer1", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Bart"))); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "obligation-issuer2", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Ned"))); + result.addObligation(obligation); + obligation = new StdMutableObligation(); + obligation.setId(XACML3.ID_SUBJECT_CATEGORY_INTERMEDIARY_SUBJECT); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "obligation-issuer3", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Maggie"))); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "obligation-issuer4", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Homer"))); + result.addObligation(obligation); + + + StdMutableAdvice advice = new StdMutableAdvice(); + advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "advice-issuer1", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu"))); + advice.addAttributeAssignment(new StdMutableAttributeAssignment( + null, + XACML3.ID_SUBJECT, + "advice-issuerNoCategory", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Crusty"))); + result.addAdvice(advice); + + + response.add(result); + + + // create a new Result with a different Decision + // add Child/minor status codes within the main status + StdStatusCode childChildChildStatusCode = new StdStatusCode(new IdentifierImpl("childChildChildStatusCode")); + StdStatusCode childChildStatusCode = new StdStatusCode(new IdentifierImpl("childChildStatusCode"), childChildChildStatusCode); + StdStatusCode child1StatusCode = new StdStatusCode(new IdentifierImpl("child1StatusCode"), childChildStatusCode); + StdStatusCode statusCode = new StdStatusCode(XACML3.ID_STATUS_OK, child1StatusCode); + + status = new StdMutableStatus(statusCode); + + + result = new StdMutableResult(status); + result.setDecision(Decision.PERMIT); + + + + + // add attribute list in result + Identifier categoryIdentifier = new IdentifierImpl("firstCategory"); + Attribute[] attrList = { + new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true), + new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent2"), new StdAttributeValue(DataTypes.DT_YEARMONTHDURATION.getId(), "P10Y4M"), "BIssue", false), + new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent3"), new StdAttributeValue(DataTypes.DT_DOUBLE.getId(), 765.432), "CIssue", true), + new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent4"), new StdAttributeValue(DataTypes.DT_BOOLEAN.getId(), true), "DIssue", true), + new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent5"), new StdAttributeValue(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(4567)), "EIssue", true), + new StdAttribute(categoryIdentifier, new IdentifierImpl("attrNoIssuer"), new StdAttributeValue(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(4567)), null, true) }; + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, Arrays.asList(attrList))); + categoryIdentifier = new IdentifierImpl("secondCategory"); + Attribute[] secondAttrList = { + new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent12"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu2"), "AIssue2", true), + new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent22"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Abc2"), "BIssue2", false), + new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent32"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Der2"), "CIssue2", true) }; + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, Arrays.asList(secondAttrList))); + + + // add PolicyIdentifierList to result + StdIdReference policyIdentifier1 = null; + StdIdReference policyIdentifier2 = null; + StdIdReference policySetIdentifier1 = null; + StdIdReference policySetIdentifier2 = null; + try { + policyIdentifier1 = new StdIdReference(new IdentifierImpl("idRef1"), StdVersion.newInstance("1.2.3")); + policyIdentifier2 = new StdIdReference(new IdentifierImpl("idRef2_NoVersion")); + policySetIdentifier1 = new StdIdReference(new IdentifierImpl("idSetRef1"), StdVersion.newInstance("4.5.6.7.8.9.0")); + policySetIdentifier2 = new StdIdReference(new IdentifierImpl("idSetRef2_NoVersion")); + } catch (ParseException e1) { + fail("creating policyIds, e="+e1); + } + + result.addPolicyIdentifier(policyIdentifier1); + result.addPolicyIdentifier(policyIdentifier2); + + result.addPolicySetIdentifier(policySetIdentifier1); + result.addPolicySetIdentifier(policySetIdentifier2); + + response.add(result); + + // convert Response to JSON + try { + jsonResponse = JSONResponse.toString(response, false); +System.out.println(jsonResponse); +//System.out.println(JSONResponse.toString(response, true)); + assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"},\"StatusMessage\":\"some status message\",\"StatusDetail\":\"doh5432meh\"},\"Decision\":\"Indeterminate\"},{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:ok\"}},\"Obligations\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Issuer\":\"obligation-issuer1\",\"Value\":\"Bart\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"},{\"Issuer\":\"obligation-issuer2\",\"Value\":\"Ned\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]},{\"Id\":\"urn:oasis:names:tc:xacml:1.0:subject-category:intermediary-subject\",\"AttributeAssignment\":[{\"Issuer\":\"obligation-issuer3\",\"Value\":\"Maggie\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"},{\"Issuer\":\"obligation-issuer4\",\"Value\":\"Homer\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}],\"Decision\":\"Deny\",\"AssociatedAdvice\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Issuer\":\"advice-issuer1\",\"Value\":\"Apu\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"},{\"Issuer\":\"advice-issuerNoCategory\",\"Value\":\"Crusty\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}]},{\"Status\":{\"StatusCode\":{\"StatusCode\":{\"StatusCode\":{\"StatusCode\":{\"Value\":\"childChildChildStatusCode\"},\"Value\":\"childChildStatusCode\"},\"Value\":\"child1StatusCode\"},\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:ok\"}},\"Category\":[{\"CategoryId\":\"firstCategory\",\"Attribute\":[{\"Issuer\":\"AIssue\",\"Value\":\"Apu\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent1\"},{\"Issuer\":\"CIssue\",\"Value\":765.432,\"DataType\":\"http://www.w3.org/2001/XMLSchema#double\",\"AttributeId\":\"attrIdent3\"},{\"Issuer\":\"DIssue\",\"Value\":true,\"DataType\":\"http://www.w3.org/2001/XMLSchema#boolean\",\"AttributeId\":\"attrIdent4\"},{\"Issuer\":\"EIssue\",\"Value\":4567,\"DataType\":\"http://www.w3.org/2001/XMLSchema#integer\",\"AttributeId\":\"attrIdent5\"},{\"Value\":4567,\"DataType\":\"http://www.w3.org/2001/XMLSchema#integer\",\"AttributeId\":\"attrNoIssuer\"}]},{\"CategoryId\":\"secondCategory\",\"Attribute\":[{\"Issuer\":\"AIssue2\",\"Value\":\"Apu2\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent12\"},{\"Issuer\":\"CIssue2\",\"Value\":\"Der2\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent32\"}]}],\"Decision\":\"Permit\",\"PolicyIdentifier\":{\"PolicyIdReference\":[{\"Id\":\"idRef1\",\"Version\":\"1.2.3\"},{\"Id\":\"idRef2_NoVersion\"}],\"PolicySetIdReference\":[{\"Id\":\"idSetRef1\",\"Version\":\"4.5.6.7.8.9.0\"},{\"Id\":\"idSetRef2_NoVersion\"}]}}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + } + + + + + // combinations of Status values with Decision values + @Test + public void testDecisionStatusMatch() { + // the tests in this method use different values and do not change structures, so we can re-use the objects + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + result.setStatus(status); + response.add(result); + + // StatusCode = OK + status.setStatusCode(StdStatusCode.STATUS_CODE_OK); + result.setDecision(Decision.PERMIT); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:ok\"}},\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + result.setDecision(Decision.DENY); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:ok\"}},\"Decision\":\"Deny\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + result.setDecision(Decision.NOTAPPLICABLE); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:ok\"}},\"Decision\":\"NotApplicable\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + result.setDecision(Decision.INDETERMINATE); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + result.setDecision(Decision.INDETERMINATE_DENY); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + result.setDecision(Decision.INDETERMINATE_DENYPERMIT); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + result.setDecision(Decision.INDETERMINATE_PERMIT); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + + + + + // StatusCode = SyntaxError + status.setStatusCode(StdStatusCode.STATUS_CODE_SYNTAX_ERROR); + result.setDecision(Decision.PERMIT); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + result.setDecision(Decision.DENY); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + result.setDecision(Decision.NOTAPPLICABLE); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + result.setDecision(Decision.INDETERMINATE); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:syntax-error\"}},\"Decision\":\"Indeterminate\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + result.setDecision(Decision.INDETERMINATE_DENY); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:syntax-error\"}},\"Decision\":\"Indeterminate{D}\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + result.setDecision(Decision.INDETERMINATE_DENYPERMIT); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:syntax-error\"}},\"Decision\":\"Indeterminate{DP}\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + result.setDecision(Decision.INDETERMINATE_PERMIT); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:syntax-error\"}},\"Decision\":\"Indeterminate{P}\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // StatusCode = ProcessingError + status.setStatusCode(StdStatusCode.STATUS_CODE_PROCESSING_ERROR); + result.setDecision(Decision.PERMIT); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + result.setDecision(Decision.DENY); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + result.setDecision(Decision.NOTAPPLICABLE); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + result.setDecision(Decision.INDETERMINATE); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:processing-error\"}},\"Decision\":\"Indeterminate\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + result.setDecision(Decision.INDETERMINATE_DENY); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:processing-error\"}},\"Decision\":\"Indeterminate{D}\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + result.setDecision(Decision.INDETERMINATE_DENYPERMIT); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:processing-error\"}},\"Decision\":\"Indeterminate{DP}\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + result.setDecision(Decision.INDETERMINATE_PERMIT); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:processing-error\"}},\"Decision\":\"Indeterminate{P}\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + + // StatusCode = MissingAttribute + status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); + result.setDecision(Decision.PERMIT); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + result.setDecision(Decision.DENY); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + result.setDecision(Decision.NOTAPPLICABLE); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + result.setDecision(Decision.INDETERMINATE); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"}},\"Decision\":\"Indeterminate\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + result.setDecision(Decision.INDETERMINATE_DENY); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"}},\"Decision\":\"Indeterminate{D}\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + result.setDecision(Decision.INDETERMINATE_DENYPERMIT); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"}},\"Decision\":\"Indeterminate{DP}\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + result.setDecision(Decision.INDETERMINATE_PERMIT); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"}},\"Decision\":\"Indeterminate{P}\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + } + + + + + // tests related to Status and its components + @Ignore //@Test + public void testStatus() { + // Status with no StatusCode - error + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + result.setStatus(status); + result.setDecision(Decision.PERMIT); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Status with StatusMessage when OK + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_OK); + status.setStatusMessage("I'm ok, you're ok"); + result.setStatus(status); + result.setDecision(Decision.PERMIT); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:ok\"},\"StatusMessage\":\"I'm ok, you're ok\"},\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // Status with StatusDetail when OK + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_OK); + StdMutableStatusDetail statusDetail = new StdMutableStatusDetail(); + status.setStatusDetail(statusDetail); + result.setStatus(status); + result.setDecision(Decision.PERMIT); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Status with StatusMessage when SyntaxError + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_SYNTAX_ERROR); + status.setStatusMessage("I'm ok, you're ok"); + result.setStatus(status); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:syntax-error\"},\"StatusMessage\":\"I'm ok, you're ok\"},\"Decision\":\"Indeterminate\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // Status with empty StatusDetail when SyntaxError + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_SYNTAX_ERROR); + statusDetail = new StdMutableStatusDetail(); + status.setStatusDetail(statusDetail); + result.setStatus(status); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // Status with StatusMessage when ProcessingError + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_PROCESSING_ERROR); + status.setStatusMessage("I'm ok, you're ok"); + result.setStatus(status); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:processing-error\"},\"StatusMessage\":\"I'm ok, you're ok\"},\"Decision\":\"Indeterminate\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // Status with empty StatusDetail when ProcessingError + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_PROCESSING_ERROR); + statusDetail = new StdMutableStatusDetail(); + status.setStatusDetail(statusDetail); + result.setStatus(status); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + // Status with StatusMessage when MissingAttribute + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); + status.setStatusMessage("I'm ok, you're ok"); + result.setStatus(status); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"},\"StatusMessage\":\"I'm ok, you're ok\"},\"Decision\":\"Indeterminate\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // Status with empty StatusDetail when MissingAttribute + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); + statusDetail = new StdMutableStatusDetail(); + status.setStatusDetail(statusDetail); + result.setStatus(status); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"}},\"Decision\":\"Indeterminate\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + + // Status with StatusDetail with empty detail when MissingAttribute + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); + statusDetail = new StdMutableStatusDetail(); + StdMutableMissingAttributeDetail mad = new StdMutableMissingAttributeDetail(); + statusDetail.addMissingAttributeDetail(mad); + status.setStatusDetail(statusDetail); + result.setStatus(status); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Status with StatusDetail with valid detail with no value when MissingAttribute + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); + statusDetail = new StdMutableStatusDetail(); + mad = new StdMutableMissingAttributeDetail(); + mad.setAttributeId(new IdentifierImpl("mad")); + mad.setCategory(XACML3.ID_ACTION); + mad.setDataTypeId(DataTypes.DT_STRING.getId()); + statusDetail.addMissingAttributeDetail(mad); + status.setStatusDetail(statusDetail); + result.setStatus(status); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"},\"StatusDetail\":\"\"},\"Decision\":\"Indeterminate\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // Status with StatusDetail with valid detail with value when MissingAttribute + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); + statusDetail = new StdMutableStatusDetail(); + mad = new StdMutableMissingAttributeDetail(); + mad.setAttributeId(new IdentifierImpl("mad")); + mad.setCategory(XACML3.ID_ACTION); + mad.setDataTypeId(DataTypes.DT_STRING.getId()); + mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_STRING.getId(), "meh")); + statusDetail.addMissingAttributeDetail(mad); + status.setStatusDetail(statusDetail); + result.setStatus(status); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"},\"StatusDetail\":\"meh\"},\"Decision\":\"Indeterminate\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // Status with StatusDetail with array valid detail with value when MissingAttribute + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); + statusDetail = new StdMutableStatusDetail(); + mad = new StdMutableMissingAttributeDetail(); + mad.setAttributeId(new IdentifierImpl("mad")); + mad.setCategory(XACML3.ID_ACTION); + mad.setDataTypeId(DataTypes.DT_STRING.getId()); + mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_STRING.getId(), "meh")); + mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_STRING.getId(), "nu?")); + statusDetail.addMissingAttributeDetail(mad); + status.setStatusDetail(statusDetail); + result.setStatus(status); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"},\"StatusDetail\":\"mehnu?\"},\"Decision\":\"Indeterminate\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // Status with StatusDetail with valid detail with Integer value when MissingAttribute + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); + statusDetail = new StdMutableStatusDetail(); + mad = new StdMutableMissingAttributeDetail(); + mad.setAttributeId(new IdentifierImpl("mad")); + mad.setCategory(XACML3.ID_ACTION); + mad.setDataTypeId(DataTypes.DT_INTEGER.getId()); + mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(1111))); + statusDetail.addMissingAttributeDetail(mad); + status.setStatusDetail(statusDetail); + result.setStatus(status); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); +// assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"},\"StatusDetail\":\"1111\"},\"Decision\":\"Indeterminate\"}]}", jsonResponse); + } catch (Exception e) { + java.io.StringWriter sw = new java.io.StringWriter(); + java.io.PrintWriter pw = new java.io.PrintWriter(sw); + e.printStackTrace(pw); + + + fail("operation failed, e="+e + sw.toString()); + } + + // Status with StatusDetail with array valid detail with Integer value when MissingAttribute + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); + statusDetail = new StdMutableStatusDetail(); + mad = new StdMutableMissingAttributeDetail(); + mad.setAttributeId(new IdentifierImpl("mad")); + mad.setCategory(XACML3.ID_ACTION); + mad.setDataTypeId(DataTypes.DT_STRING.getId()); + mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(1111))); + mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(2222))); + statusDetail.addMissingAttributeDetail(mad); + status.setStatusDetail(statusDetail); + result.setStatus(status); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"},\"StatusDetail\":\"11112222\"},\"Decision\":\"Indeterminate\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + +// StringNamespaceContext snc = new StringNamespaceContext(); +// try { +// snc.add("defaultURI"); +// snc.add("md", "referenceForMD"); +// } catch (Exception e) { +// fail("unable to create NamespaceContext e="+e); +// } +// XPathExpressionWrapper xpathExpressionWrapper = new XPathExpressionWrapper(snc, "//md:record"); +// +//TODO - assume that we will never try to pass back an XPathExpression in a MissingAttributeDetail - it doesn't make sense and is unclear how to put into XML +// // Status with StatusDetail with valid detail with XPathExpression value when MissingAttribute +// response = new StdMutableResponse(); +// result = new StdMutableResult(); +// status = new StdMutableStatus(); +// status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); +// statusDetail = new StdMutableStatusDetail(); +// mad = new StdMutableMissingAttributeDetail(); +// mad.setAttributeId(new IdentifierImpl("mad")); +// mad.setCategory(XACML3.ID_ACTION); +// mad.setDataTypeId(DataTypes.DT_STRING.getId()); +// mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("xpathCategoryId"))); +// statusDetail.addMissingAttributeDetail(mad); +// status.setStatusDetail(statusDetail); +// result.setStatus(status); +// result.setDecision(Decision.INDETERMINATE); +// response.add(result); +// try { +// jsonResponse = JSONResponse.toString(response, false); +// assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"},\"StatusDetail\":\"1111urn:oasis:names:tc:xacml:1.0:actionmadhttp://www.w3.org/2001/XMLSchema#string\"},\"Decision\":\"Indeterminate\"}]}", jsonResponse); +// } catch (Exception e) { +// fail("operation failed, e="+e); +// } +// +// // Status with StatusDetail with array valid detail with XPathExpression value when MissingAttribute +// response = new StdMutableResponse(); +// result = new StdMutableResult(); +// status = new StdMutableStatus(); +// status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); +// statusDetail = new StdMutableStatusDetail(); +// mad = new StdMutableMissingAttributeDetail(); +// mad.setAttributeId(new IdentifierImpl("mad")); +// mad.setCategory(XACML3.ID_ACTION); +// mad.setDataTypeId(DataTypes.DT_STRING.getId()); +// mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("xpathCategoryId1"))); +// mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("xpathCategoryId2"))); +// statusDetail.addMissingAttributeDetail(mad); +// status.setStatusDetail(statusDetail); +// result.setStatus(status); +// result.setDecision(Decision.INDETERMINATE); +// response.add(result); +// try { +// jsonResponse = JSONResponse.toString(response, false); +// assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"},\"StatusDetail\":\"11112222urn:oasis:names:tc:xacml:1.0:actionmadhttp://www.w3.org/2001/XMLSchema#string\"},\"Decision\":\"Indeterminate\"}]}", jsonResponse); +// } catch (Exception e) { +// fail("operation failed, e="+e); +// } + +//TODO - try with other data types, esp XPathExpression + + // Status with StatusDetail with array valid detail with value when SyntaxError + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_SYNTAX_ERROR); + statusDetail = new StdMutableStatusDetail(); + mad = new StdMutableMissingAttributeDetail(); + mad.setAttributeId(new IdentifierImpl("mad")); + mad.setCategory(XACML3.ID_ACTION); + mad.setDataTypeId(DataTypes.DT_STRING.getId()); + mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_STRING.getId(), "meh")); + mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_STRING.getId(), "nu?")); + statusDetail.addMissingAttributeDetail(mad); + status.setStatusDetail(statusDetail); + result.setStatus(status); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Status with StatusDetail with array valid detail with value when ProcessingError + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + status.setStatusCode(StdStatusCode.STATUS_CODE_PROCESSING_ERROR); + statusDetail = new StdMutableStatusDetail(); + mad = new StdMutableMissingAttributeDetail(); + mad.setAttributeId(new IdentifierImpl("mad")); + mad.setCategory(XACML3.ID_ACTION); + mad.setDataTypeId(DataTypes.DT_STRING.getId()); + mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_STRING.getId(), "meh")); + mad.addAttributeValue(new StdAttributeValue(DataTypes.DT_STRING.getId(), "nu?")); + statusDetail.addMissingAttributeDetail(mad); + status.setStatusDetail(statusDetail); + result.setStatus(status); + result.setDecision(Decision.INDETERMINATE); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + + // Status with nested child StatusCodes (child status containing child status containing...) + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + StdStatusCode child1StatusCode = new StdStatusCode(new IdentifierImpl("child1StatusCode")); + StdStatusCode statusCode = new StdStatusCode(XACML3.ID_STATUS_OK, child1StatusCode); + status = new StdMutableStatus(statusCode); + status.setStatusMessage("I'm ok, you're ok"); + result.setStatus(status); + result.setDecision(Decision.PERMIT); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"StatusCode\":{\"Value\":\"child1StatusCode\"},\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:ok\"},\"StatusMessage\":\"I'm ok, you're ok\"},\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + response = new StdMutableResponse(); + result = new StdMutableResult(); + status = new StdMutableStatus(); + StdStatusCode childChildChildStatusCode = new StdStatusCode(new IdentifierImpl("childChildChildStatusCode")); + StdStatusCode childChildStatusCode = new StdStatusCode(new IdentifierImpl("childChildStatusCode"), childChildChildStatusCode); + child1StatusCode = new StdStatusCode(new IdentifierImpl("child1StatusCode"), childChildStatusCode); + statusCode = new StdStatusCode(XACML3.ID_STATUS_OK, child1StatusCode); + status = new StdMutableStatus(statusCode); + status.setStatusMessage("I'm ok, you're ok"); + result.setStatus(status); + result.setDecision(Decision.PERMIT); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"StatusCode\":{\"StatusCode\":{\"StatusCode\":{\"Value\":\"childChildChildStatusCode\"},\"Value\":\"childChildStatusCode\"},\"Value\":\"child1StatusCode\"},\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:ok\"},\"StatusMessage\":\"I'm ok, you're ok\"},\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + } + + + + @Ignore //@Test + public void testObligations() { + + // create an XPathExpression for use later + StringNamespaceContext snc = new StringNamespaceContext(); + try { + snc.add("defaultURI"); + snc.add("md", "referenceForMD"); + } catch (Exception e) { + fail("unable to create NamespaceContext e="+e); + } + XPathExpressionWrapper xpathExpressionWrapper = new XPathExpressionWrapper(snc, "//md:record"); + XPathExpressionWrapper xpathExpressionWrapper2 = new XPathExpressionWrapper(snc, "//md:hospital"); + + StdMutableObligation obligation; + + // test Obligation single decision no attributes + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + obligation = new StdMutableObligation(); + obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + result.addObligation(obligation); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Obligations\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"}],\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // obligation missing Id + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + obligation = new StdMutableObligation(); + result.addObligation(obligation); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + + // AttributeAssignment - with AttributeId, Value, Category, DataType, Issuer + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + obligation = new StdMutableObligation(); + obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "obligation-issuer1", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Bart"))); + result.addObligation(obligation); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Obligations\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Issuer\":\"obligation-issuer1\",\"Value\":\"Bart\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // AttributeAssignment - with AttributeId, Value, no Category, DataType, Issuer + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + obligation = new StdMutableObligation(); + obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + null, + XACML3.ID_SUBJECT, + "obligation-issuer1", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Bart"))); + result.addObligation(obligation); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Obligations\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Issuer\":\"obligation-issuer1\",\"Value\":\"Bart\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // AttributeAssignment - Missing AttributeId + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + obligation = new StdMutableObligation(); + obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + null, + "obligation-issuer1", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Bart"))); + result.addObligation(obligation); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // AttributeAssignment - Missing Value + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + obligation = new StdMutableObligation(); + obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "obligation-issuer1", + null)); + result.addObligation(obligation); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Obligations\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Issuer\":\"obligation-issuer1\",\"Value\":\"\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // AttributeAssignment - missing DataType + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + obligation = new StdMutableObligation(); + obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "obligation-issuer1", + new StdAttributeValue(null, "Bart"))); + result.addObligation(obligation); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Obligations\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Issuer\":\"obligation-issuer1\",\"Value\":\"Bart\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // AttributeAssignment - missing issuer + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + obligation = new StdMutableObligation(); + obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + null, + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Bart"))); + result.addObligation(obligation); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Obligations\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Value\":\"Bart\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // AttributeAssignment - Integer type + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + obligation = new StdMutableObligation(); + obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + null, + new StdAttributeValue(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(1111)))); + result.addObligation(obligation); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Obligations\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Value\":1111,\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#integer\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // AttributeAssignment - XPathExpression type + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + obligation = new StdMutableObligation(); + obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + null, + new StdAttributeValue(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("SimpleXPathCategory")))); + result.addObligation(obligation); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Obligations\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Value\":{\"Namespaces\":[{\"Namespace\":\"referenceForMD\",\"Prefix\":\"md\"},{\"Namespace\":\"defaultURI\"}],\"XPathCategory\":\"SimpleXPathCategory\",\"XPath\":\"//md:record\"},\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + + + // + // Technically arrays cannot occur in Obligations and Advice elements. The XML spec boils down to the following definition: + // + // value + // value + // : + // may have multiple elements. + // For Obligations and Advice we can simulate an array by having multiple AttributeAssignment elements with the same Category, Id and Issuer. + // + + + // AttributeAssignment - Multiple values with same Category and Id (one way of doing array) + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + obligation = new StdMutableObligation(); + obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "obligation-issuer1", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Bart"))); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "obligation-issuer1", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Lisa"))); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "obligation-issuer1", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Maggie"))); + result.addObligation(obligation); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Obligations\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Issuer\":\"obligation-issuer1\",\"Value\":\"Bart\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"},{\"Issuer\":\"obligation-issuer1\",\"Value\":\"Lisa\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"},{\"Issuer\":\"obligation-issuer1\",\"Value\":\"Maggie\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // AttributeAssignment - Multiple Integer values with same Category and Id (one way of doing array) + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + obligation = new StdMutableObligation(); + obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "obligation-issuer1", + new StdAttributeValue(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(1111)))); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "obligation-issuer1", + new StdAttributeValue(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(2222)))); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "obligation-issuer1", + new StdAttributeValue(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(3333)))); + result.addObligation(obligation); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Obligations\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Issuer\":\"obligation-issuer1\",\"Value\":1111,\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#integer\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"},{\"Issuer\":\"obligation-issuer1\",\"Value\":2222,\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#integer\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"},{\"Issuer\":\"obligation-issuer1\",\"Value\":3333,\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#integer\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // Multiple XPathExpression values with same Category and Id (one way of doing array) + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + obligation = new StdMutableObligation(); + obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + null, + new StdAttributeValue(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("SimpleXPathCategory")))); + obligation.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + null, + new StdAttributeValue(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper2, new IdentifierImpl("SimpleXPathCategory")))); + result.addObligation(obligation); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Obligations\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Value\":{\"Namespaces\":[{\"Namespace\":\"referenceForMD\",\"Prefix\":\"md\"},{\"Namespace\":\"defaultURI\"}],\"XPathCategory\":\"SimpleXPathCategory\",\"XPath\":\"//md:record\"},\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"},{\"Value\":{\"Namespaces\":[{\"Namespace\":\"referenceForMD\",\"Prefix\":\"md\"},{\"Namespace\":\"defaultURI\"}],\"XPathCategory\":\"SimpleXPathCategory\",\"XPath\":\"//md:hospital\"},\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + } + + + + + @Ignore //@Test + public void testAdvice() { + + // create an XPathExpression for use later + StringNamespaceContext snc = new StringNamespaceContext(); + try { + snc.add("defaultURI"); + snc.add("md", "referenceForMD"); + } catch (Exception e) { + fail("unable to create NamespaceContext e="+e); + } + XPathExpressionWrapper xpathExpressionWrapper = new XPathExpressionWrapper(snc, "//md:record"); + XPathExpressionWrapper xpathExpressionWrapper2 = new XPathExpressionWrapper(snc, "//md:hospital"); + + StdMutableAdvice Advice; + + // test Advice single decision no attributes + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + Advice = new StdMutableAdvice(); + Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + result.addAdvice(Advice); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Decision\":\"Permit\",\"AssociatedAdvice\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"}]}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // Advice missing Id + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + Advice = new StdMutableAdvice(); + result.addAdvice(Advice); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + + + // AttributeAssignment - with AttributeId, Value, Category, DataType, Issuer + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + Advice = new StdMutableAdvice(); + Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "Advice-issuer1", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Bart"))); + result.addAdvice(Advice); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Decision\":\"Permit\",\"AssociatedAdvice\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Issuer\":\"Advice-issuer1\",\"Value\":\"Bart\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}]}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // AttributeAssignment - with AttributeId, Value, no Category, DataType, Issuer + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + Advice = new StdMutableAdvice(); + Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + null, + XACML3.ID_SUBJECT, + "Advice-issuer1", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Bart"))); + result.addAdvice(Advice); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Decision\":\"Permit\",\"AssociatedAdvice\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Issuer\":\"Advice-issuer1\",\"Value\":\"Bart\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}]}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // AttributeAssignment - Missing AttributeId + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + Advice = new StdMutableAdvice(); + Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + null, + "Advice-issuer1", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Bart"))); + result.addAdvice(Advice); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // AttributeAssignment - Missing Value + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + Advice = new StdMutableAdvice(); + Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "Advice-issuer1", + null)); + result.addAdvice(Advice); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Decision\":\"Permit\",\"AssociatedAdvice\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Issuer\":\"Advice-issuer1\",\"Value\":\"\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}]}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // AttributeAssignment - missing DataType + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + Advice = new StdMutableAdvice(); + Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "Advice-issuer1", + new StdAttributeValue(null, "Bart"))); + result.addAdvice(Advice); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Decision\":\"Permit\",\"AssociatedAdvice\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Issuer\":\"Advice-issuer1\",\"Value\":\"Bart\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}]}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // AttributeAssignment - missing issuer + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + Advice = new StdMutableAdvice(); + Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + null, + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Bart"))); + result.addAdvice(Advice); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Decision\":\"Permit\",\"AssociatedAdvice\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Value\":\"Bart\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}]}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // AttributeAssignment - Integer type + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + Advice = new StdMutableAdvice(); + Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + null, + new StdAttributeValue(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(1111)))); + result.addAdvice(Advice); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Decision\":\"Permit\",\"AssociatedAdvice\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Value\":1111,\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#integer\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}]}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // AttributeAssignment - XPathExpression type + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + Advice = new StdMutableAdvice(); + Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + null, + new StdAttributeValue(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("SimpleXPathCategory")))); + result.addAdvice(Advice); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Decision\":\"Permit\",\"AssociatedAdvice\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Value\":{\"Namespaces\":[{\"Namespace\":\"referenceForMD\",\"Prefix\":\"md\"},{\"Namespace\":\"defaultURI\"}],\"XPathCategory\":\"SimpleXPathCategory\",\"XPath\":\"//md:record\"},\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}]}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + + + // + // Technically arrays cannot occur in Obligations and Advice elements. The XML spec boils down to the following definition: + // + // value + // value + // : + // may have multiple elements. + // For Obligations and Advice we can simulate an array by having multiple AttributeAssignment elements with the same Category, Id and Issuer. + // + + // AttributeAssignment - Multiple values with same Category and Id (one way of doing array) + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + Advice = new StdMutableAdvice(); + Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "Advice-issuer1", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Bart"))); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "Advice-issuer1", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Lisa"))); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "Advice-issuer1", + new StdAttributeValue(DataTypes.DT_STRING.getId(), "Maggie"))); + result.addAdvice(Advice); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Decision\":\"Permit\",\"AssociatedAdvice\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Issuer\":\"Advice-issuer1\",\"Value\":\"Bart\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"},{\"Issuer\":\"Advice-issuer1\",\"Value\":\"Lisa\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"},{\"Issuer\":\"Advice-issuer1\",\"Value\":\"Maggie\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}]}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // AttributeAssignment - Multiple Integer values with same Category and Id (one way of doing array) + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + Advice = new StdMutableAdvice(); + Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "Advice-issuer1", + new StdAttributeValue(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(1111)))); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "Advice-issuer1", + new StdAttributeValue(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(2222)))); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + "Advice-issuer1", + new StdAttributeValue(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(3333)))); + result.addAdvice(Advice); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Decision\":\"Permit\",\"AssociatedAdvice\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Issuer\":\"Advice-issuer1\",\"Value\":1111,\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#integer\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"},{\"Issuer\":\"Advice-issuer1\",\"Value\":2222,\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#integer\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"},{\"Issuer\":\"Advice-issuer1\",\"Value\":3333,\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#integer\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}]}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // Multiple XPathExpression values with same Category and Id (one way of doing array) + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + Advice = new StdMutableAdvice(); + Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + null, + new StdAttributeValue(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("SimpleXPathCategory")))); + Advice.addAttributeAssignment(new StdMutableAttributeAssignment( + XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + XACML3.ID_SUBJECT, + null, + new StdAttributeValue(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper2, new IdentifierImpl("SimpleXPathCategory")))); + result.addAdvice(Advice); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Decision\":\"Permit\",\"AssociatedAdvice\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Value\":{\"Namespaces\":[{\"Namespace\":\"referenceForMD\",\"Prefix\":\"md\"},{\"Namespace\":\"defaultURI\"}],\"XPathCategory\":\"SimpleXPathCategory\",\"XPath\":\"//md:record\"},\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"},{\"Value\":{\"Namespaces\":[{\"Namespace\":\"referenceForMD\",\"Prefix\":\"md\"},{\"Namespace\":\"defaultURI\"}],\"XPathCategory\":\"SimpleXPathCategory\",\"XPath\":\"//md:hospital\"},\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}]}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + } + + + + + + + + + + + // Attributes tests + @Ignore //@Test + public void testAttributes() { + + // create an XPathExpression for use later + StringNamespaceContext snc = new StringNamespaceContext(); + try { + snc.add("defaultURI"); + snc.add("md", "referenceForMD"); + } catch (Exception e) { + fail("unable to create NamespaceContext e="+e); + } + XPathExpressionWrapper xpathExpressionWrapper = new XPathExpressionWrapper(snc, "//md:record"); + + + Identifier categoryIdentifier; + List attrList = new ArrayList(); + StdMutableAttribute mutableAttribute; + + // Attr list with no entries + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Category\":[{\"CategoryId\":\"firstCategory\",\"Attribute\":[]}],\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // one Attribute + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true)); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Category\":[{\"CategoryId\":\"firstCategory\",\"Attribute\":[{\"Issuer\":\"AIssue\",\"Value\":\"Apu\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent1\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // multiple attributes + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent2"), new StdAttributeValue(DataTypes.DT_YEARMONTHDURATION.getId(), "P10Y4M"), "BIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent3"), new StdAttributeValue(DataTypes.DT_DOUBLE.getId(), 765.432), "CIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent4"), new StdAttributeValue(DataTypes.DT_BOOLEAN.getId(), true), "DIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent5"), new StdAttributeValue(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(4567)), "EIssue", true)); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Category\":[{\"CategoryId\":\"firstCategory\",\"Attribute\":[{\"Issuer\":\"AIssue\",\"Value\":\"Apu\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent1\"},{\"Issuer\":\"BIssue\",\"Value\":\"P10Y4M\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#yearMonthDuration\",\"AttributeId\":\"attrIdent2\"},{\"Issuer\":\"CIssue\",\"Value\":765.432,\"DataType\":\"http://www.w3.org/2001/XMLSchema#double\",\"AttributeId\":\"attrIdent3\"},{\"Issuer\":\"DIssue\",\"Value\":true,\"DataType\":\"http://www.w3.org/2001/XMLSchema#boolean\",\"AttributeId\":\"attrIdent4\"},{\"Issuer\":\"EIssue\",\"Value\":4567,\"DataType\":\"http://www.w3.org/2001/XMLSchema#integer\",\"AttributeId\":\"attrIdent5\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // IncludeInResult=false/true + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", false)); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Category\":[{\"CategoryId\":\"firstCategory\",\"Attribute\":[]}],\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // Missing AttributeId (mandatory) + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + attrList.add(new StdAttribute(categoryIdentifier, null, new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true)); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Missing mandatory Value + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), null), "AIssue", true)); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // Missing optional Issuer + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu"), null, true)); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Category\":[{\"CategoryId\":\"firstCategory\",\"Attribute\":[{\"Value\":\"Apu\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent1\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // missing optional DataType + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(null, "Apu"), "AIssue", true)); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Category\":[{\"CategoryId\":\"firstCategory\",\"Attribute\":[{\"Issuer\":\"AIssue\",\"Value\":\"Apu\",\"AttributeId\":\"attrIdent1\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // same id, same type different issuer + // (This is not an array of values because issuer is different) + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Bart"), "BIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Simpson"), "CIssue", true)); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Category\":[{\"CategoryId\":\"firstCategory\",\"Attribute\":[{\"Issuer\":\"AIssue\",\"Value\":\"Apu\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent1\"},{\"Issuer\":\"BIssue\",\"Value\":\"Bart\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent1\"},{\"Issuer\":\"CIssue\",\"Value\":\"Simpson\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent1\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // same id, same type different issuer + // (This is effectively an array of values, but we return them as separate values to the client) + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Bart"), "AIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Simpson"), "AIssue", true)); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Category\":[{\"CategoryId\":\"firstCategory\",\"Attribute\":[{\"Issuer\":\"AIssue\",\"Value\":\"Apu\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent1\"},{\"Issuer\":\"AIssue\",\"Value\":\"Bart\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent1\"},{\"Issuer\":\"AIssue\",\"Value\":\"Simpson\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent1\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // same Id, different types, same issuer + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_YEARMONTHDURATION.getId(), "P10Y4M"), "AIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_DOUBLE.getId(), 765.432), "AIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_BOOLEAN.getId(), true), "AIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(4567)), "AIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(4567)), "AIssue", true)); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Category\":[{\"CategoryId\":\"firstCategory\",\"Attribute\":[{\"Issuer\":\"AIssue\",\"Value\":\"Apu\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent1\"},{\"Issuer\":\"AIssue\",\"Value\":\"P10Y4M\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#yearMonthDuration\",\"AttributeId\":\"attrIdent1\"},{\"Issuer\":\"AIssue\",\"Value\":765.432,\"DataType\":\"http://www.w3.org/2001/XMLSchema#double\",\"AttributeId\":\"attrIdent1\"},{\"Issuer\":\"AIssue\",\"Value\":true,\"DataType\":\"http://www.w3.org/2001/XMLSchema#boolean\",\"AttributeId\":\"attrIdent1\"},{\"Issuer\":\"AIssue\",\"Value\":4567,\"DataType\":\"http://www.w3.org/2001/XMLSchema#integer\",\"AttributeId\":\"attrIdent1\"},{\"Issuer\":\"AIssue\",\"Value\":4567,\"DataType\":\"http://www.w3.org/2001/XMLSchema#integer\",\"AttributeId\":\"attrIdent1\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // same Id, different types, different issuer + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_YEARMONTHDURATION.getId(), "P10Y4M"), "BIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_DOUBLE.getId(), 765.432), "CIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_BOOLEAN.getId(), true), "DIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(4567)), "EIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(4567)), null, true)); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Category\":[{\"CategoryId\":\"firstCategory\",\"Attribute\":[{\"Issuer\":\"AIssue\",\"Value\":\"Apu\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent1\"},{\"Issuer\":\"BIssue\",\"Value\":\"P10Y4M\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#yearMonthDuration\",\"AttributeId\":\"attrIdent1\"},{\"Issuer\":\"CIssue\",\"Value\":765.432,\"DataType\":\"http://www.w3.org/2001/XMLSchema#double\",\"AttributeId\":\"attrIdent1\"},{\"Issuer\":\"DIssue\",\"Value\":true,\"DataType\":\"http://www.w3.org/2001/XMLSchema#boolean\",\"AttributeId\":\"attrIdent1\"},{\"Issuer\":\"EIssue\",\"Value\":4567,\"DataType\":\"http://www.w3.org/2001/XMLSchema#integer\",\"AttributeId\":\"attrIdent1\"},{\"Value\":4567,\"DataType\":\"http://www.w3.org/2001/XMLSchema#integer\",\"AttributeId\":\"attrIdent1\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + // different Id, different types, same issuer + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent2"), new StdAttributeValue(DataTypes.DT_YEARMONTHDURATION.getId(), "AIssue"), "BIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent3"), new StdAttributeValue(DataTypes.DT_DOUBLE.getId(), 765.432), "AIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent4"), new StdAttributeValue(DataTypes.DT_BOOLEAN.getId(), true), "AIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent5"), new StdAttributeValue(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(4567)), "AIssue", true)); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Category\":[{\"CategoryId\":\"firstCategory\",\"Attribute\":[{\"Issuer\":\"AIssue\",\"Value\":\"Apu\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent1\"},{\"Issuer\":\"BIssue\",\"Value\":\"AIssue\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#yearMonthDuration\",\"AttributeId\":\"attrIdent2\"},{\"Issuer\":\"AIssue\",\"Value\":765.432,\"DataType\":\"http://www.w3.org/2001/XMLSchema#double\",\"AttributeId\":\"attrIdent3\"},{\"Issuer\":\"AIssue\",\"Value\":true,\"DataType\":\"http://www.w3.org/2001/XMLSchema#boolean\",\"AttributeId\":\"attrIdent4\"},{\"Issuer\":\"AIssue\",\"Value\":4567,\"DataType\":\"http://www.w3.org/2001/XMLSchema#integer\",\"AttributeId\":\"attrIdent5\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // one Attribute of type XPathExpression (the only complex data type) + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("xpathCategory")), "AIssue", true)); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Category\":[{\"CategoryId\":\"firstCategory\",\"Attribute\":[{\"Issuer\":\"AIssue\",\"Value\":{\"Namespaces\":[{\"Namespace\":\"referenceForMD\",\"Prefix\":\"md\"},{\"Namespace\":\"defaultURI\"}],\"XPathCategory\":\"xpathCategory\",\"XPath\":\"//md:record\"},\"DataType\":\"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\",\"AttributeId\":\"attrIdent1\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // multiple sets of values + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + categoryIdentifier = new IdentifierImpl("firstCategory"); + attrList.clear(); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent2"), new StdAttributeValue(DataTypes.DT_YEARMONTHDURATION.getId(), "P10Y4M"), "BIssue", false)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent3"), new StdAttributeValue(DataTypes.DT_DOUBLE.getId(), 765.432), "CIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent4"), new StdAttributeValue(DataTypes.DT_BOOLEAN.getId(), true), "DIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent5"), new StdAttributeValue(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(4567)), "EIssue", true)); + attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrNoIssuer"), new StdAttributeValue(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(4567)), null, true)); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + categoryIdentifier = new IdentifierImpl("secondCategory"); + Attribute[] secondAttrList = { + new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent12"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu2"), "AIssue2", true), + new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent22"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Abc2"), "BIssue2", false), + new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent32"), new StdAttributeValue(DataTypes.DT_STRING.getId(), "Der2"), "CIssue2", true) }; + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, Arrays.asList(secondAttrList))); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Category\":[{\"CategoryId\":\"firstCategory\",\"Attribute\":[{\"Issuer\":\"AIssue\",\"Value\":\"Apu\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent1\"},{\"Issuer\":\"CIssue\",\"Value\":765.432,\"DataType\":\"http://www.w3.org/2001/XMLSchema#double\",\"AttributeId\":\"attrIdent3\"},{\"Issuer\":\"DIssue\",\"Value\":true,\"DataType\":\"http://www.w3.org/2001/XMLSchema#boolean\",\"AttributeId\":\"attrIdent4\"},{\"Issuer\":\"EIssue\",\"Value\":4567,\"DataType\":\"http://www.w3.org/2001/XMLSchema#integer\",\"AttributeId\":\"attrIdent5\"},{\"Value\":4567,\"DataType\":\"http://www.w3.org/2001/XMLSchema#integer\",\"AttributeId\":\"attrNoIssuer\"}]},{\"CategoryId\":\"secondCategory\",\"Attribute\":[{\"Issuer\":\"AIssue2\",\"Value\":\"Apu2\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent12\"},{\"Issuer\":\"CIssue2\",\"Value\":\"Der2\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent32\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // array of values - same type + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + attrList.clear(); + categoryIdentifier = new IdentifierImpl("firstCategory"); + mutableAttribute = new StdMutableAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), (Collection>)null, "AIssue", true); + + mutableAttribute.addValue(new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu")); + mutableAttribute.addValue(new StdAttributeValue(DataTypes.DT_STRING.getId(), "Bart")); + mutableAttribute.addValue(new StdAttributeValue(DataTypes.DT_STRING.getId(), "Homer")); + mutableAttribute.addValue(new StdAttributeValue(DataTypes.DT_STRING.getId(), "Ned")); + + attrList.add(mutableAttribute); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Category\":[{\"CategoryId\":\"firstCategory\",\"Attribute\":[{\"Issuer\":\"AIssue\",\"Value\":[\"Apu\",\"Bart\",\"Homer\",\"Ned\"],\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent1\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // array of values - compatible different types + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + attrList.clear(); + categoryIdentifier = new IdentifierImpl("firstCategory"); + mutableAttribute = new StdMutableAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), (Collection>)null, "AIssue", true); + + mutableAttribute.addValue(new StdAttributeValue(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(4567))); + mutableAttribute.addValue(new StdAttributeValue(DataTypes.DT_DOUBLE.getId(), 765.432)); + mutableAttribute.addValue(new StdAttributeValue(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(4567))); + attrList.add(mutableAttribute); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Category\":[{\"CategoryId\":\"firstCategory\",\"Attribute\":[{\"Issuer\":\"AIssue\",\"Value\":[4567,765.432,4567],\"DataType\":\"http://www.w3.org/2001/XMLSchema#double\",\"AttributeId\":\"attrIdent1\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // array of values - incompatible different types + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + attrList.clear(); + categoryIdentifier = new IdentifierImpl("firstCategory"); + mutableAttribute = new StdMutableAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), (Collection>)null, "AIssue", true); + + mutableAttribute.addValue(new StdAttributeValue(DataTypes.DT_STRING.getId(), "Apu")); + mutableAttribute.addValue(new StdAttributeValue(DataTypes.DT_YEARMONTHDURATION.getId(), "P10Y4M")); + mutableAttribute.addValue(new StdAttributeValue(DataTypes.DT_DOUBLE.getId(), 765.432)); + mutableAttribute.addValue(new StdAttributeValue(DataTypes.DT_BOOLEAN.getId(), true)); + mutableAttribute.addValue(new StdAttributeValue(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(4567))); + mutableAttribute.addValue(new StdAttributeValue(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(4567))); + attrList.add(mutableAttribute); + result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + } + + + + + + // PolicyIdentifier tests + @Ignore //@Test + public void testPolicyIdentifier() { + + StdIdReference policyIdentifier1 = null; + StdIdReference policyIdentifier2 = null; + StdIdReference policySetIdentifier1 = null; + StdIdReference policySetIdentifier2 = null; + + // multiple PolicyIdentifiers of both types + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + try { + policyIdentifier1 = new StdIdReference(new IdentifierImpl("idRef1"), StdVersion.newInstance("1.2.3")); + policyIdentifier2 = new StdIdReference(new IdentifierImpl("idRef2_NoVersion")); + policySetIdentifier1 = new StdIdReference(new IdentifierImpl("idSetRef1"), StdVersion.newInstance("4.5.6.7.8.9.0")); + policySetIdentifier2 = new StdIdReference(new IdentifierImpl("idSetRef2_NoVersion")); + } catch (ParseException e1) { + fail("creating policyIds, e="+e1); + } + result.addPolicyIdentifier(policyIdentifier1); + result.addPolicyIdentifier(policyIdentifier2); + result.addPolicySetIdentifier(policySetIdentifier1); + result.addPolicySetIdentifier(policySetIdentifier2); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Decision\":\"Permit\",\"PolicyIdentifier\":{\"PolicyIdReference\":[{\"Id\":\"idRef1\",\"Version\":\"1.2.3\"},{\"Id\":\"idRef2_NoVersion\"}],\"PolicySetIdReference\":[{\"Id\":\"idSetRef1\",\"Version\":\"4.5.6.7.8.9.0\"},{\"Id\":\"idSetRef2_NoVersion\"}]}}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // PolicyIdentifier exists but has no IdReferences + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + policyIdentifier1 = null; + result.addPolicyIdentifier(policyIdentifier1); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // PolicySetIdentifier exists but has not IdReferences + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + policySetIdentifier1 = null; + result.addPolicyIdentifier(policySetIdentifier1); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + fail("Operation should throw exception"); + } catch (JSONStructureException e) { + // correct response + } catch (Exception e) { + fail ("Failed convert from JSON to object: " + e); + } + + // PolicyIdentifier with PolicyIdReference and no PolicySetIdReference + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + try { + policyIdentifier1 = new StdIdReference(new IdentifierImpl("idRef1"), StdVersion.newInstance("1.2.3")); + } catch (ParseException e1) { + fail("creating policyIds, e="+e1); + } + result.addPolicyIdentifier(policyIdentifier1); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Decision\":\"Permit\",\"PolicyIdentifier\":{\"PolicyIdReference\":[{\"Id\":\"idRef1\",\"Version\":\"1.2.3\"}]}}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + + // PolicyIdentifier with no PolicyIdReference and with PolicySetIdReference + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + try { + policySetIdentifier1 = new StdIdReference(new IdentifierImpl("idSetRef1"), StdVersion.newInstance("4.5.6.7.8.9.0")); + } catch (ParseException e1) { + fail("creating policyIds, e="+e1); + } + result.addPolicySetIdentifier(policySetIdentifier1); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Decision\":\"Permit\",\"PolicyIdentifier\":{\"PolicySetIdReference\":[{\"Id\":\"idSetRef1\",\"Version\":\"4.5.6.7.8.9.0\"}]}}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + + + // IdReferences without version + response = new StdMutableResponse(); + result = new StdMutableResult(); + result.setDecision(Decision.PERMIT); + + policyIdentifier1 = new StdIdReference(new IdentifierImpl("idRef1"), null); + policyIdentifier2 = new StdIdReference(new IdentifierImpl("idRef2_NoVersion")); + policySetIdentifier1 = new StdIdReference(new IdentifierImpl("idSetRef1")); + policySetIdentifier2 = new StdIdReference(new IdentifierImpl("idSetRef2_NoVersion")); + + result.addPolicyIdentifier(policyIdentifier1); + result.addPolicyIdentifier(policyIdentifier2); + result.addPolicySetIdentifier(policySetIdentifier1); + result.addPolicySetIdentifier(policySetIdentifier2); + response.add(result); + try { + jsonResponse = JSONResponse.toString(response, false); + assertEquals("{\"Response\":[{\"Decision\":\"Permit\",\"PolicyIdentifier\":{\"PolicyIdReference\":[{\"Id\":\"idRef1\"},{\"Id\":\"idRef2_NoVersion\"}],\"PolicySetIdReference\":[{\"Id\":\"idSetRef1\"},{\"Id\":\"idSetRef2_NoVersion\"}]}}]}", jsonResponse); + } catch (Exception e) { + fail("operation failed, e="+e); + } + } + + +//TODO - the JSON and XML spec imply that the Result Attributes may include the Content (It is part of the UML) + + + // test indentation??? + + // order does not matter?? + +} + + + + + + + + + + + + + + + + diff --git a/ECOMP-XACML/src/test/resources/log4j.properties b/ECOMP-XACML/src/test/resources/log4j.properties new file mode 100644 index 000000000..4c9773d76 --- /dev/null +++ b/ECOMP-XACML/src/test/resources/log4j.properties @@ -0,0 +1,42 @@ +### +# ============LICENSE_START======================================================= +# ECOMP-XACML +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +# +# Use this properties for debugging and development. +# +# +# Set root logger level to DEBUG and its only appender to A1. +log4j.rootLogger=INFO, MAIN_LOG + +# A1 is set to be a ConsoleAppender. +log4j.appender.MAIN_LOG=org.apache.log4j.ConsoleAppender + +# A1 uses PatternLayout. +log4j.appender.MAIN_LOG.layout=org.apache.log4j.PatternLayout +log4j.appender.MAIN_LOG.layout.ConversionPattern=%d{yyyy_MM_dd_HH_mm_ss_SSS} [%t] %-5p %l- %m%n + +# +# This is specifically for Xacml request/response logging +# +log4j.logger.xacml.request=INFO, REQUEST_LOG + +log4j.appender.REQUEST_LOG=org.apache.log4j.ConsoleAppender +log4j.appender.REQUEST_LOG.layout=org.apache.log4j.PatternLayout +log4j.appender.REQUEST_LOG.layout.ConversionPattern=%d{yyyy_MM_dd_HH_mm_ss_SSS} %m%n diff --git a/ECOMP-XACML/src/test/resources/logback.xml b/ECOMP-XACML/src/test/resources/logback.xml new file mode 100644 index 000000000..f2b70a01b --- /dev/null +++ b/ECOMP-XACML/src/test/resources/logback.xml @@ -0,0 +1,252 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --> + + + + + + + + + + + + + + + + + + + + ${defaultPattern} + + + + + + + + + + + + + ${logDirectory}/${auditLogName}.log + + ${logDirectory}/${auditLogName}.%i.log.zip + + 1 + 9 + + + 5MB + + + ${defaultAuditPattern} + + + + + 256 + + + + + + + + ${logDirectory}/${metricsLogName}.log + + ${logDirectory}/${metricsLogName}.%i.log.zip + + 1 + 9 + + + 5MB + + + + ${defaultMetricPattern} + + + + + 256 + + + + + + + + ${logDirectory}/${errorLogName}.log + + ${logDirectory}/${errorLogName}.%i.log.zip + + 1 + 9 + + + ERROR + + + 5MB + + + ${defaultErrorPattern} + + + + + 256 + + + + + + + ${debugLogDirectory}/${debugLogName}.log + + ${debugLogDirectory}/${debugLogName}.%i.log.zip + + 1 + 9 + + + INFO + + + 5MB + + + ${debugLoggerPattern} + + + + + 256 + + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ECOMP-XACML/src/test/resources/logging.properties b/ECOMP-XACML/src/test/resources/logging.properties new file mode 100644 index 000000000..6d1bd488e --- /dev/null +++ b/ECOMP-XACML/src/test/resources/logging.properties @@ -0,0 +1,32 @@ +### +# ============LICENSE_START======================================================= +# ECOMP-XACML +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +handlers = java.util.logging.ConsoleHandler, java.util.logging.FileHandler + +.level = FINE + +java.util.logging.SimpleFormatter.format=%4$s: %5$s %n + +java.util.logging.ConsoleHandler.level = FINEST +java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter + +java.util.logging.FileHandler.level = SEVERE +java.util.logging.FileHandler.pattern=%h/xacml_log%u.log +java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter diff --git a/ECOMP-XACML/src/test/resources/xacml.pip.properties b/ECOMP-XACML/src/test/resources/xacml.pip.properties new file mode 100644 index 000000000..dbff01086 --- /dev/null +++ b/ECOMP-XACML/src/test/resources/xacml.pip.properties @@ -0,0 +1,23 @@ +### +# ============LICENSE_START======================================================= +# ECOMP-XACML +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +# +#Fri Mar 06 12:06:30 EST 2015 +xacml.pip.engines= diff --git a/ECOMP-XACML/src/test/resources/xacml.policy.properties b/ECOMP-XACML/src/test/resources/xacml.policy.properties new file mode 100644 index 000000000..b1247cdfc --- /dev/null +++ b/ECOMP-XACML/src/test/resources/xacml.policy.properties @@ -0,0 +1,25 @@ +### +# ============LICENSE_START======================================================= +# ECOMP-XACML +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +# +#Fri Mar 06 12:06:30 EST 2015 +xacml.referencedPolicies= +xacml.rootPolicies= + diff --git a/ECOMP-XACML/testclient.properties b/ECOMP-XACML/testclient.properties new file mode 100644 index 000000000..84bcd4363 --- /dev/null +++ b/ECOMP-XACML/testclient.properties @@ -0,0 +1,21 @@ +### +# ============LICENSE_START======================================================= +# ECOMP-XACML +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +test=test,MASTER diff --git a/ECOMP-XACML/testpdp.properties b/ECOMP-XACML/testpdp.properties new file mode 100644 index 000000000..500f8a406 --- /dev/null +++ b/ECOMP-XACML/testpdp.properties @@ -0,0 +1,21 @@ +### +# ============LICENSE_START======================================================= +# ECOMP-XACML +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +PDP_URL= , test, test diff --git a/ECOMP-XACML/xacml.pap.properties b/ECOMP-XACML/xacml.pap.properties new file mode 100644 index 000000000..15c5cfb9c --- /dev/null +++ b/ECOMP-XACML/xacml.pap.properties @@ -0,0 +1,107 @@ +### +# ============LICENSE_START======================================================= +# ECOMP-XACML +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +# +# This is our factory that will create our engine +# +xacml.PAP.papEngineFactory=org.openecomp.policy.xacml.std.pap.StdEngineFactory + +# +# Where we store our PAP PDP Group/Node information +# +xacml.pap.pdps=pdps +# +# Need the PAP's url (how PDPs will reach it) configured here +# because we need it to generate the URLs of the Policy Files +# sent to the PDPs in the configuration when the PAP is first brought up. +# (In other cases, such as the PDP calling the PAP, we could generate this URL, +# but for startup there is no other way to get it.) +# +# + +xacml.rest.pap.url=http://localhost:8070/pap/ + +# +# Upon startup, have the PAP servlet send latest configuration information to all +# the PDP nodes it knows about. +# +xacml.rest.pap.initiate.pdp=true +# +# Heartbeat from PAP to PDPs +# +# How much time (in milliseconds) between heartbeats +# (i.e. the time between completing the heartbeat with all PDPs and starting the next cycle) +# +xacml.rest.pap.heartbeat.interval=10000 +# +# Heartbeat connection timeout (in milliseconds) +# +xacml.rest.pap.heartbeat.timeout=10000 + +################################################################################################ +# Adding properties for getting properties previously used by PAP-ADMIN for creating Policies +# THis is part of the Policy Creation API project +################################################################################################ + +# Set your domain here: +xacml.rest.pap.domain=com + +# Location where all the user workspaces are located. +xacml.rest.pap.workspace=workspace + +# Location where the GIT repository is located +xacml.rest.pap.repository=repository + +# new Property Please mention your PAP-REST webapps Location here. +xacml.rest.config.webapps=C:\\Second Tomcat\\apache-tomcat-8.0.23\\webapps\\ConfigPAP\\ + +#Turn the audit on to synchronize the DB/file system +#xacml.rest.pap.run.audit.flag=true +#Turn the audit off to not synchronize the DB/file system +#xacml.rest.pap.run.audit.flag=false +xacml.rest.pap.run.audit.flag=false + +#Audit will synchronize the file system to match the contents of the DB +#xacml.rest.pap.filesystem.audit=true +#Audit will synchronize the DB to match the contents of the file system +#xacml.rest.pap.filesystem.audit=false +xacml.rest.pap.filesystem.audit=false + +# id +xacml.rest.pap.userid=testpap +# pass +xacml.rest.pap.password=alpha123 +# pdps file +xacml.rest.pdp.idfile=test.properties + +#Properties for db access +javax.persistence.jdbc.driver=org.h2.Driver +javax.persistence.jdbc.url=jdbc:h2:file:./sql/xacmlTest +javax.persistence.jdbc.user=sa +javax.persistence.jdbc.password= + +#Time in ms which a Policy DB transaction will wait to get the transaction lock object +xacml.rest.pap.transaction.waitms=1000 + +#Policy DB transaction timeout in ms after it has obtained the transaction lock object +xacml.rest.pap.transaction.timeoutms=500 + +#Policy Audit timeout in ms after it has obtained the transaction lock object +xacml.rest.pap.audit.timeoutms=5000 diff --git a/ECOMP-XACML/xacml.pdp.properties b/ECOMP-XACML/xacml.pdp.properties new file mode 100644 index 000000000..fc731bf29 --- /dev/null +++ b/ECOMP-XACML/xacml.pdp.properties @@ -0,0 +1,86 @@ +### +# ============LICENSE_START======================================================= +# ECOMP-XACML +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +# Default XACML Properties File for PDP RESTful servlet +# +# Standard API Factories +# +xacml.dataTypeFactory=com.att.research.xacml.std.StdDataTypeFactory +xacml.pdpEngineFactory=com.att.research.xacmlatt.pdp.ATTPDPEngineFactory +xacml.pepEngineFactory=com.att.research.xacml.std.pep.StdEngineFactory +# NOT USED SEE BELOW xacml.pipFinderFactory=org.openecomp.policy.xacml.std.pip.StdPIPFinderFactory +xacml.traceEngineFactory=com.att.research.xacml.std.trace.LoggingTraceEngineFactory +# +# AT&T PDP Implementation Factories +# +xacml.att.evaluationContextFactory=com.att.research.xacmlatt.pdp.std.StdEvaluationContextFactory +xacml.att.combiningAlgorithmFactory=com.att.research.xacmlatt.pdp.std.StdCombiningAlgorithmFactory +xacml.att.functionDefinitionFactory=com.att.research.xacmlatt.pdp.std.StdFunctionDefinitionFactory +# NOT USED SEE BELOW xacml.att.policyFinderFactory=com.att.research.xacmlatt.pdp.std.StdPolicyFinderFactory + +# +# AT&T RESTful PDP Implementation Factories +# +xacml.pipFinderFactory=org.openecomp.policy.pdp.rest.impl.XACMLPdpPIPFinderFactory +xacml.att.policyFinderFactory=org.openecomp.policy.pdp.rest.impl.XACMLPdpPolicyFinderFactory +# +# When set to true, this flag tells the StdPolicyFinderFactory to combined all the root policy files into +# into one PolicySet and use the given Policy Algorithm. +# +xacml.att.policyFinderFactory.combineRootPolicies=urn:com:att:xacml:3.0:policy-combining-algorithm:combined-deny-overrides +# +# PDP RESTful API properties +# +# Set this to the address where the XACML-PAP-REST servlet is running +# http://localhost:9090/pap/ +xacml.rest.pap.url=http://localhost:8070/pap/ +# +# Give the running PDP an ID for the PAP. The url that its running as is a good choice. +# The PAP identifies PDP's using the URL of the PDP. +# +xacml.rest.pdp.id=http://localhost:8082/pdp/ +# +# Set the directory where the PDP holds its Policy Cache and PIP Configuration +# +xacml.rest.pdp.config=config_testing + +xacml.rest.pdp.webapps=/webapps + +xacml.rest.pdp.configparams=../webapps/configparams +# +# Initialize register with PAP servlet +# +xacml.rest.pdp.register=true +# +# Sleep period in seconds between register attempts +# +xacml.rest.pdp.register.sleep=15 +# +# number of attempts to register. -1 means keep trying forever. +# +xacml.rest.pdp.register.retries=-1 +# +# max number of bytes in a POST of a XML/JSON request +# +xacml.rest.pdp.maxcontent=32767 +# +# testClient file +# +xacml.rest.pep.idfile = testclient.properties diff --git a/ECOMP-XACML/xacml.properties b/ECOMP-XACML/xacml.properties new file mode 100644 index 000000000..0c563028e --- /dev/null +++ b/ECOMP-XACML/xacml.properties @@ -0,0 +1,46 @@ +### +# ============LICENSE_START======================================================= +# ECOMP-XACML +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +# Default XACML Properties File +# Standard API Factories +# +xacml.dataTypeFactory=com.att.research.xacml.std.StdDataTypeFactory +xacml.pdpEngineFactory=com.att.research.xacmlatt.pdp.ATTPDPEngineFactory +xacml.pepEngineFactory=com.att.research.xacml.std.pep.StdEngineFactory +xacml.pipFinderFactory=com.att.research.xacml.std.pip.StdPIPFinderFactory + +# If there is a standard set of PIPEngines: +# xacml.pip.engines=engine1,engine2,...,engineN +# engine1.classname=com.att.research.xacmlpip.OraclePIP +# engine1.prop1=foo +# engine1.prop2=bar +# ... +# engine2.classname=com.att.research.xacmlpip.ActiveDirectoryPIP +# ... + +# AT&T PDP Implementation Factories +# +xacml.att.evaluationContextFactory=com.att.research.xacmlatt.pdp.std.StdEvaluationContextFactory +xacml.att.combiningAlgorithmFactory=com.att.research.xacmlatt.pdp.std.StdCombiningAlgorithmFactory +xacml.att.functionDefinitionFactory=com.att.research.xacmlatt.pdp.std.StdFunctionDefinitionFactory +xacml.att.policyFinderFactory=com.att.research.xacmlatt.pdp.std.StdPolicyFinderFactory + +# If there is a standard policy for the engine: +# xacml.att.stdPolicyFinderFactory.rootPolicyFile=/etc/stdpolicyset.xml diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 000000000..3ce0584e0 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,16 @@ +Copyright © 2017 AT&T Intellectual Property. All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); you may +not use this file except in compliance with the License. + +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +License for the specific language governing permissions and limitations +under the License. + +ECOMP and OpenECOMP are trademarks and service marks of AT&T Intellectual Property. diff --git a/LogParser/.gitignore b/LogParser/.gitignore new file mode 100644 index 000000000..09e3bc9b2 --- /dev/null +++ b/LogParser/.gitignore @@ -0,0 +1,2 @@ +/bin/ +/target/ diff --git a/LogParser/LineTest.txt b/LogParser/LineTest.txt new file mode 100644 index 000000000..449644219 --- /dev/null +++ b/LogParser/LineTest.txt @@ -0,0 +1,9 @@ +2016-04-26T00:00:00{GMT+0}+00:00|||Thread-5||||ERROR|||localhost.com||org.openecomp.policy.im.IntegrityMonitor.writeFpc(IntegrityMonitor.java:377)||ERROR_VALUE +2016-04-27T11:22:08{GMT+0}+00:00|||main||||INFO|||||org.openecomp.xacml.parser.ParseLog.main(ParseLog.java:86)||File Line Count: 18409 value read in: 0 +2016-04-27T11:22:48{GMT+0}+00:00|||Thread-0||||INFO|||||org.openecomp.xacml.parser.ParseLog$1.lambda$0(ParseLog.java:96)||Last line Read: 12 +2015_10_02_15_11_19_006 [http-nio-8081-exec-10] INFO corg.openecomp.research.xacml.rest.XACMLPdpServlet.doPutConfig(XACMLPdpServlet.java:409)- Success +2015-04-01 09:13:44.947 INFO 17482 --- [nio-8480-exec-7] c.a.l.ecomp.policy.std.StdPolicyConfig : config Retrieved +08-Apr-2015 10:31:26.503 WARNING [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [PyPDPServer] appears to have started a thread named [Grizzly(1) SelectorRunner] but has failed to stop it. This is very likely to create a memory leak. service Catalina08-Apr-2015 10:31:26.503 WARNING [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [PyPDPServer] appears to have started a thread named [Grizzly(1) SelectorRunner] but has failed to stop it. This is very likely to create a memory leak. +06-Mar-2015 11:50:06.243 SEVERE [main] org.apache.coyote.AbstractProtocol.init Failed to initialize end point associated with ProtocolHandler ["ajp-nio-8009"] java.net.BindException: Address already in use +2015_09_30_10_39_31_675 [http-nio-8081-exec-1] ERROR org.openecomp.research.xacml.rest.XACMLPdpServlet.doPost(XACMLPdpServlet.java:644)- PE100 - Permissions Error: PEP not Authorized for making this Request!! +2015_03_17_15_01_08_348 [qtp1688376486-32] WARN org.openecomp.research.xacml.admin.components.PolicyManagement$1.accept(PolicyManagement.java:184)- Filtering out: C:\git\D2PE-take2\policy-engine-prototype\XACML-PAP-ADMIN\workspace\admin\repository\com\.svnignore \ No newline at end of file diff --git a/LogParser/LineTest2.txt b/LogParser/LineTest2.txt new file mode 100644 index 000000000..2243960df --- /dev/null +++ b/LogParser/LineTest2.txt @@ -0,0 +1,7 @@ +2016-04-26T00:00:00{GMT+0}+00:00|||Thread-5||||ERROR|||localhost.com||org.openecomp.ecomp.policy.im.IntegrityMonitor.writeFpc(IntegrityMonitor.java:377)||ERROR_VALUE +2015_10_02_15_11_19_006 [http-nio-8081-exec-10] INFO org.openecomp.research.xacml.rest.XACMLPdpServlet.doPutConfig(XACMLPdpServlet.java:409)- Success +2015-04-01 09:13:44.947 INFO 17482 --- [nio-8480-exec-7] c.a.l.ecomp.policy.std.StdPolicyConfig : config Retrieved +08-Apr-2015 10:31:26.503 WARNING [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [PyPDPServer] appears to have started a thread named [Grizzly(1) SelectorRunner] but has failed to stop it. This is very likely to create a memory leak. service Catalina08-Apr-2015 10:31:26.503 WARNING [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [PyPDPServer] appears to have started a thread named [Grizzly(1) SelectorRunner] but has failed to stop it. This is very likely to create a memory leak. +06-Mar-2015 11:50:06.243 SEVERE [main] org.apache.coyote.AbstractProtocol.init Failed to initialize end point associated with ProtocolHandler ["ajp-nio-8009"] java.net.BindException: Address already in use +2015_09_30_10_39_31_675 [http-nio-8081-exec-1] ERROR org.openecomp.research.xacml.rest.XACMLPdpServlet.doPost(XACMLPdpServlet.java:644)- PE100 - Permissions Error: PEP not Authorized for making this Request!! +2015_03_17_15_01_08_348 [qtp1688376486-32] WARN org.openecomp.research.xacml.admin.components.PolicyManagement$1.accept(PolicyManagement.java:184)- Filtering out: C:\git\D2PE-take2\policy-engine-prototype\XACML-PAP-ADMIN\workspace\admin\repository\com\.svnignore \ No newline at end of file diff --git a/LogParser/parserlog.properties b/LogParser/parserlog.properties new file mode 100644 index 000000000..8b0ac753f --- /dev/null +++ b/LogParser/parserlog.properties @@ -0,0 +1,38 @@ +### +# ============LICENSE_START======================================================= +# LogParser +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +#Health Check Values +RESOURCE_NAME=logparser_pap01 +javax.persistence.jdbc.driver=com.mysql.jdbc.Driver +javax.persistence.jdbc.url=jdbc:mysql://localhost:3306/xacml +javax.persistence.jdbc.user=policy_user +javax.persistence.jdbc.password=password + +#Log Parser application values +JDBC_DRIVER=com.mysql.jdbc.Driver +JDBC_URL=jdbc:mysql://localhost:3306/log +JDBC_USER=policy_user +JDBC_PASSWORD=password +SERVER=https://localhost:9091/pap/ +LOGTYPE=PAP +LOGPATH=C:\\Workspaces\\HealthCheck\\pap-rest.log +PARSERLOGPATH=parserlog.log +node_type=logparser +site_name=site_1 diff --git a/LogParser/policyLogger.properties b/LogParser/policyLogger.properties new file mode 100644 index 000000000..131267dcf --- /dev/null +++ b/LogParser/policyLogger.properties @@ -0,0 +1,44 @@ +### +# ============LICENSE_START======================================================= +# LogParser +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +################################### Set concurrentHashMap and timer info ####################### +#Timer initial delay and the delay between in milliseconds before task is to be execute. +timer.delay.time=1000 +#Timer scheduleAtFixedRate period - time in milliseconds between successive task executions. +check.interval= 30000 +#Longest time an event info can be stored in the concurrentHashMap for logging - in seconds. +event.expired.time=86400 +#Size of the concurrentHashMap which stores the event starting time, etc - when its size reaches this limit, the Timer gets executed +#to remove all expired records from this concurrentHashMap. +concurrentHashMap.limit=5000 +#Size of the concurrentHashMap - when its size drops to this point, stop the Timer +stop.check.point=2500 +################################### Set logging format ############################################# +# set EELF for EELF logging format, set LOG4J for using log4j, set SYSTEMOUT for using system.out.println +logger.type=EELF +#################################### Set level for EELF or SYSTEMOUT logging ################################## +# Set level for debug file. Set DEBUG to enable .info, .warn and .debug; set INFO for enable .info and .warn; set OFF to disable all +debugLogger.level=INFO +# Set level for metrics file. Set OFF to disable; set ON to enable +metricsLogger.level=ON +# Set level for error file. Set OFF to disable; set ON to enable +error.level=ON +# Set level for audit file. Set OFF to disable; set ON to enable +audit.level=ON diff --git a/LogParser/pom.xml b/LogParser/pom.xml new file mode 100644 index 000000000..ae67d0d1a --- /dev/null +++ b/LogParser/pom.xml @@ -0,0 +1,113 @@ + + + + + 4.0.0 + + + org.openecomp.policy.engine + PolicyEngineSuite + 1.0.0-SNAPSHOT + + org.openecomp.policy.engine + LogParser + + + + com.h2database + h2 + 1.4.193 + + + mysql + mysql-connector-java + 5.1.30 + + + org.mariadb.jdbc + mariadb-java-client + 1.2.3 + + + org.openecomp.policy.common + integrity-monitor + ${common-modules.version} + + + log4j + log4j + 1.2.17 + + + org.eclipse.persistence + javax.persistence + 2.1.0 + + + org.eclipse.persistence + eclipselink + 2.6.0 + + + junit + junit + 4.11 + test + + + org.mockito + mockito-core + 1.9.5 + + + + + + + org.apache.maven.plugins + maven-assembly-plugin + 2.2 + + + + true + lib/ + org.openecomp.xacml.parser.ParseLog + + + + jar-with-dependencies + + + + + make-assembly + package + + single + + + + + + + diff --git a/LogParser/src/META-INF/MANIFEST.MF b/LogParser/src/META-INF/MANIFEST.MF new file mode 100644 index 000000000..254272e1c --- /dev/null +++ b/LogParser/src/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Class-Path: + diff --git a/LogParser/src/main/java/org/openecomp/xacml/parser/LogEntryObject.java b/LogParser/src/main/java/org/openecomp/xacml/parser/LogEntryObject.java new file mode 100644 index 000000000..4b03d2aaa --- /dev/null +++ b/LogParser/src/main/java/org/openecomp/xacml/parser/LogEntryObject.java @@ -0,0 +1,74 @@ +/*- + * ============LICENSE_START======================================================= + * LogParser + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.xacml.parser; + +import java.util.Date; + +public class LogEntryObject { + + private String system; + private String description; + private Date date; + private String remote; + private String systemType; + private LOGTYPE logType; + + public enum LOGTYPE { + INFO, ERROR, SEVERE, WARN; + } + + public String getSystem() { + return system; + } + public void setSystem(String system) { + this.system = system; + } + public String getDescription() { + return description; + } + public void setDescription(String description) { + this.description = description; + } + public Date getDate() { + return date; + } + public void setDate(Date date) { + this.date = date; + } + public String getRemote() { + return remote; + } + public void setRemote(String remote) { + this.remote = remote; + } + public String getSystemType() { + return systemType; + } + public void setSystemType(String systemType) { + this.systemType = systemType; + } + public LOGTYPE getLogType() { + return logType; + } + public void setLogType(LOGTYPE logType) { + this.logType = logType; + } +} diff --git a/LogParser/src/main/java/org/openecomp/xacml/parser/ParseLog.java b/LogParser/src/main/java/org/openecomp/xacml/parser/ParseLog.java new file mode 100644 index 000000000..5303bacc2 --- /dev/null +++ b/LogParser/src/main/java/org/openecomp/xacml/parser/ParseLog.java @@ -0,0 +1,437 @@ +/*- + * ============LICENSE_START======================================================= + * LogParser + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.xacml.parser; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.LineNumberReader; +import java.io.RandomAccessFile; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.text.Format; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Properties; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Stream; + +import org.openecomp.policy.common.im.AdministrativeStateException; +import org.openecomp.policy.common.im.IntegrityMonitor; +import org.openecomp.policy.common.im.StandbyStatusException; + +import org.apache.log4j.Logger; +import org.openecomp.xacml.parser.LogEntryObject.LOGTYPE; + +/** + * Parse log files and store the information in a H2 database. + * + * + */ +public class ParseLog { + + private static final Logger logger = Logger.getLogger(ParseLog.class.getName()); + + private static String system; + private static int lastNumberRead = 0; + private static String type; + private static long startFileSize; + private static String systemLogFile; + private static String logFile; + + private static String JDBC_URL; + private static String JDBC_USER; + private static String JDBC_PASSWORD = ""; + private static String JDBC_DRIVER; + private static int maxLength = 255; //Max length that is allowed in the DB table + private static String resourceName; + private static long sleepTimer = 50000; + static IntegrityMonitor im; + + public static void main(String[] args) throws Exception { + + Properties logProperties = getPropertiesValue("parserlog.properties"); + Path filePath = Paths.get(logFile); + File file = new File(logFile); + File fileLog = new File(systemLogFile); + startFileSize = file.length(); + + im = IntegrityMonitor.getInstance(resourceName,logProperties ); + + logger.info("System: " + system ); + logger.info("System type: " + type ); + logger.info("Logging File: " + systemLogFile ); + logger.info("log file: " + logFile); + logger.info("JDBC_URL: " + JDBC_URL); + logger.info("JDBC_DRIVER: " + JDBC_DRIVER); + + String filesRead = PullLastLineRead(fileLog); + if (filesRead!= null){ + filesRead = filesRead.replaceAll("(\\r\\n|\\n)", "
"); + lastNumberRead= Integer.parseInt(filesRead.trim()); + }else{ + lastNumberRead = 0; + } + startFileSize = countLines(logFile); + logger.info("File Line Count: " + startFileSize + " value read in: " + lastNumberRead); + if (startFileSize < lastNumberRead ){ + logger.error("Filed Rolled: set Last number read to 0"); + lastNumberRead = 0; + } + Runnable runnable = new Runnable (){ + public void run(){ + while (true){ + + if (file.isFile()){ + try (Stream lines = Files.lines(filePath, Charset.defaultCharset()).onClose(() -> logger.info("Last line Read: " + lastNumberRead)).skip(lastNumberRead)) { + + lines.forEachOrdered(line -> process(line, type)); + + } catch (IOException e) { + logger.error("Error processing line in log file: " + e); + } + } + try { + Thread.sleep(sleepTimer); + startFileSize = countLines(logFile); + } catch (InterruptedException | IOException e) { + logger.error("Error: " + e); + } + + logger.info("File Line Count: " + startFileSize + " value read in: " + lastNumberRead); + if (startFileSize < lastNumberRead ){ + logger.info("Failed Rolled: set Last number read to 0"); + lastNumberRead = 0; + } + } + } + }; + + Thread thread = new Thread(runnable); + thread.start(); + + } + + public static int countLines(String filename) throws IOException { + LineNumberReader reader = new LineNumberReader(new FileReader(filename)); + int cnt = 0; + String lineRead = ""; + while ((lineRead = reader.readLine()) != null) {} + + cnt = reader.getLineNumber(); + reader.close(); + return cnt; + } + + public static String PullLastLineRead(File file) throws IOException { + if(!file.exists()){ + file.createNewFile(); + return null; + } + RandomAccessFile randomAccessFile = new RandomAccessFile(file, "r"); + int lines = 0; + StringBuilder builder = new StringBuilder(); + long length = file.length(); + length--; + randomAccessFile.seek(length); + for(long seek = length; seek >= 0; --seek){ + randomAccessFile.seek(seek); + char c = (char)randomAccessFile.read(); + builder.append(c); + if(c == '\n'){ + builder = builder.reverse(); + if (builder.toString().contains("Last line Read:")){ + String[] parseString = builder.toString().split("Last line Read:"); + String returnValue = parseString[1].replace("\r", ""); + return returnValue.trim(); + //return parseString[2].replace("\r", ""); + } + lines++; + builder = null; + builder = new StringBuilder(); + } + + } + return null; + } + + public static LogEntryObject pullOutLogValues(String line, String type){ + Date date; + LogEntryObject logEntry = new LogEntryObject(); + logEntry.setSystemType(type); + String description = null; + + logEntry.setSystem(system); + + //Values for PDP/PAP log file + if(line.contains("||INFO||") || line.contains("||ERROR||")){ + String[] splitString = line.split("[||]"); + String dateString = splitString[0].substring(0, 19); + logEntry.setDescription(splitString[splitString.length-1]); + + //parse out date + date = parseDate(dateString.replace("T", " "), "yyyy-MM-dd HH:mm:ss", false); + logEntry.setDate(date); + + logEntry.setRemote(parseRemoteSystem(line)); + if (line.contains("||INFO||")){ + logEntry.setLogType(LOGTYPE.INFO); + }else{ + logEntry.setLogType(LOGTYPE.ERROR); + } + }else if (line.contains("INFO") && line.contains(")-")){ + //parse out description + logEntry.setDescription(line.substring(line.indexOf(")-")+3)); + + date = parseDate(line, "yy_MM_dd_HH_mm_ss", true); + logEntry.setDate(date); + + logEntry.setRemote(parseRemoteSystem(line)); + logEntry.setLogType(LOGTYPE.INFO); + } else if (line.contains("INFO") && line.contains("--- [")){ + //parse out description + String temp = line.substring(line.indexOf("---")+1); + String[] split = temp.split(":"); + + logEntry.setDescription(split[1]); + + //parse out date + date = parseDate(line, "yyyy-MM-dd HH:mm:ss", false); + logEntry.setDate(date); + + //remote system + logEntry.setRemote(parseRemoteSystem(line)); + logEntry.setLogType(LOGTYPE.INFO); + }else if (line.contains("SEVERE") && line.contains("[main]")){ + String[] splitString = line.split(" "); + + for (int i = 5; i < splitString.length; i++){ + description = description + " " + splitString[i]; + } + + logEntry.setDescription(description); + //parse out date + date = parseDate(line, "dd-MMM-yyyy HH:mm:ss", false); + logEntry.setDate(date); + logEntry.setLogType(LOGTYPE.SEVERE); + } else if (line.contains("WARN") && line.contains(")-")){ + //parse out description + + logEntry.setDescription(line.substring(line.indexOf(")-")+3)); + + //parse out date + date = parseDate(line, "yy_MM_dd_HH_mm_ss", true); + logEntry.setDate(date); + + //remote system + logEntry.setRemote(parseRemoteSystem(line)); + logEntry.setLogType(LOGTYPE.WARN); + }else if (line.contains("WARNING") && type =="PyPDP"){ + String[] splitString = line.split(" "); + for (int i = 5; i < splitString.length; i++){ + description = description + " " + splitString[i]; + } + + //parse out date + date = parseDate(line, "dd-MMM-yyyy HH:mm:ss", false); + logEntry.setDate(date); + logEntry.setLogType(LOGTYPE.WARN); + }else if (line.contains("ERROR") && line.contains(")-")){ + //parse out description + description = line.substring(line.indexOf(")-")+3); + + //parse out date + date = parseDate(line, "yy_MM_dd_HH_mm_ss", true); + logEntry.setDate(date); + //remote system + logEntry.setRemote(parseRemoteSystem(line)); + logEntry.setLogType(LOGTYPE.ERROR); + }else { + return null; + } + + + return logEntry; + } + + private static void DBClose(Connection conn) { + try { + conn.close(); + } catch (SQLException e) { + logger.error("Error closing DB Connection: " + e); + + } + } + + public static void process(String line, String type) { + LogEntryObject returnLogValue = null; + if (im!=null){ + try { + im.startTransaction(); + } catch (AdministrativeStateException e) { + logger.error("Error received" + e); + + } catch (StandbyStatusException e) { + logger.error("Error received" + e); + } + } + returnLogValue = pullOutLogValues(line, type); + lastNumberRead++; + if (returnLogValue!=null){ + writeDB(returnLogValue); + } + if (im!=null){ + im.endTransaction(); + } + } + + private static void writeDB(LogEntryObject returnLogValue) { + Connection conn = DBConnection(JDBC_DRIVER, JDBC_URL, JDBC_USER,JDBC_PASSWORD); + DBAccesss(conn, returnLogValue.getSystem(), returnLogValue.getDescription(), + returnLogValue.getDate(), returnLogValue.getRemote(), + returnLogValue.getSystemType(), returnLogValue.getLogType().toString()); + DBClose(conn); + } + + private static Connection DBConnection(String driver, String jdbc, String user, String pass){ + + try { + Class.forName(driver); + Connection conn = DriverManager.getConnection(jdbc, user, pass); + return conn; + } catch ( Exception e) { + logger.error("Error connecting to DB: " + e); + } + return null; + } + private static void DBAccesss(Connection conn, String system, String description, Date date, String remote, String type, String logType) { + + String sdate = null; + + if (date!=null){ + Format formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + sdate = formatter.format(date); + } + + //ensure the length of description is less than the maximumm db char length + if (description.length() > maxLength) { + description = description.substring(0, maxLength); + } + + try { + PreparedStatement prep = conn.prepareStatement("insert into SYSTEMLOGDB values (NULL, ?, ?, ?, ?, ?, ?);"); + prep.setString(1, system); + prep.setString(2, description); + prep.setString(3, remote); + prep.setString(4, type); + prep.setString(5, sdate); + prep.setString(6, logType); + + prep.executeUpdate(); + prep.close(); + + } catch (SQLException e1) { + logger.error("Error trying to excute SQL Statment: " + e1); + } + } + + public static Date parseDate(String dateline, String pattern, boolean singleSplit) { + + Date returnDate; + String[] splitString = dateline.split(" "); + SimpleDateFormat formatter = new SimpleDateFormat(pattern); + if (singleSplit){ + try { + returnDate = formatter.parse(splitString[0]); + } catch (ParseException e) { + logger.error("Unable to parse date for line: " + dateline); + returnDate = null; + } + }else{ + String tmpString = splitString[0] + " " + splitString[1]; + try { + returnDate = formatter.parse(tmpString); + } catch (ParseException e) { + logger.error("Unable to parse date for line: " + dateline); + returnDate = null; + } + } + + return returnDate; + } + + + public static String parseRemoteSystem(String line) { + + if (line.contains("http") && !(line.contains("www.w3.org"))){ + + Pattern pattern = Pattern.compile("://(.+?)/"); + Matcher remote = pattern.matcher(line); + if (remote.find()) + { + return remote.group(1); + } + } + return null; + } + + public static Properties getPropertiesValue(String fileName) { + Properties config = new Properties(); + Path file = Paths.get(fileName); + if (Files.notExists(file)) { + logger.info("File doesn't exist in the specified Path " + file.toString()); + }else{ + if (file.toString().endsWith(".properties")) { + InputStream in; + try { + in = new FileInputStream(file.toFile()); + config.load(in); + + resourceName = config.getProperty("RESOURCE_NAME"); + system = config.getProperty("SERVER"); + type = config.getProperty("LOGTYPE"); + systemLogFile = config.getProperty("PARSERLOGPATH"); + logFile = config.getProperty("LOGPATH"); + JDBC_URL = config.getProperty("JDBC_URL").replace("'", ""); + JDBC_USER = config.getProperty("JDBC_USER"); + JDBC_DRIVER = config.getProperty("JDBC_DRIVER"); + JDBC_PASSWORD = config.getProperty("JDBC_PASSWORD"); + return config; + + } catch (IOException e) { + logger.info("Error porcessing Cofnig file will be unable to create Health Check"); + } + + } + } + return null; + } +} diff --git a/LogParser/src/main/scripts/parserlog.sh b/LogParser/src/main/scripts/parserlog.sh new file mode 100644 index 000000000..79ea8a3b3 --- /dev/null +++ b/LogParser/src/main/scripts/parserlog.sh @@ -0,0 +1,130 @@ +### +# ============LICENSE_START======================================================= +# LogParser +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +#!/bin/sh +# +# init script for a Java application +# + +#Arguments for application +SERVER=http://localhost:8070/pap/ +LOGTYPE=PAP +LOGPATH="/var/lib/servers/pap/logs/catalina.out" +PARSERLOGPATH="$POLICY_HOME/logs/parserlog.log" +JDBC_URL="jdbc:h2:tcp://localhost:9092/log" +JDBC_USER="sa" +JDBC_DRIVER="org.h2.Driver" +JDBC_PASSWORD="" +SERVICE="LogParser.jar" + +# Check the application status +# +# This function checks if the application is running +check_status() { + + # Running pgrep with some arguments to check if the PID exists + if pgrep -f "$SERVICE $SERVER $LOGTYPE" ; then + RESULT=$(pgrep -f ${SERVICE}) + return $RESULT + fi + return 0 + # In any another case, return 0 + +} + +# Starts the application +start() { + + # At first checks if the application is already started calling the check_status + # function + check_status + + # $? is a special variable that hold the "exit status of the most recently executed + # foreground pipeline" + pid=$? + + if [ $pid -ne 0 ] ; then + echo "The application is already started" + exit 1 + fi + + # If the application isn't running, starts it + echo -n "Starting application: " + + # Redirects default and error output to a log file + java -jar LogParser.jar $SERVER $LOGTYPE $LOGPATH $PARSERLOGPATH $JDBC_URL $JDBC_USER $JDBC_DRIVER $JDBC_PASSWORD>> $POLICY_HOME/logs/parserlog.log 2>&1 & + echo "OK" +} + +# Stops the application +stop() { + + # Like as the start function, checks the application status + check_status + + pid=$? + + if [ $pid -eq 0 ] ; then + echo "Application is already stopped" + exit 1 + fi + + # Kills the application process + echo -n "Stopping application: " + kill -9 $pid & + echo "OK" +} + +# Show the application status +status() { + + # The check_status function, again... + check_status + + # If the PID was returned means the application is running + if [ $? -ne 0 ] ; then + echo "Application is started" + else + echo "Application is stopped" + fi + +} + +# Main logic, a simple case to call functions +case "$1" in + start) + start + ;; + stop) + stop + ;; + status) + status + ;; + restart|reload) + stop + start + ;; + *) + echo "Usage: $0 {start|stop|restart|reload|status}" + exit 1 +esac + +exit 0 diff --git a/LogParser/src/test/java/org/openecomp/xacml/parser/ParseLogTest.java b/LogParser/src/test/java/org/openecomp/xacml/parser/ParseLogTest.java new file mode 100644 index 000000000..08df57a9b --- /dev/null +++ b/LogParser/src/test/java/org/openecomp/xacml/parser/ParseLogTest.java @@ -0,0 +1,382 @@ +/*- + * ============LICENSE_START======================================================= + * LogParser + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.xacml.parser; + +import static org.junit.Assert.*; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.text.SimpleDateFormat; +import java.util.Collections; +import java.util.Date; +import java.util.Properties; + +import org.openecomp.policy.common.im.AdministrativeStateException; +import org.openecomp.policy.common.im.IntegrityMonitor; +import org.openecomp.policy.common.im.StandbyStatusException; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.openecomp.xacml.parser.LogEntryObject; +import org.openecomp.xacml.parser.ParseLog; +import org.openecomp.xacml.parser.LogEntryObject.LOGTYPE; + + +public class ParseLogTest { + + private ParseLog logParser = new ParseLog(); + private Properties config = new Properties(); + private String configFile = "test_config.properties"; + private static Properties myProp; + private static Properties systemProps; + private static String resourceName; + private IntegrityMonitor im; + + + @Before + public void setUp() throws Exception { + System.setProperty("com.sun.management.jmxremote.port", "9998"); + im = Mockito.mock(IntegrityMonitor.class); + + // Need PowerMockito for mocking static method getInstance(...) + // PowerMockito.mockStatic(IntegrityMonitor.class); + + try { + Mockito.doNothing().when(im).startTransaction(); + } catch (StandbyStatusException | AdministrativeStateException e) { + fail(); + } + Mockito.doNothing().when(im).endTransaction(); + + } + + @After + public void tearDown() { + File file = new File("nonExistFile.txt"); + file.delete(); +// systemProps.remove("com.sun.management.jmxremote.port"); + } + + @Test + public void testMain() { + try { + + logParser.main(null); + } catch (Exception e) { + //fail(); + } + } + + @Test + public void testCountLines() throws IOException { + String fileName = "LineTest.txt"; + int returnValue = logParser.countLines(fileName); + + assertEquals(9, returnValue); + } + + @Test + public void testParseRemoteSystem() { + String line = "||org.openecomp.policy.pap.xacml.rest.XACMLPapServlet$Heartbeat.run(XACMLPapServlet.java:2801)||Heartbeat 'https://localhost:8081/pdp/' status='UP_TO_DATE'"; + String returnValue = ParseLog.parseRemoteSystem(line); + assertEquals("localhost:8081", returnValue); + } + + @Test + public void testGetPropertiesValue() { + config = new Properties(); + config.put("RESOURCE_NAME", "logparser_pap01"); + config.put("JDBC_DRIVER" ,"com.mysql.jdbc.Driver"); + config.put("JDBC_URL", "jdbc:mysql://localhost:3306/"); + config.put("JDBC_USER", "root"); + config.put("JDBC_PASSWORD", "password"); + config.put("JMX_URL", "service:jmx:rmi:///jndi/rmi://localhost:9998/jmxrmi"); + config.put("SERVER", "password"); + config.put("JDBC_PASSWORD", "https://localhost:9091/pap/"); + config.put("LOGTYPE", "PAP"); + config.put("LOGPATH", "C:\\Workspaces\\HealthCheck\\pap-rest.log"); + config.put("PARSERLOGPATH", "IntegrityMonitor.log"); + + Properties returnConfig = logParser.getPropertiesValue(configFile); + + + assertEquals(config.get("RESOURCE_NAME"), returnConfig.get("RESOURCE_NAME")); + } + + @Test + public void testGetPropertiesFail() { + Properties returnValue = ParseLog.getPropertiesValue("nonExistFile"); + + assertEquals(null, returnValue); + } + + @Test + public void testParseDate(){ + String line = "2016-02-23 08:07:30"; + Date returnValue = ParseLog.parseDate(line, "yyyy-MM-dd HH:mm:ss", false); + + assertEquals("Tue Feb 23 08:07:30 CST 2016", returnValue.toString()); + } + + @Test + public void testParseDateFail(){ + String line = "2016-02-23 08:07:30"; + Date returnValue = ParseLog.parseDate(line, "yyyy-MM-dd HH:mm:ss", true); + + assertEquals(null, returnValue); + } + + @Test + public void testPullLastLineRead(){ + + File file = new File("LineTest.txt"); + String returnValue = null; + try { + returnValue = ParseLog.PullLastLineRead(file).trim(); + } catch (IOException e) { + fail(); + } + assertEquals("12", returnValue); + + } + + @Test + public void testPullLastLineReadNoFile(){ + + File file = new File("nonExistFile.txt"); + try { + assertEquals(null, ParseLog.PullLastLineRead(file)); + } catch (IOException e) { + fail(); + } + } + @Test + public void testPullLastLineReadFail(){ + + File file = new File("LineTest2.txt"); + try { + assertEquals(null, ParseLog.PullLastLineRead(file)); + } catch (IOException e) { + fail(); + } + } + + @Test + public void testPullOutLogValues(){ + //ERROR_VALUE + // Open the file + FileInputStream fstream; + try { + fstream = new FileInputStream("LineTest.txt"); + BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); + String strLine = br.readLine(); + LogEntryObject retrunObject = ParseLog.pullOutLogValues(strLine, "ERROR"); + assertEquals("ERROR_VALUE", retrunObject.getDescription()); + br.close(); + } catch (IOException e) { + fail(); + } +// assert(true); + } + @Test + public void testPullOutLogValuesSecond(){ + //ERROR_VALUE + // Open the file + FileInputStream fstream; + try { + fstream = new FileInputStream("LineTest.txt"); + BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); + String strLine = br.readLine(); + strLine = br.readLine(); + LogEntryObject retrunObject = ParseLog.pullOutLogValues(strLine, "INFO"); + assertEquals(LOGTYPE.INFO, retrunObject.getLogType()); + br.close(); + } catch (IOException e) { + fail(); + } + } + + @Test + public void testPullOutLogValuesThird(){ + //ERROR_VALUE + // Open the file + FileInputStream fstream; + try { + int number = 3; + fstream = new FileInputStream("LineTest.txt"); + BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); + String strLine = br.readLine(); + for (int i =0; i < number; i++){ + strLine = br.readLine(); + } + LogEntryObject retrunObject = ParseLog.pullOutLogValues(strLine, "PAP"); + assertEquals(LOGTYPE.INFO, retrunObject.getLogType()); + br.close(); + } catch (IOException e) { + fail(); + } + } + + @Test + public void testPullOutLogValuesFourth(){ + // Open the file + FileInputStream fstream; + try { + int number = 4; + fstream = new FileInputStream("LineTest.txt"); + BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); + String strLine = br.readLine(); + for (int i =0; i < number; i++){ + strLine = br.readLine(); + } + LogEntryObject retrunObject = ParseLog.pullOutLogValues(strLine, "PAP"); + assertEquals(LOGTYPE.INFO, retrunObject.getLogType()); + br.close(); + } catch (IOException e) { + fail(); + } + } + + @Test + public void testPullOutLogValuesFith(){ + // Open the file + FileInputStream fstream; + try { + int number = 5; + fstream = new FileInputStream("LineTest.txt"); + BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); + String strLine = br.readLine(); + for (int i =0; i < number; i++){ + strLine = br.readLine(); + } + LogEntryObject retrunObject = ParseLog.pullOutLogValues(strLine, "PyPDP"); + assertEquals(LOGTYPE.WARN, retrunObject.getLogType()); + br.close(); + } catch (IOException e) { + fail(); + } + } + + @Test + public void testPullOutLogValuesSixth(){ + // Open the file + FileInputStream fstream; + try { + int number = 6; + fstream = new FileInputStream("LineTest.txt"); + BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); + String strLine = br.readLine(); + for (int i =0; i < number; i++){ + strLine = br.readLine(); + } + LogEntryObject retrunObject = ParseLog.pullOutLogValues(strLine, "PyPDP"); + assertEquals(LOGTYPE.SEVERE, retrunObject.getLogType()); + br.close(); + } catch (IOException e) { + fail(); + } + } + + @Test + public void testPullOutLogValuesSeven(){ + // Open the file + FileInputStream fstream; + try { + int number = 7; + fstream = new FileInputStream("LineTest.txt"); + BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); + String strLine = br.readLine(); + for (int i =0; i < number; i++){ + strLine = br.readLine(); + } + LogEntryObject retrunObject = ParseLog.pullOutLogValues(strLine, "Console"); + assertEquals(LOGTYPE.ERROR, retrunObject.getLogType()); + br.close(); + } catch (IOException e) { + fail(); + } + } + + @Test + public void testPullOutLogValuesEight(){ + // Open the file + FileInputStream fstream; + try { + int number = 8; + fstream = new FileInputStream("LineTest.txt"); + BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); + String strLine = br.readLine(); + for (int i =0; i < number; i++){ + strLine = br.readLine(); + } + LogEntryObject retrunObject = ParseLog.pullOutLogValues(strLine, "pap"); + assertEquals(LOGTYPE.WARN, retrunObject.getLogType()); + br.close(); + } catch (IOException e) { + fail(); + } + } + + @Test + public void testPullOutLogValuesNull(){ + // Open the file + FileInputStream fstream; + LogEntryObject retrunObject = ParseLog.pullOutLogValues("", "Console"); + assertEquals(null, retrunObject); + } + + @Test + public void testLogEntryObject(){ + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); + Date date = new Date(); + + // Open the file + LogEntryObject logObject = new LogEntryObject(); + logObject.setSystem("vm02"); + logObject.setSystemType("pap"); + logObject.setDate(date); + logObject.setRemote("remote"); + + assertEquals("vm02", logObject.getSystem()); + assertEquals("pap", logObject.getSystemType()); + assertEquals(date, logObject.getDate()); + assertEquals("remote", logObject.getRemote()); + } + + @Test + public void testProcess(){ + String line = "2015-04-01 09:13:44.947 DEBUG 17482 --- [nio-8480-exec-7] c.a.l.ecomp.policy.std.StdPolicyConfig : config Retrieved "; + + im = Mockito.mock(IntegrityMonitor.class); + try { + Mockito.doNothing().when(im).startTransaction(); + } catch (StandbyStatusException | AdministrativeStateException e) { + fail(); + } + Mockito.doNothing().when(im).endTransaction(); + ParseLog.process(line, "pap"); + } +} diff --git a/LogParser/test_config.properties b/LogParser/test_config.properties new file mode 100644 index 000000000..5a6a460ba --- /dev/null +++ b/LogParser/test_config.properties @@ -0,0 +1,31 @@ +### +# ============LICENSE_START======================================================= +# LogParser +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + + +RESOURCE_NAME=logparser_pap01 +JDBC_DRIVER=com.mysql.jdbc.Driver +JDBC_URL=jdbc:mysql://localhost:3306/ +JDBC_USER=root +JDBC_PASSWORD=password +jmx_url=service:jmx:rmi:///jndi/rmi://localhost:9996/jmxrmi +SERVER=https://localhost:9091/pap/ +LOGTYPE=PAP +LOGPATH=C:\\Workspaces\\HealthCheck\\pap-rest.log +PARSERLOGPATH=IntegrityMonitor.log diff --git a/PolicyEngineAPI/Config/Config.properties b/PolicyEngineAPI/Config/Config.properties new file mode 100644 index 000000000..34a9a82ce --- /dev/null +++ b/PolicyEngineAPI/Config/Config.properties @@ -0,0 +1,26 @@ +### +# ============LICENSE_START======================================================= +# PolicyEngineAPI +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +# Policies to load +# +PDP_URL = http://localhost:8081/pdp/ , testpdp, alpha123 +PAP_URL=http://localhost:8070/pap/, testpap, alpha123 +NOTIFICATION_TYPE = ueb +NOTIFICATION_UEB_SERVERS=localhost.com,localhost1.com diff --git a/PolicyEngineAPI/policyLogger.properties b/PolicyEngineAPI/policyLogger.properties new file mode 100644 index 000000000..7c4d9e2f0 --- /dev/null +++ b/PolicyEngineAPI/policyLogger.properties @@ -0,0 +1,44 @@ +### +# ============LICENSE_START======================================================= +# PolicyEngineAPI +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +################################### Set concurrentHashMap and timer info ####################### +#Timer initial delay and the delay between in milliseconds before task is to be execute. +timer.delay.time=1000 +#Timer scheduleAtFixedRate period - time in milliseconds between successive task executions. +check.interval= 30000 +#Longest time an event info can be stored in the concurrentHashMap for logging - in seconds. +event.expired.time=86400 +#Size of the concurrentHashMap which stores the event starting time, etc - when its size reaches this limit, the Timer gets executed +#to remove all expired records from this concurrentHashMap. +concurrentHashMap.limit=5000 +#Size of the concurrentHashMap - when its size drops to this point, stop the Timer +stop.check.point=2500 +################################### Set logging format ############################################# +# set EELF for EELF logging format, set LOG4J for using log4j, set SYSTEMOUT for using system.out.println +logger.type=EELF +#################################### Set level for EELF or SYSTEMOUT logging ################################## +# Set level for debug file. Set DEBUG to enable .info, .warn and .debug; set INFO for enable .info and .warn; set OFF to disable all +debugLogger.level=INFO +# Set level for metrics file. Set OFF to disable; set ON to enable +metricsLogger.level=ON +# Set level for error file. Set OFF to disable; set ON to enable +error.level=ON +# Set level for audit file. Set OFF to disable; set ON to enable +audit.level=ON diff --git a/PolicyEngineAPI/pom.xml b/PolicyEngineAPI/pom.xml new file mode 100644 index 000000000..7cabd8210 --- /dev/null +++ b/PolicyEngineAPI/pom.xml @@ -0,0 +1,165 @@ + + + + + 4.0.0 + + + org.openecomp.policy.engine + PolicyEngineSuite + 1.0.0-SNAPSHOT + + + org.openecomp.policy.engine + PolicyEngineAPI + + + xml-apis + xml-apis + 1.4.01 + + + com.fasterxml.jackson.core + jackson-databind + 2.8.5 + + + org.glassfish + javax.json + 1.0.4 + + + org.apache.httpcomponents + httpclient + 4.3.1 + + + commons-io + commons-io + 2.4 + + + com.google.guava + guava + 14.0.1 + + + junit + junit + 4.11 + + + javax.websocket + javax.websocket-api + 1.1 + + + org.glassfish.tyrus + tyrus-client + 1.13 + + + org.glassfish.tyrus + tyrus-container-grizzly-client + 1.13 + + + log4j + log4j + 1.2.17 + + + com.att.nsa + cambriaClient + 0.0.1 + + + org.slf4j + slf4j-log4j12 + + + + + org.openecomp.policy.engine + ECOMP-XACML + ${project.version} + + + org.eclipse.persistence + javax.persistence + 2.1.0 + + + org.eclipse.persistence + eclipselink + 2.5.2 + + + mysql + mysql-connector-java + 5.1.30 + + + org.mariadb.jdbc + mariadb-java-client + 1.2.3 + + + org.openecomp.policy.engine + PolicyEngineUtils + ${project.version} + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.2 + + 1.8 + 1.8 + + + + + org.apache.maven.plugins + maven-assembly-plugin + 2.2 + + + jar-with-dependencies + + + + + make-assembly + package + + single + + + + + + + diff --git a/PolicyEngineAPI/src/log4j.properties b/PolicyEngineAPI/src/log4j.properties new file mode 100644 index 000000000..9e5bf710a --- /dev/null +++ b/PolicyEngineAPI/src/log4j.properties @@ -0,0 +1,48 @@ +### +# ============LICENSE_START======================================================= +# PolicyEngineAPI +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +# +# Use this properties for debugging and development. +# +# +# Set root logger level to DEBUG and its only appender to A1. +log4j.rootLogger=INFO, FILE + +# A1 is set to be a DailyRollingFileAppender. +log4j.appender.FILE=org.apache.log4j.DailyRollingFileAppender + +# Set the name of the file +log4j.appender.FILE.File=src.out + +# Set the immediate flush to true (default) +log4j.appender.FILE.ImmediateFlush=true + +# Set the threshold to debug mode +log4j.appender.FILE.Threshold=debug + +# Set the append to false, should not overwrite +log4j.appender.FILE.Append=true + +# Set the DatePattern +log4j.appender.FILE.DatePattern='.' yyyy-MM-dd-a + +# A1 uses PatternLayout. +log4j.appender.FILE.layout=org.apache.log4j.PatternLayout +log4j.appender.FILE.layout.ConversionPattern=%d{yyyy_MM_dd_HH_mm_ss_SSS} [%t] %-5p %l- %m%n diff --git a/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/AttributeType.java b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/AttributeType.java new file mode 100644 index 000000000..2a887919b --- /dev/null +++ b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/AttributeType.java @@ -0,0 +1,66 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.api; + +/** + * Enumeration of the Attribute Types that is used as a part of + * {@link org.openecomp.policy.api.PolicyParameters}. + * + * @version 0.1 + */ +public enum AttributeType { + /** + * Indicates Attributes required to Match the Policy. + */ + MATCHING("matching"), + /** + * Indicates Attributes required to create DRL based Rules. + */ + RULE("rule"), + /** + * Indicates Attributes required to create MicroService policy. + */ + MICROSERVICE("microService"), + /** + * Indicates Attributes required to create settings for Decision Policy. + */ + SETTINGS("settings"), + /** + * Indicates Attributes required to create dictionary fields for creating Dictionary Items + */ + DICTIONARY("dictionary") + ; + + + private String name; + + private AttributeType(String typeName){ + this.name = typeName; + } + + /** + * Returns the String format of Type for this AttributeType + * @return the String of the Type for this AttributeType + */ + public String toString() { + return this.name; + } +} diff --git a/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/ConfigRequestParameters.java b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/ConfigRequestParameters.java new file mode 100644 index 000000000..1830679e0 --- /dev/null +++ b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/ConfigRequestParameters.java @@ -0,0 +1,148 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.api; + +import java.util.Map; +import java.util.UUID; + +/** + * ConfigRequestParameters defines the Config Policy Request Parameters + * which retrieve(s) the policy from PDP if the request parameters match with any Config Policy. + * + * @version 0.1 + */ +public class ConfigRequestParameters { + private String policyName; + private String eCOMPComponentName; + private String configName; + private Map configAttributes; + private UUID requestID; + private Boolean unique = false; + + /** + * Sets the PolicyName of the Config policy which needs to be retrieved. + * + * @param policyName the String format of the PolicyFile Name whose configuration is required. + */ + public void setPolicyName(String policyName){ + this.policyName = policyName; + } + + /** + * Sets the ECOMP Component Name of the Config policy which needs to be retrieved. + * + * @param eCOMPComponentName the String format of the eCOMPComponentName whose configuration is required. + */ + public void setEcompName(String eCOMPComponentName){ + this.eCOMPComponentName = eCOMPComponentName; + } + + /** + * Sets the Config Name of the Config policy which needs to be retrieved. + * + * @param configName the String format of the configurationName whose configuration is required. + */ + public void setConfigName(String configName){ + this.configName = configName; + } + + /** + * Sets the ConfigAttributes of the Config policy which needs to be retrieved. + * + * @param configAttributes the Map of String,String format of the configuration attributes which are required. + */ + public void setConfigAttributes(Map configAttributes){ + this.configAttributes = configAttributes; + } + + /** + * Sets the Request ID of the ECOMP request. + * + * @param requestID unique UUID requestID which will be passed throughout the ECOMP components to correlate logging messages. + */ + public void setRequestID(UUID requestID){ + this.requestID = requestID; + } + + /** + * Gets the policyName of the Request Parameters. + * + * @return String format of the policyName. + */ + public String getPolicyName(){ + return policyName; + } + + /** + * Gets the ECOMP Component Name of the Request Parameters. + * + * @return String format of the ECOMP Component Name. + */ + public String getEcompName(){ + return eCOMPComponentName; + } + + /** + * Gets the Config name of the Request Parameters. + * + * @return String format of the Config Name. + */ + public String getConfigName(){ + return configName; + } + + /** + * Gets the Config Attributes of the Request Parameters. + * + * @return Map of String,String format of the config Attributes. + */ + public Map getConfigAttributes(){ + return configAttributes; + } + + /** + * Gets the Request ID of the Request Paramters. + * + * @return UUID format of requestID. + */ + public UUID getRequestID(){ + return requestID; + } + + /** + * Makes the results Unique, priority based. If set to True. Default Value is set to False. + * + * @param unique flag which is either true or false. + */ + public void makeUnique(Boolean unique){ + this.unique = unique; + } + + /** + * Gets the Unique flag value from the Config Request Parameters. + * + * @return unique flag which is either true or false. + */ + public Boolean getUnique(){ + return this.unique; + } + +} diff --git a/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/DecisionRequestParameters.java b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/DecisionRequestParameters.java new file mode 100644 index 000000000..dc485f7b3 --- /dev/null +++ b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/DecisionRequestParameters.java @@ -0,0 +1,104 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.api; + +import java.util.Map; +import java.util.UUID; + +/** + * DecisionRequestParameters defines the Decision Policy Request Parameters + * which retrieve(s) the response from PDP if the request parameters match with any Decision Policy. + * + * @version 0.1 + */ +public class DecisionRequestParameters { + private String eCOMPComponentName; + private Map decisionAttributes; + private UUID requestID; + + /** + * Constructor with no Parameters + */ + public DecisionRequestParameters(){ + } + + /** + * Constructor with Parameters + * + * @param eCOMPComponentName the String format of the eCOMPComponentName whose Decision is required. + * @param decisionAttributes the Map of String,String format of the decisionAttributes that contain the ID and values. + * @param requestID unique request ID which will be passed throughout the ECOMP components to correlate logging messages. + */ + public DecisionRequestParameters(String eCOMPComponentName, Map decisionAttributes, UUID requestID){ + this.eCOMPComponentName = eCOMPComponentName; + this.decisionAttributes = decisionAttributes; + this.requestID = requestID; + } + + /** + * Gets the ECOMPComponentName of the Decision Request Parameters. + * + * @return ECOMPComponentName the String format of the eCOMPComponentName of the Decision Request Parameters. + */ + public String getECOMPComponentName() { + return eCOMPComponentName; + } + /** + * Sets the ECOMPComponentName of the Decision Request parameters. + * + * @param eCOMPComponentName the String format of the eCOMPComponentName whose Decision is required. + */ + public void setECOMPComponentName(String eCOMPComponentName) { + this.eCOMPComponentName = eCOMPComponentName; + } + /** + * Gets the Decision Attributes from Decision Request Parameters. + * + * @return decisionAttributes the Map of String,String format of the decisionAttributes that contain the ID and values. + */ + public Map getDecisionAttributes() { + return decisionAttributes; + } + /** + * Sets the Decision Attributes which contain ID and values for obtaining Decision from PDP. + * + * @param decisionAttributes the Map of String,String format of the decisionAttributes that must contain the ID and values. + */ + public void setDecisionAttributes(Map decisionAttributes) { + this.decisionAttributes = decisionAttributes; + } + /** + * Gets the request ID of Decision Request Parameters. + * + * @return the requestID unique request ID which will be passed throughout the ECOMP components to correlate logging messages. + */ + public UUID getRequestID() { + return requestID; + } + /** + * Sets the ReqestID of Decision Request Parameters which will be passed around ECOMP requests. + * + * @param requestID unique request ID which will be passed throughout the ECOMP components to correlate logging messages. + */ + public void setRequestID(UUID requestID) { + this.requestID = requestID; + } +} diff --git a/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/DecisionResponse.java b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/DecisionResponse.java new file mode 100644 index 000000000..caa9fda74 --- /dev/null +++ b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/DecisionResponse.java @@ -0,0 +1,43 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.api; + +/** + * Defines the Object that represents the Policy Decision Response elements. + * DecisionResponse communicates the decision and details + * + * @version 0.1 + */ +public interface DecisionResponse { + /** + * Gets the Decision of the Policy, Either a Permit or Deny. + * + * @return {@link org.openecomp.policy.api.PolicyDecision} Enumeration. + */ + public PolicyDecision getDecision(); + + /** + * Gets the details of the result. Would be required in case of Deny. + * + * @return String format of the details of Deny cause. + */ + public String getDetails(); +} diff --git a/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/DeletePolicyCondition.java b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/DeletePolicyCondition.java new file mode 100644 index 000000000..3440c99aa --- /dev/null +++ b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/DeletePolicyCondition.java @@ -0,0 +1,53 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.api; + +/** + * Enumeration of the Policy Delete Condition that is used as a part of + * {@link org.openecomp.policy.api.DeletePolicyParameters}. + * + * @version 0.1 + */ +public enum DeletePolicyCondition { + + /** + * Indicates a condition to only delete the current version of the policy. + */ + ONE("Current Version"), + + /** + * Indicates a condition to delete all versions of the policy. + */ + ALL("All Versions"); + private String name; + + private DeletePolicyCondition(String name){ + this.name = name; + } + + /** + * Returns the String format of delete condition for this Policy + * @return the String of the delete condition for this Policy + */ + public String toString(){ + return this.name; + } +} diff --git a/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/DeletePolicyParameters.java b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/DeletePolicyParameters.java new file mode 100644 index 000000000..3999c5e22 --- /dev/null +++ b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/DeletePolicyParameters.java @@ -0,0 +1,101 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.api; + +import java.util.UUID; + +/** + * PushPolicyParameters defines the Policy Parameters + * which are required to Push a Policy to PDPGroup. + * + * @version 0.1 + */ +public class DeletePolicyParameters { + + private String policyName; + private String policyComponent; + private DeletePolicyCondition deleteCondition; + private String pdpGroup; + private UUID requestID; + + + /** + * @return the policyName + */ + public String getPolicyName() { + return policyName; + } + /** + * @param policyName the policyName to set + */ + public void setPolicyName(String policyName) { + this.policyName = policyName; + } + /** + * @return the policyComponent + */ + public String getPolicyComponent() { + return policyComponent; + } + /** + * @param policyComponent the policyComponent to set + */ + public void setPolicyComponent(String policyComponent) { + this.policyComponent = policyComponent; + } + /** + * @return the deleteCondition + */ + public DeletePolicyCondition getDeleteCondition() { + return deleteCondition; + } + /** + * @param deleteCondition the deleteCondition to set + */ + public void setDeleteCondition(DeletePolicyCondition deleteCondition) { + this.deleteCondition = deleteCondition; + } + /** + * @return the requestID + */ + public UUID getRequestID() { + return requestID; + } + /** + * @param requestID the requestID to set + */ + public void setRequestID(UUID requestID) { + this.requestID = requestID; + } + /** + * @return the pdpGroup + */ + public String getPdpGroup() { + return pdpGroup; + } + /** + * @param pdpGroup the pdpGroup to set + */ + public void setPdpGroup(String pdpGroup) { + this.pdpGroup = pdpGroup; + } + +} diff --git a/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/DictionaryParameters.java b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/DictionaryParameters.java new file mode 100644 index 000000000..1506effd7 --- /dev/null +++ b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/DictionaryParameters.java @@ -0,0 +1,83 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.api; + +import java.util.Map; +import java.util.UUID; + +public class DictionaryParameters { + + private DictionaryType dictionaryType; + private String dictionary; + private Map> dictionaryFields; + private UUID requestID; + + + /** + * @return the dictionaryType + */ + public DictionaryType getDictionaryType() { + return dictionaryType; + } + /** + * @param dictionaryType the dictionaryType to set + */ + public void setDictionaryType(DictionaryType dictionaryType) { + this.dictionaryType = dictionaryType; + } + /** + * @return the dictionary + */ + public String getDictionary() { + return dictionary; + } + /** + * @param dictionary the dictionary to set + */ + public void setDictionary(String dictionary) { + this.dictionary = dictionary; + } + /** + * @return the dictionaryFields + */ + public Map> getDictionaryFields() { + return dictionaryFields; + } + /** + * @param dictionaryFields the dictionaryFields to set + */ + public void setDictionaryFields(Map> dictionaryFields) { + this.dictionaryFields = dictionaryFields; + } + /** + * @return the requestID + */ + public UUID getRequestID() { + return requestID; + } + /** + * @param requestID the requestID to set + */ + public void setRequestID(UUID requestID) { + this.requestID = requestID; + } + +} diff --git a/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/DictionaryType.java b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/DictionaryType.java new file mode 100644 index 000000000..0935f64b9 --- /dev/null +++ b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/DictionaryType.java @@ -0,0 +1,73 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.api; + +public enum DictionaryType { + /** + * Indicates Common Dictionaries. + */ + Common("Common"), + /** + * Indicates ClosedLoop Policy Dictionaries. + */ + ClosedLoop("ClosedLoop"), + /** + * Indicates Firewall Config Policy Dictionaries. + */ + Firewall("FW"), + /** + * Indicates Decision Policy Dictionaries. + */ + Decision("Decision"), + /** + * Indicates BRMS Policy Dictionaries. + */ + BRMS("BRMS"), + /** + * Indicates DCAE Micro Service Policy Dictionaries. + */ + MicroService("MS"), + /** + * Indicates Descriptive Scope Dictionaries + */ + DescriptiveScope("DescriptiveScope"), + /** + * Indicates Policy Scope Dictionaries + */ + PolicyScope("PolicyScope"), + ; + + private String name; + + private DictionaryType(String typeName){ + this.name = typeName; + } + + /** + * Returns the String format of Type for this PolicyClass + * @return the String of the Type for this PolicyClass + */ + public String toString() { + return this.name; + } + + +} diff --git a/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/EventRequestParameters.java b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/EventRequestParameters.java new file mode 100644 index 000000000..155d9c6a5 --- /dev/null +++ b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/EventRequestParameters.java @@ -0,0 +1,89 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.api; + +import java.util.Map; +import java.util.UUID; + +/** + * EventRequestParameters defines the Event Policy Request Parameters + * which retrieve(s) the response from PDP if the request parameters match with any Action Policy. + * + * @version 0.1 + */ +public class EventRequestParameters { + private Map eventAttributes; + private UUID requestID; + + /** + * Constructor with no Parameters + */ + public EventRequestParameters(){ + } + + /** + * Constructor with Parameters + * + * @param eventAttributes the Map of String,String format of the eventAttributes that contains the event ID and values. + * @param requestID unique request ID which will be passed throughout the ECOMP components to correlate logging messages. + */ + public EventRequestParameters(Map eventAttributes, UUID requestID){ + this.eventAttributes = eventAttributes; + this.requestID = requestID; + } + + /** + * Gets the eventAttributes of Event Request Parameters. + * + * @return eventAttributes the Map of String,String format of the eventAttributes that contains the event ID and values. + */ + public Map getEventAttributes() { + return eventAttributes; + } + + /** + * Sets the eventAttributes that contain the eventID and values to the Event Request Parameters. + * + * @param eventAttributes the Map of String,String format of the eventAttributes that must contain the event ID and values. + */ + public void setEventAttributes(Map eventAttributes) { + this.eventAttributes = eventAttributes; + } + + /** + * Gets the ReqestID of Event Request Parameters which will be passed around ECOMP requests. + * + * @return requestID unique request ID which will be passed throughout the ECOMP components to correlate logging messages. + */ + public UUID getRequestID() { + return requestID; + } + + /** + * Sets the ReqestID of Event Request Parameters which will be passed around ECOMP requests. + * + * @param requestID unique request ID which will be passed throughout the ECOMP components to correlate logging messages. + */ + public void setRequestID(UUID requestID) { + this.requestID = requestID; + } + +} diff --git a/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/ImportParameters.java b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/ImportParameters.java new file mode 100644 index 000000000..299f29a93 --- /dev/null +++ b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/ImportParameters.java @@ -0,0 +1,194 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.api; + +import java.util.List; +import java.util.UUID; + + +/** + * ImportParameters defines the Policy Engine Import Parameters + * which are required to import a new Policy Service or Value. + * + * @version 0.1 + */ +public class ImportParameters { + private String serviceName; + private String description; + private UUID requestID; + private String filePath; + private String importBody; + private String version; + private IMPORT_TYPE importType; + + public enum IMPORT_TYPE { + MICROSERVICE + } + + /** + * Sets Import Policy Parameters. + * + * @param serviceName the String format of the Service Name + * @param description the String format of the i Description + * @param requestID unique request ID which will be passed throughout the ECOMP components to correlate logging messages. + * @param filePath the List format of the file paths for the service files + * @param importType the {@link IMPORT_TYPE} format of the Policy Service List + * @param version the String format of the Policy Import Version + * A different request ID should be passed for each request. + */ + public void setImportParameters(String serviceName, String description, UUID requestID, String filePath, IMPORT_TYPE importType, String version){ + + this.setServiceName(serviceName); + this.setDescription(description); + this.setRequestID(requestID); + this.setFilePath(filePath); + this.setServiceType(importType); + this.setVersion(version); + + } + + /** + * Gets the Policy Service of the Policy Service Import Parameters. + * + * @return serviceName the String format of the Policy Service Name + */ + public String getServiceName() { + return serviceName; + } + + /** + * Sets the serviceName of the Policy Service Parameters. + * + * @param serviceName the String format of the Policy Service Name + */ + public void setServiceName(String serviceName) { + this.serviceName = serviceName; + } + + /** + * Gets the Policy Import Description. + * + * @return description the String format of the Policy Import Description + */ + public String getDescription() { + return description; + } + + /** + * Sets the Description of the new Policy Import Description. + * + * @param description the String format of the Policy Import Description + */ + public void setDescription(String description) { + this.description = description; + } + + /** + * Gets the requestID of the Policy Parameters. + * + * @return unique request ID which will be passed throughout the ECOMP components to correlate logging messages. + */ + public UUID getRequestID() { + return requestID; + } + + /** + * Sets the requestID of the Policy Parameters. + * + * @param requestID unique request ID which will be passed throughout the ECOMP components to correlate logging messages. + */ + public void setRequestID(UUID requestID) { + this.requestID = requestID; + } + + /** + * Gets the importBody of the new policy import. + * + * @return importBody the String format of the Policy Import Body + */ + public String getImportBody() { + return importBody; + } + + /** + * Sets the importBody of the Policy Import Body. + * + * @param importBody the String format of the Policy Import Body + */ + public void setImportBody(String importBody) { + this.importBody = importBody; + } + + /** + * Gets the List of File Paths of the new import. + * + * @return filePath the List format of the Policy Import File + */ + public String getFilePath() { + return filePath; + } + + /** + * Sets the policy Import File List of the new Policy Import. + * + * @param filePath the List format of the Policy Import File + */ + public void setFilePath(String filePath) { + this.filePath = filePath; + } + + /** + * Gets the Service Type of the new policy import. + * + * @return ImportType {@link IMPORT_TYPE} format of the Policy Service List + */ + public IMPORT_TYPE getServiceType() { + return importType; + } + + /** + * Sets the policy Service Type of the new Policy Service. + * + * @param enumImportType the enumServiceType format of the Policy Service List + */ + public void setServiceType(IMPORT_TYPE enumImportType) { + this.importType = enumImportType; + } + + /** + * + * Gets the Import Version of the new policy import. + * + * @return version the String format of the Policy Import Version + */ + public String getVersion() { + return version; + } + + /** + * Sets the policy Import Version of the new Policy Import. + * + * @param version the String format of the Policy Import Version + */ + public void setVersion(String version) { + this.version = version; + } +} diff --git a/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/NotificationScheme.java b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/NotificationScheme.java new file mode 100644 index 000000000..2e88d9c38 --- /dev/null +++ b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/NotificationScheme.java @@ -0,0 +1,61 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.api; + +/** + * Enumeration of NotificationScheme describes the Notification Scheme that will be used by the PolicyEngine. + * + * @version 0.1 + */ +public enum NotificationScheme { + /** + * Notifications for policyUpdates on policy Configs already retrieved + */ + AUTO_NOTIFICATIONS("auto_notifications"), + /** + * Subscribing to all notifications from the PDP + */ + AUTO_ALL_NOTIFICATIONS("auto_all_notifications"), + /** + * Client can poll for updates that receive policyUpdates on policy Configs that have already been retrieved + */ + MANUAL_NOTIFICATIONS("manual_notifications"), + /** + * Client can poll for updates that receive all notifications from the PDP + */ + MANUAL_ALL_NOTIFICATIONS("manual_all_notifications") + ; + + private String name; + private NotificationScheme(String name){ + this.name = name; + } + + /** + * Returns the String name for this NotificationScheme + * + * @return the String name for this NotificationScheme + */ + @Override + public String toString(){ + return this.name; + } +} diff --git a/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyChangeResponse.java b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyChangeResponse.java new file mode 100644 index 000000000..98bfdc2e3 --- /dev/null +++ b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyChangeResponse.java @@ -0,0 +1,44 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.api; + +/** + * PolicyChangeResponse defines the Policy Response + * which is Contains responseCode corresponding to HTTP response Codes with response Message. + * + * @version 0.1 + */ +public interface PolicyChangeResponse { + + /** + * Policy Change Response Message in String format from the Policy Engine. + * + * @return the responseMessage in String format related to Response from Policy Engine. + */ + public String getResponseMessage(); + + /** + * Response code of type Integer which corresponds to the HTTP Response code explaining the response from Policy Engine. + * + * @return the responseCode in Integer format corresponding to the HTTP response code from Policy Engine. + */ + public int getResponseCode(); +} diff --git a/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyClass.java b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyClass.java new file mode 100644 index 000000000..caf3c11f1 --- /dev/null +++ b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyClass.java @@ -0,0 +1,56 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.api; + +/** + * Enumeration of the Policy Types that is used as a part of + * {@link org.openecomp.policy.api.PolicyParameters}. + * + * @version 0.1 + */ +public enum PolicyClass { + /** + * Indicates Config based Policy. + */ + Config("Config"), + /** + * Indicates Action based Policy. + */ + Action("Action"), + /** + * Indicates Decision based Policy. + */ + Decision("Decision") + ; + private String name; + + private PolicyClass(String typeName){ + this.name = typeName; + } + + /** + * Returns the String format of Type for this PolicyClass + * @return the String of the Type for this PolicyClass + */ + public String toString() { + return this.name; + } +} diff --git a/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyConfig.java b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyConfig.java new file mode 100644 index 000000000..5cb7d8176 --- /dev/null +++ b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyConfig.java @@ -0,0 +1,123 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.api; + +import java.util.Map; +import java.util.Properties; + +import javax.json.JsonObject; + +import org.w3c.dom.Document; +/** + * Defines the objects that represent PolicyEngine config elements. PolicyConfig communicates the PolicyConfigStatus, + * PolicyConfigMessage, PolicyType, Properties, JsonObject, String and Document. + * + * @version 0.7 + */ + +public interface PolicyConfig { + /** + * Gets the {@link org.openecomp.policy.api.PolicyType} associated with PolicyConfig + * + * @return the PolicyType associated with this PolicyConfig + */ + public PolicyType getType(); + + /** + * Gives the Properties response associated with the PolicyConfig + * + * @return the Properties associated with this PolicyConfig + */ + public Properties toProperties(); + + /** + * Gives the JsonObject response associated with the PolicyConfig + * + * @return the JsonObject result associated with PolicyConfig + */ + public JsonObject toJSON(); + + /** + * Gives the XML Document result associated with PolicyConfig + * + * @return the Document result associated with PolicyConfig + */ + public Document toXML(); + + /** + * Gives the Other String response associated with PolicyConfig + * + * @return the String result associated with PolicyConfig + */ + public String toOther(); + + /** + * Gets the {@link org.openecomp.policy.api.PolicyConfigStatus} associated with this PolicyConfig. + * + * @return the PolicyConfigStatus associated with this PolicyConfig + */ + public PolicyConfigStatus getPolicyConfigStatus(); + + /** + * Gets the String of the PolicyConfigMessage from PolicyConfig. + * + * @return the String which consists of PolicyConfigMessage from PolicyConfig + */ + public String getPolicyConfigMessage(); + + /** + * Gets the String of the PolicyName retrieved. + * + * @return the String which consists of Policy Name which has been retrieved. + */ + public String getPolicyName(); + + + /** + * Gets the String of the PolicyVersion retrieved. + * + * @return the String which consists of the Policy Version number which has been retrieved. + */ + public String getPolicyVersion(); + + /** + * Gets the Matching Conditions of the policy retrieved which can be used in the getConfig call. + * + * @return Map of String, String which consists of the Matching conditions of the Policy retrieved. + */ + public Map getMatchingConditions(); + + /** + * Gets the Response Attributes of the policy retrieved. Which can hold additional information about the policy retrieved. + * + * @return Map of String, String which consists of the Response Attributes of the Policy retrieved. + */ + public Map getResponseAttributes(); + + /** + * Returns the String version of the PolicyConfig object. + * + * @return String of the PolicyConfig Object. + */ + @Override + public String toString(); + +} diff --git a/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyConfigException.java b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyConfigException.java new file mode 100644 index 000000000..ad6948e77 --- /dev/null +++ b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyConfigException.java @@ -0,0 +1,49 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.api; + +/** + * PolicyConfigException extends Exception to implement exceptions thrown by {@link org.openecomp.policy.api.PolicyEngine} + * + * @version 0.1 + */ +public class PolicyConfigException extends Exception{ + private static final long serialVersionUID = -188355220060684215L; + + public PolicyConfigException() { + } + + public PolicyConfigException(String message) { + super(message); + } + + public PolicyConfigException(Throwable cause){ + super(cause); + } + + public PolicyConfigException(String message, Throwable cause) { + super(message, cause); + } + + public PolicyConfigException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } +} diff --git a/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyConfigStatus.java b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyConfigStatus.java new file mode 100644 index 000000000..9f45b652b --- /dev/null +++ b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyConfigStatus.java @@ -0,0 +1,68 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.api; + +/** + * Enumeration of PolicyConfigStatus that can be returned as a part of + * {@link org.openecomp.policy.api.PolicyConfig}. + * + * @version 0.1 + */ +public enum PolicyConfigStatus { + /** + * Indicates that the Configuration has been successfully retrieved. + */ + CONFIG_RETRIEVED("retrieved"), + /** + * Indicates that there is no Configuration Retrieved from PolicyConfig. + */ + CONFIG_NOT_FOUND("not_found"), + ; + + private String name; + private PolicyConfigStatus(String name){ + this.name = name; + } + + /** + * Get the PolicyConfigStatus based on String representation of PolicyConfig + * + * @param configStatus the String Configuration Status + * @return the PolicyConfigResponse with the name matching CONFIG_RETRIEVED or CONFIG_NOT_FOUND + * if no match is found + */ + public static PolicyConfigStatus getStatus(String configStatus) { + if(configStatus.equalsIgnoreCase("retrieved")) { + return CONFIG_RETRIEVED; + }else { + return CONFIG_NOT_FOUND; + } + } + + /** + * Returns the String name for this PolicyConfigStatus + * + * @return the String name for this PolicyConfigStatus + */ + public String toString(){ + return this.name; + } +} diff --git a/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyConfigType.java b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyConfigType.java new file mode 100644 index 000000000..111c85623 --- /dev/null +++ b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyConfigType.java @@ -0,0 +1,73 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.api; + +/** + * Enumeration of the Policy Config Types that is used as a part of + * {@link org.openecomp.policy.api.PolicyParameters}. + * + * @version 0.1 + */ +public enum PolicyConfigType { + /** + * Indicates Base Config Policy. + */ + Base("Base"), + /** + * Indicates ClosedLoop Fault Policy. + */ + ClosedLoop_Fault("Fault"), + /** + * Indicates ClosedLoop Performance Metrics Policy. + */ + ClosedLoop_PM("PM"), + /** + * Indicates Firewall Config Policy. + */ + Firewall("FW"), + /** + * Indicates BRMS based raw DRL Rule Policy. + */ + BRMS_RAW("BRMS_Raw"), + /** + * Indicates BRMS based Param DRL policy. + */ + BRMS_PARAM("BRMS_Param"), + /** + * Indicates DCAE Micro Service based Policy. + */ + MicroService("MS") + ; + + private String name; + + private PolicyConfigType(String typeName){ + this.name = typeName; + } + + /** + * Returns the String format of Type for this PolicyClass + * @return the String of the Type for this PolicyClass + */ + public String toString() { + return this.name; + } +} diff --git a/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyDecision.java b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyDecision.java new file mode 100644 index 000000000..18d066905 --- /dev/null +++ b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyDecision.java @@ -0,0 +1,57 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.api; + +/** + * Enumeration of PolicyDecision that can be returned as a part of + * {@link org.openecomp.policy.api.DecisionResponse} getDecision(). + * + * @version 0.1 + */ +public enum PolicyDecision { + /** + * Indicates that the Decision is to Permit. + */ + PERMIT("permit"), + /** + * Indicates that the Decision is to Deny. + */ + DENY("deny"), + /** + * Indicates that the Decision process has some issues. + */ + ERROR("error") + ; + + private String name; + private PolicyDecision(String name){ + this.name = name; + } + + /** + * Returns the String name for this PolicyDecision + * + * @return the String name for this PolicyDecision + */ + public String toString(){ + return this.name; + } +} diff --git a/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyDecisionException.java b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyDecisionException.java new file mode 100644 index 000000000..7f08fcb36 --- /dev/null +++ b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyDecisionException.java @@ -0,0 +1,50 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.api; + +/** + * PolicyDecisionException extends Exception to implement exceptions thrown by {@link org.openecomp.policy.api.PolicyEngine} + * + * @version 0.1 + */ +public class PolicyDecisionException extends Exception { + + private static final long serialVersionUID = -2080072039363261175L; + + public PolicyDecisionException() { + } + + public PolicyDecisionException(String message) { + super(message); + } + + public PolicyDecisionException(Throwable cause){ + super(cause); + } + + public PolicyDecisionException(String message, Throwable cause) { + super(message, cause); + } + + public PolicyDecisionException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } +} diff --git a/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyEngine.java b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyEngine.java new file mode 100644 index 000000000..0b46c57cf --- /dev/null +++ b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyEngine.java @@ -0,0 +1,575 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.api; + +import java.util.Collection; +import java.util.Map; +import java.util.UUID; + +import javax.json.JsonObject; + +import org.openecomp.policy.api.NotificationHandler; +import org.openecomp.policy.api.PDPNotification; +import org.openecomp.policy.std.StdPolicyEngine; + +/** + * PolicyEngine is the Interface that applications use to make policy queries against a PEPEngine + * + * @version 1.0 + */ +public class PolicyEngine{ + private String propertyFilePath = null; + private StdPolicyEngine stdPolicyEngine; + private NotificationScheme scheme = null; + private NotificationHandler handler = null; + + /** + * Gets the configuration from the PolicyDecisionPoint(PDP) for the String which represents the Policy File Name + * + * @param policyName the String format of the PolicyFile Name whose configuration is required. + * @return Collection of {@link org.openecomp.policy.api.PolicyConfig} which has the configuration. + * @throws PolicyConfigException + * @deprecated use {@link #getConfigByPolicyName(String policyName, UUID requestID)} Instead. + */ + @Deprecated + public Collection getConfigByPolicyName(String policyName) throws PolicyConfigException { + Collection policyConfig = stdPolicyEngine.policyName(policyName,(UUID)null); + return policyConfig; + } + + /** + * Gets the configuration from the PolicyDecisionPoint(PDP) for the String which represents the Policy File Name + * + * @param policyName the String format of the PolicyFile Name whose configuration is required. + * @param requestID unique request ID which will be passed throughout the ECOMP components to correlate logging messages. + * A different request ID should be passed for each request. + * @return Collection of {@link org.openecomp.policy.api.PolicyConfig} which has the configuration. + * @throws PolicyConfigException + * @deprecated use {@link #getConfigByPolicyName(String policyName, UUID requestID)} Instead. + */ + @Deprecated + public Collection getConfigByPolicyName(String policyName, UUID requestID) throws PolicyConfigException { + Collection policyConfig = stdPolicyEngine.policyName(policyName,requestID); + return policyConfig; + } + + /** + * Gets the configuration from the PolicyDecisionPoint(PDP) for the String which represents the eCOMPComponentName + * + * @param eCOMPComponentName the String format of the eCOMPComponentName whose configuration is required. + * @return Collection of {@link org.openecomp.policy.api.PolicyConfig} which has the configuration. + * @throws PolicyConfigException + * @deprecated use {@link #getConfig(ConfigRequestParameters)} Instead. + */ + @Deprecated + public Collection getConfig(String eCOMPComponentName) throws PolicyConfigException { + Collection policyConfig = stdPolicyEngine.config(eCOMPComponentName,(UUID)null); + return policyConfig; + } + + /** + * Gets the configuration from the PolicyDecisionPoint(PDP) for the String which represents the eCOMPComponentName + * + * @param eCOMPComponentName the String format of the eCOMPComponentName whose configuration is required. + * @return Collection of {@link org.openecomp.policy.api.PolicyConfig} which has the configuration. + * @param requestID unique request ID which will be passed throughout the ECOMP components to correlate logging messages. + * A different request ID should be passed for each request. + * @throws PolicyConfigException + * @deprecated use {@link #getConfig(ConfigRequestParameters)} Instead. + */ + @Deprecated + public Collection getConfig(String eCOMPComponentName, UUID requestID) throws PolicyConfigException { + Collection policyConfig = stdPolicyEngine.config(eCOMPComponentName,requestID); + return policyConfig; + } + + /** + * Requests the configuration of the String which represents the eCOMPComponentName and String + * which represents the configName and returns the configuration if different Configurations exist for the + * particular eCOMPComponentName. + * + * @param eCOMPComponentName the String format of the eCOMPComponentName whose configuration is required. + * @param configName the String format of the configurationName whose configuration is required. + * @return Collection of {@link org.openecomp.policy.api.PolicyConfig} which has the configuration. + * @throws PolicyConfigException + * @deprecated use {@link #getConfig(ConfigRequestParameters)} Instead. + */ + @Deprecated + public Collection getConfig(String eCOMPComponentName, String configName) throws PolicyConfigException { + Collection policyConfig = stdPolicyEngine.config(eCOMPComponentName,configName,(UUID)null); + return policyConfig; + } + + /** + * Requests the configuration of the String which represents the eCOMPComponentName and String + * which represents the configName and returns the configuration if different Configurations exist for the + * particular eCOMPComponentName. + * + * @param eCOMPComponentName the String format of the eCOMPComponentName whose configuration is required. + * @param configName the String format of the configurationName whose configuration is required. + * @param requestID unique request ID which will be passed throughout the ECOMP components to correlate logging messages. + * A different request ID should be passed for each request. + * @return Collection of {@link org.openecomp.policy.api.PolicyConfig} which has the configuration. + * @throws PolicyConfigException + * @deprecated use {@link #getConfig(ConfigRequestParameters)} Instead. + */ + @Deprecated + public Collection getConfig(String eCOMPComponentName, String configName, UUID requestID) throws PolicyConfigException { + Collection policyConfig = stdPolicyEngine.config(eCOMPComponentName,configName,requestID); + return policyConfig; + } + + /** + * Requests the configuration of the String which represents the eCOMPComponentName, String + * which represents the configName and Map of String,String which has the configAttribute and returns the specific + * configuration related to the configAttributes mentioned. + * + * @param eCOMPComponentName the String format of the eCOMPComponentName whose configuration is required. + * @param configName the String format of the configurationName whose configuration is required. + * @param configAttributes the Map of String,String format of the configuration attributes which are required. + * @return Collection of {@link org.openecomp.policy.api.PolicyConfig} which has the configuration. + * @throws PolicyConfigException + * @deprecated use {@link #getConfig(ConfigRequestParameters)} Instead. + */ + @Deprecated + public Collection getConfig(String eCOMPComponentName, String configName, Map configAttributes) throws PolicyConfigException{ + Collection policyConfig = stdPolicyEngine.config(eCOMPComponentName,configName,configAttributes,(UUID)null); + return policyConfig; + } + + /** + * Requests the configuration of the String which represents the eCOMPComponentName, String + * which represents the configName and Map of String,String which has the configAttribute and returns the specific + * configuration related to the configAttributes mentioned. + * + * @param eCOMPComponentName the String format of the eCOMPComponentName whose configuration is required. + * @param configName the String format of the configurationName whose configuration is required. + * @param configAttributes the Map of String,String format of the configuration attributes which are required. + * @param requestID unique request ID which will be passed throughout the ECOMP components to correlate logging messages. + * A different request ID should be passed for each request. + * @return Collection of {@link org.openecomp.policy.api.PolicyConfig} which has the configuration. + * @throws PolicyConfigException + * @deprecated use {@link #getConfig(ConfigRequestParameters)} Instead. + */ + @Deprecated + public Collection getConfig(String eCOMPComponentName, String configName, Map configAttributes, UUID requestID) throws PolicyConfigException{ + Collection policyConfig = stdPolicyEngine.config(eCOMPComponentName,configName,configAttributes,requestID); + return policyConfig; + } + + /** + * Requests the configuration of the ConfigRequestParameters which represents the Config policy request parameters + * and returns the specific configuration related to the matching parameters. + * + * @param configRequestParameters {@link org.openecomp.policy.api.ConfigRequestParameters} which represents the Config policy request parameters. + * @return Collection of {@link org.openecomp.policy.api.PolicyConfig} which has the configuration. + * @throws PolicyConfigException + */ + public Collection getConfig(ConfigRequestParameters configRequestParameters) throws PolicyConfigException{ + Collection policyConfig = stdPolicyEngine.config(configRequestParameters); + return policyConfig; + } + + /** + * Requests the list of policies based on the ConfigRequestParameters which represents the policy request parameters + * and returns the list of policies filtered by the parameters. + * + * @param configRequestParameters {@link org.openecomp.policy.api.ConfigRequestParameters} which represents the List Policy request parameters. + * @return Collection of String which returns the list of policies. + * @throws PolicyConfigException + */ + public Collection listConfig(ConfigRequestParameters listPolicyRequestParameters) throws PolicyConfigException{ + Collection policyList = stdPolicyEngine.listConfig(listPolicyRequestParameters); + return policyList; + } + + + /** + * Sends the Events specified to the PEP and returns back the PolicyResponse. + * + * @param eventAttributes the Map of String,String format of the eventAttributes that must contain the event ID and values. + * @return Collection of {@link org.openecomp.policy.api.PolicyResponse} which has the Response. + * @throws PolicyEventException + * @deprecated use {@link #sendEvent(EventRequestParameters)} Instead. + */ + @Deprecated + public Collection sendEvent(Map eventAttributes) throws PolicyEventException { + Collection policyResponse = stdPolicyEngine.event(eventAttributes, (UUID) null); + return policyResponse; + } + + /** + * Sends the Events specified to the PEP and returns back the PolicyResponse. + * + * @param eventAttributes the Map of String,String format of the eventAttributes that must contain the event ID and values. + * @param requestID unique request ID which will be passed throughout the ECOMP components to correlate logging messages. + * A different request ID should be passed for each request. + * @return Collection of {@link org.openecomp.policy.api.PolicyResponse} which has the Response. + * @throws PolicyEventException + * @deprecated use {@link #sendEvent(EventRequestParameters)} Instead. + */ + @Deprecated + public Collection sendEvent(Map eventAttributes, UUID requestID) throws PolicyEventException { + Collection policyResponse = stdPolicyEngine.event(eventAttributes, requestID); + return policyResponse; + } + + /** + * Sends the Events specified to the PEP and returns back the PolicyResponse. + * + * @param eventRequestParameters {@link org.openecomp.policy.api.EventRequestParameters} which represents the Event Request Parameters. + * @return Collection of {@link org.openecomp.policy.api.PolicyResponse} which has the Response. + * @throws PolicyEventException + */ + public Collection sendEvent(EventRequestParameters eventRequestParameters) throws PolicyEventException { + Collection policyResponse = stdPolicyEngine.event(eventRequestParameters); + return policyResponse; + } + + /** + * Sends the decision Attributes specified to the PEP and returns back the PolicyDecision. + * + * @param eCOMPComponentName the String format of the eCOMPComponentName whose Decision is required. + * @param decisionAttributes the Map of String,String format of the decisionAttributes that must contain the ID and values. + * @return {@link org.openecomp.policy.api.DecisionResponse} which has the Decision. + * @throws PolicyDecisionException + * @deprecated use {@link #getDecision(DecisionRequestParameters)} Instead. + */ + @Deprecated + public DecisionResponse getDecision(String eCOMPComponentName, Map decisionAttributes) throws PolicyDecisionException { + DecisionResponse policyDecision = stdPolicyEngine.decide(eCOMPComponentName, decisionAttributes, null); + return policyDecision; + } + + /** + * Sends the decision Attributes specified to the PEP and returns back the PolicyDecision. + * + * @param eCOMPComponentName the String format of the eCOMPComponentName whose Decision is required. + * @param decisionAttributes the Map of String,String format of the decisionAttributes that must contain the ID and values. + * @param requestID unique request ID which will be passed throughout the ECOMP components to correlate logging messages. + * A different request ID should be passed for each request. + * @return {@link org.openecomp.policy.api.DecisionResponse} which has the Decision. + * @throws PolicyDecisionException + * @deprecated use {@link #getDecision(DecisionRequestParameters)} Instead. + */ + @Deprecated + public DecisionResponse getDecision(String eCOMPComponentName, Map decisionAttributes, UUID requestID) throws PolicyDecisionException { + DecisionResponse policyDecision = stdPolicyEngine.decide(eCOMPComponentName, decisionAttributes, requestID); + return policyDecision; + } + + /** + * Sends the decision Attributes specified to the PEP and returns back the PolicyDecision. + * + * @param decisionRequestParameters {@link org.openecomp.policy.api.DecisionRequestParameters} which represents the Decision Request Parameters. + * @return {@link org.openecomp.policy.api.DecisionResponse} which has the Decision. + * @throws PolicyDecisionException + */ + public DecisionResponse getDecision(DecisionRequestParameters decisionRequestParameters) throws PolicyDecisionException { + DecisionResponse policyDecision = stdPolicyEngine.decide(decisionRequestParameters); + return policyDecision; + } + + /** + * setNotification allows changes to the Notification Scheme and Notification Handler + * + * @param scheme the NotificationScheme of {@link org.openecomp.policy.api.NotificationScheme} which defines the Notification Scheme + * @param handler the NotificationHandler of {@link org.openecomp.policy.api.NotificationHandler} which defines what should happen when a notification is received. + */ + public void setNotification(NotificationScheme scheme, NotificationHandler handler) { + this.scheme = scheme; + this.handler = handler; + stdPolicyEngine.notification(this.scheme,this.handler); + } + + /** + * clearNotification shutsDown the Notification Service if the Auto Scehme Notification service is running. + */ + public void clearNotification(){ + stdPolicyEngine.stopNotification(); + } + + /** + * setNotification allows changes to the Notification Scheme + * + * @param scheme the NotificationScheme of {@link org.openecomp.policy.api.NotificationScheme} which defines the Notification Scheme + */ + public void setScheme(NotificationScheme scheme){ + this.scheme = scheme; + stdPolicyEngine.setScheme(this.scheme); + } + /** + * Gets the PDPNotification if there is one exists. This is used for Polling Patterns. + * + * @return PDPNotification of {@link org.openecomp.policy.api.PDPNotification} which has the Notification. + */ + public PDPNotification getNotification() { + return stdPolicyEngine.getNotification(); + } + + /** + * Creates a Config Policy based on given arguments + * @param policyName the String format of the Policy Name + * @param policyDescription the String format of the Policy Description + * @param ecompName the String format of the ECOMP Name + * @param configName the String format of the Config Name + * @param configAttributes the List the Map Attributes that must contain the key and value. + * @param configType the String format of the Config Type + * @param body the String format of the Policy Body + * @param policyScope the String value of the sub scope directory where the policy will be created and stored + * @param requestID unique request ID which will be passed throughout the ECOMP components to correlate logging messages. + * A different request ID should be passed for each request. + * @throws Exception + * @return String format of response + * @deprecated use {@link #createPolicy(PolicyParameters)} Instead. + */ + @Deprecated + public String createConfigPolicy(String policyName, String policyDescription, String ecompName, String configName, + Map configAttributes, String configType, String body, String policyScope, UUID requestID, + String riskLevel, String riskType, String guard, String ttlDate) throws Exception { + + String response = stdPolicyEngine.createConfigPolicy(policyName, policyDescription, ecompName, configName, + configAttributes, configType, body, policyScope, requestID, + riskLevel, riskType, guard, ttlDate); + + return response; + + } + + /** + * Creates a Config Policy based on given arguments + * @param policyName the String format of the Policy Name + * @param policyDescription the String format of the Policy Description + * @param ecompName the String format of the ECOMP Name + * @param configName the String format of the Config Name + * @param configAttributes the List the Map Attributes that must contain the key and value. + * @param configType the String format of the Config Type + * @param body the String format of the Policy Body + * @param policyScope the String value of the sub scope directory where the policy will be created and stored + * @param requestID unique request ID which will be passed throughout the ECOMP components to correlate logging messages. + * A different request ID should be passed for each request. + * @throws Exception + * @return String format of response + * @deprecated use {@link #updatePolicy(PolicyParameters)} Instead. + */ + @Deprecated + public String updateConfigPolicy(String policyName, String policyDescription, String ecompName, String configName, + Map configAttributes, String configType, String body, String policyScope, UUID requestID, + String riskLevel, String riskType, String guard, String ttlDate) throws Exception { + + String response = stdPolicyEngine.updateConfigPolicy(policyName, policyDescription, ecompName, configName, + configAttributes, configType, body, policyScope, requestID,riskLevel, riskType, guard, ttlDate); + + return response; + + } + + /** + * Creates a Config Firewall Policy based on given arguments + * @param policyName the String format of the Policy Name + * @param firewallJson the JsonObject representation of the Firewall Rules List + * @param policyScope the String value of the sub scope directory where the policy will be created and stored + * @param requestID unique request ID which will be passed throughout the ECOMP components to correlate logging messages. + * A different request ID should be passed for each request. + * @throws Exception + * @return String format of response. + * @deprecated use {@link #createPolicy(PolicyParameters)} Instead. + */ + @Deprecated + public String createConfigFirewallPolicy(String policyName, JsonObject firewallJson, String policyScope, UUID requestID, + String riskLevel, String riskType, String guard, String ttlDate) throws Exception { + + String response = stdPolicyEngine.createConfigFirewallPolicy(policyName, firewallJson, policyScope, requestID,riskLevel, + riskType, guard, ttlDate); + + return response; + + } + + /** + * Updates a Config Firewall Policy based on given arguments + * @param policyName the String format of the Policy Name + * @param firewallJson the JsonObject representation of the Firewall Rules List + * @param policyScope the String value of the sub scope directory where the policy will be created and stored + * @param requestID unique request ID which will be passed throughout the ECOMP components to correlate logging messages. + * A different request ID should be passed for each request. + * @throws Exception + * @return String format of response. + * @deprecated use {@link #updatePolicy(PolicyParameters)} Instead. + */ + @Deprecated + public String updateConfigFirewallPolicy(String policyName, JsonObject firewallJson, String policyScope, UUID requestID, + String riskLevel, String riskType, String guard, String ttlDate) throws Exception { + + String response = stdPolicyEngine.updateConfigFirewallPolicy(policyName, firewallJson, policyScope, requestID,riskLevel, riskType, guard, ttlDate); + + return response; + + } + + /** + * Creates a Dictionary Item based on given Dictionary Parameters + * + * @param policyParameters {@link org.openecomp.policy.api.DictionaryParameters} which represents the Dictionary Parameters required to create a Dictionary Item. + * @return {@link org.openecomp.policy.api.PolicyChangeResponse} which consists of the response related to create dictionary item Request. + * @throws Exception + */ + public PolicyChangeResponse createDictionaryItem(DictionaryParameters parameters) throws Exception { + PolicyChangeResponse response = stdPolicyEngine.createDictionaryItem(parameters); + return response; + } + + /** + * Creates a Policy based on given Policy Parameters. + * + * @param policyParameters {@link org.openecomp.policy.api.PolicyParameters} which represents the Policy Parameters required to create a Policy. + * @return {@link org.openecomp.policy.api.PolicyChangeResponse} which consists of the response related to create policy Request. + * @throws Exception + */ + public PolicyChangeResponse createPolicy(PolicyParameters policyParameters) throws Exception { + PolicyChangeResponse response = stdPolicyEngine.createPolicy(policyParameters); + return response; + } + + /** + * Update Policy based on given Policy Parameters. + * + * @param policyParameters {@link org.openecomp.policy.api.PolicyParameters} which represents the Policy Parameters required to update a Policy. + * @return {@link org.openecomp.policy.api.PolicyChangeResponse} which consists of the response related to create policy Request. + * @throws Exception + */ + public PolicyChangeResponse updatePolicy(PolicyParameters policyParameters) throws Exception { + PolicyChangeResponse response = stdPolicyEngine.updatePolicy(policyParameters); + return response; + } + + /** + * Pushes the specified policy to the PDP Group. If no PDP group is selected default is used. + * + * @param policyScope the String value of the sub scope directory where the policy is located + * @param policyName the String format of the Policy Name being pushed. + * @param policyType the String format of the Policy Type which is being pushed. + * @param pdpGroup the String format of the PDP Group name to which the policy needs to be pushed to. + * @param requestID unique request ID which will be passed throughout the ECOMP components to correlate logging messages. + * @return String format of the response related to the push Policy Request. + * @throws Exception + * @deprecated use {@link #pushPolicy(PushPolicyParameters)} instead. + */ + @Deprecated + public String pushPolicy(String policyScope, String policyName, String policyType, String pdpGroup, UUID requestID) throws Exception { + + String response = stdPolicyEngine.pushPolicy(policyScope, policyName, policyType, pdpGroup, requestID); + + return response; + } + + /** + * Pushes the specified policy to the PDP Group. If no PDP group is selected default is used. + * + * @param pushPolicyParameters {@link org.openecomp.policy.api.PushPolicyParameters} which represents the Push Policy parameters required to push a policy. + * @return {@link org.openecomp.policy.api.PolicyChangeResponse} which consists of the response related to the push Policy Request. + * @throws Exception + */ + public PolicyChangeResponse pushPolicy(PushPolicyParameters pushPolicyParameters) throws Exception { + PolicyChangeResponse response = stdPolicyEngine.pushPolicy(pushPolicyParameters); + return response; + } + + /** + * Deletes the specified policy from the PAP or PDP. + * + * @param deletePolicyParameters {@link org.openecomp.policy.api.DeletePolicyParameters} which represents the Delete Policy parameters to delete a policy. + * @return {@link org.openecomp.policy.api.PolicyChangeResponse} which consists of the response related to the Delete Policy Request. + * @throws Exception + */ + public PolicyChangeResponse deletePolicy(DeletePolicyParameters deletePolicyParameters) throws Exception { + PolicyChangeResponse response = stdPolicyEngine.deletePolicy(deletePolicyParameters); + return response; + } + + /** + * PolicyEngine Constructor with String format of propertiesFilePathname + * + * @param propertiesFilePathname the String format of the propertiesFilePathname + * @throws PolicyEngineException + */ + public PolicyEngine(String propertiesFilePathname) throws PolicyEngineException { + this.propertyFilePath = propertiesFilePathname ; + this.stdPolicyEngine= new StdPolicyEngine(this.propertyFilePath); + } + + /** + * PolicyEngine Constructor with String format of PropertiesFilePathname, NotificationScheme and NotificationHandler + * + * @param propertiesFilePathname the String format of the propertiesFilePathname + * @param scheme the NotificationScheme of {@link org.openecomp.policy.api.NotificationScheme} which defines the Notification Scheme + * @param handler the NotificationHandler of {@link org.openecomp.policy.api.NotificationHandler} which defines what should happen when a notification is received. + * @throws PolicyEngineException + */ + public PolicyEngine(String propertiesFilePathname, NotificationScheme scheme, NotificationHandler handler) throws PolicyEngineException { + this.propertyFilePath = propertiesFilePathname ; + this.scheme = scheme; + this.handler = handler; + this.stdPolicyEngine= new StdPolicyEngine(this.propertyFilePath,this.scheme,this.handler); + } + + /** + * Creates a new Policy Service based on given Service Parameters. + * + * @param importParameters {@link org.openecomp.policy.api.ImportParameters} which represents the Service Parameters required to create a Policy Service. + * @return {@link org.openecomp.policy.api.PolicyChangeResponse} which consists of the response related to create import Service. + * @throws Exception + */ + public PolicyChangeResponse policyEngineImport(ImportParameters importParameters) throws Exception { + PolicyChangeResponse response = stdPolicyEngine.policyEngineImport(importParameters); + return response; + } + + /** + * PolicyEngine Constructor with String format of PropertiesFilePathname and NotificationScheme + * + * @param propertiesFilePathname the String format of the propertiesFilePathname + * @param scheme the NotificationScheme of {@link org.openecomp.policy.api.NotificationScheme} which defines the Notification Scheme + * @throws PolicyEngineException + */ + public PolicyEngine(String propertiesFilePathname, NotificationScheme scheme) throws PolicyEngineException{ + this.propertyFilePath = propertiesFilePathname; + this.scheme = scheme; + this.stdPolicyEngine = new StdPolicyEngine(this.propertyFilePath, this.scheme); + } + /** + * PolicyEngine Constructor with no parameters. + *//* + public PolicyEngine(){ + + } + public void createFirewallPolicy(String filterName, String termName, String preIPSource, String preIPDest, + String sourcePort, String destPort, String Port, String protocol, String direction, String action ) throws PolicyDecisionException { + stdPolicyEngine.createFirewallPolicy(filterName, termName, preIPSource, preIPDest, sourcePort, destPort, Port, + protocol, direction, action); + } + + public void updateFirewallPolicy(String filterName, String termName, String preIPSource, String preIPDest, + String sourcePort, String destPort, String Port, String protocol, String direction, String action ) throws PolicyDecisionException { + stdPolicyEngine.updateFirewallPolicy(filterName, termName, preIPSource, preIPDest, sourcePort, destPort, Port, + protocol, direction, action); + }*/ +} diff --git a/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyEngineException.java b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyEngineException.java new file mode 100644 index 000000000..e80513ad8 --- /dev/null +++ b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyEngineException.java @@ -0,0 +1,49 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.api; + +/** + * PolicyEngineException extends Exception to implement exceptions thrown by {@link org.openecomp.policy.api.PolicyEngine} + * + * @version 0.1 + */ +public class PolicyEngineException extends Exception{ + private static final long serialVersionUID = 4945973094200118969L; + + public PolicyEngineException() { + } + + public PolicyEngineException(String message) { + super(message); + } + + public PolicyEngineException(Throwable cause){ + super(cause); + } + + public PolicyEngineException(String message, Throwable cause) { + super(message, cause); + } + + public PolicyEngineException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } +} diff --git a/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyEventException.java b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyEventException.java new file mode 100644 index 000000000..8e4c81990 --- /dev/null +++ b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyEventException.java @@ -0,0 +1,49 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.api; + +/** + * PolicyEventException extends Exception to implement exceptions thrown by {@link org.openecomp.policy.api.PolicyEngine} + * + * @version 0.1 + */ +public class PolicyEventException extends Exception { + private static final long serialVersionUID = -1477625011320634608L; + + public PolicyEventException() { + } + + public PolicyEventException(String message) { + super(message); + } + + public PolicyEventException(Throwable cause){ + super(cause); + } + + public PolicyEventException(String message, Throwable cause) { + super(message, cause); + } + + public PolicyEventException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } +} diff --git a/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyParameters.java b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyParameters.java new file mode 100644 index 000000000..32cd75b5f --- /dev/null +++ b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyParameters.java @@ -0,0 +1,497 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.api; + +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +/** + * PolicyParameters defines the Policy Parameters + * which are required to Create/Update a Policy. + * + * @version 0.1 + */ +public class PolicyParameters { + private PolicyClass policyClass; + private PolicyConfigType policyConfigType; + private String policyName; + private String policyDescription; + private String ecompName; + private String configName; + private Map> attributes; + private String configBody; + private PolicyType configBodyType; + private String actionPerformer; + private String actionAttribute; + private UUID requestID; + private List dynamicRuleAlgorithmLabels; + private List dynamicRuleAlgorithmFunctions; + private List dynamicRuleAlgorithmField1; + private List dynamicRuleAlgorithmField2; + private String priority; + private RuleProvider ruleProvider; + private Date TTLDate; + private boolean guard = false; + private String riskLevel = "5"; + private String riskType = "defualt"; + + /** + * Sets Config Policy Parameters. + * + * @param policyConfigType the {@link org.openecomp.policy.api.PolicyConfigType} Enum format of the Config Type + * @param policyName the String format of the Policy Name + * @param policyDescription the String format of the Policy Description + * @param ecompName the String format of the ECOMP Name + * @param configName the String format of the Config Name + * @param attributes the Map Attributes that must contain the AttributeType and Map of key,value pairs corresponding to it. + * @param configBodyType the {@link org.openecomp.policy.api.PolicyType} Enum format of the config Body Type. + * @param configBody the String format of the Policy Body + * @param requestID unique request ID which will be passed throughout the ECOMP components to correlate logging messages. + * A different request ID should be passed for each request. + */ + public void setConfigPolicyParameters(PolicyConfigType policyConfigType, String policyName, String policyDescription, String ecompName, String configName, + Map> attributes, PolicyType configBodyType, String configBody, UUID requestID){ + this.setPolicyConfigType(policyConfigType); + this.setPolicyName(policyName); + this.setPolicyDescription(policyDescription); + this.setEcompName(ecompName); + this.setConfigName(configName); + this.setAttributes(attributes); + this.setConfigBody(configBody); + this.setConfigBodyType(configBodyType); + this.setRequestID(requestID); + } + + /** + * Sets config Firewall Policy Parameters. + * + * @param policyName the String format of the Policy Name + * @param firewallJson the String representation of the Firewall Rules List + * @param requestID unique request ID which will be passed throughout the ECOMP components to correlate logging messages. + * A different request ID should be passed for each request. + */ + public void setConfigFirewallPolicyParameters(String policyName, String firewallJson, UUID requestID){ + this.setPolicyConfigType(PolicyConfigType.Firewall); + this.setPolicyName(policyName); + this.setConfigBody(firewallJson); + this.setConfigBodyType(PolicyType.JSON); + this.setRequestID(requestID); + } + + /** + * Gets the PolicyName of the Policy Parameters. + * + * @return policyName the String format of the Policy Name + */ + public String getPolicyName() { + return policyName; + } + + /** + * Sets the policyName of the Policy Parameters. + * + * @param policyName the String format of the Policy Name + */ + public void setPolicyName(String policyName) { + this.policyName = policyName; + } + + /** + * Gets the policy Description. + * + * @return the String format of the Policy Description + */ + public String getPolicyDescription() { + return policyDescription; + } + + /** + * Sets the policy Description of the Policy Description. + * + * @param policyDescription the String format of the Policy Description + */ + public void setPolicyDescription(String policyDescription) { + this.policyDescription = policyDescription; + } + + /** + * Gets the ECOMP Name value of the Policy Paramters. + * + * @return String format of the ECOMP Name + */ + public String getEcompName() { + return ecompName; + } + + /** + * Sets the ECOMP Name field of the Policy Parameters. + * + * @param ecompName the String format of the ECOMP Name + */ + public void setEcompName(String ecompName) { + this.ecompName = ecompName; + } + + /** + * Gets the Config Name value of the Policy Parameters. + * + * @return String format of the Config Name + */ + public String getConfigName() { + return configName; + } + + /** + * Sets the Config Name field of the Policy Parameters. + * + * @param configName the String format of the Config Name + */ + public void setConfigName(String configName) { + this.configName = configName; + } + + /** + * Gets the Attributes of the policy Parameters. + * + * @return List the Map Attributes that must contain the AttributeType and Map of key,value pairs corresponding to it. + */ + public Map> getAttributes() { + return attributes; + } + + /** + * Sets the Attributes of the Policy Parameters. + * + * @param attributes the Map Attributes that must contain the AttributeType and Map of key,value pairs corresponding to it. + */ + public void setAttributes(Map> attributes) { + this.attributes = attributes; + } + + /** + * Gets the Policy Config Type value the Policy parameters. + * + * @return {@link org.openecomp.policy.api.PolicyConfigType} Enum of the Config Type + */ + public PolicyConfigType getPolicyConfigType() { + return policyConfigType; + } + + /** + * Sets the Policy Config Type field of the policy Parameters. + * + * @param policyConfigType the {@link org.openecomp.policy.api.PolicyConfigType} Enum format of the Config Type + */ + public void setPolicyConfigType(PolicyConfigType policyConfigType) { + setPolicyClass(PolicyClass.Config); + this.policyConfigType = policyConfigType; + } + + /** + * Gets the configBody value of the Policy Parameters. + * + * @return the String format of the Policy Body + */ + public String getConfigBody() { + return configBody; + } + + /** + * Sets the configBody field of the Policy Parameters. + * + * @param configBody the String format of the Policy Body + */ + public void setConfigBody(String configBody) { + this.configBody = configBody; + } + + /** + * Gets the config Body Type value of the Policy Parameters. + * + * @return the PolicyType representation of the configBodyType + */ + public PolicyType getConfigBodyType() { + return configBodyType; + } + + /** + * Sets the configBodyType field of the Policy Parameters. + * + * @param configBodyType the PolicyType representation of the config BodyType + */ + public void setConfigBodyType(PolicyType configBodyType) { + this.configBodyType = configBodyType; + } + + /** + * Gets the requestID of the Policy Parameters. + * + * @return unique request ID which will be passed throughout the ECOMP components to correlate logging messages. + */ + public UUID getRequestID() { + return requestID; + } + + /** + * Sets the requestID of the Policy Parameters. + * + * @param requestID unique request ID which will be passed throughout the ECOMP components to correlate logging messages. + */ + public void setRequestID(UUID requestID) { + this.requestID = requestID; + } + + /** + * Gets the Policy Class of the Policy Parameters. + * + * @return {@link org.openecomp.policy.api.PolicyClass} of the Policy Parameters. + */ + public PolicyClass getPolicyClass() { + return policyClass; + } + + /** + * Sets the Policy Class of the Policy Parameters. + * + * @param policyClass the Enum {@link org.openecomp.policy.api.PolicyClass} to set Policy Class Type of Policy parameters. + */ + public void setPolicyClass(PolicyClass policyClass) { + this.policyClass = policyClass; + } + + /** + * Gets the Action Performer value of the Policy Parameters for Action Policies. + * + * @return the String value of the Action Performer for Action Policies + */ + public String getActionPerformer() { + return actionPerformer; + } + + /** + * Sets the Action Performer value of the Policy Parameters for Action Policies. + * + * @param actionPerformer the String format of the Action Performer + */ + public void setActionPerformer(String actionPerformer) { + this.actionPerformer = actionPerformer; + } + + /** + * Gets the Action Attribute value of the Policy Parameters for Action Policies. + * + * @return the String value of the Action Attribute for Action Policies + */ + public String getActionAttribute() { + return actionAttribute; + } + + /** + * Sets the Action Attribute value of the Policy Parameters for Action Policies. + * + * @param actionAttribute the String format of the Action Attribute + */ + public void setActionAttribute(String actionAttribute) { + this.actionAttribute = actionAttribute; + } + + /** + * Gets the Dynamic Rule Algorithm Label of the policy Parameters. Used in conjunction with the Label, Field1, + * Function, and Field2 to complete the complex and simple Rule Algorithms + * + * @return List the Dynamic Rule Algorithm Label that must contain the Labels in order + */ + public List getDynamicRuleAlgorithmLabels() { + return dynamicRuleAlgorithmLabels; + } + + /** + * Sets the Dynamic Rule Algorithm Labels used in conjunction with the Label, Field1, + * Function, and Field2 to complete the complex and simple Rule Algorithms + * + * @param dynamicRuleAlgorithmLabels the List dynamicRuleAlgoritmLabels in order + */ + public void setDynamicRuleAlgorithmLabels( + List dynamicRuleAlgorithmLabels) { + this.dynamicRuleAlgorithmLabels = dynamicRuleAlgorithmLabels; + } + + /** + * Gets the Dynamic Rule Algorithm Function of the policy Parameters. Used in conjunction with the Label, Field1, + * FunctionDef, and Field2 to complete the complex and simple Rule Algorithms + * + * @return List the Dynamic Rule Algorithm Functions that must contain the values in order + */ + public List getDynamicRuleAlgorithmFunctions() { + return dynamicRuleAlgorithmFunctions; + } + + /** + * Sets the Dynamic Rule Algorithm Functions used in conjunction with the Label, Field1, + * Function, and Field2 to complete the complex and simple Rule Algorithms + * + * @param dynamicRuleAlgorithmFunctions the List dynamicRuleAlgorithmFunctions in order + */ + public void setDynamicRuleAlgorithmFunctions(List dynamicRuleAlgorithmFunctions) { + this.dynamicRuleAlgorithmFunctions = dynamicRuleAlgorithmFunctions; + } + + /** + * Gets the Dynamic Rule Algorithm Field1 of the policy Parameters. Used in conjunction with the Label, Field1, + * Function, and Field2 to complete the complex and simple Rule Algorithms + * + * @return List the Dynamic Rule Algorithm Field1 that must contain the Field1 values in order + */ + public List getDynamicRuleAlgorithmField1() { + return dynamicRuleAlgorithmField1; + } + + /** + * Sets the Dynamic Rule Algorithm Field1 used in conjunction with the Label, Field1, + * Function, and Field2 to complete the complex and simple Rule Algorithms + * + * @param dynamicRuleAlgorithmField1 the List dynamicRuleAlgorithmField1 in order + */ + public void setDynamicRuleAlgorithmField1( + List dynamicRuleAlgorithmField1) { + this.dynamicRuleAlgorithmField1 = dynamicRuleAlgorithmField1; + } + + /** + * Gets the Dynamic Rule Algorithm Field2 of the policy Parameters. Used in conjunction with the Label, Field1, + * Operator, and Field2 to complete the complex and simple Rule Algorithms + * + * @return List the Dynamic Rule Algorithm Field2 that must contain the Field2 values in order + */ + public List getDynamicRuleAlgorithmField2() { + return dynamicRuleAlgorithmField2; + } + + /** + * Sets the Dynamic Rule Algorithm Field2 used in conjunction with the Label, Field1, + * Function, and Field2 to complete the complex and simple Rule Algorithms + * + * @param dynamicRuleAlgorithmField2 the List dynamicRuleAlgorithmField2 in order + */ + public void setDynamicRuleAlgorithmField2( + List dynamicRuleAlgorithmField2) { + this.dynamicRuleAlgorithmField2 = dynamicRuleAlgorithmField2; + } + + /** + * Gets the Priority of the Policy Parameters. + * + * @return priority the String format of the Micro Services priority + */ + public String getPriority() { + return priority; + } + + /** + * Sets the Priority of the Policy Parameters. + * + * @param priority the String format of the Micro Services priority + */ + public void setPriority(String priority) { + this.priority = priority; + } + + public RuleProvider getRuleProvider() { + return ruleProvider; + } + + public void setRuleProvider(RuleProvider ruleProvider) { + this.ruleProvider = ruleProvider; + } + /** + * Sets the Guard field of the Policy Parameters. + * + * @param guard the Boolean format of the guard value + */ + public void setGuard(boolean guard){ + this.guard = guard; + } + + /** + * Gets the guard value of the Policy Parameters for Action Policies. + * + * @return the boolean value of the Guard for Config Policies + */ + public boolean getGuard(){ + return guard; + } + + /** + * Sets the riskType field of the Policy Parameters. + * + * @param guard the String format of the riskType value + */ + public void setRiskType(String riskType){ + this.riskType = riskType; + } + + /** + * Gets the riskType value of the Policy Parameters for Config Policies. + * + * @return the String value of the riskType for Config Policies + */ + public String getRiskType(){ + return riskType; + } + + /** + * Sets the riskLevel field of the Policy Parameters. + * + * @param riskLevel the String format of the riskType value + */ + public void setRiskLevel(String riskLevel){ + this.riskLevel = riskLevel; + } + + /** + * Gets the riskLevel value of the Policy Parameters for Config Policies. + * + * @return the String value of the riskLevel for Config Policies + */ + public String getRiskLevel(){ + return riskLevel; + } + + /** + * Sets the TTLDate field of the Policy Parameters. + * + * @param TTLDate the Date format of the TTLDate value + */ + public void setTtlDate(Date TTLDate){ + this.TTLDate = TTLDate; + } + + /** + * Gets the TTLDate value of the Policy Parameters for Config Policies. + * + * @return the Date value of the TTLDate for Config Policies + */ + public Date getTtlDate(){ + return TTLDate; + } +} diff --git a/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyResponse.java b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyResponse.java new file mode 100644 index 000000000..316f7dd83 --- /dev/null +++ b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyResponse.java @@ -0,0 +1,77 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + + +package org.openecomp.policy.api; + +import java.util.Map; + +/** + * Defines the objects that represent PolicyEngine Response elements. PolicyResponse communicates the PolicyResponseStatus, + * PolicyResponseMessage, ActionAdvised, ActionTaken and RequestAttributes. + * + * @version 0.3 + */ +public interface PolicyResponse { + /** + * Gets the {@link org.openecomp.policy.api.PolicyResponseStatus} associated with this PolicyResponse. + * + * @return the PolicyResponseStatus associated with this PolicyResponse + */ + public PolicyResponseStatus getPolicyResponseStatus(); + + /** + * Gets the Map of String,String which consists of ActionAdvised in this PolicyResponse. + * If there is no ActionAdvised this method must return an empty Map. + * + * @return the Map of String,String which consists of AdviceAttributes in PolicyResponse + */ + public Map getActionAdvised(); + + /** + * Gets the Map of String,String which consists of ActionTaken in this PolicyResponse. + * If there are no ActionTaken this method must return an empty Map. + * + * @return the Map of String,String which consists of ActionTaken in PolicyResponse + */ + public Map getActionTaken(); + + /** + * Gets the Map of String,String which consists of RequestAttributes in this PolicyResponse. + * + * @return the Map of String,String which consists of RequestAttributes from PolicyResponse + */ + public Map getRequestAttributes(); + + /** + * Gets the String of the PolicyResponseMessage from PolicyResponse + * + * @return the String which consists of PolicyResponseMessage from PolicyResponse + */ + public String getPolicyResponseMessage(); + + /** + * Returns the String version of the PolicyResponse object. + * + * @return String of the PolicyResponse Object. + */ + @Override + public String toString(); +} diff --git a/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyResponseStatus.java b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyResponseStatus.java new file mode 100644 index 000000000..a9c329621 --- /dev/null +++ b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyResponseStatus.java @@ -0,0 +1,73 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.api; + +/** + * Enumeration of PolicyResponseStatus that can be returned as a part of + * {@link org.openecomp.policy.api.PolicyResponse}. + * + * @version 0.2 + */ +public enum PolicyResponseStatus { + /** + * Indicates there is no action required. + */ + NO_ACTION_REQUIRED("no_action"), + /** + * Indicates that an action has been advised. + */ + ACTION_ADVISED("action_advised"), + /** + * Indicates that an action has been taken. + */ + ACTION_TAKEN("action_taken") + ; + + private String name; + private PolicyResponseStatus(String name){ + this.name = name; + } + + /** + * Get the PolicyResponseStatus based on String representation of PolicyResponse + * + * @param responseStatus the String Response Status + * @return the PolicyResponseStatus with the name matching ACTION_ADVISED or ACTION_TAKEN or NO_ACTION_REQUIRED + */ + public static PolicyResponseStatus getStatus(String responseStatus) { + if(responseStatus.equalsIgnoreCase("action_advised")) { + return ACTION_ADVISED; + }else if(responseStatus.equalsIgnoreCase("action_taken")) { + return ACTION_TAKEN; + }else { + return NO_ACTION_REQUIRED; + } + } + + /** + * Returns the String name for this PolicyResponseStatus + * + * @return the String name for this PolicyResponseStatus + */ + public String toString(){ + return this.name; + } +} diff --git a/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyType.java b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyType.java new file mode 100644 index 000000000..b86f9521f --- /dev/null +++ b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PolicyType.java @@ -0,0 +1,61 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.api; + +/** + * Enumeration of the Policy Return Types that can be returned as part of a + * {@link org.openecomp.policy.api.PolicyConfig}. + * + * @version 0.2 + */ +public enum PolicyType { + /** + * Indicates the response is Properties type + */ + PROPERTIES("Properties"), + /** + * Indicates the response is JSON type + */ + JSON("json"), + /** + * Indicates the response is XML type + */ + XML("xml"), + /** + * Indicates the response is Other type + */ + OTHER("other") + ; + + private String name; + + private PolicyType(String typeName) { + this.name = typeName; + } + + /** + * Returns the String format of Type for this PolicyType + * @return the String of the Type for this PolicyType + */ + public String toString() { + return this.name; + } +} diff --git a/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PushPolicyParameters.java b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PushPolicyParameters.java new file mode 100644 index 000000000..8a822065b --- /dev/null +++ b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/PushPolicyParameters.java @@ -0,0 +1,131 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.api; + +import java.util.UUID; + +/** + * PushPolicyParameters defines the Policy Parameters + * which are required to Push a Policy to PDPGroup. + * + * @version 0.1 + */ +public class PushPolicyParameters { + private String policyName; + private String policyType; + private String pdpGroup; + private UUID requestID; + + /** + * Constructor with no Parameters. + */ + public PushPolicyParameters(){ + } + + /** + * Constructor with Parameters. + * + * @param policyName the String format of the Policy Name + * @param policyType the String format of the Policy Type + * @param pdpGroup the String format of the PDPGroup + * @param requestID unique request ID which will be passed throughout the ECOMP components to correlate logging messages. + */ + public PushPolicyParameters(String policyName, String policyType, String pdpGroup, UUID requestID){ + this.policyName = policyName; + this.policyType = policyType; + this.pdpGroup = pdpGroup; + this.requestID = requestID; + } + + /** + * Gets the PolicyName of the Push Policy Parameters. + * + * @return policyName the String format of the Policy Name + */ + public String getPolicyName() { + return policyName; + } + + /** + * Sets the policyName of the Push Policy Parameters. + * + * @param policyName the String format of the Policy Name + */ + public void setPolicyName(String policyName) { + this.policyName = policyName; + } + + /** + * Gets the PolicyType of the Push Policy Parameters. + * + * @return policyType the String format of the Policy Type + */ + public String getPolicyType() { + return policyType; + } + + /** + * Sets the policyType of the Push Policy Parameters. + * + * @param policyType the String format of the Policy Type + */ + public void setPolicyType(String policyType) { + this.policyType = policyType; + } + + /** + * Gets the PDPGroup of the Push Policy Parameters. + * + * @return pdpGroup the String format of the PDPGroup + */ + public String getPdpGroup() { + return pdpGroup; + } + + /** + * Sets the PDPGroup of the Push Policy Parameters. + * + * @param pdpGroup the String format of the PDPGroup + */ + public void setPdpGroup(String pdpGroup) { + this.pdpGroup = pdpGroup; + } + + /** + * Gets the requestID of the Push Policy Parameters. + * + * @return unique request ID which will be passed throughout the ECOMP components to correlate logging messages. + */ + public UUID getRequestID() { + return requestID; + } + + /** + * Sets the requestID of the Push Policy Parameters. + * + * @param requestID unique request ID which will be passed throughout the ECOMP components to correlate logging messages. + */ + public void setRequestID(UUID requestID) { + this.requestID = requestID; + } + + +} diff --git a/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/RuleProvider.java b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/RuleProvider.java new file mode 100644 index 000000000..8e9218124 --- /dev/null +++ b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/RuleProvider.java @@ -0,0 +1,53 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.api; + +/** + * Enumeration of the Attribute Types that is used as a part of + * {@link org.openecomp.policy.api.PolicyParameters}. + * + * @version 0.1 + */ +public enum RuleProvider { + /** + * Indicates User will be defining the Rule information. + */ + CUSTOM("Custom"), + /** + * Indicates AAF will be providing the Rule information. + */ + AAF("AAF") + ; + + private String name; + + private RuleProvider(String typeName){ + this.name = typeName; + } + + /** + * Returns the String format of Type for this AttributeType + * @return the String of the Type for this AttributeType + */ + public String toString() { + return this.name; + } +} diff --git a/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/package-info.java b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/package-info.java new file mode 100644 index 000000000..982dbb47c --- /dev/null +++ b/PolicyEngineAPI/src/main/java/org/openecomp/policy/api/package-info.java @@ -0,0 +1,36 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + + +package org.openecomp.policy.api; + +/** + * org.openecomp.policy.api contains the API for the PolicyEngine ProtoType + * + * @version 0.9 + * + * Changes: + * Addition of Notifications methods to the Client API. + * Combining Multiple results. and Minor changes to retrieve all policies. + * Retrieve config policy using policyFile Name and the matching conditions of the policy in the results. + * Addition of Decision policy call + * + * + */ diff --git a/PolicyEngineAPI/src/main/java/org/openecomp/policy/std/AutoClientEnd.java b/PolicyEngineAPI/src/main/java/org/openecomp/policy/std/AutoClientEnd.java new file mode 100644 index 000000000..3f4fe0c7e --- /dev/null +++ b/PolicyEngineAPI/src/main/java/org/openecomp/policy/std/AutoClientEnd.java @@ -0,0 +1,244 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.std; + +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; + +import javax.websocket.ClientEndpoint; +import javax.websocket.DeploymentException; +import javax.websocket.OnClose; +import javax.websocket.OnError; +import javax.websocket.OnMessage; +import javax.websocket.OnOpen; +import javax.websocket.Session; + +//import org.apache.log4j.Logger; +import org.glassfish.tyrus.client.ClientManager; +import org.openecomp.policy.api.NotificationHandler; +import org.openecomp.policy.api.NotificationScheme; +import org.openecomp.policy.api.NotificationType; +import org.openecomp.policy.api.PDPNotification; +import org.openecomp.policy.std.NotificationStore; +import org.openecomp.policy.std.StdPDPNotification; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; +import org.openecomp.policy.common.logging.flexlogger.*; + +@ClientEndpoint +public class AutoClientEnd { + private static StdPDPNotification notification = null; + private static StdPDPNotification oldNotification = null; + private static ClientManager client = null; + private static NotificationScheme scheme = null; + private static NotificationHandler handler = null; + private static String url = null; + private static Session session = null; + private static boolean status = false; + private static boolean stop = false; + private static boolean message = false; + private static boolean error = false; + private static Logger logger = FlexLogger.getLogger(AutoClientEnd.class.getName()); + + public static void setAuto(NotificationScheme scheme, + NotificationHandler handler) { + AutoClientEnd.scheme = scheme; + AutoClientEnd.handler = handler; + } + + public static void setScheme(NotificationScheme scheme) { + AutoClientEnd.scheme = scheme; + } + + public static boolean getStatus(){ + return AutoClientEnd.status; + } + + public static String getURL() { + return AutoClientEnd.url; + } + + public static void start(String url) { + AutoClientEnd.url = url; + // Stop and Start needs to be done. + if (scheme != null && handler!=null) { + if (scheme.equals(NotificationScheme.AUTO_ALL_NOTIFICATIONS) || scheme.equals(NotificationScheme.AUTO_NOTIFICATIONS)) { + if (AutoClientEnd.client == null) { + client = ClientManager.createClient(); + if(url.contains("https")){ + url = url.replaceAll("https", "wss"); + }else { + url = url.replaceAll("http", "ws"); + } + try { + logger.info("Starting Auto Notification with the PDP server : " + url); + client.connectToServer(AutoClientEnd.class, new URI(url + "notifications")); + status = true; + if(error){ + // The URL's will be in Sync according to design Spec. + ManualClientEnd.start(AutoClientEnd.url); + StdPDPNotification notification = NotificationStore.getDeltaNotification((StdPDPNotification)ManualClientEnd.result(NotificationScheme.MANUAL_ALL_NOTIFICATIONS)); + if(notification.getNotificationType()!=null){ + if(oldNotification!=notification){ + oldNotification= notification; + AutoClientEnd.notification = notification; + callHandler(); + } + } + error = false; + } + // + } catch (DeploymentException | IOException | URISyntaxException e) { + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e); + client = null; + status = false; + changeURL(); + } + } + } + } + } + + private static void changeURL(){ + // Change the PDP if it is not Up. + StdPolicyEngine.rotateList(); + start(StdPolicyEngine.getPDPURL()); + } + + public static void stop() { + if (client != null) { + client.shutdown(); + if(session!=null){ + try { + stop = true; + logger.info("\n Closing Auto Notification WebSocket Connection.. "); + session.close(); + session = null; + } catch (IOException e) { + // + } + } + client = null; + status = false; + stop = false; + } + } + + private static void callHandler() { + if (handler != null && scheme != null) { + if (scheme.equals(NotificationScheme.AUTO_ALL_NOTIFICATIONS)) { + boolean removed = false, updated = false; + if (notification.getRemovedPolicies() != null && !notification.getRemovedPolicies().isEmpty()) { + removed = true; + } + if (notification.getLoadedPolicies() != null && !notification.getLoadedPolicies().isEmpty()) { + updated = true; + } + if (removed && updated) { + notification.setNotificationType(NotificationType.BOTH); + } else if (removed) { + notification.setNotificationType(NotificationType.REMOVE); + } else if (updated) { + notification.setNotificationType(NotificationType.UPDATE); + } + try{ + handler.notificationReceived(notification); + }catch (Exception e){ + logger.error("Error in Clients Handler Object : " + e.getMessage()); + } + } else if (scheme.equals(NotificationScheme.AUTO_NOTIFICATIONS)) { + PDPNotification newNotification = MatchStore.checkMatch(notification); + if (newNotification.getNotificationType() != null) { + handler.notificationReceived(newNotification); + } + } + } + } + + // WebSockets Code.. + @OnOpen + public void onOpen(Session session) throws IOException { + // session.getBasicRemote().sendText("Connected to Client with Session: " + // + session.getId()); + logger.debug("Auto Notification Session Started... " + session.getId()); + if(AutoClientEnd.session == null){ + AutoClientEnd.session = session; + } + } + + @OnError + public void onError(Session session, Throwable e) { + // trying to Restart by self. + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Session Error.. "+ session.getId() + "\n Error is : " + e ); + // e.printStackTrace(); + stop(); + if (url != null) { + client = null; + status = false; + error= true; + start(url); + } + } + + @OnClose + public void onClose(Session session) { + logger.info("Session ended with "+ session.getId()); + if(!stop && !message){ + // This Block of code is executed if there is any Network Failure or if the Notification is Down. + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Disconnected from Notification Server"); + client = null; + status = false; + AutoClientEnd.session=null; + // Try to connect Back to available PDP. + error = true; + start(url); + } + AutoClientEnd.message=false; + } + + @OnMessage + public void onMessage(String message, Session session) throws JsonParseException, JsonMappingException, IOException { + AutoClientEnd.message = true; + logger.debug("Auto Notification Recieved Message " + message + " Session info is : " + session.getId()); + try { + notification = NotificationUnMarshal.notificationJSON(message); + } catch (Exception e) { + logger.error("PE500 " + e); + } + if(AutoClientEnd.session == session){ + try{ + NotificationStore.recordNotification(notification); + }catch(Exception e){ + logger.error(e); + } + if(oldNotification!=notification){ + oldNotification= notification; + callHandler(); + } + }else{ + session.close(); + } + AutoClientEnd.message = false; + } +} diff --git a/PolicyEngineAPI/src/main/java/org/openecomp/policy/std/AutoClientUEB.java b/PolicyEngineAPI/src/main/java/org/openecomp/policy/std/AutoClientUEB.java new file mode 100644 index 000000000..87bb50154 --- /dev/null +++ b/PolicyEngineAPI/src/main/java/org/openecomp/policy/std/AutoClientUEB.java @@ -0,0 +1,170 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.std; + +import java.net.MalformedURLException; +import java.net.URL; +import java.security.GeneralSecurityException; +import java.util.List; +import java.util.UUID; + +import org.openecomp.policy.api.NotificationHandler; +import org.openecomp.policy.api.NotificationScheme; +import org.openecomp.policy.api.NotificationType; +import org.openecomp.policy.api.PDPNotification; +import org.openecomp.policy.std.StdPDPNotification; + +import com.att.nsa.cambria.client.CambriaClientFactory; +import com.att.nsa.cambria.client.CambriaConsumer; +import org.openecomp.policy.common.logging.flexlogger.*; +/** + * Create a UEB Consumer to receive policy update notification. + * + * + * + */ +public class AutoClientUEB implements Runnable { + private static StdPDPNotification notification = null; + private static NotificationScheme scheme = null; + private static NotificationHandler handler = null; + private static String url = null; + private static boolean status = false; + private static Logger logger = FlexLogger.getLogger(AutoClientUEB.class.getName()); + private static String notficatioinType = null; + private static CambriaConsumer CConsumer = null; +// private volatile boolean stop = false; + private static List uebURLList = null; + public volatile boolean isRunning = false; + + + public AutoClientUEB(String url, List uebURLList) { + AutoClientUEB.url = url; + AutoClientUEB.uebURLList = uebURLList; + } + + public void setAuto(NotificationScheme scheme, + NotificationHandler handler) { + AutoClientUEB.scheme = scheme; + AutoClientUEB.handler = handler; + } + + public static void setScheme(NotificationScheme scheme) { + AutoClientUEB.scheme = scheme; + } + + public static boolean getStatus(){ + return AutoClientUEB.status; + } + + public static String getURL() { + return AutoClientUEB.url; + } + + public static String getNotficationType(){ + return AutoClientUEB.notficatioinType; + } + + public synchronized boolean isRunning() { + return this.isRunning; + } + + public synchronized void terminate() { + this.isRunning = false; + } + @SuppressWarnings("deprecation") + @Override + public void run() { + synchronized(this) { + this.isRunning = true; + } + String group = UUID.randomUUID ().toString (); + String id = "0"; + String topic = null; + // Stop and Start needs to be done. + if (scheme != null && handler!=null) { + if (scheme.equals(NotificationScheme.AUTO_ALL_NOTIFICATIONS) || scheme.equals(NotificationScheme.AUTO_NOTIFICATIONS)) { + //Check if the Notification Type is UEB t if (notficationType.equals("ueb")){ + URL aURL; + try { + aURL = new URL(AutoClientUEB.url); + topic = aURL.getHost() + aURL.getPort(); + } catch (MalformedURLException e) { + topic = AutoClientUEB.url.replace("[:/]", ""); + } + + //TODO create a loop to listen for messages from UEB cluster + try { + CConsumer = CambriaClientFactory.createConsumer ( null, uebURLList, topic, group, id, 15*1000, 1000 ); + } catch (MalformedURLException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } catch (GeneralSecurityException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + while (this.isRunning() ) + { + try { + for ( String msg : CConsumer.fetch () ) + { + logger.debug("Auto Notification Recieved Message " + msg + " from UEB cluster : " + uebURLList.toString()); + notification = NotificationUnMarshal.notificationJSON(msg); + callHandler(); + } + } catch (Exception e) { + // TODO Auto-generated catch block + logger.debug("Error in processing UEB message"); + } + + } + logger.debug("Stopping UEB Consuer loop will not logger fetch messages from the cluser"); + } + } + } + + private static void callHandler() { + if (handler != null && scheme != null) { + if (scheme.equals(NotificationScheme.AUTO_ALL_NOTIFICATIONS)) { + boolean removed = false, updated = false; + if (notification.getRemovedPolicies() != null && !notification.getRemovedPolicies().isEmpty()) { + removed = true; + } + if (notification.getLoadedPolicies() != null && !notification.getLoadedPolicies().isEmpty()) { + updated = true; + } + if (removed && updated) { + notification.setNotificationType(NotificationType.BOTH); + } else if (removed) { + notification.setNotificationType(NotificationType.REMOVE); + } else if (updated) { + notification.setNotificationType(NotificationType.UPDATE); + } + handler.notificationReceived(notification); + } else if (scheme.equals(NotificationScheme.AUTO_NOTIFICATIONS)) { + PDPNotification newNotification = MatchStore.checkMatch(notification); + if (newNotification.getNotificationType() != null) { + handler.notificationReceived(newNotification); + } + } + } + } + +} diff --git a/PolicyEngineAPI/src/main/java/org/openecomp/policy/std/ManualClientEnd.java b/PolicyEngineAPI/src/main/java/org/openecomp/policy/std/ManualClientEnd.java new file mode 100644 index 000000000..c006b057b --- /dev/null +++ b/PolicyEngineAPI/src/main/java/org/openecomp/policy/std/ManualClientEnd.java @@ -0,0 +1,138 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.std; + +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.concurrent.CountDownLatch; + +import javax.websocket.ClientEndpoint; +import javax.websocket.DeploymentException; +import javax.websocket.OnClose; +import javax.websocket.OnError; +import javax.websocket.OnMessage; +import javax.websocket.OnOpen; +import javax.websocket.Session; + +//import org.apache.log4j.Logger; +import org.glassfish.tyrus.client.ClientManager; +import org.openecomp.policy.api.NotificationScheme; +import org.openecomp.policy.api.NotificationType; +import org.openecomp.policy.api.PDPNotification; +import org.openecomp.policy.std.StdPDPNotification; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +import org.openecomp.policy.common.logging.flexlogger.*; + +@ClientEndpoint +public class ManualClientEnd { + private static CountDownLatch latch; + private static StdPDPNotification notification = null; + private static String resultJson = null; + private static Logger logger = FlexLogger.getLogger(ManualClientEnd.class.getName()); + + public static void start(String url) { + latch = new CountDownLatch(1); + ClientManager client = ClientManager.createClient(); + if(url.contains("https")){ + url = url.replaceAll("https", "wss"); + }else { + url = url.replaceAll("http", "ws"); + } + try { + client.connectToServer(ManualClientEnd.class, new URI(url+"notifications")); + latch.await(); + } catch (DeploymentException | URISyntaxException | InterruptedException e) { + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e); + } catch (IOException e) { + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e); + } + } + + public static PDPNotification result(NotificationScheme scheme) { + if (resultJson == null || notification == null) { + logger.debug("No Result" ); + return null; + } else { + if(scheme.equals(NotificationScheme.MANUAL_ALL_NOTIFICATIONS)) { + boolean removed = false, updated = false; + if(notification.getRemovedPolicies()!=null && !notification.getRemovedPolicies().isEmpty()){ + removed = true; + } + if(notification.getLoadedPolicies()!=null && !notification.getLoadedPolicies().isEmpty()){ + updated = true; + } + if(removed && updated) { + notification.setNotificationType(NotificationType.BOTH); + }else if(removed){ + notification.setNotificationType(NotificationType.REMOVE); + }else if(updated){ + notification.setNotificationType(NotificationType.UPDATE); + } + return notification; + }else if(scheme.equals(NotificationScheme.MANUAL_NOTIFICATIONS)) { + return MatchStore.checkMatch(notification); + }else { + return null; + } + } + } + + // WebSockets Code.. + @OnOpen + public void onOpen(Session session) throws IOException { + logger.info("Session Started with : " + session.getId()); + session.getBasicRemote().sendText("Manual"); + } + + @OnError + public void onError(Session session, Throwable e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error in: "+ session.getId()); + latch.countDown(); + } + + @OnClose + public void onClose(Session session) { + logger.info("Session ended with "+ session.getId()); + latch.countDown(); + } + + @OnMessage + public void onMessage(String message, Session session){ + logger.debug(" Manual Notification Recieved Message : " + message +" Session info is : "+ session.getId()); + resultJson = message; + try { + notification = NotificationUnMarshal.notificationJSON(message); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e); + latch.countDown(); + } + try { + session.close(); + } catch (IOException e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + latch.countDown(); + } // For Manual Client.. + latch.countDown(); + } +} diff --git a/PolicyEngineAPI/src/main/java/org/openecomp/policy/std/ManualClientEndUEB.java b/PolicyEngineAPI/src/main/java/org/openecomp/policy/std/ManualClientEndUEB.java new file mode 100644 index 000000000..b1962bc77 --- /dev/null +++ b/PolicyEngineAPI/src/main/java/org/openecomp/policy/std/ManualClientEndUEB.java @@ -0,0 +1,173 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.std; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.security.GeneralSecurityException; +import java.util.List; +import java.util.UUID; +import java.util.concurrent.CountDownLatch; + +//import org.apache.log4j.Logger; +import org.json.JSONObject; +import org.openecomp.policy.api.NotificationScheme; +import org.openecomp.policy.api.NotificationType; +import org.openecomp.policy.api.PDPNotification; +import org.openecomp.policy.std.StdPDPNotification; + +import com.att.nsa.cambria.client.CambriaClientFactory; +import com.att.nsa.cambria.client.CambriaConsumer; +import com.att.nsa.cambria.client.CambriaPublisher; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; +import org.openecomp.policy.common.logging.flexlogger.*; + + +public class ManualClientEndUEB { + private static StdPDPNotification notification = null; + private static String resultJson = null; + private static Logger logger = FlexLogger.getLogger(ManualClientEndUEB.class.getName()); + private static CambriaConsumer CConsumer = null; + private static List uebURLList = null; + private static boolean messageNotReceived = false; + private static String url = null; + private static String uniquID = null; + private static String topic = null; + + + public static PDPNotification result(NotificationScheme scheme) { + if (resultJson == null || notification == null) { + logger.debug("No Result" ); + return null; + } else { + if(scheme.equals(NotificationScheme.MANUAL_ALL_NOTIFICATIONS)) { + boolean removed = false, updated = false; + if(notification.getRemovedPolicies()!=null && !notification.getRemovedPolicies().isEmpty()){ + removed = true; + } + if(notification.getLoadedPolicies()!=null && !notification.getLoadedPolicies().isEmpty()){ + updated = true; + } + if(removed && updated) { + notification.setNotificationType(NotificationType.BOTH); + }else if(removed){ + notification.setNotificationType(NotificationType.REMOVE); + }else if(updated){ + notification.setNotificationType(NotificationType.UPDATE); + } + return notification; + }else if(scheme.equals(NotificationScheme.MANUAL_NOTIFICATIONS)) { + return MatchStore.checkMatch(notification); + }else { + return null; + } + } + } + + private static void publishMessage(String pubTopic, String uniqueID , List uebURLList) { + + String UEBlist = uebURLList.toString(); + UEBlist = UEBlist.substring(1,UEBlist.length()-1); + CambriaPublisher pub = null; + try { + pub = CambriaClientFactory.createSimplePublisher(null, UEBlist, pubTopic); + } catch (MalformedURLException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } catch (GeneralSecurityException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + final JSONObject msg1 = new JSONObject (); + + msg1.put ( "JSON", "UEB Update Ruest UID=" + uniqueID); + + try { + pub.send ( "MyPartitionKey", msg1.toString () ); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + pub.close (); + + } + + public static void createTopic (String url, String uniquID, List uebURLList){ + URL aURL; + try { + aURL = new URL(url); + topic = aURL.getHost() + aURL.getPort(); + } catch (MalformedURLException e) { + topic = url.replace("[:/]", ""); + } + + publishMessage(topic+ uniquID , uniquID, uebURLList); + + } + public static void start(String url, List uebURLList, + String uniqueID) { + ManualClientEndUEB.uebURLList = uebURLList; + ManualClientEndUEB.url = url; + ManualClientEndUEB.uniquID = uniqueID; + URL aURL; + try { + aURL = new URL(url); + ManualClientEndUEB.topic = aURL.getHost() + aURL.getPort(); + } catch (MalformedURLException e) { + ManualClientEndUEB.topic = url.replace("[:/]", ""); + } + String id = "0"; + try { + CConsumer = CambriaClientFactory.createConsumer ( null, uebURLList, topic + uniquID, "clientGroup", id, 15*1000, 1000 ); + } catch (MalformedURLException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } catch (GeneralSecurityException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + int count = 1; + while (count < 4) { + publishMessage(topic + "UpdateRequest", uniquID, uebURLList); + try { + for ( String msg : CConsumer.fetch () ) + { + + logger.debug("Manual Notification Recieved Message " + msg + " from UEB cluster : " + uebURLList.toString()); + resultJson = msg; + if (!msg.contains("UEB Update")){ +// System.out.println("Manual Notification Recieved Message " + msg + " from UEB cluster : " + uebURLList.toString()); + notification = NotificationUnMarshal.notificationJSON(msg); + count = 4; + } + } + }catch (Exception e) { + + } + count++; + } + } + +} diff --git a/PolicyEngineAPI/src/main/java/org/openecomp/policy/std/MatchStore.java b/PolicyEngineAPI/src/main/java/org/openecomp/policy/std/MatchStore.java new file mode 100644 index 000000000..2c06b9a9e --- /dev/null +++ b/PolicyEngineAPI/src/main/java/org/openecomp/policy/std/MatchStore.java @@ -0,0 +1,246 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.std; + +import java.util.Collection; +import java.util.HashSet; + +import org.openecomp.policy.api.LoadedPolicy; +import org.openecomp.policy.api.NotificationType; +import org.openecomp.policy.api.PDPNotification; +import org.openecomp.policy.api.RemovedPolicy; +import org.openecomp.policy.std.StdLoadedPolicy; +import org.openecomp.policy.std.StdPDPNotification; +import org.openecomp.policy.std.StdRemovedPolicy; + +import org.openecomp.policy.common.logging.flexlogger.*; + +public class MatchStore { + private static HashSet matchStore = new HashSet(); + private static Logger logger = FlexLogger.getLogger(MatchStore.class.getName()); + + public static HashSet getMatchStore() { + return matchStore; + } + + public static void storeMatch(Matches newMatch){ + // Initialization.. + if(newMatch!=null){ + if(matchStore.isEmpty()){ + matchStore.add(newMatch); + }else{ + // Check if it is a new Match + Boolean match = false; + for(Matches oldMatch: matchStore){ + // Compare ECOMPName + if(oldMatch.getEcompName().equals(newMatch.getEcompName())){ + // Compare ConfigName if it exists. + if(newMatch.getConfigName()!=null && oldMatch.getConfigName()!=null){ + if(oldMatch.getConfigName().equals(newMatch.getConfigName())){ + // Compare the Config Attributes if they exist. + if(newMatch.getConfigAttributes()!= null && oldMatch.getConfigAttributes()!=null) { + //Simple thing would be comparing their size. + if(newMatch.getConfigAttributes().size()==oldMatch.getConfigAttributes().size()){ + // Now need to compare each of them.. + int count= 0; + for(String oldkey: oldMatch.getConfigAttributes().keySet()){ + boolean check = false; + for(String newKey: newMatch.getConfigAttributes().keySet()){ + if(oldkey.equals(newKey)){ + if(oldMatch.getConfigAttributes().get(oldkey).equals(newMatch.getConfigAttributes().get(newKey))){ + check = true; + } + } + } + if(check){ + count++; + }else{ + break; + } + } + if(count==oldMatch.getConfigAttributes().size()){ + match = true; + break; + } + } + }else if(newMatch.getConfigAttributes()== null && oldMatch.getConfigAttributes()==null){ + match = true; + break; + } + } + }else if(newMatch.getConfigName()==null && oldMatch.getConfigName()==null){ + match = true; + break; + } + } + + } + // IF not a match then add it to the MatchStore + if(match==false){ + matchStore.add(newMatch); + } + } + } + } + + //TODO Logic changes for Requested Policies notifications.. + public static PDPNotification checkMatch(PDPNotification oldNotification) { + boolean removed = false, updated = false; + if(oldNotification==null){ + return null; + } + StdPDPNotification newNotification = new StdPDPNotification(); + if(matchStore.isEmpty()) { + logger.debug("No Success Config Calls made yet.. "); + System.out.println("No success Config calls made yet. "); + return null; + } + if(oldNotification.getRemovedPolicies()!=null && !oldNotification.getRemovedPolicies().isEmpty()){ + // send all removed policies to client. + Collection removedPolicies = new HashSet(); + StdRemovedPolicy newRemovedPolicy; + for(RemovedPolicy removedPolicy: oldNotification.getRemovedPolicies()){ + newRemovedPolicy = new StdRemovedPolicy(); + newRemovedPolicy.setPolicyName(removedPolicy.getPolicyName()); + newRemovedPolicy.setVersionNo(removedPolicy.getVersionNo()); + removedPolicies.add(newRemovedPolicy); + } + newNotification.setRemovedPolicies(removedPolicies); + removed = true; + } + if(oldNotification.getLoadedPolicies()!=null && !oldNotification.getLoadedPolicies().isEmpty()){ + Collection updatedPolicies = new HashSet(); + StdLoadedPolicy newUpdatedPolicy; + for(LoadedPolicy updatedPolicy: oldNotification.getLoadedPolicies()){ + // if it is config policies check their matches.. + if(updatedPolicy.getMatches()!=null && !updatedPolicy.getMatches().isEmpty()){ + boolean matched = false; + for(Matches match : matchStore){ + matched = false; + // Again Better way would be comparing sizes first. + // Matches are different need to check if has configAttributes + if(match.getConfigAttributes()!=null && !match.getConfigAttributes().isEmpty()){ + // adding ecomp and config to config-attributes. + int compValues = match.getConfigAttributes().size() + 2; + if(updatedPolicy.getMatches().size()== compValues){ + // Comparing both the values.. + boolean matchAttributes = false; + for(String newKey: updatedPolicy.getMatches().keySet()){ + if(newKey.equals("ECOMPName")){ + if(updatedPolicy.getMatches().get(newKey).equals(match.getEcompName())){ + matchAttributes = true; + }else { + matchAttributes = false; + break; + } + }else if(newKey.equals("ConfigName")) { + if(updatedPolicy.getMatches().get(newKey).equals(match.getConfigName())){ + matchAttributes = true; + }else{ + matchAttributes = false; + break; + } + }else { + if(match.getConfigAttributes().containsKey(newKey)){ + if(updatedPolicy.getMatches().get(newKey).equals(match.getConfigAttributes().get(newKey))){ + matchAttributes = true; + }else{ + matchAttributes = false; + break; + } + }else{ + matchAttributes = false; + break; + } + } + } + if(matchAttributes){ + // Match.. + matched = true; + }else{ + break; + } + }else { + break; + } + }else if(match.getConfigName()!=null){ + // If there are no config Attributes then check if it has Config Name + if(updatedPolicy.getMatches().size()== 2){ + if(updatedPolicy.getMatches().get("ECOMPName").equals(match.getEcompName())){ + if(updatedPolicy.getMatches().get("ConfigName").equals(match.getConfigName())){ + // Match.. + matched = true; + }else{ + break; + } + }else { + break; + } + }else{ + break; + } + }else { + // If non exist then assuming the ECOMP Name to be there. + if(updatedPolicy.getMatches().size()== 1){ + if(updatedPolicy.getMatches().get("ECOMPName").equals(match.getEcompName())){ + // Match.. + matched = true; + }else { + break; + } + }else{ + break; + } + } + // Add logic to add the policy. + if(matched){ + newUpdatedPolicy = new StdLoadedPolicy(); + newUpdatedPolicy.setPolicyName(updatedPolicy.getPolicyName()); + newUpdatedPolicy.setVersionNo(updatedPolicy.getVersionNo()); + newUpdatedPolicy.setMatches(updatedPolicy.getMatches()); + updatedPolicies.add(newUpdatedPolicy); + updated = true; + } + } + + }else { + //send all non config notifications to client. + newUpdatedPolicy = new StdLoadedPolicy(); + newUpdatedPolicy.setPolicyName(updatedPolicy.getPolicyName()); + newUpdatedPolicy.setVersionNo(updatedPolicy.getVersionNo()); + updatedPolicies.add(newUpdatedPolicy); + updated = true; + } + } + newNotification.setLoadedPolicies(updatedPolicies); + } + // Need to set the type of Update.. + if(removed && updated) { + newNotification.setNotificationType(NotificationType.BOTH); + }else if(removed){ + newNotification.setNotificationType(NotificationType.REMOVE); + }else if(updated){ + newNotification.setNotificationType(NotificationType.UPDATE); + } + return newNotification; + } + +} diff --git a/PolicyEngineAPI/src/main/java/org/openecomp/policy/std/Matches.java b/PolicyEngineAPI/src/main/java/org/openecomp/policy/std/Matches.java new file mode 100644 index 000000000..8e6a8ee97 --- /dev/null +++ b/PolicyEngineAPI/src/main/java/org/openecomp/policy/std/Matches.java @@ -0,0 +1,48 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.std; + +import java.util.Map; + +public class Matches { + private String ecompName = null; + private String configName = null; + private Map configAttributes = null; + public String getEcompName() { + return ecompName; + } + public void setEcompName(String ecompName) { + this.ecompName = ecompName; + } + public String getConfigName() { + return configName; + } + public void setConfigName(String configName) { + this.configName = configName; + } + public Map getConfigAttributes() { + return configAttributes; + } + public void setConfigAttributes(Map configAttributes) { + this.configAttributes = configAttributes; + } + +} diff --git a/PolicyEngineAPI/src/main/java/org/openecomp/policy/std/NotificationUnMarshal.java b/PolicyEngineAPI/src/main/java/org/openecomp/policy/std/NotificationUnMarshal.java new file mode 100644 index 000000000..a09391baf --- /dev/null +++ b/PolicyEngineAPI/src/main/java/org/openecomp/policy/std/NotificationUnMarshal.java @@ -0,0 +1,69 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.std; + +import java.util.ArrayList; +import java.util.Collection; + +import org.openecomp.policy.api.LoadedPolicy; +import org.openecomp.policy.api.RemovedPolicy; +import org.openecomp.policy.api.UpdateType; +import org.openecomp.policy.std.StdLoadedPolicy; +import org.openecomp.policy.std.StdPDPNotification; + +import com.fasterxml.jackson.databind.ObjectMapper; + +public class NotificationUnMarshal { + private static StdPDPNotification notification; + + public static StdPDPNotification notificationJSON(String json) throws Exception{ + ObjectMapper mapper = new ObjectMapper(); + notification = mapper.readValue(json, StdPDPNotification.class); + if(notification!=null){ + if(notification.getLoadedPolicies()!=null){ + Collection stdLoadedPolicies = new ArrayList(); + for(LoadedPolicy loadedPolicy: notification.getLoadedPolicies()){ + StdLoadedPolicy stdLoadedPolicy = (StdLoadedPolicy) loadedPolicy; + if(notification.getRemovedPolicies()!=null){ + Boolean updated = false; + for(RemovedPolicy removedPolicy: notification.getRemovedPolicies()){ + String regex = ".(\\d)*.xml"; + if(removedPolicy.getPolicyName().replaceAll(regex, "").equals(stdLoadedPolicy.getPolicyName().replaceAll(regex, ""))){ + updated = true; + break; + } + } + if(updated){ + stdLoadedPolicy.setUpdateType(UpdateType.UPDATE); + }else{ + stdLoadedPolicy.setUpdateType(UpdateType.NEW); + } + }else{ + stdLoadedPolicy.setUpdateType(UpdateType.NEW); + } + stdLoadedPolicies.add(stdLoadedPolicy); + } + notification.setLoadedPolicies(stdLoadedPolicies); + } + } + return notification; + } +} diff --git a/PolicyEngineAPI/src/main/java/org/openecomp/policy/std/StdDecisionResponse.java b/PolicyEngineAPI/src/main/java/org/openecomp/policy/std/StdDecisionResponse.java new file mode 100644 index 000000000..1f4cf65d0 --- /dev/null +++ b/PolicyEngineAPI/src/main/java/org/openecomp/policy/std/StdDecisionResponse.java @@ -0,0 +1,55 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + + +package org.openecomp.policy.std; + +import org.openecomp.policy.api.DecisionResponse; +import org.openecomp.policy.api.PolicyDecision; + +/** + * Decision Response Implementation Class. + * + * @version 0.1 + */ +public class StdDecisionResponse implements DecisionResponse { + + private PolicyDecision decision = PolicyDecision.DENY; + private String details; + + @Override + public PolicyDecision getDecision() { + return decision; + } + + @Override + public String getDetails() { + return details; + } + + public void setDecision(PolicyDecision decision){ + this.decision = decision; + } + + public void setDetails(String details) { + this.details = details; + } + +} diff --git a/PolicyEngineAPI/src/main/java/org/openecomp/policy/std/StdPolicyChangeResponse.java b/PolicyEngineAPI/src/main/java/org/openecomp/policy/std/StdPolicyChangeResponse.java new file mode 100644 index 000000000..2fec8605c --- /dev/null +++ b/PolicyEngineAPI/src/main/java/org/openecomp/policy/std/StdPolicyChangeResponse.java @@ -0,0 +1,47 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.std; + +import org.openecomp.policy.api.PolicyChangeResponse; + +public class StdPolicyChangeResponse implements PolicyChangeResponse{ + private String responseMessage = null; + private int responseCode; + + @Override + public String getResponseMessage() { + return responseMessage; + } + + @Override + public int getResponseCode() { + return responseCode; + } + + public void setResponseMessage(String responseMessage){ + this.responseMessage = responseMessage; + } + + public void setResponseCode(int responseCode){ + this.responseCode = responseCode; + } + +} diff --git a/PolicyEngineAPI/src/main/java/org/openecomp/policy/std/StdPolicyConfig.java b/PolicyEngineAPI/src/main/java/org/openecomp/policy/std/StdPolicyConfig.java new file mode 100644 index 000000000..ec205dab2 --- /dev/null +++ b/PolicyEngineAPI/src/main/java/org/openecomp/policy/std/StdPolicyConfig.java @@ -0,0 +1,168 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + + +package org.openecomp.policy.std; + +import java.util.Map; +import java.util.Properties; + +import javax.json.JsonObject; + +import org.openecomp.policy.api.PolicyConfig; +import org.openecomp.policy.api.PolicyConfigStatus; +import org.openecomp.policy.api.PolicyType; +import org.w3c.dom.Document; + +/** + * PolicyConfig Implementation. + * + * @version 0.3 + * + */ + +public class StdPolicyConfig implements PolicyConfig{ + private PolicyType policyType; + private Properties properties; + private JsonObject jsonObject; + private Document document; + private String other; + private PolicyConfigStatus policyConfigStatus; + private String configStatus; + private String policyName; + private String policyVersion; + private Map matchingConditions; + private Map responseAttributes; + + @Override + public PolicyType getType() { + return policyType; + } + + @Override + public Properties toProperties() { + return properties; + } + + @Override + public JsonObject toJSON() { + return jsonObject; + } + + @Override + public Document toXML() { + return document; + } + + @Override + public String toOther() { + return other; + } + + @Override + public PolicyConfigStatus getPolicyConfigStatus() { + return policyConfigStatus; + } + + @Override + public String getPolicyConfigMessage() { + return configStatus; + } + + @Override + public String getPolicyName() { + if(policyName!=null && policyName.contains(".xml")){ + return (policyName.substring(0, policyName.substring(0, policyName.lastIndexOf(".")).lastIndexOf("."))); + } + return policyName; + } + + @Override + public String getPolicyVersion() { + return policyVersion; + } + + @Override + public Map getMatchingConditions(){ + return matchingConditions; + } + + @Override + public Map getResponseAttributes(){ + return responseAttributes; + } + + public void setPolicyType(PolicyType policyType) { + this.policyType = policyType; + } + + public void setPolicyName(String policyName) { + this.policyName = policyName; + } + + public void setPolicyVersion(String policyVersion) { + this.policyVersion = policyVersion; + } + + public void setProperties(Properties properties) { + this.properties = properties; + } + + public void setJsonObject(JsonObject jsonObject) { + this.jsonObject = jsonObject; + } + + public void setDocument(Document document) { + this.document = document; + } + + public void setOther(String other) { + this.other = other; + } + + public void setConfigStatus(String configStatus) { + this.configStatus = configStatus; + } + + public void setPolicyConfigStatus(PolicyConfigStatus policyConfigStatus) { + this.policyConfigStatus = policyConfigStatus; + } + + public void setConfigStatus(String configStatus, PolicyConfigStatus policyConfigStatus) { + this.configStatus = configStatus; + this.policyConfigStatus = policyConfigStatus; + } + + public void setMatchingConditions(Map matchingConditions){ + this.matchingConditions = matchingConditions; + } + + public void setResponseAttributes(Map responseAttributes){ + this.responseAttributes = responseAttributes; + } + + @Override + public String toString() { + return "PolicyConfig [ policyConfigStatus=" + policyConfigStatus + ", policyConfigMessage=" + configStatus + ", policyName=" + policyName + + "" + + "]"; + } + +} diff --git a/PolicyEngineAPI/src/main/java/org/openecomp/policy/std/StdPolicyEngine.java b/PolicyEngineAPI/src/main/java/org/openecomp/policy/std/StdPolicyEngine.java new file mode 100644 index 000000000..11e4e4f5c --- /dev/null +++ b/PolicyEngineAPI/src/main/java/org/openecomp/policy/std/StdPolicyEngine.java @@ -0,0 +1,4227 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + + +package org.openecomp.policy.std; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.StringReader; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URL; +import java.net.URLConnection; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Base64; +import java.util.Collection; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.UUID; + +import javax.json.Json; +import javax.json.JsonArrayBuilder; +import javax.json.JsonObject; +import javax.json.JsonObjectBuilder; +import javax.json.JsonReader; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +import org.apache.commons.io.IOUtils; +import org.apache.http.entity.ContentType; +//import org.apache.log4j.Logger; +import org.json.JSONObject; +import org.openecomp.policy.api.AttributeType; +import org.openecomp.policy.api.ConfigRequestParameters; +import org.openecomp.policy.api.DecisionRequestParameters; +import org.openecomp.policy.api.DecisionResponse; +import org.openecomp.policy.api.DeletePolicyParameters; +import org.openecomp.policy.api.DictionaryParameters; +import org.openecomp.policy.api.EventRequestParameters; +import org.openecomp.policy.api.ImportParameters; +import org.openecomp.policy.api.NotificationHandler; +import org.openecomp.policy.api.NotificationScheme; +import org.openecomp.policy.api.PDPNotification; +import org.openecomp.policy.api.PolicyChangeResponse; +import org.openecomp.policy.api.PolicyClass; +import org.openecomp.policy.api.PolicyConfig; +import org.openecomp.policy.api.PolicyConfigException; +import org.openecomp.policy.api.PolicyConfigStatus; +import org.openecomp.policy.api.PolicyConfigType; +import org.openecomp.policy.api.PolicyDecision; +import org.openecomp.policy.api.PolicyDecisionException; +import org.openecomp.policy.api.PolicyEngineException; +import org.openecomp.policy.api.PolicyEventException; +import org.openecomp.policy.api.PolicyParameters; +import org.openecomp.policy.api.PolicyResponse; +import org.openecomp.policy.api.PolicyResponseStatus; +import org.openecomp.policy.api.PolicyType; +import org.openecomp.policy.api.PushPolicyParameters; +import org.openecomp.policy.api.RuleProvider; +//import org.openecomp.policy.utils.AAFPolicyClient; +//import org.openecomp.policy.utils.AAFPolicyException; +import org.w3c.dom.Document; +import org.xml.sax.SAXException; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +import com.att.research.xacml.api.Advice; +import com.att.research.xacml.api.AttributeAssignment; +import com.att.research.xacml.api.Decision; +import com.att.research.xacml.api.Obligation; +import com.att.research.xacml.api.Request; +import com.att.research.xacml.api.Response; +import com.att.research.xacml.api.Result; +import org.openecomp.policy.xacml.api.XACMLErrorConstants; +import org.openecomp.policy.xacml.std.pap.StdPAPPolicy; +import org.openecomp.policy.xacml.std.pap.StdPDPPolicy; + +import com.att.research.xacml.api.pap.PAPException; +import com.att.research.xacml.api.pap.PDPPolicy; +import com.att.research.xacml.std.json.JSONRequest; +import com.att.research.xacml.std.json.JSONResponse; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.base.CharMatcher; + + + +/** + * PolicyEngine Implementation class + * + * @version 1.0 + */ +public class StdPolicyEngine { + // Change the default Priority value here. + private static final int defaultPriority = 9999; + + private String propertyFilePath = null; + private static List pdps = null; + private static List paps = null; + private static String environment= null; + private static String userName = null; + private static String pass = null; + private static List encoding = null; + private static List encodingPAP = null; + private List pdp_default = null; + private List pap_default = null; + private List type_default = null; + private List notificationType = new ArrayList(); + private List uebURLList = new ArrayList(); + private NotificationScheme scheme = null; + private NotificationHandler handler = null; + private Matches match = null; + private Boolean decide = false; + private AutoClientUEB UEBClientThread = null; + private Thread registerUEBThread = null; + private boolean UEBThread = false; + private String policyId = null; + private String description = null; + private String pushVersion = null; + private boolean isValid = false; + private int responseCode = 0; + private boolean unique = false; + private boolean junit = false; + //private AAFPolicyClient aafClient = null; + // Backward code. + private String pyPDPClientFile = null; + + final private static String uniqueID = UUID.randomUUID ().toString (); + + private static Logger logger = FlexLogger.getLogger(StdPolicyConfig.class.getName()); + + /* + * Taking the Property file even if it null. + */ + public StdPolicyEngine(String propertyFilePath) + throws PolicyEngineException { + setProperty(propertyFilePath); + } + + /* + * Taking the Notification Constructor. + */ + public StdPolicyEngine(String propertyFilePath, NotificationScheme scheme, + NotificationHandler handler) throws PolicyEngineException { + setProperty(propertyFilePath); + this.scheme = scheme; + this.handler = handler; + if (!notificationType.get(0).equals("ueb")){ + AutoClientEnd.setAuto(scheme, handler); + } + notification(scheme, handler); + } + + /* + * Taking the Notification Constructor. + */ + public StdPolicyEngine(String propertyFilePath, NotificationScheme scheme) + throws PolicyEngineException { + setProperty(propertyFilePath); + this.scheme = scheme; + setScheme(scheme); + } + + // This Call will be used by PyPDP Requests + public StdPolicyEngine(List configURL, List configPapURL, List encodingPAP, List encoding, NotificationScheme scheme, NotificationHandler handler, String environment, String clientProperties, Boolean isTest) { + StdPolicyEngine.pdps = configURL; + StdPolicyEngine.paps = configPapURL; + StdPolicyEngine.encoding = encoding; + StdPolicyEngine.encodingPAP = encodingPAP; + StdPolicyEngine.environment = environment; + Properties props = new Properties(); + props.setProperty("ENVIRONMENT", environment); + //Not Supported for 1610 Open Source + /*try { + aafClient = AAFPolicyClient.getInstance(props); + } catch (AAFPolicyException e) { + logger.error(XACMLErrorConstants.ERROR_UNKNOWN + e.getMessage()); + }*/ + pyPDPClientFile = clientProperties; + // Default Notification Type for PyPDPServers. + notificationType.add("websocket"); + if(!isTest){ + notification(scheme, handler); + } + } + + /* + * sendEvent API Implementation + */ + public Collection event(Map eventAttributes, UUID requestID) + throws PolicyEventException { + Collection policyResponse = null; + policyResponse = event(eventAttributes, requestID, userName, pass); + return policyResponse; + } + + /* + * sendEvent API Implementation for eventRequestParameters + */ + public Collection event(EventRequestParameters eventRequestParameters) throws PolicyEventException{ + Collection response = event(eventRequestParameters.getEventAttributes(), eventRequestParameters.getRequestID()); + return response; + } + + /* + * getConfig API Implementation + */ + public Collection config(String eCOMPComponentName, + String configName, Map configAttributes, UUID requestID) + throws PolicyConfigException { + Collection policyConfig = null; + policyConfig = config(eCOMPComponentName, configName, configAttributes, requestID, userName, pass); + return policyConfig; + } + + /* + * getConfig API Implementation + */ + public Collection config(String eCOMPComponentName, + String configName, UUID requestID) throws PolicyConfigException { + Collection policyConfig = null; + policyConfig = config(eCOMPComponentName, configName,null, requestID, userName, pass); + return policyConfig; + } + + /* + * getConfig API Implementation + */ + public Collection config(String eCOMPComponentName, UUID requestID) + throws PolicyConfigException { + Collection policyConfig = null; + policyConfig = config(eCOMPComponentName, requestID, userName, pass); + return policyConfig; + } + + /* + * getConfig using the PolicyFileName Implementation + */ + public Collection policyName(String policyName, UUID requestID) + throws PolicyConfigException { + Collection policyConfig = null; + policyConfig = configPolicyName(policyName, requestID, userName, pass); + return policyConfig; + } + + /* + * getConfig using configRequestParameters Implementation + */ + public Collection config(ConfigRequestParameters configRequestParameters) throws PolicyConfigException{ + Collection response = null; + response = configRequest(configRequestParameters, userName, pass); + return response; + } + + /* + * listPolicies using configRequestParameters Implementation + */ + public Collection listConfig(ConfigRequestParameters listPolicyRequestParameters) throws PolicyConfigException{ + Collection policyList = new ArrayList(); + policyList = listConfigRequest(listPolicyRequestParameters, userName, pass); + return policyList; + } + + /* + * getDecision using the decision Attributes. + */ + public DecisionResponse decide(String eCOMPComponentName, + Map decisionAttributes, UUID requestID) + throws PolicyDecisionException { + DecisionResponse policyDecision = policyDecide(eCOMPComponentName, + decisionAttributes, requestID, userName, pass); + return policyDecision; + } + + /* + * getDecision Using decisionRequestParameters. + */ + public DecisionResponse decide(DecisionRequestParameters decisionRequestParameters) throws PolicyDecisionException{ + DecisionResponse decision = decide(decisionRequestParameters.getECOMPComponentName(), decisionRequestParameters.getDecisionAttributes(), decisionRequestParameters.getRequestID()); + return decision; + } + + /* + * PushPolicy using pushPolicyParameters. + */ + public PolicyChangeResponse pushPolicy(PushPolicyParameters pushPolicyParameters) throws Exception{ + return pushPolicy(pushPolicyParameters, userName, pass); + } + + public PolicyChangeResponse pushPolicy(PushPolicyParameters pushPolicyParameters, String userID, String passcode) throws Exception{ + StdPolicyChangeResponse response = new StdPolicyChangeResponse(); + String resource= "pushPolicy"; + if(!checkPermissions(userID, passcode, resource)){ + logger.error(XACMLErrorConstants.ERROR_PERMISSIONS + "You are not allowed to Make this Request. Please contact PolicyAdmin to give access to:" + resource); + response.setResponseMessage(XACMLErrorConstants.ERROR_PERMISSIONS + "You are not allowed to Make this Request. Please contact PolicyAdmin to give access to:" + resource); + response.setResponseCode(401); + return response; + } + String plainName = null; + String scope = null; + try{ + if(pushPolicyParameters.getPolicyName()!=null){ + plainName = pushPolicyParameters.getPolicyName().substring(pushPolicyParameters.getPolicyName().lastIndexOf(".")+1, pushPolicyParameters.getPolicyName().length()); + scope = pushPolicyParameters.getPolicyName().substring(0, pushPolicyParameters.getPolicyName().lastIndexOf(".")); + logger.info("Name is "+ plainName +" scope is "+ scope); + } + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Scope given."); + response.setResponseMessage(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Scope given."); + } + + // check incoming requestID, if null then generate one here so the same id can be used for the multiple transactions for the same Push Policy request (i.e. POST, PUT) + UUID requestID = pushPolicyParameters.getRequestID(); + if (requestID == null) { + requestID = UUID.randomUUID(); + logger.info("Request ID was not provided from input, so sending generated ID: " + requestID.toString()); + } else { + logger.info("Request ID was provided from input: " + requestID.toString()); + } + // now use the local requestID field derived above to pass to the rest of the Push Policy process (below) + // response.setResponseMessage(pushPolicy(scope, plainName, pushPolicyParameters.getPolicyType(), pushPolicyParameters.getPdpGroup(), pushPolicyParameters.getRequestID())); + response.setResponseMessage(pushPolicy(scope, plainName, pushPolicyParameters.getPolicyType(), pushPolicyParameters.getPdpGroup(), requestID)); + response.setResponseCode(responseCode); + return response; + } + + /* + * Delete a Policy using deletePolicyParameters + */ + public PolicyChangeResponse deletePolicy(DeletePolicyParameters parameters) throws Exception { + return deletePolicy(parameters, userName, pass); + } + + public PolicyChangeResponse deletePolicy(DeletePolicyParameters parameters, String userID,String passcode) throws Exception { + StdPolicyChangeResponse response = new StdPolicyChangeResponse(); + String resource= "deletePolicy"; + if(!checkPermissions(userID, passcode, resource)){ + logger.error(XACMLErrorConstants.ERROR_PERMISSIONS + "You are not allowed to Make this Request. Please contact PolicyAdmin to give access to:" + resource); + response.setResponseMessage(XACMLErrorConstants.ERROR_PERMISSIONS + "You are not allowed to Make this Request. Please contact PolicyAdmin to give access to:" + resource); + response.setResponseCode(401); + return response; + } + if (parameters.getPolicyComponent()!=null) { + if (parameters.getPolicyComponent().equalsIgnoreCase("PAP")) { + response.setResponseMessage(deletePolicyFromPAP(parameters)); + } else if (parameters.getPolicyComponent().equalsIgnoreCase("PDP")) { + response.setResponseMessage(deletePolicyFromPDP(parameters)); + } else { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Policy Component does not exist."); + response.setResponseMessage(XACMLErrorConstants.ERROR_DATA_ISSUE + "Policy Component does not exist. Please enter either PAP or PDP to delete the policy from a specified Policy Component."); + } + } else { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Component given."); + response.setResponseMessage(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Component given."); + } + + response.setResponseCode(responseCode); + return response; + } + + /* + * createDictionaryItem using dictionaryParameters. + */ + public PolicyChangeResponse createDictionaryItem(DictionaryParameters parameters) throws Exception{ + StdPolicyChangeResponse response = new StdPolicyChangeResponse(); + + if(parameters.getDictionaryType()!=null || parameters.getDictionaryType().equals("")){ + if(parameters.getDictionary()!=null || parameters.getDictionary().equals("")){ + if(parameters.getDictionaryFields()!=null){ + logger.info("Parameters are good... start create dictionary item API..."); + + Map dictionaryFields = parameters.getDictionaryFields().get(AttributeType.DICTIONARY); + + StdPAPPolicy newDictionaryItem = new StdPAPPolicy(parameters.getDictionaryType().toString(), parameters.getDictionary(), dictionaryFields); + + String result = (String) callPAP(newDictionaryItem, new String[] {"operation=createDictionary", "apiflag=dictionaryApi"}, parameters.getRequestID(), "dictionaryItem"); + + response.setResponseCode(responseCode); + response.setResponseMessage(result); + + }else{ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Dictionary Fields given."); + response.setResponseMessage(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Dictionary Fields given."); + } + }else{ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Dictionary given."); + response.setResponseMessage(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Dictionary given."); + } + }else{ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Dictionary Type given."); + response.setResponseMessage(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Dictionary Type given."); + } + try{ + + }catch(Exception e){ + + } + + return response; + } + + /* + * createPolicy Using policyParameters. + */ + public PolicyChangeResponse createPolicy(PolicyParameters policyParameters) throws Exception{ + return createPolicy(policyParameters, userName, pass); + } + + public PolicyChangeResponse createPolicy(PolicyParameters policyParameters, String userID, String passcode) throws Exception{ + StdPolicyChangeResponse response = new StdPolicyChangeResponse(); + String resource= "createPolicy"; + if(!checkPermissions(userID, passcode, resource)){ + logger.error(XACMLErrorConstants.ERROR_PERMISSIONS + "You are not allowed to Make this Request. Please contact PolicyAdmin to give access to:" + resource); + response.setResponseMessage(XACMLErrorConstants.ERROR_PERMISSIONS + "You are not allowed to Make this Request. Please contact PolicyAdmin to give access to:" + resource); + response.setResponseCode(401); + return response; + } + String plainName = null; + String scope = null; + String date = "NA"; + if (policyParameters.getTtlDate()!=null){ + date = ConvertDate(policyParameters.getTtlDate()); + } + try{ + if(policyParameters.getPolicyName()!=null){ + plainName = policyParameters.getPolicyName().substring(policyParameters.getPolicyName().lastIndexOf(".")+1, policyParameters.getPolicyName().length()); + scope = policyParameters.getPolicyName().substring(0, policyParameters.getPolicyName().lastIndexOf(".")); + logger.info("Name is "+ plainName +" scope is "+ scope); + } + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Scope given."); + response.setResponseMessage(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Scope given."); + } + if(policyParameters.getPolicyConfigType()!=null){ + // This is Config Class Policy. + // Firewall + if(policyParameters.getPolicyConfigType().equals(PolicyConfigType.Firewall)){ + if(policyParameters.getConfigBody()!=null){ + JsonObject json = null; + try{ + json = stringToJsonObject(policyParameters.getConfigBody()); + }catch(Exception e){ + String message = XACMLErrorConstants.ERROR_DATA_ISSUE+ " improper JSON object : " + policyParameters.getConfigBody(); + logger.error(message); + throw new Exception(message); + } + response.setResponseMessage(createConfigFirewallPolicy(plainName, json, scope, policyParameters.getRequestID(), userID, passcode, + policyParameters.getRiskLevel(), policyParameters.getRiskType(), String.valueOf(policyParameters.getGuard()), date)); + }else{ + String message = XACMLErrorConstants.ERROR_DATA_ISSUE+ "No Config Body given."; + logger.error(message); + response.setResponseMessage(message); + } + } + //Base + else if(policyParameters.getPolicyConfigType().equals(PolicyConfigType.Base)){ + if(policyParameters.getConfigBody()!=null) { + if(policyParameters.getConfigBodyType()!=null){ + response.setResponseMessage(createConfigPolicy(plainName, policyParameters.getPolicyDescription(), policyParameters.getEcompName(), policyParameters.getConfigName(), + policyParameters.getAttributes().get(AttributeType.MATCHING), policyParameters.getConfigBodyType().toString(), policyParameters.getConfigBody(), scope, policyParameters.getRequestID(), userID, passcode, + policyParameters.getRiskLevel(), policyParameters.getRiskType(), String.valueOf(policyParameters.getGuard()), date)); + } else { + String message = XACMLErrorConstants.ERROR_DATA_ISSUE+ "No Config Body Type given."; + logger.error(message); + response.setResponseMessage(message); + } + } else { + String message = XACMLErrorConstants.ERROR_DATA_ISSUE+ "No Config Body given."; + logger.error(message); + response.setResponseMessage(message); + } + } + //BRMS Raw + else if(policyParameters.getPolicyConfigType().equals(PolicyConfigType.BRMS_RAW)){ + if(policyParameters.getConfigBody()!=null){ + + /*public String createUpdateBRMSRawPolicy(String policyName, String policyDescription, Map dyanamicFieldConfigAttributes, + * String brmsRawBody, String policyScope, Boolean isEdit, UUID requestID)*/ + response.setResponseMessage(createUpdateBRMSRawPolicy(plainName, policyParameters.getPolicyDescription(),policyParameters.getAttributes(), + policyParameters.getConfigBody(),scope, false, + policyParameters.getRequestID(),policyParameters.getRiskLevel(), policyParameters.getRiskType(), String.valueOf(policyParameters.getGuard()), + date)); + }else{ + String message = XACMLErrorConstants.ERROR_DATA_ISSUE+ " No Config Body Present"; + logger.error(message); + throw new Exception(message); + } + } + //BRMS Param + else if(policyParameters.getPolicyConfigType().equals(PolicyConfigType.BRMS_PARAM)){ + if(policyParameters.getConfigBody()!=null){ + + response.setResponseMessage(createUpdateBRMSParamPolicy(plainName, policyParameters.getPolicyDescription(),policyParameters.getAttributes(), + policyParameters.getConfigBody(),scope, false, + policyParameters.getRequestID(),policyParameters.getAttributes(),policyParameters.getRiskLevel(), policyParameters.getRiskType(), + String.valueOf(policyParameters.getGuard()), date)); + }else{ + response.setResponseMessage(createUpdateBRMSParamPolicy(plainName, policyParameters.getPolicyDescription(),policyParameters.getAttributes(), + null,scope, false, + policyParameters.getRequestID(),policyParameters.getAttributes(),policyParameters.getRiskLevel(), policyParameters.getRiskType(), + String.valueOf(policyParameters.getGuard()), date)); + } + } + // Micro Services Policy + else if(policyParameters.getPolicyConfigType().equals(PolicyConfigType.MicroService)){ + if(policyParameters.getConfigBody()!=null){ + JsonObject json = null; + try{ + json = stringToJsonObject(policyParameters.getConfigBody()); + }catch(Exception e){ + String message = XACMLErrorConstants.ERROR_DATA_ISSUE+ " improper JSON object : " + policyParameters.getConfigBody(); + logger.error(message); + throw new Exception(message); + } + //call Micro Services Create API here + response.setResponseMessage(createUpdateMicroServicesPolicy(plainName, json, policyParameters.getEcompName(), + scope, false, policyParameters.getRequestID(),policyParameters.getRiskLevel(), policyParameters.getRiskType(), + String.valueOf(policyParameters.getGuard()), date)); + + }else{ + String message = XACMLErrorConstants.ERROR_DATA_ISSUE+ " No Micro Service or Attributes Config Body Present"; + logger.error(message); + throw new Exception(message); + } + } + // ClosedLoop_Fault Policy + else if(policyParameters.getPolicyConfigType().equals(PolicyConfigType.ClosedLoop_Fault)){ + if(policyParameters.getConfigBody()!=null){ + JsonObject json = null; + try{ + if(validateNONASCIICharactersAndAllowSpaces(policyParameters.getConfigBody())){ + json = stringToJsonObject(policyParameters.getConfigBody()); + } else { + String message = XACMLErrorConstants.ERROR_DATA_ISSUE+ "The ClosedLoop JSON Contains Non ASCII Characters."; + logger.error(message); + response.setResponseCode(400); + response.setResponseMessage(message); + return response; + } + + }catch(Exception e){ + String message = XACMLErrorConstants.ERROR_DATA_ISSUE+ " improper JSON object : " + policyParameters.getConfigBody(); + logger.error(message); + response.setResponseCode(400); + response.setResponseMessage(message); + return response; + + } + //call ClosedLoop_Fault Create API here + response.setResponseMessage(createUpdateClosedLoopPolicy(plainName, json, policyParameters.getPolicyDescription(), + scope, false, policyParameters.getRequestID(),policyParameters.getRiskLevel(), policyParameters.getRiskType(), + String.valueOf(policyParameters.getGuard()), date)); + + }else{ + String message = XACMLErrorConstants.ERROR_DATA_ISSUE+ " No Config Body Present"; + logger.error(message); + response.setResponseMessage(message); + response.setResponseCode(400); + return response; + } + } + // ClosedLoop_PM Policy + else if(policyParameters.getPolicyConfigType().equals(PolicyConfigType.ClosedLoop_PM)){ + if(policyParameters.getConfigBody()!=null){ + JsonObject json = null; + try{ + if(validateNONASCIICharactersAndAllowSpaces(policyParameters.getConfigBody())){ + json = stringToJsonObject(policyParameters.getConfigBody()); + } else { + String message = XACMLErrorConstants.ERROR_DATA_ISSUE+ "The ClosedLoop PM JSON Contains Non ASCII Characters."; + logger.error(message); + response.setResponseMessage(message); + response.setResponseCode(400); + return response; + + } + + }catch(Exception e){ + String message = XACMLErrorConstants.ERROR_DATA_ISSUE+ " improper JSON object : " + policyParameters.getConfigBody(); + logger.error(message); + response.setResponseMessage(message); + response.setResponseCode(400); + return response; + + } + //call ClosedLoop_Fault Create API here + response.setResponseMessage(createUpdateClosedLoopPmPolicy(plainName, json, policyParameters.getPolicyDescription(), + scope, false, policyParameters.getRequestID(),policyParameters.getRiskLevel(), policyParameters.getRiskType(), + String.valueOf(policyParameters.getGuard()), date)); + + }else{ + String message = XACMLErrorConstants.ERROR_DATA_ISSUE+ " No Config Body Present"; + logger.error(message); + response.setResponseMessage(message); + response.setResponseCode(400); + return response; + + } + } + + } else if (policyParameters.getPolicyClass()!=null){ + if(policyParameters.getPolicyClass().equals(PolicyClass.Action)){ + // call Action Create API here. + response.setResponseMessage(createUpdateActionPolicy(plainName, policyParameters.getPolicyDescription(), policyParameters.getAttributes().get(AttributeType.MATCHING), + policyParameters.getDynamicRuleAlgorithmLabels(), policyParameters.getDynamicRuleAlgorithmField1(), policyParameters.getDynamicRuleAlgorithmFunctions(), policyParameters.getDynamicRuleAlgorithmField2(), + policyParameters.getActionPerformer(), policyParameters.getActionAttribute(), scope, false, policyParameters.getRequestID())); + }else if(policyParameters.getPolicyClass().equals(PolicyClass.Decision)){ + // Call Decision Create API here. + if (policyParameters.getAttributes()!=null && policyParameters.getAttributes().containsKey(AttributeType.MATCHING) && policyParameters.getAttributes().containsKey(AttributeType.SETTINGS)) { + response.setResponseMessage(createUpdateDecisionPolicy(plainName, policyParameters.getPolicyDescription(), policyParameters.getEcompName(), policyParameters.getRuleProvider(), + policyParameters.getAttributes().get(AttributeType.MATCHING), policyParameters.getAttributes().get(AttributeType.SETTINGS), policyParameters.getDynamicRuleAlgorithmLabels(), + policyParameters.getDynamicRuleAlgorithmField1(), policyParameters.getDynamicRuleAlgorithmFunctions(), policyParameters.getDynamicRuleAlgorithmField2(), + scope, false, policyParameters.getRequestID())); + }else if(policyParameters.getAttributes()!=null && !policyParameters.getAttributes().containsKey(AttributeType.MATCHING) && policyParameters.getAttributes().containsKey(AttributeType.SETTINGS)){ + response.setResponseMessage(createUpdateDecisionPolicy(plainName, policyParameters.getPolicyDescription(), policyParameters.getEcompName(), policyParameters.getRuleProvider(), + null, policyParameters.getAttributes().get(AttributeType.SETTINGS), policyParameters.getDynamicRuleAlgorithmLabels(), + policyParameters.getDynamicRuleAlgorithmField1(), policyParameters.getDynamicRuleAlgorithmFunctions(), policyParameters.getDynamicRuleAlgorithmField2(), + scope, false, policyParameters.getRequestID())); + }else if(policyParameters.getAttributes()!=null && policyParameters.getAttributes().containsKey(AttributeType.MATCHING) && !policyParameters.getAttributes().containsKey(AttributeType.SETTINGS)){ + response.setResponseMessage(createUpdateDecisionPolicy(plainName, policyParameters.getPolicyDescription(), policyParameters.getEcompName(), policyParameters.getRuleProvider(), + policyParameters.getAttributes().get(AttributeType.MATCHING), null, policyParameters.getDynamicRuleAlgorithmLabels(), + policyParameters.getDynamicRuleAlgorithmField1(), policyParameters.getDynamicRuleAlgorithmFunctions(), policyParameters.getDynamicRuleAlgorithmField2(), + scope, false, policyParameters.getRequestID())); + }else{ + response.setResponseMessage(createUpdateDecisionPolicy(plainName, policyParameters.getPolicyDescription(), policyParameters.getEcompName(), policyParameters.getRuleProvider(), + null, null, policyParameters.getDynamicRuleAlgorithmLabels(), + policyParameters.getDynamicRuleAlgorithmField1(), policyParameters.getDynamicRuleAlgorithmFunctions(), policyParameters.getDynamicRuleAlgorithmField2(), + scope, false, policyParameters.getRequestID())); + } + } + } else { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Class found."); + response.setResponseMessage(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Class found."); + } + response.setResponseCode(responseCode); + return response; + } + + /* + * updatePolicy using policyParameters. + */ + public PolicyChangeResponse updatePolicy(PolicyParameters policyParameters) throws Exception{ + return updatePolicy(policyParameters, userName, pass); + } + + public PolicyChangeResponse updatePolicy(PolicyParameters policyParameters,String userID, String passcode) throws Exception{ + StdPolicyChangeResponse response = new StdPolicyChangeResponse(); + String resource= "updatePolicy"; + if(!checkPermissions(userID, passcode, resource)){ + logger.error(XACMLErrorConstants.ERROR_PERMISSIONS + "You are not allowed to Make this Request. Please contact PolicyAdmin to give access to:" + resource); + response.setResponseMessage(XACMLErrorConstants.ERROR_PERMISSIONS + "You are not allowed to Make this Request. Please contact PolicyAdmin to give access to:" + resource); + response.setResponseCode(401); + return response; + } + String plainName = null; + String scope = null; + String date = "NA"; + if (policyParameters.getTtlDate()!=null){ + date = ConvertDate(policyParameters.getTtlDate()); + } + try{ + if(policyParameters.getPolicyName()!=null){ + plainName = policyParameters.getPolicyName().substring(policyParameters.getPolicyName().lastIndexOf(".")+1, policyParameters.getPolicyName().length()); + scope = policyParameters.getPolicyName().substring(0, policyParameters.getPolicyName().lastIndexOf(".")); + logger.info("Name is "+ plainName +" scope is "+ scope); + } + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Scope given."); + response.setResponseMessage(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Scope given."); + } + if(policyParameters.getPolicyConfigType()!=null){ + // This is Config Class Policy. + //Firewall + if(policyParameters.getPolicyConfigType().equals(PolicyConfigType.Firewall)){ + if(policyParameters.getConfigBody()!=null){ + JsonObject json = null; + try{ + json = stringToJsonObject(policyParameters.getConfigBody()); + }catch(Exception e){ + String message = XACMLErrorConstants.ERROR_DATA_ISSUE+ " improper JSON object : " + policyParameters.getConfigBody(); + logger.error(message); + throw new Exception(message); + } + response.setResponseMessage(updateConfigFirewallPolicy(plainName, json, scope, policyParameters.getRequestID(), userID, passcode,policyParameters.getRiskLevel(), + policyParameters.getRiskType(), String.valueOf(policyParameters.getGuard()), date)); + }else{ + String message = XACMLErrorConstants.ERROR_DATA_ISSUE+ "No Config Body given."; + logger.error(message); + response.setResponseMessage(message); + } + } + //Base Policy + else if(policyParameters.getPolicyConfigType().equals(PolicyConfigType.Base)){ + if(policyParameters.getConfigBody()!=null) { + if(policyParameters.getConfigBodyType()!=null){ + response.setResponseMessage(updateConfigPolicy(plainName, policyParameters.getPolicyDescription(), policyParameters.getEcompName(), policyParameters.getConfigName(), + policyParameters.getAttributes().get(AttributeType.MATCHING), policyParameters.getConfigBodyType().toString(), policyParameters.getConfigBody(), scope, + policyParameters.getRequestID(), userID, passcode, policyParameters.getRiskLevel(), policyParameters.getRiskType(), String.valueOf(policyParameters.getGuard()), date)); + } else { + String message = XACMLErrorConstants.ERROR_DATA_ISSUE+ "No Config Body Type given."; + logger.error(message); + response.setResponseMessage(message); + } + } else { + String message = XACMLErrorConstants.ERROR_DATA_ISSUE+ "No Config Body given."; + logger.error(message); + response.setResponseMessage(message); + } + } + //BRMS Raw + else if(policyParameters.getPolicyConfigType().equals(PolicyConfigType.BRMS_RAW)){ + if(policyParameters.getConfigBody()!=null){ + /*public String createUpdateBRMSRawPolicy(String policyName, String policyDescription, Map dyanamicFieldConfigAttributes, + * String brmsRawBody, String policyScope, Boolean isEdit, UUID requestID)*/ + response.setResponseMessage(createUpdateBRMSRawPolicy(plainName, policyParameters.getPolicyDescription(),policyParameters.getAttributes(), + policyParameters.getConfigBody(),scope, true, + policyParameters.getRequestID(),policyParameters.getRiskLevel(), policyParameters.getRiskType(), String.valueOf(policyParameters.getGuard()), date)); + }else{ + String message = XACMLErrorConstants.ERROR_DATA_ISSUE+ " No Config Body Present"; + logger.error(message); + throw new Exception(message); + } + } + //BRMS Param + else if(policyParameters.getPolicyConfigType().equals(PolicyConfigType.BRMS_PARAM)){ + if(policyParameters.getConfigBody()!=null){ + + /* public String createUpdateBRMSParamPolicy(String policyName, String policyDescription, Map> dyanamicFieldConfigAttributes, + String brmsRawBody, String policyScope, Boolean isEdit, + UUID requestID,Map drlRuleAndUIParams)*/ + response.setResponseMessage(createUpdateBRMSParamPolicy(plainName, policyParameters.getPolicyDescription(),policyParameters.getAttributes(), + policyParameters.getConfigBody(),scope, true, + policyParameters.getRequestID(),policyParameters.getAttributes(),policyParameters.getRiskLevel(), policyParameters.getRiskType(), String.valueOf(policyParameters.getGuard()), date)); + }else{ + response.setResponseMessage(createUpdateBRMSParamPolicy(plainName, policyParameters.getPolicyDescription(),policyParameters.getAttributes(), + null,scope, true, + policyParameters.getRequestID(),policyParameters.getAttributes(),policyParameters.getRiskLevel(), policyParameters.getRiskType(), String.valueOf(policyParameters.getGuard()), date)); + } + } + // Micro Services Policy + else if(policyParameters.getPolicyConfigType().equals(PolicyConfigType.MicroService)){ + if(policyParameters.getConfigBody()!=null){ + JsonObject json = null; + try{ + json = stringToJsonObject(policyParameters.getConfigBody()); + }catch(Exception e){ + String message = XACMLErrorConstants.ERROR_DATA_ISSUE+ " improper JSON object : " + policyParameters.getConfigBody(); + logger.error(message); + throw new Exception(message); + } + //call Micro Services Create API here + response.setResponseMessage(createUpdateMicroServicesPolicy(plainName, json, policyParameters.getEcompName(), + scope, true, policyParameters.getRequestID(),policyParameters.getRiskLevel(), policyParameters.getRiskType(), String.valueOf(policyParameters.getGuard()), date)); + + }else{ + String message = XACMLErrorConstants.ERROR_DATA_ISSUE+ " No Micro Service or Attributes Config Body Present"; + logger.error(message); + throw new Exception(message); + } + } + // ClosedLoop_Fault Policy + else if(policyParameters.getPolicyConfigType().equals(PolicyConfigType.ClosedLoop_Fault)){ + if(policyParameters.getConfigBody()!=null){ + JsonObject json = null; + try{ + if(validateNONASCIICharactersAndAllowSpaces(policyParameters.getConfigBody())){ + json = stringToJsonObject(policyParameters.getConfigBody()); + } else { + String message = XACMLErrorConstants.ERROR_DATA_ISSUE+ "The ClosedLoop JSON Contains Non ASCII Characters."; + logger.error(message); + response.setResponseMessage(message); + return response; + } + + }catch(Exception e){ + String message = XACMLErrorConstants.ERROR_DATA_ISSUE+ " improper JSON object : " + policyParameters.getConfigBody(); + logger.error(message); + response.setResponseMessage(message); + return response; + } + //call ClosedLoop_Fault Create API here + response.setResponseMessage(createUpdateClosedLoopPolicy(plainName, json, policyParameters.getPolicyDescription(), + scope, true, policyParameters.getRequestID(),policyParameters.getRiskLevel(), policyParameters.getRiskType(), String.valueOf(policyParameters.getGuard()), date)); + + }else{ + String message = XACMLErrorConstants.ERROR_DATA_ISSUE+ " No Config Body Present"; + logger.error(message); + response.setResponseMessage(message); + } + } + // ClosedLoop_PM Policy + else if(policyParameters.getPolicyConfigType().equals(PolicyConfigType.ClosedLoop_PM)){ + if(policyParameters.getConfigBody()!=null){ + JsonObject json = null; + try{ + if(validateNONASCIICharactersAndAllowSpaces(policyParameters.getConfigBody())){ + json = stringToJsonObject(policyParameters.getConfigBody()); + } else { + String message = XACMLErrorConstants.ERROR_DATA_ISSUE+ "The ClosedLoop PM JSON Contains Non ASCII Characters."; + logger.error(message); + response.setResponseMessage(message); + return response; + } + + }catch(Exception e){ + String message = XACMLErrorConstants.ERROR_DATA_ISSUE+ " improper JSON object : " + policyParameters.getConfigBody(); + logger.error(message); + response.setResponseMessage(message); + return response; + } + //call ClosedLoop_Fault Create API here + response.setResponseMessage(createUpdateClosedLoopPmPolicy(plainName, json, policyParameters.getPolicyDescription(), + scope, true, policyParameters.getRequestID(),policyParameters.getRiskLevel(), policyParameters.getRiskType(), + String.valueOf(policyParameters.getGuard()), date)); + + }else{ + String message = XACMLErrorConstants.ERROR_DATA_ISSUE+ " No Config Body Present"; + logger.error(message); + response.setResponseMessage(message); + } + } + + }else{ + + if(policyParameters.getPolicyClass().equals(PolicyClass.Action)){ + // call Action Update API here. + response.setResponseMessage(createUpdateActionPolicy(plainName, policyParameters.getPolicyDescription(), policyParameters.getAttributes().get(AttributeType.MATCHING), + policyParameters.getDynamicRuleAlgorithmLabels(), policyParameters.getDynamicRuleAlgorithmField1(), policyParameters.getDynamicRuleAlgorithmFunctions(), policyParameters.getDynamicRuleAlgorithmField2(), + policyParameters.getActionPerformer(), policyParameters.getActionAttribute(), scope, true, policyParameters.getRequestID())); + + }else if(policyParameters.getPolicyClass().equals(PolicyClass.Decision)){ + // Call Decision Create API here. + if (policyParameters.getAttributes()!=null && policyParameters.getAttributes().containsKey(AttributeType.MATCHING) && policyParameters.getAttributes().containsKey(AttributeType.SETTINGS)) { + response.setResponseMessage(createUpdateDecisionPolicy(plainName, policyParameters.getPolicyDescription(), policyParameters.getEcompName(), policyParameters.getRuleProvider(), + policyParameters.getAttributes().get(AttributeType.MATCHING), policyParameters.getAttributes().get(AttributeType.SETTINGS), policyParameters.getDynamicRuleAlgorithmLabels(), + policyParameters.getDynamicRuleAlgorithmField1(), policyParameters.getDynamicRuleAlgorithmFunctions(), policyParameters.getDynamicRuleAlgorithmField2(), + scope, true, policyParameters.getRequestID())); + }else if(policyParameters.getAttributes()!=null && !policyParameters.getAttributes().containsKey(AttributeType.MATCHING) && policyParameters.getAttributes().containsKey(AttributeType.SETTINGS)){ + response.setResponseMessage(createUpdateDecisionPolicy(plainName, policyParameters.getPolicyDescription(), policyParameters.getEcompName(), policyParameters.getRuleProvider(), + null, policyParameters.getAttributes().get(AttributeType.SETTINGS), policyParameters.getDynamicRuleAlgorithmLabels(), + policyParameters.getDynamicRuleAlgorithmField1(), policyParameters.getDynamicRuleAlgorithmFunctions(), policyParameters.getDynamicRuleAlgorithmField2(), + scope, true, policyParameters.getRequestID())); + }else if(policyParameters.getAttributes()!=null && policyParameters.getAttributes().containsKey(AttributeType.MATCHING) && !policyParameters.getAttributes().containsKey(AttributeType.SETTINGS)){ + response.setResponseMessage(createUpdateDecisionPolicy(plainName, policyParameters.getPolicyDescription(), policyParameters.getEcompName(), policyParameters.getRuleProvider(), + policyParameters.getAttributes().get(AttributeType.MATCHING), null, policyParameters.getDynamicRuleAlgorithmLabels(), + policyParameters.getDynamicRuleAlgorithmField1(), policyParameters.getDynamicRuleAlgorithmFunctions(), policyParameters.getDynamicRuleAlgorithmField2(), + scope, true, policyParameters.getRequestID())); + }else{ + response.setResponseMessage(createUpdateDecisionPolicy(plainName, policyParameters.getPolicyDescription(), policyParameters.getEcompName(), policyParameters.getRuleProvider(), + null, null, policyParameters.getDynamicRuleAlgorithmLabels(), + policyParameters.getDynamicRuleAlgorithmField1(), policyParameters.getDynamicRuleAlgorithmFunctions(), policyParameters.getDynamicRuleAlgorithmField2(), + scope, true, policyParameters.getRequestID())); + } + } + } + response.setResponseCode(responseCode); + return response; + } + + public DecisionResponse policyDecide(String eCOMPComponentName, + Map decisionAttributes, UUID requestID, String userID, String passcode) + throws PolicyDecisionException { + String resource= "getDecision"; + if(!checkPermissions(userID, passcode, resource)){ + logger.error(XACMLErrorConstants.ERROR_PERMISSIONS + "You are not allowed to Make this Request. Please contact PolicyAdmin to give access to:" + resource); + throw new PolicyDecisionException(XACMLErrorConstants.ERROR_PERMISSIONS + "You are not allowed to Make this Request. Please contact PolicyAdmin to give access to:" + resource); + } + DecisionResponse policyDecision; + if (eCOMPComponentName == null || eCOMPComponentName.isEmpty()) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No eCOMPComponentName given : " + eCOMPComponentName); + throw new PolicyDecisionException(XACMLErrorConstants.ERROR_DATA_ISSUE + "No eCOMPComponentName given."); + } + if (decisionAttributes != null && !decisionAttributes.isEmpty()) { + JsonArrayBuilder resourceArray = Json.createArrayBuilder(); + for (String key : decisionAttributes.keySet()) { + if (key.isEmpty()) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Cannot have an Empty Key"); + throw new PolicyDecisionException(XACMLErrorConstants.ERROR_DATA_ISSUE + "Cannot have an empty Key"); + } + JsonObjectBuilder resourceBuilder = Json.createObjectBuilder(); + if (decisionAttributes.get(key).matches("[0-9]+")) { + int val = Integer.parseInt(decisionAttributes.get(key)); + resourceBuilder.add("Value", val); + } else { + resourceBuilder.add("Value", decisionAttributes.get(key)); + } + resourceBuilder.add("AttributeId", key); + resourceArray.add(resourceBuilder); + } + JsonObject model = Json + .createObjectBuilder() + .add("Request", + Json.createObjectBuilder() + .add("AccessSubject", + Json.createObjectBuilder() + .add("Attribute", + Json.createObjectBuilder() + .add("Value", + eCOMPComponentName) + .add("AttributeId", + "ECOMPName"))) + .add("Resource", + Json.createObjectBuilder().add( + "Attribute", resourceArray)) + .add("Action", + Json.createObjectBuilder() + .add("Attribute", + Json.createObjectBuilder() + .add("Value", + "DECIDE") + .add("AttributeId", + "urn:oasis:names:tc:xacml:1.0:action:action-id")))) + .build(); + try { + decide = true; + policyDecision = decisionResult(generateRequest(model + .toString(), requestID)); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e); + decide = false; + throw new PolicyDecisionException(e); + } + } else { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Decision Attributes Given. "); + throw new PolicyDecisionException(XACMLErrorConstants.ERROR_DATA_ISSUE +"No DecisionAttributes Given."); + } + decide = false; + return policyDecision; + } + + public Collection configPolicyName(String policyName, UUID requestID, String userID, String passcode) + throws PolicyConfigException { + String resource= "getConfigByPolicyName"; + if(!checkPermissions(userID, passcode, resource)){ + logger.error(XACMLErrorConstants.ERROR_PERMISSIONS + "You are not allowed to Make this Request. Please contact PolicyAdmin to give access to:" + resource); + throw new PolicyConfigException(XACMLErrorConstants.ERROR_PERMISSIONS + "You are not allowed to Make this Request. Please contact PolicyAdmin to give access to:" + resource); + } + Collection policyConfig = null; + if (policyName == null || policyName.isEmpty()) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE+ "No Policy FileName specified!! : " + policyName); + throw new PolicyConfigException(XACMLErrorConstants.ERROR_DATA_ISSUE+"No Policy FileName specified!!"); + } + if(policyName!= null && !policyName.trim().equals("") && !policyName.endsWith("xml")){ + policyName = policyName + ".[\\d].*"; + } + JsonObject model = Json + .createObjectBuilder() + .add("Request", + Json.createObjectBuilder() + .add("AccessSubject", + Json.createObjectBuilder().add( + "Attribute", + Json.createObjectBuilder() + .add("Value", + policyName) + .add("AttributeId", + "PolicyName"))) + .add("Action", + Json.createObjectBuilder() + .add("Attribute", + Json.createObjectBuilder() + .add("Value", + "ACCESS") + .add("AttributeId", + "urn:oasis:names:tc:xacml:1.0:action:action-id"))) + .add("Resource", + Json.createObjectBuilder() + .add("Attribute", + Json.createObjectBuilder() + .add("Value", + "Config") + .add("AttributeId", + "urn:oasis:names:tc:xacml:1.0:resource:resource-id")))) + .build(); + try { + policyConfig = configResult(generateRequest(model.toString(), requestID)); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e); + throw new PolicyConfigException(XACMLErrorConstants.ERROR_DATA_ISSUE +e); + } + return policyConfig; + } + + public Collection config(String eCOMPComponentName, UUID requestID, String userID, String passcode) + throws PolicyConfigException { + String resource= "getConfig"; + if(!checkPermissions(userID, passcode, resource)){ + logger.error(XACMLErrorConstants.ERROR_PERMISSIONS + "You are not allowed to Make this Request. Please contact PolicyAdmin to give access to:" + resource); + throw new PolicyConfigException(XACMLErrorConstants.ERROR_PERMISSIONS + "You are not allowed to Make this Request. Please contact PolicyAdmin to give access to:" + resource); + } + Collection policyConfig = null; + if (eCOMPComponentName == null || eCOMPComponentName.isEmpty()) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No eCOMPComponentName given : " + eCOMPComponentName); + throw new PolicyConfigException(XACMLErrorConstants.ERROR_DATA_ISSUE + "No eCOMPComponentName given."); + } + JsonObject model = Json + .createObjectBuilder() + .add("Request", + Json.createObjectBuilder() + .add("AccessSubject", + Json.createObjectBuilder() + .add("Attribute", + Json.createObjectBuilder() + .add("Value", + eCOMPComponentName) + .add("AttributeId", + "ECOMPName"))) + .add("Action", + Json.createObjectBuilder() + .add("Attribute", + Json.createObjectBuilder() + .add("Value", + "ACCESS") + .add("AttributeId", + "urn:oasis:names:tc:xacml:1.0:action:action-id"))) + .add("Resource", + Json.createObjectBuilder() + .add("Attribute", + Json.createObjectBuilder() + .add("Value", + "Config") + .add("AttributeId", + "urn:oasis:names:tc:xacml:1.0:resource:resource-id")))) + .build(); + try { + policyConfig = configResult(generateRequest(model.toString(), requestID)); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e); + throw new PolicyConfigException(XACMLErrorConstants.ERROR_DATA_ISSUE +e); + } + return policyConfig; + } + + public Collection config(String eCOMPComponentName, + String configName, UUID requestID, String userID, String passcode) throws PolicyConfigException { + String resource= "getConfig"; + if(!checkPermissions(userID, passcode, resource)){ + logger.error(XACMLErrorConstants.ERROR_PERMISSIONS + "You are not allowed to Make this Request. Please contact PolicyAdmin to give access to:" + resource); + throw new PolicyConfigException(XACMLErrorConstants.ERROR_PERMISSIONS + "You are not allowed to Make this Request. Please contact PolicyAdmin to give access to:" + resource); + } + Collection policyConfig = null; + if (eCOMPComponentName == null || eCOMPComponentName.isEmpty()) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No eCOMPComponentName given : " + eCOMPComponentName); + throw new PolicyConfigException(XACMLErrorConstants.ERROR_DATA_ISSUE + "No eCOMPComponentName given."); + } + if (configName == null || configName.isEmpty()) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No configName given : " + configName); + throw new PolicyConfigException(XACMLErrorConstants.ERROR_DATA_ISSUE +"No configName given."); + } + JsonObject model = Json + .createObjectBuilder() + .add("Request", + Json.createObjectBuilder() + .add("AccessSubject", + Json.createObjectBuilder() + .add("Attribute", + Json.createArrayBuilder() + .add(Json + .createObjectBuilder() + .add("Value", + eCOMPComponentName) + .add("AttributeId", + "ECOMPName")) + .add(Json + .createObjectBuilder() + .add("Value", + configName) + .add("AttributeId", + "ConfigName")))) + .add("Action", + Json.createObjectBuilder() + .add("Attribute", + Json.createObjectBuilder() + .add("Value", + "ACCESS") + .add("AttributeId", + "urn:oasis:names:tc:xacml:1.0:action:action-id"))) + .add("Resource", + Json.createObjectBuilder() + .add("Attribute", + Json.createObjectBuilder() + .add("Value", + "Config") + .add("AttributeId", + "urn:oasis:names:tc:xacml:1.0:resource:resource-id")))) + .build(); + try { + policyConfig = configResult(generateRequest(model.toString(), requestID)); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e); + throw new PolicyConfigException(XACMLErrorConstants.ERROR_DATA_ISSUE +e); + } + + return policyConfig; + } + + public Collection config(String eCOMPComponentName, + String configName, Map configAttributes, UUID requestID, String userID, String passcode) + throws PolicyConfigException { + String resource= "getConfig"; + if(!checkPermissions(userID, passcode, resource)){ + logger.error(XACMLErrorConstants.ERROR_PERMISSIONS + "You are not allowed to Make this Request. Please contact PolicyAdmin to give access to:" + resource); + throw new PolicyConfigException(XACMLErrorConstants.ERROR_PERMISSIONS + "You are not allowed to Make this Request. Please contact PolicyAdmin to give access to:" + resource); + } + Collection policyConfig = null; + if (eCOMPComponentName == null || eCOMPComponentName.isEmpty()) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No eCOMPComponentName given : " + eCOMPComponentName); + throw new PolicyConfigException(XACMLErrorConstants.ERROR_DATA_ISSUE + "No eCOMPComponentName given."); + } + if (configName == null || configName.isEmpty()) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No configName given : " + configName); + throw new PolicyConfigException(XACMLErrorConstants.ERROR_DATA_ISSUE +"No configName given."); + } + if (configAttributes != null && !configAttributes.isEmpty()) { + if(!configAttributes.containsKey("RiskType")){ + configAttributes.put("RiskType", ".*"); + } + if(!configAttributes.containsKey("RiskLevel")){ + configAttributes.put("RiskLevel", ".*"); + } + if(!configAttributes.containsKey("guard")){ + configAttributes.put("guard", ".*"); + } + if(!configAttributes.containsKey("TTLDate")){ + configAttributes.put("TTLDate", ".*"); + } + }else{ + // ConfigAttributes is Null. So add basic values. + configAttributes = new HashMap(); + configAttributes.put("RiskType", ".*"); + configAttributes.put("RiskLevel", ".*"); + configAttributes.put("guard", ".*"); + configAttributes.put("TTLDate", ".*"); + } + JsonArrayBuilder resourceArray = Json.createArrayBuilder(); + for (String key : configAttributes.keySet()) { + if (key.isEmpty()) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Cannot have an empty Key"); + throw new PolicyConfigException(XACMLErrorConstants.ERROR_DATA_ISSUE +"Cannot have an empty Key"); + } + JsonObjectBuilder resourceBuilder = Json.createObjectBuilder(); + /*if (configAttributes.get(key).matches("[0-9]+")) { + int val = Integer.parseInt(configAttributes.get(key)); + resourceBuilder.add("Value", val); + } else {*/ + resourceBuilder.add("Value", configAttributes.get(key)); + resourceBuilder.add("AttributeId", key); + resourceArray.add(resourceBuilder); + } + JsonObject model = Json + .createObjectBuilder() + .add("Request", + Json.createObjectBuilder() + .add("AccessSubject", + Json.createObjectBuilder() + .add("Attribute", + Json.createArrayBuilder() + .add(Json + .createObjectBuilder() + .add("Value", + eCOMPComponentName) + .add("AttributeId", + "ECOMPName")) + .add(Json + .createObjectBuilder() + .add("Value", + configName) + .add("AttributeId", + "ConfigName")))) + .add("Action", + Json.createObjectBuilder() + .add("Attribute", + Json.createObjectBuilder() + .add("Value", + "ACCESS") + .add("AttributeId", + "urn:oasis:names:tc:xacml:1.0:action:action-id"))) + .add("Resource", + Json.createObjectBuilder() + .add("Attribute", + resourceArray + .add(Json.createObjectBuilder() + .add("Value", + "Config") + .add("AttributeId", + "urn:oasis:names:tc:xacml:1.0:resource:resource-id"))))) + .build(); + try { + policyConfig = configResult(generateRequest(model.toString(), requestID)); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e); + throw new PolicyConfigException(XACMLErrorConstants.ERROR_DATA_ISSUE +e); + } + return policyConfig; + } + + public Collection configRequest(ConfigRequestParameters configRequestParameters, String userID, String passcode) throws PolicyConfigException{ + String resource= "getConfig"; + if(!checkPermissions(userID, passcode, resource)){ + logger.error(XACMLErrorConstants.ERROR_PERMISSIONS + "You are not allowed to Make this Request. Please contact PolicyAdmin to give access to:" + resource); + throw new PolicyConfigException(XACMLErrorConstants.ERROR_PERMISSIONS + "You are not allowed to Make this Request. Please contact PolicyAdmin to give access to:" + resource); + } + Collection policyConfig = null; + unique = false; + if(configRequestParameters==null){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No config Request Parameters given "); + throw new PolicyConfigException(XACMLErrorConstants.ERROR_DATA_ISSUE + "No config Request Parameters given."); + } + if(configRequestParameters.getEcompName() == null && configRequestParameters.getPolicyName() == null){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Cannot proceed without eCOMPComponentName or PolicyName"); + throw new PolicyConfigException(XACMLErrorConstants.ERROR_DATA_ISSUE + "No eCOMPComponentName or PolicyName given."); + } + String policyName = configRequestParameters.getPolicyName(); + if(policyName!= null && !policyName.trim().equals("") && !policyName.endsWith("xml")){ + policyName = policyName + ".[\\d].*"; + } + JsonArrayBuilder subjectArray = Json.createArrayBuilder(); + JsonArrayBuilder resourceArray = Json.createArrayBuilder(); + if(configRequestParameters.getPolicyName()!=null){ + JsonObjectBuilder subjectBuilder = Json.createObjectBuilder(); + subjectBuilder.add("Value", policyName); + subjectBuilder.add("AttributeId", "PolicyName"); + subjectArray.add(subjectBuilder); + }else{ + logger.info("PolicyName values are not given. "); + } + if(configRequestParameters.getEcompName()!=null){ + JsonObjectBuilder subjectBuilder = Json.createObjectBuilder(); + subjectBuilder.add("Value", configRequestParameters.getEcompName()); + subjectBuilder.add("AttributeId", "ECOMPName"); + subjectArray.add(subjectBuilder); + if(configRequestParameters.getConfigName()!=null){ + subjectBuilder = Json.createObjectBuilder(); + subjectBuilder.add("Value", configRequestParameters.getConfigName()); + subjectBuilder.add("AttributeId", "ConfigName"); + subjectArray.add(subjectBuilder); + Map configAttributes = configRequestParameters.getConfigAttributes(); + if (configAttributes != null && !configAttributes.isEmpty()) { + if(!configAttributes.containsKey("RiskType")){ + configAttributes.put("RiskType", ".*"); + } + if(!configAttributes.containsKey("RiskLevel")){ + configAttributes.put("RiskLevel", ".*"); + } + if(!configAttributes.containsKey("guard")){ + configAttributes.put("guard", ".*"); + } + if(!configAttributes.containsKey("TTLDate")){ + configAttributes.put("TTLDate", ".*"); + } + }else{ + // ConfigAttributes is Null. So add basic values. + configAttributes = new HashMap(); + configAttributes.put("RiskType", ".*"); + configAttributes.put("RiskLevel", ".*"); + configAttributes.put("guard", ".*"); + configAttributes.put("TTLDate", ".*"); + } + for (String key : configAttributes.keySet()) { + if (key.isEmpty()) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Cannot have an empty Key"); + throw new PolicyConfigException(XACMLErrorConstants.ERROR_DATA_ISSUE +"Cannot have an empty Key"); + } + JsonObjectBuilder resourceBuilder = Json.createObjectBuilder(); + /*if (configAttributes.get(key).matches("[0-9]+")) { + int val = Integer.parseInt(configAttributes.get(key)); + resourceBuilder.add("Value", val); + } else {*/ + resourceBuilder.add("Value", configAttributes.get(key)); + resourceBuilder.add("AttributeId", key); + resourceArray.add(resourceBuilder); + } + }else{ + logger.info("Config Name is not given. "); + } + }else{ + logger.info("Ecomp Name is not given. "); + } + JsonObject model = Json + .createObjectBuilder() + .add("Request", + Json.createObjectBuilder() + .add("AccessSubject", + Json.createObjectBuilder() + .add("Attribute",subjectArray)) + .add("Action", + Json.createObjectBuilder() + .add("Attribute", + Json.createObjectBuilder() + .add("Value", + "ACCESS") + .add("AttributeId", + "urn:oasis:names:tc:xacml:1.0:action:action-id"))) + .add("Resource", + Json.createObjectBuilder() + .add("Attribute", + resourceArray + .add(Json + .createObjectBuilder() + .add("Value", + "Config") + .add("AttributeId", + "urn:oasis:names:tc:xacml:1.0:resource:resource-id"))))) + .build(); + logger.debug("Generated JSON Request is: " + model.toString()); + if(configRequestParameters.getUnique()){ + logger.info("Requested for Unique Result only. "); + unique = true; + } + try { + policyConfig = configResult(generateRequest(model.toString(), configRequestParameters.getRequestID())); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e); + throw new PolicyConfigException(XACMLErrorConstants.ERROR_DATA_ISSUE +e); + } + return policyConfig; + } + + public Collection listConfigRequest(ConfigRequestParameters listRequestParameters, String userID, String passcode) throws PolicyConfigException{ + String resource= "listConfig"; + if(!checkPermissions(userID, passcode, resource)){ + logger.error(XACMLErrorConstants.ERROR_PERMISSIONS + "You are not allowed to Make this Request. Please contact PolicyAdmin to give access to:" + resource); + throw new PolicyConfigException(XACMLErrorConstants.ERROR_PERMISSIONS + "You are not allowed to Make this Request. Please contact PolicyAdmin to give access to:" + resource); + } + Collection policyConfig = null; + Collection policyList = new ArrayList(); + + unique = false; + if(listRequestParameters==null){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Request Parameters given "); + throw new PolicyConfigException(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Request Parameters given."); + } + + if (junit){ + policyList.add("Policy Name: listConfigTest"); + return policyList; + } + + String policyName = listRequestParameters.getPolicyName(); + if(policyName!= null && !policyName.trim().equals("") && !policyName.endsWith("xml")){ + policyName = policyName + ".[\\d].*"; + } + JsonArrayBuilder subjectArray = Json.createArrayBuilder(); + JsonArrayBuilder resourceArray = Json.createArrayBuilder(); + if(listRequestParameters.getPolicyName()!=null){ + JsonObjectBuilder subjectBuilder = Json.createObjectBuilder(); + subjectBuilder.add("Value", policyName); + subjectBuilder.add("AttributeId", "PolicyName"); + subjectArray.add(subjectBuilder); + }else{ + logger.info("PolicyName values are not given. "); + } + if(listRequestParameters.getEcompName()!=null){ + JsonObjectBuilder subjectBuilder = Json.createObjectBuilder(); + subjectBuilder.add("Value", listRequestParameters.getEcompName()); + subjectBuilder.add("AttributeId", "ECOMPName"); + subjectArray.add(subjectBuilder); + if(listRequestParameters.getConfigName()!=null){ + subjectBuilder = Json.createObjectBuilder(); + subjectBuilder.add("Value", listRequestParameters.getConfigName()); + subjectBuilder.add("AttributeId", "ConfigName"); + subjectArray.add(subjectBuilder); + Map configAttributes = listRequestParameters.getConfigAttributes(); + if (configAttributes != null && !configAttributes.isEmpty()) { + if(!configAttributes.containsKey("RiskType")){ + configAttributes.put("RiskType", ".*"); + } + if(!configAttributes.containsKey("RiskLevel")){ + configAttributes.put("RiskLevel", ".*"); + } + if(!configAttributes.containsKey("guard")){ + configAttributes.put("guard", ".*"); + } + if(!configAttributes.containsKey("TTLDate")){ + configAttributes.put("TTLDate", ".*"); + } + }else{ + // ConfigAttributes is Null. So add basic values. + configAttributes = new HashMap(); + configAttributes.put("RiskType", ".*"); + configAttributes.put("RiskLevel", ".*"); + configAttributes.put("guard", ".*"); + configAttributes.put("TTLDate", ".*"); + } + for (String key : configAttributes.keySet()) { + if (key.isEmpty()) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Cannot have an empty Key"); + throw new PolicyConfigException(XACMLErrorConstants.ERROR_DATA_ISSUE +"Cannot have an empty Key"); + } + JsonObjectBuilder resourceBuilder = Json.createObjectBuilder(); + /*if (configAttributes.get(key).matches("[0-9]+")) { + int val = Integer.parseInt(configAttributes.get(key)); + resourceBuilder.add("Value", val); + } else {*/ + resourceBuilder.add("Value", configAttributes.get(key)); + resourceBuilder.add("AttributeId", key); + resourceArray.add(resourceBuilder); + } + }else{ + logger.info("Config Name is not given. "); + } + }else{ + logger.info("Ecomp Name is not given. "); + } + JsonObject model = Json + .createObjectBuilder() + .add("Request", + Json.createObjectBuilder() + .add("AccessSubject", + Json.createObjectBuilder() + .add("Attribute",subjectArray)) + .add("Action", + Json.createObjectBuilder() + .add("Attribute", + Json.createObjectBuilder() + .add("Value", + "ACCESS") + .add("AttributeId", + "urn:oasis:names:tc:xacml:1.0:action:action-id"))) + .add("Resource", + Json.createObjectBuilder() + .add("Attribute", + resourceArray + .add(Json + .createObjectBuilder() + .add("Value", + "Config") + .add("AttributeId", + "urn:oasis:names:tc:xacml:1.0:resource:resource-id"))))) + .build(); + logger.debug("Generated JSON Request is: " + model.toString()); + if(listRequestParameters.getUnique()){ + logger.info("Requested for Unique Result only. "); + unique = true; + } + try { + policyConfig = configResult(generateRequest(model.toString(), listRequestParameters.getRequestID())); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e); + throw new PolicyConfigException(XACMLErrorConstants.ERROR_DATA_ISSUE +e); + } + for(PolicyConfig policy : policyConfig){ + if(policy.getPolicyConfigMessage()!=null && policy.getPolicyConfigMessage().contains("PE300")){ + policyList.add(policy.getPolicyConfigMessage()); + } else { + policyList.add("Policy Name: " + policy.getPolicyName()); + } + } + return policyList; + } + + + + public Collection event(Map eventAttributes, UUID requestID, String userID, String passcode) + throws PolicyEventException { + String resource= "sendEvent"; + if(!checkPermissions(userID, passcode, resource)){ + logger.error(XACMLErrorConstants.ERROR_PERMISSIONS + "You are not allowed to Make this Request. Please contact PolicyAdmin to give access to:" + resource); + throw new PolicyEventException(XACMLErrorConstants.ERROR_PERMISSIONS + "You are not allowed to Make this Request. Please contact PolicyAdmin to give access to:" + resource); + } + Collection policyResponse = null; + if (eventAttributes != null && !eventAttributes.isEmpty()) { + JsonArrayBuilder resourceArray = Json.createArrayBuilder(); + for (String key : eventAttributes.keySet()) { + if (key.isEmpty()) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Cannot have an Empty Key"); + throw new PolicyEventException(XACMLErrorConstants.ERROR_DATA_ISSUE +"Cannot have an empty Key"); + } + JsonObjectBuilder resourceBuilder = Json.createObjectBuilder(); + if (eventAttributes.get(key).matches("[0-9]+")) { + int val = Integer.parseInt(eventAttributes.get(key)); + resourceBuilder.add("Value", val); + } else { + resourceBuilder.add("Value", eventAttributes.get(key)); + } + resourceBuilder.add("AttributeId", key); + resourceArray.add(resourceBuilder); + } + JsonObject model = Json + .createObjectBuilder() + .add("Request", + Json.createObjectBuilder().add( + "Resource", + Json.createObjectBuilder().add("Attribute", + resourceArray))).build(); + // Removed Part can be Useful in Future. + /* + * .add("AccessSubject",Json.createObjectBuilder() .add("Attribute", + * subjectArray)) .add("Action", Json.createObjectBuilder() + * .add("Attribute", actionArray)) + */ + // System.out.println(model.toString()); + try { + // StdPolicyResponse stdPolicyResponse = + // generateRequest(model.toString()); + // stdPolicyResponse.setRequestAttributes(eventAttributes); + policyResponse = eventResult(generateRequest(model.toString(), requestID), + eventAttributes); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e); + throw new PolicyEventException(XACMLErrorConstants.ERROR_DATA_ISSUE +e); + } + } else { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No event Attributes Given. "); + throw new PolicyEventException(XACMLErrorConstants.ERROR_DATA_ISSUE +"No EventAttributes Given."); + } + return policyResponse; + } + + private Collection generateRequest(String Json, UUID requestID) throws Exception { + Collection results = null; + + Response response = null; + // Create Request. We need XACML API here. + try { + Request request = JSONRequest.load(Json); + String jRequest = JSONRequest.toString(request); + + // Call the PDP + logger.debug("--- Generating Request: ---\n" + jRequest ); + response = callPDP(new ByteArrayInputStream(jRequest.getBytes()), requestID); + + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_SCHEMA_INVALID + e); + StdStatus stdStatus = new StdStatus(); + results = new HashSet(); + stdStatus.setStatus("Unable to Call PDP. Error with the URL", + PolicyResponseStatus.NO_ACTION_REQUIRED, + PolicyConfigStatus.CONFIG_NOT_FOUND); + results.add(stdStatus); + throw new Exception(e); + } + + if(this.UEBThread){ + this.UEBThread = registerUEBThread.isAlive(); + } + if (response != null) { + results = checkResponse(response); + // TODO Starting Auto Client Here. + if (notificationType.get(0).equals("ueb") && !this.UEBThread){ + this.UEBClientThread = new AutoClientUEB(pdps.get(0), uebURLList); + this.registerUEBThread = new Thread(this.UEBClientThread); + this.registerUEBThread.start(); + this.UEBThread = true; + + }else { + if(AutoClientEnd.getURL()==null){ + AutoClientEnd.start(pdps.get(0)); + }else if(AutoClientEnd.getURL()!=pdps.get(0)){ + AutoClientEnd.stop(); + AutoClientEnd.start(pdps.get(0)); + } + } + } else { + logger.debug("No Response Received from PDP"); + StdStatus stdStatus = new StdStatus(); + results = new HashSet(); + stdStatus.setStatus("No Response Received", + PolicyResponseStatus.NO_ACTION_REQUIRED, + PolicyConfigStatus.CONFIG_NOT_FOUND); + results.add(stdStatus); + } + + return results; + } + + private Response callPDP(ByteArrayInputStream input, UUID requestID) throws Exception { + Response response = null; + HttpURLConnection connection = null; + responseCode = 0; + // Checking for the available PDPs is done during the first Request and + // the List is going to have the connected PDP as first element. + // This makes it Real-Time to change the list depending on their + // availability. + if (pdps == null || pdps.isEmpty()) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "PDPs List is Empty."); + throw new Exception(XACMLErrorConstants.ERROR_DATA_ISSUE +"PDPs List is empty."); + } else { + int pdpsCount = 0; + boolean connected = false; + while (pdpsCount < pdps.size()) { + input.reset(); + try { + String urlValue = pdps.get(0); + URL url = new URL(urlValue); + logger.debug("--- Sending Request to PDP : "+ url.toString() + " ---"); + connection = (HttpURLConnection) url.openConnection(); + // Setting Content-Type + connection.setRequestProperty("Content-Type","application/json"); + // Adding Authorization + connection.setRequestProperty("Authorization", "Basic " + encoding.get(0)); + // Adding Environment. + connection.setRequestProperty("Environment", environment); + // Adding RequestID + if (requestID == null) { + requestID = UUID.randomUUID(); + logger.info("No request ID provided, sending generated ID: " + requestID.toString()); + } else { + logger.info("Using provided request ID: " + requestID.toString()); + } + connection.setRequestProperty("X-ECOMP-RequestID", requestID.toString()); + // Setting up connection method and headers. + connection.setRequestMethod("POST"); + connection.setUseCaches(false); + connection.setInstanceFollowRedirects(false); + connection.setDoOutput(true); + connection.setDoInput(true); + OutputStream os = connection.getOutputStream(); + IOUtils.copy(input, os); + + + connection.connect(); + responseCode = connection.getResponseCode(); + // If Connected to a PDP Then break from the loop and + // continue with the Request. + if (connection.getResponseCode() == 200 || junit) { + connected = true; + break; + } else { + logger.debug(XACMLErrorConstants.ERROR_PERMISSIONS+ "PDP Response Code : " + connection.getResponseCode()); + Collections.rotate(pdps, -1); + Collections.rotate(encoding, -1); + } + } catch (Exception e) { + // This means that the PDP is not working and needs to + // Re-Order our List and Connect to the next one. + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "PDP connection Error : " + e); + Collections.rotate(pdps, -1); + Collections.rotate(encoding, -1); + } + pdpsCount++; + } + if (connected) { + // Read the Response + // System.out.println("connected to PDP : " + pdps.get(0)); + logger.debug("connected to PDP : " + pdps.get(0)); + logger.debug("--- Response: ---"); + Map> headers = connection.getHeaderFields(); + for(String key : headers.keySet()){ + logger.debug("Header : " + key + " Value: " + headers.get(key)); + } + try { + if (connection.getResponseCode() == 200 || junit) { + // Read the Response + ContentType contentType = null; + try { + contentType = ContentType.parse(connection + .getContentType()); + if (contentType.getMimeType().equalsIgnoreCase( + ContentType.APPLICATION_JSON.getMimeType())) { + if(junit){ + response = JSONResponse.load(getJsonResponseString()); + } else { + response = JSONResponse.load(connection.getInputStream()); + } + logger.debug(response + "\n---"); + } else { + logger.error(XACMLErrorConstants.ERROR_SCHEMA_INVALID + "Unknown Content-Type: " + + contentType); + throw new Exception(XACMLErrorConstants.ERROR_SCHEMA_INVALID + "Unknown Content-Type: " + + contentType); + } + } catch (Exception e) { + String message = XACMLErrorConstants.ERROR_SCHEMA_INVALID + "Parsing Content-Type: " + + connection.getContentType() + ", error=" + + e; + logger.error(XACMLErrorConstants.ERROR_SCHEMA_INVALID + e); + throw new Exception(message, e); + } + } else { + throw new Exception(XACMLErrorConstants.ERROR_PERMISSIONS+ "ERROR response code of the URL " + pdps.get(0) + " is " + + connection.getResponseCode()); + } + } catch (IOException e) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e); + throw new Exception(XACMLErrorConstants.ERROR_DATA_ISSUE +"Error in Connecting to the PDP ", e); + } + return response; + } else { + if(junit){ + response = JSONResponse.load(getJsonResponseString()); + return response; + } + throw new Exception(XACMLErrorConstants.ERROR_PERMISSIONS+ "Unable to get valid Response from PDP(s) " + pdps); + } + } + } + + private Collection checkResponse(Response response) + throws Exception { + + String pdpConfigURL = null; + + Collection combinedResult = new HashSet(); + int priority = defaultPriority; + Map uniqueResult = new HashMap(); + for (Result result : response.getResults()) { + if (!result.getDecision().equals(Decision.PERMIT)) { + logger.debug("Decision not a Permit. " + result.getDecision().toString()); + StdStatus stdStatus = new StdStatus(); + if (decide) { + stdStatus.setDecision(PolicyDecision.DENY); + for(Advice advice: result.getAssociatedAdvice()){ + for(AttributeAssignment attribute: advice.getAttributeAssignments()){ + stdStatus.setDetails(attribute.getAttributeValue().getValue().toString()); + break; + } + } + combinedResult.add(stdStatus); + return combinedResult; + } + stdStatus.setStatus(XACMLErrorConstants.ERROR_DATA_ISSUE + "Incorrect Params passed: Decision not a Permit.",PolicyResponseStatus.NO_ACTION_REQUIRED,PolicyConfigStatus.CONFIG_NOT_FOUND); + combinedResult.add(stdStatus); + return combinedResult; + } else { + if (decide) { + // check for Decision for decision based calls. + StdStatus stdStatus = new StdStatus(); + stdStatus.setDecision(PolicyDecision.PERMIT); + stdStatus.setDetails("Decision Permit. OK!"); + combinedResult.add(stdStatus); + return combinedResult; + } + if (!result.getAssociatedAdvice().isEmpty()) { + // @ TODO Add advice actions + // Configurations should be in advice. + Also PDP took + // actions could be here. + for (Advice advice : result.getAssociatedAdvice()) { + int config = 0, uri = 0; + String configURL = null; + String policyName = null; + String policyVersion = null; + Map matchingConditions = new HashMap(); + match = new Matches(); + Map configAttributes = new HashMap(); + Map responseAttributes = new HashMap(); + Map actionTaken = new HashMap(); + StdStatus stdStatus = new StdStatus(); + Map adviseAttributes = new HashMap(); + for (AttributeAssignment attribute : advice.getAttributeAssignments()) { + adviseAttributes.put(attribute.getAttributeId().stringValue(), attribute.getAttributeValue().getValue().toString()); + if (attribute.getAttributeValue().getValue().toString().equalsIgnoreCase("CONFIGURATION")) { + config++; + } else if (attribute.getDataTypeId().stringValue().endsWith("anyURI")) { + uri++; + if (uri == 1) { + configURL = attribute.getAttributeValue().getValue().toString(); + String currentUsedPDP = pdps.get(0); + int pos = (pdps.get(0)).lastIndexOf("/"); + String configURLPath = currentUsedPDP.substring(0, pos); + int pos1 = configURLPath.lastIndexOf("/"); + String pdpConfigURLPath = configURLPath.substring(0, pos1 + 1); + pdpConfigURL = configURL.replace("$URL", pdpConfigURLPath); + } else { + if (!(attribute.getIssuer().equalsIgnoreCase("PDP"))) { + throw new Exception(XACMLErrorConstants.ERROR_DATA_ISSUE + "Error having multiple URI in the Policy"); + } + } + } else if (attribute.getAttributeId().stringValue() + .equalsIgnoreCase("PolicyName")) { + policyName = attribute.getAttributeValue() + .getValue().toString(); + } else if (attribute.getAttributeId().stringValue() + .equalsIgnoreCase("VersionNumber")) { + policyVersion = attribute.getAttributeValue() + .getValue().toString(); + } else if (attribute.getAttributeId().stringValue().equalsIgnoreCase("Priority")){ + try{ + priority = Integer.parseInt(attribute.getAttributeValue().getValue().toString()); + } catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE+ "Unable to Parse Integer for Priority. Setting to default value"); + priority = defaultPriority; + } + } else if (attribute.getAttributeId().stringValue() + .startsWith("matching")) { + matchingConditions.put(attribute + .getAttributeId().stringValue() + .replaceFirst("(matching).", ""), + attribute.getAttributeValue() + .getValue().toString()); + if (attribute.getAttributeId().stringValue() + .replaceFirst("(matching).", "") + .equals("ECOMPName")) { + match.setEcompName(attribute + .getAttributeValue().getValue() + .toString()); + } else if (attribute.getAttributeId() + .stringValue() + .replaceFirst("(matching).", "") + .equals("ConfigName")) { + match.setConfigName(attribute + .getAttributeValue().getValue() + .toString()); + } else { + configAttributes.put(attribute + .getAttributeId().stringValue() + .replaceFirst("(matching).", ""), + attribute.getAttributeValue() + .getValue().toString()); + } + } else if (attribute.getAttributeId().stringValue().startsWith("key:")) { + responseAttributes.put(attribute + .getAttributeId().stringValue() + .replaceFirst("(key).", ""), + attribute.getAttributeValue() + .getValue().toString()); + } + } + if (!configAttributes.isEmpty()) { + match.setConfigAttributes(configAttributes); + } + if ((config == 1) && (uri == 1)) { + // If there is a configuration. + try { + logger.debug("Configuration Call to : " + + configURL); + stdStatus = ConfigCall(pdpConfigURL); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW+ e); + stdStatus + .setStatus( + "Error in Calling the Configuration URL " + + e, + PolicyResponseStatus.NO_ACTION_REQUIRED, + PolicyConfigStatus.CONFIG_NOT_FOUND); + } + stdStatus.setPolicyName(policyName); + stdStatus.setPolicyVersion(policyVersion); + stdStatus.setMatchingConditions(matchingConditions); + stdStatus.setResposneAttributes(responseAttributes); + if(!unique){ + combinedResult.add(stdStatus); + }else{ + if(!uniqueResult.isEmpty()){ + if(uniqueResult.containsKey(priority)){ + // Not any more unique, check the matching conditions size + int oldSize = uniqueResult.get(priority).getMatchingConditions().size(); + int newSize = matchingConditions.size(); + if(oldSize < newSize){ + uniqueResult.put(priority, stdStatus); + }else if(oldSize == newSize){ + stdStatus = new StdStatus(); + stdStatus.setStatus("Two/more Policies have Same Priority and matching conditions, Please correct your policies.", PolicyResponseStatus.NO_ACTION_REQUIRED, + PolicyConfigStatus.CONFIG_NOT_FOUND); + combinedResult.add(stdStatus); + unique = false; + return combinedResult; + } + }else{ + uniqueResult.put(priority, stdStatus); + } + }else{ + uniqueResult.put(priority, stdStatus); + } + } + } else { + // Else it is Action Taken. + logger.info("Action Taken by PDP. "); + actionTaken.putAll(adviseAttributes); + stdStatus.setActionTaken(actionTaken); + stdStatus.setPolicyResponseStatus( + "Action Taken by the PDP", + PolicyResponseStatus.ACTION_TAKEN); + combinedResult.add(stdStatus); + } + } + } + if (!result.getObligations().isEmpty()) { + // @ TODO add Obligation actions + // Action advised should be in obligations. + for (Obligation obligation : result.getObligations()) { + Map actionAdvised = new HashMap(); + StdStatus stdStatus = new StdStatus(); + for (AttributeAssignment attribute : obligation + .getAttributeAssignments()) { + actionAdvised.put(attribute.getAttributeId() + .stringValue(), attribute + .getAttributeValue().getValue().toString()); + } + stdStatus.setActionAdvised(actionAdvised); + stdStatus.setPolicyResponseStatus( + "Action has been Advised ", + PolicyResponseStatus.ACTION_ADVISED); + combinedResult.add(stdStatus); + } + } + } + } + if(unique){ + // Select Unique policy. + int minNum = defaultPriority; + for(int num: uniqueResult.keySet()){ + if(num < minNum){ + minNum = num; + } + } + combinedResult.add(uniqueResult.get(minNum)); + // Turn off Unique + unique = false; + } + + return combinedResult; + } + + private StdStatus ConfigCall(String stringURL) throws Exception { + StdStatus stdStatus = new StdStatus(); + try { + URL configURL = new URL(stringURL); + URLConnection connection = null; + try { + connection = configURL.openConnection(); + if (stringURL.endsWith("json")) { + stdStatus.setPolicyType(PolicyType.JSON); + JsonReader jsonReader = Json.createReader(connection + .getInputStream()); + stdStatus.setJsonObject(jsonReader.readObject()); + jsonReader.close(); + logger.info("config Retrieved "); + stdStatus.setStatus("Config Retrieved from: " + configURL, + PolicyResponseStatus.NO_ACTION_REQUIRED, + PolicyConfigStatus.CONFIG_RETRIEVED); + try { + MatchStore.storeMatch(match); + } catch (Exception e) { + logger.info("StoreMatch failed for Ecomp:" + + match.getEcompName() + " Config: " + + match.getConfigName()); + } + return stdStatus; + } else if (stringURL.endsWith("xml")) { + stdStatus.setPolicyType(PolicyType.XML); + DocumentBuilderFactory dbf = DocumentBuilderFactory + .newInstance(); + DocumentBuilder db = null; + try { + db = dbf.newDocumentBuilder(); + Document config = db.parse(connection.getInputStream()); + stdStatus.setDocument(config); + } catch (ParserConfigurationException e) { + logger.error(XACMLErrorConstants.ERROR_SCHEMA_INVALID + e); + throw new Exception(XACMLErrorConstants.ERROR_SCHEMA_INVALID + "Unable to create Document Object", + e); + } catch (SAXException e) { + logger.error(XACMLErrorConstants.ERROR_SCHEMA_INVALID+ e); + throw new Exception(XACMLErrorConstants.ERROR_SCHEMA_INVALID+ "Unable to parse the XML config", e); + } + logger.info("config Retrieved "); + stdStatus.setStatus("Config Retrieved from: " + configURL, + PolicyResponseStatus.NO_ACTION_REQUIRED, + PolicyConfigStatus.CONFIG_RETRIEVED); + try { + MatchStore.storeMatch(match); + } catch (Exception e) { + logger.info("StoreMatch failed for Ecomp:" + + match.getEcompName() + " Config: " + + match.getConfigName()); + } + return stdStatus; + } else if (stringURL.endsWith("properties")) { + stdStatus.setPolicyType(PolicyType.PROPERTIES); + Properties configProp = new Properties(); + configProp.load(connection.getInputStream()); + stdStatus.setProperties(configProp); + logger.info("config Retrieved "); + stdStatus.setStatus("Config Retrieved from: " + configURL, + PolicyResponseStatus.NO_ACTION_REQUIRED, + PolicyConfigStatus.CONFIG_RETRIEVED); + try { + MatchStore.storeMatch(match); + } catch (Exception e) { + logger.info("StoreMatch failed for Ecomp:" + + match.getEcompName() + " Config: " + + match.getConfigName()); + } + return stdStatus; + } else if (stringURL.endsWith("txt")) { + stdStatus.setPolicyType(PolicyType.OTHER); + InputStream in = connection.getInputStream(); + String other = IOUtils.toString(in); + IOUtils.closeQuietly(in); + stdStatus.setOther(other); + logger.info("config Retrieved "); + stdStatus.setStatus("Config Retrieved from: " + configURL, + PolicyResponseStatus.NO_ACTION_REQUIRED, + PolicyConfigStatus.CONFIG_RETRIEVED); + try { + MatchStore.storeMatch(match); + } catch (Exception e) { + logger.info("StoreMatch failed for Ecomp:" + + match.getEcompName() + " Config: " + + match.getConfigName()); + } + return stdStatus; + } else { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Config Not Found"); + stdStatus + .setPolicyConfigStatus(PolicyConfigStatus.CONFIG_NOT_FOUND); + stdStatus + .setConfigStatus("Illegal form of Configuration Type Found."); + return stdStatus; + } + } catch (IOException e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + throw new Exception(XACMLErrorConstants.ERROR_PROCESS_FLOW + + "Cannot open a connection to the configURL", e); + } + } catch (MalformedURLException e) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e); + throw new Exception(XACMLErrorConstants.ERROR_DATA_ISSUE + "Error in ConfigURL", e); + } + } + + private void setProperty(String propertyFilePath) + throws PolicyEngineException { + this.propertyFilePath = propertyFilePath; + if (this.propertyFilePath == null) { + // This is only for testing purpose. Or We will add a default PDP + // address here. + // url_default = "http://localhost:8080/pdp/"; + // The General Error Message is Below. + throw new PolicyEngineException(XACMLErrorConstants.ERROR_DATA_ISSUE + "Error NO PropertyFile Path provided"); + } else { + // Adding logic for remote Properties file. + Properties prop = new Properties(); + if (propertyFilePath.startsWith("http")) { + URL configURL; + try { + configURL = new URL(propertyFilePath); + URLConnection connection = null; + connection = configURL.openConnection(); + prop.load(connection.getInputStream()); + } catch (IOException e) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e); + throw new PolicyEngineException(XACMLErrorConstants.ERROR_DATA_ISSUE + "Maformed property URL "+ e.getMessage()); + } + } else { + Path file = Paths.get(propertyFilePath); + if (Files.notExists(file)) { + throw new PolicyEngineException(XACMLErrorConstants.ERROR_DATA_ISSUE + "File doesn't exist in the specified Path " + file.toString()); + } + if (file.toString().endsWith(".properties")) { + InputStream in; + prop = new Properties(); + try { + in = new FileInputStream(file.toFile()); + prop.load(in); + } catch (IOException e) { + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e); + throw new PolicyEngineException(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Cannot Load the Properties file", e); + } + } else { + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Not a .properties file " + propertyFilePath); + throw new PolicyEngineException(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Not a .properties file"); + } + } + // UEB Settings + String check_type = prop.getProperty("NOTIFICATION_TYPE"); + String serverList = prop.getProperty("NOTIFICATION_UEB_SERVERS"); + if(check_type==null) { + notificationType.add("websocket"); + logger.info("Properties file doesn't have the NOTIFICATION_TYPE parameter system will use defualt websockets"); + }else{ + if(check_type.contains(",")) { + type_default = new ArrayList(Arrays.asList(prop.getProperty("NOTIFICATION_TYPE").split(","))); + notificationType = type_default; + } else { + notificationType = new ArrayList(); + notificationType.add(check_type); + } + } + if(serverList==null) { + notificationType.clear(); + notificationType.add("websocket"); + logger.info("Properties file doesn't have the NOTIFICATION_UEB_SERVERS parameter system will use defualt websockets"); + }else{ + if(serverList.contains(",")) { + uebURLList = new ArrayList(Arrays.asList(prop.getProperty("NOTIFICATION_UEB_SERVERS").split(","))); + } else { + uebURLList = new ArrayList(); + uebURLList.add(serverList); + } + } + // Client ID Authorization Settings. + String clientID = prop.getProperty("CLIENT_ID"); + String clientKey = prop.getProperty("CLIENT_KEY"); + userName = clientID; + pass = clientKey; + pyPDPClientFile = prop.getProperty("CLIENT_FILE"); + environment = prop.getProperty("ENVIRONMENT", "DEVL"); + /*try { + aafClient = AAFPolicyClient.getInstance(prop); + } catch (AAFPolicyException e) { + logger.error(XACMLErrorConstants.ERROR_UNKNOWN + e.getMessage()); + throw new PolicyEngineException(XACMLErrorConstants.ERROR_UNKNOWN + e); + }*/ + // Initializing the values. + pdps = new ArrayList(); + paps = new ArrayList(); + encoding = new ArrayList(); + encodingPAP = new ArrayList(); + // Check the Keys for PDP_URLs + Collection unsorted = prop.keySet(); + @SuppressWarnings({ "rawtypes", "unchecked" }) + List sorted = new ArrayList(unsorted); + Collections.sort(sorted); + for (String propKey : sorted) { + if (propKey.startsWith("PDP_URL")) { + String check_val = prop.getProperty(propKey); + if (check_val == null) { + throw new PolicyEngineException(XACMLErrorConstants.ERROR_DATA_ISSUE + "Properties file doesn't have the PDP_URL parameter"); + } + if (check_val.contains(";")) { + pdp_default = new ArrayList(Arrays.asList(check_val.split("\\s*;\\s*"))); + int pdpCount = 0; + while (pdpCount < pdp_default.size()) { + String pdpVal = pdp_default.get(pdpCount); + readPDPParam(pdpVal); + pdpCount++; + } + } else { + readPDPParam(check_val); + } + } else if (propKey.startsWith("PAP_URL")) { + String check_val = prop.getProperty(propKey); + if (check_val == null) { + throw new PolicyEngineException(XACMLErrorConstants.ERROR_DATA_ISSUE + "Properties file doesn't have the PAP_URL parameter"); + } + if (check_val.contains(";")) { + pap_default = new ArrayList(Arrays.asList(check_val.split("\\s*;\\s*"))); + int papCount = 0; + while (papCount < pap_default.size()) { + String papVal = pap_default.get(papCount); + readPAPParam(papVal); + papCount++; + } + } else { + readPAPParam(check_val); + } + } + } + if (pdps == null || pdps.isEmpty()) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Cannot Proceed without PDP_URLs"); + throw new PolicyEngineException(XACMLErrorConstants.ERROR_DATA_ISSUE + "Cannot Proceed without PDP_URLs"); + } + + if (paps == null || paps.isEmpty()) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Cannot Proceed without PAP_URLs"); + throw new PolicyEngineException(XACMLErrorConstants.ERROR_DATA_ISSUE + "Cannot Proceed with out PAP_URLs"); + } + + // Get JUNIT property from properties file when running tests + String junit = prop.getProperty("JUNIT"); + if(junit == null || junit.isEmpty()){ + logger.info("No JUNIT property provided, this will not be executed as a test."); + }else{ + if(junit.equals("test")){ + this.junit = true; + } else { + this.junit = false; + } + } + } + } + + /* + * Read the PDP_URL parameter + */ + private void readPDPParam(String pdpVal) throws PolicyEngineException{ + if(pdpVal.contains(",")){ + List pdpValues = new ArrayList(Arrays.asList(pdpVal.split("\\s*,\\s*"))); + if(pdpValues.size()==3){ + // 0 - PDPURL + pdps.add(pdpValues.get(0)); + // 1:2 will be UserID:Password + String userID = pdpValues.get(1); + String pass = pdpValues.get(2); + Base64.Encoder encoder = Base64.getEncoder(); + encoding.add(encoder.encodeToString((userID+":"+pass).getBytes(StandardCharsets.UTF_8))); + }else{ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Credentials to send Request: " + pdpValues); + throw new PolicyEngineException(XACMLErrorConstants.ERROR_DATA_ISSUE + "No enough Credentials to send Request. " + pdpValues); + } + }else{ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "PDP value is improper/missing required values: " + pdpVal); + throw new PolicyEngineException(XACMLErrorConstants.ERROR_DATA_ISSUE + "PDP value is improper/missing required values."); + } + } + + /* + * Read the PAP_URL parameter + */ + private void readPAPParam(String papVal) throws PolicyEngineException{ + if(papVal.contains(",")){ + List papValues = new ArrayList(Arrays.asList(papVal.split("\\s*,\\s*"))); + if(papValues.size()==3){ + // 0 - PAPURL + paps.add(papValues.get(0)); + // 1:2 will be UserID:Password + String userID = papValues.get(1); + String pass = papValues.get(2); + Base64.Encoder encoder = Base64.getEncoder(); + encodingPAP.add(encoder.encodeToString((userID+":"+pass).getBytes(StandardCharsets.UTF_8))); + }else{ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Credentials to send Request: " + papValues); + throw new PolicyEngineException(XACMLErrorConstants.ERROR_DATA_ISSUE + "No enough Credentials to send Request. " + papValues); + } + }else{ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Credentials to send Request: " + papVal); + throw new PolicyEngineException(XACMLErrorConstants.ERROR_DATA_ISSUE + "No enough Credentials to send Request."); + } + } + /* + * Allowing changes to the scheme and Handler. + */ + public void notification(NotificationScheme scheme, NotificationHandler handler) { + this.scheme = scheme; + this.handler = handler; + logger.debug("Scheme is : " + scheme.toString()); + logger.debug("Handler is : " + handler.getClass().getName()); + if (!notificationType.get(0).equals("ueb")){ + AutoClientEnd.setAuto(scheme, handler); + }else { + if (this.UEBThread){ + UEBClientThread.setAuto(scheme, handler); + this.UEBThread = registerUEBThread.isAlive(); + } + } + + //TODO This could also be a Start point for Auto Notifications.. + if(pdps!=null){ + if (notificationType.get(0).equals("ueb") && !this.UEBThread){ + this.UEBClientThread = new AutoClientUEB(pdps.get(0), uebURLList); + this.UEBClientThread.setAuto(scheme, handler); + this.registerUEBThread = new Thread(this.UEBClientThread); + this.registerUEBThread.start(); + this.UEBThread = true; + } + if (!notificationType.get(0).equals("ueb")){ + if(pdps.get(0)!=null){ + if(AutoClientEnd.getURL()==null){ + AutoClientEnd.start(pdps.get(0)); + }else { + AutoClientEnd.stop(); + AutoClientEnd.start(pdps.get(0)); + } + } + } + } + } + + /* + * Gets the Notification if one exists. Used only for Manual Polling + * purposes. + */ + public PDPNotification getNotification(){ + //TODO manual Polling + //Check if there is proper scheme.. + PDPNotification notification = null; + if(this.scheme.equals(NotificationScheme.MANUAL_ALL_NOTIFICATIONS) || this.scheme.equals(NotificationScheme.MANUAL_NOTIFICATIONS)) { + if (notificationType.get(0).equals("ueb")){ + ManualClientEndUEB.start(pdps.get(0), uebURLList, uniqueID); + notification = ManualClientEndUEB.result(scheme); + }else{ + ManualClientEnd.start(pdps.get(0)); + logger.debug("manual notification requested.. : " + scheme.toString()); + notification = ManualClientEnd.result(scheme); + } + + if (notification == null){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Notification yet.."); + return null; + } else { + return notification; + } + + }else { + return null; + } + } + + /* + * Setting the Scheme. + */ + public void setScheme(NotificationScheme scheme) { + this.scheme = scheme; + if (notificationType.get(0).equals("ueb")){ + AutoClientUEB.setScheme(this.scheme); + if (this.scheme.equals(NotificationScheme.MANUAL_ALL_NOTIFICATIONS)){ + ManualClientEndUEB.createTopic(pdps.get(0), uniqueID, uebURLList); + } + }else{ + AutoClientEnd.setScheme(this.scheme); + } + } + + /* + * Returns the Scheme + */ + public NotificationScheme getScheme() { + return this.scheme; + } + + /* + * Returns the NotificationHandler + */ + public NotificationHandler getNotificationHandler() { + return this.handler; + } + + private Collection configResult( + Collection generateRequest) { + Collection result = new HashSet(); + if (generateRequest == null) { + return null; + } + if (!generateRequest.isEmpty()) { + for (StdStatus stdStatus : generateRequest) { + PolicyConfig policyConfig = new StdPolicyConfig(); + policyConfig = stdStatus; + result.add(policyConfig); + } + } + return result; + } + + private Collection eventResult( + Collection generateRequest, + Map eventAttributes) { + Collection result = new HashSet(); + if (generateRequest == null) { + return null; + } + if (!generateRequest.isEmpty()) { + for (StdStatus stdStatus : generateRequest) { + StdPolicyResponse policyResponse = new StdPolicyResponse(); + policyResponse = stdStatus; + policyResponse.setRequestAttributes(eventAttributes); + result.add(policyResponse); + } + } + return result; + } + + private DecisionResponse decisionResult(Collection generateRequest) { + StdDecisionResponse policyDecision = new StdDecisionResponse(); + if (generateRequest == null) { + return policyDecision; + } + if (!generateRequest.isEmpty()) { + for (StdStatus stdStatus : generateRequest) { + policyDecision.setDecision(stdStatus.getDecision()); + policyDecision.setDetails(stdStatus.getDetails()); + } + } + return policyDecision; + } + + /* + * Stop the Notification Service if its running. + */ + public void stopNotification() { + if (this.scheme != null && this.handler != null) { + if (this.scheme.equals(NotificationScheme.AUTO_ALL_NOTIFICATIONS) + || this.scheme + .equals(NotificationScheme.AUTO_NOTIFICATIONS)) { + logger.info("Clear Notification called.. "); + if (notificationType.get(0).equals("ueb")){ + this.UEBClientThread.terminate(); + this.UEBThread = false; + }else{ + AutoClientEnd.stop(); + } + } + } + } + + /* + * Create Config Policy API Implementation + */ + public String createConfigPolicy(String policyName, String policyDescription, String ecompName, String configName, + Map configAttributes, String configType, String body, String policyScope, UUID requestID, + String riskLevel, String riskType, String guard, String ttlDate) throws Exception { + return createConfigPolicy(policyName,policyDescription, ecompName, configName, + configAttributes, configType, body, policyScope, requestID, userName , pass, riskLevel, riskType, guard, ttlDate); + } + + public String createConfigPolicy(String policyName, String policyDescription, String ecompName, String configName, + Map configAttributes, String configType, String body, String policyScope, UUID requestID, String userID, String passcode, + String riskLevel, String riskType, String guard, String ttlDate) throws Exception { + + String response = null; + String configBody = null; + String resource= "createPolicy"; + if(!checkPermissions(userID, passcode, resource)){ + logger.error(XACMLErrorConstants.ERROR_PERMISSIONS + "You are not allowed to Make this Request. Please contact PolicyAdmin to give access to:" + resource); + response = XACMLErrorConstants.ERROR_PERMISSIONS + "You are not allowed to Make this Request. Please contact PolicyAdmin to give access to:" + resource; + return response; + } + + //check body for JSON form and remove single quotes if present + if (configType.equalsIgnoreCase("JSON")) { + if (body.contains("'")) { + configBody = body.replace("'", "\""); + } else { + configBody = body; + } + } else { + configBody = body; + } + + boolean levelCheck = isNumeric(riskLevel); + + if (policyName==null||policyName.equalsIgnoreCase("")){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Name given."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Name given."; + } else if (ecompName==null||ecompName.equalsIgnoreCase("")){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No ECOMP Name given."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "No ECOMP Name given."; + } else if (configName==null||configName.equalsIgnoreCase("")){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Config Name given."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Config Name given."; + } else if (policyScope==null||policyScope.equalsIgnoreCase("")){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Scope given."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Scope given."; + } else if (!levelCheck){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Incorrect Risk Level given."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "Incorrect Risk Level given."; + }else { + + StdPAPPolicy newPAPPolicy = new StdPAPPolicy("Base", policyName, policyDescription, ecompName, configName, configAttributes, configType, + configBody, false, policyScope,0, riskLevel, riskType, guard, ttlDate); + + //send JSON object to PAP + response = (String) callPAP(newPAPPolicy, new String[] {"operation=create", "apiflag=api", "policyType=Config"}, requestID, "Config"); + } + return response; + + } + + /* + * Create Config Policy API Implementation + */ + public String updateConfigPolicy(String policyName, String policyDescription, String ecompName, String configName, + Map configAttributes, String configType, String body, String policyScope, UUID requestID, + String riskLevel, String riskType, String guard, String ttlDate) throws Exception { + return updateConfigPolicy(policyName, policyDescription, ecompName, configName, + configAttributes, configType, body, policyScope, requestID, userName, pass, riskLevel, riskType, guard, ttlDate); + } + + public String updateConfigPolicy(String policyName, String policyDescription, String ecompName, String configName, + Map configAttributes, String configType, String body, String policyScope, + UUID requestID, String userID, String passcode,String riskLevel, String riskType, String guard, + String ttlDate) throws Exception { + + String response = null; + String configBody = null; + String resource= "updatePolicy"; + if(!checkPermissions(userID, passcode, resource)){ + logger.error(XACMLErrorConstants.ERROR_PERMISSIONS + "You are not allowed to Make this Request. Please contact PolicyAdmin to give access to:" + resource); + response = XACMLErrorConstants.ERROR_PERMISSIONS + "You are not allowed to Make this Request. Please contact PolicyAdmin to give access to:" + resource; + return response; + } + //check body for JSON form and remove single quotes if present + if (configType.equalsIgnoreCase("JSON")) { + if (body.contains("'")) { + configBody = body.replace("'", "\""); + } else { + configBody = body; + } + } else { + configBody = body; + } + + boolean levelCheck = isNumeric(riskLevel); + + if (policyName==null||policyName.equalsIgnoreCase("")){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Name given."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Name given."; + } else if (ecompName==null||ecompName.equalsIgnoreCase("")){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No ECOMP Name given."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "No ECOMP Name given."; + } else if (configName==null||configName.equalsIgnoreCase("")){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Config Name given."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Config Name given."; + } else if (policyScope==null||policyScope.equalsIgnoreCase("")){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Scope given."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Scope given."; + } else if (!levelCheck){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Incorrect Risk Level given."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "Incorrect Risk Level given."; + } else { + + //set values for basic policy information + String policyType = "Config"; + String configPolicyType = "base"; + + StdPAPPolicy newPAPPolicy = new StdPAPPolicy(configPolicyType, policyName, policyDescription, ecompName, configName, configAttributes, configType, + configBody, true, policyScope,0, riskLevel, riskType, guard, ttlDate); + + //send JSON object to PAP + response = (String) callPAP(newPAPPolicy, new String[] {"operation=update", "apiflag=api", "policyType=" + policyType}, requestID, "Config"); + + } + return response; + + } + + + /* + * Create Config Firewall Policy API implementation + */ + public String createConfigFirewallPolicy(String policyName, JsonObject firewallJson, String policyScope, UUID requestID, + String riskLevel, String riskType, String guard, String ttlDate) throws Exception { + return createConfigFirewallPolicy(policyName, firewallJson, policyScope, requestID, userName, pass, riskLevel, riskType, guard, ttlDate); + } + + public String createConfigFirewallPolicy(String policyName, JsonObject firewallJson, String policyScope, UUID requestID, String userID, String passcode, + String riskLevel, String riskType, String guard, String ttlDate) throws Exception { + + String response = null; + String resource= "createPolicy"; + if(!checkPermissions(userID, passcode, resource)){ + logger.error(XACMLErrorConstants.ERROR_PERMISSIONS + "You are not allowed to Make this Request. Please contact PolicyAdmin to give access to:" + resource); + response = XACMLErrorConstants.ERROR_PERMISSIONS + "You are not allowed to Make this Request. Please contact PolicyAdmin to give access to:" + resource; + return response; + } + + //set values for basic policy information + String configName = firewallJson.get("configName").toString(); + //String configDescription = firewallJson.get("configDescription").toString(); + String configDescription = ""; + String json = firewallJson.toString(); + + boolean levelCheck = isNumeric(riskLevel); + + if (!isJSONValid(json)) { + logger.error(XACMLErrorConstants.ERROR_SCHEMA_INVALID + "Invalid JSON for firewallJson: " + json); + throw new PolicyDecisionException(XACMLErrorConstants.ERROR_SCHEMA_INVALID + "Invalid JSON for firewallJson: " + json); + } + + if (policyName==null||policyName.equalsIgnoreCase("")){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Name given."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Name given."; + } else if (policyScope==null||policyScope.equalsIgnoreCase("")){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Scope given."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Scope given."; + } else if (!levelCheck){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Incorrect Risk Level given."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "Incorrect Risk Level given."; + } else { + + StdPAPPolicy newPAPPolicy = new StdPAPPolicy("Firewall Config", policyName, configDescription, configName, false, policyScope, json, 0, + riskLevel, riskType, guard, ttlDate); + + //send JSON object to PAP + response = (String) callPAP(newPAPPolicy, new String[] {"operation=create", "apiflag=api", "policyType=Config"}, requestID, "ConfigFirewall"); + } + + return response; + } + + /* + * Update Config Firewall Policy API implementation + */ + public String updateConfigFirewallPolicy(String policyName, JsonObject firewallJson, String policyScope, UUID requestID, String riskLevel, String riskType, + String guard, String ttlDate) throws Exception { + return updateConfigFirewallPolicy(policyName, firewallJson, policyScope, requestID, userName, pass, riskLevel, riskType, guard, ttlDate); + } + + public String updateConfigFirewallPolicy(String policyName, JsonObject firewallJson, String policyScope, UUID requestID, String userID, String passcode, + String riskLevel, String riskType, String guard, String ttlDate) throws Exception { + + String response = null; + String resource= "updatePolicy"; + if(!checkPermissions(userID, passcode, resource)){ + logger.error(XACMLErrorConstants.ERROR_PERMISSIONS + "You are not allowed to Make this Request. Please contact PolicyAdmin to give access to:" + resource); + response = XACMLErrorConstants.ERROR_PERMISSIONS + "You are not allowed to Make this Request. Please contact PolicyAdmin to give access to:" + resource; + return response; + } + String configName = firewallJson.get("configName").toString(); + //String configDescription = firewallJson.get("configDescription").toString(); + String configDescription = ""; //ASK Lak about this...**** + String json = firewallJson.toString(); + boolean levelCheck = isNumeric(riskLevel); + + if (policyName==null||policyName.equalsIgnoreCase("")){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Name given."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Name given."; + } else if (policyScope==null||policyScope.equalsIgnoreCase("")){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Scope given."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Scope given."; + } else if (!levelCheck){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Incorrect Risk Level given."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "Incorrect Risk Level given."; + } else { + + StdPAPPolicy newPAPPolicy = new StdPAPPolicy("Firewall Config", policyName, configDescription, configName, true, policyScope, json, 0, + riskLevel, riskType, guard, ttlDate); + + //send JSON object to PAP + response = (String) callPAP(newPAPPolicy, new String[] {"operation=update", "apiflag=api", "policyType=Config"}, requestID, "ConfigFirewall"); + } + + return response; + } + + /* + * Create or Update BRMS Raw Config Policy API implementation + */ + public String createUpdateBRMSRawPolicy(String policyName, + String policyDescription, + Map> dyanamicFieldConfigAttributes, + String brmsRawBody, + String policyScope, + Boolean isEdit, + UUID requestID, + String riskLevel, + String riskType, + String guard, + String ttlDate) { + + String response = null; + String operation = null; + + + if (isEdit){ + operation = "update"; + } else { + operation = "create"; + } + + boolean levelCheck = isNumeric(riskLevel); + + if (policyName==null||policyName.equalsIgnoreCase("")){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Name given."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Name given."; + } else if(policyDescription==null || policyDescription.equalsIgnoreCase("")){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No policyDescription given."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "No policyDescription given."; + } else if (policyScope==null||policyScope.equalsIgnoreCase("")){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Scope given."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Scope given."; + } else if (brmsRawBody==null ||brmsRawBody.equalsIgnoreCase("")){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No rule body given."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "No rule body given."; + } else if (!levelCheck){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Incorrect Risk Level given."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "Incorrect Risk Level given."; + } else { + /*String configPolicyType, String policyName, String description, + String configName, Boolean editPolicy, String domain, + Map dyanamicFieldConfigAttributes, Integer highestVersion, String eCompName, + String configBodyData*/ + + StdPAPPolicy newPAPPolicy = new StdPAPPolicy("BRMS_Raw",policyName,policyDescription, + "BRMS_RAW_RULE",isEdit,policyScope, + dyanamicFieldConfigAttributes.get(AttributeType.RULE), 0, "DROOLS", + brmsRawBody, riskLevel, riskType, guard, ttlDate); + + //send JSON object to PAP + try { + response = (String) callPAP(newPAPPolicy, new String[] {"operation="+operation, "apiflag=api", "policyType=Config"}, requestID, "ConfigBrmsRaw"); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + return response; + } + + /* + * Create or Update BRMS Param Config Policy API implementation + */ + public String createUpdateBRMSParamPolicy(String policyName, + String policyDescription, + Map> dyanamicFieldConfigAttributes, + String brmsRawBody, + String policyScope, + Boolean isEdit, + UUID requestID, + Map> drlRuleAndUIParams, + String riskLevel, String riskType, String guard, String ttlDate) { + + String response = null; + String operation = null; + + + if (isEdit){ + operation = "update"; + } else { + operation = "create"; + } + + boolean levelCheck = isNumeric(riskLevel); + + if (policyName==null||policyName.equalsIgnoreCase("")){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Name given."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Name given."; + } else if(policyDescription==null || policyDescription.equalsIgnoreCase("")){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No policyDescription given."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "No policyDescription given."; + } else if (policyScope==null||policyScope.equalsIgnoreCase("")){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Scope given."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Scope given."; + } else if ((dyanamicFieldConfigAttributes==null)){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Rule Attributes given."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Rule Attributes given."; + } else if (!levelCheck){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Incorrect Risk Level given."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "Incorrect Risk Level given."; + }else { + /*public StdPAPPolicy (String configPolicyType, String policyName, String description, + String configName, Boolean editPolicy, String domain, + Map dyanamicFieldConfigAttributes, Integer highestVersion, String eCompName, + String configBodyData,Map drlRuleAndUIParams) */ + + StdPAPPolicy newPAPPolicy = new StdPAPPolicy("BRMS_Param",policyName,policyDescription, + "BRMS_PARAM_RULE",isEdit,policyScope, + drlRuleAndUIParams.get(AttributeType.MATCHING), 0, "DROOLS", + brmsRawBody, drlRuleAndUIParams.get(AttributeType.RULE), riskLevel, riskType, guard, ttlDate); + + //send JSON object to PAP + try { + response = (String) callPAP(newPAPPolicy, new String[] {"operation="+operation, "apiflag=api", "policyType=Config"}, requestID, "ConfigBrmsParam"); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + return response; + } + + /* + * Create or Update Action Policy API implementation + */ + public String createUpdateActionPolicy(String policyName, String policyDescription, Map componentAttributes, List dynamicRuleAlgorithmLabels, + List dynamicRuleAlgorithmField1, List dynamicRuleAlgorithmFunctions, List dynamicRuleAlgorithmField2, + String actionPerformer, String actionAttribute, String policyScope, Boolean isEdit, UUID requestID) { + + String response = null; + String operation = null; + + if (isEdit){ + operation = "update"; + } else { + operation = "create"; + } + + if (policyName==null||policyName.equalsIgnoreCase("")){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Name given."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Name given."; + return response; + } else if (componentAttributes==null||componentAttributes.equals("")){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Component Attributes given."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Component Attributes given."; + return response; + } else if (actionAttribute==null||actionAttribute.equalsIgnoreCase("")){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Action Attribute given."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Action Attribute given."; + return response; + } else if (policyScope==null||policyScope.equalsIgnoreCase("")){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Scope given."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Scope given."; + return response; + } else if (actionPerformer==null||actionPerformer.equalsIgnoreCase("")){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Action Performer given."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Action Performer given."; + return response; + } else if (!actionPerformer.equals("PEP")) { + if (!actionPerformer.equals("PDP")) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Invalid Action Performer given."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "Invalid Action Performer given."; + return response; + } + } + + StdPAPPolicy newPAPPolicy = new StdPAPPolicy(policyName, policyDescription, componentAttributes, dynamicRuleAlgorithmLabels, dynamicRuleAlgorithmFunctions, + dynamicRuleAlgorithmField1, dynamicRuleAlgorithmField2, actionPerformer, actionAttribute, isEdit, policyScope, 0); + + //send JSON object to PAP + try { + response = (String) callPAP(newPAPPolicy, new String[] {"operation="+operation, "apiflag=api", "policyType=Action"}, requestID, "Action"); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + return response; + + } + + /* + * Create or Update Decision Policy implementation + */ + private String createUpdateDecisionPolicy(String policyName, String policyDescription, String ecompName, RuleProvider ruleProvider, Map componentAttributes, Map settings, + List dynamicRuleAlgorithmLabels, List dynamicRuleAlgorithmField1, List dynamicRuleAlgorithmFunctions, List dynamicRuleAlgorithmField2, + String policyScope, Boolean isEdit, UUID requestID) { + + String response = null; + String operation = null; + + if (isEdit){ + operation = "update"; + } else { + operation = "create"; + } + + if (policyName==null||policyName.equalsIgnoreCase("")){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Name given."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Name given."; + } else if (ecompName==null||ecompName.equalsIgnoreCase("")){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No ECOMP Name given."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "No ECOMP Name given."; + } else if (policyScope==null||policyScope.equalsIgnoreCase("")){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Scope given."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Scope given."; + } else { + + if (ruleProvider==null) { + ruleProvider = RuleProvider.CUSTOM ; + } + + StdPAPPolicy newPAPPolicy = new StdPAPPolicy(policyName, policyDescription, ecompName, ruleProvider.toString(), componentAttributes, settings, dynamicRuleAlgorithmLabels, dynamicRuleAlgorithmFunctions, + dynamicRuleAlgorithmField1, dynamicRuleAlgorithmField2, null, null, null, isEdit, policyScope, 0); + + //send JSON object to PAP + try { + response = (String) callPAP(newPAPPolicy, new String[] {"operation="+operation, "apiflag=api", "policyType=Decision"}, requestID, "Decision"); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + return response; + } + + /* + * Create or Update ClosedLoop_Fault policy implementation + */ + private String createUpdateClosedLoopPolicy(String policyName, JsonObject configBody, String policyDescription, String policyScope, Boolean isEdit, + UUID requestID,String riskLevel, String riskType, String guard, String ttlDate) { + + String response = null; + String operation = null; + String oldPolicyName = null; + + if (isEdit){ + operation = "update"; + if (policyName.endsWith("_Draft")) { + oldPolicyName = policyName + "_Draft.1"; + } + } else { + operation = "create"; + } + + boolean levelCheck = isNumeric(riskLevel); + + // get values and attributes from the JsonObject + String ecompName = configBody.get("ecompname").toString().replace("\"", ""); + String jsonBody = configBody.toString(); + + + if (policyName==null||policyName.equalsIgnoreCase("")){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Name given."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Name given."; + } else if (ecompName==null||ecompName.equals("")){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Ecomp Name given."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Ecomp Name given."; + } else if (policyScope==null||policyScope.equalsIgnoreCase("")){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Scope given."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Scope given."; + } else if (!levelCheck){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Incorrect Risk Level given."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "Incorrect Risk Level given."; + } else { + + + StdPAPPolicy newPAPPolicy = new StdPAPPolicy("ClosedLoop_Fault", policyName, policyDescription, ecompName, + jsonBody, false, oldPolicyName, null, isEdit, policyScope, 0, riskLevel, riskType, guard, ttlDate); + + //send JSON object to PAP + try { + response = (String) callPAP(newPAPPolicy, new String[] {"operation="+operation, "apiflag=api", "policyType=Config"}, requestID, "ConfigClosedLoop"); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + return response; + + } + + private String createUpdateClosedLoopPmPolicy(String policyName, JsonObject configBody, String policyDescription, String policyScope, Boolean isEdit, + UUID requestID, String riskLevel, String riskType, String guard, String ttlDate) { + + String response = null; + String operation = null; + String oldPolicyName = null; + + if (isEdit){ + operation = "update"; + } else { + operation = "create"; + } + + boolean levelCheck = isNumeric(riskLevel); + + // get values and attributes from the JsonObject + String ecompName = configBody.get("ecompname").toString().replace("\"", ""); + String serviceType = configBody.get("serviceTypePolicyName").toString().replace("\"", ""); + String jsonBody = configBody.toString(); + + + if (policyName==null||policyName.equalsIgnoreCase("")){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Name given."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Name given."; + } else if (ecompName==null||ecompName.equals("")){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Ecomp Name given."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Ecomp Name given."; + } else if (policyScope==null||policyScope.equalsIgnoreCase("")){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Scope given."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Scope given."; + } else if (!levelCheck){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Incorrect Risk Level given."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "Incorrect Risk Level given."; + } else { + + + StdPAPPolicy newPAPPolicy = new StdPAPPolicy("ClosedLoop_PM", policyName, policyDescription, ecompName, + jsonBody, false, oldPolicyName, serviceType, isEdit, policyScope, 0, riskLevel, riskType, guard, ttlDate); + + //send JSON object to PAP + try { + response = (String) callPAP(newPAPPolicy, new String[] {"operation="+operation, "apiflag=api", "policyType=Config"}, requestID, "ConfigClosedLoop"); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + return response; + + } + + public Boolean validateNONASCIICharactersAndAllowSpaces(Object json){ + Boolean isValidForm = false; + if (json instanceof String) { + String jsonString = (String)json; + if (jsonString.isEmpty()) { + logger.info("JSON String is empty so cannot validate NON ACSII Characters."); + } else { + if(CharMatcher.ASCII.matchesAllOf((CharSequence) jsonString)){ + logger.info("The Value does not contain ASCII Characters"); + isValidForm = true; + }else{ + logger.error("The Value Contains Non ASCII Characters"); + isValidForm = false; + } + } + } else if (json instanceof JsonObject) { + JsonObject jsonObj = (JsonObject)json; + if (jsonObj.isEmpty()){ + logger.info("JSON object is empty so cannot validate NON ACSII Characters."); + } else { + if(CharMatcher.ASCII.matchesAllOf((CharSequence) jsonObj.toString())){ + logger.info("The Value does not contain ASCII Characters"); + isValidForm = true; + }else{ + logger.error("The Value Contains Non ASCII Characters"); + isValidForm = false; + } + } + + } + + return isValidForm; + } + + private String createUpdateMicroServicesPolicy(String policyName, JsonObject microServiceAttributes, String ecompName, String policyScope, Boolean isEdit, UUID requestID, + String riskLevel, String riskType, String guard, String ttlDate) { + + String response = null; + String operation = null; + + if (isEdit){ + operation = "update"; + } else { + operation = "create"; + } + + boolean levelCheck = isNumeric(riskLevel); + + // get values and attributes from the JsonObject + String microService = microServiceAttributes.get("service").toString().replace("\"", ""); + String uuid = microServiceAttributes.get("uuid").toString().replace("\"", ""); + String msLocation = microServiceAttributes.get("location").toString().replace("\"", "");; + String policyDescription = microServiceAttributes.get("description").toString().replace("\"", ""); + String configName = microServiceAttributes.get("configName").toString().replace("\"", ""); + String priority = microServiceAttributes.get("priority").toString().replace("\"", ""); + String version = microServiceAttributes.get("version").toString().replace("\"", ""); + + + if (policyName==null||policyName.equalsIgnoreCase("")){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Name given."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Name given."; + } else if (ecompName==null||ecompName.equals("")){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Ecomp Name given."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Ecomp Name given."; + } else if (configName==null||configName.equalsIgnoreCase("")){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Configuration Name given."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Configuration Name given."; + } else if (policyScope==null||policyScope.equalsIgnoreCase("")){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Scope given."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Scope given."; + } else if (!levelCheck){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Incorrect Risk Level given."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "Incorrect Risk Level given."; + } else { + + + StdPAPPolicy newPAPPolicy = new StdPAPPolicy("DCAE Micro Service", policyName, policyDescription, ecompName, + configName, microService, uuid, msLocation, microServiceAttributes.toString(), priority, + version, isEdit, policyScope, 0, riskLevel, riskType, guard, ttlDate); + + //send JSON object to PAP + try { + response = (String) callPAP(newPAPPolicy, new String[] {"operation="+operation, "apiflag=api", "policyType=Config"}, requestID, "ConfigMS"); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + return response; + + } + + + /* + * Push a policy to the PDP API implementation + */ + public String pushPolicy(String policyScope, String policyName, String policyType, String pdpGroup, UUID requestID) throws Exception { + return pushPolicy(policyScope, policyName, policyType, pdpGroup, requestID, userName, pass); + } + + public String pushPolicy(String policyScope, String policyName, String policyType, String pdpGroup, UUID requestID, String userID, String passcode) throws Exception { + String resource= "pushPolicy"; + if(!checkPermissions(userID, passcode, resource)){ + logger.error(XACMLErrorConstants.ERROR_PERMISSIONS + "You are not allowed to Make this Request. Please contact PolicyAdmin to give access to:" + resource); + return (XACMLErrorConstants.ERROR_PERMISSIONS + "You are not allowed to Make this Request. Please contact PolicyAdmin to give access to:" + resource); + } + String response = null; + String filePrefix = null; + String clientScope = null; + String activeVersion = null; + + //get the client scope based policy type + if (policyType.equalsIgnoreCase("Firewall")){ + clientScope = "ConfigFirewall"; + filePrefix = "Config_FW_"; + } else if (policyType.equalsIgnoreCase("Action")) { + clientScope = "Action"; + filePrefix = "Action_"; + } else if (policyType.equalsIgnoreCase("Decision")){ + clientScope = "Decision"; + filePrefix = "Decision_"; + } else if (policyType.equalsIgnoreCase("Base")){ + clientScope = "Config"; + filePrefix = "Config_"; + } else if (policyType.equalsIgnoreCase("ClosedLoop_Fault")){ + clientScope = "ConfigClosedLoop"; + filePrefix = "Config_Fault_"; + } else if (policyType.equalsIgnoreCase("ClosedLoop_PM")){ + clientScope = "ConfigClosedLoop"; + filePrefix = "Config_PM_"; + } else if (policyType.equalsIgnoreCase("MicroService")) { + clientScope = "ConfigMS"; + filePrefix = "Config_MS_"; + }else if (policyType.equalsIgnoreCase("BRMS_RAW")){ + clientScope = "ConfigBrmsRaw"; + filePrefix = "Config_BRMS_Raw_"; + } else if (policyType.equalsIgnoreCase("BRMS_PARAM")){ + clientScope = "ConfigBrmsParam"; + filePrefix = "Config_BRMS_Param_"; + } else { + clientScope = null; + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + policyType + " is not a valid Policy Type."); + return XACMLErrorConstants.ERROR_DATA_ISSUE + policyType + " is not a valid Policy Type."; + } + + logger.debug("clientScope is " + clientScope); + logger.debug("filePrefix is " + filePrefix); + + if (pdpGroup == null) { + pdpGroup = "default"; + } + + if (policyName==null||policyName.equalsIgnoreCase("")){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Name given."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Name given."; + } else if (policyScope==null||policyScope.equalsIgnoreCase("")){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Scope given."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Scope given."; + } else if (policyType==null||policyType.equalsIgnoreCase("")){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Type given."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Type given."; + } else { + // requestID null check. + if(requestID==null){ + requestID = UUID.randomUUID(); + logger.debug("Request ID not provided. Generating request ID " + requestID.toString()); + } + + // change call to getActiveVersion to pass requestID for PAP to receive on the GET process so PAP won't generate another + // activeVersion = getActiveVersion(policyScope, filePrefix, policyName, clientScope); + activeVersion = getActiveVersion(policyScope, filePrefix, policyName, clientScope, requestID); + logger.debug("The active version of " + policyScope + File.separator + filePrefix + policyName + " is " + activeVersion); + + String id = null; + if (activeVersion.equalsIgnoreCase("pe100")) { + logger.error(XACMLErrorConstants.ERROR_PERMISSIONS + "response code of the URL is 403. PEP is not Authorized for making this Request!! " + + "\n Contact Administrator for this Scope. "); + return XACMLErrorConstants.ERROR_PERMISSIONS + "response code of the URL is 403. PEP is not Authorized for making this Request!! " + + "Contact Administrator for this Scope. "; + + } else if (activeVersion.equalsIgnoreCase("pe300")) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "response code of the URL is 404. " + + "This indicates a problem with getting the version from the PAP or the policy does not exist."); + return XACMLErrorConstants.ERROR_DATA_ISSUE + "response code of the URL is 404. " + + "This indicates a problem with getting the version from the PAP or the policy does not exist."; + } + + + if (!activeVersion.equalsIgnoreCase("0")) { + id = policyScope + "." + filePrefix + policyName + "." + activeVersion + ".xml"; + logger.debug("The policyId is " + id); + } else { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "could not retrieve the activeVersion for this policy. " + + "This indicates the policy does not exist, please verify the policy exists."); + return XACMLErrorConstants.ERROR_DATA_ISSUE + "could not retrieve the activeVersion for this policy. could not retrieve the activeVersion for this policy. " + + "This indicates the policy does not exist, please verify the policy exists."; + } + + // change call to getgitPath to pass requestID for PAP to receive on the GET process so PAP won't generate another + // String gitPath = getGitPath(policyScope, filePrefix, policyName, activeVersion, clientScope); + String gitPath = getGitPath(policyScope, filePrefix, policyName, activeVersion, clientScope, requestID); + logger.debug("Full gitPath policy xml file: " + gitPath); + + // change call to getSelectedURI to pass requestID for PAP to receive on the GET process so PAP won't generate another + // URI selectedURI = getSelectedURI(gitPath, clientScope); + URI selectedURI = getSelectedURI(gitPath, clientScope, requestID); + + logger.debug("The selectedURI is : " + selectedURI.toString()); + String name = filePrefix+policyName; + + StdPDPPolicy selectedPolicy = new StdPDPPolicy(id, true, name, selectedURI, isValid, policyId, description, pushVersion); + + logger.debug("StdPDPPolicy object contains: " + selectedPolicy.getId() + ", " + selectedPolicy.getName() + ", " + selectedPolicy.getLocation().toString()); + + response = copyPolicy(selectedPolicy, pdpGroup, clientScope, requestID); + + logger.debug("copyPolicy response: " + response); + + if(response.contains("successfully")){ + response = (String) callPAP(selectedPolicy, new String[]{"groupId=" + pdpGroup, "policyId="+id, "apiflag=addPolicyToGroup", "operation=PUT"}, requestID, clientScope); + } + + logger.debug("Final API response: " + response); + } + + return response; + + } + + private String deletePolicyFromPAP(DeletePolicyParameters parameters) { + String response = null; + String clientScope = null; + String pdpGroup = parameters.getPdpGroup(); + + if (pdpGroup==null){ + pdpGroup="NA"; + } + + //get the client scope based policy type + if (parameters.getPolicyName().contains("Config_FW")){ + clientScope = "ConfigFirewall"; + } else if (parameters.getPolicyName().contains("Action")) { + clientScope = "Action"; + } else if (parameters.getPolicyName().contains("Decision")){ + clientScope = "Decision"; + } else if (parameters.getPolicyName().contains("Config_Fault")){ + clientScope = "ConfigClosedLoop"; + } else if (parameters.getPolicyName().contains("Config_PM")){ + clientScope = "ConfigClosedLoop"; + } else if (parameters.getPolicyName().contains("Config_MS")){ + clientScope = "ConfigMS"; + } else if (parameters.getPolicyName().contains("Config_BRMS_Raw")){ + clientScope = "ConfigBrmsRaw"; + } else if (parameters.getPolicyName().contains("Config_BRMS_Param")){ + clientScope = "ConfigBrmsParam"; + } else { + clientScope = "Config"; + } + + logger.debug("clientScope is " + clientScope); + + if (clientScope==null||clientScope.equals("")){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + parameters.getPolicyName() + " is not a valid Policy Name."); + return XACMLErrorConstants.ERROR_DATA_ISSUE + parameters.getPolicyName() + " is not a valid Policy Name."; + } + + if (parameters.getPolicyName()==null||parameters.getPolicyName().equalsIgnoreCase("")){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Name given."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Name given."; + } else if (parameters.getDeleteCondition()==null||parameters.getDeleteCondition().equals("")){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Delete Condition given."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Delete Condition given."; + } else { + + StdPAPPolicy deletePapPolicy = new StdPAPPolicy(parameters.getPolicyName(), parameters.getDeleteCondition().toString()); + + //send JSON object to PAP + try { + response = (String) callPAP(deletePapPolicy, new String[] {"groupId="+pdpGroup, "apiflag=deletePapApi", "operation=delete" }, parameters.getRequestID(), clientScope); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + return response; + } + + private String deletePolicyFromPDP(DeletePolicyParameters parameters) { + String response = null; + String clientScope = null; + String pdpGroup = parameters.getPdpGroup(); + + if (pdpGroup==null){ + pdpGroup="NA"; + } + + //get the client scope based policy type + if (parameters.getPolicyName().contains("Config_FW")){ + clientScope = "ConfigFirewall"; + } else if (parameters.getPolicyName().contains("Action")) { + clientScope = "Action"; + } else if (parameters.getPolicyName().contains("Decision")){ + clientScope = "Decision"; + } else if (parameters.getPolicyName().contains("Config_Fault")){ + clientScope = "ConfigClosedLoop"; + } else if (parameters.getPolicyName().contains("Config_PM")){ + clientScope = "ConfigClosedLoop"; + } else if (parameters.getPolicyName().contains("Config_MS")){ + clientScope = "ConfigMS"; + }else if (parameters.getPolicyName().contains("Config_BRMS_Raw")){ + clientScope = "ConfigBrmsRaw"; + } else if (parameters.getPolicyName().contains("Config_BRMS_Param")){ + clientScope = "ConfigBrmsParam"; + } else { + clientScope = "Config"; + } + + logger.debug("clientScope is " + clientScope); + + if (clientScope==null||clientScope.equals("")){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + parameters.getPolicyName() + " is not a valid Policy Name."); + return XACMLErrorConstants.ERROR_DATA_ISSUE + parameters.getPolicyName() + " is not a valid Policy Name."; + } + + if (parameters.getPolicyName()==null||parameters.getPolicyName().equalsIgnoreCase("")){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Name given."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Name given."; + } else if (parameters.getPdpGroup()==null||parameters.getPdpGroup().equals("")){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No PDP Group given."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "No PDP Group given."; + } else { + + //send JSON object to PAP + try { + response = (String) callPAP(null, new String[] {"policyName="+parameters.getPolicyName(), "groupId="+pdpGroup, "apiflag=deletePdpApi", "operation=delete" }, parameters.getRequestID(), clientScope); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + return response; + } + + /* + * Copy a single Policy file from the input stream to the PAP Servlet. + * Either this works (silently) or it throws an exception. + * + */ + public String copyFile(String policyId, String group, StdPAPPolicy location, String clientScope, UUID requestID) throws PAPException { + String response = null; + //String clientScope = null; + + // send the policy file to the PAP Servlet + try { + response = (String) callPAP(location, new String[] {"groupId=" + group, "policyId="+policyId, "apiflag=api", "operation=post"}, requestID, clientScope); + } catch (Exception e) { + String message = "Unable to PUT policy '" + policyId + "', e:" + e; + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + message, e); + throw new PAPException(message); + } + + return response; + } + + public String copyPolicy(PDPPolicy policy, String group, String policyType, UUID requestID) throws PAPException { + String response = null; + + if (policy == null || group == null) { + throw new PAPException("Null input policy="+policy+" group="+group); + } + try { + StdPAPPolicy location = new StdPAPPolicy(policy.getLocation()); + response = copyFile(policy.getId(), group, location, policyType, requestID); + } catch (Exception e) { + String message = "Unable to PUT policy '" + policy.getId() + "', e:" + e; + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + message, e); + throw new PAPException(message); + } + + return response; + } + + public Object callPAP(Object content, String[] parameters, UUID requestID, String clientScope) throws Exception { + String response = null; + HttpURLConnection connection = null; + String requestMethod = null; + String operation = null; + responseCode = 0; + // Checking for the available PDPs is done during the first Request and the List is going to have the connected PDP as first element. + // This makes it Real-Time to change the list depending on their availability. + if (paps == null || paps.isEmpty()) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "PAPs List is Empty."); + throw new Exception(XACMLErrorConstants.ERROR_DATA_ISSUE +"PAPs List is empty."); + }else { + int papsCount = 0; + boolean connected = false; + while (papsCount < paps.size()) { + try { + String fullURL = paps.get(0); + if (parameters != null && parameters.length > 0) { + String queryString = ""; + for (String p : parameters) { + queryString += "&" + p; + if (p.equalsIgnoreCase("operation=post")){ + requestMethod = "POST"; + } else if (p.equalsIgnoreCase("operation=delete")){ + requestMethod = "DELETE"; + operation = "delete"; + } else { + requestMethod = "PUT"; + if (p.equalsIgnoreCase("operation=create")){ + operation = "create"; + } else if (p.equalsIgnoreCase("operation=update")){ + operation = "update"; + } else if (p.equalsIgnoreCase("operation=createDictionary")){ + operation = "createDictionary"; + } + } + } + fullURL += "?" + queryString.substring(1); + } + + URL url = new URL (fullURL); + + //Open the connection + connection = (HttpURLConnection)url.openConnection(); + + // Setting Content-Type + connection.setRequestProperty("Content-Type", + "application/json"); + + // Adding Authorization + connection.setRequestProperty("Authorization", "Basic " + + encodingPAP.get(0)); + + connection.setRequestProperty("Environment", environment); + connection.setRequestProperty("ClientScope", clientScope); + + //set the method and headers + connection.setRequestMethod(requestMethod); + connection.setUseCaches(false); + connection.setInstanceFollowRedirects(false); + connection.setDoOutput(true); + connection.setDoInput(true); + // Adding RequestID + if (requestID == null) { + requestID = UUID.randomUUID(); + logger.info("No request ID provided, sending generated ID: " + requestID.toString()); + } else { + logger.info("Using provided request ID: " + requestID.toString()); + } + connection.setRequestProperty("X-ECOMP-RequestID", requestID.toString()); + + if (content != null) { + if (content instanceof InputStream) { + try { + //send current configuration + try (OutputStream os = connection.getOutputStream()) { + int count = IOUtils.copy((InputStream)content, os); + if (logger.isDebugEnabled()) { + logger.debug("copied to output, bytes=" + count); + } + } + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Failed to write content in 'PUT'", e); + throw e; + } + } else { + // the content is an object to be encoded in JSON + ObjectMapper mapper = new ObjectMapper(); + if(!junit){ + mapper.writeValue(connection.getOutputStream(), content); + } + } + } + + //DO the connect + connection.connect(); + responseCode = connection.getResponseCode(); + // If Connected to PAP then break from the loop and continue with the Request + if (connection.getResponseCode() > 0 || junit) { + connected = true; + break; + + } else { + logger.debug(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "PAP connection Error"); + } + } catch (Exception e) { + // This means that the PAP is not working + if (junit) { + connected = true; + break; + } + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "PAP connection Error : " + e); + } + papsCount++; + } + + if (connected) { + //Read the Response + logger.debug("connected to the PAP : " + paps.get(0)); + logger.debug("--- Response: ---"); + Map> headers = connection.getHeaderFields(); + for (String key : headers.keySet()) { + logger.debug("Header :" + key + " Value: " + headers.get(key)); + } + try { + if (responseCode == 200 || junit) { + + // Check for successful creation of policy + String isSuccess = null; + if(!junit){ //is this a junit test? + isSuccess = connection.getHeaderField("successMapKey"); + operation = connection.getHeaderField("operation"); + } else { + isSuccess = "success"; + } + + if (isSuccess.equals("success")) { + if (operation.equals("update")) { + logger.info("Transaction ID: " + requestID + " --Policy Updated Successfully!" ); + response = "Transaction ID: " + requestID + " --Policy with the name " + connection.getHeaderField("policyName") + " was successfully updated."; + } else if (operation.equals("delete")) { + logger.info("Transaction ID: " + requestID + " --Policy Deleted Successfully!"); + response = "Transaction ID: " + requestID + " --The policy was successfully deleted."; + } else if (operation.equals("import")) { + logger.info("Transaction ID: " + requestID + " --Policy Engine Import Successful!"); + response = "Transaction ID: " + requestID + " --The policy engine import for " + connection.getHeaderField("service") + " was successfull."; + }else { + logger.info("Transaction ID: " + requestID + " --Policy Created Successfully!" ); + response = "Transaction ID: " + requestID + " --Policy with the name " + connection.getHeaderField("policyName") + " was successfully created."; + } + + } else { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Unable to Create/Update the Policy!"); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "Unable to Create/Update the Policy!"; + } + } else if (connection.getResponseCode() == 202) { + if (connection.getHeaderField("operation")!=null && connection.getHeaderField("operation").equalsIgnoreCase("delete")){ + if (connection.getHeaderField("lockdown")!=null && connection.getHeaderField("lockdown").equals("true")){ + logger.warn("Transaction ID: " + requestID + "Policies are locked down."); + response = "Transaction ID: " + requestID + " --Policies are locked down, please try again later."; + } + } + } else if (connection.getResponseCode() == 204) { + if (connection.getHeaderField("operation")!=null && connection.getHeaderField("operation").equals("push")){ + logger.info("Transaction ID: " + requestID + " --Policy '" + connection.getHeaderField("policyId") + + "' was successfully pushed to the PDP group '" + connection.getHeaderField("groupId") + "'."); + response = "Transaction ID: " + requestID + " --Policy '" + connection.getHeaderField("policyId") + + "' was successfully pushed to the PDP group '" + connection.getHeaderField("groupId") + "'."; + } + } else if (connection.getResponseCode() == 400 && connection.getHeaderField("error")!=null){ + if (connection.getHeaderField("error").equals("noPolicyExist")) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Policy does not exist on the PDP."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "Policy does not exist on the PDP."; + } else if (connection.getHeaderField("error").equals("invalidPolicyName")) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Invalid policyName... " + + "policyName must be the full name of the file to be deleted including version and extension"); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "Invalid policyName... " + + "policyName must be the full name of the file to be deleted including version and extension"; + } else if (connection.getHeaderField("error").equals("actionPolicyDB")){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Could not find " + connection.getHeaderField("actionAttribute") + " in the ActionPolicyDict table."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "Invalid actionAttribute given."; + } else if (connection.getHeaderField("error").equals("serviceModelDB")){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Invalid Service or Version. The Service Model, " + + connection.getHeaderField("modelName") + " of version " + connection.getHeaderField("modelVersion") + + " was not found in the dictionary."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "Invalid Service or Version. The Service Model, " + + connection.getHeaderField("modelName") + " of version " + connection.getHeaderField("modelVersion") + + " was not found in the dictionary."; + } else if (connection.getHeaderField("error").equals("FWDBError")){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Error when inserting Firewall ConfigBody data into database."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "Error when inserting Firewall ConfigBody data into the database."; + } else if (connection.getHeaderField("error").equals("savePolicy")){ + logger.error(connection.getHeaderField("message")); + response = connection.getHeaderField("message"); + } + } else if (connection.getResponseCode() == 403) { + logger.error(XACMLErrorConstants.ERROR_PERMISSIONS + "response code of the URL is " + + connection.getResponseCode() + ". PEP is not Authorized for making this Request!! \n Contact Administrator for this Scope. "); + response = XACMLErrorConstants.ERROR_PERMISSIONS + "response code of the URL is " + + connection.getResponseCode() + ". PEP is not Authorized for making this Request!! \n Contact Administrator for this Scope. "; + } else if (connection.getResponseCode() == 404 && connection.getHeaderField("error")!=null) { + if (connection.getHeaderField("error").equals("unknownGroupId")){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + connection.getHeaderField("message")); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + connection.getHeaderField("message") + + " Please check the pdpGroup you are requesting to move the policy to."; + } + } else if (connection.getResponseCode() == 409 && connection.getHeaderField("error")!=null) { + if (connection.getHeaderField("error").equals("modelExistsDB")) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Import Value Exist Error"); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "Import Value Exist Error: The import value "+connection.getHeaderField("service")+" already exist on the PAP. " + + "Please create a new import value."; + }else if (connection.getHeaderField("error").equals("policyExists")){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Policy Exist Error"); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "Policy Exist Error: The Policy "+connection.getHeaderField("policyName")+" already exist on the PAP. " + + "Please create a new policy or use the update API to modify the existing one."; + } + } else if (connection.getResponseCode() == 500 && connection.getHeaderField("error")!=null) { + if (connection.getHeaderField("error").equals("jpautils")){ + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Could not create JPAUtils instance on the PAP"); + response = XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Could not create JPAUtils instance on the PAP"; + } else if (connection.getHeaderField("error").equals("deleteDB")){ + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Failed to delete Policy from database."); + response = XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Failed to delete Policy from database."; + } else if (connection.getHeaderField("error").equals("deleteFile")){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Cannot delete the policy file."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "Cannot delete the policy file"; + } else if (connection.getHeaderField("error").equals("groupUpdate")){ + logger.error(connection.getHeaderField("message")); + response = connection.getHeaderField("message"); + }else if (connection.getHeaderField("error").equals("unknown")){ + logger.error(XACMLErrorConstants.ERROR_UNKNOWN + "Failed to delete the policy for an unknown reason. Check the file system and other logs for further information."); + response = XACMLErrorConstants.ERROR_UNKNOWN + "Failed to delete the policy for an unknown reason. Check the file system and other logs for further information."; + } else if (connection.getHeaderField("error").equals("deleteConfig")){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Cannot delete the configuration or action body file in specified location"); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "Cannot delete the configuration or action body file in specified location."; + }else if (connection.getHeaderField("error").equals("missing")){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Failed to create value in database because service does match a value in file"); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "Failed to create value in database because service does match a value in file"; + }else if (connection.getHeaderField("error").equals("importDB")){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Database errors during policy engine import"); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "Database errors during policy engine import"; + }else if (connection.getHeaderField("error").equals("policyCopyError")){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + connection.getHeaderField("message")); + response = XACMLErrorConstants.ERROR_PROCESS_FLOW + connection.getHeaderField("message"); + }else if (connection.getHeaderField("error").equals("addGroupError")){ + logger.error(connection.getHeaderField("message")); + response = connection.getHeaderField("message"); + }else if (connection.getHeaderField("error").equals("error")){ + logger.error(XACMLErrorConstants.ERROR_UNKNOWN + "Could not create or update the policy for and unknown reason"); + response = XACMLErrorConstants.ERROR_UNKNOWN + "Could not create or update the policy for and unknown reason"; + } + } else { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "BAD REQUEST: Error occured while attempting perform this operation.. the request may be incorrect."); + response = XACMLErrorConstants.ERROR_DATA_ISSUE + "BAD REQUEST: Error occured while attempting perform this operation.. the request may be incorrect."; + } + } catch (IOException e) { + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e); + response = XACMLErrorConstants.ERROR_SYSTEM_ERROR + e; + throw new Exception(XACMLErrorConstants.ERROR_SYSTEM_ERROR +"ERROR in connecting to the PAP ", e); + } + + if (junit){ + response = "success"; + } + return response; + + } else { + response = XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Unable to get valid response from PAP(s) " + paps; + return response; + } + } + + } + + // change getSelectedURI method to receive requestID to be used to send to PAP on the GET request so PAP won't generate another + // private URI getSelectedURI(String gitPath, String clientScope){ + private URI getSelectedURI(String gitPath, String clientScope, UUID requestID){ + //Connect to the PAP + URI selectedURI = null; + HttpURLConnection connection = null; + String [] parameters = {"apiflag=uri", "gitPath="+gitPath}; + + + // Checking for the available PDPs is done during the first Request and the List is going to have the connected PDP as first element. + // This makes it Real-Time to change the list depending on their availability. + if (paps == null || paps.isEmpty()) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "PAPs List is Empty."); + try { + throw new Exception(XACMLErrorConstants.ERROR_DATA_ISSUE +"PAPs List is empty."); + } catch (Exception e) { + logger.error(e.getMessage()); + } + }else { + int papsCount = 0; + boolean connected = false; + while (papsCount < paps.size()) { + try { + String fullURL = paps.get(0); + if (parameters != null && parameters.length > 0) { + String queryString = ""; + for (String p : parameters) { + queryString += "&" + p; + } + fullURL += "?" + queryString.substring(1); + } + + URL url = new URL (fullURL); + + //Open the connection + connection = (HttpURLConnection)url.openConnection(); + + // Setting Content-Type + connection.setRequestProperty("Content-Type", + "application/json"); + + // Adding Authorization + connection.setRequestProperty("Authorization", "Basic " + + encodingPAP.get(0)); + + connection.setRequestProperty("Environment", environment); + connection.setRequestProperty("ClientScope", clientScope); + + //set the method and headers + connection.setRequestMethod("GET"); + connection.setUseCaches(false); + connection.setInstanceFollowRedirects(false); + connection.setDoOutput(true); + connection.setDoInput(true); + + // set requestID in header properties to be used to send to PAP on the GET request so PAP won't generate another + connection.setRequestProperty("X-ECOMP-RequestID", requestID.toString()); + + //DO the connect + connection.connect(); + responseCode = connection.getResponseCode(); + // If Connected to PAP then break from the loop and continue with the Request + if (connection.getResponseCode() > 0) { + connected = true; + break; + + } else { + logger.debug(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "PAP connection Error"); + } + } catch (Exception e) { + // This means that the PAP is not working + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "PAP connection Error : " + e); + } + papsCount++; + } + + if (connected) { + //Read the Response + logger.debug("connected to the PAP : " + paps.get(0)); + logger.debug("--- Response: ---"); + Map> headers = connection.getHeaderFields(); + for (String key : headers.keySet()) { + logger.debug("Header :" + key + " Value: " + headers.get(key)); + } + try { + if (connection.getResponseCode() == 200) { + // Check for successful creation of policy + String uri = connection.getHeaderField("selectedURI"); + logger.debug("URI from Header: " + uri); + if (uri != null && !uri.equalsIgnoreCase("")) { + selectedURI = URI.create(uri); + return selectedURI; + } else { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "could not retrieve the gitPath from the PAP"); + } + } else if (connection.getResponseCode() == 404) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "response code of the URL is " + + connection.getResponseCode() + ". This indicates a problem with getting the gitPath from the PAP"); + } else { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "BAD REQUEST: Error occured while getting the gitPath from the PAP. The request may be incorrect."); + } + } catch (IOException e) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e); + try { + throw new Exception(XACMLErrorConstants.ERROR_DATA_ISSUE +"ERROR in connecting to the PAP ", e); + } catch (Exception e1) { + logger.error(e1.getMessage()); + } + } + + } else { + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Unable to get valid response from PAP(s) " + paps); + try { + throw new Exception(XACMLErrorConstants.ERROR_DATA_ISSUE +"ERROR in connecting to the PAP "); + } catch (Exception e) { + logger.error(e.getMessage()); + } + } + } + return selectedURI; + + } + + // Make a call to the PAP to get the gitPath + // change getGitPath method to receive requestID to be used to send to PAP on the GET request so PAP won't generate another + // private String getGitPath(String policyScope, String filePrefix, String policyName, String activeVersion, String clientScope){ + private String getGitPath(String policyScope, String filePrefix, String policyName, String activeVersion, String clientScope, UUID requestID){ + + //Connect to the PAP + String gitPath = null; + HttpURLConnection connection = null; + String [] parameters = {"apiflag=gitPath", "policyScope="+policyScope, "filePrefix="+filePrefix, + "policyName="+policyName, "activeVersion="+activeVersion}; + + + // Checking for the available PDPs is done during the first Request and the List is going to have the connected PDP as first element. + // This makes it Real-Time to change the list depending on their availability. + if (paps == null || paps.isEmpty()) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "PAPs List is Empty."); + try { + throw new Exception(XACMLErrorConstants.ERROR_DATA_ISSUE +"PAPs List is empty."); + } catch (Exception e) { + logger.error(e.getMessage()); + } + }else { + int papsCount = 0; + boolean connected = false; + while (papsCount < paps.size()) { + try { + String fullURL = paps.get(0); + if (parameters != null && parameters.length > 0) { + String queryString = ""; + for (String p : parameters) { + queryString += "&" + p; + } + fullURL += "?" + queryString.substring(1); + } + + URL url = new URL (fullURL); + + //Open the connection + connection = (HttpURLConnection)url.openConnection(); + + // Setting Content-Type + connection.setRequestProperty("Content-Type", + "application/json"); + + // Adding Authorization + connection.setRequestProperty("Authorization", "Basic " + + encodingPAP.get(0)); + + connection.setRequestProperty("Environment", environment); + connection.setRequestProperty("ClientScope", clientScope); + + //set the method and headers + connection.setRequestMethod("GET"); + connection.setUseCaches(false); + connection.setInstanceFollowRedirects(false); + connection.setDoOutput(true); + connection.setDoInput(true); + + // set requestID in header properties to be used to send to PAP on the GET request so PAP won't generate another + connection.setRequestProperty("X-ECOMP-RequestID", requestID.toString()); + + //DO the connect + connection.connect(); + + // If Connected to PAP then break from the loop and continue with the Request + if (connection.getResponseCode() > 0) { + connected = true; + break; + + } else { + logger.debug(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "PAP connection Error"); + } + } catch (Exception e) { + // This means that the PAP is not working + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "PAP connection Error : " + e); + } + papsCount++; + } + + if (connected) { + //Read the Response + logger.debug("connected to the PAP : " + paps.get(0)); + logger.debug("--- Response: ---"); + Map> headers = connection.getHeaderFields(); + for (String key : headers.keySet()) { + logger.debug("Header :" + key + " Value: " + headers.get(key)); + } + try { + if (connection.getResponseCode() == 200) { + // Check for successful creation of policy + gitPath = connection.getHeaderField("gitPath"); + this.policyId = connection.getHeaderField("policyId"); + this.description = connection.getHeaderField("description"); + this.pushVersion = connection.getHeaderField("version"); + String isValid = connection.getHeaderField("isValid"); + this.isValid = Boolean.parseBoolean(isValid); + + logger.debug("GitPath from Header: " + gitPath); + logger.debug("policyId from Header: " + policyId); + logger.debug("description from Header: " + description); + logger.debug("version from Header: " + pushVersion); + logger.debug("isValid from Header: " + isValid); + + if (gitPath != null && !gitPath.equalsIgnoreCase("")) { + return gitPath; + } else { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "could not retrieve the gitPath from the PAP"); + } + } else if (connection.getResponseCode() == 404) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "response code of the URL is " + + connection.getResponseCode() + ". This indicates a problem with getting the gitPath from the PAP"); + } else { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "BAD REQUEST: Error occured while getting the gitPath from the PAP. The request may be incorrect."); + } + } catch (IOException e) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e); + try { + throw new Exception(XACMLErrorConstants.ERROR_DATA_ISSUE +"ERROR in connecting to the PAP ", e); + } catch (Exception e1) { + logger.error(e1.getMessage()); + } + } + + } else { + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Unable to get valid response from PAP(s) " + paps); + try { + throw new Exception(XACMLErrorConstants.ERROR_DATA_ISSUE +"ERROR in connecting to the PAP "); + } catch (Exception e) { + logger.error(e.getMessage()); + } + } + } + return gitPath; + + } + + // change getActiveVersion method to receive requestID to be used to send to PAP on the GET request so PAP won't generate another +// private String getActiveVersion(String policyScope, String filePrefix, String policyName, String clientScope) { + private String getActiveVersion(String policyScope, String filePrefix, String policyName, String clientScope, UUID requestID) { + + //Connect to the PAP + String version = null; + HttpURLConnection connection = null; + String [] parameters = {"apiflag=version","policyScope="+policyScope, "filePrefix="+filePrefix, "policyName="+policyName}; + + + // Checking for the available PDPs is done during the first Request and the List is going to have the connected PDP as first element. + // This makes it Real-Time to change the list depending on their availability. + if (paps == null || paps.isEmpty()) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "PAPs List is Empty."); + try { + throw new Exception(XACMLErrorConstants.ERROR_DATA_ISSUE +"PAPs List is empty."); + } catch (Exception e) { + logger.error(e.getMessage()); + } + }else { + int papsCount = 0; + boolean connected = false; + while (papsCount < paps.size()) { + try { + String fullURL = paps.get(0); + if (parameters != null && parameters.length > 0) { + String queryString = ""; + for (String p : parameters) { + queryString += "&" + p; + } + fullURL += "?" + queryString.substring(1); + } + + URL url = new URL (fullURL); + + //Open the connection + connection = (HttpURLConnection)url.openConnection(); + + // Setting Content-Type + connection.setRequestProperty("Content-Type", + "application/json"); + + // Adding Authorization + connection.setRequestProperty("Authorization", "Basic " + + encodingPAP.get(0)); + + connection.setRequestProperty("Environment", environment); + connection.setRequestProperty("ClientScope", clientScope); + + + //set the method and headers + connection.setRequestMethod("GET"); + connection.setUseCaches(false); + connection.setInstanceFollowRedirects(false); + connection.setDoOutput(true); + connection.setDoInput(true); + + // set requestID in header properties to be used to send to PAP on the GET request so PAP won't generate another + connection.setRequestProperty("X-ECOMP-RequestID", requestID.toString()); + + //DO the connect + connection.connect(); + + // If Connected to PAP then break from the loop and continue with the Request + if (connection.getResponseCode() > 0) { + connected = true; + break; + + } else { + logger.debug(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "PAP connection Error"); + } + } catch (Exception e) { + // This means that the PAP is not working + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "PAP connection Error : " + e); + } + papsCount++; + } + + if (connected) { + //Read the Response + logger.debug("connected to the PAP : " + paps.get(0)); + logger.debug("--- Response: ---"); + Map> headers = connection.getHeaderFields(); + for (String key : headers.keySet()) { + logger.debug("Header :" + key + " Value: " + headers.get(key)); + } + try { + if (connection.getResponseCode() == 200) { + // Check for successful creation of policy + version = connection.getHeaderField("version"); + logger.debug("ActiveVersion from the Header: " + version); + } else if (connection.getResponseCode() == 403) { + logger.error(XACMLErrorConstants.ERROR_PERMISSIONS + "response code of the URL is " + + connection.getResponseCode() + ". PEP is not Authorized for making this Request!! \n Contact Administrator for this Scope. "); + version = "pe100"; + } else if (connection.getResponseCode() == 404) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "response code of the URL is " + + connection.getResponseCode() + ". This indicates a problem with getting the version from the PAP"); + version = "pe300"; + } else { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "BAD REQUEST: Error occured while getting the version from the PAP. The request may be incorrect."); + } + } catch (IOException e) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e); + try { + throw new Exception(XACMLErrorConstants.ERROR_DATA_ISSUE +"ERROR in connecting to the PAP ", e); + } catch (Exception e1) { + logger.error(e1.getMessage()); + } + } + + } else { + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Unable to get valid response from PAP(s) " + paps); + try { + throw new Exception(XACMLErrorConstants.ERROR_DATA_ISSUE +"ERROR in connecting to the PAP "); + } catch (Exception e) { + logger.error(e.getMessage()); + } + } + } + return version; + } + + // Validation for json inputs + public static boolean isJSONValid(String data) { + try { + new JSONObject(data); + InputStream stream = new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8)); + JsonReader jsonReader = Json.createReader(stream); + logger.debug("Json Value is: " + jsonReader.read().toString() ); + } catch (Exception e) { + return false; + } + return true; + } + + /* + * Rotate the PDP list upon WEBsocket Failures + */ + public static void rotateList() { + Collections.rotate(pdps, -1); + Collections.rotate(encoding, -1); + /* not required for 1510. //TODO uncomment when PAP API has been implemented + * This Broke the PyPDP :( Since there is no PAP LIST yet. + Collections.rotate(paps, -1); + Collections.rotate(encodingPAP, -1); + */ + } + + /* + * Get the latest PDP + */ + public static String getPDPURL() { + return pdps.get(0); + } + + /* + * Get the latest PAP + */ + public static String getPAPURL() { + return paps.get(0); + } + + private JsonObject stringToJsonObject(String value) throws Exception{ + JsonReader jsonReader = Json.createReader(new StringReader(value)); + JsonObject object = jsonReader.readObject(); + jsonReader.close(); + return object; + } + + private String getJsonResponseString() { + String jsonString = "{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:ok\"}}," + + "\"AssociatedAdvice\":[{\"AttributeAssignment\":[{\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + + "\"Issuer\":\"\",\"AttributeId\":\"type\",\"Value\":\"Configuration\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\"}," + + "{\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"Issuer\":\"\",\"AttributeId\":\"URLID\",\"Value\":" + + "\"$URL/Config/JunitTest.Config_testing.1.json\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#anyURI\"},{\"Category\":" + + "\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"Issuer\":\"\",\"AttributeId\":\"PolicyName\",\"Value\":" + + "\"JunitTest.Config_testing.1.xml\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\"},{\"Category\":" + + "\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"Issuer\":\"\",\"AttributeId\":\"VersionNumber\",\"Value\":" + + "\"1\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\"},{\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + + "\"Issuer\":\"\",\"AttributeId\":\"matching:ECOMPName\",\"Value\":\"test\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\"}," + + "{\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"Issuer\":\"\",\"AttributeId\":\"matching:ConfigName\"," + + "\"Value\":\"TestName\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\"},{\"Category\":" + + "\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"Issuer\":\"\",\"AttributeId\":\"matching:service\"," + + "\"Value\":\"ControllerServiceOpendcaeCapsuleServiceInstance\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\"}," + + "{\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"Issuer\":\"\",\"AttributeId\":\"matching:uuid\"," + + "\"Value\":\"TestUUID\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\"},{\"Category\":" + + "\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"Issuer\":\"\",\"AttributeId\":\"matching:Location\"," + + "\"Value\":\"Edge\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\"},{\"Category\":" + + "\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"Issuer\":\"\",\"AttributeId\":\"Priority\",\"Value\":\"1\",\"DataType\":" + + "\"http://www.w3.org/2001/XMLSchema#string\"}],\"Id\":\"MSID\"}],\"Decision\":\"Permit\"}]}"; + + return jsonString; + } + + public PolicyChangeResponse policyEngineImport(ImportParameters importParameters) throws Exception { + return policyEngineImport(importParameters, userName, pass); + } + + public PolicyChangeResponse policyEngineImport(ImportParameters importParameters, String userID, String passcode) throws Exception { + StdPolicyChangeResponse response = new StdPolicyChangeResponse(); + String resource= "policyEngineImport"; + if(!checkPermissions(userID, passcode, resource)){ + logger.error(XACMLErrorConstants.ERROR_PERMISSIONS + "You are not allowed to Make this Request. Please contact PolicyAdmin to give access to:" + resource); + response.setResponseMessage(XACMLErrorConstants.ERROR_PERMISSIONS + "You are not allowed to Make this Request. Please contact PolicyAdmin to give access to:" + resource); + response.setResponseCode(401); + return response; + } + InputStream targetStream = null; + if(importParameters.getServiceName()!=null && importParameters.getVersion()!=null && importParameters.getServiceType()!=null){ + // This is Config Class Policy. + if(importParameters.getFilePath()!=null){ + File input = new File(importParameters.getFilePath()); + if (input.getName().endsWith(".xmi") || input.getName().endsWith(".zip")){ + try { + if (input.exists()){ + targetStream = new FileInputStream(input); + }else { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "File provided in ImportParameters does not exists."); + response.setResponseMessage(XACMLErrorConstants.ERROR_DATA_ISSUE + "File provided in ImportParameters does not exist."); + return response; + } + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Error reading in File"); + response.setResponseMessage(XACMLErrorConstants.ERROR_DATA_ISSUE + "Error in reading in the file provided"); + } + }else{ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Incorrect File Data type."); + response.setResponseMessage(XACMLErrorConstants.ERROR_DATA_ISSUE + "Incorrect File Type Given. Please use a file of type .xmi or .zip."); + return response; + } + String[] parameters = new String[] {"importService=" + importParameters.getServiceType(), "serviceName=" + + importParameters.getServiceName(), "fileName=" + input.getName(), "version=" + importParameters.getVersion()}; + String responseMessage = (String) callPAP(targetStream, parameters, importParameters.getRequestID(), "importMS"); + response.setResponseMessage(responseMessage); + }else{ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Missing required ImportParameters value."); + response.setResponseMessage(XACMLErrorConstants.ERROR_DATA_ISSUE + "Missing required ImportParameters value."); + } + }else{ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Missing required ImportParameters value."); + response.setResponseMessage(XACMLErrorConstants.ERROR_DATA_ISSUE + "Missing required ImportParameters value."); + } + return response; + } + + /* + * Give userID, Passcode and the Resoruce they are requesting for. + */ + private boolean checkPermissions(String userID, String passcode, String resource){ + Boolean result = false; + if(pyPDPClientFile!=null){ + // Backward compatible pyPDP called us. So validate the user names and scope. + Path clientPath = Paths.get(pyPDPClientFile); + if (Files.notExists(clientPath)) { + result = false; + }else if(clientPath.toString().endsWith(".properties")) { + try { + HashMap> clientMap = readProps(clientPath); + if (clientMap.containsKey(userID) && clientMap.get(userID).get(0).equals(passcode)) { + result= true; + } + } catch (Exception e) { + result = false; + } + } + }else{ + //Allowing Every Client who ever don't have access for AAF and Backup Client file + result = true; + } + return result; + } + + private HashMap> readProps(Path clientPath) throws Exception{ + InputStream in; + Properties clientProp = new Properties(); + try { + in = new FileInputStream(clientPath.toFile()); + clientProp.load(in); + } catch (IOException e) { + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e); + throw new Exception(XACMLErrorConstants.ERROR_SYSTEM_ERROR +"Cannot Load the Properties file", e); + } + // Read the Properties and Load the Clients and their scopes. + HashMap>clientMap = new HashMap>(); + // + for (Object propKey : clientProp.keySet()) { + String clientID = (String)propKey; + String clientValue = clientProp.getProperty(clientID); + if (clientValue != null) { + if (clientValue.contains(",")) { + ArrayList clientValues = new ArrayList(Arrays.asList(clientValue.split("\\s*,\\s*"))); + if(clientValues.get(0)!=null || clientValues.get(1)!=null || clientValues.get(0).isEmpty() || clientValues.get(1).isEmpty()){ + clientMap.put(clientID, clientValues); + } + } + } + } + if (clientMap == null || clientMap.isEmpty()) { + logger.debug(XACMLErrorConstants.ERROR_PERMISSIONS + "No Clients ID , Client Key and Scopes are available. Cannot serve any Clients !!"); + throw new Exception("Empty Client file"); + } + return clientMap; + } + + protected boolean isNumeric(String str) + { + for (char c : str.toCharArray()) + { + if (!Character.isDigit(c)) return false; + } + return true; + } + + private String ConvertDate(Date date){ + String strDate = null; + if (date!=null) + { + SimpleDateFormat dateformatJava = new SimpleDateFormat("dd-MM-yyyy"); + strDate = dateformatJava.format(date); + } + + return strDate; + } +} diff --git a/PolicyEngineAPI/src/main/java/org/openecomp/policy/std/StdPolicyResponse.java b/PolicyEngineAPI/src/main/java/org/openecomp/policy/std/StdPolicyResponse.java new file mode 100644 index 000000000..eed40ba2e --- /dev/null +++ b/PolicyEngineAPI/src/main/java/org/openecomp/policy/std/StdPolicyResponse.java @@ -0,0 +1,98 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + + +package org.openecomp.policy.std; + +import java.util.Map; + +import org.openecomp.policy.api.PolicyResponse; +import org.openecomp.policy.api.PolicyResponseStatus; + +/** + * PolicyResponse Implementation class. + * + * @version 0.1 + * + */ +public class StdPolicyResponse implements PolicyResponse{ + private PolicyResponseStatus policyResponseStatus; + private Map actionAdvised; + private Map actionTaken; + private Map requestAttributes; + private String policyResponseMessage; + + @Override + public PolicyResponseStatus getPolicyResponseStatus() { + return policyResponseStatus; + } + + @Override + public Map getActionAdvised() { + return actionAdvised; + } + + @Override + public Map getActionTaken() { + return actionTaken; + } + + @Override + public Map getRequestAttributes() { + return requestAttributes; + } + + @Override + public String getPolicyResponseMessage() { + return policyResponseMessage; + } + + public void setPolicyResponseStatus(PolicyResponseStatus policyResponseStatus) { + this.policyResponseStatus = policyResponseStatus; + } + + public void setActionAdvised(Map actionAdvised) { + this.actionAdvised = actionAdvised; + } + + public void setActionTaken(Map actionTaken) { + this.actionTaken = actionTaken; + } + + public void setRequestAttributes(Map requestAttributes) { + this.requestAttributes = requestAttributes; + } + + public void setPolicyResponseMessage(String policyResponseMessage) { + this.policyResponseMessage = policyResponseMessage; + } + + public void setPolicyResponseStatus(String policyResponseMessage, PolicyResponseStatus policyResponseStatus) { + this.policyResponseMessage = policyResponseMessage; + this.policyResponseStatus = policyResponseStatus; + } + + @Override + public String toString() { + return "PolicyResponse [ policyResponseStatus=" + policyResponseStatus + ", policyResponseMessage=" + policyResponseMessage + ", " + + "" + + "]"; + } +} diff --git a/PolicyEngineAPI/src/main/java/org/openecomp/policy/std/StdStatus.java b/PolicyEngineAPI/src/main/java/org/openecomp/policy/std/StdStatus.java new file mode 100644 index 000000000..a7d22b7cb --- /dev/null +++ b/PolicyEngineAPI/src/main/java/org/openecomp/policy/std/StdStatus.java @@ -0,0 +1,235 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + + +package org.openecomp.policy.std; + +import java.util.Map; +import java.util.Properties; + +import javax.json.JsonObject; + +import org.openecomp.policy.api.DecisionResponse; +import org.openecomp.policy.api.PolicyConfig; +import org.openecomp.policy.api.PolicyConfigStatus; +import org.openecomp.policy.api.PolicyDecision; +import org.openecomp.policy.api.PolicyResponse; +import org.openecomp.policy.api.PolicyResponseStatus; +import org.openecomp.policy.api.PolicyType; +import org.w3c.dom.Document; + +public class StdStatus extends StdPolicyResponse implements PolicyConfig, PolicyResponse, DecisionResponse{ + private PolicyType policyType; + private Properties properties; + private JsonObject jsonObject; + private Document document; + private String other; + private PolicyConfigStatus policyConfigStatus; + private String configStatus; + private PolicyResponseStatus policyResponseStatus; + private Map actionAdvised; + private Map actionTaken; + private Map requestAttributes; + private String policyResponseMessage; + private String policyName; + private String policyVersion; + private Map matchingConditions; + private Map responseAttributes; + private PolicyDecision policyDecision; + private String details; + + public void setStatus(String message, PolicyResponseStatus policyResponseStatus, PolicyConfigStatus policyConfigStatus) { + this.configStatus = message; + this.policyResponseMessage = message; + this.policyResponseStatus = policyResponseStatus; + this.policyConfigStatus = policyConfigStatus; + } + @Override + public PolicyResponseStatus getPolicyResponseStatus() { + return policyResponseStatus; + } + + @Override + public Map getActionAdvised() { + return actionAdvised; + } + + @Override + public Map getActionTaken() { + return actionTaken; + } + + @Override + public Map getRequestAttributes() { + return requestAttributes; + } + + @Override + public String getPolicyResponseMessage() { + return policyResponseMessage; + } + + public void setPolicyResponseStatus(PolicyResponseStatus policyResponseStatus) { + this.policyResponseStatus = policyResponseStatus; + } + + public void setActionAdvised(Map actionAdvised) { + this.actionAdvised = actionAdvised; + } + + public void setActionTaken(Map actionTaken) { + this.actionTaken = actionTaken; + } + + public void setRequestAttributes(Map requestAttributes) { + this.requestAttributes = requestAttributes; + } + + public void setPolicyResponseMessage(String policyResponseMessage) { + this.policyResponseMessage = policyResponseMessage; + } + + public void setPolicyResponseStatus(String policyResponseMessage, PolicyResponseStatus policyResponseStatus) { + this.policyResponseMessage = policyResponseMessage; + this.policyResponseStatus = policyResponseStatus; + } + + @Override + public PolicyType getType() { + return policyType; + } + + @Override + public Properties toProperties() { + return properties; + } + + @Override + public JsonObject toJSON() { + return jsonObject; + } + + @Override + public Document toXML() { + return document; + } + + @Override + public PolicyConfigStatus getPolicyConfigStatus() { + return policyConfigStatus; + } + + @Override + public String getPolicyConfigMessage() { + return configStatus; + } + + @Override + public String getPolicyName() { + if(policyName!=null && policyName.contains(".xml")){ + return (policyName.substring(0, policyName.substring(0, policyName.lastIndexOf(".")).lastIndexOf("."))); + } + return policyName; + } + + @Override + public String getPolicyVersion() { + return policyVersion; + } + + @Override + public Map getMatchingConditions(){ + return matchingConditions; + } + + @Override + public Map getResponseAttributes(){ + return responseAttributes; + } + + public void setPolicyType(PolicyType policyType) { + this.policyType = policyType; + } + + public void setProperties(Properties properties) { + this.properties = properties; + } + + public void setJsonObject(JsonObject jsonObject) { + this.jsonObject = jsonObject; + } + + public void setDocument(Document document) { + this.document = document; + } + + public void setConfigStatus(String configStatus) { + this.configStatus = configStatus; + } + + public void setPolicyName(String policyName) { + this.policyName = policyName; + } + + public void setPolicyVersion(String policyVersion) { + this.policyVersion = policyVersion; + } + + public void setMatchingConditions(Map matchingConditions){ + this.matchingConditions = matchingConditions; + } + + public void setResposneAttributes(Map responseAttributes){ + this.responseAttributes = responseAttributes; + } + + public void setPolicyConfigStatus(PolicyConfigStatus policyConfigStatus) { + this.policyConfigStatus = policyConfigStatus; + } + + public void setPolicyConfigStatus(String configStatus, PolicyConfigStatus policyConfigStatus) { + this.policyConfigStatus = policyConfigStatus; + this.configStatus = configStatus; + } + + @Override + public String toOther() { + return other; + } + + public void setOther(String other) { + this.other = other; + } + + public PolicyDecision getDecision() { + return policyDecision; + } + public void setDecision(PolicyDecision policyDecision) { + this.policyDecision = policyDecision; + } + + public void setDetails(String details){ + this.details = details; + } + + public String getDetails(){ + return details; + } +} diff --git a/PolicyEngineAPI/src/main/java/org/openecomp/policy/std/package-info.java b/PolicyEngineAPI/src/main/java/org/openecomp/policy/std/package-info.java new file mode 100644 index 000000000..a10f347e9 --- /dev/null +++ b/PolicyEngineAPI/src/main/java/org/openecomp/policy/std/package-info.java @@ -0,0 +1,27 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.std; +/** + * Provides standard implementations of the interfaces from the {@link org.openecomp.policy.api} package. + * + * @version 0.3 + * + */ diff --git a/PolicyEngineAPI/src/main/resources/log4j.properties b/PolicyEngineAPI/src/main/resources/log4j.properties new file mode 100644 index 000000000..83a68a767 --- /dev/null +++ b/PolicyEngineAPI/src/main/resources/log4j.properties @@ -0,0 +1,56 @@ +### +# ============LICENSE_START======================================================= +# PolicyEngineAPI +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +# +# Use this properties for debugging and development. +# +# +# Set root logger level to DEBUG and its only appender to A1. +log4j.rootLogger=INFO, FILE + +# A1 is set to be a DailyRollingFileAppender. +log4j.appender.FILE=org.apache.log4j.DailyRollingFileAppender + +# Set the name of the file +log4j.appender.FILE.File=policyEngineLog.log + +# Set the immediate flush to true (default) +log4j.appender.FILE.ImmediateFlush=true + +# Set the threshold to debug mode +log4j.appender.FILE.Threshold=debug + +# Set the append to false, should not overwrite +log4j.appender.FILE.Append=true + +# Set the DatePattern +log4j.appender.FILE.DatePattern='.'yyyy-MM-dd + +# A1 uses PatternLayout. +log4j.appender.FILE.layout=org.apache.log4j.PatternLayout +log4j.appender.FILE.layout.ConversionPattern=%d{yyyy_MM_dd_HH_mm_ss_SSS} [%t] %-5p %l- %m%n + +# For AstraGW feature. +log4j.appender.astra=org.apache.log4j.FileAppender +log4j.appender.astra.File=astragw.log +log4j.appender.astra.layout=org.apache.log4j.PatternLayout +log4j.appender.astra.layout.ConversionPattern=%d{yyyy_MM_dd_HH_mm_ss_SSS} [%t] %-5p %l- %m%n +log4j.category.astraLogger=TRACE, astra +log4j.additivity.astraLogger=false diff --git a/PolicyEngineAPI/src/main/resources/logback.xml b/PolicyEngineAPI/src/main/resources/logback.xml new file mode 100644 index 000000000..dd36a50df --- /dev/null +++ b/PolicyEngineAPI/src/main/resources/logback.xml @@ -0,0 +1,252 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --> + + + + + + + + + + + + + + + + + + + + ${defaultPattern} + + + + + + + + + + + + + ${logDirectory}/${auditLogName}.log + + ${logDirectory}/${auditLogName}.%i.log.zip + + 1 + 9 + + + 5MB + + + ${defaultAuditPattern} + + + + + 256 + + + + + + + + ${logDirectory}/${metricsLogName}.log + + ${logDirectory}/${metricsLogName}.%i.log.zip + + 1 + 9 + + + 5MB + + + + ${defaultMetricPattern} + + + + + 256 + + + + + + + + ${logDirectory}/${errorLogName}.log + + ${logDirectory}/${errorLogName}.%i.log.zip + + 1 + 9 + + + ERROR + + + 5MB + + + ${defaultErrorPattern} + + + + + 256 + + + + + + + ${debugLogDirectory}/${debugLogName}.log + + ${debugLogDirectory}/${debugLogName}.%i.log.zip + + 1 + 9 + + + INFO + + + 5MB + + + ${debugLoggerPattern} + + + + + 256 + + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/AutoClientEndTest.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/AutoClientEndTest.java new file mode 100644 index 000000000..af36d6d71 --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/AutoClientEndTest.java @@ -0,0 +1,312 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.std.test; + +import javax.websocket.Session; + +import org.junit.*; +import org.mockito.Mockito; +import org.openecomp.policy.api.NotificationHandler; +import org.openecomp.policy.api.NotificationScheme; +import org.openecomp.policy.std.AutoClientEnd; +import org.openecomp.policy.std.StdPolicyEngine; + +import static org.junit.Assert.*; + +/** + * The class AutoClientEndTest contains tests for the class {@link AutoClientEnd}. + * + * @generatedBy CodePro at 6/1/16 1:40 PM + * @version $Revision: 1.0 $ + */ +public class AutoClientEndTest { + /** + * Run the AutoClientEnd() constructor test. + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testAutoClientEnd_1() + throws Exception { + AutoClientEnd result = new AutoClientEnd(); + assertNotNull(result); + // add additional test code here + } + + /** + * Run the boolean getStatus() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetStatus_1() + throws Exception { + + boolean result = AutoClientEnd.getStatus(); + + assertNotNull(result); + } + + /** + * Run the String getURL() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetURL_1() + throws Exception { + + String result = AutoClientEnd.getURL(); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.AutoClientEnd + assertNotNull(result); + } + + /** + * Run the void onClose(Session) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testOnClose() + throws Exception { + AutoClientEnd fixture = new AutoClientEnd(); + Session mockSession = Mockito.mock(Session.class); + fixture.onClose(mockSession); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.AutoClientEnd + } + + + /** + * Run the void onError(Session,Throwable) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testOnError() + throws Exception { + AutoClientEnd fixture = new AutoClientEnd(); + Session mockSession = Mockito.mock(Session.class); + Throwable e = new Throwable(); + + fixture.onError(mockSession, e); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.AutoClientEnd + } + + /** + * Run the void onMessage(String,Session) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testOnMessage() + throws Exception { + AutoClientEnd fixture = new AutoClientEnd(); + Session mockSession = Mockito.mock(Session.class); + String message = ""; + //Session session = null; + + fixture.onMessage(message, mockSession); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.AutoClientEnd + } + + + /** + * Run the void onOpen(Session) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testOnOpen() + throws Exception { + AutoClientEnd fixture = new AutoClientEnd(); + Session mockSession = Mockito.mock(Session.class); + + fixture.onOpen(mockSession); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.AutoClientEnd + } + + /** + * Run the void setAuto(NotificationScheme,NotificationHandler) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetAuto() + throws Exception { + NotificationScheme scheme = NotificationScheme.AUTO_ALL_NOTIFICATIONS; + NotificationHandler handler = null; + + AutoClientEnd.setAuto(scheme, handler); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.ExceptionInInitializerError + // at org.apache.log4j.Logger.getLogger(Logger.java:104) + // at org.openecomp.policy.std.AutoClientEnd.(AutoClientEnd.java:39) + } + + /** + * Run the void setScheme(NotificationScheme) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetScheme() + throws Exception { + + NotificationScheme scheme = NotificationScheme.AUTO_ALL_NOTIFICATIONS; + AutoClientEnd.setScheme(scheme); + + } + + /** + * Run the void start(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testStart() + throws Exception { + String url = "http://test.com"; + + AutoClientEnd.start(url); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.AutoClientEnd + } + + + /** + * Run the void start(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testStart_2() + throws Exception { + String url = null; + + AutoClientEnd.start(url); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.AutoClientEnd + } + + /** + * Run the void stop() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testStop_1() + throws Exception { + + AutoClientEnd.stop(); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.AutoClientEnd + } + + /** + * Perform pre-test initialization. + * + * @throws Exception + * if the initialization fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Before + public void setUp() + throws Exception { + // add set up code here + StdPolicyEngine policyEngine = new StdPolicyEngine("Test/config_pass.properties"); + + NotificationHandler handler = policyEngine.getNotificationHandler(); + AutoClientEnd.setAuto(NotificationScheme.AUTO_ALL_NOTIFICATIONS, handler); + AutoClientEnd.start("http://testurl.com"); + + } + + /** + * Perform post-test clean-up. + * + * @throws Exception + * if the clean-up fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @After + public void tearDown() + throws Exception { + // Add additional tear down code here + } + + /** + * Launch the test. + * + * @param args the command line arguments + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(AutoClientEndTest.class); + } +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/AutoClientUEBTest.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/AutoClientUEBTest.java new file mode 100644 index 000000000..f6760056f --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/AutoClientUEBTest.java @@ -0,0 +1,569 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.std.test; + +import java.util.LinkedList; +import java.util.List; + +import org.junit.*; +import org.openecomp.policy.api.NotificationHandler; +import org.openecomp.policy.api.NotificationScheme; +import org.openecomp.policy.std.AutoClientEnd; +import org.openecomp.policy.std.AutoClientUEB; +import org.openecomp.policy.std.StdPolicyEngine; + +import static org.junit.Assert.*; + +/** + * The class AutoClientUEBTest contains tests for the class {@link AutoClientUEB}. + * + * @generatedBy CodePro at 6/1/16 1:40 PM + * @version $Revision: 1.0 $ + */ +public class AutoClientUEBTest { + /** + * Run the AutoClientUEB(String,List) constructor test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testAutoClientUEB_1() + throws Exception { + String url = ""; + List uebURLList = new LinkedList(); + + AutoClientUEB result = new AutoClientUEB(url, uebURLList); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.ExceptionInInitializerError + // at org.apache.log4j.Logger.getLogger(Logger.java:104) + // at org.openecomp.policy.std.AutoClientUEB.(AutoClientUEB.java:39) + assertNotNull(result); + } + + /** + * Run the String getNotficationType() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetNotficationType_1() + throws Exception { + + String result = AutoClientUEB.getNotficationType(); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.AutoClientUEB + assertNull(result); + } + + /** + * Run the boolean getStatus() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetStatus_1() + throws Exception { + + boolean result = AutoClientUEB.getStatus(); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.AutoClientUEB + assertFalse(result); + } + + /** + * Run the String getURL() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetURL_1() + throws Exception { + + String result = AutoClientUEB.getURL(); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.AutoClientUEB + assertNotNull(result); + } + + /** + * Run the boolean isRunning() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testIsRunning_1() + throws Exception { + AutoClientUEB fixture = new AutoClientUEB("", new LinkedList()); + fixture.isRunning = true; + + boolean result = fixture.isRunning(); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.AutoClientUEB + assertTrue(result); + } + + /** + * Run the void run() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testRun_1() + throws Exception { + AutoClientUEB fixture = new AutoClientUEB("", new LinkedList()); + fixture.isRunning = true; + + fixture.run(); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.AutoClientUEB + } + + /** + * Run the void run() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testRun_2() + throws Exception { + AutoClientUEB fixture = new AutoClientUEB("", new LinkedList()); + fixture.isRunning = true; + + fixture.run(); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.AutoClientUEB + } + + /** + * Run the void run() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testRun_3() + throws Exception { + AutoClientUEB fixture = new AutoClientUEB("", new LinkedList()); + fixture.isRunning = true; + + fixture.run(); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.AutoClientUEB + } + + /** + * Run the void run() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testRun_4() + throws Exception { + AutoClientUEB fixture = new AutoClientUEB("", new LinkedList()); + fixture.isRunning = true; + + fixture.run(); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.AutoClientUEB + } + + /** + * Run the void run() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testRun_5() + throws Exception { + AutoClientUEB fixture = new AutoClientUEB("", new LinkedList()); + fixture.isRunning = true; + + fixture.run(); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.AutoClientUEB + } + + /** + * Run the void run() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testRun_6() + throws Exception { + AutoClientUEB fixture = new AutoClientUEB("", new LinkedList()); + fixture.isRunning = true; + + fixture.run(); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.AutoClientUEB + } + + /** + * Run the void run() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testRun_7() + throws Exception { + AutoClientUEB fixture = new AutoClientUEB("", new LinkedList()); + fixture.isRunning = true; + + fixture.run(); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.AutoClientUEB + } + + /** + * Run the void run() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testRun_8() + throws Exception { + AutoClientUEB fixture = new AutoClientUEB("", new LinkedList()); + fixture.isRunning = true; + + fixture.run(); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.AutoClientUEB + } + + /** + * Run the void run() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testRun_9() + throws Exception { + AutoClientUEB fixture = new AutoClientUEB("", new LinkedList()); + fixture.isRunning = true; + + fixture.run(); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.AutoClientUEB + } + + /** + * Run the void run() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testRun_10() + throws Exception { + AutoClientUEB fixture = new AutoClientUEB("", new LinkedList()); + fixture.isRunning = true; + + fixture.run(); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.AutoClientUEB + } + + /** + * Run the void run() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testRun_11() + throws Exception { + AutoClientUEB fixture = new AutoClientUEB("", new LinkedList()); + fixture.isRunning = true; + + fixture.run(); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.AutoClientUEB + } + + /** + * Run the void run() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testRun_12() + throws Exception { + AutoClientUEB fixture = new AutoClientUEB("", new LinkedList()); + fixture.isRunning = true; + + fixture.run(); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.AutoClientUEB + } + + /** + * Run the void run() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testRun_13() + throws Exception { + AutoClientUEB fixture = new AutoClientUEB("", new LinkedList()); + fixture.isRunning = true; + + fixture.run(); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.AutoClientUEB + } + + /** + * Run the void run() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testRun_14() + throws Exception { + AutoClientUEB fixture = new AutoClientUEB("", new LinkedList()); + fixture.isRunning = true; + + fixture.run(); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.AutoClientUEB + } + + /** + * Run the void run() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testRun_15() + throws Exception { + AutoClientUEB fixture = new AutoClientUEB("", new LinkedList()); + fixture.isRunning = true; + + fixture.run(); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.AutoClientUEB + } + + /** + * Run the void run() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testRun_16() + throws Exception { + AutoClientUEB fixture = new AutoClientUEB("", new LinkedList()); + fixture.isRunning = true; + + fixture.run(); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.AutoClientUEB + } + + /** + * Run the void setAuto(NotificationScheme,NotificationHandler) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetAuto_1() + throws Exception { + AutoClientUEB fixture = new AutoClientUEB("", new LinkedList()); + fixture.isRunning = true; + NotificationScheme scheme = NotificationScheme.AUTO_ALL_NOTIFICATIONS; + NotificationHandler handler = null; + + fixture.setAuto(scheme, handler); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.AutoClientUEB + } + + /** + * Run the void setScheme(NotificationScheme) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetScheme_1() + throws Exception { + NotificationScheme scheme = NotificationScheme.AUTO_ALL_NOTIFICATIONS; + + AutoClientUEB.setScheme(scheme); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.AutoClientUEB + } + + /** + * Run the void terminate() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testTerminate_1() + throws Exception { + AutoClientUEB fixture = new AutoClientUEB("", new LinkedList()); + fixture.isRunning = true; + + fixture.terminate(); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.AutoClientUEB + } + + /** + * Perform pre-test initialization. + * + * @throws Exception + * if the initialization fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Before + public void setUp() + throws Exception { + // add set up code here + StdPolicyEngine policyEngine = new StdPolicyEngine("Test/config_pass.properties"); + List urlList = new LinkedList(); + urlList.add("test2.com"); + AutoClientUEB client = new AutoClientUEB("test.com", urlList); + NotificationHandler handler = null; + //AutoClientEnd.setAuto(NotificationScheme.AUTO_ALL_NOTIFICATIONS, handler); + client.setAuto(NotificationScheme.AUTO_ALL_NOTIFICATIONS, handler); + } + + /** + * Perform post-test clean-up. + * + * @throws Exception + * if the clean-up fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @After + public void tearDown() + throws Exception { + // Add additional tear down code here + } + + /** + * Launch the test. + * + * @param args the command line arguments + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(AutoClientUEBTest.class); + } +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/Handler.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/Handler.java new file mode 100644 index 000000000..e1e398e1a --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/Handler.java @@ -0,0 +1,120 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.std.test; + +import java.util.Collection; + +import org.openecomp.policy.api.LoadedPolicy; +import org.openecomp.policy.api.NotificationHandler; +import org.openecomp.policy.api.NotificationType; +import org.openecomp.policy.api.PDPNotification; +import org.openecomp.policy.api.PolicyConfig; +import org.openecomp.policy.api.PolicyConfigException; +import org.openecomp.policy.api.PolicyConfigStatus; +import org.openecomp.policy.api.PolicyEngine; +import org.openecomp.policy.api.PolicyEngineException; +import org.openecomp.policy.api.RemovedPolicy; + +public class Handler implements NotificationHandler{ + + @Override + public void notificationReceived(PDPNotification notification) { + System.out.println("Notification Received..."); + System.out.println(notification.getNotificationType()); + if(notification.getNotificationType().equals(NotificationType.REMOVE)){ + System.out.println("Removed Policies: \n"); + for(RemovedPolicy removedPolicy: notification.getRemovedPolicies()){ + System.out.println(removedPolicy.getPolicyName()); + System.out.println(removedPolicy.getVersionNo()); + } + }else if(notification.getNotificationType().equals(NotificationType.UPDATE)){ + System.out.println("Updated Policies: \n"); + for(LoadedPolicy updatedPolicy: notification.getLoadedPolicies()){ + System.out.println("policyName : " + updatedPolicy.getPolicyName()); + System.out.println("policyVersion :" + updatedPolicy.getVersionNo()); + if(updatedPolicy.getPolicyName().contains(".Config_")){ + System.out.println("Matches: " + updatedPolicy.getMatches()); + System.out.println("UpdateType: "+ updatedPolicy.getUpdateType()); + // Checking the Name is correct or not. + try { + PolicyEngine policyEngine = new PolicyEngine("config.properties"); + Collection policyConfigs = policyEngine.getConfigByPolicyName(updatedPolicy.getPolicyName()); + for(PolicyConfig policyConfig: policyConfigs){ + if(policyConfig.getPolicyConfigStatus().equals(PolicyConfigStatus.CONFIG_RETRIEVED)){ + System.out.println("Policy Retrieved with this Name notified. "); + }else{ + System.err.println("\n\n Fail to retrieve policy !!!!\n\n"); + } + // Also Test this case. + if(policyConfig.getPolicyName().equals(updatedPolicy.getPolicyName())){ + System.out.println("Policy Name is good. "); + }else{ + System.err.println("\n\n Fail to check Name \n\n"); + } + } + } catch (PolicyEngineException e) { + e.printStackTrace(); + } catch (PolicyConfigException e) { + e.printStackTrace(); + } + } + } + }else if(notification.getNotificationType().equals(NotificationType.BOTH)){ + System.out.println("Both updated and Removed Notification: \n"); + System.out.println("Removed Policies: \n"); + for(RemovedPolicy removedPolicy: notification.getRemovedPolicies()){ + System.out.println(removedPolicy.getPolicyName()); + System.out.println(removedPolicy.getVersionNo()); + } + System.out.println("Updated Policies: \n"); + for(LoadedPolicy updatedPolicy: notification.getLoadedPolicies()){ + System.out.println("policyName : " + updatedPolicy.getPolicyName()); + System.out.println("policyVersion :" + updatedPolicy.getVersionNo()); + System.out.println("Matches: " + updatedPolicy.getMatches()); + System.out.println("UpdateType: "+ updatedPolicy.getUpdateType()); + // Checking the Name is correct or not. + try { + PolicyEngine policyEngine = new PolicyEngine("config.properties"); + Collection policyConfigs = policyEngine.getConfigByPolicyName(updatedPolicy.getPolicyName()); + for(PolicyConfig policyConfig: policyConfigs){ + if(policyConfig.getPolicyConfigStatus().equals(PolicyConfigStatus.CONFIG_RETRIEVED)){ + System.out.println("Policy Retrieved with this Name notified. "); + }else{ + System.err.println("\n\n Fail to retrieve policy !!!!\n\n"); + } + // Also Test this case. + if(policyConfig.getPolicyName().equals(updatedPolicy.getPolicyName())){ + System.out.println("Policy Name is good. "); + }else{ + System.err.println("\n\n Fail to check Name \n\n"); + } + } + } catch (PolicyEngineException e) { + e.printStackTrace(); + } catch (PolicyConfigException e) { + e.printStackTrace(); + } + } + } + } + + +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/ManualClientEndTest.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/ManualClientEndTest.java new file mode 100644 index 000000000..21cb14f6a --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/ManualClientEndTest.java @@ -0,0 +1,195 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.std.test; + +import javax.websocket.Session; + +import org.junit.*; +import org.mockito.Mockito; +import org.openecomp.policy.api.NotificationScheme; +import org.openecomp.policy.api.PDPNotification; +import org.openecomp.policy.std.ManualClientEnd; + +import static org.junit.Assert.*; + +/** + * The class ManualClientEndTest contains tests for the class {@link ManualClientEnd}. + * + * @generatedBy CodePro at 6/1/16 1:41 PM + * @version $Revision: 1.0 $ + */ +public class ManualClientEndTest { + /** + * Run the ManualClientEnd() constructor test. + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testManualClientEnd_1() + throws Exception { + ManualClientEnd result = new ManualClientEnd(); + assertNotNull(result); + // add additional test code here + } + + /** + * Run the void onClose(Session) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testOnClose() + throws Exception { + ManualClientEnd fixture = Mockito.mock(ManualClientEnd.class); + Session mockSession = Mockito.mock(Session.class); + + fixture.onClose(mockSession); + + } + + /** + * Run the void onError(Session,Throwable) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testOnError() + throws Exception { + ManualClientEnd fixture = Mockito.mock(ManualClientEnd.class); + Session mockSession = Mockito.mock(Session.class); + Throwable e = new Throwable(); + + fixture.onError(mockSession, e); + } + + /** + * Run the void onMessage(String,Session) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testOnMessage() + throws Exception { + ManualClientEnd fixture = new ManualClientEnd(); + ManualClientEnd mockclient = Mockito.mock(ManualClientEnd.class); + String message = ""; + Session mockSession = Mockito.mock(Session.class); + + Mockito.doNothing().when(mockclient).onMessage(message,mockSession); + mockclient.onMessage(message,mockSession); + } + + /** + * Run the void onOpen(Session) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testOnOpen() + throws Exception { + ManualClientEnd fixture = Mockito.mock(ManualClientEnd.class); + Session mockSession = Mockito.mock(Session.class); + + fixture.onOpen(mockSession); + + } + + /** + * Run the PDPNotification result(NotificationScheme) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testResult_1() + throws Exception { + NotificationScheme scheme = NotificationScheme.AUTO_ALL_NOTIFICATIONS; + + PDPNotification result = ManualClientEnd.result(scheme); + + assertNull(result); + } + + + /** + * Run the void start(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testStart_1() + throws Exception { + String url = ""; + + ManualClientEnd.start(url); + + } + + /** + * Perform pre-test initialization. + * + * @throws Exception + * if the initialization fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Before + public void setUp() + throws Exception { + // add additional set up code here + } + + /** + * Perform post-test clean-up. + * + * @throws Exception + * if the clean-up fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @After + public void tearDown() + throws Exception { + // Add additional tear down code here + } + + /** + * Launch the test. + * + * @param args the command line arguments + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(ManualClientEndTest.class); + } +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/ManualClientEndUEBTest.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/ManualClientEndUEBTest.java new file mode 100644 index 000000000..fedcc9992 --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/ManualClientEndUEBTest.java @@ -0,0 +1,164 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.std.test; + +import java.util.LinkedList; +import java.util.List; + +import org.junit.*; +import org.mockito.Mockito; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; +import org.openecomp.policy.api.NotificationScheme; +import org.openecomp.policy.api.PDPNotification; +import org.openecomp.policy.std.ManualClientEndUEB; +import org.openecomp.policy.std.NotificationUnMarshal; +import org.openecomp.policy.std.StdPDPNotification; + +import static org.junit.Assert.*; + +/** + * The class ManualClientEndUEBTest contains tests for the class {@link ManualClientEndUEB}. + * + * @generatedBy CodePro at 6/1/16 1:40 PM + * @version $Revision: 1.0 $ + */ +public class ManualClientEndUEBTest { + + String resultJson = "{'test':'testing'}"; + String json = "{\"test\":\"testing\"}"; + StdPDPNotification notification = new StdPDPNotification(); + ManualClientEndUEB mockManualClient = null; + /** + * Perform pre-test initialization. + * + * @throws Exception + * if the initialization fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Before + public void setUp() + throws Exception { + String url = "http://test.com"; + String uniqueID = "test"; + List uebURLList = new LinkedList(); + uebURLList.add(url); + + } + /** + * Run the ManualClientEndUEB() constructor test. + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testManualClientEndUEB_1() + throws Exception { + ManualClientEndUEB result = new ManualClientEndUEB(); + assertNotNull(result); + // add additional test code here + } + + /** + * Run the void createTopic(String,String,List) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testCreateTopic_1() + throws Exception { + String url = "http://test.com"; + String uniqueID = "test"; + List uebURLList = new LinkedList(); + uebURLList.add(url); + + ManualClientEndUEB.createTopic(url, uniqueID, uebURLList); + + } + + /** + * Run the PDPNotification result(NotificationScheme) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testResult_1() + throws Exception { + NotificationScheme scheme = NotificationScheme.AUTO_ALL_NOTIFICATIONS; + + PDPNotification result = ManualClientEndUEB.result(scheme); + + assertNull(result); + } + + + /** + * Run the void start(String,List,String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testStart_1() + throws Exception { + String url = "http://test.com"; + List uebURLList = new LinkedList(); + String uniqueID = "test"; + uebURLList.add(url); + + ManualClientEndUEB.start(url, uebURLList, uniqueID); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.ManualClientEndUEB + } + + + /** + * Perform post-test clean-up. + * + * @throws Exception + * if the clean-up fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @After + public void tearDown() + throws Exception { + // Add additional tear down code here + } + + /** + * Launch the test. + * + * @param args the command line arguments + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(ManualClientEndUEBTest.class); + } +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/MatchStoreTest.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/MatchStoreTest.java new file mode 100644 index 000000000..917e9d5e6 --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/MatchStoreTest.java @@ -0,0 +1,774 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.std.test; + +import java.util.HashSet; +import java.util.Hashtable; +import java.util.Map; + +import org.junit.*; +import org.openecomp.policy.api.PDPNotification; +import org.openecomp.policy.std.MatchStore; +import org.openecomp.policy.std.Matches; +import org.openecomp.policy.std.StdPDPNotification; + +import static org.junit.Assert.*; + +/** + * The class MatchStoreTest contains tests for the class {@link MatchStore}. + * + * @generatedBy CodePro at 6/1/16 1:41 PM + * @version $Revision: 1.0 $ + */ +public class MatchStoreTest { + /** + * Run the MatchStore() constructor test. + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testMatchStore_1() + throws Exception { + MatchStore result = new MatchStore(); + assertNotNull(result); + // add additional test code here + } + + /** + * Run the PDPNotification checkMatch(PDPNotification) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testCheckMatch_1() + throws Exception { + PDPNotification oldNotification = null; + + PDPNotification result = MatchStore.checkMatch(oldNotification); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.MatchStore + assertNull(result); + } + + /** + * Run the PDPNotification checkMatch(PDPNotification) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testCheckMatch_2() + throws Exception { + PDPNotification oldNotification = new StdPDPNotification(); + + PDPNotification result = MatchStore.checkMatch(oldNotification); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.MatchStore + assertNotNull(result); + } + + /** + * Run the PDPNotification checkMatch(PDPNotification) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testCheckMatch_3() + throws Exception { + PDPNotification oldNotification = new StdPDPNotification(); + + PDPNotification result = MatchStore.checkMatch(oldNotification); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.MatchStore + assertNotNull(result); + } + + /** + * Run the PDPNotification checkMatch(PDPNotification) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testCheckMatch_4() + throws Exception { + PDPNotification oldNotification = new StdPDPNotification(); + + PDPNotification result = MatchStore.checkMatch(oldNotification); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.MatchStore + assertNotNull(result); + } + + /** + * Run the PDPNotification checkMatch(PDPNotification) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testCheckMatch_5() + throws Exception { + PDPNotification oldNotification = new StdPDPNotification(); + + PDPNotification result = MatchStore.checkMatch(oldNotification); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.MatchStore + assertNotNull(result); + } + + /** + * Run the PDPNotification checkMatch(PDPNotification) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testCheckMatch_6() + throws Exception { + PDPNotification oldNotification = new StdPDPNotification(); + + PDPNotification result = MatchStore.checkMatch(oldNotification); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.MatchStore + assertNotNull(result); + } + + /** + * Run the PDPNotification checkMatch(PDPNotification) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testCheckMatch_7() + throws Exception { + PDPNotification oldNotification = new StdPDPNotification(); + + PDPNotification result = MatchStore.checkMatch(oldNotification); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.MatchStore + assertNotNull(result); + } + + /** + * Run the PDPNotification checkMatch(PDPNotification) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testCheckMatch_8() + throws Exception { + PDPNotification oldNotification = new StdPDPNotification(); + + PDPNotification result = MatchStore.checkMatch(oldNotification); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.MatchStore + assertNotNull(result); + } + + /** + * Run the PDPNotification checkMatch(PDPNotification) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testCheckMatch_9() + throws Exception { + PDPNotification oldNotification = new StdPDPNotification(); + + PDPNotification result = MatchStore.checkMatch(oldNotification); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.MatchStore + assertNotNull(result); + } + + /** + * Run the PDPNotification checkMatch(PDPNotification) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testCheckMatch_10() + throws Exception { + PDPNotification oldNotification = new StdPDPNotification(); + + PDPNotification result = MatchStore.checkMatch(oldNotification); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.MatchStore + assertNotNull(result); + } + + /** + * Run the PDPNotification checkMatch(PDPNotification) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testCheckMatch_11() + throws Exception { + PDPNotification oldNotification = new StdPDPNotification(); + + PDPNotification result = MatchStore.checkMatch(oldNotification); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.MatchStore + assertNotNull(result); + } + + /** + * Run the PDPNotification checkMatch(PDPNotification) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testCheckMatch_12() + throws Exception { + PDPNotification oldNotification = new StdPDPNotification(); + + PDPNotification result = MatchStore.checkMatch(oldNotification); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.MatchStore + assertNotNull(result); + } + + /** + * Run the PDPNotification checkMatch(PDPNotification) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testCheckMatch_13() + throws Exception { + PDPNotification oldNotification = new StdPDPNotification(); + + PDPNotification result = MatchStore.checkMatch(oldNotification); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.MatchStore + assertNotNull(result); + } + + /** + * Run the PDPNotification checkMatch(PDPNotification) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testCheckMatch_14() + throws Exception { + PDPNotification oldNotification = new StdPDPNotification(); + + PDPNotification result = MatchStore.checkMatch(oldNotification); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.MatchStore + assertNotNull(result); + } + + /** + * Run the PDPNotification checkMatch(PDPNotification) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testCheckMatch_15() + throws Exception { + PDPNotification oldNotification = new StdPDPNotification(); + + PDPNotification result = MatchStore.checkMatch(oldNotification); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.MatchStore + assertNotNull(result); + } + + /** + * Run the PDPNotification checkMatch(PDPNotification) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testCheckMatch_16() + throws Exception { + PDPNotification oldNotification = new StdPDPNotification(); + + PDPNotification result = MatchStore.checkMatch(oldNotification); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.MatchStore + assertNotNull(result); + } + + /** + * Run the HashSet getMatchStore() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testGetMatchStore_1() + throws Exception { + + HashSet result = MatchStore.getMatchStore(); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.ExceptionInInitializerError + // at org.apache.log4j.Logger.getLogger(Logger.java:104) + // at org.openecomp.policy.std.MatchStore.(MatchStore.java:15) + assertNotNull(result); + } + + /** + * Run the void storeMatch(Matches) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testStoreMatch_1() + throws Exception { + Matches newMatch = new Matches(); + newMatch.setConfigName(""); + newMatch.setEcompName(""); + + MatchStore.storeMatch(newMatch); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.MatchStore + } + + /** + * Run the void storeMatch(Matches) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testStoreMatch_2() + throws Exception { + Matches newMatch = new Matches(); + newMatch.setConfigName(""); + newMatch.setEcompName(""); + + MatchStore.storeMatch(newMatch); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.MatchStore + } + + /** + * Run the void storeMatch(Matches) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testStoreMatch_3() + throws Exception { + Matches newMatch = new Matches(); + newMatch.setConfigName(""); + newMatch.setEcompName(""); + + MatchStore.storeMatch(newMatch); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.MatchStore + } + + /** + * Run the void storeMatch(Matches) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testStoreMatch_4() + throws Exception { + Matches newMatch = new Matches(); + newMatch.setConfigAttributes(new Hashtable()); + newMatch.setConfigName(""); + newMatch.setEcompName(""); + + MatchStore.storeMatch(newMatch); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.MatchStore + } + + /** + * Run the void storeMatch(Matches) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testStoreMatch_5() + throws Exception { + Matches newMatch = new Matches(); + newMatch.setConfigAttributes(new Hashtable()); + newMatch.setConfigName(""); + newMatch.setEcompName(""); + + MatchStore.storeMatch(newMatch); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.MatchStore + } + + /** + * Run the void storeMatch(Matches) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testStoreMatch_6() + throws Exception { + Matches newMatch = new Matches(); + newMatch.setConfigAttributes(new Hashtable()); + newMatch.setConfigName(""); + newMatch.setEcompName(""); + + MatchStore.storeMatch(newMatch); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.MatchStore + } + + /** + * Run the void storeMatch(Matches) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testStoreMatch_7() + throws Exception { + Matches newMatch = new Matches(); + newMatch.setConfigAttributes(new Hashtable()); + newMatch.setConfigName(""); + newMatch.setEcompName(""); + + MatchStore.storeMatch(newMatch); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.MatchStore + } + + /** + * Run the void storeMatch(Matches) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testStoreMatch_8() + throws Exception { + Matches newMatch = new Matches(); + newMatch.setConfigName(""); + newMatch.setEcompName(""); + + MatchStore.storeMatch(newMatch); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.MatchStore + } + + /** + * Run the void storeMatch(Matches) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testStoreMatch_9() + throws Exception { + Matches newMatch = new Matches(); + newMatch.setEcompName(""); + + MatchStore.storeMatch(newMatch); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.MatchStore + } + + /** + * Run the void storeMatch(Matches) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testStoreMatch_10() + throws Exception { + Matches newMatch = new Matches(); + newMatch.setConfigAttributes(new Hashtable()); + newMatch.setConfigName(""); + newMatch.setEcompName(""); + + MatchStore.storeMatch(newMatch); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.MatchStore + } + + /** + * Run the void storeMatch(Matches) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testStoreMatch_11() + throws Exception { + Matches newMatch = new Matches(); + newMatch.setConfigAttributes(new Hashtable()); + newMatch.setConfigName(""); + newMatch.setEcompName(""); + + MatchStore.storeMatch(newMatch); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.MatchStore + } + + /** + * Run the void storeMatch(Matches) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testStoreMatch_12() + throws Exception { + Matches newMatch = new Matches(); + newMatch.setConfigAttributes(new Hashtable()); + newMatch.setConfigName(""); + newMatch.setEcompName(""); + + MatchStore.storeMatch(newMatch); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.MatchStore + } + + /** + * Run the void storeMatch(Matches) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testStoreMatch_13() + throws Exception { + Matches newMatch = new Matches(); + newMatch.setConfigAttributes(new Hashtable()); + newMatch.setConfigName(""); + newMatch.setEcompName(""); + + MatchStore.storeMatch(newMatch); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.MatchStore + } + + /** + * Run the void storeMatch(Matches) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testStoreMatch_14() + throws Exception { + Matches newMatch = new Matches(); + newMatch.setConfigAttributes(new Hashtable()); + newMatch.setConfigName(""); + newMatch.setEcompName(""); + + MatchStore.storeMatch(newMatch); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.MatchStore + } + + /** + * Run the void storeMatch(Matches) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testStoreMatch_15() + throws Exception { + Matches newMatch = new Matches(); + + MatchStore.storeMatch(newMatch); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.MatchStore + } + + /** + * Run the void storeMatch(Matches) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testStoreMatch_16() + throws Exception { + Matches newMatch = null; + + MatchStore.storeMatch(newMatch); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.MatchStore + } + + /** + * Perform pre-test initialization. + * + * @throws Exception + * if the initialization fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Before + public void setUp() + throws Exception { + // add additional set up code here + } + + /** + * Perform post-test clean-up. + * + * @throws Exception + * if the clean-up fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @After + public void tearDown() + throws Exception { + // Add additional tear down code here + } + + /** + * Launch the test. + * + * @param args the command line arguments + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(MatchStoreTest.class); + } +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/MatchesTest.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/MatchesTest.java new file mode 100644 index 000000000..735d12561 --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/MatchesTest.java @@ -0,0 +1,216 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.std.test; + +import java.util.Hashtable; +import java.util.Map; + +import org.junit.*; +import org.openecomp.policy.std.Matches; + +import static org.junit.Assert.*; + +/** + * The class MatchesTest contains tests for the class {@link Matches}. + * + * @generatedBy CodePro at 6/1/16 1:41 PM + * @version $Revision: 1.0 $ + */ +public class MatchesTest { + /** + * Run the Matches() constructor test. + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testMatches_1() + throws Exception { + Matches result = new Matches(); + assertNotNull(result); + // add additional test code here + } + + /** + * Run the Map getConfigAttributes() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testGetConfigAttributes_1() + throws Exception { + Matches fixture = new Matches(); + fixture.setEcompName(""); + fixture.setConfigAttributes(new Hashtable()); + fixture.setConfigName(""); + + Map result = fixture.getConfigAttributes(); + + // add additional test code here + assertNotNull(result); + assertEquals(0, result.size()); + } + + /** + * Run the String getConfigName() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testGetConfigName_1() + throws Exception { + Matches fixture = new Matches(); + fixture.setEcompName(""); + fixture.setConfigAttributes(new Hashtable()); + fixture.setConfigName(""); + + String result = fixture.getConfigName(); + + // add additional test code here + assertEquals("", result); + } + + /** + * Run the String getEcompName() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testGetEcompName_1() + throws Exception { + Matches fixture = new Matches(); + fixture.setEcompName(""); + fixture.setConfigAttributes(new Hashtable()); + fixture.setConfigName(""); + + String result = fixture.getEcompName(); + + // add additional test code here + assertEquals("", result); + } + + /** + * Run the void setConfigAttributes(Map) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testSetConfigAttributes_1() + throws Exception { + Matches fixture = new Matches(); + fixture.setEcompName(""); + fixture.setConfigAttributes(new Hashtable()); + fixture.setConfigName(""); + Map configAttributes = new Hashtable(); + + fixture.setConfigAttributes(configAttributes); + + // add additional test code here + } + + /** + * Run the void setConfigName(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testSetConfigName_1() + throws Exception { + Matches fixture = new Matches(); + fixture.setEcompName(""); + fixture.setConfigAttributes(new Hashtable()); + fixture.setConfigName(""); + String configName = ""; + + fixture.setConfigName(configName); + + // add additional test code here + } + + /** + * Run the void setEcompName(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testSetEcompName_1() + throws Exception { + Matches fixture = new Matches(); + fixture.setEcompName(""); + fixture.setConfigAttributes(new Hashtable()); + fixture.setConfigName(""); + String ecompName = ""; + + fixture.setEcompName(ecompName); + + // add additional test code here + } + + /** + * Perform pre-test initialization. + * + * @throws Exception + * if the initialization fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Before + public void setUp() + throws Exception { + // add additional set up code here + } + + /** + * Perform post-test clean-up. + * + * @throws Exception + * if the clean-up fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @After + public void tearDown() + throws Exception { + // Add additional tear down code here + } + + /** + * Launch the test. + * + * @param args the command line arguments + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(MatchesTest.class); + } +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/NotificationStoreTest.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/NotificationStoreTest.java new file mode 100644 index 000000000..d54c4f4cb --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/NotificationStoreTest.java @@ -0,0 +1,359 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.std.test; + +import org.junit.*; +import org.openecomp.policy.std.NotificationStore; +import org.openecomp.policy.std.StdPDPNotification; + +import static org.junit.Assert.*; + +/** + * The class NotificationStoreTest contains tests for the class {@link NotificationStore}. + * + * @generatedBy CodePro at 6/1/16 1:40 PM + * @version $Revision: 1.0 $ + */ +public class NotificationStoreTest { + /** + * Run the NotificationStore() constructor test. + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testNotificationStore_1() + throws Exception { + NotificationStore result = new NotificationStore(); + assertNotNull(result); + // add additional test code here + } + + /** + * Run the void recordNotification(StdPDPNotification) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testRecordNotification_1() + throws Exception { + StdPDPNotification notification = new StdPDPNotification(); + + NotificationStore.recordNotification(notification); + + // add additional test code here + } + + /** + * Run the void recordNotification(StdPDPNotification) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testRecordNotification_2() + throws Exception { + StdPDPNotification notification = new StdPDPNotification(); + + NotificationStore.recordNotification(notification); + + // add additional test code here + } + + /** + * Run the void recordNotification(StdPDPNotification) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testRecordNotification_3() + throws Exception { + StdPDPNotification notification = new StdPDPNotification(); + + NotificationStore.recordNotification(notification); + + // add additional test code here + } + + /** + * Run the void recordNotification(StdPDPNotification) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testRecordNotification_4() + throws Exception { + StdPDPNotification notification = new StdPDPNotification(); + + NotificationStore.recordNotification(notification); + + // add additional test code here + } + + /** + * Run the void recordNotification(StdPDPNotification) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testRecordNotification_5() + throws Exception { + StdPDPNotification notification = new StdPDPNotification(); + + NotificationStore.recordNotification(notification); + + // add additional test code here + } + + /** + * Run the void recordNotification(StdPDPNotification) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testRecordNotification_6() + throws Exception { + StdPDPNotification notification = new StdPDPNotification(); + + NotificationStore.recordNotification(notification); + + // add additional test code here + } + + /** + * Run the void recordNotification(StdPDPNotification) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testRecordNotification_7() + throws Exception { + StdPDPNotification notification = new StdPDPNotification(); + + NotificationStore.recordNotification(notification); + + // add additional test code here + } + + /** + * Run the void recordNotification(StdPDPNotification) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testRecordNotification_8() + throws Exception { + StdPDPNotification notification = new StdPDPNotification(); + + NotificationStore.recordNotification(notification); + + // add additional test code here + } + + /** + * Run the void recordNotification(StdPDPNotification) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testRecordNotification_9() + throws Exception { + StdPDPNotification notification = new StdPDPNotification(); + + NotificationStore.recordNotification(notification); + + // add additional test code here + } + + /** + * Run the void recordNotification(StdPDPNotification) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testRecordNotification_10() + throws Exception { + StdPDPNotification notification = new StdPDPNotification(); + + NotificationStore.recordNotification(notification); + + // add additional test code here + } + + /** + * Run the void recordNotification(StdPDPNotification) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testRecordNotification_11() + throws Exception { + StdPDPNotification notification = new StdPDPNotification(); + + NotificationStore.recordNotification(notification); + + // add additional test code here + } + + /** + * Run the void recordNotification(StdPDPNotification) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testRecordNotification_12() + throws Exception { + StdPDPNotification notification = new StdPDPNotification(); + + NotificationStore.recordNotification(notification); + + // add additional test code here + } + + /** + * Run the void recordNotification(StdPDPNotification) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testRecordNotification_13() + throws Exception { + StdPDPNotification notification = new StdPDPNotification(); + + NotificationStore.recordNotification(notification); + + // add additional test code here + } + + /** + * Run the void recordNotification(StdPDPNotification) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testRecordNotification_14() + throws Exception { + StdPDPNotification notification = new StdPDPNotification(); + + NotificationStore.recordNotification(notification); + + // add additional test code here + } + + /** + * Run the void recordNotification(StdPDPNotification) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testRecordNotification_15() + throws Exception { + StdPDPNotification notification = new StdPDPNotification(); + + NotificationStore.recordNotification(notification); + + // add additional test code here + } + + /** + * Run the void recordNotification(StdPDPNotification) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testRecordNotification_16() + throws Exception { + StdPDPNotification notification = null; + + NotificationStore.recordNotification(notification); + + // add additional test code here + } + + /** + * Perform pre-test initialization. + * + * @throws Exception + * if the initialization fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Before + public void setUp() + throws Exception { + // add additional set up code here + } + + /** + * Perform post-test clean-up. + * + * @throws Exception + * if the clean-up fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @After + public void tearDown() + throws Exception { + // Add additional tear down code here + } + + /** + * Launch the test. + * + * @param args the command line arguments + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(NotificationStoreTest.class); + } +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/NotificationUnMarshalTest.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/NotificationUnMarshalTest.java new file mode 100644 index 000000000..7a93a7b49 --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/NotificationUnMarshalTest.java @@ -0,0 +1,256 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.std.test; + +import org.junit.*; +import org.openecomp.policy.std.NotificationUnMarshal; +import org.openecomp.policy.std.StdPDPNotification; + +import static org.junit.Assert.*; + +import com.fasterxml.jackson.databind.JsonMappingException; + +/** + * The class NotificationUnMarshalTest contains tests for the class {@link NotificationUnMarshal}. + * + * @generatedBy CodePro at 6/1/16 1:40 PM + * @version $Revision: 1.0 $ + */ +public class NotificationUnMarshalTest { + /** + * Run the StdPDPNotification notificationJSON(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test(expected = com.fasterxml.jackson.databind.JsonMappingException.class) + public void testNotificationJSON_1() + throws Exception { + String json = ""; + + StdPDPNotification result = NotificationUnMarshal.notificationJSON(json); + + // add additional test code here + assertNotNull(result); + } + + /** + * Run the StdPDPNotification notificationJSON(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test(expected = com.fasterxml.jackson.databind.JsonMappingException.class) + public void testNotificationJSON_2() + throws Exception { + String json = ""; + + StdPDPNotification result = NotificationUnMarshal.notificationJSON(json); + + // add additional test code here + assertNotNull(result); + } + + /** + * Run the StdPDPNotification notificationJSON(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test(expected = com.fasterxml.jackson.databind.JsonMappingException.class) + public void testNotificationJSON_3() + throws Exception { + String json = ""; + + StdPDPNotification result = NotificationUnMarshal.notificationJSON(json); + + // add additional test code here + assertNotNull(result); + } + + /** + * Run the StdPDPNotification notificationJSON(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test(expected = com.fasterxml.jackson.databind.JsonMappingException.class) + public void testNotificationJSON_4() + throws Exception { + String json = ""; + + StdPDPNotification result = NotificationUnMarshal.notificationJSON(json); + + // add additional test code here + assertNotNull(result); + } + + /** + * Run the StdPDPNotification notificationJSON(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test(expected = com.fasterxml.jackson.databind.JsonMappingException.class) + public void testNotificationJSON_5() + throws Exception { + String json = ""; + + StdPDPNotification result = NotificationUnMarshal.notificationJSON(json); + + // add additional test code here + assertNotNull(result); + } + + /** + * Run the StdPDPNotification notificationJSON(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test(expected = com.fasterxml.jackson.databind.JsonMappingException.class) + public void testNotificationJSON_6() + throws Exception { + String json = ""; + + StdPDPNotification result = NotificationUnMarshal.notificationJSON(json); + + // add additional test code here + assertNotNull(result); + } + + /** + * Run the StdPDPNotification notificationJSON(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test(expected = com.fasterxml.jackson.databind.JsonMappingException.class) + public void testNotificationJSON_7() + throws Exception { + String json = ""; + + StdPDPNotification result = NotificationUnMarshal.notificationJSON(json); + + // add additional test code here + assertNotNull(result); + } + + /** + * Run the StdPDPNotification notificationJSON(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test(expected = com.fasterxml.jackson.databind.JsonMappingException.class) + public void testNotificationJSON_8() + throws Exception { + String json = ""; + + StdPDPNotification result = NotificationUnMarshal.notificationJSON(json); + + // add additional test code here + assertNotNull(result); + } + + /** + * Run the StdPDPNotification notificationJSON(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test(expected = com.fasterxml.jackson.databind.JsonMappingException.class) + public void testNotificationJSON_9() + throws Exception { + String json = ""; + + StdPDPNotification result = NotificationUnMarshal.notificationJSON(json); + + // add additional test code here + assertNotNull(result); + } + + /** + * Run the StdPDPNotification notificationJSON(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test(expected = com.fasterxml.jackson.databind.JsonMappingException.class) + public void testNotificationJSON_10() + throws Exception { + String json = ""; + + StdPDPNotification result = NotificationUnMarshal.notificationJSON(json); + + // add additional test code here + assertNotNull(result); + } + + /** + * Perform pre-test initialization. + * + * @throws Exception + * if the initialization fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Before + public void setUp() + throws Exception { + // add additional set up code here + } + + /** + * Perform post-test clean-up. + * + * @throws Exception + * if the clean-up fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @After + public void tearDown() + throws Exception { + // Add additional tear down code here + } + + /** + * Launch the test. + * + * @param args the command line arguments + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(NotificationUnMarshalTest.class); + } +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/StdLoadedPolicyTest.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/StdLoadedPolicyTest.java new file mode 100644 index 000000000..ce6d361df --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/StdLoadedPolicyTest.java @@ -0,0 +1,314 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.std.test; + +import java.util.Hashtable; +import java.util.Map; + +import org.junit.*; +import org.openecomp.policy.api.UpdateType; +import org.openecomp.policy.std.StdLoadedPolicy; + +import static org.junit.Assert.*; + +/** + * The class StdLoadedPolicyTest contains tests for the class {@link StdLoadedPolicy}. + * + * @generatedBy CodePro at 6/1/16 1:40 PM + * @version $Revision: 1.0 $ + */ +public class StdLoadedPolicyTest { + /** + * Run the StdLoadedPolicy() constructor test. + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testStdLoadedPolicy_1() + throws Exception { + StdLoadedPolicy result = new StdLoadedPolicy(); + assertNotNull(result); + // add additional test code here + } + + /** + * Run the Map getMatches() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetMatches_1() + throws Exception { + StdLoadedPolicy fixture = new StdLoadedPolicy(); + fixture.setPolicyName(""); + fixture.setVersionNo(""); + fixture.setUpdateType(UpdateType.NEW); + fixture.setMatches(new Hashtable()); + + Map result = fixture.getMatches(); + + // add additional test code here + assertNotNull(result); + assertEquals(0, result.size()); + } + + /** + * Run the String getPolicyName() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetPolicyName_1() + throws Exception { + StdLoadedPolicy fixture = new StdLoadedPolicy(); + fixture.setPolicyName(""); + fixture.setVersionNo(""); + fixture.setUpdateType(UpdateType.NEW); + fixture.setMatches(new Hashtable()); + + String result = fixture.getPolicyName(); + + // add additional test code here + assertEquals("", result); + } + + /** + * Run the String getPolicyName() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetPolicyName_2() + throws Exception { + StdLoadedPolicy fixture = new StdLoadedPolicy(); + fixture.setPolicyName((String) null); + fixture.setVersionNo(""); + fixture.setUpdateType(UpdateType.NEW); + fixture.setMatches(new Hashtable()); + + String result = fixture.getPolicyName(); + + // add additional test code here + assertEquals(null, result); + } + + /** + * Run the String getPolicyName() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetPolicyName_3() + throws Exception { + StdLoadedPolicy fixture = new StdLoadedPolicy(); + fixture.setPolicyName(""); + fixture.setVersionNo(""); + fixture.setUpdateType(UpdateType.NEW); + fixture.setMatches(new Hashtable()); + + String result = fixture.getPolicyName(); + + // add additional test code here + assertEquals("", result); + } + + /** + * Run the UpdateType getUpdateType() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetUpdateType_1() + throws Exception { + StdLoadedPolicy fixture = new StdLoadedPolicy(); + fixture.setPolicyName(""); + fixture.setVersionNo(""); + fixture.setUpdateType(UpdateType.NEW); + fixture.setMatches(new Hashtable()); + + UpdateType result = fixture.getUpdateType(); + + // add additional test code here + assertNotNull(result); + assertEquals("new", result.toString()); + assertEquals("NEW", result.name()); + assertEquals(1, result.ordinal()); + } + + /** + * Run the String getVersionNo() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetVersionNo_1() + throws Exception { + StdLoadedPolicy fixture = new StdLoadedPolicy(); + fixture.setPolicyName(""); + fixture.setVersionNo(""); + fixture.setUpdateType(UpdateType.NEW); + fixture.setMatches(new Hashtable()); + + String result = fixture.getVersionNo(); + + // add additional test code here + assertEquals("", result); + } + + /** + * Run the void setMatches(Map) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetMatches_1() + throws Exception { + StdLoadedPolicy fixture = new StdLoadedPolicy(); + fixture.setPolicyName(""); + fixture.setVersionNo(""); + fixture.setUpdateType(UpdateType.NEW); + fixture.setMatches(new Hashtable()); + Map matches = new Hashtable(); + + fixture.setMatches(matches); + + // add additional test code here + } + + /** + * Run the void setPolicyName(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetPolicyName_1() + throws Exception { + StdLoadedPolicy fixture = new StdLoadedPolicy(); + fixture.setPolicyName(""); + fixture.setVersionNo(""); + fixture.setUpdateType(UpdateType.NEW); + fixture.setMatches(new Hashtable()); + String policyName = ""; + + fixture.setPolicyName(policyName); + + // add additional test code here + } + + /** + * Run the void setUpdateType(UpdateType) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetUpdateType_1() + throws Exception { + StdLoadedPolicy fixture = new StdLoadedPolicy(); + fixture.setPolicyName(""); + fixture.setVersionNo(""); + fixture.setUpdateType(UpdateType.NEW); + fixture.setMatches(new Hashtable()); + UpdateType updateType = UpdateType.NEW; + + fixture.setUpdateType(updateType); + + // add additional test code here + } + + /** + * Run the void setVersionNo(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetVersionNo_1() + throws Exception { + StdLoadedPolicy fixture = new StdLoadedPolicy(); + fixture.setPolicyName(""); + fixture.setVersionNo(""); + fixture.setUpdateType(UpdateType.NEW); + fixture.setMatches(new Hashtable()); + String versionNo = ""; + + fixture.setVersionNo(versionNo); + + // add additional test code here + } + + /** + * Perform pre-test initialization. + * + * @throws Exception + * if the initialization fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Before + public void setUp() + throws Exception { + // add additional set up code here + } + + /** + * Perform post-test clean-up. + * + * @throws Exception + * if the clean-up fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @After + public void tearDown() + throws Exception { + // Add additional tear down code here + } + + /** + * Launch the test. + * + * @param args the command line arguments + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(StdLoadedPolicyTest.class); + } +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/StdPDPNotificationTest.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/StdPDPNotificationTest.java new file mode 100644 index 000000000..490120fb9 --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/StdPDPNotificationTest.java @@ -0,0 +1,311 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.std.test; + +import java.util.Collection; +import java.util.LinkedList; + +import org.junit.*; +import org.openecomp.policy.api.LoadedPolicy; +import org.openecomp.policy.api.NotificationType; +import org.openecomp.policy.api.RemovedPolicy; +import org.openecomp.policy.std.StdLoadedPolicy; +import org.openecomp.policy.std.StdPDPNotification; +import org.openecomp.policy.std.StdRemovedPolicy; + +import static org.junit.Assert.*; + +/** + * The class StdPDPNotificationTest contains tests for the class {@link StdPDPNotification}. + * + * @generatedBy CodePro at 6/1/16 1:41 PM + * @version $Revision: 1.0 $ + */ +public class StdPDPNotificationTest { + /** + * Run the StdPDPNotification() constructor test. + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testStdPDPNotification_1() + throws Exception { + StdPDPNotification result = new StdPDPNotification(); + assertNotNull(result); + // add additional test code here + } + + /** + * Run the Collection getLoadedPolicies() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testGetLoadedPolicies_1() + throws Exception { + StdPDPNotification fixture = new StdPDPNotification(); + fixture.setRemovedPolicies(new LinkedList()); + fixture.setNotificationType(NotificationType.BOTH); + fixture.setLoadedPolicies(new LinkedList()); + + Collection result = fixture.getLoadedPolicies(); + + // add additional test code here + assertNotNull(result); + assertEquals(0, result.size()); + } + + /** + * Run the Collection getLoadedPolicies() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testGetLoadedPolicies_2() + throws Exception { + StdPDPNotification fixture = new StdPDPNotification(); + fixture.setRemovedPolicies(new LinkedList()); + fixture.setNotificationType(NotificationType.BOTH); + fixture.setLoadedPolicies(new LinkedList()); + + Collection result = fixture.getLoadedPolicies(); + + // add additional test code here + assertNotNull(result); + assertEquals(0, result.size()); + } + + /** + * Run the Collection getLoadedPolicies() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testGetLoadedPolicies_3() + throws Exception { + StdPDPNotification fixture = new StdPDPNotification(); + fixture.setRemovedPolicies(new LinkedList()); + fixture.setNotificationType(NotificationType.BOTH); + fixture.setLoadedPolicies(null); + + Collection result = fixture.getLoadedPolicies(); + + // add additional test code here + assertEquals(null, result); + } + + /** + * Run the NotificationType getNotificationType() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testGetNotificationType_1() + throws Exception { + StdPDPNotification fixture = new StdPDPNotification(); + fixture.setRemovedPolicies(new LinkedList()); + fixture.setNotificationType(NotificationType.BOTH); + fixture.setLoadedPolicies(new LinkedList()); + + NotificationType result = fixture.getNotificationType(); + + // add additional test code here + assertNotNull(result); + assertEquals("both", result.toString()); + assertEquals("BOTH", result.name()); + assertEquals(2, result.ordinal()); + } + + /** + * Run the Collection getRemovedPolicies() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testGetRemovedPolicies_1() + throws Exception { + StdPDPNotification fixture = new StdPDPNotification(); + fixture.setRemovedPolicies(new LinkedList()); + fixture.setNotificationType(NotificationType.BOTH); + fixture.setLoadedPolicies(new LinkedList()); + + Collection result = fixture.getRemovedPolicies(); + + // add additional test code here + assertNotNull(result); + assertEquals(0, result.size()); + } + + /** + * Run the Collection getRemovedPolicies() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testGetRemovedPolicies_2() + throws Exception { + StdPDPNotification fixture = new StdPDPNotification(); + fixture.setRemovedPolicies(new LinkedList()); + fixture.setNotificationType(NotificationType.BOTH); + fixture.setLoadedPolicies(new LinkedList()); + + Collection result = fixture.getRemovedPolicies(); + + // add additional test code here + assertNotNull(result); + assertEquals(0, result.size()); + } + + /** + * Run the Collection getRemovedPolicies() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testGetRemovedPolicies_3() + throws Exception { + StdPDPNotification fixture = new StdPDPNotification(); + fixture.setRemovedPolicies(null); + fixture.setNotificationType(NotificationType.BOTH); + fixture.setLoadedPolicies(new LinkedList()); + + Collection result = fixture.getRemovedPolicies(); + + // add additional test code here + assertEquals(null, result); + } + + /** + * Run the void setNotificationType(NotificationType) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testSetNotificationType_1() + throws Exception { + StdPDPNotification fixture = new StdPDPNotification(); + fixture.setRemovedPolicies(new LinkedList()); + fixture.setNotificationType(NotificationType.BOTH); + fixture.setLoadedPolicies(new LinkedList()); + NotificationType notificationType = NotificationType.BOTH; + + fixture.setNotificationType(notificationType); + + // add additional test code here + } + + /** + * Run the void setRemovedPolicies(Collection) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testSetRemovedPolicies_1() + throws Exception { + StdPDPNotification fixture = new StdPDPNotification(); + fixture.setRemovedPolicies(new LinkedList()); + fixture.setNotificationType(NotificationType.BOTH); + fixture.setLoadedPolicies(new LinkedList()); + Collection removedPolicies = new LinkedList(); + + fixture.setRemovedPolicies(removedPolicies); + + // add additional test code here + } + + /** + * Run the void setUpdatedPolicies(Collection) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testSetUpdatedPolicies_1() + throws Exception { + StdPDPNotification fixture = new StdPDPNotification(); + fixture.setRemovedPolicies(new LinkedList()); + fixture.setNotificationType(NotificationType.BOTH); + fixture.setLoadedPolicies(new LinkedList()); + Collection updatedPolicies = new LinkedList(); + + fixture.setLoadedPolicies(updatedPolicies); + + // add additional test code here + } + + /** + * Perform pre-test initialization. + * + * @throws Exception + * if the initialization fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Before + public void setUp() + throws Exception { + // add additional set up code here + } + + /** + * Perform post-test clean-up. + * + * @throws Exception + * if the clean-up fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @After + public void tearDown() + throws Exception { + // Add additional tear down code here + } + + /** + * Launch the test. + * + * @param args the command line arguments + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(StdPDPNotificationTest.class); + } +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/StdPolicyChangeResponseTest.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/StdPolicyChangeResponseTest.java new file mode 100644 index 000000000..45c70187d --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/StdPolicyChangeResponseTest.java @@ -0,0 +1,166 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.std.test; + +import org.junit.*; +import org.openecomp.policy.std.StdPolicyChangeResponse; + +import static org.junit.Assert.*; + +/** + * The class StdPolicyChangeResponseTest contains tests for the class {@link StdPolicyChangeResponse}. + * + * @generatedBy CodePro at 6/1/16 1:40 PM + * @version $Revision: 1.0 $ + */ +public class StdPolicyChangeResponseTest { + /** + * Run the StdPolicyChangeResponse() constructor test. + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testStdPolicyChangeResponse_1() + throws Exception { + StdPolicyChangeResponse result = new StdPolicyChangeResponse(); + assertNotNull(result); + // add additional test code here + } + + /** + * Run the int getResponseCode() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetResponseCode_1() + throws Exception { + StdPolicyChangeResponse fixture = new StdPolicyChangeResponse(); + fixture.setResponseMessage(""); + fixture.setResponseCode(1); + + int result = fixture.getResponseCode(); + + // add additional test code here + assertEquals(1, result); + } + + /** + * Run the String getResponseMessage() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetResponseMessage_1() + throws Exception { + StdPolicyChangeResponse fixture = new StdPolicyChangeResponse(); + fixture.setResponseMessage(""); + fixture.setResponseCode(1); + + String result = fixture.getResponseMessage(); + + // add additional test code here + assertEquals("", result); + } + + /** + * Run the void setResponseCode(int) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetResponseCode_1() + throws Exception { + StdPolicyChangeResponse fixture = new StdPolicyChangeResponse(); + fixture.setResponseMessage(""); + fixture.setResponseCode(1); + int responseCode = 1; + + fixture.setResponseCode(responseCode); + + // add additional test code here + } + + /** + * Run the void setResponseMessage(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetResponseMessage_1() + throws Exception { + StdPolicyChangeResponse fixture = new StdPolicyChangeResponse(); + fixture.setResponseMessage(""); + fixture.setResponseCode(1); + String responseMessage = ""; + + fixture.setResponseMessage(responseMessage); + + // add additional test code here + } + + /** + * Perform pre-test initialization. + * + * @throws Exception + * if the initialization fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Before + public void setUp() + throws Exception { + // add additional set up code here + } + + /** + * Perform post-test clean-up. + * + * @throws Exception + * if the clean-up fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @After + public void tearDown() + throws Exception { + // Add additional tear down code here + } + + /** + * Launch the test. + * + * @param args the command line arguments + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(StdPolicyChangeResponseTest.class); + } +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/StdPolicyConfigTest.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/StdPolicyConfigTest.java new file mode 100644 index 000000000..88a22c300 --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/StdPolicyConfigTest.java @@ -0,0 +1,821 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.std.test; + +import java.util.Hashtable; +import java.util.Map; +import java.util.Properties; + +import javax.json.JsonObject; + +import org.junit.*; +import org.openecomp.policy.api.PolicyConfigStatus; +import org.openecomp.policy.api.PolicyType; +import org.openecomp.policy.std.StdPolicyConfig; + +import static org.junit.Assert.*; + +import org.w3c.dom.Document; + +/** + * The class StdPolicyConfigTest contains tests for the class {@link StdPolicyConfig}. + * + * @generatedBy CodePro at 6/1/16 1:41 PM + * @version $Revision: 1.0 $ + */ +public class StdPolicyConfigTest { + /** + * Run the Map getMatchingConditions() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testGetMatchingConditions_1() + throws Exception { + StdPolicyConfig fixture = new StdPolicyConfig(); + fixture.setConfigStatus("", PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setDocument((Document) null); + fixture.setResponseAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setOther(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setPolicyName(""); + fixture.setProperties(new Properties()); + fixture.setJsonObject((JsonObject) null); + fixture.setMatchingConditions(new Hashtable()); + + Map result = fixture.getMatchingConditions(); + + // add additional test code here + assertNotNull(result); + assertEquals(0, result.size()); + } + + /** + * Run the String getPolicyConfigMessage() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testGetPolicyConfigMessage_1() + throws Exception { + StdPolicyConfig fixture = new StdPolicyConfig(); + fixture.setConfigStatus("", PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setDocument((Document) null); + fixture.setResponseAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setOther(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setPolicyName(""); + fixture.setProperties(new Properties()); + fixture.setJsonObject((JsonObject) null); + fixture.setMatchingConditions(new Hashtable()); + + String result = fixture.getPolicyConfigMessage(); + + // add additional test code here + assertEquals("", result); + } + + /** + * Run the PolicyConfigStatus getPolicyConfigStatus() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testGetPolicyConfigStatus_1() + throws Exception { + StdPolicyConfig fixture = new StdPolicyConfig(); + fixture.setConfigStatus("", PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setDocument((Document) null); + fixture.setResponseAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setOther(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setPolicyName(""); + fixture.setProperties(new Properties()); + fixture.setJsonObject((JsonObject) null); + fixture.setMatchingConditions(new Hashtable()); + + PolicyConfigStatus result = fixture.getPolicyConfigStatus(); + + // add additional test code here + assertNotNull(result); + assertEquals("not_found", result.toString()); + assertEquals("CONFIG_NOT_FOUND", result.name()); + assertEquals(1, result.ordinal()); + } + + /** + * Run the String getPolicyName() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testGetPolicyName_1() + throws Exception { + StdPolicyConfig fixture = new StdPolicyConfig(); + fixture.setConfigStatus("", PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setDocument((Document) null); + fixture.setResponseAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setOther(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setPolicyName(""); + fixture.setProperties(new Properties()); + fixture.setJsonObject((JsonObject) null); + fixture.setMatchingConditions(new Hashtable()); + + String result = fixture.getPolicyName(); + + // add additional test code here + assertEquals("", result); + } + + /** + * Run the String getPolicyName() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testGetPolicyName_2() + throws Exception { + StdPolicyConfig fixture = new StdPolicyConfig(); + fixture.setConfigStatus("", PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setDocument((Document) null); + fixture.setResponseAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setOther(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setPolicyName((String) null); + fixture.setProperties(new Properties()); + fixture.setJsonObject((JsonObject) null); + fixture.setMatchingConditions(new Hashtable()); + + String result = fixture.getPolicyName(); + + // add additional test code here + assertEquals(null, result); + } + + /** + * Run the String getPolicyName() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testGetPolicyName_3() + throws Exception { + StdPolicyConfig fixture = new StdPolicyConfig(); + fixture.setConfigStatus("", PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setDocument((Document) null); + fixture.setResponseAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setOther(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setPolicyName(""); + fixture.setProperties(new Properties()); + fixture.setJsonObject((JsonObject) null); + fixture.setMatchingConditions(new Hashtable()); + + String result = fixture.getPolicyName(); + + // add additional test code here + assertEquals("", result); + } + + /** + * Run the String getPolicyVersion() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testGetPolicyVersion_1() + throws Exception { + StdPolicyConfig fixture = new StdPolicyConfig(); + fixture.setConfigStatus("", PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setDocument((Document) null); + fixture.setResponseAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setOther(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setPolicyName(""); + fixture.setProperties(new Properties()); + fixture.setJsonObject((JsonObject) null); + fixture.setMatchingConditions(new Hashtable()); + + String result = fixture.getPolicyVersion(); + + // add additional test code here + assertEquals("", result); + } + + /** + * Run the Map getResponseAttributes() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testGetResponseAttributes_1() + throws Exception { + StdPolicyConfig fixture = new StdPolicyConfig(); + fixture.setConfigStatus("", PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setDocument((Document) null); + fixture.setResponseAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setOther(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setPolicyName(""); + fixture.setProperties(new Properties()); + fixture.setJsonObject((JsonObject) null); + fixture.setMatchingConditions(new Hashtable()); + + Map result = fixture.getResponseAttributes(); + + // add additional test code here + assertNotNull(result); + assertEquals(0, result.size()); + } + + /** + * Run the PolicyType getType() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testGetType_1() + throws Exception { + StdPolicyConfig fixture = new StdPolicyConfig(); + fixture.setConfigStatus("", PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setDocument((Document) null); + fixture.setResponseAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setOther(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setPolicyName(""); + fixture.setProperties(new Properties()); + fixture.setJsonObject((JsonObject) null); + fixture.setMatchingConditions(new Hashtable()); + + PolicyType result = fixture.getType(); + + // add additional test code here + assertNotNull(result); + assertEquals("json", result.toString()); + assertEquals("JSON", result.name()); + assertEquals(1, result.ordinal()); + } + + /** + * Run the void setConfigStatus(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testSetConfigStatus_1() + throws Exception { + StdPolicyConfig fixture = new StdPolicyConfig(); + fixture.setConfigStatus("", PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setDocument((Document) null); + fixture.setResponseAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setOther(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setPolicyName(""); + fixture.setProperties(new Properties()); + fixture.setJsonObject((JsonObject) null); + fixture.setMatchingConditions(new Hashtable()); + String configStatus = ""; + + fixture.setConfigStatus(configStatus); + + // add additional test code here + } + + /** + * Run the void setConfigStatus(String,PolicyConfigStatus) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testSetConfigStatus_2() + throws Exception { + StdPolicyConfig fixture = new StdPolicyConfig(); + fixture.setConfigStatus("", PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setDocument((Document) null); + fixture.setResponseAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setOther(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setPolicyName(""); + fixture.setProperties(new Properties()); + fixture.setJsonObject((JsonObject) null); + fixture.setMatchingConditions(new Hashtable()); + String configStatus = ""; + PolicyConfigStatus policyConfigStatus = PolicyConfigStatus.CONFIG_NOT_FOUND; + + fixture.setConfigStatus(configStatus, policyConfigStatus); + + // add additional test code here + } + + /** + * Run the void setDocument(Document) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testSetDocument_1() + throws Exception { + StdPolicyConfig fixture = new StdPolicyConfig(); + fixture.setConfigStatus("", PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setDocument((Document) null); + fixture.setResponseAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setOther(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setPolicyName(""); + fixture.setProperties(new Properties()); + fixture.setJsonObject((JsonObject) null); + fixture.setMatchingConditions(new Hashtable()); + Document document = null; + + fixture.setDocument(document); + + // add additional test code here + } + + /** + * Run the void setJsonObject(JsonObject) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testSetJsonObject_1() + throws Exception { + StdPolicyConfig fixture = new StdPolicyConfig(); + fixture.setConfigStatus("", PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setDocument((Document) null); + fixture.setResponseAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setOther(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setPolicyName(""); + fixture.setProperties(new Properties()); + fixture.setJsonObject((JsonObject) null); + fixture.setMatchingConditions(new Hashtable()); + JsonObject jsonObject = null; + + fixture.setJsonObject(jsonObject); + + // add additional test code here + } + + /** + * Run the void setMatchingConditions(Map) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testSetMatchingConditions_1() + throws Exception { + StdPolicyConfig fixture = new StdPolicyConfig(); + fixture.setConfigStatus("", PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setDocument((Document) null); + fixture.setResponseAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setOther(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setPolicyName(""); + fixture.setProperties(new Properties()); + fixture.setJsonObject((JsonObject) null); + fixture.setMatchingConditions(new Hashtable()); + Map matchingConditions = new Hashtable(); + + fixture.setMatchingConditions(matchingConditions); + + // add additional test code here + } + + /** + * Run the void setOther(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testSetOther_1() + throws Exception { + StdPolicyConfig fixture = new StdPolicyConfig(); + fixture.setConfigStatus("", PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setDocument((Document) null); + fixture.setResponseAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setOther(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setPolicyName(""); + fixture.setProperties(new Properties()); + fixture.setJsonObject((JsonObject) null); + fixture.setMatchingConditions(new Hashtable()); + String other = ""; + + fixture.setOther(other); + + // add additional test code here + } + + /** + * Run the void setPolicyConfigStatus(PolicyConfigStatus) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testSetPolicyConfigStatus_1() + throws Exception { + StdPolicyConfig fixture = new StdPolicyConfig(); + fixture.setConfigStatus("", PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setDocument((Document) null); + fixture.setResponseAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setOther(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setPolicyName(""); + fixture.setProperties(new Properties()); + fixture.setJsonObject((JsonObject) null); + fixture.setMatchingConditions(new Hashtable()); + PolicyConfigStatus policyConfigStatus = PolicyConfigStatus.CONFIG_NOT_FOUND; + + fixture.setPolicyConfigStatus(policyConfigStatus); + + // add additional test code here + } + + /** + * Run the void setPolicyName(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testSetPolicyName_1() + throws Exception { + StdPolicyConfig fixture = new StdPolicyConfig(); + fixture.setConfigStatus("", PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setDocument((Document) null); + fixture.setResponseAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setOther(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setPolicyName(""); + fixture.setProperties(new Properties()); + fixture.setJsonObject((JsonObject) null); + fixture.setMatchingConditions(new Hashtable()); + String policyName = ""; + + fixture.setPolicyName(policyName); + + // add additional test code here + } + + /** + * Run the void setPolicyType(PolicyType) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testSetPolicyType_1() + throws Exception { + StdPolicyConfig fixture = new StdPolicyConfig(); + fixture.setConfigStatus("", PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setDocument((Document) null); + fixture.setResponseAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setOther(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setPolicyName(""); + fixture.setProperties(new Properties()); + fixture.setJsonObject((JsonObject) null); + fixture.setMatchingConditions(new Hashtable()); + PolicyType policyType = PolicyType.JSON; + + fixture.setPolicyType(policyType); + + // add additional test code here + } + + /** + * Run the void setPolicyVersion(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testSetPolicyVersion_1() + throws Exception { + StdPolicyConfig fixture = new StdPolicyConfig(); + fixture.setConfigStatus("", PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setDocument((Document) null); + fixture.setResponseAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setOther(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setPolicyName(""); + fixture.setProperties(new Properties()); + fixture.setJsonObject((JsonObject) null); + fixture.setMatchingConditions(new Hashtable()); + String policyVersion = ""; + + fixture.setPolicyVersion(policyVersion); + + // add additional test code here + } + + /** + * Run the void setProperties(Properties) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testSetProperties_1() + throws Exception { + StdPolicyConfig fixture = new StdPolicyConfig(); + fixture.setConfigStatus("", PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setDocument((Document) null); + fixture.setResponseAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setOther(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setPolicyName(""); + fixture.setProperties(new Properties()); + fixture.setJsonObject((JsonObject) null); + fixture.setMatchingConditions(new Hashtable()); + Properties properties = new Properties(); + + fixture.setProperties(properties); + + // add additional test code here + } + + /** + * Run the void setResponseAttributes(Map) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testSetResponseAttributes_1() + throws Exception { + StdPolicyConfig fixture = new StdPolicyConfig(); + fixture.setConfigStatus("", PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setDocument((Document) null); + fixture.setResponseAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setOther(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setPolicyName(""); + fixture.setProperties(new Properties()); + fixture.setJsonObject((JsonObject) null); + fixture.setMatchingConditions(new Hashtable()); + Map responseAttributes = new Hashtable(); + + fixture.setResponseAttributes(responseAttributes); + + // add additional test code here + } + + /** + * Run the JsonObject toJSON() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testToJSON_1() + throws Exception { + StdPolicyConfig fixture = new StdPolicyConfig(); + fixture.setConfigStatus("", PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setDocument((Document) null); + fixture.setResponseAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setOther(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setPolicyName(""); + fixture.setProperties(new Properties()); + fixture.setJsonObject((JsonObject) null); + fixture.setMatchingConditions(new Hashtable()); + + JsonObject result = fixture.toJSON(); + + // add additional test code here + assertEquals(null, result); + } + + /** + * Run the String toOther() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testToOther_1() + throws Exception { + StdPolicyConfig fixture = new StdPolicyConfig(); + fixture.setConfigStatus("", PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setDocument((Document) null); + fixture.setResponseAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setOther(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setPolicyName(""); + fixture.setProperties(new Properties()); + fixture.setJsonObject((JsonObject) null); + fixture.setMatchingConditions(new Hashtable()); + + String result = fixture.toOther(); + + // add additional test code here + assertEquals("", result); + } + + /** + * Run the Properties toProperties() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testToProperties_1() + throws Exception { + StdPolicyConfig fixture = new StdPolicyConfig(); + fixture.setConfigStatus("", PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setDocument((Document) null); + fixture.setResponseAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setOther(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setPolicyName(""); + fixture.setProperties(new Properties()); + fixture.setJsonObject((JsonObject) null); + fixture.setMatchingConditions(new Hashtable()); + + Properties result = fixture.toProperties(); + + // add additional test code here + assertNotNull(result); + assertEquals(0, result.size()); + } + + /** + * Run the String toString() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testToString_1() + throws Exception { + StdPolicyConfig fixture = new StdPolicyConfig(); + fixture.setConfigStatus("", PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setDocument((Document) null); + fixture.setResponseAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setOther(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setPolicyName("test"); + fixture.setProperties(new Properties()); + fixture.setJsonObject((JsonObject) null); + fixture.setMatchingConditions(new Hashtable()); + + String result = fixture.toString(); + + // add additional test code here + assertEquals("PolicyConfig [ policyConfigStatus=not_found, policyConfigMessage=, policyName=test]", result); + } + + /** + * Run the Document toXML() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testToXML_1() + throws Exception { + StdPolicyConfig fixture = new StdPolicyConfig(); + fixture.setConfigStatus("", PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setDocument((Document) null); + fixture.setResponseAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setOther(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setPolicyName(""); + fixture.setProperties(new Properties()); + fixture.setJsonObject((JsonObject) null); + fixture.setMatchingConditions(new Hashtable()); + + Document result = fixture.toXML(); + + // add additional test code here + assertEquals(null, result); + } + + /** + * Perform pre-test initialization. + * + * @throws Exception + * if the initialization fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Before + public void setUp() + throws Exception { + // add additional set up code here + } + + /** + * Perform post-test clean-up. + * + * @throws Exception + * if the clean-up fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @After + public void tearDown() + throws Exception { + // Add additional tear down code here + } + + /** + * Launch the test. + * + * @param args the command line arguments + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(StdPolicyConfigTest.class); + } +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/StdPolicyEngineTest.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/StdPolicyEngineTest.java new file mode 100644 index 000000000..c2fee2f0e --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/StdPolicyEngineTest.java @@ -0,0 +1,1002 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.std.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.StringReader; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.UUID; + +import javax.json.Json; +import javax.json.JsonObject; +import javax.json.JsonReader; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.openecomp.policy.api.AttributeType; +import org.openecomp.policy.api.ConfigRequestParameters; +import org.openecomp.policy.api.DecisionRequestParameters; +import org.openecomp.policy.api.DecisionResponse; +import org.openecomp.policy.api.DeletePolicyCondition; +import org.openecomp.policy.api.DeletePolicyParameters; +import org.openecomp.policy.api.DictionaryParameters; +import org.openecomp.policy.api.DictionaryType; +import org.openecomp.policy.api.EventRequestParameters; +import org.openecomp.policy.api.ImportParameters; +import org.openecomp.policy.api.NotificationHandler; +import org.openecomp.policy.api.NotificationScheme; +import org.openecomp.policy.api.PolicyChangeResponse; +import org.openecomp.policy.api.PolicyClass; +import org.openecomp.policy.api.PolicyConfig; +import org.openecomp.policy.api.PolicyConfigStatus; +import org.openecomp.policy.api.PolicyConfigType; +import org.openecomp.policy.api.PolicyDecision; +import org.openecomp.policy.api.PolicyParameters; +import org.openecomp.policy.api.PolicyResponse; +import org.openecomp.policy.api.PolicyType; +import org.openecomp.policy.api.PushPolicyParameters; +import org.openecomp.policy.api.ImportParameters.IMPORT_TYPE; +import org.openecomp.policy.std.StdDecisionResponse; +import org.openecomp.policy.std.StdPolicyChangeResponse; +import org.openecomp.policy.std.StdPolicyConfig; +import org.openecomp.policy.std.StdPolicyEngine; +import org.openecomp.policy.std.StdPolicyResponse; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +/** + * The class StdPolicyEngineTest contains tests for the class {@link StdPolicyEngine}. + * + * @generatedBy CodePro at 6/3/16 2:03 PM + * @version $Revision: 1.0 $ + */ +public class StdPolicyEngineTest { + + private static final Logger logger = FlexLogger.getLogger(StdPolicyEngine.class); + + private StdPolicyEngine fixture = null; + private StdPolicyEngine mockEngine = null; + + PolicyChangeResponse result = null; + StdPolicyChangeResponse response = new StdPolicyChangeResponse(); + PolicyParameters policyParameters = new PolicyParameters(); + String json = null; + + /** + * Perform pre-test initialization. + * + * @throws Exception + * if the initialization fails for some reason + * + * @generatedBy CodePro at 6/3/16 2:03 PM + */ + @Before + public void setUp() + throws Exception { + fixture = new StdPolicyEngine("Test/config_pass.properties"); + + //Mocks + mockEngine = Mockito.mock(StdPolicyEngine.class); + } + + private static JsonObject buildJSON(String jsonString) { + JsonObject json = null;; + if (jsonString != null) { + StringReader in = null; + + in = new StringReader(jsonString); + + JsonReader jsonReader = Json.createReader(in); + json = jsonReader.readObject(); + } + + return json; + } + + //Reads a File and converts into a String. + private static String readFile( String file ) throws IOException { + BufferedReader reader = new BufferedReader( new FileReader (file)); + String line = null; + StringBuilder stringBuilder = new StringBuilder(); + String ls = System.getProperty("line.separator"); + + try { + while( ( line = reader.readLine() ) != null ) { + stringBuilder.append( line ); + stringBuilder.append( ls ); + } + + return stringBuilder.toString(); + } finally { + reader.close(); + } + } + + /** + * Run the StdPolicyEngine(String) constructor test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/3/16 2:03 PM + */ + @Test + public void testStdPolicyEngine() + throws Exception { + String propertyFilePath = "Test/config_pass.properties"; + + StdPolicyEngine result = new StdPolicyEngine(propertyFilePath); + + assertNotNull(result); + } + + /** + * Run the StdPolicyEngine(String) constructor test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/3/16 2:03 PM + */ +/* @Test + public void testStdPolicyEngine_2() + throws Exception { + String propertyFilePath = "http"; + + StdPolicyEngine result = new StdPolicyEngine(propertyFilePath); + + assertNull(result); + } +*/ + /** + * Run the StdPolicyEngine(String,NotificationScheme) constructor test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/3/16 2:03 PM + */ + @Test + public void testStdPolicyEngine_3() + throws Exception { + String propertyFilePath = "Test/config_pass.properties"; + NotificationScheme scheme = NotificationScheme.AUTO_ALL_NOTIFICATIONS; + + StdPolicyEngine result = new StdPolicyEngine(propertyFilePath, scheme); + + assertNotNull(result); + } + + /** + * Run the StdPolicyEngine(String,NotificationScheme) constructor test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/3/16 2:03 PM + */ +/* @Test + public void testStdPolicyEngine_4() + throws Exception { + String propertyFilePath = "http"; + NotificationScheme scheme = NotificationScheme.AUTO_ALL_NOTIFICATIONS; + + StdPolicyEngine result = new StdPolicyEngine(propertyFilePath, scheme); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.StdPolicyEngine + assertNull(result); + }*/ + + /** + * Run the StdPolicyEngine(String,NotificationScheme,NotificationHandler) constructor test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/3/16 2:03 PM + */ +/* @Test + public void testStdPolicyEngine_5() + throws Exception { + String propertyFilePath = "Test/config_pass.properties"; + NotificationScheme scheme = NotificationScheme.AUTO_ALL_NOTIFICATIONS; + NotificationHandler handler = new Handler(); + + StdPolicyEngine result = new StdPolicyEngine(propertyFilePath, scheme, handler); + + assertNull(result); + }*/ + + /** + * Run the StdPolicyEngine(String,NotificationScheme,NotificationHandler) constructor test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/3/16 2:03 PM + */ +/* @Test + public void testStdPolicyEngine_6() + throws Exception { + String propertyFilePath = "http"; + NotificationScheme scheme = NotificationScheme.AUTO_ALL_NOTIFICATIONS; + NotificationHandler handler = new Handler(); + + StdPolicyEngine result = new StdPolicyEngine(propertyFilePath, scheme, handler); + + assertNull(result); + } +*/ + /** + * Run the StdPolicyEngine(List,List,List,List,NotificationScheme,NotificationHandler,String) constructor test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/3/16 2:03 PM + */ +/* @Test + public void testStdPolicyEngine_8() + throws Exception { + List configURL = new LinkedList(); + List configPapURL = new LinkedList(); + List encodingPAP = new LinkedList(); + List encoding = new LinkedList(); + NotificationScheme scheme = NotificationScheme.AUTO_ALL_NOTIFICATIONS; + NotificationHandler handler = new Handler(); + String clientAuth = "TEST"; + + StdPolicyEngine result = new StdPolicyEngine(configURL, configPapURL, encodingPAP, encoding, scheme, handler, clientAuth); + + // add additional test code here + // An unexpected exception was thrown in user code while executing this test: + // java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.StdPolicyEngine + assertNull(result); + } +*/ + /** + * Run the Collection config(ConfigRequestParameters) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/3/16 2:03 PM + */ + @Test + public void testConfig() + throws Exception { + String configMessage = "Error in Calling the Configuration URL java.lang.Exception: PE500 - Process Flow Issue: Cannot open a connection to the configURL"; + PolicyConfigStatus configStatus = PolicyConfigStatus.CONFIG_NOT_FOUND; + String policyName = "JunitTest.Config_testing"; + String policyVersion = "1"; + + ConfigRequestParameters configRequestParameters = new ConfigRequestParameters(); + configRequestParameters.setPolicyName(".*"); + Collection result = fixture.config(configRequestParameters); + + //assertEquals(response, result); + for(PolicyConfig policyConfig: result){ + assertEquals(policyName, policyConfig.getPolicyName()); + assertEquals(policyVersion, policyConfig.getPolicyVersion()); + assertEquals(configStatus, policyConfig.getPolicyConfigStatus()); + assertEquals(configMessage, policyConfig.getPolicyConfigMessage()); + } + } + + + /** + * Run the Collection listConfig(ConfigRequestParameters) method test. + * + * @throws Exception + * + */ + @Test + public void testListConfig() + throws Exception { + + Collection response = new ArrayList(); + response.add("Policy Name: listConfigTest"); + + ConfigRequestParameters configRequestParameters = new ConfigRequestParameters(); + configRequestParameters.setPolicyName(".*"); + Collection result = fixture.listConfig(configRequestParameters); + + assertEquals(result, response); + } + + /** + * Run the String copyFile(String,String,StdPAPPolicy,String,UUID) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/3/16 2:03 PM + */ +/* @Test + public void testCopyFile() + throws Exception { + String policyId = "test.testing"; + String group = "default"; + URI selectedURI = null; + StdPDPPolicy policy = new StdPDPPolicy("testing", true, "test", selectedURI, true, "test", "testing", "1"); + StdPAPPolicy location = new StdPAPPolicy(policy.getLocation()); + String clientScope = "Config"; + UUID requestID = UUID.randomUUID(); + + String result = fixture.copyFile(policyId, group, location, clientScope, requestID); + + assertNotNull(result); + }*/ + + /** + * Run the String copyPolicy(PDPPolicy,String,String,UUID) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/3/16 2:03 PM + */ +/* @Test + public void testCopyPolicy() + throws Exception { + //StdPolicyEngine fixture = new StdPolicyEngine("http", NotificationScheme.AUTO_ALL_NOTIFICATIONS, (NotificationHandler) null); + URI selectedURI = null; + + StdPDPPolicy policy = new StdPDPPolicy("testing", true, "test", selectedURI, true, "test", "testing", "1"); + String group = "default"; + String policyType = "Base"; + UUID requestID = UUID.randomUUID(); + + String result = fixture.copyPolicy(policy, group, policyType, requestID); + + assertNotNull(result); + } +*/ + /** + * Run the String createConfigFirewallPolicy(String,JsonObject,String,UUID) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/3/16 2:03 PM + */ + @Test + public void testCreateConfigFirewallPolicy() + throws Exception { + + response.setResponseMessage("success"); + PolicyParameters policyParameters = new PolicyParameters(); + policyParameters.setPolicyConfigType(PolicyConfigType.Firewall); + + String json= "{\"serviceTypeId\": \"/v0/firewall/pan\",\"configName\": \"rule1607\",\"deploymentOption\":{\"deployNow\": false},\"securityZoneId\": \"/v0/firewall/pan\",\"serviceGroups\": [{\"name\": \"1607Group\",\"description\": null,\"members\": [{\"type\": \"REFERENCE\",\"name\": \"SList\"},{\"type\": \"REFERENCE\",\"name\": \"Syslog\"}]}, {\"name\": \"Syslog\",\"description\": \"NA\",\"type\": \"SERVICE\",\"transportProtocol\": \"udp\",\"appProtocol\": null,\"ports\": \"514\"}, {\"name\": \"SList\",\"description\": \"Service List\",\"type\": \"SERVICE\",\"transportProtocol\": \"tcp\",\"appProtocol\": null,\"ports\": \"8080\"}],\"addressGroups\": [{\"name\": \"1607Group\",\"description\": null,\"members\": [{\"type\": \"REFERENCE\",\"name\": \"10.11.12.13/14\"},{\"type\": \"REFERENCE\",\"name\": \"10.11.12.13/14\"}]},{\"name\": \"PL_CCE3\",\"description\": \"CCE Routers\",\"members\":[{\"type\": \"REFERENCE\",\"name\": \"10.11.12.13/14\"}]}],\"firewallRuleList\": [{\"position\": \"1\",\"ruleName\": \"1607Rule\",\"fromZones\": [\"Trusted\"],\"toZones\": [\"Untrusted\"],\"negateSource\": false,\"negateDestination\": false,\"sourceList\": [{\"type\": \"REFERENCE\",\"name\": \"PL_CCE3\"}, {\"type\": \"REFERENCE\",\"name\": \"1607Group\"}],\"destinationList\": [{\"type\": \"REFERENCE\",\"name\": \"1607Group\"}],\"sourceServices\": [],\"destServices\": [{\"type\": \"REFERENCE\",\"name\": \"1607Group\"}],\"action\": \"accept\",\"description\": \"Rule for 1607 templates\",\"enabled\": true,\"log\": true}]}"; + policyParameters.setConfigBody(json); + policyParameters.setPolicyName("test.testing"); + + PolicyChangeResponse result = fixture.createPolicy(policyParameters); + + assertEquals(response.getResponseMessage(), result.getResponseMessage()); + } + + /** + * Run the String createConfigPolicy(String,String,String,String,Map,String,String,String,UUID) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/3/16 2:03 PM + */ + @Test + public void testCreateConfigPolicy() + throws Exception { + response.setResponseMessage("success"); + PolicyParameters policyParameters = new PolicyParameters(); + policyParameters.setPolicyConfigType(PolicyConfigType.Base); + policyParameters.setPolicyName("test.junittest"); + policyParameters.setPolicyDescription("testing junit"); + policyParameters.setEcompName("test"); + policyParameters.setConfigName("testname"); + Map configAttributes = new HashMap(); + configAttributes.put("Template", "SampleTemplate"); + configAttributes.put("controller", "default"); + configAttributes.put("SamPoll", "30"); + configAttributes.put("value", "abcd"); + Map> attributes = new HashMap>(); + attributes.put(AttributeType.MATCHING, configAttributes); + policyParameters.setAttributes(attributes); + policyParameters.setRequestID(UUID.randomUUID()); + policyParameters.setConfigBodyType(PolicyType.OTHER); + policyParameters.setConfigBody("test"); + + PolicyChangeResponse result = fixture.createPolicy(policyParameters); + + assertEquals(response.getResponseMessage(), result.getResponseMessage()); + } + + + /** + * Run the String createUpdateActionPolicy(String,String,Map,List,List,List,List,String,String,String,Boolean,UUID) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/3/16 2:03 PM + */ + @Test + public void testCreateUpdateActionPolicy_Create() + throws Exception { + response.setResponseMessage("success"); + PolicyParameters policyParameters = new PolicyParameters(); + policyParameters.setPolicyClass(PolicyClass.Action); + policyParameters.setPolicyName("test.junittest"); + policyParameters.setPolicyDescription("testing"); + Map configAttributes = new HashMap(); + configAttributes.put("Template", "UpdateTemplate"); + configAttributes.put("controller", "default"); + configAttributes.put("SamPoll", "30"); + configAttributes.put("value", "abcd"); + Map> attributes = new HashMap>(); + attributes.put(AttributeType.MATCHING, configAttributes); + policyParameters.setAttributes(attributes); + policyParameters.setActionPerformer("PDP"); + policyParameters.setActionAttribute("test"); + + PolicyChangeResponse result = fixture.createPolicy(policyParameters); + + assertEquals(response.getResponseMessage(), result.getResponseMessage()); + } + + /** + * Run the String createUpdateActionPolicy(String,String,Map,List,List,List,List,String,String,String,Boolean,UUID) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/3/16 2:03 PM + */ + @Test + public void testCreateUpdateActionPolicy_Update() + throws Exception { + response.setResponseMessage("success"); + PolicyParameters policyParameters = new PolicyParameters(); + policyParameters.setPolicyClass(PolicyClass.Action); + policyParameters.setPolicyName("test.junittest"); + policyParameters.setPolicyDescription("testing"); + Map configAttributes = new HashMap(); + configAttributes.put("Template", "UpdateTemplate"); + configAttributes.put("controller", "default"); + configAttributes.put("SamPoll", "30"); + configAttributes.put("value", "abcd"); + Map> attributes = new HashMap>(); + attributes.put(AttributeType.MATCHING, configAttributes); + policyParameters.setAttributes(attributes); + policyParameters.setActionPerformer("PDP"); + policyParameters.setActionAttribute("test"); + + PolicyChangeResponse result = fixture.updatePolicy(policyParameters); + + assertEquals(response.getResponseMessage(), result.getResponseMessage()); + } + + + /** + * Run the String createUpdateBRMSParamPolicy(String,String,Map>,String,String,Boolean,UUID,Map>) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/3/16 2:03 PM + */ + @Test + public void testCreateUpdateBRMSParamPolicy_Create() + throws Exception { + response.setResponseMessage("success"); + PolicyParameters policyParameters = new PolicyParameters(); + policyParameters.setPolicyConfigType(PolicyConfigType.BRMS_PARAM); + policyParameters.setPolicyName("test.testing"); + policyParameters.setPolicyDescription("testing"); + Map ruleAttributes = new HashMap(); + ruleAttributes.put("templateName", "Sample"); // This sampleTemplate is the Template name from dictionary. + ruleAttributes.put("controller", "default"); // Set Rule to a PDP Controller, default is the controller name. + ruleAttributes.put("SamPoll", "300"); // Template specific key and value set by us. + ruleAttributes.put("value", "abcd"); // Template specific key and value set by us. + Map> attributes = new HashMap>(); + attributes.put(AttributeType.RULE, ruleAttributes); + policyParameters.setAttributes(attributes); + + PolicyChangeResponse result = fixture.createPolicy(policyParameters); + + assertEquals(response.getResponseMessage(), result.getResponseMessage()); + } + + /** + * Run the String createUpdateBRMSParamPolicy(String,String,Map>,String,String,Boolean,UUID,Map>) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/3/16 2:03 PM + */ + @Test + public void testCreateUpdateBRMSParamPolicy_Update() + throws Exception { + response.setResponseMessage("success"); + PolicyParameters policyParameters = new PolicyParameters(); + policyParameters.setPolicyConfigType(PolicyConfigType.BRMS_PARAM); + policyParameters.setPolicyName("test.testing"); + policyParameters.setPolicyDescription("testing"); + Map ruleAttributes = new HashMap(); + ruleAttributes.put("templateName", "Sample"); // This sampleTemplate is the Template name from dictionary. + ruleAttributes.put("controller", "default"); // Set Rule to a PDP Controller, default is the controller name. + ruleAttributes.put("SamPoll", "300"); // Template specific key and value set by us. + ruleAttributes.put("value", "abcd"); // Template specific key and value set by us. + Map> attributes = new HashMap>(); + attributes.put(AttributeType.RULE, ruleAttributes); + policyParameters.setAttributes(attributes); + + PolicyChangeResponse result = fixture.updatePolicy(policyParameters); + + assertEquals(response.getResponseMessage(), result.getResponseMessage()); + } + + /** + * Run the String createUpdateBRMSRawPolicy(String,String,Map>,String,String,Boolean,UUID) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/3/16 2:03 PM + */ + @Test + public void testCreateUpdateBRMSRawPolicy_Create() + throws Exception { + response.setResponseMessage("success"); + PolicyParameters policyParameters = new PolicyParameters(); + policyParameters.setPolicyConfigType(PolicyConfigType.BRMS_PARAM); + policyParameters.setPolicyName("test.testing"); + policyParameters.setPolicyDescription("testing"); + Map attrib= new HashMap(); + attrib.put("cpu","80"); + attrib.put("memory", "50"); + Map> attributes = new HashMap>(); + attributes.put(AttributeType.RULE, attrib); + + policyParameters.setAttributes(attributes); + + File rawBodyFile = null; + Path file = Paths.get("Test/test.Config_BRMS_Raw_TestBrmsPolicy.1.txt"); + rawBodyFile = file.toFile(); + + policyParameters.setConfigBody(readFile(rawBodyFile.toString())); + + PolicyChangeResponse result = fixture.updatePolicy(policyParameters); + + assertEquals(response.getResponseMessage(), result.getResponseMessage()); + } + + /** + * Run the PolicyChangeResponse createDictionaryItem(DictionaryParameters) method test. + * + * @throws Exception + * + */ + @Test + public void testCreateDictionaryItem() throws Exception { + response.setResponseMessage("success"); + DictionaryParameters parameters = new DictionaryParameters(); + + parameters.setDictionaryType(DictionaryType.Common); + parameters.setDictionary("Attribute"); + + Map fields = new HashMap(); + fields.put("ATTRIBUTEID", "A5:"); + fields.put("DATATYPE", "user"); + fields.put("DESCRIPTION", "testing something"); + fields.put("ATTRIBUTEVALUE", "1,2,A,B"); + fields.put("PRIORITY", "High"); + Map> dictionaryFields = new HashMap>(); + dictionaryFields.put(AttributeType.DICTIONARY, fields); + + parameters.setDictionaryFields(dictionaryFields); + + PolicyChangeResponse result = fixture.createDictionaryItem(parameters); + + assertEquals(response.getResponseMessage(), result.getResponseMessage()); + } + + + /** + * Run the PolicyDecision decide(DecisionRequestParameters) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/3/16 2:03 PM + */ + @Test + public void testDecide() + throws Exception { + //StdPolicyEngine fixture = new StdPolicyEngine("http", NotificationScheme.AUTO_ALL_NOTIFICATIONS, (NotificationHandler) null); + StdDecisionResponse response = new StdDecisionResponse(); + response.setDecision(PolicyDecision.PERMIT); + + DecisionRequestParameters decisionRequestParameters = new DecisionRequestParameters(); + decisionRequestParameters.setECOMPComponentName("testEcompName"); + Map decisionAttributes = new HashMap(); + decisionAttributes.put("key", "value"); + decisionRequestParameters.setDecisionAttributes(decisionAttributes); + decisionRequestParameters.setRequestID(UUID.randomUUID()); + + Mockito.when(mockEngine.decide(decisionRequestParameters)).thenReturn(response); + DecisionResponse result = mockEngine.decide(decisionRequestParameters); + + assertNotNull(result); + } + + /** + * Run the PolicyChangeResponse deletePolicy(DeletePolicyParameters) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/3/16 2:03 PM + */ + @Test + public void testDeletePolicy() + throws Exception { + response.setResponseMessage("success"); + DeletePolicyParameters parameters = new DeletePolicyParameters(); + parameters.setDeleteCondition(DeletePolicyCondition.ALL); + parameters.setPolicyComponent("PAP"); + parameters.setPolicyName("testing.Config_junittest.1.xml"); + + PolicyChangeResponse result = fixture.deletePolicy(parameters); + + assertNotNull(result); + } + + /** + * Run the Collection event(EventRequestParameters) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/3/16 2:03 PM + */ + @Test + public void testEvent() + throws Exception { + + //StdPolicyEngine fixture = new StdPolicyEngine("http", NotificationScheme.AUTO_ALL_NOTIFICATIONS, (NotificationHandler) null); + StdPolicyResponse response = new StdPolicyResponse(); + response.setPolicyResponseMessage("tested"); + Collection mockResult = new HashSet(); + mockResult.add(response); + StdPolicyEngine mockEngine = Mockito.mock(StdPolicyEngine.class); + + Map eventAttributes = new HashMap(); + eventAttributes.put("key", "test"); + EventRequestParameters eventRequestParameters = new EventRequestParameters(eventAttributes, UUID.randomUUID()); + Mockito.when(mockEngine.event(eventRequestParameters)).thenReturn(mockResult); + + Collection result = mockEngine.event(eventRequestParameters); + + assertEquals(result, mockResult); + } + + /** + * Run the PDPNotification getNotification() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/3/16 2:03 PM + */ +/* @Test + public void testGetNotification() + throws Exception { + //StdPolicyEngine fixture = new StdPolicyEngine("http", NotificationScheme.AUTO_ALL_NOTIFICATIONS, (NotificationHandler) null); + + PDPNotification result = fixture.getNotification(); + + assertNull(result); + }*/ + + /** + * Run the NotificationHandler getNotificationHandler() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/3/16 2:03 PM + */ + @Test + public void testGetNotificationHandler() + throws Exception { + //StdPolicyEngine fixture = new StdPolicyEngine("http", NotificationScheme.AUTO_ALL_NOTIFICATIONS, (NotificationHandler) null); + + NotificationHandler result = fixture.getNotificationHandler(); + + assertNull(result); + } + + /** + * Run the String getPAPURL() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/3/16 2:03 PM + */ + @Test + public void testGetPAPURL() + throws Exception { + + String result = StdPolicyEngine.getPAPURL(); + + assertNotNull(result); + } + + /** + * Run the String getPDPURL() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/3/16 2:03 PM + */ + @Test + public void testGetPDPURL() + throws Exception { + + String result = StdPolicyEngine.getPDPURL(); + + assertNotNull(result); + } + + /** + * Run the NotificationScheme getScheme() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/3/16 2:03 PM + */ + @Test + public void testGetScheme() + throws Exception { + //StdPolicyEngine fixture = new StdPolicyEngine("http", NotificationScheme.AUTO_ALL_NOTIFICATIONS, (NotificationHandler) null); + + NotificationScheme result = fixture.getScheme(); + + assertNull(result); + } + + /** + * Run the boolean isJSONValid(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/3/16 2:03 PM + */ + @Test + public void testIsJSONValid() + throws Exception { + String data = "{\"test\": \"testing\"}"; + + boolean result = StdPolicyEngine.isJSONValid(data); + + assertTrue(result); + } + + /** + * Run the void notification(NotificationScheme,NotificationHandler) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/3/16 2:03 PM + */ +/* @Test + public void testNotification() + throws Exception { + //StdPolicyEngine fixture = new StdPolicyEngine("http", NotificationScheme.AUTO_ALL_NOTIFICATIONS, (NotificationHandler) null); + NotificationScheme scheme = NotificationScheme.AUTO_ALL_NOTIFICATIONS; + Handler handler = new Handler(); + + fixture.notification(scheme, handler); + + } +*/ + /** + * Run the PolicyChangeResponse policyEngineImport(ImportParameters) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/3/16 2:03 PM + */ + @Test + public void testPolicyEngineImport() + throws Exception { + response.setResponseMessage("success"); + ImportParameters importParameters = new ImportParameters(); + importParameters.setServiceName("ControllerServiceSampleSdnlServiceInstance"); + importParameters.setVersion("1607-2"); + importParameters.setFilePath("C:\\Workspaces\\models\\TestingModel\\ControllerServiceSampleSdnlServiceInstance-v0.1.0-SNAPSHOT.zip"); + importParameters.setServiceType(IMPORT_TYPE.MICROSERVICE); + + PolicyChangeResponse result = fixture.policyEngineImport(importParameters); + + assertNotNull(result); + + } + + /** + * Run the Collection policyName(String,UUID) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/3/16 2:03 PM + */ + @Test + public void testPolicyName() + throws Exception { + //StdPolicyEngine fixture = new StdPolicyEngine("http", NotificationScheme.AUTO_ALL_NOTIFICATIONS, (NotificationHandler) null); + StdPolicyConfig config = new StdPolicyConfig(); + config.setPolicyName("testing"); + Collection response = new HashSet(); + response.add(config); + String policyName = "test.testing"; + UUID requestID = UUID.randomUUID(); + + Mockito.when(mockEngine.policyName(policyName, requestID)).thenReturn(response); + Collection result = mockEngine.policyName(policyName, requestID); + + assertEquals(result, response); + } + + /** + * Run the PolicyChangeResponse pushPolicy(PushPolicyParameters) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/3/16 2:03 PM + */ + @Test + public void testPushPolicy() + throws Exception { + response.setResponseMessage("success"); + + response.setResponseMessage("success"); + PolicyChangeResponse result = null; + + PushPolicyParameters pushPolicyParameters = new PushPolicyParameters(); + pushPolicyParameters.setPolicyName("test.testPolicy"); + pushPolicyParameters.setPdpGroup("default"); + pushPolicyParameters.setPolicyType("Base"); + + try { + + Mockito.when(mockEngine.pushPolicy(pushPolicyParameters)).thenReturn(response); + result = mockEngine.pushPolicy(pushPolicyParameters); + + } catch (Exception e) { + logger.warn(e.getMessage()); + } + assertEquals(result, response); + } + + /** + * Run the void rotateList() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/3/16 2:03 PM + */ + @Test + public void testRotateList() + throws Exception { + + StdPolicyEngine.rotateList(); + + } + + /** + * Run the void setScheme(NotificationScheme) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/3/16 2:03 PM + */ + @Test + public void testSetScheme() + throws Exception { + //StdPolicyEngine fixture = new StdPolicyEngine("http", NotificationScheme.AUTO_ALL_NOTIFICATIONS, (NotificationHandler) null); + NotificationScheme scheme = NotificationScheme.AUTO_ALL_NOTIFICATIONS; + + fixture.setScheme(scheme); + + } + + /** + * Run the void stopNotification() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/3/16 2:03 PM + */ +/* @Test + public void testStopNotification_1() + throws Exception { + Handler handler = new Handler(); + + Mockito.doNothing().when(mockStdPolicyEngine).notification(NotificationScheme.AUTO_ALL_NOTIFICATIONS, handler); + StdPolicyEngine fixture = new StdPolicyEngine("Test/config_pass.properties", NotificationScheme.AUTO_ALL_NOTIFICATIONS, handler); + + //verify(mockStdPolicyEngine, times(1)).fixture("Test/config_pass.properties", NotificationScheme.AUTO_ALL_NOTIFICATIONS, handler); + + fixture.stopNotification(); + }*/ + + /** + * Run the String updateConfigFirewallPolicy(String,JsonObject,String,UUID) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/3/16 2:03 PM + */ + @Test + public void testUpdateConfigFirewallPolicy() + throws Exception { + response.setResponseMessage("success"); + String json= "{\"serviceTypeId\": \"/v0/firewall/pan\",\"configName\": \"rule1607\",\"deploymentOption\":{\"deployNow\": false},\"securityZoneId\": \"/v0/firewall/pan\",\"serviceGroups\": [{\"name\": \"1607Group\",\"description\": null,\"members\": [{\"type\": \"REFERENCE\",\"name\": \"SList\"},{\"type\": \"REFERENCE\",\"name\": \"Syslog\"}]}, {\"name\": \"Syslog\",\"description\": \"NA\",\"type\": \"SERVICE\",\"transportProtocol\": \"udp\",\"appProtocol\": null,\"ports\": \"514\"}, {\"name\": \"SList\",\"description\": \"Service List\",\"type\": \"SERVICE\",\"transportProtocol\": \"tcp\",\"appProtocol\": null,\"ports\": \"8080\"}],\"addressGroups\": [{\"name\": \"1607Group\",\"description\": null,\"members\": [{\"type\": \"REFERENCE\",\"name\": \"10.11.12.13/14\"},{\"type\": \"REFERENCE\",\"name\": \"10.11.12.13/14\"}]},{\"name\": \"PL_CCE3\",\"description\": \"CCE Routers\",\"members\":[{\"type\": \"REFERENCE\",\"name\": \"10.11.12.13/14\"}]}],\"firewallRuleList\": [{\"position\": \"1\",\"ruleName\": \"1607Rule\",\"fromZones\": [\"Trusted\"],\"toZones\": [\"Untrusted\"],\"negateSource\": false,\"negateDestination\": false,\"sourceList\": [{\"type\": \"REFERENCE\",\"name\": \"PL_CCE3\"}, {\"type\": \"REFERENCE\",\"name\": \"1607Group\"}],\"destinationList\": [{\"type\": \"REFERENCE\",\"name\": \"1607Group\"}],\"sourceServices\": [],\"destServices\": [{\"type\": \"REFERENCE\",\"name\": \"1607Group\"}],\"action\": \"accept\",\"description\": \"Rule for 1607 templates\",\"enabled\": true,\"log\": true}]}"; + String policyName = "testing"; + JsonObject firewallJson = buildJSON(json); + String policyScope = "test"; + UUID requestID = UUID.randomUUID(); + String riskLevel = ""; + String riskType = ""; + String guard = ""; + String date = ""; + + String result = fixture.updateConfigFirewallPolicy(policyName, firewallJson, policyScope, requestID,riskLevel, riskType, guard, date); + + assertNotNull(result); + } + + + /** + * Perform post-test clean-up. + * + * @throws Exception + * if the clean-up fails for some reason + * + * @generatedBy CodePro at 6/3/16 2:03 PM + */ + @After + public void tearDown() + throws Exception { + // Add additional tear down code here + } + + /** + * Launch the test. + * + * @param args the command line arguments + * + * @generatedBy CodePro at 6/3/16 2:03 PM + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(StdPolicyEngineTest.class); + } +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/StdPolicyResponseTest.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/StdPolicyResponseTest.java new file mode 100644 index 000000000..2cb21ef19 --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/StdPolicyResponseTest.java @@ -0,0 +1,348 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.std.test; + +import java.util.Hashtable; +import java.util.Map; + +import org.junit.*; +import org.openecomp.policy.api.PolicyResponseStatus; +import org.openecomp.policy.std.StdPolicyResponse; + +import static org.junit.Assert.*; + +/** + * The class StdPolicyResponseTest contains tests for the class {@link StdPolicyResponse}. + * + * @generatedBy CodePro at 6/1/16 1:40 PM + * @version $Revision: 1.0 $ + */ +public class StdPolicyResponseTest { + /** + * Run the Map getActionAdvised() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetActionAdvised_1() + throws Exception { + StdPolicyResponse fixture = new StdPolicyResponse(); + fixture.setPolicyResponseStatus("", PolicyResponseStatus.ACTION_ADVISED); + fixture.setRequestAttributes(new Hashtable()); + fixture.setActionAdvised(new Hashtable()); + fixture.setActionTaken(new Hashtable()); + + Map result = fixture.getActionAdvised(); + + // add additional test code here + assertNotNull(result); + assertEquals(0, result.size()); + } + + /** + * Run the Map getActionTaken() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetActionTaken_1() + throws Exception { + StdPolicyResponse fixture = new StdPolicyResponse(); + fixture.setPolicyResponseStatus("", PolicyResponseStatus.ACTION_ADVISED); + fixture.setRequestAttributes(new Hashtable()); + fixture.setActionAdvised(new Hashtable()); + fixture.setActionTaken(new Hashtable()); + + Map result = fixture.getActionTaken(); + + // add additional test code here + assertNotNull(result); + assertEquals(0, result.size()); + } + + /** + * Run the String getPolicyResponseMessage() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetPolicyResponseMessage_1() + throws Exception { + StdPolicyResponse fixture = new StdPolicyResponse(); + fixture.setPolicyResponseStatus("", PolicyResponseStatus.ACTION_ADVISED); + fixture.setRequestAttributes(new Hashtable()); + fixture.setActionAdvised(new Hashtable()); + fixture.setActionTaken(new Hashtable()); + + String result = fixture.getPolicyResponseMessage(); + + // add additional test code here + assertEquals("", result); + } + + /** + * Run the PolicyResponseStatus getPolicyResponseStatus() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetPolicyResponseStatus_1() + throws Exception { + StdPolicyResponse fixture = new StdPolicyResponse(); + fixture.setPolicyResponseStatus("", PolicyResponseStatus.ACTION_ADVISED); + fixture.setRequestAttributes(new Hashtable()); + fixture.setActionAdvised(new Hashtable()); + fixture.setActionTaken(new Hashtable()); + + PolicyResponseStatus result = fixture.getPolicyResponseStatus(); + + // add additional test code here + assertNotNull(result); + assertEquals("action_advised", result.toString()); + assertEquals("ACTION_ADVISED", result.name()); + assertEquals(1, result.ordinal()); + } + + /** + * Run the Map getRequestAttributes() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetRequestAttributes_1() + throws Exception { + StdPolicyResponse fixture = new StdPolicyResponse(); + fixture.setPolicyResponseStatus("", PolicyResponseStatus.ACTION_ADVISED); + fixture.setRequestAttributes(new Hashtable()); + fixture.setActionAdvised(new Hashtable()); + fixture.setActionTaken(new Hashtable()); + + Map result = fixture.getRequestAttributes(); + + // add additional test code here + assertNotNull(result); + assertEquals(0, result.size()); + } + + /** + * Run the void setActionAdvised(Map) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetActionAdvised_1() + throws Exception { + StdPolicyResponse fixture = new StdPolicyResponse(); + fixture.setPolicyResponseStatus("", PolicyResponseStatus.ACTION_ADVISED); + fixture.setRequestAttributes(new Hashtable()); + fixture.setActionAdvised(new Hashtable()); + fixture.setActionTaken(new Hashtable()); + Map actionAdvised = new Hashtable(); + + fixture.setActionAdvised(actionAdvised); + + // add additional test code here + } + + /** + * Run the void setActionTaken(Map) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetActionTaken_1() + throws Exception { + StdPolicyResponse fixture = new StdPolicyResponse(); + fixture.setPolicyResponseStatus("", PolicyResponseStatus.ACTION_ADVISED); + fixture.setRequestAttributes(new Hashtable()); + fixture.setActionAdvised(new Hashtable()); + fixture.setActionTaken(new Hashtable()); + Map actionTaken = new Hashtable(); + + fixture.setActionTaken(actionTaken); + + // add additional test code here + } + + /** + * Run the void setPolicyResponseMessage(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetPolicyResponseMessage_1() + throws Exception { + StdPolicyResponse fixture = new StdPolicyResponse(); + fixture.setPolicyResponseStatus("", PolicyResponseStatus.ACTION_ADVISED); + fixture.setRequestAttributes(new Hashtable()); + fixture.setActionAdvised(new Hashtable()); + fixture.setActionTaken(new Hashtable()); + String policyResponseMessage = ""; + + fixture.setPolicyResponseMessage(policyResponseMessage); + + // add additional test code here + } + + /** + * Run the void setPolicyResponseStatus(PolicyResponseStatus) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetPolicyResponseStatus_1() + throws Exception { + StdPolicyResponse fixture = new StdPolicyResponse(); + fixture.setPolicyResponseStatus("", PolicyResponseStatus.ACTION_ADVISED); + fixture.setRequestAttributes(new Hashtable()); + fixture.setActionAdvised(new Hashtable()); + fixture.setActionTaken(new Hashtable()); + PolicyResponseStatus policyResponseStatus = PolicyResponseStatus.ACTION_ADVISED; + + fixture.setPolicyResponseStatus(policyResponseStatus); + + // add additional test code here + } + + /** + * Run the void setPolicyResponseStatus(String,PolicyResponseStatus) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetPolicyResponseStatus_2() + throws Exception { + StdPolicyResponse fixture = new StdPolicyResponse(); + fixture.setPolicyResponseStatus("", PolicyResponseStatus.ACTION_ADVISED); + fixture.setRequestAttributes(new Hashtable()); + fixture.setActionAdvised(new Hashtable()); + fixture.setActionTaken(new Hashtable()); + String policyResponseMessage = ""; + PolicyResponseStatus policyResponseStatus = PolicyResponseStatus.ACTION_ADVISED; + + fixture.setPolicyResponseStatus(policyResponseMessage, policyResponseStatus); + + // add additional test code here + } + + /** + * Run the void setRequestAttributes(Map) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetRequestAttributes_1() + throws Exception { + StdPolicyResponse fixture = new StdPolicyResponse(); + fixture.setPolicyResponseStatus("", PolicyResponseStatus.ACTION_ADVISED); + fixture.setRequestAttributes(new Hashtable()); + fixture.setActionAdvised(new Hashtable()); + fixture.setActionTaken(new Hashtable()); + Map requestAttributes = new Hashtable(); + + fixture.setRequestAttributes(requestAttributes); + + // add additional test code here + } + + /** + * Run the String toString() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testToString_1() + throws Exception { + StdPolicyResponse fixture = new StdPolicyResponse(); + fixture.setPolicyResponseStatus("", PolicyResponseStatus.ACTION_ADVISED); + fixture.setRequestAttributes(new Hashtable()); + fixture.setActionAdvised(new Hashtable()); + fixture.setActionTaken(new Hashtable()); + + String result = fixture.toString(); + + // add additional test code here + assertEquals("PolicyResponse [ policyResponseStatus=action_advised, policyResponseMessage=, ]", result); + } + + /** + * Perform pre-test initialization. + * + * @throws Exception + * if the initialization fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Before + public void setUp() + throws Exception { + // add additional set up code here + } + + /** + * Perform post-test clean-up. + * + * @throws Exception + * if the clean-up fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @After + public void tearDown() + throws Exception { + // Add additional tear down code here + } + + /** + * Launch the test. + * + * @param args the command line arguments + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(StdPolicyResponseTest.class); + } +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/StdRemovedPolicyTest.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/StdRemovedPolicyTest.java new file mode 100644 index 000000000..0a0865c82 --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/StdRemovedPolicyTest.java @@ -0,0 +1,206 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.std.test; + +import org.junit.*; +import org.openecomp.policy.std.StdRemovedPolicy; + +import static org.junit.Assert.*; + +/** + * The class StdRemovedPolicyTest contains tests for the class {@link StdRemovedPolicy}. + * + * @generatedBy CodePro at 6/1/16 1:40 PM + * @version $Revision: 1.0 $ + */ +public class StdRemovedPolicyTest { + /** + * Run the StdRemovedPolicy() constructor test. + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testStdRemovedPolicy_1() + throws Exception { + StdRemovedPolicy result = new StdRemovedPolicy(); + assertNotNull(result); + // add additional test code here + } + + /** + * Run the String getPolicyName() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetPolicyName_1() + throws Exception { + StdRemovedPolicy fixture = new StdRemovedPolicy(); + fixture.setVersionNo(""); + fixture.setPolicyName(""); + + String result = fixture.getPolicyName(); + + // add additional test code here + assertEquals("", result); + } + + /** + * Run the String getPolicyName() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetPolicyName_2() + throws Exception { + StdRemovedPolicy fixture = new StdRemovedPolicy(); + fixture.setVersionNo(""); + fixture.setPolicyName((String) null); + + String result = fixture.getPolicyName(); + + // add additional test code here + assertEquals(null, result); + } + + /** + * Run the String getPolicyName() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetPolicyName_3() + throws Exception { + StdRemovedPolicy fixture = new StdRemovedPolicy(); + fixture.setVersionNo(""); + fixture.setPolicyName(""); + + String result = fixture.getPolicyName(); + + // add additional test code here + assertEquals("", result); + } + + /** + * Run the String getVersionNo() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetVersionNo_1() + throws Exception { + StdRemovedPolicy fixture = new StdRemovedPolicy(); + fixture.setVersionNo(""); + fixture.setPolicyName(""); + + String result = fixture.getVersionNo(); + + // add additional test code here + assertEquals("", result); + } + + /** + * Run the void setPolicyName(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetPolicyName_1() + throws Exception { + StdRemovedPolicy fixture = new StdRemovedPolicy(); + fixture.setVersionNo(""); + fixture.setPolicyName(""); + String policyName = ""; + + fixture.setPolicyName(policyName); + + // add additional test code here + } + + /** + * Run the void setVersionNo(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetVersionNo_1() + throws Exception { + StdRemovedPolicy fixture = new StdRemovedPolicy(); + fixture.setVersionNo(""); + fixture.setPolicyName(""); + String versionNo = ""; + + fixture.setVersionNo(versionNo); + + // add additional test code here + } + + /** + * Perform pre-test initialization. + * + * @throws Exception + * if the initialization fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Before + public void setUp() + throws Exception { + // add additional set up code here + } + + /** + * Perform post-test clean-up. + * + * @throws Exception + * if the clean-up fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @After + public void tearDown() + throws Exception { + // Add additional tear down code here + } + + /** + * Launch the test. + * + * @param args the command line arguments + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(StdRemovedPolicyTest.class); + } +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/StdStatusTest.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/StdStatusTest.java new file mode 100644 index 000000000..4412dbdb7 --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/StdStatusTest.java @@ -0,0 +1,1433 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.std.test; + +import java.util.Hashtable; +import java.util.Map; +import java.util.Properties; + +import javax.json.JsonObject; + +import org.junit.*; +import org.openecomp.policy.api.PolicyConfigStatus; +import org.openecomp.policy.api.PolicyDecision; +import org.openecomp.policy.api.PolicyResponseStatus; +import org.openecomp.policy.api.PolicyType; +import org.openecomp.policy.std.StdStatus; + +import static org.junit.Assert.*; + +import org.w3c.dom.Document; + +/** + * The class StdStatusTest contains tests for the class {@link StdStatus}. + * + * @generatedBy CodePro at 6/1/16 1:40 PM + * @version $Revision: 1.0 $ + */ +public class StdStatusTest { + /** + * Run the Map getActionAdvised() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetActionAdvised_1() + throws Exception { + StdStatus fixture = new StdStatus(); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setPolicyName(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setResposneAttributes(new Hashtable()); + fixture.setMatchingConditions(new Hashtable()); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setJsonObject((JsonObject) null); + fixture.setDocument((Document) null); + fixture.setProperties(new Properties()); + fixture.setRequestAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setActionAdvised(new Hashtable()); + fixture.setOther(""); + fixture.setDecision(PolicyDecision.DENY); + fixture.setDetails(""); + fixture.setActionTaken(new Hashtable()); + + Map result = fixture.getActionAdvised(); + + // add additional test code here + assertNotNull(result); + assertEquals(0, result.size()); + } + + /** + * Run the Map getActionTaken() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetActionTaken_1() + throws Exception { + StdStatus fixture = new StdStatus(); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setPolicyName(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setResposneAttributes(new Hashtable()); + fixture.setMatchingConditions(new Hashtable()); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setJsonObject((JsonObject) null); + fixture.setDocument((Document) null); + fixture.setProperties(new Properties()); + fixture.setRequestAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setActionAdvised(new Hashtable()); + fixture.setOther(""); + fixture.setDecision(PolicyDecision.DENY); + fixture.setDetails(""); + fixture.setActionTaken(new Hashtable()); + + Map result = fixture.getActionTaken(); + + // add additional test code here + assertNotNull(result); + assertEquals(0, result.size()); + } + + /** + * Run the Map getMatchingConditions() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetMatchingConditions_1() + throws Exception { + StdStatus fixture = new StdStatus(); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setPolicyName(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setResposneAttributes(new Hashtable()); + fixture.setMatchingConditions(new Hashtable()); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setJsonObject((JsonObject) null); + fixture.setDocument((Document) null); + fixture.setProperties(new Properties()); + fixture.setRequestAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setActionAdvised(new Hashtable()); + fixture.setOther(""); + fixture.setDecision(PolicyDecision.DENY); + fixture.setDetails(""); + fixture.setActionTaken(new Hashtable()); + + Map result = fixture.getMatchingConditions(); + + // add additional test code here + assertNotNull(result); + assertEquals(0, result.size()); + } + + /** + * Run the String getPolicyConfigMessage() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetPolicyConfigMessage_1() + throws Exception { + StdStatus fixture = new StdStatus(); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setPolicyName(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setResposneAttributes(new Hashtable()); + fixture.setMatchingConditions(new Hashtable()); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setJsonObject((JsonObject) null); + fixture.setDocument((Document) null); + fixture.setProperties(new Properties()); + fixture.setRequestAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setActionAdvised(new Hashtable()); + fixture.setOther(""); + fixture.setDecision(PolicyDecision.DENY); + fixture.setDetails(""); + fixture.setActionTaken(new Hashtable()); + + String result = fixture.getPolicyConfigMessage(); + + // add additional test code here + assertEquals("", result); + } + + /** + * Run the PolicyConfigStatus getPolicyConfigStatus() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetPolicyConfigStatus_1() + throws Exception { + StdStatus fixture = new StdStatus(); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setPolicyName(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setResposneAttributes(new Hashtable()); + fixture.setMatchingConditions(new Hashtable()); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setJsonObject((JsonObject) null); + fixture.setDocument((Document) null); + fixture.setProperties(new Properties()); + fixture.setRequestAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setActionAdvised(new Hashtable()); + fixture.setOther(""); + fixture.setDecision(PolicyDecision.DENY); + fixture.setDetails(""); + fixture.setActionTaken(new Hashtable()); + + PolicyConfigStatus result = fixture.getPolicyConfigStatus(); + + // add additional test code here + assertNotNull(result); + assertEquals("not_found", result.toString()); + assertEquals("CONFIG_NOT_FOUND", result.name()); + assertEquals(1, result.ordinal()); + } + + /** + * Run the PolicyDecision getPolicyDecision() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetPolicyDecision_1() + throws Exception { + StdStatus fixture = new StdStatus(); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setPolicyName(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setResposneAttributes(new Hashtable()); + fixture.setMatchingConditions(new Hashtable()); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setJsonObject((JsonObject) null); + fixture.setDocument((Document) null); + fixture.setProperties(new Properties()); + fixture.setRequestAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setActionAdvised(new Hashtable()); + fixture.setOther(""); + fixture.setDecision(PolicyDecision.DENY); + fixture.setDetails(""); + fixture.setActionTaken(new Hashtable()); + + PolicyDecision result = fixture.getDecision(); + + // add additional test code here + assertNotNull(result); + assertEquals("deny", result.toString()); + assertEquals("DENY", result.name()); + assertEquals(1, result.ordinal()); + } + + /** + * Run the String getPolicyName() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetPolicyName_1() + throws Exception { + StdStatus fixture = new StdStatus(); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setPolicyName(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setResposneAttributes(new Hashtable()); + fixture.setMatchingConditions(new Hashtable()); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setJsonObject((JsonObject) null); + fixture.setDocument((Document) null); + fixture.setProperties(new Properties()); + fixture.setRequestAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setActionAdvised(new Hashtable()); + fixture.setOther(""); + fixture.setDecision(PolicyDecision.DENY); + fixture.setDetails(""); + fixture.setActionTaken(new Hashtable()); + + String result = fixture.getPolicyName(); + + // add additional test code here + assertEquals("", result); + } + + /** + * Run the String getPolicyName() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetPolicyName_2() + throws Exception { + StdStatus fixture = new StdStatus(); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setPolicyName((String) null); + fixture.setPolicyType(PolicyType.JSON); + fixture.setResposneAttributes(new Hashtable()); + fixture.setMatchingConditions(new Hashtable()); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setJsonObject((JsonObject) null); + fixture.setDocument((Document) null); + fixture.setProperties(new Properties()); + fixture.setRequestAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setActionAdvised(new Hashtable()); + fixture.setOther(""); + fixture.setDecision(PolicyDecision.DENY); + fixture.setDetails(""); + fixture.setActionTaken(new Hashtable()); + + String result = fixture.getPolicyName(); + + // add additional test code here + assertEquals(null, result); + } + + /** + * Run the String getPolicyName() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetPolicyName_3() + throws Exception { + StdStatus fixture = new StdStatus(); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setPolicyName(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setResposneAttributes(new Hashtable()); + fixture.setMatchingConditions(new Hashtable()); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setJsonObject((JsonObject) null); + fixture.setDocument((Document) null); + fixture.setProperties(new Properties()); + fixture.setRequestAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setActionAdvised(new Hashtable()); + fixture.setOther(""); + fixture.setDecision(PolicyDecision.DENY); + fixture.setDetails(""); + fixture.setActionTaken(new Hashtable()); + + String result = fixture.getPolicyName(); + + // add additional test code here + assertEquals("", result); + } + + /** + * Run the String getPolicyResponseMessage() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetPolicyResponseMessage_1() + throws Exception { + StdStatus fixture = new StdStatus(); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setPolicyName(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setResposneAttributes(new Hashtable()); + fixture.setMatchingConditions(new Hashtable()); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setJsonObject((JsonObject) null); + fixture.setDocument((Document) null); + fixture.setProperties(new Properties()); + fixture.setRequestAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setActionAdvised(new Hashtable()); + fixture.setOther(""); + fixture.setDecision(PolicyDecision.DENY); + fixture.setDetails(""); + fixture.setActionTaken(new Hashtable()); + + String result = fixture.getPolicyResponseMessage(); + + // add additional test code here + assertEquals("", result); + } + + /** + * Run the PolicyResponseStatus getPolicyResponseStatus() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetPolicyResponseStatus_1() + throws Exception { + StdStatus fixture = new StdStatus(); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setPolicyName(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setResposneAttributes(new Hashtable()); + fixture.setMatchingConditions(new Hashtable()); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setJsonObject((JsonObject) null); + fixture.setDocument((Document) null); + fixture.setProperties(new Properties()); + fixture.setRequestAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setActionAdvised(new Hashtable()); + fixture.setOther(""); + fixture.setDecision(PolicyDecision.DENY); + fixture.setDetails(""); + fixture.setActionTaken(new Hashtable()); + + PolicyResponseStatus result = fixture.getPolicyResponseStatus(); + + // add additional test code here + assertNotNull(result); + assertEquals("action_advised", result.toString()); + assertEquals("ACTION_ADVISED", result.name()); + assertEquals(1, result.ordinal()); + } + + /** + * Run the String getPolicyVersion() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetPolicyVersion_1() + throws Exception { + StdStatus fixture = new StdStatus(); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setPolicyName(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setResposneAttributes(new Hashtable()); + fixture.setMatchingConditions(new Hashtable()); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setJsonObject((JsonObject) null); + fixture.setDocument((Document) null); + fixture.setProperties(new Properties()); + fixture.setRequestAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setActionAdvised(new Hashtable()); + fixture.setOther(""); + fixture.setDecision(PolicyDecision.DENY); + fixture.setDetails(""); + fixture.setActionTaken(new Hashtable()); + + String result = fixture.getPolicyVersion(); + + // add additional test code here + assertEquals("", result); + } + + /** + * Run the Map getRequestAttributes() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetRequestAttributes_1() + throws Exception { + StdStatus fixture = new StdStatus(); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setPolicyName(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setResposneAttributes(new Hashtable()); + fixture.setMatchingConditions(new Hashtable()); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setJsonObject((JsonObject) null); + fixture.setDocument((Document) null); + fixture.setProperties(new Properties()); + fixture.setRequestAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setActionAdvised(new Hashtable()); + fixture.setOther(""); + fixture.setDecision(PolicyDecision.DENY); + fixture.setDetails(""); + fixture.setActionTaken(new Hashtable()); + + Map result = fixture.getRequestAttributes(); + + // add additional test code here + assertNotNull(result); + assertEquals(0, result.size()); + } + + /** + * Run the Map getResponseAttributes() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetResponseAttributes_1() + throws Exception { + StdStatus fixture = new StdStatus(); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setPolicyName(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setResposneAttributes(new Hashtable()); + fixture.setMatchingConditions(new Hashtable()); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setJsonObject((JsonObject) null); + fixture.setDocument((Document) null); + fixture.setProperties(new Properties()); + fixture.setRequestAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setActionAdvised(new Hashtable()); + fixture.setOther(""); + fixture.setDecision(PolicyDecision.DENY); + fixture.setDetails(""); + fixture.setActionTaken(new Hashtable()); + + Map result = fixture.getResponseAttributes(); + + // add additional test code here + assertNotNull(result); + assertEquals(0, result.size()); + } + + /** + * Run the PolicyType getType() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetType_1() + throws Exception { + StdStatus fixture = new StdStatus(); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setPolicyName(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setResposneAttributes(new Hashtable()); + fixture.setMatchingConditions(new Hashtable()); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setJsonObject((JsonObject) null); + fixture.setDocument((Document) null); + fixture.setProperties(new Properties()); + fixture.setRequestAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setActionAdvised(new Hashtable()); + fixture.setOther(""); + fixture.setDecision(PolicyDecision.DENY); + fixture.setDetails(""); + fixture.setActionTaken(new Hashtable()); + + PolicyType result = fixture.getType(); + + // add additional test code here + assertNotNull(result); + assertEquals("json", result.toString()); + assertEquals("JSON", result.name()); + assertEquals(1, result.ordinal()); + } + + /** + * Run the void setActionAdvised(Map) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetActionAdvised_1() + throws Exception { + StdStatus fixture = new StdStatus(); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setPolicyName(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setResposneAttributes(new Hashtable()); + fixture.setMatchingConditions(new Hashtable()); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setJsonObject((JsonObject) null); + fixture.setDocument((Document) null); + fixture.setProperties(new Properties()); + fixture.setRequestAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setActionAdvised(new Hashtable()); + fixture.setOther(""); + fixture.setDecision(PolicyDecision.DENY); + fixture.setDetails(""); + fixture.setActionTaken(new Hashtable()); + Map actionAdvised = new Hashtable(); + + fixture.setActionAdvised(actionAdvised); + + // add additional test code here + } + + /** + * Run the void setActionTaken(Map) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetActionTaken_1() + throws Exception { + StdStatus fixture = new StdStatus(); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setPolicyName(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setResposneAttributes(new Hashtable()); + fixture.setMatchingConditions(new Hashtable()); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setJsonObject((JsonObject) null); + fixture.setDocument((Document) null); + fixture.setProperties(new Properties()); + fixture.setRequestAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setActionAdvised(new Hashtable()); + fixture.setOther(""); + fixture.setDecision(PolicyDecision.DENY); + fixture.setDetails(""); + fixture.setActionTaken(new Hashtable()); + Map actionTaken = new Hashtable(); + + fixture.setActionTaken(actionTaken); + + // add additional test code here + } + + /** + * Run the void setConfigStatus(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetConfigStatus_1() + throws Exception { + StdStatus fixture = new StdStatus(); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setPolicyName(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setResposneAttributes(new Hashtable()); + fixture.setMatchingConditions(new Hashtable()); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setJsonObject((JsonObject) null); + fixture.setDocument((Document) null); + fixture.setProperties(new Properties()); + fixture.setRequestAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setActionAdvised(new Hashtable()); + fixture.setOther(""); + fixture.setDecision(PolicyDecision.DENY); + fixture.setDetails(""); + fixture.setActionTaken(new Hashtable()); + String configStatus = ""; + + fixture.setConfigStatus(configStatus); + + // add additional test code here + } + + /** + * Run the void setDocument(Document) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetDocument_1() + throws Exception { + StdStatus fixture = new StdStatus(); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setPolicyName(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setResposneAttributes(new Hashtable()); + fixture.setMatchingConditions(new Hashtable()); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setJsonObject((JsonObject) null); + fixture.setDocument((Document) null); + fixture.setProperties(new Properties()); + fixture.setRequestAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setActionAdvised(new Hashtable()); + fixture.setOther(""); + fixture.setDecision(PolicyDecision.DENY); + fixture.setDetails(""); + fixture.setActionTaken(new Hashtable()); + Document document = null; + + fixture.setDocument(document); + + // add additional test code here + } + + /** + * Run the void setJsonObject(JsonObject) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetJsonObject_1() + throws Exception { + StdStatus fixture = new StdStatus(); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setPolicyName(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setResposneAttributes(new Hashtable()); + fixture.setMatchingConditions(new Hashtable()); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setJsonObject((JsonObject) null); + fixture.setDocument((Document) null); + fixture.setProperties(new Properties()); + fixture.setRequestAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setActionAdvised(new Hashtable()); + fixture.setOther(""); + fixture.setDecision(PolicyDecision.DENY); + fixture.setDetails(""); + fixture.setActionTaken(new Hashtable()); + JsonObject jsonObject = null; + + fixture.setJsonObject(jsonObject); + + // add additional test code here + } + + /** + * Run the void setMatchingConditions(Map) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetMatchingConditions_1() + throws Exception { + StdStatus fixture = new StdStatus(); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setPolicyName(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setResposneAttributes(new Hashtable()); + fixture.setMatchingConditions(new Hashtable()); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setJsonObject((JsonObject) null); + fixture.setDocument((Document) null); + fixture.setProperties(new Properties()); + fixture.setRequestAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setActionAdvised(new Hashtable()); + fixture.setOther(""); + fixture.setDecision(PolicyDecision.DENY); + fixture.setDetails(""); + fixture.setActionTaken(new Hashtable()); + Map matchingConditions = new Hashtable(); + + fixture.setMatchingConditions(matchingConditions); + + // add additional test code here + } + + /** + * Run the void setOther(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetOther_1() + throws Exception { + StdStatus fixture = new StdStatus(); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setPolicyName(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setResposneAttributes(new Hashtable()); + fixture.setMatchingConditions(new Hashtable()); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setJsonObject((JsonObject) null); + fixture.setDocument((Document) null); + fixture.setProperties(new Properties()); + fixture.setRequestAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setActionAdvised(new Hashtable()); + fixture.setOther(""); + fixture.setDecision(PolicyDecision.DENY); + fixture.setDetails(""); + fixture.setActionTaken(new Hashtable()); + String other = ""; + + fixture.setOther(other); + + // add additional test code here + } + + /** + * Run the void setPolicyConfigStatus(PolicyConfigStatus) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetPolicyConfigStatus_1() + throws Exception { + StdStatus fixture = new StdStatus(); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setPolicyName(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setResposneAttributes(new Hashtable()); + fixture.setMatchingConditions(new Hashtable()); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setJsonObject((JsonObject) null); + fixture.setDocument((Document) null); + fixture.setProperties(new Properties()); + fixture.setRequestAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setActionAdvised(new Hashtable()); + fixture.setOther(""); + fixture.setDecision(PolicyDecision.DENY); + fixture.setDetails(""); + fixture.setActionTaken(new Hashtable()); + PolicyConfigStatus policyConfigStatus = PolicyConfigStatus.CONFIG_NOT_FOUND; + + fixture.setPolicyConfigStatus(policyConfigStatus); + + // add additional test code here + } + + /** + * Run the void setPolicyConfigStatus(String,PolicyConfigStatus) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetPolicyConfigStatus_2() + throws Exception { + StdStatus fixture = new StdStatus(); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setPolicyName(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setResposneAttributes(new Hashtable()); + fixture.setMatchingConditions(new Hashtable()); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setJsonObject((JsonObject) null); + fixture.setDocument((Document) null); + fixture.setProperties(new Properties()); + fixture.setRequestAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setActionAdvised(new Hashtable()); + fixture.setOther(""); + fixture.setDecision(PolicyDecision.DENY); + fixture.setDetails(""); + fixture.setActionTaken(new Hashtable()); + String configStatus = ""; + PolicyConfigStatus policyConfigStatus = PolicyConfigStatus.CONFIG_NOT_FOUND; + + fixture.setPolicyConfigStatus(configStatus, policyConfigStatus); + + // add additional test code here + } + + /** + * Run the void setPolicyDecision(PolicyDecision) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetPolicyDecision_1() + throws Exception { + StdStatus fixture = new StdStatus(); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setPolicyName(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setResposneAttributes(new Hashtable()); + fixture.setMatchingConditions(new Hashtable()); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setJsonObject((JsonObject) null); + fixture.setDocument((Document) null); + fixture.setProperties(new Properties()); + fixture.setRequestAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setActionAdvised(new Hashtable()); + fixture.setOther(""); + fixture.setDecision(PolicyDecision.DENY); + fixture.setDetails(""); + fixture.setActionTaken(new Hashtable()); + PolicyDecision policyDecision = PolicyDecision.DENY; + + fixture.setDecision(policyDecision); + + // add additional test code here + } + + /** + * Run the void setPolicyName(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetPolicyName_1() + throws Exception { + StdStatus fixture = new StdStatus(); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setPolicyName(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setResposneAttributes(new Hashtable()); + fixture.setMatchingConditions(new Hashtable()); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setJsonObject((JsonObject) null); + fixture.setDocument((Document) null); + fixture.setProperties(new Properties()); + fixture.setRequestAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setActionAdvised(new Hashtable()); + fixture.setOther(""); + fixture.setDecision(PolicyDecision.DENY); + fixture.setDetails(""); + fixture.setActionTaken(new Hashtable()); + String policyName = ""; + + fixture.setPolicyName(policyName); + + // add additional test code here + } + + /** + * Run the void setPolicyResponseMessage(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetPolicyResponseMessage_1() + throws Exception { + StdStatus fixture = new StdStatus(); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setPolicyName(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setResposneAttributes(new Hashtable()); + fixture.setMatchingConditions(new Hashtable()); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setJsonObject((JsonObject) null); + fixture.setDocument((Document) null); + fixture.setProperties(new Properties()); + fixture.setRequestAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setActionAdvised(new Hashtable()); + fixture.setOther(""); + fixture.setDecision(PolicyDecision.DENY); + fixture.setDetails(""); + fixture.setActionTaken(new Hashtable()); + String policyResponseMessage = ""; + + fixture.setPolicyResponseMessage(policyResponseMessage); + + // add additional test code here + } + + /** + * Run the void setPolicyResponseStatus(PolicyResponseStatus) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetPolicyResponseStatus_1() + throws Exception { + StdStatus fixture = new StdStatus(); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setPolicyName(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setResposneAttributes(new Hashtable()); + fixture.setMatchingConditions(new Hashtable()); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setJsonObject((JsonObject) null); + fixture.setDocument((Document) null); + fixture.setProperties(new Properties()); + fixture.setRequestAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setActionAdvised(new Hashtable()); + fixture.setOther(""); + fixture.setDecision(PolicyDecision.DENY); + fixture.setDetails(""); + fixture.setActionTaken(new Hashtable()); + PolicyResponseStatus policyResponseStatus = PolicyResponseStatus.ACTION_ADVISED; + + fixture.setPolicyResponseStatus(policyResponseStatus); + + // add additional test code here + } + + /** + * Run the void setPolicyResponseStatus(String,PolicyResponseStatus) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetPolicyResponseStatus_2() + throws Exception { + StdStatus fixture = new StdStatus(); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setPolicyName(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setResposneAttributes(new Hashtable()); + fixture.setMatchingConditions(new Hashtable()); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setJsonObject((JsonObject) null); + fixture.setDocument((Document) null); + fixture.setProperties(new Properties()); + fixture.setRequestAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setActionAdvised(new Hashtable()); + fixture.setOther(""); + fixture.setDecision(PolicyDecision.DENY); + fixture.setDetails(""); + fixture.setActionTaken(new Hashtable()); + String policyResponseMessage = ""; + PolicyResponseStatus policyResponseStatus = PolicyResponseStatus.ACTION_ADVISED; + + fixture.setPolicyResponseStatus(policyResponseMessage, policyResponseStatus); + + // add additional test code here + } + + /** + * Run the void setPolicyType(PolicyType) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetPolicyType_1() + throws Exception { + StdStatus fixture = new StdStatus(); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setPolicyName(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setResposneAttributes(new Hashtable()); + fixture.setMatchingConditions(new Hashtable()); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setJsonObject((JsonObject) null); + fixture.setDocument((Document) null); + fixture.setProperties(new Properties()); + fixture.setRequestAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setActionAdvised(new Hashtable()); + fixture.setOther(""); + fixture.setDecision(PolicyDecision.DENY); + fixture.setDetails(""); + fixture.setActionTaken(new Hashtable()); + PolicyType policyType = PolicyType.JSON; + + fixture.setPolicyType(policyType); + + // add additional test code here + } + + /** + * Run the void setPolicyVersion(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetPolicyVersion_1() + throws Exception { + StdStatus fixture = new StdStatus(); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setPolicyName(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setResposneAttributes(new Hashtable()); + fixture.setMatchingConditions(new Hashtable()); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setJsonObject((JsonObject) null); + fixture.setDocument((Document) null); + fixture.setProperties(new Properties()); + fixture.setRequestAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setActionAdvised(new Hashtable()); + fixture.setOther(""); + fixture.setDecision(PolicyDecision.DENY); + fixture.setDetails(""); + fixture.setActionTaken(new Hashtable()); + String policyVersion = ""; + + fixture.setPolicyVersion(policyVersion); + + // add additional test code here + } + + /** + * Run the void setProperties(Properties) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetProperties_1() + throws Exception { + StdStatus fixture = new StdStatus(); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setPolicyName(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setResposneAttributes(new Hashtable()); + fixture.setMatchingConditions(new Hashtable()); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setJsonObject((JsonObject) null); + fixture.setDocument((Document) null); + fixture.setProperties(new Properties()); + fixture.setRequestAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setActionAdvised(new Hashtable()); + fixture.setOther(""); + fixture.setDecision(PolicyDecision.DENY); + fixture.setDetails(""); + fixture.setActionTaken(new Hashtable()); + Properties properties = new Properties(); + + fixture.setProperties(properties); + + // add additional test code here + } + + /** + * Run the void setRequestAttributes(Map) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetRequestAttributes_1() + throws Exception { + StdStatus fixture = new StdStatus(); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setPolicyName(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setResposneAttributes(new Hashtable()); + fixture.setMatchingConditions(new Hashtable()); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setJsonObject((JsonObject) null); + fixture.setDocument((Document) null); + fixture.setProperties(new Properties()); + fixture.setRequestAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setActionAdvised(new Hashtable()); + fixture.setOther(""); + fixture.setDecision(PolicyDecision.DENY); + fixture.setDetails(""); + fixture.setActionTaken(new Hashtable()); + Map requestAttributes = new Hashtable(); + + fixture.setRequestAttributes(requestAttributes); + + // add additional test code here + } + + /** + * Run the void setResposneAttributes(Map) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetResposneAttributes_1() + throws Exception { + StdStatus fixture = new StdStatus(); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setPolicyName(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setResposneAttributes(new Hashtable()); + fixture.setMatchingConditions(new Hashtable()); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setJsonObject((JsonObject) null); + fixture.setDocument((Document) null); + fixture.setProperties(new Properties()); + fixture.setRequestAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setActionAdvised(new Hashtable()); + fixture.setOther(""); + fixture.setDecision(PolicyDecision.DENY); + fixture.setDetails(""); + fixture.setActionTaken(new Hashtable()); + Map responseAttributes = new Hashtable(); + + fixture.setResposneAttributes(responseAttributes); + + // add additional test code here + } + + /** + * Run the void setStatus(String,PolicyResponseStatus,PolicyConfigStatus) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetStatus_1() + throws Exception { + StdStatus fixture = new StdStatus(); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setPolicyName(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setResposneAttributes(new Hashtable()); + fixture.setMatchingConditions(new Hashtable()); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setJsonObject((JsonObject) null); + fixture.setDocument((Document) null); + fixture.setProperties(new Properties()); + fixture.setRequestAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setActionAdvised(new Hashtable()); + fixture.setOther(""); + fixture.setDecision(PolicyDecision.DENY); + fixture.setDetails(""); + fixture.setActionTaken(new Hashtable()); + String message = ""; + PolicyResponseStatus policyResponseStatus = PolicyResponseStatus.ACTION_ADVISED; + PolicyConfigStatus policyConfigStatus = PolicyConfigStatus.CONFIG_NOT_FOUND; + + fixture.setStatus(message, policyResponseStatus, policyConfigStatus); + + // add additional test code here + } + + /** + * Run the JsonObject toJSON() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testToJSON_1() + throws Exception { + StdStatus fixture = new StdStatus(); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setPolicyName(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setResposneAttributes(new Hashtable()); + fixture.setMatchingConditions(new Hashtable()); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setJsonObject((JsonObject) null); + fixture.setDocument((Document) null); + fixture.setProperties(new Properties()); + fixture.setRequestAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setActionAdvised(new Hashtable()); + fixture.setOther(""); + fixture.setDecision(PolicyDecision.DENY); + fixture.setDetails(""); + fixture.setActionTaken(new Hashtable()); + + JsonObject result = fixture.toJSON(); + + // add additional test code here + assertEquals(null, result); + } + + /** + * Run the String toOther() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testToOther_1() + throws Exception { + StdStatus fixture = new StdStatus(); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setPolicyName(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setResposneAttributes(new Hashtable()); + fixture.setMatchingConditions(new Hashtable()); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setJsonObject((JsonObject) null); + fixture.setDocument((Document) null); + fixture.setProperties(new Properties()); + fixture.setRequestAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setActionAdvised(new Hashtable()); + fixture.setOther(""); + fixture.setDecision(PolicyDecision.DENY); + fixture.setDetails(""); + fixture.setActionTaken(new Hashtable()); + + String result = fixture.toOther(); + + // add additional test code here + assertEquals("", result); + } + + /** + * Run the Properties toProperties() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testToProperties_1() + throws Exception { + StdStatus fixture = new StdStatus(); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setPolicyName(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setResposneAttributes(new Hashtable()); + fixture.setMatchingConditions(new Hashtable()); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setJsonObject((JsonObject) null); + fixture.setDocument((Document) null); + fixture.setProperties(new Properties()); + fixture.setRequestAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setActionAdvised(new Hashtable()); + fixture.setOther(""); + fixture.setDecision(PolicyDecision.DENY); + fixture.setDetails(""); + fixture.setActionTaken(new Hashtable()); + + Properties result = fixture.toProperties(); + + // add additional test code here + assertNotNull(result); + assertEquals(0, result.size()); + } + + /** + * Run the Document toXML() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testToXML_1() + throws Exception { + StdStatus fixture = new StdStatus(); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setPolicyName(""); + fixture.setPolicyType(PolicyType.JSON); + fixture.setResposneAttributes(new Hashtable()); + fixture.setMatchingConditions(new Hashtable()); + fixture.setStatus("", PolicyResponseStatus.ACTION_ADVISED, PolicyConfigStatus.CONFIG_NOT_FOUND); + fixture.setJsonObject((JsonObject) null); + fixture.setDocument((Document) null); + fixture.setProperties(new Properties()); + fixture.setRequestAttributes(new Hashtable()); + fixture.setPolicyVersion(""); + fixture.setActionAdvised(new Hashtable()); + fixture.setOther(""); + fixture.setDecision(PolicyDecision.DENY); + fixture.setDetails(""); + fixture.setActionTaken(new Hashtable()); + + Document result = fixture.toXML(); + + // add additional test code here + assertEquals(null, result); + } + + /** + * Perform pre-test initialization. + * + * @throws Exception + * if the initialization fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Before + public void setUp() + throws Exception { + // add additional set up code here + } + + /** + * Perform post-test clean-up. + * + * @throws Exception + * if the clean-up fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @After + public void tearDown() + throws Exception { + // Add additional tear down code here + } + + /** + * Launch the test. + * + * @param args the command line arguments + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(StdStatusTest.class); + } +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/package-info.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/package-info.java new file mode 100644 index 000000000..75bfc39ad --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/std/test/package-info.java @@ -0,0 +1,27 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + * + */ +/** + * + */ +package org.openecomp.policy.std.test; diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/ActionPolicyApiTest.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/ActionPolicyApiTest.java new file mode 100644 index 000000000..d830a1a29 --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/ActionPolicyApiTest.java @@ -0,0 +1,240 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.test; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.openecomp.policy.api.AttributeType; +import org.openecomp.policy.api.PolicyChangeResponse; +import org.openecomp.policy.api.PolicyClass; +import org.openecomp.policy.api.PolicyEngine; +import org.openecomp.policy.api.PolicyEngineException; +import org.openecomp.policy.api.PolicyParameters; +import org.openecomp.policy.std.StdPolicyChangeResponse; + +import junit.framework.TestCase; +import org.openecomp.policy.common.logging.flexlogger.*; + +public class ActionPolicyApiTest extends TestCase { + + private static final Logger logger = FlexLogger.getLogger(ActionPolicyApiTest.class); + + private PolicyEngine policyEngine = null; + private PolicyEngine mockPolicyEngine = null; + + PolicyChangeResponse result = null; + StdPolicyChangeResponse response = new StdPolicyChangeResponse(); + PolicyParameters policyParameters = new PolicyParameters(); + + @Before + protected void setUp() throws Exception { + try { + policyEngine = new PolicyEngine("Test/config_pass.properties"); + } catch (PolicyEngineException e) { + logger.error(e.getMessage()); + fail("PolicyEngine Instantiation Error" + e); + } + logger.info("Loaded.. PolicyEngine"); + + mockPolicyEngine = Mockito.mock(PolicyEngine.class); + + policyParameters.setPolicyClass(PolicyClass.Action); //required + policyParameters.setPolicyName("test.junitTest"); //required + policyParameters.setPolicyDescription("testing"); //optional + //policyParameters.setPolicyScope("test"); //Directory will be created where the Policies are saved... this displays a a subscope on the GUI + + //Set the Component Attributes... These are Optional + Map configAttributes = new HashMap(); + configAttributes.put("test", "testing"); + + Map> attributes = new HashMap>(); + attributes.put(AttributeType.MATCHING, configAttributes); + policyParameters.setAttributes(attributes); + + policyParameters.setActionPerformer("PEP"); + policyParameters.setActionAttribute("testing"); + policyParameters.setRequestID(UUID.randomUUID()); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + @Test + public final void testCreatePolicy() { + response.setResponseMessage("success"); + PolicyChangeResponse result = null; + try { + + Mockito.when(mockPolicyEngine.createPolicy(policyParameters)).thenReturn(response); + result = mockPolicyEngine.createPolicy(policyParameters); + + } catch (Exception e) { + logger.warn(e.getMessage()); + } + assertEquals(result, response); + } + + @Test + public final void testUpdatePolicy() { + response.setResponseMessage("success"); + PolicyChangeResponse result = null; + try { + + Mockito.when(mockPolicyEngine.updatePolicy(policyParameters)).thenReturn(response); + result = mockPolicyEngine.updatePolicy(policyParameters); + + } catch (Exception e) { + logger.warn(e.getMessage()); + } + assertEquals(result, response); + + } + + @Test + public final void testCreatePolicyNullPolicyName() { + response.setResponseMessage("PE300 - Data Issue: No Policy Name given."); + policyParameters.setPolicyName(null); + try{ + result = policyEngine.createPolicy(policyParameters); + } catch (Exception e){ + logger.warn(e.getMessage()); + } + assertEquals(result.getResponseMessage(), response.getResponseMessage()); + } + + @Test + public final void testCreatePolicyNullPolicyScope() { + response.setResponseMessage("PE300 - Data Issue: No Policy Scope given."); + policyParameters.setPolicyName("test"); + try{ + result = policyEngine.createPolicy(policyParameters); + } catch (Exception e){ + logger.warn(e.getMessage()); + } + assertEquals(result.getResponseMessage(), response.getResponseMessage()); + } + + @Test + public final void testCreatePolicyNullActionAttributes() { + response.setResponseMessage("PE300 - Data Issue: No Action Attribute given."); + policyParameters.setActionAttribute(null); + try{ + result = policyEngine.createPolicy(policyParameters); + } catch (Exception e){ + logger.warn(e.getMessage()); + } + assertEquals(result.getResponseMessage(), response.getResponseMessage()); + } + + @Test + public final void testCreatePolicyNullActionPerformer() { + response.setResponseMessage("PE300 - Data Issue: No Action Performer given."); + policyParameters.setActionPerformer(null); + try{ + result = policyEngine.createPolicy(policyParameters); + } catch (Exception e){ + logger.warn(e.getMessage()); + } + assertEquals(result.getResponseMessage(), response.getResponseMessage()); + } + + @Test + public final void testCreatePolicyInvalidActionPerformer() { + response.setResponseMessage("PE300 - Data Issue: Invalid Action Performer given."); + policyParameters.setActionPerformer("testfail"); + try{ + result = policyEngine.createPolicy(policyParameters); + } catch (Exception e){ + logger.warn(e.getMessage()); + } + assertEquals(result.getResponseMessage(), response.getResponseMessage()); + } + + @Test + public final void testUpdatePolicyNullPolicyName() { + response.setResponseMessage("PE300 - Data Issue: No Policy Name given."); + policyParameters.setPolicyName(null); + try{ + result = policyEngine.updatePolicy(policyParameters); + } catch (Exception e){ + logger.warn(e.getMessage()); + } + assertEquals(result.getResponseMessage(), response.getResponseMessage()); + } + + @Test + public final void testUpdatePolicyNullPolicyScope() { + response.setResponseMessage("PE300 - Data Issue: No Policy Scope given."); + policyParameters.setPolicyName("test"); + try{ + result = policyEngine.updatePolicy(policyParameters); + } catch (Exception e){ + logger.warn(e.getMessage()); + } + assertEquals(result.getResponseMessage(), response.getResponseMessage()); + } + + @Test + public final void testUpdatePolicyNullActionAttributes() { + response.setResponseMessage("PE300 - Data Issue: No Action Attribute given."); + policyParameters.setActionAttribute(null); + try{ + result = policyEngine.updatePolicy(policyParameters); + } catch (Exception e){ + logger.warn(e.getMessage()); + } + assertEquals(result.getResponseMessage(), response.getResponseMessage()); + } + + @Test + public final void testUpdatePolicyNullActionPerformer() { + response.setResponseMessage("PE300 - Data Issue: No Action Performer given."); + policyParameters.setActionPerformer(null); + try{ + result = policyEngine.updatePolicy(policyParameters); + } catch (Exception e){ + logger.warn(e.getMessage()); + } + assertEquals(result.getResponseMessage(), response.getResponseMessage()); + } + + @Test + public final void testUpdatePolicyInvalidActionPerformer() { + response.setResponseMessage("PE300 - Data Issue: Invalid Action Performer given."); + policyParameters.setActionPerformer("testfail"); + try{ + result = policyEngine.updatePolicy(policyParameters); + } catch (Exception e){ + logger.warn(e.getMessage()); + } + assertEquals(result.getResponseMessage(), response.getResponseMessage()); + } + + +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/AttributeTypeTest.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/AttributeTypeTest.java new file mode 100644 index 000000000..df8713ab8 --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/AttributeTypeTest.java @@ -0,0 +1,81 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.test; + +import org.junit.*; +import org.openecomp.policy.api.AttributeType; + +import static org.junit.Assert.*; + +/** + * The class AttributeTypeTest contains tests for the class {@link AttributeType}. + * + * @generatedBy CodePro at 6/1/16 1:40 PM + * @version $Revision: 1.0 $ + */ +public class AttributeTypeTest { + /** + * Run the String toString() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testToString_1() + throws Exception { + AttributeType fixture = AttributeType.MATCHING; + + String result = fixture.toString(); + + // add additional test code here + assertEquals("matching", result); + } + + /** + * Perform pre-test initialization. + * + * @throws Exception + * if the initialization fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Before + public void setUp() + throws Exception { + // add additional set up code here + } + + /** + * Perform post-test clean-up. + * + * @throws Exception + * if the clean-up fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @After + public void tearDown() + throws Exception { + // Add additional tear down code here + } + +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/ConfigBasePolicyTest.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/ConfigBasePolicyTest.java new file mode 100644 index 000000000..c6c624af0 --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/ConfigBasePolicyTest.java @@ -0,0 +1,325 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.test; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import junit.framework.TestCase; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.Test; +import org.mockito.Mockito; +import org.openecomp.policy.api.AttributeType; +import org.openecomp.policy.api.PolicyChangeResponse; +import org.openecomp.policy.api.PolicyConfigType; +import org.openecomp.policy.api.PolicyEngine; +import org.openecomp.policy.api.PolicyEngineException; +import org.openecomp.policy.api.PolicyParameters; +import org.openecomp.policy.api.PolicyType; +import org.openecomp.policy.std.StdPolicyChangeResponse; + +import org.openecomp.policy.common.logging.flexlogger.*; + +/** + * The class ConfigBasePolicyTest contains tests for the class + * {@link PolicyEngine} + * + * @pattern JUnit Test Case + * * + */ +public class ConfigBasePolicyTest extends TestCase { + + private static final Logger logger = FlexLogger.getLogger(DecisionPolicyApiTest.class); + + private PolicyEngine policyEngine = null; + private PolicyEngine mockPolicyEngine = null; + + PolicyChangeResponse result = null; + StdPolicyChangeResponse response = new StdPolicyChangeResponse(); + PolicyParameters policyParameters = new PolicyParameters(); + + /** + * Perform pre-test initialization + * + * @throws Exception + * + * @see TestCase#setUp() + */ + protected void setUp() throws Exception { + try { + policyEngine = new PolicyEngine("Test/config_pass.properties"); + } catch (PolicyEngineException e) { + logger.error(e.getMessage()); + fail("PolicyEngine Instantiation Error" + e); + } + logger.info("Loaded.. PolicyEngine"); + + mockPolicyEngine = Mockito.mock(PolicyEngine.class); + + policyParameters.setPolicyConfigType(PolicyConfigType.Base); //required + policyParameters.setPolicyName("test.junitTest"); //required + policyParameters.setEcompName("test"); + policyParameters.setConfigName("testBase"); + policyParameters.setConfigBodyType(PolicyType.OTHER); + policyParameters.setConfigBody("testing"); + policyParameters.setPolicyDescription("testing"); //optional + //policyParameters.setPolicyScope("test"); //Directory will be created where the Policies are saved... this displays a a subscope on the GUI + + //Set the Component Attributes... These are Optional + Map configAttributes = new HashMap(); + configAttributes.put("test", "testing"); + + Map> attributes = new HashMap>(); + attributes.put(AttributeType.MATCHING, configAttributes); + policyParameters.setAttributes(attributes); + + policyParameters.setRequestID(UUID.randomUUID()); + } + + /** + * Perform post-test clean up + * + * @throws Exception + * + * @see TestCase#tearDown() + */ + protected void tearDown() throws Exception { + super.tearDown(); + // Add additional tear down code here + } + + /** + * Run the PolicyChangeResponse createPolicy(PolicyParameters) method test + */ + public void testCreatePolicy() { + response.setResponseMessage("success"); + PolicyChangeResponse result = null; + try { + + Mockito.when(mockPolicyEngine.createPolicy(policyParameters)).thenReturn(response); + result = mockPolicyEngine.createPolicy(policyParameters); + + } catch (Exception e) { + logger.warn(e.getMessage()); + } + assertEquals(result, response); + } + + /** + * Run the String createConfigPolicy() method test + */ + @Test + public void testCreateConfigPolicy() { + String response = "success"; + String result = null; + try { + + Mockito.when(mockPolicyEngine.createConfigPolicy("testPolicy","test","test","testConfig",null,"OTHER","test","test",null, null, null, null, null)).thenReturn(response); + result = mockPolicyEngine.createConfigPolicy("testPolicy","test","test","testConfig",null,"OTHER","test","test",null, null, null, null, null); + + } catch (Exception e) { + logger.warn(e.getMessage()); + } + assertEquals(result, response); + } + + /** + * Run the PolicyChangeResponse updatePolicy(PolicyParameters) method test + */ + public void testUpdatePolicy() { + response.setResponseMessage("success"); + PolicyChangeResponse result = null; + try { + + Mockito.when(mockPolicyEngine.updatePolicy(policyParameters)).thenReturn(response); + result = mockPolicyEngine.updatePolicy(policyParameters); + + } catch (Exception e) { + logger.warn(e.getMessage()); + } + assertEquals(result, response); + } + + /** + * Run the String updateConfigPolicy() method test + */ + @Test + public void testUpdateConfigPolicy() { + String response = "success"; + String result = null; + try { + + Mockito.when(mockPolicyEngine.updateConfigPolicy("testPolicy","test","test","testConfig",null,"OTHER","test","test",null, null, null, null, null)).thenReturn(response); + result = mockPolicyEngine.updateConfigPolicy("testPolicy","test","test","testConfig",null,"OTHER","test","test",null, null, null, null, null); + + } catch (Exception e) { + logger.warn(e.getMessage()); + } + assertEquals(result, response); + } + + @Test + public final void testCreatePolicyNullPolicyName() { + response.setResponseMessage("PE300 - Data Issue: No Policy Name given."); + policyParameters.setPolicyName(null); + try{ + result = policyEngine.createPolicy(policyParameters); + } catch (Exception e){ + logger.warn(e.getMessage()); + } + assertEquals(result.getResponseMessage(), response.getResponseMessage()); + } + + @Test + public final void testCreatePolicyNullPolicyScope() { + response.setResponseMessage("PE300 - Data Issue: No Policy Scope given."); + policyParameters.setPolicyName("test"); + try{ + result = policyEngine.createPolicy(policyParameters); + } catch (Exception e){ + logger.warn(e.getMessage()); + } + assertEquals(result.getResponseMessage(), response.getResponseMessage()); + } + + @Test + public final void testCreatePolicyNullEcompName() { + response.setResponseMessage("PE300 - Data Issue: No ECOMP Name given."); + policyParameters.setEcompName(null); + try{ + result = policyEngine.createPolicy(policyParameters); + } catch (Exception e){ + logger.warn(e.getMessage()); + } + assertEquals(result.getResponseMessage(), response.getResponseMessage()); + } + + @Test + public final void testCreatePolicyNullPolicyConfigName() { + response.setResponseMessage("PE300 - Data Issue: No Config Name given."); + policyParameters.setConfigName(null);; + try{ + result = policyEngine.createPolicy(policyParameters); + } catch (Exception e){ + logger.warn(e.getMessage()); + } + assertEquals(result.getResponseMessage(), response.getResponseMessage()); + } + + @Test + public final void testCreatePolicyNullPolicyConfigBodyType() { + response.setResponseMessage("PE300 - Data Issue: No Config Body Type given."); + policyParameters.setConfigBodyType(null); + try{ + result = policyEngine.createPolicy(policyParameters); + } catch (Exception e){ + logger.warn(e.getMessage()); + } + assertEquals(result.getResponseMessage(), response.getResponseMessage()); + } + + @Test + public final void testCreatePolicyNullPolicyConfigBody() { + response.setResponseMessage("PE300 - Data Issue: No Config Body given."); + policyParameters.setConfigBody(null); + try{ + result = policyEngine.createPolicy(policyParameters); + } catch (Exception e){ + logger.warn(e.getMessage()); + } + assertEquals(result.getResponseMessage(), response.getResponseMessage()); + } + + @Test + public final void testUpdatePolicyNullPolicyName() { + response.setResponseMessage("PE300 - Data Issue: No Policy Name given."); + policyParameters.setPolicyName(null); + try{ + result = policyEngine.updatePolicy(policyParameters); + } catch (Exception e){ + logger.warn(e.getMessage()); + } + assertEquals(result.getResponseMessage(), response.getResponseMessage()); + } + + @Test + public final void testUpdatePolicyNullPolicyScope() { + response.setResponseMessage("PE300 - Data Issue: No Policy Scope given."); + policyParameters.setPolicyName("test"); + try{ + result = policyEngine.updatePolicy(policyParameters); + } catch (Exception e){ + logger.warn(e.getMessage()); + } + assertEquals(result.getResponseMessage(), response.getResponseMessage()); + } + + @Test + public final void testUpdatePolicyNullEcompName() { + response.setResponseMessage("PE300 - Data Issue: No ECOMP Name given."); + policyParameters.setEcompName(null); + try{ + result = policyEngine.updatePolicy(policyParameters); + } catch (Exception e){ + logger.warn(e.getMessage()); + } + assertEquals(result.getResponseMessage(), response.getResponseMessage()); + } + + @Test + public final void testUpdatePolicyNullPolicyConfigName() { + response.setResponseMessage("PE300 - Data Issue: No Config Name given."); + policyParameters.setConfigName(null);; + try{ + result = policyEngine.createPolicy(policyParameters); + } catch (Exception e){ + logger.warn(e.getMessage()); + } + assertEquals(result.getResponseMessage(), response.getResponseMessage()); + } + + @Test + public final void testUpdatePolicyNullPolicyConfigBodyType() { + response.setResponseMessage("PE300 - Data Issue: No Config Body Type given."); + policyParameters.setConfigBodyType(null); + try{ + result = policyEngine.createPolicy(policyParameters); + } catch (Exception e){ + logger.warn(e.getMessage()); + } + assertEquals(result.getResponseMessage(), response.getResponseMessage()); + } + + @Test + public final void testUpdatePolicyNullPolicyConfigBody() { + response.setResponseMessage("PE300 - Data Issue: No Config Body given."); + policyParameters.setConfigBody(null); + try{ + result = policyEngine.createPolicy(policyParameters); + } catch (Exception e){ + logger.warn(e.getMessage()); + } + assertEquals(result.getResponseMessage(), response.getResponseMessage()); + } +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/ConfigFirewallPolicyTest.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/ConfigFirewallPolicyTest.java new file mode 100644 index 000000000..4725c17e9 --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/ConfigFirewallPolicyTest.java @@ -0,0 +1,256 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.test; + +import java.io.StringReader; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import javax.json.Json; +import javax.json.JsonObject; +import javax.json.JsonReader; + +import junit.framework.TestCase; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.Test; +import org.mockito.Mockito; +import org.openecomp.policy.api.PolicyChangeResponse; +import org.openecomp.policy.api.PolicyConfigType; +import org.openecomp.policy.api.PolicyEngine; +import org.openecomp.policy.api.PolicyEngineException; +import org.openecomp.policy.api.PolicyParameters; +import org.openecomp.policy.std.StdPolicyChangeResponse; + +import org.openecomp.policy.common.logging.flexlogger.*; + +public class ConfigFirewallPolicyTest extends TestCase { + + private static final Logger logger = FlexLogger.getLogger(DecisionPolicyApiTest.class); + + private PolicyEngine policyEngine = null; + private PolicyEngine mockPolicyEngine = null; + + PolicyChangeResponse result = null; + StdPolicyChangeResponse response = new StdPolicyChangeResponse(); + PolicyParameters policyParameters = new PolicyParameters(); + String json = null; + + /** + * Perform pre-test initialization + * + * @throws Exception + * + * @see TestCase#setUp() + */ + protected void setUp() throws Exception { + try { + policyEngine = new PolicyEngine("Test/config_pass.properties"); + } catch (PolicyEngineException e) { + logger.error(e.getMessage()); + fail("PolicyEngine Instantiation Error" + e); + } + logger.info("Loaded.. PolicyEngine"); + + mockPolicyEngine = Mockito.mock(PolicyEngine.class); + + policyParameters.setPolicyConfigType(PolicyConfigType.Firewall); //required + policyParameters.setPolicyName("test.junitTest"); //required + + json = "{\"serviceTypeId\":\"/v0/firewall/pan\",\"configName\":\"rule1607\",\"deploymentOption\":{\"deployNow\":false},\"securityZoneId\":\"/v0/firewall/pan\",\"serviceGroups\":[{\"name\":\"1607Group\",\"description\":null,\"members\":[{\"type\":\"REFERENCE\",\"name\":\"SList\"},{\"type\":\"REFERENCE\",\"name\":\"Syslog\"}]},{\"name\":\"Syslog\",\"description\":\"NA\",\"type\":\"SERVICE\",\"transportProtocol\":\"udp\",\"appProtocol\":null,\"ports\":\"514\"},{\"name\":\"SList\",\"description\":\"Service List\",\"type\":\"SERVICE\",\"transportProtocol\":\"tcp\",\"appProtocol\":null,\"ports\":\"8080\"}],\"addressGroups\":[{\"name\":\"1607Group\",\"description\":null,\"members\":[{\"type\":\"SUBNET\",\"value\":\"10.11.12.13/14\"},{\"type\":\"SUBNET\",\"value\":\"10.11.12.13/14\"}]},{\"name\":\"PL_CCE3\",\"description\":\"CCE Routers\",\"members\":[{\"type\":\"SUBNET\",\"value\":\"10.11.12.13/14\"}]}],\"firewallRuleList\":[{\"position\":\"1\",\"ruleName\":\"1607Rule\",\"fromZones\":[\"Trusted\"],\"toZones\":[\"Untrusted\"],\"negateSource\":false,\"negateDestination\":false,\"sourceList\":[{\"type\":\"REFERENCE\",\"value\":\"PL_CCE3\"},{\"type\":\"REFERENCE\",\"value\":\"1607Group\"}],\"destinationList\":[{\"type\":\"REFERENCE\",\"value\":\"1607Group\"}],\"sourceServices\":[],\"destServices\":[{\"type\":\"REFERENCE\",\"name\":\"1607Group\"}],\"action\":\"accept\",\"description\":\"Rule for 1607 templates\",\"enabled\":true,\"log\":true}]}"; + + policyParameters.setConfigBody(buildJSON(json).toString()); + + //policyParameters.setPolicyScope("test"); //Directory will be created where the Policies are saved... this displays a a subscope on the GUI + policyParameters.setRequestID(UUID.randomUUID()); + } + + private static JsonObject buildJSON(String jsonString) { + JsonObject json = null;; + if (jsonString != null) { + StringReader in = null; + + in = new StringReader(jsonString); + + JsonReader jsonReader = Json.createReader(in); + json = jsonReader.readObject(); + } + + return json; + } + /** + * Perform post-test clean up + * + * @throws Exception + * + * @see TestCase#tearDown() + */ + protected void tearDown() throws Exception { + super.tearDown(); + // Add additional tear down code here + } + + /** + * Run the PolicyChangeResponse createPolicy(PolicyParameters) method test + */ + public void testCreatePolicy() { + response.setResponseMessage("success"); + PolicyChangeResponse result = null; + try { + + Mockito.when(mockPolicyEngine.createPolicy(policyParameters)).thenReturn(response); + result = mockPolicyEngine.createPolicy(policyParameters); + + } catch (Exception e) { + logger.warn(e.getMessage()); + } + assertEquals(result, response); + } + + /** + * Run the String createConfigFirewallPolicy() method test + */ + @Test + public void testCreateConfigFirewallPolicy() { + String response = "success"; + String result = null; + JsonObject jsonObj = buildJSON(json); + try { + + Mockito.when(mockPolicyEngine.createConfigFirewallPolicy("testPolicy",jsonObj, "test", null, null, null, null, null)).thenReturn(response); + result = mockPolicyEngine.createConfigFirewallPolicy("testPolicy",jsonObj, "test", null, null, null, null, null); + + } catch (Exception e) { + logger.warn(e.getMessage()); + } + assertEquals(result, response); + } + + /** + * Run the PolicyChangeResponse updatePolicy(PolicyParameters) method test + */ + public void testUpdatePolicy() { + response.setResponseMessage("success"); + PolicyChangeResponse result = null; + try { + + Mockito.when(mockPolicyEngine.updatePolicy(policyParameters)).thenReturn(response); + result = mockPolicyEngine.updatePolicy(policyParameters); + + } catch (Exception e) { + logger.warn(e.getMessage()); + } + assertEquals(result, response); + } + + /** + * Run the String updateConfigFirewallPolicy() method test + */ + @Test + public void testUpdateConfigFirewallPolicy() { + String response = "success"; + String result = null; + JsonObject jsonObj = buildJSON(json); + try { + + Mockito.when(mockPolicyEngine.updateConfigFirewallPolicy("testPolicy",jsonObj, "test", null, null, null, null, null)).thenReturn(response); + result = mockPolicyEngine.updateConfigFirewallPolicy("testPolicy",jsonObj, "test", null, null, null, null, null); + + } catch (Exception e) { + logger.warn(e.getMessage()); + } + assertEquals(result, response); + } + + @Test + public final void testCreatePolicyNullPolicyName() { + response.setResponseMessage("PE300 - Data Issue: No Policy Name given."); + policyParameters.setPolicyName(null); + try{ + result = policyEngine.createPolicy(policyParameters); + } catch (Exception e){ + logger.warn(e.getMessage()); + } + assertEquals(result.getResponseMessage(), response.getResponseMessage()); + } + + @Test + public final void testCreatePolicyNullPolicyScope() { + response.setResponseMessage("PE300 - Data Issue: No Policy Scope given."); + policyParameters.setPolicyName("test"); + try{ + result = policyEngine.createPolicy(policyParameters); + } catch (Exception e){ + logger.warn(e.getMessage()); + } + assertEquals(result.getResponseMessage(), response.getResponseMessage()); + } + + @Test + public final void testCreatePolicyNullPolicyConfigBody() { + response.setResponseMessage("PE300 - Data Issue: No Config Body given."); + policyParameters.setConfigBody(null); + try{ + result = policyEngine.createPolicy(policyParameters); + } catch (Exception e){ + logger.warn(e.getMessage()); + } + assertEquals(result.getResponseMessage(), response.getResponseMessage()); + } + + @Test + public final void testUpdatePolicyNullPolicyName() { + response.setResponseMessage("PE300 - Data Issue: No Policy Name given."); + policyParameters.setPolicyName(null); + try{ + result = policyEngine.updatePolicy(policyParameters); + } catch (Exception e){ + logger.warn(e.getMessage()); + } + assertEquals(result.getResponseMessage(), response.getResponseMessage()); + } + + @Test + public final void testUpdatePolicyNullPolicyScope() { + response.setResponseMessage("PE300 - Data Issue: No Policy Scope given."); + policyParameters.setPolicyName("test"); + try{ + result = policyEngine.updatePolicy(policyParameters); + } catch (Exception e){ + logger.warn(e.getMessage()); + } + assertEquals(result.getResponseMessage(), response.getResponseMessage()); + } + + @Test + public final void testUpdatePolicyNullPolicyConfigBody() { + response.setResponseMessage("PE300 - Data Issue: No Config Body given."); + policyParameters.setConfigBody(null); + try{ + result = policyEngine.createPolicy(policyParameters); + } catch (Exception e){ + logger.warn(e.getMessage()); + } + assertEquals(result.getResponseMessage(), response.getResponseMessage()); + } +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/ConfigRequestParametersTest.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/ConfigRequestParametersTest.java new file mode 100644 index 000000000..c632a0035 --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/ConfigRequestParametersTest.java @@ -0,0 +1,362 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.test; + +import java.util.Hashtable; +import java.util.Map; +import java.util.UUID; + +import org.junit.*; +import org.openecomp.policy.api.ConfigRequestParameters; + +import static org.junit.Assert.*; + +/** + * The class ConfigRequestParametersTest contains tests for the class {@link ConfigRequestParameters}. + * + * @generatedBy CodePro at 6/1/16 1:40 PM + * @version $Revision: 1.0 $ + */ +public class ConfigRequestParametersTest { + /** + * Run the ConfigRequestParameters() constructor test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testConfigRequestParameters_1() + throws Exception { + + ConfigRequestParameters result = new ConfigRequestParameters(); + + // add additional test code here + assertNotNull(result); + assertEquals(null, result.getPolicyName()); + assertEquals(null, result.getConfigName()); + assertEquals(null, result.getConfigAttributes()); + assertEquals(null, result.getRequestID()); + assertEquals(null, result.getEcompName()); + assertEquals(Boolean.FALSE, result.getUnique()); + } + + /** + * Run the ConfigRequestParameters(String,String,String,Map,Boolean,UUID) constructor test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testConfigRequestParameters_2() + throws Exception { + String policyName = ""; + String eCOMPComponentName = ""; + String configName = ""; + Map configAttributes = new Hashtable(); + Boolean unique = new Boolean(true); + UUID requestID = UUID.randomUUID(); + + ConfigRequestParameters result = createConfigRequest(policyName, eCOMPComponentName, configName, configAttributes, unique, requestID); + + // add additional test code here + assertNotNull(result); + assertEquals("", result.getPolicyName()); + assertEquals("", result.getConfigName()); + assertEquals("", result.getEcompName()); + assertEquals(Boolean.TRUE, result.getUnique()); + } + + /** + * Run the Map getConfigAttributes() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetConfigAttributes_1() + throws Exception { + ConfigRequestParameters fixture = createConfigRequest("", "", "", new Hashtable(), new Boolean(true), UUID.randomUUID()); + + Map result = fixture.getConfigAttributes(); + + // add additional test code here + assertNotNull(result); + assertEquals(0, result.size()); + } + + /** + * Run the String getConfigName() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetConfigName_1() + throws Exception { + ConfigRequestParameters fixture = createConfigRequest("", "", "", new Hashtable(), new Boolean(true), UUID.randomUUID()); + + String result = fixture.getConfigName(); + + // add additional test code here + assertEquals("", result); + } + + /** + * Run the String getEcompName() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetEcompName_1() + throws Exception { + ConfigRequestParameters fixture = createConfigRequest("", "", "", new Hashtable(), new Boolean(true), UUID.randomUUID()); + + String result = fixture.getEcompName(); + + // add additional test code here + assertEquals("", result); + } + + /** + * Run the String getPolicyName() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetPolicyName_1() + throws Exception { + ConfigRequestParameters fixture = createConfigRequest("", "", "", new Hashtable(), new Boolean(true), UUID.randomUUID()); + + String result = fixture.getPolicyName(); + + // add additional test code here + assertEquals("", result); + } + + /** + * Run the UUID getRequestID() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetRequestID_1() + throws Exception { + ConfigRequestParameters fixture = createConfigRequest("", "", "", new Hashtable(), new Boolean(true), UUID.fromString("6b5aa070-90bc-46a6-9a59-e1fe526df7ae")); + + UUID result = fixture.getRequestID(); + + // add additional test code here + assertNotNull(result); + assertEquals("6b5aa070-90bc-46a6-9a59-e1fe526df7ae", result.toString()); + assertEquals(4, result.version()); + assertEquals(2, result.variant()); + assertEquals(-7324574836520519762L, result.getLeastSignificantBits()); + assertEquals(7735671715287287462L, result.getMostSignificantBits()); + } + + /** + * Run the Boolean getUnique() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetUnique_1() + throws Exception { + ConfigRequestParameters fixture = createConfigRequest("", "", "", new Hashtable(), new Boolean(true), UUID.randomUUID()); + + Boolean result = fixture.getUnique(); + + // add additional test code here + assertNotNull(result); + assertEquals("true", result.toString()); + assertEquals(true, result.booleanValue()); + } + + /** + * Run the void makeUnique(Boolean) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testMakeUnique_1() + throws Exception { + ConfigRequestParameters fixture = createConfigRequest("", "", "", new Hashtable(), new Boolean(true), UUID.randomUUID()); + Boolean unique = new Boolean(true); + + fixture.makeUnique(unique); + + // add additional test code here + } + + /** + * Run the void setConfigAttributes(Map) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetConfigAttributes_1() + throws Exception { + ConfigRequestParameters fixture = createConfigRequest("", "", "", new Hashtable(), new Boolean(true), UUID.randomUUID()); + Map configAttributes = new Hashtable(); + + fixture.setConfigAttributes(configAttributes); + + // add additional test code here + } + + /** + * Run the void setConfigName(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetConfigName_1() + throws Exception { + ConfigRequestParameters fixture = createConfigRequest("", "", "", new Hashtable(), new Boolean(true), UUID.randomUUID()); + String configName = ""; + + fixture.setConfigName(configName); + + // add additional test code here + } + + /** + * Run the void setEcompName(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetEcompName_1() + throws Exception { + ConfigRequestParameters fixture = createConfigRequest("", "", "", new Hashtable(), new Boolean(true), UUID.randomUUID()); + String eCOMPComponentName = ""; + + fixture.setEcompName(eCOMPComponentName); + + // add additional test code here + } + + /** + * Run the void setPolicyName(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetPolicyName_1() + throws Exception { + ConfigRequestParameters fixture = createConfigRequest("", "", "", new Hashtable(), new Boolean(true), UUID.randomUUID()); + String policyName = ""; + + fixture.setPolicyName(policyName); + + // add additional test code here + } + + /** + * Run the void setRequestID(UUID) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetRequestID_1() + throws Exception { + ConfigRequestParameters fixture = createConfigRequest("", "", "", new Hashtable(), new Boolean(true), UUID.randomUUID()); + UUID requestID = UUID.randomUUID(); + + fixture.setRequestID(requestID); + + // add additional test code here + } + + /** + * Perform pre-test initialization. + * + * @throws Exception + * if the initialization fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Before + public void setUp() + throws Exception { + // add additional set up code here + } + + /** + * Perform post-test clean-up. + * + * @throws Exception + * if the clean-up fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @After + public void tearDown() + throws Exception { + // Add additional tear down code here + } + + /** + * Launch the test. + * + * @param args the command line arguments + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(ConfigRequestParametersTest.class); + } + + private ConfigRequestParameters createConfigRequest(String policyName, String eCOMPComponentName, String configName, Map configAttributes, Boolean unique, UUID requestID){ + ConfigRequestParameters configRequestParameters = new ConfigRequestParameters(); + configRequestParameters.setRequestID(requestID); + configRequestParameters.setPolicyName(policyName); + configRequestParameters.setEcompName(eCOMPComponentName); + configRequestParameters.setConfigName(configName); + configRequestParameters.setConfigAttributes(configAttributes); + configRequestParameters.makeUnique(unique); + return configRequestParameters; + } +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/DecisionPolicyApiTest.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/DecisionPolicyApiTest.java new file mode 100644 index 000000000..70adbe032 --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/DecisionPolicyApiTest.java @@ -0,0 +1,221 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.test; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.Test; +import org.mockito.Mockito; +import org.openecomp.policy.api.AttributeType; +import org.openecomp.policy.api.PolicyChangeResponse; +import org.openecomp.policy.api.PolicyClass; +import org.openecomp.policy.api.PolicyEngine; +import org.openecomp.policy.api.PolicyEngineException; +import org.openecomp.policy.api.PolicyParameters; +import org.openecomp.policy.std.StdPolicyChangeResponse; + +import org.openecomp.policy.common.logging.flexlogger.*; + +import junit.framework.TestCase; + +/** + * The class DecisionPolicyApiTest contains tests for the class + * {@link PolicyEngine} + * + * @pattern JUnit Test Case + * * + */ +public class DecisionPolicyApiTest extends TestCase { + + private static final Logger logger = FlexLogger.getLogger(DecisionPolicyApiTest.class); + + private PolicyEngine policyEngine = null; + private PolicyEngine mockPolicyEngine = null; + + PolicyChangeResponse result = null; + StdPolicyChangeResponse response = new StdPolicyChangeResponse(); + PolicyParameters policyParameters = new PolicyParameters(); + + /** + * Perform pre-test initialization + * + * @throws Exception + * + * @see TestCase#setUp() + */ + protected void setUp() throws Exception { + try { + policyEngine = new PolicyEngine("Test/config_pass.properties"); + } catch (PolicyEngineException e) { + logger.error(e.getMessage()); + fail("PolicyEngine Instantiation Error" + e); + } + logger.info("Loaded.. PolicyEngine"); + + mockPolicyEngine = Mockito.mock(PolicyEngine.class); + + policyParameters.setPolicyClass(PolicyClass.Decision); //required + policyParameters.setPolicyName("test.junitTest"); //required + policyParameters.setEcompName("test"); + policyParameters.setPolicyDescription("testing"); //optional + //policyParameters.setPolicyScope("test"); //Directory will be created where the Policies are saved... this displays a a subscope on the GUI + + //Set the Component Attributes... These are Optional + Map configAttributes = new HashMap(); + configAttributes.put("test", "testing"); + + Map> attributes = new HashMap>(); + attributes.put(AttributeType.MATCHING, configAttributes); + policyParameters.setAttributes(attributes); + + //Set the settings... These are Optional +/* Map settingsMap = new HashMap(); + settingsMap.put("server", "5"); + + Map> settings = new HashMap>(); + settings.put(AttributeType.SETTINGS, settingsMap); + policyParameters.setSettings(settings);*/ + + policyParameters.setRequestID(UUID.randomUUID()); + } + + /** + * Perform post-test clean up + * + * @throws Exception + * + * @see TestCase#tearDown() + */ + protected void tearDown() throws Exception { + super.tearDown(); + // Add additional tear down code here + } + + /** + * Run the PolicyChangeResponse createPolicy(PolicyParameters) method test + */ + public void testCreatePolicy() { + response.setResponseMessage("success"); + PolicyChangeResponse result = null; + try { + + Mockito.when(mockPolicyEngine.createPolicy(policyParameters)).thenReturn(response); + result = mockPolicyEngine.createPolicy(policyParameters); + + } catch (Exception e) { + logger.warn(e.getMessage()); + } + assertEquals(result, response); + } + + /** + * Run the PolicyChangeResponse updatePolicy(PolicyParameters) method test + */ + public void testUpdatePolicy() { + response.setResponseMessage("success"); + PolicyChangeResponse result = null; + try { + + Mockito.when(mockPolicyEngine.updatePolicy(policyParameters)).thenReturn(response); + result = mockPolicyEngine.updatePolicy(policyParameters); + + } catch (Exception e) { + logger.warn(e.getMessage()); + } + assertEquals(result, response); + } + + @Test + public final void testCreatePolicyNullPolicyName() { + response.setResponseMessage("PE300 - Data Issue: No Policy Name given."); + policyParameters.setPolicyName(null); + try{ + result = policyEngine.createPolicy(policyParameters); + } catch (Exception e){ + logger.warn(e.getMessage()); + } + assertEquals(result.getResponseMessage(), response.getResponseMessage()); + } + + @Test + public final void testCreatePolicyNullPolicyScope() { + response.setResponseMessage("PE300 - Data Issue: No Policy Scope given."); + policyParameters.setPolicyName("test"); + try{ + result = policyEngine.createPolicy(policyParameters); + } catch (Exception e){ + logger.warn(e.getMessage()); + } + assertEquals(result.getResponseMessage(), response.getResponseMessage()); + } + + @Test + public final void testCreatePolicyNullEcompName() { + response.setResponseMessage("PE300 - Data Issue: No ECOMP Name given."); + policyParameters.setEcompName(null); + try{ + result = policyEngine.createPolicy(policyParameters); + } catch (Exception e){ + logger.warn(e.getMessage()); + } + assertEquals(result.getResponseMessage(), response.getResponseMessage()); + } + + @Test + public final void testUpdatePolicyNullPolicyName() { + response.setResponseMessage("PE300 - Data Issue: No Policy Name given."); + policyParameters.setPolicyName(null); + try{ + result = policyEngine.updatePolicy(policyParameters); + } catch (Exception e){ + logger.warn(e.getMessage()); + } + assertEquals(result.getResponseMessage(), response.getResponseMessage()); + } + + @Test + public final void testUpdatePolicyNullPolicyScope() { + response.setResponseMessage("PE300 - Data Issue: No Policy Scope given."); + policyParameters.setPolicyName("test"); + try{ + result = policyEngine.updatePolicy(policyParameters); + } catch (Exception e){ + logger.warn(e.getMessage()); + } + assertEquals(result.getResponseMessage(), response.getResponseMessage()); + } + + @Test + public final void testUpdatePolicyNullEcompName() { + response.setResponseMessage("PE300 - Data Issue: No ECOMP Name given."); + policyParameters.setEcompName(null); + try{ + result = policyEngine.updatePolicy(policyParameters); + } catch (Exception e){ + logger.warn(e.getMessage()); + } + assertEquals(result.getResponseMessage(), response.getResponseMessage()); + } +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/DecisionRequestParametersTest.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/DecisionRequestParametersTest.java new file mode 100644 index 000000000..5b8782658 --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/DecisionRequestParametersTest.java @@ -0,0 +1,232 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.test; + +import java.util.Hashtable; +import java.util.Map; +import java.util.UUID; + +import org.junit.*; +import org.openecomp.policy.api.DecisionRequestParameters; + +import static org.junit.Assert.*; + +/** + * The class DecisionRequestParametersTest contains tests for the class {@link DecisionRequestParameters}. + * + * @generatedBy CodePro at 6/1/16 1:41 PM + * @version $Revision: 1.0 $ + */ +public class DecisionRequestParametersTest { + /** + * Run the DecisionRequestParameters() constructor test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testDecisionRequestParameters_1() + throws Exception { + + DecisionRequestParameters result = new DecisionRequestParameters(); + + // add additional test code here + assertNotNull(result); + assertEquals(null, result.getECOMPComponentName()); + assertEquals(null, result.getDecisionAttributes()); + assertEquals(null, result.getRequestID()); + } + + /** + * Run the DecisionRequestParameters(String,Map,UUID) constructor test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testDecisionRequestParameters_2() + throws Exception { + String eCOMPComponentName = ""; + Map decisionAttributes = new Hashtable(); + UUID requestID = UUID.randomUUID(); + + DecisionRequestParameters result = new DecisionRequestParameters(eCOMPComponentName, decisionAttributes, requestID); + + // add additional test code here + assertNotNull(result); + assertEquals("", result.getECOMPComponentName()); + } + + /** + * Run the Map getDecisionAttributes() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testGetDecisionAttributes_1() + throws Exception { + DecisionRequestParameters fixture = new DecisionRequestParameters("", new Hashtable(), UUID.randomUUID()); + + Map result = fixture.getDecisionAttributes(); + + // add additional test code here + assertNotNull(result); + assertEquals(0, result.size()); + } + + /** + * Run the String getECOMPComponentName() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testGetECOMPComponentName_1() + throws Exception { + DecisionRequestParameters fixture = new DecisionRequestParameters("", new Hashtable(), UUID.randomUUID()); + + String result = fixture.getECOMPComponentName(); + + // add additional test code here + assertEquals("", result); + } + + /** + * Run the UUID getRequestID() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testGetRequestID_1() + throws Exception { + DecisionRequestParameters fixture = new DecisionRequestParameters("", new Hashtable(), UUID.fromString("d1db6a6d-7140-4864-8200-6b541261fdd2")); + + UUID result = fixture.getRequestID(); + + // add additional test code here + assertNotNull(result); + assertEquals("d1db6a6d-7140-4864-8200-6b541261fdd2", result.toString()); + assertEquals(4, result.version()); + assertEquals(2, result.variant()); + assertEquals(-9079138839949083182L, result.getLeastSignificantBits()); + assertEquals(-3324946881598961564L, result.getMostSignificantBits()); + } + + /** + * Run the void setDecisionAttributes(Map) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testSetDecisionAttributes_1() + throws Exception { + DecisionRequestParameters fixture = new DecisionRequestParameters("", new Hashtable(), UUID.randomUUID()); + Map decisionAttributes = new Hashtable(); + + fixture.setDecisionAttributes(decisionAttributes); + + // add additional test code here + } + + /** + * Run the void setECOMPComponentName(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testSetECOMPComponentName_1() + throws Exception { + DecisionRequestParameters fixture = new DecisionRequestParameters("", new Hashtable(), UUID.randomUUID()); + String eCOMPComponentName = ""; + + fixture.setECOMPComponentName(eCOMPComponentName); + + // add additional test code here + } + + /** + * Run the void setRequestID(UUID) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testSetRequestID_1() + throws Exception { + DecisionRequestParameters fixture = new DecisionRequestParameters("", new Hashtable(), UUID.randomUUID()); + UUID requestID = UUID.randomUUID(); + + fixture.setRequestID(requestID); + + // add additional test code here + } + + /** + * Perform pre-test initialization. + * + * @throws Exception + * if the initialization fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Before + public void setUp() + throws Exception { + // add additional set up code here + } + + /** + * Perform post-test clean-up. + * + * @throws Exception + * if the clean-up fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @After + public void tearDown() + throws Exception { + // Add additional tear down code here + } + + /** + * Launch the test. + * + * @param args the command line arguments + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(DecisionRequestParametersTest.class); + } +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/DeletePolicyConditionTest.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/DeletePolicyConditionTest.java new file mode 100644 index 000000000..c2941202b --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/DeletePolicyConditionTest.java @@ -0,0 +1,91 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.test; + +import org.junit.*; +import org.openecomp.policy.api.DeletePolicyCondition; + +import static org.junit.Assert.*; + +/** + * The class DeletePolicyConditionTest contains tests for the class {@link DeletePolicyCondition}. + * + * @generatedBy CodePro at 6/1/16 1:41 PM + * @version $Revision: 1.0 $ + */ +public class DeletePolicyConditionTest { + /** + * Run the String toString() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testToString_1() + throws Exception { + DeletePolicyCondition fixture = DeletePolicyCondition.ALL; + + String result = fixture.toString(); + + // add additional test code here + assertEquals("All Versions", result); + } + + /** + * Perform pre-test initialization. + * + * @throws Exception + * if the initialization fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Before + public void setUp() + throws Exception { + // add additional set up code here + } + + /** + * Perform post-test clean-up. + * + * @throws Exception + * if the clean-up fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @After + public void tearDown() + throws Exception { + // Add additional tear down code here + } + + /** + * Launch the test. + * + * @param args the command line arguments + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(DeletePolicyConditionTest.class); + } +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/DeletePolicyParametersTest.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/DeletePolicyParametersTest.java new file mode 100644 index 000000000..7723f9819 --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/DeletePolicyParametersTest.java @@ -0,0 +1,314 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.test; + +import java.util.UUID; + +import org.junit.*; +import org.openecomp.policy.api.DeletePolicyCondition; +import org.openecomp.policy.api.DeletePolicyParameters; + +import static org.junit.Assert.*; + +/** + * The class DeletePolicyParametersTest contains tests for the class {@link DeletePolicyParameters}. + * + * @generatedBy CodePro at 6/1/16 1:40 PM + * @version $Revision: 1.0 $ + */ +public class DeletePolicyParametersTest { + /** + * Run the DeletePolicyCondition getDeleteCondition() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetDeleteCondition_1() + throws Exception { + DeletePolicyParameters fixture = new DeletePolicyParameters(); + fixture.setPolicyComponent(""); + fixture.setPolicyName(""); + fixture.setDeleteCondition(DeletePolicyCondition.ALL); + fixture.setRequestID(UUID.randomUUID()); + fixture.setPdpGroup(""); + + DeletePolicyCondition result = fixture.getDeleteCondition(); + + // add additional test code here + assertNotNull(result); + assertEquals("All Versions", result.toString()); + assertEquals("ALL", result.name()); + assertEquals(1, result.ordinal()); + } + + /** + * Run the String getPdpGroup() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetPdpGroup_1() + throws Exception { + DeletePolicyParameters fixture = new DeletePolicyParameters(); + fixture.setPolicyComponent(""); + fixture.setPolicyName(""); + fixture.setDeleteCondition(DeletePolicyCondition.ALL); + fixture.setRequestID(UUID.randomUUID()); + fixture.setPdpGroup(""); + + String result = fixture.getPdpGroup(); + + // add additional test code here + assertEquals("", result); + } + + /** + * Run the String getPolicyComponent() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetPolicyComponent_1() + throws Exception { + DeletePolicyParameters fixture = new DeletePolicyParameters(); + fixture.setPolicyComponent(""); + fixture.setPolicyName(""); + fixture.setDeleteCondition(DeletePolicyCondition.ALL); + fixture.setRequestID(UUID.randomUUID()); + fixture.setPdpGroup(""); + + String result = fixture.getPolicyComponent(); + + // add additional test code here + assertEquals("", result); + } + + /** + * Run the String getPolicyName() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetPolicyName_1() + throws Exception { + DeletePolicyParameters fixture = new DeletePolicyParameters(); + fixture.setPolicyComponent(""); + fixture.setPolicyName(""); + fixture.setDeleteCondition(DeletePolicyCondition.ALL); + fixture.setRequestID(UUID.randomUUID()); + fixture.setPdpGroup(""); + + String result = fixture.getPolicyName(); + + // add additional test code here + assertEquals("", result); + } + + /** + * Run the UUID getRequestID() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetRequestID_1() + throws Exception { + DeletePolicyParameters fixture = new DeletePolicyParameters(); + fixture.setPolicyComponent(""); + fixture.setPolicyName(""); + fixture.setDeleteCondition(DeletePolicyCondition.ALL); + fixture.setRequestID(UUID.fromString("482e90e2-2ad7-4265-9893-4cfe08ef1e3d")); + fixture.setPdpGroup(""); + + UUID result = fixture.getRequestID(); + + // add additional test code here + assertNotNull(result); + assertEquals("482e90e2-2ad7-4265-9893-4cfe08ef1e3d", result.toString()); + assertEquals(4, result.version()); + assertEquals(2, result.variant()); + assertEquals(-7452528304412746179L, result.getLeastSignificantBits()); + assertEquals(5201253920715260517L, result.getMostSignificantBits()); + } + + /** + * Run the void setDeleteCondition(DeletePolicyCondition) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetDeleteCondition_1() + throws Exception { + DeletePolicyParameters fixture = new DeletePolicyParameters(); + fixture.setPolicyComponent(""); + fixture.setPolicyName(""); + fixture.setDeleteCondition(DeletePolicyCondition.ALL); + fixture.setRequestID(UUID.randomUUID()); + fixture.setPdpGroup(""); + DeletePolicyCondition deleteCondition = DeletePolicyCondition.ALL; + + fixture.setDeleteCondition(deleteCondition); + + // add additional test code here + } + + /** + * Run the void setPdpGroup(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetPdpGroup_1() + throws Exception { + DeletePolicyParameters fixture = new DeletePolicyParameters(); + fixture.setPolicyComponent(""); + fixture.setPolicyName(""); + fixture.setDeleteCondition(DeletePolicyCondition.ALL); + fixture.setRequestID(UUID.randomUUID()); + fixture.setPdpGroup(""); + String pdpGroup = ""; + + fixture.setPdpGroup(pdpGroup); + + // add additional test code here + } + + /** + * Run the void setPolicyComponent(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetPolicyComponent_1() + throws Exception { + DeletePolicyParameters fixture = new DeletePolicyParameters(); + fixture.setPolicyComponent(""); + fixture.setPolicyName(""); + fixture.setDeleteCondition(DeletePolicyCondition.ALL); + fixture.setRequestID(UUID.randomUUID()); + fixture.setPdpGroup(""); + String policyComponent = ""; + + fixture.setPolicyComponent(policyComponent); + + // add additional test code here + } + + /** + * Run the void setPolicyName(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetPolicyName_1() + throws Exception { + DeletePolicyParameters fixture = new DeletePolicyParameters(); + fixture.setPolicyComponent(""); + fixture.setPolicyName(""); + fixture.setDeleteCondition(DeletePolicyCondition.ALL); + fixture.setRequestID(UUID.randomUUID()); + fixture.setPdpGroup(""); + String policyName = ""; + + fixture.setPolicyName(policyName); + + // add additional test code here + } + + /** + * Run the void setRequestID(UUID) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetRequestID_1() + throws Exception { + DeletePolicyParameters fixture = new DeletePolicyParameters(); + fixture.setPolicyComponent(""); + fixture.setPolicyName(""); + fixture.setDeleteCondition(DeletePolicyCondition.ALL); + fixture.setRequestID(UUID.randomUUID()); + fixture.setPdpGroup(""); + UUID requestID = UUID.randomUUID(); + + fixture.setRequestID(requestID); + + // add additional test code here + } + + /** + * Perform pre-test initialization. + * + * @throws Exception + * if the initialization fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Before + public void setUp() + throws Exception { + // add additional set up code here + } + + /** + * Perform post-test clean-up. + * + * @throws Exception + * if the clean-up fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @After + public void tearDown() + throws Exception { + // Add additional tear down code here + } + + /** + * Launch the test. + * + * @param args the command line arguments + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(DeletePolicyParametersTest.class); + } +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/EventRequestParametersTest.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/EventRequestParametersTest.java new file mode 100644 index 000000000..c8d9bd492 --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/EventRequestParametersTest.java @@ -0,0 +1,193 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.test; + +import java.util.Hashtable; +import java.util.Map; +import java.util.UUID; + +import org.junit.*; +import org.openecomp.policy.api.EventRequestParameters; + +import static org.junit.Assert.*; + +/** + * The class EventRequestParametersTest contains tests for the class {@link EventRequestParameters}. + * + * @generatedBy CodePro at 6/1/16 1:41 PM + * @version $Revision: 1.0 $ + */ +public class EventRequestParametersTest { + /** + * Run the EventRequestParameters() constructor test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testEventRequestParameters_1() + throws Exception { + + EventRequestParameters result = new EventRequestParameters(); + + // add additional test code here + assertNotNull(result); + assertEquals(null, result.getEventAttributes()); + assertEquals(null, result.getRequestID()); + } + + /** + * Run the EventRequestParameters(Map,UUID) constructor test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testEventRequestParameters_2() + throws Exception { + Map eventAttributes = new Hashtable(); + UUID requestID = UUID.randomUUID(); + + EventRequestParameters result = new EventRequestParameters(eventAttributes, requestID); + + // add additional test code here + assertNotNull(result); + } + + /** + * Run the Map getEventAttributes() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testGetEventAttributes_1() + throws Exception { + EventRequestParameters fixture = new EventRequestParameters(new Hashtable(), UUID.randomUUID()); + + Map result = fixture.getEventAttributes(); + + // add additional test code here + assertNotNull(result); + assertEquals(0, result.size()); + } + + /** + * Run the UUID getRequestID() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testGetRequestID_1() + throws Exception { + EventRequestParameters fixture = new EventRequestParameters(new Hashtable(), UUID.fromString("5b15376d-569b-4772-ac75-9362043f6a6c")); + + UUID result = fixture.getRequestID(); + + // add additional test code here + assertNotNull(result); + assertEquals("5b15376d-569b-4772-ac75-9362043f6a6c", result.toString()); + assertEquals(4, result.version()); + assertEquals(2, result.variant()); + assertEquals(-6019743277723456916L, result.getLeastSignificantBits()); + assertEquals(6563212974706345842L, result.getMostSignificantBits()); + } + + /** + * Run the void setEventAttributes(Map) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testSetEventAttributes_1() + throws Exception { + EventRequestParameters fixture = new EventRequestParameters(new Hashtable(), UUID.randomUUID()); + Map eventAttributes = new Hashtable(); + + fixture.setEventAttributes(eventAttributes); + + // add additional test code here + } + + /** + * Run the void setRequestID(UUID) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testSetRequestID_1() + throws Exception { + EventRequestParameters fixture = new EventRequestParameters(new Hashtable(), UUID.randomUUID()); + UUID requestID = UUID.randomUUID(); + + fixture.setRequestID(requestID); + + // add additional test code here + } + + /** + * Perform pre-test initialization. + * + * @throws Exception + * if the initialization fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Before + public void setUp() + throws Exception { + // add additional set up code here + } + + /** + * Perform post-test clean-up. + * + * @throws Exception + * if the clean-up fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @After + public void tearDown() + throws Exception { + // Add additional tear down code here + } + + /** + * Launch the test. + * + * @param args the command line arguments + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(EventRequestParametersTest.class); + } +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/GetConfigByPolicyNameTest.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/GetConfigByPolicyNameTest.java new file mode 100644 index 000000000..ccab587da --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/GetConfigByPolicyNameTest.java @@ -0,0 +1,64 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.test; + +import java.util.Collection; + +import junit.framework.TestCase; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.Before; +import org.junit.Test; +import org.openecomp.policy.api.PolicyConfig; +import org.openecomp.policy.api.PolicyConfigException; +import org.openecomp.policy.api.PolicyEngine; +import org.openecomp.policy.api.PolicyEngineException; + +import org.openecomp.policy.common.logging.flexlogger.*; + +public class GetConfigByPolicyNameTest extends TestCase { + private PolicyEngine policyEngine = null; + private String policyName = null; + private Collection policyConfig = null; + private static final Logger logger = FlexLogger.getLogger(GetConfigByPolicyNameTest.class); + @Before + public void setUp() { + try { + policyEngine = new PolicyEngine("Test/config_pass.properties"); + } catch (PolicyEngineException e) { + logger.error(e.getMessage()); + fail("PolicyEngine Instantiation Error" + e); + } + logger.info("Loaded.. PolicyEngine"); + } + + @Test + public void testGetConfigPolicyNameNotValid(){ + policyName = null; + try{ + policyConfig = policyEngine.getConfigByPolicyName(policyName); + } catch (PolicyConfigException e){ + logger.warn(e.getMessage()); + } + assertNull(policyConfig); + } +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/GetConfigStringStringMapTest.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/GetConfigStringStringMapTest.java new file mode 100644 index 000000000..23cce3d8f --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/GetConfigStringStringMapTest.java @@ -0,0 +1,251 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.Before; +import org.junit.Test; +import org.openecomp.policy.api.PolicyConfig; +import org.openecomp.policy.api.PolicyConfigException; +import org.openecomp.policy.api.PolicyConfigStatus; +import org.openecomp.policy.api.PolicyEngine; +import org.openecomp.policy.api.PolicyEngineException; +import org.openecomp.policy.api.PolicyType; + +import org.openecomp.policy.common.logging.flexlogger.*; + +public class GetConfigStringStringMapTest { + + private PolicyEngine policyEngine = null; + private String eCOMPComponentName = null; + private String configName = null; + private Map configAttributes = new HashMap(); + private Collection policyConfig = null; + private static final Logger logger = FlexLogger.getLogger(GetConfigStringStringMapTest.class); + @Before + public void setUp() { + try { + policyEngine = new PolicyEngine("Test/config_pass.properties"); + } catch (PolicyEngineException e) { + logger.error(e.getMessage()); + fail("PolicyEngine Instantiation Error" + e); + } + logger.info("Loaded.. PolicyEngine"); + } + + @Test + public void testGetConfigStringStringMapFail() { + eCOMPComponentName = null; + configName = null; + configAttributes = null; + try { + policyConfig = policyEngine.getConfig(eCOMPComponentName, configName, configAttributes); + } catch (PolicyConfigException e) { + logger.warn(e.getMessage()); + } + assertNull(policyConfig); + } + + @Test + public void testGetConfigStringStringMapFail1() { + eCOMPComponentName = null; + configName = "testFail"; + configAttributes.put("TestValue", "Fail"); + try { + policyConfig = policyEngine.getConfig(eCOMPComponentName, configName, configAttributes); + } catch (PolicyConfigException e) { + logger.warn(e.getMessage()); + } + assertNull(policyConfig); + } + + @Test + public void testGetConfigStringStringMapFail2() { + eCOMPComponentName = "TestFail"; + configName = null; + configAttributes.put("TestValue", "Fail"); + try { + policyConfig = policyEngine.getConfig(eCOMPComponentName, configName, configAttributes); + } catch (PolicyConfigException e) { + logger.warn(e.getMessage()); + } + assertNull(policyConfig); + } + + @Test + public void testGetConfigStringStringMapFail3() { + eCOMPComponentName = "TestFail"; + configName = "configFail"; + configAttributes= null; + try { + policyConfig = policyEngine.getConfig(eCOMPComponentName, configName, configAttributes); + } catch (PolicyConfigException e) { + logger.warn(e.getMessage()); + } + assertNull(policyConfig); + } + + @Test + public void testGetConfigStringStringMapfail4() { + eCOMPComponentName = "TestFail"; + configName = "configFail"; + configAttributes.put("", ""); + try { + policyConfig = policyEngine.getConfig(eCOMPComponentName, configName, configAttributes); + } catch (PolicyConfigException e) { + logger.warn(e.getMessage()); + } + assertNull(policyConfig); + } + + //@Test + public void testGetConfigStringStringMapNotValid() { + eCOMPComponentName = "TestFail"; + configName = "configFail"; + configAttributes.put("Action:com.test.fail", "Value"); + try { + policyConfig = policyEngine.getConfig(eCOMPComponentName, configName, configAttributes); + } catch (PolicyConfigException e) { + logger.warn(e.getMessage()); + } + for(PolicyConfig policyConfig : this.policyConfig){ + logger.info(policyConfig.getPolicyConfigMessage() + " , " +policyConfig.getPolicyConfigStatus()); + assertNotNull(policyConfig); + assertEquals(PolicyConfigStatus.CONFIG_NOT_FOUND,policyConfig.getPolicyConfigStatus()); + assertNotNull(policyConfig.getPolicyConfigMessage()); + assertNull(policyConfig.getType()); + assertNull(policyConfig.toJSON()); + assertNull(policyConfig.toProperties()); + assertNull(policyConfig.toXML()); + assertNull(policyConfig.toOther()); + } + } + + //@Test + public void testGetConfigStringStringMapValidJSON() { + eCOMPComponentName = "JSON"; + configName = "JSONconfig"; + configAttributes.put("Resource.com:test:resource:json", "Test"); + configAttributes.put("Action.com:test:action:json", "TestJSON"); + configAttributes.put("Subject.com:test:subject:json", "TestSubject"); + try { + policyConfig = policyEngine.getConfig(eCOMPComponentName, configName, configAttributes); + } catch (PolicyConfigException e) { + logger.warn(e.getMessage()); + } + for(PolicyConfig policyConfig : this.policyConfig){ + logger.info(policyConfig.getPolicyConfigMessage() + " , " +policyConfig.getPolicyConfigStatus()); + assertNotNull(policyConfig); + assertEquals(PolicyConfigStatus.CONFIG_RETRIEVED,policyConfig.getPolicyConfigStatus()); + assertNotNull(policyConfig.getPolicyConfigMessage()); + assertEquals(PolicyType.JSON,policyConfig.getType()); + assertNotNull(policyConfig.toJSON()); + assertNull(policyConfig.toProperties()); + assertNull(policyConfig.toXML()); + assertNull(policyConfig.toOther()); + } + } + + //@Test + public void testGetConfigStringStringMapValidXML() { + eCOMPComponentName = "XML"; + configName = "XMLconfig"; + configAttributes.put("Resource.com:test:resource:json", "Test"); + configAttributes.put("Action.com:test:action:json", "TestJSON"); + configAttributes.put("Subject.com:test:subject:json", "TestSubject"); + try { + policyConfig = policyEngine.getConfig(eCOMPComponentName, configName, configAttributes); + } catch (PolicyConfigException e) { + logger.warn(e.getMessage()); + } + for(PolicyConfig policyConfig : this.policyConfig){ + logger.info(policyConfig.getPolicyConfigMessage() + " , " +policyConfig.getPolicyConfigStatus()); + assertNotNull(policyConfig); + assertEquals(PolicyConfigStatus.CONFIG_RETRIEVED,policyConfig.getPolicyConfigStatus()); + assertNotNull(policyConfig.getPolicyConfigMessage()); + assertEquals(PolicyType.XML,policyConfig.getType()); + assertNull(policyConfig.toJSON()); + assertNull(policyConfig.toProperties()); + assertNotNull(policyConfig.toXML()); + assertNull(policyConfig.toOther()); + } + } + + //@Test + public void testGetConfigStringStringMapValidProperties() { + eCOMPComponentName = "Properties"; + configName = "PropConfig" ; + configAttributes.put("Resource.com:test:resource:json", "Test"); + configAttributes.put("Action.com:test:action:json", "TestJSON"); + configAttributes.put("Subject.com:test:subject:json", "TestSubject"); + try { + policyConfig = policyEngine.getConfig(eCOMPComponentName, configName, configAttributes); + } catch (PolicyConfigException e) { + logger.warn(e.getMessage()); + } + for(PolicyConfig policyConfig : this.policyConfig){ + logger.info(policyConfig.getPolicyConfigMessage() + " , " +policyConfig.getPolicyConfigStatus()); + assertNotNull(policyConfig); + assertEquals(PolicyConfigStatus.CONFIG_RETRIEVED,policyConfig.getPolicyConfigStatus()); + assertNotNull(policyConfig.getPolicyConfigMessage()); + assertEquals(PolicyType.PROPERTIES,policyConfig.getType()); + assertNull(policyConfig.toJSON()); + assertNotNull(policyConfig.toProperties()); + assertNull(policyConfig.toXML()); + assertNull(policyConfig.toOther()); + } + } + + //@Test + public void testGetConfigStringStringMapValidOther() { + eCOMPComponentName = "Other"; + configName = "OtherConfig" ; + configAttributes.put("Resource.com:test:resource:json", "Test"); + configAttributes.put("Action.com:test:action:json", "TestJSON"); + configAttributes.put("Subject.com:test:subject:json", "TestSubject"); + try { + policyConfig = policyEngine.getConfig(eCOMPComponentName, configName, configAttributes); + } catch (PolicyConfigException e) { + logger.warn(e.getMessage()); + } + for(PolicyConfig policyConfig : this.policyConfig){ + logger.info(policyConfig.getPolicyConfigMessage() + " , " +policyConfig.getPolicyConfigStatus()); + assertNotNull(policyConfig); + assertEquals(PolicyConfigStatus.CONFIG_RETRIEVED,policyConfig.getPolicyConfigStatus()); + assertNotNull(policyConfig.getPolicyConfigMessage()); + assertEquals(PolicyType.OTHER,policyConfig.getType()); + assertNull(policyConfig.toJSON()); + assertNull(policyConfig.toProperties()); + assertNull(policyConfig.toXML()); + assertNotNull(policyConfig.toOther()); + } + } +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/GetConfigStringStringTest.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/GetConfigStringStringTest.java new file mode 100644 index 000000000..fc8302c0b --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/GetConfigStringStringTest.java @@ -0,0 +1,207 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; + +import java.util.Collection; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.Before; +import org.junit.Test; +import org.openecomp.policy.api.PolicyConfig; +import org.openecomp.policy.api.PolicyConfigException; +import org.openecomp.policy.api.PolicyConfigStatus; +import org.openecomp.policy.api.PolicyEngine; +import org.openecomp.policy.api.PolicyEngineException; +import org.openecomp.policy.api.PolicyType; + +import org.openecomp.policy.common.logging.flexlogger.*; + +public class GetConfigStringStringTest { + + private PolicyEngine policyEngine = null; + private String eCOMPComponentName = null; + private String configName = null; + private Collection policyConfig = null; + private static final Logger logger = FlexLogger.getLogger(GetConfigStringStringTest.class); + @Before + public void setUp() { + try { + policyEngine = new PolicyEngine("Test/config_pass.properties"); + } catch (PolicyEngineException e) { + logger.error(e.getMessage()); + fail("PolicyEngine Instantiation Error" + e); + } + logger.info("Loaded.. PolicyEngine"); + } + + @Test + public void testGetConfigStringStringFail() { + eCOMPComponentName = null; + configName = null; + try { + policyConfig = policyEngine.getConfig(eCOMPComponentName, configName); + } catch (PolicyConfigException e) { + logger.warn(e.getMessage()); + } + assertNull(policyConfig); + } + + @Test + public void testGetConfigStringStringFail1() { + eCOMPComponentName = null; + configName = ""; + try { + policyConfig = policyEngine.getConfig(eCOMPComponentName, configName); + } catch (PolicyConfigException e) { + logger.warn(e.getMessage()); + } + assertNull(policyConfig); + } + + @Test + public void testGetConfigStringStringFail2() { + eCOMPComponentName = ""; + configName = null; + try { + policyConfig = policyEngine.getConfig(eCOMPComponentName, configName); + } catch (PolicyConfigException e) { + logger.warn(e.getMessage()); + } + assertNull(policyConfig); + } + + //@Test + public void testGetConfigStringStringNotvalid() { + eCOMPComponentName = "fail"; + configName = "fail"; + try { + policyConfig = policyEngine.getConfig(eCOMPComponentName, configName); + } catch (PolicyConfigException e) { + logger.warn(e.getMessage()); + } + for(PolicyConfig policyConfig : this.policyConfig){ + logger.info(policyConfig.getPolicyConfigMessage() + " , " +policyConfig.getPolicyConfigStatus()); + assertNotNull(policyConfig); + assertEquals(PolicyConfigStatus.CONFIG_NOT_FOUND,policyConfig.getPolicyConfigStatus()); + assertNotNull(policyConfig.getPolicyConfigMessage()); + assertNull(policyConfig.getType()); + assertNull(policyConfig.toJSON()); + assertNull(policyConfig.toProperties()); + assertNull(policyConfig.toXML()); + assertNull(policyConfig.toOther()); + } + } + + //@Test + public void testGetConfigStringStringValidJSON() { + eCOMPComponentName = "JSON"; + configName = "JSONconfig"; + try { + policyConfig = policyEngine.getConfig(eCOMPComponentName, configName); + } catch (PolicyConfigException e) { + logger.warn(e.getMessage()); + } + for(PolicyConfig policyConfig : this.policyConfig){ + logger.info(policyConfig.getPolicyConfigMessage() + " , " +policyConfig.getPolicyConfigStatus()); + assertNotNull(policyConfig); + assertEquals(PolicyConfigStatus.CONFIG_RETRIEVED,policyConfig.getPolicyConfigStatus()); + assertNotNull(policyConfig.getPolicyConfigMessage()); + assertEquals(PolicyType.JSON,policyConfig.getType()); + assertNotNull(policyConfig.toJSON()); + assertNull(policyConfig.toProperties()); + assertNull(policyConfig.toXML()); + assertNull(policyConfig.toOther()); + } + } + + //@Test + public void testGetConfigStringStringValidXML() { + eCOMPComponentName = "XML"; + configName = "XMLconfig"; + try { + policyConfig = policyEngine.getConfig(eCOMPComponentName, configName); + } catch (PolicyConfigException e) { + logger.warn(e.getMessage()); + } + for(PolicyConfig policyConfig : this.policyConfig){ + logger.info(policyConfig.getPolicyConfigMessage() + " , " +policyConfig.getPolicyConfigStatus()); + assertNotNull(policyConfig); + assertEquals(PolicyConfigStatus.CONFIG_RETRIEVED,policyConfig.getPolicyConfigStatus()); + assertNotNull(policyConfig.getPolicyConfigMessage()); + assertEquals(PolicyType.XML,policyConfig.getType()); + assertNull(policyConfig.toJSON()); + assertNull(policyConfig.toProperties()); + assertNotNull(policyConfig.toXML()); + assertNull(policyConfig.toOther()); + } + } + + //@Test + public void testGetConfigStringStringValidProperties() { + eCOMPComponentName = "Properties"; + configName = "PropConfig" ; + try { + policyConfig = policyEngine.getConfig(eCOMPComponentName, configName); + } catch (PolicyConfigException e) { + logger.warn(e.getMessage()); + } + for(PolicyConfig policyConfig : this.policyConfig){ + logger.info(policyConfig.getPolicyConfigMessage() + " , " +policyConfig.getPolicyConfigStatus()); + assertNotNull(policyConfig); + assertEquals(PolicyConfigStatus.CONFIG_RETRIEVED,policyConfig.getPolicyConfigStatus()); + assertNotNull(policyConfig.getPolicyConfigMessage()); + assertEquals(PolicyType.PROPERTIES,policyConfig.getType()); + assertNull(policyConfig.toJSON()); + assertNotNull(policyConfig.toProperties()); + assertNull(policyConfig.toXML()); + assertNull(policyConfig.toOther()); + } + } + + //@Test + public void testGetConfigStringStringValidOther() { + eCOMPComponentName = "Other"; + configName = "OtherConfig" ; + try { + policyConfig = policyEngine.getConfig(eCOMPComponentName, configName); + } catch (PolicyConfigException e) { + logger.warn(e.getMessage()); + } + for(PolicyConfig policyConfig : this.policyConfig){ + logger.info(policyConfig.getPolicyConfigMessage() + " , " +policyConfig.getPolicyConfigStatus()); + assertNotNull(policyConfig); + assertEquals(PolicyConfigStatus.CONFIG_RETRIEVED,policyConfig.getPolicyConfigStatus()); + assertNotNull(policyConfig.getPolicyConfigMessage()); + assertEquals(PolicyType.OTHER,policyConfig.getType()); + assertNull(policyConfig.toJSON()); + assertNull(policyConfig.toProperties()); + assertNull(policyConfig.toXML()); + assertNotNull(policyConfig.toOther()); + } + } + +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/GetConfigStringTest.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/GetConfigStringTest.java new file mode 100644 index 000000000..42d38539b --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/GetConfigStringTest.java @@ -0,0 +1,175 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.test; + +import java.util.Collection; + +import junit.framework.TestCase; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import org.openecomp.policy.api.PolicyConfig; +import org.openecomp.policy.api.PolicyConfigException; +import org.openecomp.policy.api.PolicyConfigStatus; +import org.openecomp.policy.api.PolicyEngine; +import org.openecomp.policy.api.PolicyEngineException; +import org.openecomp.policy.api.PolicyType; + +import org.openecomp.policy.common.logging.flexlogger.*; + +public class GetConfigStringTest extends TestCase{ + + private PolicyEngine policyEngine = null; + private String eCOMPComponentName = null; + private Collection policyConfig = null; + private static final Logger logger = FlexLogger.getLogger(GetConfigStringTest.class); + @Before + public void setUp() { + try { + policyEngine = new PolicyEngine("Test/config_pass.properties"); + } catch (PolicyEngineException e) { + logger.error(e.getMessage()); + fail("PolicyEngine Instantiation Error" + e); + } + logger.info("Loaded.. PolicyEngine"); + } + + //@Test + public void testGetConfigStringFail() { + eCOMPComponentName = null; + try { + policyConfig = policyEngine.getConfig(eCOMPComponentName); + } catch (PolicyConfigException e) { + logger.warn(e.getMessage()); + } + assertNull(policyConfig); + } + + /*@Test + public void testGetConfigStringNotvalid() { + eCOMPComponentName = "fail"; + try { + policyConfig = policyEngine.getConfig(eCOMPComponentName); + } catch (PolicyConfigException e) { + logger.warn(e.getMessage()); + } + for(PolicyConfig policyConfig : this.policyConfig){ + logger.info(policyConfig.getPolicyConfigMessage() + " , " +policyConfig.getPolicyConfigStatus()); + assertNotNull(policyConfig); + assertEquals(PolicyConfigStatus.CONFIG_NOT_FOUND,policyConfig.getPolicyConfigStatus()); + assertNotNull(policyConfig.getPolicyConfigMessage()); + assertNull(policyConfig.getType()); + assertNull(policyConfig.toJSON()); + assertNull(policyConfig.toProperties()); + assertNull(policyConfig.toXML()); + assertNull(policyConfig.toOther()); + } + } + */ + + /*@Test + public void testGetConfigStringValidJSON() { + eCOMPComponentName = "JSON"; + try { + policyConfig = policyEngine.getConfig(eCOMPComponentName); + } catch (PolicyConfigException e) { + logger.warn(e.getMessage()); + } + for(PolicyConfig policyConfig : this.policyConfig){ + logger.info(policyConfig.getPolicyConfigMessage() + " , " +policyConfig.getPolicyConfigStatus()); + assertNotNull(policyConfig); + assertEquals(PolicyConfigStatus.CONFIG_RETRIEVED,policyConfig.getPolicyConfigStatus()); + assertNotNull(policyConfig.getPolicyConfigMessage()); + assertEquals(PolicyType.JSON,policyConfig.getType()); + assertNotNull(policyConfig.toJSON()); + assertNull(policyConfig.toProperties()); + assertNull(policyConfig.toXML()); + assertNull(policyConfig.toOther()); + } + } + */ + /*@Test + public void testGetConfigStringValidXML() { + eCOMPComponentName = "XML"; + try { + policyConfig = policyEngine.getConfig(eCOMPComponentName); + } catch (PolicyConfigException e) { + logger.warn(e.getMessage()); + } + for(PolicyConfig policyConfig : this.policyConfig){ + logger.info(policyConfig.getPolicyConfigMessage() + " , " +policyConfig.getPolicyConfigStatus()); + assertNotNull(policyConfig); + assertEquals(PolicyConfigStatus.CONFIG_RETRIEVED,policyConfig.getPolicyConfigStatus()); + assertNotNull(policyConfig.getPolicyConfigMessage()); + assertEquals(PolicyType.XML,policyConfig.getType()); + assertNull(policyConfig.toJSON()); + assertNull(policyConfig.toProperties()); + assertNotNull(policyConfig.toXML()); + assertNull(policyConfig.toOther()); + } + } + */ + /*@Test + public void testGetConfigStringValidProperties() { + eCOMPComponentName = "Properties"; + try { + policyConfig = policyEngine.getConfig(eCOMPComponentName); + } catch (PolicyConfigException e) { + logger.warn(e.getMessage()); + } + for(PolicyConfig policyConfig : this.policyConfig){ + logger.info(policyConfig.getPolicyConfigMessage() + " , " +policyConfig.getPolicyConfigStatus()); + assertNotNull(policyConfig); + assertEquals(PolicyConfigStatus.CONFIG_RETRIEVED,policyConfig.getPolicyConfigStatus()); + assertNotNull(policyConfig.getPolicyConfigMessage()); + assertEquals(PolicyType.PROPERTIES,policyConfig.getType()); + assertNull(policyConfig.toJSON()); + assertNotNull(policyConfig.toProperties()); + assertNull(policyConfig.toXML()); + assertNull(policyConfig.toOther()); + } + } + */ + /*@Test + public void testGetConfigStringValidOther() { + eCOMPComponentName = "Other"; + try { + policyConfig = policyEngine.getConfig(eCOMPComponentName); + } catch (PolicyConfigException e) { + logger.warn(e.getMessage()); + } + for(PolicyConfig policyConfig : this.policyConfig){ + logger.info(policyConfig.getPolicyConfigMessage() + " , " +policyConfig.getPolicyConfigStatus()); + assertNotNull(policyConfig); + assertEquals(PolicyConfigStatus.CONFIG_RETRIEVED,policyConfig.getPolicyConfigStatus()); + assertNotNull(policyConfig.getPolicyConfigMessage()); + assertEquals(PolicyType.OTHER,policyConfig.getType()); + assertNull(policyConfig.toJSON()); + assertNull(policyConfig.toProperties()); + assertNull(policyConfig.toXML()); + assertNotNull(policyConfig.toOther()); + } + } + */ +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/ImportParametersTest.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/ImportParametersTest.java new file mode 100644 index 000000000..f6ceff682 --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/ImportParametersTest.java @@ -0,0 +1,464 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.test; + +import java.util.UUID; + +import org.junit.*; +import org.openecomp.policy.api.ImportParameters; +import org.openecomp.policy.api.ImportParameters.IMPORT_TYPE; + +import static org.junit.Assert.*; + +/** + * The class ImportParametersTest contains tests for the class {@link ImportParameters}. + * + * @generatedBy CodePro at 6/1/16 1:40 PM + * @version $Revision: 1.0 $ + */ +public class ImportParametersTest { + /** + * Run the String getDescription() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetDescription_1() + throws Exception { + ImportParameters fixture = new ImportParameters(); + fixture.setFilePath(""); + fixture.setVersion(""); + fixture.setImportBody(""); + fixture.setServiceType(ImportParameters.IMPORT_TYPE.MICROSERVICE); + fixture.setRequestID(UUID.randomUUID()); + fixture.setDescription(""); + fixture.setServiceName(""); + + String result = fixture.getDescription(); + + // add additional test code here + assertEquals("", result); + } + + /** + * Run the String getFilePath() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetFilePath_1() + throws Exception { + ImportParameters fixture = new ImportParameters(); + fixture.setFilePath(""); + fixture.setVersion(""); + fixture.setImportBody(""); + fixture.setServiceType(ImportParameters.IMPORT_TYPE.MICROSERVICE); + fixture.setRequestID(UUID.randomUUID()); + fixture.setDescription(""); + fixture.setServiceName(""); + + String result = fixture.getFilePath(); + + // add additional test code here + assertEquals("", result); + } + + /** + * Run the String getImportBody() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetImportBody_1() + throws Exception { + ImportParameters fixture = new ImportParameters(); + fixture.setFilePath(""); + fixture.setVersion(""); + fixture.setImportBody(""); + fixture.setServiceType(ImportParameters.IMPORT_TYPE.MICROSERVICE); + fixture.setRequestID(UUID.randomUUID()); + fixture.setDescription(""); + fixture.setServiceName(""); + + String result = fixture.getImportBody(); + + // add additional test code here + assertEquals("", result); + } + + /** + * Run the UUID getRequestID() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetRequestID_1() + throws Exception { + ImportParameters fixture = new ImportParameters(); + fixture.setFilePath(""); + fixture.setVersion(""); + fixture.setImportBody(""); + fixture.setServiceType(ImportParameters.IMPORT_TYPE.MICROSERVICE); + fixture.setRequestID(UUID.fromString("731dca0a-fe99-456c-8ad2-87cff8437b2f")); + fixture.setDescription(""); + fixture.setServiceName(""); + + UUID result = fixture.getRequestID(); + + // add additional test code here + assertNotNull(result); + assertEquals("731dca0a-fe99-456c-8ad2-87cff8437b2f", result.toString()); + assertEquals(4, result.version()); + assertEquals(2, result.variant()); + assertEquals(-8443537024073106641L, result.getLeastSignificantBits()); + assertEquals(8295008237256263020L, result.getMostSignificantBits()); + } + + /** + * Run the String getServiceName() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetServiceName_1() + throws Exception { + ImportParameters fixture = new ImportParameters(); + fixture.setFilePath(""); + fixture.setVersion(""); + fixture.setImportBody(""); + fixture.setServiceType(ImportParameters.IMPORT_TYPE.MICROSERVICE); + fixture.setRequestID(UUID.randomUUID()); + fixture.setDescription(""); + fixture.setServiceName(""); + + String result = fixture.getServiceName(); + + // add additional test code here + assertEquals("", result); + } + + /** + * Run the ImportParameters.IMPORT_TYPE getServiceType() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetServiceType_1() + throws Exception { + ImportParameters fixture = new ImportParameters(); + fixture.setFilePath(""); + fixture.setVersion(""); + fixture.setImportBody(""); + fixture.setServiceType(ImportParameters.IMPORT_TYPE.MICROSERVICE); + fixture.setRequestID(UUID.randomUUID()); + fixture.setDescription(""); + fixture.setServiceName(""); + + ImportParameters.IMPORT_TYPE result = fixture.getServiceType(); + + // add additional test code here + assertNotNull(result); + assertEquals("MICROSERVICE", result.name()); + assertEquals("MICROSERVICE", result.toString()); + assertEquals(0, result.ordinal()); + } + + /** + * Run the String getVersion() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetVersion_1() + throws Exception { + ImportParameters fixture = new ImportParameters(); + fixture.setFilePath(""); + fixture.setVersion(""); + fixture.setImportBody(""); + fixture.setServiceType(ImportParameters.IMPORT_TYPE.MICROSERVICE); + fixture.setRequestID(UUID.randomUUID()); + fixture.setDescription(""); + fixture.setServiceName(""); + + String result = fixture.getVersion(); + + // add additional test code here + assertEquals("", result); + } + + /** + * Run the void setDescription(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetDescription_1() + throws Exception { + ImportParameters fixture = new ImportParameters(); + fixture.setFilePath(""); + fixture.setVersion(""); + fixture.setImportBody(""); + fixture.setServiceType(ImportParameters.IMPORT_TYPE.MICROSERVICE); + fixture.setRequestID(UUID.randomUUID()); + fixture.setDescription(""); + fixture.setServiceName(""); + String description = ""; + + fixture.setDescription(description); + + // add additional test code here + } + + /** + * Run the void setFilePath(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetFilePath_1() + throws Exception { + ImportParameters fixture = new ImportParameters(); + fixture.setFilePath(""); + fixture.setVersion(""); + fixture.setImportBody(""); + fixture.setServiceType(ImportParameters.IMPORT_TYPE.MICROSERVICE); + fixture.setRequestID(UUID.randomUUID()); + fixture.setDescription(""); + fixture.setServiceName(""); + String filePath = ""; + + fixture.setFilePath(filePath); + + // add additional test code here + } + + /** + * Run the void setImportBody(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetImportBody_1() + throws Exception { + ImportParameters fixture = new ImportParameters(); + fixture.setFilePath(""); + fixture.setVersion(""); + fixture.setImportBody(""); + fixture.setServiceType(ImportParameters.IMPORT_TYPE.MICROSERVICE); + fixture.setRequestID(UUID.randomUUID()); + fixture.setDescription(""); + fixture.setServiceName(""); + String importBody = ""; + + fixture.setImportBody(importBody); + + // add additional test code here + } + + /** + * Run the void setImportParameters(String,String,UUID,String,IMPORT_TYPE,String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetImportParameters_1() + throws Exception { + ImportParameters fixture = new ImportParameters(); + fixture.setFilePath(""); + fixture.setVersion(""); + fixture.setImportBody(""); + fixture.setServiceType(ImportParameters.IMPORT_TYPE.MICROSERVICE); + fixture.setRequestID(UUID.randomUUID()); + fixture.setDescription(""); + fixture.setServiceName(""); + String serviceName = ""; + String description = ""; + UUID requestID = UUID.randomUUID(); + String filePath = ""; + ImportParameters.IMPORT_TYPE importType = ImportParameters.IMPORT_TYPE.MICROSERVICE; + String version = ""; + + fixture.setImportParameters(serviceName, description, requestID, filePath, importType, version); + + // add additional test code here + } + + /** + * Run the void setRequestID(UUID) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetRequestID_1() + throws Exception { + ImportParameters fixture = new ImportParameters(); + fixture.setFilePath(""); + fixture.setVersion(""); + fixture.setImportBody(""); + fixture.setServiceType(ImportParameters.IMPORT_TYPE.MICROSERVICE); + fixture.setRequestID(UUID.randomUUID()); + fixture.setDescription(""); + fixture.setServiceName(""); + UUID requestID = UUID.randomUUID(); + + fixture.setRequestID(requestID); + + // add additional test code here + } + + /** + * Run the void setServiceName(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetServiceName_1() + throws Exception { + ImportParameters fixture = new ImportParameters(); + fixture.setFilePath(""); + fixture.setVersion(""); + fixture.setImportBody(""); + fixture.setServiceType(ImportParameters.IMPORT_TYPE.MICROSERVICE); + fixture.setRequestID(UUID.randomUUID()); + fixture.setDescription(""); + fixture.setServiceName(""); + String serviceName = ""; + + fixture.setServiceName(serviceName); + + // add additional test code here + } + + /** + * Run the void setServiceType(IMPORT_TYPE) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetServiceType_1() + throws Exception { + ImportParameters fixture = new ImportParameters(); + fixture.setFilePath(""); + fixture.setVersion(""); + fixture.setImportBody(""); + fixture.setServiceType(ImportParameters.IMPORT_TYPE.MICROSERVICE); + fixture.setRequestID(UUID.randomUUID()); + fixture.setDescription(""); + fixture.setServiceName(""); + ImportParameters.IMPORT_TYPE enumImportType = ImportParameters.IMPORT_TYPE.MICROSERVICE; + + fixture.setServiceType(enumImportType); + + // add additional test code here + } + + /** + * Run the void setVersion(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetVersion_1() + throws Exception { + ImportParameters fixture = new ImportParameters(); + fixture.setFilePath(""); + fixture.setVersion(""); + fixture.setImportBody(""); + fixture.setServiceType(ImportParameters.IMPORT_TYPE.MICROSERVICE); + fixture.setRequestID(UUID.randomUUID()); + fixture.setDescription(""); + fixture.setServiceName(""); + String version = ""; + + fixture.setVersion(version); + + // add additional test code here + } + + /** + * Perform pre-test initialization. + * + * @throws Exception + * if the initialization fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Before + public void setUp() + throws Exception { + // add additional set up code here + } + + /** + * Perform post-test clean-up. + * + * @throws Exception + * if the clean-up fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @After + public void tearDown() + throws Exception { + // Add additional tear down code here + } + + /** + * Launch the test. + * + * @param args the command line arguments + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(ImportParametersTest.class); + } +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/LoadedPolicyTest.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/LoadedPolicyTest.java new file mode 100644 index 000000000..f750312b1 --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/LoadedPolicyTest.java @@ -0,0 +1,75 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.test; + +import java.util.Map; + +import org.junit.*; +import org.openecomp.policy.api.LoadedPolicy; + +import static org.junit.Assert.*; + +/** + * The class LoadedPolicyTest contains tests for the class {@link LoadedPolicy}. + * + * @generatedBy CodePro at 6/1/16 1:40 PM + * @version $Revision: 1.0 $ + */ +public class LoadedPolicyTest { + /** + * Perform pre-test initialization. + * + * @throws Exception + * if the initialization fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Before + public void setUp() + throws Exception { + // add additional set up code here + } + + /** + * Perform post-test clean-up. + * + * @throws Exception + * if the clean-up fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @After + public void tearDown() + throws Exception { + // Add additional tear down code here + } + + /** + * Launch the test. + * + * @param args the command line arguments + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(LoadedPolicyTest.class); + } +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/NotificationHandlerTest.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/NotificationHandlerTest.java new file mode 100644 index 000000000..fe6b53c0d --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/NotificationHandlerTest.java @@ -0,0 +1,73 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.test; + +import org.junit.*; +import org.openecomp.policy.api.NotificationHandler; + +import static org.junit.Assert.*; + +/** + * The class NotificationHandlerTest contains tests for the class {@link NotificationHandler}. + * + * @generatedBy CodePro at 6/1/16 1:41 PM + * @version $Revision: 1.0 $ + */ +public class NotificationHandlerTest { + /** + * Perform pre-test initialization. + * + * @throws Exception + * if the initialization fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Before + public void setUp() + throws Exception { + // add additional set up code here + } + + /** + * Perform post-test clean-up. + * + * @throws Exception + * if the clean-up fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @After + public void tearDown() + throws Exception { + // Add additional tear down code here + } + + /** + * Launch the test. + * + * @param args the command line arguments + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(NotificationHandlerTest.class); + } +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/NotificationSchemeTest.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/NotificationSchemeTest.java new file mode 100644 index 000000000..1cb105c2f --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/NotificationSchemeTest.java @@ -0,0 +1,91 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.test; + +import org.junit.*; +import org.openecomp.policy.api.NotificationScheme; + +import static org.junit.Assert.*; + +/** + * The class NotificationSchemeTest contains tests for the class {@link NotificationScheme}. + * + * @generatedBy CodePro at 6/1/16 1:40 PM + * @version $Revision: 1.0 $ + */ +public class NotificationSchemeTest { + /** + * Run the String toString() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testToString_1() + throws Exception { + NotificationScheme fixture = NotificationScheme.AUTO_ALL_NOTIFICATIONS; + + String result = fixture.toString(); + + // add additional test code here + assertEquals("auto_all_notifications", result); + } + + /** + * Perform pre-test initialization. + * + * @throws Exception + * if the initialization fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Before + public void setUp() + throws Exception { + // add additional set up code here + } + + /** + * Perform post-test clean-up. + * + * @throws Exception + * if the clean-up fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @After + public void tearDown() + throws Exception { + // Add additional tear down code here + } + + /** + * Launch the test. + * + * @param args the command line arguments + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(NotificationSchemeTest.class); + } +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/NotificationTypeTest.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/NotificationTypeTest.java new file mode 100644 index 000000000..95dce6a60 --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/NotificationTypeTest.java @@ -0,0 +1,91 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.test; + +import org.junit.*; +import org.openecomp.policy.api.NotificationType; + +import static org.junit.Assert.*; + +/** + * The class NotificationTypeTest contains tests for the class {@link NotificationType}. + * + * @generatedBy CodePro at 6/1/16 1:40 PM + * @version $Revision: 1.0 $ + */ +public class NotificationTypeTest { + /** + * Run the String toString() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testToString_1() + throws Exception { + NotificationType fixture = NotificationType.BOTH; + + String result = fixture.toString(); + + // add additional test code here + assertEquals("both", result); + } + + /** + * Perform pre-test initialization. + * + * @throws Exception + * if the initialization fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Before + public void setUp() + throws Exception { + // add additional set up code here + } + + /** + * Perform post-test clean-up. + * + * @throws Exception + * if the clean-up fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @After + public void tearDown() + throws Exception { + // Add additional tear down code here + } + + /** + * Launch the test. + * + * @param args the command line arguments + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(NotificationTypeTest.class); + } +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PDPNotificationTest.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PDPNotificationTest.java new file mode 100644 index 000000000..4a7cdf54c --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PDPNotificationTest.java @@ -0,0 +1,75 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.test; + +import java.util.Collection; + +import org.junit.*; +import org.openecomp.policy.api.PDPNotification; + +import static org.junit.Assert.*; + +/** + * The class PDPNotificationTest contains tests for the class {@link PDPNotification}. + * + * @generatedBy CodePro at 6/1/16 1:41 PM + * @version $Revision: 1.0 $ + */ +public class PDPNotificationTest { + /** + * Perform pre-test initialization. + * + * @throws Exception + * if the initialization fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Before + public void setUp() + throws Exception { + // add additional set up code here + } + + /** + * Perform post-test clean-up. + * + * @throws Exception + * if the clean-up fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @After + public void tearDown() + throws Exception { + // Add additional tear down code here + } + + /** + * Launch the test. + * + * @param args the command line arguments + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(PDPNotificationTest.class); + } +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyChangeResponseTest.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyChangeResponseTest.java new file mode 100644 index 000000000..2c8dc04fc --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyChangeResponseTest.java @@ -0,0 +1,73 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.test; + +import org.junit.*; +import org.openecomp.policy.api.PolicyChangeResponse; + +import static org.junit.Assert.*; + +/** + * The class PolicyChangeResponseTest contains tests for the class {@link PolicyChangeResponse}. + * + * @generatedBy CodePro at 6/1/16 1:41 PM + * @version $Revision: 1.0 $ + */ +public class PolicyChangeResponseTest { + /** + * Perform pre-test initialization. + * + * @throws Exception + * if the initialization fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Before + public void setUp() + throws Exception { + // add additional set up code here + } + + /** + * Perform post-test clean-up. + * + * @throws Exception + * if the clean-up fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @After + public void tearDown() + throws Exception { + // Add additional tear down code here + } + + /** + * Launch the test. + * + * @param args the command line arguments + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(PolicyChangeResponseTest.class); + } +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyClassTest.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyClassTest.java new file mode 100644 index 000000000..28e5beefd --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyClassTest.java @@ -0,0 +1,91 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.test; + +import org.junit.*; +import org.openecomp.policy.api.PolicyClass; + +import static org.junit.Assert.*; + +/** + * The class PolicyClassTest contains tests for the class {@link PolicyClass}. + * + * @generatedBy CodePro at 6/1/16 1:40 PM + * @version $Revision: 1.0 $ + */ +public class PolicyClassTest { + /** + * Run the String toString() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testToString_1() + throws Exception { + PolicyClass fixture = PolicyClass.Action; + + String result = fixture.toString(); + + // add additional test code here + assertEquals("Action", result); + } + + /** + * Perform pre-test initialization. + * + * @throws Exception + * if the initialization fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Before + public void setUp() + throws Exception { + // add additional set up code here + } + + /** + * Perform post-test clean-up. + * + * @throws Exception + * if the clean-up fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @After + public void tearDown() + throws Exception { + // Add additional tear down code here + } + + /** + * Launch the test. + * + * @param args the command line arguments + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(PolicyClassTest.class); + } +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyConfigExceptionTest.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyConfigExceptionTest.java new file mode 100644 index 000000000..4134eacc2 --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyConfigExceptionTest.java @@ -0,0 +1,183 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.test; + +import org.junit.*; +import org.openecomp.policy.api.PolicyConfigException; + +import static org.junit.Assert.*; + +/** + * The class PolicyConfigExceptionTest contains tests for the class {@link PolicyConfigException}. + * + * @generatedBy CodePro at 6/1/16 1:40 PM + * @version $Revision: 1.0 $ + */ +public class PolicyConfigExceptionTest { + /** + * Run the PolicyConfigException() constructor test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testPolicyConfigException_1() + throws Exception { + + PolicyConfigException result = new PolicyConfigException(); + + // add additional test code here + assertNotNull(result); + assertEquals(null, result.getCause()); + assertEquals("org.openecomp.policy.api.PolicyConfigException", result.toString()); + assertEquals(null, result.getLocalizedMessage()); + assertEquals(null, result.getMessage()); + } + + /** + * Run the PolicyConfigException(String) constructor test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testPolicyConfigException_2() + throws Exception { + String message = ""; + + PolicyConfigException result = new PolicyConfigException(message); + + // add additional test code here + assertNotNull(result); + assertEquals(null, result.getCause()); + assertEquals("org.openecomp.policy.api.PolicyConfigException: ", result.toString()); + assertEquals("", result.getLocalizedMessage()); + assertEquals("", result.getMessage()); + } + + /** + * Run the PolicyConfigException(Throwable) constructor test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testPolicyConfigException_3() + throws Exception { + Throwable cause = new Throwable(); + + PolicyConfigException result = new PolicyConfigException(cause); + + // add additional test code here + assertNotNull(result); + assertEquals("org.openecomp.policy.api.PolicyConfigException: java.lang.Throwable", result.toString()); + assertEquals("java.lang.Throwable", result.getLocalizedMessage()); + assertEquals("java.lang.Throwable", result.getMessage()); + } + + /** + * Run the PolicyConfigException(String,Throwable) constructor test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testPolicyConfigException_4() + throws Exception { + String message = ""; + Throwable cause = new Throwable(); + + PolicyConfigException result = new PolicyConfigException(message, cause); + + // add additional test code here + assertNotNull(result); + assertEquals("org.openecomp.policy.api.PolicyConfigException: ", result.toString()); + assertEquals("", result.getLocalizedMessage()); + assertEquals("", result.getMessage()); + } + + /** + * Run the PolicyConfigException(String,Throwable,boolean,boolean) constructor test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testPolicyConfigException_5() + throws Exception { + String message = ""; + Throwable cause = new Throwable(); + boolean enableSuppression = true; + boolean writableStackTrace = true; + + PolicyConfigException result = new PolicyConfigException(message, cause, enableSuppression, writableStackTrace); + + // add additional test code here + assertNotNull(result); + assertEquals("org.openecomp.policy.api.PolicyConfigException: ", result.toString()); + assertEquals("", result.getLocalizedMessage()); + assertEquals("", result.getMessage()); + } + + /** + * Perform pre-test initialization. + * + * @throws Exception + * if the initialization fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Before + public void setUp() + throws Exception { + // add additional set up code here + } + + /** + * Perform post-test clean-up. + * + * @throws Exception + * if the clean-up fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @After + public void tearDown() + throws Exception { + // Add additional tear down code here + } + + /** + * Launch the test. + * + * @param args the command line arguments + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(PolicyConfigExceptionTest.class); + } +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyConfigStatusTest.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyConfigStatusTest.java new file mode 100644 index 000000000..c40253890 --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyConfigStatusTest.java @@ -0,0 +1,133 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.test; + +import org.junit.*; +import org.openecomp.policy.api.PolicyConfigStatus; + +import static org.junit.Assert.*; + +/** + * The class PolicyConfigStatusTest contains tests for the class {@link PolicyConfigStatus}. + * + * @generatedBy CodePro at 6/1/16 1:41 PM + * @version $Revision: 1.0 $ + */ +public class PolicyConfigStatusTest { + /** + * Run the PolicyConfigStatus getStatus(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testGetStatus_1() + throws Exception { + String configStatus = ""; + + PolicyConfigStatus result = PolicyConfigStatus.getStatus(configStatus); + + // add additional test code here + assertNotNull(result); + assertEquals("not_found", result.toString()); + assertEquals("CONFIG_NOT_FOUND", result.name()); + assertEquals(1, result.ordinal()); + } + + /** + * Run the PolicyConfigStatus getStatus(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testGetStatus_2() + throws Exception { + String configStatus = ""; + + PolicyConfigStatus result = PolicyConfigStatus.getStatus(configStatus); + + // add additional test code here + assertNotNull(result); + assertEquals("not_found", result.toString()); + assertEquals("CONFIG_NOT_FOUND", result.name()); + assertEquals(1, result.ordinal()); + } + + /** + * Run the String toString() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testToString_1() + throws Exception { + PolicyConfigStatus fixture = PolicyConfigStatus.CONFIG_NOT_FOUND; + + String result = fixture.toString(); + + // add additional test code here + assertEquals("not_found", result); + } + + /** + * Perform pre-test initialization. + * + * @throws Exception + * if the initialization fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Before + public void setUp() + throws Exception { + // add additional set up code here + } + + /** + * Perform post-test clean-up. + * + * @throws Exception + * if the clean-up fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @After + public void tearDown() + throws Exception { + // Add additional tear down code here + } + + /** + * Launch the test. + * + * @param args the command line arguments + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(PolicyConfigStatusTest.class); + } +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyConfigTest.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyConfigTest.java new file mode 100644 index 000000000..cbe11f460 --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyConfigTest.java @@ -0,0 +1,80 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.test; + +import java.util.Map; +import java.util.Properties; + +import javax.json.JsonObject; + +import org.junit.*; +import org.openecomp.policy.api.PolicyConfig; + +import static org.junit.Assert.*; + +import org.w3c.dom.Document; + +/** + * The class PolicyConfigTest contains tests for the class {@link PolicyConfig}. + * + * @generatedBy CodePro at 6/1/16 1:41 PM + * @version $Revision: 1.0 $ + */ +public class PolicyConfigTest { + /** + * Perform pre-test initialization. + * + * @throws Exception + * if the initialization fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Before + public void setUp() + throws Exception { + // add additional set up code here + } + + /** + * Perform post-test clean-up. + * + * @throws Exception + * if the clean-up fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @After + public void tearDown() + throws Exception { + // Add additional tear down code here + } + + /** + * Launch the test. + * + * @param args the command line arguments + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(PolicyConfigTest.class); + } +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyConfigTypeTest.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyConfigTypeTest.java new file mode 100644 index 000000000..cd6c6a977 --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyConfigTypeTest.java @@ -0,0 +1,91 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.test; + +import org.junit.*; +import org.openecomp.policy.api.PolicyConfigType; + +import static org.junit.Assert.*; + +/** + * The class PolicyConfigTypeTest contains tests for the class {@link PolicyConfigType}. + * + * @generatedBy CodePro at 6/1/16 1:41 PM + * @version $Revision: 1.0 $ + */ +public class PolicyConfigTypeTest { + /** + * Run the String toString() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testToString_1() + throws Exception { + PolicyConfigType fixture = PolicyConfigType.BRMS_PARAM; + + String result = fixture.toString(); + + // add additional test code here + assertEquals("BRMS_Param", result); + } + + /** + * Perform pre-test initialization. + * + * @throws Exception + * if the initialization fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Before + public void setUp() + throws Exception { + // add additional set up code here + } + + /** + * Perform post-test clean-up. + * + * @throws Exception + * if the clean-up fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @After + public void tearDown() + throws Exception { + // Add additional tear down code here + } + + /** + * Launch the test. + * + * @param args the command line arguments + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(PolicyConfigTypeTest.class); + } +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyDecisionExceptionTest.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyDecisionExceptionTest.java new file mode 100644 index 000000000..95dfd7acd --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyDecisionExceptionTest.java @@ -0,0 +1,183 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.test; + +import org.junit.*; +import org.openecomp.policy.api.PolicyDecisionException; + +import static org.junit.Assert.*; + +/** + * The class PolicyDecisionExceptionTest contains tests for the class {@link PolicyDecisionException}. + * + * @generatedBy CodePro at 6/1/16 1:40 PM + * @version $Revision: 1.0 $ + */ +public class PolicyDecisionExceptionTest { + /** + * Run the PolicyDecisionException() constructor test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testPolicyDecisionException_1() + throws Exception { + + PolicyDecisionException result = new PolicyDecisionException(); + + // add additional test code here + assertNotNull(result); + assertEquals(null, result.getCause()); + assertEquals("org.openecomp.policy.api.PolicyDecisionException", result.toString()); + assertEquals(null, result.getLocalizedMessage()); + assertEquals(null, result.getMessage()); + } + + /** + * Run the PolicyDecisionException(String) constructor test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testPolicyDecisionException_2() + throws Exception { + String message = ""; + + PolicyDecisionException result = new PolicyDecisionException(message); + + // add additional test code here + assertNotNull(result); + assertEquals(null, result.getCause()); + assertEquals("org.openecomp.policy.api.PolicyDecisionException: ", result.toString()); + assertEquals("", result.getLocalizedMessage()); + assertEquals("", result.getMessage()); + } + + /** + * Run the PolicyDecisionException(Throwable) constructor test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testPolicyDecisionException_3() + throws Exception { + Throwable cause = new Throwable(); + + PolicyDecisionException result = new PolicyDecisionException(cause); + + // add additional test code here + assertNotNull(result); + assertEquals("org.openecomp.policy.api.PolicyDecisionException: java.lang.Throwable", result.toString()); + assertEquals("java.lang.Throwable", result.getLocalizedMessage()); + assertEquals("java.lang.Throwable", result.getMessage()); + } + + /** + * Run the PolicyDecisionException(String,Throwable) constructor test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testPolicyDecisionException_4() + throws Exception { + String message = ""; + Throwable cause = new Throwable(); + + PolicyDecisionException result = new PolicyDecisionException(message, cause); + + // add additional test code here + assertNotNull(result); + assertEquals("org.openecomp.policy.api.PolicyDecisionException: ", result.toString()); + assertEquals("", result.getLocalizedMessage()); + assertEquals("", result.getMessage()); + } + + /** + * Run the PolicyDecisionException(String,Throwable,boolean,boolean) constructor test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testPolicyDecisionException_5() + throws Exception { + String message = ""; + Throwable cause = new Throwable(); + boolean enableSuppression = true; + boolean writableStackTrace = true; + + PolicyDecisionException result = new PolicyDecisionException(message, cause, enableSuppression, writableStackTrace); + + // add additional test code here + assertNotNull(result); + assertEquals("org.openecomp.policy.api.PolicyDecisionException: ", result.toString()); + assertEquals("", result.getLocalizedMessage()); + assertEquals("", result.getMessage()); + } + + /** + * Perform pre-test initialization. + * + * @throws Exception + * if the initialization fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Before + public void setUp() + throws Exception { + // add additional set up code here + } + + /** + * Perform post-test clean-up. + * + * @throws Exception + * if the clean-up fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @After + public void tearDown() + throws Exception { + // Add additional tear down code here + } + + /** + * Launch the test. + * + * @param args the command line arguments + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(PolicyDecisionExceptionTest.class); + } +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyDecisionTest.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyDecisionTest.java new file mode 100644 index 000000000..12069abeb --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyDecisionTest.java @@ -0,0 +1,91 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.test; + +import org.junit.*; +import org.openecomp.policy.api.PolicyDecision; + +import static org.junit.Assert.*; + +/** + * The class PolicyDecisionTest contains tests for the class {@link PolicyDecision}. + * + * @generatedBy CodePro at 6/1/16 1:41 PM + * @version $Revision: 1.0 $ + */ +public class PolicyDecisionTest { + /** + * Run the String toString() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testToString_1() + throws Exception { + PolicyDecision fixture = PolicyDecision.DENY; + + String result = fixture.toString(); + + // add additional test code here + assertEquals("deny", result); + } + + /** + * Perform pre-test initialization. + * + * @throws Exception + * if the initialization fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Before + public void setUp() + throws Exception { + // add additional set up code here + } + + /** + * Perform post-test clean-up. + * + * @throws Exception + * if the clean-up fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @After + public void tearDown() + throws Exception { + // Add additional tear down code here + } + + /** + * Launch the test. + * + * @param args the command line arguments + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(PolicyDecisionTest.class); + } +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyEngineExceptionTest.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyEngineExceptionTest.java new file mode 100644 index 000000000..d21fb12e2 --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyEngineExceptionTest.java @@ -0,0 +1,183 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.test; + +import org.junit.*; +import org.openecomp.policy.api.PolicyEngineException; + +import static org.junit.Assert.*; + +/** + * The class PolicyEngineExceptionTest contains tests for the class {@link PolicyEngineException}. + * + * @generatedBy CodePro at 6/1/16 1:41 PM + * @version $Revision: 1.0 $ + */ +public class PolicyEngineExceptionTest { + /** + * Run the PolicyEngineException() constructor test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testPolicyEngineException_1() + throws Exception { + + PolicyEngineException result = new PolicyEngineException(); + + // add additional test code here + assertNotNull(result); + assertEquals(null, result.getCause()); + assertEquals("org.openecomp.policy.api.PolicyEngineException", result.toString()); + assertEquals(null, result.getLocalizedMessage()); + assertEquals(null, result.getMessage()); + } + + /** + * Run the PolicyEngineException(String) constructor test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testPolicyEngineException_2() + throws Exception { + String message = ""; + + PolicyEngineException result = new PolicyEngineException(message); + + // add additional test code here + assertNotNull(result); + assertEquals(null, result.getCause()); + assertEquals("org.openecomp.policy.api.PolicyEngineException: ", result.toString()); + assertEquals("", result.getLocalizedMessage()); + assertEquals("", result.getMessage()); + } + + /** + * Run the PolicyEngineException(Throwable) constructor test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testPolicyEngineException_3() + throws Exception { + Throwable cause = new Throwable(); + + PolicyEngineException result = new PolicyEngineException(cause); + + // add additional test code here + assertNotNull(result); + assertEquals("org.openecomp.policy.api.PolicyEngineException: java.lang.Throwable", result.toString()); + assertEquals("java.lang.Throwable", result.getLocalizedMessage()); + assertEquals("java.lang.Throwable", result.getMessage()); + } + + /** + * Run the PolicyEngineException(String,Throwable) constructor test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testPolicyEngineException_4() + throws Exception { + String message = ""; + Throwable cause = new Throwable(); + + PolicyEngineException result = new PolicyEngineException(message, cause); + + // add additional test code here + assertNotNull(result); + assertEquals("org.openecomp.policy.api.PolicyEngineException: ", result.toString()); + assertEquals("", result.getLocalizedMessage()); + assertEquals("", result.getMessage()); + } + + /** + * Run the PolicyEngineException(String,Throwable,boolean,boolean) constructor test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testPolicyEngineException_5() + throws Exception { + String message = ""; + Throwable cause = new Throwable(); + boolean enableSuppression = true; + boolean writableStackTrace = true; + + PolicyEngineException result = new PolicyEngineException(message, cause, enableSuppression, writableStackTrace); + + // add additional test code here + assertNotNull(result); + assertEquals("org.openecomp.policy.api.PolicyEngineException: ", result.toString()); + assertEquals("", result.getLocalizedMessage()); + assertEquals("", result.getMessage()); + } + + /** + * Perform pre-test initialization. + * + * @throws Exception + * if the initialization fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Before + public void setUp() + throws Exception { + // add additional set up code here + } + + /** + * Perform post-test clean-up. + * + * @throws Exception + * if the clean-up fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @After + public void tearDown() + throws Exception { + // Add additional tear down code here + } + + /** + * Launch the test. + * + * @param args the command line arguments + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(PolicyEngineExceptionTest.class); + } +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyEngineInterfaceTest.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyEngineInterfaceTest.java new file mode 100644 index 000000000..51a3c20f8 --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyEngineInterfaceTest.java @@ -0,0 +1,672 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.test; + +import java.io.StringReader; +import java.net.HttpURLConnection; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import javax.json.Json; +import javax.json.JsonObject; +import javax.json.JsonReader; + +import junit.framework.TestCase; + +import org.mockito.Mockito; +import org.openecomp.policy.api.AttributeType; +import org.openecomp.policy.api.ConfigRequestParameters; +import org.openecomp.policy.api.DecisionRequestParameters; +import org.openecomp.policy.api.DecisionResponse; +import org.openecomp.policy.api.DeletePolicyCondition; +import org.openecomp.policy.api.DeletePolicyParameters; +import org.openecomp.policy.api.EventRequestParameters; +import org.openecomp.policy.api.ImportParameters; +import org.openecomp.policy.api.NotificationHandler; +import org.openecomp.policy.api.NotificationScheme; +import org.openecomp.policy.api.PDPNotification; +import org.openecomp.policy.api.PolicyChangeResponse; +import org.openecomp.policy.api.PolicyClass; +import org.openecomp.policy.api.PolicyConfig; +import org.openecomp.policy.api.PolicyConfigException; +import org.openecomp.policy.api.PolicyDecision; +import org.openecomp.policy.api.PolicyDecisionException; +import org.openecomp.policy.api.PolicyEngine; +import org.openecomp.policy.api.PolicyEngineException; +import org.openecomp.policy.api.PolicyEventException; +import org.openecomp.policy.api.PolicyParameters; +import org.openecomp.policy.api.PolicyResponse; +import org.openecomp.policy.api.PushPolicyParameters; +import org.openecomp.policy.api.ImportParameters.IMPORT_TYPE; +import org.openecomp.policy.std.StdPDPNotification; +import org.openecomp.policy.std.StdPolicyChangeResponse; +import org.openecomp.policy.std.StdPolicyEngine; +import org.openecomp.policy.std.StdPolicyResponse; + +import org.openecomp.policy.xacml.std.pap.StdPAPPolicy; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +/** + * The class PolicyEngineInterfaceTest contains tests for the + * class {@link PolicyEngine} + * + * @pattern JUnit Test Case + * + * @generatedBy CodePro at 5/27/16 10:33 AM + * + * + * @version $Revision$ + */ +public class PolicyEngineInterfaceTest extends TestCase { + + private static final Logger logger = FlexLogger.getLogger(PolicyEngineInterfaceTest.class); + + private PolicyEngine policyEngine = null; + private StdPolicyEngine stdPolicyEngine = null; + private PolicyEngine mockPolicyEngine = null; + private Collection policyConfig = null; + private UUID requestID = UUID.randomUUID(); + + + PolicyChangeResponse result = null; + StdPolicyChangeResponse response = new StdPolicyChangeResponse(); + + + /** + * Construct new test instance + * + * @param name the test name + */ + public PolicyEngineInterfaceTest(String name) { + super(name); + } + + /** + * Perform pre-test initialization + * + * @throws Exception + * + * @see TestCase#setUp() + */ + protected void setUp() throws Exception { + try { + policyEngine = new PolicyEngine("Test/config_pass.properties"); + } catch (PolicyEngineException e) { + logger.error(e.getMessage()); + fail("PolicyEngine Instantiation Error" + e); + } + logger.info("Loaded.. PolicyEngine"); + + mockPolicyEngine = Mockito.mock(PolicyEngine.class); + HttpURLConnection conn = Mockito.mock(HttpURLConnection.class); + Mockito.when(conn.getResponseCode()).thenReturn(HttpURLConnection.HTTP_OK); + + } + + /** + * Perform post-test clean up + * + * @throws Exception + * + * @see TestCase#tearDown() + */ + protected void tearDown() throws Exception { + super.tearDown(); + // Add additional tear down code here + } + + /** + * Run the Collection getConfigByPolicyName(String) method + * test + */ + public void testGetConfigByPolicyName() { + String policyName = null; + try{ + policyConfig = policyEngine.getConfigByPolicyName(policyName); + } catch (PolicyConfigException e){ + logger.warn(e.getMessage()); + } + assertNull(policyConfig); + } + + public void testGetConfigByPolicyName2() { + String policyName = null; + + try{ + policyConfig = policyEngine.getConfigByPolicyName(policyName, requestID); + } catch (PolicyConfigException e){ + logger.warn(e.getMessage()); + } + assertNull(policyConfig); + } + + /** + * Run the Collection getConfig(String) method test + */ + public void testGetConfig() { + String ecompName = null; + + try{ + policyConfig = policyEngine.getConfig(ecompName); + } catch (PolicyConfigException e){ + logger.warn(e.getMessage()); + } + assertNull(policyConfig); + } + + public void testGetConfig2() { + String ecompName = null; + + try{ + policyConfig = policyEngine.getConfig(ecompName,requestID); + } catch (PolicyConfigException e){ + logger.warn(e.getMessage()); + } + assertNull(policyConfig); + } + + + public void testGetConfig3() { + String ecompName = null; + String configName = null; + + try{ + policyConfig = policyEngine.getConfig(ecompName,configName,requestID); + } catch (PolicyConfigException e){ + logger.warn(e.getMessage()); + } + assertNull(policyConfig); + } + + public void testGetConfig4() { + String ecompName = null; + String configName = null; + Map configAttributes = null; + + try{ + policyConfig = policyEngine.getConfig(ecompName,configName,configAttributes); + } catch (PolicyConfigException e){ + logger.warn(e.getMessage()); + } + assertNull(policyConfig); + } + + public void testGetConfig5() { + String ecompName = null; + String configName = null; + Map configAttributes = null; + + try{ + policyConfig = policyEngine.getConfig(ecompName,configName,configAttributes,requestID); + } catch (PolicyConfigException e){ + logger.warn(e.getMessage()); + } + assertNull(policyConfig); + } + + public void testGetConfig6() { + ConfigRequestParameters parameters = new ConfigRequestParameters(); + + try{ + policyConfig = policyEngine.getConfig(parameters); + } catch (PolicyConfigException e){ + logger.warn(e.getMessage()); + } + assertNull(policyConfig); + } + + + /** + * Run the Collection sendEvent(Map) method + * test + */ + public void testSendEvent() + { + Collection result = null; + Collection response = null; + Map eventAttributes = null; + + try { + Mockito.when(mockPolicyEngine.sendEvent(eventAttributes)).thenReturn(result); + result = mockPolicyEngine.sendEvent(eventAttributes); + } catch (PolicyEventException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + + assertEquals(result,response); + + } + + public void testSendEvent2() + { + Collection result = null; + Collection response = null; + Map eventAttributes = null; + + try { + Mockito.when(mockPolicyEngine.sendEvent(eventAttributes,requestID)).thenReturn(result); + result = mockPolicyEngine.sendEvent(eventAttributes,requestID); + } catch (PolicyEventException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + + assertEquals(result,response); + + } + + public void testSendEvent3() + { + Collection result = null; + Collection response = null; + EventRequestParameters parameters = new EventRequestParameters(); + + try { + Mockito.when(mockPolicyEngine.sendEvent(parameters)).thenReturn(result); + result = mockPolicyEngine.sendEvent(parameters); + } catch (PolicyEventException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + assertEquals(result,response); + + } + + + + /** + * Run the PolicyDecision getDecision(String, Map) method + * test + */ + public void testGetDecision() + { + String eCOMPComponentName = null; + Map decisionAttributes = null; + + DecisionResponse result = null; + + try { + Mockito.when(mockPolicyEngine.getDecision(eCOMPComponentName,decisionAttributes)).thenReturn(null); + result = mockPolicyEngine.getDecision(eCOMPComponentName,decisionAttributes); + } catch (PolicyDecisionException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + assertEquals(result,null); + } + + public void testGetDecision2() + { + String eCOMPComponentName = null; + Map decisionAttributes = null; + + DecisionResponse result = null; + + try { + Mockito.when(mockPolicyEngine.getDecision(eCOMPComponentName,decisionAttributes,requestID)).thenReturn(null); + result = mockPolicyEngine.getDecision(eCOMPComponentName,decisionAttributes); + } catch (PolicyDecisionException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + assertEquals(result,null); + } + + public void testGetDecision3() + { + DecisionRequestParameters parameters = new DecisionRequestParameters(); + DecisionResponse result = null; + + try { + Mockito.when(mockPolicyEngine.getDecision(parameters)).thenReturn(null); + result = mockPolicyEngine.getDecision(parameters); + } catch (PolicyDecisionException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + assertEquals(result,null); + } + + /** + * Run the void setNotification(NotificationScheme, NotificationHandler) + * method test + */ + public void testSetNotification() { + // add test code here + + NotificationScheme scheme = null; + NotificationHandler handler = null; + + Mockito.doNothing().when(mockPolicyEngine).setNotification(scheme, handler); + mockPolicyEngine.setNotification(scheme, handler); + //assertTrue(true); + } + + /** + * Run the void clearNotification() method test + */ + public void testClearNotification() { + // add test code here + + Mockito.doNothing().when(mockPolicyEngine).clearNotification(); + mockPolicyEngine.clearNotification(); + //assertTrue(true); + } + + /** + * Run the void setScheme(NotificationScheme) method test + */ + public void testSetScheme() { + NotificationScheme scheme = null; + + Mockito.doNothing().when(mockPolicyEngine).setScheme(scheme); + mockPolicyEngine.setScheme(scheme); + //assertTrue(true); + } + + /** + * Run the PDPNotification getNotification() method test + */ + public void testGetNotification() { + PDPNotification result = null; + StdPDPNotification response = null; + Mockito.when(mockPolicyEngine.getNotification()).thenReturn(response); + result = mockPolicyEngine.getNotification(); + + assertEquals(result,response); + } + + /** + * Run the String createConfigPolicy(String, String, String, String, + * Map, String, String, String, UUID) method test + */ + @SuppressWarnings("deprecation") + public void testCreateConfigPolicy() + { + String response = "success"; + String result = null; + try { + + Mockito.when(mockPolicyEngine.createConfigPolicy("testPolicy","test","test","testConfig",null,"OTHER","test","test",null, null, null, null, null)).thenReturn(response); + result = mockPolicyEngine.createConfigPolicy("testPolicy","test","test","testConfig",null,"OTHER","test","test",null, null, null, null, null); + + } catch (Exception e) { + logger.warn(e.getMessage()); + } + assertEquals(result, response); + } + + /** + * Run the String updateConfigPolicy(String, String, String, String, + * Map, String, String, String, UUID) method test + */ + @SuppressWarnings("deprecation") + public void testUpdateConfigPolicy() + { + String response = "success"; + String result = null; + try { + + Mockito.when(mockPolicyEngine.updateConfigPolicy("testPolicy","test","test","testConfig",null,"OTHER","test","test",null, null, null, null, null)).thenReturn(response); + result = mockPolicyEngine.updateConfigPolicy("testPolicy","test","test","testConfig",null,"OTHER","test","test",null, null, null, null, null); + + } catch (Exception e) { + logger.warn(e.getMessage()); + } + assertEquals(result, response); + } + + /** + * Run the String createConfigFirewallPolicy(String, JsonObject, String, + * UUID) method test + */ + @SuppressWarnings("deprecation") + public void testCreateConfigFirewallPolicy() { + String response = "success"; + String result = null; + String json = "{\"serviceTypeId\":\"/v0/firewall/pan\",\"configName\":\"rule1607\",\"deploymentOption\":{\"deployNow\":false},\"securityZoneId\":\"/v0/firewall/pan\",\"serviceGroups\":[{\"name\":\"1607Group\",\"description\":null,\"members\":[{\"type\":\"REFERENCE\",\"name\":\"SList\"},{\"type\":\"REFERENCE\",\"name\":\"Syslog\"}]},{\"name\":\"Syslog\",\"description\":\"NA\",\"type\":\"SERVICE\",\"transportProtocol\":\"udp\",\"appProtocol\":null,\"ports\":\"514\"},{\"name\":\"SList\",\"description\":\"Service List\",\"type\":\"SERVICE\",\"transportProtocol\":\"tcp\",\"appProtocol\":null,\"ports\":\"8080\"}],\"addressGroups\":[{\"name\":\"1607Group\",\"description\":null,\"members\":[{\"type\":\"SUBNET\",\"value\":\"10.11.12.13/14\"},{\"type\":\"SUBNET\",\"value\":\"10.11.12.13/14\"}]},{\"name\":\"PL_CCE3\",\"description\":\"CCE Routers\",\"members\":[{\"type\":\"SUBNET\",\"value\":\"10.11.12.13/14\"}]}],\"firewallRuleList\":[{\"position\":\"1\",\"ruleName\":\"1607Rule\",\"fromZones\":[\"Trusted\"],\"toZones\":[\"Untrusted\"],\"negateSource\":false,\"negateDestination\":false,\"sourceList\":[{\"type\":\"REFERENCE\",\"value\":\"PL_CCE3\"},{\"type\":\"REFERENCE\",\"value\":\"1607Group\"}],\"destinationList\":[{\"type\":\"REFERENCE\",\"value\":\"1607Group\"}],\"sourceServices\":[],\"destServices\":[{\"type\":\"REFERENCE\",\"name\":\"1607Group\"}],\"action\":\"accept\",\"description\":\"Rule for 1607 templates\",\"enabled\":true,\"log\":true}]}"; + JsonObject jsonObj = buildJSON(json); + try { + + Mockito.when(mockPolicyEngine.createConfigFirewallPolicy("testPolicy",jsonObj, "test", null, null, null, null, null)).thenReturn(response); + result = mockPolicyEngine.createConfigFirewallPolicy("testPolicy",jsonObj, "test", null, null, null, null, null); + + } catch (Exception e) { + logger.warn(e.getMessage()); + } + assertEquals(result, response); + } + + /** + * Run the String updateConfigFirewallPolicy(String, JsonObject, String, + * UUID) method test + */ + @SuppressWarnings("deprecation") + public void testUpdateConfigFirewallPolicy() { + String response = "success"; + String result = null; + String json = "{\"serviceTypeId\":\"/v0/firewall/pan\",\"configName\":\"rule1607\",\"deploymentOption\":{\"deployNow\":false},\"securityZoneId\":\"/v0/firewall/pan\",\"serviceGroups\":[{\"name\":\"1607Group\",\"description\":null,\"members\":[{\"type\":\"REFERENCE\",\"name\":\"SList\"},{\"type\":\"REFERENCE\",\"name\":\"Syslog\"}]},{\"name\":\"Syslog\",\"description\":\"NA\",\"type\":\"SERVICE\",\"transportProtocol\":\"udp\",\"appProtocol\":null,\"ports\":\"514\"},{\"name\":\"SList\",\"description\":\"Service List\",\"type\":\"SERVICE\",\"transportProtocol\":\"tcp\",\"appProtocol\":null,\"ports\":\"8080\"}],\"addressGroups\":[{\"name\":\"1607Group\",\"description\":null,\"members\":[{\"type\":\"SUBNET\",\"value\":\"10.11.12.13/14\"},{\"type\":\"SUBNET\",\"value\":\"10.11.12.13/14\"}]},{\"name\":\"PL_CCE3\",\"description\":\"CCE Routers\",\"members\":[{\"type\":\"SUBNET\",\"value\":\"10.11.12.13/14\"}]}],\"firewallRuleList\":[{\"position\":\"1\",\"ruleName\":\"1607Rule\",\"fromZones\":[\"Trusted\"],\"toZones\":[\"Untrusted\"],\"negateSource\":false,\"negateDestination\":false,\"sourceList\":[{\"type\":\"REFERENCE\",\"value\":\"PL_CCE3\"},{\"type\":\"REFERENCE\",\"value\":\"1607Group\"}],\"destinationList\":[{\"type\":\"REFERENCE\",\"value\":\"1607Group\"}],\"sourceServices\":[],\"destServices\":[{\"type\":\"REFERENCE\",\"name\":\"1607Group\"}],\"action\":\"accept\",\"description\":\"Rule for 1607 templates\",\"enabled\":true,\"log\":true}]}"; + JsonObject jsonObj = buildJSON(json); + try { + + Mockito.when(mockPolicyEngine.updateConfigFirewallPolicy("testPolicy",jsonObj, "test", null, null, null, null, null)).thenReturn(response); + result = mockPolicyEngine.updateConfigFirewallPolicy("testPolicy",jsonObj, "test", null, null, null, null, null); + + } catch (Exception e) { + logger.warn(e.getMessage()); + } + assertEquals(result, response); + } + + /** + * Run the PolicyChangeResponse createPolicy(PolicyParameters) method test + */ + public void testCreatePolicy() { + response.setResponseMessage("success"); + String callPapResponse = "success"; + PolicyChangeResponse result = null; + PolicyParameters policyParameters = new PolicyParameters(); + StdPAPPolicy newPAPPolicy = null; + + policyParameters.setPolicyClass(PolicyClass.Action); //required + policyParameters.setPolicyName("test.junitTest"); //required + policyParameters.setPolicyDescription("testing"); //optional + + //Set the Component Attributes... These are Optional + Map configAttributes = new HashMap(); + configAttributes.put("test", "testing"); + + Map> attributes = new HashMap>(); + attributes.put(AttributeType.MATCHING, configAttributes); + policyParameters.setAttributes(attributes); + + policyParameters.setActionPerformer("PEP"); + policyParameters.setActionAttribute("testing"); + policyParameters.setRequestID(UUID.randomUUID()); + + try { + + //stdPolicyEngine = Mockito.mock(StdPolicyEngine.class); + //Mockito.when(stdPolicyEngine.callPAP(newPAPPolicy, new String[] {"operation=create", "apiflag=api", "policyType=Action"}, null, "Action")).thenReturn(callPapResponse); + Mockito.when(mockPolicyEngine.createPolicy(policyParameters)).thenReturn(response); + result = mockPolicyEngine.createPolicy(policyParameters); + + } catch (Exception e) { + logger.warn(e.getMessage()); + e.printStackTrace(); + } + assertEquals(result, response); + } + + /** + * Run the PolicyChangeResponse updatePolicy(PolicyParameters) method test + */ + public void testUpdatePolicy() { + response.setResponseMessage("success"); + PolicyChangeResponse result = null; + PolicyParameters policyParameters = new PolicyParameters(); + + policyParameters.setPolicyClass(PolicyClass.Action); //required + policyParameters.setPolicyName("test.junitTest"); //required + policyParameters.setPolicyDescription("testing"); //optional + + //Set the Component Attributes... These are Optional + Map configAttributes = new HashMap(); + configAttributes.put("test", "testing"); + + Map> attributes = new HashMap>(); + attributes.put(AttributeType.MATCHING, configAttributes); + policyParameters.setAttributes(attributes); + + policyParameters.setActionPerformer("PEP"); + policyParameters.setActionAttribute("testing"); + policyParameters.setRequestID(UUID.randomUUID()); + + try { + + Mockito.when(mockPolicyEngine.updatePolicy(policyParameters)).thenReturn(response); + result = mockPolicyEngine.updatePolicy(policyParameters); + + } catch (Exception e) { + logger.warn(e.getMessage()); + } + assertEquals(result, response); + } + + /** + * Run the String pushPolicy(String, String, String, String, UUID) method + * test + */ + public void testPushPolicy() { + String response = "Success"; + String result = null; + try { + + Mockito.when(mockPolicyEngine.pushPolicy("testing","test","Base","default",requestID)).thenReturn(response); + result = mockPolicyEngine.pushPolicy("testing","test","Base","default",requestID); + + } catch (Exception e) { + logger.warn(e.getMessage()); + } + + assertEquals(result, response); + } + + public void testPushPolicy2() { + PushPolicyParameters policyParameters = new PushPolicyParameters(); + PolicyChangeResponse result = null; + + //String policyScope = null; + policyParameters.setPolicyName("test.junitTest"); + policyParameters.setPolicyType("Action"); + policyParameters.setPdpGroup("Default"); + + try { + + Mockito.when(mockPolicyEngine.pushPolicy(policyParameters)).thenReturn(response); + result = mockPolicyEngine.pushPolicy(policyParameters); + + } catch (Exception e) { + logger.warn(e.getMessage()); + } + + assertEquals(result, response); + } + + /** + * Run the PolicyChangeResponse deletePolicy(DeletePolicyParameters) method + * test + */ + public void testDeletePolicy() { + DeletePolicyParameters policyParameters = new DeletePolicyParameters(); + PolicyChangeResponse result = null; + + //String policyScope = null; + policyParameters.setPolicyName("test.junitTest.1.xml"); + policyParameters.setDeleteCondition(DeletePolicyCondition.ALL); + policyParameters.setPolicyComponent("PAP"); + policyParameters.setPdpGroup("Default"); + + try { + + Mockito.when(mockPolicyEngine.deletePolicy(policyParameters)).thenReturn(response); + result = mockPolicyEngine.deletePolicy(policyParameters); + + } catch (Exception e) { + logger.warn(e.getMessage()); + } + + assertEquals(result, response); + } + + /** + * Run the PolicyChangeResponse policyEngineImport(ImportParameters) method + * test + */ + public void testPolicyEngineImport() { + ImportParameters importParameters = new ImportParameters(); + PolicyChangeResponse result = null; + + importParameters.setFilePath("C:\\Workspaces\\models\\TestingModel\\ControllerServiceSampleSdnlServiceInstance-v0.1.0-SNAPSHOT.zip"); + importParameters.setServiceName("ControllerServiceSampleSdnlServiceInstance"); + + importParameters.setRequestID(UUID.randomUUID()); + importParameters.setServiceType(IMPORT_TYPE.MICROSERVICE); + importParameters.setVersion("1607-2"); + + + try { + + Mockito.when(mockPolicyEngine.policyEngineImport(importParameters)).thenReturn(response); + result = mockPolicyEngine.policyEngineImport(importParameters); + + } catch (Exception e) { + logger.warn(e.getMessage()); + } + + assertEquals(result, response); + } + + private static JsonObject buildJSON(String jsonString) { + JsonObject json = null;; + if (jsonString != null) { + StringReader in = null; + + in = new StringReader(jsonString); + + JsonReader jsonReader = Json.createReader(in); + json = jsonReader.readObject(); + } + + return json; + } +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyEngineTest.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyEngineTest.java new file mode 100644 index 000000000..e2d7c7879 --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyEngineTest.java @@ -0,0 +1,172 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.test; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.Test; +import org.openecomp.policy.api.NotificationScheme; +import org.openecomp.policy.api.PolicyEngine; +import org.openecomp.policy.api.PolicyEngineException; + +import org.openecomp.policy.common.logging.flexlogger.*; + +public class PolicyEngineTest { + + private static final Logger logger = FlexLogger.getLogger(PolicyEngineTest.class); + private PolicyEngine policyEngine = null; + private String filePath = null; + + @Test + public void testPolicyEngineForFail() { + filePath = null; + try { + policyEngine = new PolicyEngine(filePath); + } catch (PolicyEngineException e) { + logger.warn(e.getMessage()); + } + assertNull(policyEngine); + // Test even for this case. + filePath = "NotNull"; + try { + policyEngine = new PolicyEngine(filePath); + } catch (PolicyEngineException e) { + logger.warn(e.getMessage()); + } + assertNull(policyEngine); + } + + @Test + public void testPolicyEngineforPropertyFileError() { + filePath = "Test/config_error.property"; + isFileAvailable(filePath); + try { + policyEngine = new PolicyEngine(filePath); + } catch (PolicyEngineException e) { + logger.warn(e.getMessage()); + } + assertNull(policyEngine); + } + + @Test + public void testPolicyEngineforPDPURLError() { + String filePath = "Test/config_fail.properties"; + isFileAvailable(filePath); + try { + policyEngine = new PolicyEngine(filePath); + } catch (PolicyEngineException e) { + logger.warn(e.getMessage()); + } + assertNull(policyEngine); + } + + @Test + public void testPolicyEngineForPass() { + String filePath = "Test/config_pass.properties"; + isFileAvailable(filePath); + try { + policyEngine = new PolicyEngine(filePath); + } catch (PolicyEngineException e) { + logger.warn(e.getMessage()); + } + assertNotNull(policyEngine); + } + + @Test + public void testPolicyEngineForUEBPass() { + String filePath = "Test/config_UEB_pass.properties"; + isFileAvailable(filePath); + try { + policyEngine = new PolicyEngine(filePath); + } catch (PolicyEngineException e) { + logger.warn(e.getMessage()); + } + assertNotNull(policyEngine); + } + + + @Test + public void testPolicyEngineForUEBBadType() { + String filePath = "Test/config_UEB_bad_type.properties"; + isFileAvailable(filePath); + try { + policyEngine = new PolicyEngine(filePath); + } catch (PolicyEngineException e) { + logger.warn(e.getMessage()); + } + assertNotNull(policyEngine); + } + + @Test + public void testPolicyEngineForUEBBadServerType() { + String filePath = "Test/config_UEB_badservers.properties"; + isFileAvailable(filePath); + try { + policyEngine = new PolicyEngine(filePath); + } catch (PolicyEngineException e) { + logger.warn(e.getMessage()); + } + assertNotNull(policyEngine); + } + + @Test + public void testPolicyEngineNotficationAutoUEB() { + String filePath = "Test/config_UEB_pass.properties"; + isFileAvailable(filePath); + try { + policyEngine = new PolicyEngine(filePath); + policyEngine.setScheme(NotificationScheme.AUTO_ALL_NOTIFICATIONS); + } catch (PolicyEngineException e) { + logger.warn(e.getMessage()); + } + assertNotNull(policyEngine); + } + + @Test + public void testPolicyEngineNotficationAuto() { + String filePath = "Test/config_pass.properties"; + isFileAvailable(filePath); + try { + policyEngine = new PolicyEngine(filePath); + policyEngine.setScheme(NotificationScheme.AUTO_ALL_NOTIFICATIONS); + //policyEngine.getNotification(); + } catch (PolicyEngineException e) { + logger.warn(e.getMessage()); + } + assertNotNull(policyEngine); + } + + public void isFileAvailable(String filePath) { + Path file = Paths.get(filePath); + if (Files.notExists(file)) { + logger.error("File Doesn't Exist "+ file.toString()); + fail("File: " +filePath + " Not found"); + } + } +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyEventExceptionTest.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyEventExceptionTest.java new file mode 100644 index 000000000..fa8d5d1d8 --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyEventExceptionTest.java @@ -0,0 +1,183 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.test; + +import org.junit.*; +import org.openecomp.policy.api.PolicyEventException; + +import static org.junit.Assert.*; + +/** + * The class PolicyEventExceptionTest contains tests for the class {@link PolicyEventException}. + * + * @generatedBy CodePro at 6/1/16 1:40 PM + * @version $Revision: 1.0 $ + */ +public class PolicyEventExceptionTest { + /** + * Run the PolicyEventException() constructor test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testPolicyEventException_1() + throws Exception { + + PolicyEventException result = new PolicyEventException(); + + // add additional test code here + assertNotNull(result); + assertEquals(null, result.getCause()); + assertEquals("org.openecomp.policy.api.PolicyEventException", result.toString()); + assertEquals(null, result.getLocalizedMessage()); + assertEquals(null, result.getMessage()); + } + + /** + * Run the PolicyEventException(String) constructor test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testPolicyEventException_2() + throws Exception { + String message = ""; + + PolicyEventException result = new PolicyEventException(message); + + // add additional test code here + assertNotNull(result); + assertEquals(null, result.getCause()); + assertEquals("org.openecomp.policy.api.PolicyEventException: ", result.toString()); + assertEquals("", result.getLocalizedMessage()); + assertEquals("", result.getMessage()); + } + + /** + * Run the PolicyEventException(Throwable) constructor test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testPolicyEventException_3() + throws Exception { + Throwable cause = new Throwable(); + + PolicyEventException result = new PolicyEventException(cause); + + // add additional test code here + assertNotNull(result); + assertEquals("org.openecomp.policy.api.PolicyEventException: java.lang.Throwable", result.toString()); + assertEquals("java.lang.Throwable", result.getLocalizedMessage()); + assertEquals("java.lang.Throwable", result.getMessage()); + } + + /** + * Run the PolicyEventException(String,Throwable) constructor test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testPolicyEventException_4() + throws Exception { + String message = ""; + Throwable cause = new Throwable(); + + PolicyEventException result = new PolicyEventException(message, cause); + + // add additional test code here + assertNotNull(result); + assertEquals("org.openecomp.policy.api.PolicyEventException: ", result.toString()); + assertEquals("", result.getLocalizedMessage()); + assertEquals("", result.getMessage()); + } + + /** + * Run the PolicyEventException(String,Throwable,boolean,boolean) constructor test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testPolicyEventException_5() + throws Exception { + String message = ""; + Throwable cause = new Throwable(); + boolean enableSuppression = true; + boolean writableStackTrace = true; + + PolicyEventException result = new PolicyEventException(message, cause, enableSuppression, writableStackTrace); + + // add additional test code here + assertNotNull(result); + assertEquals("org.openecomp.policy.api.PolicyEventException: ", result.toString()); + assertEquals("", result.getLocalizedMessage()); + assertEquals("", result.getMessage()); + } + + /** + * Perform pre-test initialization. + * + * @throws Exception + * if the initialization fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Before + public void setUp() + throws Exception { + // add additional set up code here + } + + /** + * Perform post-test clean-up. + * + * @throws Exception + * if the clean-up fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @After + public void tearDown() + throws Exception { + // Add additional tear down code here + } + + /** + * Launch the test. + * + * @param args the command line arguments + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(PolicyEventExceptionTest.class); + } +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyParametersTest.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyParametersTest.java new file mode 100644 index 000000000..ca272c786 --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyParametersTest.java @@ -0,0 +1,1406 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.test; + +import java.util.Hashtable; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.junit.*; +import org.openecomp.policy.api.AttributeType; +import org.openecomp.policy.api.PolicyClass; +import org.openecomp.policy.api.PolicyConfigType; +import org.openecomp.policy.api.PolicyParameters; +import org.openecomp.policy.api.PolicyType; + +import static org.junit.Assert.*; + +/** + * The class PolicyParametersTest contains tests for the class {@link PolicyParameters}. + * + * @generatedBy CodePro at 6/1/16 1:41 PM + * @version $Revision: 1.0 $ + */ +public class PolicyParametersTest { + /** + * Run the String getActionAttribute() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testGetActionAttribute_1() + throws Exception { + PolicyParameters fixture = new PolicyParameters(); + fixture.setRequestID(UUID.randomUUID()); + fixture.setActionAttribute(""); + fixture.setAttributes(new Hashtable()); + fixture.setDynamicRuleAlgorithmLabels(new LinkedList()); + fixture.setPolicyDescription(""); + fixture.setPolicyConfigType(PolicyConfigType.BRMS_PARAM); + fixture.setDynamicRuleAlgorithmField2(new LinkedList()); + fixture.setPolicyName(""); + fixture.setConfigName(""); + fixture.setDynamicRuleAlgorithmFunctions(new LinkedList()); + fixture.setPolicyClass(PolicyClass.Action); + fixture.setEcompName(""); + fixture.setConfigBodyType(PolicyType.JSON); + fixture.setDynamicRuleAlgorithmField1(new LinkedList()); + fixture.setPriority(""); + fixture.setActionPerformer(""); + fixture.setConfigBody(""); + + String result = fixture.getActionAttribute(); + + // add additional test code here + assertEquals("", result); + } + + /** + * Run the String getActionPerformer() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testGetActionPerformer_1() + throws Exception { + PolicyParameters fixture = new PolicyParameters(); + fixture.setRequestID(UUID.randomUUID()); + fixture.setActionAttribute(""); + fixture.setAttributes(new Hashtable()); + fixture.setDynamicRuleAlgorithmLabels(new LinkedList()); + fixture.setPolicyDescription(""); + fixture.setPolicyConfigType(PolicyConfigType.BRMS_PARAM); + fixture.setDynamicRuleAlgorithmField2(new LinkedList()); + fixture.setPolicyName(""); + fixture.setConfigName(""); + fixture.setDynamicRuleAlgorithmFunctions(new LinkedList()); + fixture.setPolicyClass(PolicyClass.Action); + fixture.setEcompName(""); + fixture.setConfigBodyType(PolicyType.JSON); + fixture.setDynamicRuleAlgorithmField1(new LinkedList()); + fixture.setPriority(""); + fixture.setActionPerformer(""); + fixture.setConfigBody(""); + + String result = fixture.getActionPerformer(); + + // add additional test code here + assertEquals("", result); + } + + /** + * Run the Map> getAttributes() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testGetAttributes_1() + throws Exception { + PolicyParameters fixture = new PolicyParameters(); + fixture.setRequestID(UUID.randomUUID()); + fixture.setActionAttribute(""); + fixture.setAttributes(new Hashtable()); + fixture.setDynamicRuleAlgorithmLabels(new LinkedList()); + fixture.setPolicyDescription(""); + + fixture.setPolicyConfigType(PolicyConfigType.BRMS_PARAM); + fixture.setDynamicRuleAlgorithmField2(new LinkedList()); + fixture.setPolicyName(""); + fixture.setConfigName(""); + fixture.setDynamicRuleAlgorithmFunctions(new LinkedList()); + fixture.setPolicyClass(PolicyClass.Action); + fixture.setEcompName(""); + fixture.setConfigBodyType(PolicyType.JSON); + fixture.setDynamicRuleAlgorithmField1(new LinkedList()); + fixture.setPriority(""); + fixture.setActionPerformer(""); + fixture.setConfigBody(""); + + Map> result = fixture.getAttributes(); + + // add additional test code here + assertNotNull(result); + assertEquals(0, result.size()); + } + + /** + * Run the String getConfigBody() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testGetConfigBody_1() + throws Exception { + PolicyParameters fixture = new PolicyParameters(); + fixture.setRequestID(UUID.randomUUID()); + fixture.setActionAttribute(""); + fixture.setAttributes(new Hashtable()); + fixture.setDynamicRuleAlgorithmLabels(new LinkedList()); + fixture.setPolicyDescription(""); + + fixture.setPolicyConfigType(PolicyConfigType.BRMS_PARAM); + fixture.setDynamicRuleAlgorithmField2(new LinkedList()); + fixture.setPolicyName(""); + fixture.setConfigName(""); + fixture.setDynamicRuleAlgorithmFunctions(new LinkedList()); + fixture.setPolicyClass(PolicyClass.Action); + fixture.setEcompName(""); + fixture.setConfigBodyType(PolicyType.JSON); + fixture.setDynamicRuleAlgorithmField1(new LinkedList()); + fixture.setPriority(""); + fixture.setActionPerformer(""); + fixture.setConfigBody(""); + + String result = fixture.getConfigBody(); + + // add additional test code here + assertEquals("", result); + } + + /** + * Run the PolicyType getConfigBodyType() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testGetConfigBodyType_1() + throws Exception { + PolicyParameters fixture = new PolicyParameters(); + fixture.setRequestID(UUID.randomUUID()); + fixture.setActionAttribute(""); + fixture.setAttributes(new Hashtable()); + fixture.setDynamicRuleAlgorithmLabels(new LinkedList()); + fixture.setPolicyDescription(""); + + fixture.setPolicyConfigType(PolicyConfigType.BRMS_PARAM); + fixture.setDynamicRuleAlgorithmField2(new LinkedList()); + fixture.setPolicyName(""); + fixture.setConfigName(""); + fixture.setDynamicRuleAlgorithmFunctions(new LinkedList()); + fixture.setPolicyClass(PolicyClass.Action); + fixture.setEcompName(""); + fixture.setConfigBodyType(PolicyType.JSON); + fixture.setDynamicRuleAlgorithmField1(new LinkedList()); + fixture.setPriority(""); + fixture.setActionPerformer(""); + fixture.setConfigBody(""); + + PolicyType result = fixture.getConfigBodyType(); + + // add additional test code here + assertNotNull(result); + assertEquals("json", result.toString()); + assertEquals("JSON", result.name()); + assertEquals(1, result.ordinal()); + } + + /** + * Run the String getConfigName() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testGetConfigName_1() + throws Exception { + PolicyParameters fixture = new PolicyParameters(); + fixture.setRequestID(UUID.randomUUID()); + fixture.setActionAttribute(""); + fixture.setAttributes(new Hashtable()); + fixture.setDynamicRuleAlgorithmLabels(new LinkedList()); + fixture.setPolicyDescription(""); + + fixture.setPolicyConfigType(PolicyConfigType.BRMS_PARAM); + fixture.setDynamicRuleAlgorithmField2(new LinkedList()); + fixture.setPolicyName(""); + fixture.setConfigName(""); + fixture.setDynamicRuleAlgorithmFunctions(new LinkedList()); + fixture.setPolicyClass(PolicyClass.Action); + fixture.setEcompName(""); + fixture.setConfigBodyType(PolicyType.JSON); + fixture.setDynamicRuleAlgorithmField1(new LinkedList()); + fixture.setPriority(""); + fixture.setActionPerformer(""); + fixture.setConfigBody(""); + + String result = fixture.getConfigName(); + + // add additional test code here + assertEquals("", result); + } + + /** + * Run the List getDynamicRuleAlgorithmField1() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testGetDynamicRuleAlgorithmField1_1() + throws Exception { + PolicyParameters fixture = new PolicyParameters(); + fixture.setRequestID(UUID.randomUUID()); + fixture.setActionAttribute(""); + fixture.setAttributes(new Hashtable()); + fixture.setDynamicRuleAlgorithmLabels(new LinkedList()); + fixture.setPolicyDescription(""); + + fixture.setPolicyConfigType(PolicyConfigType.BRMS_PARAM); + fixture.setDynamicRuleAlgorithmField2(new LinkedList()); + fixture.setPolicyName(""); + fixture.setConfigName(""); + fixture.setDynamicRuleAlgorithmFunctions(new LinkedList()); + fixture.setPolicyClass(PolicyClass.Action); + fixture.setEcompName(""); + fixture.setConfigBodyType(PolicyType.JSON); + fixture.setDynamicRuleAlgorithmField1(new LinkedList()); + fixture.setPriority(""); + fixture.setActionPerformer(""); + fixture.setConfigBody(""); + + List result = fixture.getDynamicRuleAlgorithmField1(); + + // add additional test code here + assertNotNull(result); + assertEquals(0, result.size()); + } + + /** + * Run the List getDynamicRuleAlgorithmField2() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testGetDynamicRuleAlgorithmField2_1() + throws Exception { + PolicyParameters fixture = new PolicyParameters(); + fixture.setRequestID(UUID.randomUUID()); + fixture.setActionAttribute(""); + fixture.setAttributes(new Hashtable()); + fixture.setDynamicRuleAlgorithmLabels(new LinkedList()); + fixture.setPolicyDescription(""); + + fixture.setPolicyConfigType(PolicyConfigType.BRMS_PARAM); + fixture.setDynamicRuleAlgorithmField2(new LinkedList()); + fixture.setPolicyName(""); + fixture.setConfigName(""); + fixture.setDynamicRuleAlgorithmFunctions(new LinkedList()); + fixture.setPolicyClass(PolicyClass.Action); + fixture.setEcompName(""); + fixture.setConfigBodyType(PolicyType.JSON); + fixture.setDynamicRuleAlgorithmField1(new LinkedList()); + fixture.setPriority(""); + fixture.setActionPerformer(""); + fixture.setConfigBody(""); + + List result = fixture.getDynamicRuleAlgorithmField2(); + + // add additional test code here + assertNotNull(result); + assertEquals(0, result.size()); + } + + /** + * Run the List getDynamicRuleAlgorithmFunctions() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testGetDynamicRuleAlgorithmFunctions_1() + throws Exception { + PolicyParameters fixture = new PolicyParameters(); + fixture.setRequestID(UUID.randomUUID()); + fixture.setActionAttribute(""); + fixture.setAttributes(new Hashtable()); + fixture.setDynamicRuleAlgorithmLabels(new LinkedList()); + fixture.setPolicyDescription(""); + + fixture.setPolicyConfigType(PolicyConfigType.BRMS_PARAM); + fixture.setDynamicRuleAlgorithmField2(new LinkedList()); + fixture.setPolicyName(""); + fixture.setConfigName(""); + fixture.setDynamicRuleAlgorithmFunctions(new LinkedList()); + fixture.setPolicyClass(PolicyClass.Action); + fixture.setEcompName(""); + fixture.setConfigBodyType(PolicyType.JSON); + fixture.setDynamicRuleAlgorithmField1(new LinkedList()); + fixture.setPriority(""); + fixture.setActionPerformer(""); + fixture.setConfigBody(""); + + List result = fixture.getDynamicRuleAlgorithmFunctions(); + + // add additional test code here + assertNotNull(result); + assertEquals(0, result.size()); + } + + /** + * Run the List getDynamicRuleAlgorithmLabels() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testGetDynamicRuleAlgorithmLabels_1() + throws Exception { + PolicyParameters fixture = new PolicyParameters(); + fixture.setRequestID(UUID.randomUUID()); + fixture.setActionAttribute(""); + fixture.setAttributes(new Hashtable()); + fixture.setDynamicRuleAlgorithmLabels(new LinkedList()); + fixture.setPolicyDescription(""); + + fixture.setPolicyConfigType(PolicyConfigType.BRMS_PARAM); + fixture.setDynamicRuleAlgorithmField2(new LinkedList()); + fixture.setPolicyName(""); + fixture.setConfigName(""); + fixture.setDynamicRuleAlgorithmFunctions(new LinkedList()); + fixture.setPolicyClass(PolicyClass.Action); + fixture.setEcompName(""); + fixture.setConfigBodyType(PolicyType.JSON); + fixture.setDynamicRuleAlgorithmField1(new LinkedList()); + fixture.setPriority(""); + fixture.setActionPerformer(""); + fixture.setConfigBody(""); + + List result = fixture.getDynamicRuleAlgorithmLabels(); + + // add additional test code here + assertNotNull(result); + assertEquals(0, result.size()); + } + + /** + * Run the String getEcompName() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testGetEcompName_1() + throws Exception { + PolicyParameters fixture = new PolicyParameters(); + fixture.setRequestID(UUID.randomUUID()); + fixture.setActionAttribute(""); + fixture.setAttributes(new Hashtable()); + fixture.setDynamicRuleAlgorithmLabels(new LinkedList()); + fixture.setPolicyDescription(""); + + fixture.setPolicyConfigType(PolicyConfigType.BRMS_PARAM); + fixture.setDynamicRuleAlgorithmField2(new LinkedList()); + fixture.setPolicyName(""); + fixture.setConfigName(""); + fixture.setDynamicRuleAlgorithmFunctions(new LinkedList()); + fixture.setPolicyClass(PolicyClass.Action); + fixture.setEcompName(""); + fixture.setConfigBodyType(PolicyType.JSON); + fixture.setDynamicRuleAlgorithmField1(new LinkedList()); + fixture.setPriority(""); + fixture.setActionPerformer(""); + fixture.setConfigBody(""); + + String result = fixture.getEcompName(); + + // add additional test code here + assertEquals("", result); + } + + /** + * Run the PolicyClass getPolicyClass() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testGetPolicyClass_1() + throws Exception { + PolicyParameters fixture = new PolicyParameters(); + fixture.setRequestID(UUID.randomUUID()); + fixture.setActionAttribute(""); + fixture.setAttributes(new Hashtable()); + fixture.setDynamicRuleAlgorithmLabels(new LinkedList()); + fixture.setPolicyDescription(""); + + fixture.setPolicyConfigType(PolicyConfigType.BRMS_PARAM); + fixture.setDynamicRuleAlgorithmField2(new LinkedList()); + fixture.setPolicyName(""); + fixture.setConfigName(""); + fixture.setDynamicRuleAlgorithmFunctions(new LinkedList()); + fixture.setPolicyClass(PolicyClass.Action); + fixture.setEcompName(""); + fixture.setConfigBodyType(PolicyType.JSON); + fixture.setDynamicRuleAlgorithmField1(new LinkedList()); + fixture.setPriority(""); + fixture.setActionPerformer(""); + fixture.setConfigBody(""); + + PolicyClass result = fixture.getPolicyClass(); + + // add additional test code here + assertNotNull(result); + assertEquals("Action", result.toString()); + assertEquals("Action", result.name()); + assertEquals(1, result.ordinal()); + } + + /** + * Run the PolicyConfigType getPolicyConfigType() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testGetPolicyConfigType_1() + throws Exception { + PolicyParameters fixture = new PolicyParameters(); + fixture.setRequestID(UUID.randomUUID()); + fixture.setActionAttribute(""); + fixture.setAttributes(new Hashtable()); + fixture.setDynamicRuleAlgorithmLabels(new LinkedList()); + fixture.setPolicyDescription(""); + + fixture.setPolicyConfigType(PolicyConfigType.BRMS_PARAM); + fixture.setDynamicRuleAlgorithmField2(new LinkedList()); + fixture.setPolicyName(""); + fixture.setConfigName(""); + fixture.setDynamicRuleAlgorithmFunctions(new LinkedList()); + fixture.setPolicyClass(PolicyClass.Action); + fixture.setEcompName(""); + fixture.setConfigBodyType(PolicyType.JSON); + fixture.setDynamicRuleAlgorithmField1(new LinkedList()); + fixture.setPriority(""); + fixture.setActionPerformer(""); + fixture.setConfigBody(""); + + PolicyConfigType result = fixture.getPolicyConfigType(); + + // add additional test code here + assertNotNull(result); + assertEquals("BRMS_Param", result.toString()); + assertEquals("BRMS_PARAM", result.name()); + assertEquals(5, result.ordinal()); + } + + /** + * Run the String getPolicyDescription() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testGetPolicyDescription_1() + throws Exception { + PolicyParameters fixture = new PolicyParameters(); + fixture.setRequestID(UUID.randomUUID()); + fixture.setActionAttribute(""); + fixture.setAttributes(new Hashtable()); + fixture.setDynamicRuleAlgorithmLabels(new LinkedList()); + fixture.setPolicyDescription(""); + + fixture.setPolicyConfigType(PolicyConfigType.BRMS_PARAM); + fixture.setDynamicRuleAlgorithmField2(new LinkedList()); + fixture.setPolicyName(""); + fixture.setConfigName(""); + fixture.setDynamicRuleAlgorithmFunctions(new LinkedList()); + fixture.setPolicyClass(PolicyClass.Action); + fixture.setEcompName(""); + fixture.setConfigBodyType(PolicyType.JSON); + fixture.setDynamicRuleAlgorithmField1(new LinkedList()); + fixture.setPriority(""); + fixture.setActionPerformer(""); + fixture.setConfigBody(""); + + String result = fixture.getPolicyDescription(); + + // add additional test code here + assertEquals("", result); + } + + /** + * Run the String getPolicyName() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testGetPolicyName_1() + throws Exception { + PolicyParameters fixture = new PolicyParameters(); + fixture.setRequestID(UUID.randomUUID()); + fixture.setActionAttribute(""); + fixture.setAttributes(new Hashtable()); + fixture.setDynamicRuleAlgorithmLabels(new LinkedList()); + fixture.setPolicyDescription(""); + + fixture.setPolicyConfigType(PolicyConfigType.BRMS_PARAM); + fixture.setDynamicRuleAlgorithmField2(new LinkedList()); + fixture.setPolicyName(""); + fixture.setConfigName(""); + fixture.setDynamicRuleAlgorithmFunctions(new LinkedList()); + fixture.setPolicyClass(PolicyClass.Action); + fixture.setEcompName(""); + fixture.setConfigBodyType(PolicyType.JSON); + fixture.setDynamicRuleAlgorithmField1(new LinkedList()); + fixture.setPriority(""); + fixture.setActionPerformer(""); + fixture.setConfigBody(""); + + String result = fixture.getPolicyName(); + + // add additional test code here + assertEquals("", result); + } + + /** + * Run the String getPriority() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testGetPriority_1() + throws Exception { + PolicyParameters fixture = new PolicyParameters(); + fixture.setRequestID(UUID.randomUUID()); + fixture.setActionAttribute(""); + fixture.setAttributes(new Hashtable()); + fixture.setDynamicRuleAlgorithmLabels(new LinkedList()); + fixture.setPolicyDescription(""); + + fixture.setPolicyConfigType(PolicyConfigType.BRMS_PARAM); + fixture.setDynamicRuleAlgorithmField2(new LinkedList()); + fixture.setPolicyName(""); + fixture.setConfigName(""); + fixture.setDynamicRuleAlgorithmFunctions(new LinkedList()); + fixture.setPolicyClass(PolicyClass.Action); + fixture.setEcompName(""); + fixture.setConfigBodyType(PolicyType.JSON); + fixture.setDynamicRuleAlgorithmField1(new LinkedList()); + fixture.setPriority(""); + fixture.setActionPerformer(""); + fixture.setConfigBody(""); + + String result = fixture.getPriority(); + + // add additional test code here + assertEquals("", result); + } + + /** + * Run the UUID getRequestID() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testGetRequestID_1() + throws Exception { + PolicyParameters fixture = new PolicyParameters(); + fixture.setRequestID(UUID.fromString("878d319c-2799-4684-b480-99f40e1042b2")); + fixture.setActionAttribute(""); + fixture.setAttributes(new Hashtable()); + fixture.setDynamicRuleAlgorithmLabels(new LinkedList()); + fixture.setPolicyDescription(""); + + fixture.setPolicyConfigType(PolicyConfigType.BRMS_PARAM); + fixture.setDynamicRuleAlgorithmField2(new LinkedList()); + fixture.setPolicyName(""); + fixture.setConfigName(""); + fixture.setDynamicRuleAlgorithmFunctions(new LinkedList()); + fixture.setPolicyClass(PolicyClass.Action); + fixture.setEcompName(""); + fixture.setConfigBodyType(PolicyType.JSON); + fixture.setDynamicRuleAlgorithmField1(new LinkedList()); + fixture.setPriority(""); + fixture.setActionPerformer(""); + fixture.setConfigBody(""); + + UUID result = fixture.getRequestID(); + + // add additional test code here + assertNotNull(result); + assertEquals("878d319c-2799-4684-b480-99f40e1042b2", result.toString()); + assertEquals(4, result.version()); + assertEquals(2, result.variant()); + assertEquals(-5440179076376542542L, result.getLeastSignificantBits()); + assertEquals(-8679226360124062076L, result.getMostSignificantBits()); + } + + /** + * Run the void setActionAttribute(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testSetActionAttribute_1() + throws Exception { + PolicyParameters fixture = new PolicyParameters(); + fixture.setRequestID(UUID.randomUUID()); + fixture.setActionAttribute(""); + fixture.setAttributes(new Hashtable()); + fixture.setDynamicRuleAlgorithmLabels(new LinkedList()); + fixture.setPolicyDescription(""); + + fixture.setPolicyConfigType(PolicyConfigType.BRMS_PARAM); + fixture.setDynamicRuleAlgorithmField2(new LinkedList()); + fixture.setPolicyName(""); + fixture.setConfigName(""); + fixture.setDynamicRuleAlgorithmFunctions(new LinkedList()); + fixture.setPolicyClass(PolicyClass.Action); + fixture.setEcompName(""); + fixture.setConfigBodyType(PolicyType.JSON); + fixture.setDynamicRuleAlgorithmField1(new LinkedList()); + fixture.setPriority(""); + fixture.setActionPerformer(""); + fixture.setConfigBody(""); + String actionAttribute = ""; + + fixture.setActionAttribute(actionAttribute); + + // add additional test code here + } + + /** + * Run the void setActionPerformer(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testSetActionPerformer_1() + throws Exception { + PolicyParameters fixture = new PolicyParameters(); + fixture.setRequestID(UUID.randomUUID()); + fixture.setActionAttribute(""); + fixture.setAttributes(new Hashtable()); + fixture.setDynamicRuleAlgorithmLabels(new LinkedList()); + fixture.setPolicyDescription(""); + + fixture.setPolicyConfigType(PolicyConfigType.BRMS_PARAM); + fixture.setDynamicRuleAlgorithmField2(new LinkedList()); + fixture.setPolicyName(""); + fixture.setConfigName(""); + fixture.setDynamicRuleAlgorithmFunctions(new LinkedList()); + fixture.setPolicyClass(PolicyClass.Action); + fixture.setEcompName(""); + fixture.setConfigBodyType(PolicyType.JSON); + fixture.setDynamicRuleAlgorithmField1(new LinkedList()); + fixture.setPriority(""); + fixture.setActionPerformer(""); + fixture.setConfigBody(""); + String actionPerformer = ""; + + fixture.setActionPerformer(actionPerformer); + + // add additional test code here + } + + /** + * Run the void setAttributes(Map>) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testSetAttributes_1() + throws Exception { + PolicyParameters fixture = new PolicyParameters(); + fixture.setRequestID(UUID.randomUUID()); + fixture.setActionAttribute(""); + fixture.setAttributes(new Hashtable()); + fixture.setDynamicRuleAlgorithmLabels(new LinkedList()); + fixture.setPolicyDescription(""); + + fixture.setPolicyConfigType(PolicyConfigType.BRMS_PARAM); + fixture.setDynamicRuleAlgorithmField2(new LinkedList()); + fixture.setPolicyName(""); + fixture.setConfigName(""); + fixture.setDynamicRuleAlgorithmFunctions(new LinkedList()); + fixture.setPolicyClass(PolicyClass.Action); + fixture.setEcompName(""); + fixture.setConfigBodyType(PolicyType.JSON); + fixture.setDynamicRuleAlgorithmField1(new LinkedList()); + fixture.setPriority(""); + fixture.setActionPerformer(""); + fixture.setConfigBody(""); + Map> attributes = new Hashtable(); + + fixture.setAttributes(attributes); + + // add additional test code here + } + + /** + * Run the void setConfigBody(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testSetConfigBody_1() + throws Exception { + PolicyParameters fixture = new PolicyParameters(); + fixture.setRequestID(UUID.randomUUID()); + fixture.setActionAttribute(""); + fixture.setAttributes(new Hashtable()); + fixture.setDynamicRuleAlgorithmLabels(new LinkedList()); + fixture.setPolicyDescription(""); + + fixture.setPolicyConfigType(PolicyConfigType.BRMS_PARAM); + fixture.setDynamicRuleAlgorithmField2(new LinkedList()); + fixture.setPolicyName(""); + fixture.setConfigName(""); + fixture.setDynamicRuleAlgorithmFunctions(new LinkedList()); + fixture.setPolicyClass(PolicyClass.Action); + fixture.setEcompName(""); + fixture.setConfigBodyType(PolicyType.JSON); + fixture.setDynamicRuleAlgorithmField1(new LinkedList()); + fixture.setPriority(""); + fixture.setActionPerformer(""); + fixture.setConfigBody(""); + String configBody = ""; + + fixture.setConfigBody(configBody); + + // add additional test code here + } + + /** + * Run the void setConfigBodyType(PolicyType) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testSetConfigBodyType_1() + throws Exception { + PolicyParameters fixture = new PolicyParameters(); + fixture.setRequestID(UUID.randomUUID()); + fixture.setActionAttribute(""); + fixture.setAttributes(new Hashtable()); + fixture.setDynamicRuleAlgorithmLabels(new LinkedList()); + fixture.setPolicyDescription(""); + + fixture.setPolicyConfigType(PolicyConfigType.BRMS_PARAM); + fixture.setDynamicRuleAlgorithmField2(new LinkedList()); + fixture.setPolicyName(""); + fixture.setConfigName(""); + fixture.setDynamicRuleAlgorithmFunctions(new LinkedList()); + fixture.setPolicyClass(PolicyClass.Action); + fixture.setEcompName(""); + fixture.setConfigBodyType(PolicyType.JSON); + fixture.setDynamicRuleAlgorithmField1(new LinkedList()); + fixture.setPriority(""); + fixture.setActionPerformer(""); + fixture.setConfigBody(""); + PolicyType configBodyType = PolicyType.JSON; + + fixture.setConfigBodyType(configBodyType); + + // add additional test code here + } + + /** + * Run the void setConfigFirewallPolicyParameters(String,String,UUID) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testSetConfigFirewallPolicyParameters_1() + throws Exception { + PolicyParameters fixture = new PolicyParameters(); + fixture.setRequestID(UUID.randomUUID()); + fixture.setActionAttribute(""); + fixture.setAttributes(new Hashtable()); + fixture.setDynamicRuleAlgorithmLabels(new LinkedList()); + fixture.setPolicyDescription(""); + + fixture.setPolicyConfigType(PolicyConfigType.BRMS_PARAM); + fixture.setDynamicRuleAlgorithmField2(new LinkedList()); + fixture.setPolicyName(""); + fixture.setConfigName(""); + fixture.setDynamicRuleAlgorithmFunctions(new LinkedList()); + fixture.setPolicyClass(PolicyClass.Action); + fixture.setEcompName(""); + fixture.setConfigBodyType(PolicyType.JSON); + fixture.setDynamicRuleAlgorithmField1(new LinkedList()); + fixture.setPriority(""); + fixture.setActionPerformer(""); + fixture.setConfigBody(""); + String policyName = ""; + String firewallJson = ""; + UUID requestID = UUID.randomUUID(); + + fixture.setConfigFirewallPolicyParameters(policyName, firewallJson, requestID); + + // add additional test code here + } + + /** + * Run the void setConfigName(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testSetConfigName_1() + throws Exception { + PolicyParameters fixture = new PolicyParameters(); + fixture.setRequestID(UUID.randomUUID()); + fixture.setActionAttribute(""); + fixture.setAttributes(new Hashtable()); + fixture.setDynamicRuleAlgorithmLabels(new LinkedList()); + fixture.setPolicyDescription(""); + + fixture.setPolicyConfigType(PolicyConfigType.BRMS_PARAM); + fixture.setDynamicRuleAlgorithmField2(new LinkedList()); + fixture.setPolicyName(""); + fixture.setConfigName(""); + fixture.setDynamicRuleAlgorithmFunctions(new LinkedList()); + fixture.setPolicyClass(PolicyClass.Action); + fixture.setEcompName(""); + fixture.setConfigBodyType(PolicyType.JSON); + fixture.setDynamicRuleAlgorithmField1(new LinkedList()); + fixture.setPriority(""); + fixture.setActionPerformer(""); + fixture.setConfigBody(""); + String configName = ""; + + fixture.setConfigName(configName); + + // add additional test code here + } + + /** + * Run the void setConfigPolicyParameters(PolicyConfigType,String,String,String,String,Map>,PolicyType,String,UUID) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testSetConfigPolicyParameters_1() + throws Exception { + PolicyParameters fixture = new PolicyParameters(); + fixture.setRequestID(UUID.randomUUID()); + fixture.setActionAttribute(""); + fixture.setAttributes(new Hashtable()); + fixture.setDynamicRuleAlgorithmLabels(new LinkedList()); + fixture.setPolicyDescription(""); + + fixture.setPolicyConfigType(PolicyConfigType.BRMS_PARAM); + fixture.setDynamicRuleAlgorithmField2(new LinkedList()); + fixture.setPolicyName(""); + fixture.setConfigName(""); + fixture.setDynamicRuleAlgorithmFunctions(new LinkedList()); + fixture.setPolicyClass(PolicyClass.Action); + fixture.setEcompName(""); + fixture.setConfigBodyType(PolicyType.JSON); + fixture.setDynamicRuleAlgorithmField1(new LinkedList()); + fixture.setPriority(""); + fixture.setActionPerformer(""); + fixture.setConfigBody(""); + PolicyConfigType policyConfigType = PolicyConfigType.BRMS_PARAM; + String policyName = ""; + String policyDescription = ""; + String ecompName = ""; + String configName = ""; + Map> attributes = new Hashtable(); + PolicyType configBodyType = PolicyType.JSON; + String configBody = ""; + UUID requestID = UUID.randomUUID(); + + fixture.setConfigPolicyParameters(policyConfigType, policyName, policyDescription, ecompName, configName, attributes, configBodyType, configBody, requestID); + + // add additional test code here + } + + /** + * Run the void setDynamicRuleAlgorithmField1(List) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testSetDynamicRuleAlgorithmField1_1() + throws Exception { + PolicyParameters fixture = new PolicyParameters(); + fixture.setRequestID(UUID.randomUUID()); + fixture.setActionAttribute(""); + fixture.setAttributes(new Hashtable()); + fixture.setDynamicRuleAlgorithmLabels(new LinkedList()); + fixture.setPolicyDescription(""); + + fixture.setPolicyConfigType(PolicyConfigType.BRMS_PARAM); + fixture.setDynamicRuleAlgorithmField2(new LinkedList()); + fixture.setPolicyName(""); + fixture.setConfigName(""); + fixture.setDynamicRuleAlgorithmFunctions(new LinkedList()); + fixture.setPolicyClass(PolicyClass.Action); + fixture.setEcompName(""); + fixture.setConfigBodyType(PolicyType.JSON); + fixture.setDynamicRuleAlgorithmField1(new LinkedList()); + fixture.setPriority(""); + fixture.setActionPerformer(""); + fixture.setConfigBody(""); + List dynamicRuleAlgorithmField1 = new LinkedList(); + + fixture.setDynamicRuleAlgorithmField1(dynamicRuleAlgorithmField1); + + // add additional test code here + } + + /** + * Run the void setDynamicRuleAlgorithmField2(List) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testSetDynamicRuleAlgorithmField2_1() + throws Exception { + PolicyParameters fixture = new PolicyParameters(); + fixture.setRequestID(UUID.randomUUID()); + fixture.setActionAttribute(""); + fixture.setAttributes(new Hashtable()); + fixture.setDynamicRuleAlgorithmLabels(new LinkedList()); + fixture.setPolicyDescription(""); + + fixture.setPolicyConfigType(PolicyConfigType.BRMS_PARAM); + fixture.setDynamicRuleAlgorithmField2(new LinkedList()); + fixture.setPolicyName(""); + fixture.setConfigName(""); + fixture.setDynamicRuleAlgorithmFunctions(new LinkedList()); + fixture.setPolicyClass(PolicyClass.Action); + fixture.setEcompName(""); + fixture.setConfigBodyType(PolicyType.JSON); + fixture.setDynamicRuleAlgorithmField1(new LinkedList()); + fixture.setPriority(""); + fixture.setActionPerformer(""); + fixture.setConfigBody(""); + List dynamicRuleAlgorithmField2 = new LinkedList(); + + fixture.setDynamicRuleAlgorithmField2(dynamicRuleAlgorithmField2); + + // add additional test code here + } + + /** + * Run the void setDynamicRuleAlgorithmFunctions(List) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testSetDynamicRuleAlgorithmFunctions_1() + throws Exception { + PolicyParameters fixture = new PolicyParameters(); + fixture.setRequestID(UUID.randomUUID()); + fixture.setActionAttribute(""); + fixture.setAttributes(new Hashtable()); + fixture.setDynamicRuleAlgorithmLabels(new LinkedList()); + fixture.setPolicyDescription(""); + + fixture.setPolicyConfigType(PolicyConfigType.BRMS_PARAM); + fixture.setDynamicRuleAlgorithmField2(new LinkedList()); + fixture.setPolicyName(""); + fixture.setConfigName(""); + fixture.setDynamicRuleAlgorithmFunctions(new LinkedList()); + fixture.setPolicyClass(PolicyClass.Action); + fixture.setEcompName(""); + fixture.setConfigBodyType(PolicyType.JSON); + fixture.setDynamicRuleAlgorithmField1(new LinkedList()); + fixture.setPriority(""); + fixture.setActionPerformer(""); + fixture.setConfigBody(""); + List dynamicRuleAlgorithmFunctions = new LinkedList(); + + fixture.setDynamicRuleAlgorithmFunctions(dynamicRuleAlgorithmFunctions); + + // add additional test code here + } + + /** + * Run the void setDynamicRuleAlgorithmLabels(List) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testSetDynamicRuleAlgorithmLabels_1() + throws Exception { + PolicyParameters fixture = new PolicyParameters(); + fixture.setRequestID(UUID.randomUUID()); + fixture.setActionAttribute(""); + fixture.setAttributes(new Hashtable()); + fixture.setDynamicRuleAlgorithmLabels(new LinkedList()); + fixture.setPolicyDescription(""); + + fixture.setPolicyConfigType(PolicyConfigType.BRMS_PARAM); + fixture.setDynamicRuleAlgorithmField2(new LinkedList()); + fixture.setPolicyName(""); + fixture.setConfigName(""); + fixture.setDynamicRuleAlgorithmFunctions(new LinkedList()); + fixture.setPolicyClass(PolicyClass.Action); + fixture.setEcompName(""); + fixture.setConfigBodyType(PolicyType.JSON); + fixture.setDynamicRuleAlgorithmField1(new LinkedList()); + fixture.setPriority(""); + fixture.setActionPerformer(""); + fixture.setConfigBody(""); + List dynamicRuleAlgorithmLabels = new LinkedList(); + + fixture.setDynamicRuleAlgorithmLabels(dynamicRuleAlgorithmLabels); + + // add additional test code here + } + + /** + * Run the void setEcompName(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testSetEcompName_1() + throws Exception { + PolicyParameters fixture = new PolicyParameters(); + fixture.setRequestID(UUID.randomUUID()); + fixture.setActionAttribute(""); + fixture.setAttributes(new Hashtable()); + fixture.setDynamicRuleAlgorithmLabels(new LinkedList()); + fixture.setPolicyDescription(""); + + fixture.setPolicyConfigType(PolicyConfigType.BRMS_PARAM); + fixture.setDynamicRuleAlgorithmField2(new LinkedList()); + fixture.setPolicyName(""); + fixture.setConfigName(""); + fixture.setDynamicRuleAlgorithmFunctions(new LinkedList()); + fixture.setPolicyClass(PolicyClass.Action); + fixture.setEcompName(""); + fixture.setConfigBodyType(PolicyType.JSON); + fixture.setDynamicRuleAlgorithmField1(new LinkedList()); + fixture.setPriority(""); + fixture.setActionPerformer(""); + fixture.setConfigBody(""); + String ecompName = ""; + + fixture.setEcompName(ecompName); + + // add additional test code here + } + + /** + * Run the void setPolicyClass(PolicyClass) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testSetPolicyClass_1() + throws Exception { + PolicyParameters fixture = new PolicyParameters(); + fixture.setRequestID(UUID.randomUUID()); + fixture.setActionAttribute(""); + fixture.setAttributes(new Hashtable()); + fixture.setDynamicRuleAlgorithmLabels(new LinkedList()); + fixture.setPolicyDescription(""); + + fixture.setPolicyConfigType(PolicyConfigType.BRMS_PARAM); + fixture.setDynamicRuleAlgorithmField2(new LinkedList()); + fixture.setPolicyName(""); + fixture.setConfigName(""); + fixture.setDynamicRuleAlgorithmFunctions(new LinkedList()); + fixture.setPolicyClass(PolicyClass.Action); + fixture.setEcompName(""); + fixture.setConfigBodyType(PolicyType.JSON); + fixture.setDynamicRuleAlgorithmField1(new LinkedList()); + fixture.setPriority(""); + fixture.setActionPerformer(""); + fixture.setConfigBody(""); + PolicyClass policyClass = PolicyClass.Action; + + fixture.setPolicyClass(policyClass); + + // add additional test code here + } + + /** + * Run the void setPolicyConfigType(PolicyConfigType) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testSetPolicyConfigType_1() + throws Exception { + PolicyParameters fixture = new PolicyParameters(); + fixture.setRequestID(UUID.randomUUID()); + fixture.setActionAttribute(""); + fixture.setAttributes(new Hashtable()); + fixture.setDynamicRuleAlgorithmLabels(new LinkedList()); + fixture.setPolicyDescription(""); + + fixture.setPolicyConfigType(PolicyConfigType.BRMS_PARAM); + fixture.setDynamicRuleAlgorithmField2(new LinkedList()); + fixture.setPolicyName(""); + fixture.setConfigName(""); + fixture.setDynamicRuleAlgorithmFunctions(new LinkedList()); + fixture.setPolicyClass(PolicyClass.Action); + fixture.setEcompName(""); + fixture.setConfigBodyType(PolicyType.JSON); + fixture.setDynamicRuleAlgorithmField1(new LinkedList()); + fixture.setPriority(""); + fixture.setActionPerformer(""); + fixture.setConfigBody(""); + PolicyConfigType policyConfigType = PolicyConfigType.BRMS_PARAM; + + fixture.setPolicyConfigType(policyConfigType); + + // add additional test code here + } + + /** + * Run the void setPolicyDescription(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testSetPolicyDescription_1() + throws Exception { + PolicyParameters fixture = new PolicyParameters(); + fixture.setRequestID(UUID.randomUUID()); + fixture.setActionAttribute(""); + fixture.setAttributes(new Hashtable()); + fixture.setDynamicRuleAlgorithmLabels(new LinkedList()); + fixture.setPolicyDescription(""); + + fixture.setPolicyConfigType(PolicyConfigType.BRMS_PARAM); + fixture.setDynamicRuleAlgorithmField2(new LinkedList()); + fixture.setPolicyName(""); + fixture.setConfigName(""); + fixture.setDynamicRuleAlgorithmFunctions(new LinkedList()); + fixture.setPolicyClass(PolicyClass.Action); + fixture.setEcompName(""); + fixture.setConfigBodyType(PolicyType.JSON); + fixture.setDynamicRuleAlgorithmField1(new LinkedList()); + fixture.setPriority(""); + fixture.setActionPerformer(""); + fixture.setConfigBody(""); + String policyDescription = ""; + + fixture.setPolicyDescription(policyDescription); + + // add additional test code here + } + + /** + * Run the void setPolicyName(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testSetPolicyName_1() + throws Exception { + PolicyParameters fixture = new PolicyParameters(); + fixture.setRequestID(UUID.randomUUID()); + fixture.setActionAttribute(""); + fixture.setAttributes(new Hashtable()); + fixture.setDynamicRuleAlgorithmLabels(new LinkedList()); + fixture.setPolicyDescription(""); + + fixture.setPolicyConfigType(PolicyConfigType.BRMS_PARAM); + fixture.setDynamicRuleAlgorithmField2(new LinkedList()); + fixture.setPolicyName(""); + fixture.setConfigName(""); + fixture.setDynamicRuleAlgorithmFunctions(new LinkedList()); + fixture.setPolicyClass(PolicyClass.Action); + fixture.setEcompName(""); + fixture.setConfigBodyType(PolicyType.JSON); + fixture.setDynamicRuleAlgorithmField1(new LinkedList()); + fixture.setPriority(""); + fixture.setActionPerformer(""); + fixture.setConfigBody(""); + String policyName = ""; + + fixture.setPolicyName(policyName); + + // add additional test code here + } + + /** + * Run the void setPriority(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testSetPriority_1() + throws Exception { + PolicyParameters fixture = new PolicyParameters(); + fixture.setRequestID(UUID.randomUUID()); + fixture.setActionAttribute(""); + fixture.setAttributes(new Hashtable()); + fixture.setDynamicRuleAlgorithmLabels(new LinkedList()); + fixture.setPolicyDescription(""); + + fixture.setPolicyConfigType(PolicyConfigType.BRMS_PARAM); + fixture.setDynamicRuleAlgorithmField2(new LinkedList()); + fixture.setPolicyName(""); + fixture.setConfigName(""); + fixture.setDynamicRuleAlgorithmFunctions(new LinkedList()); + fixture.setPolicyClass(PolicyClass.Action); + fixture.setEcompName(""); + fixture.setConfigBodyType(PolicyType.JSON); + fixture.setDynamicRuleAlgorithmField1(new LinkedList()); + fixture.setPriority(""); + fixture.setActionPerformer(""); + fixture.setConfigBody(""); + String priority = ""; + + fixture.setPriority(priority); + + // add additional test code here + } + + /** + * Run the void setRequestID(UUID) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testSetRequestID_1() + throws Exception { + PolicyParameters fixture = new PolicyParameters(); + fixture.setRequestID(UUID.randomUUID()); + fixture.setActionAttribute(""); + fixture.setAttributes(new Hashtable()); + fixture.setDynamicRuleAlgorithmLabels(new LinkedList()); + fixture.setPolicyDescription(""); + + fixture.setPolicyConfigType(PolicyConfigType.BRMS_PARAM); + fixture.setDynamicRuleAlgorithmField2(new LinkedList()); + fixture.setPolicyName(""); + fixture.setConfigName(""); + fixture.setDynamicRuleAlgorithmFunctions(new LinkedList()); + fixture.setPolicyClass(PolicyClass.Action); + fixture.setEcompName(""); + fixture.setConfigBodyType(PolicyType.JSON); + fixture.setDynamicRuleAlgorithmField1(new LinkedList()); + fixture.setPriority(""); + fixture.setActionPerformer(""); + fixture.setConfigBody(""); + UUID requestID = UUID.randomUUID(); + + fixture.setRequestID(requestID); + + // add additional test code here + } + + /** + * Perform pre-test initialization. + * + * @throws Exception + * if the initialization fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Before + public void setUp() + throws Exception { + // add additional set up code here + } + + /** + * Perform post-test clean-up. + * + * @throws Exception + * if the clean-up fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @After + public void tearDown() + throws Exception { + // Add additional tear down code here + } + + /** + * Launch the test. + * + * @param args the command line arguments + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(PolicyParametersTest.class); + } +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyResponseStatusTest.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyResponseStatusTest.java new file mode 100644 index 000000000..5841571bd --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyResponseStatusTest.java @@ -0,0 +1,154 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.test; + +import org.junit.*; +import org.openecomp.policy.api.PolicyResponseStatus; + +import static org.junit.Assert.*; + +/** + * The class PolicyResponseStatusTest contains tests for the class {@link PolicyResponseStatus}. + * + * @generatedBy CodePro at 6/1/16 1:41 PM + * @version $Revision: 1.0 $ + */ +public class PolicyResponseStatusTest { + /** + * Run the PolicyResponseStatus getStatus(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testGetStatus_1() + throws Exception { + String responseStatus = ""; + + PolicyResponseStatus result = PolicyResponseStatus.getStatus(responseStatus); + + // add additional test code here + assertNotNull(result); + assertEquals("no_action", result.toString()); + assertEquals("NO_ACTION_REQUIRED", result.name()); + assertEquals(0, result.ordinal()); + } + + /** + * Run the PolicyResponseStatus getStatus(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testGetStatus_2() + throws Exception { + String responseStatus = ""; + + PolicyResponseStatus result = PolicyResponseStatus.getStatus(responseStatus); + + // add additional test code here + assertNotNull(result); + assertEquals("no_action", result.toString()); + assertEquals("NO_ACTION_REQUIRED", result.name()); + assertEquals(0, result.ordinal()); + } + + /** + * Run the PolicyResponseStatus getStatus(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testGetStatus_3() + throws Exception { + String responseStatus = ""; + + PolicyResponseStatus result = PolicyResponseStatus.getStatus(responseStatus); + + // add additional test code here + assertNotNull(result); + assertEquals("no_action", result.toString()); + assertEquals("NO_ACTION_REQUIRED", result.name()); + assertEquals(0, result.ordinal()); + } + + /** + * Run the String toString() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testToString_1() + throws Exception { + PolicyResponseStatus fixture = PolicyResponseStatus.ACTION_ADVISED; + + String result = fixture.toString(); + + // add additional test code here + assertEquals("action_advised", result); + } + + /** + * Perform pre-test initialization. + * + * @throws Exception + * if the initialization fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Before + public void setUp() + throws Exception { + // add additional set up code here + } + + /** + * Perform post-test clean-up. + * + * @throws Exception + * if the clean-up fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @After + public void tearDown() + throws Exception { + // Add additional tear down code here + } + + /** + * Launch the test. + * + * @param args the command line arguments + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(PolicyResponseStatusTest.class); + } +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyResponseTest.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyResponseTest.java new file mode 100644 index 000000000..f99a238e5 --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyResponseTest.java @@ -0,0 +1,75 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.test; + +import java.util.Map; + +import org.junit.*; +import org.openecomp.policy.api.PolicyResponse; + +import static org.junit.Assert.*; + +/** + * The class PolicyResponseTest contains tests for the class {@link PolicyResponse}. + * + * @generatedBy CodePro at 6/1/16 1:41 PM + * @version $Revision: 1.0 $ + */ +public class PolicyResponseTest { + /** + * Perform pre-test initialization. + * + * @throws Exception + * if the initialization fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Before + public void setUp() + throws Exception { + // add additional set up code here + } + + /** + * Perform post-test clean-up. + * + * @throws Exception + * if the clean-up fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @After + public void tearDown() + throws Exception { + // Add additional tear down code here + } + + /** + * Launch the test. + * + * @param args the command line arguments + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(PolicyResponseTest.class); + } +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyTypeTest.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyTypeTest.java new file mode 100644 index 000000000..5b31e857b --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PolicyTypeTest.java @@ -0,0 +1,91 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.test; + +import org.junit.*; +import org.openecomp.policy.api.PolicyType; + +import static org.junit.Assert.*; + +/** + * The class PolicyTypeTest contains tests for the class {@link PolicyType}. + * + * @generatedBy CodePro at 6/1/16 1:41 PM + * @version $Revision: 1.0 $ + */ +public class PolicyTypeTest { + /** + * Run the String toString() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Test + public void testToString_1() + throws Exception { + PolicyType fixture = PolicyType.JSON; + + String result = fixture.toString(); + + // add additional test code here + assertEquals("json", result); + } + + /** + * Perform pre-test initialization. + * + * @throws Exception + * if the initialization fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @Before + public void setUp() + throws Exception { + // add additional set up code here + } + + /** + * Perform post-test clean-up. + * + * @throws Exception + * if the clean-up fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + @After + public void tearDown() + throws Exception { + // Add additional tear down code here + } + + /** + * Launch the test. + * + * @param args the command line arguments + * + * @generatedBy CodePro at 6/1/16 1:41 PM + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(PolicyTypeTest.class); + } +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PushPolicyParametersTest.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PushPolicyParametersTest.java new file mode 100644 index 000000000..ef005f1f4 --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/PushPolicyParametersTest.java @@ -0,0 +1,269 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.test; + +import java.util.UUID; + +import org.junit.*; +import org.openecomp.policy.api.PushPolicyParameters; + +import static org.junit.Assert.*; + +/** + * The class PushPolicyParametersTest contains tests for the class {@link PushPolicyParameters}. + * + * @generatedBy CodePro at 6/1/16 1:40 PM + * @version $Revision: 1.0 $ + */ +public class PushPolicyParametersTest { + /** + * Run the PushPolicyParameters() constructor test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testPushPolicyParameters_1() + throws Exception { + + PushPolicyParameters result = new PushPolicyParameters(); + + // add additional test code here + assertNotNull(result); + assertEquals(null, result.getPolicyName()); + assertEquals(null, result.getRequestID()); + assertEquals(null, result.getPolicyType()); + assertEquals(null, result.getPdpGroup()); + } + + /** + * Run the PushPolicyParameters(String,String,String,UUID) constructor test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testPushPolicyParameters_2() + throws Exception { + String policyName = ""; + String policyType = ""; + String pdpGroup = ""; + UUID requestID = UUID.randomUUID(); + + PushPolicyParameters result = new PushPolicyParameters(policyName, policyType, pdpGroup, requestID); + + // add additional test code here + assertNotNull(result); + assertEquals("", result.getPolicyName()); + assertEquals("", result.getPolicyType()); + assertEquals("", result.getPdpGroup()); + } + + /** + * Run the String getPdpGroup() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetPdpGroup_1() + throws Exception { + PushPolicyParameters fixture = new PushPolicyParameters("", "", "", UUID.randomUUID()); + + String result = fixture.getPdpGroup(); + + // add additional test code here + assertEquals("", result); + } + + /** + * Run the String getPolicyName() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetPolicyName_1() + throws Exception { + PushPolicyParameters fixture = new PushPolicyParameters("", "", "", UUID.randomUUID()); + + String result = fixture.getPolicyName(); + + // add additional test code here + assertEquals("", result); + } + + /** + * Run the String getPolicyType() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetPolicyType_1() + throws Exception { + PushPolicyParameters fixture = new PushPolicyParameters("", "", "", UUID.randomUUID()); + + String result = fixture.getPolicyType(); + + // add additional test code here + assertEquals("", result); + } + + /** + * Run the UUID getRequestID() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testGetRequestID() + throws Exception { + PushPolicyParameters fixture = new PushPolicyParameters("", "", "", UUID.fromString("d1dbaac1-0944-4f07-9ce7-733c697537ea")); + + UUID result = fixture.getRequestID(); + + // add additional test code here + assertNotNull(result); + assertEquals("d1dbaac1-0944-4f07-9ce7-733c697537ea", result.toString()); + assertEquals(4, result.version()); + assertEquals(2, result.variant()); + assertEquals(-7140611980868110358L, result.getLeastSignificantBits()); + assertEquals(-3324876153822097657L, result.getMostSignificantBits()); + } + + /** + * Run the void setPdpGroup(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetPdpGroup_1() + throws Exception { + PushPolicyParameters fixture = new PushPolicyParameters("", "", "", UUID.randomUUID()); + String pdpGroup = ""; + + fixture.setPdpGroup(pdpGroup); + + // add additional test code here + } + + /** + * Run the void setPolicyName(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetPolicyName_1() + throws Exception { + PushPolicyParameters fixture = new PushPolicyParameters("", "", "", UUID.randomUUID()); + String policyName = ""; + + fixture.setPolicyName(policyName); + + // add additional test code here + } + + /** + * Run the void setPolicyType(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetPolicyType_1() + throws Exception { + PushPolicyParameters fixture = new PushPolicyParameters("", "", "", UUID.randomUUID()); + String policyType = ""; + + fixture.setPolicyType(policyType); + + // add additional test code here + } + + /** + * Run the void setRequestID(UUID) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Test + public void testSetRequestID_1() + throws Exception { + PushPolicyParameters fixture = new PushPolicyParameters("", "", "", UUID.randomUUID()); + UUID requestID = UUID.randomUUID(); + + fixture.setRequestID(requestID); + + // add additional test code here + } + + /** + * Perform pre-test initialization. + * + * @throws Exception + * if the initialization fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Before + public void setUp() + throws Exception { + // add additional set up code here + } + + /** + * Perform post-test clean-up. + * + * @throws Exception + * if the clean-up fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @After + public void tearDown() + throws Exception { + // Add additional tear down code here + } + + /** + * Launch the test. + * + * @param args the command line arguments + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(PushPolicyParametersTest.class); + } +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/RemovedPolicyTest.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/RemovedPolicyTest.java new file mode 100644 index 000000000..6a3bf34df --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/RemovedPolicyTest.java @@ -0,0 +1,73 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.test; + +import org.junit.*; +import org.openecomp.policy.api.RemovedPolicy; + +import static org.junit.Assert.*; + +/** + * The class RemovedPolicyTest contains tests for the class {@link RemovedPolicy}. + * + * @generatedBy CodePro at 6/1/16 1:40 PM + * @version $Revision: 1.0 $ + */ +public class RemovedPolicyTest { + /** + * Perform pre-test initialization. + * + * @throws Exception + * if the initialization fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @Before + public void setUp() + throws Exception { + // add additional set up code here + } + + /** + * Perform post-test clean-up. + * + * @throws Exception + * if the clean-up fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + @After + public void tearDown() + throws Exception { + // Add additional tear down code here + } + + /** + * Launch the test. + * + * @param args the command line arguments + * + * @generatedBy CodePro at 6/1/16 1:40 PM + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(RemovedPolicyTest.class); + } +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/SendEventTest.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/SendEventTest.java new file mode 100644 index 000000000..6fb5137a4 --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/SendEventTest.java @@ -0,0 +1,153 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.Before; +import org.junit.Test; +import org.openecomp.policy.api.PolicyEngine; +import org.openecomp.policy.api.PolicyEngineException; +import org.openecomp.policy.api.PolicyEventException; +import org.openecomp.policy.api.PolicyResponse; +import org.openecomp.policy.api.PolicyResponseStatus; + +import org.openecomp.policy.common.logging.flexlogger.*; + +public class SendEventTest { + + private PolicyEngine policyEngine = null; + private Map eventAttributes = new HashMap(); + private Collection policyResponse = null; + private static final Logger logger = FlexLogger.getLogger(SendEventTest.class); + @Before + public void setUp() { + try { + policyEngine = new PolicyEngine("Test/config_pass.properties"); + } catch (PolicyEngineException e) { + logger.error(e.getMessage()); + fail("PolicyEngine Instantiation Error" + e); + } + logger.info("Loaded.. PolicyEngine"); + } + + //@Test + public void testSendEventFail() { + eventAttributes = null; + try { + policyResponse = policyEngine.sendEvent(eventAttributes); + } catch (PolicyEventException e) { + logger.warn(e.getMessage()); + } + assertNull(policyResponse); + } + + //@Test + public void testSendEventFailNull() { + eventAttributes.put("", ""); + try { + policyResponse = policyEngine.sendEvent(eventAttributes); + } catch (PolicyEventException e) { + logger.warn(e.getMessage()); + } + assertNull(policyResponse); + } + + // deprecated Test. + /*@Test + public void testSendEventFailAttribute() { + eventAttributes.put("Fail.key", "Value"); + try { + policyResponse = policyEngine.sendEvent(eventAttributes); + } catch (PolicyEventException e) { + logger.warn(e.getMessage()); + } + assertNull(policyResponse.getPolicyResponseMessage()); + }*/ + + //@Test + public void testSendEventNotValid() { + eventAttributes.put("Action.fail", "Value"); + try { + policyResponse = policyEngine.sendEvent(eventAttributes); + } catch (PolicyEventException e) { + logger.warn(e.getMessage()); + } + for(PolicyResponse policyResponse: this.policyResponse){ + logger.info(policyResponse.getPolicyResponseMessage() + " , " + policyResponse.getPolicyResponseStatus()); + assertNotNull(policyResponse); + assertEquals(PolicyResponseStatus.NO_ACTION_REQUIRED, policyResponse.getPolicyResponseStatus()); + assertNotNull(policyResponse.getPolicyResponseMessage()); + assertNotNull(policyResponse.getRequestAttributes()); + assertNull(policyResponse.getActionTaken()); + assertNull(policyResponse.getActionAdvised()); + } + } + + //@Test + public void testSendEventActionAdvised() { + eventAttributes.put("Key", "Value"); + eventAttributes.put("cpu", "80"); + try { + policyResponse = policyEngine.sendEvent(eventAttributes); + } catch (PolicyEventException e) { + logger.warn(e.getMessage()); + } + for(PolicyResponse policyResponse: this.policyResponse){ + logger.info(policyResponse.getPolicyResponseMessage() + " , " + policyResponse.getPolicyResponseStatus()); + assertNotNull(policyResponse); + assertEquals(PolicyResponseStatus.ACTION_ADVISED, policyResponse.getPolicyResponseStatus()); + assertNotNull(policyResponse.getPolicyResponseMessage()); + assertNotNull(policyResponse.getRequestAttributes()); + assertNull(policyResponse.getActionTaken()); + assertNotNull(policyResponse.getActionAdvised()); + } + } + + //@Test + public void testSendEventActionTaken() { + eventAttributes.put("Key", "Value"); + eventAttributes.put("cpu", "91"); + try { + policyResponse = policyEngine.sendEvent(eventAttributes); + } catch (PolicyEventException e) { + logger.warn(e.getMessage()); + } + for(PolicyResponse policyResponse: this.policyResponse){ + logger.info(policyResponse.getPolicyResponseMessage() + " , " + policyResponse.getPolicyResponseStatus()); + assertNotNull(policyResponse); + assertEquals(PolicyResponseStatus.ACTION_TAKEN, policyResponse.getPolicyResponseStatus()); + assertNotNull(policyResponse.getPolicyResponseMessage()); + assertNotNull(policyResponse.getRequestAttributes()); + assertNotNull(policyResponse.getActionTaken()); + assertNull(policyResponse.getActionAdvised()); + } + } +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/TestRunner.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/TestRunner.java new file mode 100644 index 000000000..69cbd834e --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/TestRunner.java @@ -0,0 +1,49 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.test; + +import org.junit.runner.JUnitCore; +import org.junit.runner.Result; +import org.junit.runner.notification.Failure; + +public class TestRunner { + public static void main(String[] args) { + Result result = JUnitCore.runClasses(PolicyEngineTest.class); + for(Failure failure: result.getFailures()) { + System.out.println("Failed Test: " + failure.toString()); + } + Result results = null; + if(result.wasSuccessful()) { + System.out.println("API Methods are being Tested.. "); + results = JUnitCore.runClasses(GetConfigByPolicyNameTest.class, GetConfigStringTest.class,GetConfigStringStringTest.class,GetConfigStringStringMapTest.class,SendEventTest.class); + for(Failure failure: results.getFailures()) { + System.out.println("Failed Test: " + failure.toString()); + } + System.out.println("Test Results.. "); + System.out.println("Stats: \nRun Time: " + (results.getRunTime()+result.getRunTime()) + "\nTotal Tests:" + results.getRunCount()+ result.getRunCount() + + "\nFailures: " + results.getFailureCount()+ result.getFailureCount()); + System.exit(1); + } + System.out.println("Test Failed.."); + System.out.println("Stats: \nRun Time: " + result.getRunTime() + "\nTests:" + result.getRunCount() + + "\nFailures: " + result.getFailureCount()); + } +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/UpdateTypeTest.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/UpdateTypeTest.java new file mode 100644 index 000000000..909a05f0e --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/UpdateTypeTest.java @@ -0,0 +1,91 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.test; + +import org.junit.*; +import org.openecomp.policy.api.UpdateType; + +import static org.junit.Assert.*; + +/** + * The class UpdateTypeTest contains tests for the class {@link UpdateType}. + * + * @generatedBy CodePro at 6/1/16 1:39 PM + * @version $Revision: 1.0 $ + */ +public class UpdateTypeTest { + /** + * Run the String toString() method test. + * + * @throws Exception + * + * @generatedBy CodePro at 6/1/16 1:39 PM + */ + @Test + public void testToString_1() + throws Exception { + UpdateType fixture = UpdateType.NEW; + + String result = fixture.toString(); + + // add additional test code here + assertEquals("new", result); + } + + /** + * Perform pre-test initialization. + * + * @throws Exception + * if the initialization fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:39 PM + */ + @Before + public void setUp() + throws Exception { + // add additional set up code here + } + + /** + * Perform post-test clean-up. + * + * @throws Exception + * if the clean-up fails for some reason + * + * @generatedBy CodePro at 6/1/16 1:39 PM + */ + @After + public void tearDown() + throws Exception { + // Add additional tear down code here + } + + /** + * Launch the test. + * + * @param args the command line arguments + * + * @generatedBy CodePro at 6/1/16 1:39 PM + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(UpdateTypeTest.class); + } +} diff --git a/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/package-info.java b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/package-info.java new file mode 100644 index 000000000..e678c4be2 --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/openecomp/policy/test/package-info.java @@ -0,0 +1,24 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + * API JUNIT TestCases. + */ +package org.openecomp.policy.test; diff --git a/PolicyEngineClient/.gitignore b/PolicyEngineClient/.gitignore new file mode 100644 index 000000000..b83d22266 --- /dev/null +++ b/PolicyEngineClient/.gitignore @@ -0,0 +1 @@ +/target/ diff --git a/PolicyEngineClient/config.properties b/PolicyEngineClient/config.properties new file mode 100644 index 000000000..4bc176d53 --- /dev/null +++ b/PolicyEngineClient/config.properties @@ -0,0 +1,53 @@ +### +# ============LICENSE_START======================================================= +# PolicyEngineClient +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +# PIP Engine Definition +PDP_URL1 = http://localhost:8081/pdp/ , testpdp , alpha123 +PAP_URL = http://localhost:9091/pap/ , testpap , alpha123 +#PDP_URL1 = http://localhost:8082/pdp/, testpdp, alpha456 +#PAP_URL = http://localhost:8070/pap/, testpap, alpha123 +NOTIFICATION_TYPE=websocket +NOTIFICATION_UEB_SERVERS=localhost.com +CLIENT_ID= +CLIENT_KEY=PolicyR0ck$ +ENVIRONMENT=TEST + +########################################### +## FOR CONNECTION TO THE IST PAP AND PDP ## +########################################### +#PAP_URL=http://localhost:9091/pap/ , testpap, alpha123 +#PAP_URL=http://localhost:9091/pap/,testpap,alpha123 +#PDP_URL1=http://localhost:8081/pdp/ , testpdp, alpha123 +#PDP_URL2=http://localhost:8081/pdp/ , testpdp, alpha123 +#NOTIFICATION_TYPE=ueb +#NOTIFICATION_UEB_SERVERS=localhost.com +#CLIENT_ID=PyPDPServer +#CLIENT_KEY=test + + +########################################### +## FOR CONNECTION TO THE E2E PAP AND PDP ## +########################################### +#PDP_URL = http://localhost:8081/pdp/, testpdp, alpha123 +#PAP_URL = http://localhost:9091/pap/, testpap, alpha123 +#NOTIFICATION_TYPE=websocket +#NOTIFICATION_UEB_SERVERS=localhost.com +#CLIENT_ID=PyPDPServer +#CLIENT_KEY=test diff --git a/PolicyEngineClient/config.test.properties b/PolicyEngineClient/config.test.properties new file mode 100644 index 000000000..d9a955c2b --- /dev/null +++ b/PolicyEngineClient/config.test.properties @@ -0,0 +1,24 @@ +### +# ============LICENSE_START======================================================= +# PolicyEngineClient +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +PDP_URL= http://localhost:8082/pdp/, testpdp, alpha456 +PAP_URL = http://localhost:9090/pap/ , testpap, alpha123 +CLIENT_ID= +CLIENT_KEY= diff --git a/PolicyEngineClient/input.testCases b/PolicyEngineClient/input.testCases new file mode 100644 index 000000000..edb374001 --- /dev/null +++ b/PolicyEngineClient/input.testCases @@ -0,0 +1,419 @@ +[ +{ + "id": 1, + "testCaseDescription": "test GetConfig String Not valid", + "testFor": "getConfig", + "PDP_URLConfigFile": "config.properties" + "ECOMPName": "fail", + "ConfigName": null, + "configAttributes": null, + "expectedResult":[ + "Policy Name: null Policy version: null - not_found", + ] +}, +{ + "id": 2, + "testCaseDescription": "test Get ConfigString Valid JSON", + "testFor": "getConfig", + "PDP_URLConfigFile": "config.properties" + "ECOMPName": "JSON", + "ConfigName": null, + "configAttributes": null, + "expectedResult":[ + "Policy Name: null Policy version: null - not_found", + ] +}, +{ + "id": 3, + "testCaseDescription": "test Get ConfigString Valid XML", + "testFor": "getConfig", + "PDP_URLConfigFile": "config.properties" + "ECOMPName": "XML", + "ConfigName": null, + "configAttributes": null, + "expectedResult":[ + "Policy Name: null Policy version: null - not_found", + ] +}, +{ + "id": 4, + "testCaseDescription": "test Get ConfigString Valid properties", + "testFor": "getConfig", + "PDP_URLConfigFile": "config.properties" + "ECOMPName": "Properties", + "ConfigName": null, + "configAttributes": null, + "expectedResult":[ + "Policy Name: null Policy version: null - not_found", + ] +}, +{ + "id": 5, + "testCaseDescription": "test Get ConfigString Valid other", + "testFor": "getConfig", + "PDP_URLConfigFile": "config.properties" + "ECOMPName": "Other", + "ConfigName": null, + "configAttributes": null, + "expectedResult":[ + "Policy Name: null Policy version: null - not_found", + ] +}, +{ + "id": 6, + "testCaseDescription": "test GetConfig String String Fail", + "testFor": "getConfig", + "PDP_URLConfigFile": "config.properties" + "ECOMPName": null, + "ConfigName": null, + "configAttributes": null, + "expectedResult":[ + "org.openecomp.policy.api.PolicyConfigException: No eCOMPComponentName given.", + ] +}, +{ + "id": 7, + "testCaseDescription": "test GetConfig String String Fail1", + "testFor": "getConfig", + "PDP_URLConfigFile": "config.properties" + "ECOMPName": null, + "ConfigName": null, + "configAttributes": null, + "expectedResult":[ + "org.openecomp.policy.api.PolicyConfigException: No eCOMPComponentName given." + + ] +}, +{ + "id": 8, + "testCaseDescription": "test GetConfig String String Valid ", + "testFor": "getConfig", + "PDP_URLConfigFile": "config.properties" + "ECOMPName": "fail", + "ConfigName": "fail", + "configAttributes": null, + "expectedResult":[ + "Policy Name: null Policy version: null - not_found", + ] +}, +{ + "id": 9, + "testCaseDescription": "test GetConfig String String Valid JSON", + "testFor": "getConfig", + "PDP_URLConfigFile": "config.properties" + "ECOMPName": "JSON", + "ConfigName": "JSONconfig", + "configAttributes": null, + "expectedResult":[ + "Policy Name: null Policy version: null - not_found", + ] +}, +{ + "id": 10, + "testCaseDescription": "test GetConfig String String Valid XML", + "testFor": "getConfig", + "PDP_URLConfigFile": "config.properties" + "ECOMPName": "XML", + "ConfigName": "XMLconfig", + "configAttributes": null, + "expectedResult":[ + "Policy Name: null Policy version: null - not_found", + ] +}, +{ + "id": 11, + "testCaseDescription": "test GetConfig String String Valid properties", + "testFor": "getConfig", + "PDP_URLConfigFile": "config.properties" + "ECOMPName": "Properties", + "ConfigName": "PropConfig", + "configAttributes": null, + "expectedResult":[ + "Policy Name: null Policy version: null - not_found", + ] +}, +{ + "id": 12, + "testCaseDescription": "test GetConfig String String Valid other", + "testFor": "getConfig", + "PDP_URLConfigFile": "config.properties" + "ECOMPName": "Other", + "ConfigName": "OtherConfig", + "configAttributes": null, + "expectedResult":[ + "Policy Name: null Policy version: null - not_found", + ] +}, +{ + "id": 13, + "testCaseDescription": "test GetConfig String String String fail", + "testFor": "getConfig", + "PDP_URLConfigFile": "config.properties" + "ECOMPName": null, + "ConfigName": null, + "configAttributes": null, + "expectedResult":[ + "org.openecomp.policy.api.PolicyConfigException: No eCOMPComponentName given." + ] +}, +{ + "id": 14, + "testCaseDescription": "test GetConfig String String String fail1", + "testFor": "getConfig", + "PDP_URLConfigFile": "config.properties" + "ECOMPName": null, + "ConfigName": "testFail", + "configAttributes": [ + { + "key": "TestValue", + "value": "Fail", + }, + ], + "expectedResult":[ + "org.openecomp.policy.api.PolicyConfigException: No eCOMPComponentName given.", + ] +}, +{ + "id": 15, + "testCaseDescription": "test GetConfig String String String fail2", + "testFor": "getConfig", + "PDP_URLConfigFile": "config.properties" + "ECOMPName": "TestFail", + "ConfigName": null, + "configAttributes": [ + { + "key": "TestValue", + "value": "Fail", + }, + ], + "expectedResult":[ + "Policy Name: null Policy version: null - not_found", + ] +}, +{ + "id": 16, + "testCaseDescription": "test GetConfig String String String fail3", + "testFor": "getConfig", + "PDP_URLConfigFile": "config.properties" + "ECOMPName": "TestFail", + "ConfigName": "configFail", + "configAttributes": null, + "expectedResult":[ + "Policy Name: null Policy version: null - not_found", + ] +}, +{ + "id": 17, + "testCaseDescription": "test GetConfig String String String fail4", + "testFor": "getConfig", + "PDP_URLConfigFile": "config.properties" + "ECOMPName": "TestFail", + "ConfigName": "configFail", + "configAttributes": [ + { + "key": "", + "value": "", + }, + ], + "expectedResult":[ + "org.openecomp.policy.api.PolicyConfigException: Cannot have an empty Key", + + ] +}, +{ + "id": 18, + "testCaseDescription": "test GetConfig String String String Valid", + "testFor": "getConfig", + "PDP_URLConfigFile": "config.properties" + "ECOMPName": "TestFail", + "ConfigName": "configFail", + "configAttributes": [ + { + "key": "Action:com.test.fail", + "value": "Value", + }, + ], + "expectedResult":[ + "Policy Name: null Policy version: null - not_found", + ] +}, +{ + "id": 19, + "testCaseDescription": "test GetConfig String String String Valid JSON", + "testFor": "getConfig", + "PDP_URLConfigFile": "config.properties" + "ECOMPName": "JSON", + "ConfigName": "JSONconfig", + "configAttributes": [ + { + "key": "Resource.com:test:resource:json", + "value":"Test", + }, + { + "key": "Action.com:test:action:json", + "value":"TestJSON", + }, + { + "key": "Subject.com:test:subject:json", + "value":"TestSubject", + } + ], + "expectedResult":[ + "Policy Name: null Policy version: null - not_found", + ] +}, +{ + "id": 20, + "testCaseDescription": "test GetConfig String String String Valid XML", + "testFor": "getConfig", + "PDP_URLConfigFile": "config.properties" + "ECOMPName": "XML", + "ConfigName": "XMLconfig", + "configAttributes": [ + { + "key": "Resource.com:test:resource:json", + "value":"Test", + }, + { + "key": "Action.com:test:action:json", + "value":"TestJSON", + }, + { + "key": "Subject.com:test:subject:json", + "value":"TestSubject", + } + ], + "expectedResult":[ + "Policy Name: null Policy version: null - not_found", + ] +}, +{ + "id": 21, + "testCaseDescription": "test GetConfig String String String Valid properties", + "testFor": "getConfig", + "PDP_URLConfigFile": "config.properties" + "ECOMPName": "Properties", + "ConfigName": "PropConfig", + "configAttributes": [ + { + "key": "Resource.com:test:resource:json", + "value":"Test", + }, + { + "key": "Action.com:test:action:json", + "value":"TestJSON", + }, + { + "key": "Subject.com:test:subject:json", + "value":"TestSubject", + } + ], + "expectedResult":[ + "Policy Name: null Policy version: null - not_found", + ] +}, +{ + "id": 22, + "testCaseDescription": "test GetConfig String String String Valid other", + "testFor": "getConfig", + "PDP_URLConfigFile": "config.properties" + "ECOMPName": "Other", + "ConfigName": "OtherConfig", + "configAttributes": [ + { + "key": "Resource.com:test:resource:json", + "value":"Test", + }, + { + "key": "Action.com:test:action:json", + "value":"TestJSON", + }, + { + "key": "Subject.com:test:subject:json", + "value":"TestSubject", + } + ], + "expectedResult":[ + "Policy Name: null Policy version: null - not_found", + ] +}, +{ + "id": 23, + "testCaseDescription": "test SendEvent Fail", + "testFor": "getAction", + "PDP_URLConfigFile": "config.properties", + "eventAttributes": null, + "expectedResult":[ + "org.openecomp.policy.api.PolicyEventException: No EventAttributes Given.", + ] +}, +{ + "id": 24, + "testCaseDescription": "test SendEvent Fail null", + "testFor": "getAction", + "PDP_URLConfigFile": "config.properties", + "eventAttributes": [ + { + "key": "", + "value": "" + }, + ], + "expectedResult":[ + "org.openecomp.policy.api.PolicyEventException: Cannot have an empty Key", + + ] +}, +{ + "id": 25, + "testCaseDescription": "test SendEvent Not Valid", + "testFor": "getAction", + "PDP_URLConfigFile": "config.properties", + "eventAttributes": [ + { + "key": "Action.fail", + "value": "Value" + }, + ], + "expectedResult":[ + "Decision not a Permit. : no_action", + ] +}, +{ + "id": 26, + "testCaseDescription": "test SendEvent Action Advised", + "testFor": "getAction", + "PDP_URLConfigFile": "config.properties", + "eventAttributes": [ + { + "key": "Key", + "value": "Value" + }, + { + "key": "cpu", + "value": "80" + }, + ], + "expectedResult":[ + "Decision not a Permit. : no_action", + ] +}, +{ + "id": 27, + "testCaseDescription": "test SendEvent Action Taken", + "testFor": "getAction", + "PDP_URLConfigFile": "config.properties", + "eventAttributes": [ + { + "key": "Key", + "value": "Value" + }, + { + "key": "cpu", + "value": "91" + }, + ], + "expectedResult":[ + "Decision not a Permit. : no_action", + ] +}, +] \ No newline at end of file diff --git a/PolicyEngineClient/policyLogger.properties b/PolicyEngineClient/policyLogger.properties new file mode 100644 index 000000000..3c3f3b5f5 --- /dev/null +++ b/PolicyEngineClient/policyLogger.properties @@ -0,0 +1,44 @@ +### +# ============LICENSE_START======================================================= +# PolicyEngineClient +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +################################### Set concurrentHashMap and timer info ####################### +#Timer initial delay and the delay between in milliseconds before task is to be execute. +timer.delay.time=1000 +#Timer scheduleAtFixedRate period - time in milliseconds between successive task executions. +check.interval= 30000 +#Longest time an event info can be stored in the concurrentHashMap for logging - in seconds. +event.expired.time=86400 +#Size of the concurrentHashMap which stores the event starting time, etc - when its size reaches this limit, the Timer gets executed +#to remove all expired records from this concurrentHashMap. +concurrentHashMap.limit=5000 +#Size of the concurrentHashMap - when its size drops to this point, stop the Timer +stop.check.point=2500 +################################### Set logging format ############################################# +# set EELF for EELF logging format, set LOG4J for using log4j, set SYSTEMOUT for using system.out.println +logger.type=EELF +#################################### Set level for EELF or SYSTEMOUT logging ################################## +# Set level for debug file. Set DEBUG to enable .info, .warn and .debug; set INFO for enable .info and .warn; set OFF to disable all +debugLogger.level=INFO +# Set level for metrics file. Set OFF to disable; set ON to enable +metricsLogger.level=ON +# Set level for error file. Set OFF to disable; set ON to enable +error.level=ON +# Set level for audit file. Set OFF to disable; set ON to enable +audit.level=ON diff --git a/PolicyEngineClient/pom.xml b/PolicyEngineClient/pom.xml new file mode 100644 index 000000000..8d667dd6c --- /dev/null +++ b/PolicyEngineClient/pom.xml @@ -0,0 +1,62 @@ + + + + + 4.0.0 + + org.openecomp.policy.engine + PolicyEngineSuite + 1.0.0-SNAPSHOT + + org.openecomp.policy.engine + PolicyEngineClient + + + org.openecomp.policy.engine + PolicyEngineAPI + ${project.version} + + + com.googlecode.json-simple + json-simple + 1.1 + + + org.apache.httpcomponents + httpclient + 4.5 + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.2 + + 1.8 + 1.8 + + + + + diff --git a/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/ActionPolicyClient.java b/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/ActionPolicyClient.java new file mode 100644 index 000000000..4ecc488c5 --- /dev/null +++ b/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/ActionPolicyClient.java @@ -0,0 +1,117 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineClient + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policyEngine; + +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.openecomp.policy.api.AttributeType; +import org.openecomp.policy.api.PolicyChangeResponse; +import org.openecomp.policy.api.PolicyClass; +import org.openecomp.policy.api.PolicyConfigType; +import org.openecomp.policy.api.PolicyEngine; +import org.openecomp.policy.api.PolicyParameters; +import org.openecomp.policy.api.PolicyType; + +public class ActionPolicyClient { + static Boolean isEdit = true; + public static void main(String[] args) { + try { + PolicyEngine policyEngine = new PolicyEngine("config.properties"); + PolicyParameters policyParameters = new PolicyParameters(); + // Set Policy Type + policyParameters.setPolicyClass(PolicyClass.Action); //required + policyParameters.setPolicyName("MikeAPItesting.testActionAPI5"); //required + policyParameters.setPolicyDescription("This is a sample Action policy update example with no Action Body"); //optional + //policyParameters.setPolicyScope("MikeAPItesting"); //Directory will be created where the Policies are saved... this displays a a subscope on the GUI + + //Set the Component Attributes... These are Optional + Map configAttributes = new HashMap(); + configAttributes.put("Template", "UpdateTemplate"); + configAttributes.put("controller", "default"); + configAttributes.put("SamPoll", "30"); + configAttributes.put("value", "abcd"); + + Map> attributes = new HashMap>(); + attributes.put(AttributeType.MATCHING, configAttributes); + policyParameters.setAttributes(attributes); + + //Set the Rule Algorithm + // Map>> translated to Map>> + Map>> ruleAlgorithm = new HashMap>>(); + + List dynamicRuleAlgorithmLabels = new LinkedList(); + List dynamicRuleAlgorithmFunctions = new LinkedList(); + List dynamicRuleAlgorithmField1 = new LinkedList(); + List dynamicRuleAlgorithmField2 = new LinkedList(); + + //Example of a complex Rule algorithm + /* label field1 function field2 + * ***************************************************** + * A1 cobal integer-equal 90 + * A2 cap string-contains ca + * A3 cobal integer-equal 90 + * A4 A2 and A3 + * A5 Config integer-greater-than 45 + * A6 A4 ` or A5 + * A7 A1 and A6 + */ + dynamicRuleAlgorithmLabels = Arrays.asList("A1","A2","A3","A4","A5","A6","A7"); + dynamicRuleAlgorithmField1 = Arrays.asList("cobal","cap","cobal","A2","Config","A4","A1"); + dynamicRuleAlgorithmFunctions = Arrays.asList("integer-equal","string-contains","integer-equal","and","integer-greater-than","or","and"); + dynamicRuleAlgorithmField2 = Arrays.asList("90","ca","90","A3","45","A5","A6"); + + policyParameters.setDynamicRuleAlgorithmLabels(dynamicRuleAlgorithmLabels); + policyParameters.setDynamicRuleAlgorithmField1(dynamicRuleAlgorithmField1); + policyParameters.setDynamicRuleAlgorithmFunctions(dynamicRuleAlgorithmFunctions); + policyParameters.setDynamicRuleAlgorithmField2(dynamicRuleAlgorithmField2); + + policyParameters.setActionPerformer("PEP"); + policyParameters.setActionAttribute("mikeTest2"); + policyParameters.setRequestID(UUID.randomUUID()); + + // API method to create Policy or update policy + PolicyChangeResponse response = null; + if (!isEdit) { + response = policyEngine.createPolicy(policyParameters); + } else { + response = policyEngine.updatePolicy(policyParameters); + } + + if(response.getResponseCode()==200){ + System.out.println(response.getResponseMessage()); + System.out.println("Policy Created Successfully!"); + }else{ + System.out.println("Error! " + response.getResponseMessage()); + } + } catch (Exception e) { + System.err.println(e.getMessage()); + } + } + +} + + diff --git a/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/BrmsParamPolicyClient.java b/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/BrmsParamPolicyClient.java new file mode 100644 index 000000000..3d80fe2ef --- /dev/null +++ b/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/BrmsParamPolicyClient.java @@ -0,0 +1,107 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineClient + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policyEngine; + +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import org.openecomp.policy.api.AttributeType; +import org.openecomp.policy.api.PolicyChangeResponse; +import org.openecomp.policy.api.PolicyConfigType; +import org.openecomp.policy.api.PolicyEngine; +import org.openecomp.policy.api.PolicyParameters; + + +public class BrmsParamPolicyClient { + + public static void main(String[] args) { + try { + + PolicyEngine policyEngine = new PolicyEngine("config.properties"); + + PolicyParameters policyParameters = new PolicyParameters(); + + // Set Policy Type(Mandatory) + policyParameters.setPolicyConfigType(PolicyConfigType.BRMS_PARAM); + + // Set Policy Name(Mandatory) + policyParameters.setPolicyName("Lakshman.testParamPolicyThree"); + + // Set Safe Policy value for Risk Type + SimpleDateFormat dateformat3 = new SimpleDateFormat("dd/MM/yyyy"); + Date date = dateformat3.parse("15/10/2016"); + policyParameters.setTtlDate(date); + // Set Safe Policy value for Guard + policyParameters.setGuard(true); + // Set Safe Policy value for Risk Level + policyParameters.setRiskLevel("5"); + // Set Safe Policy value for Risk Type + policyParameters.setRiskType("PROD"); + + // Set description of the policy(Optional) + policyParameters.setPolicyDescription("This is a sample BRMS Param policy creation example"); + + //Set Scope folder where the policy needs to be created(Mandatory) + //policyParameters.setPolicyScope("Lakshman"); + + // Set BRMS Param Template Attributes(Mandatory) + Map ruleAttributes = new HashMap(); + ruleAttributes.put("templateName", "Sample"); // This sampleTemplate is the Template name from dictionary. + ruleAttributes.put("controller", "default"); // Set Rule to a PDP Controller, default is the controller name. + ruleAttributes.put("SamPoll", "300"); // Template specific key and value set by us. + ruleAttributes.put("value", "abcd"); // Template specific key and value set by us. + Map> attributes = new HashMap>(); + attributes.put(AttributeType.RULE, ruleAttributes); + policyParameters.setAttributes(attributes); + + //Set a random UUID(Mandatory) + policyParameters.setRequestID(UUID.randomUUID()); + + // CreatePolicy method to create Policy. + + PolicyChangeResponse response = policyEngine.updatePolicy(policyParameters); + + if(response.getResponseCode()==200){ + + System.out.println(response.getResponseMessage()); + + System.out.println("Policy Created Successfully!"); + + }else{ + + System.out.println("Error! " + response.getResponseMessage()); + + } + + } catch (Exception e) { + + System.err.println(e.getMessage()); + + } + + } + +} + + diff --git a/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/BrmsRawPolicyClient.java b/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/BrmsRawPolicyClient.java new file mode 100644 index 000000000..a8601c1cb --- /dev/null +++ b/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/BrmsRawPolicyClient.java @@ -0,0 +1,144 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineClient + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policyEngine; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.StringReader; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.text.SimpleDateFormat; +import java.util.Arrays; +import java.util.Collection; +import java.util.Date; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import javax.json.Json; +import javax.json.JsonObject; +import javax.json.JsonReader; + +import org.openecomp.policy.api.AttributeType; +import org.openecomp.policy.api.PolicyChangeResponse; +import org.openecomp.policy.api.PolicyClass; +import org.openecomp.policy.api.PolicyConfigType; +import org.openecomp.policy.api.PolicyEngine; +import org.openecomp.policy.api.PolicyParameters; +import org.openecomp.policy.api.PolicyType; + +public class BrmsRawPolicyClient { + static Boolean isEdit = true; + + //Reads a File and converts into a String. + private static String readFile( String file ) throws IOException { + BufferedReader reader = new BufferedReader( new FileReader (file)); + String line = null; + StringBuilder stringBuilder = new StringBuilder(); + String ls = System.getProperty("line.separator"); + + try { + while( ( line = reader.readLine() ) != null ) { + stringBuilder.append( line ); + stringBuilder.append( ls ); + } + + return stringBuilder.toString(); + } finally { + reader.close(); + } + } + + + public static void main(String[] args) { + try { + PolicyEngine policyEngine = new PolicyEngine("config.properties"); + PolicyParameters policyParameters = new PolicyParameters(); + Map attrib= new HashMap(); + attrib.put("cpu","80"); + attrib.put("memory", "50"); + Map> attributes = new HashMap>(); + attributes.put(AttributeType.RULE, attrib); + + // Set Policy Type + policyParameters.setPolicyConfigType(PolicyConfigType.BRMS_RAW); //required + policyParameters.setPolicyName("Lakshman.testBRMSRawAPITwo"); //required + policyParameters.setPolicyDescription("This is a sample BRMS Raw policy body"); //optional + policyParameters.setAttributes(attributes); + //policyParameters.setPolicyScope("Lakshman"); //Directory will be created where the Policies are saved... this displays a a subscope on the GUI + policyParameters.setRequestID(UUID.randomUUID()); + + // Set Safe Policy value for Risk Type + SimpleDateFormat dateformat3 = new SimpleDateFormat("dd/MM/yyyy"); + Date date = dateformat3.parse("15/10/2016"); + policyParameters.setTtlDate(date); + // Set Safe Policy value for Guard + policyParameters.setGuard(true); + // Set Safe Policy value for Risk Level + policyParameters.setRiskLevel("5"); + // Set Safe Policy value for Risk Type + policyParameters.setRiskType("PROD"); + + File rawBodyFile = null; + + Path file = Paths.get("C:\\Users\\testuser\\Documents\\API\\com.Config_BRMS_Raw_TestBrmsPolicy.1.txt"); + rawBodyFile = file.toFile(); + + policyParameters.setConfigBody(readFile(rawBodyFile.toString())); + policyParameters.setConfigBodyType(PolicyType.OTHER); + + /*public String createUpdateBRMSRawPolicy(String policyName, + String policyDescription, + Map dyanamicFieldConfigAttributes, + String brmsRawBody, + String policyScope, + Boolean isEdit, + UUID requestID) */ + + // API method to create Policy or update policy + PolicyChangeResponse response = null; + if (!isEdit) { + response = policyEngine.createPolicy(policyParameters); + } else { + response = policyEngine.updatePolicy(policyParameters); + } + + if(response.getResponseCode()==200){ + System.out.println(response.getResponseMessage()); + System.out.println("Policy Created Successfully!"); + }else{ + System.out.println("Error! " + response.getResponseMessage()); + } + } catch (Exception e) { + System.err.println(e.getMessage()); + } + } + +} + + diff --git a/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/ClosedLoopPolicyClient.java b/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/ClosedLoopPolicyClient.java new file mode 100644 index 000000000..4f0926cca --- /dev/null +++ b/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/ClosedLoopPolicyClient.java @@ -0,0 +1,119 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineClient + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policyEngine; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.InputStream; +import java.io.StringReader; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.UUID; + +import javax.json.Json; +import javax.json.JsonObject; +import javax.json.JsonReader; + +import org.openecomp.policy.api.PolicyChangeResponse; +import org.openecomp.policy.api.PolicyConfigType; +import org.openecomp.policy.api.PolicyEngine; +import org.openecomp.policy.api.PolicyParameters; +import org.openecomp.policy.api.PolicyType; + +public class ClosedLoopPolicyClient { + //For updating a ClosedLoop_Fault policy set the "isEdit" flag to true. + //For creating a ClosedLoop_Fault policy set the "isEdit" flag to false. + static Boolean isEdit = false; + + //Builds JSONObject from File + private static JsonObject buildJSON(File jsonInput, String jsonString) throws FileNotFoundException { + JsonObject json = null;; + + if (jsonString != null && jsonInput == null) { + StringReader in = null; + in = new StringReader(jsonString); + JsonReader jsonReader = Json.createReader(in); + json = jsonReader.readObject(); + } + else { + InputStream in = null; + in = new FileInputStream(jsonInput); + JsonReader jsonReader = Json.createReader(in); + json = jsonReader.readObject(); + } + + return json; + } + public static void main(String[] args) { + try { + PolicyEngine policyEngine = new PolicyEngine("config.properties"); + PolicyParameters policyParameters = new PolicyParameters(); + // Set Policy Type + policyParameters.setPolicyConfigType(PolicyConfigType.ClosedLoop_Fault); + policyParameters.setPolicyName("MikeAPItests.ClosedLoopFaultApiTest45"); + policyParameters.setPolicyDescription("This is a sample ClosedLoop_Fault policy CREATE example"); + //policyParameters.setPolicyScope("MikeAPItests"); + + // Set up Micro Services Attributes + File jsonFile = null; + String MSjsonString= null; + if (MSjsonString == null) { + Path file = Paths.get("C:\\policyAPI\\ClosedLoopJSON\\faultTestJson.json"); + jsonFile = file.toFile(); + } + policyParameters.setConfigBody(buildJSON(jsonFile, MSjsonString).toString()); + policyParameters.setConfigBodyType(PolicyType.JSON); + + policyParameters.setRequestID(UUID.randomUUID()); + // Set Safe Policy value for Risk Type + SimpleDateFormat dateformat3 = new SimpleDateFormat("dd/MM/yyyy"); + Date date = dateformat3.parse("15/10/2016"); + policyParameters.setTtlDate(date); + // Set Safe Policy value for Guard + policyParameters.setGuard(true); + // Set Safe Policy value for Risk Level + policyParameters.setRiskLevel("5"); + // Set Safe Policy value for Risk Type + policyParameters.setRiskType("PROD"); + + // API method to create or update Policy. + PolicyChangeResponse response = null; + if (!isEdit) { + response = policyEngine.createPolicy(policyParameters); + } + else { + response = policyEngine.updatePolicy(policyParameters); + } + + if(response.getResponseCode()==200){ + System.out.println(response.getResponseMessage()); + System.out.println("Policy Created Successfully!"); + }else{ + System.out.println("Error! " + response.getResponseMessage()); + } + } catch (Exception e) { + System.err.println(e.getMessage()); + } + } +} diff --git a/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/ClosedLoopPolicyPerformanceMetricClient.java b/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/ClosedLoopPolicyPerformanceMetricClient.java new file mode 100644 index 000000000..6357cea5a --- /dev/null +++ b/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/ClosedLoopPolicyPerformanceMetricClient.java @@ -0,0 +1,121 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineClient + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policyEngine; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.InputStream; +import java.io.StringReader; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.UUID; + +import javax.json.Json; +import javax.json.JsonObject; +import javax.json.JsonReader; + +import org.openecomp.policy.api.PolicyChangeResponse; +import org.openecomp.policy.api.PolicyConfigType; +import org.openecomp.policy.api.PolicyEngine; +import org.openecomp.policy.api.PolicyParameters; +import org.openecomp.policy.api.PolicyType; + +public class ClosedLoopPolicyPerformanceMetricClient { + + //For updating a ClosedLoop_Fault policy set the "isEdit" flag to true. + //For creating a ClosedLoop_Fault policy set the "isEdit" flag to false. + static Boolean isEdit = true; + + //Builds JSONObject from File + private static JsonObject buildJSON(File jsonInput, String jsonString) throws FileNotFoundException { + JsonObject json = null;; + + if (jsonString != null && jsonInput == null) { + StringReader in = null; + in = new StringReader(jsonString); + JsonReader jsonReader = Json.createReader(in); + json = jsonReader.readObject(); + } + else { + InputStream in = null; + in = new FileInputStream(jsonInput); + JsonReader jsonReader = Json.createReader(in); + json = jsonReader.readObject(); + } + + return json; + } + + public static void main(String[] args) { + try { + PolicyEngine policyEngine = new PolicyEngine("config.properties"); + PolicyParameters policyParameters = new PolicyParameters(); + // Set Policy Type + policyParameters.setPolicyConfigType(PolicyConfigType.ClosedLoop_PM); + policyParameters.setPolicyName("MikeAPItests.ClosedLoopPmApiTest"); + policyParameters.setPolicyDescription("This is a sample ClosedLoop_PM policy CREATE example"); + //policyParameters.setPolicyScope("MikeAPItests"); + + // Set up Micro Services Attributes + File jsonFile = null; + String MSjsonString= null; + if (MSjsonString == null) { + Path file = Paths.get("C:\\policyAPI\\ClosedLoopJSON\\pmTestJson.json"); + jsonFile = file.toFile(); + } + policyParameters.setConfigBody(buildJSON(jsonFile, MSjsonString).toString()); + policyParameters.setConfigBodyType(PolicyType.JSON); + + policyParameters.setRequestID(UUID.randomUUID()); + // Set Safe Policy value for Risk Type + SimpleDateFormat dateformat3 = new SimpleDateFormat("dd/MM/yyyy"); + Date date = dateformat3.parse("15/10/2016"); + policyParameters.setTtlDate(date); + // Set Safe Policy value for Guard + policyParameters.setGuard(true); + // Set Safe Policy value for Risk Level + policyParameters.setRiskLevel("5"); + // Set Safe Policy value for Risk Type + policyParameters.setRiskType("PROD"); + + // API method to create or update Policy. + PolicyChangeResponse response = null; + if (!isEdit) { + response = policyEngine.createPolicy(policyParameters); + } + else { + response = policyEngine.updatePolicy(policyParameters); + } + + if(response.getResponseCode()==200){ + System.out.println(response.getResponseMessage()); + System.out.println("Policy Created Successfully!"); + }else{ + System.out.println("Error! " + response.getResponseMessage()); + } + } catch (Exception e) { + System.err.println(e.getMessage()); + } + } +} diff --git a/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/ConfigBasePolicyClient.java b/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/ConfigBasePolicyClient.java new file mode 100644 index 000000000..dcaaaf188 --- /dev/null +++ b/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/ConfigBasePolicyClient.java @@ -0,0 +1,92 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineClient + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policyEngine; + +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import org.openecomp.policy.api.AttributeType; +import org.openecomp.policy.api.PolicyChangeResponse; +import org.openecomp.policy.api.PolicyConfigType; +import org.openecomp.policy.api.PolicyEngine; +import org.openecomp.policy.api.PolicyParameters; +import org.openecomp.policy.api.PolicyType; + +public class ConfigBasePolicyClient{ + static Boolean isEdit = false; + public static void main(String[] args) { + try { + PolicyEngine policyEngine = new PolicyEngine("config.properties"); + PolicyParameters policyParameters = new PolicyParameters(); + // Set Policy Type + policyParameters.setPolicyConfigType(PolicyConfigType.Base); //required + policyParameters.setPolicyName("MikeConsole.testDeleteAPI6"); //required + policyParameters.setPolicyDescription("This is a sample Config Base policy creation example"); //optional + policyParameters.setEcompName("DCAE"); //required + policyParameters.setConfigName("testBase"); //required + policyParameters.setConfigBodyType(PolicyType.OTHER); //required + policyParameters.setConfigBody("testing"); //required + //policyParameters.setPolicyScope("MikeConsole"); //Directory will be created where the Policies are saved... this displays a a subscope on the GUI + + //Set the Config Attributes... These are Optional + Map configAttributes = new HashMap(); + configAttributes.put("Template", "SampleTemplate"); + configAttributes.put("controller", "default"); + configAttributes.put("SamPoll", "30"); + configAttributes.put("value", "abcd"); + Map> attributes = new HashMap>(); + attributes.put(AttributeType.MATCHING, configAttributes); + policyParameters.setAttributes(attributes); + policyParameters.setRequestID(UUID.randomUUID()); + // Set Safe Policy value for Risk Type + SimpleDateFormat dateformat3 = new SimpleDateFormat("dd/MM/yyyy"); + Date date = dateformat3.parse("15/10/2016"); + policyParameters.setTtlDate(date); + // Set Safe Policy value for Guard + policyParameters.setGuard(true); + // Set Safe Policy value for Risk Level + policyParameters.setRiskLevel("5"); + // Set Safe Policy value for Risk Type + policyParameters.setRiskType("PROD"); + + // API method to create Policy or update policy + PolicyChangeResponse response = null; + if (!isEdit) { + response = policyEngine.createPolicy(policyParameters); + } else { + response = policyEngine.updatePolicy(policyParameters); + } + + if(response.getResponseCode()==200){ + System.out.println(response.getResponseMessage()); + System.out.println("Policy Created Successfully!"); + }else{ + System.out.println("Error! " + response.getResponseMessage()); + } + } catch (Exception e) { + System.err.println(e.getMessage()); + } + } + +} diff --git a/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/ConfigFirewallPolicyClient.java b/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/ConfigFirewallPolicyClient.java new file mode 100644 index 000000000..5c6752bd5 --- /dev/null +++ b/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/ConfigFirewallPolicyClient.java @@ -0,0 +1,117 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineClient + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policyEngine; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.InputStream; +import java.io.StringReader; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.UUID; + +import javax.json.Json; +import javax.json.JsonObject; +import javax.json.JsonReader; + +import org.openecomp.policy.api.PolicyChangeResponse; +import org.openecomp.policy.api.PolicyConfigType; +import org.openecomp.policy.api.PolicyEngine; +import org.openecomp.policy.api.PolicyParameters; +import org.openecomp.policy.api.PolicyType; + +public class ConfigFirewallPolicyClient { + static Boolean isEdit = false; + public static void main(String[] args) { + try{ + PolicyEngine policyEngine = new PolicyEngine("config.properties"); + PolicyParameters policyParameters = new PolicyParameters(); + // Set Policy Type + policyParameters.setPolicyConfigType(PolicyConfigType.Firewall); //required + policyParameters.setPolicyName("MikeAPItesting.testConfigFirewallPolicy1607_1"); //required + //policyParameters.setPolicyScope("MikeAPItesting"); //Directory will be created where the Policies are saved... this displays a a subscope on the GUI + policyParameters.setRequestID(UUID.randomUUID()); + + // Set Safe Policy value for Risk Type + SimpleDateFormat dateformat3 = new SimpleDateFormat("dd/MM/yyyy"); + Date date = dateformat3.parse("15/10/2016"); + policyParameters.setTtlDate(date); + // Set Safe Policy value for Guard + policyParameters.setGuard(true); + // Set Safe Policy value for Risk Level + policyParameters.setRiskLevel("5"); + // Set Safe Policy value for Risk Type + policyParameters.setRiskType("PROD"); + File jsonFile = null; + String jsonRuleList = null; + if (jsonRuleList == null) { + Path file = Paths.get("C:\\policyAPI\\firewallRulesJSON\\Config_FW_1607Rule.json"); + jsonFile = file.toFile(); + } + //buildJSON(jsonFile, jsonRuleList); + policyParameters.setConfigBody(buildJSON(jsonFile, jsonRuleList).toString()); + policyParameters.setConfigBodyType(PolicyType.JSON); + // API method to create Policy or update policy + PolicyChangeResponse response = null; + if (!isEdit) { + response = policyEngine.createPolicy(policyParameters); + } else { + response = policyEngine.updatePolicy(policyParameters); + } + + if(response.getResponseCode()==200){ + System.out.println(response.getResponseMessage()); + System.out.println("Policy Created Successfully!"); + }else{ + System.out.println("Error! " + response.getResponseMessage()); + } + } catch (Exception e) { + System.err.println(e.getMessage()); + } + +} + + private static JsonObject buildJSON(File jsonInput, String jsonString) throws FileNotFoundException { + JsonObject json = null;; + if (jsonString != null && jsonInput == null) { + StringReader in = null; + + in = new StringReader(jsonString); + + JsonReader jsonReader = Json.createReader(in); + json = jsonReader.readObject(); + + + } else { + InputStream in = null; + in = new FileInputStream(jsonInput); + + JsonReader jsonReader = Json.createReader(in); + json = jsonReader.readObject(); + } + + return json; + } + +} diff --git a/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/DecisionPolicyClient.java b/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/DecisionPolicyClient.java new file mode 100644 index 000000000..1c446fdca --- /dev/null +++ b/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/DecisionPolicyClient.java @@ -0,0 +1,116 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineClient + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policyEngine; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.openecomp.policy.api.AttributeType; +import org.openecomp.policy.api.PolicyChangeResponse; +import org.openecomp.policy.api.PolicyClass; +import org.openecomp.policy.api.PolicyEngine; +import org.openecomp.policy.api.PolicyParameters; + +public class DecisionPolicyClient { + static Boolean isEdit = true; + public static void main(String[] args) { + try { + PolicyEngine policyEngine = new PolicyEngine("config.properties"); + PolicyParameters policyParameters = new PolicyParameters(); + // Set Policy Type + policyParameters.setPolicyClass(PolicyClass.Decision); //required + policyParameters.setPolicyName("MikeAPItests.testDecisionAPI"); //required + policyParameters.setEcompName("java"); //required + policyParameters.setPolicyDescription("This is a sample Decision policy UPDATE example with Settings"); //optional + //policyParameters.setPolicyScope("MikeAPItests"); //Directory will be created where the Policies are saved... this displays a a subscope on the GUI + + //Set the Component Attributes... These are Optional + Map configAttributes = new HashMap(); + configAttributes.put("Template", "UpdateTemplate"); + configAttributes.put("controller", "default"); + configAttributes.put("SamPoll", "30"); + configAttributes.put("value", "abcd"); + + Map> attributes = new HashMap>(); + attributes.put(AttributeType.MATCHING, configAttributes); + + //Set the settings... These are Optional + Map settingsMap = new HashMap(); + settingsMap.put("server", "5"); + + attributes.put(AttributeType.SETTINGS, settingsMap); + policyParameters.setAttributes(attributes); + + //Set the Rule Algorithm... These are Optional + Map>> ruleAlgorithm = new HashMap>>(); + + List dynamicRuleAlgorithmLabels = new LinkedList(); + List dynamicRuleAlgorithmFunctions = new LinkedList(); + List dynamicRuleAlgorithmField1 = new LinkedList(); + List dynamicRuleAlgorithmField2 = new LinkedList(); + + //Example of a complex Rule algorithm using the settings in the Field1 + /* label field1 function field2 + * ***************************************************** + * A1 S_server integer-equal 90 + * A2 cap string-contains ca + * A3 cobal integer-equal 90 + * A4 A2 and A3 + * A5 Config integer-greater-than 45 + * A6 A4 ` or A5 + * A7 A1 and A6 + */ + dynamicRuleAlgorithmLabels = Arrays.asList("A1","A2","A3","A4","A5","A6","A7"); + dynamicRuleAlgorithmField1 = Arrays.asList("S_server","cap","cobal","A2","Config","A4","A1"); + dynamicRuleAlgorithmFunctions = Arrays.asList("integer-equal","string-contains","integer-equal","and","integer-greater-than","or","and"); + dynamicRuleAlgorithmField2 = Arrays.asList("90","ca","90","A3","45","A5","A6"); + + policyParameters.setDynamicRuleAlgorithmLabels(dynamicRuleAlgorithmLabels); + policyParameters.setDynamicRuleAlgorithmField1(dynamicRuleAlgorithmField1); + policyParameters.setDynamicRuleAlgorithmFunctions(dynamicRuleAlgorithmFunctions); + policyParameters.setDynamicRuleAlgorithmField2(dynamicRuleAlgorithmField2); + + policyParameters.setRequestID(UUID.randomUUID()); + + // API method to create Policy or update policy + PolicyChangeResponse response = null; + if (!isEdit) { + response = policyEngine.createPolicy(policyParameters); + } else { + response = policyEngine.updatePolicy(policyParameters); + } + + if(response.getResponseCode()==200){ + System.out.println(response.getResponseMessage()); + System.out.println("Policy Created Successfully!"); + }else{ + System.out.println("Error! " + response.getResponseMessage()); + } + } catch (Exception e) { + System.err.println(e.getMessage()); + } + } + +} diff --git a/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/DeletePolicyClient.java b/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/DeletePolicyClient.java new file mode 100644 index 000000000..79ec99f85 --- /dev/null +++ b/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/DeletePolicyClient.java @@ -0,0 +1,62 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineClient + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policyEngine; + +import org.openecomp.policy.api.DeletePolicyCondition; +import org.openecomp.policy.api.DeletePolicyParameters; +import org.openecomp.policy.api.PolicyChangeResponse; +import org.openecomp.policy.api.PolicyEngine; + +public class DeletePolicyClient { + + public static void main(String[] args) { + try { + + PolicyEngine policyEngine = new PolicyEngine("config.properties"); + DeletePolicyParameters policyParameters = new DeletePolicyParameters(); + + //Parameter arguments + policyParameters.setPolicyName("MikeConsole.Config_testDeleteAPI6.1.xml"); + policyParameters.setPolicyComponent("PDP"); + policyParameters.setPdpGroup("default"); + policyParameters.setDeleteCondition(DeletePolicyCondition.ALL); + policyParameters.setRequestID(null); + + // API method to Push Policy to PDP + PolicyChangeResponse response = null; + response = policyEngine.deletePolicy(policyParameters); + + if(response.getResponseCode()==200){ + System.out.println(response.getResponseMessage()); + System.out.println("Policy Deleted Successfully!"); + }else{ + System.out.println("Error! " + response.getResponseMessage()); + } + + } catch (Exception e) { + System.err.println(e.getMessage()); + + } + + } + + +} diff --git a/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/GeneralTestClient.java b/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/GeneralTestClient.java new file mode 100644 index 000000000..c78fc6f11 --- /dev/null +++ b/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/GeneralTestClient.java @@ -0,0 +1,398 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineClient + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/* + * AT&T - PROPRIETARY + * THIS FILE CONTAINS PROPRIETARY INFORMATION OF + * AT&T AND IS NOT TO BE DISCLOSED OR USED EXCEPT IN + * ACCORDANCE WITH APPLICABLE AGREEMENTS. + * + * Copyright (c) 2014 AT&T Knowledge Ventures + * Unpublished and Not for Publication + * All Rights Reserved + */ +package org.openecomp.policyEngine; + +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; +import org.openecomp.policy.api.PolicyEngine; +import org.openecomp.policy.api.PolicyEngineException; + +/** + * Class reads from .testCases file and run the test cases available in the file + * and generates output for each test cases specifing whether is passed or fail + * and reason why it fails. + * + * + * @version 1.0 + * + */ +public class GeneralTestClient { + static int totalTC = 0, passTC = 0, failTC = 0; + + public static void main(String[] args) { + Path file; + /* command line arguments */ + if (args.length != 0) { + for (int index = 0; index < args.length; index++) { + // System.out.println(args[index]); + file = Paths.get(args[index]); + runTestClientOnConfigFile(file); + } + } else { + /* default file */ + file = Paths.get("input.testCases"); + runTestClientOnConfigFile(file); + } + System.out + .println("###############################################################################################"); + System.out.println("\n\t SUMMARY: TOTAL: " + totalTC + ",\tPASS: " + + passTC + ",\tFAIL: " + failTC + "\n"); + System.out + .println("###############################################################################################"); + + System.out.println("Enter a any key to exit"); + try { + System.in.read(); + } catch (IOException e) { + // + } + + } + + /** + * This function reads the files passed as arguments and runs the test cases + * in the file + * + * @param file + */ + private static void runTestClientOnConfigFile(Path file) { + String resultReturned, eCOMPComponentName; + int totalTCforFile = 0, passTCforFile = 0, failTCforFile = 0; + System.out + .println("\n###############################################################################################"); + System.out.println("\tRuning test Client on Config file: " + file); + System.out + .println("###############################################################################################\n"); + + if (Files.notExists(file)) { + System.out.println("file doesnot exist"); + // throw new + // PolicyEngineException("File doesn't exist in the specified Path " + // + file.toString()); + } else if (file.toString().endsWith(".testCases")) { + try { + // read the json file + FileReader reader = new FileReader(file.toString()); + + JSONParser jsonParser = new JSONParser(); + JSONArray jsonObjectArray = (JSONArray) jsonParser + .parse(reader); + for (Object jsonObject : jsonObjectArray) { + totalTC++; + totalTCforFile++; + ArrayList expectedResult = new ArrayList(); + ArrayList resultReceived = new ArrayList(); + JSONObject testCase = (JSONObject) jsonObject; + // get a String from the JSON object + long id = (long) testCase.get("id"); + String testFor = (String) testCase.get("testFor"); + String testCaseDescription = (String) testCase + .get("testCaseDescription"); + JSONArray expectedResultJson = (JSONArray) testCase + .get("expectedResult"); + @SuppressWarnings("rawtypes") + Iterator i = expectedResultJson.iterator(); + while (i.hasNext()) { + expectedResult.add((String) i.next()); + } + String pdp_urlConfigFile = (String) testCase + .get("PDP_URLConfigFile"); + // System.out.println(pdp_urlConfigFile); + PolicyEngine policyEngine; + try { + policyEngine = new PolicyEngine(pdp_urlConfigFile); + + switch (testFor) { + + case "getConfig": + eCOMPComponentName = (String) testCase + .get("ECOMPName"); + String configName = (String) testCase + .get("ConfigName"); + Map configAttributes = new HashMap(); + configAttributes.put("key", "value"); + JSONArray configAttributesJSON = (JSONArray) testCase + .get("configAttributes"); + if(configAttributesJSON!=null){ + i = configAttributesJSON.iterator(); + while (i.hasNext()) { + JSONObject innerObj = (JSONObject) i.next(); + configAttributes.put( + (String) innerObj.get("key"), + (String) innerObj.get("value")); + + } + }else{ + configAttributes = null; + } + resultReceived = PolicyEngineTestClient.getConfig( + policyEngine, eCOMPComponentName, + configName, configAttributes); + Collections.sort(expectedResult); + Collections.sort(resultReceived); + resultReturned = compareResults(expectedResult,resultReceived); + if (resultReturned.equals("PASSED")) { + printResult(id, testFor, testCaseDescription, + "PASSED"); + passTCforFile++; + passTC++; + } else { + printResult(id, testFor, testCaseDescription, + "FAILED", resultReturned); + failTCforFile++; + failTC++; + } + break; + + case "getAction": + Map eventAttributes = new HashMap(); + eventAttributes.put("Key", "Value"); + JSONArray eventAttributesJSON = (JSONArray) testCase + .get("eventAttributes"); + if(eventAttributesJSON != null){ + i = eventAttributesJSON.iterator(); + while (i.hasNext()) { + JSONObject innerObj = (JSONObject) i.next(); + eventAttributes.put( + (String) innerObj.get("key"), + (String) innerObj.get("value")); + } + }else{ + eventAttributes=null; + } + resultReceived = PolicyEngineTestClient.getAction( + policyEngine, eventAttributes); + Collections.sort(expectedResult); + Collections.sort(resultReceived); + resultReturned = compareResults(expectedResult, + resultReceived); + if (resultReturned.equals("PASSED")) { + printResult(id, testFor, testCaseDescription, + "PASSED"); + passTCforFile++; + passTC++; + } else { + printResult(id, testFor, testCaseDescription, + "FAILED", resultReturned); + failTCforFile++; + failTC++; + } + break; + + case "getDecision": + eCOMPComponentName = (String) testCase + .get("ECOMPName"); + Map decisionAttributes = new HashMap(); + decisionAttributes.put("Key", "Value"); + JSONArray decisionAttributesJSON = (JSONArray) testCase + .get("decisionAttributes"); + i = decisionAttributesJSON.iterator(); + while (i.hasNext()) { + JSONObject innerObj = (JSONObject) i.next(); + decisionAttributes.put( + (String) innerObj.get("key"), + (String) innerObj.get("value")); + + } + + resultReceived = PolicyEngineTestClient + .getDecision(policyEngine, + eCOMPComponentName, + decisionAttributes); + Collections.sort(expectedResult); + Collections.sort(resultReceived); + resultReturned = compareResults(expectedResult, + resultReceived); + if (resultReturned.equals("PASSED")) { + printResult(id, testFor, testCaseDescription, + "PASSED"); + passTCforFile++; + passTC++; + } else { + printResult(id, testFor, testCaseDescription, + "FAILED", resultReturned); + failTCforFile++; + failTC++; + } + break; + + // case "getManualNotification": + // PolicyEngineTestClient + // .getManualNotifications(org.openecomp.policyEngine); + // break; + // case "getAutoNotification": + // PolicyEngineTestClient + // .getAutoNotifications(org.openecomp.policyEngine); + // break; + + default: + printResult(id, testFor, testCaseDescription, + "FAILED", "\tINVAILD TEST CASE."); + failTCforFile++; + failTC++; + break; + + } + } catch (PolicyEngineException e) { + // TODO Auto-generated catch block + printResult(id, testFor, testCaseDescription, "FAILED"); + failTCforFile++; + failTC++; + e.printStackTrace(); + } catch (Exception e) { + // TODO Auto-generated catch block + printResult(id, testFor, testCaseDescription, "FAILED"); + failTCforFile++; + failTC++; + e.printStackTrace(); + } + } + + } catch (FileNotFoundException ex) { + ex.printStackTrace(); + } catch (IOException ex) { + ex.printStackTrace(); + } catch (NullPointerException ex) { + ex.printStackTrace(); + } catch (org.json.simple.parser.ParseException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + System.out.println("\n\n\t Summary for the file: TOTAL: " + + totalTCforFile + ",\tPASS: " + passTCforFile + ",\tFAIL: " + + failTCforFile + "\n"); + } + + /** + * This function prints the reason if test fails. + * + * @param id + * @param testFor + * @param testCaseDescription + * @param passFail + * @param resultReturned + */ + private static void printResult(long id, String testFor, + String testCaseDescription, String passFail, String resultReturned) { + // TODO Auto-generated method stub + printResult(id, testFor, testCaseDescription, passFail); + System.out.println(resultReturned); + + } + + /** + * This function prints in output in required format. + * + * @param id + * @param testFor + * @param testCaseDescription + * @param result + */ + private static void printResult(long id, String testFor, + String testCaseDescription, String result) { + System.out.println(result + " - Test Case " + id + " - Test type: " + + testFor + " - " + testCaseDescription); + } + + /** + * This function compares the required expected output and received output + * and returns PASS if expected output and received output matches + * + * @param expectedResult + * @param resultReceived + * @return + */ + private static String compareResults(ArrayList expectedResult, + ArrayList resultReceived) { + // TODO Auto-generated method stub + String returnString = ""; + int index; +// System.out.println(expectedResult.size()); +// System.out.println(resultReceived.size()); + for (index = 0; index < expectedResult.size() + || index < resultReceived.size(); index++) { + if (index < expectedResult.size() && index < resultReceived.size()) { + if (!expectedResult.get(index) + .equals(resultReceived.get(index))) { + //returnString = "FAILED"; + returnString += "\tExpected Output: " + + expectedResult.get(index) + + ",\n\tOutput Received: " + + resultReceived.get(index)+"\n"; +// + //System.out.println(resultReceived.get(index)); + } + + } else { + if (index >= expectedResult.size()) { + returnString += "\tExpected Size of output: " + + expectedResult.size() + + ", Size of output received: " + + resultReceived.size() + + "\n\tExpected Output: none,\n\tOutput Received: " + + resultReceived.get(index)+"\n"; + + } else { + if (index >= resultReceived.size()) { + returnString += "\tExpected Size of output: " + + expectedResult.size() + + ", Size of output received: " + + resultReceived.size() + + "\n\tExpected Output: " + + expectedResult.get(index) + + ",\n\tOutput Received: none\n"; + + } + } + } + + } + if(index==expectedResult.size() && index==resultReceived.size() && returnString.equals("")){ + returnString="PASSED"; + } + return returnString; + + } +} diff --git a/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/GetConfigSample.java b/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/GetConfigSample.java new file mode 100644 index 000000000..cdba1c9fe --- /dev/null +++ b/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/GetConfigSample.java @@ -0,0 +1,41 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineClient + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policyEngine; + +import java.util.Collection; + +import org.openecomp.policy.api.ConfigRequestParameters; +import org.openecomp.policy.api.PolicyConfig; +import org.openecomp.policy.api.PolicyEngine; + +public class GetConfigSample { + + public static void main(String[] args) throws Exception { + PolicyEngine pe = new PolicyEngine("config.properties"); + ConfigRequestParameters configRequestParams = new ConfigRequestParameters(); + configRequestParams.setPolicyName(".*"); + Collection configs = pe.getConfig(configRequestParams); + for (PolicyConfig config: configs){ + System.out.println(config.getPolicyConfigMessage()); + System.out.println(config.getPolicyConfigStatus()); + } + } +} diff --git a/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/Handler.java b/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/Handler.java new file mode 100644 index 000000000..448b54270 --- /dev/null +++ b/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/Handler.java @@ -0,0 +1,121 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineClient + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policyEngine; + +import java.util.Collection; + +import org.openecomp.policy.api.LoadedPolicy; +import org.openecomp.policy.api.NotificationHandler; +import org.openecomp.policy.api.NotificationType; +import org.openecomp.policy.api.PDPNotification; +import org.openecomp.policy.api.PolicyConfig; +import org.openecomp.policy.api.PolicyConfigException; +import org.openecomp.policy.api.PolicyConfigStatus; +import org.openecomp.policy.api.PolicyEngine; +import org.openecomp.policy.api.PolicyEngineException; +import org.openecomp.policy.api.RemovedPolicy; + +public class Handler implements NotificationHandler{ + + @Override + public void notificationReceived(PDPNotification notification) { + System.out.println("Notification Received..."); + System.out.println(notification.getNotificationType()); + if(notification.getNotificationType().equals(NotificationType.REMOVE)){ + System.out.println("Removed Policies: \n"); + for(RemovedPolicy removedPolicy: notification.getRemovedPolicies()){ + System.out.println(removedPolicy.getPolicyName()); + System.out.println(removedPolicy.getVersionNo()); + } + }else if(notification.getNotificationType().equals(NotificationType.UPDATE)){ + System.out.println("Updated Policies: \n"); + for(LoadedPolicy updatedPolicy: notification.getLoadedPolicies()){ + System.out.println("policyName : " + updatedPolicy.getPolicyName()); + System.out.println("policyVersion :" + updatedPolicy.getVersionNo()); + if(updatedPolicy.getPolicyName().contains(".Config_")){ + System.out.println("Matches: " + updatedPolicy.getMatches()); + System.out.println("UpdateType: "+ updatedPolicy.getUpdateType()); + // Checking the Name is correct or not. + try { + PolicyEngine policyEngine = new PolicyEngine("config.properties"); + Collection policyConfigs = policyEngine.getConfigByPolicyName(updatedPolicy.getPolicyName()); + for(PolicyConfig policyConfig: policyConfigs){ + if(policyConfig.getPolicyConfigStatus().equals(PolicyConfigStatus.CONFIG_RETRIEVED)){ + System.out.println("Policy Retrieved with this Name notified. "); + }else{ + System.err.println("\n\n Fail to retrieve policy !!!!\n\n"); + } + // Also Test this case. + if(policyConfig.getPolicyName().equals(updatedPolicy.getPolicyName())){ + System.out.println("Policy Name is good. "); + }else{ + System.err.println("\n\n Fail to check Name \n\n"); + } + } + } catch (PolicyEngineException e) { + e.printStackTrace(); + } catch (PolicyConfigException e) { + e.printStackTrace(); + } + } + } + }else if(notification.getNotificationType().equals(NotificationType.BOTH)){ + System.out.println("Both updated and Removed Notification: \n"); + System.out.println("Removed Policies: \n"); + for(RemovedPolicy removedPolicy: notification.getRemovedPolicies()){ + System.out.println(removedPolicy.getPolicyName()); + System.out.println(removedPolicy.getVersionNo()); + } + System.out.println("Updated Policies: \n"); + for(LoadedPolicy updatedPolicy: notification.getLoadedPolicies()){ + System.out.println("policyName : " + updatedPolicy.getPolicyName()); + System.out.println("policyVersion :" + updatedPolicy.getVersionNo()); + System.out.println("Matches: " + updatedPolicy.getMatches()); + System.out.println("UpdateType: "+ updatedPolicy.getUpdateType()); + // Checking the Name is correct or not. + try { + PolicyEngine policyEngine = new PolicyEngine("config.properties"); + Collection policyConfigs = policyEngine.getConfigByPolicyName(updatedPolicy.getPolicyName()); + for(PolicyConfig policyConfig: policyConfigs){ + if(policyConfig.getPolicyConfigStatus().equals(PolicyConfigStatus.CONFIG_RETRIEVED)){ + System.out.println("Policy Retrieved with this Name notified. "); + }else{ + System.err.println("\n\n Fail to retrieve policy !!!!\n\n"); + } + // Also Test this case. + if(policyConfig.getPolicyName().equals(updatedPolicy.getPolicyName())){ + System.out.println("Policy Name is good. "); + }else{ + System.err.println("\n\n Fail to check Name \n\n"); + } + } + } catch (PolicyEngineException e) { + e.printStackTrace(); + } catch (PolicyConfigException e) { + e.printStackTrace(); + } + } + } + } + + + +} diff --git a/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/ImportMicroServiceClient.java b/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/ImportMicroServiceClient.java new file mode 100644 index 000000000..ffb49d5ed --- /dev/null +++ b/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/ImportMicroServiceClient.java @@ -0,0 +1,56 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineClient + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policyEngine; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +import org.openecomp.policy.api.ImportParameters; +import org.openecomp.policy.api.PolicyChangeResponse; +import org.openecomp.policy.api.PolicyEngine; +import org.openecomp.policy.api.ImportParameters.IMPORT_TYPE; + +public class ImportMicroServiceClient { + static Boolean isEdit = false; + public static void main(String[] args) { + try{ + PolicyEngine policyEngine = new PolicyEngine("config.properties"); + ImportParameters importParameters = new ImportParameters(); + List filepath = new ArrayList(); + importParameters.setFilePath("C:\\Workspaces\\models\\TestingModel\\ControllerServiceSampleSdnlServiceInstance-v0.1.0-SNAPSHOT.zip"); + importParameters.setServiceName("ControllerServiceSampleSdnlServiceInstance"); + + importParameters.setRequestID(UUID.randomUUID()); + importParameters.setServiceType(IMPORT_TYPE.MICROSERVICE); + importParameters.setVersion("1607-2"); + + // API method to create Policy or update policy + PolicyChangeResponse response = null; + response = policyEngine.policyEngineImport(importParameters); + System.out.println(response.getResponseMessage()); + + } catch (Exception e) { + System.err.println(e.getMessage()); + } + } + +} diff --git a/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/ListConfigPoliciesClient.java b/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/ListConfigPoliciesClient.java new file mode 100644 index 000000000..fa013bb69 --- /dev/null +++ b/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/ListConfigPoliciesClient.java @@ -0,0 +1,83 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineClient + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policyEngine; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +import org.openecomp.policy.api.ConfigRequestParameters; +import org.openecomp.policy.api.PolicyConfigException; +import org.openecomp.policy.api.PolicyEngine; +import org.openecomp.policy.api.PolicyEngineException; +import org.w3c.dom.Document; + +public class ListConfigPoliciesClient { + public static void main(String[] args) { + PolicyEngine policyEngine; + + // List Config Policies Example + try { + policyEngine = new PolicyEngine("config.properties"); + ConfigRequestParameters parameters = new ConfigRequestParameters(); + + parameters.setPolicyName(".*"); + parameters.setEcompName(".*"); + parameters.setConfigName(".*"); + + Map configAttributes = new HashMap(); + configAttributes.put("java", "java"); + configAttributes.put("peach", "Tar"); + configAttributes.put("true", "false"); + configAttributes.put("small", "testPass"); + parameters.setConfigAttributes(configAttributes); + + parameters.setRequestID(UUID.randomUUID()); + + Collection response = policyEngine.listConfig(parameters); + if(response!=null && !response.contains("PE300")){ + for(String configList : response){ + System.out.println(configList.toString()+"\n"); + } + }else{ + System.out.println("Error! " +response); + } + + } catch (PolicyConfigException e) { + e.printStackTrace(); + } catch (PolicyEngineException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + +} diff --git a/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/MainClient.java b/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/MainClient.java new file mode 100644 index 000000000..e7a2f8195 --- /dev/null +++ b/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/MainClient.java @@ -0,0 +1,162 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineClient + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policyEngine; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +import org.openecomp.policy.api.LoadedPolicy; +import org.openecomp.policy.api.NotificationScheme; +import org.openecomp.policy.api.PolicyConfig; +import org.openecomp.policy.api.PolicyConfigException; +import org.openecomp.policy.api.PolicyConfigStatus; +import org.openecomp.policy.api.PolicyEngine; +import org.openecomp.policy.api.PolicyEngineException; +import org.openecomp.policy.api.PolicyType; +import org.openecomp.policy.api.RemovedPolicy; +import org.w3c.dom.Document; + +public class MainClient { + public static void main(String[] args) { + PolicyEngine policyEngine; + try { + policyEngine = new PolicyEngine("config.properties"); + String eCOMPComponentName = ".*" ; + String configName = ".*" ; + Map configAttributes = new HashMap(); + configAttributes.put("java", "java"); + configAttributes.put("peach", "Tar"); + configAttributes.put("true", "false"); + configAttributes.put("small", "testPass"); + Map eventAttributes = new HashMap(); + eventAttributes.put("true", "true"); + eventAttributes.put("cpu", "91"); + Map decisionAttributes = new HashMap(); + decisionAttributes.put("Key", "Value"); + + // Config Example + try { + Collection policyConfigs = policyEngine.getConfigByPolicyName(".*");//(eCOMPComponentName, configName, configAttributes); + if(policyConfigs!=null && !policyConfigs.isEmpty()){ + for(PolicyConfig policyConfig: policyConfigs){ + System.out.println("\nConfig Message: "+ policyConfig.getPolicyConfigMessage()); + System.out.println("Config Status: " + policyConfig.getPolicyConfigStatus()); + System.out.println("Policy Name: "+ policyConfig.getPolicyName()); + System.out.println("policy Version: " + policyConfig.getPolicyVersion()); + /*System.out.println("policy Type: " + policyConfig.getType().toString()); + System.out.println("Matching Conditions: " + policyConfig.getMatchingConditions()); + System.out.println("Body is : "); + if(policyConfig.getPolicyConfigStatus().equals(PolicyConfigStatus.CONFIG_RETRIEVED)){ + if(policyConfig.getType().equals(PolicyType.OTHER)){ + System.out.println(policyConfig.toOther()); + }else if(policyConfig.getType().equals(PolicyType.JSON)){ + System.out.println(policyConfig.toJSON().toString()); + }else if(policyConfig.getType().equals(PolicyType.PROPERTIES)){ + System.out.println(policyConfig.toProperties().toString()); + }else if(policyConfig.getType().equals(PolicyType.XML)){ + try { + printDocument(policyConfig.toXML(), System.out); + } catch (Exception e) { + e.printStackTrace(); + } + } + }*/ + } + } + } catch (PolicyConfigException e) { + e.printStackTrace(); + } + // Action example + /*try{ + Collection policyResponses = org.openecomp.policyEngine.sendEvent(eventAttributes); + if(policyResponses!=null && !policyResponses.isEmpty()){ + for(PolicyResponse policyResponse: policyResponses){ + System.out.println(policyResponse.getPolicyResponseMessage() + " : " + policyResponse.getPolicyResponseStatus()); + System.out.println(policyResponse.getActionAdvised()); + System.out.println(policyResponse.getActionTaken()); + System.out.println(policyResponse.getRequestAttributes()); + } + } + }catch (PolicyEventException e){ + e.printStackTrace(); + }*/ + /*// Decision example + try{ + PolicyDecision policyDecision = org.openecomp.policyEngine.getDecision(eCOMPComponentName, decisionAttributes); + System.out.println(policyDecision.toString()); + } catch(PolicyDecisionException e){ + e.printStackTrace(); + }*/ + + // Manual Notifications.. + policyEngine.setScheme(NotificationScheme.MANUAL_ALL_NOTIFICATIONS); + if(policyEngine.getNotification()!=null){ + System.out.println(policyEngine.getNotification().getNotificationType()); + for(LoadedPolicy updated: policyEngine.getNotification().getLoadedPolicies()){ + System.out.println(updated.getPolicyName()); + System.out.println(updated.getVersionNo()); + System.out.println(updated.getMatches()); + } + for(RemovedPolicy removed: policyEngine.getNotification().getRemovedPolicies()){ + System.out.println(removed.getPolicyName()); + System.out.println(removed.getVersionNo()); + } + } + // Auto Notifications.. + Handler handler = new Handler(); + policyEngine.setNotification(NotificationScheme.AUTO_ALL_NOTIFICATIONS, handler); + // + System.out.println("Enter a any key to exit"); + try { + System.in.read(); + } catch (IOException e) { + // + } + + } catch (PolicyEngineException e1) { + e1.printStackTrace(); + } + } + + public static void printDocument(Document doc, OutputStream out) throws IOException, TransformerException { + TransformerFactory tf = TransformerFactory.newInstance(); + Transformer transformer = tf.newTransformer(); + transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); + transformer.setOutputProperty(OutputKeys.METHOD, "xml"); + transformer.setOutputProperty(OutputKeys.INDENT, "yes"); + transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); + transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); + + transformer.transform(new DOMSource(doc), + new StreamResult(new OutputStreamWriter(out, "UTF-8"))); + } +} diff --git a/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/MicroServicesPolicyClient.java b/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/MicroServicesPolicyClient.java new file mode 100644 index 000000000..4021c9432 --- /dev/null +++ b/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/MicroServicesPolicyClient.java @@ -0,0 +1,121 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineClient + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policyEngine; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.InputStream; +import java.io.StringReader; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.UUID; +import javax.json.Json; +import javax.json.JsonObject; +import javax.json.JsonReader; + +import org.openecomp.policy.api.PolicyChangeResponse; +import org.openecomp.policy.api.PolicyConfigType; +import org.openecomp.policy.api.PolicyEngine; +import org.openecomp.policy.api.PolicyParameters; +import org.openecomp.policy.api.PolicyType; +public class MicroServicesPolicyClient { + +//For updating a Micro Services policy set the "isEdit" flag to true. +//For creating a Micro Services policy set the "isEdit" flag to false. +static Boolean isEdit = false; + +//Builds JSONObject from File +private static JsonObject buildJSON(File jsonInput, String jsonString) throws FileNotFoundException { + JsonObject json = null;; + + if (jsonString != null && jsonInput == null) { + StringReader in = null; + in = new StringReader(jsonString); + JsonReader jsonReader = Json.createReader(in); + json = jsonReader.readObject(); + } + else { + InputStream in = null; + in = new FileInputStream(jsonInput); + JsonReader jsonReader = Json.createReader(in); + json = jsonReader.readObject(); + } + + return json; +} +public static void main(String[] args) { + try { + PolicyEngine policyEngine = new PolicyEngine("config.properties"); + PolicyParameters policyParameters = new PolicyParameters(); + // Set Policy Type + policyParameters.setPolicyConfigType(PolicyConfigType.MicroService); + policyParameters.setPolicyName("Katrina.configuration_dcae_microservice_stringmatcher"); + //policyParameters.setPolicyDescription("This is a sample Micro Service policy Create example"); + policyParameters.setEcompName("DCAE"); + //policyParameters.setConfigName("Collector"); + //policyParameters.setPriority("1"); + //policyParameters.setPolicyScope("service=vSCP;resource=F5;type=configuration;closedLoopControlName=vSCP_F5_Firewall_d925ed73-8231-4d02-9545-db4e113213abab322"); + + // Set up Micro Services Attributes + File jsonFile = null; + String MSjsonString= null; + if (MSjsonString == null) { + Path file = Paths.get("C:\\policyAPI\\MicroServicesJSON\\testStringMatching.json"); + jsonFile = file.toFile(); + } + policyParameters.setConfigBody(buildJSON(jsonFile, MSjsonString).toString()); + policyParameters.setConfigBodyType(PolicyType.JSON); + + policyParameters.setRequestID(UUID.randomUUID()); + // Set Safe Policy value for Risk Type + SimpleDateFormat dateformat3 = new SimpleDateFormat("dd/MM/yyyy"); + Date date = dateformat3.parse("15/10/2016"); + policyParameters.setTtlDate(date); + // Set Safe Policy value for Guard + policyParameters.setGuard(true); + // Set Safe Policy value for Risk Level + policyParameters.setRiskLevel("5"); + // Set Safe Policy value for Risk Type + policyParameters.setRiskType("PROD"); + + // API method to create or update Policy. + PolicyChangeResponse response = null; + if (!isEdit) { + response = policyEngine.createPolicy(policyParameters); + } + else { + response = policyEngine.updatePolicy(policyParameters); + } + + if(response.getResponseCode()==200){ + System.out.println(response.getResponseMessage()); + System.out.println("Policy Created Successfully!"); + }else{ + System.out.println("Error! " + response.getResponseMessage()); + } + } catch (Exception e) { + System.err.println(e.getMessage()); + } + } +} diff --git a/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/PolicyEngineTestClient.java b/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/PolicyEngineTestClient.java new file mode 100644 index 000000000..f2606a971 --- /dev/null +++ b/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/PolicyEngineTestClient.java @@ -0,0 +1,201 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineClient + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/* + * AT&T - PROPRIETARY + * THIS FILE CONTAINS PROPRIETARY INFORMATION OF + * AT&T AND IS NOT TO BE DISCLOSED OR USED EXCEPT IN + * ACCORDANCE WITH APPLICABLE AGREEMENTS. + * + * Copyright (c) 2014 AT&T Knowledge Ventures + * Unpublished and Not for Publication + * All Rights Reserved + */ +package org.openecomp.policyEngine; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Map; +import java.util.UUID; + +import org.openecomp.policy.api.DecisionResponse; +import org.openecomp.policy.api.LoadedPolicy; +import org.openecomp.policy.api.NotificationScheme; +import org.openecomp.policy.api.PolicyConfig; +import org.openecomp.policy.api.PolicyConfigException; +import org.openecomp.policy.api.PolicyDecisionException; +import org.openecomp.policy.api.PolicyEngine; +import org.openecomp.policy.api.PolicyEventException; +import org.openecomp.policy.api.PolicyResponse; +import org.openecomp.policy.api.RemovedPolicy; + +/** + * Class contains static functions which make call to policy engine using API. + * This class is used by generalTestClient.java + * + * + * @version 1.0 + * + */ +public class PolicyEngineTestClient { + /** + * This fuction make API call to policy engine to get config. And returns + * policy name, policy version and policy configStatus + * + * @param org.openecomp.policyEngine + * @param eCOMPComponentName + * @param configName + * @param configAttributes + * @return + */ + + public static ArrayList getConfig(PolicyEngine policyEngine, + String eCOMPComponentName, String configName, + Map configAttributes) { + ArrayList resultReceived = new ArrayList(); + try { + UUID requestID = UUID.randomUUID(); + Collection policyConfigs; + if (configName == null) { + policyConfigs = policyEngine.getConfig(eCOMPComponentName, requestID); + } else { + if (configAttributes == null) { + policyConfigs = policyEngine.getConfig(eCOMPComponentName, + configName, requestID); + } else { + + policyConfigs = policyEngine.getConfig(eCOMPComponentName, + configName, configAttributes, requestID); + } + } + if (policyConfigs != null && !policyConfigs.isEmpty()) { + for (PolicyConfig policyConfig : policyConfigs) { + resultReceived.add("Policy Name: " + + policyConfig.getPolicyName() + + " Policy version: " + + policyConfig.getPolicyVersion() + " - " + + policyConfig.getPolicyConfigStatus()); + } + } + } catch (PolicyConfigException e) { +// e.printStackTrace(); + resultReceived.add(""+e); + } + return resultReceived; + } + + /** + * This functions make API call to policy engine to get decision. And + * returns policy Decision + * + * @param org.openecomp.policyEngine + * @param eCOMPComponentName + * @param decisionAttributes + * @return + */ + public static ArrayList getDecision(PolicyEngine policyEngine, + String eCOMPComponentName, Map decisionAttributes) { + ArrayList resultReceived = new ArrayList(); + // Decision example + try { + UUID requestID = UUID.randomUUID(); + DecisionResponse policyDecision = policyEngine.getDecision( + eCOMPComponentName, decisionAttributes, requestID); + resultReceived.add(policyDecision.getDecision().toString()); + } catch (PolicyDecisionException e) { +// e.printStackTrace(); + resultReceived.add(""+e); + } + return resultReceived; + } + + /** + * This function makes API call to policy engine to get action. And returns + * responseMessage and responseStatus + * + * @param org.openecomp.policyEngine + * @param eventAttributes + * @return + */ + public static ArrayList getAction(PolicyEngine policyEngine, + Map eventAttributes) { + ArrayList resultReceived = new ArrayList(); + try { + UUID requestID = UUID.randomUUID(); + Collection policyResponses = policyEngine + .sendEvent(eventAttributes, requestID); + if (policyResponses != null && !policyResponses.isEmpty()) { + for (PolicyResponse policyResponse : policyResponses) { + resultReceived.add(policyResponse + .getPolicyResponseMessage() + + " : " + + policyResponse.getPolicyResponseStatus()); + } + } + } catch (PolicyEventException e) { +// e.printStackTrace(); + resultReceived.add(""+e); + } + return resultReceived; + } + + /** + * This function makes API call to policy engine to get manual + * notifications. + * + * @param org.openecomp.policyEngine + */ + + public static void getManualNotifications(PolicyEngine policyEngine) { + policyEngine.setScheme(NotificationScheme.MANUAL_ALL_NOTIFICATIONS); + System.out.println(policyEngine.getNotification().getNotificationType()); + for (LoadedPolicy updated : policyEngine.getNotification().getLoadedPolicies()) { + System.out.println(updated.getPolicyName()); + System.out.println(updated.getVersionNo()); + System.out.println(updated.getMatches()); + } + for (RemovedPolicy removed : policyEngine.getNotification() + .getRemovedPolicies()) { + System.out.println(removed.getPolicyName()); + System.out.println(removed.getVersionNo()); + } + } + + /** + * This function makes API call to policy engine to get automatic + * notifications. + * + * @param org.openecomp.policyEngine + */ + public static void getAutoNotifications(PolicyEngine policyEngine) { + Handler handler = new Handler(); + policyEngine.setNotification(NotificationScheme.AUTO_ALL_NOTIFICATIONS, + handler); + // + System.out.println("Enter a any key to exit"); + try { + System.in.read(); + } catch (IOException e) { + // + } + } + +} diff --git a/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/PushPoliciesToPDP.java b/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/PushPoliciesToPDP.java new file mode 100644 index 000000000..2a4086357 --- /dev/null +++ b/PolicyEngineClient/src/main/java/org/openecomp/policyEngine/PushPoliciesToPDP.java @@ -0,0 +1,59 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineClient + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policyEngine; + +import org.openecomp.policy.api.PolicyChangeResponse; +import org.openecomp.policy.api.PolicyEngine; +import org.openecomp.policy.api.PushPolicyParameters; + +public class PushPoliciesToPDP { + public static void main(String[] args) { + try { + + PolicyEngine policyEngine = new PolicyEngine("config.properties"); + PushPolicyParameters policyParameters = new PushPolicyParameters(); + + //Parameter arguments + policyParameters.setPolicyName("Mike.testCase1"); + policyParameters.setPolicyType("Base"); + //policyParameters.setPolicyScope("MikeAPItesting"); + policyParameters.setPdpGroup("default"); + policyParameters.setRequestID(null); + + // API method to Push Policy to PDP + PolicyChangeResponse response = null; + response = policyEngine.pushPolicy(policyParameters); + + if(response.getResponseCode()==204){ + System.out.println(response.getResponseMessage()); + System.out.println("Policy Pushed Successfully!"); + }else{ + System.out.println("Error! " + response.getResponseMessage()); + } + + } catch (Exception e) { + System.err.println(e.getMessage()); + + } + + } + +} diff --git a/PolicyEngineUtils/policyLogger.properties b/PolicyEngineUtils/policyLogger.properties new file mode 100644 index 000000000..3cf88e816 --- /dev/null +++ b/PolicyEngineUtils/policyLogger.properties @@ -0,0 +1,44 @@ +### +# ============LICENSE_START======================================================= +# PolicyEngineUtils +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +################################### Set concurrentHashMap and timer info ####################### +#Timer initial delay and the delay between in milliseconds before task is to be execute. +timer.delay.time=1000 +#Timer scheduleAtFixedRate period - time in milliseconds between successive task executions. +check.interval= 30000 +#Longest time an event info can be stored in the concurrentHashMap for logging - in seconds. +event.expired.time=86400 +#Size of the concurrentHashMap which stores the event starting time, etc - when its size reaches this limit, the Timer gets executed +#to remove all expired records from this concurrentHashMap. +concurrentHashMap.limit=5000 +#Size of the concurrentHashMap - when its size drops to this point, stop the Timer +stop.check.point=2500 +################################### Set logging format ############################################# +# set EELF for EELF logging format, set LOG4J for using log4j, set SYSTEMOUT for using system.out.println +logger.type=EELF +#################################### Set level for EELF or SYSTEMOUT logging ################################## +# Set level for debug file. Set DEBUG to enable .info, .warn and .debug; set INFO for enable .info and .warn; set OFF to disable all +debugLogger.level=INFO +# Set level for metrics file. Set OFF to disable; set ON to enable +metricsLogger.level=ON +# Set level for error file. Set OFF to disable; set ON to enable +error.level=ON +# Set level for audit file. Set OFF to disable; set ON to enable +audit.level=ON diff --git a/PolicyEngineUtils/pom.xml b/PolicyEngineUtils/pom.xml new file mode 100644 index 000000000..0588453c3 --- /dev/null +++ b/PolicyEngineUtils/pom.xml @@ -0,0 +1,85 @@ + + + + 4.0.0 + + org.openecomp.policy.engine + PolicyEngineSuite + 1.0.0-SNAPSHOT + + org.openecomp.policy.engine + PolicyEngineUtils + + + log4j + log4j + 1.2.17 + + + org.eclipse.persistence + javax.persistence + 2.1.0 + + + org.eclipse.persistence + eclipselink + 2.6.0 + + + com.h2database + h2 + [1.4.186,) + + + mysql + mysql-connector-java + 5.1.30 + + + com.fasterxml.jackson.core + jackson-databind + 2.7.5 + + + com.github.fge + json-patch + 1.9 + + + junit + junit + 4.11 + + + + com.att.cadi + cadi-aaf + 1.3.0 + + + com.att.aft + dme2 + + + + + diff --git a/PolicyEngineUtils/src/main/java/org/openecomp/policy/api/LoadedPolicy.java b/PolicyEngineUtils/src/main/java/org/openecomp/policy/api/LoadedPolicy.java new file mode 100644 index 000000000..574580bac --- /dev/null +++ b/PolicyEngineUtils/src/main/java/org/openecomp/policy/api/LoadedPolicy.java @@ -0,0 +1,57 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineUtils + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.api; + +import java.util.Map; +/** + * LoadedPolicy defines the Policy that has been Loaded into the PDP. + * + * @version 0.2 + */ +public interface LoadedPolicy { + /** + * Gets the String format of the Policy Name that has been Loaded into the PDP. + * + * @return String format of Policy Name + */ + public String getPolicyName(); + + /** + * Gets the String format of the Policy Version that has been Loaded into the PDP. + * + * @return String format of the Policy Version. + */ + public String getVersionNo(); + + /** + * Gets the Map of String,String format of the Matches if the policy Loaded is of Config Type. + * + * @return the Map of String,String format of the matches in the policy. + */ + public Map getMatches(); + + /** + * Gets the UpdateType of {@link org.openecomp.policy.api.UpdateType} received. + * + * @return UpdateType associated with this PDPNotification + */ + public UpdateType getUpdateType(); +} diff --git a/PolicyEngineUtils/src/main/java/org/openecomp/policy/api/NotificationHandler.java b/PolicyEngineUtils/src/main/java/org/openecomp/policy/api/NotificationHandler.java new file mode 100644 index 000000000..9661b72f1 --- /dev/null +++ b/PolicyEngineUtils/src/main/java/org/openecomp/policy/api/NotificationHandler.java @@ -0,0 +1,34 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineUtils + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.api; +/** + * Defines the methods which need to run when an Event or Notification is received. + * + * @version 0.1 + */ +public interface NotificationHandler { + /** + * notificationReceived method will be triggered automatically whenever a Notification is received by the PEP. + * + * @param notification PDPNotification of {@link org.openecomp.policy.api.PDPNotification} is the object that has information of the notification. + */ + public void notificationReceived(PDPNotification notification); +} diff --git a/PolicyEngineUtils/src/main/java/org/openecomp/policy/api/NotificationType.java b/PolicyEngineUtils/src/main/java/org/openecomp/policy/api/NotificationType.java new file mode 100644 index 000000000..8bd5bc8db --- /dev/null +++ b/PolicyEngineUtils/src/main/java/org/openecomp/policy/api/NotificationType.java @@ -0,0 +1,58 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineUtils + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.api; + +/** + * Enumeration of the Update Type that has occurred in the PDPNotification of + * {@link org.openecomp.policy.api.PDPNotification} + * + * @version 0.1 + */ +public enum NotificationType { + /** + * Indicates that a policy has been updated + */ + UPDATE("update"), + /** + * Indicates that a policy has been removed + */ + REMOVE("remove"), + /** + * Indicates that both update and removal of policy events has occurred. + */ + BOTH("both") + ; + + private String name; + + private NotificationType(String name){ + this.name = name; + } + + /** + * Returns the String format of the Type for this UpdateType + * @return the String Type of UpdateType + */ + @Override + public String toString(){ + return this.name; + } +} diff --git a/PolicyEngineUtils/src/main/java/org/openecomp/policy/api/PDPNotification.java b/PolicyEngineUtils/src/main/java/org/openecomp/policy/api/PDPNotification.java new file mode 100644 index 000000000..18da617cf --- /dev/null +++ b/PolicyEngineUtils/src/main/java/org/openecomp/policy/api/PDPNotification.java @@ -0,0 +1,52 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineUtils + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.api; + +import java.util.Collection; + +/** + * Defines the Notification event sent from PDP to Client PEP. + * + * @version 0.2 + */ +public interface PDPNotification { + /** + * Gets the Collection of {@link org.openecomp.policy.api.RemovedPolicy} objects received. + * + * @return the Collection which consists of RemovedPolicy objects. + */ + public Collection getRemovedPolicies(); + + /** + * Gets the Collection of {@link org.openecomp.policy.api.LoadedPolicy} objects receieved. + * + * @return the Collection which consists of UpdatedPolicy objects. + */ + public Collection getLoadedPolicies(); + + /** + * Gets the NotificationType of {@link org.openecomp.policy.api.NotificationType} received. + * + * @return NotificationType associated with this PDPNotification + */ + public NotificationType getNotificationType(); + +} diff --git a/PolicyEngineUtils/src/main/java/org/openecomp/policy/api/RemovedPolicy.java b/PolicyEngineUtils/src/main/java/org/openecomp/policy/api/RemovedPolicy.java new file mode 100644 index 000000000..b94fdce42 --- /dev/null +++ b/PolicyEngineUtils/src/main/java/org/openecomp/policy/api/RemovedPolicy.java @@ -0,0 +1,41 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineUtils + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.api; +/** + * RemovedPolicy defines the Policy that has been removed + * + * @version 0.1 + */ +public interface RemovedPolicy { + /** + * Gets the String format of the Policy Name that has been removed. + * + * @return String format of Policy Name + */ + public String getPolicyName(); + + /** + * Gets the String format of the Policy Version that has been removed. + * + * @return String format of Policy Version + */ + public String getVersionNo(); +} diff --git a/PolicyEngineUtils/src/main/java/org/openecomp/policy/api/UpdateType.java b/PolicyEngineUtils/src/main/java/org/openecomp/policy/api/UpdateType.java new file mode 100644 index 000000000..d48121b69 --- /dev/null +++ b/PolicyEngineUtils/src/main/java/org/openecomp/policy/api/UpdateType.java @@ -0,0 +1,54 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineUtils + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.api; + +/** + * Enumeration of the Update Type that has occurred in the UpdatedPolicy of + * {@link org.openecomp.policy.api.LoadedPolicy} + * + * @version 0.1 + */ +public enum UpdateType { + /** + * Indicates that a policy has been updated + */ + UPDATE("update"), + /** + * Indicates that a policy is new + */ + NEW("new") + ; + + private String name; + + private UpdateType(String name){ + this.name = name; + } + + /** + * Returns the String format of the Type for this UpdateType + * @return the String Type of UpdateType + */ + @Override + public String toString(){ + return this.name; + } +} diff --git a/PolicyEngineUtils/src/main/java/org/openecomp/policy/jpa/BackUpMonitorEntity.java b/PolicyEngineUtils/src/main/java/org/openecomp/policy/jpa/BackUpMonitorEntity.java new file mode 100644 index 000000000..731cfc7f7 --- /dev/null +++ b/PolicyEngineUtils/src/main/java/org/openecomp/policy/jpa/BackUpMonitorEntity.java @@ -0,0 +1,117 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineUtils + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.jpa; + +import java.io.Serializable; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Lob; +import javax.persistence.NamedQuery; +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + + +@Entity +@Table(name="BackUpMonitorEntity") +@NamedQuery(name="BackUpMonitorEntity.findAll", query= "SELECT b FROM BackUpMonitorEntity b ") +public class BackUpMonitorEntity implements Serializable{ + private static final long serialVersionUID = -9190606334322230630L; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name="id") + private int id; + + @Column(name="node_name", nullable=false) + private String resourceNodeName; + + @Column(name="resource_name", nullable=false, unique=true) + private String resourceName; + + @Column(name="flag", nullable=false) + private String flag; + + @Lob + @Column(name="notification_record") + private String notificationRecord; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="last_seen") + private Date timeStamp; + + @PrePersist + public void prePersist(){ + this.timeStamp = new Date(); + } + + @PreUpdate + public void preUpdate(){ + this.timeStamp = new Date(); + } + + public String getResourceName(){ + return this.resourceName; + } + + public String getResourceNodeName(){ + return this.resourceNodeName; + } + + public String getFlag(){ + return this.flag; + } + + public String getNotificationRecord(){ + return this.notificationRecord; + } + + public Date getTimeStamp(){ + return this.timeStamp; + } + + public void setResourceName(String resourceName){ + this.resourceName = resourceName; + } + + public void setResoruceNodeName(String resourceNodeName){ + this.resourceNodeName = resourceNodeName; + } + + public void setFlag(String flag){ + this.flag = flag; + } + + public void setNotificationRecord(String notificationRecord){ + this.notificationRecord = notificationRecord; + } + + public void setTimeStamp(Date timeStamp){ + this.timeStamp = timeStamp; + } +} diff --git a/PolicyEngineUtils/src/main/java/org/openecomp/policy/std/NotificationStore.java b/PolicyEngineUtils/src/main/java/org/openecomp/policy/std/NotificationStore.java new file mode 100644 index 000000000..1c5950c5d --- /dev/null +++ b/PolicyEngineUtils/src/main/java/org/openecomp/policy/std/NotificationStore.java @@ -0,0 +1,264 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineUtils + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.std; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; + +import org.openecomp.policy.api.LoadedPolicy; +import org.openecomp.policy.api.NotificationType; +import org.openecomp.policy.api.PDPNotification; +import org.openecomp.policy.api.RemovedPolicy; + + +/* + * This Should Compare and save the Notifications from the beginning of Time. + * If there is something new (missed) We notify the client. + * Works for PDP failures. + * + */ +public class NotificationStore { + private static StdPDPNotification notificationRecord = new StdPDPNotification(); + + public static StdPDPNotification getDeltaNotification(StdPDPNotification newNotification){ + StdPDPNotification notificationDelta = new StdPDPNotification(); + ArrayList removedDelta = new ArrayList(); + ArrayList updatedDelta = new ArrayList(); + Collection newUpdatedPolicies = new ArrayList(); + Collection newRemovedPolicies = new ArrayList(); + Collection oldUpdatedLostPolicies = notificationRecord.getLoadedPolicies(); + Collection oldRemovedPolicies = notificationRecord.getRemovedPolicies(); + Collection oldUpdatedPolicies = notificationRecord.getLoadedPolicies(); + Boolean update = false; + Boolean remove = false; + // if the NotificationRecord is empty + if(notificationRecord.getRemovedPolicies()==null || notificationRecord.getLoadedPolicies()==null){ + if(newNotification!=null){ + notificationRecord = newNotification; + } + return notificationDelta; + } + // do the Delta operation. + if(newNotification!=null){ + // check for old removed policies. + if(!newNotification.getRemovedPolicies().isEmpty()){ + for(RemovedPolicy newRemovedPolicy: newNotification.getRemovedPolicies()){ + //Look for policy Not in Remove + Boolean removed = true; + for(RemovedPolicy oldRemovedPolicy: notificationRecord.getRemovedPolicies()){ + if(newRemovedPolicy.getPolicyName().equals(oldRemovedPolicy.getPolicyName())){ + if(newRemovedPolicy.getVersionNo().equals(oldRemovedPolicy.getVersionNo())){ + removed = false; + // Don't want a duplicate. + oldRemovedPolicies.remove(oldRemovedPolicy); + } + } + } + //We need to change our record we have an Update record of this remove. + for(LoadedPolicy oldUpdatedPolicy: notificationRecord.getLoadedPolicies()){ + if(newRemovedPolicy.getPolicyName().equals(oldUpdatedPolicy.getPolicyName())){ + if(newRemovedPolicy.getVersionNo().equals(oldUpdatedPolicy.getVersionNo())){ + oldUpdatedPolicies.remove(oldUpdatedPolicy); + oldUpdatedLostPolicies.remove(oldUpdatedPolicy); + } + } + } + if(removed){ + remove = true; + notificationRecord.getRemovedPolicies().add(newRemovedPolicy); + removedDelta.add((StdRemovedPolicy)newRemovedPolicy); + } + // This will be converted to New Later. + oldRemovedPolicies.add(newRemovedPolicy); + } + } + // Check for old Updated Policies. + if(!newNotification.getLoadedPolicies().isEmpty()){ + for(LoadedPolicy newUpdatedPolicy: newNotification.getLoadedPolicies()){ + // Look for policies which are not in Update + Boolean updated = true; + for(LoadedPolicy oldUpdatedPolicy: notificationRecord.getLoadedPolicies()){ + if(newUpdatedPolicy.getPolicyName().equals(oldUpdatedPolicy.getPolicyName())){ + if(newUpdatedPolicy.getVersionNo().equals(oldUpdatedPolicy.getVersionNo())){ + updated = false; + // Remove the policy from copy. + oldUpdatedLostPolicies.remove(oldUpdatedPolicy); + // Eliminating Duplicate. + oldUpdatedPolicies.remove(oldUpdatedPolicy); + } + } + } + // Change the record if the policy has been Removed earlier. + for(RemovedPolicy oldRemovedPolicy: notificationRecord.getRemovedPolicies()){ + if(oldRemovedPolicy.getPolicyName().equals(newUpdatedPolicy.getPolicyName())){ + if(oldRemovedPolicy.getVersionNo().equals(newUpdatedPolicy.getVersionNo())){ + oldRemovedPolicies.remove(oldRemovedPolicy); + } + } + } + if(updated){ + update = true; + updatedDelta.add((StdLoadedPolicy)newUpdatedPolicy); + } + // This will be converted to new Later + oldUpdatedPolicies.add(newUpdatedPolicy); + } + // Conversion of Update to Remove if that occurred. + if(!oldUpdatedLostPolicies.isEmpty()){ + for(LoadedPolicy updatedPolicy: oldUpdatedLostPolicies){ + StdRemovedPolicy removedPolicy = new StdRemovedPolicy(); + removedPolicy.setPolicyName(updatedPolicy.getPolicyName()); + removedPolicy.setVersionNo(updatedPolicy.getVersionNo()); + removedDelta.add(removedPolicy); + remove = true; + } + } + } + // Update our Record. + if(!oldUpdatedPolicies.isEmpty()){ + for(LoadedPolicy updatedPolicy: oldUpdatedPolicies){ + newUpdatedPolicies.add((StdLoadedPolicy)updatedPolicy); + } + } + if(!oldRemovedPolicies.isEmpty()){ + for(RemovedPolicy removedPolicy: oldRemovedPolicies){ + newRemovedPolicies.add((StdRemovedPolicy)removedPolicy); + } + } + notificationRecord.setRemovedPolicies(newRemovedPolicies); + notificationRecord.setLoadedPolicies(newUpdatedPolicies); + // Update the notification Result. + notificationDelta.setRemovedPolicies(removedDelta); + notificationDelta.setLoadedPolicies(updatedDelta); + if(remove&&update){ + notificationDelta.setNotificationType(NotificationType.BOTH); + }else if(remove){ + notificationDelta.setNotificationType(NotificationType.REMOVE); + }else if(update){ + notificationDelta.setNotificationType(NotificationType.UPDATE); + } + } + return notificationDelta; + } + + public static void recordNotification(StdPDPNotification notification){ + if(notification!=null){ + if(notificationRecord.getRemovedPolicies()==null || notificationRecord.getLoadedPolicies()==null){ + notificationRecord = notification; + }else{ + // Check if there is anything new and update the record. + if(notificationRecord.getLoadedPolicies()!=null || notificationRecord.getRemovedPolicies()!=null){ + HashSet removedPolicies = new HashSet(); + for(RemovedPolicy rPolicy: notificationRecord.getRemovedPolicies()){ + StdRemovedPolicy sRPolicy = new StdRemovedPolicy(); + sRPolicy.setPolicyName(rPolicy.getPolicyName()); + sRPolicy.setVersionNo(rPolicy.getVersionNo()); + removedPolicies.add(sRPolicy); + } + HashSet updatedPolicies = new HashSet(); + for(LoadedPolicy uPolicy: notificationRecord.getLoadedPolicies()){ + StdLoadedPolicy sUPolicy = new StdLoadedPolicy(); + sUPolicy.setMatches(uPolicy.getMatches()); + sUPolicy.setPolicyName(uPolicy.getPolicyName()); + sUPolicy.setVersionNo(uPolicy.getVersionNo()); + updatedPolicies.add(sUPolicy); + } + + // Checking with the new updated policies. + if(notification.getLoadedPolicies()!=null && !notification.getLoadedPolicies().isEmpty()){ + for(LoadedPolicy newUpdatedPolicy: notification.getLoadedPolicies()){ + // If it was removed earlier then we need to remove from our record + Iterator oldRemovedPolicy = removedPolicies.iterator(); + while(oldRemovedPolicy.hasNext()){ + RemovedPolicy policy = oldRemovedPolicy.next(); + if(newUpdatedPolicy.getPolicyName().equals(policy.getPolicyName())) { + if(newUpdatedPolicy.getVersionNo().equals(policy.getVersionNo())) { + oldRemovedPolicy.remove(); + } + } + } + // If it was previously updated need to Overwrite it to the record. + Iterator oldUpdatedPolicy = updatedPolicies.iterator(); + while(oldUpdatedPolicy.hasNext()){ + LoadedPolicy policy = oldUpdatedPolicy.next(); + if(newUpdatedPolicy.getPolicyName().equals(policy.getPolicyName())) { + if(newUpdatedPolicy.getVersionNo().equals(policy.getVersionNo())) { + oldUpdatedPolicy.remove(); + } + } + } + StdLoadedPolicy sUPolicy = new StdLoadedPolicy(); + sUPolicy.setMatches(newUpdatedPolicy.getMatches()); + sUPolicy.setPolicyName(newUpdatedPolicy.getPolicyName()); + sUPolicy.setVersionNo(newUpdatedPolicy.getVersionNo()); + updatedPolicies.add(sUPolicy); + } + } + // Checking with New Removed Policies. + if(notification.getRemovedPolicies()!=null && !notification.getRemovedPolicies().isEmpty()){ + for(RemovedPolicy newRemovedPolicy : notification.getRemovedPolicies()){ + // If it was previously removed Overwrite it to the record. + Iterator oldRemovedPolicy = removedPolicies.iterator(); + while(oldRemovedPolicy.hasNext()){ + RemovedPolicy policy = oldRemovedPolicy.next(); + if(newRemovedPolicy.getPolicyName().equals(policy.getPolicyName())) { + if(newRemovedPolicy.getVersionNo().equals(policy.getVersionNo())) { + oldRemovedPolicy.remove(); + } + } + } + // If it was added earlier then we need to remove from our record. + Iterator oldUpdatedPolicy = updatedPolicies.iterator(); + while(oldUpdatedPolicy.hasNext()){ + LoadedPolicy policy = oldUpdatedPolicy.next(); + if(newRemovedPolicy.getPolicyName().equals(policy.getPolicyName())) { + if(newRemovedPolicy.getVersionNo().equals(policy.getVersionNo())) { + oldUpdatedPolicy.remove(); + } + } + } + StdRemovedPolicy sRPolicy = new StdRemovedPolicy(); + sRPolicy.setPolicyName(newRemovedPolicy.getPolicyName()); + sRPolicy.setVersionNo(newRemovedPolicy.getVersionNo()); + removedPolicies.add(sRPolicy); + } + } + notificationRecord.setRemovedPolicies(removedPolicies); + notificationRecord.setLoadedPolicies(updatedPolicies); + } + if(!notificationRecord.getLoadedPolicies().isEmpty() && !notificationRecord.getRemovedPolicies().isEmpty()){ + notificationRecord.setNotificationType(NotificationType.BOTH); + }else if(!notificationRecord.getLoadedPolicies().isEmpty()){ + notificationRecord.setNotificationType(NotificationType.UPDATE); + }else if(!notificationRecord.getRemovedPolicies().isEmpty()){ + notificationRecord.setNotificationType(NotificationType.REMOVE); + } + } + } + } + + // This should return the current Notification Record. + public static PDPNotification getNotificationRecord(){ + return notificationRecord; + } +} diff --git a/PolicyEngineUtils/src/main/java/org/openecomp/policy/std/StdLoadedPolicy.java b/PolicyEngineUtils/src/main/java/org/openecomp/policy/std/StdLoadedPolicy.java new file mode 100644 index 000000000..e11ec8ce7 --- /dev/null +++ b/PolicyEngineUtils/src/main/java/org/openecomp/policy/std/StdLoadedPolicy.java @@ -0,0 +1,72 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineUtils + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.std; + +import java.util.Map; + +import org.openecomp.policy.api.LoadedPolicy; +import org.openecomp.policy.api.UpdateType; + +public class StdLoadedPolicy implements LoadedPolicy{ + private String policyName = null; + private String versionNo = null; + private Map matches = null; + private UpdateType updateType = null; + + @Override + public String getPolicyName() { + if(policyName!=null && policyName.contains(".xml")){ + return (policyName.substring(0, policyName.substring(0, policyName.lastIndexOf(".")).lastIndexOf("."))); + } + return this.policyName; + } + + public void setPolicyName(String policyName) { + this.policyName = policyName; + } + + @Override + public String getVersionNo() { + return this.versionNo; + } + + public void setVersionNo(String versionNo) { + this.versionNo = versionNo; + } + + @Override + public Map getMatches() { + return this.matches; + } + + public void setMatches(Map matches) { + this.matches = matches; + } + + @Override + public UpdateType getUpdateType() { + return this.updateType; + } + + public void setUpdateType(UpdateType updateType){ + this.updateType = updateType; + } +} diff --git a/PolicyEngineUtils/src/main/java/org/openecomp/policy/std/StdPDPNotification.java b/PolicyEngineUtils/src/main/java/org/openecomp/policy/std/StdPDPNotification.java new file mode 100644 index 000000000..6a6bf23e5 --- /dev/null +++ b/PolicyEngineUtils/src/main/java/org/openecomp/policy/std/StdPDPNotification.java @@ -0,0 +1,80 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineUtils + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.std; + +import java.util.Collection; +import java.util.HashSet; + +import org.openecomp.policy.api.LoadedPolicy; +import org.openecomp.policy.api.NotificationType; +import org.openecomp.policy.api.PDPNotification; +import org.openecomp.policy.api.RemovedPolicy; + +public class StdPDPNotification implements PDPNotification{ + private Collection removedPolicies = null; + private Collection loadedPolicies = null; + private Collection removed = null; + private Collection updated = null; + private NotificationType notificationType= null; + + @Override + public Collection getRemovedPolicies() { + removed = new HashSet(); + if(removedPolicies!=null){ + for(RemovedPolicy removedPolicy: removedPolicies){ + removed.add(removedPolicy); + } + return this.removed; + }else{ + return null; + } + } + + @Override + public Collection getLoadedPolicies() { + updated = new HashSet(); + if(loadedPolicies!=null){ + for(LoadedPolicy updatedPolicy: loadedPolicies){ + updated.add(updatedPolicy); + } + return updated; + }else{ + return null; + } + } + + @Override + public NotificationType getNotificationType() { + return notificationType; + } + + public void setNotificationType(NotificationType notificationType){ + this.notificationType= notificationType; + } + + public void setLoadedPolicies(Collection loadedPolicies) { + this.loadedPolicies = loadedPolicies; + } + + public void setRemovedPolicies(Collection removedPolicies) { + this.removedPolicies = removedPolicies; + } +} diff --git a/PolicyEngineUtils/src/main/java/org/openecomp/policy/std/StdRemovedPolicy.java b/PolicyEngineUtils/src/main/java/org/openecomp/policy/std/StdRemovedPolicy.java new file mode 100644 index 000000000..665f3c584 --- /dev/null +++ b/PolicyEngineUtils/src/main/java/org/openecomp/policy/std/StdRemovedPolicy.java @@ -0,0 +1,49 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineUtils + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.std; + +import org.openecomp.policy.api.RemovedPolicy; + +public class StdRemovedPolicy implements RemovedPolicy{ + private String policyName = null; + private String versionNo = null; + + @Override + public String getVersionNo() { + return this.versionNo; + } + + public void setVersionNo(String versionNo) { + this.versionNo = versionNo; + } + + @Override + public String getPolicyName() { + if(policyName!=null && policyName.contains(".xml")){ + return (policyName.substring(0, policyName.substring(0, policyName.lastIndexOf(".")).lastIndexOf("."))); + } + return this.policyName; + } + + public void setPolicyName(String policyName) { + this.policyName = policyName; + } +} diff --git a/PolicyEngineUtils/src/main/java/org/openecomp/policy/utils/AAFPolicyClient.java b/PolicyEngineUtils/src/main/java/org/openecomp/policy/utils/AAFPolicyClient.java new file mode 100644 index 000000000..1565c18d0 --- /dev/null +++ b/PolicyEngineUtils/src/main/java/org/openecomp/policy/utils/AAFPolicyClient.java @@ -0,0 +1,208 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineUtils + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + + +package org.openecomp.policy.utils; + +import java.io.IOException; +import java.util.Properties; + +import org.apache.log4j.Logger; + +import com.att.cadi.Access; +import com.att.cadi.Access.Level; +import com.att.cadi.CadiException; +import com.att.cadi.aaf.AAFPermission; +import com.att.cadi.aaf.v2_0.AAFAuthn; +import com.att.cadi.aaf.v2_0.AAFCon; +import com.att.cadi.aaf.v2_0.AAFConDME2; +import com.att.cadi.aaf.v2_0.AAFLurPerm; +import com.att.cadi.config.Config; + + +/** + * AAF Client: Generic AAF Client implementation to connect to AAF Resources to validate permissions and authorization. + * + */ +public class AAFPolicyClient { + private static Logger LOGGER = Logger.getLogger(AAFPolicyClient.class.getName()); + + private static final String DEFAULT_AFT_LATITUDE = "32.780140"; + private static final String DEFAULT_AFT_LONGITUDE = "-96.800451"; + private static final String DEFAULT_AAF_USER_EXPIRES = Integer.toString(5*60000); // 5 minutes for found items to live in cache + private static final String DEFAULT_AAF_HIGH_COUNT = Integer.toString(400); // Maximum number of items in Cache + + private static AAFPolicyClient instance = null; + private static Properties props = new Properties(); + private static AAFCon aafCon = null; + private static AAFLurPerm aafLurPerm = null; + private static AAFAuthn aafAuthn = null; + private static Access access = null; + + + private AAFPolicyClient(Properties properties) throws AAFPolicyException{ + if(instance == null){ + instance = this; + } + setup(properties); + } + + /** + * Gets the instance of the AAFClient instance. Needs Proper properties with CLIENT_ID, CLIENT_KEY and ENVIRONMENT + * + * @param properties Properties with CLIENT_ID, CLIENT_KEY and ENVIRONMENT + * @return AAFClient instance. + * @throws AAFPolicyException Exceptions. + */ + public static synchronized AAFPolicyClient getInstance(Properties properties) throws AAFPolicyException{ + if(instance == null) { + LOGGER.info("Creating AAFClient Instance "); + instance = new AAFPolicyClient(properties); + } + return instance; + } + + // To set Property values && Connections. + private void setup(Properties properties) throws AAFPolicyException { + /*if(properties!=null && !properties.isEmpty()){ + props = System.getProperties(); + props.setProperty("AFT_LATITUDE", properties.getProperty("AFT_LATITUDE", DEFAULT_AFT_LATITUDE)); + props.setProperty("AFT_LONGITUDE", properties.getProperty("AFT_LONGITUDE", DEFAULT_AFT_LONGITUDE)); + props.setProperty("aaf_id",properties.getProperty("aaf_id", "aafID")); + props.setProperty("aaf_password", properties.getProperty("aaf_password", "aafPass")); + if(properties.containsKey(Config.AAF_URL)){ + // if given a value in properties file. + props.setProperty(Config.AAF_URL, properties.getProperty(Config.AAF_URL)); + }else{ + LOGGER.error("Required Property value is missing : " + Config.AAF_URL); + throw new AAFPolicyException("Required Property value is missing : " + Config.AAF_URL); + } + + if(properties.containsKey("AFT_ENVIRONMENT")){ + props.setProperty("AFT_ENVIRONMENT", properties.getProperty("AFT_ENVIRONMENT")); + }else{ + LOGGER.error("Required Property value is missing : AFT_ENVIRONMENT"); + throw new AAFPolicyException("Required Property value is missing : AFT_ENVIRONMENT"); + } + props.setProperty(Config.AAF_USER_EXPIRES, properties.getProperty(Config.AAF_USER_EXPIRES, DEFAULT_AAF_USER_EXPIRES)); + props.setProperty(Config.AAF_HIGH_COUNT, properties.getProperty(Config.AAF_HIGH_COUNT, DEFAULT_AAF_HIGH_COUNT)); + }else{ + LOGGER.error("Required Property value is missing "); + throw new AAFPolicyException("Required Property value is missing"); + } + access = new PolicyAccess(props, Level.valueOf(properties.getProperty("AAF_LOG_LEVEL", Level.INFO.toString()))); + setUpAAF();*/ + } + + /** + * Updates the Properties file in case if required. + * + * @param properties Properties with CLIENT_ID, CLIENT_KEY and ENVIRONMENT + * @throws AAFPolicyException exceptions if any. + */ + public void updateProperties(Properties properties) throws AAFPolicyException{ + setup(properties); + } + + /** + * Checks the Authentication and Permissions for the given values. + * + * @param pass Password pertaining to the loginId + * @param type Permissions Type. + * @param instance Permissions Instance. + * @param action Permissions Action. + * @return + */ + public boolean checkAuthPerm(String mechID, String pass, String type, String instance, String action){ + if(checkAuth(mechID, pass) && checkPerm(mechID, pass, type, instance, action)){ + return true; + } + return false; + } + + /** + * Checks the Authentication of the UserName and Password Given. + * + * @param userName UserName + * @param pass Password. + * @return True or False. + */ + public boolean checkAuth(String userName, String pass){ + /*if(aafAuthn!=null){ + try { + int i=0; + do{ + if(aafAuthn.validate(userName, pass)==null){ + return true; + } + i++; + }while(i<2); + } catch (Exception e) { + LOGGER.error(e.getMessage()); + } + } + LOGGER.debug("Authentication failed for : " + userName + " in " + props.getProperty("AAF_URL")); + return false;*/ + return true; + } + + /** + * Checks Permissions for the given UserName, Password and Type, Instance Action. + * + * @param userName UserName + * @param pass Password. + * @param type Permissions Type. + * @param instance Permissions Instance. + * @param action Permissions Action. + * @return True or False. + */ + public boolean checkPerm(String userName, String pass, String type, String instance, String action){ + /*int i =0; + Boolean result= false; + do{ + if(aafCon!=null && aafLurPerm !=null){ + try { + aafCon.basicAuth(userName, pass); + AAFPermission perm = new AAFPermission(type, instance, action); + result = aafLurPerm.fish(userName, perm); + } catch (CadiException e) { + LOGGER.error(e.getMessage()); + aafLurPerm.destroy(); + } + } + LOGGER.debug("Permissions for : " + userName + " in " + props.getProperty("AAF_URL") + "for " + type + "," + instance + "," + action + "\n Result is: " + result); + i++; + }while(i<2 && !result); // Try once more to check if this can be passed. AAF has some issues. + return result;*/ + return true; + } + + /*private boolean setUpAAF(){ + try { + aafCon = new AAFConDME2(access); + aafLurPerm = aafCon.newLur();//new AAFLurPerm(aafCon); + aafAuthn = aafCon.newAuthn(aafLurPerm);//new AAFAuthn(aafCon, aafLurPerm); + return true; + } catch (Exception e) { + LOGGER.error("Error while creating Connection " + e.getMessage()); + return false; + } + }*/ +} diff --git a/PolicyEngineUtils/src/main/java/org/openecomp/policy/utils/AAFPolicyException.java b/PolicyEngineUtils/src/main/java/org/openecomp/policy/utils/AAFPolicyException.java new file mode 100644 index 000000000..a798b6e53 --- /dev/null +++ b/PolicyEngineUtils/src/main/java/org/openecomp/policy/utils/AAFPolicyException.java @@ -0,0 +1,48 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineUtils + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.utils; + +/** + * AAFPolicyException to show exception messages. + * + */ +public class AAFPolicyException extends Exception { + private static final long serialVersionUID = 1910606668038621L; + + public AAFPolicyException() { + } + + public AAFPolicyException(String message) { + super(message); + } + + public AAFPolicyException(Throwable cause){ + super(cause); + } + + public AAFPolicyException(String message, Throwable cause) { + super(message, cause); + } + + public AAFPolicyException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } +} diff --git a/PolicyEngineUtils/src/main/java/org/openecomp/policy/utils/BackUpHandler.java b/PolicyEngineUtils/src/main/java/org/openecomp/policy/utils/BackUpHandler.java new file mode 100644 index 000000000..227d0ceff --- /dev/null +++ b/PolicyEngineUtils/src/main/java/org/openecomp/policy/utils/BackUpHandler.java @@ -0,0 +1,41 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineUtils + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.utils; + +import org.openecomp.policy.api.NotificationHandler; +import org.openecomp.policy.api.PDPNotification; + +public interface BackUpHandler extends NotificationHandler{ + + /** + * notificationReceived method will be triggered automatically whenever a Notification is received by the PEP. + * + * @param notification PDPNotification of {@link org.openecomp.policy.api.PDPNotification} is the object that has information of the notification. + */ + public void notificationReceived(PDPNotification notification); + + /** + * runOnNotification method will be triggered automatically whenever a Notification is received by the PEP This needs to be the main implementation. + * + * @param notification PDPNotification of {@link org.openecomp.policy.api.PDPNotification} is the object that has information of the notification. + */ + public void runOnNotification(PDPNotification notification); +} diff --git a/PolicyEngineUtils/src/main/java/org/openecomp/policy/utils/BackUpMonitor.java b/PolicyEngineUtils/src/main/java/org/openecomp/policy/utils/BackUpMonitor.java new file mode 100644 index 000000000..1b35dcc57 --- /dev/null +++ b/PolicyEngineUtils/src/main/java/org/openecomp/policy/utils/BackUpMonitor.java @@ -0,0 +1,378 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineUtils + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.utils; + +import java.io.IOException; +import java.util.Date; +import java.util.List; +import java.util.Properties; +import java.util.concurrent.TimeUnit; + +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.EntityTransaction; +import javax.persistence.Persistence; +import javax.persistence.Query; + +import org.apache.log4j.Logger; +import org.eclipse.persistence.config.PersistenceUnitProperties; +import org.openecomp.policy.api.PDPNotification; +import org.openecomp.policy.jpa.BackUpMonitorEntity; +import org.openecomp.policy.std.NotificationStore; +import org.openecomp.policy.std.StdPDPNotification; + +import com.fasterxml.jackson.databind.JsonNode; +import com.github.fge.jackson.JsonLoader; +import com.github.fge.jsonpatch.JsonPatch; +import com.github.fge.jsonpatch.JsonPatchException; +import com.github.fge.jsonpatch.diff.JsonDiff; + +/** + * BackUp Monitor checks Backup Status with the Database and maintains Redundancy for Gateway Applications. + * + */ +public class BackUpMonitor { + private static final Logger logger = Logger.getLogger(BackUpMonitor.class.getName()); + private static final int DEFAULT_PING = 60000; // Value is in milliseconds. + + private static BackUpMonitor instance = null; + private static String resourceName = null; + private static String resourceNodeName = null; + private static String notificationRecord = null; + private static String lastMasterNotification= null; + private static int pingInterval = DEFAULT_PING; + private static Boolean masterFlag = false; + private static Object lock = new Object(); + private static Object notificationLock = new Object(); + private static BackUpHandler handler= null; + private EntityManager em; + private EntityManagerFactory emf; + + /* + * Enumeration for the Resource Node Naming. Add here if required. + */ + public enum ResourceNode{ + BRMS, + ASTRA + } + + private BackUpMonitor(String resourceNodeName, String resourceName, Properties properties, BackUpHandler handler) throws Exception{ + if(instance == null){ + instance = this; + } + BackUpMonitor.resourceNodeName = resourceNodeName; + BackUpMonitor.resourceName = resourceName; + BackUpMonitor.handler = handler; + // Create Persistence Entity + properties.setProperty(PersistenceUnitProperties.ECLIPSELINK_PERSISTENCE_XML, "META-INF/persistencePU.xml"); + emf = Persistence.createEntityManagerFactory("PolicyEngineUtils", properties); + if(emf==null){ + logger.error("Unable to create Entity Manger Factory "); + throw new Exception("Unable to create Entity Manger Factory"); + } + em = emf.createEntityManager(); + + // Check Database if this is Master or Slave. + checkDataBase(); + + // Start thread. + Thread t = new Thread(new BMonitor()); + t.start(); + } + + /** + * Gets the BackUpMonitor Instance if given proper resourceName and properties. Else returns null. + * + * @param resourceNodeName String format of the Resource Node to which the resource Belongs to. + * @param resourceName String format of the ResourceName. This needs to be Unique. + * @param properties Properties format of the properties file. + * @return BackUpMonitor instance. + */ + public static synchronized BackUpMonitor getInstance(String resourceNodeName, String resourceName, Properties properties, BackUpHandler handler) throws Exception { + if(resourceNodeName==null || resourceNodeName.trim().equals("") ||resourceName==null|| resourceName.trim().equals("") || properties == null || handler==null){ + logger.error("Error while getting Instance. Please check resourceName and/or properties file"); + return null; + }else if((resourceNodeName.equals(ResourceNode.ASTRA.toString()) || resourceNodeName.equals(ResourceNode.BRMS.toString())) && validate(properties) && instance==null){ + logger.info("Creating Instance of BackUpMonitor"); + instance = new BackUpMonitor(resourceNodeName, resourceName, properties, handler); + } + return instance; + } + + // This is to validate given Properties with required values. + private static Boolean validate(Properties properties){ + if(properties.getProperty("javax.persistence.jdbc.driver")==null ||properties.getProperty("javax.persistence.jdbc.driver").trim().equals("")){ + logger.error("javax.persistence.jdbc.driver property is empty"); + return false; + } + if(properties.getProperty("javax.persistence.jdbc.url")==null || properties.getProperty("javax.persistence.jdbc.url").trim().equals("")){ + logger.error("javax.persistence.jdbc.url property is empty"); + return false; + } + if(properties.getProperty("javax.persistence.jdbc.user")==null || properties.getProperty("javax.persistence.jdbc.user").trim().equals("")){ + logger.error("javax.persistence.jdbc.user property is empty"); + return false; + } + if(properties.getProperty("javax.persistence.jdbc.password")==null || properties.getProperty("javax.persistence.jdbc.password").trim().equals("")){ + logger.error("javax.persistence.jdbc.password property is empty"); + return false; + } + if(properties.getProperty("ping_interval")==null || properties.getProperty("ping_interval").trim().equals("")){ + logger.info("ping_interval property not specified. Taking default value"); + }else{ + try{ + pingInterval = Integer.parseInt(properties.getProperty("ping_interval").trim()); + }catch(NumberFormatException e){ + logger.warn("Ignored invalid proeprty ping_interval. Taking default value."); + pingInterval = DEFAULT_PING; + } + } + return true; + } + + // Sets the Flag for masterFlag to either True or False. + private static void setFlag(Boolean flag){ + synchronized (lock) { + masterFlag = flag; + } + } + + /** + * Gets the Boolean value of Master(True) or Slave mode (False) + * + * @return Boolean flag which if True means that the operation needs to be performed(Master mode) or if false the operation is in slave mode. + */ + public synchronized Boolean getFlag(){ + synchronized (lock) { + return masterFlag; + } + } + + // BackUpMonitor Thread + private class BMonitor implements Runnable{ + @Override + public void run() { + logger.info("Starting BackUpMonitor Thread.. "); + while(true){ + try { + TimeUnit.MILLISECONDS.sleep(pingInterval); + checkDataBase(); + } catch (Exception e) { + logger.error("Error during Thread execution " + e.getMessage()); + } + } + } + } + + // Set Master + private static BackUpMonitorEntity setMaster(BackUpMonitorEntity bMEntity){ + bMEntity.setFlag("MASTER"); + setFlag(true); + return bMEntity; + } + + // Set Slave + private static BackUpMonitorEntity setSlave(BackUpMonitorEntity bMEntity){ + bMEntity.setFlag("SLAVE"); + setFlag(false); + return bMEntity; + } + + // Check Database and set the Flag. + private void checkDataBase() throws Exception { + EntityTransaction et = em.getTransaction(); + notificationRecord = PolicyUtils.objectToJsonString(NotificationStore.getNotificationRecord()); + // Clear Cache. + logger.info("Clearing Cache"); + em.getEntityManagerFactory().getCache().evictAll(); + try{ + logger.info("Checking Datatbase for BackUpMonitor.. "); + et.begin(); + Query query = em.createQuery("select b from BackUpMonitorEntity b where b.resourceNodeName = :nn"); + if(resourceNodeName.equals(ResourceNode.ASTRA.toString())){ + query.setParameter("nn", ResourceNode.ASTRA.toString()); + }else if(resourceNodeName.equals(ResourceNode.BRMS.toString())){ + query.setParameter("nn", ResourceNode.BRMS.toString()); + } + List bMList = query.getResultList(); + if(bMList.isEmpty()){ + // This is New. create an entry as Master. + logger.info("Adding resource " + resourceName + " to Database"); + BackUpMonitorEntity bMEntity = new BackUpMonitorEntity(); + bMEntity.setResoruceNodeName(resourceNodeName); + bMEntity.setResourceName(resourceName); + bMEntity = setMaster(bMEntity); + bMEntity.setTimeStamp(new Date()); + em.persist(bMEntity); + em.flush(); + }else{ + // Check if resourceName already exists and if there is a Master in Node. + Boolean masterFlag = false; + Boolean alreadyMaster = false; + Date currentTime; + BackUpMonitorEntity masterEntity = null; + BackUpMonitorEntity slaveEntity = null; + long timeDiff = 0; + for(int i=0; i< bMList.size(); i++){ + BackUpMonitorEntity bMEntity = (BackUpMonitorEntity) bMList.get(i); + logger.info("Refreshing Entity. "); + em.refresh(bMEntity); + if(bMEntity.getResourceName().equals(resourceName)){ + logger.info("Resource Name already Exists. " + resourceName); + if(bMEntity.getFlag().equalsIgnoreCase("MASTER")){ + // Master mode + setFlag(true); + logger.info(resourceName + " is on Master Mode"); + bMEntity.setTimeStamp(new Date()); + bMEntity.setNotificationRecord(notificationRecord); + em.persist(bMEntity); + em.flush(); + setLastNotification(null); + alreadyMaster = true; + break; + }else{ + // Slave mode. + setFlag(false); + slaveEntity = bMEntity; + logger.info(resourceName + " is on Slave Mode"); + } + }else{ + if(bMEntity.getFlag().equalsIgnoreCase("MASTER")){ + // check if its time stamp is old. + currentTime = new Date(); + timeDiff = currentTime.getTime()-bMEntity.getTimeStamp().getTime(); + masterEntity = bMEntity; + masterFlag = true; + } + } + } + // If there is master and no slave entry then add the slave entry to database. + // If we are slave and there is a masterFlag then check timeStamp to find if master is down. + if(!alreadyMaster){ + BackUpMonitorEntity bMEntity; + if(slaveEntity==null){ + bMEntity = new BackUpMonitorEntity(); + }else{ + bMEntity = slaveEntity; + } + if(masterFlag && !getFlag()){ + if(timeDiff > pingInterval){ + // This is down or has an issue and we need to become Master while turning the Master to slave. + masterEntity = setSlave(masterEntity); + String lastNotification = null; + if(masterEntity.getNotificationRecord()!=null){ + lastNotification = calculatePatch(masterEntity.getNotificationRecord()); + } + setLastNotification(lastNotification); + em.persist(masterEntity); + em.flush(); + bMEntity = setMaster(bMEntity); + logger.info(resourceName + " changed to Master Mode"); + }else{ + bMEntity = setSlave(bMEntity); + setLastNotification(null); + logger.info(resourceName + " is on Slave Mode"); + } + }else{ + // If there is no Master. we need to become Master. + bMEntity = setMaster(bMEntity); + logger.info(resourceName + " is on Master Mode"); + setLastNotification(null); + } + bMEntity.setNotificationRecord(notificationRecord); + bMEntity.setResoruceNodeName(resourceNodeName); + bMEntity.setResourceName(resourceName); + bMEntity.setTimeStamp(new Date()); + em.persist(bMEntity); + em.flush(); + } + } + et.commit(); + }catch(Exception e){ + logger.error("failed Database Operation " + e.getMessage()); + if(et.isActive()){ + et.rollback(); + } + throw new Exception(e); + } + } + + // Calculate Patch and return String JsonPatch of the notification Delta. + private synchronized String calculatePatch(String oldNotificationRecord) { + try{ + JsonNode notification = JsonLoader.fromString(notificationRecord); + JsonNode oldNotification = JsonLoader.fromString(oldNotificationRecord); + JsonNode patchNode = JsonDiff.asJson(oldNotification, notification); + logger.info("Generated JSON Patch is " + patchNode.toString()); + JsonPatch patch = JsonPatch.fromJson(patchNode); + try { + JsonNode patched = patch.apply(oldNotification); + logger.info("Generated New Notification is : " + patched.toString()); + return patched.toString(); + } catch (JsonPatchException e) { + logger.error("Error generating Patched " +e.getMessage()); + return null; + } + }catch(IOException e){ + logger.error("Error generating Patched " +e.getMessage()); + return null; + } + } + + /** + * Updates Notification in the Database while Performing the health check. + * + * @param notification String format of notification record to store in the Database. + * @throws Exception + */ + public synchronized void updateNotification() throws Exception{ + checkDataBase(); + } + + // Take in string notification and send the record delta to Handler. + private static void callHandler(String notification){ + if(handler!=null){ + try { + PDPNotification notificationObject = PolicyUtils.jsonStringToObject(notification, StdPDPNotification.class); + if(notificationObject.getNotificationType()!=null){ + logger.info("Performing Patched notification "); + try{ + handler.runOnNotification(notificationObject); + }catch (Exception e){ + logger.error("Error in Clients Handler Object : " + e.getMessage()); + } + } + } catch (IOException e) { + logger.info("Error while notification Conversion " + e.getMessage()); + } + } + } + + // Used to set LastMasterNotification Record. + private static void setLastNotification(String notification){ + synchronized(notificationLock){ + lastMasterNotification = notification; + if(lastMasterNotification!=null && !lastMasterNotification.equals("\"notificationType\":null")){ + callHandler(notification); + } + } + } +} diff --git a/PolicyEngineUtils/src/main/java/org/openecomp/policy/utils/PolicyAccess.java b/PolicyEngineUtils/src/main/java/org/openecomp/policy/utils/PolicyAccess.java new file mode 100644 index 000000000..6141a5f73 --- /dev/null +++ b/PolicyEngineUtils/src/main/java/org/openecomp/policy/utils/PolicyAccess.java @@ -0,0 +1,107 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineUtils + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.utils; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Date; +import java.util.Properties; + +import org.apache.log4j.Logger; + +import com.att.cadi.Access; + +/** + * PolicyAccess used by AAF for logging purposes. + * + */ +public class PolicyAccess implements Access { + private static final Logger logger = Logger.getLogger(PolicyAccess.class.getName()); + + private Properties properties = new Properties(); + private Access.Level logLevel = Access.Level.INFO; + + public PolicyAccess(Properties properties, Level level) { + this.properties = properties; + if(level!=null){ + logLevel = level; + } + } + + @Override + public ClassLoader classLoader() { + return getClass().getClassLoader(); + } + + @Override + public String decrypt(String enc, boolean arg1) throws IOException { + return enc; + } + + @Override + public String getProperty(String prop, String def) { + return properties.getProperty(prop, def); + } + + @Override + public void load(InputStream in) throws IOException { + properties.load(in); + } + + @Override + public void log(Level level, Object... args) { + if (logLevel.compareTo(level) > 0) { + return; + } + StringBuffer sb = new StringBuffer(); + sb.append(new Date()).append(' ').append(level); + logtail(sb, args); + } + + @Override + public void log(Exception e, Object... args) { + StringBuffer sb = new StringBuffer(); + sb.append(new Date()).append(" EXCEPTION ").append(e.getMessage()); + logtail(sb, args); + logger.error(e.getMessage() + e); + } + + @Override + public void setLogLevel(Level level) { + logLevel = level; + } + + private void logtail(StringBuffer sb, Object[] args) { + for (Object o: args) { + String s = o.toString(); + if (s.length() > 0) { + sb.append(' ').append(s); + } + } + logger.info(sb.toString()); + } + + @Override + public boolean willLog(Level arg0) { + // TODO Auto-generated method stub + return false; + } +} diff --git a/PolicyEngineUtils/src/main/java/org/openecomp/policy/utils/PolicyUtils.java b/PolicyEngineUtils/src/main/java/org/openecomp/policy/utils/PolicyUtils.java new file mode 100644 index 000000000..fd8102af3 --- /dev/null +++ b/PolicyEngineUtils/src/main/java/org/openecomp/policy/utils/PolicyUtils.java @@ -0,0 +1,59 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineUtils + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.utils; + +import java.io.IOException; +import java.util.Base64; +import java.util.StringTokenizer; + +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class PolicyUtils { + + public static String objectToJsonString(Object o) throws JsonProcessingException{ + ObjectMapper mapper = new ObjectMapper(); + return mapper.writeValueAsString(o); + } + + public static T jsonStringToObject(String jsonString, Class className) throws JsonParseException, JsonMappingException, IOException{ + ObjectMapper mapper = new ObjectMapper(); + T t = mapper.readValue(jsonString, className); + return t; + } + + public static String[] decodeBasicEncoding(String encodedValue) throws Exception{ + if(encodedValue!=null && encodedValue.contains("Basic ")){ + String encodedUserPassword = encodedValue.replaceFirst("Basic" + " ", ""); + String usernameAndPassword = null; + byte[] decodedBytes = Base64.getDecoder().decode(encodedUserPassword); + usernameAndPassword = new String(decodedBytes, "UTF-8"); + StringTokenizer tokenizer = new StringTokenizer(usernameAndPassword, ":"); + String username = tokenizer.nextToken(); + String password = tokenizer.nextToken(); + return new String[]{username, password}; + }else{ + return null; + } + } +} diff --git a/PolicyEngineUtils/src/main/resources/META-INF/persistencePU.xml b/PolicyEngineUtils/src/main/resources/META-INF/persistencePU.xml new file mode 100644 index 000000000..147dddf8e --- /dev/null +++ b/PolicyEngineUtils/src/main/resources/META-INF/persistencePU.xml @@ -0,0 +1,29 @@ + + + + + + org.eclipse.persistence.jpa.PersistenceProvider + org.openecomp.policy.jpa.BackUpMonitorEntity + + diff --git a/PolicyEngineUtils/src/test/java/org/openecomp/policy/test/Handler.java b/PolicyEngineUtils/src/test/java/org/openecomp/policy/test/Handler.java new file mode 100644 index 000000000..eb811ab22 --- /dev/null +++ b/PolicyEngineUtils/src/test/java/org/openecomp/policy/test/Handler.java @@ -0,0 +1,38 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineUtils + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.test; + +import org.openecomp.policy.api.PDPNotification; +import org.openecomp.policy.utils.BackUpHandler; + +public class Handler implements BackUpHandler{ + + @Override + public void notificationReceived(PDPNotification notification) { + System.out.println("Received Notification from PDP. "); + } + + @Override + public void runOnNotification(PDPNotification notification) { + System.out.println("Running main Notification Function. "); + } + +} diff --git a/PolicyEngineUtils/src/test/java/org/openecomp/policy/test/PolicyUtilsTest.java b/PolicyEngineUtils/src/test/java/org/openecomp/policy/test/PolicyUtilsTest.java new file mode 100644 index 000000000..c3f8bedb0 --- /dev/null +++ b/PolicyEngineUtils/src/test/java/org/openecomp/policy/test/PolicyUtilsTest.java @@ -0,0 +1,69 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineUtils + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.test; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.junit.Test; +import org.openecomp.policy.api.NotificationType; +import org.openecomp.policy.api.PDPNotification; +import org.openecomp.policy.api.UpdateType; +import org.openecomp.policy.std.StdLoadedPolicy; +import org.openecomp.policy.std.StdPDPNotification; +import org.openecomp.policy.std.StdRemovedPolicy; +import org.openecomp.policy.utils.PolicyUtils; + +public class PolicyUtilsTest { + + @Test + public void testJsonConversions() throws Exception{ + @SuppressWarnings("unused") + PolicyUtils policyUtils = new PolicyUtils(); + StdPDPNotification notification = new StdPDPNotification(); + notification.setNotificationType(NotificationType.BOTH); + Collection removedPolicies = new ArrayList(); + Collection loadedPolicies = new ArrayList(); + StdRemovedPolicy removedPolicy = new StdRemovedPolicy(); + StdLoadedPolicy updatedPolicy = new StdLoadedPolicy(); + removedPolicy.setPolicyName("Test"); + removedPolicy.setVersionNo("1"); + removedPolicies.add(removedPolicy); + updatedPolicy.setPolicyName("Testing"); + updatedPolicy.setVersionNo("1"); + updatedPolicy.setUpdateType(UpdateType.NEW); + Map matches = new HashMap(); + matches.put("key", "value"); + updatedPolicy.setMatches(matches); + loadedPolicies.add(updatedPolicy); + notification.setRemovedPolicies(removedPolicies); + notification.setLoadedPolicies(loadedPolicies); + + String json = PolicyUtils.objectToJsonString(notification); + PDPNotification getBackObject = PolicyUtils.jsonStringToObject(json, StdPDPNotification.class); + assertEquals(0,getBackObject.getNotificationType().compareTo(notification.getNotificationType())); + + } +} diff --git a/PolicyEngineUtils/src/test/java/org/openecomp/policy/test/testBackUpMonitor.java b/PolicyEngineUtils/src/test/java/org/openecomp/policy/test/testBackUpMonitor.java new file mode 100644 index 000000000..8763f0fca --- /dev/null +++ b/PolicyEngineUtils/src/test/java/org/openecomp/policy/test/testBackUpMonitor.java @@ -0,0 +1,121 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineUtils + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.test; + +import static org.junit.Assert.assertNull; +import java.util.Properties; + +import org.junit.Test; +import org.openecomp.policy.utils.BackUpMonitor; + + +public class testBackUpMonitor { + + @Test + public void backUpMonitorTestFail() throws Exception{ + Properties properties = new Properties(); + properties.setProperty("javax.persistence.jdbc.driver", "com.mysql.jdbc.Driver"); + properties.setProperty("javax.persistence.jdbc.url", "jdbc:mysql://localhost:3306/xacml"); + properties.setProperty("javax.persistence.jdbc.user", "policy_user"); + properties.setProperty("javax.persistence.jdbc.password", ""); + //properties.setProperty("ping_interval", "500000"); + BackUpMonitor bum = BackUpMonitor.getInstance(BackUpMonitor.ResourceNode.BRMS.toString(), "brms_test" , properties, new Handler()); + assertNull(bum); + } + + @Test + public void backUpMonitorTestFailNoUser() throws Exception{ + Properties properties = new Properties(); + properties.setProperty("javax.persistence.jdbc.driver", "com.mysql.jdbc.Driver"); + properties.setProperty("javax.persistence.jdbc.url", "jdbc:mysql://localhost:3306/xacml"); + properties.setProperty("javax.persistence.jdbc.user", ""); + properties.setProperty("javax.persistence.jdbc.password", "password"); + //properties.setProperty("ping_interval", "500000"); + BackUpMonitor bum = BackUpMonitor.getInstance(BackUpMonitor.ResourceNode.BRMS.toString(), "brms_test" , properties, new Handler()); + assertNull(bum); + } + + @Test + public void backUpMonitorTestFailNoURL() throws Exception{ + Properties properties = new Properties(); + properties.setProperty("javax.persistence.jdbc.driver", "com.mysql.jdbc.Driver"); + properties.setProperty("javax.persistence.jdbc.url", ""); + properties.setProperty("javax.persistence.jdbc.user", "test"); + properties.setProperty("javax.persistence.jdbc.password", "password"); + //properties.setProperty("ping_interval", "500000"); + BackUpMonitor bum = BackUpMonitor.getInstance(BackUpMonitor.ResourceNode.BRMS.toString(), "brms_test" , properties, new Handler()); + assertNull(bum); + } + + @Test + public void backUpMonitorTestFailNoDriver() throws Exception{ + Properties properties = new Properties(); + properties.setProperty("javax.persistence.jdbc.driver", ""); + properties.setProperty("javax.persistence.jdbc.url", "jdbc:mysql://localhost:3306/xacml"); + properties.setProperty("javax.persistence.jdbc.user", "test"); + properties.setProperty("javax.persistence.jdbc.password", "password"); + //properties.setProperty("ping_interval", "500000"); + BackUpMonitor bum = BackUpMonitor.getInstance(BackUpMonitor.ResourceNode.BRMS.toString(), "brms_test" , properties, new Handler()); + assertNull(bum); + } + + @Test + public void backUpMonitorTestFailNoNode() throws Exception{ + Properties properties = new Properties(); + properties.setProperty("javax.persistence.jdbc.driver", "com.mysql.jdbc.Driver"); + properties.setProperty("javax.persistence.jdbc.url", "jdbc:mysql://localhost:3306/xacml"); + properties.setProperty("javax.persistence.jdbc.user", "test"); + properties.setProperty("javax.persistence.jdbc.password", "password"); + //properties.setProperty("ping_interval", "500000"); + BackUpMonitor bum = BackUpMonitor.getInstance(null, "brms_test" , properties, new Handler()); + assertNull(bum); + } + + @Test + public void backUpMonitorTestFailNoResource() throws Exception{ + Properties properties = new Properties(); + properties.setProperty("javax.persistence.jdbc.driver", "com.mysql.jdbc.Driver"); + properties.setProperty("javax.persistence.jdbc.url", "jdbc:mysql://localhost:3306/xacml"); + properties.setProperty("javax.persistence.jdbc.user", "test"); + properties.setProperty("javax.persistence.jdbc.password", "password"); + //properties.setProperty("ping_interval", "500000"); + BackUpMonitor bum = BackUpMonitor.getInstance(BackUpMonitor.ResourceNode.BRMS.toString(), null , properties, new Handler()); + assertNull(bum); + } + + @Test + public void backUpMonitorTestFailNoProperties() throws Exception{ + BackUpMonitor bum = BackUpMonitor.getInstance(BackUpMonitor.ResourceNode.BRMS.toString(), "brms_test" , null, new Handler()); + assertNull(bum); + } + + @Test + public void backUpMonitorTestFailNoHandler() throws Exception{ + Properties properties = new Properties(); + properties.setProperty("javax.persistence.jdbc.driver", "com.mysql.jdbc.Driver"); + properties.setProperty("javax.persistence.jdbc.url", "jdbc:mysql://localhost:3306/xacml"); + properties.setProperty("javax.persistence.jdbc.user", "test"); + properties.setProperty("javax.persistence.jdbc.password", "password"); + //properties.setProperty("ping_interval", "500000"); + BackUpMonitor bum = BackUpMonitor.getInstance(BackUpMonitor.ResourceNode.BRMS.toString(), "brms_test" , properties, null); + assertNull(bum); + } +} diff --git a/PyPDPServer/client.properties b/PyPDPServer/client.properties new file mode 100644 index 000000000..0b8dc258e --- /dev/null +++ b/PyPDPServer/client.properties @@ -0,0 +1,22 @@ +### +# ============LICENSE_START======================================================= +# ECOMP Policy Engine +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +python=test,MASTER +PyPDPServer=test,MASTER \ No newline at end of file diff --git a/PyPDPServer/config.properties b/PyPDPServer/config.properties new file mode 100644 index 000000000..96253ebb0 --- /dev/null +++ b/PyPDPServer/config.properties @@ -0,0 +1,49 @@ +### +# ============LICENSE_START======================================================= +# ECOMP Policy Engine +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +# PIP Engine Definition +#PDP_URL2 = http://localhost:8082/pdp/ ,testpdp,alpha456 +PDP_URL1= http://localhost:9091/pdp/ ,testpdp, alpha456 +PAP_URL = http://localhost:8070/pap/ , testpap, alpha123 +PYPDP_ID=testrest +PYPDP_PASSWORD=secUre +# DO NOT ADD THIS TO THE INSTALLTION SCRIPTS. This is for build Test purposes. +Test = true + +#Integrity Monitor values +#database driver for Integrity Monitor +javax.persistence.jdbc.driver=com.mysql.jdbc.Driver +#database URL for Integrity Monitor +javax.persistence.jdbc.url=jdbc:mysql://localhost:3306/ecomp_sdk +#database username for Integrity Monitor +javax.persistence.jdbc.user=policy_user +#database password for Integrity Monitor +javax.persistence.jdbc.password=policy_user +#resource name +RESOURCE_NAME=pypdp_pdp01 + +#The site name for the Admin +site_name=site_1 + +#Has to be one of pdp_xacml, pdp_drools, pap, pap_admin, logparser, brms_gateway, astra_gateway, elk_server, pypdp +node_type=pypdp + +ENVIRONMENT=DEVL +CLIENT_FILE=client.properties \ No newline at end of file diff --git a/PyPDPServer/policyLogger.properties b/PyPDPServer/policyLogger.properties new file mode 100644 index 000000000..0deb1b3d6 --- /dev/null +++ b/PyPDPServer/policyLogger.properties @@ -0,0 +1,44 @@ +### +# ============LICENSE_START======================================================= +# ECOMP Policy Engine +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +################################### Set concurrentHashMap and timer info ####################### +#Timer initial delay and the delay between in milliseconds before task is to be execute. +timer.delay.time=1000 +#Timer scheduleAtFixedRate period - time in milliseconds between successive task executions. +check.interval= 30000 +#Longest time an event info can be stored in the concurrentHashMap for logging - in seconds. +event.expired.time=86400 +#Size of the concurrentHashMap which stores the event starting time, etc - when its size reaches this limit, the Timer gets executed +#to remove all expired records from this concurrentHashMap. +concurrentHashMap.limit=5000 +#Size of the concurrentHashMap - when its size drops to this point, stop the Timer +stop.check.point=2500 +################################### Set logging format ############################################# +# set EELF for EELF logging format, set LOG4J for using log4j, set SYSTEMOUT for using system.out.println +logger.type=EELF +#################################### Set level for EELF or SYSTEMOUT logging ################################## +# Set level for debug file. Set DEBUG to enable .info, .warn and .debug; set INFO for enable .info and .warn; set OFF to disable all +debugLogger.level=INFO +# Set level for metrics file. Set OFF to disable; set ON to enable +metricsLogger.level=ON +# Set level for error file. Set OFF to disable; set ON to enable +error.level=ON +# Set level for audit file. Set OFF to disable; set ON to enable +audit.level=ON diff --git a/PyPDPServer/pom.xml b/PyPDPServer/pom.xml new file mode 100644 index 000000000..5875edc29 --- /dev/null +++ b/PyPDPServer/pom.xml @@ -0,0 +1,257 @@ + + + + + + 4.0.0 + org.openecomp.policy.engine + PyPDPServer + 1.0.0-SNAPSHOT + war + + PyPDP Server + + + org.springframework.boot + spring-boot-starter-parent + 1.3.3.RELEASE + + + + org.openecomp.policy.pypdp.controller.Application + 1.8 + 1.8 + + + java + jacoco + ${project.build.directory}/surefire-reports + ${project.build.directory}/coverage-reports/jacoco.exec + /opt/app/jacoco-it.exec + true + + + + + spring-releases + https://repo.spring.io/libs-release + + + + + spring-releases + https://repo.spring.io/libs-release + + + + + + org.openecomp.policy.engine + PolicyEngineAPI + ${project.version} + + + javax.websocket + javax.websocket-api + + + com.google.guava + guava + + + slf4j-log4j12 + org.slf4j + + + org.springframework + spring-mock + + + + + org.springframework.boot + spring-boot-starter-web + + + org.slf4j + log4j-over-slf4j + + + logback-classic + ch.qos.logback + + + logback-core + ch.qos.logback + + + + + javax.servlet + javax.servlet-api + 3.0.1 + provided + + + io.springfox + springfox-swagger2 + 2.4.0 + + + io.springfox + springfox-swagger-ui + 2.4.0 + + + org.springframework + spring-web + + + org.springframework.boot + spring-boot-starter-tomcat + provided + + + com.fasterxml.jackson.core + jackson-databind + + + org.glassfish + javax.json + 1.0.4 + + + org.apache.httpcomponents + httpclient + 4.2.4 + + + commons-io + commons-io + 2.4 + + + org.neo4j + neo4j-cypher-compiler-2.1 + 2.1.2 + + + javax.validation + validation-api + 1.1.0.Final + + + com.google.guava + guava + 19.0 + + + ch.qos.logback + logback-core + 1.1.1 + + + ch.qos.logback + logback-classic + 1.1.1 + + + org.springframework + spring-test + + + org.mapstruct + mapstruct + 1.0.0.Final + + + org.skyscreamer + jsonassert + 1.3.0 + + + javax.ws.rs + javax.ws.rs-api + 2.0.1 + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + repackage + + none + + + + + maven-war-plugin + + WEB-INF/lib/javax.websocket-api-1.1.jar + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.2 + + 1.8 + 1.8 + + + + org.jacoco + jacoco-maven-plugin + 0.7.1.201405082137 + + true + + org.openecomp.policy.* + + + + + jacoco-initialize-unit-tests + + prepare-agent + + + ${project.build.directory}/coverage-reports/jacoco.exec + + + + + + com.fortify.ps.maven.plugin + sca-maven-plugin + 4.20 + + + + diff --git a/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/ConfigFirewallPolicyRequest.java b/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/ConfigFirewallPolicyRequest.java new file mode 100644 index 000000000..4a11b8c9e --- /dev/null +++ b/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/ConfigFirewallPolicyRequest.java @@ -0,0 +1,128 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pypdp; + +import java.io.StringReader; +import java.util.UUID; + +import javax.json.Json; +import javax.json.JsonObject; +import javax.json.JsonReader; + +import org.openecomp.policy.api.PolicyConfigException; +import org.openecomp.policy.pypdp.model_pojo.PepConfigFirewallPolicyRequest; +import org.openecomp.policy.std.StdPolicyEngine; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +import org.openecomp.policy.common.logging.eelf.PolicyLogger; + +public class ConfigFirewallPolicyRequest { + + private StdPolicyEngine pe; + public ConfigFirewallPolicyRequest(StdPolicyEngine pe){ + this.pe= pe; + } + + public String run(PepConfigFirewallPolicyRequest pep, String requestID, String operation, String userID, String passcode) { + + String result = null; + + // construct a UUID from the request string + UUID requestUUID = null; + if (requestID != null && !requestID.isEmpty()) { + try { + requestUUID = UUID.fromString(requestID); + } + catch (IllegalArgumentException e) { + requestUUID = UUID.randomUUID(); + PolicyLogger.info("Generated Random UUID: " + requestUUID.toString()); + } + } + + if (pep.getPolicyName()!= null && !pep.getPolicyName().isEmpty()) { + if (pep.getFirewallJson() != null && !pep.getFirewallJson().isEmpty()) { + if (pep.getPolicyScope() != null && !pep.getPolicyScope().isEmpty()) { + try { + + JsonObject json = stringToJson(pep.getFirewallJson()); + + if(!json.toString().contains("errorMessage")){ + if (operation.equalsIgnoreCase("create")) { + result = pe.createConfigFirewallPolicy(pep.getPolicyName(), json, pep.getPolicyScope(), requestUUID, userID, passcode, + pep.getRiskLevel(), pep.getRiskType(), pep.getGuard(), pep.getTtlDate()); + } else { + result = pe.updateConfigFirewallPolicy(pep.getPolicyName(), json, pep.getPolicyScope(), requestUUID, userID, passcode, + pep.getRiskLevel(), pep.getRiskType(), pep.getGuard(), pep.getTtlDate()); + } + } else { + result = XACMLErrorConstants.ERROR_SCHEMA_INVALID + "BAD REQUEST: Invalid Json for firewallJson: " + pep.getFirewallJson(); + } + } catch (PolicyConfigException e) { + result = e.getMessage(); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } else { + result = XACMLErrorConstants.ERROR_DATA_ISSUE + "BAD REQUEST: policyScope was null or empty."; + } + } else { + result = XACMLErrorConstants.ERROR_DATA_ISSUE + "BAD REQUEST: firewallJson was null or empty."; + } + } else { + result = XACMLErrorConstants.ERROR_DATA_ISSUE + "BAD REQUEST: policyName was null or empty."; + } + + return result; + + } + + private JsonObject stringToJson(String jsonString) { + + JsonObject json = null; + if (jsonString != null) { + + try { + + //Read jsonBody to JsonObject + StringReader in = null; + + in = new StringReader(jsonString); + + JsonReader jsonReader = Json.createReader(in); + json = jsonReader.readObject(); + + } catch (Exception e) { + String jsonError = "{\"errorMessage\": \"" + e.getMessage() + "\"}"; + StringReader error = null; + error = new StringReader(jsonError); + JsonReader jsonReader = Json.createReader(error); + JsonObject badJson = jsonReader.readObject(); + return badJson; + } + + } + + return json; + } + +} diff --git a/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/ConfigRequest.java b/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/ConfigRequest.java new file mode 100644 index 000000000..694d010f3 --- /dev/null +++ b/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/ConfigRequest.java @@ -0,0 +1,182 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pypdp; + +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; +import java.util.UUID; + +import javax.json.JsonObject; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +import org.openecomp.policy.api.ConfigRequestParameters; +import org.openecomp.policy.api.PolicyConfig; +import org.openecomp.policy.api.PolicyConfigException; +import org.openecomp.policy.api.PolicyConfigStatus; +import org.openecomp.policy.api.PolicyType; +import org.openecomp.policy.pypdp.model_pojo.PepConfigPolicyNameRequest; +import org.openecomp.policy.pypdp.model_pojo.PyPolicyConfig; +import org.openecomp.policy.std.StdPolicyConfig; +import org.openecomp.policy.std.StdPolicyEngine; +import org.w3c.dom.Document; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +import org.openecomp.policy.common.logging.eelf.PolicyLogger; + +public class ConfigRequest { + + private StdPolicyEngine pe; + public ConfigRequest(StdPolicyEngine pe){ + this.pe= pe; + } + + public Collection run(ConfigRequestParameters pep, String requestID, String userID, String passcode) { + PolicyLogger.debug("... Request Params : \n" + + "configName " + pep.getConfigName() + "\n" + + "ecompName" + pep.getEcompName() + "\n" + + "policyName" + pep.getPolicyName() + "\n"); + StdPolicyConfig policyConfig = new StdPolicyConfig(); + Collection result = new ArrayList(); + // construct a UUID from the request string + if(pep.getRequestID()==null){ + UUID requestUUID = null; + if (requestID != null && !requestID.isEmpty()) { + try { + requestUUID = UUID.fromString(requestID); + } + catch (IllegalArgumentException e) { + requestUUID = UUID.randomUUID(); + PolicyLogger.info("Generated Random UUID: " + requestUUID.toString()); + } + } + pep.setRequestID(requestUUID); + } + try { + PolicyLogger.debug("\n\n calling PEP.. "); + Collection pConfigs = pe.configRequest(pep, userID, passcode); + for(PolicyConfig pConfig: pConfigs){ + PyPolicyConfig pyPolicyConfig = checkResponse(pConfig); + result.add(pyPolicyConfig); + } + return result; + } catch(Exception e){ + policyConfig.setConfigStatus(e.getMessage(), PolicyConfigStatus.CONFIG_NOT_FOUND); + PyPolicyConfig pyPolicyConfig = checkResponse(policyConfig); + result.add(pyPolicyConfig); + return result; + } + } + + public Collection run(PepConfigPolicyNameRequest pep, String requestID, String userID, String passcode) { + PolicyLogger.debug("... Request Params : \n" + + "policyName" + pep.getPolicyName() + "\n"); + StdPolicyConfig policyConfig = new StdPolicyConfig(); + Collection result = new ArrayList(); + // construct a UUID from the request string + UUID requestUUID = null; + if (requestID != null && !requestID.isEmpty()) { + try { + requestUUID = UUID.fromString(requestID); + } + catch (IllegalArgumentException e) { + requestUUID = UUID.randomUUID(); + PolicyLogger.info("Generated Random UUID: " + requestUUID.toString()); + } + } + if(pep.getPolicyName()!= null && !pep.getPolicyName().isEmpty()) { + try { + Collection pConfigs = pe.configPolicyName(pep.getPolicyName(), requestUUID, userID, passcode); + for(PolicyConfig pConfig: pConfigs){ + PyPolicyConfig pyPolicyConfig = checkResponse(pConfig); + result.add(pyPolicyConfig); + } + return result; + } catch (PolicyConfigException e) { + policyConfig.setConfigStatus(e.getMessage(), PolicyConfigStatus.CONFIG_NOT_FOUND); + PyPolicyConfig pyPolicyConfig = checkResponse(policyConfig); + result.add(pyPolicyConfig); + return result; + } + } + else { + policyConfig.setConfigStatus(XACMLErrorConstants.ERROR_DATA_ISSUE + "PolicyFile Name is empty", PolicyConfigStatus.CONFIG_NOT_FOUND); + PyPolicyConfig pyPolicyConfig = checkResponse(policyConfig); + result.add(pyPolicyConfig); + return result; + } + } + + public PyPolicyConfig checkResponse(PolicyConfig pConfig) { + PyPolicyConfig policyConfig = new PyPolicyConfig(); + policyConfig.setPolicyConfigMessage(pConfig.getPolicyConfigMessage()); + policyConfig.setPolicyConfigStatus(pConfig.getPolicyConfigStatus()); + policyConfig.setType(pConfig.getType()); + policyConfig.setPolicyName(pConfig.getPolicyName()); + policyConfig.setMatchingConditions(pConfig.getMatchingConditions()); + policyConfig.setResponseAttributes(pConfig.getResponseAttributes()); + policyConfig.setPolicyVersion(pConfig.getPolicyVersion()); + if (pConfig.getPolicyConfigStatus().equals(PolicyConfigStatus.CONFIG_RETRIEVED)) { + PolicyType policyType = policyConfig.getType(); + if(policyType.equals(PolicyType.PROPERTIES)) { + Properties properties = pConfig.toProperties(); + Map propVal = new HashMap(); + for(String name: properties.stringPropertyNames()) { + propVal.put(name, properties.getProperty(name)); + } + policyConfig.setProperty(propVal); + } else if(policyType.equals(PolicyType.OTHER)) { + String other = pConfig.toOther(); + policyConfig.setConfig(other); + } else if (policyType.equals(PolicyType.JSON)) { + JsonObject json = pConfig.toJSON(); + policyConfig.setConfig(json.toString()); + } else if (policyType.equals(PolicyType.XML)) { + Document document = pConfig.toXML(); + DOMSource domSource = new DOMSource(document); + StringWriter writer = new StringWriter(); + StreamResult result = new StreamResult(writer); + TransformerFactory tf = TransformerFactory.newInstance(); + Transformer transformer; + try { + transformer = tf.newTransformer(); + transformer.transform(domSource, result); + policyConfig.setConfig(writer.toString()); + } catch (TransformerException e) { + policyConfig.setConfig(null); + policyConfig.setPolicyConfigMessage(XACMLErrorConstants.ERROR_SCHEMA_INVALID + "XML error in the Configuration. " + e.getMessage()); + policyConfig.setPolicyConfigStatus(PolicyConfigStatus.CONFIG_NOT_FOUND); + } + } + } else { + policyConfig.setConfig(null); + } + return policyConfig; + } +} diff --git a/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/DeletePolicyRequest.java b/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/DeletePolicyRequest.java new file mode 100644 index 000000000..0ca5bb0d2 --- /dev/null +++ b/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/DeletePolicyRequest.java @@ -0,0 +1,80 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pypdp; + +import java.util.UUID; + +import org.openecomp.policy.api.DeletePolicyParameters; +import org.openecomp.policy.api.PolicyConfigException; +import org.openecomp.policy.std.StdPolicyEngine; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +import org.openecomp.policy.common.logging.eelf.PolicyLogger; + +public class DeletePolicyRequest { + private StdPolicyEngine pe; + public DeletePolicyRequest(StdPolicyEngine pe){ + this.pe= pe; + } + + public String run(DeletePolicyParameters pep, String requestID, String userID, String passcode) { + + String result = null; + + // construct a UUID from the request string + if(pep.getRequestID()==null){ + if (requestID != null && !requestID.isEmpty()) { + try { + pep.setRequestID(UUID.fromString(requestID)); + } + catch (IllegalArgumentException e) { + pep.setRequestID(UUID.randomUUID()); + PolicyLogger.info("Generated Random UUID: " + pep.getRequestID().toString()); + } + } + } + + if (pep.getPolicyName()!= null && !pep.getPolicyName().isEmpty()) { + if (pep.getPolicyComponent() != null && !pep.getPolicyComponent().isEmpty()) { + + try { + + result = pe.deletePolicy(pep, userID, passcode).getResponseMessage(); + + } catch (PolicyConfigException e) { + result = e.getMessage(); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } else { + result = XACMLErrorConstants.ERROR_DATA_ISSUE + "BAD REQUEST: policyComponent was null or empty."; + } + } else { + result = XACMLErrorConstants.ERROR_DATA_ISSUE + "BAD REQUEST: policyName was null or empty."; + } + + return result; + + } +} diff --git a/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/EventRequest.java b/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/EventRequest.java new file mode 100644 index 000000000..021b3d7f0 --- /dev/null +++ b/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/EventRequest.java @@ -0,0 +1,83 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pypdp; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.UUID; + +import org.openecomp.policy.api.EventRequestParameters; +import org.openecomp.policy.api.PolicyResponse; +import org.openecomp.policy.api.PolicyResponseStatus; +import org.openecomp.policy.std.StdPolicyEngine; +import org.openecomp.policy.std.StdPolicyResponse; + +import org.openecomp.policy.common.logging.eelf.PolicyLogger; + +public class EventRequest { + + private StdPolicyEngine pe; + public EventRequest(StdPolicyEngine pe){ + this.pe= pe; + } + + public Collection run(EventRequestParameters pep, String requestID, String userID, String passcode){ + StdPolicyResponse policyResponse = new StdPolicyResponse(); + Collection result = new ArrayList(); + // construct a UUID from the request string + if(pep.getRequestID()==null){ + UUID requestUUID = null; + if (requestID != null && !requestID.isEmpty()) { + try { + requestUUID = UUID.fromString(requestID); + } + catch (IllegalArgumentException e) { + requestUUID = UUID.randomUUID(); + PolicyLogger.info("Generated Random UUID: " + requestUUID.toString()); + } + } + pep.setRequestID(requestUUID); + } + try { + Collection pResponses = pe.event(pep.getEventAttributes(), pep.getRequestID(), userID, passcode); + for(PolicyResponse pResponse: pResponses){ + pResponse = checkResponse(pResponse); + result.add(pResponse); + } + return result; + } catch(Exception e){ + policyResponse.setPolicyResponseStatus(e.getMessage(), PolicyResponseStatus.NO_ACTION_REQUIRED); + policyResponse = checkResponse(policyResponse); + result.add(policyResponse); + return result; + } + } + + private StdPolicyResponse checkResponse(PolicyResponse pResponse) { + StdPolicyResponse policyResponse= new StdPolicyResponse(); + policyResponse.setActionAdvised(pResponse.getActionAdvised()); + policyResponse.setActionTaken(pResponse.getActionTaken()); + policyResponse.setPolicyResponseMessage(pResponse.getPolicyResponseMessage()); + policyResponse.setPolicyResponseStatus(pResponse.getPolicyResponseStatus()); + policyResponse.setRequestAttributes(pResponse.getRequestAttributes()); + return policyResponse; + } +} diff --git a/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/ListConfigRequest.java b/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/ListConfigRequest.java new file mode 100644 index 000000000..8aac105bf --- /dev/null +++ b/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/ListConfigRequest.java @@ -0,0 +1,69 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pypdp; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.UUID; + +import org.openecomp.policy.api.ConfigRequestParameters; +import org.openecomp.policy.api.PolicyConfigStatus; +import org.openecomp.policy.std.StdPolicyConfig; +import org.openecomp.policy.std.StdPolicyEngine; + +import org.openecomp.policy.common.logging.eelf.PolicyLogger; + +public class ListConfigRequest { + + private StdPolicyEngine pe; + public ListConfigRequest(StdPolicyEngine pe){ + this.pe= pe; + } + + public Collection run(ConfigRequestParameters pep, String requestID, String userID, String passcode) { + + StdPolicyConfig policyConfig = new StdPolicyConfig(); + Collection configList = new ArrayList(); + + // construct a UUID from the request string + UUID requestUUID = null; + if (requestID != null && !requestID.isEmpty()) { + try { + requestUUID = UUID.fromString(requestID); + } + catch (IllegalArgumentException e) { + requestUUID = UUID.randomUUID(); + PolicyLogger.info("Generated Random UUID: " + requestUUID.toString()); + } + } + pep.setRequestID(requestUUID); + try { + PolicyLogger.debug("\n\n calling PEP.. "); + configList = pe.listConfigRequest(pep, userID, passcode); + return configList; + } catch(Exception e){ + policyConfig.setConfigStatus(e.getMessage(), PolicyConfigStatus.CONFIG_NOT_FOUND); + configList.add(policyConfig.getPolicyConfigStatus().toString()); + return configList; + } + } + +} diff --git a/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/PolicyCreateUpdateRequest.java b/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/PolicyCreateUpdateRequest.java new file mode 100644 index 000000000..56151f483 --- /dev/null +++ b/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/PolicyCreateUpdateRequest.java @@ -0,0 +1,124 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pypdp; + +import java.util.UUID; + +import org.openecomp.policy.api.PolicyConfigException; +import org.openecomp.policy.api.PolicyParameters; +import org.openecomp.policy.pypdp.model_pojo.PepConfigPolicyRequest; +import org.openecomp.policy.std.StdPolicyEngine; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +import org.openecomp.policy.common.logging.eelf.PolicyLogger; + +public class PolicyCreateUpdateRequest { + private StdPolicyEngine pe; + public PolicyCreateUpdateRequest(StdPolicyEngine pe){ + this.pe= pe; + } + + public String run(PolicyParameters pep, String requestID, String operation, String userID, String passcode) { + String result = null; + if(pep.getRequestID()==null){ + if (requestID != null && !requestID.isEmpty()) { + try { + pep.setRequestID(UUID.fromString(requestID)); + } + catch (IllegalArgumentException e) { + pep.setRequestID(UUID.randomUUID()); + PolicyLogger.info("Generated Random UUID: " + pep.getRequestID().toString()); + } + } + } + // check if this is create + try{ + if (operation.equalsIgnoreCase("create")) { + result = pe.createPolicy(pep, userID, passcode ).getResponseMessage(); + }else{ + // this is Update policy. + result = pe.updatePolicy(pep, userID, passcode ).getResponseMessage(); + } + }catch(Exception e){ + result = e.getMessage(); + } + return result; + } + + public String run(PepConfigPolicyRequest pep, String requestID, String operation, String userID, String passcode) { + + String result = null; + + // construct a UUID from the request string + UUID requestUUID = null; + if (requestID != null && !requestID.isEmpty()) { + try { + requestUUID = UUID.fromString(requestID); + } + catch (IllegalArgumentException e) { + requestUUID = UUID.randomUUID(); + PolicyLogger.info("Generated Random UUID: " + requestUUID.toString()); + } + } + + if (pep.getPolicyName()!= null && !pep.getPolicyName().isEmpty()) { + if (pep.getEcompName() != null && !pep.getEcompName().isEmpty()) { + if (pep.getConfigName() != null && !pep.getConfigName().isEmpty()){ + if (pep.getPolicyScope() != null && !pep.getPolicyScope().isEmpty()) { + try { + + if (operation.equalsIgnoreCase("create")) { + + result = pe.createConfigPolicy(pep.getPolicyName(), pep.getPolicyDescription(), pep.getEcompName(), + pep.getConfigName(), pep.getConfigAttributes(), pep.getConfigType(), pep.getBody(), + pep.getPolicyScope(), requestUUID, userID, passcode, pep.getRiskLevel(), pep.getRiskType(), pep.getGuard(), pep.getTtlDate()); + } else { + result = pe.updateConfigPolicy(pep.getPolicyName(), pep.getPolicyDescription(), pep.getEcompName(), + pep.getConfigName(), pep.getConfigAttributes(), pep.getConfigType(), pep.getBody(), + pep.getPolicyScope(), requestUUID, userID, passcode, pep.getRiskLevel(), pep.getRiskType(), pep.getGuard(), pep.getTtlDate()); + } + + + } catch (PolicyConfigException e) { + result = e.getMessage(); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } else { + result = XACMLErrorConstants.ERROR_DATA_ISSUE + "BAD REQUEST: policyScope was null or empty."; + } + + } else { + result = XACMLErrorConstants.ERROR_DATA_ISSUE + "BAD REQUEST: configName was null or empty."; + } + } else { + result = XACMLErrorConstants.ERROR_DATA_ISSUE + "BAD REQUEST: ecompName was null or empty."; + } + } else { + result = XACMLErrorConstants.ERROR_DATA_ISSUE + "BAD REQUEST: policyName was null or empty."; + } + + return result; + } +} diff --git a/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/PushPolicyRequest.java b/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/PushPolicyRequest.java new file mode 100644 index 000000000..47326b326 --- /dev/null +++ b/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/PushPolicyRequest.java @@ -0,0 +1,90 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pypdp; + +import java.util.UUID; + +import org.openecomp.policy.api.PolicyConfigException; +import org.openecomp.policy.pypdp.model_pojo.PepPushPolicyRequest; +import org.openecomp.policy.std.StdPolicyEngine; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.eelf.PolicyLogger; + +public class PushPolicyRequest { + private StdPolicyEngine pe; + public PushPolicyRequest(StdPolicyEngine pe){ + this.pe= pe; + } + + public String run(PepPushPolicyRequest pep, String requestID, String userID, String passcode) { + + String result = null; + + // construct a UUID from the request string + UUID requestUUID = null; + if (requestID != null && !requestID.isEmpty()) { + try { + requestUUID = UUID.fromString(requestID); + } + catch (IllegalArgumentException e) { + requestUUID = UUID.randomUUID(); + PolicyLogger.info("Generated Random UUID: " + requestUUID.toString()); + } + }else{ + requestUUID = UUID.randomUUID(); + PolicyLogger.error("No Request UUID Given, hence generating one random ID: " + requestUUID.toString()); + } + String policyName = pep.getPolicyName(); + String policyScope = pep.getPolicyScope(); + if(policyName==null || policyName.isEmpty()){ + return XACMLErrorConstants.ERROR_DATA_ISSUE + "BAD REQUEST: policyName was null or empty."; + } + if(policyScope== null || policyScope.isEmpty()){ + try{ + policyName = pep.getPolicyName().substring(pep.getPolicyName().lastIndexOf(".")+1, pep.getPolicyName().length()); + policyScope = pep.getPolicyName().substring(0, pep.getPolicyName().lastIndexOf(".")); + } catch (Exception e){ + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "BAD REQUEST: policyScope was null or empty."); + return XACMLErrorConstants.ERROR_DATA_ISSUE + "BAD REQUEST: policyScope was null or empty."; + } + } + PolicyLogger.info("policyName: " + policyName + " policyScope is : " + policyScope); + if (pep.getPolicyType() != null && !pep.getPolicyType().isEmpty()) { + if (pep.getPdpGroup() != null && !pep.getPdpGroup().isEmpty()) { + try { + result = pe.pushPolicy(policyScope ,policyName , pep.getPolicyType(), pep.getPdpGroup(), requestUUID, userID, passcode); + } catch (PolicyConfigException e) { + result = e.getMessage(); + } catch (Exception e) { + result = e.getMessage(); + } + } else { + result = XACMLErrorConstants.ERROR_DATA_ISSUE + "BAD REQUEST: policyGroup was null or empty."; + } + } else { + result = XACMLErrorConstants.ERROR_DATA_ISSUE + "BAD REQUEST: policyType was null or empty."; + } + return result; + } +} diff --git a/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/authorization/AuthenticationFilter.java b/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/authorization/AuthenticationFilter.java new file mode 100644 index 000000000..c5526d753 --- /dev/null +++ b/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/authorization/AuthenticationFilter.java @@ -0,0 +1,80 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pypdp.authorization; + +import java.io.IOException; + +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.annotation.WebFilter; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebFilter("/*") +public class AuthenticationFilter implements Filter { + + public static final String AUTHENTICATION_HEADER = "Authorization"; + public static final String ENVIRONMENT_HEADER = "Environment"; + + @Override + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain filter) throws IOException, ServletException { + if (request instanceof HttpServletRequest) { + HttpServletRequest httpServletRequest = (HttpServletRequest) request; + String authCredentials = httpServletRequest.getHeader(AUTHENTICATION_HEADER); + String environment = httpServletRequest.getHeader(ENVIRONMENT_HEADER); + String path = ((HttpServletRequest) request).getRequestURI(); + + // better injected + AuthenticationService authenticationService = new AuthenticationService(); + + boolean authenticationStatus = authenticationService.authenticate(authCredentials); + + if (authenticationStatus && environment!=null && (environment.equalsIgnoreCase(Config.getEnvironment()))) { + filter.doFilter(request, response); + } else if(environment==null| path.contains("org.openecomp.policy.pypdp.notifications") || path.contains("swagger") || path.contains("api-docs") || path.contains("configuration") || path.contains("pdps") || path.contains("count") || path.contains("paps")){ + filter.doFilter(request, response); + } else { + if (response instanceof HttpServletResponse) { + HttpServletResponse httpServletResponse = (HttpServletResponse) response; + httpServletResponse.setStatus(HttpServletResponse.SC_UNAUTHORIZED); + } + } + if (path.contains("error")){ + HttpServletResponse httpServletResponse = (HttpServletResponse) response; + httpServletResponse.setStatus(HttpServletResponse.SC_BAD_REQUEST); + } + } + } + + @Override + public void destroy() { + } + + @Override + public void init(FilterConfig arg0) throws ServletException { + Config.setProperty(); + } +} diff --git a/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/authorization/AuthenticationService.java b/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/authorization/AuthenticationService.java new file mode 100644 index 000000000..c7deac910 --- /dev/null +++ b/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/authorization/AuthenticationService.java @@ -0,0 +1,232 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pypdp.authorization; + +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Base64; +import java.util.HashMap; +import java.util.Properties; +import java.util.StringTokenizer; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.eelf.PolicyLogger; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +public class AuthenticationService { + private String pyPDPID = Config.getPYPDPID(); + private String pyPDPPass = Config.getPYPDPPass(); + private static Path clientPath = null; + private static HashMap> clientMap = null; + private static Long oldModified = null; + private static Long newModified = null; + private static final Log logger = LogFactory.getLog(AuthenticationService.class); + + public boolean authenticate(String authCredentials) { + + if (null == authCredentials) + return false; + // header value format will be "Basic encodedstring" for Basic authentication. + final String encodedUserPassword = authCredentials.replaceFirst("Basic" + " ", ""); + String usernameAndPassword = null; + try { + byte[] decodedBytes = Base64.getDecoder().decode(encodedUserPassword); + usernameAndPassword = new String(decodedBytes, "UTF-8"); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, ""); + return false; + } + try { + final StringTokenizer tokenizer = new StringTokenizer(usernameAndPassword, ":"); + final String username = tokenizer.nextToken(); + final String password = tokenizer.nextToken(); + + boolean authenticationStatus = pyPDPID.equals(username) && pyPDPPass.equals(password); + return authenticationStatus; + } catch (Exception e){ + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, ""); + return false; + } + } + + public static boolean clientAuth(String clientCredentials) { + if(clientCredentials == null){ + return false; + } + // Decode the encoded Client Credentials. + String usernameAndPassword = null; + try { + byte[] decodedBytes = Base64.getDecoder().decode(clientCredentials); + usernameAndPassword = new String(decodedBytes, "UTF-8"); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, ""); + return false; + } + try { + final StringTokenizer tokenizer = new StringTokenizer(usernameAndPassword, ":"); + final String username = tokenizer.nextToken(); + final String password = tokenizer.nextToken(); + return checkClient(username,password); + } catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, ""); + return false; + } + } + + public static boolean checkClientScope(String clientCredentials, String scope) { + if(clientCredentials == null){ + return false; + } + // Decode the encoded Client Credentials. + String usernameAndPassword = null; + try { + byte[] decodedBytes = Base64.getDecoder().decode(clientCredentials); + usernameAndPassword = new String(decodedBytes, "UTF-8"); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, ""); + return false; + } + final StringTokenizer tokenizer = new StringTokenizer(usernameAndPassword, ":"); + final String username = tokenizer.nextToken(); + // Read the properties and compare. + try{ + readFile(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, ""); + return false; + } + // Check ID, Scope + if (clientMap.containsKey(username) && (clientMap.get(username).get(1).equals(scope) || clientMap.get(username).get(1).equals("MASTER"))) { + return true; + } + return false; + } + + private static boolean checkClient(String username, String password) { + // Read the properties and compare. + try{ + readFile(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, ""); + return false; + } + // Check ID, Key + if (clientMap.containsKey(username) && clientMap.get(username).get(0).equals(password)) { + return true; + } + return false; + } + + private static void readFile() throws Exception { + String clientFile = Config.getClientFile(); + if (clientFile == null) { + Config.setProperty(); + if(clientFile == null){ + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Missing CLIENT_FILE property value: " + clientFile); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, "Missing CLIENT_FILE property value: " + clientFile); + throw new Exception(XACMLErrorConstants.ERROR_SYSTEM_ERROR +"Missing CLIENT_FILE property value: " + clientFile); + } + } + if (clientPath == null) { + clientPath = Paths.get(clientFile); + if (Files.notExists(clientPath)) { + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "File doesn't exist in the specified Path : " + clientPath.toString()); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, "File doesn't exist in the specified Path : " + clientPath.toString()); + throw new Exception(XACMLErrorConstants.ERROR_SYSTEM_ERROR +"File doesn't exist in the specified Path : "+ clientPath.toString()); + } + if (clientPath.toString().endsWith(".properties")) { + readProps(); + } else { + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Not a .properties file " + clientFile); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, "Not a .properties file " + clientFile); + throw new Exception(XACMLErrorConstants.ERROR_SYSTEM_ERROR +"Not a .properties file " + clientFile); + } + } + // Check if File is updated recently + else { + newModified = clientPath.toFile().lastModified(); + if (newModified != oldModified) { + // File has been updated. + readProps(); + } + } + } + + private static void readProps() throws Exception{ + InputStream in; + Properties clientProp = new Properties(); + try { + in = new FileInputStream(clientPath.toFile()); + oldModified = clientPath.toFile().lastModified(); + clientProp.load(in); + } catch (IOException e) { + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, ""); + throw new Exception(XACMLErrorConstants.ERROR_SYSTEM_ERROR +"Cannot Load the Properties file", e); + + } + // Read the Properties and Load the PDPs and encoding. + clientMap = new HashMap>(); + // + for (Object propKey : clientProp.keySet()) { + String clientID = (String)propKey; + String clientValue = clientProp.getProperty(clientID); + if (clientValue != null) { + if (clientValue.contains(",")) { + ArrayList clientValues = new ArrayList(Arrays.asList(clientValue.split("\\s*,\\s*"))); + if(clientValues.get(0)!=null || clientValues.get(1)!=null || clientValues.get(0).isEmpty() || clientValues.get(1).isEmpty()){ + clientMap.put(clientID, clientValues); + } + } + } + } + if (clientMap == null || clientMap.isEmpty()) { + logger.debug(XACMLErrorConstants.ERROR_PERMISSIONS + "No Clients ID , Client Key and Scopes are available. Cannot serve any Clients !!"); + } + } +} diff --git a/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/authorization/Config.java b/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/authorization/Config.java new file mode 100644 index 000000000..388909ecf --- /dev/null +++ b/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/authorization/Config.java @@ -0,0 +1,300 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pypdp.authorization; + +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Base64; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Properties; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.eelf.PolicyLogger; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +import org.openecomp.policy.common.im.IntegrityMonitor; + + +public class Config { + private static final String propertyFilePath = "config.properties"; + private static Properties prop = new Properties(); + private static List pdps = null; + private static List paps = null; + private static List encoding = null; + private static List encodingPAP = null; + private static String pyPDPPass = null; + private static String pyPDPID = null; + private static String environment = null; + private static final Log logger = LogFactory.getLog(Config.class); + private static String clientFile = null; + private static boolean test = false; + + private static IntegrityMonitor im; + private static String resourceName = null; + + public static String getProperty(String propertyKey) { + return prop.getProperty(propertyKey); + } + + /* + * Set Property by reading the properties File. + */ + public static void setProperty() { + Path file = Paths.get(propertyFilePath); + if (Files.notExists(file)) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE+ "File doesn't exist in the specified Path "+ file.toString()); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "File doesn't exist in the specified Path "+ file.toString()); + } else { + InputStream in; + prop = new Properties(); + try { + in = new FileInputStream(file.toFile()); + prop.load(in); + } catch (IOException e) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE+"Cannot Load the Properties file" + e); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "Cannot Load the Properties file"); + } + } + // Initializing the values. + pdps = new ArrayList(); + paps = new ArrayList(); + encoding = new ArrayList(); + encodingPAP = new ArrayList(); + + // Check the Keys for PDP_URLs + Collection unsorted = prop.keySet(); + List sorted = new ArrayList(unsorted); + Collections.sort(sorted); + for (String propKey : sorted) { + if (propKey.startsWith("PDP_URL")) { + String check_val = prop.getProperty(propKey); + logger.debug("Property file value for Key : \"" + propKey + "\" Value is : \"" + check_val + "\""); + if (check_val == null) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE+"Properties file doesn't have the PDP_URL parameter"); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "Properties file doesn't have the PDP_URL parameter"); + } + if (check_val.contains(";")) { + List pdp_default = new ArrayList(Arrays.asList(check_val.split("\\s*;\\s*"))); + int pdpCount = 0; + while (pdpCount < pdp_default.size()) { + String pdpVal = pdp_default.get(pdpCount); + readPDPParam(pdpVal); + pdpCount++; + } + } else { + readPDPParam(check_val); + } + } else if (propKey.startsWith("PAP_URL")) { + String check_val = prop.getProperty(propKey); + logger.debug("Property file value for Key : \"" + propKey + "\" Value is : \"" + check_val + "\""); + if (check_val == null) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE+"Properties file doesn't have the PAP_URL parameter"); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "Properties file doesn't have the PAP_URL parameter"); + } + if (check_val.contains(";")) { + List pap_default = new ArrayList(Arrays.asList(check_val.split("\\s*;\\s*"))); + int papCount=0; + while (papCount < pap_default.size()) { + String papVal = pap_default.get(papCount); + readPAPParam(papVal); + papCount++; + } + } else { + readPAPParam(check_val); + } + } + } + if (pdps == null || pdps.isEmpty()) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE+"Cannot Proceed without PDP_URLs"); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "Cannot Proceed without PDP_URLs"); + } + + if (prop.containsKey("PYPDP_ID")) { + String id = prop.getProperty("PYPDP_ID"); + logger.debug("Property file value key: \"PYPDP_ID\" Value is : \"" + id + "\""); + if (id == null) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE+"Properties file doesn't have PYPDP_ID parameter"); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "Properties file doesn't have PYPDP_ID parameter"); + } + Config.pyPDPID = id; + } else { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE+"Properties file doesn't have PYPDP_ID parameter"); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "Properties file doesn't have PYPDP_ID parameter"); + } + if (prop.containsKey("PYPDP_PASSWORD")) { + String pass = prop.getProperty("PYPDP_PASSWORD"); + logger.debug("Property file value key: \"PYPDP_PASSWORD\" Value is : \"" + pass + "\""); + if (pass == null) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE+"Properties file doesn't have PYPDP_PASSWORD parameter"); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "Properties file doesn't have PYPDP_PASSWORD parameter"); + } + Config.pyPDPPass = pass; + } else { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE+"Properties file doesn't have PYPDP_PASSWORD parameter"); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "Properties file doesn't have PYPDP_PASSWORD parameter"); + } + environment = prop.getProperty("ENVIRONMENT", "DEVL"); + logger.info("Property value for Environment " + environment); + String value = prop.getProperty("Test"); + if(value!= null && value.equalsIgnoreCase("true")){ + test = true; + } + if(prop.containsKey("CLIENT_FILE")){ + clientFile = prop.getProperty("CLIENT_FILE"); + logger.debug("Property file value key: \"CLIENT_FILE\" Value is : \"" + clientFile + "\""); + if(clientFile == null){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE+"CLIENT_FILE value is missing."); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "CLIENT_FILE value is missing."); + } + }else{ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE+"CLIENT_FILE paramter is missing from the property file."); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "CLIENT_FILE paramter is missing from the property file."); + } + logger.info("Trying to set up IntegrityMonitor"); + try { + logger.info("Trying to set up IntegrityMonitor"); + resourceName = prop.getProperty("RESOURCE_NAME").replaceAll(" ", "");; + if(resourceName==null){ + logger.warn("RESOURCE_NAME is missing setting default value. "); + resourceName = "pypdp_pdp01"; + } + im = IntegrityMonitor.getInstance(resourceName, prop); + } catch (Exception e) { + logger.error("Error starting Integerity Monitor: " + e); + } + } + + private static void readPDPParam(String pdpVal) { + if (pdpVal.contains(",")) { + List pdpValues = new ArrayList(Arrays.asList(pdpVal.split("\\s*,\\s*"))); + if (pdpValues.size() == 3) { + // 0 - PDPURL + pdps.add(pdpValues.get(0)); + // 1:2 will be UserID:Password + String userID = pdpValues.get(1); + String pass = pdpValues.get(2); + Base64.Encoder encoder = Base64.getEncoder(); + encoding.add(encoder.encodeToString((userID + ":" + pass) + .getBytes(StandardCharsets.UTF_8))); + } else { + logger.error(XACMLErrorConstants.ERROR_PERMISSIONS+"No enough Credentials to send Request. "+ pdpValues); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "No enough Credentials to send Request. "+ pdpValues); + } + } else { + logger.error(XACMLErrorConstants.ERROR_PERMISSIONS+"No enough Credentials to send Request."); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "No enough Credentials to send Request."); + } + } + + private static void readPAPParam(String papVal) { + if (papVal.contains(",")) { + List papValues = new ArrayList(Arrays.asList(papVal.split("\\s*,\\s*"))); + if (papValues.size() == 3) { + // 0 - PAPURL + paps.add(papValues.get(0)); + // 1:2 will be UserID:Password + String userID = papValues.get(1); + String pass = papValues.get(2); + Base64.Encoder encoder = Base64.getEncoder(); + encodingPAP.add(encoder.encodeToString((userID + ":" + pass) + .getBytes(StandardCharsets.UTF_8))); + } else { + logger.error(XACMLErrorConstants.ERROR_PERMISSIONS+"Not enough Credentials to send Request. "+ papValues); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.error(MessageCodes.ERROR_PERMISSIONS, "Not enough Credentials to send Request. "+ papValues); + } + } else { + logger.error(XACMLErrorConstants.ERROR_PERMISSIONS+"Not enough Credentials to send Request."); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.error(MessageCodes.ERROR_PERMISSIONS, "Not enough Credentials to send Request."); + } + } + + public static List getPDPs() { + setProperty(); + return Config.pdps; + } + + public static List getPAPs() { + setProperty(); + return Config.paps; + } + + public static List getEncoding() { + return Config.encoding; + } + + public static List getEncodingPAP() { + return Config.encodingPAP; + } + + public static String getPYPDPID() { + return Config.pyPDPID; + } + + public static String getPYPDPPass() { + return Config.pyPDPPass; + } + + public static String getEnvironment(){ + return Config.environment; + } + + public static IntegrityMonitor getIntegrityMonitor(){ + if(im==null){ + setProperty(); + } + return im; + } + + public static String getClientFile() { + return Config.clientFile; + } + + public static Boolean isTest() { + return Config.test; + } +} diff --git a/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/controller/Application.java b/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/controller/Application.java new file mode 100644 index 000000000..a98e1109d --- /dev/null +++ b/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/controller/Application.java @@ -0,0 +1,80 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pypdp.controller; + +import javax.servlet.Filter; + +import org.openecomp.policy.pypdp.authorization.AuthenticationFilter; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.context.web.SpringBootServletInitializer; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; + +import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.service.ApiInfo; +import springfox.documentation.service.Contact; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2; + +@SpringBootApplication +@EnableSwagger2 +@ComponentScan(basePackageClasses = {PolicyEngineServices.class}) +public class Application extends SpringBootServletInitializer { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { + return application.sources(applicationClass); + } + + private static Class applicationClass = Application.class; + + @Bean + public Filter authenticationFilter(){ + return new AuthenticationFilter(); + } + + private ApiInfo apiInfo(){ + return new ApiInfoBuilder() + .title("Policy Engine REST API") + .description("This API helps applications across Domain 2.0 Platform to make queries against Policy Engine") + .version("2.0") + .build(); + } + + @Bean + public Docket policyAPI(){ + return new Docket(DocumentationType.SWAGGER_2) + .apiInfo(apiInfo()) + .select() + .apis(RequestHandlerSelectors.basePackage("org.openecomp.policy.pypdp.controller")) + .build() + .pathMapping("/") + ; + } +} diff --git a/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/controller/PolicyEngineServices.java b/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/controller/PolicyEngineServices.java new file mode 100644 index 000000000..12a5f25f5 --- /dev/null +++ b/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/controller/PolicyEngineServices.java @@ -0,0 +1,556 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pypdp.controller; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; + +import java.util.Base64; +import java.util.Collection; +import java.util.List; +import java.util.StringTokenizer; +import java.util.concurrent.atomic.AtomicLong; + +import org.openecomp.policy.api.ConfigRequestParameters; +import org.openecomp.policy.api.DeletePolicyParameters; +import org.openecomp.policy.api.EventRequestParameters; +import org.openecomp.policy.api.NotificationScheme; +import org.openecomp.policy.api.PolicyParameters; +import org.openecomp.policy.api.PolicyResponse; +import org.openecomp.policy.pypdp.ConfigFirewallPolicyRequest; +import org.openecomp.policy.pypdp.ConfigRequest; +import org.openecomp.policy.pypdp.DeletePolicyRequest; +import org.openecomp.policy.pypdp.EventRequest; +import org.openecomp.policy.pypdp.ListConfigRequest; +import org.openecomp.policy.pypdp.PolicyCreateUpdateRequest; +import org.openecomp.policy.pypdp.PushPolicyRequest; +import org.openecomp.policy.pypdp.authorization.AuthenticationService; +import org.openecomp.policy.pypdp.authorization.Config; +import org.openecomp.policy.pypdp.jmx.PyPdpMonitor; +import org.openecomp.policy.pypdp.model_pojo.PepConfigFirewallPolicyRequest; +import org.openecomp.policy.pypdp.model_pojo.PepConfigPolicyNameRequest; +import org.openecomp.policy.pypdp.model_pojo.PepConfigPolicyRequest; +import org.openecomp.policy.pypdp.model_pojo.PepPushPolicyRequest; +import org.openecomp.policy.pypdp.model_pojo.PyPolicyConfig; +import org.openecomp.policy.pypdp.notifications.NotificationController; +import org.openecomp.policy.std.StdPolicyEngine; +import org.openecomp.policy.utils.PolicyUtils; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +import springfox.documentation.annotations.ApiIgnore; + +import org.openecomp.policy.common.logging.eelf.PolicyLogger; +import org.openecomp.policy.common.im.AdministrativeStateException; +import org.openecomp.policy.common.im.StandbyStatusException; + +@RestController +@Api(value="Policy Engine Services") +public class PolicyEngineServices { + private final NotificationScheme scheme = NotificationScheme.AUTO_ALL_NOTIFICATIONS; + private final NotificationController handler = new NotificationController(); + private final AtomicLong configCounter = PyPdpMonitor.singleton.getAtomicConfigCounter(); + private final AtomicLong eventCounter = PyPdpMonitor.singleton.getAtomicEventCounter(); + private final AtomicLong configPolicyNameCounter = PyPdpMonitor.singleton.getAtomicConfigPolicyNameCounter(); + private final StdPolicyEngine policyEngine = new StdPolicyEngine(Config.getPDPs(), Config.getPAPs(), Config.getEncodingPAP(), Config.getEncoding(), scheme, handler, Config.getEnvironment(), Config.getClientFile(), Config.isTest()); + + @ApiImplicitParams({ + @ApiImplicitParam(name ="Authorization", required = true, paramType = "Header"), + @ApiImplicitParam(name ="Environment", required = true, paramType = "Header") + }) + @ApiOperation(value= "Gets the configuration from the PolicyDecisionPoint(PDP)") + @RequestMapping(value = "/getConfig", method = RequestMethod.POST) + public @ResponseBody ResponseEntity> createConfigRequest(@RequestBody ConfigRequestParameters pep,@RequestHeader(value="ClientAuth", required=true)String clientEncoding, @RequestHeader(value="X-ECOMP-RequestID", required=false)String requestID) { + Collection policyConfig = null; + String[] userNamePass = null; + try { + userNamePass = decodeEncoding(clientEncoding, "CONFIG"); + } catch (Exception e1) { + return new ResponseEntity>(policyConfig, HttpStatus.UNAUTHORIZED); + } + ConfigRequest configRequest = new ConfigRequest(policyEngine); + try{ + Config.getIntegrityMonitor().startTransaction(); + } catch (AdministrativeStateException e) { + PolicyLogger.error("Error while starting Transaction " + e); + } catch (Exception e) { + PolicyLogger.error("Error while starting Transaction " + e); + } + policyConfig = configRequest.run(pep, requestID, userNamePass[0], userNamePass[1]); + configCounter.incrementAndGet(); + Config.getIntegrityMonitor().endTransaction(); + for(PyPolicyConfig pythonConfig: policyConfig){ + if(pythonConfig.getPolicyConfigMessage()!=null && pythonConfig.getPolicyConfigMessage().contains("PE300")){ + return new ResponseEntity>(policyConfig, HttpStatus.BAD_REQUEST); + } + } + return new ResponseEntity>(policyConfig, HttpStatus.OK); + } + + @ApiImplicitParams({ + @ApiImplicitParam(name ="Authorization", required = true, paramType = "Header"), + @ApiImplicitParam(name ="Environment", required = true, paramType = "Header") + }) + @ApiOperation(value= "Gets the configuration from the PDP") + @RequestMapping(value = "/listConfig", method = RequestMethod.POST) + public @ResponseBody ResponseEntity> createListConfigRequest(@RequestBody ConfigRequestParameters pep,@RequestHeader(value="ClientAuth", required=true)String clientEncoding, @RequestHeader(value="X-ECOMP-RequestID", required=false)String requestID) { + Collection policyList = null; + String[] userNamePass = null; + try { + userNamePass = decodeEncoding(clientEncoding, "CONFIG"); + } catch (Exception e1) { + return new ResponseEntity>(policyList, HttpStatus.UNAUTHORIZED); + } + ListConfigRequest listConfigRequest = new ListConfigRequest(policyEngine); + try{ + Config.getIntegrityMonitor().startTransaction(); + } catch (AdministrativeStateException e) { + PolicyLogger.error("Error while starting Transaction " + e); + } catch (StandbyStatusException e) { + PolicyLogger.error("Error while starting Transaction " + e); + } + policyList = listConfigRequest.run(pep, requestID, userNamePass[0], userNamePass[1]); + + configCounter.incrementAndGet(); + Config.getIntegrityMonitor().endTransaction(); + + for(String response : policyList){ + if(response!=null && response.contains("PE300")){ + return new ResponseEntity>(policyList, HttpStatus.BAD_REQUEST); + } + } + return new ResponseEntity>(policyList, HttpStatus.OK); + } + + @ApiImplicitParams({ + @ApiImplicitParam(name ="Authorization", required = true, paramType = "Header"), + @ApiImplicitParam(name ="Environment", required = true, paramType = "Header") + }) + @ApiOperation(value= "Sends the Events specified to the Policy Engine") + @RequestMapping(value = "/sendEvent", method = RequestMethod.POST) + public @ResponseBody ResponseEntity> createEventParameterRequest(@RequestBody EventRequestParameters pep,@RequestHeader(value="ClientAuth", required=true)String clientEncoding, @RequestHeader(value="X-ECOMP-RequestID", required=false) String requestID) { + Collection policyResponse = null; + String[] userNamePass = null; + try { + userNamePass = decodeEncoding(clientEncoding, "ACTION"); + } catch (Exception e1) { + return new ResponseEntity>(policyResponse, HttpStatus.UNAUTHORIZED); + } + EventRequest eventRequest = new EventRequest(policyEngine); + try{ + Config.getIntegrityMonitor().startTransaction(); + } catch (AdministrativeStateException e) { + PolicyLogger.error("Error while starting Transaction " + e); + } catch (Exception e) { + PolicyLogger.error("Error while starting Transaction " + e); + } + policyResponse = eventRequest.run(pep, requestID, userNamePass[0], userNamePass[1]); + eventCounter.incrementAndGet(); + Config.getIntegrityMonitor().endTransaction(); + for(PolicyResponse response: policyResponse ){ + if(response.getPolicyResponseMessage()!=null && response.getPolicyResponseMessage().contains("PE300")){ + return new ResponseEntity>(policyResponse,HttpStatus.BAD_REQUEST); + } + } + return new ResponseEntity>(policyResponse,HttpStatus.OK); + } + + @ApiImplicitParams({ + @ApiImplicitParam(name ="Authorization", required = true, paramType = "Header"), + @ApiImplicitParam(name ="Environment", required = true, paramType = "Header") + }) + @ApiOperation(value= "Gets the configuration from the PolicyDecisionPoint(PDP)") + @RequestMapping(value = "/getConfigByPolicyName", method = RequestMethod.POST) + @Deprecated + public @ResponseBody ResponseEntity> createConfigRequest(@RequestBody PepConfigPolicyNameRequest pep,@RequestHeader(value="ClientAuth", required=true)String clientEncoding, @RequestHeader(value="X-ECOMP-RequestID", required=false) String requestID) { + Collection policyConfig = null; + String[] userNamePass = null; + try { + userNamePass = decodeEncoding(clientEncoding, "CONFIG"); + } catch (Exception e1) { + return new ResponseEntity>(policyConfig, HttpStatus.UNAUTHORIZED); + } + ConfigRequest configRequest = new ConfigRequest(policyEngine); + try{ + Config.getIntegrityMonitor().startTransaction(); + } catch (AdministrativeStateException e) { + PolicyLogger.error("Error while starting Transaction " + e); + } catch (Exception e) { + PolicyLogger.error("Error while starting Transaction " + e); + } + policyConfig = configRequest.run(pep, requestID, userNamePass[0], userNamePass[1]); + configPolicyNameCounter.incrementAndGet(); + Config.getIntegrityMonitor().endTransaction(); + return new ResponseEntity>(policyConfig, HttpStatus.OK); + } + + @ApiImplicitParams({ + @ApiImplicitParam(name ="Authorization", required = true, paramType = "Header"), + @ApiImplicitParam(name ="Environment", required = true, paramType = "Header") + }) + @ApiOperation(value="Pushes the specified policy to the PDP Group.") + @RequestMapping(value = "/pushPolicy", method = RequestMethod.PUT) + public @ResponseBody ResponseEntity pushPolicyRequest(@RequestBody PepPushPolicyRequest pep,@RequestHeader(value="ClientAuth", required=true)String clientEncoding, + @RequestHeader(value="X-ECOMP-RequestID", required=false) String requestID) { + String response = null; + String[] userNamePass = null; + try { + userNamePass = decodeEncoding(clientEncoding, "CREATEPOLICY"); + } catch (Exception e1) { + return new ResponseEntity(response, HttpStatus.UNAUTHORIZED); + } + PushPolicyRequest pushPolicy = new PushPolicyRequest(policyEngine); + try{ + Config.getIntegrityMonitor().startTransaction(); + } catch (AdministrativeStateException e) { + PolicyLogger.error("Error while starting Transaction " + e); + } catch (Exception e) { + PolicyLogger.error("Error while starting Transaction " + e); + } + response = pushPolicy.run(pep, requestID, userNamePass[0], userNamePass[1]); + + Config.getIntegrityMonitor().endTransaction(); + if (response.contains("BAD REQUEST")||response.contains("PE300")) { + return new ResponseEntity(response, HttpStatus.BAD_REQUEST); + } else { + return new ResponseEntity(response, HttpStatus.OK); + } + } + + @ApiImplicitParams({ + @ApiImplicitParam(name ="Authorization", required = true, paramType = "Header"), + @ApiImplicitParam(name ="Environment", required = true, paramType = "Header") + }) + @ApiOperation(value="Deletes the specified policy from the PDP Group or PAP.") + @RequestMapping(value = "/deletePolicy", method = RequestMethod.DELETE) + public @ResponseBody ResponseEntity deletePolicyRequest(@RequestBody DeletePolicyParameters pep,@RequestHeader(value="ClientAuth", required=true)String clientEncoding, + @RequestHeader(value="X-ECOMP-RequestID", required=false) String requestID) { + String response = null; + String[] userNamePass = null; + try { + userNamePass = decodeEncoding(clientEncoding, "DELETEPOLICY"); + } catch (Exception e1) { + return new ResponseEntity(response, HttpStatus.UNAUTHORIZED); + } + DeletePolicyRequest deletePolicy = new DeletePolicyRequest(policyEngine); + try{ + Config.getIntegrityMonitor().startTransaction(); + } catch (AdministrativeStateException e) { + PolicyLogger.error("Error while starting Transaction " + e); + } catch (Exception e) { + PolicyLogger.error("Error while starting Transaction " + e); + } + response = deletePolicy.run(pep, requestID, userNamePass[0], userNamePass[1]); + + Config.getIntegrityMonitor().endTransaction(); + if (response.contains("BAD REQUEST")||response.contains("PE300")||response.contains("not exist")||response.contains("Invalid policyName")) { + return new ResponseEntity(response, HttpStatus.BAD_REQUEST); + } else if (response.contains("locked down")){ + return new ResponseEntity(response, HttpStatus.ACCEPTED); + } else if (response.contains("not Authorized")) { + return new ResponseEntity(response, HttpStatus.FORBIDDEN); + } else if (response.contains("groupId")) { + return new ResponseEntity(response, HttpStatus.NOT_FOUND); + } else if (response.contains("JPAUtils")||response.contains("database")||response.contains("policy file")|| + response.contains("unknown")||response.contains("configuration")) { + return new ResponseEntity(response, HttpStatus.INTERNAL_SERVER_ERROR); + } else { + return new ResponseEntity(response, HttpStatus.OK); + } + } + + @ApiImplicitParams({ + @ApiImplicitParam(name ="Authorization", required = true, paramType = "Header"), + @ApiImplicitParam(name ="Environment", required = true, paramType = "Header") + }) + @ApiOperation(value= "Creates a Policy based on given Policy Parameters.") + @RequestMapping(value = "/createPolicy", method = RequestMethod.PUT) + public @ResponseBody ResponseEntity createRequest(@RequestBody PolicyParameters pep,@RequestHeader(value="ClientAuth", required=true)String clientEncoding, + @RequestHeader(value="X-ECOMP-RequestID", required=false)String requestID) { + String response = null; + String[] userNamePass = null; + try { + userNamePass = decodeEncoding(clientEncoding, "CREATEPOLICY"); + } catch (Exception e1) { + return new ResponseEntity(response, HttpStatus.UNAUTHORIZED); + } + PolicyCreateUpdateRequest policyCreateUpdateRequest = new PolicyCreateUpdateRequest(policyEngine); + try{ + Config.getIntegrityMonitor().startTransaction(); + } catch (AdministrativeStateException e) { + PolicyLogger.error("Error while starting Transaction " + e); + } catch (Exception e) { + PolicyLogger.error("Error while starting Transaction " + e); + } + response = policyCreateUpdateRequest.run(pep, requestID, "create", userNamePass[0], userNamePass[1]); + + Config.getIntegrityMonitor().endTransaction(); + if(response== null || response.contains("BAD REQUEST")||response.contains("PE300")){ + return new ResponseEntity(response, HttpStatus.BAD_REQUEST); + } + else if (response.contains("Policy Exist Error")) { + return new ResponseEntity(response, HttpStatus.CONFLICT); + } else if (response.contains("PE200")){ + return new ResponseEntity(response, HttpStatus.INTERNAL_SERVER_ERROR); + } else { + return new ResponseEntity(response, HttpStatus.OK); + } + + } + + @ApiImplicitParams({ + @ApiImplicitParam(name ="Authorization", required = true, paramType = "Header"), + @ApiImplicitParam(name ="Environment", required = true, paramType = "Header") + }) + @ApiOperation(value= "Updates a Policy based on given Policy Parameters.") + @RequestMapping(value = "/updatePolicy", method = RequestMethod.PUT) + public @ResponseBody ResponseEntity updateRequest(@RequestBody PolicyParameters pep,@RequestHeader(value="ClientAuth", required=true)String clientEncoding, + @RequestHeader(value="X-ECOMP-RequestID", required=false) String requestID) { + String response = null; + String[] userNamePass = null; + try { + userNamePass = decodeEncoding(clientEncoding, "CREATEPOLICY"); + } catch (Exception e1) { + return new ResponseEntity(response, HttpStatus.UNAUTHORIZED); + } + PolicyCreateUpdateRequest policyCreateUpdateRequest = new PolicyCreateUpdateRequest(policyEngine); + try{ + Config.getIntegrityMonitor().startTransaction(); + } catch (AdministrativeStateException e) { + PolicyLogger.error("Error while starting Transaction " + e); + } catch (Exception e) { + PolicyLogger.error("Error while starting Transaction " + e); + } + response = policyCreateUpdateRequest.run(pep, requestID, "update", userNamePass[0], userNamePass[1]); + + Config.getIntegrityMonitor().endTransaction(); + if (response==null|| response.contains("BAD REQUEST")||response.contains("PE300")){ + return new ResponseEntity(response, HttpStatus.BAD_REQUEST); + } else if (response.contains("PE200")){ + return new ResponseEntity(response, HttpStatus.INTERNAL_SERVER_ERROR); + } else { + return new ResponseEntity(response, HttpStatus.OK); + } + + } + + @ApiImplicitParams({ + @ApiImplicitParam(name ="Authorization", required = true, paramType = "Header"), + @ApiImplicitParam(name ="Environment", required = true, paramType = "Header") + }) + @ApiOperation(value= "Creates a Config Policy based on given Policy Parameters.") + @RequestMapping(value = "/createConfig", method = RequestMethod.PUT) + @Deprecated + public @ResponseBody ResponseEntity createConfigRequest(@RequestBody PepConfigPolicyRequest pep, @RequestHeader(value="ClientAuth", required=true)String clientEncoding, + @RequestHeader(value="X-ECOMP-RequestID", required=false) String requestID) { + String response = null; + String[] userNamePass = null; + try { + userNamePass = decodeEncoding(clientEncoding, "CREATEPOLICY"); + } catch (Exception e1) { + return new ResponseEntity(response, HttpStatus.UNAUTHORIZED); + } + PolicyCreateUpdateRequest policyCreateUpdateRequest = new PolicyCreateUpdateRequest(policyEngine); + try{ + Config.getIntegrityMonitor().startTransaction(); + } catch (AdministrativeStateException e) { + PolicyLogger.error("Error while starting Transaction " + e); + } catch (Exception e) { + PolicyLogger.error("Error while starting Transaction " + e); + } + response = policyCreateUpdateRequest.run(pep, requestID, "create", userNamePass[0], userNamePass[1]); + + Config.getIntegrityMonitor().endTransaction(); + if (response!=null && !response.contains("BAD REQUEST")) { + return new ResponseEntity(response, HttpStatus.OK); + } else { + return new ResponseEntity(response, HttpStatus.BAD_REQUEST); + } + + } + + @ApiImplicitParams({ + @ApiImplicitParam(name ="Authorization", required = true, paramType = "Header"), + @ApiImplicitParam(name ="Environment", required = true, paramType = "Header") + }) + @ApiOperation(value= "Updates a Config Policy based on given Policy Parameters.") + @RequestMapping(value = "/updateConfig", method = RequestMethod.PUT) + @Deprecated + public @ResponseBody ResponseEntity updateConfigRequest(@RequestBody PepConfigPolicyRequest pep, @RequestHeader(value="ClientAuth", required=true)String clientEncoding, + @RequestHeader(value="X-ECOMP-RequestID", required=false) String requestID) { + String response = null; + String[] userNamePass = null; + try { + userNamePass = decodeEncoding(clientEncoding, "CREATEPOLICY"); + } catch (Exception e1) { + return new ResponseEntity(response, HttpStatus.UNAUTHORIZED); + } + PolicyCreateUpdateRequest policyCreateUpdateRequest = new PolicyCreateUpdateRequest(policyEngine); + try{ + Config.getIntegrityMonitor().startTransaction(); + } catch (AdministrativeStateException e) { + PolicyLogger.error("Error while starting Transaction " + e); + } catch (Exception e) { + PolicyLogger.error("Error while starting Transaction " + e); + } + response = policyCreateUpdateRequest.run(pep, requestID, "update", userNamePass[0], userNamePass[1]); + + Config.getIntegrityMonitor().endTransaction(); + if (response!=null && !response.contains("BAD REQUEST")) { + return new ResponseEntity(response, HttpStatus.OK); + } else { + return new ResponseEntity(response, HttpStatus.BAD_REQUEST); + } + + } + + @ApiImplicitParams({ + @ApiImplicitParam(name ="Authorization", required = true, paramType = "Header"), + @ApiImplicitParam(name ="Environment", required = true, paramType = "Header") + }) + @ApiOperation(value = "Creates a Config Firewall Policy") + @RequestMapping(value = "/createFirewallConfig", method = RequestMethod.PUT) + @Deprecated + public @ResponseBody ResponseEntity createFirewallConfigRequest(@RequestBody PepConfigFirewallPolicyRequest pep, @RequestHeader(value="ClientAuth", required=true)String clientEncoding, + @RequestHeader(value="X-ECOMP-RequestID", required=false) String requestID) { + String response = null; + String[] userNamePass = null; + try { + userNamePass = decodeEncoding(clientEncoding, "CREATEPOLICY"); + } catch (Exception e1) { + return new ResponseEntity(response, HttpStatus.UNAUTHORIZED); + } + ConfigFirewallPolicyRequest firewallPolicyRequest = new ConfigFirewallPolicyRequest(policyEngine); + try{ + Config.getIntegrityMonitor().startTransaction(); + } catch (AdministrativeStateException e) { + PolicyLogger.error("Error while starting Transaction " + e); + } catch (Exception e) { + PolicyLogger.error("Error while starting Transaction " + e); + } + response = firewallPolicyRequest.run(pep, requestID, "create", userNamePass[0], userNamePass[1]); + + Config.getIntegrityMonitor().endTransaction(); + if (response!=null && !response.contains("BAD REQUEST")) { + return new ResponseEntity(response, HttpStatus.OK); + } else { + return new ResponseEntity(response, HttpStatus.BAD_REQUEST); + } + + } + + @ApiImplicitParams({ + @ApiImplicitParam(name ="Authorization", required = true, paramType = "Header"), + @ApiImplicitParam(name ="Environment", required = true, paramType = "Header") + }) + @ApiOperation(value = "Updates a Config Firewall Policy") + @RequestMapping(value = "/updateFirewallConfig", method = RequestMethod.PUT) + @Deprecated + public @ResponseBody ResponseEntity updateFirewallConfigRequest(@RequestBody PepConfigFirewallPolicyRequest pep, @RequestHeader(value="ClientAuth", required=true)String clientEncoding, + @RequestHeader(value="X-ECOMP-RequestID", required=false) String requestID) { + String response = null; + String[] userNamePass = null; + try { + userNamePass = decodeEncoding(clientEncoding, "CREATEPOLICY"); + } catch (Exception e1) { + return new ResponseEntity(response, HttpStatus.UNAUTHORIZED); + } + ConfigFirewallPolicyRequest firewallPolicyRequest = new ConfigFirewallPolicyRequest(policyEngine); + try{ + Config.getIntegrityMonitor().startTransaction(); + } catch (AdministrativeStateException e) { + PolicyLogger.error("Error while starting Transaction " + e); + } catch (Exception e) { + PolicyLogger.error("Error while starting Transaction " + e); + } + response = firewallPolicyRequest.run(pep, requestID, "update", userNamePass[0], userNamePass[1]); + + Config.getIntegrityMonitor().endTransaction(); + if (response!=null && !response.contains("BAD REQUEST")) { + return new ResponseEntity(response, HttpStatus.OK); + } else { + return new ResponseEntity(response, HttpStatus.BAD_REQUEST); + } + + } + + @ApiImplicitParams({ + @ApiImplicitParam(name ="Authorization", required = true, paramType = "Header") + }) + @ApiOperation(value= "Gets the API Services usage Information") + @ApiIgnore + @RequestMapping(value = "/count", method = RequestMethod.GET) + public String getCount() { + return "Total Config Calls : " + configCounter + "\n" + +"Total Config calls made using Policy File Name: " + configPolicyNameCounter + "\n" + + "Total Event Calls : " + eventCounter; + } + + @ApiImplicitParams({ + @ApiImplicitParam(name ="Authorization", required = true, paramType = "Header") + }) + @ApiOperation(value = "Gets the PDPs that are listed to provide service.") + @RequestMapping(value = "/pdps", method = RequestMethod.GET) + public List listPDPs() { + return Config.getPDPs(); + } + + @ApiImplicitParams({ + @ApiImplicitParam(name ="Authorization", required = true, paramType = "Header") + }) + @ApiOperation(value = "Gets the PAPs that are listed to provide service.") + @RequestMapping(value = "/paps", method = RequestMethod.GET) + public List listPAPs() { + return Config.getPAPs(); + } + + /* + * Internal Decoding System. to support old and new Calls. + */ + private String[] decodeEncoding(String clientEncoding, String scope) throws Exception{ + String[] userNamePass = PolicyUtils.decodeBasicEncoding(clientEncoding); + if(userNamePass==null){ + if(AuthenticationService.clientAuth(clientEncoding)){ + if(AuthenticationService.checkClientScope(clientEncoding, scope)){ + String usernameAndPassword = null; + byte[] decodedBytes = Base64.getDecoder().decode(clientEncoding); + usernameAndPassword = new String(decodedBytes, "UTF-8"); + StringTokenizer tokenizer = new StringTokenizer(usernameAndPassword, ":"); + String username = tokenizer.nextToken(); + String password = tokenizer.nextToken(); + userNamePass= new String[]{username, password}; + } + } + } + if(userNamePass==null){ + throw new Exception("Client is Not authrorized to make this call. Please contact PyPDP Admin."); + } + return userNamePass; + } +} \ No newline at end of file diff --git a/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/jmx/PyPdpMBeanListener.java b/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/jmx/PyPdpMBeanListener.java new file mode 100644 index 000000000..cd1c95d53 --- /dev/null +++ b/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/jmx/PyPdpMBeanListener.java @@ -0,0 +1,75 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pypdp.jmx; + +import java.lang.management.ManagementFactory; + +import javax.management.MBeanServer; +import javax.management.ObjectName; +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; +import javax.servlet.annotation.WebListener; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +@WebListener +public class PyPdpMBeanListener implements ServletContextListener { + private static final String JMX_OBJECT_NAME = "PyPdp:type=PyPdpMonitor"; +// private static final Log logger = LogFactory.getLog(PyPdpMBeanListener.class); + private static final Logger logger = FlexLogger.getLogger(PyPdpMBeanListener.class); + + private ObjectName objectName; + + @Override + public void contextInitialized(ServletContextEvent contextEvent) { + if (logger.isInfoEnabled()) + logger.info("Registering."); + + final MBeanServer server = ManagementFactory.getPlatformMBeanServer(); + try { + objectName = new ObjectName(JMX_OBJECT_NAME); + server.registerMBean(PyPdpMonitor.singleton, objectName); + logger.info("MBean registered: " + objectName); + } catch (Exception e) { + logger.warn(e.getMessage(), e); + } + } + + @Override + public void contextDestroyed(ServletContextEvent arg0) { + if (logger.isInfoEnabled()) + logger.info("Unregistering"); + final MBeanServer server = ManagementFactory.getPlatformMBeanServer(); + try { + objectName = new ObjectName(JMX_OBJECT_NAME); + server.unregisterMBean(objectName); + if (logger.isInfoEnabled()) + logger.info("MBean unregistered: " + objectName); + } catch (Exception e) { + logger.warn(e.getMessage(), e); + } + } + +} diff --git a/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/jmx/PyPdpMonitor.java b/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/jmx/PyPdpMonitor.java new file mode 100644 index 000000000..849d8ae3f --- /dev/null +++ b/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/jmx/PyPdpMonitor.java @@ -0,0 +1,90 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pypdp.jmx; + +import java.util.concurrent.atomic.AtomicLong; + +public class PyPdpMonitor implements PyPdpMonitorMBean { + + public static PyPdpMonitor singleton = new PyPdpMonitor(); + + private final AtomicLong configCounter; + private final AtomicLong eventCounter; + private final AtomicLong configPolicyNameCounter; + + private PyPdpMonitor() { + this.configCounter = new AtomicLong(); + this.eventCounter = new AtomicLong(); + this.configPolicyNameCounter = new AtomicLong(); + } + + /** + * @return the configCounter + */ + public AtomicLong getAtomicConfigCounter() { + return configCounter; + } + + /** + * @return the eventCounter + */ + public AtomicLong getAtomicEventCounter() { + return eventCounter; + } + + /** + * @return the configPolicyNameCounter + */ + public AtomicLong getAtomicConfigPolicyNameCounter() { + return configPolicyNameCounter; + } + /** + * @return the configCounter + */ + @Override + public long getConfigCounter() { + return configCounter.longValue(); + } + + /** + * @return the eventCounter + */ + @Override + public long getEventCounter() { + return eventCounter.longValue(); + } + + /** + * @return the configPolicyNameCounter + */ + @Override + public long getConfigPolicyNameCounter() { + return configPolicyNameCounter.longValue(); + } + + @Override + public synchronized void resetCounters() { + this.configCounter.set(0); + this.eventCounter.set(0); + this.configPolicyNameCounter.set(0); + } + +} diff --git a/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/jmx/PyPdpMonitorMBean.java b/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/jmx/PyPdpMonitorMBean.java new file mode 100644 index 000000000..b111bb6f1 --- /dev/null +++ b/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/jmx/PyPdpMonitorMBean.java @@ -0,0 +1,28 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pypdp.jmx; + +public interface PyPdpMonitorMBean { + public long getConfigCounter(); + public long getEventCounter(); + public long getConfigPolicyNameCounter(); + public void resetCounters(); +} diff --git a/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/model_pojo/PepConfigFirewallPolicyRequest.java b/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/model_pojo/PepConfigFirewallPolicyRequest.java new file mode 100644 index 000000000..1e76854c5 --- /dev/null +++ b/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/model_pojo/PepConfigFirewallPolicyRequest.java @@ -0,0 +1,82 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pypdp.model_pojo; + +import java.io.Serializable; +import java.util.Map; + +import javax.json.JsonObject; + +public class PepConfigFirewallPolicyRequest implements Serializable { + + private static final long serialVersionUID = 1L; + + private String policyName = null; + private String policyScope = null; + private String firewallJson = null; + private String riskType = "defualt"; + private String riskLevel = "5"; + private String guard = "false"; + private String ttlDate = null; + + public String getPolicyName() { + return policyName; + } + public String getPolicyScope() { + return policyScope; + } + public String getFirewallJson() { + return firewallJson; + } + public void setPolicyName(String policyName) { + this.policyName = policyName; + } + public void setPolicyScope(String policyScope) { + this.policyScope = policyScope; + } + public void setFirewallJson(String firewallJson) { + this.firewallJson = firewallJson; + } + public String getRiskType() { + return riskType; + } + public void setRiskType(String riskType) { + this.riskType = riskType; + } + public String getRiskLevel() { + return riskLevel; + } + public void setRiskLevel(String riskLevel) { + this.riskLevel = riskLevel; + } + public String getGuard() { + return guard; + } + public void setGuard(String guard) { + this.guard = guard; + } + public String getTtlDate() { + return ttlDate; + } + public void setTtlDate(String ttlDate) { + this.ttlDate = ttlDate; + } +} diff --git a/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/model_pojo/PepConfigPolicyNameRequest.java b/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/model_pojo/PepConfigPolicyNameRequest.java new file mode 100644 index 000000000..14979b8a1 --- /dev/null +++ b/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/model_pojo/PepConfigPolicyNameRequest.java @@ -0,0 +1,39 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pypdp.model_pojo; + +import java.io.Serializable; + +public class PepConfigPolicyNameRequest implements Serializable{ + + private static final long serialVersionUID = -5045734290192376081L; + + private String policyName = null; + + public void setPolicyName(String policyName) { + this.policyName = policyName; + } + + public String getPolicyName() { + return policyName; + } + +} diff --git a/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/model_pojo/PepConfigPolicyRequest.java b/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/model_pojo/PepConfigPolicyRequest.java new file mode 100644 index 000000000..9776e5091 --- /dev/null +++ b/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/model_pojo/PepConfigPolicyRequest.java @@ -0,0 +1,187 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pypdp.model_pojo; + +import java.io.Serializable; +import java.util.Map; + +public class PepConfigPolicyRequest implements Serializable { + + private static final long serialVersionUID = 7946941587312347282L; + + private String policyScope = null; + private String policyName = null; + private String policyDescription = null; + private String ecompName = null; + private String configName = null; + private Map configAttributes = null; + private String configType = null; + private String body = null; + private String riskType = "defualt"; + private String riskLevel = "5"; + private String guard = "false"; + private String ttlDate = null; + + /** + * @return the policyScope + */ + public String getPolicyScope() { + return policyScope; + } + /** + * @return the policyName + */ + public String getPolicyName() { + return policyName; + } + /** + * @return the policyDescription + */ + public String getPolicyDescription() { + return policyDescription; + } + /** + * @return the ecompName + */ + public String getEcompName() { + return ecompName; + } + /** + * @return the configName + */ + public String getConfigName() { + return configName; + } + /** + * @return the configAttributes + */ + public Map getConfigAttributes() { + return configAttributes; + } + /** + * @return the configType + */ + public String getConfigType() { + return configType; + } + /** + * @return the body + */ + public String getBody() { + return body; + } + /** + * @param policyScope the policyScope to set + */ + public void setPolicyScope(String policyScope) { + this.policyScope = policyScope; + } + /** + * @param policyName the policyName to set + */ + public void setPolicyName(String policyName) { + this.policyName = policyName; + } + /** + * @param policyDescription the policyDescription to set + */ + public void setPolicyDescription(String policyDescription) { + this.policyDescription = policyDescription; + } + /** + * @param ecompName the ecompName to set + */ + public void setEcompName(String ecompName) { + this.ecompName = ecompName; + } + /** + * @param configName the configName to set + */ + public void setConfigName(String configName) { + this.configName = configName; + } + /** + * @param configAttributes the configAttributes to set + */ + public void setConfigAttributes(Map configAttributes) { + this.configAttributes = configAttributes; + } + /** + * @param configType the configType to set + */ + public void setConfigType(String configType) { + this.configType = configType; + } + /** + * @param body the body to set + */ + public void setBody(String body) { + this.body = body; + } + /** + * @return the guard + */ + public String getGuard() { + return guard; + } + /** + * @param guard the guard to set + */ + public void setGuard(String guard) { + this.guard = guard; + } + /** + * @return the riskLevel + */ + public String getRiskLevel() { + return riskLevel; + } + /** + * @param riskLevel the riskLevel to set + */ + public void setRiskLevel(String riskLevel) { + this.riskLevel = riskLevel; + } + /** + * @return the ttlDate + */ + public String getTtlDate() { + return ttlDate; + } + /** + * @param ttlDate the ttlDate to set + */ + public void setTtlDate(String ttlDate) { + this.ttlDate = ttlDate; + } + /** + * @return the riskType + */ + public String getRiskType() { + return riskType; + } + /** + * @param riskType the riskType to set + */ + public void setRiskType(String riskType) { + this.riskType = riskType; + } +} diff --git a/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/model_pojo/PepPushPolicyRequest.java b/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/model_pojo/PepPushPolicyRequest.java new file mode 100644 index 000000000..0c3c8efd9 --- /dev/null +++ b/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/model_pojo/PepPushPolicyRequest.java @@ -0,0 +1,66 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pypdp.model_pojo; + +import java.io.Serializable; + +public class PepPushPolicyRequest implements Serializable { + + private static final long serialVersionUID = 2638006651985508836L; + + private String policyScope = null; + private String policyName = null; + private String policyType = null; + private String pdpGroup = null; + + public String getPolicyScope() { + return policyScope; + } + + public String getPolicyName() { + return policyName; + } + + public String getPolicyType() { + return policyType; + } + + public String getPdpGroup() { + return pdpGroup; + } + + public void setPolicyScope(String policyScope) { + this.policyScope = policyScope; + } + + public void setPolicyType(String policyType) { + this.policyType = policyType; + } + + public void setPdpGroup(String pdpGroup) { + this.pdpGroup = pdpGroup; + } + + public void setPolicyName(String policyName) { + this.policyName = policyName; + } + +} diff --git a/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/model_pojo/PyPolicyConfig.java b/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/model_pojo/PyPolicyConfig.java new file mode 100644 index 000000000..22882764c --- /dev/null +++ b/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/model_pojo/PyPolicyConfig.java @@ -0,0 +1,95 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pypdp.model_pojo; + +import io.swagger.annotations.ApiModel; + +import java.util.Map; + +import org.openecomp.policy.api.PolicyConfigStatus; +import org.openecomp.policy.api.PolicyType; + +@ApiModel +public class PyPolicyConfig{ + private String policyConfigMessage; + private PolicyConfigStatus policyConfigStatus; + private PolicyType type; + private String config; + private String policyName; + private String policyVersion; + private Map matchingConditions; + private Map responseAttributes; + private Map property; + public String getConfig() { + return config; + } + public void setConfig(String config) { + this.config = config; + } + public PolicyType getType() { + return type; + } + public void setType(PolicyType type) { + this.type = type; + } + public PolicyConfigStatus getPolicyConfigStatus() { + return policyConfigStatus; + } + public void setPolicyConfigStatus(PolicyConfigStatus policyConfigStatus) { + this.policyConfigStatus = policyConfigStatus; + } + public String getPolicyConfigMessage() { + return policyConfigMessage; + } + public void setPolicyConfigMessage(String policyConfigMessage) { + this.policyConfigMessage = policyConfigMessage; + } + public Map getProperty() { + return property; + } + public void setProperty(Map property) { + this.property = property; + } + public String getPolicyName(){ + return policyName; + } + public void setPolicyName(String policyName){ + this.policyName = policyName; + } + public String getPolicyVersion(){ + return policyVersion; + } + public void setPolicyVersion(String policyVersion){ + this.policyVersion = policyVersion; + } + public Map getMatchingConditions(){ + return matchingConditions; + } + public void setMatchingConditions(Map matchingConditions){ + this.matchingConditions = matchingConditions; + } + public void setResponseAttributes(Map responseAttributes){ + this.responseAttributes = responseAttributes; + } + public Map getResponseAttributes(){ + return responseAttributes; + } +} diff --git a/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/notifications/Notification.java b/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/notifications/Notification.java new file mode 100644 index 000000000..a1717c275 --- /dev/null +++ b/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/notifications/Notification.java @@ -0,0 +1,50 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pypdp.notifications; + +import java.util.Collection; + +import org.openecomp.policy.api.LoadedPolicy; +import org.openecomp.policy.api.RemovedPolicy; + +public class Notification{ + + private Collection removedPolicies = null; + private Collection loadedPolicies = null; + + public Collection getRemovedPolicies() { + return removedPolicies; + } + + public Collection getLoadedPolicies() { + return loadedPolicies; + } + + + public void setRemovedPolicies(Collection removedPolicies){ + this.removedPolicies = removedPolicies; + } + + public void setLoadedPolicies(Collection loadedPolicies){ + this.loadedPolicies = loadedPolicies; + } + +} diff --git a/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/notifications/NotificationController.java b/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/notifications/NotificationController.java new file mode 100644 index 000000000..0f2ed9b45 --- /dev/null +++ b/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/notifications/NotificationController.java @@ -0,0 +1,149 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pypdp.notifications; + +import java.util.HashSet; +import java.util.Iterator; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openecomp.policy.api.LoadedPolicy; +import org.openecomp.policy.api.NotificationHandler; +import org.openecomp.policy.api.PDPNotification; +import org.openecomp.policy.api.RemovedPolicy; +import org.openecomp.policy.common.logging.eelf.MessageCodes; +import org.openecomp.policy.common.logging.eelf.PolicyLogger; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; + +public class NotificationController implements NotificationHandler{ + private static final Log logger = LogFactory.getLog(NotificationController.class); + private static Notification record = new Notification(); + //private static CountDownLatch latch; + + @Override + public void notificationReceived(PDPNotification notification) { + //latch = new CountDownLatch(1); + if(notification!=null){ + // Take this into our Record holder for polling requests. + NotificationServer.setUpdate(record(notification)); + // Send the Update as is for AUTO clients. + ObjectWriter ow = new ObjectMapper().writer(); + try{ + String json = ow.writeValueAsString(notification); + System.out.println("\n Notification: "+json); + logger.info(json); + NotificationServer.sendNotification(json); + //latch.await(); + } catch (JsonProcessingException e) { + logger.error(XACMLErrorConstants.ERROR_SCHEMA_INVALID + e.getMessage()); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.error(MessageCodes.ERROR_SCHEMA_INVALID, e, ""); + } + + } + } + + public static String record(PDPNotification notification) { + // Initialization with updates. + if(record.getRemovedPolicies()== null){ + record.setRemovedPolicies(notification.getRemovedPolicies()); + } + if(record.getLoadedPolicies()== null){ + record.setLoadedPolicies(notification.getLoadedPolicies()); + } + // Check if there is anything new and update the record.. + if(record.getLoadedPolicies()!= null || record.getRemovedPolicies()!=null) { + HashSet removedPolicies = (HashSet) record.getRemovedPolicies(); + HashSet updatedPolicies = (HashSet) record.getLoadedPolicies(); + // Checking with New updated policies. + if(notification.getLoadedPolicies()!= null && !notification.getLoadedPolicies().isEmpty()) { + for( LoadedPolicy newUpdatedPolicy : notification.getLoadedPolicies()) { + // If it was removed earlier then we need to remove from our record + Iterator oldRemovedPolicy = removedPolicies.iterator(); + while(oldRemovedPolicy.hasNext()){ + RemovedPolicy policy = oldRemovedPolicy.next(); + if(newUpdatedPolicy.getPolicyName().equals(policy.getPolicyName())) { + if(newUpdatedPolicy.getVersionNo().equals(policy.getVersionNo())) { + oldRemovedPolicy.remove(); + } + } + } + // If it was previously updated need to Overwrite it to the record. + Iterator oldUpdatedPolicy = updatedPolicies.iterator(); + while(oldUpdatedPolicy.hasNext()){ + LoadedPolicy policy = oldUpdatedPolicy.next(); + if(newUpdatedPolicy.getPolicyName().equals(policy.getPolicyName())) { + if(newUpdatedPolicy.getVersionNo().equals(policy.getVersionNo())) { + oldUpdatedPolicy.remove(); + } + } + } + updatedPolicies.add(newUpdatedPolicy); + } + } + // Checking with New Removed policies. + if(notification.getRemovedPolicies()!= null && !notification.getRemovedPolicies().isEmpty()) { + for( RemovedPolicy newRemovedPolicy : notification.getRemovedPolicies()) { + // If it was removed earlier then we need to remove from our record + Iterator oldRemovedPolicy = removedPolicies.iterator(); + while(oldRemovedPolicy.hasNext()){ + RemovedPolicy policy = oldRemovedPolicy.next(); + if(newRemovedPolicy.getPolicyName().equals(policy.getPolicyName())) { + if(newRemovedPolicy.getVersionNo().equals(policy.getVersionNo())) { + oldRemovedPolicy.remove(); + } + } + } + // If it was previously updated need to Overwrite it to the record. + Iterator oldUpdatedPolicy = updatedPolicies.iterator(); + while(oldUpdatedPolicy.hasNext()){ + LoadedPolicy policy = oldUpdatedPolicy.next(); + if(newRemovedPolicy.getPolicyName().equals(policy.getPolicyName())) { + if(newRemovedPolicy.getVersionNo().equals(policy.getVersionNo())) { + oldUpdatedPolicy.remove(); + } + } + } + removedPolicies.add(newRemovedPolicy); + } + } + record.setRemovedPolicies(removedPolicies); + record.setLoadedPolicies(updatedPolicies); + } + // Send the Result to the caller. + ObjectWriter om = new ObjectMapper().writer(); + String json = null; + try { + json = om.writeValueAsString(record); + } catch (JsonProcessingException e) { + logger.error(XACMLErrorConstants.ERROR_SCHEMA_INVALID + e.getMessage()); + // TODO:EELF Cleanup - Remove logger + PolicyLogger.error(MessageCodes.ERROR_SCHEMA_INVALID, e, ""); + } + logger.info(json); + return json; + } + +} diff --git a/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/notifications/NotificationServer.java b/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/notifications/NotificationServer.java new file mode 100644 index 000000000..44324b55c --- /dev/null +++ b/PyPDPServer/src/main/java/org/openecomp/policy/pypdp/notifications/NotificationServer.java @@ -0,0 +1,90 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pypdp.notifications; + +import java.io.IOException; +import java.util.Queue; +import java.util.concurrent.ConcurrentLinkedQueue; + +import javax.websocket.OnClose; +import javax.websocket.OnError; +import javax.websocket.OnMessage; +import javax.websocket.OnOpen; +import javax.websocket.Session; +import javax.websocket.server.ServerEndpoint; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + + +@ServerEndpoint(value = "/org.openecomp.policy.pypdp.notifications") +public class NotificationServer { + private static final Logger logger = FlexLogger.getLogger(NotificationServer.class); + private static Queue queue = new ConcurrentLinkedQueue(); + private static String update = null; + + @OnOpen + public void openConnection(Session session) { + logger.info("Session Connected: " + session.getId()); + queue.add(session); + } + + @OnClose + public void closeConnection(Session session) { + queue.remove(session); + } + + @OnError + public void error(Session session, Throwable t) { + queue.remove(session); + logger.info(XACMLErrorConstants.ERROR_SYSTEM_ERROR+ "Session Error for : " + session.getId() + " Error: " + t.getMessage()); + + } + + @OnMessage + public void Message(String message, Session session) { + if(message.equalsIgnoreCase("Manual")) { + try { + session.getBasicRemote().sendText(update); + } catch (IOException e) { + logger.info(XACMLErrorConstants.ERROR_SYSTEM_ERROR+ "Error in sending the Event Notification: "+ e.getMessage()); + } + } + } + + public static void sendNotification(String notification){ + for(Session session: queue) { + try { + session.getBasicRemote().sendText(notification); + } catch (IOException e) { + logger.info(XACMLErrorConstants.ERROR_SYSTEM_ERROR+ "Error in sending the Event Notification: "+ e.getMessage()); + } + } + } + + public static void setUpdate(String update) { + NotificationServer.update = update; + } +} \ No newline at end of file diff --git a/PyPDPServer/src/main/resources/log4j.properties b/PyPDPServer/src/main/resources/log4j.properties new file mode 100644 index 000000000..2d810f0ad --- /dev/null +++ b/PyPDPServer/src/main/resources/log4j.properties @@ -0,0 +1,56 @@ +### +# ============LICENSE_START======================================================= +# ECOMP Policy Engine +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +# +# Use this properties for Deployments. +# +# +# Set root logger level to DEBUG and its only appender to FILE. +#log4j.rootLogger=DEBUG, FILE, CONSOLE +log4j.rootLogger=INFO, FILE + +# FILE appender +log4j.appender.FILE=org.apache.log4j.DailyRollingFileAppender +log4j.appender.FILE.File=${catalina.base}/logs/pypdp.log +log4j.appender.FILE.ImmediateFlush=true +log4j.appender.FILE.Threshold=debug +log4j.appender.FILE.append=true +log4j.appender.FILE.DatePattern='.'yyyy-MM-dd +log4j.appender.FILE.layout=org.apache.log4j.PatternLayout +log4j.appender.FILE.layout.ConversionPattern=%d{yyyy-MM-dd'T'HH:mm:ss}{GMT+0}+00:00|%X{requestId}|%X{serviceInstanceId}|%t|%X{serverName}|%X{serviceName}|%X{instanceUuid}|%p|%X{severity}|%X{serverIpAddress}|%X{server}|%X{clientIpAddress}|%l||%m%n + +# for Developments and Debugging +#log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender +#log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout +#log4j.appender.CONSOLE.layout.ConversionPattern=%d{yyyy_MM_dd_HH_mm_ss_SSS} [%t] %-5p %l- %m%n + +# +# audit (transaction) logging -- CURRENTLY NOT DONE IN PYPDP +# +#log4j.logger.auditLogger=INFO,AUDIT_LOG +#log4j.additivity.auditLogger=false + +#log4j.appender.AUDIT_LOG=org.apache.log4j.DailyRollingFileAppender +#log4j.appender.AUDIT_LOG.File=${catalina.base}/logs/audit.log +#log4j.appender.AUDIT_LOG.Append=true +#log4j.appender.AUDIT_LOG.DatePattern='.'yyyy-MM-dd +#log4j.appender.AUDIT_LOG.threshold=INFO +#log4j.appender.AUDIT_LOG.layout=org.apache.log4j.EnhancedPatternLayout +#log4j.appender.AUDIT_LOG.layout.ConversionPattern=%d{yyyy-MM-dd'T'HH:mm:ss}{GMT+0}+00:00|%X{requestId}|%X{serviceInstanceId}|%t|%X{serverName}|%X{serviceName}|%X{instanceUuid}|%p|%X{severity}|%X{serverIpAddress}|%X{server}|%X{clientIpAddress}|%X{className}|%X{timer}|%m%n diff --git a/PyPDPServer/src/main/resources/logback.xml b/PyPDPServer/src/main/resources/logback.xml new file mode 100644 index 000000000..f89074199 --- /dev/null +++ b/PyPDPServer/src/main/resources/logback.xml @@ -0,0 +1,252 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --> + + + + + + + + + + + + + + + + + + + + ${defaultPattern} + + + + + + + + + + + + + ${logDirectory}/${auditLogName}.log + + ${logDirectory}/${auditLogName}.%i.log.zip + + 1 + 9 + + + 5MB + + + ${defaultAuditPattern} + + + + + 256 + + + + + + + + ${logDirectory}/${metricsLogName}.log + + ${logDirectory}/${metricsLogName}.%i.log.zip + + 1 + 9 + + + 5MB + + + + ${defaultMetricPattern} + + + + + 256 + + + + + + + + ${logDirectory}/${errorLogName}.log + + ${logDirectory}/${errorLogName}.%i.log.zip + + 1 + 9 + + + ERROR + + + 5MB + + + ${defaultErrorPattern} + + + + + 256 + + + + + + + ${debugLogDirectory}/${debugLogName}.log + + ${debugLogDirectory}/${debugLogName}.%i.log.zip + + 1 + 9 + + + INFO + + + 5MB + + + ${debugLoggerPattern} + + + + + 256 + + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/PyPDPServer/src/test/java/testpypdp/AuthorizationTest.java b/PyPDPServer/src/test/java/testpypdp/AuthorizationTest.java new file mode 100644 index 000000000..228e926a8 --- /dev/null +++ b/PyPDPServer/src/test/java/testpypdp/AuthorizationTest.java @@ -0,0 +1,382 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package testpypdp; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.io.IOException; + +import javax.servlet.FilterChain; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import org.openecomp.policy.pypdp.authorization.AuthenticationFilter; + +/* + * Authentication Filter Testing + */ +public class AuthorizationTest { + private static final String MASTERCLIENT= "cHl0aG9uOnRlc3Q="; + /*private static final String CONFIGCLIENT= "Y29uZmlnOmNvbmZpZw=="; + private static final String ACTIONCLIENT= "YWN0aW9uOmFjdGlvbg=="; + private static final String DECIDECLIENT= "ZGVjaWRlOmRlY2lkZQ=="; + private static final String CREATECLIENT= "Y3JlYXRlOmNyZWF0ZQ=="; + private static final String DELETECLIENT= "ZGVsZXRlOmRlbGV0ZQ==";*/ + + private AuthenticationFilter authenticationFilter = new AuthenticationFilter(); + + @Before + public void setUp() throws Exception{ + authenticationFilter.init(null); + } + + @Test + public void testDoFilterError() throws IOException, ServletException { + // create the objects to be mocked + HttpServletRequest httpServletRequest = mock(HttpServletRequest.class); + HttpServletResponse httpServletResponse = mock(HttpServletResponse.class); + FilterChain filterChain = mock(FilterChain.class); + // + when(httpServletRequest.getRequestURI()).thenReturn("error"); + + authenticationFilter.doFilter(httpServletRequest, httpServletResponse, + filterChain); + + // verify if unauthorized + verify(httpServletResponse).setStatus(HttpServletResponse.SC_BAD_REQUEST); + } + + @Test + public void testDoFilterNotification() throws IOException, ServletException { + // create the objects to be mocked + HttpServletRequest httpServletRequest = mock(HttpServletRequest.class); + HttpServletResponse httpServletResponse = mock(HttpServletResponse.class); + FilterChain filterChain = mock(FilterChain.class); + // + when(httpServletRequest.getRequestURI()).thenReturn("org.openecomp.policy.pypdp.notifications swagger api-docs configuration"); + + authenticationFilter.doFilter(httpServletRequest, httpServletResponse, + filterChain); + + verify(filterChain).doFilter(httpServletRequest,httpServletResponse); + } + + /*@Test + public void testDoFilterWrongAuthenticaton() throws IOException, ServletException { + // create the objects to be mocked + HttpServletRequest httpServletRequest = mock(HttpServletRequest.class); + HttpServletResponse httpServletResponse = mock(HttpServletResponse.class); + FilterChain filterChain = mock(FilterChain.class); + // + when(httpServletRequest.getHeader(AuthenticationFilter.AUTHENTICATION_HEADER)).thenReturn("error"); + when(httpServletRequest.getRequestURI()).thenReturn("getConfig"); + + authenticationFilter.doFilter(httpServletRequest, httpServletResponse, + filterChain); + + // verify if unauthorized + verify(httpServletResponse).setStatus(HttpServletResponse.SC_UNAUTHORIZED); + }*/ + + /*@Test + public void testDoFilterWrongClientAuthenticaton() throws IOException, ServletException { + // create the objects to be mocked + HttpServletRequest httpServletRequest = mock(HttpServletRequest.class); + HttpServletResponse httpServletResponse = mock(HttpServletResponse.class); + FilterChain filterChain = mock(FilterChain.class); + // + when(httpServletRequest.getHeader(AuthenticationFilter.AUTHENTICATION_HEADER)).thenReturn("Basic dGVzdHJlc3Q6c2VjVXJl"); + when(httpServletRequest.getRequestURI()).thenReturn("getConfig"); + when(httpServletRequest.getHeader("ClientAuth")).thenReturn("Error"); + + authenticationFilter.doFilter(httpServletRequest, httpServletResponse, + filterChain); + // verify if unauthorized + verify(httpServletResponse).setStatus(HttpServletResponse.SC_UNAUTHORIZED); + }*/ + + @Test + public void testDoFilterWrongClientAuthenticatonCount() throws IOException, ServletException { + // create the objects to be mocked + HttpServletRequest httpServletRequest = mock(HttpServletRequest.class); + HttpServletResponse httpServletResponse = mock(HttpServletResponse.class); + FilterChain filterChain = mock(FilterChain.class); + // + when(httpServletRequest.getHeader(AuthenticationFilter.AUTHENTICATION_HEADER)).thenReturn("Basic dGVzdHJlc3Q6c2VjVXJl"); + when(httpServletRequest.getRequestURI()).thenReturn("count"); + when(httpServletRequest.getHeader("ClientAuth")).thenReturn("Error"); + + authenticationFilter.doFilter(httpServletRequest, httpServletResponse, + filterChain); + + verify(filterChain).doFilter(httpServletRequest,httpServletResponse); + } + + /*@Test + public void testDoFilterWrongGetConfigAuthorization() throws IOException, ServletException { + // create the objects to be mocked + HttpServletRequest httpServletRequest = mock(HttpServletRequest.class); + HttpServletResponse httpServletResponse = mock(HttpServletResponse.class); + FilterChain filterChain = mock(FilterChain.class); + // + when(httpServletRequest.getHeader(AuthenticationFilter.AUTHENTICATION_HEADER)).thenReturn("Basic dGVzdHJlc3Q6c2VjVXJl"); + when(httpServletRequest.getRequestURI()).thenReturn("getConfig"); + when(httpServletRequest.getHeader("ClientAuth")).thenReturn(ACTIONCLIENT); + + authenticationFilter.doFilter(httpServletRequest, httpServletResponse, + filterChain); + // verify if unauthorized + verify(httpServletResponse).setStatus(HttpServletResponse.SC_UNAUTHORIZED); + }*/ + + /*@Test + public void testDoFilterWrongSendEventAuthorization() throws IOException, ServletException { + // create the objects to be mocked + HttpServletRequest httpServletRequest = mock(HttpServletRequest.class); + HttpServletResponse httpServletResponse = mock(HttpServletResponse.class); + FilterChain filterChain = mock(FilterChain.class); + // + when(httpServletRequest.getHeader(AuthenticationFilter.AUTHENTICATION_HEADER)).thenReturn("Basic dGVzdHJlc3Q6c2VjVXJl"); + when(httpServletRequest.getRequestURI()).thenReturn("sendEvent"); + when(httpServletRequest.getHeader("ClientAuth")).thenReturn(CONFIGCLIENT); + + authenticationFilter.doFilter(httpServletRequest, httpServletResponse, + filterChain); + // verify if unauthorized + verify(httpServletResponse).setStatus(HttpServletResponse.SC_UNAUTHORIZED); + }*/ + + /*@Test + public void testDoFilterWrongUpdatePolicyAuthorization() throws IOException, ServletException { + // create the objects to be mocked + HttpServletRequest httpServletRequest = mock(HttpServletRequest.class); + HttpServletResponse httpServletResponse = mock(HttpServletResponse.class); + FilterChain filterChain = mock(FilterChain.class); + // + when(httpServletRequest.getHeader(AuthenticationFilter.AUTHENTICATION_HEADER)).thenReturn("Basic dGVzdHJlc3Q6c2VjVXJl"); + when(httpServletRequest.getRequestURI()).thenReturn("updatePolicy"); + when(httpServletRequest.getHeader("ClientAuth")).thenReturn(ACTIONCLIENT); + + authenticationFilter.doFilter(httpServletRequest, httpServletResponse, + filterChain); + // verify if unauthorized + verify(httpServletResponse).setStatus(HttpServletResponse.SC_UNAUTHORIZED); + }*/ + + /*@Test + public void testDoFilterWrongCreatePolicyAuthorization() throws IOException, ServletException { + // create the objects to be mocked + HttpServletRequest httpServletRequest = mock(HttpServletRequest.class); + HttpServletResponse httpServletResponse = mock(HttpServletResponse.class); + FilterChain filterChain = mock(FilterChain.class); + // + when(httpServletRequest.getHeader(AuthenticationFilter.AUTHENTICATION_HEADER)).thenReturn("Basic dGVzdHJlc3Q6c2VjVXJl"); + when(httpServletRequest.getRequestURI()).thenReturn("createPolicy"); + when(httpServletRequest.getHeader("ClientAuth")).thenReturn(ACTIONCLIENT); + + authenticationFilter.doFilter(httpServletRequest, httpServletResponse, + filterChain); + // verify if unauthorized + verify(httpServletResponse).setStatus(HttpServletResponse.SC_UNAUTHORIZED); + }*/ + + /*@Test + public void testDoFilterWrongPushPolicyAuthorization() throws IOException, ServletException { + // create the objects to be mocked + HttpServletRequest httpServletRequest = mock(HttpServletRequest.class); + HttpServletResponse httpServletResponse = mock(HttpServletResponse.class); + FilterChain filterChain = mock(FilterChain.class); + // + when(httpServletRequest.getHeader(AuthenticationFilter.AUTHENTICATION_HEADER)).thenReturn("Basic dGVzdHJlc3Q6c2VjVXJl"); + when(httpServletRequest.getRequestURI()).thenReturn("pushPolicy"); + when(httpServletRequest.getHeader("ClientAuth")).thenReturn(DELETECLIENT); + + authenticationFilter.doFilter(httpServletRequest, httpServletResponse, + filterChain); + // verify if unauthorized + verify(httpServletResponse).setStatus(HttpServletResponse.SC_UNAUTHORIZED); + }*/ + + /*@Test + public void testDoFilterWrongDeletePolicyAuthorization() throws IOException, ServletException { + // create the objects to be mocked + HttpServletRequest httpServletRequest = mock(HttpServletRequest.class); + HttpServletResponse httpServletResponse = mock(HttpServletResponse.class); + FilterChain filterChain = mock(FilterChain.class); + // + when(httpServletRequest.getHeader(AuthenticationFilter.AUTHENTICATION_HEADER)).thenReturn("Basic dGVzdHJlc3Q6c2VjVXJl"); + when(httpServletRequest.getRequestURI()).thenReturn("deletePolicy"); + when(httpServletRequest.getHeader("ClientAuth")).thenReturn(DECIDECLIENT); + + authenticationFilter.doFilter(httpServletRequest, httpServletResponse, + filterChain); + // verify if unauthorized + verify(httpServletResponse).setStatus(HttpServletResponse.SC_UNAUTHORIZED); + }*/ + + /*@Test + public void testDoFilterWrongDecidePolicyAuthorization() throws IOException, ServletException { + // create the objects to be mocked + HttpServletRequest httpServletRequest = mock(HttpServletRequest.class); + HttpServletResponse httpServletResponse = mock(HttpServletResponse.class); + FilterChain filterChain = mock(FilterChain.class); + // + when(httpServletRequest.getHeader(AuthenticationFilter.AUTHENTICATION_HEADER)).thenReturn("Basic dGVzdHJlc3Q6c2VjVXJl"); + when(httpServletRequest.getRequestURI()).thenReturn("getDecision"); + when(httpServletRequest.getHeader("ClientAuth")).thenReturn(CREATECLIENT); + + authenticationFilter.doFilter(httpServletRequest, httpServletResponse, + filterChain); + // verify if unauthorized + verify(httpServletResponse).setStatus(HttpServletResponse.SC_UNAUTHORIZED); + }*/ + + @Test + public void testDoFilterAuthorizedError() throws IOException, ServletException { + // create the objects to be mocked + HttpServletRequest httpServletRequest = mock(HttpServletRequest.class); + HttpServletResponse httpServletResponse = mock(HttpServletResponse.class); + FilterChain filterChain = mock(FilterChain.class); + // + when(httpServletRequest.getHeader(AuthenticationFilter.AUTHENTICATION_HEADER)).thenReturn("Basic dGVzdHJlc3Q6c2VjVXJl"); + when(httpServletRequest.getRequestURI()).thenReturn("error"); + when(httpServletRequest.getHeader("ClientAuth")).thenReturn(MASTERCLIENT); + + authenticationFilter.doFilter(httpServletRequest, httpServletResponse, + filterChain); + // verify if unauthorized + verify(httpServletResponse).setStatus(HttpServletResponse.SC_BAD_REQUEST); + } + + @Test + public void testDoFilterAuthorizedPDPs() throws IOException, ServletException { + // create the objects to be mocked + HttpServletRequest httpServletRequest = mock(HttpServletRequest.class); + HttpServletResponse httpServletResponse = mock(HttpServletResponse.class); + FilterChain filterChain = mock(FilterChain.class); + // + when(httpServletRequest.getHeader(AuthenticationFilter.AUTHENTICATION_HEADER)).thenReturn("Basic dGVzdHJlc3Q6c2VjVXJl"); + when(httpServletRequest.getRequestURI()).thenReturn("pdps paps"); + when(httpServletRequest.getHeader("ClientAuth")).thenReturn(MASTERCLIENT); + + authenticationFilter.doFilter(httpServletRequest, httpServletResponse, + filterChain); + + verify(filterChain).doFilter(httpServletRequest,httpServletResponse); + } + + @Test + public void testDoFilterDecideAuthorized() throws IOException, ServletException { + // create the objects to be mocked + HttpServletRequest httpServletRequest = mock(HttpServletRequest.class); + HttpServletResponse httpServletResponse = mock(HttpServletResponse.class); + FilterChain filterChain = mock(FilterChain.class); + // + when(httpServletRequest.getHeader(AuthenticationFilter.AUTHENTICATION_HEADER)).thenReturn("Basic dGVzdHJlc3Q6c2VjVXJl"); + when(httpServletRequest.getRequestURI()).thenReturn("getDecision"); + when(httpServletRequest.getHeader(AuthenticationFilter.ENVIRONMENT_HEADER)).thenReturn("DEVL"); + + authenticationFilter.doFilter(httpServletRequest, httpServletResponse, + filterChain); + + verify(filterChain).doFilter(httpServletRequest,httpServletResponse); + } + + @Test + public void testDoFilterDeleteAuthorized() throws IOException, ServletException { + // create the objects to be mocked + HttpServletRequest httpServletRequest = mock(HttpServletRequest.class); + HttpServletResponse httpServletResponse = mock(HttpServletResponse.class); + FilterChain filterChain = mock(FilterChain.class); + // + when(httpServletRequest.getHeader(AuthenticationFilter.AUTHENTICATION_HEADER)).thenReturn("Basic dGVzdHJlc3Q6c2VjVXJl"); + when(httpServletRequest.getRequestURI()).thenReturn("deletePolicy"); + when(httpServletRequest.getHeader(AuthenticationFilter.ENVIRONMENT_HEADER)).thenReturn("DEVL"); + + authenticationFilter.doFilter(httpServletRequest, httpServletResponse, + filterChain); + + verify(filterChain).doFilter(httpServletRequest,httpServletResponse); + } + + @Test + public void testDoFilterEventAuthorized() throws IOException, ServletException { + // create the objects to be mocked + HttpServletRequest httpServletRequest = mock(HttpServletRequest.class); + HttpServletResponse httpServletResponse = mock(HttpServletResponse.class); + FilterChain filterChain = mock(FilterChain.class); + // + when(httpServletRequest.getHeader(AuthenticationFilter.AUTHENTICATION_HEADER)).thenReturn("Basic dGVzdHJlc3Q6c2VjVXJl"); + when(httpServletRequest.getRequestURI()).thenReturn("sendEvent"); + when(httpServletRequest.getHeader(AuthenticationFilter.ENVIRONMENT_HEADER)).thenReturn("DEVL"); + + authenticationFilter.doFilter(httpServletRequest, httpServletResponse, + filterChain); + + verify(filterChain).doFilter(httpServletRequest,httpServletResponse); + } + + @Test + public void testDoFilterCreateAuthorized() throws IOException, ServletException { + // create the objects to be mocked + HttpServletRequest httpServletRequest = mock(HttpServletRequest.class); + HttpServletResponse httpServletResponse = mock(HttpServletResponse.class); + FilterChain filterChain = mock(FilterChain.class); + // + when(httpServletRequest.getHeader(AuthenticationFilter.AUTHENTICATION_HEADER)).thenReturn("Basic dGVzdHJlc3Q6c2VjVXJl"); + when(httpServletRequest.getRequestURI()).thenReturn("createPolicy pushPolicy updatePolicy"); + when(httpServletRequest.getHeader(AuthenticationFilter.ENVIRONMENT_HEADER)).thenReturn("DEVL"); + + authenticationFilter.doFilter(httpServletRequest, httpServletResponse, + filterChain); + + verify(filterChain).doFilter(httpServletRequest,httpServletResponse); + } + + @Test + public void testDoFilterConfigAuthorized() throws IOException, ServletException { + // create the objects to be mocked + HttpServletRequest httpServletRequest = mock(HttpServletRequest.class); + HttpServletResponse httpServletResponse = mock(HttpServletResponse.class); + FilterChain filterChain = mock(FilterChain.class); + // + when(httpServletRequest.getHeader(AuthenticationFilter.AUTHENTICATION_HEADER)).thenReturn("Basic dGVzdHJlc3Q6c2VjVXJl"); + when(httpServletRequest.getRequestURI()).thenReturn("getConfig"); + when(httpServletRequest.getHeader(AuthenticationFilter.ENVIRONMENT_HEADER)).thenReturn("DEVL"); + + authenticationFilter.doFilter(httpServletRequest, httpServletResponse, + filterChain); + + verify(filterChain).doFilter(httpServletRequest,httpServletResponse); + } + + @After + public void tearDown(){ + authenticationFilter.destroy(); + } +} diff --git a/PyPDPServer/src/test/java/testpypdp/ConfigRequestTest.java b/PyPDPServer/src/test/java/testpypdp/ConfigRequestTest.java new file mode 100644 index 000000000..30e94fed9 --- /dev/null +++ b/PyPDPServer/src/test/java/testpypdp/ConfigRequestTest.java @@ -0,0 +1,82 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package testpypdp; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.io.StringReader; +import java.util.HashMap; +import java.util.Properties; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + +import org.openecomp.policy.pypdp.model_pojo.PyPolicyConfig; + +import org.junit.Before; +import org.junit.Test; +import org.openecomp.policy.api.PolicyConfigStatus; +import org.openecomp.policy.api.PolicyType; +import org.openecomp.policy.std.StdPolicyConfig; +import org.w3c.dom.Document; +import org.xml.sax.InputSource; + +import org.openecomp.policy.pypdp.ConfigRequest; + +public class ConfigRequestTest { + + private StdPolicyConfig config; + private ConfigRequest request; + + @Before + public void setUp() { + request = new ConfigRequest(null); + config = new StdPolicyConfig(); + config.setPolicyConfigStatus(PolicyConfigStatus.CONFIG_RETRIEVED); + } + + @Test + public void checkResponsePropertiesTest() { + config.setPolicyType(PolicyType.PROPERTIES); + Properties prop = new Properties(); + prop.put("Key", "value"); + config.setProperties(prop); + PyPolicyConfig pConfig = request.checkResponse(config); + HashMap result = new HashMap(); + result.put("Key", "value"); + assertEquals(pConfig.getProperty(), result); + } + + @Test + public void checkResponseDocumentTest() throws Exception { + config.setPolicyType(PolicyType.XML); + String xmlString = ""; + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder; + builder = factory.newDocumentBuilder(); + Document document = builder.parse(new InputSource(new StringReader( + xmlString))); + config.setDocument(document); + PyPolicyConfig pConfig = request.checkResponse(config); + assertNotNull(pConfig.getConfig()); + } +} diff --git a/PyPDPServer/src/test/java/testpypdp/NotificationControllerTest.java b/PyPDPServer/src/test/java/testpypdp/NotificationControllerTest.java new file mode 100644 index 000000000..c2d9089e3 --- /dev/null +++ b/PyPDPServer/src/test/java/testpypdp/NotificationControllerTest.java @@ -0,0 +1,129 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package testpypdp; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.openecomp.policy.pypdp.notifications.NotificationController; + +import org.junit.Before; +import org.junit.Test; +import org.openecomp.policy.api.LoadedPolicy; +import org.openecomp.policy.api.NotificationType; +import org.openecomp.policy.api.PDPNotification; +import org.openecomp.policy.api.RemovedPolicy; +import org.openecomp.policy.api.UpdateType; +import org.openecomp.policy.std.StdLoadedPolicy; +import org.openecomp.policy.std.StdPDPNotification; +import org.openecomp.policy.std.StdRemovedPolicy; + +import com.fasterxml.jackson.databind.ObjectMapper; + +public class NotificationControllerTest { + private NotificationController notificationController = new NotificationController(); + private StdPDPNotification notification; + + @Before + public void setUp() { + notification = new StdPDPNotification(); + notification.setNotificationType(NotificationType.BOTH); + Collection removedPolicies = new ArrayList(); + Collection loadedPolicies = new ArrayList(); + StdRemovedPolicy removedPolicy = new StdRemovedPolicy(); + StdLoadedPolicy updatedPolicy = new StdLoadedPolicy(); + removedPolicy.setPolicyName("Test"); + removedPolicy.setVersionNo("1"); + removedPolicies.add(removedPolicy); + updatedPolicy.setPolicyName("Testing"); + updatedPolicy.setVersionNo("1"); + updatedPolicy.setUpdateType(UpdateType.NEW); + Map matches = new HashMap(); + matches.put("key", "value"); + updatedPolicy.setMatches(matches); + loadedPolicies.add(updatedPolicy); + notification.setRemovedPolicies(removedPolicies); + notification.setLoadedPolicies(loadedPolicies); + NotificationController.record(notification); + } + + @Test + public void notificationReceivedUpdateTest() throws Exception{ + StdPDPNotification notification = new StdPDPNotification(); + notification.setNotificationType(NotificationType.UPDATE); + Collection loadedPolicies = new ArrayList(); + StdLoadedPolicy updatedPolicy = new StdLoadedPolicy(); + updatedPolicy.setPolicyName("Test"); + updatedPolicy.setVersionNo("1"); + updatedPolicy.setUpdateType(UpdateType.NEW); + Map matches = new HashMap(); + matches.put("key", "value"); + updatedPolicy.setMatches(matches); + loadedPolicies.add(updatedPolicy); + notification.setLoadedPolicies(loadedPolicies); + notificationController.notificationReceived(notification); + Boolean result = false; + PDPNotification newNotification= jsonStringToNotification(NotificationController.record(notification)); + for(LoadedPolicy loadedPolicy: newNotification.getLoadedPolicies()){ + if(loadedPolicy.getPolicyName().equals("Test") && loadedPolicy.getVersionNo().equals("1")){ + result = true; + } + } + assertEquals(result,true); + /*assertEquals( + NotificationController.record(notification), + "{\"removedPolicies\":[],\"updatedPolicies\":[{\"policyName\":\"Test\",\"versionNo\":\"1\",\"matches\":{\"key\":\"value\"},\"updateType\":\"NEW\"},{\"policyName\":\"Testing\",\"versionNo\":\"1\",\"matches\":{\"key\":\"value\"},\"updateType\":\"NEW\"}]}");*/ + } + + @Test + public void notificationReceivedRemovedTest() throws Exception{ + StdPDPNotification notification = new StdPDPNotification(); + notification.setNotificationType(NotificationType.REMOVE); + Collection removedPolicies = new ArrayList(); + StdRemovedPolicy removedPolicy = new StdRemovedPolicy(); + removedPolicy.setPolicyName("Testing"); + removedPolicy.setVersionNo("1"); + removedPolicies.add(removedPolicy); + notification.setRemovedPolicies(removedPolicies); + notificationController.notificationReceived(notification); + Boolean result = false; + PDPNotification newNotification= jsonStringToNotification(NotificationController.record(notification)); + for(RemovedPolicy removed: newNotification.getRemovedPolicies()){ + if(removed.getPolicyName().equals("Testing") && removed.getVersionNo().equals("1")){ + result = true; + } + } + assertEquals(result,true); + /*assertEquals( + NotificationController.record(notification), + "{\"removedPolicies\":[{\"policyName\":\"Test\",\"versionNo\":\"1\"},{\"policyName\":\"Testing\",\"versionNo\":\"1\"}],\"updatedPolicies\":[]}");*/ + } + + public StdPDPNotification jsonStringToNotification(String json) throws Exception{ + ObjectMapper mapper = new ObjectMapper(); + return notification = mapper.readValue(json, StdPDPNotification.class); + } + +} diff --git a/PyPDPServer/src/test/java/testpypdp/PolicyEngineServicesTest.java b/PyPDPServer/src/test/java/testpypdp/PolicyEngineServicesTest.java new file mode 100644 index 000000000..a451c84f0 --- /dev/null +++ b/PyPDPServer/src/test/java/testpypdp/PolicyEngineServicesTest.java @@ -0,0 +1,969 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package testpypdp; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppContextSetup; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import javax.ws.rs.core.MediaType; + +import org.openecomp.policy.pypdp.model_pojo.PepConfigFirewallPolicyRequest; +import org.openecomp.policy.pypdp.model_pojo.PepConfigPolicyNameRequest; +import org.openecomp.policy.pypdp.model_pojo.PepConfigPolicyRequest; +import org.openecomp.policy.pypdp.model_pojo.PepPushPolicyRequest; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.openecomp.policy.api.ConfigRequestParameters; +import org.openecomp.policy.api.DeletePolicyParameters; +import org.openecomp.policy.api.EventRequestParameters; +import org.openecomp.policy.api.PolicyParameters; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.web.context.WebApplicationContext; + +import com.fasterxml.jackson.databind.ObjectMapper; + +import org.openecomp.policy.pypdp.controller.Application; +import org.openecomp.policy.pypdp.controller.PolicyEngineServices; + +/** + * Test for Policy Engine REST Services + * + * + */ +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(classes = { Application.class, + PolicyEngineServices.class }) +@WebAppConfiguration +public class PolicyEngineServicesTest { + private MockMvc mockMvc; + // Don't Change this. + private static final String CONFIG_ERROR_MESSAGE = "[{\"policyConfigMessage\": \"PE300 - Data Issue: PolicyFile Name is empty\"," + + "\"policyConfigStatus\": \"CONFIG_NOT_FOUND\"," + + "\"type\": null," + + "\"config\": null," + + "\"policyName\": null," + + "\"policyVersion\": null," + + "\"matchingConditions\": null," + + "\"responseAttributes\": null," + "\"property\": null" + "}]"; + private static final String VALID_JSON = "{\"serviceTypeId\": \"/v0/firewall/pan\",\"configName\": \"rule1607\",\"deploymentOption\":{\"deployNow\": false},\"securityZoneId\": \"/v0/firewall/pan\",\"serviceGroups\": [{\"name\": \"1607Group\",\"description\": null,\"members\": [{\"type\": \"REFERENCE\",\"name\": \"SList\"},{\"type\": \"REFERENCE\",\"name\": \"Syslog\"}]}, {\"name\": \"Syslog\",\"description\": \"NA\",\"type\": \"SERVICE\",\"transportProtocol\": \"udp\",\"appProtocol\": null,\"ports\": \"514\"}, {\"name\": \"SList\",\"description\": \"Service List\",\"type\": \"SERVICE\",\"transportProtocol\": \"tcp\",\"appProtocol\": null,\"ports\": \"8080\"}],\"addressGroups\": [{\"name\": \"1607Group\",\"description\": null,\"members\": [{\"type\": \"REFERENCE\",\"name\": \"10.11.12.13/14\"},{\"type\": \"REFERENCE\",\"name\": \"10.11.12.13/14\"}]},{\"name\": \"PL_CCE3\",\"description\": \"CCE Routers\",\"members\":[{\"type\": \"REFERENCE\",\"name\": \"10.11.12.13/14\"}]}],\"firewallRuleList\": [{\"position\": \"1\",\"ruleName\": \"1607Rule\",\"fromZones\": [\"Trusted\"],\"toZones\": [\"Untrusted\"],\"negateSource\": false,\"negateDestination\": false,\"sourceList\": [{\"type\": \"REFERENCE\",\"name\": \"PL_CCE3\"}, {\"type\": \"REFERENCE\",\"name\": \"1607Group\"}],\"destinationList\": [{\"type\": \"REFERENCE\",\"name\": \"1607Group\"}],\"sourceServices\": [],\"destServices\": [{\"type\": \"REFERENCE\",\"name\": \"1607Group\"}],\"action\": \"accept\",\"description\": \"Rule for 1607 templates\",\"enabled\": true,\"log\": true}]}"; + private static final String INVALID_JSON = "{\"test\": \"value}"; + + @Autowired + private PolicyEngineServices policyEngineServicesMock; + + @Autowired + private WebApplicationContext webApplicationContext; + + @Before + public void setup() throws Exception { + this.mockMvc = webAppContextSetup(webApplicationContext).build(); + + } + + // Tests for getConfig API + @Test + public void getConfigUsingNoHeader() throws Exception { + ConfigRequestParameters pep = new ConfigRequestParameters(); + pep.setPolicyName(".*"); + mockMvc.perform( + post("/getConfig").content(this.ObjectToJsonString(pep)) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().is(400)); + } + + @Test + public void getConfigUsingErrorHeader() throws Exception { + ConfigRequestParameters pep = new ConfigRequestParameters(); + pep.setPolicyName(".*"); + mockMvc.perform( + post("/getConfig").header("X-ECOMP-RequestID", "Error123") + .header("ClientAuth", "Basic bTAzNzQyOlBvbGljeVIwY2sk") + .content(this.ObjectToJsonString(pep)) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isOk()); + } + + @Test + public void getConfigEmptyEcompName() throws Exception { + ConfigRequestParameters pep = new ConfigRequestParameters(); + pep.setEcompName(""); + mockMvc.perform( + post("/getConfig") + .header("X-ECOMP-RequestID", + UUID.randomUUID().toString()) + .content(this.ObjectToJsonString(pep)) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isBadRequest()); + } + + @Test + public void getConfigEmptyPolicyName() throws Exception { + ConfigRequestParameters pep = new ConfigRequestParameters(); + pep.setPolicyName(""); + mockMvc.perform( + post("/getConfig") + .header("X-ECOMP-RequestID", + UUID.randomUUID().toString()) + .content(this.ObjectToJsonString(pep)) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isBadRequest()); + } + + @Test + public void getConfigUsingErrorPolicyName() throws Exception { + ConfigRequestParameters pep = new ConfigRequestParameters(); + pep.setPolicyName("test"); + mockMvc.perform( + post("/getConfig") + .header("X-ECOMP-RequestID", + UUID.randomUUID().toString()) + .content(this.ObjectToJsonString(pep)) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isBadRequest()); + } + + @Test + public void getConfigUsingErrorEcompName() throws Exception { + ConfigRequestParameters pep = new ConfigRequestParameters(); + pep.setEcompName("test"); + mockMvc.perform( + post("/getConfig") + .header("X-ECOMP-RequestID", + UUID.randomUUID().toString()) + .content(this.ObjectToJsonString(pep)) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isBadRequest()); + } + + @Test + public void getConfigUsingALLPolicyName() throws Exception { + ConfigRequestParameters pep = new ConfigRequestParameters(); + pep.setPolicyName(".*"); + mockMvc.perform( + post("/getConfig") + .header("X-ECOMP-RequestID", + UUID.randomUUID().toString()) + .header("ClientAuth", "Basic bTAzNzQyOlBvbGljeVIwY2sk") + .content(this.ObjectToJsonString(pep)) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isOk()); + } + + @Test + public void getConfigUsingNullPolicyName() throws Exception { + ConfigRequestParameters pep = new ConfigRequestParameters(); + mockMvc.perform( + post("/getConfig") + .header("X-ECOMP-RequestID", + UUID.randomUUID().toString()) + .content(this.ObjectToJsonString(pep)) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isBadRequest()); + } + + @Test + public void getConfigUsingNullEcompName() throws Exception { + ConfigRequestParameters pep = new ConfigRequestParameters(); + pep.setEcompName(null); + mockMvc.perform( + post("/getConfig") + .header("X-ECOMP-RequestID", + UUID.randomUUID().toString()) + .content(this.ObjectToJsonString(pep)) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isBadRequest()); + } + + // Tests for GetConfigByPolicyName API + @Test + public void getConfigByPolicyNameUsingErrorHeader() throws Exception { + PepConfigPolicyNameRequest pep = new PepConfigPolicyNameRequest(); + pep.setPolicyName(null); + mockMvc.perform( + post("/getConfigByPolicyName") + .header("X-ECOMP-RequestID", "ERROR123") + .content(this.ObjectToJsonString(pep)) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().is(400)); + } + + @Test + public void getConfigByPolicyNameUsingNoHeader() throws Exception { + PepConfigPolicyNameRequest pep = new PepConfigPolicyNameRequest(); + pep.setPolicyName(null); + mockMvc.perform( + post("/getConfigByPolicyName").content( + this.ObjectToJsonString(pep)).contentType( + MediaType.APPLICATION_JSON)).andExpect(status().is(400)); + } + + @Test + public void getConfigByPolicyNameUsingEmptyPolicyName() throws Exception { + PepConfigPolicyNameRequest pep = new PepConfigPolicyNameRequest(); + pep.setPolicyName(""); + mockMvc.perform( + post("/getConfigByPolicyName") + .header("X-ECOMP-RequestID", + UUID.randomUUID().toString()) + .header("ClientAuth", "Basic bTAzNzQyOlBvbGljeVIwY2sk") + .content(this.ObjectToJsonString(pep)) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(content().json(CONFIG_ERROR_MESSAGE)); + } + + @Test + public void getConfigByPolicyNameUsingNullPolicyName() throws Exception { + PepConfigPolicyNameRequest pep = new PepConfigPolicyNameRequest(); + pep.setPolicyName(null); + mockMvc.perform( + post("/getConfigByPolicyName") + .header("X-ECOMP-RequestID", + UUID.randomUUID().toString()) + .header("ClientAuth", "Basic bTAzNzQyOlBvbGljeVIwY2sk") + .content(this.ObjectToJsonString(pep)) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(content().json(CONFIG_ERROR_MESSAGE)); + } + + @Test + public void getConfigByPolicyNameUsingALLPolicyName() throws Exception { + PepConfigPolicyNameRequest pep = new PepConfigPolicyNameRequest(); + pep.setPolicyName(".*"); + mockMvc.perform( + post("/getConfigByPolicyName") + .header("X-ECOMP-RequestID", + UUID.randomUUID().toString()) + .header("ClientAuth", "Basic bTAzNzQyOlBvbGljeVIwY2sk") + .content(this.ObjectToJsonString(pep)) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isOk()); + } + + // Tests for SendEvent API + @Test + public void sendEventUsingNoHeader() throws Exception { + EventRequestParameters pep = new EventRequestParameters(); + pep.setEventAttributes(null); + mockMvc.perform( + post("/sendEvent").content(this.ObjectToJsonString(pep)) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isBadRequest()); + } + + @Test + public void sendEventUsingErrorHeader() throws Exception { + EventRequestParameters pep = new EventRequestParameters(); + pep.setEventAttributes(null); + mockMvc.perform( + post("/sendEvent").header("X-ECOMP-RequestID", "ERROR123") + .content(this.ObjectToJsonString(pep)) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isBadRequest()); + } + + @Test + public void sendEventUsingNullEventAttributes() throws Exception { + EventRequestParameters pep = new EventRequestParameters(); + pep.setEventAttributes(null); + mockMvc.perform( + post("/sendEvent") + .header("X-ECOMP-RequestID", + UUID.randomUUID().toString()) + .content(this.ObjectToJsonString(pep)) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isBadRequest()); + } + + @Test + public void sendEventUsingEmptyEventAttributes() throws Exception { + EventRequestParameters pep = new EventRequestParameters(); + Map emptyMap = new HashMap(); + pep.setEventAttributes(emptyMap); + mockMvc.perform( + post("/sendEvent") + .header("X-ECOMP-RequestID", + UUID.randomUUID().toString()) + .content(this.ObjectToJsonString(pep)) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isBadRequest()); + } + + @Test + public void sendEventUsingErrorEventAttributes() throws Exception { + EventRequestParameters pep = new EventRequestParameters(); + Map eventMap = new HashMap(); + eventMap.put("key", "value"); + pep.setEventAttributes(eventMap); + mockMvc.perform( + post("/sendEvent") + .header("X-ECOMP-RequestID", + UUID.randomUUID().toString()) + .content(this.ObjectToJsonString(pep)) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isBadRequest()); + } + + // Tests for Push Policy API + @Test + public void pushPolicyUsingNoHeader() throws Exception { + PepPushPolicyRequest pep = new PepPushPolicyRequest(); + mockMvc.perform( + put("/pushPolicy").content(this.ObjectToJsonString(pep)) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isBadRequest()); + } + + @Test + public void pushPolicyUsingErrorHeader() throws Exception { + PepPushPolicyRequest pep = new PepPushPolicyRequest(); + mockMvc.perform( + put("/pushPolicy").header("X-ECOMP-RequestID", "Error123") + .content(this.ObjectToJsonString(pep)) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isBadRequest()); + } + + @Test + public void pushPolicyUsingNullRequest() throws Exception { + PepPushPolicyRequest pep = new PepPushPolicyRequest(); + mockMvc.perform( + put("/pushPolicy") + .header("X-ECOMP-RequestID", + UUID.randomUUID().toString()) + .content(this.ObjectToJsonString(pep)) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isBadRequest()); + } + + @Test + public void pushPolicyUsingNoScope() throws Exception { + PepPushPolicyRequest pep = new PepPushPolicyRequest(); + pep.setPolicyName("Tarun"); + mockMvc.perform( + put("/pushPolicy") + .header("X-ECOMP-RequestID", + UUID.randomUUID().toString()) + .content(this.ObjectToJsonString(pep)) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isBadRequest()); + } + + @Test + public void pushPolicyUsingScopeinName() throws Exception { + PepPushPolicyRequest pep = new PepPushPolicyRequest(); + pep.setPolicyName("Test.PolicyName"); + mockMvc.perform( + put("/pushPolicy") + .header("X-ECOMP-RequestID", + UUID.randomUUID().toString()) + .content(this.ObjectToJsonString(pep)) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isBadRequest()); + } + + @Test + public void pushPolicyUsingPolicyType() throws Exception { + PepPushPolicyRequest pep = new PepPushPolicyRequest(); + pep.setPolicyName("Test.PolicyName"); + pep.setPolicyType("CONFIG BASE"); + mockMvc.perform( + put("/pushPolicy") + .header("X-ECOMP-RequestID", + UUID.randomUUID().toString()) + .content(this.ObjectToJsonString(pep)) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isBadRequest()); + } + + @Test + public void pushPolicyUsingErrorRequest() throws Exception { + PepPushPolicyRequest pep = new PepPushPolicyRequest(); + pep.setPolicyName("Test.PolicyName"); + pep.setPolicyType("CONFIG BASE"); + pep.setPdpGroup("default"); + mockMvc.perform( + put("/pushPolicy") + .header("X-ECOMP-RequestID", + UUID.randomUUID().toString()) + .content(this.ObjectToJsonString(pep)) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isBadRequest()); + } + + // Tests for Delete Policy API + @Test + public void deletePolicyUsingNoHeader() throws Exception { + DeletePolicyParameters pep = new DeletePolicyParameters(); + mockMvc.perform( + delete("/deletePolicy").content(this.ObjectToJsonString(pep)) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isBadRequest()); + } + + @Test + public void deletePolicyUsingErrorHeader() throws Exception { + DeletePolicyParameters pep = new DeletePolicyParameters(); + mockMvc.perform( + delete("/deletePolicy").header("X-ECOMP-RequestID", "ERROR123") + .content(this.ObjectToJsonString(pep)) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isBadRequest()); + } + + @Test + public void deletePolicyUsingErrorPolicyName() throws Exception { + DeletePolicyParameters pep = new DeletePolicyParameters(); + pep.setPolicyName("test"); + mockMvc.perform( + delete("/deletePolicy") + .header("X-ECOMP-RequestID", + UUID.randomUUID().toString()) + .content(this.ObjectToJsonString(pep)) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isBadRequest()); + } + + @Test + public void deletePolicyUsingErrorPolicyComponent() throws Exception { + DeletePolicyParameters pep = new DeletePolicyParameters(); + pep.setPolicyName("test"); + pep.setPolicyComponent("test"); + mockMvc.perform( + delete("/deletePolicy") + .header("X-ECOMP-RequestID", + UUID.randomUUID().toString()) + .content(this.ObjectToJsonString(pep)) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isBadRequest()); + } + + // Tests for CreatePolicy API + @Test + public void createPolicyUsingNoHeader() throws Exception { + PolicyParameters pep = new PolicyParameters(); + pep.setPolicyName("test"); + mockMvc.perform( + put("/createPolicy").content(this.ObjectToJsonString(pep)) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isBadRequest()); + } + + @Test + public void createPolicyUsingErrorHeader() throws Exception { + PolicyParameters pep = new PolicyParameters(); + pep.setPolicyName("test"); + mockMvc.perform( + put("/createPolicy").content(this.ObjectToJsonString(pep)) + .header("X-ECOMP-RequestID", "Error123") + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isBadRequest()); + } + + @Test + public void createPolicyUsingNullParameters() throws Exception { + PolicyParameters pep = new PolicyParameters(); + mockMvc.perform( + put("/createPolicy") + .content(this.ObjectToJsonString(pep)) + .header("X-ECOMP-RequestID", + UUID.randomUUID().toString()) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isBadRequest()); + } + + @Test + public void createPolicyUsingEmptyPolicyName() throws Exception { + PolicyParameters pep = new PolicyParameters(); + pep.setPolicyName(""); + mockMvc.perform( + put("/createPolicy") + .content(this.ObjectToJsonString(pep)) + .header("X-ECOMP-RequestID", + UUID.randomUUID().toString()) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isBadRequest()); + } + + // Tests for UpdatePolicy API + @Test + public void updatePolicyUsingNoHeader() throws Exception { + PolicyParameters pep = new PolicyParameters(); + pep.setPolicyName("test"); + mockMvc.perform( + put("/updatePolicy").content(this.ObjectToJsonString(pep)) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isBadRequest()); + } + + @Test + public void updatePolicyUsingErrorHeader() throws Exception { + PolicyParameters pep = new PolicyParameters(); + pep.setPolicyName("test"); + mockMvc.perform( + put("/updatePolicy").content(this.ObjectToJsonString(pep)) + .header("X-ECOMP-RequestID", "Error123") + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isBadRequest()); + } + + @Test + public void updatePolicyUsingNullParameters() throws Exception { + PolicyParameters pep = new PolicyParameters(); + mockMvc.perform( + put("/updatePolicy") + .content(this.ObjectToJsonString(pep)) + .header("X-ECOMP-RequestID", + UUID.randomUUID().toString()) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isBadRequest()); + } + + @Test + public void updatePolicyUsingEmptyPolicyName() throws Exception { + PolicyParameters pep = new PolicyParameters(); + pep.setPolicyName(""); + mockMvc.perform( + put("/updatePolicy") + .content(this.ObjectToJsonString(pep)) + .header("X-ECOMP-RequestID", + UUID.randomUUID().toString()) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isBadRequest()); + } + + // Tests for createConfig API + @Test + public void createConfigUsingNoHeader() throws Exception { + PepConfigPolicyRequest pep = new PepConfigPolicyRequest(); + pep.setPolicyName("test"); + mockMvc.perform( + put("/createConfig").content(this.ObjectToJsonString(pep)) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isBadRequest()); + } + + @Test + public void createConfigUsingErrorHeader() throws Exception { + PepConfigPolicyRequest pep = new PepConfigPolicyRequest(); + pep.setPolicyName("test"); + mockMvc.perform( + put("/createConfig").content(this.ObjectToJsonString(pep)) + .header("X-ECOMP-RequestID", "Error123") + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isBadRequest()); + } + + @Test + public void createConfigUsingNullParameters() throws Exception { + PepConfigPolicyRequest pep = new PepConfigPolicyRequest(); + mockMvc.perform( + put("/createConfig") + .content(this.ObjectToJsonString(pep)) + .header("X-ECOMP-RequestID", + UUID.randomUUID().toString()) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isBadRequest()); + } + + @Test + public void createConfigUsingEmptyPolicyName() throws Exception { + PepConfigPolicyRequest pep = new PepConfigPolicyRequest(); + pep.setPolicyName(""); + mockMvc.perform( + put("/createConfig") + .content(this.ObjectToJsonString(pep)) + .header("X-ECOMP-RequestID", + UUID.randomUUID().toString()) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isBadRequest()); + } + + @Test + public void createConfigUsingEmptyConfigName() throws Exception { + PepConfigPolicyRequest pep = new PepConfigPolicyRequest(); + pep.setPolicyName("test"); + pep.setEcompName("ecomp"); + mockMvc.perform( + put("/createConfig") + .content(this.ObjectToJsonString(pep)) + .header("X-ECOMP-RequestID", + UUID.randomUUID().toString()) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isBadRequest()); + } + + @Test + public void createConfigUsingEmptyPolicyScope() throws Exception { + PepConfigPolicyRequest pep = new PepConfigPolicyRequest(); + pep.setPolicyName("test"); + pep.setEcompName("ecomp"); + pep.setConfigName("config"); + mockMvc.perform( + put("/createConfig") + .content(this.ObjectToJsonString(pep)) + .header("X-ECOMP-RequestID", + UUID.randomUUID().toString()) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isBadRequest()); + } + + @Test + public void createConfigUsingErrorPolicyScope() throws Exception { + PepConfigPolicyRequest pep = new PepConfigPolicyRequest(); + pep.setPolicyName("test"); + pep.setEcompName("ecomp"); + pep.setConfigName("config"); + pep.setPolicyScope("test"); + mockMvc.perform( + put("/createConfig") + .content(this.ObjectToJsonString(pep)) + .header("X-ECOMP-RequestID", + UUID.randomUUID().toString()) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isBadRequest()); + } + + // Test API for updateConfig API + @Test + public void updateConfigUsingNoHeader() throws Exception { + PepConfigPolicyRequest pep = new PepConfigPolicyRequest(); + pep.setPolicyName("test"); + mockMvc.perform( + put("/updateConfig").content(this.ObjectToJsonString(pep)) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isBadRequest()); + } + + @Test + public void updateConfigUsingErrorHeader() throws Exception { + PepConfigPolicyRequest pep = new PepConfigPolicyRequest(); + pep.setPolicyName("test"); + mockMvc.perform( + put("/updateConfig").content(this.ObjectToJsonString(pep)) + .header("X-ECOMP-RequestID", "Error123") + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isBadRequest()); + } + + @Test + public void updateConfigUsingNullParameters() throws Exception { + PepConfigPolicyRequest pep = new PepConfigPolicyRequest(); + mockMvc.perform( + put("/updateConfig") + .content(this.ObjectToJsonString(pep)) + .header("X-ECOMP-RequestID", + UUID.randomUUID().toString()) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isBadRequest()); + } + + @Test + public void updateConfigUsingEmptyPolicyName() throws Exception { + PepConfigPolicyRequest pep = new PepConfigPolicyRequest(); + pep.setPolicyName(""); + mockMvc.perform( + put("/updateConfig") + .content(this.ObjectToJsonString(pep)) + .header("X-ECOMP-RequestID", + UUID.randomUUID().toString()) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isBadRequest()); + } + + @Test + public void updateConfigUsingEmptyConfigName() throws Exception { + PepConfigPolicyRequest pep = new PepConfigPolicyRequest(); + pep.setPolicyName("test"); + pep.setEcompName("ecomp"); + mockMvc.perform( + put("/updateConfig") + .content(this.ObjectToJsonString(pep)) + .header("X-ECOMP-RequestID", + UUID.randomUUID().toString()) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isBadRequest()); + } + + @Test + public void updateConfigUsingEmptyPolicyScope() throws Exception { + PepConfigPolicyRequest pep = new PepConfigPolicyRequest(); + pep.setPolicyName("test"); + pep.setEcompName("ecomp"); + pep.setConfigName("config"); + mockMvc.perform( + put("/updateConfig") + .content(this.ObjectToJsonString(pep)) + .header("X-ECOMP-RequestID", + UUID.randomUUID().toString()) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isBadRequest()); + } + + @Test + public void updateConfigUsingErrorPolicyScope() throws Exception { + PepConfigPolicyRequest pep = new PepConfigPolicyRequest(); + pep.setPolicyName("test"); + pep.setEcompName("ecomp"); + pep.setConfigName("config"); + pep.setPolicyScope("test"); + mockMvc.perform( + put("/updateConfig") + .content(this.ObjectToJsonString(pep)) + .header("X-ECOMP-RequestID", + UUID.randomUUID().toString()) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isBadRequest()); + } + + // Tests for createFirewallConfig API + @Test + public void createFirewallConfigUsingNoHeader() throws Exception { + PepConfigFirewallPolicyRequest pep = new PepConfigFirewallPolicyRequest(); + pep.setPolicyName("test"); + mockMvc.perform( + put("/createFirewallConfig").content( + this.ObjectToJsonString(pep)).contentType( + MediaType.APPLICATION_JSON)).andExpect( + status().isBadRequest()); + } + + @Test + public void createFirewallConfigUsingErrorHeader() throws Exception { + PepConfigFirewallPolicyRequest pep = new PepConfigFirewallPolicyRequest(); + pep.setPolicyName("test"); + mockMvc.perform( + put("/createFirewallConfig") + .header("X-ECOMP-RequestID", "Error123") + .content(this.ObjectToJsonString(pep)) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isBadRequest()); + } + + @Test + public void createFirewallConfigUsingNullParameters() throws Exception { + PepConfigFirewallPolicyRequest pep = new PepConfigFirewallPolicyRequest(); + mockMvc.perform( + put("/createFirewallConfig") + .header("X-ECOMP-RequestID", + UUID.randomUUID().toString()) + .content(this.ObjectToJsonString(pep)) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isBadRequest()); + } + + @Test + public void createFirewallConfigUsingEmptyPolicyName() throws Exception { + PepConfigFirewallPolicyRequest pep = new PepConfigFirewallPolicyRequest(); + pep.setPolicyName(""); + mockMvc.perform( + put("/createFirewallConfig") + .header("X-ECOMP-RequestID", + UUID.randomUUID().toString()) + .content(this.ObjectToJsonString(pep)) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isBadRequest()); + } + + @Test + public void createFirewallConfigUsingEmptyPolicyScope() throws Exception { + PepConfigFirewallPolicyRequest pep = new PepConfigFirewallPolicyRequest(); + pep.setPolicyName("test"); + pep.setFirewallJson(VALID_JSON); + pep.setPolicyScope(""); + mockMvc.perform( + put("/createFirewallConfig") + .header("X-ECOMP-RequestID", + UUID.randomUUID().toString()) + .content(this.ObjectToJsonString(pep)) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isBadRequest()); + } + + @Test + public void createFirewallConfigUsingInValidJSON() throws Exception { + PepConfigFirewallPolicyRequest pep = new PepConfigFirewallPolicyRequest(); + pep.setPolicyName("test"); + pep.setFirewallJson(INVALID_JSON); + pep.setPolicyScope("test"); + mockMvc.perform( + put("/createFirewallConfig") + .header("X-ECOMP-RequestID", + UUID.randomUUID().toString()) + .content(this.ObjectToJsonString(pep)) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isBadRequest()); + } + + @Test + public void createFirewallConfigUsingValidJSON() throws Exception { + PepConfigFirewallPolicyRequest pep = new PepConfigFirewallPolicyRequest(); + pep.setPolicyName("test"); + pep.setFirewallJson(VALID_JSON); + pep.setPolicyScope("test"); + mockMvc.perform( + put("/createFirewallConfig") + .header("X-ECOMP-RequestID", + UUID.randomUUID().toString()) + .header("ClientAuth", "Basic bTAzNzQyOlBvbGljeVIwY2sk") + .content(this.ObjectToJsonString(pep)) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isOk()); + } + + // Tests for updateFirewallConfig API + @Test + public void updateFirewallConfigUsingNoHeader() throws Exception { + PepConfigFirewallPolicyRequest pep = new PepConfigFirewallPolicyRequest(); + pep.setPolicyName("test"); + mockMvc.perform( + put("/updateFirewallConfig").content( + this.ObjectToJsonString(pep)).contentType( + MediaType.APPLICATION_JSON)).andExpect( + status().isBadRequest()); + } + + @Test + public void updateFirewallConfigUsingErrorHeader() throws Exception { + PepConfigFirewallPolicyRequest pep = new PepConfigFirewallPolicyRequest(); + pep.setPolicyName("test"); + mockMvc.perform( + put("/updateFirewallConfig") + .header("X-ECOMP-RequestID", "Error123") + .content(this.ObjectToJsonString(pep)) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isBadRequest()); + } + + @Test + public void updateFirewallConfigUsingNullParameters() throws Exception { + PepConfigFirewallPolicyRequest pep = new PepConfigFirewallPolicyRequest(); + mockMvc.perform( + put("/updateFirewallConfig") + .header("X-ECOMP-RequestID", + UUID.randomUUID().toString()) + .content(this.ObjectToJsonString(pep)) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isBadRequest()); + } + + @Test + public void updateFirewallConfigUsingEmptyPolicyName() throws Exception { + PepConfigFirewallPolicyRequest pep = new PepConfigFirewallPolicyRequest(); + pep.setPolicyName(""); + mockMvc.perform( + put("/updateFirewallConfig") + .header("X-ECOMP-RequestID", + UUID.randomUUID().toString()) + .content(this.ObjectToJsonString(pep)) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isBadRequest()); + } + + @Test + public void updateFirewallConfigUsingEmptyPolicyScope() throws Exception { + PepConfigFirewallPolicyRequest pep = new PepConfigFirewallPolicyRequest(); + pep.setPolicyName("test"); + pep.setFirewallJson(VALID_JSON); + pep.setPolicyScope(""); + mockMvc.perform( + put("/updateFirewallConfig") + .header("X-ECOMP-RequestID", + UUID.randomUUID().toString()) + .content(this.ObjectToJsonString(pep)) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isBadRequest()); + } + + @Test + public void updateFirewallConfigUsingInValidJSON() throws Exception { + PepConfigFirewallPolicyRequest pep = new PepConfigFirewallPolicyRequest(); + pep.setPolicyName("test"); + pep.setFirewallJson(INVALID_JSON); + pep.setPolicyScope("test"); + mockMvc.perform( + put("/updateFirewallConfig") + .header("X-ECOMP-RequestID", + UUID.randomUUID().toString()) + .content(this.ObjectToJsonString(pep)) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isBadRequest()); + } + + @Test + public void updateFirewallConfigUsingValidJSON() throws Exception { + PepConfigFirewallPolicyRequest pep = new PepConfigFirewallPolicyRequest(); + pep.setPolicyName("test"); + pep.setFirewallJson(VALID_JSON); + pep.setPolicyScope("test"); + mockMvc.perform( + put("/updateFirewallConfig") + .header("X-ECOMP-RequestID", + UUID.randomUUID().toString()) + .header("ClientAuth", "Basic bTAzNzQyOlBvbGljeVIwY2sk") + .content(this.ObjectToJsonString(pep)) + .contentType(MediaType.APPLICATION_JSON)).andExpect( + status().isOk()); + } + + //Health Check Tests + @Test + public void getCountTest() throws Exception { + mockMvc.perform(get("/count")) + .andExpect(status().isOk()); + } + + @Test + public void getPDPsTest() throws Exception { + mockMvc.perform(get("/pdps")) + .andExpect(status().isOk()); + } + + @Test + public void getPAPsTest() throws Exception { + mockMvc.perform(get("/paps")) + .andExpect(status().isOk()); + } + + // Helper Method to create JSONString from a given Object. + public String ObjectToJsonString(Object o) throws IOException { + ObjectMapper mapper = new ObjectMapper(); + return mapper.writeValueAsString(o); + } + +} diff --git a/README.md b/README.md new file mode 100644 index 000000000..fcec8f949 --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +This source repository contains the OpenECOMP Policy Engine code. The settings file needs to support the standard Maven repositories (e.g. central = http://repo1.maven.org/maven2/), and any proxy settings needed in your environment. In addition, this code is dependent upon the following OpenECOMP artifacts, which are not part of Policy: + + org.openecomp.ecompsdkos:ecompSDK-project:pom:3.3.9 + org.openecomp.ecompsdkos:ecompSDK-core:jar:3.3.9 + org.openecomp.ecompsdkos:ecompSDK-analytics:jar:3.3.9 + org.openecomp.ecompsdkos:ecompSDK-workflow:jar:3.3.9 + org.openecomp.ecompsdkos:ecompFW:jar:3.3.9 + +To build it using Maven 3, first build 'policy-common-modules' (which contains dependencies), and then run: mvn -Dmaven.test.failure.ignore=true clean install diff --git a/ecomp-sdk-app/.externalToolBuilders/org.eclipse.wst.jsdt.core.javascriptValidator.launch b/ecomp-sdk-app/.externalToolBuilders/org.eclipse.wst.jsdt.core.javascriptValidator.launch new file mode 100644 index 000000000..627021fb9 --- /dev/null +++ b/ecomp-sdk-app/.externalToolBuilders/org.eclipse.wst.jsdt.core.javascriptValidator.launch @@ -0,0 +1,7 @@ + + + + + + + diff --git a/ecomp-sdk-app/.gitignore b/ecomp-sdk-app/.gitignore new file mode 100644 index 000000000..64634ffb1 --- /dev/null +++ b/ecomp-sdk-app/.gitignore @@ -0,0 +1,2 @@ +/target +/doc/ diff --git a/ecomp-sdk-app/README.md b/ecomp-sdk-app/README.md new file mode 100644 index 000000000..f66bc3e8f --- /dev/null +++ b/ecomp-sdk-app/README.md @@ -0,0 +1,20 @@ +Ecomp SDK Web App +================= + +This is the ECOMP SDK web application. It includes java source files, +as well as CSS, JavaScript, JSP and HTML files. The java code depends +on the following ECOMP SDK libraries that are developed by the ECOMP +Portal: + +* ECOMP SDK Framework library +* ECOMP SDK Core library +* ECOMP SDK Analytics library +* ECOMP SDK Workflow library + +Use Apache Maven to build and package this webapp. + + +Framework for Java Application using Spring and Hibernate with Analytical Engine and Workflow + + +. \ No newline at end of file diff --git a/ecomp-sdk-app/db-scripts/EcompSdkDDLMySql_1610_Complete_OS.sql b/ecomp-sdk-app/db-scripts/EcompSdkDDLMySql_1610_Complete_OS.sql new file mode 100644 index 000000000..cd5126980 --- /dev/null +++ b/ecomp-sdk-app/db-scripts/EcompSdkDDLMySql_1610_Complete_OS.sql @@ -0,0 +1,1421 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +-- --------------------------------------------------------------------------------------------------------------- +-- This is for the 1610 Version of SDK database called ecomp_sdk for Open Source + +-- Note to : Database Admin, set the MySQL system variable called lower_case_table_names + +-- It can be set 3 different ways: +-- command-line options (Cmd-line), +-- options valid in configuration files (Option file), or +-- server system variables (System Var). + +-- It needs to be set to 1, then table names are stored in lowercase on disk and comparisons are not case sensitive. + +-- MySql/MariaDB Version compatibility information +-- $ mysql --version +-- mysql Ver 15.1 Distrib 5.5.35-MariaDB, for Linux (x86_64) using readline 5.1 + +-- bash-4.2$ mysql --version – cluster version +-- mysql Ver 15.1 Distrib 10.1.17-MariaDB, for Linux (x86_64) using readline 5.1 + +-- All versions newer or older than these DO NOT necessarily mean they are compatible. +-- ------------------------------------------------------------------------------------------------------------------ + +SET FOREIGN_KEY_CHECKS=1; + +CREATE DATABASE ecomp_sdk; + +USE ecomp_sdk; + +-- ---------- create table SECTION +-- +-- NAME: CR_FAVORITE_REPORTS; TYPE: TABLE +-- +create table cr_favorite_reports ( + USER_ID INTEGER NOT NULL, + REP_ID INTEGER NOT NULL +); + +-- +-- NAME: CR_FILEHIST_LOG; TYPE: TABLE +-- +create table cr_filehist_log ( + SCHEDULE_ID NUMERIC(11,0) NOT NULL, + URL CHARACTER VARYING(4000), + NOTES CHARACTER VARYING(3500), + RUN_TIME TIMESTAMP +); + +-- +-- NAME: CR_FOLDER; TYPE: TABLE +-- +create table cr_folder ( + FOLDER_ID INTEGER NOT NULL, + FOLDER_NAME CHARACTER VARYING(50) NOT NULL, + DESCR CHARACTER VARYING(500), + CREATE_ID INTEGER NOT NULL, + CREATE_DATE TIMESTAMP NOT NULL, + PARENT_FOLDER_ID INTEGER, + PUBLIC_YN CHARACTER VARYING(1) DEFAULT 'N' NOT NULL +); + +-- +-- NAME: CR_FOLDER_ACCESS; TYPE: TABLE +-- +create table cr_folder_access ( + FOLDER_ACCESS_ID NUMERIC(11,0) NOT NULL, + FOLDER_ID NUMERIC(11,0) NOT NULL, + ORDER_NO NUMERIC(11,0) NOT NULL, + ROLE_ID NUMERIC(11,0), + USER_ID NUMERIC(11,0), + READ_ONLY_YN CHARACTER VARYING(1) DEFAULT 'N' NOT NULL +); + +-- +-- NAME: CR_HIST_USER_MAP; TYPE: TABLE +-- +create table cr_hist_user_map ( + HIST_ID INT(11) NOT NULL, + USER_ID INT(11) NOT NULL +); + +-- +-- NAME: CR_LU_FILE_TYPE; TYPE: TABLE +-- +create table cr_lu_file_type ( + LOOKUP_ID NUMERIC(2,0) NOT NULL, + LOOKUP_DESCR CHARACTER VARYING(255) NOT NULL, + ACTIVE_YN CHARACTER(1) DEFAULT 'Y', + ERROR_CODE NUMERIC(11,0) +); + +-- +-- NAME: CR_RAPTOR_ACTION_IMG; TYPE: TABLE +-- +create table cr_raptor_action_img ( + IMAGE_ID CHARACTER VARYING(100) NOT NULL, + IMAGE_LOC CHARACTER VARYING(400) +); + +-- +-- NAME: CR_RAPTOR_PDF_IMG; TYPE: TABLE +-- +create table cr_raptor_pdf_img ( + IMAGE_ID CHARACTER VARYING(100) NOT NULL, + IMAGE_LOC CHARACTER VARYING(400) +); + +-- +-- NAME: CR_REMOTE_SCHEMA_INFO; TYPE: TABLE +-- +create table cr_remote_schema_info ( + SCHEMA_PREFIX CHARACTER VARYING(5) NOT NULL, + SCHEMA_DESC CHARACTER VARYING(75) NOT NULL, + DATASOURCE_TYPE CHARACTER VARYING(100) +); + +-- +-- NAME: CR_REPORT; TYPE: TABLE +-- +create table cr_report ( + REP_ID NUMERIC(11,0) NOT NULL, + TITLE CHARACTER VARYING(100) NOT NULL, + DESCR CHARACTER VARYING(255), + PUBLIC_YN CHARACTER VARYING(1) DEFAULT 'N' NOT NULL, + REPORT_XML TEXT, + CREATE_ID NUMERIC(11,0), + CREATE_DATE TIMESTAMP default now(), + MAINT_ID NUMERIC(11,0), + MAINT_DATE TIMESTAMP DEFAULT NOW(), + MENU_ID CHARACTER VARYING(500), + MENU_APPROVED_YN CHARACTER VARYING(1) DEFAULT 'N' NOT NULL, + OWNER_ID NUMERIC(11,0), + FOLDER_ID INTEGER DEFAULT 0, + DASHBOARD_TYPE_YN CHARACTER VARYING(1) DEFAULT 'N', + DASHBOARD_YN CHARACTER VARYING(1) DEFAULT 'N' +); + +-- +-- NAME: CR_REPORT_ACCESS; TYPE: TABLE +-- +create table cr_report_access ( + REP_ID NUMERIC(11,0) NOT NULL, + ORDER_NO NUMERIC(11,0) NOT NULL, + ROLE_ID NUMERIC(11,0), + USER_ID NUMERIC(11,0), + READ_ONLY_YN CHARACTER VARYING(1) DEFAULT 'N' NOT NULL +); + +-- +-- NAME: CR_REPORT_DWNLD_LOG; TYPE: TABLE +-- +create table cr_report_dwnld_log ( + USER_ID NUMERIC(11,0) NOT NULL, + REP_ID INTEGER NOT NULL, + FILE_NAME CHARACTER VARYING(100) NOT NULL, + DWNLD_START_TIME TIMESTAMP DEFAULT NOW() NOT NULL, + RECORD_READY_TIME TIMESTAMP DEFAULT NOW(), + FILTER_PARAMS CHARACTER VARYING(2000) +); + +-- +-- NAME: CR_REPORT_EMAIL_SENT_LOG; TYPE: TABLE +-- +create table cr_report_email_sent_log ( + LOG_ID INTEGER NOT NULL, + SCHEDULE_ID NUMERIC(11,0), + GEN_KEY CHARACTER VARYING(25) NOT NULL, + REP_ID NUMERIC(11,0) NOT NULL, + USER_ID NUMERIC(11,0), + SENT_DATE TIMESTAMP DEFAULT NOW(), + ACCESS_FLAG CHARACTER VARYING(1) DEFAULT 'Y' NOT NULL, + TOUCH_DATE TIMESTAMP DEFAULT NOW() +); + +-- +-- NAME: CR_REPORT_FILE_HISTORY; TYPE: TABLE +-- +create table cr_report_file_history ( + HIST_ID INT(11) NOT NULL, + SCHED_USER_ID NUMERIC(11,0) NOT NULL, + SCHEDULE_ID NUMERIC(11,0) NOT NULL, + USER_ID NUMERIC(11,0) NOT NULL, + REP_ID NUMERIC(11,0), + RUN_DATE TIMESTAMP, + RECURRENCE CHARACTER VARYING(50), + FILE_TYPE_ID NUMERIC(2,0), + FILE_NAME CHARACTER VARYING(80), + FILE_BLOB BLOB, + FILE_SIZE NUMERIC(11,0), + RAPTOR_URL CHARACTER VARYING(4000), + ERROR_YN CHARACTER(1) DEFAULT 'N', + ERROR_CODE NUMERIC(11,0), + DELETED_YN CHARACTER(1) DEFAULT 'N', + DELETED_BY NUMERIC(38,0) +); + +-- +-- NAME: CR_REPORT_LOG; TYPE: TABLE +-- +create table cr_report_log ( + REP_ID NUMERIC(11,0) NOT NULL, + LOG_TIME TIMESTAMP NOT NULL, + USER_ID NUMERIC(11,0) NOT NULL, + ACTION CHARACTER VARYING(2000) NOT NULL, + ACTION_VALUE CHARACTER VARYING(50), + FORM_FIELDS CHARACTER VARYING(4000) +); + +-- +-- NAME: CR_REPORT_SCHEDULE; TYPE: TABLE +-- +create table cr_report_schedule ( + SCHEDULE_ID NUMERIC(11,0) NOT NULL, + SCHED_USER_ID NUMERIC(11,0) NOT NULL, + REP_ID NUMERIC(11,0) NOT NULL, + ENABLED_YN CHARACTER VARYING(1) NOT NULL, + START_DATE TIMESTAMP DEFAULT NOW(), + END_DATE TIMESTAMP DEFAULT NOW(), + RUN_DATE TIMESTAMP DEFAULT NOW(), + RECURRENCE CHARACTER VARYING(50), + CONDITIONAL_YN CHARACTER VARYING(1) NOT NULL, + CONDITION_SQL CHARACTER VARYING(4000), + NOTIFY_TYPE INTEGER DEFAULT 0, + MAX_ROW INTEGER DEFAULT 1000, + INITIAL_FORMFIELDS CHARACTER VARYING(3500), + PROCESSED_FORMFIELDS CHARACTER VARYING(3500), + FORMFIELDS CHARACTER VARYING(3500), + CONDITION_LARGE_SQL TEXT, + ENCRYPT_YN CHARACTER(1) DEFAULT 'N', + ATTACHMENT_YN CHARACTER(1) DEFAULT 'Y' +); + +-- +-- NAME: CR_REPORT_SCHEDULE_USERS; TYPE: TABLE +-- +create table cr_report_schedule_users ( + SCHEDULE_ID NUMERIC(11,0) NOT NULL, + REP_ID NUMERIC(11,0) NOT NULL, + USER_ID NUMERIC(11,0) NOT NULL, + ROLE_ID NUMERIC(11,0), + ORDER_NO NUMERIC(11,0) NOT NULL +); + +-- +-- NAME: CR_REPORT_TEMPLATE_MAP; TYPE: TABLE +-- +create table cr_report_template_map ( + REPORT_ID INTEGER NOT NULL, + TEMPLATE_FILE CHARACTER VARYING(200) +); + +-- +-- NAME: CR_SCHEDULE_ACTIVITY_LOG; TYPE: TABLE +-- +create table cr_schedule_activity_log ( + SCHEDULE_ID NUMERIC(11,0) NOT NULL, + URL CHARACTER VARYING(4000), + NOTES CHARACTER VARYING(2000), + RUN_TIME TIMESTAMP +); + +-- +-- NAME: CR_TABLE_JOIN; TYPE: TABLE +-- +create table cr_table_join ( + SRC_TABLE_NAME CHARACTER VARYING(30) NOT NULL, + DEST_TABLE_NAME CHARACTER VARYING(30) NOT NULL, + JOIN_EXPR CHARACTER VARYING(500) NOT NULL +); + +-- +-- NAME: CR_TABLE_ROLE; TYPE: TABLE +-- +create table cr_table_role ( + TABLE_NAME CHARACTER VARYING(30) NOT NULL, + ROLE_ID NUMERIC(11,0) NOT NULL +); + +-- +-- NAME: CR_TABLE_SOURCE; TYPE: TABLE +-- +create table cr_table_source ( + TABLE_NAME CHARACTER VARYING(30) NOT NULL, + DISPLAY_NAME CHARACTER VARYING(30) NOT NULL, + PK_FIELDS CHARACTER VARYING(200), + WEB_VIEW_ACTION CHARACTER VARYING(50), + LARGE_DATA_SOURCE_YN CHARACTER VARYING(1) DEFAULT 'N' NOT NULL, + FILTER_SQL CHARACTER VARYING(4000), + SOURCE_DB CHARACTER VARYING(50) +); + +-- +-- NAME: FN_LU_TIMEZONE; TYPE: TABLE +-- +create table fn_lu_timezone ( + TIMEZONE_ID INT(11) NOT NULL, + TIMEZONE_NAME CHARACTER VARYING(100) NOT NULL, + TIMEZONE_VALUE CHARACTER VARYING(100) NOT NULL +); + +create table fn_user ( + USER_ID INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, + ORG_ID INT(11), + MANAGER_ID INT(11), + FIRST_NAME CHARACTER VARYING(25), + MIDDLE_NAME CHARACTER VARYING(25), + LAST_NAME CHARACTER VARYING(25), + PHONE CHARACTER VARYING(25), + FAX CHARACTER VARYING(25), + CELLULAR CHARACTER VARYING(25), + EMAIL CHARACTER VARYING(50), + ADDRESS_ID NUMERIC(11,0), + ALERT_METHOD_CD CHARACTER VARYING(10), + HRID CHARACTER VARYING(20), + ORG_USER_ID CHARACTER VARYING(20), + ORG_CODE CHARACTER VARYING(30), + LOGIN_ID CHARACTER VARYING(25), + LOGIN_PWD CHARACTER VARYING(25), + LAST_LOGIN_DATE TIMESTAMP, + ACTIVE_YN CHARACTER VARYING(1) DEFAULT 'Y' NOT NULL, + CREATED_ID INT(11), + CREATED_DATE TIMESTAMP DEFAULT NOW(), + MODIFIED_ID INT(11), + MODIFIED_DATE TIMESTAMP default now(), + IS_INTERNAL_YN CHARACTER(1) DEFAULT 'N' NOT NULL, + ADDRESS_LINE_1 CHARACTER VARYING(100), + ADDRESS_LINE_2 CHARACTER VARYING(100), + CITY CHARACTER VARYING(50), + STATE_CD CHARACTER VARYING(3), + ZIP_CODE CHARACTER VARYING(11), + COUNTRY_CD CHARACTER VARYING(3), + LOCATION_CLLI CHARACTER VARYING(8), + ORG_MANAGER_USERID CHARACTER VARYING(20), + COMPANY CHARACTER VARYING(100), + DEPARTMENT_NAME CHARACTER VARYING(100), + JOB_TITLE CHARACTER VARYING(100), + TIMEZONE INT(11), + DEPARTMENT CHARACTER VARYING(25), + BUSINESS_UNIT CHARACTER VARYING(25), + BUSINESS_UNIT_NAME CHARACTER VARYING(100), + COST_CENTER CHARACTER VARYING(25), + FIN_LOC_CODE CHARACTER VARYING(10), + SILO_STATUS CHARACTER VARYING(10) +); + +-- +-- NAME: FN_ROLE; TYPE: TABLE +-- +create table fn_role ( + ROLE_ID INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, + ROLE_NAME CHARACTER VARYING(50) NOT NULL, + ACTIVE_YN CHARACTER VARYING(1) DEFAULT 'Y' NOT NULL, + PRIORITY NUMERIC(4,0) +); + +-- +-- NAME: FN_AUDIT_ACTION; TYPE: TABLE +-- +create table fn_audit_action ( + AUDIT_ACTION_ID INTEGER NOT NULL, + CLASS_NAME CHARACTER VARYING(500) NOT NULL, + METHOD_NAME CHARACTER VARYING(50) NOT NULL, + AUDIT_ACTION_CD CHARACTER VARYING(20) NOT NULL, + AUDIT_ACTION_DESC CHARACTER VARYING(200), + ACTIVE_YN CHARACTER VARYING(1) +); + +-- +-- NAME: FN_AUDIT_ACTION_LOG; TYPE: TABLE +-- +create table fn_audit_action_log ( + AUDIT_LOG_ID INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, + AUDIT_ACTION_CD CHARACTER VARYING(200), + ACTION_TIME TIMESTAMP, + USER_ID NUMERIC(11,0), + CLASS_NAME CHARACTER VARYING(100), + METHOD_NAME CHARACTER VARYING(50), + SUCCESS_MSG CHARACTER VARYING(20), + ERROR_MSG CHARACTER VARYING(500) +); + +-- +-- NAME: FN_LU_ACTIVITY; TYPE: TABLE +-- +create table fn_lu_activity ( + ACTIVITY_CD CHARACTER VARYING(50) NOT NULL PRIMARY KEY, + ACTIVITY CHARACTER VARYING(50) NOT NULL +); + +-- +-- NAME: FN_AUDIT_LOG; TYPE: TABLE +-- +create table fn_audit_log ( + LOG_ID INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, + USER_ID INT(11) NOT NULL, + ACTIVITY_CD CHARACTER VARYING(50) NOT NULL, + AUDIT_DATE TIMESTAMP DEFAULT NOW() NOT NULL, + COMMENTS CHARACTER VARYING(1000), + AFFECTED_RECORD_ID_BK CHARACTER VARYING(500), + AFFECTED_RECORD_ID CHARACTER VARYING(4000), + CONSTRAINT FK_FN_AUDIT_REF_209_FN_USER FOREIGN KEY (USER_ID) REFERENCES FN_USER(USER_ID) +); + +-- +-- NAME: FN_BROADCAST_MESSAGE; TYPE: TABLE +-- +create table fn_broadcast_message ( + MESSAGE_ID INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, + MESSAGE_TEXT CHARACTER VARYING(1000) NOT NULL, + MESSAGE_LOCATION_ID NUMERIC(11,0) NOT NULL, + BROADCAST_START_DATE TIMESTAMP NOT NULL DEFAULT NOW(), + BROADCAST_END_DATE TIMESTAMP NOT NULL DEFAULT NOW(), + ACTIVE_YN CHARACTER(1) DEFAULT 'Y' NOT NULL, + SORT_ORDER NUMERIC(4,0) NOT NULL, + BROADCAST_SITE_CD CHARACTER VARYING(50) +); + +-- +-- NAME: FN_CHAT_LOGS; TYPE: TABLE +-- +create table fn_chat_logs ( + CHAT_LOG_ID INTEGER NOT NULL, + CHAT_ROOM_ID INTEGER, + USER_ID INTEGER, + MESSAGE CHARACTER VARYING(1000), + MESSAGE_DATE_TIME TIMESTAMP +); + +-- +-- NAME: FN_CHAT_ROOM; TYPE: TABLE +-- +create table fn_chat_room ( + CHAT_ROOM_ID INTEGER NOT NULL, + NAME CHARACTER VARYING(50) NOT NULL, + DESCRIPTION CHARACTER VARYING(500), + OWNER_ID INTEGER, + CREATED_DATE TIMESTAMP DEFAULT NOW(), + UPDATED_DATE TIMESTAMP DEFAULT NOW() +); + +-- +-- NAME: FN_CHAT_USERS; TYPE: TABLE +-- +create table fn_chat_users ( + CHAT_ROOM_ID INTEGER, + USER_ID INTEGER, + LAST_ACTIVITY_DATE_TIME TIMESTAMP, + CHAT_STATUS CHARACTER VARYING(20), + ID INTEGER NOT NULL +); + +-- +-- NAME: FN_DATASOURCE; TYPE: TABLE +-- +create table fn_datasource ( + ID INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, + NAME CHARACTER VARYING(50), + DRIVER_NAME CHARACTER VARYING(256), + SERVER CHARACTER VARYING(256), + PORT INTEGER, + USER_NAME CHARACTER VARYING(256), + PASSWORD CHARACTER VARYING(256), + URL CHARACTER VARYING(256), + MIN_POOL_SIZE INTEGER, + MAX_POOL_SIZE INTEGER, + ADAPTER_ID INTEGER, + DS_TYPE CHARACTER VARYING(20) +); + +-- +-- NAME: FN_FUNCTION; TYPE: TABLE +-- +create table fn_function ( + FUNCTION_CD CHARACTER VARYING(30) NOT NULL PRIMARY KEY, + FUNCTION_NAME CHARACTER VARYING(50) NOT NULL +); + +-- +-- NAME: FN_LU_ALERT_METHOD; TYPE: TABLE +-- +create table fn_lu_alert_method ( + ALERT_METHOD_CD CHARACTER VARYING(10) NOT NULL, + ALERT_METHOD CHARACTER VARYING(50) NOT NULL +); + +-- +-- NAME: FN_LU_BROADCAST_SITE; TYPE: TABLE +-- +create table fn_lu_broadcast_site ( + BROADCAST_SITE_CD CHARACTER VARYING(50) NOT NULL, + BROADCAST_SITE_DESCR CHARACTER VARYING(100) +); +-- +-- NAME: FN_LU_MENU_SET; TYPE: TABLE +-- +create table fn_lu_menu_set ( + MENU_SET_CD CHARACTER VARYING(10) NOT NULL PRIMARY KEY, + MENU_SET_NAME CHARACTER VARYING(50) NOT NULL +); + +-- +-- NAME: FN_LU_PRIORITY; TYPE: TABLE +-- +create table fn_lu_priority ( + PRIORITY_ID NUMERIC(11,0) NOT NULL, + PRIORITY CHARACTER VARYING(50) NOT NULL, + ACTIVE_YN CHARACTER(1) NOT NULL, + SORT_ORDER NUMERIC(5,0) +); + +-- +-- NAME: FN_LU_ROLE_TYPE; TYPE: TABLE +-- +create table fn_lu_role_type ( + ROLE_TYPE_ID NUMERIC(11,0) NOT NULL, + ROLE_TYPE CHARACTER VARYING(50) NOT NULL +); +-- +-- NAME: FN_LU_TAB_SET; TYPE: TABLE +-- +create table fn_lu_tab_set ( + TAB_SET_CD CHARACTER VARYING(30) NOT NULL, + TAB_SET_NAME CHARACTER VARYING(50) NOT NULL +); + +-- +-- NAME: FN_MENU; TYPE: TABLE +-- +create table fn_menu ( + MENU_ID INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, + LABEL CHARACTER VARYING(100), + PARENT_ID INT(11), + SORT_ORDER NUMERIC(4,0), + ACTION CHARACTER VARYING(200), + FUNCTION_CD CHARACTER VARYING(30), + ACTIVE_YN CHARACTER VARYING(1) DEFAULT 'Y' NOT NULL, + SERVLET CHARACTER VARYING(50), + QUERY_STRING CHARACTER VARYING(200), + EXTERNAL_URL CHARACTER VARYING(200), + TARGET CHARACTER VARYING(25), + MENU_SET_CD CHARACTER VARYING(10) DEFAULT 'APP', + SEPARATOR_YN CHARACTER(1) DEFAULT 'N', + IMAGE_SRC CHARACTER VARYING(100), + CONSTRAINT FK_FN_MENU_REF_196_FN_MENU FOREIGN KEY (PARENT_ID) REFERENCES FN_MENU(MENU_ID), + CONSTRAINT FK_FN_MENU_MENU_SET_CD FOREIGN KEY (MENU_SET_CD) REFERENCES FN_LU_MENU_SET(MENU_SET_CD), + CONSTRAINT FK_FN_MENU_REF_223_FN_FUNCT FOREIGN KEY (FUNCTION_CD) REFERENCES FN_FUNCTION(FUNCTION_CD) +); + +-- +-- NAME: FN_ORG; TYPE: TABLE +-- +create table fn_org ( + ORG_ID INT(11) NOT NULL, + ORG_NAME CHARACTER VARYING(50) NOT NULL, + ACCESS_CD CHARACTER VARYING(10) +); + +-- +-- NAME: FN_RESTRICTED_URL; TYPE: TABLE +-- +create table fn_restricted_url ( + RESTRICTED_URL CHARACTER VARYING(250) NOT NULL, + FUNCTION_CD CHARACTER VARYING(30) NOT NULL +); + +-- +-- NAME: FN_ROLE_COMPOSITE; TYPE: TABLE +-- +create table fn_role_composite ( + PARENT_ROLE_ID INT(11) NOT NULL, + CHILD_ROLE_ID INT(11) NOT NULL, + CONSTRAINT FK_FN_ROLE_COMPOSITE_CHILD FOREIGN KEY (CHILD_ROLE_ID) REFERENCES FN_ROLE(ROLE_ID), + CONSTRAINT FK_FN_ROLE_COMPOSITE_PARENT FOREIGN KEY (PARENT_ROLE_ID) REFERENCES FN_ROLE(ROLE_ID) +); + +-- +-- NAME: FN_ROLE_FUNCTION; TYPE: TABLE +-- +create table fn_role_function ( + ROLE_ID INT(11) NOT NULL, + FUNCTION_CD CHARACTER VARYING(30) NOT NULL, + CONSTRAINT FK_FN_ROLE__REF_198_FN_ROLE FOREIGN KEY (ROLE_ID) REFERENCES FN_ROLE(ROLE_ID) +); + +-- +-- NAME: FN_TAB; TYPE: TABLE +-- +create table fn_tab ( + TAB_CD CHARACTER VARYING(30) NOT NULL, + TAB_NAME CHARACTER VARYING(50) NOT NULL, + TAB_DESCR CHARACTER VARYING(100), + ACTION CHARACTER VARYING(100) NOT NULL, + FUNCTION_CD CHARACTER VARYING(30) NOT NULL, + ACTIVE_YN CHARACTER(1) NOT NULL, + SORT_ORDER NUMERIC(11,0) NOT NULL, + PARENT_TAB_CD CHARACTER VARYING(30), + TAB_SET_CD CHARACTER VARYING(30) +); + +-- +-- NAME: FN_TAB_SELECTED; TYPE: TABLE +-- +create table fn_tab_selected ( + SELECTED_TAB_CD CHARACTER VARYING(30) NOT NULL, + TAB_URI CHARACTER VARYING(40) NOT NULL +); + +-- +-- NAME: FN_USER_PSEUDO_ROLE; TYPE: TABLE +-- +create table fn_user_pseudo_role ( + PSEUDO_ROLE_ID INT(11) NOT NULL, + USER_ID INT(11) NOT NULL +); + +-- +-- NAME: FN_USER_ROLE; TYPE: TABLE +-- +create table fn_user_role ( + USER_ID INT(10) NOT NULL, + ROLE_ID INT(10) NOT NULL, + PRIORITY NUMERIC(4,0), + APP_ID INT(11) DEFAULT 1, + CONSTRAINT FK_FN_USER__REF_172_FN_USER FOREIGN KEY (USER_ID) REFERENCES FN_USER(USER_ID), + CONSTRAINT FK_FN_USER__REF_175_FN_ROLE FOREIGN KEY (ROLE_ID) REFERENCES FN_ROLE(ROLE_ID) +); +-- +-- NAME: SCHEMA_INFO; TYPE: TABLE +-- +create table schema_info ( + SCHEMA_ID CHARACTER VARYING(25) NOT NULL, + SCHEMA_DESC CHARACTER VARYING(75) NOT NULL, + DATASOURCE_TYPE CHARACTER VARYING(100), + CONNECTION_URL VARCHAR(200) NOT NULL, + USER_NAME VARCHAR(45) NOT NULL, + PASSWORD VARCHAR(45) NULL DEFAULT NULL, + DRIVER_CLASS VARCHAR(100) NOT NULL, + MIN_POOL_SIZE INT NOT NULL, + MAX_POOL_SIZE INT NOT NULL, + IDLE_CONNECTION_TEST_PERIOD INT NOT NULL + +); + +-- ---------------------------------------------------------- +-- NAME: FN_APP; TYPE: TABLE +-- ---------------------------------------------------------- +create table fn_app ( + APP_ID int(11) PRIMARY KEY NOT NULL AUTO_INCREMENT, + APP_NAME varchar(100) NOT NULL DEFAULT '?', + APP_IMAGE_URL varchar(256) DEFAULT NULL, + APP_DESCRIPTION varchar(512) DEFAULT NULL, + APP_NOTES varchar(4096) DEFAULT NULL, + APP_URL varchar(256) DEFAULT NULL, + APP_ALTERNATE_URL varchar(256) DEFAULT NULL, + APP_REST_ENDPOINT varchar(2000) DEFAULT NULL, + ML_APP_NAME varchar(50) NOT NULL DEFAULT '?', + ML_APP_ADMIN_ID varchar(7) NOT NULL DEFAULT '?', + MOTS_ID int(11) DEFAULT NULL, + APP_PASSWORD varchar(256) NOT NULL DEFAULT '?', + OPEN char(1) DEFAULT 'N', + ENABLED char(1) DEFAULT 'Y', + THUMBNAIL mediumblob, + APP_USERNAME varchar(50), + UEB_KEY VARCHAR(256) DEFAULT NULL, + UEB_SECRET VARCHAR(256) DEFAULT NULL, + UEB_TOPIC_NAME VARCHAR(256) DEFAULT NULL + +); + +-- ---------------------------------------------------------- +-- NAME: FN_FN_WORKFLOW; TYPE: TABLE +-- ---------------------------------------------------------- +create table fn_workflow ( + id mediumint(9) NOT NULL AUTO_INCREMENT, + name varchar(20) NOT NULL, + description varchar(500) DEFAULT NULL, + run_link varchar(300) DEFAULT NULL, + suspend_link varchar(300) DEFAULT NULL, + modified_link varchar(300) DEFAULT NULL, + active_yn varchar(300) DEFAULT NULL, + created varchar(300) DEFAULT NULL, + created_by int(11) DEFAULT NULL, + modified varchar(300) DEFAULT NULL, + modified_by int(11) DEFAULT NULL, + workflow_key varchar(50) DEFAULT NULL, + PRIMARY KEY (id), + UNIQUE KEY name (name) +); + +-- ---------------------------------------------------------- +-- NAME: FN_SCHEDULE_WORKFLOWS; TYPE: TABLE +-- ---------------------------------------------------------- +create table fn_schedule_workflows ( + id_schedule_workflows bigint(25) PRIMARY KEY NOT NULL AUTO_INCREMENT, + workflow_server_url varchar(45) DEFAULT NULL, + workflow_key varchar(45) NOT NULL, + workflow_arguments varchar(45) DEFAULT NULL, + startDateTimeCron varchar(45) DEFAULT NULL, + endDateTime TIMESTAMP DEFAULT NOW(), + start_date_time TIMESTAMP DEFAULT NOW(), + recurrence varchar(45) DEFAULT NULL + ); + +-- For demo reporting application add : demo_bar_chart, demo_bar_chart_inter, demo_line_chart, demo_pie_chart and demo_util_chart +-- demo_scatter_chart, demo_scatter_plot +-- ---------------------------------------------------------- +-- NAME: DEMO_BAR_CHART; TYPE: TABLE +-- ---------------------------------------------------------- +create table demo_bar_chart ( + label varchar(20), + value numeric(25,15) + ); + +-- ---------------------------------------------------------- +-- NAME: DEMO_BAR_CHART_INTER; TYPE: TABLE +-- ---------------------------------------------------------- +create table demo_bar_chart_inter ( + spam_date date, + num_rpt_sources numeric(10,0), + num_det_sources numeric(10,0) + ); + +-- ---------------------------------------------------------- +-- NAME: DEMO_LINE_CHART; TYPE: TABLE +-- ---------------------------------------------------------- +create table demo_line_chart ( + series varchar(20), + log_date date, + data_value numeric(10,5) + ); + +-- ---------------------------------------------------------- +-- NAME: DEMO_PIE_CHART; TYPE: TABLE +-- ---------------------------------------------------------- +create table demo_pie_chart ( + legend varchar(20), + data_value numeric(10,5) + ); + +-- ---------------------------------------------------------- +-- NAME: DEMO_UTIL_CHART; TYPE: TABLE +-- ---------------------------------------------------------- +create table demo_util_chart ( + traffic_date date, + util_perc numeric(10,5) + ); + +-- ---------------------------------------------------------- +-- NAME: DEMO_SCATTER_CHART; TYPE: TABLE +-- ---------------------------------------------------------- +create table demo_scatter_chart ( + rainfall numeric(10,2), + key_value varchar(20), + measurements numeric(10,2) +); + +-- ---------------------------------------------------------- +-- NAME: DEMO_SCATTER_PLOT; TYPE: TABLE +-- ---------------------------------------------------------- +create table demo_scatter_plot +( + SERIES VARCHAR(20), + VALUEX numeric(25,15), + VALUEY numeric(25,15) +); + +-- ---------------------------------------------------------- +-- NAME: FN_QZ_JOB_DETAILS; TYPE: TABLE +-- ---------------------------------------------------------- +create table fn_qz_job_details ( +SCHED_NAME VARCHAR(120) NOT NULL, +JOB_NAME VARCHAR(200) NOT NULL, +JOB_GROUP VARCHAR(200) NOT NULL, +DESCRIPTION VARCHAR(250) NULL, +JOB_CLASS_NAME VARCHAR(250) NOT NULL, +IS_DURABLE VARCHAR(1) NOT NULL, +IS_NONCONCURRENT VARCHAR(1) NOT NULL, +IS_UPDATE_DATA VARCHAR(1) NOT NULL, +REQUESTS_RECOVERY VARCHAR(1) NOT NULL, +JOB_DATA BLOB NULL, +PRIMARY KEY (SCHED_NAME,JOB_NAME,JOB_GROUP) +); + +-- ---------------------------------------------------------- +-- NAME: FN_QZ_TRIGGERS; TYPE: TABLE +-- ---------------------------------------------------------- +create table fn_qz_triggers ( +SCHED_NAME VARCHAR(120) NOT NULL, +TRIGGER_NAME VARCHAR(200) NOT NULL, +TRIGGER_GROUP VARCHAR(200) NOT NULL, +JOB_NAME VARCHAR(200) NOT NULL, +JOB_GROUP VARCHAR(200) NOT NULL, +DESCRIPTION VARCHAR(250) NULL, +NEXT_FIRE_TIME BIGINT(13) NULL, +PREV_FIRE_TIME BIGINT(13) NULL, +PRIORITY INTEGER NULL, +TRIGGER_STATE VARCHAR(16) NOT NULL, +TRIGGER_TYPE VARCHAR(8) NOT NULL, +START_TIME BIGINT(13) NOT NULL, +END_TIME BIGINT(13) NULL, +CALENDAR_NAME VARCHAR(200) NULL, +MISFIRE_INSTR SMALLINT(2) NULL, +JOB_DATA BLOB NULL, +PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP), +FOREIGN KEY (SCHED_NAME,JOB_NAME,JOB_GROUP) +REFERENCES FN_QZ_JOB_DETAILS(SCHED_NAME,JOB_NAME,JOB_GROUP) +); + +-- ---------------------------------------------------------- +-- NAME: FN_QZ_SIMPLE_TRIGGERS; TYPE: TABLE +-- ---------------------------------------------------------- +create table fn_qz_simple_triggers ( +SCHED_NAME VARCHAR(120) NOT NULL, +TRIGGER_NAME VARCHAR(200) NOT NULL, +TRIGGER_GROUP VARCHAR(200) NOT NULL, +REPEAT_COUNT BIGINT(7) NOT NULL, +REPEAT_INTERVAL BIGINT(12) NOT NULL, +TIMES_TRIGGERED BIGINT(10) NOT NULL, +PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP), +FOREIGN KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP) +REFERENCES FN_QZ_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP) +); + +-- ---------------------------------------------------------- +-- NAME: FN_QZ_CRON_TRIGGERS; TYPE: TABLE +-- ---------------------------------------------------------- +create table fn_qz_cron_triggers ( +SCHED_NAME VARCHAR(120) NOT NULL, +TRIGGER_NAME VARCHAR(200) NOT NULL, +TRIGGER_GROUP VARCHAR(200) NOT NULL, +CRON_EXPRESSION VARCHAR(120) NOT NULL, +TIME_ZONE_ID VARCHAR(80), +PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP), +FOREIGN KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP) +REFERENCES FN_QZ_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP) +); + +-- ---------------------------------------------------------- +-- NAME: FN_QZ_SIMPROP_TRIGGERS; TYPE: TABLE +-- ---------------------------------------------------------- +create table fn_qz_simprop_triggers + ( + SCHED_NAME VARCHAR(120) NOT NULL, + TRIGGER_NAME VARCHAR(200) NOT NULL, + TRIGGER_GROUP VARCHAR(200) NOT NULL, + STR_PROP_1 VARCHAR(512) NULL, + STR_PROP_2 VARCHAR(512) NULL, + STR_PROP_3 VARCHAR(512) NULL, + INT_PROP_1 INT NULL, + INT_PROP_2 INT NULL, + LONG_PROP_1 BIGINT NULL, + LONG_PROP_2 BIGINT NULL, + DEC_PROP_1 NUMERIC(13,4) NULL, + DEC_PROP_2 NUMERIC(13,4) NULL, + BOOL_PROP_1 VARCHAR(1) NULL, + BOOL_PROP_2 VARCHAR(1) NULL, + PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP), + FOREIGN KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP) + REFERENCES FN_QZ_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP) +); + +-- ---------------------------------------------------------- +-- NAME: FN_QZ_BLOB_TRIGGERS; TYPE: TABLE +-- ---------------------------------------------------------- +create table fn_qz_blob_triggers ( +SCHED_NAME VARCHAR(120) NOT NULL, +TRIGGER_NAME VARCHAR(200) NOT NULL, +TRIGGER_GROUP VARCHAR(200) NOT NULL, +BLOB_DATA BLOB NULL, +PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP), +INDEX (SCHED_NAME,TRIGGER_NAME, TRIGGER_GROUP), +FOREIGN KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP) +REFERENCES FN_QZ_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP) +); + +-- ---------------------------------------------------------- +-- NAME: FN_QZ_CALENDARS; TYPE: TABLE +-- ---------------------------------------------------------- +create table fn_qz_calendars ( +SCHED_NAME VARCHAR(120) NOT NULL, +CALENDAR_NAME VARCHAR(200) NOT NULL, +CALENDAR BLOB NOT NULL, +PRIMARY KEY (SCHED_NAME,CALENDAR_NAME) +); + +-- ---------------------------------------------------------- +-- NAME: FN_QZ_PAUSED_TRIGGER_GRPS; TYPE: TABLE +-- ---------------------------------------------------------- +create table fn_qz_paused_trigger_grps ( +SCHED_NAME VARCHAR(120) NOT NULL, +TRIGGER_GROUP VARCHAR(200) NOT NULL, +PRIMARY KEY (SCHED_NAME,TRIGGER_GROUP) +); + +-- ---------------------------------------------------------- +-- NAME: FN_QZ_FIRED_TRIGGERS; TYPE: TABLE +-- ---------------------------------------------------------- +create table fn_qz_fired_triggers ( +SCHED_NAME VARCHAR(120) NOT NULL, +ENTRY_ID VARCHAR(95) NOT NULL, +TRIGGER_NAME VARCHAR(200) NOT NULL, +TRIGGER_GROUP VARCHAR(200) NOT NULL, +INSTANCE_NAME VARCHAR(200) NOT NULL, +FIRED_TIME BIGINT(13) NOT NULL, +SCHED_TIME BIGINT(13) NOT NULL, +PRIORITY INTEGER NOT NULL, +STATE VARCHAR(16) NOT NULL, +JOB_NAME VARCHAR(200) NULL, +JOB_GROUP VARCHAR(200) NULL, +IS_NONCONCURRENT VARCHAR(1) NULL, +REQUESTS_RECOVERY VARCHAR(1) NULL, +PRIMARY KEY (SCHED_NAME,ENTRY_ID) +); + +-- ---------------------------------------------------------- +-- NAME: FN_QZ_SCHEDULER_STATE; TYPE: TABLE +-- ---------------------------------------------------------- +create table fn_qz_scheduler_state ( +SCHED_NAME VARCHAR(120) NOT NULL, +INSTANCE_NAME VARCHAR(200) NOT NULL, +LAST_CHECKIN_TIME BIGINT(13) NOT NULL, +CHECKIN_INTERVAL BIGINT(13) NOT NULL, +PRIMARY KEY (SCHED_NAME,INSTANCE_NAME) +); + +-- ---------------------------------------------------------- +-- NAME: FN_QZ_LOCKS; TYPE: TABLE +-- ---------------------------------------------------------- +create table fn_qz_locks ( +SCHED_NAME VARCHAR(120) NOT NULL, +LOCK_NAME VARCHAR(40) NOT NULL, +PRIMARY KEY (SCHED_NAME,LOCK_NAME) +); + +-- +-- name: rcloudinvocation; type: table +-- +create table rcloudinvocation ( + id varchar(128) not null primary key, + created timestamp not null, + userinfo varchar(2048) not null, + notebookid varchar(128) not null, + parameters varchar(2048) default null, + tokenreaddate timestamp null +); + +-- +-- name: rcloudnotebook; type: table +-- +create table rcloudnotebook ( + notebookname varchar(128) not null primary key, + notebookid varchar(128) not null +); + +-- +-- Name: fn_lu_message_location; Type: TABLE +-- + +CREATE TABLE fn_lu_message_location ( + message_location_id numeric(11,0) NOT NULL, + message_location_descr character varying(30) NOT NULL +); + +-- ------------------ CREATE VIEW SECTION +-- +-- NAME: V_URL_ACCESS; TYPE: VIEW +-- +CREATE VIEW v_url_access AS + SELECT DISTINCT M.ACTION AS URL, + M.FUNCTION_CD + FROM FN_MENU M + WHERE (M.ACTION IS NOT NULL) +UNION + SELECT DISTINCT T.ACTION AS URL, + T.FUNCTION_CD + FROM FN_TAB T + WHERE (T.ACTION IS NOT NULL) +UNION + SELECT R.RESTRICTED_URL AS URL, + R.FUNCTION_CD + FROM FN_RESTRICTED_URL R; + +-- ------------------ ALTER TABLE ADD CONSTRAINT PRIMARY KEY SECTION +-- +-- NAME: CR_FAVORITE_REPORTS_USER_IDREP_ID; TYPE: CONSTRAINT +-- +alter table cr_favorite_reports + add constraint cr_favorite_reports_user_idrep_id primary key (user_id, rep_id); +-- +-- NAME: CR_FOLDER_FOLDER_ID; TYPE: CONSTRAINT +-- +alter table cr_folder + add constraint cr_folder_folder_id primary key (folder_id); +-- +-- NAME: CR_FOLDER_ACCESS_FOLDER_ACCESS_ID; TYPE: CONSTRAINT +-- +alter table cr_folder_access + add constraint cr_folder_access_folder_access_id primary key (folder_access_id); +-- +-- NAME: CR_HIST_USER_MAP_HIST_IDUSER_ID; TYPE: CONSTRAINT +-- +alter table cr_hist_user_map + add constraint cr_hist_user_map_hist_iduser_id primary key (hist_id, user_id); +-- +-- NAME: CR_LU_FILE_TYPE_LOOKUP_ID; TYPE: CONSTRAINT +-- +alter table cr_lu_file_type + add constraint cr_lu_file_type_lookup_id primary key (lookup_id); +-- +-- NAME: CR_RAPTOR_ACTION_IMG_IMAGE_ID; TYPE: CONSTRAINT +-- +alter table cr_raptor_action_img + add constraint cr_raptor_action_img_image_id primary key (image_id); +-- +-- NAME: CR_RAPTOR_PDF_IMG_IMAGE_ID; TYPE: CONSTRAINT +-- +alter table cr_raptor_pdf_img + add constraint cr_raptor_pdf_img_image_id primary key (image_id); +-- +-- NAME: CR_REMOTE_SCHEMA_INFO_SCHEMA_PREFIX; TYPE: CONSTRAINT +-- +alter table cr_remote_schema_info + add constraint cr_remote_schema_info_schema_prefix primary key (schema_prefix); +-- +-- NAME: CR_REPORT_REP_ID; TYPE: CONSTRAINT +-- +alter table cr_report + add constraint cr_report_rep_id primary key (rep_id); +-- +-- NAME: CR_REPORT_ACCESS_REP_IDORDER_NO; TYPE: CONSTRAINT +-- +alter table cr_report_access + add constraint cr_report_access_rep_idorder_no primary key (rep_id, order_no); +-- +-- NAME: CR_REPORT_EMAIL_SENT_LOG_LOG_ID; TYPE: CONSTRAINT +-- +alter table cr_report_email_sent_log + add constraint cr_report_email_sent_log_log_id primary key (log_id); +-- +-- NAME: CR_REPORT_FILE_HISTORY_HIST_ID; TYPE: CONSTRAINT +-- +alter table cr_report_file_history + add constraint cr_report_file_history_hist_id primary key (hist_id); +-- +-- NAME: CR_REPORT_SCHEDULE_SCHEDULE_ID; TYPE: CONSTRAINT +-- +alter table cr_report_schedule + add constraint cr_report_schedule_schedule_id primary key (schedule_id); +-- +-- NAME: CR_REPORT_SCHEDULE_USERS_SCHEDULE_IDREP_IDUSER_IDORDER_NO; TYPE: CONSTRAINT +-- +alter table cr_report_schedule_users + add constraint cr_report_schedule_users_schedule_idrep_iduser_idorder_no primary key (schedule_id, rep_id, user_id, order_no); +-- +-- NAME: CR_REPORT_TEMPLATE_MAP_REPORT_ID; TYPE: CONSTRAINT +-- +alter table cr_report_template_map + add constraint cr_report_template_map_report_id primary key (report_id); +-- +-- NAME: CR_TABLE_ROLE_TABLE_NAMEROLE_ID; TYPE: CONSTRAINT +-- +alter table cr_table_role + add constraint cr_table_role_table_namerole_id primary key (table_name, role_id); +-- +-- NAME: CR_TABLE_SOURCE_TABLE_NAME; TYPE: CONSTRAINT +-- +alter table cr_table_source + add constraint cr_table_source_table_name primary key (table_name); +-- +-- NAME: FN_AUDIT_ACTION_AUDIT_ACTION_ID; TYPE: CONSTRAINT +-- +alter table fn_audit_action + add constraint fn_audit_action_audit_action_id primary key (audit_action_id); +-- +-- NAME: FN_CHAT_LOGS_CHAT_LOG_ID; TYPE: CONSTRAINT +-- +alter table fn_chat_logs + add constraint fn_chat_logs_chat_log_id primary key (chat_log_id); +-- +-- NAME: FN_CHAT_ROOM_CHAT_ROOM_ID; TYPE: CONSTRAINT +-- +alter table fn_chat_room + add constraint fn_chat_room_chat_room_id primary key (chat_room_id); +-- +-- NAME: FN_CHAT_USERS_ID; TYPE: CONSTRAINT +-- +alter table fn_chat_users + add constraint fn_chat_users_id primary key (id); +-- +-- NAME: FN_LU_ALERT_METHOD_ALERT_METHOD_CD; TYPE: CONSTRAINT +-- +alter table fn_lu_alert_method + add constraint fn_lu_alert_method_alert_method_cd primary key (alert_method_cd); +-- +-- NAME: FN_LU_BROADCAST_SITE_BROADCAST_SITE_CD; TYPE: CONSTRAINT +-- +alter table fn_lu_broadcast_site + add constraint fn_lu_broadcast_site_broadcast_site_cd primary key (broadcast_site_cd); +-- +-- NAME: FN_LU_PRIORITY_PRIORITY_ID; TYPE: CONSTRAINT +-- +alter table fn_lu_priority + add constraint fn_lu_priority_priority_id primary key (priority_id); +-- +-- NAME: FN_LU_ROLE_TYPE_ROLE_TYPE_ID; TYPE: CONSTRAINT +-- +alter table fn_lu_role_type + add constraint fn_lu_role_type_role_type_id primary key (role_type_id); +-- +-- NAME: FN_LU_TAB_SET_TAB_SET_CD; TYPE: CONSTRAINT +-- +alter table fn_lu_tab_set + add constraint fn_lu_tab_set_tab_set_cd primary key (tab_set_cd); +-- +-- NAME: FN_LU_TIMEZONE_TIMEZONE_ID; TYPE: CONSTRAINT +-- +alter table fn_lu_timezone + add constraint fn_lu_timezone_timezone_id primary key (timezone_id); +-- +-- NAME: FN_ORG_ORG_ID; TYPE: CONSTRAINT +-- +alter table fn_org + add constraint fn_org_org_id primary key (org_id); +-- +-- NAME: FN_RESTRICTED_URL_RESTRICTED_URLFUNCTION_CD; TYPE: CONSTRAINT +-- +alter table fn_restricted_url + add constraint fn_restricted_url_restricted_urlfunction_cd primary key (restricted_url, function_cd); +-- +-- NAME: FN_ROLE_COMPOSITE_PARENT_ROLE_IDCHILD_ROLE_ID; TYPE: CONSTRAINT +-- +alter table fn_role_composite + add constraint fn_role_composite_parent_role_idchild_role_id primary key (parent_role_id, child_role_id); +-- +-- NAME: FN_ROLE_FUNCTION_ROLE_IDFUNCTION_CD; TYPE: CONSTRAINT +-- +alter table fn_role_function + add constraint fn_role_function_role_idfunction_cd primary key (role_id, function_cd); +-- +-- NAME: FN_TAB_TAB_CD; TYPE: CONSTRAINT +-- +alter table fn_tab + add constraint fn_tab_tab_cd primary key (tab_cd); +-- +-- NAME: FN_TAB_SELECTED_SELECTED_TAB_CDTAB_URI; TYPE: CONSTRAINT +-- +alter table fn_tab_selected + add constraint fn_tab_selected_selected_tab_cdtab_uri primary key (selected_tab_cd, tab_uri); +-- +-- NAME: FN_USER_PSEUDO_ROLE_PSEUDO_ROLE_IDUSER_ID; TYPE: CONSTRAINT +-- +alter table fn_user_pseudo_role + add constraint fn_user_pseudo_role_pseudo_role_iduser_id primary key (pseudo_role_id, user_id); +-- +-- NAME: FN_USER_ROLE_USER_IDROLE_ID; TYPE: CONSTRAINT +-- +alter table fn_user_role + add constraint fn_user_role_user_idrole_id primary key (user_id, role_id, app_id); +-- +-- Name: fn_lu_message_location_MESSAGE_LOCATION_ID; Type: CONSTRAINT +-- + +ALTER TABLE fn_lu_message_location + ADD CONSTRAINT fn_lu_message_location_MESSAGE_LOCATION_ID PRIMARY KEY (message_location_id); + +-- ------------------ CREATE INDEX SECTION +-- +-- NAME: CR_REPORT_CREATE_IDPUBLIC_YNTITLE; TYPE: INDEX +-- +create index cr_report_create_idpublic_yntitle using btree on cr_report (create_id, public_yn, title); +-- +-- NAME: CR_TABLE_JOIN_DEST_TABLE_NAME; TYPE: INDEX +-- +create index cr_table_join_dest_table_name using btree on cr_table_join (dest_table_name); +-- +-- NAME: CR_TABLE_JOIN_SRC_TABLE_NAME; TYPE: INDEX +-- +create index cr_table_join_src_table_name using btree on cr_table_join (src_table_name); +-- +-- NAME: FN_AUDIT_LOG_ACTIVITY_CD; TYPE: INDEX +-- +create index fn_audit_log_activity_cd using btree on fn_audit_log (activity_cd); +-- +-- NAME: FN_AUDIT_LOG_USER_ID; TYPE: INDEX +-- +create index fn_audit_log_user_id using btree on fn_audit_log (user_id); +-- +-- NAME: FN_MENU_FUNCTION_CD; TYPE: INDEX +-- +create index fn_menu_function_cd using btree on fn_menu (function_cd); +-- +-- NAME: FN_ORG_ACCESS_CD; TYPE: INDEX +-- +create index fn_org_access_cd using btree on fn_org (access_cd); +-- +-- NAME: FN_ROLE_FUNCTION_FUNCTION_CD; TYPE: INDEX +-- +create index fn_role_function_function_cd using btree on fn_role_function (function_cd); +-- +-- NAME: FN_ROLE_FUNCTION_ROLE_ID; TYPE: INDEX +-- +create index fn_role_function_role_id using btree on fn_role_function (role_id); +-- +-- NAME: FN_USER_ADDRESS_ID; TYPE: INDEX +-- +create index fn_user_address_id using btree on fn_user (address_id); +-- +-- NAME: FN_USER_ALERT_METHOD_CD; TYPE: INDEX +-- +create index fn_user_alert_method_cd using btree on fn_user (alert_method_cd); +-- +-- NAME: FN_USER_HRID; TYPE: INDEX +-- +create unique index fn_user_hrid using btree on fn_user (hrid); +-- +-- NAME: FN_USER_LOGIN_ID; TYPE: INDEX +-- +create unique index fn_user_login_id using btree on fn_user (login_id); +-- +-- NAME: FN_USER_ORG_ID; TYPE: INDEX +-- +create index fn_user_org_id using btree on fn_user (org_id); +-- +-- NAME: FN_USER_ROLE_ROLE_ID; TYPE: INDEX +-- +create index fn_user_role_role_id using btree on fn_user_role (role_id); +-- +-- NAME: FN_USER_ROLE_USER_ID; TYPE: INDEX +-- +create index fn_user_role_user_id using btree on fn_user_role (user_id); +-- +-- NAME: FK_FN_USER__REF_178_FN_APP_idx; TYPE: INDEX +-- +create index fk_fn_user__ref_178_fn_app_IDX on fn_user_role (app_id); + +-- ---------------------------------------------------------- +-- NAME: QUARTZ TYPE: INDEXES +-- ---------------------------------------------------------- +create index idx_fn_qz_j_req_recovery on fn_qz_job_details(sched_name,requests_recovery); +create index idx_fn_qz_j_grp on fn_qz_job_details(sched_name,job_group); +create index idx_fn_qz_t_j on fn_qz_triggers(sched_name,job_name,job_group); +create index idx_fn_qz_t_jg on fn_qz_triggers(sched_name,job_group); +create index idx_fn_qz_t_c on fn_qz_triggers(sched_name,calendar_name); +create index idx_fn_qz_t_g on fn_qz_triggers(sched_name,trigger_group); +create index idx_fn_qz_t_state on fn_qz_triggers(sched_name,trigger_state); +create index idx_fn_qz_t_n_state on fn_qz_triggers(sched_name,trigger_name,trigger_group,trigger_state); +create index idx_fn_qz_t_n_g_state on fn_qz_triggers(sched_name,trigger_group,trigger_state); +create index idx_fn_qz_t_next_fire_time on fn_qz_triggers(sched_name,next_fire_time); +create index idx_fn_qz_t_nft_st on fn_qz_triggers(sched_name,trigger_state,next_fire_time); +create index idx_fn_qz_t_nft_misfire on fn_qz_triggers(sched_name,misfire_instr,next_fire_time); +create index idx_fn_qz_t_nft_st_misfire on fn_qz_triggers(sched_name,misfire_instr,next_fire_time,trigger_state); +create index idx_fn_qz_t_nft_st_misfire_grp on fn_qz_triggers(sched_name,misfire_instr,next_fire_time,trigger_group,trigger_state); +create index idx_fn_qz_ft_trig_inst_name on fn_qz_fired_triggers(sched_name,instance_name); +create index idx_fn_qz_ft_inst_job_req_rcvry on fn_qz_fired_triggers(sched_name,instance_name,requests_recovery); +create index idx_fn_qz_ft_j_g on fn_qz_fired_triggers(sched_name,job_name,job_group); +create index idx_fn_qz_ft_jg on fn_qz_fired_triggers(sched_name,job_group); +create index idx_fn_qz_ft_t_g on fn_qz_fired_triggers(sched_name,trigger_name,trigger_group); +create index idx_fn_qz_ft_tg on fn_qz_fired_triggers(sched_name,trigger_group); + +-- ------------------ ALTER TABLE ADD CONSTRAINT FOREIGN KEY SECTION +-- +-- NAME: FK_FN_AUDIT_REF_205_FN_LU_AC; TYPE: CONSTRAINT +-- +alter table fn_audit_log + add constraint fk_fn_audit_ref_205_fn_lu_ac foreign key (activity_cd) references fn_lu_activity(activity_cd); +-- +-- NAME: FK_FN_ROLE__REF_201_FN_FUNCT; TYPE: CONSTRAINT +-- +alter table fn_role_function + add constraint fk_fn_role__ref_201_fn_funct foreign key (function_cd) references fn_function(function_cd); +-- +-- NAME: FK_FN_USER__REF_178_FN_APP; TYPE: FK CONSTRAINT +-- +alter table fn_user_role + add constraint fk_fn_user__ref_178_fn_app foreign key (app_id) references fn_app(app_id); +-- +-- NAME: FK_CR_REPOR_REF_14707_CR_REPOR; TYPE: FK CONSTRAINT +-- +alter table cr_report_schedule + add constraint fk_cr_repor_ref_14707_cr_repor foreign key (rep_id) references cr_report(rep_id); +-- +-- NAME: FK_CR_REPOR_REF_14716_CR_REPOR; TYPE: FK CONSTRAINT +-- +alter table cr_report_schedule_users + add constraint fk_cr_repor_ref_14716_cr_repor foreign key (schedule_id) references cr_report_schedule(schedule_id); +-- +-- NAME: FK_CR_REPOR_REF_17645_CR_REPOR; TYPE: FK CONSTRAINT +-- +alter table cr_report_log + add constraint fk_cr_repor_ref_17645_cr_repor foreign key (rep_id) references cr_report(rep_id); +-- +-- NAME: FK_CR_REPOR_REF_8550_CR_REPOR; TYPE: FK CONSTRAINT +-- +alter table cr_report_access + add constraint fk_cr_repor_ref_8550_cr_repor foreign key (rep_id) references cr_report(rep_id); +-- +-- NAME: FK_CR_REPORT_REP_ID; TYPE: FK CONSTRAINT +-- +alter table cr_report_email_sent_log + add constraint fk_cr_report_rep_id foreign key (rep_id) references cr_report(rep_id); +-- +-- NAME: FK_CR_TABLE_REF_311_CR_TAB; TYPE: FK CONSTRAINT +-- +alter table cr_table_join + add constraint fk_cr_table_ref_311_cr_tab foreign key (src_table_name) references cr_table_source(table_name); +-- +-- NAME: FK_CR_TABLE_REF_315_CR_TAB; TYPE: FK CONSTRAINT +-- +alter table cr_table_join + add constraint fk_cr_table_ref_315_cr_tab foreign key (dest_table_name) references cr_table_source(table_name); +-- +-- NAME: FK_CR_TABLE_REF_32384_CR_TABLE; TYPE: FK CONSTRAINT +-- +alter table cr_table_role + add constraint fk_cr_table_ref_32384_cr_table foreign key (table_name) references cr_table_source(table_name); +-- +-- NAME: FK_FN_TAB_FUNCTION_CD; TYPE: FK CONSTRAINT +-- +alter table fn_tab + add constraint fk_fn_tab_function_cd foreign key (function_cd) references fn_function(function_cd); +-- +-- NAME: FK_FN_TAB_SELECTED_TAB_CD; TYPE: FK CONSTRAINT +-- +alter table fn_tab_selected + add constraint fk_fn_tab_selected_tab_cd foreign key (selected_tab_cd) references fn_tab(tab_cd); +-- +-- NAME: FK_FN_TAB_SET_CD; TYPE: FK CONSTRAINT +-- +alter table fn_tab + add constraint fk_fn_tab_set_cd foreign key (tab_set_cd) references fn_lu_tab_set(tab_set_cd); +-- +-- NAME: FK_FN_USER_REF_110_FN_ORG; TYPE: FK CONSTRAINT +-- +alter table fn_user + add constraint fk_fn_user_ref_110_fn_org foreign key (org_id) references fn_org(org_id); +-- +-- NAME: FK_FN_USER_REF_123_FN_LU_AL; TYPE: FK CONSTRAINT +-- +alter table fn_user + add constraint fk_fn_user_ref_123_fn_lu_al foreign key (alert_method_cd) references fn_lu_alert_method(alert_method_cd); +-- +-- NAME: FK_FN_USER_REF_197_FN_USER; TYPE: FK CONSTRAINT +-- +alter table fn_user + add constraint fk_fn_user_ref_197_fn_user foreign key (manager_id) references fn_user(user_id); +-- +-- NAME: FK_FN_USER_REF_198_FN_USER; TYPE: FK CONSTRAINT +-- +alter table fn_user + add constraint fk_fn_user_ref_198_fn_user foreign key (created_id) references fn_user(user_id); +-- +-- NAME: FK_FN_USER_REF_199_FN_USER; TYPE: FK CONSTRAINT +-- +alter table fn_user + add constraint fk_fn_user_ref_199_fn_user foreign key (modified_id) references fn_user(user_id); +-- +-- NAME: FK_PARENT_KEY_CR_FOLDER; TYPE: FK CONSTRAINT +-- +alter table cr_folder + add constraint fk_parent_key_cr_folder foreign key (parent_folder_id) references cr_folder(folder_id); +-- +-- NAME: FK_PSEUDO_ROLE_PSEUDO_ROLE_ID; TYPE: FK CONSTRAINT +-- +alter table fn_user_pseudo_role + add constraint fk_pseudo_role_pseudo_role_id foreign key (pseudo_role_id) references fn_role(role_id); +-- +-- NAME: FK_PSEUDO_ROLE_USER_ID; TYPE: FK CONSTRAINT +-- +alter table fn_user_pseudo_role + add constraint fk_pseudo_role_user_id foreign key (user_id) references fn_user(user_id); +-- +-- NAME: FK_RESTRICTED_URL_FUNCTION_CD; TYPE: FK CONSTRAINT +-- +alter table fn_restricted_url + add constraint fk_restricted_url_function_cd foreign key (function_cd) references fn_function(function_cd); +-- +-- NAME: FK_TIMEZONE; TYPE: FK CONSTRAINT +-- +alter table fn_user + add constraint fk_timezone foreign key (timezone) references fn_lu_timezone(timezone_id); +-- +-- NAME: SYS_C0014614; TYPE: FK CONSTRAINT +-- +alter table cr_report_file_history + add constraint sys_c0014614 foreign key (file_type_id) references cr_lu_file_type(lookup_id); +-- +-- NAME: SYS_C0014615; TYPE: FK CONSTRAINT +-- +alter table cr_report_file_history + add constraint sys_c0014615 foreign key (rep_id) references cr_report(rep_id); +-- +-- NAME: SYS_C0014616; TYPE: FK CONSTRAINT +-- +alter table cr_hist_user_map + add constraint sys_c0014616 foreign key (hist_id) references cr_report_file_history(hist_id); +-- +-- NAME: SYS_C0014617; TYPE: FK CONSTRAINT +-- +alter table cr_hist_user_map + add constraint sys_c0014617 foreign key (user_id) references fn_user(user_id); + +commit; diff --git a/ecomp-sdk-app/db-scripts/EcompSdkDMLMySql_1610_Complete_OS.sql b/ecomp-sdk-app/db-scripts/EcompSdkDMLMySql_1610_Complete_OS.sql new file mode 100644 index 000000000..c00d435fd --- /dev/null +++ b/ecomp-sdk-app/db-scripts/EcompSdkDMLMySql_1610_Complete_OS.sql @@ -0,0 +1,2928 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +-- --------------------------------------------------------------------------------------------------------------- +-- This is for the default data for 1610 Version of SDK database for Open Source called ecomp_sdk + +USE ecomp_sdk; + +set foreign_key_checks=1; + +-- fn_function +Insert into fn_function (FUNCTION_CD,FUNCTION_NAME) values ('menu_process','Process List'); +Insert into fn_function (FUNCTION_CD,FUNCTION_NAME) values ('1','test role function'); +Insert into fn_function (FUNCTION_CD,FUNCTION_NAME) values ('menu_job','Job Menu'); +Insert into fn_function (FUNCTION_CD,FUNCTION_NAME) values ('menu_job_create','Job Create'); +Insert into fn_function (FUNCTION_CD,FUNCTION_NAME) values ('menu_job_designer','Process in Designer view'); +Insert into fn_function (FUNCTION_CD,FUNCTION_NAME) values ('menu_task','Task Menu'); +Insert into fn_function (FUNCTION_CD,FUNCTION_NAME) values ('menu_task_search','Task Search'); +Insert into fn_function (FUNCTION_CD,FUNCTION_NAME) values ('menu_map','Map Menu'); +Insert into fn_function (FUNCTION_CD,FUNCTION_NAME) values ('menu_sample','Sample Pages Menu'); +Insert into fn_function (FUNCTION_CD,FUNCTION_NAME) values ('menu_test','Test Menu'); +Insert into fn_function (FUNCTION_CD,FUNCTION_NAME) values ('login','Login'); +Insert into fn_function (FUNCTION_CD,FUNCTION_NAME) values ('menu_home','Home Menu'); +Insert into fn_function (FUNCTION_CD,FUNCTION_NAME) values ('menu_customer','Customer Menu'); +Insert into fn_function (FUNCTION_CD,FUNCTION_NAME) values ('menu_reports','Reports Menu'); +Insert into fn_function (FUNCTION_CD,FUNCTION_NAME) values ('menu_profile','Profile Menu'); +Insert into fn_function (FUNCTION_CD,FUNCTION_NAME) values ('menu_admin','Admin Menu'); +Insert into fn_function (FUNCTION_CD,FUNCTION_NAME) values ('menu_feedback','Feedback Menu'); +Insert into fn_function (FUNCTION_CD,FUNCTION_NAME) values ('menu_help','Help Menu'); +Insert into fn_function (FUNCTION_CD,FUNCTION_NAME) values ('menu_logout','Logout Menu'); +Insert into fn_function (FUNCTION_CD,FUNCTION_NAME) values ('menu_doclib','Document Library Menu'); +Insert into fn_function (FUNCTION_CD,FUNCTION_NAME) values ('doclib','Document Library'); +Insert into fn_function (FUNCTION_CD,FUNCTION_NAME) values ('doclib_admin','Document Library Admin'); +Insert into fn_function (FUNCTION_CD,FUNCTION_NAME) values ('menu_notes','Notes Menu'); +Insert into fn_function (FUNCTION_CD,FUNCTION_NAME) values ('menu_ajax','Ajax Menu'); +Insert into fn_function (FUNCTION_CD,FUNCTION_NAME) values ('menu_customer_create','Customer Create'); +Insert into fn_function (FUNCTION_CD,FUNCTION_NAME) values ('menu_profile_create','Profile Create'); +Insert into fn_function (FUNCTION_CD,FUNCTION_NAME) values ('menu_profile_import','Profile Import'); +Insert into fn_function (FUNCTION_CD,FUNCTION_NAME) values ('menu_tab','Sample Tab Menu'); +Insert into fn_function (FUNCTION_CD,FUNCTION_NAME) values ('menu_concept','CoNCEPT'); +Insert into fn_function (FUNCTION_CD,FUNCTION_NAME) values ('menu_itracker','iTracker Menu'); +Insert into fn_function (FUNCTION_CD,FUNCTION_NAME) values ('view_reports','View Raptor reports'); +Insert into fn_function (FUNCTION_CD,FUNCTION_NAME) values ('menu_itracker_admin','Itracker Admin/Support menu'); + +-- fn_lu_activity +Insert into fn_lu_activity (ACTIVITY_CD,ACTIVITY) values ('add_role','add_role'); +Insert into fn_lu_activity (ACTIVITY_CD,ACTIVITY) values ('remove_role','remove_role'); +Insert into fn_lu_activity (ACTIVITY_CD,ACTIVITY) values ('add_user_role','add_user_role'); +Insert into fn_lu_activity (ACTIVITY_CD,ACTIVITY) values ('remove_user_role','remove_user_role'); +Insert into fn_lu_activity (ACTIVITY_CD,ACTIVITY) values ('add_role_function','add_role_function'); +Insert into fn_lu_activity (ACTIVITY_CD,ACTIVITY) values ('remove_role_function','remove_role_function'); +Insert into fn_lu_activity (ACTIVITY_CD,ACTIVITY) values ('add_child_role','add_child_role'); +Insert into fn_lu_activity (ACTIVITY_CD,ACTIVITY) values ('remove_child_role','remove_child_role'); +Insert into fn_lu_activity (ACTIVITY_CD,ACTIVITY) values ('mobile_login','Mobile Login'); +Insert into fn_lu_activity (ACTIVITY_CD,ACTIVITY) values ('mobile_logout','Mobile Logout'); +Insert into fn_lu_activity (ACTIVITY_CD,ACTIVITY) values ('login','Login'); +Insert into fn_lu_activity (ACTIVITY_CD,ACTIVITY) values ('logout','Logout'); + +-- fn_lu_alert_method +Insert into fn_lu_alert_method (ALERT_METHOD_CD,ALERT_METHOD) values ('PHONE','Phone'); +Insert into fn_lu_alert_method (ALERT_METHOD_CD,ALERT_METHOD) values ('FAX','Fax'); +Insert into fn_lu_alert_method (ALERT_METHOD_CD,ALERT_METHOD) values ('PAGER','Pager'); +Insert into fn_lu_alert_method (ALERT_METHOD_CD,ALERT_METHOD) values ('EMAIL','Email'); +Insert into fn_lu_alert_method (ALERT_METHOD_CD,ALERT_METHOD) values ('SMS','SMS'); + +-- fn_lu_menu_set +Insert into fn_lu_menu_set (MENU_SET_CD,MENU_SET_NAME) values ('APP','Application Menu'); + +-- fn_lu_priority +Insert into fn_lu_priority (PRIORITY_ID,PRIORITY,ACTIVE_YN,SORT_ORDER) values (10,'Low','Y',10); +Insert into fn_lu_priority (PRIORITY_ID,PRIORITY,ACTIVE_YN,SORT_ORDER) values (20,'Normal','Y',20); +Insert into fn_lu_priority (PRIORITY_ID,PRIORITY,ACTIVE_YN,SORT_ORDER) values (30,'High','Y',30); +Insert into fn_lu_priority (PRIORITY_ID,PRIORITY,ACTIVE_YN,SORT_ORDER) values (40,'Urgent','Y',40); +Insert into fn_lu_priority (PRIORITY_ID,PRIORITY,ACTIVE_YN,SORT_ORDER) values (50,'Fatal','Y',50); + +-- fn_lu_tab_set +Insert into fn_lu_tab_set (TAB_SET_CD,TAB_SET_NAME) values ('APP','Application Tabs'); + +-- fn_lu_timezone +Insert into fn_lu_timezone (TIMEZONE_ID,TIMEZONE_NAME,TIMEZONE_VALUE) values (10,'US/Eastern','US/Eastern'); +Insert into fn_lu_timezone (TIMEZONE_ID,TIMEZONE_NAME,TIMEZONE_VALUE) values (20,'US/Central','US/Central'); +Insert into fn_lu_timezone (TIMEZONE_ID,TIMEZONE_NAME,TIMEZONE_VALUE) values (30,'US/Mountain','US/Mountain'); +Insert into fn_lu_timezone (TIMEZONE_ID,TIMEZONE_NAME,TIMEZONE_VALUE) values (40,'US/Arizona','America/Phoenix'); +Insert into fn_lu_timezone (TIMEZONE_ID,TIMEZONE_NAME,TIMEZONE_VALUE) values (50,'US/Pacific','US/Pacific'); +Insert into fn_lu_timezone (TIMEZONE_ID,TIMEZONE_NAME,TIMEZONE_VALUE) values (60,'US/Alaska','US/Alaska'); +Insert into fn_lu_timezone (TIMEZONE_ID,TIMEZONE_NAME,TIMEZONE_VALUE) values (70,'US/Hawaii','US/Hawaii'); + +-- fn_menu +INSERT INTO fn_menu (MENU_ID, LABEL, PARENT_ID, SORT_ORDER, ACTION, FUNCTION_CD, ACTIVE_YN, SERVLET, QUERY_STRING, EXTERNAL_URL, TARGET, MENU_SET_CD, SEPARATOR_YN, IMAGE_SRC) VALUES (1, 'Root', NULL, 10, NULL, 'menu_home', 'N', NULL, NULL, NULL, NULL, 'APP', 'N', NULL); -- we need even though it's inactive +INSERT INTO fn_menu (MENU_ID, LABEL, PARENT_ID, SORT_ORDER, ACTION, FUNCTION_CD, ACTIVE_YN, SERVLET, QUERY_STRING, EXTERNAL_URL, TARGET, MENU_SET_CD, SEPARATOR_YN, IMAGE_SRC) VALUES (5000, 'Sample Pages', 1, 30, 'sample.htm', 'menu_sample', 'Y', NULL, NULL, NULL, NULL, 'APP', 'N', 'icon-local-search'); +INSERT INTO fn_menu (MENU_ID, LABEL, PARENT_ID, SORT_ORDER, ACTION, FUNCTION_CD, ACTIVE_YN, SERVLET, QUERY_STRING, EXTERNAL_URL, TARGET, MENU_SET_CD, SEPARATOR_YN, IMAGE_SRC) VALUES (2, 'Home', 1, 10, 'welcome.htm', 'menu_home', 'Y', NULL, NULL, NULL, NULL, 'APP', 'N', 'icon-location-pin'); +INSERT INTO fn_menu (MENU_ID, LABEL, PARENT_ID, SORT_ORDER, ACTION, FUNCTION_CD, ACTIVE_YN, SERVLET, QUERY_STRING, EXTERNAL_URL, TARGET, MENU_SET_CD, SEPARATOR_YN, IMAGE_SRC) VALUES (8, 'Reports', 1, 40, 'report.htm', 'menu_reports', 'Y', NULL, NULL, NULL, NULL, 'APP', 'N', 'icon-data'); +INSERT INTO fn_menu (MENU_ID, LABEL, PARENT_ID, SORT_ORDER, ACTION, FUNCTION_CD, ACTIVE_YN, SERVLET, QUERY_STRING, EXTERNAL_URL, TARGET, MENU_SET_CD, SEPARATOR_YN, IMAGE_SRC) VALUES (9, 'Profile', 1, 90, 'userProfile', 'menu_profile', 'Y', NULL, NULL, NULL, NULL, 'APP', 'N', 'icon-user'); +INSERT INTO fn_menu (MENU_ID, LABEL, PARENT_ID, SORT_ORDER, ACTION, FUNCTION_CD, ACTIVE_YN, SERVLET, QUERY_STRING, EXTERNAL_URL, TARGET, MENU_SET_CD, SEPARATOR_YN, IMAGE_SRC) VALUES (10, 'Admin', 1, 110, 'role_list.htm', 'menu_admin', 'Y', NULL, NULL, NULL, NULL, 'APP', 'N', 'icon-settings'); +INSERT INTO fn_menu (MENU_ID, LABEL, PARENT_ID, SORT_ORDER, ACTION, FUNCTION_CD, ACTIVE_YN, SERVLET, QUERY_STRING, EXTERNAL_URL, TARGET, MENU_SET_CD, SEPARATOR_YN, IMAGE_SRC) VALUES (13, 'Application Logout', 1, 130, 'app_logout.htm', 'menu_logout', 'Y', NULL, NULL, NULL, NULL, 'APP', 'N', 'icon-sign-out'); +INSERT INTO fn_menu (MENU_ID, LABEL, PARENT_ID, SORT_ORDER, ACTION, FUNCTION_CD, ACTIVE_YN, SERVLET, QUERY_STRING, EXTERNAL_URL, TARGET, MENU_SET_CD, SEPARATOR_YN, IMAGE_SRC) VALUES (84, 'All Reports', 8, 50, 'report', 'menu_reports', 'Y', NULL, NULL, NULL, NULL, 'APP', 'N', '/static/fusion/images/reports.png'); +INSERT INTO fn_menu (MENU_ID, LABEL, PARENT_ID, SORT_ORDER, ACTION, FUNCTION_CD, ACTIVE_YN, SERVLET, QUERY_STRING, EXTERNAL_URL, TARGET, MENU_SET_CD, SEPARATOR_YN, IMAGE_SRC) values (87, 'Create Reports', 8, 120, 'report_wizard.htm?r_action=report.create', 'menu_reports', 'Y', NULL, 'r_action=report.create', NULL, NULL, 'APP', 'N', NULL); +INSERT INTO fn_menu (MENU_ID, LABEL, PARENT_ID, SORT_ORDER, ACTION, FUNCTION_CD, ACTIVE_YN, SERVLET, QUERY_STRING, EXTERNAL_URL, TARGET, MENU_SET_CD, SEPARATOR_YN, IMAGE_SRC) values (88, 'Sample Dashboard', 8, 130, 'report_sample', 'menu_reports', 'Y', NULL, NULL, NULL, NULL, 'APP', 'N', NULL); +INSERT INTO fn_menu (MENU_ID, LABEL, PARENT_ID, SORT_ORDER, ACTION, FUNCTION_CD, ACTIVE_YN, SERVLET, QUERY_STRING, EXTERNAL_URL, TARGET, MENU_SET_CD, SEPARATOR_YN, IMAGE_SRC) VALUES (92, 'Import User', 9, 30, null, 'menu_profile_import', 'Y', NULL, NULL, NULL, NULL, 'APP', 'N', '/static/fusion/images/webphone.ico'); -- rename +INSERT INTO fn_menu (MENU_ID, LABEL, PARENT_ID, SORT_ORDER, ACTION, FUNCTION_CD, ACTIVE_YN, SERVLET, QUERY_STRING, EXTERNAL_URL, TARGET, MENU_SET_CD, SEPARATOR_YN, IMAGE_SRC) VALUES (94, 'Self', 9, 40, null, 'menu_profile', 'Y', NULL, NULL, NULL, NULL, 'APP', 'N', '/static/fusion/images/profile.png'); +INSERT INTO fn_menu (MENU_ID, LABEL, PARENT_ID, SORT_ORDER, ACTION, FUNCTION_CD, ACTIVE_YN, SERVLET, QUERY_STRING, EXTERNAL_URL, TARGET, MENU_SET_CD, SEPARATOR_YN, IMAGE_SRC) VALUES (101, 'Roles', 10, 20, 'admin', 'menu_admin', 'Y', NULL, NULL, NULL, NULL, 'APP', 'N', '/static/fusion/images/users.png'); +INSERT INTO fn_menu (MENU_ID, LABEL, PARENT_ID, SORT_ORDER, ACTION, FUNCTION_CD, ACTIVE_YN, SERVLET, QUERY_STRING, EXTERNAL_URL, TARGET, MENU_SET_CD, SEPARATOR_YN, IMAGE_SRC) VALUES (102, 'Role Functions', 10, 30, 'admin#/role_function_list', 'menu_admin', 'Y', NULL, NULL, NULL, NULL, 'APP', 'N', NULL); +INSERT INTO fn_menu (MENU_ID, LABEL, PARENT_ID, SORT_ORDER, ACTION, FUNCTION_CD, ACTIVE_YN, SERVLET, QUERY_STRING, EXTERNAL_URL, TARGET, MENU_SET_CD, SEPARATOR_YN, IMAGE_SRC) VALUES (103, 'Broadcast Messages', 10, 50, 'admin#/broadcast_list', 'menu_admin', 'Y', NULL, NULL, NULL, NULL, 'APP', 'N', '/static/fusion/images/bubble.png'); +INSERT INTO fn_menu (MENU_ID, LABEL, PARENT_ID, SORT_ORDER, ACTION, FUNCTION_CD, ACTIVE_YN, SERVLET, QUERY_STRING, EXTERNAL_URL, TARGET, MENU_SET_CD, SEPARATOR_YN, IMAGE_SRC) VALUES (105, 'Cache Admin', 10, 40, 'admin#/jcs_admin', 'menu_admin', 'Y', NULL, NULL, NULL, NULL, 'APP', 'N', '/static/fusion/images/cache.png'); +INSERT INTO fn_menu (MENU_ID, LABEL, PARENT_ID, SORT_ORDER, ACTION, FUNCTION_CD, ACTIVE_YN, SERVLET, QUERY_STRING, EXTERNAL_URL, TARGET, MENU_SET_CD, SEPARATOR_YN, IMAGE_SRC) VALUES (108, 'Usage', 10, 80, 'admin#/usage_list', 'menu_admin', 'Y', NULL, NULL, NULL, NULL, 'APP', 'N', '/static/fusion/images/users.png'); +INSERT INTO fn_menu (MENU_ID, LABEL, PARENT_ID, SORT_ORDER, ACTION, FUNCTION_CD, ACTIVE_YN, SERVLET, QUERY_STRING, EXTERNAL_URL, TARGET, MENU_SET_CD, SEPARATOR_YN, IMAGE_SRC) VALUES (121, 'Collaboration', 5000, 100, 'collaborate_list.htm', 'menu_sample', 'Y', NULL, NULL, NULL, NULL, 'APP', 'N', '/static/fusion/images/bubble.png'); +INSERT INTO fn_menu (MENU_ID, LABEL, PARENT_ID, SORT_ORDER, ACTION, FUNCTION_CD, ACTIVE_YN, SERVLET, QUERY_STRING, EXTERNAL_URL, TARGET, MENU_SET_CD, SEPARATOR_YN, IMAGE_SRC) VALUES (930, 'Search', 9, 15, 'userProfile', 'menu_admin', 'Y', NULL, NULL, NULL, NULL, 'APP', 'N', '/static/fusion/images/search_profile.png'); +INSERT INTO fn_menu (MENU_ID, LABEL, PARENT_ID, SORT_ORDER, ACTION, FUNCTION_CD, ACTIVE_YN, SERVLET, QUERY_STRING, EXTERNAL_URL, TARGET, MENU_SET_CD, SEPARATOR_YN, IMAGE_SRC) VALUES (5010, 'Services', 5000, 102, NULL, 'menu_sample', 'N', NULL, NULL, NULL, NULL, 'APP', 'N', '/static/images/vsp_network_small.png'); +INSERT INTO fn_menu (MENU_ID, LABEL, PARENT_ID, SORT_ORDER, ACTION, FUNCTION_CD, ACTIVE_YN, SERVLET, QUERY_STRING, EXTERNAL_URL, TARGET, MENU_SET_CD, SEPARATOR_YN, IMAGE_SRC) VALUES (5011, 'My Services', 5010, 10, 'my_services.htm', 'menu_sample', 'Y', NULL, NULL, NULL, NULL, 'APP', 'N', NULL); +INSERT INTO fn_menu (MENU_ID, LABEL, PARENT_ID, SORT_ORDER, ACTION, FUNCTION_CD, ACTIVE_YN, SERVLET, QUERY_STRING, EXTERNAL_URL, TARGET, MENU_SET_CD, SEPARATOR_YN, IMAGE_SRC) VALUES (5012, 'Add Services', 5010, 10, 'add_services.htm', 'menu_sample', 'Y', NULL, NULL, NULL, NULL, 'APP', 'N', NULL); +INSERT INTO fn_menu (MENU_ID, LABEL, PARENT_ID, SORT_ORDER, ACTION, FUNCTION_CD, ACTIVE_YN, SERVLET, QUERY_STRING, EXTERNAL_URL, TARGET, MENU_SET_CD, SEPARATOR_YN, IMAGE_SRC) VALUES (5040, 'Sample Nested Menu', 5000, 20, NULL, 'menu_sample', 'N', NULL, NULL, NULL, NULL, 'APP', 'N', NULL); +INSERT INTO fn_menu (MENU_ID, LABEL, PARENT_ID, SORT_ORDER, ACTION, FUNCTION_CD, ACTIVE_YN, SERVLET, QUERY_STRING, EXTERNAL_URL, TARGET, MENU_SET_CD, SEPARATOR_YN, IMAGE_SRC) VALUES (6000, 'Nested Menu Item #1', 5040, 10, NULL, 'menu_sample', 'Y', NULL, NULL, NULL, NULL, 'APP', 'N', NULL); +INSERT INTO fn_menu (MENU_ID, LABEL, PARENT_ID, SORT_ORDER, ACTION, FUNCTION_CD, ACTIVE_YN, SERVLET, QUERY_STRING, EXTERNAL_URL, TARGET, MENU_SET_CD, SEPARATOR_YN, IMAGE_SRC) VALUES (6010, 'Nested Menu Item #2', 5040, 20, NULL, 'menu_sample', 'Y', NULL, NULL, NULL, NULL, 'APP', 'N', NULL); +INSERT INTO fn_menu (MENU_ID, LABEL, PARENT_ID, SORT_ORDER, ACTION, FUNCTION_CD, ACTIVE_YN, SERVLET, QUERY_STRING, EXTERNAL_URL, TARGET, MENU_SET_CD, SEPARATOR_YN, IMAGE_SRC) VALUES (6100, 'Another Nested Menu', 6000, 10, NULL, 'menu_sample', 'Y', NULL, NULL, NULL, NULL, 'APP', 'N', NULL); +INSERT INTO fn_menu (MENU_ID, LABEL, PARENT_ID, SORT_ORDER, ACTION, FUNCTION_CD, ACTIVE_YN, SERVLET, QUERY_STRING, EXTERNAL_URL, TARGET, MENU_SET_CD, SEPARATOR_YN, IMAGE_SRC) VALUES (6200, 'Another Nested Child Menu A', 6100, 10, NULL, 'menu_sample', 'Y', NULL, NULL, NULL, NULL, 'APP', 'N', NULL); +INSERT INTO fn_menu (MENU_ID, LABEL, PARENT_ID, SORT_ORDER, ACTION, FUNCTION_CD, ACTIVE_YN, SERVLET, QUERY_STRING, EXTERNAL_URL, TARGET, MENU_SET_CD, SEPARATOR_YN, IMAGE_SRC) VALUES (6210, 'Another Nested Child Menu B', 6100, 10, NULL, 'menu_sample', 'Y', NULL, NULL, NULL, NULL, 'APP', 'N', NULL); +INSERT INTO fn_menu (MENU_ID, LABEL, PARENT_ID, SORT_ORDER, ACTION, FUNCTION_CD, ACTIVE_YN, SERVLET, QUERY_STRING, EXTERNAL_URL, TARGET, MENU_SET_CD, SEPARATOR_YN, IMAGE_SRC) VALUES (5050, 'Grid Implementations', 5000, 70, NULL, 'menu_sample', 'N', NULL, NULL, NULL, NULL, 'APP', 'N', '/static/fusion/images/table.png'); +INSERT INTO fn_menu (MENU_ID, LABEL, PARENT_ID, SORT_ORDER, ACTION, FUNCTION_CD, ACTIVE_YN, SERVLET, QUERY_STRING, EXTERNAL_URL, TARGET, MENU_SET_CD, SEPARATOR_YN, IMAGE_SRC) VALUES (7010, 'Customer List', 5050, 10, 'customer_list.htm', 'menu_sample', 'Y', NULL, NULL, NULL, NULL, 'APP', 'N', NULL); +INSERT INTO fn_menu (MENU_ID, LABEL, PARENT_ID, SORT_ORDER, ACTION, FUNCTION_CD, ACTIVE_YN, SERVLET, QUERY_STRING, EXTERNAL_URL, TARGET, MENU_SET_CD, SEPARATOR_YN, IMAGE_SRC) VALUES (7020, 'Contact List', 5050, 20, 'app_contact_list.htm', 'menu_sample', 'Y', NULL, NULL, NULL, NULL, 'APP', 'N', NULL); +INSERT INTO fn_menu (MENU_ID, LABEL, PARENT_ID, SORT_ORDER, ACTION, FUNCTION_CD, ACTIVE_YN, SERVLET, QUERY_STRING, EXTERNAL_URL, TARGET, MENU_SET_CD, SEPARATOR_YN, IMAGE_SRC) VALUES (7030, 'Alternate Contact List', 5050, 30, 'alt_contact_list.htm', 'menu_sample', 'Y', NULL, NULL, NULL, NULL, 'APP', 'N', NULL); +INSERT INTO fn_menu (MENU_ID, LABEL, PARENT_ID, SORT_ORDER, ACTION, FUNCTION_CD, ACTIVE_YN, SERVLET, QUERY_STRING, EXTERNAL_URL, TARGET, MENU_SET_CD, SEPARATOR_YN, IMAGE_SRC) VALUES (7040, 'Customer Update', 5050, 15, 'customer_update.htm', 'menu_sample', 'Y', NULL, NULL, NULL, NULL, 'APP', 'N', NULL); +INSERT INTO fn_menu (MENU_ID, LABEL, PARENT_ID, SORT_ORDER, ACTION, FUNCTION_CD, ACTIVE_YN, SERVLET, QUERY_STRING, EXTERNAL_URL, TARGET, MENU_SET_CD, SEPARATOR_YN, IMAGE_SRC) VALUES (150022, 'Menus', 10, 60, 'admin#/admin_menu_edit', 'menu_admin', 'Y', NULL, NULL, NULL, NULL, 'APP', 'N', NULL); +INSERT INTO fn_menu (MENU_ID, LABEL, PARENT_ID, SORT_ORDER, ACTION, FUNCTION_CD, ACTIVE_YN, SERVLET, QUERY_STRING, EXTERNAL_URL, TARGET, MENU_SET_CD, SEPARATOR_YN, IMAGE_SRC) VALUES (150026, 'Workflows', 10, 71, 'workflows#/all', 'menu_admin', 'Y', NULL, NULL, NULL, NULL, 'APP', 'Y', NULL); +INSERT INTO fn_menu (MENU_ID, LABEL, PARENT_ID, SORT_ORDER, ACTION, FUNCTION_CD, ACTIVE_YN, SERVLET, QUERY_STRING, EXTERNAL_URL, TARGET, MENU_SET_CD, SEPARATOR_YN, IMAGE_SRC) VALUES (150028, 'Drools', 5000, 110, 'drools.htm', 'menu_sample', 'Y', NULL, NULL, NULL, NULL, 'APP', 'N', NULL); +INSERT INTO fn_menu (MENU_ID, LABEL, PARENT_ID, SORT_ORDER, ACTION, FUNCTION_CD, ACTIVE_YN, SERVLET, QUERY_STRING, EXTERNAL_URL, TARGET, MENU_SET_CD, SEPARATOR_YN, IMAGE_SRC) VALUES (150038,'Notebook',5000,135,'notebook.htm','menu_sample','Y',NULL,NULL,NULL,NULL,'APP','N',NULL); + +-- fn_restricted_url +INSERT INTO fn_restricted_url (restricted_url, function_cd) VALUES ('attachment.htm','menu_admin'); +INSERT INTO fn_restricted_url (restricted_url, function_cd) VALUES ('broadcast.htm','menu_admin'); +INSERT INTO fn_restricted_url (restricted_url, function_cd) VALUES ('file_upload.htm','menu_admin'); +INSERT INTO fn_restricted_url (restricted_url, function_cd) VALUES ('job.htm','menu_admin'); +INSERT INTO fn_restricted_url (restricted_url, function_cd) VALUES ('role.htm','menu_admin'); +INSERT INTO fn_restricted_url (restricted_url, function_cd) VALUES ('role_function.htm','menu_admin'); +INSERT INTO fn_restricted_url (restricted_url, function_cd) VALUES ('test.htm','menu_admin'); +INSERT INTO fn_restricted_url (restricted_url, function_cd) VALUES ('async_test.htm','menu_home'); +INSERT INTO fn_restricted_url (restricted_url, function_cd) VALUES ('chatWindow.htm','menu_home'); +INSERT INTO fn_restricted_url (restricted_url, function_cd) VALUES ('contact_list.htm','menu_home'); +INSERT INTO fn_restricted_url (restricted_url, function_cd) VALUES ('customer_dynamic_list.htm','menu_home'); +INSERT INTO fn_restricted_url (restricted_url, function_cd) VALUES ('event.htm','menu_home'); +INSERT INTO fn_restricted_url (restricted_url, function_cd) VALUES ('event_list.htm','menu_home'); +INSERT INTO fn_restricted_url (restricted_url, function_cd) VALUES ('mobile_welcome.htm','menu_home'); +INSERT INTO fn_restricted_url (restricted_url, function_cd) VALUES ('sample_map.htm','menu_home'); +INSERT INTO fn_restricted_url (restricted_url, function_cd) VALUES ('template.jsp','menu_home'); +INSERT INTO fn_restricted_url (restricted_url, function_cd) VALUES ('zkau','menu_home'); +INSERT INTO fn_restricted_url (restricted_url, function_cd) VALUES ('itracker_assign.htm','menu_itracker'); +INSERT INTO fn_restricted_url (restricted_url, function_cd) VALUES ('itracker_byassignee.htm','menu_itracker'); +INSERT INTO fn_restricted_url (restricted_url, function_cd) VALUES ('itracker_create.htm','menu_itracker'); +INSERT INTO fn_restricted_url (restricted_url, function_cd) VALUES ('itracker_update.htm','menu_itracker'); +INSERT INTO fn_restricted_url (restricted_url, function_cd) VALUES ('manage_license.htm','menu_itracker'); +INSERT INTO fn_restricted_url (restricted_url, function_cd) VALUES ('support_ticket.htm','menu_itracker'); +INSERT INTO fn_restricted_url (restricted_url, function_cd) VALUES ('jbpm_designer.htm','menu_job_create'); -- check +INSERT INTO fn_restricted_url (restricted_url, function_cd) VALUES ('jbpm_drools.htm','menu_job_create'); -- check +INSERT INTO fn_restricted_url (restricted_url, function_cd) VALUES ('process_job.htm','menu_job_create'); +INSERT INTO fn_restricted_url (restricted_url, function_cd) VALUES ('profile.htm','menu_profile_create'); +INSERT INTO fn_restricted_url (restricted_url, function_cd) VALUES ('raptor.htm','menu_reports'); +INSERT INTO fn_restricted_url (restricted_url, function_cd) VALUES ('raptor2.htm','menu_reports'); +INSERT INTO fn_restricted_url (restricted_url, function_cd) VALUES ('raptor_blob_extract.htm','menu_reports'); +INSERT INTO fn_restricted_url (restricted_url, function_cd) VALUES ('raptor_email_attachment.htm','menu_reports'); +INSERT INTO fn_restricted_url (restricted_url, function_cd) VALUES ('raptor_search.htm','menu_reports'); +INSERT INTO fn_restricted_url (restricted_url, function_cd) VALUES ('report_list.htm','menu_reports'); +INSERT INTO fn_restricted_url (restricted_url, function_cd) VALUES ('gauge.htm','menu_tab'); +INSERT INTO fn_restricted_url (restricted_url, function_cd) VALUES ('gmap_controller.htm','menu_tab'); +INSERT INTO fn_restricted_url (restricted_url, function_cd) VALUES ('gmap_frame.htm','menu_tab'); +INSERT INTO fn_restricted_url (restricted_url, function_cd) VALUES ('map.htm','menu_tab'); +INSERT INTO fn_restricted_url (restricted_url, function_cd) VALUES ('map_download.htm','menu_tab'); +INSERT INTO fn_restricted_url (restricted_url, function_cd) VALUES ('map_grid_search.htm','menu_tab'); +INSERT INTO fn_restricted_url (restricted_url, function_cd) VALUES ('sample_animated_map.htm','menu_tab'); +INSERT INTO fn_restricted_url (restricted_url, function_cd) VALUES ('sample_map_2.htm','menu_tab'); +INSERT INTO fn_restricted_url (restricted_url, function_cd) VALUES ('sample_map_3.htm','menu_tab'); +INSERT INTO fn_restricted_url (restricted_url, function_cd) VALUES ('tab2_sub1.htm','menu_tab'); +INSERT INTO fn_restricted_url (restricted_url, function_cd) VALUES ('tab2_sub2_link1.htm','menu_tab'); +INSERT INTO fn_restricted_url (restricted_url, function_cd) VALUES ('tab2_sub2_link2.htm','menu_tab'); +INSERT INTO fn_restricted_url (restricted_url, function_cd) VALUES ('tab2_sub3.htm','menu_tab'); +INSERT INTO fn_restricted_url (restricted_url, function_cd) VALUES ('tab3.htm','menu_tab'); +INSERT INTO fn_restricted_url (restricted_url, function_cd) VALUES ('tab4.htm','menu_tab'); +INSERT INTO fn_restricted_url (restricted_url, function_cd) VALUES ('raptor.htm','view_reports'); +INSERT INTO fn_restricted_url (restricted_url, function_cd) VALUES ('raptor_blob_extract.htm','view_reports'); + +-- fn_role +Insert into fn_role (ROLE_ID,ROLE_NAME,ACTIVE_YN,PRIORITY) values (16,'Standard User','Y',5); +Insert into fn_role (ROLE_ID,ROLE_NAME,ACTIVE_YN,PRIORITY) values (1,'System Administrator','Y',1); + +-- fn_role_composite +Insert into fn_role_composite (PARENT_ROLE_ID,CHILD_ROLE_ID) values (1,16); + +-- fn_role_function +Insert into fn_role_function (ROLE_ID,FUNCTION_CD) values (1,'doclib'); +Insert into fn_role_function (ROLE_ID,FUNCTION_CD) values (1,'doclib_admin'); +Insert into fn_role_function (ROLE_ID,FUNCTION_CD) values (1,'login'); +Insert into fn_role_function (ROLE_ID,FUNCTION_CD) values (1,'menu_admin'); +Insert into fn_role_function (ROLE_ID,FUNCTION_CD) values (1,'menu_ajax'); +Insert into fn_role_function (ROLE_ID,FUNCTION_CD) values (1,'menu_customer'); +Insert into fn_role_function (ROLE_ID,FUNCTION_CD) values (1,'menu_customer_create'); +Insert into fn_role_function (ROLE_ID,FUNCTION_CD) values (1,'menu_feedback'); +Insert into fn_role_function (ROLE_ID,FUNCTION_CD) values (1,'menu_help'); +Insert into fn_role_function (ROLE_ID,FUNCTION_CD) values (1,'menu_home'); +Insert into fn_role_function (ROLE_ID,FUNCTION_CD) values (1,'menu_itracker'); +Insert into fn_role_function (ROLE_ID,FUNCTION_CD) values (1,'menu_itracker_admin'); +Insert into fn_role_function (ROLE_ID,FUNCTION_CD) values (1,'menu_job'); +Insert into fn_role_function (ROLE_ID,FUNCTION_CD) values (1,'menu_job_create'); +Insert into fn_role_function (ROLE_ID,FUNCTION_CD) values (1,'menu_logout'); +Insert into fn_role_function (ROLE_ID,FUNCTION_CD) values (1,'menu_notes'); +Insert into fn_role_function (ROLE_ID,FUNCTION_CD) values (1,'menu_process'); +Insert into fn_role_function (ROLE_ID,FUNCTION_CD) values (1,'menu_profile'); +Insert into fn_role_function (ROLE_ID,FUNCTION_CD) values (1,'menu_profile_create'); +Insert into fn_role_function (ROLE_ID,FUNCTION_CD) values (1,'menu_profile_import'); +Insert into fn_role_function (ROLE_ID,FUNCTION_CD) values (1,'menu_reports'); +Insert into fn_role_function (ROLE_ID,FUNCTION_CD) values (1,'menu_sample'); +Insert into fn_role_function (ROLE_ID,FUNCTION_CD) values (1,'menu_tab'); +Insert into fn_role_function (ROLE_ID,FUNCTION_CD) values (1,'menu_test'); +Insert into fn_role_function (ROLE_ID,FUNCTION_CD) values (16,'login'); +Insert into fn_role_function (ROLE_ID,FUNCTION_CD) values (16,'menu_ajax'); +Insert into fn_role_function (ROLE_ID,FUNCTION_CD) values (16,'menu_customer'); +Insert into fn_role_function (ROLE_ID,FUNCTION_CD) values (16,'menu_customer_create'); +Insert into fn_role_function (ROLE_ID,FUNCTION_CD) values (16,'menu_home'); +Insert into fn_role_function (ROLE_ID,FUNCTION_CD) values (16,'menu_itracker'); +Insert into fn_role_function (ROLE_ID,FUNCTION_CD) values (16,'menu_logout'); +Insert into fn_role_function (ROLE_ID,FUNCTION_CD) values (16,'menu_map'); +Insert into fn_role_function (ROLE_ID,FUNCTION_CD) values (16,'menu_profile'); +Insert into fn_role_function (ROLE_ID,FUNCTION_CD) values (16,'menu_reports'); +Insert into fn_role_function (ROLE_ID,FUNCTION_CD) values (16,'menu_tab'); + +-- fn_tab +Insert into fn_tab (TAB_CD,TAB_NAME,TAB_DESCR,ACTION,FUNCTION_CD,ACTIVE_YN,SORT_ORDER,PARENT_TAB_CD,TAB_SET_CD) values ('TAB2_SUB1_S1','Left Tab 1','Sub - Sub Tab 1 Information','tab2_sub1.htm','menu_tab','Y',10,'TAB2_SUB1','APP'); +Insert into fn_tab (TAB_CD,TAB_NAME,TAB_DESCR,ACTION,FUNCTION_CD,ACTIVE_YN,SORT_ORDER,PARENT_TAB_CD,TAB_SET_CD) values ('TAB1','Tab 1','Tab 1 Information','tab1.htm','menu_tab','Y',10,null,'APP'); +Insert into fn_tab (TAB_CD,TAB_NAME,TAB_DESCR,ACTION,FUNCTION_CD,ACTIVE_YN,SORT_ORDER,PARENT_TAB_CD,TAB_SET_CD) values ('TAB2','Tab 2','Tab 2 Information','tab2_sub1.htm','menu_tab','Y',20,null,'APP'); +Insert into fn_tab (TAB_CD,TAB_NAME,TAB_DESCR,ACTION,FUNCTION_CD,ACTIVE_YN,SORT_ORDER,PARENT_TAB_CD,TAB_SET_CD) values ('TAB3','Tab 3','Tab 3 Information','tab3.htm','menu_tab','Y',30,null,'APP'); +Insert into fn_tab (TAB_CD,TAB_NAME,TAB_DESCR,ACTION,FUNCTION_CD,ACTIVE_YN,SORT_ORDER,PARENT_TAB_CD,TAB_SET_CD) values ('TAB4','Tab 4','Tab 4 Information','tab4.htm','menu_tab','Y',40,null,'APP'); +Insert into fn_tab (TAB_CD,TAB_NAME,TAB_DESCR,ACTION,FUNCTION_CD,ACTIVE_YN,SORT_ORDER,PARENT_TAB_CD,TAB_SET_CD) values ('TAB2_SUB1','Sub Tab 1','Sub Tab 1 Information','tab2_sub1.htm','menu_tab','Y',10,'TAB2','APP'); +Insert into fn_tab (TAB_CD,TAB_NAME,TAB_DESCR,ACTION,FUNCTION_CD,ACTIVE_YN,SORT_ORDER,PARENT_TAB_CD,TAB_SET_CD) values ('TAB2_SUB2','Sub Tab 2','Sub Tab 2 Information','tab2_sub2.htm','menu_tab','Y',20,'TAB2','APP'); +Insert into fn_tab (TAB_CD,TAB_NAME,TAB_DESCR,ACTION,FUNCTION_CD,ACTIVE_YN,SORT_ORDER,PARENT_TAB_CD,TAB_SET_CD) values ('TAB2_SUB3','Sub Tab 3','Sub Tab 3 Information','tab2_sub3.htm','menu_tab','Y',30,'TAB2','APP'); + +-- fn_tab_selected +Insert into fn_tab_selected (SELECTED_TAB_CD,TAB_URI) values ('TAB1','tab1'); +Insert into fn_tab_selected (SELECTED_TAB_CD,TAB_URI) values ('TAB2','tab2_sub1'); +Insert into fn_tab_selected (SELECTED_TAB_CD,TAB_URI) values ('TAB2','tab2_sub2'); +Insert into fn_tab_selected (SELECTED_TAB_CD,TAB_URI) values ('TAB2','tab2_sub3'); +Insert into fn_tab_selected (SELECTED_TAB_CD,TAB_URI) values ('TAB2_SUB1','tab2_sub1'); +Insert into fn_tab_selected (SELECTED_TAB_CD,TAB_URI) values ('TAB2_SUB1_S1','tab2_sub1'); +Insert into fn_tab_selected (SELECTED_TAB_CD,TAB_URI) values ('TAB2_SUB2','tab2_sub2'); +Insert into fn_tab_selected (SELECTED_TAB_CD,TAB_URI) values ('TAB2_SUB3','tab2_sub3'); +Insert into fn_tab_selected (SELECTED_TAB_CD,TAB_URI) values ('TAB3','tab3'); +Insert into fn_tab_selected (SELECTED_TAB_CD,TAB_URI) values ('TAB4','tab4'); + +-- fn_user +Insert into fn_user (USER_ID,ORG_ID,MANAGER_ID,FIRST_NAME,MIDDLE_NAME,LAST_NAME,PHONE,FAX,CELLULAR,EMAIL,ADDRESS_ID,ALERT_METHOD_CD,HRID,ORG_USER_ID,ORG_CODE,LOGIN_ID,LOGIN_PWD,LAST_LOGIN_DATE,ACTIVE_YN,CREATED_ID,CREATED_DATE,MODIFIED_ID,MODIFIED_DATE,IS_INTERNAL_YN,ADDRESS_LINE_1,ADDRESS_LINE_2,CITY,STATE_CD,ZIP_CODE,COUNTRY_CD,LOCATION_CLLI,ORG_MANAGER_USERID,COMPANY,DEPARTMENT_NAME,JOB_TITLE,TIMEZONE,DEPARTMENT,BUSINESS_UNIT,BUSINESS_UNIT_NAME,COST_CENTER,FIN_LOC_CODE,SILO_STATUS) values (1,null,null,'Demo',null,'User',null,null,null,null,null,null,null,'demo',null,'demo','demo',str_to_date('24-OCT-16','%d-%M-%Y'),'Y',null,str_to_date('17-OCT-16','%d-%M-%Y'),1,str_to_date('24-OCT-16','%d-%M-%Y'),'N',null,null,null,'NJ',null,'US',null,null,null,null,null,10,null,null,null,null,null,null); + +-- cr_raptor_action_img +Insert into cr_raptor_action_img (IMAGE_ID, IMAGE_LOC) Values ('DELETE', '/static/fusion/raptor/img/deleteicon.gif'); +Insert into cr_raptor_action_img (IMAGE_ID, IMAGE_LOC) Values ('CALENDAR', '/static/fusion/raptor/img/Calendar-16x16.png'); + +-- fn_app +Insert into fn_app (APP_ID,APP_NAME,APP_IMAGE_URL,APP_DESCRIPTION,APP_NOTES,APP_URL,APP_ALTERNATE_URL,APP_REST_ENDPOINT,ML_APP_NAME,ML_APP_ADMIN_ID,MOTS_ID,APP_PASSWORD,OPEN,ENABLED,THUMBNAIL,APP_USERNAME,UEB_KEY,UEB_SECRET,UEB_TOPIC_NAME) VALUES (1,'Default',null,'Some Default Description','Some Default Note',null,null,null,'ECPP','?','1','app_password_here','N','N',null,'Default',null,null,'ECOMP-PORTAL-INBOX'); + +-- fn_user_role +Insert into fn_user_role (USER_ID,ROLE_ID,PRIORITY,APP_ID) values (1,1,null,1); + +-- DEMO_BAR_CHART +Insert into demo_bar_chart (label, value) values ('A', 29.765957771107); +Insert into demo_bar_chart (label, value) values ('B', 0); +Insert into demo_bar_chart (label, value) values ('C', 32.807804682612); +Insert into demo_bar_chart (label, value) values ('D', 196.45946739256); +Insert into demo_bar_chart (label, value) values ('E', 0.19434030906893); +Insert into demo_bar_chart (label, value) values ('F', 98.079782601442); +Insert into demo_bar_chart (label, value) values ('G', 13.925743130903); +Insert into demo_bar_chart (label, value) values ('H', 5.1387322875705); + +-- DEMO_BAR_CHART_INTER +Insert into demo_bar_chart_inter (spam_date, num_rpt_sources, num_det_sources) values (STR_TO_DATE('6-Mar-13','%e-%b-%y'), 198, 220); +Insert into demo_bar_chart_inter (spam_date, num_rpt_sources, num_det_sources) values (STR_TO_DATE('5-Mar-13','%e-%b-%y'), 198, 220); +Insert into demo_bar_chart_inter (spam_date, num_rpt_sources, num_det_sources) values (STR_TO_DATE('4-Mar-13','%e-%b-%y'), 238, 235); +Insert into demo_bar_chart_inter (spam_date, num_rpt_sources, num_det_sources) values (STR_TO_DATE('3-Mar-13','%e-%b-%y'), 238, 235); +Insert into demo_bar_chart_inter (spam_date, num_rpt_sources, num_det_sources) values (STR_TO_DATE('2-Mar-13','%e-%b-%y'), 256, 275); +Insert into demo_bar_chart_inter (spam_date, num_rpt_sources, num_det_sources) values (STR_TO_DATE('1-Mar-13','%e-%b-%y'), 239, 260); +Insert into demo_bar_chart_inter (spam_date, num_rpt_sources, num_det_sources) values (STR_TO_DATE('28-Feb-13','%e-%b-%y'), 247, 255); +Insert into demo_bar_chart_inter (spam_date, num_rpt_sources, num_det_sources) values (STR_TO_DATE('27-Feb-13','%e-%b-%y'), 252, 265); +Insert into demo_bar_chart_inter (spam_date, num_rpt_sources, num_det_sources) values (STR_TO_DATE('26-Feb-13','%e-%b-%y'), 198, 220); + +-- DEMO_LINE_CHART +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('1-May-12','%e-%b-%y'),582.13); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('30-Apr-12','%e-%b-%y'),583.98); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('27-Apr-12','%e-%b-%y'),603); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('26-Apr-12','%e-%b-%y'),607.7); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('25-Apr-12','%e-%b-%y'),610); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('24-Apr-12','%e-%b-%y'),560.28); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('23-Apr-12','%e-%b-%y'),571.7); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('20-Apr-12','%e-%b-%y'),572.98); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('19-Apr-12','%e-%b-%y'),587.44); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('18-Apr-12','%e-%b-%y'),608.34); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('17-Apr-12','%e-%b-%y'),609.7); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('16-Apr-12','%e-%b-%y'),580.13); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('13-Apr-12','%e-%b-%y'),605.23); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('12-Apr-12','%e-%b-%y'),622.77); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('11-Apr-12','%e-%b-%y'),626.2); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('10-Apr-12','%e-%b-%y'),628.44); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('9-Apr-12','%e-%b-%y'),636.23); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('5-Apr-12','%e-%b-%y'),633.68); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('4-Apr-12','%e-%b-%y'),624.31); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('3-Apr-12','%e-%b-%y'),629.32); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('2-Apr-12','%e-%b-%y'),618.63); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('30-Mar-12','%e-%b-%y'),599.55); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('29-Mar-12','%e-%b-%y'),609.86); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('28-Mar-12','%e-%b-%y'),617.62); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('27-Mar-12','%e-%b-%y'),614.48); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('26-Mar-12','%e-%b-%y'),606.98); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('23-Mar-12','%e-%b-%y'),596.05); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('22-Mar-12','%e-%b-%y'),599.34); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('21-Mar-12','%e-%b-%y'),602.5); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('20-Mar-12','%e-%b-%y'),605.96); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('19-Mar-12','%e-%b-%y'),601.1); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('16-Mar-12','%e-%b-%y'),585.57); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('15-Mar-12','%e-%b-%y'),585.56); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('14-Mar-12','%e-%b-%y'),589.58); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('13-Mar-12','%e-%b-%y'),568.1); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('12-Mar-12','%e-%b-%y'),552); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('9-Mar-12','%e-%b-%y'),545.17); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('8-Mar-12','%e-%b-%y'),541.99); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('7-Mar-12','%e-%b-%y'),530.69); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('6-Mar-12','%e-%b-%y'),530.26); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('5-Mar-12','%e-%b-%y'),533.16); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('2-Mar-12','%e-%b-%y'),545.18); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('1-Mar-12','%e-%b-%y'),544.47); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('29-Feb-12','%e-%b-%y'),542.44); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('28-Feb-12','%e-%b-%y'),535.41); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('27-Feb-12','%e-%b-%y'),525.76); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('24-Feb-12','%e-%b-%y'),522.41); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('23-Feb-12','%e-%b-%y'),516.39); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('22-Feb-12','%e-%b-%y'),513.04); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('21-Feb-12','%e-%b-%y'),514.85); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('17-Feb-12','%e-%b-%y'),502.12); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('16-Feb-12','%e-%b-%y'),502.21); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('15-Feb-12','%e-%b-%y'),497.67); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('14-Feb-12','%e-%b-%y'),509.46); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('13-Feb-12','%e-%b-%y'),502.6); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('10-Feb-12','%e-%b-%y'),493.42); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('9-Feb-12','%e-%b-%y'),493.17); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('8-Feb-12','%e-%b-%y'),476.68); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('7-Feb-12','%e-%b-%y'),468.83); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('6-Feb-12','%e-%b-%y'),463.97); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('3-Feb-12','%e-%b-%y'),459.68); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('2-Feb-12','%e-%b-%y'),455.12); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('1-Feb-12','%e-%b-%y'),456.19); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('31-Jan-12','%e-%b-%y'),456.48); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('30-Jan-12','%e-%b-%y'),453.01); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('27-Jan-12','%e-%b-%y'),447.28); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('26-Jan-12','%e-%b-%y'),444.63); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('25-Jan-12','%e-%b-%y'),446.66); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('24-Jan-12','%e-%b-%y'),420.41); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('23-Jan-12','%e-%b-%y'),427.41); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('20-Jan-12','%e-%b-%y'),420.3); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('19-Jan-12','%e-%b-%y'),427.75); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('18-Jan-12','%e-%b-%y'),429.11); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('17-Jan-12','%e-%b-%y'),424.7); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('13-Jan-12','%e-%b-%y'),419.81); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('12-Jan-12','%e-%b-%y'),421.39); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('11-Jan-12','%e-%b-%y'),422.55); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('10-Jan-12','%e-%b-%y'),423.24); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('9-Jan-12','%e-%b-%y'),421.73); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('6-Jan-12','%e-%b-%y'),422.4); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('5-Jan-12','%e-%b-%y'),418.03); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('4-Jan-12','%e-%b-%y'),413.44); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('3-Jan-12','%e-%b-%y'),411.23); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('30-Dec-11','%e-%b-%y'),405); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('29-Dec-11','%e-%b-%y'),405.12); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('28-Dec-11','%e-%b-%y'),402.64); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('27-Dec-11','%e-%b-%y'),406.53); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('23-Dec-11','%e-%b-%y'),403.43); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('22-Dec-11','%e-%b-%y'),398.55); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('21-Dec-11','%e-%b-%y'),396.44); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('20-Dec-11','%e-%b-%y'),395.95); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('19-Dec-11','%e-%b-%y'),382.21); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('16-Dec-11','%e-%b-%y'),381.02); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('15-Dec-11','%e-%b-%y'),378.94); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('14-Dec-11','%e-%b-%y'),380.19); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('13-Dec-11','%e-%b-%y'),388.81); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('12-Dec-11','%e-%b-%y'),391.84); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('9-Dec-11','%e-%b-%y'),393.62); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('8-Dec-11','%e-%b-%y'),390.66); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('7-Dec-11','%e-%b-%y'),389.09); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('6-Dec-11','%e-%b-%y'),390.95); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('5-Dec-11','%e-%b-%y'),393.01); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('2-Dec-11','%e-%b-%y'),389.7); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('1-Dec-11','%e-%b-%y'),387.93); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('30-Nov-11','%e-%b-%y'),382.2); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('29-Nov-11','%e-%b-%y'),373.2); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('28-Nov-11','%e-%b-%y'),376.12); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('25-Nov-11','%e-%b-%y'),363.57); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('23-Nov-11','%e-%b-%y'),366.99); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('22-Nov-11','%e-%b-%y'),376.51); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('21-Nov-11','%e-%b-%y'),369.01); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('18-Nov-11','%e-%b-%y'),374.94); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('17-Nov-11','%e-%b-%y'),377.41); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('16-Nov-11','%e-%b-%y'),384.77); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('15-Nov-11','%e-%b-%y'),388.83); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('14-Nov-11','%e-%b-%y'),379.26); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('11-Nov-11','%e-%b-%y'),384.62); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('10-Nov-11','%e-%b-%y'),385.22); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('9-Nov-11','%e-%b-%y'),395.28); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('8-Nov-11','%e-%b-%y'),406.23); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('7-Nov-11','%e-%b-%y'),399.73); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('4-Nov-11','%e-%b-%y'),400.24); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('3-Nov-11','%e-%b-%y'),403.07); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('2-Nov-11','%e-%b-%y'),397.41); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('1-Nov-11','%e-%b-%y'),396.51); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('31-Oct-11','%e-%b-%y'),404.78); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('28-Oct-11','%e-%b-%y'),404.95); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('27-Oct-11','%e-%b-%y'),404.69); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('26-Oct-11','%e-%b-%y'),400.6); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('25-Oct-11','%e-%b-%y'),397.77); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('24-Oct-11','%e-%b-%y'),405.77); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('21-Oct-11','%e-%b-%y'),392.87); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('20-Oct-11','%e-%b-%y'),395.31); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('19-Oct-11','%e-%b-%y'),398.62); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('18-Oct-11','%e-%b-%y'),422.24); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('17-Oct-11','%e-%b-%y'),419.99); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('14-Oct-11','%e-%b-%y'),422); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('13-Oct-11','%e-%b-%y'),408.43); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('12-Oct-11','%e-%b-%y'),402.19); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('11-Oct-11','%e-%b-%y'),400.29); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('10-Oct-11','%e-%b-%y'),388.81); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('7-Oct-11','%e-%b-%y'),369.8); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('6-Oct-11','%e-%b-%y'),377.37); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('5-Oct-11','%e-%b-%y'),378.25); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('4-Oct-11','%e-%b-%y'),372.5); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('3-Oct-11','%e-%b-%y'),374.6); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('30-Sep-11','%e-%b-%y'),381.32); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('29-Sep-11','%e-%b-%y'),390.57); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('28-Sep-11','%e-%b-%y'),397.01); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('27-Sep-11','%e-%b-%y'),399.26); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('26-Sep-11','%e-%b-%y'),403.17); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('23-Sep-11','%e-%b-%y'),404.3); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('22-Sep-11','%e-%b-%y'),401.82); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('21-Sep-11','%e-%b-%y'),412.14); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('20-Sep-11','%e-%b-%y'),413.45); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('19-Sep-11','%e-%b-%y'),411.63); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('16-Sep-11','%e-%b-%y'),400.5); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('15-Sep-11','%e-%b-%y'),392.96); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('14-Sep-11','%e-%b-%y'),389.3); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('13-Sep-11','%e-%b-%y'),384.62); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('12-Sep-11','%e-%b-%y'),379.94); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('9-Sep-11','%e-%b-%y'),377.48); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('8-Sep-11','%e-%b-%y'),384.14); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('7-Sep-11','%e-%b-%y'),383.93); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('6-Sep-11','%e-%b-%y'),379.74); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('2-Sep-11','%e-%b-%y'),374.05); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('1-Sep-11','%e-%b-%y'),381.03); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('31-Aug-11','%e-%b-%y'),384.83); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('30-Aug-11','%e-%b-%y'),389.99); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('29-Aug-11','%e-%b-%y'),389.97); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('26-Aug-11','%e-%b-%y'),383.58); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('25-Aug-11','%e-%b-%y'),373.72); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('24-Aug-11','%e-%b-%y'),376.18); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('23-Aug-11','%e-%b-%y'),373.6); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('22-Aug-11','%e-%b-%y'),356.44); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('19-Aug-11','%e-%b-%y'),356.03); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('18-Aug-11','%e-%b-%y'),366.05); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('17-Aug-11','%e-%b-%y'),380.44); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('16-Aug-11','%e-%b-%y'),380.48); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('15-Aug-11','%e-%b-%y'),383.41); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('12-Aug-11','%e-%b-%y'),376.99); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('11-Aug-11','%e-%b-%y'),373.7); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('10-Aug-11','%e-%b-%y'),363.69); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('9-Aug-11','%e-%b-%y'),374.01); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('8-Aug-11','%e-%b-%y'),353.21); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('5-Aug-11','%e-%b-%y'),373.62); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('4-Aug-11','%e-%b-%y'),377.37); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('3-Aug-11','%e-%b-%y'),392.57); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('2-Aug-11','%e-%b-%y'),388.91); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('1-Aug-11','%e-%b-%y'),396.75); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('29-Jul-11','%e-%b-%y'),390.48); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('28-Jul-11','%e-%b-%y'),391.82); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('27-Jul-11','%e-%b-%y'),392.59); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('26-Jul-11','%e-%b-%y'),403.41); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('25-Jul-11','%e-%b-%y'),398.5); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('22-Jul-11','%e-%b-%y'),393.3); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('21-Jul-11','%e-%b-%y'),387.29); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('20-Jul-11','%e-%b-%y'),386.9); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('19-Jul-11','%e-%b-%y'),376.85); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('18-Jul-11','%e-%b-%y'),373.8); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('15-Jul-11','%e-%b-%y'),364.92); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('14-Jul-11','%e-%b-%y'),357.77); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('13-Jul-11','%e-%b-%y'),358.02); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('12-Jul-11','%e-%b-%y'),353.75); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('11-Jul-11','%e-%b-%y'),354); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('8-Jul-11','%e-%b-%y'),359.71); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('7-Jul-11','%e-%b-%y'),357.2); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('6-Jul-11','%e-%b-%y'),351.76); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('5-Jul-11','%e-%b-%y'),349.43); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('1-Jul-11','%e-%b-%y'),343.26); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('30-Jun-11','%e-%b-%y'),335.67); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('29-Jun-11','%e-%b-%y'),334.04); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('28-Jun-11','%e-%b-%y'),335.26); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('27-Jun-11','%e-%b-%y'),332.04); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('24-Jun-11','%e-%b-%y'),326.35); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('23-Jun-11','%e-%b-%y'),331.23); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('22-Jun-11','%e-%b-%y'),322.61); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('21-Jun-11','%e-%b-%y'),325.3); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('20-Jun-11','%e-%b-%y'),315.32); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('17-Jun-11','%e-%b-%y'),320.26); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('16-Jun-11','%e-%b-%y'),325.16); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('15-Jun-11','%e-%b-%y'),326.75); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('14-Jun-11','%e-%b-%y'),332.44); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('13-Jun-11','%e-%b-%y'),326.6); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('10-Jun-11','%e-%b-%y'),325.9); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('9-Jun-11','%e-%b-%y'),331.49); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('8-Jun-11','%e-%b-%y'),332.24); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('7-Jun-11','%e-%b-%y'),332.04); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('6-Jun-11','%e-%b-%y'),338.04); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('3-Jun-11','%e-%b-%y'),343.44); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('2-Jun-11','%e-%b-%y'),346.1); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('1-Jun-11','%e-%b-%y'),345.51); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('31-May-11','%e-%b-%y'),347.83); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('27-May-11','%e-%b-%y'),337.41); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('26-May-11','%e-%b-%y'),335); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('25-May-11','%e-%b-%y'),336.78); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('24-May-11','%e-%b-%y'),332.19); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('23-May-11','%e-%b-%y'),334.4); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('20-May-11','%e-%b-%y'),335.22); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('19-May-11','%e-%b-%y'),340.53); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('18-May-11','%e-%b-%y'),339.87); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('17-May-11','%e-%b-%y'),336.14); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('16-May-11','%e-%b-%y'),333.3); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('13-May-11','%e-%b-%y'),340.5); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('12-May-11','%e-%b-%y'),346.57); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('11-May-11','%e-%b-%y'),347.23); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('10-May-11','%e-%b-%y'),349.45); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('9-May-11','%e-%b-%y'),347.6); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('6-May-11','%e-%b-%y'),346.66); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('5-May-11','%e-%b-%y'),346.75); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('4-May-11','%e-%b-%y'),349.57); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('3-May-11','%e-%b-%y'),348.2); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('2-May-11','%e-%b-%y'),346.28); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('29-Apr-11','%e-%b-%y'),350.13); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('28-Apr-11','%e-%b-%y'),346.75); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('27-Apr-11','%e-%b-%y'),350.15); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('26-Apr-11','%e-%b-%y'),350.42); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('25-Apr-11','%e-%b-%y'),353.01); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('21-Apr-11','%e-%b-%y'),350.7); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('20-Apr-11','%e-%b-%y'),342.41); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('19-Apr-11','%e-%b-%y'),337.86); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('18-Apr-11','%e-%b-%y'),331.85); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('15-Apr-11','%e-%b-%y'),327.46); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('14-Apr-11','%e-%b-%y'),332.42); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('13-Apr-11','%e-%b-%y'),336.13); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('12-Apr-11','%e-%b-%y'),332.4); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('11-Apr-11','%e-%b-%y'),330.8); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('8-Apr-11','%e-%b-%y'),335.06); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('7-Apr-11','%e-%b-%y'),338.08); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('6-Apr-11','%e-%b-%y'),338.04); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('5-Apr-11','%e-%b-%y'),338.89); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('4-Apr-11','%e-%b-%y'),341.19); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('1-Apr-11','%e-%b-%y'),344.56); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('31-Mar-11','%e-%b-%y'),348.51); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('30-Mar-11','%e-%b-%y'),348.63); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('29-Mar-11','%e-%b-%y'),350.96); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('28-Mar-11','%e-%b-%y'),350.44); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('25-Mar-11','%e-%b-%y'),351.54); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('24-Mar-11','%e-%b-%y'),344.97); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('23-Mar-11','%e-%b-%y'),339.19); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('22-Mar-11','%e-%b-%y'),341.2); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('21-Mar-11','%e-%b-%y'),339.3); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('18-Mar-11','%e-%b-%y'),330.67); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('17-Mar-11','%e-%b-%y'),334.64); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('16-Mar-11','%e-%b-%y'),330.01); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('15-Mar-11','%e-%b-%y'),345.43); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('14-Mar-11','%e-%b-%y'),353.56); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('11-Mar-11','%e-%b-%y'),351.99); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('10-Mar-11','%e-%b-%y'),346.67); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('9-Mar-11','%e-%b-%y'),352.47); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('8-Mar-11','%e-%b-%y'),355.76); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('7-Mar-11','%e-%b-%y'),355.36); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('4-Mar-11','%e-%b-%y'),360); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('3-Mar-11','%e-%b-%y'),359.56); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('2-Mar-11','%e-%b-%y'),352.12); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('1-Mar-11','%e-%b-%y'),349.31); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('28-Feb-11','%e-%b-%y'),353.21); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('25-Feb-11','%e-%b-%y'),348.16); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('24-Feb-11','%e-%b-%y'),342.88); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('23-Feb-11','%e-%b-%y'),342.62); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('22-Feb-11','%e-%b-%y'),338.61); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('18-Feb-11','%e-%b-%y'),350.56); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('17-Feb-11','%e-%b-%y'),358.3); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('16-Feb-11','%e-%b-%y'),363.13); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('15-Feb-11','%e-%b-%y'),359.9); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('14-Feb-11','%e-%b-%y'),359.18); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('11-Feb-11','%e-%b-%y'),356.85); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('10-Feb-11','%e-%b-%y'),354.54); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('9-Feb-11','%e-%b-%y'),358.16); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('8-Feb-11','%e-%b-%y'),355.2); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('7-Feb-11','%e-%b-%y'),351.88); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('4-Feb-11','%e-%b-%y'),346.5); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('3-Feb-11','%e-%b-%y'),343.44); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('2-Feb-11','%e-%b-%y'),344.32); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('1-Feb-11','%e-%b-%y'),345.03); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('31-Jan-11','%e-%b-%y'),339.32); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('28-Jan-11','%e-%b-%y'),336.1); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('27-Jan-11','%e-%b-%y'),343.21); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('26-Jan-11','%e-%b-%y'),343.85); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('25-Jan-11','%e-%b-%y'),341.4); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('24-Jan-11','%e-%b-%y'),337.45); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('21-Jan-11','%e-%b-%y'),326.72); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('20-Jan-11','%e-%b-%y'),332.68); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('19-Jan-11','%e-%b-%y'),338.84); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('18-Jan-11','%e-%b-%y'),340.65); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('14-Jan-11','%e-%b-%y'),348.48); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('13-Jan-11','%e-%b-%y'),345.68); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('12-Jan-11','%e-%b-%y'),344.42); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('11-Jan-11','%e-%b-%y'),341.64); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('10-Jan-11','%e-%b-%y'),342.46); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('7-Jan-11','%e-%b-%y'),336.12); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('6-Jan-11','%e-%b-%y'),333.73); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('5-Jan-11','%e-%b-%y'),334); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('4-Jan-11','%e-%b-%y'),331.29); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('3-Jan-11','%e-%b-%y'),329.57); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('31-Dec-10','%e-%b-%y'),322.56); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('30-Dec-10','%e-%b-%y'),323.66); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('29-Dec-10','%e-%b-%y'),325.29); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('28-Dec-10','%e-%b-%y'),325.47); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('27-Dec-10','%e-%b-%y'),324.68); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('23-Dec-10','%e-%b-%y'),323.6); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('22-Dec-10','%e-%b-%y'),325.16); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('21-Dec-10','%e-%b-%y'),324.2); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('20-Dec-10','%e-%b-%y'),322.21); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('17-Dec-10','%e-%b-%y'),320.61); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('16-Dec-10','%e-%b-%y'),321.25); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('15-Dec-10','%e-%b-%y'),320.36); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('14-Dec-10','%e-%b-%y'),320.29); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('13-Dec-10','%e-%b-%y'),321.67); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('10-Dec-10','%e-%b-%y'),320.56); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('9-Dec-10','%e-%b-%y'),319.76); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('8-Dec-10','%e-%b-%y'),321.01); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('7-Dec-10','%e-%b-%y'),318.21); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('6-Dec-10','%e-%b-%y'),320.15); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('3-Dec-10','%e-%b-%y'),317.44); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('2-Dec-10','%e-%b-%y'),318.15); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('1-Dec-10','%e-%b-%y'),316.4); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('30-Nov-10','%e-%b-%y'),311.15); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('29-Nov-10','%e-%b-%y'),316.87); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('26-Nov-10','%e-%b-%y'),315); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('24-Nov-10','%e-%b-%y'),314.8); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('23-Nov-10','%e-%b-%y'),308.73); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('22-Nov-10','%e-%b-%y'),313.36); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('19-Nov-10','%e-%b-%y'),306.73); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('18-Nov-10','%e-%b-%y'),308.43); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('17-Nov-10','%e-%b-%y'),300.5); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('16-Nov-10','%e-%b-%y'),301.59); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('15-Nov-10','%e-%b-%y'),307.04); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('12-Nov-10','%e-%b-%y'),308.03); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('11-Nov-10','%e-%b-%y'),316.66); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('10-Nov-10','%e-%b-%y'),318.03); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('9-Nov-10','%e-%b-%y'),316.08); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('8-Nov-10','%e-%b-%y'),318.62); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('5-Nov-10','%e-%b-%y'),317.13); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('4-Nov-10','%e-%b-%y'),318.27); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('3-Nov-10','%e-%b-%y'),312.8); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('2-Nov-10','%e-%b-%y'),309.36); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('1-Nov-10','%e-%b-%y'),304.18); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('29-Oct-10','%e-%b-%y'),300.98); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('28-Oct-10','%e-%b-%y'),305.24); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('27-Oct-10','%e-%b-%y'),307.83); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('26-Oct-10','%e-%b-%y'),308.05); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('25-Oct-10','%e-%b-%y'),308.84); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('22-Oct-10','%e-%b-%y'),307.47); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('21-Oct-10','%e-%b-%y'),309.52); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('20-Oct-10','%e-%b-%y'),310.53); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('19-Oct-10','%e-%b-%y'),309.49); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('18-Oct-10','%e-%b-%y'),318); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('15-Oct-10','%e-%b-%y'),314.74); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('14-Oct-10','%e-%b-%y'),302.31); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('13-Oct-10','%e-%b-%y'),300.14); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('12-Oct-10','%e-%b-%y'),298.54); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('11-Oct-10','%e-%b-%y'),295.36); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('8-Oct-10','%e-%b-%y'),294.07); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('7-Oct-10','%e-%b-%y'),289.22); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('6-Oct-10','%e-%b-%y'),289.19); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('5-Oct-10','%e-%b-%y'),288.94); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('4-Oct-10','%e-%b-%y'),278.64); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('1-Oct-10','%e-%b-%y'),282.52); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('30-Sep-10','%e-%b-%y'),283.75); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('29-Sep-10','%e-%b-%y'),287.37); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('28-Sep-10','%e-%b-%y'),286.86); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('27-Sep-10','%e-%b-%y'),291.16); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('24-Sep-10','%e-%b-%y'),292.32); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('23-Sep-10','%e-%b-%y'),288.92); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('22-Sep-10','%e-%b-%y'),287.75); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('21-Sep-10','%e-%b-%y'),283.77); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('20-Sep-10','%e-%b-%y'),283.23); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('17-Sep-10','%e-%b-%y'),275.37); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('16-Sep-10','%e-%b-%y'),276.57); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('15-Sep-10','%e-%b-%y'),270.22); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('14-Sep-10','%e-%b-%y'),268.06); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('13-Sep-10','%e-%b-%y'),267.04); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('10-Sep-10','%e-%b-%y'),263.41); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('9-Sep-10','%e-%b-%y'),263.07); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('8-Sep-10','%e-%b-%y'),262.92); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('7-Sep-10','%e-%b-%y'),257.81); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('6-Sep-10','%e-%b-%y'),258.77); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('3-Sep-10','%e-%b-%y'),258.77); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('2-Sep-10','%e-%b-%y'),252.17); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('1-Sep-10','%e-%b-%y'),250.33); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('31-Aug-10','%e-%b-%y'),243.1); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('30-Aug-10','%e-%b-%y'),242.5); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('27-Aug-10','%e-%b-%y'),241.62); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('26-Aug-10','%e-%b-%y'),240.28); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('25-Aug-10','%e-%b-%y'),242.89); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('24-Aug-10','%e-%b-%y'),239.93); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('23-Aug-10','%e-%b-%y'),245.8); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('20-Aug-10','%e-%b-%y'),249.64); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('19-Aug-10','%e-%b-%y'),249.88); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('18-Aug-10','%e-%b-%y'),253.07); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('17-Aug-10','%e-%b-%y'),251.97); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('16-Aug-10','%e-%b-%y'),247.64); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('13-Aug-10','%e-%b-%y'),249.1); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('12-Aug-10','%e-%b-%y'),251.79); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('11-Aug-10','%e-%b-%y'),250.19); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('10-Aug-10','%e-%b-%y'),259.41); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('9-Aug-10','%e-%b-%y'),261.75); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('6-Aug-10','%e-%b-%y'),260.09); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('5-Aug-10','%e-%b-%y'),261.7); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('4-Aug-10','%e-%b-%y'),262.98); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('3-Aug-10','%e-%b-%y'),261.93); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('2-Aug-10','%e-%b-%y'),261.85); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('30-Jul-10','%e-%b-%y'),257.25); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('29-Jul-10','%e-%b-%y'),258.11); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('28-Jul-10','%e-%b-%y'),260.96); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('27-Jul-10','%e-%b-%y'),264.08); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('26-Jul-10','%e-%b-%y'),259.28); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('23-Jul-10','%e-%b-%y'),259.94); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('22-Jul-10','%e-%b-%y'),259.02); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('21-Jul-10','%e-%b-%y'),254.24); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('20-Jul-10','%e-%b-%y'),251.89); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('19-Jul-10','%e-%b-%y'),245.58); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('16-Jul-10','%e-%b-%y'),249.9); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('15-Jul-10','%e-%b-%y'),251.45); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('14-Jul-10','%e-%b-%y'),252.73); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('13-Jul-10','%e-%b-%y'),251.8); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('12-Jul-10','%e-%b-%y'),257.28); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('9-Jul-10','%e-%b-%y'),259.62); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('8-Jul-10','%e-%b-%y'),258.09); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('7-Jul-10','%e-%b-%y'),258.66); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('6-Jul-10','%e-%b-%y'),248.63); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('5-Jul-10','%e-%b-%y'),246.94); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('2-Jul-10','%e-%b-%y'),246.94); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('1-Jul-10','%e-%b-%y'),248.48); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('30-Jun-10','%e-%b-%y'),251.53); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('29-Jun-10','%e-%b-%y'),256.17); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('28-Jun-10','%e-%b-%y'),268.3); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('25-Jun-10','%e-%b-%y'),266.7); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('24-Jun-10','%e-%b-%y'),269); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('23-Jun-10','%e-%b-%y'),270.97); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('22-Jun-10','%e-%b-%y'),273.85); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('21-Jun-10','%e-%b-%y'),270.17); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('18-Jun-10','%e-%b-%y'),274.07); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('17-Jun-10','%e-%b-%y'),271.87); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('16-Jun-10','%e-%b-%y'),267.25); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('15-Jun-10','%e-%b-%y'),259.69); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('14-Jun-10','%e-%b-%y'),254.28); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('11-Jun-10','%e-%b-%y'),253.51); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('10-Jun-10','%e-%b-%y'),250.51); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('9-Jun-10','%e-%b-%y'),243.2); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('8-Jun-10','%e-%b-%y'),249.33); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('7-Jun-10','%e-%b-%y'),250.94); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('4-Jun-10','%e-%b-%y'),255.96); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('3-Jun-10','%e-%b-%y'),263.12); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('2-Jun-10','%e-%b-%y'),263.95); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('1-Jun-10','%e-%b-%y'),260.83); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('31-May-10','%e-%b-%y'),256.88); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('28-May-10','%e-%b-%y'),256.88); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('27-May-10','%e-%b-%y'),253.35); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('26-May-10','%e-%b-%y'),244.11); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('25-May-10','%e-%b-%y'),245.22); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('24-May-10','%e-%b-%y'),246.76); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('21-May-10','%e-%b-%y'),242.32); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('20-May-10','%e-%b-%y'),237.76); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('19-May-10','%e-%b-%y'),248.34); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('18-May-10','%e-%b-%y'),252.36); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('17-May-10','%e-%b-%y'),254.22); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('14-May-10','%e-%b-%y'),253.82); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('13-May-10','%e-%b-%y'),258.36); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('12-May-10','%e-%b-%y'),262.09); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('11-May-10','%e-%b-%y'),256.52); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('10-May-10','%e-%b-%y'),253.99); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('7-May-10','%e-%b-%y'),235.86); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('6-May-10','%e-%b-%y'),246.25); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('5-May-10','%e-%b-%y'),255.98); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('4-May-10','%e-%b-%y'),258.68); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('3-May-10','%e-%b-%y'),266.35); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('30-Apr-10','%e-%b-%y'),261.09); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('29-Apr-10','%e-%b-%y'),268.64); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('28-Apr-10','%e-%b-%y'),261.6); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('27-Apr-10','%e-%b-%y'),262.04); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('26-Apr-10','%e-%b-%y'),269.5); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('23-Apr-10','%e-%b-%y'),270.83); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('22-Apr-10','%e-%b-%y'),266.47); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('21-Apr-10','%e-%b-%y'),259.22); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('20-Apr-10','%e-%b-%y'),244.59); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('19-Apr-10','%e-%b-%y'),247.07); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('16-Apr-10','%e-%b-%y'),247.4); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('15-Apr-10','%e-%b-%y'),248.92); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('14-Apr-10','%e-%b-%y'),245.69); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('13-Apr-10','%e-%b-%y'),242.43); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('12-Apr-10','%e-%b-%y'),242.29); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('9-Apr-10','%e-%b-%y'),241.79); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('8-Apr-10','%e-%b-%y'),239.95); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('7-Apr-10','%e-%b-%y'),240.6); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('6-Apr-10','%e-%b-%y'),239.54); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('5-Apr-10','%e-%b-%y'),238.49); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('2-Apr-10','%e-%b-%y'),235.97); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('1-Apr-10','%e-%b-%y'),235.97); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('31-Mar-10','%e-%b-%y'),235); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('30-Mar-10','%e-%b-%y'),235.84); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('29-Mar-10','%e-%b-%y'),232.39); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('26-Mar-10','%e-%b-%y'),230.9); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('25-Mar-10','%e-%b-%y'),226.65); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('24-Mar-10','%e-%b-%y'),229.37); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('23-Mar-10','%e-%b-%y'),228.36); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('22-Mar-10','%e-%b-%y'),224.75); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('19-Mar-10','%e-%b-%y'),222.25); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('18-Mar-10','%e-%b-%y'),224.65); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('17-Mar-10','%e-%b-%y'),224.12); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('16-Mar-10','%e-%b-%y'),224.45); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('15-Mar-10','%e-%b-%y'),223.84); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('12-Mar-10','%e-%b-%y'),226.6); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('11-Mar-10','%e-%b-%y'),225.5); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('10-Mar-10','%e-%b-%y'),224.84); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('9-Mar-10','%e-%b-%y'),223.02); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('8-Mar-10','%e-%b-%y'),219.08); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('5-Mar-10','%e-%b-%y'),218.95); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('4-Mar-10','%e-%b-%y'),210.71); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('3-Mar-10','%e-%b-%y'),209.33); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('2-Mar-10','%e-%b-%y'),208.85); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('1-Mar-10','%e-%b-%y'),208.99); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('26-Feb-10','%e-%b-%y'),204.62); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('25-Feb-10','%e-%b-%y'),202); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('24-Feb-10','%e-%b-%y'),200.66); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('23-Feb-10','%e-%b-%y'),197.06); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('22-Feb-10','%e-%b-%y'),200.42); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('19-Feb-10','%e-%b-%y'),201.67); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('18-Feb-10','%e-%b-%y'),202.93); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('17-Feb-10','%e-%b-%y'),202.55); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('16-Feb-10','%e-%b-%y'),203.4); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('15-Feb-10','%e-%b-%y'),200.38); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('12-Feb-10','%e-%b-%y'),200.38); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('11-Feb-10','%e-%b-%y'),198.67); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('10-Feb-10','%e-%b-%y'),195.12); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('9-Feb-10','%e-%b-%y'),196.19); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('8-Feb-10','%e-%b-%y'),194.12); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('5-Feb-10','%e-%b-%y'),195.46); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('4-Feb-10','%e-%b-%y'),192.05); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('3-Feb-10','%e-%b-%y'),199.23); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('2-Feb-10','%e-%b-%y'),195.86); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('1-Feb-10','%e-%b-%y'),194.73); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('29-Jan-10','%e-%b-%y'),192.06); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('28-Jan-10','%e-%b-%y'),199.29); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('27-Jan-10','%e-%b-%y'),207.88); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('26-Jan-10','%e-%b-%y'),205.94); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('25-Jan-10','%e-%b-%y'),203.08); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('22-Jan-10','%e-%b-%y'),197.75); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('21-Jan-10','%e-%b-%y'),208.07); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('20-Jan-10','%e-%b-%y'),211.72); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('19-Jan-10','%e-%b-%y'),215.04); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('18-Jan-10','%e-%b-%y'),205.93); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('15-Jan-10','%e-%b-%y'),205.93); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('14-Jan-10','%e-%b-%y'),209.43); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('13-Jan-10','%e-%b-%y'),210.65); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('12-Jan-10','%e-%b-%y'),207.72); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('11-Jan-10','%e-%b-%y'),210.11); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('8-Jan-10','%e-%b-%y'),211.98); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('7-Jan-10','%e-%b-%y'),210.58); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('6-Jan-10','%e-%b-%y'),210.97); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('5-Jan-10','%e-%b-%y'),214.38); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('4-Jan-10','%e-%b-%y'),214.01); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('1-Jan-10','%e-%b-%y'),210.73); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('31-Dec-09','%e-%b-%y'),210.73); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('30-Dec-09','%e-%b-%y'),211.64); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('29-Dec-09','%e-%b-%y'),209.1); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('28-Dec-09','%e-%b-%y'),211.61); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('25-Dec-09','%e-%b-%y'),209.04); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('24-Dec-09','%e-%b-%y'),209.04); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('23-Dec-09','%e-%b-%y'),202.1); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('22-Dec-09','%e-%b-%y'),200.36); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('21-Dec-09','%e-%b-%y'),198.23); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('18-Dec-09','%e-%b-%y'),195.43); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('17-Dec-09','%e-%b-%y'),191.86); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('16-Dec-09','%e-%b-%y'),195.03); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('15-Dec-09','%e-%b-%y'),194.17); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('14-Dec-09','%e-%b-%y'),196.98); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('11-Dec-09','%e-%b-%y'),194.67); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('10-Dec-09','%e-%b-%y'),196.43); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('9-Dec-09','%e-%b-%y'),197.8); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('8-Dec-09','%e-%b-%y'),189.87); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('7-Dec-09','%e-%b-%y'),188.95); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('4-Dec-09','%e-%b-%y'),193.32); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('3-Dec-09','%e-%b-%y'),196.48); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('2-Dec-09','%e-%b-%y'),196.23); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('1-Dec-09','%e-%b-%y'),196.97); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('30-Nov-09','%e-%b-%y'),199.91); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('27-Nov-09','%e-%b-%y'),200.59); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('26-Nov-09','%e-%b-%y'),204.19); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('25-Nov-09','%e-%b-%y'),204.19); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('24-Nov-09','%e-%b-%y'),204.44); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('23-Nov-09','%e-%b-%y'),205.88); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('20-Nov-09','%e-%b-%y'),199.92); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('19-Nov-09','%e-%b-%y'),200.51); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('18-Nov-09','%e-%b-%y'),205.96); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('17-Nov-09','%e-%b-%y'),207); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('16-Nov-09','%e-%b-%y'),206.63); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('13-Nov-09','%e-%b-%y'),204.45); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('12-Nov-09','%e-%b-%y'),201.99); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('11-Nov-09','%e-%b-%y'),203.25); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('10-Nov-09','%e-%b-%y'),202.98); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('9-Nov-09','%e-%b-%y'),201.46); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('6-Nov-09','%e-%b-%y'),194.34); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('5-Nov-09','%e-%b-%y'),194.03); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('4-Nov-09','%e-%b-%y'),190.81); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('3-Nov-09','%e-%b-%y'),188.75); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('2-Nov-09','%e-%b-%y'),189.31); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('30-Oct-09','%e-%b-%y'),188.5); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('29-Oct-09','%e-%b-%y'),196.35); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('28-Oct-09','%e-%b-%y'),192.4); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('27-Oct-09','%e-%b-%y'),197.37); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('26-Oct-09','%e-%b-%y'),202.48); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('23-Oct-09','%e-%b-%y'),203.94); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('22-Oct-09','%e-%b-%y'),205.2); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('21-Oct-09','%e-%b-%y'),204.92); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('20-Oct-09','%e-%b-%y'),198.76); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('19-Oct-09','%e-%b-%y'),189.86); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('16-Oct-09','%e-%b-%y'),188.05); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('15-Oct-09','%e-%b-%y'),190.56); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('14-Oct-09','%e-%b-%y'),191.29); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('13-Oct-09','%e-%b-%y'),190.02); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('12-Oct-09','%e-%b-%y'),190.81); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('9-Oct-09','%e-%b-%y'),190.47); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('8-Oct-09','%e-%b-%y'),189.27); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('7-Oct-09','%e-%b-%y'),190.25); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('6-Oct-09','%e-%b-%y'),190.01); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('5-Oct-09','%e-%b-%y'),186.02); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('2-Oct-09','%e-%b-%y'),184.9); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('1-Oct-09','%e-%b-%y'),180.86); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('30-Sep-09','%e-%b-%y'),185.35); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('29-Sep-09','%e-%b-%y'),185.38); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('28-Sep-09','%e-%b-%y'),186.15); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('25-Sep-09','%e-%b-%y'),182.37); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('24-Sep-09','%e-%b-%y'),183.82); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('23-Sep-09','%e-%b-%y'),185.5); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('22-Sep-09','%e-%b-%y'),184.48); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('21-Sep-09','%e-%b-%y'),184.02); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('18-Sep-09','%e-%b-%y'),185.02); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('17-Sep-09','%e-%b-%y'),184.55); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('16-Sep-09','%e-%b-%y'),181.87); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('15-Sep-09','%e-%b-%y'),175.16); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('14-Sep-09','%e-%b-%y'),173.72); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('11-Sep-09','%e-%b-%y'),172.16); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('10-Sep-09','%e-%b-%y'),172.56); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('9-Sep-09','%e-%b-%y'),171.14); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('8-Sep-09','%e-%b-%y'),172.93); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('4-Sep-09','%e-%b-%y'),170.31); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('3-Sep-09','%e-%b-%y'),166.55); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('2-Sep-09','%e-%b-%y'),165.18); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('1-Sep-09','%e-%b-%y'),165.3); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('31-Aug-09','%e-%b-%y'),168.21); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('28-Aug-09','%e-%b-%y'),170.05); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('27-Aug-09','%e-%b-%y'),169.45); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('26-Aug-09','%e-%b-%y'),167.41); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('25-Aug-09','%e-%b-%y'),169.4); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('24-Aug-09','%e-%b-%y'),169.06); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('21-Aug-09','%e-%b-%y'),169.22); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('20-Aug-09','%e-%b-%y'),166.33); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('19-Aug-09','%e-%b-%y'),164.6); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('18-Aug-09','%e-%b-%y'),164); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('17-Aug-09','%e-%b-%y'),159.59); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('14-Aug-09','%e-%b-%y'),166.78); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('13-Aug-09','%e-%b-%y'),168.42); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('12-Aug-09','%e-%b-%y'),165.31); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('10-Aug-09','%e-%b-%y'),164.72); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('7-Aug-09','%e-%b-%y'),165.51); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('6-Aug-09','%e-%b-%y'),163.91); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('5-Aug-09','%e-%b-%y'),165.11); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('4-Aug-09','%e-%b-%y'),165.55); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('3-Aug-09','%e-%b-%y'),166.43); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('31-Jul-09','%e-%b-%y'),163.39); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('30-Jul-09','%e-%b-%y'),162.79); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('29-Jul-09','%e-%b-%y'),160.03); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('28-Jul-09','%e-%b-%y'),160); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('27-Jul-09','%e-%b-%y'),160.1); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('24-Jul-09','%e-%b-%y'),159.99); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('23-Jul-09','%e-%b-%y'),157.82); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('22-Jul-09','%e-%b-%y'),156.74); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('21-Jul-09','%e-%b-%y'),151.51); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('20-Jul-09','%e-%b-%y'),152.91); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('17-Jul-09','%e-%b-%y'),151.75); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('16-Jul-09','%e-%b-%y'),147.52); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('15-Jul-09','%e-%b-%y'),146.88); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('14-Jul-09','%e-%b-%y'),142.27); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('13-Jul-09','%e-%b-%y'),142.34); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('10-Jul-09','%e-%b-%y'),138.52); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('9-Jul-09','%e-%b-%y'),136.36); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('8-Jul-09','%e-%b-%y'),137.22); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('7-Jul-09','%e-%b-%y'),135.4); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('6-Jul-09','%e-%b-%y'),138.61); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('3-Jul-09','%e-%b-%y'),140.02); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('2-Jul-09','%e-%b-%y'),140.02); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('1-Jul-09','%e-%b-%y'),142.83); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('30-Jun-09','%e-%b-%y'),142.43); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('29-Jun-09','%e-%b-%y'),141.97); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('26-Jun-09','%e-%b-%y'),142.44); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('25-Jun-09','%e-%b-%y'),139.86); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('24-Jun-09','%e-%b-%y'),136.22); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('23-Jun-09','%e-%b-%y'),134.01); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('22-Jun-09','%e-%b-%y'),137.37); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('19-Jun-09','%e-%b-%y'),139.48); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('18-Jun-09','%e-%b-%y'),135.88); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('17-Jun-09','%e-%b-%y'),135.58); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('16-Jun-09','%e-%b-%y'),136.35); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('15-Jun-09','%e-%b-%y'),136.09); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('12-Jun-09','%e-%b-%y'),136.97); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('11-Jun-09','%e-%b-%y'),139.95); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('10-Jun-09','%e-%b-%y'),140.25); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('9-Jun-09','%e-%b-%y'),142.72); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('8-Jun-09','%e-%b-%y'),143.85); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('5-Jun-09','%e-%b-%y'),144.67); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('4-Jun-09','%e-%b-%y'),143.74); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('3-Jun-09','%e-%b-%y'),140.95); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('2-Jun-09','%e-%b-%y'),139.49); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('1-Jun-09','%e-%b-%y'),139.35); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('29-May-09','%e-%b-%y'),135.81); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('28-May-09','%e-%b-%y'),135.07); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('27-May-09','%e-%b-%y'),133.05); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('26-May-09','%e-%b-%y'),130.78); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('22-May-09','%e-%b-%y'),122.5); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('21-May-09','%e-%b-%y'),124.18); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('20-May-09','%e-%b-%y'),125.87); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('19-May-09','%e-%b-%y'),127.45); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('18-May-09','%e-%b-%y'),126.65); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('15-May-09','%e-%b-%y'),122.42); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('14-May-09','%e-%b-%y'),122.95); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('13-May-09','%e-%b-%y'),119.49); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('12-May-09','%e-%b-%y'),124.42); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('11-May-09','%e-%b-%y'),129.57); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('8-May-09','%e-%b-%y'),129.19); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('7-May-09','%e-%b-%y'),129.06); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('6-May-09','%e-%b-%y'),132.5); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('5-May-09','%e-%b-%y'),132.71); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('4-May-09','%e-%b-%y'),132.07); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('1-May-09','%e-%b-%y'),127.24); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('30-Apr-09','%e-%b-%y'),125.83); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('29-Apr-09','%e-%b-%y'),125.14); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('28-Apr-09','%e-%b-%y'),123.9); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('27-Apr-09','%e-%b-%y'),124.73); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('24-Apr-09','%e-%b-%y'),123.9); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('23-Apr-09','%e-%b-%y'),125.4); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('22-Apr-09','%e-%b-%y'),121.51); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('21-Apr-09','%e-%b-%y'),121.76); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('20-Apr-09','%e-%b-%y'),120.5); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('17-Apr-09','%e-%b-%y'),123.42); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('16-Apr-09','%e-%b-%y'),121.45); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('15-Apr-09','%e-%b-%y'),117.64); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('14-Apr-09','%e-%b-%y'),118.31); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('13-Apr-09','%e-%b-%y'),120.22); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('10-Apr-09','%e-%b-%y'),119.57); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('9-Apr-09','%e-%b-%y'),119.57); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('8-Apr-09','%e-%b-%y'),116.32); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('7-Apr-09','%e-%b-%y'),115); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('6-Apr-09','%e-%b-%y'),118.45); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('3-Apr-09','%e-%b-%y'),115.99); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('2-Apr-09','%e-%b-%y'),112.71); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('1-Apr-09','%e-%b-%y'),108.69); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('31-Mar-09','%e-%b-%y'),105.12); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('30-Mar-09','%e-%b-%y'),104.49); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('27-Mar-09','%e-%b-%y'),106.85); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('26-Mar-09','%e-%b-%y'),109.87); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('25-Mar-09','%e-%b-%y'),106.49); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('24-Mar-09','%e-%b-%y'),106.5); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('23-Mar-09','%e-%b-%y'),107.66); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('20-Mar-09','%e-%b-%y'),101.59); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('19-Mar-09','%e-%b-%y'),101.62); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('18-Mar-09','%e-%b-%y'),101.52); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('17-Mar-09','%e-%b-%y'),99.66); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('16-Mar-09','%e-%b-%y'),95.42); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('13-Mar-09','%e-%b-%y'),95.93); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('12-Mar-09','%e-%b-%y'),96.35); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('11-Mar-09','%e-%b-%y'),92.68); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('10-Mar-09','%e-%b-%y'),88.63); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('9-Mar-09','%e-%b-%y'),83.11); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('6-Mar-09','%e-%b-%y'),85.3); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('5-Mar-09','%e-%b-%y'),88.84); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('4-Mar-09','%e-%b-%y'),91.17); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('3-Mar-09','%e-%b-%y'),88.37); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('2-Mar-09','%e-%b-%y'),87.94); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('27-Feb-09','%e-%b-%y'),89.31); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('26-Feb-09','%e-%b-%y'),89.19); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('25-Feb-09','%e-%b-%y'),91.16); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('24-Feb-09','%e-%b-%y'),90.25); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('23-Feb-09','%e-%b-%y'),86.95); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('20-Feb-09','%e-%b-%y'),91.2); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('19-Feb-09','%e-%b-%y'),90.64); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('18-Feb-09','%e-%b-%y'),94.37); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('17-Feb-09','%e-%b-%y'),94.53); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('13-Feb-09','%e-%b-%y'),99.16); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('12-Feb-09','%e-%b-%y'),99.27); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('11-Feb-09','%e-%b-%y'),96.82); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('10-Feb-09','%e-%b-%y'),97.83); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('9-Feb-09','%e-%b-%y'),102.51); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('6-Feb-09','%e-%b-%y'),99.72); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('5-Feb-09','%e-%b-%y'),96.46); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('4-Feb-09','%e-%b-%y'),93.55); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('3-Feb-09','%e-%b-%y'),92.98); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('2-Feb-09','%e-%b-%y'),91.51); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('30-Jan-09','%e-%b-%y'),90.13); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('29-Jan-09','%e-%b-%y'),93); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('28-Jan-09','%e-%b-%y'),94.2); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('27-Jan-09','%e-%b-%y'),90.73); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('26-Jan-09','%e-%b-%y'),89.64); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('23-Jan-09','%e-%b-%y'),88.36); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('22-Jan-09','%e-%b-%y'),88.36); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('21-Jan-09','%e-%b-%y'),82.83); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('20-Jan-09','%e-%b-%y'),78.2); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('16-Jan-09','%e-%b-%y'),82.33); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('15-Jan-09','%e-%b-%y'),83.38); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('14-Jan-09','%e-%b-%y'),85.33); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('13-Jan-09','%e-%b-%y'),87.71); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('12-Jan-09','%e-%b-%y'),88.66); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('9-Jan-09','%e-%b-%y'),90.58); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('8-Jan-09','%e-%b-%y'),92.7); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('7-Jan-09','%e-%b-%y'),91.01); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('6-Jan-09','%e-%b-%y'),93.02); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('5-Jan-09','%e-%b-%y'),94.58); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('2-Jan-09','%e-%b-%y'),90.75); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('1-Jan-09','%e-%b-%y'),85.35); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('31-Dec-08','%e-%b-%y'),85.35); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('30-Dec-08','%e-%b-%y'),86.29); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('29-Dec-08','%e-%b-%y'),86.61); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('26-Dec-08','%e-%b-%y'),85.81); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('25-Dec-08','%e-%b-%y'),85.04); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('24-Dec-08','%e-%b-%y'),85.04); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('23-Dec-08','%e-%b-%y'),86.38); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('22-Dec-08','%e-%b-%y'),85.74); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('19-Dec-08','%e-%b-%y'),90); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('18-Dec-08','%e-%b-%y'),89.43); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('17-Dec-08','%e-%b-%y'),89.16); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('16-Dec-08','%e-%b-%y'),95.43); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('15-Dec-08','%e-%b-%y'),94.75); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('12-Dec-08','%e-%b-%y'),98.27); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('11-Dec-08','%e-%b-%y'),95); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('10-Dec-08','%e-%b-%y'),98.21); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('9-Dec-08','%e-%b-%y'),100.06); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('8-Dec-08','%e-%b-%y'),99.72); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('5-Dec-08','%e-%b-%y'),94); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('4-Dec-08','%e-%b-%y'),91.41); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('3-Dec-08','%e-%b-%y'),95.9); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('2-Dec-08','%e-%b-%y'),92.47); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('1-Dec-08','%e-%b-%y'),88.93); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('28-Nov-08','%e-%b-%y'),92.67); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('27-Nov-08','%e-%b-%y'),95); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('26-Nov-08','%e-%b-%y'),95); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('25-Nov-08','%e-%b-%y'),90.8); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('24-Nov-08','%e-%b-%y'),92.95); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('21-Nov-08','%e-%b-%y'),82.58); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('20-Nov-08','%e-%b-%y'),80.49); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('19-Nov-08','%e-%b-%y'),86.29); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('18-Nov-08','%e-%b-%y'),89.91); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('17-Nov-08','%e-%b-%y'),88.14); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('14-Nov-08','%e-%b-%y'),90.24); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('13-Nov-08','%e-%b-%y'),96.44); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('12-Nov-08','%e-%b-%y'),90.12); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('11-Nov-08','%e-%b-%y'),94.77); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('10-Nov-08','%e-%b-%y'),95.88); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('7-Nov-08','%e-%b-%y'),98.24); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('6-Nov-08','%e-%b-%y'),99.1); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('5-Nov-08','%e-%b-%y'),103.3); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('4-Nov-08','%e-%b-%y'),110.99); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('3-Nov-08','%e-%b-%y'),106.96); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('31-Oct-08','%e-%b-%y'),107.59); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('30-Oct-08','%e-%b-%y'),111.04); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('29-Oct-08','%e-%b-%y'),104.55); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('28-Oct-08','%e-%b-%y'),99.91); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('27-Oct-08','%e-%b-%y'),92.09); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('24-Oct-08','%e-%b-%y'),96.38); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('23-Oct-08','%e-%b-%y'),98.23); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('22-Oct-08','%e-%b-%y'),96.87); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('21-Oct-08','%e-%b-%y'),91.49); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('20-Oct-08','%e-%b-%y'),98.44); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('17-Oct-08','%e-%b-%y'),97.4); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('16-Oct-08','%e-%b-%y'),101.89); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('15-Oct-08','%e-%b-%y'),97.95); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('14-Oct-08','%e-%b-%y'),104.08); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('13-Oct-08','%e-%b-%y'),110.26); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('10-Oct-08','%e-%b-%y'),96.8); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('9-Oct-08','%e-%b-%y'),88.74); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('8-Oct-08','%e-%b-%y'),89.79); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('7-Oct-08','%e-%b-%y'),89.16); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('6-Oct-08','%e-%b-%y'),98.14); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('3-Oct-08','%e-%b-%y'),97.07); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('2-Oct-08','%e-%b-%y'),100.1); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('1-Oct-08','%e-%b-%y'),109.12); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('30-Sep-08','%e-%b-%y'),113.66); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('29-Sep-08','%e-%b-%y'),105.26); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('26-Sep-08','%e-%b-%y'),128.24); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('25-Sep-08','%e-%b-%y'),131.93); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('24-Sep-08','%e-%b-%y'),128.71); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('23-Sep-08','%e-%b-%y'),126.84); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('22-Sep-08','%e-%b-%y'),131.05); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('19-Sep-08','%e-%b-%y'),140.91); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('18-Sep-08','%e-%b-%y'),134.09); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('17-Sep-08','%e-%b-%y'),127.83); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('16-Sep-08','%e-%b-%y'),139.88); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('15-Sep-08','%e-%b-%y'),140.36); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('12-Sep-08','%e-%b-%y'),148.94); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('11-Sep-08','%e-%b-%y'),152.65); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('10-Sep-08','%e-%b-%y'),151.61); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('9-Sep-08','%e-%b-%y'),151.68); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('8-Sep-08','%e-%b-%y'),157.92); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('5-Sep-08','%e-%b-%y'),160.18); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('4-Sep-08','%e-%b-%y'),161.22); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('3-Sep-08','%e-%b-%y'),166.96); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('2-Sep-08','%e-%b-%y'),166.19); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('29-Aug-08','%e-%b-%y'),169.53); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('28-Aug-08','%e-%b-%y'),173.74); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('27-Aug-08','%e-%b-%y'),174.67); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('26-Aug-08','%e-%b-%y'),173.64); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('25-Aug-08','%e-%b-%y'),172.55); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('22-Aug-08','%e-%b-%y'),176.79); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('21-Aug-08','%e-%b-%y'),174.29); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('20-Aug-08','%e-%b-%y'),175.84); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('19-Aug-08','%e-%b-%y'),173.53); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('18-Aug-08','%e-%b-%y'),175.39); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('15-Aug-08','%e-%b-%y'),175.74); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('14-Aug-08','%e-%b-%y'),179.32); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('13-Aug-08','%e-%b-%y'),179.3); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('12-Aug-08','%e-%b-%y'),176.73); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('11-Aug-08','%e-%b-%y'),173.56); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('8-Aug-08','%e-%b-%y'),169.55); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('7-Aug-08','%e-%b-%y'),163.57); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('6-Aug-08','%e-%b-%y'),164.19); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('5-Aug-08','%e-%b-%y'),160.64); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('4-Aug-08','%e-%b-%y'),153.23); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('1-Aug-08','%e-%b-%y'),156.66); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('31-Jul-08','%e-%b-%y'),158.95); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('30-Jul-08','%e-%b-%y'),159.88); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('29-Jul-08','%e-%b-%y'),157.08); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('28-Jul-08','%e-%b-%y'),154.4); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('25-Jul-08','%e-%b-%y'),162.12); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('24-Jul-08','%e-%b-%y'),159.03); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('23-Jul-08','%e-%b-%y'),166.26); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('22-Jul-08','%e-%b-%y'),162.02); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('21-Jul-08','%e-%b-%y'),166.29); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('18-Jul-08','%e-%b-%y'),165.15); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('17-Jul-08','%e-%b-%y'),171.81); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('16-Jul-08','%e-%b-%y'),172.81); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('15-Jul-08','%e-%b-%y'),169.64); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('14-Jul-08','%e-%b-%y'),173.88); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('11-Jul-08','%e-%b-%y'),172.58); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('10-Jul-08','%e-%b-%y'),176.63); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('9-Jul-08','%e-%b-%y'),174.25); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('8-Jul-08','%e-%b-%y'),179.55); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('7-Jul-08','%e-%b-%y'),175.16); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('3-Jul-08','%e-%b-%y'),170.12); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('2-Jul-08','%e-%b-%y'),168.18); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('1-Jul-08','%e-%b-%y'),174.68); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('30-Jun-08','%e-%b-%y'),167.44); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('27-Jun-08','%e-%b-%y'),170.09); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('26-Jun-08','%e-%b-%y'),168.26); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('25-Jun-08','%e-%b-%y'),177.39); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('24-Jun-08','%e-%b-%y'),173.25); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('23-Jun-08','%e-%b-%y'),173.16); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('20-Jun-08','%e-%b-%y'),175.27); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('19-Jun-08','%e-%b-%y'),180.9); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('18-Jun-08','%e-%b-%y'),178.75); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('17-Jun-08','%e-%b-%y'),181.43); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('16-Jun-08','%e-%b-%y'),176.84); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('13-Jun-08','%e-%b-%y'),172.37); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('12-Jun-08','%e-%b-%y'),173.26); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('11-Jun-08','%e-%b-%y'),180.81); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('10-Jun-08','%e-%b-%y'),185.64); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('9-Jun-08','%e-%b-%y'),181.61); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('6-Jun-08','%e-%b-%y'),185.64); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('5-Jun-08','%e-%b-%y'),189.43); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('4-Jun-08','%e-%b-%y'),185.19); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('3-Jun-08','%e-%b-%y'),185.37); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('2-Jun-08','%e-%b-%y'),186.1); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('30-May-08','%e-%b-%y'),188.75); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('29-May-08','%e-%b-%y'),186.69); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('28-May-08','%e-%b-%y'),187.01); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('27-May-08','%e-%b-%y'),186.43); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('23-May-08','%e-%b-%y'),181.17); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('22-May-08','%e-%b-%y'),177.05); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('21-May-08','%e-%b-%y'),178.19); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('20-May-08','%e-%b-%y'),185.9); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('19-May-08','%e-%b-%y'),183.6); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('16-May-08','%e-%b-%y'),187.62); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('15-May-08','%e-%b-%y'),189.73); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('14-May-08','%e-%b-%y'),186.26); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('13-May-08','%e-%b-%y'),189.96); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('12-May-08','%e-%b-%y'),188.16); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('9-May-08','%e-%b-%y'),183.45); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('8-May-08','%e-%b-%y'),185.06); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('7-May-08','%e-%b-%y'),182.59); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('6-May-08','%e-%b-%y'),186.66); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('5-May-08','%e-%b-%y'),184.73); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('2-May-08','%e-%b-%y'),180.94); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('1-May-08','%e-%b-%y'),180); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('30-Apr-08','%e-%b-%y'),173.95); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('29-Apr-08','%e-%b-%y'),175.05); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('28-Apr-08','%e-%b-%y'),172.24); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('25-Apr-08','%e-%b-%y'),169.73); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('24-Apr-08','%e-%b-%y'),168.94); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('23-Apr-08','%e-%b-%y'),162.89); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('22-Apr-08','%e-%b-%y'),160.2); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('21-Apr-08','%e-%b-%y'),168.16); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('18-Apr-08','%e-%b-%y'),161.04); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('17-Apr-08','%e-%b-%y'),154.49); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('16-Apr-08','%e-%b-%y'),153.7); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('15-Apr-08','%e-%b-%y'),148.38); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('14-Apr-08','%e-%b-%y'),147.78); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('11-Apr-08','%e-%b-%y'),147.14); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('10-Apr-08','%e-%b-%y'),154.55); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('9-Apr-08','%e-%b-%y'),151.44); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('8-Apr-08','%e-%b-%y'),152.84); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('7-Apr-08','%e-%b-%y'),155.89); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('4-Apr-08','%e-%b-%y'),153.08); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('3-Apr-08','%e-%b-%y'),151.61); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('2-Apr-08','%e-%b-%y'),147.49); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('1-Apr-08','%e-%b-%y'),149.53); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('31-Mar-08','%e-%b-%y'),143.5); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('28-Mar-08','%e-%b-%y'),143.01); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('27-Mar-08','%e-%b-%y'),140.25); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('26-Mar-08','%e-%b-%y'),145.06); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('25-Mar-08','%e-%b-%y'),140.98); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('24-Mar-08','%e-%b-%y'),139.53); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('20-Mar-08','%e-%b-%y'),133.27); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('19-Mar-08','%e-%b-%y'),129.67); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('18-Mar-08','%e-%b-%y'),132.82); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('17-Mar-08','%e-%b-%y'),126.73); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('14-Mar-08','%e-%b-%y'),126.61); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('13-Mar-08','%e-%b-%y'),127.94); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('12-Mar-08','%e-%b-%y'),126.03); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('11-Mar-08','%e-%b-%y'),127.35); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('10-Mar-08','%e-%b-%y'),119.69); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('7-Mar-08','%e-%b-%y'),122.25); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('6-Mar-08','%e-%b-%y'),120.93); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('5-Mar-08','%e-%b-%y'),124.49); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('4-Mar-08','%e-%b-%y'),124.62); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('3-Mar-08','%e-%b-%y'),121.73); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('29-Feb-08','%e-%b-%y'),125.02); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('28-Feb-08','%e-%b-%y'),129.91); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('27-Feb-08','%e-%b-%y'),122.96); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('26-Feb-08','%e-%b-%y'),119.15); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('25-Feb-08','%e-%b-%y'),119.74); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('22-Feb-08','%e-%b-%y'),119.46); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('21-Feb-08','%e-%b-%y'),121.54); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('20-Feb-08','%e-%b-%y'),123.82); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('19-Feb-08','%e-%b-%y'),122.18); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('15-Feb-08','%e-%b-%y'),124.63); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('14-Feb-08','%e-%b-%y'),127.46); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('13-Feb-08','%e-%b-%y'),129.4); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('12-Feb-08','%e-%b-%y'),124.86); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('11-Feb-08','%e-%b-%y'),129.45); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('8-Feb-08','%e-%b-%y'),125.48); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('7-Feb-08','%e-%b-%y'),121.24); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('6-Feb-08','%e-%b-%y'),122); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('5-Feb-08','%e-%b-%y'),129.36); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('4-Feb-08','%e-%b-%y'),131.65); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('1-Feb-08','%e-%b-%y'),133.75); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('31-Jan-08','%e-%b-%y'),135.36); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('30-Jan-08','%e-%b-%y'),132.18); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('29-Jan-08','%e-%b-%y'),131.54); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('28-Jan-08','%e-%b-%y'),130.01); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('25-Jan-08','%e-%b-%y'),130.01); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('24-Jan-08','%e-%b-%y'),135.6); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('23-Jan-08','%e-%b-%y'),139.07); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('22-Jan-08','%e-%b-%y'),155.64); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('18-Jan-08','%e-%b-%y'),161.36); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('17-Jan-08','%e-%b-%y'),160.89); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('16-Jan-08','%e-%b-%y'),159.64); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('15-Jan-08','%e-%b-%y'),169.04); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('14-Jan-08','%e-%b-%y'),178.78); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('11-Jan-08','%e-%b-%y'),172.69); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('10-Jan-08','%e-%b-%y'),178.02); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('9-Jan-08','%e-%b-%y'),179.4); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('8-Jan-08','%e-%b-%y'),171.25); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('7-Jan-08','%e-%b-%y'),177.64); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('4-Jan-08','%e-%b-%y'),180.05); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('3-Jan-08','%e-%b-%y'),194.93); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('2-Jan-08','%e-%b-%y'),194.84); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('31-Dec-07','%e-%b-%y'),198.08); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('28-Dec-07','%e-%b-%y'),199.83); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('27-Dec-07','%e-%b-%y'),198.57); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('26-Dec-07','%e-%b-%y'),198.95); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('24-Dec-07','%e-%b-%y'),198.8); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('21-Dec-07','%e-%b-%y'),193.91); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('20-Dec-07','%e-%b-%y'),187.21); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('19-Dec-07','%e-%b-%y'),183.12); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('18-Dec-07','%e-%b-%y'),182.98); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('17-Dec-07','%e-%b-%y'),184.4); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('14-Dec-07','%e-%b-%y'),190.39); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('13-Dec-07','%e-%b-%y'),191.83); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('12-Dec-07','%e-%b-%y'),190.86); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('11-Dec-07','%e-%b-%y'),188.54); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('10-Dec-07','%e-%b-%y'),194.21); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('7-Dec-07','%e-%b-%y'),194.3); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('6-Dec-07','%e-%b-%y'),189.95); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('5-Dec-07','%e-%b-%y'),185.5); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('4-Dec-07','%e-%b-%y'),179.81); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('3-Dec-07','%e-%b-%y'),178.86); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('30-Nov-07','%e-%b-%y'),182.22); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('29-Nov-07','%e-%b-%y'),184.29); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('28-Nov-07','%e-%b-%y'),180.22); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('27-Nov-07','%e-%b-%y'),174.81); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('26-Nov-07','%e-%b-%y'),172.54); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('23-Nov-07','%e-%b-%y'),171.54); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('21-Nov-07','%e-%b-%y'),168.46); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('20-Nov-07','%e-%b-%y'),168.85); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('19-Nov-07','%e-%b-%y'),163.95); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('16-Nov-07','%e-%b-%y'),166.39); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('15-Nov-07','%e-%b-%y'),164.3); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('14-Nov-07','%e-%b-%y'),166.11); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('13-Nov-07','%e-%b-%y'),169.96); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('12-Nov-07','%e-%b-%y'),153.76); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('9-Nov-07','%e-%b-%y'),165.37); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('8-Nov-07','%e-%b-%y'),175.47); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('7-Nov-07','%e-%b-%y'),186.3); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('6-Nov-07','%e-%b-%y'),191.79); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('5-Nov-07','%e-%b-%y'),186.18); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('2-Nov-07','%e-%b-%y'),187.87); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('1-Nov-07','%e-%b-%y'),187.44); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('31-Oct-07','%e-%b-%y'),189.95); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('30-Oct-07','%e-%b-%y'),187); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('29-Oct-07','%e-%b-%y'),185.09); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('26-Oct-07','%e-%b-%y'),184.7); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('25-Oct-07','%e-%b-%y'),182.78); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('24-Oct-07','%e-%b-%y'),185.93); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('23-Oct-07','%e-%b-%y'),186.16); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('22-Oct-07','%e-%b-%y'),174.36); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('19-Oct-07','%e-%b-%y'),170.42); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('18-Oct-07','%e-%b-%y'),173.5); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('17-Oct-07','%e-%b-%y'),172.75); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('16-Oct-07','%e-%b-%y'),169.58); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('15-Oct-07','%e-%b-%y'),166.98); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('12-Oct-07','%e-%b-%y'),167.25); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('11-Oct-07','%e-%b-%y'),162.23); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('10-Oct-07','%e-%b-%y'),166.79); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('9-Oct-07','%e-%b-%y'),167.86); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('8-Oct-07','%e-%b-%y'),167.91); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('5-Oct-07','%e-%b-%y'),161.45); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('4-Oct-07','%e-%b-%y'),156.24); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('3-Oct-07','%e-%b-%y'),157.92); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('2-Oct-07','%e-%b-%y'),158.45); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('1-Oct-07','%e-%b-%y'),156.34); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('28-Sep-07','%e-%b-%y'),153.47); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('27-Sep-07','%e-%b-%y'),154.5); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('26-Sep-07','%e-%b-%y'),152.77); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('25-Sep-07','%e-%b-%y'),153.18); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('24-Sep-07','%e-%b-%y'),148.28); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('21-Sep-07','%e-%b-%y'),144.15); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('20-Sep-07','%e-%b-%y'),140.31); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('19-Sep-07','%e-%b-%y'),140.77); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('18-Sep-07','%e-%b-%y'),140.92); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('17-Sep-07','%e-%b-%y'),138.41); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('14-Sep-07','%e-%b-%y'),138.81); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('13-Sep-07','%e-%b-%y'),137.2); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('12-Sep-07','%e-%b-%y'),136.85); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('11-Sep-07','%e-%b-%y'),135.49); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('10-Sep-07','%e-%b-%y'),136.71); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('7-Sep-07','%e-%b-%y'),131.77); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('6-Sep-07','%e-%b-%y'),135.01); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('5-Sep-07','%e-%b-%y'),136.76); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('4-Sep-07','%e-%b-%y'),144.16); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('31-Aug-07','%e-%b-%y'),138.48); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('30-Aug-07','%e-%b-%y'),136.25); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('29-Aug-07','%e-%b-%y'),134.08); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('28-Aug-07','%e-%b-%y'),126.82); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('27-Aug-07','%e-%b-%y'),132.25); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('24-Aug-07','%e-%b-%y'),135.3); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('23-Aug-07','%e-%b-%y'),131.07); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('22-Aug-07','%e-%b-%y'),132.51); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('21-Aug-07','%e-%b-%y'),127.57); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('20-Aug-07','%e-%b-%y'),122.22); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('17-Aug-07','%e-%b-%y'),122.06); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('16-Aug-07','%e-%b-%y'),117.05); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('15-Aug-07','%e-%b-%y'),119.9); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('14-Aug-07','%e-%b-%y'),124.03); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('13-Aug-07','%e-%b-%y'),127.79); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('10-Aug-07','%e-%b-%y'),125); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('9-Aug-07','%e-%b-%y'),126.39); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('8-Aug-07','%e-%b-%y'),134.01); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('7-Aug-07','%e-%b-%y'),135.03); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('6-Aug-07','%e-%b-%y'),135.25); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('3-Aug-07','%e-%b-%y'),131.85); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('2-Aug-07','%e-%b-%y'),136.49); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('1-Aug-07','%e-%b-%y'),135); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('31-Jul-07','%e-%b-%y'),131.76); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('30-Jul-07','%e-%b-%y'),141.43); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('27-Jul-07','%e-%b-%y'),143.85); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('26-Jul-07','%e-%b-%y'),146); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('25-Jul-07','%e-%b-%y'),137.26); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('24-Jul-07','%e-%b-%y'),134.89); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('23-Jul-07','%e-%b-%y'),143.7); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('20-Jul-07','%e-%b-%y'),143.75); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('19-Jul-07','%e-%b-%y'),140); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('18-Jul-07','%e-%b-%y'),138.12); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('17-Jul-07','%e-%b-%y'),138.91); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('16-Jul-07','%e-%b-%y'),138.1); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('13-Jul-07','%e-%b-%y'),137.73); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('12-Jul-07','%e-%b-%y'),134.07); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('11-Jul-07','%e-%b-%y'),132.39); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('10-Jul-07','%e-%b-%y'),132.35); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('9-Jul-07','%e-%b-%y'),130.33); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('6-Jul-07','%e-%b-%y'),132.3); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('5-Jul-07','%e-%b-%y'),132.75); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('3-Jul-07','%e-%b-%y'),127.17); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('2-Jul-07','%e-%b-%y'),121.26); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('29-Jun-07','%e-%b-%y'),122.04); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('28-Jun-07','%e-%b-%y'),120.56); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('27-Jun-07','%e-%b-%y'),121.89); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('26-Jun-07','%e-%b-%y'),119.65); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('25-Jun-07','%e-%b-%y'),122.34); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('22-Jun-07','%e-%b-%y'),123); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('21-Jun-07','%e-%b-%y'),123.9); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('20-Jun-07','%e-%b-%y'),121.55); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('19-Jun-07','%e-%b-%y'),123.66); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('18-Jun-07','%e-%b-%y'),125.09); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('15-Jun-07','%e-%b-%y'),120.5); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('14-Jun-07','%e-%b-%y'),118.75); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('13-Jun-07','%e-%b-%y'),117.5); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('12-Jun-07','%e-%b-%y'),120.38); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('11-Jun-07','%e-%b-%y'),120.19); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('8-Jun-07','%e-%b-%y'),124.49); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('7-Jun-07','%e-%b-%y'),124.07); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('6-Jun-07','%e-%b-%y'),123.64); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('5-Jun-07','%e-%b-%y'),122.67); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('4-Jun-07','%e-%b-%y'),121.33); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('1-Jun-07','%e-%b-%y'),118.4); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('31-May-07','%e-%b-%y'),121.19); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('30-May-07','%e-%b-%y'),118.77); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('29-May-07','%e-%b-%y'),114.35); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('25-May-07','%e-%b-%y'),113.62); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('24-May-07','%e-%b-%y'),110.69); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('23-May-07','%e-%b-%y'),112.89); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('22-May-07','%e-%b-%y'),113.54); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('21-May-07','%e-%b-%y'),111.98); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('18-May-07','%e-%b-%y'),110.02); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('17-May-07','%e-%b-%y'),109.44); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('16-May-07','%e-%b-%y'),107.34); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('15-May-07','%e-%b-%y'),107.52); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('14-May-07','%e-%b-%y'),109.36); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('11-May-07','%e-%b-%y'),108.74); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('10-May-07','%e-%b-%y'),107.34); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('9-May-07','%e-%b-%y'),106.88); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('8-May-07','%e-%b-%y'),105.06); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('7-May-07','%e-%b-%y'),103.92); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('4-May-07','%e-%b-%y'),100.81); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('3-May-07','%e-%b-%y'),100.4); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('2-May-07','%e-%b-%y'),100.39); +Insert into demo_line_chart (series, log_date, data_value) values ('Series3',STR_TO_DATE('1-May-07','%e-%b-%y'),99.47); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('30-Apr-07','%e-%b-%y'),99.8); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('27-Apr-07','%e-%b-%y'),99.92); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('26-Apr-07','%e-%b-%y'),98.84); +Insert into demo_line_chart (series, log_date, data_value) values ('Series2',STR_TO_DATE('25-Apr-07','%e-%b-%y'),95.35); +Insert into demo_line_chart (series, log_date, data_value) values ('Series1',STR_TO_DATE('24-Apr-07','%e-%b-%y'),93.24); + +-- DEMO_PIE_CHART +Insert into demo_pie_chart (legend, data_value) values ('One', 5); +Insert into demo_pie_chart (legend, data_value) values ('Two', 2); +Insert into demo_pie_chart (legend, data_value) values ('Three', 9); +Insert into demo_pie_chart (legend, data_value) values ('Four', 7); +Insert into demo_pie_chart (legend, data_value) values ('Five', 4); +Insert into demo_pie_chart (legend, data_value) values ('Six', 3); +Insert into demo_pie_chart (legend, data_value) values ('Seven', .5); + + +-- DEMO_SCATTER_CHART +Insert into demo_scatter_chart (rainfall, key_value, measurements) values (4.1, 'Particulate', 122); +Insert into demo_scatter_chart (rainfall, key_value, measurements) values (4.3, 'Particulate', 117); +Insert into demo_scatter_chart (rainfall, key_value, measurements) values (5.7, 'Particulate', 112); +Insert into demo_scatter_chart (rainfall, key_value, measurements) values (5.4, 'Particulate', 114); +Insert into demo_scatter_chart (rainfall, key_value, measurements) values (5.9, 'Particulate', 110); +Insert into demo_scatter_chart (rainfall, key_value, measurements) values (5.0, 'Particulate', 114); +Insert into demo_scatter_chart (rainfall, key_value, measurements) values (3.6, 'Particulate', 128); +Insert into demo_scatter_chart (rainfall, key_value, measurements) values (1.9, 'Particulate', 137); +Insert into demo_scatter_chart (rainfall, key_value, measurements) values (7.3, 'Particulate', 104); +Insert into demo_scatter_chart (rainfall, key_value, measurements) values (6.9, 'Humidity', 119); +Insert into demo_scatter_chart (rainfall, key_value, measurements) values (7.9, 'Humidity', 118); +Insert into demo_scatter_chart (rainfall, key_value, measurements) values (9.8, 'Humidity', 103); +Insert into demo_scatter_chart (rainfall, key_value, measurements) values (4.9, 'Humidity', 137); +Insert into demo_scatter_chart (rainfall, key_value, measurements) values (6.8, 'Humidity', 102); +Insert into demo_scatter_chart (rainfall, key_value, measurements) values (4.7, 'Humidity', 89); +Insert into demo_scatter_chart (rainfall, key_value, measurements) values (2.7, 'Humidity', 98); +Insert into demo_scatter_chart (rainfall, key_value, measurements) values (3.7, 'Humidity', 145); +Insert into demo_scatter_chart (rainfall, key_value, measurements) values (7.4, 'Humidity', 118); + +-- DEMO_SCATTER_PLOT + +-- SET DEFINE OFF; +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample0', -46.5901128883449, -464.477370615131); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample0', -85.0293361247543, -362.252178232471); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample0', 70.9700275365898, 402.214363675566); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample0', -50.1110580054506, -310.108907443154); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample0', 85.043005750476, 813.481841353449); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample0', -14.2356123424179, -134.200903707809); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample0', -66.7014933188071, -445.754374526706); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample0', -79.941582021797, -694.089097548454); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample0', -64.4665101305822, -431.660620986243); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample0', 13.718818366452, 100.010719918027); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample0', 35.457456199233, 223.254643848734); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample0', 55.2326402548387, 268.940835852805); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample0', -32.9989160276248, -237.280626944034); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample0', -0.464911506111831, -2.65656324666862); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample0', -59.0205101710777, -498.895652307826); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample0', 28.0939970575828, 117.200615553207); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample0', 31.7305239061572, 186.662624012256); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample0', 50.9035126419798, 440.937283203403); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample0', 58.3875046571053, 547.879249694999); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample0', 76.7846997917459, 525.020578968308); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample0', 1.73485745801611, 7.28149474936192); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample0', 15.304841061276, 71.2374666595537); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample0', 75.1342455000693, 381.145932349436); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample0', -58.2087417684623, -573.630956069476); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample0', 76.7977837302114, 624.733726327778); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample0', 56.3295585433654, 309.697529902676); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample0', -9.27601440680639, -49.5126219388194); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample0', 98.3002030040236, 765.653589829535); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample0', -25.0987502451517, -174.651201240269); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample0', 39.9215299020147, 337.889176256456); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample0', 77.9225832868337, 356.183903852096); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample0', 75.4311841137638, 14.5258766665983); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample0', 58.9445375968278, 376.359576288564); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample0', 46.9521897141796, 3.5679984193934); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample0', -49.0378307695689, -230.816092788509); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample0', -96.2461776340861, -863.765255159092); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample0', -96.3388912796447, -538.147283544646); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample0', -21.4684477767032, -200.140077054848); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample0', -30.3532837083366, -226.462637188158); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample0', -17.5055590488884, -118.709622452841); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample1', 56.6394671790491, 385.48951169801); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample1', 70.4622912302344, 356.986529538635); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample1', 58.2647422222769, 489.418744916999); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample1', -92.16093253903, -425.576081634713); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample1', -2.64574970943097, -26.190027661226); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample1', -16.7568654181289, -117.460886096034); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample1', 68.215377945908, 606.917788617984); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample1', 53.7387814434413, 367.53491797949); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample1', -51.8861573715238, -289.998186955562); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample1', -15.9721784074351, -75.335027134323); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample1', 63.2540648905791, 602.546517566905); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample1', -53.376167960458, -470.921238684285); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample1', 40.8307443439851, 276.112653117961); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample1', -13.0540977188468, -127.648158921993); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample1', -43.7358336047599, -435.080470107322); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample1', -74.5673321340732, -617.960236798371); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample1', -6.47907144443936, -55.654651151187); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample1', 68.1915507628225, 352.320728639801); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample1', -23.5393521654339, -137.714557244391); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample1', 28.3621412621467, 141.103859877604); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample1', -99.5615230664525, -974.857161307048); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample1', -77.7132553058204, -736.182131225006); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample1', 95.9321864873013, 478.286112499176); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample1', 97.7451855292708, 940.301427763062); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample1', -10.2483179758141, -70.1145330070458); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample1', -24.0750124187893, -113.523998470537); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample1', -5.5721118558967, -43.8516395203455); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample1', -55.5378338160537, -368.506951528332); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample1', 52.6669516338013, 38.2926120131942); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample1', -74.1981412067658, -436.990411988621); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample1', -8.70511941690364, -71.3277811558721); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample1', 63.2921735621378, 534.825008407329); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample1', 97.9066635843841, 678.994971737474); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample1', -83.1613916743288, -494.53303650568); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample1', 23.4730547863992, 223.031148353333); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample1', 40.6105099506845, 199.937366405274); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample1', 35.4473225526307, 331.61786915261); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample1', 27.2050975460142, 146.277993239147); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample1', -1.54684302938646, -12.6706471561247); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample1', 45.8386162291745, 401.780882699918); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample2', 43.4241956158593, 228.71488367607); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample2', -23.4517134254585, -165.958577325218); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample2', -98.8954664030229, -829.964553125469); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample2', 48.0527046113198, 451.527720751234); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample2', -77.8912947988124, -416.867729852279); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample2', 23.8325471824168, 206.907438743452); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample2', 83.2787398847467, 814.01250022556); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample2', 49.1572992549647, 451.03037365466); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample2', -11.1351768833872, -57.3863334655361); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample2', 71.1980242104626, 572.745863967841); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample2', 15.0952976022392, 103.30274980367); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample2', 75.0300005037414, 406.581640027236); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample2', -82.0092720309019, -690.340287049552); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample2', 40.2433497232209, 363.579616486762); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample2', 26.8157962678174, 262.150124949525); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample2', -83.9563210001448, -432.739081022174); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample2', -20.6480437627346, -161.330015497217); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample2', 37.1388896882226, 161.352404658606); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample2', 20.2126667486174, 168.833789818416); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample2', 58.3723632769494, 293.206814023827); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample2', -20.2876832456236, -88.0090685884954); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample2', 72.9768050433371, 691.684023528398); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample2', -21.6612128833675, -130.834158714088); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample2', 97.4870524045038, 806.47904449193); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample2', 60.6688063197852, 255.749289305775); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample2', -44.235772358471, -336.262226570567); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample2', -47.39573087854, -321.133647936626); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample2', -24.7522484346097, -204.548308435727); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample2', -42.903238078129, -239.651563752902); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample2', 20.4656734934697, 172.700213789797); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample2', 56.0665747085147, 365.360390019834); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample2', 31.9979219049038, 237.490140339893); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample2', -29.9884426739069, -203.821484170813); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample2', 13.5011085362703, 79.4784314297668); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample2', 41.8402945507358, 297.04934398378); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample2', -84.9323678979223, -345.2331996232); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample2', -42.2469964847455, -361.468816319656); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample2', 98.1057699772752, 445.181262282444); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample2', 95.5327901766563, 522.663100406047); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample2', 35.0916611161316, 246.796980313209); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample3', 99.3987950082867, 401.97428571655); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample3', -3.0419413965969, -14.5325761725203); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample3', -79.388026451666, -701.817589967372); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample3', -88.451242397524, -668.370526000304); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample3', 34.3131838963851, 254.418322223563); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample3', -61.518208630511, -347.521623572776); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample3', 45.6124480237487, 356.33565541369); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample3', -1.0716036518037, -7.80544934354423); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample3', 31.7371714687412, 283.925868763573); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample3', -76.771029786315, -626.268489584739); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample3', -67.913690110843, -614.736930677921); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample3', 34.9311671860034, 171.384205820777); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample3', 94.3264454603021, 914.267819214392); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample3', 76.7493996267558, 705.649611960615); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample3', -87.795202856922, -749.505178721718); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample3', 2.10914716736019, 15.4036733330536); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample3', -50.456669557937, -318.410608422062); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample3', -94.646644883092, -734.660992935541); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample3', 34.9170862075359, 347.583881438806); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample3', 44.3524585090071, 294.615219199443); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample3', -67.191016143335, -609.956472872497); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample3', -78.826443879164, -369.129912603377); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample3', -50.427554400015, -418.144241602024); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample3', -70.371769526721, -307.02193189609); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample3', 16.3220947890044, 97.0997346831135); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample3', -47.067245718878, -398.27032236792); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample3', 5.91206661301702, 24.7239863780181); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample3', -99.621681801868, -843.593457399484); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample3', 87.4503492670535, 695.345037859433); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample3', -91.176921118057, -683.305064255346); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample3', -0.6632900001386, -5.34157539224209); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample3', 2.98188785882178, 12.1181973600389); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample3', 30.6008700087597, 205.922863867274); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample3', 7.90348761612496, 65.5271597329641); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample3', 40.3565229854156, 268.058138389501); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample3', 37.6892733312091, 247.519083233639); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample3', 16.4759733864001, 107.72661087278); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample3', -53.578492311122, -369.768816039059); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample3', 77.1292326560541, 765.262108306778); +Insert into demo_scatter_plot + (SERIES, VALUEX, VALUEY) + Values + ('Sample3', -79.566811593352, -677.545127214159); + +-- DEMO_UTIL_CHART +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-04-17','%Y-%m-%d'),53.86667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-08-10','%Y-%m-%d'),62.95747); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-04-21','%Y-%m-%d'),48.80000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-04-22','%Y-%m-%d'),51.33333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-08-11','%Y-%m-%d'),56.13373); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-04-23','%Y-%m-%d'),53.40000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-08-12','%Y-%m-%d'),57.05287); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-04-24','%Y-%m-%d'),51.00000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-08-13','%Y-%m-%d'),55.78947); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-04-25','%Y-%m-%d'),54.60000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-08-14','%Y-%m-%d'),63.34907); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-04-26','%Y-%m-%d'),50.86667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-08-15','%Y-%m-%d'),52.21327); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-04-27','%Y-%m-%d'),48.33333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-08-16','%Y-%m-%d'),51.32080); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-04-28','%Y-%m-%d'),50.26667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-08-17','%Y-%m-%d'),58.35720); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-04-29','%Y-%m-%d'),51.73333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-08-18','%Y-%m-%d'),57.62293); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-04-30','%Y-%m-%d'),67.60000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-08-19','%Y-%m-%d'),55.25000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-05-01','%Y-%m-%d'),59.89393); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-08-20','%Y-%m-%d'),58.79573); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-05-02','%Y-%m-%d'),61.20753); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-08-21','%Y-%m-%d'),54.09720); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-05-03','%Y-%m-%d'),58.98340); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-08-22','%Y-%m-%d'),59.95813); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-05-04','%Y-%m-%d'),59.55873); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-08-23','%Y-%m-%d'),62.03067); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-05-05','%Y-%m-%d'),58.73680); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-08-24','%Y-%m-%d'),61.97620); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-05-06','%Y-%m-%d'),59.89967); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-08-25','%Y-%m-%d'),58.00207); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-05-07','%Y-%m-%d'),60.67973); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-08-26','%Y-%m-%d'),59.95440); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-05-08','%Y-%m-%d'),60.85913); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-08-27','%Y-%m-%d'),55.43747); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-05-09','%Y-%m-%d'),60.62460); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-08-28','%Y-%m-%d'),52.53933); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-05-10','%Y-%m-%d'),59.51887); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-08-29','%Y-%m-%d'),57.46260); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-05-11','%Y-%m-%d'),61.57187); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-08-30','%Y-%m-%d'),60.04787); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-05-12','%Y-%m-%d'),60.70000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-08-31','%Y-%m-%d'),58.79480); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-05-13','%Y-%m-%d'),69.85133); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-09-01','%Y-%m-%d'),54.40107); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-05-14','%Y-%m-%d'),68.99620); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-09-02','%Y-%m-%d'),62.26007); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-05-15','%Y-%m-%d'),67.64080); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-09-03','%Y-%m-%d'),60.72360); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-05-16','%Y-%m-%d'),59.71433); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-09-04','%Y-%m-%d'),60.95847); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-05-17','%Y-%m-%d'),59.99667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-09-05','%Y-%m-%d'),59.45920); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-05-18','%Y-%m-%d'),63.27207); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-09-06','%Y-%m-%d'),60.58620); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-05-19','%Y-%m-%d'),60.32080); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-09-07','%Y-%m-%d'),61.94207); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-05-20','%Y-%m-%d'),57.32907); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-09-08','%Y-%m-%d'),59.03327); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-05-21','%Y-%m-%d'),59.76933); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-09-09','%Y-%m-%d'),62.83087); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-05-22','%Y-%m-%d'),59.12453); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-09-10','%Y-%m-%d'),59.36840); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-05-23','%Y-%m-%d'),57.10167); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-09-11','%Y-%m-%d'),56.11480); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-05-24','%Y-%m-%d'),58.45820); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-09-12','%Y-%m-%d'),62.23393); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-05-25','%Y-%m-%d'),59.45440); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-09-13','%Y-%m-%d'),59.72313); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-05-26','%Y-%m-%d'),60.12807); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-09-14','%Y-%m-%d'),53.37093); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-05-27','%Y-%m-%d'),59.11760); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-09-15','%Y-%m-%d'),52.99233); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-05-28','%Y-%m-%d'),57.32020); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-09-16','%Y-%m-%d'),55.99080); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-05-29','%Y-%m-%d'),59.80360); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-09-17','%Y-%m-%d'),53.93853); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-05-30','%Y-%m-%d'),66.73280); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-09-18','%Y-%m-%d'),55.99313); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-05-31','%Y-%m-%d'),58.78673); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-09-19','%Y-%m-%d'),68.23393); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-06-01','%Y-%m-%d'),58.82773); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-09-20','%Y-%m-%d'),61.86213); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-06-02','%Y-%m-%d'),63.12100); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-09-21','%Y-%m-%d'),61.20307); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-06-03','%Y-%m-%d'),59.70467); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-09-22','%Y-%m-%d'),61.05900); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-06-04','%Y-%m-%d'),58.85173); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-09-23','%Y-%m-%d'),58.41040); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-06-05','%Y-%m-%d'),61.21880); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-09-24','%Y-%m-%d'),59.15967); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-06-06','%Y-%m-%d'),58.99920); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-09-25','%Y-%m-%d'),56.42153); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-06-07','%Y-%m-%d'),59.94693); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-09-26','%Y-%m-%d'),60.46580); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-06-08','%Y-%m-%d'),66.27293); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-09-27','%Y-%m-%d'),57.44333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-06-09','%Y-%m-%d'),61.46773); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-09-28','%Y-%m-%d'),56.88887); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-06-10','%Y-%m-%d'),59.70467); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-09-29','%Y-%m-%d'),61.85773); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-06-11','%Y-%m-%d'),60.16000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-09-30','%Y-%m-%d'),61.96400); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-06-12','%Y-%m-%d'),61.20300); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-10-01','%Y-%m-%d'),65.88833); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-06-13','%Y-%m-%d'),60.95673); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-10-02','%Y-%m-%d'),62.67920); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-06-14','%Y-%m-%d'),60.70207); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-10-03','%Y-%m-%d'),63.52047); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-06-15','%Y-%m-%d'),61.02520); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-10-04','%Y-%m-%d'),58.60280); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-06-16','%Y-%m-%d'),60.33953); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-10-05','%Y-%m-%d'),63.74487); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-06-17','%Y-%m-%d'),61.20300); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-10-06','%Y-%m-%d'),59.94880); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-06-18','%Y-%m-%d'),63.12100); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-10-07','%Y-%m-%d'),59.44380); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-06-23','%Y-%m-%d'),61.09153); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-10-08','%Y-%m-%d'),59.16320); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-06-24','%Y-%m-%d'),61.28867); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-10-09','%Y-%m-%d'),60.84593); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-06-25','%Y-%m-%d'),60.95673); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-10-10','%Y-%m-%d'),58.84113); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-06-26','%Y-%m-%d'),60.61100); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-10-11','%Y-%m-%d'),62.59827); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-06-27','%Y-%m-%d'),61.22913); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-10-12','%Y-%m-%d'),60.94660); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-06-28','%Y-%m-%d'),58.88507); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-10-13','%Y-%m-%d'),59.37593); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-06-29','%Y-%m-%d'),59.73693); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-10-14','%Y-%m-%d'),67.21840); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-06-30','%Y-%m-%d'),62.45307); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-10-15','%Y-%m-%d'),68.56020); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-07-01','%Y-%m-%d'),61.30167); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-10-16','%Y-%m-%d'),57.56493); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-07-02','%Y-%m-%d'),62.92727); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-10-17','%Y-%m-%d'),57.02280); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-07-03','%Y-%m-%d'),60.05887); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-10-18','%Y-%m-%d'),56.20947); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-07-06','%Y-%m-%d'),61.20100); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-10-19','%Y-%m-%d'),55.69353); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-07-07','%Y-%m-%d'),60.66120); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-10-20','%Y-%m-%d'),57.17640); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-07-08','%Y-%m-%d'),59.78180); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-10-21','%Y-%m-%d'),57.50867); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-07-09','%Y-%m-%d'),58.74653); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-10-22','%Y-%m-%d'),61.67860); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-07-10','%Y-%m-%d'),59.77893); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-10-23','%Y-%m-%d'),57.34867); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-07-11','%Y-%m-%d'),67.34500); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-10-24','%Y-%m-%d'),61.68080); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-07-12','%Y-%m-%d'),57.07293); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-10-25','%Y-%m-%d'),55.55793); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-07-13','%Y-%m-%d'),57.37567); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-10-26','%Y-%m-%d'),55.81013); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-07-14','%Y-%m-%d'),63.97820); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-10-27','%Y-%m-%d'),59.85540); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-07-15','%Y-%m-%d'),56.06647); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-10-28','%Y-%m-%d'),61.05073); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-07-16','%Y-%m-%d'),53.66347); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-10-29','%Y-%m-%d'),59.81253); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-07-23','%Y-%m-%d'),56.50813); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-10-30','%Y-%m-%d'),61.02047); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-07-24','%Y-%m-%d'),53.19667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-10-31','%Y-%m-%d'),60.60413); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-07-25','%Y-%m-%d'),51.57133); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-11-01','%Y-%m-%d'),57.43067); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-07-26','%Y-%m-%d'),45.98160); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-11-02','%Y-%m-%d'),58.63027); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-07-27','%Y-%m-%d'),49.21113); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-11-03','%Y-%m-%d'),59.08127); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-07-28','%Y-%m-%d'),49.67213); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-11-04','%Y-%m-%d'),59.37373); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-07-29','%Y-%m-%d'),52.94053); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-11-05','%Y-%m-%d'),58.13413); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-07-30','%Y-%m-%d'),57.55727); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-11-06','%Y-%m-%d'),57.18893); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-07-31','%Y-%m-%d'),61.76900); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-11-07','%Y-%m-%d'),56.72853); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-08-01','%Y-%m-%d'),56.51953); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-11-08','%Y-%m-%d'),56.47340); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-08-02','%Y-%m-%d'),61.04853); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-11-09','%Y-%m-%d'),62.02333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-08-03','%Y-%m-%d'),70.06067); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-11-10','%Y-%m-%d'),61.21787); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-08-04','%Y-%m-%d'),60.97787); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-11-11','%Y-%m-%d'),62.01087); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-08-05','%Y-%m-%d'),59.25967); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-11-12','%Y-%m-%d'),62.67573); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-08-06','%Y-%m-%d'),56.12287); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-11-13','%Y-%m-%d'),59.23993); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-08-07','%Y-%m-%d'),63.99913); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-11-14','%Y-%m-%d'),67.34973); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-08-08','%Y-%m-%d'),58.71127); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-11-15','%Y-%m-%d'),60.93753); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-08-09','%Y-%m-%d'),64.01913); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-11-16','%Y-%m-%d'),54.52607); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-11-17','%Y-%m-%d'),57.81127); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-11-18','%Y-%m-%d'),63.53027); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-11-19','%Y-%m-%d'),58.13000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-11-20','%Y-%m-%d'),58.46827); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-11-21','%Y-%m-%d'),65.27807); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-11-22','%Y-%m-%d'),53.74513); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-11-23','%Y-%m-%d'),60.99107); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-11-24','%Y-%m-%d'),60.45427); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-11-25','%Y-%m-%d'),56.16847); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-11-26','%Y-%m-%d'),59.04040); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-11-27','%Y-%m-%d'),54.62040); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-11-28','%Y-%m-%d'),56.34687); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-11-29','%Y-%m-%d'),54.81560); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-11-30','%Y-%m-%d'),60.22753); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-12-01','%Y-%m-%d'),59.07307); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-12-02','%Y-%m-%d'),59.73553); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-12-03','%Y-%m-%d'),68.69447); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-12-04','%Y-%m-%d'),68.91767); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-12-05','%Y-%m-%d'),67.86460); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-12-06','%Y-%m-%d'),64.43120); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-03-01','%Y-%m-%d'),61.22507); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-12-07','%Y-%m-%d'),60.67793); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-03-02','%Y-%m-%d'),63.27533); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-12-08','%Y-%m-%d'),62.47060); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-03-03','%Y-%m-%d'),69.88087); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-12-09','%Y-%m-%d'),58.26053); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-03-04','%Y-%m-%d'),66.84920); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-12-10','%Y-%m-%d'),61.03340); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-03-05','%Y-%m-%d'),61.57367); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-12-11','%Y-%m-%d'),57.32620); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-03-06','%Y-%m-%d'),60.52293); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-12-12','%Y-%m-%d'),63.10353); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-03-07','%Y-%m-%d'),62.21027); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-12-13','%Y-%m-%d'),61.73167); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-03-08','%Y-%m-%d'),63.20380); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-12-14','%Y-%m-%d'),65.31080); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-03-09','%Y-%m-%d'),62.72427); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-12-15','%Y-%m-%d'),64.67620); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-03-10','%Y-%m-%d'),61.59373); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-12-16','%Y-%m-%d'),62.87287); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-03-11','%Y-%m-%d'),61.21280); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-12-17','%Y-%m-%d'),60.14680); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-03-12','%Y-%m-%d'),60.79787); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-12-18','%Y-%m-%d'),63.01007); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-03-13','%Y-%m-%d'),60.00080); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-12-19','%Y-%m-%d'),57.82680); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-03-14','%Y-%m-%d'),60.82333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-12-20','%Y-%m-%d'),62.59173); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-03-15','%Y-%m-%d'),59.62020); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-12-21','%Y-%m-%d'),61.65607); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-03-16','%Y-%m-%d'),60.27420); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-12-23','%Y-%m-%d'),61.80000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-03-17','%Y-%m-%d'),60.06200); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-12-24','%Y-%m-%d'),59.93333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-03-18','%Y-%m-%d'),60.88900); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-12-25','%Y-%m-%d'),50.93333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-03-19','%Y-%m-%d'),59.92547); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-12-26','%Y-%m-%d'),60.46667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-03-20','%Y-%m-%d'),59.99853); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-12-27','%Y-%m-%d'),62.06667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-03-21','%Y-%m-%d'),58.65873); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-12-28','%Y-%m-%d'),61.93333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-03-22','%Y-%m-%d'),60.61000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-12-29','%Y-%m-%d'),61.26667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-03-23','%Y-%m-%d'),59.92280); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-12-30','%Y-%m-%d'),61.60000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-03-24','%Y-%m-%d'),59.52427); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2014-12-31','%Y-%m-%d'),62.86667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-03-25','%Y-%m-%d'),59.44887); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-01-01','%Y-%m-%d'),60.93333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-03-26','%Y-%m-%d'),60.23540); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-01-02','%Y-%m-%d'),62.66667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-03-27','%Y-%m-%d'),61.18333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-01-03','%Y-%m-%d'),62.46667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-03-28','%Y-%m-%d'),60.88133); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-01-04','%Y-%m-%d'),60.80000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-03-29','%Y-%m-%d'),61.74160); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-01-06','%Y-%m-%d'),62.40000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-03-30','%Y-%m-%d'),60.25647); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-01-08','%Y-%m-%d'),61.40000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-03-31','%Y-%m-%d'),60.41220); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-01-09','%Y-%m-%d'),63.20000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-04-01','%Y-%m-%d'),59.21053); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-01-10','%Y-%m-%d'),61.82227); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-04-02','%Y-%m-%d'),55.04713); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-01-11','%Y-%m-%d'),61.89553); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-04-03','%Y-%m-%d'),56.08473); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-01-12','%Y-%m-%d'),60.90127); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-04-04','%Y-%m-%d'),64.51107); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-01-13','%Y-%m-%d'),62.23660); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-04-05','%Y-%m-%d'),56.75193); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-01-14','%Y-%m-%d'),61.76947); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-04-06','%Y-%m-%d'),61.64240); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-01-15','%Y-%m-%d'),63.08853); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-04-07','%Y-%m-%d'),61.33653); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-01-16','%Y-%m-%d'),60.12627); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-04-08','%Y-%m-%d'),69.28867); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-01-17','%Y-%m-%d'),60.60020); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-04-09','%Y-%m-%d'),60.87507); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-01-18','%Y-%m-%d'),60.43440); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-04-10','%Y-%m-%d'),68.08707); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-01-19','%Y-%m-%d'),65.02820); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-04-11','%Y-%m-%d'),60.57680); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-01-20','%Y-%m-%d'),62.95593); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-04-12','%Y-%m-%d'),61.52467); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-01-21','%Y-%m-%d'),61.23967); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-04-13','%Y-%m-%d'),58.06567); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-01-22','%Y-%m-%d'),62.61853); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-04-14','%Y-%m-%d'),59.80807); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-01-23','%Y-%m-%d'),63.64227); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-04-15','%Y-%m-%d'),79.90007); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-01-24','%Y-%m-%d'),63.42147); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-04-16','%Y-%m-%d'),54.75020); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-01-25','%Y-%m-%d'),60.82687); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-04-17','%Y-%m-%d'),65.69500); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-01-26','%Y-%m-%d'),60.66260); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-04-18','%Y-%m-%d'),68.56247); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-01-27','%Y-%m-%d'),60.12767); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-04-19','%Y-%m-%d'),72.67153); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-01-28','%Y-%m-%d'),60.51513); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-04-20','%Y-%m-%d'),71.30720); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-01-29','%Y-%m-%d'),61.71520); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-04-21','%Y-%m-%d'),57.75233); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-01-30','%Y-%m-%d'),60.89553); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-04-22','%Y-%m-%d'),59.04200); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-01-31','%Y-%m-%d'),63.50540); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-04-23','%Y-%m-%d'),62.30153); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-02-01','%Y-%m-%d'),62.37533); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-04-24','%Y-%m-%d'),67.68287); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-02-02','%Y-%m-%d'),60.31400); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-04-25','%Y-%m-%d'),69.21800); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-02-03','%Y-%m-%d'),63.43920); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-04-26','%Y-%m-%d'),69.75993); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-02-04','%Y-%m-%d'),61.20487); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-04-27','%Y-%m-%d'),64.64113); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-02-05','%Y-%m-%d'),62.11167); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-04-28','%Y-%m-%d'),60.10053); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-02-06','%Y-%m-%d'),59.96140); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-04-29','%Y-%m-%d'),58.67653); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-02-07','%Y-%m-%d'),62.60727); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-04-30','%Y-%m-%d'),58.29180); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-02-08','%Y-%m-%d'),61.95493); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-05-01','%Y-%m-%d'),60.56173); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-02-09','%Y-%m-%d'),58.89653); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-05-02','%Y-%m-%d'),57.15840); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-02-10','%Y-%m-%d'),66.20167); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-05-03','%Y-%m-%d'),54.49167); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-02-11','%Y-%m-%d'),64.76873); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-05-04','%Y-%m-%d'),61.54087); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-02-12','%Y-%m-%d'),69.90680); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-05-05','%Y-%m-%d'),63.86073); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-02-13','%Y-%m-%d'),68.49253); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-05-06','%Y-%m-%d'),64.13460); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-02-14','%Y-%m-%d'),63.19360); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-05-07','%Y-%m-%d'),65.30087); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-02-15','%Y-%m-%d'),63.35453); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-05-08','%Y-%m-%d'),64.46353); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-02-16','%Y-%m-%d'),59.78020); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-05-09','%Y-%m-%d'),62.81193); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-02-17','%Y-%m-%d'),60.70760); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-05-10','%Y-%m-%d'),56.14480); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-02-18','%Y-%m-%d'),58.05167); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-05-11','%Y-%m-%d'),61.47853); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-02-19','%Y-%m-%d'),57.12700); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-05-12','%Y-%m-%d'),63.39287); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-02-20','%Y-%m-%d'),59.49013); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-05-13','%Y-%m-%d'),64.30640); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-02-21','%Y-%m-%d'),59.18607); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-05-14','%Y-%m-%d'),64.29447); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-02-22','%Y-%m-%d'),60.94680); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-05-15','%Y-%m-%d'),65.63307); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-02-23','%Y-%m-%d'),59.85807); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-05-16','%Y-%m-%d'),62.32887); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-02-24','%Y-%m-%d'),60.06767); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-05-17','%Y-%m-%d'),56.52853); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-02-25','%Y-%m-%d'),61.60267); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-05-18','%Y-%m-%d'),70.26520); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-02-26','%Y-%m-%d'),60.94220); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-05-19','%Y-%m-%d'),64.38267); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-02-27','%Y-%m-%d'),59.99040); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-05-20','%Y-%m-%d'),63.01447); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-02-28','%Y-%m-%d'),63.05567); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-05-21','%Y-%m-%d'),61.89200); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-05-22','%Y-%m-%d'),62.06920); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-05-23','%Y-%m-%d'),68.49253); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-05-24','%Y-%m-%d'),69.98867); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-05-25','%Y-%m-%d'),60.26940); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-05-26','%Y-%m-%d'),62.91493); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-06-09','%Y-%m-%d'),62.28433); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-05-27','%Y-%m-%d'),62.36827); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-06-10','%Y-%m-%d'),64.38787); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-06-11','%Y-%m-%d'),61.17093); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-05-28','%Y-%m-%d'),60.33887); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-06-12','%Y-%m-%d'),57.17713); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-05-29','%Y-%m-%d'),83.89220); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-06-13','%Y-%m-%d'),57.69653); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-05-30','%Y-%m-%d'),60.96747); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-06-14','%Y-%m-%d'),55.97980); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-05-31','%Y-%m-%d'),57.80627); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-06-15','%Y-%m-%d'),62.08940); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-06-01','%Y-%m-%d'),61.60173); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-06-16','%Y-%m-%d'),83.81047); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-06-02','%Y-%m-%d'),63.23627); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-06-17','%Y-%m-%d'),61.32540); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-06-03','%Y-%m-%d'),58.39987); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-06-18','%Y-%m-%d'),61.08900); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-06-04','%Y-%m-%d'),69.51947); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-06-19','%Y-%m-%d'),67.26267); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-06-05','%Y-%m-%d'),69.67787); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-06-20','%Y-%m-%d'),58.71120); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-06-06','%Y-%m-%d'),62.40513); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-06-21','%Y-%m-%d'),55.77320); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-06-07','%Y-%m-%d'),61.01893); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-06-22','%Y-%m-%d'),59.99420); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-06-08','%Y-%m-%d'),61.34813); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-06-23','%Y-%m-%d'),60.83867); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-06-24','%Y-%m-%d'),59.57020); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-06-25','%Y-%m-%d'),63.20393); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-09-17','%Y-%m-%d'),67.93333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-06-26','%Y-%m-%d'),58.30480); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-09-18','%Y-%m-%d'),64.06667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-06-27','%Y-%m-%d'),58.79667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-09-19','%Y-%m-%d'),60.13333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-06-28','%Y-%m-%d'),54.04967); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-09-20','%Y-%m-%d'),57.86667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-06-29','%Y-%m-%d'),57.88313); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-09-21','%Y-%m-%d'),58.33333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-06-30','%Y-%m-%d'),56.94940); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-09-22','%Y-%m-%d'),59.86667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-07-01','%Y-%m-%d'),65.01080); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-09-23','%Y-%m-%d'),59.60000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-07-02','%Y-%m-%d'),64.97013); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-09-24','%Y-%m-%d'),59.80000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-07-03','%Y-%m-%d'),65.06647); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-09-25','%Y-%m-%d'),59.46667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-07-04','%Y-%m-%d'),64.08287); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-09-26','%Y-%m-%d'),76.00000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-07-05','%Y-%m-%d'),65.40367); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-09-27','%Y-%m-%d'),59.86667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-07-06','%Y-%m-%d'),72.61373); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-09-28','%Y-%m-%d'),59.13333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-07-07','%Y-%m-%d'),72.53120); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-09-29','%Y-%m-%d'),58.93333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-07-08','%Y-%m-%d'),72.54133); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-12-26','%Y-%m-%d'),58.93333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-09-30','%Y-%m-%d'),54.00000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-10-01','%Y-%m-%d'),58.26667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-10-02','%Y-%m-%d'),59.46667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-10-03','%Y-%m-%d'),58.86667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-10-04','%Y-%m-%d'),60.33333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-10-05','%Y-%m-%d'),101.00000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-10-06','%Y-%m-%d'),58.00000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-10-07','%Y-%m-%d'),59.53333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-10-08','%Y-%m-%d'),56.00000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-10-09','%Y-%m-%d'),57.93333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-10-10','%Y-%m-%d'),65.73333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-10-11','%Y-%m-%d'),56.00000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-10-12','%Y-%m-%d'),54.86667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-10-13','%Y-%m-%d'),68.60000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-10-14','%Y-%m-%d'),69.93333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-10-15','%Y-%m-%d'),66.86667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-10-16','%Y-%m-%d'),58.66667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-10-17','%Y-%m-%d'),60.06667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-10-18','%Y-%m-%d'),58.40000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-10-19','%Y-%m-%d'),55.26667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-10-20','%Y-%m-%d'),55.86667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-10-21','%Y-%m-%d'),57.86667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-10-22','%Y-%m-%d'),57.40000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-10-23','%Y-%m-%d'),58.20000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-10-24','%Y-%m-%d'),57.93333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-10-25','%Y-%m-%d'),58.60000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-10-26','%Y-%m-%d'),61.66667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-10-27','%Y-%m-%d'),57.66667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-10-28','%Y-%m-%d'),58.40000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-10-29','%Y-%m-%d'),59.33333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-10-30','%Y-%m-%d'),55.73333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-10-31','%Y-%m-%d'),53.80000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-11-01','%Y-%m-%d'),56.86667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-11-02','%Y-%m-%d'),57.00000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-11-03','%Y-%m-%d'),55.00000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-11-04','%Y-%m-%d'),57.06667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-11-05','%Y-%m-%d'),65.13333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-11-06','%Y-%m-%d'),55.26667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-11-07','%Y-%m-%d'),57.60000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-11-08','%Y-%m-%d'),59.06667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-11-09','%Y-%m-%d'),60.13333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-11-10','%Y-%m-%d'),58.93333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-11-11','%Y-%m-%d'),58.13333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-11-12','%Y-%m-%d'),57.40000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-11-13','%Y-%m-%d'),57.66667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-11-14','%Y-%m-%d'),55.80000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-11-15','%Y-%m-%d'),55.66667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-11-16','%Y-%m-%d'),58.26667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-11-17','%Y-%m-%d'),58.93333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-11-18','%Y-%m-%d'),64.73333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-11-19','%Y-%m-%d'),59.26667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-11-20','%Y-%m-%d'),57.66667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-11-21','%Y-%m-%d'),57.00000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-11-22','%Y-%m-%d'),59.00000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-11-23','%Y-%m-%d'),56.80000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-11-24','%Y-%m-%d'),58.60000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-11-25','%Y-%m-%d'),57.80000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-11-26','%Y-%m-%d'),57.13333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-11-27','%Y-%m-%d'),53.00000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-11-28','%Y-%m-%d'),58.80000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-11-29','%Y-%m-%d'),56.80000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-11-30','%Y-%m-%d'),58.93333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-12-01','%Y-%m-%d'),60.40000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-12-02','%Y-%m-%d'),59.60000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-12-03','%Y-%m-%d'),58.53333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-12-04','%Y-%m-%d'),77.60000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-12-05','%Y-%m-%d'),56.53333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-12-06','%Y-%m-%d'),55.93333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-12-07','%Y-%m-%d'),57.13333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-12-08','%Y-%m-%d'),57.20000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-12-09','%Y-%m-%d'),71.86667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-12-10','%Y-%m-%d'),62.53333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-12-11','%Y-%m-%d'),59.93333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-12-12','%Y-%m-%d'),59.13333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-12-13','%Y-%m-%d'),62.73333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-12-14','%Y-%m-%d'),59.66667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-12-15','%Y-%m-%d'),59.86667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-12-16','%Y-%m-%d'),62.00000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-12-17','%Y-%m-%d'),66.73333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-12-18','%Y-%m-%d'),59.46667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-12-19','%Y-%m-%d'),60.66667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-12-20','%Y-%m-%d'),57.26667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-12-21','%Y-%m-%d'),60.86667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-12-22','%Y-%m-%d'),59.86667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-12-23','%Y-%m-%d'),61.13333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-12-24','%Y-%m-%d'),57.93333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-12-25','%Y-%m-%d'),52.73333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-07-09','%Y-%m-%d'),70.77980); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-07-10','%Y-%m-%d'),70.40000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-07-11','%Y-%m-%d'),60.00000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-07-12','%Y-%m-%d'),58.40000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-07-13','%Y-%m-%d'),58.80000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-07-14','%Y-%m-%d'),58.73333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-07-15','%Y-%m-%d'),68.86667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-07-16','%Y-%m-%d'),84.00000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-07-17','%Y-%m-%d'),61.13333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-07-18','%Y-%m-%d'),64.40000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-07-19','%Y-%m-%d'),59.60000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-07-20','%Y-%m-%d'),77.00000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-07-21','%Y-%m-%d'),60.53333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-07-22','%Y-%m-%d'),65.33333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-07-23','%Y-%m-%d'),68.06667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-07-24','%Y-%m-%d'),58.53333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-07-25','%Y-%m-%d'),56.86667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-07-26','%Y-%m-%d'),58.73333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-07-27','%Y-%m-%d'),59.06667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-07-28','%Y-%m-%d'),59.73333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-07-29','%Y-%m-%d'),58.46667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-07-30','%Y-%m-%d'),59.40000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-12-27','%Y-%m-%d'),59.06667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-07-31','%Y-%m-%d'),57.93333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-12-28','%Y-%m-%d'),305.60000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-08-01','%Y-%m-%d'),59.93333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-12-29','%Y-%m-%d'),62.26667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-08-02','%Y-%m-%d'),61.26667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-12-30','%Y-%m-%d'),60.53333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-08-03','%Y-%m-%d'),59.06667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-12-31','%Y-%m-%d'),60.66667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-08-04','%Y-%m-%d'),83.00000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-01-01','%Y-%m-%d'),55.00000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-08-05','%Y-%m-%d'),59.80000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-01-02','%Y-%m-%d'),61.26667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-08-06','%Y-%m-%d'),58.53333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-01-03','%Y-%m-%d'),61.20000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-08-07','%Y-%m-%d'),59.13333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-01-04','%Y-%m-%d'),62.46667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-08-08','%Y-%m-%d'),57.33333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-01-05','%Y-%m-%d'),61.40000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-08-09','%Y-%m-%d'),58.66667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-01-06','%Y-%m-%d'),61.13333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-08-10','%Y-%m-%d'),59.06667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-01-07','%Y-%m-%d'),62.46667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-08-11','%Y-%m-%d'),58.80000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-01-08','%Y-%m-%d'),100.66667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-08-12','%Y-%m-%d'),57.20000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-01-09','%Y-%m-%d'),62.60000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-08-13','%Y-%m-%d'),61.60000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-01-10','%Y-%m-%d'),66.00000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-08-14','%Y-%m-%d'),58.66667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-01-11','%Y-%m-%d'),61.20000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-08-15','%Y-%m-%d'),59.66667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-01-12','%Y-%m-%d'),60.46667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-08-16','%Y-%m-%d'),61.40000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-01-13','%Y-%m-%d'),61.46667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-08-17','%Y-%m-%d'),59.06667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-01-14','%Y-%m-%d'),60.93333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-08-18','%Y-%m-%d'),59.60000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-01-15','%Y-%m-%d'),61.26667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-08-19','%Y-%m-%d'),59.60000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-01-16','%Y-%m-%d'),61.53333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-08-20','%Y-%m-%d'),60.33333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-01-17','%Y-%m-%d'),70.93333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-08-21','%Y-%m-%d'),63.80000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-01-18','%Y-%m-%d'),61.46667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-08-22','%Y-%m-%d'),58.53333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-01-19','%Y-%m-%d'),61.33333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-08-23','%Y-%m-%d'),59.00000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-01-20','%Y-%m-%d'),61.00000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-08-24','%Y-%m-%d'),59.66667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-01-21','%Y-%m-%d'),61.86667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-08-25','%Y-%m-%d'),63.06667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-01-22','%Y-%m-%d'),60.93333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-08-26','%Y-%m-%d'),61.33333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-01-23','%Y-%m-%d'),61.26667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-08-27','%Y-%m-%d'),60.73333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-01-24','%Y-%m-%d'),60.80000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-08-28','%Y-%m-%d'),57.13333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-01-25','%Y-%m-%d'),61.13333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-08-29','%Y-%m-%d'),59.13333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-01-26','%Y-%m-%d'),61.86667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-08-30','%Y-%m-%d'),57.13333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-01-27','%Y-%m-%d'),61.93333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-08-31','%Y-%m-%d'),59.86667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-01-28','%Y-%m-%d'),61.33333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-09-01','%Y-%m-%d'),58.26667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-01-29','%Y-%m-%d'),61.06667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-09-02','%Y-%m-%d'),61.46667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-01-30','%Y-%m-%d'),61.46667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-09-03','%Y-%m-%d'),59.60000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-01-31','%Y-%m-%d'),59.26667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-09-04','%Y-%m-%d'),59.53333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-02-01','%Y-%m-%d'),60.86667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-09-05','%Y-%m-%d'),59.93333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-02-02','%Y-%m-%d'),60.86667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-09-06','%Y-%m-%d'),61.66667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-02-03','%Y-%m-%d'),60.00000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-09-07','%Y-%m-%d'),59.20000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-02-04','%Y-%m-%d'),61.06667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-09-08','%Y-%m-%d'),61.73333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-02-05','%Y-%m-%d'),60.80000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-09-09','%Y-%m-%d'),61.60000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-02-06','%Y-%m-%d'),60.46667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-09-10','%Y-%m-%d'),60.26667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-02-07','%Y-%m-%d'),60.66667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-09-11','%Y-%m-%d'),58.00000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-02-08','%Y-%m-%d'),61.00000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-09-12','%Y-%m-%d'),58.60000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-02-09','%Y-%m-%d'),61.26667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-09-13','%Y-%m-%d'),58.53333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-02-10','%Y-%m-%d'),60.60000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-09-14','%Y-%m-%d'),60.66667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-02-11','%Y-%m-%d'),60.13333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-09-15','%Y-%m-%d'),62.06667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-02-12','%Y-%m-%d'),59.93333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2015-09-16','%Y-%m-%d'),65.60000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-02-13','%Y-%m-%d'),61.60000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-02-14','%Y-%m-%d'),69.33333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-02-15','%Y-%m-%d'),59.80000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-02-16','%Y-%m-%d'),59.80000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-02-17','%Y-%m-%d'),60.46667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-02-18','%Y-%m-%d'),61.26667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-02-19','%Y-%m-%d'),62.33333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-02-20','%Y-%m-%d'),60.93333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-02-21','%Y-%m-%d'),59.73333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-02-22','%Y-%m-%d'),61.40000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-02-23','%Y-%m-%d'),60.93333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-02-24','%Y-%m-%d'),64.13333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-02-25','%Y-%m-%d'),61.53333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-02-26','%Y-%m-%d'),59.06667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-02-27','%Y-%m-%d'),61.60000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-02-28','%Y-%m-%d'),60.86667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-02-29','%Y-%m-%d'),61.00000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-03-01','%Y-%m-%d'),61.86667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-03-02','%Y-%m-%d'),61.66667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-03-03','%Y-%m-%d'),60.73333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-03-04','%Y-%m-%d'),61.26667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-03-05','%Y-%m-%d'),61.60000); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-03-06','%Y-%m-%d'),61.33333); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-03-07','%Y-%m-%d'),61.86667); +INSERT INTO demo_util_chart (TRAFFIC_DATE,UTIL_PERC ) VALUES (str_to_date('2016-03-08','%Y-%m-%d'),62.00000); + +commit; \ No newline at end of file diff --git a/ecomp-sdk-app/policyLogger.properties b/ecomp-sdk-app/policyLogger.properties new file mode 100644 index 000000000..0deb1b3d6 --- /dev/null +++ b/ecomp-sdk-app/policyLogger.properties @@ -0,0 +1,44 @@ +### +# ============LICENSE_START======================================================= +# ECOMP Policy Engine +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +################################### Set concurrentHashMap and timer info ####################### +#Timer initial delay and the delay between in milliseconds before task is to be execute. +timer.delay.time=1000 +#Timer scheduleAtFixedRate period - time in milliseconds between successive task executions. +check.interval= 30000 +#Longest time an event info can be stored in the concurrentHashMap for logging - in seconds. +event.expired.time=86400 +#Size of the concurrentHashMap which stores the event starting time, etc - when its size reaches this limit, the Timer gets executed +#to remove all expired records from this concurrentHashMap. +concurrentHashMap.limit=5000 +#Size of the concurrentHashMap - when its size drops to this point, stop the Timer +stop.check.point=2500 +################################### Set logging format ############################################# +# set EELF for EELF logging format, set LOG4J for using log4j, set SYSTEMOUT for using system.out.println +logger.type=EELF +#################################### Set level for EELF or SYSTEMOUT logging ################################## +# Set level for debug file. Set DEBUG to enable .info, .warn and .debug; set INFO for enable .info and .warn; set OFF to disable all +debugLogger.level=INFO +# Set level for metrics file. Set OFF to disable; set ON to enable +metricsLogger.level=ON +# Set level for error file. Set OFF to disable; set ON to enable +error.level=ON +# Set level for audit file. Set OFF to disable; set ON to enable +audit.level=ON diff --git a/ecomp-sdk-app/pom.xml b/ecomp-sdk-app/pom.xml new file mode 100644 index 000000000..317e53c2f --- /dev/null +++ b/ecomp-sdk-app/pom.xml @@ -0,0 +1,324 @@ + + + + 4.0.0 + + org.openecomp.policy.engine + PolicyEngineSuite + 1.0.0-SNAPSHOT + + org.openecomp.policy.engine + ecomp-sdk-app + war + + + UTF-8 + 1.0.0 + 4.2.0.RELEASE + 4.3.11.Final + true + + true + 2.6.0 + + + + + + doclint-java8-disable + + [1.8,) + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.10.4 + + -Xdoclint:none + + + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + 1.8 + 1.8 + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.19.1 + + ${skiptests} + + **/Test*.java + **/*Test.java + **/*TestCase.java + + + ${basedir}/war + + + classpath: + + + + + + maven-assembly-plugin + + ${skipassembly} + + ${basedir}/distribution.xml + + + + + make-assembly + package + + single + + + + + + + + + + org.openecomp.ecompsdkos + ecompSDK-core + ${epsdk.version} + + + org.openecomp.ecompsdkos + ecompSDK-analytics + ${epsdk.version} + + + com.oracle + ojdbc6 + + + + + org.openecomp.ecompsdkos + ecompSDK-workflow + ${epsdk.version} + + + com.att.eelf + eelf-core + 0.0.1 + + + + + org.springframework + spring-core + ${springframework.version} + + + commons-logging + commons-logging + + + + + org.springframework + spring-test + ${springframework.version} + + + org.springframework + spring-web + ${springframework.version} + + + org.springframework + spring-webmvc + ${springframework.version} + + + org.springframework + spring-tx + ${springframework.version} + + + org.springframework + spring-context-support + ${springframework.version} + + + + javax.mail + mail + 1.4.7 + + + + org.slf4j + jcl-over-slf4j + 1.7.12 + + + org.apache.commons + commons-compress + 1.8 + + + + com.fasterxml.jackson.core + jackson-annotations + 2.6.3 + + + com.fasterxml.jackson.core + jackson-core + 2.6.3 + + + com.fasterxml.jackson.core + jackson-databind + 2.6.3 + + + com.fasterxml.jackson.module + jackson-module-jaxb-annotations + ${jackson.version} + + + com.fasterxml.jackson.module + jackson-module-jsonSchema + ${jackson.version} + + + com.fasterxml.jackson.dataformat + jackson-dataformat-xml + ${jackson.version} + + + com.mchange + c3p0 + 0.9.5.2 + + + args4j + args4j + 2.32 + + + + org.mariadb.jdbc + mariadb-java-client + 1.2.3 + + + commons-dbcp + commons-dbcp + 1.4 + + + org.eclipse.jgit + org.eclipse.jgit + 3.2.0.201312181205-r + + + + org.quartz-scheduler + quartz + 2.2.1 + + + + c3p0 + c3p0 + + + + + javax.servlet + javax.servlet-api + 3.1.0 + + + junit + junit + 4.12 + + + + org.elasticsearch + elasticsearch + 2.2.0 + + + org.json + json + 20160212 + + + io.searchbox + jest + 2.0.0 + + + commons-logging + commons-logging + + + + + + org.openecomp.policy.engine + ECOMP-PDP + ${project.version} + + + commons-logging + commons-logging + + + org.apache.httpcomponents + httpcore + + + + + commons-fileupload + commons-fileupload + 1.3.1 + + + diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/AddressGroupJson.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/AddressGroupJson.java new file mode 100644 index 000000000..e60e4061e --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/AddressGroupJson.java @@ -0,0 +1,79 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.adapter; + + +import java.util.ArrayList; +import java.util.List; + +public class AddressGroupJson { + + protected String name; + protected String description; + protected List members; + + // name + public String getName() { + return name; + } + + public void setName(String value) { + this.name = value; + } + + public boolean equals(Object obj) + { + AddressGroupJson servGroupobj=(AddressGroupJson) obj; + if(this.getName().equals(servGroupobj.getName())) + { + return true; + } + return false; + } + + public int hashCode() { + return Integer.valueOf(name.charAt(0)+(name.charAt(1))); + } + + // description + public String getDescription() { + return description; + } + + public void setDescription(String value) { + this.description = value; + } + + public List getMembers() + { + if(members==null) + { + members= new ArrayList(); + } + return this.members; + } + + public void setMembers(List members) + { + this.members = members; + } + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/AddressJson.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/AddressJson.java new file mode 100644 index 000000000..372eddf1b --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/AddressJson.java @@ -0,0 +1,44 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.adapter; + + +public class AddressJson { + + protected String type; + protected String value; + // type + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/AddressMembers.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/AddressMembers.java new file mode 100644 index 000000000..3fd22eec6 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/AddressMembers.java @@ -0,0 +1,46 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.adapter; + + + +public class AddressMembers { + + protected String type; + protected String value; + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/AutoPushTabAdapter.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/AutoPushTabAdapter.java new file mode 100644 index 000000000..85f767f26 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/AutoPushTabAdapter.java @@ -0,0 +1,42 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.adapter; + + +import java.util.ArrayList; + +public class AutoPushTabAdapter { + + private ArrayList pdpDatas; + private ArrayList policyDatas; + public ArrayList getPdpDatas() { + return pdpDatas; + } + public void setPdpDatas(ArrayList pdpDatas) { + this.pdpDatas = pdpDatas; + } + public ArrayList getPolicyDatas() { + return policyDatas; + } + public void setPolicyDatas(ArrayList policyDatas) { + this.policyDatas = policyDatas; + } +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/ClosedLoopFaultBody.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/ClosedLoopFaultBody.java new file mode 100644 index 000000000..cb1ce55a6 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/ClosedLoopFaultBody.java @@ -0,0 +1,280 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.adapter; + + + +public class ClosedLoopFaultBody { + + private boolean trinity; + private boolean vUSP; + private boolean mcr; + private boolean gama; + private boolean vDNS; + + private String vnfType; + private String vServices; + private String ECOMPname; + + private String closedLoopPolicyStatus; + private ClosedLoopSignatures triggerSignatures; + private String actions; + private int timeInterval; + private int timeOutvPRO; + private int timeOutRuby; + private int retrys; + private int agingWindow; + private String geoLink; + private String emailAddress; + private ClosedLoopSignatures verificationSignatures; + private ClosedLoopPolicyConditions conditions; + private ClosedLoopFaultTriggerUISignatures triggerSignaturesUsedForUI; + private ClosedLoopFaultTriggerUISignatures verificationSignaturesUsedForUI; + private int triggerTimeWindowUsedForUI; + private int verfificationTimeWindowUsedForUI; + private String pepName; + private String pepAction; + private String templateVersion; + private int trapMaxAgeUsedForUI; + + + public Integer getTrapMaxAgeUsedForUI() { + return trapMaxAgeUsedForUI; + } + + public void setTrapMaxAgeUsedForUI(int trapMaxAgeUsedForUI) { + this.trapMaxAgeUsedForUI = trapMaxAgeUsedForUI; + } + + public String getTemplateVersion() { + return templateVersion; + } + + public void setTemplateVersion(String templateVersion) { + this.templateVersion = templateVersion; + } + + public Integer getTimeOutvPRO() { + return timeOutvPRO; + } + + public void setTimeOutvPRO(int timeOutvPRO) { + this.timeOutvPRO = timeOutvPRO; + } + + + public Integer getTriggerTimeWindowUsedForUI() { + return triggerTimeWindowUsedForUI; + } + + public String getPepName() { + return pepName; + } + + public void setPepName(String pepName) { + this.pepName = pepName; + } + + public String getPepAction() { + return pepAction; + } + + public void setPepAction(String pepAction) { + this.pepAction = pepAction; + } + + public void setTriggerTimeWindowUsedForUI(int triggerTimeWindowUsedForUI) { + this.triggerTimeWindowUsedForUI = triggerTimeWindowUsedForUI; + } + + public Integer getVerfificationTimeWindowUsedForUI() { + return verfificationTimeWindowUsedForUI; + } + + public void setVerfificationTimeWindowUsedForUI( + int verfificationTimeWindowUsedForUI) { + this.verfificationTimeWindowUsedForUI = verfificationTimeWindowUsedForUI; + } + + public String getECOMPname(){ + return ECOMPname; + } + + public void setECOMPname(String ECOMPname){ + this.ECOMPname = ECOMPname; + } + + public String getvServices() { + return vServices; + } + public void setvServices(String vServices) { + this.vServices = vServices; + } + + public ClosedLoopFaultTriggerUISignatures getVerificationSignaturesUsedForUI() { + return verificationSignaturesUsedForUI; + } + public void setVerificationSignaturesUsedForUI( + ClosedLoopFaultTriggerUISignatures verificationSignaturesUsedForUI) { + this.verificationSignaturesUsedForUI = verificationSignaturesUsedForUI; + } + public ClosedLoopFaultTriggerUISignatures getTriggerSignaturesUsedForUI() { + return triggerSignaturesUsedForUI; + } + public void setTriggerSignaturesUsedForUI( + ClosedLoopFaultTriggerUISignatures triggerSignaturesUsedForUI) { + this.triggerSignaturesUsedForUI = triggerSignaturesUsedForUI; + } + public ClosedLoopPolicyConditions getConditions() { + return conditions; + } + public void setConditions(ClosedLoopPolicyConditions conditions) { + this.conditions = conditions; + } + + public String getVnfType() { + return vnfType; + } + public void setVnfType(String vnfType) { + this.vnfType = vnfType; + } + + public Integer getAgingWindow() { + return agingWindow; + } + public void setAgingWindow(int agingWindow) { + this.agingWindow = agingWindow; + } + + public String getClosedLoopPolicyStatus() { + return closedLoopPolicyStatus; + } + public void setClosedLoopPolicyStatus( + String closedLoopPolicyStatus) { + this.closedLoopPolicyStatus = closedLoopPolicyStatus; + } + public ClosedLoopSignatures getTriggerSignatures() { + return triggerSignatures; + } + public void setTriggerSignatures(ClosedLoopSignatures triggerSignatures) { + this.triggerSignatures = triggerSignatures; + } + public String getActions() { + return actions; + } + public void setActions(String actions) { + this.actions = actions; + } + public Integer getTimeInterval() { + return timeInterval; + } + public void setTimeInterval(int timeInterval) { + this.timeInterval = timeInterval; + } + public Integer getTimeOutRuby() { + return timeOutRuby; + } + public void setTimeOutRuby(int timeOutRuby) { + this.timeOutRuby = timeOutRuby; + } + public Integer getRetrys() { + return retrys; + } + public void setRetrys(int retrys) { + this.retrys = retrys; + } + public String getGeoLink() { + return geoLink; + } + public void setGeoLink(String geoLink) { + this.geoLink = geoLink; + } + public String getEmailAddress() { + return emailAddress; + } + public void setEmailAddress(String emailAddress) { + this.emailAddress = emailAddress; + } + public ClosedLoopSignatures getVerificationSignatures() { + return verificationSignatures; + } + public void setVerificationSignatures( + ClosedLoopSignatures verificationSignatures) { + this.verificationSignatures = verificationSignatures; + } + + /*public ArrayList getD2Services() { + return d2Services; + } + + public void setD2Services(ArrayList d2Services) { + this.d2Services = d2Services; + } + + public ArrayList getSiteNames() { + return siteNames; + } + + public void setSiteNames(ArrayList siteNames) { + this.siteNames = siteNames; + }*/ + + public boolean isvDNS() { + return vDNS; + } + + public void setvDNS(boolean vDNS) { + this.vDNS = vDNS; + } + + public boolean isTrinity() { + return trinity; + } + + public void setTrinity(boolean trinity) { + this.trinity = trinity; + } + + public boolean isvUSP() { + return vUSP; + } + + public void setvUSP(boolean vUSP) { + this.vUSP = vUSP; + } + + public boolean isMcr() { + return mcr; + } + + public void setMcr(boolean mcr) { + this.mcr = mcr; + } + + public boolean isGama() { + return gama; + } + + public void setGama(boolean gama) { + this.gama = gama; + } +} + diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/ClosedLoopFaultTriggerUISignatures.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/ClosedLoopFaultTriggerUISignatures.java new file mode 100644 index 000000000..2330496fe --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/ClosedLoopFaultTriggerUISignatures.java @@ -0,0 +1,44 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.adapter; + + + +public class ClosedLoopFaultTriggerUISignatures { + + private String signatures; + + private String connectSignatures; + + public String getConnectSignatures() { + return connectSignatures; + } + public void setConnectSignatures(String connectSignatures) { + this.connectSignatures = connectSignatures; + } + public String getSignatures() { + return signatures; + } + public void setSignatures(String signatures) { + this.signatures = signatures; + } + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/ClosedLoopPMBody.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/ClosedLoopPMBody.java new file mode 100644 index 000000000..bbbf5508b --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/ClosedLoopPMBody.java @@ -0,0 +1,133 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.adapter; + + +import java.util.Map; + +public class ClosedLoopPMBody { + + private boolean trinity; + private boolean vUSP; + private boolean mcr; + private boolean gama; + private boolean vDNS; + private String geoLink; + private String vServices; + private String ECOMPname; + + private String emailAddress; + + private String serviceTypePolicyName; + + private Map attributes; + private String templateVersion; + + public String getTemplateVersion() { + return templateVersion; + } + + public void setTemplateVersion(String templateVersion) { + this.templateVersion = templateVersion; + } + + public String getECOMPname(){ + return ECOMPname; + } + + public void setECOMPname(String ECOMPname){ + this.ECOMPname = ECOMPname; + } + + public String getvServices() { + return vServices; + } + + public void setvServices(String vServices) { + this.vServices = vServices; + } + + public Map getAttributes() { + return attributes; + } + + public void setAttributes(Map map) { + this.attributes = map; + } + + public String getGeoLink() { + return geoLink; + } + + public void setGeoLink(String geoLink) { + this.geoLink = geoLink; + } + + public String getEmailAddress() { + return emailAddress; + } + + public void setEmailAddress(String emailAddress) { + this.emailAddress = emailAddress; + } + + public String getServiceTypePolicyName() { + return serviceTypePolicyName; + } + + public void setServiceTypePolicyName(String serviceTypePolicyName) { + this.serviceTypePolicyName = serviceTypePolicyName; + } + + public boolean isGama() { + return gama; + } + public void setGama(boolean gama) { + this.gama = gama; + } + public boolean isvDNS() { + return vDNS; + } + public void setvDNS(boolean vDNS) { + this.vDNS = vDNS; + } + + public boolean isTrinity() { + return trinity; + } + public void setTrinity(boolean trinity) { + this.trinity = trinity; + } + public boolean isvUSP() { + return vUSP; + } + public void setvUSP(boolean vUSP) { + this.vUSP = vUSP; + } + public boolean isMcr() { + return mcr; + } + public void setMcr(boolean mcr) { + this.mcr = mcr; + } + +} + diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/ClosedLoopPerformanceMetrics.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/ClosedLoopPerformanceMetrics.java new file mode 100644 index 000000000..25d83169f --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/ClosedLoopPerformanceMetrics.java @@ -0,0 +1,36 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.adapter; + + +public class ClosedLoopPerformanceMetrics { + public static final String CLPM_UIFIELD_ONSET_MESSAGE = "Onset Message"; + public static final String CLPM_UIJSON_ONSET_MESSAGE = "attributes.OnsetMessage"; + + public static final String CLPM_UIFIELD_POLICY_NAME = "PolicyName"; + public static final String CLPM_UIJSON_POLICY_NAME = "attributes.PolicyName"; + + public static final String CLPM_UIFIELD_ABATEMENT_MESSAGE = "Abatement Message"; + public static final String CLPM_UIJSON_ABATEMENT_MESSAGE = "attributes.AbatementMessage"; + + public static final String CLPM_UIFIELD_GEOLINK = "Geo Link"; + public static final String CLPM_UIJSON_GEOLINK = "geoLink"; +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/ClosedLoopPolicy.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/ClosedLoopPolicy.java new file mode 100644 index 000000000..727c9cba8 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/ClosedLoopPolicy.java @@ -0,0 +1,61 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.adapter; + + +public class ClosedLoopPolicy { + public static final String CLFAULT_UIFIELD_D2_SERVICES_TRINITY = "Hosted Voice (Trinity)"; + public static final String CLFAULT_UIJSON_D2_SERVICES_TRINITY = "trinity"; + + public static final String CLFAULT_UIFIELD_D2_SERVICES_VUSP = "vUSP"; + public static final String CLFAULT_UIJSON_D2_SERVICES_VUSP = "vUSP"; + + public static final String CLFAULT_UIFIELD_D2_SERVICES_MCR = "MCR"; + public static final String CLFAULT_UIJSON_D2_SERVICES_MCR = "mcr"; + + public static final String CLFAULT_UIFIELD_D2_SERVICES_GAMMA = "Gamma"; + public static final String CLFAULT_UIJSON_D2_SERVICES_GAMMA = "gama"; + + public static final String CLFAULT_UIFIELD_D2_SERVICES_VDNS = "vDNS"; + public static final String CLFAULT_UIJSON_D2_SERVICES_VDNS = "vDNS"; + + public static final String CLFAULT_UIFIELD_EMAIL_ADDRESS = "Email Address"; + public static final String CLFAULT_UIJSON_EMAIL_ADDRESS = "emailAddress"; + + public static final String CLFAULT_UIFIELD_TRIGGER_SIGNATURE = "Trigger Signature"; + public static final String CLFAULT_UIJSON_TRIGGER_SIGNATURE = "triggerSignaturesUsedForUI.signatures"; + + public static final String CLFAULT_UIFIELD_VERIFICATION_SIGNATURE = "Verification Signature"; + public static final String CLFAULT_UIJSON_VERIFICATION_SIGNATURE = "verificationSignaturesUsedForUI.signatures"; + + public static final String CLFAULT_UIFIELD_CONNECT_ALL_TRAPS = "Connect All Traps"; + public static final String CLFAULT_UIJSON_CONNECT_ALL_TRAPS = "triggerSignaturesUsedForUI.connectSignatures"; + + public static final String CLFAULT_UIFIELD_CONNECT_ALL_FAULTS = "Connect All Faults"; + public static final String CLFAULT_UIJSON_CONNECT_ALL_FAULTS = "verificationSignaturesUsedForUI.connectSignatures"; + + public static final String CLFAULT_UIFIELD_POLICY_STATUS_ACTIVE = "Active"; + public static final String CLFAULT_UIJSON_POLICY_STATUS_ACTIVE = "ACTIVE"; + + public static final String CLFAULT_UIFIELD_POLICY_STATUS_INACTIVE = "InActive"; + public static final String CLFAULT_UIJSON_POLICY_STATUS_INACTIVE = "INACTIVE"; + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/ClosedLoopPolicyConditions.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/ClosedLoopPolicyConditions.java new file mode 100644 index 000000000..cdae20e17 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/ClosedLoopPolicyConditions.java @@ -0,0 +1,39 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.adapter; + + +public enum ClosedLoopPolicyConditions { + SEND("DCAE should send event notification"), + + NOTSEND("DCAE should not send event notification"); + private String name; + + private ClosedLoopPolicyConditions(String name){ + this.name = name; + } + + @Override + public String toString(){ + return this.name; + } +} + diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/ClosedLoopPolicyStatus.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/ClosedLoopPolicyStatus.java new file mode 100644 index 000000000..7ecd3b053 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/ClosedLoopPolicyStatus.java @@ -0,0 +1,41 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.adapter; + + +public enum ClosedLoopPolicyStatus { + ACTIVE("active"), + + INACTIVE("inactive") + ; + + private String name; + + private ClosedLoopPolicyStatus(String name){ + this.name = name; + } + + @Override + public String toString(){ + return this.name; + } +} + diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/ClosedLoopSignatures.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/ClosedLoopSignatures.java new file mode 100644 index 000000000..2eab27eea --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/ClosedLoopSignatures.java @@ -0,0 +1,52 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.adapter; + + +public class ClosedLoopSignatures { + + private String signatures; + + private int timeWindow; + + private Integer trapMaxAge; + + public String getSignatures() { + return signatures; + } + public void setSignatures(String signatures) { + this.signatures = signatures; + } + + public Integer getTimeWindow() { + return timeWindow; + } + public void setTimeWindow(Integer timeWindow) { + this.timeWindow = timeWindow; + } + + public Integer getTrapMaxAge() { + return trapMaxAge; + } + public void setTrapMaxAge(Integer trapMaxAge) { + this.trapMaxAge = trapMaxAge; + } +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/DeletePolicyCondition.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/DeletePolicyCondition.java new file mode 100644 index 000000000..4698aa672 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/DeletePolicyCondition.java @@ -0,0 +1,38 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.adapter; + + +public enum DeletePolicyCondition { + ONE("Are you sure you want to delete Current Version of policy"), + + ALL("Are you sure you want to delete All Versions of policy"); + private String name; + + private DeletePolicyCondition(String name){ + this.name = name; + } + + @Override + public String toString(){ + return this.name; + } +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/DeployNowJson.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/DeployNowJson.java new file mode 100644 index 000000000..635431559 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/DeployNowJson.java @@ -0,0 +1,36 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.adapter; + + +public class DeployNowJson { + + protected boolean deployNow; + + // deployNow + public boolean getDeployNow() { + return deployNow; + } + + public void setDeployNow(boolean value) { + this.deployNow = value; + } +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/GridData.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/GridData.java new file mode 100644 index 000000000..dfb3e0024 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/GridData.java @@ -0,0 +1,54 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.adapter; + + +import java.util.ArrayList; + +public class GridData { + private ArrayList attributes; + private ArrayList transportProtocols; + private ArrayList appProtocols; + + public ArrayList getAttributes() { + return attributes; + } + + public void setAttributes(ArrayList attributes) { + this.attributes = attributes; + } + + public ArrayList getAppProtocols() { + return appProtocols; + } + + public void setAppProtocols(ArrayList appProtocols) { + this.appProtocols = appProtocols; + } + + public ArrayList getTransportProtocols() { + return transportProtocols; + } + + public void setTransportProtocols(ArrayList transportProtocols) { + this.transportProtocols = transportProtocols; + } +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/PolicyAdapter.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/PolicyAdapter.java new file mode 100644 index 000000000..f9a0bd48e --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/PolicyAdapter.java @@ -0,0 +1,619 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.adapter; + + +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import org.openecomp.policy.rest.jpa.EcompName; + +public class PolicyAdapter { + + private Object data; + private String policyName = null; + private Path parentPath; + public boolean isEditPolicy = false; + private boolean isViewPolicy = false; + private Object policyData = null; + private String comboPolicyType; + private boolean readOnly; + + //adding new properties for REST interface call when creating Policies + private String oldPolicyFileName = null; + private String configType = null; + private String policyID = null; + private String policyType = null; + private String configPolicyType = null; + private String policyDescription = null; + private String ecompName = null; + private String configName = null; + private String ruleID = null; + private String ruleCombiningAlgId = null; + private Map dynamicFieldConfigAttributes; + private Map dropDownMap; + private Map dynamicSettingsMap; + private Path gitPath; + private String configBodyData = null; + private boolean isValidData = false; + private boolean draft = false; + private String version = null; + private String domain = null; + private String filterName = null; + private String comboConfigPolicyType; + private String jsonBody = null; + private Map brmsParamBody=null; + private Integer highestVersion; + private String actionPerformer = null; + private String actionAttribute = null; + private List dynamicRuleAlgorithmLabels; + private List dynamicRuleAlgorithmCombo; + private List dynamicRuleAlgorithmField1; + private List dynamicRuleAlgorithmField2; + private List dynamicVariableList; + private List dataTypeList; + private String actionBody = null; + private String actionDictHeader = null; + private String actionDictType = null; + private String actionDictUrl = null; + private String actionDictMethod = null; + private String serviceType = null; + private String uuid = null; + private String location = null; + private String priority = null; + private String actionAttributeValue; + private String ruleProvider; + + private EcompName ecompNameField; + private Object jsonBodyData; + private String dirPath; + private String configBodyPath; + private ArrayList attributes; + private ArrayList settings; + private ArrayList ruleAlgorithmschoices; + + private LinkedHashMap serviceTypePolicyName; + private String ruleName; + private LinkedHashMap ruleData; + private LinkedHashMap ruleListData; + private String clearTimeOut; + private String trapMaxAge; + private String verificationclearTimeOut; + private String fwPolicyType; + private ArrayList fwattributes; + private String parentForChild; + public String getFwPolicyType() { + return fwPolicyType; + } + public ArrayList getFwattributes() { + return fwattributes; + } + public String getParentForChild() { + return parentForChild; + } + public void setFwPolicyType(String fwPolicyType) { + this.fwPolicyType = fwPolicyType; + } + public void setFwattributes(ArrayList fwattributes) { + this.fwattributes = fwattributes; + } + public void setParentForChild(String parentForChild) { + this.parentForChild = parentForChild; + } + + private String riskLevel; + private String riskType = null; + private String guard = null; + private String ttlDate = null; + + public String getClearTimeOut() { + return clearTimeOut; + } + public void setClearTimeOut(String clearTimeOut) { + this.clearTimeOut = clearTimeOut; + } + public String getTrapMaxAge() { + return trapMaxAge; + } + public void setTrapMaxAge(String trapMaxAge) { + this.trapMaxAge = trapMaxAge; + } + public String getVerificationclearTimeOut() { + return verificationclearTimeOut; + } + public void setVerificationclearTimeOut(String verificationclearTimeOut) { + this.verificationclearTimeOut = verificationclearTimeOut; + } + public LinkedHashMap getRuleListData() { + return ruleListData; + } + public void setRuleListData(LinkedHashMap ruleListData) { + this.ruleListData = ruleListData; + } + private ArrayList triggerSignatures; + private ArrayList symptomSignatures; + private String logicalConnector; + private String policyStatus; + public String gocServerScope; + public Map dynamicLayoutMap; + private String securityZone; + + private String policyScope; + private String supressionType; + + + + public String getSupressionType() { + return supressionType; + } + public void setSupressionType(String supressionType) { + this.supressionType = supressionType; + } + public Map getDynamicLayoutMap() { + return dynamicLayoutMap; + } + public void setDynamicLayoutMap(Map dynamicLayoutMap) { + this.dynamicLayoutMap = dynamicLayoutMap; + } + public String getGocServerScope() { + return gocServerScope; + } + public void setGocServerScope(String gocServerScope) { + this.gocServerScope = gocServerScope; + } + public Object getJsonBodyData() { + return jsonBodyData; + } + public void setJsonBodyData(Object jsonBodyData) { + this.jsonBodyData = jsonBodyData; + } + public EcompName getEcompNameField() { + return ecompNameField; + } + public void setEcompNameField(EcompName ecompNameField) { + this.ecompNameField = ecompNameField; + } + public Integer getHighestVersion() { + return highestVersion; + } + public void setHighestVersion(Integer highestVersion) { + this.highestVersion = highestVersion; + } + public String getConfigType() { + return configType; + } + public void setConfigType(String configType) { + this.configType = configType; + } + public String getPolicyID() { + return policyID; + } + public void setPolicyID(String policyID) { + this.policyID = policyID; + } + public String getPolicyType() { + return policyType; + } + public void setPolicyType(String policyType) { + this.policyType = policyType; + } + public String getPolicyDescription() { + return policyDescription; + } + public void setPolicyDescription(String policyDescription) { + this.policyDescription = policyDescription; + } + public String getEcompName() { + return ecompName; + } + public void setEcompName(String ecompName) { + this.ecompName = ecompName; + } + public String getConfigName() { + return configName; + } + public void setConfigName(String configName) { + this.configName = configName; + } + public String getRuleID() { + return ruleID; + } + public void setRuleID(String ruleID) { + this.ruleID = ruleID; + } + public String getRuleCombiningAlgId() { + return ruleCombiningAlgId; + } + public void setRuleCombiningAlgId(String ruleCombiningAlgId) { + this.ruleCombiningAlgId = ruleCombiningAlgId; + } + public Map getDynamicFieldConfigAttributes() { + return dynamicFieldConfigAttributes; + } + public void setDynamicFieldConfigAttributes( + Map dynamicFieldConfigAttributes) { + this.dynamicFieldConfigAttributes = dynamicFieldConfigAttributes; + } + public Path getGitPath() { + return gitPath; + } + public void setGitPath(Path gitPath) { + this.gitPath = gitPath; + } + public Object getData() { + return data; + } + public void setData(Object data) { + this.data = data; + } + public String getPolicyName() { + return policyName; + } + public void setPolicyName(String policyName) { + this.policyName = policyName; + } + public Path getParentPath() { + return parentPath; + } + public void setParentPath(Path parentPath) { + this.parentPath = parentPath; + } + public boolean isEditPolicy() { + return isEditPolicy; + } + public void setEditPolicy(boolean isEditPolicy) { + this.isEditPolicy = isEditPolicy; + } + public boolean isViewPolicy() { + return isViewPolicy; + } + public void setViewPolicy(boolean isViewPolicy) { + this.isViewPolicy = isViewPolicy; + } + public Object getPolicyData() { + return policyData; + } + public void setPolicyData(Object policyData) { + this.policyData = policyData; + } + public String getComboPolicyType() { + return comboPolicyType; + } + public void setComboPolicyType(String comboPolicyType) { + this.comboPolicyType = comboPolicyType; + } + public boolean isReadOnly() { + return readOnly; + } + public void setReadOnly(boolean readOnly) { + this.readOnly = readOnly; + } + public String getConfigBodyData() { + return configBodyData; + } + public void setConfigBodyData(String configBodyData) { + this.configBodyData = configBodyData; + } + public boolean isValidData() { + return isValidData; + } + public void setValidData(boolean isValidData) { + this.isValidData = isValidData; + } + public String getVersion() { + return version; + } + public void setVersion(String version) { + this.version = version; + } + public String getDomainDir() { + return domain; + } + public void setDomainDir(java.lang.String domain) { + this.domain = domain; + + } + public String getFilterName() { + return filterName; + } + public void setFilterName(String filterName) { + this.filterName = filterName; + } + public String getComboConfigPolicyType() { + return comboConfigPolicyType; + } + public void setComboConfigPolicyType(String comboConfigPolicyType) { + this.comboConfigPolicyType = comboConfigPolicyType; + } + public Map getBRMSParamBody() { + return brmsParamBody; + } + public void setBRMSParamBody(Map brmsParamBody) { + this.brmsParamBody = brmsParamBody; + } + public String getJsonBody() { + return jsonBody; + } + public void setJsonBody(String jsonBody) { + this.jsonBody = jsonBody; + } + public String getConfigPolicyType() { + return configPolicyType; + } + public void setConfigPolicyType(String configPolicyType) { + this.configPolicyType = configPolicyType; + } + public String getActionPerformer() { + return actionPerformer; + } + public void setActionPerformer(String actionPerformer) { + this.actionPerformer = actionPerformer; + } + public String getActionAttribute() { + return actionAttribute; + } + public void setActionAttribute(String actionAttribute) { + this.actionAttribute = actionAttribute; + } + public List getDynamicRuleAlgorithmLabels() { + return dynamicRuleAlgorithmLabels; + } + public void setDynamicRuleAlgorithmLabels( + List dynamicRuleAlgorithmLabels) { + this.dynamicRuleAlgorithmLabels = dynamicRuleAlgorithmLabels; + } + public List getDynamicRuleAlgorithmCombo() { + return dynamicRuleAlgorithmCombo; + } + public void setDynamicRuleAlgorithmCombo( + List dynamicRuleAlgorithmCombo) { + this.dynamicRuleAlgorithmCombo = dynamicRuleAlgorithmCombo; + } + public List getDynamicRuleAlgorithmField1() { + return dynamicRuleAlgorithmField1; + } + public void setDynamicRuleAlgorithmField1( + List dynamicRuleAlgorithmField1) { + this.dynamicRuleAlgorithmField1 = dynamicRuleAlgorithmField1; + } + public List getDynamicRuleAlgorithmField2() { + return dynamicRuleAlgorithmField2; + } + public void setDynamicRuleAlgorithmField2( + List dynamicRuleAlgorithmField2) { + this.dynamicRuleAlgorithmField2 = dynamicRuleAlgorithmField2; + } + public String getActionBody() { + return actionBody; + } + public void setActionBody(String actionBody) { + this.actionBody = actionBody; + } + public Map getDropDownMap() { + return dropDownMap; + } + public void setDropDownMap(Map dropDownMap) { + this.dropDownMap = dropDownMap; + } + public String getActionDictHeader() { + return actionDictHeader; + } + public void setActionDictHeader(String actionDictHeader) { + this.actionDictHeader = actionDictHeader; + } + public String getActionDictType() { + return actionDictType; + } + public void setActionDictType(String actionDictType) { + this.actionDictType = actionDictType; + } + public String getActionDictUrl() { + return actionDictUrl; + } + public void setActionDictUrl(String actionDictUrl) { + this.actionDictUrl = actionDictUrl; + } + public String getActionDictMethod() { + return actionDictMethod; + } + public void setActionDictMethod(String actionDictMethod) { + this.actionDictMethod = actionDictMethod; + } + public boolean isDraft() { + return draft; + } + public void setDraft(boolean draft) { + this.draft = draft; + } + public Map getDynamicSettingsMap() { + return dynamicSettingsMap; + } + public void setDynamicSettingsMap(Map dynamicSettingsMap) { + this.dynamicSettingsMap = dynamicSettingsMap; + } + public List getDynamicVariableList() { + return dynamicVariableList; + } + public void setDynamicVariableList(List dynamicVariableList) { + this.dynamicVariableList = dynamicVariableList; + } + public List getDataTypeList() { + return dataTypeList; + } + public void setDataTypeList(List dataTypeList) { + this.dataTypeList = dataTypeList; + } + public String getOldPolicyFileName() { + return oldPolicyFileName; + } + public void setOldPolicyFileName(String oldPolicyFileName) { + this.oldPolicyFileName = oldPolicyFileName; + } + public String getServiceType() { + return serviceType; + } + public void setServiceType(String serviceType) { + this.serviceType = serviceType; + } + public String getUuid() { + return uuid; + } + public void setUuid(String uuid) { + this.uuid = uuid; + } + public String getLocation() { + return location; + } + public void setLocation(String location) { + this.location = location; + } + public String getPriority() { + return priority; + } + public void setPriority(String priority) { + this.priority = priority; + } + public String getDirPath() { + return dirPath; + } + public void setDirPath(String dirPath) { + this.dirPath = dirPath; + } + public String getConfigBodyPath() { + return configBodyPath; + } + public void setConfigBodyPath(String configBodyPath) { + this.configBodyPath = configBodyPath; + } + public ArrayList getAttributes() { + return attributes; + } + + @SuppressWarnings("unchecked") + public void setAttributes(Object attributes) { + this.attributes = (ArrayList) attributes; + } + public LinkedHashMap getServiceTypePolicyName() { + return serviceTypePolicyName; + } + public void setServiceTypePolicyName(LinkedHashMap serviceTypePolicyName) { + this.serviceTypePolicyName = (LinkedHashMap) serviceTypePolicyName; + } + public ArrayList getSettings() { + return settings; + } + public void setSettings(ArrayList settings) { + this.settings = settings; + } + public String getRuleName() { + return ruleName; + } + public void setRuleName(String ruleName) { + this.ruleName = ruleName; + } + public LinkedHashMap getRuleData() { + return ruleData; + } + public void setRuleData(LinkedHashMap ruleData) { + this.ruleData = ruleData; + } + public ArrayList getTriggerSignatures() { + return triggerSignatures; + } + public void setTriggerSignatures(ArrayList triggerSignatures) { + this.triggerSignatures = triggerSignatures; + } + public String getLogicalConnector() { + return logicalConnector; + } + public void setLogicalConnector(String logicalConnector) { + this.logicalConnector = logicalConnector; + } + public String getPolicyStatus() { + return policyStatus; + } + public void setPolicyStatus(String policyStatus) { + this.policyStatus = policyStatus; + } + public String getActionAttributeValue() { + return actionAttributeValue; + } + public void setActionAttributeValue(String actionAttributeValue) { + this.actionAttributeValue = actionAttributeValue; + } + public ArrayList getRuleAlgorithmschoices() { + return ruleAlgorithmschoices; + } + public void setRuleAlgorithmschoices(ArrayList ruleAlgorithmschoices) { + this.ruleAlgorithmschoices = ruleAlgorithmschoices; + } + public String getSecurityZone() { + return securityZone; + } + public void setSecurityZone(String securityZone) { + this.securityZone = securityZone; + } + public ArrayList getSymptomSignatures() { + return symptomSignatures; + } + public void setSymptomSignatures(ArrayList symptomSignatures) { + this.symptomSignatures = symptomSignatures; + } + public String getPolicyScope() { + return policyScope; + } + public void setPolicyScope(String policyScope) { + this.policyScope = policyScope; + } + public String getRuleProvider() { + return ruleProvider; + } + public void setRuleProvider(String ruleProvider) { + this.ruleProvider = ruleProvider; + } + public String getRiskLevel() { + return riskLevel; + } + public void setRiskLevel(String riskLevel) { + this.riskLevel = riskLevel; + } + public String getRiskType() { + return riskType; + } + public void setRiskType(String riskType) { + this.riskType = riskType; + } + public String getGuard() { + return guard; + } + public void setGuard(String guard) { + this.guard = guard; + } + public String getTtlDate() { + return ttlDate; + } + public void setTtlDate(String ttlDate) { + this.ttlDate = ttlDate; + } +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/PolicyExportAdapter.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/PolicyExportAdapter.java new file mode 100644 index 000000000..37ed83d16 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/PolicyExportAdapter.java @@ -0,0 +1,36 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.adapter; + + +import java.util.ArrayList; + +public class PolicyExportAdapter { + + private ArrayList policyDatas; + + public ArrayList getPolicyDatas() { + return policyDatas; + } + public void setPolicyDatas(ArrayList policyDatas) { + this.policyDatas = policyDatas; + } +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/PrefixIPList.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/PrefixIPList.java new file mode 100644 index 000000000..e2c70e69f --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/PrefixIPList.java @@ -0,0 +1,74 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.adapter; + + + +import java.util.ArrayList; +import java.util.List; + + +public class PrefixIPList { + protected String name; + protected String description; + protected List members; + /* protected String type; + protected String value;*/ + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public List getMembers() + { + if(members==null) + { + members= new ArrayList(); + } + return this.members; + } + + public void setMembers(List members) + { + this.members = members; + } + /*public String getValue() { + return value; + } + + + public void setValue(String value) { + this.value = value; + }*/ + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/ServiceGroupJson.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/ServiceGroupJson.java new file mode 100644 index 000000000..1cc34fbb4 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/ServiceGroupJson.java @@ -0,0 +1,79 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.adapter; + + +import java.util.ArrayList; +import java.util.List; + +public class ServiceGroupJson { + + protected String name; + protected String description; + protected List members; + + // name + public String getName() { + return name; + } + + public void setName(String value) { + this.name = value; + } + + public boolean equals(Object obj) + { + ServiceGroupJson servGroupobj=(ServiceGroupJson) obj; + if(this.getName().equals(servGroupobj.getName())) + { + return true; + } + return false; + } + + public int hashCode() { + return Integer.valueOf(name.charAt(0)+(name.charAt(1))); + } + + // description + public String getDescription() { + return description; + } + + public void setDescription(String value) { + this.description = value; + } + + public List getMembers() + { + if(members==null) + { + members= new ArrayList(); + } + return this.members; + } + + public void setMembers(List members) + { + this.members = members; + } + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/ServiceListJson.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/ServiceListJson.java new file mode 100644 index 000000000..05df303b9 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/ServiceListJson.java @@ -0,0 +1,107 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.adapter; + + + +public class ServiceListJson { + + protected String name; + protected String description; + protected String type; + protected String transportProtocol; + protected String appProtocol; + protected String ports; + // name + public String getName() { + return name; + } + + public void setName(String value) { + this.name = value; + } + + public boolean equals(Object obj) + { + ServiceListJson servobj=(ServiceListJson) obj; + if(this.getName().equals(servobj.getName())) + { + return true; + } + return false; + } + + public int hashCode() { + if(name!=null){ + return Integer.valueOf(name.charAt(0)+(name.charAt(1))); + }else{ + return 0; + } + } + + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + // type + public String getType() { + return type; + } + + public void setType(String value) { + this.type = value; + } + + // transportProtocol + public String getTransportProtocol() { + return transportProtocol; + } + + public void setTransportProtocol(String value) { + this.transportProtocol = value; + } + + // appProtocol + public String getAppProtocol() { + return appProtocol; + } + + public void setAppProtocol(String value) { + this.appProtocol = value; + } + + // ports + public String getPorts() { + return ports; + } + + public void setPorts(String value) { + this.ports = value; + } + + + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/ServiceMembers.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/ServiceMembers.java new file mode 100644 index 000000000..a8b1abea5 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/ServiceMembers.java @@ -0,0 +1,48 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.adapter; + + + +public class ServiceMembers { + + protected String type; + protected String name; + + // type + public String getType() { + return type; + } + + public void setType(String value) { + this.type = value; + } + + // transportProtocol + public String getName() { + return name; + } + + public void setName(String value) { + this.name = value; + } + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/ServicesJson.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/ServicesJson.java new file mode 100644 index 000000000..bdc9232b5 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/ServicesJson.java @@ -0,0 +1,44 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.adapter; + + +public class ServicesJson { + + protected String type; + protected String name; + // type + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getName() { + return name; + } + + public void setName(String value) { + this.name = value; + } +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/Term.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/Term.java new file mode 100644 index 000000000..3080f2707 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/Term.java @@ -0,0 +1,201 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.adapter; + + + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + + +public class Term { + + String position; + protected String ruleName; + protected List fromZones; + protected List toZones; + protected boolean negateSource; //hardcoded + protected boolean negateDestination; //hardcoded + protected List sourceList; + protected List destinationList; + protected List sourceServices; + protected Set destServices; + protected String action; + protected String description; + boolean enabled; //hardcoded + boolean log; //hardcoded + + //position + public String getPosition() { + return position; + } + + public void setPosition(String value) { + this.position = value; + } + + //RuleName + public String getRuleName() { + return ruleName; + } + + public void setRuleName(String value) { + this.ruleName = value; + } + + //From Zone + public List getFromZones() { + if (fromZones==null) + { + fromZones= new ArrayList(); + } + return fromZones; + } + + public void setFromZones(List fromZones) { + this.fromZones = fromZones; + } + + //To Zone + public List getToZones() { + if (toZones==null) + { + toZones= new ArrayList(); + } + return toZones; + } + + public void setToZones(List toZones) { + this.toZones = toZones; + } + + + //Negate Source + public boolean getNegateSource() { + return negateSource; + } + + public void setNegateSource(boolean negateSource) { + this.negateSource = negateSource; + } + + //Negate Destination + public boolean getNegateDestination() { + return negateDestination; + } + + public void setNegateDestination(boolean negateDestination) { + this.negateDestination = negateDestination; + } + + //SourceList + public List getSourceList() + { + if(sourceList==null) + { + sourceList= new ArrayList(); + } + return this.sourceList; + } + + public void setSourceList(List srcList) { + this.sourceList = srcList; + } + + //Destination List + public List getDestinationList() + { + if(destinationList==null) + { + destinationList= new ArrayList(); + } + return this.destinationList; + } + + public void setDestinationList(List destList) { + this.destinationList = destList; + } + + //Source Services + public List getSourceServices() { + if(sourceServices==null) + { + sourceServices= new ArrayList(); + } + return this.sourceServices; + } + + public void setSourceServices(List sourceServices) { + this.sourceServices = sourceServices; + } + + //Destination services. + public Set getDestServices() { + if(destServices==null) + { + destServices= new HashSet(); + } + return this.destServices; + } + + public void setDestServices(Set destServices) { + this.destServices = destServices; + } + + //Action + public String getAction() { + return action; + } + + public void setAction(String value) { + this.action = value; + } + + //description + public String getDescription() { + return description; + } + + public void setDescription(String desc) { + this.description = desc; + } + + //enabled + public boolean getEnabled() { + return enabled; + } + + public void setEnabled(boolean value) { + this.enabled = value; + } + + //Log + public boolean getLog() { + return log; + } + + public void setLog(boolean value) { + this.log = value; + } + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/TermCollector.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/TermCollector.java new file mode 100644 index 000000000..169ab3637 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/adapter/TermCollector.java @@ -0,0 +1,132 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.adapter; + + + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + + +public class TermCollector { + String serviceTypeId; + String configName; + DeployNowJson deploymentOption; + String securityZoneId; + + protected Set serviceGroups; + protected Set addressGroups; + protected List firewallRuleList; + + private String primaryParentZoneId; + + + //SecurityTypeId + public String getServiceTypeId() { + return serviceTypeId; + } + + public void setServiceTypeId(String serviceTypeId) { + this.serviceTypeId = serviceTypeId; + } + + //ConfigName + public String getConfigName() { + return configName; + } + + public void setConfigName(String configName) { + this.configName = configName; + } + + //DeploymentControl + public DeployNowJson getDeploymentOption() { + return deploymentOption; + } + + public void setDeploymentOption(DeployNowJson deploymentOption) { + this.deploymentOption = deploymentOption; + } + + //SecurityZoneId + public String getSecurityZoneId() { + return securityZoneId; + } + public void setSecurityZoneId(String securityZoneId) { + this.securityZoneId = securityZoneId; + } + + + //ServiceGroup + public Set getServiceGroups() { + if(serviceGroups==null) + { + serviceGroups= new HashSet(); + } + return this.serviceGroups; + } + + public void setServiceGroups(Set servListArray) { + this.serviceGroups = servListArray; + } + + //AddressGroup + public Set getAddressGroups() { + if(addressGroups==null) + { + addressGroups= new HashSet(); + } + return this.addressGroups; + } + + public void setAddressGroups(Set addressGroups) { + this.addressGroups = addressGroups; + } + + //FirewallRuleList + public List getFirewallRuleList() { + + if(firewallRuleList==null) + { + firewallRuleList= new ArrayList(); + } + return this.firewallRuleList; + } + + public void setFirewallRuleList(List firewallRuleList) { + this.firewallRuleList = firewallRuleList; + } + + + //primaryParentZoneId + public String getPrimaryParentZoneId() { + return primaryParentZoneId; + } + + public void setPrimaryParentZoneId(String primaryParentZoneId) { + this.primaryParentZoneId = primaryParentZoneId; + } + + + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/admin/CheckPDP.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/admin/CheckPDP.java new file mode 100644 index 000000000..f1447f135 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/admin/CheckPDP.java @@ -0,0 +1,187 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.admin; + + +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Base64; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Properties; + +import org.openecomp.policy.rest.XACMLRestProperties; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; +import com.att.research.xacml.util.XACMLProperties; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +public class CheckPDP { + private static Path pdpPath = null; + private static Properties pdpProp = null; + private static Long oldModified = null; + private static Long newModified = null; + private static HashMap pdpMap = null; + private static final Logger logger = FlexLogger.getLogger(CheckPDP.class); + + public static boolean validateID(String id) { + // ReadFile + try { + readFile(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e); + return false; + } + // Check ID + if (pdpMap.containsKey(id)) { + return true; + } + return false; + } + + private static void readFile() throws Exception { + String pdpFile = null; + try{ + pdpFile = XACMLProperties.getProperty(XACMLRestProperties.PROP_PDP_IDFILE); + }catch (Exception e){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Cannot read the PDP ID File"); + return; + } + if (pdpFile == null) { + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "PDP File name not Valid : " + pdpFile); + throw new Exception(XACMLErrorConstants.ERROR_SYSTEM_ERROR +"PDP File name not Valid : " + pdpFile); + } + if (pdpPath == null) { + pdpPath = Paths.get(pdpFile); + if (Files.notExists(pdpPath)) { + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "File doesn't exist in the specified Path : " + pdpPath.toString()); + throw new Exception(XACMLErrorConstants.ERROR_SYSTEM_ERROR +"File doesn't exist in the specified Path : "+ pdpPath.toString()); + } + if (pdpPath.toString().endsWith(".properties")) { + readProps(); + } else { + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Not a .properties file " + pdpFile); + throw new Exception(XACMLErrorConstants.ERROR_SYSTEM_ERROR +"Not a .properties file"); + } + } + // Check if File is updated recently + else { + newModified = pdpPath.toFile().lastModified(); + if (newModified != oldModified) { + // File has been updated. + readProps(); + } + } + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + private static void readProps() throws Exception { + InputStream in; + pdpProp = new Properties(); + try { + in = new FileInputStream(pdpPath.toFile()); + oldModified = pdpPath.toFile().lastModified(); + pdpProp.load(in); + } catch (IOException e) { + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e); + throw new Exception("Cannot Load the Properties file", e); + } + // Read the Properties and Load the PDPs and encoding. + pdpMap = new HashMap(); + // Check the Keys for PDP_URLs + Collection unsorted = pdpProp.keySet(); + List sorted = new ArrayList(unsorted); + Collections.sort(sorted); + for (String propKey : sorted) { + if (propKey.startsWith("PDP_URL")) { + String check_val = pdpProp.getProperty(propKey); + if (check_val == null) { + throw new Exception("Properties file doesn't have the PDP_URL parameter"); + } + if (check_val.contains(";")) { + List pdp_default = new ArrayList(Arrays.asList(check_val.split("\\s*;\\s*"))); + int pdpCount = 0; + while (pdpCount < pdp_default.size()) { + String pdpVal = pdp_default.get(pdpCount); + readPDPParam(pdpVal); + pdpCount++; + } + } else { + readPDPParam(check_val); + } + } + } + if (pdpMap == null || pdpMap.isEmpty()) { + logger.debug(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Cannot Proceed without PDP_URLs"); + throw new Exception(XACMLErrorConstants.ERROR_SYSTEM_ERROR +"Cannot Proceed without PDP_URLs"); + } + } + + private static void readPDPParam(String pdpVal) throws Exception{ + if(pdpVal.contains(",")){ + List pdpValues = new ArrayList(Arrays.asList(pdpVal.split("\\s*,\\s*"))); + if(pdpValues.size()==3){ + // 1:2 will be UserID:Password + String userID = pdpValues.get(1); + String pass = pdpValues.get(2); + Base64.Encoder encoder = Base64.getEncoder(); + // 0 - PDPURL + pdpMap.put(pdpValues.get(0), encoder.encodeToString((userID+":"+pass).getBytes(StandardCharsets.UTF_8))); + }else{ + logger.error(XACMLErrorConstants.ERROR_PERMISSIONS + "No Credentials to send Request: " + pdpValues); + throw new Exception(XACMLErrorConstants.ERROR_PERMISSIONS + "No enough Credentials to send Request. " + pdpValues); + } + }else{ + logger.error(XACMLErrorConstants.ERROR_PERMISSIONS + "No Credentials to send Request: " + pdpVal); + throw new Exception(XACMLErrorConstants.ERROR_PERMISSIONS +"No enough Credentials to send Request."); + } + } + + public static String getEncoding(String pdpID){ + try { + readFile(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e); + } + String encoding = null; + if(pdpMap!=null && (!pdpMap.isEmpty())){ + try{ + encoding = pdpMap.get(pdpID); + } catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e); + } + return encoding; + }else{ + return null; + } + } +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/admin/PAPNotificationBroadcaster.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/admin/PAPNotificationBroadcaster.java new file mode 100644 index 000000000..cff0828e2 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/admin/PAPNotificationBroadcaster.java @@ -0,0 +1,120 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.admin; + + +import java.io.Serializable; +import java.util.LinkedList; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +/** + * Handle Notifications from the PAP that the PDP Groups have been changed. + * We need a Server Push Broadcaster because there may be multiple Vaadin instances (i.e. Users) that need to be told when a change occurs. + * + * Initially we only update the entire set of PDPGroups in one shot. + * + * (Code copied from Book of Vaadin chapter on Server Push + * + */ +public class PAPNotificationBroadcaster implements Serializable { + /** + * + */ + private static final long serialVersionUID = -2539940306348821754L; + + + private static Logger logger = FlexLogger.getLogger(PAPNotificationBroadcaster.class); + + + static ExecutorService executorService = Executors.newSingleThreadExecutor(); + + /** + * Interface used by all classes that need to be notified when PAP sends an update message. + * + * + */ + public interface PAPNotificationBroadcastListener { + void updateAllGroups(); + } + + + + /* + * list of registered listeners + */ + private static LinkedList listeners = + new LinkedList(); + + /** + * Listener registers to hear about updates. + * @param listener + */ + public static synchronized void register( + PAPNotificationBroadcastListener listener) { + listeners.add(listener); + } + + + /** + * Listener is going away. + * + * @param listener + */ + public static synchronized void unregister( + PAPNotificationBroadcastListener listener) { + listeners.remove(listener); + } + + + + /** + * Tell all listeners about an update. + * + * @param message + */ + public static synchronized void updateAllGroups() { + for (final PAPNotificationBroadcastListener listener: listeners) { + // Original code copied from example: + // executorService.execute(new Runnable() { + // @Override + // public void run() { + // The problem with this is that the execute starts a new Thread, but the thing we are calling (the listener.updateAllGroups) + // happens in this case to ALSO create a new thread, and it locks up because the shared threadpool queue is already locked by this method. + // On application shutdown that left us with a blocked thread, so the process never goes away. + // Since the listener.updateAllGroups does ALL of its work inside a new Runnable thread, there should be no need for this method to also create a thread. + + /* + * IMPORTANT: + * All listeners MUST either execute with no possibility of blocking + * OR must start their own threads to handle blocking and concurrent operations. + */ + if (logger.isDebugEnabled()) { + logger.debug("updateAllGroups"); + } + listener.updateAllGroups(); + } + } +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/admin/PolicyManagerServlet.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/admin/PolicyManagerServlet.java new file mode 100644 index 000000000..e355b8295 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/admin/PolicyManagerServlet.java @@ -0,0 +1,1334 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/* + * + * + * + * */ +package org.openecomp.policy.admin; + + +import java.io.BufferedOutputStream; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileFilter; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.nio.file.DirectoryStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.attribute.BasicFileAttributes; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.compress.utils.IOUtils; +import org.apache.commons.fileupload.FileItem; +import org.apache.commons.fileupload.disk.DiskFileItemFactory; +import org.apache.commons.fileupload.servlet.ServletFileUpload; +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.FilenameUtils; +import org.apache.commons.io.filefilter.WildcardFileFilter; +import org.apache.http.HttpStatus; +import org.json.JSONException; +import org.json.JSONObject; +import org.openecomp.policy.adapter.PolicyAdapter; +import org.openecomp.policy.components.HumanPolicyComponent; +import org.openecomp.policy.controller.ActionPolicyController; +import org.openecomp.policy.controller.CreateBRMSParamController; +import org.openecomp.policy.controller.CreateBRMSRawController; +import org.openecomp.policy.controller.CreateClosedLoopFaultController; +import org.openecomp.policy.controller.CreateClosedLoopPMController; +import org.openecomp.policy.controller.CreateDcaeMicroServiceController; +import org.openecomp.policy.controller.CreateFirewallController; +import org.openecomp.policy.controller.CreatePolicyController; +import org.openecomp.policy.controller.DecisionPolicyController; +import org.openecomp.policy.controller.PolicyController; +import org.openecomp.policy.controller.PolicyExportAndImportController; +import org.openecomp.policy.elk.client.ElkConnector; +import org.openecomp.policy.model.Roles; +import org.openecomp.policy.rest.jpa.PolicyEditorScopes; +import org.openecomp.policy.rest.jpa.PolicyVersion; +import org.openecomp.policy.rest.jpa.UserInfo; +import org.openecomp.policy.utils.XACMLPolicyWriterWithPapNotify; +import org.openecomp.portalsdk.core.web.support.UserUtils; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; +import org.openecomp.policy.xacml.util.XACMLPolicyScanner; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class PolicyManagerServlet extends HttpServlet { + private static final Logger LOG = FlexLogger.getLogger(PolicyManagerServlet.class); + private static final long serialVersionUID = -8453502699403909016L; + + private enum Mode { + LIST, RENAME, COPY, DELETE, EDITFILE, ADDFOLDER, DESCRIBEPOLICYFILE, VIEWPOLICY, ADDSUBSCOPE, SWITCHVERSION, EXPORT + } + + public static final String REPOSITORY_BASE_PATH = PolicyController.getGitPath().toString(); + private static String DATE_FORMAT = "yyyy-MM-dd hh:mm:ss"; + public static final String CONFIG_HOME = PolicyController.getConfigHome(); + public static final String ACTION_HOME = PolicyController.getActionHome(); + private static String CONTENTTYPE = "application/json"; + private File repofilePath; + private static String SUPERADMIN = "super-admin"; + private static String SUPEREDITOR = "super-editor"; + private static String SUPERGUEST = "super-guest"; + private static String ADMIN = "admin"; + private static String EDITOR = "editor"; + private static String GUEST = "guest"; + private static String RESULT = "result"; + private static String REPOSITORY = "repository"; + + private static String CONFIG = "Config_"; + private static String ACTION = "Action_"; + private static String DECISION = "Decision_"; + + @Override + public void init() throws ServletException { + super.init(); + } + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + String path = request.getParameter("path"); + File file = new File(REPOSITORY_BASE_PATH, path); + + if (!file.isFile()) { + // if not a file, it is a folder, show this error. + response.sendError(HttpServletResponse.SC_NOT_FOUND, "Resource Not Found"); + return; + } + + response.setHeader("Content-Type", getServletContext().getMimeType(file.getName())); + response.setHeader("Content-Length", String.valueOf(file.length())); + response.setHeader("Content-Disposition", "inline; filename=\"" + file.getName() + "\""); + + FileInputStream input = null; + BufferedOutputStream output = null; + try { + input = new FileInputStream(file); + output = new BufferedOutputStream(response.getOutputStream()); + byte[] buffer = new byte[8192]; + for (int length = 0; (length = input.read(buffer)) > 0;) { + output.write(buffer, 0, length); + } + } catch (Exception e) { + LOG.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Exception Occured While Reading Imput Stream" + e); + } finally { + if (output != null) { + try { + output.close(); + } catch (Exception e) { + LOG.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Exception Occured While Closing Output Stream" + e); + } + } + if (input != null) { + try { + input.close(); + } catch (Exception e) { + LOG.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Exception Occured While Closing Input Stream" + e); + } + } + } + + } + + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + LOG.debug("doPost"); + try { + // if request contains multipart-form-data + if (ServletFileUpload.isMultipartContent(request)) { + uploadFile(request, response); + } + // all other post request has json params in body + else { + fileOperation(request, response); + } + } catch (Exception e) { + setError(e, response); + } + } + + //Set Error Message for Exception + private void setError(Exception t, HttpServletResponse response) throws IOException { + try { + JSONObject responseJsonObject = error(t.getMessage()); + response.setContentType(CONTENTTYPE); + PrintWriter out = response.getWriter(); + out.print(responseJsonObject); + out.flush(); + } catch (Exception x) { + response.sendError(HttpStatus.SC_INTERNAL_SERVER_ERROR, x.getMessage()); + } + } + + //Policy Import Functionality + private void uploadFile(HttpServletRequest request, HttpServletResponse response) throws ServletException { + try { + String newFile; + Map files = new HashMap(); + + List items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request); + for (FileItem item : items) { + if (!item.isFormField()) { + // Process form file field (input type="file"). + files.put(item.getName(), item.getInputStream()); + if(item.getName().endsWith(".tar")){ + try{ + File file = new File(item.getName()); + OutputStream outputStream = new FileOutputStream(file); + IOUtils.copy(item.getInputStream(), outputStream); + outputStream.close(); + newFile = file.toString(); + PolicyExportAndImportController importController = new PolicyExportAndImportController(); + importController.ImportRepositoryFile(newFile, request); + }catch(Exception e){ + LOG.error("Upload error : " + e); + } + } + } + } + + JSONObject responseJsonObject = null; + responseJsonObject = this.success(); + response.setContentType("application/json"); + PrintWriter out = response.getWriter(); + out.print(responseJsonObject); + out.flush(); + } catch (Exception e) { + LOG.debug("Cannot write file"); + throw new ServletException("Cannot write file", e); + } + } + + //File Operation Functionality + private void fileOperation(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + JSONObject responseJsonObject = null; + try { + StringBuilder sb = new StringBuilder(); + BufferedReader br = request.getReader(); + String str; + while ((str = br.readLine()) != null) { + sb.append(str); + } + br.close(); + JSONObject jObj = new JSONObject(sb.toString()); + JSONObject params = jObj.getJSONObject("params"); + Mode mode = Mode.valueOf(params.getString("mode")); + switch (mode) { + case ADDFOLDER: + responseJsonObject = addFolder(params, request); + break; + case COPY: + responseJsonObject = copy(params, request); + break; + case DELETE: + responseJsonObject = delete(params, request); + break; + case EDITFILE: + responseJsonObject = editFile(params); + break; + case VIEWPOLICY: + responseJsonObject = editFile(params); + break; + case LIST: + responseJsonObject = list(params, request); + break; + case RENAME: + responseJsonObject = rename(params, request); + break; + case DESCRIBEPOLICYFILE: + responseJsonObject = describePolicy(params); + break; + case ADDSUBSCOPE: + responseJsonObject = addFolder(params, request); + break; + case SWITCHVERSION: + responseJsonObject = switchVersion(params, request); + break; + default: + throw new ServletException("not implemented"); + } + if (responseJsonObject == null) { + responseJsonObject = error("generic error : responseJsonObject is null"); + } + } catch (Exception e) { + LOG.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Exception Occured While doing File Operation" + e); + responseJsonObject = error(e.getMessage()); + } + response.setContentType("application/json"); + PrintWriter out = response.getWriter(); + out.print(responseJsonObject); + out.flush(); + } + + //Switch Version Functionality + private JSONObject switchVersion(JSONObject params, HttpServletRequest request) throws ServletException{ + String path = params.getString("path"); + String userId = null; + try { + userId = UserUtils.getUserIdFromCookie(request); + } catch (Exception e) { + LOG.error("Exception Occured while reading userid from cookie" +e); + } + if(params.toString().contains("activeVersion")){ + String activeVersion = params.getString("activeVersion"); + String highestVersion = params.getString("highestVersion"); + if(Integer.parseInt(activeVersion) > Integer.parseInt(highestVersion)){ + return error("The Version shouldn't be greater than Highest Value"); + }else{ + String removeExtension = path.replace(".xml", ""); + String policyName = removeExtension.substring(0, removeExtension.lastIndexOf(".")); + String activePolicy = policyName + "." + activeVersion + ".xml"; + File file = new File(Paths.get(REPOSITORY_BASE_PATH, activePolicy).toString()); + if(!file.exists()){ + return error("The Policy is Not Existing in Workspace"); + }else{ + if(policyName.contains("/")){ + policyName = policyName.replace("/", File.separator); + } + policyName = policyName.substring(policyName.indexOf(File.separator)+1); + if(policyName.contains("\\")){ + policyName = policyName.replace(File.separator, "\\"); + } + String query = "update PolicyVersion set active_version='"+activeVersion+"' where policy_name ='" +policyName+"' and id >0"; + //query the database + PolicyController.updatePolicyVersion(query); + //Policy Notification + PolicyController controller = new PolicyController(); + PolicyVersion entity = new PolicyVersion(); + entity.setPolicyName(policyName); + entity.setActiveVersion(Integer.parseInt(activeVersion)); + entity.setModifiedBy(userId); + controller.WatchPolicyFunction(entity, policyName, "SwitchVersion"); + } + } + } + File policyFile = new File(REPOSITORY_BASE_PATH, path); + PolicyController policyController = new PolicyController(); + return policyController.SwitchVersionPolicyContent(policyFile); + } + + //Describe Policy + private JSONObject describePolicy(JSONObject params){ + String path = params.getString("path"); + File policyFile = new File(REPOSITORY_BASE_PATH, path); + + return HumanPolicyComponent.DescribePolicy(policyFile); + } + + //Get the List of Policies and Scopes for Showing in Editor tab + private JSONObject list(JSONObject params, HttpServletRequest request) throws ServletException { + Set scopes = null; + List roles = null; + try { + //Get the Login Id of the User from Request + String userId = UserUtils.getUserIdFromCookie(request); + //Check if the Role and Scope Size are Null get the values from db. + List userRoles = PolicyController.getRoles(userId); + roles = new ArrayList(); + scopes = new HashSet(); + for(Roles userRole: userRoles){ + roles.add(userRole.getRole()); + if(userRole.getScope() != null){ + if(userRole.getScope().contains(",")){ + String[] multipleScopes = userRole.getScope().split(","); + for(int i =0; i < multipleScopes.length; i++){ + scopes.add(multipleScopes[i]); + } + }else{ + scopes.add(userRole.getScope()); + } + } + } + if (roles.contains(ADMIN) || roles.contains(EDITOR) || roles.contains(GUEST) ) { + if(scopes.isEmpty()){ + return error("No Scopes has been Assigned to the User. Please, Contact Super-Admin"); + } + } + + List resultList = new ArrayList(); + SimpleDateFormat dt = new SimpleDateFormat(DATE_FORMAT); + boolean onlyFolders = params.getBoolean("onlyFolders"); + String path = params.getString("path"); + if(path.contains("..xml")){ + path = path.replaceAll("..xml", "").trim(); + } + + + if("/".equals(path)){ + if(roles.contains(SUPERADMIN) || roles.contains(SUPEREDITOR) || roles.contains(SUPERGUEST)){ + try (DirectoryStream directoryStream = Files.newDirectoryStream(Paths.get(REPOSITORY_BASE_PATH, path))) { + for (Path pathObj : directoryStream) { + BasicFileAttributes attrs = Files.readAttributes(pathObj, BasicFileAttributes.class); + if (onlyFolders && !attrs.isDirectory()) { + continue; + } + JSONObject el = new JSONObject(); + String fileName = pathObj.getFileName().toString(); + if (!(fileName.equals(".DS_Store") || fileName.contains(".git"))) { + if(!fileName.endsWith(".xml")){ + el.put("name", fileName); + el.put("date", dt.format(new Date(attrs.lastModifiedTime().toMillis()))); + el.put("size", attrs.size()); + el.put("type", attrs.isDirectory() ? "dir" : "file"); + resultList.add(el); + } + } + } + } catch (IOException ex) { + LOG.error("Error Occured While reading Policy Files List"+ex ); + } + }else if(roles.contains(ADMIN) || roles.contains(EDITOR) || roles.contains(GUEST)){ + for(Object scope : scopes){ + JSONObject el = new JSONObject(); + Path filePath = Paths.get(REPOSITORY_BASE_PATH + File.separator + scope); + if(Files.exists(filePath)){ + el.put("name", scope); + el.put("date", dt.format(filePath.toFile().lastModified())); + el.put("size", ""); + el.put("type", "dir"); + resultList.add(el); + } + } + } + }else{ + try{ + String scopeName = path.substring(path.indexOf("/") +1); + activePolicyList(scopeName, resultList, roles, scopes, onlyFolders); + } catch (Exception ex) { + LOG.error("Error Occured While reading Policy Files List"+ex ); + } + } + + return new JSONObject().put(RESULT, resultList); + } catch (Exception e) { + LOG.error("list", e); + return error(e.getMessage()); + } + } + + //Get Active Policy List based on Scope Selection form Policy Version table + private void activePolicyList(String scopeName, List resultList, List roles, Set scopes, boolean onlyFolders){ + if(scopeName.contains("/")){ + scopeName = scopeName.replace("/", File.separator); + } + if(scopeName.contains("\\")){ + scopeName = scopeName.replace("\\", "\\\\\\\\"); + } + String query = "from PolicyVersion where POLICY_NAME like'" +scopeName+"%'"; + String scopeNamequery = "from PolicyEditorScopes where SCOPENAME like'" +scopeName+"%'"; + List activePolicies = PolicyController.getListOfActivePolicies(query); + List scopesList = PolicyController.getListOfPolicyEditorScopes(scopeNamequery); + for(PolicyEditorScopes scopeById : scopesList){ + String scope = scopeById.getScopeName(); + if(scope.contains(File.separator)){ + String checkScope = scope.substring(0, scope.lastIndexOf(File.separator)); + if(scopeName.contains("\\\\")){ + scopeName = scopeName.replace("\\\\", File.separator); + } + if(scopeName.equalsIgnoreCase(checkScope)){ + JSONObject el = new JSONObject(); + Path filePath = Paths.get(REPOSITORY_BASE_PATH + File.separator + scope); + if(Files.exists(filePath)){ + el.put("name", filePath.getFileName()); + el.put("date", scopeById.getModifiedDate()); + el.put("size", ""); + el.put("type", "dir"); + el.put("createdBy", scopeById.getUserCreatedBy().getUserName()); + el.put("modifiedBy", scopeById.getUserModifiedBy().getUserName()); + resultList.add(el); + } + } + } + } + for (PolicyVersion policy : activePolicies) { + String scopeNameValue = policy.getPolicyName().substring(0, policy.getPolicyName().lastIndexOf(File.separator)); + String activepath = REPOSITORY_BASE_PATH + File.separator + policy.getPolicyName() + "." + policy.getActiveVersion() + ".xml"; + Path pathObj = Paths.get(activepath); + if(Files.exists(pathObj)){ + BasicFileAttributes attrs; + try { + attrs = Files.readAttributes(pathObj, BasicFileAttributes.class); + if (onlyFolders && !attrs.isDirectory()) { + continue; + } + if(roles.contains(SUPERADMIN) || roles.contains(SUPEREDITOR) || roles.contains(SUPERGUEST)){ + readPolicies(pathObj, attrs, scopeName, resultList); + }else if(!scopes.isEmpty()){ + for(String value : scopes){ + if(scopeNameValue.startsWith(value)){ + readPolicies(pathObj, attrs, scopeName, resultList); + } + } + } + } catch (Exception e) { + LOG.error(XACMLErrorConstants.ERROR_PROCESS_FLOW+"Exception occured while reading File Attributes"+e); + } + } + } + } + + //Read the Policy File to get Created by and Modified by User Name of Policy + public void readPolicies(Path pathObj, BasicFileAttributes attrs, String scopeName, List resultList){ + JSONObject el = new JSONObject(); + String policyName = ""; + String version = ""; + String scope = ""; + if(scopeName.contains("\\\\")){ + scopeName = scopeName.replace("\\\\", File.separator); + } + SimpleDateFormat dt = new SimpleDateFormat(DATE_FORMAT); + String fileName = pathObj.getFileName().toString(); + if (!(fileName.equals(".DS_Store") || fileName.startsWith(".git"))) { + if(fileName.endsWith(".xml")){ + fileName = fileName.substring(0, fileName.lastIndexOf('.')); + fileName = fileName.substring(0, fileName.lastIndexOf('.')); + //Query the database + String parent = pathObj.toString().substring(pathObj.toString().indexOf(REPOSITORY)+ 11); + parent = FilenameUtils.removeExtension(parent); + version = parent.substring(parent.indexOf(".")+1); + policyName = parent.substring(0, parent.lastIndexOf(".")); + scope = policyName.substring(0, policyName.lastIndexOf(File.separator)); + if(policyName.contains("\\")){ + policyName = scope + "\\" + policyName.substring(policyName.lastIndexOf("\\")); + } + } + if(scopeName.equalsIgnoreCase(scope)){ + el.put("name", fileName); + if(pathObj.toFile().toString().endsWith(".xml")){ + el.put("version", version); + List createdByModifiedBy; + try { + createdByModifiedBy = XACMLPolicyScanner.getCreatedByModifiedBy(pathObj); + } catch (IOException e) { + LOG.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error while Reading the Policy File" + pathObj.toString() + e.getMessage()); + createdByModifiedBy = Arrays.asList("", ""); + } + el.put("createdBy", getUserName(createdByModifiedBy.get(0))); + el.put("modifiedBy", getUserName(createdByModifiedBy.get(1))); + } + el.put("date", dt.format(new Date(attrs.lastModifiedTime().toMillis()))); + el.put("size", attrs.size()); + el.put("type", attrs.isDirectory() ? "dir" : "file"); + } + } + + if(!el.keySet().isEmpty()){ + resultList.add(el); + } + + } + + //Get the User Name based on ID from User Info table + public String getUserName(String userId) { + String userName = "super-admin"; + if("".equals(userId)){ + return userName; + } + try{ + return PolicyController.getUserName(userId); + }catch(Exception e){ + LOG.error(XACMLErrorConstants.ERROR_DATA_ISSUE+"Error Occured while Retriving User Name from User Info table"+e); + return userName; + } + } + + //Rename Policy + private JSONObject rename(JSONObject params, HttpServletRequest request) throws ServletException { + try { + String userId = null; + try { + userId = UserUtils.getUserIdFromCookie(request); + } catch (Exception e) { + LOG.error("Exception Occured while reading userid from cookie" +e); + } + String path = params.getString("path"); + String newpath = params.getString("newPath"); + LOG.debug("rename from: {} to: {}" +path + newpath); + + File srcFile = new File(REPOSITORY_BASE_PATH, path); + File destFile = new File(REPOSITORY_BASE_PATH, newpath); + if (srcFile.isFile()) { + renameXMLandConfig(destFile.getPath().toString(), srcFile.getPath().toString(), userId); + } else { + FileUtils.moveDirectory(srcFile, destFile); + String oldScopeName = path.substring(1).replace("/", File.separator); + String newScopeName = newpath.substring(1).replace("/", File.separator); + String scopeNamequery = "from PolicyEditorScopes where SCOPENAME like'" +oldScopeName.replace("\\", "\\\\\\\\")+"%'"; + UserInfo userInfo = new UserInfo(); + userInfo.setUserLoginId(userId); + List scopesList = PolicyController.getListOfPolicyEditorScopes(scopeNamequery); + for(PolicyEditorScopes scopes : scopesList){ + String scope = scopes.getScopeName(); + String newScope = scope.replace(oldScopeName, newScopeName); + scopes.setScopeName(newScope); + scopes.setUserModifiedBy(userInfo); + PolicyController.updatePolicyScopeEditor(scopes); + } + File[] list = destFile.listFiles(); + if(list.length > 0){ + renameXMLandConfig(destFile.getPath().toString(), srcFile.getPath().toString(), userId); + } + } + return success(); + } catch (Exception e) { + LOG.error(XACMLErrorConstants.ERROR_DATA_ISSUE+"Exception Occured While Renaming Policy"+e); + return error(e.getMessage()); + } + } + + //rename the xml and config files when renaming scope + public void renameXMLandConfig(String newPath, String oldPath, String loginId){ + if(!newPath.endsWith(".xml")){ + File dir = new File(newPath); + File[] listOfFiles = dir.listFiles(); + for(File file : listOfFiles){ + if(file.toString().endsWith(".xml")){ + renameFile(file, oldPath, newPath ); + }else if(file.isDirectory()){ + String oldFilePath = oldPath + File.separator +file.getName(); + renameXMLandConfig(file.toString(), oldFilePath, loginId); + } + } + }else{ + Path parent = Paths.get(oldPath.toString().substring(0, oldPath.toString().lastIndexOf(File.separator))); + String policyName = oldPath.toString().substring(oldPath.toString().indexOf(REPOSITORY) +11); + String removeExtension = policyName.replace(".xml", ""); + String dbPolicyName = removeExtension.substring(0, removeExtension.lastIndexOf(".")); + //Policy Notifcation + PolicyController controller = new PolicyController(); + PolicyVersion entity = new PolicyVersion(); + entity.setPolicyName(dbPolicyName); + entity.setModifiedBy(loginId); + controller.WatchPolicyFunction(entity, dbPolicyName, "Rename"); + String filterPolicyName = dbPolicyName.substring(dbPolicyName.lastIndexOf(File.separator)+1); + FileFilter fileFilter = new WildcardFileFilter(filterPolicyName + "." + "*" + ".xml"); + File[] files = parent.toFile().listFiles(fileFilter); + for(File file : files){ + String removeNewPathExtension = newPath.replace(".xml", ""); + String removeNewFileVersion = removeNewPathExtension.substring(0, removeNewPathExtension.lastIndexOf(".")); + String oldFile = file.getPath(); + oldFile = oldFile.replace(".xml", ""); + String version = oldFile.substring(oldFile.lastIndexOf(".")+1); + String finalPath = removeNewFileVersion + "." + version + ".xml"; + File destFile = new File(finalPath); + try { + FileUtils.moveFile(file, destFile); + renameFile(file, oldFile, finalPath); + } catch (IOException e) { + LOG.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Exception Occured While Renaming or Moving Policy"+e); + } + + } + } + } + + //Rename File + private void renameFile(File file, String oldPath, String newPath){ + if(file.toString().contains(CONFIG) || file.toString().contains(ACTION) || file.toString().contains(DECISION)){ + File xmlFileName = new File(newPath); + String oldfileWithExtension = null; + String filelocation = null; + String oldfile = null; + String newfile = null; + String extension = null; + if(newPath.endsWith(".xml")){ + extension = XACMLPolicyWriterWithPapNotify.changeFileNameInXmlWhenRenamePolicy(xmlFileName.toPath()); + }else{ + extension = XACMLPolicyWriterWithPapNotify.changeFileNameInXmlWhenRenamePolicy(file.toPath()); + String fileName = file.getName(); + oldPath = oldPath + File.separator + fileName; + newPath = newPath + File.separator + fileName; + } + + try{ + if(file.toString().contains(CONFIG)){ + filelocation = PolicyController.getConfigHome(); + } + if(file.toString().contains(ACTION)){ + filelocation = PolicyController.getActionHome(); + } + File oldFilePath = new File(oldPath); + String oldFileName = oldFilePath.getName().replace(".xml", ""); + File newFilePath = new File(newPath); + String newFileName = newFilePath.getName().replace(".xml", ""); + File target = new File(oldPath); + File newParentScope = new File(newPath); + if(newParentScope.toString().endsWith(".xml")){ + String newScope = newParentScope.toString().substring(0, newParentScope.toString().lastIndexOf(File.separator)); + newParentScope = new File(newScope); + } + String oldParentScope = target.toString().substring(0, target.toString().lastIndexOf(File.separator)); + String oldDomain = oldParentScope.toString().substring(oldParentScope.toString().indexOf(REPOSITORY) + 11); + if(oldDomain.endsWith(".xml")){ + oldDomain = oldDomain.substring(0, oldDomain.lastIndexOf(File.separator)); + } + oldfile = oldDomain + File.separator + oldFileName.substring(0, oldFileName.indexOf(".")); + if(oldDomain.contains(File.separator)){ + oldDomain = oldDomain.replace(File.separator, "."); + } + String newDomain = newParentScope.toString().substring(newParentScope.toString().indexOf(REPOSITORY) + 11); + newfile = newDomain + File.separator +newFileName.substring(0, newFileName.indexOf(".")); + if(newDomain.contains(File.separator)){ + newDomain = newDomain.replace(File.separator, "."); + } + if(file.toString().contains(CONFIG) || file.toString().contains(ACTION)){ + oldfileWithExtension = oldDomain + "." + oldFileName + "."+ extension; + String newfilewithExtension = newDomain + "." + newFileName + "." + extension; + File file1 = new File(filelocation, oldfileWithExtension); + file1.renameTo(new File(filelocation , newfilewithExtension)); + } + String query = "update PolicyVersion set policy_name='"+newfile.replace("\\", "\\\\")+"' where policy_name ='" +oldfile.replace("\\", "\\\\")+"' and id >0"; + //query the database + PolicyController.updatePolicyVersion(query); + }catch(Exception e){ + LOG.error(XACMLErrorConstants.ERROR_DATA_ISSUE +"Config file cannot found:" + oldfileWithExtension + e); + } + } + } + + //Clone the Policy + private JSONObject copy(JSONObject params, HttpServletRequest request) throws ServletException { + try { + String path = params.getString("path"); + String newpath = params.getString("newPath"); + LOG.debug("copy from: {} to: {}" + path +newpath); + File srcFile = new File(REPOSITORY_BASE_PATH, path); + File destFile = new File(REPOSITORY_BASE_PATH, newpath); + if (srcFile.isFile()) { + FileUtils.copyFile(srcFile, destFile); + cloneXMLandConfig(destFile, srcFile, request); + } else { + FileUtils.copyDirectory(srcFile, destFile); + } + return success(); + } catch (Exception e) { + LOG.error("copy", e); + return error(e.getMessage()); + } + } + + public void cloneXMLandConfig(File newPath, File oldPath, HttpServletRequest request){ + String userId = null; + try { + userId = UserUtils.getUserIdFromCookie(request); + } catch (Exception e) { + LOG.error("Exception Occured while reading userid from cookie" +e); + } + String newPolicyName = newPath.getPath().toString().substring(newPath.getPath().toString().indexOf(REPOSITORY) + 11); + newPolicyName = newPolicyName.replace(".xml", ""); + String version = newPolicyName.substring(newPolicyName.lastIndexOf(".") +1); + String policyName = newPolicyName.substring(0, newPolicyName.indexOf(".")); + newPolicyName = newPolicyName.replace(File.separator, "."); + //if the user leaves the name of the policy blank + if (newPolicyName == null) { + return; + }else{ + Path newPolicyPath = newPath.toPath(); + File dir = null; + File[] listOfFiles = null; + if(newPolicyName.contains(CONFIG)){ + LOG.debug("CONFIG_HOME: "+CONFIG_HOME); + dir=new File(CONFIG_HOME); + listOfFiles = dir.listFiles(); + }else if(newPolicyName.contains(ACTION)){ + LOG.debug("ACTION_HOME: "+ACTION_HOME); + dir=new File(ACTION_HOME); + listOfFiles = dir.listFiles(); + } + String indexValue = ""; + String orignalPolicyName = oldPath.getPath().toString().substring(oldPath.getPath().toString().indexOf(REPOSITORY) + 11); + orignalPolicyName = orignalPolicyName.replace(".xml", ""); + orignalPolicyName = orignalPolicyName.replace(File.separator, "."); + if(orignalPolicyName.contains("Config_Fault_")){ + indexValue = "Config_Fault_"; + } else if(orignalPolicyName.contains("Config_PM_")){ + indexValue = "Config_PM_"; + }else if(orignalPolicyName.contains("Config_FW")){ + indexValue = "Config_FW_"; + }else if(orignalPolicyName.contains("Config_BRMS_Param")){ + indexValue = "Config_BRMS_Param_"; + }else if(orignalPolicyName.contains("Config_BRMS_Raw")){ + indexValue = "Config_BRMS_Raw_"; + } else if(orignalPolicyName.contains("Config_MS")){ + indexValue = "Config_MS_"; + }else if(orignalPolicyName.contains(ACTION)){ + indexValue = ACTION; + }else if(orignalPolicyName.contains(DECISION)){ + indexValue = DECISION; + }else{ + indexValue = CONFIG; + } + File newConfigFile = null; + + //making changes to the xml file + if(indexValue.contains(CONFIG) || indexValue.contains(ACTION)){ + for (File file : listOfFiles) { + if (file.isFile()){ + String fileName=file.getName(); + if(fileName.contains(orignalPolicyName)){ + String newConfigFileName=fileName.replaceAll(orignalPolicyName,newPolicyName); + if(dir.toString().contains(File.separator)){ + newConfigFile=new File(dir.toString()+ File.separator +newConfigFileName); + } + try { + Files.copy(file.toPath(), newConfigFile.toPath()); + } catch (Exception e) { + LOG.error(XACMLErrorConstants.ERROR_DATA_ISSUE +"Error while Cloning the config file" + e); + return; + } + } + } + } + XACMLPolicyWriterWithPapNotify.changeFileNameInXmlWhenRenamePolicy(newPolicyPath); + } + //set the clone policy name into policy version database table + PolicyVersion entityItem = new PolicyVersion(); + entityItem.setActiveVersion(Integer.parseInt(version)); + entityItem.setHigherVersion(Integer.parseInt(version)); + entityItem.setPolicyName(policyName); + entityItem.setCreatedBy(userId); + entityItem.setModifiedBy(userId); + PolicyController.SaveToPolicyVersion(entityItem); + + + new Thread(new Runnable() { + @Override + public void run() { + try { + ElkConnector.singleton.update(newPolicyPath.toFile()); + if (LOG.isInfoEnabled()) { + LOG.info("ELK cloning to " + newPolicyPath); + } + } catch (Exception e) { + LOG.warn(XACMLErrorConstants.ERROR_DATA_ISSUE + ": Internal Error: Unsucessful clone: " + e.getMessage(), e); + } + } + }).start(); + + //send to pap + XACMLPolicyWriterWithPapNotify.notifyPapOfCreateUpdate(newPolicyPath.toAbsolutePath().toString()); + LOG.info("Cloned policy "+newPolicyName+" created successfully."); + return; + } + } + + //Delete Policy or Scope Functionality + private JSONObject delete(JSONObject params, HttpServletRequest request) throws ServletException { + try { + String userId = UserUtils.getUserIdFromCookie(request); + String deleteVersion = ""; + String path1 = params.getString("path"); + LOG.debug("delete {}" +path1); + if(params.has("deleteVersion")){ + deleteVersion = params.getString("deleteVersion"); + } + + this.repofilePath = new File(REPOSITORY_BASE_PATH, path1); + File policyFile = new File(REPOSITORY_BASE_PATH, path1); + if("ALL".equals(deleteVersion)){ + String removexmlExtension = policyFile.toString().substring(0, policyFile.toString().lastIndexOf(".")); + String removeVersion = removexmlExtension.substring(0, removexmlExtension.lastIndexOf(".")); + String notificationName = removeVersion.substring(removeVersion.lastIndexOf(REPOSITORY)+11); + //Policy Notifcation + PolicyController controller = new PolicyController(); + PolicyVersion entity = new PolicyVersion(); + entity.setPolicyName(notificationName); + entity.setModifiedBy(userId); + controller.WatchPolicyFunction(entity, notificationName, "DeleteAll"); + File dirXML = new File(policyFile.getParent()); + File[] listOfXMLFiles = dirXML.listFiles(); + for (File file : listOfXMLFiles) { + //delete the xml files from Repository + if (file.isFile() && file.toString().contains(removeVersion)) { + if(XACMLPolicyWriterWithPapNotify.notifyPapOfDelete(file.toString())){ + LOG.info("Policy deleted from database. Continuing with file delete"); + } else { + LOG.error("Failed to delete Policy from database. Aborting file delete"); + } + //Elk Update + updateElkOnPolicyDelete(file); + + if (file.delete()) { + if (LOG.isDebugEnabled()) { + LOG.debug("Deleted file: " + file.toString()); + } + } else { + LOG.warn(XACMLErrorConstants.ERROR_DATA_ISSUE + "Cannot delete the policy file in specified location: " + file.getAbsolutePath()); + } + + // Get tomcat home directory for deleting config data + String path = getParentPathSubScopeDir(); + path = path.replace('\\', '.'); + if(path.contains("/")){ + path = path.replace('/', '.'); + } + String fileName = FilenameUtils.removeExtension(file.getName()); + String removeVersionInFileName = fileName.substring(0, fileName.lastIndexOf(".")); + String fileLocation = null; + if (fileName != null && fileName.contains(CONFIG)) { + fileLocation = CONFIG_HOME; + } else if (fileName != null && fileName.contains(ACTION)) { + fileLocation = ACTION_HOME; + } + if (LOG.isDebugEnabled()) { + LOG.debug("Attempting to rename file from the location: "+ fileLocation); + } + if(!file.toString().contains(DECISION)){ + // Get the file from the saved location + File dir = new File(fileLocation); + File[] listOfFiles = dir.listFiles(); + + for (File file1 : listOfFiles) { + if (file1.isFile() && file1.getName().contains( path + removeVersionInFileName)) { + try { + if (file1.delete() == false) { + throw new Exception("No known error, Delete failed"); + } + } catch (Exception e) { + LOG.error("Failed to Delete file: "+ e.getLocalizedMessage()); + } + } + } + } + + //Delete the Policy from Database Policy Version table + String removeExtension = removeVersion.substring(removeVersion.indexOf(REPOSITORY)+11); + String policyVersionQuery = "delete from PolicyVersion where policy_name ='" +removeExtension.replace("\\", "\\\\")+"' and id >0"; + if(policyVersionQuery != null){ + PolicyController.updatePolicyVersion(policyVersionQuery); + } + } + } + //If Only Particular version to be deleted + }else if("CURRENT".equals(deleteVersion)){ + String removexmlExtension = policyFile.toString().substring(0, policyFile.toString().lastIndexOf(".")); + String getVersion = removexmlExtension.substring(removexmlExtension.indexOf(".")+1); + String removeVersion = removexmlExtension.substring(0, removexmlExtension.lastIndexOf(".")); + String notificationName = removeVersion.substring(removeVersion.lastIndexOf(REPOSITORY)+11); + //Policy Notifcation + PolicyController controller = new PolicyController(); + PolicyVersion entity = new PolicyVersion(); + entity.setPolicyName(notificationName); + entity.setActiveVersion(Integer.parseInt(getVersion)); + entity.setModifiedBy(userId); + controller.WatchPolicyFunction(entity, notificationName, "DeleteOne"); + if(XACMLPolicyWriterWithPapNotify.notifyPapOfDelete(policyFile.toString())){ + LOG.info("Policy deleted from database. Continuing with file delete"); + } else { + LOG.error("Failed to delete Policy from database. Aborting file delete"); + } + //Elk Update + updateElkOnPolicyDelete(policyFile); + + if (policyFile.delete()) { + LOG.debug("Deleted file: " + policyFile.toString()); + } else { + LOG.warn(XACMLErrorConstants.ERROR_DATA_ISSUE + "Cannot delete the policy file in specified location: " +policyFile.getAbsolutePath()); + } + + // Get tomcat home directory for storing action body config data + String path = getParentPathSubScopeDir(); + path = path.replace('\\', '.'); + if(path.contains("/")){ + path = path.replace('/', '.'); + LOG.info("print the path:" +path); + } + final String tempPath = path; + String fileName = FilenameUtils.removeExtension(policyFile.getName()); + String fileLocation = null; + if (fileName != null && fileName.contains(CONFIG)) { + fileLocation = CONFIG_HOME; + } else if (fileName != null && fileName.contains(ACTION)) { + fileLocation = ACTION_HOME; + } + if (LOG.isDebugEnabled()) { + LOG.debug("Attempting to delete file from the location: "+ fileLocation); + } + if(!policyFile.toString().contains(DECISION)){ + // Get the file from the saved location + File dir = new File(fileLocation); + File[] listOfFiles = dir.listFiles(); + + for (File file : listOfFiles) { + if (file.isFile() && file.toString().contains( tempPath + fileName)) { + try { + if (file.delete() == false) { + throw new Exception("No known error, Delete failed"); + } + } catch (Exception e) { + LOG.error("Failed to Delete file: "+ e.getLocalizedMessage()); + } + } + } + } + //Delete the Policy from Database and set Active Version based on the deleted file. + int highestVersion = 0; + String removeExtension = removeVersion.substring(removeVersion.indexOf(REPOSITORY)+11); + PolicyVersion policyVersionEntity = PolicyController.getPolicyEntityFromPolicyVersion(removeExtension); + if(policyVersionEntity != null){ + highestVersion = policyVersionEntity.getHigherVersion(); + } + int i =0; + int version = Integer.parseInt(getVersion); + if(version == highestVersion){ + for(i = highestVersion; i >= 1 ; i--){ + highestVersion = highestVersion-1; + path = removeVersion + "."+ highestVersion +".xml"; + File file = new File(path); + if(file.exists()){ + break; + } + } + } + String updatequery = "update PolicyVersion set active_version='"+highestVersion+"' , highest_version='"+highestVersion+"' where policy_name ='" +removeExtension.replace("\\", "\\\\")+"'"; + PolicyController.updatePolicyVersion(updatequery); + }else{ + String scopeName = policyFile.getAbsolutePath().substring(policyFile.getAbsolutePath().indexOf(REPOSITORY)+11); + String policyVersionQuery = "delete PolicyVersion where POLICY_NAME like '"+scopeName.replace("\\", "\\\\")+"%' and id >0"; + String policyScopeQuery = "delete PolicyEditorScopes where SCOPENAME like '"+scopeName.replace("\\", "\\\\")+"%' and id >0"; + PolicyController.updatePolicyVersion(policyVersionQuery); + PolicyController.updatePolicyScopeEditorWithQuery(policyScopeQuery); + delete(policyFile); + //Policy Notifcation + PolicyController controller = new PolicyController(); + PolicyVersion entity = new PolicyVersion(); + entity.setPolicyName(scopeName); + entity.setModifiedBy(userId); + controller.WatchPolicyFunction(entity, scopeName, "DeleteScope"); + } + return success(); + } catch (Exception e) { + LOG.error("delete", e); + return error(e.getMessage()); + } + } + + //Notify ELK on File Delete + private void updateElkOnPolicyDelete(File file){ + try { + ElkConnector.singleton.delete(file); + } catch (Exception e) { + LOG.warn(XACMLErrorConstants.ERROR_DATA_ISSUE + ": Cannot delete: " + file.getName() + + " at " + file.getAbsolutePath() + ": " + e.getMessage(), e); + } + } + //Deletes Files when Scope is Selected to delete + public void delete(File file) throws IOException{ + if(file.isDirectory()){ + //directory is empty, then delete it + if(file.list().length==0){ + file.delete(); + }else{ + //list all the directory contents + String[] files = file.list(); + for (String temp : files) { + //construct the file structure + File fileDelete = new File(file, temp); + //delete from Elk first + if(fileDelete.getAbsolutePath().toString().endsWith(".xml")){ + try { + String deleteFile= fileDelete.getAbsoluteFile().toString().substring(fileDelete.getAbsoluteFile().toString().indexOf("workspace")); + File deletePath= new File(deleteFile); + LOG.debug("Search:"+deletePath); + ElkConnector.singleton.delete(deletePath); + } catch (Exception e) { + LOG.warn(XACMLErrorConstants.ERROR_DATA_ISSUE + ": Cannot delete: " + fileDelete.getAbsoluteFile().getName() + + " at " + fileDelete.getAbsoluteFile().getAbsolutePath() + ": " +e.getMessage(), e); + } + } + + //recursive delete + delete(fileDelete); + + //Delete the Configuration files from Config and Action Home Location + String fileLocation = null; + String policyName = fileDelete.toString().substring(fileDelete.toString().indexOf(REPOSITORY)+11, fileDelete.toString().lastIndexOf(".")); + if(policyName.contains(CONFIG)){ + fileLocation = PolicyController.getConfigHome(); + } + if(policyName.contains(ACTION)){ + fileLocation = PolicyController.getActionHome(); + } + if(policyName.contains(File.separator)){ + policyName = policyName.replace(File.separator, "."); + } + if(!fileDelete.toString().contains(DECISION) && fileLocation != null){ + // Get the file from the saved location and delete + File dir = new File(fileLocation); + FileFilter fileFilter = new WildcardFileFilter(policyName + ".*"); + File[] configFiles = (dir).listFiles(fileFilter); + if(configFiles.length > 0){ + configFiles[0].delete(); + } + } + //Notify the PAP and Elk database for deleting the Policies Under Scopes + if(fileDelete.getAbsolutePath().toString().endsWith(".xml")){ + if(!XACMLPolicyWriterWithPapNotify.notifyPapOfDelete(fileDelete.getAbsolutePath().toString())){ + LOG.error(XACMLErrorConstants.ERROR_PROCESS_FLOW+"Could not delete the policy from the database: "+ + fileDelete.getAbsolutePath().toString()); + throw new IOException("Could not delete the policy from the database: "+ + fileDelete.getAbsolutePath().toString()); + } + } + } + //check the directory again, if empty then delete it + if(file.list().length==0){ + file.delete(); + } + } + }else{ + //if file, then delete it + file.delete(); + } + } + + //Get the Parent Scope of File + protected String getParentPathSubScopeDir() { + String domain1 = null; + final Path gitPath = PolicyController.getGitPath(); + String policyDir = this.repofilePath.getAbsolutePath(); + int startIndex = policyDir.indexOf(gitPath.toString()) + gitPath.toString().length() + 1; + policyDir = policyDir.substring(startIndex, policyDir.length()); + if(policyDir.contains(CONFIG)){ + domain1 = policyDir.substring(0,policyDir.indexOf(CONFIG)); + }else if(policyDir.contains(ACTION)){ + domain1 = policyDir.substring(0,policyDir.indexOf(ACTION)); + }else{ + domain1 = policyDir.substring(0,policyDir.indexOf(DECISION)); + } + LOG.info("print the main domain value"+policyDir); + return domain1; + } + + //Edit the Policy + private JSONObject editFile(JSONObject params) throws ServletException { + // get content + try { + String mode = params.getString("mode"); + String path = params.getString("path"); + LOG.debug("editFile path: {}"+ path); + + File policyFile = new File(REPOSITORY_BASE_PATH, path); + + Object policy = XACMLPolicyScanner.readPolicy(new FileInputStream(policyFile)); + Path fullPath = Paths.get(policyFile.getAbsolutePath(), new String[0]); + PolicyAdapter policyAdapter = new PolicyAdapter(); + policyAdapter.setData(policy); + String dirPath = fullPath.getParent().toString().substring(fullPath.getParent().toString().lastIndexOf(REPOSITORY)+11); + policyAdapter.setDirPath(dirPath); + policyAdapter.setParentPath(fullPath.getParent()); + + if("viewPolicy".equalsIgnoreCase(mode)){ + policyAdapter.setReadOnly(true); + policyAdapter.setEditPolicy(false); + }else{ + policyAdapter.setReadOnly(false); + policyAdapter.setEditPolicy(true); + } + + policyAdapter.setPolicyData(policy); + policyAdapter.setPolicyName(FilenameUtils.removeExtension(policyFile.getName())); + + String policyNameValue = null ; + String configPolicyName = null ; + if(policyAdapter.getPolicyName().startsWith("Config_PM")){ + policyNameValue = policyAdapter.getPolicyName().substring(0, policyAdapter.getPolicyName().indexOf("_")); + configPolicyName = "ClosedLoop_PM"; + }else if(policyAdapter.getPolicyName().startsWith("Config_Fault")){ + policyNameValue = policyAdapter.getPolicyName().substring(0, policyAdapter.getPolicyName().indexOf("_")); + configPolicyName = "ClosedLoop_Fault"; + }else if(policyAdapter.getPolicyName().startsWith("Config_FW")){ + policyNameValue = policyAdapter.getPolicyName().substring(0, policyAdapter.getPolicyName().indexOf("_")); + configPolicyName = "Firewall Config"; + }else if(policyAdapter.getPolicyName().startsWith("Config_BRMS_Raw")){ + policyNameValue = policyAdapter.getPolicyName().substring(0, policyAdapter.getPolicyName().indexOf("_")); + configPolicyName = "BRMS_Raw"; + }else if(policyAdapter.getPolicyName().startsWith("Config_BRMS_Param")){ + policyNameValue = policyAdapter.getPolicyName().substring(0, policyAdapter.getPolicyName().indexOf("_")); + configPolicyName = "BRMS_Param"; + }else if(policyAdapter.getPolicyName().startsWith("Config_MS")){ + policyNameValue = policyAdapter.getPolicyName().substring(0, policyAdapter.getPolicyName().indexOf("_")); + configPolicyName = "DCAE Micro Service"; + }else if(policyAdapter.getPolicyName().startsWith("Action") || policyAdapter.getPolicyName().startsWith("Decision") ){ + policyNameValue = policyAdapter.getPolicyName().substring(0, policyAdapter.getPolicyName().indexOf("_")); + } + else{ + policyNameValue = policyAdapter.getPolicyName().substring(0, policyAdapter.getPolicyName().indexOf("_")); + configPolicyName = "Base"; + } + if (policyNameValue != null) { + policyAdapter.setPolicyType(policyNameValue); + } + if (configPolicyName != null) { + policyAdapter.setConfigPolicyType(configPolicyName); + } + + if("Action".equalsIgnoreCase(policyAdapter.getPolicyType())){ + ActionPolicyController actionController = new ActionPolicyController(); + actionController.PrePopulateActionPolicyData(policyAdapter); + } + if("Decision".equalsIgnoreCase(policyAdapter.getPolicyType())){ + DecisionPolicyController decisionController = new DecisionPolicyController(); + decisionController.PrePopulateDecisionPolicyData(policyAdapter); + } + if("Config".equalsIgnoreCase(policyAdapter.getPolicyType())){ + if("Base".equalsIgnoreCase(policyAdapter.getConfigPolicyType())){ + CreatePolicyController baseController = new CreatePolicyController(); + baseController.PrePopulateBaseConfigPolicyData(policyAdapter); + } + else if("BRMS_Raw".equalsIgnoreCase(policyAdapter.getConfigPolicyType())){ + CreateBRMSRawController brmsController = new CreateBRMSRawController(); + brmsController.PrePopulateBRMSRawPolicyData(policyAdapter); + } + else if("BRMS_Param".equalsIgnoreCase(policyAdapter.getConfigPolicyType())){ + CreateBRMSParamController paramController = new CreateBRMSParamController(); + paramController.PrePopulateBRMSParamPolicyData(policyAdapter); + } + else if("ClosedLoop_Fault".equalsIgnoreCase(policyAdapter.getConfigPolicyType())){ + CreateClosedLoopFaultController newFaultTemplate = new CreateClosedLoopFaultController(); + newFaultTemplate.PrePopulateClosedLoopFaultPolicyData(policyAdapter); + } + else if("ClosedLoop_PM".equalsIgnoreCase(policyAdapter.getConfigPolicyType())){ + CreateClosedLoopPMController pmController = new CreateClosedLoopPMController(); + pmController.PrePopulateClosedLoopPMPolicyData(policyAdapter); + } + else if("DCAE Micro Service".equalsIgnoreCase(policyAdapter.getConfigPolicyType())){ + CreateDcaeMicroServiceController msController = new CreateDcaeMicroServiceController(); + msController.PrePopulateDCAEMSPolicyData(policyAdapter); + } + else if("Firewall Config".equalsIgnoreCase(policyAdapter.getConfigPolicyType())){ + CreateFirewallController firewallController = new CreateFirewallController(); + firewallController.PrePopulateFWPolicyData(policyAdapter); + } + } + + + policyAdapter.setParentPath(null); + ObjectMapper mapper = new ObjectMapper(); + String json = mapper.writeValueAsString(policyAdapter); + JsonNode jsonNode = mapper.readTree(json); + + return new JSONObject().put(RESULT, jsonNode); + } catch (Exception e) { + LOG.error("editFile", e); + return error(e.getMessage()); + } + } + + //Add Scopes + private JSONObject addFolder(JSONObject params, HttpServletRequest request) throws ServletException { + String name = ""; + + try { + String userId = UserUtils.getUserIdFromCookie(request); + String path = params.getString("path"); + try{ + if(params.has("subScopename")){ + if(!params.getString("subScopename").equals("")){ + name = params.getString("path").replace("/", File.separator) + File.separator +params.getString("subScopename"); + } + }else{ + name = params.getString("name"); + } + }catch(Exception e){ + name = params.getString("name"); + LOG.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Exception Occured While Adding Scope"+e); + } + + + LOG.debug("addFolder path: {} name: {}" + path +name); + File newDir = new File(REPOSITORY_BASE_PATH, name); + if(!newDir.exists()){ + if (!newDir.mkdir()) { + throw new Exception("Can't create directory: " + newDir.getAbsolutePath()); + } + UserInfo userInfo = new UserInfo(); + userInfo.setUserLoginId(userId); + PolicyEditorScopes newScope = new PolicyEditorScopes(); + String scopeName = null; + if(name.startsWith(File.separator)){ + scopeName = name.substring(1); + }else{ + scopeName = name; + } + newScope.setScopeName(scopeName); + newScope.setUserCreatedBy(userInfo); + newScope.setUserModifiedBy(userInfo); + PolicyController.SavePolicyScope(newScope); + }else{ + return error("Scope Already Exists"); + } + + return success(); + } catch (Exception e) { + LOG.error("addFolder", e); + return error(e.getMessage()); + } + } + + //Return Error Object + private JSONObject error(String msg) throws ServletException { + try { + JSONObject result = new JSONObject(); + result.put("success", false); + result.put("error", msg); + return new JSONObject().put(RESULT, result); + } catch (JSONException e) { + throw new ServletException(e); + } + } + + //Return Success Object + private JSONObject success() throws ServletException { + try { + JSONObject result = new JSONObject(); + result.put("success", true); + result.put("error", (Object) null); + return new JSONObject().put(RESULT, result); + } catch (JSONException e) { + throw new ServletException(e); + } + } +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/admin/PolicyNotificationMail.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/admin/PolicyNotificationMail.java new file mode 100644 index 000000000..186adfa29 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/admin/PolicyNotificationMail.java @@ -0,0 +1,140 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.admin; + +/* + * + * + * + * */ +import java.io.UnsupportedEncodingException; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.List; +import java.util.Properties; + +import javax.mail.MessagingException; +import javax.mail.internet.InternetAddress; +import javax.mail.internet.MimeMessage; + +import org.openecomp.policy.controller.PolicyController; +import org.openecomp.policy.dao.WatchPolicyNotificationDao; +import org.openecomp.policy.rest.jpa.PolicyVersion; +import org.openecomp.policy.rest.jpa.WatchPolicyNotificationTable; +import org.springframework.beans.factory.annotation.Configurable; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.mail.javamail.JavaMailSenderImpl; +import org.springframework.mail.javamail.MimeMessageHelper; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +@Configurable +public class PolicyNotificationMail{ + private static Logger logger = FlexLogger.getLogger(PolicyNotificationMail.class); + + @Bean + public JavaMailSenderImpl javaMailSenderImpl(){ + JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); + mailSender.setHost(PolicyController.smtpHost); + mailSender.setPort(Integer.parseInt(PolicyController.smtpPort)); + mailSender.setUsername(PolicyController.smtpUsername); + mailSender.setPassword(PolicyController.smtpPassword); + Properties prop = mailSender.getJavaMailProperties(); + prop.put("mail.transport.protocol", "smtp"); + prop.put("mail.smtp.auth", "true"); + prop.put("mail.smtp.starttls.enable", "true"); + prop.put("mail.debug", "true"); + return mailSender; + } + + @SuppressWarnings("resource") + public void sendMail(PolicyVersion entityItem, String policyName, String mode, WatchPolicyNotificationDao policyNotificationDao) throws MessagingException { + String from = PolicyController.smtpUsername; + String to = ""; + String subject = ""; + String message = ""; + DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); + Date date = new Date(); + if(mode.equalsIgnoreCase("EditPolicy")){ + subject = "Policy has been Updated : "+entityItem.getPolicyName(); + message = "The Policy Which you are watching in " + PolicyController.smtpApplicationName + " has been Updated" + '\n' + '\n' + '\n'+ "Scope + Policy Name : " + policyName + '\n' + "Active Version : " +entityItem.getActiveVersion() + + '\n' + '\n' + "Modified By : " +entityItem.getModifiedBy() + '\n' + "Modified Time : " +dateFormat.format(date) + '\n' + '\n' + '\n' + '\n' + "Policy Notification System (please don't respond to this email)"; + } + if(mode.equalsIgnoreCase("Rename")){ + subject = "Policy has been Renamed : "+entityItem.getPolicyName(); + message = "The Policy Which you are watching in " + PolicyController.smtpApplicationName + " has been Renamed" + '\n' + '\n' + '\n'+ "Scope + Policy Name : " + policyName + '\n' + "Active Version : " +entityItem.getActiveVersion() + + '\n' + '\n' + "Renamed By : " +entityItem.getModifiedBy() + '\n' + "Renamed Time : " +dateFormat.format(date) + '\n' + '\n' + '\n' + '\n' + "Policy Notification System (please don't respond to this email)"; + } + if(mode.equalsIgnoreCase("DeleteAll")){ + subject = "Policy has been Deleted : "+entityItem.getPolicyName(); + message = "The Policy Which you are watching in " + PolicyController.smtpApplicationName + " has been Deleted with All Versions" + '\n' + '\n' + '\n'+ "Scope + Policy Name : " + policyName + '\n' + + '\n' + '\n' + "Deleted By : " +entityItem.getModifiedBy() + '\n' + "Deleted Time : " +dateFormat.format(date) + '\n' + '\n' + '\n' + '\n' + "Policy Notification System (please don't respond to this email)"; + } + if(mode.equalsIgnoreCase("DeleteOne")){ + subject = "Policy has been Deleted : "+entityItem.getPolicyName(); + message = "The Policy Which you are watching in " + PolicyController.smtpApplicationName + " has been Deleted" + '\n' + '\n' + '\n'+ "Scope + Policy Name : " + policyName + '\n' +"Policy Version : " +entityItem.getActiveVersion() + + '\n' + '\n' + "Deleted By : " +entityItem.getModifiedBy() + '\n' + "Deleted Time : " +dateFormat.format(date) + '\n' + '\n' + '\n' + '\n' + "Policy Notification System (please don't respond to this email)"; + } + if(mode.equalsIgnoreCase("DeleteScope")){ + subject = "Scope has been Deleted : "+entityItem.getPolicyName(); + message = "The Scope Which you are watching in " + PolicyController.smtpApplicationName + " has been Deleted" + '\n' + '\n' + '\n'+ "Scope + Scope Name : " + policyName + '\n' + + '\n' + '\n' + "Deleted By : " +entityItem.getModifiedBy() + '\n' + "Deleted Time : " +dateFormat.format(date) + '\n' + '\n' + '\n' + '\n' + "Policy Notification System (please don't respond to this email)"; + } + if(mode.equalsIgnoreCase("SwitchVersion")){ + subject = "Policy has been SwitchedVersion : "+entityItem.getPolicyName(); + message = "The Policy Which you are watching in " + PolicyController.smtpApplicationName + " has been SwitchedVersion" + '\n' + '\n' + '\n'+ "Scope + Policy Name : " + policyName + '\n' + "Active Version : " +entityItem.getActiveVersion() + + '\n' + '\n' + "Switched By : " +entityItem.getModifiedBy() + '\n' + "Switched Time : " +dateFormat.format(date) + '\n' + '\n' + '\n' + '\n' + "Policy Notification System (please don't respond to this email)"; + } + if(mode.equalsIgnoreCase("Move")){ + subject = "Policy has been Moved to Other Scope : "+entityItem.getPolicyName(); + message = "The Policy Which you are watching in " + PolicyController.smtpApplicationName + " has been Moved to Other Scope" + '\n' + '\n' + '\n'+ "Scope + Policy Name : " + policyName + '\n' + "Active Version : " +entityItem.getActiveVersion() + + '\n' + '\n' + "Moved By : " +entityItem.getModifiedBy() + '\n' + "Moved Time : " +dateFormat.format(date) + '\n' + '\n' + '\n' + '\n' + "Policy Notification System (please don't respond to this email)"; + } + String policyFileName = entityItem.getPolicyName(); + List watchList = policyNotificationDao.getListDataByPolicyName(policyFileName); + if(watchList.size() > 0){ + for(WatchPolicyNotificationTable list : watchList){ + to = list.getLoginIds()+"@"+PolicyController.smtpEmailExtension; + to = to.trim(); + AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); + ctx.register(PolicyNotificationMail.class); + ctx.refresh(); + JavaMailSenderImpl mailSender = ctx.getBean(JavaMailSenderImpl.class); + MimeMessage mimeMessage = mailSender.createMimeMessage(); + MimeMessageHelper mailMsg = new MimeMessageHelper(mimeMessage); + try { + mailMsg.setFrom(new InternetAddress(from, "Policy Notification System")); + } catch (UnsupportedEncodingException e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW+"Exception Occured in Policy Notification" +e); + } + mailMsg.setTo(to); + mailMsg.setSubject(subject); + mailMsg.setText(message); + mailSender.send(mimeMessage); + } + } + } +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/admin/RESTfulPAPEngine.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/admin/RESTfulPAPEngine.java new file mode 100644 index 000000000..ecb610264 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/admin/RESTfulPAPEngine.java @@ -0,0 +1,732 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.admin; + + + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.UnsupportedEncodingException; +import java.net.HttpURLConnection; +import java.net.URL; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import java.util.Base64; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +import org.apache.commons.io.IOUtils; +import org.openecomp.policy.adapter.PolicyAdapter; +import org.openecomp.policy.rest.XACMLRestProperties; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; +import org.openecomp.policy.xacml.api.pap.EcompPDP; +import org.openecomp.policy.xacml.api.pap.EcompPDPGroup; +import org.openecomp.policy.xacml.api.pap.PAPPolicyEngine; +import org.openecomp.policy.xacml.std.pap.StdPAPPolicy; +import org.openecomp.policy.xacml.std.pap.StdPDP; +import org.openecomp.policy.xacml.std.pap.StdPDPGroup; +import org.openecomp.policy.xacml.std.pap.StdPDPItemSetChangeNotifier; +import org.openecomp.policy.xacml.std.pap.StdPDPPolicy; +import org.openecomp.policy.xacml.std.pap.StdPDPStatus; +import com.att.research.xacml.api.pap.PAPEngine; +import com.att.research.xacml.api.pap.PAPException; +import com.att.research.xacml.api.pap.PDP; +import com.att.research.xacml.api.pap.PDPGroup; +//import com.att.research.xacml.api.pap.PDP; +//import com.att.research.xacml.api.pap.PDPGroup; +import com.att.research.xacml.api.pap.PDPPolicy; +import com.att.research.xacml.api.pap.PDPStatus; +import com.att.research.xacml.util.XACMLProperties; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.introspect.VisibilityChecker; +import com.fasterxml.jackson.databind.type.CollectionType; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +/** + * Implementation of the PAPEngine interface that communicates with a PAP engine in a remote servlet + * through a RESTful interface + * + * + */ +public class RESTfulPAPEngine extends StdPDPItemSetChangeNotifier implements PAPPolicyEngine { + private static final Logger logger = FlexLogger.getLogger(RESTfulPAPEngine.class); + + // + // URL of the PAP Servlet that this Admin Console talks to + // + private String papServletURLString; + + /** + * Set up link with PAP Servlet and get our initial set of Groups + * @throws Exception + */ + public RESTfulPAPEngine (String myURLString) throws PAPException, IOException { + // + // Get our URL to the PAP servlet + // + this.papServletURLString = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_URL); + if (this.papServletURLString == null || this.papServletURLString.length() == 0) { + String message = "The property 'POLICYENGINE_ADMIN_ACTIVE' was not set during installation. Admin Console cannot call PAP."; + logger.error(message); + throw new PAPException(message); + } + + // + // register this Admin Console with the PAP Servlet to get updates + // + Object newURL = sendToPAP("PUT", null, null, null, "adminConsoleURL=" + myURLString); + if (newURL != null) { + // assume this was a re-direct and try again + logger.warn("Redirecting to '" + newURL + "'"); + this.papServletURLString = (String)newURL; + newURL = sendToPAP("PUT", null, null, null, "adminConsoleURL=" + myURLString); + if (newURL != null) { + logger.error("Failed to redirect to " + this.papServletURLString); + throw new PAPException("Failed to register with PAP"); + } + } + } + + + // + // High-level commands used by the Admin Console code through the PAPEngine Interface + // + + @Override + public EcompPDPGroup getDefaultGroup() throws PAPException { + EcompPDPGroup newGroup = (EcompPDPGroup)sendToPAP("GET", null, null, StdPDPGroup.class, "groupId=", "default="); + return newGroup; + } + + @Override + public void SetDefaultGroup(EcompPDPGroup group) throws PAPException { + sendToPAP("POST", null, null, null, "groupId=" + group.getId(), "default=true"); + } + + @SuppressWarnings("unchecked") + @Override + public Set getEcompPDPGroups() throws PAPException { + Set newGroupSet; + newGroupSet = (Set) this.sendToPAP("GET", null, Set.class, StdPDPGroup.class, "groupId="); + return Collections.unmodifiableSet(newGroupSet); + } + + + @Override + public EcompPDPGroup getGroup(String id) throws PAPException { + EcompPDPGroup newGroup = (EcompPDPGroup)sendToPAP("GET", null, null, StdPDPGroup.class, "groupId=" + id); + return newGroup; + } + + @Override + public void newGroup(String name, String description) + throws PAPException, NullPointerException { + String escapedName = null; + String escapedDescription = null; + try { + escapedName = URLEncoder.encode(name, "UTF-8"); + escapedDescription = URLEncoder.encode(description, "UTF-8"); + } catch (UnsupportedEncodingException e) { + throw new PAPException("Unable to send name or description to PAP: " + e.getMessage()); + } + + this.sendToPAP("POST", null, null, null, "groupId=", "groupName="+escapedName, "groupDescription=" + escapedDescription); + } + + + /** + * Update the configuration on the PAP for a single Group. + * + * @param group + * @return + * @throws PAPException + */ + public void updateGroup(EcompPDPGroup group) throws PAPException { + + try { + + // + // ASSUME that all of the policies mentioned in this group are already located in the correct directory on the PAP! + // + // Whenever a Policy is added to the group, that file must be automatically copied to the PAP from the Workspace. + // + + +// // Copy all policies from the local machine's workspace to the PAP's PDPGroup directory. +// // This is not efficient since most of the policies will already exist there. +// // However, the policy files are (probably!) not too huge, and this is a good way to ensure that any corrupted files on the PAP get refreshed. +// + + // now update the group object on the PAP + + sendToPAP("PUT", group, null, null, "groupId=" + group.getId()); + } catch (Exception e) { + String message = "Unable to PUT policy '" + group.getId() + "', e:" + e; + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + message, e); + throw new PAPException(message); + } + } + + + @Override + public void removeGroup(EcompPDPGroup group, EcompPDPGroup newGroup) + throws PAPException, NullPointerException { + String moveToGroupString = null; + if (newGroup != null) { + moveToGroupString = "movePDPsToGroupId=" + newGroup.getId(); + } + sendToPAP("DELETE", null, null, null, "groupId=" + group.getId(), moveToGroupString); + } + + @Override + public EcompPDPGroup getPDPGroup(EcompPDP pdp) throws PAPException { + return getPDPGroup(pdp.getId()); + } + + + public EcompPDPGroup getPDPGroup(String pdpId) throws PAPException { + EcompPDPGroup newGroup = (EcompPDPGroup)sendToPAP("GET", null, null, StdPDPGroup.class, "groupId=", "pdpId=" + pdpId, "getPDPGroup="); + return newGroup; + } + + @Override + public EcompPDP getPDP(String pdpId) throws PAPException { + EcompPDP newPDP = (EcompPDP)sendToPAP("GET", null, null, StdPDP.class, "groupId=", "pdpId=" + pdpId); + return newPDP; + } + + @Override + public void newPDP(String id, EcompPDPGroup group, String name, String description, int jmxport) throws PAPException, + NullPointerException { + StdPDP newPDP = new StdPDP(id, name, description, jmxport); + sendToPAP("PUT", newPDP, null, null, "groupId=" + group.getId(), "pdpId=" + id); + return; + } + + @Override + public void movePDP(EcompPDP pdp, EcompPDPGroup newGroup) throws PAPException { + sendToPAP("POST", null, null, null, "groupId=" + newGroup.getId(), "pdpId=" + pdp.getId()); + return; + } + + @Override + public void updatePDP(EcompPDP pdp) throws PAPException { + EcompPDPGroup group = getPDPGroup(pdp); + sendToPAP("PUT", pdp, null, null, "groupId=" + group.getId(), "pdpId=" + pdp.getId()); + return; + } + + @Override + public void removePDP(EcompPDP pdp) throws PAPException { + EcompPDPGroup group = getPDPGroup(pdp); + sendToPAP("DELETE", null, null, null, "groupId=" + group.getId(), "pdpId=" + pdp.getId()); + return; + } + + //Validate the Policy Data + public boolean validatePolicyRequest(PolicyAdapter policyAdapter, String policyType) throws PAPException { + Boolean isValidData = false; +/* StdPAPPolicy newPAPPolicy = new StdPAPPolicy(policyAdapter.getPolicyName(), policyAdapter.getPolicyDescription(), policyAdapter.getEcompName(), policyAdapter.getConfigName(), + policyAdapter.getDynamicFieldConfigAttributes(), policyAdapter.getConfigBodyData(), policyAdapter.getPolicyID(), policyAdapter.getRuleID(), + policyAdapter.getRuleCombiningAlgId(), policyAdapter.getParentPath().toString(), policyAdapter.getGitPath().toString(), policyAdapter.getConfigType(), policyAdapter.isEditPolicy()); + */ + + StdPAPPolicy newPAPPolicy = new StdPAPPolicy(policyAdapter.getPolicyName(), policyAdapter.getConfigBodyData(), policyAdapter.getConfigType(), "Base"); + + //send JSON object to PAP + isValidData = (Boolean) sendToPAP("PUT", newPAPPolicy, null, null, "operation=validate", "apiflag=admin", "policyType=" + policyType); + return isValidData; + } + + //create a new policy + @SuppressWarnings("unchecked") + public Map createPolicyRequest(PolicyAdapter policyAdapter) throws PAPException { + Map successMap = new HashMap(); + StdPAPPolicy newPAPPolicy = null; + + if (policyAdapter.getPolicyType().equalsIgnoreCase("Config")) { + + if (policyAdapter.getConfigPolicyType().equalsIgnoreCase("Firewall Config")) { + + //create StdPAPPolicy object for Config Firewall Policy + newPAPPolicy = new StdPAPPolicy(policyAdapter.getConfigPolicyType(), policyAdapter.getPolicyName(), policyAdapter.getPolicyDescription(), + policyAdapter.getConfigName(), policyAdapter.isEditPolicy(), policyAdapter.getDomainDir(), policyAdapter.getJsonBody(), + policyAdapter.getHighestVersion() ,policyAdapter.getRiskLevel(), policyAdapter.getRiskType(), policyAdapter.getGuard(),policyAdapter.getTtlDate()); + + } + else if (policyAdapter.getConfigPolicyType().equalsIgnoreCase("BRMS_Raw")) { + + //create StdPAPPolicy object for BRMS_Raw Policy + newPAPPolicy = new StdPAPPolicy(policyAdapter.getConfigPolicyType(), policyAdapter.getPolicyName(), policyAdapter.getPolicyDescription(), + policyAdapter.getConfigName(), policyAdapter.isEditPolicy(), policyAdapter.getDomainDir(), policyAdapter.getDynamicFieldConfigAttributes(), + policyAdapter.getHighestVersion(),policyAdapter.getEcompName(),policyAdapter.getConfigBodyData(),policyAdapter.getRiskLevel(), + policyAdapter.getRiskType(), policyAdapter.getGuard(),policyAdapter.getTtlDate()); + + } + else if (policyAdapter.getConfigPolicyType().equalsIgnoreCase("BRMS_Param")) { + + //create StdPAPPolicy object for BRMS_Param Policy + newPAPPolicy = new StdPAPPolicy(policyAdapter.getConfigPolicyType(), policyAdapter.getPolicyName(), policyAdapter.getPolicyDescription(), + policyAdapter.getConfigName(), policyAdapter.isEditPolicy(), policyAdapter.getDomainDir(), policyAdapter.getDynamicFieldConfigAttributes(), + policyAdapter.getHighestVersion(),policyAdapter.getEcompName(),policyAdapter.getConfigBodyData(),policyAdapter.getBRMSParamBody(), + policyAdapter.getRiskLevel(), policyAdapter.getRiskType(), policyAdapter.getGuard(),policyAdapter.getTtlDate()); + + } + + else if (policyAdapter.getConfigPolicyType().equalsIgnoreCase("Base")) { + + //create StdPAPPolicy object for Config Base Policy + newPAPPolicy = new StdPAPPolicy(policyAdapter.getConfigPolicyType(), policyAdapter.getPolicyName(), policyAdapter.getPolicyDescription(), + policyAdapter.getEcompName(), policyAdapter.getConfigName(), policyAdapter.getDynamicFieldConfigAttributes(), policyAdapter.getConfigType(), + policyAdapter.getConfigBodyData(), policyAdapter.isEditPolicy(), policyAdapter.getDomainDir(), policyAdapter.getHighestVersion(), + policyAdapter.getRiskLevel(), policyAdapter.getRiskType(), policyAdapter.getGuard(),policyAdapter.getTtlDate()); + + }else if (policyAdapter.getConfigPolicyType().equalsIgnoreCase("ClosedLoop_Fault")) { + + //create StdPAPPolicy object for CloseLoop Fault Policy + newPAPPolicy = new StdPAPPolicy(policyAdapter.getConfigPolicyType(), policyAdapter.getPolicyName(), policyAdapter.getPolicyDescription(), + policyAdapter.getEcompName(), policyAdapter.getJsonBody(), policyAdapter.isDraft(), policyAdapter.getOldPolicyFileName(), null, policyAdapter.isEditPolicy(), + policyAdapter.getDomainDir(), policyAdapter.getHighestVersion(), + policyAdapter.getRiskLevel(), policyAdapter.getRiskType(), policyAdapter.getGuard(),policyAdapter.getTtlDate()); + + }else if (policyAdapter.getConfigPolicyType().equalsIgnoreCase("ClosedLoop_PM")) { + + //create StdPAPPolicy object for CloseLoop PM Policy + newPAPPolicy = new StdPAPPolicy(policyAdapter.getConfigPolicyType(), policyAdapter.getPolicyName(), policyAdapter.getPolicyDescription(), + policyAdapter.getEcompName(), policyAdapter.getJsonBody(), policyAdapter.isDraft(), policyAdapter.getOldPolicyFileName(), policyAdapter.getServiceType(), + policyAdapter.isEditPolicy(), policyAdapter.getDomainDir(), policyAdapter.getHighestVersion(),policyAdapter.getRiskLevel(), policyAdapter.getRiskType(), + policyAdapter.getGuard(),policyAdapter.getTtlDate()); + + }else if (policyAdapter.getConfigPolicyType().equalsIgnoreCase("DCAE Micro Service")) { + + //create StdPAPPolicy object for DCAE Micro Service Policy + newPAPPolicy = new StdPAPPolicy(policyAdapter.getConfigPolicyType(), policyAdapter.getPolicyName(), policyAdapter.getPolicyDescription(), + policyAdapter.getEcompName(), policyAdapter.getConfigName(), policyAdapter.getServiceType(), policyAdapter.getUuid(), policyAdapter.getLocation(), + policyAdapter.getJsonBody(), policyAdapter.getPriority(), null, policyAdapter.isEditPolicy(), policyAdapter.getDomainDir(), + policyAdapter.getHighestVersion(),policyAdapter.getRiskLevel(), policyAdapter.getRiskType(), policyAdapter.getGuard(),policyAdapter.getTtlDate()); + + } + } else if (policyAdapter.getPolicyType().equalsIgnoreCase("Action")) { + + //create StdPAPPolicy object for Action Policy + newPAPPolicy = new StdPAPPolicy(policyAdapter.getPolicyName(), policyAdapter.getPolicyDescription(), policyAdapter.getDynamicFieldConfigAttributes(), + policyAdapter.getDynamicRuleAlgorithmLabels(), policyAdapter.getDynamicRuleAlgorithmCombo(), policyAdapter.getDynamicRuleAlgorithmField1(), + policyAdapter.getDynamicRuleAlgorithmField2(), policyAdapter.getActionPerformer(), policyAdapter.getActionAttribute(), + policyAdapter.isEditPolicy(), policyAdapter.getDomainDir(), policyAdapter.getHighestVersion()); + + } else if (policyAdapter.getPolicyType().equalsIgnoreCase("Decision")) { + + //create StdPAPPolicy object for Decision Policy + newPAPPolicy = new StdPAPPolicy(policyAdapter.getPolicyName(), policyAdapter.getPolicyDescription(), policyAdapter.getEcompName(), policyAdapter.getRuleProvider(), + policyAdapter.getDynamicFieldConfigAttributes(), policyAdapter.getDynamicSettingsMap(), policyAdapter.getDynamicRuleAlgorithmLabels(), + policyAdapter.getDynamicRuleAlgorithmCombo(), policyAdapter.getDynamicRuleAlgorithmField1(), policyAdapter.getDynamicRuleAlgorithmField2(), + policyAdapter.getDropDownMap(), policyAdapter.getDynamicVariableList(), policyAdapter.getDataTypeList(), policyAdapter.isEditPolicy(), + policyAdapter.getDomainDir(), policyAdapter.getHighestVersion()); + + } + + //send JSON object to PAP + successMap = (Map) sendToPAP("PUT", newPAPPolicy, null, null, "operation=create", "apiflag=admin", "policyType=" + policyAdapter.getPolicyType()); + return successMap; + + + } + + //update an existing policy + @SuppressWarnings("unchecked") + public Map updatePolicyRequest(PolicyAdapter policyAdapter) throws PAPException { + Map successMap = new HashMap(); + StdPAPPolicy newPAPPolicy = null; + + if (policyAdapter.getPolicyType().equalsIgnoreCase("Config")) { + + if (policyAdapter.getConfigPolicyType().equalsIgnoreCase("Firewall Config")) { + + //create StdPAPPolicy object for Firewall Config Policy + newPAPPolicy = new StdPAPPolicy(policyAdapter.getConfigPolicyType(), policyAdapter.getPolicyName(), policyAdapter.getPolicyDescription(), policyAdapter.getConfigName(), + policyAdapter.isEditPolicy(), policyAdapter.getDomainDir(), policyAdapter.getPolicyID(), + policyAdapter.getRuleID(), policyAdapter.getVersion(), policyAdapter.getJsonBody(), policyAdapter.getHighestVersion(),policyAdapter.getRiskLevel(), + policyAdapter.getRiskType(), policyAdapter.getGuard(),policyAdapter.getTtlDate()); + + } + else if (policyAdapter.getConfigPolicyType().equalsIgnoreCase("BRMS_Raw")) { + //create StdPAPPolicy object for BRMS_Raw Policy + newPAPPolicy = new StdPAPPolicy(policyAdapter.getConfigPolicyType(), policyAdapter.getPolicyName(), policyAdapter.getPolicyDescription(), + policyAdapter.getConfigName(), policyAdapter.isEditPolicy(), policyAdapter.getDomainDir(), policyAdapter.getDynamicFieldConfigAttributes(), + policyAdapter.getHighestVersion(),policyAdapter.getEcompName(),policyAdapter.getConfigBodyData(),policyAdapter.getRiskLevel(), + policyAdapter.getRiskType(), policyAdapter.getGuard(),policyAdapter.getTtlDate()); + + }else if (policyAdapter.getConfigPolicyType().equalsIgnoreCase("BRMS_Param")) { + //create StdPAPPolicy object for BRMS_Raw Policy + newPAPPolicy = new StdPAPPolicy(policyAdapter.getConfigPolicyType(), policyAdapter.getPolicyName(), policyAdapter.getPolicyDescription(), + policyAdapter.getConfigName(), policyAdapter.isEditPolicy(), policyAdapter.getDomainDir(), policyAdapter.getDynamicFieldConfigAttributes(), + policyAdapter.getHighestVersion(),policyAdapter.getEcompName(),policyAdapter.getConfigBodyData(),policyAdapter.getBRMSParamBody(), + policyAdapter.getRiskLevel(), policyAdapter.getRiskType(), policyAdapter.getGuard(),policyAdapter.getTtlDate()); + + }else if (policyAdapter.getConfigPolicyType().equalsIgnoreCase("Base")) { + + //create StdPAPPolicy object for Config Base Policy + newPAPPolicy = new StdPAPPolicy(policyAdapter.getConfigPolicyType(), policyAdapter.getPolicyName(), policyAdapter.getPolicyDescription(), policyAdapter.getEcompName(), policyAdapter.getConfigName(), + policyAdapter.getDynamicFieldConfigAttributes(), policyAdapter.getConfigBodyData(), policyAdapter.getPolicyID(), policyAdapter.getRuleID(), + policyAdapter.getConfigType(), policyAdapter.isEditPolicy(), policyAdapter.getVersion(), policyAdapter.getDomainDir(), policyAdapter.getHighestVersion(),policyAdapter.getRiskLevel(), + policyAdapter.getRiskType(), policyAdapter.getGuard(),policyAdapter.getTtlDate()); + + }else if (policyAdapter.getConfigPolicyType().equalsIgnoreCase("ClosedLoop_Fault")) { + + //create StdPAPPolicy object for CloseLoop Fault Policy + newPAPPolicy = new StdPAPPolicy(policyAdapter.getConfigPolicyType(), policyAdapter.getPolicyName(), policyAdapter.getPolicyDescription(), + policyAdapter.getEcompName(), policyAdapter.getJsonBody(), policyAdapter.isDraft(), policyAdapter.getOldPolicyFileName(), null, policyAdapter.isEditPolicy(), + policyAdapter.getDomainDir(), policyAdapter.getHighestVersion(),policyAdapter.getRiskLevel(), policyAdapter.getRiskType(), policyAdapter.getGuard(), + policyAdapter.getTtlDate()); + + }else if (policyAdapter.getConfigPolicyType().equalsIgnoreCase("ClosedLoop_PM")) { + + //create StdPAPPolicy object for CloseLoop PM Policy + newPAPPolicy = new StdPAPPolicy(policyAdapter.getConfigPolicyType(), policyAdapter.getPolicyName(), policyAdapter.getPolicyDescription(), + policyAdapter.getEcompName(), policyAdapter.getJsonBody(), policyAdapter.isDraft(), policyAdapter.getOldPolicyFileName(), policyAdapter.getServiceType(), + policyAdapter.isEditPolicy(), policyAdapter.getDomainDir(), policyAdapter.getHighestVersion(),policyAdapter.getRiskLevel(), policyAdapter.getRiskType(), + policyAdapter.getGuard(),policyAdapter.getTtlDate()); + + }else if (policyAdapter.getConfigPolicyType().equalsIgnoreCase("DCAE Micro Service")) { + + //create StdPAPPolicy object for DCAE Micro Service Policy + newPAPPolicy = new StdPAPPolicy(policyAdapter.getConfigPolicyType(), policyAdapter.getPolicyName(), policyAdapter.getPolicyDescription(), + policyAdapter.getEcompName(), policyAdapter.getConfigName(), policyAdapter.getServiceType(), policyAdapter.getUuid(), policyAdapter.getLocation(), + policyAdapter.getJsonBody(), policyAdapter.getPriority(), null, policyAdapter.isEditPolicy(), policyAdapter.getDomainDir(), policyAdapter.getHighestVersion(), + policyAdapter.getRiskLevel(), policyAdapter.getRiskType(), policyAdapter.getGuard(),policyAdapter.getTtlDate()); + + } + } else if (policyAdapter.getPolicyType().equalsIgnoreCase("Action")) { + + //create StdPAPPolicy object for Action Policy + newPAPPolicy = new StdPAPPolicy(policyAdapter.getPolicyName(), policyAdapter.getPolicyDescription(), policyAdapter.getDynamicFieldConfigAttributes(), + policyAdapter.getDynamicRuleAlgorithmLabels(), policyAdapter.getDynamicRuleAlgorithmCombo(), policyAdapter.getDynamicRuleAlgorithmField1(), + policyAdapter.getDynamicRuleAlgorithmField2(), policyAdapter.getActionPerformer(), policyAdapter.getActionAttribute(), + policyAdapter.isEditPolicy(), policyAdapter.getDomainDir(), policyAdapter.getHighestVersion()); + + } else if (policyAdapter.getPolicyType().equalsIgnoreCase("Decision")) { + + //create StdPAPPolicy object for Decision Policy + newPAPPolicy = new StdPAPPolicy(policyAdapter.getPolicyName(), policyAdapter.getPolicyDescription(), policyAdapter.getEcompName(), policyAdapter.getRuleProvider(), + policyAdapter.getDynamicFieldConfigAttributes(), policyAdapter.getDynamicSettingsMap(), policyAdapter.getDynamicRuleAlgorithmLabels(), + policyAdapter.getDynamicRuleAlgorithmCombo(), policyAdapter.getDynamicRuleAlgorithmField1(), policyAdapter.getDynamicRuleAlgorithmField2(), + policyAdapter.getDropDownMap(), policyAdapter.getDynamicVariableList(), policyAdapter.getDataTypeList(), policyAdapter.isEditPolicy(), + policyAdapter.getDomainDir(), policyAdapter.getHighestVersion()); + + } + + //send JSON object to PAP + successMap = (Map) sendToPAP("PUT", newPAPPolicy, null, null, "operation=update", "apiflag=admin", "policyType=" + policyAdapter.getPolicyType()); + return successMap; + } + + @Override + public void publishPolicy(String id, String name, boolean isRoot, + InputStream policy, EcompPDPGroup group) throws PAPException { + + + // copy the (one) file into the target directory on the PAP servlet + copyFile(id, group, policy); + + // adjust the local copy of the group to include the new policy + PDPPolicy pdpPolicy = new StdPDPPolicy(id, isRoot, name); + group.getPolicies().add(pdpPolicy); + + // tell the PAP servlet to include the policy in the configuration + updateGroup(group); + + return; + } + + + + /** + * Copy a single Policy file from the input stream to the PAP Servlet. + * Either this works (silently) or it throws an exception. + * + * @param policyId + * @param group + * @param policy + * @return + * @throws PAPException + */ + public void copyFile(String policyId, EcompPDPGroup group, InputStream policy) throws PAPException { + // send the policy file to the PAP Servlet + try { + sendToPAP("POST", policy, null, null, "groupId=" + group.getId(), "policyId="+policyId); + } catch (Exception e) { + String message = "Unable to PUT policy '" + policyId + "', e:" + e; + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + message, e); + throw new PAPException(message); + } + } + + + @Override + public void copyPolicy(PDPPolicy policy, EcompPDPGroup group) throws PAPException { + if (policy == null || group == null) { + throw new PAPException("Null input policy="+policy+" group="+group); + } + try (InputStream is = new FileInputStream(new File(policy.getLocation())) ) { + copyFile(policy.getId(), group, is ); + } catch (Exception e) { + String message = "Unable to PUT policy '" + policy.getId() + "', e:" + e; + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + message, e); + throw new PAPException(message); + } + } + + + + + @Override + public void removePolicy(PDPPolicy policy, EcompPDPGroup group) throws PAPException { + throw new PAPException("NOT IMPLEMENTED"); + + } + + + + /** + * Special operation - Similar to the normal PAP operations but this one contacts the PDP directly + * to get detailed status info. + * + * @param pdp + * @return + * @throws PAPException + */ + + public PDPStatus getStatus(EcompPDP pdp) throws PAPException { + StdPDPStatus status = (StdPDPStatus)sendToPAP("GET", pdp, null, StdPDPStatus.class); + return status; + } + + + + + // + // Internal Operations called by the PAPEngine Interface methods + // + + /** + * Send a request to the PAP Servlet and get the response. + * + * The content is either an InputStream to be copied to the Request OutputStream + * OR it is an object that is to be encoded into JSON and pushed into the Request OutputStream. + * + * The Request parameters may be encoded in multiple "name=value" sets, or parameters may be combined by the caller. + * + * @param method + * @param content - EITHER an InputStream OR an Object to be encoded in JSON + * @param collectionTypeClass + * @param responseContentClass + * @param parameters + * @return + * @throws Exception + */ + private Object sendToPAP(String method, Object content, Class collectionTypeClass, Class responseContentClass, String... parameters ) throws PAPException { + HttpURLConnection connection = null; + String papID = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_USERID); + logger.info("User Id is " + papID); + String papPass = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_PASS); + logger.info("Pass is: " + papPass); + Base64.Encoder encoder = Base64.getEncoder(); + String encoding = encoder.encodeToString((papID+":"+papPass).getBytes(StandardCharsets.UTF_8)); + logger.info("Encoding for the PAP is: " + encoding); + try { + String fullURL = papServletURLString; + if (parameters != null && parameters.length > 0) { + String queryString = ""; + for (String p : parameters) { + queryString += "&" + p; + } + fullURL += "?" + queryString.substring(1); + } + + // special case - Status (actually the detailed status) comes from the PDP directly, not the PAP + if (method.equals("GET") && (content instanceof EcompPDP) && responseContentClass == StdPDPStatus.class) { + // Adjust the url and properties appropriately + String pdpID =((EcompPDP)content).getId(); + fullURL = pdpID + "?type=Status"; + content = null; + if(CheckPDP.validateID(pdpID)){ + encoding = CheckPDP.getEncoding(pdpID); + } + } + + + URL url = new URL(fullURL); + + // + // Open up the connection + // + connection = (HttpURLConnection)url.openConnection(); + // + // Setup our method and headers + // + connection.setRequestMethod(method); +// connection.setRequestProperty("Accept", "text/x-java-properties"); +// connection.setRequestProperty("Content-Type", "text/x-java-properties"); + connection.setUseCaches(false); + // + // Adding this in. It seems the HttpUrlConnection class does NOT + // properly forward our headers for POST re-direction. It does so + // for a GET re-direction. + // + // So we need to handle this ourselves. + // + connection.setInstanceFollowRedirects(false); + connection.setRequestProperty("Authorization", "Basic " + encoding); + connection.setDoOutput(true); + connection.setDoInput(true); + + if (content != null) { + if (content instanceof InputStream) { + try { + // + // Send our current policy configuration + // + try (OutputStream os = connection.getOutputStream()) { + int count = IOUtils.copy((InputStream)content, os); + if (logger.isDebugEnabled()) { + logger.debug("copied to output, bytes="+count); + } + } + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Failed to write content in '" + method + "'", e); + throw e; + } + } else { + // The content is an object to be encoded in JSON + ObjectMapper mapper = new ObjectMapper(); + mapper.writeValue(connection.getOutputStream(), content); + } + } + // + // Do the connect + // + connection.connect(); + if (connection.getResponseCode() == 204) { + logger.info("Success - no content."); + return null; + } else if (connection.getResponseCode() == 200) { + logger.info("Success. We have a return object."); + String isValidData = connection.getHeaderField("isValidData"); + String isSuccess = connection.getHeaderField("successMapKey"); + Map successMap = new HashMap(); + if (isValidData != null && isValidData.equalsIgnoreCase("true")){ + logger.info("Policy Data is valid."); + return true; + } else if (isValidData != null && isValidData.equalsIgnoreCase("false")) { + logger.info("Policy Data is invalid."); + return false; + } else if (isSuccess != null && isSuccess.equalsIgnoreCase("success")) { + logger.info("Policy Created Successfully!" ); + String finalPolicyPath = connection.getHeaderField("finalPolicyPath"); + successMap.put("success", finalPolicyPath); + return successMap; + } else if (isSuccess != null && isSuccess.equalsIgnoreCase("error")) { + logger.info("There was an error while creating the policy!"); + successMap.put("error", "error"); + return successMap; + } else { + // get the response content into a String + String json = null; + // read the inputStream into a buffer (trick found online scans entire input looking for end-of-file) + java.util.Scanner scanner = new java.util.Scanner(connection.getInputStream()); + scanner.useDelimiter("\\A"); + json = scanner.hasNext() ? scanner.next() : ""; + scanner.close(); + logger.info("JSON response from PAP: " + json); + + // convert Object sent as JSON into local object + ObjectMapper mapper = new ObjectMapper(); + mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); + if (collectionTypeClass != null) { + // collection of objects expected + final CollectionType javaType = + mapper.getTypeFactory().constructCollectionType(collectionTypeClass, responseContentClass); + + Object objectFromJSON = mapper.readValue(json, javaType); + return objectFromJSON; + } else { + // single value object expected + Object objectFromJSON = mapper.readValue(json, responseContentClass); + return objectFromJSON; + } + } + + } else if (connection.getResponseCode() >= 300 && connection.getResponseCode() <= 399) { + // redirection + String newURL = connection.getHeaderField("Location"); + if (newURL == null) { + logger.error("No Location header to redirect to when response code="+connection.getResponseCode()); + throw new IOException("No redirect Location header when response code="+connection.getResponseCode()); + } + int qIndex = newURL.indexOf("?"); + if (qIndex > 0) { + newURL = newURL.substring(0, qIndex); + } + logger.info("Redirect seen. Redirecting " + fullURL + " to " + newURL); + return newURL; + } else { + logger.warn("Unexpected response code: " + connection.getResponseCode() + " message: " + connection.getResponseMessage()); + throw new IOException("Server Response: " + connection.getResponseCode() + ": " + connection.getResponseMessage()); + } + + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "HTTP Request/Response to PAP: " + e,e); + throw new PAPException("Request/Response threw :" + e); + } finally { + // cleanup the connection + if (connection != null) { + try { + // For some reason trying to get the inputStream from the connection + // throws an exception rather than returning null when the InputStream does not exist. + InputStream is = null; + try { + is = connection.getInputStream(); + } catch (Exception e1) { + // ignore this + } + if (is != null) { + is.close(); + } + + } catch (IOException ex) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Failed to close connection: " + ex, ex); + } + connection.disconnect(); + } + } + } + +} + + diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/admin/XacmlAdminUI.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/admin/XacmlAdminUI.java new file mode 100644 index 000000000..aec8a0ac1 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/admin/XacmlAdminUI.java @@ -0,0 +1,266 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.admin; + + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebInitParam; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; + + +import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.api.errors.GitAPIException; +import org.eclipse.jgit.lib.Repository; +import org.eclipse.jgit.lib.StoredConfig; +import org.eclipse.jgit.storage.file.FileRepositoryBuilder; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.openecomp.policy.rest.XACMLRest; +import org.openecomp.policy.rest.XACMLRestProperties; +import org.openecomp.policy.rest.dao.UserInfoDao; +import org.openecomp.policy.rest.jpa.UserInfo; +import org.openecomp.policy.rest.util.Webapps; +import org.openecomp.policy.xacml.api.pap.PAPPolicyEngine; +import org.springframework.beans.factory.annotation.Autowired; + +import com.att.research.xacml.util.XACMLProperties; +import com.google.common.base.Splitter; + + + +public class XacmlAdminUI extends HttpServlet implements PAPNotificationBroadcaster.PAPNotificationBroadcastListener{ + + private static final long serialVersionUID = 1L; + // + // The PAP Engine + // + private PAPPolicyEngine papEngine; + private static Path repositoryPath; + private static Repository repository; + + @Autowired + UserInfoDao userInfoDao; + + @Autowired + SessionFactory sessionfactory; + + @WebServlet(value = "/policy#/*", description = "XACML Admin Console", asyncSupported = true, loadOnStartup = 1, initParams = { @WebInitParam(name = "XACML_PROPERTIES_NAME", value = "xacml.admin.properties", description = "The location of the properties file holding configuration information.") }) + public static class Servlet extends HttpServlet { + private static final long serialVersionUID = -5274600248961852835L; + + @Override + public void init(ServletConfig servletConfig) throws ServletException { + super.init(servletConfig); + // + // Common initialization + // + XACMLRest.xacmlInit(servletConfig); + // + // Initialize GIT repository. + // + XacmlAdminUI.initializeGitRepository(); + // + // Read the Props + // The webapps Action and Config are read when getActionHome or getConfigHome are called + try { + getConfigHome(); + } catch (Exception e) { + throw new ServletException(e); + } + + } + + + @Override + public void destroy() { + if (XacmlAdminUI.repository != null) { + XacmlAdminUI.repository.close(); + } + super.destroy(); + } + } + + private static void initializeGitRepository() throws ServletException { + + try { + XacmlAdminUI.repositoryPath = Paths.get(XACMLProperties.getProperty(XACMLRestProperties.PROP_ADMIN_REPOSITORY)); + } catch (Exception e) { + XACMLProperties.reloadProperties(); + XacmlAdminUI.repositoryPath = Paths.get(XACMLProperties.getProperty(XACMLRestProperties.PROP_ADMIN_REPOSITORY)); + } + FileRepositoryBuilder builder = new FileRepositoryBuilder(); + try { + XacmlAdminUI.repository = builder.setGitDir(XacmlAdminUI.repositoryPath.toFile()).readEnvironment().findGitDir().setBare().build(); + if (Files.notExists(XacmlAdminUI.repositoryPath)|| Files.notExists(Paths.get(XacmlAdminUI.repositoryPath.toString(), "HEAD"))) { + // + // Create it if it doesn't exist. As a bare repository + XacmlAdminUI.repository.create(); + // + // Add the magic file so remote works. + // + Path daemon = Paths.get(XacmlAdminUI.repositoryPath.toString(), "git-daemon-export-ok"); + Files.createFile(daemon); + } + } catch (IOException e) { + throw new ServletException(e.getMessage(), e.getCause()); + } + // + // Make sure the workspace directory is created + // + Path workspace = Paths.get(XACMLProperties.getProperty(XACMLRestProperties.PROP_ADMIN_WORKSPACE)); + workspace = workspace.toAbsolutePath(); + if (Files.notExists(workspace)) { + try { + Files.createDirectory(workspace); + } catch (IOException e) { + throw new ServletException(e.getMessage(), e.getCause()); + } + } + // + // Create the user workspace directory + // + workspace = Paths.get(workspace.toString(), "admin"); + + if (Files.notExists(workspace)) { + try { + Files.createDirectory(workspace); + } catch (IOException e) { + throw new ServletException(e.getMessage(), e.getCause()); + } + } + // + // Get the path to where the repository is going to be + // + Path gitPath = Paths.get(workspace.toString(), XacmlAdminUI.repositoryPath.getFileName().toString()); + if (Files.notExists(gitPath)) { + try { + Files.createDirectory(gitPath); + } catch (IOException e) { + throw new ServletException(e.getMessage(), e.getCause()); + } + } + // + // Initialize the domain structure + // + String base = null; + String domain = XacmlAdminUI.getDomain(); + if (domain != null) { + for (String part : Splitter.on(':').trimResults().split(domain)) { + if (base == null) { + base = part; + } + Path subdir = Paths.get(gitPath.toString(), part); + if (Files.notExists(subdir)) { + try { + Files.createDirectory(subdir); + Files.createFile(Paths.get(subdir.toString(), ".svnignore")); + } catch (IOException e) { + throw new ServletException(e.getMessage(), e.getCause()); + } + } + } + } else { + try { + Files.createFile(Paths.get(workspace.toString(), ".svnignore")); + base = ".svnignore"; + } catch (IOException e) { + throw new ServletException(e.getMessage(), e.getCause()); + } + } + try { + // + // These are the sequence of commands that must be done initially to + // finish setting up the remote bare repository. + // + Git git = Git.init().setDirectory(gitPath.toFile()).setBare(false).call(); + git.add().addFilepattern(base).call(); + git.commit().setMessage("Initialize Bare Repository").call(); + StoredConfig config = git.getRepository().getConfig(); + config.setString("remote", "origin", "url", XacmlAdminUI.repositoryPath.toAbsolutePath().toString()); + config.setString("remote", "origin", "fetch", "+refs/heads/*:refs/remotes/origin/*"); + config.save(); + git.push().setRemote("origin").add("master").call(); + /* + * This will not work unless + * git.push().setRemote("origin").add("master").call(); is called + * first. Otherwise it throws an exception. However, if the push() + * is called then calling this function seems to add nothing. + * + * git.branchCreate().setName("master") + * .setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM) + * .setStartPoint("origin/master").setForce(true).call(); + */ + } catch (GitAPIException | IOException e) { + throw new ServletException(e.getMessage(), e.getCause()); + } + } + + public UserInfo getUserNameFromUserInfoTable(String createdBy){ + String loginId = createdBy; + Object user = null; + Session session = sessionfactory.openSession(); + user = session.load(UserInfo.class, loginId); + return (UserInfo) user; + } + + @Override + public void updateAllGroups() { + + } + + public PAPPolicyEngine getPapEngine() { + return papEngine; + } + + public void setPapEngine(PAPPolicyEngine papEngine) { + this.papEngine = papEngine; + } + + public static String getConfigHome() { + return Webapps.getConfigHome(); + } + + public static String getDomain() { + return XACMLProperties.getProperty(XACMLRestProperties.PROP_ADMIN_DOMAIN, "urn"); + } + + // get the repository path from property file + public static Path getRepositoryPath() { + if(repositoryPath == null){ + try { + initializeGitRepository(); + } catch (ServletException e) { + + } + } + return repositoryPath; + } + + +} + diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/components/ElasticSearchComponent.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/components/ElasticSearchComponent.java new file mode 100644 index 000000000..35a4d14b8 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/components/ElasticSearchComponent.java @@ -0,0 +1,426 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.components; + + +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.regex.Pattern; + +import org.openecomp.policy.dao.PolicyVersionDao; +import org.openecomp.policy.elk.client.ElkConnector; +import org.openecomp.policy.elk.client.ElkConnector.PolicyIndexType; +import org.openecomp.policy.rest.dao.DescriptiveScopeDao; +import org.openecomp.policy.rest.jpa.DescriptiveScope; +import org.openecomp.policy.rest.jpa.PolicyVersion; +import org.openecomp.policy.elk.client.Pair; +import org.openecomp.policy.elk.client.PolicyLocator; +import org.springframework.beans.factory.annotation.Autowired; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + + +public class ElasticSearchComponent { + private static final Logger logger = FlexLogger.getLogger(ElasticSearchComponent.class); + + + private static PolicyVersionDao policyVersionDao; + private static DescriptiveScopeDao descriptiveScopeDao; + + @Autowired + public ElasticSearchComponent(PolicyVersionDao policyVersionDao){ + ElasticSearchComponent.policyVersionDao = policyVersionDao; + } + + @Autowired + public ElasticSearchComponent(DescriptiveScopeDao descriptiveScopeDao){ + ElasticSearchComponent.descriptiveScopeDao = descriptiveScopeDao; + } + + + private volatile static HashMap filteredPolicies = new HashMap(); + + public static final HashMap name2jsonPath = new HashMap() { + private static final long serialVersionUID = 1L; + { + put(CLFAULT_UIFIELD_D2_SERVICES_TRINITY, CLFAULT_UIJSON_D2_SERVICES_TRINITY); + put(CLFAULT_UIFIELD_D2_SERVICES_VUSP, CLFAULT_UIJSON_D2_SERVICES_VUSP); + put(CLFAULT_UIFIELD_D2_SERVICES_MCR, CLFAULT_UIJSON_D2_SERVICES_MCR); + put(CLFAULT_UIFIELD_D2_SERVICES_GAMMA, CLFAULT_UIJSON_D2_SERVICES_GAMMA); + put(CLFAULT_UIFIELD_D2_SERVICES_VDNS, CLFAULT_UIJSON_D2_SERVICES_VDNS); + + put(CLFAULT_UIFIELD_EMAIL_ADDRESS, CLFAULT_UIJSON_EMAIL_ADDRESS); + put(CLFAULT_UIFIELD_TRIGGER_SIGNATURE, CLFAULT_UIJSON_TRIGGER_SIGNATURE); + put(CLFAULT_UIFIELD_VERIFICATION_SIGNATURE, CLFAULT_UIJSON_VERIFICATION_SIGNATURE); + put(CLFAULT_UIFIELD_CONNECT_ALL_TRAPS, CLFAULT_UIJSON_CONNECT_ALL_TRAPS); + put(CLFAULT_UIFIELD_CONNECT_ALL_FAULTS, CLFAULT_UIJSON_CONNECT_ALL_FAULTS); + + put(CLFAULT_UIFIELD_POLICY_STATUS_INACTIVE, CLFAULT_UIJSON_POLICY_STATUS_ACTIVE); + put(CLFAULT_UIFIELD_POLICY_STATUS_ACTIVE, CLFAULT_UIJSON_POLICY_STATUS_INACTIVE); + + put(CLPM_UIFIELD_ONSET_MESSAGE, CLPM_UIJSON_ONSET_MESSAGE); + put(CLPM_UIFIELD_POLICY_NAME, CLPM_UIJSON_POLICY_NAME); + put(CLPM_UIFIELD_ABATEMENT_MESSAGE, CLPM_UIJSON_ABATEMENT_MESSAGE); + put(CLPM_UIFIELD_GEOLINK, CLPM_UIJSON_GEOLINK); + }}; + + //For AND and OR logical connector AND=0 and OR=1 + private static int connectorSelected; + + public static final String CLFAULT_UIFIELD_D2_SERVICES_TRINITY = "Hosted Voice (Trinity)"; + public static final String CLFAULT_UIJSON_D2_SERVICES_TRINITY = "trinity"; + + public static final String CLFAULT_UIFIELD_D2_SERVICES_VUSP = "vUSP"; + public static final String CLFAULT_UIJSON_D2_SERVICES_VUSP = "vUSP"; + + public static final String CLFAULT_UIFIELD_D2_SERVICES_MCR = "MCR"; + public static final String CLFAULT_UIJSON_D2_SERVICES_MCR = "mcr"; + + public static final String CLFAULT_UIFIELD_D2_SERVICES_GAMMA = "Gamma"; + public static final String CLFAULT_UIJSON_D2_SERVICES_GAMMA = "gama"; + + public static final String CLFAULT_UIFIELD_D2_SERVICES_VDNS = "vDNS"; + public static final String CLFAULT_UIJSON_D2_SERVICES_VDNS = "vDNS"; + + public static final String CLFAULT_UIFIELD_EMAIL_ADDRESS = "Email Address"; + public static final String CLFAULT_UIJSON_EMAIL_ADDRESS = "emailAddress"; + + public static final String CLFAULT_UIFIELD_TRIGGER_SIGNATURE = "Trigger Signature"; + public static final String CLFAULT_UIJSON_TRIGGER_SIGNATURE = "triggerSignaturesUsedForUI.signatures"; + + public static final String CLFAULT_UIFIELD_VERIFICATION_SIGNATURE = "Verification Signature"; + public static final String CLFAULT_UIJSON_VERIFICATION_SIGNATURE = "verificationSignaturesUsedForUI.signatures"; + + public static final String CLFAULT_UIFIELD_CONNECT_ALL_TRAPS = "Connect All Traps"; + public static final String CLFAULT_UIJSON_CONNECT_ALL_TRAPS = "triggerSignaturesUsedForUI.connectSignatures"; + + public static final String CLFAULT_UIFIELD_CONNECT_ALL_FAULTS = "Connect All Faults"; + public static final String CLFAULT_UIJSON_CONNECT_ALL_FAULTS = "verificationSignaturesUsedForUI.connectSignatures"; + + public static final String CLFAULT_UIFIELD_POLICY_STATUS_ACTIVE = "Active"; + public static final String CLFAULT_UIJSON_POLICY_STATUS_ACTIVE = "ACTIVE"; + + public static final String CLFAULT_UIFIELD_POLICY_STATUS_INACTIVE = "InActive"; + public static final String CLFAULT_UIJSON_POLICY_STATUS_INACTIVE = "INACTIVE"; + + + public static final String CLPM_UIFIELD_ONSET_MESSAGE = "Onset Message"; + public static final String CLPM_UIJSON_ONSET_MESSAGE = "attributes.OnsetMessage"; + + public static final String CLPM_UIFIELD_POLICY_NAME = "PolicyName"; + public static final String CLPM_UIJSON_POLICY_NAME = "attributes.PolicyName"; + + public static final String CLPM_UIFIELD_ABATEMENT_MESSAGE = "Abatement Message"; + public static final String CLPM_UIJSON_ABATEMENT_MESSAGE = "attributes.AbatementMessage"; + + public static final String CLPM_UIFIELD_GEOLINK = "Geo Link"; + public static final String CLPM_UIJSON_GEOLINK = "geoLink"; + + public static void search(String value){ + String policyType = "all";//(String) self.searchPolicyType.getValue() + + ArrayList,ArrayList>> filter_s = new ArrayList,ArrayList>>(); + + String searchText = "";//self.searchTextBox.getValue() + if (searchText == null || searchText.isEmpty()) { + if (policyType == null || policyType.isEmpty() && + !policyType.equals(ElkConnector.PolicyIndexType.closedloop.toString())) { + if (logger.isDebugEnabled()) { + logger.debug("Clearing search filters, nothing to search and not closed loop."); + } + return; + } + } else { + searchText = searchText.trim(); + //Descriptive Scope. + /* + When a item is selected in the "descriptiveScope" comboBox, the name of the item + is added to the Search-Text Box with the prefix "Descriptive-Scope" + User needs to press the "Search" button to perform the search. + */ + if(searchText.contains("Descriptive-Scope=")) + { + if (logger.isDebugEnabled()) { + logger.debug("Inside the Descriptive Scope"); + } + /* + First item is always String "Descriptive-Scope" before the "=", + So taking the second item of "split using =" + */ + String[] dsName= searchText.split("=",2); + /* + Trying to find the search String by traversing different items from the dictionary by Scope-Name + Once when the the "scope-name" is found, we get the search string from dictionary. + */ + for (int i = 0; i < descriptiveScopeDao.getDescriptiveScope().size(); i++) { + DescriptiveScope dsSearch=descriptiveScopeDao.getDescriptiveScope().get(i); + if(dsSearch.getScopeName().equals(dsName[1])){ + searchText=dsSearch.getSearch(); + if (logger.isDebugEnabled()) { + logger.debug("DescriptiveScope Search String is " +searchText ); + } + } + } + } + + if(searchText.contains(":")) + { + String connector="&"; + + if(searchText.contains("&")) + { + connector="&"; + connectorSelected=0; + } + else if(searchText.contains("|")) + { + connector=Pattern.quote("|"); + connectorSelected=1; + } + for (String retval: searchText.split(connector)){ + + int index= retval.indexOf(':'); + String filterKey=null; + String filterValue=null; + + filterKey=retval.substring(0,index); + filterValue= retval.substring(index+1); + + String clSearchBoxFilter=filterKey; + + ArrayList clSearchBoxFilterField_s = new ArrayList(); + + clSearchBoxFilterField_s.add("Policy.Body." + ElkConnector.PolicyType.Config_Fault.name() + "_Body." + clSearchBoxFilter); + clSearchBoxFilterField_s.add("Policy.Body." + ElkConnector.PolicyType.Config_PM.name() + "_Body." + clSearchBoxFilter); + clSearchBoxFilterField_s.add("Policy.Body." + ElkConnector.PolicyType.Config_FW.name() + "_Body." + clSearchBoxFilter); + clSearchBoxFilterField_s.add("Policy.Body." + ElkConnector.PolicyType.Config_MS.name() + "_Body." + clSearchBoxFilter); + + + ArrayList clSearchBoxFilterValue_s = new ArrayList(); + clSearchBoxFilterValue_s.add(filterValue); + + filter_s.add(new Pair,ArrayList>(clSearchBoxFilterField_s, clSearchBoxFilterValue_s)); + } + } + } + + if (policyType != null && !policyType.isEmpty() && + policyType.equals(ElkConnector.PolicyIndexType.closedloop.toString())) { + + /* closed loop policy type */ + + String clPolicyType = "";//(String) self.cbSearchCLPolicyType.getValue() + if (clPolicyType != null && !clPolicyType.isEmpty()) { + ArrayList clPolicyTypeField_s = new ArrayList(); + clPolicyTypeField_s.add("Policy.PolicyType"); + + ArrayList clPolicyTypeValue_s = new ArrayList(); + clPolicyTypeValue_s.add(clPolicyType); + + filter_s.add(new Pair,ArrayList>(clPolicyTypeField_s, clPolicyTypeValue_s)); + } + + String clEcompName = "";//(String) self.cbSearchCLEcompName.getValue() + if (clEcompName != null && !clEcompName.isEmpty()) { + clSearchBody(clPolicyType, "ecompname", clEcompName, filter_s); + } + + String clD2Services = "";//(String) self.cbSearchCLD2Services.getValue() + if (clD2Services != null && !clD2Services.isEmpty()) { + switch (clD2Services) { + case CLFAULT_UIFIELD_D2_SERVICES_TRINITY: + case CLFAULT_UIFIELD_D2_SERVICES_VUSP: + case CLFAULT_UIFIELD_D2_SERVICES_MCR: + case CLFAULT_UIFIELD_D2_SERVICES_GAMMA: + case CLFAULT_UIFIELD_D2_SERVICES_VDNS: + clSearchBody(clPolicyType, name2jsonPath.get(clD2Services), "true", filter_s); + break; + default: + if (logger.isWarnEnabled()) + logger.warn("Unexpected D2 Service: " + clD2Services); + break; + } + } + + String clFaultAction = "";//(String) self.cbSearchCLFaultAction.getValue() + if (clFaultAction != null && !clFaultAction.isEmpty()) { + if (clPolicyType == null || clPolicyType.equals(ElkConnector.PolicyType.Config_Fault.name())) { + clSearchFilter(ElkConnector.PolicyType.Config_Fault.name(), "actions", clFaultAction, filter_s); + } + } + + String clFaultStatus = "";//(String) self.cbSearchCLFaultStatus.getValue() + if (clFaultStatus != null && !clFaultStatus.isEmpty()) { + if (clPolicyType == null || clPolicyType.equals(ElkConnector.PolicyType.Config_Fault.name())) { + clSearchFilter(ElkConnector.PolicyType.Config_Fault.name(), "closedLoopPolicyStatus", clFaultStatus, filter_s); + } + } + + String clFaultVnfTypes = "";//(String) self.cbSearchCLFaultVnfTypes.getValue() + if (clFaultVnfTypes != null && !clFaultVnfTypes.isEmpty()) { + if (clPolicyType == null || clPolicyType.equals(ElkConnector.PolicyType.Config_Fault.name())) { + clSearchFilter(ElkConnector.PolicyType.Config_Fault.name(), "vnfType", clFaultVnfTypes, filter_s); + } + } + + String clPMServiceType = "";//(String) self.cbSearchCLPMServiceType.getValue() + if (clPMServiceType != null && !clPMServiceType.isEmpty()) { + if (clPolicyType == null || clPolicyType.equals(ElkConnector.PolicyType.Config_PM.name())) { + clSearchFilter(ElkConnector.PolicyType.Config_PM.name(), "serviceTypePolicyName", clPMServiceType, filter_s); + } + } + + String clSearchBoxFilter = "";//(String) self.cbSearchCLTextFilter.getValue() + if (clSearchBoxFilter != null && !clSearchBoxFilter.isEmpty() && + searchText != null && !searchText.isEmpty()) { + + if (name2jsonPath.containsKey(clSearchBoxFilter)) { + clSearchBoxFilter = name2jsonPath.get(clSearchBoxFilter); + } + + ArrayList clSearchBoxFilterField_s = new ArrayList(); + if (clPolicyType == null || clPolicyType.isEmpty()) { + clSearchBoxFilterField_s.add("Policy.Body." + ElkConnector.PolicyType.Config_Fault.name() + "_Body." + clSearchBoxFilter); + clSearchBoxFilterField_s.add("Policy.Body." + ElkConnector.PolicyType.Config_PM.name() + "_Body." + clSearchBoxFilter); + } else { + clSearchBoxFilterField_s.add("Policy.Body." + clPolicyType + "_Body." + clSearchBoxFilter); + } + + ArrayList clSearchBoxFilterValue_s = new ArrayList(); + clSearchBoxFilterValue_s.add(searchText); + + filter_s.add(new Pair,ArrayList>(clSearchBoxFilterField_s, clSearchBoxFilterValue_s)); + + // deactivate search all fields in case a searchbox filter is provided + searchText = ""; + } + } + + if ((searchText == null || searchText.isEmpty()) && + (filter_s == null || filter_s.size() <=0) ) { + if (logger.isWarnEnabled()) { + logger.warn("Clearing search filters, closed loop but nothing to search nor filters"); + } + + return; + } + + ArrayList locators; + try { + locators = ElkConnector.singleton.policyLocators(toPolicyIndexType(policyType), + searchText, filter_s,connectorSelected); + } catch (Exception ise) { + /*AdminNotification.warn("Search is unavailable: " + ise.getMessage());*/ + return; + } + + synchronized(filteredPolicies) { + if (locators.isEmpty()) { + if (logger.isInfoEnabled()) { + logger.info("No match has been found"); + } + //AdminNotification.warn("No match has been found"); + return; + } + + // Retrieve active versions + + HashMap policyVersion_s = new HashMap(); + for(int i = 0; i < policyVersionDao.getPolicyVersionData().size(); i++) { + PolicyVersion entityVersion = policyVersionDao.getPolicyVersionData().get(i); + String dbPolicy = entityVersion.getPolicyName() + "." + entityVersion.getActiveVersion(); + policyVersion_s.put(dbPolicy, true); + if (logger.isDebugEnabled()) + logger.debug("Map addition: DB Policy Name: " + dbPolicy); + } + + filteredPolicies.clear(); + for (PolicyLocator p: locators) { + String dbPolicyName = p.scope + "/" + p.policyType + "_" + p.policyName; + if (policyVersion_s.containsKey(dbPolicyName)) { + String filterPolicyName = dbPolicyName + ".xml"; + filteredPolicies.put(Paths.get(filterPolicyName), filterPolicyName); + if (logger.isInfoEnabled()) + logger.info("Active Version Policy found in search: " + + dbPolicyName + " -> " + filterPolicyName); + } else { + if (logger.isInfoEnabled()) + logger.info("Inactive Version Policy found in search: " + dbPolicyName); + } + } + + if (filteredPolicies.isEmpty()) { + if (logger.isInfoEnabled()) { + logger.info("No match has been found for active versions"); + } + //AdminNotification.warn("No match has been found for active versions"); + return; + } + + //self.policyContainer.setFilter(self.filteredPolicies); + } + /* self.policyContainer.refresh();*/ + } + + + protected static void clSearchBody(String clPolicyType, String bodyField, String bodyValue, + ArrayList, ArrayList>> filter_s) { + if (logger.isDebugEnabled()) + logger.debug("ENTER: " + clPolicyType + ":" + bodyField + ":" + bodyValue); + + final ArrayList clBodyField_s = new ArrayList(); + final ArrayList clBodyValue_s = new ArrayList(); + + if (clPolicyType == null || clPolicyType.isEmpty()) { + clBodyField_s.add("Policy.Body." + ElkConnector.PolicyType.Config_Fault.name() + "_Body." + bodyField); + clBodyField_s.add("Policy.Body."+ ElkConnector.PolicyType.Config_PM.name() + "_Body." + bodyField); + clBodyValue_s.add(bodyValue); + } else { + clBodyField_s.add("Policy.Body." + clPolicyType + "_Body." + bodyField); + clBodyValue_s.add(bodyValue); + } + filter_s.add(new Pair, ArrayList>(clBodyField_s, clBodyValue_s)); + } + + protected static void clSearchFilter(String clType, String clField, String clValue, + ArrayList,ArrayList>> filter_s) { + if (logger.isDebugEnabled()) + logger.debug("ENTER: " + clType + ":" + clField + ":" + clValue); + + ArrayList clSearchField_s = new ArrayList(); + clSearchField_s.add("Policy.Body." + clType + "_Body." + clField); + + ArrayList clSearchValue_s = new ArrayList(); + clSearchValue_s.add(clValue); + + filter_s.add(new Pair,ArrayList>(clSearchField_s, clSearchValue_s)); + } + + public static ElkConnector.PolicyIndexType toPolicyIndexType(String type) throws IllegalArgumentException { + if (type == null || type.isEmpty()) + return PolicyIndexType.all; + + return PolicyIndexType.valueOf(type); + } +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/components/HumanPolicyComponent.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/components/HumanPolicyComponent.java new file mode 100644 index 000000000..037888b7c --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/components/HumanPolicyComponent.java @@ -0,0 +1,982 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.components; + + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.nio.file.FileSystems; +import java.nio.file.Path; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import javax.xml.bind.JAXBElement; + +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionsType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.ApplyType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeAssignmentExpressionType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeSelectorType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.ConditionType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObligationExpressionType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObligationExpressionsType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicySetType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.RuleType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.VariableReferenceType; + +import org.apache.commons.io.FilenameUtils; +import org.json.JSONObject; +import org.openecomp.policy.controller.PolicyController; +import org.openecomp.policy.rest.jpa.FunctionDefinition; +import org.openecomp.policy.utils.XACMLPolicyWriterWithPapNotify; + +import com.att.research.xacml.api.AttributeValue; +import org.openecomp.policy.xacml.api.XACMLErrorConstants; +import com.att.research.xacml.std.IdentifierImpl; +import com.att.research.xacml.std.StdAttribute; +import com.att.research.xacml.std.StdAttributeValue; +import org.openecomp.policy.xacml.util.XACMLPolicyScanner; +import com.att.research.xacml.util.XACMLPolicyScanner.CallbackResult; +import com.att.research.xacml.util.XACMLPolicyScanner.SimpleCallback; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + + + +public class HumanPolicyComponent{ + + private static final Logger logger = FlexLogger.getLogger(HumanPolicyComponent.class); + + // Constants Used in XML Creation + public static final String CATEGORY_RECIPIENT_SUBJECT = "urn:oasis:names:tc:xacml:1.0:subject-category:recipient-subject"; + public static final String CATEGORY_RESOURCE = "urn:oasis:names:tc:xacml:3.0:attribute-category:resource"; + public static final String CATEGORY_ACTION = "urn:oasis:names:tc:xacml:3.0:attribute-category:action"; + public static final String CATEGORY_ACCESS_SUBJECT = "urn:oasis:names:tc:xacml:1.0:subject-category:access-subject"; + public static final String ACTION_ID = "urn:oasis:names:tc:xacml:1.0:action:action-id"; + public static final String SUBJECT_ID = "urn:oasis:names:tc:xacml:1.0:subject:subject-id"; + public static final String RESOURCE_ID = "urn:oasis:names:tc:xacml:1.0:resource:resource-id"; + public static final String FUNTION_INTEGER_ONE_AND_ONLY = "urn:oasis:names:tc:xacml:1.0:function:integer-one-and-only"; + public static final String FUNCTION_STRING_ONE_AND_ONLY = "urn:oasis:names:tc:xacml:1.0:function:string-one-and-only"; + public static final String FUNCTION_STRING_EQUAL = "urn:oasis:names:tc:xacml:1.0:function:string-equal"; + public static final String FUNCTION_STRING_REGEX_MATCH = "org.openecomp.function.regex-match"; + public static final String FUNCTION_STRING_EQUAL_IGNORE = "urn:oasis:names:tc:xacml:3.0:function:string-equal-ignore-case"; + public static final String INTEGER_DATATYPE = "http://www.w3.org/2001/XMLSchema#integer"; + public static final String BOOLEAN_DATATYPE = "http://www.w3.org/2001/XMLSchema#boolean"; + public static final String STRING_DATATYPE = "http://www.w3.org/2001/XMLSchema#string"; + public static final String URI_DATATYPE = "http://www.w3.org/2001/XMLSchema#anyURI"; + public static final String RULE_VARIABLE = "var:"; + public static final String EMPTY_STRING = ""; + + private static HtmlProcessor htmlProcessor; + + private static File policyFile; + + public static JSONObject DescribePolicy(final File policyFile) { + if (logger.isTraceEnabled()) + logger.trace("ENTER"); + + HumanPolicyComponent.policyFile = policyFile; + return humanPolicyLayout(); + + } + + private static JSONObject humanPolicyLayout() { + if (logger.isTraceEnabled()) + logger.trace("ENTER"); + + try { + String html = processPolicy(); + JSONObject result = new JSONObject(); + result.put("html", html); + return result; + //ByteArrayInputStream is = new ByteArrayInputStream(html.getBytes(StandardCharsets.UTF_8)); + + } catch (IllegalArgumentException e) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "cannot build html area por policy", e); + /*AdminNotification.warn("An error has occurred. Cannot describe this policy: " + + e.getMessage());*/ + } + return null; + } + + private static String processPolicy() throws IllegalArgumentException { + if (logger.isTraceEnabled()) + logger.trace("ENTER"); + + FileInputStream pIS = null; + try { + pIS = new FileInputStream(policyFile); + Object policy = XACMLPolicyScanner.readPolicy(pIS); + if (policy == null) + throw new IllegalArgumentException("Policy File " + policyFile.getName() + + " cannot be unmarshalled"); + + HumanPolicyComponent.htmlProcessor = + new HtmlProcessor(HumanPolicyComponent.policyFile, policy); + + Path policyPath = FileSystems.getDefault().getPath(policyFile.getAbsolutePath()); + XACMLPolicyScanner xacmlScanner = new XACMLPolicyScanner(policyPath, htmlProcessor); + xacmlScanner.scan(); + String html = htmlProcessor.html(); + if (logger.isDebugEnabled()) + logger.debug(policyPath + System.lineSeparator() + html); + + return html; + + } catch (Exception e) { + String msg = "Exception reading policy: " + policyFile.getAbsolutePath() + + ": " + e.getMessage(); + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + msg, e); + throw new IllegalArgumentException(msg); + } finally { + if (pIS != null) { + try { + pIS.close(); + } catch (IOException e) { + logger.warn(e.getMessage(), e); + } + } + } + } + +} + +class HtmlProcessor extends SimpleCallback { + + private static final Logger logger = FlexLogger.getLogger(HtmlProcessor.class); + + private static Map function2human; + static { + function2human = new HashMap(); + function2human.put(HumanPolicyComponent.FUNCTION_STRING_EQUAL, "equal"); + function2human.put(HumanPolicyComponent.FUNCTION_STRING_EQUAL_IGNORE, "equal"); + function2human.put(HumanPolicyComponent.FUNCTION_STRING_ONE_AND_ONLY, "one-and-only"); + function2human.put(HumanPolicyComponent.FUNCTION_STRING_REGEX_MATCH, "matching regular expression"); + function2human.put(HumanPolicyComponent.FUNTION_INTEGER_ONE_AND_ONLY, "one-and-only"); + } + + private static Map combiningAlgo2human; + static { + combiningAlgo2human = new HashMap(); + combiningAlgo2human.put("deny-overrides", "to deny if any $placeholder$ below evaluates to deny"); + combiningAlgo2human.put("permit-overrides", "to permit if any $placeholder$ below evaluates to permit"); + + combiningAlgo2human.put("ordered-deny-overrides", "to deny if any $placeholder$ below evaluates to deny"); + combiningAlgo2human.put("ordered-permit-overrides", "to permit if any $placeholder$ below evaluates to permit"); + combiningAlgo2human.put("deny-unless-permit", "to permit if any $placeholder$ below evaluates to deny and not indeterminate"); + + combiningAlgo2human.put("permit-unless-deny", "to deny if any $placeholder$ below evaluates to is permit and not indeterminate"); + combiningAlgo2human.put("first-applicable", "to honour the result of the first successfully evaluated $placeholder$ in order"); + combiningAlgo2human.put("only-one-applicable", "to honour the result of the first successfully evaluated $placeholder$ in order"); + } + + private Map attributeIdentifiersMap = new HashMap(); + + private final StringWriter stringWriter = new StringWriter(); + private final PrintWriter htmlOut = new PrintWriter(stringWriter); + private final String policyName; + private final Object rootPolicyObject; + + public HtmlProcessor(File policyFile, Object policyObject) + throws IllegalArgumentException { + if (logger.isTraceEnabled()) + logger.trace("ENTER"); + + if (policyFile == null) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Null Policy File"); + throw new IllegalArgumentException("Null Policy File"); + } + + if (!policyFile.exists() || !policyFile.canRead()) { + String msg = "Can't access " + policyFile.getAbsolutePath(); + logger.error(XACMLErrorConstants.ERROR_PERMISSIONS + msg); + throw new IllegalArgumentException(msg); + } + + if (policyObject == null || + (!(policyObject instanceof PolicySetType) && !(policyObject instanceof PolicyType))) { + String msg = "Invalid unmarshalled object: " + policyObject; + logger.error(XACMLErrorConstants.ERROR_SCHEMA_INVALID + msg); + throw new IllegalArgumentException(msg); + } + + this.policyName = FilenameUtils.removeExtension(policyFile.getName()); + this.rootPolicyObject = policyObject; + + String version = "-"; + if (policyObject instanceof PolicyType) { + PolicyType policy = (PolicyType) policyObject; + version = policy.getVersion(); + htmlOut.println("

Policy: " + policyName + + " (version " + version + ")

"); + + } else { + PolicySetType policySet = (PolicySetType) policyObject; + version = policySet.getVersion(); + htmlOut.println("

Policy Set: " + policyName + + " (v" + version + ")

"); + } + + htmlOut.println("

Location: " + policyFile.getPath() + "

"); + htmlOut.println("
"); + + if (rootPolicyObject instanceof PolicySetType) { + if (policyName.startsWith("Config_")) { + htmlOut.println("

This is a config policy set.

"); + } else if (policyName.startsWith("Action_")) { + htmlOut.println("

This is an action policy set.

"); + } + htmlOut.println("
"); + } else { + if (policyName.startsWith("Config_")) { + htmlOut.println("

This is a config policy.

"); + } else if (policyName.startsWith("Action_")) { + htmlOut.println("

This is an action policy.

"); + } + htmlOut.println("
    "); + } + } + + /** + * @return the attributeIdentifiersMap + */ + public Map getAttributeIdentifiersMap() { + return attributeIdentifiersMap; + } + + @Override + public void onFinishScan(Object root) { + if (logger.isTraceEnabled()) + logger.trace("ENTER"); + + if (rootPolicyObject instanceof PolicySetType) { + htmlOut.println("
"); + } else { + htmlOut.println(""); + } + + htmlOut.println("
"); + + htmlOut.println("

Attribute Table:

"); + + htmlOut.println(""); + htmlOut.println(""); + htmlOut.print(""); + htmlOut.print(""); + htmlOut.print(""); + htmlOut.println(""); + for(Map.Entry entry : this.attributeIdentifiersMap.entrySet()){ + AttributeIdentifiers value = entry.getValue(); + htmlOut.println(""); + htmlOut.print(""); + htmlOut.print(""); + htmlOut.print(""); + htmlOut.println(""); + } + htmlOut.println("
CategoryTypeIdentifier
" + value.category + "" + value.type + "" + value.id + "
"); + + htmlOut.println("

"); + + // Not necessary for the user, uncomment if desired at some point + // writeRawXACML() + + super.onFinishScan(root); + } + + @SuppressWarnings("unused") + private void writeRawXACML() { + if (logger.isTraceEnabled()) + logger.trace("ENTER"); + + htmlOut.println("
"); + htmlOut.println("

Raw XACML:

"); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + if (rootPolicyObject instanceof PolicySetType) { + XACMLPolicyWriterWithPapNotify.writePolicyFile(bos, (PolicySetType) rootPolicyObject); + } else if (rootPolicyObject instanceof PolicyType) { + XACMLPolicyWriterWithPapNotify.writePolicyFile(bos, (PolicyType) rootPolicyObject); + } + + String xacml = bos.toString(); + xacml = xacml.replaceAll("<", "<"); + xacml = xacml.replaceAll(">", ">"); + htmlOut.println("
");
+		htmlOut.println(xacml);
+		htmlOut.println("
"); + } + + @Override + public CallbackResult onPreVisitPolicySet(PolicySetType parent, PolicySetType policySet) { + if (logger.isTraceEnabled()) + logger.trace("PolicySet: " + policySet.getPolicySetId() + " Version: " + policySet.getVersion()); + + if (parent != null && logger.isTraceEnabled()) + logger.trace("PolicySet: " + policySet.getPolicySetId() + + "Parent PolicySet: " + parent.getPolicySetId() + " Version: " + parent.getVersion()); + + String description = policySet.getDescription(); + if (description != null && logger.isTraceEnabled()) + logger.trace("PolicySet: " + policySet.getPolicySetId() + + " Description: " + policySet.getDescription()); + + if (parent == null) // root + policySet(policySet, "dl"); + else + policySet(policySet, "li"); + + if (policySet.getPolicySetOrPolicyOrPolicySetIdReference().size() > 0) + htmlOut.println("
    "); + + return super.onPreVisitPolicySet(parent, policySet); + } + + @Override + public CallbackResult onPostVisitPolicySet(PolicySetType parent, PolicySetType policySet) { + if (logger.isTraceEnabled()) + logger.trace("PolicySet: " + policySet.getPolicySetId() + " Version: " + policySet.getVersion()); + + if (parent != null && logger.isTraceEnabled()) + logger.trace("PolicySet: " + policySet.getPolicySetId() + + "Parent PolicySet: " + parent.getPolicySetId() + " Version: " + parent.getVersion()); + + String description = policySet.getDescription(); + if (description != null && logger.isTraceEnabled()) + logger.trace("PolicySet: " + policySet.getPolicySetId() + + " Description: " + policySet.getDescription()); + + if (policySet.getPolicySetOrPolicyOrPolicySetIdReference().size() > 0) + htmlOut.println("
"); + + htmlOut.println("

"); + + return super.onPostVisitPolicySet(parent, policySet); + } + + public void policySet(PolicySetType policySet, String htmlListElement) { + if (logger.isTraceEnabled()) + logger.trace("PolicySet: " + policySet.getPolicySetId()); + + String combiningAlgorithm = "-"; + String id = "-"; + String version = "-"; + + + if (policySet.getPolicyCombiningAlgId() != null) + combiningAlgorithm = extractLastIdentifier(policySet.getPolicyCombiningAlgId(), ":"); + + if (policySet.getPolicySetId() != null) + id = extractLastIdentifier(policySet.getPolicySetId(), ":"); + + if (policySet.getVersion() != null) + version = policySet.getVersion(); + + + htmlOut.println("<" + htmlListElement + ">Policy Set ID: " + id + + " (v" + version + ") " + ""); + + if (policySet.getTarget() == null || + policySet.getTarget().getAnyOf() == null || + policySet.getTarget().getAnyOf().size() <= 0) { + htmlOut.println("

This policy set applies to all requests.

"); + } else { + htmlOut.print("

"); + htmlOut.print("This policy set applies to requests with attributes "); + + List anyOf_s = policySet.getTarget().getAnyOf(); + target(anyOf_s); + htmlOut.println(".

"); + } + + if (policySet.getPolicySetOrPolicyOrPolicySetIdReference() != null && + policySet.getPolicySetOrPolicyOrPolicySetIdReference().size() > 0) { + String algoDesc = combiningAlgo2human.get(combiningAlgorithm); + if (algoDesc != null) { + algoDesc = algoDesc.replace("$placeholder$", "policy") + " (" + "" + combiningAlgorithm + ")"; + } else { + algoDesc = combiningAlgorithm; + } + + htmlOut.println("

The result is " + algoDesc + ":

"); + } + } + + @Override + public CallbackResult onPreVisitPolicy(PolicySetType parent, PolicyType policy) { + if (logger.isTraceEnabled()) + logger.trace("PolicySet: " + policy.getPolicyId() + " Version: " + policy.getVersion()); + + if (parent != null && logger.isTraceEnabled()) + logger.trace("PolicySet: " + policy.getPolicyId() + + "Parent PolicySet: " + parent.getPolicySetId() + " Version: " + parent.getVersion()); + + String description = policy.getDescription(); + if (description != null && logger.isTraceEnabled()) + logger.trace("PolicySet: " + policy.getPolicyId() + + " Description: " + policy.getDescription()); + + policy(policy); + + if (policy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().size() > 0) + htmlOut.println("
    "); + + return super.onPreVisitPolicy(parent, policy); + } + + @Override + public CallbackResult onPostVisitPolicy(PolicySetType parent, PolicyType policy) { + if (logger.isTraceEnabled()) + logger.trace("PolicySet: " + policy.getPolicyId() + " Version: " + policy.getVersion()); + + if (parent != null && logger.isTraceEnabled()) + logger.trace("PolicySet: " + policy.getPolicyId() + + "Parent PolicySet: " + parent.getPolicySetId() + " Version: " + parent.getVersion()); + + if (policy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().size() > 0) + htmlOut.println("
"); + + htmlOut.println("

"); + return super.onPostVisitPolicy(parent, policy); + } + + public void policy(PolicyType policy) { + if (logger.isTraceEnabled()) + logger.trace("Policy: " + policy.getPolicyId()); + + String combiningAlgorithm = "-"; + String id = "-"; + String version = "-"; + + + if (policy.getRuleCombiningAlgId() != null) + combiningAlgorithm = extractLastIdentifier(policy.getRuleCombiningAlgId(), ":"); + + if (policy.getPolicyId() != null) + id = extractLastIdentifier(policy.getPolicyId(), ":"); + + if (policy.getVersion() != null) + version = policy.getVersion(); + + htmlOut.println("
  • Policy ID: " + id + + " (v" + version + ") " + "
  • "); + + if (policy.getTarget() == null || + policy.getTarget().getAnyOf() == null || + policy.getTarget().getAnyOf().size() <= 0) { + htmlOut.println("

    This policy applies to all requests.

    "); + } else { + htmlOut.print("

    "); + htmlOut.print("This policy applies to requests with attributes "); + + List anyOf_s = policy.getTarget().getAnyOf(); + target(anyOf_s); + htmlOut.println(".

    "); + } + + if (policy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition() != null && + policy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().size() > 0) { + String algoDesc = combiningAlgo2human.get(combiningAlgorithm); + if (algoDesc != null) { + algoDesc = algoDesc.replace("$placeholder$", "rule") + " (" + combiningAlgorithm + ")"; + } else { + algoDesc = combiningAlgorithm; + } + htmlOut.println("

    The result is " + algoDesc + ":

    "); + } + } + + + @Override + public CallbackResult onPreVisitRule(PolicyType parent, RuleType rule) { + if (logger.isTraceEnabled()) + logger.trace("Rule: " + rule.getRuleId()); + + if (parent != null && logger.isTraceEnabled()) + logger.trace("Parent Policy: " + parent.getPolicyId() + " Version: " + parent.getVersion()); + + String description = rule.getDescription(); + if (description != null && logger.isTraceEnabled()) { + logger.trace("Rule: " + rule.getRuleId() + + " Description: " + rule.getDescription()); + } + + rule(rule); + + return super.onPreVisitRule(parent, rule); + } + + @Override + public CallbackResult onPostVisitRule(PolicyType parent, RuleType rule) { + if (logger.isTraceEnabled()) + logger.trace("Rule: " + rule.getRuleId()); + + if (parent != null && logger.isTraceEnabled()) + logger.trace("Parent Policy: " + parent.getPolicyId() + " Version: " + parent.getVersion()); + + return super.onPostVisitRule(parent, rule); + } + + public void rule(RuleType rule) { + if (logger.isTraceEnabled()) + logger.trace("Rule: " + rule.getRuleId()); + + String id = "-"; + + if (rule.getRuleId() != null) + id = extractLastIdentifier(rule.getRuleId(), ":"); + + htmlOut.println("
  • Rule ID: " + id + "
  • "); + + htmlOut.println("
    "); + + htmlOut.print("

    "); + htmlOut.print(rule.getEffect().value()); + + if (rule.getTarget() == null || + rule.getTarget().getAnyOf() == null || + rule.getTarget().getAnyOf().size() <= 0) { + htmlOut.print(" for all requests"); + } else { + List anyOf_s = rule.getTarget().getAnyOf(); + htmlOut.print(" for requests with attributes "); + target(anyOf_s); + } + + if (rule.getCondition() != null) { + htmlOut.print(" when "); + htmlOut.println(this.stringifyCondition(rule.getCondition()) + " "); + } else { + htmlOut.print(" with no conditions "); + } + + if (rule.getAdviceExpressions() != null) { + advice(rule.getAdviceExpressions()); + if (rule.getObligationExpressions() != null) + htmlOut.println(" and "); + } + + if (rule.getObligationExpressions() != null) { + obligation(rule.getObligationExpressions()); + } + + htmlOut.println("

    "); + } + + private void advice(AdviceExpressionsType adviceExpressions) { + if (logger.isTraceEnabled()) + logger.trace("ENTER"); + + List ae = adviceExpressions.getAdviceExpression(); + for (AdviceExpressionType expression : ae) { + htmlOut.println(" with advice (" + expression.getAdviceId() + ") on " + + expression.getAppliesTo().value() + ":" ); + htmlOut.println("
      "); + List assignments = expression.getAttributeAssignmentExpression(); + if (assignments != null) { + processAttributeAssignments(assignments); + } + htmlOut.println("
    "); + } + } + + private void obligation(ObligationExpressionsType obligationExpressions) { + if (logger.isTraceEnabled()) + logger.trace("ENTER"); + + List oe = obligationExpressions.getObligationExpression(); + for (ObligationExpressionType expression : oe) { + htmlOut.println(" with obligations (" + expression.getObligationId() + ") to be fullfilled on " + + expression.getFulfillOn().value() + ":" ); + htmlOut.println("
      "); + List assignments = expression.getAttributeAssignmentExpression(); + if (assignments != null) { + processAttributeAssignments(assignments); + } + htmlOut.println("
    "); + } + } + + /** + * @param assignments + */ + private void processAttributeAssignments(List assignments) { + if (logger.isTraceEnabled()) + logger.trace("ENTER"); + + for (AttributeAssignmentExpressionType assignment : assignments) { + String succintIdentifier = extractLastIdentifier(assignment.getCategory(), ":") + + ":" + extractLastIdentifier(assignment.getAttributeId(), ":"); + AttributeIdentifiers attributeIdentifiers = null; + if (!this.attributeIdentifiersMap.containsKey(succintIdentifier)) { + // Note Attribute Assignments do not have an Attribute Type, assume string + // but note this case is unlikely since attributeMap should have been populated + // during parsing of target and conditions, and not in this case for Advice and + // Obligations. + attributeIdentifiers = new AttributeIdentifiers(assignment.getCategory(), + "NA", + assignment.getAttributeId()); + this.attributeIdentifiersMap.put(succintIdentifier, attributeIdentifiers); + } + + htmlOut.print("
  • " + succintIdentifier + " is "); + // AttributeValueType + JAXBElement jaxbExp = assignment.getExpression(); + Object assignmentObject = jaxbExp.getValue(); + if (assignmentObject instanceof AttributeValueType) { + AttributeValueType avt = (AttributeValueType) assignmentObject; + if (attributeIdentifiers != null) { + attributeIdentifiers.type = avt.getDataType(); + } + int numContent = avt.getContent().size(); + int countContent = 0; + for (Object c: avt.getContent()) { + countContent++; + htmlOut.print("" + c + ""); + if (countContent < numContent) + htmlOut.print(" or "); + } + htmlOut.println("
  • "); + } else if (assignmentObject instanceof AttributeDesignatorType) { + htmlOut.println("NA"); + } else if (assignmentObject instanceof AttributeSelectorType) { + htmlOut.println("NA"); + } else if (assignmentObject instanceof ApplyType) { + htmlOut.println("NA"); + } else { + htmlOut.println("Unexpected"); + } + } + } + + /** + * + * @param anyOfList + */ + public void target(List anyOfList) { + if (logger.isTraceEnabled()) + logger.trace("ENTER"); + + if (anyOfList != null) { + Iterator iterAnyOf = anyOfList.iterator(); + String targetInHuman = ""; + while (iterAnyOf.hasNext()) { + AnyOfType anyOf = iterAnyOf.next(); + List allOfList = anyOf.getAllOf(); + if (allOfList != null) { + Iterator iterAllOf = allOfList.iterator(); + while (iterAllOf.hasNext()) { + AllOfType allOf = iterAllOf.next(); + List matchList = allOf.getMatch(); + if (matchList != null) { + Iterator iterMatch = matchList.iterator(); + if (matchList.size() > 1) + targetInHuman += "("; + while (iterMatch.hasNext()) { + MatchType match = iterMatch.next(); + // + // Finally down to the actual attribute + // + StdAttribute attribute = null; + AttributeValueType value = match.getAttributeValue(); + String attributeDataType = null; + if (match.getAttributeDesignator() != null && value != null) { + AttributeDesignatorType designator = match.getAttributeDesignator(); + attribute = new StdAttribute(new IdentifierImpl(designator.getCategory()), + new IdentifierImpl(designator.getAttributeId()), + new StdAttributeValue>(new IdentifierImpl(value.getDataType()), value.getContent()), + designator.getIssuer(), + false); + attributeDataType = designator.getDataType(); + } else if (match.getAttributeSelector() != null && value != null) { + AttributeSelectorType selector = match.getAttributeSelector(); + attribute = new StdAttribute(new IdentifierImpl(selector.getCategory()), + new IdentifierImpl(selector.getContextSelectorId()), + new StdAttributeValue>(new IdentifierImpl(value.getDataType()), value.getContent()), + null, + false); + attributeDataType = selector.getDataType(); + } else { + logger.warn("NULL designator/selector or value for match."); + attributeDataType = "NA"; + } + + String functionName = getHumanFunction(match.getMatchId()); + + String succintIdentifier = extractLastIdentifier(attribute.getCategory().stringValue(), ":") + + ":" + extractLastIdentifier(attribute.getAttributeId().stringValue(), ":"); + AttributeIdentifiers ai = new AttributeIdentifiers(attribute.getCategory().stringValue(), + attributeDataType, + attribute.getAttributeId().stringValue()); + this.attributeIdentifiersMap.put(succintIdentifier,ai); + + targetInHuman += "" + succintIdentifier + " " + functionName + " "; + + int numAttributes = attribute.getValues().size(); + int count = 0; + for (AttributeValue v: attribute.getValues()) { + count++; + if (v.getValue() instanceof Collection) { + Collection value_s = (Collection) v.getValue(); + int numValues = value_s.size(); + int countValues = 0; + for (Object o : value_s) { + countValues++; + targetInHuman += " " + o + ""; + if (countValues < numValues) { + targetInHuman += ", or"; + } + } + } else { + targetInHuman += " " + v.getValue() + ""; + if (count < numAttributes) { + targetInHuman += ", or "; + } + } + } + + if (iterMatch.hasNext()) { + targetInHuman += " and "; + } + } // end iterMatch + if (matchList.size() > 1) { + targetInHuman += ")"; + } + } + if (iterAllOf.hasNext()) { + targetInHuman += " or "; + } + } // end iterAllOf + } + if (iterAnyOf.hasNext()) { + targetInHuman = "(" + targetInHuman + ")" + " or "; + } else { + if (anyOfList.size() > 1) { + targetInHuman += ")"; + } + } + } // end iterAnyOf + htmlOut.println(targetInHuman); + } + } + + private String getHumanFunction(String matchId) { + if (HtmlProcessor.function2human.containsKey(matchId)) { + return HtmlProcessor.function2human.get(matchId); + } + + FunctionDefinition function = PolicyController.getFunctionIDMap().get(matchId); + String functionName = function.getShortname(); + + if (logger.isDebugEnabled()) { + logger.debug(functionName + + ": #args[" + function.getArgLb() + "," + function.getArgUb() +"]"); + } + + return extractLastIdentifier(removePrimitives(functionName), ":"); + } + + public String html() { + this.htmlOut.flush(); + return this.stringWriter.toString(); + } + + private String extractLastIdentifier(String in, String separator) { + int lastIndex = in.lastIndexOf(separator); + if (lastIndex < 0) + return in; + else + return in.substring(lastIndex+1); + } + + private String removePrimitives(String in) { + in = in.replace("string-", ""); + in = in.replace("integer-", ""); + in = in.replace("double-", ""); + in = in.replace("boolean-", ""); + return in; + } + + private String stringifyCondition(ConditionType condition) { + if (condition.getExpression() == null) { + return ""; + } + + return stringifyExpression(condition.getExpression().getValue()); + } + + private String stringifyExpression(Object expression) { + if (expression instanceof ApplyType) { + ApplyType apply = (ApplyType) expression; + FunctionDefinition function = PolicyController.getFunctionIDMap().get(apply.getFunctionId()); + String functionName = function.getShortname(); + + if (logger.isDebugEnabled()) { + logger.debug(functionName + + ": #args[" + function.getArgLb() + "," + function.getArgUb() +"]"); + } + + if (functionName.contains("one-and-only")) { + if (logger.isDebugEnabled()) { + logger.debug("one-and-only found: " + functionName); + } + + List> exps = apply.getExpression(); + if (exps == null || exps.size() == 0) + return ""; + else { + String forResult = ""; + for (JAXBElement e : exps) { + Object v = e.getValue(); + if (logger.isDebugEnabled()) { + logger.debug("one-and-only children: " + v); + } + if (v != null) { + // C: return stringifyExpression(v, result); + forResult += stringifyExpression(v); + } + } + return forResult; + } + } + + final int numExpr = (apply.getExpression() == null) ? -1 : apply.getExpression().size(); + if (numExpr <= 0) { + if (logger.isDebugEnabled()) { + logger.debug(functionName + " 0 expressions: " + numExpr); + } + return ""; + } else if (numExpr == 1) { + // eg: not + if (logger.isDebugEnabled()) { + logger.debug(functionName + " 1 expression: " + numExpr); + } + String applySubresult = ""; + for (JAXBElement e : apply.getExpression()) { + Object v = e.getValue(); + if (v != null) { + applySubresult += this.stringifyExpression(e.getValue()); + } + } + return " " + removePrimitives(functionName) + " (" + applySubresult + ")"; + } else { + // > 1 arguments + if (logger.isDebugEnabled()) { + logger.debug(functionName + " > 1 expressions: " + numExpr); + } + String applySubresult = ""; + int exprCount = 0; + for (JAXBElement e : apply.getExpression()) { + exprCount++; + Object ev = e.getValue(); + if (ev != null) { + if (ev instanceof ApplyType) { + if (((ApplyType) ev).getFunctionId().contains("one-and-only")) { + applySubresult += this.stringifyExpression(e.getValue()); + } else { + applySubresult += "(" + this.stringifyExpression(e.getValue()) + ")"; + } + } else { + applySubresult += this.stringifyExpression(e.getValue()); + } + + if (exprCount < numExpr) { + applySubresult += " " + removePrimitives(functionName) + " "; + } + } + } + return applySubresult; + } + } + if (expression instanceof AttributeDesignatorType) { + AttributeDesignatorType adt = (AttributeDesignatorType) expression; + + String succintIdentifier = extractLastIdentifier(adt.getCategory(), ":") + + ":" + extractLastIdentifier(adt.getAttributeId(), ":"); + AttributeIdentifiers ai = new AttributeIdentifiers(adt.getCategory(), + adt.getDataType(), + adt.getAttributeId()); + this.attributeIdentifiersMap.put(succintIdentifier,ai); + + return "" + succintIdentifier + ""; + } + if (expression instanceof AttributeSelectorType) { + AttributeSelectorType ast = (AttributeSelectorType) expression; + + String attrName = ast.getPath(); + if (attrName == null || (attrName.length() == 0)) { + return ""; + } + + String textSelector = "/text()"; + if (attrName.endsWith(textSelector)) { + attrName = attrName.substring(0, attrName.length() - textSelector.length()); + } + + attrName = extractLastIdentifier(attrName, "/"); + attrName = extractLastIdentifier(attrName, ":"); + return " " + attrName; + } + if (expression instanceof AttributeValueType) { + AttributeValueType avt = (AttributeValueType) expression; + List content = avt.getContent(); + String value_s = ""; + for (Object o: content) { + value_s += " " + o.toString(); + } + return " " + value_s; + } + if (expression instanceof VariableReferenceType) { + // + // Really unknown - the variable may or may not have been defined + // + return " VARIABLEREF-NOT-HANDLED"; + } else { + throw new IllegalArgumentException("Unexpected input expression"); + } + } +} + + +class AttributeIdentifiers { + public final String category; + public String type; + public final String id; + + public AttributeIdentifiers(String category, String type, String id) { + this.category = category; + this.type = type; + this.id = id; + } +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/components/PolicyImportWindow.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/components/PolicyImportWindow.java new file mode 100644 index 000000000..c70e331d0 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/components/PolicyImportWindow.java @@ -0,0 +1,226 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.components; + + +/* + * + */ +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Set; + +import org.apache.commons.compress.archivers.tar.TarArchiveEntry; +import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; +import org.apache.commons.io.IOUtils; +import org.openecomp.policy.controller.PolicyController; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + + + +public class PolicyImportWindow{ + + private static final Logger logger = FlexLogger.getLogger(PolicyImportWindow.class); + private static final int BUFFER_SIZE = 4096; + private static Path directory = PolicyController.getGitPath(); + private Path newfile = null; + private boolean succeeded = false; + public static String CONFIG_HOME = PolicyController.getConfigHome(); + public static String ACTION_HOME = PolicyController.getActionHome(); + private Boolean superadmin = false; + private ArrayList xacmlFiles = new ArrayList(); + /** + * The constructor should first build the main layout, set the + * composition root and then do any custom initialization. + * + * The constructor will not be automatically regenerated by the + * visual editor. + */ + + public OutputStream receiveUpload(String filename, String mimeType) { + + // + // Create its new full path + // + this.newfile = Paths.get(PolicyImportWindow.directory.toString(), filename); + // + // Does it already exist? + // + if (Files.exists(this.newfile)) { + return null; + } + // + // Try to create the output stream + // + try { + return new FileOutputStream(this.newfile.toFile()); + } catch (FileNotFoundException e) { + logger.error("Failed to create uploaded file", e); + } + return null; + } + + public void Upload(){ + TarArchiveEntry entry = null; + TarArchiveInputStream extractFile = null; + try { + extractFile = new TarArchiveInputStream (new FileInputStream(this.newfile.toFile())); + } catch (FileNotFoundException e1) { + e1.printStackTrace(); + } + //Create a loop to read every single entry in TAR file + try { + while ((entry = extractFile.getNextTarEntry()) != null) { + this.superadmin = true; + try{ + copyFileToLocation(extractFile, entry, xacmlFiles, null, superadmin); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR+"Exception while Importing Polcies"+e); + } + } + } catch (IOException e) { + e.printStackTrace(); + } + + } + + + + + + //Copy files to Directorys + public static void copyFileToLocation(TarArchiveInputStream extractFile, TarArchiveEntry entry, ArrayList xacmlFiles, Set finalScopes, Boolean superadminValue ) throws IOException{ + String individualFiles = ""; + int offset = 0; + FileOutputStream outputFile=null; + // Get the name of the file + if(superadminValue){ + individualFiles = entry.getName(); + }else{ + for(int i =0; i< finalScopes.size(); i++){ + if(entry.getName().startsWith(finalScopes.toArray()[i].toString())){ + individualFiles = entry.getName(); + } + } + } + + if(individualFiles.endsWith(".xls")){ + if(individualFiles.contains("\\")){ + individualFiles = individualFiles.replace("\\", File.separator); + }else if(individualFiles.contains("/")){ + individualFiles = individualFiles.replace("/", File.separator); + } + return; + } + + individualFiles = individualFiles.replace("/", File.separator); + individualFiles = individualFiles.replace("\\", File.separator); + + //Create the path with the entry name + String filePath = directory.toAbsolutePath() + File.separator + individualFiles; + String configPath = CONFIG_HOME + File.separator + individualFiles; + String actionPath = ACTION_HOME + File.separator + individualFiles; + logger.info("File Name in TAR File is: " + individualFiles); + logger.info("Xml directory file path: " + filePath); + logger.info("Config Home directory file path: " + configPath); + logger.info("Action Home directory file path: " + actionPath); + + + // Get Size of the file and create a byte array for the size + byte[] content = new byte[(int) entry.getSize()]; + + offset=0; + logger.info("File Name in TAR File is: " + individualFiles); + logger.info("Size of the File is: " + entry.getSize()); + // Read file from the archive into byte array + extractFile.read(content, offset, content.length - offset); + if (!entry.isDirectory()) { + if(!individualFiles.contains(".Config_") || !individualFiles.contains(".Action_")){ + // if the entry is a file, extracts it + String filePath1 = filePath.substring(0, filePath.lastIndexOf(File.separator)); + File newFile = new File(filePath1); + if(!(newFile.exists())) { + File dir = new File(filePath1); + dir.mkdir(); + extractFile(extractFile, filePath); + } + } + } else { + // if the entry is a directory, make the director + File dir = new File(filePath); + dir.mkdir(); + } + // Define OutputStream for writing the file + if(individualFiles.contains(".Config_")){ + outputFile=new FileOutputStream(new File(configPath)); + }else if(individualFiles.contains(".Action_")){ + outputFile=new FileOutputStream(new File(actionPath)); + }else{ + if(filePath != null){ + outputFile=new FileOutputStream(new File(filePath)); + xacmlFiles.add(filePath); + } + } + + // Use IOUtiles to write content of byte array to physical file + IOUtils.write(content,outputFile); + + // Close Output Stream + try { + outputFile.close(); + } catch (IOException e) { + logger.info("IOException:" +e); + e.printStackTrace(); + } + } + + private static void extractFile(TarArchiveInputStream extractFile, String filePath) throws IOException { + BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filePath)); + byte[] bytesIn = new byte[BUFFER_SIZE]; + int read = 0; + while ((read = extractFile.read(bytesIn)) != -1) { + bos.write(bytesIn, 0, read); + } + bos.close(); + + } + + public Path getUploadedFile() { + if (this.succeeded) { + return this.newfile; + } + return null; + } + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/conf/HibernateSession.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/conf/HibernateSession.java new file mode 100644 index 000000000..b3db51df4 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/conf/HibernateSession.java @@ -0,0 +1,60 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.conf; + +/* + * + * + * */ +import java.util.Properties; + +import org.hibernate.HibernateException; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.cfg.Configuration; +import org.openecomp.policy.controller.PolicyController; +import org.openecomp.policy.rest.jpa.SystemLogDB; + +@SuppressWarnings("deprecation") +public class HibernateSession{ + + private static SessionFactory logSessionFactory; + + static { + try { + Properties prop= new Properties(); + prop.setProperty("hibernate.connection.url", PolicyController.logdbUrl); + prop.setProperty("hibernate.connection.username", PolicyController.logdbUserName); + prop.setProperty("hibernate.connection.password", PolicyController.logdbPassword); + prop.setProperty("dialect", PolicyController.logdbDialect); + prop.setProperty("hibernate.connection.driver_class", PolicyController.logdbDriver); + prop.setProperty("show_sql", "false"); + logSessionFactory = new Configuration().addPackage("org.openecomp.policy.*").addProperties(prop) + .addAnnotatedClass(SystemLogDB.class).buildSessionFactory(); + } catch (Throwable ex) { + throw new ExceptionInInitializerError(ex); + } + } + public static Session getSession() throws HibernateException { + return logSessionFactory.openSession(); + } + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/ActionPolicyController.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/ActionPolicyController.java new file mode 100644 index 000000000..0688846b4 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/ActionPolicyController.java @@ -0,0 +1,535 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.controller; + +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.xml.bind.JAXBElement; + +import org.json.JSONObject; +import org.openecomp.policy.adapter.PolicyAdapter; +import org.openecomp.policy.admin.PolicyNotificationMail; +import org.openecomp.policy.admin.RESTfulPAPEngine; +import org.openecomp.policy.dao.FunctionDefinitionDao; +import org.openecomp.policy.dao.PolicyVersionDao; +import org.openecomp.policy.dao.RuleAlgorithmsDao; +import org.openecomp.policy.dao.WatchPolicyNotificationDao; +import org.openecomp.policy.elk.client.PolicyElasticSearchController; +import org.openecomp.policy.rest.dao.ActionPolicyDictDao; +import org.openecomp.policy.rest.jpa.ActionPolicyDict; +import org.openecomp.policy.rest.jpa.PolicyVersion; +import org.openecomp.policy.rest.jpa.RuleAlgorithms; +import org.openecomp.portalsdk.core.controller.RestrictedBaseController; +import org.openecomp.portalsdk.core.web.support.JsonMessage; +import org.openecomp.portalsdk.core.web.support.UserUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + +import com.att.research.xacml.api.XACML3; +import org.openecomp.policy.xacml.api.XACMLErrorConstants; +import org.openecomp.policy.xacml.util.XACMLPolicyScanner; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.base.Joiner; + +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.ApplyType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeAssignmentExpressionType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.ConditionType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObligationExpressionType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObligationExpressionsType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.RuleType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +@Controller +@RequestMapping({"/"}) +public class ActionPolicyController extends RestrictedBaseController{ + private static final Logger logger = FlexLogger.getLogger(ActionPolicyController.class); + + private static FunctionDefinitionDao functionDefinitionDao; + private static RuleAlgorithmsDao ruleAlgorithmsDao; + private static ActionPolicyDictDao actionPolciyDictDao; + private static PolicyVersionDao policyVersionDao; + private static WatchPolicyNotificationDao policyNotificationDao; + + @Autowired + private ActionPolicyController(RuleAlgorithmsDao ruleAlgorithmsDao, ActionPolicyDictDao actionPolciyDictDao, + PolicyVersionDao policyVersionDao, FunctionDefinitionDao functionDefinitionDao, WatchPolicyNotificationDao policyNotificationDao){ + ActionPolicyController.ruleAlgorithmsDao =ruleAlgorithmsDao; + ActionPolicyController.actionPolciyDictDao =actionPolciyDictDao; + ActionPolicyController.policyVersionDao =policyVersionDao; + ActionPolicyController.functionDefinitionDao = functionDefinitionDao; + ActionPolicyController.policyNotificationDao = policyNotificationDao; + } + + public ActionPolicyController(){} + + private String ruleID = ""; + private ArrayList attributeList; + protected LinkedList ruleAlgoirthmTracker; + public static final String PERFORMER_ATTRIBUTEID = "performer"; + protected Map performer = new HashMap(); + private ArrayList ruleAlgorithmList; + + public String newPolicyID() { + return Joiner.on(':').skipNulls().join((PolicyController.getDomain().startsWith("urn") ? null: "urn"), + PolicyController.getDomain().replaceAll("[/\\\\.]", ":"), "xacml", "policy", "id", UUID.randomUUID()); + } + + + @RequestMapping(value={"/get_FunctionDefinitionDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getFunctionDefinitionData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("functionDefinitionDatas", mapper.writeValueAsString(functionDefinitionDao.getFunctionDefinitionByName())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + logger.equals(XACMLErrorConstants.ERROR_DATA_ISSUE +"Error while retriving the Function Definition data"+e); + } + } + + @RequestMapping(value={"/policyController/save_Actionpolicy.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveActionPolicy(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + String userId = UserUtils.getUserIdFromCookie(request); + RESTfulPAPEngine engine = (RESTfulPAPEngine) PolicyController.getPapEngine(); + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + PolicyAdapter policyData = (PolicyAdapter)mapper.readValue(root.get("policyData").get("policy").toString(), PolicyAdapter.class); + if(root.get("policyData").get("model").get("type").toString().replace("\"", "").equals("file")){ + policyData.isEditPolicy = true; + } + if(root.get("policyData").get("model").get("path").size() != 0){ + String dirName = ""; + for(int i = 0; i < root.get("policyData").get("model").get("path").size(); i++){ + dirName = dirName.replace("\"", "") + root.get("policyData").get("model").get("path").get(i).toString().replace("\"", "") + File.separator; + } + policyData.setDomainDir(dirName.substring(0, dirName.lastIndexOf(File.separator))); + }else{ + policyData.setDomainDir(root.get("policyData").get("model").get("name").toString().replace("\"", "")); + } + int version = 0; + int highestVersion = 0; + int descriptionVersion = 0; + //get the highest version of policy from policy version table. + //getting the sub scope domain where the policy is created or updated + String dbCheckPolicyName = policyData.getDomainDir() + File.separator + "Action_" + policyData.getPolicyName(); + List versionList = policyVersionDao.getPolicyVersionEntityByName(dbCheckPolicyName); + if (versionList.size() > 0) { + for(int i = 0; i < versionList.size(); i++) { + PolicyVersion entityItem = versionList.get(i); + if(entityItem.getPolicyName().equals(dbCheckPolicyName)){ + highestVersion = entityItem.getHigherVersion(); + } + } + } + if(highestVersion != 0){ + version = highestVersion; + descriptionVersion = highestVersion +1; + }else{ + version = 1; + descriptionVersion = 1; + } + + //set policy adapter values for Building JSON object containing policy data + String createdBy = ""; + String modifiedBy = userId; + if(descriptionVersion == 1){ + createdBy = userId; + }else{ + String policyName = PolicyController.getGitPath().toAbsolutePath().toString() + File.separator + policyData.getDomainDir() + File.separator + policyData.getOldPolicyFileName() + ".xml"; + File policyPath = new File(policyName); + try { + createdBy = XACMLPolicyScanner.getCreatedBy(policyPath.toPath()); + } catch (IOException e) { + createdBy = "guest"; + } + } + + policyData.setPolicyDescription(policyData.getPolicyDescription()+ "@CreatedBy:" +createdBy + "@CreatedBy:" + "@ModifiedBy:" +modifiedBy + "@ModifiedBy:"); + Map successMap = new HashMap(); + Map attributeMap = new HashMap(); + + List dynamicRuleAlgorithmLabels = new LinkedList(); + List dynamicRuleAlgorithmCombo = new LinkedList(); + List dynamicRuleAlgorithmField1 = new LinkedList(); + List dynamicRuleAlgorithmField2 = new LinkedList(); + + //set the Rule Combining Algorithm Id to be sent to PAP-REST via JSON + List ruleAlgorithmsList = ruleAlgorithmsDao.getRuleAlgorithms(); + for (int i = 0; i < ruleAlgorithmsList.size(); i++) { + RuleAlgorithms a = ruleAlgorithmsList.get(i); + if (a.getXacmlId().equals(XACML3.ID_RULE_PERMIT_OVERRIDES.stringValue())) { + policyData.setRuleCombiningAlgId(a.getXacmlId()); + break; + } + } + + if(policyData.getAttributes().size() > 0){ + for(Object attribute : policyData.getAttributes()){ + if(attribute instanceof LinkedHashMap){ + String key = ((LinkedHashMap) attribute).get("option").toString(); + String value = ((LinkedHashMap) attribute).get("number").toString(); + attributeMap.put(key, value); + } + } + } + + if(policyData.getRuleAlgorithmschoices().size() > 0){ + for(Object attribute : policyData.getRuleAlgorithmschoices()){ + if(attribute instanceof LinkedHashMap){ + String label = ((LinkedHashMap) attribute).get("id").toString(); + String key = ((LinkedHashMap) attribute).get("dynamicRuleAlgorithmField1").toString(); + String rule = ((LinkedHashMap) attribute).get("dynamicRuleAlgorithmCombo").toString(); + String value = ((LinkedHashMap) attribute).get("dynamicRuleAlgorithmField2").toString(); + dynamicRuleAlgorithmLabels.add(label); + dynamicRuleAlgorithmField1.add(key); + dynamicRuleAlgorithmCombo.add(rule); + dynamicRuleAlgorithmField2.add(value); + } + } + } + + String actionDictValue = policyData.getActionAttributeValue(); + ActionPolicyDict jsonData = ((ActionPolicyDict) actionPolciyDictDao.getActionEntityDatabyId(actionDictValue)); + String actionBodyString = jsonData.getBody(); + String actionDictHeader = jsonData.getHeader(); + String actionDictType = jsonData.getType(); + String actionDictUrl = jsonData.getUrl(); + String actionDictMethod = jsonData.getMethod(); + policyData.setActionDictHeader(actionDictHeader); + policyData.setActionDictType(actionDictType); + policyData.setActionDictUrl(actionDictUrl); + policyData.setActionDictMethod(actionDictMethod); + policyData.setActionAttribute(actionDictValue); + policyData.setDynamicRuleAlgorithmLabels(dynamicRuleAlgorithmLabels); + policyData.setDynamicRuleAlgorithmCombo(dynamicRuleAlgorithmCombo); + policyData.setDynamicRuleAlgorithmField1(dynamicRuleAlgorithmField1); + policyData.setDynamicRuleAlgorithmField2(dynamicRuleAlgorithmField2); + if (actionBodyString != null) { + policyData.setActionBody(actionBodyString); + } + policyData.setDynamicFieldConfigAttributes(attributeMap); + + if (policyData.isEditPolicy()){ + //increment the version and set in policyAdapter + policyData.setVersion(String.valueOf(version)); + policyData.setHighestVersion(version); + policyData.setPolicyID(this.newPolicyID()); + policyData.setRuleID(ruleID); + successMap = engine.updatePolicyRequest(policyData); + } else { + //send it for policy creation + policyData.setVersion(String.valueOf(version)); + policyData.setHighestVersion(version); + successMap = engine.createPolicyRequest(policyData); + + } + if (successMap.containsKey("success")) { + // Add it into our tree + Path finalPolicyPath = null; + finalPolicyPath = Paths.get(successMap.get("success")); + PolicyElasticSearchController controller = new PolicyElasticSearchController(); + controller.updateElk(finalPolicyPath.toString()); + File file = finalPolicyPath.toFile(); + if(file != null){ + String policyName = file.toString(); + String removePath = policyName.substring(policyName.indexOf("repository")+11); + String removeXml = removePath.replace(".xml", ""); + String removeExtension = removeXml.substring(0, removeXml.indexOf(".")); + List policyVersionList = policyVersionDao.getPolicyVersionEntityByName(removeExtension); + if (policyVersionList.size() > 0) { + for(int i = 0; i < policyVersionList.size(); i++) { + PolicyVersion entityItem = policyVersionList.get(i); + if(entityItem.getPolicyName().equals(removeExtension)){ + version = entityItem.getHigherVersion() +1; + entityItem.setActiveVersion(version); + entityItem.setHigherVersion(version); + entityItem.setModifiedBy(userId); + policyVersionDao.update(entityItem); + if(policyData.isEditPolicy){ + PolicyNotificationMail email = new PolicyNotificationMail(); + String mode = "EditPolicy"; + String policyNameForEmail = policyData.getDomainDir() + File.separator + policyData.getOldPolicyFileName() + ".xml"; + email.sendMail(entityItem, policyNameForEmail, mode, policyNotificationDao); + } + } + } + }else{ + PolicyVersion entityItem = new PolicyVersion(); + entityItem.setActiveVersion(version); + entityItem.setHigherVersion(version); + entityItem.setPolicyName(removeExtension); + entityItem.setCreatedBy(userId); + entityItem.setModifiedBy(userId); + policyVersionDao.Save(entityItem); + } + } + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = mapper.writeValueAsString(successMap); + JSONObject j = new JSONObject("{policyData: " + responseString + "}"); + out.write(j.toString()); + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + public void PrePopulateActionPolicyData(PolicyAdapter policyAdapter) { + attributeList = new ArrayList(); + ruleAlgorithmList = new ArrayList(); + performer.put("PDP", "PDPAction"); + performer.put("PEP", "PEPAction"); + + if (policyAdapter.getPolicyData() instanceof PolicyType) { + Object policyData = policyAdapter.getPolicyData(); + PolicyType policy = (PolicyType) policyData; + policyAdapter.setOldPolicyFileName(policyAdapter.getPolicyName()); + String policyNameValue = policyAdapter.getPolicyName().substring(policyAdapter.getPolicyName().indexOf("_") + 1, policyAdapter.getPolicyName().lastIndexOf(".")); + policyAdapter.setPolicyName(policyNameValue); + String description = ""; + try{ + description = policy.getDescription().substring(0, policy.getDescription().indexOf("@CreatedBy:")); + }catch(Exception e){ + description = policy.getDescription(); + } + policyAdapter.setPolicyDescription(description); + // Get the target data under policy for Action. + TargetType target = policy.getTarget(); + if (target != null) { + // under target we have AnyOFType + List anyOfList = target.getAnyOf(); + if (anyOfList != null) { + Iterator iterAnyOf = anyOfList.iterator(); + while (iterAnyOf.hasNext()) { + AnyOfType anyOf = iterAnyOf.next(); + // Under AntOfType we have AllOfType + List allOfList = anyOf.getAllOf(); + if (allOfList != null) { + Iterator iterAllOf = allOfList.iterator(); + while (iterAllOf.hasNext()) { + AllOfType allOf = iterAllOf.next(); + // Under AllOfType we have Mathch. + List matchList = allOf.getMatch(); + if (matchList != null) { + Iterator iterMatch = matchList.iterator(); + while (iterMatch.hasNext()) { + MatchType match = iterMatch.next(); + // + // Under the match we have attributevalue and + // attributeDesignator. So,finally down to the actual attribute. + // + AttributeValueType attributeValue = match.getAttributeValue(); + String value = (String) attributeValue.getContent().get(0); + AttributeDesignatorType designator = match.getAttributeDesignator(); + String attributeId = designator.getAttributeId(); + // Component attributes are saved under Target here we are fetching them back. + // One row is default so we are not adding dynamic componet at index 0. + Map attribute = new HashMap(); + attribute.put("option", attributeId); + attribute.put("number", value); + attributeList.add(attribute); + } + } + policyAdapter.setAttributes(attributeList); + } + } + } + } + + List ruleList = policy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition(); + // Under rule we have Condition and obligation. + for (Object o : ruleList) { + if (o instanceof RuleType) { + // get the condition data under the rule for rule Algorithms. + ruleID = ((RuleType) o).getRuleId(); + ConditionType condition = ((RuleType) o).getCondition(); + ObligationExpressionsType obligations = ((RuleType) o).getObligationExpressions(); + if (condition != null) { + int index = 0; + ApplyType actionApply = (ApplyType) condition.getExpression().getValue(); + ruleAlgoirthmTracker = new LinkedList(); + // Populating Rule Algorithms starting from compound. + prePopulateCompoundRuleAlgorithm(index, actionApply); + } + policyAdapter.setRuleAlgorithmschoices(ruleAlgorithmList); + // get the Obligation data under the rule for Form elements. + if (obligations != null) { + // Under the obligationExpressions we have obligationExpression. + List obligationList = obligations.getObligationExpression(); + if (obligationList != null) { + Iterator iterObligation = obligationList.iterator(); + while (iterObligation.hasNext()) { + ObligationExpressionType obligation = iterObligation.next(); + policyAdapter.setActionAttributeValue(obligation.getObligationId()); + // Under the obligationExpression we have attributeAssignmentExpression. + List attributeAssignmentExpressionList = obligation.getAttributeAssignmentExpression(); + if (attributeAssignmentExpressionList != null) { + Iterator iterAttributeAssignmentExpression = attributeAssignmentExpressionList.iterator(); + while (iterAttributeAssignmentExpression.hasNext()) { + AttributeAssignmentExpressionType attributeAssignmentExpression = iterAttributeAssignmentExpression.next(); + String attributeID = attributeAssignmentExpression.getAttributeId(); + AttributeValueType attributeValue = (AttributeValueType) attributeAssignmentExpression.getExpression().getValue(); + if (attributeID.equals(PERFORMER_ATTRIBUTEID)) { + for (String key : performer.keySet()) { + String keyValue = performer.get(key); + if (keyValue.equals(attributeValue.getContent().get(0))) { + policyAdapter.setActionPerformer(key); + } + } + } + } + } + } + } + } + } + } + } + } + } + + private int prePopulateCompoundRuleAlgorithm(int index, ApplyType actionApply) { + boolean isCompoundRule = true; + List> jaxbActionTypes = actionApply.getExpression(); + for (JAXBElement jaxbElement : jaxbActionTypes) { + // If There is Attribute Value under Action Type that means we came to the final child + if (logger.isDebugEnabled()) { + logger.debug("Prepopulating rule algoirthm: " + index); + } + // Check to see if Attribute Value exists, if yes then it is not a compound rule + if (jaxbElement.getValue() instanceof AttributeValueType) { + prePopulateRuleAlgorithms(index, actionApply, jaxbActionTypes); + ruleAlgoirthmTracker.addLast(index); + isCompoundRule = false; + index++; + } + } + if (isCompoundRule) { + // As it's compound rule, Get the Apply types + for (JAXBElement jaxbElement : jaxbActionTypes) { + ApplyType innerActionApply = (ApplyType) jaxbElement.getValue(); + index = prePopulateCompoundRuleAlgorithm(index, innerActionApply); + } + // Populate combo box + if (logger.isDebugEnabled()) { + logger.debug("Prepopulating Compound rule algorithm: " + index); + } + Map rule = new HashMap(); + for (String key : PolicyController.getDropDownMap().keySet()) { + String keyValue = PolicyController.getDropDownMap().get(key); + if (keyValue.equals(actionApply.getFunctionId())) { + rule.put("dynamicRuleAlgorithmCombo", key); + } + } + rule.put("id", "A" + (index +1)); + // Populate Key and values for Compound Rule + rule.put("dynamicRuleAlgorithmField1", "A" + (ruleAlgoirthmTracker.getLast() + 1 )); + ruleAlgoirthmTracker.removeLast(); + rule.put("dynamicRuleAlgorithmField2", "A" + (ruleAlgoirthmTracker.getLast() + 1)); + ruleAlgoirthmTracker.removeLast(); + ruleAlgoirthmTracker.addLast(index); + ruleAlgorithmList.add(rule); + index++; + } + return index; + } + + private void prePopulateRuleAlgorithms(int index, ApplyType actionApply, List> jaxbActionTypes) { + Map ruleMap = new HashMap(); + ruleMap.put("id", "A" + (index +1)); + // Populate combo box + Map dropDownMap = PolicyController.getDropDownMap(); + for (String key : dropDownMap.keySet()) { + String keyValue = dropDownMap.get(key); + if (keyValue.equals(actionApply.getFunctionId())) { + ruleMap.put("dynamicRuleAlgorithmCombo", key); + } + } + // Populate the key and value fields + // Rule Attribute added as key + if ((jaxbActionTypes.get(0).getValue()) instanceof ApplyType) { + // Get from Attribute Designator + ApplyType innerActionApply = (ApplyType) jaxbActionTypes.get(0).getValue(); + List> jaxbInnerActionTypes = innerActionApply.getExpression(); + AttributeDesignatorType attributeDesignator = (AttributeDesignatorType) jaxbInnerActionTypes.get(0).getValue(); + ruleMap.put("dynamicRuleAlgorithmField1", attributeDesignator.getAttributeId()); + + // Get from Attribute Value + AttributeValueType actionConditionAttributeValue = (AttributeValueType) jaxbActionTypes.get(1).getValue(); + String attributeValue = (String) actionConditionAttributeValue.getContent().get(0); + ruleMap.put("dynamicRuleAlgorithmField2", attributeValue); + } + // Rule Attribute added as value + else if (((jaxbActionTypes.get(0).getValue()) instanceof AttributeValueType)) { + AttributeValueType actionConditionAttributeValue = (AttributeValueType) jaxbActionTypes.get(0).getValue(); + String attributeValue = (String) actionConditionAttributeValue.getContent().get(0); + ruleMap.put("dynamicRuleAlgorithmField2", attributeValue); + + ApplyType innerActionApply = (ApplyType) jaxbActionTypes.get(1).getValue(); + List> jaxbInnerActionTypes = innerActionApply.getExpression(); + AttributeDesignatorType attributeDesignator = (AttributeDesignatorType) jaxbInnerActionTypes.get(0).getValue(); + ruleMap.put("dynamicRuleAlgorithmField1", attributeDesignator.getAttributeId()); + } + ruleAlgorithmList.add(ruleMap); + } + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/AdminTabController.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/AdminTabController.java new file mode 100644 index 000000000..67c2d3080 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/AdminTabController.java @@ -0,0 +1,100 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.controller; + + +import java.io.PrintWriter; +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.json.JSONObject; +import org.openecomp.policy.dao.GlobalRoleSettingsDao; +import org.openecomp.policy.rest.jpa.GlobalRoleSettings; +import org.openecomp.portalsdk.core.controller.RestrictedBaseController; +import org.openecomp.portalsdk.core.web.support.JsonMessage; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +@Controller +@RequestMapping({"/"}) +public class AdminTabController extends RestrictedBaseController{ + + @Autowired + GlobalRoleSettingsDao globalRoleSettingsDao; + + + + @RequestMapping(value={"/get_LockDownData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getAdminTabEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("lockdowndata", mapper.writeValueAsString(globalRoleSettingsDao.getGlobalRoleSettings())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/adminTabController/save_LockDownValue.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveAdminTabLockdownValue(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + GlobalRoleSettings globalRole = mapper.readValue(root.get("lockdowndata").toString(), GlobalRoleSettings.class); + globalRole.setRole("super-admin"); + globalRoleSettingsDao.update(globalRole); + + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = mapper.writeValueAsString(this.globalRoleSettingsDao.getGlobalRoleSettings()); + JSONObject j = new JSONObject("{descriptiveScopeDictionaryDatas: " + responseString + "}"); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/AutoPushController.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/AutoPushController.java new file mode 100644 index 000000000..699d8ed00 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/AutoPushController.java @@ -0,0 +1,433 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.controller; + + +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; +import java.net.URI; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Date; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Set; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.io.FilenameUtils; +import org.json.JSONArray; +import org.json.JSONObject; +import org.openecomp.policy.adapter.AutoPushTabAdapter; +import org.openecomp.policy.dao.PolicyVersionDao; +import org.openecomp.policy.model.PDPGroupContainer; +import org.openecomp.policy.model.PDPPolicyContainer; +import org.openecomp.policy.model.Roles; +import org.openecomp.portalsdk.core.controller.RestrictedBaseController; +import org.openecomp.portalsdk.core.web.support.JsonMessage; +import org.openecomp.portalsdk.core.web.support.UserUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; +import org.openecomp.policy.xacml.api.pap.EcompPDPGroup; + +import com.att.research.xacml.api.pap.PAPException; +//import com.att.research.xacml.api.pap.PDPGroup; +import com.att.research.xacml.api.pap.PDPPolicy; +import org.openecomp.policy.xacml.std.pap.StdPDPGroup; +import org.openecomp.policy.xacml.std.pap.StdPDPPolicy; +import org.openecomp.policy.xacml.util.XACMLPolicyScanner; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + + +@Controller +@RequestMapping({"/"}) +public class AutoPushController extends RestrictedBaseController{ + + private static final Logger logger = FlexLogger.getLogger(AutoPushController.class); + + private PDPGroupContainer container; + protected List groups = Collections.synchronizedList(new ArrayList()); + + private static PDPPolicyContainer policyContainer; + Set selectedPolicies; + + @Autowired + PolicyVersionDao policyVersionDao; + + public synchronized void refreshGroups() { + synchronized(this.groups) { + this.groups.clear(); + try { + this.groups.addAll(PolicyController.getPapEngine().getEcompPDPGroups()); + } catch (PAPException e) { + String message = "Unable to retrieve Groups from server: " + e; + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + message); + } + + } + } + + @RequestMapping(value={"/get_AutoPushPoliciesContainerData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getPolicyGroupContainerData(HttpServletRequest request, HttpServletResponse response){ + try{ + Path gitPath = PolicyController.getGitPath().toAbsolutePath(); + PrintWriter out = response.getWriter(); + JSONObject j = new JSONObject("{data: " + readFileRepository(gitPath,0,0,request).toString() + "}"); + out.write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @SuppressWarnings("rawtypes") + public JSONArray readFileRepository(Path path, int id, int parentid, HttpServletRequest request){ + Set scopes = null; + List roles = null; + String userId = null; + try { + userId = UserUtils.getUserIdFromCookie(request); + } catch (Exception e) { + logger.error("Exception Occured while reading userid from cookie" +e); + } + JSONArray fileJSONArray = new JSONArray(); + File root = new File(path.toString()); + if(parentid==0 ){ + parentid = 1; + } + List userRoles = PolicyController.getRoles(userId); + roles = new ArrayList(); + scopes = new HashSet(); + for(Roles userRole: userRoles){ + roles.add(userRole.getRole()); + scopes.add(userRole.getScope()); + } + + for ( File file : root.listFiles()){ + if (!(file.toString().contains(".git") || file.equals(".DS_Store"))) { + if(file.isDirectory()){ + JSONObject el = new JSONObject(); + String fileName = file.getName().toString(); + el.put("categoryId", id+1); + el.put("name", fileName); + el.put("dateModified", lastModified(file)); + el.put("filePath", file.getPath()); + el.put("parentCategoryId", parentid); + el.put("files",readFileRepository(file.toPath(),id+1, id+1, request)); + if (roles.contains("super-admin") || roles.contains("super-editor") || roles.contains("super-guest") ) { + fileJSONArray.put(el); + }else{ + String filePath = file.getPath().toString(); + int startIndex = filePath.indexOf("repository") + 11; + filePath = filePath.substring(startIndex, filePath.length()); + if (scopes.contains(filePath)) { + fileJSONArray.put(el); + } + } + }else{ + JSONObject el = new JSONObject(); + String policyName = ""; + String version = ""; + String fileName = file.getName().toString(); + if(fileName.endsWith(".xml")){ + fileName = fileName.substring(0, fileName.lastIndexOf('.')); + fileName = fileName.substring(0, fileName.lastIndexOf('.')); + //Query the database + String parent = file.toString().substring(file.toString().indexOf("repository")+ 11); + parent = FilenameUtils.removeExtension(parent); + version = parent.substring(parent.indexOf(".")+1); + policyName = parent.substring(0, parent.lastIndexOf(".")); + if(policyName.contains("\\")){ + String scope = policyName.substring(0, policyName.lastIndexOf("\\")); + policyName = scope + "\\" + policyName.substring(policyName.lastIndexOf("\\")); + } + } + el.put("categoryId", id+1); + el.put("name", fileName); + el.put("parentCategoryId", parentid); + el.put("dateModified", lastModified(file)); + el.put("version", version); + el.put("filePath", file.getPath()); + el.put("files",new ArrayList()); + String query = "from PolicyVersion where POLICY_NAME ='" +policyName+"' and ACTIVE_VERSION ='"+version+"'"; + Boolean active = PolicyController.getActivePolicy(query); + if(active){ + if (roles.contains("super-admin") || roles.contains("super-editor") || roles.contains("super-guest") ) { + fileJSONArray.put(el); + }else{ + String filePath = file.getPath().toString(); + int startIndex = filePath.indexOf("repository") + 11; + filePath = filePath.substring(startIndex, filePath.length()); + filePath = filePath.substring(0, filePath.lastIndexOf(File.separator)); + if (scopes.contains(filePath)) { + fileJSONArray.put(el); + } + } + } + } + } + } + return fileJSONArray; + } + + public Date lastModified(File file) { + return new Date(file.lastModified()); + } + + public String getVersion(File file) { + try { + return XACMLPolicyScanner.getVersion(Paths.get(file.getAbsolutePath())); + } catch (IOException e) { + return ""; + } + } + + public String getDomain(File file) { + String filePath = file.getAbsolutePath(); + int startIndex = filePath.indexOf("repository") + 11; + return filePath.substring(startIndex, filePath.length()); + } + + + @RequestMapping(value={"/auto_Push/PushPolicyToPDP.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView PushPolicyToPDPGroup(HttpServletRequest request, HttpServletResponse response) throws Exception { + try { + ArrayList selectedPDPS = new ArrayList(); + ArrayList selectedPoliciesInUI = new ArrayList(); + this.groups.addAll(PolicyController.getPapEngine().getEcompPDPGroups()); + ObjectMapper mapper = new ObjectMapper(); + this.container = new PDPGroupContainer(PolicyController.getPapEngine()); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + AutoPushTabAdapter adapter = (AutoPushTabAdapter) mapper.readValue(root.get("pushTabData").toString(), AutoPushTabAdapter.class); + for (Object pdpGroupId : adapter.getPdpDatas()) { + LinkedHashMap selectedPDP = (LinkedHashMap)pdpGroupId; + for(EcompPDPGroup pdpGroup : this.groups){ + if(pdpGroup.getId().equals(selectedPDP.get("id"))){ + selectedPDPS.add(pdpGroup); + } + } + } + + for (Object policyId : adapter.getPolicyDatas()) { + LinkedHashMap selected = (LinkedHashMap)policyId; + Path file = Paths.get(selected.get("filePath").toString()); + selectedPoliciesInUI.add(file.toFile()); + } + + for (Object pdpDestinationGroupId : selectedPDPS) { + Set currentPoliciesInGroup = new HashSet(); + Set selectedPolicies = new HashSet(); + for (File policyId : selectedPoliciesInUI) { + logger.debug("Handlepolicies..." + pdpDestinationGroupId + policyId); + // + // Get the current selection + File selectedItem = policyId; + // + assert (selectedItem != null); + if (selectedItem.isDirectory()) { + //AdminNotification.warn("Select only the Policy"); + return null; + } + // create the id of the target file + // Our standard for file naming is: + // ...xml + // since the file name usually has a ".xml", we need to strip + // that + // before adding the other parts + String name = selectedItem.getName(); + if(name.endsWith(".xml")){ + name = name.substring(0, name.length() - 4); + name = name.substring(0, name.lastIndexOf(".")); + } + String id = name; + if (id.endsWith(".xml")) { + id = id.substring(0, id.length() - 4); + id = id.substring(0, id.lastIndexOf(".")); + } + // add on the version string + String version = getVersion(selectedItem); + id += "." + version; + // put the .xml on the end + id += ".xml"; + // track on the domain in front. Do this one level at a time + // until we + // reach one of the roots + String domain = getDomain(selectedItem); + String mainDomain = domain.substring(0, domain.lastIndexOf(File.separator) ); + logger.info("print the main domain value"+mainDomain); + String path = mainDomain.replace('\\', '.'); + if(path.contains("/")){ + path = mainDomain.replace('/', '.'); + logger.info("print the path:" +path); + } + id = path + "." + id; + // Default policy to be Root policy; user can change to deferred + // later + URI selectedURI = selectedItem.toURI(); + StdPDPPolicy selectedPolicy = null; + try { + // + // Create the policy + selectedPolicy = new StdPDPPolicy(id, true, name, selectedURI); + } catch (IOException e) { + logger.error("Unable to create policy '" + id + "': "+ e.getMessage()); + //AdminNotification.warn("Unable to create policy '" + id + "': " + e.getMessage()); + } + StdPDPGroup selectedGroup = (StdPDPGroup) pdpDestinationGroupId; + if (selectedPolicy != null) { + // Add Current policies from container + for (EcompPDPGroup group : container.getGroups()) { + if (group.getId().equals(selectedGroup.getId())) { + currentPoliciesInGroup.addAll(group.getPolicies()); + } + } + // copy policy to PAP + try { + PolicyController.getPapEngine().copyPolicy(selectedPolicy, (StdPDPGroup) pdpDestinationGroupId); + } catch (PAPException e) { + e.printStackTrace(); + return null; + } + selectedPolicies.add(selectedPolicy); + } + } + StdPDPGroup pdpGroup = (StdPDPGroup) pdpDestinationGroupId; + StdPDPGroup updatedGroupObject = new StdPDPGroup(pdpGroup.getId(), pdpGroup.isDefaultGroup(), pdpGroup.getName(), pdpGroup.getDescription(), pdpGroup.getDirectory()); + updatedGroupObject.setEcompPdps(pdpGroup.getEcompPdps()); + updatedGroupObject.setPipConfigs(pdpGroup.getPipConfigs()); + updatedGroupObject.setStatus(pdpGroup.getStatus()); + + // replace the original set of Policies with the set from the + // container (possibly modified by the user) + // do not allow multiple copies of same policy + Iterator policyIterator = currentPoliciesInGroup.iterator(); + logger.debug("policyIterator....." + selectedPolicies); + while (policyIterator.hasNext()) { + PDPPolicy existingPolicy = policyIterator.next(); + for (PDPPolicy selPolicy : selectedPolicies) { + if (selPolicy.getName().equals(existingPolicy.getName())) { + if (selPolicy.getVersion().equals(existingPolicy.getVersion())) { + if (selPolicy.getId().equals(existingPolicy.getId())) { + policyIterator.remove(); + logger.debug("Removing policy: " + selPolicy); + break; + } + } else { + policyIterator.remove(); + logger.debug("Removing Old Policy version: "+ selPolicy); + break; + } + } + } + } + + currentPoliciesInGroup.addAll(selectedPolicies); + updatedGroupObject.setPolicies(currentPoliciesInGroup); + this.container.updateGroup(updatedGroupObject); + + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + refreshGroups(); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(groups)); + JSONObject j = new JSONObject(msg); + out.write(j.toString()); + return null; + } + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/auto_Push/remove_GroupPolicies.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removePDPGroup(HttpServletRequest request, HttpServletResponse response) throws Exception { + try { + this.container = new PDPGroupContainer(PolicyController.getPapEngine()); + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + StdPDPGroup group = (StdPDPGroup)mapper.readValue(root.get("activePdpGroup").toString(), StdPDPGroup.class); + JsonNode removePolicyData = root.get("data"); + policyContainer = new PDPPolicyContainer(group); + if(removePolicyData.size() > 0){ + for(int i = 0 ; i < removePolicyData.size(); i++){ + String data = removePolicyData.get(i).toString(); + AutoPushController.policyContainer.removeItem(data); + } + Set changedPolicies = new HashSet(); + changedPolicies.addAll((Collection) AutoPushController.policyContainer.getItemIds()); + StdPDPGroup updatedGroupObject = new StdPDPGroup(group.getId(), group.isDefaultGroup(), group.getName(), group.getDescription(),null); + updatedGroupObject.setPolicies(changedPolicies); + updatedGroupObject.setEcompPdps(group.getEcompPdps()); + updatedGroupObject.setPipConfigs(group.getPipConfigs()); + updatedGroupObject.setStatus(group.getStatus()); + this.container.updateGroup(updatedGroupObject); + } + + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + refreshGroups(); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(groups)); + JSONObject j = new JSONObject(msg); + + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + +} \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/CreateBRMSParamController.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/CreateBRMSParamController.java new file mode 100644 index 000000000..7a2b24e84 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/CreateBRMSParamController.java @@ -0,0 +1,723 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.controller; + + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintWriter; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.xml.bind.JAXBElement; + +import org.json.JSONObject; +import org.openecomp.policy.adapter.PolicyAdapter; +import org.openecomp.policy.admin.PolicyNotificationMail; +import org.openecomp.policy.admin.RESTfulPAPEngine; +import org.openecomp.policy.dao.PolicyVersionDao; +import org.openecomp.policy.dao.RuleAlgorithmsDao; +import org.openecomp.policy.dao.WatchPolicyNotificationDao; +import org.openecomp.policy.elk.client.PolicyElasticSearchController; +import org.openecomp.policy.rest.dao.BRMSParamTemplateDao; +import org.openecomp.policy.rest.jpa.BRMSParamTemplate; +import org.openecomp.policy.rest.jpa.PolicyVersion; +import org.openecomp.policy.rest.jpa.RuleAlgorithms; +import org.openecomp.portalsdk.core.controller.RestrictedBaseController; +import org.openecomp.portalsdk.core.web.support.UserUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + +import com.att.research.xacml.api.XACML3; +import org.openecomp.policy.xacml.api.XACMLErrorConstants; +import org.openecomp.policy.xacml.util.XACMLPolicyScanner; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.base.Joiner; + +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionsType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeAssignmentExpressionType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.RuleType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +@Controller +@RequestMapping("/") +public class CreateBRMSParamController extends RestrictedBaseController { + private static final Logger logger = FlexLogger.getLogger(CreateBRMSParamController.class); + + private static RuleAlgorithmsDao ruleAlgorithmsDao; + private static BRMSParamTemplateDao bRMSParamTemplateDao; + private static PolicyVersionDao policyVersionDao; + private static WatchPolicyNotificationDao policyNotificationDao; + + @Autowired + private CreateBRMSParamController(RuleAlgorithmsDao ruleAlgorithmsDao, BRMSParamTemplateDao bRMSParamTemplateDao, PolicyVersionDao policyVersionDao, + WatchPolicyNotificationDao policyNotificationDao){ + CreateBRMSParamController.policyVersionDao = policyVersionDao; + CreateBRMSParamController.ruleAlgorithmsDao = ruleAlgorithmsDao; + CreateBRMSParamController.bRMSParamTemplateDao = bRMSParamTemplateDao; + CreateBRMSParamController.policyNotificationDao = policyNotificationDao; + } + + public CreateBRMSParamController(){} + protected PolicyAdapter policyAdapter = null; + private ArrayList attributeList; + private String ruleID = ""; + + private HashMap dynamicLayoutMap; + + public String newPolicyID() { + return Joiner.on(':').skipNulls().join((PolicyController.getDomain().startsWith("urn") ? null: "urn"), + PolicyController.getDomain().replaceAll("[/\\\\.]", ":"), "xacml", "policy", "id", UUID.randomUUID()); + } + + @RequestMapping(value={"/policyController/getBRMSTemplateData.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView getBRMSParamPolicyRuleData(HttpServletRequest request, HttpServletResponse response) throws Exception{ + dynamicLayoutMap = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + String rule = findRule(root.get("policyData").toString().replaceAll("^\"|\"$", "")); + generateUI(rule); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = mapper.writeValueAsString(dynamicLayoutMap); + JSONObject j = new JSONObject("{policyData: " + responseString + "}"); + out.write(j.toString()); + return null; + } + + protected String findRule(String ruleTemplate) { + for (BRMSParamTemplate bRMSParamTemplate: bRMSParamTemplateDao.getBRMSParamTemplateData()){ + if(bRMSParamTemplate.getRuleName().equals(ruleTemplate)){ + return bRMSParamTemplate.getRule(); + } + } + return null; + } + + protected void generateUI(String rule) { + if(rule!=null){ + try { + String params = ""; + Boolean flag = false; + Boolean comment = false; + String lines[] = rule.split("\n"); + for(String line : lines){ + if (line.isEmpty() || line.startsWith("//")) { + continue; + } + if (line.startsWith("/*")) { + comment = true; + continue; + } + if (line.contains("//")) { + line = line.split("\\/\\/")[0]; + } + if (line.contains("/*")) { + comment = true; + if (line.contains("*/")) { + try { + comment = false; + line = line.split("\\/\\*")[0] + + line.split("\\*\\/")[1].replace("*/", ""); + } catch (Exception e) { + line = line.split("\\/\\*")[0]; + } + } else { + line = line.split("\\/\\*")[0]; + } + } + if (line.contains("*/")) { + comment = false; + try { + line = line.split("\\*\\/")[1].replace("*/", ""); + } catch (Exception e) { + line = ""; + } + } + if (comment) { + continue; + } + if (flag) { + params = params + line; + } + if (line.contains("declare Params")) { + params = params + line; + flag = true; + } + if (line.contains("end") && flag) { + break; + } + } + params = params.replace("declare Params", "").replace("end", "") + .replaceAll("\\s+", ""); + String[] components = params.split(":"); + String caption = ""; + for (int i = 0; i < components.length; i++) { + String type = ""; + if (i == 0) { + caption = components[i]; + } + if(caption.equals("")){ + break; + } + String nextComponent = ""; + try { + nextComponent = components[i + 1]; + } catch (Exception e) { + nextComponent = components[i]; + } + if (nextComponent.startsWith("String")) { + type = "String"; + createField(caption, type); + caption = nextComponent.replace("String", ""); + } else if (nextComponent.startsWith("int")) { + type = "int"; + createField(caption, type); + caption = nextComponent.replace("int", ""); + } + } + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e); + } + } + } + + private String convertDate(String dateTTL) { + String formateDate = null; + String[] date = dateTTL.split("T"); + String[] parts = date[0].split("-"); + + formateDate = parts[2] + "-" + parts[1] + "-" + parts[0]; + return formateDate; + } + + private void createField(String caption, String type) { + dynamicLayoutMap.put(caption, type); + } + + @RequestMapping(value={"/policyController/save_BRMSParamPolicy.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveBRMSParamPolicy(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + String userId = UserUtils.getUserIdFromCookie(request); + RESTfulPAPEngine engine = (RESTfulPAPEngine) PolicyController.getPapEngine(); + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + PolicyAdapter policyData = (PolicyAdapter)mapper.readValue(root.get("policyData").get("policy").toString(), PolicyAdapter.class); + + if (policyData.getTtlDate()==null){ + policyData.setTtlDate("NA"); + }else{ + String dateTTL = policyData.getTtlDate(); + String newDate = convertDate(dateTTL); + policyData.setTtlDate(newDate); + } + + if(root.get("policyData").get("model").get("type").toString().replace("\"", "").equals("file")){ + policyData.isEditPolicy = true; + } + if(root.get("policyData").get("model").get("path").size() != 0){ + String dirName = ""; + for(int i = 0; i < root.get("policyData").get("model").get("path").size(); i++){ + dirName = dirName.replace("\"", "") + root.get("policyData").get("model").get("path").get(i).toString().replace("\"", "") + File.separator; + } + policyData.setDomainDir(dirName.substring(0, dirName.lastIndexOf(File.separator))); + }else{ + policyData.setDomainDir(root.get("policyData").get("model").get("name").toString().replace("\"", "")); + } + int version = 0; + int highestVersion = 0; + int descriptionVersion = 0; + //get the highest version of policy from policy version table. + //getting the sub scope domain where the policy is created or updated + String dbCheckPolicyName = policyData.getDomainDir() + File.separator + "Config_BRMS_Param_" + policyData.getPolicyName(); + List policyVersionList = policyVersionDao.getPolicyVersionEntityByName(dbCheckPolicyName); + if (policyVersionList.size() > 0) { + for(int i = 0; i < policyVersionList.size(); i++) { + PolicyVersion entityItem = policyVersionList.get(i); + if(entityItem.getPolicyName().equals(dbCheckPolicyName)){ + highestVersion = entityItem.getHigherVersion(); + } + } + } + if(highestVersion != 0){ + version = highestVersion; + descriptionVersion = highestVersion +1; + }else{ + version = 1; + descriptionVersion = 1; + } + + //set policy adapter values for Building JSON object containing policy data + String createdBy = ""; + String modifiedBy = userId; + if(descriptionVersion == 1){ + createdBy = userId; + }else{ + String policyName = PolicyController.getGitPath().toAbsolutePath().toString() + File.separator + policyData.getDomainDir() + File.separator + policyData.getOldPolicyFileName() + ".xml"; + File policyPath = new File(policyName); + try { + createdBy = XACMLPolicyScanner.getCreatedBy(policyPath.toPath()); + } catch (IOException e) { + createdBy = "guest"; + } + } + + policyData.setPolicyDescription(policyData.getPolicyDescription()+ "@CreatedBy:" +createdBy + "@CreatedBy:" + "@ModifiedBy:" +modifiedBy + "@ModifiedBy:"); + Map successMap = new HashMap(); + Map attributeMap = new HashMap(); + //set the Rule Combining Algorithm Id to be sent to PAP-REST via JSON + List ruleAlgorithmsList = ruleAlgorithmsDao.getRuleAlgorithms(); + for (int i = 0; i < ruleAlgorithmsList.size(); i++) { + RuleAlgorithms a = ruleAlgorithmsList.get(i); + if (a.getXacmlId().equals(XACML3.ID_RULE_PERMIT_OVERRIDES.stringValue())) { + policyData.setRuleCombiningAlgId(a.getXacmlId()); + break; + } + } + if(policyData.getAttributes().size() > 0){ + for(Object attribute : policyData.getAttributes()){ + if(attribute instanceof LinkedHashMap){ + String key = ((LinkedHashMap) attribute).get("key").toString(); + String value = ((LinkedHashMap) attribute).get("value").toString(); + attributeMap.put(key, value); + } + } + } + + policyData.setEcompName("DROOLS"); + policyData.setConfigName("BRMS_PARAM_RULE"); + policyData.setDynamicFieldConfigAttributes(attributeMap); + //convert drl rule and UI parameters into a map + Map drlRuleAndUIParams = new HashMap(); + // If there is any dynamic field create the matches here + String key="templateName"; + String value=(String) policyData.getRuleName(); + drlRuleAndUIParams.put(key, value); + System.out.println(policyData.getRuleData()); + if(policyData.getRuleData().size() > 0){ + for(Object keyValue: policyData.getRuleData().keySet()){ + drlRuleAndUIParams.put(keyValue.toString(), policyData.getRuleData().get(keyValue).toString()); + } + } + policyData.setBRMSParamBody(drlRuleAndUIParams); + if (policyData.isEditPolicy()){ + //increment the version and set in policyAdapter + policyData.setVersion(String.valueOf(version)); + policyData.setHighestVersion(version); + policyData.setPolicyID(this.newPolicyID()); + policyData.setRuleID(ruleID); + successMap = engine.updatePolicyRequest(policyData); + } else { + //send it for policy creation + policyData.setVersion(String.valueOf(version)); + policyData.setHighestVersion(version); + successMap = engine.createPolicyRequest(policyData); + + } + + if (successMap.containsKey("success")) { + // Add it into our tree + Path finalPolicyPath = null; + finalPolicyPath = Paths.get(successMap.get("success")); + PolicyElasticSearchController controller = new PolicyElasticSearchController(); + controller.updateElk(finalPolicyPath.toString()); + File file = finalPolicyPath.toFile(); + if(file != null){ + String policyName = file.toString(); + String removePath = policyName.substring(policyName.indexOf("repository")+11); + String removeXml = removePath.replace(".xml", ""); + String removeExtension = removeXml.substring(0, removeXml.indexOf(".")); + List versionList = policyVersionDao.getPolicyVersionEntityByName(removeExtension); + if (versionList.size() > 0) { + for(int i = 0; i < versionList.size(); i++) { + PolicyVersion entityItem = versionList.get(i); + if(entityItem.getPolicyName().equals(removeExtension)){ + version = entityItem.getHigherVersion() +1; + entityItem.setActiveVersion(version); + entityItem.setHigherVersion(version); + entityItem.setModifiedBy(userId); + policyVersionDao.update(entityItem); + if(policyData.isEditPolicy){ + PolicyNotificationMail email = new PolicyNotificationMail(); + String mode = "EditPolicy"; + String policyNameForEmail = policyData.getDomainDir() + File.separator + policyData.getOldPolicyFileName() + ".xml"; + email.sendMail(entityItem, policyNameForEmail, mode, policyNotificationDao); + } + } + } + }else{ + PolicyVersion entityItem = new PolicyVersion(); + entityItem.setActiveVersion(version); + entityItem.setHigherVersion(version); + entityItem.setPolicyName(removeExtension); + entityItem.setCreatedBy(userId); + entityItem.setModifiedBy(userId); + policyVersionDao.Save(entityItem); + } + } + } + + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = mapper.writeValueAsString(successMap); + JSONObject j = new JSONObject("{policyData: " + responseString + "}"); + out.write(j.toString()); + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + public void PrePopulateBRMSParamPolicyData(PolicyAdapter policyAdapter) { + attributeList = new ArrayList(); + dynamicLayoutMap = new HashMap(); + if (policyAdapter.getPolicyData() instanceof PolicyType) { + PolicyType policy = (PolicyType) policyAdapter.getPolicyData(); + policyAdapter.setOldPolicyFileName(policyAdapter.getPolicyName()); + // policy name value is the policy name without any prefix and + // Extensions. + String policyNameValue = policyAdapter.getPolicyName().substring(policyAdapter.getPolicyName().indexOf("BRMS_Param_") +11, policyAdapter.getPolicyName().lastIndexOf(".")); + if (logger.isDebugEnabled()) { + logger.debug("Prepopulating form data for BRMS RAW Policy selected:" + policyAdapter.getPolicyName()); + } + policyAdapter.setPolicyName(policyNameValue); + String description = ""; + try{ + description = policy.getDescription().substring(0, policy.getDescription().indexOf("@CreatedBy:")); + }catch(Exception e){ + description = policy.getDescription(); + } + policyAdapter.setPolicyDescription(description); + // Set Attributes. + AdviceExpressionsType expressionTypes = ((RuleType)policy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().get(0)).getAdviceExpressions(); + for( AdviceExpressionType adviceExpression: expressionTypes.getAdviceExpression()){ + for(AttributeAssignmentExpressionType attributeAssignment: adviceExpression.getAttributeAssignmentExpression()){ + if(attributeAssignment.getAttributeId().startsWith("key:")){ + Map attribute = new HashMap(); + String key = attributeAssignment.getAttributeId().replace("key:", ""); + attribute.put("key", key); + JAXBElement attributevalue = (JAXBElement) attributeAssignment.getExpression(); + String value = (String) attributevalue.getValue().getContent().get(0); + attribute.put("value", value); + attributeList.add(attribute); + } + } + policyAdapter.setAttributes(attributeList); + } + String ruleConfigName = policyAdapter.getDirPath().replace(File.separator, ".")+ "." + policyAdapter.getOldPolicyFileName() + ".txt"; + policyAdapter.setConfigBodyPath(ruleConfigName); + paramUIGenerate(policyAdapter); + // Get the target data under policy. + policyAdapter.setDynamicLayoutMap(dynamicLayoutMap); + if(policyAdapter.getDynamicLayoutMap().size() > 0){ + LinkedHashMap drlRule = new LinkedHashMap(); + for(Object keyValue: policyAdapter.getDynamicLayoutMap().keySet()){ + drlRule.put(keyValue.toString(), policyAdapter.getDynamicLayoutMap().get(keyValue).toString()); + } + policyAdapter.setRuleData(drlRule); + } + TargetType target = policy.getTarget(); + if (target != null) { + // Under target we have AnyOFType + List anyOfList = target.getAnyOf(); + if (anyOfList != null) { + Iterator iterAnyOf = anyOfList.iterator(); + while (iterAnyOf.hasNext()) { + AnyOfType anyOf = iterAnyOf.next(); + // Under AnyOFType we have AllOFType + List allOfList = anyOf.getAllOf(); + if (allOfList != null) { + Iterator iterAllOf = allOfList.iterator(); + int index = 0; + while (iterAllOf.hasNext()) { + AllOfType allOf = iterAllOf.next(); + // Under AllOFType we have Match + List matchList = allOf.getMatch(); + if (matchList != null) { + Iterator iterMatch = matchList.iterator(); + while (iterMatch.hasNext()) { + MatchType match = iterMatch.next(); + // + // Under the match we have attributevalue and + // attributeDesignator. So,finally down to the actual attribute. + // + AttributeValueType attributeValue = match.getAttributeValue(); + String value = (String) attributeValue.getContent().get(0); + + if (index == 3){ + policyAdapter.setRiskType(value); + } + + if (index == 4){ + policyAdapter.setRiskLevel(value); + } + + if (index == 5){ + policyAdapter.setGuard(value); + } + if (index == 6 && !value.contains("NA")){ + String newDate = convertDate(value, true); + policyAdapter.setTtlDate(newDate); + } + + index++; + } + } + } + } + } + } + } + } + } + + private String convertDate(String dateTTL, boolean portalType) { + String formateDate = null; + String[] date; + String[] parts; + + if (portalType){ + parts = dateTTL.split("-"); + formateDate = parts[2] + "-" + parts[1] + "-" + parts[0] + "T05:00:00.000Z"; + } else { + date = dateTTL.split("T"); + parts = date[0].split("-"); + formateDate = parts[2] + "-" + parts[1] + "-" + parts[0]; + } + return formateDate; + } + // This method generates the UI from rule configuration + private void paramUIGenerate(PolicyAdapter policyAdapter) { + String fileLocation = null; + String fileName = policyAdapter.getConfigBodyPath(); + if (fileName != null) { + fileLocation = PolicyController.getConfigHome(); + } + if (logger.isDebugEnabled()) { + logger.debug("Attempting to read file from the location: " + fileLocation); + } + if (fileLocation == null) { + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Error with the FileName: " + fileName); + return; + } + File dir = new File(fileLocation); + File[] listOfFiles = dir.listFiles(); + for (File file : listOfFiles) { + if (file.isFile() && file.getName().contains(fileName) + && file.toString().endsWith(".txt")) { + // Reading the file + try { + try (BufferedReader br = new BufferedReader(new FileReader(file))) { + StringBuilder sb = new StringBuilder(); + String line = br.readLine(); + while (line != null) { + sb.append(line); + sb.append("\n"); + line = br.readLine(); + } + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE+ e.getMessage()); + } + String params = ""; + Boolean flag = false; + Boolean comment = false; + for (String line : Files.readAllLines(Paths.get(file.toString()))) { + if (line.isEmpty() || line.startsWith("//")) { + continue; + } + if(line.contains("<$%BRMSParamTemplate=")){ + String value = line.substring(line.indexOf("<$%"),line.indexOf("%$>")); + value = value.replace("<$%BRMSParamTemplate=", ""); + policyAdapter.setRuleName(value); + } + if (line.startsWith("/*")) { + comment = true; + continue; + } + if (line.contains("//")) { + if(!(line.contains("http://") || line.contains("https://"))){ + line = line.split("\\/\\/")[0]; + } + } + if (line.contains("/*")) { + comment = true; + if (line.contains("*/")) { + try { + comment = false; + line = line.split("\\/\\*")[0] + + line.split("\\*\\/")[1].replace( + "*/", ""); + } catch (Exception e) { + line = line.split("\\/\\*")[0]; + } + } else { + line = line.split("\\/\\*")[0]; + } + } + if (line.contains("*/")) { + comment = false; + try { + line = line.split("\\*\\/")[1] + .replace("*/", ""); + } catch (Exception e) { + line = ""; + } + } + if (comment) { + continue; + } + if (flag) { + params = params + line; + } + if (line.contains("rule \"Params\"")) { + params = params + line; + flag = true; + } + if (line.contains("end") && flag) { + break; + } + } + params = params.replaceAll("\\s+", "").replace("rule\"Params\"salience1000whenthenParamsparams=newParams();","") + .replace("insert(params);end", "") + .replace("params.set", ""); + String[] components = params.split(";"); + if(components!= null && components.length > 0){ + for (int i = 0; i < components.length; i++) { + String value = null; + String caption = components[i].substring(0, + components[i].indexOf("(")); + caption = caption.substring(0, 1).toLowerCase() + caption.substring(1); + if (components[i].contains("(\"")) { + value = components[i] + .substring(components[i].indexOf("(\""), + components[i].indexOf("\")")) + .replace("(\"", "").replace("\")", ""); + } else { + value = components[i] + .substring(components[i].indexOf("("), + components[i].indexOf(")")) + .replace("(", "").replace(")", ""); + } + dynamicLayoutMap.put(caption, value); + + } + } + } catch (FileNotFoundException e) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e.getMessage()); + } catch (IOException e1) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE+ e1.getMessage()); + } + } + } + } + + // set View Rule + @RequestMapping(value={"/policyController/ViewBRMSParamPolicyRule.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView setViewRule(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + PolicyAdapter policyData = (PolicyAdapter)mapper.readValue(root.get("policyData").get("policy").toString(), PolicyAdapter.class); + + String body = ""; + + body = "/* Autogenerated Code Please Don't change/remove this comment section. This is for the UI purpose. \n\t " + + "<$%BRMSParamTemplate=" + policyData.getRuleName() + "%$> \n */ \n"; + body = body + findRule((String) policyData.getRuleName()) + "\n"; + String generatedRule = "rule \"Params\" \n\tsalience 1000 \n\twhen\n\tthen\n\t\tParams params = new Params();"; + + if(policyData.getRuleData().size() > 0){ + for(Object keyValue: policyData.getRuleData().keySet()){ + String key = keyValue.toString().substring(0, 1).toUpperCase() + keyValue.toString().substring(1); + if (keyValue.equals("String")) { + generatedRule = generatedRule + "\n\t\tparams.set" + + key + "(\"" + + policyData.getRuleData().get(keyValue).toString() + "\");"; + } else { + generatedRule = generatedRule + "\n\t\tparams.set" + + key + "(" + + policyData.getRuleData().get(keyValue).toString() + ");"; + } + } + } + generatedRule = generatedRule + + "\n\t\tinsert(params);\nend"; + logger.info("New rule generated with :" + generatedRule); + body = body + generatedRule; + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = mapper.writeValueAsString(body); + JSONObject j = new JSONObject("{policyData: " + responseString + "}"); + out.write(j.toString()); + return null; + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + } + return null; + } +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/CreateBRMSRawController.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/CreateBRMSRawController.java new file mode 100644 index 000000000..6dcd8400b --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/CreateBRMSRawController.java @@ -0,0 +1,440 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.controller; + + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintWriter; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.xml.bind.JAXBElement; + +//import org.apache.commons.logging.Log; +//import org.apache.commons.logging.LogFactory; +import org.json.JSONObject; +import org.openecomp.policy.adapter.PolicyAdapter; +import org.openecomp.policy.admin.PolicyNotificationMail; +import org.openecomp.policy.admin.RESTfulPAPEngine; +import org.openecomp.policy.dao.PolicyVersionDao; +import org.openecomp.policy.dao.RuleAlgorithmsDao; +import org.openecomp.policy.dao.WatchPolicyNotificationDao; +import org.openecomp.policy.elk.client.PolicyElasticSearchController; +import org.openecomp.policy.rest.jpa.PolicyVersion; +import org.openecomp.policy.rest.jpa.RuleAlgorithms; +import org.openecomp.portalsdk.core.controller.RestrictedBaseController; +import org.openecomp.portalsdk.core.web.support.UserUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + +import com.att.research.xacml.api.XACML3; +import org.openecomp.policy.xacml.api.XACMLErrorConstants; +import org.openecomp.policy.xacml.util.XACMLPolicyScanner; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.base.Joiner; + +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionsType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeAssignmentExpressionType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.RuleType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +@Controller +@RequestMapping("/") +public class CreateBRMSRawController extends RestrictedBaseController { + + private static final Logger logger = FlexLogger.getLogger(CreateBRMSRawController.class); + + private static RuleAlgorithmsDao ruleAlgorithmsDao; + private static PolicyVersionDao policyVersionDao; + private static WatchPolicyNotificationDao policyNotificationDao; + + @Autowired + private CreateBRMSRawController(RuleAlgorithmsDao ruleAlgorithmsDao, PolicyVersionDao policyVersionDao, WatchPolicyNotificationDao policyNotificationDao){ + CreateBRMSRawController.policyVersionDao = policyVersionDao; + CreateBRMSRawController.ruleAlgorithmsDao = ruleAlgorithmsDao; + CreateBRMSRawController.policyNotificationDao = policyNotificationDao; + } + + public CreateBRMSRawController(){} + protected PolicyAdapter policyAdapter = null; + private ArrayList attributeList; + private String ruleID = ""; + public String newPolicyID() { + return Joiner.on(':').skipNulls().join((PolicyController.getDomain().startsWith("urn") ? null: "urn"), + PolicyController.getDomain().replaceAll("[/\\\\.]", ":"), "xacml", "policy", "id", UUID.randomUUID()); + } + + + + @RequestMapping(value={"/policyController/save_BRMSRawPolicy.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveBRMSRawPolicy(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + String userId = UserUtils.getUserIdFromCookie(request); + RESTfulPAPEngine engine = (RESTfulPAPEngine) PolicyController.getPapEngine(); + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + PolicyAdapter policyData = (PolicyAdapter)mapper.readValue(root.get("policyData").get("policy").toString(), PolicyAdapter.class); + + if(root.get("policyData").get("model").get("type").toString().replace("\"", "").equals("file")){ + policyData.isEditPolicy = true; + } + if(root.get("policyData").get("model").get("path").size() != 0){ + String dirName = ""; + for(int i = 0; i < root.get("policyData").get("model").get("path").size(); i++){ + dirName = dirName.replace("\"", "") + root.get("policyData").get("model").get("path").get(i).toString().replace("\"", "") + File.separator; + } + policyData.setDomainDir(dirName.substring(0, dirName.lastIndexOf(File.separator))); + }else{ + policyData.setDomainDir(root.get("policyData").get("model").get("name").toString().replace("\"", "")); + } + + if (policyData.getTtlDate()==null){ + policyData.setTtlDate("NA"); + }else{ + String dateTTL = policyData.getTtlDate(); + String newDate = convertDate(dateTTL); + policyData.setTtlDate(newDate); + } + + int version = 0; + int highestVersion = 0; + int descriptionVersion = 0; + //get the highest version of policy from policy version table. + //getting the sub scope domain where the policy is created or updated + String dbCheckPolicyName = policyData.getDomainDir() + File.separator + "Config_BRMS_Raw_" + policyData.getPolicyName(); + List policyVersionList = policyVersionDao.getPolicyVersionEntityByName(dbCheckPolicyName); + if (policyVersionList.size() > 0) { + for(int i = 0; i < policyVersionList.size(); i++) { + PolicyVersion entityItem = policyVersionList.get(i); + if(entityItem.getPolicyName().equals(dbCheckPolicyName)){ + highestVersion = entityItem.getHigherVersion(); + } + } + } + if(highestVersion != 0){ + version = highestVersion; + descriptionVersion = highestVersion +1; + }else{ + version = 1; + descriptionVersion = 1; + } + + //set policy adapter values for Building JSON object containing policy data + String createdBy = ""; + String modifiedBy = userId; + if(descriptionVersion == 1){ + createdBy = userId; + }else{ + String policyName = PolicyController.getGitPath().toAbsolutePath().toString() + File.separator + policyData.getDomainDir() + File.separator + policyData.getOldPolicyFileName() + ".xml"; + File policyPath = new File(policyName); + try { + createdBy = XACMLPolicyScanner.getCreatedBy(policyPath.toPath()); + } catch (IOException e) { + createdBy = "guest"; + } + } + + policyData.setPolicyDescription(policyData.getPolicyDescription()+ "@CreatedBy:" +createdBy + "@CreatedBy:" + "@ModifiedBy:" +modifiedBy + "@ModifiedBy:"); + Map successMap = new HashMap(); + Map attributeMap = new HashMap(); + //set the Rule Combining Algorithm Id to be sent to PAP-REST via JSON + List ruleAlgorithmsList = ruleAlgorithmsDao.getRuleAlgorithms(); + for (int i = 0; i < ruleAlgorithmsList.size(); i++) { + RuleAlgorithms a = ruleAlgorithmsList.get(i); + if (a.getXacmlId().equals(XACML3.ID_RULE_PERMIT_OVERRIDES.stringValue())) { + policyData.setRuleCombiningAlgId(a.getXacmlId()); + break; + } + } + + if(policyData.getAttributes().size() > 0){ + for(Object attribute : policyData.getAttributes()){ + if(attribute instanceof LinkedHashMap){ + String key = ((LinkedHashMap) attribute).get("key").toString(); + String value = ((LinkedHashMap) attribute).get("value").toString(); + attributeMap.put(key, value); + } + } + } + + + policyData.setEcompName("DROOLS"); + policyData.setConfigName("BRMS_RAW_RULE"); + policyData.setDynamicFieldConfigAttributes(attributeMap); + if (policyData.isEditPolicy()){ + //increment the version and set in policyAdapter + policyData.setVersion(String.valueOf(version)); + policyData.setHighestVersion(version); + policyData.setPolicyID(this.newPolicyID()); + policyData.setRuleID(ruleID); + successMap = engine.updatePolicyRequest(policyData); + } else { + //send it for policy creation + policyData.setVersion(String.valueOf(version)); + policyData.setHighestVersion(version); + successMap = engine.createPolicyRequest(policyData); + } + + if (successMap.containsKey("success")) { + // Add it into our tree + Path finalPolicyPath = null; + finalPolicyPath = Paths.get(successMap.get("success")); + PolicyElasticSearchController controller = new PolicyElasticSearchController(); + controller.updateElk(finalPolicyPath.toString()); + File file = finalPolicyPath.toFile(); + if(file != null){ + String policyName = file.toString(); + String removePath = policyName.substring(policyName.indexOf("repository")+11); + String removeXml = removePath.replace(".xml", ""); + String removeExtension = removeXml.substring(0, removeXml.indexOf(".")); + List versionList = policyVersionDao.getPolicyVersionEntityByName(removeExtension); + if (versionList.size() > 0) { + for(int i = 0; i < versionList.size(); i++) { + PolicyVersion entityItem = versionList.get(i); + if(entityItem.getPolicyName().equals(removeExtension)){ + version = entityItem.getHigherVersion() +1; + entityItem.setActiveVersion(version); + entityItem.setHigherVersion(version); + entityItem.setModifiedBy(userId); + policyVersionDao.update(entityItem); + if(policyData.isEditPolicy){ + PolicyNotificationMail email = new PolicyNotificationMail(); + String mode = "EditPolicy"; + String policyNameForEmail = policyData.getDomainDir() + File.separator + policyData.getOldPolicyFileName() + ".xml"; + email.sendMail(entityItem, policyNameForEmail, mode, policyNotificationDao); + } + } + } + }else{ + PolicyVersion entityItem = new PolicyVersion(); + entityItem.setActiveVersion(version); + entityItem.setHigherVersion(version); + entityItem.setPolicyName(removeExtension); + entityItem.setCreatedBy(userId); + entityItem.setModifiedBy(userId); + policyVersionDao.Save(entityItem); + } + } + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = mapper.writeValueAsString(successMap); + JSONObject j = new JSONObject("{policyData: " + responseString + "}"); + out.write(j.toString()); + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + private String convertDate(String dateTTL) { + String formateDate = null; + String[] date = dateTTL.split("T"); + String[] parts = date[0].split("-"); + + formateDate = parts[2] + "-" + parts[1] + "-" + parts[0]; + return formateDate; + } + + public void PrePopulateBRMSRawPolicyData(PolicyAdapter policyAdapter) { + attributeList = new ArrayList(); + if (policyAdapter.getPolicyData() instanceof PolicyType) { + PolicyType policy = (PolicyType) policyAdapter.getPolicyData(); + policyAdapter.setOldPolicyFileName(policyAdapter.getPolicyName()); + // policy name value is the policy name without any prefix and + // Extensions. + String policyNameValue = policyAdapter.getPolicyName().substring(policyAdapter.getPolicyName().indexOf("BRMS_Raw_") +9, policyAdapter.getPolicyName().lastIndexOf(".")); + if (logger.isDebugEnabled()) { + logger.debug("Prepopulating form data for BRMS RAW Policy selected:" + policyAdapter.getPolicyName()); + } + policyAdapter.setPolicyName(policyNameValue); + String description = ""; + try{ + description = policy.getDescription().substring(0, policy.getDescription().indexOf("@CreatedBy:")); + }catch(Exception e){ + description = policy.getDescription(); + } + policyAdapter.setPolicyDescription(description); + // Set Attributes. + AdviceExpressionsType expressionTypes = ((RuleType)policy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().get(0)).getAdviceExpressions(); + for( AdviceExpressionType adviceExpression: expressionTypes.getAdviceExpression()){ + for(AttributeAssignmentExpressionType attributeAssignment: adviceExpression.getAttributeAssignmentExpression()){ + if(attributeAssignment.getAttributeId().startsWith("key:")){ + Map attribute = new HashMap(); + String key = attributeAssignment.getAttributeId().replace("key:", ""); + attribute.put("key", key); + JAXBElement attributevalue = (JAXBElement) attributeAssignment.getExpression(); + String value = (String) attributevalue.getValue().getContent().get(0); + attribute.put("value", value); + attributeList.add(attribute); + } + } + policyAdapter.setAttributes(attributeList); + } + String ruleConfigName = policyAdapter.getDirPath().replace(File.separator, ".")+ "." + policyAdapter.getOldPolicyFileName() + "."; + policyAdapter.setConfigBodyPath(ruleConfigName); + // Get the target data under policy. + policyAdapter.setConfigBodyData(readFile(policyAdapter)); + TargetType target = policy.getTarget(); + if (target != null) { + // Under target we have AnyOFType + List anyOfList = target.getAnyOf(); + if (anyOfList != null) { + Iterator iterAnyOf = anyOfList.iterator(); + while (iterAnyOf.hasNext()) { + AnyOfType anyOf = iterAnyOf.next(); + // Under AnyOFType we have AllOFType + List allOfList = anyOf.getAllOf(); + if (allOfList != null) { + Iterator iterAllOf = allOfList.iterator(); + int index = 0; + while (iterAllOf.hasNext()) { + AllOfType allOf = iterAllOf.next(); + // Under AllOFType we have Match + List matchList = allOf.getMatch(); + if (matchList != null) { + Iterator iterMatch = matchList.iterator(); + while (iterMatch.hasNext()) { + MatchType match = iterMatch.next(); + // + // Under the match we have attributevalue and + // attributeDesignator. So,finally down to the actual attribute. + // + AttributeValueType attributeValue = match.getAttributeValue(); + String value = (String) attributeValue.getContent().get(0); + + if (index == 3){ + policyAdapter.setRiskType(value); + } + + if (index == 4){ + policyAdapter.setRiskLevel(value); + } + + if (index == 5){ + policyAdapter.setGuard(value); + } + if (index == 6 && !value.contains("NA")){ + String newDate = convertDate(value, true); + policyAdapter.setTtlDate(newDate); + } + + index++; + } + } + } + } + } + } + } + } + } + + private String convertDate(String dateTTL, boolean portalType) { + String formateDate = null; + String[] date; + String[] parts; + + if (portalType){ + parts = dateTTL.split("-"); + formateDate = parts[2] + "-" + parts[1] + "-" + parts[0] + "T05:00:00.000Z"; + } else { + date = dateTTL.split("T"); + parts = date[0].split("-"); + formateDate = parts[2] + "-" + parts[1] + "-" + parts[0]; + } + return formateDate; + } + + // Here we are reading the configurations file + protected String readFile(PolicyAdapter policyAdapter) { + String fileLocation = null; + String fileName = policyAdapter.getConfigBodyPath(); + if (fileName != null ) { + fileLocation = PolicyController.getConfigHome(); + } + if (fileLocation == null) { + return fileLocation; + } + File dir = new File(fileLocation); + File[] listOfFiles = dir.listFiles(); + for (File file : listOfFiles) { + if (file.isFile() && file.getName().contains(fileName) && file.toString().endsWith(".txt")) { + // Reading the file + try (BufferedReader br = new BufferedReader(new FileReader(file))) { + StringBuilder sb = new StringBuilder(); + String line = br.readLine(); + while (line != null) { + sb.append(line); + sb.append("\n"); + line = br.readLine(); + } + return sb.toString(); + } catch (FileNotFoundException e) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e.getMessage()); + } catch (IOException e1) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e1.getMessage()); + } + } + } + return null; + } + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/CreateClosedLoopFaultController.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/CreateClosedLoopFaultController.java new file mode 100644 index 000000000..b41f7e0ef --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/CreateClosedLoopFaultController.java @@ -0,0 +1,889 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.controller; + + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import javax.json.Json; +import javax.json.JsonReader; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.json.JSONObject; +import org.openecomp.policy.adapter.ClosedLoopFaultBody; +import org.openecomp.policy.adapter.ClosedLoopFaultTriggerUISignatures; +import org.openecomp.policy.adapter.ClosedLoopSignatures; +import org.openecomp.policy.adapter.PolicyAdapter; +import org.openecomp.policy.admin.PolicyNotificationMail; +import org.openecomp.policy.admin.RESTfulPAPEngine; +import org.openecomp.policy.dao.PolicyVersionDao; +import org.openecomp.policy.dao.RuleAlgorithmsDao; +import org.openecomp.policy.dao.WatchPolicyNotificationDao; +import org.openecomp.policy.elk.client.PolicyElasticSearchController; +import org.openecomp.policy.rest.dao.VarbindDictionaryDao; +import org.openecomp.policy.rest.jpa.EcompName; +import org.openecomp.policy.rest.jpa.PolicyVersion; +import org.openecomp.policy.rest.jpa.RuleAlgorithms; +import org.openecomp.policy.rest.jpa.VarbindDictionary; +import org.openecomp.portalsdk.core.controller.RestrictedBaseController; +import org.openecomp.portalsdk.core.web.support.UserUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + +import com.att.research.xacml.api.XACML3; +import org.openecomp.policy.xacml.api.XACMLErrorConstants; +import org.openecomp.policy.xacml.util.XACMLPolicyScanner; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; +import com.google.common.base.Joiner; + +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType; + +@Controller +@RequestMapping("/") +public class CreateClosedLoopFaultController extends RestrictedBaseController{ + + private static RuleAlgorithmsDao ruleAlgorithmsDao; + private static PolicyVersionDao policyVersionDao; + private static VarbindDictionaryDao varbindDictionaryDao; + private static WatchPolicyNotificationDao policyNotificationDao; + + @Autowired + private CreateClosedLoopFaultController(RuleAlgorithmsDao ruleAlgorithmsDao, PolicyVersionDao policyVersionDao, VarbindDictionaryDao varbindDictionaryDao, + WatchPolicyNotificationDao policyNotificationDao){ + CreateClosedLoopFaultController.policyVersionDao = policyVersionDao; + CreateClosedLoopFaultController.ruleAlgorithmsDao = ruleAlgorithmsDao; + CreateClosedLoopFaultController.varbindDictionaryDao = varbindDictionaryDao; + CreateClosedLoopFaultController.policyNotificationDao = policyNotificationDao; + } + + public CreateClosedLoopFaultController(){} + protected PolicyAdapter policyAdapter = null; + private String ruleID = ""; + public String newPolicyID() { + return Joiner.on(':').skipNulls().join((PolicyController.getDomain().startsWith("urn") ? null: "urn"), + PolicyController.getDomain().replaceAll("[/\\\\.]", ":"), "xacml", "policy", "id", UUID.randomUUID()); + } + + @RequestMapping(value={"/policyController/save_Faultpolicy.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveFaultPolicy(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + String userId = UserUtils.getUserIdFromCookie(request); + RESTfulPAPEngine engine = (RESTfulPAPEngine) PolicyController.getPapEngine(); + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + PolicyAdapter policyData = (PolicyAdapter)mapper.readValue(root.get("policyData").get("policy").toString(), PolicyAdapter.class); + TrapDatas trapDatas = mapper.readValue(root.get("trapData").toString(), TrapDatas.class); + TrapDatas faultDatas = mapper.readValue(root.get("faultData").toString(), TrapDatas.class); + ClosedLoopGridJSONData policyJsonData = mapper.readValue(root.get("policyData").get("policy").toString(), ClosedLoopGridJSONData.class); + ClosedLoopFaultBody jsonBody = mapper.readValue(root.get("policyData").get("policy").get("jsonBodyData").toString(), ClosedLoopFaultBody.class); + policyData.setDomainDir(root.get("policyData").get("model").get("name").toString().replace("\"", "")); + if(root.get("policyData").get("model").get("type").toString().replace("\"", "").equals("file")){ + policyData.isEditPolicy = true; + } + + if (policyData.getTtlDate()==null){ + policyData.setTtlDate("NA"); + }else{ + String dateTTL = policyData.getTtlDate(); + String newDate = convertDate(dateTTL); + policyData.setTtlDate(newDate); + } + + if(root.get("policyData").get("model").get("path").size() != 0){ + String dirName = ""; + for(int i = 0; i < root.get("policyData").get("model").get("path").size(); i++){ + dirName = dirName.replace("\"", "") + root.get("policyData").get("model").get("path").get(i).toString().replace("\"", "") + File.separator; + } + policyData.setDomainDir(dirName.substring(0, dirName.lastIndexOf(File.separator))); + }else{ + policyData.setDomainDir(root.get("policyData").get("model").get("name").toString().replace("\"", "")); + } + ArrayList trapSignatureDatas = new ArrayList(); + if(trapDatas.getTrap1() != null){ + trapSignatureDatas.add(trapDatas); + } + ArrayList faultSignatureDatas = new ArrayList(); + if(faultDatas.getTrap1() != null){ + faultSignatureDatas.add(faultDatas); + } + + String resultBody = ""; + if(!policyJsonData.getConnecttriggerSignatures().isEmpty()){ + resultBody = resultBody + "("; + for(int i = policyJsonData.getConnecttriggerSignatures().size()-1; i>=0 ; i--){ + String connectBody = connectTriggerSignature(i, policyJsonData.getConnecttriggerSignatures(), trapSignatureDatas.get(0)); + resultBody = resultBody + connectBody; + } + resultBody = resultBody + ")"; + }else{ + if(!trapSignatureDatas.isEmpty()){ + resultBody = callTrap("nill", trapSignatureDatas.get(0)); + } + } + ClosedLoopSignatures triggerSignatures = new ClosedLoopSignatures(); + triggerSignatures.setSignatures(resultBody); + if(policyData.getClearTimeOut() != null){ + triggerSignatures.setTimeWindow(Integer.parseInt(policyData.getClearTimeOut())); + triggerSignatures.setTrapMaxAge(Integer.parseInt(policyData.getTrapMaxAge())); + ClosedLoopFaultTriggerUISignatures uiTriggerSignatures = new ClosedLoopFaultTriggerUISignatures(); + if(!trapSignatureDatas.isEmpty()){ + uiTriggerSignatures.setSignatures(getUITriggerSignature("Trap", trapSignatureDatas.get(0))); + if(!policyJsonData.getConnecttriggerSignatures().isEmpty()){ + uiTriggerSignatures.setConnectSignatures(getUIConnectTraps(policyJsonData.getConnecttriggerSignatures())); + } + } + jsonBody.setTriggerSignaturesUsedForUI(uiTriggerSignatures); + jsonBody.setTriggerTimeWindowUsedForUI(Integer.parseInt(policyData.getClearTimeOut())); + jsonBody.setTrapMaxAgeUsedForUI(Integer.parseInt(policyData.getTrapMaxAge())); + } + + jsonBody.setTriggerSignatures(triggerSignatures); + String faultBody = ""; + if(!policyJsonData.getConnectVerificationSignatures().isEmpty()){ + faultBody = faultBody + "("; + for(int i = policyJsonData.getConnectVerificationSignatures().size()-1; i>=0 ; i--){ + String connectBody = connectTriggerSignature(i, policyJsonData.getConnectVerificationSignatures(), faultSignatureDatas.get(0)); + faultBody = faultBody + connectBody; + } + faultBody = faultBody + ")"; + }else{ + if(!faultSignatureDatas.isEmpty()){ + faultBody = callTrap("nill", faultSignatureDatas.get(0)); + } + } + ClosedLoopSignatures faultSignatures = new ClosedLoopSignatures(); + faultSignatures.setSignatures(faultBody); + if(policyData.getVerificationclearTimeOut() != null){ + faultSignatures.setTimeWindow(Integer.parseInt(policyData.getVerificationclearTimeOut())); + ClosedLoopFaultTriggerUISignatures uifaultSignatures = new ClosedLoopFaultTriggerUISignatures(); + if(!faultSignatureDatas.isEmpty()){ + uifaultSignatures.setSignatures(getUITriggerSignature("Fault", faultSignatureDatas.get(0))); + if(!policyJsonData.getConnectVerificationSignatures().isEmpty()){ + uifaultSignatures.setConnectSignatures(getUIConnectTraps(policyJsonData.getConnectVerificationSignatures())); + } + } + + jsonBody.setVerificationSignaturesUsedForUI(uifaultSignatures); + jsonBody.setVerfificationTimeWindowUsedForUI(Integer.parseInt(policyData.getVerificationclearTimeOut())); + } + jsonBody.setVerificationSignatures(faultSignatures); + ObjectWriter om = new ObjectMapper().writer(); + String json = om.writeValueAsString(jsonBody); + policyData.setJsonBody(json); + + int version = 0; + int highestVersion = 0; + int descriptionVersion = 0; + //get the highest version of policy from policy version table. + //getting the sub scope domain where the policy is created or updated + String dbCheckPolicyName = policyData.getDomainDir() + File.separator + "Config_Fault_" + policyData.getPolicyName(); + List policyVersionList = policyVersionDao.getPolicyVersionEntityByName(dbCheckPolicyName); + if (policyVersionList.size() > 0) { + for(int i = 0; i < policyVersionList.size(); i++) { + PolicyVersion entityItem = policyVersionList.get(i); + if(entityItem.getPolicyName().equals(dbCheckPolicyName)){ + highestVersion = entityItem.getHigherVersion(); + } + } + } + if(highestVersion != 0){ + version = highestVersion; + descriptionVersion = highestVersion +1; + }else{ + version = 1; + descriptionVersion = 1; + } + + //set policy adapter values for Building JSON object containing policy data + String createdBy = ""; + String modifiedBy = userId; + if(descriptionVersion == 1){ + createdBy = userId; + }else{ + String policyName = PolicyController.getGitPath().toAbsolutePath().toString() + File.separator + policyData.getDomainDir() + File.separator + policyData.getOldPolicyFileName() + ".xml"; + File policyPath = new File(policyName); + try { + createdBy = XACMLPolicyScanner.getCreatedBy(policyPath.toPath()); + } catch (IOException e) { + createdBy = "guest"; + } + } + + policyData.setPolicyDescription(policyData.getPolicyDescription()+ "@CreatedBy:" +createdBy + "@CreatedBy:" + "@ModifiedBy:" +modifiedBy + "@ModifiedBy:"); + Map successMap = new HashMap(); + //set the Rule Combining Algorithm Id to be sent to PAP-REST via JSON + List ruleAlgorithsList = ruleAlgorithmsDao.getRuleAlgorithms(); + for (int i = 0; i < ruleAlgorithsList.size(); i++) { + RuleAlgorithms a = ruleAlgorithsList.get(i); + if (a.getXacmlId().equals(XACML3.ID_RULE_PERMIT_OVERRIDES.stringValue())) { + policyData.setRuleCombiningAlgId(a.getXacmlId()); + break; + } + } + if (policyData.isEditPolicy()){ + //increment the version and set in policyAdapter + policyData.setVersion(String.valueOf(version)); + policyData.setHighestVersion(version); + policyData.setPolicyID(this.newPolicyID()); + policyData.setRuleID(ruleID); + successMap = engine.updatePolicyRequest(policyData); + } else { + //send it for policy creation + policyData.setVersion(String.valueOf(version)); + policyData.setHighestVersion(version); + successMap = engine.createPolicyRequest(policyData); + + } + + if (successMap.containsKey("success")) { + // Add it into our tree + Path finalPolicyPath = null; + finalPolicyPath = Paths.get(successMap.get("success")); + PolicyElasticSearchController controller = new PolicyElasticSearchController(); + controller.updateElk(finalPolicyPath.toString()); + File file = finalPolicyPath.toFile(); + if(file != null){ + String policyName = file.toString(); + String removePath = policyName.substring(policyName.indexOf("repository")+11); + String removeXml = removePath.replace(".xml", ""); + String removeExtension = removeXml.substring(0, removeXml.indexOf(".")); + List versionlist = policyVersionDao.getPolicyVersionEntityByName(removeExtension); + if (versionlist.size() > 0) { + for(int i = 0; i < versionlist.size(); i++) { + PolicyVersion entityItem = versionlist.get(i); + if(entityItem.getPolicyName().equals(removeExtension)){ + version = entityItem.getHigherVersion() +1; + entityItem.setActiveVersion(version); + entityItem.setHigherVersion(version); + entityItem.setModifiedBy(userId); + policyVersionDao.update(entityItem); + if(policyData.isEditPolicy){ + PolicyNotificationMail email = new PolicyNotificationMail(); + String mode = "EditPolicy"; + String policyNameForEmail = policyData.getDomainDir() + File.separator + policyData.getOldPolicyFileName() + ".xml"; + email.sendMail(entityItem, policyNameForEmail, mode, policyNotificationDao); + } + } + } + }else{ + PolicyVersion entityItem = new PolicyVersion(); + entityItem.setActiveVersion(version); + entityItem.setHigherVersion(version); + entityItem.setPolicyName(removeExtension); + entityItem.setCreatedBy(userId); + entityItem.setModifiedBy(userId); + policyVersionDao.Save(entityItem); + } + } + } + + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = mapper.writeValueAsString(successMap); + JSONObject j = new JSONObject("{policyData: " + responseString + "}"); + out.write(j.toString()); + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + //connect traps data set to JSON Body as String + @SuppressWarnings("rawtypes") + private String getUIConnectTraps(ArrayList connectTrapSignatures) { + String resultBody = ""; + String connectMainBody = ""; + for(int j = 0; j < connectTrapSignatures.size(); j++){ + Map connectTraps = (Map)connectTrapSignatures.get(j); + String connectBody = ""; + Object object = connectTraps; + if(object instanceof LinkedHashMap){ + String notBox = ""; + if(((LinkedHashMap) object).keySet().contains("notBox")){ + notBox = ((LinkedHashMap) object).get("notBox").toString(); + } + String connectTrap1 = ((LinkedHashMap) object).get("connectTrap1").toString(); + String trapCount1 = ((LinkedHashMap) object).get("trapCount1").toString(); + String operatorBox = ((LinkedHashMap) object).get("operatorBox").toString(); + String connectTrap2 = ((LinkedHashMap) object).get("connectTrap2").toString(); + String trapCount2 = ((LinkedHashMap) object).get("trapCount2").toString(); + connectBody = notBox + "@!" + connectTrap1 + "@!" + trapCount1 + "@!" + operatorBox + "@!" + connectTrap2 + "@!" + trapCount2 + "#!?!"; + } + resultBody = resultBody + connectBody; + } + connectMainBody = connectMainBody + resultBody; + return connectMainBody; + } + + + + // get Trigger signature from JSON body + private String getUITriggerSignature(String trap, Object object2) { + String triggerBody = ""; + TrapDatas trapDatas = (TrapDatas) object2; + ArrayList attributeList = new ArrayList<>(); + // Read the Trap + if(trap.startsWith("Trap")){ + if(trapDatas.getTrap1()!= null){ + attributeList.add(trapDatas.getTrap1()); + } + if(trapDatas.getTrap2()!= null){ + attributeList.add(trapDatas.getTrap2()); + } + if(trapDatas.getTrap3()!= null){ + attributeList.add(trapDatas.getTrap3()); + } + if(trapDatas.getTrap4()!= null){ + attributeList.add(trapDatas.getTrap4()); + } + if(trapDatas.getTrap5()!= null){ + attributeList.add(trapDatas.getTrap5()); + } + if(trapDatas.getTrap6()!= null){ + attributeList.add(trapDatas.getTrap6()); + } + }else{ + if(trap.equals("Fault")){ + if(trapDatas.getTrap1()!= null){ + attributeList.add(trapDatas.getTrap1()); + } + if(trapDatas.getTrap2()!= null){ + attributeList.add(trapDatas.getTrap2()); + } + if(trapDatas.getTrap3()!= null){ + attributeList.add(trapDatas.getTrap3()); + } + if(trapDatas.getTrap4()!= null){ + attributeList.add(trapDatas.getTrap4()); + } + if(trapDatas.getTrap5()!= null){ + attributeList.add(trapDatas.getTrap5()); + } + if(trapDatas.getTrap6()!= null){ + attributeList.add(trapDatas.getTrap6()); + } + } + } + + for(int j = 0; j < attributeList.size(); j++){ + String signatureBody = ""; + ArrayList connectTraps = (ArrayList) attributeList.get(j); + for(int i =0 ; i < connectTraps.size(); i++){ + String connectBody = ""; + Object object = connectTraps.get(i); + if(object instanceof LinkedHashMap){ + String notBox = ""; + if(((LinkedHashMap) object).keySet().contains("notBox")){ + notBox = ((LinkedHashMap) object).get("notBox").toString(); + } + String trigger1 = ((LinkedHashMap) object).get("trigger1").toString(); + String operatorBox = ((LinkedHashMap) object).get("operatorBox").toString(); + String trigger2 = ((LinkedHashMap) object).get("trigger2").toString(); + connectBody = notBox + "@!" + trigger1 + "@!" + operatorBox + "@!" + trigger2 + "#!"; + } + signatureBody = signatureBody + connectBody; + } + triggerBody = triggerBody + signatureBody + "?!"; + } + + return triggerBody; + } + + private String convertDate(String dateTTL) { + String formateDate = null; + String[] date = dateTTL.split("T"); + String[] parts = date[0].split("-"); + + formateDate = parts[2] + "-" + parts[1] + "-" + parts[0]; + return formateDate; + } + + private String callTrap(String trap, Object object) { + String signatureBody = ""; + TrapDatas trapDatas = (TrapDatas) object; + ArrayList attributeList = new ArrayList<>(); + // Read the Trap + if(!trap.equals("nill")){ + try{ + if(trap.startsWith("Trap")){ + if(trap.equals("Trap1")){ + attributeList = trapDatas.getTrap1(); + }else if(trap.equals("Trap2")){ + attributeList = trapDatas.getTrap2(); + }else if(trap.equals("Trap3")){ + attributeList = trapDatas.getTrap3(); + }else if(trap.equals("Trap4")){ + attributeList = trapDatas.getTrap4(); + }else if(trap.equals("Trap5")){ + attributeList = trapDatas.getTrap5(); + }else if(trap.equals("Trap6")){ + attributeList = trapDatas.getTrap6(); + } + }else{ + if(trap.equals("Fault")){ + if(trap.equals("Fault1")){ + attributeList = trapDatas.getTrap1(); + }else if(trap.equals("Fault2")){ + attributeList = trapDatas.getTrap2(); + }else if(trap.equals("Fault3")){ + attributeList = trapDatas.getTrap3(); + }else if(trap.equals("Fault4")){ + attributeList = trapDatas.getTrap4(); + }else if(trap.equals("Fault5")){ + attributeList = trapDatas.getTrap5(); + }else if(trap.equals("Fault6")){ + attributeList = trapDatas.getTrap6(); + } + } + } + } catch(Exception e){ + return "(" + trap + ")"; + } + }else{ + if(trapDatas.getTrap1()!=null){ + attributeList = trapDatas.getTrap1(); + }else{ + return ""; + } + } + signatureBody = signatureBody + "(" + readAttributes(attributeList, attributeList.size()-1) + ")"; + return signatureBody; + } + + private String readAttributes(ArrayList object, int index) { + String attributes = ""; + Map trapSignatures = (Map) object.get(index); + // Read the Elements. + Object notBox = ""; + if(trapSignatures.keySet().contains("notBox")){ + notBox = trapSignatures.get("notBox"); + } + if(notBox!=null){ + attributes = attributes + notBox.toString(); + } + Object trapName1 = trapSignatures.get("trigger1"); + if(trapName1!=null){ + String attrib = trapName1.toString(); + if(attrib.startsWith("A")){ + try{ + int iy = Integer.parseInt(attrib.substring(1))-1; + attributes = attributes + "(" + readAttributes(object, iy) + ")"; + }catch(NumberFormatException e){ + try { + attrib = getVarbindOID(attrib); + attributes = attributes + "("+ URLEncoder.encode(attrib, "UTF-8")+ ")"; + } catch (UnsupportedEncodingException e1) { + //logger.error("Caused Exception while Encoding Varbind Dictionary Values"+e1); + } + } + }else{ + try { + attrib = getVarbindOID(attrib); + attributes = attributes + "("+ URLEncoder.encode(attrib, "UTF-8")+ ")"; + } catch (UnsupportedEncodingException e) { + //logger.error("Caused Exception while Encoding Varbind Dictionary Values"+e); + } + } + }else{ + return ""; + } + Object comboBox = trapSignatures.get("operatorBox"); + if(comboBox!=null){ + attributes = attributes + comboBox.toString(); + }else{ + return attributes; + } + Object trapName2 = trapSignatures.get("trigger2"); + if(trapName2!=null){ + String attrib = trapName2.toString(); + if(attrib.startsWith("A")){ + try{ + int iy = Integer.parseInt(attrib.substring(1))-1; + attributes = attributes + "(" + readAttributes(object, iy) + ")"; + }catch(NumberFormatException e){ + try { + attrib = getVarbindOID(attrib); + attributes = attributes + "("+ URLEncoder.encode(attrib, "UTF-8") + ")"; + } catch (UnsupportedEncodingException e1) { + //logger.error("Caused Exception while Encoding Varbind Dictionary Values"+e1); + } + } + }else{ + try { + attrib = getVarbindOID(attrib); + attributes = attributes + "("+ URLEncoder.encode(attrib, "UTF-8") + ")"; + } catch (UnsupportedEncodingException e) { + //logger.error("Caused Exception while Encoding Varbind Dictionary Values"+e); + } + } + } + return attributes; + } + + private String getVarbindOID(String attrib) { + VarbindDictionary varbindId = varbindDictionaryDao.getVarbindEntityByName(attrib).get(0); + return varbindId.getVarbindOID(); + } + + private String connectTriggerSignature(int index, ArrayList triggerSignatures, Object object) { + String resultBody = ""; + Map connectTraps = (Map) triggerSignatures.get(index); + try{ + String notBox = ""; + if(connectTraps.keySet().contains("notBox")){ + notBox = connectTraps.get("notBox"); + } + resultBody = resultBody + "(" + notBox; + }catch(NullPointerException e){ + resultBody = resultBody + "("; + } + String connectTrap1 = connectTraps.get("connectTrap1"); + if(connectTrap1.startsWith("Trap") || connectTrap1.startsWith("Fault")){ + String trapBody = callTrap(connectTrap1, object); + if(trapBody!=null){ + resultBody = resultBody + trapBody; + } + }else if(connectTrap1.startsWith("C")){ + for(int i=0; i<= triggerSignatures.size(); i++){ + Map triggerSignature = (Map) triggerSignatures.get(i); + if(triggerSignature.get("id").equals(connectTrap1)){ + resultBody = resultBody + "("; + String connectBody = connectTriggerSignature(i, triggerSignatures, object); + resultBody = resultBody + connectBody + ")"; + }else{ + i++; + } + } + } + try{ + String trapCount1 = connectTraps.get("trapCount1"); + resultBody = resultBody + ", Time = " + trapCount1 + ")"; + }catch(NullPointerException e){ + } + try{ + String operatorBox = connectTraps.get("operatorBox"); + resultBody = resultBody + operatorBox +"("; + }catch (NullPointerException e){ + } + try{ + String connectTrap2 = connectTraps.get("connectTrap2"); + if(connectTrap2.startsWith("Trap") || connectTrap2.startsWith("Fault")){ + String trapBody = callTrap(connectTrap2, object); + if(trapBody!=null){ + resultBody = resultBody + trapBody; + } + }else if(connectTrap2.startsWith("C")){ + for(int i=0; i<= triggerSignatures.size(); i++){ + Map triggerSignature = (Map) triggerSignatures.get(i); + if(triggerSignature.get("id").equals(connectTrap2)){ + resultBody = resultBody + "("; + String connectBody = connectTriggerSignature(i, triggerSignatures, object); + resultBody = resultBody + connectBody + ")"; + }else{ + i++; + } + } + } + }catch(NullPointerException e){ + } + try{ + String trapCount2 = connectTraps.get("trapCount2"); + resultBody = resultBody + ", Time = " + trapCount2 + ")"; + }catch(NullPointerException e){ + } + return resultBody; + } + + public void PrePopulateClosedLoopFaultPolicyData(PolicyAdapter policyAdapter) { + if (policyAdapter.getPolicyData() instanceof PolicyType) { + Object policyData = policyAdapter.getPolicyData(); + PolicyType policy = (PolicyType) policyData; + policyAdapter.setOldPolicyFileName(policyAdapter.getPolicyName()); + String policyNameValue = policyAdapter.getPolicyName().substring(policyAdapter.getPolicyName().indexOf("Fault_") +6 , policyAdapter.getPolicyName().lastIndexOf(".")); + policyAdapter.setPolicyName(policyNameValue); + String description = ""; + try{ + description = policy.getDescription().substring(0, policy.getDescription().indexOf("@CreatedBy:")); + }catch(Exception e){ + description = policy.getDescription(); + } + policyAdapter.setPolicyDescription(description); + // Get the target data under policy. + TargetType target = policy.getTarget(); + if (target != null) { + // Under target we have AnyOFType + List anyOfList = target.getAnyOf(); + if (anyOfList != null) { + Iterator iterAnyOf = anyOfList.iterator(); + while (iterAnyOf.hasNext()) { + AnyOfType anyOf = iterAnyOf.next(); + // Under AnyOFType we have AllOFType + List allOfList = anyOf.getAllOf(); + if (allOfList != null) { + Iterator iterAllOf = allOfList.iterator(); + int index = 0; + while (iterAllOf.hasNext()) { + AllOfType allOf = iterAllOf.next(); + // Under AllOFType we have Match + List matchList = allOf.getMatch(); + if (matchList != null) { + Iterator iterMatch = matchList.iterator(); + while (iterMatch.hasNext()) { + MatchType match = iterMatch.next(); + // + // Under the match we have attributevalue and + // attributeDesignator. So,finally down to the actual attribute. + // + AttributeValueType attributeValue = match.getAttributeValue(); + String value = (String) attributeValue.getContent().get(0); + + // First match in the target is EcompName, so set that value. + if (index == 1) { + policyAdapter.setEcompName(value); + EcompName ecompName = new EcompName(); + ecompName.setEcompName(value); + policyAdapter.setEcompNameField(ecompName); + } + if (index == 2){ + policyAdapter.setRiskType(value); + } + + if (index == 3){ + policyAdapter.setRiskLevel(value); + } + + if (index == 4){ + policyAdapter.setGuard(value); + } + if (index == 5 && !value.contains("NA")){ + String newDate = convertDate(value, true); + policyAdapter.setTtlDate(newDate); + } + index++; + } + } + } + } + } + } + } + String jsonBodyName = policyAdapter.getDirPath().replace(File.separator, ".")+ "." + policyAdapter.getOldPolicyFileName() + "."; + policyAdapter.setConfigBodyPath(jsonBodyName); + readClosedLoopJSONFile(policyAdapter); + } + + } + + private String convertDate(String dateTTL, boolean portalType) { + String formateDate = null; + String[] date; + String[] parts; + + if (portalType){ + parts = dateTTL.split("-"); + formateDate = parts[2] + "-" + parts[1] + "-" + parts[0] + "T05:00:00.000Z"; + } else { + date = dateTTL.split("T"); + parts = date[0].split("-"); + formateDate = parts[2] + "-" + parts[1] + "-" + parts[0]; + } + return formateDate; + } + + private String readClosedLoopJSONFile(PolicyAdapter policyAdapter) { + String fileLocation = null; + String fileName = policyAdapter.getConfigBodyPath(); + if (fileName != null ) { + fileLocation = PolicyController.getConfigHome(); + } + if (fileLocation == null) { + return fileLocation; + } + File dir = new File(fileLocation); + File[] listOfFiles = dir.listFiles(); + for (File file : listOfFiles) { + if (file.isFile() && file.getName().contains(fileName)) { + FileInputStream inputStream = null; + String location = file.toString(); + try { + inputStream = new FileInputStream(location); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + if (location.endsWith("json")) { + JsonReader jsonReader = null; + jsonReader = Json.createReader(inputStream); + ObjectMapper mapper = new ObjectMapper(); + try { + ClosedLoopFaultBody closedLoopBody = mapper.readValue(jsonReader.read().toString(), ClosedLoopFaultBody.class); + if(closedLoopBody.getClosedLoopPolicyStatus().equalsIgnoreCase("ACTIVE")){ + closedLoopBody.setClosedLoopPolicyStatus("Active"); + }else{ + closedLoopBody.setClosedLoopPolicyStatus("InActive"); + } + policyAdapter.setJsonBodyData(closedLoopBody); + if(closedLoopBody.getTrapMaxAgeUsedForUI() != null){ + policyAdapter.setTrapMaxAge(closedLoopBody.getTrapMaxAgeUsedForUI().toString()); + } + if(closedLoopBody.getTriggerTimeWindowUsedForUI() != null){ + policyAdapter.setClearTimeOut(closedLoopBody.getTriggerTimeWindowUsedForUI().toString()); + } + if(closedLoopBody.getVerfificationTimeWindowUsedForUI() != null){ + policyAdapter.setVerificationclearTimeOut(closedLoopBody.getVerfificationTimeWindowUsedForUI().toString()); + } + + } catch (Exception e) { + e.printStackTrace(); + } + jsonReader.close(); + } + } + } + return null; + } + +} + +class ClosedLoopGridJSONData{ + + private String clearTimeOut; + private String trapMaxAge; + private String verificationclearTimeOut; + private ArrayList connecttriggerSignatures; + private ArrayList connectVerificationSignatures; + + public String getClearTimeOut() { + return clearTimeOut; + } + public void setClearTimeOut(String clearTimeOut) { + this.clearTimeOut = clearTimeOut; + } + public String getTrapMaxAge() { + return trapMaxAge; + } + public void setTrapMaxAge(String trapMaxAge) { + this.trapMaxAge = trapMaxAge; + } + public String getVerificationclearTimeOut() { + return verificationclearTimeOut; + } + public void setVerificationclearTimeOut(String verificationclearTimeOut) { + this.verificationclearTimeOut = verificationclearTimeOut; + } + + + public ArrayList getConnecttriggerSignatures() { + return connecttriggerSignatures; + } + public void setConnecttriggerSignatures(ArrayList connecttriggerSignatures) { + this.connecttriggerSignatures = connecttriggerSignatures; + } + public ArrayList getConnectVerificationSignatures() { + return connectVerificationSignatures; + } + public void setConnectVerificationSignatures(ArrayList connectVerificationSignatures) { + this.connectVerificationSignatures = connectVerificationSignatures; + } +} + +class TrapDatas{ + private ArrayList trap1; + private ArrayList trap2; + private ArrayList trap3; + private ArrayList trap4; + private ArrayList trap5; + private ArrayList trap6; + public ArrayList getTrap1() { + return trap1; + } + public void setTrap1(ArrayList trap1) { + this.trap1 = trap1; + } + public ArrayList getTrap2() { + return trap2; + } + public void setTrap2(ArrayList trap2) { + this.trap2 = trap2; + } + public ArrayList getTrap3() { + return trap3; + } + public void setTrap3(ArrayList trap3) { + this.trap3 = trap3; + } + public ArrayList getTrap4() { + return trap4; + } + public void setTrap4(ArrayList trap4) { + this.trap4 = trap4; + } + public ArrayList getTrap5() { + return trap5; + } + public void setTrap5(ArrayList trap5) { + this.trap5 = trap5; + } + public ArrayList getTrap6() { + return trap6; + } + public void setTrap6(ArrayList trap6) { + this.trap6 = trap6; + } +} \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/CreateClosedLoopPMController.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/CreateClosedLoopPMController.java new file mode 100644 index 000000000..f5e0557f8 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/CreateClosedLoopPMController.java @@ -0,0 +1,422 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.controller; + + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.PrintWriter; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import javax.json.Json; +import javax.json.JsonReader; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.json.JSONObject; +import org.openecomp.policy.adapter.ClosedLoopPMBody; +import org.openecomp.policy.adapter.PolicyAdapter; +import org.openecomp.policy.admin.PolicyNotificationMail; +import org.openecomp.policy.admin.RESTfulPAPEngine; +import org.openecomp.policy.dao.PolicyVersionDao; +import org.openecomp.policy.dao.RuleAlgorithmsDao; +import org.openecomp.policy.dao.WatchPolicyNotificationDao; +import org.openecomp.policy.elk.client.PolicyElasticSearchController; +import org.openecomp.policy.rest.jpa.PolicyVersion; +import org.openecomp.policy.rest.jpa.RuleAlgorithms; +import org.openecomp.portalsdk.core.controller.RestrictedBaseController; +import org.openecomp.portalsdk.core.web.support.UserUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + +import com.att.research.xacml.api.XACML3; +import org.openecomp.policy.xacml.api.XACMLErrorConstants; +import org.openecomp.policy.xacml.util.XACMLPolicyScanner; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.base.Joiner; + +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType; + +@Controller +@RequestMapping("/") +public class CreateClosedLoopPMController extends RestrictedBaseController{ + + private static RuleAlgorithmsDao ruleAlgorithmsDao; + private static PolicyVersionDao policyVersionDao; + private static WatchPolicyNotificationDao policyNotificationDao; + + @Autowired + private CreateClosedLoopPMController(RuleAlgorithmsDao ruleAlgorithmsDao, PolicyVersionDao policyVersionDao, WatchPolicyNotificationDao policyNotificationDao){ + CreateClosedLoopPMController.policyVersionDao = policyVersionDao; + CreateClosedLoopPMController.ruleAlgorithmsDao = ruleAlgorithmsDao; + CreateClosedLoopPMController.policyNotificationDao = policyNotificationDao; + } + + public CreateClosedLoopPMController(){} + + protected PolicyAdapter policyAdapter = null; + private String ruleID = ""; + + public String newPolicyID() { + return Joiner.on(':').skipNulls().join((PolicyController.getDomain().startsWith("urn") ? null: "urn"), + PolicyController.getDomain().replaceAll("[/\\\\.]", ":"), "xacml", "policy", "id", UUID.randomUUID()); + } + + @RequestMapping(value={"/policyController/save_PMPolicy.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView savePMPolicy(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + String userId = UserUtils.getUserIdFromCookie(request); + RESTfulPAPEngine engine = (RESTfulPAPEngine) PolicyController.getPapEngine(); + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + PolicyAdapter policyData = (PolicyAdapter)mapper.readValue(root.get("policyData").get("policy").toString(), PolicyAdapter.class); + + if(root.get("policyData").get("model").get("type").toString().replace("\"", "").equals("file")){ + policyData.isEditPolicy = true; + } + if(root.get("policyData").get("model").get("path").size() != 0){ + String dirName = ""; + for(int i = 0; i < root.get("policyData").get("model").get("path").size(); i++){ + dirName = dirName.replace("\"", "") + root.get("policyData").get("model").get("path").get(i).toString().replace("\"", "") + File.separator; + } + policyData.setDomainDir(dirName.substring(0, dirName.lastIndexOf(File.separator))); + }else{ + policyData.setDomainDir(root.get("policyData").get("model").get("name").toString().replace("\"", "")); + } + + if (policyData.getTtlDate()==null){ + policyData.setTtlDate("NA"); + }else{ + String dateTTL = policyData.getTtlDate(); + String newDate = convertDate(dateTTL); + policyData.setTtlDate(newDate); + } + + int version = 0; + int highestVersion = 0; + int descriptionVersion = 0; + //get the highest version of policy from policy version table. + //getting the sub scope domain where the policy is created or updated + String dbCheckPolicyName = policyData.getDomainDir() + File.separator + "Config_PM_" + policyData.getPolicyName(); + List policyVersionList = policyVersionDao.getPolicyVersionEntityByName(dbCheckPolicyName); + if (policyVersionList.size() > 0) { + for(int i = 0; i < policyVersionList.size(); i++) { + PolicyVersion entityItem = policyVersionList.get(i); + if(entityItem.getPolicyName().equals(dbCheckPolicyName)){ + highestVersion = entityItem.getHigherVersion(); + } + } + } + if(highestVersion != 0){ + version = highestVersion; + descriptionVersion = highestVersion +1; + }else{ + version = 1; + descriptionVersion = 1; + } + + //set policy adapter values for Building JSON object containing policy data + String createdBy = ""; + String modifiedBy = userId; + if(descriptionVersion == 1){ + createdBy = userId; + }else{ + String policyName = PolicyController.getGitPath().toAbsolutePath().toString() + File.separator + policyData.getDomainDir() + File.separator + policyData.getOldPolicyFileName() + ".xml"; + File policyPath = new File(policyName); + try { + createdBy = XACMLPolicyScanner.getCreatedBy(policyPath.toPath()); + } catch (IOException e) { + createdBy = "guest"; + } + } + + policyData.setPolicyDescription(policyData.getPolicyDescription()+ "@CreatedBy:" +createdBy + "@CreatedBy:" + "@ModifiedBy:" +modifiedBy + "@ModifiedBy:"); + + + if(policyData.getServiceTypePolicyName() != null){ + policyData.setServiceType(policyData.getServiceTypePolicyName().get("serviceTypePolicyName").toString()); + } + + ObjectMapper jsonMapper = new ObjectMapper(); + String jsonBody = jsonMapper.writeValueAsString(policyData.getJsonBodyData()); + jsonBody = jsonBody.replaceFirst("\\{", "\\{\"serviceTypePolicyName\": \"serviceTypeFieldValue\","); + jsonBody = jsonBody.replace("serviceTypeFieldValue", policyData.getServiceType()); + policyData.setJsonBody(jsonBody); + + Map successMap = new HashMap(); + + //set the Rule Combining Algorithm Id to be sent to PAP-REST via JSON + List ruleAlgorithmsList = ruleAlgorithmsDao.getRuleAlgorithms(); + for (int i = 0; i < ruleAlgorithmsList.size(); i++) { + RuleAlgorithms a = ruleAlgorithmsList.get(i); + if (a.getXacmlId().equals(XACML3.ID_RULE_PERMIT_OVERRIDES.stringValue())) { + policyData.setRuleCombiningAlgId(a.getXacmlId()); + break; + } + } + + if (policyData.isEditPolicy()){ + //increment the version and set in policyAdapter + policyData.setVersion(String.valueOf(version)); + policyData.setHighestVersion(version); + policyData.setPolicyID(this.newPolicyID()); + policyData.setRuleID(ruleID); + successMap = engine.updatePolicyRequest(policyData); + } else { + //send it for policy creation + policyData.setVersion(String.valueOf(version)); + policyData.setHighestVersion(version); + successMap = engine.createPolicyRequest(policyData); + + } + + if (successMap.containsKey("success")) { + // Add it into our tree + Path finalPolicyPath = null; + finalPolicyPath = Paths.get(successMap.get("success")); + PolicyElasticSearchController controller = new PolicyElasticSearchController(); + controller.updateElk(finalPolicyPath.toString()); + File file = finalPolicyPath.toFile(); + if(file != null){ + String policyName = file.toString(); + String removePath = policyName.substring(policyName.indexOf("repository")+11); + String removeXml = removePath.replace(".xml", ""); + String removeExtension = removeXml.substring(0, removeXml.indexOf(".")); + List versionList = policyVersionDao.getPolicyVersionEntityByName(removeExtension); + if (versionList.size() > 0) { + for(int i = 0; i < versionList.size(); i++) { + PolicyVersion entityItem = versionList.get(i); + if(entityItem.getPolicyName().equals(removeExtension)){ + version = entityItem.getHigherVersion() +1; + entityItem.setActiveVersion(version); + entityItem.setHigherVersion(version); + entityItem.setModifiedBy(userId); + policyVersionDao.update(entityItem); + if(policyData.isEditPolicy){ + PolicyNotificationMail email = new PolicyNotificationMail(); + String mode = "EditPolicy"; + String policyNameForEmail = policyData.getDomainDir() + File.separator + policyData.getOldPolicyFileName() + ".xml"; + email.sendMail(entityItem, policyNameForEmail, mode, policyNotificationDao); + } + } + } + }else{ + PolicyVersion entityItem = new PolicyVersion(); + entityItem.setActiveVersion(version); + entityItem.setHigherVersion(version); + entityItem.setPolicyName(removeExtension); + entityItem.setCreatedBy(userId); + entityItem.setModifiedBy(userId); + policyVersionDao.Save(entityItem); + } + } + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = mapper.writeValueAsString(successMap); + JSONObject j = new JSONObject("{policyData: " + responseString + "}"); + out.write(j.toString()); + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + private String convertDate(String dateTTL) { + String formateDate = null; + String[] date = dateTTL.split("T"); + String[] parts = date[0].split("-"); + + formateDate = parts[2] + "-" + parts[1] + "-" + parts[0]; + return formateDate; + } + + public void PrePopulateClosedLoopPMPolicyData(PolicyAdapter policyAdapter) { + if (policyAdapter.getPolicyData() instanceof PolicyType) { + Object policyData = policyAdapter.getPolicyData(); + PolicyType policy = (PolicyType) policyData; + policyAdapter.setOldPolicyFileName(policyAdapter.getPolicyName()); + String policyNameValue = policyAdapter.getPolicyName().substring(policyAdapter.getPolicyName().indexOf("PM_") +3 , policyAdapter.getPolicyName().lastIndexOf(".")); + policyAdapter.setPolicyName(policyNameValue); + String description = ""; + try{ + description = policy.getDescription().substring(0, policy.getDescription().indexOf("@CreatedBy:")); + }catch(Exception e){ + description = policy.getDescription(); + } + policyAdapter.setPolicyDescription(description); + // Get the target data under policy. + TargetType target = policy.getTarget(); + if (target != null) { + // Under target we have AnyOFType + List anyOfList = target.getAnyOf(); + if (anyOfList != null) { + Iterator iterAnyOf = anyOfList.iterator(); + while (iterAnyOf.hasNext()) { + AnyOfType anyOf = iterAnyOf.next(); + // Under AnyOFType we have AllOFType + List allOfList = anyOf.getAllOf(); + if (allOfList != null) { + Iterator iterAllOf = allOfList.iterator(); + while (iterAllOf.hasNext()) { + AllOfType allOf = iterAllOf.next(); + // Under AllOFType we have Match + List matchList = allOf.getMatch(); + if (matchList != null) { + int index = 0; + Iterator iterMatch = matchList.iterator(); + while (matchList.size()>1 && iterMatch.hasNext()) { + MatchType match = iterMatch.next(); + // + // Under the match we have attributevalue and + // attributeDesignator. So,finally down to the actual attribute. + // + AttributeValueType attributeValue = match.getAttributeValue(); + String value = (String) attributeValue.getContent().get(0); + + // First match in the target is EcompName, so set that value. + if (index == 0) { + policyAdapter.setEcompName(value); + } + + if (index == 1){ + policyAdapter.setRiskType(value); + } + + if (index == 2){ + policyAdapter.setRiskLevel(value); + } + + if (index == 3){ + policyAdapter.setGuard(value); + } + + if (index == 4 && !value.contains("NA")){ + String newDate = convertDate(value, true); + policyAdapter.setTtlDate(newDate); + } + if (index == 5){ + LinkedHashMap serviceTypePolicyName1 = new LinkedHashMap<>(); + String key = "serviceTypePolicyName"; + serviceTypePolicyName1.put(key, value); + policyAdapter.setServiceTypePolicyName(serviceTypePolicyName1); + } + index++; + } + } + } + } + } + } + } + String jsonBodyName = policyAdapter.getDirPath().replace(File.separator, ".")+"."+ policyAdapter.getOldPolicyFileName() + "."; + policyAdapter.setConfigBodyPath(jsonBodyName); + readClosedLoopJSONFile(policyAdapter); + } + } + + private String convertDate(String dateTTL, boolean portalType) { + String formateDate = null; + String[] date; + String[] parts; + + if (portalType){ + parts = dateTTL.split("-"); + formateDate = parts[2] + "-" + parts[1] + "-" + parts[0] + "T05:00:00.000Z"; + } else { + date = dateTTL.split("T"); + parts = date[0].split("-"); + formateDate = parts[2] + "-" + parts[1] + "-" + parts[0]; + } + return formateDate; + } + + protected String readClosedLoopJSONFile(PolicyAdapter policyAdapter) { + String fileLocation = null; + String fileName = policyAdapter.getConfigBodyPath(); + if (fileName != null ) { + fileLocation = PolicyController.getConfigHome(); + } + if (fileLocation == null) { + return fileLocation; + } + + File dir = new File(fileLocation); + File[] listOfFiles = dir.listFiles(); + for (File file : listOfFiles) { + if (file.isFile() && file.getName().contains(fileName)) { + FileInputStream inputStream = null; + String location = file.toString(); + try { + inputStream = new FileInputStream(location); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + if (location.endsWith("json")) { + JsonReader jsonReader = null; + jsonReader = Json.createReader(inputStream); + ObjectMapper mapper = new ObjectMapper(); + try { + ClosedLoopPMBody closedLoopBody = mapper.readValue(jsonReader.read().toString(), ClosedLoopPMBody.class); + policyAdapter.setJsonBodyData(closedLoopBody); + } catch (IOException e) { + e.printStackTrace(); + /*logger.error("JSON Body Mapping Error");*/ + } + jsonReader.close(); + } + } + } + return null; + } + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/CreateDcaeMicroServiceController.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/CreateDcaeMicroServiceController.java new file mode 100644 index 000000000..c4d4cfd50 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/CreateDcaeMicroServiceController.java @@ -0,0 +1,987 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.controller; + + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.io.PrintWriter; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import java.util.Map.Entry; +import java.util.Properties; +import java.util.TreeMap; + +import javax.json.Json; +import javax.json.JsonReader; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.lang.StringUtils; +import org.json.JSONArray; +import org.json.JSONObject; +import org.openecomp.policy.adapter.PolicyAdapter; +import org.openecomp.policy.admin.PolicyNotificationMail; +import org.openecomp.policy.admin.RESTfulPAPEngine; +import org.openecomp.policy.dao.PolicyVersionDao; +import org.openecomp.policy.dao.RemoteCatalogValuesDao; +import org.openecomp.policy.dao.RuleAlgorithmsDao; +import org.openecomp.policy.dao.WatchPolicyNotificationDao; +import org.openecomp.policy.elk.client.PolicyElasticSearchController; +import org.openecomp.policy.rest.XACMLRestProperties; +import org.openecomp.policy.rest.dao.GroupPolicyScopeListDao; +import org.openecomp.policy.rest.dao.MicroServiceModelsDao; +import org.openecomp.policy.rest.jpa.GroupPolicyScopeList; +import org.openecomp.policy.rest.jpa.MicroServiceModels; +import org.openecomp.policy.rest.jpa.PolicyVersion; +import org.openecomp.policy.rest.jpa.RemoteCatalogValues; +import org.openecomp.policy.rest.jpa.RuleAlgorithms; +import org.openecomp.policy.utils.ConfigurableRESTUtils; +import org.openecomp.policy.utils.ConfigurableRESTUtils.RESQUEST_METHOD; +import org.openecomp.policy.utils.ConfigurableRESTUtils.REST_RESPONSE_FORMAT; +import org.openecomp.portalsdk.core.controller.RestrictedBaseController; +import org.openecomp.portalsdk.core.web.support.JsonMessage; +import org.openecomp.portalsdk.core.web.support.UserUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + +import com.att.research.xacml.api.XACML3; +import org.openecomp.policy.xacml.api.XACMLErrorConstants; +import org.openecomp.policy.xacml.util.XACMLPolicyScanner; +import com.att.research.xacml.util.XACMLProperties; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; +import com.fasterxml.jackson.databind.node.JsonNodeFactory; +import com.fasterxml.jackson.databind.node.ObjectNode; +import com.google.common.base.Joiner; +import com.google.common.base.Splitter; +import com.google.gson.Gson; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; + +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +@Controller +@RequestMapping("/") +public class CreateDcaeMicroServiceController extends RestrictedBaseController { + private static final Logger logger = FlexLogger.getLogger(CreateDcaeMicroServiceController.class); + + private static RuleAlgorithmsDao ruleAlgorithmsDao; + private static RemoteCatalogValuesDao remoteCatalogValuesDao; + private static MicroServiceModelsDao microServiceModelsDao; + private static PolicyVersionDao policyVersionDao; + private static GroupPolicyScopeListDao groupPolicyScopeListDao; + private static WatchPolicyNotificationDao policyNotificationDao; + + @Autowired + private CreateDcaeMicroServiceController(RuleAlgorithmsDao ruleAlgorithmsDao, RemoteCatalogValuesDao remoteCatalogValuesDao, + MicroServiceModelsDao microServiceModelsDao, PolicyVersionDao policyVersionDao, GroupPolicyScopeListDao groupPolicyScopeListDao, + WatchPolicyNotificationDao policyNotificationDao){ + CreateDcaeMicroServiceController.groupPolicyScopeListDao = groupPolicyScopeListDao; + CreateDcaeMicroServiceController.policyVersionDao = policyVersionDao; + CreateDcaeMicroServiceController.microServiceModelsDao = microServiceModelsDao; + CreateDcaeMicroServiceController.remoteCatalogValuesDao = remoteCatalogValuesDao; + CreateDcaeMicroServiceController.ruleAlgorithmsDao = ruleAlgorithmsDao; + CreateDcaeMicroServiceController.policyNotificationDao = policyNotificationDao; + } + + public CreateDcaeMicroServiceController(){} + + protected PolicyAdapter policyAdapter = null; + private String ruleID = ""; + private int priorityCount; + private Map attributesListRefMap = new HashMap(); + private Map> arrayTextList = new HashMap>(); + + + public String newPolicyID() { + return Joiner.on(':').skipNulls().join((PolicyController.getDomain().startsWith("urn") ? null: "urn"), + PolicyController.getDomain().replaceAll("[/\\\\.]", ":"), "xacml", "policy", "id", UUID.randomUUID()); + } + + + @RequestMapping(value={"/policyController/getDCAEMSTemplateData.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView getBRMSParamPolicyRuleData(HttpServletRequest request, HttpServletResponse response) throws Exception{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + + String value = root.get("policyData").toString().replaceAll("^\"|\"$", ""); + String servicename = value.toString().split("-v")[0]; + String version = null; + if (value.toString().contains("-v")){ + version = value.toString().split("-v")[1]; + } + MicroServiceModels returnModel = getAttributeObject(servicename, version); + + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + List list = new ArrayList<>(); + PrintWriter out = response.getWriter(); + String responseString = mapper.writeValueAsString(returnModel); + JSONObject j = new JSONObject("{dcaeModelData: " + responseString +"}"); + list.add(j); + out.write(list.toString()); + return null; + } + + private MicroServiceModels getAttributeObject(String name, String version) { + MicroServiceModels workingModel = new MicroServiceModels(); + List microServiceModelsData = microServiceModelsDao.getMicroServiceModelsData(); + for (int i = 0; i < microServiceModelsData.size(); i++) { + workingModel = microServiceModelsData.get(i); + if (version!=null && workingModel.getVersion()!=null){ + if (workingModel.getModelName().equals(name) && workingModel.getVersion().equals(version)){ + break; + } + }else{ + if (workingModel.getModelName().equals(name) && workingModel.getVersion() == null){ + break; + } + } + } + return workingModel; + } + + @RequestMapping(value={"/get_DCAEPriorityValues"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getDCAEPriorityValuesData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + List priorityList = new ArrayList(); + priorityCount = 10; + for (int i = 1; i < priorityCount; i++) { + priorityList.add(String.valueOf(i)); + } + model.put("priorityDatas", mapper.writeValueAsString(priorityList)); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + + @RequestMapping(value={"/policyController/save_DCAEMSPolicy.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveDCAEMSPolicy(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + String userId = UserUtils.getUserIdFromCookie(request); + RESTfulPAPEngine engine = (RESTfulPAPEngine) PolicyController.getPapEngine(); + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + String jsonContent = null; + try{ + jsonContent = decodeContent(root.get("policyJSON")).toString(); + }catch(Exception e){ + logger.error("Error while decoding microservice content"); + } + PolicyAdapter policyData = (PolicyAdapter)mapper.readValue(root.get("policyData").get("policy").toString(), PolicyAdapter.class); + policyData.setDomainDir(root.get("policyData").get("model").get("name").toString().replace("\"", "")); + if(root.get("policyData").get("model").get("type").toString().replace("\"", "").equals("file")){ + policyData.isEditPolicy = true; + } + + if(root.get("policyData").get("model").get("path").size() != 0){ + String dirName = ""; + for(int i = 0; i < root.get("policyData").get("model").get("path").size(); i++){ + dirName = dirName.replace("\"", "") + root.get("policyData").get("model").get("path").get(i).toString().replace("\"", "") + File.separator; + } + if(policyData.isEditPolicy){ + policyData.setDomainDir(dirName.substring(0, dirName.lastIndexOf(File.separator))); + }else{ + policyData.setDomainDir(dirName + root.get("policyData").get("model").get("name").toString().replace("\"", "")); + } + }else{ + policyData.setDomainDir(root.get("policyData").get("model").get("name").toString().replace("\"", "")); + } + + if (policyData.getTtlDate()==null){ + policyData.setTtlDate("NA"); + }else{ + String dateTTL = policyData.getTtlDate(); + String newDate = convertDate(dateTTL); + policyData.setTtlDate(newDate); + } + + int version = 0; + int highestVersion = 0; + int descriptionVersion = 0; + //get the highest version of policy from policy version table. + //getting the sub scope domain where the policy is created or updated + String dbCheckPolicyName = policyData.getDomainDir() + File.separator + "Config_MS_" + policyData.getPolicyName(); + List versionList = policyVersionDao.getPolicyVersionEntityByName(dbCheckPolicyName); + if (versionList.size() > 0) { + for(int i = 0; i < versionList.size(); i++) { + PolicyVersion entityItem = versionList.get(i); + if(entityItem.getPolicyName().equals(dbCheckPolicyName)){ + highestVersion = entityItem.getHigherVersion(); + } + } + } + if(highestVersion != 0){ + version = highestVersion; + descriptionVersion = highestVersion +1; + }else{ + version = 1; + descriptionVersion = 1; + } + + //set policy adapter values for Building JSON object containing policy data + String createdBy = ""; + String modifiedBy = userId; + if(descriptionVersion == 1){ + createdBy = userId; + }else{ + String policyName = PolicyController.getGitPath().toAbsolutePath().toString() + File.separator + policyData.getDomainDir() + File.separator + policyData.getOldPolicyFileName() + ".xml"; + File policyPath = new File(policyName); + try { + createdBy = XACMLPolicyScanner.getCreatedBy(policyPath.toPath()); + } catch (IOException e) { + createdBy = "guest"; + } + } + + policyData.setPolicyDescription(policyData.getPolicyDescription()+ "@CreatedBy:" +createdBy + "@CreatedBy:" + "@ModifiedBy:" +modifiedBy + "@ModifiedBy:"); + policyData.setEcompName(policyData.getEcompName()); + //get the jsonBody + String jsonBody = null; + try { + jsonBody = constructJson(policyData, jsonContent); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + } + policyData.setJsonBody(jsonBody); + Map successMap = new HashMap(); + //set the Rule Combining Algorithm Id to be sent to PAP-REST via JSON + List ruleAlgorithmsList = ruleAlgorithmsDao.getRuleAlgorithms(); + for (int i = 0; i < ruleAlgorithmsList.size(); i++) { + RuleAlgorithms a = ruleAlgorithmsList.get(i); + if (a.getXacmlId().equals(XACML3.ID_RULE_PERMIT_OVERRIDES.stringValue())) { + policyData.setRuleCombiningAlgId(a.getXacmlId()); + break; + } + } + if (policyData.isEditPolicy()){ + //increment the version and set in policyAdapter + policyData.setVersion(String.valueOf(version)); + policyData.setHighestVersion(version); + policyData.setPolicyID(this.newPolicyID()); + policyData.setRuleID(ruleID); + successMap = engine.updatePolicyRequest(policyData); + } else { + //send it for policy creation + policyData.setVersion(String.valueOf(version)); + policyData.setHighestVersion(version); + successMap = engine.createPolicyRequest(policyData); + + } + + if (successMap.containsKey("success")) { + // Add it into our tree + Path finalPolicyPath = null; + finalPolicyPath = Paths.get(successMap.get("success")); + PolicyElasticSearchController controller = new PolicyElasticSearchController(); + controller.updateElk(finalPolicyPath.toString()); + File file = finalPolicyPath.toFile(); + if(file != null){ + String policyName = file.toString(); + String removePath = policyName.substring(policyName.indexOf("repository")+11); + String removeXml = removePath.replace(".xml", ""); + String removeExtension = removeXml.substring(0, removeXml.indexOf(".")); + List policyVersionList = policyVersionDao.getPolicyVersionEntityByName(removeExtension); + if (policyVersionList.size() > 0) { + for(int i = 0; i < policyVersionList.size(); i++) { + PolicyVersion entityItem = policyVersionList.get(i); + if(entityItem.getPolicyName().equals(removeExtension)){ + version = entityItem.getHigherVersion() +1; + entityItem.setActiveVersion(version); + entityItem.setHigherVersion(version); + entityItem.setModifiedBy(userId); + policyVersionDao.update(entityItem); + if(policyData.isEditPolicy){ + PolicyNotificationMail email = new PolicyNotificationMail(); + String mode = "EditPolicy"; + String policyNameForEmail = policyData.getDomainDir() + File.separator + policyData.getOldPolicyFileName() + ".xml"; + email.sendMail(entityItem, policyNameForEmail, mode, policyNotificationDao); + } + } + } + }else{ + PolicyVersion entityItem = new PolicyVersion(); + entityItem.setActiveVersion(version); + entityItem.setHigherVersion(version); + entityItem.setPolicyName(removeExtension); + entityItem.setCreatedBy(userId); + entityItem.setModifiedBy(userId); + policyVersionDao.Save(entityItem); + } + } + } + + System.out.println(root); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = mapper.writeValueAsString(successMap); + JSONObject j = new JSONObject("{policyData: " + responseString + "}"); + out.write(j.toString()); + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + private JSONObject decodeContent(JsonNode jsonNode){ + Iterator jsonElements = jsonNode.elements(); + Iterator jsonKeys = jsonNode.fieldNames(); + Map element = new TreeMap(); + while(jsonElements.hasNext() && jsonKeys.hasNext()){ + element.put(jsonKeys.next(), jsonElements.next().toString()); + } + JSONObject jsonResult = new JSONObject(); + JSONArray jsonArray = null; + String oldValue = null; + String nodeKey = null; + String arryKey = null; + Boolean isArray = false; + JsonNodeFactory nodeFactory = JsonNodeFactory.instance; + ObjectNode node = nodeFactory.objectNode(); + String prevKey = null; + String presKey = null; + for(String key: element.keySet()){ + if(key.contains(".")){ + presKey = key.substring(0,key.indexOf(".")); + }else if(key.contains("@")){ + presKey = key.substring(0,key.indexOf("@")); + }else{ + presKey = key; + } + // first check if we are different from old. + System.out.println(key+"\n"); + if(jsonArray!=null && jsonArray.length()>0 && key.contains("@") && !key.contains(".") && oldValue!=null){ + if(!oldValue.equals(key.substring(0,key.indexOf("@")))){ + jsonResult.put(oldValue, jsonArray); + jsonArray = new JSONArray(); + } + }else if(jsonArray!=null && jsonArray.length()>0 && !presKey.equals(prevKey) && oldValue!=null){ + jsonResult.put(oldValue, jsonArray); + isArray = false; + jsonArray = new JSONArray(); + } + /*if(node.size()!=0 && key.contains("@")){ + + }else{ + if(node.size()!=0){ + + } + }*/ + prevKey = presKey; + // + if(key.contains(".")){ + if(nodeKey==null){ + nodeKey = key.substring(0,key.indexOf(".")); + } + if(nodeKey.equals(key.substring(0,key.indexOf(".")))){ + node.put(key.substring(key.indexOf(".")+1), element.get(key)); + }else{ + if(node.size()!=0){ + if(nodeKey.contains("@")){ + if(arryKey==null){ + arryKey = nodeKey.substring(0,nodeKey.indexOf("@")); + } + if(nodeKey.endsWith("@0")){ + isArray = true; + jsonArray = new JSONArray(); + } + if(arryKey.equals(nodeKey.substring(0,nodeKey.indexOf("@")))){ + jsonArray.put(decodeContent(node)); + } + if(key.contains("@") && !arryKey.equals(key.substring(0,nodeKey.indexOf("@")))){ + jsonResult.put(arryKey, jsonArray); + jsonArray = new JSONArray(); + }else if(!key.contains("@")){ + jsonResult.put(arryKey, jsonArray); + jsonArray = new JSONArray(); + } + arryKey = nodeKey.substring(0,nodeKey.indexOf("@")); + }else{ + isArray = false; + jsonResult.put(nodeKey, decodeContent(node)); + } + node = nodeFactory.objectNode(); + } + nodeKey = key.substring(0,key.indexOf(".")); + if(nodeKey.contains("@")){ + arryKey = nodeKey.substring(0,nodeKey.indexOf("@")); + } + node.put(key.substring(key.indexOf(".")+1), element.get(key)); + } + }else if(node.size()!=0){ + if(nodeKey.contains("@")){ + if(arryKey==null){ + arryKey = nodeKey.substring(0,nodeKey.indexOf("@")); + } + if(nodeKey.endsWith("@0")){ + isArray = true; + jsonArray = new JSONArray(); + } + if(arryKey.equals(nodeKey.substring(0,nodeKey.indexOf("@")))){ + jsonArray.put(decodeContent(node)); + } + jsonResult.put(arryKey, jsonArray); + jsonArray = new JSONArray(); + arryKey = nodeKey.substring(0,nodeKey.indexOf("@")); + }else{ + isArray = false; + jsonResult.put(nodeKey, decodeContent(node)); + } + node = nodeFactory.objectNode(); + if(key.contains("@")){ + isArray = true; + if(key.endsWith("@0")|| jsonArray==null){ + jsonArray = new JSONArray(); + } + }else if(!key.contains("@")){ + isArray = false; + } + if(isArray){ + if(oldValue==null){ + oldValue = key.substring(0,key.indexOf("@")); + } + if(oldValue!=prevKey){ + oldValue = key.substring(0,key.indexOf("@")); + } + if(oldValue.equals(key.substring(0,key.indexOf("@")))){ + jsonArray.put(element.get(key)); + }else{ + jsonResult.put(oldValue, jsonArray); + jsonArray = new JSONArray(); + } + oldValue = key.substring(0,key.indexOf("@")); + }else{ + jsonResult.put(key, element.get(key)); + } + }else{ + if(key.contains("@")){ + isArray = true; + if(key.endsWith("@0")|| jsonArray==null){ + jsonArray = new JSONArray(); + } + }else if(!key.contains("@")){ + isArray = false; + } + if(isArray){ + if(oldValue==null){ + oldValue = key.substring(0,key.indexOf("@")); + } + if(oldValue!=prevKey){ + oldValue = key.substring(0,key.indexOf("@")); + } + if(oldValue.equals(key.substring(0,key.indexOf("@")))){ + jsonArray.put(element.get(key)); + }else{ + jsonResult.put(oldValue, jsonArray); + jsonArray = new JSONArray(); + } + oldValue = key.substring(0,key.indexOf("@")); + }else{ + jsonResult.put(key, element.get(key)); + } + } + } + if(node.size()>0){ + if(nodeKey.contains("@")){ + if(jsonArray==null){ + jsonArray = new JSONArray(); + } + if(arryKey==null){ + arryKey = nodeKey.substring(0,nodeKey.indexOf("@")); + } + jsonArray.put(decodeContent(node)); + jsonResult.put(arryKey, jsonArray); + isArray = false;; + }else{ + jsonResult.put(nodeKey, decodeContent(node)); + } + } + if(isArray && jsonArray.length() > 0){ + jsonResult.put(oldValue, jsonArray); + } + return jsonResult; + } + + public void PrePopulateDCAEMSPolicyData(PolicyAdapter policyAdapter) { + if (policyAdapter.getPolicyData() instanceof PolicyType) { + Object policyData = policyAdapter.getPolicyData(); + PolicyType policy = (PolicyType) policyData; + policyAdapter.setOldPolicyFileName(policyAdapter.getPolicyName()); + String policyNameValue = policyAdapter.getPolicyName().substring(policyAdapter.getPolicyName().indexOf("MS_") +3 , policyAdapter.getPolicyName().lastIndexOf(".")); + policyAdapter.setPolicyName(policyNameValue); + String description = ""; + try{ + description = policy.getDescription().substring(0, policy.getDescription().indexOf("@CreatedBy:")); + }catch(Exception e){ + description = policy.getDescription(); + } + policyAdapter.setPolicyDescription(description); + String jsonBodyName = policyAdapter.getDirPath().replace(File.separator, ".")+ "." + policyAdapter.getOldPolicyFileName() + "."; + policyAdapter.setConfigBodyPath(jsonBodyName); + // Get the target data under policy. + TargetType target = policy.getTarget(); + if (target != null) { + // Under target we have AnyOFType + List anyOfList = target.getAnyOf(); + if (anyOfList != null) { + Iterator iterAnyOf = anyOfList.iterator(); + while (iterAnyOf.hasNext()) { + AnyOfType anyOf = iterAnyOf.next(); + // Under AnyOFType we have AllOFType + List allOfList = anyOf.getAllOf(); + if (allOfList != null) { + Iterator iterAllOf = allOfList.iterator(); + while (iterAllOf.hasNext()) { + AllOfType allOf = iterAllOf.next(); + // Under AllOFType we have Match + List matchList = allOf.getMatch(); + if (matchList != null) { + int index = 0; + Iterator iterMatch = matchList.iterator(); + while (matchList.size()>1 && iterMatch.hasNext()) { + MatchType match = iterMatch.next(); + // + // Under the match we have attributevalue and + // attributeDesignator. So,finally down to the actual attribute. + // + AttributeValueType attributeValue = match.getAttributeValue(); + String value = (String) attributeValue.getContent().get(0); + + // First match in the target is EcompName, so set that value. + if (index == 0) { + policyAdapter.setEcompName(value); + } + if (index == 1){ + policyAdapter.setConfigName(value); + } + if (index == 2){ + if(value != null){ + readFile(policyAdapter); + } + } + if (index == 3){ + policyAdapter.setUuid(value); + } + if (index == 4){ + policyAdapter.setLocation(value); + } + if (index == 5){ + policyAdapter.setRiskType(value); + } + + if (index == 6){ + policyAdapter.setRiskLevel(value); + } + + if (index == 7){ + policyAdapter.setGuard(value); + } + if (index == 8 && !value.contains("NA")){ + String newDate = convertDate(value, true); + policyAdapter.setTtlDate(newDate); + } + index++; + } + } + } + } + } + } + } + } + + } + + private String convertDate(String dateTTL, boolean portalType) { + String formateDate = null; + String[] date; + String[] parts; + + if (portalType){ + parts = dateTTL.split("-"); + formateDate = parts[2] + "-" + parts[1] + "-" + parts[0] + "T05:00:00.000Z"; + } else { + date = dateTTL.split("T"); + parts = date[0].split("-"); + formateDate = parts[2] + "-" + parts[1] + "-" + parts[0]; + } + return formateDate; + } + + @SuppressWarnings("unchecked") + private String readFile(PolicyAdapter policyAdapter) { + String fileLocation = null; + String policyScopeName = null; + String fileName = policyAdapter.getConfigBodyPath(); + if (fileName != null ) { + fileLocation = PolicyController.getConfigHome(); + } + if (fileLocation == null) { + return fileLocation; + } + File dir = new File(fileLocation); + File[] listOfFiles = dir.listFiles(); + for (File file : listOfFiles) { + if (file.isFile() && file.getName().contains(fileName)) { + FileInputStream inputStream = null; + String location = file.toString(); + try { + inputStream = new FileInputStream(location); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + if (location.endsWith("json")) { + JsonReader jsonReader = null; + jsonReader = Json.createReader(inputStream); + ObjectMapper mapper = new ObjectMapper(); + try { + DCAEMicroServiceObject msBody = (DCAEMicroServiceObject) mapper.readValue(jsonReader.read().toString(), DCAEMicroServiceObject.class); + policyScopeName = getPolicyScope(msBody.getPolicyScope()); + policyAdapter.setPolicyScope(policyScopeName); + + policyAdapter.setPriority(msBody.getPriority()); + + if (msBody.getVersion()!= null){ + policyAdapter.setServiceType(msBody.getService() + "-v" + msBody.getVersion()); + }else{ + policyAdapter.setServiceType(msBody.getService()); + } + if(msBody.getContent() != null){ + LinkedHashMap data = new LinkedHashMap(); + LinkedHashMap map = (LinkedHashMap) msBody.getContent(); + readRecursivlyJSONContent(map, data); + policyAdapter.setRuleData(data); + } + + } catch (Exception e) { + e.printStackTrace(); + } + jsonReader.close(); + } + } + } + return fileName; + + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + private void readRecursivlyJSONContent(LinkedHashMap map, LinkedHashMap data){ + for (Iterator iterator = map.keySet().iterator(); iterator.hasNext();) { + Object key = iterator.next(); + Object value = map.get(key); + if(value instanceof LinkedHashMap){ + readRecursivlyJSONContent((LinkedHashMap) value, data); + }else if(value instanceof ArrayList){ + ArrayList jsonArrayVal = (ArrayList)value; + for(int i = 0; i < jsonArrayVal.size(); i++){ + Object arrayvalue = jsonArrayVal.get(i); + if(arrayvalue instanceof LinkedHashMap){ + LinkedHashMap newData = new LinkedHashMap(); + readRecursivlyJSONContent((LinkedHashMap) arrayvalue, newData); + for(String objKey: newData.keySet()){ + data.put(key+"@"+i+"." +objKey, newData.get(objKey)); + } + }else if(arrayvalue instanceof ArrayList){ + ArrayList jsonArrayVal1 = (ArrayList)value; + for(int j = 0; j < jsonArrayVal1.size(); j++){ + Object arrayvalue1 = jsonArrayVal1.get(i); + data.put(key+"@"+j, arrayvalue1.toString()); + } + }else{ + data.put(key+"@"+i, arrayvalue.toString()); + } + } + }else{ + data.put(key.toString(), value.toString()); + } + } + } + + private String getPolicyScope(String value) { + GroupPolicyScopeList pScope = new GroupPolicyScopeList(); + List groupList= groupPolicyScopeListDao.getGroupPolicyScopeListData(); + if(groupList.size() > 0){ + for(int i = 0 ; i < groupList.size() ; i ++){ + pScope = groupList.get(i); + if (pScope.getGroupList().equals(value)){ + break; + } + } + } + return pScope.getGroupName(); + } + + private GroupPolicyScopeList getPolicyObject(String policyScope) { + GroupPolicyScopeList pScope = new GroupPolicyScopeList(); + List groupList = groupPolicyScopeListDao.getGroupPolicyScopeListData(); + if(groupList.size() > 0){ + for(int i = 0 ; i < groupList.size() ; i ++){ + pScope = groupList.get(i); + if (pScope.getGroupName().equals(policyScope)){ + break; + } + } + } + return pScope; + } + + private String constructJson(PolicyAdapter policyAdapter, String jsonContent) { + ObjectWriter om = new ObjectMapper().writer(); + String json=""; + DCAEMicroServiceObject microServiceObject = new DCAEMicroServiceObject(); + + microServiceObject.setTemplateVersion(XACMLProperties.getProperty(XACMLRestProperties.TemplateVersion_MS)); + if(policyAdapter.getServiceType() !=null){ + microServiceObject.setService(policyAdapter.getServiceType().toString().split("-v")[0]); + if (policyAdapter.getServiceType().toString().contains("-v")){ + microServiceObject.setVersion(policyAdapter.getServiceType().toString().split("-v")[1]); + } + } + if(policyAdapter.getUuid()!=null){ + microServiceObject.setUuid(policyAdapter.getUuid()); + } + + if(policyAdapter.getLocation()!=null){ + microServiceObject.setLocation(policyAdapter.getLocation()); + } + if(policyAdapter.getPolicyName()!=null){ + microServiceObject.setPolicyName(policyAdapter.getPolicyName()); + } + + if(policyAdapter.getConfigName()!=null){ + microServiceObject.setConfigName(policyAdapter.getConfigName()); + } + if(policyAdapter.getPolicyDescription()!=null){ + microServiceObject.setDescription(policyAdapter.getPolicyDescription()); + } + if (policyAdapter.getPriority()!=null){ + microServiceObject.setPriority(policyAdapter.getPriority()); + }else { + microServiceObject.setPriority("9999"); + } + microServiceObject.setContent(jsonContent); + GroupPolicyScopeList policyScopeValue = getPolicyObject(policyAdapter.getPolicyScope()); + microServiceObject.setPolicyScope(policyScopeValue.getGroupList()); + try { + json = om.writeValueAsString(microServiceObject); + } catch (JsonProcessingException e) { + logger.error("Error writing out the object"); + } + System.out.println(json); + String cleanJson = cleanUPJson(json); + return cleanJson; + } + + private String cleanUPJson(String json) { + String cleanJason = StringUtils.replaceEach(json, new String[]{"\\\\", "\\\\\\", "\\\\\\\\"}, new String[]{"\\", "\\", "\\"}); + cleanJason = StringUtils.replaceEach(json, new String[]{"\\\\\\"}, new String[]{"\\"}); + cleanJason = StringUtils.replaceEach(cleanJason, new String[]{"\\\\", "[[", "]]"}, new String[]{"\\", "[", "]"}); + + cleanJason = StringUtils.replaceEach(cleanJason, new String[]{"\\\\\"", "\\\"", "\"[{", "}]\""}, new String[]{"\"", "\"", "[{", "}]"}); + cleanJason = StringUtils.replaceEach(cleanJason, new String[]{"\"[{", "}]\""}, new String[]{"[{", "}]"}); + cleanJason = StringUtils.replaceEach(cleanJason, new String[]{"\"[", "]\""}, new String[]{"[", "]"}); + cleanJason = StringUtils.replaceEach(cleanJason, new String[]{"\"{", "}\""}, new String[]{"{", "}"}); + cleanJason = StringUtils.replaceEach(cleanJason, new String[]{"\"\"\"", "\"\""}, new String[]{"\"", "\""}); + cleanJason = StringUtils.replaceEach(cleanJason, new String[]{"\\\""}, new String[]{""}); + return cleanJason; + } + + //Convert the map values and set into JSON body + public Map convertMap(Map attributesMap, Map attributesRefMap) { + Map attribute = new HashMap(); + String temp = null; + String key; + String value; + for (Entry entry : attributesMap.entrySet()) { + key = entry.getKey(); + value = entry.getValue(); + attribute.put(key, value); + } + for (Entry entryRef : attributesRefMap.entrySet()) { + key = entryRef.getKey(); + value = entryRef.getValue().toString(); + attribute.put(key, value); + } + for (Entry entryList : attributesListRefMap.entrySet()) { + key = entryList.getKey(); + value = entryList.getValue().toString(); + attribute.put(key, value); + } + for (Entry> arrayList : arrayTextList.entrySet()){ + key = arrayList.getKey(); + temp = null; + for (Object textList : arrayList.getValue()){ + if (temp == null){ + temp = "[" + textList; + }else{ + temp = temp + "," + textList; + } + } + attribute.put(key, temp+ "]"); + } + + return attribute; + } + + private String convertDate(String dateTTL) { + String formateDate = null; + String[] date = dateTTL.split("T"); + String[] parts = date[0].split("-"); + + formateDate = parts[2] + "-" + parts[1] + "-" + parts[0]; + return formateDate; + } +} + +class DCAEMicroServiceObject { + + public String service; + public String location; + public String uuid; + public String policyName; + public String description; + public String configName; + public String templateVersion; + public String version; + public String priority; + public String policyScope; + + public String getPolicyScope() { + return policyScope; + } + public void setPolicyScope(String policyScope) { + this.policyScope = policyScope; + } + + public String getPriority() { + return priority; + } + public void setPriority(String priority) { + this.priority = priority; + } + public String getVersion() { + return version; + } + public void setVersion(String version) { + this.version = version; + } + private Object content; + + + public String getPolicyName() { + return policyName; + } + public void setPolicyName(String policyName) { + this.policyName = policyName; + } + public String getDescription() { + return description; + } + public void setDescription(String description) { + this.description = description; + } + public String getConfigName() { + return configName; + } + public void setConfigName(String configName) { + this.configName = configName; + } + public Object getContent() { + return content; + } + public void setContent(Object content) { + this.content = content; + } + + public String getService() { + return service; + } + public void setService(String service) { + this.service = service; + } + public String getLocation() { + return location; + } + public void setLocation(String location) { + this.location = location; + } + + public String getUuid() { + return uuid; + } + public void setUuid(String uuid) { + this.uuid = uuid; + } + public String getTemplateVersion() { + return templateVersion; + } + public void setTemplateVersion(String templateVersion) { + this.templateVersion = templateVersion; + } + +} \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/CreateFirewallController.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/CreateFirewallController.java new file mode 100644 index 000000000..6d7c0c752 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/CreateFirewallController.java @@ -0,0 +1,1292 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.controller; + + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintWriter; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.UUID; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.hibernate.SQLQuery; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.json.JSONObject; +import org.openecomp.policy.adapter.AddressGroupJson; +import org.openecomp.policy.adapter.AddressJson; +import org.openecomp.policy.adapter.AddressMembers; +import org.openecomp.policy.adapter.DeployNowJson; +import org.openecomp.policy.adapter.PolicyAdapter; +import org.openecomp.policy.adapter.PrefixIPList; +import org.openecomp.policy.adapter.ServiceGroupJson; +import org.openecomp.policy.adapter.ServiceListJson; +import org.openecomp.policy.adapter.ServiceMembers; +import org.openecomp.policy.adapter.ServicesJson; +import org.openecomp.policy.adapter.Term; +import org.openecomp.policy.adapter.TermCollector; +import org.openecomp.policy.admin.PolicyNotificationMail; +import org.openecomp.policy.admin.RESTfulPAPEngine; +import org.openecomp.policy.dao.PolicyVersionDao; +import org.openecomp.policy.dao.RuleAlgorithmsDao; +import org.openecomp.policy.dao.WatchPolicyNotificationDao; +import org.openecomp.policy.elk.client.PolicyElasticSearchController; +import org.openecomp.policy.rest.dao.AddressGroupDao; +import org.openecomp.policy.rest.dao.FirewallDictionaryListDao; +import org.openecomp.policy.rest.dao.PrefixListDao; +import org.openecomp.policy.rest.dao.SecurityZoneDao; +import org.openecomp.policy.rest.dao.ServiceGroupDao; +import org.openecomp.policy.rest.dao.ServiceListDao; +import org.openecomp.policy.rest.dao.TermListDao; +import org.openecomp.policy.rest.jpa.AddressGroup; +import org.openecomp.policy.rest.jpa.FirewallDictionaryList; +import org.openecomp.policy.rest.jpa.GroupServiceList; +import org.openecomp.policy.rest.jpa.PREFIXLIST; +import org.openecomp.policy.rest.jpa.PolicyVersion; +import org.openecomp.policy.rest.jpa.RuleAlgorithms; +import org.openecomp.policy.rest.jpa.SecurityZone; +import org.openecomp.policy.rest.jpa.ServiceList; +import org.openecomp.policy.rest.jpa.TermList; +import org.openecomp.portalsdk.core.controller.RestrictedBaseController; +import org.openecomp.portalsdk.core.web.support.JsonMessage; +import org.openecomp.portalsdk.core.web.support.UserUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +import com.att.research.xacml.api.XACML3; +import org.openecomp.policy.xacml.api.XACMLErrorConstants; +import org.openecomp.policy.xacml.util.XACMLPolicyScanner; +import com.fasterxml.jackson.core.JsonGenerationException; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; +import com.google.common.base.Joiner; + +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType; + +@Controller +@RequestMapping("/") +public class CreateFirewallController extends RestrictedBaseController { + private static Logger logger = FlexLogger.getLogger(CreateFirewallController.class); + + private static RuleAlgorithmsDao ruleAlgorithmsDao; + private static PolicyVersionDao policyVersionDao; + private static PrefixListDao prefixListDao; + private static ServiceListDao serviceListDao; + private static TermListDao termListDao; + private static ServiceGroupDao serviceGroupDao; + private static AddressGroupDao addressGroupDao; + private static SecurityZoneDao securityZoneDao; + private static SessionFactory sessionFactory; + private static FirewallDictionaryListDao fwDictionaryListDao; + private static WatchPolicyNotificationDao policyNotificationDao; + + List expandablePrefixIPList = new ArrayList(); + List expandableServicesList= new ArrayList(); + + private String parentSecurityZone; + + + public String getParentSecurityZone() { + return parentSecurityZone; + } + + public void setParentSecurityZone(String parentSecurityZone) { + this.parentSecurityZone = parentSecurityZone; + } + + + + @Autowired + private CreateFirewallController(RuleAlgorithmsDao ruleAlgorithmsDao, PolicyVersionDao policyVersionDao, PrefixListDao prefixListDao, + ServiceListDao serviceListDao, TermListDao termListDao, ServiceGroupDao serviceGroupDao, AddressGroupDao addressGroupDao, SecurityZoneDao securityZoneDao, SessionFactory sessionFactory + ,FirewallDictionaryListDao fwDictionaryListDao, WatchPolicyNotificationDao policyNotificationDao){ + CreateFirewallController.addressGroupDao = addressGroupDao; + CreateFirewallController.ruleAlgorithmsDao = ruleAlgorithmsDao; + CreateFirewallController.policyVersionDao = policyVersionDao; + CreateFirewallController.prefixListDao = prefixListDao; + CreateFirewallController.serviceListDao = serviceListDao; + CreateFirewallController.termListDao = termListDao; + CreateFirewallController.serviceGroupDao = serviceGroupDao; + CreateFirewallController.securityZoneDao = securityZoneDao; + CreateFirewallController.sessionFactory = sessionFactory; + CreateFirewallController.fwDictionaryListDao = fwDictionaryListDao; + CreateFirewallController.policyNotificationDao = policyNotificationDao; + } + + public CreateFirewallController(){} + protected PolicyAdapter policyAdapter = null; + private List termCollectorList; + private List parentDictionaryList; + private String ruleID = ""; + private String jsonBody; + private ArrayList attributeList; + private ArrayList fwAttributeList; + + public String newPolicyID() { + return Joiner.on(':').skipNulls().join((PolicyController.getDomain().startsWith("urn") ? null: "urn"), + PolicyController.getDomain().replaceAll("[/\\\\.]", ":"), "xacml", "policy", "id", UUID.randomUUID()); + } + + @RequestMapping(value={"/get_FWParentListDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getFWParentListEntityDataByName(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + String query= "select distinct parent from fwparent"; + model.put("fwParentListDictionaryDatas", mapper.writeValueAsString(queryToDatabase(query))); + + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @SuppressWarnings("unchecked") + private List queryToDatabase(String query) { + Session session = sessionFactory.openSession(); + Transaction tx = session.beginTransaction(); + List data = null; + try { + SQLQuery sqlquery=session.createSQLQuery(query); + //Query hbquery = session.createQuery(query); + data = sqlquery.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Qurying Parent Child Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + + } + + @SuppressWarnings("unchecked") + private void updateToDatabase(String updateQuery) { + Session session = sessionFactory.openSession(); + Transaction tx = session.beginTransaction(); + List data = null; + try { + SQLQuery sqlquery=session.createSQLQuery(updateQuery); + sqlquery.executeUpdate(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating FWChildParent Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + + @RequestMapping(value={"/policyController/save_FirewallPolicy.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveFirewallPolicy(HttpServletRequest request, HttpServletResponse response) throws Exception{ + termCollectorList = new ArrayList(); + parentDictionaryList= new ArrayList(); + try { + String userId = UserUtils.getUserIdFromCookie(request); + RESTfulPAPEngine engine = (RESTfulPAPEngine) PolicyController.getPapEngine(); + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + PolicyAdapter policyData = (PolicyAdapter)mapper.readValue(root.get("policyData").get("policy").toString(), PolicyAdapter.class); + policyData.setDomainDir(root.get("policyData").get("model").get("name").toString().replace("\"", "")); + if(root.get("policyData").get("model").get("type").toString().replace("\"", "").equals("file")){ + policyData.isEditPolicy = true; + } + this.policyAdapter = policyData; + if(root.get("policyData").get("model").get("path").size() != 0){ + String dirName = ""; + for(int i = 0; i < root.get("policyData").get("model").get("path").size(); i++){ + dirName = dirName.replace("\"", "") + root.get("policyData").get("model").get("path").get(i).toString().replace("\"", "") + File.separator; + } + policyData.setDomainDir(dirName.substring(0, dirName.lastIndexOf(File.separator))); + }else{ + policyData.setDomainDir(root.get("policyData").get("model").get("name").toString().replace("\"", "")); + } + + if (policyData.getTtlDate()==null){ + policyData.setTtlDate("NA"); + }else{ + String dateTTL = policyData.getTtlDate(); + String newDate = convertDate(dateTTL); + policyData.setTtlDate(newDate); + } + + int version = 0; + int highestVersion = 0; + int descriptionVersion = 0; + //get the highest version of policy from policy version table. + //getting the sub scope domain where the policy is created or updated + String dbCheckPolicyName = policyData.getDomainDir() + File.separator + "Config_FW_" + policyData.getPolicyName(); + List policyVersionList = policyVersionDao.getPolicyVersionEntityByName(dbCheckPolicyName); + if (policyVersionList.size() > 0) { + for(int i = 0; i < policyVersionList.size(); i++) { + PolicyVersion entityItem = policyVersionList.get(i); + if(entityItem.getPolicyName().equals(dbCheckPolicyName)){ + highestVersion = entityItem.getHigherVersion(); + } + } + } + if(highestVersion != 0){ + version = highestVersion; + descriptionVersion = highestVersion +1; + }else{ + version = 1; + descriptionVersion = 1; + } + + //set policy adapter values for Building JSON object containing policy data + String createdBy = ""; + String modifiedBy = userId; + if(descriptionVersion == 1){ + createdBy = userId; + }else{ + String policyName = PolicyController.getGitPath().toAbsolutePath().toString() + File.separator + policyData.getDomainDir() + File.separator + policyData.getOldPolicyFileName() + ".xml"; + File policyPath = new File(policyName); + try { + createdBy = XACMLPolicyScanner.getCreatedBy(policyPath.toPath()); + } catch (IOException e) { + createdBy = "guest"; + } + } + + if(policyData.getFwPolicyType().equalsIgnoreCase("Parent Policy")){ + String comboNames=""; + int i=0; + for(Object fwattribute : policyData.getFwattributes()){ + if(fwattribute instanceof LinkedHashMap){ + String key = ((LinkedHashMap) fwattribute).get("option").toString(); + if(i>0){ + comboNames = comboNames+","+ key; + } + else{ + comboNames = key; + } + i++; + } + } + policyData.setPolicyDescription(policyData.getPolicyDescription()+ "@CreatedBy:" +createdBy + "@CreatedBy:" + "@ModifiedBy:" +modifiedBy + "@ModifiedBy:"+"@comboList:"+comboNames); + } + else{ + policyData.setPolicyDescription(policyData.getPolicyDescription()+ "@CreatedBy:" +createdBy + "@CreatedBy:" + "@ModifiedBy:" +modifiedBy + "@ModifiedBy:"); + } + + //policyData.setPolicyDescription(policyData.getPolicyDescription()+ "@CreatedBy:" +createdBy + "@CreatedBy:" + "@ModifiedBy:" +modifiedBy + "@ModifiedBy:"); + Map successMap = new HashMap(); + + //set the Rule Combining Algorithm Id to be sent to PAP-REST via JSON + List ruleAlgorithmsList = ruleAlgorithmsDao.getRuleAlgorithms(); + for (int i = 0; i < ruleAlgorithmsList.size(); i++) { + RuleAlgorithms a = ruleAlgorithmsList.get(i); + if (a.getXacmlId().equals(XACML3.ID_RULE_PERMIT_OVERRIDES.stringValue())) { + policyData.setRuleCombiningAlgId(a.getXacmlId()); + break; + } + } + + if(policyData.getAttributes().size() > 0){ + for(Object attribute : policyData.getAttributes()){ + if(attribute instanceof LinkedHashMap){ + String key = ((LinkedHashMap) attribute).get("option").toString(); + termCollectorList.add(key); + } + } + } + if(policyData.getFwattributes()!=null){ + if(policyData.getFwattributes().size() > 0){ + for(Object fwattribute : policyData.getFwattributes()){ + if(fwattribute instanceof LinkedHashMap){ + String key = ((LinkedHashMap) fwattribute).get("option").toString(); + FirewallDictionaryList fwDictValue = fwDictionaryListDao.getFWDictionaryDataById(key); + parentDictionaryList.add(fwDictValue); + if(fwDictValue.getAddressList().contains(",")) { + for(String individualAddressObject:fwDictValue.getAddressList().split(",") ){ + expandablePrefixIPList.add(individualAddressObject); + } + } + else{ + expandablePrefixIPList.add(fwDictValue.getAddressList()); + } + + if(fwDictValue.getServiceList().contains(",")) { + for(String individualAddressObject:fwDictValue.getServiceList().split(",") ){ + expandableServicesList.add(individualAddressObject); + } + } + else{ + expandableServicesList.add(fwDictValue.getServiceList()); + } + } + } + } + } + + jsonBody = constructJson(); + if (jsonBody != null || jsonBody.equalsIgnoreCase("")) { + policyAdapter.setJsonBody(jsonBody); + + } else { + policyAdapter.setJsonBody("{}"); + } + policyData.setJsonBody(jsonBody); + + + if (policyData.isEditPolicy()){ + //increment the version and set in policyAdapter + policyData.setVersion(String.valueOf(version)); + policyData.setHighestVersion(version); + policyData.setPolicyID(this.newPolicyID()); + policyData.setRuleID(ruleID); + successMap = engine.updatePolicyRequest(policyData); + } else { + //send it for policy creation + policyData.setVersion(String.valueOf(version)); + policyData.setHighestVersion(version); + successMap = engine.createPolicyRequest(policyData); + + } + + if (successMap.containsKey("success")) { + // Add it into our tree + Path finalPolicyPath = null; + finalPolicyPath = Paths.get(successMap.get("success")); + PolicyElasticSearchController controller = new PolicyElasticSearchController(); + controller.updateElk(finalPolicyPath.toString()); + File file = finalPolicyPath.toFile(); + if(file != null){ + String policyName = file.toString(); + String removePath = policyName.substring(policyName.indexOf("repository")+11); + String removeXml = removePath.replace(".xml", ""); + String removeExtension = removeXml.substring(0, removeXml.indexOf(".")); + List versionList = policyVersionDao.getPolicyVersionEntityByName(removeExtension); + if (versionList.size() > 0) { + for(int i = 0; i < versionList.size(); i++) { + PolicyVersion entityItem = versionList.get(i); + if(entityItem.getPolicyName().equals(removeExtension)){ + version = entityItem.getHigherVersion() +1; + entityItem.setActiveVersion(version); + entityItem.setHigherVersion(version); + entityItem.setModifiedBy(userId); + policyVersionDao.update(entityItem); + if(policyData.isEditPolicy){ + PolicyNotificationMail email = new PolicyNotificationMail(); + String mode = "EditPolicy"; + String policyNameForEmail = policyData.getDomainDir() + File.separator + policyData.getOldPolicyFileName() + ".xml"; + email.sendMail(entityItem, policyNameForEmail, mode, policyNotificationDao); + } + } + } + }else{ + PolicyVersion entityItem = new PolicyVersion(); + entityItem.setActiveVersion(version); + entityItem.setHigherVersion(version); + entityItem.setPolicyName(removeExtension); + entityItem.setCreatedBy(userId); + entityItem.setModifiedBy(userId); + policyVersionDao.Save(entityItem); + } + removeExtension=removeExtension.replace(File.separator, "."); + //PC Feature + if(policyAdapter.getFwPolicyType().equalsIgnoreCase("Parent Policy")){ + //Reads the SecurityZone from the Parent UI and then gets the value from the DB + //Stores the Parent Policy Name and securityZone value to the fwparent table. + String parentSecurityZoneValue= getParentSecurityZone(); + String parentQuery= "INSERT INTO FWPARENT(PARENT,SECURITYZONE) VALUES ('"; + parentQuery=parentQuery+removeExtension+"','"+ parentSecurityZoneValue +"')"; + updateToDatabase(parentQuery); + } + else{ + String updateQuery = ""; + if(policyAdapter.isEditPolicy()){ + updateQuery= "UPDATE FWCHILDTOPARENT SET PARENT='"+policyAdapter.getParentForChild()+"' WHERE CHILD='"+removeExtension+"'"; + } + else{ + updateQuery= "INSERT INTO FWCHILDTOPARENT(CHILD,PARENT) VALUES ('"; + updateQuery =updateQuery+removeExtension+"','"+ policyAdapter.getParentForChild() +"')"; + } + updateToDatabase(updateQuery); + } + } + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = mapper.writeValueAsString(successMap); + JSONObject j = new JSONObject("{policyData: " + responseString + "}"); + out.write(j.toString()); + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + private String convertDate(String dateTTL) { + String formateDate = null; + String[] date = dateTTL.split("T"); + String[] parts = date[0].split("-"); + + formateDate = parts[2] + "-" + parts[1] + "-" + parts[0]; + return formateDate; + } + + private String constructJson() { + int ruleCount=1; + //Maps to assosciate the values read from the TermList dictionary + Map srcIP_map =null; + Map destIP_map=null; + Map srcPort_map =null; + Map destPort_map =null; + Map action_map=null; + Map fromZone_map=null; + Map toZone_map=null; + + String ruleDesc=null; + String ruleFromZone=null; + String ruleToZone=null; + String ruleSrcPrefixList=null; + String ruleDestPrefixList=null; + String ruleSrcPort=null; + String ruleDestPort=null; + String ruleAction=null; + + String json = null; + + + List expandableList = new ArrayList(); + TermList jpaTermList; + SecurityZone jpaSecurityZone; + List termList = new ArrayList(); + + ServiceListJson targetSl=null; + try{ + + for (int tl = 0 ; tl< termCollectorList.size(); tl++) { + expandableList.add(termCollectorList.get(tl)); + Term targetTerm = new Term(); + //targetSl= new ServiceListJson(); + targetTerm.setRuleName(termCollectorList.get(tl)); + List termListData = termListDao.getTermListData(); + for (int j =0; j < termListData.size(); j++) { + jpaTermList = termListData.get(j); + if (jpaTermList.getTermName().equals(termCollectorList.get(tl))){ + ruleDesc=jpaTermList.getTermDescription(); + if ((ruleDesc!=null)&& (!ruleDesc.isEmpty())){ + targetTerm.setDescription(ruleDesc); + } + ruleFromZone=jpaTermList.getFromZone(); + + if ((ruleFromZone != null) && (!ruleFromZone.isEmpty())){ + fromZone_map = new HashMap(); + fromZone_map.put(tl, ruleFromZone); + } + ruleToZone=jpaTermList.getToZone(); + + if ((ruleToZone != null) && (!ruleToZone.isEmpty())){ + toZone_map = new HashMap(); + toZone_map.put(tl, ruleToZone); + } + ruleSrcPrefixList=jpaTermList.getSrcIPList(); + + if ((ruleSrcPrefixList != null) && (!ruleSrcPrefixList.isEmpty())){ + srcIP_map = new HashMap(); + srcIP_map.put(tl, ruleSrcPrefixList); + } + + ruleDestPrefixList= jpaTermList.getDestIPList(); + if ((ruleDestPrefixList != null) && (!ruleDestPrefixList.isEmpty())){ + destIP_map = new HashMap(); + destIP_map.put(tl, ruleDestPrefixList); + } + + ruleSrcPort=jpaTermList.getSrcPortList(); + + if (ruleSrcPort != null && (!ruleSrcPort.isEmpty())){ + srcPort_map = new HashMap(); + srcPort_map.put(tl, ruleSrcPort); + } + + ruleDestPort= jpaTermList.getDestPortList(); + + if (ruleDestPort!= null && (!jpaTermList.getDestPortList().isEmpty())){ + destPort_map = new HashMap(); + destPort_map.put(tl, ruleDestPort); + } + + ruleAction=jpaTermList.getAction(); + + if (( ruleAction!= null) && (!ruleAction.isEmpty())){ + action_map = new HashMap(); + action_map.put(tl, ruleAction); + } + } + } + targetTerm.setEnabled(true); + targetTerm.setLog(true); + targetTerm.setNegateSource(false); + targetTerm.setNegateDestination(false); + + if(action_map!=null){ + targetTerm.setAction(action_map.get(tl)); + } + + //FromZone arrays + if(fromZone_map!=null){ + List fromZone= new ArrayList(); + for(String fromZoneStr:fromZone_map.get(tl).split(",") ){ + fromZone.add(fromZoneStr); + } + targetTerm.setFromZones(fromZone); + } + + //ToZone arrays + if(toZone_map!=null){ + List toZone= new ArrayList(); + for(String toZoneStr:toZone_map.get(tl).split(",") ){ + toZone.add(toZoneStr); + } + targetTerm.setToZones(toZone); + } + + //Destination Services. + if(destPort_map!=null){ + Set destServicesJsonList= new HashSet(); + for(String destServices:destPort_map.get(tl).split(",") ){ + ServicesJson destServicesJson= new ServicesJson(); + destServicesJson.setType("REFERENCE"); + if(destServices.equals("ANY")){ + destServicesJson.setName("any"); + destServicesJsonList.add(destServicesJson); + break; + }else{ + if(destServices.startsWith("Group_")){ + destServicesJson.setName(destServices.substring(6,destServices.length())); + } else{ + destServicesJson.setName(destServices); + } + destServicesJsonList.add(destServicesJson); + } + } + targetTerm.setDestServices(destServicesJsonList); + } + //ExpandableServicesList + if((srcPort_map!=null) && (destPort_map!=null)){ + String servicesCollateString = (srcPort_map.get(tl) + "," + destPort_map.get(tl)); + expandableServicesList.add(servicesCollateString); + }else if (srcPort_map!=null){ + expandableServicesList.add(srcPort_map.get(tl)); + }else if (destPort_map!=null){ + expandableServicesList.add(destPort_map.get(tl)); + } + + if(srcIP_map!=null){ + //Source List + List sourceListArrayJson= new ArrayList(); + for(String srcList:srcIP_map.get(tl).split(",") ){ + AddressJson srcListJson= new AddressJson(); + if(srcList.equals("ANY")){ + srcListJson.setType("any"); + sourceListArrayJson.add(srcListJson); + break; + }else{ + srcListJson.setType("REFERENCE"); + if(srcList.startsWith("Group_")){ + srcListJson.setValue(srcList.substring(6,srcList.length())); + }else{ + srcListJson.setValue(srcList); + } + sourceListArrayJson.add(srcListJson); + } + } + targetTerm.setSourceList(sourceListArrayJson); + } + if(destIP_map!=null){ + //Destination List + List destListArrayJson= new ArrayList(); + for(String destList:destIP_map.get(tl).split(",")){ + AddressJson destListJson= new AddressJson(); + if(destList.equals("ANY")){ + destListJson.setType("any"); + destListArrayJson.add(destListJson); + break; + }else{ + destListJson.setType("REFERENCE"); + if(destList.startsWith("Group_")){ + destListJson.setValue(destList.substring(6,destList.length())); + }else{ + destListJson.setValue(destList); + } + destListArrayJson.add(destListJson); + } + } + targetTerm.setDestinationList(destListArrayJson); + } + //ExpandablePrefixIPList + if ((srcIP_map!=null) && (destIP_map!=null)) + { + String collateString = (srcIP_map.get(tl) + "," + destIP_map + .get(tl)); + expandablePrefixIPList.add(collateString); + } + else if(srcIP_map!=null){ + expandablePrefixIPList.add(srcIP_map.get(tl)); + } + else if(destIP_map!=null){ + expandablePrefixIPList.add(destIP_map.get(tl)); + } + termList.add(targetTerm); + targetTerm.setPosition("" + (ruleCount++)); + } + TermCollector tc = new TermCollector(); + List securityZoneData = securityZoneDao.getSecurityZoneData(); + for (int j =0 ; j< securityZoneData.size() ; j++){ + jpaSecurityZone = securityZoneData.get(j); + if (jpaSecurityZone.getZoneName().equals(policyAdapter.getSecurityZone())){ + tc.setSecurityZoneId(jpaSecurityZone.getZoneValue()); + setParentSecurityZone(jpaSecurityZone.getZoneValue());//For storing the securityZone IDs to the DB + break; + } + } + + tc.setServiceTypeId("/v0/firewall/pan"); + tc.setConfigName(policyAdapter.getConfigName()); + + if(policyAdapter.getFwPolicyType().equalsIgnoreCase("Child Policy")){ + String securityZoneQuery="SELECT SECURITYZONE FROM FWPARENT WHERE PARENT='"; + securityZoneQuery=securityZoneQuery+policyAdapter.getParentForChild()+"'"; + List securityZoneValue= queryToDatabase(securityZoneQuery); + tc.setPrimaryParentZoneId(securityZoneValue.get(0)); + } + //Astra is rejecting the packet when it sees a new JSON field, so removing it for now. + //tc.setTemplateVersion(XACMLProperties.getProperty(XACMLRestProperties.TemplateVersion_FW)); + + DeployNowJson deployNow= new DeployNowJson(); + deployNow.setDeployNow(false); + + tc.setDeploymentOption(deployNow); + + Set servListArray = new HashSet(); + Set servGroupArray= new HashSet(); + Set addrGroupArray= new HashSet(); + + ServiceGroupJson targetSg= null; + AddressGroupJson addressSg=null; + ServiceListJson targetAny= null; + ServiceListJson targetAnyTcp=null; + ServiceListJson targetAnyUdp=null; + + for(String serviceList:expandableServicesList){ + for(String t: serviceList.split(",")){ + if((!t.startsWith("Group_"))){ + if(!t.equals("ANY")){ + ServiceList sl = new ServiceList(); + targetSl= new ServiceListJson(); + sl= mappingServiceList(t); + targetSl.setName(sl.getServiceName()); + targetSl.setDescription(sl.getServiceDescription()); + targetSl.setTransportProtocol(sl.getServiceTransProtocol()); + targetSl.setType(sl.getServiceType()); + targetSl.setPorts(sl.getServicePorts()); + servListArray.add(targetSl); + }else{ + //Any for destinationServices. + //Add names any, any-tcp, any-udp to the serviceGroup object. + targetAny= new ServiceListJson(); + targetAny.setName("any"); + targetAny.setType("SERVICE"); + targetAny.setTransportProtocol("any"); + targetAny.setPorts("any"); + + servListArray.add(targetAny); + + targetAnyTcp= new ServiceListJson(); + targetAnyTcp.setName("any-tcp"); + targetAnyTcp.setType("SERVICE"); + targetAnyTcp.setTransportProtocol("tcp"); + targetAnyTcp.setPorts("any"); + + servListArray.add(targetAnyTcp); + + targetAnyUdp= new ServiceListJson(); + targetAnyUdp.setName("any-udp"); + targetAnyUdp.setType("SERVICE"); + targetAnyUdp.setTransportProtocol("udp"); + targetAnyUdp.setPorts("any"); + + servListArray.add(targetAnyUdp); + } + }else{//This is a group + GroupServiceList sg= new GroupServiceList(); + targetSg= new ServiceGroupJson(); + sg= mappingServiceGroup(t); + + String name=sg.getGroupName(); + //Removing the "Group_" prepending string before packing the JSON + targetSg.setName(name.substring(6,name.length())); + List servMembersList= new ArrayList(); + + for(String groupString: sg.getServiceList().split(",")){ + ServiceMembers serviceMembers= new ServiceMembers(); + serviceMembers.setType("REFERENCE"); + serviceMembers.setName(groupString); + servMembersList.add(serviceMembers); + //Expand the group Name + ServiceList expandGroupSl = new ServiceList(); + targetSl= new ServiceListJson(); + expandGroupSl= mappingServiceList(groupString); + + targetSl.setName(expandGroupSl.getServiceName()); + targetSl.setDescription(expandGroupSl.getServiceDescription()); + targetSl.setTransportProtocol(expandGroupSl.getServiceTransProtocol()); + targetSl.setType(expandGroupSl.getServiceType()); + targetSl.setPorts(expandGroupSl.getServicePorts()); + servListArray.add(targetSl); + } + + targetSg.setMembers(servMembersList); + servGroupArray.add(targetSg); + + } + } + } + + Set prefixIPList = new HashSet(); + for(String prefixList:expandablePrefixIPList){ + for(String prefixIP: prefixList.split(",")){ + if((!prefixIP.startsWith("Group_"))){ + if(!prefixIP.equals("ANY")){ + List addMembersList= new ArrayList(); + List valueDesc= new ArrayList(); + PrefixIPList targetAddressList = new PrefixIPList(); + AddressMembers addressMembers= new AddressMembers(); + targetAddressList.setName(prefixIP); + + valueDesc = mapping(prefixIP); + targetAddressList.setDescription(valueDesc.get(1)); + + addressMembers.setType("SUBNET"); + addressMembers.setValue(valueDesc.get(0)); + + addMembersList.add(addressMembers); + + targetAddressList.setMembers(addMembersList); + prefixIPList.add(targetAddressList); + } + } + else{//This is a group + AddressGroup ag= new AddressGroup(); + addressSg= new AddressGroupJson(); + ag= mappingAddressGroup(prefixIP); + + String name=ag.getGroupName(); + //Removing the "Group_" prepending string before packing the JSON + addressSg.setName(name.substring(6,name.length())); + + List addrMembersList= new ArrayList(); + for(String groupString: ag.getPrefixList().split(",")){ + List valueDesc= new ArrayList(); + AddressMembers addressMembers= new AddressMembers(); + valueDesc= mapping (groupString); + if(valueDesc.size() > 0){ + addressMembers.setValue(valueDesc.get(0)); + } + addressMembers.setType("SUBNET"); + addrMembersList.add(addressMembers); + //Expand the group Name + } + addressSg.setMembers(addrMembersList); + addrGroupArray.add(addressSg); + } + + + } + } + + Set serviceGroup= new HashSet(); + + for(Object obj1:servGroupArray){ + serviceGroup.add(obj1); + } + + for(Object obj:servListArray){ + serviceGroup.add(obj); + } + + Set addressGroup= new HashSet(); + + for(Object addObj:prefixIPList){ + addressGroup.add(addObj); + } + + for(Object addObj1:addrGroupArray){ + addressGroup.add(addObj1); + } + + tc.setServiceGroups(serviceGroup); + tc.setAddressGroups(addressGroup); + tc.setFirewallRuleList(termList); + + + ObjectWriter om = new ObjectMapper().writer(); + try { + json = om.writeValueAsString(tc); + } catch (JsonGenerationException e) { + e.printStackTrace(); + } catch (JsonMappingException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + + }catch (Exception e) { + e.printStackTrace(); + } + + return json; + } + + private List mapping(String expandableList) { + String value = new String(); + String desc = new String(); + List valueDesc= new ArrayList(); + List prefixListData = prefixListDao.getPREFIXLISTData(); + for (int i = 0; i< prefixListData.size(); i++) { + PREFIXLIST prefixList = prefixListData.get(i); + if (prefixList.getPrefixListName().equals(expandableList)) { + value = prefixList.getPrefixListValue(); + valueDesc.add(value); + desc= prefixList.getDescription(); + valueDesc.add(desc); + break; + } + } + return valueDesc; + } + + private ServiceList mappingServiceList(String expandableList) { + ServiceList serviceList=null; + List serviceListData = serviceListDao.getServiceListData(); + for (int i = 0; i< serviceListData.size(); i++) { + serviceList = serviceListData.get(i); + if (serviceList.getServiceName().equals(expandableList)) { + break; + } + } + return serviceList; + } + + private GroupServiceList mappingServiceGroup(String expandableList) { + + GroupServiceList serviceGroup=null; + List serviceGroupData = serviceGroupDao.getGroupServiceListData(); + for (int i = 0; i< serviceGroupData.size(); i++) { + serviceGroup = serviceGroupData.get(i); + if (serviceGroup.getGroupName().equals(expandableList)) { + break; + } + } + return serviceGroup; + } + + private AddressGroup mappingAddressGroup(String expandableList) { + + AddressGroup addressGroup=null; + List addressGroupData = addressGroupDao.getAddressGroupData(); + for (int i = 0; i< addressGroupData.size(); i++) { + addressGroup = addressGroupData.get(i); + if (addressGroup.getGroupName().equals(expandableList)) { + break; + } + } + return addressGroup; + } + + public void PrePopulateFWPolicyData(PolicyAdapter policyAdapter) { + attributeList = new ArrayList(); + fwAttributeList = new ArrayList(); + if (policyAdapter.getPolicyData() instanceof PolicyType) { + Object policyData = policyAdapter.getPolicyData(); + PolicyType policy = (PolicyType) policyData; + // policy name value is the policy name without any prefix and Extensions. + policyAdapter.setOldPolicyFileName(policyAdapter.getPolicyName()); + String policyNameValue = policyAdapter.getPolicyName().substring(policyAdapter.getPolicyName().indexOf("FW_") +3, policyAdapter.getPolicyName().lastIndexOf(".")); + if (logger.isDebugEnabled()) { + logger.debug("Prepopulating form data for Config Policy selected:"+ policyAdapter.getPolicyName()); + } + policyAdapter.setPolicyName(policyNameValue); + String description = ""; + try{ + description = policy.getDescription().substring(0, policy.getDescription().indexOf("@CreatedBy:")); + }catch(Exception e){ + description = policy.getDescription(); + } + policyAdapter.setPolicyDescription(description); + + ObjectMapper mapper = new ObjectMapper(); + + TermCollector tc1=null; + BufferedReader br=null; + try { + //Json conversion. + String data=null; + SecurityZone jpaSecurityZone; + File file = new File(PolicyController.getConfigHome()+ File.separator+ policyAdapter.getDirPath().replace(File.separator, ".")+"."+ policyAdapter.getOldPolicyFileName() +".json"); + // Get data from this file using a file reader. + FileReader fr = new FileReader(file); + // To store the contents read via File Reader + br = new BufferedReader(fr); + // Read br and store a line in 'data', print data + data = br.readLine(); + tc1 = (TermCollector)mapper.readValue(data, TermCollector.class); + List securityZoneData = securityZoneDao.getSecurityZoneData(); + for (int i = 0; i < securityZoneData.size() ; i++) { + jpaSecurityZone = securityZoneData.get(i); + if (jpaSecurityZone.getZoneValue().equals(tc1.getSecurityZoneId())){ + policyAdapter.setSecurityZone(jpaSecurityZone.getZoneName()); + break; + } + } + if(tc1.getPrimaryParentZoneId()!=null)//Child policy + { + policyAdapter.setFwPolicyType("Child Policy"); + + String pathName=policyAdapter.getParentPath().toString(); + String scope= pathName.substring(pathName.lastIndexOf(File.separator)+1); + String fullPathName=scope+".Config_FW_"+policyNameValue; + + String query= "select parent from FWChildToParent where child='"; + query=query+fullPathName+"'"; + + List parentName=queryToDatabase(query); + policyAdapter.setParentForChild(parentName.get(0)); + + } + else{//Parent Policy + policyAdapter.setFwPolicyType("Parent Policy"); + //Retrieving the Dictionary combo list. + String desc = policy.getDescription(); + String descripComboList = desc.substring(desc.indexOf("@comboList:")+11,desc.length()) ; + Map parentMap = new HashMap(); + for(String value : descripComboList.split(",")){ + parentMap.put("option", value); + fwAttributeList.add(parentMap); + } + policyAdapter.setFwattributes(fwAttributeList); + } + } + catch(Exception e) { + logger.error("Exception Caused while Retriving the JSON body data" +e); + } + finally { + try { + if (br != null)br.close(); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + + for (Term t : tc1.getFirewallRuleList()) { + Map termMap = new HashMap(); + termMap.put("option", t.getRuleName()); + attributeList.add(termMap); + } + policyAdapter.setAttributes(attributeList); + // Get the target data under policy. + TargetType target = policy.getTarget(); + if (target != null) { + // Under target we have AnyOFType + List anyOfList = target.getAnyOf(); + if (anyOfList != null) { + int index = 0; + Iterator iterAnyOf = anyOfList.iterator(); + while (iterAnyOf.hasNext()) { + AnyOfType anyOf = iterAnyOf.next(); + // Under AnyOFType we have AllOFType + List allOfList = anyOf.getAllOf(); + if (allOfList != null) { + Iterator iterAllOf = allOfList.iterator(); + while (iterAllOf.hasNext()) { + AllOfType allOf = iterAllOf.next(); + // Under AllOFType we have Match + List matchList = allOf.getMatch(); + if (matchList != null) { + + Iterator iterMatch = matchList.iterator(); + while (iterMatch.hasNext()) { + MatchType match = iterMatch.next(); + // + // Under the match we have attribute value and + // attributeDesignator. So,finally down to the actual attribute. + // + AttributeValueType attributeValue = match.getAttributeValue(); + String value = (String) attributeValue.getContent().get(0); + if (index == 1) { + policyAdapter.setConfigName(value); + } + if (index == 2){ + policyAdapter.setRiskType(value); + } + + if (index == 3){ + policyAdapter.setRiskLevel(value); + } + + if (index == 4){ + policyAdapter.setGuard(value); + } + if (index == 5 && !value.contains("NA")){ + String newDate = convertDate(value, true); + policyAdapter.setTtlDate(newDate); + } + index++; + } + } + } + } + } + } + } + } + } + + private String convertDate(String dateTTL, boolean portalType) { + String formateDate = null; + String[] date; + String[] parts; + + if (portalType){ + parts = dateTTL.split("-"); + formateDate = parts[2] + "-" + parts[1] + "-" + parts[0] + "T05:00:00.000Z"; + } else { + date = dateTTL.split("T"); + parts = date[0].split("-"); + formateDate = parts[2] + "-" + parts[1] + "-" + parts[0]; + } + return formateDate; + } + + @RequestMapping(value={"/policyController/ViewFWPolicyRule.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView setFWViewRule(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + termCollectorList = new ArrayList(); + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + PolicyAdapter policyData = (PolicyAdapter)mapper.readValue(root.get("policyData").toString(), PolicyAdapter.class); + if(policyData.getAttributes().size() > 0){ + for(Object attribute : policyData.getAttributes()){ + if(attribute instanceof LinkedHashMap){ + String key = ((LinkedHashMap) attribute).get("option").toString(); + termCollectorList.add(key); + } + } + } + TermList jpaTermList; + String ruleSrcList=null; + String ruleDestList=null; + String ruleSrcPort=null; + String ruleDestPort=null; + String ruleAction=null; + List valueDesc= new ArrayList(); + StringBuffer displayString = new StringBuffer(); + for (String id : termCollectorList) { + jpaTermList = termListDao.getTermListValueByName(id); + if (jpaTermList != null){ + ruleSrcList= ((TermList) jpaTermList).getSrcIPList(); + if ((ruleSrcList!= null) && (!ruleSrcList.isEmpty()) && !ruleSrcList.equals("null")){ + displayString.append("Source IP List: " + ((TermList) jpaTermList).getSrcIPList()); + displayString.append(" ; \t\n"); + for(String srcList:ruleSrcList.split(",")){ + if(srcList.startsWith("Group_")){ + AddressGroup ag= new AddressGroup(); + ag= mappingAddressGroup(srcList); + displayString.append("\n\t"+"Group has :"+ag.getPrefixList()+"\n"); + for(String groupItems:ag.getPrefixList().split(",")){ + valueDesc=mapping(groupItems); + displayString.append("\n\t"+"Name: "+groupItems); + if(!valueDesc.isEmpty()){ + displayString.append("\n\t"+"Description: "+valueDesc.get(1)); + displayString.append("\n\t"+"Value: "+valueDesc.get(0)); + } + displayString.append("\n"); + } + }else{ + if(!srcList.equals("ANY")){ + valueDesc=mapping(srcList); + displayString.append("\n\t"+"Name: "+srcList); + displayString.append("\n\t"+"Description: "+valueDesc.get(1)); + displayString.append("\n\t"+"Value: "+valueDesc.get(0)); + displayString.append("\n"); + } + } + } + displayString.append("\n"); + } + ruleDestList= ((TermList) jpaTermList).getDestIPList(); + if ( ruleDestList!= null && (!ruleDestList.isEmpty())&& !ruleDestList.equals("null")){ + displayString.append("Destination IP List: " + ((TermList) jpaTermList).getDestIPList()); + displayString.append(" ; \t\n"); + for(String destList:ruleDestList.split(",")){ + if(destList.startsWith("Group_")){ + AddressGroup ag= new AddressGroup(); + ag= mappingAddressGroup(destList); + displayString.append("\n\t"+"Group has :"+ag.getPrefixList()+"\n"); + for(String groupItems:ag.getPrefixList().split(",")){ + valueDesc=mapping(groupItems); + displayString.append("\n\t"+"Name: "+groupItems); + displayString.append("\n\t"+"Description: "+valueDesc.get(1)); + displayString.append("\n\t"+"Value: "+valueDesc.get(0)); + displayString.append("\n\t"); + } + }else{ + if(!destList.equals("ANY")){ + valueDesc=mapping(destList); + displayString.append("\n\t"+"Name: "+destList); + displayString.append("\n\t"+"Description: "+valueDesc.get(1)); + displayString.append("\n\t"+"Value: "+valueDesc.get(0)); + displayString.append("\n\t"); + } + } + } + displayString.append("\n"); + } + + ruleSrcPort=((TermList) jpaTermList).getSrcPortList(); + if ( ruleSrcPort!= null && (!ruleSrcPort.isEmpty())&& !ruleSrcPort.equals("null")) { + displayString.append("\n"+"Source Port List:" + + ruleSrcPort); + displayString.append(" ; \t\n"); + } + + ruleDestPort= ((TermList) jpaTermList).getDestPortList(); + if (ruleDestPort != null && (!ruleDestPort.isEmpty())&& !ruleDestPort.equals("null")) { + displayString.append("\n"+"Destination Port List:" + + ruleDestPort); + displayString.append(" ; \t\n"); + for(String destServices:ruleDestPort.split(",")){ + if(destServices.startsWith("Group_")){ + GroupServiceList sg= new GroupServiceList(); + sg= mappingServiceGroup(destServices); + displayString.append("\n\t"+"Service Group has :"+sg.getServiceList()+"\n"); + for(String groupItems:sg.getServiceList().split(",")){ + ServiceList sl= new ServiceList(); + sl= mappingServiceList(groupItems); + displayString.append("\n\t"+"Name: "+ + sl.getServiceName()); + displayString.append("\n\t"+"Description: "+ + sl.getServiceDescription()); + displayString.append("\n\t"+"Transport-Protocol: "+ + sl.getServiceTransProtocol()); + displayString.append("\n\t"+"Ports: "+ + sl.getServicePorts()); + displayString.append("\n"); + } + } + else{ + if(!destServices.equals("ANY")){ + ServiceList sl= new ServiceList(); + sl= mappingServiceList(destServices); + displayString.append("\n\t"+"Name: "+ + sl.getServiceName()); + displayString.append("\n\t"+"Description: "+ + sl.getServiceDescription()); + displayString.append("\n\t"+"Transport-Protocol: "+ + sl.getServiceTransProtocol()); + displayString.append("\n\t"+"Ports: "+ + sl.getServicePorts()); + displayString.append("\n"); + } + } + } + displayString.append("\n"); + } + + ruleAction=(jpaTermList).getAction(); + if ( ruleAction!= null && (!ruleAction.isEmpty())) { + displayString.append("\n"+"Action List:" + + ruleAction); + displayString.append(" ; \t\n"); + } + } + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = mapper.writeValueAsString(displayString); + JSONObject j = new JSONObject("{policyData: " + responseString + "}"); + out.write(j.toString()); + return null; + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + } + return null; + } + + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/CreatePolicyController.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/CreatePolicyController.java new file mode 100644 index 000000000..f5c0a576c --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/CreatePolicyController.java @@ -0,0 +1,484 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.controller; + + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintWriter; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +//import org.apache.commons.logging.Log; +//import org.apache.commons.logging.LogFactory; +import org.json.JSONObject; +import org.openecomp.policy.adapter.PolicyAdapter; +import org.openecomp.policy.admin.PolicyNotificationMail; +import org.openecomp.policy.admin.RESTfulPAPEngine; +import org.openecomp.policy.dao.PolicyVersionDao; +import org.openecomp.policy.dao.RuleAlgorithmsDao; +import org.openecomp.policy.dao.WatchPolicyNotificationDao; +import org.openecomp.policy.elk.client.PolicyElasticSearchController; +import org.openecomp.policy.rest.jpa.PolicyVersion; +import org.openecomp.policy.rest.jpa.RuleAlgorithms; +import org.openecomp.portalsdk.core.controller.RestrictedBaseController; +import org.openecomp.portalsdk.core.web.support.JsonMessage; +import org.openecomp.portalsdk.core.web.support.UserUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +import com.att.research.xacml.api.XACML3; +import org.openecomp.policy.xacml.api.XACMLErrorConstants; +import org.openecomp.policy.xacml.util.XACMLPolicyScanner; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.base.Joiner; + +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.RuleType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType; + +@Controller +@RequestMapping("/") +public class CreatePolicyController extends RestrictedBaseController{ + private static Logger logger = FlexLogger.getLogger(CreatePolicyController.class); + + private static RuleAlgorithmsDao ruleAlgorithmsDao; + private static PolicyVersionDao policyVersionDao; + private static WatchPolicyNotificationDao policyNotificationDao; + + @Autowired + private CreatePolicyController(RuleAlgorithmsDao ruleAlgorithmsDao, PolicyVersionDao policyVersionDao, WatchPolicyNotificationDao policyNotificationDao){ + CreatePolicyController.policyVersionDao = policyVersionDao; + CreatePolicyController.ruleAlgorithmsDao = ruleAlgorithmsDao; + CreatePolicyController.policyNotificationDao = policyNotificationDao; + } + + public CreatePolicyController(){} + + protected PolicyAdapter policyAdapter = null; + private String ruleID = ""; + private ArrayList attributeList; + boolean isValidForm = false; + private int riskLevelCount; + + public String newPolicyID() { + return Joiner.on(':').skipNulls().join((PolicyController.getDomain().startsWith("urn") ? null: "urn"), + PolicyController.getDomain().replaceAll("[/\\\\.]", ":"), "xacml", "policy", "id", UUID.randomUUID()); + } + + @RequestMapping(value={"/get_RiskLevelValues"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getRiskLevelValuesData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + List riskLevelList = new ArrayList(); + riskLevelCount = 5; + for (int i = 1; i <= riskLevelCount; i++) { + riskLevelList.add(String.valueOf(i)); + } + model.put("riskLevelDatas", mapper.writeValueAsString(riskLevelList)); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_GuardlValues"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getGuardValuesData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + List guardList = new ArrayList(); + guardList.add("True"); + guardList.add("False"); + model.put("guardDatas", mapper.writeValueAsString(guardList)); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + + @RequestMapping(value={"/policyController/save_policy.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView savePolicy(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + String userId = UserUtils.getUserIdFromCookie(request); + RESTfulPAPEngine engine = (RESTfulPAPEngine) PolicyController.getPapEngine(); + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + PolicyAdapter policyData = (PolicyAdapter)mapper.readValue(root.get("policyData").get("policy").toString(), PolicyAdapter.class); + policyData.setDomainDir(root.get("policyData").get("model").get("name").toString().replace("\"", "")); + if(root.get("policyData").get("model").get("type").toString().replace("\"", "").equals("file")){ + policyData.isEditPolicy = true; + } + + if (policyData.getTtlDate()==null){ + policyData.setTtlDate("NA"); + }else{ + String dateTTL = policyData.getTtlDate(); + String newDate = convertDate(dateTTL, false); + policyData.setTtlDate(newDate); + } + + if(root.get("policyData").get("model").get("path").size() != 0){ + String dirName = ""; + for(int i = 0; i < root.get("policyData").get("model").get("path").size(); i++){ + dirName = dirName.replace("\"", "") + root.get("policyData").get("model").get("path").get(i).toString().replace("\"", "") + File.separator; + } + policyData.setDomainDir(dirName.substring(0, dirName.lastIndexOf(File.separator))); + }else{ + policyData.setDomainDir(root.get("policyData").get("model").get("name").toString().replace("\"", "")); + } + + int version = 0; + int highestVersion = 0; + int descriptionVersion = 0; + //get the highest version of policy from policy version table. + //getting the sub scope domain where the policy is created or updated + String dbCheckPolicyName = policyData.getDomainDir() + File.separator + "Config_" + policyData.getPolicyName(); + List policyVersionlist = policyVersionDao.getPolicyVersionEntityByName(dbCheckPolicyName); + if (policyVersionlist.size() > 0) { + for(int i = 0; i < policyVersionlist.size(); i++) { + PolicyVersion entityItem = policyVersionlist.get(i); + if(entityItem.getPolicyName().equals(dbCheckPolicyName)){ + highestVersion = entityItem.getHigherVersion(); + } + } + } + if(highestVersion != 0){ + version = highestVersion; + descriptionVersion = highestVersion +1; + }else{ + version = 1; + descriptionVersion = 1; + } + + //set policy adapter values for Building JSON object containing policy data + String createdBy = ""; + String modifiedBy = userId; + if(descriptionVersion == 1){ + createdBy = userId; + }else{ + String policyName = PolicyController.getGitPath().toAbsolutePath().toString() + File.separator + policyData.getDomainDir() + File.separator + policyData.getOldPolicyFileName() + ".xml"; + File policyPath = new File(policyName); + try { + createdBy = XACMLPolicyScanner.getCreatedBy(policyPath.toPath()); + } catch (IOException e) { + createdBy = "guest"; + } + } + + policyData.setPolicyDescription(policyData.getPolicyDescription()+ "@CreatedBy:" +createdBy + "@CreatedBy:" + "@ModifiedBy:" +modifiedBy + "@ModifiedBy:"); + + Map successMap = new HashMap(); + Map attributeMap = new HashMap(); + //set the Rule Combining Algorithm Id to be sent to PAP-REST via JSON + List ruleAlgorithmList = ruleAlgorithmsDao.getRuleAlgorithms(); + for (int i = 0; i < ruleAlgorithmList.size(); i++) { + RuleAlgorithms a = ruleAlgorithmList.get(i); + if (a.getXacmlId().equals(XACML3.ID_RULE_PERMIT_OVERRIDES.stringValue())) { + policyData.setRuleCombiningAlgId(a.getXacmlId()); + break; + } + } + + if(policyData.getAttributes().size() > 0){ + for(Object attribute : policyData.getAttributes()){ + if(attribute instanceof LinkedHashMap){ + String key = ((LinkedHashMap) attribute).get("option").toString(); + String value = ((LinkedHashMap) attribute).get("number").toString(); + attributeMap.put(key, value); + } + } + } + policyData.setDynamicFieldConfigAttributes(attributeMap); + + if (policyData.isEditPolicy()){ + //increment the version and set in policyAdapter + policyData.setVersion(String.valueOf(version)); + policyData.setHighestVersion(version); + policyData.setPolicyID(this.newPolicyID()); + policyData.setRuleID(ruleID); + successMap = engine.updatePolicyRequest(policyData); + } else { + //send it for policy creation + policyData.setVersion(String.valueOf(version)); + policyData.setHighestVersion(version); + successMap = engine.createPolicyRequest(policyData); + + } + + if (successMap.containsKey("success")) { + // Add it into our tree + Path finalPolicyPath = null; + finalPolicyPath = Paths.get(successMap.get("success")); + PolicyElasticSearchController controller = new PolicyElasticSearchController(); + controller.updateElk(finalPolicyPath.toString()); + File file = finalPolicyPath.toFile(); + if(file != null){ + String policyName = file.toString(); + String removePath = policyName.substring(policyName.indexOf("repository")+11); + String removeXml = removePath.replace(".xml", ""); + String removeExtension = removeXml.substring(0, removeXml.indexOf(".")); + List versionList = policyVersionDao.getPolicyVersionEntityByName(removeExtension); + if (versionList.size() > 0) { + for(int i = 0; i < versionList.size(); i++) { + PolicyVersion entityItem = versionList.get(i); + if(entityItem.getPolicyName().equals(removeExtension)){ + version = entityItem.getHigherVersion() +1; + entityItem.setActiveVersion(version); + entityItem.setHigherVersion(version); + entityItem.setModifiedBy(userId); + policyVersionDao.update(entityItem); + if(policyData.isEditPolicy){ + PolicyNotificationMail email = new PolicyNotificationMail(); + String mode = "EditPolicy"; + String policyNameForEmail = policyData.getDomainDir() + File.separator + policyData.getOldPolicyFileName() + ".xml"; + email.sendMail(entityItem, policyNameForEmail, mode, policyNotificationDao); + } + } + } + }else{ + PolicyVersion entityItem = new PolicyVersion(); + entityItem.setActiveVersion(version); + entityItem.setHigherVersion(version); + entityItem.setPolicyName(removeExtension); + entityItem.setCreatedBy(userId); + entityItem.setModifiedBy(userId); + policyVersionDao.Save(entityItem); + } + } + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = mapper.writeValueAsString(successMap); + JSONObject j = new JSONObject("{policyData: " + responseString + "}"); + out.write(j.toString()); + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + private String convertDate(String dateTTL, boolean portalType) { + String formateDate = null; + String[] date; + String[] parts; + + if (portalType){ + parts = dateTTL.split("-"); + formateDate = parts[2] + "-" + parts[1] + "-" + parts[0] + "T05:00:00.000Z"; + } else { + date = dateTTL.split("T"); + parts = date[0].split("-"); + formateDate = parts[2] + "-" + parts[1] + "-" + parts[0]; + } + return formateDate; + } + + public void PrePopulateBaseConfigPolicyData(PolicyAdapter policyAdapter) { + attributeList = new ArrayList(); + if (policyAdapter.getPolicyData() instanceof PolicyType) { + Object policyData = policyAdapter.getPolicyData(); + PolicyType policy = (PolicyType) policyData; + policyAdapter.setOldPolicyFileName(policyAdapter.getPolicyName()); + policyAdapter.setConfigBodyData(readBaseConfigJSONFile(policyAdapter)); + String policyNameValue = policyAdapter.getPolicyName().substring(policyAdapter.getPolicyName().indexOf("_") + 1 , policyAdapter.getPolicyName().lastIndexOf(".")); + policyAdapter.setPolicyName(policyNameValue); + String description = ""; + try{ + description = policy.getDescription().substring(0, policy.getDescription().indexOf("@CreatedBy:")); + }catch(Exception e){ + description = policy.getDescription(); + } + policyAdapter.setPolicyDescription(description); + // Get the target data under policy. + TargetType target = policy.getTarget(); + if (target != null) { + // Under target we have AnyOFType + List anyOfList = target.getAnyOf(); + if (anyOfList != null) { + Iterator iterAnyOf = anyOfList.iterator(); + while (iterAnyOf.hasNext()) { + AnyOfType anyOf = iterAnyOf.next(); + // Under AnyOFType we have AllOFType + List allOfList = anyOf.getAllOf(); + if (allOfList != null) { + Iterator iterAllOf = allOfList.iterator(); + int index = 0; + while (iterAllOf.hasNext()) { + AllOfType allOf = iterAllOf.next(); + // Under AllOFType we have Match + List matchList = allOf.getMatch(); + if (matchList != null) { + Iterator iterMatch = matchList.iterator(); + while (iterMatch.hasNext()) { + MatchType match = iterMatch.next(); + // + // Under the match we have attributevalue and + // attributeDesignator. So,finally down to the actual attribute. + // + AttributeValueType attributeValue = match.getAttributeValue(); + String value = (String) attributeValue.getContent().get(0); + AttributeDesignatorType designator = match.getAttributeDesignator(); + String attributeId = designator.getAttributeId(); + // First match in the target is EcompName, so set that value. + if (index == 1) { + policyAdapter.setEcompName(value); + } + if (index == 2){ + policyAdapter.setRiskType(value); + } + + if (index == 3){ + policyAdapter.setRiskLevel(value); + } + + if (index == 4){ + policyAdapter.setGuard(value); + } + if (index == 5 && !value.contains("NA")){ + String newDate = convertDate(value, true); + policyAdapter.setTtlDate(newDate); + } + if (index == 6){ + policyAdapter.setConfigName(value); + } + // After Ecomp and Config it is optional to have attributes, so + // check weather dynamic values or there or not. + if (index >= 7) { + Map attribute = new HashMap(); + attribute.put("option", attributeId); + attribute.put("number", value); + attributeList.add(attribute); + } + index++; + } + } + } + } + } + } + + policyAdapter.setAttributes(attributeList); + } + List ruleList = policy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition(); + for (Object o : ruleList) { + if (o instanceof RuleType) { + // get the condition data under the rule for rule Algorithms. + policyAdapter.setRuleID(((RuleType) o).getRuleId()); + } + } + } + } + + private String readBaseConfigJSONFile(PolicyAdapter policyAdapter) { + String fileName = policyAdapter.getPolicyName(); + String fileLocation = null; + if (fileName != null && fileName.contains("Config")) { + fileLocation = PolicyController.getConfigHome(); + } + if (logger.isDebugEnabled()) { + logger.debug("Attempting to read file from the location: " + fileLocation); + } + + if (fileLocation == null) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Error with the FileName: " + fileName); + return fileLocation; + } + + + File dir = new File(fileLocation); + File[] listOfFiles = dir.listFiles(); + String extension = null; + for (File file : listOfFiles) { + if (file.isFile() && file.getName().contains(fileName)) { + // For config form we have set the ConfigType Based on the extention. + if (fileName.contains("Config")) { + extension = file.getName().substring(file.getName().lastIndexOf('.') + 1); + // Based on file type set Combobox config value + if (extension.equals("txt")) { + policyAdapter.setConfigType("OTHER"); + } else { + policyAdapter.setConfigType(extension.toUpperCase()); + } + } + // Reading the file + try (BufferedReader br = new BufferedReader(new FileReader(file))) { + StringBuilder sb = new StringBuilder(); + String line = br.readLine(); + while (line != null) { + sb.append(line); + sb.append("\n"); + line = br.readLine(); + } + return sb.toString(); + } catch (FileNotFoundException e) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e.getMessage()); + } catch (IOException e1) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e1.getMessage()); + } + } + } + return null; + } +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/DashboardController.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/DashboardController.java new file mode 100644 index 000000000..301c824f0 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/DashboardController.java @@ -0,0 +1,430 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.controller; + + +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import javax.management.AttributeNotFoundException; +import javax.management.InstanceNotFoundException; +import javax.management.MBeanException; +import javax.management.MalformedObjectNameException; +import javax.management.ObjectName; +import javax.management.ReflectionException; +import javax.management.remote.JMXConnector; +import javax.management.remote.JMXConnectorFactory; +import javax.management.remote.JMXServiceURL; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +//import org.apache.commons.logging.Log; +//import org.apache.commons.logging.LogFactory; +import org.json.JSONObject; +import org.openecomp.policy.dao.SystemLogDbDao; +import org.openecomp.policy.model.PDPGroupContainer; +import org.openecomp.policy.rest.XACMLRestProperties; +import org.openecomp.portalsdk.core.controller.RestrictedBaseController; +import org.openecomp.portalsdk.core.web.support.JsonMessage; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; +import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; +import org.openecomp.policy.xacml.api.XACMLErrorConstants; +import org.openecomp.policy.xacml.api.pap.EcompPDP; +import org.openecomp.policy.xacml.api.pap.EcompPDPGroup; + +import com.att.research.xacml.api.pap.PAPException; +import com.att.research.xacml.api.pap.PDP; +import com.att.research.xacml.api.pap.PDPGroup; +import com.att.research.xacml.api.pap.PDPPolicy; +import com.att.research.xacml.util.XACMLProperties; +import com.fasterxml.jackson.annotation.PropertyAccessor; +import com.fasterxml.jackson.databind.ObjectMapper; + +@Controller +@RequestMapping({"/"}) +public class DashboardController extends RestrictedBaseController{ + private static final Logger logger = FlexLogger.getLogger(DashboardController.class); + @Autowired + SystemLogDbDao systemDAO; + + private int pdpCount; + private PDPGroupContainer pdpConatiner; + private ArrayList pdpStatusData; + private ArrayList papStatusData; + private ArrayList policyActivityData; + + + + @RequestMapping(value={"/get_DashboardLoggingData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("availableLoggingDatas", mapper.writeValueAsString(systemDAO.getLoggingData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_DashboardSystemAlertData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getSystemAlertData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("systemAlertsTableDatas", mapper.writeValueAsString(systemDAO.getSystemAlertData())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_DashboardPAPStatusData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getPAPStatusData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY); + addPAPToTable(); + model.put("papTableDatas", mapper.writeValueAsString(papStatusData)); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_DashboardPDPStatusData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getPDPStatusData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY); + this.pdpConatiner = new PDPGroupContainer(PolicyController.getPapEngine()); + addPDPToTable(); + model.put("pdpTableDatas", mapper.writeValueAsString(pdpStatusData)); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/get_DashboardPolicyActivityData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getPolicyActivityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY); + this.pdpConatiner = new PDPGroupContainer(PolicyController.getPapEngine()); + addPolicyToTable(); + model.put("policyActivityTableDatas", mapper.writeValueAsString(policyActivityData)); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + /* + * Add the PAP information to the PAP Table + */ + public void addPAPToTable(){ + papStatusData = new ArrayList(); + File folder = new File(PolicyController.getGitPath().toAbsolutePath().toString()); + String papStatus = null; + try { + Set groups = PolicyController.getPapEngine().getEcompPDPGroups(); + if (groups == null) { + papStatus = "UNKNOWN"; + throw new PAPException("PAP not running"); + }else { + papStatus = "IS_OK"; + } + } catch (PAPException | NullPointerException e1) { + papStatus = "CANNOT_CONNECT"; + logger.error("Error getting PAP status, PAP not responding to requests"); + } + String papURL = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_URL); + JSONObject object = new JSONObject(); + object.put("system", papURL); + object.put("status", papStatus); + object.put("noOfPolicy", countFilesInDirectory(folder)); + object.put("noOfConnectedTrap", pdpCount); + papStatusData.add(0, object); + } + + private int countFilesInDirectory(File directory) { + int count = 0; + for (File file : directory.listFiles()) { + if (file.isFile() && file.getName().endsWith(".xml")) { + count++; + } + if (file.isDirectory()) { + count += countFilesInDirectory(file); + } + } + return count; + } + /** + * Add PDP Information to the PDP Table + * + */ + public void addPDPToTable(){ + pdpCount = 0; + pdpStatusData = new ArrayList(); + long naCount; + long denyCount = 0; + long permitCount = 0; + for (PDPGroup group : this.pdpConatiner.getGroups()){ + for (PDP pdp : group.getPdps()){ + naCount = -1; + if (pdp.getStatus().getStatus().toString() == "UP_TO_DATE" && ((EcompPDP) pdp).getJmxPort() != 0){ + String pdpIpAddress = parseIPSystem(pdp.getId()); + int port = ((EcompPDP) pdp).getJmxPort(); + if (port != 0) + logger.debug("Getting JMX Response Counts from " + pdpIpAddress + " at JMX port " + port); + naCount = getRequestCounts(pdpIpAddress, port, "pdpEvaluationNA"); + permitCount = getRequestCounts(pdpIpAddress, port, "PdpEvaluationPermit"); + denyCount = getRequestCounts(pdpIpAddress, port, "PdpEvaluationDeny"); + } + if (naCount == -1){ + JSONObject object = new JSONObject(); + object.put("id", pdp.getId()); + object.put("name", pdp.getName()); + object.put("groupname", group.getName()); + object.put("status", pdp.getStatus().getStatus().toString()); + object.put("description", pdp.getDescription()); + object.put("permitCount", "NA"); + object.put("denyCount", "NA"); + object.put("naCount", "NA"); + pdpStatusData.add(object); + }else{ + JSONObject object = new JSONObject(); + object.put("id", pdp.getId()); + object.put("name", pdp.getName()); + object.put("groupname", group.getName()); + object.put("status", pdp.getStatus().getStatus().toString()); + object.put("description", pdp.getDescription()); + object.put("permitCount", permitCount); + object.put("denyCount", denyCount); + object.put("naCount", naCount); + pdpStatusData.add(object); + } + pdpCount++; + } + } + } + + private static String parseIPSystem(String line) { + Pattern pattern = Pattern.compile("://(.+?):"); + Matcher ip = pattern.matcher(line); + if (ip.find()) + { + return ip.group(1); + } + return null; + } + + /* + * Contact JMX Connector Sever and return the value of the given jmxAttribute + */ + @SuppressWarnings("rawtypes") + private long getRequestCounts(String host, int port, String jmxAttribute) { + + logger.debug("Create an RMI connector client and connect it to the JMX connector server"); + HashMap map = new HashMap(); + map = null; + JMXConnector jmxConnection; + try { + jmxConnection = JMXConnectorFactory.newJMXConnector(createConnectionURL(host, port), map); + jmxConnection.connect(); + Object o = jmxConnection.getMBeanServerConnection().getAttribute(new ObjectName("PdpRest:type=PdpRestMonitor"), jmxAttribute); + jmxConnection.close(); + logger.debug("pdpEvaluationNA value retreived: " + o); + return (long) o; + } catch (MalformedURLException e) { + logger.error("MalformedURLException for JMX connection"); + } catch (IOException e) { + logger.error("Error in reteriving" + jmxAttribute + " from JMX connection"); + } catch (AttributeNotFoundException e) { + logger.error("AttributeNotFoundException " + jmxAttribute + " for JMX connection"); + } catch (InstanceNotFoundException e) { + logger.error("InstanceNotFoundException " + host + " for JMX connection"); + } catch (MalformedObjectNameException e) { + logger.error("MalformedObjectNameException for JMX connection"); + } catch (MBeanException e) { + logger.error("MBeanException for JMX connection"); + e.printStackTrace(); + } catch (ReflectionException e) { + logger.error("ReflectionException for JMX connection"); + } + + return -1; + } + + private static JMXServiceURL createConnectionURL(String host, int port) throws MalformedURLException{ + return new JMXServiceURL("rmi", "", 0, "/jndi/rmi://" + host + ":" + port + "/jmxrmi"); + } + + + /* + * Add the information to the Policy Table + */ + private void addPolicyToTable() { + policyActivityData = new ArrayList(); + int i = 1; + String policyID = null; + int policyFireCount = 0; + Map policyMap = new HashMap<>(); + Object policyList = null; + //get list of policy + + for (PDPGroup group : this.pdpConatiner.getGroups()){ + for (PDPPolicy policy : group.getPolicies()){ + try{ + policyMap.put(policy.getPolicyId().replace(" ", ""), policy.getId()); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_SCHEMA_INVALID+policy.getName() +e); + } + } + + for (PDP pdp : group.getPdps()){ + // Add rows to the Policy Table + policyList = null; + if (pdp.getStatus().getStatus().toString() == "UP_TO_DATE" && ((EcompPDP) pdp).getJmxPort() != 0){ + String pdpIpAddress = parseIPSystem(pdp.getId()); + policyList = getPolicy(pdpIpAddress, ((EcompPDP) pdp).getJmxPort(), "policyCount"); + } + if (policyList != null && policyList.toString().length() > 3){ + String[] splitPolicy = policyList.toString().split(","); + for (String policyKeyValue : splitPolicy){ + policyID = urnPolicyID(policyKeyValue); + policyFireCount = countPolicyID(policyKeyValue); + if (policyID != null ){ + if (policyMap.containsKey(policyID)){ + JSONObject object = new JSONObject(); + object.put("policyId", policyMap.get(policyID)); + object.put("fireCount", policyFireCount); + object.put("system", pdp.getId()); + policyActivityData.add(i, object); + i++; + } + } + } + }else { + if (policyList != null){ + JSONObject object = new JSONObject(); + object.put("policyId", "Unable to retrieve policy information"); + object.put("fireCount", "NA"); + object.put("system", pdp.getId()); + policyActivityData.add(i, object); + i++; + }else{ + JSONObject object = new JSONObject(); + object.put("policyId", "Unable to access PDP JMX Server"); + object.put("fireCount", "NA"); + object.put("system", pdp.getId()); + policyActivityData.add(i, object); + i++; + } + } + + } + } + } + + /* + * Contact JMX Connector Sever and return the list of {policy id , count} + */ + @SuppressWarnings("rawtypes") + private Object getPolicy(String host, int port, String jmxAttribute){ + logger.debug("Create an RMI connector client and connect it to the JMX connector server for Policy: " + host); + HashMap map = new HashMap(); + map = null; + JMXConnector jmxConnection; + try { + jmxConnection = JMXConnectorFactory.newJMXConnector(createConnectionURL(host, port), map); + jmxConnection.connect(); + Object o = jmxConnection.getMBeanServerConnection().getAttribute(new ObjectName("PdpRest:type=PdpRestMonitor"), "policyMap"); + jmxConnection.close(); + logger.debug("policyMap value retreived: " + o); + return o; + } catch (MalformedURLException e) { + logger.error("MalformedURLException for JMX connection"); + } catch (IOException e) { + logger.error("AttributeNotFoundException for policyMap" ); + } catch (AttributeNotFoundException e) { + logger.error("AttributeNotFoundException for JMX connection"); + } catch (InstanceNotFoundException e) { + logger.error("InstanceNotFoundException " + host + " for JMX connection"); + } catch (MalformedObjectNameException e) { + logger.error("MalformedObjectNameException for JMX connection"); + } catch (MBeanException e) { + logger.error("MBeanException for JMX connection"); + e.printStackTrace(); + } catch (ReflectionException e) { + logger.error("ReflectionException for JMX connection"); + } + + return null; + + } + + private static String urnPolicyID(String line){ + String[] splitLine = line.toString().split("="); + String removeSpaces = splitLine[0].replaceAll("\\s+", ""); + return removeSpaces.replace("{", ""); + } + + private static Integer countPolicyID(String line){ + String[] splitLine = line.toString().split("="); + String sCount = splitLine[1].replace("}", ""); + int intCount = Integer.parseInt(sCount); + return intCount; + } + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/DecisionPolicyController.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/DecisionPolicyController.java new file mode 100644 index 000000000..20cde7f43 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/DecisionPolicyController.java @@ -0,0 +1,507 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.controller; + + +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.xml.bind.JAXBElement; + +import org.json.JSONObject; +import org.openecomp.policy.adapter.PolicyAdapter; +import org.openecomp.policy.admin.PolicyNotificationMail; +import org.openecomp.policy.admin.RESTfulPAPEngine; +import org.openecomp.policy.dao.PolicyVersionDao; +import org.openecomp.policy.dao.RuleAlgorithmsDao; +import org.openecomp.policy.dao.WatchPolicyNotificationDao; +import org.openecomp.policy.elk.client.PolicyElasticSearchController; +import org.openecomp.policy.rest.jpa.PolicyVersion; +import org.openecomp.policy.rest.jpa.RuleAlgorithms; +import org.openecomp.portalsdk.core.controller.RestrictedBaseController; +import org.openecomp.portalsdk.core.web.support.UserUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +import com.att.research.xacml.api.XACML3; +import org.openecomp.policy.xacml.util.XACMLPolicyScanner; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.base.Joiner; + +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.ApplyType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.ConditionType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.EffectType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.RuleType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.VariableDefinitionType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.VariableReferenceType; + +@Controller +@RequestMapping("/") +public class DecisionPolicyController extends RestrictedBaseController { + private static final Logger logger = FlexLogger.getLogger(DecisionPolicyController.class); + + private static RuleAlgorithmsDao ruleAlgorithmsDao; + private static PolicyVersionDao policyVersionDao; + private static WatchPolicyNotificationDao policyNotificationDao; + + @Autowired + private DecisionPolicyController(RuleAlgorithmsDao ruleAlgorithmsDao, PolicyVersionDao policyVersionDao, WatchPolicyNotificationDao policyNotificationDao){ + DecisionPolicyController.policyVersionDao = policyVersionDao; + DecisionPolicyController.ruleAlgorithmsDao = ruleAlgorithmsDao; + DecisionPolicyController.policyNotificationDao = policyNotificationDao; + } + + public DecisionPolicyController(){} + + protected PolicyAdapter policyAdapter = null; + private static String ruleID = ""; + private ArrayList attributeList; + private ArrayList decisionList; + private ArrayList ruleAlgorithmList; + protected LinkedList ruleAlgoirthmTracker; + public static final String FUNCTION_NOT = "urn:oasis:names:tc:xacml:1.0:function:not"; + + public String newPolicyID() { + return Joiner.on(':').skipNulls().join((PolicyController.getDomain().startsWith("urn") ? null: "urn"), + PolicyController.getDomain().replaceAll("[/\\\\.]", ":"), "xacml", "policy", "id", UUID.randomUUID()); + } + + @RequestMapping(value={"/policyController/save_DecisionPolicy.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView saveDecisionPolicy(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + String userId = UserUtils.getUserIdFromCookie(request); + RESTfulPAPEngine engine = (RESTfulPAPEngine) PolicyController.getPapEngine(); + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + PolicyAdapter policyData = (PolicyAdapter)mapper.readValue(root.get("policyData").get("policy").toString(), PolicyAdapter.class); + if(root.get("policyData").get("model").get("type").toString().replace("\"", "").equals("file")){ + policyData.isEditPolicy = true; + } + if(root.get("policyData").get("model").get("path").size() != 0){ + String dirName = ""; + for(int i = 0; i < root.get("policyData").get("model").get("path").size(); i++){ + dirName = dirName.replace("\"", "") + root.get("policyData").get("model").get("path").get(i).toString().replace("\"", "") + File.separator; + } + policyData.setDomainDir(dirName.substring(0, dirName.lastIndexOf(File.separator))); + }else{ + policyData.setDomainDir(root.get("policyData").get("model").get("name").toString().replace("\"", "")); + } + int version = 0; + int highestVersion = 0; + int descriptionVersion = 0; + //get the highest version of policy from policy version table. + //getting the sub scope domain where the policy is created or updated + String dbCheckPolicyName = policyData.getDomainDir() + File.separator + "Decision_" + policyData.getPolicyName(); + List policyVersionList = policyVersionDao.getPolicyVersionEntityByName(dbCheckPolicyName); + if (policyVersionList.size() > 0) { + for(int i = 0; i < policyVersionList.size(); i++) { + PolicyVersion entityItem = policyVersionList.get(i); + if(entityItem.getPolicyName().equals(dbCheckPolicyName)){ + highestVersion = entityItem.getHigherVersion(); + } + } + } + if(highestVersion != 0){ + version = highestVersion; + descriptionVersion = highestVersion +1; + }else{ + version = 1; + descriptionVersion = 1; + } + + //set policy adapter values for Building JSON object containing policy data + String createdBy = ""; + String modifiedBy = userId; + if(descriptionVersion == 1){ + createdBy = userId; + }else{ + String policyName = PolicyController.getGitPath().toAbsolutePath().toString() + File.separator + policyData.getDomainDir() + File.separator + policyData.getOldPolicyFileName() + ".xml"; + File policyPath = new File(policyName); + try { + createdBy = XACMLPolicyScanner.getCreatedBy(policyPath.toPath()); + } catch (IOException e) { + createdBy = "guest"; + } + } + + policyData.setPolicyDescription(policyData.getPolicyDescription()+ "@CreatedBy:" +createdBy + "@CreatedBy:" + "@ModifiedBy:" +modifiedBy + "@ModifiedBy:"); + Map successMap = new HashMap(); + Map attributeMap = new HashMap(); + Map settingsMap = new HashMap(); + + List dynamicRuleAlgorithmLabels = new LinkedList(); + List dynamicRuleAlgorithmCombo = new LinkedList(); + List dynamicRuleAlgorithmField1 = new LinkedList(); + List dynamicRuleAlgorithmField2 = new LinkedList(); + List dynamicVariableList = new LinkedList(); + List dataTypeList = new LinkedList(); + + //set the Rule Combining Algorithm Id to be sent to PAP-REST via JSON + List ruleAlgorithmsList = ruleAlgorithmsDao.getRuleAlgorithms(); + for (int i = 0; i < ruleAlgorithmsList.size(); i++) { + RuleAlgorithms a = ruleAlgorithmsList.get(i); + if (a.getXacmlId().equals(XACML3.ID_RULE_PERMIT_OVERRIDES.stringValue())) { + policyData.setRuleCombiningAlgId(a.getXacmlId()); + break; + } + } + + if(policyData.getAttributes().size() > 0){ + for(Object attribute : policyData.getAttributes()){ + if(attribute instanceof LinkedHashMap){ + String key = ((LinkedHashMap) attribute).get("option").toString(); + String value = ((LinkedHashMap) attribute).get("number").toString(); + attributeMap.put(key, value); + } + } + } + + if(policyData.getSettings().size() > 0){ + for(Object settingsData : policyData.getSettings()){ + if(settingsData instanceof LinkedHashMap){ + String key = ((LinkedHashMap) settingsData).get("option").toString(); + String value = ((LinkedHashMap) settingsData).get("number").toString(); + settingsMap.put(key, value); + } + } + } + + if(policyData.getRuleAlgorithmschoices().size() > 0){ + for(Object attribute : policyData.getRuleAlgorithmschoices()){ + if(attribute instanceof LinkedHashMap){ + String label = ((LinkedHashMap) attribute).get("id").toString(); + String key = ((LinkedHashMap) attribute).get("dynamicRuleAlgorithmField1").toString(); + String rule = ((LinkedHashMap) attribute).get("dynamicRuleAlgorithmCombo").toString(); + String value = ((LinkedHashMap) attribute).get("dynamicRuleAlgorithmField2").toString(); + dynamicRuleAlgorithmLabels.add(label); + dynamicRuleAlgorithmField1.add(key); + dynamicRuleAlgorithmCombo.add(rule); + dynamicRuleAlgorithmField2.add(value); + } + } + } + + policyData.setDynamicRuleAlgorithmLabels(dynamicRuleAlgorithmLabels); + policyData.setDynamicRuleAlgorithmCombo(dynamicRuleAlgorithmCombo); + policyData.setDynamicRuleAlgorithmField1(dynamicRuleAlgorithmField1); + policyData.setDynamicRuleAlgorithmField2(dynamicRuleAlgorithmField2); + policyData.setDynamicVariableList(dynamicVariableList); + policyData.setDynamicSettingsMap(settingsMap); + policyData.setDynamicFieldConfigAttributes(attributeMap); + policyData.setDataTypeList(dataTypeList); + if (policyData.isEditPolicy()){ + //increment the version and set in policyAdapter + policyData.setVersion(String.valueOf(version)); + policyData.setHighestVersion(version); + policyData.setPolicyID(this.newPolicyID()); + policyData.setRuleID(ruleID); + successMap = engine.updatePolicyRequest(policyData); + } else { + //send it for policy creation + policyData.setVersion(String.valueOf(version)); + policyData.setHighestVersion(version); + successMap = engine.createPolicyRequest(policyData); + + } + + if (successMap.containsKey("success")) { + // Add it into our tree + Path finalPolicyPath = null; + finalPolicyPath = Paths.get(successMap.get("success")); + PolicyElasticSearchController controller = new PolicyElasticSearchController(); + controller.updateElk(finalPolicyPath.toString()); + File file = finalPolicyPath.toFile(); + if(file != null){ + String policyName = file.toString(); + String removePath = policyName.substring(policyName.indexOf("repository")+11); + String removeXml = removePath.replace(".xml", ""); + String removeExtension = removeXml.substring(0, removeXml.indexOf(".")); + List vesionList = policyVersionDao.getPolicyVersionEntityByName(removeExtension); + if (vesionList.size() > 0) { + for(int i = 0; i < vesionList.size(); i++) { + PolicyVersion entityItem = vesionList.get(i); + if(entityItem.getPolicyName().equals(removeExtension)){ + version = entityItem.getHigherVersion() +1; + entityItem.setActiveVersion(version); + entityItem.setHigherVersion(version); + entityItem.setModifiedBy(userId); + policyVersionDao.update(entityItem); + if(policyData.isEditPolicy){ + PolicyNotificationMail email = new PolicyNotificationMail(); + String mode = "EditPolicy"; + String policyNameForEmail = policyData.getDomainDir() + File.separator + policyData.getOldPolicyFileName() + ".xml"; + email.sendMail(entityItem, policyNameForEmail, mode, policyNotificationDao); + } + } + } + }else{ + PolicyVersion entityItem = new PolicyVersion(); + entityItem.setActiveVersion(version); + entityItem.setHigherVersion(version); + entityItem.setPolicyName(removeExtension); + entityItem.setCreatedBy(userId); + entityItem.setModifiedBy(userId); + policyVersionDao.Save(entityItem); + } + } + } + + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = mapper.writeValueAsString(successMap); + JSONObject j = new JSONObject("{policyData: " + responseString + "}"); + out.write(j.toString()); + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + public void PrePopulateDecisionPolicyData(PolicyAdapter policyAdapter) { + attributeList = new ArrayList(); + decisionList = new ArrayList(); + ruleAlgorithmList = new ArrayList(); + if (policyAdapter.getPolicyData() instanceof PolicyType) { + Object policyData = policyAdapter.getPolicyData(); + PolicyType policy = (PolicyType) policyData; + policyAdapter.setOldPolicyFileName(policyAdapter.getPolicyName()); + String policyNameValue = policyAdapter.getPolicyName().substring(policyAdapter.getPolicyName().indexOf("_") + 1, policyAdapter.getPolicyName().lastIndexOf(".")); + policyAdapter.setPolicyName(policyNameValue); + String description = ""; + try{ + description = policy.getDescription().substring(0, policy.getDescription().indexOf("@CreatedBy:")); + }catch(Exception e){ + description = policy.getDescription(); + } + policyAdapter.setPolicyDescription(description); + // Get the target data under policy for Action. + TargetType target = policy.getTarget(); + if (target != null) { + // under target we have AnyOFType + List anyOfList = target.getAnyOf(); + if (anyOfList != null) { + Iterator iterAnyOf = anyOfList.iterator(); + while (iterAnyOf.hasNext()) { + AnyOfType anyOf = iterAnyOf.next(); + // Under AntOfType we have AllOfType + List allOfList = anyOf.getAllOf(); + if (allOfList != null) { + Iterator iterAllOf = allOfList.iterator(); + while (iterAllOf.hasNext()) { + AllOfType allOf = iterAllOf.next(); + // Under AllOfType we have Mathch. + List matchList = allOf.getMatch(); + int index = 0; + if (matchList != null) { + Iterator iterMatch = matchList.iterator(); + while (iterMatch.hasNext()) { + MatchType match = iterMatch.next(); + // + // Under the match we have attributevalue and + // attributeDesignator. So,finally down to the actual attribute. + // + AttributeValueType attributeValue = match.getAttributeValue(); + String value = (String) attributeValue.getContent().get(0); + AttributeDesignatorType designator = match.getAttributeDesignator(); + String attributeId = designator.getAttributeId(); + // First match in the target is EcompName, so set that value. + if (index == 0) { + policyAdapter.setEcompName(value); + } + // Component attributes are saved under Target here we are fetching them back. + // One row is default so we are not adding dynamic componet at index 0. + if (index >= 1) { + Map attribute = new HashMap(); + attribute.put("option", attributeId); + attribute.put("number", value); + attributeList.add(attribute); + } + index++; + } + } + policyAdapter.setAttributes(attributeList); + } + } + } + } + + List ruleList = policy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition(); + int index = 0; + for (Object object : ruleList) { + if (object instanceof VariableDefinitionType) { + VariableDefinitionType variableDefinitionType = (VariableDefinitionType) object; + Map settings = new HashMap(); + settings.put("option", variableDefinitionType.getVariableId()); + JAXBElement attributeValueTypeElement = (JAXBElement) variableDefinitionType.getExpression(); + if (attributeValueTypeElement != null) { + AttributeValueType attributeValueType = attributeValueTypeElement.getValue(); + settings.put("number", attributeValueType.getContent().get(0).toString()); + } + decisionList.add(settings); + } else if (object instanceof RuleType) { + // get the condition data under the rule for rule Algorithms. + ruleID = ((RuleType) object).getRuleId(); + if (((RuleType) object).getEffect().equals(EffectType.PERMIT)) { + ConditionType condition = ((RuleType) object).getCondition(); + if (condition != null) { + ApplyType decisionApply = (ApplyType) condition.getExpression().getValue(); + ruleAlgoirthmTracker = new LinkedList(); + // Populating Rule Algorithms starting from compound. + prePopulateDecisionCompoundRuleAlgorithm(index, decisionApply); + policyAdapter.setRuleAlgorithmschoices(ruleAlgorithmList); + } + }else if(((RuleType) object).getEffect().equals(EffectType.DENY)) { + if(((RuleType) object).getAdviceExpressions()!=null){ + if(((RuleType) object).getAdviceExpressions().getAdviceExpression().get(0).getAdviceId().toString().equalsIgnoreCase("AAF")){ + policyAdapter.setRuleProvider("AAF"); + break; + } + }else{ + policyAdapter.setRuleProvider("Custom"); + } + } + } + } + } + policyAdapter.setSettings(decisionList); + } + + } + + private void prePopulateDecisionRuleAlgorithms(int index, ApplyType decisionApply, List> jaxbDecisionTypes) { + Map ruleMap = new HashMap(); + ruleMap.put("id", "A" + (index +1)); + Map dropDownMap = PolicyController.getDropDownMap(); + for (String key : dropDownMap.keySet()) { + String keyValue = dropDownMap.get(key); + if (keyValue.equals(decisionApply.getFunctionId())) { + ruleMap.put("dynamicRuleAlgorithmCombo", key); + } + } + // Populate the key and value fields + if (((jaxbDecisionTypes.get(0).getValue()) instanceof AttributeValueType)) { + ApplyType innerDecisionApply = (ApplyType) jaxbDecisionTypes.get(1).getValue(); + List> jaxbInnerDecisionTypes = innerDecisionApply.getExpression(); + if (jaxbInnerDecisionTypes.get(0).getValue() instanceof AttributeDesignatorType) { + AttributeDesignatorType attributeDesignator = (AttributeDesignatorType) jaxbInnerDecisionTypes.get(0).getValue(); + ruleMap.put("dynamicRuleAlgorithmField1", attributeDesignator.getAttributeId()); + + // Get from Attribute Value + AttributeValueType actionConditionAttributeValue = (AttributeValueType) jaxbDecisionTypes.get(0).getValue(); + String attributeValue = (String) actionConditionAttributeValue.getContent().get(0); + ruleMap.put("dynamicRuleAlgorithmField2", attributeValue); + } + } else if ((jaxbDecisionTypes.get(0).getValue()) instanceof VariableReferenceType) { + VariableReferenceType variableReference = (VariableReferenceType) jaxbDecisionTypes.get(0).getValue(); + ruleMap.put("dynamicRuleAlgorithmField1", "S_"+ variableReference.getVariableId()); + + + // Get from Attribute Value + AttributeValueType actionConditionAttributeValue = (AttributeValueType) jaxbDecisionTypes.get(1).getValue(); + String attributeValue = (String) actionConditionAttributeValue.getContent().get(0); + ruleMap.put("dynamicRuleAlgorithmField2", attributeValue); + } + ruleAlgorithmList.add(ruleMap); + } + + private int prePopulateDecisionCompoundRuleAlgorithm(int index, ApplyType decisionApply) { + boolean isCompoundRule = true; + List> jaxbDecisionTypes = decisionApply.getExpression(); + for (JAXBElement jaxbElement : jaxbDecisionTypes) { + // If There is Attribute Value under Decision Type that means we came to the final child + if (logger.isDebugEnabled()) { + logger.debug("Prepopulating rule algoirthm: " + index); + } + // Check to see if Attribute Value exists, if yes then it is not a compound rule + if(jaxbElement.getValue() instanceof AttributeValueType) { + prePopulateDecisionRuleAlgorithms(index, decisionApply, jaxbDecisionTypes); + ruleAlgoirthmTracker.addLast(index); + isCompoundRule = false; + index++; + } + } + if (isCompoundRule) { + // As it's compound rule, Get the Apply types + for (JAXBElement jaxbElement : jaxbDecisionTypes) { + ApplyType innerDecisionApply = (ApplyType) jaxbElement.getValue(); + index = prePopulateDecisionCompoundRuleAlgorithm(index, innerDecisionApply); + } + // Populate combo box + if (logger.isDebugEnabled()) { + logger.debug("Prepopulating Compound rule algorithm: " + index); + } + Map rule = new HashMap(); + for (String key : PolicyController.getDropDownMap().keySet()) { + String keyValue = PolicyController.getDropDownMap().get(key); + if (keyValue.equals(decisionApply.getFunctionId())) { + rule.put("dynamicRuleAlgorithmCombo", key); + } + } + + rule.put("id", "A" + (index +1)); + // Populate Key and values for Compound Rule + rule.put("dynamicRuleAlgorithmField1", "A" + (ruleAlgoirthmTracker.getLast() + 1 )); + ruleAlgoirthmTracker.removeLast(); + rule.put("dynamicRuleAlgorithmField2", "A" + (ruleAlgoirthmTracker.getLast() + 1)); + ruleAlgoirthmTracker.removeLast(); + ruleAlgoirthmTracker.addLast(index); + ruleAlgorithmList.add(rule); + index++; + } + return index; + } +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/PDPController.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/PDPController.java new file mode 100644 index 000000000..add650b1e --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/PDPController.java @@ -0,0 +1,302 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.controller; + + +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.json.JSONObject; +import org.openecomp.policy.dao.GroupEntityDao; +import org.openecomp.policy.dao.PDPEntityDao; +import org.openecomp.policy.model.PDPGroupContainer; +import org.openecomp.portalsdk.core.controller.RestrictedBaseController; +import org.openecomp.portalsdk.core.web.support.JsonMessage; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; +import org.openecomp.policy.xacml.api.pap.EcompPDPGroup; + +import com.att.research.xacml.api.pap.PAPException; +import com.att.research.xacml.api.pap.PDPGroup; +import org.openecomp.policy.xacml.std.pap.StdPDP; +import org.openecomp.policy.xacml.std.pap.StdPDPGroup; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +@Controller +@RequestMapping({"/"}) +public class PDPController extends RestrictedBaseController { + private static final Logger logger = FlexLogger.getLogger(PDPController.class); + + @Autowired + GroupEntityDao groupDAO; + + @Autowired + PDPEntityDao pdpDAO; + + protected List groups = Collections.synchronizedList(new ArrayList()); + private PDPGroupContainer container; + + public synchronized void refreshGroups() { + synchronized(this.groups) { + this.groups.clear(); + try { + this.groups.addAll(PolicyController.getPapEngine().getEcompPDPGroups()); + } catch (PAPException e) { + String message = "Unable to retrieve Groups from server: " + e; + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR+"Pap Engine is Null" + message); + } + + } + } + + @RequestMapping(value={"/get_PDPGroupContainerData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getPDPGroupContainerData(HttpServletRequest request, HttpServletResponse response){ + try{ + ObjectMapper mapper = new ObjectMapper(); + refreshGroups(); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(groups)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE+"Error Occured while retrieving the PDP Group Container data" + e); + } + } + + @RequestMapping(value={"/get_PDPGroupData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getPDPGroupEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + ObjectMapper mapper = new ObjectMapper(); + refreshGroups(); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(groups)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE+"Error Occured while retrieving the PDP Group data" + e); + } + } + + @RequestMapping(value={"/pdp_Group/save_pdp_group"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView savePDPGroup(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + this.container = new PDPGroupContainer(PolicyController.getPapEngine()); + StdPDPGroup pdpGroupData = mapper.readValue(root.get("pdpGroupData").toString().replace("groupName", "name"), StdPDPGroup.class); + try { + if(pdpGroupData.getId() == null){ + this.container.addNewGroup(pdpGroupData.getName(), pdpGroupData.getDescription()); + }else{ + this.container.updateGroup(pdpGroupData); + } + + } catch (Exception e) { + String message = "Unable to create Group. Reason:\n" + e.getMessage(); + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE+"Error Occured while creating the PDP Group" + message); + } + + + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + refreshGroups(); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(groups)); + JSONObject j = new JSONObject(msg); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE+"Error Occured while Saving the PDP Group" + e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/pdp_Group/remove_pdp_group"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removePDPGroup(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + this.container = new PDPGroupContainer(PolicyController.getPapEngine()); + StdPDPGroup pdpGroupData = mapper.readValue(root.get("pdpGroupData").toString(), StdPDPGroup.class); + if(pdpGroupData.getName().equals("Default")) { + throw new UnsupportedOperationException("You can't remove the Default Group."); + }else{ + this.container.removeGroup(pdpGroupData, null); + } + + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + + refreshGroups(); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(groups)); + JSONObject j = new JSONObject(msg); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE+"Error Occured while Removing the PDP Group" + e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/pdp_Group/save_pdpTogroup"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView savePDPToGroup(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try { + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + this.container = new PDPGroupContainer(PolicyController.getPapEngine()); + String update = root.get("update").toString(); + PdpData pdpGroupData = (PdpData)mapper.readValue(root.get("pdpInGroup").toString(), PdpData.class); + StdPDPGroup activeGroupData = mapper.readValue(root.get("activePDP").toString(), StdPDPGroup.class); + try { + + if(update.contains("false")){ + this.container.addNewPDP(pdpGroupData.getId(), activeGroupData, pdpGroupData.getName(), pdpGroupData.getDescription(), pdpGroupData.getJmxPort()); + }else{ + this.container.updateGroup(activeGroupData); + } + } catch (Exception e) { + String message = "Unable to create Group. Reason:\n" + e.getMessage(); + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE+"Error Occured while Creating Pdp in PDP Group" + message); + } + + + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + refreshGroups(); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(groups)); + JSONObject j = new JSONObject(msg); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE+"Error Occured while Creating Pdp in PDP Group" + e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + @RequestMapping(value={"/pdp_Group/remove_pdpFromGroup"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView removePDPFromGroup(HttpServletRequest request, HttpServletResponse response) throws Exception { + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + this.container = new PDPGroupContainer(PolicyController.getPapEngine()); + StdPDP deletePdp = mapper.readValue(root.get("data").toString(), StdPDP.class); + StdPDPGroup activeGroupData = mapper.readValue(root.get("activePDP").toString(), StdPDPGroup.class); + + this.container.removePDP(deletePdp, activeGroupData); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + refreshGroups(); + String responseString = mapper.writeValueAsString(groups); + JSONObject j = new JSONObject("{pdpEntityDatas: " + responseString + "}"); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE+"Error Occured while Removing Pdp from PDP Group" + e); + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } +} + +class PdpData{ + String id; + int jmxPort; + String name; + String description; + public String getId() { + return id; + } + public void setId(String id) { + this.id = id; + } + public int getJmxPort() { + return jmxPort; + } + public void setJmxPort(int jmxPort) { + this.jmxPort = jmxPort; + } + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + public String getDescription() { + return description; + } + public void setDescription(String description) { + this.description = description; + } + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/PolicyController.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/PolicyController.java new file mode 100644 index 000000000..c4b254c8e --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/PolicyController.java @@ -0,0 +1,418 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.controller; + + +import java.io.File; +import java.io.FileFilter; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import javax.annotation.PostConstruct; +import javax.mail.MessagingException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.io.filefilter.WildcardFileFilter; +import org.json.JSONObject; +import org.openecomp.policy.admin.PolicyNotificationMail; +import org.openecomp.policy.admin.RESTfulPAPEngine; +import org.openecomp.policy.dao.FunctionDefinitionDao; +import org.openecomp.policy.dao.PolicyEditorScopesDao; +import org.openecomp.policy.dao.PolicyVersionDao; +import org.openecomp.policy.dao.RolesDao; +import org.openecomp.policy.dao.WatchPolicyNotificationDao; +import org.openecomp.policy.model.PDPGroupContainer; +import org.openecomp.policy.model.Roles; +import org.openecomp.policy.rest.XACMLRestProperties; +import org.openecomp.policy.rest.XacmlAdminAuthorization; +import org.openecomp.policy.rest.dao.UserInfoDao; +import org.openecomp.policy.rest.jpa.Datatype; +import org.openecomp.policy.rest.jpa.FunctionDefinition; +import org.openecomp.policy.rest.jpa.PolicyEditorScopes; +import org.openecomp.policy.rest.jpa.PolicyVersion; +import org.openecomp.policy.rest.util.Webapps; +import org.openecomp.portalsdk.core.controller.RestrictedBaseController; +import org.openecomp.portalsdk.core.web.support.JsonMessage; +import org.openecomp.portalsdk.core.web.support.UserUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.servlet.ModelAndView; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; +import org.openecomp.policy.xacml.api.pap.PAPPolicyEngine; + +import com.att.research.xacml.api.pap.PAPEngine; +import com.att.research.xacml.util.XACMLProperties; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + + +@Controller +@RequestMapping("/") +public class PolicyController extends RestrictedBaseController { + private static final Logger LOGGER = FlexLogger.getLogger(PolicyController.class); + private static UserInfoDao userInfoDao; + private static PolicyVersionDao policyVersionDao; + private static RolesDao rolesDao; + private static PolicyEditorScopesDao policyEditorScopesDao; + private static WatchPolicyNotificationDao watchPolicyNotificationDao; + // Our authorization object + // + XacmlAdminAuthorization authorizer = new XacmlAdminAuthorization(); + // + // The PAP Engine + // + private static PAPPolicyEngine papEngine; + private Path repositoryPath = null; + private static Path workspacePath; + private static Path gitPath; + public static String logTableLimit; + public static String systemAlertTableLimit; + public static String CONFIG_HOME = PolicyController.getConfigHome(); + public static String ACTION_HOME = PolicyController.getActionHome(); + protected static Map dropDownMap = new HashMap(); + public static Map getDropDownMap() { + return dropDownMap; + } + + public static void setDropDownMap(Map dropDownMap) { + PolicyController.dropDownMap = dropDownMap; + } + + public static String getDomain() { + return XACMLProperties.getProperty(XACMLRestProperties.PROP_ADMIN_DOMAIN, "urn"); + } + + private static final Object mapAccess = new Object(); + private static Map> mapDatatype2Function = null; + private static Map mapID2Function = null; + + private static FunctionDefinitionDao functionDefinitionDao; + + //Smtp Java Mail Properties + public static String smtpHost = null; + public static String smtpPort = null; + public static String smtpUsername = null; + public static String smtpPassword = null; + public static String smtpApplicationName = null; + public static String smtpEmailExtension = null; + //log db Properties + public static String logdbDriver = null; + public static String logdbUrl = null; + public static String logdbUserName = null; + public static String logdbPassword = null; + public static String logdbDialect = null; + + + @Autowired + private PolicyController(UserInfoDao userinfoDao, PolicyVersionDao policyVersionDao, FunctionDefinitionDao functionDefinitionDao, + RolesDao rolesDao, PolicyEditorScopesDao policyEditorScopesDao, WatchPolicyNotificationDao watchPolicyNotificationDao){ + PolicyController.userInfoDao = userinfoDao; + PolicyController.policyVersionDao = policyVersionDao; + PolicyController.functionDefinitionDao = functionDefinitionDao; + PolicyController.rolesDao = rolesDao; + PolicyController.policyEditorScopesDao = policyEditorScopesDao; + PolicyController.watchPolicyNotificationDao = watchPolicyNotificationDao; + } + + public PolicyController() { + } + + @PostConstruct + public void init(){ + Properties prop = new Properties(); + InputStream input = null; + try { + input = new FileInputStream("xacml.admin.properties"); + // load a properties file + prop.load(input); + // get the property values + smtpHost = prop.getProperty("ecomp.smtp.host"); + smtpPort = prop.getProperty("ecomp.smtp.port"); + smtpUsername = prop.getProperty("ecomp.smtp.userName"); + smtpPassword = prop.getProperty("ecomp.smtp.password"); + smtpApplicationName = prop.getProperty("ecomp.application.name"); + smtpEmailExtension = prop.getProperty("ecomp.smtp.emailExtension"); + //Log Database Properties + logdbDriver = prop.getProperty("xacml.log.db.driver"); + logdbUrl = prop.getProperty("xacml.log.db.url"); + logdbUserName = prop.getProperty("xacml.log.db.user"); + logdbPassword = prop.getProperty("xacml.log.db.password"); + logdbDialect = prop.getProperty("ecomp.dialect"); + //Get the Property Values for Dashboard tab Limit + try{ + logTableLimit = prop.getProperty("xacml.ecomp.dashboard.logTableLimit"); + systemAlertTableLimit = prop.getProperty("xacml.ecomp.dashboard.systemAlertTableLimit"); + }catch(Exception e){ + LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE+"Dashboard tab Property fields are missing" +e); + logTableLimit = "5000"; + systemAlertTableLimit = "2000"; + } + repositoryPath = Paths.get(XACMLProperties.getProperty(XACMLRestProperties.PROP_ADMIN_REPOSITORY)); + PolicyController.workspacePath = Paths.get(XACMLProperties.getProperty(XACMLRestProperties.PROP_ADMIN_WORKSPACE), getDefaultWorkspace()); + setGitPath(Paths.get(workspacePath.toString(), repositoryPath.getFileName().toString())); + System.setProperty(XACMLProperties.XACML_PROPERTIES_NAME, "xacml.admin.properties"); + } catch (IOException ex) { + LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE+"Exception Occured while reading the Smtp properties from xacml.admin.properties file" +ex); + } finally { + if (input != null) { + try { + input.close(); + } catch (IOException e) { + LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE+"Exception Occured while Closing the xacml.admin.properties file" +e); + } + } + } + + //Initialize the FunctionDefinition table at Server Start up + Map> functionMap = getFunctionDatatypeMap(); + for (Datatype id : functionMap.keySet()) { + List functionDefinations = (List) functionMap.get(id); + for (FunctionDefinition functionDef : functionDefinations) { + dropDownMap.put(functionDef.getShortname(),functionDef.getXacmlid()); + } + } + + } + + public static Map> getFunctionDatatypeMap() { + synchronized(mapAccess) { + if (mapDatatype2Function == null) { + buildFunctionMaps(); + } + } + return mapDatatype2Function; + } + + public static Map getFunctionIDMap() { + synchronized(mapAccess) { + if (mapID2Function == null) { + buildFunctionMaps(); + } + } + return mapID2Function; + } + + private static void buildFunctionMaps() { + mapDatatype2Function = new HashMap>(); + mapID2Function = new HashMap(); + List functiondefinitions = functionDefinitionDao.getFunctionDefinition(); + for (int i = 0; i < functiondefinitions.size(); i ++) { + FunctionDefinition value = functiondefinitions.get(i); + mapID2Function.put(value.getXacmlid(), value); + if (mapDatatype2Function.containsKey(value.getDatatypeBean()) == false) { + mapDatatype2Function.put(value.getDatatypeBean(), new ArrayList()); + } + mapDatatype2Function.get(value.getDatatypeBean()).add(value); + } + } + + public static Map getUserRoles(String userId) { + Map scopes = new HashMap(); + List roles = rolesDao.getUserRoles(userId); + if (roles != null && roles.size() > 0) { + for (Roles role : roles) { + scopes.put(role.getScope(), role); + } + } + return scopes; + } + + public static List getRolesOfUser(String userId) { + List rolesList = new ArrayList(); + List roles = rolesDao.getUserRoles(userId); + for (Roles role: roles) { + rolesList.add(role.getRole()); + } + return rolesList; + } + + public static List getRoles(String userId) { + return rolesDao.getUserRoles(userId); + } + + //Get List of User Roles + @RequestMapping(value={"/get_UserRolesData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getUserRolesEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + String userId = UserUtils.getUserIdFromCookie(request); + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("userRolesDatas", mapper.writeValueAsString(getRolesOfUser(userId))); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + //Policy tabs Model and View + @RequestMapping(value= {"/policy", "/policy/*" }, method = RequestMethod.GET) + public ModelAndView view(HttpServletRequest request){ + String myRequestURL = request.getRequestURL().toString(); + try { + // + // Set the URL for the RESTful PAP Engine + // + setPapEngine((PAPPolicyEngine) new RESTfulPAPEngine(myRequestURL)); + new PDPGroupContainer((PAPPolicyEngine) new RESTfulPAPEngine(myRequestURL)); + } catch (Exception e) { + LOGGER.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR+"Exception Occured while loading PAP"+e); + } + Map model = new HashMap(); + return new ModelAndView("policy_Editor","model", model); + } + + public static String getDefaultWorkspace() { + return "admin"; + } + + public static PAPPolicyEngine getPapEngine() { + return papEngine; + } + + public void setPapEngine(PAPPolicyEngine papEngine) { + PolicyController.papEngine = papEngine; + } + + //Config and Action Directory's + public static String getConfigHome() { + return Webapps.getConfigHome(); + } + + public static String getActionHome() { + return Webapps.getActionHome(); + } + + public static Path getGitPath() { + return gitPath; + } + + public static void setGitPath(Path gitPath) { + PolicyController.gitPath = gitPath; + } + + public static String getUserName(String createdBy) { + String loginId = createdBy; + return userInfoDao.getUserName(loginId); + } + + public static boolean getActivePolicy(String query) { + if(policyVersionDao.getActiveVersionPolicy(query).size() > 0){ + return true; + }else{ + return false; + } + + } + + //Get the Active Version of Policy List from Policy Version table + public static List getListOfActivePolicies(String query){ + return policyVersionDao.getActiveVersionPolicy(query); + } + + public static void updatePolicyVersion(String query) { + policyVersionDao.updateQuery(query); + } + + public static void SaveToPolicyVersion(PolicyVersion policyversion) { + policyVersionDao.Save(policyversion); + } + + public static PolicyVersion getPolicyEntityFromPolicyVersion(String query){ + PolicyVersion policyVersionEntity = policyVersionDao.getPolicyVersionEntityByName(query).get(0); + return policyVersionEntity; + } + + public static void SavePolicyScope(PolicyEditorScopes policyScope){ + policyEditorScopesDao.Save(policyScope); + } + + public static List getListOfPolicyEditorScopes(String query){ + return policyEditorScopesDao.getListOfPolicyScopes(query); + } + + public static void updatePolicyScopeEditorWithQuery(String policyScopeQuery) { + policyEditorScopesDao.updateQuery(policyScopeQuery); + + } + + public static void updatePolicyScopeEditor(PolicyEditorScopes policyScopeQuery) { + policyEditorScopesDao.update(policyScopeQuery); + + } + + public void WatchPolicyFunction(PolicyVersion entity, String policyName, String mode){ + PolicyNotificationMail email = new PolicyNotificationMail(); + try { + email.sendMail(entity, policyName, mode, watchPolicyNotificationDao); + } catch (MessagingException e) { + LOGGER.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Excepton Occured while Renaming/Deleting a Policy or Scope" + e); + } + } + + //Switch Version + public JSONObject SwitchVersionPolicyContent(File policyFile) { + Path parent = Paths.get(policyFile.toString().substring(0, policyFile.toString().lastIndexOf(File.separator))); + String policyName = policyFile.toString().substring(policyFile.toString().indexOf("repository") +11); + String removeExtension = policyName.replace(".xml", ""); + String activeVersion = removeExtension.substring(removeExtension.lastIndexOf(".")+1); + String dbPolicyName = removeExtension.substring(0, removeExtension.lastIndexOf(".")); + String filterPolicyName = dbPolicyName.substring(dbPolicyName.lastIndexOf(File.separator)+1); + FileFilter fileFilter = new WildcardFileFilter(filterPolicyName + "." + "*" + ".xml"); + File[] files = ((File) parent.toFile()).listFiles(fileFilter); + List av = new ArrayList(); + for(File file : files){ + String fileName = file.toString().substring(file.toString().indexOf("repository") +11); + String removeXMLExtension = fileName.replace(".xml", ""); + String availableVersion = removeXMLExtension.substring(removeXMLExtension.lastIndexOf(".")+1); + av.add(availableVersion); + } + PolicyVersion entity = (PolicyVersion) policyVersionDao.getPolicyVersionEntityByName(dbPolicyName).get(0); + String highestVersion = Integer.toString(entity.getHigherVersion()); + JSONObject el = new JSONObject(); + el.put("activeVersion", activeVersion); + el.put("availableVersions", av); + el.put("highestVersion", highestVersion); + return el; + } + + public static Path getUserWorkspace() { + return PolicyController.workspacePath; + } + +} + diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/PolicyExportAndImportController.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/PolicyExportAndImportController.java new file mode 100644 index 000000000..76fadb59d --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/PolicyExportAndImportController.java @@ -0,0 +1,563 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.controller; + + +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.servlet.ServletContext; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.compress.archivers.tar.TarArchiveEntry; +import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; +import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; +import org.apache.commons.io.FilenameUtils; +import org.apache.commons.io.IOUtils; +import org.json.JSONObject; +import org.openecomp.policy.adapter.PolicyExportAdapter; +import org.openecomp.policy.dao.PolicyVersionDao; +import org.openecomp.policy.elk.client.ElkConnector; +import org.openecomp.policy.model.Roles; +import org.openecomp.policy.rest.jpa.PolicyVersion; +import org.openecomp.policy.utils.XACMLPolicyWriterWithPapNotify; +import org.openecomp.portalsdk.core.controller.RestrictedBaseController; +import org.openecomp.portalsdk.core.web.support.UserUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + + +@Controller +@RequestMapping("/") +public class PolicyExportAndImportController extends RestrictedBaseController { + private static Logger logger = FlexLogger.getLogger(PolicyExportAndImportController.class); + private ArrayList selectedPolicy; + public static String CONFIG_HOME = PolicyController.getConfigHome(); + public static String ACTION_HOME = PolicyController.getActionHome(); + + private Set scopes = null; + private List roles = null; + private Boolean superadmin = false; + private Boolean showMessage = false; + private static final int BUFFER_SIZE = 4096; + private Path directory = PolicyController.getGitPath(); + + //Scopes Which Super Editor can't import + private Set sEditorScopesCantCreate = new HashSet(); + //List of scopes in Tar file + private Set listOfTarNewScopes = new HashSet(); + //List of xml policies + private ArrayList xacmlFiles = new ArrayList(); + //Scopes of the User based on the Roles + private List userScopes = null; + //Directory names from tar file + private Set directoryNames = new HashSet(); + //compare the scopes of the user and tar file get unique + private Set finalScopesToImport = new HashSet(); + //final scopes User can import + private Set finalScopes = new HashSet(); + //User don't have permissions to import to scopes + private Set roleIsNotSufficient = new HashSet(); + //User don't have access to import new scopes + private Set userDontHavePermission = new HashSet(); + + private Map scopeAndRoles = null; + + private static PolicyVersionDao policyVersionDao; + + @Autowired + ServletContext servletContext; + + @Autowired + private PolicyExportAndImportController(PolicyVersionDao policyVersionDao){ + PolicyExportAndImportController.policyVersionDao = policyVersionDao; + } + + public PolicyExportAndImportController(){} + + @RequestMapping(value={"/policy_download/exportPolicy.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView ExportPolicy(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try{ + selectedPolicy = new ArrayList(); + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + PolicyExportAdapter adapter = mapper.readValue(root.get("exportData").toString(), PolicyExportAdapter.class); + for (Object policyId : adapter.getPolicyDatas()) { + LinkedHashMap selected = (LinkedHashMap)policyId; + Path file = Paths.get(selected.get("filePath").toString()); + selectedPolicy.add(file.toFile()); + } + // Grab our working repository + // + final Path repoPath = PolicyController.getGitPath().toAbsolutePath(); + if(CONFIG_HOME == null || ACTION_HOME == null ){ + CONFIG_HOME = PolicyController.getConfigHome(); + ACTION_HOME = PolicyController.getActionHome(); + } + Path configPath = Paths.get(CONFIG_HOME); + Path actionPath = Paths.get(ACTION_HOME); + String tempDir = System.getProperty("catalina.base") + File.separator + "webapps" + File.separator + "temp"; + File temPath = new File(tempDir); + if(!temPath.exists()){ + temPath.mkdir(); + } + final Path tarFile = Paths.get(tempDir, "Repository.tar"); + try (OutputStream os = Files.newOutputStream(tarFile)) { + try (TarArchiveOutputStream tarOut = new TarArchiveOutputStream(os)) { + tarOut.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU); + Files.walkFileTree(configPath, new SimpleFileVisitor() { + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + for (File policyId : selectedPolicy) { + // Get the current selection + String policyDir = policyId.toString(); + policyDir = policyDir.substring(policyDir.indexOf("repository")+11); + String path = policyDir.replace('\\', '.'); + if(path.contains("/")){ + path = policyDir.replace('/', '.'); + logger.info("print the path:" +path); + } + path = FilenameUtils.removeExtension(path); + if (path.endsWith(".xml")) { + path = path.substring(0, path.length() - 4); + } + File configFile = new File(path); + String fileName = FilenameUtils.removeExtension(file.getFileName().toString()); + File configHome = new File(fileName); + if(configFile.equals(configHome)) { + Path relative = configPath.relativize(file); + TarArchiveEntry entry = new TarArchiveEntry(relative.toFile()); + entry.setSize(Files.size(file)); + tarOut.putArchiveEntry(entry); + try { + IOUtils.copy(Files.newInputStream(file), tarOut); + } catch (IOException e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + } + tarOut.closeArchiveEntry(); + return super.visitFile(file, attrs); + } + } + return super.visitFile(file, attrs); + } + }); + + Files.walkFileTree(actionPath, new SimpleFileVisitor() { + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + for (File policyId : selectedPolicy) { + // Get the current selection + String policyDir = policyId.toString(); + policyDir = policyDir.substring(policyDir.indexOf("repository")+11); + String path = policyDir.replace('\\', '.'); + if(path.contains("/")){ + path = policyDir.replace('/', '.'); + logger.info("print the path:" +path); + } + path = FilenameUtils.removeExtension(path); + if (path.endsWith(".xml")) { + path = path.substring(0, path.length() - 4); + } + File actionFile = new File(path); + String fileName = FilenameUtils.removeExtension(file.getFileName().toString()); + File actionHome = new File(fileName); + if(actionFile.equals(actionHome)) { + Path relative = actionPath.relativize(file); + TarArchiveEntry entry = new TarArchiveEntry(relative.toFile()); + entry.setSize(Files.size(file)); + tarOut.putArchiveEntry(entry); + try { + IOUtils.copy(Files.newInputStream(file), tarOut); + } catch (IOException e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + } + tarOut.closeArchiveEntry(); + return super.visitFile(file, attrs); + } + } + return super.visitFile(file, attrs); + } + }); + + Files.walkFileTree(repoPath, new SimpleFileVisitor() { + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + if (file.getFileName().toString().endsWith(".xml") == false) { + return super.visitFile(file, attrs); + } + for (File policyId : selectedPolicy) { + // Get the current selection + if(policyId.getAbsoluteFile().getName().equals(file.getFileName().toString())) { + Path relative = repoPath.relativize(file); + TarArchiveEntry entry = new TarArchiveEntry(relative.toFile()); + entry.setSize(Files.size(file)); + tarOut.putArchiveEntry(entry); + try { + IOUtils.copy(Files.newInputStream(file), tarOut); + } catch (IOException e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + } + tarOut.closeArchiveEntry(); + return super.visitFile(file, attrs); + } + } + return super.visitFile(file, attrs); + } + }); + + tarOut.closeArchiveEntry(); + tarOut.finish(); + logger.debug("closing the tar file"); + } + } catch (IOException e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "getting IOexception"); + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + } + logger.info("trying to send tar file "+tarFile.toAbsolutePath().toString()); + + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + String successMap = tarFile.toString().substring(tarFile.toString().lastIndexOf("webapps")+8); + PrintWriter out = response.getWriter(); + String responseString = mapper.writeValueAsString(successMap); + JSONObject j = new JSONObject("{data: " + responseString + "}"); + out.write(j.toString()); + + + return null; + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR+"Exception Occured while Exporting Policies"+e); + } + return null; + } + + //Policy Import + public JSONObject ImportRepositoryFile(String file, HttpServletRequest request){ + TarArchiveEntry entry = null; + TarArchiveInputStream extractFile = null; + try { + extractFile = new TarArchiveInputStream (new FileInputStream(file)); + } catch (FileNotFoundException e1) { + e1.printStackTrace(); + } + String userId = null; + try { + userId = UserUtils.getUserIdFromCookie(request); + } catch (Exception e) { + logger.error("Exception Occured while reading userid from cookie" +e); + } + scopeAndRoles = PolicyController.getUserRoles(userId); + //Check if the Role and Scope Size are Null get the values from db. + List userRoles = PolicyController.getRoles(userId); + roles = new ArrayList(); + scopes = new HashSet(); + for(Roles userRole: userRoles){ + roles.add(userRole.getRole()); + scopes.add(userRole.getScope()); + } + //Create a loop to read every single entry in TAR file + try { + if (roles.contains("super-admin") || roles.contains("super-editor") || roles.contains("super-guest") ) { + while ((entry = extractFile.getNextTarEntry()) != null) { + this.superadmin = true; + try{ + copyFileToLocation(extractFile, entry, xacmlFiles, null, superadmin); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR+"Exception while Importing Polcies"+e); + } + } + }else{ + this.showMessage = true; + //get the directory names from tar file and add to the list + while ((entry = extractFile.getNextTarEntry()) != null) { + if(entry.getName().endsWith(".xls")) { + this.superadmin = true; + try{ + copyFileToLocation(extractFile, entry, xacmlFiles, finalScopes, superadmin); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR+"Exception while Importing Polcies"+e); + } + } + if(entry.getName().endsWith(".xml")){ + String filename = null; + if(entry.getName().contains("\\")){ + filename = entry.getName().replace("\\", File.separator); + }else{ + filename = entry.getName().replace("/", File.separator); + } + directoryNames.add(filename.substring(0, filename.lastIndexOf(File.separator))); + } + + //get the matching scopes on comparing user scopes and tar file scopes + for(int i=0;i< userScopes.size(); i++){ + for(int j=0; j xacmlFiles, Set finalScopes, Boolean superadminValue ) throws IOException{ + String individualFiles = ""; + int offset = 0; + FileOutputStream outputFile=null; + // Get the name of the file + if(superadminValue){ + individualFiles = entry.getName(); + //Add the list of scopes + if(entry.getName().endsWith(".xml")){ + String filename = null; + if(entry.getName().contains("\\")){ + filename = entry.getName().replace("\\", File.separator); + }else{ + filename = entry.getName().replace("/", File.separator); + } + if(roles.contains("super-editor")){ + listOfTarNewScopes.add(filename.substring(0, filename.lastIndexOf(File.separator))); + } + } + }else{ + for(int i =0; i< finalScopes.size(); i++){ + if(entry.getName().startsWith(finalScopes.toArray()[i].toString())){ + individualFiles = entry.getName(); + } + } + } + + //Filter the new Scopes which Super-Editor can't create + if(roles.contains("super-editor")){ + for(int j= 0; j< listOfTarNewScopes.size(); j++){ + boolean scopeExistsFlag = false; // This Flag is used to know if the Scope Exists. + for(int i=0; i < scopes.size(); i++ ){ + if(scopes.contains(listOfTarNewScopes.toArray()[j])){ + scopeExistsFlag = true; + } + } + if(!scopeExistsFlag){ + sEditorScopesCantCreate.add(listOfTarNewScopes.toArray()[j].toString()); + showMessage = true; + } + } + } + + individualFiles = individualFiles.replace("/", File.separator); + individualFiles = individualFiles.replace("\\", File.separator); + + //Create the path with the entry name + String filePath = directory + File.separator + individualFiles; + String configPath = CONFIG_HOME + File.separator + individualFiles; + String actionPath = ACTION_HOME + File.separator + individualFiles; + logger.info("File Name in TAR File is: " + individualFiles); + logger.info("Xml directory file path: " + filePath); + logger.info("Config Home directory file path: " + configPath); + logger.info("Action Home directory file path: " + actionPath); + + + // Get Size of the file and create a byte array for the size + byte[] content = new byte[(int) entry.getSize()]; + + offset=0; + logger.info("File Name in TAR File is: " + individualFiles); + logger.info("Size of the File is: " + entry.getSize()); + // Read file from the archive into byte array + extractFile.read(content, offset, content.length - offset); + if (!entry.isDirectory()) { + if(!individualFiles.contains(".Config_") || !individualFiles.contains(".Action_")){ + // if the entry is a file, extracts it + String filePath1 = filePath.substring(0, filePath.lastIndexOf(File.separator)); + File newFile = new File(filePath1); + if(!(newFile.exists()) && !(roles.contains("super-editor") || roles.contains("editor"))) { + File dir = new File(filePath1); + dir.mkdir(); + extractFile(extractFile, filePath); + } + } + } else { + // if the entry is a directory, make the directory + if(!(roles.contains("super-editor") || roles.contains("editor"))){ + File dir = new File(filePath); + dir.mkdir(); + } + } + // Define OutputStream for writing the file + if(individualFiles.contains(".Config_")){ + outputFile=new FileOutputStream(new File(configPath)); + }else if(individualFiles.contains(".Action_")){ + outputFile=new FileOutputStream(new File(actionPath)); + }else{ + if(filePath != null){ + outputFile=new FileOutputStream(new File(filePath)); + xacmlFiles.add(filePath); + } + } + + // Use IOUtiles to write content of byte array to physical file + IOUtils.write(content,outputFile); + + // Close Output Stream + try { + outputFile.close(); + } catch (IOException e) { + logger.info("IOException:" +e); + e.printStackTrace(); + } + } + + private void extractFile(TarArchiveInputStream extractFile, String filePath) throws IOException { + BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filePath)); + byte[] bytesIn = new byte[BUFFER_SIZE]; + int read = 0; + while ((read = extractFile.read(bytesIn)) != -1) { + bos.write(bytesIn, 0, read); + } + bos.close(); + + } +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/PolicyNotificationController.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/PolicyNotificationController.java new file mode 100644 index 000000000..203f3dcc6 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/PolicyNotificationController.java @@ -0,0 +1,122 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.controller; + + +/* + * + * */ +import java.io.File; +import java.io.PrintWriter; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.json.JSONObject; +import org.openecomp.policy.dao.WatchPolicyNotificationDao; +import org.openecomp.policy.rest.jpa.WatchPolicyNotificationTable; +import org.openecomp.portalsdk.core.controller.RestrictedBaseController; +import org.openecomp.portalsdk.core.web.support.UserUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ArrayNode; + +@Controller +@RequestMapping({"/"}) +public class PolicyNotificationController extends RestrictedBaseController { + + @Autowired + WatchPolicyNotificationDao policyNotificationDao; + + @RequestMapping(value={"/watchPolicy"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView watchPolicy(HttpServletRequest request, HttpServletResponse response) throws Exception{ + String path = ""; + String responseValue = ""; + try { + String userId = UserUtils.getUserIdFromCookie(request); + System.out.println(userId); + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + String name = root.get("watchData").get("name").toString(); + JsonNode pathList = root.get("watchData").get("path"); + String finalName = ""; + if(pathList.isArray()){ + ArrayNode arrayNode = (ArrayNode) pathList; + for (int i = 0; i < arrayNode.size(); i++) { + JsonNode individualElement = arrayNode.get(i); + if(i == 0){ + path = path + individualElement.toString().replace("\"", "").trim(); + }else{ + path = path + File.separator + individualElement.toString().replace("\"", "").trim(); + } + } + } + + if(pathList.size() > 0){ + finalName = path + File.separator + name.replace("\"", "").trim(); + }else{ + finalName = name.replace("\"", "").trim(); + } + if(finalName.contains("\\")){ + finalName = finalName.replace("\\", "\\\\"); + } + String query = "from WatchPolicyNotificationTable where POLICYNAME = '"+finalName+"' and LOGINIDS = '"+userId+"'"; + List watchList = policyNotificationDao.watchListQuery(query); + if(watchList.isEmpty()){ + if(finalName.contains("\\\\")){ + finalName = finalName.replace("\\\\", File.separator); + } + WatchPolicyNotificationTable watch = new WatchPolicyNotificationTable(); + watch.setPolicyName(finalName); + watch.setLoginIds(userId); + policyNotificationDao.save(watch); + responseValue = "You have Subscribed Successfully"; + }else{ + policyNotificationDao.delete(watchList.get(0)); + responseValue = "You have UnSubscribed Successfully"; + } + + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = mapper.writeValueAsString(responseValue); + JSONObject j = new JSONObject("{watchData: " + responseString + "}"); + out.write(j.toString()); + return null; + }catch(Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/PolicyRolesController.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/PolicyRolesController.java new file mode 100644 index 000000000..dea341ea9 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/PolicyRolesController.java @@ -0,0 +1,137 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.controller; + + +import java.io.File; +import java.io.PrintWriter; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.json.JSONObject; +import org.openecomp.policy.dao.PolicyRolesDao; +import org.openecomp.policy.rest.jpa.PolicyRoles; +import org.openecomp.portalsdk.core.controller.RestrictedBaseController; +import org.openecomp.portalsdk.core.web.support.JsonMessage; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + +import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; +import com.fasterxml.jackson.annotation.PropertyAccessor; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +@Controller +@RequestMapping("/") +public class PolicyRolesController extends RestrictedBaseController{ + + @Autowired + PolicyRolesDao policyRolesDao; + List scopelist; + + @RequestMapping(value={"/get_RolesData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getPolicyRolesEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + model.put("rolesDatas", mapper.writeValueAsString(policyRolesDao.getUserRoles())); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + @RequestMapping(value={"/save_NonSuperRolesData"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView SaveRolesEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + PolicyRoles adapter = mapper.readValue(root.get("editRoleData").toString(), PolicyRoles.class); + policyRolesDao.update(adapter); + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + String responseString = mapper.writeValueAsString(policyRolesDao.getUserRoles()); + JSONObject j = new JSONObject("{rolesDatas: " + responseString + "}"); + + out.write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + return null; + } + + @RequestMapping(value={"/get_PolicyRolesScopeData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getPolicyScopesEntityData(HttpServletRequest request, HttpServletResponse response){ + try{ + scopelist = new ArrayList(); + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY); + Path gitPath = PolicyController.getGitPath().toAbsolutePath(); + model.put("scopeDatas", mapper.writeValueAsString(readFileRepository(gitPath))); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + } + catch (Exception e){ + e.printStackTrace(); + } + } + + public List readFileRepository(Path path){ + File root = new File(path.toString()); + for ( File file : root.listFiles()){ + if(file.isDirectory()){ + String fileName = getDomain(file); + if (!(fileName.contains(".git") || fileName.equals(".DS_Store"))) { + scopelist.add(fileName); + } + readFileRepository(file.toPath()); + } + } + return scopelist; + } + + public String getDomain(File file) { + String filePath = file.getAbsolutePath(); + int startIndex = filePath.indexOf("repository") + 11; + return filePath.substring(startIndex, filePath.length()); + } + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/PolicyValidationController.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/PolicyValidationController.java new file mode 100644 index 000000000..5ffdd062a --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/controller/PolicyValidationController.java @@ -0,0 +1,300 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.controller; + + +import java.io.PrintWriter; +import java.util.Arrays; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.json.JSONObject; +import org.openecomp.policy.adapter.ClosedLoopFaultBody; +import org.openecomp.policy.adapter.ClosedLoopPMBody; +import org.openecomp.policy.adapter.PolicyAdapter; +import org.openecomp.policy.admin.RESTfulPAPEngine; +import org.openecomp.policy.rest.dao.SafePolicyWarningDao; +import org.openecomp.policy.rest.jpa.SafePolicyWarning; +import org.openecomp.portalsdk.core.controller.RestrictedBaseController; +import org.openecomp.portalsdk.core.web.support.JsonMessage; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.base.CharMatcher; + +@Controller +@RequestMapping("/") +public class PolicyValidationController extends RestrictedBaseController { + + public static final String CONFIG_POLICY = "Config"; + public static final String ACTION_POLICY = "Action"; + public static final String DECISION_POLICY = "Decision"; + public static final String CLOSEDLOOP_POLICY = "ClosedLoop_Fault"; + public static final String CLOSEDLOOP_PM = "ClosedLoop_PM"; + public static final String ENFORCER_CONFIG_POLICY= "Enforcer Config"; + public static final String MICROSERVICES="DCAE Micro Service"; + private Pattern pattern; + private Matcher matcher; + + private static final String EMAIL_PATTERN = + "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@" + + "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$"; + + @Autowired + SafePolicyWarningDao safePolicyWarningDao; + + @RequestMapping(value={"/policyController/validate_policy.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView validatePolicy(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try{ + boolean valid = true; + String responseString = ""; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + PolicyAdapter policyData = (PolicyAdapter)mapper.readValue(root.get("policyData").toString(), PolicyAdapter.class); + if(policyData.getPolicyName() != null){ + String policyNameValidate = emptyValidator(policyData.getPolicyName()); + if(!policyNameValidate.contains("success")){ + responseString = responseString + "PolicyName:" + policyNameValidate; + valid = false; + }; + }else{ + responseString = responseString + "PolicyName: PolicyName Should not be empty" + "
    "; + } + if(policyData.getPolicyDescription() != null){ + String descriptionValidate = descriptionValidator(policyData.getPolicyDescription()); + if(!descriptionValidate.contains("success")){ + responseString = responseString + "Description:" + descriptionValidate; + valid = false; + } + } + + if(policyData.getPolicyType().equals(CONFIG_POLICY)){ + if (policyData.getConfigPolicyType().equals("Base") || policyData.getConfigPolicyType().equals(CLOSEDLOOP_POLICY) + || policyData.getConfigPolicyType().equals(CLOSEDLOOP_PM) || policyData.getConfigPolicyType().equals(ENFORCER_CONFIG_POLICY) || policyData.getConfigPolicyType().equals(MICROSERVICES)) { + if(policyData.getEcompName() != null){ + String ecompNameValidate = emptyValidator(policyData.getEcompName()); + if(!ecompNameValidate.contains("success")){ + responseString = responseString + "EcompName:" + ecompNameValidate; + valid = false; + } + }else{ + responseString = responseString + "Ecomp Name: Ecomp Name Should not be empty" + "
    "; + } + } + + if(policyData.getRiskType() != null){ + String riskTypeValidate = emptyValidator(policyData.getRiskType()); + if(!riskTypeValidate.contains("success")){ + responseString = responseString + "RiskType:" + riskTypeValidate; + valid = false; + }else { + SafePolicyWarning safePolicyWarningData = safePolicyWarningDao.getSafePolicyWarningDataById(policyData.getRiskType()); + if (safePolicyWarningData!=null){ + safePolicyWarningData.getMessage(); + responseString = responseString + "Messaage:" + safePolicyWarningData.getMessage(); + } + } + }else { + responseString = responseString + "Risk Type: Risk Type Should not be Empty" + "
    "; + valid = false; + } + + if(policyData.getRiskLevel() != null){ + String validateRiskLevel = emptyValidator(policyData.getRiskLevel()); + if(!validateRiskLevel.contains("success")){ + responseString = responseString + "RiskLevel:" + validateRiskLevel; + valid = false; + } + }else { + responseString = responseString + "Risk Level: Risk Level Should not be Empty" + "
    "; + valid = false; + } + + if(policyData.getGuard() != null){ + String validateGuard = emptyValidator(policyData.getGuard()); + if(!validateGuard.contains("success")){ + responseString = responseString + "Guard:" + validateGuard; + valid = false; + } + }else { + responseString = responseString + "Guard: Guard Value Should not be Empty" + "
    "; + valid = false; + } + + if(policyData.getConfigPolicyType().equals("Base")){ + if(policyData.getConfigName() != null){ + String configNameValidate = emptyValidator(policyData.getConfigName()); + if(!configNameValidate.contains("success")){ + responseString = responseString + "ConfigName:" + configNameValidate; + valid = false; + } + }else{ + responseString = responseString + "Config Name: Config Name Should not be Empty" + "
    "; + } + if(policyData.getConfigType() != null){ + String configTypeValidate = emptyValidator(policyData.getConfigType()); + if(!configTypeValidate.contains("success")){ + responseString = responseString + "ConfigType:" + configTypeValidate; + valid = false; + } + }else{ + responseString = responseString + "Config Type: Config Type Should not be Empty" + "
    "; + } + if(policyData.getConfigBodyData() != null){ + String policyType = policyData.getPolicyType(); + RESTfulPAPEngine engine = (RESTfulPAPEngine) PolicyController.getPapEngine(); + if(!engine.validatePolicyRequest(policyData, policyType)){ + responseString = responseString + "ConfigBody: Validation Failed"; + valid = false; + } + }else{ + responseString = responseString + "Config Body: Config Body Should not be Empty" + "
    "; + } + } + + + if(policyData.getJsonBodyData() != null){ + if(policyData.getConfigPolicyType().equals("ClosedLoop_PM")){ + ClosedLoopPMBody pmBody = (ClosedLoopPMBody)mapper.readValue(root.get("policyData").get("jsonBodyData").toString(), ClosedLoopPMBody.class); + if(pmBody.getEmailAddress() != null){ + String validateEmail = validateEmailAddress(pmBody.getEmailAddress().toString()); + if(!validateEmail.contains("success")){ + responseString = responseString + "Email:" + validateEmail; + valid = false; + } + }else{ + valid = true; + } + }else if(policyData.getConfigPolicyType().equals("ClosedLoop_Fault")){ + ClosedLoopFaultBody faultBody = (ClosedLoopFaultBody)mapper.readValue(root.get("policyData").get("jsonBodyData").toString(), ClosedLoopFaultBody.class); + if(faultBody.getEmailAddress() != null){ + String validateEmail = validateEmailAddress(faultBody.getEmailAddress().toString()); + if(!validateEmail.contains("success")){ + responseString = responseString + "Email:" + validateEmail; + valid = false; + } + }else{ + valid = true; + } + } + } + } + if (policyData.getPolicyType().equals(DECISION_POLICY)){ + String ecompNameValidate = emptyValidator(policyData.getEcompName()); + if(!ecompNameValidate.contains("success")){ + responseString = responseString + "EcompName:" + ecompNameValidate; + valid = false; + } + } + + if(policyData.getPolicyType().equals(ACTION_POLICY)){ + String actionPerformer = emptyValidator(policyData.getActionPerformer()); + String actionAttribute = emptyValidator(policyData.getActionAttributeValue()); + if(!actionPerformer.contains("success")){ + responseString = responseString + "ActionPerformer:" + actionPerformer; + valid = false; + }; + if(!actionAttribute.contains("success")){ + responseString = responseString + "ActionAttribute:" + actionAttribute; + valid = false; + }; + } + + if(policyData.getPolicyType().equals(CONFIG_POLICY)){ + if(valid){ + responseString = "success" + "@#"+ responseString; + } + }else{ + if(valid){ + responseString = "success"; + } + } + + PrintWriter out = response.getWriter(); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(responseString)); + JSONObject j = new JSONObject(msg); + out.write(j.toString()); + + return null; + } + catch (Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + protected String emptyValidator(String field){ + String error = "success"; + if (field.equals("") || field.contains(" ") || !field.matches("^[a-zA-Z0-9_]*$")) { + error = "The Value in Required Field will allow only '{0-9}, {a-z}, {A-Z}, _' following set of Combinations"; + return error; + } else { + if(CharMatcher.ASCII.matchesAllOf((CharSequence) field)){ + error = "success"; + }else{ + error = "The Value Contains Non ASCII Characters"; + return error; + } + } + return error; + } + + protected String descriptionValidator(String field) { + String error = "success"; + if (field.contains("@CreatedBy:") || field.contains("@ModifiedBy:")) { + error = "The value in the description shouldn't contain @CreatedBy: or @ModifiedBy:"; + return error; + } else { + error = "success"; + } + return error; + } + + public String validateEmailAddress(String emailAddressValue) { + String error = "success"; + List emailList = Arrays.asList(emailAddressValue.toString().split(",")); + for(int i =0 ; i < emailList.size() ; i++){ + pattern = Pattern.compile(EMAIL_PATTERN); + matcher = pattern.matcher(emailList.get(i).trim()); + if(!matcher.matches()){ + error = "Please check the Following Email Address is not Valid .... " +emailList.get(i).toString(); + return error; + }else{ + error = "success"; + } + } + return error; + } + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/dao/FunctionDefinitionDao.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/dao/FunctionDefinitionDao.java new file mode 100644 index 000000000..c216ca589 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/dao/FunctionDefinitionDao.java @@ -0,0 +1,32 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.dao; + + +import java.util.List; + +import org.openecomp.policy.rest.jpa.FunctionDefinition; + +public interface FunctionDefinitionDao { + + List getFunctionDefinition(); + List getFunctionDefinitionByName(); +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/dao/GlobalRoleSettingsDao.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/dao/GlobalRoleSettingsDao.java new file mode 100644 index 000000000..35aab5211 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/dao/GlobalRoleSettingsDao.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.dao; + + +import java.util.List; + +import org.openecomp.policy.rest.jpa.GlobalRoleSettings; + +public interface GlobalRoleSettingsDao { + + void update(GlobalRoleSettings globalRoleSettings); + List getGlobalRoleSettings(); + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/dao/GroupEntityDao.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/dao/GroupEntityDao.java new file mode 100644 index 000000000..8983382f7 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/dao/GroupEntityDao.java @@ -0,0 +1,39 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.dao; + + +import java.util.List; + +import org.openecomp.policy.rest.jpa.GroupEntity; + + +public abstract interface GroupEntityDao { + + public abstract List getGroupEntityData(); + + public abstract GroupEntity getPDPGroupEntity(String string); + + public abstract void savePDPGroupEntity(GroupEntity pdpGroupDataFunction); + + public abstract void deletePDPGroupEntity(GroupEntity pdpGroupDataFunction); + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/dao/PDPEntityDao.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/dao/PDPEntityDao.java new file mode 100644 index 000000000..60f7441b3 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/dao/PDPEntityDao.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.dao; + + +import java.util.List; + +import org.openecomp.policy.rest.jpa.PdpEntity; + + +public abstract interface PDPEntityDao { + + public abstract List getPDPEntityData(); + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/dao/PolicyEditorScopesDao.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/dao/PolicyEditorScopesDao.java new file mode 100644 index 000000000..f40de6d50 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/dao/PolicyEditorScopesDao.java @@ -0,0 +1,37 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.dao; + + +import java.util.List; + +import org.openecomp.policy.rest.jpa.PolicyEditorScopes; + + +public interface PolicyEditorScopesDao { + List getPolicyEditorScopesData(); + List getPolicyEditorScopesDataByName(); + void Save(PolicyEditorScopes policyEditorScopes); + void delete(PolicyEditorScopes policyEditorScopes); + void update(PolicyEditorScopes policyEditorScopes); + List getListOfPolicyScopes(String query); + void updateQuery(String policyScopeQuery); +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/dao/PolicyRolesDao.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/dao/PolicyRolesDao.java new file mode 100644 index 000000000..49cd17c10 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/dao/PolicyRolesDao.java @@ -0,0 +1,37 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.dao; + + +import java.util.List; + +import org.openecomp.policy.rest.jpa.PolicyRoles; + +public interface PolicyRolesDao { + + List getRoles(); + List getUserRoles(); + void save(PolicyRoles role); + + void update(PolicyRoles role); + + void delete(PolicyRoles role); +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/dao/PolicyVersionDao.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/dao/PolicyVersionDao.java new file mode 100644 index 000000000..0c2692e6c --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/dao/PolicyVersionDao.java @@ -0,0 +1,38 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.dao; + + +import java.util.List; + +import org.openecomp.policy.rest.jpa.PolicyVersion; + + +public interface PolicyVersionDao { + List getPolicyVersionData(); + List getPolicyVersionEntityByName(String policyVersion); + List getPolicyVersionDataByName(); + List getActiveVersionPolicy(String query); + void Save(PolicyVersion policyVersion); + void delete(PolicyVersion policyVersion); + void update(PolicyVersion policyVersion); + void updateQuery(String policyVersion); +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/dao/RemoteCatalogValuesDao.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/dao/RemoteCatalogValuesDao.java new file mode 100644 index 000000000..c2ff0f7b8 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/dao/RemoteCatalogValuesDao.java @@ -0,0 +1,34 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.dao; + + +import java.util.List; + +import org.openecomp.policy.rest.jpa.RemoteCatalogValues; + +public interface RemoteCatalogValuesDao { + List getRemoteCatalogValuesData(); + List getRemoteCatalogValuesDataByName(); + void Save(RemoteCatalogValues attribute); + void delete(RemoteCatalogValues attribute); + void update(RemoteCatalogValues attribute); +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/dao/RolesDao.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/dao/RolesDao.java new file mode 100644 index 000000000..4612daea0 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/dao/RolesDao.java @@ -0,0 +1,38 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.dao; + + +import java.util.List; + +import org.openecomp.policy.model.Roles; + + + +public interface RolesDao { + + List getUserRoles(String userId); + + void save(Roles role); + + void delete(Roles role); + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/dao/RuleAlgorithmsDao.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/dao/RuleAlgorithmsDao.java new file mode 100644 index 000000000..6a9c6b303 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/dao/RuleAlgorithmsDao.java @@ -0,0 +1,31 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.dao; + + +import java.util.List; + +import org.openecomp.policy.rest.jpa.RuleAlgorithms; + +public interface RuleAlgorithmsDao { + + List getRuleAlgorithms(); +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/dao/SystemLogDbDao.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/dao/SystemLogDbDao.java new file mode 100644 index 000000000..bdfdd8f0a --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/dao/SystemLogDbDao.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.dao; + + +import java.util.List; + +import org.openecomp.policy.rest.jpa.SystemLogDB; + + + +public abstract interface SystemLogDbDao { + public abstract List getLoggingData(); + public abstract List getSystemAlertData(); +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/dao/WatchPolicyNotificationDao.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/dao/WatchPolicyNotificationDao.java new file mode 100644 index 000000000..a43294e94 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/dao/WatchPolicyNotificationDao.java @@ -0,0 +1,35 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.dao; + + +import java.util.List; + +import org.openecomp.policy.rest.jpa.WatchPolicyNotificationTable; + +public interface WatchPolicyNotificationDao { + List getListData(); + List getListDataByPolicyName(String policyName); + void save(WatchPolicyNotificationTable data); + void update(WatchPolicyNotificationTable data); + void delete(WatchPolicyNotificationTable data); + List watchListQuery(String query); +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/ActionPolicyDictDaoImpl.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/ActionPolicyDictDaoImpl.java new file mode 100644 index 000000000..b29aafec2 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/ActionPolicyDictDaoImpl.java @@ -0,0 +1,178 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.daoImp; + + +import java.util.ArrayList; +import java.util.List; + +//import org.apache.commons.logging.Log; +//import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.hibernate.criterion.Restrictions; +import org.openecomp.policy.rest.dao.ActionPolicyDictDao; +import org.openecomp.policy.rest.jpa.ActionPolicyDict; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +@Service("ActionPolicyDictDao") +public class ActionPolicyDictDaoImpl implements ActionPolicyDictDao { + private static final Logger logger = FlexLogger.getLogger(ActionPolicyDictDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + @SuppressWarnings("unchecked") + @Override + public List getActionDictData() { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + + List actionDictData = null; + try { + Criteria cr = session.createCriteria(ActionPolicyDict.class); + actionDictData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying ActionDictionary Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return actionDictData; + } + + @Override + public void Save(ActionPolicyDict action) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.persist(action); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving ActionDictionary Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void delete(ActionPolicyDict action) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.delete(action); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting ActionDictionary Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(ActionPolicyDict action) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.update(action); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating ActionDictionary Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getActionDictDataByName() { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(ActionPolicyDict.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getAttributeName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying ActionDictionary Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + + @SuppressWarnings("unchecked") + @Override + public ActionPolicyDict getActionEntityDatabyId(String action) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + ActionPolicyDict data = null; + try { + Criteria cr = session.createCriteria(ActionPolicyDict.class); + List attributeData = cr.add(Restrictions.eq("attributeName", action)).list(); + for(Object entity : attributeData){ + data = (ActionPolicyDict) entity; + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying ActionDictionary Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/AddressGroupDaoImpl.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/AddressGroupDaoImpl.java new file mode 100644 index 000000000..132220f5f --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/AddressGroupDaoImpl.java @@ -0,0 +1,152 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.daoImp; + + +import java.util.ArrayList; +import java.util.List; + +//import org.apache.commons.logging.Log; +//import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.rest.dao.AddressGroupDao; +import org.openecomp.policy.rest.jpa.AddressGroup; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +@Service("AddressGroupDao") +public class AddressGroupDaoImpl implements AddressGroupDao{ + private static final Logger logger = FlexLogger.getLogger(AddressGroupDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + @SuppressWarnings("unchecked") + @Override + public List getAddressGroupData() { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + List attributeData = null; + try { + Criteria cr = session.createCriteria(AddressGroup.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying AddressGroup Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + + } + + @Override + public void Save(AddressGroup attribute) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.persist(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving AddressGroup Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(AddressGroup attribute) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.delete(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting AddressGroup Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(AddressGroup attribute) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.update(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating AddressGroup Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getAddressGroupDataByName() { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(AddressGroup.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getGroupName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying AddressGroup Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/BRMSParamTemplateDaoImpl.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/BRMSParamTemplateDaoImpl.java new file mode 100644 index 000000000..0b634ff73 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/BRMSParamTemplateDaoImpl.java @@ -0,0 +1,152 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.daoImp; + + +import java.util.ArrayList; +import java.util.List; + +//import org.apache.commons.logging.Log; +//import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.rest.dao.BRMSParamTemplateDao; +import org.openecomp.policy.rest.jpa.BRMSParamTemplate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +@Service("BRMSParamTemplateDao") +public class BRMSParamTemplateDaoImpl implements BRMSParamTemplateDao{ + private static final Logger logger = FlexLogger.getLogger(BRMSParamTemplateDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + @SuppressWarnings("unchecked") + @Override + public List getBRMSParamTemplateData() { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + List attributeData =null; + try { + Criteria cr = session.createCriteria(BRMSParamTemplate.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying BRMSParamTemplate Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + + } + + @Override + public void Save(BRMSParamTemplate attribute) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.persist(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving BRMSParamTemplate Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(BRMSParamTemplate attribute) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.delete(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting BRMSParamTemplate Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(BRMSParamTemplate attribute) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.update(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating BRMSParamTemplate Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getBRMSParamDataByName() { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(BRMSParamTemplate.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getRuleName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying BRMSParamTemplate Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/DescriptiveScopeDaoImpl.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/DescriptiveScopeDaoImpl.java new file mode 100644 index 000000000..600b42ce7 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/DescriptiveScopeDaoImpl.java @@ -0,0 +1,177 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.daoImp; + + +import java.util.ArrayList; +import java.util.List; + +//import org.apache.commons.logging.Log; +//import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.hibernate.criterion.Restrictions; +import org.openecomp.policy.rest.dao.DescriptiveScopeDao; +import org.openecomp.policy.rest.jpa.DescriptiveScope; +import org.openecomp.policy.rest.jpa.PolicyVersion; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +@Service("DescriptiveScopeDao") +public class DescriptiveScopeDaoImpl implements DescriptiveScopeDao{ + private static final Logger logger = FlexLogger.getLogger(DescriptiveScopeDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + @SuppressWarnings("unchecked") + @Override + public List getDescriptiveScope() { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + List descriptiveScopeData = null; + try { + Criteria cr = session.createCriteria(DescriptiveScope.class); + descriptiveScopeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying DescriptiveScope Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return descriptiveScopeData; + } + + @Override + public void Save(DescriptiveScope descriptiveScope) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.persist(descriptiveScope); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving DescriptiveScope Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(DescriptiveScope descriptiveScope) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.delete(descriptiveScope); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting DescriptiveScope Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void update(DescriptiveScope descriptiveScope) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.update(descriptiveScope); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating DescriptiveScope Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getDescriptiveScopeDataByName() { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(DescriptiveScope.class); + List descriptiveScopeData = cr.list(); + for(int i = 0; i < descriptiveScopeData.size(); i++){ + data.add(descriptiveScopeData.get(i).getScopeName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying DescriptiveScope Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + + @Override + public DescriptiveScope getDescriptiveScopeById(String name) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + DescriptiveScope data = null; + try { + Criteria cr = session.createCriteria(PolicyVersion.class); + cr.add(Restrictions.eq("scopename",name)); + data = (DescriptiveScope) cr.list().get(0); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying DescriptiveScope Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/FirewallDictionaryListDaoImpl.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/FirewallDictionaryListDaoImpl.java new file mode 100644 index 000000000..e002aa962 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/FirewallDictionaryListDaoImpl.java @@ -0,0 +1,196 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.daoImp; + + +import java.util.ArrayList; +import java.util.List; + +import org.hibernate.Criteria; +import org.hibernate.Query; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.hibernate.criterion.Restrictions; +import org.openecomp.policy.rest.dao.FirewallDictionaryListDao; +import org.openecomp.policy.rest.jpa.FirewallDictionaryList; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +@Service("FirewallDictionaryListDao") +public class FirewallDictionaryListDaoImpl implements FirewallDictionaryListDao { + private static final Logger logger = FlexLogger.getLogger(FirewallDictionaryListDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + @SuppressWarnings("unchecked") + @Override + public List getFWDictionaryListData() { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + List attributeData = null; + try { + Criteria cr = session.createCriteria(FirewallDictionaryList.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying FirewallDictionaryList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + + } + + @SuppressWarnings("unchecked") + @Override + public List getFWDictionaryListDataByName() { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(FirewallDictionaryList.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getParentItemName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying FirewallDictionaryList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + + @Override + public void Save(FirewallDictionaryList firewallDictionaryList) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.persist(firewallDictionaryList); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving FirewallDictionaryList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(FirewallDictionaryList firewallDictionaryList) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.delete(firewallDictionaryList); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting FirewallDictionaryList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void update(FirewallDictionaryList firewallDictionaryList) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.update(firewallDictionaryList); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating FirewallDictionaryList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void updateQuery(String query) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + Query hbquery = session.createQuery(query); + hbquery.executeUpdate(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating FirewallDictionaryList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public FirewallDictionaryList getFWDictionaryDataById(String value) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + FirewallDictionaryList data = null; + try { + Criteria cr = session.createCriteria(FirewallDictionaryList.class); + cr = cr.add(Restrictions.eq("parentItemName",value)); + data = (FirewallDictionaryList) cr.list().get(0); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying FirewallDictionaryList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/FunctionDefinitionDaoImpl.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/FunctionDefinitionDaoImpl.java new file mode 100644 index 000000000..ebb833585 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/FunctionDefinitionDaoImpl.java @@ -0,0 +1,94 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.daoImp; + + +import java.util.ArrayList; +import java.util.List; + +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.dao.FunctionDefinitionDao; +import org.openecomp.policy.rest.jpa.FunctionDefinition; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +@Service("FunctionDefinitionDao") +public class FunctionDefinitionDaoImpl implements FunctionDefinitionDao{ + private static final Logger logger = FlexLogger.getLogger(FunctionDefinitionDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + @SuppressWarnings("unchecked") + @Override + public List getFunctionDefinitionByName() { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(FunctionDefinition.class); + List functionDefinitionData = cr.list(); + for(int i = 0; i < functionDefinitionData.size(); i++){ + data.add(functionDefinitionData.get(i).getShortname()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying FunctionDefinition Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + + @SuppressWarnings("unchecked") + @Override + public List getFunctionDefinition() { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + List functionDefinitionData = null; + try { + Criteria cr = session.createCriteria(FunctionDefinition.class); + functionDefinitionData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying FunctionDefinition Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return functionDefinitionData; + } + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/GlobalRoleSettingsDaoImpl.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/GlobalRoleSettingsDaoImpl.java new file mode 100644 index 000000000..718b8e98f --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/GlobalRoleSettingsDaoImpl.java @@ -0,0 +1,91 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.daoImp; + + +import java.util.List; + +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.dao.GlobalRoleSettingsDao; +import org.openecomp.policy.rest.jpa.GlobalRoleSettings; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + + +@Service("GlobalRoleSettingsDao") +public class GlobalRoleSettingsDaoImpl implements GlobalRoleSettingsDao{ + private static final Logger logger = FlexLogger.getLogger(GlobalRoleSettingsDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + + + @SuppressWarnings("unchecked") + @Override + public List getGlobalRoleSettings() { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + List lockdownData = null; + try { + Criteria cr = session.createCriteria(GlobalRoleSettings.class); + lockdownData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying GlobalRoleSettings Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return lockdownData; + } + + + + @Override + public void update(GlobalRoleSettings globalRoleSettings) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.update(globalRoleSettings); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating GlobalRoleSettings Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/GroupEntityDaoImpl.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/GroupEntityDaoImpl.java new file mode 100644 index 000000000..1a468253c --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/GroupEntityDaoImpl.java @@ -0,0 +1,124 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.daoImp; + + +import java.util.List; + +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.dao.GroupEntityDao; +import org.openecomp.policy.rest.jpa.GroupEntity; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +@Service("PDPGroupDataDao") +public class GroupEntityDaoImpl implements GroupEntityDao{ + private static final Logger logger = FlexLogger.getLogger(GroupEntityDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + @SuppressWarnings("unchecked") + @Override + public List getGroupEntityData() { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + Criteria cr = session.createCriteria(GroupEntity.class); + List groupData = null; + try { + groupData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying GroupEntity Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return groupData; + } + + @Override + public GroupEntity getPDPGroupEntity(String getgroupName) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + GroupEntity entity = null; + try { + entity = (GroupEntity) session.get(GroupEntity.class, getgroupName); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying GroupEntity Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return entity; + } + + @Override + public void savePDPGroupEntity(GroupEntity pdpGroupDataFunction) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.persist(pdpGroupDataFunction); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving GroupEntity Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void deletePDPGroupEntity(GroupEntity pdpGroupDataFunction) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.delete(pdpGroupDataFunction); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting GroupEntity Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/GroupPolicyScopeListDaoImpl.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/GroupPolicyScopeListDaoImpl.java new file mode 100644 index 000000000..a51eef102 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/GroupPolicyScopeListDaoImpl.java @@ -0,0 +1,177 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.daoImp; + + +import java.util.ArrayList; +import java.util.List; + +//import org.apache.commons.logging.Log; +//import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.hibernate.criterion.Restrictions; +import org.openecomp.policy.rest.dao.GroupPolicyScopeListDao; +import org.openecomp.policy.rest.jpa.GroupPolicyScopeList; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +@Service("GroupPolicyScopeListDao") +public class GroupPolicyScopeListDaoImpl implements GroupPolicyScopeListDao { + private static final Logger logger = FlexLogger.getLogger(GroupPolicyScopeListDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + @SuppressWarnings("unchecked") + @Override + public List getGroupPolicyScopeListData() { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + List attributeData = null; + try { + Criteria cr = session.createCriteria(GroupPolicyScopeList.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying GroupPolicyScopeList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + } + + @SuppressWarnings("unchecked") + @Override + public List getGroupPolicyScopeListDataByName() { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(GroupPolicyScopeList.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getGroupName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying GroupPolicyScopeList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + + @Override + public void Save(GroupPolicyScopeList attribute) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.persist(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving GroupPolicyScopeList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(GroupPolicyScopeList attribute) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.delete(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting Attribute Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void update(GroupPolicyScopeList attribute) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.update(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating Attribute Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List CheckDuplicateEntry(String value) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + List data = null; + try { + Criteria cr = session.createCriteria(GroupPolicyScopeList.class); + cr.add(Restrictions.eq("name",value)); + data = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying GroupPolicyScopeList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/MicroServiceModelsDaoImpl.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/MicroServiceModelsDaoImpl.java new file mode 100644 index 000000000..6c198aa11 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/MicroServiceModelsDaoImpl.java @@ -0,0 +1,156 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.daoImp; + + +import java.util.ArrayList; +import java.util.List; + +//import org.apache.commons.logging.Log; +//import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.rest.dao.MicroServiceModelsDao; +import org.openecomp.policy.rest.jpa.MicroServiceModels; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +@Service("MicroServiceModelsDao") +public class MicroServiceModelsDaoImpl implements MicroServiceModelsDao{ + private static final Logger logger = FlexLogger.getLogger(MicroServiceModelsDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + @SuppressWarnings("unchecked") + @Override + public List getMicroServiceModelsData() { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + List attributeData = null; + try { + Criteria cr = session.createCriteria(MicroServiceModels.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying MicroServiceModels Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + + } + + @Override + public void Save(MicroServiceModels attribute) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.persist(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving MicroServiceModels Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(MicroServiceModels attribute) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.delete(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting MicroServiceModels Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(MicroServiceModels attribute) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.update(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating MicroServiceModels Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getMSModelsDataByName() { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(MicroServiceModels.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + if(attributeData.get(i).getVersion() == null || attributeData.get(i).getVersion().equals("")){ + data.add(attributeData.get(i).getModelName()); + }else{ + data.add(attributeData.get(i).getModelName() + "-v" + attributeData.get(i).getVersion()); + } + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying MicroServiceModels Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/PDPEntityDaoImpl.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/PDPEntityDaoImpl.java new file mode 100644 index 000000000..2a2250e87 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/PDPEntityDaoImpl.java @@ -0,0 +1,68 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.daoImp; + + +import java.util.List; + +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.dao.PDPEntityDao; +import org.openecomp.policy.rest.jpa.PdpEntity; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +@Service("PDPEntityDataDao") +public class PDPEntityDaoImpl implements PDPEntityDao { + private static final Logger logger = FlexLogger.getLogger(PDPEntityDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + @SuppressWarnings("unchecked") + @Override + public List getPDPEntityData() { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + List pdpData = null; + try { + Criteria cr = session.createCriteria(PdpEntity.class); + pdpData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying PdpEntity Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return pdpData; + } + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/PolicyEditorScopesDaoImpl.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/PolicyEditorScopesDaoImpl.java new file mode 100644 index 000000000..4aad7efbd --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/PolicyEditorScopesDaoImpl.java @@ -0,0 +1,193 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.daoImp; + + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Query; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.dao.PolicyEditorScopesDao; +import org.openecomp.policy.rest.jpa.PolicyEditorScopes; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("PolicyEditorScopesDao") +public class PolicyEditorScopesDaoImpl implements PolicyEditorScopesDao { + private static final Log logger = LogFactory.getLog(PolicyEditorScopesDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + @SuppressWarnings("unchecked") + @Override + public List getPolicyEditorScopesData() { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + List scopeNameData = null; + try { + Criteria cr = session.createCriteria(PolicyEditorScopes.class); + scopeNameData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying PolicyEditorScopes Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return scopeNameData; + } + + @SuppressWarnings("unchecked") + @Override + public List getPolicyEditorScopesDataByName() { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(PolicyEditorScopes.class); + List scopeNameData = cr.list(); + for(int i = 0; i < scopeNameData.size(); i++){ + data.add(scopeNameData.get(i).getScopeName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying PolicyEditorScopes Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + + @Override + public void Save(PolicyEditorScopes policyEditorScopes) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.persist(policyEditorScopes); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving PolicyEditorScopes Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(PolicyEditorScopes policyEditorScopes) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.delete(policyEditorScopes); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting PolicyEditorScopes Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void update(PolicyEditorScopes policyEditorScopes) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.update(policyEditorScopes); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating PolicyEditorScopes Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getListOfPolicyScopes(String query) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + List data = null; + try { + Query hbquery = session.createQuery(query); + data = hbquery.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying PolicyEditorScopes Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + + @Override + public void updateQuery(String policyScopeQuery) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + Query hbquery = session.createQuery(policyScopeQuery); + hbquery.executeUpdate(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating PolicyEditorScopes Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/PolicyRolesDaoImpl.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/PolicyRolesDaoImpl.java new file mode 100644 index 000000000..f10a94229 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/PolicyRolesDaoImpl.java @@ -0,0 +1,159 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.daoImp; + +import java.util.List; + +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.hibernate.criterion.Conjunction; +import org.hibernate.criterion.Disjunction; +import org.hibernate.criterion.Restrictions; +import org.openecomp.policy.dao.PolicyRolesDao; +import org.openecomp.policy.rest.jpa.PolicyRoles; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +@Service("PolicyRolesDao") +public class PolicyRolesDaoImpl implements PolicyRolesDao{ + private static final Logger logger = FlexLogger.getLogger(PolicyRolesDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + @SuppressWarnings("unchecked") + @Override + public List getUserRoles() { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + List rolesData = null; + try { + Criteria cr = session.createCriteria(PolicyRoles.class); + Disjunction disjunction = Restrictions.disjunction(); + Conjunction conjunction1 = Restrictions.conjunction(); + conjunction1.add(Restrictions.eq("role", "admin")); + Conjunction conjunction2 = Restrictions.conjunction(); + conjunction2.add(Restrictions.eq("role", "editor")); + Conjunction conjunction3 = Restrictions.conjunction(); + conjunction3.add(Restrictions.eq("role", "guest")); + disjunction.add(conjunction1); + disjunction.add(conjunction2); + disjunction.add(conjunction3); + rolesData = cr.add(disjunction).list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying PolicyRoles Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return rolesData; + } + + @Override + public void save(PolicyRoles role) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.persist(role); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving PolicyRoles Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(PolicyRoles role) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.delete(role); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting PolicyRoles Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void update(PolicyRoles role) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.update(role); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating PolicyRoles Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getRoles() { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + List rolesData = null; + try { + Criteria cr = session.createCriteria(PolicyRoles.class); + rolesData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying PolicyRoles Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return rolesData; + } + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/PolicyVersionDaoImpl.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/PolicyVersionDaoImpl.java new file mode 100644 index 000000000..02188ec47 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/PolicyVersionDaoImpl.java @@ -0,0 +1,216 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.daoImp; + + +import java.util.ArrayList; +import java.util.List; + +import org.hibernate.Criteria; +import org.hibernate.Query; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.hibernate.criterion.Restrictions; +import org.openecomp.policy.dao.PolicyVersionDao; +import org.openecomp.policy.rest.jpa.PolicyVersion; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +@Service("PolicyVersionDao") +public class PolicyVersionDaoImpl implements PolicyVersionDao { + private static final Logger logger = FlexLogger.getLogger(PolicyVersionDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + @SuppressWarnings("unchecked") + @Override + public List getPolicyVersionData() { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + List versionData = null; + try { + Criteria cr = session.createCriteria(PolicyVersion.class); + versionData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying PolicyVersion Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return versionData; + + } + + @SuppressWarnings("unchecked") + @Override + public List getPolicyVersionDataByName() { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(PolicyVersion.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getPolicyName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying PolicyVersion Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + + @Override + public void Save(PolicyVersion policyVersion) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.persist(policyVersion); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving PolicyVersion Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void delete(PolicyVersion policyVersion) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.delete(policyVersion); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting PolicyVersion Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(PolicyVersion policyVersion) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.update(policyVersion); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating PolicyVersion Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @SuppressWarnings("unchecked") + @Override + public List getPolicyVersionEntityByName(String policyVersion) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + List data = null; + try { + Criteria cr = session.createCriteria(PolicyVersion.class); + cr.add(Restrictions.eq("policyName",policyVersion)); + data = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying PolicyVersion Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + + @SuppressWarnings("unchecked") + @Override + public List getActiveVersionPolicy(String query) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + List data = null; + try { + Query hbquery = session.createQuery(query); + data = hbquery.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying PolicyVersion Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + + @Override + public void updateQuery(String policyVersion) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + Query hbquery = session.createQuery(policyVersion); + hbquery.executeUpdate(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating PolicyVersion Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/PrefixListDaoImpl.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/PrefixListDaoImpl.java new file mode 100644 index 000000000..cc8701361 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/PrefixListDaoImpl.java @@ -0,0 +1,153 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.daoImp; + + +import java.util.ArrayList; +import java.util.List; + +//import org.apache.commons.logging.Log; +//import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.rest.dao.PrefixListDao; +import org.openecomp.policy.rest.jpa.PREFIXLIST; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +@Service("PrefixListDao") +public class PrefixListDaoImpl implements PrefixListDao{ + private static final Logger logger = FlexLogger.getLogger(PrefixListDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + @SuppressWarnings("unchecked") + @Override + public List getPREFIXLISTData() { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + List attributeData = null; + try { + Criteria cr = session.createCriteria(PREFIXLIST.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying PREFIXLIST Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + + } + + @Override + public void Save(PREFIXLIST attribute) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.persist(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving PREFIXLIST Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(PREFIXLIST attribute) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.delete(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting PREFIXLIST Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(PREFIXLIST attribute) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.update(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating PREFIXLIST Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getPrefixListDataByName() { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(PREFIXLIST.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getPrefixListName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying PREFIXLIST Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/RemoteCatalogValuesDaoImpl.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/RemoteCatalogValuesDaoImpl.java new file mode 100644 index 000000000..5f42ba73e --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/RemoteCatalogValuesDaoImpl.java @@ -0,0 +1,150 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.daoImp; + + +import java.util.ArrayList; +import java.util.List; + +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.dao.RemoteCatalogValuesDao; +import org.openecomp.policy.rest.jpa.RemoteCatalogValues; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +@Service("RemoteCatalogValuesDao") +public class RemoteCatalogValuesDaoImpl implements RemoteCatalogValuesDao { + private static final Logger logger = FlexLogger.getLogger(RemoteCatalogValuesDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + + @SuppressWarnings("unchecked") + @Override + public List getRemoteCatalogValuesData() { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + List attributeData = null; + try { + Criteria cr = session.createCriteria(RemoteCatalogValues.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying RemoteCatalogValues Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + } + + @SuppressWarnings("unchecked") + @Override + public List getRemoteCatalogValuesDataByName() { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(RemoteCatalogValues.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying RemoteCatalogValues Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + + @Override + public void Save(RemoteCatalogValues attribute) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.persist(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving RemoteCatalogValues Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void delete(RemoteCatalogValues attribute) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.delete(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting RemoteCatalogValues Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(RemoteCatalogValues attribute) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.update(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating RemoteCatalogValues Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/RolesDaoImpl.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/RolesDaoImpl.java new file mode 100644 index 000000000..7e5c860de --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/RolesDaoImpl.java @@ -0,0 +1,109 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.daoImp; + + +import java.util.List; + +import org.hibernate.Criteria; +import org.hibernate.Query; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.hibernate.criterion.Restrictions; +import org.openecomp.policy.dao.RolesDao; +import org.openecomp.policy.model.Roles; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +@Service("RolesDao") +public class RolesDaoImpl implements RolesDao{ + private static final Logger logger = FlexLogger.getLogger(RolesDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + @Override + public void save(Roles role) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.persist(role); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving Roles Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void delete(Roles role) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + System.out.println("delete from Roles where loginid = '"+role.getLoginId()+"'"); + Query q = session.createQuery(" delete from Roles where loginid = '"+role.getLoginId()+"'"); + q.executeUpdate(); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting Roles Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @SuppressWarnings("unchecked") + @Override + public List getUserRoles(String userId) { + System.out.println("User Id:"+userId); + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + List rolesData = null; + try { + Criteria cr = session.createCriteria(Roles.class); + cr = cr.add(Restrictions.eq("loginId",userId)); + rolesData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying Roles Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return rolesData; + } +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/RuleAlgorithmsDaoImpl.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/RuleAlgorithmsDaoImpl.java new file mode 100644 index 000000000..149038501 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/RuleAlgorithmsDaoImpl.java @@ -0,0 +1,68 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.daoImp; + + +import java.util.List; + +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.dao.RuleAlgorithmsDao; +import org.openecomp.policy.rest.jpa.RuleAlgorithms; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +@Service("RuleAlgorithmsDao") +public class RuleAlgorithmsDaoImpl implements RuleAlgorithmsDao{ + private static final Logger logger = FlexLogger.getLogger(RuleAlgorithmsDaoImpl.class); + @Autowired + SessionFactory sessionFactory; + + @SuppressWarnings("unchecked") + @Override + public List getRuleAlgorithms() { + Session session = sessionFactory.openSession(); + Transaction tx = session.beginTransaction(); + List ruleAlgorithmsData = null; + try { + Criteria cr = session.createCriteria(RuleAlgorithms.class); + ruleAlgorithmsData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying RuleAlgorithms Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return ruleAlgorithmsData; + } + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/SafePolicyWarningDaoImpl.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/SafePolicyWarningDaoImpl.java new file mode 100644 index 000000000..209d60b2d --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/SafePolicyWarningDaoImpl.java @@ -0,0 +1,181 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.daoImp; + + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.hibernate.criterion.Restrictions; +import org.openecomp.policy.rest.dao.SafePolicyWarningDao; +import org.openecomp.policy.rest.jpa.SafePolicyWarning; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("SafePolicyWarningDao") +public class SafePolicyWarningDaoImpl implements SafePolicyWarningDao { + private static final Log logger = LogFactory.getLog(SafePolicyWarningDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getSafePolicyWarningData() { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + List attributeData = null; + try { + Criteria cr = session.createCriteria(SafePolicyWarning.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying SafePolicyWarning Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + } + + @SuppressWarnings("unchecked") + @Override + public List getSafePolicyWarningDataByName() { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(SafePolicyWarning.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying SafePolicyWarning Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + + @Override + public void Save(SafePolicyWarning attribute) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.persist(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving SafePolicyWarning Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(SafePolicyWarning attribute) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.delete(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting Attribute Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void update(SafePolicyWarning attribute) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.update(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating Attribute Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public SafePolicyWarning getSafePolicyWarningDataById(String riskType) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + SafePolicyWarning data = null; + try { + Criteria cr = session.createCriteria(SafePolicyWarning.class); + cr.add(Restrictions.eq("riskType",riskType)); + data = (SafePolicyWarning) cr.list().get(0); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying SafePolicyWarning Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/SecurityZoneDaoImpl.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/SecurityZoneDaoImpl.java new file mode 100644 index 000000000..e3661ceb9 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/SecurityZoneDaoImpl.java @@ -0,0 +1,152 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.daoImp; + + +import java.util.ArrayList; +import java.util.List; + +//import org.apache.commons.logging.Log; +//import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.rest.dao.SecurityZoneDao; +import org.openecomp.policy.rest.jpa.SecurityZone; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +@Service("SecurityZoneDao") +public class SecurityZoneDaoImpl implements SecurityZoneDao{ + private static final Logger logger = FlexLogger.getLogger(SecurityZoneDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + @SuppressWarnings("unchecked") + @Override + public List getSecurityZoneData() { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + List attributeData = null; + try { + Criteria cr = session.createCriteria(SecurityZone.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying SecurityZone Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + + } + + @Override + public void Save(SecurityZone attribute) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.persist(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving SecurityZone Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void delete(SecurityZone attribute) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.delete(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting SecurityZone Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(SecurityZone attribute) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.update(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating SecurityZone Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getSecurityZoneDataByName() { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(SecurityZone.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getZoneName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying SecurityZone Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/ServiceGroupDaoImpl.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/ServiceGroupDaoImpl.java new file mode 100644 index 000000000..f2e9c5be8 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/ServiceGroupDaoImpl.java @@ -0,0 +1,153 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.daoImp; + + +import java.util.ArrayList; +import java.util.List; + +//import org.apache.commons.logging.Log; +//import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.rest.dao.ServiceGroupDao; +import org.openecomp.policy.rest.jpa.GroupServiceList; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +@Service("ServiceGroupDao") +public class ServiceGroupDaoImpl implements ServiceGroupDao{ + private static final Logger logger = FlexLogger.getLogger(ServiceGroupDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + @SuppressWarnings("unchecked") + @Override + public List getGroupServiceListData() { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + List attributeData = null; + try { + Criteria cr = session.createCriteria(GroupServiceList.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying GroupServiceList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + + } + + @Override + public void Save(GroupServiceList attribute) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.persist(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving GroupServiceList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(GroupServiceList attribute) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.delete(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting GroupServiceList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(GroupServiceList attribute) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.update(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating GroupServiceList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getGroupServiceDataByName() { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(GroupServiceList.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getGroupName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying GroupServiceList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/ServiceListDaoImpl.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/ServiceListDaoImpl.java new file mode 100644 index 000000000..0f80a16d3 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/ServiceListDaoImpl.java @@ -0,0 +1,154 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.daoImp; + + +import java.util.ArrayList; +import java.util.List; + +//import org.apache.commons.logging.Log; +//import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.rest.dao.ServiceListDao; +import org.openecomp.policy.rest.jpa.ServiceList; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +@Service("ServiceListDao") +public class ServiceListDaoImpl implements ServiceListDao { + private static final Logger logger = FlexLogger.getLogger(ServiceListDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + @SuppressWarnings("unchecked") + @Override + public List getServiceListData() { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + List attributeData = null; + try { + Criteria cr = session.createCriteria(ServiceList.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying ServiceList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + + } + + @Override + public void Save(ServiceList attribute) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.persist(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving ServiceList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(ServiceList attribute) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.delete(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting ServiceList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(ServiceList attribute) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.update(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating ServiceList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getServiceListDataByName() { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(ServiceList.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getServiceName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying ServiceList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + + } + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/SystemLogDbDaoImpl.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/SystemLogDbDaoImpl.java new file mode 100644 index 000000000..927d20f2f --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/SystemLogDbDaoImpl.java @@ -0,0 +1,93 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.daoImp; + + +import java.util.List; + +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +import org.hibernate.Transaction; +import org.hibernate.criterion.Restrictions; +import org.openecomp.policy.conf.HibernateSession; +import org.openecomp.policy.controller.PolicyController; +import org.openecomp.policy.dao.SystemLogDbDao; +import org.openecomp.policy.rest.jpa.SystemLogDB; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + + +@Service("SystemLogDbDao") +public class SystemLogDbDaoImpl implements SystemLogDbDao { + private static final Logger logger = FlexLogger.getLogger(SystemLogDbDaoImpl.class); + @SuppressWarnings("unchecked") + @Override + public List getLoggingData() { + Session session = HibernateSession.getSession(); + Transaction tx = session.beginTransaction(); + List system = null; + try { + String sqlWhere = "date > DATE_SUB(curdate(), INTERVAL 5 DAY) ORDER BY date DESC limit "+PolicyController.logTableLimit+""; + Criteria cr = session.createCriteria(SystemLogDB.class); + cr.add(Restrictions.sqlRestriction(sqlWhere)); + system = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying SystemLogDB Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return system; + } + + @SuppressWarnings("unchecked") + @Override + public List getSystemAlertData() { + Session session = HibernateSession.getSession();; + Transaction tx = session.beginTransaction(); + List system = null; + try { + String sqlWhere = "date > DATE_SUB(curdate(), INTERVAL 5 DAY) and logtype = 'error' ORDER BY date DESC limit "+PolicyController.systemAlertTableLimit+""; + Criteria cr = session.createCriteria(SystemLogDB.class); + cr.add(Restrictions.sqlRestriction(sqlWhere)); + system = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying SystemLogDB Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return system; + } + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/TermListDaoImpl.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/TermListDaoImpl.java new file mode 100644 index 000000000..ff8f1f26d --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/TermListDaoImpl.java @@ -0,0 +1,176 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.daoImp; + + +import java.util.ArrayList; +import java.util.List; + +//import org.apache.commons.logging.Log; +//import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.hibernate.criterion.Restrictions; +import org.openecomp.policy.rest.dao.TermListDao; +import org.openecomp.policy.rest.jpa.TermList; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +@Service("TermListDao") +public class TermListDaoImpl implements TermListDao{ + private static final Logger logger = FlexLogger.getLogger(TermListDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + @SuppressWarnings("unchecked") + @Override + public List getTermListData() { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + List attributeData = null; + try { + Criteria cr = session.createCriteria(TermList.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying TermList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + + } + + @Override + public void Save(TermList attribute) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.persist(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving TermList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(TermList attribute) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.delete(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting TermList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(TermList attribute) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.update(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating TermList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getTermListDataByName() { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(TermList.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getTermName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying TermList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + + @Override + public TermList getTermListValueByName(String name) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + TermList data = null; + try { + Criteria cr = session.createCriteria(TermList.class); + cr.add(Restrictions.eq("termName",name)); + data = (TermList) cr.list().get(0); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying TermList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/UserInfoDaoImpl.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/UserInfoDaoImpl.java new file mode 100644 index 000000000..ad13b5940 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/UserInfoDaoImpl.java @@ -0,0 +1,123 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.daoImp; + + +import java.util.List; + +//import org.apache.commons.logging.Log; +//import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.rest.dao.UserInfoDao; +import org.openecomp.policy.rest.jpa.UserInfo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + + +@Service("UserInfoDao") +public class UserInfoDaoImpl implements UserInfoDao{ + private static final Logger logger = FlexLogger.getLogger(UserInfoDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @Override + public void save(UserInfo userInfo) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.persist(userInfo); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving UserInfo Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @SuppressWarnings("unchecked") + @Override + public List getUserInfo() { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + List userData = null; + try { + Criteria cr = session.createCriteria(UserInfo.class); + userData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying UserInfo Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return userData; + } + + @Override + public String getUserName(String loginid) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + UserInfo user = null; + try { + user = (UserInfo) session.get(UserInfo.class, loginid); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying UserInfo Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return user.getUserName().toString(); + } + + @Override + public UserInfo getUserInfoByLoginId(String loginid) { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/VarbindDictionaryDaoImpl.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/VarbindDictionaryDaoImpl.java new file mode 100644 index 000000000..a24c0e7ad --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/VarbindDictionaryDaoImpl.java @@ -0,0 +1,177 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.daoImp; + + +import java.util.ArrayList; +import java.util.List; + +//import org.apache.commons.logging.Log; +//import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.hibernate.criterion.Restrictions; +import org.openecomp.policy.rest.dao.VarbindDictionaryDao; +import org.openecomp.policy.rest.jpa.VarbindDictionary; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +@Service("VarbindDictionaryDao") +public class VarbindDictionaryDaoImpl implements VarbindDictionaryDao { + private static final Logger logger = FlexLogger.getLogger(VarbindDictionaryDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + @SuppressWarnings("unchecked") + @Override + public List getVarbindDictionaryData() { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + List varbindDictionaryData = null; + try { + Criteria cr = session.createCriteria(VarbindDictionary.class); + varbindDictionaryData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying VarbindDictionary Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return varbindDictionaryData; + + } + + @Override + public void Save(VarbindDictionary varbindDictionary) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.persist(varbindDictionary); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving VarbindDictionary Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(VarbindDictionary varbindDictionary) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.delete(varbindDictionary); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting VarbindDictionary Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(VarbindDictionary varbindDictionary) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.update(varbindDictionary); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating VarbindDictionary Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getVarbindDataByName() { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(VarbindDictionary.class); + List varbindDictionaryData = cr.list(); + for(int i = 0; i < varbindDictionaryData.size(); i++){ + data.add(varbindDictionaryData.get(i).getVarbindName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying VarbindDictionary Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + + @SuppressWarnings("unchecked") + @Override + public List getVarbindEntityByName(String value) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + List data = null; + try { + Criteria cr = session.createCriteria(VarbindDictionary.class); + cr.add(Restrictions.eq("varbindName",value)); + data = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying VarbindDictionary Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/WatchPolicyNotificationDaoImpl.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/WatchPolicyNotificationDaoImpl.java new file mode 100644 index 000000000..b4b807fbd --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/daoImp/WatchPolicyNotificationDaoImpl.java @@ -0,0 +1,173 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.daoImp; + + +import java.util.List; + +import org.hibernate.Criteria; +import org.hibernate.Query; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.hibernate.criterion.Restrictions; +import org.openecomp.policy.dao.WatchPolicyNotificationDao; +import org.openecomp.policy.rest.jpa.WatchPolicyNotificationTable; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +@Service("WatchPolicyNotificationDao") +public class WatchPolicyNotificationDaoImpl implements WatchPolicyNotificationDao{ + + private static final Logger logger = FlexLogger.getLogger(WatchPolicyNotificationDaoImpl.class); + + @Autowired + SessionFactory sessionfactory; + + @SuppressWarnings("unchecked") + @Override + public List getListData() { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + List attributeData =null; + try { + Criteria cr = session.createCriteria(WatchPolicyNotificationTable.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying WatchPolicyNotificationTable Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + } + + @Override + public void save(WatchPolicyNotificationTable attribute) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.persist(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving WatchPolicyNotificationTable Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(WatchPolicyNotificationTable attribute) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.delete(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting WatchPolicyNotificationTable Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(WatchPolicyNotificationTable attribute) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + try { + session.update(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating WatchPolicyNotificationTable Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getListDataByPolicyName(String policyName) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + List data = null; + try { + Criteria cr = session.createCriteria(WatchPolicyNotificationTable.class); + cr.add(Restrictions.eq("policyName",policyName)); + data = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying WatchPolicyNotificationTable Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + + @SuppressWarnings("unchecked") + @Override + public List watchListQuery(String query) { + Session session = sessionfactory.openSession(); + Transaction tx = session.beginTransaction(); + List data = null; + try { + Query hbquery = session.createQuery(query); + data = hbquery.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying WatchPolicyNotificationTable Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/elk/client/ElkConnector.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/elk/client/ElkConnector.java new file mode 100644 index 000000000..617e67ccb --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/elk/client/ElkConnector.java @@ -0,0 +1,1235 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.elk.client; + + +import io.searchbox.action.Action; +import io.searchbox.client.JestClient; +import io.searchbox.client.JestClientFactory; +import io.searchbox.client.JestResult; +import io.searchbox.client.config.HttpClientConfig; +import io.searchbox.core.Delete; +import io.searchbox.core.Get; +import io.searchbox.core.Index; +import io.searchbox.core.Search; +import io.searchbox.core.Search.Builder; +import io.searchbox.indices.IndicesExists; +import io.searchbox.indices.type.TypeExist; +import io.searchbox.params.Parameters; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Map.Entry; + +import javax.xml.bind.JAXBException; + +//import org.apache.commons.logging.Log; +//import org.apache.commons.logging.LogFactory; +import org.elasticsearch.index.query.QueryBuilders; +import org.elasticsearch.index.query.QueryStringQueryBuilder; +import org.elasticsearch.search.builder.SearchSourceBuilder; +import org.kohsuke.args4j.CmdLineException; +import org.kohsuke.args4j.CmdLineParser; +import org.kohsuke.args4j.Option; +import org.openecomp.policy.elk.converter.ElkRecord; +import org.openecomp.policy.elk.converter.Xacml2Elk; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.google.gson.Gson; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +public interface ElkConnector { + + public static final String ELK_URL = "http://localhost:9200"; + public static final String ELK_INDEX_POLICY = "policy"; + + public enum PolicyIndexType { + config, + action, + decision, + closedloop, + all, + } + + public enum PolicyType { + Config, + Action, + Decision, + Config_Fault, + Config_PM, + Config_FW, + Config_MS, + none, + } + + public enum PolicyBodyType { + json, + xml, + properties, + txt, + none, + } + + public ElkRecord create(PolicyType type, String name, String owner, String scope, + File xacmlFile, PolicyBodyType bodyType, String body, + File destinationDir) + throws IllegalStateException; + + public boolean testAndUpdate(File xacmlFile) throws IllegalStateException; + + public JestResult policy(String policyId) + throws IllegalStateException, IllegalArgumentException; + + public boolean clone(String origPolicyId, String clonePolicyId) + throws IllegalStateException; + + public boolean delete(File xacmlFile) + throws IllegalStateException; + + public ArrayList policyLocators(PolicyIndexType type, String text,int connector) + throws IllegalStateException, IllegalArgumentException; + + public ArrayList policyLocators(PolicyIndexType type, String text, + ArrayList,ArrayList>> filter_s,int connector) + throws IllegalStateException, IllegalArgumentException; + + public JestResult search(PolicyIndexType type, String text) + throws IllegalStateException, IllegalArgumentException; + + public JestResult search(PolicyIndexType type, String text, + ArrayList,ArrayList>> filter_s) + throws IllegalStateException, IllegalArgumentException; + + public boolean update(File xacmlFile) throws IllegalStateException; + + public ElkConnector singleton = new ElkConnectorImpl(); + + public static PolicyIndexType toPolicyIndexType(PolicyType type) + throws IllegalArgumentException { + if (type == null) + throw new IllegalArgumentException("Unsupported NULL type conversion"); + + switch(type) { + case Config: + return PolicyIndexType.config; + case Action: + return PolicyIndexType.action; + case Decision: + return PolicyIndexType.decision; + case Config_Fault: + return PolicyIndexType.closedloop; + case Config_PM: + return PolicyIndexType.closedloop; + case Config_FW: + return PolicyIndexType.config; + case Config_MS: + return PolicyIndexType.config; + case none: + return PolicyIndexType.all; + default: + throw new IllegalArgumentException("Unsupported type conversion to index: " + type.name()); + } + } + + public static PolicyIndexType toPolicyIndexType(String policyName) + throws IllegalArgumentException { + if (policyName == null) + throw new IllegalArgumentException("Unsupported NULL policy name conversion"); + + if (policyName.startsWith("Config_Fault")) { + return PolicyIndexType.closedloop; + } else if (policyName.startsWith("Config_PM")) { + return PolicyIndexType.closedloop; + } else if (policyName.startsWith("Config_FW")) { + return PolicyIndexType.config; + } else if (policyName.startsWith("Config_MS")) { + return PolicyIndexType.config; + }else if (policyName.startsWith("Action")) { + return PolicyIndexType.action; + } else if (policyName.startsWith("Decision")) { + return PolicyIndexType.decision; + } else if (policyName.startsWith("Config")) { + return PolicyIndexType.config; + } else { + throw new IllegalArgumentException + ("Unsupported policy name conversion to index: " + + policyName); + } + } + + public static PolicyType toPolicyType(String policyName) + throws IllegalArgumentException { + if (policyName == null) + throw new IllegalArgumentException("Unsupported NULL policy name conversion to Policy Type"); + + if (policyName.startsWith("Config_Fault")) { + return PolicyType.Config_Fault; + } else if (policyName.startsWith("Config_PM")) { + return PolicyType.Config_PM; + } else if (policyName.startsWith("Config_FW")) { + return PolicyType.Config_FW; + } else if (policyName.startsWith("Config_MS")) { + return PolicyType.Config_MS; + }else if (policyName.startsWith("Action")) { + return PolicyType.Action; + } else if (policyName.startsWith("Decision")) { + return PolicyType.Decision; + } else if (policyName.startsWith("Config")) { + return PolicyType.Config; + } else { + throw new IllegalArgumentException + ("Unsupported policy name conversion to index: " + + policyName); + } + } + + public static void main(String args[]) + throws JAXBException, IOException, CmdLineException, IllegalStateException { + ElkConnectorImpl.CLIOptions cliOptions = new ElkConnectorImpl.CLIOptions(); + CmdLineParser cliParser= new CmdLineParser(cliOptions); + try { + cliParser.parseArgument(args); + } catch (CmdLineException e) { + System.out.println("Usage: ElkConnector"); + cliParser.printUsage(System.out); + throw e; + } + + if (cliOptions.searchText != null && !cliOptions.searchText.isEmpty()) { + ArrayList locators = + ElkConnector.singleton.policyLocators(PolicyIndexType.all, cliOptions.searchText,0); + for (PolicyLocator l: locators) { + System.out.println(l); + } + } else if (cliOptions.testFile != null && cliOptions.testFile.canRead()) { + boolean ok = ElkConnector.singleton.testAndUpdate(cliOptions.testFile); + System.out.println(cliOptions.testFile.getName() + ":" + ok); + } + } +} + +class ElkConnectorImpl implements ElkConnector { + + protected static class CLIOptions { + @Option(name="-s", usage="search", aliases={"-search", "--search"}, required=false, metaVar="") + protected String searchText; + + @Option(name="-e", usage="test and update policy if not exists", aliases={"-exist", "--exists"}, required=false, metaVar="") + protected File testFile; + + @Option(name = "-h", aliases = {"-help", "--help"}, usage = "print this message") + private boolean help = false; + }; + + private static final String POLICY_RESULT_FIELDS = "[ \"Policy.PolicyType\", " + + "\"Policy.PolicyName\", " + + "\"Policy.Owner\", " + + "\"Policy.Scope\", " + + "\"Policy.PolicyId\", " + + "\"Policy.Version\" ]"; + + private static final String SOURCE_RESULT_FIELDS = "\"_source\": " + POLICY_RESULT_FIELDS; + + private static final Logger logger = FlexLogger.getLogger(ElkConnector.class); + + protected final JestClientFactory jestFactory = new JestClientFactory(); + protected final JestClient jestClient; + protected static int QUERY_MAXRECORDS = 1000; + + public ElkConnectorImpl() { + if (logger.isDebugEnabled()) logger.debug("ENTER: -"); + + HttpClientConfig jestClientConfig = + new HttpClientConfig.Builder(ELK_URL).multiThreaded(true).build(); + jestFactory.setHttpClientConfig(jestClientConfig); + jestClient = jestFactory.getObject(); + } + + protected boolean isType(PolicyIndexType type) throws IOException { + if (logger.isDebugEnabled()) logger.debug("ENTER: -"); + + try { + Action typeQuery = new TypeExist.Builder(ELK_INDEX_POLICY). + addType(type.toString()). + build(); + JestResult result = jestClient.execute(typeQuery); + + if (logger.isInfoEnabled()) { + logger.info("JSON:" + result.getJsonString()); + logger.info("ERROR:" + result.getErrorMessage()); + logger.info("PATH:" + result.getPathToResult()); + logger.info(result.getJsonObject()); + } + return result.isSucceeded(); + } catch (IOException e) { + logger.warn("Error checking type existance of " + type.toString() + + ": " + e.getMessage(), e); + throw e; + } + } + + protected boolean isIndex() throws IOException { + try { + Action indexQuery = + new IndicesExists.Builder(ELK_INDEX_POLICY).build(); + + JestResult result = jestClient.execute(indexQuery); + if (logger.isInfoEnabled()) { + logger.info("JSON:" + result.getJsonString()); + logger.info("ERROR:" + result.getErrorMessage()); + logger.info("PATH:" + result.getPathToResult()); + logger.info(result.getJsonObject()); + } + return result.isSucceeded(); + } catch (IOException e) { + logger.warn("Error checking index existance of " + + ELK_INDEX_POLICY + + ": " + e.getMessage(), e); + throw e; + } + } + + @Override + public JestResult search(PolicyIndexType type, String text) throws IllegalStateException, IllegalArgumentException { + if (logger.isTraceEnabled()) + logger.trace("ENTER: " + text); + + if (text == null || text.isEmpty()) { + throw new IllegalArgumentException("No search string provided"); + } + + // MatchQueryBuilder mQ = QueryBuilders.matchQuery("_all", text); + QueryStringQueryBuilder mQ = QueryBuilders.queryStringQuery(text); + SearchSourceBuilder searchSourceBuilder = + new SearchSourceBuilder().query(mQ). + fetchSource(new String[]{"Policy.PolicyType", + "Policy.PolicyName", + "Policy.Owner", + "Policy.Scope", + "Policy.PolicyId", + "Policy.Version"}, + null); + Builder searchBuilder = new Search.Builder(searchSourceBuilder.toString()). + addIndex(ELK_INDEX_POLICY). + setParameter(Parameters.SIZE, ElkConnectorImpl.QUERY_MAXRECORDS); + + if (type == null || type == PolicyIndexType.all) { + for (PolicyIndexType pT: PolicyIndexType.values()) { + if (pT != PolicyIndexType.all) { + searchBuilder.addType(pT.toString()); + } + } + } else { + searchBuilder.addType(type.toString()); + } + + Search search = searchBuilder.build(); + + JestResult result; + try { + result = jestClient.execute(search); + } catch (IOException ioe) { + logger.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR + ":" + + search + ": " + ioe.getMessage(), ioe); + throw new IllegalStateException(ioe); + } + + if (result.isSucceeded()) { + if (logger.isInfoEnabled()) + logger.info("OK:" + result.getResponseCode() + ":" + search + ": " + + result.getPathToResult() + ":" + System.lineSeparator() + + result.getJsonString()); + } else { + /* Unsuccessful search */ + if (logger.isWarnEnabled()) + logger.warn(XACMLErrorConstants.ERROR_PROCESS_FLOW + ":" + + result.getResponseCode() + ": " + + search.getURI() + ":" + + result.getPathToResult() + ":" + + result.getJsonString() + ":" + + result.getErrorMessage()); + + String errorMessage = result.getErrorMessage(); + if (errorMessage != null && !errorMessage.isEmpty()) { + String xMessage = errorMessage; + if (errorMessage.contains("TokenMgrError")) { + int indexError = errorMessage.lastIndexOf("TokenMgrError"); + xMessage = "Invalid Search Expression. Details: " + errorMessage.substring(indexError); + } else if (errorMessage.contains("QueryParsingException")) { + int indexError = errorMessage.lastIndexOf("QueryParsingException"); + xMessage = "Invalid Search Expression. Details: " + errorMessage.substring(indexError); + } else if (errorMessage.contains("JsonParseException")) { + int indexError = errorMessage.lastIndexOf("JsonParseException"); + xMessage = "Invalid Search Expression. Details: " + errorMessage.substring(indexError); + } else if (errorMessage.contains("Parse Failure")) { + int indexError = errorMessage.lastIndexOf("Parse Failure"); + xMessage = "Invalid Search Expression. Details: " + errorMessage.substring(indexError); + } else if (errorMessage.contains("SearchParseException")) { + int indexError = errorMessage.lastIndexOf("SearchParseException"); + xMessage = "Invalid Search Expression. Details: " + errorMessage.substring(indexError); + } else { + xMessage = result.getErrorMessage(); + } + throw new IllegalStateException(xMessage); + } + } + + return result; + } + + public JestResult searchKey(PolicyIndexType type, String text, + ArrayList,ArrayList>> filter_s,int connector) + throws IllegalStateException, IllegalArgumentException { + if (logger.isTraceEnabled()) + logger.trace("ENTER: " + text); + + if (filter_s == null || filter_s.size() <= 0) { + return search(type, text); + } + + String matches_s = ""; + + if(connector==0)// AND CONNECTOR + { + matches_s = "{\n" + + " " + SOURCE_RESULT_FIELDS + ",\n" + + " \"size\" : "+ ElkConnectorImpl.QUERY_MAXRECORDS + ",\n" + + " \"query\": {\n" + + " \"bool\" : {\n" + + " \"must\" : ["; + } + else if (connector ==1)//OR CONNECTOR + { + matches_s = "{\n" + + " " + SOURCE_RESULT_FIELDS + ",\n" + + " \"size\" : "+ ElkConnectorImpl.QUERY_MAXRECORDS + ",\n" + + " \"query\": {\n" + + " \"bool\" : {\n" + + " \"should\" : ["; + } + + for (Pair,ArrayList> p : filter_s) { + ArrayList name_s = p.left(); + ArrayList value_s = p.right(); + + if (name_s == null || name_s.size() <= 0) { + if (logger.isWarnEnabled()) + logger.warn("Defaulting to text search: Empty field name array passed in"); + return search(type, text); + } + + if (logger.isDebugEnabled()) { + for (String n: name_s) { + logger.debug("Filter Name: " + n); + } + } + + if (value_s == null || value_s.size() <= 0) { + if (logger.isWarnEnabled()) + logger.warn("Defaulting to text search: Empty field value array passed in"); + return search(type, text); + } + + if (logger.isDebugEnabled()) { + for (String v: value_s) { + logger.debug("Filter Value: " + v); + } + } + + /* common case: # filter names == # filter values */ + if (name_s.size() == value_s.size()) { + String match = ""; + for (int i=0; i value_s.size() && (value_s.size() == 1)) { + String match = + "{ \"multi_match\": { \"query\": \"" + value_s.get(0) + "\", \"type\": \"phrase\", \"fields\": ["; + for (String n: name_s) { + match += " \"" + n + "\","; + } + match = match.substring(0, match.length()-1); + //match += " ] } },"; + match += " ] } },";//debug + if (logger.isDebugEnabled()) + logger.debug("Adding Match Line: " + match); + matches_s = matches_s + "\n " + match; + } else { + if (logger.isWarnEnabled()) + logger.warn("Defaulting to text search: different number of filter names and values"); + return search(type, text); + } + } + + matches_s = matches_s.substring(0, matches_s.length()-1); // remove last comma + + matches_s = matches_s + + " ]\n" + + " }\n" + + " }\n" + + "}"; + + if (logger.isDebugEnabled()) { + logger.debug(matches_s); + } + + Builder searchBuilder = new Search.Builder(matches_s). + addIndex(ELK_INDEX_POLICY); + + if (type == null || type == PolicyIndexType.all) { + for (PolicyIndexType pT: PolicyIndexType.values()) { + if (pT != PolicyIndexType.all) { + searchBuilder.addType(pT.toString()); + } + } + } else { + searchBuilder.addType(type.toString()); + } + + Search search = searchBuilder.build(); + + JestResult result; + try { + result = jestClient.execute(search); + } catch (IOException ioe) { + logger.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR + ":" + + search + ": " + ioe.getMessage(), ioe); + throw new IllegalStateException(ioe); + } + + if (result.isSucceeded()) { + if (logger.isInfoEnabled()) + logger.info("OK:" + result.getResponseCode() + ":" + search + ": " + + result.getPathToResult() + ":" + System.lineSeparator() + + result.getJsonString()); + } else { + /* Unsuccessful search */ + if (logger.isWarnEnabled()) + logger.warn(XACMLErrorConstants.ERROR_PROCESS_FLOW + ":" + + result.getResponseCode() + ": " + + search.getURI() + ":" + + result.getPathToResult() + ":" + + result.getJsonString() + ":" + + result.getErrorMessage()); + + String errorMessage = result.getErrorMessage(); + if (errorMessage != null && !errorMessage.isEmpty()) { + String xMessage = errorMessage; + if (errorMessage.contains("TokenMgrError")) { + int indexError = errorMessage.lastIndexOf("TokenMgrError"); + xMessage = "Invalid Search Expression. Details: " + errorMessage.substring(indexError); + } else if (errorMessage.contains("QueryParsingException")) { + int indexError = errorMessage.lastIndexOf("QueryParsingException"); + xMessage = "Invalid Search Expression. Details: " + errorMessage.substring(indexError); + } else if (errorMessage.contains("JsonParseException")) { + int indexError = errorMessage.lastIndexOf("JsonParseException"); + xMessage = "Invalid Search Expression. Details: " + errorMessage.substring(indexError); + } else if (errorMessage.contains("Parse Failure")) { + int indexError = errorMessage.lastIndexOf("Parse Failure"); + xMessage = "Invalid Search Expression. Details: " + errorMessage.substring(indexError); + } else if (errorMessage.contains("SearchParseException")) { + int indexError = errorMessage.lastIndexOf("SearchParseException"); + xMessage = "Invalid Search Expression. Details: " + errorMessage.substring(indexError); + } else { + xMessage = result.getErrorMessage(); + } + throw new IllegalStateException(xMessage); + } + } + + return result; + } + + + @Override + public JestResult search(PolicyIndexType type, String text, + ArrayList,ArrayList>> filter_s) + throws IllegalStateException, IllegalArgumentException { + if (logger.isTraceEnabled()) + logger.trace("ENTER: " + text); + + if (filter_s == null || filter_s.size() <= 0) { + return search(type, text); + } + + String matches_s = ""; + matches_s = "{\n" + + " " + SOURCE_RESULT_FIELDS + ",\n" + + " \"size\" : "+ ElkConnectorImpl.QUERY_MAXRECORDS + ",\n" + + " \"query\": {\n" + + " \"bool\" : {\n" + + " \"must\" : ["; + for (Pair,ArrayList> p : filter_s) { + ArrayList name_s = p.left(); + ArrayList value_s = p.right(); + + if (name_s == null || name_s.size() <= 0) { + if (logger.isWarnEnabled()) + logger.warn("Defaulting to text search: Empty field name array passed in"); + return search(type, text); + } + + if (logger.isDebugEnabled()) { + for (String n: name_s) { + logger.debug("Filter Name: " + n); + } + } + + if (value_s == null || value_s.size() <= 0) { + if (logger.isWarnEnabled()) + logger.warn("Defaulting to text search: Empty field value array passed in"); + return search(type, text); + } + + if (logger.isDebugEnabled()) { + for (String v: value_s) { + logger.debug("Filter Value: " + v); + } + } + + /* common case: # filter names == # filter values */ + if (name_s.size() == value_s.size()) { + String match = ""; + for (int i=0; i value_s.size() && (value_s.size() == 1)) { + String match = + "{ \"multi_match\": { \"query\": \"" + value_s.get(0) + "\", \"type\": \"phrase\", \"fields\": ["; + for (String n: name_s) { + match += " \"" + n + "\","; + } + match = match.substring(0, match.length()-1); + match += " ] } },"; + if (logger.isDebugEnabled()) + logger.debug("Adding Match Line: " + match); + matches_s = matches_s + "\n " + match; + } else { + if (logger.isWarnEnabled()) + logger.warn("Defaulting to text search: different number of filter names and values"); + return search(type, text); + } + } + if (text != null && !text.isEmpty()) { + if (logger.isDebugEnabled()) + logger.debug("Adding Match Line for search text: " + text); + + final JsonObject jsonText = new JsonObject(); + jsonText.addProperty("_all", text); + String escapedText = jsonText.toString(); + + matches_s = matches_s + "\n " + + "{ \"match\": " + + escapedText + " },"; + } + matches_s = matches_s.substring(0, matches_s.length()-1); // remove last comma + matches_s = matches_s + "\n" + + " ]\n" + + " }\n" + + " }\n" + + "}"; + + if (logger.isDebugEnabled()) { + logger.debug(matches_s); + } + + Builder searchBuilder = new Search.Builder(matches_s). + addIndex(ELK_INDEX_POLICY); + + if (type == null || type == PolicyIndexType.all) { + for (PolicyIndexType pT: PolicyIndexType.values()) { + if (pT != PolicyIndexType.all) { + searchBuilder.addType(pT.toString()); + } + } + } else { + searchBuilder.addType(type.toString()); + } + + Search search = searchBuilder.build(); + + JestResult result; + try { + result = jestClient.execute(search); + } catch (IOException ioe) { + logger.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR + ":" + + search + ": " + ioe.getMessage(), ioe); + throw new IllegalStateException(ioe); + } + + if (result.isSucceeded()) { + if (logger.isInfoEnabled()) + logger.info("OK:" + result.getResponseCode() + ":" + search + ": " + + result.getPathToResult() + ":" + System.lineSeparator() + + result.getJsonString()); + } else { + /* Unsuccessful search */ + if (logger.isWarnEnabled()) + logger.warn(XACMLErrorConstants.ERROR_PROCESS_FLOW + ":" + + result.getResponseCode() + ": " + + search.getURI() + ":" + + result.getPathToResult() + ":" + + result.getJsonString() + ":" + + result.getErrorMessage()); + + String errorMessage = result.getErrorMessage(); + if (errorMessage != null && !errorMessage.isEmpty()) { + String xMessage = errorMessage; + if (errorMessage.contains("TokenMgrError")) { + int indexError = errorMessage.lastIndexOf("TokenMgrError"); + xMessage = "Invalid Search Expression. Details: " + errorMessage.substring(indexError); + } else if (errorMessage.contains("QueryParsingException")) { + int indexError = errorMessage.lastIndexOf("QueryParsingException"); + xMessage = "Invalid Search Expression. Details: " + errorMessage.substring(indexError); + } else if (errorMessage.contains("JsonParseException")) { + int indexError = errorMessage.lastIndexOf("JsonParseException"); + xMessage = "Invalid Search Expression. Details: " + errorMessage.substring(indexError); + } else if (errorMessage.contains("Parse Failure")) { + int indexError = errorMessage.lastIndexOf("Parse Failure"); + xMessage = "Invalid Search Expression. Details: " + errorMessage.substring(indexError); + } else if (errorMessage.contains("SearchParseException")) { + int indexError = errorMessage.lastIndexOf("SearchParseException"); + xMessage = "Invalid Search Expression. Details: " + errorMessage.substring(indexError); + } else { + xMessage = result.getErrorMessage(); + } + throw new IllegalStateException(xMessage); + } + } + + return result; + } + + @Override + public JestResult policy(String policyId) + throws IllegalStateException, IllegalArgumentException { + if (logger.isTraceEnabled()) + logger.trace("ENTER: " + policyId); + + if (policyId == null || policyId.isEmpty()) { + throw new IllegalArgumentException("No policy id string provided"); + } + + Get policyRequest = new Get.Builder(ELK_INDEX_POLICY, policyId).build(); + + if (logger.isInfoEnabled()) + logger.info("ELK Search body request: " + policyRequest.toString()); + + JestResult result; + try { + result = jestClient.execute(policyRequest); + } catch (IOException ioe) { + logger.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR + ":" + + policyId + ": " + ioe.getMessage(), ioe); + throw new IllegalStateException(ioe); + } + + if (result.isSucceeded()) { + if (logger.isInfoEnabled()) + logger.info("OK:" + result.getResponseCode() + ":" + policyId + ":" + + result.getPathToResult() + ":" + System.lineSeparator() + + result.getJsonString()); + + return result; + } + + /* Unsuccessful search */ + if (logger.isWarnEnabled()) + logger.warn(XACMLErrorConstants.ERROR_PROCESS_FLOW + ":" + + result.getResponseCode() + ": " + policyId + ":" + + result.getPathToResult() + ":" + + result.getErrorMessage()); + + return result; + } + + protected JsonObject getJsonObject(JsonObject jsonObject, String member) throws IllegalArgumentException { + if (jsonObject == null) { + if (logger.isWarnEnabled()) + logger.warn("No JSON object provided to get " + member); + + throw new IllegalArgumentException("No JSON Object provided"); + } + + if (logger.isTraceEnabled()) { + logger.trace("ENTER: " + member); + for (Entry entry: jsonObject.entrySet()) { + logger.trace("JSONOBJECT: " + entry.getKey() + "->" + entry.getValue()); + } + } + + if (jsonObject.has(member)) { + JsonElement element = jsonObject.getAsJsonObject(member); + if (element.isJsonObject()) { + return (JsonObject) element; + } + } + + throw new IllegalArgumentException(member + " is not a JSON Object"); + } + + protected JsonArray getJsonArray(JsonObject jsonObject, String member) throws IllegalArgumentException { + if (jsonObject == null) { + throw new IllegalArgumentException("No JSON Object provided"); + } + + if (jsonObject.has(member)) { + if (jsonObject.get(member).isJsonArray()) { + return (JsonArray) jsonObject.get(member); + } + } + + throw new IllegalArgumentException(member + " is not a JSON Array"); + } + + protected String getJsonPolicyMember(JsonObject aHit, String member) throws IllegalArgumentException { + if (aHit == null) { + throw new IllegalArgumentException("No JSON Object provided"); + } + + JsonObject jSource = getJsonObject(aHit, "_source"); + JsonObject jPolicy = getJsonObject(jSource, "Policy"); + JsonElement jMember = jPolicy.get(member); + if (jMember == null) { + throw new IllegalArgumentException(member + " is not a JSON Object"); + } + return jMember.getAsString(); + } + + @Override + public ArrayList policyLocators(PolicyIndexType indexType, String text, int connector) + throws IllegalStateException, IllegalArgumentException { + return policyLocators(indexType, text, new ArrayList,ArrayList>>(),connector); + } + + @Override + public ArrayList policyLocators(PolicyIndexType indexType, + String text, + ArrayList,ArrayList>> filter_s, int connector) + throws IllegalStateException, IllegalArgumentException { + final ArrayList policyLocators = new ArrayList(); + + JestResult results = searchKey(indexType, text, filter_s,connector); + if (!results.isSucceeded()) { + return policyLocators; + } + + JsonArray jsonHit_s = null; + try { + JsonObject jsonHits = getJsonObject(results.getJsonObject(), "hits"); + jsonHit_s = getJsonArray(jsonHits, "hits"); + } catch (IllegalArgumentException e) { + logger.warn("SEARCH:" + text + " no valid element provided", e); + return policyLocators; + } + + for (JsonElement e : jsonHit_s) { + JsonObject elkSource = (JsonObject) e; + try { + String policyType = getJsonPolicyMember(elkSource,"PolicyType"); + String policyName = getJsonPolicyMember(elkSource,"PolicyName"); + String owner = getJsonPolicyMember(elkSource,"Owner"); + String scope = getJsonPolicyMember(elkSource,"Scope"); + String policyId = getJsonPolicyMember(elkSource,"PolicyId"); + String version = getJsonPolicyMember(elkSource,"Version"); + PolicyLocator policyLocator = + new PolicyLocator(policyType, policyName, owner, + scope, policyId, version); + policyLocators.add(policyLocator); + if (logger.isInfoEnabled()) { + logger.info("SEARCH:" + text + "|FOUND:" + policyLocator); + } + } catch (IllegalArgumentException ex) { + logger.warn("SEARCH:" + text + " missing locator information.", ex); + } + } + return policyLocators; + } + + public boolean put(String record, PolicyType type, String id) + throws IOException, IllegalStateException { + if (logger.isTraceEnabled()) logger.trace("ENTER"); + + PolicyIndexType indexType; + try { + indexType = ElkConnector.toPolicyIndexType(type); + } catch (IllegalArgumentException e) { + throw new IllegalStateException("ELK: Index: " + ELK_INDEX_POLICY + + " Type: " + type + " :" + e.getMessage()); + } + + if (indexType == PolicyIndexType.all) { + throw new IllegalStateException("ELK: Index: " + ELK_INDEX_POLICY + + " Bad Type: " + type.toString()); + } + + if (!isType(indexType)) { + throw new IllegalStateException("ELK: Index: " + ELK_INDEX_POLICY + + " Type: " + type.toString() + + " is not configured"); + } + + Index elkPut = new Index.Builder(record). + index(ELK_INDEX_POLICY). + type(indexType.name()). + id(id). + build(); + + JestResult result = jestClient.execute(elkPut); + + if (result.isSucceeded()) { + if (logger.isInfoEnabled()) + logger.info("OK: PUT operation of " + type.name() + "->" + indexType + ":" + id + ": " + + "success=" + result.isSucceeded() + "[" + result.getResponseCode() + ":" + + result.getPathToResult() + "]" + System.lineSeparator() + + result.getJsonString()); + } else { + if (logger.isWarnEnabled()) + logger.warn("FAILURE: PUT operation of " + type.name() + "->" + indexType + ":" + id + ": " + + "success=" + result.isSucceeded() + "[" + result.getResponseCode() + ":" + + result.getPathToResult() + "]" + System.lineSeparator() + + result.getJsonString()); + + } + + return result.isSucceeded(); + } + + @Override + public boolean clone(String origPolicyId, String clonePolicyId) + throws IllegalStateException { + if (logger.isTraceEnabled()) logger.trace("ENTER"); + + String methodLog = "[" + + "original-policy-id:" + origPolicyId + "|" + + "cloned-policy-id:" + clonePolicyId + "]"; + + if (logger.isDebugEnabled()) + logger.debug(methodLog); + + if (origPolicyId == null || clonePolicyId == null || + origPolicyId.isEmpty() || clonePolicyId.isEmpty()) { + logger.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR + ":" + + "Internal Error: original and cloned policy ids are identical: " + + origPolicyId + "->" + clonePolicyId + " :" + + methodLog); + throw new IllegalStateException(": " + "original and cloned policy ids are identical."); + } + + // GET original record + JestResult result = this.policy(origPolicyId); + if (!result.isSucceeded()) { + logger.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR + ":" + + "Internal Error: not found policy id: " + + origPolicyId + " :" + + methodLog); + throw new IllegalStateException(": " + "policy id: " + origPolicyId + " not found"); + } + + try { + String policyId = getJsonPolicyMember(result.getJsonObject(),"PolicyId"); + String policyType = getJsonPolicyMember(result.getJsonObject(),"PolicyType"); + if (policyType == null || policyType.isEmpty()) { + throw new IllegalStateException(": " + origPolicyId + + " invalid policy type: " + policyType); + } + PolicyType policyTypeEnum = PolicyType.valueOf(policyType); + String newPolicyId = policyId.replace(origPolicyId, clonePolicyId); + + JsonObject jsonSource = getJsonObject(result.getJsonObject(), "_source"); + JsonObject jsonPolicy = getJsonObject(jsonSource, "Policy"); + jsonPolicy.addProperty("PolicyId", newPolicyId); + String sourcePolicy = new Gson().toJson(jsonPolicy); + return put(sourcePolicy, policyTypeEnum, clonePolicyId); + } catch (IllegalArgumentException e) { + logger.warn("POLICY-SEARCH:" + origPolicyId + " not properly found", e); + throw new IllegalStateException(": " + origPolicyId + " not found in ELK"); + } catch (IOException e) { + logger.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR + ":" + + "cannot create searchable record for " + methodLog + + ". Reason: " + e.getMessage(), e); + throw new IllegalStateException(": Communication Problem with ELK server"); + } + } + + @Override + public boolean delete(File xacmlFile) throws IllegalStateException { + if (logger.isDebugEnabled()) + logger.debug("ENTER: " + "[xacml-file:" + + ((xacmlFile != null) ? xacmlFile.getPath() : "null")+ "]"); + + if (xacmlFile == null || !xacmlFile.canRead()) { + logger.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR + ":" + + "Internal Error: invalid arguments provided: " + + ((xacmlFile != null) ? xacmlFile.getPath() : "null")+ "]"); + throw new IllegalStateException(": " + "Invalid arguments to convert to ELK format."); + } + + String policyId = ""; + PolicyIndexType indexType = null; + JestResult result; + try { + indexType = ElkConnector.toPolicyIndexType(xacmlFile.getName()); + if (!isType(indexType)) { + throw new IllegalStateException("ELK: Index: " + ELK_INDEX_POLICY + + " Type: " + indexType + + " is not configured"); + } + Xacml2Elk searchablePolicy = new Xacml2Elk(xacmlFile, true); + policyId = searchablePolicy.getPolicy().getValue().getPolicyId(); + policyId = policyId.substring(policyId.lastIndexOf(":")+1); + Delete deleteRequest = + new Delete.Builder(policyId).index(ELK_INDEX_POLICY). + type(indexType.name()).build(); + result = jestClient.execute(deleteRequest); + } catch (IllegalArgumentException | IOException e) { + logger.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR + ": delete:" + + ((indexType != null) ? indexType.name() : "null") + ":" + policyId + ": " + + e.getMessage(), e); + throw new IllegalStateException(e); + } + + if (result.isSucceeded()) { + if (logger.isInfoEnabled()) + logger.info("OK: DELETE operation of " + indexType + ":" + policyId + ": " + + "success=" + result.isSucceeded() + "[" + result.getResponseCode() + ":" + + result.getPathToResult() + "]" + System.lineSeparator() + + result.getJsonString()); + } else { + if (logger.isWarnEnabled()) + logger.warn("FAILURE: DELETE operation of " + indexType + ":" + policyId + ": " + + "success=" + result.isSucceeded() + "[" + result.getResponseCode() + ":" + + result.getPathToResult() + "]" + System.lineSeparator() + + result.getJsonString()); + } + + return result.isSucceeded(); + } + + @Override + public ElkRecord create(PolicyType policyType, + String name, + String owner, + String scope, + File xacmlFile, + PolicyBodyType bodyType, + String body, + File destinationDir) + throws IllegalStateException { + if (logger.isTraceEnabled()) logger.trace("ENTER"); + + String methodLog = "[" + + "type:" + policyType.name() + "|" + + "owner:" + owner + "|" + + "scope:" + scope + "|" + + "xacml-file:" + ((xacmlFile != null) ? xacmlFile.getPath() : "null")+ "|" + + "body-type:" + bodyType.name() + "|" + + "body:" + body + "|" + + "destination-dir:" + ((destinationDir != null) ? destinationDir.getPath() : "null")+ "]"; + + if (logger.isDebugEnabled()) + logger.debug(methodLog); + + if (policyType == null || name == null || owner == null || scope == null || + xacmlFile == null) { + logger.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR + ":" + + "Internal Error: invalid arguments provided for " + methodLog); + throw new IllegalStateException(": " + "Invalid arguments to convert to ELK format."); + } + + try { + Xacml2Elk searchablePolicy = + new Xacml2Elk(policyType.name(), + name, + owner, + scope, + xacmlFile, + bodyType, + body, + destinationDir); + ElkRecord elkRecord = searchablePolicy.record(); + put(elkRecord.record, policyType, elkRecord.policyId); + return elkRecord; + } catch (JAXBException | JsonProcessingException | IllegalArgumentException e) { + logger.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR + ":" + + "cannot create searchable record for " + methodLog + + ". Reason: " + e.getMessage(), e); + throw new IllegalStateException(": " + "Error encountered converting to ELK format."); + } catch (IOException e) { + logger.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR + ":" + + "cannot create searchable record for " + methodLog + + ". Reason: " + e.getMessage(), e); + throw new IllegalStateException(": " + "Communication Problem with ELK server."); + } + } + + @Override + public boolean update(File xacmlFile) throws IllegalStateException { + if (logger.isDebugEnabled()) + logger.debug("ENTER: " + "[xacml-file:" + + ((xacmlFile != null) ? xacmlFile.getPath() : "null")+ "]"); + + if (xacmlFile == null || !xacmlFile.canRead()) { + logger.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR + ":" + + "Internal Error: invalid arguments provided: " + + ((xacmlFile != null) ? xacmlFile.getPath() : "null")+ "]"); + throw new IllegalStateException(": " + "Invalid arguments to convert to ELK format."); + } + + Xacml2Elk searchablePolicy = new Xacml2Elk(xacmlFile, false); + return update(xacmlFile, searchablePolicy); + } + + protected boolean update(File xacmlFile, Xacml2Elk searchablePolicy) throws IllegalStateException { + if (logger.isDebugEnabled()) + logger.debug("ENTER"); + + try { + ElkRecord elkRecord = searchablePolicy.record(); + boolean success = put(elkRecord.record, ElkConnector.toPolicyType(xacmlFile.getName()), elkRecord.policyId); + return success; + } catch (JAXBException | JsonProcessingException | IllegalArgumentException e) { + logger.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR + ":" + + "cannot create searchable record for " + xacmlFile.getAbsolutePath() + + ". Reason: " + e.getMessage(), e); + throw new IllegalStateException(": " + "Error encountered converting to ELK format for " + + xacmlFile.getAbsolutePath()); + } catch (IOException e) { + logger.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR + ":" + + "cannot create ELK searchable record for " + xacmlFile.getAbsolutePath() + + ". Reason: " + e.getMessage(), e); + throw new IllegalStateException(": " + "Communication Problem with ELK server."); + } catch (IllegalStateException e) { + /* unexpected */ + throw e; + } catch (Exception e) { + logger.warn(XACMLErrorConstants.ERROR_UNKNOWN + ":" + "cannot test and update", e); + throw new IllegalStateException(e); + } + } + + @Override + public boolean testAndUpdate(File xacmlFile) throws IllegalStateException { + if (logger.isDebugEnabled()) + logger.debug("ENTER: " + "[xacml-file:" + + ((xacmlFile != null) ? xacmlFile.getPath() : "null")+ "]"); + + if (xacmlFile == null || !xacmlFile.canRead()) { + logger.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR + ":" + + "Internal Error: invalid arguments provided: " + + ((xacmlFile != null) ? xacmlFile.getPath() : "null")+ "]"); + throw new IllegalStateException(": " + "Invalid arguments to convert to ELK format."); + } + + try { + Xacml2Elk searchablePolicy = new Xacml2Elk(xacmlFile, true); + String policyId = searchablePolicy.getPolicy().getValue().getPolicyId(); + policyId = policyId.substring(policyId.lastIndexOf(":")+1); + JestResult result = this.policy(policyId); + if (result.isSucceeded()) { + logger.info("Policy exists: " + policyId); + + /* validation tests */ + + String policyType = getJsonPolicyMember(result.getJsonObject(), "PolicyType"); + String scope = getJsonPolicyMember(result.getJsonObject(), "Scope"); + String policyName = getJsonPolicyMember(result.getJsonObject(), "PolicyName"); + if (policyType == null || policyType.isEmpty() || + scope == null || scope.isEmpty() || + policyName == null || policyName.isEmpty()) { + logger.warn("Policy metadata not found. Updating record .."); + update(xacmlFile, searchablePolicy); + return false; + } + + if (!xacmlFile.getName().startsWith(policyType)) { + logger.warn(xacmlFile.getName() + " does not match Policy Type: " + + policyType); + update(xacmlFile, searchablePolicy); + return false; + } + + java.nio.file.Path xacmlElkPath = Paths.get(scope, policyType + "_" + policyName + ".xml"); + java.nio.file.Path xacmlPath = xacmlFile.toPath(); + + if (logger.isDebugEnabled()) { + logger.debug(xacmlElkPath + " in " + xacmlElkPath + "? "); + } + + if (!xacmlPath.endsWith(xacmlElkPath)) { + logger.warn(xacmlPath + " does not match ELK inferred path: " + + xacmlElkPath); + update(xacmlFile, searchablePolicy); + return false; + } + + if (logger.isInfoEnabled()) { + logger.warn("OK: " + xacmlPath + " matches ELK inferred path: " + + xacmlElkPath); + } + return true; + } else { + logger.info("Policy ID not found. Adding to database: " + policyId); + update(xacmlFile, searchablePolicy); + return false; + } + } catch (Exception e) { + logger.warn(XACMLErrorConstants.ERROR_UNKNOWN + ":" + "cannot test and update", e); + throw new IllegalStateException(e); + } + } +} \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/elk/client/Pair.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/elk/client/Pair.java new file mode 100644 index 000000000..3c7b9951d --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/elk/client/Pair.java @@ -0,0 +1,35 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.elk.client; + + +public class Pair { + private L left; + private R right; + public Pair(L l, R r){ + this.left = l; + this.right = r; + } + public L left(){ return left; } + public R right(){ return right; } + public void left(L l){ this.left = l; } + public void right(R r){ this.right = r; } +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/elk/client/PolicyElasticSearchController.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/elk/client/PolicyElasticSearchController.java new file mode 100644 index 000000000..ee745236f --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/elk/client/PolicyElasticSearchController.java @@ -0,0 +1,756 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.elk.client; + + +import java.io.File; +import java.io.PrintWriter; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.regex.Pattern; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.json.JSONObject; +import org.openecomp.policy.adapter.ClosedLoopPerformanceMetrics; +import org.openecomp.policy.adapter.ClosedLoopPolicy; +import org.openecomp.policy.dao.PolicyVersionDao; +import org.openecomp.policy.elk.client.ElkConnector.PolicyIndexType; +import org.openecomp.policy.rest.dao.DescriptiveScopeDao; +import org.openecomp.policy.rest.jpa.ActionPolicyDict; +import org.openecomp.policy.rest.jpa.Attribute; +import org.openecomp.policy.rest.jpa.BRMSParamTemplate; +import org.openecomp.policy.rest.jpa.ClosedLoopD2Services; +import org.openecomp.policy.rest.jpa.ClosedLoopSite; +import org.openecomp.policy.rest.jpa.DCAEuuid; +import org.openecomp.policy.rest.jpa.DecisionSettings; +import org.openecomp.policy.rest.jpa.DescriptiveScope; +import org.openecomp.policy.rest.jpa.EcompName; +import org.openecomp.policy.rest.jpa.EnforcingType; +import org.openecomp.policy.rest.jpa.GroupPolicyScopeList; +import org.openecomp.policy.rest.jpa.MicroServiceLocation; +import org.openecomp.policy.rest.jpa.MicroServiceModels; +import org.openecomp.policy.rest.jpa.PEPOptions; +import org.openecomp.policy.rest.jpa.PolicyVersion; +import org.openecomp.policy.rest.jpa.RiskType; +import org.openecomp.policy.rest.jpa.SafePolicyWarning; +import org.openecomp.policy.rest.jpa.TermList; +import org.openecomp.policy.rest.jpa.VNFType; +import org.openecomp.policy.rest.jpa.VSCLAction; +import org.openecomp.policy.rest.jpa.VarbindDictionary; +import org.openecomp.portalsdk.core.controller.RestrictedBaseController; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +@Controller +@RequestMapping({"/"}) +public class PolicyElasticSearchController extends RestrictedBaseController{ + + private static final Logger logger = FlexLogger.getLogger(PolicyElasticSearchController.class); + private volatile HashMap filteredPolicies = new HashMap(); + private List policyNames = null; + + enum Mode{ + attribute, ecompName, actionPolicy, brmsParam, pepOptions, clSite, clService, clVarbind, clVnf, clVSCL, decision, enforcer, fwTerm, gocEventAlarm, + gocTraversal, gocRootCause, gocVnfType, gocServerScope, gocHPEventSource, msDCAEUUID, msConfigName, msLocation, msModels, + psGroupPolicy, safeRisk, safePolicyWarning + } + + public static final HashMap name2jsonPath = new HashMap() { + private static final long serialVersionUID = 1L; + { + put(ClosedLoopPolicy.CLFAULT_UIFIELD_D2_SERVICES_TRINITY, ClosedLoopPolicy.CLFAULT_UIJSON_D2_SERVICES_TRINITY); + put(ClosedLoopPolicy.CLFAULT_UIFIELD_D2_SERVICES_VUSP, ClosedLoopPolicy.CLFAULT_UIJSON_D2_SERVICES_VUSP); + put(ClosedLoopPolicy.CLFAULT_UIFIELD_D2_SERVICES_MCR, ClosedLoopPolicy.CLFAULT_UIJSON_D2_SERVICES_MCR); + put(ClosedLoopPolicy.CLFAULT_UIFIELD_D2_SERVICES_GAMMA, ClosedLoopPolicy.CLFAULT_UIJSON_D2_SERVICES_GAMMA); + put(ClosedLoopPolicy.CLFAULT_UIFIELD_D2_SERVICES_VDNS, ClosedLoopPolicy.CLFAULT_UIJSON_D2_SERVICES_VDNS); + + put(ClosedLoopPolicy.CLFAULT_UIFIELD_EMAIL_ADDRESS, ClosedLoopPolicy.CLFAULT_UIJSON_EMAIL_ADDRESS); + put(ClosedLoopPolicy.CLFAULT_UIFIELD_TRIGGER_SIGNATURE, ClosedLoopPolicy.CLFAULT_UIJSON_TRIGGER_SIGNATURE); + put(ClosedLoopPolicy.CLFAULT_UIFIELD_VERIFICATION_SIGNATURE, ClosedLoopPolicy.CLFAULT_UIJSON_VERIFICATION_SIGNATURE); + put(ClosedLoopPolicy.CLFAULT_UIFIELD_CONNECT_ALL_TRAPS, ClosedLoopPolicy.CLFAULT_UIJSON_CONNECT_ALL_TRAPS); + put(ClosedLoopPolicy.CLFAULT_UIFIELD_CONNECT_ALL_FAULTS, ClosedLoopPolicy.CLFAULT_UIJSON_CONNECT_ALL_FAULTS); + + put(ClosedLoopPolicy.CLFAULT_UIFIELD_POLICY_STATUS_INACTIVE, ClosedLoopPolicy.CLFAULT_UIJSON_POLICY_STATUS_ACTIVE); + put(ClosedLoopPolicy.CLFAULT_UIFIELD_POLICY_STATUS_ACTIVE, ClosedLoopPolicy.CLFAULT_UIJSON_POLICY_STATUS_INACTIVE); + + put(ClosedLoopPerformanceMetrics.CLPM_UIFIELD_ONSET_MESSAGE, ClosedLoopPerformanceMetrics.CLPM_UIJSON_ONSET_MESSAGE); + put(ClosedLoopPerformanceMetrics.CLPM_UIFIELD_POLICY_NAME, ClosedLoopPerformanceMetrics.CLPM_UIJSON_POLICY_NAME); + put(ClosedLoopPerformanceMetrics.CLPM_UIFIELD_ABATEMENT_MESSAGE, ClosedLoopPerformanceMetrics.CLPM_UIJSON_ABATEMENT_MESSAGE); + put(ClosedLoopPerformanceMetrics.CLPM_UIFIELD_GEOLINK, ClosedLoopPerformanceMetrics.CLPM_UIJSON_GEOLINK); + }}; + + + //For AND and OR logical connector AND=0 and OR=1 + private int connectorSelected; + + public static DescriptiveScopeDao descriptiveScopeDao; + public static PolicyVersionDao policyVersionDao; + + @Autowired + public PolicyElasticSearchController(DescriptiveScopeDao descriptiveScopeDao, PolicyVersionDao policyVersionDao) { + PolicyElasticSearchController.descriptiveScopeDao = descriptiveScopeDao; + PolicyElasticSearchController.policyVersionDao = policyVersionDao; + + } + + public PolicyElasticSearchController() { + } + + @RequestMapping(value={"/searchPolicy"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView searchPolicy(HttpServletRequest request, HttpServletResponse response) throws Exception{ + List resultList = new ArrayList(); + try { + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + SearchData searchData = (SearchData)mapper.readValue(root.get("searchdata").toString(), SearchData.class); + + String policyType = searchData.getPolicyType(); + ArrayList,ArrayList>> filter_s = new ArrayList,ArrayList>>(); + + String searchText = searchData.getQuery(); + if (searchText == null || searchText.isEmpty()) { + String descriptiveValue = searchData.getDescriptiveScope(); + if(descriptiveValue != null){ + searchText = "Descriptive-Scope="+descriptiveValue; + } + if (policyType == null || policyType.isEmpty() && + !policyType.equals(ElkConnector.PolicyIndexType.closedloop.toString())) { + if (logger.isDebugEnabled()) { + logger.debug("Clearing search filters, nothing to search and not closed loop."); + } + } + } else { + searchText = searchText.trim(); + //Descriptive Scope. + /* + When a item is selected in the "descriptiveScope" comboBox, the name of the item + is added to the Search-Text Box with the prefix "Descriptive-Scope" + User needs to press the "Search" button to perform the search. + */ + if(searchText.contains("Descriptive-Scope=")){ + if (logger.isDebugEnabled()) { + logger.debug("Inside the Descriptive Scope"); + } + /* + First item is always String "Descriptive-Scope" before the "=", + So taking the second item of "split using =" + */ + String[] dsName= searchText.split("=",2); + /* + Trying to find the search String by traversing different items from the dictionary by Scope-Name + Once when the the "scope-name" is found, we get the search string from dictionary. + */ + if(searchData.getDescriptiveScope() != null){ + DescriptiveScope dsSearch = descriptiveScopeDao.getDescriptiveScopeById(searchData.getDescriptiveScope()); + if(dsSearch.getScopeName().equals(dsName[1])){ + searchText=dsSearch.getSearch(); + if (logger.isDebugEnabled()) { + logger.debug("DescriptiveScope Search String is " +searchText ); + } + } + } + + } + // '&' turned to "AND" to make it inline with Freeform search. + if(searchText.contains(":")){ + String connector="AND"; + if(searchText.contains("AND")){ + connector="AND"; + connectorSelected=0; + }else if(searchText.contains("OR")){ + connector=Pattern.quote("OR"); + connectorSelected=1; + } + for (String retval: searchText.split(connector)){ + + int index= retval.indexOf(':'); + String filterKey=null; + String filterValue=null; + + filterKey=retval.substring(0,index).trim(); + filterValue= retval.substring(index+1).trim(); + + logger.debug("Key is "+filterKey+" and value is "+filterValue); + String clSearchBoxFilter=filterKey; + + ArrayList clSearchBoxFilterField_s = new ArrayList(); + + clSearchBoxFilterField_s.add("Policy.Body." + ElkConnector.PolicyType.Config_Fault.name() + "_Body." + clSearchBoxFilter); + clSearchBoxFilterField_s.add("Policy.Body." + ElkConnector.PolicyType.Config_PM.name() + "_Body." + clSearchBoxFilter); + clSearchBoxFilterField_s.add("Policy.Body." + ElkConnector.PolicyType.Config_FW.name() + "_Body." + clSearchBoxFilter); + clSearchBoxFilterField_s.add("Policy.Body." + ElkConnector.PolicyType.Config_MS.name() + "_Body." + clSearchBoxFilter); + + + ArrayList clSearchBoxFilterValue_s = new ArrayList(); + clSearchBoxFilterValue_s.add(filterValue); + + filter_s.add(new Pair,ArrayList>(clSearchBoxFilterField_s, clSearchBoxFilterValue_s)); + } + } + } + + if (policyType != null && !policyType.isEmpty() && + policyType.equals(ElkConnector.PolicyIndexType.closedloop.toString())) { + + /* closed loop policy type */ + + String clPolicyType = searchData.getClosedLooppolicyType(); + if (clPolicyType != null && !clPolicyType.isEmpty()) { + ArrayList clPolicyTypeField_s = new ArrayList(); + clPolicyTypeField_s.add("Policy.PolicyType"); + + ArrayList clPolicyTypeValue_s = new ArrayList(); + clPolicyTypeValue_s.add(clPolicyType); + + filter_s.add(new Pair,ArrayList>(clPolicyTypeField_s, clPolicyTypeValue_s)); + } + + String clEcompName = searchData.getEcompName(); + if (clEcompName != null && !clEcompName.isEmpty()) { + clSearchBody(clPolicyType, "ecompname", clEcompName, filter_s); + } + + String clD2Services = searchData.getD2Service(); + if (clD2Services != null && !clD2Services.isEmpty()) { + switch (clD2Services) { + case ClosedLoopPolicy.CLFAULT_UIFIELD_D2_SERVICES_TRINITY: + case ClosedLoopPolicy.CLFAULT_UIFIELD_D2_SERVICES_VUSP: + case ClosedLoopPolicy.CLFAULT_UIFIELD_D2_SERVICES_MCR: + case ClosedLoopPolicy.CLFAULT_UIFIELD_D2_SERVICES_GAMMA: + case ClosedLoopPolicy.CLFAULT_UIFIELD_D2_SERVICES_VDNS: + clSearchBody(clPolicyType, name2jsonPath.get(clD2Services), "true", filter_s); + break; + default: + if (logger.isWarnEnabled()) + logger.warn("Unexpected D2 Service: " + clD2Services); + break; + } + } + + String clFaultAction = searchData.getVproAction(); + if (clFaultAction != null && !clFaultAction.isEmpty()) { + if (clPolicyType == null || clPolicyType.equals(ElkConnector.PolicyType.Config_Fault.name())) { + clSearchFilter(ElkConnector.PolicyType.Config_Fault.name(), "actions", clFaultAction, filter_s); + } + } + + String clFaultStatus = searchData.getPolicyStatus(); + if (clFaultStatus != null && !clFaultStatus.isEmpty()) { + if (clPolicyType == null || clPolicyType.equals(ElkConnector.PolicyType.Config_Fault.name())) { + clSearchFilter(ElkConnector.PolicyType.Config_Fault.name(), "closedLoopPolicyStatus", clFaultStatus, filter_s); + } + } + + String clFaultVnfTypes = searchData.getVnfType(); + if (clFaultVnfTypes != null && !clFaultVnfTypes.isEmpty()) { + if (clPolicyType == null || clPolicyType.equals(ElkConnector.PolicyType.Config_Fault.name())) { + clSearchFilter(ElkConnector.PolicyType.Config_Fault.name(), "vnfType", clFaultVnfTypes, filter_s); + } + } + + String clPMServiceType = searchData.getServiceType(); + if (clPMServiceType != null && !clPMServiceType.isEmpty()) { + if (clPolicyType == null || clPolicyType.equals(ElkConnector.PolicyType.Config_PM.name())) { + clSearchFilter(ElkConnector.PolicyType.Config_PM.name(), "serviceTypePolicyName", clPMServiceType, filter_s); + } + } + + String clSearchBoxFilter = searchData.getBindTextSearch(); + if (clSearchBoxFilter != null && !clSearchBoxFilter.isEmpty() && + searchText != null && !searchText.isEmpty()) { + + if (name2jsonPath.containsKey(clSearchBoxFilter)) { + clSearchBoxFilter = name2jsonPath.get(clSearchBoxFilter); + } + + ArrayList clSearchBoxFilterField_s = new ArrayList(); + if (clPolicyType == null || clPolicyType.isEmpty()) { + clSearchBoxFilterField_s.add("Policy.Body." + ElkConnector.PolicyType.Config_Fault.name() + "_Body." + clSearchBoxFilter); + clSearchBoxFilterField_s.add("Policy.Body." + ElkConnector.PolicyType.Config_PM.name() + "_Body." + clSearchBoxFilter); + } else { + clSearchBoxFilterField_s.add("Policy.Body." + clPolicyType + "_Body." + clSearchBoxFilter); + } + + ArrayList clSearchBoxFilterValue_s = new ArrayList(); + clSearchBoxFilterValue_s.add(searchText); + + filter_s.add(new Pair,ArrayList>(clSearchBoxFilterField_s, clSearchBoxFilterValue_s)); + + // deactivate search all fields in case a searchbox filter is provided + searchText = ""; + } + } + + if ((searchText == null || searchText.isEmpty()) && + (filter_s == null || filter_s.size() <=0) ) { + if (logger.isWarnEnabled()) { + logger.warn("Clearing search filters, closed loop but nothing to search nor filters"); + } + } + + ArrayList locators = null; + try { + locators = ElkConnector.singleton.policyLocators(toPolicyIndexType(policyType), + searchText, filter_s,connectorSelected); + } catch (Exception ise) { + logger.warn("Search is unavailable: " + ise.getMessage()); + } + + synchronized(this.filteredPolicies) { + if (locators.isEmpty()) { + if (logger.isInfoEnabled()) { + logger.info("No match has been found"); + } + logger.warn("No match has been found"); + } + + HashMap policyVersion_s = new HashMap(); + List policyVersionList = policyVersionDao.getPolicyVersionData(); + for(int i = 0; i < policyVersionList.size(); i++) { + PolicyVersion entityVersion = policyVersionList.get(i); + String dbPolicy = entityVersion.getPolicyName() + "." + entityVersion.getActiveVersion(); + policyVersion_s.put(dbPolicy, true); + if (logger.isDebugEnabled()) + logger.debug("Map addition: DB Policy Name: " + dbPolicy); + } + + this.filteredPolicies.clear(); + for (PolicyLocator p: locators) { + String dbPolicyName = p.scope + File.separator + p.policyType + "_" + p.policyName; + if (policyVersion_s.containsKey(dbPolicyName)) { + String filterPolicyName = dbPolicyName + ".xml"; + this.filteredPolicies.put(Paths.get(filterPolicyName), filterPolicyName); + JSONObject el = new JSONObject(); + el.put("name", dbPolicyName); + resultList.add(el); + if (logger.isInfoEnabled()) + logger.info("Active Version Policy found in search: " + dbPolicyName + " -> " + filterPolicyName); + } else { + if (logger.isInfoEnabled()) + logger.info("Inactive Version Policy found in search: " + dbPolicyName); + } + } + + if (this.filteredPolicies.isEmpty()) { + if (logger.isInfoEnabled()) { + logger.info("No match has been found for active versions"); + } + JSONObject result = new JSONObject(); + result.put("success", false); + result.put("error", "No match has been found for active versions"); + resultList.add(result); + logger.warn("No match has been found for active versions"); + + } + + System.out.println(this.filteredPolicies); + } + + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + JSONObject j = new JSONObject("{result: " + resultList + "}"); + out.write(j.toString()); + return null; + }catch(Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + protected void clSearchBody(String clPolicyType, String bodyField, String bodyValue, + ArrayList, ArrayList>> filter_s) { + if (logger.isDebugEnabled()) + logger.debug("ENTER: " + clPolicyType + ":" + bodyField + ":" + bodyValue); + + final ArrayList clBodyField_s = new ArrayList(); + final ArrayList clBodyValue_s = new ArrayList(); + + if (clPolicyType == null || clPolicyType.isEmpty()) { + clBodyField_s.add("Policy.Body." + ElkConnector.PolicyType.Config_Fault.name() + "_Body." + bodyField); + clBodyField_s.add("Policy.Body."+ ElkConnector.PolicyType.Config_PM.name() + "_Body." + bodyField); + clBodyValue_s.add(bodyValue); + } else { + clBodyField_s.add("Policy.Body." + clPolicyType + "_Body." + bodyField); + clBodyValue_s.add(bodyValue); + } + filter_s.add(new Pair, ArrayList>(clBodyField_s, clBodyValue_s)); + } + + protected void clSearchFilter(String clType, String clField, String clValue, + ArrayList,ArrayList>> filter_s) { + if (logger.isDebugEnabled()) + logger.debug("ENTER: " + clType + ":" + clField + ":" + clValue); + + ArrayList clSearchField_s = new ArrayList(); + clSearchField_s.add("Policy.Body." + clType + "_Body." + clField); + + ArrayList clSearchValue_s = new ArrayList(); + clSearchValue_s.add(clValue); + + filter_s.add(new Pair,ArrayList>(clSearchField_s, clSearchValue_s)); + } + + public ElkConnector.PolicyIndexType toPolicyIndexType(String type) throws IllegalArgumentException { + if (type == null || type.isEmpty()) + return PolicyIndexType.all; + + return PolicyIndexType.valueOf(type); + } + + public boolean updateElk(String xacmlFilePath) { + boolean success = true; + try { + File xacmlPolicy = new File(xacmlFilePath); + success = ElkConnector.singleton.update(xacmlPolicy); + if (!success) { + if (logger.isWarnEnabled()) { + logger.warn("FAILURE to create ELK record created for " + xacmlPolicy.getPath()); + } + } else { + if (logger.isInfoEnabled()) { + logger.warn("SUCCESS creating ELK record created for " + xacmlPolicy.getPath()); + } + } + } catch (Exception e) { + logger.warn(XACMLErrorConstants.ERROR_DATA_ISSUE + ": " + e.getMessage(), e); + success = false; + } + return success; + } + + @RequestMapping(value={"/searchDictionary"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) + public ModelAndView searchDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{ + try{ + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + String dictionaryType = root.get("type").textValue(); + Mode mode = Mode.valueOf(dictionaryType); + String value; + String msg; + switch (mode){ + case attribute : + Attribute attributedata = (Attribute)mapper.readValue(root.get("data").toString(), Attribute.class); + value = attributedata.getXacmlId(); + msg = searchElkDatabase("pholder",value); + break; + case ecompName : + EcompName ecompName = (EcompName)mapper.readValue(root.get("data").toString(), EcompName.class); + value = ecompName.getEcompName(); + msg = searchElkDatabase("pholder",value); + break; + case actionPolicy : + ActionPolicyDict actionPolicyDict = (ActionPolicyDict)mapper.readValue(root.get("data").toString(), ActionPolicyDict.class); + value = actionPolicyDict.getAttributeName(); + msg = searchElkDatabase("pholder",value); + break; + case brmsParam : + BRMSParamTemplate bRMSParamTemplate = (BRMSParamTemplate)mapper.readValue(root.get("data").toString(), BRMSParamTemplate.class); + value = bRMSParamTemplate.getRuleName(); + msg = searchElkDatabase("BRMSParamTemplate AND " + value); + break; + case pepOptions : + PEPOptions pEPOptions = (PEPOptions)mapper.readValue(root.get("data").toString(), PEPOptions.class); + value = pEPOptions.getPepName(); + msg = searchElkDatabase("pepName",value); + break; + case clSite : + ClosedLoopSite closedLoopSite = (ClosedLoopSite)mapper.readValue(root.get("data").toString(), ClosedLoopSite.class); + value = closedLoopSite.getSiteName(); + msg = searchElkDatabase("siteNames",value); + break; + case clService : + ClosedLoopD2Services closedLoopD2Services = (ClosedLoopD2Services)mapper.readValue(root.get("data").toString(), ClosedLoopD2Services.class); + value = closedLoopD2Services.getServiceName(); + msg = searchElkDatabase("d2Services",value); + break; + case clVarbind : + VarbindDictionary varbindDictionary = (VarbindDictionary)mapper.readValue(root.get("data").toString(), VarbindDictionary.class); + value = varbindDictionary.getVarbindName(); + msg = searchElkDatabase("triggerSignaturesUsedForUI.signatures",value); + break; + case clVnf : + VNFType vNFType = (VNFType)mapper.readValue(root.get("data").toString(), VNFType.class); + value = vNFType.getVnftype(); + msg = searchElkDatabase("vnfType",value); + break; + case clVSCL : + VSCLAction vsclAction = (VSCLAction)mapper.readValue(root.get("data").toString(), VSCLAction.class); + value = vsclAction.getVsclaction(); + msg = searchElkDatabase("actions",value); + break; + case decision : + DecisionSettings decisionSettings = (DecisionSettings)mapper.readValue(root.get("data").toString(), DecisionSettings.class); + value = decisionSettings.getXacmlId(); + msg = searchElkDatabase("pholder",value); + break; + case enforcer : + EnforcingType enforcingType = (EnforcingType)mapper.readValue(root.get("data").toString(), EnforcingType.class); + value = enforcingType.getEnforcingType(); + msg = searchElkDatabase("pholder",value); + break; + case fwTerm : + TermList term = (TermList)mapper.readValue(root.get("data").toString(), TermList.class); + value = term.getTermName(); + msg = searchElkDatabase("firewallRuleList.ruleName",value); + break; + case msDCAEUUID : + DCAEuuid dcaeUUID = (DCAEuuid)mapper.readValue(root.get("data").toString(), DCAEuuid.class); + value = dcaeUUID.getName(); + msg = searchElkDatabase("uuid",value); + break; + case msLocation : + MicroServiceLocation mslocation = (MicroServiceLocation)mapper.readValue(root.get("data").toString(), MicroServiceLocation.class); + value = mslocation.getName(); + msg = searchElkDatabase("location",value); + break; + case msModels : + MicroServiceModels msModels = (MicroServiceModels)mapper.readValue(root.get("data").toString(), MicroServiceModels.class); + value = msModels.getModelName(); + msg = searchElkDatabase("configName",value); + break; + case psGroupPolicy : + GroupPolicyScopeList groupPoilicy = (GroupPolicyScopeList)mapper.readValue(root.get("data").toString(), GroupPolicyScopeList.class); + value = groupPoilicy.getGroupName(); + msg = searchElkDatabase("PolicyScope",value); + break; + case safeRisk : + RiskType riskType= (RiskType)mapper.readValue(root.get("data").toString(), RiskType.class); + value = riskType.getRiskName(); + msg = searchElkDatabase("Risk Type",value); + break; + case safePolicyWarning : + SafePolicyWarning safePolicy = (SafePolicyWarning)mapper.readValue(root.get("data").toString(), SafePolicyWarning.class); + value = safePolicy.getName(); + msg = searchElkDatabase("Safe Warning",value); + break; + default: + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + JSONObject j = new JSONObject("{result: " + policyNames + "}"); + out.write(j.toString()); + return null; + }catch(Exception e){ + response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding("UTF-8"); + PrintWriter out = response.getWriter(); + out.write(e.getMessage()); + } + return null; + } + + //Search Elk database + public String searchElkDatabase(String value){ + String policyType = ""; + String searchText = value; + ArrayList locators; + ArrayList,ArrayList>> filter_s = new ArrayList,ArrayList>>(); + try { + locators = ElkConnector.singleton.policyLocators(toPolicyIndexType(policyType), searchText, filter_s,0); + } catch (Exception ise) { + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR+"Search is unavailable: " + ise.getMessage()); + value = "$notSuccess%"; + return value; + } + policyNames = new ArrayList(); + for (PolicyLocator p: locators) { + String dbPolicyName = p.scope + "/" + p.policyType + "_" + p.policyName + "." +p.version + ".xml"; + logger.debug(dbPolicyName); + JSONObject el = new JSONObject(); + el.put("name", dbPolicyName); + policyNames.add(el); + } + if(!locators.isEmpty()){ + value = "$success%"; + return value; + } + return value; + } + + //Search the Elk database + public String searchElkDatabase(String key, String value){ + String policyType = ""; + String searchText = key+":"+value; + ArrayList locators; + ArrayList,ArrayList>> filter_s = new ArrayList,ArrayList>>(); + logger.debug("Parameter value is"+value); + + String clSearchKey=null; + clSearchKey=key; + + logger.debug("Filter value is"+clSearchKey); + + ArrayList clSearchBoxFilterField_s = new ArrayList(); + + clSearchBoxFilterField_s.add("Policy.Body." + ElkConnector.PolicyType.Config_Fault.name() + "_Body." + clSearchKey); + clSearchBoxFilterField_s.add("Policy.Body." + ElkConnector.PolicyType.Config_PM.name() + "_Body." + clSearchKey); + clSearchBoxFilterField_s.add("Policy.Body." + ElkConnector.PolicyType.Config_FW.name() + "_Body." + clSearchKey); + clSearchBoxFilterField_s.add("Policy.Body." + ElkConnector.PolicyType.Config_MS.name() + "_Body." + clSearchKey); + //clSearchBoxFilterField_s.add("Policy.Body." + ElkConnector.PolicyType.Config_PM.name() + "_Body." + clSearchKey); + + String clSearchValue=null; + clSearchValue=value; + + logger.debug("Search value is"+clSearchValue); + + ArrayList clSearchBoxFilterValue_s = new ArrayList(); + clSearchBoxFilterValue_s.add(clSearchValue); + + filter_s.add(new Pair,ArrayList>(clSearchBoxFilterField_s, clSearchBoxFilterValue_s)); + + try { + locators = ElkConnector.singleton.policyLocators(toPolicyIndexType(policyType), searchText, filter_s,0); + logger.debug("No Exceptions"); + for (PolicyLocator l: locators) { + logger.debug(l.policyName); + } + logger.debug("After for"); + } catch (Exception ise) { + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR+"Search is unavailable: " + ise.getMessage()); + //PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, ise, "AttributeDictionary", " Exception while searching Elk database "); + logger.debug("Exceptions"); + value = "$notSuccess%"; + return value; + } + policyNames = new ArrayList(); + for (PolicyLocator p: locators) { + String dbPolicyName = p.scope + File.separator + p.policyType + "_" + p.policyName + ".xml"; + logger.debug(dbPolicyName); + JSONObject el = new JSONObject(); + el.put("name", dbPolicyName); + policyNames.add(el); + } + if(!locators.isEmpty()){ + value = "$success%"; + logger.debug("Success"); + return value; + } + return value; + } + +} + + +class SearchData{ + private String query; + private String policyType; + private String descriptiveScope; + private String closedLooppolicyType; + private String ecompName; + private String d2Service; + private String vnfType; + private String policyStatus; + private String vproAction; + private String serviceType; + private String bindTextSearch; + public String getQuery() { + return query; + } + public void setQuery(String query) { + this.query = query; + } + public String getPolicyType() { + return policyType; + } + public void setPolicyType(String policyType) { + this.policyType = policyType; + } + public String getDescriptiveScope() { + return descriptiveScope; + } + public void setDescriptiveScope(String descriptiveScope) { + this.descriptiveScope = descriptiveScope; + } + public String getClosedLooppolicyType() { + return closedLooppolicyType; + } + public void setClosedLooppolicyType(String closedLooppolicyType) { + this.closedLooppolicyType = closedLooppolicyType; + } + public String getEcompName() { + return ecompName; + } + public void setEcompName(String ecompName) { + this.ecompName = ecompName; + } + public String getD2Service() { + return d2Service; + } + public void setD2Service(String d2Service) { + this.d2Service = d2Service; + } + public String getVnfType() { + return vnfType; + } + public void setVnfType(String vnfType) { + this.vnfType = vnfType; + } + public String getPolicyStatus() { + return policyStatus; + } + public void setPolicyStatus(String policyStatus) { + this.policyStatus = policyStatus; + } + public String getVproAction() { + return vproAction; + } + public void setVproAction(String vproAction) { + this.vproAction = vproAction; + } + public String getServiceType() { + return serviceType; + } + public void setServiceType(String serviceType) { + this.serviceType = serviceType; + } + public String getBindTextSearch() { + return bindTextSearch; + } + public void setBindTextSearch(String bindTextSearch) { + this.bindTextSearch = bindTextSearch; + } +} \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/elk/client/PolicyLocator.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/elk/client/PolicyLocator.java new file mode 100644 index 000000000..f7cc58fa2 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/elk/client/PolicyLocator.java @@ -0,0 +1,53 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.elk.client; + + +public class PolicyLocator { + public final String policyType; + public final String policyName; + public final String owner; + public final String scope; + public final String policyId; + public final String version; + + public PolicyLocator(String policyType, String policyName, + String owner, String scope, String policyId, + String version) { + this.policyType = policyType; + this.policyName= policyName; + this.owner = owner; + this.scope = scope; + this.policyId = policyId; + this.version = version; + } + + public String toString() { + return "[" + + this.owner + "|" + + this.scope + "|" + + this.policyType + "|" + + this.policyName + "|" + + this.policyId + "|" + + "v" + this.version + "|" + "]"; + + } +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/elk/converter/ElkRecord.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/elk/converter/ElkRecord.java new file mode 100644 index 000000000..40bdb7929 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/elk/converter/ElkRecord.java @@ -0,0 +1,42 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.elk.converter; + + +import com.fasterxml.jackson.databind.JsonNode; + +public class ElkRecord { + public final String record; + public final String policyId; + public final JsonNode jsonRecord; + public final boolean bodyAttached; + + public ElkRecord(final String policyId, + final String record, + final JsonNode jsonRecord, + final boolean bodyAttached) { + this.policyId = policyId; + this.record = record; + this.jsonRecord = jsonRecord; + this.bodyAttached = bodyAttached; + } + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/elk/converter/Xacml2Elk.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/elk/converter/Xacml2Elk.java new file mode 100644 index 000000000..f7aa34ff2 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/elk/converter/Xacml2Elk.java @@ -0,0 +1,978 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.elk.converter; + + +import io.searchbox.core.Update; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.StringReader; +import java.io.StringWriter; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBElement; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Marshaller; +import javax.xml.bind.Unmarshaller; +import javax.xml.transform.Result; +import javax.xml.transform.stream.StreamResult; + +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeAssignmentExpressionType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.EffectType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObligationExpressionType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType; + +import org.apache.commons.io.IOUtils; +import org.eclipse.persistence.jaxb.JAXBContextFactory; +import org.eclipse.persistence.jaxb.MarshallerProperties; +import org.eclipse.persistence.jaxb.json.JsonSchemaOutputResolver; + +import com.att.research.xacml.api.Advice; +import com.att.research.xacml.api.AttributeAssignment; +import com.att.research.xacml.api.Identifier; +import com.att.research.xacml.api.Obligation; +import org.openecomp.policy.xacml.api.XACMLErrorConstants; +import com.att.research.xacml.util.XACMLPolicyScanner; +import com.att.research.xacml.util.XACMLProperties; +import com.att.research.xacml.util.XACMLPolicyScanner.CallbackResult; +import com.att.research.xacml.util.XACMLPolicyScanner.SimpleCallback; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.databind.node.ObjectNode; +import com.fasterxml.jackson.dataformat.xml.XmlMapper; +import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule; +import com.fasterxml.jackson.module.jsonSchema.JsonSchema; +import com.fasterxml.jackson.module.jsonSchema.factories.SchemaFactoryWrapper; + +import org.kohsuke.args4j.CmdLineException; +import org.kohsuke.args4j.CmdLineParser; +import org.kohsuke.args4j.Option; +import org.openecomp.policy.elk.client.ElkConnector; +import org.openecomp.policy.elk.client.ElkConnector.PolicyBodyType; +import org.openecomp.policy.rest.XACMLRestProperties; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + + +@SuppressWarnings("unused") +public class Xacml2Elk { + public static final String URLID_ATTRIBUTE = "URLID"; + public static final String BODY_ATTRIBUTE = "body"; + + protected static final Logger logger = FlexLogger.getLogger(Xacml2Elk.class); + protected static JAXBContext jaxbContext = jaxbContext(); + + protected static String toConfigsWebDirectory(String policyType) + throws IllegalArgumentException { + if (policyType == null || policyType.isEmpty()) + throw new IllegalArgumentException("Unexpected policy type: " + policyType); + + ElkConnector.PolicyType type = ElkConnector.PolicyType.valueOf(policyType); + switch(type) { + case Config: + return type.name(); + case Action: + return type.name(); + case Decision: + return type.name(); + case Config_Fault: + case Config_PM: + case Config_FW: + case Config_MS: + return ElkConnector.PolicyType.Config.name(); + default: + throw new IllegalArgumentException("Unexpected policy type: " + policyType); + } + } + + protected synchronized static JAXBContext jaxbContext() { + if (jaxbContext != null) { + return jaxbContext; + } + + try { + jaxbContext = JAXBContextFactory.createContext(new Class[] {PolicyType.class}, null); + } catch (JAXBException e) { + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + ":" + + "JAXB Context cannot be created"); + return null; + } + + return jaxbContext; + } + + protected static class CLIOptions { + @Option(name="-t", usage="policy type", aliases={"-type", "--type"}, required=true) + protected String type; + + @Option(name="-n", usage="policy name", aliases={"-name", "--name"}, required=true) + protected String name; + + @Option(name="-o", usage="git repository owner", aliases={"-owner", "--owner"}, required=true) + protected String owner; + + @Option(name="-s", usage="enclosing scope", aliases={"-scope", "--scope"}, required=true) + protected String scope; + + @Option(name="-x", usage="xacml input file", aliases={"-xacml", "--xacml"}, required=true, metaVar="") + protected File xacmlFile; + + @Option(name="-p", usage="payload body type", aliases={"-payloadType", "--payloadType"}, required=false, metaVar="", depends={"-b"}) + protected PolicyBodyType bodyType; + + @Option(name="-b", usage="payload body", aliases={"-body", "--body"}, required=false, metaVar="", depends={"-p"}) + protected String body; + + @Option(name="-d", usage="elk record output directory", aliases={"-d", "--directory"}, required=true, metaVar="") + protected File elkDirectory; + + @Option(name = "-h", aliases = {"-help", "--help"}, usage = "print this message") + private boolean help = false; + }; + + class AttributeAssignmentFinderProcessor extends SimpleCallback { + protected final String attributeId; + protected String attributeValue = null; + + public AttributeAssignmentFinderProcessor(String attributeId) { + this.attributeId = attributeId; + } + + public String getAttributeValue() { + return attributeValue; + } + + public boolean isAttributeValue() { + return (this.attributeValue != null && !this.attributeValue.isEmpty()); + } + + private boolean processAssignments( + List assignments) { + if (logger.isTraceEnabled()) + logger.trace("ENTER"); + + for (AttributeAssignmentExpressionType assignment : assignments) { + if (!assignment.getAttributeId().equals(attributeId)) { + if (logger.isDebugEnabled()) + logger.debug("Ignoring: " + assignment.getAttributeId()); + continue; + } + + if (logger.isDebugEnabled()) + logger.debug("Found Attribute ID: " + assignment.getAttributeId()); + + JAXBElement jaxbExp = assignment.getExpression(); + Object assignmentObject = jaxbExp.getValue(); + if (assignmentObject instanceof AttributeValueType) { + AttributeValueType avt = (AttributeValueType) assignmentObject; + if (avt.getContent().size() <= 0) { + logger.warn("Ignoring: " + assignment.getAttributeId() + ": No values"); + continue; + } + + this.attributeValue = avt.getContent().get(0).toString(); + if (logger.isInfoEnabled()) + logger.info("Found: " + this.attributeValue); + + return true; + } + } + return false; + } + + @Override + public CallbackResult onAdvice(Object parent, AdviceExpressionType expression, Advice advice) { + if (logger.isTraceEnabled()) + logger.trace("ENTER"); + + List assignments = + expression.getAttributeAssignmentExpression(); + + if (assignments != null) { + boolean found = processAssignments(assignments); + if (found) + return CallbackResult.STOP; + } + + return super.onAdvice(parent, expression, advice); + } + + @Override + public CallbackResult onObligation(Object parent, ObligationExpressionType expression, Obligation obligation) { + if (logger.isTraceEnabled()) + logger.trace("ENTER"); + + List assignments = + expression.getAttributeAssignmentExpression(); + + if (assignments != null) { + boolean found = processAssignments(assignments); + if (found) + return CallbackResult.STOP; + } + + return super.onObligation(parent, expression, obligation); + + } + } + + final protected String type; + final protected String name; + final protected String owner; + final protected String scope; + final protected File xacmlFile; + final protected File elkDirectory; + + final protected JAXBElement policy; + + protected PolicyBodyType bodyType; + protected String body; + + + public Xacml2Elk(String type, String name, + String owner, String scope, + File xacmlFile, File elkDirectory) + throws IllegalArgumentException { + + this.type = type; + this.name = name; + this.owner = owner; + this.scope = scope; + this.xacmlFile = xacmlFile; + this.elkDirectory = elkDirectory; + + this.policy = jaxbXacml(xacmlFile); + + this.body = ""; + this.bodyType = PolicyBodyType.none; + bodyFromXacml(); + } + + public Xacml2Elk(CLIOptions args) throws IllegalArgumentException { + this.type = args.type; + this.name = args.name; + this.owner = args.owner; + this.scope = args.scope; + this.xacmlFile = args.xacmlFile; + this.elkDirectory = args.elkDirectory; + + this.policy = jaxbXacml(xacmlFile); + + if (args.body == null || args.body.isEmpty()) { + this.body = ""; + this.bodyType = PolicyBodyType.none; + bodyFromXacml(); + } else { + this.body = args.body; + this.bodyType = args.bodyType; + } + } + + public Xacml2Elk(String type, String name, String owner, + String scope, File xacmlFile, PolicyBodyType bodyType, + String body, File destinationDir) + throws IllegalArgumentException { + this.type = type; + this.name = name; + this.owner = owner; + this.scope = scope; + this.xacmlFile = xacmlFile; + this.bodyType = bodyType; + this.body = body; + this.elkDirectory = destinationDir; + + this.policy = jaxbXacml(xacmlFile); + } + + public Xacml2Elk(File xacmlFile, boolean skipBody) + throws IllegalArgumentException { + this.policy = jaxbXacml(xacmlFile); + PolicyType jPolicy = this.policy.getValue(); + + this.xacmlFile = xacmlFile; + + this.type = ElkConnector.toPolicyType(xacmlFile.getName()).name(); + String fileName = xacmlFile.getName().replaceFirst(this.type + "_", ""); + if (fileName.indexOf(".") > 0) + this.name = fileName.substring(0, fileName.lastIndexOf(".")); + else + this.name = fileName; + + this.owner = "admin"; + this.scope = getScope(xacmlFile.getParent()); + this.elkDirectory = null; + + this.body = ""; + this.bodyType = PolicyBodyType.none; + if (!skipBody) { + bodyFromXacml(); + } + } + + @SuppressWarnings("unchecked") + protected JAXBElement jaxbXacml(File xacmlFile) throws IllegalArgumentException { + Path xacmlPath = xacmlFile.toPath(); + if (!Files.isReadable(xacmlPath) || !Files.isRegularFile(xacmlPath)) { + if (logger.isWarnEnabled()) { + logger.warn("Error: " + xacmlPath + " is invalid."); + } + throw new IllegalArgumentException("Error: " + xacmlPath + " is invalid."); + } + + try { + Unmarshaller u = jaxbContext.createUnmarshaller(); + return (JAXBElement) u.unmarshal(xacmlFile); + } catch (Exception e) { + if (logger.isWarnEnabled()) { + logger.warn(XACMLErrorConstants.ERROR_DATA_ISSUE + " - error: " + xacmlPath + " is invalid."); + } + throw new IllegalArgumentException(xacmlFile.getAbsolutePath() + " does not contain valid XACML"); + } + } + + public JAXBElement getPolicy() { + return policy; + } + + protected String getScope(String xacmlDirPath) { + if (logger.isTraceEnabled()) logger.trace("ENTER"); + + xacmlDirPath = xacmlDirPath.replaceAll("//", "/"); + xacmlDirPath = xacmlDirPath.replaceAll("\\\\", "/"); + xacmlDirPath = xacmlDirPath.replace('\\', '/'); + + String ws = XACMLProperties.getProperty(XACMLRestProperties.PROP_ADMIN_WORKSPACE); + String adminRepo = XACMLProperties.getProperty(XACMLRestProperties.PROP_ADMIN_REPOSITORY); + Path wsPath = Paths.get(ws, "admin", adminRepo); + File repoDir = wsPath.toFile(); + String repoPath = repoDir.getPath(); + repoPath = repoPath.replaceAll("//", "/"); + repoPath = repoPath.replaceAll("\\\\", "/"); + repoPath = repoPath.replace('\\', '/'); + + int startIndex = xacmlDirPath.indexOf(repoPath.toString()) + repoPath.toString().length() + 1; + String scope = xacmlDirPath.substring(startIndex, xacmlDirPath.length()); + + if (logger.isInfoEnabled()) + logger.info("xacml-policy-path=" + xacmlDirPath + "|" + + "repository-path=" + repoPath + "|" + + "scope=" + scope); + + return scope; + } + + @SuppressWarnings("deprecation") + private boolean bodyFromXacml() { + if (logger.isTraceEnabled()) + logger.trace("ENTER"); + + String urlAttribute = URLID_ATTRIBUTE; + try { + switch (ElkConnector.toPolicyType(this.type)) { + case Action: + urlAttribute = BODY_ATTRIBUTE; + break; + case Decision: + case none: + /* no body attached to decision policies */ + if (logger.isInfoEnabled()) + logger.info("No body attached for this type of policy: " + this.xacmlFile.getAbsolutePath()); + return false; + default: + /* a flavour of a config policy - default is fine */ + break; + } + } catch (IllegalArgumentException iae) { + if (logger.isWarnEnabled()) { + logger.warn(this.type + " cannot be converted to a valid type: " + iae.getMessage(), iae); + } + return false; + } + + AttributeAssignmentFinderProcessor + processor = new AttributeAssignmentFinderProcessor(urlAttribute); + XACMLPolicyScanner xacmlScanner = + new XACMLPolicyScanner(this.policy.getValue(), processor); + xacmlScanner.scan(); + if (!processor.isAttributeValue()) { + if (logger.isInfoEnabled()) + logger.info(urlAttribute + " not found in " + this.xacmlFile.getAbsolutePath()); + return false; + } + + String configsUrl = XACMLProperties.getProperty(XACMLRestProperties.PROP_CONFIG_URL); + if (configsUrl == null || configsUrl.isEmpty() || !configsUrl.startsWith("http")) { + if (logger.isWarnEnabled()) { + logger.warn(XACMLRestProperties.PROP_CONFIG_URL + " property is not set."); + } + configsUrl = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_URL); + if (configsUrl == null || configsUrl.isEmpty() || !configsUrl.startsWith("http")) { + if (logger.isWarnEnabled()) { + logger.warn(XACMLRestProperties.PROP_PAP_URL + " property is not set."); + } + return false; + } else { + configsUrl = configsUrl.replaceFirst("/pap", ""); + } + } + + if (!configsUrl.endsWith("/")) { + configsUrl += "/"; + } + + String urlXacml = processor.getAttributeValue(); + if (logger.isDebugEnabled()) { + logger.debug("configs url is " + configsUrl + "and url in xacml is " + urlXacml); + } + + if (urlXacml.startsWith("http")) { + // assuming this an unescaped url + } else if (urlXacml.startsWith("$URLConfig/")) { + urlXacml = urlXacml.replace("$URLConfig/", configsUrl); + } else if (urlXacml.startsWith("$URL/")) { + urlXacml = urlXacml.replace("$URL/", configsUrl); + } else{ + if (logger.isWarnEnabled()) { + logger.warn("XACML url is not in the expected format: " + urlXacml); + } + return false; + } + + if (urlXacml.endsWith(".properties")) { + this.bodyType = PolicyBodyType.properties; + } else if (urlXacml.endsWith(".json")) { + this.bodyType = PolicyBodyType.json; + } else if (urlXacml.endsWith(".xml")) { + this.bodyType = PolicyBodyType.xml; + } else if (urlXacml.endsWith(".txt")) { + this.bodyType = PolicyBodyType.txt; + } + + if (logger.isDebugEnabled()) { + logger.debug("converted url from xacml is " + urlXacml + ", body-type is " + this.bodyType); + } + + InputStream inConfigs = null; + try { + URL url = new URL(urlXacml); + URLConnection connection = url.openConnection(); + inConfigs = connection.getInputStream(); + String encoding = connection.getContentEncoding(); + encoding = (encoding == null ? "UTF-8" : encoding); + this.body = IOUtils.toString(inConfigs, encoding); + if (logger.isInfoEnabled()) { + logger.info("The following document of type " + this.bodyType.toString() + + " has been fetched from " + urlXacml + System.lineSeparator() + + this.body); + } + try { + inConfigs.close(); + } catch (IOException e) { + // ignore + logger.warn("Unexpected error closing stream to " + urlXacml, e); + } + return true; + } catch (Exception e) { + if (logger.isWarnEnabled()) { + logger.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR + + "- XACML url is not in the expected format: " + e.getMessage() + + ": " + urlXacml, e); + } + // continue + } finally { + if (inConfigs != null) { + try { + inConfigs.close(); + } catch (IOException e) { + // ignore + logger.warn("Unexpected error closing stream to " + urlXacml, e); + } + } + } + + // if retrieval through PAP url was not possible, try to retrieve it from + // filesystem instead. + + if (this.body == null || this.body.isEmpty()) { + Path webappsPath = Paths.get(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_WEBAPPS)); + if (webappsPath == null) { + logger.error("Invalid Webapps Path Location property : " + + XACMLRestProperties.PROP_PAP_WEBAPPS); + return false; + } + String waPath = webappsPath.toFile().getAbsolutePath(); + + String typeDir = null; + try { + typeDir = Xacml2Elk.toConfigsWebDirectory(this.type); + } catch (IllegalArgumentException iae) { + if (logger.isWarnEnabled()) { + logger.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR + + "- " + this.type + + " cannot be converted to body-directory: " + iae.getMessage(), + iae); + } + this.bodyType = PolicyBodyType.none; + return false; + } + + String scopePrefix = this.scope.replace('/', '.'); + Path bodyPath = Paths.get(waPath, + typeDir, + scopePrefix + "." + this.type + "_" + + this.name + "." + this.bodyType.name()); + File bodyFile = bodyPath.toFile(); + if (Files.notExists(bodyPath)) { + if (logger.isWarnEnabled()) { + logger.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR + + "The following document of type " + this.bodyType.toString() + + " does not exist at filesystem location " + bodyFile.getAbsolutePath()); + } + this.bodyType = PolicyBodyType.none; + return false; + } else { + if (logger.isInfoEnabled()) { + logger.info("The following document of type " + this.bodyType.toString() + + " will be fetched from filesystem location " + bodyFile.getAbsolutePath()); + } + } + + try { + inConfigs = new FileInputStream(bodyFile); + this.body = IOUtils.toString(inConfigs); + inConfigs.close(); + if (logger.isInfoEnabled()) { + logger.info("The document of type " + this.bodyType.toString() + + " has been found at filesystem location " + bodyFile.getAbsolutePath()); + } + } catch (Exception e) { + if (logger.isWarnEnabled()) { + logger.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR + + "- XACML Body File cannot be read: " + bodyFile.getAbsolutePath(), e); + } + this.bodyType = PolicyBodyType.none; + return false; + } finally { + if (inConfigs != null) { + try { + inConfigs.close(); + } catch (IOException e) { + // ignore + logger.warn("Unexpected error closing stream to " + urlXacml, e); + } + } else { + return false; + } + } + } + return true; + } + + public boolean attachJsonBody(JsonNode jPolicy) { + if (this.body == null) { + if (logger.isWarnEnabled()) { + logger.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR + + "- JSON Body expected but none provided from " + + this.scope + ":" + this.type + ":" + this.name); + } + return true; + } + + ObjectNode jPolicyRoot = (ObjectNode) jPolicy; + + // verify the json is valid + final ObjectMapper mapper = new ObjectMapper(); + JsonNode jBodyContent; + try { + jBodyContent = mapper.readTree(this.body); + } catch (IOException e) { + logger.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR + + "- JSON Body is invalid in " + + this.scope + ":" + this.type + ":" + this.name + ":" + + e.getMessage() + System.lineSeparator() + this.body, e); + return false; + } + + String jBodyName = this.type + "_" + "Body"; + ObjectNode jBodyContainer = mapper.createObjectNode(); + jBodyContainer.set(jBodyName, jBodyContent); + + jPolicyRoot.set("Body", jBodyContainer); + + if (logger.isDebugEnabled()) + logger.debug("Attaching JSON to " + + this.scope + ":" + + this.type + ":" + this.name + ":" + + jBodyName + System.lineSeparator() + + jBodyContent); + + return true; + } + + @SuppressWarnings("unchecked") + public boolean attachXmlBody(JsonNode jPolicy) { + if (this.body == null) { + if (logger.isWarnEnabled()) { + logger.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR + + "- JSON Body expected but none provided from " + + this.scope + ":" + this.type + ":" + this.name); + } + return true; + } + + XmlMapper xmlMapper = new XmlMapper(); + xmlMapper.setConfig(xmlMapper.getSerializationConfig().withRootName("")); + Map map; + try { + map = xmlMapper.readValue(this.body, Map.class); + } catch (IOException e) { + logger.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR + + "- XML Body is invalid in " + + this.scope + ":" + this.type + ":" + this.name + ":" + + e.getMessage() + System.lineSeparator() + this.body, e); + return false; + } + + final ObjectMapper mapper = new ObjectMapper(); + String jXmlBody; + try { + jXmlBody = mapper.writeValueAsString(map); + } catch (JsonProcessingException e) { + logger.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR + + "- Cannot convert XML Body to JSON in " + + this.scope + ":" + this.type + ":" + this.name + ":" + + e.getMessage() + System.lineSeparator() + this.body, e); + return false; + } + + if (logger.isDebugEnabled()) + logger.debug("XML-to-JSON Body conversion: " + this.scope + ":" + + this.type + ":" + this.name +jXmlBody); + + JsonNode jBodyContent; + try { + jBodyContent = mapper.readTree(jXmlBody); + } catch (IOException e) { + logger.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR + + "- JSON Body (converted from XML) is invalid in " + + this.scope + ":" + this.type + ":" + this.name + ":" + + e.getMessage() + System.lineSeparator() + jXmlBody, e); + return false; + } + + ObjectNode jPolicyRoot = (ObjectNode) jPolicy; + + String jBodyName = this.type + "_" + "Body"; + ObjectNode jBodyContainer = mapper.createObjectNode(); + jBodyContainer.set(jBodyName, jBodyContent); + + jPolicyRoot.set("Body", jBodyContainer); + + + if (logger.isDebugEnabled()) + logger.debug("Attaching JSON to " + + this.scope + ":" + + this.type + ":" + this.name + ":" + + jBodyName + System.lineSeparator() + + jBodyContent); + + return true; + } + + protected boolean attachPropertiesBody(JsonNode jPolicy) { + if (this.body == null) { + if (logger.isWarnEnabled()) { + logger.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR + + "- JSON Body expected but none provided from " + + this.scope + ":" + this.type + ":" + this.name); + } + return true; + } + + final Properties propBody = new Properties(); + try { + propBody.load(new StringReader(this.body)); + } catch (IOException e) { + logger.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR + + "- JSON Body is invalid in " + + this.scope + ":" + this.type + ":" + this.name + ":" + + e.getMessage() + System.lineSeparator() + this.body, e); + return false; + } + + if (propBody.isEmpty()) { + if (logger.isInfoEnabled()) { + logger.info("Empty set of properties: " + + this.scope + ":" + this.type + ":" + this.name + + System.lineSeparator() + this.body); + } + return true; + } + + + final ObjectMapper mapper = new ObjectMapper(); + + ObjectNode jPolicyRoot = (ObjectNode) jPolicy; + ObjectNode jBody = jPolicyRoot.putObject("Body"); + String jBodyName = this.type + "_" + "Body"; + ObjectNode jBodyContainer = jBody.putObject(jBodyName); + + // ObjectNode jBodyContainer = mapper.createObjectNode(); + + for(String key : propBody.stringPropertyNames()) { + String value = propBody.getProperty(key); + if (logger.isDebugEnabled()) { + logger.debug("Attaching JSON field to " + jBodyName + " for " + + this.type.toString() + ":" + + this.scope + ":" + this.name + ":" + jBodyName + ":" + + " <" + key +"," + value + ">"); + } + jBodyContainer.put(key, propBody.getProperty(key)); + } + + return true; + } + + public boolean attachTextBody(JsonNode jPolicy) { + if (this.body == null) { + if (logger.isWarnEnabled()) { + logger.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR + + "- JSON Body expected but none provided from " + + this.scope + ":" + this.type + ":" + this.name); + } + return true; + } + + final ObjectMapper mapper = new ObjectMapper(); + StringWriter jsonEscapedTextWriter = new StringWriter(); + try { + mapper.writer().writeValue(jsonEscapedTextWriter, this.body); + } catch (IOException e) { + if (logger.isWarnEnabled()) { + logger.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR + + "- Text Body cannot be converted from " + + this.scope + ":" + this.type + ":" + this.name + ":" + + e.getMessage() + ":" + jsonEscapedTextWriter , e); + } + return false; + } + String jTextBody = jsonEscapedTextWriter.toString(); + + if (logger.isDebugEnabled()) + logger.debug("XML 2JSON Body conversion: " + this.scope + ":" + + this.type + ":" + this.name + ":" + jTextBody); + + ObjectNode jPolicyRoot = (ObjectNode) jPolicy; + + String jBodyName = this.type + "_" + "Body"; + ObjectNode jBodyContainer = mapper.createObjectNode(); + jBodyContainer.put(jBodyName, jTextBody); + + jPolicyRoot.set("Body", jBodyContainer); + + if (logger.isDebugEnabled()) + logger.debug("Attaching JSON to " + + this.scope + ":" + + this.type + ":" + this.name + ":" + + jBodyName + ":" + + jTextBody); + + return true; + } + + protected boolean attachBody(JsonNode jPolicy) { + if (logger.isTraceEnabled()) logger.trace("ENTER"); + + if (this.bodyType == PolicyBodyType.none) { + if (logger.isInfoEnabled()) + logger.info("No body to attach for policy " + + this.scope + "/" + this.type + "_" + this.name); + + return true; + } + + if (this.body == null || this.body.isEmpty()) { + if (logger.isWarnEnabled()) + logger.warn("No body to attach for policy " + + this.bodyType + this.type + this.scope + this.name); + + return true; + } + + switch (this.bodyType) { + case json: + return attachJsonBody(jPolicy); + case properties: + return attachPropertiesBody(jPolicy); + case xml: + return attachXmlBody(jPolicy); + case txt: + return attachTextBody(jPolicy); + case none: + default: + if (logger.isWarnEnabled()) + logger.warn("Unexpected body type: " + this.bodyType + + this.bodyType + this.type + this.scope + this.name); + return false; + } + } + + public ElkRecord record() throws JAXBException, JsonProcessingException, + IOException, IllegalArgumentException { + if (logger.isTraceEnabled()) logger.trace("ENTER"); + + Marshaller m = jaxbContext.createMarshaller(); + m.setProperty(MarshallerProperties.MEDIA_TYPE, "application/json"); + m.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, true); + m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); + m.setProperty(MarshallerProperties.JSON_REDUCE_ANY_ARRAYS, true); + m.setProperty(MarshallerProperties.JSON_MARSHAL_EMPTY_COLLECTIONS, false); + + StringWriter policyStringWriter = new StringWriter(); + m.marshal(policy, policyStringWriter); + + // add metadata to elk record + + final ObjectMapper mapper = new ObjectMapper(); + JsonNode jRoot = mapper.readTree(policyStringWriter.toString()); + JsonNode jPolicy = jRoot.path("Policy"); + if (jPolicy.isMissingNode()) { + logger.warn("Aborting: Policy root node is missing."); + throw new IllegalArgumentException("Missing policy root node"); + } + + ((ObjectNode) jPolicy).put("PolicyType", this.type.toString()); + ((ObjectNode) jPolicy).put("PolicyName", this.name); + ((ObjectNode) jPolicy).put("Owner", this.owner); + ((ObjectNode) jPolicy).put("Scope", this.scope); + + JsonNode jPolicyId = jPolicy.path("PolicyId"); + if (jPolicyId.isMissingNode()) { + logger.warn("Aborting: Policy ID node is missing."); + throw new IllegalArgumentException("Missing policy id"); + } + + if (!jPolicyId.isTextual() || !jPolicyId.isValueNode()) { + logger.warn("Aborting: Policy ID invalid."); + throw new IllegalArgumentException("Invalid policy id"); + } + + String xacmlPolicyId = jPolicyId.asText(); + String policyId = xacmlPolicyId.substring(xacmlPolicyId.lastIndexOf(":")+1); + + boolean success = attachBody(jPolicy); + + mapper.configure(SerializationFeature.INDENT_OUTPUT, true); + mapper.configure(SerializationFeature.WRITE_ENUMS_USING_TO_STRING, true); + mapper.configure(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, false); + mapper.configure(SerializationFeature.WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED, true); + + String recordText = mapper.writeValueAsString(jRoot); + if (logger.isDebugEnabled()) { + logger.debug("ELK Record: " + System.lineSeparator() + recordText); + } + + ElkRecord elkRecord = new ElkRecord(policyId, recordText, jRoot, success); + return elkRecord; + } + + public void store(String policyId, String record) throws IOException { + if (logger.isTraceEnabled()) logger.trace("ENTER"); + + if (this.elkDirectory != null) { + Files.createDirectories(this.elkDirectory.toPath());; + Path elkPolicyFile = Paths.get(this.elkDirectory.getPath(), policyId + ".json"); + + if (logger.isDebugEnabled()) { + logger.info("Output: " + elkPolicyFile.toAbsolutePath().toString()); + logger.info("---------------------------------------------------"); + } + + Files.write(elkPolicyFile, record.getBytes()); + } + } + + public static void main(String args[]) + throws JAXBException, IOException, CmdLineException, IllegalStateException { + + CLIOptions cliOptions = new CLIOptions(); + CmdLineParser cliParser= new CmdLineParser(cliOptions); + + try { + cliParser.parseArgument(args); + } catch (CmdLineException e) { + System.err.println("Usage: Xacml2elk"); + cliParser.printUsage(System.err); + throw e; + } + + System.out.println("---------------------------------------------------"); + System.out.println("Converting " + cliOptions.xacmlFile.getName() + " to ELK format"); + System.out.println("Metadata=" + "[type:" + cliOptions.type + + "|name:" + cliOptions.name + + "|owner:" + cliOptions.owner + + "|scope:" + cliOptions.scope + "]"); + + // generate json from jaxb input file + + Path xacmlPath = cliOptions.xacmlFile.toPath(); + if (!Files.isReadable(xacmlPath) || !Files.isRegularFile(xacmlPath)) { + System.out.println("Error: " + xacmlPath + " is invalid."); + throw new IllegalArgumentException("Error: " + xacmlPath + " is invalid."); + } + + + Xacml2Elk convertor = new Xacml2Elk(cliOptions); + ElkRecord elkRecord = convertor.record(); + System.out.println(elkRecord.record); + + Path elkOutDir = cliOptions.elkDirectory.toPath(); + if (!Files.isReadable(elkOutDir) || !Files.isDirectory(elkOutDir) || + !Files.isWritable(elkOutDir) || !Files.isExecutable(elkOutDir)) { + System.out.println("Error: " + elkOutDir.getFileName() + " is invalid."); + throw new IllegalArgumentException("Error: " + elkOutDir.getFileName() + " is invalid."); + } + + convertor.store(elkRecord.policyId, elkRecord.record); + } +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/model/PDPGroupContainer.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/model/PDPGroupContainer.java new file mode 100644 index 000000000..fd996f444 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/model/PDPGroupContainer.java @@ -0,0 +1,531 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.model; + + +import java.awt.Checkbox; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; + +import org.openecomp.policy.utils.PolicyContainer; +import org.openecomp.policy.utils.PolicyItemSetChangeNotifier; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; +import org.openecomp.policy.xacml.api.pap.EcompPDP; +import org.openecomp.policy.xacml.api.pap.EcompPDPGroup; +import org.openecomp.policy.xacml.api.pap.PAPPolicyEngine; + +import com.att.research.xacml.api.pap.PAPEngine; +import com.att.research.xacml.api.pap.PAPException; +import com.att.research.xacml.api.pap.PDP; +//import com.att.research.xacml.api.pap.PDP; +//import com.att.research.xacml.api.pap.PDPGroup; +import com.att.research.xacml.api.pap.PDPPIPConfig; +import com.att.research.xacml.api.pap.PDPPolicy; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +public class PDPGroupContainer extends PolicyItemSetChangeNotifier implements PolicyContainer.Indexed, PolicyContainer.ItemSetChangeNotifier { + private static final long serialVersionUID = 1L; + private static Logger logger = FlexLogger.getLogger(PDPGroupContainer.class); + + /** + * String identifier of a file's "Id" property. + */ + public static String PROPERTY_ID = "Id"; + + /** + * String identifier of a file's "name" property. + */ + public static String PROPERTY_NAME = "Name"; + + /** + * String identifier of a file's "Description" property. + */ + public static String PROPERTY_DESCRIPTION = "Description"; + + /** + * String identifier of a file's "Default" property. + */ + public static String PROPERTY_DEFAULT = "Default"; + + /** + * String identifier of a file's "icon" property. + */ + public static String PROPERTY_ICON = "Icon"; + + /** + * String identifier of a file's "Status" property. + */ + public static String PROPERTY_STATUS = "Status"; + + /** + * String identifier of a file's "PDPs" property. + */ + public static String PROPERTY_PDPS = "PDPs"; + + /** + * String identifier of a file's "Policies" property. + */ + public static String PROPERTY_POLICIES = "Policies"; + + /** + * String identifier of a file's "PIP Configurations" property. + */ + public static String PROPERTY_PIPCONFIG = "PIP Configurations"; + + /** + * String identifier of a file's "Selected" property. + */ + public static String PROPERTY_SELECTED = "Selected"; + + /** + * List of the string identifiers for the available properties. + */ + public static Collection PDP_PROPERTIES; + + private PAPPolicyEngine papEngine = null; + protected List groups = Collections.synchronizedList(new ArrayList()); + + public PDPGroupContainer(PAPPolicyEngine papPolicyEngine) { + super(); + this.setContainer(this); + // + // + // + this.papEngine = (PAPPolicyEngine) papPolicyEngine; + // + // + // + this.refreshGroups(); + } + + public boolean isSupported(Object itemId) { + if (itemId instanceof EcompPDPGroup) { + return true; + } + return false; + } + + public synchronized void refreshGroups() { + synchronized(this.groups) { + this.groups.clear(); + try { + this.groups.addAll(this.papEngine.getEcompPDPGroups()); + } catch (PAPException e) { + String message = "Unable to retrieve Groups from server: " + e; + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + message, e); + } + logger.info("refreshGroups"); + } + // + // Notify that we have changed + // + this.fireItemSetChange(); + } + + public List getGroups() { + return Collections.unmodifiableList(this.groups); + } + + public void makeDefault(EcompPDPGroup group) { + try { + this.papEngine.SetDefaultGroup(group); + } catch (PAPException e) { + String message = "Unable to set Default Group on server: " + e; + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + message, e); + } + return; + } + + public void removeGroup(EcompPDPGroup group, EcompPDPGroup newGroup) throws PAPException { + if (logger.isTraceEnabled()) { + logger.trace("removeGroup: " + group + " new group for PDPs: " + newGroup); + } + if (group.isDefaultGroup()) { + throw new UnsupportedOperationException("You can't remove the Default Group."); + } + try { + this.papEngine.removeGroup(group, newGroup); + } catch (NullPointerException | PAPException e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Failed to removeGroup " + group.getId(), e); + throw new PAPException("Failed to remove group '" + group.getId()+ "'", e); + } + } + + public void removePDP(EcompPDP pdp, EcompPDPGroup group) throws PAPException { + if (logger.isTraceEnabled()) { + logger.trace("removePDP: " + pdp + " from group: " + group); + } + try { + this.papEngine.removePDP(pdp); + } catch (PAPException e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Failed to removePDP " + pdp.getId(), e); + throw new PAPException("Failed to remove pdp '" + pdp.getId()+ "'", e); + } + } + + public void updatePDP(EcompPDP pdp) { + try { + papEngine.updatePDP(pdp); + } catch (PAPException e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + } + } + + public void updateGroup(EcompPDPGroup group) { + try { + papEngine.updateGroup(group); + } catch (PAPException e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + } + } + + @Override + public Collection getContainerPropertyIds() { + return PDP_PROPERTIES; + } + + @Override + public Collection getItemIds() { + final Collection items = new ArrayList(); + items.addAll(this.groups); + if (logger.isTraceEnabled()) { + logger.trace("getItemIds: " + items); + } + return Collections.unmodifiableCollection(items); + } + + @Override + public Class getType(Object propertyId) { + if (propertyId.equals(PROPERTY_ID)) { + return String.class; + } + if (propertyId.equals(PROPERTY_NAME)) { + return String.class; + } + if (propertyId.equals(PROPERTY_DESCRIPTION)) { + return String.class; + } + if (propertyId.equals(PROPERTY_DEFAULT)) { + return Boolean.class; + } + if (propertyId.equals(PROPERTY_STATUS)) { + return String.class; + } + if (propertyId.equals(PROPERTY_PDPS)) { + return Set.class; + } + if (propertyId.equals(PROPERTY_POLICIES)) { + return Set.class; + } + if (propertyId.equals(PROPERTY_PIPCONFIG)) { + return Set.class; + } + if (propertyId.equals(PROPERTY_SELECTED)) { + return Checkbox.class; + } + return null; + } + + @Override + public int size() { + return this.groups.size(); + } + + @Override + public boolean containsId(Object itemId) { + if (logger.isTraceEnabled()) { + logger.trace("containsId: " + itemId); + } + if (this.isSupported(itemId) == false) { + return false; + } + return this.groups.contains(itemId); + } + + @Override + public Object addItem() throws UnsupportedOperationException { + throw new UnsupportedOperationException("PDP Container cannot add a given item."); + } + + public void addNewGroup(String name, String description) throws NullPointerException, PAPException { + if (logger.isTraceEnabled()) { + logger.trace("addNewGroup " + name + " " + description); + } + this.papEngine.newGroup(name, description); + } + + public void addNewPDP(String id, EcompPDPGroup group, String name, String description, int jmxport) throws NullPointerException, PAPException { + if (logger.isTraceEnabled()) { + logger.trace("addNewPDP " + id + " " + name + " " + description + " " + jmxport); + } + this.papEngine.newPDP(id, group, name, description, jmxport); + } + + public void movePDP(EcompPDP pdp, EcompPDPGroup group) { + try { + this.papEngine.movePDP(pdp, group); + } catch (PAPException e) { + String message = "Unable to move PDP to new group on server: " + e; + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + message, e); + } + return; + } + + @Override + public boolean addContainerProperty(Object propertyId, Class type, Object defaultValue) throws UnsupportedOperationException { + throw new UnsupportedOperationException("Cannot add a container property."); + } + + @Override + public boolean removeContainerProperty(Object propertyId) throws UnsupportedOperationException { + throw new UnsupportedOperationException("Cannot remove a container property."); + } + + @Override + public boolean removeAllItems() throws UnsupportedOperationException { + throw new UnsupportedOperationException("PDP Container cannot remove all items. You must have at least the Default group."); + } + + @Override + public void addItemSetChangeListener(ItemSetChangeListener listener) { + if (getItemSetChangeListeners() == null) { + setItemSetChangeListeners(new LinkedList()); + } + getItemSetChangeListeners().add(listener); + } + + @Override + public Object nextItemId(Object itemId) { + if (this.isSupported(itemId) == false) { + return null; + } + int index = this.groups.indexOf(itemId); + if (index == -1) { + // + // We don't know this group + // + return null; + } + // + // Is it the last one? + // + if (index == this.groups.size() - 1) { + // + // Yes + // + return null; + } + // + // Return the next one + // + return this.groups.get(index + 1); + } + + @Override + public Object prevItemId(Object itemId) { + if (this.isSupported(itemId) == false) { + return null; + } + int index = this.groups.indexOf(itemId); + if (index == -1) { + // + // We don't know this group + // + return null; + } + // + // Is it the first one? + // + if (index == 0) { + // + // Yes + // + return null; + } + // + // Return the previous one + // + return this.groups.get(index - 1); + } + + @Override + public Object firstItemId() { + synchronized (this.groups) { + if (this.groups.size() > 0) { + return this.groups.get(0); + } + } + return null; + } + + @Override + public Object lastItemId() { + synchronized (this.groups) { + if (this.groups.size() > 0) { + return this.groups.get(this.groups.size() - 1); + } + } + return null; + } + + @Override + public boolean isFirstId(Object itemId) { + synchronized (this.groups) { + if (this.groups.size() > 0) { + return (this.groups.get(0).equals(itemId)); + } + } + return false; + } + + @Override + public boolean isLastId(Object itemId) { + synchronized (this.groups) { + if (this.groups.size() > 0) { + return (this.groups.get(this.groups.size() - 1).equals(itemId)); + } + } + return false; + } + + @Override + public Object addItemAfter(Object previousItemId) throws UnsupportedOperationException { + throw new UnsupportedOperationException("Cannot addItemAfter, there really is no real ordering."); + } + + @Override + public int indexOfId(Object itemId) { + return this.groups.indexOf(itemId); + } + + @Override + public Object getIdByIndex(int index) { + return this.groups.get(index); + } + + @Override + public List getItemIds(int startIndex, int numberOfItems) { + synchronized (this.groups) { + int endIndex = startIndex + numberOfItems; + if (endIndex > this.groups.size()) { + endIndex = this.groups.size() - 1; + } + return this.groups.subList(startIndex, endIndex); + } + } + + @Override + public Object addItemAt(int index) throws UnsupportedOperationException { + throw new UnsupportedOperationException("Cannot addItemAt"); + } + + @Override + public boolean removeItem(Object itemId) throws UnsupportedOperationException { + if (logger.isTraceEnabled()) { + logger.trace("removeItem: " + itemId); + } + if (this.isSupported(itemId) == false) { + return false; + } + // + // You cannot remove the default group + // + if (((EcompPDPGroup) itemId).getId().equals("Default")) { + throw new UnsupportedOperationException("You can't remove the Default Group."); + } + // + // Remove PDPGroup and move any PDP's in it into the default group + // + try { + this.papEngine.removeGroup((EcompPDPGroup) itemId, this.papEngine.getDefaultGroup()); + return true; + } catch (NullPointerException | PAPException e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Failed to remove group", e); + } + return false; + } + + public class PDPGroupItem{ + private final EcompPDPGroup group; + + public PDPGroupItem(EcompPDPGroup itemId) { + this.group = itemId; + } + + public String getId() { + if (logger.isTraceEnabled()) { + logger.trace("getId: " + this.group); + } + return this.group.getId(); + } + + public String getName() { + if (logger.isTraceEnabled()) { + logger.trace("getName: " + this.group); + } + return this.group.getName(); + } + + public String getDescription() { + if (logger.isTraceEnabled()) { + logger.trace("getDescription: " + this.group); + } + return this.group.getDescription(); + } + + public Boolean getDefault() { + if (logger.isTraceEnabled()) { + logger.trace("getDefault: " + this.group); + } + return this.group.isDefaultGroup(); + } + + + public String getStatus() { + return this.group.getStatus().getStatus().toString(); + } + + public Set getPDPs() { + return Collections.unmodifiableSet(this.group.getPdps()); + } + + public Set getPolicies() { + if (logger.isTraceEnabled()) { + logger.trace("getPolicies: " + this.group); + } + return this.group.getPolicies(); + } + + public Set getPipConfigs() { + if (logger.isTraceEnabled()) { + logger.trace("getPIPConfigs: " + this.group); + } + return this.group.getPipConfigs(); + } + } +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/model/PDPPolicyContainer.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/model/PDPPolicyContainer.java new file mode 100644 index 000000000..bea7915a4 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/model/PDPPolicyContainer.java @@ -0,0 +1,348 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.model; + + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Set; + +import org.openecomp.policy.utils.PolicyContainer; +import org.openecomp.policy.utils.PolicyItemSetChangeNotifier; +import org.openecomp.policy.common.logging.flexlogger.*; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; +import com.att.research.xacml.api.pap.PDP; +import com.att.research.xacml.api.pap.PDPGroup; +import com.att.research.xacml.api.pap.PDPPolicy; +import org.openecomp.policy.xacml.std.pap.StdPDPPolicy; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class PDPPolicyContainer extends PolicyItemSetChangeNotifier implements PolicyContainer.Indexed { + private static final long serialVersionUID = 1L; + private static Logger logger = FlexLogger.getLogger(PDPPolicyContainer.class); + + /** + * String identifier of a file's "Id" property. + */ + public static String PROPERTY_ID = "Id"; + + /** + * String identifier of a file's "name" property. + */ + public static String PROPERTY_NAME = "Name"; + + /** + * String identifier of a file's "name" property. + */ + public static String PROPERTY_VERSION = "Version"; + + /** + * String identifier of a file's "Description" property. + */ + public static String PROPERTY_DESCRIPTION = "Description"; + + /** + * String identifier of a file's "IsRoot" property. + */ + public static String PROPERTY_ISROOT = "Root"; + + /** + * List of the string identifiers for the available properties. + */ + public static Collection PDPPOLICY_PROPERTIES; + + private final Object data; + private List policies; + + @SuppressWarnings("unchecked") + public PDPPolicyContainer(Object data) { + super(); + this.data = data; + if (this.data instanceof PDPGroup) { + policies = new ArrayList (((PDPGroup) this.data).getPolicies()); + } + if (this.data instanceof PDP) { + policies = new ArrayList (((PDP) this.data).getPolicies()); + } + if (this.data instanceof Set) { + policies = new ArrayList ((Set)data); + } + if (this.policies == null) { + logger.info("NULL policies"); + throw new NullPointerException("PDPPolicyContainer created with unexpected Object type '" + data.getClass().getName() + "'"); + } + this.setContainer(this); + } + + @Override + public Object nextItemId(Object itemId) { + if (logger.isTraceEnabled()) { + logger.trace("nextItemId: " + itemId); + } + int index = this.policies.indexOf(itemId); + if (index == -1 || ((index + 1) >= this.policies.size())) { + return null; + } + return new PDPPolicyItem(this.policies.get(index + 1)); + } + + @Override + public Object prevItemId(Object itemId) { + if (logger.isTraceEnabled()) { + logger.trace("prevItemId: " + itemId); + } + int index = this.policies.indexOf(itemId); + if (index <= 0) { + return null; + } + return new PDPPolicyItem(this.policies.get(index - 1)); + } + + @Override + public Object firstItemId() { + if (logger.isTraceEnabled()) { + logger.trace("firstItemId: "); + } + if (this.policies.isEmpty()) { + return null; + } + return new PDPPolicyItem(this.policies.get(0)); + } + + @Override + public Object lastItemId() { + if (logger.isTraceEnabled()) { + logger.trace("lastItemid: "); + } + if (this.policies.isEmpty()) { + return null; + } + return new PDPPolicyItem(this.policies.get(this.policies.size() - 1)); + } + + @Override + public boolean isFirstId(Object itemId) { + if (logger.isTraceEnabled()) { + logger.trace("isFirstId: " + itemId); + } + if (this.policies.isEmpty()) { + return false; + } + return (itemId.equals(this.policies.get(0))); + } + + @Override + public boolean isLastId(Object itemId) { + if (logger.isTraceEnabled()) { + logger.trace("isLastId: " + itemId); + } + if (this.policies.isEmpty()) { + return false; + } + return (itemId.equals(this.policies.get(this.policies.size() - 1))); + } + + @Override + public Object addItemAfter(Object previousItemId) + throws UnsupportedOperationException { + return null; + } + + @Override + public Collection getContainerPropertyIds() { + return PDPPOLICY_PROPERTIES; + } + + @Override + public Collection getItemIds() { + final Collection items = new ArrayList(); + items.addAll(this.policies); + return Collections.unmodifiableCollection(items); + } + + + @Override + public Class getType(Object propertyId) { + if (propertyId.equals(PROPERTY_ID)) { + return String.class; + } + if (propertyId.equals(PROPERTY_NAME)) { + return String.class; + } + if (propertyId.equals(PROPERTY_VERSION)) { + return String.class; + } + if (propertyId.equals(PROPERTY_DESCRIPTION)) { + return String.class; + } + if (propertyId.equals(PROPERTY_ISROOT)) { + return Boolean.class; + } + return null; + } + + @Override + public int size() { + if (logger.isTraceEnabled()) { + logger.trace("size: " + this.policies.size()); + } + return this.policies.size(); + } + + @Override + public boolean containsId(Object itemId) { + if (logger.isTraceEnabled()) { + logger.trace("containsId: " + itemId); + } + return this.policies.contains(itemId); + } + + @Override + public Object addItem() throws UnsupportedOperationException { + throw new UnsupportedOperationException("Cannot add an empty policy."); + } + + @Override + public boolean removeItem(Object itemId) + throws UnsupportedOperationException { + if (logger.isTraceEnabled()) { + logger.trace("removeItem: " + itemId); + } + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + StdPDPPolicy pdpPolicy = null; + try { + pdpPolicy = mapper.readValue(itemId.toString() , StdPDPPolicy.class); + for(int i = 0; i< policies.size(); i++){ + if(policies.get(i).getId().equalsIgnoreCase(pdpPolicy.getId())){ + return this.policies.remove(this.policies.get(i)); + } + } + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Exception Occured While Mapping the Removing Policy from PDP Group to Std Policy"+e); + } + return this.policies.remove(itemId); + } + + @Override + public boolean addContainerProperty(Object propertyId, Class type, + Object defaultValue) throws UnsupportedOperationException { + return false; + } + + @Override + public boolean removeContainerProperty(Object propertyId) + throws UnsupportedOperationException { + return false; + } + + @Override + public boolean removeAllItems() throws UnsupportedOperationException { + return false; + } + + @Override + public int indexOfId(Object itemId) { + if (logger.isTraceEnabled()) { + logger.trace("indexOfId: " + itemId); + } + return this.policies.indexOf(itemId); + } + + @Override + public Object getIdByIndex(int index) { + if (logger.isTraceEnabled()) { + logger.trace("getIdByIndex: " + index); + } + return this.policies.get(index); + } + + @Override + public List getItemIds(int startIndex, int numberOfItems) { + if (logger.isTraceEnabled()) { + logger.trace("getItemIds: " + startIndex + " " + numberOfItems); + } + if (numberOfItems < 0) { + throw new IllegalArgumentException(); + } + return this.policies.subList(startIndex, startIndex + numberOfItems); + } + + @Override + public Object addItemAt(int index) throws UnsupportedOperationException { + if (logger.isTraceEnabled()) { + logger.trace("addItemAt: " + index); + } + return null; + } + + public class PDPPolicyItem { + private final PDPPolicy policy; + + public PDPPolicyItem(PDPPolicy itemId) { + this.policy = itemId; + } + + public String getId() { + if (logger.isTraceEnabled()) { + logger.trace("getId: " + this.policy); + } + return this.policy.getId(); + } + + public String getName() { + if (logger.isTraceEnabled()) { + logger.trace("getName: " + this.policy); + } + return this.policy.getName(); + } + + public String getVersion() { + if (logger.isTraceEnabled()) { + logger.trace("getVersion: " + this.policy); + } + return this.policy.getVersion(); + } + + public String getDescription() { + if (logger.isTraceEnabled()) { + logger.trace("getDescription: " + this.policy); + } + return this.policy.getDescription(); + } + + public boolean getRoot() { + if (logger.isTraceEnabled()) { + logger.trace("isRoot: " + this.policy); + } + return this.policy.isRoot(); + } + + public void setRoot(Boolean root) { + ((StdPDPPolicy)this.policy).setRoot(root); + } + + } +} \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/model/Roles.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/model/Roles.java new file mode 100644 index 000000000..5cad87f41 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/model/Roles.java @@ -0,0 +1,95 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.model; + + +import java.io.Serializable; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + +@Entity +@Table(name="Roles") +@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) +public class Roles implements Serializable{ + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + + @Column(name="id") + private int id; + + private String loginId; + private String name; + private String scope; + private String role; + + public Roles(){ + + } + + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + + public String getLoginId() { + return this.loginId; + } + + public void setLoginId(String loginId) { + this.loginId = loginId; + + } + public String getScope() { + return this.scope; + } + + public void setScope(String scope) { + this.scope = scope; + + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + public String getRole() { + return this.role; + } + + public void setRole(String role) { + this.role = role; + } +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/utils/ConfigurableRESTUtils.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/utils/ConfigurableRESTUtils.java new file mode 100644 index 000000000..eafd2196d --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/utils/ConfigurableRESTUtils.java @@ -0,0 +1,163 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.utils; + + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStreamWriter; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.Map; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + + +public class ConfigurableRESTUtils { + + protected Logger logger = FlexLogger.getLogger(this.getClass()); + + // + // How the value is returned from the RESTful server + // httpResponseCode means the result is simply the HTTP Response code (e.g. 200, 505, etc.) + // other values identify the encoding used for the string in the body of the HTTP response + // + public enum REST_RESPONSE_FORMAT {httpResponseCode, json } + public enum RESQUEST_METHOD { + GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS, TRACE; + } + + public String ERROR_RECEIVED = "ERROR - Unexpected HTTP response: "; + + public ConfigurableRESTUtils() { + + } + + + /** + * Call the RESTful API and return a string containing the result. The string may be either a httpResponseCode or json body + * + * @param fullURI + * @param hardCodedHeaders + * @param httpResponseCodes + * @param responseFormat + * @param jsonBody + * @param requestMethod + * @return String + */ + public String sendRESTRequest(String fullURI, Map hardCodedHeaderMap, + Map httpResponseCodeMap, + REST_RESPONSE_FORMAT responseFormat, + String jsonBody, + RESQUEST_METHOD requestMethod ){ + + String responseString = null; + HttpURLConnection connection = null; + try { + + URL url = new URL(fullURI); + + // + // Open up the connection + // + connection = (HttpURLConnection)url.openConnection(); + // + // Setup our method and headers + // + connection.setRequestMethod(requestMethod.toString()); + + connection.setUseCaches(false); + + // add hard-coded headers + for (String headerName : hardCodedHeaderMap.keySet()) { + connection.addRequestProperty(headerName, hardCodedHeaderMap.get(headerName)); + } + + + + if (jsonBody != null){ + connection.setDoInput(true); + connection.setDoOutput(true); + OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream()); + out.write(jsonBody); + out.flush(); + out.close(); + } else{ + connection.connect(); + } + + int responseCode = connection.getResponseCode(); + + // check that the response is one we expected (and get the associated value at the same time) + responseString = httpResponseCodeMap.get(responseCode); + if (responseString == null) { + // the response was not configured, meaning it is unexpected and therefore an error + logger.error("Unexpected HTTP response code '" + responseCode + "' from RESTful Server"); + return ERROR_RECEIVED + " code" + responseCode + " from RESTful Server"; + } + + // if the response is contained only in the http code we are done. Otherwise we need to read the body + if (responseFormat == REST_RESPONSE_FORMAT.httpResponseCode) { + return responseString; + } + + // Need to read the body and return that as the responseString. + + responseString = null; + // read the inputStream into a buffer (trick found online scans entire input looking for end-of-file) + java.util.Scanner scanner = new java.util.Scanner(connection.getInputStream()); + scanner.useDelimiter("\\A"); + responseString = scanner.hasNext() ? scanner.next() : ""; + scanner.close(); + logger.debug("RESTful body: " + responseString); + return responseString; + + } catch (Exception e) { + logger.error("HTTP Request/Response from RESTFUL server: " + e); + responseString = ERROR_RECEIVED + e; + } finally { + // cleanup the connection + if (connection != null) { + try { + // For some reason trying to get the inputStream from the connection + // throws an exception rather than returning null when the InputStream does not exist. + InputStream is = null; + try { + is = connection.getInputStream(); + } catch (Exception e1) { + // ignore this + } + if (is != null) { + is.close(); + } + + } catch (IOException ex) { + logger.error("Failed to close connection: " + ex, ex); + } + connection.disconnect(); + } + } + return responseString; + + } + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/utils/PolicyContainer.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/utils/PolicyContainer.java new file mode 100644 index 000000000..fdca336ea --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/utils/PolicyContainer.java @@ -0,0 +1,121 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.utils; + +import java.io.Serializable; +import java.util.Collection; +import java.util.List; + + +public interface PolicyContainer extends Serializable{ + + public Collection getContainerPropertyIds(); + + public Collection getItemIds(); + + public Class getType(Object propertyId); + + public int size(); + + public boolean containsId(Object itemId); + + public Object addItem() throws UnsupportedOperationException; + + public boolean removeItem(Object itemId) + throws UnsupportedOperationException; + + public boolean addContainerProperty(Object propertyId, Class type, + Object defaultValue) throws UnsupportedOperationException; + + public boolean removeContainerProperty(Object propertyId) + throws UnsupportedOperationException; + + public boolean removeAllItems() throws UnsupportedOperationException; + + public interface Ordered extends PolicyContainer { + + public Object nextItemId(Object itemId); + + public Object prevItemId(Object itemId); + + public Object firstItemId(); + + public Object lastItemId(); + + public boolean isFirstId(Object itemId); + + public boolean isLastId(Object itemId); + + public Object addItemAfter(Object previousItemId) + throws UnsupportedOperationException; + + } + + + public interface Indexed extends Ordered { + + public int indexOfId(Object itemId); + + public Object getIdByIndex(int index); + + public List getItemIds(int startIndex, int numberOfItems); + + public Object addItemAt(int index) throws UnsupportedOperationException; + + public interface ItemAddEvent extends ItemSetChangeEvent { + + public Object getFirstItemId(); + + public int getFirstIndex(); + + public int getAddedItemsCount(); + } + + + public interface ItemRemoveEvent extends ItemSetChangeEvent { + + public Object getFirstItemId(); + + public int getFirstIndex(); + + public int getRemovedItemsCount(); + } + } + + public interface ItemSetChangeEvent extends Serializable { + + public PolicyContainer getContainer(); + } + + public interface ItemSetChangeListener extends Serializable { + + public void containerItemSetChange(PolicyContainer.ItemSetChangeEvent event); + } + + public interface ItemSetChangeNotifier extends Serializable { + + public void addItemSetChangeListener( + PolicyContainer.ItemSetChangeListener listener); + + public void removeItemSetChangeListener( + PolicyContainer.ItemSetChangeListener listener); + } +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/utils/PolicyItemSetChangeNotifier.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/utils/PolicyItemSetChangeNotifier.java new file mode 100644 index 000000000..934c30564 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/utils/PolicyItemSetChangeNotifier.java @@ -0,0 +1,95 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.utils; + + +import java.io.Serializable; +import java.util.Collection; +import java.util.EventObject; +import java.util.LinkedList; + +import org.openecomp.policy.utils.PolicyContainer.ItemSetChangeEvent; +import org.openecomp.policy.utils.PolicyContainer.ItemSetChangeListener; + + + +public class PolicyItemSetChangeNotifier implements PolicyContainer.ItemSetChangeNotifier { + private static final long serialVersionUID = 1L; + private Collection itemSetChangeListeners = null; + private PolicyContainer container = null; + + public PolicyItemSetChangeNotifier() { + } + + protected void setContainer(PolicyContainer c) { + this.container = c; + } + + @Override + public void addItemSetChangeListener(ItemSetChangeListener listener) { + if (getItemSetChangeListeners() == null) { + setItemSetChangeListeners(new LinkedList()); + } + getItemSetChangeListeners().add(listener); } + + @Override + public void removeItemSetChangeListener(ItemSetChangeListener listener) { + if (getItemSetChangeListeners() != null) { + getItemSetChangeListeners().remove(listener); + } + } + + protected static class BaseItemSetChangeEvent extends EventObject implements + PolicyContainer.ItemSetChangeEvent, Serializable { + private static final long serialVersionUID = 1L; + + protected BaseItemSetChangeEvent(PolicyContainer source) { + super(source); + } + + @Override + public PolicyContainer getContainer() { + return (PolicyContainer) getSource(); + } + } + + protected void setItemSetChangeListeners( + Collection itemSetChangeListeners) { + this.itemSetChangeListeners = itemSetChangeListeners; + } + protected Collection getItemSetChangeListeners() { + return itemSetChangeListeners; + } + + protected void fireItemSetChange() { + fireItemSetChange(new BaseItemSetChangeEvent(this.container)); + } + + protected void fireItemSetChange(ItemSetChangeEvent event) { + if (getItemSetChangeListeners() != null) { + final Object[] l = getItemSetChangeListeners().toArray(); + for (int i = 0; i < l.length; i++) { + ((PolicyContainer.ItemSetChangeListener) l[i]) + .containerItemSetChange(event); + } + } + } +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/policy/utils/XACMLPolicyWriterWithPapNotify.java b/ecomp-sdk-app/src/main/java/org/openecomp/policy/utils/XACMLPolicyWriterWithPapNotify.java new file mode 100644 index 000000000..20bfa1a50 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/policy/utils/XACMLPolicyWriterWithPapNotify.java @@ -0,0 +1,494 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.utils; + + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.UnsupportedEncodingException; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.ProtocolException; +import java.net.URL; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import java.nio.file.DirectoryNotEmptyException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Base64; +import java.util.UUID; + +import org.openecomp.policy.rest.XACMLRestProperties; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; +import org.openecomp.policy.xacml.util.XACMLPolicyWriter; +import com.att.research.xacml.util.XACMLProperties; + +import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicySetType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +/** + * Helper static class that wraps XACMLPolicyWriter + * + * + */ +public class XACMLPolicyWriterWithPapNotify{ + private static final Logger logger = FlexLogger.getLogger(XACMLPolicyWriterWithPapNotify.class); + + /** + * Helper static class that does the work to write a policy set to a file on disk and notify PAP + * + * + */ + public static Path writePolicyFile(Path filename, PolicySetType policySet) { + if(logger.isDebugEnabled()){ + logger.debug("\nXACMLPolicyWriterWithPapNotify.writePolicyFile(Path filename, PolicySetType policySet)" + + "\nfilename = " + filename + + "\npolicySet = " + policySet); + } + //write to file + Path path = XACMLPolicyWriter.writePolicyFile(filename, policySet); + + if(path!=null){ + //write to DB + if(notifyPapOfCreateUpdate(filename.toAbsolutePath().toString())){ + return path; + }else{ + //write to DB failed. So, delete the file + try{ + Files.deleteIfExists(path); + }catch(DirectoryNotEmptyException e){ + //We are trying to delete a directory and it is not empty + logger.error("\nXACMLPolicyWriterWithPapNotify.writePolicyFile(Path filename, PolicySetType policySet): Files.deleteIfExists(path)" + + "\nDirectoryNotEmptyException for path = " + path + + "\nException message = " + e); + }catch(IOException e) { + // File permission problems are caught here. + logger.error("\nXACMLPolicyWriterWithPapNotify.writePolicyFile(Path filename, PolicySetType policySet): Files.deleteIfExists(path)" + + "\nIOException for path = " + path + + "\nException message = " + e); + }catch(Exception e){ + logger.error("\nXACMLPolicyWriterWithPapNotify.writePolicyFile(Path filename, PolicySetType policySet): Files.deleteIfExists(path)" + + "\nException for path = " + path + + "\nException message = " + e); + } + return null; + } + + }else{ + return null; + } + } + + /** + * Helper static class that does the work to write a policy set to an output stream and notify PAP + * + * + */ + public static void writePolicyFile(OutputStream os, PolicySetType policySet) { + if(logger.isDebugEnabled()){ + logger.debug("\nXACMLPolicyWriterWithPapNotify.writePolicyFile(OutputStream os, PolicySetType policySet)" + + "\nos = " + os + + "\npolicySet = " + policySet); + } + //Only used for writing a byte array output stream for a message. No file is written + XACMLPolicyWriter.writePolicyFile(os, policySet); + } + + /** + * Helper static class that does the work to write a policy to a file on disk. + * + * + */ + public static Path writePolicyFile(Path filename, PolicyType policy) { + if(logger.isDebugEnabled()){ + logger.debug("\nXACMLPolicyWriterWithPapNotify.writePolicyFile(Path filename, PolicyType policy)" + + "\nfilename = " + filename + + "\npolicy = " + policy); + } + + //write to file + Path path = XACMLPolicyWriter.writePolicyFile(filename, policy); + + if(path!=null){ + //write to DB + if(notifyPapOfCreateUpdate(filename.toAbsolutePath().toString())){ + return path; + }else{ + //write to DB failed so delete the file + try{ + Files.deleteIfExists(path); + }catch(DirectoryNotEmptyException e){ + //We are trying to delete a directory and it is not empty + logger.error("\nXACMLPolicyWriterWithPapNotify.writePolicyFile(Path filename, PolicySetType policySet)Files.deleteIfExists(path) :" + + "\nDirectoryNotEmptyException for path = " + path + + "\nException message = " + e); + }catch(IOException e) { + // File permission problems are caught here. + logger.error("\nXACMLPolicyWriterWithPapNotify.writePolicyFile(Path filename, PolicySetType policySet): Files.deleteIfExists(path)" + + "\nIOException for path = " + path + + "\nException message = " + e); + }catch(Exception e){ + logger.error("\nXACMLPolicyWriterWithPapNotify.writePolicyFile(Path filename, PolicySetType policySet): Files.deleteIfExists(path)" + + "\nException for path = " + path + + "\nException message = " + e); + } + return null; + } + + }else{ + return null; + } + } + + + /** + * Helper static class that does the work to write a policy to a file on disk. + * + * + */ + public static InputStream getXmlAsInputStream(PolicyType policy) { + if(logger.isDebugEnabled()){ + logger.debug("\nXACMLPolicyWriterWithPapNotify.getXmlAsInputStream(PolicyType policy)" + + "\npolicy = " + policy); + } + return XACMLPolicyWriter.getXmlAsInputStream(policy); + } + /** + * Helper static class that does the work to write a policy set to an output stream. + * + * + */ + public static void writePolicyFile(OutputStream os, PolicyType policy) { + if(logger.isDebugEnabled()){ + logger.debug("\nXACMLPolicyWriterWithPapNotify.writePolicyFile(OutputStream os, PolicyType policy)" + + "\nos = " + os + + "\npolicy = " + policy); + } + //There are no references to this and if there were, it would most likely be used in an http message + XACMLPolicyWriter.writePolicyFile(os, policy); + } + + public static String changeFileNameInXmlWhenRenamePolicy(Path filename) { + if(logger.isDebugEnabled()){ + logger.debug("\nXACMLPolicyWriterWithPapNotify.changeFileNameInXmlWhenRenamePolicy(Path filename)" + + "\nfilename = " + filename); + } + return XACMLPolicyWriter.changeFileNameInXmlWhenRenamePolicy(filename); + } + + public static boolean notifyPapOfPolicyRename(String oldPolicyName, String newPolicyName){ + if(logger.isDebugEnabled()){ + logger.debug("\nXACMLPolicyWriterWithPapNotify.notifyPapOfCreateUpdate(String policyToCreateUpdate) " + + "\npolicyToCreateUpdate = " + " "); + } + Base64.Encoder encoder = Base64.getEncoder(); + String encoding = encoder.encodeToString((XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_USERID)+":"+XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_PASS)).getBytes(StandardCharsets.UTF_8)); + HttpURLConnection connection = null; + UUID requestID = UUID.randomUUID(); + //loggingContext.setRequestID(requestID.toString()); + //loggingContext.transactionStarted(); + URL url; + try { + url = new URL(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_URL)+"?oldPolicyName="+ URLEncoder.encode(oldPolicyName, "UTF-8")+"&newPolicyName="+URLEncoder.encode(newPolicyName,"UTF-8")); + if(logger.isDebugEnabled()){ + logger.debug("\nnotifyPapOfCreateUpdate: URL = " + url); + } + } catch (MalformedURLException e) { + logger.error("\nnotifyPapOfCreateUpdate(String policyToCreateUpdate)" + + "\nMalformedURLException message = " + e); + + return false; + } catch (UnsupportedEncodingException e) { + logger.error("\nnotifyPapOfCreateUpdate(String policyToCreateUpdate)" + + "\nUnsupportedEncodingException message = " + e); + + return false; + } + // + // Open up the connection + // + try { + connection = (HttpURLConnection)url.openConnection(); + } catch (IOException e) { + logger.error("\nnotifyPapOfCreateUpdate(String policyToCreateUpdate)" + + "\nurl.openConnection() IOException message = " + e); + return false; + } + // + // Setup our method and headers + // + try { + connection.setRequestMethod("PUT"); + } catch (ProtocolException e) { + logger.error("\nnotifyPapOfCreateUpdate(String policyToCreateUpdate)" + + "\nconnection.setRequestMethod(PUT) ProtocolException message = " + e); + connection.disconnect(); + return false; + } + connection.setRequestProperty("Authorization", "Basic " + encoding); + connection.setRequestProperty("Accept", "text/x-java-properties"); + connection.setRequestProperty("Content-Type", "text/x-java-properties"); + connection.setRequestProperty("requestID", requestID.toString()); + connection.setUseCaches(false); + // + // Adding this in. It seems the HttpUrlConnection class does NOT + // properly forward our headers for POST re-direction. It does so + // for a GET re-direction. + // + // So we need to handle this ourselves. + // + connection.setInstanceFollowRedirects(false); + connection.setDoOutput(true); + connection.setDoInput(true); + try { + connection.connect(); + } catch (IOException e) { + logger.error("\nnotifyPapOfCreateUpdate(String policyToCreateUpdate)" + + "\nconnection.connect() IOException message = " + e); + connection.disconnect(); + return false; + } + try { + int responseCode = connection.getResponseCode(); + if(logger.isDebugEnabled()){ + logger.debug("\nnotifyPapOfCreateUpdate(String policyToCreateUpdate)" + + "\nconnection.getResponseCode() = " + responseCode); + } + if (responseCode == 200) { + connection.disconnect(); + return true; + } else { + connection.disconnect(); + return false; + //System.out.println(connection.getResponseMessage()); + //System.out.println(connection.getResponseCode()); + //System.out.println(connection.g); + } + } catch (IOException e) { + logger.error("\nnotifyPapOfCreateUpdate(String policyToCreateUpdate)" + + "\nconnection.getResponseCode() IOException message = " + e); + connection.disconnect(); + return false; + } + } + + public static boolean notifyPapOfDelete(String policyToDelete){ + Base64.Encoder encoder = Base64.getEncoder(); + String encoding = encoder.encodeToString((XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_USERID)+":"+XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_PASS)).getBytes(StandardCharsets.UTF_8)); + HttpURLConnection connection = null; + UUID requestID = UUID.randomUUID(); + //loggingContext.setRequestID(requestID.toString()); + //loggingContext.transactionStarted(); + String papUrl = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_URL); + if(papUrl == null){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + + "PAP url property does not exist"); + return false; + } + String urlString = ""; + try{ + urlString = papUrl+"?groupId=0&isDeleteNotify=1&policyToDelete="+ URLEncoder.encode(policyToDelete, "UTF-8"); + } catch(UnsupportedEncodingException e){ + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + + "Invalid encoding: UTF-8", e); + return false; + } + URL url; + try { + url = new URL(urlString); + } catch (MalformedURLException e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + + "Error parsing PAP url: " + + urlString + , e); + return false; + } + // + // Open up the connection + // + try { + connection = (HttpURLConnection)url.openConnection(); + } catch (IOException e) { + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + + "Error opening HttpURLConnection to: " + + url.toString() + , e); + return false; + } + // + // Setup our method and headers + // + try { + connection.setRequestMethod("DELETE"); + } catch (ProtocolException e) { + logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + + "Invalid request method: DELETE", e); + connection.disconnect(); + return false; + } + connection.setRequestProperty("Authorization", "Basic " + encoding); + connection.setRequestProperty("Accept", "text/x-java-properties"); + connection.setRequestProperty("Content-Type", "text/x-java-properties"); + connection.setRequestProperty("requestID", requestID.toString()); + connection.setUseCaches(false); + // + // Adding this in. It seems the HttpUrlConnection class does NOT + // properly forward our headers for POST re-direction. It does so + // for a GET re-direction. + // + // So we need to handle this ourselves. + // + connection.setInstanceFollowRedirects(false); + connection.setDoOutput(true); + connection.setDoInput(true); + try { + connection.connect(); + } catch (IOException e) { + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + + "Error connecting HttpURLConnection to: " + + connection.getURL().toString() + , e); + connection.disconnect(); + return false; + } + try { + if (connection.getResponseCode() == 200) { + connection.disconnect(); + //worked + return true; + } else { + connection.disconnect(); + return false; + //System.out.println(connection.getResponseMessage()); + //System.out.println(connection.getResponseCode()); + //System.out.println(connection.g); + } + } catch (IOException e) { + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + + "Error getting HttpUrlConnection response code for: " + + connection.getURL().toString() + , e); + connection.disconnect(); + return false; + } + } + + public static boolean notifyPapOfCreateUpdate(String policyToCreateUpdate){ + if(logger.isDebugEnabled()){ + logger.debug("\nXACMLPolicyWriterWithPapNotify.notifyPapOfCreateUpdate(String policyToCreateUpdate) " + + "\npolicyToCreateUpdate = " + policyToCreateUpdate); + } + Base64.Encoder encoder = Base64.getEncoder(); + String encoding = encoder.encodeToString((XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_USERID)+":"+XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_PASS)).getBytes(StandardCharsets.UTF_8)); + HttpURLConnection connection = null; + UUID requestID = UUID.randomUUID(); + //loggingContext.setRequestID(requestID.toString()); + //loggingContext.transactionStarted(); + URL url; + try { + url = new URL(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_URL)+"?policyToCreateUpdate="+ URLEncoder.encode(policyToCreateUpdate, "UTF-8")); + if(logger.isDebugEnabled()){ + logger.debug("\nnotifyPapOfCreateUpdate: URL = " + url); + } + } catch (MalformedURLException e) { + logger.error("\nnotifyPapOfCreateUpdate(String policyToCreateUpdate)" + + "\nMalformedURLException message = " + e); + + return false; + } catch (UnsupportedEncodingException e) { + logger.error("\nnotifyPapOfCreateUpdate(String policyToCreateUpdate)" + + "\nUnsupportedEncodingException message = " + e); + + return false; + } + // + // Open up the connection + // + try { + connection = (HttpURLConnection)url.openConnection(); + } catch (IOException e) { + logger.error("\nnotifyPapOfCreateUpdate(String policyToCreateUpdate)" + + "\nurl.openConnection() IOException message = " + e); + return false; + } + // + // Setup our method and headers + // + try { + connection.setRequestMethod("PUT"); + } catch (ProtocolException e) { + logger.error("\nnotifyPapOfCreateUpdate(String policyToCreateUpdate)" + + "\nconnection.setRequestMethod(PUT) ProtocolException message = " + e); + connection.disconnect(); + return false; + } + connection.setRequestProperty("Authorization", "Basic " + encoding); + connection.setRequestProperty("Accept", "text/x-java-properties"); + connection.setRequestProperty("Content-Type", "text/x-java-properties"); + connection.setRequestProperty("requestID", requestID.toString()); + connection.setUseCaches(false); + // + // Adding this in. It seems the HttpUrlConnection class does NOT + // properly forward our headers for POST re-direction. It does so + // for a GET re-direction. + // + // So we need to handle this ourselves. + // + connection.setInstanceFollowRedirects(false); + connection.setDoOutput(true); + connection.setDoInput(true); + try { + connection.connect(); + } catch (IOException e) { + logger.error("\nnotifyPapOfCreateUpdate(String policyToCreateUpdate)" + + "\nconnection.connect() IOException message = " + e); + connection.disconnect(); + return false; + } + try { + int responseCode = connection.getResponseCode(); + if(logger.isDebugEnabled()){ + logger.debug("\nnotifyPapOfCreateUpdate(String policyToCreateUpdate)" + + "\nconnection.getResponseCode() = " + responseCode); + } + if (responseCode == 200) { + connection.disconnect(); + return true; + } else { + connection.disconnect(); + return false; + //System.out.println(connection.getResponseMessage()); + //System.out.println(connection.getResponseCode()); + //System.out.println(connection.g); + } + } catch (IOException e) { + logger.error("\nnotifyPapOfCreateUpdate(String policyToCreateUpdate)" + + "\nconnection.getResponseCode() IOException message = " + e); + connection.disconnect(); + return false; + } + } +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/conf/ExternalAppConfig.java b/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/conf/ExternalAppConfig.java new file mode 100644 index 000000000..ff9f0f1ab --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/conf/ExternalAppConfig.java @@ -0,0 +1,188 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +package org.openecomp.portalapp.conf; + +import java.util.ArrayList; +import java.util.List; + +import org.openecomp.portalapp.scheduler.RegistryAdapter; +import org.openecomp.portalapp.uebhandler.InitUebHandler; +import org.openecomp.portalapp.uebhandler.MainUebHandler; +import org.openecomp.portalapp.uebhandler.WidgetNotificationHandler; +import org.openecomp.portalsdk.core.conf.AppConfig; +import org.openecomp.portalsdk.core.conf.Configurable; +import org.openecomp.portalsdk.core.objectcache.AbstractCacheManager; +import org.openecomp.portalsdk.core.service.DataAccessService; +import org.openecomp.portalsdk.core.util.CacheManager; +import org.openecomp.portalsdk.core.util.SystemProperties; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; +import org.springframework.context.annotation.Profile; +import org.springframework.context.annotation.PropertySource; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.scheduling.quartz.SchedulerFactoryBean; +import org.springframework.web.servlet.ViewResolver; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; + +/** + * Configures Spring features in the ECOMP Portal SDK sample application. + * Subclasses the ECOMP Portal SDK core AppConfig class to reuse interceptors, + * view resolvers and other features defined there. + */ +@Configuration +@EnableWebMvc +@ComponentScan(basePackages = "org.openecomp") +@PropertySource(value = { "${container.classpath:}/WEB-INF/conf/app/test.properties" }, ignoreResourceNotFound = true) +@Profile("src") +@EnableAsync +@EnableScheduling +public class ExternalAppConfig extends AppConfig implements Configurable { + + private RegistryAdapter schedulerRegistryAdapter; + + @Configuration + @Import(SystemProperties.class) + static class InnerConfiguration { + } + + /** + * @see org.openecomp.portalsdk.core.conf.AppConfig#viewResolver() + */ + public ViewResolver viewResolver() { + return super.viewResolver(); + } + + /** + * @see org.openecomp.portalsdk.core.conf.AppConfig#addResourceHandlers(ResourceHandlerRegistry) + * + * @param registry + */ + public void addResourceHandlers(ResourceHandlerRegistry registry) { + super.addResourceHandlers(registry); + } + + /** + * @see org.openecomp.portalsdk.core.conf.AppConfig#dataAccessService() + */ + public DataAccessService dataAccessService() { + return super.dataAccessService(); + } + + /** + * Creates a new list with a single entry that is the external app + * definitions.xml path. + * + * @return List of String, size 1 + */ + public List addTileDefinitions() { + List definitions = new ArrayList(); + definitions.add("/WEB-INF/defs/definitions.xml"); + return definitions; + } + + /** + * Adds request interceptors to the specified registry by calling + * {@link AppConfig#addInterceptors(InterceptorRegistry)}, but excludes + * certain paths from the session timeout interceptor. + */ + @Override + public void addInterceptors(InterceptorRegistry registry) { + super.setExcludeUrlPathsForSessionTimeout("/login_external", "*/login_external.htm", "login", "/login.htm", + "/api*","/single_signon.htm","/single_signon"); + super.addInterceptors(registry); + } + + /** + * Creates and returns a new instance of a {@link CacheManager} class. + * + * @return New instance of {@link CacheManager} + */ + @Bean + public AbstractCacheManager cacheManager() { + return new CacheManager(); + } + + /** + * Creates and returns a new instance of a {@link MainUebHandler}. + * + * @return New instance of {@link MainUebHandler}. + */ + @Bean + public MainUebHandler mainUebHandler() { + + return new MainUebHandler(); + } + + /** + * Creates and returns a new instance of a {@link InitUebHandler}. + * + * @return New instance of {@link InitUebHandler}. + */ + @Bean + public InitUebHandler initUebHandler() { + + return new InitUebHandler(); + } + + /** + * Creates and returns a new instance of a {@link WidgetNotificationHandler} + * . + * + * @return New instance of {@link WidgetNotificationHandler}. + */ + @Bean + public WidgetNotificationHandler widgetNotificationHandler() { + return new WidgetNotificationHandler(); + } + + /** + * Creates and returns a new instance of a {@link SchedulerFactoryBean} and + * populates it with triggers. + * + * @return New instance of {@link SchedulerFactoryBean} + * @throws Exception + */ + // @Bean // ANNOTATION COMMENTED OUT + // APPLICATIONS REQUIRING QUARTZ SHOULD RESTORE ANNOTATION + public SchedulerFactoryBean schedulerFactoryBean() throws Exception { + SchedulerFactoryBean scheduler = new SchedulerFactoryBean(); + scheduler.setTriggers(schedulerRegistryAdapter.getTriggers()); + scheduler.setConfigLocation(appApplicationContext.getResource("WEB-INF/conf/quartz.properties")); + scheduler.setDataSource(dataSource()); + return scheduler; + } + + + /** + * Sets the scheduler registry adapter. + * + * @param schedulerRegistryAdapter + */ + @Autowired + public void setSchedulerRegistryAdapter(final RegistryAdapter schedulerRegistryAdapter) { + this.schedulerRegistryAdapter = schedulerRegistryAdapter; + } +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/conf/ExternalAppInitializer.java b/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/conf/ExternalAppInitializer.java new file mode 100644 index 000000000..dfdfcadec --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/conf/ExternalAppInitializer.java @@ -0,0 +1,60 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +package org.openecomp.portalapp.conf; + +import java.util.Arrays; + +import org.openecomp.portalsdk.core.conf.AppInitializer; + +public class ExternalAppInitializer extends AppInitializer{ + + + @Override + protected Class[] getRootConfigClasses() { + return super.getRootConfigClasses(); + } + + @Override + protected Class[] getServletConfigClasses() { +// Class[] configClasses = super.getServletConfigClasses(); +// Class[] additionalConfigClasses = Arrays.copyOf(configClasses, configClasses.length); +// addConfigClass(additionalConfigClasses, ExternalAppConfig.class); +// return additionalConfigClasses; +// + return new Class[] {ExternalAppConfig.class}; + } + + static Class[] addConfigClass(Class[] a, Class e) { + a = Arrays.copyOf(a, a.length + 1); + a[a.length - 1] = e; + return a; + } + + /* + * URL request will direct to the Spring dispatcher for processing + */ + @Override + protected String[] getServletMappings() { + return super.getServletMappings(); + } + +} + + diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/conf/HibernateMappingLocations.java b/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/conf/HibernateMappingLocations.java new file mode 100644 index 000000000..3e1d89d25 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/conf/HibernateMappingLocations.java @@ -0,0 +1,37 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +package org.openecomp.portalapp.conf; + +import org.openecomp.portalsdk.core.conf.HibernateMappingLocatable; +import org.springframework.context.annotation.Profile; +import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.Resource; +import org.springframework.stereotype.Component; + +@Component +@Profile("src") +public class HibernateMappingLocations implements HibernateMappingLocatable { + + public Resource[] getMappingLocations() { + return new Resource[]{new ClassPathResource("../fusion/orm/Fusion.hbm.xml"), new ClassPathResource("../fusion/orm/Workflow.hbm.xml"), new ClassPathResource("../fusion/orm/RNoteBookIntegration.hbm.xml")}; + } + + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/controller/AngularSinglePageController.java b/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/controller/AngularSinglePageController.java new file mode 100644 index 000000000..e654a51c0 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/controller/AngularSinglePageController.java @@ -0,0 +1,48 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +package org.openecomp.portalapp.controller; + +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; + +import org.openecomp.portalsdk.core.controller.RestrictedBaseController; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.servlet.ModelAndView; + +/** + * Controller for a single-page application sample. The view is restricted to + * authenticated users. The named view resolves to page singlePageSample.html, + * which uses Angular. + */ +@Controller +@RequestMapping("/") +public class AngularSinglePageController extends RestrictedBaseController { + + @RequestMapping(value = { "/singlePageSample" }, method = RequestMethod.GET) + public ModelAndView view(HttpServletRequest request) { + Map model = new HashMap(); + return new ModelAndView("single_page_sample", "model", model); + } + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/controller/CallflowController.java b/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/controller/CallflowController.java new file mode 100644 index 000000000..a3d1be5f0 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/controller/CallflowController.java @@ -0,0 +1,44 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +package org.openecomp.portalapp.controller; + +import org.openecomp.portalsdk.core.controller.RestrictedBaseController; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.servlet.ModelAndView; + +/** + * Controller for a message sequence chart view. The view is restricted to + * authenticated users. The view name defaults to the request name with no + * suffix, "callflow", which resolves to page details.jsp. That page is an + * iframe around page details.html. + */ +@Controller +@RequestMapping("/") +public class CallflowController extends RestrictedBaseController { + + @RequestMapping(value = { "/callflow" }, method = RequestMethod.GET) + public ModelAndView plot() { + final String defaultViewName = null; + return new ModelAndView(defaultViewName); + } + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/controller/ElasticSearchController.java b/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/controller/ElasticSearchController.java new file mode 100644 index 000000000..69ff63db6 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/controller/ElasticSearchController.java @@ -0,0 +1,128 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +package org.openecomp.portalapp.controller; + +import java.io.IOException; + +import org.json.JSONObject; +import org.openecomp.portalapp.model.Result; +import org.openecomp.portalsdk.core.controller.RestrictedBaseController; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.servlet.ModelAndView; + +import io.searchbox.client.JestClient; +import io.searchbox.client.JestClientFactory; +import io.searchbox.client.config.HttpClientConfig; +import io.searchbox.core.Search; +import io.searchbox.core.SearchResult; +import io.searchbox.core.Suggest; +import io.searchbox.core.SuggestResult; +import io.searchbox.params.Parameters; + +/** + * Controller for views that demonstrate Elastic Search features. + */ +@RestController +public class ElasticSearchController extends RestrictedBaseController{ + + @RequestMapping(value = {"/es_search_demo" }, method = RequestMethod.GET) + public ModelAndView search() { + return new ModelAndView("es_search_demo"); + } + + @RequestMapping(value = {"/es_suggest_demo" }, method = RequestMethod.GET) + public ModelAndView suggest() { + return new ModelAndView("es_suggest_demo"); + } + + @RequestMapping(value="/es_suggest/{task}",method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity doSuggest(@PathVariable("task") String task) throws IOException { + JSONObject obj = new JSONObject(task); + String searchTerm = obj.getString("data"); + String searchSize = obj.getString("size"); + String searchFuzzy = obj.getString("fuzzy"); + String resultName = obj.getString("resultname"); + + JestClientFactory factory = new JestClientFactory(); + factory.setHttpClientConfig(new HttpClientConfig + .Builder("http://todo_elastic_search_server") + .multiThreaded(true) + .build()); + JestClient client = factory.getObject(); + + + Suggest suggest = new Suggest.Builder("{\n" + +"\"" + resultName +"\" : {\n" + +"\"text\" : \""+ searchTerm +"\",\n" + +"\"completion\" : {\n" + +"\"field\" : \"suggest\",\n" + +"\"size\" : " + searchSize + ",\n" + +"\"fuzzy\" : \"" + searchFuzzy + "\"\n" + +"}\n" + +"}\n" + +"}").addIndex("customer").build(); + + SuggestResult result = client.execute(suggest); + System.err.println(result.getJsonObject().toString()); + return new ResponseEntity(new Result(result.getJsonObject().toString()),HttpStatus.OK); + } + + @RequestMapping(value="/es_search/{task}",method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity doSearch(@PathVariable("task") String task) throws IOException { + JSONObject obj = new JSONObject(task); + String searchTerm = obj.getString("data"); + String searchSize = obj.getString("size"); + // String searchFuzzy = obj.getString("fuzzy"); + + JestClientFactory factory = new JestClientFactory(); + factory.setHttpClientConfig(new HttpClientConfig + .Builder("http://todo_elastic_search_server") + .multiThreaded(true) + .build()); + JestClient client = factory.getObject(); + + Search search = new Search.Builder("{\n" + +"\"query\" : {\n" + +"\"query_string\" : {\n" + +"\"query\" : \"name:"+ searchTerm +"\"\n" + +"}\n" + +"}\n" + +"}").addIndex("customer").setParameter(Parameters.SIZE,Integer.valueOf(searchSize)).build(); + + SearchResult result = client.execute(search); + System.err.println(result.getJsonObject().toString()); + return new ResponseEntity(new Result(result.getJsonObject().toString()),HttpStatus.OK); + } + + public ResponseEntity sendResult(Result result) { + return new ResponseEntity(result, HttpStatus.OK); + } + + @Override + public boolean isRESTfulCall() { + return true; + } +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/controller/LeafletMapContoller.java b/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/controller/LeafletMapContoller.java new file mode 100644 index 000000000..4c603fe19 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/controller/LeafletMapContoller.java @@ -0,0 +1,43 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +package org.openecomp.portalapp.controller; + +import org.openecomp.portalsdk.core.controller.RestrictedBaseController; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.servlet.ModelAndView; + +/** + * Controller for geographic map view. The view is restricted to authenticated + * users. The view name defaults to the request name with no suffix, + * "leafletMap", which resolves to page leafletMap.jsp. + */ +@Controller +@RequestMapping("/") +public class LeafletMapContoller extends RestrictedBaseController { + + @RequestMapping(value = { "/leafletMap" }, method = RequestMethod.GET) + public ModelAndView plot() { + final String defaultViewName = null; + return new ModelAndView(defaultViewName); + } + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/controller/PostDroolsController.java b/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/controller/PostDroolsController.java new file mode 100644 index 000000000..2729e8731 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/controller/PostDroolsController.java @@ -0,0 +1,138 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +package org.openecomp.portalapp.controller; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.json.JSONObject; +import org.openecomp.portalsdk.core.command.PostDroolsBean; +import org.openecomp.portalsdk.core.controller.RestrictedBaseController; +import org.openecomp.portalsdk.core.service.PostDroolsService; +import org.openecomp.portalsdk.core.web.support.JsonMessage; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.servlet.ModelAndView; + +import com.fasterxml.jackson.core.JsonGenerationException; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +@Controller +@RequestMapping("/") +public class PostDroolsController extends RestrictedBaseController{ + + @Autowired + private PostDroolsService postDroolsService; + + @RequestMapping(value = {"/drools" }, method = RequestMethod.GET) + public ModelAndView drools(HttpServletRequest request) { + + return new ModelAndView(getViewName()); + } + + + @RequestMapping(value = {"/getDrools" }, method = RequestMethod.GET) + public void getDrools(HttpServletRequest request, HttpServletResponse response) { + // Map model = new HashMap(); + + ObjectMapper mapper = new ObjectMapper(); + try { + List beanList = postDroolsService.fetchDroolBeans(); + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(beanList)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + + } catch (JsonGenerationException e) { + e.printStackTrace(); + } catch (JsonMappingException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @RequestMapping(value = {"/getDroolDetails" }, method = RequestMethod.GET) + public void getDroolDetails(HttpServletRequest request, HttpServletResponse response) { + + ObjectMapper mapper = new ObjectMapper(); + try { + + PostDroolsBean postDroolsBean = new PostDroolsBean(); + String selectedFile = request.getParameter("selectedFile"); + postDroolsBean.setDroolsFile(selectedFile);//sample populated + //postDroolsBean.setSelectedRules("[\"NJ\",\"NY\",\"KY\"]"); + postDroolsBean.setClassName(postDroolsService.retrieveClass(selectedFile)); + + JsonMessage msg = new JsonMessage(mapper.writeValueAsString(postDroolsBean)); + JSONObject j = new JSONObject(msg); + response.getWriter().write(j.toString()); + + } catch (JsonGenerationException e) { + e.printStackTrace(); + } catch (JsonMappingException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @RequestMapping(value = {"/post_drools/execute" }, method = RequestMethod.POST) + public ModelAndView search(HttpServletRequest request, + HttpServletResponse response) throws Exception { + try { + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + PostDroolsBean postDroolsBean = mapper.readValue(root.get("postDroolsBean").toString(), PostDroolsBean.class); + + String resultsString = postDroolsService.execute(postDroolsBean.getDroolsFile(), postDroolsBean.getClassName(), postDroolsBean.getSelectedRules()); + + response.setCharacterEncoding("UTF-8"); + response.setContentType("application / json"); + request.setCharacterEncoding("UTF-8"); + + PrintWriter out = response.getWriter(); + //String responseString = mapper.writeValueAsString(resultsString); + JSONObject j = new JSONObject("{resultsString: "+resultsString+"}"); + + out.write(j.toString()); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + return null; + } + + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/controller/UserProfileController.java b/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/controller/UserProfileController.java new file mode 100644 index 000000000..2f4ea93de --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/controller/UserProfileController.java @@ -0,0 +1,72 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +package org.openecomp.portalapp.controller; + +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; + +import org.openecomp.portalsdk.core.controller.RestrictedBaseController; +import org.openecomp.portalsdk.core.domain.Profile; +import org.openecomp.portalsdk.core.service.ProfileService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.servlet.ModelAndView; + +import com.fasterxml.jackson.core.JsonGenerationException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +/** + * Controller for user profile view. The view is restricted to authenticated + * users. The view name resolves to page user_profile.jsp which uses Angular. + */ + +@Controller +@RequestMapping("/") +public class UserProfileController extends RestrictedBaseController { + + @Autowired + ProfileService service; + + @RequestMapping(value = { "/user_profile" }, method = RequestMethod.GET) + public ModelAndView ProfileSearch(HttpServletRequest request) { + Map model = new HashMap(); + ObjectMapper mapper = new ObjectMapper(); + List profileList = service.findAll(); + try { + model.put("customerInfo", mapper.writeValueAsString(profileList)); + } catch (JsonGenerationException e) { + e.printStackTrace(); + } catch (JsonMappingException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + + return new ModelAndView("user_profile", "model", model); + } + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/controller/WelcomeController.java b/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/controller/WelcomeController.java new file mode 100644 index 000000000..06853f0e3 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/controller/WelcomeController.java @@ -0,0 +1,43 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +package org.openecomp.portalapp.controller; + +import javax.servlet.http.HttpServletRequest; + +import org.openecomp.portalsdk.core.controller.RestrictedBaseController; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.servlet.ModelAndView; + +/** + * Controller for welcome view. The view is restricted to authenticated users. + * The view name defaults to the request name with no suffix, "welcome", which + * resolves to page welcome.jsp. + */ +@Controller +@RequestMapping("/") +public class WelcomeController extends RestrictedBaseController { + @RequestMapping(value = { "/welcome" }, method = RequestMethod.GET) + public ModelAndView welcome(HttpServletRequest request) { + final String defaultViewName = null; + return new ModelAndView(defaultViewName); + } +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/model/Result.java b/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/model/Result.java new file mode 100644 index 000000000..5e09cb2cc --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/model/Result.java @@ -0,0 +1,37 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +package org.openecomp.portalapp.model; + +public class Result { + private String result; + + public Result(String result) { + this.result = result; + } + + public String getResult() { + return result; + } + + public void setResult(String result) { + this.result = result; + } + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/scheduler/LogJob.java b/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/scheduler/LogJob.java new file mode 100644 index 000000000..b308efbb2 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/scheduler/LogJob.java @@ -0,0 +1,47 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +package org.openecomp.portalapp.scheduler; + +import org.openecomp.portalapp.conf.ExternalAppConfig; +import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.quartz.DisallowConcurrentExecution; +import org.quartz.JobExecutionContext; +import org.quartz.JobExecutionException; +import org.quartz.PersistJobDataAfterExecution; +import org.springframework.scheduling.quartz.QuartzJobBean; + +@PersistJobDataAfterExecution +@DisallowConcurrentExecution +public class LogJob extends QuartzJobBean { + + EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ExternalAppConfig.class); + + + @Override + protected void executeInternal(JobExecutionContext ctx) + throws JobExecutionException { + // JobDataMap dataMap = ctx.getJobDetail().getJobDataMap(); + //int cnt = dataMap.getInt(""); + // JobKey jobKey = ctx.getJobDetail().getKey(); + logger.info(EELFLoggerDelegate.debugLogger, (Runtime.getRuntime().maxMemory() + " " + Runtime.getRuntime().maxMemory())); + + } + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/scheduler/LogRegistry.java b/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/scheduler/LogRegistry.java new file mode 100644 index 000000000..dce9e26bf --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/scheduler/LogRegistry.java @@ -0,0 +1,57 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +package org.openecomp.portalapp.scheduler; + +import java.text.ParseException; +import java.util.HashMap; +import java.util.Map; + +import org.openecomp.portalsdk.core.scheduler.CronRegistry; +import org.openecomp.portalsdk.core.util.SystemProperties; +import org.springframework.context.annotation.DependsOn; +import org.springframework.scheduling.quartz.CronTriggerFactoryBean; +import org.springframework.scheduling.quartz.JobDetailFactoryBean; +import org.springframework.stereotype.Component; + +@Component +@DependsOn({ "systemProperties" }) +public class LogRegistry extends CronRegistry { + + private static final String groupName = "AppGroup"; + private static final String jobName = "LogJob"; + private static final String triggerName = "LogTrigger"; + + // @Autowired + // private SystemProperties systemProperties; + + // @Bean + public JobDetailFactoryBean jobDetailFactoryBean() { + Map map = new HashMap(); + map.put("units", "bytes"); + return jobDetailFactoryBean(groupName, jobName, LogJob.class, map); + } + + // @Bean + public CronTriggerFactoryBean cronTriggerFactoryBean() throws ParseException { + // "0 * * * * ? * + return cronTriggerFactoryBean(groupName, triggerName, SystemProperties.getProperty(SystemProperties.LOG_CRON)); + } + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/scheduler/Register.java b/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/scheduler/Register.java new file mode 100644 index 000000000..3a29520ec --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/scheduler/Register.java @@ -0,0 +1,82 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +package org.openecomp.portalapp.scheduler; + +import java.util.ArrayList; +import java.util.List; + +import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.openecomp.portalsdk.core.scheduler.Registerable; +import org.openecomp.portalsdk.core.util.SystemProperties; +import org.quartz.Trigger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.DependsOn; +import org.springframework.stereotype.Component; + +@Component +@DependsOn({"logRegistry", "systemProperties"}) +public class Register implements Registerable { + + EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(Register.class); + + + private List scheduleTriggers = new ArrayList(); + Trigger trigger[] = new Trigger[1]; + + + @Autowired + private LogRegistry logRegistry; + + + + @Override + public Trigger[] getTriggers() { + return getScheduleTriggers().toArray(trigger); + } + + @Override + public void registerTriggers() { + // if the property value is not available; the cron will not be added and can be ignored. its safe to ignore the exceptions + try { + if(SystemProperties.getProperty(SystemProperties.LOG_CRON) != null) + getScheduleTriggers().add(logRegistry.getTrigger()); + + } catch(IllegalStateException ies) { + logger.info(EELFLoggerDelegate.debugLogger, ("Log Cron not available")); + } + + + } + + + public List getScheduleTriggers() { + return scheduleTriggers; + } + + public void setScheduleTriggers(List scheduleTriggers) { + this.scheduleTriggers = scheduleTriggers; + } + + + + + + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/scheduler/RegistryAdapter.java b/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/scheduler/RegistryAdapter.java new file mode 100644 index 000000000..1bc43fee6 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/scheduler/RegistryAdapter.java @@ -0,0 +1,108 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +package org.openecomp.portalapp.scheduler; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.openecomp.portalsdk.core.scheduler.Registerable; +import org.openecomp.portalsdk.workflow.services.WorkflowScheduleService; +import org.quartz.Trigger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.quartz.SchedulerFactoryBean; +import org.springframework.stereotype.Component; + +/** + * TODO REFACTOR + * moved from org.openecomp.portalsdk.core.scheduler + * to org.openecomp.portalapp.scheduler + * + */ +@Component +public class RegistryAdapter { + + @Autowired + private Registerable registry; + + @Autowired + private WorkflowScheduleService workflowScheduleService; + + private SchedulerFactoryBean schedulerBean; + + Trigger trigger[] = new Trigger[1]; + + public Trigger[] getTriggers() { + + registry.registerTriggers(); + + List allTriggers = new ArrayList(); + + List coreTriggers = addCoreTriggers(); + final Trigger[] extTriggerArray = registry.getTriggers(); + + allTriggers.addAll(Arrays.asList(extTriggerArray)); + allTriggers.addAll(coreTriggers); + + return allTriggers.toArray(trigger); + + + } + + + public List addCoreTriggers() { + //On startup of the application after crash recovery, invoke workflow schedule trigger + List triggers = getWorkflowScheduleService().triggerWorkflowScheduling(); + return triggers; + } + + + public void setSchedulerBean(SchedulerFactoryBean _schedulerBean) { + schedulerBean = _schedulerBean; + + } + + public SchedulerFactoryBean getSchedulerBean() { + return schedulerBean; + + } + + + public Registerable getRegistry() { + return registry; + } + + + public void setRegistry(Registerable registry) { + this.registry = registry; + } + + + public WorkflowScheduleService getWorkflowScheduleService() { + return workflowScheduleService; + } + + + public void setWorkflowScheduleService( + WorkflowScheduleService workflowScheduleService) { + this.workflowScheduleService = workflowScheduleService; + } + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/service/AdminAuthExtension.java b/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/service/AdminAuthExtension.java new file mode 100644 index 000000000..1b9e020c5 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/service/AdminAuthExtension.java @@ -0,0 +1,84 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.portalapp.service; + + +import org.openecomp.policy.dao.RolesDao; +import org.openecomp.policy.model.Roles; +import org.openecomp.policy.rest.dao.UserInfoDao; +import org.openecomp.policy.rest.jpa.UserInfo; +import org.openecomp.portalsdk.core.domain.Role; +import org.openecomp.portalsdk.core.domain.User; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; + +@Service("adminAuthExtension") +@Transactional +public class AdminAuthExtension { + + @Autowired + RolesDao rolesDAO; + + @Autowired + UserInfoDao userInfoDao; + + private static Logger logger = FlexLogger.getLogger(AdminAuthExtension.class); + public void saveUserExtension(User user){ + System.out.println("User Object Recieved"); + try{ + Roles roles = new Roles(); + roles.setName(user.getFullName()); + roles.setLoginId(user.getLoginId()); + if(user.getRoles() != null){ + rolesDAO.delete(roles); + for(Role role : user.getRoles()){ + if(role.getName().trim().equalsIgnoreCase("Policy Super Admin") || role.getName().trim().equalsIgnoreCase("System Administrator") || role.getName().trim().equalsIgnoreCase("Standard User") ){ + roles.setRole("super-admin"); + }else if(role.getName().trim().equalsIgnoreCase("Policy Super Editor")){ + roles.setRole("super-editor"); + }else if(role.getName().trim().equalsIgnoreCase("Policy Super Guest")){ + roles.setRole("super-guest"); + }else if(role.getName().trim().equalsIgnoreCase("Policy Admin")){ + roles.setRole("admin"); + }else if(role.getName().trim().equalsIgnoreCase("Policy Editor")){ + roles.setRole("editor"); + }else if(role.getName().trim().equalsIgnoreCase("Policy Guest")){ + roles.setRole("guest"); + } + rolesDAO.save(roles); + } + } + + UserInfo userInfo = new UserInfo(); + userInfo.setUserLoginId(user.getLoginId()); + userInfo.setUserName(user.getFullName()); + userInfoDao.save(userInfo); + } + catch(Exception e){ + logger.error("Exception caused while Setting role to Policy DB"+e); + } + } + +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/service/OnBoardingApiServiceImplPolicy.java b/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/service/OnBoardingApiServiceImplPolicy.java new file mode 100644 index 000000000..083c57683 --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/service/OnBoardingApiServiceImplPolicy.java @@ -0,0 +1,348 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + + +package org.openecomp.portalapp.service; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; + +import javax.servlet.http.HttpServletRequest; + +import org.openecomp.portalsdk.core.domain.Role; +import org.openecomp.portalsdk.core.domain.User; +import org.openecomp.portalsdk.core.domain.UserApp; +import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.openecomp.portalsdk.core.onboarding.client.AppContextManager; +import org.openecomp.portalsdk.core.onboarding.crossapi.IPortalRestAPIService; +import org.openecomp.portalsdk.core.onboarding.crossapi.PortalAPIException; +import org.openecomp.portalsdk.core.onboarding.crossapi.PortalTimeoutHandler; +import org.openecomp.portalsdk.core.restful.domain.EcompRole; +import org.openecomp.portalsdk.core.restful.domain.EcompUser; +import org.openecomp.portalsdk.core.service.RoleService; +import org.openecomp.portalsdk.core.service.UserProfileService; +import org.openecomp.portalsdk.core.service.WebServiceCallService; +import org.openecomp.portalsdk.core.util.JSONUtil; +import org.openecomp.portalsdk.core.util.SystemProperties; +import org.openecomp.portalsdk.core.web.support.UserUtils; +import org.slf4j.MDC; + + +public class OnBoardingApiServiceImplPolicy implements IPortalRestAPIService { + RoleService roleService; + UserProfileService userProfileService; + AdminAuthExtension adminAuthExtension; + + EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(OnBoardingApiServiceImplPolicy.class); + + public OnBoardingApiServiceImplPolicy(){ + roleService = AppContextManager.getAppContext().getBean(RoleService.class); + userProfileService = AppContextManager.getAppContext().getBean(UserProfileService.class); + adminAuthExtension = AppContextManager.getAppContext().getBean(AdminAuthExtension.class); + } + + private void setCurrentAttributes(User user, EcompUser userJson){ + user.setEmail(userJson.getEmail()); + user.setFirstName(userJson.getFirstName()); + user.setHrid(userJson.getHrid()); + user.setJobTitle(userJson.getJobTitle()); + user.setLastName(userJson.getLastName()); + user.setLoginId(userJson.getLoginId()); + user.setOrgManagerUserId(userJson.getOrgManagerUserId()); + user.setMiddleInitial(userJson.getMiddleInitial()); + user.setOrgCode(userJson.getOrgCode()); + user.setOrgId(userJson.getOrgId()); + user.setPhone(userJson.getPhone()); + user.setOrgUserId(userJson.getOrgUserId()); + user.setActive(userJson.isActive()); + } + + + @Override + public void pushUser(EcompUser userJson) throws PortalAPIException { + + logger.debug(EELFLoggerDelegate.debugLogger, "pushUser was invoked" + userJson); + + User user = new User(); + String response = ""; + + logger.debug(EELFLoggerDelegate.debugLogger, "## REST API ## userJson: " + userJson); + + try { + + //Set input attributes to the object about to be saved + setCurrentAttributes(user, userJson); + + user.setRoles(new TreeSet()); + user.setUserApps(new TreeSet()); + user.setPseudoRoles(new TreeSet()); + + userProfileService.saveUser(user); + adminAuthExtension.saveUserExtension(user); + logger.debug(EELFLoggerDelegate.debugLogger, "push user success."); + response = "push user success."; + response = JSONUtil.convertResponseToJSON(response); + } catch (Exception e) { + e.printStackTrace(); + response = "push user failed with error: " + e.getMessage(); + logger.error(EELFLoggerDelegate.debugLogger, response); + logger.error(EELFLoggerDelegate.errorLogger, "Error happened during OnboardingApiService.pushUser operation: " + response); + logger.error(EELFLoggerDelegate.debugLogger, "Error happened during OnboardingApiService.pushUser operation: " + response); + logger.info(EELFLoggerDelegate.metricsLogger, "OnboardingApiService.pushUser operation has failed."); + throw new PortalAPIException(response, e); + }finally { + MDC.remove(SystemProperties.MDC_TIMER); + } + } + + @Override + public void editUser(String loginId, EcompUser userJson) throws PortalAPIException { + + logger.debug(EELFLoggerDelegate.debugLogger, "OnboardingApi editUser was invoked" + userJson); + + User editUser = new User(); + String response = ""; + logger.debug(EELFLoggerDelegate.debugLogger, "## REST API ## loginId: " + loginId); + logger.debug(EELFLoggerDelegate.debugLogger, "## REST API ## userJson: " + userJson); + + try { + + setCurrentAttributes(editUser, userJson); + + if (editUser.getOrgUserId() != null) { + editUser.setLoginId(editUser.getOrgUserId()); + } + + User domainUser = userProfileService.getUserByLoginId(loginId); + if (domainUser != null) + domainUser = JSONUtil.mapToDomainUser(domainUser, editUser); + else + domainUser = editUser; + userProfileService.saveUser(domainUser); + adminAuthExtension.saveUserExtension(domainUser); + + logger.debug(EELFLoggerDelegate.debugLogger, "edit user success."); + response = "edit user success."; + response = JSONUtil.convertResponseToJSON(response); + } catch (Exception e) { + e.printStackTrace(); + response = "edit user failed with error: " + e.getMessage(); + logger.error(EELFLoggerDelegate.errorLogger, response); + logger.error(EELFLoggerDelegate.debugLogger, "Error happened during OnboardingApiService.editUser operation: " + response); + logger.error(EELFLoggerDelegate.errorLogger, "Error happened during OnboardingApiService.editUser operation: " + response); + throw new PortalAPIException(response, e); + }finally { + MDC.remove(SystemProperties.MDC_TIMER); + } + + //return response; + } + + @Override + public EcompUser getUser(String loginId) throws PortalAPIException { + try{ + logger.debug(EELFLoggerDelegate.debugLogger, "## REST API ## loginId: " + loginId); + + User user = userProfileService.getUserByLoginId(loginId); + + if(user == null){ + logger.info(EELFLoggerDelegate.debugLogger, "User + " + loginId + " doesn't exist"); + return null; + } + else + return UserUtils.convertToEcompUser(user); + } + catch(Exception e){ + logger.error(EELFLoggerDelegate.errorLogger, e.getMessage()); + return null; + } + + } + + @Override + public List getUsers() throws PortalAPIException { + + + String response = ""; + + try { + + List users = userProfileService.findAllActive(); + List ecompUsers = new ArrayList(); + for(User user : users) + ecompUsers.add(UserUtils.convertToEcompUser(user)); + + return ecompUsers; + + } + catch (Exception pe){ + + response = "getUsers failed with error: " + pe.getMessage(); + pe.printStackTrace(); + logger.error(EELFLoggerDelegate.debugLogger, response); + logger.error(EELFLoggerDelegate.errorLogger, response); + throw new PortalAPIException(response, pe); + } + + + } + + @Override + public List getAvailableRoles() throws PortalAPIException{ + + String response = ""; + + try{ + List roles = roleService.getActiveRoles(); + List ecompRoles = new ArrayList(); + + for(Role role : roles) + ecompRoles.add(UserUtils.convertToEcompRole(role)); + + return ecompRoles; + + } + catch (Exception pe){ + response = "getUsers failed with error: " + pe.getMessage(); + pe.printStackTrace(); + logger.error(EELFLoggerDelegate.debugLogger, response); + logger.error(EELFLoggerDelegate.errorLogger, response); + throw new PortalAPIException(response, pe); + } + } + + @Override + public void pushUserRole(String loginId, List rolesJson) throws PortalAPIException { + + + String response = ""; + try { + logger.debug(EELFLoggerDelegate.debugLogger, "## REST API ## loginId: " + loginId); + logger.debug(EELFLoggerDelegate.debugLogger, "## REST API ## rolesJson: " + rolesJson); + User user = userProfileService.getUserByLoginId(loginId); + + SortedSet roles = new TreeSet(); + for (EcompRole role : rolesJson) { + roles.add(roleService.getRole(role.getId())); + } + // Replace existing roles with new ones + replaceExistingRoles(roles, user); + + logger.debug(EELFLoggerDelegate.debugLogger, "push user role success."); + response = "push user role success."; + response = JSONUtil.convertResponseToJSON(response); + + } catch (Exception e) { + response = "pushUserRole failed with error: " + e.getMessage(); + e.printStackTrace(); + logger.error(EELFLoggerDelegate.debugLogger, response); + logger.error(EELFLoggerDelegate.errorLogger, response); + throw new PortalAPIException(response, e); + }finally { + MDC.remove(SystemProperties.MDC_TIMER); + } + + } + + @Override + public List getUserRoles(String loginId) throws PortalAPIException { + + logger.debug(EELFLoggerDelegate.debugLogger, "## REST API ## loginId: " + loginId); + + List ecompRoles = new ArrayList(); + try { + + + User user = userProfileService.getUserByLoginId(loginId); + + SortedSet currentRoles = null; + if(user != null){ + + currentRoles = user.getRoles(); + + if(currentRoles != null) + for(Role role : currentRoles) + ecompRoles.add(UserUtils.convertToEcompRole(role)); + } + return ecompRoles; + } + catch (Exception e){ + String response = "getUserRoles failed with error: " + e.getMessage(); + e.printStackTrace(); + logger.error(EELFLoggerDelegate.debugLogger, response); + logger.debug(EELFLoggerDelegate.errorLogger, response); + throw new PortalAPIException(response, e); + } + } + + private void replaceExistingRoles(SortedSet roles, User user) { + // 1. remove existing roles + Set userApps = user.getUserApps(); + Iterator appsItr = (Iterator) userApps.iterator(); + while (appsItr.hasNext()) { + UserApp tempUserApp = (UserApp)appsItr.next(); + boolean roleFound = false; + for (Role role : roles) { + if (tempUserApp.getRole().getId().equals(role.getId())) { + roleFound = true; + break; + } + } + if (!roleFound) + appsItr.remove(); + } + user.setUserApps(userApps); + userProfileService.saveUser(user); + + // 2. add new roles + user.setRoles(roles); + userProfileService.saveUser(user); + adminAuthExtension.saveUserExtension(user); + } + + + @Override + public boolean isAppAuthenticated(HttpServletRequest request) throws PortalAPIException { + WebServiceCallService securityService = AppContextManager.getAppContext().getBean(WebServiceCallService.class); + try { + String appUser = request.getHeader("username"); + String password = request.getHeader("password"); + boolean flag = securityService.verifyRESTCredential(null, appUser, password); + return flag; + + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "Failed to authenticate" + e.getMessage()); + throw new PortalAPIException("Failed to authenticate: " + e.getMessage()); + } + + } + + public String getSessionTimeOuts() throws Exception{ + return PortalTimeoutHandler.gatherSessionExtensions(); + } + + public void updateSessionTimeOuts(String sessionMap) throws Exception{ + PortalTimeoutHandler.updateSessionExtensions(sessionMap); + } +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/uebhandler/InitUebHandler.java b/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/uebhandler/InitUebHandler.java new file mode 100644 index 000000000..c052187af --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/uebhandler/InitUebHandler.java @@ -0,0 +1,73 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +package org.openecomp.portalapp.uebhandler; + +import java.util.concurrent.ConcurrentLinkedQueue; + +import javax.annotation.PostConstruct; + +import org.openecomp.portalsdk.core.logging.format.AlarmSeverityEnum; +import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.openecomp.portalsdk.core.onboarding.crossapi.PortalApiConstants; +import org.openecomp.portalsdk.core.onboarding.crossapi.PortalApiProperties; +import org.openecomp.portalsdk.core.onboarding.ueb.UebManager; +import org.openecomp.portalsdk.core.onboarding.ueb.UebMsg; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Configuration; + +// +// Adding this class for the sole purpose of insuring that the MainUebHandler really +// honors @Async and kicks off a thread. For more info google @Async and read about +// @Async only working if called from different class. +// +@Configuration +public class InitUebHandler { + + EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(InitUebHandler.class); + + + @Autowired + MainUebHandler mainUebHandler; + + public InitUebHandler() { + + } + + @PostConstruct + public void initUeb() { + + try { + String enableListenerThread = PortalApiProperties.getProperty(PortalApiConstants.UEB_LISTENERS_ENABLE); + if (enableListenerThread.equalsIgnoreCase("true")) { + ConcurrentLinkedQueue inboxQueue = new ConcurrentLinkedQueue(); + UebManager.getInstance().initListener(inboxQueue); + mainUebHandler.runHandler(inboxQueue); + logger.info(EELFLoggerDelegate.debugLogger, ("Returned from initiating mainUebHandler...")); + } + else { + logger.info(EELFLoggerDelegate.debugLogger, ("Not starting UEB listening thread because ueb_listeners_enable is not set to true in the properties file.")); + } + } + catch (Exception e) { + logger.error(EELFLoggerDelegate.debugLogger, ("Not starting UEB listening thread because property could not be read " + PortalApiConstants.UEB_LISTENERS_ENABLE),AlarmSeverityEnum.MAJOR); + } + + } +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/uebhandler/MainUebHandler.java b/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/uebhandler/MainUebHandler.java new file mode 100644 index 000000000..7ff07dd4e --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/uebhandler/MainUebHandler.java @@ -0,0 +1,104 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +package org.openecomp.portalapp.uebhandler; + +import java.util.concurrent.ConcurrentLinkedQueue; + +import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.openecomp.portalsdk.core.onboarding.ueb.UebMsg; +import org.openecomp.portalsdk.core.onboarding.ueb.UebMsgTypes; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Component; + +//------------------------------------------------------------------------- +// Listens for received UEB messages and handles the messages +// +// Note: To implement a synchronous reply call getMsgId on the request +// and putMsgId on the reply (echoing the request MsgId). +// +//------------------------------------------------------------------------- +@Component("MainUebHandler") +public class MainUebHandler { + + EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MainUebHandler.class); + + + ConcurrentLinkedQueue inboxQueue = null; + + @Autowired + WidgetNotificationHandler widgetNotificationHandler; + + @Async + public void runHandler(ConcurrentLinkedQueue queue) { + inboxQueue = queue; + + logger.info(EELFLoggerDelegate.debugLogger, ("==> MainUebHandler started")); + + while (true) { + UebMsg msg = null; + while ((msg = inboxQueue.poll()) != null) { + if (msg.getMsgType() != null) { + logger.debug(EELFLoggerDelegate.debugLogger, ("<== Received UEB message : " + msg.toString())); + + switch (msg.getMsgType()) { + /* + * Add your own defined handler objects, use @Component for + * the class. See WidgetNotificationHandler as an example. + * + * Use @Async on methods for performance + * + * For syncronous replies use UebManager publishReply and + * echo back the msgId in your response ie + * msg.putMsgId(requestMsg.getMsgId()) + * + * case UebMsgTypes.UEB_MSG_TYPE_XYZ: { + * XYZHandler.handleMsg(msg); break; } + */ + case UebMsgTypes.UEB_MSG_TYPE_WIDGET_NOTIFICATION: { + widgetNotificationHandler.handleWidgetNotification(msg); + break; + } + default: { + + logger.info(EELFLoggerDelegate.debugLogger, ("Unknown message type [" + msg.getMsgType() + "] from " + msg.getSourceTopicName())); + + break; + } + } + } + } + + if (Thread.interrupted()) { + + logger.info(EELFLoggerDelegate.debugLogger, ("==> UebMainHandler exiting")); + + break; + } + + try { + Thread.sleep(10); + } catch (InterruptedException e) { + logger.info(EELFLoggerDelegate.debugLogger, ("UebMainHandler interrupted during sleep" + e.getMessage())); + + } + } + } +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/uebhandler/WidgetNotificationHandler.java b/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/uebhandler/WidgetNotificationHandler.java new file mode 100644 index 000000000..dd2213dae --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/uebhandler/WidgetNotificationHandler.java @@ -0,0 +1,46 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +package org.openecomp.portalapp.uebhandler; + +import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.openecomp.portalsdk.core.onboarding.ueb.UebMsg; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Component; + +@Component +public class WidgetNotificationHandler { + + EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(WidgetNotificationHandler.class); + + + public WidgetNotificationHandler() { + } + + @Async + public void handleWidgetNotification(UebMsg requestMsg) { + logger.debug(EELFLoggerDelegate.debugLogger, ("handleWidgetNotification received notification: " + requestMsg.toString())); + /* + * Here the notification msg can be handled + * + * requestMsg.getPayload() - returns string that contains the + * Application defined content + */ + } +} diff --git a/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/util/CustomLoggingFilter.java b/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/util/CustomLoggingFilter.java new file mode 100644 index 000000000..48c51195f --- /dev/null +++ b/ecomp-sdk-app/src/main/java/org/openecomp/portalapp/util/CustomLoggingFilter.java @@ -0,0 +1,54 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +package org.openecomp.portalapp.util; + +import ch.qos.logback.classic.Level; +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.filter.Filter; +import ch.qos.logback.core.spi.FilterReply; + +/** + * Custom Filter class bind with logback.xml + * configuration file to strip out certain log messages + * coming out of special packages or classes. + * + */ +public class CustomLoggingFilter extends Filter { + + /** + * Custom Filter is added to strip out the continuous U-EB logging messages + * But make sure we log the ERROR & WARNING Level messages. + */ + @Override + public FilterReply decide(ILoggingEvent event) { + try { + if ((event.getLevel() != Level.ERROR || event.getLevel() != Level.WARN) && + (event.getThreadName().equalsIgnoreCase("UEBConsumerThread")) && + (event.getLoggerName().contains("org.openecomp.nsa") || event.getLoggerName().contains("org.apache.http")) + ) { + return FilterReply.DENY; + } else { + return FilterReply.NEUTRAL; + } + } catch(Exception e) { + return FilterReply.NEUTRAL; + } + } +} diff --git a/ecomp-sdk-app/src/main/resources/att-rules.drl b/ecomp-sdk-app/src/main/resources/att-rules.drl new file mode 100644 index 000000000..e15c3fb18 --- /dev/null +++ b/ecomp-sdk-app/src/main/resources/att-rules.drl @@ -0,0 +1,16 @@ +package org.openecomp.portalsdk.core.drools; + + +rule "Drools NJ" +when +$droolsRuleService : DroolsRuleServiceImpl( state == "NJ" ) +then +$droolsRuleService.setResultsString("NJ state :" + " Garden State"); +end + +rule "Drools NY" +when +$droolsRuleService : DroolsRuleServiceImpl( state == "NY" ) +then +$droolsRuleService.setResultsString("NY state :" + " Empire State"); +end diff --git a/ecomp-sdk-app/src/main/resources/cache.ccf b/ecomp-sdk-app/src/main/resources/cache.ccf new file mode 100644 index 000000000..d21404b09 --- /dev/null +++ b/ecomp-sdk-app/src/main/resources/cache.ccf @@ -0,0 +1,30 @@ +# DEFAULT CACHE REGION +jcs.default=DC +jcs.default.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes +jcs.default.cacheattributes.MaxObjects=1000 +jcs.default.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache +jcs.default.elementattributes=org.apache.jcs.engine.ElementAttributes +jcs.default.elementattributes.IsEternal=true +jcs.default.elementattributes.IsSpool=true + + +# MEMORY SHRINKING CONFIGURATION (Commented) +#jcs.default.cacheattributes.UseMemoryShrinker=true +#jcs.default.cacheattributes.MaxMemoryIdleTimeSeconds=3600 +#jcs.default.cacheattributes.ShrinkerIntervalSeconds=60 +#jcs.default.cacheattributes.MaxSpoolPerRun=500 +#jcs.default.elementattributes=org.apache.jcs.engine.ElementAttributes +#jcs.default.elementattributes.IsEternal=false + + +# AUXILLARY CACHE CONFIGURATION +jcs.auxiliary.DC=org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCacheFactory +jcs.auxiliary.DC.attributes=org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCacheAttributes +jcs.auxiliary.DC.attributes.DiskPath=/tmp + + +# PRE-DEFINED REGION FOR LOOKUP DATA +jcs.region.lookUpObjectCache=DC +jcs.region.lookUpObjectCache.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes +jcs.region.lookUpObjectCache.cacheattributes.MaxObjects=4000 +jcs.region.lookUpObjectCache.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache diff --git a/ecomp-sdk-app/src/main/resources/logback.xml b/ecomp-sdk-app/src/main/resources/logback.xml new file mode 100644 index 000000000..4f773ee2b --- /dev/null +++ b/ecomp-sdk-app/src/main/resources/logback.xml @@ -0,0 +1,370 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ${defaultLoggerPattern} + + + + + + + + + + + + ${logDirectory}/${generalLogName}.log + + + ${logDirectory}/${generalLogName}.%d{yyyy-MM-dd}.log.zip + + + 30 + 3GB + + + + ${applicationLoggerPattern} + + + + + + 256 + + true + + + + + + + + + + + + + + + + + + + ${logDirectory}/${auditLogName}.log + + + ${logDirectory}/${auditLogName}.%d{yyyy-MM-dd}.log.zip + + + 30 + 3GB + + + + ${auditLoggerPattern} + + + + 256 + + + + + ${logDirectory}/${metricsLogName}.log + + + ${logDirectory}/${metricsLogName}.%d{yyyy-MM-dd}.log.zip + + + 30 + 3GB + + + + ${metricsLoggerPattern} + + + + + + 256 + + + + + ${logDirectory}/${errorLogName}.log + + + ${logDirectory}/${errorLogName}.%d{yyyy-MM-dd}.log.zip + + + 30 + 3GB + + + + ${errorLoggerPattern} + + + + + 256 + + + + + ${debugLogDirectory}/${debugLogName}.log + + + ${logDirectory}/${debugLogName}.%d{yyyy-MM-dd}.log.zip + + + 30 + 3GB + + + + ${defaultLoggerPattern} + + + + + 256 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ecomp-sdk-app/src/main/resources/mchange-log.properties b/ecomp-sdk-app/src/main/resources/mchange-log.properties new file mode 100644 index 000000000..77e260bbc --- /dev/null +++ b/ecomp-sdk-app/src/main/resources/mchange-log.properties @@ -0,0 +1,23 @@ +### +# ================================================================================ +# eCOMP Portal SDK +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ================================================================================ +### +# Direct the proprietary logger used by com.mchange.c3p0 to use slf4j + +com.mchange.v2.log.MLog=com.mchange.v2.log.FallbackMLog +com.mchange.v2.log.FallbackMLog.DEFAULT_CUTOFF_LEVEL=OFF diff --git a/ecomp-sdk-app/src/main/resources/portal.properties b/ecomp-sdk-app/src/main/resources/portal.properties new file mode 100644 index 000000000..f20bc2c2e --- /dev/null +++ b/ecomp-sdk-app/src/main/resources/portal.properties @@ -0,0 +1,69 @@ +### +# ================================================================================ +# eCOMP Portal SDK +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ================================================================================ +### +# Properties read by ECOMP Framework library, ecompFW.jar + +########################################################################## +# The following properties should NOT be changed by partner applications. +########################################################################## + +portal.api.prefix = /api +max.idle.time = 5 +user.attribute.name = user_attribute + +testing=testing + +#Use REST API instead of UEB to fetch the functional menu data +use_rest_for_functional_menu=true + +########################################################################## +# The following properties MUST be changed by partner applications. +########################################################################## + +# Name of java class that implements the OnBoardingApiService interface. +portal.api.impl.class = org.openecomp.portalapp.service.OnBoardingApiServiceImplPolicy + +# CSP Global Log On for single sign on +ecomp_redirect_url = http://todo_enter_portal_hostname:8080/ecompportal/login.htm + +# URL of the ECOMP Portal REST API + +ecomp_rest_url = TODO_Portal_URL + +# Applications do not need to run a UEB listener in 1610. +ueb_listeners_enable = false + +# UEB Configuration +# In release 1607, all 6 entries below were required. +# In release 1610, if key ueb_listeners_enable is set to false, +# then only the ueb_app_key is required. +# UEB servers +ueb_url_list = todo_ueb_url_list +# ECOMP Portal listens on this UEB topic +ecomp_portal_inbox_name = ECOMP-PORTAL-INBOX-TEST-DEMETER +# Replace these 3 default values with the ones for your specific App, +# as shown on the on-boarding page on the ECOMP Portal web application. +ueb_app_key = ZOicEniw7BWDL1pM +ueb_app_secret = PJIsBErHfo2RGKzuu03CZKgV +ueb_app_mailbox_name = ECOMP-PORTAL-OUTBOX-TEST-32756 +# Consumer group name for UEB topic. +# Use the special tag '{UUID}' to generate a unique one for each sdk-app server. +ueb_app_consumer_group_name = {UUID} + +decryption_key = AGLDdG4D04BKm2IxIWEr8o== diff --git a/ecomp-sdk-app/src/main/resources/state-rules.drl b/ecomp-sdk-app/src/main/resources/state-rules.drl new file mode 100644 index 000000000..586ae6b77 --- /dev/null +++ b/ecomp-sdk-app/src/main/resources/state-rules.drl @@ -0,0 +1,38 @@ +package org.openecomp.portalsdk.core.drools; +global String age + +rule "Default" +when +$droolsRuleService : DroolsRuleServiceImpl( state != null ) +then +System.out.println($droolsRuleService.accessLabel() +" "+ $droolsRuleService.getState() +" state legal age is " + getDefaultIfNull(age)); +$droolsRuleService.setResultsString($droolsRuleService.getState()+" state legal age is " + getDefaultIfNull(age)); +end + +rule "Drools NJ" +when +$droolsRuleService : DroolsRuleServiceImpl( state == "NJ" ) +then +System.out.println($droolsRuleService.accessLabel() +" "+ "NJ state legal age is " + getDefaultIfNull(age)); +$droolsRuleService.setResultsString("NJ state legal age is " + getDefaultIfNull(age)); +end + +rule "Drools KY" +when +$droolsRuleService : DroolsRuleServiceImpl( state == "KY" ) +then +System.out.println($droolsRuleService.accessLabel() +" "+ "KY state legal age is " + getDefaultIfNull("20")); +$droolsRuleService.setResultsString("KY state legal age is " + getDefaultIfNull("20")); +end + +rule "Drools NY" +when +$droolsRuleService : DroolsRuleServiceImpl( state == "NY" ) +then +System.out.println($droolsRuleService.accessLabel() +" "+ "NY state legal age is " + getDefaultIfNull("21")); +$droolsRuleService.setResultsString("NY state legal age is " + getDefaultIfNull("21")); +end + +function String getDefaultIfNull(String age) { +return age == null ? "18" : age; +} \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/conf/quartz.properties b/ecomp-sdk-app/src/main/webapp/WEB-INF/conf/quartz.properties new file mode 100644 index 000000000..23340ddc1 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/conf/quartz.properties @@ -0,0 +1,30 @@ +################################################################################# +# Quartz configurations for Quantum Work Flow # +################################################################################# + +org.quartz.scheduler.instanceId = AUTO + +################################################################################# +# Main configurations +org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool +org.quartz.threadPool.threadCount = 30 + +============================================================================ +# Configure JobStore +#============================================================================ + +org.quartz.jobStore.misfireThreshold = 60000 + +org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX +org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.StdJDBCDelegate +org.quartz.jobStore.useProperties = false +#org.quartz.jobStore.dataSource = myDS +org.quartz.jobStore.tablePrefix = FN_QZ_ + +org.quartz.jobStore.isClustered = true +org.quartz.jobStore.clusterCheckinInterval = 20000 + +#============================================================================ +# Configure Datasources +#============================================================================ + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/conf/raptor.properties b/ecomp-sdk-app/src/main/webapp/WEB-INF/conf/raptor.properties new file mode 100644 index 000000000..68b1f707e --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/conf/raptor.properties @@ -0,0 +1,187 @@ +### +# ================================================================================ +# eCOMP Portal SDK +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ================================================================================ +### +##C## Mention the name of the framework. At present RAPTOR supports FUSION +system=fusion +##C## Determines the priority for the debug message. +debug_level=5 +##C## Determines the number of records can be downloaded in excel when you select "download all" option. +download_limit=65000 +csv_download_limit=10 +##C## Determines the number of records to be displayed in a single page. +default_page_size=50 +##C## Determines the list size in the form field. +form_fields_list_size=99000 +##C## Determines the scheduler interval +#scheduler_interval=0 => disabled +scheduler_interval=0 +##C## System Name +system_name=RAPTOR +##C## This is used for Bread crumbs. +base_title=ANALYSIS +##C## whether to allow SQL-based report definition (security risk); super users are always allowed to create SQL-based reports +allow_sql_based_reports=yes +##C## Determines whether to include disclaimer page at the bottom of each screen +show_disclaimer=yes +disclaimer_positioned_top_in_csvexcel=yes +##C## Determines whether to display the form page as a separate page before running the report +display_form_before_run=yes +##C## Determines whether to include the form page on the report data page +include_form_with_data=yes +##C## Determines whether to cache chart data in the session => faster re-display if the data volume does not get too large +cache_chart_data=yes +##C## Determines whether to cache report data for the currently displayed page in the session => faster re-display + ##C## if the data volume does not get too large +cache_cur_page_data=yes +##C## Determines Chart width +default_chart_width=700 +##C## Determines Chart height +default_chart_height=420 +##C## Determines whether to permit report deletion only by report owner or by everyone with "write" access +delete_only_by_owner=no +##C## Determines whether to log each report execution and update time and user ID +enable_report_log=yes +##C## Determines whether to cache user roles info in memory (saves many DB reads, but does not account for roles + ##C## assigned after the cache was loaded) +cache_user_roles=yes +##C## Determines whether to convert month formats (e.g. MM/YYYY) to the last day of the month (true) or + ##C## first day (false) - like 12/2003 is converted to either 12/31/2003 or 12/01/2003 +month_format_use_last_day=no +##C## Determines whether to print the report title in the download files +print_title_in_download=yes +##C## Determines whether to show report description when the report is run and in the quick links +show_descr_at_runtime=no +##C## Determines whether to skip labels on the Line chart axis when they overlap +#DEPRECATED skip_chart_labels_to_fit=no +##C## Determines whether to show chart types that are purpose and/or data specific +show_nonstandard_charts=yes +##C## Determines whether to allow the user to change the chart type at runtime +allow_runtime_chart_sel=yes +##C## Determines whether to display the report title as chart title as well +display_chart_title=yes +##C## Determines whether to merge/blank multi-level row headings in cross-tab report +merge_crosstab_row_headings=yes +##C## Determines whether to display chart when displaying the report at first or just a "Show Chart" button +display_chart_by_default=yes +##C## Determines whether to print the form field values in the download files +print_params_in_download=yes +##C## Determines the limitation to the characters in chart label. +skip_chart_labels_limit=30 +##C## Determines whether to users with read-only rights for a report can copy it +can_copy_on_read_only=yes +##C## Determines the no of decimals to be displayed in Totals column +#max_decimals_on_totals=-1 => don't truncate, display all decimal digits +max_decimals_on_totals=2 +##C## Determines which JFreeChart to use. +jfree_version=latest +#jfree_version=0.9.11 +# Added this restriction so that heavily used system which contain +# more than 1000 users can enable this feature not to display whole +# users in the drop down menu +display_all_users=yes +##Sheet name +sheet_name=raptor +#shell_script_name=/home/sundar/test.sh +#download_query_folder=/titan/PROJECT3/RAPTOR/raptor/dwnld/query/ +## this directory is mentioned if the flat file is downloaded using shell script +shell_script_dir=/titan/PROJECT3/RAPTOR/raptor/dwnld/ +flat_file_lower_limit=1 +flat_file_upper_limit=200000 +## whatever request mentioned here would be parsed in sql and request parameter would be filled +request_get_params=isEmbedded +print_footer_in_download=yes +## footer mentioned here appears in downloaded excel +footer_first_line=TODO footer first line +footer_second_line=Use Pursuant to Company Instructions +## to run report in popup window +report_in_popup_window=yes +## to run each report in new popup window if the above is selected +popup_in_new_window=yes +## "Yes" allows the request param to be passed to the drill down report +pass_request_param_in_drilldown=yes +## Show PDF download icon +show_pdf_download=yes +# Show Folder Tree +show_folder_tree=no +#Show folder tree only for Admin Users +show_folder_tree_only_to_admin_users=no +#folder tree should be minimized +folder_tree_minimized=yes +## whatever session mentioned here would be parsed in sql and session parameter would be filled +session_params=login_id +display_formfield_info=yes +customize_formfield_info=yes +#schedule limit for end users +schedule_limit=10 +# customized query if you need any restrictions for schedule and security tab for fusion +#schedule_custom_query_for_users=getAllUsersByCustomer +#schedule_custom_query_for_roles=getAllRolesByCustomer +# customized query if you need any restrictions for schedule and security tab for prisms example +#schedule_custom_query_for_users=SELECT au.user_id, au.first_name||' '||au.last_name user_name FROM app_user au order by 2 +schedule_custom_query_for_users=SELECT au.user_id id, au.first_name||' '||au.last_name name FROM app_user au where user_id = 1 order by 2 +#schedule_custom_query_for_roles=SELECT ar.role_id, ar.descr role_name FROM app_role ar order by 2 +schedule_date_pattern=MM/dd/yyyy hh:mm:ss a +## This is used to display in right format in chart timestamp axis as we give in the sql +#chart_yearly_format=yyyy +#chart_monthly_format=MMM-yyyy +#chart_daily_format=MM-dd-yyyy +chart_hourly_format=MM/dd HH +#chart_minute_format=HH:mm +chart_minute_format=MM-dd-yyyy-HH:mm +#chart_second_format=HH:mm:ss +chart_second_format=MM-dd-yyyy +#chart_millisecond_format=HH:mm:ss.S +schedule_help_text=This form is used to schedule a specific Reporting Platform report to be delivered to one or more email addresses associated with your Company's Business Direct user logins. Note that report output delivered via email does not include the capability to drill down/back up to additional data levels. So, select the appropriate data level report for the scheduled report. View the status of scheduled report requests in the My Schedules menu item. +use_loginid_in_schedYN=Y +session_params_for_scheduling=login_id +session_date_formfield_auto_incr=yes +display_session_param_pdfexcel=login_id;Login Id +session_params_for_displaying_in_scheduling=login_id;Login Id +application_server=tomcat +#gmap properties +gmap_key=ABQIAAAAToJSSetKBMjBJx8MiRw4ghQiU0SbbKnm8C5eu25cpyLwgkLzyRShrQTbgZtqnKAqZU9JwcSq1bKwiA +PROJECT-FOLDER=/Users/sundar/git/st_quantum/quantum/target/quantum-1.0 +# +MARKET-SHAPEFILE-FOLDER=resources/files +# output folder for files generated on server side +OUTPUT-FOLDER=resources/temp +# tile size in pixel +TILE-SIZE=256 +#check if map is disabled or not +map_allowed=Y +max_drilldown_level=2 +admin_role_equiv_to_super_role=N +show_loading_during_formfield_chain=Y +show_print_icon=N +globally_nowrap=N +calendar_output_date_format=MM/dd/yyyy +memory_threshold_percentage=99 +print_params_in_csv_download=yes +notitle_in_dashboard=yes +generate_store_sched_reports=yes +show_excel_2007_download=yes +print_excel_in_landscape=yes +show_animated_chart_option=yes +show_animated_chart_only=no +adjust_content_based_on_height=yes +custom_submit_button_text=Run Button +customize_formfield_layout=yes +#db_type=postgresql +#db_type=oracle +db_type=mysql diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/conf/raptor_app_fusion.properties b/ecomp-sdk-app/src/main/webapp/WEB-INF/conf/raptor_app_fusion.properties new file mode 100644 index 000000000..ce9d57c37 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/conf/raptor_app_fusion.properties @@ -0,0 +1,39 @@ +### +# ================================================================================ +# eCOMP Portal SDK +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ================================================================================ +### +temp_folder_path=/demeter/WebApps/dev/ECOMP_PORTAL/temp/ +upload_folder_path=/demeter/WebApps/dev/ECOMP_PORTAL/files/ +excel_template_path=/demeter/WebApps/dev/ECOMP_PORTAL/files/raptor_template/ +temp_folder_url=temp/ +upload_folder_url=upload/ +smtp_server=todo.smtp.com +default_email_sender=email-name@email.com +error_page=error_page.jsp +jsp_context_path=raptor/ +img_folder_url=static/fusion/raptor/images/ +base_folder_url=static/fusion/raptor/ +direct_access_url=http://localhost:8080/quantum/raptor_email_attachment.htm?action=raptor&source_page=report_run&display_content=y +#base_action_url=report.htm#/report_run/ +drill_action_url=report.htm#/report_run/c_master= +base_action_url=report_wizard.htm?action= +base_action_url_ng=report#/ +base_action_param=c_master= +super_role_id=1 +admin_role_ids=1 +quick_links_menu_ids=HOME,CUSTOMER,REPORTS diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/conf/raptor_db_fusion.properties b/ecomp-sdk-app/src/main/webapp/WEB-INF/conf/raptor_db_fusion.properties new file mode 100644 index 000000000..8b9870686 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/conf/raptor_db_fusion.properties @@ -0,0 +1,19 @@ +### +# ================================================================================ +# eCOMP Portal SDK +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ================================================================================ +### diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/conf/raptor_pdf.properties b/ecomp-sdk-app/src/main/webapp/WEB-INF/conf/raptor_pdf.properties new file mode 100644 index 000000000..d98a47cd6 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/conf/raptor_pdf.properties @@ -0,0 +1,49 @@ +### +# ================================================================================ +# eCOMP Portal SDK +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ================================================================================ +### +## pdf file specific properties +pdf_data_font_size=9 +pdf_data_font_family=Arial +#reduce the font size from html config +pdf_data_font_size_offset=2 +pdf_data_alternate_color=true +#data row background(white), alternate(light light blue/gray) +pdf_data_background_alternate_hex_code=#EDEDED +pdf_data_default_background_hex_code=#FFFFFF +#header font (white) background (gray) +pdf_data_table_header_font_hex_code=#FFFFFF +pdf_data_table_header_background_hex_code=#8A9BB3 +#footer header +pdf_footer_font_size=9 +pdf_footer_font_family=Arial +pdf_att_proprietary=Proprietary\nUse Pursuant to Company Instructions +pdf_att_proprierary_font_size=7 +pdf_date_timezone=GMT +pdf_date_pattern=MM/dd/yyyy hh:mm:ss a +##page number position at 1 - footer middle, 0 -- header right, 2 - both +pdf_page_number_position=1 +pdf_word_before_page_number=Page +pdf_word_after_page_number= +pdf_coverpage_firstcolumn_size=0.3 +pdf_image_auto_rotate=false +display_create_owner_info=true +#session_info=customer,customerId +display_loginid_for_downloaded_by=false +# please use false if you want landscape to be default. +is_default_orientation_portrait=true diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/conf/sql.properties b/ecomp-sdk-app/src/main/webapp/WEB-INF/conf/sql.properties new file mode 100644 index 000000000..671690237 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/conf/sql.properties @@ -0,0 +1,322 @@ +### +# ================================================================================ +# eCOMP Portal SDK +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ================================================================================ +### +#SQL Statements for PostgreSQL + +#ReportLoader.java + +load.custom.report.xml = SELECT cr.report_xml FROM cr_report cr WHERE rep_id=? + +# need to copy to oracle +load.remoteDB.schema = SELECT 'local' SCHEMA_ID, 'local' SCHEMA_DESC, null DATASOURCE_TYPE FROM dual union SELECT a.SCHEMA_ID, a.SCHEMA_DESC, DATASOURCE_TYPE FROM SCHEMA_INFO a where schema_id <> 'local' order by schema_id +load.remoteDB.schema.where = SELECT a.SCHEMA_ID, a.SCHEMA_DESC, DATASOURCE_TYPE FROM SCHEMA_INFO a where schema_id = '[schema_id]' +#formfield rendering + +formfield.id.name.sql.prefix=SELECT id, name FROM ( +formfield.id.name.sql=SELECT id, name + +formfield.id.name.sql.suffix= + +report.security.create= SELECT coalesce(cr.owner_id, cr.create_id) AS owner_id, cr.create_id, DATE_FORMAT(cr.create_date, '%m/%d/%Y') create_date, maint_id, DATE_FORMAT(cr.maint_date, '%m/%d/%Y') update_date, cr.public_yn FROM cr_report cr WHERE cr.rep_id = [rw.getReportID()] + +db.update.report.xml = SELECT cr.rep_id, cr.report_xml FROM cr_report cr WHERE rep_id=? FOR UPDATE + +update.custom.report.rec = UPDATE cr_report SET title='[Utils.oracleSafe(rw.getReportName())]', descr='[Utils.oracleSafe(rw.getReportDescr())]', public_yn='[(rw.isPublic()]', menu_id='[rw.getMenuID()]', menu_approved_yn='[(rw.isMenuApproved()]', owner_id=[rw.getOwnerID()], maint_id=[rw.getUpdateID()], maint_date=STR_TO_DATE('[rw.getUpdateDate()]', '[Globals.getOracleTimeFormat()]'), dashboard_type_yn='[(rw.isDashboardType()]', dashboard_yn= '[(rw.getReportType().equals(AppConstants.RT_DASHBOARD)]' WHERE rep_id = [rw.getReportID()] + +is.report.already.scheduled = select rep_id from cr_report_schedule where rep_id = ? + +create.custom.report.rec = INSERT INTO cr_report(rep_id, title, descr, public_yn, menu_id, menu_approved_yn, report_xml, owner_id, create_id, create_date, maint_id, maint_date, dashboard_type_yn, dashboard_yn, folder_id) VALUES([rw.getReportID()], '[Utils.oracleSafe(rw.getReportName())]', '[Utils.oracleSafe(rw.getReportDescr())]', '[rw.isPublic()]', '[rw.getMenuID()]', '[rw.isMenuApproved()]', '', [rw.getOwnerID()], [rw.getCreateID()], STR_TO_DATE('[rw.getCreateDate()]', '[Globals.getOracleTimeFormat()]'), [rw.getUpdateID()], STR_TO_DATE('[rw.getUpdateDate()]', '[Globals.getOracleTimeFormat()]'), '[rw.isDashboardType()]', '[rw.getReportType().equals(AppConstants.RT_DASHBOARD)]',[rw.getFolderId()]) + +get.user.report.names = SELECT cr.rep_id, cr.title FROM cr_report cr WHERE coalesce(cr.owner_id, cr.create_id) = [userID] + +get.report.owner.id = SELECT coalesce(cr.owner_id, cr.create_id) AS owner FROM cr_report cr WHERE rep_id = ? + +delete.report.record.log = DELETE FROM cr_report_log WHERE rep_id = [reportID] + +delete.report.record.users = DELETE FROM cr_report_schedule_users WHERE rep_id = [reportID] + +delete.report.record.schedule = DELETE FROM cr_report_schedule WHERE rep_id = [reportID] + +delete.report.record.access = DELETE FROM cr_report_access WHERE rep_id = [reportID] + +delete.report.record.email = DELETE FROM cr_report_email_sent_log WHERE rep_id = [reportID] + +delete.report.record.favorite = DELETE FROM cr_favorite_reports WHERE rep_id = [reportID] + +delete.report.record.report = DELETE FROM cr_report WHERE rep_id = [reportID] + +load.quick.links = select finalcr.rep_id, finalcr.title, finalcr.descr from (SELECT cr.rep_id, cr.title, cr.descr FROM (SELECT rep_id, MIN(read_only_yn) read_only_yn FROM ((SELECT ua.rep_id, ua.read_only_yn FROM cr_report_access ua WHERE ua.user_id = [userID]) UNION ALL (SELECT ra.rep_id, ra.read_only_yn FROM cr_report_access ra WHERE ra.role_id IN ([roleList.toString()]))) report_access GROUP BY rep_id) ra LEFT JOIN cr_report cr ON cr.rep_id = ra.rep_id WHERE cr.menu_id LIKE '%[nvls(menuId)]%' AND cr.menu_approved_yn = 'Y' AND (coalesce(cr.owner_id, cr.create_id) = [userID] OR cr.public_yn = 'Y' OR ra.read_only_yn IS NOT NULL) UNION SELECT cr.rep_id, cr.title, cr.descr FROM cr_report cr WHERE cr.menu_id LIKE '%[nvls(menuId)]%' AND (coalesce(cr.owner_id, cr.create_id) = [userID] OR cr.public_yn = 'Y' or EXISTS (select * from fn_user_role where user_id=[userID] and role_id in (1)))) finalcr ORDER BY finalcr.title + +load.folder.reports = SELECT cr.rep_id, cr.rep_id report_id, concat([rep_title_sql] , (CASE WHEN cr.public_yn = 'Y' THEN '' ELSE '[PRIVATE_ICON]' END),cr.title,'') title, cr.descr, concat(au.first_name,' ',au.last_name) owner_name, DATE_FORMAT(cr.create_date, '%m/%d/%Y') create_date, CASE WHEN coalesce(cr.owner_id, cr.create_id) = [userID] THEN 'N' ELSE coalesce(ra.read_only_yn, 'Y') END read_only_yn, CASE WHEN coalesce(cr.owner_id, cr.create_id) = [userID] THEN 'Y' ELSE 'N' END user_is_owner_yn FROM cr_report cr JOIN app_user au ON coalesce(cr.owner_id, cr.create_id) = au.user_id AND cr.folder_id= '[folderId]' LEFT JOIN (SELECT rep_id, MIN(read_only_yn) read_only_yn FROM ((SELECT ua.rep_id, ua.read_only_yn FROM cr_report_access ua WHERE ua.user_id = [userID]) UNION ALL(SELECT ra.rep_id, ra.read_only_yn FROM cr_report_access ra WHERE ra.role_id IN ([roleList.toString()]))) report_access GROUP BY rep_id) ra ON cr.rep_id = ra.rep_id +#If roleList.toString() is '' PostgreSQL returns an error - needs to be null instead of empty + +load.folder.reports.user = AND coalesce(cr.owner_id, cr.create_id) = [userID] + +load.folder.reports.publicsql = AND (coalesce(cr.owner_id, cr.create_id) = [userID] OR cr.public_yn = 'Y' OR ra.read_only_yn IS NOT NULL) + +load.quick.download.links = SELECT a.file_name, b.title,DATE_FORMAT(a.dwnld_start_time, '%W %d-%m-%Y %H:%i:%s') as time, a.dwnld_start_time FROM cr_report_dwnld_log a, cr_report b where a.user_id = [userID] and a.rep_id = b.rep_id and (a.dwnld_start_time) >= STR_TO_DATE(DATE_FORMAT(now() - INTERVAL 1 DAY, '%m/%d/%Y'), '%m/%d/%Y') and a.record_ready_time is not null order by a.dwnld_start_time + +load.reports.to.schedule = SELECT cr.rep_id, Initcap(cr.title), cr.descr FROM cr_report cr LEFT OUTER JOIN (SELECT rep_id, MIN(read_only_yn) read_only_yn FROM ((SELECT ua.rep_id, ua.read_only_yn FROM cr_report_access ua WHERE ua.user_id = [userID]) UNION ALL (SELECT ra.rep_id, ra.read_only_yn FROM cr_report_access ra WHERE ra.role_id IN ([roleList.toString()]))) report_access GROUP BY rep_id) ra ON cr.rep_id = ra.rep_id AND (cr.public_yn = 'Y' OR ra.read_only_yn IS NOT NULL or cr.owner_id = [userID] )ORDER BY Initcap(cr.title) + +load.reports.to.add.in.dashboard = SELECT cr.rep_id, cr.title, cr.descr FROM cr_report cr LEFT OUTER JOIN (SELECT rep_id, MIN(read_only_yn) read_only_yn FROM ((SELECT ua.rep_id, ua.read_only_yn FROM cr_report_access ua WHERE ua.user_id = [userID]) UNION ALL (SELECT ra.rep_id, ra.read_only_yn FROM cr_report_access ra WHERE ra.role_id IN ([roleList.toString()]))) report_access GROUP BY rep_id) ra ON cr.rep_id = ra.rep_id AND (coalesce(cr.owner_id, cr.create_id) = [userID] OR cr.public_yn = 'Y' OR ra.read_only_yn IS NOT NULL) AND (cr.dashboard_yn = 'N' or cr.dashboard_yn is null) ORDER BY cr.title + +load.my.recent.links = select rep_id, title, descr, form_fields from ( select rep_id, title, descr, form_fields from (select cr.rep_id, cr.title, a.form_fields, cr.descr, a.log_time, a.user_id, a.action, a.action_value from cr_report_log a, cr_report cr where user_id = [userID] AND action = 'Report Execution Time' and a.rep_id = cr.rep_id order by log_time desc) AS x) AS y where LIMIT 1, 6 + +create.report.log.entry = INSERT INTO cr_report_log (rep_id, log_time, user_id, action, action_value, form_fields) VALUES([reportID], now(), [userID], '[action]' , '[executionTime]', '[form_fields]') + +create.report.log.entry.exec.time = INSERT INTO cr_report_log (rep_id, log_time, user_id, action, action_value, form_fields) VALUES([reportID], NOW() + INTERVAL 1 SECOND, [userID], '[action]' , '[executionTime]', '[formFields]') + +clear.report.log.entries = DELETE FROM cr_report_log WHERE rep_id = ? and user_id = ? + +load.report.log.entries = SELECT x.log_time, x.user_id, (CASE WHEN x.action = 'Report Execution Time' THEN concat('',x.action,'') ELSE x.action END) action, (CASE WHEN x.action = 'Report Execution Time' THEN action_value ELSE 'N/A' END) time_taken, (CASE WHEN x.action = 'Report Execution Time' THEN concat('\"Run') ELSE 'N/A' END) run_image, x.name FROM (SELECT rl.rep_id, DATE_FORMAT(rl.log_time, '%m/%d/%Y %h:%i:%s %p') log_time, rl.action_value, concat(fuser.last_name ,', ',fuser.first_name) name, rl.user_id, rl.action, rl.form_fields FROM cr_report_log rl, fn_user fuser WHERE rl.rep_id = [nvls(reportId)] and rl.action != 'Report Run' and fuser.user_id = rl.user_id ORDER BY rl.log_time DESC) x LIMIT 100 + +does.user.can.schedule.report = select crs.sched_user_id, count(*) from cr_report_schedule crs where sched_user_id = [userId] group by crs.sched_user_id having count(*) >= [Globals.getScheduleLimit()] + +does.user.can.schedule = select crs.schedule_id from cr_report_schedule crs where schedule_id = [scheduleId] + +get.system.date.time = select DATE_FORMAT(now(),'%m/%d/%Y %H:%i:%s') + +get.next.day.date.time = select DATE_FORMAT(NOW() + INTERVAL 1 DAY,'%m/%d/%Y %H:%i:%s') + +get.next.fifteen.minutes.date.time = select DATE_FORMAT(NOW() + INTERVAL 15 MINUTES,'%m/%d/%Y %H:%i:%s') + +get.next.thirty.minutes.date.time = select DATE_FORMAT(NOW() + INTERVAL 30 MINUTES,'%m/%d/%Y %H:%i:%s') + +get.template.file = select template_file from cr_report_template_map where report_id = [reportId] + +load.pdf.img.lookup = select image_id, image_loc from cr_raptor_pdf_img + +load.action.img.lookup = select image_id, image_loc from cr_raptor_action_img + + +#ActionHandler.java + +report.values.map.def.a = SELECT x FROM (SELECT DISTINCT + +report.values.map.def.b = TO_CHAR([colName], '[nvl(displayFormat, AppConstants.DEFAULT_DATE_FORMAT)]') + +report.values.map.def.c = [colName] + +report.values.map.def.d = x FROM [rdef.getTableById(tableId).getTableName()] WHERE [colName] IS NOT NULL ORDER BY 1) xx LIMIT <= [Globals.getDefaultPageSize()] + +test.sched.cond.popup = SELECT 1 WHERE EXISTS ([sql]) + +download.all.email.sent = Select user_id, rep_id from CR_REPORT_EMAIL_SENT_LOG where gen_key='[pdfAttachmentKey.trim()]' and log_id =[report_email_sent_log_id.trim()] and (now() - sent_date) < '1 day' limit 1 + +download.all.gen.key = select schedule_id from cr_report_email_sent_log u where U.GEN_KEY = '[pdfAttachmentKey]' + +download.all.retrieve = SELECT au.user_id FROM (SELECT rs.schedule_id, rs.rep_id FROM cr_report_schedule rs WHERE rs.enabled_yn='Y' AND rs.run_date IS NOT NULL AND rs.schedule_id = [scheduleId]) x, cr_report r, app_user au WHERE x.rep_id = r.rep_id AND au.user_id IN (SELECT rsu.user_id FROM cr_report_schedule_users rsu WHERE rsu.schedule_id = x.schedule_id and rsu.schedule_id = [scheduleId] UNION SELECT ur.user_id FROM fn_user_role ur WHERE ur.role_id IN (SELECT rsu2.role_id FROM cr_report_schedule_users rsu2 WHERE rsu2.schedule_id = x.schedule_id and rsu2.schedule_id = [scheduleId])) + +download.all.insert = insert into cr_report_dwnld_log (user_id,rep_id,file_name,dwnld_start_time,filter_params) values (?,?,?,?,?) + +#ReportWrapper.java + +report.wrapper.format = SELECT coalesce(cr.owner_id, cr.create_id) owner_id, cr.create_id, DATE_FORMAT(cr.create_date, '[Globals.getOracleTimeFormat()]') create_date, maint_id, DATE_FORMAT(cr.maint_date, '[Globals.getOracleTimeFormat()]') update_date, cr.menu_id, cr.menu_approved_yn FROM cr_report cr WHERE cr.rep_id= [reportID] + +generate.subset.sql = SELECT [colNames.toString()] FROM (SELECT [colNames.toString()] FROM ([reportSQL]) AS x ) AS y + +report.sql.only.first.part = SELECT [colNames.toString()] FROM (SELECT [colNames.toString()] FROM ( + +report.sql.only.second.part.a = [startRow] + +report.sql.only.second.part.b = [pageSize] +#MYSQL: LIMIT [startRow], [pageSize] +#ORacle: rownum >= [startRow] and rownum <= ([startRow]+[pageSize]) +#Postgre: limit [pageSize] offset [startRow] + +report.sql.only.second.part.b.noorderby = LIMIT [startRow] + +generate.sql.visual.select = SELECT + +generate.sql.visual.count = COUNT(*) cnt + +generate.sql.visual.dual = +#No DUAL table in PostgreSQL so this is blank + +#ReportRuntime.java + +load.crosstab.report.data = SELECT [colNames.toString()] FROM ( [reportSQL] + +#RaptorRunHandler.java + +generate.sql.handler = SELECT x.* from ([sql]) AS x LIMIT 2 + +generate.sql.select = SELECT [colNames.toString()] FROM (SELECT [colNames.toString()] FROM ([sql]) AS y) AS x + +#ReportSchedule.java + +load.schedule.data = SELECT rs.enabled_yn, DATE_FORMAT(rs.start_date, '%m/%d/%Y') start_date, DATE_FORMAT(rs.end_date, '%m/%d/%Y') end_date, DATE_FORMAT(rs.run_date, '%m/%d/%Y') run_date, coalesce(DATE_FORMAT(rs.run_date, '%h'), '12') run_hour, coalesce(DATE_FORMAT(rs.run_date, '%i'), '00') run_min, coalesce(DATE_FORMAT(rs.run_date, '%p'), 'AM') run_ampm, rs.recurrence, rs.conditional_yn, rs.notify_type, rs.max_row, rs.initial_formfields, rs.schedule_id, coalesce(DATE_FORMAT(rs.end_date, '%h'), '11') end_hour, coalesce(DATE_FORMAT(rs.end_date, '%i'), '45') end_min, coalesce(DATE_FORMAT(rs.end_date, '%p'), 'PM') end_ampm, encrypt_yn, attachment_yn FROM cr_report_schedule rs WHERE rs.rep_id = [reportID] + +load.schedule.getid = SELECT rsu.user_id, concat(fuser.last_name,', ',fuser.first_name), fuser.login_id FROM cr_report_schedule_users rsu, fn_user fuser WHERE rsu.rep_id = [reportID] AND rsu.schedule_id = [getScheduleID()] and rsu.user_id IS NOT NULL and rsu.user_id = fuser.user_id + +load.schedule.users = SELECT rsu.role_id FROM cr_report_schedule_users rsu WHERE rsu.rep_id = [reportID] AND rsu.schedule_id = [getScheduleID()] AND rsu.role_id IS NOT NULL + +new.schedule.data = select coalesce(max(schedule_id),0)+1 AS sequence from cr_report_schedule + +new.report.data = select coalesce(max(rep_id),0)+1 AS rep_id from cr_report + +execute.update = DELETE FROM cr_report_schedule_users WHERE rep_id = [reportID] and schedule_id = [getScheduleID()] + +execute.update.users = INSERT INTO cr_report_schedule_users (schedule_id, rep_id, user_id, role_id, order_no) VALUES([getScheduleID()], [reportID], [emailToUsers.get(i)).getId()], NULL, [(i + 1)]) + +execute.update.roles = INSERT INTO cr_report_schedule_users (schedule_id, rep_id, user_id, role_id, order_no) VALUES([getScheduleID()], [reportID], NULL, [emailToRoles.get(i)).getId()], [((emailToUsers.size() + i + 1)]) + +execute.update.activity = INSERT into cr_schedule_activity_log (schedule_id, notes, run_time) values ([getScheduleID()],'Submitted:Schedule',TO_DATE('[getRunDate()] [getRunHour()]:[getRunMin()] [getRunAMPM()]', 'MM/DD/YYYY HH:MI AM')) + +delete.schedule.data = SELECT 1 FROM cr_report_schedule WHERE rep_id = [reportID] and sched_user_id = [getScheduleUserID()] and schedule_id = [getScheduleID()] + +delete.schedule.data.users = DELETE FROM cr_report_schedule_users WHERE rep_id = [reportID] and schedule_id = [getScheduleID()] + +delete.schedule.data.id = DELETE FROM cr_report_schedule where rep_id = [reportID] and sched_user_id = [getScheduleUserID()] and schedule_id = [getScheduleID()] + +load.cond.sql = SELECT condition_large_sql FROM cr_report_schedule WHERE schedule_id=? + +load.cond.sql.select = SELECT condition_sql FROM cr_report_schedule WHERE schedule_id = [scheduleId] + +persist.cond.sql.update = update cr_report_schedule set condition_large_sql = '' where schedule_id = [scheduleId] +#EMPTY CLOB() changed to '' + +persist.cond.sql.large = SELECT condition_large_sql FROM cr_report_schedule cr WHERE schedule_id=? FOR UPDATE + +persist.cond.sql.set = update cr_report_schedule set condition_sql = ? where schedule_id = [scheduleId] + +#DataCache.java + +get.data.view.actions = SELECT ts.web_view_action FROM cr_table_source ts WHERE ts.web_view_action IS NOT NULL + +get.public.report.id.names = SELECT rep_id, title FROM cr_report WHERE public_yn = 'Y' ORDER BY title + +get.private.accessible.names.a = SELECT cr.rep_id, cr.title FROM cr_report cr WHERE cr.rep_id not in (select rep_id from cr_report_access cra where user_id = '[user_id]' + +get.private.accessible.names.if = OR role_id in ( + +get.private.accessible.names.b = ) AND public_yn = 'N' and cr.owner_id = '[user_id]' order by 2 + +get.group.accessible.names.a = SELECT cr.rep_id, cr.title FROM cr_report cr WHERE cr.rep_id in (select rep_id from cr_report_access cra where user_id = '[user_id]' + +get.group.accessible.names.b = ) AND public_yn = 'N' order by 2 + +get.report.table.sources.a = SELECT table_name, display_name, pk_fields, web_view_action, large_data_source_yn, filter_sql FROM cr_table_source + +get.report.table.sources.where = where SOURCE_DB= '[dBInfo]' + +get.report.table.sources.if = where SOURCE_DB is null or SOURCE_DB = '[AppConstants.DB_LOCAL]' + +get.report.table.sources.else = ORDER BY table_name + +grab.report.table.a = SELECT ts.table_name, ts.display_name, ts.pk_fields, ts.web_view_action, ts.large_data_source_yn, ts.filter_sql FROM cr_table_source ts WHERE + +grab.report.table.if = ts.SOURCE_DB= '[dBInfo]' + +grab.report.table.else = (ts.SOURCE_DB is null or ts.SOURCE_DB = '[AppConstants.DB_LOCAL]') + +grab.report.table.b = except SELECT ts.table_name, ts.display_name, ts.pk_fields, ts.web_view_action, ts.large_data_source_yn, ts.filter_sql from cr_table_source ts where table_name in (select table_name from cr_table_role where role_id not IN [sb.toString()]) and + +grab.report.table.c = ORDER BY 1 + +get.report.table.crjoin = SELECT src_table_name, dest_table_name, join_expr FROM cr_table_join + +get.report.table.joins = SELECT tj.src_table_name, tj.dest_table_name, tj.join_expr FROM cr_table_join tj WHERE ((EXISTS (SELECT 1 FROM cr_table_role trs WHERE trs.table_name=tj.src_table_name AND trs.role_id IN [sb.toString()])) OR (NOT EXISTS (SELECT 1 FROM cr_table_role trs WHERE trs.table_name=tj.src_table_name))) AND ((EXISTS (SELECT 1 FROM cr_table_role trd WHERE trd.table_name=tj.dest_table_name AND trd.role_id IN [sb.toString()])) OR (NOT EXISTS (SELECT 1 FROM cr_table_role trd WHERE trd.table_name=tj.dest_table_name))) + +generate.report.table.col = SELECT a.table_name, a.column_name, a.data_type, a.label FROM user_column_def a WHERE a.table_name = '[tableName.toUpperCase()]' ORDER BY a.column_id + +generate.db.user.sql.a = SELECT utc.table_name, utc.column_name, utc.data_type, + +generate.db.user.sql.if = utc.column_name FROM user_tab_columns utc + +generate.db.user.sql.else = coalesce(x.label, utc.column_name) FROM user_tab_columns utc + +generate.db.user.sql.b = WHERE utc.table_name = '[tableName.toUpperCase()]' + +generate.db.user.sql.c = AND utc.table_name = x.table_name AND utc.column_name = x.column_name + +generate.db.user.sql.d = ORDER BY utc.column_id + +#SearchHandler.java + +load.report.search.result = SELECT cr.rep_id, cr.rep_id report_id, [rep_title_sql] title, cr.descr, concat(au.first_name,' ',au.last_name) owner_name, DATE_FORMAT(cr.create_date, '%m/%d/%Y') create_date, CASE WHEN coalesce(cr.owner_id, cr.create_id) = [userID] THEN 'N' ELSE coalesce(ra.read_only_yn, 'Y') END read_only_yn, CASE WHEN coalesce(cr.owner_id, cr.create_id) = [userID] THEN 'Y' ELSE 'N' END user_is_owner_yn, case when report_xml like '%N%' then 'N' when report_xml like '%Y%' or 1 = (select distinct 1 from cr_report_schedule where rep_id = cr.rep_id) then 'Y' else 'N' end FROM cr_report cr JOIN fn_user au ON coalesce (cr.owner_id, cr.create_id) = au.user_id [fReportID] [fReportName] LEFT JOIN(SELECT rep_id, MIN(read_only_yn) read_only_yn FROM ((SELECT ua.rep_id, ua.read_only_yn FROM cr_report_access ua WHERE ua.user_id = [userID]) UNION ALL (SELECT ra.rep_id, ra.read_only_yn FROM cr_report_access ra WHERE ra.role_id IN ([roleList.toString()]))) report_access GROUP BY rep_id) ra ON ra.rep_id = cr.rep_id + +load.report.search.instr = WHERE cr.menu_id LIKE '%[menuId]%' + +load.report.search.result.user = WHERE coalesce(cr.owner_id, cr.create_id) = [userID] + +load.report.search.result.public = WHERE (coalesce(cr.owner_id, cr.create_id) = [userID] OR cr.public_yn = 'Y' OR ra.read_only_yn IS NOT NULL) + +load.report.search.result.fav = WHERE cr.rep_id in (select rep_id from cr_favorite_reports where user_id = [userID] + +load.report.search.result.sort = ORDER BY CASE coalesce(cr.owner_id, cr.create_id) WHEN [userID] THEN ' ' WHEN 'upper(concat(au.first_name,' ',au.last_name))' ELSE 'upper(cr.title)' END + +load.folder.report.result = SELECT cr.rep_id, cr.rep_id report_id, concat([rep_title_sql] , (CASE WHEN cr.public_yn = 'Y' THEN '' ELSE '[PRIVATE_ICON]' END),cr.title,'') title, cr.descr, concat(au.first_name,' ',au.last_name) owner_name, TO_CHAR(cr.create_date, 'MM/DD/YYYY') create_date, CASE WHEN coalesce(cr.owner_id, cr.create_id) = [userID] THEN 'N' ELSE coalesce(ra.read_only_yn, 'Y') END read_only_yn, CASE WHEN coalesce(cr.owner_id, cr.create_id) = [userID] THEN 'Y' ELSE 'N' END user_is_owner_yn FROM cr_report cr JOIN fn_user au ON coalesce (cr.owner_id, cr.create_id) = au.user_id AND TO_CHAR(cr.rep_id, 'FM99999999') like coalesce('%[fReportID]%', TO_CHAR(cr.rep_id, 'FM99999999')) AND UPPER(cr.title) LIKE UPPER('%[fReportName]%') LEFT JOIN(SELECT rep_id, MIN(read_only_yn) read_only_yn FROM ((SELECT ua.rep_id, ua.read_only_yn FROM cr_report_access ua WHERE ua.user_id = [userID]) UNION ALL (SELECT ra.rep_id, ra.read_only_yn FROM cr_report_access ra WHERE ra.role_id IN ([roleList.toString()]))) report_access GROUP BY rep_id) ra ON ra.rep_id = cr.rep_id + +load.folder.report.result.sort = ORDER BY CASE coalesce(cr.owner_id, cr.create_id) WHEN [userID] THEN ' ' WHEN '(concat(au.first_name,' ',au.last_name))' ELSE 'cr.title' END + +#WizardProcessor.java + +process.filter.add.edit = '[argValue]' + +#ReportDefinition.java + +persist.report.adhoc = SELECT nextval('[Globals.getAdhocReportSequence()]') AS sequence + +#Globals.java + +initialize.roles = SELECT 1 WHERE EXISTS (SELECT 1 FROM cr_table_role) + +initialize.version = SELECT cr_raptor.get_version + +# scheduler + + +scheduler.available.schedules = SELECT x.rep_id, x.schedule_id, x.conditional_yn, x.condition_large_sql, x.notify_type, x.max_row, x.initial_formfields, x.processed_formfields, r.title, x.user_id FROM ( SELECT rs.rep_id, rs.schedule_id, rs.sched_user_id user_id, rs.conditional_yn, rs.condition_large_sql, rs.notify_type, rs.max_row, rs.initial_formfields, rs.processed_formfields FROM cr_report_schedule rs WHERE rs.enabled_yn='Y' AND rs.start_date <= [currentDate] AND (rs.end_date >= [currentDate] or rs.end_date is null ) AND rs.run_date IS NOT NULL ) x, cr_report r WHERE x.rep_id = r.rep_id + +random.string = select ( concat('Z' , round(random() * 1000000000000) ) ) + + +scheduler.user.emails = SELECT au.user_id FROM (SELECT rs.schedule_id, rs.rep_id FROM cr_report_schedule rs WHERE rs.enabled_yn='Y' AND rs.start_date <= now() AND rs.end_date >= now() AND rs.run_date IS NOT NULL AND rs.schedule_id = [p_schedule_id] ) x, cr_report r, fn_user au WHERE x.rep_id = r.rep_id AND au.user_id IN (SELECT rsu.user_id FROM cr_report_schedule_users rsu WHERE rsu.schedule_id = x.schedule_id and rsu.schedule_id = [p_schedule_id] UNION SELECT ur.user_id FROM fn_user_role ur WHERE ur.role_id IN (SELECT rsu2.role_id FROM cr_report_schedule_users rsu2 WHERE rsu2.schedule_id = x.schedule_id and rsu2.schedule_id = [p_schedule_id])) + + +# my logins + +app.query = SELECT APP_ID, ML_APP_NAME, MOTS_ID from fn_app + +user.log.query = SELECT DISTINCT IFNULL(ORG_USER_ID, '') CUID, '' AWID, CONCAT('"',IFNULL(ORG_USER_ID, ''),'"') APPLICATIONUSERID, CONCAT('"',IFNULL(FIRST_NAME, ''),'"') FIRST_NAME, CONCAT('"',substr(IFNULL(MIDDLE_NAME, ''), 0, 1),'"') MIDDLE_INITIAL, CONCAT('"',IFNULL(LAST_NAME, ''),'"') LAST_NAME, IFNULL(DATE_FORMAT(LAST_LOGIN_DATE, '%Y/%m/%d'), '') LAST_LOGON_DATE, DATE_FORMAT(CREATED_DATE, '%Y/%m/%d') ACCOUNT_ACTIVATION_DATE, IFNULL(DATE_FORMAT(MODIFIED_DATE, '%Y/%m/%d'), '') LAST_DATE_ACCOUNT_MODIFIED, '' LAST_PASSWORD_CHANGE_DATE, CONCAT('"',IFNULL(FIRST_NAME, ''),' ',IFNULL(MIDDLE_NAME, ''),' ',IFNULL(LAST_NAME, ''),'"') FULL_USER_NAME, '' NT_ID, IFNULL(EMAIL, '') EMAIL FROM FN_USER FU, FN_USER_ROLE FUR WHERE FU.USER_ID \= FUR.USER_ID and FUR.app_id \= ? and ACTIVE_YN \= 'Y' and ORG_USER_ID is not null order by 1 + +profile.log.query = SELECT DISTINCT CONCAT('"' , ROLE_NAME , '"') PROFILE_NAME, '""' SECURITY_SETTINGS FROM FN_ROLE FR, FN_USER_ROLE FUR WHERE FUR.ROLE_ID \= FR.ROLE_ID and FR.ACTIVE_YN \= 'Y' and ((FUR.APP_ID \= 1 and FR.ROLE_NAME <> 'Standard User') or (FUR.APP_ID \= ? and FUR.APP_ID <> 1)) ORDER BY 1 + +user.profile.log.query = SELECT DISTINCT IFNULL(ORG_USER_ID, '') CUID, '' AWID, CONCAT('"' , IFNULL(ORG_USER_ID, '') , '"') APPLICATIONUSERID , CONCAT('"' , ROLE_NAME , '"') PROFILE_NAME FROM FN_USER A, FN_USER_ROLE B, FN_ROLE C WHERE A.USER_ID \= B.USER_ID AND B.ROLE_ID \= C.ROLE_ID AND A.ACTIVE_YN \= 'Y' AND C.ACTIVE_YN \= 'Y' AND a.ORG_USER_ID is not null AND ((B.APP_ID \= 1 and C.ROLE_NAME <> 'Standard User') or (B.APP_ID \= ? and B.APP_ID <> 1)) ORDER BY 1 + +all.accounts.log.query = SELECT DISTINCT IFNULL(ORG_USER_ID, '') CUID, (case when A.ACTIVE_YN\='Y' then 'ACTIVE' else 'INACTIVE' end) ACTIVE_YN, CONCAT('"' , IFNULL(ORG_USER_ID, '') , '"') APPLICATIONUSERID , IFNULL(DATE_FORMAT(LAST_LOGIN_DATE, '%Y/%m/%d'), '') LAST_LOGON_DATE, '' LAST_PASSWORD_CHANGE_DATE, CONCAT('"' , ROLE_NAME , '"') PROFILE_NAME FROM FN_USER A, FN_USER_ROLE B, FN_ROLE C WHERE A.USER_ID \= B.USER_ID AND B.ROLE_ID \= C.ROLE_ID AND a.ORG_USER_ID is not null AND ((B.APP_ID \= 1 and C.ROLE_NAME <> 'Standard User') or (B.APP_ID \= ? and B.APP_ID <> 1)) ORDER BY 1 + +# basic sql + +seq.next.val = SELECT nextval('[sequenceName]') AS id + +current.date = now() + +nvl = IFNULL + +# report security +report.user.access = SELECT ra.role_id, ra.user_id, ra.read_only_yn FROM cr_report_access ra WHERE ra.rep_id = [reportID] +add.user.access = INSERT INTO cr_report_access (rep_id, order_no, role_id, user_id, read_only_yn) VALUES([reportID], IFNULL((select order_no from (SELECT MAX(order_no) AS order_no FROM cr_report_access WHERE rep_id=[reportID]) AS temp), 0)+1, NULL, [userID], '[readOnlyAccess]') +update.user.access = UPDATE cr_report_access SET read_only_yn='[readOnlyAccess]' WHERE rep_id=[reportID] AND user_id=[userID] +remove.user.access = DELETE FROM cr_report_access WHERE rep_id=[reportID] AND user_id=[userID] +add.role.access = INSERT INTO cr_report_access (rep_id, order_no, role_id, user_id, read_only_yn) VALUES([reportID], IFNULL((select order_no from (SELECT MAX(order_no) AS order_no FROM cr_report_access WHERE rep_id=[reportID]) AS temp), 0)+1, [roleID], NULL, '[readOnlyAccess]') +update.role.access = UPDATE cr_report_access SET read_only_yn='[readOnlyAccess]' WHERE rep_id=[reportID] AND role_id=[roleID] +remove.role.access = DELETE FROM cr_report_access WHERE rep_id=[reportID] AND role_id=[roleID] + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/conf/system.properties b/ecomp-sdk-app/src/main/webapp/WEB-INF/conf/system.properties new file mode 100644 index 000000000..af7425ebe --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/conf/system.properties @@ -0,0 +1,105 @@ +### +# ================================================================================ +# eCOMP Portal SDK +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ================================================================================ +### +# Properties read by ECOMP Core library, ecompSDK-core.jar + +########################################################################## +# The following properties should NOT be changed by partner applications. +########################################################################## + +application_user_id = 30000 +post_default_role_id = 16 +clustered = true + +#Enable Fusion Mobile capabilities for the application +mobile_enable = false + +# Cache config file is needed on the classpath +cache_config_file_path = /WEB-INF/classes/cache.ccf +cache_switch = 199 +cache_load_on_startup = false + +user_name = fullName +decryption_key = AGLDdG4D04BKm2IxIWEr8o== + +########################################################################## +# The following properties MAY require changes by partner applications. +########################################################################## + +#Oracle +#db.userName=quantumbd +#db.password=c1syn2yhmr +#db.connectionURL=jdbc:oracle:thin:todo.link +#db.hib.dialect=org.hibernate.dialect.Oracle10gDialect +#db.driver=oracle.jdbc.driver.OracleDriver +#Hibernate +#hb.dialect=org.hibernate.dialect.Oracle10gDialect +#hb.show_sql=true + +#Postgres +#db.userName=quantumbd +#db.password=c1syn2yhmr +#db.connectionURL=jdbc:postgresql:todo.link +#db.hib.dialect=org.hibernate.dialect.PostgreSQLDialect +#db.driver=org.postgresql.Driver +#hb.dialect=org.hibernate.dialect.PostgreSQLDialect +#hb.show_sql=true + +#Mysql +db.driver = com.mysql.jdbc.Driver +db.connectionURL = jdbc:mysql://localhost:3306/ecomp_sdk +db.userName = root +db.password = +db.min_pool_size = 5 +db.max_pool_size = 10 +hb.dialect = org.hibernate.dialect.MySQLDialect +# SQL statements are logged to stdout +hb.show_sql = false +hb.idle_connection_test_period = 3600 + +app_display_name = EP SDK App +files_path = /tmp + +#element map files +element_map_file_path = /tmp +element_map_icon_path = app/fusionapp/icons/ + +#Cron Schedules +log_cron = 0 0/1 * * * ?; +mylogins_feed_cron = 0 0/60 * * * ?; +#sessiontimeout_feed_cron = 0 * * * * ? * +my_login_feed_output_dir = /tmp/MyLogins + +# ECOMP Portal Shared Context REST API URL +ecomp_shared_context_rest_url= http://todo_enter_be_hostname:9000/ecompportal/context +# Link shown in Help menu +contact_us_link = https://todo_contact_us_link.com + +# An Unique 128-bit value defined to identify a specific version +# of an application deployed on a specific virtual machine. +# This value must be generated and updated by the application +# which is using the ECOMP SDK at the time of its deployment. +# Online Unique UUID generator - https://www.uuidgenerator.net/ +instance_uuid=8da691c9-987d-43ed-a358-00ac2f35685d + +# R Cloud feature - configure this property to enable notebook feature - for more details on RCloud please visit https://rcloud.social/index.html +guard_notebook_url= + +#authenticate user server +authenticate_user_server=http://todo_enter_auth_server_hostname:8383/openid-connect-server-webapp/allUsers diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/defs/definitions.xml b/ecomp-sdk-app/src/main/webapp/WEB-INF/defs/definitions.xml new file mode 100644 index 000000000..74287d0e8 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/defs/definitions.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/conf/fusion.properties b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/conf/fusion.properties new file mode 100644 index 000000000..b2cef9f89 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/conf/fusion.properties @@ -0,0 +1,61 @@ +### +# ================================================================================ +# eCOMP Portal SDK +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ================================================================================ +### + + +# validator settings +#default_error_message = Default error message + +#login message +login.error.hrid.empty = Login failed, please contact system administrator. +login.error.hrid.not-found = User not found, please contact system administrator. +login.error.user.inactive = Account is disabled, please contact system administrator. + +authentication_mechanism = BOTH + +user_attribute_name = user + +# User Session settings +#user_attribute_name = user +roles_attribute_name = roles +role_functions_attribute_name = role_functions +#client_device_attribute_name = client_device +#client_device_emulation = false + + +# menu settings +menu_query_name = menuData +#menu_properties_file_location = /WEB-INF/fusion/menu/ +application_menu_set_name = APP +application_menu_attribute_name = applicationMenuData +#application_menu_properties_name = menu.properties +business_direct_menu_set_name = BD +#business_direct_menu_properties_name = bd.menu.properties +business_direct_menu_attribute_name = businessDirectMenuData + +# RAPTOR config settings +#raptor_config_file_path = /WEB-INF/conf/ + +# Role settings +sys_admin_role_id = 1 +#sys_admin_role_function_delete_from_ui = true + +# Profile Search settings +#profile_search_report_id=181 +#callable_profile_search_report_id=386 diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/defs/definitions.xml b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/defs/definitions.xml new file mode 100644 index 000000000..fb18cb798 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/defs/definitions.xml @@ -0,0 +1,240 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/.gitignore b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/.gitignore new file mode 100644 index 000000000..e69de29bb diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/broadcast.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/broadcast.jsp new file mode 100644 index 000000000..d4e7810c1 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/broadcast.jsp @@ -0,0 +1,137 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +<%@ page import="org.openecomp.portalsdk.core.web.support.UserUtils" %> +<%@ page import="org.openecomp.portalsdk.core.web.support.ControllerProperties" %> +<%@ page import="org.openecomp.portalsdk.core.util.SystemProperties" %> + +<%-- <%@ include file="/WEB-INF/fusion/jsp/include.jsp" %> --%> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> +<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> + + + "/> + + + +
    +

    + + +

    Broadcast Message Edit

    +
    + +

    Broadcast Message Create

    +
    +
    +

    +
    + +
    + Please edit the broadcast message details below: 

    +
    +
    + +
    +
    +
    +
    + + +
    + +
    +
    + + +
    + +
    +
    + +
    + + +
    +
    +
    +
    +
    +
    +
    + +
    +
    + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/broadcast_list.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/broadcast_list.jsp new file mode 100644 index 000000000..2f6c68b51 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/broadcast_list.jsp @@ -0,0 +1,201 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +<%@ page import="java.util.*" %> +<%@ page import="com.fasterxml.jackson.databind.ObjectMapper" %> +<%@ page import="org.json.JSONObject" %> +<%@ page import="java.io.StringWriter" %> +<%@ page import="org.openecomp.portalsdk.core.web.support.ControllerProperties" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> +<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> + + + + +
    +

    + Broadcast Messages +

    +
    + + <%-- Display a table for the broadcast messages of each message location --%> +
    + +
    + {{location.label}} Messages +
    + + + + + + + + + + + + + + + + + {{message.id}} + + + + + + + + + + + +
    No.Message TextStart DateEnd DateSort OrderServerActive?Delete?
    {{$index+1}}{{message.messageText}} + {{message.displayStartDate}} + {{message.displayEndDate}}{{message.sortOrder}}{{message.siteCd}} +
    + +
    +
    +
    +
    +
    + +


    +
    +
    + + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/collaborateList.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/collaborateList.jsp new file mode 100644 index 000000000..b1fbfab14 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/collaborateList.jsp @@ -0,0 +1,146 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +<%@ include file="/WEB-INF/fusion/jsp/popup_modal.html" %> + +
    +
    +

    User List

    +
    + + + + + + + + + + + + + + + + + + + + + + +
    User IDLast NameFirst NameEmailUserIdOnline/Offline
    + Offline + Online +
    +
    +
    +
    + Rows Per Page: + +
    +
    + Current Page: + +
    +
    + Total Page(s): + +
    + + +
    + + + + + + + + + + + +
    diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/data_out.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/data_out.jsp new file mode 100644 index 000000000..f3fb7a747 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/data_out.jsp @@ -0,0 +1,20 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +${model.output_string} diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/ebz/ebz_footer.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/ebz/ebz_footer.jsp new file mode 100644 index 000000000..5a33314f2 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/ebz/ebz_footer.jsp @@ -0,0 +1,46 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> + +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> + + + + + +
    +
    + +
    + +
    +
    +
    + + +
    +
    +
    +
    +
    +
    +
    + + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/ebz/ebz_header.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/ebz/ebz_header.jsp new file mode 100644 index 000000000..285ffd76f --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/ebz/ebz_header.jsp @@ -0,0 +1,799 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> +<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> +<%@ page isELIgnored="false"%> +<%@ page import="org.openecomp.portalsdk.core.util.SystemProperties"%> +<%@ page import="org.openecomp.portalsdk.core.onboarding.crossapi.PortalApiProperties"%> +<%@ page import="org.openecomp.portalsdk.core.onboarding.crossapi.PortalApiConstants"%> +<%@ page import="org.openecomp.portalsdk.core.domain.MenuData"%> + + + + + + + + + + + + + + + + + + + + + + + + + + + + +" /> +" /> + +<% + String contactUsLink = SystemProperties.getProperty(SystemProperties.CONTACT_US_LINK); + String redirectUrl = PortalApiProperties.getProperty(PortalApiConstants.ECOMP_REDIRECT_URL); + String portalUrl = redirectUrl.substring(0, redirectUrl.lastIndexOf('/')) + "/processSingleSignOn"; + String getAccessLink = redirectUrl.substring(0, redirectUrl.lastIndexOf('/')) + "/get_access"; +%> + + + + +<%@include file="/WEB-INF/fusion/jsp/ebz/loginSnippet.html" %> + +
    +
    + +
    +
    +
    + + +
    +
    +
    +
    +
  • + + ECOMP Portal +
  • +
    +
    + +
    +
    + + +
    + + +
    +
    +
    +
  • + Unable to load menus +
  • +
    + +
    +
  • +
    + + +
    +
  • +
  •  
  • +
    + +
    +
    +
    +
    +
    +
    +
    + +
    +
    + + + +     {{app_name}} + +
    +
    +
    +
    + + + + + +
    +
    +
    +
    +
    +
    +
    +
    + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/ebz/loginSnippet.html b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/ebz/loginSnippet.html new file mode 100644 index 000000000..0f29ee776 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/ebz/loginSnippet.html @@ -0,0 +1,120 @@ + + + + + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/ebz_template.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/ebz_template.jsp new file mode 100644 index 000000000..59b61d198 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/ebz_template.jsp @@ -0,0 +1,45 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%> + + + + + <%@ include file="/WEB-INF/fusion/jsp/meta.jsp" %> + + + +
    +
    + +
    +
    +
    +
    + +
    +
    +
    +
    + +
    +
    + + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/ebz_template_noheader_nofooter.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/ebz_template_noheader_nofooter.jsp new file mode 100644 index 000000000..98dccb4c0 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/ebz_template_noheader_nofooter.jsp @@ -0,0 +1,35 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%> + + + <%@ include file="/WEB-INF/fusion/jsp/meta.jsp" %> + +
    + +
    +
    + +
    +
    + +
    + + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/ebz_template_report_embedded.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/ebz_template_report_embedded.jsp new file mode 100644 index 000000000..4281a0636 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/ebz_template_report_embedded.jsp @@ -0,0 +1,48 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%> + + + <%@ include file="/WEB-INF/fusion/jsp/meta.jsp" %> + + + + + + + + + + + + + + + + + + +
    +
    + +
    +
    + + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/es_search_demo.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/es_search_demo.jsp new file mode 100644 index 000000000..9dc2102f9 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/es_search_demo.jsp @@ -0,0 +1,97 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> + + + +
    +
    Elastic Search - Corporate Location Data System
    +
    +
    + +   +
    + + + + + + + + + + + + + + + + + + + + + + + + +
    Customer NamePhoneStreetCityStateZIPCLLI
    {{options._source.name}}{{options._source.suggest.payload.tn}}{{options._source.suggest.payload.addr}}{{options._source.suggest.payload.city}}{{options._source.suggest.payload.st}}{{options._source.suggest.payload.zip}}{{options._source.suggest.payload.clli}}
    +
    +
    diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/es_suggest_demo.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/es_suggest_demo.jsp new file mode 100644 index 000000000..95b5e7cff --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/es_suggest_demo.jsp @@ -0,0 +1,97 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> + + + +
    +
    Elastic Search - Corporate Location Data System
    +
    +
    + +   +
    + + + + + + + + + + + + + + + + + + + + + + + + +
    Customer NamePhoneStreetCityStateZIPCLLI
    {{options.text}}{{options.payload.tn}}{{options.payload.addr}}{{options.payload.city}}{{options.payload.st}}{{options.payload.zip}}{{options.payload.clli}}
    +
    +
    diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/frame_insert.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/frame_insert.jsp new file mode 100644 index 000000000..5f550c683 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/frame_insert.jsp @@ -0,0 +1,44 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> + + + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/include.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/include.jsp new file mode 100644 index 000000000..cd6a5e09e --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/include.jsp @@ -0,0 +1,30 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +<%@ page import="org.openecomp.portalsdk.core.util.SystemProperties" %> +<%@ page import="org.openecomp.portalsdk.core.web.support.AppUtils" %> + +<%@ page import="java.util.LinkedHashMap" %> + + +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> +<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> + + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/jcs_admin.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/jcs_admin.jsp new file mode 100644 index 000000000..845beac2f --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/jcs_admin.jsp @@ -0,0 +1,144 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +<%-- <%@ include file="/WEB-INF/fusion/jsp/include.jsp"%> --%> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> +<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> + +<%@ include file="/WEB-INF/fusion/jsp/popup_modal.html" %> + +
    +

    Cache Regions

    + These are the regions which are currently defined in the cache. 'Items' and 'Bytes' refer to the elements currently in memory (not spooled). + You can clear all items for a region by clicking on the Clear icon next to the desired region below. You can also clear all regions which + empties the entire cache.

    + +
    +
    +
    Cache Name
    +
    # of Items
    +
    Bytes
    +
    Status
    +
    Memory Hits
    +
    Aux Hits
    +
    Not Found Misses
    +
    Expired Misses
    +
    Clear?
    +
    Items
    +
    +
    +
    + +
    {{region.size}}
    +
    {{region.byteCount}}
    +
    {{region.status}}
    +
    {{region.hitCountRam}}
    +
    {{region.hitCountAux}}
    +
    {{region.missCountNotFound}}
    +
    {{region.missCountExpired}}
    +
    +
    +
    +
    +
    +
    + +
    Key
    +
    Eternal?
    +
    Created
    +
    Max Life
    +
    Expires
    +
    Clear?
    +
    +
    +
    + + +
    {{item.eternal}}
    +
    {{item.createTime}}
    +
    {{item.maxLifeSeconds}}
    +
    {{item.expiresInSeconds}}
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/meta.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/meta.jsp new file mode 100644 index 000000000..3c4ff52ae --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/meta.jsp @@ -0,0 +1,36 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> + + + + + + + + + + + + + + + + + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/popup_modal.html b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/popup_modal.html new file mode 100644 index 000000000..0766cecdc --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/popup_modal.html @@ -0,0 +1,324 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/popup_modal_role.html b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/popup_modal_role.html new file mode 100644 index 000000000..c163002d9 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/popup_modal_role.html @@ -0,0 +1,274 @@ + + + + + + + + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/popup_modal_rolefunction.html b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/popup_modal_rolefunction.html new file mode 100644 index 000000000..ee0b51215 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/popup_modal_rolefunction.html @@ -0,0 +1,87 @@ + + + + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/post_search.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/post_search.jsp new file mode 100644 index 000000000..94d4b0bf6 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/post_search.jsp @@ -0,0 +1,356 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +<%@ page import="java.util.*" %> +<%@ page import="com.fasterxml.jackson.databind.ObjectMapper" %> +<%@ page import="org.json.JSONObject" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> +<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> +<%@ include file="/WEB-INF/fusion/jsp/popup_modal.html" %> +<%@ include file="/WEB-INF/fusion/jsp/popup_modal_rolefunction.html" %> +<%@ include file="/WEB-INF/fusion/jsp/popup_modal_role.html" %> + + +
    + +

    WEBPHONE Search

    +
    + Please enter search criteria below:
    + +
    + Last Name:
    + +
    + +
    + First Name:
    + +
    + +
    + UserId:
    + +
    + +
    + Manager OrgUserId:
    + +
    +
    +
    + Organization:
    + +
    + +
    + Email:
    + +
    +
    + +
    + + + +
    +
    + {{noResultsString}} +
    + + + + + + + + + + + + + + + + + + + + + + + + + +
    NoNameOrgUserIdOrganizationPhoneEmailImport?
    + {{$index + 1}} + +
    + {{profile.lastName}}, {{profile.firstName}} +
    + + +
    + {{profile.orgUserId}} + + {{profile.orgCode}} + + {{profile.phone}} + + {{profile.email}} + +
    +
    + +
    +
    +
    + Exists +
    +
    +
    + Rows Per Page: + +
    +
    + Current Page: + +
    +
    + Total Page(s): + +
    + +
    + +
    + +
    + + + + +
    + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/profile.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/profile.jsp new file mode 100644 index 000000000..b8e0106ec --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/profile.jsp @@ -0,0 +1,442 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +<%@ page import="org.openecomp.portalsdk.core.domain.User"%> +<%@ page import="org.openecomp.portalsdk.core.web.support.UserUtils"%> + +<%@page import="org.openecomp.portalsdk.core.web.support.ControllerProperties"%> +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> +<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> + + + +<%@ include file="/WEB-INF/fusion/jsp/popup_modal.html" %> + +<%@ include file="/WEB-INF/fusion/jsp/include.jsp"%> + +
    +

    + + +

    Profile Edit

    +
    + +

    Profile Edit

    +
    +
    +

    +
    + +
    + + Please edit the profile details below: 

    + +
    +
    + +
    + +
    +
    + +
    + +
    +
    + +
    + +
    +
    + +
    +
    +
    +
    + +
    + +
    +
    + +
    + +
    +
    + +
    + +
    +
    + +
    +
    +
    +
    + +
    + +
    +
    + +
    + +
    +
    + +
    + +
    +
    + +
    +
    +
    +
    + +
    + +
    +
    +
    +
    + +
    +
    + +
    + +
    +
    +
    +
    +
    +
    +
    +
    +
    + +
    + +
    + +
    +
    + + + +
    + + + + + + + + + + + + + + + + +
    NameRemove?
    {{ role.name }} + +
    + + + +
    + + + + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/profile_search.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/profile_search.jsp new file mode 100644 index 000000000..295faf035 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/profile_search.jsp @@ -0,0 +1,104 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +<%@ include file="/WEB-INF/fusion/jsp/popup_modal.html" %> +
    +
    +

    Profile Search

    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    User IDLast NameFirst NameEmailOrgUserIdManager OrgUserIdEditActive?
    {{rowData.id}}{{rowData.lastName}}{{rowData.firstName}}{{rowData.email}}{{rowData.orgUserId}}{{rowData.managerId}} +
    + +
    +
    +
    +
    +
    + Rows Per Page: + +
    +
    + Current Page: + +
    +
    + Total Page(s): + +
    +
    + + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/role.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/role.jsp new file mode 100644 index 000000000..9e944aa47 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/role.jsp @@ -0,0 +1,286 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> +<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> + +<%@ include file="/WEB-INF/fusion/jsp/popup_modal.html" %> +<%@ include file="/WEB-INF/fusion/jsp/popup_modal_rolefunction.html" %> +<%@ include file="/WEB-INF/fusion/jsp/popup_modal_role.html" %> + +
    + +
    +
    +

    + + +

    Role Edit

    +
    + +

    Role Create

    +
    +
    +

    +
    + +
    + +
    + Please edit the role details below: 
    + +
    +
    + +
    + +
    +
    + +
    + +
    + +
    + +
    +
    + + +
    + + + + + + + + + + + + + + +
    NameRemove?
    {{ roleFunction.name }} +
    +
    + Manage Role Functions

    + +
    + + +
    + + + + + + + + + + + + + + +
    NameRemove?
    {{ role.name }} +
    +
    + +
    + + + + + + + + + + + + + + +
    Role
    +
    + +
    +
    {{ availableRole.name }}
    +
    +
    + + + + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/role_function_list.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/role_function_list.jsp new file mode 100644 index 000000000..2df44ce1f --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/role_function_list.jsp @@ -0,0 +1,213 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> + +<%-- <%@ include file="/WEB-INF/fusion/jsp/include.jsp" %> --%> + +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> +<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> + +<%@ include file="/WEB-INF/fusion/jsp/popup_modal_rolefunction.html" %> +<%@ include file="/WEB-INF/fusion/jsp/popup_modal.html" %> +
    +
    + +

    Role Functions

    + + +

    + +
    + +
    + Click on the edit icon to update a role function, the plus icon to add additional role functions, or the delete icon to remove them. +
    +
    + + + + + + + + + + + + + + + + + +
    NameCodeEdit?Delete?
    {{ availableRoleFunction.name }}{{ availableRoleFunction.code }} + +
    +
    + +
    +
    +
    + + + + + + +
    + +
    +
    + +
    +
    +
    +
    + +
    +
    + + +
    + +
    + + + + + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/role_list.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/role_list.jsp new file mode 100644 index 000000000..c27c360b9 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/role_list.jsp @@ -0,0 +1,139 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> + +<%-- <%@ include file="/WEB-INF/fusion/jsp/include.jsp" %> --%> + +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> +<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> +<%@ include file="/WEB-INF/fusion/jsp/popup_modal.html" %> + +
    +

    Roles

    +
    +
    +Click on a Role to view its details. + +
    +
    + + + + + + + + + + + + + + + + + + +
    NamePriorityActive?Delete?
    {{ availableRole.name }}{{ availableRole.priority }} +
    + +
    +
    +
    +
    +
    + +
    + +
    + +
    + + + + + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/usage_list.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/usage_list.jsp new file mode 100644 index 000000000..4e45ffb37 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/usage_list.jsp @@ -0,0 +1,87 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> + +<%-- <%@ include file="/WEB-INF/fusion/jsp/include.jsp" %> --%> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> +<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> +<%@ include file="/WEB-INF/fusion/jsp/popup_modal.html" %> + +
    +
    +

    + Usage +

    +
    +
    + The following shows all users currently logged into the application. Click the icon to expel a user from the application. + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Current User Sessions
    User IdUser NameEmailLast Access Time (minutes)Time Remaining (minutes)Expel?
    {{user.id}}{{user.lastName}}{{user.email}}{{user.lastAccess}}{{user.remaining}}
    Current Session
    +
    +
    +
    +
    + + + + + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/webrtc/collaboration.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/webrtc/collaboration.jsp new file mode 100644 index 000000000..ff6c985e3 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/jsp/webrtc/collaboration.jsp @@ -0,0 +1,492 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + <%@ include file="/WEB-INF/fusion/jsp/popup_modal.html" %> + + + + + + + + + + + + + + + +
    +
    + + + + + + + + + + + + + + + + + +
    + + + + +
    + +
    +
    + + +
    +
    +
    +
    + +
    +
    + +
    +
    +
    +
    +
    +
    + + + + + + + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/orm/Fusion.hbm.xml b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/orm/Fusion.hbm.xml new file mode 100644 index 000000000..28060a7c4 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/orm/Fusion.hbm.xml @@ -0,0 +1,352 @@ + + + + + + + + + + + + seq_fn_user + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + seq_fn_audit_log + + + + + + + + + + + + + seq_fn_role + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + seq_fn_menu + + + + + + + + + + + + + + + + + + + + + + + + seq_fn_menu + + + + + + + + + + + + + + + + + + + + + + + + + + + + seq_fn_broadcast_message + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + select distinct md.parentMenu.id from MenuData as md where md.label = :paramLabel and md.label is not null + + + + select distinct md.id from MenuData as md where md.label = :paramLabel + + + + select distinct md.id, md.label, md.parentMenu.id from MenuData as md where md.label is not null + + + + select distinct functionCd from MenuData + + + + select distinct code from RoleFunction + + + + from MenuData where menuSetCode = :menu_set_cd and parentMenu is null + + + FROM UrlsAccessible A where upper(A.urlsAccessibleKey.url) = upper(:current_url) + + + + select firstName, lastName from User where id = :user_id + + + + select email from User where id = :user_id + + + + select id, firstName, lastName from User where active = true order by lastName, firstName + + + + select name from Role where id = :role_id + + + + select id, name from Role order by name + + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/orm/RNoteBookIntegration.hbm.xml b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/orm/RNoteBookIntegration.hbm.xml new file mode 100644 index 000000000..6638b4bc7 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/orm/RNoteBookIntegration.hbm.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/orm/Workflow.hbm.xml b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/orm/Workflow.hbm.xml new file mode 100644 index 000000000..3d8852cb3 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/orm/Workflow.hbm.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/custom_header_include.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/custom_header_include.jsp new file mode 100644 index 000000000..0bd373b75 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/custom_header_include.jsp @@ -0,0 +1,135 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +<%@ page import="org.openecomp.portalsdk.analytics.model.runtime.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.system.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.util.*" %> + +<%@ page import="java.net.*" %> + + + + + + +<%@ include file="/WEB-INF/fusion/jsp/include.jsp" %> + +<% + String url = request.getParameter("returnUrl"); + + if (url != null) { + request.setAttribute("returnUrl", URLDecoder.decode(url, "UTF-8")); + } + +%> + + +
    " method="POST" target="_parent"> + +
    + + + + + + + + + + + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/custom_js_include.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/custom_js_include.jsp new file mode 100644 index 000000000..5abbb5ad0 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/custom_js_include.jsp @@ -0,0 +1,31 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +<%-- + + +--%> diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/date_end_field_run_sql.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/date_end_field_run_sql.jsp new file mode 100644 index 000000000..fd2f9c366 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/date_end_field_run_sql.jsp @@ -0,0 +1,38 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +<%@ page import="java.util.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.system.AppUtils" %> +<%@ page import="org.openecomp.portalsdk.analytics.util.AppConstants" %> + + + +
    + + + +
    + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/date_start_field_run_sql.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/date_start_field_run_sql.jsp new file mode 100644 index 000000000..698272621 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/date_start_field_run_sql.jsp @@ -0,0 +1,39 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +<%@ page import="java.util.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.system.AppUtils" %> +<%@ page import="org.openecomp.portalsdk.analytics.util.AppConstants" %> + + + +
    + + + +
    + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/default_field_run_sql.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/default_field_run_sql.jsp new file mode 100644 index 000000000..95c99f378 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/default_field_run_sql.jsp @@ -0,0 +1,39 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +<%@ page import="java.util.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.system.AppUtils" %> +<%@ page import="org.openecomp.portalsdk.analytics.util.AppConstants" %> + + + +
    + + + +
    + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/disclaimer.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/disclaimer.jsp new file mode 100644 index 000000000..d5d252492 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/disclaimer.jsp @@ -0,0 +1,38 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +<% if(org.openecomp.portalsdk.analytics.system.Globals.getShowDisclaimer()) { %> + + + + <%if(!org.openecomp.portalsdk.analytics.system.Globals.hideRaptorFooter()) { %> + + + + + <% } %> + + + + + +
     
       
       
     
    + +<% } %> + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/error_include.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/error_include.jsp new file mode 100644 index 000000000..8158e6046 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/error_include.jsp @@ -0,0 +1,58 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +<%@ page import="java.util.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.util.*" %> + +<% ArrayList alErrorList = (ArrayList) request.getAttribute(AppConstants.RI_ERROR_LIST); + if((alErrorList!=null)&&(alErrorList.size()>0)) { %> +
    + + + + +<% for(int i=0; i=0) + sErrorMsg = sErrorMsg.substring(sErrorMsg.indexOf("|")+1); + if((i%2)==0) { %> + +<% } %> + +<% if((i%2)==1) { %> + +<% } + } // for +%> +<% if((alErrorList.size()%2)==1) { %> + + + +<% } %> +
    + Validation Errors Found
    + Following errors need to be corrected to continue: +
    +
  • <%= sErrorMsg %> +
  • +   +
    +<% } // if +%> + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/error_page.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/error_page.jsp new file mode 100644 index 000000000..8ee73be01 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/error_page.jsp @@ -0,0 +1,229 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +<%@ page import="java.io.*" %> +<%@ page import="java.util.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.runtime.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.system.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.util.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.error.UserAccessException"%> +<%@ page import="org.openecomp.portalsdk.analytics.error.RaptorException"%> +<%@ page import="org.openecomp.portalsdk.analytics.error.UserDefinedException"%> +<%@ page isErrorPage="true" %> + + +<% java.lang.Exception ex = (Exception) request.getAttribute(AppConstants.RI_EXCEPTION); %> +<% boolean showEditLink = false; + if(AppUtils.getRequestNvlValue(request, "r_action").equals("report.run")) { + ReportRuntime rr = (ReportRuntime) request.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME); + if(rr!=null) + try { + rr.checkUserWriteAccess(request); + showEditLink = true; + } catch(Exception e) {} + } // if +%> + + + + + + + + + + + Application Error + + + +<%-- jsp:include page="custom_header_include.jsp" flush="true" /--%> + +
    + + + "> + + +
    + + + + +<% if(ex!=null) { %> + <% if(ex instanceof org.openecomp.portalsdk.analytics.error.RaptorSchedularException) { %> + <% if(AppUtils.isAdminUser(request)) { %> + + + + <% } %> + + + + <% } %> + <% if(ex!=null) ex.printStackTrace(); %> + <% if(AppUtils.isAdminUser(request)) { + if ((ex instanceof org.openecomp.portalsdk.analytics.error.ReportSQLException)|| + (request.getAttribute("c_error_sql")!=null && !((String) request.getAttribute("c_error_sql")).trim().equals(""))) { + String sql = ""; + if(ex instanceof org.openecomp.portalsdk.analytics.error.ReportSQLException) + sql = ((org.openecomp.portalsdk.analytics.error.ReportSQLException) ex).getReportSQL(); + else + sql = (String) request.getAttribute("c_error_sql"); %> + <% if (sql!=null && sql.length() > 0) { %> + + + + + + + <% request.setAttribute("c_error_sql", sql); + %> + <% } %> + + + + <% if(request.getAttribute("c_error_url")!=null && !((String) request.getAttribute("c_error_url")).trim().equals("")) { %> + + + + <% } // if %> + <% } else { // reportSQLException + if (ex instanceof RaptorException) { %> + + + + <%} %> + <% } %> + <% } else { + if (ex instanceof UserAccessException) { %> + + + + <% } else if (ex instanceof UserDefinedException) { %> + + + + <% } + } %> + + + +<% } else { %> +<% if(exception instanceof org.openecomp.portalsdk.analytics.error.RaptorSchedularException) { %> + <% if(AppUtils.isAdminUser(request)) { %> + + + + <% } %> + + + <% if(exception!=null) exception.printStackTrace(); %> + +<% } %> +<% if(AppUtils.isAdminUser(request)) { + if ((exception instanceof org.openecomp.portalsdk.analytics.error.ReportSQLException)|| + (request.getAttribute("c_error_sql")!=null && !((String) request.getAttribute("c_error_sql")).trim().equals(""))) { + String sql = ""; + if(exception instanceof org.openecomp.portalsdk.analytics.error.ReportSQLException) + sql = ((org.openecomp.portalsdk.analytics.error.ReportSQLException) ex).getReportSQL(); + else + sql = (String) request.getAttribute("c_error_sql"); %> + <% if (sql!=null && sql.length() > 0) { %> + + + + + + +<% request.setAttribute("c_error_sql", sql); + %> + <% } %> + + + +<% if(request.getAttribute("c_error_url")!=null && !((String) request.getAttribute("c_error_url")).trim().equals("")) { %> + + + +<% } %> +<% } %> +<% } %> + + + +<% if(AppUtils.isAdminUser(request)) { %> + +<% } %> +<% if(exception!=null) exception.printStackTrace(); %> + +<% } // else +%> +
    +<% if(showEditLink) { %> + +<% } %> + Error/User-Alert Message: +
    + Exception Class: <%= (ex!=null && ex instanceof org.openecomp.portalsdk.analytics.error.RaptorSchedularException)?ex.getClass().toString():"" %> +
    Message: <%= (ex!=null && ex instanceof org.openecomp.portalsdk.analytics.error.RaptorSchedularException)?ex.getMessage():"" %> +
    + SQL Execution Error: +
    + <%= sql %> +
    + Error Message:
    + <%= AppUtils.getRequestNvlValue(request, "error_extra_msg") %><%= ex.getMessage() %> +
    + Please ">click here to edit report definition. +
    + Error Message:
    + <%= AppUtils.getRequestNvlValue(request, "error_extra_msg") %><%= ex.getMessage() %> +
    + Error Message:
    + <%= AppUtils.getRequestNvlValue(request, "error_extra_msg") %><%= ex.getMessage() %> +
    + Error Message:
    + <%= AppUtils.getRequestNvlValue(request, "error_extra_msg") %><%= ex.getMessage() %> +
    + ** The system administrator has been notified for this error. +
    + Exception Class: <%= (exception!=null && exception instanceof org.openecomp.portalsdk.analytics.error.RaptorSchedularException)?exception.getClass().toString():"" %> +
    Message: <%= (exception!=null && exception instanceof org.openecomp.portalsdk.analytics.error.RaptorSchedularException)?exception.getMessage():"" %> +
    + SQL Execution Error: +
    + <%= sql %> +
    + Error Message:
    + <%= AppUtils.getRequestNvlValue(request, "error_extra_msg") %><%= ex.getMessage() %> +
    + Please ">click here to edit report definition. +
    + ** The system administrator has been notified for this error. +
    + +
    + + + + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/footer.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/footer.jsp new file mode 100644 index 000000000..c4fbe9e84 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/footer.jsp @@ -0,0 +1,25 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> + + + + + +<%----%> diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/popup_drill_down_report.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/popup_drill_down_report.jsp new file mode 100644 index 000000000..53959482c --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/popup_drill_down_report.jsp @@ -0,0 +1,601 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +<%@ page import="java.util.*" %> + +<%@ page import="org.openecomp.portalsdk.analytics.xmlobj.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.definition.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.runtime.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.system.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.util.*" %> + +<% ReportDefinition rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION); + List reportCols = rdef.getAllColumns(); + List rFormFields = null; + if(rdef.getFormFieldList()!=null&&rdef.getFormFieldList().getFormField().size()>0) + rFormFields = rdef.getFormFieldList().getFormField(); + + ReportFormFields ddReportFormFields = (ReportFormFields) request.getAttribute(AppConstants.RI_FORM_FIELDS); + + String drillDownSuppress = AppUtils.getRequestNvlValue(request, "drillDownSuppress"); + String drillDownParams = AppUtils.getRequestNvlValue(request, "drillDownParams"); + String drillDownRequest = AppUtils.getRequestNvlValue(request, "drillDownRequest"); + + Hashtable paramDefinitions = new Hashtable(); + StringTokenizer st = new StringTokenizer(drillDownParams, "&"); + //Added for passing request parameters in Drill Down + String[] reqParameters = Globals.getRequestParams().split(","); + int icnt=0; + // + while(st.hasMoreTokens()) { + String param = st.nextToken(); + DrillDownParamDef paramDef = new DrillDownParamDef(param); + if(paramDef.getFieldName().length()>0) + paramDefinitions.put(paramDef.getFieldName(), paramDef); + } // while +%> + + + + Drill-down Parameters Configuration + + + + + + + +
    + + + + + +<% if(ddReportFormFields!=null) + for(ddReportFormFields.resetNext(); ddReportFormFields.hasNext(); ) { + FormField ff = ddReportFormFields.getNext(); + if(!ff.getFieldType().equals(FormField.FFT_BLANK)) { + + DrillDownParamDef paramDef = (DrillDownParamDef) paramDefinitions.get(ff.getFieldName()); + if(paramDef==null) + paramDef = new DrillDownParamDef(""); %> + + <% if (ff!=null && (ff.getValidationType().equals(FormField.VT_TIMESTAMP_HR) || ff.getValidationType().equals(FormField.VT_TIMESTAMP_MIN) || ff.getValidationType().equals(FormField.VT_TIMESTAMP_SEC)) ) { + %> + + + + + + + + + + + + + + + +<% if(rFormFields!=null) { %> + + + + + + + + +<% } // if + +%> + + <% + paramDef = (DrillDownParamDef) paramDefinitions.get(ff.getFieldName()+"_Hr"); + if(paramDef==null) + paramDef = new DrillDownParamDef(""); + %> + + + + + + + + + + + +<% + if (ff.getValidationType().equals(FormField.VT_TIMESTAMP_MIN) || ff.getValidationType().equals(FormField.VT_TIMESTAMP_SEC)) { +%> + <% + paramDef = (DrillDownParamDef) paramDefinitions.get(ff.getFieldName()+"_Min"); + if(paramDef==null) + paramDef = new DrillDownParamDef(""); + %> + + + + + + + + + + + +<% + } + if(ff.getValidationType().equals(FormField.VT_TIMESTAMP_SEC)) { +%> + <% + paramDef = (DrillDownParamDef) paramDefinitions.get(ff.getFieldName()+"_Sec"); + if(paramDef==null) + paramDef = new DrillDownParamDef(""); + %> + + + + + + + + + + + +<% + + } + + } else { +%> + + + + + + + + + + + + + + + +<% if(rFormFields!=null) { %> + + + + + + + + +<% } // if + } // else + } // if BLANK + } // for +%> + + + + + + + + + + + + + + + + + <% if(!Globals.getPassRequestParamInDrilldown() && (!(reqParameters.length==1 && reqParameters[0].length()<=0))) { + %> + + + + + <% + icnt=0; + + for (int i = 0; i < reqParameters.length; i++) { + icnt++; + + %> + > + + + + + <% + } //for + %> + + <% + } // if requestParam + %> + + + + + + + +
    + DRILL-DOWN PARAMETERS CONFIGURATION +
    +  <%= ff.getFieldDisplayName() %> +
    +       + >No value + + Accept default +
    +       + >Fixed value + + " onChange="document.dataform.r_<%= ff.getFieldName() %>[1].click();"> +
    +       + >Value of column + + +
    +       + >Value of form field + + +
    +       + >Value set + + Pass the value of the selected column if not empty,
    + otherwise pass the value of the selected form field
    +
    +  <%= ff.getFieldDisplayName() %> (Hour) +
    +       + >No value + + Accept default +
    +       + >Value of column + + + + +
    +  <%= ff.getFieldDisplayName() %> (Minutes) +
    +       + >No value + + Accept default +
    +       + >Value of column + + + + +
    +  <%= ff.getFieldDisplayName() %> (Seconds) +
    +       + >No value + + Accept default +
    +       + >Value of column + + + + +
    +  <%= ff.getFieldDisplayName() %> +
    +       + >No value + + Accept default +
    +       + >Fixed value + + " onChange="document.dataform.r_<%= ff.getFieldName() %>[1].click();"> +
    +       + >Value of column + + +
    +       + >Value of form field + + +
    +       + >Value set + + Pass the value of the selected column if not empty,
    + otherwise pass the value of the selected form field
    +
     
    +  Parameter values not to be passed to the drill-down report
    +       + Suppress values + + +
    separate by | if multiple values
    +
     
    +  Request Parameter values to be passed to the drill-down report
    <%= reqParameters[i]%> + > +
    + Show Drilled Down Report In Popup Window: +
    +
    +

    + + + + +<%! private String nvl(String s) { return (s==null)?"":s; } + private String nvl(String s, String sDefault) { return nvl(s).equals("")?sDefault:s; } %> + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/popup_import_semaphore.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/popup_import_semaphore.jsp new file mode 100644 index 000000000..d73a7fe25 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/popup_import_semaphore.jsp @@ -0,0 +1,80 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +<%@ page import="java.util.*" %> + +<%@ page import="org.openecomp.portalsdk.analytics.xmlobj.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.base.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.definition.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.system.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.util.*" %> + +<% ArrayList importedList = (ArrayList) request.getAttribute(AppConstants.RI_DATA_SET); %> + + + + Advanced Display Formatting + + + + + + +
    + + + + + + + + + + + +
     Advanced Display Formatting Import
    +<% if(importedList!=null&&importedList.size()>0) { %> + <%= importedList.size() %> Advanced Display Formattings successfully imported. +<% } else { %> + The selected report does not have Advanced Display Formattings
    + defined. No Advanced Display Formattings were imported. +<% } %> +
    +
    + +
    + + + + + + +<%! private String nvl(String s) { return (s==null)?"":s; } + private String nvl(String s, String sDefault) { return nvl(s).equals("")?sDefault:s; } %> + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/popup_semaphore.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/popup_semaphore.jsp new file mode 100644 index 000000000..39eafb249 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/popup_semaphore.jsp @@ -0,0 +1,419 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +<%@ page import="java.util.*" %> + +<%@ page import="org.openecomp.portalsdk.analytics.xmlobj.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.base.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.definition.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.system.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.util.*" %> + +<% ReportDefinition rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION); + + String semaphoreId = AppUtils.getRequestNvlValue(request, "semaphoreId"); + String semaphoreType = AppUtils.getRequestNvlValue(request, "semaphoreType"); + SemaphoreType semaphore = rdef.getSemaphoreById(semaphoreId); + String semaphoreName = null; + List listColumns = rdef.getAllColumns(); + if(semaphore!=null) + semaphoreName = semaphore.getSemaphoreName(); + else + if(rdef.getSemaphoreList()!=null) + semaphoreName = "Display Formatting "+(rdef.getSemaphoreList().getSemaphore().size()+1); + else + semaphoreName = "Display Formatting 1"; + + String submitBtn = AppUtils.getRequestNvlValue(request, "submit_btn"); %> + + + + Advanced Display Formatting + + +<% if(submitBtn.startsWith("Save")) { %> + +<% } %> + +<% if(submitBtn.equals("Save")) { %> + + + Please wait... +<% } else { %> + + + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +<% for(int i = 0; i<3+((semaphore==null)?2:semaphore.getFormatList().getFormat().size()); i++) { + FormatType ft = null; + if(semaphore!=null&&i + > + <% if(i==0) { %> + + <% } else { %> + + + + <% } %> + + + + + + + + + + +<% } // for +%> + + + +
     Advanced Display Formatting Definition
    Display Name: + +
    Apply Formatting To: + <% String sValue = AppConstants.ST_CELL; + if(semaphore!=null) + sValue = nvl(semaphore.getSemaphoreType(), AppConstants.ST_CELL); %> +
     
    Column Value IsBold?Italic?Under-
    line?
    Background ColorFont ColorFont FaceFont Size     Preview     
    + Any Other + "> + + + + + "> + <% sValue = "="; + if(ft!=null) + sValue = nvl(ft.getExpression(), "="); %> + + + "> + + <% boolean bValue = false; + if(ft!=null) + bValue = ft.isBold(); %> + "> + onClick="setBold(<%= i %>)"> + + <% bValue = false; + if(ft!=null) + bValue = ft.isItalic(); %> + "> + onClick="setItalic(<%= i %>)"> + + <% bValue = false; + if(ft!=null) + bValue = ft.isUnderline(); %> + "> + onClick="setUnderline(<%= i %>)"> + + <% sValue = ""; + if(ft!=null) + sValue = nvl(ft.getBgColor()); %> + + + <% sValue = ""; + if(ft!=null) + sValue = nvl(ft.getFontColor()); %> + + + <% sValue = ""; + if(ft!=null) + sValue = nvl(ft.getFontFace()); %> + + + <% sValue = "11"; + if(ft!=null) + sValue = nvl(ft.getFontSize(), "11"); %> + + + Sample +
    +
    + + + +
    + +
    + +<% } // if(submitBtn.equals("Save")) { ... } else { +%> + + + + +<%! private String nvl(String s) { return (s==null)?"":s; } + private String nvl(String s, String sDefault) { return nvl(s).equals("")?sDefault:s; } %> + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/popup_sql.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/popup_sql.jsp new file mode 100644 index 000000000..c685bb138 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/popup_sql.jsp @@ -0,0 +1,55 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +<%@ page import="java.util.*" %> + +<%@ page import="org.openecomp.portalsdk.analytics.system.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.util.*" %> + + + + <%= nvl((String) request.getAttribute(AppConstants.RI_PAGE_TITLE)) %> + + + + + + + + + + + + + +
    + <%= nvl((String) request.getAttribute(AppConstants.RI_PAGE_SUBTITLE), nvl((String) request.getAttribute(AppConstants.RI_PAGE_TITLE))) %> +
    > + <%= nvl((String) request.getAttribute(AppConstants.RI_FORMATTED_SQL)) %> +
    +
    + +
    +
    + + + +<%! private String nvl(String s) { return (s==null)?"":s; } + private String nvl(String s, String sDefault) { return nvl(s).equals("")?sDefault:s; } %> + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/popup_table_cols.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/popup_table_cols.jsp new file mode 100644 index 000000000..9dec6a53a --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/popup_table_cols.jsp @@ -0,0 +1,171 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +<%@ page import="java.util.*" %> + +<%@ page import="org.openecomp.portalsdk.analytics.xmlobj.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.base.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.definition.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.system.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.util.*" %> + +<% String tableName = AppUtils.getRequestValue(request, AppConstants.RI_TABLE_NAME); + String remoteDbPrefix = (String) session.getAttribute("remoteDB"); + Vector tableSources = null; + Vector dbColumns = null; + if(tableName==null) { + tableSources = DataCache.getReportTableSources(remoteDbPrefix); + if(tableSources.size()>0) + tableName = ((TableSource) DataCache.getReportTableSources(remoteDbPrefix).get(0)).getTableName(); + } + if(tableName!=null) + dbColumns = DataCache.getReportTableDbColumns(tableName.toUpperCase(),remoteDbPrefix); + + + boolean isSingleValueChoice = AppUtils.getRequestFlag(request, "single_value"); + boolean includeTableNameInResult = AppUtils.getRequestFlag(request, "return_table_name"); + boolean includeColTypeInResult = AppUtils.getRequestFlag(request, "return_col_type"); %> + + + + Table Columns + + + + + + + + +<% if(! isSingleValueChoice) { %> + +<% } // if +%> + + +
    + + +<% if(isSingleValueChoice) { %> + +<% } %> +<% if(includeTableNameInResult) { %> + +<% } %> +<% if(includeColTypeInResult) { %> + +<% } %> + + + + + + + <% int rNum = 0; + if(dbColumns!=null) + for(rNum=0; rNum + > + + <% if(isSingleValueChoice) { %> + + <% } else { %> + + + <% } // else + %> + + <% } // for + if(rNum==0) { %> + + + + <% } else { // if + %> + + + + <% + } + %> + + + + +
      + <% if(! isSingleValueChoice) { %> +   + <% } %> + + + DB Table Columns +
    <%= (rNum+1) %><%= sDisplay %> + + <%= sDisplay %>
    No columns found for table [<%= tableName %>]
    <%= "CLEAR VALUE" %>
      + <% if(! isSingleValueChoice) { %> +   + <% } %> +  
    + + + +
    + + + + +<%! private String nvl(String s) { return (s==null)?"":s; } + private String nvl(String s, String sDefault) { return nvl(s).equals("")?sDefault:s; } %> + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/popup_testrun_sql.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/popup_testrun_sql.jsp new file mode 100644 index 000000000..a5dbd5026 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/popup_testrun_sql.jsp @@ -0,0 +1,103 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +<%@ page import="java.io.*" %> +<%@ page import="java.util.*" %> + +<%@ page import="org.openecomp.portalsdk.analytics.model.definition.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.system.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.util.*" %> + +<% Exception ex = (Exception) request.getAttribute(AppConstants.RI_EXCEPTION); + DataSet ds = (DataSet) request.getAttribute(AppConstants.RI_DATA_SET); %> + + + +SQL Statement Test Run + + + + + + + + +<% if(ex!=null) { %> + + + +<% } else if(ds!=null) { %> + + + <% for(int c=0; c + + <% } %> + + <% for(int r=0; r + > + + <% for(int c=0; c + + <% } %> + + <% } // for r + if(ds.getRowCount()>Globals.getDefaultPageSize()) { %> + > + + + + <% } else if(ds.getRowCount()==0) { %> + + + + <% } // else if + } // else if +%> + + + +
    +
    +
    + <%= nvl(ex.getMessage(), " ") %> +

    + +
     <%= ds.getColumnName(c) %>
    <%= (r+1) %><%= nvl(ds.getString(r, c), " ") %>
    <%= (Globals.getDefaultPageSize()+1) %>...
    No data found
    +
    +
    + + + +<%! private String nvl(String s) { return (s==null)?"":s; } + private String nvl(String s, String sDefault) { return nvl(s).equals("")?sDefault:s; } %> + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/report_download_csv.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/report_download_csv.jsp new file mode 100644 index 000000000..811580474 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/report_download_csv.jsp @@ -0,0 +1,89 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +<%@ page trimDirectiveWhitespaces="true" %> +<%@ page import="java.util.*" %><%@ page import="java.text.*" %><%@ page import="java.io.*" %><%@ page import="org.openecomp.portalsdk.analytics.model.*" %><%@ page import="org.openecomp.portalsdk.analytics.model.runtime.*" %><%@ page import="org.openecomp.portalsdk.analytics.view.*" %><%@ page import="org.openecomp.portalsdk.analytics.system.*" %><%@ page import="org.openecomp.portalsdk.analytics.util.*" %><% + ReportRuntime rr = null; + ReportData rd = null; + String parent = ""; + int parentFlag = 0; + if(!nvl(request.getParameter("parent"), "").equals("N")) parent = nvl(request.getParameter("parent"), ""); + if(parent.startsWith("parent_")) parentFlag = 1; + if(parentFlag == 1) { + rr = (ReportRuntime) request.getSession().getAttribute(parent+"_rr"); + rd = (ReportData) request.getSession().getAttribute(parent+"_rd"); + } + if(rr==null) rr = (ReportRuntime) request.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME); + if(rd==null) rd = (ReportData) request.getSession().getAttribute(AppConstants.RI_REPORT_DATA); + String formattedReportName = new HtmlStripper().stripSpecialCharacters(rr.getReportName()); + String formattedDate = new SimpleDateFormat("MMddyyyyHHmm").format(new Date()); + String fName = formattedReportName+formattedDate+AppUtils.getUserID(request); + boolean raw = AppUtils.getRequestFlag(request, "raw"); + if(true && !raw) + response.setContentType("application/octet-stream"); + else + response.setContentType("application/csv"); + String fileName = fName+".csv"; + String sql_whole = (String) request.getAttribute(AppConstants.RI_REPORT_SQL_WHOLE); + if(true && !raw) + response.setHeader("Content-disposition","attachment;filename="+fName+".zip"); + else + response.setHeader("Content-disposition","attachment;filename="+fName+".csv"); + try {(new ReportHandler()).createCSVFileContent(out, rd, rr, sql_whole, request,fName); + //out.flush(); + //out.close(); + if(true) { + // response.reset(); + ServletOutputStream outS = response.getOutputStream(); + java.io.File file = null; + if(true && !raw) { + response.setContentType("application/octet-stream"); + response.setHeader("Content-disposition","attachment;filename="+fName+".zip"); + file = new java.io.File(AppUtils.getTempFolderPath()+""+fName+".zip"); + } else { + response.setContentType("application/csv"); + response.setHeader("Content-disposition","attachment;filename="+fName+".csv"); + file = new java.io.File(AppUtils.getTempFolderPath()+""+fName+".csv"); + } + FileInputStream fileIn = new FileInputStream(file); + int c; + while((c=fileIn.read()) != -1){ + outS.write(c); + } + outS.flush(); + outS.close(); + fileIn.close(); + + + /*byte[] outputByte = new byte[4096]; + //copy binary contect to output stream + while(fileIn.read(outputByte, 0, 4096) != -1) { + outS.write(outputByte, 0, 4096); + } + fileIn.close(); + outS.flush(); + outS.close();*/ + } + } catch(Exception e) { + e.printStackTrace(); + Log.write("Fatal error [report_download_csv.jsp]: "+e.getMessage()); + } +%> +<%! private String nvl(String s) { return (s==null)?"":s; } + private String nvl(String s, String sDefault) { return nvl(s).equals("")?sDefault:s; } %> diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/report_download_pdf.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/report_download_pdf.jsp new file mode 100644 index 000000000..e5ae9ddef --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/report_download_pdf.jsp @@ -0,0 +1,40 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +<%@ page trimDirectiveWhitespaces="true" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.pdf.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.runtime.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.view.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.system.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.util.*" %> +<% + ReportRuntime rr = (ReportRuntime) request.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME); + ReportData rd = (ReportData) request.getSession().getAttribute(AppConstants.RI_REPORT_DATA); + try { + new PdfReportHandler().createPdfFileContent(request,response, 3); + } catch(Exception e) { + Log.write("Fatal error [report_download_pdf.jsp]: "+e.getMessage()); + e.printStackTrace(); + } + out.clear(); + out = pageContext.pushBody(); +%> + + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/report_download_xls.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/report_download_xls.jsp new file mode 100644 index 000000000..a82470d81 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/report_download_xls.jsp @@ -0,0 +1,64 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +<%@ page import="org.openecomp.portalsdk.analytics.model.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.runtime.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.view.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.system.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.util.*" %> +<% +ReportRuntime rr = null; +ReportData rd = null; +String parent = ""; +int parentFlag = 0; +if(!nvl(request.getParameter("parent"), "").equals("N")) parent = nvl(request.getParameter("parent"), ""); +if(parent.startsWith("parent_")) parentFlag = 1; +if(parentFlag == 1) { + rr = (ReportRuntime) request.getSession().getAttribute(parent+"_rr"); + rd = (ReportData) request.getSession().getAttribute(parent+"_rd"); +} +if(rr==null) rr = (ReportRuntime) request.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME); +if(rd==null) rd = (ReportData) request.getSession().getAttribute(AppConstants.RI_REPORT_DATA); + + if(rr != null && rr.getReportType().equals(AppConstants.RT_DASHBOARD)) { + //rr = (ReportRuntime) request.getSession().getAttribute("FirstDashReport"); + } else if (rr == null) + rr = (ReportRuntime) request.getSession().getAttribute("FirstDashReport"); + //rd = (ReportData) request.getSession().getAttribute(AppConstants.RI_REPORT_DATA); + + //response.setContentType("application/vnd.ms-excel"); + //response.setHeader("Content-disposition","attachment;filename=download_all_"+AppUtils.getUserID(request)+".xls"); + String user_id = AppUtils.getUserID(request); + try { +/* if (rr.getReportType().equals(AppConstants.RT_CROSSTAB)) { + int downloadLimit = (rr.getMaxRowsInExcelDownload()>0)?rr.getMaxRowsInExcelDownload():Globals.getDownloadLimit(); + rd = rr.loadReportData(-1, AppUtils.getUserID(request), downloadLimit,request); + } +*/ + new ReportHandler().createExcelFileContent(out, rd, rr, request, response, user_id, 3); //3 whole + } catch(Exception e) { + e.printStackTrace(); + Log.write("Fatal error [report_download_xls.jsp]: "+e.getMessage()); + } + out.clear(); + out = pageContext.pushBody(); +%> +<%! private String nvl(String s) { return (s==null)?"":s; } + private String nvl(String s, String sDefault) { return nvl(s).equals("")?sDefault:s; } %> + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/report_ebz.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/report_ebz.jsp new file mode 100644 index 000000000..8d42b65ba --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/report_ebz.jsp @@ -0,0 +1,179 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    Loading...
    +
    +
    +
    + + + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/report_import.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/report_import.jsp new file mode 100644 index 000000000..014f98ac5 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/report_import.jsp @@ -0,0 +1,69 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +<%@ page import="java.util.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.system.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.util.*" %> + + + + Import + + + + +

    + +
    + + + + + + + + + + + + + +
    + <%= Globals.getBaseTitle() %> > IMPORT REPORT XML +
    + + + +
    +
    + +
    + + + +
    + + + + + + +<%! private String nvl(String s) { return (s==null)?"":s; } + private String nvl(String s, String sDefault) { return nvl(s).equals("")?sDefault:s; } %> + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/report_sample.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/report_sample.jsp new file mode 100644 index 000000000..cfbfad14e --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/report_sample.jsp @@ -0,0 +1,40 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +

    Customizable Analytics Dashboard

    + + + + + + + + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/report_search.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/report_search.jsp new file mode 100644 index 000000000..480bdbcb9 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/report_search.jsp @@ -0,0 +1,2432 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> + + + + + + + +
    +
    +
    + + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/report_wizard.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/report_wizard.jsp new file mode 100644 index 000000000..cdfe943a5 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/report_wizard.jsp @@ -0,0 +1,309 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +<%-- + Name: report_wizard.jsp + Use : Master JSP which navigates to specific JSP when different tab is selected. Default it navigates to the wizard_definition.jsp + + Change Log + ========== + + 22-Jun-2009 : Version 8.4 (Sundar); + +
      +
    • Save button is suppressed from showing when wizard is in the last page (Run page).
    • +
    • width of the content_iframe is changed back to default one when navigated from >100% report's run page.
    • +
    +--%> +<%@ page import="java.util.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.xmlobj.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.base.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.definition.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.runtime.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.controller.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.system.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.util.*" %> + +<%@ page errorPage="error_page.jsp" %> + + + + + + +<% ReportDefinition rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION); + + String reportID = rdef.getReportID(); + WizardSequence ws = rdef.getWizardSequence(); + + String curStep = ws.getCurrentStep(); + String curSubStep = ws.getCurrentSubStep(); + + String dbInfo = null; + dbInfo = rdef.getDBInfo(); + int sessionflag = 0; + if(dbInfo == null || dbInfo.length() == 0) { + dbInfo = (String) session.getAttribute("remoteDB"); + sessionflag = 1; + } + session.setAttribute("remoteDB", dbInfo); + if((dbInfo == null) && (request.getParameter("dataSource")!=null)) + session.setAttribute("remoteDB", request.getParameter("dataSource")); + + String title = (reportID.equals("-1")?"Create Report":"Edit Report"); + String navTitle = Globals.getBaseTitle()+" > " + title; + + boolean isCrossTab = rdef.getReportType().equals(AppConstants.RT_CROSSTAB); + boolean isSQLBased = rdef.getReportDefType().equals(AppConstants.RD_SQL_BASED); +%> + +<% + request.setAttribute(AppConstants.SI_REPORT_DEFINITION,rdef); +%> + + + + + + + + + + + + + +
    + +
    +
    +
    + +
    + + + + + + + + + + +
    + + +<% for(ws.resetNext(); ws.hasNext(); ) { + String sTab = ws.getNext(); %> + + + +<% } // for +%> + + +
    " width="9" height="24"> align="center" valign="middle"> + <% if(sTab.equals(curStep)) { %> +  <%= clearSpaces(sTab) %>  + <% } else if(reportID.equals("-1")) { %> +  <%= clearSpaces(sTab) %>  + <% } else { %> +  <%= clearSpaces(sTab) %>  + <% } %> + " width="9" height="24"> 
    +
    + + + + +
    <%= navTitle %>
    +
    <% if(curStep.equals(AppConstants.WS_DEFINITION)) { %> + <% if(sessionflag == 1) dbInfo = ""; %> + +<% } else if(curStep.equals(AppConstants.WS_SQL)) { %> + +<% } else if(curStep.equals(AppConstants.WS_TABLES)&&curSubStep.equals("")) { %> + +<% } else if(curStep.equals(AppConstants.WS_TABLES)&&(curSubStep.equals(AppConstants.WSS_ADD)||curSubStep.equals(AppConstants.WSS_EDIT))) { %> + +<% } else if(curStep.equals(AppConstants.WS_COLUMNS)&&curSubStep.equals("")) { %> + +<% } else if(curStep.equals(AppConstants.WS_COLUMNS)&&curSubStep.equals(AppConstants.WSS_ADD_MULTI)) { %> + +<% } else if(curStep.equals(AppConstants.WS_COLUMNS)&&curSubStep.equals(AppConstants.WSS_ORDER_ALL)) { %> + +<% } else if(curStep.equals(AppConstants.WS_COLUMNS)&&(curSubStep.equals(AppConstants.WSS_ADD)||curSubStep.equals(AppConstants.WSS_EDIT) ||curSubStep.equals(AppConstants.WA_MODIFY))) { %> + +<% } else if(curStep.equals(AppConstants.WS_FORM_FIELDS)&&curSubStep.equals("")||curSubStep.equals(AppConstants.WSS_ADD_BLANK)) { %> + +<% } else if(curStep.equals(AppConstants.WS_FORM_FIELDS)&&(curSubStep.equals(AppConstants.WSS_ADD)||curSubStep.equals(AppConstants.WSS_EDIT))) { %> + +<% } else if(curStep.equals(AppConstants.WS_FILTERS)&&curSubStep.equals("")) { %> + +<% } else if(curStep.equals(AppConstants.WS_FILTERS)&&(curSubStep.equals(AppConstants.WSS_ADD)||curSubStep.equals(AppConstants.WSS_EDIT))) { %> + +<% } else if(curStep.equals(AppConstants.WS_SORTING)&&curSubStep.equals("")) { %> + +<% } else if(curStep.equals(AppConstants.WS_SORTING)&&curSubStep.equals(AppConstants.WSS_ORDER_ALL)) { %> + +<% } else if(curStep.equals(AppConstants.WS_SORTING)&&(curSubStep.equals(AppConstants.WSS_ADD)||curSubStep.equals(AppConstants.WSS_EDIT))) { %> + +<% } else if(curStep.equals(AppConstants.WS_JAVASCRIPT)) { %> + +<% } else if(curStep.equals(AppConstants.WS_CHART)) { %> + +<% } else if(curStep.equals(AppConstants.WS_USER_ACCESS)) { %> + +<% } else if(curStep.equals(AppConstants.WS_SCHEDULE)) { %> + +<% } else if(curStep.equals(AppConstants.WS_REPORT_LOG)) { %> + +<% } else if(curStep.equals(AppConstants.WS_MAP)) { %> + +<% } else if(curStep.equals(AppConstants.WS_DATA_FORECASTING)) { %> + +<% } else { %> + +<% } %> + +
    + + + + + +
    +   + + <% if(! ws.isInitialStep()) { %> + + <% } %> + + <% if(! ws.isFinalStep()) { %> + + + <% } %> +
    +
    + +
    + + + + + +
    +
    +<%----%> + +<%! private String HTMLEncode(String value) { + StringBuffer sb = new StringBuffer(value); + + for(int i=0; i') + sb.replace(i, i+1, ">"); + else if(sb.charAt(i)=='"') + sb.replace(i, i+1, """); + + return sb.toString(); + } // HTMLEncode + + private String clearSpaces(String value) { + StringBuffer sb = new StringBuffer(value); + + for(int i=0; i + + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/test_field_run_sql.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/test_field_run_sql.jsp new file mode 100644 index 000000000..2fdcee46e --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/test_field_run_sql.jsp @@ -0,0 +1,39 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +<%@ page import="java.util.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.system.AppUtils" %> +<%@ page import="org.openecomp.portalsdk.analytics.util.AppConstants" %> + + + +
    + + + +
    + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/test_run_sql.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/test_run_sql.jsp new file mode 100644 index 000000000..1c30437bc --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/test_run_sql.jsp @@ -0,0 +1,38 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +<%@ page import="java.util.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.system.AppUtils" %> +<%@ page import="org.openecomp.portalsdk.analytics.util.AppConstants" %> + + + +
    + + + +
    + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/tree/folderNav.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/tree/folderNav.jsp new file mode 100644 index 000000000..ca091bab5 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/tree/folderNav.jsp @@ -0,0 +1,483 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +<%@page import="org.openecomp.portalsdk.analytics.system.AppUtils" %> +<%@page import="org.openecomp.portalsdk.analytics.model.runtime.ReportRuntime"%> +<%@page import="org.openecomp.portalsdk.analytics.util.AppConstants"%> +<%@page import="org.openecomp.portalsdk.analytics.system.Globals"%> + +<% + boolean isFolderAllowed = false; + ReportRuntime rr = (ReportRuntime) request.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME); + boolean adminUser = AppUtils.isAdminUser(request); + if (Globals.isFolderTreeAllowed()) { + if(adminUser) { + isFolderAllowed = true; + } else if (!Globals.isFolderTreeAllowedOnlyForAdminUsers()) { + isFolderAllowed = true; + } else isFolderAllowed = false; + } + + + +%> + + + + + + + + + + + + + + + + + +
    + + + + + + + + + + + + + <% if(isFolderAllowed) { %> + + <% } %> + + + + <% if(isFolderAllowed) { %> +
    + Show Folder Tree +
    + <% } %> + + + +
    + + + + + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/tree/testTree.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/tree/testTree.jsp new file mode 100644 index 000000000..951bf379c --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/tree/testTree.jsp @@ -0,0 +1,248 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +<%@page import="org.openecomp.portalsdk.analytics.system.AppUtils" %> + + + + + + + + Folder tree with Drag and Drop capabilities + + + + + + + + + + + + + +
    + + + + + + + + + +
    + +
    +
    + + + + +
    + Hide Folder Tree +     + + Create Folder | + Delete Fodler | + Run Report | + Edit Report +
    +
    +
    +
    + + + + + + + +
    +
    + + + + +
    + <%=request.getAttribute("folderList")%> +
    +
    +
    + + + +
    + Collapse all | + Expand all +
    + + +
    + +
    +
    +
    +
    + +
    +
    +
    + + + +
    + + + + +
    + + + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_adhoc_schedule.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_adhoc_schedule.jsp new file mode 100644 index 000000000..76fe7a58c --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_adhoc_schedule.jsp @@ -0,0 +1,733 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +<%-- + Name: wizard_adhoc_schedule.jsp + Use : This JSP is used for accepting user parameters for scheduling the report. + + Change Log + ========== + + 28-Aug-2009 : Version 8.4 (Sundar); initFormFields function is removed as it is handled in back end. + 23-Jun-2009 : Version 8.4 (Sundar); + +
      +
    • Bug related to creating startDate variable (in Javascript) for the Validation purpose is fixed.
    • +
    + + +--%> + +<%@ page import="org.openecomp.portalsdk.analytics.xmlobj.DataColumnType" %> +<%@ page import="org.openecomp.portalsdk.analytics.util.AppConstants" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.definition.ReportDefinition" %> +<%@ page import="org.openecomp.portalsdk.analytics.system.AppUtils" %> +<%@ page import="org.openecomp.portalsdk.analytics.system.Globals" %> +<%@ page import="org.openecomp.portalsdk.analytics.controller.WizardSequence" %> +<%@ page import="java.util.Vector" %> +<%@ page import="java.util.List" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.DataCache" %> +<%@ page import="java.util.Iterator" %> +<%@ page import="org.openecomp.portalsdk.analytics.xmlobj.DataSourceType" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.definition.DBColumnInfo" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.definition.TableSource" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.base.IdNameValue" %> +<%@ page import="org.openecomp.portalsdk.analytics.xmlobj.SemaphoreType" %> +<%@ page import="org.openecomp.portalsdk.analytics.xmlobj.FormFieldType" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.definition.ReportSchedule" %> +<%@ page import="org.openecomp.portalsdk.analytics.util.Utils" %> + +<% + ReportSchedule reportSchedule = (ReportSchedule) request.getSession().getAttribute(AppConstants.SI_REPORT_SCHEDULE); + ReportDefinition rdefRecurrance = (ReportDefinition) request.getAttribute(AppConstants.SI_REPORT_DEFINITION); + session.setAttribute("login_id", AppUtils.getUserBackdoorLoginId(request)); + if(reportSchedule==null) reportSchedule = (ReportSchedule) request.getAttribute(AppConstants.SI_REPORT_SCHEDULE); + String remoteDbPrefix = (String) session.getAttribute("remoteDB"); + boolean isSQLAllowed = Globals.getAllowSQLBasedReports(); +%> +<%@page import="java.util.Calendar"%> +<%@page import="java.text.DateFormat"%> +<%@page import="java.text.SimpleDateFormat"%> +<%@page import="java.util.TimeZone"%> +<%@page import="java.util.Date"%> +<%@page import="org.openecomp.portalsdk.analytics.model.ReportLoader"%> + + + + + + + + + + + +
    + <% + Calendar startCalendarDate = Calendar.getInstance(); + startCalendarDate.add(Calendar.DAY_OF_MONTH, - 540); + Calendar endCalendarDate = Calendar.getInstance(); + endCalendarDate.add(Calendar.DAY_OF_MONTH, 540); + SimpleDateFormat dtf = new SimpleDateFormat("MM/dd/yyyy"); + SimpleDateFormat oracleDateFormat = new SimpleDateFormat("MM/dd/yyyy kk:mm:ss"); + Date sysdate = oracleDateFormat.parse(ReportLoader.getSystemDateTime()); + SimpleDateFormat dtimestamp = new SimpleDateFormat(Globals.getScheduleDatePattern()); + Calendar systemCalendar = Calendar.getInstance(); + systemCalendar.setTime(sysdate); + Date sysNext15date = oracleDateFormat.parse(ReportLoader.getNext15MinutesOfSystemDateTime()); + //dtimestamp = new SimpleDateFormat(Globals.getScheduleDatePattern()); + Calendar systemNext15Calendar = Calendar.getInstance(); + systemNext15Calendar.setTime(sysNext15date); + Date sysNext30date = oracleDateFormat.parse(ReportLoader.getNext30MinutesOfSystemDateTime()); + //dtimestamp = new SimpleDateFormat(Globals.getScheduleDatePattern()); + Calendar systemNext30Calendar = Calendar.getInstance(); + systemNext30Calendar.setTime(sysNext30date); + + System.out.println(" systemNext15Calendar " + systemNext15Calendar); + System.out.println(" systemNext30Calendar " + systemNext30Calendar); + + //dtimestamp.setTimeZone(TimeZone.getTimeZone(Globals.getTimeZone())); + +%> + + + + + + + + + + + + <%if(nvl(Globals.getScheduleHelpMessage()).length()>0) { %> + + + + <% } %> + + + + + + + + + + + + + + + + + + + + + + + + + + <% if(AppUtils.isAdminUser(request) || isSQLAllowed ) { %> + + + + + + + + + <% } %> + + + + + + + + + + + + + + + +<% List emailToUsers = reportSchedule.getEmailToUsers(); + for(int i=0; i + + + + +<% } // for + List emailToRoles = reportSchedule.getEmailToRoles(); + for(int i=0; i + + + + +<% } // for + + Vector remainingUsers = Utils.getUsersNotInList(emailToUsers,request); + Vector remainingRoles = Utils.getRolesNotInList(emailToRoles,request); + if((emailToUsers.size()+emailToRoles.size()==0)||(remainingUsers.size()>0)||(remainingRoles.size()>0)) { %> + + + +<% } // if +%> +
    + <%if(nvl(Globals.getScheduleHelpMessage()).trim().length()>0) { %> + + <% } %> + Please enter Time in <%= Globals.getTimeZone()%>. The Current System Time is <%=dtimestamp.format(sysdate)%> <%=Globals.getTimeZone()%> +
    +
    +

    Report Desc: + <%= Globals.getScheduleHelpMessage() %>

    +
    +
    Schedule Emails: + toolTipText="This is used for the enabling or disabling the scheduling feature for this report."/>Yes +   + toolTipText="This is used for the enabling or disabling the scheduling feature for this report."/>No + +
    Email Attachment: + + <%if(!rdefRecurrance.getReportType().equals(AppConstants.RT_HIVE)) {%> + toolTipText="Provides the capability to attach reports as PDF format to the email."/>PDF Attachment +    + toolTipText="Provides the capability to attach reports as Excel format to the email."/>Excel Attachment +    + <% } %> + toolTipText="Provides the capability to attach reports as Excel format to the email."/>Excelx Attachment +    + toolTipText="Provides the capability to attach reports as CSV format to the email."/>CSV Attachment + <%if(!rdefRecurrance.getReportType().equals(AppConstants.RT_HIVE)) {%> + <% if(nvl(Globals.getShellScriptDir()).length()>1) { %> + toolTipText="Provides the capability to send only links to the generated report in the email."/>Link to Generated report + <% } %> + <% } %> + + +
    Recurrence: + +
    First Schedule Date: + + + +       + + + + <%= Globals.getTimeZone()%> + + +
    Last Schedule Date: + + + +       + + + + <%= Globals.getTimeZone()%> + + +
    Use Condition: + > Send Emails Only When Condition Is Met +
    Condition SQL: + + +   +
    Max rows in attachment: + + +
    + Form Fields +

    <%= (i==0)?"Email To: ":" " %> + <%= userValue.getName() %> +       + +
    <%= (emailToUsers.size()==0&&i==0)?"Email To: ":" " %>Everyone With Role:  + <%= roleValue.getName() %> +       + +
    + + + + <% if ( nvl(Globals.getEncryptedSMTPServer(),"").length() > 0 ) { %> + + <% } %> + <% if (Globals.generateSchedReportsInFileSystem()) { %> + + <% } %> + +
    <%= (emailToUsers.size()+emailToRoles.size()==0)?"Email To: ":" " %> +<% if(remainingUsers.size()>0) { %> + +<% } else { %> + No user emails available +<% } %> +       +<% if(remainingRoles.size()>0) { %> + +<% } else { %> + No roles available +<% } %> + + Encrypt Attachment + toolTipText="Choose the encryption mode."/>Yes +    + toolTipText="Choose the encryption mode."/>No + Send as Attachment + toolTipText="Send As Attachment"/>Yes +    + toolTipText="Store it in file system."/>No +
    +
    + + +
    + + + + + + +<%! + private String nvl(String s) { return (s==null)?"":s; } + private String nvl(String s, String sDefault) { return nvl(s).equals("")?sDefault:s; } +%> diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_chart.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_chart.jsp new file mode 100644 index 000000000..959adc230 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_chart.jsp @@ -0,0 +1,1335 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +<%-- + Name: wizard_chart.jsp + Use : This JSP is invoked when chart tab is selected. This is used for creating chart configuration for the report. + + Change Log + ========== + + 12-Aug-2009 : Version 8.5 (Sundar); +
      +
    • For Line Chart Category can be configured. For this UI is added.
    • +
    • Line Chart can be displayed as 3D or 2D.
    • +
    + 29-Jun-2009 : Version 8.4 (Sundar); +
      +
    • For Bar Chart Last Series/Category can be configured as Line Chart or Bar Chart. For this UI is added.
    • +
    • UI options for compare to prev year chart has been added.
    • +
    + + 23-Jun-2009 : Version 8.4 (Sundar); +
      +
    • Hiding/ Unhiding parameters based on chart type is checked throughly and missing elements were added.
    • +
    • Table width is made 100% for special input parameters
    • +
    + + 22-Jun-2009 : Version 8.4 (Sundar); + +
      +
    • Calendar JS and CSS were added to this page as it is used in customizable input parameters for Time Difference Chart.
    • +
    • JS method and configurable input parameters were added for Multiple Pie Chart, Bar Chart 3D, Pareto, Time Difference Chart and Multiple + Time Series Chart.
    • +
    +--%> +<%@page import="org.openecomp.portalsdk.analytics.model.runtime.FormField"%> +<%@page import="org.openecomp.portalsdk.analytics.model.runtime.ReportFormFields"%> +<%@page import="org.openecomp.portalsdk.analytics.model.runtime.ReportRuntime"%> +<%@page import="org.openecomp.portalsdk.analytics.model.base.IdNameValue"%> +<%@page import="org.openecomp.portalsdk.analytics.model.DataCache"%> +<%@page import="org.openecomp.portalsdk.analytics.model.ReportHandler"%> +<%@page import="java.util.Vector"%> +<%@ page import="java.util.List" %> +<%@ page import="java.util.ArrayList" %> +<%@ page import="java.util.Iterator" %> +<%@ page import="org.openecomp.portalsdk.analytics.xmlobj.DataColumnType" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.definition.ReportDefinition" %> +<%@ page import="org.openecomp.portalsdk.analytics.controller.WizardSequence" %> +<%@ page import="org.openecomp.portalsdk.analytics.util.AppConstants" %> +<%@ page import="org.openecomp.portalsdk.analytics.system.Globals" %> +<%@ page import="org.openecomp.portalsdk.analytics.system.AppUtils" %> +<%@ page import="org.openecomp.portalsdk.analytics.xmlobj.Reports"%> + +<% + ReportDefinition rdef = (ReportDefinition) request.getAttribute(AppConstants.SI_REPORT_DEFINITION); + WizardSequence ws = rdef.getWizardSequence(); + boolean isCrossTab = rdef.getReportType().equals(AppConstants.RT_CROSSTAB); + boolean isSQLBased = rdef.getReportDefType().equals(AppConstants.RD_SQL_BASED) || rdef.getReportDefType().equals(AppConstants.RD_SQL_BASED_DATAMIN); + + String legendColId = null; + String valueColId = null; + + //String firstColId = null; + //String firstNumColId = null; + + List reportCols = rdef.getAllColumns(); + List chartValueCols = rdef.getChartValueColumnsList(AppConstants.CHART_ALL_COLUMNS, null); + + ArrayList unusedNumCols = new ArrayList(reportCols.size()); + int numColsCount = 0; + for(Iterator iter=reportCols.iterator(); iter.hasNext(); ) { + DataColumnType dct = (DataColumnType) iter.next(); + + if(nvl(dct.getColOnChart()).equals(AppConstants.GC_LEGEND)) + legendColId = dct.getColId(); + + if(isSQLBased||nvl(dct.getColType()).equals(AppConstants.CT_NUMBER)) { + numColsCount++; + if(nvl(dct.getColOnChart()).length()==0) //dct.getChartSeq()<0) + unusedNumCols.add(dct); + } // if + +/* if(dct.getChartSeq()>0) + valueColId = dct.getColId(); + + if(firstColId==null) + firstColId = dct.getColId(); + if(firstNumColId==null) + if(isSQLBased) + firstNumColId = dct.getColId(); + else + if(nvl(dct.getColType()).equals(AppConstants.CT_NUMBER)) + firstNumColId = dct.getColId();*/ + } // for + + String chartType = nvl(rdef.getChartType()); %> + + + + + + + + +
    + + + + + + +<% if(numColsCount==0) { %> + + + + + + + +<% } else { %> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +<% if(chartValueCols.size()==0) { %> + + + + + +<% } else { + int count = 1; + String colIdx = ""; + for(Iterator iterV=chartValueCols.iterator(); iterV.hasNext(); count++) { + colIdx = ""; + DataColumnType dctV = (DataColumnType) iterV.next(); + colIdx = dctV.getColId(); + int colAxisIdx = 0; + boolean newChart = false; + try { + colAxisIdx = Integer.parseInt(dctV.getColOnChart()); + } catch(Exception e) {} + newChart = (dctV.isCreateInNewChart()!=null)?dctV.isCreateInNewChart().booleanValue():false; + %> + + + + + + + + +<% } // for + } // else (chartValueCols.size()==0) + if(unusedNumCols.size()>0) { %> + + + + + + +<% } // if(unusedNumCols.size()==0) + if(chartValueCols.size()>1 || rdef.hasSeriesColumn()) { %> + + + + + + + + +<% } // if(chartValueCols.size()>1) +%> + + + + + + + +<%! + private String nvl(String s) { return (s==null)?"":s; } + private String nvl(String s, String sDefault) { return nvl(s).equals("")?sDefault:s; } +%> + + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_log.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_log.jsp new file mode 100644 index 000000000..2b1703852 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_log.jsp @@ -0,0 +1,109 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +<%@ page import="org.openecomp.portalsdk.analytics.xmlobj.DataColumnType" %> +<%@ page import="org.openecomp.portalsdk.analytics.util.AppConstants" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.definition.ReportDefinition" %> +<%@ page import="org.openecomp.portalsdk.analytics.system.AppUtils" %> +<%@ page import="org.openecomp.portalsdk.analytics.controller.WizardSequence" %> +<%@ page import="java.util.List" %> +<%@ page import="java.util.Iterator" %> +<%@ page import="org.openecomp.portalsdk.analytics.system.Globals" %> +<%@ page import="org.openecomp.portalsdk.analytics.util.Utils" %> +<%@ page import="java.util.Vector" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.ReportLoader" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.base.IdNameValue" %> +<%@ page import="org.openecomp.portalsdk.analytics.xmlobj.FormFieldType" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.base.ReportWrapper" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.DataCache" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.runtime.FormField" %> +<%@ page import="org.openecomp.portalsdk.analytics.util.Log" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.definition.ReportLogEntry" %> +<% + ReportDefinition rdef = (ReportDefinition) request.getAttribute(AppConstants.SI_REPORT_DEFINITION); + WizardSequence ws = rdef.getWizardSequence(); + String curSubStep = ws.getCurrentSubStep(); + String reportID = rdef.getReportID(); + boolean isCrossTab = rdef.getReportType().equals(AppConstants.RT_CROSSTAB); + boolean isSQLBased = rdef.getReportDefType().equals(AppConstants.RD_SQL_BASED); + +%> + +<% String errorMsg = null; + Vector reportLogEntries = null; + try { + reportLogEntries = ReportLoader.loadReportLogEntries(reportID); + } catch(Exception e) { + Log.write("ERROR [wizard_log.jsp] Unable to load report log entries. Exception: "+e.getMessage()); + errorMsg = "ERROR: Unable to load report log entries from the database "; + } %> + +
    Step <%= ws.getCurrentStepIndex() %> of <%= ws.getStepCount() %> - Report <%= ws.getCurrentStep() %>
    No numeric columns found - chart not available
    + + + + + + +
    Chart Type: + + > +  Do NOT allow user to change chart type at runtime +
    +
    Chart Width (px): + " size="10" maxlength="4">
    Chart Height (px): + " size="10" maxlength="4">
    Domain Axis: +
    Category: +
    last Category display As Line Chart + + > +
    last Category display As Bar Chart + + > +
    Multi Series + 0? (AppUtils.getRequestNvlValue(request, "multiSeries").equals("Y")? " checked ":""): (rdef.isMultiSeries() ? " checked ":" checked ")) %>>Yes + 0? (AppUtils.getRequestNvlValue(request, "multiSeries").equals("N")? " checked ":""): (!rdef.isMultiSeries() ? " checked":"")) %>>No +
    Range Axis: + + <% String sValue = ""; %> + +
    Range Axis <%= count %>: + + <% if(count>1) { %> +   + + <% } %> +   + + <% + String chartGroupOrg = dctV.getChartGroup(); + String yAxisGroup = dctV.getYAxis(); + String chartGroup = (chartGroupOrg!=null && chartGroupOrg.length()>0 && chartGroupOrg.indexOf("|")!= -1)?chartGroupOrg.substring(0,chartGroupOrg.lastIndexOf("|")):""; + String yAxis = (yAxisGroup!=null && yAxisGroup.length()>0 && yAxisGroup.indexOf("|")!= -1)?yAxisGroup.substring(0,yAxisGroup.lastIndexOf("|")):""; + %> +
    + Chart Title:"/> + YAxis:"/> +
    + +
    + <% String sValue = nvl(dctV.getChartColor()); %> + + + <% if(count>1) { %> +
    + > +  Create in New Chart +
    + 0)?" checked":"" %>> +  Use secondary axis (Line chart only) + <% } %> +  
    Add Values Column: + + + <% String sValue = ""; %> + + + +  Use secondary axis (Line chart only) +
    Primary Axis Label: + +  (Multi-series Chart Only)
    Secondary Axis Label: + +  (Multi-series Chart Only)
      + Note: Some chart types (like Pie) will only display Series 1 Values.
    + + + + + + + + + + + + + + + + + + +
    + + + + + + + + + + + +<% int iCount = 0; + if(reportLogEntries!=null) + for(Iterator iter=reportLogEntries.iterator(); iter.hasNext(); iCount++) { + ReportLogEntry logEntry = (ReportLogEntry) iter.next(); %> + > + + + + + + + + +<% } // for + if(errorMsg!=null) { %> + + + +<% } else if(iCount==0) { %> + + + +<% } else { %> + + + +<% } // if +%> +
    Step <%= ws.getCurrentStepIndex() %> of <%= ws.getStepCount() %> - Report <%= ws.getCurrentStep() %>
      No  Date/TimeUser NameActionExecution TimeRun
    <%= iCount+1 %><%= logEntry.getLogTime() %><%= logEntry.getUserName() %><%= logEntry.getAction() %><%= logEntry.getTimeTaken() %><%= logEntry.getRunIcon() %>
    <%= errorMsg %>
    No log entries found
    + +
    +
    + + + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_map.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_map.jsp new file mode 100644 index 000000000..50fe1da68 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_map.jsp @@ -0,0 +1,424 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +<%@ page import="org.openecomp.portalsdk.analytics.xmlobj.DataColumnType" %> +<%@ page import="org.openecomp.portalsdk.analytics.util.AppConstants" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.definition.ReportDefinition" %> +<%@ page import="org.openecomp.portalsdk.analytics.system.AppUtils" %> +<%@ page import="org.openecomp.portalsdk.analytics.controller.WizardSequence" %> +<%@ page import="java.util.List" %> +<%@ page import="java.util.Iterator" %> +<%@page import="org.openecomp.portalsdk.analytics.xmlobj.ReportMap"%> +<% + ReportDefinition rdef = (ReportDefinition) request.getAttribute(AppConstants.SI_REPORT_DEFINITION); + WizardSequence ws = rdef.getWizardSequence(); + boolean isCrossTab = rdef.getReportType().equals(AppConstants.RT_CROSSTAB); + boolean isSQLBased = rdef.getReportDefType().equals(AppConstants.RD_SQL_BASED); + ReportMap repMap = rdef.getReportMap(); + String addressColumn = ""; + String latColumn = ""; + String longColumn = ""; + String legendColumn = ""; + String colorColumn = ""; + String dataColumn = ""; + String isMapAllowed = ""; + String addAddress = "N"; + String useDefaultSize = ""; + String width = ""; + String height = ""; + + int reportMapSize = 0; + if (repMap != null){ + if (repMap.getAddressColumn() != null) + addressColumn = repMap.getAddressColumn(); + + if (repMap.getDataColumn() != null) + dataColumn = repMap.getDataColumn(); + if (repMap.getIsMapAllowedYN() != null) + isMapAllowed = repMap.getIsMapAllowedYN(); + if (repMap.getAddAddressInDataYN() != null) + addAddress = repMap.getAddAddressInDataYN(); + if (repMap.getLatColumn() != null) + latColumn = repMap.getLatColumn(); + if (repMap.getLongColumn() != null) + longColumn = repMap.getLongColumn(); + if (repMap.getColorColumn() != null) + colorColumn = repMap.getColorColumn(); + if (repMap.getLegendColumn() != null) + legendColumn = repMap.getLegendColumn(); + if (repMap.getUseDefaultSize() != null) + useDefaultSize = repMap.getUseDefaultSize(); + if (repMap.getHeight() != null) + height = repMap.getHeight(); + if (repMap.getWidth() != null) + width = repMap.getWidth(); + + reportMapSize = repMap.getMarkers().size(); + } + +%> +<%@page import="org.openecomp.portalsdk.analytics.xmlobj.Marker"%> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +<% for (int i = 1; repMap != null && i < repMap.getMarkers().size(); i ++){ + Marker marker = (Marker) repMap.getMarkers().get(i); +%> + + + + + + + + + + <%}%> + + + +
    Step <%= ws.getCurrentStepIndex() %> of <%= ws.getStepCount() %> - Report <%= ws.getCurrentStep() %>
    Map Enabled ? + checked <%} %>/> +
    Default Size ? + checked <%} %>/> + Height + + + + Width + +  
    Lat Column + + + + Long Column + + + + Color Column + + + + Legend Column + + + +
      + +
    Data Header + + Display Column + + + + + Remove +  
    +
    + + + + + + +<%! + private String nvl(String s) { return (s==null)?"":s; } + private String nvl(String s, String sDefault) { return nvl(s).equals("")?sDefault:s; } +%> diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_run.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_run.jsp new file mode 100644 index 000000000..688e7ff74 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_run.jsp @@ -0,0 +1,74 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +<%@ page import="org.openecomp.portalsdk.analytics.xmlobj.DataColumnType" %> +<%@ page import="org.openecomp.portalsdk.analytics.util.AppConstants" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.definition.ReportDefinition" %> +<%@ page import="org.openecomp.portalsdk.analytics.system.AppUtils" %> +<%@ page import="org.openecomp.portalsdk.analytics.controller.WizardSequence" %> +<%@ page import="java.util.List" %> +<%@ page import="java.util.Iterator" %> +<% + ReportDefinition rdef = (ReportDefinition) request.getAttribute(AppConstants.SI_REPORT_DEFINITION); + WizardSequence ws = rdef.getWizardSequence(); +%> + + + + + + + + + +
    Step <%= ws.getCurrentStepIndex() %> of <%= ws.getStepCount() %> - Report <%= ws.getCurrentStep() %>
    + + + + + + + + + + +
    + + SQL Click here to view the generated SQL  + +
    + + Report definition successfully completed.
    +
    + + + Run +
    +
     
    +
    +
    + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_schedule.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_schedule.jsp new file mode 100644 index 000000000..b8d1ad1ca --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_schedule.jsp @@ -0,0 +1,376 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +<%@ page import="org.openecomp.portalsdk.analytics.xmlobj.DataColumnType" %> +<%@ page import="org.openecomp.portalsdk.analytics.util.AppConstants" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.definition.ReportDefinition" %> +<%@ page import="org.openecomp.portalsdk.analytics.system.AppUtils" %> +<%@ page import="org.openecomp.portalsdk.analytics.system.Globals" %> +<%@ page import="org.openecomp.portalsdk.analytics.controller.WizardSequence" %> +<%@ page import="java.util.Vector" %> +<%@ page import="java.util.List" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.DataCache" %> +<%@ page import="java.util.Iterator" %> +<%@ page import="org.openecomp.portalsdk.analytics.xmlobj.DataSourceType" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.definition.DBColumnInfo" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.definition.TableSource" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.base.IdNameValue" %> +<%@ page import="org.openecomp.portalsdk.analytics.xmlobj.SemaphoreType" %> +<%@ page import="org.openecomp.portalsdk.analytics.xmlobj.FormFieldType" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.definition.ReportSchedule" %> +<%@ page import="org.openecomp.portalsdk.analytics.util.Utils" %> + +<% + ReportDefinition rdef = (ReportDefinition) request.getAttribute(AppConstants.SI_REPORT_DEFINITION); + WizardSequence ws = rdef.getWizardSequence(); + ReportSchedule reportSchedule = rdef.getReportSchedule(); + String remoteDbPrefix = (String) session.getAttribute("remoteDB"); + boolean isSQLAllowed = Globals.getAllowSQLBasedReports(); + +%> +<%@page import="java.util.Calendar"%> +<%@page import="java.text.DateFormat"%> +<%@page import="java.text.SimpleDateFormat"%> +<%@page import="java.util.TimeZone"%> +<%@page import="java.util.Date"%> +<%@page import="org.openecomp.portalsdk.analytics.model.ReportLoader"%> + + + + + + + <% + Calendar startCalendarDate = Calendar.getInstance(); + startCalendarDate.add(Calendar.DAY_OF_MONTH, - 540); + Calendar endCalendarDate = Calendar.getInstance(); + endCalendarDate.add(Calendar.DAY_OF_MONTH, 540); + SimpleDateFormat dtf = new SimpleDateFormat("MM/dd/yyyy"); + SimpleDateFormat oracleDateFormat = new SimpleDateFormat("MM/dd/yyyy kk:mm:ss"); + Date sysdate = oracleDateFormat.parse(ReportLoader.getSystemDateTime()); + SimpleDateFormat dtimestamp = new SimpleDateFormat(Globals.getScheduleDatePattern()); + //dtimestamp.setTimeZone(TimeZone.getTimeZone(Globals.getTimeZone())); + + + + + %> + + + + <% if(request.getAttribute("schedule_only")!=null) { %> + + + + <% } %> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + <% if(AppUtils.isAdminUser(request) || isSQLAllowed ) { %> + + + + + + + + + <% } %> + + + + + + + + + +<% List emailToUsers = reportSchedule.getEmailToUsers(); + for(int i=0; i + + + + +<% } // for + List emailToRoles = reportSchedule.getEmailToRoles(); + for(int i=0; i + + + + +<% } // for + + Vector remainingUsers = Utils.getUsersNotInList(emailToUsers,request); + Vector remainingRoles = Utils.getRolesNotInList(emailToRoles,request); + if((emailToUsers.size()+emailToRoles.size()==0)||(remainingUsers.size()>0)||(remainingRoles.size()>0)) { %> + + + + +<% } // if +%> +
    Step <%= ws.getCurrentStepIndex() %> of <%= ws.getStepCount() %> - Report <%= ws.getCurrentStep() %>
    Please enter Time in <%= Globals.getTimeZone()%>. The Current System Time is <%=dtimestamp.format(sysdate)%> <%=Globals.getTimeZone()%>
    +
    +

    Quick Help: +

    +
    +
    Schedule Emails: + />Yes +   + />No +
    Email Attachment: + + />PDF Attachment +    + />Excel Attachment + + +
    Recurrence: +
    Start Date: + + + +       + + + + +
    End Date: + + + +
    Use Condition: + > Send Emails Only When Condition Is Met +
    Condition SQL:SELECT 1 FROM DUAL WHERE EXISTS (
    + + ) +      + +   +
    Max rows in attachment: + +
    <%= (i==0)?"Email To: ":" " %> + <%= userValue.getName() %> +       + +
    <%= (emailToUsers.size()==0&&i==0)?"Email To: ":" " %>Everyone With Role:  + <%= roleValue.getName() %> +       + +
    <%= (emailToUsers.size()+emailToRoles.size()==0)?"Email To: ":" " %> +<% if(remainingUsers.size()>0) { %> + +<% } else { %> + No user emails available +<% } %> +       +<% if(remainingRoles.size()>0) { %> + +<% } else { %> + No roles available +<% } %> +
    +
    + + + +<%! + private String nvl(String s) { return (s==null)?"":s; } + private String nvl(String s, String sDefault) { return nvl(s).equals("")?sDefault:s; } +%> diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_schedule_formfield_include.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_schedule_formfield_include.jsp new file mode 100644 index 000000000..206e23de1 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_schedule_formfield_include.jsp @@ -0,0 +1,754 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +<%-- + Name: wizard_schedule_formfield_include.jsp + Use : Shows formfield of the report in the schedule page. + + Change Log + ========== + + 28-Aug-2009 : Version 8.5.1 (Sundar); Checkbox and Radio button are also handled. + 18-Aug-2009 : Version 8.5.1 (Sundar); + + a) ajax.js is loaded in startup for AJAX functionality. + b) showArgPopupNew is modified as per report_form.jsp + c) Ajax function is added very similiar to report_form.jsp + d) "auto" bug is resolved. + +14-Jul-2009 : Version 8.4 (Sundar); + +
      +
    • Shows the form field of the first Dashboard report in schedule page if the report is dashboard.
    • +
    +--%> +<%@ page import="java.io.*" %> +<%@ page import="java.util.*" %> +<%@ page import="java.text.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.runtime.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.system.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.util.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.definition.ReportDefinition" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.ReportHandler" %> +<%@ page import="org.openecomp.portalsdk.analytics.xmlobj.JavascriptItemType"%> +<%@ page import="java.util.regex.*"%> +<%@ page import="javax.servlet.http.*"%> +<%@ page import="org.openecomp.portalsdk.analytics.model.definition.ReportSchedule" %> + + +<% + ReportDefinition rdef = (ReportDefinition) request.getAttribute(AppConstants.SI_REPORT_DEFINITION); + ReportHandler rh = new ReportHandler(); + ReportRuntime rr = rh.loadReportRuntime(request, rdef.getReportID()); + request.getSession().setAttribute(AppConstants.SI_REPORT_RUNTIME, rr); + boolean isDashboard = rr.isDashboardType(); + ReportFormFields rff = rr.getReportFormFields(); + ReportFormFields rff1 = (ReportFormFields) rff.clone(); + ReportFormFields rff2 = (ReportFormFields) rff.clone(); + ReportFormFields rff5 = (ReportFormFields) rff.clone(); + boolean isFirstTime = nvl(request.getParameter("refresh")).toUpperCase().startsWith("Y"); + ReportSchedule reportSchedule = (ReportSchedule) request.getSession().getAttribute(AppConstants.SI_REPORT_SCHEDULE); + + int dashboardFlag = 0; + ReportRuntime rr1 = null; + java.text.SimpleDateFormat sdf = null; + +%> + + + +<%--=(rr.getJavascriptElement()!=null && rr.getJavascriptElement().length()>0)?rr.getJavascriptElement().replaceAll("formd","forma"):""--%> + + <% + if(rr.getReportType().equals(AppConstants.RT_DASHBOARD)) { + dashboardFlag = 1; + String strHTML = rr.getDashboardLayoutHTML(); //getdashboardLayoutHTML(); + String rep_id = parseAndGetFirstReportID(strHTML); + ReportHandler rh1 = new ReportHandler(); + rr1 = null; + int requestFlag = 1; + try { + rr1 = rh1.loadReportRuntime(request, rep_id, true, requestFlag); + } catch(Exception e) { + } + rff = rr1.getReportFormFields(); + } + %> + <%if((dashboardFlag == 0 && rr.needFormInput()) || (dashboardFlag == 1 && rr1.needFormInput())) { %> + + + + Please input values into the Form Fields for email attachment. Note those fields user must provide value can not leave as blank. + + + <% + int colidx = 0; + java.util.HashMap paramsMap = Globals.getRequestParamtersMap(request, false); + java.util.HashMap getScheduleMap = getFormFieldsHashMap (request, reportSchedule.getFormFields()); + java.util.HashMap paramsScheduleMap = Globals.getRequestParametersMap(request, getScheduleMap); + for (int i = 0; i < rff.size(); i ++){ + FormField ff = (FormField) rff.get(i); + ff.setDbInfo(rr.getDbInfo()); + ff.setUserId(AppUtils.getUserID(request)); + if(ff.getFieldType().equals(FormField.FFT_HIDDEN)) { + %> + <% + if(nvl(reportSchedule.getFormFields()).length() <= 0) + out.println(ff.getHtml(rr.getParamValue(ff.getFieldName()), paramsMap, rr, true)); + else + out.println(ff.getHtml(getParameterString(request, ff.getFieldName(), getScheduleMap), paramsScheduleMap, rr, true).replaceAll("formd","forma")); + + + %> + <% } + if(!ff.getFieldType().equals(FormField.FFT_HIDDEN) && ff.isVisible()) { + + %> + <%if (colidx == 0){%><%}%> + + + + <%colidx++;%> + <%if (colidx == rr.getNumFormColsAsInt()){%><%colidx=0;}%> + <% } + } //for %> +
    + + <%if (!ff.getFieldType().equals(FormField.FFT_BLANK)){%> + <%= ff.getDisplayNameHtml() %>: + <%}%> + + + <%-- ff.getHtml(rr.getParamValue(ff.getFieldName()), paramsMap,rr, true).replaceAll("formd","forma") --%> + <% + if(nvl(reportSchedule.getFormFields()).length() <= 0) + out.println(ff.getHtml(rr.getParamValue(ff.getFieldName()), paramsMap, rr, true).replaceAll("formd","forma")); + else + out.println(ff.getHtml(getParameterString(request, ff.getFieldName(), getScheduleMap), paramsScheduleMap, rr, true).replaceAll("formd","forma")); + %> +
    + + +<% } //if(rr.needFormInput()) %> + + + + +<% /* if(request.getAttribute(AppConstants.RI_REPORT_DATA) == null){ */ %> + + +<%! private String nvl(String s) { return (s==null)?"":s; } + private String nvl(String s, String sDefault) { return nvl(s).equals("")?sDefault:s; } + private String getCallableJavascriptForSubmit(ReportRuntime rr) { + JavascriptItemType javascriptItemType = null; + StringBuffer callJavascriptText = new StringBuffer(""); + if(rr.getJavascriptList()!=null) { + for (Iterator iter = rr.getJavascriptList().getJavascriptItem().iterator(); iter.hasNext();) { + javascriptItemType = (JavascriptItemType)iter.next(); + if(javascriptItemType.getFieldId().equals("os1")) { + callJavascriptText.append(" "+javascriptItemType.getCallText()); + break; + } + } + } + return callJavascriptText.toString(); + } + + private HashMap getFormFieldsHashMap (HttpServletRequest request, String formFieldsString) { + String splitName[] = null; + ArrayList keyValue = new ArrayList(); + HashMap keyValueMap = new HashMap(); + String newValue = ""; + //System.out.println("Request Str "+ formFieldsString); + StringTokenizer st = null; + StringTokenizer st2 = null; + String key1 = ""; + String value = ""; + + if(formFieldsString.length() > 0) { + st = new StringTokenizer(formFieldsString, "&"); + while (st.hasMoreTokens()) { + keyValue.add(st.nextToken()); + } + if(keyValue.size() > 0) { + + for (int num = 0; num < keyValue.size(); num++) { + st2 = new StringTokenizer((String) keyValue.get(num), "="); + while(st2.hasMoreTokens()) { + key1 = ""; value = ""; + key1 = st2.nextToken(); + key1 = Utils.replaceInString(key1, "_auto", ""); + try { + value = st2.nextToken(); + }catch (NoSuchElementException ex) { value = "";} + if(!keyValueMap.containsKey(key1)) + keyValueMap.put(key1,value); + else { + String value1 = (String) keyValueMap.get(key1); + value = value+"|"+value1; + keyValueMap.put(key1,value); + } + } + } + + } + } + return keyValueMap; + } + + private String getParameterString (HttpServletRequest request, String key, HashMap keyValueMap) { + String newValue = ""; + if(keyValueMap.containsKey(key)) { + //System.out.println("VALUE IN MAP IS " +key+ " "+ (String) keyValueMap.get(key)); + newValue = XSSFilter.filterRequestOnlyScript((String) keyValueMap.get(key)); + if(nvl(newValue).length()<=0) { + newValue = XSSFilter.filterRequestOnlyScript((String) keyValueMap.get(key+"_auto")); + } + } + return newValue; + } + private String parseAndGetFirstReportID(String strHTML) { + String sourcestring = strHTML; + //System.out.println("String HTML1 " + strHTML); + Pattern re = Pattern.compile("\\[(.*?)\\]"); //\\[(.*?)\\] + Matcher m = re.matcher(sourcestring); + int mIdx = 0; + while (m.find()){ + for( int groupIdx = 0; groupIdx < m.groupCount(); groupIdx++ ){ + String str = m.group(groupIdx); + //System.out.println("REP ID1 " + str.substring(str.indexOf("#")+1, str.length()-1)) ; + return str.substring(str.indexOf("#")+1, str.length()-1); + } + mIdx++; + + }return ""; + } +%> diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_schedule_multiple.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_schedule_multiple.jsp new file mode 100644 index 000000000..70c9812a8 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_schedule_multiple.jsp @@ -0,0 +1,157 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +<%@ page import="java.util.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.xmlobj.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.base.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.definition.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.runtime.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.controller.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.system.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.util.*" %> + +<%@ page errorPage="error_page.jsp" %> +<%! +class ValueComparator implements Comparator { + public int compare(Object o1, Object o2) { + Map.Entry e1 = (Map.Entry) o1; + Map.Entry e2 = (Map.Entry) o2; + Comparable c1 = (Comparable)e1.getValue(); + Comparable c2 = (Comparable)e2.getValue(); + return c1.compareTo(c2); + } +} +%> +<% +HashMap hashMap = ReportLoader.loadReportsToSchedule(request); +ReportDefinition rdef = (ReportDefinition) request.getAttribute(AppConstants.SI_REPORT_DEFINITION); +if(rdef ==null) rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION); +Set mapSet = hashMap.entrySet(); +List entrylist = new ArrayList(mapSet); +Collections.sort(entrylist, new ValueComparator()); +Map.Entry me; +session.removeAttribute(AppConstants.SI_REPORT_SCHEDULE); +session.removeAttribute(AppConstants.SI_REPORT_DEFINITION); +ReportSchedule reportSchedule = (ReportSchedule) session.getAttribute(AppConstants.SI_REPORT_SCHEDULE); +%> + + + + + + +


    +<% if (rdef == null || request.getSession().getAttribute(AppConstants.SI_REPORT_SCHEDULE) == null) {%> + +
    + + + + + + + + +
    + + + + + + <% if(request.getAttribute("message")!=null) { %> + + + + <% } %> +
    <%= "Scheduling Report" %>
    <%= (String) request.getAttribute("message") %>
    +
    Reports: + <% if (rdef !=null && request.getSession().getAttribute(AppConstants.SI_REPORT_SCHEDULE) != null ) {%> + <%= rdef.getReportName()%> + <% } else { %> + + <% } %> + +
    +
    +<% } %> +<% if(reportSchedule!=null) { %> + +<% } %> + + + + + +<%----%> + +<%! private String HTMLEncode(String value) { + StringBuffer sb = new StringBuffer(value); + + for(int i=0; i') + sb.replace(i, i+1, ">"); + else if(sb.charAt(i)=='"') + sb.replace(i, i+1, """); + + return sb.toString(); + } // HTMLEncode + + private String clearSpaces(String value) { + StringBuffer sb = new StringBuffer(value); + + for(int i=0; i + + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_schedule_only.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_schedule_only.jsp new file mode 100644 index 000000000..ad3c612ee --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_schedule_only.jsp @@ -0,0 +1,172 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +<%@ page import="java.util.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.xmlobj.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.base.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.definition.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.runtime.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.controller.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.system.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.util.*" %> + +<%@ page errorPage="error_page.jsp" %> + + + +<% ReportDefinition rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION); + + String reportID = rdef.getReportID(); + + + + String dbInfo = null; + dbInfo = rdef.getDBInfo(); + int sessionflag = 0; + if(dbInfo == null || dbInfo.length() == 0) { + dbInfo = (String) session.getAttribute("remoteDB"); + sessionflag = 1; + } + session.setAttribute("remoteDB", dbInfo); + if((dbInfo == null) && (request.getParameter("dataSource")!=null)) + session.setAttribute("remoteDB", request.getParameter("dataSource")); + + StringBuffer title = new StringBuffer(""); + title.append(Globals.getBaseTitle()+" > "+(reportID.equals("-1")?"Create Report":"Schedule Report")); + title.append(" > "+rdef.getReportName()); + + boolean isCrossTab = rdef.getReportType().equals(AppConstants.RT_CROSSTAB); + boolean isSQLBased = rdef.getReportDefType().equals(AppConstants.RD_SQL_BASED); +%> + +<% + request.setAttribute(AppConstants.SI_REPORT_DEFINITION,rdef); +%> + + + + + + + + + + + + +
    + +
    +
    +
    +
    + + + + + + + + + + + +
    + + + + + <% if(request.getAttribute("message")!=null) { %> + + + + <% } %> +
    <%= title.toString() %>
    <%= (String) request.getAttribute("message") %>
    +
    + +
    + + + + + +
    +   + + + <%----%> + +
    +
    +
    + + +
    +
    +<%----%> + +<%! private String HTMLEncode(String value) { + StringBuffer sb = new StringBuffer(value); + + for(int i=0; i') + sb.replace(i, i+1, ">"); + else if(sb.charAt(i)=='"') + sb.replace(i, i+1, """); + + return sb.toString(); + } // HTMLEncode + + private String clearSpaces(String value) { + StringBuffer sb = new StringBuffer(value); + + for(int i=0; i + + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_schedule_only_from_search.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_schedule_only_from_search.jsp new file mode 100644 index 000000000..af951cc23 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_schedule_only_from_search.jsp @@ -0,0 +1,173 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +<%@ page import="java.util.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.xmlobj.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.base.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.definition.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.runtime.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.controller.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.system.*" %> +<%@ page import="org.openecomp.portalsdk.analytics.util.*" %> + +<%@ page errorPage="error_page.jsp" %> + + + +<% ReportDefinition rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION); + + String reportID = rdef.getReportID(); + + + + String dbInfo = null; + dbInfo = rdef.getDBInfo(); + int sessionflag = 0; + if(dbInfo == null || dbInfo.length() == 0) { + dbInfo = (String) session.getAttribute("remoteDB"); + sessionflag = 1; + } + session.setAttribute("remoteDB", dbInfo); + if((dbInfo == null) && (request.getParameter("dataSource")!=null)) + session.setAttribute("remoteDB", request.getParameter("dataSource")); + + StringBuffer title = new StringBuffer(""); + title.append(Globals.getBaseTitle()+" > "+(reportID.equals("-1")?"Create Report":"Schedule Report")); + title.append(" > "+rdef.getReportName()); + + boolean isCrossTab = rdef.getReportType().equals(AppConstants.RT_CROSSTAB); + boolean isSQLBased = rdef.getReportDefType().equals(AppConstants.RD_SQL_BASED); +%> + +<% + request.setAttribute(AppConstants.SI_REPORT_DEFINITION,rdef); +%> + + + + + + + + + + + + +
    + +
    +
    +
    +
    + + + + + + + + + + + +
    + + <% if(request.getAttribute("message")!=null) { %> + + + + <% } %> + + + + +
    <%= (String) request.getAttribute("message") %>
    <%= title.toString() %>
    +
    + +
    + + + + + +
    +   + + + <%----%> + +
    +
    +
    + + +
    +
    +<%----%> + +<%! private String HTMLEncode(String value) { + StringBuffer sb = new StringBuffer(value); + + for(int i=0; i') + sb.replace(i, i+1, ">"); + else if(sb.charAt(i)=='"') + sb.replace(i, i+1, """); + + return sb.toString(); + } // HTMLEncode + + private String clearSpaces(String value) { + StringBuffer sb = new StringBuffer(value); + + for(int i=0; i + + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_sorting_edit.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_sorting_edit.jsp new file mode 100644 index 000000000..18c450ba9 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_sorting_edit.jsp @@ -0,0 +1,86 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +<%@ page import="org.openecomp.portalsdk.analytics.xmlobj.DataColumnType" %> +<%@ page import="org.openecomp.portalsdk.analytics.util.AppConstants" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.definition.ReportDefinition" %> +<%@ page import="org.openecomp.portalsdk.analytics.system.AppUtils" %> +<%@ page import="org.openecomp.portalsdk.analytics.controller.WizardSequence" %> +<%@ page import="java.util.List" %> +<%@ page import="java.util.Iterator" %> +<% + ReportDefinition rdef = (ReportDefinition) request.getAttribute(AppConstants.SI_REPORT_DEFINITION); + WizardSequence ws = rdef.getWizardSequence(); + String curSubStep = ws.getCurrentSubStep(); + boolean isEdit = curSubStep.equals(AppConstants.WSS_EDIT); + DataColumnType currColumn = null; + if(isEdit) + currColumn = rdef.getColumnById(AppUtils.getRequestNvlValue(request, AppConstants.RI_DETAIL_ID)); %> + + + + + + + + + + + + + +
    Step <%= ws.getCurrentStepIndex() %> of <%= ws.getStepCount() %> - Report <%= ws.getCurrentStep() %><%= curSubStep.equals(AppConstants.WSS_EDIT)?"Edit Sorting":(curSubStep.equals(AppConstants.WSS_ADD)?"Add Sorting":"") %>
    + Sort By Column: + + <% if(isEdit) { %> + <%= currColumn.getDisplayName() %> + <% } else { %> + + <% } // else + %> +
    Sort Type: + +
    +
    + + + +<%! + private String nvl(String s) { return (s==null)?"":s; } + private String nvl(String s, String sDefault) { return nvl(s).equals("")?sDefault:s; } +%> diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_sorting_list.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_sorting_list.jsp new file mode 100644 index 000000000..63bf9cd32 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_sorting_list.jsp @@ -0,0 +1,116 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +<%@ page import="org.openecomp.portalsdk.analytics.xmlobj.DataColumnType" %> +<%@ page import="org.openecomp.portalsdk.analytics.util.AppConstants" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.definition.ReportDefinition" %> +<%@ page import="org.openecomp.portalsdk.analytics.system.AppUtils" %> +<%@ page import="org.openecomp.portalsdk.analytics.controller.WizardSequence" %> +<%@ page import="java.util.List" %> +<%@ page import="java.util.Iterator" %> +<%@ page import="org.openecomp.portalsdk.analytics.system.Globals" %> +<%@ page import="org.openecomp.portalsdk.analytics.util.Utils" %> +<%@ page import="java.util.Vector" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.ReportLoader" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.base.IdNameValue" %> +<%@ page import="org.openecomp.portalsdk.analytics.xmlobj.FormFieldType" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.base.ReportWrapper" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.DataCache" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.runtime.FormField" %> +<%@ page import="java.util.Collections" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.base.OrderSeqComparator" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.base.OrderBySeqComparator" %> + +<% + ReportDefinition rdef = (ReportDefinition) request.getAttribute(AppConstants.SI_REPORT_DEFINITION); + WizardSequence ws = rdef.getWizardSequence(); + String curSubStep = ws.getCurrentSubStep(); + String reportID = rdef.getReportID(); + boolean isCrossTab = rdef.getReportType().equals(AppConstants.RT_CROSSTAB); + boolean isSQLBased = rdef.getReportDefType().equals(AppConstants.RD_SQL_BASED); + List reportCols = rdef.getAllColumns(); + Collections.sort(reportCols, new OrderSeqComparator()); + int numSortCols = rdef.getNumSortColumns(); %> + + + + + + + + + + + +<% int iCount = 0; + Collections.sort(reportCols,new OrderBySeqComparator()); + for(Iterator iter=reportCols.iterator(); iter.hasNext(); ) { + DataColumnType dct = (DataColumnType) iter.next(); + if(dct.getOrderBySeq()>0) { %> + > + + + + + + + +<% + iCount++; + } // if + } // for + Collections.sort(reportCols, new OrderSeqComparator()); +%> +<% if(numSortCols==0) { %> + + + +<% } %> +
    Step <%= ws.getCurrentStepIndex() %> of <%= ws.getStepCount() %> - Report <%= ws.getCurrentStep() %>
    Sort OrderSort By ColumnSort TypeRe-order + <% if(numSortCols + + +
    + <% } %> + + <% if(numSortCols +
    + <% } %> +
    <%= iCount+1 %><%= dct.getDisplayName() %><%= dct.getOrderByAscDesc().equals(AppConstants.SO_ASC)?"Ascending":"Descending" %> +<% if(iCount==0) { %> + +<% } else { %> + +<% } %> +<% if(iCount==numSortCols-1) { %> + +<% } else { %> + +<% } %> +
    No sorting defined
    +
    + + + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_sorting_order_all.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_sorting_order_all.jsp new file mode 100644 index 000000000..9e04f2b84 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_sorting_order_all.jsp @@ -0,0 +1,112 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +<%@ page import="org.openecomp.portalsdk.analytics.xmlobj.DataColumnType" %> +<%@ page import="org.openecomp.portalsdk.analytics.util.AppConstants" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.definition.ReportDefinition" %> +<%@ page import="org.openecomp.portalsdk.analytics.system.AppUtils" %> +<%@ page import="org.openecomp.portalsdk.analytics.controller.WizardSequence" %> +<%@ page import="java.util.List" %> +<%@ page import="java.util.Iterator" %> +<%@ page import="org.openecomp.portalsdk.analytics.system.Globals" %> +<%@ page import="org.openecomp.portalsdk.analytics.util.Utils" %> +<%@ page import="java.util.Vector" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.ReportLoader" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.base.IdNameValue" %> +<%@ page import="org.openecomp.portalsdk.analytics.xmlobj.FormFieldType" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.base.ReportWrapper" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.DataCache" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.runtime.FormField" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.base.OrderBySeqComparator" %> +<%@ page import="java.util.Collections" %> +<% + ReportDefinition rdef = (ReportDefinition) request.getAttribute(AppConstants.SI_REPORT_DEFINITION); + WizardSequence ws = rdef.getWizardSequence(); + String curSubStep = ws.getCurrentSubStep(); + String reportID = rdef.getReportID(); + boolean isCrossTab = rdef.getReportType().equals(AppConstants.RT_CROSSTAB); + boolean isSQLBased = rdef.getReportDefType().equals(AppConstants.RD_SQL_BASED); + +%> + + + + + + + + + + +<% int icnt = 0; + for(Iterator iter=rdef.getAllColumns().iterator(); iter.hasNext(); icnt++) { + DataColumnType dct = (DataColumnType) iter.next(); %> + > + + + + + +<% } // for +%> +
    Step <%= ws.getCurrentStepIndex() %> of <%= ws.getStepCount() %> - Report <%= ws.getCurrentStep() %> - <%= curSubStep %>
      No  ColumnSort OrderSort Type
    <%= icnt+1 %><%= dct.getDisplayName() %> + + "> + + +
    + + +
    + + + +<%! + private String nvl(String s) { return (s==null)?"":s; } + private String nvl(String s, String sDefault) { return nvl(s).equals("")?sDefault:s; } +%> + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_sql_def.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_sql_def.jsp new file mode 100644 index 000000000..d8152c05f --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_sql_def.jsp @@ -0,0 +1,226 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +<%@ page import="org.openecomp.portalsdk.analytics.xmlobj.DataColumnType" %> +<%@ page import="org.openecomp.portalsdk.analytics.util.AppConstants" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.definition.ReportDefinition" %> +<%@ page import="org.openecomp.portalsdk.analytics.system.AppUtils" %> +<%@ page import="org.openecomp.portalsdk.analytics.controller.WizardSequence" %> +<%@ page import="java.util.List" %> +<%@ page import="java.util.Iterator" %> +<%@ page import="org.openecomp.portalsdk.analytics.system.Globals" %> +<%@ page import="org.openecomp.portalsdk.analytics.util.Utils" %> +<%@ page import="java.util.Vector" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.ReportLoader" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.base.IdNameValue" %> +<%@ page import="org.openecomp.portalsdk.analytics.xmlobj.FormFieldType" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.base.ReportWrapper" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.DataCache" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.runtime.FormField" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.base.OrderBySeqComparator" %> +<%@ page import="java.util.Collections" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.definition.TableSource" %> +<% + ReportDefinition rdef = (ReportDefinition) request.getAttribute(AppConstants.SI_REPORT_DEFINITION); + WizardSequence ws = rdef.getWizardSequence(); + String curSubStep = ws.getCurrentSubStep(); + String reportID = rdef.getReportID(); + boolean isCrossTab = rdef.getReportType().equals(AppConstants.RT_CROSSTAB); + boolean isSQLBased = rdef.getReportDefType().equals(AppConstants.RD_SQL_BASED); + +%> + + + + + + + + + + + + + + + + + +
    Step <%= ws.getCurrentStepIndex() %> of <%= ws.getStepCount() %> - Report <%= ws.getCurrentStep() %>
    +  Report SQL:
    + <% boolean sqlValidated = (nvl(AppUtils.getRequestValue(request, "sqlValidated"), nvl(rdef.getReportSQL())).length()>0); + if(request.getAttribute(AppConstants.RI_ERROR_LIST)!=null) + sqlValidated = false; + + String sql = nvl(rdef.getReportSQL(), "SELECT "); + if(! sqlValidated) + sql = nvl(AppUtils.getRequestValue(request, "reportSQL"), sql); %> + "> +   +
    +  Keyword Assistance
    + +       SELECT  DISTINCT 
    +       FROM 
    +       WHERE 
    +       GROUP BY 
    +       HAVING 
    +       ORDER BY  ASC  DESC 
    +
    +       UNION  ALL  INTERSECT  MINUS 
    +
    +       AND  OR  NOT  EXISTS 
    +       IS  NULL  IN  BETWEEN 
    +
    +       COUNT(  SUM(  AVG(  MAX(  MIN( 
    +
    +       NVL(  DECODE(  SYSDATE 
    +       TO_CHAR(  TO_NUMBER(  TO_DATE( 
    +       TRUNC(  ROUND(  ABS( 
    +       SUBSTR(  REPLACE(  LOWER(  UPPER( 
    +       LTRIM(  RTRIM(  LPAD(  RPAD( 
    +
    +
    + + +   + +   + +   + +
    You need to click the "Validate SQL" button in order to store the SQL before going forward
    +
    + + + +<%! + private String nvl(String s) { return (s==null)?"":s; } + private String nvl(String s, String sDefault) { return nvl(s).equals("")?sDefault:s; } +%> diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_tables_edit.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_tables_edit.jsp new file mode 100644 index 000000000..88ecda311 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_tables_edit.jsp @@ -0,0 +1,369 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +<%@ page import="org.openecomp.portalsdk.analytics.xmlobj.DataColumnType" %> +<%@ page import="org.openecomp.portalsdk.analytics.util.AppConstants" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.definition.ReportDefinition" %> +<%@ page import="org.openecomp.portalsdk.analytics.system.AppUtils" %> +<%@ page import="org.openecomp.portalsdk.analytics.controller.WizardSequence" %> +<%@ page import="java.util.Vector" %> +<%@ page import="java.util.List" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.DataCache" %> +<%@ page import="java.util.Iterator" %> +<%@ page import="org.openecomp.portalsdk.analytics.xmlobj.DataSourceType" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.definition.DBColumnInfo" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.definition.TableSource" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.base.IdNameValue" %> +<%@ page import="org.openecomp.portalsdk.analytics.xmlobj.SemaphoreType" %> +<%@ page import="org.openecomp.portalsdk.analytics.xmlobj.FormFieldType" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.definition.TableJoin" %> +<%@ page import="org.openecomp.portalsdk.analytics.error.UserDefinedException"%> + +<% + ReportDefinition rdef = (ReportDefinition) request.getAttribute(AppConstants.SI_REPORT_DEFINITION); + WizardSequence ws = rdef.getWizardSequence(); + String curSubStep = ws.getCurrentSubStep(); + boolean isEdit = curSubStep.equals(AppConstants.WSS_EDIT); + DataSourceType currTable = null; + if(isEdit) + currTable = rdef.getTableById(AppUtils.getRequestNvlValue(request, AppConstants.RI_DETAIL_ID)); + Vector reportTableSources = (isEdit)?DataCache.getReportTableSources((String) session.getAttribute("remoteDB")):DataCache.getReportTableSources(AppUtils.getUserRoles(request),((String) session.getAttribute("remoteDB")), AppUtils.getUserID(request), request); + if(reportTableSources.size()<=0) { + request.setAttribute(AppConstants.RI_EXCEPTION, new Exception("Please add table name to the raptor table for generating report")); + throw new UserDefinedException("Please add table name to the raptor table for generating report"); + } + Vector reportTableJoins = (isEdit)?DataCache.getReportTableJoins():DataCache.getReportTableJoins(AppUtils.getUserRoles(request)); %> + +<% if(! isEdit) { %> + +<% } %> + + + + + + + + + + + + + + + +<% if(rdef.getDataSourceList().getDataSource().size()>(isEdit?1:0)) { + String outerJoinType = (isEdit?rdef.getOuterJoinType(currTable):""); %> + + + + + + + + + + <% if(isEdit) { %> + + <%} %> + + + + + +<% } %> +
    Step <%= ws.getCurrentStepIndex() %> of <%= ws.getStepCount() %> - Report <%= ws.getCurrentStep() %> - <%= curSubStep %>
    Table Name + <% if(isEdit) { + String tName = null; + for(int i=0; i + <%= nvl(tName, currTable.getTableName()) %> + + <% } else { %> + + <% } %> + +
    Display Name +
    Join To Table + <% if(isEdit) { %> + <% if(currTable.getRefTableId()==null){%> + --- Table Not Joined --- + <%} else { %> + <%=rdef.getTableById(currTable.getRefTableId()).getDisplayName() %> +
    on : <%=currTable.getRefDefinition() %> + <%} %> + + + <% } else { %> + + <% } %> +
    All availabe Join Options + +
    Join Type + +
    +
    + + + +<%! + private String nvl(String s) { return (s==null)?"":s; } + private String nvl(String s, String sDefault) { return nvl(s).equals("")?sDefault:s; } +%> diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_tables_list.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_tables_list.jsp new file mode 100644 index 000000000..47fd435ff --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_tables_list.jsp @@ -0,0 +1,85 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +<%@ page import="org.openecomp.portalsdk.analytics.xmlobj.DataColumnType" %> +<%@ page import="org.openecomp.portalsdk.analytics.util.AppConstants" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.definition.ReportDefinition" %> +<%@ page import="org.openecomp.portalsdk.analytics.system.AppUtils" %> +<%@ page import="org.openecomp.portalsdk.analytics.controller.WizardSequence" %> +<%@ page import="java.util.Vector" %> +<%@ page import="java.util.List" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.DataCache" %> +<%@ page import="java.util.Iterator" %> +<%@ page import="org.openecomp.portalsdk.analytics.xmlobj.DataSourceType" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.definition.DBColumnInfo" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.definition.TableSource" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.base.IdNameValue" %> +<%@ page import="org.openecomp.portalsdk.analytics.xmlobj.SemaphoreType" %> +<%@ page import="org.openecomp.portalsdk.analytics.xmlobj.FormFieldType" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.definition.TableJoin" %> + +<% + ReportDefinition rdef = (ReportDefinition) request.getAttribute(AppConstants.SI_REPORT_DEFINITION); + WizardSequence ws = rdef.getWizardSequence(); + String curSubStep = ws.getCurrentSubStep(); +%> + + + + + + + + + +<% int iCount = 0; + for(Iterator iter=rdef.getDataSourceList().getDataSource().iterator(); iter.hasNext(); iCount++) { + DataSourceType dst = (DataSourceType) iter.next(); %> + > + + + + + +<% } %> +<% if(iCount==0) { %> + + + +<% } %> +
    Step <%= ws.getCurrentStepIndex() %> of <%= ws.getStepCount() %> - Report <%= ws.getCurrentStep() %>
      No  Table
    <%= iCount+1 %><%= nvl(dst.getDisplayName()).length()>0?dst.getDisplayName():dst.getTableName()%>
    No tables defined
    +
    + + + +<%! private String nvl(String s) { return (s==null)?"":s; } + private String nvl(String s, String sDefault) { return nvl(s).equals("")?sDefault:s; } +%> + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_user_access.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_user_access.jsp new file mode 100644 index 000000000..b5c68045f --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/fusion/raptor/wizard_user_access.jsp @@ -0,0 +1,184 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +<%@ page import="org.openecomp.portalsdk.analytics.xmlobj.DataColumnType" %> +<%@ page import="org.openecomp.portalsdk.analytics.util.AppConstants" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.definition.ReportDefinition" %> +<%@ page import="org.openecomp.portalsdk.analytics.system.AppUtils" %> +<%@ page import="org.openecomp.portalsdk.analytics.controller.WizardSequence" %> +<%@ page import="java.util.Vector" %> +<%@ page import="java.util.List" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.DataCache" %> +<%@ page import="java.util.Iterator" %> +<%@ page import="org.openecomp.portalsdk.analytics.xmlobj.DataSourceType" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.definition.DBColumnInfo" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.definition.TableSource" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.base.IdNameValue" %> +<%@ page import="org.openecomp.portalsdk.analytics.xmlobj.SemaphoreType" %> +<%@ page import="org.openecomp.portalsdk.analytics.xmlobj.FormFieldType" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.definition.TableJoin" %> +<%@ page import="org.openecomp.portalsdk.analytics.model.definition.SecurityEntry" %> +<%@ page import="org.openecomp.portalsdk.analytics.util.Utils" %> + +<% + ReportDefinition rdef = (ReportDefinition) request.getAttribute(AppConstants.SI_REPORT_DEFINITION); + WizardSequence ws = rdef.getWizardSequence(); + String curSubStep = ws.getCurrentSubStep(); +%> + + + + + + + + + + + + + + + + + + + + + + +
    Step <%= ws.getCurrentStepIndex() %> of <%= ws.getStepCount() %> - Report <%= ws.getCurrentStep() %>
    Created By: <%= AppUtils.getUserName(rdef.getCreateID()) %>Created Date: <%= rdef.getCreateDate() %>
    Last Updated By: <%= AppUtils.getUserName(rdef.getUpdateID()) %>Last Updated: <%= rdef.getUpdateDate() %>
    Report Owner: + + Public? (All users can run the report) + +
    +
    + + + + + + + + + + + + +<% int iCount = 0; + Vector reportUsers = rdef.getReportUsers(request); + for(Iterator iter=reportUsers.iterator(); iter.hasNext(); iCount++) { + SecurityEntry rUser = (SecurityEntry) iter.next(); %> + "> + + + + + + +<% } // for +// if(iCount==0) { %> + +<% //} + Vector remainingUsers = Utils.getUsersNotInList(reportUsers,request); + if(remainingUsers.size()>0) { %> + + +<% } // if +%> + +
    Report Users
      No  User NameRun AccessEdit AccessRemove
    <%= iCount+1 %><%= rUser.getName() %>" alt="<%= rUser.isReadOnly()?"Grant":"Revoke" %> edit access" width="16" height="16" border="0" onClick="document.forma.<%= AppConstants.RI_WIZARD_ACTION %>.value='<%= rUser.isReadOnly()?AppConstants.WA_GRANT_USER:AppConstants.WA_REVOKE_USER %>'; document.forma.<%= AppConstants.RI_DETAIL_ID %>.value='<%= rUser.getId() %>';">
    Grant Access To  + +
    +
    + + + + + + + + + + + + +<% iCount = 0; + Vector reportRoles = rdef.getReportRoles(request); + for(Iterator iter=reportRoles.iterator(); iter.hasNext(); iCount++) { + SecurityEntry rRole = (SecurityEntry) iter.next(); %> + "> + + + + + + +<% } // for +// if(iCount==0) { %> + +<% //} + Vector remainingRoles = Utils.getRolesNotInList(reportRoles,request); + if(remainingRoles.size()>0) { %> + + +<% } // if +%> + +
    Report Roles
      No  Role NameRun AccessEdit AccessRemove
    <%= iCount+1 %><%= rRole.getName() %>" alt="<%= rRole.isReadOnly()?"Grant":"Revoke" %> edit access" width="16" height="16" border="0" onClick="document.forma.<%= AppConstants.RI_WIZARD_ACTION %>.value='<%= rRole.isReadOnly()?AppConstants.WA_GRANT_ROLE:AppConstants.WA_REVOKE_ROLE %>'; document.forma.<%= AppConstants.RI_DETAIL_ID %>.value='<%= rRole.getId() %>';">
    Grant Access To  + +
    +
    + + + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/jsp/error.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/jsp/error.jsp new file mode 100644 index 000000000..2a48507c9 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/jsp/error.jsp @@ -0,0 +1,20 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +${errMsg} diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/jsp/leafletMap.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/jsp/leafletMap.jsp new file mode 100644 index 000000000..77981f736 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/jsp/leafletMap.jsp @@ -0,0 +1,288 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> + + + + + + + + + + + + + + + + + + +
    + + +
    + + + + + + + + + +
    SiteUsage
    + + + + + + + + + +
    LinkUsage
    +
    + + + + + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/jsp/login_external.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/jsp/login_external.jsp new file mode 100644 index 000000000..b4e3c0932 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/jsp/login_external.jsp @@ -0,0 +1,154 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> +<%@ page import="org.openecomp.portalsdk.core.util.SystemProperties" %> + +" /> + + + + + + + Login + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + +
    +
    + +

    ECOMP Portal

    + + +
    +
    + + +
    +
    +                + +
    +
    +
    +






    + +
    + + + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/jsp/net_map.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/jsp/net_map.jsp new file mode 100644 index 000000000..2a341467f --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/jsp/net_map.jsp @@ -0,0 +1,38 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> + + + + + + + + + +
    + +
    + + + + + + + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/jsp/user_profile.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/jsp/user_profile.jsp new file mode 100644 index 000000000..cb5c4e3bf --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/jsp/user_profile.jsp @@ -0,0 +1,84 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +<%@ include file="/WEB-INF/fusion/jsp/popup_modal.html" %> +
    +
    +

    Profile Search

    +
    + + + + + + + + + + + + + + + + + + + + + + +
    User IDLast NameFirst NameEmailOrgUserIdManager OrgUserId
    {{rowData.id}}{{rowData.last_name}}{{rowData.first_name}}{{rowData.email}}{{rowData.orgUserId}}{{rowData.org_manager_userid}}
    +
    +
    +
    + Rows Per Page: + +
    +
    + Current Page: + +
    +
    + Total Page(s): + +
    +
    + + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/jsp/welcome.jsp b/ecomp-sdk-app/src/main/webapp/WEB-INF/jsp/welcome.jsp new file mode 100644 index 000000000..d7d3b8967 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/jsp/welcome.jsp @@ -0,0 +1,629 @@ +<%-- + ================================================================================ + eCOMP Portal SDK + ================================================================================ + Copyright (C) 2017 AT&T Intellectual Property + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ================================================================================ + --%> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> +<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + +
    + Welcome ${sessionScope.user.firstName} ${sessionScope.user.lastName}  + (Last Login:  ${lastLogin}) +
    + +
    +
    +
    +
    +
    + +
    + + + + +
    + +
    +
    + +
    +
    +
    + +
    +
    + +
    +
    +
    +
    + +
    + +
    +
    + +
    +
    +
    +
    + +
    + + +
    +
    + +
    + +
    +
    +
      +
    • {{Daytab.title}}
    • +
    +
    +
    +
    + + + + + + + +
    +
    + +
    +
    +
      +
    • {{TrafficTab.title}}
    • +
    +
    +
    +
    + + + + + +
    +
    + +
    + + + + + + + + + + + + + + + + + + +
    JQuery + +
    Animated Map + +
    Chat Session + +
    +
    +
    +
    +
    + +
    + + + + + + + + + +
    + +
    + + +
    + +
    +
    +
    +
    + +
    + + + + + diff --git a/ecomp-sdk-app/src/main/webapp/WEB-INF/web.xml b/ecomp-sdk-app/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 000000000..32cfa88ec --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,24 @@ + + + + ecomp-sdk-app + + + + + FileManagerServlet + org.openecomp.policy.admin.PolicyManagerServlet + + + FileManagerServlet + /fm/* + + + 7 + COOKIE + + + diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-animate.js b/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-animate.js new file mode 100644 index 000000000..2778fc564 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-animate.js @@ -0,0 +1,4121 @@ +/** + * @license AngularJS v1.5.0 + * (c) 2010-2016 Google, Inc. http://angularjs.org + * License: MIT + */ +(function(window, angular, undefined) {'use strict'; + +/* jshint ignore:start */ +var noop = angular.noop; +var copy = angular.copy; +var extend = angular.extend; +var jqLite = angular.element; +var forEach = angular.forEach; +var isArray = angular.isArray; +var isString = angular.isString; +var isObject = angular.isObject; +var isUndefined = angular.isUndefined; +var isDefined = angular.isDefined; +var isFunction = angular.isFunction; +var isElement = angular.isElement; + +var ELEMENT_NODE = 1; +var COMMENT_NODE = 8; + +var ADD_CLASS_SUFFIX = '-add'; +var REMOVE_CLASS_SUFFIX = '-remove'; +var EVENT_CLASS_PREFIX = 'ng-'; +var ACTIVE_CLASS_SUFFIX = '-active'; +var PREPARE_CLASS_SUFFIX = '-prepare'; + +var NG_ANIMATE_CLASSNAME = 'ng-animate'; +var NG_ANIMATE_CHILDREN_DATA = '$$ngAnimateChildren'; + +// Detect proper transitionend/animationend event names. +var CSS_PREFIX = '', TRANSITION_PROP, TRANSITIONEND_EVENT, ANIMATION_PROP, ANIMATIONEND_EVENT; + +// If unprefixed events are not supported but webkit-prefixed are, use the latter. +// Otherwise, just use W3C names, browsers not supporting them at all will just ignore them. +// Note: Chrome implements `window.onwebkitanimationend` and doesn't implement `window.onanimationend` +// but at the same time dispatches the `animationend` event and not `webkitAnimationEnd`. +// Register both events in case `window.onanimationend` is not supported because of that, +// do the same for `transitionend` as Safari is likely to exhibit similar behavior. +// Also, the only modern browser that uses vendor prefixes for transitions/keyframes is webkit +// therefore there is no reason to test anymore for other vendor prefixes: +// http://caniuse.com/#search=transition +if (isUndefined(window.ontransitionend) && isDefined(window.onwebkittransitionend)) { + CSS_PREFIX = '-webkit-'; + TRANSITION_PROP = 'WebkitTransition'; + TRANSITIONEND_EVENT = 'webkitTransitionEnd transitionend'; +} else { + TRANSITION_PROP = 'transition'; + TRANSITIONEND_EVENT = 'transitionend'; +} + +if (isUndefined(window.onanimationend) && isDefined(window.onwebkitanimationend)) { + CSS_PREFIX = '-webkit-'; + ANIMATION_PROP = 'WebkitAnimation'; + ANIMATIONEND_EVENT = 'webkitAnimationEnd animationend'; +} else { + ANIMATION_PROP = 'animation'; + ANIMATIONEND_EVENT = 'animationend'; +} + +var DURATION_KEY = 'Duration'; +var PROPERTY_KEY = 'Property'; +var DELAY_KEY = 'Delay'; +var TIMING_KEY = 'TimingFunction'; +var ANIMATION_ITERATION_COUNT_KEY = 'IterationCount'; +var ANIMATION_PLAYSTATE_KEY = 'PlayState'; +var SAFE_FAST_FORWARD_DURATION_VALUE = 9999; + +var ANIMATION_DELAY_PROP = ANIMATION_PROP + DELAY_KEY; +var ANIMATION_DURATION_PROP = ANIMATION_PROP + DURATION_KEY; +var TRANSITION_DELAY_PROP = TRANSITION_PROP + DELAY_KEY; +var TRANSITION_DURATION_PROP = TRANSITION_PROP + DURATION_KEY; + +var isPromiseLike = function(p) { + return p && p.then ? true : false; +}; + +var ngMinErr = angular.$$minErr('ng'); +function assertArg(arg, name, reason) { + if (!arg) { + throw ngMinErr('areq', "Argument '{0}' is {1}", (name || '?'), (reason || "required")); + } + return arg; +} + +function mergeClasses(a,b) { + if (!a && !b) return ''; + if (!a) return b; + if (!b) return a; + if (isArray(a)) a = a.join(' '); + if (isArray(b)) b = b.join(' '); + return a + ' ' + b; +} + +function packageStyles(options) { + var styles = {}; + if (options && (options.to || options.from)) { + styles.to = options.to; + styles.from = options.from; + } + return styles; +} + +function pendClasses(classes, fix, isPrefix) { + var className = ''; + classes = isArray(classes) + ? classes + : classes && isString(classes) && classes.length + ? classes.split(/\s+/) + : []; + forEach(classes, function(klass, i) { + if (klass && klass.length > 0) { + className += (i > 0) ? ' ' : ''; + className += isPrefix ? fix + klass + : klass + fix; + } + }); + return className; +} + +function removeFromArray(arr, val) { + var index = arr.indexOf(val); + if (val >= 0) { + arr.splice(index, 1); + } +} + +function stripCommentsFromElement(element) { + if (element instanceof jqLite) { + switch (element.length) { + case 0: + return []; + break; + + case 1: + // there is no point of stripping anything if the element + // is the only element within the jqLite wrapper. + // (it's important that we retain the element instance.) + if (element[0].nodeType === ELEMENT_NODE) { + return element; + } + break; + + default: + return jqLite(extractElementNode(element)); + break; + } + } + + if (element.nodeType === ELEMENT_NODE) { + return jqLite(element); + } +} + +function extractElementNode(element) { + if (!element[0]) return element; + for (var i = 0; i < element.length; i++) { + var elm = element[i]; + if (elm.nodeType == ELEMENT_NODE) { + return elm; + } + } +} + +function $$addClass($$jqLite, element, className) { + forEach(element, function(elm) { + $$jqLite.addClass(elm, className); + }); +} + +function $$removeClass($$jqLite, element, className) { + forEach(element, function(elm) { + $$jqLite.removeClass(elm, className); + }); +} + +function applyAnimationClassesFactory($$jqLite) { + return function(element, options) { + if (options.addClass) { + $$addClass($$jqLite, element, options.addClass); + options.addClass = null; + } + if (options.removeClass) { + $$removeClass($$jqLite, element, options.removeClass); + options.removeClass = null; + } + } +} + +function prepareAnimationOptions(options) { + options = options || {}; + if (!options.$$prepared) { + var domOperation = options.domOperation || noop; + options.domOperation = function() { + options.$$domOperationFired = true; + domOperation(); + domOperation = noop; + }; + options.$$prepared = true; + } + return options; +} + +function applyAnimationStyles(element, options) { + applyAnimationFromStyles(element, options); + applyAnimationToStyles(element, options); +} + +function applyAnimationFromStyles(element, options) { + if (options.from) { + element.css(options.from); + options.from = null; + } +} + +function applyAnimationToStyles(element, options) { + if (options.to) { + element.css(options.to); + options.to = null; + } +} + +function mergeAnimationDetails(element, oldAnimation, newAnimation) { + var target = oldAnimation.options || {}; + var newOptions = newAnimation.options || {}; + + var toAdd = (target.addClass || '') + ' ' + (newOptions.addClass || ''); + var toRemove = (target.removeClass || '') + ' ' + (newOptions.removeClass || ''); + var classes = resolveElementClasses(element.attr('class'), toAdd, toRemove); + + if (newOptions.preparationClasses) { + target.preparationClasses = concatWithSpace(newOptions.preparationClasses, target.preparationClasses); + delete newOptions.preparationClasses; + } + + // noop is basically when there is no callback; otherwise something has been set + var realDomOperation = target.domOperation !== noop ? target.domOperation : null; + + extend(target, newOptions); + + // TODO(matsko or sreeramu): proper fix is to maintain all animation callback in array and call at last,but now only leave has the callback so no issue with this. + if (realDomOperation) { + target.domOperation = realDomOperation; + } + + if (classes.addClass) { + target.addClass = classes.addClass; + } else { + target.addClass = null; + } + + if (classes.removeClass) { + target.removeClass = classes.removeClass; + } else { + target.removeClass = null; + } + + oldAnimation.addClass = target.addClass; + oldAnimation.removeClass = target.removeClass; + + return target; +} + +function resolveElementClasses(existing, toAdd, toRemove) { + var ADD_CLASS = 1; + var REMOVE_CLASS = -1; + + var flags = {}; + existing = splitClassesToLookup(existing); + + toAdd = splitClassesToLookup(toAdd); + forEach(toAdd, function(value, key) { + flags[key] = ADD_CLASS; + }); + + toRemove = splitClassesToLookup(toRemove); + forEach(toRemove, function(value, key) { + flags[key] = flags[key] === ADD_CLASS ? null : REMOVE_CLASS; + }); + + var classes = { + addClass: '', + removeClass: '' + }; + + forEach(flags, function(val, klass) { + var prop, allow; + if (val === ADD_CLASS) { + prop = 'addClass'; + allow = !existing[klass]; + } else if (val === REMOVE_CLASS) { + prop = 'removeClass'; + allow = existing[klass]; + } + if (allow) { + if (classes[prop].length) { + classes[prop] += ' '; + } + classes[prop] += klass; + } + }); + + function splitClassesToLookup(classes) { + if (isString(classes)) { + classes = classes.split(' '); + } + + var obj = {}; + forEach(classes, function(klass) { + // sometimes the split leaves empty string values + // incase extra spaces were applied to the options + if (klass.length) { + obj[klass] = true; + } + }); + return obj; + } + + return classes; +} + +function getDomNode(element) { + return (element instanceof angular.element) ? element[0] : element; +} + +function applyGeneratedPreparationClasses(element, event, options) { + var classes = ''; + if (event) { + classes = pendClasses(event, EVENT_CLASS_PREFIX, true); + } + if (options.addClass) { + classes = concatWithSpace(classes, pendClasses(options.addClass, ADD_CLASS_SUFFIX)); + } + if (options.removeClass) { + classes = concatWithSpace(classes, pendClasses(options.removeClass, REMOVE_CLASS_SUFFIX)); + } + if (classes.length) { + options.preparationClasses = classes; + element.addClass(classes); + } +} + +function clearGeneratedClasses(element, options) { + if (options.preparationClasses) { + element.removeClass(options.preparationClasses); + options.preparationClasses = null; + } + if (options.activeClasses) { + element.removeClass(options.activeClasses); + options.activeClasses = null; + } +} + +function blockTransitions(node, duration) { + // we use a negative delay value since it performs blocking + // yet it doesn't kill any existing transitions running on the + // same element which makes this safe for class-based animations + var value = duration ? '-' + duration + 's' : ''; + applyInlineStyle(node, [TRANSITION_DELAY_PROP, value]); + return [TRANSITION_DELAY_PROP, value]; +} + +function blockKeyframeAnimations(node, applyBlock) { + var value = applyBlock ? 'paused' : ''; + var key = ANIMATION_PROP + ANIMATION_PLAYSTATE_KEY; + applyInlineStyle(node, [key, value]); + return [key, value]; +} + +function applyInlineStyle(node, styleTuple) { + var prop = styleTuple[0]; + var value = styleTuple[1]; + node.style[prop] = value; +} + +function concatWithSpace(a,b) { + if (!a) return b; + if (!b) return a; + return a + ' ' + b; +} + +var $$rAFSchedulerFactory = ['$$rAF', function($$rAF) { + var queue, cancelFn; + + function scheduler(tasks) { + // we make a copy since RAFScheduler mutates the state + // of the passed in array variable and this would be difficult + // to track down on the outside code + queue = queue.concat(tasks); + nextTick(); + } + + queue = scheduler.queue = []; + + /* waitUntilQuiet does two things: + * 1. It will run the FINAL `fn` value only when an uncanceled RAF has passed through + * 2. It will delay the next wave of tasks from running until the quiet `fn` has run. + * + * The motivation here is that animation code can request more time from the scheduler + * before the next wave runs. This allows for certain DOM properties such as classes to + * be resolved in time for the next animation to run. + */ + scheduler.waitUntilQuiet = function(fn) { + if (cancelFn) cancelFn(); + + cancelFn = $$rAF(function() { + cancelFn = null; + fn(); + nextTick(); + }); + }; + + return scheduler; + + function nextTick() { + if (!queue.length) return; + + var items = queue.shift(); + for (var i = 0; i < items.length; i++) { + items[i](); + } + + if (!cancelFn) { + $$rAF(function() { + if (!cancelFn) nextTick(); + }); + } + } +}]; + +/** + * @ngdoc directive + * @name ngAnimateChildren + * @restrict AE + * @element ANY + * + * @description + * + * ngAnimateChildren allows you to specify that children of this element should animate even if any + * of the children's parents are currently animating. By default, when an element has an active `enter`, `leave`, or `move` + * (structural) animation, child elements that also have an active structural animation are not animated. + * + * Note that even if `ngAnimteChildren` is set, no child animations will run when the parent element is removed from the DOM (`leave` animation). + * + * + * @param {string} ngAnimateChildren If the value is empty, `true` or `on`, + * then child animations are allowed. If the value is `false`, child animations are not allowed. + * + * @example + * + +
    + + +
    +
    +
    + List of items: +
    Item {{item}}
    +
    +
    +
    +
    + + + .container.ng-enter, + .container.ng-leave { + transition: all ease 1.5s; + } + + .container.ng-enter, + .container.ng-leave-active { + opacity: 0; + } + + .container.ng-leave, + .container.ng-enter-active { + opacity: 1; + } + + .item { + background: firebrick; + color: #FFF; + margin-bottom: 10px; + } + + .item.ng-enter, + .item.ng-leave { + transition: transform 1.5s ease; + } + + .item.ng-enter { + transform: translateX(50px); + } + + .item.ng-enter-active { + transform: translateX(0); + } + + + angular.module('ngAnimateChildren', ['ngAnimate']) + .controller('mainController', function() { + this.animateChildren = false; + this.enterElement = false; + }); + +
    + */ +var $$AnimateChildrenDirective = ['$interpolate', function($interpolate) { + return { + link: function(scope, element, attrs) { + var val = attrs.ngAnimateChildren; + if (angular.isString(val) && val.length === 0) { //empty attribute + element.data(NG_ANIMATE_CHILDREN_DATA, true); + } else { + // Interpolate and set the value, so that it is available to + // animations that run right after compilation + setData($interpolate(val)(scope)); + attrs.$observe('ngAnimateChildren', setData); + } + + function setData(value) { + value = value === 'on' || value === 'true'; + element.data(NG_ANIMATE_CHILDREN_DATA, value); + } + } + }; +}]; + +var ANIMATE_TIMER_KEY = '$$animateCss'; + +/** + * @ngdoc service + * @name $animateCss + * @kind object + * + * @description + * The `$animateCss` service is a useful utility to trigger customized CSS-based transitions/keyframes + * from a JavaScript-based animation or directly from a directive. The purpose of `$animateCss` is NOT + * to side-step how `$animate` and ngAnimate work, but the goal is to allow pre-existing animations or + * directives to create more complex animations that can be purely driven using CSS code. + * + * Note that only browsers that support CSS transitions and/or keyframe animations are capable of + * rendering animations triggered via `$animateCss` (bad news for IE9 and lower). + * + * ## Usage + * Once again, `$animateCss` is designed to be used inside of a registered JavaScript animation that + * is powered by ngAnimate. It is possible to use `$animateCss` directly inside of a directive, however, + * any automatic control over cancelling animations and/or preventing animations from being run on + * child elements will not be handled by Angular. For this to work as expected, please use `$animate` to + * trigger the animation and then setup a JavaScript animation that injects `$animateCss` to trigger + * the CSS animation. + * + * The example below shows how we can create a folding animation on an element using `ng-if`: + * + * ```html + * + *
    + * This element will go BOOM + *
    + * + * ``` + * + * Now we create the **JavaScript animation** that will trigger the CSS transition: + * + * ```js + * ngModule.animation('.fold-animation', ['$animateCss', function($animateCss) { + * return { + * enter: function(element, doneFn) { + * var height = element[0].offsetHeight; + * return $animateCss(element, { + * from: { height:'0px' }, + * to: { height:height + 'px' }, + * duration: 1 // one second + * }); + * } + * } + * }]); + * ``` + * + * ## More Advanced Uses + * + * `$animateCss` is the underlying code that ngAnimate uses to power **CSS-based animations** behind the scenes. Therefore CSS hooks + * like `.ng-EVENT`, `.ng-EVENT-active`, `.ng-EVENT-stagger` are all features that can be triggered using `$animateCss` via JavaScript code. + * + * This also means that just about any combination of adding classes, removing classes, setting styles, dynamically setting a keyframe animation, + * applying a hardcoded duration or delay value, changing the animation easing or applying a stagger animation are all options that work with + * `$animateCss`. The service itself is smart enough to figure out the combination of options and examine the element styling properties in order + * to provide a working animation that will run in CSS. + * + * The example below showcases a more advanced version of the `.fold-animation` from the example above: + * + * ```js + * ngModule.animation('.fold-animation', ['$animateCss', function($animateCss) { + * return { + * enter: function(element, doneFn) { + * var height = element[0].offsetHeight; + * return $animateCss(element, { + * addClass: 'red large-text pulse-twice', + * easing: 'ease-out', + * from: { height:'0px' }, + * to: { height:height + 'px' }, + * duration: 1 // one second + * }); + * } + * } + * }]); + * ``` + * + * Since we're adding/removing CSS classes then the CSS transition will also pick those up: + * + * ```css + * /* since a hardcoded duration value of 1 was provided in the JavaScript animation code, + * the CSS classes below will be transitioned despite them being defined as regular CSS classes */ + * .red { background:red; } + * .large-text { font-size:20px; } + * + * /* we can also use a keyframe animation and $animateCss will make it work alongside the transition */ + * .pulse-twice { + * animation: 0.5s pulse linear 2; + * -webkit-animation: 0.5s pulse linear 2; + * } + * + * @keyframes pulse { + * from { transform: scale(0.5); } + * to { transform: scale(1.5); } + * } + * + * @-webkit-keyframes pulse { + * from { -webkit-transform: scale(0.5); } + * to { -webkit-transform: scale(1.5); } + * } + * ``` + * + * Given this complex combination of CSS classes, styles and options, `$animateCss` will figure everything out and make the animation happen. + * + * ## How the Options are handled + * + * `$animateCss` is very versatile and intelligent when it comes to figuring out what configurations to apply to the element to ensure the animation + * works with the options provided. Say for example we were adding a class that contained a keyframe value and we wanted to also animate some inline + * styles using the `from` and `to` properties. + * + * ```js + * var animator = $animateCss(element, { + * from: { background:'red' }, + * to: { background:'blue' } + * }); + * animator.start(); + * ``` + * + * ```css + * .rotating-animation { + * animation:0.5s rotate linear; + * -webkit-animation:0.5s rotate linear; + * } + * + * @keyframes rotate { + * from { transform: rotate(0deg); } + * to { transform: rotate(360deg); } + * } + * + * @-webkit-keyframes rotate { + * from { -webkit-transform: rotate(0deg); } + * to { -webkit-transform: rotate(360deg); } + * } + * ``` + * + * The missing pieces here are that we do not have a transition set (within the CSS code nor within the `$animateCss` options) and the duration of the animation is + * going to be detected from what the keyframe styles on the CSS class are. In this event, `$animateCss` will automatically create an inline transition + * style matching the duration detected from the keyframe style (which is present in the CSS class that is being added) and then prepare both the transition + * and keyframe animations to run in parallel on the element. Then when the animation is underway the provided `from` and `to` CSS styles will be applied + * and spread across the transition and keyframe animation. + * + * ## What is returned + * + * `$animateCss` works in two stages: a preparation phase and an animation phase. Therefore when `$animateCss` is first called it will NOT actually + * start the animation. All that is going on here is that the element is being prepared for the animation (which means that the generated CSS classes are + * added and removed on the element). Once `$animateCss` is called it will return an object with the following properties: + * + * ```js + * var animator = $animateCss(element, { ... }); + * ``` + * + * Now what do the contents of our `animator` variable look like: + * + * ```js + * { + * // starts the animation + * start: Function, + * + * // ends (aborts) the animation + * end: Function + * } + * ``` + * + * To actually start the animation we need to run `animation.start()` which will then return a promise that we can hook into to detect when the animation ends. + * If we choose not to run the animation then we MUST run `animation.end()` to perform a cleanup on the element (since some CSS classes and styles may have been + * applied to the element during the preparation phase). Note that all other properties such as duration, delay, transitions and keyframes are just properties + * and that changing them will not reconfigure the parameters of the animation. + * + * ### runner.done() vs runner.then() + * It is documented that `animation.start()` will return a promise object and this is true, however, there is also an additional method available on the + * runner called `.done(callbackFn)`. The done method works the same as `.finally(callbackFn)`, however, it does **not trigger a digest to occur**. + * Therefore, for performance reasons, it's always best to use `runner.done(callback)` instead of `runner.then()`, `runner.catch()` or `runner.finally()` + * unless you really need a digest to kick off afterwards. + * + * Keep in mind that, to make this easier, ngAnimate has tweaked the JS animations API to recognize when a runner instance is returned from $animateCss + * (so there is no need to call `runner.done(doneFn)` inside of your JavaScript animation code). + * Check the {@link ngAnimate.$animateCss#usage animation code above} to see how this works. + * + * @param {DOMElement} element the element that will be animated + * @param {object} options the animation-related options that will be applied during the animation + * + * * `event` - The DOM event (e.g. enter, leave, move). When used, a generated CSS class of `ng-EVENT` and `ng-EVENT-active` will be applied + * to the element during the animation. Multiple events can be provided when spaces are used as a separator. (Note that this will not perform any DOM operation.) + * * `structural` - Indicates that the `ng-` prefix will be added to the event class. Setting to `false` or omitting will turn `ng-EVENT` and + * `ng-EVENT-active` in `EVENT` and `EVENT-active`. Unused if `event` is omitted. + * * `easing` - The CSS easing value that will be applied to the transition or keyframe animation (or both). + * * `transitionStyle` - The raw CSS transition style that will be used (e.g. `1s linear all`). + * * `keyframeStyle` - The raw CSS keyframe animation style that will be used (e.g. `1s my_animation linear`). + * * `from` - The starting CSS styles (a key/value object) that will be applied at the start of the animation. + * * `to` - The ending CSS styles (a key/value object) that will be applied across the animation via a CSS transition. + * * `addClass` - A space separated list of CSS classes that will be added to the element and spread across the animation. + * * `removeClass` - A space separated list of CSS classes that will be removed from the element and spread across the animation. + * * `duration` - A number value representing the total duration of the transition and/or keyframe (note that a value of 1 is 1000ms). If a value of `0` + * is provided then the animation will be skipped entirely. + * * `delay` - A number value representing the total delay of the transition and/or keyframe (note that a value of 1 is 1000ms). If a value of `true` is + * used then whatever delay value is detected from the CSS classes will be mirrored on the elements styles (e.g. by setting delay true then the style value + * of the element will be `transition-delay: DETECTED_VALUE`). Using `true` is useful when you want the CSS classes and inline styles to all share the same + * CSS delay value. + * * `stagger` - A numeric time value representing the delay between successively animated elements + * ({@link ngAnimate#css-staggering-animations Click here to learn how CSS-based staggering works in ngAnimate.}) + * * `staggerIndex` - The numeric index representing the stagger item (e.g. a value of 5 is equal to the sixth item in the stagger; therefore when a + * `stagger` option value of `0.1` is used then there will be a stagger delay of `600ms`) + * * `applyClassesEarly` - Whether or not the classes being added or removed will be used when detecting the animation. This is set by `$animate` when enter/leave/move animations are fired to ensure that the CSS classes are resolved in time. (Note that this will prevent any transitions from occurring on the classes being added and removed.) + * * `cleanupStyles` - Whether or not the provided `from` and `to` styles will be removed once + * the animation is closed. This is useful for when the styles are used purely for the sake of + * the animation and do not have a lasting visual effect on the element (e.g. a collapse and open animation). + * By default this value is set to `false`. + * + * @return {object} an object with start and end methods and details about the animation. + * + * * `start` - The method to start the animation. This will return a `Promise` when called. + * * `end` - This method will cancel the animation and remove all applied CSS classes and styles. + */ +var ONE_SECOND = 1000; +var BASE_TEN = 10; + +var ELAPSED_TIME_MAX_DECIMAL_PLACES = 3; +var CLOSING_TIME_BUFFER = 1.5; + +var DETECT_CSS_PROPERTIES = { + transitionDuration: TRANSITION_DURATION_PROP, + transitionDelay: TRANSITION_DELAY_PROP, + transitionProperty: TRANSITION_PROP + PROPERTY_KEY, + animationDuration: ANIMATION_DURATION_PROP, + animationDelay: ANIMATION_DELAY_PROP, + animationIterationCount: ANIMATION_PROP + ANIMATION_ITERATION_COUNT_KEY +}; + +var DETECT_STAGGER_CSS_PROPERTIES = { + transitionDuration: TRANSITION_DURATION_PROP, + transitionDelay: TRANSITION_DELAY_PROP, + animationDuration: ANIMATION_DURATION_PROP, + animationDelay: ANIMATION_DELAY_PROP +}; + +function getCssKeyframeDurationStyle(duration) { + return [ANIMATION_DURATION_PROP, duration + 's']; +} + +function getCssDelayStyle(delay, isKeyframeAnimation) { + var prop = isKeyframeAnimation ? ANIMATION_DELAY_PROP : TRANSITION_DELAY_PROP; + return [prop, delay + 's']; +} + +function computeCssStyles($window, element, properties) { + var styles = Object.create(null); + var detectedStyles = $window.getComputedStyle(element) || {}; + forEach(properties, function(formalStyleName, actualStyleName) { + var val = detectedStyles[formalStyleName]; + if (val) { + var c = val.charAt(0); + + // only numerical-based values have a negative sign or digit as the first value + if (c === '-' || c === '+' || c >= 0) { + val = parseMaxTime(val); + } + + // by setting this to null in the event that the delay is not set or is set directly as 0 + // then we can still allow for negative values to be used later on and not mistake this + // value for being greater than any other negative value. + if (val === 0) { + val = null; + } + styles[actualStyleName] = val; + } + }); + + return styles; +} + +function parseMaxTime(str) { + var maxValue = 0; + var values = str.split(/\s*,\s*/); + forEach(values, function(value) { + // it's always safe to consider only second values and omit `ms` values since + // getComputedStyle will always handle the conversion for us + if (value.charAt(value.length - 1) == 's') { + value = value.substring(0, value.length - 1); + } + value = parseFloat(value) || 0; + maxValue = maxValue ? Math.max(value, maxValue) : value; + }); + return maxValue; +} + +function truthyTimingValue(val) { + return val === 0 || val != null; +} + +function getCssTransitionDurationStyle(duration, applyOnlyDuration) { + var style = TRANSITION_PROP; + var value = duration + 's'; + if (applyOnlyDuration) { + style += DURATION_KEY; + } else { + value += ' linear all'; + } + return [style, value]; +} + +function createLocalCacheLookup() { + var cache = Object.create(null); + return { + flush: function() { + cache = Object.create(null); + }, + + count: function(key) { + var entry = cache[key]; + return entry ? entry.total : 0; + }, + + get: function(key) { + var entry = cache[key]; + return entry && entry.value; + }, + + put: function(key, value) { + if (!cache[key]) { + cache[key] = { total: 1, value: value }; + } else { + cache[key].total++; + } + } + }; +} + +// we do not reassign an already present style value since +// if we detect the style property value again we may be +// detecting styles that were added via the `from` styles. +// We make use of `isDefined` here since an empty string +// or null value (which is what getPropertyValue will return +// for a non-existing style) will still be marked as a valid +// value for the style (a falsy value implies that the style +// is to be removed at the end of the animation). If we had a simple +// "OR" statement then it would not be enough to catch that. +function registerRestorableStyles(backup, node, properties) { + forEach(properties, function(prop) { + backup[prop] = isDefined(backup[prop]) + ? backup[prop] + : node.style.getPropertyValue(prop); + }); +} + +var $AnimateCssProvider = ['$animateProvider', function($animateProvider) { + var gcsLookup = createLocalCacheLookup(); + var gcsStaggerLookup = createLocalCacheLookup(); + + this.$get = ['$window', '$$jqLite', '$$AnimateRunner', '$timeout', + '$$forceReflow', '$sniffer', '$$rAFScheduler', '$$animateQueue', + function($window, $$jqLite, $$AnimateRunner, $timeout, + $$forceReflow, $sniffer, $$rAFScheduler, $$animateQueue) { + + var applyAnimationClasses = applyAnimationClassesFactory($$jqLite); + + var parentCounter = 0; + function gcsHashFn(node, extraClasses) { + var KEY = "$$ngAnimateParentKey"; + var parentNode = node.parentNode; + var parentID = parentNode[KEY] || (parentNode[KEY] = ++parentCounter); + return parentID + '-' + node.getAttribute('class') + '-' + extraClasses; + } + + function computeCachedCssStyles(node, className, cacheKey, properties) { + var timings = gcsLookup.get(cacheKey); + + if (!timings) { + timings = computeCssStyles($window, node, properties); + if (timings.animationIterationCount === 'infinite') { + timings.animationIterationCount = 1; + } + } + + // we keep putting this in multiple times even though the value and the cacheKey are the same + // because we're keeping an internal tally of how many duplicate animations are detected. + gcsLookup.put(cacheKey, timings); + return timings; + } + + function computeCachedCssStaggerStyles(node, className, cacheKey, properties) { + var stagger; + + // if we have one or more existing matches of matching elements + // containing the same parent + CSS styles (which is how cacheKey works) + // then staggering is possible + if (gcsLookup.count(cacheKey) > 0) { + stagger = gcsStaggerLookup.get(cacheKey); + + if (!stagger) { + var staggerClassName = pendClasses(className, '-stagger'); + + $$jqLite.addClass(node, staggerClassName); + + stagger = computeCssStyles($window, node, properties); + + // force the conversion of a null value to zero incase not set + stagger.animationDuration = Math.max(stagger.animationDuration, 0); + stagger.transitionDuration = Math.max(stagger.transitionDuration, 0); + + $$jqLite.removeClass(node, staggerClassName); + + gcsStaggerLookup.put(cacheKey, stagger); + } + } + + return stagger || {}; + } + + var cancelLastRAFRequest; + var rafWaitQueue = []; + function waitUntilQuiet(callback) { + rafWaitQueue.push(callback); + $$rAFScheduler.waitUntilQuiet(function() { + gcsLookup.flush(); + gcsStaggerLookup.flush(); + + // DO NOT REMOVE THIS LINE OR REFACTOR OUT THE `pageWidth` variable. + // PLEASE EXAMINE THE `$$forceReflow` service to understand why. + var pageWidth = $$forceReflow(); + + // we use a for loop to ensure that if the queue is changed + // during this looping then it will consider new requests + for (var i = 0; i < rafWaitQueue.length; i++) { + rafWaitQueue[i](pageWidth); + } + rafWaitQueue.length = 0; + }); + } + + function computeTimings(node, className, cacheKey) { + var timings = computeCachedCssStyles(node, className, cacheKey, DETECT_CSS_PROPERTIES); + var aD = timings.animationDelay; + var tD = timings.transitionDelay; + timings.maxDelay = aD && tD + ? Math.max(aD, tD) + : (aD || tD); + timings.maxDuration = Math.max( + timings.animationDuration * timings.animationIterationCount, + timings.transitionDuration); + + return timings; + } + + return function init(element, initialOptions) { + // all of the animation functions should create + // a copy of the options data, however, if a + // parent service has already created a copy then + // we should stick to using that + var options = initialOptions || {}; + if (!options.$$prepared) { + options = prepareAnimationOptions(copy(options)); + } + + var restoreStyles = {}; + var node = getDomNode(element); + if (!node + || !node.parentNode + || !$$animateQueue.enabled()) { + return closeAndReturnNoopAnimator(); + } + + var temporaryStyles = []; + var classes = element.attr('class'); + var styles = packageStyles(options); + var animationClosed; + var animationPaused; + var animationCompleted; + var runner; + var runnerHost; + var maxDelay; + var maxDelayTime; + var maxDuration; + var maxDurationTime; + var startTime; + var events = []; + + if (options.duration === 0 || (!$sniffer.animations && !$sniffer.transitions)) { + return closeAndReturnNoopAnimator(); + } + + var method = options.event && isArray(options.event) + ? options.event.join(' ') + : options.event; + + var isStructural = method && options.structural; + var structuralClassName = ''; + var addRemoveClassName = ''; + + if (isStructural) { + structuralClassName = pendClasses(method, EVENT_CLASS_PREFIX, true); + } else if (method) { + structuralClassName = method; + } + + if (options.addClass) { + addRemoveClassName += pendClasses(options.addClass, ADD_CLASS_SUFFIX); + } + + if (options.removeClass) { + if (addRemoveClassName.length) { + addRemoveClassName += ' '; + } + addRemoveClassName += pendClasses(options.removeClass, REMOVE_CLASS_SUFFIX); + } + + // there may be a situation where a structural animation is combined together + // with CSS classes that need to resolve before the animation is computed. + // However this means that there is no explicit CSS code to block the animation + // from happening (by setting 0s none in the class name). If this is the case + // we need to apply the classes before the first rAF so we know to continue if + // there actually is a detected transition or keyframe animation + if (options.applyClassesEarly && addRemoveClassName.length) { + applyAnimationClasses(element, options); + } + + var preparationClasses = [structuralClassName, addRemoveClassName].join(' ').trim(); + var fullClassName = classes + ' ' + preparationClasses; + var activeClasses = pendClasses(preparationClasses, ACTIVE_CLASS_SUFFIX); + var hasToStyles = styles.to && Object.keys(styles.to).length > 0; + var containsKeyframeAnimation = (options.keyframeStyle || '').length > 0; + + // there is no way we can trigger an animation if no styles and + // no classes are being applied which would then trigger a transition, + // unless there a is raw keyframe value that is applied to the element. + if (!containsKeyframeAnimation + && !hasToStyles + && !preparationClasses) { + return closeAndReturnNoopAnimator(); + } + + var cacheKey, stagger; + if (options.stagger > 0) { + var staggerVal = parseFloat(options.stagger); + stagger = { + transitionDelay: staggerVal, + animationDelay: staggerVal, + transitionDuration: 0, + animationDuration: 0 + }; + } else { + cacheKey = gcsHashFn(node, fullClassName); + stagger = computeCachedCssStaggerStyles(node, preparationClasses, cacheKey, DETECT_STAGGER_CSS_PROPERTIES); + } + + if (!options.$$skipPreparationClasses) { + $$jqLite.addClass(element, preparationClasses); + } + + var applyOnlyDuration; + + if (options.transitionStyle) { + var transitionStyle = [TRANSITION_PROP, options.transitionStyle]; + applyInlineStyle(node, transitionStyle); + temporaryStyles.push(transitionStyle); + } + + if (options.duration >= 0) { + applyOnlyDuration = node.style[TRANSITION_PROP].length > 0; + var durationStyle = getCssTransitionDurationStyle(options.duration, applyOnlyDuration); + + // we set the duration so that it will be picked up by getComputedStyle later + applyInlineStyle(node, durationStyle); + temporaryStyles.push(durationStyle); + } + + if (options.keyframeStyle) { + var keyframeStyle = [ANIMATION_PROP, options.keyframeStyle]; + applyInlineStyle(node, keyframeStyle); + temporaryStyles.push(keyframeStyle); + } + + var itemIndex = stagger + ? options.staggerIndex >= 0 + ? options.staggerIndex + : gcsLookup.count(cacheKey) + : 0; + + var isFirst = itemIndex === 0; + + // this is a pre-emptive way of forcing the setup classes to be added and applied INSTANTLY + // without causing any combination of transitions to kick in. By adding a negative delay value + // it forces the setup class' transition to end immediately. We later then remove the negative + // transition delay to allow for the transition to naturally do it's thing. The beauty here is + // that if there is no transition defined then nothing will happen and this will also allow + // other transitions to be stacked on top of each other without any chopping them out. + if (isFirst && !options.skipBlocking) { + blockTransitions(node, SAFE_FAST_FORWARD_DURATION_VALUE); + } + + var timings = computeTimings(node, fullClassName, cacheKey); + var relativeDelay = timings.maxDelay; + maxDelay = Math.max(relativeDelay, 0); + maxDuration = timings.maxDuration; + + var flags = {}; + flags.hasTransitions = timings.transitionDuration > 0; + flags.hasAnimations = timings.animationDuration > 0; + flags.hasTransitionAll = flags.hasTransitions && timings.transitionProperty == 'all'; + flags.applyTransitionDuration = hasToStyles && ( + (flags.hasTransitions && !flags.hasTransitionAll) + || (flags.hasAnimations && !flags.hasTransitions)); + flags.applyAnimationDuration = options.duration && flags.hasAnimations; + flags.applyTransitionDelay = truthyTimingValue(options.delay) && (flags.applyTransitionDuration || flags.hasTransitions); + flags.applyAnimationDelay = truthyTimingValue(options.delay) && flags.hasAnimations; + flags.recalculateTimingStyles = addRemoveClassName.length > 0; + + if (flags.applyTransitionDuration || flags.applyAnimationDuration) { + maxDuration = options.duration ? parseFloat(options.duration) : maxDuration; + + if (flags.applyTransitionDuration) { + flags.hasTransitions = true; + timings.transitionDuration = maxDuration; + applyOnlyDuration = node.style[TRANSITION_PROP + PROPERTY_KEY].length > 0; + temporaryStyles.push(getCssTransitionDurationStyle(maxDuration, applyOnlyDuration)); + } + + if (flags.applyAnimationDuration) { + flags.hasAnimations = true; + timings.animationDuration = maxDuration; + temporaryStyles.push(getCssKeyframeDurationStyle(maxDuration)); + } + } + + if (maxDuration === 0 && !flags.recalculateTimingStyles) { + return closeAndReturnNoopAnimator(); + } + + if (options.delay != null) { + var delayStyle; + if (typeof options.delay !== "boolean") { + delayStyle = parseFloat(options.delay); + // number in options.delay means we have to recalculate the delay for the closing timeout + maxDelay = Math.max(delayStyle, 0); + } + + if (flags.applyTransitionDelay) { + temporaryStyles.push(getCssDelayStyle(delayStyle)); + } + + if (flags.applyAnimationDelay) { + temporaryStyles.push(getCssDelayStyle(delayStyle, true)); + } + } + + // we need to recalculate the delay value since we used a pre-emptive negative + // delay value and the delay value is required for the final event checking. This + // property will ensure that this will happen after the RAF phase has passed. + if (options.duration == null && timings.transitionDuration > 0) { + flags.recalculateTimingStyles = flags.recalculateTimingStyles || isFirst; + } + + maxDelayTime = maxDelay * ONE_SECOND; + maxDurationTime = maxDuration * ONE_SECOND; + if (!options.skipBlocking) { + flags.blockTransition = timings.transitionDuration > 0; + flags.blockKeyframeAnimation = timings.animationDuration > 0 && + stagger.animationDelay > 0 && + stagger.animationDuration === 0; + } + + if (options.from) { + if (options.cleanupStyles) { + registerRestorableStyles(restoreStyles, node, Object.keys(options.from)); + } + applyAnimationFromStyles(element, options); + } + + if (flags.blockTransition || flags.blockKeyframeAnimation) { + applyBlocking(maxDuration); + } else if (!options.skipBlocking) { + blockTransitions(node, false); + } + + // TODO(matsko): for 1.5 change this code to have an animator object for better debugging + return { + $$willAnimate: true, + end: endFn, + start: function() { + if (animationClosed) return; + + runnerHost = { + end: endFn, + cancel: cancelFn, + resume: null, //this will be set during the start() phase + pause: null + }; + + runner = new $$AnimateRunner(runnerHost); + + waitUntilQuiet(start); + + // we don't have access to pause/resume the animation + // since it hasn't run yet. AnimateRunner will therefore + // set noop functions for resume and pause and they will + // later be overridden once the animation is triggered + return runner; + } + }; + + function endFn() { + close(); + } + + function cancelFn() { + close(true); + } + + function close(rejected) { // jshint ignore:line + // if the promise has been called already then we shouldn't close + // the animation again + if (animationClosed || (animationCompleted && animationPaused)) return; + animationClosed = true; + animationPaused = false; + + if (!options.$$skipPreparationClasses) { + $$jqLite.removeClass(element, preparationClasses); + } + $$jqLite.removeClass(element, activeClasses); + + blockKeyframeAnimations(node, false); + blockTransitions(node, false); + + forEach(temporaryStyles, function(entry) { + // There is only one way to remove inline style properties entirely from elements. + // By using `removeProperty` this works, but we need to convert camel-cased CSS + // styles down to hyphenated values. + node.style[entry[0]] = ''; + }); + + applyAnimationClasses(element, options); + applyAnimationStyles(element, options); + + if (Object.keys(restoreStyles).length) { + forEach(restoreStyles, function(value, prop) { + value ? node.style.setProperty(prop, value) + : node.style.removeProperty(prop); + }); + } + + // the reason why we have this option is to allow a synchronous closing callback + // that is fired as SOON as the animation ends (when the CSS is removed) or if + // the animation never takes off at all. A good example is a leave animation since + // the element must be removed just after the animation is over or else the element + // will appear on screen for one animation frame causing an overbearing flicker. + if (options.onDone) { + options.onDone(); + } + + if (events && events.length) { + // Remove the transitionend / animationend listener(s) + element.off(events.join(' '), onAnimationProgress); + } + + //Cancel the fallback closing timeout and remove the timer data + var animationTimerData = element.data(ANIMATE_TIMER_KEY); + if (animationTimerData) { + $timeout.cancel(animationTimerData[0].timer); + element.removeData(ANIMATE_TIMER_KEY); + } + + // if the preparation function fails then the promise is not setup + if (runner) { + runner.complete(!rejected); + } + } + + function applyBlocking(duration) { + if (flags.blockTransition) { + blockTransitions(node, duration); + } + + if (flags.blockKeyframeAnimation) { + blockKeyframeAnimations(node, !!duration); + } + } + + function closeAndReturnNoopAnimator() { + runner = new $$AnimateRunner({ + end: endFn, + cancel: cancelFn + }); + + // should flush the cache animation + waitUntilQuiet(noop); + close(); + + return { + $$willAnimate: false, + start: function() { + return runner; + }, + end: endFn + }; + } + + function onAnimationProgress(event) { + event.stopPropagation(); + var ev = event.originalEvent || event; + + // we now always use `Date.now()` due to the recent changes with + // event.timeStamp in Firefox, Webkit and Chrome (see #13494 for more info) + var timeStamp = ev.$manualTimeStamp || Date.now(); + + /* Firefox (or possibly just Gecko) likes to not round values up + * when a ms measurement is used for the animation */ + var elapsedTime = parseFloat(ev.elapsedTime.toFixed(ELAPSED_TIME_MAX_DECIMAL_PLACES)); + + /* $manualTimeStamp is a mocked timeStamp value which is set + * within browserTrigger(). This is only here so that tests can + * mock animations properly. Real events fallback to event.timeStamp, + * or, if they don't, then a timeStamp is automatically created for them. + * We're checking to see if the timeStamp surpasses the expected delay, + * but we're using elapsedTime instead of the timeStamp on the 2nd + * pre-condition since animationPauseds sometimes close off early */ + if (Math.max(timeStamp - startTime, 0) >= maxDelayTime && elapsedTime >= maxDuration) { + // we set this flag to ensure that if the transition is paused then, when resumed, + // the animation will automatically close itself since transitions cannot be paused. + animationCompleted = true; + close(); + } + } + + function start() { + if (animationClosed) return; + if (!node.parentNode) { + close(); + return; + } + + // even though we only pause keyframe animations here the pause flag + // will still happen when transitions are used. Only the transition will + // not be paused since that is not possible. If the animation ends when + // paused then it will not complete until unpaused or cancelled. + var playPause = function(playAnimation) { + if (!animationCompleted) { + animationPaused = !playAnimation; + if (timings.animationDuration) { + var value = blockKeyframeAnimations(node, animationPaused); + animationPaused + ? temporaryStyles.push(value) + : removeFromArray(temporaryStyles, value); + } + } else if (animationPaused && playAnimation) { + animationPaused = false; + close(); + } + }; + + // checking the stagger duration prevents an accidentally cascade of the CSS delay style + // being inherited from the parent. If the transition duration is zero then we can safely + // rely that the delay value is an intentional stagger delay style. + var maxStagger = itemIndex > 0 + && ((timings.transitionDuration && stagger.transitionDuration === 0) || + (timings.animationDuration && stagger.animationDuration === 0)) + && Math.max(stagger.animationDelay, stagger.transitionDelay); + if (maxStagger) { + $timeout(triggerAnimationStart, + Math.floor(maxStagger * itemIndex * ONE_SECOND), + false); + } else { + triggerAnimationStart(); + } + + // this will decorate the existing promise runner with pause/resume methods + runnerHost.resume = function() { + playPause(true); + }; + + runnerHost.pause = function() { + playPause(false); + }; + + function triggerAnimationStart() { + // just incase a stagger animation kicks in when the animation + // itself was cancelled entirely + if (animationClosed) return; + + applyBlocking(false); + + forEach(temporaryStyles, function(entry) { + var key = entry[0]; + var value = entry[1]; + node.style[key] = value; + }); + + applyAnimationClasses(element, options); + $$jqLite.addClass(element, activeClasses); + + if (flags.recalculateTimingStyles) { + fullClassName = node.className + ' ' + preparationClasses; + cacheKey = gcsHashFn(node, fullClassName); + + timings = computeTimings(node, fullClassName, cacheKey); + relativeDelay = timings.maxDelay; + maxDelay = Math.max(relativeDelay, 0); + maxDuration = timings.maxDuration; + + if (maxDuration === 0) { + close(); + return; + } + + flags.hasTransitions = timings.transitionDuration > 0; + flags.hasAnimations = timings.animationDuration > 0; + } + + if (flags.applyAnimationDelay) { + relativeDelay = typeof options.delay !== "boolean" && truthyTimingValue(options.delay) + ? parseFloat(options.delay) + : relativeDelay; + + maxDelay = Math.max(relativeDelay, 0); + timings.animationDelay = relativeDelay; + delayStyle = getCssDelayStyle(relativeDelay, true); + temporaryStyles.push(delayStyle); + node.style[delayStyle[0]] = delayStyle[1]; + } + + maxDelayTime = maxDelay * ONE_SECOND; + maxDurationTime = maxDuration * ONE_SECOND; + + if (options.easing) { + var easeProp, easeVal = options.easing; + if (flags.hasTransitions) { + easeProp = TRANSITION_PROP + TIMING_KEY; + temporaryStyles.push([easeProp, easeVal]); + node.style[easeProp] = easeVal; + } + if (flags.hasAnimations) { + easeProp = ANIMATION_PROP + TIMING_KEY; + temporaryStyles.push([easeProp, easeVal]); + node.style[easeProp] = easeVal; + } + } + + if (timings.transitionDuration) { + events.push(TRANSITIONEND_EVENT); + } + + if (timings.animationDuration) { + events.push(ANIMATIONEND_EVENT); + } + + startTime = Date.now(); + var timerTime = maxDelayTime + CLOSING_TIME_BUFFER * maxDurationTime; + var endTime = startTime + timerTime; + + var animationsData = element.data(ANIMATE_TIMER_KEY) || []; + var setupFallbackTimer = true; + if (animationsData.length) { + var currentTimerData = animationsData[0]; + setupFallbackTimer = endTime > currentTimerData.expectedEndTime; + if (setupFallbackTimer) { + $timeout.cancel(currentTimerData.timer); + } else { + animationsData.push(close); + } + } + + if (setupFallbackTimer) { + var timer = $timeout(onAnimationExpired, timerTime, false); + animationsData[0] = { + timer: timer, + expectedEndTime: endTime + }; + animationsData.push(close); + element.data(ANIMATE_TIMER_KEY, animationsData); + } + + if (events.length) { + element.on(events.join(' '), onAnimationProgress); + } + + if (options.to) { + if (options.cleanupStyles) { + registerRestorableStyles(restoreStyles, node, Object.keys(options.to)); + } + applyAnimationToStyles(element, options); + } + } + + function onAnimationExpired() { + var animationsData = element.data(ANIMATE_TIMER_KEY); + + // this will be false in the event that the element was + // removed from the DOM (via a leave animation or something + // similar) + if (animationsData) { + for (var i = 1; i < animationsData.length; i++) { + animationsData[i](); + } + element.removeData(ANIMATE_TIMER_KEY); + } + } + } + }; + }]; +}]; + +var $$AnimateCssDriverProvider = ['$$animationProvider', function($$animationProvider) { + $$animationProvider.drivers.push('$$animateCssDriver'); + + var NG_ANIMATE_SHIM_CLASS_NAME = 'ng-animate-shim'; + var NG_ANIMATE_ANCHOR_CLASS_NAME = 'ng-anchor'; + + var NG_OUT_ANCHOR_CLASS_NAME = 'ng-anchor-out'; + var NG_IN_ANCHOR_CLASS_NAME = 'ng-anchor-in'; + + function isDocumentFragment(node) { + return node.parentNode && node.parentNode.nodeType === 11; + } + + this.$get = ['$animateCss', '$rootScope', '$$AnimateRunner', '$rootElement', '$sniffer', '$$jqLite', '$document', + function($animateCss, $rootScope, $$AnimateRunner, $rootElement, $sniffer, $$jqLite, $document) { + + // only browsers that support these properties can render animations + if (!$sniffer.animations && !$sniffer.transitions) return noop; + + var bodyNode = $document[0].body; + var rootNode = getDomNode($rootElement); + + var rootBodyElement = jqLite( + // this is to avoid using something that exists outside of the body + // we also special case the doc fragment case because our unit test code + // appends the $rootElement to the body after the app has been bootstrapped + isDocumentFragment(rootNode) || bodyNode.contains(rootNode) ? rootNode : bodyNode + ); + + var applyAnimationClasses = applyAnimationClassesFactory($$jqLite); + + return function initDriverFn(animationDetails) { + return animationDetails.from && animationDetails.to + ? prepareFromToAnchorAnimation(animationDetails.from, + animationDetails.to, + animationDetails.classes, + animationDetails.anchors) + : prepareRegularAnimation(animationDetails); + }; + + function filterCssClasses(classes) { + //remove all the `ng-` stuff + return classes.replace(/\bng-\S+\b/g, ''); + } + + function getUniqueValues(a, b) { + if (isString(a)) a = a.split(' '); + if (isString(b)) b = b.split(' '); + return a.filter(function(val) { + return b.indexOf(val) === -1; + }).join(' '); + } + + function prepareAnchoredAnimation(classes, outAnchor, inAnchor) { + var clone = jqLite(getDomNode(outAnchor).cloneNode(true)); + var startingClasses = filterCssClasses(getClassVal(clone)); + + outAnchor.addClass(NG_ANIMATE_SHIM_CLASS_NAME); + inAnchor.addClass(NG_ANIMATE_SHIM_CLASS_NAME); + + clone.addClass(NG_ANIMATE_ANCHOR_CLASS_NAME); + + rootBodyElement.append(clone); + + var animatorIn, animatorOut = prepareOutAnimation(); + + // the user may not end up using the `out` animation and + // only making use of the `in` animation or vice-versa. + // In either case we should allow this and not assume the + // animation is over unless both animations are not used. + if (!animatorOut) { + animatorIn = prepareInAnimation(); + if (!animatorIn) { + return end(); + } + } + + var startingAnimator = animatorOut || animatorIn; + + return { + start: function() { + var runner; + + var currentAnimation = startingAnimator.start(); + currentAnimation.done(function() { + currentAnimation = null; + if (!animatorIn) { + animatorIn = prepareInAnimation(); + if (animatorIn) { + currentAnimation = animatorIn.start(); + currentAnimation.done(function() { + currentAnimation = null; + end(); + runner.complete(); + }); + return currentAnimation; + } + } + // in the event that there is no `in` animation + end(); + runner.complete(); + }); + + runner = new $$AnimateRunner({ + end: endFn, + cancel: endFn + }); + + return runner; + + function endFn() { + if (currentAnimation) { + currentAnimation.end(); + } + } + } + }; + + function calculateAnchorStyles(anchor) { + var styles = {}; + + var coords = getDomNode(anchor).getBoundingClientRect(); + + // we iterate directly since safari messes up and doesn't return + // all the keys for the coords object when iterated + forEach(['width','height','top','left'], function(key) { + var value = coords[key]; + switch (key) { + case 'top': + value += bodyNode.scrollTop; + break; + case 'left': + value += bodyNode.scrollLeft; + break; + } + styles[key] = Math.floor(value) + 'px'; + }); + return styles; + } + + function prepareOutAnimation() { + var animator = $animateCss(clone, { + addClass: NG_OUT_ANCHOR_CLASS_NAME, + delay: true, + from: calculateAnchorStyles(outAnchor) + }); + + // read the comment within `prepareRegularAnimation` to understand + // why this check is necessary + return animator.$$willAnimate ? animator : null; + } + + function getClassVal(element) { + return element.attr('class') || ''; + } + + function prepareInAnimation() { + var endingClasses = filterCssClasses(getClassVal(inAnchor)); + var toAdd = getUniqueValues(endingClasses, startingClasses); + var toRemove = getUniqueValues(startingClasses, endingClasses); + + var animator = $animateCss(clone, { + to: calculateAnchorStyles(inAnchor), + addClass: NG_IN_ANCHOR_CLASS_NAME + ' ' + toAdd, + removeClass: NG_OUT_ANCHOR_CLASS_NAME + ' ' + toRemove, + delay: true + }); + + // read the comment within `prepareRegularAnimation` to understand + // why this check is necessary + return animator.$$willAnimate ? animator : null; + } + + function end() { + clone.remove(); + outAnchor.removeClass(NG_ANIMATE_SHIM_CLASS_NAME); + inAnchor.removeClass(NG_ANIMATE_SHIM_CLASS_NAME); + } + } + + function prepareFromToAnchorAnimation(from, to, classes, anchors) { + var fromAnimation = prepareRegularAnimation(from, noop); + var toAnimation = prepareRegularAnimation(to, noop); + + var anchorAnimations = []; + forEach(anchors, function(anchor) { + var outElement = anchor['out']; + var inElement = anchor['in']; + var animator = prepareAnchoredAnimation(classes, outElement, inElement); + if (animator) { + anchorAnimations.push(animator); + } + }); + + // no point in doing anything when there are no elements to animate + if (!fromAnimation && !toAnimation && anchorAnimations.length === 0) return; + + return { + start: function() { + var animationRunners = []; + + if (fromAnimation) { + animationRunners.push(fromAnimation.start()); + } + + if (toAnimation) { + animationRunners.push(toAnimation.start()); + } + + forEach(anchorAnimations, function(animation) { + animationRunners.push(animation.start()); + }); + + var runner = new $$AnimateRunner({ + end: endFn, + cancel: endFn // CSS-driven animations cannot be cancelled, only ended + }); + + $$AnimateRunner.all(animationRunners, function(status) { + runner.complete(status); + }); + + return runner; + + function endFn() { + forEach(animationRunners, function(runner) { + runner.end(); + }); + } + } + }; + } + + function prepareRegularAnimation(animationDetails) { + var element = animationDetails.element; + var options = animationDetails.options || {}; + + if (animationDetails.structural) { + options.event = animationDetails.event; + options.structural = true; + options.applyClassesEarly = true; + + // we special case the leave animation since we want to ensure that + // the element is removed as soon as the animation is over. Otherwise + // a flicker might appear or the element may not be removed at all + if (animationDetails.event === 'leave') { + options.onDone = options.domOperation; + } + } + + // We assign the preparationClasses as the actual animation event since + // the internals of $animateCss will just suffix the event token values + // with `-active` to trigger the animation. + if (options.preparationClasses) { + options.event = concatWithSpace(options.event, options.preparationClasses); + } + + var animator = $animateCss(element, options); + + // the driver lookup code inside of $$animation attempts to spawn a + // driver one by one until a driver returns a.$$willAnimate animator object. + // $animateCss will always return an object, however, it will pass in + // a flag as a hint as to whether an animation was detected or not + return animator.$$willAnimate ? animator : null; + } + }]; +}]; + +// TODO(matsko): use caching here to speed things up for detection +// TODO(matsko): add documentation +// by the time... + +var $$AnimateJsProvider = ['$animateProvider', function($animateProvider) { + this.$get = ['$injector', '$$AnimateRunner', '$$jqLite', + function($injector, $$AnimateRunner, $$jqLite) { + + var applyAnimationClasses = applyAnimationClassesFactory($$jqLite); + // $animateJs(element, 'enter'); + return function(element, event, classes, options) { + var animationClosed = false; + + // the `classes` argument is optional and if it is not used + // then the classes will be resolved from the element's className + // property as well as options.addClass/options.removeClass. + if (arguments.length === 3 && isObject(classes)) { + options = classes; + classes = null; + } + + options = prepareAnimationOptions(options); + if (!classes) { + classes = element.attr('class') || ''; + if (options.addClass) { + classes += ' ' + options.addClass; + } + if (options.removeClass) { + classes += ' ' + options.removeClass; + } + } + + var classesToAdd = options.addClass; + var classesToRemove = options.removeClass; + + // the lookupAnimations function returns a series of animation objects that are + // matched up with one or more of the CSS classes. These animation objects are + // defined via the module.animation factory function. If nothing is detected then + // we don't return anything which then makes $animation query the next driver. + var animations = lookupAnimations(classes); + var before, after; + if (animations.length) { + var afterFn, beforeFn; + if (event == 'leave') { + beforeFn = 'leave'; + afterFn = 'afterLeave'; // TODO(matsko): get rid of this + } else { + beforeFn = 'before' + event.charAt(0).toUpperCase() + event.substr(1); + afterFn = event; + } + + if (event !== 'enter' && event !== 'move') { + before = packageAnimations(element, event, options, animations, beforeFn); + } + after = packageAnimations(element, event, options, animations, afterFn); + } + + // no matching animations + if (!before && !after) return; + + function applyOptions() { + options.domOperation(); + applyAnimationClasses(element, options); + } + + function close() { + animationClosed = true; + applyOptions(); + applyAnimationStyles(element, options); + } + + var runner; + + return { + $$willAnimate: true, + end: function() { + if (runner) { + runner.end(); + } else { + close(); + runner = new $$AnimateRunner(); + runner.complete(true); + } + return runner; + }, + start: function() { + if (runner) { + return runner; + } + + runner = new $$AnimateRunner(); + var closeActiveAnimations; + var chain = []; + + if (before) { + chain.push(function(fn) { + closeActiveAnimations = before(fn); + }); + } + + if (chain.length) { + chain.push(function(fn) { + applyOptions(); + fn(true); + }); + } else { + applyOptions(); + } + + if (after) { + chain.push(function(fn) { + closeActiveAnimations = after(fn); + }); + } + + runner.setHost({ + end: function() { + endAnimations(); + }, + cancel: function() { + endAnimations(true); + } + }); + + $$AnimateRunner.chain(chain, onComplete); + return runner; + + function onComplete(success) { + close(success); + runner.complete(success); + } + + function endAnimations(cancelled) { + if (!animationClosed) { + (closeActiveAnimations || noop)(cancelled); + onComplete(cancelled); + } + } + } + }; + + function executeAnimationFn(fn, element, event, options, onDone) { + var args; + switch (event) { + case 'animate': + args = [element, options.from, options.to, onDone]; + break; + + case 'setClass': + args = [element, classesToAdd, classesToRemove, onDone]; + break; + + case 'addClass': + args = [element, classesToAdd, onDone]; + break; + + case 'removeClass': + args = [element, classesToRemove, onDone]; + break; + + default: + args = [element, onDone]; + break; + } + + args.push(options); + + var value = fn.apply(fn, args); + if (value) { + if (isFunction(value.start)) { + value = value.start(); + } + + if (value instanceof $$AnimateRunner) { + value.done(onDone); + } else if (isFunction(value)) { + // optional onEnd / onCancel callback + return value; + } + } + + return noop; + } + + function groupEventedAnimations(element, event, options, animations, fnName) { + var operations = []; + forEach(animations, function(ani) { + var animation = ani[fnName]; + if (!animation) return; + + // note that all of these animations will run in parallel + operations.push(function() { + var runner; + var endProgressCb; + + var resolved = false; + var onAnimationComplete = function(rejected) { + if (!resolved) { + resolved = true; + (endProgressCb || noop)(rejected); + runner.complete(!rejected); + } + }; + + runner = new $$AnimateRunner({ + end: function() { + onAnimationComplete(); + }, + cancel: function() { + onAnimationComplete(true); + } + }); + + endProgressCb = executeAnimationFn(animation, element, event, options, function(result) { + var cancelled = result === false; + onAnimationComplete(cancelled); + }); + + return runner; + }); + }); + + return operations; + } + + function packageAnimations(element, event, options, animations, fnName) { + var operations = groupEventedAnimations(element, event, options, animations, fnName); + if (operations.length === 0) { + var a,b; + if (fnName === 'beforeSetClass') { + a = groupEventedAnimations(element, 'removeClass', options, animations, 'beforeRemoveClass'); + b = groupEventedAnimations(element, 'addClass', options, animations, 'beforeAddClass'); + } else if (fnName === 'setClass') { + a = groupEventedAnimations(element, 'removeClass', options, animations, 'removeClass'); + b = groupEventedAnimations(element, 'addClass', options, animations, 'addClass'); + } + + if (a) { + operations = operations.concat(a); + } + if (b) { + operations = operations.concat(b); + } + } + + if (operations.length === 0) return; + + // TODO(matsko): add documentation + return function startAnimation(callback) { + var runners = []; + if (operations.length) { + forEach(operations, function(animateFn) { + runners.push(animateFn()); + }); + } + + runners.length ? $$AnimateRunner.all(runners, callback) : callback(); + + return function endFn(reject) { + forEach(runners, function(runner) { + reject ? runner.cancel() : runner.end(); + }); + }; + }; + } + }; + + function lookupAnimations(classes) { + classes = isArray(classes) ? classes : classes.split(' '); + var matches = [], flagMap = {}; + for (var i=0; i < classes.length; i++) { + var klass = classes[i], + animationFactory = $animateProvider.$$registeredAnimations[klass]; + if (animationFactory && !flagMap[klass]) { + matches.push($injector.get(animationFactory)); + flagMap[klass] = true; + } + } + return matches; + } + }]; +}]; + +var $$AnimateJsDriverProvider = ['$$animationProvider', function($$animationProvider) { + $$animationProvider.drivers.push('$$animateJsDriver'); + this.$get = ['$$animateJs', '$$AnimateRunner', function($$animateJs, $$AnimateRunner) { + return function initDriverFn(animationDetails) { + if (animationDetails.from && animationDetails.to) { + var fromAnimation = prepareAnimation(animationDetails.from); + var toAnimation = prepareAnimation(animationDetails.to); + if (!fromAnimation && !toAnimation) return; + + return { + start: function() { + var animationRunners = []; + + if (fromAnimation) { + animationRunners.push(fromAnimation.start()); + } + + if (toAnimation) { + animationRunners.push(toAnimation.start()); + } + + $$AnimateRunner.all(animationRunners, done); + + var runner = new $$AnimateRunner({ + end: endFnFactory(), + cancel: endFnFactory() + }); + + return runner; + + function endFnFactory() { + return function() { + forEach(animationRunners, function(runner) { + // at this point we cannot cancel animations for groups just yet. 1.5+ + runner.end(); + }); + }; + } + + function done(status) { + runner.complete(status); + } + } + }; + } else { + return prepareAnimation(animationDetails); + } + }; + + function prepareAnimation(animationDetails) { + // TODO(matsko): make sure to check for grouped animations and delegate down to normal animations + var element = animationDetails.element; + var event = animationDetails.event; + var options = animationDetails.options; + var classes = animationDetails.classes; + return $$animateJs(element, event, classes, options); + } + }]; +}]; + +var NG_ANIMATE_ATTR_NAME = 'data-ng-animate'; +var NG_ANIMATE_PIN_DATA = '$ngAnimatePin'; +var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) { + var PRE_DIGEST_STATE = 1; + var RUNNING_STATE = 2; + var ONE_SPACE = ' '; + + var rules = this.rules = { + skip: [], + cancel: [], + join: [] + }; + + function makeTruthyCssClassMap(classString) { + if (!classString) { + return null; + } + + var keys = classString.split(ONE_SPACE); + var map = Object.create(null); + + forEach(keys, function(key) { + map[key] = true; + }); + return map; + } + + function hasMatchingClasses(newClassString, currentClassString) { + if (newClassString && currentClassString) { + var currentClassMap = makeTruthyCssClassMap(currentClassString); + return newClassString.split(ONE_SPACE).some(function(className) { + return currentClassMap[className]; + }); + } + } + + function isAllowed(ruleType, element, currentAnimation, previousAnimation) { + return rules[ruleType].some(function(fn) { + return fn(element, currentAnimation, previousAnimation); + }); + } + + function hasAnimationClasses(animation, and) { + var a = (animation.addClass || '').length > 0; + var b = (animation.removeClass || '').length > 0; + return and ? a && b : a || b; + } + + rules.join.push(function(element, newAnimation, currentAnimation) { + // if the new animation is class-based then we can just tack that on + return !newAnimation.structural && hasAnimationClasses(newAnimation); + }); + + rules.skip.push(function(element, newAnimation, currentAnimation) { + // there is no need to animate anything if no classes are being added and + // there is no structural animation that will be triggered + return !newAnimation.structural && !hasAnimationClasses(newAnimation); + }); + + rules.skip.push(function(element, newAnimation, currentAnimation) { + // why should we trigger a new structural animation if the element will + // be removed from the DOM anyway? + return currentAnimation.event == 'leave' && newAnimation.structural; + }); + + rules.skip.push(function(element, newAnimation, currentAnimation) { + // if there is an ongoing current animation then don't even bother running the class-based animation + return currentAnimation.structural && currentAnimation.state === RUNNING_STATE && !newAnimation.structural; + }); + + rules.cancel.push(function(element, newAnimation, currentAnimation) { + // there can never be two structural animations running at the same time + return currentAnimation.structural && newAnimation.structural; + }); + + rules.cancel.push(function(element, newAnimation, currentAnimation) { + // if the previous animation is already running, but the new animation will + // be triggered, but the new animation is structural + return currentAnimation.state === RUNNING_STATE && newAnimation.structural; + }); + + rules.cancel.push(function(element, newAnimation, currentAnimation) { + var nA = newAnimation.addClass; + var nR = newAnimation.removeClass; + var cA = currentAnimation.addClass; + var cR = currentAnimation.removeClass; + + // early detection to save the global CPU shortage :) + if ((isUndefined(nA) && isUndefined(nR)) || (isUndefined(cA) && isUndefined(cR))) { + return false; + } + + return hasMatchingClasses(nA, cR) || hasMatchingClasses(nR, cA); + }); + + this.$get = ['$$rAF', '$rootScope', '$rootElement', '$document', '$$HashMap', + '$$animation', '$$AnimateRunner', '$templateRequest', '$$jqLite', '$$forceReflow', + function($$rAF, $rootScope, $rootElement, $document, $$HashMap, + $$animation, $$AnimateRunner, $templateRequest, $$jqLite, $$forceReflow) { + + var activeAnimationsLookup = new $$HashMap(); + var disabledElementsLookup = new $$HashMap(); + var animationsEnabled = null; + + function postDigestTaskFactory() { + var postDigestCalled = false; + return function(fn) { + // we only issue a call to postDigest before + // it has first passed. This prevents any callbacks + // from not firing once the animation has completed + // since it will be out of the digest cycle. + if (postDigestCalled) { + fn(); + } else { + $rootScope.$$postDigest(function() { + postDigestCalled = true; + fn(); + }); + } + }; + } + + // Wait until all directive and route-related templates are downloaded and + // compiled. The $templateRequest.totalPendingRequests variable keeps track of + // all of the remote templates being currently downloaded. If there are no + // templates currently downloading then the watcher will still fire anyway. + var deregisterWatch = $rootScope.$watch( + function() { return $templateRequest.totalPendingRequests === 0; }, + function(isEmpty) { + if (!isEmpty) return; + deregisterWatch(); + + // Now that all templates have been downloaded, $animate will wait until + // the post digest queue is empty before enabling animations. By having two + // calls to $postDigest calls we can ensure that the flag is enabled at the + // very end of the post digest queue. Since all of the animations in $animate + // use $postDigest, it's important that the code below executes at the end. + // This basically means that the page is fully downloaded and compiled before + // any animations are triggered. + $rootScope.$$postDigest(function() { + $rootScope.$$postDigest(function() { + // we check for null directly in the event that the application already called + // .enabled() with whatever arguments that it provided it with + if (animationsEnabled === null) { + animationsEnabled = true; + } + }); + }); + } + ); + + var callbackRegistry = {}; + + // remember that the classNameFilter is set during the provider/config + // stage therefore we can optimize here and setup a helper function + var classNameFilter = $animateProvider.classNameFilter(); + var isAnimatableClassName = !classNameFilter + ? function() { return true; } + : function(className) { + return classNameFilter.test(className); + }; + + var applyAnimationClasses = applyAnimationClassesFactory($$jqLite); + + function normalizeAnimationDetails(element, animation) { + return mergeAnimationDetails(element, animation, {}); + } + + // IE9-11 has no method "contains" in SVG element and in Node.prototype. Bug #10259. + var contains = Node.prototype.contains || function(arg) { + // jshint bitwise: false + return this === arg || !!(this.compareDocumentPosition(arg) & 16); + // jshint bitwise: true + }; + + function findCallbacks(parent, element, event) { + var targetNode = getDomNode(element); + var targetParentNode = getDomNode(parent); + + var matches = []; + var entries = callbackRegistry[event]; + if (entries) { + forEach(entries, function(entry) { + if (contains.call(entry.node, targetNode)) { + matches.push(entry.callback); + } else if (event === 'leave' && contains.call(entry.node, targetParentNode)) { + matches.push(entry.callback); + } + }); + } + + return matches; + } + + return { + on: function(event, container, callback) { + var node = extractElementNode(container); + callbackRegistry[event] = callbackRegistry[event] || []; + callbackRegistry[event].push({ + node: node, + callback: callback + }); + }, + + off: function(event, container, callback) { + var entries = callbackRegistry[event]; + if (!entries) return; + + callbackRegistry[event] = arguments.length === 1 + ? null + : filterFromRegistry(entries, container, callback); + + function filterFromRegistry(list, matchContainer, matchCallback) { + var containerNode = extractElementNode(matchContainer); + return list.filter(function(entry) { + var isMatch = entry.node === containerNode && + (!matchCallback || entry.callback === matchCallback); + return !isMatch; + }); + } + }, + + pin: function(element, parentElement) { + assertArg(isElement(element), 'element', 'not an element'); + assertArg(isElement(parentElement), 'parentElement', 'not an element'); + element.data(NG_ANIMATE_PIN_DATA, parentElement); + }, + + push: function(element, event, options, domOperation) { + options = options || {}; + options.domOperation = domOperation; + return queueAnimation(element, event, options); + }, + + // this method has four signatures: + // () - global getter + // (bool) - global setter + // (element) - element getter + // (element, bool) - element setter + enabled: function(element, bool) { + var argCount = arguments.length; + + if (argCount === 0) { + // () - Global getter + bool = !!animationsEnabled; + } else { + var hasElement = isElement(element); + + if (!hasElement) { + // (bool) - Global setter + bool = animationsEnabled = !!element; + } else { + var node = getDomNode(element); + var recordExists = disabledElementsLookup.get(node); + + if (argCount === 1) { + // (element) - Element getter + bool = !recordExists; + } else { + // (element, bool) - Element setter + disabledElementsLookup.put(node, !bool); + } + } + } + + return bool; + } + }; + + function queueAnimation(element, event, initialOptions) { + // we always make a copy of the options since + // there should never be any side effects on + // the input data when running `$animateCss`. + var options = copy(initialOptions); + + var node, parent; + element = stripCommentsFromElement(element); + if (element) { + node = getDomNode(element); + parent = element.parent(); + } + + options = prepareAnimationOptions(options); + + // we create a fake runner with a working promise. + // These methods will become available after the digest has passed + var runner = new $$AnimateRunner(); + + // this is used to trigger callbacks in postDigest mode + var runInNextPostDigestOrNow = postDigestTaskFactory(); + + if (isArray(options.addClass)) { + options.addClass = options.addClass.join(' '); + } + + if (options.addClass && !isString(options.addClass)) { + options.addClass = null; + } + + if (isArray(options.removeClass)) { + options.removeClass = options.removeClass.join(' '); + } + + if (options.removeClass && !isString(options.removeClass)) { + options.removeClass = null; + } + + if (options.from && !isObject(options.from)) { + options.from = null; + } + + if (options.to && !isObject(options.to)) { + options.to = null; + } + + // there are situations where a directive issues an animation for + // a jqLite wrapper that contains only comment nodes... If this + // happens then there is no way we can perform an animation + if (!node) { + close(); + return runner; + } + + var className = [node.className, options.addClass, options.removeClass].join(' '); + if (!isAnimatableClassName(className)) { + close(); + return runner; + } + + var isStructural = ['enter', 'move', 'leave'].indexOf(event) >= 0; + + // this is a hard disable of all animations for the application or on + // the element itself, therefore there is no need to continue further + // past this point if not enabled + // Animations are also disabled if the document is currently hidden (page is not visible + // to the user), because browsers slow down or do not flush calls to requestAnimationFrame + var skipAnimations = !animationsEnabled || $document[0].hidden || disabledElementsLookup.get(node); + var existingAnimation = (!skipAnimations && activeAnimationsLookup.get(node)) || {}; + var hasExistingAnimation = !!existingAnimation.state; + + // there is no point in traversing the same collection of parent ancestors if a followup + // animation will be run on the same element that already did all that checking work + if (!skipAnimations && (!hasExistingAnimation || existingAnimation.state != PRE_DIGEST_STATE)) { + skipAnimations = !areAnimationsAllowed(element, parent, event); + } + + if (skipAnimations) { + close(); + return runner; + } + + if (isStructural) { + closeChildAnimations(element); + } + + var newAnimation = { + structural: isStructural, + element: element, + event: event, + addClass: options.addClass, + removeClass: options.removeClass, + close: close, + options: options, + runner: runner + }; + + if (hasExistingAnimation) { + var skipAnimationFlag = isAllowed('skip', element, newAnimation, existingAnimation); + if (skipAnimationFlag) { + if (existingAnimation.state === RUNNING_STATE) { + close(); + return runner; + } else { + mergeAnimationDetails(element, existingAnimation, newAnimation); + return existingAnimation.runner; + } + } + var cancelAnimationFlag = isAllowed('cancel', element, newAnimation, existingAnimation); + if (cancelAnimationFlag) { + if (existingAnimation.state === RUNNING_STATE) { + // this will end the animation right away and it is safe + // to do so since the animation is already running and the + // runner callback code will run in async + existingAnimation.runner.end(); + } else if (existingAnimation.structural) { + // this means that the animation is queued into a digest, but + // hasn't started yet. Therefore it is safe to run the close + // method which will call the runner methods in async. + existingAnimation.close(); + } else { + // this will merge the new animation options into existing animation options + mergeAnimationDetails(element, existingAnimation, newAnimation); + + return existingAnimation.runner; + } + } else { + // a joined animation means that this animation will take over the existing one + // so an example would involve a leave animation taking over an enter. Then when + // the postDigest kicks in the enter will be ignored. + var joinAnimationFlag = isAllowed('join', element, newAnimation, existingAnimation); + if (joinAnimationFlag) { + if (existingAnimation.state === RUNNING_STATE) { + normalizeAnimationDetails(element, newAnimation); + } else { + applyGeneratedPreparationClasses(element, isStructural ? event : null, options); + + event = newAnimation.event = existingAnimation.event; + options = mergeAnimationDetails(element, existingAnimation, newAnimation); + + //we return the same runner since only the option values of this animation will + //be fed into the `existingAnimation`. + return existingAnimation.runner; + } + } + } + } else { + // normalization in this case means that it removes redundant CSS classes that + // already exist (addClass) or do not exist (removeClass) on the element + normalizeAnimationDetails(element, newAnimation); + } + + // when the options are merged and cleaned up we may end up not having to do + // an animation at all, therefore we should check this before issuing a post + // digest callback. Structural animations will always run no matter what. + var isValidAnimation = newAnimation.structural; + if (!isValidAnimation) { + // animate (from/to) can be quickly checked first, otherwise we check if any classes are present + isValidAnimation = (newAnimation.event === 'animate' && Object.keys(newAnimation.options.to || {}).length > 0) + || hasAnimationClasses(newAnimation); + } + + if (!isValidAnimation) { + close(); + clearElementAnimationState(element); + return runner; + } + + // the counter keeps track of cancelled animations + var counter = (existingAnimation.counter || 0) + 1; + newAnimation.counter = counter; + + markElementAnimationState(element, PRE_DIGEST_STATE, newAnimation); + + $rootScope.$$postDigest(function() { + var animationDetails = activeAnimationsLookup.get(node); + var animationCancelled = !animationDetails; + animationDetails = animationDetails || {}; + + // if addClass/removeClass is called before something like enter then the + // registered parent element may not be present. The code below will ensure + // that a final value for parent element is obtained + var parentElement = element.parent() || []; + + // animate/structural/class-based animations all have requirements. Otherwise there + // is no point in performing an animation. The parent node must also be set. + var isValidAnimation = parentElement.length > 0 + && (animationDetails.event === 'animate' + || animationDetails.structural + || hasAnimationClasses(animationDetails)); + + // this means that the previous animation was cancelled + // even if the follow-up animation is the same event + if (animationCancelled || animationDetails.counter !== counter || !isValidAnimation) { + // if another animation did not take over then we need + // to make sure that the domOperation and options are + // handled accordingly + if (animationCancelled) { + applyAnimationClasses(element, options); + applyAnimationStyles(element, options); + } + + // if the event changed from something like enter to leave then we do + // it, otherwise if it's the same then the end result will be the same too + if (animationCancelled || (isStructural && animationDetails.event !== event)) { + options.domOperation(); + runner.end(); + } + + // in the event that the element animation was not cancelled or a follow-up animation + // isn't allowed to animate from here then we need to clear the state of the element + // so that any future animations won't read the expired animation data. + if (!isValidAnimation) { + clearElementAnimationState(element); + } + + return; + } + + // this combined multiple class to addClass / removeClass into a setClass event + // so long as a structural event did not take over the animation + event = !animationDetails.structural && hasAnimationClasses(animationDetails, true) + ? 'setClass' + : animationDetails.event; + + markElementAnimationState(element, RUNNING_STATE); + var realRunner = $$animation(element, event, animationDetails.options); + + realRunner.done(function(status) { + close(!status); + var animationDetails = activeAnimationsLookup.get(node); + if (animationDetails && animationDetails.counter === counter) { + clearElementAnimationState(getDomNode(element)); + } + notifyProgress(runner, event, 'close', {}); + }); + + // this will update the runner's flow-control events based on + // the `realRunner` object. + runner.setHost(realRunner); + notifyProgress(runner, event, 'start', {}); + }); + + return runner; + + function notifyProgress(runner, event, phase, data) { + runInNextPostDigestOrNow(function() { + var callbacks = findCallbacks(parent, element, event); + if (callbacks.length) { + // do not optimize this call here to RAF because + // we don't know how heavy the callback code here will + // be and if this code is buffered then this can + // lead to a performance regression. + $$rAF(function() { + forEach(callbacks, function(callback) { + callback(element, phase, data); + }); + }); + } + }); + runner.progress(event, phase, data); + } + + function close(reject) { // jshint ignore:line + clearGeneratedClasses(element, options); + applyAnimationClasses(element, options); + applyAnimationStyles(element, options); + options.domOperation(); + runner.complete(!reject); + } + } + + function closeChildAnimations(element) { + var node = getDomNode(element); + var children = node.querySelectorAll('[' + NG_ANIMATE_ATTR_NAME + ']'); + forEach(children, function(child) { + var state = parseInt(child.getAttribute(NG_ANIMATE_ATTR_NAME)); + var animationDetails = activeAnimationsLookup.get(child); + if (animationDetails) { + switch (state) { + case RUNNING_STATE: + animationDetails.runner.end(); + /* falls through */ + case PRE_DIGEST_STATE: + activeAnimationsLookup.remove(child); + break; + } + } + }); + } + + function clearElementAnimationState(element) { + var node = getDomNode(element); + node.removeAttribute(NG_ANIMATE_ATTR_NAME); + activeAnimationsLookup.remove(node); + } + + function isMatchingElement(nodeOrElmA, nodeOrElmB) { + return getDomNode(nodeOrElmA) === getDomNode(nodeOrElmB); + } + + /** + * This fn returns false if any of the following is true: + * a) animations on any parent element are disabled, and animations on the element aren't explicitly allowed + * b) a parent element has an ongoing structural animation, and animateChildren is false + * c) the element is not a child of the body + * d) the element is not a child of the $rootElement + */ + function areAnimationsAllowed(element, parentElement, event) { + var bodyElement = jqLite($document[0].body); + var bodyElementDetected = isMatchingElement(element, bodyElement) || element[0].nodeName === 'HTML'; + var rootElementDetected = isMatchingElement(element, $rootElement); + var parentAnimationDetected = false; + var animateChildren; + var elementDisabled = disabledElementsLookup.get(getDomNode(element)); + + var parentHost = element.data(NG_ANIMATE_PIN_DATA); + if (parentHost) { + parentElement = parentHost; + } + + while (parentElement && parentElement.length) { + if (!rootElementDetected) { + // angular doesn't want to attempt to animate elements outside of the application + // therefore we need to ensure that the rootElement is an ancestor of the current element + rootElementDetected = isMatchingElement(parentElement, $rootElement); + } + + var parentNode = parentElement[0]; + if (parentNode.nodeType !== ELEMENT_NODE) { + // no point in inspecting the #document element + break; + } + + var details = activeAnimationsLookup.get(parentNode) || {}; + // either an enter, leave or move animation will commence + // therefore we can't allow any animations to take place + // but if a parent animation is class-based then that's ok + if (!parentAnimationDetected) { + var parentElementDisabled = disabledElementsLookup.get(parentNode); + + if (parentElementDisabled === true && elementDisabled !== false) { + // disable animations if the user hasn't explicitly enabled animations on the + // current element + elementDisabled = true; + // element is disabled via parent element, no need to check anything else + break; + } else if (parentElementDisabled === false) { + elementDisabled = false; + } + parentAnimationDetected = details.structural; + } + + if (isUndefined(animateChildren) || animateChildren === true) { + var value = parentElement.data(NG_ANIMATE_CHILDREN_DATA); + if (isDefined(value)) { + animateChildren = value; + } + } + + // there is no need to continue traversing at this point + if (parentAnimationDetected && animateChildren === false) break; + + if (!bodyElementDetected) { + // we also need to ensure that the element is or will be a part of the body element + // otherwise it is pointless to even issue an animation to be rendered + bodyElementDetected = isMatchingElement(parentElement, bodyElement); + } + + if (bodyElementDetected && rootElementDetected) { + // If both body and root have been found, any other checks are pointless, + // as no animation data should live outside the application + break; + } + + if (!rootElementDetected) { + // If no rootElement is detected, check if the parentElement is pinned to another element + parentHost = parentElement.data(NG_ANIMATE_PIN_DATA); + if (parentHost) { + // The pin target element becomes the next parent element + parentElement = parentHost; + continue; + } + } + + parentElement = parentElement.parent(); + } + + var allowAnimation = (!parentAnimationDetected || animateChildren) && elementDisabled !== true; + return allowAnimation && rootElementDetected && bodyElementDetected; + } + + function markElementAnimationState(element, state, details) { + details = details || {}; + details.state = state; + + var node = getDomNode(element); + node.setAttribute(NG_ANIMATE_ATTR_NAME, state); + + var oldValue = activeAnimationsLookup.get(node); + var newValue = oldValue + ? extend(oldValue, details) + : details; + activeAnimationsLookup.put(node, newValue); + } + }]; +}]; + +var $$AnimationProvider = ['$animateProvider', function($animateProvider) { + var NG_ANIMATE_REF_ATTR = 'ng-animate-ref'; + + var drivers = this.drivers = []; + + var RUNNER_STORAGE_KEY = '$$animationRunner'; + + function setRunner(element, runner) { + element.data(RUNNER_STORAGE_KEY, runner); + } + + function removeRunner(element) { + element.removeData(RUNNER_STORAGE_KEY); + } + + function getRunner(element) { + return element.data(RUNNER_STORAGE_KEY); + } + + this.$get = ['$$jqLite', '$rootScope', '$injector', '$$AnimateRunner', '$$HashMap', '$$rAFScheduler', + function($$jqLite, $rootScope, $injector, $$AnimateRunner, $$HashMap, $$rAFScheduler) { + + var animationQueue = []; + var applyAnimationClasses = applyAnimationClassesFactory($$jqLite); + + function sortAnimations(animations) { + var tree = { children: [] }; + var i, lookup = new $$HashMap(); + + // this is done first beforehand so that the hashmap + // is filled with a list of the elements that will be animated + for (i = 0; i < animations.length; i++) { + var animation = animations[i]; + lookup.put(animation.domNode, animations[i] = { + domNode: animation.domNode, + fn: animation.fn, + children: [] + }); + } + + for (i = 0; i < animations.length; i++) { + processNode(animations[i]); + } + + return flatten(tree); + + function processNode(entry) { + if (entry.processed) return entry; + entry.processed = true; + + var elementNode = entry.domNode; + var parentNode = elementNode.parentNode; + lookup.put(elementNode, entry); + + var parentEntry; + while (parentNode) { + parentEntry = lookup.get(parentNode); + if (parentEntry) { + if (!parentEntry.processed) { + parentEntry = processNode(parentEntry); + } + break; + } + parentNode = parentNode.parentNode; + } + + (parentEntry || tree).children.push(entry); + return entry; + } + + function flatten(tree) { + var result = []; + var queue = []; + var i; + + for (i = 0; i < tree.children.length; i++) { + queue.push(tree.children[i]); + } + + var remainingLevelEntries = queue.length; + var nextLevelEntries = 0; + var row = []; + + for (i = 0; i < queue.length; i++) { + var entry = queue[i]; + if (remainingLevelEntries <= 0) { + remainingLevelEntries = nextLevelEntries; + nextLevelEntries = 0; + result.push(row); + row = []; + } + row.push(entry.fn); + entry.children.forEach(function(childEntry) { + nextLevelEntries++; + queue.push(childEntry); + }); + remainingLevelEntries--; + } + + if (row.length) { + result.push(row); + } + + return result; + } + } + + // TODO(matsko): document the signature in a better way + return function(element, event, options) { + options = prepareAnimationOptions(options); + var isStructural = ['enter', 'move', 'leave'].indexOf(event) >= 0; + + // there is no animation at the current moment, however + // these runner methods will get later updated with the + // methods leading into the driver's end/cancel methods + // for now they just stop the animation from starting + var runner = new $$AnimateRunner({ + end: function() { close(); }, + cancel: function() { close(true); } + }); + + if (!drivers.length) { + close(); + return runner; + } + + setRunner(element, runner); + + var classes = mergeClasses(element.attr('class'), mergeClasses(options.addClass, options.removeClass)); + var tempClasses = options.tempClasses; + if (tempClasses) { + classes += ' ' + tempClasses; + options.tempClasses = null; + } + + var prepareClassName; + if (isStructural) { + prepareClassName = 'ng-' + event + PREPARE_CLASS_SUFFIX; + $$jqLite.addClass(element, prepareClassName); + } + + animationQueue.push({ + // this data is used by the postDigest code and passed into + // the driver step function + element: element, + classes: classes, + event: event, + structural: isStructural, + options: options, + beforeStart: beforeStart, + close: close + }); + + element.on('$destroy', handleDestroyedElement); + + // we only want there to be one function called within the post digest + // block. This way we can group animations for all the animations that + // were apart of the same postDigest flush call. + if (animationQueue.length > 1) return runner; + + $rootScope.$$postDigest(function() { + var animations = []; + forEach(animationQueue, function(entry) { + // the element was destroyed early on which removed the runner + // form its storage. This means we can't animate this element + // at all and it already has been closed due to destruction. + if (getRunner(entry.element)) { + animations.push(entry); + } else { + entry.close(); + } + }); + + // now any future animations will be in another postDigest + animationQueue.length = 0; + + var groupedAnimations = groupAnimations(animations); + var toBeSortedAnimations = []; + + forEach(groupedAnimations, function(animationEntry) { + toBeSortedAnimations.push({ + domNode: getDomNode(animationEntry.from ? animationEntry.from.element : animationEntry.element), + fn: function triggerAnimationStart() { + // it's important that we apply the `ng-animate` CSS class and the + // temporary classes before we do any driver invoking since these + // CSS classes may be required for proper CSS detection. + animationEntry.beforeStart(); + + var startAnimationFn, closeFn = animationEntry.close; + + // in the event that the element was removed before the digest runs or + // during the RAF sequencing then we should not trigger the animation. + var targetElement = animationEntry.anchors + ? (animationEntry.from.element || animationEntry.to.element) + : animationEntry.element; + + if (getRunner(targetElement)) { + var operation = invokeFirstDriver(animationEntry); + if (operation) { + startAnimationFn = operation.start; + } + } + + if (!startAnimationFn) { + closeFn(); + } else { + var animationRunner = startAnimationFn(); + animationRunner.done(function(status) { + closeFn(!status); + }); + updateAnimationRunners(animationEntry, animationRunner); + } + } + }); + }); + + // we need to sort each of the animations in order of parent to child + // relationships. This ensures that the child classes are applied at the + // right time. + $$rAFScheduler(sortAnimations(toBeSortedAnimations)); + }); + + return runner; + + // TODO(matsko): change to reference nodes + function getAnchorNodes(node) { + var SELECTOR = '[' + NG_ANIMATE_REF_ATTR + ']'; + var items = node.hasAttribute(NG_ANIMATE_REF_ATTR) + ? [node] + : node.querySelectorAll(SELECTOR); + var anchors = []; + forEach(items, function(node) { + var attr = node.getAttribute(NG_ANIMATE_REF_ATTR); + if (attr && attr.length) { + anchors.push(node); + } + }); + return anchors; + } + + function groupAnimations(animations) { + var preparedAnimations = []; + var refLookup = {}; + forEach(animations, function(animation, index) { + var element = animation.element; + var node = getDomNode(element); + var event = animation.event; + var enterOrMove = ['enter', 'move'].indexOf(event) >= 0; + var anchorNodes = animation.structural ? getAnchorNodes(node) : []; + + if (anchorNodes.length) { + var direction = enterOrMove ? 'to' : 'from'; + + forEach(anchorNodes, function(anchor) { + var key = anchor.getAttribute(NG_ANIMATE_REF_ATTR); + refLookup[key] = refLookup[key] || {}; + refLookup[key][direction] = { + animationID: index, + element: jqLite(anchor) + }; + }); + } else { + preparedAnimations.push(animation); + } + }); + + var usedIndicesLookup = {}; + var anchorGroups = {}; + forEach(refLookup, function(operations, key) { + var from = operations.from; + var to = operations.to; + + if (!from || !to) { + // only one of these is set therefore we can't have an + // anchor animation since all three pieces are required + var index = from ? from.animationID : to.animationID; + var indexKey = index.toString(); + if (!usedIndicesLookup[indexKey]) { + usedIndicesLookup[indexKey] = true; + preparedAnimations.push(animations[index]); + } + return; + } + + var fromAnimation = animations[from.animationID]; + var toAnimation = animations[to.animationID]; + var lookupKey = from.animationID.toString(); + if (!anchorGroups[lookupKey]) { + var group = anchorGroups[lookupKey] = { + structural: true, + beforeStart: function() { + fromAnimation.beforeStart(); + toAnimation.beforeStart(); + }, + close: function() { + fromAnimation.close(); + toAnimation.close(); + }, + classes: cssClassesIntersection(fromAnimation.classes, toAnimation.classes), + from: fromAnimation, + to: toAnimation, + anchors: [] // TODO(matsko): change to reference nodes + }; + + // the anchor animations require that the from and to elements both have at least + // one shared CSS class which effectively marries the two elements together to use + // the same animation driver and to properly sequence the anchor animation. + if (group.classes.length) { + preparedAnimations.push(group); + } else { + preparedAnimations.push(fromAnimation); + preparedAnimations.push(toAnimation); + } + } + + anchorGroups[lookupKey].anchors.push({ + 'out': from.element, 'in': to.element + }); + }); + + return preparedAnimations; + } + + function cssClassesIntersection(a,b) { + a = a.split(' '); + b = b.split(' '); + var matches = []; + + for (var i = 0; i < a.length; i++) { + var aa = a[i]; + if (aa.substring(0,3) === 'ng-') continue; + + for (var j = 0; j < b.length; j++) { + if (aa === b[j]) { + matches.push(aa); + break; + } + } + } + + return matches.join(' '); + } + + function invokeFirstDriver(animationDetails) { + // we loop in reverse order since the more general drivers (like CSS and JS) + // may attempt more elements, but custom drivers are more particular + for (var i = drivers.length - 1; i >= 0; i--) { + var driverName = drivers[i]; + if (!$injector.has(driverName)) continue; // TODO(matsko): remove this check + + var factory = $injector.get(driverName); + var driver = factory(animationDetails); + if (driver) { + return driver; + } + } + } + + function beforeStart() { + element.addClass(NG_ANIMATE_CLASSNAME); + if (tempClasses) { + $$jqLite.addClass(element, tempClasses); + } + if (prepareClassName) { + $$jqLite.removeClass(element, prepareClassName); + prepareClassName = null; + } + } + + function updateAnimationRunners(animation, newRunner) { + if (animation.from && animation.to) { + update(animation.from.element); + update(animation.to.element); + } else { + update(animation.element); + } + + function update(element) { + getRunner(element).setHost(newRunner); + } + } + + function handleDestroyedElement() { + var runner = getRunner(element); + if (runner && (event !== 'leave' || !options.$$domOperationFired)) { + runner.end(); + } + } + + function close(rejected) { // jshint ignore:line + element.off('$destroy', handleDestroyedElement); + removeRunner(element); + + applyAnimationClasses(element, options); + applyAnimationStyles(element, options); + options.domOperation(); + + if (tempClasses) { + $$jqLite.removeClass(element, tempClasses); + } + + element.removeClass(NG_ANIMATE_CLASSNAME); + runner.complete(!rejected); + } + }; + }]; +}]; + +/** + * @ngdoc directive + * @name ngAnimateSwap + * @restrict A + * @scope + * + * @description + * + * ngAnimateSwap is a animation-oriented directive that allows for the container to + * be removed and entered in whenever the associated expression changes. A + * common usecase for this directive is a rotating banner component which + * contains one image being present at a time. When the active image changes + * then the old image will perform a `leave` animation and the new element + * will be inserted via an `enter` animation. + * + * @example + * + * + *
    + *
    + * {{ number }} + *
    + *
    + *
    + * + * angular.module('ngAnimateSwapExample', ['ngAnimate']) + * .controller('AppCtrl', ['$scope', '$interval', function($scope, $interval) { + * $scope.number = 0; + * $interval(function() { + * $scope.number++; + * }, 1000); + * + * var colors = ['red','blue','green','yellow','orange']; + * $scope.colorClass = function(number) { + * return colors[number % colors.length]; + * }; + * }]); + * + * + * .container { + * height:250px; + * width:250px; + * position:relative; + * overflow:hidden; + * border:2px solid black; + * } + * .container .cell { + * font-size:150px; + * text-align:center; + * line-height:250px; + * position:absolute; + * top:0; + * left:0; + * right:0; + * border-bottom:2px solid black; + * } + * .swap-animation.ng-enter, .swap-animation.ng-leave { + * transition:0.5s linear all; + * } + * .swap-animation.ng-enter { + * top:-250px; + * } + * .swap-animation.ng-enter-active { + * top:0px; + * } + * .swap-animation.ng-leave { + * top:0px; + * } + * .swap-animation.ng-leave-active { + * top:250px; + * } + * .red { background:red; } + * .green { background:green; } + * .blue { background:blue; } + * .yellow { background:yellow; } + * .orange { background:orange; } + * + *
    + */ +var ngAnimateSwapDirective = ['$animate', '$rootScope', function($animate, $rootScope) { + return { + restrict: 'A', + transclude: 'element', + terminal: true, + priority: 600, // we use 600 here to ensure that the directive is caught before others + link: function(scope, $element, attrs, ctrl, $transclude) { + var previousElement, previousScope; + scope.$watchCollection(attrs.ngAnimateSwap || attrs['for'], function(value) { + if (previousElement) { + $animate.leave(previousElement); + } + if (previousScope) { + previousScope.$destroy(); + previousScope = null; + } + if (value || value === 0) { + previousScope = scope.$new(); + $transclude(previousScope, function(element) { + previousElement = element; + $animate.enter(element, null, $element); + }); + } + }); + } + }; +}]; + +/* global angularAnimateModule: true, + + ngAnimateSwapDirective, + $$AnimateAsyncRunFactory, + $$rAFSchedulerFactory, + $$AnimateChildrenDirective, + $$AnimateQueueProvider, + $$AnimationProvider, + $AnimateCssProvider, + $$AnimateCssDriverProvider, + $$AnimateJsProvider, + $$AnimateJsDriverProvider, +*/ + +/** + * @ngdoc module + * @name ngAnimate + * @description + * + * The `ngAnimate` module provides support for CSS-based animations (keyframes and transitions) as well as JavaScript-based animations via + * callback hooks. Animations are not enabled by default, however, by including `ngAnimate` the animation hooks are enabled for an Angular app. + * + *
    + * + * # Usage + * Simply put, there are two ways to make use of animations when ngAnimate is used: by using **CSS** and **JavaScript**. The former works purely based + * using CSS (by using matching CSS selectors/styles) and the latter triggers animations that are registered via `module.animation()`. For + * both CSS and JS animations the sole requirement is to have a matching `CSS class` that exists both in the registered animation and within + * the HTML element that the animation will be triggered on. + * + * ## Directive Support + * The following directives are "animation aware": + * + * | Directive | Supported Animations | + * |----------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------| + * | {@link ng.directive:ngRepeat#animations ngRepeat} | enter, leave and move | + * | {@link ngRoute.directive:ngView#animations ngView} | enter and leave | + * | {@link ng.directive:ngInclude#animations ngInclude} | enter and leave | + * | {@link ng.directive:ngSwitch#animations ngSwitch} | enter and leave | + * | {@link ng.directive:ngIf#animations ngIf} | enter and leave | + * | {@link ng.directive:ngClass#animations ngClass} | add and remove (the CSS class(es) present) | + * | {@link ng.directive:ngShow#animations ngShow} & {@link ng.directive:ngHide#animations ngHide} | add and remove (the ng-hide class value) | + * | {@link ng.directive:form#animation-hooks form} & {@link ng.directive:ngModel#animation-hooks ngModel} | add and remove (dirty, pristine, valid, invalid & all other validations) | + * | {@link module:ngMessages#animations ngMessages} | add and remove (ng-active & ng-inactive) | + * | {@link module:ngMessages#animations ngMessage} | enter and leave | + * + * (More information can be found by visiting each the documentation associated with each directive.) + * + * ## CSS-based Animations + * + * CSS-based animations with ngAnimate are unique since they require no JavaScript code at all. By using a CSS class that we reference between our HTML + * and CSS code we can create an animation that will be picked up by Angular when an the underlying directive performs an operation. + * + * The example below shows how an `enter` animation can be made possible on an element using `ng-if`: + * + * ```html + *
    + * Fade me in out + *
    + * + * + * ``` + * + * Notice the CSS class **fade**? We can now create the CSS transition code that references this class: + * + * ```css + * /* The starting CSS styles for the enter animation */ + * .fade.ng-enter { + * transition:0.5s linear all; + * opacity:0; + * } + * + * /* The finishing CSS styles for the enter animation */ + * .fade.ng-enter.ng-enter-active { + * opacity:1; + * } + * ``` + * + * The key thing to remember here is that, depending on the animation event (which each of the directives above trigger depending on what's going on) two + * generated CSS classes will be applied to the element; in the example above we have `.ng-enter` and `.ng-enter-active`. For CSS transitions, the transition + * code **must** be defined within the starting CSS class (in this case `.ng-enter`). The destination class is what the transition will animate towards. + * + * If for example we wanted to create animations for `leave` and `move` (ngRepeat triggers move) then we can do so using the same CSS naming conventions: + * + * ```css + * /* now the element will fade out before it is removed from the DOM */ + * .fade.ng-leave { + * transition:0.5s linear all; + * opacity:1; + * } + * .fade.ng-leave.ng-leave-active { + * opacity:0; + * } + * ``` + * + * We can also make use of **CSS Keyframes** by referencing the keyframe animation within the starting CSS class: + * + * ```css + * /* there is no need to define anything inside of the destination + * CSS class since the keyframe will take charge of the animation */ + * .fade.ng-leave { + * animation: my_fade_animation 0.5s linear; + * -webkit-animation: my_fade_animation 0.5s linear; + * } + * + * @keyframes my_fade_animation { + * from { opacity:1; } + * to { opacity:0; } + * } + * + * @-webkit-keyframes my_fade_animation { + * from { opacity:1; } + * to { opacity:0; } + * } + * ``` + * + * Feel free also mix transitions and keyframes together as well as any other CSS classes on the same element. + * + * ### CSS Class-based Animations + * + * Class-based animations (animations that are triggered via `ngClass`, `ngShow`, `ngHide` and some other directives) have a slightly different + * naming convention. Class-based animations are basic enough that a standard transition or keyframe can be referenced on the class being added + * and removed. + * + * For example if we wanted to do a CSS animation for `ngHide` then we place an animation on the `.ng-hide` CSS class: + * + * ```html + *
    + * Show and hide me + *
    + * + * + * + * ``` + * + * All that is going on here with ngShow/ngHide behind the scenes is the `.ng-hide` class is added/removed (when the hidden state is valid). Since + * ngShow and ngHide are animation aware then we can match up a transition and ngAnimate handles the rest. + * + * In addition the addition and removal of the CSS class, ngAnimate also provides two helper methods that we can use to further decorate the animation + * with CSS styles. + * + * ```html + *
    + * Highlight this box + *
    + * + * + * + * ``` + * + * We can also make use of CSS keyframes by placing them within the CSS classes. + * + * + * ### CSS Staggering Animations + * A Staggering animation is a collection of animations that are issued with a slight delay in between each successive operation resulting in a + * curtain-like effect. The ngAnimate module (versions >=1.2) supports staggering animations and the stagger effect can be + * performed by creating a **ng-EVENT-stagger** CSS class and attaching that class to the base CSS class used for + * the animation. The style property expected within the stagger class can either be a **transition-delay** or an + * **animation-delay** property (or both if your animation contains both transitions and keyframe animations). + * + * ```css + * .my-animation.ng-enter { + * /* standard transition code */ + * transition: 1s linear all; + * opacity:0; + * } + * .my-animation.ng-enter-stagger { + * /* this will have a 100ms delay between each successive leave animation */ + * transition-delay: 0.1s; + * + * /* As of 1.4.4, this must always be set: it signals ngAnimate + * to not accidentally inherit a delay property from another CSS class */ + * transition-duration: 0s; + * } + * .my-animation.ng-enter.ng-enter-active { + * /* standard transition styles */ + * opacity:1; + * } + * ``` + * + * Staggering animations work by default in ngRepeat (so long as the CSS class is defined). Outside of ngRepeat, to use staggering animations + * on your own, they can be triggered by firing multiple calls to the same event on $animate. However, the restrictions surrounding this + * are that each of the elements must have the same CSS className value as well as the same parent element. A stagger operation + * will also be reset if one or more animation frames have passed since the multiple calls to `$animate` were fired. + * + * The following code will issue the **ng-leave-stagger** event on the element provided: + * + * ```js + * var kids = parent.children(); + * + * $animate.leave(kids[0]); //stagger index=0 + * $animate.leave(kids[1]); //stagger index=1 + * $animate.leave(kids[2]); //stagger index=2 + * $animate.leave(kids[3]); //stagger index=3 + * $animate.leave(kids[4]); //stagger index=4 + * + * window.requestAnimationFrame(function() { + * //stagger has reset itself + * $animate.leave(kids[5]); //stagger index=0 + * $animate.leave(kids[6]); //stagger index=1 + * + * $scope.$digest(); + * }); + * ``` + * + * Stagger animations are currently only supported within CSS-defined animations. + * + * ### The `ng-animate` CSS class + * + * When ngAnimate is animating an element it will apply the `ng-animate` CSS class to the element for the duration of the animation. + * This is a temporary CSS class and it will be removed once the animation is over (for both JavaScript and CSS-based animations). + * + * Therefore, animations can be applied to an element using this temporary class directly via CSS. + * + * ```css + * .zipper.ng-animate { + * transition:0.5s linear all; + * } + * .zipper.ng-enter { + * opacity:0; + * } + * .zipper.ng-enter.ng-enter-active { + * opacity:1; + * } + * .zipper.ng-leave { + * opacity:1; + * } + * .zipper.ng-leave.ng-leave-active { + * opacity:0; + * } + * ``` + * + * (Note that the `ng-animate` CSS class is reserved and it cannot be applied on an element directly since ngAnimate will always remove + * the CSS class once an animation has completed.) + * + * + * ### The `ng-[event]-prepare` class + * + * This is a special class that can be used to prevent unwanted flickering / flash of content before + * the actual animation starts. The class is added as soon as an animation is initialized, but removed + * before the actual animation starts (after waiting for a $digest). + * It is also only added for *structural* animations (`enter`, `move`, and `leave`). + * + * In practice, flickering can appear when nesting elements with structural animations such as `ngIf` + * into elements that have class-based animations such as `ngClass`. + * + * ```html + *
    + *
    + *
    + *
    + *
    + * ``` + * + * It is possible that during the `enter` animation, the `.message` div will be briefly visible before it starts animating. + * In that case, you can add styles to the CSS that make sure the element stays hidden before the animation starts: + * + * ```css + * .message.ng-enter-prepare { + * opacity: 0; + * } + * + * ``` + * + * ## JavaScript-based Animations + * + * ngAnimate also allows for animations to be consumed by JavaScript code. The approach is similar to CSS-based animations (where there is a shared + * CSS class that is referenced in our HTML code) but in addition we need to register the JavaScript animation on the module. By making use of the + * `module.animation()` module function we can register the animation. + * + * Let's see an example of a enter/leave animation using `ngRepeat`: + * + * ```html + *
    + * {{ item }} + *
    + * ``` + * + * See the **slide** CSS class? Let's use that class to define an animation that we'll structure in our module code by using `module.animation`: + * + * ```js + * myModule.animation('.slide', [function() { + * return { + * // make note that other events (like addClass/removeClass) + * // have different function input parameters + * enter: function(element, doneFn) { + * jQuery(element).fadeIn(1000, doneFn); + * + * // remember to call doneFn so that angular + * // knows that the animation has concluded + * }, + * + * move: function(element, doneFn) { + * jQuery(element).fadeIn(1000, doneFn); + * }, + * + * leave: function(element, doneFn) { + * jQuery(element).fadeOut(1000, doneFn); + * } + * } + * }]); + * ``` + * + * The nice thing about JS-based animations is that we can inject other services and make use of advanced animation libraries such as + * greensock.js and velocity.js. + * + * If our animation code class-based (meaning that something like `ngClass`, `ngHide` and `ngShow` triggers it) then we can still define + * our animations inside of the same registered animation, however, the function input arguments are a bit different: + * + * ```html + *
    + * this box is moody + *
    + * + * + * + * ``` + * + * ```js + * myModule.animation('.colorful', [function() { + * return { + * addClass: function(element, className, doneFn) { + * // do some cool animation and call the doneFn + * }, + * removeClass: function(element, className, doneFn) { + * // do some cool animation and call the doneFn + * }, + * setClass: function(element, addedClass, removedClass, doneFn) { + * // do some cool animation and call the doneFn + * } + * } + * }]); + * ``` + * + * ## CSS + JS Animations Together + * + * AngularJS 1.4 and higher has taken steps to make the amalgamation of CSS and JS animations more flexible. However, unlike earlier versions of Angular, + * defining CSS and JS animations to work off of the same CSS class will not work anymore. Therefore the example below will only result in **JS animations taking + * charge of the animation**: + * + * ```html + *
    + * Slide in and out + *
    + * ``` + * + * ```js + * myModule.animation('.slide', [function() { + * return { + * enter: function(element, doneFn) { + * jQuery(element).slideIn(1000, doneFn); + * } + * } + * }]); + * ``` + * + * ```css + * .slide.ng-enter { + * transition:0.5s linear all; + * transform:translateY(-100px); + * } + * .slide.ng-enter.ng-enter-active { + * transform:translateY(0); + * } + * ``` + * + * Does this mean that CSS and JS animations cannot be used together? Do JS-based animations always have higher priority? We can make up for the + * lack of CSS animations by using the `$animateCss` service to trigger our own tweaked-out, CSS-based animations directly from + * our own JS-based animation code: + * + * ```js + * myModule.animation('.slide', ['$animateCss', function($animateCss) { + * return { + * enter: function(element) { +* // this will trigger `.slide.ng-enter` and `.slide.ng-enter-active`. + * return $animateCss(element, { + * event: 'enter', + * structural: true + * }); + * } + * } + * }]); + * ``` + * + * The nice thing here is that we can save bandwidth by sticking to our CSS-based animation code and we don't need to rely on a 3rd-party animation framework. + * + * The `$animateCss` service is very powerful since we can feed in all kinds of extra properties that will be evaluated and fed into a CSS transition or + * keyframe animation. For example if we wanted to animate the height of an element while adding and removing classes then we can do so by providing that + * data into `$animateCss` directly: + * + * ```js + * myModule.animation('.slide', ['$animateCss', function($animateCss) { + * return { + * enter: function(element) { + * return $animateCss(element, { + * event: 'enter', + * structural: true, + * addClass: 'maroon-setting', + * from: { height:0 }, + * to: { height: 200 } + * }); + * } + * } + * }]); + * ``` + * + * Now we can fill in the rest via our transition CSS code: + * + * ```css + * /* the transition tells ngAnimate to make the animation happen */ + * .slide.ng-enter { transition:0.5s linear all; } + * + * /* this extra CSS class will be absorbed into the transition + * since the $animateCss code is adding the class */ + * .maroon-setting { background:red; } + * ``` + * + * And `$animateCss` will figure out the rest. Just make sure to have the `done()` callback fire the `doneFn` function to signal when the animation is over. + * + * To learn more about what's possible be sure to visit the {@link ngAnimate.$animateCss $animateCss service}. + * + * ## Animation Anchoring (via `ng-animate-ref`) + * + * ngAnimate in AngularJS 1.4 comes packed with the ability to cross-animate elements between + * structural areas of an application (like views) by pairing up elements using an attribute + * called `ng-animate-ref`. + * + * Let's say for example we have two views that are managed by `ng-view` and we want to show + * that there is a relationship between two components situated in within these views. By using the + * `ng-animate-ref` attribute we can identify that the two components are paired together and we + * can then attach an animation, which is triggered when the view changes. + * + * Say for example we have the following template code: + * + * ```html + * + *
    + *
    + * + * + * + * + * + * + * + * + * ``` + * + * Now, when the view changes (once the link is clicked), ngAnimate will examine the + * HTML contents to see if there is a match reference between any components in the view + * that is leaving and the view that is entering. It will scan both the view which is being + * removed (leave) and inserted (enter) to see if there are any paired DOM elements that + * contain a matching ref value. + * + * The two images match since they share the same ref value. ngAnimate will now create a + * transport element (which is a clone of the first image element) and it will then attempt + * to animate to the position of the second image element in the next view. For the animation to + * work a special CSS class called `ng-anchor` will be added to the transported element. + * + * We can now attach a transition onto the `.banner.ng-anchor` CSS class and then + * ngAnimate will handle the entire transition for us as well as the addition and removal of + * any changes of CSS classes between the elements: + * + * ```css + * .banner.ng-anchor { + * /* this animation will last for 1 second since there are + * two phases to the animation (an `in` and an `out` phase) */ + * transition:0.5s linear all; + * } + * ``` + * + * We also **must** include animations for the views that are being entered and removed + * (otherwise anchoring wouldn't be possible since the new view would be inserted right away). + * + * ```css + * .view-animation.ng-enter, .view-animation.ng-leave { + * transition:0.5s linear all; + * position:fixed; + * left:0; + * top:0; + * width:100%; + * } + * .view-animation.ng-enter { + * transform:translateX(100%); + * } + * .view-animation.ng-leave, + * .view-animation.ng-enter.ng-enter-active { + * transform:translateX(0%); + * } + * .view-animation.ng-leave.ng-leave-active { + * transform:translateX(-100%); + * } + * ``` + * + * Now we can jump back to the anchor animation. When the animation happens, there are two stages that occur: + * an `out` and an `in` stage. The `out` stage happens first and that is when the element is animated away + * from its origin. Once that animation is over then the `in` stage occurs which animates the + * element to its destination. The reason why there are two animations is to give enough time + * for the enter animation on the new element to be ready. + * + * The example above sets up a transition for both the in and out phases, but we can also target the out or + * in phases directly via `ng-anchor-out` and `ng-anchor-in`. + * + * ```css + * .banner.ng-anchor-out { + * transition: 0.5s linear all; + * + * /* the scale will be applied during the out animation, + * but will be animated away when the in animation runs */ + * transform: scale(1.2); + * } + * + * .banner.ng-anchor-in { + * transition: 1s linear all; + * } + * ``` + * + * + * + * + * ### Anchoring Demo + * + + + Home +
    +
    +
    +
    +
    + + angular.module('anchoringExample', ['ngAnimate', 'ngRoute']) + .config(['$routeProvider', function($routeProvider) { + $routeProvider.when('/', { + templateUrl: 'home.html', + controller: 'HomeController as home' + }); + $routeProvider.when('/profile/:id', { + templateUrl: 'profile.html', + controller: 'ProfileController as profile' + }); + }]) + .run(['$rootScope', function($rootScope) { + $rootScope.records = [ + { id:1, title: "Miss Beulah Roob" }, + { id:2, title: "Trent Morissette" }, + { id:3, title: "Miss Ava Pouros" }, + { id:4, title: "Rod Pouros" }, + { id:5, title: "Abdul Rice" }, + { id:6, title: "Laurie Rutherford Sr." }, + { id:7, title: "Nakia McLaughlin" }, + { id:8, title: "Jordon Blanda DVM" }, + { id:9, title: "Rhoda Hand" }, + { id:10, title: "Alexandrea Sauer" } + ]; + }]) + .controller('HomeController', [function() { + //empty + }]) + .controller('ProfileController', ['$rootScope', '$routeParams', function($rootScope, $routeParams) { + var index = parseInt($routeParams.id, 10); + var record = $rootScope.records[index - 1]; + + this.title = record.title; + this.id = record.id; + }]); + + +

    Welcome to the home page

    +

    Please click on an element

    + + {{ record.title }} + +
    + +
    + {{ profile.title }} +
    +
    + + .record { + display:block; + font-size:20px; + } + .profile { + background:black; + color:white; + font-size:100px; + } + .view-container { + position:relative; + } + .view-container > .view.ng-animate { + position:absolute; + top:0; + left:0; + width:100%; + min-height:500px; + } + .view.ng-enter, .view.ng-leave, + .record.ng-anchor { + transition:0.5s linear all; + } + .view.ng-enter { + transform:translateX(100%); + } + .view.ng-enter.ng-enter-active, .view.ng-leave { + transform:translateX(0%); + } + .view.ng-leave.ng-leave-active { + transform:translateX(-100%); + } + .record.ng-anchor-out { + background:red; + } + +
    + * + * ### How is the element transported? + * + * When an anchor animation occurs, ngAnimate will clone the starting element and position it exactly where the starting + * element is located on screen via absolute positioning. The cloned element will be placed inside of the root element + * of the application (where ng-app was defined) and all of the CSS classes of the starting element will be applied. The + * element will then animate into the `out` and `in` animations and will eventually reach the coordinates and match + * the dimensions of the destination element. During the entire animation a CSS class of `.ng-animate-shim` will be applied + * to both the starting and destination elements in order to hide them from being visible (the CSS styling for the class + * is: `visibility:hidden`). Once the anchor reaches its destination then it will be removed and the destination element + * will become visible since the shim class will be removed. + * + * ### How is the morphing handled? + * + * CSS Anchoring relies on transitions and keyframes and the internal code is intelligent enough to figure out + * what CSS classes differ between the starting element and the destination element. These different CSS classes + * will be added/removed on the anchor element and a transition will be applied (the transition that is provided + * in the anchor class). Long story short, ngAnimate will figure out what classes to add and remove which will + * make the transition of the element as smooth and automatic as possible. Be sure to use simple CSS classes that + * do not rely on DOM nesting structure so that the anchor element appears the same as the starting element (since + * the cloned element is placed inside of root element which is likely close to the body element). + * + * Note that if the root element is on the `` element then the cloned node will be placed inside of body. + * + * + * ## Using $animate in your directive code + * + * So far we've explored how to feed in animations into an Angular application, but how do we trigger animations within our own directives in our application? + * By injecting the `$animate` service into our directive code, we can trigger structural and class-based hooks which can then be consumed by animations. Let's + * imagine we have a greeting box that shows and hides itself when the data changes + * + * ```html + * Hi there + * ``` + * + * ```js + * ngModule.directive('greetingBox', ['$animate', function($animate) { + * return function(scope, element, attrs) { + * attrs.$observe('active', function(value) { + * value ? $animate.addClass(element, 'on') : $animate.removeClass(element, 'on'); + * }); + * }); + * }]); + * ``` + * + * Now the `on` CSS class is added and removed on the greeting box component. Now if we add a CSS class on top of the greeting box element + * in our HTML code then we can trigger a CSS or JS animation to happen. + * + * ```css + * /* normally we would create a CSS class to reference on the element */ + * greeting-box.on { transition:0.5s linear all; background:green; color:white; } + * ``` + * + * The `$animate` service contains a variety of other methods like `enter`, `leave`, `animate` and `setClass`. To learn more about what's + * possible be sure to visit the {@link ng.$animate $animate service API page}. + * + * + * ### Preventing Collisions With Third Party Libraries + * + * Some third-party frameworks place animation duration defaults across many element or className + * selectors in order to make their code small and reuseable. This can lead to issues with ngAnimate, which + * is expecting actual animations on these elements and has to wait for their completion. + * + * You can prevent this unwanted behavior by using a prefix on all your animation classes: + * + * ```css + * /* prefixed with animate- */ + * .animate-fade-add.animate-fade-add-active { + * transition:1s linear all; + * opacity:0; + * } + * ``` + * + * You then configure `$animate` to enforce this prefix: + * + * ```js + * $animateProvider.classNameFilter(/animate-/); + * ``` + * + * This also may provide your application with a speed boost since only specific elements containing CSS class prefix + * will be evaluated for animation when any DOM changes occur in the application. + * + * ## Callbacks and Promises + * + * When `$animate` is called it returns a promise that can be used to capture when the animation has ended. Therefore if we were to trigger + * an animation (within our directive code) then we can continue performing directive and scope related activities after the animation has + * ended by chaining onto the returned promise that animation method returns. + * + * ```js + * // somewhere within the depths of the directive + * $animate.enter(element, parent).then(function() { + * //the animation has completed + * }); + * ``` + * + * (Note that earlier versions of Angular prior to v1.4 required the promise code to be wrapped using `$scope.$apply(...)`. This is not the case + * anymore.) + * + * In addition to the animation promise, we can also make use of animation-related callbacks within our directives and controller code by registering + * an event listener using the `$animate` service. Let's say for example that an animation was triggered on our view + * routing controller to hook into that: + * + * ```js + * ngModule.controller('HomePageController', ['$animate', function($animate) { + * $animate.on('enter', ngViewElement, function(element) { + * // the animation for this route has completed + * }]); + * }]) + * ``` + * + * (Note that you will need to trigger a digest within the callback to get angular to notice any scope-related changes.) + */ + +/** + * @ngdoc service + * @name $animate + * @kind object + * + * @description + * The ngAnimate `$animate` service documentation is the same for the core `$animate` service. + * + * Click here {@link ng.$animate to learn more about animations with `$animate`}. + */ +angular.module('ngAnimate', []) + .directive('ngAnimateSwap', ngAnimateSwapDirective) + + .directive('ngAnimateChildren', $$AnimateChildrenDirective) + .factory('$$rAFScheduler', $$rAFSchedulerFactory) + + .provider('$$animateQueue', $$AnimateQueueProvider) + .provider('$$animation', $$AnimationProvider) + + .provider('$animateCss', $AnimateCssProvider) + .provider('$$animateCssDriver', $$AnimateCssDriverProvider) + + .provider('$$animateJs', $$AnimateJsProvider) + .provider('$$animateJsDriver', $$AnimateJsDriverProvider); + + +})(window, window.angular); diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-animate.min.js b/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-animate.min.js new file mode 100644 index 000000000..8e8e41dfd --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-animate.min.js @@ -0,0 +1,56 @@ +/* + AngularJS v1.5.0 + (c) 2010-2016 Google, Inc. http://angularjs.org + License: MIT +*/ +(function(D,r,Va){'use strict';function ya(a,b,c){if(!a)throw Ka("areq",b||"?",c||"required");return a}function za(a,b){if(!a&&!b)return"";if(!a)return b;if(!b)return a;ba(a)&&(a=a.join(" "));ba(b)&&(b=b.join(" "));return a+" "+b}function La(a){var b={};a&&(a.to||a.from)&&(b.to=a.to,b.from=a.from);return b}function X(a,b,c){var d="";a=ba(a)?a:a&&R(a)&&a.length?a.split(/\s+/):[];s(a,function(a,g){a&&0=a&&(a=e,e=0,b.push(t),t=[]);t.push(g.fn);g.children.forEach(function(a){e++; +c.push(a)});a--}t.length&&b.push(t);return b}(c)}var M=[],r=U(a);return function(u,A,v){function z(a){a=a.hasAttribute("ng-animate-ref")?[a]:a.querySelectorAll("[ng-animate-ref]");var b=[];s(a,function(a){var c=a.getAttribute("ng-animate-ref");c&&c.length&&b.push(a)});return b}function K(a){var b=[],c={};s(a,function(a,f){var d=G(a.element),h=0<=["enter","move"].indexOf(a.event),d=a.structural?z(d):[];if(d.length){var e=h?"to":"from";s(d,function(a){var b=a.getAttribute("ng-animate-ref");c[b]=c[b]|| +{};c[b][e]={animationID:f,element:I(a)}})}else b.push(a)});var d={},h={};s(c,function(c,e){var l=c.from,t=c.to;if(l&&t){var g=a[l.animationID],E=a[t.animationID],k=l.animationID.toString();if(!h[k]){var z=h[k]={structural:!0,beforeStart:function(){g.beforeStart();E.beforeStart()},close:function(){g.close();E.close()},classes:J(g.classes,E.classes),from:g,to:E,anchors:[]};z.classes.length?b.push(z):(b.push(g),b.push(E))}h[k].anchors.push({out:l.element,"in":t.element})}else l=l?l.animationID:t.animationID, +t=l.toString(),d[t]||(d[t]=!0,b.push(a[l]))});return b}function J(a,b){a=a.split(" ");b=b.split(" ");for(var c=[],d=0;d=P&&b>=O&&(wa=!0,q())}function L(){function b(){if(!A){t(!1);s(m, +function(a){l.style[a[0]]=a[1]});z(a,f);e.addClass(a,ca);if(p.recalculateTimingStyles){ja=l.className+" "+da;ga=r(l,ja);F=v(l,ja,ga);$=F.maxDelay;n=Math.max($,0);O=F.maxDuration;if(0===O){q();return}p.hasTransitions=0B.expectedEndTime)?H.cancel(B.timer):g.push(q)}L&&(k=H(c,k,!1),g[0]={timer:k,expectedEndTime:d},g.push(q),a.data("$$animateCss",g));if(ea.length)a.on(ea.join(" "),E);f.to&&(f.cleanupStyles&&Ga(x,l,Object.keys(f.to)),Ba(a, +f))}}function c(){var b=a.data("$$animateCss");if(b){for(var d=1;dARIA](http://www.w3.org/TR/wai-aria/) + * attributes that convey state or semantic information about the application for users + * of assistive technologies, such as screen readers. + * + *
    + * + * ## Usage + * + * For ngAria to do its magic, simply include the module `ngAria` as a dependency. The following + * directives are supported: + * `ngModel`, `ngChecked`, `ngRequired`, `ngValue`, `ngDisabled`, `ngShow`, `ngHide`, `ngClick`, + * `ngDblClick`, and `ngMessages`. + * + * Below is a more detailed breakdown of the attributes handled by ngAria: + * + * | Directive | Supported Attributes | + * |---------------------------------------------|----------------------------------------------------------------------------------------| + * | {@link ng.directive:ngModel ngModel} | aria-checked, aria-valuemin, aria-valuemax, aria-valuenow, aria-invalid, aria-required, input roles | + * | {@link ng.directive:ngDisabled ngDisabled} | aria-disabled | + * | {@link ng.directive:ngRequired ngRequired} | aria-required | + * | {@link ng.directive:ngChecked ngChecked} | aria-checked | + * | {@link ng.directive:ngValue ngValue} | aria-checked | + * | {@link ng.directive:ngShow ngShow} | aria-hidden | + * | {@link ng.directive:ngHide ngHide} | aria-hidden | + * | {@link ng.directive:ngDblclick ngDblclick} | tabindex | + * | {@link module:ngMessages ngMessages} | aria-live | + * | {@link ng.directive:ngClick ngClick} | tabindex, keypress event, button role | + * + * Find out more information about each directive by reading the + * {@link guide/accessibility ngAria Developer Guide}. + * + * ##Example + * Using ngDisabled with ngAria: + * ```html + * + * ``` + * Becomes: + * ```html + * + * ``` + * + * ##Disabling Attributes + * It's possible to disable individual attributes added by ngAria with the + * {@link ngAria.$ariaProvider#config config} method. For more details, see the + * {@link guide/accessibility Developer Guide}. + */ + /* global -ngAriaModule */ +var ngAriaModule = angular.module('ngAria', ['ng']). + provider('$aria', $AriaProvider); + +/** +* Internal Utilities +*/ +var nodeBlackList = ['BUTTON', 'A', 'INPUT', 'TEXTAREA', 'SELECT', 'DETAILS', 'SUMMARY']; + +var isNodeOneOf = function(elem, nodeTypeArray) { + if (nodeTypeArray.indexOf(elem[0].nodeName) !== -1) { + return true; + } +}; +/** + * @ngdoc provider + * @name $ariaProvider + * + * @description + * + * Used for configuring the ARIA attributes injected and managed by ngAria. + * + * ```js + * angular.module('myApp', ['ngAria'], function config($ariaProvider) { + * $ariaProvider.config({ + * ariaValue: true, + * tabindex: false + * }); + * }); + *``` + * + * ## Dependencies + * Requires the {@link ngAria} module to be installed. + * + */ +function $AriaProvider() { + var config = { + ariaHidden: true, + ariaChecked: true, + ariaDisabled: true, + ariaRequired: true, + ariaInvalid: true, + ariaValue: true, + tabindex: true, + bindKeypress: true, + bindRoleForClick: true + }; + + /** + * @ngdoc method + * @name $ariaProvider#config + * + * @param {object} config object to enable/disable specific ARIA attributes + * + * - **ariaHidden** – `{boolean}` – Enables/disables aria-hidden tags + * - **ariaChecked** – `{boolean}` – Enables/disables aria-checked tags + * - **ariaDisabled** – `{boolean}` – Enables/disables aria-disabled tags + * - **ariaRequired** – `{boolean}` – Enables/disables aria-required tags + * - **ariaInvalid** – `{boolean}` – Enables/disables aria-invalid tags + * - **ariaValue** – `{boolean}` – Enables/disables aria-valuemin, aria-valuemax and aria-valuenow tags + * - **tabindex** – `{boolean}` – Enables/disables tabindex tags + * - **bindKeypress** – `{boolean}` – Enables/disables keypress event binding on `div` and + * `li` elements with ng-click + * - **bindRoleForClick** – `{boolean}` – Adds role=button to non-interactive elements like `div` + * using ng-click, making them more accessible to users of assistive technologies + * + * @description + * Enables/disables various ARIA attributes + */ + this.config = function(newConfig) { + config = angular.extend(config, newConfig); + }; + + function watchExpr(attrName, ariaAttr, nodeBlackList, negate) { + return function(scope, elem, attr) { + var ariaCamelName = attr.$normalize(ariaAttr); + if (config[ariaCamelName] && !isNodeOneOf(elem, nodeBlackList) && !attr[ariaCamelName]) { + scope.$watch(attr[attrName], function(boolVal) { + // ensure boolean value + boolVal = negate ? !boolVal : !!boolVal; + elem.attr(ariaAttr, boolVal); + }); + } + }; + } + /** + * @ngdoc service + * @name $aria + * + * @description + * @priority 200 + * + * The $aria service contains helper methods for applying common + * [ARIA](http://www.w3.org/TR/wai-aria/) attributes to HTML directives. + * + * ngAria injects common accessibility attributes that tell assistive technologies when HTML + * elements are enabled, selected, hidden, and more. To see how this is performed with ngAria, + * let's review a code snippet from ngAria itself: + * + *```js + * ngAriaModule.directive('ngDisabled', ['$aria', function($aria) { + * return $aria.$$watchExpr('ngDisabled', 'aria-disabled', nodeBlackList, false); + * }]) + *``` + * Shown above, the ngAria module creates a directive with the same signature as the + * traditional `ng-disabled` directive. But this ngAria version is dedicated to + * solely managing accessibility attributes on custom elements. The internal `$aria` service is + * used to watch the boolean attribute `ngDisabled`. If it has not been explicitly set by the + * developer, `aria-disabled` is injected as an attribute with its value synchronized to the + * value in `ngDisabled`. + * + * Because ngAria hooks into the `ng-disabled` directive, developers do not have to do + * anything to enable this feature. The `aria-disabled` attribute is automatically managed + * simply as a silent side-effect of using `ng-disabled` with the ngAria module. + * + * The full list of directives that interface with ngAria: + * * **ngModel** + * * **ngChecked** + * * **ngRequired** + * * **ngDisabled** + * * **ngValue** + * * **ngShow** + * * **ngHide** + * * **ngClick** + * * **ngDblclick** + * * **ngMessages** + * + * Read the {@link guide/accessibility ngAria Developer Guide} for a thorough explanation of each + * directive. + * + * + * ## Dependencies + * Requires the {@link ngAria} module to be installed. + */ + this.$get = function() { + return { + config: function(key) { + return config[key]; + }, + $$watchExpr: watchExpr + }; + }; +} + + +ngAriaModule.directive('ngShow', ['$aria', function($aria) { + return $aria.$$watchExpr('ngShow', 'aria-hidden', [], true); +}]) +.directive('ngHide', ['$aria', function($aria) { + return $aria.$$watchExpr('ngHide', 'aria-hidden', [], false); +}]) +.directive('ngValue', ['$aria', function($aria) { + return $aria.$$watchExpr('ngValue', 'aria-checked', nodeBlackList, false); +}]) +.directive('ngChecked', ['$aria', function($aria) { + return $aria.$$watchExpr('ngChecked', 'aria-checked', nodeBlackList, false); +}]) +.directive('ngRequired', ['$aria', function($aria) { + return $aria.$$watchExpr('ngRequired', 'aria-required', nodeBlackList, false); +}]) +.directive('ngModel', ['$aria', function($aria) { + + function shouldAttachAttr(attr, normalizedAttr, elem, allowBlacklistEls) { + return $aria.config(normalizedAttr) && !elem.attr(attr) && (allowBlacklistEls || !isNodeOneOf(elem, nodeBlackList)); + } + + function shouldAttachRole(role, elem) { + // if element does not have role attribute + // AND element type is equal to role (if custom element has a type equaling shape) <-- remove? + // AND element is not INPUT + return !elem.attr('role') && (elem.attr('type') === role) && (elem[0].nodeName !== 'INPUT'); + } + + function getShape(attr, elem) { + var type = attr.type, + role = attr.role; + + return ((type || role) === 'checkbox' || role === 'menuitemcheckbox') ? 'checkbox' : + ((type || role) === 'radio' || role === 'menuitemradio') ? 'radio' : + (type === 'range' || role === 'progressbar' || role === 'slider') ? 'range' : ''; + } + + return { + restrict: 'A', + require: 'ngModel', + priority: 200, //Make sure watches are fired after any other directives that affect the ngModel value + compile: function(elem, attr) { + var shape = getShape(attr, elem); + + return { + pre: function(scope, elem, attr, ngModel) { + if (shape === 'checkbox') { + //Use the input[checkbox] $isEmpty implementation for elements with checkbox roles + ngModel.$isEmpty = function(value) { + return value === false; + }; + } + }, + post: function(scope, elem, attr, ngModel) { + var needsTabIndex = shouldAttachAttr('tabindex', 'tabindex', elem, false); + + function ngAriaWatchModelValue() { + return ngModel.$modelValue; + } + + function getRadioReaction(newVal) { + var boolVal = (attr.value == ngModel.$viewValue); + elem.attr('aria-checked', boolVal); + } + + function getCheckboxReaction() { + elem.attr('aria-checked', !ngModel.$isEmpty(ngModel.$viewValue)); + } + + switch (shape) { + case 'radio': + case 'checkbox': + if (shouldAttachRole(shape, elem)) { + elem.attr('role', shape); + } + if (shouldAttachAttr('aria-checked', 'ariaChecked', elem, false)) { + scope.$watch(ngAriaWatchModelValue, shape === 'radio' ? + getRadioReaction : getCheckboxReaction); + } + if (needsTabIndex) { + elem.attr('tabindex', 0); + } + break; + case 'range': + if (shouldAttachRole(shape, elem)) { + elem.attr('role', 'slider'); + } + if ($aria.config('ariaValue')) { + var needsAriaValuemin = !elem.attr('aria-valuemin') && + (attr.hasOwnProperty('min') || attr.hasOwnProperty('ngMin')); + var needsAriaValuemax = !elem.attr('aria-valuemax') && + (attr.hasOwnProperty('max') || attr.hasOwnProperty('ngMax')); + var needsAriaValuenow = !elem.attr('aria-valuenow'); + + if (needsAriaValuemin) { + attr.$observe('min', function ngAriaValueMinReaction(newVal) { + elem.attr('aria-valuemin', newVal); + }); + } + if (needsAriaValuemax) { + attr.$observe('max', function ngAriaValueMinReaction(newVal) { + elem.attr('aria-valuemax', newVal); + }); + } + if (needsAriaValuenow) { + scope.$watch(ngAriaWatchModelValue, function ngAriaValueNowReaction(newVal) { + elem.attr('aria-valuenow', newVal); + }); + } + } + if (needsTabIndex) { + elem.attr('tabindex', 0); + } + break; + } + + if (!attr.hasOwnProperty('ngRequired') && ngModel.$validators.required + && shouldAttachAttr('aria-required', 'ariaRequired', elem, false)) { + // ngModel.$error.required is undefined on custom controls + attr.$observe('required', function() { + elem.attr('aria-required', !!attr['required']); + }); + } + + if (shouldAttachAttr('aria-invalid', 'ariaInvalid', elem, true)) { + scope.$watch(function ngAriaInvalidWatch() { + return ngModel.$invalid; + }, function ngAriaInvalidReaction(newVal) { + elem.attr('aria-invalid', !!newVal); + }); + } + } + }; + } + }; +}]) +.directive('ngDisabled', ['$aria', function($aria) { + return $aria.$$watchExpr('ngDisabled', 'aria-disabled', nodeBlackList, false); +}]) +.directive('ngMessages', function() { + return { + restrict: 'A', + require: '?ngMessages', + link: function(scope, elem, attr, ngMessages) { + if (!elem.attr('aria-live')) { + elem.attr('aria-live', 'assertive'); + } + } + }; +}) +.directive('ngClick',['$aria', '$parse', function($aria, $parse) { + return { + restrict: 'A', + compile: function(elem, attr) { + var fn = $parse(attr.ngClick, /* interceptorFn */ null, /* expensiveChecks */ true); + return function(scope, elem, attr) { + + if (!isNodeOneOf(elem, nodeBlackList)) { + + if ($aria.config('bindRoleForClick') && !elem.attr('role')) { + elem.attr('role', 'button'); + } + + if ($aria.config('tabindex') && !elem.attr('tabindex')) { + elem.attr('tabindex', 0); + } + + if ($aria.config('bindKeypress') && !attr.ngKeypress) { + elem.on('keypress', function(event) { + var keyCode = event.which || event.keyCode; + if (keyCode === 32 || keyCode === 13) { + scope.$apply(callback); + } + + function callback() { + fn(scope, { $event: event }); + } + }); + } + } + }; + } + }; +}]) +.directive('ngDblclick', ['$aria', function($aria) { + return function(scope, elem, attr) { + if ($aria.config('tabindex') && !elem.attr('tabindex') && !isNodeOneOf(elem, nodeBlackList)) { + elem.attr('tabindex', 0); + } + }; +}]); + + +})(window, window.angular); diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-aria.min.js b/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-aria.min.js new file mode 100644 index 000000000..cf0fd7425 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-aria.min.js @@ -0,0 +1,14 @@ +/* + AngularJS v1.5.0 + (c) 2010-2016 Google, Inc. http://angularjs.org + License: MIT +*/ +(function(s,q,t){'use strict';var f="BUTTON A INPUT TEXTAREA SELECT DETAILS SUMMARY".split(" "),l=function(a,c){if(-1!==c.indexOf(a[0].nodeName))return!0};q.module("ngAria",["ng"]).provider("$aria",function(){function a(a,h,p,n){return function(d,e,b){var g=b.$normalize(h);!c[g]||l(e,p)||b[g]||d.$watch(b[a],function(b){b=n?!b:!!b;e.attr(h,b)})}}var c={ariaHidden:!0,ariaChecked:!0,ariaDisabled:!0,ariaRequired:!0,ariaInvalid:!0,ariaValue:!0,tabindex:!0,bindKeypress:!0,bindRoleForClick:!0};this.config= +function(a){c=q.extend(c,a)};this.$get=function(){return{config:function(a){return c[a]},$$watchExpr:a}}}).directive("ngShow",["$aria",function(a){return a.$$watchExpr("ngShow","aria-hidden",[],!0)}]).directive("ngHide",["$aria",function(a){return a.$$watchExpr("ngHide","aria-hidden",[],!1)}]).directive("ngValue",["$aria",function(a){return a.$$watchExpr("ngValue","aria-checked",f,!1)}]).directive("ngChecked",["$aria",function(a){return a.$$watchExpr("ngChecked","aria-checked",f,!1)}]).directive("ngRequired", +["$aria",function(a){return a.$$watchExpr("ngRequired","aria-required",f,!1)}]).directive("ngModel",["$aria",function(a){function c(c,n,d,e){return a.config(n)&&!d.attr(c)&&(e||!l(d,f))}function m(a,c){return!c.attr("role")&&c.attr("type")===a&&"INPUT"!==c[0].nodeName}function h(a,c){var d=a.type,e=a.role;return"checkbox"===(d||e)||"menuitemcheckbox"===e?"checkbox":"radio"===(d||e)||"menuitemradio"===e?"radio":"range"===d||"progressbar"===e||"slider"===e?"range":""}return{restrict:"A",require:"ngModel", +priority:200,compile:function(f,n){var d=h(n,f);return{pre:function(a,b,c,k){"checkbox"===d&&(k.$isEmpty=function(a){return!1===a})},post:function(e,b,g,k){function f(){return k.$modelValue}function h(a){b.attr("aria-checked",g.value==k.$viewValue)}function n(){b.attr("aria-checked",!k.$isEmpty(k.$viewValue))}var l=c("tabindex","tabindex",b,!1);switch(d){case "radio":case "checkbox":m(d,b)&&b.attr("role",d);c("aria-checked","ariaChecked",b,!1)&&e.$watch(f,"radio"===d?h:n);l&&b.attr("tabindex",0); +break;case "range":m(d,b)&&b.attr("role","slider");if(a.config("ariaValue")){var p=!b.attr("aria-valuemin")&&(g.hasOwnProperty("min")||g.hasOwnProperty("ngMin")),q=!b.attr("aria-valuemax")&&(g.hasOwnProperty("max")||g.hasOwnProperty("ngMax")),r=!b.attr("aria-valuenow");p&&g.$observe("min",function(a){b.attr("aria-valuemin",a)});q&&g.$observe("max",function(a){b.attr("aria-valuemax",a)});r&&e.$watch(f,function(a){b.attr("aria-valuenow",a)})}l&&b.attr("tabindex",0)}!g.hasOwnProperty("ngRequired")&& +k.$validators.required&&c("aria-required","ariaRequired",b,!1)&&g.$observe("required",function(){b.attr("aria-required",!!g.required)});c("aria-invalid","ariaInvalid",b,!0)&&e.$watch(function(){return k.$invalid},function(a){b.attr("aria-invalid",!!a)})}}}}}]).directive("ngDisabled",["$aria",function(a){return a.$$watchExpr("ngDisabled","aria-disabled",f,!1)}]).directive("ngMessages",function(){return{restrict:"A",require:"?ngMessages",link:function(a,c,f,h){c.attr("aria-live")||c.attr("aria-live", +"assertive")}}}).directive("ngClick",["$aria","$parse",function(a,c){return{restrict:"A",compile:function(m,h){var p=c(h.ngClick,null,!0);return function(c,d,e){if(!l(d,f)&&(a.config("bindRoleForClick")&&!d.attr("role")&&d.attr("role","button"),a.config("tabindex")&&!d.attr("tabindex")&&d.attr("tabindex",0),a.config("bindKeypress")&&!e.ngKeypress))d.on("keypress",function(a){function d(){p(c,{$event:a})}var e=a.which||a.keyCode;32!==e&&13!==e||c.$apply(d)})}}}}]).directive("ngDblclick",["$aria",function(a){return function(c, +m,h){!a.config("tabindex")||m.attr("tabindex")||l(m,f)||m.attr("tabindex",0)}}])})(window,window.angular); +//# sourceMappingURL=angular-aria.min.js.map diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-aria.min.js.map b/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-aria.min.js.map new file mode 100644 index 000000000..b1db15b5d --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-aria.min.js.map @@ -0,0 +1,8 @@ +{ +"version":3, +"file":"angular-aria.min.js", +"lineCount":13, +"mappings":"A;;;;;aAKC,SAAQ,CAACA,CAAD,CAASC,CAAT,CAAkBC,CAAlB,CAA6B,CA6DtC,IAAIC,EAAgB,gDAAA,MAAA,CAAA,GAAA,CAApB,CAEIC,EAAcA,QAAQ,CAACC,CAAD,CAAOC,CAAP,CAAsB,CAC9C,GAAiD,EAAjD,GAAIA,CAAAC,QAAA,CAAsBF,CAAA,CAAK,CAAL,CAAAG,SAAtB,CAAJ,CACE,MAAO,CAAA,CAFqC,CAR7BP,EAAAQ,OAAA,CAAe,QAAf,CAAyB,CAAC,IAAD,CAAzB,CAAAC,SAAAC,CACc,OADdA,CAkCnBC,QAAsB,EAAG,CAsCvBC,QAASA,EAAS,CAACC,CAAD,CAAWC,CAAX,CAAqBZ,CAArB,CAAoCa,CAApC,CAA4C,CAC5D,MAAO,SAAQ,CAACC,CAAD,CAAQZ,CAAR,CAAca,CAAd,CAAoB,CACjC,IAAIC,EAAgBD,CAAAE,WAAA,CAAgBL,CAAhB,CAChB,EAAAM,CAAA,CAAOF,CAAP,CAAJ,EAA8Bf,CAAA,CAAYC,CAAZ,CAAkBF,CAAlB,CAA9B,EAAmEe,CAAA,CAAKC,CAAL,CAAnE,EACEF,CAAAK,OAAA,CAAaJ,CAAA,CAAKJ,CAAL,CAAb,CAA6B,QAAQ,CAACS,CAAD,CAAU,CAE7CA,CAAA,CAAUP,CAAA,CAAS,CAACO,CAAV,CAAoB,CAAEA,CAAAA,CAChClB,EAAAa,KAAA,CAAUH,CAAV,CAAoBQ,CAApB,CAH6C,CAA/C,CAH+B,CADyB,CArC9D,IAAIF,EAAS,CACXG,WAAY,CAAA,CADD,CAEXC,YAAa,CAAA,CAFF,CAGXC,aAAc,CAAA,CAHH,CAIXC,aAAc,CAAA,CAJH,CAKXC,YAAa,CAAA,CALF,CAMXC,UAAW,CAAA,CANA,CAOXC,SAAU,CAAA,CAPC,CAQXC,aAAc,CAAA,CARH,CASXC,iBAAkB,CAAA,CATP,CAiCb,KAAAX,OAAA;AAAcY,QAAQ,CAACC,CAAD,CAAY,CAChCb,CAAA,CAASpB,CAAAkC,OAAA,CAAed,CAAf,CAAuBa,CAAvB,CADuB,CAiElC,KAAAE,KAAA,CAAYC,QAAQ,EAAG,CACrB,MAAO,CACLhB,OAAQA,QAAQ,CAACiB,CAAD,CAAM,CACpB,MAAOjB,EAAA,CAAOiB,CAAP,CADa,CADjB,CAILC,YAAa1B,CAJR,CADc,CAnGA,CAlCNF,CAgJnB6B,UAAA,CAAuB,QAAvB,CAAiC,CAAC,OAAD,CAAU,QAAQ,CAACC,CAAD,CAAQ,CACzD,MAAOA,EAAAF,YAAA,CAAkB,QAAlB,CAA4B,aAA5B,CAA2C,EAA3C,CAA+C,CAAA,CAA/C,CADkD,CAA1B,CAAjC,CAAAC,UAAA,CAGW,QAHX,CAGqB,CAAC,OAAD,CAAU,QAAQ,CAACC,CAAD,CAAQ,CAC7C,MAAOA,EAAAF,YAAA,CAAkB,QAAlB,CAA4B,aAA5B,CAA2C,EAA3C,CAA+C,CAAA,CAA/C,CADsC,CAA1B,CAHrB,CAAAC,UAAA,CAMW,SANX,CAMsB,CAAC,OAAD,CAAU,QAAQ,CAACC,CAAD,CAAQ,CAC9C,MAAOA,EAAAF,YAAA,CAAkB,SAAlB,CAA6B,cAA7B,CAA6CpC,CAA7C,CAA4D,CAAA,CAA5D,CADuC,CAA1B,CANtB,CAAAqC,UAAA,CASW,WATX,CASwB,CAAC,OAAD,CAAU,QAAQ,CAACC,CAAD,CAAQ,CAChD,MAAOA,EAAAF,YAAA,CAAkB,WAAlB,CAA+B,cAA/B,CAA+CpC,CAA/C,CAA8D,CAAA,CAA9D,CADyC,CAA1B,CATxB,CAAAqC,UAAA,CAYW,YAZX;AAYyB,CAAC,OAAD,CAAU,QAAQ,CAACC,CAAD,CAAQ,CACjD,MAAOA,EAAAF,YAAA,CAAkB,YAAlB,CAAgC,eAAhC,CAAiDpC,CAAjD,CAAgE,CAAA,CAAhE,CAD0C,CAA1B,CAZzB,CAAAqC,UAAA,CAeW,SAfX,CAesB,CAAC,OAAD,CAAU,QAAQ,CAACC,CAAD,CAAQ,CAE9CC,QAASA,EAAgB,CAACxB,CAAD,CAAOyB,CAAP,CAAuBtC,CAAvB,CAA6BuC,CAA7B,CAAgD,CACvE,MAAOH,EAAApB,OAAA,CAAasB,CAAb,CAAP,EAAuC,CAACtC,CAAAa,KAAA,CAAUA,CAAV,CAAxC,GAA4D0B,CAA5D,EAAiF,CAACxC,CAAA,CAAYC,CAAZ,CAAkBF,CAAlB,CAAlF,CADuE,CAIzE0C,QAASA,EAAgB,CAACC,CAAD,CAAOzC,CAAP,CAAa,CAIpC,MAAO,CAACA,CAAAa,KAAA,CAAU,MAAV,CAAR,EAA8Bb,CAAAa,KAAA,CAAU,MAAV,CAA9B,GAAoD4B,CAApD,EAAmF,OAAnF,GAA8DzC,CAAA,CAAK,CAAL,CAAAG,SAJ1B,CAOtCuC,QAASA,EAAQ,CAAC7B,CAAD,CAAOb,CAAP,CAAa,CAAA,IACxB2C,EAAO9B,CAAA8B,KADiB,CAExBF,EAAO5B,CAAA4B,KAEX,OAA2B,UAApB,IAAEE,CAAF,EAAUF,CAAV,GAA2C,kBAA3C,GAAkCA,CAAlC,CAAiE,UAAjE,CACoB,OAApB,IAAEE,CAAF,EAAUF,CAAV,GAA2C,eAA3C,GAAkCA,CAAlC,CAA8D,OAA9D,CACU,OAAV,GAACE,CAAD,EAA2C,aAA3C,GAAkCF,CAAlC,EAAqE,QAArE,GAA4DA,CAA5D,CAAiF,OAAjF,CAA2F,EANtE,CAS9B,MAAO,CACLG,SAAU,GADL,CAELC,QAAS,SAFJ;AAGLC,SAAU,GAHL,CAILC,QAASA,QAAQ,CAAC/C,CAAD,CAAOa,CAAP,CAAa,CAC5B,IAAImC,EAAQN,CAAA,CAAS7B,CAAT,CAAeb,CAAf,CAEZ,OAAO,CACLiD,IAAKA,QAAQ,CAACrC,CAAD,CAAQZ,CAAR,CAAca,CAAd,CAAoBqC,CAApB,CAA6B,CAC1B,UAAd,GAAIF,CAAJ,GAEEE,CAAAC,SAFF,CAEqBC,QAAQ,CAACC,CAAD,CAAQ,CACjC,MAAiB,CAAA,CAAjB,GAAOA,CAD0B,CAFrC,CADwC,CADrC,CASLC,KAAMA,QAAQ,CAAC1C,CAAD,CAAQZ,CAAR,CAAca,CAAd,CAAoBqC,CAApB,CAA6B,CAGzCK,QAASA,EAAqB,EAAG,CAC/B,MAAOL,EAAAM,YADwB,CAIjCC,QAASA,EAAgB,CAACC,CAAD,CAAS,CAEhC1D,CAAAa,KAAA,CAAU,cAAV,CADeA,CAAAwC,MACf,EAD6BH,CAAAS,WAC7B,CAFgC,CAKlCC,QAASA,EAAmB,EAAG,CAC7B5D,CAAAa,KAAA,CAAU,cAAV,CAA0B,CAACqC,CAAAC,SAAA,CAAiBD,CAAAS,WAAjB,CAA3B,CAD6B,CAX/B,IAAIE,EAAgBxB,CAAA,CAAiB,UAAjB,CAA6B,UAA7B,CAAyCrC,CAAzC,CAA+C,CAAA,CAA/C,CAepB,QAAQgD,CAAR,EACE,KAAK,OAAL,CACA,KAAK,UAAL,CACMR,CAAA,CAAiBQ,CAAjB,CAAwBhD,CAAxB,CAAJ,EACEA,CAAAa,KAAA,CAAU,MAAV,CAAkBmC,CAAlB,CAEEX,EAAA,CAAiB,cAAjB,CAAiC,aAAjC,CAAgDrC,CAAhD,CAAsD,CAAA,CAAtD,CAAJ,EACEY,CAAAK,OAAA,CAAasC,CAAb,CAA8C,OAAV,GAAAP,CAAA,CAChCS,CADgC,CACbG,CADvB,CAGEC,EAAJ,EACE7D,CAAAa,KAAA,CAAU,UAAV,CAAsB,CAAtB,CAEF;KACF,MAAK,OAAL,CACM2B,CAAA,CAAiBQ,CAAjB,CAAwBhD,CAAxB,CAAJ,EACEA,CAAAa,KAAA,CAAU,MAAV,CAAkB,QAAlB,CAEF,IAAIuB,CAAApB,OAAA,CAAa,WAAb,CAAJ,CAA+B,CAC7B,IAAI8C,EAAoB,CAAC9D,CAAAa,KAAA,CAAU,eAAV,CAArBiD,GACCjD,CAAAkD,eAAA,CAAoB,KAApB,CADDD,EAC+BjD,CAAAkD,eAAA,CAAoB,OAApB,CAD/BD,CAAJ,CAEIE,EAAoB,CAAChE,CAAAa,KAAA,CAAU,eAAV,CAArBmD,GACCnD,CAAAkD,eAAA,CAAoB,KAApB,CADDC,EAC+BnD,CAAAkD,eAAA,CAAoB,OAApB,CAD/BC,CAFJ,CAIIC,EAAoB,CAACjE,CAAAa,KAAA,CAAU,eAAV,CAErBiD,EAAJ,EACEjD,CAAAqD,SAAA,CAAc,KAAd,CAAqBC,QAA+B,CAACT,CAAD,CAAS,CAC3D1D,CAAAa,KAAA,CAAU,eAAV,CAA2B6C,CAA3B,CAD2D,CAA7D,CAIEM,EAAJ,EACEnD,CAAAqD,SAAA,CAAc,KAAd,CAAqBC,QAA+B,CAACT,CAAD,CAAS,CAC3D1D,CAAAa,KAAA,CAAU,eAAV,CAA2B6C,CAA3B,CAD2D,CAA7D,CAIEO,EAAJ,EACErD,CAAAK,OAAA,CAAasC,CAAb,CAAoCa,QAA+B,CAACV,CAAD,CAAS,CAC1E1D,CAAAa,KAAA,CAAU,eAAV,CAA2B6C,CAA3B,CAD0E,CAA5E,CAlB2B,CAuB3BG,CAAJ,EACE7D,CAAAa,KAAA,CAAU,UAAV,CAAsB,CAAtB,CA1CN,CA+CK,CAAAA,CAAAkD,eAAA,CAAoB,YAApB,CAAL;AAA0Cb,CAAAmB,YAAAC,SAA1C,EACKjC,CAAA,CAAiB,eAAjB,CAAkC,cAAlC,CAAkDrC,CAAlD,CAAwD,CAAA,CAAxD,CADL,EAGEa,CAAAqD,SAAA,CAAc,UAAd,CAA0B,QAAQ,EAAG,CACnClE,CAAAa,KAAA,CAAU,eAAV,CAA2B,CAAE,CAAAA,CAAA,SAA7B,CADmC,CAArC,CAKEwB,EAAA,CAAiB,cAAjB,CAAiC,aAAjC,CAAgDrC,CAAhD,CAAsD,CAAA,CAAtD,CAAJ,EACEY,CAAAK,OAAA,CAAasD,QAA2B,EAAG,CACzC,MAAOrB,EAAAsB,SADkC,CAA3C,CAEGC,QAA8B,CAACf,CAAD,CAAS,CACxC1D,CAAAa,KAAA,CAAU,cAAV,CAA0B,CAAE6C,CAAAA,CAA5B,CADwC,CAF1C,CAxEuC,CATtC,CAHqB,CAJzB,CAtBuC,CAA1B,CAftB,CAAAvB,UAAA,CAwIW,YAxIX,CAwIyB,CAAC,OAAD,CAAU,QAAQ,CAACC,CAAD,CAAQ,CACjD,MAAOA,EAAAF,YAAA,CAAkB,YAAlB,CAAgC,eAAhC,CAAiDpC,CAAjD,CAAgE,CAAA,CAAhE,CAD0C,CAA1B,CAxIzB,CAAAqC,UAAA,CA2IW,YA3IX,CA2IyB,QAAQ,EAAG,CAClC,MAAO,CACLS,SAAU,GADL,CAELC,QAAS,aAFJ,CAGL6B,KAAMA,QAAQ,CAAC9D,CAAD,CAAQZ,CAAR,CAAca,CAAd,CAAoB8D,CAApB,CAAgC,CACvC3E,CAAAa,KAAA,CAAU,WAAV,CAAL,EACEb,CAAAa,KAAA,CAAU,WAAV;AAAuB,WAAvB,CAF0C,CAHzC,CAD2B,CA3IpC,CAAAsB,UAAA,CAsJW,SAtJX,CAsJqB,CAAC,OAAD,CAAU,QAAV,CAAoB,QAAQ,CAACC,CAAD,CAAQwC,CAAR,CAAgB,CAC/D,MAAO,CACLhC,SAAU,GADL,CAELG,QAASA,QAAQ,CAAC/C,CAAD,CAAOa,CAAP,CAAa,CAC5B,IAAIgE,EAAKD,CAAA,CAAO/D,CAAAiE,QAAP,CAAyC,IAAzC,CAAqE,CAAA,CAArE,CACT,OAAO,SAAQ,CAAClE,CAAD,CAAQZ,CAAR,CAAca,CAAd,CAAoB,CAEjC,GAAK,CAAAd,CAAA,CAAYC,CAAZ,CAAkBF,CAAlB,CAAL,GAEMsC,CAAApB,OAAA,CAAa,kBAAb,CAQA,EARqC,CAAAhB,CAAAa,KAAA,CAAU,MAAV,CAQrC,EAPFb,CAAAa,KAAA,CAAU,MAAV,CAAkB,QAAlB,CAOE,CAJAuB,CAAApB,OAAA,CAAa,UAAb,CAIA,EAJ6B,CAAAhB,CAAAa,KAAA,CAAU,UAAV,CAI7B,EAHFb,CAAAa,KAAA,CAAU,UAAV,CAAsB,CAAtB,CAGE,CAAAuB,CAAApB,OAAA,CAAa,cAAb,CAAA,EAAiC+D,CAAAlE,CAAAkE,WAVvC,EAWI/E,CAAAgF,GAAA,CAAQ,UAAR,CAAoB,QAAQ,CAACC,CAAD,CAAQ,CAMlCC,QAASA,EAAQ,EAAG,CAClBL,CAAA,CAAGjE,CAAH,CAAU,CAAEuE,OAAQF,CAAV,CAAV,CADkB,CALpB,IAAIG,EAAUH,CAAAI,MAAVD,EAAyBH,CAAAG,QACb,GAAhB,GAAIA,CAAJ,EAAkC,EAAlC,GAAsBA,CAAtB,EACExE,CAAA0E,OAAA,CAAaJ,CAAb,CAHgC,CAApC,CAb6B,CAFP,CAFzB,CADwD,CAA5C,CAtJrB,CAAA/C,UAAA,CAwLW,YAxLX,CAwLyB,CAAC,OAAD,CAAU,QAAQ,CAACC,CAAD,CAAQ,CACjD,MAAO,SAAQ,CAACxB,CAAD;AAAQZ,CAAR,CAAca,CAAd,CAAoB,CAC7B,CAAAuB,CAAApB,OAAA,CAAa,UAAb,CAAJ,EAAiChB,CAAAa,KAAA,CAAU,UAAV,CAAjC,EAA2Dd,CAAA,CAAYC,CAAZ,CAAkBF,CAAlB,CAA3D,EACEE,CAAAa,KAAA,CAAU,UAAV,CAAsB,CAAtB,CAF+B,CADc,CAA1B,CAxLzB,CAvMsC,CAArC,CAAD,CAwYGlB,MAxYH,CAwYWA,MAAAC,QAxYX;", +"sources":["angular-aria.js"], +"names":["window","angular","undefined","nodeBlackList","isNodeOneOf","elem","nodeTypeArray","indexOf","nodeName","module","provider","ngAriaModule","$AriaProvider","watchExpr","attrName","ariaAttr","negate","scope","attr","ariaCamelName","$normalize","config","$watch","boolVal","ariaHidden","ariaChecked","ariaDisabled","ariaRequired","ariaInvalid","ariaValue","tabindex","bindKeypress","bindRoleForClick","this.config","newConfig","extend","$get","this.$get","key","$$watchExpr","directive","$aria","shouldAttachAttr","normalizedAttr","allowBlacklistEls","shouldAttachRole","role","getShape","type","restrict","require","priority","compile","shape","pre","ngModel","$isEmpty","ngModel.$isEmpty","value","post","ngAriaWatchModelValue","$modelValue","getRadioReaction","newVal","$viewValue","getCheckboxReaction","needsTabIndex","needsAriaValuemin","hasOwnProperty","needsAriaValuemax","needsAriaValuenow","$observe","ngAriaValueMinReaction","ngAriaValueNowReaction","$validators","required","ngAriaInvalidWatch","$invalid","ngAriaInvalidReaction","link","ngMessages","$parse","fn","ngClick","ngKeypress","on","event","callback","$event","keyCode","which","$apply"] +} diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-cookies.js b/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-cookies.js new file mode 100644 index 000000000..2157ef03f --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-cookies.js @@ -0,0 +1,322 @@ +/** + * @license AngularJS v1.5.0 + * (c) 2010-2016 Google, Inc. http://angularjs.org + * License: MIT + */ +(function(window, angular, undefined) {'use strict'; + +/** + * @ngdoc module + * @name ngCookies + * @description + * + * # ngCookies + * + * The `ngCookies` module provides a convenient wrapper for reading and writing browser cookies. + * + * + *
    + * + * See {@link ngCookies.$cookies `$cookies`} for usage. + */ + + +angular.module('ngCookies', ['ng']). + /** + * @ngdoc provider + * @name $cookiesProvider + * @description + * Use `$cookiesProvider` to change the default behavior of the {@link ngCookies.$cookies $cookies} service. + * */ + provider('$cookies', [function $CookiesProvider() { + /** + * @ngdoc property + * @name $cookiesProvider#defaults + * @description + * + * Object containing default options to pass when setting cookies. + * + * The object may have following properties: + * + * - **path** - `{string}` - The cookie will be available only for this path and its + * sub-paths. By default, this is the URL that appears in your `` tag. + * - **domain** - `{string}` - The cookie will be available only for this domain and + * its sub-domains. For security reasons the user agent will not accept the cookie + * if the current domain is not a sub-domain of this domain or equal to it. + * - **expires** - `{string|Date}` - String of the form "Wdy, DD Mon YYYY HH:MM:SS GMT" + * or a Date object indicating the exact date/time this cookie will expire. + * - **secure** - `{boolean}` - If `true`, then the cookie will only be available through a + * secured connection. + * + * Note: By default, the address that appears in your `` tag will be used as the path. + * This is important so that cookies will be visible for all routes when html5mode is enabled. + * + **/ + var defaults = this.defaults = {}; + + function calcOptions(options) { + return options ? angular.extend({}, defaults, options) : defaults; + } + + /** + * @ngdoc service + * @name $cookies + * + * @description + * Provides read/write access to browser's cookies. + * + *
    + * Up until Angular 1.3, `$cookies` exposed properties that represented the + * current browser cookie values. In version 1.4, this behavior has changed, and + * `$cookies` now provides a standard api of getters, setters etc. + *
    + * + * Requires the {@link ngCookies `ngCookies`} module to be installed. + * + * @example + * + * ```js + * angular.module('cookiesExample', ['ngCookies']) + * .controller('ExampleController', ['$cookies', function($cookies) { + * // Retrieving a cookie + * var favoriteCookie = $cookies.get('myFavorite'); + * // Setting a cookie + * $cookies.put('myFavorite', 'oatmeal'); + * }]); + * ``` + */ + this.$get = ['$$cookieReader', '$$cookieWriter', function($$cookieReader, $$cookieWriter) { + return { + /** + * @ngdoc method + * @name $cookies#get + * + * @description + * Returns the value of given cookie key + * + * @param {string} key Id to use for lookup. + * @returns {string} Raw cookie value. + */ + get: function(key) { + return $$cookieReader()[key]; + }, + + /** + * @ngdoc method + * @name $cookies#getObject + * + * @description + * Returns the deserialized value of given cookie key + * + * @param {string} key Id to use for lookup. + * @returns {Object} Deserialized cookie value. + */ + getObject: function(key) { + var value = this.get(key); + return value ? angular.fromJson(value) : value; + }, + + /** + * @ngdoc method + * @name $cookies#getAll + * + * @description + * Returns a key value object with all the cookies + * + * @returns {Object} All cookies + */ + getAll: function() { + return $$cookieReader(); + }, + + /** + * @ngdoc method + * @name $cookies#put + * + * @description + * Sets a value for given cookie key + * + * @param {string} key Id for the `value`. + * @param {string} value Raw value to be stored. + * @param {Object=} options Options object. + * See {@link ngCookies.$cookiesProvider#defaults $cookiesProvider.defaults} + */ + put: function(key, value, options) { + $$cookieWriter(key, value, calcOptions(options)); + }, + + /** + * @ngdoc method + * @name $cookies#putObject + * + * @description + * Serializes and sets a value for given cookie key + * + * @param {string} key Id for the `value`. + * @param {Object} value Value to be stored. + * @param {Object=} options Options object. + * See {@link ngCookies.$cookiesProvider#defaults $cookiesProvider.defaults} + */ + putObject: function(key, value, options) { + this.put(key, angular.toJson(value), options); + }, + + /** + * @ngdoc method + * @name $cookies#remove + * + * @description + * Remove given cookie + * + * @param {string} key Id of the key-value pair to delete. + * @param {Object=} options Options object. + * See {@link ngCookies.$cookiesProvider#defaults $cookiesProvider.defaults} + */ + remove: function(key, options) { + $$cookieWriter(key, undefined, calcOptions(options)); + } + }; + }]; + }]); + +angular.module('ngCookies'). +/** + * @ngdoc service + * @name $cookieStore + * @deprecated + * @requires $cookies + * + * @description + * Provides a key-value (string-object) storage, that is backed by session cookies. + * Objects put or retrieved from this storage are automatically serialized or + * deserialized by angular's toJson/fromJson. + * + * Requires the {@link ngCookies `ngCookies`} module to be installed. + * + *
    + * **Note:** The $cookieStore service is **deprecated**. + * Please use the {@link ngCookies.$cookies `$cookies`} service instead. + *
    + * + * @example + * + * ```js + * angular.module('cookieStoreExample', ['ngCookies']) + * .controller('ExampleController', ['$cookieStore', function($cookieStore) { + * // Put cookie + * $cookieStore.put('myFavorite','oatmeal'); + * // Get cookie + * var favoriteCookie = $cookieStore.get('myFavorite'); + * // Removing a cookie + * $cookieStore.remove('myFavorite'); + * }]); + * ``` + */ + factory('$cookieStore', ['$cookies', function($cookies) { + + return { + /** + * @ngdoc method + * @name $cookieStore#get + * + * @description + * Returns the value of given cookie key + * + * @param {string} key Id to use for lookup. + * @returns {Object} Deserialized cookie value, undefined if the cookie does not exist. + */ + get: function(key) { + return $cookies.getObject(key); + }, + + /** + * @ngdoc method + * @name $cookieStore#put + * + * @description + * Sets a value for given cookie key + * + * @param {string} key Id for the `value`. + * @param {Object} value Value to be stored. + */ + put: function(key, value) { + $cookies.putObject(key, value); + }, + + /** + * @ngdoc method + * @name $cookieStore#remove + * + * @description + * Remove given cookie + * + * @param {string} key Id of the key-value pair to delete. + */ + remove: function(key) { + $cookies.remove(key); + } + }; + + }]); + +/** + * @name $$cookieWriter + * @requires $document + * + * @description + * This is a private service for writing cookies + * + * @param {string} name Cookie name + * @param {string=} value Cookie value (if undefined, cookie will be deleted) + * @param {Object=} options Object with options that need to be stored for the cookie. + */ +function $$CookieWriter($document, $log, $browser) { + var cookiePath = $browser.baseHref(); + var rawDocument = $document[0]; + + function buildCookieString(name, value, options) { + var path, expires; + options = options || {}; + expires = options.expires; + path = angular.isDefined(options.path) ? options.path : cookiePath; + if (angular.isUndefined(value)) { + expires = 'Thu, 01 Jan 1970 00:00:00 GMT'; + value = ''; + } + if (angular.isString(expires)) { + expires = new Date(expires); + } + + var str = encodeURIComponent(name) + '=' + encodeURIComponent(value); + str += path ? ';path=' + path : ''; + str += options.domain ? ';domain=' + options.domain : ''; + str += expires ? ';expires=' + expires.toUTCString() : ''; + str += options.secure ? ';secure' : ''; + + // per http://www.ietf.org/rfc/rfc2109.txt browser must allow at minimum: + // - 300 cookies + // - 20 cookies per unique domain + // - 4096 bytes per cookie + var cookieLength = str.length + 1; + if (cookieLength > 4096) { + $log.warn("Cookie '" + name + + "' possibly not set or overflowed because it was too large (" + + cookieLength + " > 4096 bytes)!"); + } + + return str; + } + + return function(name, value, options) { + rawDocument.cookie = buildCookieString(name, value, options); + }; +} + +$$CookieWriter.$inject = ['$document', '$log', '$browser']; + +angular.module('ngCookies').provider('$$cookieWriter', function $$CookieWriterProvider() { + this.$get = $$CookieWriter; +}); + + +})(window, window.angular); diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-cookies.min.js b/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-cookies.min.js new file mode 100644 index 000000000..d0f126a95 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-cookies.min.js @@ -0,0 +1,9 @@ +/* + AngularJS v1.5.0 + (c) 2010-2016 Google, Inc. http://angularjs.org + License: MIT +*/ +(function(p,c,n){'use strict';function l(b,a,g){var d=g.baseHref(),k=b[0];return function(b,e,f){var g,h;f=f||{};h=f.expires;g=c.isDefined(f.path)?f.path:d;c.isUndefined(e)&&(h="Thu, 01 Jan 1970 00:00:00 GMT",e="");c.isString(h)&&(h=new Date(h));e=encodeURIComponent(b)+"="+encodeURIComponent(e);e=e+(g?";path="+g:"")+(f.domain?";domain="+f.domain:"");e+=h?";expires="+h.toUTCString():"";e+=f.secure?";secure":"";f=e.length+1;4096 4096 bytes)!");k.cookie=e}}c.module("ngCookies",["ng"]).provider("$cookies",[function(){var b=this.defaults={};this.$get=["$$cookieReader","$$cookieWriter",function(a,g){return{get:function(d){return a()[d]},getObject:function(d){return(d=this.get(d))?c.fromJson(d):d},getAll:function(){return a()},put:function(d,a,m){g(d,a,m?c.extend({},b,m):b)},putObject:function(d,b,a){this.put(d,c.toJson(b),a)},remove:function(a,k){g(a,n,k?c.extend({},b,k):b)}}}]}]);c.module("ngCookies").factory("$cookieStore", +["$cookies",function(b){return{get:function(a){return b.getObject(a)},put:function(a,c){b.putObject(a,c)},remove:function(a){b.remove(a)}}}]);l.$inject=["$document","$log","$browser"];c.module("ngCookies").provider("$$cookieWriter",function(){this.$get=l})})(window,window.angular); +//# sourceMappingURL=angular-cookies.min.js.map diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-cookies.min.js.map b/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-cookies.min.js.map new file mode 100644 index 000000000..555b5103b --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-cookies.min.js.map @@ -0,0 +1,8 @@ +{ +"version":3, +"file":"angular-cookies.min.js", +"lineCount":8, +"mappings":"A;;;;;aAKC,SAAQ,CAACA,CAAD,CAASC,CAAT,CAAkBC,CAAlB,CAA6B,CA2QtCC,QAASA,EAAc,CAACC,CAAD,CAAYC,CAAZ,CAAkBC,CAAlB,CAA4B,CACjD,IAAIC,EAAaD,CAAAE,SAAA,EAAjB,CACIC,EAAcL,CAAA,CAAU,CAAV,CAmClB,OAAO,SAAQ,CAACM,CAAD,CAAOC,CAAP,CAAcC,CAAd,CAAuB,CAjCW,IAC3CC,CAD2C,CACrCC,CACVF,EAAA,CAgCoDA,CAhCpD,EAAqB,EACrBE,EAAA,CAAUF,CAAAE,QACVD,EAAA,CAAOZ,CAAAc,UAAA,CAAkBH,CAAAC,KAAlB,CAAA,CAAkCD,CAAAC,KAAlC,CAAiDN,CACpDN,EAAAe,YAAA,CAAoBL,CAApB,CAAJ,GACEG,CACA,CADU,+BACV,CAAAH,CAAA,CAAQ,EAFV,CAIIV,EAAAgB,SAAA,CAAiBH,CAAjB,CAAJ,GACEA,CADF,CACY,IAAII,IAAJ,CAASJ,CAAT,CADZ,CAIIK,EAAAA,CAAMC,kBAAA,CAqB6BV,CArB7B,CAANS,CAAiC,GAAjCA,CAAuCC,kBAAA,CAAmBT,CAAnB,CAE3CQ,EAAA,CADAA,CACA,EADON,CAAA,CAAO,QAAP,CAAkBA,CAAlB,CAAyB,EAChC,GAAOD,CAAAS,OAAA,CAAiB,UAAjB,CAA8BT,CAAAS,OAA9B,CAA+C,EAAtD,CACAF,EAAA,EAAOL,CAAA,CAAU,WAAV,CAAwBA,CAAAQ,YAAA,EAAxB,CAAgD,EACvDH,EAAA,EAAOP,CAAAW,OAAA,CAAiB,SAAjB,CAA6B,EAMhCC,EAAAA,CAAeL,CAAAM,OAAfD,CAA4B,CACb,KAAnB,CAAIA,CAAJ,EACEnB,CAAAqB,KAAA,CAAU,UAAV,CASqChB,CATrC,CACE,6DADF;AAEEc,CAFF,CAEiB,iBAFjB,CASFf,EAAAkB,OAAA,CAJOR,CAG6B,CArCW,CAzPnDlB,CAAA2B,OAAA,CAAe,WAAf,CAA4B,CAAC,IAAD,CAA5B,CAAAC,SAAA,CAOY,UAPZ,CAOwB,CAACC,QAAyB,EAAG,CAwBjD,IAAIC,EAAW,IAAAA,SAAXA,CAA2B,EAiC/B,KAAAC,KAAA,CAAY,CAAC,gBAAD,CAAmB,gBAAnB,CAAqC,QAAQ,CAACC,CAAD,CAAiBC,CAAjB,CAAiC,CACxF,MAAO,CAWLC,IAAKA,QAAQ,CAACC,CAAD,CAAM,CACjB,MAAOH,EAAA,EAAA,CAAiBG,CAAjB,CADU,CAXd,CAyBLC,UAAWA,QAAQ,CAACD,CAAD,CAAM,CAEvB,MAAO,CADHzB,CACG,CADK,IAAAwB,IAAA,CAASC,CAAT,CACL,EAAQnC,CAAAqC,SAAA,CAAiB3B,CAAjB,CAAR,CAAkCA,CAFlB,CAzBpB,CAuCL4B,OAAQA,QAAQ,EAAG,CACjB,MAAON,EAAA,EADU,CAvCd,CAuDLO,IAAKA,QAAQ,CAACJ,CAAD,CAAMzB,CAAN,CAAaC,CAAb,CAAsB,CACjCsB,CAAA,CAAeE,CAAf,CAAoBzB,CAApB,CAAuCC,CAvFpC,CAAUX,CAAAwC,OAAA,CAAe,EAAf,CAAmBV,CAAnB,CAuF0BnB,CAvF1B,CAAV,CAAkDmB,CAuFrD,CADiC,CAvD9B,CAuELW,UAAWA,QAAQ,CAACN,CAAD,CAAMzB,CAAN,CAAaC,CAAb,CAAsB,CACvC,IAAA4B,IAAA,CAASJ,CAAT,CAAcnC,CAAA0C,OAAA,CAAehC,CAAf,CAAd,CAAqCC,CAArC,CADuC,CAvEpC,CAsFLgC,OAAQA,QAAQ,CAACR,CAAD,CAAMxB,CAAN,CAAe,CAC7BsB,CAAA,CAAeE,CAAf,CAAoBlC,CAApB,CAA2CU,CAtHxC,CAAUX,CAAAwC,OAAA,CAAe,EAAf,CAAmBV,CAAnB,CAsH8BnB,CAtH9B,CAAV,CAAkDmB,CAsHrD,CAD6B,CAtF1B,CADiF,CAA9E,CAzDqC,CAA7B,CAPxB,CA8JA9B,EAAA2B,OAAA,CAAe,WAAf,CAAAiB,QAAA,CAiCS,cAjCT;AAiCyB,CAAC,UAAD,CAAa,QAAQ,CAACC,CAAD,CAAW,CAErD,MAAO,CAWLX,IAAKA,QAAQ,CAACC,CAAD,CAAM,CACjB,MAAOU,EAAAT,UAAA,CAAmBD,CAAnB,CADU,CAXd,CAyBLI,IAAKA,QAAQ,CAACJ,CAAD,CAAMzB,CAAN,CAAa,CACxBmC,CAAAJ,UAAA,CAAmBN,CAAnB,CAAwBzB,CAAxB,CADwB,CAzBrB,CAsCLiC,OAAQA,QAAQ,CAACR,CAAD,CAAM,CACpBU,CAAAF,OAAA,CAAgBR,CAAhB,CADoB,CAtCjB,CAF8C,CAAhC,CAjCzB,CAqIAjC,EAAA4C,QAAA,CAAyB,CAAC,WAAD,CAAc,MAAd,CAAsB,UAAtB,CAEzB9C,EAAA2B,OAAA,CAAe,WAAf,CAAAC,SAAA,CAAqC,gBAArC,CAAuDmB,QAA+B,EAAG,CACvF,IAAAhB,KAAA,CAAY7B,CAD2E,CAAzF,CAvTsC,CAArC,CAAD,CA4TGH,MA5TH,CA4TWA,MAAAC,QA5TX;", +"sources":["angular-cookies.js"], +"names":["window","angular","undefined","$$CookieWriter","$document","$log","$browser","cookiePath","baseHref","rawDocument","name","value","options","path","expires","isDefined","isUndefined","isString","Date","str","encodeURIComponent","domain","toUTCString","secure","cookieLength","length","warn","cookie","module","provider","$CookiesProvider","defaults","$get","$$cookieReader","$$cookieWriter","get","key","getObject","fromJson","getAll","put","extend","putObject","toJson","remove","factory","$cookies","$inject","$$CookieWriterProvider"] +} diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-csp.css b/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-csp.css new file mode 100644 index 000000000..23134fdfb --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-csp.css @@ -0,0 +1,20 @@ + +@charset "UTF-8"; + +[ng\:cloak], [ng-cloak], [data-ng-cloak], [x-ng-cloak], +.ng-cloak, .x-ng-cloak, +.ng-hide:not(.ng-hide-animate) { + display: none !important; +} + +ng\:form { + display: block; +} + +.ng-animate-shim { + visibility:hidden; +} + +.ng-anchor { + position:absolute; +} diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-loader.js b/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-loader.js new file mode 100644 index 000000000..77948fd58 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-loader.js @@ -0,0 +1,484 @@ +/** + * @license AngularJS v1.5.0 + * (c) 2010-2016 Google, Inc. http://angularjs.org + * License: MIT + */ + +(function() {'use strict'; + function isFunction(value) {return typeof value === 'function';}; + +/* global: toDebugString: true */ + +function serializeObject(obj) { + var seen = []; + + return JSON.stringify(obj, function(key, val) { + val = toJsonReplacer(key, val); + if (isObject(val)) { + + if (seen.indexOf(val) >= 0) return '...'; + + seen.push(val); + } + return val; + }); +} + +function toDebugString(obj) { + if (typeof obj === 'function') { + return obj.toString().replace(/ \{[\s\S]*$/, ''); + } else if (isUndefined(obj)) { + return 'undefined'; + } else if (typeof obj !== 'string') { + return serializeObject(obj); + } + return obj; +} + +/** + * @description + * + * This object provides a utility for producing rich Error messages within + * Angular. It can be called as follows: + * + * var exampleMinErr = minErr('example'); + * throw exampleMinErr('one', 'This {0} is {1}', foo, bar); + * + * The above creates an instance of minErr in the example namespace. The + * resulting error will have a namespaced error code of example.one. The + * resulting error will replace {0} with the value of foo, and {1} with the + * value of bar. The object is not restricted in the number of arguments it can + * take. + * + * If fewer arguments are specified than necessary for interpolation, the extra + * interpolation markers will be preserved in the final string. + * + * Since data will be parsed statically during a build step, some restrictions + * are applied with respect to how minErr instances are created and called. + * Instances should have names of the form namespaceMinErr for a minErr created + * using minErr('namespace') . Error codes, namespaces and template strings + * should all be static strings, not variables or general expressions. + * + * @param {string} module The namespace to use for the new minErr instance. + * @param {function} ErrorConstructor Custom error constructor to be instantiated when returning + * error from returned function, for cases when a particular type of error is useful. + * @returns {function(code:string, template:string, ...templateArgs): Error} minErr instance + */ + +function minErr(module, ErrorConstructor) { + ErrorConstructor = ErrorConstructor || Error; + return function() { + var SKIP_INDEXES = 2; + + var templateArgs = arguments, + code = templateArgs[0], + message = '[' + (module ? module + ':' : '') + code + '] ', + template = templateArgs[1], + paramPrefix, i; + + message += template.replace(/\{\d+\}/g, function(match) { + var index = +match.slice(1, -1), + shiftedIndex = index + SKIP_INDEXES; + + if (shiftedIndex < templateArgs.length) { + return toDebugString(templateArgs[shiftedIndex]); + } + + return match; + }); + + message += '\nhttp://errors.angularjs.org/1.5.0/' + + (module ? module + '/' : '') + code; + + for (i = SKIP_INDEXES, paramPrefix = '?'; i < templateArgs.length; i++, paramPrefix = '&') { + message += paramPrefix + 'p' + (i - SKIP_INDEXES) + '=' + + encodeURIComponent(toDebugString(templateArgs[i])); + } + + return new ErrorConstructor(message); + }; +} + +/** + * @ngdoc type + * @name angular.Module + * @module ng + * @description + * + * Interface for configuring angular {@link angular.module modules}. + */ + +function setupModuleLoader(window) { + + var $injectorMinErr = minErr('$injector'); + var ngMinErr = minErr('ng'); + + function ensure(obj, name, factory) { + return obj[name] || (obj[name] = factory()); + } + + var angular = ensure(window, 'angular', Object); + + // We need to expose `angular.$$minErr` to modules such as `ngResource` that reference it during bootstrap + angular.$$minErr = angular.$$minErr || minErr; + + return ensure(angular, 'module', function() { + /** @type {Object.} */ + var modules = {}; + + /** + * @ngdoc function + * @name angular.module + * @module ng + * @description + * + * The `angular.module` is a global place for creating, registering and retrieving Angular + * modules. + * All modules (angular core or 3rd party) that should be available to an application must be + * registered using this mechanism. + * + * Passing one argument retrieves an existing {@link angular.Module}, + * whereas passing more than one argument creates a new {@link angular.Module} + * + * + * # Module + * + * A module is a collection of services, directives, controllers, filters, and configuration information. + * `angular.module` is used to configure the {@link auto.$injector $injector}. + * + * ```js + * // Create a new module + * var myModule = angular.module('myModule', []); + * + * // register a new service + * myModule.value('appName', 'MyCoolApp'); + * + * // configure existing services inside initialization blocks. + * myModule.config(['$locationProvider', function($locationProvider) { + * // Configure existing providers + * $locationProvider.hashPrefix('!'); + * }]); + * ``` + * + * Then you can create an injector and load your modules like this: + * + * ```js + * var injector = angular.injector(['ng', 'myModule']) + * ``` + * + * However it's more likely that you'll just use + * {@link ng.directive:ngApp ngApp} or + * {@link angular.bootstrap} to simplify this process for you. + * + * @param {!string} name The name of the module to create or retrieve. + * @param {!Array.=} requires If specified then new module is being created. If + * unspecified then the module is being retrieved for further configuration. + * @param {Function=} configFn Optional configuration function for the module. Same as + * {@link angular.Module#config Module#config()}. + * @returns {angular.Module} new module with the {@link angular.Module} api. + */ + return function module(name, requires, configFn) { + var assertNotHasOwnProperty = function(name, context) { + if (name === 'hasOwnProperty') { + throw ngMinErr('badname', 'hasOwnProperty is not a valid {0} name', context); + } + }; + + assertNotHasOwnProperty(name, 'module'); + if (requires && modules.hasOwnProperty(name)) { + modules[name] = null; + } + return ensure(modules, name, function() { + if (!requires) { + throw $injectorMinErr('nomod', "Module '{0}' is not available! You either misspelled " + + "the module name or forgot to load it. If registering a module ensure that you " + + "specify the dependencies as the second argument.", name); + } + + /** @type {!Array.>} */ + var invokeQueue = []; + + /** @type {!Array.} */ + var configBlocks = []; + + /** @type {!Array.} */ + var runBlocks = []; + + var config = invokeLater('$injector', 'invoke', 'push', configBlocks); + + /** @type {angular.Module} */ + var moduleInstance = { + // Private state + _invokeQueue: invokeQueue, + _configBlocks: configBlocks, + _runBlocks: runBlocks, + + /** + * @ngdoc property + * @name angular.Module#requires + * @module ng + * + * @description + * Holds the list of modules which the injector will load before the current module is + * loaded. + */ + requires: requires, + + /** + * @ngdoc property + * @name angular.Module#name + * @module ng + * + * @description + * Name of the module. + */ + name: name, + + + /** + * @ngdoc method + * @name angular.Module#provider + * @module ng + * @param {string} name service name + * @param {Function} providerType Construction function for creating new instance of the + * service. + * @description + * See {@link auto.$provide#provider $provide.provider()}. + */ + provider: invokeLaterAndSetModuleName('$provide', 'provider'), + + /** + * @ngdoc method + * @name angular.Module#factory + * @module ng + * @param {string} name service name + * @param {Function} providerFunction Function for creating new instance of the service. + * @description + * See {@link auto.$provide#factory $provide.factory()}. + */ + factory: invokeLaterAndSetModuleName('$provide', 'factory'), + + /** + * @ngdoc method + * @name angular.Module#service + * @module ng + * @param {string} name service name + * @param {Function} constructor A constructor function that will be instantiated. + * @description + * See {@link auto.$provide#service $provide.service()}. + */ + service: invokeLaterAndSetModuleName('$provide', 'service'), + + /** + * @ngdoc method + * @name angular.Module#value + * @module ng + * @param {string} name service name + * @param {*} object Service instance object. + * @description + * See {@link auto.$provide#value $provide.value()}. + */ + value: invokeLater('$provide', 'value'), + + /** + * @ngdoc method + * @name angular.Module#constant + * @module ng + * @param {string} name constant name + * @param {*} object Constant value. + * @description + * Because the constants are fixed, they get applied before other provide methods. + * See {@link auto.$provide#constant $provide.constant()}. + */ + constant: invokeLater('$provide', 'constant', 'unshift'), + + /** + * @ngdoc method + * @name angular.Module#decorator + * @module ng + * @param {string} The name of the service to decorate. + * @param {Function} This function will be invoked when the service needs to be + * instantiated and should return the decorated service instance. + * @description + * See {@link auto.$provide#decorator $provide.decorator()}. + */ + decorator: invokeLaterAndSetModuleName('$provide', 'decorator'), + + /** + * @ngdoc method + * @name angular.Module#animation + * @module ng + * @param {string} name animation name + * @param {Function} animationFactory Factory function for creating new instance of an + * animation. + * @description + * + * **NOTE**: animations take effect only if the **ngAnimate** module is loaded. + * + * + * Defines an animation hook that can be later used with + * {@link $animate $animate} service and directives that use this service. + * + * ```js + * module.animation('.animation-name', function($inject1, $inject2) { + * return { + * eventName : function(element, done) { + * //code to run the animation + * //once complete, then run done() + * return function cancellationFunction(element) { + * //code to cancel the animation + * } + * } + * } + * }) + * ``` + * + * See {@link ng.$animateProvider#register $animateProvider.register()} and + * {@link ngAnimate ngAnimate module} for more information. + */ + animation: invokeLaterAndSetModuleName('$animateProvider', 'register'), + + /** + * @ngdoc method + * @name angular.Module#filter + * @module ng + * @param {string} name Filter name - this must be a valid angular expression identifier + * @param {Function} filterFactory Factory function for creating new instance of filter. + * @description + * See {@link ng.$filterProvider#register $filterProvider.register()}. + * + *
    + * **Note:** Filter names must be valid angular {@link expression} identifiers, such as `uppercase` or `orderBy`. + * Names with special characters, such as hyphens and dots, are not allowed. If you wish to namespace + * your filters, then you can use capitalization (`myappSubsectionFilterx`) or underscores + * (`myapp_subsection_filterx`). + *
    + */ + filter: invokeLaterAndSetModuleName('$filterProvider', 'register'), + + /** + * @ngdoc method + * @name angular.Module#controller + * @module ng + * @param {string|Object} name Controller name, or an object map of controllers where the + * keys are the names and the values are the constructors. + * @param {Function} constructor Controller constructor function. + * @description + * See {@link ng.$controllerProvider#register $controllerProvider.register()}. + */ + controller: invokeLaterAndSetModuleName('$controllerProvider', 'register'), + + /** + * @ngdoc method + * @name angular.Module#directive + * @module ng + * @param {string|Object} name Directive name, or an object map of directives where the + * keys are the names and the values are the factories. + * @param {Function} directiveFactory Factory function for creating new instance of + * directives. + * @description + * See {@link ng.$compileProvider#directive $compileProvider.directive()}. + */ + directive: invokeLaterAndSetModuleName('$compileProvider', 'directive'), + + /** + * @ngdoc method + * @name angular.Module#component + * @module ng + * @param {string} name Name of the component in camel-case (i.e. myComp which will match as my-comp) + * @param {Object} options Component definition object (a simplified + * {@link ng.$compile#directive-definition-object directive definition object}) + * + * @description + * See {@link ng.$compileProvider#component $compileProvider.component()}. + */ + component: invokeLaterAndSetModuleName('$compileProvider', 'component'), + + /** + * @ngdoc method + * @name angular.Module#config + * @module ng + * @param {Function} configFn Execute this function on module load. Useful for service + * configuration. + * @description + * Use this method to register work which needs to be performed on module loading. + * For more about how to configure services, see + * {@link providers#provider-recipe Provider Recipe}. + */ + config: config, + + /** + * @ngdoc method + * @name angular.Module#run + * @module ng + * @param {Function} initializationFn Execute this function after injector creation. + * Useful for application initialization. + * @description + * Use this method to register work which should be performed when the injector is done + * loading all modules. + */ + run: function(block) { + runBlocks.push(block); + return this; + } + }; + + if (configFn) { + config(configFn); + } + + return moduleInstance; + + /** + * @param {string} provider + * @param {string} method + * @param {String=} insertMethod + * @returns {angular.Module} + */ + function invokeLater(provider, method, insertMethod, queue) { + if (!queue) queue = invokeQueue; + return function() { + queue[insertMethod || 'push']([provider, method, arguments]); + return moduleInstance; + }; + } + + /** + * @param {string} provider + * @param {string} method + * @returns {angular.Module} + */ + function invokeLaterAndSetModuleName(provider, method) { + return function(recipeName, factoryFunction) { + if (factoryFunction && isFunction(factoryFunction)) factoryFunction.$$moduleName = name; + invokeQueue.push([provider, method, arguments]); + return moduleInstance; + }; + } + }); + }; + }); + +} + +setupModuleLoader(window); +})(window); + +/** + * Closure compiler type information + * + * @typedef { { + * requires: !Array., + * invokeQueue: !Array.>, + * + * service: function(string, Function):angular.Module, + * factory: function(string, Function):angular.Module, + * value: function(string, *):angular.Module, + * + * filter: function(string, Function):angular.Module, + * + * init: function(Function):angular.Module + * } } + */ +angular.Module; + diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-loader.min.js b/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-loader.min.js new file mode 100644 index 000000000..316ee26e9 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-loader.min.js @@ -0,0 +1,10 @@ +/* + AngularJS v1.5.0 + (c) 2010-2016 Google, Inc. http://angularjs.org + License: MIT +*/ +(function(){'use strict';function d(b){return function(){var a=arguments[0],e;e="["+(b?b+":":"")+a+"] http://errors.angularjs.org/1.5.0/"+(b?b+"/":"")+a;for(a=1;a= line.length) { + index -= line.length; + } else { + return { line: i + 1, column: index + 1 }; + } + } +} +var PARSE_CACHE_FOR_TEXT_LITERALS = Object.create(null); + +function parseTextLiteral(text) { + var cachedFn = PARSE_CACHE_FOR_TEXT_LITERALS[text]; + if (cachedFn != null) { + return cachedFn; + } + function parsedFn(context) { return text; } + parsedFn['$$watchDelegate'] = function watchDelegate(scope, listener, objectEquality) { + var unwatch = scope['$watch'](noop, + function textLiteralWatcher() { + if (isFunction(listener)) { listener.call(null, text, text, scope); } + unwatch(); + }, + objectEquality); + return unwatch; + }; + PARSE_CACHE_FOR_TEXT_LITERALS[text] = parsedFn; + parsedFn['exp'] = text; // Needed to pretend to be $interpolate for tests copied from interpolateSpec.js + parsedFn['expressions'] = []; // Require this to call $compile.$$addBindingInfo() which allows Protractor to find elements by binding. + return parsedFn; +} + +function subtractOffset(expressionFn, offset) { + if (offset === 0) { + return expressionFn; + } + function minusOffset(value) { + return (value == void 0) ? value : value - offset; + } + function parsedFn(context) { return minusOffset(expressionFn(context)); } + var unwatch; + parsedFn['$$watchDelegate'] = function watchDelegate(scope, listener, objectEquality) { + unwatch = scope['$watch'](expressionFn, + function pluralExpressionWatchListener(newValue, oldValue) { + if (isFunction(listener)) { listener.call(null, minusOffset(newValue), minusOffset(oldValue), scope); } + }, + objectEquality); + return unwatch; + }; + return parsedFn; +} + +// NOTE: ADVANCED_OPTIMIZATIONS mode. +// +// This file is compiled with Closure compiler's ADVANCED_OPTIMIZATIONS flag! Be wary of using +// constructs incompatible with that mode. + +/* global $interpolateMinErr: false */ +/* global isFunction: false */ +/* global noop: false */ + +/** + * @constructor + * @private + */ +function MessageSelectorBase(expressionFn, choices) { + var self = this; + this.expressionFn = expressionFn; + this.choices = choices; + if (choices["other"] === void 0) { + throw $interpolateMinErr('reqother', '“other” is a required option.'); + } + this.parsedFn = function(context) { return self.getResult(context); }; + this.parsedFn['$$watchDelegate'] = function $$watchDelegate(scope, listener, objectEquality) { + return self.watchDelegate(scope, listener, objectEquality); + }; + this.parsedFn['exp'] = expressionFn['exp']; + this.parsedFn['expressions'] = expressionFn['expressions']; +} + +MessageSelectorBase.prototype.getMessageFn = function getMessageFn(value) { + return this.choices[this.categorizeValue(value)]; +}; + +MessageSelectorBase.prototype.getResult = function getResult(context) { + return this.getMessageFn(this.expressionFn(context))(context); +}; + +MessageSelectorBase.prototype.watchDelegate = function watchDelegate(scope, listener, objectEquality) { + var watchers = new MessageSelectorWatchers(this, scope, listener, objectEquality); + return function() { watchers.cancelWatch(); }; +}; + +/** + * @constructor + * @private + */ +function MessageSelectorWatchers(msgSelector, scope, listener, objectEquality) { + var self = this; + this.scope = scope; + this.msgSelector = msgSelector; + this.listener = listener; + this.objectEquality = objectEquality; + this.lastMessage = void 0; + this.messageFnWatcher = noop; + var expressionFnListener = function(newValue, oldValue) { return self.expressionFnListener(newValue, oldValue); }; + this.expressionFnWatcher = scope['$watch'](msgSelector.expressionFn, expressionFnListener, objectEquality); +} + +MessageSelectorWatchers.prototype.expressionFnListener = function expressionFnListener(newValue, oldValue) { + var self = this; + this.messageFnWatcher(); + var messageFnListener = function(newMessage, oldMessage) { return self.messageFnListener(newMessage, oldMessage); }; + var messageFn = this.msgSelector.getMessageFn(newValue); + this.messageFnWatcher = this.scope['$watch'](messageFn, messageFnListener, this.objectEquality); +}; + +MessageSelectorWatchers.prototype.messageFnListener = function messageFnListener(newMessage, oldMessage) { + if (isFunction(this.listener)) { + this.listener.call(null, newMessage, newMessage === oldMessage ? newMessage : this.lastMessage, this.scope); + } + this.lastMessage = newMessage; +}; + +MessageSelectorWatchers.prototype.cancelWatch = function cancelWatch() { + this.expressionFnWatcher(); + this.messageFnWatcher(); +}; + +/** + * @constructor + * @extends MessageSelectorBase + * @private + */ +function SelectMessage(expressionFn, choices) { + MessageSelectorBase.call(this, expressionFn, choices); +} + +function SelectMessageProto() {} +SelectMessageProto.prototype = MessageSelectorBase.prototype; + +SelectMessage.prototype = new SelectMessageProto(); +SelectMessage.prototype.categorizeValue = function categorizeSelectValue(value) { + return (this.choices[value] !== void 0) ? value : "other"; +}; + +/** + * @constructor + * @extends MessageSelectorBase + * @private + */ +function PluralMessage(expressionFn, choices, offset, pluralCat) { + MessageSelectorBase.call(this, expressionFn, choices); + this.offset = offset; + this.pluralCat = pluralCat; +} + +function PluralMessageProto() {} +PluralMessageProto.prototype = MessageSelectorBase.prototype; + +PluralMessage.prototype = new PluralMessageProto(); +PluralMessage.prototype.categorizeValue = function categorizePluralValue(value) { + if (isNaN(value)) { + return "other"; + } else if (this.choices[value] !== void 0) { + return value; + } else { + var category = this.pluralCat(value - this.offset); + return (this.choices[category] !== void 0) ? category : "other"; + } +}; + +// NOTE: ADVANCED_OPTIMIZATIONS mode. +// +// This file is compiled with Closure compiler's ADVANCED_OPTIMIZATIONS flag! Be wary of using +// constructs incompatible with that mode. + +/* global $interpolateMinErr: false */ +/* global isFunction: false */ +/* global parseTextLiteral: false */ + +/** + * @constructor + * @private + */ +function InterpolationParts(trustedContext, allOrNothing) { + this.trustedContext = trustedContext; + this.allOrNothing = allOrNothing; + this.textParts = []; + this.expressionFns = []; + this.expressionIndices = []; + this.partialText = ''; + this.concatParts = null; +} + +InterpolationParts.prototype.flushPartialText = function flushPartialText() { + if (this.partialText) { + if (this.concatParts == null) { + this.textParts.push(this.partialText); + } else { + this.textParts.push(this.concatParts.join('')); + this.concatParts = null; + } + this.partialText = ''; + } +}; + +InterpolationParts.prototype.addText = function addText(text) { + if (text.length) { + if (!this.partialText) { + this.partialText = text; + } else if (this.concatParts) { + this.concatParts.push(text); + } else { + this.concatParts = [this.partialText, text]; + } + } +}; + +InterpolationParts.prototype.addExpressionFn = function addExpressionFn(expressionFn) { + this.flushPartialText(); + this.expressionIndices.push(this.textParts.length); + this.expressionFns.push(expressionFn); + this.textParts.push(''); +}; + +InterpolationParts.prototype.getExpressionValues = function getExpressionValues(context) { + var expressionValues = new Array(this.expressionFns.length); + for (var i = 0; i < this.expressionFns.length; i++) { + expressionValues[i] = this.expressionFns[i](context); + } + return expressionValues; +}; + +InterpolationParts.prototype.getResult = function getResult(expressionValues) { + for (var i = 0; i < this.expressionIndices.length; i++) { + var expressionValue = expressionValues[i]; + if (this.allOrNothing && expressionValue === void 0) return; + this.textParts[this.expressionIndices[i]] = expressionValue; + } + return this.textParts.join(''); +}; + + +InterpolationParts.prototype.toParsedFn = function toParsedFn(mustHaveExpression, originalText) { + var self = this; + this.flushPartialText(); + if (mustHaveExpression && this.expressionFns.length === 0) { + return void 0; + } + if (this.textParts.length === 0) { + return parseTextLiteral(''); + } + if (this.trustedContext && this.textParts.length > 1) { + $interpolateMinErr['throwNoconcat'](originalText); + } + if (this.expressionFns.length === 0) { + if (this.textParts.length != 1) { this.errorInParseLogic(); } + return parseTextLiteral(this.textParts[0]); + } + var parsedFn = function(context) { + return self.getResult(self.getExpressionValues(context)); + }; + parsedFn['$$watchDelegate'] = function $$watchDelegate(scope, listener, objectEquality) { + return self.watchDelegate(scope, listener, objectEquality); + }; + + parsedFn['exp'] = originalText; // Needed to pretend to be $interpolate for tests copied from interpolateSpec.js + parsedFn['expressions'] = new Array(this.expressionFns.length); // Require this to call $compile.$$addBindingInfo() which allows Protractor to find elements by binding. + for (var i = 0; i < this.expressionFns.length; i++) { + parsedFn['expressions'][i] = this.expressionFns[i]['exp']; + } + + return parsedFn; +}; + +InterpolationParts.prototype.watchDelegate = function watchDelegate(scope, listener, objectEquality) { + var watcher = new InterpolationPartsWatcher(this, scope, listener, objectEquality); + return function() { watcher.cancelWatch(); }; +}; + +function InterpolationPartsWatcher(interpolationParts, scope, listener, objectEquality) { + this.interpolationParts = interpolationParts; + this.scope = scope; + this.previousResult = (void 0); + this.listener = listener; + var self = this; + this.expressionFnsWatcher = scope['$watchGroup'](interpolationParts.expressionFns, function(newExpressionValues, oldExpressionValues) { + self.watchListener(newExpressionValues, oldExpressionValues); + }); +} + +InterpolationPartsWatcher.prototype.watchListener = function watchListener(newExpressionValues, oldExpressionValues) { + var result = this.interpolationParts.getResult(newExpressionValues); + if (isFunction(this.listener)) { + this.listener.call(null, result, newExpressionValues === oldExpressionValues ? result : this.previousResult, this.scope); + } + this.previousResult = result; +}; + +InterpolationPartsWatcher.prototype.cancelWatch = function cancelWatch() { + this.expressionFnsWatcher(); +}; + +// NOTE: ADVANCED_OPTIMIZATIONS mode. +// +// This file is compiled with Closure compiler's ADVANCED_OPTIMIZATIONS flag! Be wary of using +// constructs incompatible with that mode. + +/* global $interpolateMinErr: false */ +/* global indexToLineAndColumn: false */ +/* global InterpolationParts: false */ +/* global PluralMessage: false */ +/* global SelectMessage: false */ +/* global subtractOffset: false */ + +// The params src and dst are exactly one of two types: NestedParserState or MessageFormatParser. +// This function is fully optimized by V8. (inspect via IRHydra or --trace-deopt.) +// The idea behind writing it this way is to avoid repeating oneself. This is the ONE place where +// the parser state that is saved/restored when parsing nested mustaches is specified. +function copyNestedParserState(src, dst) { + dst.expressionFn = src.expressionFn; + dst.expressionMinusOffsetFn = src.expressionMinusOffsetFn; + dst.pluralOffset = src.pluralOffset; + dst.choices = src.choices; + dst.choiceKey = src.choiceKey; + dst.interpolationParts = src.interpolationParts; + dst.ruleChoiceKeyword = src.ruleChoiceKeyword; + dst.msgStartIndex = src.msgStartIndex; + dst.expressionStartIndex = src.expressionStartIndex; +} + +function NestedParserState(parser) { + copyNestedParserState(parser, this); +} + +/** + * @constructor + * @private + */ +function MessageFormatParser(text, startIndex, $parse, pluralCat, stringifier, + mustHaveExpression, trustedContext, allOrNothing) { + this.text = text; + this.index = startIndex || 0; + this.$parse = $parse; + this.pluralCat = pluralCat; + this.stringifier = stringifier; + this.mustHaveExpression = !!mustHaveExpression; + this.trustedContext = trustedContext; + this.allOrNothing = !!allOrNothing; + this.expressionFn = null; + this.expressionMinusOffsetFn = null; + this.pluralOffset = null; + this.choices = null; + this.choiceKey = null; + this.interpolationParts = null; + this.msgStartIndex = null; + this.nestedStateStack = []; + this.parsedFn = null; + this.rule = null; + this.ruleStack = null; + this.ruleChoiceKeyword = null; + this.interpNestLevel = null; + this.expressionStartIndex = null; + this.stringStartIndex = null; + this.stringQuote = null; + this.stringInterestsRe = null; + this.angularOperatorStack = null; + this.textPart = null; +} + +// preserve v8 optimization. +var EMPTY_STATE = new NestedParserState(new MessageFormatParser( + /* text= */ '', /* startIndex= */ 0, /* $parse= */ null, /* pluralCat= */ null, /* stringifier= */ null, + /* mustHaveExpression= */ false, /* trustedContext= */ null, /* allOrNothing */ false)); + +MessageFormatParser.prototype.pushState = function pushState() { + this.nestedStateStack.push(new NestedParserState(this)); + copyNestedParserState(EMPTY_STATE, this); +}; + +MessageFormatParser.prototype.popState = function popState() { + if (this.nestedStateStack.length === 0) { + this.errorInParseLogic(); + } + var previousState = this.nestedStateStack.pop(); + copyNestedParserState(previousState, this); +}; + +// Oh my JavaScript! Who knew you couldn't match a regex at a specific +// location in a string but will always search forward?! +// Apparently you'll be growing this ability via the sticky flag (y) in +// ES6. I'll just to work around you for now. +MessageFormatParser.prototype.matchRe = function matchRe(re, search) { + re.lastIndex = this.index; + var match = re.exec(this.text); + if (match != null && (search === true || (match.index == this.index))) { + this.index = re.lastIndex; + return match; + } + return null; +}; + +MessageFormatParser.prototype.searchRe = function searchRe(re) { + return this.matchRe(re, true); +}; + + +MessageFormatParser.prototype.consumeRe = function consumeRe(re) { + // Without the sticky flag, we can't use the .test() method to consume a + // match at the current index. Instead, we'll use the slower .exec() method + // and verify match.index. + return !!this.matchRe(re); +}; + +// Run through our grammar avoiding deeply nested function call chains. +MessageFormatParser.prototype.run = function run(initialRule) { + this.ruleStack = [initialRule]; + do { + this.rule = this.ruleStack.pop(); + while (this.rule) { + this.rule(); + } + this.assertRuleOrNull(this.rule); + } while (this.ruleStack.length > 0); +}; + +MessageFormatParser.prototype.errorInParseLogic = function errorInParseLogic() { + throw $interpolateMinErr('logicbug', + 'The messageformat parser has encountered an internal error. Please file a github issue against the AngularJS project and provide this message text that triggers the bug. Text: “{0}”', + this.text); +}; + +MessageFormatParser.prototype.assertRuleOrNull = function assertRuleOrNull(rule) { + if (rule === void 0) { + this.errorInParseLogic(); + } +}; + +var NEXT_WORD_RE = /\s*(\w+)\s*/g; +MessageFormatParser.prototype.errorExpecting = function errorExpecting() { + // What was wrong with the syntax? Unsupported type, missing comma, or something else? + var match = this.matchRe(NEXT_WORD_RE), position; + if (match == null) { + position = indexToLineAndColumn(this.text, this.index); + throw $interpolateMinErr('reqarg', + 'Expected one of “plural” or “select” at line {0}, column {1} of text “{2}”', + position.line, position.column, this.text); + } + var word = match[1]; + if (word == "select" || word == "plural") { + position = indexToLineAndColumn(this.text, this.index); + throw $interpolateMinErr('reqcomma', + 'Expected a comma after the keyword “{0}” at line {1}, column {2} of text “{3}”', + word, position.line, position.column, this.text); + } else { + position = indexToLineAndColumn(this.text, this.index); + throw $interpolateMinErr('unknarg', + 'Unsupported keyword “{0}” at line {0}, column {1}. Only “plural” and “select” are currently supported. Text: “{3}”', + word, position.line, position.column, this.text); + } +}; + +var STRING_START_RE = /['"]/g; +MessageFormatParser.prototype.ruleString = function ruleString() { + var match = this.matchRe(STRING_START_RE); + if (match == null) { + var position = indexToLineAndColumn(this.text, this.index); + throw $interpolateMinErr('wantstring', + 'Expected the beginning of a string at line {0}, column {1} in text “{2}”', + position.line, position.column, this.text); + } + this.startStringAtMatch(match); +}; + +MessageFormatParser.prototype.startStringAtMatch = function startStringAtMatch(match) { + this.stringStartIndex = match.index; + this.stringQuote = match[0]; + this.stringInterestsRe = this.stringQuote == "'" ? SQUOTED_STRING_INTEREST_RE : DQUOTED_STRING_INTEREST_RE; + this.rule = this.ruleInsideString; +}; + +var SQUOTED_STRING_INTEREST_RE = /\\(?:\\|'|u[0-9A-Fa-f]{4}|x[0-9A-Fa-f]{2}|[0-7]{3}|\r\n|\n|[\s\S])|'/g; +var DQUOTED_STRING_INTEREST_RE = /\\(?:\\|"|u[0-9A-Fa-f]{4}|x[0-9A-Fa-f]{2}|[0-7]{3}|\r\n|\n|[\s\S])|"/g; +MessageFormatParser.prototype.ruleInsideString = function ruleInsideString() { + var match = this.searchRe(this.stringInterestsRe); + if (match == null) { + var position = indexToLineAndColumn(this.text, this.stringStartIndex); + throw $interpolateMinErr('untermstr', + 'The string beginning at line {0}, column {1} is unterminated in text “{2}”', + position.line, position.column, this.text); + } + var chars = match[0]; + if (match == this.stringQuote) { + this.rule = null; + } +}; + +var PLURAL_OR_SELECT_ARG_TYPE_RE = /\s*(plural|select)\s*,\s*/g; +MessageFormatParser.prototype.rulePluralOrSelect = function rulePluralOrSelect() { + var match = this.searchRe(PLURAL_OR_SELECT_ARG_TYPE_RE); + if (match == null) { + this.errorExpecting(); + } + var argType = match[1]; + switch (argType) { + case "plural": this.rule = this.rulePluralStyle; break; + case "select": this.rule = this.ruleSelectStyle; break; + default: this.errorInParseLogic(); + } +}; + +MessageFormatParser.prototype.rulePluralStyle = function rulePluralStyle() { + this.choices = Object.create(null); + this.ruleChoiceKeyword = this.rulePluralValueOrKeyword; + this.rule = this.rulePluralOffset; +}; + +MessageFormatParser.prototype.ruleSelectStyle = function ruleSelectStyle() { + this.choices = Object.create(null); + this.ruleChoiceKeyword = this.ruleSelectKeyword; + this.rule = this.ruleSelectKeyword; +}; + +var NUMBER_RE = /[0]|(?:[1-9][0-9]*)/g; +var PLURAL_OFFSET_RE = new RegExp("\\s*offset\\s*:\\s*(" + NUMBER_RE.source + ")", "g"); + +MessageFormatParser.prototype.rulePluralOffset = function rulePluralOffset() { + var match = this.matchRe(PLURAL_OFFSET_RE); + this.pluralOffset = (match == null) ? 0 : parseInt(match[1], 10); + this.expressionMinusOffsetFn = subtractOffset(this.expressionFn, this.pluralOffset); + this.rule = this.rulePluralValueOrKeyword; +}; + +MessageFormatParser.prototype.assertChoiceKeyIsNew = function assertChoiceKeyIsNew(choiceKey, index) { + if (this.choices[choiceKey] !== void 0) { + var position = indexToLineAndColumn(this.text, index); + throw $interpolateMinErr('dupvalue', + 'The choice “{0}” is specified more than once. Duplicate key is at line {1}, column {2} in text “{3}”', + choiceKey, position.line, position.column, this.text); + } +}; + +var SELECT_KEYWORD = /\s*(\w+)/g; +MessageFormatParser.prototype.ruleSelectKeyword = function ruleSelectKeyword() { + var match = this.matchRe(SELECT_KEYWORD); + if (match == null) { + this.parsedFn = new SelectMessage(this.expressionFn, this.choices).parsedFn; + this.rule = null; + return; + } + this.choiceKey = match[1]; + this.assertChoiceKeyIsNew(this.choiceKey, match.index); + this.rule = this.ruleMessageText; +}; + +var EXPLICIT_VALUE_OR_KEYWORD_RE = new RegExp("\\s*(?:(?:=(" + NUMBER_RE.source + "))|(\\w+))", "g"); +MessageFormatParser.prototype.rulePluralValueOrKeyword = function rulePluralValueOrKeyword() { + var match = this.matchRe(EXPLICIT_VALUE_OR_KEYWORD_RE); + if (match == null) { + this.parsedFn = new PluralMessage(this.expressionFn, this.choices, this.pluralOffset, this.pluralCat).parsedFn; + this.rule = null; + return; + } + if (match[1] != null) { + this.choiceKey = parseInt(match[1], 10); + } else { + this.choiceKey = match[2]; + } + this.assertChoiceKeyIsNew(this.choiceKey, match.index); + this.rule = this.ruleMessageText; +}; + +var BRACE_OPEN_RE = /\s*{/g; +var BRACE_CLOSE_RE = /}/g; +MessageFormatParser.prototype.ruleMessageText = function ruleMessageText() { + if (!this.consumeRe(BRACE_OPEN_RE)) { + var position = indexToLineAndColumn(this.text, this.index); + throw $interpolateMinErr('reqopenbrace', + 'The plural choice “{0}” must be followed by a message in braces at line {1}, column {2} in text “{3}”', + this.choiceKey, position.line, position.column, this.text); + } + this.msgStartIndex = this.index; + this.interpolationParts = new InterpolationParts(this.trustedContext, this.allOrNothing); + this.rule = this.ruleInInterpolationOrMessageText; +}; + +// Note: Since "\" is used as an escape character, don't allow it to be part of the +// startSymbol/endSymbol when I add the feature to allow them to be redefined. +var INTERP_OR_END_MESSAGE_RE = /\\.|{{|}/g; +var INTERP_OR_PLURALVALUE_OR_END_MESSAGE_RE = /\\.|{{|#|}/g; +var ESCAPE_OR_MUSTACHE_BEGIN_RE = /\\.|{{/g; +MessageFormatParser.prototype.advanceInInterpolationOrMessageText = function advanceInInterpolationOrMessageText() { + var currentIndex = this.index, match, re; + if (this.ruleChoiceKeyword == null) { // interpolation + match = this.searchRe(ESCAPE_OR_MUSTACHE_BEGIN_RE); + if (match == null) { // End of interpolation text. Nothing more to process. + this.textPart = this.text.substring(currentIndex); + this.index = this.text.length; + return null; + } + } else { + match = this.searchRe(this.ruleChoiceKeyword == this.rulePluralValueOrKeyword ? + INTERP_OR_PLURALVALUE_OR_END_MESSAGE_RE : INTERP_OR_END_MESSAGE_RE); + if (match == null) { + var position = indexToLineAndColumn(this.text, this.msgStartIndex); + throw $interpolateMinErr('reqendbrace', + 'The plural/select choice “{0}” message starting at line {1}, column {2} does not have an ending closing brace. Text “{3}”', + this.choiceKey, position.line, position.column, this.text); + } + } + // match is non-null. + var token = match[0]; + this.textPart = this.text.substring(currentIndex, match.index); + return token; +}; + +MessageFormatParser.prototype.ruleInInterpolationOrMessageText = function ruleInInterpolationOrMessageText() { + var currentIndex = this.index; + var token = this.advanceInInterpolationOrMessageText(); + if (token == null) { + // End of interpolation text. Nothing more to process. + this.index = this.text.length; + this.interpolationParts.addText(this.text.substring(currentIndex)); + this.rule = null; + return; + } + if (token[0] == "\\") { + // unescape next character and continue + this.interpolationParts.addText(this.textPart + token[1]); + return; + } + this.interpolationParts.addText(this.textPart); + if (token == "{{") { + this.pushState(); + this.ruleStack.push(this.ruleEndMustacheInInterpolationOrMessage); + this.rule = this.ruleEnteredMustache; + } else if (token == "}") { + this.choices[this.choiceKey] = this.interpolationParts.toParsedFn(/*mustHaveExpression=*/false, this.text); + this.rule = this.ruleChoiceKeyword; + } else if (token == "#") { + this.interpolationParts.addExpressionFn(this.expressionMinusOffsetFn); + } else { + this.errorInParseLogic(); + } +}; + +MessageFormatParser.prototype.ruleInterpolate = function ruleInterpolate() { + this.interpolationParts = new InterpolationParts(this.trustedContext, this.allOrNothing); + this.rule = this.ruleInInterpolation; +}; + +MessageFormatParser.prototype.ruleInInterpolation = function ruleInInterpolation() { + var currentIndex = this.index; + var match = this.searchRe(ESCAPE_OR_MUSTACHE_BEGIN_RE); + if (match == null) { + // End of interpolation text. Nothing more to process. + this.index = this.text.length; + this.interpolationParts.addText(this.text.substring(currentIndex)); + this.parsedFn = this.interpolationParts.toParsedFn(this.mustHaveExpression, this.text); + this.rule = null; + return; + } + var token = match[0]; + if (token[0] == "\\") { + // unescape next character and continue + this.interpolationParts.addText(this.text.substring(currentIndex, match.index) + token[1]); + return; + } + this.interpolationParts.addText(this.text.substring(currentIndex, match.index)); + this.pushState(); + this.ruleStack.push(this.ruleInterpolationEndMustache); + this.rule = this.ruleEnteredMustache; +}; + +MessageFormatParser.prototype.ruleInterpolationEndMustache = function ruleInterpolationEndMustache() { + var expressionFn = this.parsedFn; + this.popState(); + this.interpolationParts.addExpressionFn(expressionFn); + this.rule = this.ruleInInterpolation; +}; + +MessageFormatParser.prototype.ruleEnteredMustache = function ruleEnteredMustache() { + this.parsedFn = null; + this.ruleStack.push(this.ruleEndMustache); + this.rule = this.ruleAngularExpression; +}; + +MessageFormatParser.prototype.ruleEndMustacheInInterpolationOrMessage = function ruleEndMustacheInInterpolationOrMessage() { + var expressionFn = this.parsedFn; + this.popState(); + this.interpolationParts.addExpressionFn(expressionFn); + this.rule = this.ruleInInterpolationOrMessageText; +}; + + + +var INTERP_END_RE = /\s*}}/g; +MessageFormatParser.prototype.ruleEndMustache = function ruleEndMustache() { + var match = this.matchRe(INTERP_END_RE); + if (match == null) { + var position = indexToLineAndColumn(this.text, this.index); + throw $interpolateMinErr('reqendinterp', + 'Expecting end of interpolation symbol, “{0}”, at line {1}, column {2} in text “{3}”', + '}}', position.line, position.column, this.text); + } + if (this.parsedFn == null) { + // If we parsed a MessageFormat extension, (e.g. select/plural today, maybe more some other + // day), then the result *has* to be a string and those rules would have already set + // this.parsedFn. If there was no MessageFormat extension, then there is no requirement to + // stringify the result and parsedFn isn't set. We set it here. While we could have set it + // unconditionally when exiting the Angular expression, I intend for us to not just replace + // $interpolate, but also to replace $parse in a future version (so ng-bind can work), and in + // such a case we do not want to unnecessarily stringify something if it's not going to be used + // in a string context. + this.parsedFn = this.$parse(this.expressionFn, this.stringifier); + this.parsedFn['exp'] = this.expressionFn['exp']; // Needed to pretend to be $interpolate for tests copied from interpolateSpec.js + this.parsedFn['expressions'] = this.expressionFn['expressions']; // Require this to call $compile.$$addBindingInfo() which allows Protractor to find elements by binding. + } + this.rule = null; +}; + +MessageFormatParser.prototype.ruleAngularExpression = function ruleAngularExpression() { + this.angularOperatorStack = []; + this.expressionStartIndex = this.index; + this.rule = this.ruleInAngularExpression; +}; + +function getEndOperator(opBegin) { + switch (opBegin) { + case "{": return "}"; + case "[": return "]"; + case "(": return ")"; + default: return null; + } +} + +function getBeginOperator(opEnd) { + switch (opEnd) { + case "}": return "{"; + case "]": return "["; + case ")": return "("; + default: return null; + } +} + +// TODO(chirayu): The interpolation endSymbol must also be accounted for. It +// just so happens that "}" is an operator so it's in the list below. But we +// should support any other type of start/end interpolation symbol. +var INTERESTING_OPERATORS_RE = /[[\]{}()'",]/g; +MessageFormatParser.prototype.ruleInAngularExpression = function ruleInAngularExpression() { + var startIndex = this.index; + var match = this.searchRe(INTERESTING_OPERATORS_RE); + var position; + if (match == null) { + if (this.angularOperatorStack.length === 0) { + // This is the end of the Angular expression so this is actually a + // success. Note that when inside an interpolation, this means we even + // consumed the closing interpolation symbols if they were curlies. This + // is NOT an error at this point but will become an error further up the + // stack when the part that saw the opening curlies is unable to find the + // closing ones. + this.index = this.text.length; + this.expressionFn = this.$parse(this.text.substring(this.expressionStartIndex, this.index)); + // Needed to pretend to be $interpolate for tests copied from interpolateSpec.js + this.expressionFn['exp'] = this.text.substring(this.expressionStartIndex, this.index); + this.expressionFn['expressions'] = this.expressionFn['expressions']; + this.rule = null; + return; + } + var innermostOperator = this.angularOperatorStack[0]; + throw $interpolateMinErr('badexpr', + 'Unexpected end of Angular expression. Expecting operator “{0}” at the end of the text “{1}”', + this.getEndOperator(innermostOperator), this.text); + } + var operator = match[0]; + if (operator == "'" || operator == '"') { + this.ruleStack.push(this.ruleInAngularExpression); + this.startStringAtMatch(match); + return; + } + if (operator == ",") { + if (this.trustedContext) { + position = indexToLineAndColumn(this.text, this.index); + throw $interpolateMinErr('unsafe', + 'Use of select/plural MessageFormat syntax is currently disallowed in a secure context ({0}). At line {1}, column {2} of text “{3}”', + this.trustedContext, position.line, position.column, this.text); + } + // only the top level comma has relevance. + if (this.angularOperatorStack.length === 0) { + // todo: does this need to be trimmed? + this.expressionFn = this.$parse(this.text.substring(this.expressionStartIndex, match.index)); + // Needed to pretend to be $interpolate for tests copied from interpolateSpec.js + this.expressionFn['exp'] = this.text.substring(this.expressionStartIndex, match.index); + this.expressionFn['expressions'] = this.expressionFn['expressions']; + this.rule = null; + this.rule = this.rulePluralOrSelect; + } + return; + } + if (getEndOperator(operator) != null) { + this.angularOperatorStack.unshift(operator); + return; + } + var beginOperator = getBeginOperator(operator); + if (beginOperator == null) { + this.errorInParseLogic(); + } + if (this.angularOperatorStack.length > 0) { + if (beginOperator == this.angularOperatorStack[0]) { + this.angularOperatorStack.shift(); + return; + } + position = indexToLineAndColumn(this.text, this.index); + throw $interpolateMinErr('badexpr', + 'Unexpected operator “{0}” at line {1}, column {2} in text. Was expecting “{3}”. Text: “{4}”', + operator, position.line, position.column, getEndOperator(this.angularOperatorStack[0]), this.text); + } + // We are trying to pop off the operator stack but there really isn't anything to pop off. + this.index = match.index; + this.expressionFn = this.$parse(this.text.substring(this.expressionStartIndex, this.index)); + // Needed to pretend to be $interpolate for tests copied from interpolateSpec.js + this.expressionFn['exp'] = this.text.substring(this.expressionStartIndex, this.index); + this.expressionFn['expressions'] = this.expressionFn['expressions']; + this.rule = null; +}; + +// NOTE: ADVANCED_OPTIMIZATIONS mode. +// +// This file is compiled with Closure compiler's ADVANCED_OPTIMIZATIONS flag! Be wary of using +// constructs incompatible with that mode. + +/* global $interpolateMinErr: false */ +/* global MessageFormatParser: false */ +/* global stringify: false */ + +/** + * @ngdoc service + * @name $$messageFormat + * + * @description + * Angular internal service to recognize MessageFormat extensions in interpolation expressions. + * For more information, see: + * https://docs.google.com/a/google.com/document/d/1pbtW2yvtmFBikfRrJd8VAsabiFkKezmYZ_PbgdjQOVU/edit + * + * ## Example + * + * + * + *
    + *
    + * {{recipients.length, plural, offset:1 + * =0 {{{sender.name}} gave no gifts (\#=#)} + * =1 {{{sender.name}} gave one gift to {{recipients[0].name}} (\#=#)} + * one {{{sender.name}} gave {{recipients[0].name}} and one other person a gift (\#=#)} + * other {{{sender.name}} gave {{recipients[0].name}} and # other people a gift (\#=#)} + * }} + *
    + *
    + * + * + * function Person(name, gender) { + * this.name = name; + * this.gender = gender; + * } + * + * var alice = new Person("Alice", "female"), + * bob = new Person("Bob", "male"), + * charlie = new Person("Charlie", "male"), + * harry = new Person("Harry Potter", "male"); + * + * angular.module('msgFmtExample', ['ngMessageFormat']) + * .controller('AppController', ['$scope', function($scope) { + * $scope.recipients = [alice, bob, charlie]; + * $scope.sender = harry; + * $scope.decreaseRecipients = function() { + * --$scope.recipients.length; + * }; + * }]); + * + * + * + * describe('MessageFormat plural', function() { + * it('should pluralize initial values', function() { + * var messageElem = element(by.binding('recipients.length')), decreaseRecipientsBtn = element(by.id('decreaseRecipients')); + * expect(messageElem.getText()).toEqual('Harry Potter gave Alice and 2 other people a gift (#=2)'); + * decreaseRecipientsBtn.click(); + * expect(messageElem.getText()).toEqual('Harry Potter gave Alice and one other person a gift (#=1)'); + * decreaseRecipientsBtn.click(); + * expect(messageElem.getText()).toEqual('Harry Potter gave one gift to Alice (#=0)'); + * decreaseRecipientsBtn.click(); + * expect(messageElem.getText()).toEqual('Harry Potter gave no gifts (#=-1)'); + * }); + * }); + * + *
    + */ +var $$MessageFormatFactory = ['$parse', '$locale', '$sce', '$exceptionHandler', function $$messageFormat( + $parse, $locale, $sce, $exceptionHandler) { + + function getStringifier(trustedContext, allOrNothing, text) { + return function stringifier(value) { + try { + value = trustedContext ? $sce['getTrusted'](trustedContext, value) : $sce['valueOf'](value); + return allOrNothing && (value === void 0) ? value : stringify(value); + } catch (err) { + $exceptionHandler($interpolateMinErr['interr'](text, err)); + } + }; + } + + function interpolate(text, mustHaveExpression, trustedContext, allOrNothing) { + var stringifier = getStringifier(trustedContext, allOrNothing, text); + var parser = new MessageFormatParser(text, 0, $parse, $locale['pluralCat'], stringifier, + mustHaveExpression, trustedContext, allOrNothing); + parser.run(parser.ruleInterpolate); + return parser.parsedFn; + } + + return { + 'interpolate': interpolate + }; +}]; + +var $$interpolateDecorator = ['$$messageFormat', '$delegate', function $$interpolateDecorator($$messageFormat, $interpolate) { + if ($interpolate['startSymbol']() != "{{" || $interpolate['endSymbol']() != "}}") { + throw $interpolateMinErr('nochgmustache', 'angular-message-format.js currently does not allow you to use custom start and end symbols for interpolation.'); + } + var interpolate = $$messageFormat['interpolate']; + interpolate['startSymbol'] = $interpolate['startSymbol']; + interpolate['endSymbol'] = $interpolate['endSymbol']; + return interpolate; +}]; + + +/** + * @ngdoc module + * @name ngMessageFormat + * @packageName angular-message-format + * @description + */ +var module = window['angular']['module']('ngMessageFormat', ['ng']); +module['factory']('$$messageFormat', $$MessageFormatFactory); +module['config'](['$provide', function($provide) { + $provide['decorator']('$interpolate', $$interpolateDecorator); +}]); + + +})(window, window.angular); diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-message-format.min.js b/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-message-format.min.js new file mode 100644 index 000000000..f85a58769 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-message-format.min.js @@ -0,0 +1,26 @@ +/* + AngularJS v1.5.0 + (c) 2010-2016 Google, Inc. http://angularjs.org + License: MIT +*/ +(function(h){'use strict';function C(a){if(null==a)return"";switch(typeof a){case "string":return a;case "number":return""+a;default:return D(a)}}function f(a,b){for(var d=a.split(/\n/g),k=0;k=c.length)b-=c.length;else return{h:k+1,f:b+1}}}function t(a){function b(){return a}var d=u[a];if(null!=d)return d;b.$$watchDelegate=function(b,d,c){var e=b.$watch(v,function(){m(d)&&d.call(null,a,a,b);e()},c);return e};u[a]=b;b.exp=a;b.expressions=[];return b}function F(a,b){function d(a){return void 0== +a?a:a-b}function c(b){return d(a(b))}if(0===b)return a;var e;c.$$watchDelegate=function(b,c,k){return e=b.$watch(a,function(a,k){m(c)&&c.call(null,d(a),d(k),b)},k)};return c}function l(a,b){var d=this;this.b=a;this.e=b;if(void 0===b.other)throw e("reqother");this.d=function(a){return d.D(a)};this.d.$$watchDelegate=function(a,b,c){return d.P(a,b,c)};this.d.exp=a.exp;this.d.expressions=a.expressions}function n(a,b,d,c){var e=this;this.scope=b;this.oa=a;this.v=d;this.qa=c;this.U=void 0;this.K=v;this.ka= +b.$watch(a.b,function(a){return e.ja(a)},c)}function p(a,b){l.call(this,a,b)}function w(){}function q(a,b,d,c){l.call(this,a,b);this.offset=d;this.M=c}function x(){}function g(a,b){this.u=a;this.B=b;this.i=[];this.g=[];this.J=[];this.s="";this.q=null}function r(a,b,d){this.c=a;this.scope=b;this.W=void 0;this.v=d;var c=this;this.la=b.$watchGroup(a.g,function(a,b){c.Ea(a,b)})}function s(a,b){b.b=a.b;b.C=a.C;b.w=a.w;b.e=a.e;b.k=a.k;b.c=a.c;b.n=a.n;b.F=a.F;b.l=a.l}function y(a){s(a,this)}function c(a, +b,d,c,e,E,f,g){this.text=a;this.index=b||0;this.A=d;this.M=c;this.Da=e;this.pa=!!E;this.u=f;this.B=!!g;this.F=this.c=this.k=this.e=this.w=this.C=this.b=null;this.L=[];this.G=this.j=this.ca=this.O=this.da=this.l=this.n=this.o=this.a=this.d=null}function z(a){switch(a){case "{":return"}";case "[":return"]";case "(":return")";default:return null}}function G(a){switch(a){case "}":return"{";case "]":return"[";case ")":return"(";default:return null}}var e=h.angular.$interpolateMinErr,v=h.angular.noop,m= +h.angular.isFunction,D=h.angular.toJson,u=Object.create(null);l.prototype.T=function(a){return this.e[this.R(a)]};l.prototype.D=function(a){return this.T(this.b(a))(a)};l.prototype.P=function(a,b,d){var c=new n(this,a,b,d);return function(){c.I()}};n.prototype.ja=function(a){var b=this;this.K();a=this.oa.T(a);this.K=this.scope.$watch(a,function(a,c){return b.na(a,c)},this.qa)};n.prototype.na=function(a,b){m(this.v)&&this.v.call(null,a,a===b?a:this.U,this.scope);this.U=a};n.prototype.I=function(){this.ka(); +this.K()};w.prototype=l.prototype;p.prototype=new w;p.prototype.R=function(a){return void 0!==this.e[a]?a:"other"};x.prototype=l.prototype;q.prototype=new x;q.prototype.R=function(a){if(isNaN(a))return"other";if(void 0!==this.e[a])return a;a=this.M(a-this.offset);return void 0!==this.e[a]?a:"other"};g.prototype.S=function(){this.s&&(null==this.q?this.i.push(this.s):(this.i.push(this.q.join("")),this.q=null),this.s="")};g.prototype.p=function(a){a.length&&(this.s?this.q?this.q.push(a):this.q=[this.s, +a]:this.s=a)};g.prototype.H=function(a){this.S();this.J.push(this.i.length);this.g.push(a);this.i.push("")};g.prototype.ma=function(a){for(var b=Array(this.g.length),d=0;d + * + *
    + *
    You did not enter a field
    + *
    + * Your email must be between 5 and 100 characters long + *
    + *
    + * + * ``` + * + * Now whatever key/value entries are present within the provided object (in this case `$error`) then + * the ngMessages directive will render the inner first ngMessage directive (depending if the key values + * match the attribute value present on each ngMessage directive). In other words, if your errors + * object contains the following data: + * + * ```javascript + * + * myField.$error = { minlength : true, required : true }; + * ``` + * + * Then the `required` message will be displayed first. When required is false then the `minlength` message + * will be displayed right after (since these messages are ordered this way in the template HTML code). + * The prioritization of each message is determined by what order they're present in the DOM. + * Therefore, instead of having custom JavaScript code determine the priority of what errors are + * present before others, the presentation of the errors are handled within the template. + * + * By default, ngMessages will only display one error at a time. However, if you wish to display all + * messages then the `ng-messages-multiple` attribute flag can be used on the element containing the + * ngMessages directive to make this happen. + * + * ```html + * + *
    ...
    + * + * + * ... + * ``` + * + * ## Reusing and Overriding Messages + * In addition to prioritization, ngMessages also allows for including messages from a remote or an inline + * template. This allows for generic collection of messages to be reused across multiple parts of an + * application. + * + * ```html + * + * + *
    + *
    + *
    + * ``` + * + * However, including generic messages may not be useful enough to match all input fields, therefore, + * `ngMessages` provides the ability to override messages defined in the remote template by redefining + * them within the directive container. + * + * ```html + * + * + * + *
    + * + * + *
    + * + *
    You did not enter your email address
    + * + * + *
    Your email address is invalid
    + * + * + *
    + *
    + *
    + * ``` + * + * In the example HTML code above the message that is set on required will override the corresponding + * required message defined within the remote template. Therefore, with particular input fields (such + * email addresses, date fields, autocomplete inputs, etc...), specialized error messages can be applied + * while more generic messages can be used to handle other, more general input errors. + * + * ## Dynamic Messaging + * ngMessages also supports using expressions to dynamically change key values. Using arrays and + * repeaters to list messages is also supported. This means that the code below will be able to + * fully adapt itself and display the appropriate message when any of the expression data changes: + * + * ```html + *
    + * + *
    + *
    You did not enter your email address
    + *
    + * + *
    {{ errorMessage.text }}
    + *
    + *
    + *
    + * ``` + * + * The `errorMessage.type` expression can be a string value or it can be an array so + * that multiple errors can be associated with a single error message: + * + * ```html + * + *
    + *
    You did not enter your email address
    + *
    + * Your email must be between 5 and 100 characters long + *
    + *
    + * ``` + * + * Feel free to use other structural directives such as ng-if and ng-switch to further control + * what messages are active and when. Be careful, if you place ng-message on the same element + * as these structural directives, Angular may not be able to determine if a message is active + * or not. Therefore it is best to place the ng-message on a child element of the structural + * directive. + * + * ```html + *
    + *
    + *
    Please enter something
    + *
    + *
    + * ``` + * + * ## Animations + * If the `ngAnimate` module is active within the application then the `ngMessages`, `ngMessage` and + * `ngMessageExp` directives will trigger animations whenever any messages are added and removed from + * the DOM by the `ngMessages` directive. + * + * Whenever the `ngMessages` directive contains one or more visible messages then the `.ng-active` CSS + * class will be added to the element. The `.ng-inactive` CSS class will be applied when there are no + * messages present. Therefore, CSS transitions and keyframes as well as JavaScript animations can + * hook into the animations whenever these classes are added/removed. + * + * Let's say that our HTML code for our messages container looks like so: + * + * ```html + * + * ``` + * + * Then the CSS animation code for the message container looks like so: + * + * ```css + * .my-messages { + * transition:1s linear all; + * } + * .my-messages.ng-active { + * // messages are visible + * } + * .my-messages.ng-inactive { + * // messages are hidden + * } + * ``` + * + * Whenever an inner message is attached (becomes visible) or removed (becomes hidden) then the enter + * and leave animation is triggered for each particular element bound to the `ngMessage` directive. + * + * Therefore, the CSS code for the inner messages looks like so: + * + * ```css + * .some-message { + * transition:1s linear all; + * } + * + * .some-message.ng-enter {} + * .some-message.ng-enter.ng-enter-active {} + * + * .some-message.ng-leave {} + * .some-message.ng-leave.ng-leave-active {} + * ``` + * + * {@link ngAnimate Click here} to learn how to use JavaScript animations or to learn more about ngAnimate. + */ +angular.module('ngMessages', []) + + /** + * @ngdoc directive + * @module ngMessages + * @name ngMessages + * @restrict AE + * + * @description + * `ngMessages` is a directive that is designed to show and hide messages based on the state + * of a key/value object that it listens on. The directive itself complements error message + * reporting with the `ngModel` $error object (which stores a key/value state of validation errors). + * + * `ngMessages` manages the state of internal messages within its container element. The internal + * messages use the `ngMessage` directive and will be inserted/removed from the page depending + * on if they're present within the key/value object. By default, only one message will be displayed + * at a time and this depends on the prioritization of the messages within the template. (This can + * be changed by using the `ng-messages-multiple` or `multiple` attribute on the directive container.) + * + * A remote template can also be used to promote message reusability and messages can also be + * overridden. + * + * {@link module:ngMessages Click here} to learn more about `ngMessages` and `ngMessage`. + * + * @usage + * ```html + * + * + * ... + * ... + * ... + * + * + * + * + * ... + * ... + * ... + * + * ``` + * + * @param {string} ngMessages an angular expression evaluating to a key/value object + * (this is typically the $error object on an ngModel instance). + * @param {string=} ngMessagesMultiple|multiple when set, all messages will be displayed with true + * + * @example + * + * + *
    + * + *
    myForm.myName.$error = {{ myForm.myName.$error | json }}
    + * + *
    + *
    You did not enter a field
    + *
    Your field is too short
    + *
    Your field is too long
    + *
    + *
    + *
    + * + * angular.module('ngMessagesExample', ['ngMessages']); + * + *
    + */ + .directive('ngMessages', ['$animate', function($animate) { + var ACTIVE_CLASS = 'ng-active'; + var INACTIVE_CLASS = 'ng-inactive'; + + return { + require: 'ngMessages', + restrict: 'AE', + controller: ['$element', '$scope', '$attrs', function($element, $scope, $attrs) { + var ctrl = this; + var latestKey = 0; + var nextAttachId = 0; + + this.getAttachId = function getAttachId() { return nextAttachId++; }; + + var messages = this.messages = {}; + var renderLater, cachedCollection; + + this.render = function(collection) { + collection = collection || {}; + + renderLater = false; + cachedCollection = collection; + + // this is true if the attribute is empty or if the attribute value is truthy + var multiple = isAttrTruthy($scope, $attrs.ngMessagesMultiple) || + isAttrTruthy($scope, $attrs.multiple); + + var unmatchedMessages = []; + var matchedKeys = {}; + var messageItem = ctrl.head; + var messageFound = false; + var totalMessages = 0; + + // we use != instead of !== to allow for both undefined and null values + while (messageItem != null) { + totalMessages++; + var messageCtrl = messageItem.message; + + var messageUsed = false; + if (!messageFound) { + forEach(collection, function(value, key) { + if (!messageUsed && truthy(value) && messageCtrl.test(key)) { + // this is to prevent the same error name from showing up twice + if (matchedKeys[key]) return; + matchedKeys[key] = true; + + messageUsed = true; + messageCtrl.attach(); + } + }); + } + + if (messageUsed) { + // unless we want to display multiple messages then we should + // set a flag here to avoid displaying the next message in the list + messageFound = !multiple; + } else { + unmatchedMessages.push(messageCtrl); + } + + messageItem = messageItem.next; + } + + forEach(unmatchedMessages, function(messageCtrl) { + messageCtrl.detach(); + }); + + unmatchedMessages.length !== totalMessages + ? $animate.setClass($element, ACTIVE_CLASS, INACTIVE_CLASS) + : $animate.setClass($element, INACTIVE_CLASS, ACTIVE_CLASS); + }; + + $scope.$watchCollection($attrs.ngMessages || $attrs['for'], ctrl.render); + + this.reRender = function() { + if (!renderLater) { + renderLater = true; + $scope.$evalAsync(function() { + if (renderLater) { + cachedCollection && ctrl.render(cachedCollection); + } + }); + } + }; + + this.register = function(comment, messageCtrl) { + var nextKey = latestKey.toString(); + messages[nextKey] = { + message: messageCtrl + }; + insertMessageNode($element[0], comment, nextKey); + comment.$$ngMessageNode = nextKey; + latestKey++; + + ctrl.reRender(); + }; + + this.deregister = function(comment) { + var key = comment.$$ngMessageNode; + delete comment.$$ngMessageNode; + removeMessageNode($element[0], comment, key); + delete messages[key]; + ctrl.reRender(); + }; + + function findPreviousMessage(parent, comment) { + var prevNode = comment; + var parentLookup = []; + while (prevNode && prevNode !== parent) { + var prevKey = prevNode.$$ngMessageNode; + if (prevKey && prevKey.length) { + return messages[prevKey]; + } + + // dive deeper into the DOM and examine its children for any ngMessage + // comments that may be in an element that appears deeper in the list + if (prevNode.childNodes.length && parentLookup.indexOf(prevNode) == -1) { + parentLookup.push(prevNode); + prevNode = prevNode.childNodes[prevNode.childNodes.length - 1]; + } else { + prevNode = prevNode.previousSibling || prevNode.parentNode; + } + } + } + + function insertMessageNode(parent, comment, key) { + var messageNode = messages[key]; + if (!ctrl.head) { + ctrl.head = messageNode; + } else { + var match = findPreviousMessage(parent, comment); + if (match) { + messageNode.next = match.next; + match.next = messageNode; + } else { + messageNode.next = ctrl.head; + ctrl.head = messageNode; + } + } + } + + function removeMessageNode(parent, comment, key) { + var messageNode = messages[key]; + + var match = findPreviousMessage(parent, comment); + if (match) { + match.next = messageNode.next; + } else { + ctrl.head = messageNode.next; + } + } + }] + }; + + function isAttrTruthy(scope, attr) { + return (isString(attr) && attr.length === 0) || //empty attribute + truthy(scope.$eval(attr)); + } + + function truthy(val) { + return isString(val) ? val.length : !!val; + } + }]) + + /** + * @ngdoc directive + * @name ngMessagesInclude + * @restrict AE + * @scope + * + * @description + * `ngMessagesInclude` is a directive with the purpose to import existing ngMessage template + * code from a remote template and place the downloaded template code into the exact spot + * that the ngMessagesInclude directive is placed within the ngMessages container. This allows + * for a series of pre-defined messages to be reused and also allows for the developer to + * determine what messages are overridden due to the placement of the ngMessagesInclude directive. + * + * @usage + * ```html + * + * + * ... + * + * + * + * + * ... + * + * ``` + * + * {@link module:ngMessages Click here} to learn more about `ngMessages` and `ngMessage`. + * + * @param {string} ngMessagesInclude|src a string value corresponding to the remote template. + */ + .directive('ngMessagesInclude', + ['$templateRequest', '$document', '$compile', function($templateRequest, $document, $compile) { + + return { + restrict: 'AE', + require: '^^ngMessages', // we only require this for validation sake + link: function($scope, element, attrs) { + var src = attrs.ngMessagesInclude || attrs.src; + $templateRequest(src).then(function(html) { + $compile(html)($scope, function(contents) { + element.after(contents); + + // the anchor is placed for debugging purposes + var anchor = jqLite($document[0].createComment(' ngMessagesInclude: ' + src + ' ')); + element.after(anchor); + + // we don't want to pollute the DOM anymore by keeping an empty directive element + element.remove(); + }); + }); + } + }; + }]) + + /** + * @ngdoc directive + * @name ngMessage + * @restrict AE + * @scope + * + * @description + * `ngMessage` is a directive with the purpose to show and hide a particular message. + * For `ngMessage` to operate, a parent `ngMessages` directive on a parent DOM element + * must be situated since it determines which messages are visible based on the state + * of the provided key/value map that `ngMessages` listens on. + * + * More information about using `ngMessage` can be found in the + * {@link module:ngMessages `ngMessages` module documentation}. + * + * @usage + * ```html + * + * + * ... + * ... + * + * + * + * + * ... + * ... + * + * ``` + * + * @param {expression} ngMessage|when a string value corresponding to the message key. + */ + .directive('ngMessage', ngMessageDirectiveFactory()) + + + /** + * @ngdoc directive + * @name ngMessageExp + * @restrict AE + * @priority 1 + * @scope + * + * @description + * `ngMessageExp` is a directive with the purpose to show and hide a particular message. + * For `ngMessageExp` to operate, a parent `ngMessages` directive on a parent DOM element + * must be situated since it determines which messages are visible based on the state + * of the provided key/value map that `ngMessages` listens on. + * + * @usage + * ```html + * + * + * ... + * + * + * + * + * ... + * + * ``` + * + * {@link module:ngMessages Click here} to learn more about `ngMessages` and `ngMessage`. + * + * @param {expression} ngMessageExp|whenExp an expression value corresponding to the message key. + */ + .directive('ngMessageExp', ngMessageDirectiveFactory()); + +function ngMessageDirectiveFactory() { + return ['$animate', function($animate) { + return { + restrict: 'AE', + transclude: 'element', + priority: 1, // must run before ngBind, otherwise the text is set on the comment + terminal: true, + require: '^^ngMessages', + link: function(scope, element, attrs, ngMessagesCtrl, $transclude) { + var commentNode = element[0]; + + var records; + var staticExp = attrs.ngMessage || attrs.when; + var dynamicExp = attrs.ngMessageExp || attrs.whenExp; + var assignRecords = function(items) { + records = items + ? (isArray(items) + ? items + : items.split(/[\s,]+/)) + : null; + ngMessagesCtrl.reRender(); + }; + + if (dynamicExp) { + assignRecords(scope.$eval(dynamicExp)); + scope.$watchCollection(dynamicExp, assignRecords); + } else { + assignRecords(staticExp); + } + + var currentElement, messageCtrl; + ngMessagesCtrl.register(commentNode, messageCtrl = { + test: function(name) { + return contains(records, name); + }, + attach: function() { + if (!currentElement) { + $transclude(scope, function(elm) { + $animate.enter(elm, null, element); + currentElement = elm; + + // Each time we attach this node to a message we get a new id that we can match + // when we are destroying the node later. + var $$attachId = currentElement.$$attachId = ngMessagesCtrl.getAttachId(); + + // in the event that the parent element is destroyed + // by any other structural directive then it's time + // to deregister the message from the controller + currentElement.on('$destroy', function() { + if (currentElement && currentElement.$$attachId === $$attachId) { + ngMessagesCtrl.deregister(commentNode); + messageCtrl.detach(); + } + }); + }); + } + }, + detach: function() { + if (currentElement) { + var elm = currentElement; + currentElement = null; + $animate.leave(elm); + } + } + }); + } + }; + }]; + + function contains(collection, key) { + if (collection) { + return isArray(collection) + ? collection.indexOf(key) >= 0 + : collection.hasOwnProperty(key); + } + } +} + + +})(window, window.angular); diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-messages.min.js b/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-messages.min.js new file mode 100644 index 000000000..19f59cc89 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-messages.min.js @@ -0,0 +1,12 @@ +/* + AngularJS v1.5.0 + (c) 2010-2016 Google, Inc. http://angularjs.org + License: MIT +*/ +(function(A,d,B){'use strict';function l(){return["$animate",function(v){return{restrict:"AE",transclude:"element",priority:1,terminal:!0,require:"^^ngMessages",link:function(n,r,a,b,m){var k=r[0],f,p=a.ngMessage||a.when;a=a.ngMessageExp||a.whenExp;var d=function(a){f=a?w(a)?a:a.split(/[\s,]+/):null;b.reRender()};a?(d(n.$eval(a)),n.$watchCollection(a,d)):d(p);var e,q;b.register(k,q={test:function(a){var g=f;a=g?w(g)?0<=g.indexOf(a):g.hasOwnProperty(a):void 0;return a},attach:function(){e||m(n,function(a){v.enter(a, +null,r);e=a;var g=e.$$attachId=b.getAttachId();e.on("$destroy",function(){e&&e.$$attachId===g&&(b.deregister(k),q.detach())})})},detach:function(){if(e){var a=e;e=null;v.leave(a)}}})}}}]}var w=d.isArray,x=d.forEach,y=d.isString,z=d.element;d.module("ngMessages",[]).directive("ngMessages",["$animate",function(d){function n(a,b){return y(b)&&0===b.length||r(a.$eval(b))}function r(a){return y(a)?a.length:!!a}return{require:"ngMessages",restrict:"AE",controller:["$element","$scope","$attrs",function(a, +b,m){function k(a,b){for(var c=b,f=[];c&&c!==a;){var h=c.$$ngMessageNode;if(h&&h.length)return e[h];c.childNodes.length&&-1==f.indexOf(c)?(f.push(c),c=c.childNodes[c.childNodes.length-1]):c=c.previousSibling||c.parentNode}}var f=this,p=0,l=0;this.getAttachId=function(){return l++};var e=this.messages={},q,s;this.render=function(g){g=g||{};q=!1;s=g;for(var e=n(b,m.ngMessagesMultiple)||n(b,m.multiple),c=[],k={},h=f.head,p=!1,l=0;null!=h;){l++;var t=h.message,u=!1;p||x(g,function(a,c){!u&&r(a)&&t.test(c)&& +!k[c]&&(u=k[c]=!0,t.attach())});u?p=!e:c.push(t);h=h.next}x(c,function(a){a.detach()});c.length!==l?d.setClass(a,"ng-active","ng-inactive"):d.setClass(a,"ng-inactive","ng-active")};b.$watchCollection(m.ngMessages||m["for"],f.render);this.reRender=function(){q||(q=!0,b.$evalAsync(function(){q&&s&&f.render(s)}))};this.register=function(g,b){var c=p.toString();e[c]={message:b};var d=a[0],h=e[c];f.head?(d=k(d,g))?(h.next=d.next,d.next=h):(h.next=f.head,f.head=h):f.head=h;g.$$ngMessageNode=c;p++;f.reRender()}; +this.deregister=function(b){var d=b.$$ngMessageNode;delete b.$$ngMessageNode;var c=e[d];(b=k(a[0],b))?b.next=c.next:f.head=c.next;delete e[d];f.reRender()}}]}}]).directive("ngMessagesInclude",["$templateRequest","$document","$compile",function(d,n,l){return{restrict:"AE",require:"^^ngMessages",link:function(a,b,m){var k=m.ngMessagesInclude||m.src;d(k).then(function(d){l(d)(a,function(a){b.after(a);a=z(n[0].createComment(" ngMessagesInclude: "+k+" "));b.after(a);b.remove()})})}}}]).directive("ngMessage", +l()).directive("ngMessageExp",l())})(window,window.angular); +//# sourceMappingURL=angular-messages.min.js.map diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-messages.min.js.map b/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-messages.min.js.map new file mode 100644 index 000000000..0cb2a943d --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-messages.min.js.map @@ -0,0 +1,8 @@ +{ +"version":3, +"file":"angular-messages.min.js", +"lineCount":11, +"mappings":"A;;;;;aAKC,SAAQ,CAACA,CAAD,CAASC,CAAT,CAAkBC,CAAlB,CAA6B,CA0lBtCC,QAASA,EAAyB,EAAG,CACnC,MAAO,CAAC,UAAD,CAAa,QAAQ,CAACC,CAAD,CAAW,CACrC,MAAO,CACLC,SAAU,IADL,CAELC,WAAY,SAFP,CAGLC,SAAU,CAHL,CAILC,SAAU,CAAA,CAJL,CAKLC,QAAS,cALJ,CAMLC,KAAMA,QAAQ,CAACC,CAAD,CAAQC,CAAR,CAAiBC,CAAjB,CAAwBC,CAAxB,CAAwCC,CAAxC,CAAqD,CACjE,IAAIC,EAAcJ,CAAA,CAAQ,CAAR,CAAlB,CAEIK,CAFJ,CAGIC,EAAYL,CAAAM,UAAZD,EAA+BL,CAAAO,KAC/BC,EAAAA,CAAaR,CAAAS,aAAbD,EAAmCR,CAAAU,QACvC,KAAIC,EAAgBA,QAAQ,CAACC,CAAD,CAAQ,CAClCR,CAAA,CAAUQ,CAAA,CACHC,CAAA,CAAQD,CAAR,CAAA,CACKA,CADL,CAEKA,CAAAE,MAAA,CAAY,QAAZ,CAHF,CAIJ,IACNb,EAAAc,SAAA,EANkC,CAShCP,EAAJ,EACEG,CAAA,CAAcb,CAAAkB,MAAA,CAAYR,CAAZ,CAAd,CACA,CAAAV,CAAAmB,iBAAA,CAAuBT,CAAvB,CAAmCG,CAAnC,CAFF,EAIEA,CAAA,CAAcN,CAAd,CAnB+D,KAsB7Da,CAtB6D,CAsB7CC,CACpBlB,EAAAmB,SAAA,CAAwBjB,CAAxB,CAAqCgB,CAArC,CAAmD,CACjDE,KAAMA,QAAQ,CAACC,CAAD,CAAO,CACHlB,IAAAA,EAAAA,CAsCtB,EAAA,CADEmB,CAAJ,CACSV,CAAA,CAAQU,CAAR,CAAA,CAC0B,CAD1B,EACDA,CAAAC,QAAA,CAvCyBF,CAuCzB,CADC,CAEDC,CAAAE,eAAA,CAxCyBH,CAwCzB,CAHR,CADiC,IAAA,EApCzB,OAAO,EADY,CAD4B,CAIjDI,OAAQA,QAAQ,EAAG,CACZR,CAAL,EACEhB,CAAA,CAAYJ,CAAZ,CAAmB,QAAQ,CAAC6B,CAAD,CAAM,CAC/BpC,CAAAqC,MAAA,CAAeD,CAAf;AAAoB,IAApB,CAA0B5B,CAA1B,CACAmB,EAAA,CAAiBS,CAIjB,KAAIE,EAAaX,CAAAW,WAAbA,CAAyC5B,CAAA6B,YAAA,EAK7CZ,EAAAa,GAAA,CAAkB,UAAlB,CAA8B,QAAQ,EAAG,CACnCb,CAAJ,EAAsBA,CAAAW,WAAtB,GAAoDA,CAApD,GACE5B,CAAA+B,WAAA,CAA0B7B,CAA1B,CACA,CAAAgB,CAAAc,OAAA,EAFF,CADuC,CAAzC,CAX+B,CAAjC,CAFe,CAJ8B,CA0BjDA,OAAQA,QAAQ,EAAG,CACjB,GAAIf,CAAJ,CAAoB,CAClB,IAAIS,EAAMT,CACVA,EAAA,CAAiB,IACjB3B,EAAA2C,MAAA,CAAeP,CAAf,CAHkB,CADH,CA1B8B,CAAnD,CAvBiE,CAN9D,CAD8B,CAAhC,CAD4B,CAtlBrC,IAAId,EAAUzB,CAAAyB,QAAd,CACIsB,EAAU/C,CAAA+C,QADd,CAEIC,EAAWhD,CAAAgD,SAFf,CAGIC,EAASjD,CAAAW,QA4ObX,EAAAkD,OAAA,CAAe,YAAf,CAA6B,EAA7B,CAAAC,UAAA,CA0Ec,YA1Ed,CA0E4B,CAAC,UAAD,CAAa,QAAQ,CAAChD,CAAD,CAAW,CA0JvDiD,QAASA,EAAY,CAAC1C,CAAD,CAAQ2C,CAAR,CAAc,CAClC,MAAQL,EAAA,CAASK,CAAT,CAAR,EAA0C,CAA1C,GAA0BA,CAAAC,OAA1B,EACOC,CAAA,CAAO7C,CAAAkB,MAAA,CAAYyB,CAAZ,CAAP,CAF2B,CAKnCE,QAASA,EAAM,CAACC,CAAD,CAAM,CACnB,MAAOR,EAAA,CAASQ,CAAT,CAAA,CAAgBA,CAAAF,OAAhB,CAA6B,CAAEE,CAAAA,CADnB,CA3JrB,MAAO,CACLhD,QAAS,YADJ,CAELJ,SAAU,IAFL,CAGLqD,WAAY,CAAC,UAAD,CAAa,QAAb,CAAuB,QAAvB,CAAiC,QAAQ,CAACC,CAAD;AAAWC,CAAX,CAAmBC,CAAnB,CAA2B,CAkG9EC,QAASA,EAAmB,CAACC,CAAD,CAASC,CAAT,CAAkB,CAG5C,IAFA,IAAIC,EAAWD,CAAf,CACIE,EAAe,EACnB,CAAOD,CAAP,EAAmBA,CAAnB,GAAgCF,CAAhC,CAAA,CAAwC,CACtC,IAAII,EAAUF,CAAAG,gBACd,IAAID,CAAJ,EAAeA,CAAAZ,OAAf,CACE,MAAOc,EAAA,CAASF,CAAT,CAKLF,EAAAK,WAAAf,OAAJ,EAAqE,EAArE,EAAkCW,CAAA7B,QAAA,CAAqB4B,CAArB,CAAlC,EACEC,CAAAK,KAAA,CAAkBN,CAAlB,CACA,CAAAA,CAAA,CAAWA,CAAAK,WAAA,CAAoBL,CAAAK,WAAAf,OAApB,CAAiD,CAAjD,CAFb,EAIEU,CAJF,CAIaA,CAAAO,gBAJb,EAIyCP,CAAAQ,WAZH,CAHI,CAjG9C,IAAIC,EAAO,IAAX,CACIC,EAAY,CADhB,CAEIC,EAAe,CAEnB,KAAAjC,YAAA,CAAmBkC,QAAoB,EAAG,CAAE,MAAOD,EAAA,EAAT,CAE1C,KAAIP,EAAW,IAAAA,SAAXA,CAA2B,EAA/B,CACIS,CADJ,CACiBC,CAEjB,KAAAC,OAAA,CAAcC,QAAQ,CAAC7C,CAAD,CAAa,CACjCA,CAAA,CAAaA,CAAb,EAA2B,EAE3B0C,EAAA,CAAc,CAAA,CACdC,EAAA,CAAmB3C,CAanB,KAVA,IAAI8C,EAAW7B,CAAA,CAAaO,CAAb,CAAqBC,CAAAsB,mBAArB,CAAXD,EACW7B,CAAA,CAAaO,CAAb,CAAqBC,CAAAqB,SAArB,CADf,CAGIE,EAAoB,EAHxB,CAIIC,EAAc,EAJlB,CAKIC,EAAcZ,CAAAa,KALlB,CAMIC,EAAe,CAAA,CANnB,CAOIC,EAAgB,CAGpB,CAAsB,IAAtB,EAAOH,CAAP,CAAA,CAA4B,CAC1BG,CAAA,EACA,KAAIzD,EAAcsD,CAAAI,QAAlB,CAEIC,EAAc,CAAA,CACbH,EAAL,EACExC,CAAA,CAAQZ,CAAR,CAAoB,QAAQ,CAACwD,CAAD,CAAQC,CAAR,CAAa,CAClCF,CAAAA,CAAL,EAAoBnC,CAAA,CAAOoC,CAAP,CAApB,EAAqC5D,CAAAE,KAAA,CAAiB2D,CAAjB,CAArC;AAEM,CAAAR,CAAA,CAAYQ,CAAZ,CAFN,GAKEF,CACA,CAHAN,CAAA,CAAYQ,CAAZ,CAGA,CAHmB,CAAA,CAGnB,CAAA7D,CAAAO,OAAA,EANF,CADuC,CAAzC,CAYEoD,EAAJ,CAGEH,CAHF,CAGiB,CAACN,CAHlB,CAKEE,CAAAb,KAAA,CAAuBvC,CAAvB,CAGFsD,EAAA,CAAcA,CAAAQ,KA1BY,CA6B5B9C,CAAA,CAAQoC,CAAR,CAA2B,QAAQ,CAACpD,CAAD,CAAc,CAC/CA,CAAAc,OAAA,EAD+C,CAAjD,CAIAsC,EAAA7B,OAAA,GAA6BkC,CAA7B,CACKrF,CAAA2F,SAAA,CAAkBpC,CAAlB,CAnEQqC,WAmER,CAlEUC,aAkEV,CADL,CAEK7F,CAAA2F,SAAA,CAAkBpC,CAAlB,CAnEUsC,aAmEV,CApEQD,WAoER,CApD4B,CAuDnCpC,EAAA9B,iBAAA,CAAwB+B,CAAAqC,WAAxB,EAA6CrC,CAAA,CAAO,KAAP,CAA7C,CAA4Da,CAAAM,OAA5D,CAEA,KAAApD,SAAA,CAAgBuE,QAAQ,EAAG,CACpBrB,CAAL,GACEA,CACA,CADc,CAAA,CACd,CAAAlB,CAAAwC,WAAA,CAAkB,QAAQ,EAAG,CACvBtB,CAAJ,EACEC,CADF,EACsBL,CAAAM,OAAA,CAAYD,CAAZ,CAFK,CAA7B,CAFF,CADyB,CAW3B,KAAA9C,SAAA,CAAgBoE,QAAQ,CAACrC,CAAD,CAAUhC,CAAV,CAAuB,CAC7C,IAAIsE,EAAU3B,CAAA4B,SAAA,EACdlC,EAAA,CAASiC,CAAT,CAAA,CAAoB,CAClBZ,QAAS1D,CADS,CAGF,KAAA,EAAA2B,CAAA,CAAS,CAAT,CAAA,CAoCd6C,EAAcnC,CAAA,CApCsBiC,CAoCtB,CACb5B,EAAAa,KAAL,CAIE,CADIkB,CACJ,CADY3C,CAAA,CAAoBC,CAApB,CAxCiBC,CAwCjB,CACZ,GACEwC,CAAAV,KACA,CADmBW,CAAAX,KACnB,CAAAW,CAAAX,KAAA,CAAaU,CAFf,GAIEA,CAAAV,KACA,CADmBpB,CAAAa,KACnB,CAAAb,CAAAa,KAAA,CAAYiB,CALd,CAJF,CACE9B,CAAAa,KADF,CACciB,CArCdxC,EAAAI,gBAAA,CAA0BkC,CAC1B3B,EAAA,EAEAD,EAAA9C,SAAA,EAT6C,CAY/C;IAAAiB,WAAA,CAAkB6D,QAAQ,CAAC1C,CAAD,CAAU,CAClC,IAAI6B,EAAM7B,CAAAI,gBACV,QAAOJ,CAAAI,gBA2CP,KAAIoC,EAAcnC,CAAA,CA1CsBwB,CA0CtB,CAGlB,EADIY,CACJ,CADY3C,CAAA,CA5CMH,CAAAI,CAAS,CAATA,CA4CN,CA5CmBC,CA4CnB,CACZ,EACEyC,CAAAX,KADF,CACeU,CAAAV,KADf,CAGEpB,CAAAa,KAHF,CAGciB,CAAAV,KA/Cd,QAAOzB,CAAA,CAASwB,CAAT,CACPnB,EAAA9C,SAAA,EALkC,CA1F0C,CAApE,CAHP,CAJgD,CAAhC,CA1E5B,CAAAwB,UAAA,CA4Qc,mBA5Qd,CA6QK,CAAC,kBAAD,CAAqB,WAArB,CAAkC,UAAlC,CAA8C,QAAQ,CAACuD,CAAD,CAAmBC,CAAnB,CAA8BC,CAA9B,CAAwC,CAE9F,MAAO,CACLxG,SAAU,IADL,CAELI,QAAS,cAFJ,CAGLC,KAAMA,QAAQ,CAACkD,CAAD,CAAShD,CAAT,CAAkBC,CAAlB,CAAyB,CACrC,IAAIiG,EAAMjG,CAAAkG,kBAAND,EAAiCjG,CAAAiG,IACrCH,EAAA,CAAiBG,CAAjB,CAAAE,KAAA,CAA2B,QAAQ,CAACC,CAAD,CAAO,CACxCJ,CAAA,CAASI,CAAT,CAAA,CAAerD,CAAf,CAAuB,QAAQ,CAACsD,CAAD,CAAW,CACxCtG,CAAAuG,MAAA,CAAcD,CAAd,CAGIE,EAAAA,CAASlE,CAAA,CAAO0D,CAAA,CAAU,CAAV,CAAAS,cAAA,CAA2B,sBAA3B,CAAoDP,CAApD,CAA0D,GAA1D,CAAP,CACblG,EAAAuG,MAAA,CAAcC,CAAd,CAGAxG,EAAA0G,OAAA,EARwC,CAA1C,CADwC,CAA1C,CAFqC,CAHlC,CAFuF,CAA9F,CA7QL,CAAAlE,UAAA,CAoUa,WApUb;AAoU0BjD,CAAA,EApU1B,CAAAiD,UAAA,CAqWa,cArWb,CAqW6BjD,CAAA,EArW7B,CAnPsC,CAArC,CAAD,CAyqBGH,MAzqBH,CAyqBWA,MAAAC,QAzqBX;", +"sources":["angular-messages.js"], +"names":["window","angular","undefined","ngMessageDirectiveFactory","$animate","restrict","transclude","priority","terminal","require","link","scope","element","attrs","ngMessagesCtrl","$transclude","commentNode","records","staticExp","ngMessage","when","dynamicExp","ngMessageExp","whenExp","assignRecords","items","isArray","split","reRender","$eval","$watchCollection","currentElement","messageCtrl","register","test","name","collection","indexOf","hasOwnProperty","attach","elm","enter","$$attachId","getAttachId","on","deregister","detach","leave","forEach","isString","jqLite","module","directive","isAttrTruthy","attr","length","truthy","val","controller","$element","$scope","$attrs","findPreviousMessage","parent","comment","prevNode","parentLookup","prevKey","$$ngMessageNode","messages","childNodes","push","previousSibling","parentNode","ctrl","latestKey","nextAttachId","this.getAttachId","renderLater","cachedCollection","render","this.render","multiple","ngMessagesMultiple","unmatchedMessages","matchedKeys","messageItem","head","messageFound","totalMessages","message","messageUsed","value","key","next","setClass","ACTIVE_CLASS","INACTIVE_CLASS","ngMessages","this.reRender","$evalAsync","this.register","nextKey","toString","messageNode","match","this.deregister","$templateRequest","$document","$compile","src","ngMessagesInclude","then","html","contents","after","anchor","createComment","remove"] +} diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-mocks.js b/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-mocks.js new file mode 100644 index 000000000..34d360870 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-mocks.js @@ -0,0 +1,2842 @@ +/** + * @license AngularJS v1.5.0 + * (c) 2010-2016 Google, Inc. http://angularjs.org + * License: MIT + */ +(function(window, angular, undefined) { + +'use strict'; + +/** + * @ngdoc object + * @name angular.mock + * @description + * + * Namespace from 'angular-mocks.js' which contains testing related code. + */ +angular.mock = {}; + +/** + * ! This is a private undocumented service ! + * + * @name $browser + * + * @description + * This service is a mock implementation of {@link ng.$browser}. It provides fake + * implementation for commonly used browser apis that are hard to test, e.g. setTimeout, xhr, + * cookies, etc... + * + * The api of this service is the same as that of the real {@link ng.$browser $browser}, except + * that there are several helper methods available which can be used in tests. + */ +angular.mock.$BrowserProvider = function() { + this.$get = function() { + return new angular.mock.$Browser(); + }; +}; + +angular.mock.$Browser = function() { + var self = this; + + this.isMock = true; + self.$$url = "http://server/"; + self.$$lastUrl = self.$$url; // used by url polling fn + self.pollFns = []; + + // TODO(vojta): remove this temporary api + self.$$completeOutstandingRequest = angular.noop; + self.$$incOutstandingRequestCount = angular.noop; + + + // register url polling fn + + self.onUrlChange = function(listener) { + self.pollFns.push( + function() { + if (self.$$lastUrl !== self.$$url || self.$$state !== self.$$lastState) { + self.$$lastUrl = self.$$url; + self.$$lastState = self.$$state; + listener(self.$$url, self.$$state); + } + } + ); + + return listener; + }; + + self.$$applicationDestroyed = angular.noop; + self.$$checkUrlChange = angular.noop; + + self.deferredFns = []; + self.deferredNextId = 0; + + self.defer = function(fn, delay) { + delay = delay || 0; + self.deferredFns.push({time:(self.defer.now + delay), fn:fn, id: self.deferredNextId}); + self.deferredFns.sort(function(a, b) { return a.time - b.time;}); + return self.deferredNextId++; + }; + + + /** + * @name $browser#defer.now + * + * @description + * Current milliseconds mock time. + */ + self.defer.now = 0; + + + self.defer.cancel = function(deferId) { + var fnIndex; + + angular.forEach(self.deferredFns, function(fn, index) { + if (fn.id === deferId) fnIndex = index; + }); + + if (angular.isDefined(fnIndex)) { + self.deferredFns.splice(fnIndex, 1); + return true; + } + + return false; + }; + + + /** + * @name $browser#defer.flush + * + * @description + * Flushes all pending requests and executes the defer callbacks. + * + * @param {number=} number of milliseconds to flush. See {@link #defer.now} + */ + self.defer.flush = function(delay) { + if (angular.isDefined(delay)) { + self.defer.now += delay; + } else { + if (self.deferredFns.length) { + self.defer.now = self.deferredFns[self.deferredFns.length - 1].time; + } else { + throw new Error('No deferred tasks to be flushed'); + } + } + + while (self.deferredFns.length && self.deferredFns[0].time <= self.defer.now) { + self.deferredFns.shift().fn(); + } + }; + + self.$$baseHref = '/'; + self.baseHref = function() { + return this.$$baseHref; + }; +}; +angular.mock.$Browser.prototype = { + +/** + * @name $browser#poll + * + * @description + * run all fns in pollFns + */ + poll: function poll() { + angular.forEach(this.pollFns, function(pollFn) { + pollFn(); + }); + }, + + url: function(url, replace, state) { + if (angular.isUndefined(state)) { + state = null; + } + if (url) { + this.$$url = url; + // Native pushState serializes & copies the object; simulate it. + this.$$state = angular.copy(state); + return this; + } + + return this.$$url; + }, + + state: function() { + return this.$$state; + }, + + notifyWhenNoOutstandingRequests: function(fn) { + fn(); + } +}; + + +/** + * @ngdoc provider + * @name $exceptionHandlerProvider + * + * @description + * Configures the mock implementation of {@link ng.$exceptionHandler} to rethrow or to log errors + * passed to the `$exceptionHandler`. + */ + +/** + * @ngdoc service + * @name $exceptionHandler + * + * @description + * Mock implementation of {@link ng.$exceptionHandler} that rethrows or logs errors passed + * to it. See {@link ngMock.$exceptionHandlerProvider $exceptionHandlerProvider} for configuration + * information. + * + * + * ```js + * describe('$exceptionHandlerProvider', function() { + * + * it('should capture log messages and exceptions', function() { + * + * module(function($exceptionHandlerProvider) { + * $exceptionHandlerProvider.mode('log'); + * }); + * + * inject(function($log, $exceptionHandler, $timeout) { + * $timeout(function() { $log.log(1); }); + * $timeout(function() { $log.log(2); throw 'banana peel'; }); + * $timeout(function() { $log.log(3); }); + * expect($exceptionHandler.errors).toEqual([]); + * expect($log.assertEmpty()); + * $timeout.flush(); + * expect($exceptionHandler.errors).toEqual(['banana peel']); + * expect($log.log.logs).toEqual([[1], [2], [3]]); + * }); + * }); + * }); + * ``` + */ + +angular.mock.$ExceptionHandlerProvider = function() { + var handler; + + /** + * @ngdoc method + * @name $exceptionHandlerProvider#mode + * + * @description + * Sets the logging mode. + * + * @param {string} mode Mode of operation, defaults to `rethrow`. + * + * - `log`: Sometimes it is desirable to test that an error is thrown, for this case the `log` + * mode stores an array of errors in `$exceptionHandler.errors`, to allow later + * assertion of them. See {@link ngMock.$log#assertEmpty assertEmpty()} and + * {@link ngMock.$log#reset reset()} + * - `rethrow`: If any errors are passed to the handler in tests, it typically means that there + * is a bug in the application or test, so this mock will make these tests fail. + * For any implementations that expect exceptions to be thrown, the `rethrow` mode + * will also maintain a log of thrown errors. + */ + this.mode = function(mode) { + + switch (mode) { + case 'log': + case 'rethrow': + var errors = []; + handler = function(e) { + if (arguments.length == 1) { + errors.push(e); + } else { + errors.push([].slice.call(arguments, 0)); + } + if (mode === "rethrow") { + throw e; + } + }; + handler.errors = errors; + break; + default: + throw new Error("Unknown mode '" + mode + "', only 'log'/'rethrow' modes are allowed!"); + } + }; + + this.$get = function() { + return handler; + }; + + this.mode('rethrow'); +}; + + +/** + * @ngdoc service + * @name $log + * + * @description + * Mock implementation of {@link ng.$log} that gathers all logged messages in arrays + * (one array per logging level). These arrays are exposed as `logs` property of each of the + * level-specific log function, e.g. for level `error` the array is exposed as `$log.error.logs`. + * + */ +angular.mock.$LogProvider = function() { + var debug = true; + + function concat(array1, array2, index) { + return array1.concat(Array.prototype.slice.call(array2, index)); + } + + this.debugEnabled = function(flag) { + if (angular.isDefined(flag)) { + debug = flag; + return this; + } else { + return debug; + } + }; + + this.$get = function() { + var $log = { + log: function() { $log.log.logs.push(concat([], arguments, 0)); }, + warn: function() { $log.warn.logs.push(concat([], arguments, 0)); }, + info: function() { $log.info.logs.push(concat([], arguments, 0)); }, + error: function() { $log.error.logs.push(concat([], arguments, 0)); }, + debug: function() { + if (debug) { + $log.debug.logs.push(concat([], arguments, 0)); + } + } + }; + + /** + * @ngdoc method + * @name $log#reset + * + * @description + * Reset all of the logging arrays to empty. + */ + $log.reset = function() { + /** + * @ngdoc property + * @name $log#log.logs + * + * @description + * Array of messages logged using {@link ng.$log#log `log()`}. + * + * @example + * ```js + * $log.log('Some Log'); + * var first = $log.log.logs.unshift(); + * ``` + */ + $log.log.logs = []; + /** + * @ngdoc property + * @name $log#info.logs + * + * @description + * Array of messages logged using {@link ng.$log#info `info()`}. + * + * @example + * ```js + * $log.info('Some Info'); + * var first = $log.info.logs.unshift(); + * ``` + */ + $log.info.logs = []; + /** + * @ngdoc property + * @name $log#warn.logs + * + * @description + * Array of messages logged using {@link ng.$log#warn `warn()`}. + * + * @example + * ```js + * $log.warn('Some Warning'); + * var first = $log.warn.logs.unshift(); + * ``` + */ + $log.warn.logs = []; + /** + * @ngdoc property + * @name $log#error.logs + * + * @description + * Array of messages logged using {@link ng.$log#error `error()`}. + * + * @example + * ```js + * $log.error('Some Error'); + * var first = $log.error.logs.unshift(); + * ``` + */ + $log.error.logs = []; + /** + * @ngdoc property + * @name $log#debug.logs + * + * @description + * Array of messages logged using {@link ng.$log#debug `debug()`}. + * + * @example + * ```js + * $log.debug('Some Error'); + * var first = $log.debug.logs.unshift(); + * ``` + */ + $log.debug.logs = []; + }; + + /** + * @ngdoc method + * @name $log#assertEmpty + * + * @description + * Assert that all of the logging methods have no logged messages. If any messages are present, + * an exception is thrown. + */ + $log.assertEmpty = function() { + var errors = []; + angular.forEach(['error', 'warn', 'info', 'log', 'debug'], function(logLevel) { + angular.forEach($log[logLevel].logs, function(log) { + angular.forEach(log, function(logItem) { + errors.push('MOCK $log (' + logLevel + '): ' + String(logItem) + '\n' + + (logItem.stack || '')); + }); + }); + }); + if (errors.length) { + errors.unshift("Expected $log to be empty! Either a message was logged unexpectedly, or " + + "an expected log message was not checked and removed:"); + errors.push(''); + throw new Error(errors.join('\n---------\n')); + } + }; + + $log.reset(); + return $log; + }; +}; + + +/** + * @ngdoc service + * @name $interval + * + * @description + * Mock implementation of the $interval service. + * + * Use {@link ngMock.$interval#flush `$interval.flush(millis)`} to + * move forward by `millis` milliseconds and trigger any functions scheduled to run in that + * time. + * + * @param {function()} fn A function that should be called repeatedly. + * @param {number} delay Number of milliseconds between each function call. + * @param {number=} [count=0] Number of times to repeat. If not set, or 0, will repeat + * indefinitely. + * @param {boolean=} [invokeApply=true] If set to `false` skips model dirty checking, otherwise + * will invoke `fn` within the {@link ng.$rootScope.Scope#$apply $apply} block. + * @param {...*=} Pass additional parameters to the executed function. + * @returns {promise} A promise which will be notified on each iteration. + */ +angular.mock.$IntervalProvider = function() { + this.$get = ['$browser', '$rootScope', '$q', '$$q', + function($browser, $rootScope, $q, $$q) { + var repeatFns = [], + nextRepeatId = 0, + now = 0; + + var $interval = function(fn, delay, count, invokeApply) { + var hasParams = arguments.length > 4, + args = hasParams ? Array.prototype.slice.call(arguments, 4) : [], + iteration = 0, + skipApply = (angular.isDefined(invokeApply) && !invokeApply), + deferred = (skipApply ? $$q : $q).defer(), + promise = deferred.promise; + + count = (angular.isDefined(count)) ? count : 0; + promise.then(null, null, (!hasParams) ? fn : function() { + fn.apply(null, args); + }); + + promise.$$intervalId = nextRepeatId; + + function tick() { + deferred.notify(iteration++); + + if (count > 0 && iteration >= count) { + var fnIndex; + deferred.resolve(iteration); + + angular.forEach(repeatFns, function(fn, index) { + if (fn.id === promise.$$intervalId) fnIndex = index; + }); + + if (angular.isDefined(fnIndex)) { + repeatFns.splice(fnIndex, 1); + } + } + + if (skipApply) { + $browser.defer.flush(); + } else { + $rootScope.$apply(); + } + } + + repeatFns.push({ + nextTime:(now + delay), + delay: delay, + fn: tick, + id: nextRepeatId, + deferred: deferred + }); + repeatFns.sort(function(a, b) { return a.nextTime - b.nextTime;}); + + nextRepeatId++; + return promise; + }; + /** + * @ngdoc method + * @name $interval#cancel + * + * @description + * Cancels a task associated with the `promise`. + * + * @param {promise} promise A promise from calling the `$interval` function. + * @returns {boolean} Returns `true` if the task was successfully cancelled. + */ + $interval.cancel = function(promise) { + if (!promise) return false; + var fnIndex; + + angular.forEach(repeatFns, function(fn, index) { + if (fn.id === promise.$$intervalId) fnIndex = index; + }); + + if (angular.isDefined(fnIndex)) { + repeatFns[fnIndex].deferred.reject('canceled'); + repeatFns.splice(fnIndex, 1); + return true; + } + + return false; + }; + + /** + * @ngdoc method + * @name $interval#flush + * @description + * + * Runs interval tasks scheduled to be run in the next `millis` milliseconds. + * + * @param {number=} millis maximum timeout amount to flush up until. + * + * @return {number} The amount of time moved forward. + */ + $interval.flush = function(millis) { + now += millis; + while (repeatFns.length && repeatFns[0].nextTime <= now) { + var task = repeatFns[0]; + task.fn(); + task.nextTime += task.delay; + repeatFns.sort(function(a, b) { return a.nextTime - b.nextTime;}); + } + return millis; + }; + + return $interval; + }]; +}; + + +/* jshint -W101 */ +/* The R_ISO8061_STR regex is never going to fit into the 100 char limit! + * This directive should go inside the anonymous function but a bug in JSHint means that it would + * not be enacted early enough to prevent the warning. + */ +var R_ISO8061_STR = /^(\d{4})-?(\d\d)-?(\d\d)(?:T(\d\d)(?:\:?(\d\d)(?:\:?(\d\d)(?:\.(\d{3}))?)?)?(Z|([+-])(\d\d):?(\d\d)))?$/; + +function jsonStringToDate(string) { + var match; + if (match = string.match(R_ISO8061_STR)) { + var date = new Date(0), + tzHour = 0, + tzMin = 0; + if (match[9]) { + tzHour = toInt(match[9] + match[10]); + tzMin = toInt(match[9] + match[11]); + } + date.setUTCFullYear(toInt(match[1]), toInt(match[2]) - 1, toInt(match[3])); + date.setUTCHours(toInt(match[4] || 0) - tzHour, + toInt(match[5] || 0) - tzMin, + toInt(match[6] || 0), + toInt(match[7] || 0)); + return date; + } + return string; +} + +function toInt(str) { + return parseInt(str, 10); +} + +function padNumber(num, digits, trim) { + var neg = ''; + if (num < 0) { + neg = '-'; + num = -num; + } + num = '' + num; + while (num.length < digits) num = '0' + num; + if (trim) { + num = num.substr(num.length - digits); + } + return neg + num; +} + + +/** + * @ngdoc type + * @name angular.mock.TzDate + * @description + * + * *NOTE*: this is not an injectable instance, just a globally available mock class of `Date`. + * + * Mock of the Date type which has its timezone specified via constructor arg. + * + * The main purpose is to create Date-like instances with timezone fixed to the specified timezone + * offset, so that we can test code that depends on local timezone settings without dependency on + * the time zone settings of the machine where the code is running. + * + * @param {number} offset Offset of the *desired* timezone in hours (fractions will be honored) + * @param {(number|string)} timestamp Timestamp representing the desired time in *UTC* + * + * @example + * !!!! WARNING !!!!! + * This is not a complete Date object so only methods that were implemented can be called safely. + * To make matters worse, TzDate instances inherit stuff from Date via a prototype. + * + * We do our best to intercept calls to "unimplemented" methods, but since the list of methods is + * incomplete we might be missing some non-standard methods. This can result in errors like: + * "Date.prototype.foo called on incompatible Object". + * + * ```js + * var newYearInBratislava = new TzDate(-1, '2009-12-31T23:00:00Z'); + * newYearInBratislava.getTimezoneOffset() => -60; + * newYearInBratislava.getFullYear() => 2010; + * newYearInBratislava.getMonth() => 0; + * newYearInBratislava.getDate() => 1; + * newYearInBratislava.getHours() => 0; + * newYearInBratislava.getMinutes() => 0; + * newYearInBratislava.getSeconds() => 0; + * ``` + * + */ +angular.mock.TzDate = function(offset, timestamp) { + var self = new Date(0); + if (angular.isString(timestamp)) { + var tsStr = timestamp; + + self.origDate = jsonStringToDate(timestamp); + + timestamp = self.origDate.getTime(); + if (isNaN(timestamp)) { + throw { + name: "Illegal Argument", + message: "Arg '" + tsStr + "' passed into TzDate constructor is not a valid date string" + }; + } + } else { + self.origDate = new Date(timestamp); + } + + var localOffset = new Date(timestamp).getTimezoneOffset(); + self.offsetDiff = localOffset * 60 * 1000 - offset * 1000 * 60 * 60; + self.date = new Date(timestamp + self.offsetDiff); + + self.getTime = function() { + return self.date.getTime() - self.offsetDiff; + }; + + self.toLocaleDateString = function() { + return self.date.toLocaleDateString(); + }; + + self.getFullYear = function() { + return self.date.getFullYear(); + }; + + self.getMonth = function() { + return self.date.getMonth(); + }; + + self.getDate = function() { + return self.date.getDate(); + }; + + self.getHours = function() { + return self.date.getHours(); + }; + + self.getMinutes = function() { + return self.date.getMinutes(); + }; + + self.getSeconds = function() { + return self.date.getSeconds(); + }; + + self.getMilliseconds = function() { + return self.date.getMilliseconds(); + }; + + self.getTimezoneOffset = function() { + return offset * 60; + }; + + self.getUTCFullYear = function() { + return self.origDate.getUTCFullYear(); + }; + + self.getUTCMonth = function() { + return self.origDate.getUTCMonth(); + }; + + self.getUTCDate = function() { + return self.origDate.getUTCDate(); + }; + + self.getUTCHours = function() { + return self.origDate.getUTCHours(); + }; + + self.getUTCMinutes = function() { + return self.origDate.getUTCMinutes(); + }; + + self.getUTCSeconds = function() { + return self.origDate.getUTCSeconds(); + }; + + self.getUTCMilliseconds = function() { + return self.origDate.getUTCMilliseconds(); + }; + + self.getDay = function() { + return self.date.getDay(); + }; + + // provide this method only on browsers that already have it + if (self.toISOString) { + self.toISOString = function() { + return padNumber(self.origDate.getUTCFullYear(), 4) + '-' + + padNumber(self.origDate.getUTCMonth() + 1, 2) + '-' + + padNumber(self.origDate.getUTCDate(), 2) + 'T' + + padNumber(self.origDate.getUTCHours(), 2) + ':' + + padNumber(self.origDate.getUTCMinutes(), 2) + ':' + + padNumber(self.origDate.getUTCSeconds(), 2) + '.' + + padNumber(self.origDate.getUTCMilliseconds(), 3) + 'Z'; + }; + } + + //hide all methods not implemented in this mock that the Date prototype exposes + var unimplementedMethods = ['getUTCDay', + 'getYear', 'setDate', 'setFullYear', 'setHours', 'setMilliseconds', + 'setMinutes', 'setMonth', 'setSeconds', 'setTime', 'setUTCDate', 'setUTCFullYear', + 'setUTCHours', 'setUTCMilliseconds', 'setUTCMinutes', 'setUTCMonth', 'setUTCSeconds', + 'setYear', 'toDateString', 'toGMTString', 'toJSON', 'toLocaleFormat', 'toLocaleString', + 'toLocaleTimeString', 'toSource', 'toString', 'toTimeString', 'toUTCString', 'valueOf']; + + angular.forEach(unimplementedMethods, function(methodName) { + self[methodName] = function() { + throw new Error("Method '" + methodName + "' is not implemented in the TzDate mock"); + }; + }); + + return self; +}; + +//make "tzDateInstance instanceof Date" return true +angular.mock.TzDate.prototype = Date.prototype; +/* jshint +W101 */ + + +/** + * @ngdoc service + * @name $animate + * + * @description + * Mock implementation of the {@link ng.$animate `$animate`} service. Exposes two additional methods + * for testing animations. + */ +angular.mock.animate = angular.module('ngAnimateMock', ['ng']) + + .config(['$provide', function($provide) { + + $provide.factory('$$forceReflow', function() { + function reflowFn() { + reflowFn.totalReflows++; + } + reflowFn.totalReflows = 0; + return reflowFn; + }); + + $provide.factory('$$animateAsyncRun', function() { + var queue = []; + var queueFn = function() { + return function(fn) { + queue.push(fn); + }; + }; + queueFn.flush = function() { + if (queue.length === 0) return false; + + for (var i = 0; i < queue.length; i++) { + queue[i](); + } + queue = []; + + return true; + }; + return queueFn; + }); + + $provide.decorator('$$animateJs', ['$delegate', function($delegate) { + var runners = []; + + var animateJsConstructor = function() { + var animator = $delegate.apply($delegate, arguments); + // If no javascript animation is found, animator is undefined + if (animator) { + runners.push(animator); + } + return animator; + }; + + animateJsConstructor.$closeAndFlush = function() { + runners.forEach(function(runner) { + runner.end(); + }); + runners = []; + }; + + return animateJsConstructor; + }]); + + $provide.decorator('$animateCss', ['$delegate', function($delegate) { + var runners = []; + + var animateCssConstructor = function(element, options) { + var animator = $delegate(element, options); + runners.push(animator); + return animator; + }; + + animateCssConstructor.$closeAndFlush = function() { + runners.forEach(function(runner) { + runner.end(); + }); + runners = []; + }; + + return animateCssConstructor; + }]); + + $provide.decorator('$animate', ['$delegate', '$timeout', '$browser', '$$rAF', '$animateCss', '$$animateJs', + '$$forceReflow', '$$animateAsyncRun', '$rootScope', + function($delegate, $timeout, $browser, $$rAF, $animateCss, $$animateJs, + $$forceReflow, $$animateAsyncRun, $rootScope) { + var animate = { + queue: [], + cancel: $delegate.cancel, + on: $delegate.on, + off: $delegate.off, + pin: $delegate.pin, + get reflows() { + return $$forceReflow.totalReflows; + }, + enabled: $delegate.enabled, + /** + * @ngdoc method + * @name $animate#closeAndFlush + * @description + * + * This method will close all pending animations (both {@link ngAnimate#javascript-based-animations Javascript} + * and {@link ngAnimate.$animateCss CSS}) and it will also flush any remaining animation frames and/or callbacks. + */ + closeAndFlush: function() { + // we allow the flush command to swallow the errors + // because depending on whether CSS or JS animations are + // used, there may not be a RAF flush. The primary flush + // at the end of this function must throw an exception + // because it will track if there were pending animations + this.flush(true); + $animateCss.$closeAndFlush(); + $$animateJs.$closeAndFlush(); + this.flush(); + }, + /** + * @ngdoc method + * @name $animate#flush + * @description + * + * This method is used to flush the pending callbacks and animation frames to either start + * an animation or conclude an animation. Note that this will not actually close an + * actively running animation (see {@link ngMock.$animate#closeAndFlush `closeAndFlush()`} for that). + */ + flush: function(hideErrors) { + $rootScope.$digest(); + + var doNextRun, somethingFlushed = false; + do { + doNextRun = false; + + if ($$rAF.queue.length) { + $$rAF.flush(); + doNextRun = somethingFlushed = true; + } + + if ($$animateAsyncRun.flush()) { + doNextRun = somethingFlushed = true; + } + } while (doNextRun); + + if (!somethingFlushed && !hideErrors) { + throw new Error('No pending animations ready to be closed or flushed'); + } + + $rootScope.$digest(); + } + }; + + angular.forEach( + ['animate','enter','leave','move','addClass','removeClass','setClass'], function(method) { + animate[method] = function() { + animate.queue.push({ + event: method, + element: arguments[0], + options: arguments[arguments.length - 1], + args: arguments + }); + return $delegate[method].apply($delegate, arguments); + }; + }); + + return animate; + }]); + + }]); + + +/** + * @ngdoc function + * @name angular.mock.dump + * @description + * + * *NOTE*: this is not an injectable instance, just a globally available function. + * + * Method for serializing common angular objects (scope, elements, etc..) into strings, useful for + * debugging. + * + * This method is also available on window, where it can be used to display objects on debug + * console. + * + * @param {*} object - any object to turn into string. + * @return {string} a serialized string of the argument + */ +angular.mock.dump = function(object) { + return serialize(object); + + function serialize(object) { + var out; + + if (angular.isElement(object)) { + object = angular.element(object); + out = angular.element('
    '); + angular.forEach(object, function(element) { + out.append(angular.element(element).clone()); + }); + out = out.html(); + } else if (angular.isArray(object)) { + out = []; + angular.forEach(object, function(o) { + out.push(serialize(o)); + }); + out = '[ ' + out.join(', ') + ' ]'; + } else if (angular.isObject(object)) { + if (angular.isFunction(object.$eval) && angular.isFunction(object.$apply)) { + out = serializeScope(object); + } else if (object instanceof Error) { + out = object.stack || ('' + object.name + ': ' + object.message); + } else { + // TODO(i): this prevents methods being logged, + // we should have a better way to serialize objects + out = angular.toJson(object, true); + } + } else { + out = String(object); + } + + return out; + } + + function serializeScope(scope, offset) { + offset = offset || ' '; + var log = [offset + 'Scope(' + scope.$id + '): {']; + for (var key in scope) { + if (Object.prototype.hasOwnProperty.call(scope, key) && !key.match(/^(\$|this)/)) { + log.push(' ' + key + ': ' + angular.toJson(scope[key])); + } + } + var child = scope.$$childHead; + while (child) { + log.push(serializeScope(child, offset + ' ')); + child = child.$$nextSibling; + } + log.push('}'); + return log.join('\n' + offset); + } +}; + +/** + * @ngdoc service + * @name $httpBackend + * @description + * Fake HTTP backend implementation suitable for unit testing applications that use the + * {@link ng.$http $http service}. + * + * *Note*: For fake HTTP backend implementation suitable for end-to-end testing or backend-less + * development please see {@link ngMockE2E.$httpBackend e2e $httpBackend mock}. + * + * During unit testing, we want our unit tests to run quickly and have no external dependencies so + * we don’t want to send [XHR](https://developer.mozilla.org/en/xmlhttprequest) or + * [JSONP](http://en.wikipedia.org/wiki/JSONP) requests to a real server. All we really need is + * to verify whether a certain request has been sent or not, or alternatively just let the + * application make requests, respond with pre-trained responses and assert that the end result is + * what we expect it to be. + * + * This mock implementation can be used to respond with static or dynamic responses via the + * `expect` and `when` apis and their shortcuts (`expectGET`, `whenPOST`, etc). + * + * When an Angular application needs some data from a server, it calls the $http service, which + * sends the request to a real server using $httpBackend service. With dependency injection, it is + * easy to inject $httpBackend mock (which has the same API as $httpBackend) and use it to verify + * the requests and respond with some testing data without sending a request to a real server. + * + * There are two ways to specify what test data should be returned as http responses by the mock + * backend when the code under test makes http requests: + * + * - `$httpBackend.expect` - specifies a request expectation + * - `$httpBackend.when` - specifies a backend definition + * + * + * ## Request Expectations vs Backend Definitions + * + * Request expectations provide a way to make assertions about requests made by the application and + * to define responses for those requests. The test will fail if the expected requests are not made + * or they are made in the wrong order. + * + * Backend definitions allow you to define a fake backend for your application which doesn't assert + * if a particular request was made or not, it just returns a trained response if a request is made. + * The test will pass whether or not the request gets made during testing. + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
    Request expectationsBackend definitions
    Syntax.expect(...).respond(...).when(...).respond(...)
    Typical usagestrict unit testsloose (black-box) unit testing
    Fulfills multiple requestsNOYES
    Order of requests mattersYESNO
    Request requiredYESNO
    Response requiredoptional (see below)YES
    + * + * In cases where both backend definitions and request expectations are specified during unit + * testing, the request expectations are evaluated first. + * + * If a request expectation has no response specified, the algorithm will search your backend + * definitions for an appropriate response. + * + * If a request didn't match any expectation or if the expectation doesn't have the response + * defined, the backend definitions are evaluated in sequential order to see if any of them match + * the request. The response from the first matched definition is returned. + * + * + * ## Flushing HTTP requests + * + * The $httpBackend used in production always responds to requests asynchronously. If we preserved + * this behavior in unit testing, we'd have to create async unit tests, which are hard to write, + * to follow and to maintain. But neither can the testing mock respond synchronously; that would + * change the execution of the code under test. For this reason, the mock $httpBackend has a + * `flush()` method, which allows the test to explicitly flush pending requests. This preserves + * the async api of the backend, while allowing the test to execute synchronously. + * + * + * ## Unit testing with mock $httpBackend + * The following code shows how to setup and use the mock backend when unit testing a controller. + * First we create the controller under test: + * + ```js + // The module code + angular + .module('MyApp', []) + .controller('MyController', MyController); + + // The controller code + function MyController($scope, $http) { + var authToken; + + $http.get('/auth.py').then(function(response) { + authToken = response.headers('A-Token'); + $scope.user = response.data; + }); + + $scope.saveMessage = function(message) { + var headers = { 'Authorization': authToken }; + $scope.status = 'Saving...'; + + $http.post('/add-msg.py', message, { headers: headers } ).then(function(response) { + $scope.status = ''; + }).catch(function() { + $scope.status = 'Failed...'; + }); + }; + } + ``` + * + * Now we setup the mock backend and create the test specs: + * + ```js + // testing controller + describe('MyController', function() { + var $httpBackend, $rootScope, createController, authRequestHandler; + + // Set up the module + beforeEach(module('MyApp')); + + beforeEach(inject(function($injector) { + // Set up the mock http service responses + $httpBackend = $injector.get('$httpBackend'); + // backend definition common for all tests + authRequestHandler = $httpBackend.when('GET', '/auth.py') + .respond({userId: 'userX'}, {'A-Token': 'xxx'}); + + // Get hold of a scope (i.e. the root scope) + $rootScope = $injector.get('$rootScope'); + // The $controller service is used to create instances of controllers + var $controller = $injector.get('$controller'); + + createController = function() { + return $controller('MyController', {'$scope' : $rootScope }); + }; + })); + + + afterEach(function() { + $httpBackend.verifyNoOutstandingExpectation(); + $httpBackend.verifyNoOutstandingRequest(); + }); + + + it('should fetch authentication token', function() { + $httpBackend.expectGET('/auth.py'); + var controller = createController(); + $httpBackend.flush(); + }); + + + it('should fail authentication', function() { + + // Notice how you can change the response even after it was set + authRequestHandler.respond(401, ''); + + $httpBackend.expectGET('/auth.py'); + var controller = createController(); + $httpBackend.flush(); + expect($rootScope.status).toBe('Failed...'); + }); + + + it('should send msg to server', function() { + var controller = createController(); + $httpBackend.flush(); + + // now you don’t care about the authentication, but + // the controller will still send the request and + // $httpBackend will respond without you having to + // specify the expectation and response for this request + + $httpBackend.expectPOST('/add-msg.py', 'message content').respond(201, ''); + $rootScope.saveMessage('message content'); + expect($rootScope.status).toBe('Saving...'); + $httpBackend.flush(); + expect($rootScope.status).toBe(''); + }); + + + it('should send auth header', function() { + var controller = createController(); + $httpBackend.flush(); + + $httpBackend.expectPOST('/add-msg.py', undefined, function(headers) { + // check if the header was sent, if it wasn't the expectation won't + // match the request and the test will fail + return headers['Authorization'] == 'xxx'; + }).respond(201, ''); + + $rootScope.saveMessage('whatever'); + $httpBackend.flush(); + }); + }); + ``` + * + * ## Dynamic responses + * + * You define a response to a request by chaining a call to `respond()` onto a definition or expectation. + * If you provide a **callback** as the first parameter to `respond(callback)` then you can dynamically generate + * a response based on the properties of the request. + * + * The `callback` function should be of the form `function(method, url, data, headers, params)`. + * + * ### Query parameters + * + * By default, query parameters on request URLs are parsed into the `params` object. So a request URL + * of `/list?q=searchstr&orderby=-name` would set `params` to be `{q: 'searchstr', orderby: '-name'}`. + * + * ### Regex parameter matching + * + * If an expectation or definition uses a **regex** to match the URL, you can provide an array of **keys** via a + * `params` argument. The index of each **key** in the array will match the index of a **group** in the + * **regex**. + * + * The `params` object in the **callback** will now have properties with these keys, which hold the value of the + * corresponding **group** in the **regex**. + * + * This also applies to the `when` and `expect` shortcut methods. + * + * + * ```js + * $httpBackend.expect('GET', /\/user\/(.+)/, undefined, undefined, ['id']) + * .respond(function(method, url, data, headers, params) { + * // for requested url of '/user/1234' params is {id: '1234'} + * }); + * + * $httpBackend.whenPATCH(/\/user\/(.+)\/article\/(.+)/, undefined, undefined, ['user', 'article']) + * .respond(function(method, url, data, headers, params) { + * // for url of '/user/1234/article/567' params is {user: '1234', article: '567'} + * }); + * ``` + * + * ## Matching route requests + * + * For extra convenience, `whenRoute` and `expectRoute` shortcuts are available. These methods offer colon + * delimited matching of the url path, ignoring the query string. This allows declarations + * similar to how application routes are configured with `$routeProvider`. Because these methods convert + * the definition url to regex, declaration order is important. Combined with query parameter parsing, + * the following is possible: + * + ```js + $httpBackend.whenRoute('GET', '/users/:id') + .respond(function(method, url, data, headers, params) { + return [200, MockUserList[Number(params.id)]]; + }); + + $httpBackend.whenRoute('GET', '/users') + .respond(function(method, url, data, headers, params) { + var userList = angular.copy(MockUserList), + defaultSort = 'lastName', + count, pages, isPrevious, isNext; + + // paged api response '/v1/users?page=2' + params.page = Number(params.page) || 1; + + // query for last names '/v1/users?q=Archer' + if (params.q) { + userList = $filter('filter')({lastName: params.q}); + } + + pages = Math.ceil(userList.length / pagingLength); + isPrevious = params.page > 1; + isNext = params.page < pages; + + return [200, { + count: userList.length, + previous: isPrevious, + next: isNext, + // sort field -> '/v1/users?sortBy=firstName' + results: $filter('orderBy')(userList, params.sortBy || defaultSort) + .splice((params.page - 1) * pagingLength, pagingLength) + }]; + }); + ``` + */ +angular.mock.$HttpBackendProvider = function() { + this.$get = ['$rootScope', '$timeout', createHttpBackendMock]; +}; + +/** + * General factory function for $httpBackend mock. + * Returns instance for unit testing (when no arguments specified): + * - passing through is disabled + * - auto flushing is disabled + * + * Returns instance for e2e testing (when `$delegate` and `$browser` specified): + * - passing through (delegating request to real backend) is enabled + * - auto flushing is enabled + * + * @param {Object=} $delegate Real $httpBackend instance (allow passing through if specified) + * @param {Object=} $browser Auto-flushing enabled if specified + * @return {Object} Instance of $httpBackend mock + */ +function createHttpBackendMock($rootScope, $timeout, $delegate, $browser) { + var definitions = [], + expectations = [], + responses = [], + responsesPush = angular.bind(responses, responses.push), + copy = angular.copy; + + function createResponse(status, data, headers, statusText) { + if (angular.isFunction(status)) return status; + + return function() { + return angular.isNumber(status) + ? [status, data, headers, statusText] + : [200, status, data, headers]; + }; + } + + // TODO(vojta): change params to: method, url, data, headers, callback + function $httpBackend(method, url, data, callback, headers, timeout, withCredentials) { + var xhr = new MockXhr(), + expectation = expectations[0], + wasExpected = false; + + function prettyPrint(data) { + return (angular.isString(data) || angular.isFunction(data) || data instanceof RegExp) + ? data + : angular.toJson(data); + } + + function wrapResponse(wrapped) { + if (!$browser && timeout) { + timeout.then ? timeout.then(handleTimeout) : $timeout(handleTimeout, timeout); + } + + return handleResponse; + + function handleResponse() { + var response = wrapped.response(method, url, data, headers, wrapped.params(url)); + xhr.$$respHeaders = response[2]; + callback(copy(response[0]), copy(response[1]), xhr.getAllResponseHeaders(), + copy(response[3] || '')); + } + + function handleTimeout() { + for (var i = 0, ii = responses.length; i < ii; i++) { + if (responses[i] === handleResponse) { + responses.splice(i, 1); + callback(-1, undefined, ''); + break; + } + } + } + } + + if (expectation && expectation.match(method, url)) { + if (!expectation.matchData(data)) { + throw new Error('Expected ' + expectation + ' with different data\n' + + 'EXPECTED: ' + prettyPrint(expectation.data) + '\nGOT: ' + data); + } + + if (!expectation.matchHeaders(headers)) { + throw new Error('Expected ' + expectation + ' with different headers\n' + + 'EXPECTED: ' + prettyPrint(expectation.headers) + '\nGOT: ' + + prettyPrint(headers)); + } + + expectations.shift(); + + if (expectation.response) { + responses.push(wrapResponse(expectation)); + return; + } + wasExpected = true; + } + + var i = -1, definition; + while ((definition = definitions[++i])) { + if (definition.match(method, url, data, headers || {})) { + if (definition.response) { + // if $browser specified, we do auto flush all requests + ($browser ? $browser.defer : responsesPush)(wrapResponse(definition)); + } else if (definition.passThrough) { + $delegate(method, url, data, callback, headers, timeout, withCredentials); + } else throw new Error('No response defined !'); + return; + } + } + throw wasExpected ? + new Error('No response defined !') : + new Error('Unexpected request: ' + method + ' ' + url + '\n' + + (expectation ? 'Expected ' + expectation : 'No more request expected')); + } + + /** + * @ngdoc method + * @name $httpBackend#when + * @description + * Creates a new backend definition. + * + * @param {string} method HTTP method. + * @param {string|RegExp|function(string)} url HTTP url or function that receives a url + * and returns true if the url matches the current definition. + * @param {(string|RegExp|function(string))=} data HTTP request body or function that receives + * data string and returns true if the data is as expected. + * @param {(Object|function(Object))=} headers HTTP headers or function that receives http header + * object and returns true if the headers match the current definition. + * @param {(Array)=} keys Array of keys to assign to regex matches in request url described above. + * @returns {requestHandler} Returns an object with `respond` method that controls how a matched + * request is handled. You can save this object for later use and invoke `respond` again in + * order to change how a matched request is handled. + * + * - respond – + * `{function([status,] data[, headers, statusText]) + * | function(function(method, url, data, headers, params)}` + * – The respond method takes a set of static data to be returned or a function that can + * return an array containing response status (number), response data (string), response + * headers (Object), and the text for the status (string). The respond method returns the + * `requestHandler` object for possible overrides. + */ + $httpBackend.when = function(method, url, data, headers, keys) { + var definition = new MockHttpExpectation(method, url, data, headers, keys), + chain = { + respond: function(status, data, headers, statusText) { + definition.passThrough = undefined; + definition.response = createResponse(status, data, headers, statusText); + return chain; + } + }; + + if ($browser) { + chain.passThrough = function() { + definition.response = undefined; + definition.passThrough = true; + return chain; + }; + } + + definitions.push(definition); + return chain; + }; + + /** + * @ngdoc method + * @name $httpBackend#whenGET + * @description + * Creates a new backend definition for GET requests. For more info see `when()`. + * + * @param {string|RegExp|function(string)} url HTTP url or function that receives a url + * and returns true if the url matches the current definition. + * @param {(Object|function(Object))=} headers HTTP headers. + * @param {(Array)=} keys Array of keys to assign to regex matches in request url described above. + * @returns {requestHandler} Returns an object with `respond` method that controls how a matched + * request is handled. You can save this object for later use and invoke `respond` again in + * order to change how a matched request is handled. + */ + + /** + * @ngdoc method + * @name $httpBackend#whenHEAD + * @description + * Creates a new backend definition for HEAD requests. For more info see `when()`. + * + * @param {string|RegExp|function(string)} url HTTP url or function that receives a url + * and returns true if the url matches the current definition. + * @param {(Object|function(Object))=} headers HTTP headers. + * @param {(Array)=} keys Array of keys to assign to regex matches in request url described above. + * @returns {requestHandler} Returns an object with `respond` method that controls how a matched + * request is handled. You can save this object for later use and invoke `respond` again in + * order to change how a matched request is handled. + */ + + /** + * @ngdoc method + * @name $httpBackend#whenDELETE + * @description + * Creates a new backend definition for DELETE requests. For more info see `when()`. + * + * @param {string|RegExp|function(string)} url HTTP url or function that receives a url + * and returns true if the url matches the current definition. + * @param {(Object|function(Object))=} headers HTTP headers. + * @param {(Array)=} keys Array of keys to assign to regex matches in request url described above. + * @returns {requestHandler} Returns an object with `respond` method that controls how a matched + * request is handled. You can save this object for later use and invoke `respond` again in + * order to change how a matched request is handled. + */ + + /** + * @ngdoc method + * @name $httpBackend#whenPOST + * @description + * Creates a new backend definition for POST requests. For more info see `when()`. + * + * @param {string|RegExp|function(string)} url HTTP url or function that receives a url + * and returns true if the url matches the current definition. + * @param {(string|RegExp|function(string))=} data HTTP request body or function that receives + * data string and returns true if the data is as expected. + * @param {(Object|function(Object))=} headers HTTP headers. + * @param {(Array)=} keys Array of keys to assign to regex matches in request url described above. + * @returns {requestHandler} Returns an object with `respond` method that controls how a matched + * request is handled. You can save this object for later use and invoke `respond` again in + * order to change how a matched request is handled. + */ + + /** + * @ngdoc method + * @name $httpBackend#whenPUT + * @description + * Creates a new backend definition for PUT requests. For more info see `when()`. + * + * @param {string|RegExp|function(string)} url HTTP url or function that receives a url + * and returns true if the url matches the current definition. + * @param {(string|RegExp|function(string))=} data HTTP request body or function that receives + * data string and returns true if the data is as expected. + * @param {(Object|function(Object))=} headers HTTP headers. + * @param {(Array)=} keys Array of keys to assign to regex matches in request url described above. + * @returns {requestHandler} Returns an object with `respond` method that controls how a matched + * request is handled. You can save this object for later use and invoke `respond` again in + * order to change how a matched request is handled. + */ + + /** + * @ngdoc method + * @name $httpBackend#whenJSONP + * @description + * Creates a new backend definition for JSONP requests. For more info see `when()`. + * + * @param {string|RegExp|function(string)} url HTTP url or function that receives a url + * and returns true if the url matches the current definition. + * @param {(Array)=} keys Array of keys to assign to regex matches in request url described above. + * @returns {requestHandler} Returns an object with `respond` method that controls how a matched + * request is handled. You can save this object for later use and invoke `respond` again in + * order to change how a matched request is handled. + */ + createShortMethods('when'); + + /** + * @ngdoc method + * @name $httpBackend#whenRoute + * @description + * Creates a new backend definition that compares only with the requested route. + * + * @param {string} method HTTP method. + * @param {string} url HTTP url string that supports colon param matching. + * @returns {requestHandler} Returns an object with `respond` method that controls how a matched + * request is handled. You can save this object for later use and invoke `respond` again in + * order to change how a matched request is handled. See #when for more info. + */ + $httpBackend.whenRoute = function(method, url) { + var pathObj = parseRoute(url); + return $httpBackend.when(method, pathObj.regexp, undefined, undefined, pathObj.keys); + }; + + function parseRoute(url) { + var ret = { + regexp: url + }, + keys = ret.keys = []; + + if (!url || !angular.isString(url)) return ret; + + url = url + .replace(/([().])/g, '\\$1') + .replace(/(\/)?:(\w+)([\?\*])?/g, function(_, slash, key, option) { + var optional = option === '?' ? option : null; + var star = option === '*' ? option : null; + keys.push({ name: key, optional: !!optional }); + slash = slash || ''; + return '' + + (optional ? '' : slash) + + '(?:' + + (optional ? slash : '') + + (star && '(.+?)' || '([^/]+)') + + (optional || '') + + ')' + + (optional || ''); + }) + .replace(/([\/$\*])/g, '\\$1'); + + ret.regexp = new RegExp('^' + url, 'i'); + return ret; + } + + /** + * @ngdoc method + * @name $httpBackend#expect + * @description + * Creates a new request expectation. + * + * @param {string} method HTTP method. + * @param {string|RegExp|function(string)} url HTTP url or function that receives a url + * and returns true if the url matches the current definition. + * @param {(string|RegExp|function(string)|Object)=} data HTTP request body or function that + * receives data string and returns true if the data is as expected, or Object if request body + * is in JSON format. + * @param {(Object|function(Object))=} headers HTTP headers or function that receives http header + * object and returns true if the headers match the current expectation. + * @param {(Array)=} keys Array of keys to assign to regex matches in request url described above. + * @returns {requestHandler} Returns an object with `respond` method that controls how a matched + * request is handled. You can save this object for later use and invoke `respond` again in + * order to change how a matched request is handled. + * + * - respond – + * `{function([status,] data[, headers, statusText]) + * | function(function(method, url, data, headers, params)}` + * – The respond method takes a set of static data to be returned or a function that can + * return an array containing response status (number), response data (string), response + * headers (Object), and the text for the status (string). The respond method returns the + * `requestHandler` object for possible overrides. + */ + $httpBackend.expect = function(method, url, data, headers, keys) { + var expectation = new MockHttpExpectation(method, url, data, headers, keys), + chain = { + respond: function(status, data, headers, statusText) { + expectation.response = createResponse(status, data, headers, statusText); + return chain; + } + }; + + expectations.push(expectation); + return chain; + }; + + /** + * @ngdoc method + * @name $httpBackend#expectGET + * @description + * Creates a new request expectation for GET requests. For more info see `expect()`. + * + * @param {string|RegExp|function(string)} url HTTP url or function that receives a url + * and returns true if the url matches the current definition. + * @param {Object=} headers HTTP headers. + * @param {(Array)=} keys Array of keys to assign to regex matches in request url described above. + * @returns {requestHandler} Returns an object with `respond` method that controls how a matched + * request is handled. You can save this object for later use and invoke `respond` again in + * order to change how a matched request is handled. See #expect for more info. + */ + + /** + * @ngdoc method + * @name $httpBackend#expectHEAD + * @description + * Creates a new request expectation for HEAD requests. For more info see `expect()`. + * + * @param {string|RegExp|function(string)} url HTTP url or function that receives a url + * and returns true if the url matches the current definition. + * @param {Object=} headers HTTP headers. + * @param {(Array)=} keys Array of keys to assign to regex matches in request url described above. + * @returns {requestHandler} Returns an object with `respond` method that controls how a matched + * request is handled. You can save this object for later use and invoke `respond` again in + * order to change how a matched request is handled. + */ + + /** + * @ngdoc method + * @name $httpBackend#expectDELETE + * @description + * Creates a new request expectation for DELETE requests. For more info see `expect()`. + * + * @param {string|RegExp|function(string)} url HTTP url or function that receives a url + * and returns true if the url matches the current definition. + * @param {Object=} headers HTTP headers. + * @param {(Array)=} keys Array of keys to assign to regex matches in request url described above. + * @returns {requestHandler} Returns an object with `respond` method that controls how a matched + * request is handled. You can save this object for later use and invoke `respond` again in + * order to change how a matched request is handled. + */ + + /** + * @ngdoc method + * @name $httpBackend#expectPOST + * @description + * Creates a new request expectation for POST requests. For more info see `expect()`. + * + * @param {string|RegExp|function(string)} url HTTP url or function that receives a url + * and returns true if the url matches the current definition. + * @param {(string|RegExp|function(string)|Object)=} data HTTP request body or function that + * receives data string and returns true if the data is as expected, or Object if request body + * is in JSON format. + * @param {Object=} headers HTTP headers. + * @param {(Array)=} keys Array of keys to assign to regex matches in request url described above. + * @returns {requestHandler} Returns an object with `respond` method that controls how a matched + * request is handled. You can save this object for later use and invoke `respond` again in + * order to change how a matched request is handled. + */ + + /** + * @ngdoc method + * @name $httpBackend#expectPUT + * @description + * Creates a new request expectation for PUT requests. For more info see `expect()`. + * + * @param {string|RegExp|function(string)} url HTTP url or function that receives a url + * and returns true if the url matches the current definition. + * @param {(string|RegExp|function(string)|Object)=} data HTTP request body or function that + * receives data string and returns true if the data is as expected, or Object if request body + * is in JSON format. + * @param {Object=} headers HTTP headers. + * @param {(Array)=} keys Array of keys to assign to regex matches in request url described above. + * @returns {requestHandler} Returns an object with `respond` method that controls how a matched + * request is handled. You can save this object for later use and invoke `respond` again in + * order to change how a matched request is handled. + */ + + /** + * @ngdoc method + * @name $httpBackend#expectPATCH + * @description + * Creates a new request expectation for PATCH requests. For more info see `expect()`. + * + * @param {string|RegExp|function(string)} url HTTP url or function that receives a url + * and returns true if the url matches the current definition. + * @param {(string|RegExp|function(string)|Object)=} data HTTP request body or function that + * receives data string and returns true if the data is as expected, or Object if request body + * is in JSON format. + * @param {Object=} headers HTTP headers. + * @param {(Array)=} keys Array of keys to assign to regex matches in request url described above. + * @returns {requestHandler} Returns an object with `respond` method that controls how a matched + * request is handled. You can save this object for later use and invoke `respond` again in + * order to change how a matched request is handled. + */ + + /** + * @ngdoc method + * @name $httpBackend#expectJSONP + * @description + * Creates a new request expectation for JSONP requests. For more info see `expect()`. + * + * @param {string|RegExp|function(string)} url HTTP url or function that receives an url + * and returns true if the url matches the current definition. + * @param {(Array)=} keys Array of keys to assign to regex matches in request url described above. + * @returns {requestHandler} Returns an object with `respond` method that controls how a matched + * request is handled. You can save this object for later use and invoke `respond` again in + * order to change how a matched request is handled. + */ + createShortMethods('expect'); + + /** + * @ngdoc method + * @name $httpBackend#expectRoute + * @description + * Creates a new request expectation that compares only with the requested route. + * + * @param {string} method HTTP method. + * @param {string} url HTTP url string that supports colon param matching. + * @returns {requestHandler} Returns an object with `respond` method that controls how a matched + * request is handled. You can save this object for later use and invoke `respond` again in + * order to change how a matched request is handled. See #expect for more info. + */ + $httpBackend.expectRoute = function(method, url) { + var pathObj = parseRoute(url); + return $httpBackend.expect(method, pathObj.regexp, undefined, undefined, pathObj.keys); + }; + + + /** + * @ngdoc method + * @name $httpBackend#flush + * @description + * Flushes all pending requests using the trained responses. + * + * @param {number=} count Number of responses to flush (in the order they arrived). If undefined, + * all pending requests will be flushed. If there are no pending requests when the flush method + * is called an exception is thrown (as this typically a sign of programming error). + */ + $httpBackend.flush = function(count, digest) { + if (digest !== false) $rootScope.$digest(); + if (!responses.length) throw new Error('No pending request to flush !'); + + if (angular.isDefined(count) && count !== null) { + while (count--) { + if (!responses.length) throw new Error('No more pending request to flush !'); + responses.shift()(); + } + } else { + while (responses.length) { + responses.shift()(); + } + } + $httpBackend.verifyNoOutstandingExpectation(digest); + }; + + + /** + * @ngdoc method + * @name $httpBackend#verifyNoOutstandingExpectation + * @description + * Verifies that all of the requests defined via the `expect` api were made. If any of the + * requests were not made, verifyNoOutstandingExpectation throws an exception. + * + * Typically, you would call this method following each test case that asserts requests using an + * "afterEach" clause. + * + * ```js + * afterEach($httpBackend.verifyNoOutstandingExpectation); + * ``` + */ + $httpBackend.verifyNoOutstandingExpectation = function(digest) { + if (digest !== false) $rootScope.$digest(); + if (expectations.length) { + throw new Error('Unsatisfied requests: ' + expectations.join(', ')); + } + }; + + + /** + * @ngdoc method + * @name $httpBackend#verifyNoOutstandingRequest + * @description + * Verifies that there are no outstanding requests that need to be flushed. + * + * Typically, you would call this method following each test case that asserts requests using an + * "afterEach" clause. + * + * ```js + * afterEach($httpBackend.verifyNoOutstandingRequest); + * ``` + */ + $httpBackend.verifyNoOutstandingRequest = function() { + if (responses.length) { + throw new Error('Unflushed requests: ' + responses.length); + } + }; + + + /** + * @ngdoc method + * @name $httpBackend#resetExpectations + * @description + * Resets all request expectations, but preserves all backend definitions. Typically, you would + * call resetExpectations during a multiple-phase test when you want to reuse the same instance of + * $httpBackend mock. + */ + $httpBackend.resetExpectations = function() { + expectations.length = 0; + responses.length = 0; + }; + + return $httpBackend; + + + function createShortMethods(prefix) { + angular.forEach(['GET', 'DELETE', 'JSONP', 'HEAD'], function(method) { + $httpBackend[prefix + method] = function(url, headers, keys) { + return $httpBackend[prefix](method, url, undefined, headers, keys); + }; + }); + + angular.forEach(['PUT', 'POST', 'PATCH'], function(method) { + $httpBackend[prefix + method] = function(url, data, headers, keys) { + return $httpBackend[prefix](method, url, data, headers, keys); + }; + }); + } +} + +function MockHttpExpectation(method, url, data, headers, keys) { + + this.data = data; + this.headers = headers; + + this.match = function(m, u, d, h) { + if (method != m) return false; + if (!this.matchUrl(u)) return false; + if (angular.isDefined(d) && !this.matchData(d)) return false; + if (angular.isDefined(h) && !this.matchHeaders(h)) return false; + return true; + }; + + this.matchUrl = function(u) { + if (!url) return true; + if (angular.isFunction(url.test)) return url.test(u); + if (angular.isFunction(url)) return url(u); + return url == u; + }; + + this.matchHeaders = function(h) { + if (angular.isUndefined(headers)) return true; + if (angular.isFunction(headers)) return headers(h); + return angular.equals(headers, h); + }; + + this.matchData = function(d) { + if (angular.isUndefined(data)) return true; + if (data && angular.isFunction(data.test)) return data.test(d); + if (data && angular.isFunction(data)) return data(d); + if (data && !angular.isString(data)) { + return angular.equals(angular.fromJson(angular.toJson(data)), angular.fromJson(d)); + } + return data == d; + }; + + this.toString = function() { + return method + ' ' + url; + }; + + this.params = function(u) { + return angular.extend(parseQuery(), pathParams()); + + function pathParams() { + var keyObj = {}; + if (!url || !angular.isFunction(url.test) || !keys || keys.length === 0) return keyObj; + + var m = url.exec(u); + if (!m) return keyObj; + for (var i = 1, len = m.length; i < len; ++i) { + var key = keys[i - 1]; + var val = m[i]; + if (key && val) { + keyObj[key.name || key] = val; + } + } + + return keyObj; + } + + function parseQuery() { + var obj = {}, key_value, key, + queryStr = u.indexOf('?') > -1 + ? u.substring(u.indexOf('?') + 1) + : ""; + + angular.forEach(queryStr.split('&'), function(keyValue) { + if (keyValue) { + key_value = keyValue.replace(/\+/g,'%20').split('='); + key = tryDecodeURIComponent(key_value[0]); + if (angular.isDefined(key)) { + var val = angular.isDefined(key_value[1]) ? tryDecodeURIComponent(key_value[1]) : true; + if (!hasOwnProperty.call(obj, key)) { + obj[key] = val; + } else if (angular.isArray(obj[key])) { + obj[key].push(val); + } else { + obj[key] = [obj[key],val]; + } + } + } + }); + return obj; + } + function tryDecodeURIComponent(value) { + try { + return decodeURIComponent(value); + } catch (e) { + // Ignore any invalid uri component + } + } + }; +} + +function createMockXhr() { + return new MockXhr(); +} + +function MockXhr() { + + // hack for testing $http, $httpBackend + MockXhr.$$lastInstance = this; + + this.open = function(method, url, async) { + this.$$method = method; + this.$$url = url; + this.$$async = async; + this.$$reqHeaders = {}; + this.$$respHeaders = {}; + }; + + this.send = function(data) { + this.$$data = data; + }; + + this.setRequestHeader = function(key, value) { + this.$$reqHeaders[key] = value; + }; + + this.getResponseHeader = function(name) { + // the lookup must be case insensitive, + // that's why we try two quick lookups first and full scan last + var header = this.$$respHeaders[name]; + if (header) return header; + + name = angular.lowercase(name); + header = this.$$respHeaders[name]; + if (header) return header; + + header = undefined; + angular.forEach(this.$$respHeaders, function(headerVal, headerName) { + if (!header && angular.lowercase(headerName) == name) header = headerVal; + }); + return header; + }; + + this.getAllResponseHeaders = function() { + var lines = []; + + angular.forEach(this.$$respHeaders, function(value, key) { + lines.push(key + ': ' + value); + }); + return lines.join('\n'); + }; + + this.abort = angular.noop; +} + + +/** + * @ngdoc service + * @name $timeout + * @description + * + * This service is just a simple decorator for {@link ng.$timeout $timeout} service + * that adds a "flush" and "verifyNoPendingTasks" methods. + */ + +angular.mock.$TimeoutDecorator = ['$delegate', '$browser', function($delegate, $browser) { + + /** + * @ngdoc method + * @name $timeout#flush + * @description + * + * Flushes the queue of pending tasks. + * + * @param {number=} delay maximum timeout amount to flush up until + */ + $delegate.flush = function(delay) { + $browser.defer.flush(delay); + }; + + /** + * @ngdoc method + * @name $timeout#verifyNoPendingTasks + * @description + * + * Verifies that there are no pending tasks that need to be flushed. + */ + $delegate.verifyNoPendingTasks = function() { + if ($browser.deferredFns.length) { + throw new Error('Deferred tasks to flush (' + $browser.deferredFns.length + '): ' + + formatPendingTasksAsString($browser.deferredFns)); + } + }; + + function formatPendingTasksAsString(tasks) { + var result = []; + angular.forEach(tasks, function(task) { + result.push('{id: ' + task.id + ', ' + 'time: ' + task.time + '}'); + }); + + return result.join(', '); + } + + return $delegate; +}]; + +angular.mock.$RAFDecorator = ['$delegate', function($delegate) { + var rafFn = function(fn) { + var index = rafFn.queue.length; + rafFn.queue.push(fn); + return function() { + rafFn.queue.splice(index, 1); + }; + }; + + rafFn.queue = []; + rafFn.supported = $delegate.supported; + + rafFn.flush = function() { + if (rafFn.queue.length === 0) { + throw new Error('No rAF callbacks present'); + } + + var length = rafFn.queue.length; + for (var i = 0; i < length; i++) { + rafFn.queue[i](); + } + + rafFn.queue = rafFn.queue.slice(i); + }; + + return rafFn; +}]; + +/** + * + */ +angular.mock.$RootElementProvider = function() { + this.$get = function() { + return angular.element('
    '); + }; +}; + +/** + * @ngdoc service + * @name $controller + * @description + * A decorator for {@link ng.$controller} with additional `bindings` parameter, useful when testing + * controllers of directives that use {@link $compile#-bindtocontroller- `bindToController`}. + * + * + * ## Example + * + * ```js + * + * // Directive definition ... + * + * myMod.directive('myDirective', { + * controller: 'MyDirectiveController', + * bindToController: { + * name: '@' + * } + * }); + * + * + * // Controller definition ... + * + * myMod.controller('MyDirectiveController', ['$log', function($log) { + * $log.info(this.name); + * })]; + * + * + * // In a test ... + * + * describe('myDirectiveController', function() { + * it('should write the bound name to the log', inject(function($controller, $log) { + * var ctrl = $controller('MyDirectiveController', { /* no locals */ }, { name: 'Clark Kent' }); + * expect(ctrl.name).toEqual('Clark Kent'); + * expect($log.info.logs).toEqual(['Clark Kent']); + * }); + * }); + * + * ``` + * + * @param {Function|string} constructor If called with a function then it's considered to be the + * controller constructor function. Otherwise it's considered to be a string which is used + * to retrieve the controller constructor using the following steps: + * + * * check if a controller with given name is registered via `$controllerProvider` + * * check if evaluating the string on the current scope returns a constructor + * * if $controllerProvider#allowGlobals, check `window[constructor]` on the global + * `window` object (not recommended) + * + * The string can use the `controller as property` syntax, where the controller instance is published + * as the specified property on the `scope`; the `scope` must be injected into `locals` param for this + * to work correctly. + * + * @param {Object} locals Injection locals for Controller. + * @param {Object=} bindings Properties to add to the controller before invoking the constructor. This is used + * to simulate the `bindToController` feature and simplify certain kinds of tests. + * @return {Object} Instance of given controller. + */ +angular.mock.$ControllerDecorator = ['$delegate', function($delegate) { + return function(expression, locals, later, ident) { + if (later && typeof later === 'object') { + var create = $delegate(expression, locals, true, ident); + angular.extend(create.instance, later); + return create(); + } + return $delegate(expression, locals, later, ident); + }; +}]; + +/** + * @ngdoc service + * @name $componentController + * @description + * A service that can be used to create instances of component controllers. + *
    + * Be aware that the controller will be instantiated and attached to the scope as specified in + * the component definition object. That means that you must always provide a `$scope` object + * in the `locals` param. + *
    + * @param {string} componentName the name of the component whose controller we want to instantiate + * @param {Object} locals Injection locals for Controller. + * @param {Object=} bindings Properties to add to the controller before invoking the constructor. This is used + * to simulate the `bindToController` feature and simplify certain kinds of tests. + * @param {string=} ident Override the property name to use when attaching the controller to the scope. + * @return {Object} Instance of requested controller. + */ +angular.mock.$ComponentControllerProvider = ['$compileProvider', function($compileProvider) { + return { + $get: ['$controller','$injector', function($controller,$injector) { + return function $componentController(componentName, locals, bindings, ident) { + // get all directives associated to the component name + var directives = $injector.get(componentName + 'Directive'); + // look for those directives that are components + var candidateDirectives = directives.filter(function(directiveInfo) { + // components have controller, controllerAs and restrict:'E' + return directiveInfo.controller && directiveInfo.controllerAs && directiveInfo.restrict === 'E'; + }); + // check if valid directives found + if (candidateDirectives.length === 0) { + throw new Error('No component found'); + } + if (candidateDirectives.length > 1) { + throw new Error('Too many components found'); + } + // get the info of the component + var directiveInfo = candidateDirectives[0]; + return $controller(directiveInfo.controller, locals, bindings, ident || directiveInfo.controllerAs); + }; + }] + }; +}]; + + +/** + * @ngdoc module + * @name ngMock + * @packageName angular-mocks + * @description + * + * # ngMock + * + * The `ngMock` module provides support to inject and mock Angular services into unit tests. + * In addition, ngMock also extends various core ng services such that they can be + * inspected and controlled in a synchronous manner within test code. + * + * + *
    + * + */ +angular.module('ngMock', ['ng']).provider({ + $browser: angular.mock.$BrowserProvider, + $exceptionHandler: angular.mock.$ExceptionHandlerProvider, + $log: angular.mock.$LogProvider, + $interval: angular.mock.$IntervalProvider, + $httpBackend: angular.mock.$HttpBackendProvider, + $rootElement: angular.mock.$RootElementProvider, + $componentController: angular.mock.$ComponentControllerProvider +}).config(['$provide', function($provide) { + $provide.decorator('$timeout', angular.mock.$TimeoutDecorator); + $provide.decorator('$$rAF', angular.mock.$RAFDecorator); + $provide.decorator('$rootScope', angular.mock.$RootScopeDecorator); + $provide.decorator('$controller', angular.mock.$ControllerDecorator); +}]); + +/** + * @ngdoc module + * @name ngMockE2E + * @module ngMockE2E + * @packageName angular-mocks + * @description + * + * The `ngMockE2E` is an angular module which contains mocks suitable for end-to-end testing. + * Currently there is only one mock present in this module - + * the {@link ngMockE2E.$httpBackend e2e $httpBackend} mock. + */ +angular.module('ngMockE2E', ['ng']).config(['$provide', function($provide) { + $provide.decorator('$httpBackend', angular.mock.e2e.$httpBackendDecorator); +}]); + +/** + * @ngdoc service + * @name $httpBackend + * @module ngMockE2E + * @description + * Fake HTTP backend implementation suitable for end-to-end testing or backend-less development of + * applications that use the {@link ng.$http $http service}. + * + * *Note*: For fake http backend implementation suitable for unit testing please see + * {@link ngMock.$httpBackend unit-testing $httpBackend mock}. + * + * This implementation can be used to respond with static or dynamic responses via the `when` api + * and its shortcuts (`whenGET`, `whenPOST`, etc) and optionally pass through requests to the + * real $httpBackend for specific requests (e.g. to interact with certain remote apis or to fetch + * templates from a webserver). + * + * As opposed to unit-testing, in an end-to-end testing scenario or in scenario when an application + * is being developed with the real backend api replaced with a mock, it is often desirable for + * certain category of requests to bypass the mock and issue a real http request (e.g. to fetch + * templates or static files from the webserver). To configure the backend with this behavior + * use the `passThrough` request handler of `when` instead of `respond`. + * + * Additionally, we don't want to manually have to flush mocked out requests like we do during unit + * testing. For this reason the e2e $httpBackend flushes mocked out requests + * automatically, closely simulating the behavior of the XMLHttpRequest object. + * + * To setup the application to run with this http backend, you have to create a module that depends + * on the `ngMockE2E` and your application modules and defines the fake backend: + * + * ```js + * myAppDev = angular.module('myAppDev', ['myApp', 'ngMockE2E']); + * myAppDev.run(function($httpBackend) { + * phones = [{name: 'phone1'}, {name: 'phone2'}]; + * + * // returns the current list of phones + * $httpBackend.whenGET('/phones').respond(phones); + * + * // adds a new phone to the phones array + * $httpBackend.whenPOST('/phones').respond(function(method, url, data) { + * var phone = angular.fromJson(data); + * phones.push(phone); + * return [200, phone, {}]; + * }); + * $httpBackend.whenGET(/^\/templates\//).passThrough(); + * //... + * }); + * ``` + * + * Afterwards, bootstrap your app with this new module. + */ + +/** + * @ngdoc method + * @name $httpBackend#when + * @module ngMockE2E + * @description + * Creates a new backend definition. + * + * @param {string} method HTTP method. + * @param {string|RegExp|function(string)} url HTTP url or function that receives a url + * and returns true if the url matches the current definition. + * @param {(string|RegExp)=} data HTTP request body. + * @param {(Object|function(Object))=} headers HTTP headers or function that receives http header + * object and returns true if the headers match the current definition. + * @param {(Array)=} keys Array of keys to assign to regex matches in request url described on + * {@link ngMock.$httpBackend $httpBackend mock}. + * @returns {requestHandler} Returns an object with `respond` and `passThrough` methods that + * control how a matched request is handled. You can save this object for later use and invoke + * `respond` or `passThrough` again in order to change how a matched request is handled. + * + * - respond – + * `{function([status,] data[, headers, statusText]) + * | function(function(method, url, data, headers, params)}` + * – The respond method takes a set of static data to be returned or a function that can return + * an array containing response status (number), response data (string), response headers + * (Object), and the text for the status (string). + * - passThrough – `{function()}` – Any request matching a backend definition with + * `passThrough` handler will be passed through to the real backend (an XHR request will be made + * to the server.) + * - Both methods return the `requestHandler` object for possible overrides. + */ + +/** + * @ngdoc method + * @name $httpBackend#whenGET + * @module ngMockE2E + * @description + * Creates a new backend definition for GET requests. For more info see `when()`. + * + * @param {string|RegExp|function(string)} url HTTP url or function that receives a url + * and returns true if the url matches the current definition. + * @param {(Object|function(Object))=} headers HTTP headers. + * @param {(Array)=} keys Array of keys to assign to regex matches in request url described on + * {@link ngMock.$httpBackend $httpBackend mock}. + * @returns {requestHandler} Returns an object with `respond` and `passThrough` methods that + * control how a matched request is handled. You can save this object for later use and invoke + * `respond` or `passThrough` again in order to change how a matched request is handled. + */ + +/** + * @ngdoc method + * @name $httpBackend#whenHEAD + * @module ngMockE2E + * @description + * Creates a new backend definition for HEAD requests. For more info see `when()`. + * + * @param {string|RegExp|function(string)} url HTTP url or function that receives a url + * and returns true if the url matches the current definition. + * @param {(Object|function(Object))=} headers HTTP headers. + * @param {(Array)=} keys Array of keys to assign to regex matches in request url described on + * {@link ngMock.$httpBackend $httpBackend mock}. + * @returns {requestHandler} Returns an object with `respond` and `passThrough` methods that + * control how a matched request is handled. You can save this object for later use and invoke + * `respond` or `passThrough` again in order to change how a matched request is handled. + */ + +/** + * @ngdoc method + * @name $httpBackend#whenDELETE + * @module ngMockE2E + * @description + * Creates a new backend definition for DELETE requests. For more info see `when()`. + * + * @param {string|RegExp|function(string)} url HTTP url or function that receives a url + * and returns true if the url matches the current definition. + * @param {(Object|function(Object))=} headers HTTP headers. + * @param {(Array)=} keys Array of keys to assign to regex matches in request url described on + * {@link ngMock.$httpBackend $httpBackend mock}. + * @returns {requestHandler} Returns an object with `respond` and `passThrough` methods that + * control how a matched request is handled. You can save this object for later use and invoke + * `respond` or `passThrough` again in order to change how a matched request is handled. + */ + +/** + * @ngdoc method + * @name $httpBackend#whenPOST + * @module ngMockE2E + * @description + * Creates a new backend definition for POST requests. For more info see `when()`. + * + * @param {string|RegExp|function(string)} url HTTP url or function that receives a url + * and returns true if the url matches the current definition. + * @param {(string|RegExp)=} data HTTP request body. + * @param {(Object|function(Object))=} headers HTTP headers. + * @param {(Array)=} keys Array of keys to assign to regex matches in request url described on + * {@link ngMock.$httpBackend $httpBackend mock}. + * @returns {requestHandler} Returns an object with `respond` and `passThrough` methods that + * control how a matched request is handled. You can save this object for later use and invoke + * `respond` or `passThrough` again in order to change how a matched request is handled. + */ + +/** + * @ngdoc method + * @name $httpBackend#whenPUT + * @module ngMockE2E + * @description + * Creates a new backend definition for PUT requests. For more info see `when()`. + * + * @param {string|RegExp|function(string)} url HTTP url or function that receives a url + * and returns true if the url matches the current definition. + * @param {(string|RegExp)=} data HTTP request body. + * @param {(Object|function(Object))=} headers HTTP headers. + * @param {(Array)=} keys Array of keys to assign to regex matches in request url described on + * {@link ngMock.$httpBackend $httpBackend mock}. + * @returns {requestHandler} Returns an object with `respond` and `passThrough` methods that + * control how a matched request is handled. You can save this object for later use and invoke + * `respond` or `passThrough` again in order to change how a matched request is handled. + */ + +/** + * @ngdoc method + * @name $httpBackend#whenPATCH + * @module ngMockE2E + * @description + * Creates a new backend definition for PATCH requests. For more info see `when()`. + * + * @param {string|RegExp|function(string)} url HTTP url or function that receives a url + * and returns true if the url matches the current definition. + * @param {(string|RegExp)=} data HTTP request body. + * @param {(Object|function(Object))=} headers HTTP headers. + * @param {(Array)=} keys Array of keys to assign to regex matches in request url described on + * {@link ngMock.$httpBackend $httpBackend mock}. + * @returns {requestHandler} Returns an object with `respond` and `passThrough` methods that + * control how a matched request is handled. You can save this object for later use and invoke + * `respond` or `passThrough` again in order to change how a matched request is handled. + */ + +/** + * @ngdoc method + * @name $httpBackend#whenJSONP + * @module ngMockE2E + * @description + * Creates a new backend definition for JSONP requests. For more info see `when()`. + * + * @param {string|RegExp|function(string)} url HTTP url or function that receives a url + * and returns true if the url matches the current definition. + * @param {(Array)=} keys Array of keys to assign to regex matches in request url described on + * {@link ngMock.$httpBackend $httpBackend mock}. + * @returns {requestHandler} Returns an object with `respond` and `passThrough` methods that + * control how a matched request is handled. You can save this object for later use and invoke + * `respond` or `passThrough` again in order to change how a matched request is handled. + */ +/** + * @ngdoc method + * @name $httpBackend#whenRoute + * @module ngMockE2E + * @description + * Creates a new backend definition that compares only with the requested route. + * + * @param {string} method HTTP method. + * @param {string} url HTTP url string that supports colon param matching. + * @returns {requestHandler} Returns an object with `respond` and `passThrough` methods that + * control how a matched request is handled. You can save this object for later use and invoke + * `respond` or `passThrough` again in order to change how a matched request is handled. + */ +angular.mock.e2e = {}; +angular.mock.e2e.$httpBackendDecorator = + ['$rootScope', '$timeout', '$delegate', '$browser', createHttpBackendMock]; + + +/** + * @ngdoc type + * @name $rootScope.Scope + * @module ngMock + * @description + * {@link ng.$rootScope.Scope Scope} type decorated with helper methods useful for testing. These + * methods are automatically available on any {@link ng.$rootScope.Scope Scope} instance when + * `ngMock` module is loaded. + * + * In addition to all the regular `Scope` methods, the following helper methods are available: + */ +angular.mock.$RootScopeDecorator = ['$delegate', function($delegate) { + + var $rootScopePrototype = Object.getPrototypeOf($delegate); + + $rootScopePrototype.$countChildScopes = countChildScopes; + $rootScopePrototype.$countWatchers = countWatchers; + + return $delegate; + + // ------------------------------------------------------------------------------------------ // + + /** + * @ngdoc method + * @name $rootScope.Scope#$countChildScopes + * @module ngMock + * @description + * Counts all the direct and indirect child scopes of the current scope. + * + * The current scope is excluded from the count. The count includes all isolate child scopes. + * + * @returns {number} Total number of child scopes. + */ + function countChildScopes() { + // jshint validthis: true + var count = 0; // exclude the current scope + var pendingChildHeads = [this.$$childHead]; + var currentScope; + + while (pendingChildHeads.length) { + currentScope = pendingChildHeads.shift(); + + while (currentScope) { + count += 1; + pendingChildHeads.push(currentScope.$$childHead); + currentScope = currentScope.$$nextSibling; + } + } + + return count; + } + + + /** + * @ngdoc method + * @name $rootScope.Scope#$countWatchers + * @module ngMock + * @description + * Counts all the watchers of direct and indirect child scopes of the current scope. + * + * The watchers of the current scope are included in the count and so are all the watchers of + * isolate child scopes. + * + * @returns {number} Total number of watchers. + */ + function countWatchers() { + // jshint validthis: true + var count = this.$$watchers ? this.$$watchers.length : 0; // include the current scope + var pendingChildHeads = [this.$$childHead]; + var currentScope; + + while (pendingChildHeads.length) { + currentScope = pendingChildHeads.shift(); + + while (currentScope) { + count += currentScope.$$watchers ? currentScope.$$watchers.length : 0; + pendingChildHeads.push(currentScope.$$childHead); + currentScope = currentScope.$$nextSibling; + } + } + + return count; + } +}]; + + +if (window.jasmine || window.mocha) { + + var currentSpec = null, + annotatedFunctions = [], + isSpecRunning = function() { + return !!currentSpec; + }; + + angular.mock.$$annotate = angular.injector.$$annotate; + angular.injector.$$annotate = function(fn) { + if (typeof fn === 'function' && !fn.$inject) { + annotatedFunctions.push(fn); + } + return angular.mock.$$annotate.apply(this, arguments); + }; + + + (window.beforeEach || window.setup)(function() { + annotatedFunctions = []; + currentSpec = this; + }); + + (window.afterEach || window.teardown)(function() { + var injector = currentSpec.$injector; + + annotatedFunctions.forEach(function(fn) { + delete fn.$inject; + }); + + angular.forEach(currentSpec.$modules, function(module) { + if (module && module.$$hashKey) { + module.$$hashKey = undefined; + } + }); + + currentSpec.$injector = null; + currentSpec.$modules = null; + currentSpec.$providerInjector = null; + currentSpec = null; + + if (injector) { + injector.get('$rootElement').off(); + injector.get('$rootScope').$destroy(); + } + + // clean up jquery's fragment cache + angular.forEach(angular.element.fragments, function(val, key) { + delete angular.element.fragments[key]; + }); + + MockXhr.$$lastInstance = null; + + angular.forEach(angular.callbacks, function(val, key) { + delete angular.callbacks[key]; + }); + angular.callbacks.counter = 0; + }); + + /** + * @ngdoc function + * @name angular.mock.module + * @description + * + * *NOTE*: This function is also published on window for easy access.
    + * *NOTE*: This function is declared ONLY WHEN running tests with jasmine or mocha + * + * This function registers a module configuration code. It collects the configuration information + * which will be used when the injector is created by {@link angular.mock.inject inject}. + * + * See {@link angular.mock.inject inject} for usage example + * + * @param {...(string|Function|Object)} fns any number of modules which are represented as string + * aliases or as anonymous module initialization functions. The modules are used to + * configure the injector. The 'ng' and 'ngMock' modules are automatically loaded. If an + * object literal is passed each key-value pair will be registered on the module via + * {@link auto.$provide $provide}.value, the key being the string name (or token) to associate + * with the value on the injector. + */ + window.module = angular.mock.module = function() { + var moduleFns = Array.prototype.slice.call(arguments, 0); + return isSpecRunning() ? workFn() : workFn; + ///////////////////// + function workFn() { + if (currentSpec.$injector) { + throw new Error('Injector already created, can not register a module!'); + } else { + var fn, modules = currentSpec.$modules || (currentSpec.$modules = []); + angular.forEach(moduleFns, function(module) { + if (angular.isObject(module) && !angular.isArray(module)) { + fn = function($provide) { + angular.forEach(module, function(value, key) { + $provide.value(key, value); + }); + }; + } else { + fn = module; + } + if (currentSpec.$providerInjector) { + currentSpec.$providerInjector.invoke(fn); + } else { + modules.push(fn); + } + }); + } + } + }; + + /** + * @ngdoc function + * @name angular.mock.inject + * @description + * + * *NOTE*: This function is also published on window for easy access.
    + * *NOTE*: This function is declared ONLY WHEN running tests with jasmine or mocha + * + * The inject function wraps a function into an injectable function. The inject() creates new + * instance of {@link auto.$injector $injector} per test, which is then used for + * resolving references. + * + * + * ## Resolving References (Underscore Wrapping) + * Often, we would like to inject a reference once, in a `beforeEach()` block and reuse this + * in multiple `it()` clauses. To be able to do this we must assign the reference to a variable + * that is declared in the scope of the `describe()` block. Since we would, most likely, want + * the variable to have the same name of the reference we have a problem, since the parameter + * to the `inject()` function would hide the outer variable. + * + * To help with this, the injected parameters can, optionally, be enclosed with underscores. + * These are ignored by the injector when the reference name is resolved. + * + * For example, the parameter `_myService_` would be resolved as the reference `myService`. + * Since it is available in the function body as _myService_, we can then assign it to a variable + * defined in an outer scope. + * + * ``` + * // Defined out reference variable outside + * var myService; + * + * // Wrap the parameter in underscores + * beforeEach( inject( function(_myService_){ + * myService = _myService_; + * })); + * + * // Use myService in a series of tests. + * it('makes use of myService', function() { + * myService.doStuff(); + * }); + * + * ``` + * + * See also {@link angular.mock.module angular.mock.module} + * + * ## Example + * Example of what a typical jasmine tests looks like with the inject method. + * ```js + * + * angular.module('myApplicationModule', []) + * .value('mode', 'app') + * .value('version', 'v1.0.1'); + * + * + * describe('MyApp', function() { + * + * // You need to load modules that you want to test, + * // it loads only the "ng" module by default. + * beforeEach(module('myApplicationModule')); + * + * + * // inject() is used to inject arguments of all given functions + * it('should provide a version', inject(function(mode, version) { + * expect(version).toEqual('v1.0.1'); + * expect(mode).toEqual('app'); + * })); + * + * + * // The inject and module method can also be used inside of the it or beforeEach + * it('should override a version and test the new version is injected', function() { + * // module() takes functions or strings (module aliases) + * module(function($provide) { + * $provide.value('version', 'overridden'); // override version here + * }); + * + * inject(function(version) { + * expect(version).toEqual('overridden'); + * }); + * }); + * }); + * + * ``` + * + * @param {...Function} fns any number of functions which will be injected using the injector. + */ + + + + var ErrorAddingDeclarationLocationStack = function(e, errorForStack) { + this.message = e.message; + this.name = e.name; + if (e.line) this.line = e.line; + if (e.sourceId) this.sourceId = e.sourceId; + if (e.stack && errorForStack) + this.stack = e.stack + '\n' + errorForStack.stack; + if (e.stackArray) this.stackArray = e.stackArray; + }; + ErrorAddingDeclarationLocationStack.prototype.toString = Error.prototype.toString; + + window.inject = angular.mock.inject = function() { + var blockFns = Array.prototype.slice.call(arguments, 0); + var errorForStack = new Error('Declaration Location'); + return isSpecRunning() ? workFn.call(currentSpec) : workFn; + ///////////////////// + function workFn() { + var modules = currentSpec.$modules || []; + var strictDi = !!currentSpec.$injectorStrict; + modules.unshift(function($injector) { + currentSpec.$providerInjector = $injector; + }); + modules.unshift('ngMock'); + modules.unshift('ng'); + var injector = currentSpec.$injector; + if (!injector) { + if (strictDi) { + // If strictDi is enabled, annotate the providerInjector blocks + angular.forEach(modules, function(moduleFn) { + if (typeof moduleFn === "function") { + angular.injector.$$annotate(moduleFn); + } + }); + } + injector = currentSpec.$injector = angular.injector(modules, strictDi); + currentSpec.$injectorStrict = strictDi; + } + for (var i = 0, ii = blockFns.length; i < ii; i++) { + if (currentSpec.$injectorStrict) { + // If the injector is strict / strictDi, and the spec wants to inject using automatic + // annotation, then annotate the function here. + injector.annotate(blockFns[i]); + } + try { + /* jshint -W040 *//* Jasmine explicitly provides a `this` object when calling functions */ + injector.invoke(blockFns[i] || angular.noop, this); + /* jshint +W040 */ + } catch (e) { + if (e.stack && errorForStack) { + throw new ErrorAddingDeclarationLocationStack(e, errorForStack); + } + throw e; + } finally { + errorForStack = null; + } + } + } + }; + + + angular.mock.inject.strictDi = function(value) { + value = arguments.length ? !!value : true; + return isSpecRunning() ? workFn() : workFn; + + function workFn() { + if (value !== currentSpec.$injectorStrict) { + if (currentSpec.$injector) { + throw new Error('Injector already created, can not modify strict annotations'); + } else { + currentSpec.$injectorStrict = value; + } + } + } + }; +} + + +})(window, window.angular); diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-resource.js b/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-resource.js new file mode 100644 index 000000000..444be83c4 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-resource.js @@ -0,0 +1,768 @@ +/** + * @license AngularJS v1.5.0 + * (c) 2010-2016 Google, Inc. http://angularjs.org + * License: MIT + */ +(function(window, angular, undefined) {'use strict'; + +var $resourceMinErr = angular.$$minErr('$resource'); + +// Helper functions and regex to lookup a dotted path on an object +// stopping at undefined/null. The path must be composed of ASCII +// identifiers (just like $parse) +var MEMBER_NAME_REGEX = /^(\.[a-zA-Z_$@][0-9a-zA-Z_$@]*)+$/; + +function isValidDottedPath(path) { + return (path != null && path !== '' && path !== 'hasOwnProperty' && + MEMBER_NAME_REGEX.test('.' + path)); +} + +function lookupDottedPath(obj, path) { + if (!isValidDottedPath(path)) { + throw $resourceMinErr('badmember', 'Dotted member path "@{0}" is invalid.', path); + } + var keys = path.split('.'); + for (var i = 0, ii = keys.length; i < ii && angular.isDefined(obj); i++) { + var key = keys[i]; + obj = (obj !== null) ? obj[key] : undefined; + } + return obj; +} + +/** + * Create a shallow copy of an object and clear other fields from the destination + */ +function shallowClearAndCopy(src, dst) { + dst = dst || {}; + + angular.forEach(dst, function(value, key) { + delete dst[key]; + }); + + for (var key in src) { + if (src.hasOwnProperty(key) && !(key.charAt(0) === '$' && key.charAt(1) === '$')) { + dst[key] = src[key]; + } + } + + return dst; +} + +/** + * @ngdoc module + * @name ngResource + * @description + * + * # ngResource + * + * The `ngResource` module provides interaction support with RESTful services + * via the $resource service. + * + * + *
    + * + * See {@link ngResource.$resource `$resource`} for usage. + */ + +/** + * @ngdoc service + * @name $resource + * @requires $http + * @requires ng.$log + * @requires $q + * @requires ng.$timeout + * + * @description + * A factory which creates a resource object that lets you interact with + * [RESTful](http://en.wikipedia.org/wiki/Representational_State_Transfer) server-side data sources. + * + * The returned resource object has action methods which provide high-level behaviors without + * the need to interact with the low level {@link ng.$http $http} service. + * + * Requires the {@link ngResource `ngResource`} module to be installed. + * + * By default, trailing slashes will be stripped from the calculated URLs, + * which can pose problems with server backends that do not expect that + * behavior. This can be disabled by configuring the `$resourceProvider` like + * this: + * + * ```js + app.config(['$resourceProvider', function($resourceProvider) { + // Don't strip trailing slashes from calculated URLs + $resourceProvider.defaults.stripTrailingSlashes = false; + }]); + * ``` + * + * @param {string} url A parameterized URL template with parameters prefixed by `:` as in + * `/user/:username`. If you are using a URL with a port number (e.g. + * `http://example.com:8080/api`), it will be respected. + * + * If you are using a url with a suffix, just add the suffix, like this: + * `$resource('http://example.com/resource.json')` or `$resource('http://example.com/:id.json')` + * or even `$resource('http://example.com/resource/:resource_id.:format')` + * If the parameter before the suffix is empty, :resource_id in this case, then the `/.` will be + * collapsed down to a single `.`. If you need this sequence to appear and not collapse then you + * can escape it with `/\.`. + * + * @param {Object=} paramDefaults Default values for `url` parameters. These can be overridden in + * `actions` methods. If a parameter value is a function, it will be executed every time + * when a param value needs to be obtained for a request (unless the param was overridden). + * + * Each key value in the parameter object is first bound to url template if present and then any + * excess keys are appended to the url search query after the `?`. + * + * Given a template `/path/:verb` and parameter `{verb:'greet', salutation:'Hello'}` results in + * URL `/path/greet?salutation=Hello`. + * + * If the parameter value is prefixed with `@` then the value for that parameter will be extracted + * from the corresponding property on the `data` object (provided when calling an action method). + * For example, if the `defaultParam` object is `{someParam: '@someProp'}` then the value of + * `someParam` will be `data.someProp`. + * + * @param {Object.=} actions Hash with declaration of custom actions that should extend + * the default set of resource actions. The declaration should be created in the format of {@link + * ng.$http#usage $http.config}: + * + * {action1: {method:?, params:?, isArray:?, headers:?, ...}, + * action2: {method:?, params:?, isArray:?, headers:?, ...}, + * ...} + * + * Where: + * + * - **`action`** – {string} – The name of action. This name becomes the name of the method on + * your resource object. + * - **`method`** – {string} – Case insensitive HTTP method (e.g. `GET`, `POST`, `PUT`, + * `DELETE`, `JSONP`, etc). + * - **`params`** – {Object=} – Optional set of pre-bound parameters for this action. If any of + * the parameter value is a function, it will be executed every time when a param value needs to + * be obtained for a request (unless the param was overridden). + * - **`url`** – {string} – action specific `url` override. The url templating is supported just + * like for the resource-level urls. + * - **`isArray`** – {boolean=} – If true then the returned object for this action is an array, + * see `returns` section. + * - **`transformRequest`** – + * `{function(data, headersGetter)|Array.}` – + * transform function or an array of such functions. The transform function takes the http + * request body and headers and returns its transformed (typically serialized) version. + * By default, transformRequest will contain one function that checks if the request data is + * an object and serializes to using `angular.toJson`. To prevent this behavior, set + * `transformRequest` to an empty array: `transformRequest: []` + * - **`transformResponse`** – + * `{function(data, headersGetter)|Array.}` – + * transform function or an array of such functions. The transform function takes the http + * response body and headers and returns its transformed (typically deserialized) version. + * By default, transformResponse will contain one function that checks if the response looks + * like a JSON string and deserializes it using `angular.fromJson`. To prevent this behavior, + * set `transformResponse` to an empty array: `transformResponse: []` + * - **`cache`** – `{boolean|Cache}` – If true, a default $http cache will be used to cache the + * GET request, otherwise if a cache instance built with + * {@link ng.$cacheFactory $cacheFactory}, this cache will be used for + * caching. + * - **`timeout`** – `{number}` – timeout in milliseconds.
    + * **Note:** In contrast to {@link ng.$http#usage $http.config}, {@link ng.$q promises} are + * **not** supported in $resource, because the same value would be used for multiple requests. + * If you are looking for a way to cancel requests, you should use the `cancellable` option. + * - **`cancellable`** – `{boolean}` – if set to true, the request made by a "non-instance" call + * will be cancelled (if not already completed) by calling `$cancelRequest()` on the call's + * return value. Calling `$cancelRequest()` for a non-cancellable or an already + * completed/cancelled request will have no effect.
    + * - **`withCredentials`** - `{boolean}` - whether to set the `withCredentials` flag on the + * XHR object. See + * [requests with credentials](https://developer.mozilla.org/en/http_access_control#section_5) + * for more information. + * - **`responseType`** - `{string}` - see + * [requestType](https://developer.mozilla.org/en-US/docs/DOM/XMLHttpRequest#responseType). + * - **`interceptor`** - `{Object=}` - The interceptor object has two optional methods - + * `response` and `responseError`. Both `response` and `responseError` interceptors get called + * with `http response` object. See {@link ng.$http $http interceptors}. + * + * @param {Object} options Hash with custom settings that should extend the + * default `$resourceProvider` behavior. The supported options are: + * + * - **`stripTrailingSlashes`** – {boolean} – If true then the trailing + * slashes from any calculated URL will be stripped. (Defaults to true.) + * - **`cancellable`** – {boolean} – If true, the request made by a "non-instance" call will be + * cancelled (if not already completed) by calling `$cancelRequest()` on the call's return value. + * This can be overwritten per action. (Defaults to false.) + * + * @returns {Object} A resource "class" object with methods for the default set of resource actions + * optionally extended with custom `actions`. The default set contains these actions: + * ```js + * { 'get': {method:'GET'}, + * 'save': {method:'POST'}, + * 'query': {method:'GET', isArray:true}, + * 'remove': {method:'DELETE'}, + * 'delete': {method:'DELETE'} }; + * ``` + * + * Calling these methods invoke an {@link ng.$http} with the specified http method, + * destination and parameters. When the data is returned from the server then the object is an + * instance of the resource class. The actions `save`, `remove` and `delete` are available on it + * as methods with the `$` prefix. This allows you to easily perform CRUD operations (create, + * read, update, delete) on server-side data like this: + * ```js + * var User = $resource('/user/:userId', {userId:'@id'}); + * var user = User.get({userId:123}, function() { + * user.abc = true; + * user.$save(); + * }); + * ``` + * + * It is important to realize that invoking a $resource object method immediately returns an + * empty reference (object or array depending on `isArray`). Once the data is returned from the + * server the existing reference is populated with the actual data. This is a useful trick since + * usually the resource is assigned to a model which is then rendered by the view. Having an empty + * object results in no rendering, once the data arrives from the server then the object is + * populated with the data and the view automatically re-renders itself showing the new data. This + * means that in most cases one never has to write a callback function for the action methods. + * + * The action methods on the class object or instance object can be invoked with the following + * parameters: + * + * - HTTP GET "class" actions: `Resource.action([parameters], [success], [error])` + * - non-GET "class" actions: `Resource.action([parameters], postData, [success], [error])` + * - non-GET instance actions: `instance.$action([parameters], [success], [error])` + * + * + * Success callback is called with (value, responseHeaders) arguments, where the value is + * the populated resource instance or collection object. The error callback is called + * with (httpResponse) argument. + * + * Class actions return empty instance (with additional properties below). + * Instance actions return promise of the action. + * + * The Resource instances and collections have these additional properties: + * + * - `$promise`: the {@link ng.$q promise} of the original server interaction that created this + * instance or collection. + * + * On success, the promise is resolved with the same resource instance or collection object, + * updated with data from server. This makes it easy to use in + * {@link ngRoute.$routeProvider resolve section of $routeProvider.when()} to defer view + * rendering until the resource(s) are loaded. + * + * On failure, the promise is rejected with the {@link ng.$http http response} object, without + * the `resource` property. + * + * If an interceptor object was provided, the promise will instead be resolved with the value + * returned by the interceptor. + * + * - `$resolved`: `true` after first server interaction is completed (either with success or + * rejection), `false` before that. Knowing if the Resource has been resolved is useful in + * data-binding. + * + * The Resource instances and collections have these additional methods: + * + * - `$cancelRequest`: If there is a cancellable, pending request related to the instance or + * collection, calling this method will abort the request. + * + * @example + * + * # Credit card resource + * + * ```js + // Define CreditCard class + var CreditCard = $resource('/user/:userId/card/:cardId', + {userId:123, cardId:'@id'}, { + charge: {method:'POST', params:{charge:true}} + }); + + // We can retrieve a collection from the server + var cards = CreditCard.query(function() { + // GET: /user/123/card + // server returns: [ {id:456, number:'1234', name:'Smith'} ]; + + var card = cards[0]; + // each item is an instance of CreditCard + expect(card instanceof CreditCard).toEqual(true); + card.name = "J. Smith"; + // non GET methods are mapped onto the instances + card.$save(); + // POST: /user/123/card/456 {id:456, number:'1234', name:'J. Smith'} + // server returns: {id:456, number:'1234', name: 'J. Smith'}; + + // our custom method is mapped as well. + card.$charge({amount:9.99}); + // POST: /user/123/card/456?amount=9.99&charge=true {id:456, number:'1234', name:'J. Smith'} + }); + + // we can create an instance as well + var newCard = new CreditCard({number:'0123'}); + newCard.name = "Mike Smith"; + newCard.$save(); + // POST: /user/123/card {number:'0123', name:'Mike Smith'} + // server returns: {id:789, number:'0123', name: 'Mike Smith'}; + expect(newCard.id).toEqual(789); + * ``` + * + * The object returned from this function execution is a resource "class" which has "static" method + * for each action in the definition. + * + * Calling these methods invoke `$http` on the `url` template with the given `method`, `params` and + * `headers`. + * + * @example + * + * # User resource + * + * When the data is returned from the server then the object is an instance of the resource type and + * all of the non-GET methods are available with `$` prefix. This allows you to easily support CRUD + * operations (create, read, update, delete) on server-side data. + + ```js + var User = $resource('/user/:userId', {userId:'@id'}); + User.get({userId:123}, function(user) { + user.abc = true; + user.$save(); + }); + ``` + * + * It's worth noting that the success callback for `get`, `query` and other methods gets passed + * in the response that came from the server as well as $http header getter function, so one + * could rewrite the above example and get access to http headers as: + * + ```js + var User = $resource('/user/:userId', {userId:'@id'}); + User.get({userId:123}, function(user, getResponseHeaders){ + user.abc = true; + user.$save(function(user, putResponseHeaders) { + //user => saved user object + //putResponseHeaders => $http header getter + }); + }); + ``` + * + * You can also access the raw `$http` promise via the `$promise` property on the object returned + * + ``` + var User = $resource('/user/:userId', {userId:'@id'}); + User.get({userId:123}) + .$promise.then(function(user) { + $scope.user = user; + }); + ``` + * + * @example + * + * # Creating a custom 'PUT' request + * + * In this example we create a custom method on our resource to make a PUT request + * ```js + * var app = angular.module('app', ['ngResource', 'ngRoute']); + * + * // Some APIs expect a PUT request in the format URL/object/ID + * // Here we are creating an 'update' method + * app.factory('Notes', ['$resource', function($resource) { + * return $resource('/notes/:id', null, + * { + * 'update': { method:'PUT' } + * }); + * }]); + * + * // In our controller we get the ID from the URL using ngRoute and $routeParams + * // We pass in $routeParams and our Notes factory along with $scope + * app.controller('NotesCtrl', ['$scope', '$routeParams', 'Notes', + function($scope, $routeParams, Notes) { + * // First get a note object from the factory + * var note = Notes.get({ id:$routeParams.id }); + * $id = note.id; + * + * // Now call update passing in the ID first then the object you are updating + * Notes.update({ id:$id }, note); + * + * // This will PUT /notes/ID with the note object in the request payload + * }]); + * ``` + * + * @example + * + * # Cancelling requests + * + * If an action's configuration specifies that it is cancellable, you can cancel the request related + * to an instance or collection (as long as it is a result of a "non-instance" call): + * + ```js + // ...defining the `Hotel` resource... + var Hotel = $resource('/api/hotel/:id', {id: '@id'}, { + // Let's make the `query()` method cancellable + query: {method: 'get', isArray: true, cancellable: true} + }); + + // ...somewhere in the PlanVacationController... + ... + this.onDestinationChanged = function onDestinationChanged(destination) { + // We don't care about any pending request for hotels + // in a different destination any more + this.availableHotels.$cancelRequest(); + + // Let's query for hotels in '' + // (calls: /api/hotel?location=) + this.availableHotels = Hotel.query({location: destination}); + }; + ``` + * + */ +angular.module('ngResource', ['ng']). + provider('$resource', function() { + var PROTOCOL_AND_DOMAIN_REGEX = /^https?:\/\/[^\/]*/; + var provider = this; + + this.defaults = { + // Strip slashes by default + stripTrailingSlashes: true, + + // Default actions configuration + actions: { + 'get': {method: 'GET'}, + 'save': {method: 'POST'}, + 'query': {method: 'GET', isArray: true}, + 'remove': {method: 'DELETE'}, + 'delete': {method: 'DELETE'} + } + }; + + this.$get = ['$http', '$log', '$q', '$timeout', function($http, $log, $q, $timeout) { + + var noop = angular.noop, + forEach = angular.forEach, + extend = angular.extend, + copy = angular.copy, + isFunction = angular.isFunction; + + /** + * We need our custom method because encodeURIComponent is too aggressive and doesn't follow + * http://www.ietf.org/rfc/rfc3986.txt with regards to the character set + * (pchar) allowed in path segments: + * segment = *pchar + * pchar = unreserved / pct-encoded / sub-delims / ":" / "@" + * pct-encoded = "%" HEXDIG HEXDIG + * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" + * sub-delims = "!" / "$" / "&" / "'" / "(" / ")" + * / "*" / "+" / "," / ";" / "=" + */ + function encodeUriSegment(val) { + return encodeUriQuery(val, true). + replace(/%26/gi, '&'). + replace(/%3D/gi, '='). + replace(/%2B/gi, '+'); + } + + + /** + * This method is intended for encoding *key* or *value* parts of query component. We need a + * custom method because encodeURIComponent is too aggressive and encodes stuff that doesn't + * have to be encoded per http://tools.ietf.org/html/rfc3986: + * query = *( pchar / "/" / "?" ) + * pchar = unreserved / pct-encoded / sub-delims / ":" / "@" + * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" + * pct-encoded = "%" HEXDIG HEXDIG + * sub-delims = "!" / "$" / "&" / "'" / "(" / ")" + * / "*" / "+" / "," / ";" / "=" + */ + function encodeUriQuery(val, pctEncodeSpaces) { + return encodeURIComponent(val). + replace(/%40/gi, '@'). + replace(/%3A/gi, ':'). + replace(/%24/g, '$'). + replace(/%2C/gi, ','). + replace(/%20/g, (pctEncodeSpaces ? '%20' : '+')); + } + + function Route(template, defaults) { + this.template = template; + this.defaults = extend({}, provider.defaults, defaults); + this.urlParams = {}; + } + + Route.prototype = { + setUrlParams: function(config, params, actionUrl) { + var self = this, + url = actionUrl || self.template, + val, + encodedVal, + protocolAndDomain = ''; + + var urlParams = self.urlParams = {}; + forEach(url.split(/\W/), function(param) { + if (param === 'hasOwnProperty') { + throw $resourceMinErr('badname', "hasOwnProperty is not a valid parameter name."); + } + if (!(new RegExp("^\\d+$").test(param)) && param && + (new RegExp("(^|[^\\\\]):" + param + "(\\W|$)").test(url))) { + urlParams[param] = { + isQueryParamValue: (new RegExp("\\?.*=:" + param + "(?:\\W|$)")).test(url) + }; + } + }); + url = url.replace(/\\:/g, ':'); + url = url.replace(PROTOCOL_AND_DOMAIN_REGEX, function(match) { + protocolAndDomain = match; + return ''; + }); + + params = params || {}; + forEach(self.urlParams, function(paramInfo, urlParam) { + val = params.hasOwnProperty(urlParam) ? params[urlParam] : self.defaults[urlParam]; + if (angular.isDefined(val) && val !== null) { + if (paramInfo.isQueryParamValue) { + encodedVal = encodeUriQuery(val, true); + } else { + encodedVal = encodeUriSegment(val); + } + url = url.replace(new RegExp(":" + urlParam + "(\\W|$)", "g"), function(match, p1) { + return encodedVal + p1; + }); + } else { + url = url.replace(new RegExp("(\/?):" + urlParam + "(\\W|$)", "g"), function(match, + leadingSlashes, tail) { + if (tail.charAt(0) == '/') { + return tail; + } else { + return leadingSlashes + tail; + } + }); + } + }); + + // strip trailing slashes and set the url (unless this behavior is specifically disabled) + if (self.defaults.stripTrailingSlashes) { + url = url.replace(/\/+$/, '') || '/'; + } + + // then replace collapse `/.` if found in the last URL path segment before the query + // E.g. `http://url.com/id./format?q=x` becomes `http://url.com/id.format?q=x` + url = url.replace(/\/\.(?=\w+($|\?))/, '.'); + // replace escaped `/\.` with `/.` + config.url = protocolAndDomain + url.replace(/\/\\\./, '/.'); + + + // set params - delegate param encoding to $http + forEach(params, function(value, key) { + if (!self.urlParams[key]) { + config.params = config.params || {}; + config.params[key] = value; + } + }); + } + }; + + + function resourceFactory(url, paramDefaults, actions, options) { + var route = new Route(url, options); + + actions = extend({}, provider.defaults.actions, actions); + + function extractParams(data, actionParams) { + var ids = {}; + actionParams = extend({}, paramDefaults, actionParams); + forEach(actionParams, function(value, key) { + if (isFunction(value)) { value = value(); } + ids[key] = value && value.charAt && value.charAt(0) == '@' ? + lookupDottedPath(data, value.substr(1)) : value; + }); + return ids; + } + + function defaultResponseInterceptor(response) { + return response.resource; + } + + function Resource(value) { + shallowClearAndCopy(value || {}, this); + } + + Resource.prototype.toJSON = function() { + var data = extend({}, this); + delete data.$promise; + delete data.$resolved; + return data; + }; + + forEach(actions, function(action, name) { + var hasBody = /^(POST|PUT|PATCH)$/i.test(action.method); + var numericTimeout = action.timeout; + var cancellable = angular.isDefined(action.cancellable) ? action.cancellable : + (options && angular.isDefined(options.cancellable)) ? options.cancellable : + provider.defaults.cancellable; + + if (numericTimeout && !angular.isNumber(numericTimeout)) { + $log.debug('ngResource:\n' + + ' Only numeric values are allowed as `timeout`.\n' + + ' Promises are not supported in $resource, because the same value would ' + + 'be used for multiple requests. If you are looking for a way to cancel ' + + 'requests, you should use the `cancellable` option.'); + delete action.timeout; + numericTimeout = null; + } + + Resource[name] = function(a1, a2, a3, a4) { + var params = {}, data, success, error; + + /* jshint -W086 */ /* (purposefully fall through case statements) */ + switch (arguments.length) { + case 4: + error = a4; + success = a3; + //fallthrough + case 3: + case 2: + if (isFunction(a2)) { + if (isFunction(a1)) { + success = a1; + error = a2; + break; + } + + success = a2; + error = a3; + //fallthrough + } else { + params = a1; + data = a2; + success = a3; + break; + } + case 1: + if (isFunction(a1)) success = a1; + else if (hasBody) data = a1; + else params = a1; + break; + case 0: break; + default: + throw $resourceMinErr('badargs', + "Expected up to 4 arguments [params, data, success, error], got {0} arguments", + arguments.length); + } + /* jshint +W086 */ /* (purposefully fall through case statements) */ + + var isInstanceCall = this instanceof Resource; + var value = isInstanceCall ? data : (action.isArray ? [] : new Resource(data)); + var httpConfig = {}; + var responseInterceptor = action.interceptor && action.interceptor.response || + defaultResponseInterceptor; + var responseErrorInterceptor = action.interceptor && action.interceptor.responseError || + undefined; + var timeoutDeferred; + var numericTimeoutPromise; + + forEach(action, function(value, key) { + switch (key) { + default: + httpConfig[key] = copy(value); + break; + case 'params': + case 'isArray': + case 'interceptor': + case 'cancellable': + break; + } + }); + + if (!isInstanceCall && cancellable) { + timeoutDeferred = $q.defer(); + httpConfig.timeout = timeoutDeferred.promise; + + if (numericTimeout) { + numericTimeoutPromise = $timeout(timeoutDeferred.resolve, numericTimeout); + } + } + + if (hasBody) httpConfig.data = data; + route.setUrlParams(httpConfig, + extend({}, extractParams(data, action.params || {}), params), + action.url); + + var promise = $http(httpConfig).then(function(response) { + var data = response.data; + + if (data) { + // Need to convert action.isArray to boolean in case it is undefined + // jshint -W018 + if (angular.isArray(data) !== (!!action.isArray)) { + throw $resourceMinErr('badcfg', + 'Error in resource configuration for action `{0}`. Expected response to ' + + 'contain an {1} but got an {2} (Request: {3} {4})', name, action.isArray ? 'array' : 'object', + angular.isArray(data) ? 'array' : 'object', httpConfig.method, httpConfig.url); + } + // jshint +W018 + if (action.isArray) { + value.length = 0; + forEach(data, function(item) { + if (typeof item === "object") { + value.push(new Resource(item)); + } else { + // Valid JSON values may be string literals, and these should not be converted + // into objects. These items will not have access to the Resource prototype + // methods, but unfortunately there + value.push(item); + } + }); + } else { + var promise = value.$promise; // Save the promise + shallowClearAndCopy(data, value); + value.$promise = promise; // Restore the promise + } + } + response.resource = value; + + return response; + }, function(response) { + (error || noop)(response); + return $q.reject(response); + }); + + promise.finally(function() { + value.$resolved = true; + if (!isInstanceCall && cancellable) { + value.$cancelRequest = angular.noop; + $timeout.cancel(numericTimeoutPromise); + timeoutDeferred = numericTimeoutPromise = httpConfig.timeout = null; + } + }); + + promise = promise.then( + function(response) { + var value = responseInterceptor(response); + (success || noop)(value, response.headers); + return value; + }, + responseErrorInterceptor); + + if (!isInstanceCall) { + // we are creating instance / collection + // - set the initial promise + // - return the instance / collection + value.$promise = promise; + value.$resolved = false; + if (cancellable) value.$cancelRequest = timeoutDeferred.resolve; + + return value; + } + + // instance call + return promise; + }; + + + Resource.prototype['$' + name] = function(params, success, error) { + if (isFunction(params)) { + error = success; success = params; params = {}; + } + var result = Resource[name].call(this, params, this, success, error); + return result.$promise || result; + }; + }); + + Resource.bind = function(additionalParamDefaults) { + return resourceFactory(url, extend({}, paramDefaults, additionalParamDefaults), actions); + }; + + return Resource; + } + + return resourceFactory; + }]; + }); + + +})(window, window.angular); diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-resource.min.js b/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-resource.min.js new file mode 100644 index 000000000..306657dcb --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-resource.min.js @@ -0,0 +1,15 @@ +/* + AngularJS v1.5.0 + (c) 2010-2016 Google, Inc. http://angularjs.org + License: MIT +*/ +(function(Q,d,G){'use strict';function H(t,g){g=g||{};d.forEach(g,function(d,q){delete g[q]});for(var q in t)!t.hasOwnProperty(q)||"$"===q.charAt(0)&&"$"===q.charAt(1)||(g[q]=t[q]);return g}var z=d.$$minErr("$resource"),N=/^(\.[a-zA-Z_$@][0-9a-zA-Z_$@]*)+$/;d.module("ngResource",["ng"]).provider("$resource",function(){var t=/^https?:\/\/[^\/]*/,g=this;this.defaults={stripTrailingSlashes:!0,actions:{get:{method:"GET"},save:{method:"POST"},query:{method:"GET",isArray:!0},remove:{method:"DELETE"},"delete":{method:"DELETE"}}}; +this.$get=["$http","$log","$q","$timeout",function(q,M,I,J){function A(d,h){return encodeURIComponent(d).replace(/%40/gi,"@").replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,h?"%20":"+")}function B(d,h){this.template=d;this.defaults=v({},g.defaults,h);this.urlParams={}}function K(e,h,n,k){function c(a,b){var c={};b=v({},h,b);u(b,function(b,h){x(b)&&(b=b());var f;if(b&&b.charAt&&"@"==b.charAt(0)){f=a;var l=b.substr(1);if(null==l||""===l||"hasOwnProperty"===l||!N.test("."+ +l))throw z("badmember",l);for(var l=l.split("."),m=0,k=l.length;m + */ + /* global -ngRouteModule */ +var ngRouteModule = angular.module('ngRoute', ['ng']). + provider('$route', $RouteProvider), + $routeMinErr = angular.$$minErr('ngRoute'); + +/** + * @ngdoc provider + * @name $routeProvider + * + * @description + * + * Used for configuring routes. + * + * ## Example + * See {@link ngRoute.$route#example $route} for an example of configuring and using `ngRoute`. + * + * ## Dependencies + * Requires the {@link ngRoute `ngRoute`} module to be installed. + */ +function $RouteProvider() { + function inherit(parent, extra) { + return angular.extend(Object.create(parent), extra); + } + + var routes = {}; + + /** + * @ngdoc method + * @name $routeProvider#when + * + * @param {string} path Route path (matched against `$location.path`). If `$location.path` + * contains redundant trailing slash or is missing one, the route will still match and the + * `$location.path` will be updated to add or drop the trailing slash to exactly match the + * route definition. + * + * * `path` can contain named groups starting with a colon: e.g. `:name`. All characters up + * to the next slash are matched and stored in `$routeParams` under the given `name` + * when the route matches. + * * `path` can contain named groups starting with a colon and ending with a star: + * e.g.`:name*`. All characters are eagerly stored in `$routeParams` under the given `name` + * when the route matches. + * * `path` can contain optional named groups with a question mark: e.g.`:name?`. + * + * For example, routes like `/color/:color/largecode/:largecode*\/edit` will match + * `/color/brown/largecode/code/with/slashes/edit` and extract: + * + * * `color: brown` + * * `largecode: code/with/slashes`. + * + * + * @param {Object} route Mapping information to be assigned to `$route.current` on route + * match. + * + * Object properties: + * + * - `controller` – `{(string|function()=}` – Controller fn that should be associated with + * newly created scope or the name of a {@link angular.Module#controller registered + * controller} if passed as a string. + * - `controllerAs` – `{string=}` – An identifier name for a reference to the controller. + * If present, the controller will be published to scope under the `controllerAs` name. + * - `template` – `{string=|function()=}` – html template as a string or a function that + * returns an html template as a string which should be used by {@link + * ngRoute.directive:ngView ngView} or {@link ng.directive:ngInclude ngInclude} directives. + * This property takes precedence over `templateUrl`. + * + * If `template` is a function, it will be called with the following parameters: + * + * - `{Array.}` - route parameters extracted from the current + * `$location.path()` by applying the current route + * + * - `templateUrl` – `{string=|function()=}` – path or function that returns a path to an html + * template that should be used by {@link ngRoute.directive:ngView ngView}. + * + * If `templateUrl` is a function, it will be called with the following parameters: + * + * - `{Array.}` - route parameters extracted from the current + * `$location.path()` by applying the current route + * + * - `resolve` - `{Object.=}` - An optional map of dependencies which should + * be injected into the controller. If any of these dependencies are promises, the router + * will wait for them all to be resolved or one to be rejected before the controller is + * instantiated. + * If all the promises are resolved successfully, the values of the resolved promises are + * injected and {@link ngRoute.$route#$routeChangeSuccess $routeChangeSuccess} event is + * fired. If any of the promises are rejected the + * {@link ngRoute.$route#$routeChangeError $routeChangeError} event is fired. + * For easier access to the resolved dependencies from the template, the `resolve` map will + * be available on the scope of the route, under `$resolve` (by default) or a custom name + * specified by the `resolveAs` property (see below). This can be particularly useful, when + * working with {@link angular.Module#component components} as route templates.
    + *
    + * **Note:** If your scope already contains a property with this name, it will be hidden + * or overwritten. Make sure, you specify an appropriate name for this property, that + * does not collide with other properties on the scope. + *
    + * The map object is: + * + * - `key` – `{string}`: a name of a dependency to be injected into the controller. + * - `factory` - `{string|function}`: If `string` then it is an alias for a service. + * Otherwise if function, then it is {@link auto.$injector#invoke injected} + * and the return value is treated as the dependency. If the result is a promise, it is + * resolved before its value is injected into the controller. Be aware that + * `ngRoute.$routeParams` will still refer to the previous route within these resolve + * functions. Use `$route.current.params` to access the new route parameters, instead. + * + * - `resolveAs` - `{string=}` - The name under which the `resolve` map will be available on + * the scope of the route. If omitted, defaults to `$resolve`. + * + * - `redirectTo` – `{(string|function())=}` – value to update + * {@link ng.$location $location} path with and trigger route redirection. + * + * If `redirectTo` is a function, it will be called with the following parameters: + * + * - `{Object.}` - route parameters extracted from the current + * `$location.path()` by applying the current route templateUrl. + * - `{string}` - current `$location.path()` + * - `{Object}` - current `$location.search()` + * + * The custom `redirectTo` function is expected to return a string which will be used + * to update `$location.path()` and `$location.search()`. + * + * - `[reloadOnSearch=true]` - `{boolean=}` - reload route when only `$location.search()` + * or `$location.hash()` changes. + * + * If the option is set to `false` and url in the browser changes, then + * `$routeUpdate` event is broadcasted on the root scope. + * + * - `[caseInsensitiveMatch=false]` - `{boolean=}` - match routes without being case sensitive + * + * If the option is set to `true`, then the particular route can be matched without being + * case sensitive + * + * @returns {Object} self + * + * @description + * Adds a new route definition to the `$route` service. + */ + this.when = function(path, route) { + //copy original route object to preserve params inherited from proto chain + var routeCopy = angular.copy(route); + if (angular.isUndefined(routeCopy.reloadOnSearch)) { + routeCopy.reloadOnSearch = true; + } + if (angular.isUndefined(routeCopy.caseInsensitiveMatch)) { + routeCopy.caseInsensitiveMatch = this.caseInsensitiveMatch; + } + routes[path] = angular.extend( + routeCopy, + path && pathRegExp(path, routeCopy) + ); + + // create redirection for trailing slashes + if (path) { + var redirectPath = (path[path.length - 1] == '/') + ? path.substr(0, path.length - 1) + : path + '/'; + + routes[redirectPath] = angular.extend( + {redirectTo: path}, + pathRegExp(redirectPath, routeCopy) + ); + } + + return this; + }; + + /** + * @ngdoc property + * @name $routeProvider#caseInsensitiveMatch + * @description + * + * A boolean property indicating if routes defined + * using this provider should be matched using a case insensitive + * algorithm. Defaults to `false`. + */ + this.caseInsensitiveMatch = false; + + /** + * @param path {string} path + * @param opts {Object} options + * @return {?Object} + * + * @description + * Normalizes the given path, returning a regular expression + * and the original path. + * + * Inspired by pathRexp in visionmedia/express/lib/utils.js. + */ + function pathRegExp(path, opts) { + var insensitive = opts.caseInsensitiveMatch, + ret = { + originalPath: path, + regexp: path + }, + keys = ret.keys = []; + + path = path + .replace(/([().])/g, '\\$1') + .replace(/(\/)?:(\w+)([\?\*])?/g, function(_, slash, key, option) { + var optional = option === '?' ? option : null; + var star = option === '*' ? option : null; + keys.push({ name: key, optional: !!optional }); + slash = slash || ''; + return '' + + (optional ? '' : slash) + + '(?:' + + (optional ? slash : '') + + (star && '(.+?)' || '([^/]+)') + + (optional || '') + + ')' + + (optional || ''); + }) + .replace(/([\/$\*])/g, '\\$1'); + + ret.regexp = new RegExp('^' + path + '$', insensitive ? 'i' : ''); + return ret; + } + + /** + * @ngdoc method + * @name $routeProvider#otherwise + * + * @description + * Sets route definition that will be used on route change when no other route definition + * is matched. + * + * @param {Object|string} params Mapping information to be assigned to `$route.current`. + * If called with a string, the value maps to `redirectTo`. + * @returns {Object} self + */ + this.otherwise = function(params) { + if (typeof params === 'string') { + params = {redirectTo: params}; + } + this.when(null, params); + return this; + }; + + + this.$get = ['$rootScope', + '$location', + '$routeParams', + '$q', + '$injector', + '$templateRequest', + '$sce', + function($rootScope, $location, $routeParams, $q, $injector, $templateRequest, $sce) { + + /** + * @ngdoc service + * @name $route + * @requires $location + * @requires $routeParams + * + * @property {Object} current Reference to the current route definition. + * The route definition contains: + * + * - `controller`: The controller constructor as defined in the route definition. + * - `locals`: A map of locals which is used by {@link ng.$controller $controller} service for + * controller instantiation. The `locals` contain + * the resolved values of the `resolve` map. Additionally the `locals` also contain: + * + * - `$scope` - The current route scope. + * - `$template` - The current route template HTML. + * + * The `locals` will be assigned to the route scope's `$resolve` property. You can override + * the property name, using `resolveAs` in the route definition. See + * {@link ngRoute.$routeProvider $routeProvider} for more info. + * + * @property {Object} routes Object with all route configuration Objects as its properties. + * + * @description + * `$route` is used for deep-linking URLs to controllers and views (HTML partials). + * It watches `$location.url()` and tries to map the path to an existing route definition. + * + * Requires the {@link ngRoute `ngRoute`} module to be installed. + * + * You can define routes through {@link ngRoute.$routeProvider $routeProvider}'s API. + * + * The `$route` service is typically used in conjunction with the + * {@link ngRoute.directive:ngView `ngView`} directive and the + * {@link ngRoute.$routeParams `$routeParams`} service. + * + * @example + * This example shows how changing the URL hash causes the `$route` to match a route against the + * URL, and the `ngView` pulls in the partial. + * + * + * + *
    + * Choose: + * Moby | + * Moby: Ch1 | + * Gatsby | + * Gatsby: Ch4 | + * Scarlet Letter
    + * + *
    + * + *
    + * + *
    $location.path() = {{$location.path()}}
    + *
    $route.current.templateUrl = {{$route.current.templateUrl}}
    + *
    $route.current.params = {{$route.current.params}}
    + *
    $route.current.scope.name = {{$route.current.scope.name}}
    + *
    $routeParams = {{$routeParams}}
    + *
    + *
    + * + * + * controller: {{name}}
    + * Book Id: {{params.bookId}}
    + *
    + * + * + * controller: {{name}}
    + * Book Id: {{params.bookId}}
    + * Chapter Id: {{params.chapterId}} + *
    + * + * + * angular.module('ngRouteExample', ['ngRoute']) + * + * .controller('MainController', function($scope, $route, $routeParams, $location) { + * $scope.$route = $route; + * $scope.$location = $location; + * $scope.$routeParams = $routeParams; + * }) + * + * .controller('BookController', function($scope, $routeParams) { + * $scope.name = "BookController"; + * $scope.params = $routeParams; + * }) + * + * .controller('ChapterController', function($scope, $routeParams) { + * $scope.name = "ChapterController"; + * $scope.params = $routeParams; + * }) + * + * .config(function($routeProvider, $locationProvider) { + * $routeProvider + * .when('/Book/:bookId', { + * templateUrl: 'book.html', + * controller: 'BookController', + * resolve: { + * // I will cause a 1 second delay + * delay: function($q, $timeout) { + * var delay = $q.defer(); + * $timeout(delay.resolve, 1000); + * return delay.promise; + * } + * } + * }) + * .when('/Book/:bookId/ch/:chapterId', { + * templateUrl: 'chapter.html', + * controller: 'ChapterController' + * }); + * + * // configure html5 to get links working on jsfiddle + * $locationProvider.html5Mode(true); + * }); + * + * + * + * + * it('should load and compile correct template', function() { + * element(by.linkText('Moby: Ch1')).click(); + * var content = element(by.css('[ng-view]')).getText(); + * expect(content).toMatch(/controller\: ChapterController/); + * expect(content).toMatch(/Book Id\: Moby/); + * expect(content).toMatch(/Chapter Id\: 1/); + * + * element(by.partialLinkText('Scarlet')).click(); + * + * content = element(by.css('[ng-view]')).getText(); + * expect(content).toMatch(/controller\: BookController/); + * expect(content).toMatch(/Book Id\: Scarlet/); + * }); + * + *
    + */ + + /** + * @ngdoc event + * @name $route#$routeChangeStart + * @eventType broadcast on root scope + * @description + * Broadcasted before a route change. At this point the route services starts + * resolving all of the dependencies needed for the route change to occur. + * Typically this involves fetching the view template as well as any dependencies + * defined in `resolve` route property. Once all of the dependencies are resolved + * `$routeChangeSuccess` is fired. + * + * The route change (and the `$location` change that triggered it) can be prevented + * by calling `preventDefault` method of the event. See {@link ng.$rootScope.Scope#$on} + * for more details about event object. + * + * @param {Object} angularEvent Synthetic event object. + * @param {Route} next Future route information. + * @param {Route} current Current route information. + */ + + /** + * @ngdoc event + * @name $route#$routeChangeSuccess + * @eventType broadcast on root scope + * @description + * Broadcasted after a route change has happened successfully. + * The `resolve` dependencies are now available in the `current.locals` property. + * + * {@link ngRoute.directive:ngView ngView} listens for the directive + * to instantiate the controller and render the view. + * + * @param {Object} angularEvent Synthetic event object. + * @param {Route} current Current route information. + * @param {Route|Undefined} previous Previous route information, or undefined if current is + * first route entered. + */ + + /** + * @ngdoc event + * @name $route#$routeChangeError + * @eventType broadcast on root scope + * @description + * Broadcasted if any of the resolve promises are rejected. + * + * @param {Object} angularEvent Synthetic event object + * @param {Route} current Current route information. + * @param {Route} previous Previous route information. + * @param {Route} rejection Rejection of the promise. Usually the error of the failed promise. + */ + + /** + * @ngdoc event + * @name $route#$routeUpdate + * @eventType broadcast on root scope + * @description + * The `reloadOnSearch` property has been set to false, and we are reusing the same + * instance of the Controller. + * + * @param {Object} angularEvent Synthetic event object + * @param {Route} current Current/previous route information. + */ + + var forceReload = false, + preparedRoute, + preparedRouteIsUpdateOnly, + $route = { + routes: routes, + + /** + * @ngdoc method + * @name $route#reload + * + * @description + * Causes `$route` service to reload the current route even if + * {@link ng.$location $location} hasn't changed. + * + * As a result of that, {@link ngRoute.directive:ngView ngView} + * creates new scope and reinstantiates the controller. + */ + reload: function() { + forceReload = true; + + var fakeLocationEvent = { + defaultPrevented: false, + preventDefault: function fakePreventDefault() { + this.defaultPrevented = true; + forceReload = false; + } + }; + + $rootScope.$evalAsync(function() { + prepareRoute(fakeLocationEvent); + if (!fakeLocationEvent.defaultPrevented) commitRoute(); + }); + }, + + /** + * @ngdoc method + * @name $route#updateParams + * + * @description + * Causes `$route` service to update the current URL, replacing + * current route parameters with those specified in `newParams`. + * Provided property names that match the route's path segment + * definitions will be interpolated into the location's path, while + * remaining properties will be treated as query params. + * + * @param {!Object} newParams mapping of URL parameter names to values + */ + updateParams: function(newParams) { + if (this.current && this.current.$$route) { + newParams = angular.extend({}, this.current.params, newParams); + $location.path(interpolate(this.current.$$route.originalPath, newParams)); + // interpolate modifies newParams, only query params are left + $location.search(newParams); + } else { + throw $routeMinErr('norout', 'Tried updating route when with no current route'); + } + } + }; + + $rootScope.$on('$locationChangeStart', prepareRoute); + $rootScope.$on('$locationChangeSuccess', commitRoute); + + return $route; + + ///////////////////////////////////////////////////// + + /** + * @param on {string} current url + * @param route {Object} route regexp to match the url against + * @return {?Object} + * + * @description + * Check if the route matches the current url. + * + * Inspired by match in + * visionmedia/express/lib/router/router.js. + */ + function switchRouteMatcher(on, route) { + var keys = route.keys, + params = {}; + + if (!route.regexp) return null; + + var m = route.regexp.exec(on); + if (!m) return null; + + for (var i = 1, len = m.length; i < len; ++i) { + var key = keys[i - 1]; + + var val = m[i]; + + if (key && val) { + params[key.name] = val; + } + } + return params; + } + + function prepareRoute($locationEvent) { + var lastRoute = $route.current; + + preparedRoute = parseRoute(); + preparedRouteIsUpdateOnly = preparedRoute && lastRoute && preparedRoute.$$route === lastRoute.$$route + && angular.equals(preparedRoute.pathParams, lastRoute.pathParams) + && !preparedRoute.reloadOnSearch && !forceReload; + + if (!preparedRouteIsUpdateOnly && (lastRoute || preparedRoute)) { + if ($rootScope.$broadcast('$routeChangeStart', preparedRoute, lastRoute).defaultPrevented) { + if ($locationEvent) { + $locationEvent.preventDefault(); + } + } + } + } + + function commitRoute() { + var lastRoute = $route.current; + var nextRoute = preparedRoute; + + if (preparedRouteIsUpdateOnly) { + lastRoute.params = nextRoute.params; + angular.copy(lastRoute.params, $routeParams); + $rootScope.$broadcast('$routeUpdate', lastRoute); + } else if (nextRoute || lastRoute) { + forceReload = false; + $route.current = nextRoute; + if (nextRoute) { + if (nextRoute.redirectTo) { + if (angular.isString(nextRoute.redirectTo)) { + $location.path(interpolate(nextRoute.redirectTo, nextRoute.params)).search(nextRoute.params) + .replace(); + } else { + $location.url(nextRoute.redirectTo(nextRoute.pathParams, $location.path(), $location.search())) + .replace(); + } + } + } + + $q.when(nextRoute). + then(function() { + if (nextRoute) { + var locals = angular.extend({}, nextRoute.resolve), + template, templateUrl; + + angular.forEach(locals, function(value, key) { + locals[key] = angular.isString(value) ? + $injector.get(value) : $injector.invoke(value, null, null, key); + }); + + if (angular.isDefined(template = nextRoute.template)) { + if (angular.isFunction(template)) { + template = template(nextRoute.params); + } + } else if (angular.isDefined(templateUrl = nextRoute.templateUrl)) { + if (angular.isFunction(templateUrl)) { + templateUrl = templateUrl(nextRoute.params); + } + if (angular.isDefined(templateUrl)) { + nextRoute.loadedTemplateUrl = $sce.valueOf(templateUrl); + template = $templateRequest(templateUrl); + } + } + if (angular.isDefined(template)) { + locals['$template'] = template; + } + return $q.all(locals); + } + }). + then(function(locals) { + // after route change + if (nextRoute == $route.current) { + if (nextRoute) { + nextRoute.locals = locals; + angular.copy(nextRoute.params, $routeParams); + } + $rootScope.$broadcast('$routeChangeSuccess', nextRoute, lastRoute); + } + }, function(error) { + if (nextRoute == $route.current) { + $rootScope.$broadcast('$routeChangeError', nextRoute, lastRoute, error); + } + }); + } + } + + + /** + * @returns {Object} the current active route, by matching it against the URL + */ + function parseRoute() { + // Match a route + var params, match; + angular.forEach(routes, function(route, path) { + if (!match && (params = switchRouteMatcher($location.path(), route))) { + match = inherit(route, { + params: angular.extend({}, $location.search(), params), + pathParams: params}); + match.$$route = route; + } + }); + // No route matched; fallback to "otherwise" route + return match || routes[null] && inherit(routes[null], {params: {}, pathParams:{}}); + } + + /** + * @returns {string} interpolation of the redirect path with the parameters + */ + function interpolate(string, params) { + var result = []; + angular.forEach((string || '').split(':'), function(segment, i) { + if (i === 0) { + result.push(segment); + } else { + var segmentMatch = segment.match(/(\w+)(?:[?*])?(.*)/); + var key = segmentMatch[1]; + result.push(params[key]); + result.push(segmentMatch[2] || ''); + delete params[key]; + } + }); + return result.join(''); + } + }]; +} + +ngRouteModule.provider('$routeParams', $RouteParamsProvider); + + +/** + * @ngdoc service + * @name $routeParams + * @requires $route + * + * @description + * The `$routeParams` service allows you to retrieve the current set of route parameters. + * + * Requires the {@link ngRoute `ngRoute`} module to be installed. + * + * The route parameters are a combination of {@link ng.$location `$location`}'s + * {@link ng.$location#search `search()`} and {@link ng.$location#path `path()`}. + * The `path` parameters are extracted when the {@link ngRoute.$route `$route`} path is matched. + * + * In case of parameter name collision, `path` params take precedence over `search` params. + * + * The service guarantees that the identity of the `$routeParams` object will remain unchanged + * (but its properties will likely change) even when a route change occurs. + * + * Note that the `$routeParams` are only updated *after* a route change completes successfully. + * This means that you cannot rely on `$routeParams` being correct in route resolve functions. + * Instead you can use `$route.current.params` to access the new route's parameters. + * + * @example + * ```js + * // Given: + * // URL: http://server.com/index.html#/Chapter/1/Section/2?search=moby + * // Route: /Chapter/:chapterId/Section/:sectionId + * // + * // Then + * $routeParams ==> {chapterId:'1', sectionId:'2', search:'moby'} + * ``` + */ +function $RouteParamsProvider() { + this.$get = function() { return {}; }; +} + +ngRouteModule.directive('ngView', ngViewFactory); +ngRouteModule.directive('ngView', ngViewFillContentFactory); + + +/** + * @ngdoc directive + * @name ngView + * @restrict ECA + * + * @description + * # Overview + * `ngView` is a directive that complements the {@link ngRoute.$route $route} service by + * including the rendered template of the current route into the main layout (`index.html`) file. + * Every time the current route changes, the included view changes with it according to the + * configuration of the `$route` service. + * + * Requires the {@link ngRoute `ngRoute`} module to be installed. + * + * @animations + * enter - animation is used to bring new content into the browser. + * leave - animation is used to animate existing content away. + * + * The enter and leave animation occur concurrently. + * + * @scope + * @priority 400 + * @param {string=} onload Expression to evaluate whenever the view updates. + * + * @param {string=} autoscroll Whether `ngView` should call {@link ng.$anchorScroll + * $anchorScroll} to scroll the viewport after the view is updated. + * + * - If the attribute is not set, disable scrolling. + * - If the attribute is set without value, enable scrolling. + * - Otherwise enable scrolling only if the `autoscroll` attribute value evaluated + * as an expression yields a truthy value. + * @example + + +
    + Choose: + Moby | + Moby: Ch1 | + Gatsby | + Gatsby: Ch4 | + Scarlet Letter
    + +
    +
    +
    +
    + +
    $location.path() = {{main.$location.path()}}
    +
    $route.current.templateUrl = {{main.$route.current.templateUrl}}
    +
    $route.current.params = {{main.$route.current.params}}
    +
    $routeParams = {{main.$routeParams}}
    +
    +
    + + +
    + controller: {{book.name}}
    + Book Id: {{book.params.bookId}}
    +
    +
    + + +
    + controller: {{chapter.name}}
    + Book Id: {{chapter.params.bookId}}
    + Chapter Id: {{chapter.params.chapterId}} +
    +
    + + + .view-animate-container { + position:relative; + height:100px!important; + background:white; + border:1px solid black; + height:40px; + overflow:hidden; + } + + .view-animate { + padding:10px; + } + + .view-animate.ng-enter, .view-animate.ng-leave { + transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 1.5s; + + display:block; + width:100%; + border-left:1px solid black; + + position:absolute; + top:0; + left:0; + right:0; + bottom:0; + padding:10px; + } + + .view-animate.ng-enter { + left:100%; + } + .view-animate.ng-enter.ng-enter-active { + left:0; + } + .view-animate.ng-leave.ng-leave-active { + left:-100%; + } + + + + angular.module('ngViewExample', ['ngRoute', 'ngAnimate']) + .config(['$routeProvider', '$locationProvider', + function($routeProvider, $locationProvider) { + $routeProvider + .when('/Book/:bookId', { + templateUrl: 'book.html', + controller: 'BookCtrl', + controllerAs: 'book' + }) + .when('/Book/:bookId/ch/:chapterId', { + templateUrl: 'chapter.html', + controller: 'ChapterCtrl', + controllerAs: 'chapter' + }); + + $locationProvider.html5Mode(true); + }]) + .controller('MainCtrl', ['$route', '$routeParams', '$location', + function($route, $routeParams, $location) { + this.$route = $route; + this.$location = $location; + this.$routeParams = $routeParams; + }]) + .controller('BookCtrl', ['$routeParams', function($routeParams) { + this.name = "BookCtrl"; + this.params = $routeParams; + }]) + .controller('ChapterCtrl', ['$routeParams', function($routeParams) { + this.name = "ChapterCtrl"; + this.params = $routeParams; + }]); + + + + + it('should load and compile correct template', function() { + element(by.linkText('Moby: Ch1')).click(); + var content = element(by.css('[ng-view]')).getText(); + expect(content).toMatch(/controller\: ChapterCtrl/); + expect(content).toMatch(/Book Id\: Moby/); + expect(content).toMatch(/Chapter Id\: 1/); + + element(by.partialLinkText('Scarlet')).click(); + + content = element(by.css('[ng-view]')).getText(); + expect(content).toMatch(/controller\: BookCtrl/); + expect(content).toMatch(/Book Id\: Scarlet/); + }); + +
    + */ + + +/** + * @ngdoc event + * @name ngView#$viewContentLoaded + * @eventType emit on the current ngView scope + * @description + * Emitted every time the ngView content is reloaded. + */ +ngViewFactory.$inject = ['$route', '$anchorScroll', '$animate']; +function ngViewFactory($route, $anchorScroll, $animate) { + return { + restrict: 'ECA', + terminal: true, + priority: 400, + transclude: 'element', + link: function(scope, $element, attr, ctrl, $transclude) { + var currentScope, + currentElement, + previousLeaveAnimation, + autoScrollExp = attr.autoscroll, + onloadExp = attr.onload || ''; + + scope.$on('$routeChangeSuccess', update); + update(); + + function cleanupLastView() { + if (previousLeaveAnimation) { + $animate.cancel(previousLeaveAnimation); + previousLeaveAnimation = null; + } + + if (currentScope) { + currentScope.$destroy(); + currentScope = null; + } + if (currentElement) { + previousLeaveAnimation = $animate.leave(currentElement); + previousLeaveAnimation.then(function() { + previousLeaveAnimation = null; + }); + currentElement = null; + } + } + + function update() { + var locals = $route.current && $route.current.locals, + template = locals && locals.$template; + + if (angular.isDefined(template)) { + var newScope = scope.$new(); + var current = $route.current; + + // Note: This will also link all children of ng-view that were contained in the original + // html. If that content contains controllers, ... they could pollute/change the scope. + // However, using ng-view on an element with additional content does not make sense... + // Note: We can't remove them in the cloneAttchFn of $transclude as that + // function is called before linking the content, which would apply child + // directives to non existing elements. + var clone = $transclude(newScope, function(clone) { + $animate.enter(clone, null, currentElement || $element).then(function onNgViewEnter() { + if (angular.isDefined(autoScrollExp) + && (!autoScrollExp || scope.$eval(autoScrollExp))) { + $anchorScroll(); + } + }); + cleanupLastView(); + }); + + currentElement = clone; + currentScope = current.scope = newScope; + currentScope.$emit('$viewContentLoaded'); + currentScope.$eval(onloadExp); + } else { + cleanupLastView(); + } + } + } + }; +} + +// This directive is called during the $transclude call of the first `ngView` directive. +// It will replace and compile the content of the element with the loaded template. +// We need this directive so that the element content is already filled when +// the link function of another directive on the same element as ngView +// is called. +ngViewFillContentFactory.$inject = ['$compile', '$controller', '$route']; +function ngViewFillContentFactory($compile, $controller, $route) { + return { + restrict: 'ECA', + priority: -400, + link: function(scope, $element) { + var current = $route.current, + locals = current.locals; + + $element.html(locals.$template); + + var link = $compile($element.contents()); + + if (current.controller) { + locals.$scope = scope; + var controller = $controller(current.controller, locals); + if (current.controllerAs) { + scope[current.controllerAs] = controller; + } + $element.data('$ngControllerController', controller); + $element.children().data('$ngControllerController', controller); + } + scope[current.resolveAs || '$resolve'] = locals; + + link(scope); + } + }; +} + + +})(window, window.angular); diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-route.min.js b/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-route.min.js new file mode 100644 index 000000000..4d0d01878 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-route.min.js @@ -0,0 +1,15 @@ +/* + AngularJS v1.5.0 + (c) 2010-2016 Google, Inc. http://angularjs.org + License: MIT +*/ +(function(r,d,C){'use strict';function x(s,h,g){return{restrict:"ECA",terminal:!0,priority:400,transclude:"element",link:function(a,c,b,f,y){function k(){n&&(g.cancel(n),n=null);l&&(l.$destroy(),l=null);m&&(n=g.leave(m),n.then(function(){n=null}),m=null)}function z(){var b=s.current&&s.current.locals;if(d.isDefined(b&&b.$template)){var b=a.$new(),f=s.current;m=y(b,function(b){g.enter(b,null,m||c).then(function(){!d.isDefined(u)||u&&!a.$eval(u)||h()});k()});l=f.scope=b;l.$emit("$viewContentLoaded"); +l.$eval(v)}else k()}var l,m,n,u=b.autoscroll,v=b.onload||"";a.$on("$routeChangeSuccess",z);z()}}}function A(d,h,g){return{restrict:"ECA",priority:-400,link:function(a,c){var b=g.current,f=b.locals;c.html(f.$template);var y=d(c.contents());if(b.controller){f.$scope=a;var k=h(b.controller,f);b.controllerAs&&(a[b.controllerAs]=k);c.data("$ngControllerController",k);c.children().data("$ngControllerController",k)}a[b.resolveAs||"$resolve"]=f;y(a)}}}r=d.module("ngRoute",["ng"]).provider("$route",function(){function s(a, +c){return d.extend(Object.create(a),c)}function h(a,d){var b=d.caseInsensitiveMatch,f={originalPath:a,regexp:a},g=f.keys=[];a=a.replace(/([().])/g,"\\$1").replace(/(\/)?:(\w+)([\?\*])?/g,function(a,d,b,c){a="?"===c?c:null;c="*"===c?c:null;g.push({name:b,optional:!!a});d=d||"";return""+(a?"":d)+"(?:"+(a?d:"")+(c&&"(.+?)"||"([^/]+)")+(a||"")+")"+(a||"")}).replace(/([\/$\*])/g,"\\$1");f.regexp=new RegExp("^"+a+"$",b?"i":"");return f}var g={};this.when=function(a,c){var b=d.copy(c);d.isUndefined(b.reloadOnSearch)&& +(b.reloadOnSearch=!0);d.isUndefined(b.caseInsensitiveMatch)&&(b.caseInsensitiveMatch=this.caseInsensitiveMatch);g[a]=d.extend(b,a&&h(a,b));if(a){var f="/"==a[a.length-1]?a.substr(0,a.length-1):a+"/";g[f]=d.extend({redirectTo:a},h(f,b))}return this};this.caseInsensitiveMatch=!1;this.otherwise=function(a){"string"===typeof a&&(a={redirectTo:a});this.when(null,a);return this};this.$get=["$rootScope","$location","$routeParams","$q","$injector","$templateRequest","$sce",function(a,c,b,f,h,k,r){function l(b){var e= +t.current;(x=(p=n())&&e&&p.$$route===e.$$route&&d.equals(p.pathParams,e.pathParams)&&!p.reloadOnSearch&&!v)||!e&&!p||a.$broadcast("$routeChangeStart",p,e).defaultPrevented&&b&&b.preventDefault()}function m(){var w=t.current,e=p;if(x)w.params=e.params,d.copy(w.params,b),a.$broadcast("$routeUpdate",w);else if(e||w)v=!1,(t.current=e)&&e.redirectTo&&(d.isString(e.redirectTo)?c.path(u(e.redirectTo,e.params)).search(e.params).replace():c.url(e.redirectTo(e.pathParams,c.path(),c.search())).replace()),f.when(e).then(function(){if(e){var a= +d.extend({},e.resolve),b,c;d.forEach(a,function(b,e){a[e]=d.isString(b)?h.get(b):h.invoke(b,null,null,e)});d.isDefined(b=e.template)?d.isFunction(b)&&(b=b(e.params)):d.isDefined(c=e.templateUrl)&&(d.isFunction(c)&&(c=c(e.params)),d.isDefined(c)&&(e.loadedTemplateUrl=r.valueOf(c),b=k(c)));d.isDefined(b)&&(a.$template=b);return f.all(a)}}).then(function(c){e==t.current&&(e&&(e.locals=c,d.copy(e.params,b)),a.$broadcast("$routeChangeSuccess",e,w))},function(b){e==t.current&&a.$broadcast("$routeChangeError", +e,w,b)})}function n(){var a,b;d.forEach(g,function(f,g){var q;if(q=!b){var h=c.path();q=f.keys;var l={};if(f.regexp)if(h=f.regexp.exec(h)){for(var k=1,n=h.length;k + * + * See {@link ngSanitize.$sanitize `$sanitize`} for usage. + */ + +/** + * @ngdoc service + * @name $sanitize + * @kind function + * + * @description + * Sanitizes an html string by stripping all potentially dangerous tokens. + * + * The input is sanitized by parsing the HTML into tokens. All safe tokens (from a whitelist) are + * then serialized back to properly escaped html string. This means that no unsafe input can make + * it into the returned string. + * + * The whitelist for URL sanitization of attribute values is configured using the functions + * `aHrefSanitizationWhitelist` and `imgSrcSanitizationWhitelist` of {@link ng.$compileProvider + * `$compileProvider`}. + * + * The input may also contain SVG markup if this is enabled via {@link $sanitizeProvider}. + * + * @param {string} html HTML input. + * @returns {string} Sanitized HTML. + * + * @example + + + +
    + Snippet: + + + + + + + + + + + + + + + + + + + + + + + + + +
    DirectiveHowSourceRendered
    ng-bind-htmlAutomatically uses $sanitize
    <div ng-bind-html="snippet">
    </div>
    ng-bind-htmlBypass $sanitize by explicitly trusting the dangerous value +
    <div ng-bind-html="deliberatelyTrustDangerousSnippet()">
    +</div>
    +
    ng-bindAutomatically escapes
    <div ng-bind="snippet">
    </div>
    +
    +
    + + it('should sanitize the html snippet by default', function() { + expect(element(by.css('#bind-html-with-sanitize div')).getInnerHtml()). + toBe('

    an html\nclick here\nsnippet

    '); + }); + + it('should inline raw snippet if bound to a trusted value', function() { + expect(element(by.css('#bind-html-with-trust div')).getInnerHtml()). + toBe("

    an html\n" + + "click here\n" + + "snippet

    "); + }); + + it('should escape snippet without any filter', function() { + expect(element(by.css('#bind-default div')).getInnerHtml()). + toBe("<p style=\"color:blue\">an html\n" + + "<em onmouseover=\"this.textContent='PWN3D!'\">click here</em>\n" + + "snippet</p>"); + }); + + it('should update', function() { + element(by.model('snippet')).clear(); + element(by.model('snippet')).sendKeys('new text'); + expect(element(by.css('#bind-html-with-sanitize div')).getInnerHtml()). + toBe('new text'); + expect(element(by.css('#bind-html-with-trust div')).getInnerHtml()).toBe( + 'new text'); + expect(element(by.css('#bind-default div')).getInnerHtml()).toBe( + "new <b onclick=\"alert(1)\">text</b>"); + }); +
    +
    + */ + + +/** + * @ngdoc provider + * @name $sanitizeProvider + * + * @description + * Creates and configures {@link $sanitize} instance. + */ +function $SanitizeProvider() { + var svgEnabled = false; + + this.$get = ['$$sanitizeUri', function($$sanitizeUri) { + if (svgEnabled) { + angular.extend(validElements, svgElements); + } + return function(html) { + var buf = []; + htmlParser(html, htmlSanitizeWriter(buf, function(uri, isImage) { + return !/^unsafe:/.test($$sanitizeUri(uri, isImage)); + })); + return buf.join(''); + }; + }]; + + + /** + * @ngdoc method + * @name $sanitizeProvider#enableSvg + * @kind function + * + * @description + * Enables a subset of svg to be supported by the sanitizer. + * + *
    + *

    By enabling this setting without taking other precautions, you might expose your + * application to click-hijacking attacks. In these attacks, sanitized svg elements could be positioned + * outside of the containing element and be rendered over other elements on the page (e.g. a login + * link). Such behavior can then result in phishing incidents.

    + * + *

    To protect against these, explicitly setup `overflow: hidden` css rule for all potential svg + * tags within the sanitized content:

    + * + *
    + * + *
    
    +   *   .rootOfTheIncludedContent svg {
    +   *     overflow: hidden !important;
    +   *   }
    +   *   
    + *
    + * + * @param {boolean=} regexp New regexp to whitelist urls with. + * @returns {boolean|ng.$sanitizeProvider} Returns the currently configured value if called + * without an argument or self for chaining otherwise. + */ + this.enableSvg = function(enableSvg) { + if (angular.isDefined(enableSvg)) { + svgEnabled = enableSvg; + return this; + } else { + return svgEnabled; + } + }; +} + +function sanitizeText(chars) { + var buf = []; + var writer = htmlSanitizeWriter(buf, angular.noop); + writer.chars(chars); + return buf.join(''); +} + + +// Regular Expressions for parsing tags and attributes +var SURROGATE_PAIR_REGEXP = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g, + // Match everything outside of normal chars and " (quote character) + NON_ALPHANUMERIC_REGEXP = /([^\#-~ |!])/g; + + +// Good source of info about elements and attributes +// http://dev.w3.org/html5/spec/Overview.html#semantics +// http://simon.html5.org/html-elements + +// Safe Void Elements - HTML5 +// http://dev.w3.org/html5/spec/Overview.html#void-elements +var voidElements = toMap("area,br,col,hr,img,wbr"); + +// Elements that you can, intentionally, leave open (and which close themselves) +// http://dev.w3.org/html5/spec/Overview.html#optional-tags +var optionalEndTagBlockElements = toMap("colgroup,dd,dt,li,p,tbody,td,tfoot,th,thead,tr"), + optionalEndTagInlineElements = toMap("rp,rt"), + optionalEndTagElements = angular.extend({}, + optionalEndTagInlineElements, + optionalEndTagBlockElements); + +// Safe Block Elements - HTML5 +var blockElements = angular.extend({}, optionalEndTagBlockElements, toMap("address,article," + + "aside,blockquote,caption,center,del,dir,div,dl,figure,figcaption,footer,h1,h2,h3,h4,h5," + + "h6,header,hgroup,hr,ins,map,menu,nav,ol,pre,section,table,ul")); + +// Inline Elements - HTML5 +var inlineElements = angular.extend({}, optionalEndTagInlineElements, toMap("a,abbr,acronym,b," + + "bdi,bdo,big,br,cite,code,del,dfn,em,font,i,img,ins,kbd,label,map,mark,q,ruby,rp,rt,s," + + "samp,small,span,strike,strong,sub,sup,time,tt,u,var")); + +// SVG Elements +// https://wiki.whatwg.org/wiki/Sanitization_rules#svg_Elements +// Note: the elements animate,animateColor,animateMotion,animateTransform,set are intentionally omitted. +// They can potentially allow for arbitrary javascript to be executed. See #11290 +var svgElements = toMap("circle,defs,desc,ellipse,font-face,font-face-name,font-face-src,g,glyph," + + "hkern,image,linearGradient,line,marker,metadata,missing-glyph,mpath,path,polygon,polyline," + + "radialGradient,rect,stop,svg,switch,text,title,tspan"); + +// Blocked Elements (will be stripped) +var blockedElements = toMap("script,style"); + +var validElements = angular.extend({}, + voidElements, + blockElements, + inlineElements, + optionalEndTagElements); + +//Attributes that have href and hence need to be sanitized +var uriAttrs = toMap("background,cite,href,longdesc,src,xlink:href"); + +var htmlAttrs = toMap('abbr,align,alt,axis,bgcolor,border,cellpadding,cellspacing,class,clear,' + + 'color,cols,colspan,compact,coords,dir,face,headers,height,hreflang,hspace,' + + 'ismap,lang,language,nohref,nowrap,rel,rev,rows,rowspan,rules,' + + 'scope,scrolling,shape,size,span,start,summary,tabindex,target,title,type,' + + 'valign,value,vspace,width'); + +// SVG attributes (without "id" and "name" attributes) +// https://wiki.whatwg.org/wiki/Sanitization_rules#svg_Attributes +var svgAttrs = toMap('accent-height,accumulate,additive,alphabetic,arabic-form,ascent,' + + 'baseProfile,bbox,begin,by,calcMode,cap-height,class,color,color-rendering,content,' + + 'cx,cy,d,dx,dy,descent,display,dur,end,fill,fill-rule,font-family,font-size,font-stretch,' + + 'font-style,font-variant,font-weight,from,fx,fy,g1,g2,glyph-name,gradientUnits,hanging,' + + 'height,horiz-adv-x,horiz-origin-x,ideographic,k,keyPoints,keySplines,keyTimes,lang,' + + 'marker-end,marker-mid,marker-start,markerHeight,markerUnits,markerWidth,mathematical,' + + 'max,min,offset,opacity,orient,origin,overline-position,overline-thickness,panose-1,' + + 'path,pathLength,points,preserveAspectRatio,r,refX,refY,repeatCount,repeatDur,' + + 'requiredExtensions,requiredFeatures,restart,rotate,rx,ry,slope,stemh,stemv,stop-color,' + + 'stop-opacity,strikethrough-position,strikethrough-thickness,stroke,stroke-dasharray,' + + 'stroke-dashoffset,stroke-linecap,stroke-linejoin,stroke-miterlimit,stroke-opacity,' + + 'stroke-width,systemLanguage,target,text-anchor,to,transform,type,u1,u2,underline-position,' + + 'underline-thickness,unicode,unicode-range,units-per-em,values,version,viewBox,visibility,' + + 'width,widths,x,x-height,x1,x2,xlink:actuate,xlink:arcrole,xlink:role,xlink:show,xlink:title,' + + 'xlink:type,xml:base,xml:lang,xml:space,xmlns,xmlns:xlink,y,y1,y2,zoomAndPan', true); + +var validAttrs = angular.extend({}, + uriAttrs, + svgAttrs, + htmlAttrs); + +function toMap(str, lowercaseKeys) { + var obj = {}, items = str.split(','), i; + for (i = 0; i < items.length; i++) { + obj[lowercaseKeys ? angular.lowercase(items[i]) : items[i]] = true; + } + return obj; +} + +var inertBodyElement; +(function(window) { + var doc; + if (window.document && window.document.implementation) { + doc = window.document.implementation.createHTMLDocument("inert"); + } else { + throw $sanitizeMinErr('noinert', "Can't create an inert html document"); + } + var docElement = doc.documentElement || doc.getDocumentElement(); + var bodyElements = docElement.getElementsByTagName('body'); + + // usually there should be only one body element in the document, but IE doesn't have any, so we need to create one + if (bodyElements.length === 1) { + inertBodyElement = bodyElements[0]; + } else { + var html = doc.createElement('html'); + inertBodyElement = doc.createElement('body'); + html.appendChild(inertBodyElement); + doc.appendChild(html); + } +})(window); + +/** + * @example + * htmlParser(htmlString, { + * start: function(tag, attrs) {}, + * end: function(tag) {}, + * chars: function(text) {}, + * comment: function(text) {} + * }); + * + * @param {string} html string + * @param {object} handler + */ +function htmlParser(html, handler) { + if (html === null || html === undefined) { + html = ''; + } else if (typeof html !== 'string') { + html = '' + html; + } + inertBodyElement.innerHTML = html; + + //mXSS protection + var mXSSAttempts = 5; + do { + if (mXSSAttempts === 0) { + throw $sanitizeMinErr('uinput', "Failed to sanitize html because the input is unstable"); + } + mXSSAttempts--; + + // strip custom-namespaced attributes on IE<=11 + if (document.documentMode <= 11) { + stripCustomNsAttrs(inertBodyElement); + } + html = inertBodyElement.innerHTML; //trigger mXSS + inertBodyElement.innerHTML = html; + } while (html !== inertBodyElement.innerHTML); + + var node = inertBodyElement.firstChild; + while (node) { + switch (node.nodeType) { + case 1: // ELEMENT_NODE + handler.start(node.nodeName.toLowerCase(), attrToMap(node.attributes)); + break; + case 3: // TEXT NODE + handler.chars(node.textContent); + break; + } + + var nextNode; + if (!(nextNode = node.firstChild)) { + if (node.nodeType == 1) { + handler.end(node.nodeName.toLowerCase()); + } + nextNode = node.nextSibling; + if (!nextNode) { + while (nextNode == null) { + node = node.parentNode; + if (node === inertBodyElement) break; + nextNode = node.nextSibling; + if (node.nodeType == 1) { + handler.end(node.nodeName.toLowerCase()); + } + } + } + } + node = nextNode; + } + + while (node = inertBodyElement.firstChild) { + inertBodyElement.removeChild(node); + } +} + +function attrToMap(attrs) { + var map = {}; + for (var i = 0, ii = attrs.length; i < ii; i++) { + var attr = attrs[i]; + map[attr.name] = attr.value; + } + return map; +} + + +/** + * Escapes all potentially dangerous characters, so that the + * resulting string can be safely inserted into attribute or + * element text. + * @param value + * @returns {string} escaped text + */ +function encodeEntities(value) { + return value. + replace(/&/g, '&'). + replace(SURROGATE_PAIR_REGEXP, function(value) { + var hi = value.charCodeAt(0); + var low = value.charCodeAt(1); + return '&#' + (((hi - 0xD800) * 0x400) + (low - 0xDC00) + 0x10000) + ';'; + }). + replace(NON_ALPHANUMERIC_REGEXP, function(value) { + return '&#' + value.charCodeAt(0) + ';'; + }). + replace(//g, '>'); +} + +/** + * create an HTML/XML writer which writes to buffer + * @param {Array} buf use buf.join('') to get out sanitized html string + * @returns {object} in the form of { + * start: function(tag, attrs) {}, + * end: function(tag) {}, + * chars: function(text) {}, + * comment: function(text) {} + * } + */ +function htmlSanitizeWriter(buf, uriValidator) { + var ignoreCurrentElement = false; + var out = angular.bind(buf, buf.push); + return { + start: function(tag, attrs) { + tag = angular.lowercase(tag); + if (!ignoreCurrentElement && blockedElements[tag]) { + ignoreCurrentElement = tag; + } + if (!ignoreCurrentElement && validElements[tag] === true) { + out('<'); + out(tag); + angular.forEach(attrs, function(value, key) { + var lkey=angular.lowercase(key); + var isImage = (tag === 'img' && lkey === 'src') || (lkey === 'background'); + if (validAttrs[lkey] === true && + (uriAttrs[lkey] !== true || uriValidator(value, isImage))) { + out(' '); + out(key); + out('="'); + out(encodeEntities(value)); + out('"'); + } + }); + out('>'); + } + }, + end: function(tag) { + tag = angular.lowercase(tag); + if (!ignoreCurrentElement && validElements[tag] === true && voidElements[tag] !== true) { + out(''); + } + if (tag == ignoreCurrentElement) { + ignoreCurrentElement = false; + } + }, + chars: function(chars) { + if (!ignoreCurrentElement) { + out(encodeEntities(chars)); + } + } + }; +} + + +/** + * When IE9-11 comes across an unknown namespaced attribute e.g. 'xlink:foo' it adds 'xmlns:ns1' attribute to declare + * ns1 namespace and prefixes the attribute with 'ns1' (e.g. 'ns1:xlink:foo'). This is undesirable since we don't want + * to allow any of these custom attributes. This method strips them all. + * + * @param node Root element to process + */ +function stripCustomNsAttrs(node) { + if (node.nodeType === Node.ELEMENT_NODE) { + var attrs = node.attributes; + for (var i = 0, l = attrs.length; i < l; i++) { + var attrNode = attrs[i]; + var attrName = attrNode.name.toLowerCase(); + if (attrName === 'xmlns:ns1' || attrName.indexOf('ns1:') === 0) { + node.removeAttributeNode(attrNode); + i--; + l--; + } + } + } + + var nextNode = node.firstChild; + if (nextNode) { + stripCustomNsAttrs(nextNode); + } + + nextNode = node.nextSibling; + if (nextNode) { + stripCustomNsAttrs(nextNode); + } +} + + + +// define ngSanitize module and register $sanitize service +angular.module('ngSanitize', []).provider('$sanitize', $SanitizeProvider); + +/* global sanitizeText: false */ + +/** + * @ngdoc filter + * @name linky + * @kind function + * + * @description + * Finds links in text input and turns them into html links. Supports `http/https/ftp/mailto` and + * plain email address links. + * + * Requires the {@link ngSanitize `ngSanitize`} module to be installed. + * + * @param {string} text Input text. + * @param {string} target Window (`_blank|_self|_parent|_top`) or named frame to open links in. + * @param {object|function(url)} [attributes] Add custom attributes to the link element. + * + * Can be one of: + * + * - `object`: A map of attributes + * - `function`: Takes the url as a parameter and returns a map of attributes + * + * If the map of attributes contains a value for `target`, it overrides the value of + * the target parameter. + * + * + * @returns {string} Html-linkified and {@link $sanitize sanitized} text. + * + * @usage + + * + * @example + + +
    + Snippet: + + + + + + + + + + + + + + + + + + + + + + + + + + +
    FilterSourceRendered
    linky filter +
    <div ng-bind-html="snippet | linky">
    </div>
    +
    +
    +
    linky target +
    <div ng-bind-html="snippetWithSingleURL | linky:'_blank'">
    </div>
    +
    +
    +
    linky custom attributes +
    <div ng-bind-html="snippetWithSingleURL | linky:'_self':{rel: 'nofollow'}">
    </div>
    +
    +
    +
    no filter
    <div ng-bind="snippet">
    </div>
    + + + angular.module('linkyExample', ['ngSanitize']) + .controller('ExampleController', ['$scope', function($scope) { + $scope.snippet = + 'Pretty text with some links:\n'+ + 'http://angularjs.org/,\n'+ + 'mailto:us@somewhere.org,\n'+ + 'another@somewhere.org,\n'+ + 'and one more: ftp://127.0.0.1/.'; + $scope.snippetWithSingleURL = 'http://angularjs.org/'; + }]); + + + it('should linkify the snippet with urls', function() { + expect(element(by.id('linky-filter')).element(by.binding('snippet | linky')).getText()). + toBe('Pretty text with some links: http://angularjs.org/, us@somewhere.org, ' + + 'another@somewhere.org, and one more: ftp://127.0.0.1/.'); + expect(element.all(by.css('#linky-filter a')).count()).toEqual(4); + }); + + it('should not linkify snippet without the linky filter', function() { + expect(element(by.id('escaped-html')).element(by.binding('snippet')).getText()). + toBe('Pretty text with some links: http://angularjs.org/, mailto:us@somewhere.org, ' + + 'another@somewhere.org, and one more: ftp://127.0.0.1/.'); + expect(element.all(by.css('#escaped-html a')).count()).toEqual(0); + }); + + it('should update', function() { + element(by.model('snippet')).clear(); + element(by.model('snippet')).sendKeys('new http://link.'); + expect(element(by.id('linky-filter')).element(by.binding('snippet | linky')).getText()). + toBe('new http://link.'); + expect(element.all(by.css('#linky-filter a')).count()).toEqual(1); + expect(element(by.id('escaped-html')).element(by.binding('snippet')).getText()) + .toBe('new http://link.'); + }); + + it('should work with the target property', function() { + expect(element(by.id('linky-target')). + element(by.binding("snippetWithSingleURL | linky:'_blank'")).getText()). + toBe('http://angularjs.org/'); + expect(element(by.css('#linky-target a')).getAttribute('target')).toEqual('_blank'); + }); + + it('should optionally add custom attributes', function() { + expect(element(by.id('linky-custom-attributes')). + element(by.binding("snippetWithSingleURL | linky:'_self':{rel: 'nofollow'}")).getText()). + toBe('http://angularjs.org/'); + expect(element(by.css('#linky-custom-attributes a')).getAttribute('rel')).toEqual('nofollow'); + }); + + + */ +angular.module('ngSanitize').filter('linky', ['$sanitize', function($sanitize) { + var LINKY_URL_REGEXP = + /((ftp|https?):\/\/|(www\.)|(mailto:)?[A-Za-z0-9._%+-]+@)\S*[^\s.;,(){}<>"\u201d\u2019]/i, + MAILTO_REGEXP = /^mailto:/i; + + var linkyMinErr = angular.$$minErr('linky'); + var isString = angular.isString; + + return function(text, target, attributes) { + if (text == null || text === '') return text; + if (!isString(text)) throw linkyMinErr('notstring', 'Expected string but received: {0}', text); + + var match; + var raw = text; + var html = []; + var url; + var i; + while ((match = raw.match(LINKY_URL_REGEXP))) { + // We can not end in these as they are sometimes found at the end of the sentence + url = match[0]; + // if we did not match ftp/http/www/mailto then assume mailto + if (!match[2] && !match[4]) { + url = (match[3] ? 'http://' : 'mailto:') + url; + } + i = match.index; + addText(raw.substr(0, i)); + addLink(url, match[0].replace(MAILTO_REGEXP, '')); + raw = raw.substring(i + match[0].length); + } + addText(raw); + return $sanitize(html.join('')); + + function addText(text) { + if (!text) { + return; + } + html.push(sanitizeText(text)); + } + + function addLink(url, text) { + var key; + html.push(''); + addText(text); + html.push(''); + } + }; +}]); + + +})(window, window.angular); diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-sanitize.min.js b/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-sanitize.min.js new file mode 100644 index 000000000..135d5a0e8 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-sanitize.min.js @@ -0,0 +1,15 @@ +/* + AngularJS v1.5.0 + (c) 2010-2016 Google, Inc. http://angularjs.org + License: MIT +*/ +(function(A,e,B){'use strict';function C(a){var c=[];v(c,e.noop).chars(a);return c.join("")}function h(a,c){var b={},d=a.split(","),l;for(l=0;l=document.documentMode&&n(g);a=g.innerHTML;g.innerHTML=a}while(a!==g.innerHTML);for(b=g.firstChild;b;){switch(b.nodeType){case 1:c.start(b.nodeName.toLowerCase(),E(b.attributes)); +break;case 3:c.chars(b.textContent)}var d;if(!(d=b.firstChild)&&(1==b.nodeType&&c.end(b.nodeName.toLowerCase()),d=b.nextSibling,!d))for(;null==d;){b=b.parentNode;if(b===g)break;d=b.nextSibling;1==b.nodeType&&c.end(b.nodeName.toLowerCase())}b=d}for(;b=g.firstChild;)g.removeChild(b)}function E(a){for(var c={},b=0,d=a.length;b/g,">")}function v(a,c){var b=!1,d=e.bind(a,a.push);return{start:function(a,f){a=e.lowercase(a);!b&&H[a]&&(b=a);b||!0!==t[a]||(d("<"),d(a),e.forEach(f,function(b,f){var g=e.lowercase(f),h="img"===a&&"src"===g||"background"===g;!0!==I[g]||!0===y[g]&&!c(b,h)||(d(" "),d(f),d('="'),d(x(b)),d('"'))}),d(">"))},end:function(a){a=e.lowercase(a);b||!0!==t[a]||!0===z[a]||(d(""));a== +b&&(b=!1)},chars:function(a){b||d(x(a))}}}function n(a){if(a.nodeType===Node.ELEMENT_NODE)for(var c=a.attributes,b=0,d=c.length;b"\u201d\u2019]/i,b=/^mailto:/i,d=e.$$minErr("linky"),g=e.isString;return function(f,h,m){function k(a){a&&p.push(C(a))}function q(a,b){var c;p.push("');k(b);p.push("")}if(null==f||""===f)return f;if(!g(f))throw d("notstring",f);for(var r=f,p=[],s,n;f=r.match(c);)s=f[0],f[2]||f[4]||(s=(f[3]?"http://":"mailto:")+s),n=f.index,k(r.substr(0,n)),q(s,f[0].replace(b,"")),r=r.substring(n+f[0].length);k(r);return a(p.join(""))}}])})(window,window.angular); +//# sourceMappingURL=angular-sanitize.min.js.map diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-sanitize.min.js.map b/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-sanitize.min.js.map new file mode 100644 index 000000000..7276abd2d --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-sanitize.min.js.map @@ -0,0 +1,8 @@ +{ +"version":3, +"file":"angular-sanitize.min.js", +"lineCount":14, +"mappings":"A;;;;;aAKC,SAAQ,CAACA,CAAD,CAASC,CAAT,CAAkBC,CAAlB,CAA6B,CAsMtCC,QAASA,EAAY,CAACC,CAAD,CAAQ,CAC3B,IAAIC,EAAM,EACGC,EAAAC,CAAmBF,CAAnBE,CAAwBN,CAAAO,KAAxBD,CACbH,MAAA,CAAaA,CAAb,CACA,OAAOC,EAAAI,KAAA,CAAS,EAAT,CAJoB,CAyF7BC,QAASA,EAAK,CAACC,CAAD,CAAMC,CAAN,CAAqB,CAAA,IAC7BC,EAAM,EADuB,CACnBC,EAAQH,CAAAI,MAAA,CAAU,GAAV,CADW,CACKC,CACtC,KAAKA,CAAL,CAAS,CAAT,CAAYA,CAAZ,CAAgBF,CAAAG,OAAhB,CAA8BD,CAAA,EAA9B,CACEH,CAAA,CAAID,CAAA,CAAgBX,CAAAiB,UAAA,CAAkBJ,CAAA,CAAME,CAAN,CAAlB,CAAhB,CAA8CF,CAAA,CAAME,CAAN,CAAlD,CAAA,CAA8D,CAAA,CAEhE,OAAOH,EAL0B,CA0CnCM,QAASA,EAAU,CAACC,CAAD,CAAOC,CAAP,CAAgB,CACpB,IAAb,GAAID,CAAJ,EAAqBA,CAArB,GAA8BlB,CAA9B,CACEkB,CADF,CACS,EADT,CAE2B,QAF3B,GAEW,MAAOA,EAFlB,GAGEA,CAHF,CAGS,EAHT,CAGcA,CAHd,CAKAE,EAAAC,UAAA,CAA6BH,CAG7B,KAAII,EAAe,CACnB,GAAG,CACD,GAAqB,CAArB,GAAIA,CAAJ,CACE,KAAMC,EAAA,CAAgB,QAAhB,CAAN,CAEFD,CAAA,EAG6B,GAA7B,EAAIE,QAAAC,aAAJ,EACEC,CAAA,CAAmBN,CAAnB,CAEFF,EAAA,CAAOE,CAAAC,UACPD,EAAAC,UAAA,CAA6BH,CAX5B,CAAH,MAYSA,CAZT,GAYkBE,CAAAC,UAZlB,CAeA,KADIM,CACJ,CADWP,CAAAQ,WACX,CAAOD,CAAP,CAAA,CAAa,CACX,OAAQA,CAAAE,SAAR,EACE,KAAK,CAAL,CACEV,CAAAW,MAAA,CAAcH,CAAAI,SAAAC,YAAA,EAAd,CAA2CC,CAAA,CAAUN,CAAAO,WAAV,CAA3C,CACA;KACF,MAAK,CAAL,CACEf,CAAAjB,MAAA,CAAcyB,CAAAQ,YAAd,CALJ,CASA,IAAIC,CACJ,IAAM,EAAAA,CAAA,CAAWT,CAAAC,WAAX,CAAN,GACuB,CAIhBQ,EAJDT,CAAAE,SAICO,EAHHjB,CAAAkB,IAAA,CAAYV,CAAAI,SAAAC,YAAA,EAAZ,CAGGI,CADLA,CACKA,CADMT,CAAAW,YACNF,CAAAA,CAAAA,CALP,EAMI,IAAA,CAAmB,IAAnB,EAAOA,CAAP,CAAA,CAAyB,CACvBT,CAAA,CAAOA,CAAAY,WACP,IAAIZ,CAAJ,GAAaP,CAAb,CAA+B,KAC/BgB,EAAA,CAAWT,CAAAW,YACU,EAArB,EAAIX,CAAAE,SAAJ,EACEV,CAAAkB,IAAA,CAAYV,CAAAI,SAAAC,YAAA,EAAZ,CALqB,CAU7BL,CAAA,CAAOS,CA3BI,CA8Bb,IAAA,CAAOT,CAAP,CAAcP,CAAAQ,WAAd,CAAA,CACER,CAAAoB,YAAA,CAA6Bb,CAA7B,CAxD+B,CA4DnCM,QAASA,EAAS,CAACQ,CAAD,CAAQ,CAExB,IADA,IAAIC,EAAM,EAAV,CACS5B,EAAI,CADb,CACgB6B,EAAKF,CAAA1B,OAArB,CAAmCD,CAAnC,CAAuC6B,CAAvC,CAA2C7B,CAAA,EAA3C,CAAgD,CAC9C,IAAI8B,EAAOH,CAAA,CAAM3B,CAAN,CACX4B,EAAA,CAAIE,CAAAC,KAAJ,CAAA,CAAiBD,CAAAE,MAF6B,CAIhD,MAAOJ,EANiB,CAiB1BK,QAASA,EAAc,CAACD,CAAD,CAAQ,CAC7B,MAAOA,EAAAE,QAAA,CACG,IADH,CACS,OADT,CAAAA,QAAA,CAEGC,CAFH,CAE0B,QAAQ,CAACH,CAAD,CAAQ,CAC7C,IAAII,EAAKJ,CAAAK,WAAA,CAAiB,CAAjB,CACLC,EAAAA,CAAMN,CAAAK,WAAA,CAAiB,CAAjB,CACV,OAAO,IAAP,EAAgC,IAAhC,EAAiBD,CAAjB,CAAsB,KAAtB;CAA0CE,CAA1C,CAAgD,KAAhD,EAA0D,KAA1D,EAAqE,GAHxB,CAF1C,CAAAJ,QAAA,CAOGK,CAPH,CAO4B,QAAQ,CAACP,CAAD,CAAQ,CAC/C,MAAO,IAAP,CAAcA,CAAAK,WAAA,CAAiB,CAAjB,CAAd,CAAoC,GADW,CAP5C,CAAAH,QAAA,CAUG,IAVH,CAUS,MAVT,CAAAA,QAAA,CAWG,IAXH,CAWS,MAXT,CADsB,CAyB/B5C,QAASA,EAAkB,CAACD,CAAD,CAAMmD,CAAN,CAAoB,CAC7C,IAAIC,EAAuB,CAAA,CAA3B,CACIC,EAAMzD,CAAA0D,KAAA,CAAatD,CAAb,CAAkBA,CAAAuD,KAAlB,CACV,OAAO,CACL5B,MAAOA,QAAQ,CAAC6B,CAAD,CAAMlB,CAAN,CAAa,CAC1BkB,CAAA,CAAM5D,CAAAiB,UAAA,CAAkB2C,CAAlB,CACDJ,EAAAA,CAAL,EAA6BK,CAAA,CAAgBD,CAAhB,CAA7B,GACEJ,CADF,CACyBI,CADzB,CAGKJ,EAAL,EAAoD,CAAA,CAApD,GAA6BM,CAAA,CAAcF,CAAd,CAA7B,GACEH,CAAA,CAAI,GAAJ,CAcA,CAbAA,CAAA,CAAIG,CAAJ,CAaA,CAZA5D,CAAA+D,QAAA,CAAgBrB,CAAhB,CAAuB,QAAQ,CAACK,CAAD,CAAQiB,CAAR,CAAa,CAC1C,IAAIC,EAAKjE,CAAAiB,UAAA,CAAkB+C,CAAlB,CAAT,CACIE,EAAmB,KAAnBA,GAAWN,CAAXM,EAAqC,KAArCA,GAA4BD,CAA5BC,EAAyD,YAAzDA,GAAgDD,CAC3B,EAAA,CAAzB,GAAIE,CAAA,CAAWF,CAAX,CAAJ,EACsB,CAAA,CADtB,GACGG,CAAA,CAASH,CAAT,CADH,EAC8B,CAAAV,CAAA,CAAaR,CAAb,CAAoBmB,CAApB,CAD9B,GAEET,CAAA,CAAI,GAAJ,CAIA,CAHAA,CAAA,CAAIO,CAAJ,CAGA,CAFAP,CAAA,CAAI,IAAJ,CAEA,CADAA,CAAA,CAAIT,CAAA,CAAeD,CAAf,CAAJ,CACA,CAAAU,CAAA,CAAI,GAAJ,CANF,CAH0C,CAA5C,CAYA,CAAAA,CAAA,CAAI,GAAJ,CAfF,CAL0B,CADvB,CAwBLnB,IAAKA,QAAQ,CAACsB,CAAD,CAAM,CACjBA,CAAA,CAAM5D,CAAAiB,UAAA,CAAkB2C,CAAlB,CACDJ,EAAL,EAAoD,CAAA,CAApD,GAA6BM,CAAA,CAAcF,CAAd,CAA7B,EAAkF,CAAA,CAAlF,GAA4DS,CAAA,CAAaT,CAAb,CAA5D,GACEH,CAAA,CAAI,IAAJ,CAEA,CADAA,CAAA,CAAIG,CAAJ,CACA,CAAAH,CAAA,CAAI,GAAJ,CAHF,CAKIG,EAAJ;AAAWJ,CAAX,GACEA,CADF,CACyB,CAAA,CADzB,CAPiB,CAxBd,CAmCLrD,MAAOA,QAAQ,CAACA,CAAD,CAAQ,CAChBqD,CAAL,EACEC,CAAA,CAAIT,CAAA,CAAe7C,CAAf,CAAJ,CAFmB,CAnClB,CAHsC,CAsD/CwB,QAASA,EAAkB,CAACC,CAAD,CAAO,CAChC,GAAIA,CAAAE,SAAJ,GAAsBwC,IAAAC,aAAtB,CAEE,IADA,IAAI7B,EAAQd,CAAAO,WAAZ,CACSpB,EAAI,CADb,CACgByD,EAAI9B,CAAA1B,OAApB,CAAkCD,CAAlC,CAAsCyD,CAAtC,CAAyCzD,CAAA,EAAzC,CAA8C,CAC5C,IAAI0D,EAAW/B,CAAA,CAAM3B,CAAN,CAAf,CACI2D,EAAWD,CAAA3B,KAAAb,YAAA,EACf,IAAiB,WAAjB,GAAIyC,CAAJ,EAA6D,CAA7D,GAAgCA,CAAAC,QAAA,CAAiB,MAAjB,CAAhC,CACE/C,CAAAgD,oBAAA,CAAyBH,CAAzB,CAEA,CADA1D,CAAA,EACA,CAAAyD,CAAA,EAN0C,CAYhD,CADInC,CACJ,CADeT,CAAAC,WACf,GACEF,CAAA,CAAmBU,CAAnB,CAIF,EADAA,CACA,CADWT,CAAAW,YACX,GACEZ,CAAA,CAAmBU,CAAnB,CArB8B,CAxdlC,IAAIb,EAAkBxB,CAAA6E,SAAA,CAAiB,WAAjB,CAAtB,CAkMI3B,EAAwB,iCAlM5B,CAoMEI,EAA0B,eApM5B,CA6MIe,EAAe5D,CAAA,CAAM,wBAAN,CA7MnB,CAiNIqE,EAA8BrE,CAAA,CAAM,gDAAN,CAjNlC,CAkNIsE,EAA+BtE,CAAA,CAAM,OAAN,CAlNnC,CAmNIuE,EAAyBhF,CAAAiF,OAAA,CAAe,EAAf,CACeF,CADf,CAEeD,CAFf,CAnN7B,CAwNII,EAAgBlF,CAAAiF,OAAA,CAAe,EAAf;AAAmBH,CAAnB,CAAgDrE,CAAA,CAAM,qKAAN,CAAhD,CAxNpB,CA6NI0E,EAAiBnF,CAAAiF,OAAA,CAAe,EAAf,CAAmBF,CAAnB,CAAiDtE,CAAA,CAAM,2JAAN,CAAjD,CA7NrB,CAqOI2E,EAAc3E,CAAA,CAAM,wNAAN,CArOlB;AA0OIoD,EAAkBpD,CAAA,CAAM,cAAN,CA1OtB,CA4OIqD,EAAgB9D,CAAAiF,OAAA,CAAe,EAAf,CACeZ,CADf,CAEea,CAFf,CAGeC,CAHf,CAIeH,CAJf,CA5OpB,CAmPIZ,EAAW3D,CAAA,CAAM,8CAAN,CAnPf,CAqPI4E,EAAY5E,CAAA,CAAM,kTAAN,CArPhB,CA6PI6E,EAAW7E,CAAA,CAAM,guCAAN;AAcoE,CAAA,CAdpE,CA7Pf,CA6QI0D,EAAanE,CAAAiF,OAAA,CAAe,EAAf,CACeb,CADf,CAEekB,CAFf,CAGeD,CAHf,CA7QjB,CA0RIhE,CACH,UAAQ,CAACtB,CAAD,CAAS,CAEhB,GAAIA,CAAA0B,SAAJ,EAAuB1B,CAAA0B,SAAA8D,eAAvB,CACEC,CAAA,CAAMzF,CAAA0B,SAAA8D,eAAAE,mBAAA,CAAkD,OAAlD,CADR,KAGE,MAAMjE,EAAA,CAAgB,SAAhB,CAAN,CAGF,IAAIkE,EAAeC,CADFH,CAAAI,gBACED,EADqBH,CAAAK,mBAAA,EACrBF,sBAAA,CAAgC,MAAhC,CAGS,EAA5B,GAAID,CAAA1E,OAAJ,CACEK,CADF,CACqBqE,CAAA,CAAa,CAAb,CADrB,EAGMvE,CAGJ,CAHWqE,CAAAM,cAAA,CAAkB,MAAlB,CAGX,CAFAzE,CAEA,CAFmBmE,CAAAM,cAAA,CAAkB,MAAlB,CAEnB,CADA3E,CAAA4E,YAAA,CAAiB1E,CAAjB,CACA,CAAAmE,CAAAO,YAAA,CAAgB5E,CAAhB,CANF,CAXgB,CAAjB,CAAD,CAmBGpB,CAnBH,CAyNAC,EAAAgG,OAAA,CAAe,YAAf,CAA6B,EAA7B,CAAAC,SAAA,CAA0C,WAA1C,CApXAC,QAA0B,EAAG,CAC3B,IAAIC,EAAa,CAAA,CAEjB,KAAAC,KAAA,CAAY,CAAC,eAAD,CAAkB,QAAQ,CAACC,CAAD,CAAgB,CAChDF,CAAJ,EACEnG,CAAAiF,OAAA,CAAenB,CAAf,CAA8BsB,CAA9B,CAEF,OAAO,SAAQ,CAACjE,CAAD,CAAO,CACpB,IAAIf;AAAM,EACVc,EAAA,CAAWC,CAAX,CAAiBd,CAAA,CAAmBD,CAAnB,CAAwB,QAAQ,CAACkG,CAAD,CAAMpC,CAAN,CAAe,CAC9D,MAAO,CAAC,UAAAqC,KAAA,CAAgBF,CAAA,CAAcC,CAAd,CAAmBpC,CAAnB,CAAhB,CADsD,CAA/C,CAAjB,CAGA,OAAO9D,EAAAI,KAAA,CAAS,EAAT,CALa,CAJ8B,CAA1C,CA4CZ,KAAAgG,UAAA,CAAiBC,QAAQ,CAACD,CAAD,CAAY,CACnC,MAAIxG,EAAA0G,UAAA,CAAkBF,CAAlB,CAAJ,EACEL,CACO,CADMK,CACN,CAAA,IAFT,EAISL,CAL0B,CA/CV,CAoX7B,CAmIAnG,EAAAgG,OAAA,CAAe,YAAf,CAAAW,OAAA,CAAoC,OAApC,CAA6C,CAAC,WAAD,CAAc,QAAQ,CAACC,CAAD,CAAY,CAAA,IACzEC,EACE,yFAFuE,CAGzEC,EAAgB,WAHyD,CAKzEC,EAAc/G,CAAA6E,SAAA,CAAiB,OAAjB,CAL2D,CAMzEmC,EAAWhH,CAAAgH,SAEf,OAAO,SAAQ,CAACC,CAAD,CAAOC,CAAP,CAAe/E,CAAf,CAA2B,CAwBxCgF,QAASA,EAAO,CAACF,CAAD,CAAO,CAChBA,CAAL,EAGA9F,CAAAwC,KAAA,CAAUzD,CAAA,CAAa+G,CAAb,CAAV,CAJqB,CAOvBG,QAASA,EAAO,CAACC,CAAD,CAAMJ,CAAN,CAAY,CAC1B,IAAIjD,CACJ7C,EAAAwC,KAAA,CAAU,KAAV,CACI3D,EAAAsH,WAAA,CAAmBnF,CAAnB,CAAJ,GACEA,CADF,CACeA,CAAA,CAAWkF,CAAX,CADf,CAGA,IAAIrH,CAAAuH,SAAA,CAAiBpF,CAAjB,CAAJ,CACE,IAAK6B,CAAL,GAAY7B,EAAZ,CACEhB,CAAAwC,KAAA,CAAUK,CAAV;AAAgB,IAAhB,CAAuB7B,CAAA,CAAW6B,CAAX,CAAvB,CAAyC,IAAzC,CAFJ,KAKE7B,EAAA,CAAa,EAEX,EAAAnC,CAAA0G,UAAA,CAAkBQ,CAAlB,CAAJ,EAAmC,QAAnC,EAA+C/E,EAA/C,EACEhB,CAAAwC,KAAA,CAAU,UAAV,CACUuD,CADV,CAEU,IAFV,CAIF/F,EAAAwC,KAAA,CAAU,QAAV,CACU0D,CAAApE,QAAA,CAAY,IAAZ,CAAkB,QAAlB,CADV,CAEU,IAFV,CAGAkE,EAAA,CAAQF,CAAR,CACA9F,EAAAwC,KAAA,CAAU,MAAV,CAtB0B,CA9B5B,GAAY,IAAZ,EAAIsD,CAAJ,EAA6B,EAA7B,GAAoBA,CAApB,CAAiC,MAAOA,EACxC,IAAK,CAAAD,CAAA,CAASC,CAAT,CAAL,CAAqB,KAAMF,EAAA,CAAY,WAAZ,CAA8DE,CAA9D,CAAN,CAOrB,IAJA,IAAIO,EAAMP,CAAV,CACI9F,EAAO,EADX,CAEIkG,CAFJ,CAGItG,CACJ,CAAQ0G,CAAR,CAAgBD,CAAAC,MAAA,CAAUZ,CAAV,CAAhB,CAAA,CAEEQ,CAQA,CARMI,CAAA,CAAM,CAAN,CAQN,CANKA,CAAA,CAAM,CAAN,CAML,EANkBA,CAAA,CAAM,CAAN,CAMlB,GALEJ,CAKF,EALSI,CAAA,CAAM,CAAN,CAAA,CAAW,SAAX,CAAuB,SAKhC,EAL6CJ,CAK7C,EAHAtG,CAGA,CAHI0G,CAAAC,MAGJ,CAFAP,CAAA,CAAQK,CAAAG,OAAA,CAAW,CAAX,CAAc5G,CAAd,CAAR,CAEA,CADAqG,CAAA,CAAQC,CAAR,CAAaI,CAAA,CAAM,CAAN,CAAAxE,QAAA,CAAiB6D,CAAjB,CAAgC,EAAhC,CAAb,CACA,CAAAU,CAAA,CAAMA,CAAAI,UAAA,CAAc7G,CAAd,CAAkB0G,CAAA,CAAM,CAAN,CAAAzG,OAAlB,CAERmG,EAAA,CAAQK,CAAR,CACA,OAAOZ,EAAA,CAAUzF,CAAAX,KAAA,CAAU,EAAV,CAAV,CAtBiC,CARmC,CAAlC,CAA7C,CApoBsC,CAArC,CAAD,CAusBGT,MAvsBH,CAusBWA,MAAAC,QAvsBX;", +"sources":["angular-sanitize.js"], +"names":["window","angular","undefined","sanitizeText","chars","buf","htmlSanitizeWriter","writer","noop","join","toMap","str","lowercaseKeys","obj","items","split","i","length","lowercase","htmlParser","html","handler","inertBodyElement","innerHTML","mXSSAttempts","$sanitizeMinErr","document","documentMode","stripCustomNsAttrs","node","firstChild","nodeType","start","nodeName","toLowerCase","attrToMap","attributes","textContent","nextNode","end","nextSibling","parentNode","removeChild","attrs","map","ii","attr","name","value","encodeEntities","replace","SURROGATE_PAIR_REGEXP","hi","charCodeAt","low","NON_ALPHANUMERIC_REGEXP","uriValidator","ignoreCurrentElement","out","bind","push","tag","blockedElements","validElements","forEach","key","lkey","isImage","validAttrs","uriAttrs","voidElements","Node","ELEMENT_NODE","l","attrNode","attrName","indexOf","removeAttributeNode","$$minErr","optionalEndTagBlockElements","optionalEndTagInlineElements","optionalEndTagElements","extend","blockElements","inlineElements","svgElements","htmlAttrs","svgAttrs","implementation","doc","createHTMLDocument","bodyElements","getElementsByTagName","documentElement","getDocumentElement","createElement","appendChild","module","provider","$SanitizeProvider","svgEnabled","$get","$$sanitizeUri","uri","test","enableSvg","this.enableSvg","isDefined","filter","$sanitize","LINKY_URL_REGEXP","MAILTO_REGEXP","linkyMinErr","isString","text","target","addText","addLink","url","isFunction","isObject","raw","match","index","substr","substring"] +} diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-scenario.js b/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-scenario.js new file mode 100644 index 000000000..20af805fc --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/external/angular-1.5/angular-scenario.js @@ -0,0 +1,41849 @@ +/*! + * jQuery JavaScript Library v2.1.1 + * http://jquery.com/ + * + * Includes Sizzle.js + * http://sizzlejs.com/ + * + * Copyright 2005, 2014 jQuery Foundation, Inc. and other contributors + * Released under the MIT license + * http://jquery.org/license + * + * Date: 2014-05-01T17:11Z + */ + +(function( global, factory ) {'use strict'; + + if ( typeof module === "object" && typeof module.exports === "object" ) { + // For CommonJS and CommonJS-like environments where a proper window is present, + // execute the factory and get jQuery + // For environments that do not inherently posses a window with a document + // (such as Node.js), expose a jQuery-making factory as module.exports + // This accentuates the need for the creation of a real window + // e.g. var jQuery = require("jquery")(window); + // See ticket #14549 for more info + module.exports = global.document ? + factory( global, true ) : + function( w ) { + if ( !w.document ) { + throw new Error( "jQuery requires a window with a document" ); + } + return factory( w ); + }; + } else { + factory( global ); + } + +// Pass this if window is not defined yet +}(typeof window !== "undefined" ? window : this, function( window, noGlobal ) { + +// Can't do this because several apps including ASP.NET trace +// the stack via arguments.caller.callee and Firefox dies if +// you try to trace through "use strict" call chains. (#13335) +// Support: Firefox 18+ +// + +var arr = []; + +var slice = arr.slice; + +var concat = arr.concat; + +var push = arr.push; + +var indexOf = arr.indexOf; + +var class2type = {}; + +var toString = class2type.toString; + +var hasOwn = class2type.hasOwnProperty; + +var support = {}; + + + +var + // Use the correct document accordingly with window argument (sandbox) + document = window.document, + + version = "2.1.1", + + // Define a local copy of jQuery + jQuery = function( selector, context ) { + // The jQuery object is actually just the init constructor 'enhanced' + // Need init if jQuery is called (just allow error to be thrown if not included) + return new jQuery.fn.init( selector, context ); + }, + + // Support: Android<4.1 + // Make sure we trim BOM and NBSP + rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, + + // Matches dashed string for camelizing + rmsPrefix = /^-ms-/, + rdashAlpha = /-([\da-z])/gi, + + // Used by jQuery.camelCase as callback to replace() + fcamelCase = function( all, letter ) { + return letter.toUpperCase(); + }; + +jQuery.fn = jQuery.prototype = { + // The current version of jQuery being used + jquery: version, + + constructor: jQuery, + + // Start with an empty selector + selector: "", + + // The default length of a jQuery object is 0 + length: 0, + + toArray: function() { + return slice.call( this ); + }, + + // Get the Nth element in the matched element set OR + // Get the whole matched element set as a clean array + get: function( num ) { + return num != null ? + + // Return just the one element from the set + ( num < 0 ? this[ num + this.length ] : this[ num ] ) : + + // Return all the elements in a clean array + slice.call( this ); + }, + + // Take an array of elements and push it onto the stack + // (returning the new matched element set) + pushStack: function( elems ) { + + // Build a new jQuery matched element set + var ret = jQuery.merge( this.constructor(), elems ); + + // Add the old object onto the stack (as a reference) + ret.prevObject = this; + ret.context = this.context; + + // Return the newly-formed element set + return ret; + }, + + // Execute a callback for every element in the matched set. + // (You can seed the arguments with an array of args, but this is + // only used internally.) + each: function( callback, args ) { + return jQuery.each( this, callback, args ); + }, + + map: function( callback ) { + return this.pushStack( jQuery.map(this, function( elem, i ) { + return callback.call( elem, i, elem ); + })); + }, + + slice: function() { + return this.pushStack( slice.apply( this, arguments ) ); + }, + + first: function() { + return this.eq( 0 ); + }, + + last: function() { + return this.eq( -1 ); + }, + + eq: function( i ) { + var len = this.length, + j = +i + ( i < 0 ? len : 0 ); + return this.pushStack( j >= 0 && j < len ? [ this[j] ] : [] ); + }, + + end: function() { + return this.prevObject || this.constructor(null); + }, + + // For internal use only. + // Behaves like an Array's method, not like a jQuery method. + push: push, + sort: arr.sort, + splice: arr.splice +}; + +jQuery.extend = jQuery.fn.extend = function() { + var options, name, src, copy, copyIsArray, clone, + target = arguments[0] || {}, + i = 1, + length = arguments.length, + deep = false; + + // Handle a deep copy situation + if ( typeof target === "boolean" ) { + deep = target; + + // skip the boolean and the target + target = arguments[ i ] || {}; + i++; + } + + // Handle case when target is a string or something (possible in deep copy) + if ( typeof target !== "object" && !jQuery.isFunction(target) ) { + target = {}; + } + + // extend jQuery itself if only one argument is passed + if ( i === length ) { + target = this; + i--; + } + + for ( ; i < length; i++ ) { + // Only deal with non-null/undefined values + if ( (options = arguments[ i ]) != null ) { + // Extend the base object + for ( name in options ) { + src = target[ name ]; + copy = options[ name ]; + + // Prevent never-ending loop + if ( target === copy ) { + continue; + } + + // Recurse if we're merging plain objects or arrays + if ( deep && copy && ( jQuery.isPlainObject(copy) || (copyIsArray = jQuery.isArray(copy)) ) ) { + if ( copyIsArray ) { + copyIsArray = false; + clone = src && jQuery.isArray(src) ? src : []; + + } else { + clone = src && jQuery.isPlainObject(src) ? src : {}; + } + + // Never move original objects, clone them + target[ name ] = jQuery.extend( deep, clone, copy ); + + // Don't bring in undefined values + } else if ( copy !== undefined ) { + target[ name ] = copy; + } + } + } + } + + // Return the modified object + return target; +}; + +jQuery.extend({ + // Unique for each copy of jQuery on the page + expando: "jQuery" + ( version + Math.random() ).replace( /\D/g, "" ), + + // Assume jQuery is ready without the ready module + isReady: true, + + error: function( msg ) { + throw new Error( msg ); + }, + + noop: function() {}, + + // See test/unit/core.js for details concerning isFunction. + // Since version 1.3, DOM methods and functions like alert + // aren't supported. They return false on IE (#2968). + isFunction: function( obj ) { + return jQuery.type(obj) === "function"; + }, + + isArray: Array.isArray, + + isWindow: function( obj ) { + return obj != null && obj === obj.window; + }, + + isNumeric: function( obj ) { + // parseFloat NaNs numeric-cast false positives (null|true|false|"") + // ...but misinterprets leading-number strings, particularly hex literals ("0x...") + // subtraction forces infinities to NaN + return !jQuery.isArray( obj ) && obj - parseFloat( obj ) >= 0; + }, + + isPlainObject: function( obj ) { + // Not plain objects: + // - Any object or value whose internal [[Class]] property is not "[object Object]" + // - DOM nodes + // - window + if ( jQuery.type( obj ) !== "object" || obj.nodeType || jQuery.isWindow( obj ) ) { + return false; + } + + if ( obj.constructor && + !hasOwn.call( obj.constructor.prototype, "isPrototypeOf" ) ) { + return false; + } + + // If the function hasn't returned already, we're confident that + // |obj| is a plain object, created by {} or constructed with new Object + return true; + }, + + isEmptyObject: function( obj ) { + var name; + for ( name in obj ) { + return false; + } + return true; + }, + + type: function( obj ) { + if ( obj == null ) { + return obj + ""; + } + // Support: Android < 4.0, iOS < 6 (functionish RegExp) + return typeof obj === "object" || typeof obj === "function" ? + class2type[ toString.call(obj) ] || "object" : + typeof obj; + }, + + // Evaluates a script in a global context + globalEval: function( code ) { + var script, + indirect = eval; + + code = jQuery.trim( code ); + + if ( code ) { + // If the code includes a valid, prologue position + // strict mode pragma, execute code by injecting a + // script tag into the document. + if ( code.indexOf("use strict") === 1 ) { + script = document.createElement("script"); + script.text = code; + document.head.appendChild( script ).parentNode.removeChild( script ); + } else { + // Otherwise, avoid the DOM node creation, insertion + // and removal by using an indirect global eval + indirect( code ); + } + } + }, + + // Convert dashed to camelCase; used by the css and data modules + // Microsoft forgot to hump their vendor prefix (#9572) + camelCase: function( string ) { + return string.replace( rmsPrefix, "ms-" ).replace( rdashAlpha, fcamelCase ); + }, + + nodeName: function( elem, name ) { + return elem.nodeName && elem.nodeName.toLowerCase() === name.toLowerCase(); + }, + + // args is for internal usage only + each: function( obj, callback, args ) { + var value, + i = 0, + length = obj.length, + isArray = isArraylike( obj ); + + if ( args ) { + if ( isArray ) { + for ( ; i < length; i++ ) { + value = callback.apply( obj[ i ], args ); + + if ( value === false ) { + break; + } + } + } else { + for ( i in obj ) { + value = callback.apply( obj[ i ], args ); + + if ( value === false ) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if ( isArray ) { + for ( ; i < length; i++ ) { + value = callback.call( obj[ i ], i, obj[ i ] ); + + if ( value === false ) { + break; + } + } + } else { + for ( i in obj ) { + value = callback.call( obj[ i ], i, obj[ i ] ); + + if ( value === false ) { + break; + } + } + } + } + + return obj; + }, + + // Support: Android<4.1 + trim: function( text ) { + return text == null ? + "" : + ( text + "" ).replace( rtrim, "" ); + }, + + // results is for internal usage only + makeArray: function( arr, results ) { + var ret = results || []; + + if ( arr != null ) { + if ( isArraylike( Object(arr) ) ) { + jQuery.merge( ret, + typeof arr === "string" ? + [ arr ] : arr + ); + } else { + push.call( ret, arr ); + } + } + + return ret; + }, + + inArray: function( elem, arr, i ) { + return arr == null ? -1 : indexOf.call( arr, elem, i ); + }, + + merge: function( first, second ) { + var len = +second.length, + j = 0, + i = first.length; + + for ( ; j < len; j++ ) { + first[ i++ ] = second[ j ]; + } + + first.length = i; + + return first; + }, + + grep: function( elems, callback, invert ) { + var callbackInverse, + matches = [], + i = 0, + length = elems.length, + callbackExpect = !invert; + + // Go through the array, only saving the items + // that pass the validator function + for ( ; i < length; i++ ) { + callbackInverse = !callback( elems[ i ], i ); + if ( callbackInverse !== callbackExpect ) { + matches.push( elems[ i ] ); + } + } + + return matches; + }, + + // arg is for internal usage only + map: function( elems, callback, arg ) { + var value, + i = 0, + length = elems.length, + isArray = isArraylike( elems ), + ret = []; + + // Go through the array, translating each of the items to their new values + if ( isArray ) { + for ( ; i < length; i++ ) { + value = callback( elems[ i ], i, arg ); + + if ( value != null ) { + ret.push( value ); + } + } + + // Go through every key on the object, + } else { + for ( i in elems ) { + value = callback( elems[ i ], i, arg ); + + if ( value != null ) { + ret.push( value ); + } + } + } + + // Flatten any nested arrays + return concat.apply( [], ret ); + }, + + // A global GUID counter for objects + guid: 1, + + // Bind a function to a context, optionally partially applying any + // arguments. + proxy: function( fn, context ) { + var tmp, args, proxy; + + if ( typeof context === "string" ) { + tmp = fn[ context ]; + context = fn; + fn = tmp; + } + + // Quick check to determine if target is callable, in the spec + // this throws a TypeError, but we will just return undefined. + if ( !jQuery.isFunction( fn ) ) { + return undefined; + } + + // Simulated bind + args = slice.call( arguments, 2 ); + proxy = function() { + return fn.apply( context || this, args.concat( slice.call( arguments ) ) ); + }; + + // Set the guid of unique handler to the same of original handler, so it can be removed + proxy.guid = fn.guid = fn.guid || jQuery.guid++; + + return proxy; + }, + + now: Date.now, + + // jQuery.support is not used in Core but other projects attach their + // properties to it so it needs to exist. + support: support +}); + +// Populate the class2type map +jQuery.each("Boolean Number String Function Array Date RegExp Object Error".split(" "), function(i, name) { + class2type[ "[object " + name + "]" ] = name.toLowerCase(); +}); + +function isArraylike( obj ) { + var length = obj.length, + type = jQuery.type( obj ); + + if ( type === "function" || jQuery.isWindow( obj ) ) { + return false; + } + + if ( obj.nodeType === 1 && length ) { + return true; + } + + return type === "array" || length === 0 || + typeof length === "number" && length > 0 && ( length - 1 ) in obj; +} +var Sizzle = +/*! + * Sizzle CSS Selector Engine v1.10.19 + * http://sizzlejs.com/ + * + * Copyright 2013 jQuery Foundation, Inc. and other contributors + * Released under the MIT license + * http://jquery.org/license + * + * Date: 2014-04-18 + */ +(function( window ) { + +var i, + support, + Expr, + getText, + isXML, + tokenize, + compile, + select, + outermostContext, + sortInput, + hasDuplicate, + + // Local document vars + setDocument, + document, + docElem, + documentIsHTML, + rbuggyQSA, + rbuggyMatches, + matches, + contains, + + // Instance-specific data + expando = "sizzle" + -(new Date()), + preferredDoc = window.document, + dirruns = 0, + done = 0, + classCache = createCache(), + tokenCache = createCache(), + compilerCache = createCache(), + sortOrder = function( a, b ) { + if ( a === b ) { + hasDuplicate = true; + } + return 0; + }, + + // General-purpose constants + strundefined = typeof undefined, + MAX_NEGATIVE = 1 << 31, + + // Instance methods + hasOwn = ({}).hasOwnProperty, + arr = [], + pop = arr.pop, + push_native = arr.push, + push = arr.push, + slice = arr.slice, + // Use a stripped-down indexOf if we can't use a native one + indexOf = arr.indexOf || function( elem ) { + var i = 0, + len = this.length; + for ( ; i < len; i++ ) { + if ( this[i] === elem ) { + return i; + } + } + return -1; + }, + + booleans = "checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped", + + // Regular expressions + + // Whitespace characters http://www.w3.org/TR/css3-selectors/#whitespace + whitespace = "[\\x20\\t\\r\\n\\f]", + // http://www.w3.org/TR/css3-syntax/#characters + characterEncoding = "(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+", + + // Loosely modeled on CSS identifier characters + // An unquoted value should be a CSS identifier http://www.w3.org/TR/css3-selectors/#attribute-selectors + // Proper syntax: http://www.w3.org/TR/CSS21/syndata.html#value-def-identifier + identifier = characterEncoding.replace( "w", "w#" ), + + // Attribute selectors: http://www.w3.org/TR/selectors/#attribute-selectors + attributes = "\\[" + whitespace + "*(" + characterEncoding + ")(?:" + whitespace + + // Operator (capture 2) + "*([*^$|!~]?=)" + whitespace + + // "Attribute values must be CSS identifiers [capture 5] or strings [capture 3 or capture 4]" + "*(?:'((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\"|(" + identifier + "))|)" + whitespace + + "*\\]", + + pseudos = ":(" + characterEncoding + ")(?:\\((" + + // To reduce the number of selectors needing tokenize in the preFilter, prefer arguments: + // 1. quoted (capture 3; capture 4 or capture 5) + "('((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\")|" + + // 2. simple (capture 6) + "((?:\\\\.|[^\\\\()[\\]]|" + attributes + ")*)|" + + // 3. anything else (capture 2) + ".*" + + ")\\)|)", + + // Leading and non-escaped trailing whitespace, capturing some non-whitespace characters preceding the latter + rtrim = new RegExp( "^" + whitespace + "+|((?:^|[^\\\\])(?:\\\\.)*)" + whitespace + "+$", "g" ), + + rcomma = new RegExp( "^" + whitespace + "*," + whitespace + "*" ), + rcombinators = new RegExp( "^" + whitespace + "*([>+~]|" + whitespace + ")" + whitespace + "*" ), + + rattributeQuotes = new RegExp( "=" + whitespace + "*([^\\]'\"]*?)" + whitespace + "*\\]", "g" ), + + rpseudo = new RegExp( pseudos ), + ridentifier = new RegExp( "^" + identifier + "$" ), + + matchExpr = { + "ID": new RegExp( "^#(" + characterEncoding + ")" ), + "CLASS": new RegExp( "^\\.(" + characterEncoding + ")" ), + "TAG": new RegExp( "^(" + characterEncoding.replace( "w", "w*" ) + ")" ), + "ATTR": new RegExp( "^" + attributes ), + "PSEUDO": new RegExp( "^" + pseudos ), + "CHILD": new RegExp( "^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\(" + whitespace + + "*(even|odd|(([+-]|)(\\d*)n|)" + whitespace + "*(?:([+-]|)" + whitespace + + "*(\\d+)|))" + whitespace + "*\\)|)", "i" ), + "bool": new RegExp( "^(?:" + booleans + ")$", "i" ), + // For use in libraries implementing .is() + // We use this for POS matching in `select` + "needsContext": new RegExp( "^" + whitespace + "*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\(" + + whitespace + "*((?:-\\d)?\\d*)" + whitespace + "*\\)|)(?=[^-]|$)", "i" ) + }, + + rinputs = /^(?:input|select|textarea|button)$/i, + rheader = /^h\d$/i, + + rnative = /^[^{]+\{\s*\[native \w/, + + // Easily-parseable/retrievable ID or TAG or CLASS selectors + rquickExpr = /^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/, + + rsibling = /[+~]/, + rescape = /'|\\/g, + + // CSS escapes http://www.w3.org/TR/CSS21/syndata.html#escaped-characters + runescape = new RegExp( "\\\\([\\da-f]{1,6}" + whitespace + "?|(" + whitespace + ")|.)", "ig" ), + funescape = function( _, escaped, escapedWhitespace ) { + var high = "0x" + escaped - 0x10000; + // NaN means non-codepoint + // Support: Firefox<24 + // Workaround erroneous numeric interpretation of +"0x" + return high !== high || escapedWhitespace ? + escaped : + high < 0 ? + // BMP codepoint + String.fromCharCode( high + 0x10000 ) : + // Supplemental Plane codepoint (surrogate pair) + String.fromCharCode( high >> 10 | 0xD800, high & 0x3FF | 0xDC00 ); + }; + +// Optimize for push.apply( _, NodeList ) +try { + push.apply( + (arr = slice.call( preferredDoc.childNodes )), + preferredDoc.childNodes + ); + // Support: Android<4.0 + // Detect silently failing push.apply + arr[ preferredDoc.childNodes.length ].nodeType; +} catch ( e ) { + push = { apply: arr.length ? + + // Leverage slice if possible + function( target, els ) { + push_native.apply( target, slice.call(els) ); + } : + + // Support: IE<9 + // Otherwise append directly + function( target, els ) { + var j = target.length, + i = 0; + // Can't trust NodeList.length + while ( (target[j++] = els[i++]) ) {} + target.length = j - 1; + } + }; +} + +function Sizzle( selector, context, results, seed ) { + var match, elem, m, nodeType, + // QSA vars + i, groups, old, nid, newContext, newSelector; + + if ( ( context ? context.ownerDocument || context : preferredDoc ) !== document ) { + setDocument( context ); + } + + context = context || document; + results = results || []; + + if ( !selector || typeof selector !== "string" ) { + return results; + } + + if ( (nodeType = context.nodeType) !== 1 && nodeType !== 9 ) { + return []; + } + + if ( documentIsHTML && !seed ) { + + // Shortcuts + if ( (match = rquickExpr.exec( selector )) ) { + // Speed-up: Sizzle("#ID") + if ( (m = match[1]) ) { + if ( nodeType === 9 ) { + elem = context.getElementById( m ); + // Check parentNode to catch when Blackberry 4.6 returns + // nodes that are no longer in the document (jQuery #6963) + if ( elem && elem.parentNode ) { + // Handle the case where IE, Opera, and Webkit return items + // by name instead of ID + if ( elem.id === m ) { + results.push( elem ); + return results; + } + } else { + return results; + } + } else { + // Context is not a document + if ( context.ownerDocument && (elem = context.ownerDocument.getElementById( m )) && + contains( context, elem ) && elem.id === m ) { + results.push( elem ); + return results; + } + } + + // Speed-up: Sizzle("TAG") + } else if ( match[2] ) { + push.apply( results, context.getElementsByTagName( selector ) ); + return results; + + // Speed-up: Sizzle(".CLASS") + } else if ( (m = match[3]) && support.getElementsByClassName && context.getElementsByClassName ) { + push.apply( results, context.getElementsByClassName( m ) ); + return results; + } + } + + // QSA path + if ( support.qsa && (!rbuggyQSA || !rbuggyQSA.test( selector )) ) { + nid = old = expando; + newContext = context; + newSelector = nodeType === 9 && selector; + + // qSA works strangely on Element-rooted queries + // We can work around this by specifying an extra ID on the root + // and working up from there (Thanks to Andrew Dupont for the technique) + // IE 8 doesn't work on object elements + if ( nodeType === 1 && context.nodeName.toLowerCase() !== "object" ) { + groups = tokenize( selector ); + + if ( (old = context.getAttribute("id")) ) { + nid = old.replace( rescape, "\\$&" ); + } else { + context.setAttribute( "id", nid ); + } + nid = "[id='" + nid + "'] "; + + i = groups.length; + while ( i-- ) { + groups[i] = nid + toSelector( groups[i] ); + } + newContext = rsibling.test( selector ) && testContext( context.parentNode ) || context; + newSelector = groups.join(","); + } + + if ( newSelector ) { + try { + push.apply( results, + newContext.querySelectorAll( newSelector ) + ); + return results; + } catch(qsaError) { + } finally { + if ( !old ) { + context.removeAttribute("id"); + } + } + } + } + } + + // All others + return select( selector.replace( rtrim, "$1" ), context, results, seed ); +} + +/** + * Create key-value caches of limited size + * @returns {Function(string, Object)} Returns the Object data after storing it on itself with + * property name the (space-suffixed) string and (if the cache is larger than Expr.cacheLength) + * deleting the oldest entry + */ +function createCache() { + var keys = []; + + function cache( key, value ) { + // Use (key + " ") to avoid collision with native prototype properties (see Issue #157) + if ( keys.push( key + " " ) > Expr.cacheLength ) { + // Only keep the most recent entries + delete cache[ keys.shift() ]; + } + return (cache[ key + " " ] = value); + } + return cache; +} + +/** + * Mark a function for special use by Sizzle + * @param {Function} fn The function to mark + */ +function markFunction( fn ) { + fn[ expando ] = true; + return fn; +} + +/** + * Support testing using an element + * @param {Function} fn Passed the created div and expects a boolean result + */ +function assert( fn ) { + var div = document.createElement("div"); + + try { + return !!fn( div ); + } catch (e) { + return false; + } finally { + // Remove from its parent by default + if ( div.parentNode ) { + div.parentNode.removeChild( div ); + } + // release memory in IE + div = null; + } +} + +/** + * Adds the same handler for all of the specified attrs + * @param {String} attrs Pipe-separated list of attributes + * @param {Function} handler The method that will be applied + */ +function addHandle( attrs, handler ) { + var arr = attrs.split("|"), + i = attrs.length; + + while ( i-- ) { + Expr.attrHandle[ arr[i] ] = handler; + } +} + +/** + * Checks document order of two siblings + * @param {Element} a + * @param {Element} b + * @returns {Number} Returns less than 0 if a precedes b, greater than 0 if a follows b + */ +function siblingCheck( a, b ) { + var cur = b && a, + diff = cur && a.nodeType === 1 && b.nodeType === 1 && + ( ~b.sourceIndex || MAX_NEGATIVE ) - + ( ~a.sourceIndex || MAX_NEGATIVE ); + + // Use IE sourceIndex if available on both nodes + if ( diff ) { + return diff; + } + + // Check if b follows a + if ( cur ) { + while ( (cur = cur.nextSibling) ) { + if ( cur === b ) { + return -1; + } + } + } + + return a ? 1 : -1; +} + +/** + * Returns a function to use in pseudos for input types + * @param {String} type + */ +function createInputPseudo( type ) { + return function( elem ) { + var name = elem.nodeName.toLowerCase(); + return name === "input" && elem.type === type; + }; +} + +/** + * Returns a function to use in pseudos for buttons + * @param {String} type + */ +function createButtonPseudo( type ) { + return function( elem ) { + var name = elem.nodeName.toLowerCase(); + return (name === "input" || name === "button") && elem.type === type; + }; +} + +/** + * Returns a function to use in pseudos for positionals + * @param {Function} fn + */ +function createPositionalPseudo( fn ) { + return markFunction(function( argument ) { + argument = +argument; + return markFunction(function( seed, matches ) { + var j, + matchIndexes = fn( [], seed.length, argument ), + i = matchIndexes.length; + + // Match elements found at the specified indexes + while ( i-- ) { + if ( seed[ (j = matchIndexes[i]) ] ) { + seed[j] = !(matches[j] = seed[j]); + } + } + }); + }); +} + +/** + * Checks a node for validity as a Sizzle context + * @param {Element|Object=} context + * @returns {Element|Object|Boolean} The input node if acceptable, otherwise a falsy value + */ +function testContext( context ) { + return context && typeof context.getElementsByTagName !== strundefined && context; +} + +// Expose support vars for convenience +support = Sizzle.support = {}; + +/** + * Detects XML nodes + * @param {Element|Object} elem An element or a document + * @returns {Boolean} True iff elem is a non-HTML XML node + */ +isXML = Sizzle.isXML = function( elem ) { + // documentElement is verified for cases where it doesn't yet exist + // (such as loading iframes in IE - #4833) + var documentElement = elem && (elem.ownerDocument || elem).documentElement; + return documentElement ? documentElement.nodeName !== "HTML" : false; +}; + +/** + * Sets document-related variables once based on the current document + * @param {Element|Object} [doc] An element or document object to use to set the document + * @returns {Object} Returns the current document + */ +setDocument = Sizzle.setDocument = function( node ) { + var hasCompare, + doc = node ? node.ownerDocument || node : preferredDoc, + parent = doc.defaultView; + + // If no document and documentElement is available, return + if ( doc === document || doc.nodeType !== 9 || !doc.documentElement ) { + return document; + } + + // Set our document + document = doc; + docElem = doc.documentElement; + + // Support tests + documentIsHTML = !isXML( doc ); + + // Support: IE>8 + // If iframe document is assigned to "document" variable and if iframe has been reloaded, + // IE will throw "permission denied" error when accessing "document" variable, see jQuery #13936 + // IE6-8 do not support the defaultView property so parent will be undefined + if ( parent && parent !== parent.top ) { + // IE11 does not have attachEvent, so all must suffer + if ( parent.addEventListener ) { + parent.addEventListener( "unload", function() { + setDocument(); + }, false ); + } else if ( parent.attachEvent ) { + parent.attachEvent( "onunload", function() { + setDocument(); + }); + } + } + + /* Attributes + ---------------------------------------------------------------------- */ + + // Support: IE<8 + // Verify that getAttribute really returns attributes and not properties (excepting IE8 booleans) + support.attributes = assert(function( div ) { + div.className = "i"; + return !div.getAttribute("className"); + }); + + /* getElement(s)By* + ---------------------------------------------------------------------- */ + + // Check if getElementsByTagName("*") returns only elements + support.getElementsByTagName = assert(function( div ) { + div.appendChild( doc.createComment("") ); + return !div.getElementsByTagName("*").length; + }); + + // Check if getElementsByClassName can be trusted + support.getElementsByClassName = rnative.test( doc.getElementsByClassName ) && assert(function( div ) { + div.innerHTML = "
    "; + + // Support: Safari<4 + // Catch class over-caching + div.firstChild.className = "i"; + // Support: Opera<10 + // Catch gEBCN failure to find non-leading classes + return div.getElementsByClassName("i").length === 2; + }); + + // Support: IE<10 + // Check if getElementById returns elements by name + // The broken getElementById methods don't pick up programatically-set names, + // so use a roundabout getElementsByName test + support.getById = assert(function( div ) { + docElem.appendChild( div ).id = expando; + return !doc.getElementsByName || !doc.getElementsByName( expando ).length; + }); + + // ID find and filter + if ( support.getById ) { + Expr.find["ID"] = function( id, context ) { + if ( typeof context.getElementById !== strundefined && documentIsHTML ) { + var m = context.getElementById( id ); + // Check parentNode to catch when Blackberry 4.6 returns + // nodes that are no longer in the document #6963 + return m && m.parentNode ? [ m ] : []; + } + }; + Expr.filter["ID"] = function( id ) { + var attrId = id.replace( runescape, funescape ); + return function( elem ) { + return elem.getAttribute("id") === attrId; + }; + }; + } else { + // Support: IE6/7 + // getElementById is not reliable as a find shortcut + delete Expr.find["ID"]; + + Expr.filter["ID"] = function( id ) { + var attrId = id.replace( runescape, funescape ); + return function( elem ) { + var node = typeof elem.getAttributeNode !== strundefined && elem.getAttributeNode("id"); + return node && node.value === attrId; + }; + }; + } + + // Tag + Expr.find["TAG"] = support.getElementsByTagName ? + function( tag, context ) { + if ( typeof context.getElementsByTagName !== strundefined ) { + return context.getElementsByTagName( tag ); + } + } : + function( tag, context ) { + var elem, + tmp = [], + i = 0, + results = context.getElementsByTagName( tag ); + + // Filter out possible comments + if ( tag === "*" ) { + while ( (elem = results[i++]) ) { + if ( elem.nodeType === 1 ) { + tmp.push( elem ); + } + } + + return tmp; + } + return results; + }; + + // Class + Expr.find["CLASS"] = support.getElementsByClassName && function( className, context ) { + if ( typeof context.getElementsByClassName !== strundefined && documentIsHTML ) { + return context.getElementsByClassName( className ); + } + }; + + /* QSA/matchesSelector + ---------------------------------------------------------------------- */ + + // QSA and matchesSelector support + + // matchesSelector(:active) reports false when true (IE9/Opera 11.5) + rbuggyMatches = []; + + // qSa(:focus) reports false when true (Chrome 21) + // We allow this because of a bug in IE8/9 that throws an error + // whenever `document.activeElement` is accessed on an iframe + // So, we allow :focus to pass through QSA all the time to avoid the IE error + // See http://bugs.jquery.com/ticket/13378 + rbuggyQSA = []; + + if ( (support.qsa = rnative.test( doc.querySelectorAll )) ) { + // Build QSA regex + // Regex strategy adopted from Diego Perini + assert(function( div ) { + // Select is set to empty string on purpose + // This is to test IE's treatment of not explicitly + // setting a boolean content attribute, + // since its presence should be enough + // http://bugs.jquery.com/ticket/12359 + div.innerHTML = ""; + + // Support: IE8, Opera 11-12.16 + // Nothing should be selected when empty strings follow ^= or $= or *= + // The test attribute must be unknown in Opera but "safe" for WinRT + // http://msdn.microsoft.com/en-us/library/ie/hh465388.aspx#attribute_section + if ( div.querySelectorAll("[msallowclip^='']").length ) { + rbuggyQSA.push( "[*^$]=" + whitespace + "*(?:''|\"\")" ); + } + + // Support: IE8 + // Boolean attributes and "value" are not treated correctly + if ( !div.querySelectorAll("[selected]").length ) { + rbuggyQSA.push( "\\[" + whitespace + "*(?:value|" + booleans + ")" ); + } + + // Webkit/Opera - :checked should return selected option elements + // http://www.w3.org/TR/2011/REC-css3-selectors-20110929/#checked + // IE8 throws error here and will not see later tests + if ( !div.querySelectorAll(":checked").length ) { + rbuggyQSA.push(":checked"); + } + }); + + assert(function( div ) { + // Support: Windows 8 Native Apps + // The type and name attributes are restricted during .innerHTML assignment + var input = doc.createElement("input"); + input.setAttribute( "type", "hidden" ); + div.appendChild( input ).setAttribute( "name", "D" ); + + // Support: IE8 + // Enforce case-sensitivity of name attribute + if ( div.querySelectorAll("[name=d]").length ) { + rbuggyQSA.push( "name" + whitespace + "*[*^$|!~]?=" ); + } + + // FF 3.5 - :enabled/:disabled and hidden elements (hidden elements are still enabled) + // IE8 throws error here and will not see later tests + if ( !div.querySelectorAll(":enabled").length ) { + rbuggyQSA.push( ":enabled", ":disabled" ); + } + + // Opera 10-11 does not throw on post-comma invalid pseudos + div.querySelectorAll("*,:x"); + rbuggyQSA.push(",.*:"); + }); + } + + if ( (support.matchesSelector = rnative.test( (matches = docElem.matches || + docElem.webkitMatchesSelector || + docElem.mozMatchesSelector || + docElem.oMatchesSelector || + docElem.msMatchesSelector) )) ) { + + assert(function( div ) { + // Check to see if it's possible to do matchesSelector + // on a disconnected node (IE 9) + support.disconnectedMatch = matches.call( div, "div" ); + + // This should fail with an exception + // Gecko does not error, returns false instead + matches.call( div, "[s!='']:x" ); + rbuggyMatches.push( "!=", pseudos ); + }); + } + + rbuggyQSA = rbuggyQSA.length && new RegExp( rbuggyQSA.join("|") ); + rbuggyMatches = rbuggyMatches.length && new RegExp( rbuggyMatches.join("|") ); + + /* Contains + ---------------------------------------------------------------------- */ + hasCompare = rnative.test( docElem.compareDocumentPosition ); + + // Element contains another + // Purposefully does not implement inclusive descendent + // As in, an element does not contain itself + contains = hasCompare || rnative.test( docElem.contains ) ? + function( a, b ) { + var adown = a.nodeType === 9 ? a.documentElement : a, + bup = b && b.parentNode; + return a === bup || !!( bup && bup.nodeType === 1 && ( + adown.contains ? + adown.contains( bup ) : + a.compareDocumentPosition && a.compareDocumentPosition( bup ) & 16 + )); + } : + function( a, b ) { + if ( b ) { + while ( (b = b.parentNode) ) { + if ( b === a ) { + return true; + } + } + } + return false; + }; + + /* Sorting + ---------------------------------------------------------------------- */ + + // Document order sorting + sortOrder = hasCompare ? + function( a, b ) { + + // Flag for duplicate removal + if ( a === b ) { + hasDuplicate = true; + return 0; + } + + // Sort on method existence if only one input has compareDocumentPosition + var compare = !a.compareDocumentPosition - !b.compareDocumentPosition; + if ( compare ) { + return compare; + } + + // Calculate position if both inputs belong to the same document + compare = ( a.ownerDocument || a ) === ( b.ownerDocument || b ) ? + a.compareDocumentPosition( b ) : + + // Otherwise we know they are disconnected + 1; + + // Disconnected nodes + if ( compare & 1 || + (!support.sortDetached && b.compareDocumentPosition( a ) === compare) ) { + + // Choose the first element that is related to our preferred document + if ( a === doc || a.ownerDocument === preferredDoc && contains(preferredDoc, a) ) { + return -1; + } + if ( b === doc || b.ownerDocument === preferredDoc && contains(preferredDoc, b) ) { + return 1; + } + + // Maintain original order + return sortInput ? + ( indexOf.call( sortInput, a ) - indexOf.call( sortInput, b ) ) : + 0; + } + + return compare & 4 ? -1 : 1; + } : + function( a, b ) { + // Exit early if the nodes are identical + if ( a === b ) { + hasDuplicate = true; + return 0; + } + + var cur, + i = 0, + aup = a.parentNode, + bup = b.parentNode, + ap = [ a ], + bp = [ b ]; + + // Parentless nodes are either documents or disconnected + if ( !aup || !bup ) { + return a === doc ? -1 : + b === doc ? 1 : + aup ? -1 : + bup ? 1 : + sortInput ? + ( indexOf.call( sortInput, a ) - indexOf.call( sortInput, b ) ) : + 0; + + // If the nodes are siblings, we can do a quick check + } else if ( aup === bup ) { + return siblingCheck( a, b ); + } + + // Otherwise we need full lists of their ancestors for comparison + cur = a; + while ( (cur = cur.parentNode) ) { + ap.unshift( cur ); + } + cur = b; + while ( (cur = cur.parentNode) ) { + bp.unshift( cur ); + } + + // Walk down the tree looking for a discrepancy + while ( ap[i] === bp[i] ) { + i++; + } + + return i ? + // Do a sibling check if the nodes have a common ancestor + siblingCheck( ap[i], bp[i] ) : + + // Otherwise nodes in our document sort first + ap[i] === preferredDoc ? -1 : + bp[i] === preferredDoc ? 1 : + 0; + }; + + return doc; +}; + +Sizzle.matches = function( expr, elements ) { + return Sizzle( expr, null, null, elements ); +}; + +Sizzle.matchesSelector = function( elem, expr ) { + // Set document vars if needed + if ( ( elem.ownerDocument || elem ) !== document ) { + setDocument( elem ); + } + + // Make sure that attribute selectors are quoted + expr = expr.replace( rattributeQuotes, "='$1']" ); + + if ( support.matchesSelector && documentIsHTML && + ( !rbuggyMatches || !rbuggyMatches.test( expr ) ) && + ( !rbuggyQSA || !rbuggyQSA.test( expr ) ) ) { + + try { + var ret = matches.call( elem, expr ); + + // IE 9's matchesSelector returns false on disconnected nodes + if ( ret || support.disconnectedMatch || + // As well, disconnected nodes are said to be in a document + // fragment in IE 9 + elem.document && elem.document.nodeType !== 11 ) { + return ret; + } + } catch(e) {} + } + + return Sizzle( expr, document, null, [ elem ] ).length > 0; +}; + +Sizzle.contains = function( context, elem ) { + // Set document vars if needed + if ( ( context.ownerDocument || context ) !== document ) { + setDocument( context ); + } + return contains( context, elem ); +}; + +Sizzle.attr = function( elem, name ) { + // Set document vars if needed + if ( ( elem.ownerDocument || elem ) !== document ) { + setDocument( elem ); + } + + var fn = Expr.attrHandle[ name.toLowerCase() ], + // Don't get fooled by Object.prototype properties (jQuery #13807) + val = fn && hasOwn.call( Expr.attrHandle, name.toLowerCase() ) ? + fn( elem, name, !documentIsHTML ) : + undefined; + + return val !== undefined ? + val : + support.attributes || !documentIsHTML ? + elem.getAttribute( name ) : + (val = elem.getAttributeNode(name)) && val.specified ? + val.value : + null; +}; + +Sizzle.error = function( msg ) { + throw new Error( "Syntax error, unrecognized expression: " + msg ); +}; + +/** + * Document sorting and removing duplicates + * @param {ArrayLike} results + */ +Sizzle.uniqueSort = function( results ) { + var elem, + duplicates = [], + j = 0, + i = 0; + + // Unless we *know* we can detect duplicates, assume their presence + hasDuplicate = !support.detectDuplicates; + sortInput = !support.sortStable && results.slice( 0 ); + results.sort( sortOrder ); + + if ( hasDuplicate ) { + while ( (elem = results[i++]) ) { + if ( elem === results[ i ] ) { + j = duplicates.push( i ); + } + } + while ( j-- ) { + results.splice( duplicates[ j ], 1 ); + } + } + + // Clear input after sorting to release objects + // See https://github.com/jquery/sizzle/pull/225 + sortInput = null; + + return results; +}; + +/** + * Utility function for retrieving the text value of an array of DOM nodes + * @param {Array|Element} elem + */ +getText = Sizzle.getText = function( elem ) { + var node, + ret = "", + i = 0, + nodeType = elem.nodeType; + + if ( !nodeType ) { + // If no nodeType, this is expected to be an array + while ( (node = elem[i++]) ) { + // Do not traverse comment nodes + ret += getText( node ); + } + } else if ( nodeType === 1 || nodeType === 9 || nodeType === 11 ) { + // Use textContent for elements + // innerText usage removed for consistency of new lines (jQuery #11153) + if ( typeof elem.textContent === "string" ) { + return elem.textContent; + } else { + // Traverse its children + for ( elem = elem.firstChild; elem; elem = elem.nextSibling ) { + ret += getText( elem ); + } + } + } else if ( nodeType === 3 || nodeType === 4 ) { + return elem.nodeValue; + } + // Do not include comment or processing instruction nodes + + return ret; +}; + +Expr = Sizzle.selectors = { + + // Can be adjusted by the user + cacheLength: 50, + + createPseudo: markFunction, + + match: matchExpr, + + attrHandle: {}, + + find: {}, + + relative: { + ">": { dir: "parentNode", first: true }, + " ": { dir: "parentNode" }, + "+": { dir: "previousSibling", first: true }, + "~": { dir: "previousSibling" } + }, + + preFilter: { + "ATTR": function( match ) { + match[1] = match[1].replace( runescape, funescape ); + + // Move the given value to match[3] whether quoted or unquoted + match[3] = ( match[3] || match[4] || match[5] || "" ).replace( runescape, funescape ); + + if ( match[2] === "~=" ) { + match[3] = " " + match[3] + " "; + } + + return match.slice( 0, 4 ); + }, + + "CHILD": function( match ) { + /* matches from matchExpr["CHILD"] + 1 type (only|nth|...) + 2 what (child|of-type) + 3 argument (even|odd|\d*|\d*n([+-]\d+)?|...) + 4 xn-component of xn+y argument ([+-]?\d*n|) + 5 sign of xn-component + 6 x of xn-component + 7 sign of y-component + 8 y of y-component + */ + match[1] = match[1].toLowerCase(); + + if ( match[1].slice( 0, 3 ) === "nth" ) { + // nth-* requires argument + if ( !match[3] ) { + Sizzle.error( match[0] ); + } + + // numeric x and y parameters for Expr.filter.CHILD + // remember that false/true cast respectively to 0/1 + match[4] = +( match[4] ? match[5] + (match[6] || 1) : 2 * ( match[3] === "even" || match[3] === "odd" ) ); + match[5] = +( ( match[7] + match[8] ) || match[3] === "odd" ); + + // other types prohibit arguments + } else if ( match[3] ) { + Sizzle.error( match[0] ); + } + + return match; + }, + + "PSEUDO": function( match ) { + var excess, + unquoted = !match[6] && match[2]; + + if ( matchExpr["CHILD"].test( match[0] ) ) { + return null; + } + + // Accept quoted arguments as-is + if ( match[3] ) { + match[2] = match[4] || match[5] || ""; + + // Strip excess characters from unquoted arguments + } else if ( unquoted && rpseudo.test( unquoted ) && + // Get excess from tokenize (recursively) + (excess = tokenize( unquoted, true )) && + // advance to the next closing parenthesis + (excess = unquoted.indexOf( ")", unquoted.length - excess ) - unquoted.length) ) { + + // excess is a negative index + match[0] = match[0].slice( 0, excess ); + match[2] = unquoted.slice( 0, excess ); + } + + // Return only captures needed by the pseudo filter method (type and argument) + return match.slice( 0, 3 ); + } + }, + + filter: { + + "TAG": function( nodeNameSelector ) { + var nodeName = nodeNameSelector.replace( runescape, funescape ).toLowerCase(); + return nodeNameSelector === "*" ? + function() { return true; } : + function( elem ) { + return elem.nodeName && elem.nodeName.toLowerCase() === nodeName; + }; + }, + + "CLASS": function( className ) { + var pattern = classCache[ className + " " ]; + + return pattern || + (pattern = new RegExp( "(^|" + whitespace + ")" + className + "(" + whitespace + "|$)" )) && + classCache( className, function( elem ) { + return pattern.test( typeof elem.className === "string" && elem.className || typeof elem.getAttribute !== strundefined && elem.getAttribute("class") || "" ); + }); + }, + + "ATTR": function( name, operator, check ) { + return function( elem ) { + var result = Sizzle.attr( elem, name ); + + if ( result == null ) { + return operator === "!="; + } + if ( !operator ) { + return true; + } + + result += ""; + + return operator === "=" ? result === check : + operator === "!=" ? result !== check : + operator === "^=" ? check && result.indexOf( check ) === 0 : + operator === "*=" ? check && result.indexOf( check ) > -1 : + operator === "$=" ? check && result.slice( -check.length ) === check : + operator === "~=" ? ( " " + result + " " ).indexOf( check ) > -1 : + operator === "|=" ? result === check || result.slice( 0, check.length + 1 ) === check + "-" : + false; + }; + }, + + "CHILD": function( type, what, argument, first, last ) { + var simple = type.slice( 0, 3 ) !== "nth", + forward = type.slice( -4 ) !== "last", + ofType = what === "of-type"; + + return first === 1 && last === 0 ? + + // Shortcut for :nth-*(n) + function( elem ) { + return !!elem.parentNode; + } : + + function( elem, context, xml ) { + var cache, outerCache, node, diff, nodeIndex, start, + dir = simple !== forward ? "nextSibling" : "previousSibling", + parent = elem.parentNode, + name = ofType && elem.nodeName.toLowerCase(), + useCache = !xml && !ofType; + + if ( parent ) { + + // :(first|last|only)-(child|of-type) + if ( simple ) { + while ( dir ) { + node = elem; + while ( (node = node[ dir ]) ) { + if ( ofType ? node.nodeName.toLowerCase() === name : node.nodeType === 1 ) { + return false; + } + } + // Reverse direction for :only-* (if we haven't yet done so) + start = dir = type === "only" && !start && "nextSibling"; + } + return true; + } + + start = [ forward ? parent.firstChild : parent.lastChild ]; + + // non-xml :nth-child(...) stores cache data on `parent` + if ( forward && useCache ) { + // Seek `elem` from a previously-cached index + outerCache = parent[ expando ] || (parent[ expando ] = {}); + cache = outerCache[ type ] || []; + nodeIndex = cache[0] === dirruns && cache[1]; + diff = cache[0] === dirruns && cache[2]; + node = nodeIndex && parent.childNodes[ nodeIndex ]; + + while ( (node = ++nodeIndex && node && node[ dir ] || + + // Fallback to seeking `elem` from the start + (diff = nodeIndex = 0) || start.pop()) ) { + + // When found, cache indexes on `parent` and break + if ( node.nodeType === 1 && ++diff && node === elem ) { + outerCache[ type ] = [ dirruns, nodeIndex, diff ]; + break; + } + } + + // Use previously-cached element index if available + } else if ( useCache && (cache = (elem[ expando ] || (elem[ expando ] = {}))[ type ]) && cache[0] === dirruns ) { + diff = cache[1]; + + // xml :nth-child(...) or :nth-last-child(...) or :nth(-last)?-of-type(...) + } else { + // Use the same loop as above to seek `elem` from the start + while ( (node = ++nodeIndex && node && node[ dir ] || + (diff = nodeIndex = 0) || start.pop()) ) { + + if ( ( ofType ? node.nodeName.toLowerCase() === name : node.nodeType === 1 ) && ++diff ) { + // Cache the index of each encountered element + if ( useCache ) { + (node[ expando ] || (node[ expando ] = {}))[ type ] = [ dirruns, diff ]; + } + + if ( node === elem ) { + break; + } + } + } + } + + // Incorporate the offset, then check against cycle size + diff -= last; + return diff === first || ( diff % first === 0 && diff / first >= 0 ); + } + }; + }, + + "PSEUDO": function( pseudo, argument ) { + // pseudo-class names are case-insensitive + // http://www.w3.org/TR/selectors/#pseudo-classes + // Prioritize by case sensitivity in case custom pseudos are added with uppercase letters + // Remember that setFilters inherits from pseudos + var args, + fn = Expr.pseudos[ pseudo ] || Expr.setFilters[ pseudo.toLowerCase() ] || + Sizzle.error( "unsupported pseudo: " + pseudo ); + + // The user may use createPseudo to indicate that + // arguments are needed to create the filter function + // just as Sizzle does + if ( fn[ expando ] ) { + return fn( argument ); + } + + // But maintain support for old signatures + if ( fn.length > 1 ) { + args = [ pseudo, pseudo, "", argument ]; + return Expr.setFilters.hasOwnProperty( pseudo.toLowerCase() ) ? + markFunction(function( seed, matches ) { + var idx, + matched = fn( seed, argument ), + i = matched.length; + while ( i-- ) { + idx = indexOf.call( seed, matched[i] ); + seed[ idx ] = !( matches[ idx ] = matched[i] ); + } + }) : + function( elem ) { + return fn( elem, 0, args ); + }; + } + + return fn; + } + }, + + pseudos: { + // Potentially complex pseudos + "not": markFunction(function( selector ) { + // Trim the selector passed to compile + // to avoid treating leading and trailing + // spaces as combinators + var input = [], + results = [], + matcher = compile( selector.replace( rtrim, "$1" ) ); + + return matcher[ expando ] ? + markFunction(function( seed, matches, context, xml ) { + var elem, + unmatched = matcher( seed, null, xml, [] ), + i = seed.length; + + // Match elements unmatched by `matcher` + while ( i-- ) { + if ( (elem = unmatched[i]) ) { + seed[i] = !(matches[i] = elem); + } + } + }) : + function( elem, context, xml ) { + input[0] = elem; + matcher( input, null, xml, results ); + return !results.pop(); + }; + }), + + "has": markFunction(function( selector ) { + return function( elem ) { + return Sizzle( selector, elem ).length > 0; + }; + }), + + "contains": markFunction(function( text ) { + return function( elem ) { + return ( elem.textContent || elem.innerText || getText( elem ) ).indexOf( text ) > -1; + }; + }), + + // "Whether an element is represented by a :lang() selector + // is based solely on the element's language value + // being equal to the identifier C, + // or beginning with the identifier C immediately followed by "-". + // The matching of C against the element's language value is performed case-insensitively. + // The identifier C does not have to be a valid language name." + // http://www.w3.org/TR/selectors/#lang-pseudo + "lang": markFunction( function( lang ) { + // lang value must be a valid identifier + if ( !ridentifier.test(lang || "") ) { + Sizzle.error( "unsupported lang: " + lang ); + } + lang = lang.replace( runescape, funescape ).toLowerCase(); + return function( elem ) { + var elemLang; + do { + if ( (elemLang = documentIsHTML ? + elem.lang : + elem.getAttribute("xml:lang") || elem.getAttribute("lang")) ) { + + elemLang = elemLang.toLowerCase(); + return elemLang === lang || elemLang.indexOf( lang + "-" ) === 0; + } + } while ( (elem = elem.parentNode) && elem.nodeType === 1 ); + return false; + }; + }), + + // Miscellaneous + "target": function( elem ) { + var hash = window.location && window.location.hash; + return hash && hash.slice( 1 ) === elem.id; + }, + + "root": function( elem ) { + return elem === docElem; + }, + + "focus": function( elem ) { + return elem === document.activeElement && (!document.hasFocus || document.hasFocus()) && !!(elem.type || elem.href || ~elem.tabIndex); + }, + + // Boolean properties + "enabled": function( elem ) { + return elem.disabled === false; + }, + + "disabled": function( elem ) { + return elem.disabled === true; + }, + + "checked": function( elem ) { + // In CSS3, :checked should return both checked and selected elements + // http://www.w3.org/TR/2011/REC-css3-selectors-20110929/#checked + var nodeName = elem.nodeName.toLowerCase(); + return (nodeName === "input" && !!elem.checked) || (nodeName === "option" && !!elem.selected); + }, + + "selected": function( elem ) { + // Accessing this property makes selected-by-default + // options in Safari work properly + if ( elem.parentNode ) { + elem.parentNode.selectedIndex; + } + + return elem.selected === true; + }, + + // Contents + "empty": function( elem ) { + // http://www.w3.org/TR/selectors/#empty-pseudo + // :empty is negated by element (1) or content nodes (text: 3; cdata: 4; entity ref: 5), + // but not by others (comment: 8; processing instruction: 7; etc.) + // nodeType < 6 works because attributes (2) do not appear as children + for ( elem = elem.firstChild; elem; elem = elem.nextSibling ) { + if ( elem.nodeType < 6 ) { + return false; + } + } + return true; + }, + + "parent": function( elem ) { + return !Expr.pseudos["empty"]( elem ); + }, + + // Element/input types + "header": function( elem ) { + return rheader.test( elem.nodeName ); + }, + + "input": function( elem ) { + return rinputs.test( elem.nodeName ); + }, + + "button": function( elem ) { + var name = elem.nodeName.toLowerCase(); + return name === "input" && elem.type === "button" || name === "button"; + }, + + "text": function( elem ) { + var attr; + return elem.nodeName.toLowerCase() === "input" && + elem.type === "text" && + + // Support: IE<8 + // New HTML5 attribute values (e.g., "search") appear with elem.type === "text" + ( (attr = elem.getAttribute("type")) == null || attr.toLowerCase() === "text" ); + }, + + // Position-in-collection + "first": createPositionalPseudo(function() { + return [ 0 ]; + }), + + "last": createPositionalPseudo(function( matchIndexes, length ) { + return [ length - 1 ]; + }), + + "eq": createPositionalPseudo(function( matchIndexes, length, argument ) { + return [ argument < 0 ? argument + length : argument ]; + }), + + "even": createPositionalPseudo(function( matchIndexes, length ) { + var i = 0; + for ( ; i < length; i += 2 ) { + matchIndexes.push( i ); + } + return matchIndexes; + }), + + "odd": createPositionalPseudo(function( matchIndexes, length ) { + var i = 1; + for ( ; i < length; i += 2 ) { + matchIndexes.push( i ); + } + return matchIndexes; + }), + + "lt": createPositionalPseudo(function( matchIndexes, length, argument ) { + var i = argument < 0 ? argument + length : argument; + for ( ; --i >= 0; ) { + matchIndexes.push( i ); + } + return matchIndexes; + }), + + "gt": createPositionalPseudo(function( matchIndexes, length, argument ) { + var i = argument < 0 ? argument + length : argument; + for ( ; ++i < length; ) { + matchIndexes.push( i ); + } + return matchIndexes; + }) + } +}; + +Expr.pseudos["nth"] = Expr.pseudos["eq"]; + +// Add button/input type pseudos +for ( i in { radio: true, checkbox: true, file: true, password: true, image: true } ) { + Expr.pseudos[ i ] = createInputPseudo( i ); +} +for ( i in { submit: true, reset: true } ) { + Expr.pseudos[ i ] = createButtonPseudo( i ); +} + +// Easy API for creating new setFilters +function setFilters() {} +setFilters.prototype = Expr.filters = Expr.pseudos; +Expr.setFilters = new setFilters(); + +tokenize = Sizzle.tokenize = function( selector, parseOnly ) { + var matched, match, tokens, type, + soFar, groups, preFilters, + cached = tokenCache[ selector + " " ]; + + if ( cached ) { + return parseOnly ? 0 : cached.slice( 0 ); + } + + soFar = selector; + groups = []; + preFilters = Expr.preFilter; + + while ( soFar ) { + + // Comma and first run + if ( !matched || (match = rcomma.exec( soFar )) ) { + if ( match ) { + // Don't consume trailing commas as valid + soFar = soFar.slice( match[0].length ) || soFar; + } + groups.push( (tokens = []) ); + } + + matched = false; + + // Combinators + if ( (match = rcombinators.exec( soFar )) ) { + matched = match.shift(); + tokens.push({ + value: matched, + // Cast descendant combinators to space + type: match[0].replace( rtrim, " " ) + }); + soFar = soFar.slice( matched.length ); + } + + // Filters + for ( type in Expr.filter ) { + if ( (match = matchExpr[ type ].exec( soFar )) && (!preFilters[ type ] || + (match = preFilters[ type ]( match ))) ) { + matched = match.shift(); + tokens.push({ + value: matched, + type: type, + matches: match + }); + soFar = soFar.slice( matched.length ); + } + } + + if ( !matched ) { + break; + } + } + + // Return the length of the invalid excess + // if we're just parsing + // Otherwise, throw an error or return tokens + return parseOnly ? + soFar.length : + soFar ? + Sizzle.error( selector ) : + // Cache the tokens + tokenCache( selector, groups ).slice( 0 ); +}; + +function toSelector( tokens ) { + var i = 0, + len = tokens.length, + selector = ""; + for ( ; i < len; i++ ) { + selector += tokens[i].value; + } + return selector; +} + +function addCombinator( matcher, combinator, base ) { + var dir = combinator.dir, + checkNonElements = base && dir === "parentNode", + doneName = done++; + + return combinator.first ? + // Check against closest ancestor/preceding element + function( elem, context, xml ) { + while ( (elem = elem[ dir ]) ) { + if ( elem.nodeType === 1 || checkNonElements ) { + return matcher( elem, context, xml ); + } + } + } : + + // Check against all ancestor/preceding elements + function( elem, context, xml ) { + var oldCache, outerCache, + newCache = [ dirruns, doneName ]; + + // We can't set arbitrary data on XML nodes, so they don't benefit from dir caching + if ( xml ) { + while ( (elem = elem[ dir ]) ) { + if ( elem.nodeType === 1 || checkNonElements ) { + if ( matcher( elem, context, xml ) ) { + return true; + } + } + } + } else { + while ( (elem = elem[ dir ]) ) { + if ( elem.nodeType === 1 || checkNonElements ) { + outerCache = elem[ expando ] || (elem[ expando ] = {}); + if ( (oldCache = outerCache[ dir ]) && + oldCache[ 0 ] === dirruns && oldCache[ 1 ] === doneName ) { + + // Assign to newCache so results back-propagate to previous elements + return (newCache[ 2 ] = oldCache[ 2 ]); + } else { + // Reuse newcache so results back-propagate to previous elements + outerCache[ dir ] = newCache; + + // A match means we're done; a fail means we have to keep checking + if ( (newCache[ 2 ] = matcher( elem, context, xml )) ) { + return true; + } + } + } + } + } + }; +} + +function elementMatcher( matchers ) { + return matchers.length > 1 ? + function( elem, context, xml ) { + var i = matchers.length; + while ( i-- ) { + if ( !matchers[i]( elem, context, xml ) ) { + return false; + } + } + return true; + } : + matchers[0]; +} + +function multipleContexts( selector, contexts, results ) { + var i = 0, + len = contexts.length; + for ( ; i < len; i++ ) { + Sizzle( selector, contexts[i], results ); + } + return results; +} + +function condense( unmatched, map, filter, context, xml ) { + var elem, + newUnmatched = [], + i = 0, + len = unmatched.length, + mapped = map != null; + + for ( ; i < len; i++ ) { + if ( (elem = unmatched[i]) ) { + if ( !filter || filter( elem, context, xml ) ) { + newUnmatched.push( elem ); + if ( mapped ) { + map.push( i ); + } + } + } + } + + return newUnmatched; +} + +function setMatcher( preFilter, selector, matcher, postFilter, postFinder, postSelector ) { + if ( postFilter && !postFilter[ expando ] ) { + postFilter = setMatcher( postFilter ); + } + if ( postFinder && !postFinder[ expando ] ) { + postFinder = setMatcher( postFinder, postSelector ); + } + return markFunction(function( seed, results, context, xml ) { + var temp, i, elem, + preMap = [], + postMap = [], + preexisting = results.length, + + // Get initial elements from seed or context + elems = seed || multipleContexts( selector || "*", context.nodeType ? [ context ] : context, [] ), + + // Prefilter to get matcher input, preserving a map for seed-results synchronization + matcherIn = preFilter && ( seed || !selector ) ? + condense( elems, preMap, preFilter, context, xml ) : + elems, + + matcherOut = matcher ? + // If we have a postFinder, or filtered seed, or non-seed postFilter or preexisting results, + postFinder || ( seed ? preFilter : preexisting || postFilter ) ? + + // ...intermediate processing is necessary + [] : + + // ...otherwise use results directly + results : + matcherIn; + + // Find primary matches + if ( matcher ) { + matcher( matcherIn, matcherOut, context, xml ); + } + + // Apply postFilter + if ( postFilter ) { + temp = condense( matcherOut, postMap ); + postFilter( temp, [], context, xml ); + + // Un-match failing elements by moving them back to matcherIn + i = temp.length; + while ( i-- ) { + if ( (elem = temp[i]) ) { + matcherOut[ postMap[i] ] = !(matcherIn[ postMap[i] ] = elem); + } + } + } + + if ( seed ) { + if ( postFinder || preFilter ) { + if ( postFinder ) { + // Get the final matcherOut by condensing this intermediate into postFinder contexts + temp = []; + i = matcherOut.length; + while ( i-- ) { + if ( (elem = matcherOut[i]) ) { + // Restore matcherIn since elem is not yet a final match + temp.push( (matcherIn[i] = elem) ); + } + } + postFinder( null, (matcherOut = []), temp, xml ); + } + + // Move matched elements from seed to results to keep them synchronized + i = matcherOut.length; + while ( i-- ) { + if ( (elem = matcherOut[i]) && + (temp = postFinder ? indexOf.call( seed, elem ) : preMap[i]) > -1 ) { + + seed[temp] = !(results[temp] = elem); + } + } + } + + // Add elements to results, through postFinder if defined + } else { + matcherOut = condense( + matcherOut === results ? + matcherOut.splice( preexisting, matcherOut.length ) : + matcherOut + ); + if ( postFinder ) { + postFinder( null, results, matcherOut, xml ); + } else { + push.apply( results, matcherOut ); + } + } + }); +} + +function matcherFromTokens( tokens ) { + var checkContext, matcher, j, + len = tokens.length, + leadingRelative = Expr.relative[ tokens[0].type ], + implicitRelative = leadingRelative || Expr.relative[" "], + i = leadingRelative ? 1 : 0, + + // The foundational matcher ensures that elements are reachable from top-level context(s) + matchContext = addCombinator( function( elem ) { + return elem === checkContext; + }, implicitRelative, true ), + matchAnyContext = addCombinator( function( elem ) { + return indexOf.call( checkContext, elem ) > -1; + }, implicitRelative, true ), + matchers = [ function( elem, context, xml ) { + return ( !leadingRelative && ( xml || context !== outermostContext ) ) || ( + (checkContext = context).nodeType ? + matchContext( elem, context, xml ) : + matchAnyContext( elem, context, xml ) ); + } ]; + + for ( ; i < len; i++ ) { + if ( (matcher = Expr.relative[ tokens[i].type ]) ) { + matchers = [ addCombinator(elementMatcher( matchers ), matcher) ]; + } else { + matcher = Expr.filter[ tokens[i].type ].apply( null, tokens[i].matches ); + + // Return special upon seeing a positional matcher + if ( matcher[ expando ] ) { + // Find the next relative operator (if any) for proper handling + j = ++i; + for ( ; j < len; j++ ) { + if ( Expr.relative[ tokens[j].type ] ) { + break; + } + } + return setMatcher( + i > 1 && elementMatcher( matchers ), + i > 1 && toSelector( + // If the preceding token was a descendant combinator, insert an implicit any-element `*` + tokens.slice( 0, i - 1 ).concat({ value: tokens[ i - 2 ].type === " " ? "*" : "" }) + ).replace( rtrim, "$1" ), + matcher, + i < j && matcherFromTokens( tokens.slice( i, j ) ), + j < len && matcherFromTokens( (tokens = tokens.slice( j )) ), + j < len && toSelector( tokens ) + ); + } + matchers.push( matcher ); + } + } + + return elementMatcher( matchers ); +} + +function matcherFromGroupMatchers( elementMatchers, setMatchers ) { + var bySet = setMatchers.length > 0, + byElement = elementMatchers.length > 0, + superMatcher = function( seed, context, xml, results, outermost ) { + var elem, j, matcher, + matchedCount = 0, + i = "0", + unmatched = seed && [], + setMatched = [], + contextBackup = outermostContext, + // We must always have either seed elements or outermost context + elems = seed || byElement && Expr.find["TAG"]( "*", outermost ), + // Use integer dirruns iff this is the outermost matcher + dirrunsUnique = (dirruns += contextBackup == null ? 1 : Math.random() || 0.1), + len = elems.length; + + if ( outermost ) { + outermostContext = context !== document && context; + } + + // Add elements passing elementMatchers directly to results + // Keep `i` a string if there are no elements so `matchedCount` will be "00" below + // Support: IE<9, Safari + // Tolerate NodeList properties (IE: "length"; Safari: ) matching elements by id + for ( ; i !== len && (elem = elems[i]) != null; i++ ) { + if ( byElement && elem ) { + j = 0; + while ( (matcher = elementMatchers[j++]) ) { + if ( matcher( elem, context, xml ) ) { + results.push( elem ); + break; + } + } + if ( outermost ) { + dirruns = dirrunsUnique; + } + } + + // Track unmatched elements for set filters + if ( bySet ) { + // They will have gone through all possible matchers + if ( (elem = !matcher && elem) ) { + matchedCount--; + } + + // Lengthen the array for every element, matched or not + if ( seed ) { + unmatched.push( elem ); + } + } + } + + // Apply set filters to unmatched elements + matchedCount += i; + if ( bySet && i !== matchedCount ) { + j = 0; + while ( (matcher = setMatchers[j++]) ) { + matcher( unmatched, setMatched, context, xml ); + } + + if ( seed ) { + // Reintegrate element matches to eliminate the need for sorting + if ( matchedCount > 0 ) { + while ( i-- ) { + if ( !(unmatched[i] || setMatched[i]) ) { + setMatched[i] = pop.call( results ); + } + } + } + + // Discard index placeholder values to get only actual matches + setMatched = condense( setMatched ); + } + + // Add matches to results + push.apply( results, setMatched ); + + // Seedless set matches succeeding multiple successful matchers stipulate sorting + if ( outermost && !seed && setMatched.length > 0 && + ( matchedCount + setMatchers.length ) > 1 ) { + + Sizzle.uniqueSort( results ); + } + } + + // Override manipulation of globals by nested matchers + if ( outermost ) { + dirruns = dirrunsUnique; + outermostContext = contextBackup; + } + + return unmatched; + }; + + return bySet ? + markFunction( superMatcher ) : + superMatcher; +} + +compile = Sizzle.compile = function( selector, match /* Internal Use Only */ ) { + var i, + setMatchers = [], + elementMatchers = [], + cached = compilerCache[ selector + " " ]; + + if ( !cached ) { + // Generate a function of recursive functions that can be used to check each element + if ( !match ) { + match = tokenize( selector ); + } + i = match.length; + while ( i-- ) { + cached = matcherFromTokens( match[i] ); + if ( cached[ expando ] ) { + setMatchers.push( cached ); + } else { + elementMatchers.push( cached ); + } + } + + // Cache the compiled function + cached = compilerCache( selector, matcherFromGroupMatchers( elementMatchers, setMatchers ) ); + + // Save selector and tokenization + cached.selector = selector; + } + return cached; +}; + +/** + * A low-level selection function that works with Sizzle's compiled + * selector functions + * @param {String|Function} selector A selector or a pre-compiled + * selector function built with Sizzle.compile + * @param {Element} context + * @param {Array} [results] + * @param {Array} [seed] A set of elements to match against + */ +select = Sizzle.select = function( selector, context, results, seed ) { + var i, tokens, token, type, find, + compiled = typeof selector === "function" && selector, + match = !seed && tokenize( (selector = compiled.selector || selector) ); + + results = results || []; + + // Try to minimize operations if there is no seed and only one group + if ( match.length === 1 ) { + + // Take a shortcut and set the context if the root selector is an ID + tokens = match[0] = match[0].slice( 0 ); + if ( tokens.length > 2 && (token = tokens[0]).type === "ID" && + support.getById && context.nodeType === 9 && documentIsHTML && + Expr.relative[ tokens[1].type ] ) { + + context = ( Expr.find["ID"]( token.matches[0].replace(runescape, funescape), context ) || [] )[0]; + if ( !context ) { + return results; + + // Precompiled matchers will still verify ancestry, so step up a level + } else if ( compiled ) { + context = context.parentNode; + } + + selector = selector.slice( tokens.shift().value.length ); + } + + // Fetch a seed set for right-to-left matching + i = matchExpr["needsContext"].test( selector ) ? 0 : tokens.length; + while ( i-- ) { + token = tokens[i]; + + // Abort if we hit a combinator + if ( Expr.relative[ (type = token.type) ] ) { + break; + } + if ( (find = Expr.find[ type ]) ) { + // Search, expanding context for leading sibling combinators + if ( (seed = find( + token.matches[0].replace( runescape, funescape ), + rsibling.test( tokens[0].type ) && testContext( context.parentNode ) || context + )) ) { + + // If seed is empty or no tokens remain, we can return early + tokens.splice( i, 1 ); + selector = seed.length && toSelector( tokens ); + if ( !selector ) { + push.apply( results, seed ); + return results; + } + + break; + } + } + } + } + + // Compile and execute a filtering function if one is not provided + // Provide `match` to avoid retokenization if we modified the selector above + ( compiled || compile( selector, match ) )( + seed, + context, + !documentIsHTML, + results, + rsibling.test( selector ) && testContext( context.parentNode ) || context + ); + return results; +}; + +// One-time assignments + +// Sort stability +support.sortStable = expando.split("").sort( sortOrder ).join("") === expando; + +// Support: Chrome<14 +// Always assume duplicates if they aren't passed to the comparison function +support.detectDuplicates = !!hasDuplicate; + +// Initialize against the default document +setDocument(); + +// Support: Webkit<537.32 - Safari 6.0.3/Chrome 25 (fixed in Chrome 27) +// Detached nodes confoundingly follow *each other* +support.sortDetached = assert(function( div1 ) { + // Should return 1, but returns 4 (following) + return div1.compareDocumentPosition( document.createElement("div") ) & 1; +}); + +// Support: IE<8 +// Prevent attribute/property "interpolation" +// http://msdn.microsoft.com/en-us/library/ms536429%28VS.85%29.aspx +if ( !assert(function( div ) { + div.innerHTML = ""; + return div.firstChild.getAttribute("href") === "#" ; +}) ) { + addHandle( "type|href|height|width", function( elem, name, isXML ) { + if ( !isXML ) { + return elem.getAttribute( name, name.toLowerCase() === "type" ? 1 : 2 ); + } + }); +} + +// Support: IE<9 +// Use defaultValue in place of getAttribute("value") +if ( !support.attributes || !assert(function( div ) { + div.innerHTML = ""; + div.firstChild.setAttribute( "value", "" ); + return div.firstChild.getAttribute( "value" ) === ""; +}) ) { + addHandle( "value", function( elem, name, isXML ) { + if ( !isXML && elem.nodeName.toLowerCase() === "input" ) { + return elem.defaultValue; + } + }); +} + +// Support: IE<9 +// Use getAttributeNode to fetch booleans when getAttribute lies +if ( !assert(function( div ) { + return div.getAttribute("disabled") == null; +}) ) { + addHandle( booleans, function( elem, name, isXML ) { + var val; + if ( !isXML ) { + return elem[ name ] === true ? name.toLowerCase() : + (val = elem.getAttributeNode( name )) && val.specified ? + val.value : + null; + } + }); +} + +return Sizzle; + +})( window ); + + + +jQuery.find = Sizzle; +jQuery.expr = Sizzle.selectors; +jQuery.expr[":"] = jQuery.expr.pseudos; +jQuery.unique = Sizzle.uniqueSort; +jQuery.text = Sizzle.getText; +jQuery.isXMLDoc = Sizzle.isXML; +jQuery.contains = Sizzle.contains; + + + +var rneedsContext = jQuery.expr.match.needsContext; + +var rsingleTag = (/^<(\w+)\s*\/?>(?:<\/\1>|)$/); + + + +var risSimple = /^.[^:#\[\.,]*$/; + +// Implement the identical functionality for filter and not +function winnow( elements, qualifier, not ) { + if ( jQuery.isFunction( qualifier ) ) { + return jQuery.grep( elements, function( elem, i ) { + /* jshint -W018 */ + return !!qualifier.call( elem, i, elem ) !== not; + }); + + } + + if ( qualifier.nodeType ) { + return jQuery.grep( elements, function( elem ) { + return ( elem === qualifier ) !== not; + }); + + } + + if ( typeof qualifier === "string" ) { + if ( risSimple.test( qualifier ) ) { + return jQuery.filter( qualifier, elements, not ); + } + + qualifier = jQuery.filter( qualifier, elements ); + } + + return jQuery.grep( elements, function( elem ) { + return ( indexOf.call( qualifier, elem ) >= 0 ) !== not; + }); +} + +jQuery.filter = function( expr, elems, not ) { + var elem = elems[ 0 ]; + + if ( not ) { + expr = ":not(" + expr + ")"; + } + + return elems.length === 1 && elem.nodeType === 1 ? + jQuery.find.matchesSelector( elem, expr ) ? [ elem ] : [] : + jQuery.find.matches( expr, jQuery.grep( elems, function( elem ) { + return elem.nodeType === 1; + })); +}; + +jQuery.fn.extend({ + find: function( selector ) { + var i, + len = this.length, + ret = [], + self = this; + + if ( typeof selector !== "string" ) { + return this.pushStack( jQuery( selector ).filter(function() { + for ( i = 0; i < len; i++ ) { + if ( jQuery.contains( self[ i ], this ) ) { + return true; + } + } + }) ); + } + + for ( i = 0; i < len; i++ ) { + jQuery.find( selector, self[ i ], ret ); + } + + // Needed because $( selector, context ) becomes $( context ).find( selector ) + ret = this.pushStack( len > 1 ? jQuery.unique( ret ) : ret ); + ret.selector = this.selector ? this.selector + " " + selector : selector; + return ret; + }, + filter: function( selector ) { + return this.pushStack( winnow(this, selector || [], false) ); + }, + not: function( selector ) { + return this.pushStack( winnow(this, selector || [], true) ); + }, + is: function( selector ) { + return !!winnow( + this, + + // If this is a positional/relative selector, check membership in the returned set + // so $("p:first").is("p:last") won't return true for a doc with two "p". + typeof selector === "string" && rneedsContext.test( selector ) ? + jQuery( selector ) : + selector || [], + false + ).length; + } +}); + + +// Initialize a jQuery object + + +// A central reference to the root jQuery(document) +var rootjQuery, + + // A simple way to check for HTML strings + // Prioritize #id over to avoid XSS via location.hash (#9521) + // Strict HTML recognition (#11290: must start with <) + rquickExpr = /^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/, + + init = jQuery.fn.init = function( selector, context ) { + var match, elem; + + // HANDLE: $(""), $(null), $(undefined), $(false) + if ( !selector ) { + return this; + } + + // Handle HTML strings + if ( typeof selector === "string" ) { + if ( selector[0] === "<" && selector[ selector.length - 1 ] === ">" && selector.length >= 3 ) { + // Assume that strings that start and end with <> are HTML and skip the regex check + match = [ null, selector, null ]; + + } else { + match = rquickExpr.exec( selector ); + } + + // Match html or make sure no context is specified for #id + if ( match && (match[1] || !context) ) { + + // HANDLE: $(html) -> $(array) + if ( match[1] ) { + context = context instanceof jQuery ? context[0] : context; + + // scripts is true for back-compat + // Intentionally let the error be thrown if parseHTML is not present + jQuery.merge( this, jQuery.parseHTML( + match[1], + context && context.nodeType ? context.ownerDocument || context : document, + true + ) ); + + // HANDLE: $(html, props) + if ( rsingleTag.test( match[1] ) && jQuery.isPlainObject( context ) ) { + for ( match in context ) { + // Properties of context are called as methods if possible + if ( jQuery.isFunction( this[ match ] ) ) { + this[ match ]( context[ match ] ); + + // ...and otherwise set as attributes + } else { + this.attr( match, context[ match ] ); + } + } + } + + return this; + + // HANDLE: $(#id) + } else { + elem = document.getElementById( match[2] ); + + // Check parentNode to catch when Blackberry 4.6 returns + // nodes that are no longer in the document #6963 + if ( elem && elem.parentNode ) { + // Inject the element directly into the jQuery object + this.length = 1; + this[0] = elem; + } + + this.context = document; + this.selector = selector; + return this; + } + + // HANDLE: $(expr, $(...)) + } else if ( !context || context.jquery ) { + return ( context || rootjQuery ).find( selector ); + + // HANDLE: $(expr, context) + // (which is just equivalent to: $(context).find(expr) + } else { + return this.constructor( context ).find( selector ); + } + + // HANDLE: $(DOMElement) + } else if ( selector.nodeType ) { + this.context = this[0] = selector; + this.length = 1; + return this; + + // HANDLE: $(function) + // Shortcut for document ready + } else if ( jQuery.isFunction( selector ) ) { + return typeof rootjQuery.ready !== "undefined" ? + rootjQuery.ready( selector ) : + // Execute immediately if ready is not present + selector( jQuery ); + } + + if ( selector.selector !== undefined ) { + this.selector = selector.selector; + this.context = selector.context; + } + + return jQuery.makeArray( selector, this ); + }; + +// Give the init function the jQuery prototype for later instantiation +init.prototype = jQuery.fn; + +// Initialize central reference +rootjQuery = jQuery( document ); + + +var rparentsprev = /^(?:parents|prev(?:Until|All))/, + // methods guaranteed to produce a unique set when starting from a unique set + guaranteedUnique = { + children: true, + contents: true, + next: true, + prev: true + }; + +jQuery.extend({ + dir: function( elem, dir, until ) { + var matched = [], + truncate = until !== undefined; + + while ( (elem = elem[ dir ]) && elem.nodeType !== 9 ) { + if ( elem.nodeType === 1 ) { + if ( truncate && jQuery( elem ).is( until ) ) { + break; + } + matched.push( elem ); + } + } + return matched; + }, + + sibling: function( n, elem ) { + var matched = []; + + for ( ; n; n = n.nextSibling ) { + if ( n.nodeType === 1 && n !== elem ) { + matched.push( n ); + } + } + + return matched; + } +}); + +jQuery.fn.extend({ + has: function( target ) { + var targets = jQuery( target, this ), + l = targets.length; + + return this.filter(function() { + var i = 0; + for ( ; i < l; i++ ) { + if ( jQuery.contains( this, targets[i] ) ) { + return true; + } + } + }); + }, + + closest: function( selectors, context ) { + var cur, + i = 0, + l = this.length, + matched = [], + pos = rneedsContext.test( selectors ) || typeof selectors !== "string" ? + jQuery( selectors, context || this.context ) : + 0; + + for ( ; i < l; i++ ) { + for ( cur = this[i]; cur && cur !== context; cur = cur.parentNode ) { + // Always skip document fragments + if ( cur.nodeType < 11 && (pos ? + pos.index(cur) > -1 : + + // Don't pass non-elements to Sizzle + cur.nodeType === 1 && + jQuery.find.matchesSelector(cur, selectors)) ) { + + matched.push( cur ); + break; + } + } + } + + return this.pushStack( matched.length > 1 ? jQuery.unique( matched ) : matched ); + }, + + // Determine the position of an element within + // the matched set of elements + index: function( elem ) { + + // No argument, return index in parent + if ( !elem ) { + return ( this[ 0 ] && this[ 0 ].parentNode ) ? this.first().prevAll().length : -1; + } + + // index in selector + if ( typeof elem === "string" ) { + return indexOf.call( jQuery( elem ), this[ 0 ] ); + } + + // Locate the position of the desired element + return indexOf.call( this, + + // If it receives a jQuery object, the first element is used + elem.jquery ? elem[ 0 ] : elem + ); + }, + + add: function( selector, context ) { + return this.pushStack( + jQuery.unique( + jQuery.merge( this.get(), jQuery( selector, context ) ) + ) + ); + }, + + addBack: function( selector ) { + return this.add( selector == null ? + this.prevObject : this.prevObject.filter(selector) + ); + } +}); + +function sibling( cur, dir ) { + while ( (cur = cur[dir]) && cur.nodeType !== 1 ) {} + return cur; +} + +jQuery.each({ + parent: function( elem ) { + var parent = elem.parentNode; + return parent && parent.nodeType !== 11 ? parent : null; + }, + parents: function( elem ) { + return jQuery.dir( elem, "parentNode" ); + }, + parentsUntil: function( elem, i, until ) { + return jQuery.dir( elem, "parentNode", until ); + }, + next: function( elem ) { + return sibling( elem, "nextSibling" ); + }, + prev: function( elem ) { + return sibling( elem, "previousSibling" ); + }, + nextAll: function( elem ) { + return jQuery.dir( elem, "nextSibling" ); + }, + prevAll: function( elem ) { + return jQuery.dir( elem, "previousSibling" ); + }, + nextUntil: function( elem, i, until ) { + return jQuery.dir( elem, "nextSibling", until ); + }, + prevUntil: function( elem, i, until ) { + return jQuery.dir( elem, "previousSibling", until ); + }, + siblings: function( elem ) { + return jQuery.sibling( ( elem.parentNode || {} ).firstChild, elem ); + }, + children: function( elem ) { + return jQuery.sibling( elem.firstChild ); + }, + contents: function( elem ) { + return elem.contentDocument || jQuery.merge( [], elem.childNodes ); + } +}, function( name, fn ) { + jQuery.fn[ name ] = function( until, selector ) { + var matched = jQuery.map( this, fn, until ); + + if ( name.slice( -5 ) !== "Until" ) { + selector = until; + } + + if ( selector && typeof selector === "string" ) { + matched = jQuery.filter( selector, matched ); + } + + if ( this.length > 1 ) { + // Remove duplicates + if ( !guaranteedUnique[ name ] ) { + jQuery.unique( matched ); + } + + // Reverse order for parents* and prev-derivatives + if ( rparentsprev.test( name ) ) { + matched.reverse(); + } + } + + return this.pushStack( matched ); + }; +}); +var rnotwhite = (/\S+/g); + + + +// String to Object options format cache +var optionsCache = {}; + +// Convert String-formatted options into Object-formatted ones and store in cache +function createOptions( options ) { + var object = optionsCache[ options ] = {}; + jQuery.each( options.match( rnotwhite ) || [], function( _, flag ) { + object[ flag ] = true; + }); + return object; +} + +/* + * Create a callback list using the following parameters: + * + * options: an optional list of space-separated options that will change how + * the callback list behaves or a more traditional option object + * + * By default a callback list will act like an event callback list and can be + * "fired" multiple times. + * + * Possible options: + * + * once: will ensure the callback list can only be fired once (like a Deferred) + * + * memory: will keep track of previous values and will call any callback added + * after the list has been fired right away with the latest "memorized" + * values (like a Deferred) + * + * unique: will ensure a callback can only be added once (no duplicate in the list) + * + * stopOnFalse: interrupt callings when a callback returns false + * + */ +jQuery.Callbacks = function( options ) { + + // Convert options from String-formatted to Object-formatted if needed + // (we check in cache first) + options = typeof options === "string" ? + ( optionsCache[ options ] || createOptions( options ) ) : + jQuery.extend( {}, options ); + + var // Last fire value (for non-forgettable lists) + memory, + // Flag to know if list was already fired + fired, + // Flag to know if list is currently firing + firing, + // First callback to fire (used internally by add and fireWith) + firingStart, + // End of the loop when firing + firingLength, + // Index of currently firing callback (modified by remove if needed) + firingIndex, + // Actual callback list + list = [], + // Stack of fire calls for repeatable lists + stack = !options.once && [], + // Fire callbacks + fire = function( data ) { + memory = options.memory && data; + fired = true; + firingIndex = firingStart || 0; + firingStart = 0; + firingLength = list.length; + firing = true; + for ( ; list && firingIndex < firingLength; firingIndex++ ) { + if ( list[ firingIndex ].apply( data[ 0 ], data[ 1 ] ) === false && options.stopOnFalse ) { + memory = false; // To prevent further calls using add + break; + } + } + firing = false; + if ( list ) { + if ( stack ) { + if ( stack.length ) { + fire( stack.shift() ); + } + } else if ( memory ) { + list = []; + } else { + self.disable(); + } + } + }, + // Actual Callbacks object + self = { + // Add a callback or a collection of callbacks to the list + add: function() { + if ( list ) { + // First, we save the current length + var start = list.length; + (function add( args ) { + jQuery.each( args, function( _, arg ) { + var type = jQuery.type( arg ); + if ( type === "function" ) { + if ( !options.unique || !self.has( arg ) ) { + list.push( arg ); + } + } else if ( arg && arg.length && type !== "string" ) { + // Inspect recursively + add( arg ); + } + }); + })( arguments ); + // Do we need to add the callbacks to the + // current firing batch? + if ( firing ) { + firingLength = list.length; + // With memory, if we're not firing then + // we should call right away + } else if ( memory ) { + firingStart = start; + fire( memory ); + } + } + return this; + }, + // Remove a callback from the list + remove: function() { + if ( list ) { + jQuery.each( arguments, function( _, arg ) { + var index; + while ( ( index = jQuery.inArray( arg, list, index ) ) > -1 ) { + list.splice( index, 1 ); + // Handle firing indexes + if ( firing ) { + if ( index <= firingLength ) { + firingLength--; + } + if ( index <= firingIndex ) { + firingIndex--; + } + } + } + }); + } + return this; + }, + // Check if a given callback is in the list. + // If no argument is given, return whether or not list has callbacks attached. + has: function( fn ) { + return fn ? jQuery.inArray( fn, list ) > -1 : !!( list && list.length ); + }, + // Remove all callbacks from the list + empty: function() { + list = []; + firingLength = 0; + return this; + }, + // Have the list do nothing anymore + disable: function() { + list = stack = memory = undefined; + return this; + }, + // Is it disabled? + disabled: function() { + return !list; + }, + // Lock the list in its current state + lock: function() { + stack = undefined; + if ( !memory ) { + self.disable(); + } + return this; + }, + // Is it locked? + locked: function() { + return !stack; + }, + // Call all callbacks with the given context and arguments + fireWith: function( context, args ) { + if ( list && ( !fired || stack ) ) { + args = args || []; + args = [ context, args.slice ? args.slice() : args ]; + if ( firing ) { + stack.push( args ); + } else { + fire( args ); + } + } + return this; + }, + // Call all the callbacks with the given arguments + fire: function() { + self.fireWith( this, arguments ); + return this; + }, + // To know if the callbacks have already been called at least once + fired: function() { + return !!fired; + } + }; + + return self; +}; + + +jQuery.extend({ + + Deferred: function( func ) { + var tuples = [ + // action, add listener, listener list, final state + [ "resolve", "done", jQuery.Callbacks("once memory"), "resolved" ], + [ "reject", "fail", jQuery.Callbacks("once memory"), "rejected" ], + [ "notify", "progress", jQuery.Callbacks("memory") ] + ], + state = "pending", + promise = { + state: function() { + return state; + }, + always: function() { + deferred.done( arguments ).fail( arguments ); + return this; + }, + then: function( /* fnDone, fnFail, fnProgress */ ) { + var fns = arguments; + return jQuery.Deferred(function( newDefer ) { + jQuery.each( tuples, function( i, tuple ) { + var fn = jQuery.isFunction( fns[ i ] ) && fns[ i ]; + // deferred[ done | fail | progress ] for forwarding actions to newDefer + deferred[ tuple[1] ](function() { + var returned = fn && fn.apply( this, arguments ); + if ( returned && jQuery.isFunction( returned.promise ) ) { + returned.promise() + .done( newDefer.resolve ) + .fail( newDefer.reject ) + .progress( newDefer.notify ); + } else { + newDefer[ tuple[ 0 ] + "With" ]( this === promise ? newDefer.promise() : this, fn ? [ returned ] : arguments ); + } + }); + }); + fns = null; + }).promise(); + }, + // Get a promise for this deferred + // If obj is provided, the promise aspect is added to the object + promise: function( obj ) { + return obj != null ? jQuery.extend( obj, promise ) : promise; + } + }, + deferred = {}; + + // Keep pipe for back-compat + promise.pipe = promise.then; + + // Add list-specific methods + jQuery.each( tuples, function( i, tuple ) { + var list = tuple[ 2 ], + stateString = tuple[ 3 ]; + + // promise[ done | fail | progress ] = list.add + promise[ tuple[1] ] = list.add; + + // Handle state + if ( stateString ) { + list.add(function() { + // state = [ resolved | rejected ] + state = stateString; + + // [ reject_list | resolve_list ].disable; progress_list.lock + }, tuples[ i ^ 1 ][ 2 ].disable, tuples[ 2 ][ 2 ].lock ); + } + + // deferred[ resolve | reject | notify ] + deferred[ tuple[0] ] = function() { + deferred[ tuple[0] + "With" ]( this === deferred ? promise : this, arguments ); + return this; + }; + deferred[ tuple[0] + "With" ] = list.fireWith; + }); + + // Make the deferred a promise + promise.promise( deferred ); + + // Call given func if any + if ( func ) { + func.call( deferred, deferred ); + } + + // All done! + return deferred; + }, + + // Deferred helper + when: function( subordinate /* , ..., subordinateN */ ) { + var i = 0, + resolveValues = slice.call( arguments ), + length = resolveValues.length, + + // the count of uncompleted subordinates + remaining = length !== 1 || ( subordinate && jQuery.isFunction( subordinate.promise ) ) ? length : 0, + + // the master Deferred. If resolveValues consist of only a single Deferred, just use that. + deferred = remaining === 1 ? subordinate : jQuery.Deferred(), + + // Update function for both resolve and progress values + updateFunc = function( i, contexts, values ) { + return function( value ) { + contexts[ i ] = this; + values[ i ] = arguments.length > 1 ? slice.call( arguments ) : value; + if ( values === progressValues ) { + deferred.notifyWith( contexts, values ); + } else if ( !( --remaining ) ) { + deferred.resolveWith( contexts, values ); + } + }; + }, + + progressValues, progressContexts, resolveContexts; + + // add listeners to Deferred subordinates; treat others as resolved + if ( length > 1 ) { + progressValues = new Array( length ); + progressContexts = new Array( length ); + resolveContexts = new Array( length ); + for ( ; i < length; i++ ) { + if ( resolveValues[ i ] && jQuery.isFunction( resolveValues[ i ].promise ) ) { + resolveValues[ i ].promise() + .done( updateFunc( i, resolveContexts, resolveValues ) ) + .fail( deferred.reject ) + .progress( updateFunc( i, progressContexts, progressValues ) ); + } else { + --remaining; + } + } + } + + // if we're not waiting on anything, resolve the master + if ( !remaining ) { + deferred.resolveWith( resolveContexts, resolveValues ); + } + + return deferred.promise(); + } +}); + + +// The deferred used on DOM ready +var readyList; + +jQuery.fn.ready = function( fn ) { + // Add the callback + jQuery.ready.promise().done( fn ); + + return this; +}; + +jQuery.extend({ + // Is the DOM ready to be used? Set to true once it occurs. + isReady: false, + + // A counter to track how many items to wait for before + // the ready event fires. See #6781 + readyWait: 1, + + // Hold (or release) the ready event + holdReady: function( hold ) { + if ( hold ) { + jQuery.readyWait++; + } else { + jQuery.ready( true ); + } + }, + + // Handle when the DOM is ready + ready: function( wait ) { + + // Abort if there are pending holds or we're already ready + if ( wait === true ? --jQuery.readyWait : jQuery.isReady ) { + return; + } + + // Remember that the DOM is ready + jQuery.isReady = true; + + // If a normal DOM Ready event fired, decrement, and wait if need be + if ( wait !== true && --jQuery.readyWait > 0 ) { + return; + } + + // If there are functions bound, to execute + readyList.resolveWith( document, [ jQuery ] ); + + // Trigger any bound ready events + if ( jQuery.fn.triggerHandler ) { + jQuery( document ).triggerHandler( "ready" ); + jQuery( document ).off( "ready" ); + } + } +}); + +/** + * The ready event handler and self cleanup method + */ +function completed() { + document.removeEventListener( "DOMContentLoaded", completed, false ); + window.removeEventListener( "load", completed, false ); + jQuery.ready(); +} + +jQuery.ready.promise = function( obj ) { + if ( !readyList ) { + + readyList = jQuery.Deferred(); + + // Catch cases where $(document).ready() is called after the browser event has already occurred. + // we once tried to use readyState "interactive" here, but it caused issues like the one + // discovered by ChrisS here: http://bugs.jquery.com/ticket/12282#comment:15 + if ( document.readyState === "complete" ) { + // Handle it asynchronously to allow scripts the opportunity to delay ready + setTimeout( jQuery.ready ); + + } else { + + // Use the handy event callback + document.addEventListener( "DOMContentLoaded", completed, false ); + + // A fallback to window.onload, that will always work + window.addEventListener( "load", completed, false ); + } + } + return readyList.promise( obj ); +}; + +// Kick off the DOM ready check even if the user does not +jQuery.ready.promise(); + + + + +// Multifunctional method to get and set values of a collection +// The value/s can optionally be executed if it's a function +var access = jQuery.access = function( elems, fn, key, value, chainable, emptyGet, raw ) { + var i = 0, + len = elems.length, + bulk = key == null; + + // Sets many values + if ( jQuery.type( key ) === "object" ) { + chainable = true; + for ( i in key ) { + jQuery.access( elems, fn, i, key[i], true, emptyGet, raw ); + } + + // Sets one value + } else if ( value !== undefined ) { + chainable = true; + + if ( !jQuery.isFunction( value ) ) { + raw = true; + } + + if ( bulk ) { + // Bulk operations run against the entire set + if ( raw ) { + fn.call( elems, value ); + fn = null; + + // ...except when executing function values + } else { + bulk = fn; + fn = function( elem, key, value ) { + return bulk.call( jQuery( elem ), value ); + }; + } + } + + if ( fn ) { + for ( ; i < len; i++ ) { + fn( elems[i], key, raw ? value : value.call( elems[i], i, fn( elems[i], key ) ) ); + } + } + } + + return chainable ? + elems : + + // Gets + bulk ? + fn.call( elems ) : + len ? fn( elems[0], key ) : emptyGet; +}; + + +/** + * Determines whether an object can have data + */ +jQuery.acceptData = function( owner ) { + // Accepts only: + // - Node + // - Node.ELEMENT_NODE + // - Node.DOCUMENT_NODE + // - Object + // - Any + /* jshint -W018 */ + return owner.nodeType === 1 || owner.nodeType === 9 || !( +owner.nodeType ); +}; + + +function Data() { + // Support: Android < 4, + // Old WebKit does not have Object.preventExtensions/freeze method, + // return new empty object instead with no [[set]] accessor + Object.defineProperty( this.cache = {}, 0, { + get: function() { + return {}; + } + }); + + this.expando = jQuery.expando + Math.random(); +} + +Data.uid = 1; +Data.accepts = jQuery.acceptData; + +Data.prototype = { + key: function( owner ) { + // We can accept data for non-element nodes in modern browsers, + // but we should not, see #8335. + // Always return the key for a frozen object. + if ( !Data.accepts( owner ) ) { + return 0; + } + + var descriptor = {}, + // Check if the owner object already has a cache key + unlock = owner[ this.expando ]; + + // If not, create one + if ( !unlock ) { + unlock = Data.uid++; + + // Secure it in a non-enumerable, non-writable property + try { + descriptor[ this.expando ] = { value: unlock }; + Object.defineProperties( owner, descriptor ); + + // Support: Android < 4 + // Fallback to a less secure definition + } catch ( e ) { + descriptor[ this.expando ] = unlock; + jQuery.extend( owner, descriptor ); + } + } + + // Ensure the cache object + if ( !this.cache[ unlock ] ) { + this.cache[ unlock ] = {}; + } + + return unlock; + }, + set: function( owner, data, value ) { + var prop, + // There may be an unlock assigned to this node, + // if there is no entry for this "owner", create one inline + // and set the unlock as though an owner entry had always existed + unlock = this.key( owner ), + cache = this.cache[ unlock ]; + + // Handle: [ owner, key, value ] args + if ( typeof data === "string" ) { + cache[ data ] = value; + + // Handle: [ owner, { properties } ] args + } else { + // Fresh assignments by object are shallow copied + if ( jQuery.isEmptyObject( cache ) ) { + jQuery.extend( this.cache[ unlock ], data ); + // Otherwise, copy the properties one-by-one to the cache object + } else { + for ( prop in data ) { + cache[ prop ] = data[ prop ]; + } + } + } + return cache; + }, + get: function( owner, key ) { + // Either a valid cache is found, or will be created. + // New caches will be created and the unlock returned, + // allowing direct access to the newly created + // empty data object. A valid owner object must be provided. + var cache = this.cache[ this.key( owner ) ]; + + return key === undefined ? + cache : cache[ key ]; + }, + access: function( owner, key, value ) { + var stored; + // In cases where either: + // + // 1. No key was specified + // 2. A string key was specified, but no value provided + // + // Take the "read" path and allow the get method to determine + // which value to return, respectively either: + // + // 1. The entire cache object + // 2. The data stored at the key + // + if ( key === undefined || + ((key && typeof key === "string") && value === undefined) ) { + + stored = this.get( owner, key ); + + return stored !== undefined ? + stored : this.get( owner, jQuery.camelCase(key) ); + } + + // [*]When the key is not a string, or both a key and value + // are specified, set or extend (existing objects) with either: + // + // 1. An object of properties + // 2. A key and value + // + this.set( owner, key, value ); + + // Since the "set" path can have two possible entry points + // return the expected data based on which path was taken[*] + return value !== undefined ? value : key; + }, + remove: function( owner, key ) { + var i, name, camel, + unlock = this.key( owner ), + cache = this.cache[ unlock ]; + + if ( key === undefined ) { + this.cache[ unlock ] = {}; + + } else { + // Support array or space separated string of keys + if ( jQuery.isArray( key ) ) { + // If "name" is an array of keys... + // When data is initially created, via ("key", "val") signature, + // keys will be converted to camelCase. + // Since there is no way to tell _how_ a key was added, remove + // both plain key and camelCase key. #12786 + // This will only penalize the array argument path. + name = key.concat( key.map( jQuery.camelCase ) ); + } else { + camel = jQuery.camelCase( key ); + // Try the string as a key before any manipulation + if ( key in cache ) { + name = [ key, camel ]; + } else { + // If a key with the spaces exists, use it. + // Otherwise, create an array by matching non-whitespace + name = camel; + name = name in cache ? + [ name ] : ( name.match( rnotwhite ) || [] ); + } + } + + i = name.length; + while ( i-- ) { + delete cache[ name[ i ] ]; + } + } + }, + hasData: function( owner ) { + return !jQuery.isEmptyObject( + this.cache[ owner[ this.expando ] ] || {} + ); + }, + discard: function( owner ) { + if ( owner[ this.expando ] ) { + delete this.cache[ owner[ this.expando ] ]; + } + } +}; +var data_priv = new Data(); + +var data_user = new Data(); + + + +/* + Implementation Summary + + 1. Enforce API surface and semantic compatibility with 1.9.x branch + 2. Improve the module's maintainability by reducing the storage + paths to a single mechanism. + 3. Use the same single mechanism to support "private" and "user" data. + 4. _Never_ expose "private" data to user code (TODO: Drop _data, _removeData) + 5. Avoid exposing implementation details on user objects (eg. expando properties) + 6. Provide a clear path for implementation upgrade to WeakMap in 2014 +*/ +var rbrace = /^(?:\{[\w\W]*\}|\[[\w\W]*\])$/, + rmultiDash = /([A-Z])/g; + +function dataAttr( elem, key, data ) { + var name; + + // If nothing was found internally, try to fetch any + // data from the HTML5 data-* attribute + if ( data === undefined && elem.nodeType === 1 ) { + name = "data-" + key.replace( rmultiDash, "-$1" ).toLowerCase(); + data = elem.getAttribute( name ); + + if ( typeof data === "string" ) { + try { + data = data === "true" ? true : + data === "false" ? false : + data === "null" ? null : + // Only convert to a number if it doesn't change the string + +data + "" === data ? +data : + rbrace.test( data ) ? jQuery.parseJSON( data ) : + data; + } catch( e ) {} + + // Make sure we set the data so it isn't changed later + data_user.set( elem, key, data ); + } else { + data = undefined; + } + } + return data; +} + +jQuery.extend({ + hasData: function( elem ) { + return data_user.hasData( elem ) || data_priv.hasData( elem ); + }, + + data: function( elem, name, data ) { + return data_user.access( elem, name, data ); + }, + + removeData: function( elem, name ) { + data_user.remove( elem, name ); + }, + + // TODO: Now that all calls to _data and _removeData have been replaced + // with direct calls to data_priv methods, these can be deprecated. + _data: function( elem, name, data ) { + return data_priv.access( elem, name, data ); + }, + + _removeData: function( elem, name ) { + data_priv.remove( elem, name ); + } +}); + +jQuery.fn.extend({ + data: function( key, value ) { + var i, name, data, + elem = this[ 0 ], + attrs = elem && elem.attributes; + + // Gets all values + if ( key === undefined ) { + if ( this.length ) { + data = data_user.get( elem ); + + if ( elem.nodeType === 1 && !data_priv.get( elem, "hasDataAttrs" ) ) { + i = attrs.length; + while ( i-- ) { + + // Support: IE11+ + // The attrs elements can be null (#14894) + if ( attrs[ i ] ) { + name = attrs[ i ].name; + if ( name.indexOf( "data-" ) === 0 ) { + name = jQuery.camelCase( name.slice(5) ); + dataAttr( elem, name, data[ name ] ); + } + } + } + data_priv.set( elem, "hasDataAttrs", true ); + } + } + + return data; + } + + // Sets multiple values + if ( typeof key === "object" ) { + return this.each(function() { + data_user.set( this, key ); + }); + } + + return access( this, function( value ) { + var data, + camelKey = jQuery.camelCase( key ); + + // The calling jQuery object (element matches) is not empty + // (and therefore has an element appears at this[ 0 ]) and the + // `value` parameter was not undefined. An empty jQuery object + // will result in `undefined` for elem = this[ 0 ] which will + // throw an exception if an attempt to read a data cache is made. + if ( elem && value === undefined ) { + // Attempt to get data from the cache + // with the key as-is + data = data_user.get( elem, key ); + if ( data !== undefined ) { + return data; + } + + // Attempt to get data from the cache + // with the key camelized + data = data_user.get( elem, camelKey ); + if ( data !== undefined ) { + return data; + } + + // Attempt to "discover" the data in + // HTML5 custom data-* attrs + data = dataAttr( elem, camelKey, undefined ); + if ( data !== undefined ) { + return data; + } + + // We tried really hard, but the data doesn't exist. + return; + } + + // Set the data... + this.each(function() { + // First, attempt to store a copy or reference of any + // data that might've been store with a camelCased key. + var data = data_user.get( this, camelKey ); + + // For HTML5 data-* attribute interop, we have to + // store property names with dashes in a camelCase form. + // This might not apply to all properties...* + data_user.set( this, camelKey, value ); + + // *... In the case of properties that might _actually_ + // have dashes, we need to also store a copy of that + // unchanged property. + if ( key.indexOf("-") !== -1 && data !== undefined ) { + data_user.set( this, key, value ); + } + }); + }, null, value, arguments.length > 1, null, true ); + }, + + removeData: function( key ) { + return this.each(function() { + data_user.remove( this, key ); + }); + } +}); + + +jQuery.extend({ + queue: function( elem, type, data ) { + var queue; + + if ( elem ) { + type = ( type || "fx" ) + "queue"; + queue = data_priv.get( elem, type ); + + // Speed up dequeue by getting out quickly if this is just a lookup + if ( data ) { + if ( !queue || jQuery.isArray( data ) ) { + queue = data_priv.access( elem, type, jQuery.makeArray(data) ); + } else { + queue.push( data ); + } + } + return queue || []; + } + }, + + dequeue: function( elem, type ) { + type = type || "fx"; + + var queue = jQuery.queue( elem, type ), + startLength = queue.length, + fn = queue.shift(), + hooks = jQuery._queueHooks( elem, type ), + next = function() { + jQuery.dequeue( elem, type ); + }; + + // If the fx queue is dequeued, always remove the progress sentinel + if ( fn === "inprogress" ) { + fn = queue.shift(); + startLength--; + } + + if ( fn ) { + + // Add a progress sentinel to prevent the fx queue from being + // automatically dequeued + if ( type === "fx" ) { + queue.unshift( "inprogress" ); + } + + // clear up the last queue stop function + delete hooks.stop; + fn.call( elem, next, hooks ); + } + + if ( !startLength && hooks ) { + hooks.empty.fire(); + } + }, + + // not intended for public consumption - generates a queueHooks object, or returns the current one + _queueHooks: function( elem, type ) { + var key = type + "queueHooks"; + return data_priv.get( elem, key ) || data_priv.access( elem, key, { + empty: jQuery.Callbacks("once memory").add(function() { + data_priv.remove( elem, [ type + "queue", key ] ); + }) + }); + } +}); + +jQuery.fn.extend({ + queue: function( type, data ) { + var setter = 2; + + if ( typeof type !== "string" ) { + data = type; + type = "fx"; + setter--; + } + + if ( arguments.length < setter ) { + return jQuery.queue( this[0], type ); + } + + return data === undefined ? + this : + this.each(function() { + var queue = jQuery.queue( this, type, data ); + + // ensure a hooks for this queue + jQuery._queueHooks( this, type ); + + if ( type === "fx" && queue[0] !== "inprogress" ) { + jQuery.dequeue( this, type ); + } + }); + }, + dequeue: function( type ) { + return this.each(function() { + jQuery.dequeue( this, type ); + }); + }, + clearQueue: function( type ) { + return this.queue( type || "fx", [] ); + }, + // Get a promise resolved when queues of a certain type + // are emptied (fx is the type by default) + promise: function( type, obj ) { + var tmp, + count = 1, + defer = jQuery.Deferred(), + elements = this, + i = this.length, + resolve = function() { + if ( !( --count ) ) { + defer.resolveWith( elements, [ elements ] ); + } + }; + + if ( typeof type !== "string" ) { + obj = type; + type = undefined; + } + type = type || "fx"; + + while ( i-- ) { + tmp = data_priv.get( elements[ i ], type + "queueHooks" ); + if ( tmp && tmp.empty ) { + count++; + tmp.empty.add( resolve ); + } + } + resolve(); + return defer.promise( obj ); + } +}); +var pnum = (/[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/).source; + +var cssExpand = [ "Top", "Right", "Bottom", "Left" ]; + +var isHidden = function( elem, el ) { + // isHidden might be called from jQuery#filter function; + // in that case, element will be second argument + elem = el || elem; + return jQuery.css( elem, "display" ) === "none" || !jQuery.contains( elem.ownerDocument, elem ); + }; + +var rcheckableType = (/^(?:checkbox|radio)$/i); + + + +(function() { + var fragment = document.createDocumentFragment(), + div = fragment.appendChild( document.createElement( "div" ) ), + input = document.createElement( "input" ); + + // #11217 - WebKit loses check when the name is after the checked attribute + // Support: Windows Web Apps (WWA) + // `name` and `type` need .setAttribute for WWA + input.setAttribute( "type", "radio" ); + input.setAttribute( "checked", "checked" ); + input.setAttribute( "name", "t" ); + + div.appendChild( input ); + + // Support: Safari 5.1, iOS 5.1, Android 4.x, Android 2.3 + // old WebKit doesn't clone checked state correctly in fragments + support.checkClone = div.cloneNode( true ).cloneNode( true ).lastChild.checked; + + // Make sure textarea (and checkbox) defaultValue is properly cloned + // Support: IE9-IE11+ + div.innerHTML = ""; + support.noCloneChecked = !!div.cloneNode( true ).lastChild.defaultValue; +})(); +var strundefined = typeof undefined; + + + +support.focusinBubbles = "onfocusin" in window; + + +var + rkeyEvent = /^key/, + rmouseEvent = /^(?:mouse|pointer|contextmenu)|click/, + rfocusMorph = /^(?:focusinfocus|focusoutblur)$/, + rtypenamespace = /^([^.]*)(?:\.(.+)|)$/; + +function returnTrue() { + return true; +} + +function returnFalse() { + return false; +} + +function safeActiveElement() { + try { + return document.activeElement; + } catch ( err ) { } +} + +/* + * Helper functions for managing events -- not part of the public interface. + * Props to Dean Edwards' addEvent library for many of the ideas. + */ +jQuery.event = { + + global: {}, + + add: function( elem, types, handler, data, selector ) { + + var handleObjIn, eventHandle, tmp, + events, t, handleObj, + special, handlers, type, namespaces, origType, + elemData = data_priv.get( elem ); + + // Don't attach events to noData or text/comment nodes (but allow plain objects) + if ( !elemData ) { + return; + } + + // Caller can pass in an object of custom data in lieu of the handler + if ( handler.handler ) { + handleObjIn = handler; + handler = handleObjIn.handler; + selector = handleObjIn.selector; + } + + // Make sure that the handler has a unique ID, used to find/remove it later + if ( !handler.guid ) { + handler.guid = jQuery.guid++; + } + + // Init the element's event structure and main handler, if this is the first + if ( !(events = elemData.events) ) { + events = elemData.events = {}; + } + if ( !(eventHandle = elemData.handle) ) { + eventHandle = elemData.handle = function( e ) { + // Discard the second event of a jQuery.event.trigger() and + // when an event is called after a page has unloaded + return typeof jQuery !== strundefined && jQuery.event.triggered !== e.type ? + jQuery.event.dispatch.apply( elem, arguments ) : undefined; + }; + } + + // Handle multiple events separated by a space + types = ( types || "" ).match( rnotwhite ) || [ "" ]; + t = types.length; + while ( t-- ) { + tmp = rtypenamespace.exec( types[t] ) || []; + type = origType = tmp[1]; + namespaces = ( tmp[2] || "" ).split( "." ).sort(); + + // There *must* be a type, no attaching namespace-only handlers + if ( !type ) { + continue; + } + + // If event changes its type, use the special event handlers for the changed type + special = jQuery.event.special[ type ] || {}; + + // If selector defined, determine special event api type, otherwise given type + type = ( selector ? special.delegateType : special.bindType ) || type; + + // Update special based on newly reset type + special = jQuery.event.special[ type ] || {}; + + // handleObj is passed to all event handlers + handleObj = jQuery.extend({ + type: type, + origType: origType, + data: data, + handler: handler, + guid: handler.guid, + selector: selector, + needsContext: selector && jQuery.expr.match.needsContext.test( selector ), + namespace: namespaces.join(".") + }, handleObjIn ); + + // Init the event handler queue if we're the first + if ( !(handlers = events[ type ]) ) { + handlers = events[ type ] = []; + handlers.delegateCount = 0; + + // Only use addEventListener if the special events handler returns false + if ( !special.setup || special.setup.call( elem, data, namespaces, eventHandle ) === false ) { + if ( elem.addEventListener ) { + elem.addEventListener( type, eventHandle, false ); + } + } + } + + if ( special.add ) { + special.add.call( elem, handleObj ); + + if ( !handleObj.handler.guid ) { + handleObj.handler.guid = handler.guid; + } + } + + // Add to the element's handler list, delegates in front + if ( selector ) { + handlers.splice( handlers.delegateCount++, 0, handleObj ); + } else { + handlers.push( handleObj ); + } + + // Keep track of which events have ever been used, for event optimization + jQuery.event.global[ type ] = true; + } + + }, + + // Detach an event or set of events from an element + remove: function( elem, types, handler, selector, mappedTypes ) { + + var j, origCount, tmp, + events, t, handleObj, + special, handlers, type, namespaces, origType, + elemData = data_priv.hasData( elem ) && data_priv.get( elem ); + + if ( !elemData || !(events = elemData.events) ) { + return; + } + + // Once for each type.namespace in types; type may be omitted + types = ( types || "" ).match( rnotwhite ) || [ "" ]; + t = types.length; + while ( t-- ) { + tmp = rtypenamespace.exec( types[t] ) || []; + type = origType = tmp[1]; + namespaces = ( tmp[2] || "" ).split( "." ).sort(); + + // Unbind all events (on this namespace, if provided) for the element + if ( !type ) { + for ( type in events ) { + jQuery.event.remove( elem, type + types[ t ], handler, selector, true ); + } + continue; + } + + special = jQuery.event.special[ type ] || {}; + type = ( selector ? special.delegateType : special.bindType ) || type; + handlers = events[ type ] || []; + tmp = tmp[2] && new RegExp( "(^|\\.)" + namespaces.join("\\.(?:.*\\.|)") + "(\\.|$)" ); + + // Remove matching events + origCount = j = handlers.length; + while ( j-- ) { + handleObj = handlers[ j ]; + + if ( ( mappedTypes || origType === handleObj.origType ) && + ( !handler || handler.guid === handleObj.guid ) && + ( !tmp || tmp.test( handleObj.namespace ) ) && + ( !selector || selector === handleObj.selector || selector === "**" && handleObj.selector ) ) { + handlers.splice( j, 1 ); + + if ( handleObj.selector ) { + handlers.delegateCount--; + } + if ( special.remove ) { + special.remove.call( elem, handleObj ); + } + } + } + + // Remove generic event handler if we removed something and no more handlers exist + // (avoids potential for endless recursion during removal of special event handlers) + if ( origCount && !handlers.length ) { + if ( !special.teardown || special.teardown.call( elem, namespaces, elemData.handle ) === false ) { + jQuery.removeEvent( elem, type, elemData.handle ); + } + + delete events[ type ]; + } + } + + // Remove the expando if it's no longer used + if ( jQuery.isEmptyObject( events ) ) { + delete elemData.handle; + data_priv.remove( elem, "events" ); + } + }, + + trigger: function( event, data, elem, onlyHandlers ) { + + var i, cur, tmp, bubbleType, ontype, handle, special, + eventPath = [ elem || document ], + type = hasOwn.call( event, "type" ) ? event.type : event, + namespaces = hasOwn.call( event, "namespace" ) ? event.namespace.split(".") : []; + + cur = tmp = elem = elem || document; + + // Don't do events on text and comment nodes + if ( elem.nodeType === 3 || elem.nodeType === 8 ) { + return; + } + + // focus/blur morphs to focusin/out; ensure we're not firing them right now + if ( rfocusMorph.test( type + jQuery.event.triggered ) ) { + return; + } + + if ( type.indexOf(".") >= 0 ) { + // Namespaced trigger; create a regexp to match event type in handle() + namespaces = type.split("."); + type = namespaces.shift(); + namespaces.sort(); + } + ontype = type.indexOf(":") < 0 && "on" + type; + + // Caller can pass in a jQuery.Event object, Object, or just an event type string + event = event[ jQuery.expando ] ? + event : + new jQuery.Event( type, typeof event === "object" && event ); + + // Trigger bitmask: & 1 for native handlers; & 2 for jQuery (always true) + event.isTrigger = onlyHandlers ? 2 : 3; + event.namespace = namespaces.join("."); + event.namespace_re = event.namespace ? + new RegExp( "(^|\\.)" + namespaces.join("\\.(?:.*\\.|)") + "(\\.|$)" ) : + null; + + // Clean up the event in case it is being reused + event.result = undefined; + if ( !event.target ) { + event.target = elem; + } + + // Clone any incoming data and prepend the event, creating the handler arg list + data = data == null ? + [ event ] : + jQuery.makeArray( data, [ event ] ); + + // Allow special events to draw outside the lines + special = jQuery.event.special[ type ] || {}; + if ( !onlyHandlers && special.trigger && special.trigger.apply( elem, data ) === false ) { + return; + } + + // Determine event propagation path in advance, per W3C events spec (#9951) + // Bubble up to document, then to window; watch for a global ownerDocument var (#9724) + if ( !onlyHandlers && !special.noBubble && !jQuery.isWindow( elem ) ) { + + bubbleType = special.delegateType || type; + if ( !rfocusMorph.test( bubbleType + type ) ) { + cur = cur.parentNode; + } + for ( ; cur; cur = cur.parentNode ) { + eventPath.push( cur ); + tmp = cur; + } + + // Only add window if we got to document (e.g., not plain obj or detached DOM) + if ( tmp === (elem.ownerDocument || document) ) { + eventPath.push( tmp.defaultView || tmp.parentWindow || window ); + } + } + + // Fire handlers on the event path + i = 0; + while ( (cur = eventPath[i++]) && !event.isPropagationStopped() ) { + + event.type = i > 1 ? + bubbleType : + special.bindType || type; + + // jQuery handler + handle = ( data_priv.get( cur, "events" ) || {} )[ event.type ] && data_priv.get( cur, "handle" ); + if ( handle ) { + handle.apply( cur, data ); + } + + // Native handler + handle = ontype && cur[ ontype ]; + if ( handle && handle.apply && jQuery.acceptData( cur ) ) { + event.result = handle.apply( cur, data ); + if ( event.result === false ) { + event.preventDefault(); + } + } + } + event.type = type; + + // If nobody prevented the default action, do it now + if ( !onlyHandlers && !event.isDefaultPrevented() ) { + + if ( (!special._default || special._default.apply( eventPath.pop(), data ) === false) && + jQuery.acceptData( elem ) ) { + + // Call a native DOM method on the target with the same name name as the event. + // Don't do default actions on window, that's where global variables be (#6170) + if ( ontype && jQuery.isFunction( elem[ type ] ) && !jQuery.isWindow( elem ) ) { + + // Don't re-trigger an onFOO event when we call its FOO() method + tmp = elem[ ontype ]; + + if ( tmp ) { + elem[ ontype ] = null; + } + + // Prevent re-triggering of the same event, since we already bubbled it above + jQuery.event.triggered = type; + elem[ type ](); + jQuery.event.triggered = undefined; + + if ( tmp ) { + elem[ ontype ] = tmp; + } + } + } + } + + return event.result; + }, + + dispatch: function( event ) { + + // Make a writable jQuery.Event from the native event object + event = jQuery.event.fix( event ); + + var i, j, ret, matched, handleObj, + handlerQueue = [], + args = slice.call( arguments ), + handlers = ( data_priv.get( this, "events" ) || {} )[ event.type ] || [], + special = jQuery.event.special[ event.type ] || {}; + + // Use the fix-ed jQuery.Event rather than the (read-only) native event + args[0] = event; + event.delegateTarget = this; + + // Call the preDispatch hook for the mapped type, and let it bail if desired + if ( special.preDispatch && special.preDispatch.call( this, event ) === false ) { + return; + } + + // Determine handlers + handlerQueue = jQuery.event.handlers.call( this, event, handlers ); + + // Run delegates first; they may want to stop propagation beneath us + i = 0; + while ( (matched = handlerQueue[ i++ ]) && !event.isPropagationStopped() ) { + event.currentTarget = matched.elem; + + j = 0; + while ( (handleObj = matched.handlers[ j++ ]) && !event.isImmediatePropagationStopped() ) { + + // Triggered event must either 1) have no namespace, or + // 2) have namespace(s) a subset or equal to those in the bound event (both can have no namespace). + if ( !event.namespace_re || event.namespace_re.test( handleObj.namespace ) ) { + + event.handleObj = handleObj; + event.data = handleObj.data; + + ret = ( (jQuery.event.special[ handleObj.origType ] || {}).handle || handleObj.handler ) + .apply( matched.elem, args ); + + if ( ret !== undefined ) { + if ( (event.result = ret) === false ) { + event.preventDefault(); + event.stopPropagation(); + } + } + } + } + } + + // Call the postDispatch hook for the mapped type + if ( special.postDispatch ) { + special.postDispatch.call( this, event ); + } + + return event.result; + }, + + handlers: function( event, handlers ) { + var i, matches, sel, handleObj, + handlerQueue = [], + delegateCount = handlers.delegateCount, + cur = event.target; + + // Find delegate handlers + // Black-hole SVG instance trees (#13180) + // Avoid non-left-click bubbling in Firefox (#3861) + if ( delegateCount && cur.nodeType && (!event.button || event.type !== "click") ) { + + for ( ; cur !== this; cur = cur.parentNode || this ) { + + // Don't process clicks on disabled elements (#6911, #8165, #11382, #11764) + if ( cur.disabled !== true || event.type !== "click" ) { + matches = []; + for ( i = 0; i < delegateCount; i++ ) { + handleObj = handlers[ i ]; + + // Don't conflict with Object.prototype properties (#13203) + sel = handleObj.selector + " "; + + if ( matches[ sel ] === undefined ) { + matches[ sel ] = handleObj.needsContext ? + jQuery( sel, this ).index( cur ) >= 0 : + jQuery.find( sel, this, null, [ cur ] ).length; + } + if ( matches[ sel ] ) { + matches.push( handleObj ); + } + } + if ( matches.length ) { + handlerQueue.push({ elem: cur, handlers: matches }); + } + } + } + } + + // Add the remaining (directly-bound) handlers + if ( delegateCount < handlers.length ) { + handlerQueue.push({ elem: this, handlers: handlers.slice( delegateCount ) }); + } + + return handlerQueue; + }, + + // Includes some event props shared by KeyEvent and MouseEvent + props: "altKey bubbles cancelable ctrlKey currentTarget eventPhase metaKey relatedTarget shiftKey target timeStamp view which".split(" "), + + fixHooks: {}, + + keyHooks: { + props: "char charCode key keyCode".split(" "), + filter: function( event, original ) { + + // Add which for key events + if ( event.which == null ) { + event.which = original.charCode != null ? original.charCode : original.keyCode; + } + + return event; + } + }, + + mouseHooks: { + props: "button buttons clientX clientY offsetX offsetY pageX pageY screenX screenY toElement".split(" "), + filter: function( event, original ) { + var eventDoc, doc, body, + button = original.button; + + // Calculate pageX/Y if missing and clientX/Y available + if ( event.pageX == null && original.clientX != null ) { + eventDoc = event.target.ownerDocument || document; + doc = eventDoc.documentElement; + body = eventDoc.body; + + event.pageX = original.clientX + ( doc && doc.scrollLeft || body && body.scrollLeft || 0 ) - ( doc && doc.clientLeft || body && body.clientLeft || 0 ); + event.pageY = original.clientY + ( doc && doc.scrollTop || body && body.scrollTop || 0 ) - ( doc && doc.clientTop || body && body.clientTop || 0 ); + } + + // Add which for click: 1 === left; 2 === middle; 3 === right + // Note: button is not normalized, so don't use it + if ( !event.which && button !== undefined ) { + event.which = ( button & 1 ? 1 : ( button & 2 ? 3 : ( button & 4 ? 2 : 0 ) ) ); + } + + return event; + } + }, + + fix: function( event ) { + if ( event[ jQuery.expando ] ) { + return event; + } + + // Create a writable copy of the event object and normalize some properties + var i, prop, copy, + type = event.type, + originalEvent = event, + fixHook = this.fixHooks[ type ]; + + if ( !fixHook ) { + this.fixHooks[ type ] = fixHook = + rmouseEvent.test( type ) ? this.mouseHooks : + rkeyEvent.test( type ) ? this.keyHooks : + {}; + } + copy = fixHook.props ? this.props.concat( fixHook.props ) : this.props; + + event = new jQuery.Event( originalEvent ); + + i = copy.length; + while ( i-- ) { + prop = copy[ i ]; + event[ prop ] = originalEvent[ prop ]; + } + + // Support: Cordova 2.5 (WebKit) (#13255) + // All events should have a target; Cordova deviceready doesn't + if ( !event.target ) { + event.target = document; + } + + // Support: Safari 6.0+, Chrome < 28 + // Target should not be a text node (#504, #13143) + if ( event.target.nodeType === 3 ) { + event.target = event.target.parentNode; + } + + return fixHook.filter ? fixHook.filter( event, originalEvent ) : event; + }, + + special: { + load: { + // Prevent triggered image.load events from bubbling to window.load + noBubble: true + }, + focus: { + // Fire native event if possible so blur/focus sequence is correct + trigger: function() { + if ( this !== safeActiveElement() && this.focus ) { + this.focus(); + return false; + } + }, + delegateType: "focusin" + }, + blur: { + trigger: function() { + if ( this === safeActiveElement() && this.blur ) { + this.blur(); + return false; + } + }, + delegateType: "focusout" + }, + click: { + // For checkbox, fire native event so checked state will be right + trigger: function() { + if ( this.type === "checkbox" && this.click && jQuery.nodeName( this, "input" ) ) { + this.click(); + return false; + } + }, + + // For cross-browser consistency, don't fire native .click() on links + _default: function( event ) { + return jQuery.nodeName( event.target, "a" ); + } + }, + + beforeunload: { + postDispatch: function( event ) { + + // Support: Firefox 20+ + // Firefox doesn't alert if the returnValue field is not set. + if ( event.result !== undefined && event.originalEvent ) { + event.originalEvent.returnValue = event.result; + } + } + } + }, + + simulate: function( type, elem, event, bubble ) { + // Piggyback on a donor event to simulate a different one. + // Fake originalEvent to avoid donor's stopPropagation, but if the + // simulated event prevents default then we do the same on the donor. + var e = jQuery.extend( + new jQuery.Event(), + event, + { + type: type, + isSimulated: true, + originalEvent: {} + } + ); + if ( bubble ) { + jQuery.event.trigger( e, null, elem ); + } else { + jQuery.event.dispatch.call( elem, e ); + } + if ( e.isDefaultPrevented() ) { + event.preventDefault(); + } + } +}; + +jQuery.removeEvent = function( elem, type, handle ) { + if ( elem.removeEventListener ) { + elem.removeEventListener( type, handle, false ); + } +}; + +jQuery.Event = function( src, props ) { + // Allow instantiation without the 'new' keyword + if ( !(this instanceof jQuery.Event) ) { + return new jQuery.Event( src, props ); + } + + // Event object + if ( src && src.type ) { + this.originalEvent = src; + this.type = src.type; + + // Events bubbling up the document may have been marked as prevented + // by a handler lower down the tree; reflect the correct value. + this.isDefaultPrevented = src.defaultPrevented || + src.defaultPrevented === undefined && + // Support: Android < 4.0 + src.returnValue === false ? + returnTrue : + returnFalse; + + // Event type + } else { + this.type = src; + } + + // Put explicitly provided properties onto the event object + if ( props ) { + jQuery.extend( this, props ); + } + + // Create a timestamp if incoming event doesn't have one + this.timeStamp = src && src.timeStamp || jQuery.now(); + + // Mark it as fixed + this[ jQuery.expando ] = true; +}; + +// jQuery.Event is based on DOM3 Events as specified by the ECMAScript Language Binding +// http://www.w3.org/TR/2003/WD-DOM-Level-3-Events-20030331/ecma-script-binding.html +jQuery.Event.prototype = { + isDefaultPrevented: returnFalse, + isPropagationStopped: returnFalse, + isImmediatePropagationStopped: returnFalse, + + preventDefault: function() { + var e = this.originalEvent; + + this.isDefaultPrevented = returnTrue; + + if ( e && e.preventDefault ) { + e.preventDefault(); + } + }, + stopPropagation: function() { + var e = this.originalEvent; + + this.isPropagationStopped = returnTrue; + + if ( e && e.stopPropagation ) { + e.stopPropagation(); + } + }, + stopImmediatePropagation: function() { + var e = this.originalEvent; + + this.isImmediatePropagationStopped = returnTrue; + + if ( e && e.stopImmediatePropagation ) { + e.stopImmediatePropagation(); + } + + this.stopPropagation(); + } +}; + +// Create mouseenter/leave events using mouseover/out and event-time checks +// Support: Chrome 15+ +jQuery.each({ + mouseenter: "mouseover", + mouseleave: "mouseout", + pointerenter: "pointerover", + pointerleave: "pointerout" +}, function( orig, fix ) { + jQuery.event.special[ orig ] = { + delegateType: fix, + bindType: fix, + + handle: function( event ) { + var ret, + target = this, + related = event.relatedTarget, + handleObj = event.handleObj; + + // For mousenter/leave call the handler if related is outside the target. + // NB: No relatedTarget if the mouse left/entered the browser window + if ( !related || (related !== target && !jQuery.contains( target, related )) ) { + event.type = handleObj.origType; + ret = handleObj.handler.apply( this, arguments ); + event.type = fix; + } + return ret; + } + }; +}); + +// Create "bubbling" focus and blur events +// Support: Firefox, Chrome, Safari +if ( !support.focusinBubbles ) { + jQuery.each({ focus: "focusin", blur: "focusout" }, function( orig, fix ) { + + // Attach a single capturing handler on the document while someone wants focusin/focusout + var handler = function( event ) { + jQuery.event.simulate( fix, event.target, jQuery.event.fix( event ), true ); + }; + + jQuery.event.special[ fix ] = { + setup: function() { + var doc = this.ownerDocument || this, + attaches = data_priv.access( doc, fix ); + + if ( !attaches ) { + doc.addEventListener( orig, handler, true ); + } + data_priv.access( doc, fix, ( attaches || 0 ) + 1 ); + }, + teardown: function() { + var doc = this.ownerDocument || this, + attaches = data_priv.access( doc, fix ) - 1; + + if ( !attaches ) { + doc.removeEventListener( orig, handler, true ); + data_priv.remove( doc, fix ); + + } else { + data_priv.access( doc, fix, attaches ); + } + } + }; + }); +} + +jQuery.fn.extend({ + + on: function( types, selector, data, fn, /*INTERNAL*/ one ) { + var origFn, type; + + // Types can be a map of types/handlers + if ( typeof types === "object" ) { + // ( types-Object, selector, data ) + if ( typeof selector !== "string" ) { + // ( types-Object, data ) + data = data || selector; + selector = undefined; + } + for ( type in types ) { + this.on( type, selector, data, types[ type ], one ); + } + return this; + } + + if ( data == null && fn == null ) { + // ( types, fn ) + fn = selector; + data = selector = undefined; + } else if ( fn == null ) { + if ( typeof selector === "string" ) { + // ( types, selector, fn ) + fn = data; + data = undefined; + } else { + // ( types, data, fn ) + fn = data; + data = selector; + selector = undefined; + } + } + if ( fn === false ) { + fn = returnFalse; + } else if ( !fn ) { + return this; + } + + if ( one === 1 ) { + origFn = fn; + fn = function( event ) { + // Can use an empty set, since event contains the info + jQuery().off( event ); + return origFn.apply( this, arguments ); + }; + // Use same guid so caller can remove using origFn + fn.guid = origFn.guid || ( origFn.guid = jQuery.guid++ ); + } + return this.each( function() { + jQuery.event.add( this, types, fn, data, selector ); + }); + }, + one: function( types, selector, data, fn ) { + return this.on( types, selector, data, fn, 1 ); + }, + off: function( types, selector, fn ) { + var handleObj, type; + if ( types && types.preventDefault && types.handleObj ) { + // ( event ) dispatched jQuery.Event + handleObj = types.handleObj; + jQuery( types.delegateTarget ).off( + handleObj.namespace ? handleObj.origType + "." + handleObj.namespace : handleObj.origType, + handleObj.selector, + handleObj.handler + ); + return this; + } + if ( typeof types === "object" ) { + // ( types-object [, selector] ) + for ( type in types ) { + this.off( type, selector, types[ type ] ); + } + return this; + } + if ( selector === false || typeof selector === "function" ) { + // ( types [, fn] ) + fn = selector; + selector = undefined; + } + if ( fn === false ) { + fn = returnFalse; + } + return this.each(function() { + jQuery.event.remove( this, types, fn, selector ); + }); + }, + + trigger: function( type, data ) { + return this.each(function() { + jQuery.event.trigger( type, data, this ); + }); + }, + triggerHandler: function( type, data ) { + var elem = this[0]; + if ( elem ) { + return jQuery.event.trigger( type, data, elem, true ); + } + } +}); + + +var + rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi, + rtagName = /<([\w:]+)/, + rhtml = /<|&#?\w+;/, + rnoInnerhtml = /<(?:script|style|link)/i, + // checked="checked" or checked + rchecked = /checked\s*(?:[^=]|=\s*.checked.)/i, + rscriptType = /^$|\/(?:java|ecma)script/i, + rscriptTypeMasked = /^true\/(.*)/, + rcleanScript = /^\s*\s*$/g, + + // We have to close these tags to support XHTML (#13200) + wrapMap = { + + // Support: IE 9 + option: [ 1, "" ], + + thead: [ 1, "", "
    " ], + col: [ 2, "", "
    " ], + tr: [ 2, "", "
    " ], + td: [ 3, "", "
    " ], + + _default: [ 0, "", "" ] + }; + +// Support: IE 9 +wrapMap.optgroup = wrapMap.option; + +wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead; +wrapMap.th = wrapMap.td; + +// Support: 1.x compatibility +// Manipulating tables requires a tbody +function manipulationTarget( elem, content ) { + return jQuery.nodeName( elem, "table" ) && + jQuery.nodeName( content.nodeType !== 11 ? content : content.firstChild, "tr" ) ? + + elem.getElementsByTagName("tbody")[0] || + elem.appendChild( elem.ownerDocument.createElement("tbody") ) : + elem; +} + +// Replace/restore the type attribute of script elements for safe DOM manipulation +function disableScript( elem ) { + elem.type = (elem.getAttribute("type") !== null) + "/" + elem.type; + return elem; +} +function restoreScript( elem ) { + var match = rscriptTypeMasked.exec( elem.type ); + + if ( match ) { + elem.type = match[ 1 ]; + } else { + elem.removeAttribute("type"); + } + + return elem; +} + +// Mark scripts as having already been evaluated +function setGlobalEval( elems, refElements ) { + var i = 0, + l = elems.length; + + for ( ; i < l; i++ ) { + data_priv.set( + elems[ i ], "globalEval", !refElements || data_priv.get( refElements[ i ], "globalEval" ) + ); + } +} + +function cloneCopyEvent( src, dest ) { + var i, l, type, pdataOld, pdataCur, udataOld, udataCur, events; + + if ( dest.nodeType !== 1 ) { + return; + } + + // 1. Copy private data: events, handlers, etc. + if ( data_priv.hasData( src ) ) { + pdataOld = data_priv.access( src ); + pdataCur = data_priv.set( dest, pdataOld ); + events = pdataOld.events; + + if ( events ) { + delete pdataCur.handle; + pdataCur.events = {}; + + for ( type in events ) { + for ( i = 0, l = events[ type ].length; i < l; i++ ) { + jQuery.event.add( dest, type, events[ type ][ i ] ); + } + } + } + } + + // 2. Copy user data + if ( data_user.hasData( src ) ) { + udataOld = data_user.access( src ); + udataCur = jQuery.extend( {}, udataOld ); + + data_user.set( dest, udataCur ); + } +} + +function getAll( context, tag ) { + var ret = context.getElementsByTagName ? context.getElementsByTagName( tag || "*" ) : + context.querySelectorAll ? context.querySelectorAll( tag || "*" ) : + []; + + return tag === undefined || tag && jQuery.nodeName( context, tag ) ? + jQuery.merge( [ context ], ret ) : + ret; +} + +// Support: IE >= 9 +function fixInput( src, dest ) { + var nodeName = dest.nodeName.toLowerCase(); + + // Fails to persist the checked state of a cloned checkbox or radio button. + if ( nodeName === "input" && rcheckableType.test( src.type ) ) { + dest.checked = src.checked; + + // Fails to return the selected option to the default selected state when cloning options + } else if ( nodeName === "input" || nodeName === "textarea" ) { + dest.defaultValue = src.defaultValue; + } +} + +jQuery.extend({ + clone: function( elem, dataAndEvents, deepDataAndEvents ) { + var i, l, srcElements, destElements, + clone = elem.cloneNode( true ), + inPage = jQuery.contains( elem.ownerDocument, elem ); + + // Support: IE >= 9 + // Fix Cloning issues + if ( !support.noCloneChecked && ( elem.nodeType === 1 || elem.nodeType === 11 ) && + !jQuery.isXMLDoc( elem ) ) { + + // We eschew Sizzle here for performance reasons: http://jsperf.com/getall-vs-sizzle/2 + destElements = getAll( clone ); + srcElements = getAll( elem ); + + for ( i = 0, l = srcElements.length; i < l; i++ ) { + fixInput( srcElements[ i ], destElements[ i ] ); + } + } + + // Copy the events from the original to the clone + if ( dataAndEvents ) { + if ( deepDataAndEvents ) { + srcElements = srcElements || getAll( elem ); + destElements = destElements || getAll( clone ); + + for ( i = 0, l = srcElements.length; i < l; i++ ) { + cloneCopyEvent( srcElements[ i ], destElements[ i ] ); + } + } else { + cloneCopyEvent( elem, clone ); + } + } + + // Preserve script evaluation history + destElements = getAll( clone, "script" ); + if ( destElements.length > 0 ) { + setGlobalEval( destElements, !inPage && getAll( elem, "script" ) ); + } + + // Return the cloned set + return clone; + }, + + buildFragment: function( elems, context, scripts, selection ) { + var elem, tmp, tag, wrap, contains, j, + fragment = context.createDocumentFragment(), + nodes = [], + i = 0, + l = elems.length; + + for ( ; i < l; i++ ) { + elem = elems[ i ]; + + if ( elem || elem === 0 ) { + + // Add nodes directly + if ( jQuery.type( elem ) === "object" ) { + // Support: QtWebKit + // jQuery.merge because push.apply(_, arraylike) throws + jQuery.merge( nodes, elem.nodeType ? [ elem ] : elem ); + + // Convert non-html into a text node + } else if ( !rhtml.test( elem ) ) { + nodes.push( context.createTextNode( elem ) ); + + // Convert html into DOM nodes + } else { + tmp = tmp || fragment.appendChild( context.createElement("div") ); + + // Deserialize a standard representation + tag = ( rtagName.exec( elem ) || [ "", "" ] )[ 1 ].toLowerCase(); + wrap = wrapMap[ tag ] || wrapMap._default; + tmp.innerHTML = wrap[ 1 ] + elem.replace( rxhtmlTag, "<$1>" ) + wrap[ 2 ]; + + // Descend through wrappers to the right content + j = wrap[ 0 ]; + while ( j-- ) { + tmp = tmp.lastChild; + } + + // Support: QtWebKit + // jQuery.merge because push.apply(_, arraylike) throws + jQuery.merge( nodes, tmp.childNodes ); + + // Remember the top-level container + tmp = fragment.firstChild; + + // Fixes #12346 + // Support: Webkit, IE + tmp.textContent = ""; + } + } + } + + // Remove wrapper from fragment + fragment.textContent = ""; + + i = 0; + while ( (elem = nodes[ i++ ]) ) { + + // #4087 - If origin and destination elements are the same, and this is + // that element, do not do anything + if ( selection && jQuery.inArray( elem, selection ) !== -1 ) { + continue; + } + + contains = jQuery.contains( elem.ownerDocument, elem ); + + // Append to fragment + tmp = getAll( fragment.appendChild( elem ), "script" ); + + // Preserve script evaluation history + if ( contains ) { + setGlobalEval( tmp ); + } + + // Capture executables + if ( scripts ) { + j = 0; + while ( (elem = tmp[ j++ ]) ) { + if ( rscriptType.test( elem.type || "" ) ) { + scripts.push( elem ); + } + } + } + } + + return fragment; + }, + + cleanData: function( elems ) { + var data, elem, type, key, + special = jQuery.event.special, + i = 0; + + for ( ; (elem = elems[ i ]) !== undefined; i++ ) { + if ( jQuery.acceptData( elem ) ) { + key = elem[ data_priv.expando ]; + + if ( key && (data = data_priv.cache[ key ]) ) { + if ( data.events ) { + for ( type in data.events ) { + if ( special[ type ] ) { + jQuery.event.remove( elem, type ); + + // This is a shortcut to avoid jQuery.event.remove's overhead + } else { + jQuery.removeEvent( elem, type, data.handle ); + } + } + } + if ( data_priv.cache[ key ] ) { + // Discard any remaining `private` data + delete data_priv.cache[ key ]; + } + } + } + // Discard any remaining `user` data + delete data_user.cache[ elem[ data_user.expando ] ]; + } + } +}); + +jQuery.fn.extend({ + text: function( value ) { + return access( this, function( value ) { + return value === undefined ? + jQuery.text( this ) : + this.empty().each(function() { + if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) { + this.textContent = value; + } + }); + }, null, value, arguments.length ); + }, + + append: function() { + return this.domManip( arguments, function( elem ) { + if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) { + var target = manipulationTarget( this, elem ); + target.appendChild( elem ); + } + }); + }, + + prepend: function() { + return this.domManip( arguments, function( elem ) { + if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) { + var target = manipulationTarget( this, elem ); + target.insertBefore( elem, target.firstChild ); + } + }); + }, + + before: function() { + return this.domManip( arguments, function( elem ) { + if ( this.parentNode ) { + this.parentNode.insertBefore( elem, this ); + } + }); + }, + + after: function() { + return this.domManip( arguments, function( elem ) { + if ( this.parentNode ) { + this.parentNode.insertBefore( elem, this.nextSibling ); + } + }); + }, + + remove: function( selector, keepData /* Internal Use Only */ ) { + var elem, + elems = selector ? jQuery.filter( selector, this ) : this, + i = 0; + + for ( ; (elem = elems[i]) != null; i++ ) { + if ( !keepData && elem.nodeType === 1 ) { + jQuery.cleanData( getAll( elem ) ); + } + + if ( elem.parentNode ) { + if ( keepData && jQuery.contains( elem.ownerDocument, elem ) ) { + setGlobalEval( getAll( elem, "script" ) ); + } + elem.parentNode.removeChild( elem ); + } + } + + return this; + }, + + empty: function() { + var elem, + i = 0; + + for ( ; (elem = this[i]) != null; i++ ) { + if ( elem.nodeType === 1 ) { + + // Prevent memory leaks + jQuery.cleanData( getAll( elem, false ) ); + + // Remove any remaining nodes + elem.textContent = ""; + } + } + + return this; + }, + + clone: function( dataAndEvents, deepDataAndEvents ) { + dataAndEvents = dataAndEvents == null ? false : dataAndEvents; + deepDataAndEvents = deepDataAndEvents == null ? dataAndEvents : deepDataAndEvents; + + return this.map(function() { + return jQuery.clone( this, dataAndEvents, deepDataAndEvents ); + }); + }, + + html: function( value ) { + return access( this, function( value ) { + var elem = this[ 0 ] || {}, + i = 0, + l = this.length; + + if ( value === undefined && elem.nodeType === 1 ) { + return elem.innerHTML; + } + + // See if we can take a shortcut and just use innerHTML + if ( typeof value === "string" && !rnoInnerhtml.test( value ) && + !wrapMap[ ( rtagName.exec( value ) || [ "", "" ] )[ 1 ].toLowerCase() ] ) { + + value = value.replace( rxhtmlTag, "<$1>" ); + + try { + for ( ; i < l; i++ ) { + elem = this[ i ] || {}; + + // Remove element nodes and prevent memory leaks + if ( elem.nodeType === 1 ) { + jQuery.cleanData( getAll( elem, false ) ); + elem.innerHTML = value; + } + } + + elem = 0; + + // If using innerHTML throws an exception, use the fallback method + } catch( e ) {} + } + + if ( elem ) { + this.empty().append( value ); + } + }, null, value, arguments.length ); + }, + + replaceWith: function() { + var arg = arguments[ 0 ]; + + // Make the changes, replacing each context element with the new content + this.domManip( arguments, function( elem ) { + arg = this.parentNode; + + jQuery.cleanData( getAll( this ) ); + + if ( arg ) { + arg.replaceChild( elem, this ); + } + }); + + // Force removal if there was no new content (e.g., from empty arguments) + return arg && (arg.length || arg.nodeType) ? this : this.remove(); + }, + + detach: function( selector ) { + return this.remove( selector, true ); + }, + + domManip: function( args, callback ) { + + // Flatten any nested arrays + args = concat.apply( [], args ); + + var fragment, first, scripts, hasScripts, node, doc, + i = 0, + l = this.length, + set = this, + iNoClone = l - 1, + value = args[ 0 ], + isFunction = jQuery.isFunction( value ); + + // We can't cloneNode fragments that contain checked, in WebKit + if ( isFunction || + ( l > 1 && typeof value === "string" && + !support.checkClone && rchecked.test( value ) ) ) { + return this.each(function( index ) { + var self = set.eq( index ); + if ( isFunction ) { + args[ 0 ] = value.call( this, index, self.html() ); + } + self.domManip( args, callback ); + }); + } + + if ( l ) { + fragment = jQuery.buildFragment( args, this[ 0 ].ownerDocument, false, this ); + first = fragment.firstChild; + + if ( fragment.childNodes.length === 1 ) { + fragment = first; + } + + if ( first ) { + scripts = jQuery.map( getAll( fragment, "script" ), disableScript ); + hasScripts = scripts.length; + + // Use the original fragment for the last item instead of the first because it can end up + // being emptied incorrectly in certain situations (#8070). + for ( ; i < l; i++ ) { + node = fragment; + + if ( i !== iNoClone ) { + node = jQuery.clone( node, true, true ); + + // Keep references to cloned scripts for later restoration + if ( hasScripts ) { + // Support: QtWebKit + // jQuery.merge because push.apply(_, arraylike) throws + jQuery.merge( scripts, getAll( node, "script" ) ); + } + } + + callback.call( this[ i ], node, i ); + } + + if ( hasScripts ) { + doc = scripts[ scripts.length - 1 ].ownerDocument; + + // Reenable scripts + jQuery.map( scripts, restoreScript ); + + // Evaluate executable scripts on first document insertion + for ( i = 0; i < hasScripts; i++ ) { + node = scripts[ i ]; + if ( rscriptType.test( node.type || "" ) && + !data_priv.access( node, "globalEval" ) && jQuery.contains( doc, node ) ) { + + if ( node.src ) { + // Optional AJAX dependency, but won't run scripts if not present + if ( jQuery._evalUrl ) { + jQuery._evalUrl( node.src ); + } + } else { + jQuery.globalEval( node.textContent.replace( rcleanScript, "" ) ); + } + } + } + } + } + } + + return this; + } +}); + +jQuery.each({ + appendTo: "append", + prependTo: "prepend", + insertBefore: "before", + insertAfter: "after", + replaceAll: "replaceWith" +}, function( name, original ) { + jQuery.fn[ name ] = function( selector ) { + var elems, + ret = [], + insert = jQuery( selector ), + last = insert.length - 1, + i = 0; + + for ( ; i <= last; i++ ) { + elems = i === last ? this : this.clone( true ); + jQuery( insert[ i ] )[ original ]( elems ); + + // Support: QtWebKit + // .get() because push.apply(_, arraylike) throws + push.apply( ret, elems.get() ); + } + + return this.pushStack( ret ); + }; +}); + + +var iframe, + elemdisplay = {}; + +/** + * Retrieve the actual display of a element + * @param {String} name nodeName of the element + * @param {Object} doc Document object + */ +// Called only from within defaultDisplay +function actualDisplay( name, doc ) { + var style, + elem = jQuery( doc.createElement( name ) ).appendTo( doc.body ), + + // getDefaultComputedStyle might be reliably used only on attached element + display = window.getDefaultComputedStyle && ( style = window.getDefaultComputedStyle( elem[ 0 ] ) ) ? + + // Use of this method is a temporary fix (more like optmization) until something better comes along, + // since it was removed from specification and supported only in FF + style.display : jQuery.css( elem[ 0 ], "display" ); + + // We don't have any data stored on the element, + // so use "detach" method as fast way to get rid of the element + elem.detach(); + + return display; +} + +/** + * Try to determine the default display value of an element + * @param {String} nodeName + */ +function defaultDisplay( nodeName ) { + var doc = document, + display = elemdisplay[ nodeName ]; + + if ( !display ) { + display = actualDisplay( nodeName, doc ); + + // If the simple way fails, read from inside an iframe + if ( display === "none" || !display ) { + + // Use the already-created iframe if possible + iframe = (iframe || jQuery( "
    + + + + + + --> + + + + + + + + + + + + + + + + + + + + + + +
    +
    +
    +
    +
    +
    +
    +
    +
    + + + + + diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/notebook-integration/scripts/view-models/notebook-viz.html b/ecomp-sdk-app/src/main/webapp/app/fusion/notebook-integration/scripts/view-models/notebook-viz.html new file mode 100644 index 000000000..3c0afd29a --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/notebook-integration/scripts/view-models/notebook-viz.html @@ -0,0 +1,26 @@ + +
    + + +
    + + +
    diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/notebook-integration/scripts/view-models/notebook.htm b/ecomp-sdk-app/src/main/webapp/app/fusion/notebook-integration/scripts/view-models/notebook.htm new file mode 100644 index 000000000..bfd74ad32 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/notebook-integration/scripts/view-models/notebook.htm @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + +
    +
    +
    +
    +
    +
    +
    +
    +
    + + diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/notebook-integration/scripts/view-models/notebookInputs.html b/ecomp-sdk-app/src/main/webapp/app/fusion/notebook-integration/scripts/view-models/notebookInputs.html new file mode 100644 index 000000000..0a28b50ed --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/notebook-integration/scripts/view-models/notebookInputs.html @@ -0,0 +1,90 @@ + + + + + + + + + + +
    +
    +
    +
    + +
    +
    + + + + + + +
    +
    +
    + +
    + +
    + +
    + +
    +
    + +
    + +
    + + + Remove +
    +
    +
    +
    + + + + +
    + +
    + Submit +
    + + + +
    + + diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/att_angular_gridster/angular-gridster.js b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/att_angular_gridster/angular-gridster.js new file mode 100644 index 000000000..985fa4341 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/att_angular_gridster/angular-gridster.js @@ -0,0 +1,2244 @@ +/*global define:true*/ +(function(root, factory) { + + 'use strict'; + + if (typeof define === 'function' && define.amd) { + // AMD + define(['angular'], factory); + } else if (typeof exports === 'object') { + // CommonJS + module.exports = factory(require('angular')); + } else { + // Browser, nothing "exported". Only registered as a module with angular. + factory(root.angular); + } +}(this, function(angular) { + + 'use strict'; + + var ie8 = false; + + var getInternetExplorerVersion = function () + // Returns the version of Internet Explorer >4 or + // undefined(indicating the use of another browser). + { + var isIE10 = (eval("/*@cc_on!@*/false") && document.documentMode === 10); + if (isIE10) { + return 10; + } + var v = 3, + div = document.createElement('div'), + all = div.getElementsByTagName('i'); + do { + div.innerHTML = ''; + } while (all[0]); + return v > 4 ? v : undefined; + }; + + var browserVersion = getInternetExplorerVersion(); + + if (browserVersion && browserVersion < 9) { + ie8 = true; + } + + // This returned angular module 'gridster' is what is exported. + return angular.module('attGridsterLib', []) + + .constant('gridsterConfig', { + columns: 6, // number of columns in the grid + pushing: true, // whether to push other items out of the way + floating: true, // whether to automatically float items up so they stack + swapping: true, // whether or not to have items switch places instead of push down if they are the same size + width: 'auto', // width of the grid. "auto" will expand the grid to its parent container + colWidth: 'auto', // width of grid columns. "auto" will divide the width of the grid evenly among the columns + rowHeight: 'match', // height of grid rows. 'match' will make it the same as the column width, a numeric value will be interpreted as pixels, '/2' is half the column width, '*5' is five times the column width, etc. + margins: [10, 10], // margins in between grid items + outerMargin: false, + isMobile: false, // toggle mobile view + mobileBreakPoint: 100, // width threshold to toggle mobile mode + mobileModeEnabled: true, // whether or not to toggle mobile mode when screen width is less than mobileBreakPoint + minColumns: 1, // minimum amount of columns the grid can scale down to + minRows: 1, // minimum amount of rows to show if the grid is empty + maxRows: 100, // maximum amount of rows in the grid + defaultSizeX: 1, // default width of an item in columns + defaultSizeY: 1, // default height of an item in rows + minSizeX: 1, // minimum column width of an item + maxSizeX: null, // maximum column width of an item + minSizeY: 1, // minumum row height of an item + maxSizeY: null, // maximum row height of an item + saveGridItemCalculatedHeightInMobile: false, // grid item height in mobile display. true- to use the calculated height by sizeY given + resizable: { // options to pass to resizable handler + enabled: false, + handles: ['s', 'e', 'n', 'w', 'se', 'ne', 'sw', 'nw'] + }, + draggable: { // options to pass to draggable handler + enabled: true, + scrollSensitivity: 20, // Distance in pixels from the edge of the viewport after which the viewport should scroll, relative to pointer + scrollSpeed: 15 // Speed at which the window should scroll once the mouse pointer gets within scrollSensitivity distance + } + }) + + .controller('GridsterCtrl', ['gridsterConfig', '$timeout', + function(gridsterConfig, $timeout) { + + var gridster = this; + + /** + * Create options from gridsterConfig constant + */ + angular.extend(this, gridsterConfig); + + this.resizable = angular.extend({}, gridsterConfig.resizable || {}); + this.draggable = angular.extend({}, gridsterConfig.draggable || {}); + + var flag = false; + this.layoutChanged = function() { + if (flag) { + return; + } + flag = true; + $timeout(function() { + flag = false; + if (gridster.loaded) { + gridster.floatItemsUp(); + } + gridster.updateHeight(gridster.movingItem ? gridster.movingItem.sizeY : 0); + }, 30); + }; + + /** + * A positional array of the items in the grid + */ + this.grid = []; + + /** + * Clean up after yourself + */ + this.destroy = function() { + // empty the grid to cut back on the possibility + // of circular references + if (this.grid) { + this.grid = []; + } + this.$element = null; + }; + + /** + * Overrides default options + * + * @param {Object} options The options to override + */ + this.setOptions = function(options) { + if (!options) { + return; + } + + options = angular.extend({}, options); + + // all this to avoid using jQuery... + if (options.draggable) { + angular.extend(this.draggable, options.draggable); + delete(options.draggable); + } + if (options.resizable) { + angular.extend(this.resizable, options.resizable); + delete(options.resizable); + } + + angular.extend(this, options); + + if (!this.margins || this.margins.length !== 2) { + this.margins = [0, 0]; + } else { + for (var x = 0, l = this.margins.length; x < l; ++x) { + this.margins[x] = parseInt(this.margins[x], 10); + if (isNaN(this.margins[x])) { + this.margins[x] = 0; + } + } + } + }; + + /** + * Check if item can occupy a specified position in the grid + * + * @param {Object} item The item in question + * @param {Number} row The row index + * @param {Number} column The column index + * @returns {Boolean} True if if item fits + */ + this.canItemOccupy = function(item, row, column) { + return row > -1 && column > -1 && item.sizeX + column <= this.columns && item.sizeY + row <= this.maxRows; + }; + + /** + * Set the item in the first suitable position + * + * @param {Object} item The item to insert + */ + this.autoSetItemPosition = function(item) { + // walk through each row and column looking for a place it will fit + for (var rowIndex = 0; rowIndex < this.maxRows; ++rowIndex) { + for (var colIndex = 0; colIndex < this.columns; ++colIndex) { + // only insert if position is not already taken and it can fit + var items = this.getItems(rowIndex, colIndex, item.sizeX, item.sizeY, item); + if (items.length === 0 && this.canItemOccupy(item, rowIndex, colIndex)) { + this.putItem(item, rowIndex, colIndex); + return; + } + } + } + throw new Error('Unable to place item!'); + }; + + /** + * Gets items at a specific coordinate + * + * @param {Number} row + * @param {Number} column + * @param {Number} sizeX + * @param {Number} sizeY + * @param {Array} excludeItems An array of items to exclude from selection + * @returns {Array} Items that match the criteria + */ + this.getItems = function(row, column, sizeX, sizeY, excludeItems) { + var items = []; + if (!sizeX || !sizeY) { + sizeX = sizeY = 1; + } + if (excludeItems && !(excludeItems instanceof Array)) { + excludeItems = [excludeItems]; + } + for (var h = 0; h < sizeY; ++h) { + for (var w = 0; w < sizeX; ++w) { + var item = this.getItem(row + h, column + w, excludeItems); + if (item && (!excludeItems || excludeItems.indexOf(item) === -1) && items.indexOf(item) === -1) { + items.push(item); + } + } + } + return items; + }; + + /** + * @param {Array} items + * @returns {Object} An item that represents the bounding box of the items + */ + this.getBoundingBox = function(items) { + + if (items.length === 0) { + return null; + } + if (items.length === 1) { + return { + row: items[0].row, + col: items[0].col, + sizeY: items[0].sizeY, + sizeX: items[0].sizeX + }; + } + + var maxRow = 0; + var maxCol = 0; + var minRow = 9999; + var minCol = 9999; + + for (var i = 0, l = items.length; i < l; ++i) { + var item = items[i]; + minRow = Math.min(item.row, minRow); + minCol = Math.min(item.col, minCol); + maxRow = Math.max(item.row + item.sizeY, maxRow); + maxCol = Math.max(item.col + item.sizeX, maxCol); + } + + return { + row: minRow, + col: minCol, + sizeY: maxRow - minRow, + sizeX: maxCol - minCol + }; + }; + + + /** + * Removes an item from the grid + * + * @param {Object} item + */ + this.removeItem = function(item) { + for (var rowIndex = 0, l = this.grid.length; rowIndex < l; ++rowIndex) { + var columns = this.grid[rowIndex]; + if (!columns) { + continue; + } + var index = columns.indexOf(item); + if (index !== -1) { + columns[index] = null; + break; + } + } + this.layoutChanged(); + }; + + /** + * Returns the item at a specified coordinate + * + * @param {Number} row + * @param {Number} column + * @param {Array} excludeItems Items to exclude from selection + * @returns {Object} The matched item or null + */ + this.getItem = function(row, column, excludeItems) { + if (excludeItems && !(excludeItems instanceof Array)) { + excludeItems = [excludeItems]; + } + var sizeY = 1; + while (row > -1) { + var sizeX = 1, + col = column; + while (col > -1) { + var items = this.grid[row]; + if (items) { + var item = items[col]; + if (item && (!excludeItems || excludeItems.indexOf(item) === -1) && item.sizeX >= sizeX && item.sizeY >= sizeY) { + return item; + } + } + ++sizeX; + --col; + } + --row; + ++sizeY; + } + return null; + }; + + /** + * Insert an array of items into the grid + * + * @param {Array} items An array of items to insert + */ + this.putItems = function(items) { + for (var i = 0, l = items.length; i < l; ++i) { + this.putItem(items[i]); + } + }; + + /** + * Insert a single item into the grid + * + * @param {Object} item The item to insert + * @param {Number} row (Optional) Specifies the items row index + * @param {Number} column (Optional) Specifies the items column index + * @param {Array} ignoreItems + */ + this.putItem = function(item, row, column, ignoreItems) { + // auto place item if no row specified + if (typeof row === 'undefined' || row === null) { + row = item.row; + column = item.col; + if (typeof row === 'undefined' || row === null) { + this.autoSetItemPosition(item); + return; + } + } + + // keep item within allowed bounds + if (!this.canItemOccupy(item, row, column)) { + column = Math.min(this.columns - item.sizeX, Math.max(0, column)); + row = Math.min(this.maxRows - item.sizeY, Math.max(0, row)); + } + + // check if item is already in grid + if (item.oldRow !== null && typeof item.oldRow !== 'undefined') { + var samePosition = item.oldRow === row && item.oldColumn === column; + var inGrid = this.grid[row] && this.grid[row][column] === item; + if (samePosition && inGrid) { + item.row = row; + item.col = column; + return; + } else { + // remove from old position + var oldRow = this.grid[item.oldRow]; + if (oldRow && oldRow[item.oldColumn] === item) { + delete oldRow[item.oldColumn]; + } + } + } + + item.oldRow = item.row = row; + item.oldColumn = item.col = column; + + this.moveOverlappingItems(item, ignoreItems); + + if (!this.grid[row]) { + this.grid[row] = []; + } + this.grid[row][column] = item; + + if (this.movingItem === item) { + this.floatItemUp(item); + } + this.layoutChanged(); + }; + + /** + * Trade row and column if item1 with item2 + * + * @param {Object} item1 + * @param {Object} item2 + */ + this.swapItems = function(item1, item2) { + this.grid[item1.row][item1.col] = item2; + this.grid[item2.row][item2.col] = item1; + + var item1Row = item1.row; + var item1Col = item1.col; + item1.row = item2.row; + item1.col = item2.col; + item2.row = item1Row; + item2.col = item1Col; + }; + + /** + * Prevents items from being overlapped + * + * @param {Object} item The item that should remain + * @param {Array} ignoreItems + */ + this.moveOverlappingItems = function(item, ignoreItems) { + // don't move item, so ignore it + if (!ignoreItems) { + ignoreItems = [item]; + } else if (ignoreItems.indexOf(item) === -1) { + ignoreItems = ignoreItems.slice(0); + ignoreItems.push(item); + } + + // get the items in the space occupied by the item's coordinates + var overlappingItems = this.getItems( + item.row, + item.col, + item.sizeX, + item.sizeY, + ignoreItems + ); + this.moveItemsDown(overlappingItems, item.row + item.sizeY, ignoreItems); + }; + + /** + * Moves an array of items to a specified row + * + * @param {Array} items The items to move + * @param {Number} newRow The target row + * @param {Array} ignoreItems + */ + this.moveItemsDown = function(items, newRow, ignoreItems) { + if (!items || items.length === 0) { + return; + } + items.sort(function(a, b) { + return a.row - b.row; + }); + + ignoreItems = ignoreItems ? ignoreItems.slice(0) : []; + var topRows = {}, + item, i, l; + + // calculate the top rows in each column + for (i = 0, l = items.length; i < l; ++i) { + item = items[i]; + var topRow = topRows[item.col]; + if (typeof topRow === 'undefined' || item.row < topRow) { + topRows[item.col] = item.row; + } + } + + // move each item down from the top row in its column to the row + for (i = 0, l = items.length; i < l; ++i) { + item = items[i]; + var rowsToMove = newRow - topRows[item.col]; + this.moveItemDown(item, item.row + rowsToMove, ignoreItems); + ignoreItems.push(item); + } + }; + + /** + * Moves an item down to a specified row + * + * @param {Object} item The item to move + * @param {Number} newRow The target row + * @param {Array} ignoreItems + */ + this.moveItemDown = function(item, newRow, ignoreItems) { + if (item.row >= newRow) { + return; + } + while (item.row < newRow) { + ++item.row; + this.moveOverlappingItems(item, ignoreItems); + } + this.putItem(item, item.row, item.col, ignoreItems); + }; + + /** + * Moves all items up as much as possible + */ + this.floatItemsUp = function() { + if (this.floating === false) { + return; + } + for (var rowIndex = 0, l = this.grid.length; rowIndex < l; ++rowIndex) { + var columns = this.grid[rowIndex]; + if (!columns) { + continue; + } + for (var colIndex = 0, len = columns.length; colIndex < len; ++colIndex) { + var item = columns[colIndex]; + if (item) { + this.floatItemUp(item); + } + } + } + }; + + /** + * Float an item up to the most suitable row + * + * @param {Object} item The item to move + */ + this.floatItemUp = function(item) { + if (this.floating === false) { + return; + } + var colIndex = item.col, + sizeY = item.sizeY, + sizeX = item.sizeX, + bestRow = null, + bestColumn = null, + rowIndex = item.row - 1; + + while (rowIndex > -1) { + var items = this.getItems(rowIndex, colIndex, sizeX, sizeY, item); + if (items.length !== 0) { + break; + } + bestRow = rowIndex; + bestColumn = colIndex; + --rowIndex; + } + if (bestRow !== null) { + this.putItem(item, bestRow, bestColumn); + } + }; + + /** + * Update gridsters height + * + * @param {Number} plus (Optional) Additional height to add + */ + this.updateHeight = function(plus) { + var maxHeight = this.minRows; + plus = plus || 0; + for (var rowIndex = this.grid.length; rowIndex >= 0; --rowIndex) { + var columns = this.grid[rowIndex]; + if (!columns) { + continue; + } + for (var colIndex = 0, len = columns.length; colIndex < len; ++colIndex) { + if (columns[colIndex]) { + maxHeight = Math.max(maxHeight, rowIndex + plus + columns[colIndex].sizeY); + } + } + } + this.gridHeight = this.maxRows - maxHeight > 0 ? Math.min(this.maxRows, maxHeight) : Math.max(this.maxRows, maxHeight); + }; + + /** + * Returns the number of rows that will fit in given amount of pixels + * + * @param {Number} pixels + * @param {Boolean} ceilOrFloor (Optional) Determines rounding method + */ + this.pixelsToRows = function(pixels, ceilOrFloor) { + if (ceilOrFloor === true) { + return Math.ceil(pixels / this.curRowHeight); + } else if (ceilOrFloor === false) { + return Math.floor(pixels / this.curRowHeight); + } + + return Math.round(pixels / this.curRowHeight); + }; + + /** + * Returns the number of columns that will fit in a given amount of pixels + * + * @param {Number} pixels + * @param {Boolean} ceilOrFloor (Optional) Determines rounding method + * @returns {Number} The number of columns + */ + this.pixelsToColumns = function(pixels, ceilOrFloor) { + if (ceilOrFloor === true) { + return Math.ceil(pixels / this.curColWidth); + } else if (ceilOrFloor === false) { + return Math.floor(pixels / this.curColWidth); + } + + return Math.round(pixels / this.curColWidth); + }; + } + ]) + + .directive('gridsterPreview', function() { + return { + replace: true, + scope: true, + require: '^gridster', + template: '
    ', + link: function(scope, $el, attrs, gridster) { + + /** + * @returns {Object} style object for preview element + */ + scope.previewStyle = function() { + + if (!gridster.movingItem) { + return { + display: 'none' + }; + } + + return { + display: 'block', + height: (gridster.movingItem.sizeY * gridster.curRowHeight - gridster.margins[0]) + 'px', + width: (gridster.movingItem.sizeX * gridster.curColWidth - gridster.margins[1]) + 'px', + top: (gridster.movingItem.row * gridster.curRowHeight + (gridster.outerMargin ? gridster.margins[0] : 0)) + 'px', + left: (gridster.movingItem.col * gridster.curColWidth + (gridster.outerMargin ? gridster.margins[1] : 0)) + 'px' + }; + }; + } + }; + }) + + /** + * The gridster directive + * + * @param {Function} $timeout + * @param {Object} $window + * @param {Object} $rootScope + * @param {Function} gridsterDebounce + */ + .directive('gridster', ['$timeout', '$window', '$rootScope', 'gridsterDebounce', + function($timeout, $window, $rootScope, gridsterDebounce) { + return { + scope: true, + restrict: 'EAC', + controller: 'GridsterCtrl', + controllerAs: 'gridster', + compile: function($tplElem) { + + $tplElem.prepend('
    '); + + return function(scope, $elem, attrs, gridster) { + gridster.loaded = false; + + gridster.$element = $elem; + + scope.gridster = gridster; + + $elem.addClass('gridster'); + + var isVisible = function(ele) { + return ele.style.visibility !== 'hidden' && ele.style.display !== 'none'; + }; + + function refresh(config) { + gridster.setOptions(config); + + if (!isVisible($elem[0])) { + return; + } + + // resolve "auto" & "match" values + if (gridster.width === 'auto') { + gridster.curWidth = $elem[0].offsetWidth || parseInt($elem.css('width'), 10); + } else { + gridster.curWidth = gridster.width; + } + + if (gridster.colWidth === 'auto') { + gridster.curColWidth = (gridster.curWidth + (gridster.outerMargin ? -gridster.margins[1] : gridster.margins[1])) / gridster.columns; + } else { + gridster.curColWidth = gridster.colWidth; + } + + gridster.curRowHeight = gridster.rowHeight; + if (typeof gridster.rowHeight === 'string') { + if (gridster.rowHeight === 'match') { + gridster.curRowHeight = Math.round(gridster.curColWidth); + } else if (gridster.rowHeight.indexOf('*') !== -1) { + gridster.curRowHeight = Math.round(gridster.curColWidth * gridster.rowHeight.replace('*', '').replace(' ', '')); + } else if (gridster.rowHeight.indexOf('/') !== -1) { + gridster.curRowHeight = Math.round(gridster.curColWidth / gridster.rowHeight.replace('/', '').replace(' ', '')); + } + } + + gridster.isMobile = gridster.mobileModeEnabled && gridster.curWidth <= gridster.mobileBreakPoint; + + // loop through all items and reset their CSS + for (var rowIndex = 0, l = gridster.grid.length; rowIndex < l; ++rowIndex) { + var columns = gridster.grid[rowIndex]; + if (!columns) { + continue; + } + + for (var colIndex = 0, len = columns.length; colIndex < len; ++colIndex) { + if (columns[colIndex]) { + var item = columns[colIndex]; + item.setElementPosition(); + item.setElementSizeY(); + item.setElementSizeX(); + } + } + } + + updateHeight(); + } + + var optionsKey = attrs.gridster; + if (optionsKey) { + scope.$parent.$watch(optionsKey, function(newConfig) { + refresh(newConfig); + }, true); + } else { + refresh({}); + } + + scope.$watch(function() { + return gridster.loaded; + }, function() { + if (gridster.loaded) { + $elem.addClass('gridster-loaded'); + } else { + $elem.removeClass('gridster-loaded'); + } + }); + + scope.$watch(function() { + return gridster.isMobile; + }, function() { + if (gridster.isMobile) { + $elem.addClass('gridster-mobile').removeClass('gridster-desktop'); + } else { + $elem.removeClass('gridster-mobile').addClass('gridster-desktop'); + } + $rootScope.$broadcast('gridster-mobile-changed', gridster); + }); + + scope.$watch(function() { + return gridster.draggable; + }, function() { + $rootScope.$broadcast('gridster-draggable-changed', gridster); + }, true); + + scope.$watch(function() { + return gridster.resizable; + }, function() { + $rootScope.$broadcast('gridster-resizable-changed', gridster); + }, true); + + function updateHeight() { + if(gridster.gridHeight){ //need to put this check, otherwise fail in IE8 + $elem.css('height', (gridster.gridHeight * gridster.curRowHeight) + (gridster.outerMargin ? gridster.margins[0] : -gridster.margins[0]) + 'px'); + } + } + + scope.$watch(function() { + return gridster.gridHeight; + }, updateHeight); + + scope.$watch(function() { + return gridster.movingItem; + }, function() { + gridster.updateHeight(gridster.movingItem ? gridster.movingItem.sizeY : 0); + }); + + var prevWidth = $elem[0].offsetWidth || parseInt($elem.css('width'), 10); + + var resize = function() { + var width = $elem[0].offsetWidth || parseInt($elem.css('width'), 10); + + if (!width || width === prevWidth || gridster.movingItem) { + return; + } + prevWidth = width; + + if (gridster.loaded) { + $elem.removeClass('gridster-loaded'); + } + + refresh(); + + if (gridster.loaded) { + $elem.addClass('gridster-loaded'); + } + + $rootScope.$broadcast('gridster-resized', [width, $elem[0].offsetHeight], gridster); + }; + + // track element width changes any way we can + var onResize = gridsterDebounce(function onResize() { + resize(); + $timeout(function() { + scope.$apply(); + }); + }, 100); + + scope.$watch(function() { + return isVisible($elem[0]); + }, onResize); + + // see https://github.com/sdecima/javascript-detect-element-resize + if (typeof window.addResizeListener === 'function') { + window.addResizeListener($elem[0], onResize); + } else { + scope.$watch(function() { + return $elem[0].offsetWidth || parseInt($elem.css('width'), 10); + }, resize); + } + var $win = angular.element($window); + $win.on('resize', onResize); + + // be sure to cleanup + scope.$on('$destroy', function() { + gridster.destroy(); + $win.off('resize', onResize); + if (typeof window.removeResizeListener === 'function') { + window.removeResizeListener($elem[0], onResize); + } + }); + + // allow a little time to place items before floating up + $timeout(function() { + scope.$watch('gridster.floating', function() { + gridster.floatItemsUp(); + }); + gridster.loaded = true; + }, 100); + }; + } + }; + } + ]) + + .controller('GridsterItemCtrl', function() { + this.$element = null; + this.gridster = null; + this.row = null; + this.col = null; + this.sizeX = null; + this.sizeY = null; + this.minSizeX = 0; + this.minSizeY = 0; + this.maxSizeX = null; + this.maxSizeY = null; + + this.init = function($element, gridster) { + this.$element = $element; + this.gridster = gridster; + this.sizeX = gridster.defaultSizeX; + this.sizeY = gridster.defaultSizeY; + }; + + this.destroy = function() { + // set these to null to avoid the possibility of circular references + this.gridster = null; + this.$element = null; + }; + + /** + * Returns the items most important attributes + */ + this.toJSON = function() { + return { + row: this.row, + col: this.col, + sizeY: this.sizeY, + sizeX: this.sizeX + }; + }; + + this.isMoving = function() { + return this.gridster.movingItem === this; + }; + + /** + * Set the items position + * + * @param {Number} row + * @param {Number} column + */ + this.setPosition = function(row, column) { + this.gridster.putItem(this, row, column); + + if (!this.isMoving()) { + this.setElementPosition(); + } + }; + + /** + * Sets a specified size property + * + * @param {String} key Can be either "x" or "y" + * @param {Number} value The size amount + * @param {Boolean} preventMove + */ + this.setSize = function(key, value, preventMove) { + key = key.toUpperCase(); + var camelCase = 'size' + key, + titleCase = 'Size' + key; + if (value === '') { + return; + } + value = parseInt(value, 10); + if (isNaN(value) || value === 0) { + value = this.gridster['default' + titleCase]; + } + var max = key === 'X' ? this.gridster.columns : this.gridster.maxRows; + if (this['max' + titleCase]) { + max = Math.min(this['max' + titleCase], max); + } + if (this.gridster['max' + titleCase]) { + max = Math.min(this.gridster['max' + titleCase], max); + } + if (key === 'X' && this.cols) { + max -= this.cols; + } else if (key === 'Y' && this.rows) { + max -= this.rows; + } + + var min = 0; + if (this['min' + titleCase]) { + min = Math.max(this['min' + titleCase], min); + } + if (this.gridster['min' + titleCase]) { + min = Math.max(this.gridster['min' + titleCase], min); + } + + value = Math.max(Math.min(value, max), min); + + var changed = (this[camelCase] !== value || (this['old' + titleCase] && this['old' + titleCase] !== value)); + this['old' + titleCase] = this[camelCase] = value; + + if (!this.isMoving()) { + this['setElement' + titleCase](); + } + if (!preventMove && changed) { + this.gridster.moveOverlappingItems(this); + this.gridster.layoutChanged(); + } + + return changed; + }; + + /** + * Sets the items sizeY property + * + * @param {Number} rows + * @param {Boolean} preventMove + */ + this.setSizeY = function(rows, preventMove) { + return this.setSize('Y', rows, preventMove); + }; + + /** + * Sets the items sizeX property + * + * @param {Number} columns + * @param {Boolean} preventMove + */ + this.setSizeX = function(columns, preventMove) { + return this.setSize('X', columns, preventMove); + }; + + /** + * Sets an elements position on the page + */ + this.setElementPosition = function() { + if (this.gridster.isMobile) { + this.$element.css({ + marginLeft: this.gridster.margins[0] + 'px', + marginRight: this.gridster.margins[0] + 'px', + marginTop: this.gridster.margins[1] + 'px', + marginBottom: this.gridster.margins[1] + 'px', + top: '', + left: '' + }); + } else { + this.$element.css({ + margin: 0, + top: (this.row * this.gridster.curRowHeight + (this.gridster.outerMargin ? this.gridster.margins[0] : 0)) + 'px', + left: (this.col * this.gridster.curColWidth + (this.gridster.outerMargin ? this.gridster.margins[1] : 0)) + 'px' + }); + } + }; + + /** + * Sets an elements height + */ + this.setElementSizeY = function() { + if (this.gridster.isMobile && !this.gridster.saveGridItemCalculatedHeightInMobile) { + this.$element.css('height', ''); + } else { + var computedHeight = (this.sizeY * this.gridster.curRowHeight - this.gridster.margins[0]) + 'px'; + //this.$element.css('height', computedHeight); + this.$element.attr('style', this.$element.attr('style') + '; ' + 'height: '+computedHeight+' !important;'); + } + }; + + /** + * Sets an elements width + */ + this.setElementSizeX = function() { + if (this.gridster.isMobile) { + this.$element.css('width', ''); + } else { + this.$element.css('width', (this.sizeX * this.gridster.curColWidth - this.gridster.margins[1]) + 'px'); + } + }; + + /** + * Gets an element's width + */ + this.getElementSizeX = function() { + return (this.sizeX * this.gridster.curColWidth - this.gridster.margins[1]); + }; + + /** + * Gets an element's height + */ + this.getElementSizeY = function() { + return (this.sizeY * this.gridster.curRowHeight - this.gridster.margins[0]); + }; + + }) + + .factory('GridsterTouch', [function() { + return function GridsterTouch(target, startEvent, moveEvent, endEvent) { + var lastXYById = {}; + + // Opera doesn't have Object.keys so we use this wrapper + var numberOfKeys = function(theObject) { + if (Object.keys) { + return Object.keys(theObject).length; + } + + var n = 0, + key; + for (key in theObject) { + ++n; + } + + return n; + }; + + // this calculates the delta needed to convert pageX/Y to offsetX/Y because offsetX/Y don't exist in the TouchEvent object or in Firefox's MouseEvent object + var computeDocumentToElementDelta = function(theElement) { + var elementLeft = 0; + var elementTop = 0; + var oldIEUserAgent = navigator.userAgent.match(/\bMSIE\b/); + + for (var offsetElement = theElement; offsetElement != null; offsetElement = offsetElement.offsetParent) { + // the following is a major hack for versions of IE less than 8 to avoid an apparent problem on the IEBlog with double-counting the offsets + // this may not be a general solution to IE7's problem with offsetLeft/offsetParent + if (oldIEUserAgent && + (!document.documentMode || document.documentMode < 8) && + offsetElement.currentStyle.position === 'relative' && offsetElement.offsetParent && offsetElement.offsetParent.currentStyle.position === 'relative' && offsetElement.offsetLeft === offsetElement.offsetParent.offsetLeft) { + // add only the top + elementTop += offsetElement.offsetTop; + } else { + elementLeft += offsetElement.offsetLeft; + elementTop += offsetElement.offsetTop; + } + } + + return { + x: elementLeft, + y: elementTop + }; + }; + + // cache the delta from the document to our event target (reinitialized each mousedown/MSPointerDown/touchstart) + var documentToTargetDelta = computeDocumentToElementDelta(target); + + // common event handler for the mouse/pointer/touch models and their down/start, move, up/end, and cancel events + var doEvent = function(theEvtObj) { + + if (theEvtObj.type === 'mousemove' && numberOfKeys(lastXYById) === 0) { + return; + } + + var prevent = true; + + var pointerList = theEvtObj.changedTouches ? theEvtObj.changedTouches : [theEvtObj]; + + for (var i = 0; i < pointerList.length; ++i) { + var pointerObj = pointerList[i]; + var pointerId = (typeof pointerObj.identifier !== 'undefined') ? pointerObj.identifier : (typeof pointerObj.pointerId !== 'undefined') ? pointerObj.pointerId : 1; + + // use the pageX/Y coordinates to compute target-relative coordinates when we have them (in ie < 9, we need to do a little work to put them there) + if (typeof pointerObj.pageX === 'undefined') { + + // initialize assuming our source element is our target + if(!ie8){ + pointerObj.pageX = pointerObj.offsetX + documentToTargetDelta.x; + pointerObj.pageY = pointerObj.offsetY + documentToTargetDelta.y; + } + else{ + pointerObj.pageX = pointerObj.clientX; + pointerObj.pageY = pointerObj.clientY; + } + + if (pointerObj.srcElement.offsetParent === target && document.documentMode && document.documentMode === 8 && pointerObj.type === 'mousedown') { + // source element is a child piece of VML, we're in IE8, and we've not called setCapture yet - add the origin of the source element + pointerObj.pageX += pointerObj.srcElement.offsetLeft; + pointerObj.pageY += pointerObj.srcElement.offsetTop; + } else if (pointerObj.srcElement !== target && !document.documentMode || document.documentMode < 8) { + // source element isn't the target (most likely it's a child piece of VML) and we're in a version of IE before IE8 - + // the offsetX/Y values are unpredictable so use the clientX/Y values and adjust by the scroll offsets of its parents + // to get the document-relative coordinates (the same as pageX/Y) + var sx = -2, + sy = -2; // adjust for old IE's 2-pixel border + for (var scrollElement = pointerObj.srcElement; scrollElement !== null; scrollElement = scrollElement.parentNode) { + sx += scrollElement.scrollLeft ? scrollElement.scrollLeft : 0; + sy += scrollElement.scrollTop ? scrollElement.scrollTop : 0; + } + + pointerObj.pageX = pointerObj.clientX + sx; + pointerObj.pageY = pointerObj.clientY + sy; + } + } + + + var pageX = pointerObj.pageX; + var pageY = pointerObj.pageY; + + if (theEvtObj.type.match(/(start|down)$/i)) { + // clause for processing MSPointerDown, touchstart, and mousedown + + // refresh the document-to-target delta on start in case the target has moved relative to document + documentToTargetDelta = computeDocumentToElementDelta(target); + + // protect against failing to get an up or end on this pointerId + if (lastXYById[pointerId]) { + if (endEvent) { + endEvent({ + target: theEvtObj.target, + which: theEvtObj.which, + pointerId: pointerId, + pageX: pageX, + pageY: pageY + }); + } + + delete lastXYById[pointerId]; + } + + if (startEvent) { + if (prevent) { + prevent = startEvent({ + target: theEvtObj.target, + which: theEvtObj.which, + pointerId: pointerId, + pageX: pageX, + pageY: pageY + }); + } + } + + // init last page positions for this pointer + lastXYById[pointerId] = { + x: pageX, + y: pageY + }; + + // IE pointer model + if (target.msSetPointerCapture) { + target.msSetPointerCapture(pointerId); + } else if (theEvtObj.type === 'mousedown' && numberOfKeys(lastXYById) === 1) { + if (useSetReleaseCapture) { + target.setCapture(true); + } else { + document.addEventListener('mousemove', doEvent, false); + document.addEventListener('mouseup', doEvent, false); + } + } + } else if (theEvtObj.type.match(/move$/i)) { + // clause handles mousemove, MSPointerMove, and touchmove + + if (lastXYById[pointerId] && !(lastXYById[pointerId].x === pageX && lastXYById[pointerId].y === pageY)) { + // only extend if the pointer is down and it's not the same as the last point + + if (moveEvent && prevent) { + prevent = moveEvent({ + target: theEvtObj.target, + which: theEvtObj.which, + pointerId: pointerId, + pageX: pageX, + pageY: pageY + }); + } + + // update last page positions for this pointer + lastXYById[pointerId].x = pageX; + lastXYById[pointerId].y = pageY; + } + } else if (lastXYById[pointerId] && theEvtObj.type.match(/(up|end|cancel)$/i)) { + // clause handles up/end/cancel + + if (endEvent && prevent) { + prevent = endEvent({ + target: theEvtObj.target, + which: theEvtObj.which, + pointerId: pointerId, + pageX: pageX, + pageY: pageY + }); + } + + // delete last page positions for this pointer + delete lastXYById[pointerId]; + + // in the Microsoft pointer model, release the capture for this pointer + // in the mouse model, release the capture or remove document-level event handlers if there are no down points + // nothing is required for the iOS touch model because capture is implied on touchstart + if (target.msReleasePointerCapture) { + target.msReleasePointerCapture(pointerId); + } else if (theEvtObj.type === 'mouseup' && numberOfKeys(lastXYById) === 0) { + if (useSetReleaseCapture) { + target.releaseCapture(); + } else { + document.removeEventListener('mousemove', doEvent, false); + document.removeEventListener('mouseup', doEvent, false); + } + } + } + } + + if (prevent) { + if (theEvtObj.preventDefault) { + theEvtObj.preventDefault(); + } + + if (theEvtObj.preventManipulation) { + theEvtObj.preventManipulation(); + } + + if (theEvtObj.preventMouseEvent) { + theEvtObj.preventMouseEvent(); + } + } + }; + + var useSetReleaseCapture = false; + // saving the settings for contentZooming and touchaction before activation + var contentZooming, msTouchAction; + + this.enable = function() { + + if (window.navigator.msPointerEnabled) { + // Microsoft pointer model + target.addEventListener('MSPointerDown', doEvent, false); + target.addEventListener('MSPointerMove', doEvent, false); + target.addEventListener('MSPointerUp', doEvent, false); + target.addEventListener('MSPointerCancel', doEvent, false); + + // css way to prevent panning in our target area + if (typeof target.style.msContentZooming !== 'undefined') { + contentZooming = target.style.msContentZooming; + target.style.msContentZooming = 'none'; + } + + // new in Windows Consumer Preview: css way to prevent all built-in touch actions on our target + // without this, you cannot touch draw on the element because IE will intercept the touch events + if (typeof target.style.msTouchAction !== 'undefined') { + msTouchAction = target.style.msTouchAction; + target.style.msTouchAction = 'none'; + } + } else if (target.addEventListener) { + // iOS touch model + target.addEventListener('touchstart', doEvent, false); + target.addEventListener('touchmove', doEvent, false); + target.addEventListener('touchend', doEvent, false); + target.addEventListener('touchcancel', doEvent, false); + + // mouse model + target.addEventListener('mousedown', doEvent, false); + + // mouse model with capture + // rejecting gecko because, unlike ie, firefox does not send events to target when the mouse is outside target + if (target.setCapture && !window.navigator.userAgent.match(/\bGecko\b/)) { + useSetReleaseCapture = true; + + target.addEventListener('mousemove', doEvent, false); + target.addEventListener('mouseup', doEvent, false); + } + } else if (target.attachEvent && target.setCapture) { + // legacy IE mode - mouse with capture + useSetReleaseCapture = true; + target.attachEvent('onmousedown', function() { + doEvent(window.event); + window.event.returnValue = false; + return false; + }); + target.attachEvent('onmousemove', function() { + doEvent(window.event); + window.event.returnValue = false; + return false; + }); + target.attachEvent('onmouseup', function() { + doEvent(window.event); + window.event.returnValue = false; + return false; + }); + } + }; + + this.disable = function() { + if (window.navigator.msPointerEnabled) { + // Microsoft pointer model + target.removeEventListener('MSPointerDown', doEvent, false); + target.removeEventListener('MSPointerMove', doEvent, false); + target.removeEventListener('MSPointerUp', doEvent, false); + target.removeEventListener('MSPointerCancel', doEvent, false); + + // reset zooming to saved value + if (contentZooming) { + target.style.msContentZooming = contentZooming; + } + + // reset touch action setting + if (msTouchAction) { + target.style.msTouchAction = msTouchAction; + } + } else if (target.removeEventListener) { + // iOS touch model + target.removeEventListener('touchstart', doEvent, false); + target.removeEventListener('touchmove', doEvent, false); + target.removeEventListener('touchend', doEvent, false); + target.removeEventListener('touchcancel', doEvent, false); + + // mouse model + target.removeEventListener('mousedown', doEvent, false); + + // mouse model with capture + // rejecting gecko because, unlike ie, firefox does not send events to target when the mouse is outside target + if (target.setCapture && !window.navigator.userAgent.match(/\bGecko\b/)) { + useSetReleaseCapture = true; + + target.removeEventListener('mousemove', doEvent, false); + target.removeEventListener('mouseup', doEvent, false); + } + } else if (target.detachEvent && target.setCapture) { + // legacy IE mode - mouse with capture + useSetReleaseCapture = true; + target.detachEvent('onmousedown'); + target.detachEvent('onmousemove'); + target.detachEvent('onmouseup'); + } + }; + + return this; + }; + }]) + + .factory('GridsterDraggable', ['$document', '$timeout', '$window', 'GridsterTouch', + function($document, $timeout, $window, GridsterTouch) { + function GridsterDraggable($el, scope, gridster, item, itemOptions) { + + var elmX, elmY, elmW, elmH, + + mouseX = 0, + mouseY = 0, + lastMouseX = 0, + lastMouseY = 0, + mOffX = 0, + mOffY = 0, + + minTop = 0, + maxTop = 9999, + minLeft = 0, + realdocument = $document[0]; + + var originalCol, originalRow; + var inputTags = ['select', 'input', 'textarea', 'button']; + + var gridsterItemDragElement = $el[0].querySelector('[gridster-item-drag]'); + //console.log(gridsterItemDragElement); + var isDraggableAreaDefined = gridsterItemDragElement?true:false; + //console.log(isDraggableAreaDefined); + + function mouseDown(e) { + + if(ie8){ + e.target = window.event.srcElement; + e.which = window.event.button; + } + + if(isDraggableAreaDefined && (!gridsterItemDragElement.contains(e.target))){ + return false; + } + + if (inputTags.indexOf(e.target.nodeName.toLowerCase()) !== -1) { + return false; + } + + var $target = angular.element(e.target); + + // exit, if a resize handle was hit + if ($target.hasClass('gridster-item-resizable-handler')) { + return false; + } + + // exit, if the target has it's own click event + if ($target.attr('onclick') || $target.attr('ng-click')) { + return false; + } + + // only works if you have jQuery + if ($target.closest && $target.closest('.gridster-no-drag').length) { + return false; + } + + switch (e.which) { + case 1: + // left mouse button + break; + case 2: + case 3: + // right or middle mouse button + return; + } + + lastMouseX = e.pageX; + lastMouseY = e.pageY; + + elmX = parseInt($el.css('left'), 10); + elmY = parseInt($el.css('top'), 10); + elmW = $el[0].offsetWidth; + elmH = $el[0].offsetHeight; + + originalCol = item.col; + originalRow = item.row; + + dragStart(e); + + return true; + } + + function mouseMove(e) { + if (!$el.hasClass('gridster-item-moving') || $el.hasClass('gridster-item-resizing')) { + return false; + } + + var maxLeft = gridster.curWidth - 1; + + // Get the current mouse position. + mouseX = e.pageX; + mouseY = e.pageY; + + // Get the deltas + var diffX = mouseX - lastMouseX + mOffX; + var diffY = mouseY - lastMouseY + mOffY; + mOffX = mOffY = 0; + + // Update last processed mouse positions. + lastMouseX = mouseX; + lastMouseY = mouseY; + + var dX = diffX, + dY = diffY; + if (elmX + dX < minLeft) { + diffX = minLeft - elmX; + mOffX = dX - diffX; + } else if (elmX + elmW + dX > maxLeft) { + diffX = maxLeft - elmX - elmW; + mOffX = dX - diffX; + } + + if (elmY + dY < minTop) { + diffY = minTop - elmY; + mOffY = dY - diffY; + } else if (elmY + elmH + dY > maxTop) { + diffY = maxTop - elmY - elmH; + mOffY = dY - diffY; + } + elmX += diffX; + elmY += diffY; + + // set new position + $el.css({ + 'top': elmY + 'px', + 'left': elmX + 'px' + }); + + drag(e); + + return true; + } + + function mouseUp(e) { + if (!$el.hasClass('gridster-item-moving') || $el.hasClass('gridster-item-resizing')) { + return false; + } + + mOffX = mOffY = 0; + + dragStop(e); + + return true; + } + + function dragStart(event) { + $el.addClass('gridster-item-moving'); + gridster.movingItem = item; + + gridster.updateHeight(item.sizeY); + scope.$apply(function() { + if (gridster.draggable && gridster.draggable.start) { + gridster.draggable.start(event, $el, itemOptions); + } + }); + } + + function drag(event) { + var oldRow = item.row, + oldCol = item.col, + hasCallback = gridster.draggable && gridster.draggable.drag, + scrollSensitivity = gridster.draggable.scrollSensitivity, + scrollSpeed = gridster.draggable.scrollSpeed; + + var row = gridster.pixelsToRows(elmY); + var col = gridster.pixelsToColumns(elmX); + + var itemsInTheWay = gridster.getItems(row, col, item.sizeX, item.sizeY, item); + var hasItemsInTheWay = itemsInTheWay.length !== 0; + + if (gridster.swapping === true && hasItemsInTheWay) { + var boundingBoxItem = gridster.getBoundingBox(itemsInTheWay), + sameSize = boundingBoxItem.sizeX === item.sizeX && boundingBoxItem.sizeY === item.sizeY, + sameRow = boundingBoxItem.row === oldRow, + sameCol = boundingBoxItem.col === oldCol, + samePosition = boundingBoxItem.row === row && boundingBoxItem.col === col, + inline = sameRow || sameCol; + + if (sameSize && itemsInTheWay.length === 1) { + if (samePosition) { + gridster.swapItems(item, itemsInTheWay[0]); + } else if (inline) { + return; + } + } else if (boundingBoxItem.sizeX <= item.sizeX && boundingBoxItem.sizeY <= item.sizeY && inline) { + var emptyRow = item.row <= row ? item.row : row + item.sizeY, + emptyCol = item.col <= col ? item.col : col + item.sizeX, + rowOffset = emptyRow - boundingBoxItem.row, + colOffset = emptyCol - boundingBoxItem.col; + + for (var i = 0, l = itemsInTheWay.length; i < l; ++i) { + var itemInTheWay = itemsInTheWay[i]; + + var itemsInFreeSpace = gridster.getItems( + itemInTheWay.row + rowOffset, + itemInTheWay.col + colOffset, + itemInTheWay.sizeX, + itemInTheWay.sizeY, + item + ); + + if (itemsInFreeSpace.length === 0) { + gridster.putItem(itemInTheWay, itemInTheWay.row + rowOffset, itemInTheWay.col + colOffset); + } + } + } + } + + if (gridster.pushing !== false || !hasItemsInTheWay) { + item.row = row; + item.col = col; + } + + if(($window.navigator.appName === 'Microsoft Internet Explorer' && !ie8) || $window.navigator.userAgent.indexOf("Firefox")!==-1){ + if (event.pageY - realdocument.documentElement.scrollTop < scrollSensitivity) { + realdocument.documentElement.scrollTop = realdocument.documentElement.scrollTop - scrollSpeed; + } else if ($window.innerHeight - (event.pageY - realdocument.documentElement.scrollTop) < scrollSensitivity) { + realdocument.documentElement.scrollTop = realdocument.documentElement.scrollTop + scrollSpeed; + } + } + else{ + if (event.pageY - realdocument.body.scrollTop < scrollSensitivity) { + realdocument.body.scrollTop = realdocument.body.scrollTop - scrollSpeed; + } else if ($window.innerHeight - (event.pageY - realdocument.body.scrollTop) < scrollSensitivity) { + realdocument.body.scrollTop = realdocument.body.scrollTop + scrollSpeed; + } + } + + + + if (event.pageX - realdocument.body.scrollLeft < scrollSensitivity) { + realdocument.body.scrollLeft = realdocument.body.scrollLeft - scrollSpeed; + } else if ($window.innerWidth - (event.pageX - realdocument.body.scrollLeft) < scrollSensitivity) { + realdocument.body.scrollLeft = realdocument.body.scrollLeft + scrollSpeed; + } + + if (hasCallback || oldRow !== item.row || oldCol !== item.col) { + scope.$apply(function() { + if (hasCallback) { + gridster.draggable.drag(event, $el, itemOptions); + } + }); + } + } + + function dragStop(event) { + $el.removeClass('gridster-item-moving'); + var row = gridster.pixelsToRows(elmY); + var col = gridster.pixelsToColumns(elmX); + if (gridster.pushing !== false || gridster.getItems(row, col, item.sizeX, item.sizeY, item).length === 0) { + item.row = row; + item.col = col; + } + gridster.movingItem = null; + item.setPosition(item.row, item.col); + + scope.$apply(function() { + if (gridster.draggable && gridster.draggable.stop) { + gridster.draggable.stop(event, $el, itemOptions); + } + }); + } + + var enabled = null; + var $dragHandles = null; + var unifiedInputs = []; + + this.enable = function() { + if (enabled === true) { + return; + } + + // disable and timeout required for some template rendering + $timeout(function() { + // disable any existing draghandles + for (var u = 0, ul = unifiedInputs.length; u < ul; ++u) { + unifiedInputs[u].disable(); + } + unifiedInputs = []; + + if (gridster.draggable && gridster.draggable.handle) { + $dragHandles = angular.element($el[0].querySelectorAll(gridster.draggable.handle)); + if ($dragHandles.length === 0) { + // fall back to element if handle not found... + $dragHandles = $el; + } + } else { + $dragHandles = $el; + } + + for (var h = 0, hl = $dragHandles.length; h < hl; ++h) { + unifiedInputs[h] = new GridsterTouch($dragHandles[h], mouseDown, mouseMove, mouseUp); + unifiedInputs[h].enable(); + } + + enabled = true; + }); + }; + + this.disable = function() { + if (enabled === false) { + return; + } + + // timeout to avoid race contition with the enable timeout + $timeout(function() { + + for (var u = 0, ul = unifiedInputs.length; u < ul; ++u) { + unifiedInputs[u].disable(); + } + + unifiedInputs = []; + enabled = false; + }); + }; + + this.toggle = function(enabled) { + if (enabled) { + this.enable(); + } else { + this.disable(); + } + }; + + this.destroy = function() { + this.disable(); + }; + } + + return GridsterDraggable; + } + ]) + + .factory('GridsterResizable', ['GridsterTouch', function(GridsterTouch) { + function GridsterResizable($el, scope, gridster, item, itemOptions) { + + function ResizeHandle(handleClass) { + + var hClass = handleClass; + + var elmX, elmY, elmW, elmH, + + mouseX = 0, + mouseY = 0, + lastMouseX = 0, + lastMouseY = 0, + mOffX = 0, + mOffY = 0, + + minTop = 0, + maxTop = 9999, + minLeft = 0; + + var getMinHeight = function() { + return (item.minSizeY ? item.minSizeY : 1) * gridster.curRowHeight - gridster.margins[0]; + }; + var getMinWidth = function() { + return (item.minSizeX ? item.minSizeX : 1) * gridster.curColWidth - gridster.margins[1]; + }; + + var originalWidth, originalHeight; + var savedDraggable; + + function mouseDown(e) { + switch (e.which) { + case 1: + // left mouse button + break; + case 2: + case 3: + // right or middle mouse button + return; + } + + // save the draggable setting to restore after resize + savedDraggable = gridster.draggable.enabled; + if (savedDraggable) { + gridster.draggable.enabled = false; + scope.$broadcast('gridster-draggable-changed', gridster); + } + + // Get the current mouse position. + lastMouseX = e.pageX; + lastMouseY = e.pageY; + + // Record current widget dimensions + elmX = parseInt($el.css('left'), 10); + elmY = parseInt($el.css('top'), 10); + elmW = $el[0].offsetWidth; + elmH = $el[0].offsetHeight; + + originalWidth = item.sizeX; + originalHeight = item.sizeY; + + resizeStart(e); + + return true; + } + + function resizeStart(e) { + $el.addClass('gridster-item-moving'); + $el.addClass('gridster-item-resizing'); + + gridster.movingItem = item; + + item.setElementSizeX(); + item.setElementSizeY(); + item.setElementPosition(); + gridster.updateHeight(1); + + scope.$apply(function() { + // callback + if (gridster.resizable && gridster.resizable.start) { + gridster.resizable.start(e, $el, itemOptions); // options is the item model + } + }); + } + + function mouseMove(e) { + var maxLeft = gridster.curWidth - 1; + + // Get the current mouse position. + mouseX = e.pageX; + mouseY = e.pageY; + + // Get the deltas + var diffX = mouseX - lastMouseX + mOffX; + var diffY = mouseY - lastMouseY + mOffY; + mOffX = mOffY = 0; + + // Update last processed mouse positions. + lastMouseX = mouseX; + lastMouseY = mouseY; + + var dY = diffY, + dX = diffX; + + if (hClass.indexOf('n') >= 0) { + if (elmH - dY < getMinHeight()) { + diffY = elmH - getMinHeight(); + mOffY = dY - diffY; + } else if (elmY + dY < minTop) { + diffY = minTop - elmY; + mOffY = dY - diffY; + } + elmY += diffY; + elmH -= diffY; + } + if (hClass.indexOf('s') >= 0) { + if (elmH + dY < getMinHeight()) { + diffY = getMinHeight() - elmH; + mOffY = dY - diffY; + } else if (elmY + elmH + dY > maxTop) { + diffY = maxTop - elmY - elmH; + mOffY = dY - diffY; + } + elmH += diffY; + } + if (hClass.indexOf('w') >= 0) { + if (elmW - dX < getMinWidth()) { + diffX = elmW - getMinWidth(); + mOffX = dX - diffX; + } else if (elmX + dX < minLeft) { + diffX = minLeft - elmX; + mOffX = dX - diffX; + } + elmX += diffX; + elmW -= diffX; + } + if (hClass.indexOf('e') >= 0) { + if (elmW + dX < getMinWidth()) { + diffX = getMinWidth() - elmW; + mOffX = dX - diffX; + } else if (elmX + elmW + dX > maxLeft) { + diffX = maxLeft - elmX - elmW; + mOffX = dX - diffX; + } + elmW += diffX; + } + + // set new position + $el.css({ + 'top': elmY + 'px', + 'left': elmX + 'px', + 'width': elmW + 'px', + 'height': elmH + 'px' + }); + + resize(e); + + return true; + } + + function mouseUp(e) { + // restore draggable setting to its original state + if (gridster.draggable.enabled !== savedDraggable) { + gridster.draggable.enabled = savedDraggable; + scope.$broadcast('gridster-draggable-changed', gridster); + } + + mOffX = mOffY = 0; + + resizeStop(e); + + return true; + } + + function resize(e) { + var oldRow = item.row, + oldCol = item.col, + oldSizeX = item.sizeX, + oldSizeY = item.sizeY, + hasCallback = gridster.resizable && gridster.resizable.resize; + + var col = item.col; + // only change column if grabbing left edge + if (['w', 'nw', 'sw'].indexOf(handleClass) !== -1) { + col = gridster.pixelsToColumns(elmX, false); + } + + var row = item.row; + // only change row if grabbing top edge + if (['n', 'ne', 'nw'].indexOf(handleClass) !== -1) { + row = gridster.pixelsToRows(elmY, false); + } + + var sizeX = item.sizeX; + // only change row if grabbing left or right edge + if (['n', 's'].indexOf(handleClass) === -1) { + sizeX = gridster.pixelsToColumns(elmW, true); + } + + var sizeY = item.sizeY; + // only change row if grabbing top or bottom edge + if (['e', 'w'].indexOf(handleClass) === -1) { + sizeY = gridster.pixelsToRows(elmH, true); + } + + if (gridster.pushing !== false || gridster.getItems(row, col, sizeX, sizeY, item).length === 0) { + item.row = row; + item.col = col; + item.sizeX = sizeX; + item.sizeY = sizeY; + } + var isChanged = item.row !== oldRow || item.col !== oldCol || item.sizeX !== oldSizeX || item.sizeY !== oldSizeY; + + if (hasCallback || isChanged) { + scope.$apply(function() { + if (hasCallback) { + gridster.resizable.resize(e, $el, itemOptions); // options is the item model + } + }); + } + } + + function resizeStop(e) { + $el.removeClass('gridster-item-moving'); + $el.removeClass('gridster-item-resizing'); + + gridster.movingItem = null; + + item.setPosition(item.row, item.col); + item.setSizeY(item.sizeY); + item.setSizeX(item.sizeX); + + scope.$apply(function() { + if (gridster.resizable && gridster.resizable.stop) { + gridster.resizable.stop(e, $el, itemOptions); // options is the item model + } + }); + } + + var $dragHandle = null; + var unifiedInput; + + this.enable = function() { + if (!$dragHandle) { + $dragHandle = angular.element('
    '); + $el.append($dragHandle); + } + + unifiedInput = new GridsterTouch($dragHandle[0], mouseDown, mouseMove, mouseUp); + unifiedInput.enable(); + }; + + this.disable = function() { + if ($dragHandle) { + $dragHandle.remove(); + $dragHandle = null; + } + + unifiedInput.disable(); + unifiedInput = undefined; + }; + + this.destroy = function() { + this.disable(); + }; + } + + var handles = []; + var handlesOpts = gridster.resizable.handles; + if (typeof handlesOpts === 'string') { + handlesOpts = gridster.resizable.handles.split(','); + } + var enabled = false; + + for (var c = 0, l = handlesOpts.length; c < l; c++) { + handles.push(new ResizeHandle(handlesOpts[c])); + } + + this.enable = function() { + if (enabled) { + return; + } + for (var c = 0, l = handles.length; c < l; c++) { + handles[c].enable(); + } + enabled = true; + }; + + this.disable = function() { + if (!enabled) { + return; + } + for (var c = 0, l = handles.length; c < l; c++) { + handles[c].disable(); + } + enabled = false; + }; + + this.toggle = function(enabled) { + if (enabled) { + this.enable(); + } else { + this.disable(); + } + }; + + this.destroy = function() { + for (var c = 0, l = handles.length; c < l; c++) { + handles[c].destroy(); + } + }; + } + return GridsterResizable; + }]) + + .factory('gridsterDebounce', function() { + return function gridsterDebounce(func, wait, immediate) { + var timeout; + return function() { + var context = this, + args = arguments; + var later = function() { + timeout = null; + if (!immediate) { + func.apply(context, args); + } + }; + var callNow = immediate && !timeout; + clearTimeout(timeout); + timeout = setTimeout(later, wait); + if (callNow) { + func.apply(context, args); + } + }; + }; + }) + + /** + * GridsterItem directive + * @param $parse + * @param GridsterDraggable + * @param GridsterResizable + * @param gridsterDebounce + */ + .directive('gridsterItem', ['$parse', 'GridsterDraggable', 'GridsterResizable', 'gridsterDebounce', + function($parse, GridsterDraggable, GridsterResizable, gridsterDebounce) { + return { + scope: true, + restrict: 'EA', + controller: 'GridsterItemCtrl', + controllerAs: 'gridsterItem', + require: ['^gridster', 'gridsterItem'], + link: function(scope, $el, attrs, controllers) { + var optionsKey = attrs.gridsterItem, + options; + + var gridster = controllers[0], + item = controllers[1]; + + scope.gridster = gridster; + + + // bind the item's position properties + // options can be an object specified by gridster-item="object" + // or the options can be the element html attributes object + if (optionsKey) { + var $optionsGetter = $parse(optionsKey); + options = $optionsGetter(scope) || {}; + if (!options && $optionsGetter.assign) { + options = { + row: item.row, + col: item.col, + sizeX: item.sizeX, + sizeY: item.sizeY, + minSizeX: 0, + minSizeY: 0, + maxSizeX: null, + maxSizeY: null + }; + $optionsGetter.assign(scope, options); + } + } else { + options = attrs; + } + + item.init($el, gridster); + + $el.addClass('gridster-item'); + + var aspects = ['minSizeX', 'maxSizeX', 'minSizeY', 'maxSizeY', 'sizeX', 'sizeY', 'row', 'col'], + $getters = {}; + + var expressions = []; + var aspectFn = function(aspect) { + var expression; + if (typeof options[aspect] === 'string') { + // watch the expression in the scope + expression = options[aspect]; + } else if (typeof options[aspect.toLowerCase()] === 'string') { + // watch the expression in the scope + expression = options[aspect.toLowerCase()]; + } else if (optionsKey) { + // watch the expression on the options object in the scope + expression = optionsKey + '.' + aspect; + } else { + return; + } + expressions.push('"' + aspect + '":' + expression); + $getters[aspect] = $parse(expression); + + // initial set + var val = $getters[aspect](scope); + if (typeof val === 'number') { + item[aspect] = val; + } + }; + + for (var i = 0, l = aspects.length; i < l; ++i) { + aspectFn(aspects[i]); + } + + var watchExpressions = '{' + expressions.join(',') + '}'; + + // when the value changes externally, update the internal item object + scope.$watchCollection(watchExpressions, function(newVals, oldVals) { + for (var aspect in newVals) { + var newVal = newVals[aspect]; + var oldVal = oldVals[aspect]; + if (oldVal === newVal) { + continue; + } + newVal = parseInt(newVal, 10); + if (!isNaN(newVal)) { + item[aspect] = newVal; + } + } + }); + + function positionChanged() { + // call setPosition so the element and gridster controller are updated + item.setPosition(item.row, item.col); + + // when internal item position changes, update externally bound values + if ($getters.row && $getters.row.assign) { + $getters.row.assign(scope, item.row); + } + if ($getters.col && $getters.col.assign) { + $getters.col.assign(scope, item.col); + } + } + scope.$watch(function() { + return item.row + ',' + item.col; + }, positionChanged); + + function sizeChanged() { + var changedX = item.setSizeX(item.sizeX, true); + if (changedX && $getters.sizeX && $getters.sizeX.assign) { + $getters.sizeX.assign(scope, item.sizeX); + } + var changedY = item.setSizeY(item.sizeY, true); + if (changedY && $getters.sizeY && $getters.sizeY.assign) { + $getters.sizeY.assign(scope, item.sizeY); + } + + if (changedX || changedY) { + item.gridster.moveOverlappingItems(item); + gridster.layoutChanged(); + scope.$broadcast('gridster-item-resized', item); + } + } + + scope.$watch(function() { + return item.sizeY + ',' + item.sizeX + ',' + item.minSizeX + ',' + item.maxSizeX + ',' + item.minSizeY + ',' + item.maxSizeY; + }, sizeChanged); + + var draggable = new GridsterDraggable($el, scope, gridster, item, options); + var resizable = new GridsterResizable($el, scope, gridster, item, options); + + var updateResizable = function() { + resizable.toggle(!gridster.isMobile && gridster.resizable && gridster.resizable.enabled); + }; + updateResizable(); + + var updateDraggable = function() { + draggable.toggle(!gridster.isMobile && gridster.draggable && gridster.draggable.enabled); + }; + updateDraggable(); + + scope.$on('gridster-draggable-changed', updateDraggable); + scope.$on('gridster-resizable-changed', updateResizable); + scope.$on('gridster-resized', updateResizable); + scope.$on('gridster-mobile-changed', function() { + updateResizable(); + updateDraggable(); + }); + + function whichTransitionEvent() { + var el = document.createElement('div'); + var transitions = { + 'transition': 'transitionend', + 'OTransition': 'oTransitionEnd', + 'MozTransition': 'transitionend', + 'WebkitTransition': 'webkitTransitionEnd' + }; + for (var t in transitions) { + if (el.style[t] !== undefined) { + return transitions[t]; + } + } + } + + var debouncedTransitionEndPublisher = gridsterDebounce(function() { + scope.$apply(function() { + scope.$broadcast('gridster-item-transition-end', item); + }); + }, 50); + + if(whichTransitionEvent()){ //check for IE8, as it evaluates to null + $el.on(whichTransitionEvent(), debouncedTransitionEndPublisher); + } + + scope.$broadcast('gridster-item-initialized', item); + + return scope.$on('$destroy', function() { + try { + resizable.destroy(); + draggable.destroy(); + } catch (e) {} + + try { + gridster.removeItem(item); + } catch (e) {} + + try { + item.destroy(); + } catch (e) {} + }); + } + }; + } + ]) + + .directive('gridsterNoDrag', function() { + return { + restrict: 'A', + link: function(scope, $element) { + $element.addClass('gridster-no-drag'); + } + }; + }) + + ; + +})); diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/att_angular_gridster/ui-gridster-tpls.js b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/att_angular_gridster/ui-gridster-tpls.js new file mode 100644 index 000000000..3ca3db7d8 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/att_angular_gridster/ui-gridster-tpls.js @@ -0,0 +1,168 @@ +/** +* FileName ui-gridster +* Version 0.0.1 +* Build number ad58c6f4f8f8fd7f04ac457f95d76f09 +* Date 08/17/2015 +*/ + + +(function(angular, window){ +angular.module("att.gridster", ["att.gridster.tpls", "att.gridster.utilities","att.gridster.gridster"]); +angular.module("att.gridster.tpls", ["template/gridster/gridster.html","template/gridster/gridsterItem.html","template/gridster/gridsterItemBody.html","template/gridster/gridsterItemFooter.html","template/gridster/gridsterItemHeader.html"]); +angular.module('att.gridster.utilities', []) + .factory('$extendObj', [function() { + var _extendDeep = function(dst) { + angular.forEach(arguments, function(obj) { + if (obj !== dst) { + angular.forEach(obj, function(value, key) { + if (dst[key] && dst[key].constructor && dst[key].constructor === Object) { + _extendDeep(dst[key], value); + } else { + dst[key] = value; + } + }); + } + }); + return dst; + }; + return { + extendDeep: _extendDeep + }; + }]); + +angular.module('att.gridster.gridster', ['attGridsterLib', 'att.gridster.utilities']) + .config(['$compileProvider', function($compileProvider) { + $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|javascript):/); + }]) + .constant('attGridsterConfig', + { + columns: 3, + margins: [10, 10], + outerMargin: true, + pushing: true, + floating: true, + swapping: true, + draggable: { + enabled: true + } + }) + .directive('attGridster', ['attGridsterConfig', '$extendObj', function(attGridsterConfig, $extendObj) { + return { + restrict: 'EA', + scope: { + attGridsterOptions: '=?' + }, + templateUrl: 'template/gridster/gridster.html', + replace: false, + transclude: true, + controller: [function() {}], + link: function(scope) { + if (angular.isDefined(scope.attGridsterOptions)) { + attGridsterConfig = $extendObj.extendDeep(attGridsterConfig, scope.attGridsterOptions); + } + scope.attGridsterConfig = attGridsterConfig; + } + }; + }]) + .directive('attGridsterItem', ['$timeout', function($timeout) { + return { + restrict: 'EA', + require: ['^attGridster'], + scope: { + attGridsterItem: '=' + }, + templateUrl: 'template/gridster/gridsterItem.html', + replace: false, + transclude: true, + controller: [function() {}] + }; + }]) + .directive('attGridsterItemHeader', [function() { + return { + restrict: 'EA', + require: ['^attGridsterItem'], + scope: { + headerText: '@', + subHeaderText: '@?' + }, + templateUrl: 'template/gridster/gridsterItemHeader.html', + replace: true, + transclude: true, + link: function(scope, element) { + if (angular.isDefined(scope.subHeaderText) && scope.subHeaderText) { + angular.element(element[0].querySelector('span.gridster-item-sub-header-content')).attr("tabindex", "0"); + angular.element(element[0].querySelector('span.gridster-item-sub-header-content')).attr("aria-label", scope.subHeaderText); + } + } + }; + }]) + .directive('attGridsterItemBody', [function() { + return { + restrict: 'EA', + require: ['^attGridsterItem'], + scope: {}, + templateUrl: 'template/gridster/gridsterItemBody.html', + replace: true, + transclude: true + }; + }]) + .directive('attGridsterItemFooter', ['$location', function($location) { + return { + restrict: 'EA', + require: ['^attGridsterItem'], + scope: { + attGridsterItemFooterLink: '@?' + }, + templateUrl: 'template/gridster/gridsterItemFooter.html', + replace: true, + transclude: true, + controller: ['$scope', function($scope) { + $scope.clickOnFooterLink = function(evt) { + evt.preventDefault(); + evt.stopPropagation(); + if ($scope.attGridsterItemFooterLink) { + $location.url($scope.attGridsterItemFooterLink); + } + }; + }], + link: function(scope, element) { + if (angular.isDefined(scope.attGridsterItemFooterLink) && scope.attGridsterItemFooterLink) { + element.attr("role", "link"); + } + } + }; + }]); +angular.module("template/gridster/gridster.html", []).run(["$templateCache", function($templateCache) { + $templateCache.put("template/gridster/gridster.html", + "
    "); +}]); + +angular.module("template/gridster/gridsterItem.html", []).run(["$templateCache", function($templateCache) { + $templateCache.put("template/gridster/gridsterItem.html", + "
    "); +}]); + +angular.module("template/gridster/gridsterItemBody.html", []).run(["$templateCache", function($templateCache) { + $templateCache.put("template/gridster/gridsterItemBody.html", + "
    "); +}]); + +angular.module("template/gridster/gridsterItemFooter.html", []).run(["$templateCache", function($templateCache) { + $templateCache.put("template/gridster/gridsterItemFooter.html", + "
    \n" + + " \n" + + "
    "); +}]); + +angular.module("template/gridster/gridsterItemHeader.html", []).run(["$templateCache", function($templateCache) { + $templateCache.put("template/gridster/gridsterItemHeader.html", + "
    \n" + + " \"||\"\n" + + " {{headerText}}\n" + + " {{subHeaderText}}\n" + + "
    \n" + + "
    "); +}]); + +return {} +})(angular, window); \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/adminController.js b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/adminController.js new file mode 100644 index 000000000..a99be9fea --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/adminController.js @@ -0,0 +1,65 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +app.config(function($routeProvider) { + $routeProvider + + + .when('/role_function_list', { + templateUrl: 'app/fusion/scripts/view-models/profile-page/role_function_list.html', + controller: 'roleFunctionListController' + }) + + .when('/admin_menu_edit', { + templateUrl: 'app/fusion/scripts/view-models/profile-page/admin_menu_edit.html', + controller: 'AdminMenuEditController' + }) + .when('/role/:roleId', { + templateUrl: 'app/fusion/scripts/view-models/profile-page/role.html', + controller: 'roleController' + }) + .when('/jcs_admin', { + templateUrl: 'app/fusion/scripts/view-models/profile-page/jcs_admin.html', + controller: 'cacheAdminController' + }) + .when('/broadcast_list', { + templateUrl: 'app/fusion/scripts/view-models/profile-page/broadcast_list.html', + controller: 'broadcastListController' + }) + .when('/broadcast/:messageLocationId/:messageLocation/:messageId', { + templateUrl: 'app/fusion/scripts/view-models/profile-page/broadcast.html', + controller: 'broadcastController' + }) + .when('/broadcast/:messageLocationId/:messageLocation', { + templateUrl: 'app/fusion/scripts/view-models/profile-page/broadcast.html', + controller: 'broadcastController' + }) + .when('/collaborate_list', { + templateUrl: 'app/fusion/scripts/view-models/profile-page/collaborate_list.html', + controller: 'collaborateListController' + }) + .when('/usage_list', { + templateUrl: 'app/fusion/scripts/view-models/profile-page/usage_list.html', + controller: 'usageListController' + }) + .otherwise({ + templateUrl: 'app/fusion/scripts/view-models/profile-page/role_list.html', + controller : "roleListController" + }); +}); diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/admin_menu_edit.js b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/admin_menu_edit.js new file mode 100644 index 000000000..54d58a45a --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/admin_menu_edit.js @@ -0,0 +1,230 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +app.controller('AdminMenuEditController', function ($scope, AdminService, modalService, $modal, $route){ + $( "#dialog" ).hide(); + +/* AdminService.getRoleFunctionList().then(function(data){ + + var j = data; + $scope.data = JSON.parse(j.data); + $scope.availableRoleFunctions =JSON.parse($scope.data.availableRoleFunctions); + + //$scope.resetMenu(); + + },function(error){ + console.log("failed"); + reloadPageOnce(); + });*/ + $scope.init = function () { + $scope.numberOfRecordstoShow=20; + AdminService.getFnMenuItems().then(function(data){ + var j = data; + $scope.data =JSON.parse(j.data); + $scope.fnMenuItems =($scope.data.fnMenuItems); + + },function(error){ + console.log("failed"); + //reloadPageOnce(); + }); + } + $scope.init(); + $scope.mapActiveStatus = function(status){ + if(status) + status = "Y"; + else + status = "N"; + return status; + + }; + + + $scope.addNewFnMenuItemModalPopup = function(availableFnMenuItem) { + $scope.editFnMenuItem = null; + var modalInstance = $modal.open({ + templateUrl: 'fn_menu_add_popup.html', + controller: 'fn_menu_popupController', + resolve: { + message: function () { + var message = { + availableFnMenuItem: $scope.editFnMenuItem + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.availableFnMenuItems=response.availableFnMenuItems; + $route.reload(); + }); + }; + + $scope.removeMenuItem = function(fnMenuItem) { + modalService.popupConfirmWin("Confirm","You are about to delete the menu item "+fnMenuItem.label+". Do you want to continue?", + function(){ + var uuu = "admin_fn_menu/removeMenuItem.htm"; + var postData={fnMenuItem: fnMenuItem}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){$scope.fnMenuItem=data.fnMenuItem;}); + $route.reload(); + }, + error : function(data){ + console.log(data); + modalService.showFailure("Fail","Error while deleting: "+ data.responseText); + } + }); + + }) + + }; + + $scope.editRoleFunction = null; + var dialog = null; + $scope.editRoleFunctionPopup = function(availableRoleFunction) { + $scope.editRoleFunction = availableRoleFunction; + $( "#dialog" ).dialog({ + modal: true + }); + }; + + $scope.editMenuItemModalPopup = function(availableFnMenuItem) { + $scope.editFnMenuItem = availableFnMenuItem; + var modalInstance = $modal.open({ + templateUrl: 'fn_menu_add_popup.html', + controller: 'fn_menu_popupController', + resolve: { + message: function () { + var message = { + availableFnMenuItem: $scope.editFnMenuItem + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + $scope.availableFnMenuItems=response.availableFnMenuItems; + $route.reload(); + }); + }; + + $scope.editRoleFunctionModalPopup = function(availableRoleFunction) { + $scope.editRoleFunction = availableRoleFunction; + var modalInstance = $modal.open({ + templateUrl: 'edit_role_function_popup.html', + controller: 'rolefunctionpopupController', + resolve: { + message: function () { + var message = { + availableRoleFunction: $scope.editRoleFunction + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.availableRoleFunctions=response.availableRoleFunctions; + }); + }; + + $scope.addNewRoleFunctionModalPopup = function(availableRoleFunction) { + $scope.editRoleFunction = null; + var modalInstance = $modal.open({ + templateUrl: 'edit_role_function_popup.html', + controller: 'rolefunctionpopupController', + resolve: { + message: function () { + var message = { + availableRoleFunction: $scope.editRoleFunction + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.availableRoleFunctions=response.availableRoleFunctions; + }); + }; + + $scope.addNewRoleFunctionPopup = function() { + $scope.editRoleFunction = null; + $( "#dialog" ).dialog({ + modal: true + }); + }; + + $scope.saveRoleFunction = function(availableRoleFunction) { + var uuu = "role_function_list/saveRoleFunction.htm"; + var postData={availableRoleFunction: availableRoleFunction}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){ + $scope.availableRoleFunctions=[];$scope.$apply(); + $scope.availableRoleFunctions=data.availableRoleFunctions;}); + //alert("Update Successful.") ; + console.log($scope.availableRoleFunctions); + + $scope.editRoleFunction = null; + $( "#dialog" ).dialog("close"); + }, + error : function(data){ + modalService.showFailure("Fail","Error while saving."); + } + }); + }; + + + $scope.removeRole = function(availableRoleFunction) { + modalService.popupConfirmWin("Confirm","You are about to delete the role function "+availableRoleFunction.name+". Do you want to continue?", + function(){ + var uuu = "role_function_list/removeRoleFunction.htm"; + var postData={availableRoleFunction: availableRoleFunction}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){$scope.availableRoleFunctions=data.availableRoleFunctions;}); + }, + error : function(data){ + console.log(data); + modalService.showFailure("Fail","Error while deleting: "+ data.responseText); + } + }); + + }) + + }; + +}); diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/ase-controller.js b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/ase-controller.js new file mode 100644 index 000000000..45fc31ac8 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/ase-controller.js @@ -0,0 +1,22 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +app.controller('aseCtrl', function ($scope){ +/* do nothing yet*/ +}); diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/broadcast-controller.js b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/broadcast-controller.js new file mode 100644 index 000000000..77ee22f5f --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/broadcast-controller.js @@ -0,0 +1,79 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +app.controller('broadcastController', function ($scope, modalService, $modal,AdminService,$routeParams){ + //$scope.broadcastMessage=${broadcastMessage}; + //$scope.broadcastSites=${broadcastSites}; + //console.log($scope.broadcastMessage); + $scope.broadcastMessage=[]; + $scope.broadcastSites=[]; + AdminService.getBroadcast($routeParams.messageLocationId, $routeParams.messageLocation, $routeParams.messageId).then(function(data){ + var j = data; + $scope.data = JSON.parse(j.data); + $scope.broadcastMessage=JSON.parse($scope.data.broadcastMessage); + $scope.broadcastSites=JSON.parse($scope.data.broadcastSites); + console.log($scope.broadcastMessage); + console.log($scope.broadcastMessage.id); + console.log($scope.broadcastSites); + //$scope.resetMenu(); + + },function(error){ + console.log("failed"); + reloadPageOnce(); + }); + + $scope.save = function() { + var uuu = "broadcast/save"; + var postData={broadcastMessage: $scope.broadcastMessage}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + window.location.href = "admin#/broadcast_list"; + }, + error : function(data){ + modalService.showFailure("Fail","Error while saving."); + } + }); + }; + + $scope.close = function() { + window.location.href = "admin#/broadcast_list"; +}; + +}); + +$(function() { + $( "#startDatepicker" ).datepicker(); + $( "#endDatepicker" ).datepicker(); + + $( "#startDatepicker" ).change(function() { + var tempStartDate = moment($( "#startDatepicker" ).val()).format('YYYY-MM-DD hh:mm:ss.S'); + $( "#startDateHidden" ).val(tempStartDate.toString()); + //alert( $( "#startDateHidden" ).val() ); + }); + $( "#endDatepicker" ).change(function() { + var tempEndDate = moment($( "#endDatepicker" ).val()).format('YYYY-MM-DD hh:mm:ss.S'); + $( "#endDateHidden" ).val(tempEndDate.toString()); + //alert( $( "#endDateHidden" ).val() ); + }); +}); diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/broadcast-list-controller.js b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/broadcast-list-controller.js new file mode 100644 index 000000000..cb10a29b4 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/broadcast-list-controller.js @@ -0,0 +1,120 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +app.controller('broadcastListController', function ($scope, modalService, $modal,AdminService){ + //$scope.broadcastMessage=${broadcastMessage}; + //$scope.broadcastSites=${broadcastSites}; + //console.log($scope.broadcastMessage); + var messagesMap = {}; + AdminService.getBroadcastList().then(function(data){ + + var j = data; + $scope.data = JSON.parse(j.data); + $scope.messagesList=(($scope.data.messagesList===null) ? [""]:$scope.data.messagesList); + $scope.messageLocations=(($scope.data.messageLocations===null) ? [""]:$scope.data.messageLocations); + console.log("messages: "+$scope.messagesList); + console.log("location: "+$scope.messageLocations); + $.each($scope.messageLocations, function(i, a){ + //var result = []; + angular.forEach($scope.messagesList, function(value, key) { + if (key+'' === a.value+'') { + //var objsJSON = JSON.parse(value); + + $.each(value, function(i, a){ + var startDateLong = a.startDate; + var tempStartDate = new Date(startDateLong); + tempStartDate = moment(tempStartDate).format('DD MMM YYYY hh:mmA zz');//03 Jun 2013 04:15PM EDT + a.displayStartDate=tempStartDate.toString(); + + var endDateLong = a.endDate; + var tempEndDate = new Date(endDateLong); + tempEndDate = moment(tempEndDate).format('DD MMM YYYY hh:mmA zz');//03 Jun 2013 04:15PM EDT + a.displayEndDate=tempEndDate.toString(); + }); + a.messages = value; + } + }); + console.log(a.messages); + }); + + //$scope.resetMenu(); + + },function(error){ + console.log("failed"); + reloadPageOnce(); + }); + + + $scope.editMessage = function(location) { + + editMessage(location.value, location.label); + }; + + $scope.toggleActive = function(broadcastMessage) { + + //alert('deleted'+role.name); + var uuu = "broadcast_list/toggleActive"; + var postData={broadcastMessage:broadcastMessage}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + //window.location.reload(); + }, + error : function(data){ + console.log(data); + modalService.showFailure("Fail","Error while toggling: "+ data.responseText); + + } + }); + + + }; + + $scope.remove = function(broadcastMessage) { + + //alert('deleted'+role.name); + var uuu = "broadcast_list/remove"; + var postData={broadcastMessage:broadcastMessage}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + window.location.reload(); + }, + error : function(data){ + console.log(data); + modalService.showFailure("Fail","Error while deleting: "+ data.responseText); + } + }); + + + }; + +}); + +function editMessage(messageLocationId, messageLocation, messageId) { + window.location='admin#/broadcast/'+messageLocationId + '/' + messageLocation + ((messageId != null) ? '/' + messageId : ''); +} diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/collaborate-list-controller.js b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/collaborate-list-controller.js new file mode 100644 index 000000000..5b0b93421 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/collaborate-list-controller.js @@ -0,0 +1,63 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +app.controller("collaborateListController", function ($scope,$http,modalService, $modal,AdminService) { + // Table Data + AdminService.getCollaborateList().then(function(data){ + + var j = data; + $scope.tableData = JSON.parse(j.data); + //$scope.resetMenu(); + + },function(error){ + console.log("failed"); + reloadPageOnce(); + }); + + $scope.viewPerPage = 20; + $scope.scrollViewsPerPage = 2; + $scope.currentPage = 1; + $scope.totalPage; + $scope.searchCategory = ""; + $scope.searchString = ""; + /* modalService.showSuccess('','Modal Sample') ; */ + for(x in $scope.tableData){ + if($scope.tableData[x].active_yn=='Y') + $scope.tableData[x].active_yn=true; + else + $scope.tableData[x].active_yn=false; + } + $scope.openCollaboration = function(chatId){ + openInNewTab('collaboration?chat_id=' + chatId); + } + + $scope.toggleProfileActive = function(profileId) { + modalService.popupConfirmWin("Confirm","You are about to change user's active status. Do you want to continue?", + function(){ + $http.get("profile/toggleProfileActive?profile_id="+profileId).success(function(){}); + + }) + }; + +}); + +function openInNewTab(url) { + var win = window.open(url, '_blank'); + win.focus(); +}; diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/dummy.txt b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/dummy.txt new file mode 100644 index 000000000..e69de29bb diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/fn_menu_add_popup_controller.js b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/fn_menu_add_popup_controller.js new file mode 100644 index 000000000..e0179946f --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/fn_menu_add_popup_controller.js @@ -0,0 +1,281 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +var fn_menu_popupController = function ($scope, $modalInstance, message, $http){ /// examine the LeftMenuService + if(message.availableFnMenuItem==null) + $scope.label='Add New Menu Item' + + else{ + $scope.label='Edit Menu Item' + //$scope.disableParentId=true; + } + + $scope.getParentData = function(){ + var uuu = "admin_fn_menu/get_parent_list" + $.ajax({ + type : 'GET', + url : uuu, + dataType: 'json', // data type expected from server + contentType: 'application/json', + //data: JSON.stringify(postData), // data type sent to server + success : function(data){ + $scope.$apply(function(){ + //$scope.availableRoleFunctions=[];$scope.$apply(); + $scope.parentListSelectData=data; // data from server + menuItems = $scope.parentListSelectData; + var heirarchicalMenuItems = []; + var children = []; + for ( var i=0; i b[prop]) { + return 1; + } else if (a[prop] < b[prop]) { + return -1; + } + return 0; + } + + }; + + $scope.getParentLabel = function(parentId, parentListSelectData){ + var element; + element = parentListSelectData[0]; + for (var i=0; i=0) + $scope.importProfileList.splice(index, 1); + } + }; + + $scope.prepareProfileSelection = function() { + if($scope.importProfileList) + $.each($scope.importProfileList, function(i, profile){ + $scope.preparePostSearchBean(profile); + }); + ; + } + + $scope.preparePostSearchBean = function(profile) { + //console.log('Importing: '+profile.orgUserId); + //console.log('ngexistinguser:'+$scope.ngexistingUsers[profile.orgUserId]) + if($scope.postSearchBean.selected==null){ + $scope.postSearchBean.selected=[]; + $scope.postSearchBean.postOrgUserId=[]; + $scope.postSearchBean.postHrid=[]; + $scope.postSearchBean.postFirstName=[]; + $scope.postSearchBean.postLastName=[]; + $scope.postSearchBean.postOrgCode=[]; + $scope.postSearchBean.postPhone=[]; + $scope.postSearchBean.postEmail=[]; + $scope.postSearchBean.postAddress1=[]; + $scope.postSearchBean.postAddress2=[]; + $scope.postSearchBean.postCity=[]; + $scope.postSearchBean.postState=[]; + $scope.postSearchBean.postZipCode=[]; + $scope.postSearchBean.postLocationClli=[]; + $scope.postSearchBean.postBusinessCountryCode=[]; + $scope.postSearchBean.postBusinessCountryName=[]; + $scope.postSearchBean.postDepartment=[]; + $scope.postSearchBean.postDepartmentName=[]; + $scope.postSearchBean.postBusinessUnit=[]; + $scope.postSearchBean.postBusinessUnitName=[]; + $scope.postSearchBean.postJobTitle=[]; + $scope.postSearchBean.postOrgManagerUserId=[]; + $scope.postSearchBean.postCommandChain=[]; + $scope.postSearchBean.postCompanyCode=[]; + $scope.postSearchBean.postCompany=[]; + $scope.postSearchBean.postCostCenter=[]; + $scope.postSearchBean.postSiloStatus=[]; + $scope.postSearchBean.postFinancialLocCode=[]; + } + + $scope.postSearchBean.selected.push(profile.orgUserId); + $scope.postSearchBean.postOrgUserId.push(profile.orgUserId); + $scope.postSearchBean.postHrid.push(profile.hrid); + $scope.postSearchBean.postFirstName.push(profile.firstName); + $scope.postSearchBean.postLastName.push(profile.lastName); + $scope.postSearchBean.postOrgCode.push(profile.orgCode); + $scope.postSearchBean.postPhone.push(profile.phone); + $scope.postSearchBean.postEmail.push(profile.email); + $scope.postSearchBean.postAddress1.push(profile.address1); + $scope.postSearchBean.postAddress2.push(profile.address2); + $scope.postSearchBean.postCity.push(profile.city); + $scope.postSearchBean.postState.push(profile.state); + if(profile.zipCodeSuffix==null) + $scope.postSearchBean.postZipCode.push(profile.zipCode); + else + $scope.postSearchBean.postZipCode.push(profile.zipCode+'-'+profile.zipCodeSuffix); + $scope.postSearchBean.postLocationClli.push(profile.locationClli); + $scope.postSearchBean.postBusinessCountryCode.push(profile.businessCountryCode); + $scope.postSearchBean.postBusinessCountryName.push(profile.businessCountryName); + $scope.postSearchBean.postDepartment.push(profile.department); + $scope.postSearchBean.postDepartmentName.push(profile.departmentName); + $scope.postSearchBean.postBusinessUnit.push(profile.businessUnit); + $scope.postSearchBean.postBusinessUnitName.push(profile.businessUnitName); + $scope.postSearchBean.postJobTitle.push(profile.jobTitle); + $scope.postSearchBean.postOrgManagerUserId.push(profile.orgManagerUserId); + $scope.postSearchBean.postCommandChain.push(profile.commandChain); + $scope.postSearchBean.postCompanyCode.push(profile.companyCode); + $scope.postSearchBean.postCompany.push(profile.company); + $scope.postSearchBean.postCostCenter.push(profile.costCenter); + $scope.postSearchBean.postSiloStatus.push(profile.siloStatus); + $scope.postSearchBean.postFinancialLocCode.push(profile.financialLocCode); + }; + +}); diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/profile-controller.js b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/profile-controller.js new file mode 100644 index 000000000..aa0066b07 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/profile-controller.js @@ -0,0 +1,286 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +app.controller('profileController', function ($scope,$http,ProfileService,$routeParams,modalService){ + $scope.tableData=[]; + $scope.profile=[]; + $scope.ociavailableRoles=[]; + $scope.ociTimeZones; + $scope.ociCountries; + var stateList=[]; + $scope.availableRoles = []; + $scope.timeZones = []; + $scope.selectedTimeZone = null; + $scope.countries = []; + $scope.selectedCountry = null; + + ProfileService.getProfileDetail($routeParams.profileId).then(function(data){ + var j = data; + $scope.data = JSON.parse(j.data); + $scope.profile =JSON.parse($scope.data.profile); + $scope.ociavailableRoles =JSON.parse($scope.data.availableRoles); + $scope.ociTimeZones=JSON.parse($scope.data.timeZones); + $scope.ociCountries=JSON.parse($scope.data.countries); + stateList=JSON.parse($scope.data.stateList); + $scope.orgUserId=$scope.profile.orgUserId; + $scope.orgManagerUserId=$scope.profile.orgManagerUserId; + + + if($scope.ociavailableRoles) + $.each($scope.ociavailableRoles, function(i, a){ + var availableRole = a; + availableRole.selected = false; + $.each($scope.profile.roles, function(j, b){ + if(a.id === b.id) { + availableRole.selected = true; + } + }); + $scope.availableRoles.push(availableRole); + }); + ; + + /*$scope.ociTimeZones = ${model.timeZones};*/ + + if($scope.ociTimeZones){ + $.each($scope.ociTimeZones, function(i, a){ + var timeZone = {"index":i, "value":a.value, "title":a.label}; + $scope.timeZones.push(timeZone); + if($scope.profile.timeZoneId !== null && a.value === $scope.profile.timeZoneId.toString()){ + $scope.selectedTimeZone = timeZone; + } + }); + }; + + /*$scope.ociCountries = ${model.countries};*/ + + //alert($scope.ociCountries[0].label); + if($scope.ociCountries) + $.each($scope.ociCountries, function(i, a){ + var country = {"index":i, "value":a.value, "title":a.label}; + $scope.countries.push(country); + if(a.value === $scope.profile.country){ + $scope.selectedCountry = country; + } + }); + ; + + /*var stateList=${model.stateList};*/ + //alert(stateList[0].label); + stateList = stateList== null? []: stateList; + var selectedState= $scope.profile.state ? $scope.profile.state:""; + $scope.stateList = initDropdownWithLookUp(stateList,selectedState ); + + //$scope.resetMenu(); + },function(error){ + console.log("failed"); + reloadPageOnce(); + }); + + /*$scope.profile=${model.profile};*/ + $scope.orgUserId=$scope.profile.orgUserId; + $scope.orgManagerUserId=$scope.profile.orgManagerUserId; + + $scope.viewPerPage = 2; + $scope.currentPage = 1; + $scope.totalPage; + $scope.searchCategory = ""; + $scope.searchString = ""; + + $( "#dialog" ).hide(); + + /*$scope.ociavailableRoles=${model.availableRoles};*/ + //modalService.showFailure('Error','') ; + + + $scope.saveProfile = function() { + var uuu = "profile/saveProfile?profile_id=" + $routeParams.profileId; + var postData={profile: $scope.profile, + selectedCountry:$scope.selectedCountry!=null?$scope.selectedCountry.value:"", + selectedState:$scope.stateList.selected!=null?$scope.stateList.selected.value:"", + selectedTimeZone:$scope.selectedTimeZone!=null?$scope.selectedTimeZone.value:"" + }; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + modalService.showSuccess("Success","Update Successful."); + }, + error : function(data){ + modalService.showFailure("Fail","Error while saving."); + } + }); + }; + + $scope.addNewRolePopup = function(role) { + $( "#dialog" ).dialog({ + modal: true, + width: 500, + height:600 + }); + $(".ui-dialog").css("z-index",2001); + $(".ui-dialog-titlebar").hide(); + }; + + $scope.toggleRole = function(selected,availableRole) { + $scope.profileTemp=$scope.profile; + $scope.profile={}; + //alert('toggleRole: '+selected); + if(!selected) { + //remove role + var uuu = "profile/removeRole?profile_id=" + $routeParams.profileId; + modalService.popupConfirmWinWithCancel("Confirm","You are about to remove the role "+availableRole.name+" from the profile for "+$scope.profile.firstName+" "+$scope.profile.lastName+". Do you want to continue?", + function(){ + var postData={role:availableRole}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){$scope.profile=data;}); + }, + error : function(data){ + $scope.$apply(function(){$scope.profile=$scope.profileTemp;}); + modalService.showFailure("Fail","Error while saving."); + } + }); + }, + function(){ + availableRole.selected=!availableRole.selected; + }); + + + } else { + //add role + var uuu = "profile/addNewRole?profile_id=" + $routeParams.profileId; + modalService.popupConfirmWinWithCancel("Confirm","You are about to add the role "+availableRole.name+" from the profile for "+$scope.profile.firstName+" "+$scope.profile.lastName+". Do you want to continue?", + function(){ + var postData={role:availableRole}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){$scope.profile=data;}); + }, + error : function(data){ + $scope.$apply(function(){$scope.profile=$scope.profileTemp;}); + modalService.showFailure("Fail","Error while saving."); + } + }); + + },function(){ + availableRole.selected=!availableRole.selected; + }) + + } + + + }; + + $scope.removeRole = function(role) { + + + modalService.popupConfirmWin("Confirm","You are about to remove the role "+role.name+" from the profile for "+$scope.profile.firstName+" "+$scope.profile.lastName+". Do you want to continue?", + function(){ + $scope.profileTemp=$scope.profile; + $scope.profile={}; + var uuu = "profile/removeRole?profile_id=" + $routeParams.profileId; + var postData={role:role}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){ + $scope.profile=data; + $.each($scope.availableRoles, function(k, c){ + if(c.id === role.id) { + c.selected = false; + } + }); + }); + + }, + error : function(data){ + $scope.$apply(function(){$scope.profile=$scope.profileTemp;}); + modalService.showFailure("Fail","Error while saving."); + } + }); + + }) + + + }; + + function initDropdownWithLookUp(arr,selectedValue){ + var dropdownArray=[]; + var selected = null; + if(arr){ + for(var i = 0,l = arr.length; i < l; i++) { + var option = { + "index" : i , + "value" : arr[i].value, + "title" : arr[i].label + }; + dropdownArray.push(option); + if(arr[i].value === selectedValue){ + selected = option; + } + } + } + var dropDown={}; + dropDown.options = dropdownArray; + dropDown.selected = selected; + return dropDown; + }; + + $scope.doRolePopup = function() { + var modalInstance = $modal.open({ + templateUrl: 'roles_popup.html', + controller: 'rolepopupController', + resolve: { + message: function () { + var message ={ + availableRoles: $scope.availableRoles + }; + return message; + } + } + }); + modalInstance.result.then(function (opts) { + if(opts!=null){ + $scope.profile=opts.profile; + } + }); + } + + $scope.close = function(){ + $('#dialog').dialog('close'); + } + +}); diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/profile-search-controller.js b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/profile-search-controller.js new file mode 100644 index 000000000..6da82dcc6 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/profile-search-controller.js @@ -0,0 +1,80 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +app.controller('profileSearchCtrl', function($scope, $http,ProfileService,modalService){ + + $scope.showInput = true; + $scope.totalPages1 = 5; + $scope.viewPerPage1 = 8; + $scope.currentPage1 = 1; + + $scope.$watch('viewPerPage1', function(val) { + ProfileService.getProfilePagination($scope.currentPage1, val).then(function(data){ + var j = data; + $scope.data = JSON.parse(j.data); + $scope.tableData =JSON.parse($scope.data.profileList); + $scope.totalPages1 =JSON.parse($scope.data.totalPage); + for(x in $scope.tableData){ + if($scope.tableData[x].active_yn=='Y') + $scope.tableData[x].active_yn=true; + else + $scope.tableData[x].active_yn=false; + } + },function(error){ + console.log("failed"); + reloadPageOnce(); + }); + + }); + + $scope.customHandler = function(num) { + $scope.currentPage1 = num; + ProfileService.getProfilePagination($scope.currentPage1,$scope.viewPerPage1).then(function(data){ + var j = data; + $scope.data = JSON.parse(j.data); + $scope.tableData =JSON.parse($scope.data.profileList); + $scope.totalPages1 =JSON.parse($scope.data.totalPage); + for(x in $scope.tableData){ + if($scope.tableData[x].active_yn=='Y') + $scope.tableData[x].active_yn=true; + else + $scope.tableData[x].active_yn=false; + } + },function(error){ + console.log("failed"); + reloadPageOnce(); + }); + + }; + + $scope.editRow = function(profileId){ + window.location = 'userProfile#/profile/' + profileId; + }; + + $scope.toggleProfileActive = function(rowData) { + modalService.popupConfirmWinWithCancel("Confirm","You are about to change user's active status. Do you want to continue?", + function(){ + $http.get("profile/toggleProfileActive?profile_id="+rowData.id).success(function(){}); + }, + function(){ + rowData.active=!rowData.active; + }) + }; + +}); diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/profileController.js b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/profileController.js new file mode 100644 index 000000000..4b30e40ea --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/profileController.js @@ -0,0 +1,38 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +app.config(function($routeProvider) { + $routeProvider + .when('/profile/:profileId', { + templateUrl: 'app/fusion/scripts/view-models/profile-page/profile_detail.html', + controller: 'profileController' + }) + .when('/post_search', { + templateUrl: 'app/fusion/scripts/view-models/profile-page/post_search.html', + controller: 'postSearchCtrl' + }) + .when('/self_profile', { + templateUrl: 'app/fusion/scripts/view-models/profile-page/self_profile.html', + controller: 'selfProfileController' + }) + .otherwise({ + templateUrl: 'app/fusion/scripts/view-models/profile-page/profile_search.html', + controller : "profileSearchCtrl" + }); +}); diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/role-controller.js b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/role-controller.js new file mode 100644 index 000000000..50913af8e --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/role-controller.js @@ -0,0 +1,226 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +app.controller('roleController', function ($scope, modalService, $modal, AdminService,$routeParams){ + //$scope.role=${role}; + //console.log($scope.role.roleFunctions); + + $( "#dialogRoleFunction" ).hide(); + $( "#dialogChildRole" ).hide(); + + //$scope.ociavailableRoleFunctions=${availableRoleFunctions}; + + AdminService.getRole($routeParams.roleId).then(function(data){ + + var j = data; + $scope.data = JSON.parse(j.data); + + $scope.role =JSON.parse($scope.data.role); + console.log($scope.role); + + $scope.ociavailableRoleFunctions =JSON.parse($scope.data.availableRoleFunctions); + console.log($scope.ociavailableRoleFunctions); + $scope.availableRoleFunctions=[]; + + if($scope.ociavailableRoleFunctions) + $.each($scope.ociavailableRoleFunctions, function(i, a){ + var availableRoleFunction = a; + availableRoleFunction.selected = false; + $.each($scope.role.roleFunctions, function(j, b){ + if(a.code === b.code) { + availableRoleFunction.selected = true; + } + }); + $scope.availableRoleFunctions.push(availableRoleFunction); + }); + + + $scope.ociavailableRoles=JSON.parse($scope.data.availableRoles); + console.log($scope.ociavailableRoles); + console.log("testing roles if exist"); + $scope.availableRoles=[]; + + if($scope.ociavailableRoles) + $.each($scope.ociavailableRoles, function(i, a){ + var availableRole = a; + availableRole.selected = false; + if($scope.role.childRoles){ + $.each($scope.role.childRoles, function(j, b){ + if(a.id === b.id) { + availableRole.selected = true; + } + }); + }; + $scope.availableRoles.push(availableRole); + }); + + + },function(error){ + console.log("failed"); + reloadPageOnce(); + }); + + $scope.saveRole = function() { + var exists = false; + for(x in $scope.availableRoles){ + console.log($scope.availableRoles[x].name); + if($scope.availableRoles[x].name==$scope.role.name){ + modalService.showFailure("Warning", "Role already exists."); + exists = true; + //$modalInstance.close({availableRoleFunctions:message.availableRoleFunctions}); + } + } + if(!exists){ + var uuu = "role/saveRole.htm?role_id="+$routeParams.roleId; + var postData={role: $scope.role, childRoles: $scope.role.childRoles, roleFunctions : $scope.role.roleFunctions}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + modalService.showSuccess("Success","Update Successful."); + }, + error : function(data){ + console.log(data); + modalService.showFailure("Fail","Error while saving."); + } + }); + } + + }; + + $scope.addNewRoleFunctionModalPopup = function() { + var modalInstance = $modal.open({ + templateUrl: 'role_functions_popup.html', + controller: 'rolepopupController', + backdrop: 'static', + resolve: { + roleId: function () { + return $routeParams.roleId; + }, + role: function () { + return $scope.role; + }, + availableRoles: function () { + return $scope.ociavailableRoles; + }, + availableRoleFunctions: function () { + return $scope.ociavailableRoleFunctions; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.role=response.role; + }); + }; + + $scope.addNewChildRoleModalPopup = function() { + var modalInstance = $modal.open({ + templateUrl: 'child_roles_popup.html', + controller: 'rolepopupController', + backdrop: 'static', + resolve: { + roleId: function () { + return $routeParams.roleId; + }, + role: function () { + return $scope.role; + }, + availableRoles: function () { + return $scope.ociavailableRoles; + }, + availableRoleFunctions: function () { + return $scope.ociavailableRoleFunctions; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.role=response.role; + }); + }; + + + + $scope.removeRoleFunction = function(roleFunction) { + modalService.popupConfirmWin("Confirm","You are about to remove the role function "+roleFunction.name+" from the role for "+$scope.role.name+". Do you want to continue?", + function(){ + var uuu = "role/removeRoleFunction.htm?role_id=" + $routeParams.roleId; + var postData={roleFunction:roleFunction}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){ + $scope.role=data.role; + $.each($scope.availableRoleFunctions, function(k, c){ + if(c.code === roleFunction.code) { + c.selected = false; + } + }); + }); + + }, + error : function(data){ + modalService.showFailure("Fail","Error while saving."); + } + }); + + }) + + }; + + $scope.removeChildRole = function(childRole) { + modalService.popupConfirmWin("Confirm","You are about to remove the child role "+childRole.name+" from the role for "+$scope.role.name+". Do you want to continue?", + function(){ + var uuu = "role/removeChildRole.htm?role_id=" + $routeParams.roleId; + var postData={childRole:childRole}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){ + $scope.role=data.role; + $.each($scope.availableRoles, function(k, c){ + if(c.id === childRole.id) { + c.selected = false; + } + }); + }); + + }, + error : function(data){ + modalService.showFailure("Fail","Error while saving."); + } + }); + + }) + + }; + +}); diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/role-function-list-controller.js b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/role-function-list-controller.js new file mode 100644 index 000000000..eedac3e06 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/role-function-list-controller.js @@ -0,0 +1,157 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +app.controller('roleFunctionListController', function ($scope, AdminService, modalService, $modal){ + $( "#dialog" ).hide(); + + AdminService.getRoleFunctionList().then(function(data){ + + var j = data; + $scope.data = JSON.parse(j.data); + $scope.availableRoleFunctions =JSON.parse($scope.data.availableRoleFunctions); + + //$scope.resetMenu(); + + },function(error){ + console.log("failed"); + reloadPageOnce(); + }); + + $scope.editRoleFunction = null; + var dialog = null; + $scope.editRoleFunctionPopup = function(availableRoleFunction) { + $scope.editRoleFunction = availableRoleFunction; + $( "#dialog" ).dialog({ + modal: true + }); + }; + + $scope.editRoleFunctionModalPopup = function(availableRoleFunction) { + $scope.editRoleFunction = availableRoleFunction; + $scope.availableRoleFunctionsTemp=$scope.availableRoleFunctions; + $scope.availableRoleFunctions={}; + var modalInstance = $modal.open({ + templateUrl: 'edit_role_function_popup.html', + controller: 'rolefunctionpopupController', + resolve: { + message: function () { + var message = { + availableRoleFunction: $scope.editRoleFunction, + availableRoleFunctions: $scope.availableRoleFunctionsTemp + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + if(response!=null) + $scope.availableRoleFunctions=response.availableRoleFunctions; + else + $scope.availableRoleFunctions=$scope.availableRoleFunctionsTemp; + }); + }; + + $scope.addNewRoleFunctionModalPopup = function(availableRoleFunction) { + $scope.editRoleFunction = null; + $scope.availableRoleFunctionsTemp=$scope.availableRoleFunctions; + $scope.availableRoleFunctions={}; + var modalInstance = $modal.open({ + templateUrl: 'edit_role_function_popup.html', + controller: 'rolefunctionpopupController', + resolve: { + message: function () { + var message = { + availableRoleFunction: $scope.editRoleFunction, + availableRoleFunctions: $scope.availableRoleFunctionsTemp + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + if(response!=null) + $scope.availableRoleFunctions=response.availableRoleFunctions; + else + $scope.availableRoleFunctions=$scope.availableRoleFunctionsTemp; + }); + }; + + $scope.addNewRoleFunctionPopup = function() { + $scope.editRoleFunction = null; + $( "#dialog" ).dialog({ + modal: true + }); + }; + + $scope.saveRoleFunction = function(availableRoleFunction) { + var uuu = "role_function_list/saveRoleFunction.htm"; + var postData={availableRoleFunction: availableRoleFunction}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){ + $scope.availableRoleFunctions=[];$scope.$apply(); + $scope.availableRoleFunctions=data.availableRoleFunctions;}); + //alert("Update Successful.") ; + console.log($scope.availableRoleFunctions); + + $scope.editRoleFunction = null; + $( "#dialog" ).dialog("close"); + }, + error : function(data){ + modalService.showFailure("Fail","Error while saving."); + } + }); + }; + + + $scope.removeRole = function(availableRoleFunction) { + modalService.popupConfirmWin("Confirm","You are about to delete the role function "+availableRoleFunction.name+". Do you want to continue?", + function(){ + $scope.availableRoleFunctionsTemp=$scope.availableRoleFunctions; + $scope.availableRoleFunctions={}; + var uuu = "role_function_list/removeRoleFunction.htm"; + var postData={availableRoleFunction: availableRoleFunction}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){$scope.availableRoleFunctions=data.availableRoleFunctions;}); + }, + error : function(data){ + console.log(data); + $scope.$apply(function(){$scope.availableRoleFunctions=$scope.availableRoleFunctionsTemp;}); + modalService.showFailure("Fail","Error while deleting: "+ data.responseText); + } + }); + + }) + + }; + +}); diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/role-list-controller.js b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/role-list-controller.js new file mode 100644 index 000000000..a16d61ef2 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/role-list-controller.js @@ -0,0 +1,102 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +app.controller('roleListController', function ($scope,AdminService,modalService){ + + AdminService.getRoles().then(function(data){ + + var j = data; + $scope.data = JSON.parse(j.data); + $scope.availableRoles =JSON.parse($scope.data.availableRoles); + + //$scope.resetMenu(); + + },function(error){ + console.log("failed"); + reloadPageOnce(); + }); + + //console.log($scope.availableRoles); + $scope.toggleRole = function(selected,availableRole) { + //alert('toggleRole: '+selected); + var toggleType = null; + if(selected) { + toggleType = "activate"; + } else { + toggleType = "inactivate"; + } + + modalService.popupConfirmWinWithCancel("Confirm","You are about to "+toggleType+" the test role "+availableRole.name+". Do you want to continue?", + function(){ + var uuu = "role_list/toggleRole"; + + var postData={role:availableRole}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + console.log(data); + $scope.$apply(function(){$scope.availableRoles=data.availableRoles;}); + console.log($scope.availableRoles); + }, + error : function(data){ + console.log(data); + modalService.showFailure("Fail","Error while saving."); + } + }); + + }, + function(){ + availableRole.active=!availableRole.active; + }) + + + }; + + $scope.removeRole = function(role) { + + modalService.popupConfirmWin("Confirm","You are about to delete the role "+role.name+". Do you want to continue?", + function(){ + var uuu = "role_list/removeRole"; + var postData={role:role}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){$scope.availableRoles=data.availableRoles;}); + }, + error : function(data){ + console.log(data); + modalService.showFailure("Fail","Error while deleting: "+ data.responseText); + } + }); + + }) + + + }; + + +}); diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/rolefunctionpopupController.js b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/rolefunctionpopupController.js new file mode 100644 index 000000000..14aea22c0 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/rolefunctionpopupController.js @@ -0,0 +1,84 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +var rolefunctionpopupController = function ($scope, modalService, $modalInstance, message, $http,AdminService){ + if(message.availableRoleFunction==null) { + $scope.label='Add Role Function'; + var tempText = ""; + } + else{ + $scope.label='Edit Role Function' + $scope.disableCd=true; + var tempText = new String(message.availableRoleFunction.name); + $scope.editRoleFunction = message.availableRoleFunction; + } + + $scope.tempText = tempText; + + $scope.saveRoleFunction = function(availableRoleFunction) { + var uuu = "role_function_list/saveRoleFunction.htm"; + var postData={availableRoleFunction: availableRoleFunction}; + + if(availableRoleFunction==null){ + modalService.showFailure("Warning", "Please enter valid role function details."); + } + var exists = false; + for(x in message.availableRoleFunctions){ + console.log(message.availableRoleFunctions[x].name); + if(message.availableRoleFunctions[x].name==availableRoleFunction.name){ + modalService.showFailure("Warning", "Role Function already exists."); + exists = true; + availableRoleFunction.name = $scope.tempText; + } + } + + if(!exists && availableRoleFunction.name.trim() != '' && availableRoleFunction.code.trim() != ''){ + $http.post(uuu, JSON.stringify(postData)).then(function(res){ + console.log("data"); +// console.log(res.data); +// $scope.availableRoleFunctionsTemp = res.data.availableRoleFunctions; + AdminService.getRoleFunctionList().then(function(data){ + + var j = data; + $scope.data = JSON.parse(j.data); + $scope.availableRoleFunctions =JSON.parse($scope.data.availableRoleFunctions); + + //$scope.resetMenu(); + $modalInstance.close(); + },function(error){ + console.log("failed"); + reloadPageOnce(); + $modalInstance.close(); + }); + + + }); + + + + + } + }; + + + + $scope.close = function() { + $modalInstance.close(); + }; +} diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/rolepopupmodelController.js b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/rolepopupmodelController.js new file mode 100644 index 000000000..f8ecfaddb --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/rolepopupmodelController.js @@ -0,0 +1,205 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +var rolepopupController = function ($scope, $modalInstance, role, roleId, availableRoles, availableRoleFunctions,AdminService,modalService){ + + $scope.role = role; + console.log($scope.role); + if($scope.role.childRoles==null){ + $scope.role.childRoles=[]; + } + + $scope.ociavailableRoles=availableRoles; + console.log($scope.ociavailableRoles); + + $scope.availableRoles=[]; + if($scope.ociavailableRoles) + $.each($scope.ociavailableRoles, function(i, a){ + var availableRole = a; + availableRole.selected = false; + if($scope.role.childRoles){ + $.each($scope.role.childRoles, function(j, b){ + if(a.id === b.id) { + availableRole.selected = true; + } + }); + }; + $scope.availableRoles.push(availableRole); + }); + + $scope.ociavailableRoleFunctions = availableRoleFunctions; + console.log($scope.ociavailableRoleFunctions); + $scope.availableRoleFunctions = []; + if($scope.ociavailableRoleFunctions) + $.each($scope.ociavailableRoleFunctions, function(i, a){ + var availableRoleFunction = a; + availableRoleFunction.selected = false; + $.each($scope.role.roleFunctions, function(j, b){ + if(a.code === b.code) { + availableRoleFunction.selected = true; + } + }); + $scope.availableRoleFunctions.push(availableRoleFunction); + }); + //$scope.resetMenu(); + + $scope.toggleRoleFunction = function(selected,availableRoleFunction) { + //alert('toggleRole: '+selected); + + if(!selected) { + //remove role function + if(role.id==null){ + var index = $scope.role.roleFunctions.indexOf(availableRoleFunction); + if(index>=0) + $scope.role.roleFunctions.splice(index, 1); + return; + } + var uuu = "role/removeRoleFunction.htm?role_id=" + roleId; + modalService.popupConfirmWinWithCancel("Confirm","You are about to remove the role function "+availableRoleFunction.name+" from the role for "+$scope.role.name+". Do you want to continue?", + function(){ + var postData={roleFunction:availableRoleFunction}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){$scope.role=data.role;}); + }, + error : function(data){ + modalService.showFailure("Fail","Error while saving."); + } + }); + + }, + function(){ + availableRoleFunction.selected=!availableRoleFunction.selected; + }) + + } else { + //add role function + if(role.id==null){ + $scope.role.roleFunctions.push(availableRoleFunction); + return; + } + var uuu = "role/addRoleFunction.htm?role_id=" + roleId; + + modalService.popupConfirmWinWithCancel("Confirm","You are about to add the role function "+availableRoleFunction.name+" to the role for "+$scope.role.name+". Do you want to continue?", + function(){ + var postData={roleFunction:availableRoleFunction}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){$scope.role=data.role;}); + }, + error : function(data){ + modalService.showFailure("Fail","Error while saving."); + } + }); + + }, + function(){ + availableRoleFunction.selected=!availableRoleFunction.selected; + }) + } + + + }; + + $scope.toggleChildRole = function(selected,availableRole) { + //alert('toggleRole: '+selected); + + if(!selected) { + //remove role + if(role.id==null){ + var index = $scope.role.childRoles.indexOf(availableRole); + if(index>=0) + $scope.role.childRoles.splice(index, 1); + return; + } + var uuu = "role/removeChildRole.htm?role_id=" + roleId; + + modalService.popupConfirmWinWithCancel("Confirm","You are about to remove the child role "+availableRole.name+" from the role for "+$scope.role.name+". Do you want to continue?", + function(){ + var postData={childRole:availableRole}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + console.log('role',data.role); + $scope.$apply(function(){$scope.role=data.role;}); + }, + error : function(data){ + modalService.showFailure("Fail","Error while saving."); + } + }); + + }, + function(){ + availableRole.selected=true; + }) + + } else { + //add role + if(role.id==null){ + $scope.role.childRoles.push(availableRole); + return; + } + var uuu = "role/addChildRole.htm?role_id=" + roleId; + + modalService.popupConfirmWinWithCancel("Confirm","You are about to add the child role "+availableRole.name+" to the role for "+$scope.role.name+". Do you want to continue?", + function(){ + var postData={childRole:availableRole}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){$scope.role=data.role;}); + }, + error : function(data){ + modalService.showFailure("Fail","Error while saving."); + } + }); + + }, + function(){ + availableRole.selected=false; + }) + } + + + }; + + $scope.close = function() { + console.log('role', $scope.role); + $modalInstance.close({role:$scope.role}); + }; + +} diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/self-profile-controller.js b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/self-profile-controller.js new file mode 100644 index 000000000..b82dae306 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/self-profile-controller.js @@ -0,0 +1,284 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +app.controller('selfProfileController', function ($scope,$http,ProfileService,$routeParams,modalService){ + $scope.tableData=[]; + $scope.profile=[]; + $scope.ociavailableRoles=[]; + $scope.ociTimeZones; + $scope.ociCountries; + var stateList=[]; + $scope.availableRoles = []; + $scope.timeZones = []; + $scope.selectedTimeZone = null; + $scope.countries = []; + $scope.selectedCountry = null; + $scope.isUserSystemAdmin = false; + + ProfileService.getSelfProfileDetail().then(function(data){ + var j = data; + $scope.data = JSON.parse(j.data); + $scope.profile =JSON.parse($scope.data.profile); + $scope.profileId = $scope.profile.id; + $scope.ociavailableRoles =JSON.parse($scope.data.availableRoles); + $scope.ociTimeZones=JSON.parse($scope.data.timeZones); + $scope.ociCountries=JSON.parse($scope.data.countries); + stateList=JSON.parse($scope.data.stateList); + $scope.orgUserId=$scope.profile.orgUserId; + $scope.orgManagerUserId=$scope.profile.orgManagerUserId; + + if($scope.ociavailableRoles) + $.each($scope.ociavailableRoles, function(i, a){ + var availableRole = a; + availableRole.selected = false; + $.each($scope.profile.roles, function(j, b){ + if(a.id === b.id) { + availableRole.selected = true; + if(a.id === 1){ + $scope.isUserSystemAdmin = true; + } + } + }); + $scope.availableRoles.push(availableRole); + }); + ; + + /*$scope.ociTimeZones = ${model.timeZones};*/ + + if($scope.ociTimeZones){ + $.each($scope.ociTimeZones, function(i, a){ + var timeZone = {"index":i, "value":a.value, "title":a.label}; + $scope.timeZones.push(timeZone); + if($scope.profile.timeZoneId !== null && a.value === $scope.profile.timeZoneId.toString()){ + $scope.selectedTimeZone = timeZone; + } + }); + }; + + /*$scope.ociCountries = ${model.countries};*/ + + //alert($scope.ociCountries[0].label); + if($scope.ociCountries) + $.each($scope.ociCountries, function(i, a){ + var country = {"index":i, "value":a.value, "title":a.label}; + $scope.countries.push(country); + if(a.value === $scope.profile.country){ + $scope.selectedCountry = country; + } + }); + ; + + /*var stateList=${model.stateList};*/ + //alert(stateList[0].label); + stateList = stateList== null? []: stateList; + var selectedState= $scope.profile.state ? $scope.profile.state:""; + $scope.stateList = initDropdownWithLookUp(stateList,selectedState ); + + //$scope.resetMenu(); + },function(error){ + console.log("failed"); + reloadPageOnce(); + }); + + /*$scope.profile=${model.profile};*/ + $scope.orgUserId=$scope.profile.orgUserId; + $scope.orgManagerUserId=$scope.profile.orgManagerUserId; + + $scope.viewPerPage = 2; + $scope.currentPage = 1; + $scope.totalPage; + $scope.searchCategory = ""; + $scope.searchString = ""; + + $( "#dialog" ).hide(); + + /*$scope.ociavailableRoles=${model.availableRoles};*/ + //modalService.showFailure('Error','') ; + + + $scope.saveProfile = function() { + var uuu = "profile/saveProfile?profile_id=" + $scope.profileId;; + var postData={profile: $scope.profile, + selectedCountry:$scope.selectedCountry!=null?$scope.selectedCountry.value:"", + selectedState:$scope.stateList.selected!=null?$scope.stateList.selected.value:"", + selectedTimeZone:$scope.selectedTimeZone!=null?$scope.selectedTimeZone.value:"" + }; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + modalService.showSuccess("Success","Update Successful."); + }, + error : function(data){ + modalService.showFailure("Fail","Error while saving."); + } + }); + }; + + $scope.addNewRolePopup = function(role) { + $( "#dialog" ).dialog({ + modal: true, + width: 500, + height:600 + }); + + $(".ui-dialog").css("z-index",10002); + $(".ui-dialog-titlebar").hide(); + }; + + $scope.toggleRole = function(selected,availableRole) { + //alert('toggleRole: '+selected); + if(!selected) { + //remove role + var uuu = "profile/removeRole?profile_id=" + $scope.profileId;; + modalService.popupConfirmWinWithCancel("Confirm","You are about to remove the role "+availableRole.name+" from the profile for "+$scope.profile.firstName+" "+$scope.profile.lastName+". Do you want to continue?", + function(){ + var postData={role:availableRole}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){$scope.profile=data;}); + }, + error : function(data){ + modalService.showFailure("Fail","Error while saving."); + } + }); + }, + function(){ + availableRole.selected=!availableRole.selected; + }); + + + } else { + //add role + var uuu = "profile/addNewRole?profile_id=" + $scope.profileId;; + modalService.popupConfirmWinWithCancel("Confirm","You are about to add the role "+availableRole.name+" from the profile for "+$scope.profile.firstName+" "+$scope.profile.lastName+". Do you want to continue?", + function(){ + var postData={role:availableRole}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){$scope.profile=data;}); + }, + error : function(data){ + modalService.showFailure("Fail","Error while saving."); + } + }); + + },function(){ + availableRole.selected=!availableRole.selected; + }) + + } + + + }; + + $scope.removeRole = function(role) { + + + modalService.popupConfirmWin("Confirm","You are about to remove the role "+role.name+" from the profile for "+$scope.profile.firstName+" "+$scope.profile.lastName+". Do you want to continue?", + function(){ + var uuu = "profile/removeRole?profile_id=" + $scope.profileId;; + var postData={role:role}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){ + $scope.profile=data; + $.each($scope.availableRoles, function(k, c){ + if(c.id === role.id) { + c.selected = false; + } + }); + }); + + }, + error : function(data){ + modalService.showFailure("Fail","Error while saving."); + } + }); + + }) + + + }; + + function initDropdownWithLookUp(arr,selectedValue){ + var dropdownArray=[]; + var selected = null; + if(arr){ + for(var i = 0,l = arr.length; i < l; i++) { + var option = { + "index" : i , + "value" : arr[i].value, + "title" : arr[i].label + }; + dropdownArray.push(option); + if(arr[i].value === selectedValue){ + selected = option; + } + } + } + var dropDown={}; + dropDown.options = dropdownArray; + dropDown.selected = selected; + return dropDown; + }; + + $scope.doRolePopup = function() { + var modalInstance = $modal.open({ + templateUrl: 'roles_popup.html', + controller: 'rolepopupController', + resolve: { + message: function () { + var message ={ + availableRoles: $scope.availableRoles + }; + return message; + } + } + }); + modalInstance.result.then(function (opts) { + if(opts!=null){ + $scope.profile=opts.profile; + } + }); + } + + $scope.close = function(){ + $('#dialog').dialog('close'); + } + +}); diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/usage-list-controller.js b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/usage-list-controller.js new file mode 100644 index 000000000..b495b9340 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/usage-list-controller.js @@ -0,0 +1,41 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +app.controller('usageListController', function ($scope,$interval,$http,$modal,modalService,AdminService){ + + AdminService.getUsageList().then(function(data){ + + var j = data; + $scope.data = JSON.parse(j.data); + $scope.users =$scope.data; + //$scope.resetMenu(); + + },function(error){ + console.log("failed"); + reloadPageOnce(); + }); + + $scope.removeSession = function(sessionId) { + modalService.popupConfirmWin("Confirm","You are about to expel this user from the application. All of their unsaved data will be lost. Do you want to continue?", + function(){ + $http.get("usage_list/removeSession?deleteSessionId="+sessionId).success(function(response){$scope.users=response;}); + }) + + } +}); diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/workflows/workflowApp.js b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/workflows/workflowApp.js new file mode 100644 index 000000000..0a5c80196 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/workflows/workflowApp.js @@ -0,0 +1,24 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +angular.module('att.abs.helper', []); +angular.module('quantum', []); + +var app=angular.module("workflowApp", ["att.abs", "att.abs.helper","modalServices", + "att.gridster","checklist-model","ngRoute", "ui.bootstrap"]); diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/workflows/workflowController.js b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/workflows/workflowController.js new file mode 100644 index 000000000..169a88680 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/workflows/workflowController.js @@ -0,0 +1,509 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +app.controller('workflowsController', function($scope, $http, $uibModal, $log, modalService, $modal) { + + $scope.viewPerPage = 5; + $scope.scrollViewsPerPage = 20; + $scope.currentPage = 2; + $scope.totalPage; + $scope.searchCategory = ""; + $scope.searchString = ""; + $scope.radio = { + value: "" + }; + + + $scope.showModal = false; + $scope.toggleModal = function(){ + $scope.showModal = !$scope.showModal; + }; + + $scope.workflow = {}; + $scope.workflow.active = "true"; + + $scope.updateAllWorkflowStatus = function() { + angular.forEach($scope.workflows,function(value){ + $scope.checkWorkflowStatus(value); + }) + } + + $scope.fetchWorkflowsList = function() { + $http.get('workflows/list').then(function(workflowList){ + console.log('Got new list from server = ' + workflowList.data); + $scope.workflows = workflowList.data; + $scope.updateAllWorkflowStatus(); + }); + }; + + $scope.addNewWorkflow = function(newWorkflow) { + $http.post('workflows/addWorkflow/', JSON.stringify(newWorkflow)).success(function() { + $scope.fetchWorkflowsList(); + }); + + $scope.workflow.name = ''; + + }; + + $scope.updateWorkflow = function (workflowToEdit) { + //workflowToEdit.active='true'; + var modalInstance = $uibModal.open({ + animation: $scope.animationsEnabled, + templateUrl: 'app/fusion/scripts/view-models/workflows/workflow-new.html', + //size : modalSize, + controller: ['$scope', '$uibModalInstance', '$http', function ($scope, $uibModalInstance, $http) { + $scope.workflow = workflowToEdit; + $scope.ok = function() { + console.log('Updating existing workflow ... ' + JSON.stringify($scope.workflow)); + $http.post('workflows/editWorkflow/', JSON.stringify($scope.workflow)).then(function(returnedWorkflow){ + console.log('Returned Workflow = ' + JSON.stringify(returnedWorkflow)); + $uibModalInstance.close($scope.workflow); + }); + }; + + $scope.cancel = function() { + $uibModalInstance.dismiss(); + }; + }], + //End of inner controller + resolve: { + workflow: function() { + console.log('Passing ' + JSON.stringify($scope.workflow)); + return $scope.workflow; + } + } + }); + + modalInstance.result.then(function (editedWorkFlow) { + //Need to convert to proper date - later + delete editedWorkFlow.created; + delete editedWorkFlow.updated; + + delete editedWorkFlow.createdBy; + delete editedWorkFlow.modifiedBy; + + console.log('selected Item ' + JSON.stringify(editedWorkFlow)); + $scope.$emit('workflowAdded', editedWorkFlow); + + }, function () { + $log.info('Modal dismissed at: ' + new Date()); + }); + }; + + $scope.reset = function(){ + console.log("Resetting ...."); + }; + + $scope.update = function(){ + console.log("updating ...."); + }; + + $scope.createWorkflow = function (modalSize) { + + var modalInstance = $uibModal.open({ + animation: $scope.animationsEnabled, + templateUrl: 'app/fusion/scripts/view-models/workflows/workflow-new.html', + size : modalSize, + controller: ['$scope', '$uibModalInstance', '$http', function ($scope, $uibModalInstance, $http) { + $scope.workflow = {}; + $scope.workflow.active = 'true'; + $scope.ok = function() { + console.log('Saving new workflow ... ' + JSON.stringify($scope.workflow)); + $http.post('workflows/addWorkflow/', JSON.stringify($scope.workflow)).then(function(returnedWorkflow){ + console.log('Returned Workflow = ' + JSON.stringify(returnedWorkflow)); + $uibModalInstance.close($scope.workflow); + }); + }; +/* console.log(size);*/ + $scope.cancel = function() { + $uibModalInstance.dismiss(); + }; + }], + //End of inner controller + resolve: { + workflow: function() { + console.log('Passing ' + JSON.stringify($scope.workflow)); + return $scope.workflow; + } + } + }); + + modalInstance.result.then(function (newWorkflow) { + console.log('selected Item ' + JSON.stringify(newWorkflow)); + $scope.$emit('workflowAdded', newWorkflow); + + }, function () { + $log.info('Modal dismissed at: ' + new Date()); + }); + };//End of createWorkflow function + + + $scope.removeWorkflow = function(workflowToRemove){ + var modalInstance = $uibModal.open({ + animation: $scope.animationsEnabled, + templateUrl: 'app/fusion/scripts/view-models/workflows/workflow-remove.html', + controller: ['$scope', '$uibModalInstance', '$http', function ($scope, $uibModalInstance, $http) { + $scope.workflowToRemove = workflowToRemove; + $scope.ok = function() { + console.log('Removing workflow ... ' + JSON.stringify($scope.workflowToRemove) + ' on client request.'); + $http.post('workflows/removeWorkflow/', JSON.stringify($scope.workflowToRemove.id)).then(function(){ + console.log('Workflow successfully removed !!!'); + $uibModalInstance.close(); + }); + }; + + $scope.cancel = function() { + $uibModalInstance.dismiss(); + }; + }] + }); + + modalInstance.result.then(function () { + $scope.$emit('workflowRemoved'); + }, function () { + $log.info('Modal dismissed at: ' + new Date()); + }); + + }; + + + + $scope.scheduleWorkflow = function(workflowToSchedule){ + var modalInstance = $uibModal.open({ + animation: $scope.animationsEnabled, + templateUrl: 'app/fusion/scripts/view-models/workflows/workflow-schedule.html', + size:'lg', + + controller: ['$scope', '$uibModalInstance', '$http','dateFilter', function ($scope, $uibModalInstance, $http,dateFilter) { + + $scope.workflowToSchedule = workflowToSchedule; + $scope.dt = new Date(); + $scope.dt2 = new Date(); + $scope.dateformat = 'MM/dd/yyyy', + $scope.datetimeformat = "hh:mm a"; + + $scope.recurrenceOptions =[{ + index:0, value:'One-Time', title:'One-Time' + },{ + index:1, value: 'Hourly',title:'Hourly' + },{ + index:2, value: 'Daily',title:'Daily' + },{ + index:3, value: 'Weekly',title:'Weekly' + }] + $scope.selectRecurrenceOpt = $scope.recurrenceOptions[0]; + + $scope.hours = []; + for (var i=0; i<24; i++){ + var newObj={} + newObj.index = i; + newObj.value = ""+i; + newObj.title = ""+i; + $scope.hours.push(newObj); + } + + $scope.minutes = []; + for (var i=0; i<60; i++){ + var newObj={} + newObj.index = i; + newObj.value = ""+i; + newObj.title = ""+i; + $scope.minutes.push(newObj); + } + + $scope.AMPMOptions =[ + { + index:0, value:'AM', title:'AM' + },{ + index:1, value: 'PM',title:'PM' + }] + + $scope.selectFirstHour =$scope.hours[0]; + $scope.selectFirstMinute =$scope.minutes[0]; + + $scope.selectLastHour =$scope.hours[0]; + $scope.selectLastMinute =$scope.minutes[0]; + + $scope.selectStartAMPMOption=$scope.AMPMOptions[0]; + $scope.selectLastAMPMOption=$scope.AMPMOptions[0]; + + var GenerateCronExpression = function(trigger_dt, RecurrenceOpt) { + var CRON_sec = trigger_dt.getSeconds(); + var CRON_min = trigger_dt.getMinutes(); + var CRON_hr = trigger_dt.getHours(); + var CRON_date= trigger_dt.getDate(); + var CRON_month = trigger_dt.toLocaleString('en-US', {month: 'short'}).toUpperCase(); + var CRON_day = trigger_dt.toLocaleString('en-US', {weekday: 'short'}).toUpperCase(); + var CRON_year = trigger_dt.getFullYear(); + if (RecurrenceOpt ==="One-Time") { + CRON_day = '?' + } else { + if (RecurrenceOpt ==="Hourly") { + CRON_hr = '*'; + CRON_date = '*' + CRON_month = '*' + CRON_day = '?' + CRON_year = '*' + } else if (RecurrenceOpt ==="Daily") { + CRON_date = '*' + CRON_month = '*' + CRON_day = '?' + CRON_year = '*' + } else if (RecurrenceOpt ==="Weekly") { + CRON_date = '*' + CRON_month = '*' + CRON_year = '*' + } + } + + var CRON_Expression = [CRON_sec, CRON_min, CRON_hr, CRON_date, CRON_month, CRON_day, CRON_year]; + return CRON_Expression.join(" "); + } + + $scope.ok = function() { + + // DateTime for the start time: it should be noted that the start time + // for a CRON job should be prior to the trigger time. + $scope.trigger_dt = new Date( $scope.dt.getFullYear() + + "-" + ("0"+($scope.dt.getMonth()+1)).slice(-2) + + "-" +("0"+ $scope.dt.getDate()).slice(-2) + + " " + ("0" + $scope.selectFirstHour.value).slice(-2) + + ":" +("0" + $scope.selectFirstMinute.value).slice(-2) + + ":00.0"); + + $scope.startDateTime_CRON = GenerateCronExpression($scope.trigger_dt, $scope.selectRecurrenceOpt.value) + + //roll back the the start date time by 30 seconds (start time should be 30 seconds prior to trigger time) + dt_st = new Date($scope.trigger_dt - 30*1000) + + startDateTime = dt_st.getFullYear() + + "-" + ("0"+(dt_st.getMonth()+1)).slice(-2) + + "-" +("0"+ dt_st.getDate()).slice(-2) + + " " + ("0" + dt_st.getHours()).slice(-2) + + ":" +("0" + dt_st.getMinutes()).slice(-2) + + ":" + ("0" + dt_st.getSeconds()).slice(-2) +".0"; + $scope.startDateTime = startDateTime; + + $scope.endDateTime = $scope.dt2.getFullYear() + + "-" + ("0"+($scope.dt2.getMonth()+1)).slice(-2) + + "-" +("0"+ $scope.dt2.getDate()).slice(-2) + + " " + ("0"+ $scope.selectLastHour.value).slice(-2) + + ":" +("0" + $scope.selectLastMinute.value).slice(-2) + + ":00.0" + + $scope.WorkflowScheduleObject = {}; + $scope.WorkflowScheduleObject['startDateTime_CRON'] = $scope.startDateTime_CRON; + $scope.WorkflowScheduleObject['startDateTime'] = $scope.startDateTime; + $scope.WorkflowScheduleObject['endDateTime'] = $scope.endDateTime; + $scope.WorkflowScheduleObject['workflowKey'] = $scope.workflowToSchedule.workflowKey; + $scope.WorkflowScheduleObject['recurrence'] = $scope.selectRecurrenceOpt.value; + $scope.WorkflowScheduleObject['workflow_arguments'] = "test"; + $scope.WorkflowScheduleObject['workflow_server_url'] = $scope.workflowToSchedule.runLink; + + + TimeFromNowToStart = new Date($scope.startDateTime)-new Date() + TimeStartToEnd = new Date($scope.endDateTime)-new Date($scope.startDateTime) + + if (TimeFromNowToStart<=0) { + console.log("invalid start time input") + alert("Please ensure the scheduled start date time is later than current time.") + return; + } + if (TimeStartToEnd<=0) { + console.log("invalid end time input") + alert("Please ensure the schduled end date time is later than the start time.") + return; + } + // if successful then save and close + $scope.saveCronJob($scope.WorkflowScheduleObject); + $uibModalInstance.close(); + + }; + + $scope.saveCronJob = function(cronJobData){ + + console.log('saving cron job data: ' + cronJobData); + var uuu = "workflows/saveCronJob.htm"; + var postData={cronJobDataObj: cronJobData}; + $.ajax({ + type : 'POST', + url : uuu, + //dataType: 'json', // data type expected from server + contentType: 'application/json', + data: JSON.stringify(postData), // data type sent to server + success : function(data){ + $scope.$apply(function(){ + //$scope.availableRoleFunctions=[];$scope.$apply(); + // new // $scope.availableFnMenuItems=data.availableFnMenuItems; + } + ); + //alert("Update Successful.") ; + //$scope.editRoleFunction = null; + // new /// $modalInstance.close({availableFnMenuItems:$scope.availableRoleFunctions}); + }, + error : function(data){ + alert("Error while saving."); + } + }); + + }; + + $scope.cancel = function() { + console.log("cancel triggered") + $uibModalInstance.dismiss(); + }; + }] + }); + + modalInstance.result.then(function () { + $scope.$emit('workflowRemoved'); + }, function () { + $log.info('Modal dismissed at: ' + new Date()); + }); + + }; + + + + + + + + + $scope.previewWorkflow = function(workflowToPreview,modalSize){ + var modalInstance = $uibModal.open({ + animation: $scope.animationsEnabled, + templateUrl: 'app/fusion/scripts/view-models/workflows/workflow-preview.html', + size:modalSize, + controller: ['$scope', '$uibModalInstance', '$http', function ($scope, $uibModalInstance, $http) { + $scope.workflowToPreview = workflowToPreview; + console.log('previewWorkFlow invoked'); + console.log($scope.workflowToPreview); + + $scope.cancel = function() { + $uibModalInstance.dismiss(); + }; + }] + }); + + modalInstance.result.then(function () { + $scope.$emit('workflowRemoved'); + }, function () { + $log.info('Modal dismissed at: ' + new Date()); + }); + + }; + + + /* change work flow status based on the boolean variable "suspendBool" which corresponds whether + * we would like to suspend or activate a workflow specified by key. */ + $scope.changeWorkflowStatus = function(workflowToChangeStatus,suspendBool){ + if (workflowToChangeStatus!==null) { + var statusUrl= workflowToChangeStatus.runLink+"/engine-rest/process-definition/key/"+workflowToChangeStatus.workflowKey + var suspendedUrl= statusUrl+"/suspended" + var xmlHttp = new XMLHttpRequest(); + xmlHttp.open('PUT', suspendedUrl, false); + xmlHttp.setRequestHeader('Content-Type', 'application/json;charset=UTF-8'); + xmlHttp.onload = function() { + if (suspendBool) { + console.log("process definition is now suspended"); + workflowToChangeStatus.active="false" + } else { + console.log("process definition is now activated"); + workflowToChangeStatus.active="true" + } + }; + xmlHttp.send(JSON.stringify({ + "suspended" : suspendBool, + "includeProcessInstances" : true, + "executionDate" : "2013-11-21T10:49:45" + })); + } + + }; + + $scope.activateWorkflow = function(workflowToActivate){ + $scope.changeWorkflowStatus(workflowToActivate,false) + + }; + + $scope.suspendWorkflow = function(workflowToActivate){ + $scope.changeWorkflowStatus(workflowToActivate,true) + }; + + $scope.checkWorkflowStatus = function(workflow) { + if (workflow!==null) { + var statusUrl= workflow.runLink+"/engine-rest/process-definition/key/"+workflow.workflowKey + var xmlHttp3 = new XMLHttpRequest(); + xmlHttp3.open('GET', statusUrl, true); + xmlHttp3.withCredentials = true; + xmlHttp3.send(); + xmlHttp3.onreadystatechange = function() { + if (xmlHttp3.readyState == 4 && xmlHttp3.status == 200) { + // do something with the response in the variable data + var temp = JSON.parse(xmlHttp3.responseText) + if (temp.suspended == false){ + console.log("Activated") + workflow.active="true" + } else { + console.log("Suspended") + workflow.active="false" + } + } + } + } + }; + + $scope.StartWorkflowInstance = function(workflowToStart){ + if (workflowToStart!==null) { + var statusUrl= workflowToStart.runLink+"/engine-rest/process-definition/key/"+workflowToStart.workflowKey + var suspendedUrl= statusUrl+"/submit-form" + var xmlHttp = new XMLHttpRequest(); + xmlHttp.open('POST', suspendedUrl, false); + xmlHttp.setRequestHeader('Content-Type', 'application/json;charset=UTF-8'); + xmlHttp.onload = function() { + }; + xmlHttp.send(JSON.stringify({ + "variables": { + "customerId": {"value":"asdasda","type":"String"}, + "amount":{"value":"100","type":"String"} + } + })); + } + + }; + + + $scope.$on('workflowAdded', function(event, newWorkflow) { + console.log("New Workflow to be added in list scope " + JSON.stringify(newWorkflow)); + //$scope.workflows.push(newWorkflow); + $scope.fetchWorkflowsList(); + console.log('newly added workflow = ' + JSON.stringify(newWorkflow)); + }); + + $scope.$on('workflowRemoved', function(event) { + $scope.fetchWorkflowsList(); + }); + + $scope.fetchWorkflowsList(); + + + +}); + diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/workflows/workflowRouting.js b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/workflows/workflowRouting.js new file mode 100644 index 000000000..81fe4e283 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/controllers/workflows/workflowRouting.js @@ -0,0 +1,26 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +app.config(function($routeProvider) { + $routeProvider + .when('/all', { + templateUrl: 'app/fusion/scripts/view-models/workflows/workflow-listing.html', + controller: 'workflowsController' + }) +}); diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/directives/dummy.txt b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/directives/dummy.txt new file mode 100644 index 000000000..e69de29bb diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/directives/footer.js b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/directives/footer.js new file mode 100644 index 000000000..a2dab75c2 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/directives/footer.js @@ -0,0 +1,30 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +app.directive('qFooter', function () { + return { + restrict: 'A', //This menas that it will be used as an attribute and NOT as an element. I don't like creating custom HTML elements + replace: false, + templateUrl: "app/fusion/scripts/view-models/footer.html", + controller: ['$scope', '$filter', function ($scope, $filter) { + // Your behaviour goes here :) + }] + } +}); + diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/directives/header.js b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/directives/header.js new file mode 100644 index 000000000..bc90d2005 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/directives/header.js @@ -0,0 +1,504 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +app.directive('qHeader', function () { + return { + restrict: 'A', //This menas that it will be used as an attribute and NOT as an element. I don't like creating custom HTML elements + replace: false, + templateUrl: "app/fusion/scripts/view-models/header.html", + controller: ['$scope', '$filter','$http','$timeout', '$log','UserInfoService', '$window', '$cookies', function ($scope, $filter, $http, $timeout, $log,UserInfoService, $window, $cookies) { + + /*Define fields*/ + $scope.userName; + $scope.userFirstName; + $scope.redirectUrl; + $scope.contactUsUrl; + $scope.getAccessUrl; + $scope.childData=[]; + $scope.parentData=[]; + $scope.menuItems = []; + $scope.loadMenufail=false; + $scope.megaMenuDataObject=[]; + $scope.activeClickSubMenu = { + x: '' + }; + $scope.activeClickMenu = { + x: '' + }; + $scope.favoritesMenuItems = []; + $scope.favoriteItemsCount = 0; + $scope.showFavorites = false; + $scope.emptyFavorites = false; + $scope.favoritesWindow = false; + + /*Menu Structure*/ + var menuStructureConvert = function(menuItems) { + console.log(menuItems); + $scope.megaMenuDataObjectTemp = + [ + { + text: "ECOMP", + children: menuItems + }, + { + text: "Help", + children: [ + { + text:"Contact Us", + url:$scope.contactUsUrl + }, + { + text:"Get Access", + url:$scope.getAccessUrl + }] + } + ]; + return $scope.megaMenuDataObjectTemp; + }; + + /***************functions**************/ + /*Put user info into fields*/ + $scope.inputUserInfo = function(userInfo){ + if (typeof(userInfo) != "undefined" && userInfo!=null && userInfo!=''){ + if(typeof(userInfo.USER_FIRST_NAME) != "undefined" && userInfo.USER_FIRST_NAME!=null){ + $scope.userFirstName = userInfo.USER_FIRST_NAME; + } + } + } + /*getting user info from session*/ + $scope.getUserNameFromSession = function(){ + UserInfoService.getFunctionalMenuStaticDetailSession() + .then(function (res) { + $scope.contactUsUrl=res.contactUsLink; + $scope.userName = res.userName; + $scope.userFirstName = res.firstName; + $scope.redirectUrl = res.portalUrl; + $scope.getAccessUrl = res.getAccessUrl; + }); + } + $scope.getTopMenuStaticInfo=function() { + var promise = UserInfoService.getFunctionalMenuStaticDetailShareContext(); + promise.then( + function(res) { + if(res==null || res==''){ + $log.info('failed getting static User information'); + $scope.getUserNameFromSession(); + }else{ + $log.info('Received static User information'); + + var resData = res; + console.log(resData); + $scope.inputUserInfo(resData); + $scope.userName = $scope.firstName+ ' '+ $scope.lastName; + } + }, + function(err) { + $log.info('failed getting static User information'); + } + ); + } + + $scope.returnToPortal=function(){ + window.location.href = $scope.redirectUrl; + } + + var unflatten = function( array, parent, tree ){ + tree = typeof tree !== 'undefined' ? tree : []; + parent = typeof parent !== 'undefined' ? parent : { menuId: null }; + var children = _.filter( array, function(child){ return child.parentMenuId == parent.menuId; }); + if( !_.isEmpty( children ) ){ + if( parent.menuId === null ){ + tree = children; + }else{ + parent['children'] = children + } + _.each( children, function( child ){ unflatten( array, child ) } ); + } + return tree; + } + + $scope.getMenu=function() { + $scope.getTopMenuStaticInfo(); + $http({ + method: "GET", + url: 'get_functional_menu', +// TIMEOUT USED FOR LOCAL TESTING ONLY +// timeout: 100 + }).success(function (response) { + + if (response == '101: Timeout') { + $log.debug('Timeout attempting to get_functional_menu'); + $scope.megaMenuDataObject = menuStructureConvert(""); +// $scope.createErrorMenu(); + //$scope.loadMenufail=true; + } else { + if(typeof response != 'undefined' && response.length!=0 && typeof response[0] != 'undefined' && typeof response[0].error!="undefined"){ + $log.debug('Timeout attempting to get_functional_menu'); + $scope.menuItems = unflatten( response); + $scope.megaMenuDataObject = menuStructureConvert($scope.menuItems); +// $scope.createErrorMenu(); + //$scope.loadMenufail=true; + }else{ + $scope.loadMenufail=false; + $scope.contactUsURL = response.contactUsLink; + $log.debug('functional_menu',response); + $scope.megaMenuDataObject = menuStructureConvert(""); + } + } + }).error(function (response){ + $scope.megaMenuDataObject = menuStructureConvert(""); +// $scope.createErrorMenu(); + //$scope.loadMenufail=true; + $log.debug('REST API failed get_functional_menu...'); + }); + + } + + $scope.adjustHeader=function() { + $scope.showHeader = ($cookies.show_app_header == undefined ? true : $cookies.show_app_header); + + if($scope.showHeader == true) { + $scope.drawer_margin_top = 70; + $scope.drawer_custom_top = 54; + $scope.toggle_drawer_top = 55; + } + else { + + $scope.drawer_margin_top = 60; + $scope.drawer_custom_top = 0; + $scope.toggle_drawer_top = 10; + } + + } + + $scope.getMenu(); + $scope.adjustHeader(); + +/* **************************************************************************/ +/* Logic for the favorite menus is here */ + + $scope.loadFavorites = function () { + $log.debug('loadFavorites has happened.'); + if ($scope.favoritesMenuItems == '') { + $scope.generateFavoriteItems(); + $log.debug('loadFavorites is calling generateFavoriteItems()'); + } else { + $log.debug('loadFavorites is NOT calling generateFavoriteItems()'); + } + } + + $scope.goToUrl = function (item) { + $log.info("goToUrl called") + $log.info(item); + + var url = item.url; + var restrictedApp = item.restrictedApp; + $log.debug('Restricted app status is: ' + restrictedApp); + if (!url) { + $log.info('No url found for this application, doing nothing..'); + return; + } + if (restrictedApp) { + $window.open(url, '_blank'); + } else { + $window.open(url, '_self'); + } + + } + + $scope.submenuLevelAction = function(index, column) { + if ($scope.favoritesMenuItems == '') { + $scope.generateFavoriteItems(); + $log.debug('submenuLevelAction is calling generateFavoriteItems()'); + } + $log.debug('item hovered/clicked: ' + index + '; column = ' + column); + if (column == 2) { // 2 is Design + $scope.favoritesWindow = false; + $scope.showFavorites = false; + $scope.emptyFavorites = false; + } + if (index=='Favorites' && $scope.favoriteItemsCount != 0) { + $log.debug('Showing Favorites window'); + $scope.favoritesWindow = true; + $scope.showFavorites = true; + $scope.emptyFavorites = false; + } + if (index=='Favorites' && $scope.favoriteItemsCount == 0) { + $log.debug('Hiding Favorites window in favor of No Favorites Window'); + $scope.favoritesWindow = true; + $scope.showFavorites = false; + $scope.emptyFavorites = true; + } + if (column > 2) { + $scope.favoritesWindow = false; + $scope.showFavorites = false; + $scope.emptyFavorites = false; + } + }; + + $scope.hideFavoritesWindow = function() { + $log.debug('$scope.hideFavoritesWindow has been called'); + $scope.showFavorites = false; + $scope.emptyFavorites = false; + } + + $scope.isUrlFavorite = function (menuId) { +// $log.debug('array objects in menu favorites = ' + $scope.favoriteItemsCount + '; menuId=' + menuId); + var jsonMenu = JSON.stringify($scope.favoritesMenuItems); + var isMenuFavorite = jsonMenu.indexOf('menuId\":' + menuId); + if (isMenuFavorite==-1) { + return false; + } else { + return true; + } + + } + + $scope.generateFavoriteItems = function() { + $http({ + method: "GET", + url: 'get_favorites', +// TIMEOUT USED FOR LOCAL TESTING ONLY +// timeout: 100 + }).success(function (response) { + if (response == '101: Timeout') { + $log.error('Timeout attempting to get_favorites_menu'); + } else { + if(typeof response != 'undefined' && response.length!=0 && typeof response[0] != 'undefined' && typeof response[0].error!="undefined"){ + $log.error('REST API failed get_favorites' + response); + }else{ + $log.debug('get_favorites = ' + JSON.stringify(response)); + $scope.favoritesMenuItems = response; + $scope.favoriteItemsCount = Object.keys($scope.favoritesMenuItems).length; + $log.info('number of favorite menus: ' + $scope.favoriteItemsCount); + } + } + }).error(function (response){ + $log.error('REST API failed get_favorites' + response); +//createFavoriteErrorMenu() USED FOR LOCAL TESTING ONLY +// $scope.createFavoriteErrorMenu(); + }); + } + + $scope.createFavoriteErrorMenu=function() { + $scope.favoritesMenuItems = []; + $scope.favoriteItemsCount = Object.keys($scope.favoritesMenuItems).length; + $log.info('number of favorite menus: ' + $scope.favoriteItemsCount); + } + + /* end of Favorite Menu code */ + /* **************************************************************************/ + + + /* **************************************************************************/ + // THIS IS USED FOR LOCAL TESTING ONLY + /* **************************************************************************/ + $scope.createErrorMenu=function() { + $log.debug('Creating fake menu now...'); +// $scope.loadMenufail=true; + $scope.menuItems = [ + { + "menuId": 1, + "column": 2, + "text": "Design", + "parentMenuId": null, + "url": "" + }, + { + "menuId": 2, + "column": 3, + "text": "Infrastructure Ordering", + "parentMenuId": null, + "url": "" + }, + { + "menuId": 3, + "column": 4, + "text": "Service Creation", + "parentMenuId": null, + "url": "" + }, + { + "menuId": 4, + "column": 5, + "text": "Service Mgmt", + "parentMenuId": null, + "url": "" + }, + { + "menuId": 90, + "column": 1, + "text": "Google", + "parentMenuId": 1, + "url": "" + }, + { + "menuId": 91, + "column": 1, + "text": "Mike Little's Coffee Cup", + "parentMenuId": 2, + "url": "" + }, + { + "menuId": 92, + "column": 2, + "text": "Andy and his Astrophotgraphy", + "parentMenuId": 3, + "url": "" + }, + { + "menuId": 93, + "column": 1, + "text": "JSONLint", + "parentMenuId": 4, + "url": "" + }, + { + "menuId": 94, + "column": 2, + "text": "HROneStop", + "parentMenuId": 4, + "url": "" + }, + { + "menuId": 95, + "column": 2, + "text": "4th Level App4a R16", + "parentMenuId": 4, + "url": "" + }, + { + "menuId": 96, + "column": 3, + "text": "3rd Level App1c R200", + "parentMenuId": 4, + "url": "" + }, + { + "menuId": 97, + "column": 1, + "text": "3rd Level App4b R16", + "parentMenuId": 5, + "url": "" + }, + { + "menuId": 98, + "column": 2, + "text": "3rd Level App2b R16", + "parentMenuId": 5, + "url": "" + }, + { + "menuId": 99, + "column": 1, + "text": "Favorites", + "parentMenuId": null, + "url": "" + } + ]; + $scope.menuItems = unflatten( $scope.menuItems ); + //remove this + $scope.megaMenuDataObject = menuStructureConvert($scope.menuItems); + } + }] + } +}); + +app.filter("ellipsis", function(){ + return function(text, length){ + if (text) { + var ellipsis = text.length > length ? "..." : ""; + return text.slice(0, length) + ellipsis; + }; + return text; + } +}); + +function reloadPageOnce() { + if( window.localStorage ) + { + if( !localStorage.getItem('firstLoad') ) + { + localStorage['firstLoad'] = true; + window.location.reload(); + } + else + localStorage.removeItem('firstLoad'); + } +} +app.controller('loginSnippetCtrl', function ($scope,$http, $log,UserInfoService){ + /*Define fields*/ + $scope.userProfile={ + firstName:'', + lastName:'', + fullName:'', + email:'', + userid:'' + } + /*Put user info into fields*/ + $scope.inputUserInfo = function(userInfo){ + if (typeof(userInfo) != "undefined" && userInfo!=null && userInfo!=''){ + if (typeof(userInfo.USER_FIRST_NAME) != "undefined" && userInfo.USER_FIRST_NAME!=null && userInfo.USER_FIRST_NAME!='') + $scope.userProfile.firstName = userInfo.USER_FIRST_NAME; + if (typeof(userInfo.USER_LAST_NAME) != "undefined" && userInfo.USER_LAST_NAME!=null && userInfo.USER_LAST_NAME!='') + $scope.userProfile.lastName = userInfo.USER_LAST_NAME; + if (typeof(userInfo.USER_EMAIL) != "undefined" && userInfo.USER_EMAIL!=null && userInfo.USER_EMAIL!='') + $scope.userProfile.email = userInfo.USER_EMAIL; + if (typeof(userInfo.USER_ORGUSERID) != "undefined" && userInfo.USER_ORGUSERID!=null && userInfo.USER_ORGUSERID!='') + $scope.userProfile.userid = userInfo.USER_ORGUSERID; + } + } + /*getting user info from session*/ + $scope.getUserNameFromSession = function(){ + UserInfoService.getFunctionalMenuStaticDetailSession() + .then(function (response) { + $scope.userProfile.fullName = response.userName; + $scope.userProfile.userid = response.userid; + $scope.userProfile.email = response.email; + }); + } + /*getting user info from shared context*/ + $scope.getUserName=function() { + var promise = UserInfoService.getFunctionalMenuStaticDetailShareContext(); + promise.then( + function(res) { + if(res==null || res==''){ + $log.info('Getting User information from session'); + $scope.getUserNameFromSession(); + + }else{ + $log.info('Received User information from shared context',res); + var resData = res; + console.log(resData); + $scope.inputUserInfo(resData); + $scope.userProfile.fullName = $scope.userProfile.firstName+ ' '+ $scope.userProfile.lastName; + } + }, + function(err) { + console.log('error'); + } + ); + }; + /*call the get user info function*/ + try{ + $scope.getUserName(); + }catch(err){ + $log.info('Error while getting User information',err); + } +}); diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/directives/leftMenu.js b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/directives/leftMenu.js new file mode 100644 index 000000000..737cb8012 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/directives/leftMenu.js @@ -0,0 +1,203 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ + +app.directive('qMenu', function () { + return { + restrict: 'A', //This menas that it will be used as an attribute and NOT as an element. I don't like creating custom HTML elements + replace: false, + templateUrl: "app/fusion/scripts/view-models/left_menu.html", + controller: ['$scope', '$filter','$http','$timeout','$cookies','LeftMenuService', function ($scope, $filter, $http,$timeout,$cookies,LeftMenuService) { + + $scope.leftChildData=[]; + $scope.leftParentData=[]; + $scope.leftMenuItems = []; + $scope.app_name = ""; + $scope.app_name_full; + LeftMenuService.getLeftMenu().then(function(response){ + var j = response; + try{ + if(j && j !== "null" && j!== "undefined"){ + $scope.leftParentData = JSON.parse(j.data); + $scope.leftChildData = JSON.parse(j.data2); + }else{ + throw "Get Left Menu respsone is not an object/is empty"; + } + try{ + var leftChildItemList = $scope.leftChildData; + var pageUrl = window.location.href.split('/')[window.location.href.split('/').length-1]; + var leftParentList =$scope.leftParentData; + for (var i = 0; i < leftParentList.length; i++) { + $scope.item = { + parentLabel : leftParentList[i].label, + parentAction : leftParentList[i].action, + parentImageSrc : leftParentList[i].imageSrc, + open:pageUrl==leftParentList[i].action?true:false, + childItemList : leftChildItemList[i] + } + $scope.leftMenuItems.push($scope.item); + }; + }catch(err){ + console.log("error happened while trying to set left menu structure"+err); + } + }catch (e) { + console.log("error happened while trying to get left menu items"+e); + reloadPageOnce(); + return; + } + },function(error){ + console.log("error happened while calling getLeftMenu"+error); + }); + + LeftMenuService.getAppName().then(function(response){ + var j = response; + try{ + if(j && j !== "null" && j!== "undefined"){ + console.log("app name is " + $scope.app_name); + $scope.app_name_full = j.data; + var processed_app_name = j.data; + var n = processed_app_name.length; + if (n > 15) { + n = 15; + } + $scope.app_name = processed_app_name.substr(0, n); + }else{ + throw "Get app_name respsone is not an object/is empty"; + } + }catch (e) { + console.log("error happened while trying to get app name "+e); + return; + } + },function(error){ + console.log("error happened while calling getAppName "+error); + }); + + $scope.adjustHeader=function() { + $scope.showHeader = ($cookies.show_app_header == undefined ? true : $cookies.show_app_header); + + if($scope.showHeader == true) { + $scope.drawer_margin_top = 50; + $scope.drawer_custom_top = 20; + $scope.toggle_drawer_top = 55; + } + else { + + $scope.drawer_margin_top = 0; + $scope.drawer_custom_top = 0; + $scope.toggle_drawer_top = 0; + } + + + }; + + $scope.adjustHLeftMenu = function (type){ + $scope.showHeader = ($cookies.show_app_header == undefined ? true : $cookies.show_app_header); + + if($scope.showHeader == true) { + $scope.drawer_margin_top = 60; + $scope.drawer_custom_top = 54; + $scope.toggle_drawer_top = 55; + } + else { + + $scope.drawer_margin_top = 50; + $scope.drawer_custom_top = 0; + $scope.toggle_drawer_top = 10; + } + if(type=='burgerIcon'){ + return { "top": $scope.toggle_drawer_top+"px"}; + }else if(type=='leftMenu'){ + return { "margin-top": $scope.drawer_margin_top+"px"}; + }else + return; + } + $scope.adjustHeader(); + $scope.drawerOpen = true; + + $scope.toggleDrawer = function() { + $scope.drawerOpen = !($scope.drawerOpen); + if ($scope.drawerOpen) { + // setCookie('drawerOpen','open',30); + $scope.arrowShow = true; + + + if (document.getElementById('fnMenueContent')!=null) + document.getElementById('fnMenueContent').style.marginLeft = "0px"; + + if (document.getElementById('rightContentAdmin')!=null) + document.getElementById('rightContentAdmin').style.marginLeft = "210px"; + + else if (document.getElementById('rightContentProfile')!=null) + document.getElementById('rightContentProfile').style.marginLeft = "210px"; + + + + } else { + + $scope.arrowShow = false; + + if (document.getElementById('fnMenueContent')!=null) + document.getElementById('fnMenueContent').style.marginLeft = "-150px"; + + if (document.getElementById('rightContentAdmin')!=null) { + document.getElementById('rightContentAdmin').style.marginLeft = "50px"; + + } + + else if (document.getElementById('rightContentProfile')!=null) + document.getElementById('rightContentProfile').style.marginLeft = "50px"; + + + + + } + }; + + $timeout(function() { + detectScrollEvent(); + }, 800); + }] + } + +}); +$(window).scroll(function() { + if ($('.att-drawer').is(':visible')) { + detectScrollEvent(); + } + +}); + +function detectScrollEvent() { + try{ + var footerOff = $('#footerContainer').offset().top; + var headOff = $('#headerContainer').offset().top; + var winHeight = $(window).height(); + if ((footerOff - headOff) <= winHeight) { + $('.att-drawer').css({ + "height" : footerOff - headOff - 55 + }); + } else { + $('.att-drawer').css({ + "height" : "94vh" + }); + } + }catch(err){ + console.log(err) + } +} diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/jquery.resize.js b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/jquery.resize.js new file mode 100644 index 000000000..1ebd6c95b --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/jquery.resize.js @@ -0,0 +1,139 @@ +/*! + * jquery.resize.js 0.0.1 - https://github.com/yckart/jquery.resize.js + * Resize-event for DOM-Nodes + * + * @see http://workingdraft.de/113/ + * @see http://www.backalleycoder.com/2013/03/18/cross-browser-event-based-element-resize-detection/ + * + * Copyright (c) 2013 Yannick Albert (http://yckart.com) + * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php). + * 2013/04/01 + */ + +(function(factory) { + if(typeof define === 'function' && define.amd) { + // AMD. Register as an anonymous module. + define(['jquery'], factory); + } else if(typeof exports === 'object') { + // Node/CommonJS style for Browserify + module.exports = factory; + } else { + // Browser globals + factory(jQuery); + } +}(function($) { + + function addFlowListener(element, type, fn) { + var flow = type == 'over'; + element.addEventListener('OverflowEvent' in window ? 'overflowchanged' : type + 'flow', function(e) { + if(e.type == (type + 'flow') || ((e.orient == 0 && e.horizontalOverflow == flow) || (e.orient == 1 && e.verticalOverflow == flow) || (e.orient == 2 && e.horizontalOverflow == flow && e.verticalOverflow == flow))) { + e.flow = type; + return fn.call(this, e); + } + }, false); + }; + + function fireEvent(element, type, data, options) { + var options = options || {}, + event = document.createEvent('Event'); + event.initEvent(type, 'bubbles' in options ? options.bubbles : true, 'cancelable' in options ? options.cancelable : true); + for(var z in data) event[z] = data[z]; + element.dispatchEvent(event); + }; + + $.event.special.resize = { + setup: function() { + var element = this; + var resize = 'onresize' in element; + if(!resize && !element._resizeSensor) { + var sensor = element._resizeSensor = document.createElement('div'); + sensor.className = 'resize-sensor'; + sensor.innerHTML = '
    '; + + var x = 0, + y = 0, + first = sensor.firstElementChild.firstChild, + last = sensor.lastElementChild.firstChild, + matchFlow = function(event) { + var change = false, + width = element.offsetWidth; + if(x != width) { + first.style.width = width - 1 + 'px'; + last.style.width = width + 1 + 'px'; + change = true; + x = width; + } + var height = element.offsetHeight; + if(y != height) { + first.style.height = height - 1 + 'px'; + last.style.height = height + 1 + 'px'; + change = true; + y = height; + } + if(change && event.currentTarget != element) fireEvent(element, 'resize'); + }; + + if(getComputedStyle(element).position == 'static') { + element.style.position = 'relative'; + element._resizeSensor._resetPosition = true; + } + addFlowListener(sensor, 'over', matchFlow); + addFlowListener(sensor, 'under', matchFlow); + addFlowListener(sensor.firstElementChild, 'over', matchFlow); + addFlowListener(sensor.lastElementChild, 'under', matchFlow); + element.appendChild(sensor); + matchFlow({}); + } + var events = element._flowEvents || (element._flowEvents = []); + if(events.indexOf(handler) == -1) events.push(handler); + if(!resize) element.addEventListener('resize', handler, false); + element.onresize = function(e) { + events.forEach(function(fn) { + fn.call(element, e); + }); + }; + }, + + teardown: function() { + var element = this; + var index = element._flowEvents.indexOf(handler); + if(index > -1) element._flowEvents.splice(index, 1); + if(!element._flowEvents.length) { + var sensor = element._resizeSensor; + if(sensor) { + element.removeChild(sensor); + if(sensor._resetPosition) element.style.position = 'static'; + delete element._resizeSensor; + } + if('onresize' in element) element.onresize = null; + delete element._flowEvents; + } + element.removeEventListener('resize', handler); + } + }; + + $.fn.extend({ + resize: function(fn) { + return fn ? this.bind("resize", fn) : this.trigger("resize"); + }, + + unresize: function(fn) { + return this.unbind("resize", fn); + } + }); + + + function handler(event) { + var orgEvent = event || window.event, + args = [].slice.call(arguments, 1); + + event = $.event.fix(orgEvent); + event.type = "resize"; + + // Add event to the front of the arguments + args.unshift(event); + + return($.event.dispatch || $.event.handle).apply(this, args); + } + +})); \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/layout/debug.js b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/layout/debug.js new file mode 100644 index 000000000..eff36a250 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/layout/debug.js @@ -0,0 +1,329 @@ +/** + * debugData + * + * Pass me a data structure {} and I'll output all the key/value pairs - recursively + * + * @example var HTML = debugData( oElem.style, "Element.style", { keys: "top,left,width,height", recurse: true, sort: true, display: true, returnHTML: true }); + * + * @param Object o_Data A JSON-style data structure + * @param String s_Title Title for dialog (optional) + * @param Hash options Pass additional options in a hash + */ +function debugData (o_Data, s_Title, options) { + options = options || {}; + var + str=(s_Title||s_Title==='' ? s_Title : 'DATA') + , dType=$.type(o_Data) + // maintain backward compatibility with OLD 'recurseData' param + , recurse=($.type(options)==='boolean' ? options : options.recurse !==false) + , keys=(options.keys?','+options.keys+',':false) + , display=options.display !==false + , html=options.returnHTML !==false + , sort=!!options.sort + , prefix=options.indent ? ' ' : '' + , D=[], i=0 // Array to hold data, i=counter + , hasSubKeys = false + , k, t, skip, x, type // loop vars + ; + if (dType!=='object' && dType!=='array') { + if (options.display) alert( (s_Title || 'debugData') +': '+ o_Data ); + return o_Data; + } + if (dType==='object' && $.isPlainObject(o_Data)) + dType='hash'; + + if (o_Data.jquery) { + str=s_Title+'jQuery Collection ('+ o_Data.length +')\n context="'+ o_Data.context +'"'; + } + else if (o_Data.nodeName) { + str=s_Title+o_Data.tagName; + var id = o_Data.id, cls=o_Data.className, src=o_Data.src, hrf=o_Data.href; + if (id) str+='\n id="'+ id+'"'; + if (cls) str+='\n class="'+ cls+'"'; + if (src) str+='\n src="'+ src+'"'; + if (hrf) str+='\n href="'+ hrf+'"'; + } + else { + parse(o_Data,prefix,dType); // recursive parsing + if (sort && !hasSubKeys) D.sort(); // sort by keyName - but NOT if has subKeys! + if (str) str += '\n***'+ '****************************'.substr(0,str.length) +'\n'; + str += D.join('\n'); // add line-breaks + } + + if (display) alert(str); // display data + if (html) str=str.replace(/\n/g, '
    ').replace(/ /g, '  '); // format as HTML + return str; + + function parse ( data, prefix, parentType ) { + var first = true; + try { + $.each( data, function (key, val) { + skip = (keys && keys.indexOf(','+key+',') === -1); + type = $.type(val); + if (type==='object' && $.isPlainObject(val)) + type = 'hash'; + k = prefix + (first ? ' ' : ', '); + first = false; + + if (parentType!=='array') // no key-names for array items + k += key+': '; // NOT an array + + if (type==="date" || type==="regexp") { + val = val.toString(); + type = "string"; + } + if (type==="string") { // STRING + if (!skip) D[i++] = k +'"'+ val +'"'; + } + // NULL, UNDEFINED, NUMBER or BOOLEAN + else if (/^(null|undefined|number|boolean)/.test(type)) { + if (!skip) D[i++] = k + val; + } + else if (type==="function") { // FUNCTION + if (!skip) D[i++] = k +'function()'; + } + else if (type==="array") { // ARRAY + if (!skip) { + D[i++] = k +'['; + parse( val, prefix+' ',type); // RECURSE + D[i++] = prefix +' ]'; + } + } + else if (val.jquery) { // JQUERY OBJECT + if (!skip) D[i++] = k +'jQuery ('+ val.length +') context="'+ val.context +'"'; + } + else if (val.nodeName) { // DOM ELEMENT + var id = val.id, cls=val.className, src=val.src, hrf=val.href; + if (skip) D[i++] = k +' '+ + id ? 'id="'+ id+'"' : + src ? 'src="'+ src+'"' : + hrf ? 'href="'+ hrf+'"' : + cls ? 'class="'+cls+'"' : + ''; + } + else if (type==="hash") { // JSON + if (!recurse || $.isEmptyObject(val)) { // show an empty hash + if (!skip) D[i++] = k +'{ }'; + } + else { // recurse into JSON hash - indent output + D[i++] = k +'{'; + parse( val, prefix+' ',type); // RECURSE + D[i++] = prefix +' }'; + } + } + else { // OBJECT + if (!skip) D[i++] = k +'OBJECT'; // NOT a hash + } + }); + } catch (e) {} + } +}; + +function debugStackTrace (s_Title, options) { + var + callstack = [] + , isCallstackPopulated = false + ; + try { + i.dont.exist += 0; // doesn't exist- that's the point + } catch(e) { + if (e.stack) { // Firefox + var lines = e.stack.split('\n'); + for (var i=0, len=lines.length; i') + .html( content.replace(/\n/g, '
    ').replace(/ /g, '  ') ) // format as HTML + .css( options.css ) + ; +}; diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/layout/jquery-latest.js b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/layout/jquery-latest.js new file mode 100644 index 000000000..1c998babc --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/layout/jquery-latest.js @@ -0,0 +1,9555 @@ +/*! + * jQuery JavaScript Library v1.9.0 + * http://jquery.com/ + * + * Includes Sizzle.js + * http://sizzlejs.com/ + * + * Copyright 2005, 2012 jQuery Foundation, Inc. and other contributors + * Released under the MIT license + * http://jquery.org/license + * + * Date: 2013-1-14 + */ +(function( window, undefined ) { +"use strict"; +var + // A central reference to the root jQuery(document) + rootjQuery, + + // The deferred used on DOM ready + readyList, + + // Use the correct document accordingly with window argument (sandbox) + document = window.document, + location = window.location, + + // Map over jQuery in case of overwrite + _jQuery = window.jQuery, + + // Map over the $ in case of overwrite + _$ = window.$, + + // [[Class]] -> type pairs + class2type = {}, + + // List of deleted data cache ids, so we can reuse them + core_deletedIds = [], + + core_version = "1.9.0", + + // Save a reference to some core methods + core_concat = core_deletedIds.concat, + core_push = core_deletedIds.push, + core_slice = core_deletedIds.slice, + core_indexOf = core_deletedIds.indexOf, + core_toString = class2type.toString, + core_hasOwn = class2type.hasOwnProperty, + core_trim = core_version.trim, + + // Define a local copy of jQuery + jQuery = function( selector, context ) { + // The jQuery object is actually just the init constructor 'enhanced' + return new jQuery.fn.init( selector, context, rootjQuery ); + }, + + // Used for matching numbers + core_pnum = /[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/.source, + + // Used for splitting on whitespace + core_rnotwhite = /\S+/g, + + // Make sure we trim BOM and NBSP (here's looking at you, Safari 5.0 and IE) + rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, + + // A simple way to check for HTML strings + // Prioritize #id over to avoid XSS via location.hash (#9521) + // Strict HTML recognition (#11290: must start with <) + rquickExpr = /^(?:(<[\w\W]+>)[^>]*|#([\w-]*))$/, + + // Match a standalone tag + rsingleTag = /^<(\w+)\s*\/?>(?:<\/\1>|)$/, + + // JSON RegExp + rvalidchars = /^[\],:{}\s]*$/, + rvalidbraces = /(?:^|:|,)(?:\s*\[)+/g, + rvalidescape = /\\(?:["\\\/bfnrt]|u[\da-fA-F]{4})/g, + rvalidtokens = /"[^"\\\r\n]*"|true|false|null|-?(?:\d+\.|)\d+(?:[eE][+-]?\d+|)/g, + + // Matches dashed string for camelizing + rmsPrefix = /^-ms-/, + rdashAlpha = /-([\da-z])/gi, + + // Used by jQuery.camelCase as callback to replace() + fcamelCase = function( all, letter ) { + return letter.toUpperCase(); + }, + + // The ready event handler and self cleanup method + DOMContentLoaded = function() { + if ( document.addEventListener ) { + document.removeEventListener( "DOMContentLoaded", DOMContentLoaded, false ); + jQuery.ready(); + } else if ( document.readyState === "complete" ) { + // we're here because readyState === "complete" in oldIE + // which is good enough for us to call the dom ready! + document.detachEvent( "onreadystatechange", DOMContentLoaded ); + jQuery.ready(); + } + }; + +jQuery.fn = jQuery.prototype = { + // The current version of jQuery being used + jquery: core_version, + + constructor: jQuery, + init: function( selector, context, rootjQuery ) { + var match, elem; + + // HANDLE: $(""), $(null), $(undefined), $(false) + if ( !selector ) { + return this; + } + + // Handle HTML strings + if ( typeof selector === "string" ) { + if ( selector.charAt(0) === "<" && selector.charAt( selector.length - 1 ) === ">" && selector.length >= 3 ) { + // Assume that strings that start and end with <> are HTML and skip the regex check + match = [ null, selector, null ]; + + } else { + match = rquickExpr.exec( selector ); + } + + // Match html or make sure no context is specified for #id + if ( match && (match[1] || !context) ) { + + // HANDLE: $(html) -> $(array) + if ( match[1] ) { + context = context instanceof jQuery ? context[0] : context; + + // scripts is true for back-compat + jQuery.merge( this, jQuery.parseHTML( + match[1], + context && context.nodeType ? context.ownerDocument || context : document, + true + ) ); + + // HANDLE: $(html, props) + if ( rsingleTag.test( match[1] ) && jQuery.isPlainObject( context ) ) { + for ( match in context ) { + // Properties of context are called as methods if possible + if ( jQuery.isFunction( this[ match ] ) ) { + this[ match ]( context[ match ] ); + + // ...and otherwise set as attributes + } else { + this.attr( match, context[ match ] ); + } + } + } + + return this; + + // HANDLE: $(#id) + } else { + elem = document.getElementById( match[2] ); + + // Check parentNode to catch when Blackberry 4.6 returns + // nodes that are no longer in the document #6963 + if ( elem && elem.parentNode ) { + // Handle the case where IE and Opera return items + // by name instead of ID + if ( elem.id !== match[2] ) { + return rootjQuery.find( selector ); + } + + // Otherwise, we inject the element directly into the jQuery object + this.length = 1; + this[0] = elem; + } + + this.context = document; + this.selector = selector; + return this; + } + + // HANDLE: $(expr, $(...)) + } else if ( !context || context.jquery ) { + return ( context || rootjQuery ).find( selector ); + + // HANDLE: $(expr, context) + // (which is just equivalent to: $(context).find(expr) + } else { + return this.constructor( context ).find( selector ); + } + + // HANDLE: $(DOMElement) + } else if ( selector.nodeType ) { + this.context = this[0] = selector; + this.length = 1; + return this; + + // HANDLE: $(function) + // Shortcut for document ready + } else if ( jQuery.isFunction( selector ) ) { + return rootjQuery.ready( selector ); + } + + if ( selector.selector !== undefined ) { + this.selector = selector.selector; + this.context = selector.context; + } + + return jQuery.makeArray( selector, this ); + }, + + // Start with an empty selector + selector: "", + + // The default length of a jQuery object is 0 + length: 0, + + // The number of elements contained in the matched element set + size: function() { + return this.length; + }, + + toArray: function() { + return core_slice.call( this ); + }, + + // Get the Nth element in the matched element set OR + // Get the whole matched element set as a clean array + get: function( num ) { + return num == null ? + + // Return a 'clean' array + this.toArray() : + + // Return just the object + ( num < 0 ? this[ this.length + num ] : this[ num ] ); + }, + + // Take an array of elements and push it onto the stack + // (returning the new matched element set) + pushStack: function( elems ) { + + // Build a new jQuery matched element set + var ret = jQuery.merge( this.constructor(), elems ); + + // Add the old object onto the stack (as a reference) + ret.prevObject = this; + ret.context = this.context; + + // Return the newly-formed element set + return ret; + }, + + // Execute a callback for every element in the matched set. + // (You can seed the arguments with an array of args, but this is + // only used internally.) + each: function( callback, args ) { + return jQuery.each( this, callback, args ); + }, + + ready: function( fn ) { + // Add the callback + jQuery.ready.promise().done( fn ); + + return this; + }, + + slice: function() { + return this.pushStack( core_slice.apply( this, arguments ) ); + }, + + first: function() { + return this.eq( 0 ); + }, + + last: function() { + return this.eq( -1 ); + }, + + eq: function( i ) { + var len = this.length, + j = +i + ( i < 0 ? len : 0 ); + return this.pushStack( j >= 0 && j < len ? [ this[j] ] : [] ); + }, + + map: function( callback ) { + return this.pushStack( jQuery.map(this, function( elem, i ) { + return callback.call( elem, i, elem ); + })); + }, + + end: function() { + return this.prevObject || this.constructor(null); + }, + + // For internal use only. + // Behaves like an Array's method, not like a jQuery method. + push: core_push, + sort: [].sort, + splice: [].splice +}; + +// Give the init function the jQuery prototype for later instantiation +jQuery.fn.init.prototype = jQuery.fn; + +jQuery.extend = jQuery.fn.extend = function() { + var options, name, src, copy, copyIsArray, clone, + target = arguments[0] || {}, + i = 1, + length = arguments.length, + deep = false; + + // Handle a deep copy situation + if ( typeof target === "boolean" ) { + deep = target; + target = arguments[1] || {}; + // skip the boolean and the target + i = 2; + } + + // Handle case when target is a string or something (possible in deep copy) + if ( typeof target !== "object" && !jQuery.isFunction(target) ) { + target = {}; + } + + // extend jQuery itself if only one argument is passed + if ( length === i ) { + target = this; + --i; + } + + for ( ; i < length; i++ ) { + // Only deal with non-null/undefined values + if ( (options = arguments[ i ]) != null ) { + // Extend the base object + for ( name in options ) { + src = target[ name ]; + copy = options[ name ]; + + // Prevent never-ending loop + if ( target === copy ) { + continue; + } + + // Recurse if we're merging plain objects or arrays + if ( deep && copy && ( jQuery.isPlainObject(copy) || (copyIsArray = jQuery.isArray(copy)) ) ) { + if ( copyIsArray ) { + copyIsArray = false; + clone = src && jQuery.isArray(src) ? src : []; + + } else { + clone = src && jQuery.isPlainObject(src) ? src : {}; + } + + // Never move original objects, clone them + target[ name ] = jQuery.extend( deep, clone, copy ); + + // Don't bring in undefined values + } else if ( copy !== undefined ) { + target[ name ] = copy; + } + } + } + } + + // Return the modified object + return target; +}; + +jQuery.extend({ + noConflict: function( deep ) { + if ( window.$ === jQuery ) { + window.$ = _$; + } + + if ( deep && window.jQuery === jQuery ) { + window.jQuery = _jQuery; + } + + return jQuery; + }, + + // Is the DOM ready to be used? Set to true once it occurs. + isReady: false, + + // A counter to track how many items to wait for before + // the ready event fires. See #6781 + readyWait: 1, + + // Hold (or release) the ready event + holdReady: function( hold ) { + if ( hold ) { + jQuery.readyWait++; + } else { + jQuery.ready( true ); + } + }, + + // Handle when the DOM is ready + ready: function( wait ) { + + // Abort if there are pending holds or we're already ready + if ( wait === true ? --jQuery.readyWait : jQuery.isReady ) { + return; + } + + // Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443). + if ( !document.body ) { + return setTimeout( jQuery.ready ); + } + + // Remember that the DOM is ready + jQuery.isReady = true; + + // If a normal DOM Ready event fired, decrement, and wait if need be + if ( wait !== true && --jQuery.readyWait > 0 ) { + return; + } + + // If there are functions bound, to execute + readyList.resolveWith( document, [ jQuery ] ); + + // Trigger any bound ready events + if ( jQuery.fn.trigger ) { + jQuery( document ).trigger("ready").off("ready"); + } + }, + + // See test/unit/core.js for details concerning isFunction. + // Since version 1.3, DOM methods and functions like alert + // aren't supported. They return false on IE (#2968). + isFunction: function( obj ) { + return jQuery.type(obj) === "function"; + }, + + isArray: Array.isArray || function( obj ) { + return jQuery.type(obj) === "array"; + }, + + isWindow: function( obj ) { + return obj != null && obj == obj.window; + }, + + isNumeric: function( obj ) { + return !isNaN( parseFloat(obj) ) && isFinite( obj ); + }, + + type: function( obj ) { + if ( obj == null ) { + return String( obj ); + } + return typeof obj === "object" || typeof obj === "function" ? + class2type[ core_toString.call(obj) ] || "object" : + typeof obj; + }, + + isPlainObject: function( obj ) { + // Must be an Object. + // Because of IE, we also have to check the presence of the constructor property. + // Make sure that DOM nodes and window objects don't pass through, as well + if ( !obj || jQuery.type(obj) !== "object" || obj.nodeType || jQuery.isWindow( obj ) ) { + return false; + } + + try { + // Not own constructor property must be Object + if ( obj.constructor && + !core_hasOwn.call(obj, "constructor") && + !core_hasOwn.call(obj.constructor.prototype, "isPrototypeOf") ) { + return false; + } + } catch ( e ) { + // IE8,9 Will throw exceptions on certain host objects #9897 + return false; + } + + // Own properties are enumerated firstly, so to speed up, + // if last one is own, then all properties are own. + + var key; + for ( key in obj ) {} + + return key === undefined || core_hasOwn.call( obj, key ); + }, + + isEmptyObject: function( obj ) { + var name; + for ( name in obj ) { + return false; + } + return true; + }, + + error: function( msg ) { + throw new Error( msg ); + }, + + // data: string of html + // context (optional): If specified, the fragment will be created in this context, defaults to document + // keepScripts (optional): If true, will include scripts passed in the html string + parseHTML: function( data, context, keepScripts ) { + if ( !data || typeof data !== "string" ) { + return null; + } + if ( typeof context === "boolean" ) { + keepScripts = context; + context = false; + } + context = context || document; + + var parsed = rsingleTag.exec( data ), + scripts = !keepScripts && []; + + // Single tag + if ( parsed ) { + return [ context.createElement( parsed[1] ) ]; + } + + parsed = jQuery.buildFragment( [ data ], context, scripts ); + if ( scripts ) { + jQuery( scripts ).remove(); + } + return jQuery.merge( [], parsed.childNodes ); + }, + + parseJSON: function( data ) { + // Attempt to parse using the native JSON parser first + if ( window.JSON && window.JSON.parse ) { + return window.JSON.parse( data ); + } + + if ( data === null ) { + return data; + } + + if ( typeof data === "string" ) { + + // Make sure leading/trailing whitespace is removed (IE can't handle it) + data = jQuery.trim( data ); + + if ( data ) { + // Make sure the incoming data is actual JSON + // Logic borrowed from http://json.org/json2.js + if ( rvalidchars.test( data.replace( rvalidescape, "@" ) + .replace( rvalidtokens, "]" ) + .replace( rvalidbraces, "")) ) { + + return ( new Function( "return " + data ) )(); + } + } + } + + jQuery.error( "Invalid JSON: " + data ); + }, + + // Cross-browser xml parsing + parseXML: function( data ) { + var xml, tmp; + if ( !data || typeof data !== "string" ) { + return null; + } + try { + if ( window.DOMParser ) { // Standard + tmp = new DOMParser(); + xml = tmp.parseFromString( data , "text/xml" ); + } else { // IE + xml = new ActiveXObject( "Microsoft.XMLDOM" ); + xml.async = "false"; + xml.loadXML( data ); + } + } catch( e ) { + xml = undefined; + } + if ( !xml || !xml.documentElement || xml.getElementsByTagName( "parsererror" ).length ) { + jQuery.error( "Invalid XML: " + data ); + } + return xml; + }, + + noop: function() {}, + + // Evaluates a script in a global context + // Workarounds based on findings by Jim Driscoll + // http://weblogs.java.net/blog/driscoll/archive/2009/09/08/eval-javascript-global-context + globalEval: function( data ) { + if ( data && jQuery.trim( data ) ) { + // We use execScript on Internet Explorer + // We use an anonymous function so that context is window + // rather than jQuery in Firefox + ( window.execScript || function( data ) { + window[ "eval" ].call( window, data ); + } )( data ); + } + }, + + // Convert dashed to camelCase; used by the css and data modules + // Microsoft forgot to hump their vendor prefix (#9572) + camelCase: function( string ) { + return string.replace( rmsPrefix, "ms-" ).replace( rdashAlpha, fcamelCase ); + }, + + nodeName: function( elem, name ) { + return elem.nodeName && elem.nodeName.toLowerCase() === name.toLowerCase(); + }, + + // args is for internal usage only + each: function( obj, callback, args ) { + var value, + i = 0, + length = obj.length, + isArray = isArraylike( obj ); + + if ( args ) { + if ( isArray ) { + for ( ; i < length; i++ ) { + value = callback.apply( obj[ i ], args ); + + if ( value === false ) { + break; + } + } + } else { + for ( i in obj ) { + value = callback.apply( obj[ i ], args ); + + if ( value === false ) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if ( isArray ) { + for ( ; i < length; i++ ) { + value = callback.call( obj[ i ], i, obj[ i ] ); + + if ( value === false ) { + break; + } + } + } else { + for ( i in obj ) { + value = callback.call( obj[ i ], i, obj[ i ] ); + + if ( value === false ) { + break; + } + } + } + } + + return obj; + }, + + // Use native String.trim function wherever possible + trim: core_trim && !core_trim.call("\uFEFF\xA0") ? + function( text ) { + return text == null ? + "" : + core_trim.call( text ); + } : + + // Otherwise use our own trimming functionality + function( text ) { + return text == null ? + "" : + ( text + "" ).replace( rtrim, "" ); + }, + + // results is for internal usage only + makeArray: function( arr, results ) { + var ret = results || []; + + if ( arr != null ) { + if ( isArraylike( Object(arr) ) ) { + jQuery.merge( ret, + typeof arr === "string" ? + [ arr ] : arr + ); + } else { + core_push.call( ret, arr ); + } + } + + return ret; + }, + + inArray: function( elem, arr, i ) { + var len; + + if ( arr ) { + if ( core_indexOf ) { + return core_indexOf.call( arr, elem, i ); + } + + len = arr.length; + i = i ? i < 0 ? Math.max( 0, len + i ) : i : 0; + + for ( ; i < len; i++ ) { + // Skip accessing in sparse arrays + if ( i in arr && arr[ i ] === elem ) { + return i; + } + } + } + + return -1; + }, + + merge: function( first, second ) { + var l = second.length, + i = first.length, + j = 0; + + if ( typeof l === "number" ) { + for ( ; j < l; j++ ) { + first[ i++ ] = second[ j ]; + } + } else { + while ( second[j] !== undefined ) { + first[ i++ ] = second[ j++ ]; + } + } + + first.length = i; + + return first; + }, + + grep: function( elems, callback, inv ) { + var retVal, + ret = [], + i = 0, + length = elems.length; + inv = !!inv; + + // Go through the array, only saving the items + // that pass the validator function + for ( ; i < length; i++ ) { + retVal = !!callback( elems[ i ], i ); + if ( inv !== retVal ) { + ret.push( elems[ i ] ); + } + } + + return ret; + }, + + // arg is for internal usage only + map: function( elems, callback, arg ) { + var value, + i = 0, + length = elems.length, + isArray = isArraylike( elems ), + ret = []; + + // Go through the array, translating each of the items to their + if ( isArray ) { + for ( ; i < length; i++ ) { + value = callback( elems[ i ], i, arg ); + + if ( value != null ) { + ret[ ret.length ] = value; + } + } + + // Go through every key on the object, + } else { + for ( i in elems ) { + value = callback( elems[ i ], i, arg ); + + if ( value != null ) { + ret[ ret.length ] = value; + } + } + } + + // Flatten any nested arrays + return core_concat.apply( [], ret ); + }, + + // A global GUID counter for objects + guid: 1, + + // Bind a function to a context, optionally partially applying any + // arguments. + proxy: function( fn, context ) { + var tmp, args, proxy; + + if ( typeof context === "string" ) { + tmp = fn[ context ]; + context = fn; + fn = tmp; + } + + // Quick check to determine if target is callable, in the spec + // this throws a TypeError, but we will just return undefined. + if ( !jQuery.isFunction( fn ) ) { + return undefined; + } + + // Simulated bind + args = core_slice.call( arguments, 2 ); + proxy = function() { + return fn.apply( context || this, args.concat( core_slice.call( arguments ) ) ); + }; + + // Set the guid of unique handler to the same of original handler, so it can be removed + proxy.guid = fn.guid = fn.guid || jQuery.guid++; + + return proxy; + }, + + // Multifunctional method to get and set values of a collection + // The value/s can optionally be executed if it's a function + access: function( elems, fn, key, value, chainable, emptyGet, raw ) { + var i = 0, + length = elems.length, + bulk = key == null; + + // Sets many values + if ( jQuery.type( key ) === "object" ) { + chainable = true; + for ( i in key ) { + jQuery.access( elems, fn, i, key[i], true, emptyGet, raw ); + } + + // Sets one value + } else if ( value !== undefined ) { + chainable = true; + + if ( !jQuery.isFunction( value ) ) { + raw = true; + } + + if ( bulk ) { + // Bulk operations run against the entire set + if ( raw ) { + fn.call( elems, value ); + fn = null; + + // ...except when executing function values + } else { + bulk = fn; + fn = function( elem, key, value ) { + return bulk.call( jQuery( elem ), value ); + }; + } + } + + if ( fn ) { + for ( ; i < length; i++ ) { + fn( elems[i], key, raw ? value : value.call( elems[i], i, fn( elems[i], key ) ) ); + } + } + } + + return chainable ? + elems : + + // Gets + bulk ? + fn.call( elems ) : + length ? fn( elems[0], key ) : emptyGet; + }, + + now: function() { + return ( new Date() ).getTime(); + } +}); + +jQuery.ready.promise = function( obj ) { + if ( !readyList ) { + + readyList = jQuery.Deferred(); + + // Catch cases where $(document).ready() is called after the browser event has already occurred. + // we once tried to use readyState "interactive" here, but it caused issues like the one + // discovered by ChrisS here: http://bugs.jquery.com/ticket/12282#comment:15 + if ( document.readyState === "complete" ) { + // Handle it asynchronously to allow scripts the opportunity to delay ready + setTimeout( jQuery.ready ); + + // Standards-based browsers support DOMContentLoaded + } else if ( document.addEventListener ) { + // Use the handy event callback + document.addEventListener( "DOMContentLoaded", DOMContentLoaded, false ); + + // A fallback to window.onload, that will always work + window.addEventListener( "load", jQuery.ready, false ); + + // If IE event model is used + } else { + // Ensure firing before onload, maybe late but safe also for iframes + document.attachEvent( "onreadystatechange", DOMContentLoaded ); + + // A fallback to window.onload, that will always work + window.attachEvent( "onload", jQuery.ready ); + + // If IE and not a frame + // continually check to see if the document is ready + var top = false; + + try { + top = window.frameElement == null && document.documentElement; + } catch(e) {} + + if ( top && top.doScroll ) { + (function doScrollCheck() { + if ( !jQuery.isReady ) { + + try { + // Use the trick by Diego Perini + // http://javascript.nwbox.com/IEContentLoaded/ + top.doScroll("left"); + } catch(e) { + return setTimeout( doScrollCheck, 50 ); + } + + // and execute any waiting functions + jQuery.ready(); + } + })(); + } + } + } + return readyList.promise( obj ); +}; + +// Populate the class2type map +jQuery.each("Boolean Number String Function Array Date RegExp Object Error".split(" "), function(i, name) { + class2type[ "[object " + name + "]" ] = name.toLowerCase(); +}); + +function isArraylike( obj ) { + var length = obj.length, + type = jQuery.type( obj ); + + if ( jQuery.isWindow( obj ) ) { + return false; + } + + if ( obj.nodeType === 1 && length ) { + return true; + } + + return type === "array" || type !== "function" && + ( length === 0 || + typeof length === "number" && length > 0 && ( length - 1 ) in obj ); +} + +// All jQuery objects should point back to these +rootjQuery = jQuery(document); +// String to Object options format cache +var optionsCache = {}; + +// Convert String-formatted options into Object-formatted ones and store in cache +function createOptions( options ) { + var object = optionsCache[ options ] = {}; + jQuery.each( options.match( core_rnotwhite ) || [], function( _, flag ) { + object[ flag ] = true; + }); + return object; +} + +/* + * Create a callback list using the following parameters: + * + * options: an optional list of space-separated options that will change how + * the callback list behaves or a more traditional option object + * + * By default a callback list will act like an event callback list and can be + * "fired" multiple times. + * + * Possible options: + * + * once: will ensure the callback list can only be fired once (like a Deferred) + * + * memory: will keep track of previous values and will call any callback added + * after the list has been fired right away with the latest "memorized" + * values (like a Deferred) + * + * unique: will ensure a callback can only be added once (no duplicate in the list) + * + * stopOnFalse: interrupt callings when a callback returns false + * + */ +jQuery.Callbacks = function( options ) { + + // Convert options from String-formatted to Object-formatted if needed + // (we check in cache first) + options = typeof options === "string" ? + ( optionsCache[ options ] || createOptions( options ) ) : + jQuery.extend( {}, options ); + + var // Last fire value (for non-forgettable lists) + memory, + // Flag to know if list was already fired + fired, + // Flag to know if list is currently firing + firing, + // First callback to fire (used internally by add and fireWith) + firingStart, + // End of the loop when firing + firingLength, + // Index of currently firing callback (modified by remove if needed) + firingIndex, + // Actual callback list + list = [], + // Stack of fire calls for repeatable lists + stack = !options.once && [], + // Fire callbacks + fire = function( data ) { + memory = options.memory && data; + fired = true; + firingIndex = firingStart || 0; + firingStart = 0; + firingLength = list.length; + firing = true; + for ( ; list && firingIndex < firingLength; firingIndex++ ) { + if ( list[ firingIndex ].apply( data[ 0 ], data[ 1 ] ) === false && options.stopOnFalse ) { + memory = false; // To prevent further calls using add + break; + } + } + firing = false; + if ( list ) { + if ( stack ) { + if ( stack.length ) { + fire( stack.shift() ); + } + } else if ( memory ) { + list = []; + } else { + self.disable(); + } + } + }, + // Actual Callbacks object + self = { + // Add a callback or a collection of callbacks to the list + add: function() { + if ( list ) { + // First, we save the current length + var start = list.length; + (function add( args ) { + jQuery.each( args, function( _, arg ) { + var type = jQuery.type( arg ); + if ( type === "function" ) { + if ( !options.unique || !self.has( arg ) ) { + list.push( arg ); + } + } else if ( arg && arg.length && type !== "string" ) { + // Inspect recursively + add( arg ); + } + }); + })( arguments ); + // Do we need to add the callbacks to the + // current firing batch? + if ( firing ) { + firingLength = list.length; + // With memory, if we're not firing then + // we should call right away + } else if ( memory ) { + firingStart = start; + fire( memory ); + } + } + return this; + }, + // Remove a callback from the list + remove: function() { + if ( list ) { + jQuery.each( arguments, function( _, arg ) { + var index; + while( ( index = jQuery.inArray( arg, list, index ) ) > -1 ) { + list.splice( index, 1 ); + // Handle firing indexes + if ( firing ) { + if ( index <= firingLength ) { + firingLength--; + } + if ( index <= firingIndex ) { + firingIndex--; + } + } + } + }); + } + return this; + }, + // Control if a given callback is in the list + has: function( fn ) { + return jQuery.inArray( fn, list ) > -1; + }, + // Remove all callbacks from the list + empty: function() { + list = []; + return this; + }, + // Have the list do nothing anymore + disable: function() { + list = stack = memory = undefined; + return this; + }, + // Is it disabled? + disabled: function() { + return !list; + }, + // Lock the list in its current state + lock: function() { + stack = undefined; + if ( !memory ) { + self.disable(); + } + return this; + }, + // Is it locked? + locked: function() { + return !stack; + }, + // Call all callbacks with the given context and arguments + fireWith: function( context, args ) { + args = args || []; + args = [ context, args.slice ? args.slice() : args ]; + if ( list && ( !fired || stack ) ) { + if ( firing ) { + stack.push( args ); + } else { + fire( args ); + } + } + return this; + }, + // Call all the callbacks with the given arguments + fire: function() { + self.fireWith( this, arguments ); + return this; + }, + // To know if the callbacks have already been called at least once + fired: function() { + return !!fired; + } + }; + + return self; +}; +jQuery.extend({ + + Deferred: function( func ) { + var tuples = [ + // action, add listener, listener list, final state + [ "resolve", "done", jQuery.Callbacks("once memory"), "resolved" ], + [ "reject", "fail", jQuery.Callbacks("once memory"), "rejected" ], + [ "notify", "progress", jQuery.Callbacks("memory") ] + ], + state = "pending", + promise = { + state: function() { + return state; + }, + always: function() { + deferred.done( arguments ).fail( arguments ); + return this; + }, + then: function( /* fnDone, fnFail, fnProgress */ ) { + var fns = arguments; + return jQuery.Deferred(function( newDefer ) { + jQuery.each( tuples, function( i, tuple ) { + var action = tuple[ 0 ], + fn = jQuery.isFunction( fns[ i ] ) && fns[ i ]; + // deferred[ done | fail | progress ] for forwarding actions to newDefer + deferred[ tuple[1] ](function() { + var returned = fn && fn.apply( this, arguments ); + if ( returned && jQuery.isFunction( returned.promise ) ) { + returned.promise() + .done( newDefer.resolve ) + .fail( newDefer.reject ) + .progress( newDefer.notify ); + } else { + newDefer[ action + "With" ]( this === promise ? newDefer.promise() : this, fn ? [ returned ] : arguments ); + } + }); + }); + fns = null; + }).promise(); + }, + // Get a promise for this deferred + // If obj is provided, the promise aspect is added to the object + promise: function( obj ) { + return obj != null ? jQuery.extend( obj, promise ) : promise; + } + }, + deferred = {}; + + // Keep pipe for back-compat + promise.pipe = promise.then; + + // Add list-specific methods + jQuery.each( tuples, function( i, tuple ) { + var list = tuple[ 2 ], + stateString = tuple[ 3 ]; + + // promise[ done | fail | progress ] = list.add + promise[ tuple[1] ] = list.add; + + // Handle state + if ( stateString ) { + list.add(function() { + // state = [ resolved | rejected ] + state = stateString; + + // [ reject_list | resolve_list ].disable; progress_list.lock + }, tuples[ i ^ 1 ][ 2 ].disable, tuples[ 2 ][ 2 ].lock ); + } + + // deferred[ resolve | reject | notify ] + deferred[ tuple[0] ] = function() { + deferred[ tuple[0] + "With" ]( this === deferred ? promise : this, arguments ); + return this; + }; + deferred[ tuple[0] + "With" ] = list.fireWith; + }); + + // Make the deferred a promise + promise.promise( deferred ); + + // Call given func if any + if ( func ) { + func.call( deferred, deferred ); + } + + // All done! + return deferred; + }, + + // Deferred helper + when: function( subordinate /* , ..., subordinateN */ ) { + var i = 0, + resolveValues = core_slice.call( arguments ), + length = resolveValues.length, + + // the count of uncompleted subordinates + remaining = length !== 1 || ( subordinate && jQuery.isFunction( subordinate.promise ) ) ? length : 0, + + // the master Deferred. If resolveValues consist of only a single Deferred, just use that. + deferred = remaining === 1 ? subordinate : jQuery.Deferred(), + + // Update function for both resolve and progress values + updateFunc = function( i, contexts, values ) { + return function( value ) { + contexts[ i ] = this; + values[ i ] = arguments.length > 1 ? core_slice.call( arguments ) : value; + if( values === progressValues ) { + deferred.notifyWith( contexts, values ); + } else if ( !( --remaining ) ) { + deferred.resolveWith( contexts, values ); + } + }; + }, + + progressValues, progressContexts, resolveContexts; + + // add listeners to Deferred subordinates; treat others as resolved + if ( length > 1 ) { + progressValues = new Array( length ); + progressContexts = new Array( length ); + resolveContexts = new Array( length ); + for ( ; i < length; i++ ) { + if ( resolveValues[ i ] && jQuery.isFunction( resolveValues[ i ].promise ) ) { + resolveValues[ i ].promise() + .done( updateFunc( i, resolveContexts, resolveValues ) ) + .fail( deferred.reject ) + .progress( updateFunc( i, progressContexts, progressValues ) ); + } else { + --remaining; + } + } + } + + // if we're not waiting on anything, resolve the master + if ( !remaining ) { + deferred.resolveWith( resolveContexts, resolveValues ); + } + + return deferred.promise(); + } +}); +jQuery.support = (function() { + + var support, all, a, select, opt, input, fragment, eventName, isSupported, i, + div = document.createElement("div"); + + // Setup + div.setAttribute( "className", "t" ); + div.innerHTML = "
    a"; + + // Support tests won't run in some limited or non-browser environments + all = div.getElementsByTagName("*"); + a = div.getElementsByTagName("a")[ 0 ]; + if ( !all || !a || !all.length ) { + return {}; + } + + // First batch of tests + select = document.createElement("select"); + opt = select.appendChild( document.createElement("option") ); + input = div.getElementsByTagName("input")[ 0 ]; + + a.style.cssText = "top:1px;float:left;opacity:.5"; + support = { + // Test setAttribute on camelCase class. If it works, we need attrFixes when doing get/setAttribute (ie6/7) + getSetAttribute: div.className !== "t", + + // IE strips leading whitespace when .innerHTML is used + leadingWhitespace: div.firstChild.nodeType === 3, + + // Make sure that tbody elements aren't automatically inserted + // IE will insert them into empty tables + tbody: !div.getElementsByTagName("tbody").length, + + // Make sure that link elements get serialized correctly by innerHTML + // This requires a wrapper element in IE + htmlSerialize: !!div.getElementsByTagName("link").length, + + // Get the style information from getAttribute + // (IE uses .cssText instead) + style: /top/.test( a.getAttribute("style") ), + + // Make sure that URLs aren't manipulated + // (IE normalizes it by default) + hrefNormalized: a.getAttribute("href") === "/a", + + // Make sure that element opacity exists + // (IE uses filter instead) + // Use a regex to work around a WebKit issue. See #5145 + opacity: /^0.5/.test( a.style.opacity ), + + // Verify style float existence + // (IE uses styleFloat instead of cssFloat) + cssFloat: !!a.style.cssFloat, + + // Check the default checkbox/radio value ("" on WebKit; "on" elsewhere) + checkOn: !!input.value, + + // Make sure that a selected-by-default option has a working selected property. + // (WebKit defaults to false instead of true, IE too, if it's in an optgroup) + optSelected: opt.selected, + + // Tests for enctype support on a form (#6743) + enctype: !!document.createElement("form").enctype, + + // Makes sure cloning an html5 element does not cause problems + // Where outerHTML is undefined, this still works + html5Clone: document.createElement("nav").cloneNode( true ).outerHTML !== "<:nav>", + + // jQuery.support.boxModel DEPRECATED in 1.8 since we don't support Quirks Mode + boxModel: document.compatMode === "CSS1Compat", + + // Will be defined later + deleteExpando: true, + noCloneEvent: true, + inlineBlockNeedsLayout: false, + shrinkWrapBlocks: false, + reliableMarginRight: true, + boxSizingReliable: true, + pixelPosition: false + }; + + // Make sure checked status is properly cloned + input.checked = true; + support.noCloneChecked = input.cloneNode( true ).checked; + + // Make sure that the options inside disabled selects aren't marked as disabled + // (WebKit marks them as disabled) + select.disabled = true; + support.optDisabled = !opt.disabled; + + // Support: IE<9 + try { + delete div.test; + } catch( e ) { + support.deleteExpando = false; + } + + // Check if we can trust getAttribute("value") + input = document.createElement("input"); + input.setAttribute( "value", "" ); + support.input = input.getAttribute( "value" ) === ""; + + // Check if an input maintains its value after becoming a radio + input.value = "t"; + input.setAttribute( "type", "radio" ); + support.radioValue = input.value === "t"; + + // #11217 - WebKit loses check when the name is after the checked attribute + input.setAttribute( "checked", "t" ); + input.setAttribute( "name", "t" ); + + fragment = document.createDocumentFragment(); + fragment.appendChild( input ); + + // Check if a disconnected checkbox will retain its checked + // value of true after appended to the DOM (IE6/7) + support.appendChecked = input.checked; + + // WebKit doesn't clone checked state correctly in fragments + support.checkClone = fragment.cloneNode( true ).cloneNode( true ).lastChild.checked; + + // Support: IE<9 + // Opera does not clone events (and typeof div.attachEvent === undefined). + // IE9-10 clones events bound via attachEvent, but they don't trigger with .click() + if ( div.attachEvent ) { + div.attachEvent( "onclick", function() { + support.noCloneEvent = false; + }); + + div.cloneNode( true ).click(); + } + + // Support: IE<9 (lack submit/change bubble), Firefox 17+ (lack focusin event) + // Beware of CSP restrictions (https://developer.mozilla.org/en/Security/CSP), test/csp.php + for ( i in { submit: true, change: true, focusin: true }) { + div.setAttribute( eventName = "on" + i, "t" ); + + support[ i + "Bubbles" ] = eventName in window || div.attributes[ eventName ].expando === false; + } + + div.style.backgroundClip = "content-box"; + div.cloneNode( true ).style.backgroundClip = ""; + support.clearCloneStyle = div.style.backgroundClip === "content-box"; + + // Run tests that need a body at doc ready + jQuery(function() { + var container, marginDiv, tds, + divReset = "padding:0;margin:0;border:0;display:block;box-sizing:content-box;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;", + body = document.getElementsByTagName("body")[0]; + + if ( !body ) { + // Return for frameset docs that don't have a body + return; + } + + container = document.createElement("div"); + container.style.cssText = "border:0;width:0;height:0;position:absolute;top:0;left:-9999px;margin-top:1px"; + + body.appendChild( container ).appendChild( div ); + + // Support: IE8 + // Check if table cells still have offsetWidth/Height when they are set + // to display:none and there are still other visible table cells in a + // table row; if so, offsetWidth/Height are not reliable for use when + // determining if an element has been hidden directly using + // display:none (it is still safe to use offsets if a parent element is + // hidden; don safety goggles and see bug #4512 for more information). + div.innerHTML = "
    t
    "; + tds = div.getElementsByTagName("td"); + tds[ 0 ].style.cssText = "padding:0;margin:0;border:0;display:none"; + isSupported = ( tds[ 0 ].offsetHeight === 0 ); + + tds[ 0 ].style.display = ""; + tds[ 1 ].style.display = "none"; + + // Support: IE8 + // Check if empty table cells still have offsetWidth/Height + support.reliableHiddenOffsets = isSupported && ( tds[ 0 ].offsetHeight === 0 ); + + // Check box-sizing and margin behavior + div.innerHTML = ""; + div.style.cssText = "box-sizing:border-box;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;padding:1px;border:1px;display:block;width:4px;margin-top:1%;position:absolute;top:1%;"; + support.boxSizing = ( div.offsetWidth === 4 ); + support.doesNotIncludeMarginInBodyOffset = ( body.offsetTop !== 1 ); + + // Use window.getComputedStyle because jsdom on node.js will break without it. + if ( window.getComputedStyle ) { + support.pixelPosition = ( window.getComputedStyle( div, null ) || {} ).top !== "1%"; + support.boxSizingReliable = ( window.getComputedStyle( div, null ) || { width: "4px" } ).width === "4px"; + + // Check if div with explicit width and no margin-right incorrectly + // gets computed margin-right based on width of container. (#3333) + // Fails in WebKit before Feb 2011 nightlies + // WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right + marginDiv = div.appendChild( document.createElement("div") ); + marginDiv.style.cssText = div.style.cssText = divReset; + marginDiv.style.marginRight = marginDiv.style.width = "0"; + div.style.width = "1px"; + + support.reliableMarginRight = + !parseFloat( ( window.getComputedStyle( marginDiv, null ) || {} ).marginRight ); + } + + if ( typeof div.style.zoom !== "undefined" ) { + // Support: IE<8 + // Check if natively block-level elements act like inline-block + // elements when setting their display to 'inline' and giving + // them layout + div.innerHTML = ""; + div.style.cssText = divReset + "width:1px;padding:1px;display:inline;zoom:1"; + support.inlineBlockNeedsLayout = ( div.offsetWidth === 3 ); + + // Support: IE6 + // Check if elements with layout shrink-wrap their children + div.style.display = "block"; + div.innerHTML = "
    "; + div.firstChild.style.width = "5px"; + support.shrinkWrapBlocks = ( div.offsetWidth !== 3 ); + + // Prevent IE 6 from affecting layout for positioned elements #11048 + // Prevent IE from shrinking the body in IE 7 mode #12869 + body.style.zoom = 1; + } + + body.removeChild( container ); + + // Null elements to avoid leaks in IE + container = div = tds = marginDiv = null; + }); + + // Null elements to avoid leaks in IE + all = select = fragment = opt = a = input = null; + + return support; +})(); + +var rbrace = /(?:\{[\s\S]*\}|\[[\s\S]*\])$/, + rmultiDash = /([A-Z])/g; + +function internalData( elem, name, data, pvt /* Internal Use Only */ ){ + if ( !jQuery.acceptData( elem ) ) { + return; + } + + var thisCache, ret, + internalKey = jQuery.expando, + getByName = typeof name === "string", + + // We have to handle DOM nodes and JS objects differently because IE6-7 + // can't GC object references properly across the DOM-JS boundary + isNode = elem.nodeType, + + // Only DOM nodes need the global jQuery cache; JS object data is + // attached directly to the object so GC can occur automatically + cache = isNode ? jQuery.cache : elem, + + // Only defining an ID for JS objects if its cache already exists allows + // the code to shortcut on the same path as a DOM node with no cache + id = isNode ? elem[ internalKey ] : elem[ internalKey ] && internalKey; + + // Avoid doing any more work than we need to when trying to get data on an + // object that has no data at all + if ( (!id || !cache[id] || (!pvt && !cache[id].data)) && getByName && data === undefined ) { + return; + } + + if ( !id ) { + // Only DOM nodes need a new unique ID for each element since their data + // ends up in the global cache + if ( isNode ) { + elem[ internalKey ] = id = core_deletedIds.pop() || jQuery.guid++; + } else { + id = internalKey; + } + } + + if ( !cache[ id ] ) { + cache[ id ] = {}; + + // Avoids exposing jQuery metadata on plain JS objects when the object + // is serialized using JSON.stringify + if ( !isNode ) { + cache[ id ].toJSON = jQuery.noop; + } + } + + // An object can be passed to jQuery.data instead of a key/value pair; this gets + // shallow copied over onto the existing cache + if ( typeof name === "object" || typeof name === "function" ) { + if ( pvt ) { + cache[ id ] = jQuery.extend( cache[ id ], name ); + } else { + cache[ id ].data = jQuery.extend( cache[ id ].data, name ); + } + } + + thisCache = cache[ id ]; + + // jQuery data() is stored in a separate object inside the object's internal data + // cache in order to avoid key collisions between internal data and user-defined + // data. + if ( !pvt ) { + if ( !thisCache.data ) { + thisCache.data = {}; + } + + thisCache = thisCache.data; + } + + if ( data !== undefined ) { + thisCache[ jQuery.camelCase( name ) ] = data; + } + + // Check for both converted-to-camel and non-converted data property names + // If a data property was specified + if ( getByName ) { + + // First Try to find as-is property data + ret = thisCache[ name ]; + + // Test for null|undefined property data + if ( ret == null ) { + + // Try to find the camelCased property + ret = thisCache[ jQuery.camelCase( name ) ]; + } + } else { + ret = thisCache; + } + + return ret; +} + +function internalRemoveData( elem, name, pvt /* For internal use only */ ){ + if ( !jQuery.acceptData( elem ) ) { + return; + } + + var thisCache, i, l, + + isNode = elem.nodeType, + + // See jQuery.data for more information + cache = isNode ? jQuery.cache : elem, + id = isNode ? elem[ jQuery.expando ] : jQuery.expando; + + // If there is already no cache entry for this object, there is no + // purpose in continuing + if ( !cache[ id ] ) { + return; + } + + if ( name ) { + + thisCache = pvt ? cache[ id ] : cache[ id ].data; + + if ( thisCache ) { + + // Support array or space separated string names for data keys + if ( !jQuery.isArray( name ) ) { + + // try the string as a key before any manipulation + if ( name in thisCache ) { + name = [ name ]; + } else { + + // split the camel cased version by spaces unless a key with the spaces exists + name = jQuery.camelCase( name ); + if ( name in thisCache ) { + name = [ name ]; + } else { + name = name.split(" "); + } + } + } else { + // If "name" is an array of keys... + // When data is initially created, via ("key", "val") signature, + // keys will be converted to camelCase. + // Since there is no way to tell _how_ a key was added, remove + // both plain key and camelCase key. #12786 + // This will only penalize the array argument path. + name = name.concat( jQuery.map( name, jQuery.camelCase ) ); + } + + for ( i = 0, l = name.length; i < l; i++ ) { + delete thisCache[ name[i] ]; + } + + // If there is no data left in the cache, we want to continue + // and let the cache object itself get destroyed + if ( !( pvt ? isEmptyDataObject : jQuery.isEmptyObject )( thisCache ) ) { + return; + } + } + } + + // See jQuery.data for more information + if ( !pvt ) { + delete cache[ id ].data; + + // Don't destroy the parent cache unless the internal data object + // had been the only thing left in it + if ( !isEmptyDataObject( cache[ id ] ) ) { + return; + } + } + + // Destroy the cache + if ( isNode ) { + jQuery.cleanData( [ elem ], true ); + + // Use delete when supported for expandos or `cache` is not a window per isWindow (#10080) + } else if ( jQuery.support.deleteExpando || cache != cache.window ) { + delete cache[ id ]; + + // When all else fails, null + } else { + cache[ id ] = null; + } +} + +jQuery.extend({ + cache: {}, + + // Unique for each copy of jQuery on the page + // Non-digits removed to match rinlinejQuery + expando: "jQuery" + ( core_version + Math.random() ).replace( /\D/g, "" ), + + // The following elements throw uncatchable exceptions if you + // attempt to add expando properties to them. + noData: { + "embed": true, + // Ban all objects except for Flash (which handle expandos) + "object": "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000", + "applet": true + }, + + hasData: function( elem ) { + elem = elem.nodeType ? jQuery.cache[ elem[jQuery.expando] ] : elem[ jQuery.expando ]; + return !!elem && !isEmptyDataObject( elem ); + }, + + data: function( elem, name, data ) { + return internalData( elem, name, data, false ); + }, + + removeData: function( elem, name ) { + return internalRemoveData( elem, name, false ); + }, + + // For internal use only. + _data: function( elem, name, data ) { + return internalData( elem, name, data, true ); + }, + + _removeData: function( elem, name ) { + return internalRemoveData( elem, name, true ); + }, + + // A method for determining if a DOM node can handle the data expando + acceptData: function( elem ) { + var noData = elem.nodeName && jQuery.noData[ elem.nodeName.toLowerCase() ]; + + // nodes accept data unless otherwise specified; rejection can be conditional + return !noData || noData !== true && elem.getAttribute("classid") === noData; + } +}); + +jQuery.fn.extend({ + data: function( key, value ) { + var attrs, name, + elem = this[0], + i = 0, + data = null; + + // Gets all values + if ( key === undefined ) { + if ( this.length ) { + data = jQuery.data( elem ); + + if ( elem.nodeType === 1 && !jQuery._data( elem, "parsedAttrs" ) ) { + attrs = elem.attributes; + for ( ; i < attrs.length; i++ ) { + name = attrs[i].name; + + if ( !name.indexOf( "data-" ) ) { + name = jQuery.camelCase( name.substring(5) ); + + dataAttr( elem, name, data[ name ] ); + } + } + jQuery._data( elem, "parsedAttrs", true ); + } + } + + return data; + } + + // Sets multiple values + if ( typeof key === "object" ) { + return this.each(function() { + jQuery.data( this, key ); + }); + } + + return jQuery.access( this, function( value ) { + + if ( value === undefined ) { + // Try to fetch any internally stored data first + return elem ? dataAttr( elem, key, jQuery.data( elem, key ) ) : null; + } + + this.each(function() { + jQuery.data( this, key, value ); + }); + }, null, value, arguments.length > 1, null, true ); + }, + + removeData: function( key ) { + return this.each(function() { + jQuery.removeData( this, key ); + }); + } +}); + +function dataAttr( elem, key, data ) { + // If nothing was found internally, try to fetch any + // data from the HTML5 data-* attribute + if ( data === undefined && elem.nodeType === 1 ) { + + var name = "data-" + key.replace( rmultiDash, "-$1" ).toLowerCase(); + + data = elem.getAttribute( name ); + + if ( typeof data === "string" ) { + try { + data = data === "true" ? true : + data === "false" ? false : + data === "null" ? null : + // Only convert to a number if it doesn't change the string + +data + "" === data ? +data : + rbrace.test( data ) ? jQuery.parseJSON( data ) : + data; + } catch( e ) {} + + // Make sure we set the data so it isn't changed later + jQuery.data( elem, key, data ); + + } else { + data = undefined; + } + } + + return data; +} + +// checks a cache object for emptiness +function isEmptyDataObject( obj ) { + var name; + for ( name in obj ) { + + // if the public data object is empty, the private is still empty + if ( name === "data" && jQuery.isEmptyObject( obj[name] ) ) { + continue; + } + if ( name !== "toJSON" ) { + return false; + } + } + + return true; +} +jQuery.extend({ + queue: function( elem, type, data ) { + var queue; + + if ( elem ) { + type = ( type || "fx" ) + "queue"; + queue = jQuery._data( elem, type ); + + // Speed up dequeue by getting out quickly if this is just a lookup + if ( data ) { + if ( !queue || jQuery.isArray(data) ) { + queue = jQuery._data( elem, type, jQuery.makeArray(data) ); + } else { + queue.push( data ); + } + } + return queue || []; + } + }, + + dequeue: function( elem, type ) { + type = type || "fx"; + + var queue = jQuery.queue( elem, type ), + startLength = queue.length, + fn = queue.shift(), + hooks = jQuery._queueHooks( elem, type ), + next = function() { + jQuery.dequeue( elem, type ); + }; + + // If the fx queue is dequeued, always remove the progress sentinel + if ( fn === "inprogress" ) { + fn = queue.shift(); + startLength--; + } + + hooks.cur = fn; + if ( fn ) { + + // Add a progress sentinel to prevent the fx queue from being + // automatically dequeued + if ( type === "fx" ) { + queue.unshift( "inprogress" ); + } + + // clear up the last queue stop function + delete hooks.stop; + fn.call( elem, next, hooks ); + } + + if ( !startLength && hooks ) { + hooks.empty.fire(); + } + }, + + // not intended for public consumption - generates a queueHooks object, or returns the current one + _queueHooks: function( elem, type ) { + var key = type + "queueHooks"; + return jQuery._data( elem, key ) || jQuery._data( elem, key, { + empty: jQuery.Callbacks("once memory").add(function() { + jQuery._removeData( elem, type + "queue" ); + jQuery._removeData( elem, key ); + }) + }); + } +}); + +jQuery.fn.extend({ + queue: function( type, data ) { + var setter = 2; + + if ( typeof type !== "string" ) { + data = type; + type = "fx"; + setter--; + } + + if ( arguments.length < setter ) { + return jQuery.queue( this[0], type ); + } + + return data === undefined ? + this : + this.each(function() { + var queue = jQuery.queue( this, type, data ); + + // ensure a hooks for this queue + jQuery._queueHooks( this, type ); + + if ( type === "fx" && queue[0] !== "inprogress" ) { + jQuery.dequeue( this, type ); + } + }); + }, + dequeue: function( type ) { + return this.each(function() { + jQuery.dequeue( this, type ); + }); + }, + // Based off of the plugin by Clint Helfers, with permission. + // http://blindsignals.com/index.php/2009/07/jquery-delay/ + delay: function( time, type ) { + time = jQuery.fx ? jQuery.fx.speeds[ time ] || time : time; + type = type || "fx"; + + return this.queue( type, function( next, hooks ) { + var timeout = setTimeout( next, time ); + hooks.stop = function() { + clearTimeout( timeout ); + }; + }); + }, + clearQueue: function( type ) { + return this.queue( type || "fx", [] ); + }, + // Get a promise resolved when queues of a certain type + // are emptied (fx is the type by default) + promise: function( type, obj ) { + var tmp, + count = 1, + defer = jQuery.Deferred(), + elements = this, + i = this.length, + resolve = function() { + if ( !( --count ) ) { + defer.resolveWith( elements, [ elements ] ); + } + }; + + if ( typeof type !== "string" ) { + obj = type; + type = undefined; + } + type = type || "fx"; + + while( i-- ) { + tmp = jQuery._data( elements[ i ], type + "queueHooks" ); + if ( tmp && tmp.empty ) { + count++; + tmp.empty.add( resolve ); + } + } + resolve(); + return defer.promise( obj ); + } +}); +var nodeHook, boolHook, + rclass = /[\t\r\n]/g, + rreturn = /\r/g, + rfocusable = /^(?:input|select|textarea|button|object)$/i, + rclickable = /^(?:a|area)$/i, + rboolean = /^(?:checked|selected|autofocus|autoplay|async|controls|defer|disabled|hidden|loop|multiple|open|readonly|required|scoped)$/i, + ruseDefault = /^(?:checked|selected)$/i, + getSetAttribute = jQuery.support.getSetAttribute, + getSetInput = jQuery.support.input; + +jQuery.fn.extend({ + attr: function( name, value ) { + return jQuery.access( this, jQuery.attr, name, value, arguments.length > 1 ); + }, + + removeAttr: function( name ) { + return this.each(function() { + jQuery.removeAttr( this, name ); + }); + }, + + prop: function( name, value ) { + return jQuery.access( this, jQuery.prop, name, value, arguments.length > 1 ); + }, + + removeProp: function( name ) { + name = jQuery.propFix[ name ] || name; + return this.each(function() { + // try/catch handles cases where IE balks (such as removing a property on window) + try { + this[ name ] = undefined; + delete this[ name ]; + } catch( e ) {} + }); + }, + + addClass: function( value ) { + var classes, elem, cur, clazz, j, + i = 0, + len = this.length, + proceed = typeof value === "string" && value; + + if ( jQuery.isFunction( value ) ) { + return this.each(function( j ) { + jQuery( this ).addClass( value.call( this, j, this.className ) ); + }); + } + + if ( proceed ) { + // The disjunction here is for better compressibility (see removeClass) + classes = ( value || "" ).match( core_rnotwhite ) || []; + + for ( ; i < len; i++ ) { + elem = this[ i ]; + cur = elem.nodeType === 1 && ( elem.className ? + ( " " + elem.className + " " ).replace( rclass, " " ) : + " " + ); + + if ( cur ) { + j = 0; + while ( (clazz = classes[j++]) ) { + if ( cur.indexOf( " " + clazz + " " ) < 0 ) { + cur += clazz + " "; + } + } + elem.className = jQuery.trim( cur ); + + } + } + } + + return this; + }, + + removeClass: function( value ) { + var classes, elem, cur, clazz, j, + i = 0, + len = this.length, + proceed = arguments.length === 0 || typeof value === "string" && value; + + if ( jQuery.isFunction( value ) ) { + return this.each(function( j ) { + jQuery( this ).removeClass( value.call( this, j, this.className ) ); + }); + } + if ( proceed ) { + classes = ( value || "" ).match( core_rnotwhite ) || []; + + for ( ; i < len; i++ ) { + elem = this[ i ]; + // This expression is here for better compressibility (see addClass) + cur = elem.nodeType === 1 && ( elem.className ? + ( " " + elem.className + " " ).replace( rclass, " " ) : + "" + ); + + if ( cur ) { + j = 0; + while ( (clazz = classes[j++]) ) { + // Remove *all* instances + while ( cur.indexOf( " " + clazz + " " ) >= 0 ) { + cur = cur.replace( " " + clazz + " ", " " ); + } + } + elem.className = value ? jQuery.trim( cur ) : ""; + } + } + } + + return this; + }, + + toggleClass: function( value, stateVal ) { + var type = typeof value, + isBool = typeof stateVal === "boolean"; + + if ( jQuery.isFunction( value ) ) { + return this.each(function( i ) { + jQuery( this ).toggleClass( value.call(this, i, this.className, stateVal), stateVal ); + }); + } + + return this.each(function() { + if ( type === "string" ) { + // toggle individual class names + var className, + i = 0, + self = jQuery( this ), + state = stateVal, + classNames = value.match( core_rnotwhite ) || []; + + while ( (className = classNames[ i++ ]) ) { + // check each className given, space separated list + state = isBool ? state : !self.hasClass( className ); + self[ state ? "addClass" : "removeClass" ]( className ); + } + + // Toggle whole class name + } else if ( type === "undefined" || type === "boolean" ) { + if ( this.className ) { + // store className if set + jQuery._data( this, "__className__", this.className ); + } + + // If the element has a class name or if we're passed "false", + // then remove the whole classname (if there was one, the above saved it). + // Otherwise bring back whatever was previously saved (if anything), + // falling back to the empty string if nothing was stored. + this.className = this.className || value === false ? "" : jQuery._data( this, "__className__" ) || ""; + } + }); + }, + + hasClass: function( selector ) { + var className = " " + selector + " ", + i = 0, + l = this.length; + for ( ; i < l; i++ ) { + if ( this[i].nodeType === 1 && (" " + this[i].className + " ").replace(rclass, " ").indexOf( className ) >= 0 ) { + return true; + } + } + + return false; + }, + + val: function( value ) { + var hooks, ret, isFunction, + elem = this[0]; + + if ( !arguments.length ) { + if ( elem ) { + hooks = jQuery.valHooks[ elem.type ] || jQuery.valHooks[ elem.nodeName.toLowerCase() ]; + + if ( hooks && "get" in hooks && (ret = hooks.get( elem, "value" )) !== undefined ) { + return ret; + } + + ret = elem.value; + + return typeof ret === "string" ? + // handle most common string cases + ret.replace(rreturn, "") : + // handle cases where value is null/undef or number + ret == null ? "" : ret; + } + + return; + } + + isFunction = jQuery.isFunction( value ); + + return this.each(function( i ) { + var val, + self = jQuery(this); + + if ( this.nodeType !== 1 ) { + return; + } + + if ( isFunction ) { + val = value.call( this, i, self.val() ); + } else { + val = value; + } + + // Treat null/undefined as ""; convert numbers to string + if ( val == null ) { + val = ""; + } else if ( typeof val === "number" ) { + val += ""; + } else if ( jQuery.isArray( val ) ) { + val = jQuery.map(val, function ( value ) { + return value == null ? "" : value + ""; + }); + } + + hooks = jQuery.valHooks[ this.type ] || jQuery.valHooks[ this.nodeName.toLowerCase() ]; + + // If set returns undefined, fall back to normal setting + if ( !hooks || !("set" in hooks) || hooks.set( this, val, "value" ) === undefined ) { + this.value = val; + } + }); + } +}); + +jQuery.extend({ + valHooks: { + option: { + get: function( elem ) { + // attributes.value is undefined in Blackberry 4.7 but + // uses .value. See #6932 + var val = elem.attributes.value; + return !val || val.specified ? elem.value : elem.text; + } + }, + select: { + get: function( elem ) { + var value, option, + options = elem.options, + index = elem.selectedIndex, + one = elem.type === "select-one" || index < 0, + values = one ? null : [], + max = one ? index + 1 : options.length, + i = index < 0 ? + max : + one ? index : 0; + + // Loop through all the selected options + for ( ; i < max; i++ ) { + option = options[ i ]; + + // oldIE doesn't update selected after form reset (#2551) + if ( ( option.selected || i === index ) && + // Don't return options that are disabled or in a disabled optgroup + ( jQuery.support.optDisabled ? !option.disabled : option.getAttribute("disabled") === null ) && + ( !option.parentNode.disabled || !jQuery.nodeName( option.parentNode, "optgroup" ) ) ) { + + // Get the specific value for the option + value = jQuery( option ).val(); + + // We don't need an array for one selects + if ( one ) { + return value; + } + + // Multi-Selects return an array + values.push( value ); + } + } + + return values; + }, + + set: function( elem, value ) { + var values = jQuery.makeArray( value ); + + jQuery(elem).find("option").each(function() { + this.selected = jQuery.inArray( jQuery(this).val(), values ) >= 0; + }); + + if ( !values.length ) { + elem.selectedIndex = -1; + } + return values; + } + } + }, + + attr: function( elem, name, value ) { + var ret, hooks, notxml, + nType = elem.nodeType; + + // don't get/set attributes on text, comment and attribute nodes + if ( !elem || nType === 3 || nType === 8 || nType === 2 ) { + return; + } + + // Fallback to prop when attributes are not supported + if ( typeof elem.getAttribute === "undefined" ) { + return jQuery.prop( elem, name, value ); + } + + notxml = nType !== 1 || !jQuery.isXMLDoc( elem ); + + // All attributes are lowercase + // Grab necessary hook if one is defined + if ( notxml ) { + name = name.toLowerCase(); + hooks = jQuery.attrHooks[ name ] || ( rboolean.test( name ) ? boolHook : nodeHook ); + } + + if ( value !== undefined ) { + + if ( value === null ) { + jQuery.removeAttr( elem, name ); + + } else if ( hooks && notxml && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ) { + return ret; + + } else { + elem.setAttribute( name, value + "" ); + return value; + } + + } else if ( hooks && notxml && "get" in hooks && (ret = hooks.get( elem, name )) !== null ) { + return ret; + + } else { + + // In IE9+, Flash objects don't have .getAttribute (#12945) + // Support: IE9+ + if ( typeof elem.getAttribute !== "undefined" ) { + ret = elem.getAttribute( name ); + } + + // Non-existent attributes return null, we normalize to undefined + return ret == null ? + undefined : + ret; + } + }, + + removeAttr: function( elem, value ) { + var name, propName, + i = 0, + attrNames = value && value.match( core_rnotwhite ); + + if ( attrNames && elem.nodeType === 1 ) { + while ( (name = attrNames[i++]) ) { + propName = jQuery.propFix[ name ] || name; + + // Boolean attributes get special treatment (#10870) + if ( rboolean.test( name ) ) { + // Set corresponding property to false for boolean attributes + // Also clear defaultChecked/defaultSelected (if appropriate) for IE<8 + if ( !getSetAttribute && ruseDefault.test( name ) ) { + elem[ jQuery.camelCase( "default-" + name ) ] = + elem[ propName ] = false; + } else { + elem[ propName ] = false; + } + + // See #9699 for explanation of this approach (setting first, then removal) + } else { + jQuery.attr( elem, name, "" ); + } + + elem.removeAttribute( getSetAttribute ? name : propName ); + } + } + }, + + attrHooks: { + type: { + set: function( elem, value ) { + if ( !jQuery.support.radioValue && value === "radio" && jQuery.nodeName(elem, "input") ) { + // Setting the type on a radio button after the value resets the value in IE6-9 + // Reset value to default in case type is set after value during creation + var val = elem.value; + elem.setAttribute( "type", value ); + if ( val ) { + elem.value = val; + } + return value; + } + } + } + }, + + propFix: { + tabindex: "tabIndex", + readonly: "readOnly", + "for": "htmlFor", + "class": "className", + maxlength: "maxLength", + cellspacing: "cellSpacing", + cellpadding: "cellPadding", + rowspan: "rowSpan", + colspan: "colSpan", + usemap: "useMap", + frameborder: "frameBorder", + contenteditable: "contentEditable" + }, + + prop: function( elem, name, value ) { + var ret, hooks, notxml, + nType = elem.nodeType; + + // don't get/set properties on text, comment and attribute nodes + if ( !elem || nType === 3 || nType === 8 || nType === 2 ) { + return; + } + + notxml = nType !== 1 || !jQuery.isXMLDoc( elem ); + + if ( notxml ) { + // Fix name and attach hooks + name = jQuery.propFix[ name ] || name; + hooks = jQuery.propHooks[ name ]; + } + + if ( value !== undefined ) { + if ( hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ) { + return ret; + + } else { + return ( elem[ name ] = value ); + } + + } else { + if ( hooks && "get" in hooks && (ret = hooks.get( elem, name )) !== null ) { + return ret; + + } else { + return elem[ name ]; + } + } + }, + + propHooks: { + tabIndex: { + get: function( elem ) { + // elem.tabIndex doesn't always return the correct value when it hasn't been explicitly set + // http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/ + var attributeNode = elem.getAttributeNode("tabindex"); + + return attributeNode && attributeNode.specified ? + parseInt( attributeNode.value, 10 ) : + rfocusable.test( elem.nodeName ) || rclickable.test( elem.nodeName ) && elem.href ? + 0 : + undefined; + } + } + } +}); + +// Hook for boolean attributes +boolHook = { + get: function( elem, name ) { + var + // Use .prop to determine if this attribute is understood as boolean + prop = jQuery.prop( elem, name ), + + // Fetch it accordingly + attr = typeof prop === "boolean" && elem.getAttribute( name ), + detail = typeof prop === "boolean" ? + + getSetInput && getSetAttribute ? + attr != null : + // oldIE fabricates an empty string for missing boolean attributes + // and conflates checked/selected into attroperties + ruseDefault.test( name ) ? + elem[ jQuery.camelCase( "default-" + name ) ] : + !!attr : + + // fetch an attribute node for properties not recognized as boolean + elem.getAttributeNode( name ); + + return detail && detail.value !== false ? + name.toLowerCase() : + undefined; + }, + set: function( elem, value, name ) { + if ( value === false ) { + // Remove boolean attributes when set to false + jQuery.removeAttr( elem, name ); + } else if ( getSetInput && getSetAttribute || !ruseDefault.test( name ) ) { + // IE<8 needs the *property* name + elem.setAttribute( !getSetAttribute && jQuery.propFix[ name ] || name, name ); + + // Use defaultChecked and defaultSelected for oldIE + } else { + elem[ jQuery.camelCase( "default-" + name ) ] = elem[ name ] = true; + } + + return name; + } +}; + +// fix oldIE value attroperty +if ( !getSetInput || !getSetAttribute ) { + jQuery.attrHooks.value = { + get: function( elem, name ) { + var ret = elem.getAttributeNode( name ); + return jQuery.nodeName( elem, "input" ) ? + + // Ignore the value *property* by using defaultValue + elem.defaultValue : + + ret && ret.specified ? ret.value : undefined; + }, + set: function( elem, value, name ) { + if ( jQuery.nodeName( elem, "input" ) ) { + // Does not return so that setAttribute is also used + elem.defaultValue = value; + } else { + // Use nodeHook if defined (#1954); otherwise setAttribute is fine + return nodeHook && nodeHook.set( elem, value, name ); + } + } + }; +} + +// IE6/7 do not support getting/setting some attributes with get/setAttribute +if ( !getSetAttribute ) { + + // Use this for any attribute in IE6/7 + // This fixes almost every IE6/7 issue + nodeHook = jQuery.valHooks.button = { + get: function( elem, name ) { + var ret = elem.getAttributeNode( name ); + return ret && ( name === "id" || name === "name" || name === "coords" ? ret.value !== "" : ret.specified ) ? + ret.value : + undefined; + }, + set: function( elem, value, name ) { + // Set the existing or create a new attribute node + var ret = elem.getAttributeNode( name ); + if ( !ret ) { + elem.setAttributeNode( + (ret = elem.ownerDocument.createAttribute( name )) + ); + } + + ret.value = value += ""; + + // Break association with cloned elements by also using setAttribute (#9646) + return name === "value" || value === elem.getAttribute( name ) ? + value : + undefined; + } + }; + + // Set contenteditable to false on removals(#10429) + // Setting to empty string throws an error as an invalid value + jQuery.attrHooks.contenteditable = { + get: nodeHook.get, + set: function( elem, value, name ) { + nodeHook.set( elem, value === "" ? false : value, name ); + } + }; + + // Set width and height to auto instead of 0 on empty string( Bug #8150 ) + // This is for removals + jQuery.each([ "width", "height" ], function( i, name ) { + jQuery.attrHooks[ name ] = jQuery.extend( jQuery.attrHooks[ name ], { + set: function( elem, value ) { + if ( value === "" ) { + elem.setAttribute( name, "auto" ); + return value; + } + } + }); + }); +} + + +// Some attributes require a special call on IE +// http://msdn.microsoft.com/en-us/library/ms536429%28VS.85%29.aspx +if ( !jQuery.support.hrefNormalized ) { + jQuery.each([ "href", "src", "width", "height" ], function( i, name ) { + jQuery.attrHooks[ name ] = jQuery.extend( jQuery.attrHooks[ name ], { + get: function( elem ) { + var ret = elem.getAttribute( name, 2 ); + return ret == null ? undefined : ret; + } + }); + }); + + // href/src property should get the full normalized URL (#10299/#12915) + jQuery.each([ "href", "src" ], function( i, name ) { + jQuery.propHooks[ name ] = { + get: function( elem ) { + return elem.getAttribute( name, 4 ); + } + }; + }); +} + +if ( !jQuery.support.style ) { + jQuery.attrHooks.style = { + get: function( elem ) { + // Return undefined in the case of empty string + // Note: IE uppercases css property names, but if we were to .toLowerCase() + // .cssText, that would destroy case senstitivity in URL's, like in "background" + return elem.style.cssText || undefined; + }, + set: function( elem, value ) { + return ( elem.style.cssText = value + "" ); + } + }; +} + +// Safari mis-reports the default selected property of an option +// Accessing the parent's selectedIndex property fixes it +if ( !jQuery.support.optSelected ) { + jQuery.propHooks.selected = jQuery.extend( jQuery.propHooks.selected, { + get: function( elem ) { + var parent = elem.parentNode; + + if ( parent ) { + parent.selectedIndex; + + // Make sure that it also works with optgroups, see #5701 + if ( parent.parentNode ) { + parent.parentNode.selectedIndex; + } + } + return null; + } + }); +} + +// IE6/7 call enctype encoding +if ( !jQuery.support.enctype ) { + jQuery.propFix.enctype = "encoding"; +} + +// Radios and checkboxes getter/setter +if ( !jQuery.support.checkOn ) { + jQuery.each([ "radio", "checkbox" ], function() { + jQuery.valHooks[ this ] = { + get: function( elem ) { + // Handle the case where in Webkit "" is returned instead of "on" if a value isn't specified + return elem.getAttribute("value") === null ? "on" : elem.value; + } + }; + }); +} +jQuery.each([ "radio", "checkbox" ], function() { + jQuery.valHooks[ this ] = jQuery.extend( jQuery.valHooks[ this ], { + set: function( elem, value ) { + if ( jQuery.isArray( value ) ) { + return ( elem.checked = jQuery.inArray( jQuery(elem).val(), value ) >= 0 ); + } + } + }); +}); +var rformElems = /^(?:input|select|textarea)$/i, + rkeyEvent = /^key/, + rmouseEvent = /^(?:mouse|contextmenu)|click/, + rfocusMorph = /^(?:focusinfocus|focusoutblur)$/, + rtypenamespace = /^([^.]*)(?:\.(.+)|)$/; + +function returnTrue() { + return true; +} + +function returnFalse() { + return false; +} + +/* + * Helper functions for managing events -- not part of the public interface. + * Props to Dean Edwards' addEvent library for many of the ideas. + */ +jQuery.event = { + + global: {}, + + add: function( elem, types, handler, data, selector ) { + + var handleObjIn, eventHandle, tmp, + events, t, handleObj, + special, handlers, type, namespaces, origType, + // Don't attach events to noData or text/comment nodes (but allow plain objects) + elemData = elem.nodeType !== 3 && elem.nodeType !== 8 && jQuery._data( elem ); + + if ( !elemData ) { + return; + } + + // Caller can pass in an object of custom data in lieu of the handler + if ( handler.handler ) { + handleObjIn = handler; + handler = handleObjIn.handler; + selector = handleObjIn.selector; + } + + // Make sure that the handler has a unique ID, used to find/remove it later + if ( !handler.guid ) { + handler.guid = jQuery.guid++; + } + + // Init the element's event structure and main handler, if this is the first + if ( !(events = elemData.events) ) { + events = elemData.events = {}; + } + if ( !(eventHandle = elemData.handle) ) { + eventHandle = elemData.handle = function( e ) { + // Discard the second event of a jQuery.event.trigger() and + // when an event is called after a page has unloaded + return typeof jQuery !== "undefined" && (!e || jQuery.event.triggered !== e.type) ? + jQuery.event.dispatch.apply( eventHandle.elem, arguments ) : + undefined; + }; + // Add elem as a property of the handle fn to prevent a memory leak with IE non-native events + eventHandle.elem = elem; + } + + // Handle multiple events separated by a space + // jQuery(...).bind("mouseover mouseout", fn); + types = ( types || "" ).match( core_rnotwhite ) || [""]; + t = types.length; + while ( t-- ) { + tmp = rtypenamespace.exec( types[t] ) || []; + type = origType = tmp[1]; + namespaces = ( tmp[2] || "" ).split( "." ).sort(); + + // If event changes its type, use the special event handlers for the changed type + special = jQuery.event.special[ type ] || {}; + + // If selector defined, determine special event api type, otherwise given type + type = ( selector ? special.delegateType : special.bindType ) || type; + + // Update special based on newly reset type + special = jQuery.event.special[ type ] || {}; + + // handleObj is passed to all event handlers + handleObj = jQuery.extend({ + type: type, + origType: origType, + data: data, + handler: handler, + guid: handler.guid, + selector: selector, + needsContext: selector && jQuery.expr.match.needsContext.test( selector ), + namespace: namespaces.join(".") + }, handleObjIn ); + + // Init the event handler queue if we're the first + if ( !(handlers = events[ type ]) ) { + handlers = events[ type ] = []; + handlers.delegateCount = 0; + + // Only use addEventListener/attachEvent if the special events handler returns false + if ( !special.setup || special.setup.call( elem, data, namespaces, eventHandle ) === false ) { + // Bind the global event handler to the element + if ( elem.addEventListener ) { + elem.addEventListener( type, eventHandle, false ); + + } else if ( elem.attachEvent ) { + elem.attachEvent( "on" + type, eventHandle ); + } + } + } + + if ( special.add ) { + special.add.call( elem, handleObj ); + + if ( !handleObj.handler.guid ) { + handleObj.handler.guid = handler.guid; + } + } + + // Add to the element's handler list, delegates in front + if ( selector ) { + handlers.splice( handlers.delegateCount++, 0, handleObj ); + } else { + handlers.push( handleObj ); + } + + // Keep track of which events have ever been used, for event optimization + jQuery.event.global[ type ] = true; + } + + // Nullify elem to prevent memory leaks in IE + elem = null; + }, + + // Detach an event or set of events from an element + remove: function( elem, types, handler, selector, mappedTypes ) { + + var j, origCount, tmp, + events, t, handleObj, + special, handlers, type, namespaces, origType, + elemData = jQuery.hasData( elem ) && jQuery._data( elem ); + + if ( !elemData || !(events = elemData.events) ) { + return; + } + + // Once for each type.namespace in types; type may be omitted + types = ( types || "" ).match( core_rnotwhite ) || [""]; + t = types.length; + while ( t-- ) { + tmp = rtypenamespace.exec( types[t] ) || []; + type = origType = tmp[1]; + namespaces = ( tmp[2] || "" ).split( "." ).sort(); + + // Unbind all events (on this namespace, if provided) for the element + if ( !type ) { + for ( type in events ) { + jQuery.event.remove( elem, type + types[ t ], handler, selector, true ); + } + continue; + } + + special = jQuery.event.special[ type ] || {}; + type = ( selector ? special.delegateType : special.bindType ) || type; + handlers = events[ type ] || []; + tmp = tmp[2] && new RegExp( "(^|\\.)" + namespaces.join("\\.(?:.*\\.|)") + "(\\.|$)" ); + + // Remove matching events + origCount = j = handlers.length; + while ( j-- ) { + handleObj = handlers[ j ]; + + if ( ( mappedTypes || origType === handleObj.origType ) && + ( !handler || handler.guid === handleObj.guid ) && + ( !tmp || tmp.test( handleObj.namespace ) ) && + ( !selector || selector === handleObj.selector || selector === "**" && handleObj.selector ) ) { + handlers.splice( j, 1 ); + + if ( handleObj.selector ) { + handlers.delegateCount--; + } + if ( special.remove ) { + special.remove.call( elem, handleObj ); + } + } + } + + // Remove generic event handler if we removed something and no more handlers exist + // (avoids potential for endless recursion during removal of special event handlers) + if ( origCount && !handlers.length ) { + if ( !special.teardown || special.teardown.call( elem, namespaces, elemData.handle ) === false ) { + jQuery.removeEvent( elem, type, elemData.handle ); + } + + delete events[ type ]; + } + } + + // Remove the expando if it's no longer used + if ( jQuery.isEmptyObject( events ) ) { + delete elemData.handle; + + // removeData also checks for emptiness and clears the expando if empty + // so use it instead of delete + jQuery._removeData( elem, "events" ); + } + }, + + trigger: function( event, data, elem, onlyHandlers ) { + + var i, cur, tmp, bubbleType, ontype, handle, special, + eventPath = [ elem || document ], + type = event.type || event, + namespaces = event.namespace ? event.namespace.split(".") : []; + + cur = tmp = elem = elem || document; + + // Don't do events on text and comment nodes + if ( elem.nodeType === 3 || elem.nodeType === 8 ) { + return; + } + + // focus/blur morphs to focusin/out; ensure we're not firing them right now + if ( rfocusMorph.test( type + jQuery.event.triggered ) ) { + return; + } + + if ( type.indexOf(".") >= 0 ) { + // Namespaced trigger; create a regexp to match event type in handle() + namespaces = type.split("."); + type = namespaces.shift(); + namespaces.sort(); + } + ontype = type.indexOf(":") < 0 && "on" + type; + + // Caller can pass in a jQuery.Event object, Object, or just an event type string + event = event[ jQuery.expando ] ? + event : + new jQuery.Event( type, typeof event === "object" && event ); + + event.isTrigger = true; + event.namespace = namespaces.join("."); + event.namespace_re = event.namespace ? + new RegExp( "(^|\\.)" + namespaces.join("\\.(?:.*\\.|)") + "(\\.|$)" ) : + null; + + // Clean up the event in case it is being reused + event.result = undefined; + if ( !event.target ) { + event.target = elem; + } + + // Clone any incoming data and prepend the event, creating the handler arg list + data = data == null ? + [ event ] : + jQuery.makeArray( data, [ event ] ); + + // Allow special events to draw outside the lines + special = jQuery.event.special[ type ] || {}; + if ( !onlyHandlers && special.trigger && special.trigger.apply( elem, data ) === false ) { + return; + } + + // Determine event propagation path in advance, per W3C events spec (#9951) + // Bubble up to document, then to window; watch for a global ownerDocument var (#9724) + if ( !onlyHandlers && !special.noBubble && !jQuery.isWindow( elem ) ) { + + bubbleType = special.delegateType || type; + if ( !rfocusMorph.test( bubbleType + type ) ) { + cur = cur.parentNode; + } + for ( ; cur; cur = cur.parentNode ) { + eventPath.push( cur ); + tmp = cur; + } + + // Only add window if we got to document (e.g., not plain obj or detached DOM) + if ( tmp === (elem.ownerDocument || document) ) { + eventPath.push( tmp.defaultView || tmp.parentWindow || window ); + } + } + + // Fire handlers on the event path + i = 0; + while ( (cur = eventPath[i++]) && !event.isPropagationStopped() ) { + + event.type = i > 1 ? + bubbleType : + special.bindType || type; + + // jQuery handler + handle = ( jQuery._data( cur, "events" ) || {} )[ event.type ] && jQuery._data( cur, "handle" ); + if ( handle ) { + handle.apply( cur, data ); + } + + // Native handler + handle = ontype && cur[ ontype ]; + if ( handle && jQuery.acceptData( cur ) && handle.apply && handle.apply( cur, data ) === false ) { + event.preventDefault(); + } + } + event.type = type; + + // If nobody prevented the default action, do it now + if ( !onlyHandlers && !event.isDefaultPrevented() ) { + + if ( (!special._default || special._default.apply( elem.ownerDocument, data ) === false) && + !(type === "click" && jQuery.nodeName( elem, "a" )) && jQuery.acceptData( elem ) ) { + + // Call a native DOM method on the target with the same name name as the event. + // Can't use an .isFunction() check here because IE6/7 fails that test. + // Don't do default actions on window, that's where global variables be (#6170) + if ( ontype && elem[ type ] && !jQuery.isWindow( elem ) ) { + + // Don't re-trigger an onFOO event when we call its FOO() method + tmp = elem[ ontype ]; + + if ( tmp ) { + elem[ ontype ] = null; + } + + // Prevent re-triggering of the same event, since we already bubbled it above + jQuery.event.triggered = type; + try { + elem[ type ](); + } catch ( e ) { + // IE<9 dies on focus/blur to hidden element (#1486,#12518) + // only reproducible on winXP IE8 native, not IE9 in IE8 mode + } + jQuery.event.triggered = undefined; + + if ( tmp ) { + elem[ ontype ] = tmp; + } + } + } + } + + return event.result; + }, + + dispatch: function( event ) { + + // Make a writable jQuery.Event from the native event object + event = jQuery.event.fix( event ); + + var i, j, ret, matched, handleObj, + handlerQueue = [], + args = core_slice.call( arguments ), + handlers = ( jQuery._data( this, "events" ) || {} )[ event.type ] || [], + special = jQuery.event.special[ event.type ] || {}; + + // Use the fix-ed jQuery.Event rather than the (read-only) native event + args[0] = event; + event.delegateTarget = this; + + // Call the preDispatch hook for the mapped type, and let it bail if desired + if ( special.preDispatch && special.preDispatch.call( this, event ) === false ) { + return; + } + + // Determine handlers + handlerQueue = jQuery.event.handlers.call( this, event, handlers ); + + // Run delegates first; they may want to stop propagation beneath us + i = 0; + while ( (matched = handlerQueue[ i++ ]) && !event.isPropagationStopped() ) { + event.currentTarget = matched.elem; + + j = 0; + while ( (handleObj = matched.handlers[ j++ ]) && !event.isImmediatePropagationStopped() ) { + + // Triggered event must either 1) have no namespace, or + // 2) have namespace(s) a subset or equal to those in the bound event (both can have no namespace). + if ( !event.namespace_re || event.namespace_re.test( handleObj.namespace ) ) { + + event.handleObj = handleObj; + event.data = handleObj.data; + + ret = ( (jQuery.event.special[ handleObj.origType ] || {}).handle || handleObj.handler ) + .apply( matched.elem, args ); + + if ( ret !== undefined ) { + if ( (event.result = ret) === false ) { + event.preventDefault(); + event.stopPropagation(); + } + } + } + } + } + + // Call the postDispatch hook for the mapped type + if ( special.postDispatch ) { + special.postDispatch.call( this, event ); + } + + return event.result; + }, + + handlers: function( event, handlers ) { + var i, matches, sel, handleObj, + handlerQueue = [], + delegateCount = handlers.delegateCount, + cur = event.target; + + // Find delegate handlers + // Black-hole SVG instance trees (#13180) + // Avoid non-left-click bubbling in Firefox (#3861) + if ( delegateCount && cur.nodeType && (!event.button || event.type !== "click") ) { + + for ( ; cur != this; cur = cur.parentNode || this ) { + + // Don't process clicks on disabled elements (#6911, #8165, #11382, #11764) + if ( cur.disabled !== true || event.type !== "click" ) { + matches = []; + for ( i = 0; i < delegateCount; i++ ) { + handleObj = handlers[ i ]; + + // Don't conflict with Object.prototype properties (#13203) + sel = handleObj.selector + " "; + + if ( matches[ sel ] === undefined ) { + matches[ sel ] = handleObj.needsContext ? + jQuery( sel, this ).index( cur ) >= 0 : + jQuery.find( sel, this, null, [ cur ] ).length; + } + if ( matches[ sel ] ) { + matches.push( handleObj ); + } + } + if ( matches.length ) { + handlerQueue.push({ elem: cur, handlers: matches }); + } + } + } + } + + // Add the remaining (directly-bound) handlers + if ( delegateCount < handlers.length ) { + handlerQueue.push({ elem: this, handlers: handlers.slice( delegateCount ) }); + } + + return handlerQueue; + }, + + fix: function( event ) { + if ( event[ jQuery.expando ] ) { + return event; + } + + // Create a writable copy of the event object and normalize some properties + var i, prop, + originalEvent = event, + fixHook = jQuery.event.fixHooks[ event.type ] || {}, + copy = fixHook.props ? this.props.concat( fixHook.props ) : this.props; + + event = new jQuery.Event( originalEvent ); + + i = copy.length; + while ( i-- ) { + prop = copy[ i ]; + event[ prop ] = originalEvent[ prop ]; + } + + // Support: IE<9 + // Fix target property (#1925) + if ( !event.target ) { + event.target = originalEvent.srcElement || document; + } + + // Support: Chrome 23+, Safari? + // Target should not be a text node (#504, #13143) + if ( event.target.nodeType === 3 ) { + event.target = event.target.parentNode; + } + + // Support: IE<9 + // For mouse/key events, metaKey==false if it's undefined (#3368, #11328) + event.metaKey = !!event.metaKey; + + return fixHook.filter ? fixHook.filter( event, originalEvent ) : event; + }, + + // Includes some event props shared by KeyEvent and MouseEvent + props: "altKey bubbles cancelable ctrlKey currentTarget eventPhase metaKey relatedTarget shiftKey target timeStamp view which".split(" "), + + fixHooks: {}, + + keyHooks: { + props: "char charCode key keyCode".split(" "), + filter: function( event, original ) { + + // Add which for key events + if ( event.which == null ) { + event.which = original.charCode != null ? original.charCode : original.keyCode; + } + + return event; + } + }, + + mouseHooks: { + props: "button buttons clientX clientY fromElement offsetX offsetY pageX pageY screenX screenY toElement".split(" "), + filter: function( event, original ) { + var eventDoc, doc, body, + button = original.button, + fromElement = original.fromElement; + + // Calculate pageX/Y if missing and clientX/Y available + if ( event.pageX == null && original.clientX != null ) { + eventDoc = event.target.ownerDocument || document; + doc = eventDoc.documentElement; + body = eventDoc.body; + + event.pageX = original.clientX + ( doc && doc.scrollLeft || body && body.scrollLeft || 0 ) - ( doc && doc.clientLeft || body && body.clientLeft || 0 ); + event.pageY = original.clientY + ( doc && doc.scrollTop || body && body.scrollTop || 0 ) - ( doc && doc.clientTop || body && body.clientTop || 0 ); + } + + // Add relatedTarget, if necessary + if ( !event.relatedTarget && fromElement ) { + event.relatedTarget = fromElement === event.target ? original.toElement : fromElement; + } + + // Add which for click: 1 === left; 2 === middle; 3 === right + // Note: button is not normalized, so don't use it + if ( !event.which && button !== undefined ) { + event.which = ( button & 1 ? 1 : ( button & 2 ? 3 : ( button & 4 ? 2 : 0 ) ) ); + } + + return event; + } + }, + + special: { + load: { + // Prevent triggered image.load events from bubbling to window.load + noBubble: true + }, + click: { + // For checkbox, fire native event so checked state will be right + trigger: function() { + if ( jQuery.nodeName( this, "input" ) && this.type === "checkbox" && this.click ) { + this.click(); + return false; + } + } + }, + focus: { + // Fire native event if possible so blur/focus sequence is correct + trigger: function() { + if ( this !== document.activeElement && this.focus ) { + try { + this.focus(); + return false; + } catch ( e ) { + // Support: IE<9 + // If we error on focus to hidden element (#1486, #12518), + // let .trigger() run the handlers + } + } + }, + delegateType: "focusin" + }, + blur: { + trigger: function() { + if ( this === document.activeElement && this.blur ) { + this.blur(); + return false; + } + }, + delegateType: "focusout" + }, + + beforeunload: { + postDispatch: function( event ) { + + // Even when returnValue equals to undefined Firefox will still show alert + if ( event.result !== undefined ) { + event.originalEvent.returnValue = event.result; + } + } + } + }, + + simulate: function( type, elem, event, bubble ) { + // Piggyback on a donor event to simulate a different one. + // Fake originalEvent to avoid donor's stopPropagation, but if the + // simulated event prevents default then we do the same on the donor. + var e = jQuery.extend( + new jQuery.Event(), + event, + { type: type, + isSimulated: true, + originalEvent: {} + } + ); + if ( bubble ) { + jQuery.event.trigger( e, null, elem ); + } else { + jQuery.event.dispatch.call( elem, e ); + } + if ( e.isDefaultPrevented() ) { + event.preventDefault(); + } + } +}; + +jQuery.removeEvent = document.removeEventListener ? + function( elem, type, handle ) { + if ( elem.removeEventListener ) { + elem.removeEventListener( type, handle, false ); + } + } : + function( elem, type, handle ) { + var name = "on" + type; + + if ( elem.detachEvent ) { + + // #8545, #7054, preventing memory leaks for custom events in IE6-8 + // detachEvent needed property on element, by name of that event, to properly expose it to GC + if ( typeof elem[ name ] === "undefined" ) { + elem[ name ] = null; + } + + elem.detachEvent( name, handle ); + } + }; + +jQuery.Event = function( src, props ) { + // Allow instantiation without the 'new' keyword + if ( !(this instanceof jQuery.Event) ) { + return new jQuery.Event( src, props ); + } + + // Event object + if ( src && src.type ) { + this.originalEvent = src; + this.type = src.type; + + // Events bubbling up the document may have been marked as prevented + // by a handler lower down the tree; reflect the correct value. + this.isDefaultPrevented = ( src.defaultPrevented || src.returnValue === false || + src.getPreventDefault && src.getPreventDefault() ) ? returnTrue : returnFalse; + + // Event type + } else { + this.type = src; + } + + // Put explicitly provided properties onto the event object + if ( props ) { + jQuery.extend( this, props ); + } + + // Create a timestamp if incoming event doesn't have one + this.timeStamp = src && src.timeStamp || jQuery.now(); + + // Mark it as fixed + this[ jQuery.expando ] = true; +}; + +// jQuery.Event is based on DOM3 Events as specified by the ECMAScript Language Binding +// http://www.w3.org/TR/2003/WD-DOM-Level-3-Events-20030331/ecma-script-binding.html +jQuery.Event.prototype = { + isDefaultPrevented: returnFalse, + isPropagationStopped: returnFalse, + isImmediatePropagationStopped: returnFalse, + + preventDefault: function() { + var e = this.originalEvent; + + this.isDefaultPrevented = returnTrue; + if ( !e ) { + return; + } + + // If preventDefault exists, run it on the original event + if ( e.preventDefault ) { + e.preventDefault(); + + // Support: IE + // Otherwise set the returnValue property of the original event to false + } else { + e.returnValue = false; + } + }, + stopPropagation: function() { + var e = this.originalEvent; + + this.isPropagationStopped = returnTrue; + if ( !e ) { + return; + } + // If stopPropagation exists, run it on the original event + if ( e.stopPropagation ) { + e.stopPropagation(); + } + + // Support: IE + // Set the cancelBubble property of the original event to true + e.cancelBubble = true; + }, + stopImmediatePropagation: function() { + this.isImmediatePropagationStopped = returnTrue; + this.stopPropagation(); + } +}; + +// Create mouseenter/leave events using mouseover/out and event-time checks +jQuery.each({ + mouseenter: "mouseover", + mouseleave: "mouseout" +}, function( orig, fix ) { + jQuery.event.special[ orig ] = { + delegateType: fix, + bindType: fix, + + handle: function( event ) { + var ret, + target = this, + related = event.relatedTarget, + handleObj = event.handleObj; + + // For mousenter/leave call the handler if related is outside the target. + // NB: No relatedTarget if the mouse left/entered the browser window + if ( !related || (related !== target && !jQuery.contains( target, related )) ) { + event.type = handleObj.origType; + ret = handleObj.handler.apply( this, arguments ); + event.type = fix; + } + return ret; + } + }; +}); + +// IE submit delegation +if ( !jQuery.support.submitBubbles ) { + + jQuery.event.special.submit = { + setup: function() { + // Only need this for delegated form submit events + if ( jQuery.nodeName( this, "form" ) ) { + return false; + } + + // Lazy-add a submit handler when a descendant form may potentially be submitted + jQuery.event.add( this, "click._submit keypress._submit", function( e ) { + // Node name check avoids a VML-related crash in IE (#9807) + var elem = e.target, + form = jQuery.nodeName( elem, "input" ) || jQuery.nodeName( elem, "button" ) ? elem.form : undefined; + if ( form && !jQuery._data( form, "submitBubbles" ) ) { + jQuery.event.add( form, "submit._submit", function( event ) { + event._submit_bubble = true; + }); + jQuery._data( form, "submitBubbles", true ); + } + }); + // return undefined since we don't need an event listener + }, + + postDispatch: function( event ) { + // If form was submitted by the user, bubble the event up the tree + if ( event._submit_bubble ) { + delete event._submit_bubble; + if ( this.parentNode && !event.isTrigger ) { + jQuery.event.simulate( "submit", this.parentNode, event, true ); + } + } + }, + + teardown: function() { + // Only need this for delegated form submit events + if ( jQuery.nodeName( this, "form" ) ) { + return false; + } + + // Remove delegated handlers; cleanData eventually reaps submit handlers attached above + jQuery.event.remove( this, "._submit" ); + } + }; +} + +// IE change delegation and checkbox/radio fix +if ( !jQuery.support.changeBubbles ) { + + jQuery.event.special.change = { + + setup: function() { + + if ( rformElems.test( this.nodeName ) ) { + // IE doesn't fire change on a check/radio until blur; trigger it on click + // after a propertychange. Eat the blur-change in special.change.handle. + // This still fires onchange a second time for check/radio after blur. + if ( this.type === "checkbox" || this.type === "radio" ) { + jQuery.event.add( this, "propertychange._change", function( event ) { + if ( event.originalEvent.propertyName === "checked" ) { + this._just_changed = true; + } + }); + jQuery.event.add( this, "click._change", function( event ) { + if ( this._just_changed && !event.isTrigger ) { + this._just_changed = false; + } + // Allow triggered, simulated change events (#11500) + jQuery.event.simulate( "change", this, event, true ); + }); + } + return false; + } + // Delegated event; lazy-add a change handler on descendant inputs + jQuery.event.add( this, "beforeactivate._change", function( e ) { + var elem = e.target; + + if ( rformElems.test( elem.nodeName ) && !jQuery._data( elem, "changeBubbles" ) ) { + jQuery.event.add( elem, "change._change", function( event ) { + if ( this.parentNode && !event.isSimulated && !event.isTrigger ) { + jQuery.event.simulate( "change", this.parentNode, event, true ); + } + }); + jQuery._data( elem, "changeBubbles", true ); + } + }); + }, + + handle: function( event ) { + var elem = event.target; + + // Swallow native change events from checkbox/radio, we already triggered them above + if ( this !== elem || event.isSimulated || event.isTrigger || (elem.type !== "radio" && elem.type !== "checkbox") ) { + return event.handleObj.handler.apply( this, arguments ); + } + }, + + teardown: function() { + jQuery.event.remove( this, "._change" ); + + return !rformElems.test( this.nodeName ); + } + }; +} + +// Create "bubbling" focus and blur events +if ( !jQuery.support.focusinBubbles ) { + jQuery.each({ focus: "focusin", blur: "focusout" }, function( orig, fix ) { + + // Attach a single capturing handler while someone wants focusin/focusout + var attaches = 0, + handler = function( event ) { + jQuery.event.simulate( fix, event.target, jQuery.event.fix( event ), true ); + }; + + jQuery.event.special[ fix ] = { + setup: function() { + if ( attaches++ === 0 ) { + document.addEventListener( orig, handler, true ); + } + }, + teardown: function() { + if ( --attaches === 0 ) { + document.removeEventListener( orig, handler, true ); + } + } + }; + }); +} + +jQuery.fn.extend({ + + on: function( types, selector, data, fn, /*INTERNAL*/ one ) { + var origFn, type; + + // Types can be a map of types/handlers + if ( typeof types === "object" ) { + // ( types-Object, selector, data ) + if ( typeof selector !== "string" ) { + // ( types-Object, data ) + data = data || selector; + selector = undefined; + } + for ( type in types ) { + this.on( type, selector, data, types[ type ], one ); + } + return this; + } + + if ( data == null && fn == null ) { + // ( types, fn ) + fn = selector; + data = selector = undefined; + } else if ( fn == null ) { + if ( typeof selector === "string" ) { + // ( types, selector, fn ) + fn = data; + data = undefined; + } else { + // ( types, data, fn ) + fn = data; + data = selector; + selector = undefined; + } + } + if ( fn === false ) { + fn = returnFalse; + } else if ( !fn ) { + return this; + } + + if ( one === 1 ) { + origFn = fn; + fn = function( event ) { + // Can use an empty set, since event contains the info + jQuery().off( event ); + return origFn.apply( this, arguments ); + }; + // Use same guid so caller can remove using origFn + fn.guid = origFn.guid || ( origFn.guid = jQuery.guid++ ); + } + return this.each( function() { + jQuery.event.add( this, types, fn, data, selector ); + }); + }, + one: function( types, selector, data, fn ) { + return this.on( types, selector, data, fn, 1 ); + }, + off: function( types, selector, fn ) { + var handleObj, type; + if ( types && types.preventDefault && types.handleObj ) { + // ( event ) dispatched jQuery.Event + handleObj = types.handleObj; + jQuery( types.delegateTarget ).off( + handleObj.namespace ? handleObj.origType + "." + handleObj.namespace : handleObj.origType, + handleObj.selector, + handleObj.handler + ); + return this; + } + if ( typeof types === "object" ) { + // ( types-object [, selector] ) + for ( type in types ) { + this.off( type, selector, types[ type ] ); + } + return this; + } + if ( selector === false || typeof selector === "function" ) { + // ( types [, fn] ) + fn = selector; + selector = undefined; + } + if ( fn === false ) { + fn = returnFalse; + } + return this.each(function() { + jQuery.event.remove( this, types, fn, selector ); + }); + }, + + bind: function( types, data, fn ) { + return this.on( types, null, data, fn ); + }, + unbind: function( types, fn ) { + return this.off( types, null, fn ); + }, + + delegate: function( selector, types, data, fn ) { + return this.on( types, selector, data, fn ); + }, + undelegate: function( selector, types, fn ) { + // ( namespace ) or ( selector, types [, fn] ) + return arguments.length === 1 ? this.off( selector, "**" ) : this.off( types, selector || "**", fn ); + }, + + trigger: function( type, data ) { + return this.each(function() { + jQuery.event.trigger( type, data, this ); + }); + }, + triggerHandler: function( type, data ) { + var elem = this[0]; + if ( elem ) { + return jQuery.event.trigger( type, data, elem, true ); + } + }, + + hover: function( fnOver, fnOut ) { + return this.mouseenter( fnOver ).mouseleave( fnOut || fnOver ); + } +}); + +jQuery.each( ("blur focus focusin focusout load resize scroll unload click dblclick " + + "mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " + + "change select submit keydown keypress keyup error contextmenu").split(" "), function( i, name ) { + + // Handle event binding + jQuery.fn[ name ] = function( data, fn ) { + return arguments.length > 0 ? + this.on( name, null, data, fn ) : + this.trigger( name ); + }; + + if ( rkeyEvent.test( name ) ) { + jQuery.event.fixHooks[ name ] = jQuery.event.keyHooks; + } + + if ( rmouseEvent.test( name ) ) { + jQuery.event.fixHooks[ name ] = jQuery.event.mouseHooks; + } +}); +/*! + * Sizzle CSS Selector Engine + * Copyright 2012 jQuery Foundation and other contributors + * Released under the MIT license + * http://sizzlejs.com/ + */ +(function( window, undefined ) { + +var i, + cachedruns, + Expr, + getText, + isXML, + compile, + hasDuplicate, + outermostContext, + + // Local document vars + setDocument, + document, + docElem, + documentIsXML, + rbuggyQSA, + rbuggyMatches, + matches, + contains, + sortOrder, + + // Instance-specific data + expando = "sizzle" + -(new Date()), + preferredDoc = window.document, + support = {}, + dirruns = 0, + done = 0, + classCache = createCache(), + tokenCache = createCache(), + compilerCache = createCache(), + + // General-purpose constants + strundefined = typeof undefined, + MAX_NEGATIVE = 1 << 31, + + // Array methods + arr = [], + pop = arr.pop, + push = arr.push, + slice = arr.slice, + // Use a stripped-down indexOf if we can't use a native one + indexOf = arr.indexOf || function( elem ) { + var i = 0, + len = this.length; + for ( ; i < len; i++ ) { + if ( this[i] === elem ) { + return i; + } + } + return -1; + }, + + + // Regular expressions + + // Whitespace characters http://www.w3.org/TR/css3-selectors/#whitespace + whitespace = "[\\x20\\t\\r\\n\\f]", + // http://www.w3.org/TR/css3-syntax/#characters + characterEncoding = "(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+", + + // Loosely modeled on CSS identifier characters + // An unquoted value should be a CSS identifier http://www.w3.org/TR/css3-selectors/#attribute-selectors + // Proper syntax: http://www.w3.org/TR/CSS21/syndata.html#value-def-identifier + identifier = characterEncoding.replace( "w", "w#" ), + + // Acceptable operators http://www.w3.org/TR/selectors/#attribute-selectors + operators = "([*^$|!~]?=)", + attributes = "\\[" + whitespace + "*(" + characterEncoding + ")" + whitespace + + "*(?:" + operators + whitespace + "*(?:(['\"])((?:\\\\.|[^\\\\])*?)\\3|(" + identifier + ")|)|)" + whitespace + "*\\]", + + // Prefer arguments quoted, + // then not containing pseudos/brackets, + // then attribute selectors/non-parenthetical expressions, + // then anything else + // These preferences are here to reduce the number of selectors + // needing tokenize in the PSEUDO preFilter + pseudos = ":(" + characterEncoding + ")(?:\\(((['\"])((?:\\\\.|[^\\\\])*?)\\3|((?:\\\\.|[^\\\\()[\\]]|" + attributes.replace( 3, 8 ) + ")*)|.*)\\)|)", + + // Leading and non-escaped trailing whitespace, capturing some non-whitespace characters preceding the latter + rtrim = new RegExp( "^" + whitespace + "+|((?:^|[^\\\\])(?:\\\\.)*)" + whitespace + "+$", "g" ), + + rcomma = new RegExp( "^" + whitespace + "*," + whitespace + "*" ), + rcombinators = new RegExp( "^" + whitespace + "*([\\x20\\t\\r\\n\\f>+~])" + whitespace + "*" ), + rpseudo = new RegExp( pseudos ), + ridentifier = new RegExp( "^" + identifier + "$" ), + + matchExpr = { + "ID": new RegExp( "^#(" + characterEncoding + ")" ), + "CLASS": new RegExp( "^\\.(" + characterEncoding + ")" ), + "NAME": new RegExp( "^\\[name=['\"]?(" + characterEncoding + ")['\"]?\\]" ), + "TAG": new RegExp( "^(" + characterEncoding.replace( "w", "w*" ) + ")" ), + "ATTR": new RegExp( "^" + attributes ), + "PSEUDO": new RegExp( "^" + pseudos ), + "CHILD": new RegExp( "^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\(" + whitespace + + "*(even|odd|(([+-]|)(\\d*)n|)" + whitespace + "*(?:([+-]|)" + whitespace + + "*(\\d+)|))" + whitespace + "*\\)|)", "i" ), + // For use in libraries implementing .is() + // We use this for POS matching in `select` + "needsContext": new RegExp( "^" + whitespace + "*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\(" + + whitespace + "*((?:-\\d)?\\d*)" + whitespace + "*\\)|)(?=[^-]|$)", "i" ) + }, + + rsibling = /[\x20\t\r\n\f]*[+~]/, + + rnative = /\{\s*\[native code\]\s*\}/, + + // Easily-parseable/retrievable ID or TAG or CLASS selectors + rquickExpr = /^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/, + + rinputs = /^(?:input|select|textarea|button)$/i, + rheader = /^h\d$/i, + + rescape = /'|\\/g, + rattributeQuotes = /\=[\x20\t\r\n\f]*([^'"\]]*)[\x20\t\r\n\f]*\]/g, + + // CSS escapes http://www.w3.org/TR/CSS21/syndata.html#escaped-characters + runescape = /\\([\da-fA-F]{1,6}[\x20\t\r\n\f]?|.)/g, + funescape = function( _, escaped ) { + var high = "0x" + escaped - 0x10000; + // NaN means non-codepoint + return high !== high ? + escaped : + // BMP codepoint + high < 0 ? + String.fromCharCode( high + 0x10000 ) : + // Supplemental Plane codepoint (surrogate pair) + String.fromCharCode( high >> 10 | 0xD800, high & 0x3FF | 0xDC00 ); + }; + +// Use a stripped-down slice if we can't use a native one +try { + slice.call( docElem.childNodes, 0 )[0].nodeType; +} catch ( e ) { + slice = function( i ) { + var elem, + results = []; + for ( ; (elem = this[i]); i++ ) { + results.push( elem ); + } + return results; + }; +} + +/** + * For feature detection + * @param {Function} fn The function to test for native support + */ +function isNative( fn ) { + return rnative.test( fn + "" ); +} + +/** + * Create key-value caches of limited size + * @returns {Function(string, Object)} Returns the Object data after storing it on itself with + * property name the (space-suffixed) string and (if the cache is larger than Expr.cacheLength) + * deleting the oldest entry + */ +function createCache() { + var cache, + keys = []; + + return (cache = function( key, value ) { + // Use (key + " ") to avoid collision with native prototype properties (see Issue #157) + if ( keys.push( key += " " ) > Expr.cacheLength ) { + // Only keep the most recent entries + delete cache[ keys.shift() ]; + } + return (cache[ key ] = value); + }); +} + +/** + * Mark a function for special use by Sizzle + * @param {Function} fn The function to mark + */ +function markFunction( fn ) { + fn[ expando ] = true; + return fn; +} + +/** + * Support testing using an element + * @param {Function} fn Passed the created div and expects a boolean result + */ +function assert( fn ) { + var div = document.createElement("div"); + + try { + return fn( div ); + } catch (e) { + return false; + } finally { + // release memory in IE + div = null; + } +} + +function Sizzle( selector, context, results, seed ) { + var match, elem, m, nodeType, + // QSA vars + i, groups, old, nid, newContext, newSelector; + + if ( ( context ? context.ownerDocument || context : preferredDoc ) !== document ) { + setDocument( context ); + } + + context = context || document; + results = results || []; + + if ( !selector || typeof selector !== "string" ) { + return results; + } + + if ( (nodeType = context.nodeType) !== 1 && nodeType !== 9 ) { + return []; + } + + if ( !documentIsXML && !seed ) { + + // Shortcuts + if ( (match = rquickExpr.exec( selector )) ) { + // Speed-up: Sizzle("#ID") + if ( (m = match[1]) ) { + if ( nodeType === 9 ) { + elem = context.getElementById( m ); + // Check parentNode to catch when Blackberry 4.6 returns + // nodes that are no longer in the document #6963 + if ( elem && elem.parentNode ) { + // Handle the case where IE, Opera, and Webkit return items + // by name instead of ID + if ( elem.id === m ) { + results.push( elem ); + return results; + } + } else { + return results; + } + } else { + // Context is not a document + if ( context.ownerDocument && (elem = context.ownerDocument.getElementById( m )) && + contains( context, elem ) && elem.id === m ) { + results.push( elem ); + return results; + } + } + + // Speed-up: Sizzle("TAG") + } else if ( match[2] ) { + push.apply( results, slice.call(context.getElementsByTagName( selector ), 0) ); + return results; + + // Speed-up: Sizzle(".CLASS") + } else if ( (m = match[3]) && support.getByClassName && context.getElementsByClassName ) { + push.apply( results, slice.call(context.getElementsByClassName( m ), 0) ); + return results; + } + } + + // QSA path + if ( support.qsa && !rbuggyQSA.test(selector) ) { + old = true; + nid = expando; + newContext = context; + newSelector = nodeType === 9 && selector; + + // qSA works strangely on Element-rooted queries + // We can work around this by specifying an extra ID on the root + // and working up from there (Thanks to Andrew Dupont for the technique) + // IE 8 doesn't work on object elements + if ( nodeType === 1 && context.nodeName.toLowerCase() !== "object" ) { + groups = tokenize( selector ); + + if ( (old = context.getAttribute("id")) ) { + nid = old.replace( rescape, "\\$&" ); + } else { + context.setAttribute( "id", nid ); + } + nid = "[id='" + nid + "'] "; + + i = groups.length; + while ( i-- ) { + groups[i] = nid + toSelector( groups[i] ); + } + newContext = rsibling.test( selector ) && context.parentNode || context; + newSelector = groups.join(","); + } + + if ( newSelector ) { + try { + push.apply( results, slice.call( newContext.querySelectorAll( + newSelector + ), 0 ) ); + return results; + } catch(qsaError) { + } finally { + if ( !old ) { + context.removeAttribute("id"); + } + } + } + } + } + + // All others + return select( selector.replace( rtrim, "$1" ), context, results, seed ); +} + +/** + * Detect xml + * @param {Element|Object} elem An element or a document + */ +isXML = Sizzle.isXML = function( elem ) { + // documentElement is verified for cases where it doesn't yet exist + // (such as loading iframes in IE - #4833) + var documentElement = elem && (elem.ownerDocument || elem).documentElement; + return documentElement ? documentElement.nodeName !== "HTML" : false; +}; + +/** + * Sets document-related variables once based on the current document + * @param {Element|Object} [doc] An element or document object to use to set the document + * @returns {Object} Returns the current document + */ +setDocument = Sizzle.setDocument = function( node ) { + var doc = node ? node.ownerDocument || node : preferredDoc; + + // If no document and documentElement is available, return + if ( doc === document || doc.nodeType !== 9 || !doc.documentElement ) { + return document; + } + + // Set our document + document = doc; + docElem = doc.documentElement; + + // Support tests + documentIsXML = isXML( doc ); + + // Check if getElementsByTagName("*") returns only elements + support.tagNameNoComments = assert(function( div ) { + div.appendChild( doc.createComment("") ); + return !div.getElementsByTagName("*").length; + }); + + // Check if attributes should be retrieved by attribute nodes + support.attributes = assert(function( div ) { + div.innerHTML = ""; + var type = typeof div.lastChild.getAttribute("multiple"); + // IE8 returns a string for some attributes even when not present + return type !== "boolean" && type !== "string"; + }); + + // Check if getElementsByClassName can be trusted + support.getByClassName = assert(function( div ) { + // Opera can't find a second classname (in 9.6) + div.innerHTML = ""; + if ( !div.getElementsByClassName || !div.getElementsByClassName("e").length ) { + return false; + } + + // Safari 3.2 caches class attributes and doesn't catch changes + div.lastChild.className = "e"; + return div.getElementsByClassName("e").length === 2; + }); + + // Check if getElementById returns elements by name + // Check if getElementsByName privileges form controls or returns elements by ID + support.getByName = assert(function( div ) { + // Inject content + div.id = expando + 0; + div.innerHTML = "
    "; + docElem.insertBefore( div, docElem.firstChild ); + + // Test + var pass = doc.getElementsByName && + // buggy browsers will return fewer than the correct 2 + doc.getElementsByName( expando ).length === 2 + + // buggy browsers will return more than the correct 0 + doc.getElementsByName( expando + 0 ).length; + support.getIdNotName = !doc.getElementById( expando ); + + // Cleanup + docElem.removeChild( div ); + + return pass; + }); + + // IE6/7 return modified attributes + Expr.attrHandle = assert(function( div ) { + div.innerHTML = ""; + return div.firstChild && typeof div.firstChild.getAttribute !== strundefined && + div.firstChild.getAttribute("href") === "#"; + }) ? + {} : + { + "href": function( elem ) { + return elem.getAttribute( "href", 2 ); + }, + "type": function( elem ) { + return elem.getAttribute("type"); + } + }; + + // ID find and filter + if ( support.getIdNotName ) { + Expr.find["ID"] = function( id, context ) { + if ( typeof context.getElementById !== strundefined && !documentIsXML ) { + var m = context.getElementById( id ); + // Check parentNode to catch when Blackberry 4.6 returns + // nodes that are no longer in the document #6963 + return m && m.parentNode ? [m] : []; + } + }; + Expr.filter["ID"] = function( id ) { + var attrId = id.replace( runescape, funescape ); + return function( elem ) { + return elem.getAttribute("id") === attrId; + }; + }; + } else { + Expr.find["ID"] = function( id, context ) { + if ( typeof context.getElementById !== strundefined && !documentIsXML ) { + var m = context.getElementById( id ); + + return m ? + m.id === id || typeof m.getAttributeNode !== strundefined && m.getAttributeNode("id").value === id ? + [m] : + undefined : + []; + } + }; + Expr.filter["ID"] = function( id ) { + var attrId = id.replace( runescape, funescape ); + return function( elem ) { + var node = typeof elem.getAttributeNode !== strundefined && elem.getAttributeNode("id"); + return node && node.value === attrId; + }; + }; + } + + // Tag + Expr.find["TAG"] = support.tagNameNoComments ? + function( tag, context ) { + if ( typeof context.getElementsByTagName !== strundefined ) { + return context.getElementsByTagName( tag ); + } + } : + function( tag, context ) { + var elem, + tmp = [], + i = 0, + results = context.getElementsByTagName( tag ); + + // Filter out possible comments + if ( tag === "*" ) { + for ( ; (elem = results[i]); i++ ) { + if ( elem.nodeType === 1 ) { + tmp.push( elem ); + } + } + + return tmp; + } + return results; + }; + + // Name + Expr.find["NAME"] = support.getByName && function( tag, context ) { + if ( typeof context.getElementsByName !== strundefined ) { + return context.getElementsByName( name ); + } + }; + + // Class + Expr.find["CLASS"] = support.getByClassName && function( className, context ) { + if ( typeof context.getElementsByClassName !== strundefined && !documentIsXML ) { + return context.getElementsByClassName( className ); + } + }; + + // QSA and matchesSelector support + + // matchesSelector(:active) reports false when true (IE9/Opera 11.5) + rbuggyMatches = []; + + // qSa(:focus) reports false when true (Chrome 21), + // no need to also add to buggyMatches since matches checks buggyQSA + // A support test would require too much code (would include document ready) + rbuggyQSA = [ ":focus" ]; + + if ( (support.qsa = isNative(doc.querySelectorAll)) ) { + // Build QSA regex + // Regex strategy adopted from Diego Perini + assert(function( div ) { + // Select is set to empty string on purpose + // This is to test IE's treatment of not explictly + // setting a boolean content attribute, + // since its presence should be enough + // http://bugs.jquery.com/ticket/12359 + div.innerHTML = ""; + + // IE8 - Some boolean attributes are not treated correctly + if ( !div.querySelectorAll("[selected]").length ) { + rbuggyQSA.push( "\\[" + whitespace + "*(?:checked|disabled|ismap|multiple|readonly|selected|value)" ); + } + + // Webkit/Opera - :checked should return selected option elements + // http://www.w3.org/TR/2011/REC-css3-selectors-20110929/#checked + // IE8 throws error here and will not see later tests + if ( !div.querySelectorAll(":checked").length ) { + rbuggyQSA.push(":checked"); + } + }); + + assert(function( div ) { + + // Opera 10-12/IE8 - ^= $= *= and empty values + // Should not select anything + div.innerHTML = ""; + if ( div.querySelectorAll("[i^='']").length ) { + rbuggyQSA.push( "[*^$]=" + whitespace + "*(?:\"\"|'')" ); + } + + // FF 3.5 - :enabled/:disabled and hidden elements (hidden elements are still enabled) + // IE8 throws error here and will not see later tests + if ( !div.querySelectorAll(":enabled").length ) { + rbuggyQSA.push( ":enabled", ":disabled" ); + } + + // Opera 10-11 does not throw on post-comma invalid pseudos + div.querySelectorAll("*,:x"); + rbuggyQSA.push(",.*:"); + }); + } + + if ( (support.matchesSelector = isNative( (matches = docElem.matchesSelector || + docElem.mozMatchesSelector || + docElem.webkitMatchesSelector || + docElem.oMatchesSelector || + docElem.msMatchesSelector) )) ) { + + assert(function( div ) { + // Check to see if it's possible to do matchesSelector + // on a disconnected node (IE 9) + support.disconnectedMatch = matches.call( div, "div" ); + + // This should fail with an exception + // Gecko does not error, returns false instead + matches.call( div, "[s!='']:x" ); + rbuggyMatches.push( "!=", pseudos ); + }); + } + + rbuggyQSA = new RegExp( rbuggyQSA.join("|") ); + rbuggyMatches = new RegExp( rbuggyMatches.join("|") ); + + // Element contains another + // Purposefully does not implement inclusive descendent + // As in, an element does not contain itself + contains = isNative(docElem.contains) || docElem.compareDocumentPosition ? + function( a, b ) { + var adown = a.nodeType === 9 ? a.documentElement : a, + bup = b && b.parentNode; + return a === bup || !!( bup && bup.nodeType === 1 && ( + adown.contains ? + adown.contains( bup ) : + a.compareDocumentPosition && a.compareDocumentPosition( bup ) & 16 + )); + } : + function( a, b ) { + if ( b ) { + while ( (b = b.parentNode) ) { + if ( b === a ) { + return true; + } + } + } + return false; + }; + + // Document order sorting + sortOrder = docElem.compareDocumentPosition ? + function( a, b ) { + var compare; + + if ( a === b ) { + hasDuplicate = true; + return 0; + } + + if ( (compare = b.compareDocumentPosition && a.compareDocumentPosition && a.compareDocumentPosition( b )) ) { + if ( compare & 1 || a.parentNode && a.parentNode.nodeType === 11 ) { + if ( a === doc || contains( preferredDoc, a ) ) { + return -1; + } + if ( b === doc || contains( preferredDoc, b ) ) { + return 1; + } + return 0; + } + return compare & 4 ? -1 : 1; + } + + return a.compareDocumentPosition ? -1 : 1; + } : + function( a, b ) { + var cur, + i = 0, + aup = a.parentNode, + bup = b.parentNode, + ap = [ a ], + bp = [ b ]; + + // The nodes are identical, we can exit early + if ( a === b ) { + hasDuplicate = true; + return 0; + + // Fallback to using sourceIndex (in IE) if it's available on both nodes + } else if ( a.sourceIndex && b.sourceIndex ) { + return ( ~b.sourceIndex || MAX_NEGATIVE ) - ( contains( preferredDoc, a ) && ~a.sourceIndex || MAX_NEGATIVE ); + + // Parentless nodes are either documents or disconnected + } else if ( !aup || !bup ) { + return a === doc ? -1 : + b === doc ? 1 : + aup ? -1 : + bup ? 1 : + 0; + + // If the nodes are siblings, we can do a quick check + } else if ( aup === bup ) { + return siblingCheck( a, b ); + } + + // Otherwise we need full lists of their ancestors for comparison + cur = a; + while ( (cur = cur.parentNode) ) { + ap.unshift( cur ); + } + cur = b; + while ( (cur = cur.parentNode) ) { + bp.unshift( cur ); + } + + // Walk down the tree looking for a discrepancy + while ( ap[i] === bp[i] ) { + i++; + } + + return i ? + // Do a sibling check if the nodes have a common ancestor + siblingCheck( ap[i], bp[i] ) : + + // Otherwise nodes in our document sort first + ap[i] === preferredDoc ? -1 : + bp[i] === preferredDoc ? 1 : + 0; + }; + + // Always assume the presence of duplicates if sort doesn't + // pass them to our comparison function (as in Google Chrome). + hasDuplicate = false; + [0, 0].sort( sortOrder ); + support.detectDuplicates = hasDuplicate; + + return document; +}; + +Sizzle.matches = function( expr, elements ) { + return Sizzle( expr, null, null, elements ); +}; + +Sizzle.matchesSelector = function( elem, expr ) { + // Set document vars if needed + if ( ( elem.ownerDocument || elem ) !== document ) { + setDocument( elem ); + } + + // Make sure that attribute selectors are quoted + expr = expr.replace( rattributeQuotes, "='$1']" ); + + // rbuggyQSA always contains :focus, so no need for an existence check + if ( support.matchesSelector && !documentIsXML && (!rbuggyMatches || !rbuggyMatches.test(expr)) && !rbuggyQSA.test(expr) ) { + try { + var ret = matches.call( elem, expr ); + + // IE 9's matchesSelector returns false on disconnected nodes + if ( ret || support.disconnectedMatch || + // As well, disconnected nodes are said to be in a document + // fragment in IE 9 + elem.document && elem.document.nodeType !== 11 ) { + return ret; + } + } catch(e) {} + } + + return Sizzle( expr, document, null, [elem] ).length > 0; +}; + +Sizzle.contains = function( context, elem ) { + // Set document vars if needed + if ( ( context.ownerDocument || context ) !== document ) { + setDocument( context ); + } + return contains( context, elem ); +}; + +Sizzle.attr = function( elem, name ) { + var val; + + // Set document vars if needed + if ( ( elem.ownerDocument || elem ) !== document ) { + setDocument( elem ); + } + + if ( !documentIsXML ) { + name = name.toLowerCase(); + } + if ( (val = Expr.attrHandle[ name ]) ) { + return val( elem ); + } + if ( documentIsXML || support.attributes ) { + return elem.getAttribute( name ); + } + return ( (val = elem.getAttributeNode( name )) || elem.getAttribute( name ) ) && elem[ name ] === true ? + name : + val && val.specified ? val.value : null; +}; + +Sizzle.error = function( msg ) { + throw new Error( "Syntax error, unrecognized expression: " + msg ); +}; + +// Document sorting and removing duplicates +Sizzle.uniqueSort = function( results ) { + var elem, + duplicates = [], + i = 1, + j = 0; + + // Unless we *know* we can detect duplicates, assume their presence + hasDuplicate = !support.detectDuplicates; + results.sort( sortOrder ); + + if ( hasDuplicate ) { + for ( ; (elem = results[i]); i++ ) { + if ( elem === results[ i - 1 ] ) { + j = duplicates.push( i ); + } + } + while ( j-- ) { + results.splice( duplicates[ j ], 1 ); + } + } + + return results; +}; + +function siblingCheck( a, b ) { + var cur = a && b && a.nextSibling; + + for ( ; cur; cur = cur.nextSibling ) { + if ( cur === b ) { + return -1; + } + } + + return a ? 1 : -1; +} + +// Returns a function to use in pseudos for input types +function createInputPseudo( type ) { + return function( elem ) { + var name = elem.nodeName.toLowerCase(); + return name === "input" && elem.type === type; + }; +} + +// Returns a function to use in pseudos for buttons +function createButtonPseudo( type ) { + return function( elem ) { + var name = elem.nodeName.toLowerCase(); + return (name === "input" || name === "button") && elem.type === type; + }; +} + +// Returns a function to use in pseudos for positionals +function createPositionalPseudo( fn ) { + return markFunction(function( argument ) { + argument = +argument; + return markFunction(function( seed, matches ) { + var j, + matchIndexes = fn( [], seed.length, argument ), + i = matchIndexes.length; + + // Match elements found at the specified indexes + while ( i-- ) { + if ( seed[ (j = matchIndexes[i]) ] ) { + seed[j] = !(matches[j] = seed[j]); + } + } + }); + }); +} + +/** + * Utility function for retrieving the text value of an array of DOM nodes + * @param {Array|Element} elem + */ +getText = Sizzle.getText = function( elem ) { + var node, + ret = "", + i = 0, + nodeType = elem.nodeType; + + if ( !nodeType ) { + // If no nodeType, this is expected to be an array + for ( ; (node = elem[i]); i++ ) { + // Do not traverse comment nodes + ret += getText( node ); + } + } else if ( nodeType === 1 || nodeType === 9 || nodeType === 11 ) { + // Use textContent for elements + // innerText usage removed for consistency of new lines (see #11153) + if ( typeof elem.textContent === "string" ) { + return elem.textContent; + } else { + // Traverse its children + for ( elem = elem.firstChild; elem; elem = elem.nextSibling ) { + ret += getText( elem ); + } + } + } else if ( nodeType === 3 || nodeType === 4 ) { + return elem.nodeValue; + } + // Do not include comment or processing instruction nodes + + return ret; +}; + +Expr = Sizzle.selectors = { + + // Can be adjusted by the user + cacheLength: 50, + + createPseudo: markFunction, + + match: matchExpr, + + find: {}, + + relative: { + ">": { dir: "parentNode", first: true }, + " ": { dir: "parentNode" }, + "+": { dir: "previousSibling", first: true }, + "~": { dir: "previousSibling" } + }, + + preFilter: { + "ATTR": function( match ) { + match[1] = match[1].replace( runescape, funescape ); + + // Move the given value to match[3] whether quoted or unquoted + match[3] = ( match[4] || match[5] || "" ).replace( runescape, funescape ); + + if ( match[2] === "~=" ) { + match[3] = " " + match[3] + " "; + } + + return match.slice( 0, 4 ); + }, + + "CHILD": function( match ) { + /* matches from matchExpr["CHILD"] + 1 type (only|nth|...) + 2 what (child|of-type) + 3 argument (even|odd|\d*|\d*n([+-]\d+)?|...) + 4 xn-component of xn+y argument ([+-]?\d*n|) + 5 sign of xn-component + 6 x of xn-component + 7 sign of y-component + 8 y of y-component + */ + match[1] = match[1].toLowerCase(); + + if ( match[1].slice( 0, 3 ) === "nth" ) { + // nth-* requires argument + if ( !match[3] ) { + Sizzle.error( match[0] ); + } + + // numeric x and y parameters for Expr.filter.CHILD + // remember that false/true cast respectively to 0/1 + match[4] = +( match[4] ? match[5] + (match[6] || 1) : 2 * ( match[3] === "even" || match[3] === "odd" ) ); + match[5] = +( ( match[7] + match[8] ) || match[3] === "odd" ); + + // other types prohibit arguments + } else if ( match[3] ) { + Sizzle.error( match[0] ); + } + + return match; + }, + + "PSEUDO": function( match ) { + var excess, + unquoted = !match[5] && match[2]; + + if ( matchExpr["CHILD"].test( match[0] ) ) { + return null; + } + + // Accept quoted arguments as-is + if ( match[4] ) { + match[2] = match[4]; + + // Strip excess characters from unquoted arguments + } else if ( unquoted && rpseudo.test( unquoted ) && + // Get excess from tokenize (recursively) + (excess = tokenize( unquoted, true )) && + // advance to the next closing parenthesis + (excess = unquoted.indexOf( ")", unquoted.length - excess ) - unquoted.length) ) { + + // excess is a negative index + match[0] = match[0].slice( 0, excess ); + match[2] = unquoted.slice( 0, excess ); + } + + // Return only captures needed by the pseudo filter method (type and argument) + return match.slice( 0, 3 ); + } + }, + + filter: { + + "TAG": function( nodeName ) { + if ( nodeName === "*" ) { + return function() { return true; }; + } + + nodeName = nodeName.replace( runescape, funescape ).toLowerCase(); + return function( elem ) { + return elem.nodeName && elem.nodeName.toLowerCase() === nodeName; + }; + }, + + "CLASS": function( className ) { + var pattern = classCache[ className + " " ]; + + return pattern || + (pattern = new RegExp( "(^|" + whitespace + ")" + className + "(" + whitespace + "|$)" )) && + classCache( className, function( elem ) { + return pattern.test( elem.className || (typeof elem.getAttribute !== strundefined && elem.getAttribute("class")) || "" ); + }); + }, + + "ATTR": function( name, operator, check ) { + return function( elem ) { + var result = Sizzle.attr( elem, name ); + + if ( result == null ) { + return operator === "!="; + } + if ( !operator ) { + return true; + } + + result += ""; + + return operator === "=" ? result === check : + operator === "!=" ? result !== check : + operator === "^=" ? check && result.indexOf( check ) === 0 : + operator === "*=" ? check && result.indexOf( check ) > -1 : + operator === "$=" ? check && result.substr( result.length - check.length ) === check : + operator === "~=" ? ( " " + result + " " ).indexOf( check ) > -1 : + operator === "|=" ? result === check || result.substr( 0, check.length + 1 ) === check + "-" : + false; + }; + }, + + "CHILD": function( type, what, argument, first, last ) { + var simple = type.slice( 0, 3 ) !== "nth", + forward = type.slice( -4 ) !== "last", + ofType = what === "of-type"; + + return first === 1 && last === 0 ? + + // Shortcut for :nth-*(n) + function( elem ) { + return !!elem.parentNode; + } : + + function( elem, context, xml ) { + var cache, outerCache, node, diff, nodeIndex, start, + dir = simple !== forward ? "nextSibling" : "previousSibling", + parent = elem.parentNode, + name = ofType && elem.nodeName.toLowerCase(), + useCache = !xml && !ofType; + + if ( parent ) { + + // :(first|last|only)-(child|of-type) + if ( simple ) { + while ( dir ) { + node = elem; + while ( (node = node[ dir ]) ) { + if ( ofType ? node.nodeName.toLowerCase() === name : node.nodeType === 1 ) { + return false; + } + } + // Reverse direction for :only-* (if we haven't yet done so) + start = dir = type === "only" && !start && "nextSibling"; + } + return true; + } + + start = [ forward ? parent.firstChild : parent.lastChild ]; + + // non-xml :nth-child(...) stores cache data on `parent` + if ( forward && useCache ) { + // Seek `elem` from a previously-cached index + outerCache = parent[ expando ] || (parent[ expando ] = {}); + cache = outerCache[ type ] || []; + nodeIndex = cache[0] === dirruns && cache[1]; + diff = cache[0] === dirruns && cache[2]; + node = nodeIndex && parent.childNodes[ nodeIndex ]; + + while ( (node = ++nodeIndex && node && node[ dir ] || + + // Fallback to seeking `elem` from the start + (diff = nodeIndex = 0) || start.pop()) ) { + + // When found, cache indexes on `parent` and break + if ( node.nodeType === 1 && ++diff && node === elem ) { + outerCache[ type ] = [ dirruns, nodeIndex, diff ]; + break; + } + } + + // Use previously-cached element index if available + } else if ( useCache && (cache = (elem[ expando ] || (elem[ expando ] = {}))[ type ]) && cache[0] === dirruns ) { + diff = cache[1]; + + // xml :nth-child(...) or :nth-last-child(...) or :nth(-last)?-of-type(...) + } else { + // Use the same loop as above to seek `elem` from the start + while ( (node = ++nodeIndex && node && node[ dir ] || + (diff = nodeIndex = 0) || start.pop()) ) { + + if ( ( ofType ? node.nodeName.toLowerCase() === name : node.nodeType === 1 ) && ++diff ) { + // Cache the index of each encountered element + if ( useCache ) { + (node[ expando ] || (node[ expando ] = {}))[ type ] = [ dirruns, diff ]; + } + + if ( node === elem ) { + break; + } + } + } + } + + // Incorporate the offset, then check against cycle size + diff -= last; + return diff === first || ( diff % first === 0 && diff / first >= 0 ); + } + }; + }, + + "PSEUDO": function( pseudo, argument ) { + // pseudo-class names are case-insensitive + // http://www.w3.org/TR/selectors/#pseudo-classes + // Prioritize by case sensitivity in case custom pseudos are added with uppercase letters + // Remember that setFilters inherits from pseudos + var args, + fn = Expr.pseudos[ pseudo ] || Expr.setFilters[ pseudo.toLowerCase() ] || + Sizzle.error( "unsupported pseudo: " + pseudo ); + + // The user may use createPseudo to indicate that + // arguments are needed to create the filter function + // just as Sizzle does + if ( fn[ expando ] ) { + return fn( argument ); + } + + // But maintain support for old signatures + if ( fn.length > 1 ) { + args = [ pseudo, pseudo, "", argument ]; + return Expr.setFilters.hasOwnProperty( pseudo.toLowerCase() ) ? + markFunction(function( seed, matches ) { + var idx, + matched = fn( seed, argument ), + i = matched.length; + while ( i-- ) { + idx = indexOf.call( seed, matched[i] ); + seed[ idx ] = !( matches[ idx ] = matched[i] ); + } + }) : + function( elem ) { + return fn( elem, 0, args ); + }; + } + + return fn; + } + }, + + pseudos: { + // Potentially complex pseudos + "not": markFunction(function( selector ) { + // Trim the selector passed to compile + // to avoid treating leading and trailing + // spaces as combinators + var input = [], + results = [], + matcher = compile( selector.replace( rtrim, "$1" ) ); + + return matcher[ expando ] ? + markFunction(function( seed, matches, context, xml ) { + var elem, + unmatched = matcher( seed, null, xml, [] ), + i = seed.length; + + // Match elements unmatched by `matcher` + while ( i-- ) { + if ( (elem = unmatched[i]) ) { + seed[i] = !(matches[i] = elem); + } + } + }) : + function( elem, context, xml ) { + input[0] = elem; + matcher( input, null, xml, results ); + return !results.pop(); + }; + }), + + "has": markFunction(function( selector ) { + return function( elem ) { + return Sizzle( selector, elem ).length > 0; + }; + }), + + "contains": markFunction(function( text ) { + return function( elem ) { + return ( elem.textContent || elem.innerText || getText( elem ) ).indexOf( text ) > -1; + }; + }), + + // "Whether an element is represented by a :lang() selector + // is based solely on the element's language value + // being equal to the identifier C, + // or beginning with the identifier C immediately followed by "-". + // The matching of C against the element's language value is performed case-insensitively. + // The identifier C does not have to be a valid language name." + // http://www.w3.org/TR/selectors/#lang-pseudo + "lang": markFunction( function( lang ) { + // lang value must be a valid identifider + if ( !ridentifier.test(lang || "") ) { + Sizzle.error( "unsupported lang: " + lang ); + } + lang = lang.replace( runescape, funescape ).toLowerCase(); + return function( elem ) { + var elemLang; + do { + if ( (elemLang = documentIsXML ? + elem.getAttribute("xml:lang") || elem.getAttribute("lang") : + elem.lang) ) { + + elemLang = elemLang.toLowerCase(); + return elemLang === lang || elemLang.indexOf( lang + "-" ) === 0; + } + } while ( (elem = elem.parentNode) && elem.nodeType === 1 ); + return false; + }; + }), + + // Miscellaneous + "target": function( elem ) { + var hash = window.location && window.location.hash; + return hash && hash.slice( 1 ) === elem.id; + }, + + "root": function( elem ) { + return elem === docElem; + }, + + "focus": function( elem ) { + return elem === document.activeElement && (!document.hasFocus || document.hasFocus()) && !!(elem.type || elem.href || ~elem.tabIndex); + }, + + // Boolean properties + "enabled": function( elem ) { + return elem.disabled === false; + }, + + "disabled": function( elem ) { + return elem.disabled === true; + }, + + "checked": function( elem ) { + // In CSS3, :checked should return both checked and selected elements + // http://www.w3.org/TR/2011/REC-css3-selectors-20110929/#checked + var nodeName = elem.nodeName.toLowerCase(); + return (nodeName === "input" && !!elem.checked) || (nodeName === "option" && !!elem.selected); + }, + + "selected": function( elem ) { + // Accessing this property makes selected-by-default + // options in Safari work properly + if ( elem.parentNode ) { + elem.parentNode.selectedIndex; + } + + return elem.selected === true; + }, + + // Contents + "empty": function( elem ) { + // http://www.w3.org/TR/selectors/#empty-pseudo + // :empty is only affected by element nodes and content nodes(including text(3), cdata(4)), + // not comment, processing instructions, or others + // Thanks to Diego Perini for the nodeName shortcut + // Greater than "@" means alpha characters (specifically not starting with "#" or "?") + for ( elem = elem.firstChild; elem; elem = elem.nextSibling ) { + if ( elem.nodeName > "@" || elem.nodeType === 3 || elem.nodeType === 4 ) { + return false; + } + } + return true; + }, + + "parent": function( elem ) { + return !Expr.pseudos["empty"]( elem ); + }, + + // Element/input types + "header": function( elem ) { + return rheader.test( elem.nodeName ); + }, + + "input": function( elem ) { + return rinputs.test( elem.nodeName ); + }, + + "button": function( elem ) { + var name = elem.nodeName.toLowerCase(); + return name === "input" && elem.type === "button" || name === "button"; + }, + + "text": function( elem ) { + var attr; + // IE6 and 7 will map elem.type to 'text' for new HTML5 types (search, etc) + // use getAttribute instead to test this case + return elem.nodeName.toLowerCase() === "input" && + elem.type === "text" && + ( (attr = elem.getAttribute("type")) == null || attr.toLowerCase() === elem.type ); + }, + + // Position-in-collection + "first": createPositionalPseudo(function() { + return [ 0 ]; + }), + + "last": createPositionalPseudo(function( matchIndexes, length ) { + return [ length - 1 ]; + }), + + "eq": createPositionalPseudo(function( matchIndexes, length, argument ) { + return [ argument < 0 ? argument + length : argument ]; + }), + + "even": createPositionalPseudo(function( matchIndexes, length ) { + var i = 0; + for ( ; i < length; i += 2 ) { + matchIndexes.push( i ); + } + return matchIndexes; + }), + + "odd": createPositionalPseudo(function( matchIndexes, length ) { + var i = 1; + for ( ; i < length; i += 2 ) { + matchIndexes.push( i ); + } + return matchIndexes; + }), + + "lt": createPositionalPseudo(function( matchIndexes, length, argument ) { + var i = argument < 0 ? argument + length : argument; + for ( ; --i >= 0; ) { + matchIndexes.push( i ); + } + return matchIndexes; + }), + + "gt": createPositionalPseudo(function( matchIndexes, length, argument ) { + var i = argument < 0 ? argument + length : argument; + for ( ; ++i < length; ) { + matchIndexes.push( i ); + } + return matchIndexes; + }) + } +}; + +// Add button/input type pseudos +for ( i in { radio: true, checkbox: true, file: true, password: true, image: true } ) { + Expr.pseudos[ i ] = createInputPseudo( i ); +} +for ( i in { submit: true, reset: true } ) { + Expr.pseudos[ i ] = createButtonPseudo( i ); +} + +function tokenize( selector, parseOnly ) { + var matched, match, tokens, type, + soFar, groups, preFilters, + cached = tokenCache[ selector + " " ]; + + if ( cached ) { + return parseOnly ? 0 : cached.slice( 0 ); + } + + soFar = selector; + groups = []; + preFilters = Expr.preFilter; + + while ( soFar ) { + + // Comma and first run + if ( !matched || (match = rcomma.exec( soFar )) ) { + if ( match ) { + // Don't consume trailing commas as valid + soFar = soFar.slice( match[0].length ) || soFar; + } + groups.push( tokens = [] ); + } + + matched = false; + + // Combinators + if ( (match = rcombinators.exec( soFar )) ) { + matched = match.shift(); + tokens.push( { + value: matched, + // Cast descendant combinators to space + type: match[0].replace( rtrim, " " ) + } ); + soFar = soFar.slice( matched.length ); + } + + // Filters + for ( type in Expr.filter ) { + if ( (match = matchExpr[ type ].exec( soFar )) && (!preFilters[ type ] || + (match = preFilters[ type ]( match ))) ) { + matched = match.shift(); + tokens.push( { + value: matched, + type: type, + matches: match + } ); + soFar = soFar.slice( matched.length ); + } + } + + if ( !matched ) { + break; + } + } + + // Return the length of the invalid excess + // if we're just parsing + // Otherwise, throw an error or return tokens + return parseOnly ? + soFar.length : + soFar ? + Sizzle.error( selector ) : + // Cache the tokens + tokenCache( selector, groups ).slice( 0 ); +} + +function toSelector( tokens ) { + var i = 0, + len = tokens.length, + selector = ""; + for ( ; i < len; i++ ) { + selector += tokens[i].value; + } + return selector; +} + +function addCombinator( matcher, combinator, base ) { + var dir = combinator.dir, + checkNonElements = base && combinator.dir === "parentNode", + doneName = done++; + + return combinator.first ? + // Check against closest ancestor/preceding element + function( elem, context, xml ) { + while ( (elem = elem[ dir ]) ) { + if ( elem.nodeType === 1 || checkNonElements ) { + return matcher( elem, context, xml ); + } + } + } : + + // Check against all ancestor/preceding elements + function( elem, context, xml ) { + var data, cache, outerCache, + dirkey = dirruns + " " + doneName; + + // We can't set arbitrary data on XML nodes, so they don't benefit from dir caching + if ( xml ) { + while ( (elem = elem[ dir ]) ) { + if ( elem.nodeType === 1 || checkNonElements ) { + if ( matcher( elem, context, xml ) ) { + return true; + } + } + } + } else { + while ( (elem = elem[ dir ]) ) { + if ( elem.nodeType === 1 || checkNonElements ) { + outerCache = elem[ expando ] || (elem[ expando ] = {}); + if ( (cache = outerCache[ dir ]) && cache[0] === dirkey ) { + if ( (data = cache[1]) === true || data === cachedruns ) { + return data === true; + } + } else { + cache = outerCache[ dir ] = [ dirkey ]; + cache[1] = matcher( elem, context, xml ) || cachedruns; + if ( cache[1] === true ) { + return true; + } + } + } + } + } + }; +} + +function elementMatcher( matchers ) { + return matchers.length > 1 ? + function( elem, context, xml ) { + var i = matchers.length; + while ( i-- ) { + if ( !matchers[i]( elem, context, xml ) ) { + return false; + } + } + return true; + } : + matchers[0]; +} + +function condense( unmatched, map, filter, context, xml ) { + var elem, + newUnmatched = [], + i = 0, + len = unmatched.length, + mapped = map != null; + + for ( ; i < len; i++ ) { + if ( (elem = unmatched[i]) ) { + if ( !filter || filter( elem, context, xml ) ) { + newUnmatched.push( elem ); + if ( mapped ) { + map.push( i ); + } + } + } + } + + return newUnmatched; +} + +function setMatcher( preFilter, selector, matcher, postFilter, postFinder, postSelector ) { + if ( postFilter && !postFilter[ expando ] ) { + postFilter = setMatcher( postFilter ); + } + if ( postFinder && !postFinder[ expando ] ) { + postFinder = setMatcher( postFinder, postSelector ); + } + return markFunction(function( seed, results, context, xml ) { + var temp, i, elem, + preMap = [], + postMap = [], + preexisting = results.length, + + // Get initial elements from seed or context + elems = seed || multipleContexts( selector || "*", context.nodeType ? [ context ] : context, [] ), + + // Prefilter to get matcher input, preserving a map for seed-results synchronization + matcherIn = preFilter && ( seed || !selector ) ? + condense( elems, preMap, preFilter, context, xml ) : + elems, + + matcherOut = matcher ? + // If we have a postFinder, or filtered seed, or non-seed postFilter or preexisting results, + postFinder || ( seed ? preFilter : preexisting || postFilter ) ? + + // ...intermediate processing is necessary + [] : + + // ...otherwise use results directly + results : + matcherIn; + + // Find primary matches + if ( matcher ) { + matcher( matcherIn, matcherOut, context, xml ); + } + + // Apply postFilter + if ( postFilter ) { + temp = condense( matcherOut, postMap ); + postFilter( temp, [], context, xml ); + + // Un-match failing elements by moving them back to matcherIn + i = temp.length; + while ( i-- ) { + if ( (elem = temp[i]) ) { + matcherOut[ postMap[i] ] = !(matcherIn[ postMap[i] ] = elem); + } + } + } + + if ( seed ) { + if ( postFinder || preFilter ) { + if ( postFinder ) { + // Get the final matcherOut by condensing this intermediate into postFinder contexts + temp = []; + i = matcherOut.length; + while ( i-- ) { + if ( (elem = matcherOut[i]) ) { + // Restore matcherIn since elem is not yet a final match + temp.push( (matcherIn[i] = elem) ); + } + } + postFinder( null, (matcherOut = []), temp, xml ); + } + + // Move matched elements from seed to results to keep them synchronized + i = matcherOut.length; + while ( i-- ) { + if ( (elem = matcherOut[i]) && + (temp = postFinder ? indexOf.call( seed, elem ) : preMap[i]) > -1 ) { + + seed[temp] = !(results[temp] = elem); + } + } + } + + // Add elements to results, through postFinder if defined + } else { + matcherOut = condense( + matcherOut === results ? + matcherOut.splice( preexisting, matcherOut.length ) : + matcherOut + ); + if ( postFinder ) { + postFinder( null, results, matcherOut, xml ); + } else { + push.apply( results, matcherOut ); + } + } + }); +} + +function matcherFromTokens( tokens ) { + var checkContext, matcher, j, + len = tokens.length, + leadingRelative = Expr.relative[ tokens[0].type ], + implicitRelative = leadingRelative || Expr.relative[" "], + i = leadingRelative ? 1 : 0, + + // The foundational matcher ensures that elements are reachable from top-level context(s) + matchContext = addCombinator( function( elem ) { + return elem === checkContext; + }, implicitRelative, true ), + matchAnyContext = addCombinator( function( elem ) { + return indexOf.call( checkContext, elem ) > -1; + }, implicitRelative, true ), + matchers = [ function( elem, context, xml ) { + return ( !leadingRelative && ( xml || context !== outermostContext ) ) || ( + (checkContext = context).nodeType ? + matchContext( elem, context, xml ) : + matchAnyContext( elem, context, xml ) ); + } ]; + + for ( ; i < len; i++ ) { + if ( (matcher = Expr.relative[ tokens[i].type ]) ) { + matchers = [ addCombinator(elementMatcher( matchers ), matcher) ]; + } else { + matcher = Expr.filter[ tokens[i].type ].apply( null, tokens[i].matches ); + + // Return special upon seeing a positional matcher + if ( matcher[ expando ] ) { + // Find the next relative operator (if any) for proper handling + j = ++i; + for ( ; j < len; j++ ) { + if ( Expr.relative[ tokens[j].type ] ) { + break; + } + } + return setMatcher( + i > 1 && elementMatcher( matchers ), + i > 1 && toSelector( tokens.slice( 0, i - 1 ) ).replace( rtrim, "$1" ), + matcher, + i < j && matcherFromTokens( tokens.slice( i, j ) ), + j < len && matcherFromTokens( (tokens = tokens.slice( j )) ), + j < len && toSelector( tokens ) + ); + } + matchers.push( matcher ); + } + } + + return elementMatcher( matchers ); +} + +function matcherFromGroupMatchers( elementMatchers, setMatchers ) { + // A counter to specify which element is currently being matched + var matcherCachedRuns = 0, + bySet = setMatchers.length > 0, + byElement = elementMatchers.length > 0, + superMatcher = function( seed, context, xml, results, expandContext ) { + var elem, j, matcher, + setMatched = [], + matchedCount = 0, + i = "0", + unmatched = seed && [], + outermost = expandContext != null, + contextBackup = outermostContext, + // We must always have either seed elements or context + elems = seed || byElement && Expr.find["TAG"]( "*", expandContext && context.parentNode || context ), + // Nested matchers should use non-integer dirruns + dirrunsUnique = (dirruns += contextBackup == null ? 1 : Math.E); + + if ( outermost ) { + outermostContext = context !== document && context; + cachedruns = matcherCachedRuns; + } + + // Add elements passing elementMatchers directly to results + for ( ; (elem = elems[i]) != null; i++ ) { + if ( byElement && elem ) { + for ( j = 0; (matcher = elementMatchers[j]); j++ ) { + if ( matcher( elem, context, xml ) ) { + results.push( elem ); + break; + } + } + if ( outermost ) { + dirruns = dirrunsUnique; + cachedruns = ++matcherCachedRuns; + } + } + + // Track unmatched elements for set filters + if ( bySet ) { + // They will have gone through all possible matchers + if ( (elem = !matcher && elem) ) { + matchedCount--; + } + + // Lengthen the array for every element, matched or not + if ( seed ) { + unmatched.push( elem ); + } + } + } + + // Apply set filters to unmatched elements + // `i` starts as a string, so matchedCount would equal "00" if there are no elements + matchedCount += i; + if ( bySet && i !== matchedCount ) { + for ( j = 0; (matcher = setMatchers[j]); j++ ) { + matcher( unmatched, setMatched, context, xml ); + } + + if ( seed ) { + // Reintegrate element matches to eliminate the need for sorting + if ( matchedCount > 0 ) { + while ( i-- ) { + if ( !(unmatched[i] || setMatched[i]) ) { + setMatched[i] = pop.call( results ); + } + } + } + + // Discard index placeholder values to get only actual matches + setMatched = condense( setMatched ); + } + + // Add matches to results + push.apply( results, setMatched ); + + // Seedless set matches succeeding multiple successful matchers stipulate sorting + if ( outermost && !seed && setMatched.length > 0 && + ( matchedCount + setMatchers.length ) > 1 ) { + + Sizzle.uniqueSort( results ); + } + } + + // Override manipulation of globals by nested matchers + if ( outermost ) { + dirruns = dirrunsUnique; + outermostContext = contextBackup; + } + + return unmatched; + }; + + return bySet ? + markFunction( superMatcher ) : + superMatcher; +} + +compile = Sizzle.compile = function( selector, group /* Internal Use Only */ ) { + var i, + setMatchers = [], + elementMatchers = [], + cached = compilerCache[ selector + " " ]; + + if ( !cached ) { + // Generate a function of recursive functions that can be used to check each element + if ( !group ) { + group = tokenize( selector ); + } + i = group.length; + while ( i-- ) { + cached = matcherFromTokens( group[i] ); + if ( cached[ expando ] ) { + setMatchers.push( cached ); + } else { + elementMatchers.push( cached ); + } + } + + // Cache the compiled function + cached = compilerCache( selector, matcherFromGroupMatchers( elementMatchers, setMatchers ) ); + } + return cached; +}; + +function multipleContexts( selector, contexts, results ) { + var i = 0, + len = contexts.length; + for ( ; i < len; i++ ) { + Sizzle( selector, contexts[i], results ); + } + return results; +} + +function select( selector, context, results, seed ) { + var i, tokens, token, type, find, + match = tokenize( selector ); + + if ( !seed ) { + // Try to minimize operations if there is only one group + if ( match.length === 1 ) { + + // Take a shortcut and set the context if the root selector is an ID + tokens = match[0] = match[0].slice( 0 ); + if ( tokens.length > 2 && (token = tokens[0]).type === "ID" && + context.nodeType === 9 && !documentIsXML && + Expr.relative[ tokens[1].type ] ) { + + context = Expr.find["ID"]( token.matches[0].replace( runescape, funescape ), context )[0]; + if ( !context ) { + return results; + } + + selector = selector.slice( tokens.shift().value.length ); + } + + // Fetch a seed set for right-to-left matching + for ( i = matchExpr["needsContext"].test( selector ) ? -1 : tokens.length - 1; i >= 0; i-- ) { + token = tokens[i]; + + // Abort if we hit a combinator + if ( Expr.relative[ (type = token.type) ] ) { + break; + } + if ( (find = Expr.find[ type ]) ) { + // Search, expanding context for leading sibling combinators + if ( (seed = find( + token.matches[0].replace( runescape, funescape ), + rsibling.test( tokens[0].type ) && context.parentNode || context + )) ) { + + // If seed is empty or no tokens remain, we can return early + tokens.splice( i, 1 ); + selector = seed.length && toSelector( tokens ); + if ( !selector ) { + push.apply( results, slice.call( seed, 0 ) ); + return results; + } + + break; + } + } + } + } + } + + // Compile and execute a filtering function + // Provide `match` to avoid retokenization if we modified the selector above + compile( selector, match )( + seed, + context, + documentIsXML, + results, + rsibling.test( selector ) + ); + return results; +} + +// Deprecated +Expr.pseudos["nth"] = Expr.pseudos["eq"]; + +// Easy API for creating new setFilters +function setFilters() {} +Expr.filters = setFilters.prototype = Expr.pseudos; +Expr.setFilters = new setFilters(); + +// Initialize with the default document +setDocument(); + +// Override sizzle attribute retrieval +Sizzle.attr = jQuery.attr; +jQuery.find = Sizzle; +jQuery.expr = Sizzle.selectors; +jQuery.expr[":"] = jQuery.expr.pseudos; +jQuery.unique = Sizzle.uniqueSort; +jQuery.text = Sizzle.getText; +jQuery.isXMLDoc = Sizzle.isXML; +jQuery.contains = Sizzle.contains; + + +})( window ); +var runtil = /Until$/, + rparentsprev = /^(?:parents|prev(?:Until|All))/, + isSimple = /^.[^:#\[\.,]*$/, + rneedsContext = jQuery.expr.match.needsContext, + // methods guaranteed to produce a unique set when starting from a unique set + guaranteedUnique = { + children: true, + contents: true, + next: true, + prev: true + }; + +jQuery.fn.extend({ + find: function( selector ) { + var i, ret, self; + + if ( typeof selector !== "string" ) { + self = this; + return this.pushStack( jQuery( selector ).filter(function() { + for ( i = 0; i < self.length; i++ ) { + if ( jQuery.contains( self[ i ], this ) ) { + return true; + } + } + }) ); + } + + ret = []; + for ( i = 0; i < this.length; i++ ) { + jQuery.find( selector, this[ i ], ret ); + } + + // Needed because $( selector, context ) becomes $( context ).find( selector ) + ret = this.pushStack( jQuery.unique( ret ) ); + ret.selector = ( this.selector ? this.selector + " " : "" ) + selector; + return ret; + }, + + has: function( target ) { + var i, + targets = jQuery( target, this ), + len = targets.length; + + return this.filter(function() { + for ( i = 0; i < len; i++ ) { + if ( jQuery.contains( this, targets[i] ) ) { + return true; + } + } + }); + }, + + not: function( selector ) { + return this.pushStack( winnow(this, selector, false) ); + }, + + filter: function( selector ) { + return this.pushStack( winnow(this, selector, true) ); + }, + + is: function( selector ) { + return !!selector && ( + typeof selector === "string" ? + // If this is a positional/relative selector, check membership in the returned set + // so $("p:first").is("p:last") won't return true for a doc with two "p". + rneedsContext.test( selector ) ? + jQuery( selector, this.context ).index( this[0] ) >= 0 : + jQuery.filter( selector, this ).length > 0 : + this.filter( selector ).length > 0 ); + }, + + closest: function( selectors, context ) { + var cur, + i = 0, + l = this.length, + ret = [], + pos = rneedsContext.test( selectors ) || typeof selectors !== "string" ? + jQuery( selectors, context || this.context ) : + 0; + + for ( ; i < l; i++ ) { + cur = this[i]; + + while ( cur && cur.ownerDocument && cur !== context && cur.nodeType !== 11 ) { + if ( pos ? pos.index(cur) > -1 : jQuery.find.matchesSelector(cur, selectors) ) { + ret.push( cur ); + break; + } + cur = cur.parentNode; + } + } + + return this.pushStack( ret.length > 1 ? jQuery.unique( ret ) : ret ); + }, + + // Determine the position of an element within + // the matched set of elements + index: function( elem ) { + + // No argument, return index in parent + if ( !elem ) { + return ( this[0] && this[0].parentNode ) ? this.first().prevAll().length : -1; + } + + // index in selector + if ( typeof elem === "string" ) { + return jQuery.inArray( this[0], jQuery( elem ) ); + } + + // Locate the position of the desired element + return jQuery.inArray( + // If it receives a jQuery object, the first element is used + elem.jquery ? elem[0] : elem, this ); + }, + + add: function( selector, context ) { + var set = typeof selector === "string" ? + jQuery( selector, context ) : + jQuery.makeArray( selector && selector.nodeType ? [ selector ] : selector ), + all = jQuery.merge( this.get(), set ); + + return this.pushStack( jQuery.unique(all) ); + }, + + addBack: function( selector ) { + return this.add( selector == null ? + this.prevObject : this.prevObject.filter(selector) + ); + } +}); + +jQuery.fn.andSelf = jQuery.fn.addBack; + +function sibling( cur, dir ) { + do { + cur = cur[ dir ]; + } while ( cur && cur.nodeType !== 1 ); + + return cur; +} + +jQuery.each({ + parent: function( elem ) { + var parent = elem.parentNode; + return parent && parent.nodeType !== 11 ? parent : null; + }, + parents: function( elem ) { + return jQuery.dir( elem, "parentNode" ); + }, + parentsUntil: function( elem, i, until ) { + return jQuery.dir( elem, "parentNode", until ); + }, + next: function( elem ) { + return sibling( elem, "nextSibling" ); + }, + prev: function( elem ) { + return sibling( elem, "previousSibling" ); + }, + nextAll: function( elem ) { + return jQuery.dir( elem, "nextSibling" ); + }, + prevAll: function( elem ) { + return jQuery.dir( elem, "previousSibling" ); + }, + nextUntil: function( elem, i, until ) { + return jQuery.dir( elem, "nextSibling", until ); + }, + prevUntil: function( elem, i, until ) { + return jQuery.dir( elem, "previousSibling", until ); + }, + siblings: function( elem ) { + return jQuery.sibling( ( elem.parentNode || {} ).firstChild, elem ); + }, + children: function( elem ) { + return jQuery.sibling( elem.firstChild ); + }, + contents: function( elem ) { + return jQuery.nodeName( elem, "iframe" ) ? + elem.contentDocument || elem.contentWindow.document : + jQuery.merge( [], elem.childNodes ); + } +}, function( name, fn ) { + jQuery.fn[ name ] = function( until, selector ) { + var ret = jQuery.map( this, fn, until ); + + if ( !runtil.test( name ) ) { + selector = until; + } + + if ( selector && typeof selector === "string" ) { + ret = jQuery.filter( selector, ret ); + } + + ret = this.length > 1 && !guaranteedUnique[ name ] ? jQuery.unique( ret ) : ret; + + if ( this.length > 1 && rparentsprev.test( name ) ) { + ret = ret.reverse(); + } + + return this.pushStack( ret ); + }; +}); + +jQuery.extend({ + filter: function( expr, elems, not ) { + if ( not ) { + expr = ":not(" + expr + ")"; + } + + return elems.length === 1 ? + jQuery.find.matchesSelector(elems[0], expr) ? [ elems[0] ] : [] : + jQuery.find.matches(expr, elems); + }, + + dir: function( elem, dir, until ) { + var matched = [], + cur = elem[ dir ]; + + while ( cur && cur.nodeType !== 9 && (until === undefined || cur.nodeType !== 1 || !jQuery( cur ).is( until )) ) { + if ( cur.nodeType === 1 ) { + matched.push( cur ); + } + cur = cur[dir]; + } + return matched; + }, + + sibling: function( n, elem ) { + var r = []; + + for ( ; n; n = n.nextSibling ) { + if ( n.nodeType === 1 && n !== elem ) { + r.push( n ); + } + } + + return r; + } +}); + +// Implement the identical functionality for filter and not +function winnow( elements, qualifier, keep ) { + + // Can't pass null or undefined to indexOf in Firefox 4 + // Set to 0 to skip string check + qualifier = qualifier || 0; + + if ( jQuery.isFunction( qualifier ) ) { + return jQuery.grep(elements, function( elem, i ) { + var retVal = !!qualifier.call( elem, i, elem ); + return retVal === keep; + }); + + } else if ( qualifier.nodeType ) { + return jQuery.grep(elements, function( elem ) { + return ( elem === qualifier ) === keep; + }); + + } else if ( typeof qualifier === "string" ) { + var filtered = jQuery.grep(elements, function( elem ) { + return elem.nodeType === 1; + }); + + if ( isSimple.test( qualifier ) ) { + return jQuery.filter(qualifier, filtered, !keep); + } else { + qualifier = jQuery.filter( qualifier, filtered ); + } + } + + return jQuery.grep(elements, function( elem ) { + return ( jQuery.inArray( elem, qualifier ) >= 0 ) === keep; + }); +} +function createSafeFragment( document ) { + var list = nodeNames.split( "|" ), + safeFrag = document.createDocumentFragment(); + + if ( safeFrag.createElement ) { + while ( list.length ) { + safeFrag.createElement( + list.pop() + ); + } + } + return safeFrag; +} + +var nodeNames = "abbr|article|aside|audio|bdi|canvas|data|datalist|details|figcaption|figure|footer|" + + "header|hgroup|mark|meter|nav|output|progress|section|summary|time|video", + rinlinejQuery = / jQuery\d+="(?:null|\d+)"/g, + rnoshimcache = new RegExp("<(?:" + nodeNames + ")[\\s/>]", "i"), + rleadingWhitespace = /^\s+/, + rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi, + rtagName = /<([\w:]+)/, + rtbody = /\s*$/g, + + // We have to close these tags to support XHTML (#13200) + wrapMap = { + option: [ 1, "" ], + legend: [ 1, "
    ", "
    " ], + area: [ 1, "", "" ], + param: [ 1, "", "" ], + thead: [ 1, "", "
    " ], + tr: [ 2, "", "
    " ], + col: [ 2, "", "
    " ], + td: [ 3, "", "
    " ], + + // IE6-8 can't serialize link, script, style, or any html5 (NoScope) tags, + // unless wrapped in a div with non-breaking characters in front of it. + _default: jQuery.support.htmlSerialize ? [ 0, "", "" ] : [ 1, "X
    ", "
    " ] + }, + safeFragment = createSafeFragment( document ), + fragmentDiv = safeFragment.appendChild( document.createElement("div") ); + +wrapMap.optgroup = wrapMap.option; +wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead; +wrapMap.th = wrapMap.td; + +jQuery.fn.extend({ + text: function( value ) { + return jQuery.access( this, function( value ) { + return value === undefined ? + jQuery.text( this ) : + this.empty().append( ( this[0] && this[0].ownerDocument || document ).createTextNode( value ) ); + }, null, value, arguments.length ); + }, + + wrapAll: function( html ) { + if ( jQuery.isFunction( html ) ) { + return this.each(function(i) { + jQuery(this).wrapAll( html.call(this, i) ); + }); + } + + if ( this[0] ) { + // The elements to wrap the target around + var wrap = jQuery( html, this[0].ownerDocument ).eq(0).clone(true); + + if ( this[0].parentNode ) { + wrap.insertBefore( this[0] ); + } + + wrap.map(function() { + var elem = this; + + while ( elem.firstChild && elem.firstChild.nodeType === 1 ) { + elem = elem.firstChild; + } + + return elem; + }).append( this ); + } + + return this; + }, + + wrapInner: function( html ) { + if ( jQuery.isFunction( html ) ) { + return this.each(function(i) { + jQuery(this).wrapInner( html.call(this, i) ); + }); + } + + return this.each(function() { + var self = jQuery( this ), + contents = self.contents(); + + if ( contents.length ) { + contents.wrapAll( html ); + + } else { + self.append( html ); + } + }); + }, + + wrap: function( html ) { + var isFunction = jQuery.isFunction( html ); + + return this.each(function(i) { + jQuery( this ).wrapAll( isFunction ? html.call(this, i) : html ); + }); + }, + + unwrap: function() { + return this.parent().each(function() { + if ( !jQuery.nodeName( this, "body" ) ) { + jQuery( this ).replaceWith( this.childNodes ); + } + }).end(); + }, + + append: function() { + return this.domManip(arguments, true, function( elem ) { + if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) { + this.appendChild( elem ); + } + }); + }, + + prepend: function() { + return this.domManip(arguments, true, function( elem ) { + if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) { + this.insertBefore( elem, this.firstChild ); + } + }); + }, + + before: function() { + return this.domManip( arguments, false, function( elem ) { + if ( this.parentNode ) { + this.parentNode.insertBefore( elem, this ); + } + }); + }, + + after: function() { + return this.domManip( arguments, false, function( elem ) { + if ( this.parentNode ) { + this.parentNode.insertBefore( elem, this.nextSibling ); + } + }); + }, + + // keepData is for internal use only--do not document + remove: function( selector, keepData ) { + var elem, + i = 0; + + for ( ; (elem = this[i]) != null; i++ ) { + if ( !selector || jQuery.filter( selector, [ elem ] ).length > 0 ) { + if ( !keepData && elem.nodeType === 1 ) { + jQuery.cleanData( getAll( elem ) ); + } + + if ( elem.parentNode ) { + if ( keepData && jQuery.contains( elem.ownerDocument, elem ) ) { + setGlobalEval( getAll( elem, "script" ) ); + } + elem.parentNode.removeChild( elem ); + } + } + } + + return this; + }, + + empty: function() { + var elem, + i = 0; + + for ( ; (elem = this[i]) != null; i++ ) { + // Remove element nodes and prevent memory leaks + if ( elem.nodeType === 1 ) { + jQuery.cleanData( getAll( elem, false ) ); + } + + // Remove any remaining nodes + while ( elem.firstChild ) { + elem.removeChild( elem.firstChild ); + } + + // If this is a select, ensure that it displays empty (#12336) + // Support: IE<9 + if ( elem.options && jQuery.nodeName( elem, "select" ) ) { + elem.options.length = 0; + } + } + + return this; + }, + + clone: function( dataAndEvents, deepDataAndEvents ) { + dataAndEvents = dataAndEvents == null ? false : dataAndEvents; + deepDataAndEvents = deepDataAndEvents == null ? dataAndEvents : deepDataAndEvents; + + return this.map( function () { + return jQuery.clone( this, dataAndEvents, deepDataAndEvents ); + }); + }, + + html: function( value ) { + return jQuery.access( this, function( value ) { + var elem = this[0] || {}, + i = 0, + l = this.length; + + if ( value === undefined ) { + return elem.nodeType === 1 ? + elem.innerHTML.replace( rinlinejQuery, "" ) : + undefined; + } + + // See if we can take a shortcut and just use innerHTML + if ( typeof value === "string" && !rnoInnerhtml.test( value ) && + ( jQuery.support.htmlSerialize || !rnoshimcache.test( value ) ) && + ( jQuery.support.leadingWhitespace || !rleadingWhitespace.test( value ) ) && + !wrapMap[ ( rtagName.exec( value ) || ["", ""] )[1].toLowerCase() ] ) { + + value = value.replace( rxhtmlTag, "<$1>" ); + + try { + for (; i < l; i++ ) { + // Remove element nodes and prevent memory leaks + elem = this[i] || {}; + if ( elem.nodeType === 1 ) { + jQuery.cleanData( getAll( elem, false ) ); + elem.innerHTML = value; + } + } + + elem = 0; + + // If using innerHTML throws an exception, use the fallback method + } catch(e) {} + } + + if ( elem ) { + this.empty().append( value ); + } + }, null, value, arguments.length ); + }, + + replaceWith: function( value ) { + var isFunc = jQuery.isFunction( value ); + + // Make sure that the elements are removed from the DOM before they are inserted + // this can help fix replacing a parent with child elements + if ( !isFunc && typeof value !== "string" ) { + value = jQuery( value ).not( this ).detach(); + } + + return this.domManip( [ value ], true, function( elem ) { + var next = this.nextSibling, + parent = this.parentNode; + + if ( parent && this.nodeType === 1 || this.nodeType === 11 ) { + + jQuery( this ).remove(); + + if ( next ) { + next.parentNode.insertBefore( elem, next ); + } else { + parent.appendChild( elem ); + } + } + }); + }, + + detach: function( selector ) { + return this.remove( selector, true ); + }, + + domManip: function( args, table, callback ) { + + // Flatten any nested arrays + args = core_concat.apply( [], args ); + + var fragment, first, scripts, hasScripts, node, doc, + i = 0, + l = this.length, + set = this, + iNoClone = l - 1, + value = args[0], + isFunction = jQuery.isFunction( value ); + + // We can't cloneNode fragments that contain checked, in WebKit + if ( isFunction || !( l <= 1 || typeof value !== "string" || jQuery.support.checkClone || !rchecked.test( value ) ) ) { + return this.each(function( index ) { + var self = set.eq( index ); + if ( isFunction ) { + args[0] = value.call( this, index, table ? self.html() : undefined ); + } + self.domManip( args, table, callback ); + }); + } + + if ( l ) { + fragment = jQuery.buildFragment( args, this[ 0 ].ownerDocument, false, this ); + first = fragment.firstChild; + + if ( fragment.childNodes.length === 1 ) { + fragment = first; + } + + if ( first ) { + table = table && jQuery.nodeName( first, "tr" ); + scripts = jQuery.map( getAll( fragment, "script" ), disableScript ); + hasScripts = scripts.length; + + // Use the original fragment for the last item instead of the first because it can end up + // being emptied incorrectly in certain situations (#8070). + for ( ; i < l; i++ ) { + node = fragment; + + if ( i !== iNoClone ) { + node = jQuery.clone( node, true, true ); + + // Keep references to cloned scripts for later restoration + if ( hasScripts ) { + jQuery.merge( scripts, getAll( node, "script" ) ); + } + } + + callback.call( + table && jQuery.nodeName( this[i], "table" ) ? + findOrAppend( this[i], "tbody" ) : + this[i], + node, + i + ); + } + + if ( hasScripts ) { + doc = scripts[ scripts.length - 1 ].ownerDocument; + + // Reenable scripts + jQuery.map( scripts, restoreScript ); + + // Evaluate executable scripts on first document insertion + for ( i = 0; i < hasScripts; i++ ) { + node = scripts[ i ]; + if ( rscriptType.test( node.type || "" ) && + !jQuery._data( node, "globalEval" ) && jQuery.contains( doc, node ) ) { + + if ( node.src ) { + // Hope ajax is available... + jQuery.ajax({ + url: node.src, + type: "GET", + dataType: "script", + async: false, + global: false, + "throws": true + }); + } else { + jQuery.globalEval( ( node.text || node.textContent || node.innerHTML || "" ).replace( rcleanScript, "" ) ); + } + } + } + } + + // Fix #11809: Avoid leaking memory + fragment = first = null; + } + } + + return this; + } +}); + +function findOrAppend( elem, tag ) { + return elem.getElementsByTagName( tag )[0] || elem.appendChild( elem.ownerDocument.createElement( tag ) ); +} + +// Replace/restore the type attribute of script elements for safe DOM manipulation +function disableScript( elem ) { + var attr = elem.getAttributeNode("type"); + elem.type = ( attr && attr.specified ) + "/" + elem.type; + return elem; +} +function restoreScript( elem ) { + var match = rscriptTypeMasked.exec( elem.type ); + if ( match ) { + elem.type = match[1]; + } else { + elem.removeAttribute("type"); + } + return elem; +} + +// Mark scripts as having already been evaluated +function setGlobalEval( elems, refElements ) { + var elem, + i = 0; + for ( ; (elem = elems[i]) != null; i++ ) { + jQuery._data( elem, "globalEval", !refElements || jQuery._data( refElements[i], "globalEval" ) ); + } +} + +function cloneCopyEvent( src, dest ) { + + if ( dest.nodeType !== 1 || !jQuery.hasData( src ) ) { + return; + } + + var type, i, l, + oldData = jQuery._data( src ), + curData = jQuery._data( dest, oldData ), + events = oldData.events; + + if ( events ) { + delete curData.handle; + curData.events = {}; + + for ( type in events ) { + for ( i = 0, l = events[ type ].length; i < l; i++ ) { + jQuery.event.add( dest, type, events[ type ][ i ] ); + } + } + } + + // make the cloned public data object a copy from the original + if ( curData.data ) { + curData.data = jQuery.extend( {}, curData.data ); + } +} + +function fixCloneNodeIssues( src, dest ) { + var nodeName, data, e; + + // We do not need to do anything for non-Elements + if ( dest.nodeType !== 1 ) { + return; + } + + nodeName = dest.nodeName.toLowerCase(); + + // IE6-8 copies events bound via attachEvent when using cloneNode. + if ( !jQuery.support.noCloneEvent && dest[ jQuery.expando ] ) { + data = jQuery._data( dest ); + + for ( e in data.events ) { + jQuery.removeEvent( dest, e, data.handle ); + } + + // Event data gets referenced instead of copied if the expando gets copied too + dest.removeAttribute( jQuery.expando ); + } + + // IE blanks contents when cloning scripts, and tries to evaluate newly-set text + if ( nodeName === "script" && dest.text !== src.text ) { + disableScript( dest ).text = src.text; + restoreScript( dest ); + + // IE6-10 improperly clones children of object elements using classid. + // IE10 throws NoModificationAllowedError if parent is null, #12132. + } else if ( nodeName === "object" ) { + if ( dest.parentNode ) { + dest.outerHTML = src.outerHTML; + } + + // This path appears unavoidable for IE9. When cloning an object + // element in IE9, the outerHTML strategy above is not sufficient. + // If the src has innerHTML and the destination does not, + // copy the src.innerHTML into the dest.innerHTML. #10324 + if ( jQuery.support.html5Clone && ( src.innerHTML && !jQuery.trim(dest.innerHTML) ) ) { + dest.innerHTML = src.innerHTML; + } + + } else if ( nodeName === "input" && manipulation_rcheckableType.test( src.type ) ) { + // IE6-8 fails to persist the checked state of a cloned checkbox + // or radio button. Worse, IE6-7 fail to give the cloned element + // a checked appearance if the defaultChecked value isn't also set + + dest.defaultChecked = dest.checked = src.checked; + + // IE6-7 get confused and end up setting the value of a cloned + // checkbox/radio button to an empty string instead of "on" + if ( dest.value !== src.value ) { + dest.value = src.value; + } + + // IE6-8 fails to return the selected option to the default selected + // state when cloning options + } else if ( nodeName === "option" ) { + dest.defaultSelected = dest.selected = src.defaultSelected; + + // IE6-8 fails to set the defaultValue to the correct value when + // cloning other types of input fields + } else if ( nodeName === "input" || nodeName === "textarea" ) { + dest.defaultValue = src.defaultValue; + } +} + +jQuery.each({ + appendTo: "append", + prependTo: "prepend", + insertBefore: "before", + insertAfter: "after", + replaceAll: "replaceWith" +}, function( name, original ) { + jQuery.fn[ name ] = function( selector ) { + var elems, + i = 0, + ret = [], + insert = jQuery( selector ), + last = insert.length - 1; + + for ( ; i <= last; i++ ) { + elems = i === last ? this : this.clone(true); + jQuery( insert[i] )[ original ]( elems ); + + // Modern browsers can apply jQuery collections as arrays, but oldIE needs a .get() + core_push.apply( ret, elems.get() ); + } + + return this.pushStack( ret ); + }; +}); + +function getAll( context, tag ) { + var elems, elem, + i = 0, + found = typeof context.getElementsByTagName !== "undefined" ? context.getElementsByTagName( tag || "*" ) : + typeof context.querySelectorAll !== "undefined" ? context.querySelectorAll( tag || "*" ) : + undefined; + + if ( !found ) { + for ( found = [], elems = context.childNodes || context; (elem = elems[i]) != null; i++ ) { + if ( !tag || jQuery.nodeName( elem, tag ) ) { + found.push( elem ); + } else { + jQuery.merge( found, getAll( elem, tag ) ); + } + } + } + + return tag === undefined || tag && jQuery.nodeName( context, tag ) ? + jQuery.merge( [ context ], found ) : + found; +} + +// Used in buildFragment, fixes the defaultChecked property +function fixDefaultChecked( elem ) { + if ( manipulation_rcheckableType.test( elem.type ) ) { + elem.defaultChecked = elem.checked; + } +} + +jQuery.extend({ + clone: function( elem, dataAndEvents, deepDataAndEvents ) { + var destElements, srcElements, node, i, clone, + inPage = jQuery.contains( elem.ownerDocument, elem ); + + if ( jQuery.support.html5Clone || jQuery.isXMLDoc(elem) || !rnoshimcache.test( "<" + elem.nodeName + ">" ) ) { + clone = elem.cloneNode( true ); + + // IE<=8 does not properly clone detached, unknown element nodes + } else { + fragmentDiv.innerHTML = elem.outerHTML; + fragmentDiv.removeChild( clone = fragmentDiv.firstChild ); + } + + if ( (!jQuery.support.noCloneEvent || !jQuery.support.noCloneChecked) && + (elem.nodeType === 1 || elem.nodeType === 11) && !jQuery.isXMLDoc(elem) ) { + + // We eschew Sizzle here for performance reasons: http://jsperf.com/getall-vs-sizzle/2 + destElements = getAll( clone ); + srcElements = getAll( elem ); + + // Fix all IE cloning issues + for ( i = 0; (node = srcElements[i]) != null; ++i ) { + // Ensure that the destination node is not null; Fixes #9587 + if ( destElements[i] ) { + fixCloneNodeIssues( node, destElements[i] ); + } + } + } + + // Copy the events from the original to the clone + if ( dataAndEvents ) { + if ( deepDataAndEvents ) { + srcElements = srcElements || getAll( elem ); + destElements = destElements || getAll( clone ); + + for ( i = 0; (node = srcElements[i]) != null; i++ ) { + cloneCopyEvent( node, destElements[i] ); + } + } else { + cloneCopyEvent( elem, clone ); + } + } + + // Preserve script evaluation history + destElements = getAll( clone, "script" ); + if ( destElements.length > 0 ) { + setGlobalEval( destElements, !inPage && getAll( elem, "script" ) ); + } + + destElements = srcElements = node = null; + + // Return the cloned set + return clone; + }, + + buildFragment: function( elems, context, scripts, selection ) { + var contains, elem, tag, tmp, wrap, tbody, j, + l = elems.length, + + // Ensure a safe fragment + safe = createSafeFragment( context ), + + nodes = [], + i = 0; + + for ( ; i < l; i++ ) { + elem = elems[ i ]; + + if ( elem || elem === 0 ) { + + // Add nodes directly + if ( jQuery.type( elem ) === "object" ) { + jQuery.merge( nodes, elem.nodeType ? [ elem ] : elem ); + + // Convert non-html into a text node + } else if ( !rhtml.test( elem ) ) { + nodes.push( context.createTextNode( elem ) ); + + // Convert html into DOM nodes + } else { + tmp = tmp || safe.appendChild( context.createElement("div") ); + + // Deserialize a standard representation + tag = ( rtagName.exec( elem ) || ["", ""] )[1].toLowerCase(); + wrap = wrapMap[ tag ] || wrapMap._default; + + tmp.innerHTML = wrap[1] + elem.replace( rxhtmlTag, "<$1>" ) + wrap[2]; + + // Descend through wrappers to the right content + j = wrap[0]; + while ( j-- ) { + tmp = tmp.lastChild; + } + + // Manually add leading whitespace removed by IE + if ( !jQuery.support.leadingWhitespace && rleadingWhitespace.test( elem ) ) { + nodes.push( context.createTextNode( rleadingWhitespace.exec( elem )[0] ) ); + } + + // Remove IE's autoinserted from table fragments + if ( !jQuery.support.tbody ) { + + // String was a , *may* have spurious + elem = tag === "table" && !rtbody.test( elem ) ? + tmp.firstChild : + + // String was a bare or + wrap[1] === "
    " && !rtbody.test( elem ) ? + tmp : + 0; + + j = elem && elem.childNodes.length; + while ( j-- ) { + if ( jQuery.nodeName( (tbody = elem.childNodes[j]), "tbody" ) && !tbody.childNodes.length ) { + elem.removeChild( tbody ); + } + } + } + + jQuery.merge( nodes, tmp.childNodes ); + + // Fix #12392 for WebKit and IE > 9 + tmp.textContent = ""; + + // Fix #12392 for oldIE + while ( tmp.firstChild ) { + tmp.removeChild( tmp.firstChild ); + } + + // Remember the top-level container for proper cleanup + tmp = safe.lastChild; + } + } + } + + // Fix #11356: Clear elements from fragment + if ( tmp ) { + safe.removeChild( tmp ); + } + + // Reset defaultChecked for any radios and checkboxes + // about to be appended to the DOM in IE 6/7 (#8060) + if ( !jQuery.support.appendChecked ) { + jQuery.grep( getAll( nodes, "input" ), fixDefaultChecked ); + } + + i = 0; + while ( (elem = nodes[ i++ ]) ) { + + // #4087 - If origin and destination elements are the same, and this is + // that element, do not do anything + if ( selection && jQuery.inArray( elem, selection ) !== -1 ) { + continue; + } + + contains = jQuery.contains( elem.ownerDocument, elem ); + + // Append to fragment + tmp = getAll( safe.appendChild( elem ), "script" ); + + // Preserve script evaluation history + if ( contains ) { + setGlobalEval( tmp ); + } + + // Capture executables + if ( scripts ) { + j = 0; + while ( (elem = tmp[ j++ ]) ) { + if ( rscriptType.test( elem.type || "" ) ) { + scripts.push( elem ); + } + } + } + } + + tmp = null; + + return safe; + }, + + cleanData: function( elems, /* internal */ acceptData ) { + var data, id, elem, type, + i = 0, + internalKey = jQuery.expando, + cache = jQuery.cache, + deleteExpando = jQuery.support.deleteExpando, + special = jQuery.event.special; + + for ( ; (elem = elems[i]) != null; i++ ) { + + if ( acceptData || jQuery.acceptData( elem ) ) { + + id = elem[ internalKey ]; + data = id && cache[ id ]; + + if ( data ) { + if ( data.events ) { + for ( type in data.events ) { + if ( special[ type ] ) { + jQuery.event.remove( elem, type ); + + // This is a shortcut to avoid jQuery.event.remove's overhead + } else { + jQuery.removeEvent( elem, type, data.handle ); + } + } + } + + // Remove cache only if it was not already removed by jQuery.event.remove + if ( cache[ id ] ) { + + delete cache[ id ]; + + // IE does not allow us to delete expando properties from nodes, + // nor does it have a removeAttribute function on Document nodes; + // we must handle all of these cases + if ( deleteExpando ) { + delete elem[ internalKey ]; + + } else if ( typeof elem.removeAttribute !== "undefined" ) { + elem.removeAttribute( internalKey ); + + } else { + elem[ internalKey ] = null; + } + + core_deletedIds.push( id ); + } + } + } + } + } +}); +var curCSS, getStyles, iframe, + ralpha = /alpha\([^)]*\)/i, + ropacity = /opacity\s*=\s*([^)]*)/, + rposition = /^(top|right|bottom|left)$/, + // swappable if display is none or starts with table except "table", "table-cell", or "table-caption" + // see here for display values: https://developer.mozilla.org/en-US/docs/CSS/display + rdisplayswap = /^(none|table(?!-c[ea]).+)/, + rmargin = /^margin/, + rnumsplit = new RegExp( "^(" + core_pnum + ")(.*)$", "i" ), + rnumnonpx = new RegExp( "^(" + core_pnum + ")(?!px)[a-z%]+$", "i" ), + rrelNum = new RegExp( "^([+-])=(" + core_pnum + ")", "i" ), + elemdisplay = { BODY: "block" }, + + cssShow = { position: "absolute", visibility: "hidden", display: "block" }, + cssNormalTransform = { + letterSpacing: 0, + fontWeight: 400 + }, + + cssExpand = [ "Top", "Right", "Bottom", "Left" ], + cssPrefixes = [ "Webkit", "O", "Moz", "ms" ]; + +// return a css property mapped to a potentially vendor prefixed property +function vendorPropName( style, name ) { + + // shortcut for names that are not vendor prefixed + if ( name in style ) { + return name; + } + + // check for vendor prefixed names + var capName = name.charAt(0).toUpperCase() + name.slice(1), + origName = name, + i = cssPrefixes.length; + + while ( i-- ) { + name = cssPrefixes[ i ] + capName; + if ( name in style ) { + return name; + } + } + + return origName; +} + +function isHidden( elem, el ) { + // isHidden might be called from jQuery#filter function; + // in that case, element will be second argument + elem = el || elem; + return jQuery.css( elem, "display" ) === "none" || !jQuery.contains( elem.ownerDocument, elem ); +} + +function showHide( elements, show ) { + var elem, + values = [], + index = 0, + length = elements.length; + + for ( ; index < length; index++ ) { + elem = elements[ index ]; + if ( !elem.style ) { + continue; + } + values[ index ] = jQuery._data( elem, "olddisplay" ); + if ( show ) { + // Reset the inline display of this element to learn if it is + // being hidden by cascaded rules or not + if ( !values[ index ] && elem.style.display === "none" ) { + elem.style.display = ""; + } + + // Set elements which have been overridden with display: none + // in a stylesheet to whatever the default browser style is + // for such an element + if ( elem.style.display === "" && isHidden( elem ) ) { + values[ index ] = jQuery._data( elem, "olddisplay", css_defaultDisplay(elem.nodeName) ); + } + } else if ( !values[ index ] && !isHidden( elem ) ) { + jQuery._data( elem, "olddisplay", jQuery.css( elem, "display" ) ); + } + } + + // Set the display of most of the elements in a second loop + // to avoid the constant reflow + for ( index = 0; index < length; index++ ) { + elem = elements[ index ]; + if ( !elem.style ) { + continue; + } + if ( !show || elem.style.display === "none" || elem.style.display === "" ) { + elem.style.display = show ? values[ index ] || "" : "none"; + } + } + + return elements; +} + +jQuery.fn.extend({ + css: function( name, value ) { + return jQuery.access( this, function( elem, name, value ) { + var styles, len, + map = {}, + i = 0; + + if ( jQuery.isArray( name ) ) { + styles = getStyles( elem ); + len = name.length; + + for ( ; i < len; i++ ) { + map[ name[ i ] ] = jQuery.css( elem, name[ i ], false, styles ); + } + + return map; + } + + return value !== undefined ? + jQuery.style( elem, name, value ) : + jQuery.css( elem, name ); + }, name, value, arguments.length > 1 ); + }, + show: function() { + return showHide( this, true ); + }, + hide: function() { + return showHide( this ); + }, + toggle: function( state ) { + var bool = typeof state === "boolean"; + + return this.each(function() { + if ( bool ? state : isHidden( this ) ) { + jQuery( this ).show(); + } else { + jQuery( this ).hide(); + } + }); + } +}); + +jQuery.extend({ + // Add in style property hooks for overriding the default + // behavior of getting and setting a style property + cssHooks: { + opacity: { + get: function( elem, computed ) { + if ( computed ) { + // We should always get a number back from opacity + var ret = curCSS( elem, "opacity" ); + return ret === "" ? "1" : ret; + } + } + } + }, + + // Exclude the following css properties to add px + cssNumber: { + "columnCount": true, + "fillOpacity": true, + "fontWeight": true, + "lineHeight": true, + "opacity": true, + "orphans": true, + "widows": true, + "zIndex": true, + "zoom": true + }, + + // Add in properties whose names you wish to fix before + // setting or getting the value + cssProps: { + // normalize float css property + "float": jQuery.support.cssFloat ? "cssFloat" : "styleFloat" + }, + + // Get and set the style property on a DOM Node + style: function( elem, name, value, extra ) { + // Don't set styles on text and comment nodes + if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 || !elem.style ) { + return; + } + + // Make sure that we're working with the right name + var ret, type, hooks, + origName = jQuery.camelCase( name ), + style = elem.style; + + name = jQuery.cssProps[ origName ] || ( jQuery.cssProps[ origName ] = vendorPropName( style, origName ) ); + + // gets hook for the prefixed version + // followed by the unprefixed version + hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ]; + + // Check if we're setting a value + if ( value !== undefined ) { + type = typeof value; + + // convert relative number strings (+= or -=) to relative numbers. #7345 + if ( type === "string" && (ret = rrelNum.exec( value )) ) { + value = ( ret[1] + 1 ) * ret[2] + parseFloat( jQuery.css( elem, name ) ); + // Fixes bug #9237 + type = "number"; + } + + // Make sure that NaN and null values aren't set. See: #7116 + if ( value == null || type === "number" && isNaN( value ) ) { + return; + } + + // If a number was passed in, add 'px' to the (except for certain CSS properties) + if ( type === "number" && !jQuery.cssNumber[ origName ] ) { + value += "px"; + } + + // Fixes #8908, it can be done more correctly by specifing setters in cssHooks, + // but it would mean to define eight (for every problematic property) identical functions + if ( !jQuery.support.clearCloneStyle && value === "" && name.indexOf("background") === 0 ) { + style[ name ] = "inherit"; + } + + // If a hook was provided, use that value, otherwise just set the specified value + if ( !hooks || !("set" in hooks) || (value = hooks.set( elem, value, extra )) !== undefined ) { + + // Wrapped to prevent IE from throwing errors when 'invalid' values are provided + // Fixes bug #5509 + try { + style[ name ] = value; + } catch(e) {} + } + + } else { + // If a hook was provided get the non-computed value from there + if ( hooks && "get" in hooks && (ret = hooks.get( elem, false, extra )) !== undefined ) { + return ret; + } + + // Otherwise just get the value from the style object + return style[ name ]; + } + }, + + css: function( elem, name, extra, styles ) { + var val, num, hooks, + origName = jQuery.camelCase( name ); + + // Make sure that we're working with the right name + name = jQuery.cssProps[ origName ] || ( jQuery.cssProps[ origName ] = vendorPropName( elem.style, origName ) ); + + // gets hook for the prefixed version + // followed by the unprefixed version + hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ]; + + // If a hook was provided get the computed value from there + if ( hooks && "get" in hooks ) { + val = hooks.get( elem, true, extra ); + } + + // Otherwise, if a way to get the computed value exists, use that + if ( val === undefined ) { + val = curCSS( elem, name, styles ); + } + + //convert "normal" to computed value + if ( val === "normal" && name in cssNormalTransform ) { + val = cssNormalTransform[ name ]; + } + + // Return, converting to number if forced or a qualifier was provided and val looks numeric + if ( extra ) { + num = parseFloat( val ); + return extra === true || jQuery.isNumeric( num ) ? num || 0 : val; + } + return val; + }, + + // A method for quickly swapping in/out CSS properties to get correct calculations + swap: function( elem, options, callback, args ) { + var ret, name, + old = {}; + + // Remember the old values, and insert the new ones + for ( name in options ) { + old[ name ] = elem.style[ name ]; + elem.style[ name ] = options[ name ]; + } + + ret = callback.apply( elem, args || [] ); + + // Revert the old values + for ( name in options ) { + elem.style[ name ] = old[ name ]; + } + + return ret; + } +}); + +// NOTE: we've included the "window" in window.getComputedStyle +// because jsdom on node.js will break without it. +if ( window.getComputedStyle ) { + getStyles = function( elem ) { + return window.getComputedStyle( elem, null ); + }; + + curCSS = function( elem, name, _computed ) { + var width, minWidth, maxWidth, + computed = _computed || getStyles( elem ), + + // getPropertyValue is only needed for .css('filter') in IE9, see #12537 + ret = computed ? computed.getPropertyValue( name ) || computed[ name ] : undefined, + style = elem.style; + + if ( computed ) { + + if ( ret === "" && !jQuery.contains( elem.ownerDocument, elem ) ) { + ret = jQuery.style( elem, name ); + } + + // A tribute to the "awesome hack by Dean Edwards" + // Chrome < 17 and Safari 5.0 uses "computed value" instead of "used value" for margin-right + // Safari 5.1.7 (at least) returns percentage for a larger set of values, but width seems to be reliably pixels + // this is against the CSSOM draft spec: http://dev.w3.org/csswg/cssom/#resolved-values + if ( rnumnonpx.test( ret ) && rmargin.test( name ) ) { + + // Remember the original values + width = style.width; + minWidth = style.minWidth; + maxWidth = style.maxWidth; + + // Put in the new values to get a computed value out + style.minWidth = style.maxWidth = style.width = ret; + ret = computed.width; + + // Revert the changed values + style.width = width; + style.minWidth = minWidth; + style.maxWidth = maxWidth; + } + } + + return ret; + }; +} else if ( document.documentElement.currentStyle ) { + getStyles = function( elem ) { + return elem.currentStyle; + }; + + curCSS = function( elem, name, _computed ) { + var left, rs, rsLeft, + computed = _computed || getStyles( elem ), + ret = computed ? computed[ name ] : undefined, + style = elem.style; + + // Avoid setting ret to empty string here + // so we don't default to auto + if ( ret == null && style && style[ name ] ) { + ret = style[ name ]; + } + + // From the awesome hack by Dean Edwards + // http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291 + + // If we're not dealing with a regular pixel number + // but a number that has a weird ending, we need to convert it to pixels + // but not position css attributes, as those are proportional to the parent element instead + // and we can't measure the parent instead because it might trigger a "stacking dolls" problem + if ( rnumnonpx.test( ret ) && !rposition.test( name ) ) { + + // Remember the original values + left = style.left; + rs = elem.runtimeStyle; + rsLeft = rs && rs.left; + + // Put in the new values to get a computed value out + if ( rsLeft ) { + rs.left = elem.currentStyle.left; + } + style.left = name === "fontSize" ? "1em" : ret; + ret = style.pixelLeft + "px"; + + // Revert the changed values + style.left = left; + if ( rsLeft ) { + rs.left = rsLeft; + } + } + + return ret === "" ? "auto" : ret; + }; +} + +function setPositiveNumber( elem, value, subtract ) { + var matches = rnumsplit.exec( value ); + return matches ? + // Guard against undefined "subtract", e.g., when used as in cssHooks + Math.max( 0, matches[ 1 ] - ( subtract || 0 ) ) + ( matches[ 2 ] || "px" ) : + value; +} + +function augmentWidthOrHeight( elem, name, extra, isBorderBox, styles ) { + var i = extra === ( isBorderBox ? "border" : "content" ) ? + // If we already have the right measurement, avoid augmentation + 4 : + // Otherwise initialize for horizontal or vertical properties + name === "width" ? 1 : 0, + + val = 0; + + for ( ; i < 4; i += 2 ) { + // both box models exclude margin, so add it if we want it + if ( extra === "margin" ) { + val += jQuery.css( elem, extra + cssExpand[ i ], true, styles ); + } + + if ( isBorderBox ) { + // border-box includes padding, so remove it if we want content + if ( extra === "content" ) { + val -= jQuery.css( elem, "padding" + cssExpand[ i ], true, styles ); + } + + // at this point, extra isn't border nor margin, so remove border + if ( extra !== "margin" ) { + val -= jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles ); + } + } else { + // at this point, extra isn't content, so add padding + val += jQuery.css( elem, "padding" + cssExpand[ i ], true, styles ); + + // at this point, extra isn't content nor padding, so add border + if ( extra !== "padding" ) { + val += jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles ); + } + } + } + + return val; +} + +function getWidthOrHeight( elem, name, extra ) { + + // Start with offset property, which is equivalent to the border-box value + var valueIsBorderBox = true, + val = name === "width" ? elem.offsetWidth : elem.offsetHeight, + styles = getStyles( elem ), + isBorderBox = jQuery.support.boxSizing && jQuery.css( elem, "boxSizing", false, styles ) === "border-box"; + + // some non-html elements return undefined for offsetWidth, so check for null/undefined + // svg - https://bugzilla.mozilla.org/show_bug.cgi?id=649285 + // MathML - https://bugzilla.mozilla.org/show_bug.cgi?id=491668 + if ( val <= 0 || val == null ) { + // Fall back to computed then uncomputed css if necessary + val = curCSS( elem, name, styles ); + if ( val < 0 || val == null ) { + val = elem.style[ name ]; + } + + // Computed unit is not pixels. Stop here and return. + if ( rnumnonpx.test(val) ) { + return val; + } + + // we need the check for style in case a browser which returns unreliable values + // for getComputedStyle silently falls back to the reliable elem.style + valueIsBorderBox = isBorderBox && ( jQuery.support.boxSizingReliable || val === elem.style[ name ] ); + + // Normalize "", auto, and prepare for extra + val = parseFloat( val ) || 0; + } + + // use the active box-sizing model to add/subtract irrelevant styles + return ( val + + augmentWidthOrHeight( + elem, + name, + extra || ( isBorderBox ? "border" : "content" ), + valueIsBorderBox, + styles + ) + ) + "px"; +} + +// Try to determine the default display value of an element +function css_defaultDisplay( nodeName ) { + var doc = document, + display = elemdisplay[ nodeName ]; + + if ( !display ) { + display = actualDisplay( nodeName, doc ); + + // If the simple way fails, read from inside an iframe + if ( display === "none" || !display ) { + // Use the already-created iframe if possible + iframe = ( iframe || + jQuery("' : ''); + inst._keyEvent = false; + return html; + }, + + /* Generate the month and year header. */ + _generateMonthYearHeader: function(inst, drawMonth, drawYear, minDate, maxDate, + secondary, monthNames, monthNamesShort) { + var changeMonth = this._get(inst, 'changeMonth'); + var changeYear = this._get(inst, 'changeYear'); + var showMonthAfterYear = this._get(inst, 'showMonthAfterYear'); + var html = '
    '; + var monthHtml = ''; + // month selection + if (secondary || !changeMonth) + monthHtml += '' + monthNames[drawMonth] + ''; + else { + var inMinYear = (minDate && minDate.getFullYear() == drawYear); + var inMaxYear = (maxDate && maxDate.getFullYear() == drawYear); + monthHtml += ''; + } + if (!showMonthAfterYear) + html += monthHtml + (secondary || !(changeMonth && changeYear) ? ' ' : ''); + // year selection + if ( !inst.yearshtml ) { + inst.yearshtml = ''; + if (secondary || !changeYear) + html += '' + drawYear + ''; + else { + // determine range of years to display + var years = this._get(inst, 'yearRange').split(':'); + var thisYear = new Date().getFullYear(); + var determineYear = function(value) { + var year = (value.match(/c[+-].*/) ? drawYear + parseInt(value.substring(1), 10) : + (value.match(/[+-].*/) ? thisYear + parseInt(value, 10) : + parseInt(value, 10))); + return (isNaN(year) ? thisYear : year); + }; + var year = determineYear(years[0]); + var endYear = Math.max(year, determineYear(years[1] || '')); + year = (minDate ? Math.max(year, minDate.getFullYear()) : year); + endYear = (maxDate ? Math.min(endYear, maxDate.getFullYear()) : endYear); + inst.yearshtml += ''; + + html += inst.yearshtml; + inst.yearshtml = null; + } + } + html += this._get(inst, 'yearSuffix'); + if (showMonthAfterYear) + html += (secondary || !(changeMonth && changeYear) ? ' ' : '') + monthHtml; + html += '
    '; // Close datepicker_header + return html; + }, + + /* Adjust one of the date sub-fields. */ + _adjustInstDate: function(inst, offset, period) { + var year = inst.drawYear + (period == 'Y' ? offset : 0); + var month = inst.drawMonth + (period == 'M' ? offset : 0); + var day = Math.min(inst.selectedDay, this._getDaysInMonth(year, month)) + + (period == 'D' ? offset : 0); + var date = this._restrictMinMax(inst, + this._daylightSavingAdjust(new Date(year, month, day))); + inst.selectedDay = date.getDate(); + inst.drawMonth = inst.selectedMonth = date.getMonth(); + inst.drawYear = inst.selectedYear = date.getFullYear(); + if (period == 'M' || period == 'Y') + this._notifyChange(inst); + }, + + /* Ensure a date is within any min/max bounds. */ + _restrictMinMax: function(inst, date) { + var minDate = this._getMinMaxDate(inst, 'min'); + var maxDate = this._getMinMaxDate(inst, 'max'); + var newDate = (minDate && date < minDate ? minDate : date); + newDate = (maxDate && newDate > maxDate ? maxDate : newDate); + return newDate; + }, + + /* Notify change of month/year. */ + _notifyChange: function(inst) { + var onChange = this._get(inst, 'onChangeMonthYear'); + if (onChange) + onChange.apply((inst.input ? inst.input[0] : null), + [inst.selectedYear, inst.selectedMonth + 1, inst]); + }, + + /* Determine the number of months to show. */ + _getNumberOfMonths: function(inst) { + var numMonths = this._get(inst, 'numberOfMonths'); + return (numMonths == null ? [1, 1] : (typeof numMonths == 'number' ? [1, numMonths] : numMonths)); + }, + + /* Determine the current maximum date - ensure no time components are set. */ + _getMinMaxDate: function(inst, minMax) { + return this._determineDate(inst, this._get(inst, minMax + 'Date'), null); + }, + + /* Find the number of days in a given month. */ + _getDaysInMonth: function(year, month) { + return 32 - this._daylightSavingAdjust(new Date(year, month, 32)).getDate(); + }, + + /* Find the day of the week of the first of a month. */ + _getFirstDayOfMonth: function(year, month) { + return new Date(year, month, 1).getDay(); + }, + + /* Determines if we should allow a "next/prev" month display change. */ + _canAdjustMonth: function(inst, offset, curYear, curMonth) { + var numMonths = this._getNumberOfMonths(inst); + var date = this._daylightSavingAdjust(new Date(curYear, + curMonth + (offset < 0 ? offset : numMonths[0] * numMonths[1]), 1)); + if (offset < 0) + date.setDate(this._getDaysInMonth(date.getFullYear(), date.getMonth())); + return this._isInRange(inst, date); + }, + + /* Is the given date in the accepted range? */ + _isInRange: function(inst, date) { + var minDate = this._getMinMaxDate(inst, 'min'); + var maxDate = this._getMinMaxDate(inst, 'max'); + return ((!minDate || date.getTime() >= minDate.getTime()) && + (!maxDate || date.getTime() <= maxDate.getTime())); + }, + + /* Provide the configuration settings for formatting/parsing. */ + _getFormatConfig: function(inst) { + var shortYearCutoff = this._get(inst, 'shortYearCutoff'); + shortYearCutoff = (typeof shortYearCutoff != 'string' ? shortYearCutoff : + new Date().getFullYear() % 100 + parseInt(shortYearCutoff, 10)); + return {shortYearCutoff: shortYearCutoff, + dayNamesShort: this._get(inst, 'dayNamesShort'), dayNames: this._get(inst, 'dayNames'), + monthNamesShort: this._get(inst, 'monthNamesShort'), monthNames: this._get(inst, 'monthNames')}; + }, + + /* Format the given date for display. */ + _formatDate: function(inst, day, month, year) { + if (!day) { + inst.currentDay = inst.selectedDay; + inst.currentMonth = inst.selectedMonth; + inst.currentYear = inst.selectedYear; + } + var date = (day ? (typeof day == 'object' ? day : + this._daylightSavingAdjust(new Date(year, month, day))) : + this._daylightSavingAdjust(new Date(inst.currentYear, inst.currentMonth, inst.currentDay))); + return this.formatDate(this._get(inst, 'dateFormat'), date, this._getFormatConfig(inst)); + } +}); + +/* + * Bind hover events for datepicker elements. + * Done via delegate so the binding only occurs once in the lifetime of the parent div. + * Global instActive, set by _updateDatepicker allows the handlers to find their way back to the active picker. + */ +function bindHover(dpDiv) { + var selector = 'button, .ui-datepicker-prev, .ui-datepicker-next, .ui-datepicker-calendar td a'; + return dpDiv.delegate(selector, 'mouseout', function() { + $(this).removeClass('ui-state-hover'); + if (this.className.indexOf('ui-datepicker-prev') != -1) $(this).removeClass('ui-datepicker-prev-hover'); + if (this.className.indexOf('ui-datepicker-next') != -1) $(this).removeClass('ui-datepicker-next-hover'); + }) + .delegate(selector, 'mouseover', function(){ + if (!$.datepicker._isDisabledDatepicker( instActive.inline ? dpDiv.parent()[0] : instActive.input[0])) { + $(this).parents('.ui-datepicker-calendar').find('a').removeClass('ui-state-hover'); + $(this).addClass('ui-state-hover'); + if (this.className.indexOf('ui-datepicker-prev') != -1) $(this).addClass('ui-datepicker-prev-hover'); + if (this.className.indexOf('ui-datepicker-next') != -1) $(this).addClass('ui-datepicker-next-hover'); + } + }); +} + +/* jQuery extend now ignores nulls! */ +function extendRemove(target, props) { + $.extend(target, props); + for (var name in props) + if (props[name] == null || props[name] == undefined) + target[name] = props[name]; + return target; +}; + +/* Invoke the datepicker functionality. + @param options string - a command, optionally followed by additional parameters or + Object - settings for attaching new datepicker functionality + @return jQuery object */ +$.fn.datepicker = function(options){ + + /* Verify an empty collection wasn't passed - Fixes #6976 */ + if ( !this.length ) { + return this; + } + + /* Initialise the date picker. */ + if (!$.datepicker.initialized) { + $(document).mousedown($.datepicker._checkExternalClick). + find(document.body).append($.datepicker.dpDiv); + $.datepicker.initialized = true; + } + + var otherArgs = Array.prototype.slice.call(arguments, 1); + if (typeof options == 'string' && (options == 'isDisabled' || options == 'getDate' || options == 'widget')) + return $.datepicker['_' + options + 'Datepicker']. + apply($.datepicker, [this[0]].concat(otherArgs)); + if (options == 'option' && arguments.length == 2 && typeof arguments[1] == 'string') + return $.datepicker['_' + options + 'Datepicker']. + apply($.datepicker, [this[0]].concat(otherArgs)); + return this.each(function() { + typeof options == 'string' ? + $.datepicker['_' + options + 'Datepicker']. + apply($.datepicker, [this].concat(otherArgs)) : + $.datepicker._attachDatepicker(this, options); + }); +}; + +$.datepicker = new Datepicker(); // singleton instance +$.datepicker.initialized = false; +$.datepicker.uuid = new Date().getTime(); +$.datepicker.version = "1.9.2"; + +// Workaround for #4055 +// Add another global to avoid noConflict issues with inline event handlers +window['DP_jQuery_' + dpuuid] = $; + +})(jQuery); +(function( $, undefined ) { + +var uiDialogClasses = "ui-dialog ui-widget ui-widget-content ui-corner-all ", + sizeRelatedOptions = { + buttons: true, + height: true, + maxHeight: true, + maxWidth: true, + minHeight: true, + minWidth: true, + width: true + }, + resizableRelatedOptions = { + maxHeight: true, + maxWidth: true, + minHeight: true, + minWidth: true + }; + +$.widget("ui.dialog", { + version: "1.9.2", + options: { + autoOpen: true, + buttons: {}, + closeOnEscape: true, + closeText: "close", + dialogClass: "", + draggable: true, + hide: null, + height: "auto", + maxHeight: false, + maxWidth: false, + minHeight: 150, + minWidth: 150, + modal: false, + position: { + my: "center", + at: "center", + of: window, + collision: "fit", + // ensure that the titlebar is never outside the document + using: function( pos ) { + var topOffset = $( this ).css( pos ).offset().top; + if ( topOffset < 0 ) { + $( this ).css( "top", pos.top - topOffset ); + } + } + }, + resizable: true, + show: null, + stack: true, + title: "", + width: 300, + zIndex: 1000 + }, + + _create: function() { + this.originalTitle = this.element.attr( "title" ); + // #5742 - .attr() might return a DOMElement + if ( typeof this.originalTitle !== "string" ) { + this.originalTitle = ""; + } + this.oldPosition = { + parent: this.element.parent(), + index: this.element.parent().children().index( this.element ) + }; + this.options.title = this.options.title || this.originalTitle; + var that = this, + options = this.options, + + title = options.title || " ", + uiDialog, + uiDialogTitlebar, + uiDialogTitlebarClose, + uiDialogTitle, + uiDialogButtonPane; + + uiDialog = ( this.uiDialog = $( "
    " ) ) + .addClass( uiDialogClasses + options.dialogClass ) + .css({ + display: "none", + outline: 0, // TODO: move to stylesheet + zIndex: options.zIndex + }) + // setting tabIndex makes the div focusable + .attr( "tabIndex", -1) + .keydown(function( event ) { + if ( options.closeOnEscape && !event.isDefaultPrevented() && event.keyCode && + event.keyCode === $.ui.keyCode.ESCAPE ) { + that.close( event ); + event.preventDefault(); + } + }) + .mousedown(function( event ) { + that.moveToTop( false, event ); + }) + .appendTo( "body" ); + + this.element + .show() + .removeAttr( "title" ) + .addClass( "ui-dialog-content ui-widget-content" ) + .appendTo( uiDialog ); + + uiDialogTitlebar = ( this.uiDialogTitlebar = $( "
    " ) ) + .addClass( "ui-dialog-titlebar ui-widget-header " + + "ui-corner-all ui-helper-clearfix" ) + .bind( "mousedown", function() { + // Dialog isn't getting focus when dragging (#8063) + uiDialog.focus(); + }) + .prependTo( uiDialog ); + + uiDialogTitlebarClose = $( "" ) + .addClass( "ui-dialog-titlebar-close ui-corner-all" ) + .attr( "role", "button" ) + .click(function( event ) { + event.preventDefault(); + that.close( event ); + }) + .appendTo( uiDialogTitlebar ); + + ( this.uiDialogTitlebarCloseText = $( "" ) ) + .addClass( "ui-icon ui-icon-closethick" ) + .text( options.closeText ) + .appendTo( uiDialogTitlebarClose ); + + uiDialogTitle = $( "" ) + .uniqueId() + .addClass( "ui-dialog-title" ) + .html( title ) + .prependTo( uiDialogTitlebar ); + + uiDialogButtonPane = ( this.uiDialogButtonPane = $( "
    " ) ) + .addClass( "ui-dialog-buttonpane ui-widget-content ui-helper-clearfix" ); + + ( this.uiButtonSet = $( "
    " ) ) + .addClass( "ui-dialog-buttonset" ) + .appendTo( uiDialogButtonPane ); + + uiDialog.attr({ + role: "dialog", + "aria-labelledby": uiDialogTitle.attr( "id" ) + }); + + uiDialogTitlebar.find( "*" ).add( uiDialogTitlebar ).disableSelection(); + this._hoverable( uiDialogTitlebarClose ); + this._focusable( uiDialogTitlebarClose ); + + if ( options.draggable && $.fn.draggable ) { + this._makeDraggable(); + } + if ( options.resizable && $.fn.resizable ) { + this._makeResizable(); + } + + this._createButtons( options.buttons ); + this._isOpen = false; + + if ( $.fn.bgiframe ) { + uiDialog.bgiframe(); + } + + // prevent tabbing out of modal dialogs + this._on( uiDialog, { keydown: function( event ) { + if ( !options.modal || event.keyCode !== $.ui.keyCode.TAB ) { + return; + } + + var tabbables = $( ":tabbable", uiDialog ), + first = tabbables.filter( ":first" ), + last = tabbables.filter( ":last" ); + + if ( event.target === last[0] && !event.shiftKey ) { + first.focus( 1 ); + return false; + } else if ( event.target === first[0] && event.shiftKey ) { + last.focus( 1 ); + return false; + } + }}); + }, + + _init: function() { + if ( this.options.autoOpen ) { + this.open(); + } + }, + + _destroy: function() { + var next, + oldPosition = this.oldPosition; + + if ( this.overlay ) { + this.overlay.destroy(); + } + this.uiDialog.hide(); + this.element + .removeClass( "ui-dialog-content ui-widget-content" ) + .hide() + .appendTo( "body" ); + this.uiDialog.remove(); + + if ( this.originalTitle ) { + this.element.attr( "title", this.originalTitle ); + } + + next = oldPosition.parent.children().eq( oldPosition.index ); + // Don't try to place the dialog next to itself (#8613) + if ( next.length && next[ 0 ] !== this.element[ 0 ] ) { + next.before( this.element ); + } else { + oldPosition.parent.append( this.element ); + } + }, + + widget: function() { + return this.uiDialog; + }, + + close: function( event ) { + var that = this, + maxZ, thisZ; + + if ( !this._isOpen ) { + return; + } + + if ( false === this._trigger( "beforeClose", event ) ) { + return; + } + + this._isOpen = false; + + if ( this.overlay ) { + this.overlay.destroy(); + } + + if ( this.options.hide ) { + this._hide( this.uiDialog, this.options.hide, function() { + that._trigger( "close", event ); + }); + } else { + this.uiDialog.hide(); + this._trigger( "close", event ); + } + + $.ui.dialog.overlay.resize(); + + // adjust the maxZ to allow other modal dialogs to continue to work (see #4309) + if ( this.options.modal ) { + maxZ = 0; + $( ".ui-dialog" ).each(function() { + if ( this !== that.uiDialog[0] ) { + thisZ = $( this ).css( "z-index" ); + if ( !isNaN( thisZ ) ) { + maxZ = Math.max( maxZ, thisZ ); + } + } + }); + $.ui.dialog.maxZ = maxZ; + } + + return this; + }, + + isOpen: function() { + return this._isOpen; + }, + + // the force parameter allows us to move modal dialogs to their correct + // position on open + moveToTop: function( force, event ) { + var options = this.options, + saveScroll; + + if ( ( options.modal && !force ) || + ( !options.stack && !options.modal ) ) { + return this._trigger( "focus", event ); + } + + if ( options.zIndex > $.ui.dialog.maxZ ) { + $.ui.dialog.maxZ = options.zIndex; + } + if ( this.overlay ) { + $.ui.dialog.maxZ += 1; + $.ui.dialog.overlay.maxZ = $.ui.dialog.maxZ; + this.overlay.$el.css( "z-index", $.ui.dialog.overlay.maxZ ); + } + + // Save and then restore scroll + // Opera 9.5+ resets when parent z-index is changed. + // http://bugs.jqueryui.com/ticket/3193 + saveScroll = { + scrollTop: this.element.scrollTop(), + scrollLeft: this.element.scrollLeft() + }; + $.ui.dialog.maxZ += 1; + this.uiDialog.css( "z-index", $.ui.dialog.maxZ ); + this.element.attr( saveScroll ); + this._trigger( "focus", event ); + + return this; + }, + + open: function() { + if ( this._isOpen ) { + return; + } + + var hasFocus, + options = this.options, + uiDialog = this.uiDialog; + + this._size(); + this._position( options.position ); + uiDialog.show( options.show ); + this.overlay = options.modal ? new $.ui.dialog.overlay( this ) : null; + this.moveToTop( true ); + + // set focus to the first tabbable element in the content area or the first button + // if there are no tabbable elements, set focus on the dialog itself + hasFocus = this.element.find( ":tabbable" ); + if ( !hasFocus.length ) { + hasFocus = this.uiDialogButtonPane.find( ":tabbable" ); + if ( !hasFocus.length ) { + hasFocus = uiDialog; + } + } + hasFocus.eq( 0 ).focus(); + + this._isOpen = true; + this._trigger( "open" ); + + return this; + }, + + _createButtons: function( buttons ) { + var that = this, + hasButtons = false; + + // if we already have a button pane, remove it + this.uiDialogButtonPane.remove(); + this.uiButtonSet.empty(); + + if ( typeof buttons === "object" && buttons !== null ) { + $.each( buttons, function() { + return !(hasButtons = true); + }); + } + if ( hasButtons ) { + $.each( buttons, function( name, props ) { + var button, click; + props = $.isFunction( props ) ? + { click: props, text: name } : + props; + // Default to a non-submitting button + props = $.extend( { type: "button" }, props ); + // Change the context for the click callback to be the main element + click = props.click; + props.click = function() { + click.apply( that.element[0], arguments ); + }; + button = $( "", props ) + .appendTo( that.uiButtonSet ); + if ( $.fn.button ) { + button.button(); + } + }); + this.uiDialog.addClass( "ui-dialog-buttons" ); + this.uiDialogButtonPane.appendTo( this.uiDialog ); + } else { + this.uiDialog.removeClass( "ui-dialog-buttons" ); + } + }, + + _makeDraggable: function() { + var that = this, + options = this.options; + + function filteredUi( ui ) { + return { + position: ui.position, + offset: ui.offset + }; + } + + this.uiDialog.draggable({ + cancel: ".ui-dialog-content, .ui-dialog-titlebar-close", + handle: ".ui-dialog-titlebar", + containment: "document", + start: function( event, ui ) { + $( this ) + .addClass( "ui-dialog-dragging" ); + that._trigger( "dragStart", event, filteredUi( ui ) ); + }, + drag: function( event, ui ) { + that._trigger( "drag", event, filteredUi( ui ) ); + }, + stop: function( event, ui ) { + options.position = [ + ui.position.left - that.document.scrollLeft(), + ui.position.top - that.document.scrollTop() + ]; + $( this ) + .removeClass( "ui-dialog-dragging" ); + that._trigger( "dragStop", event, filteredUi( ui ) ); + $.ui.dialog.overlay.resize(); + } + }); + }, + + _makeResizable: function( handles ) { + handles = (handles === undefined ? this.options.resizable : handles); + var that = this, + options = this.options, + // .ui-resizable has position: relative defined in the stylesheet + // but dialogs have to use absolute or fixed positioning + position = this.uiDialog.css( "position" ), + resizeHandles = typeof handles === 'string' ? + handles : + "n,e,s,w,se,sw,ne,nw"; + + function filteredUi( ui ) { + return { + originalPosition: ui.originalPosition, + originalSize: ui.originalSize, + position: ui.position, + size: ui.size + }; + } + + this.uiDialog.resizable({ + cancel: ".ui-dialog-content", + containment: "document", + alsoResize: this.element, + maxWidth: options.maxWidth, + maxHeight: options.maxHeight, + minWidth: options.minWidth, + minHeight: this._minHeight(), + handles: resizeHandles, + start: function( event, ui ) { + $( this ).addClass( "ui-dialog-resizing" ); + that._trigger( "resizeStart", event, filteredUi( ui ) ); + }, + resize: function( event, ui ) { + that._trigger( "resize", event, filteredUi( ui ) ); + }, + stop: function( event, ui ) { + $( this ).removeClass( "ui-dialog-resizing" ); + options.height = $( this ).height(); + options.width = $( this ).width(); + that._trigger( "resizeStop", event, filteredUi( ui ) ); + $.ui.dialog.overlay.resize(); + } + }) + .css( "position", position ) + .find( ".ui-resizable-se" ) + .addClass( "ui-icon ui-icon-grip-diagonal-se" ); + }, + + _minHeight: function() { + var options = this.options; + + if ( options.height === "auto" ) { + return options.minHeight; + } else { + return Math.min( options.minHeight, options.height ); + } + }, + + _position: function( position ) { + var myAt = [], + offset = [ 0, 0 ], + isVisible; + + if ( position ) { + // deep extending converts arrays to objects in jQuery <= 1.3.2 :-( + // if (typeof position == 'string' || $.isArray(position)) { + // myAt = $.isArray(position) ? position : position.split(' '); + + if ( typeof position === "string" || (typeof position === "object" && "0" in position ) ) { + myAt = position.split ? position.split( " " ) : [ position[ 0 ], position[ 1 ] ]; + if ( myAt.length === 1 ) { + myAt[ 1 ] = myAt[ 0 ]; + } + + $.each( [ "left", "top" ], function( i, offsetPosition ) { + if ( +myAt[ i ] === myAt[ i ] ) { + offset[ i ] = myAt[ i ]; + myAt[ i ] = offsetPosition; + } + }); + + position = { + my: myAt[0] + (offset[0] < 0 ? offset[0] : "+" + offset[0]) + " " + + myAt[1] + (offset[1] < 0 ? offset[1] : "+" + offset[1]), + at: myAt.join( " " ) + }; + } + + position = $.extend( {}, $.ui.dialog.prototype.options.position, position ); + } else { + position = $.ui.dialog.prototype.options.position; + } + + // need to show the dialog to get the actual offset in the position plugin + isVisible = this.uiDialog.is( ":visible" ); + if ( !isVisible ) { + this.uiDialog.show(); + } + this.uiDialog.position( position ); + if ( !isVisible ) { + this.uiDialog.hide(); + } + }, + + _setOptions: function( options ) { + var that = this, + resizableOptions = {}, + resize = false; + + $.each( options, function( key, value ) { + that._setOption( key, value ); + + if ( key in sizeRelatedOptions ) { + resize = true; + } + if ( key in resizableRelatedOptions ) { + resizableOptions[ key ] = value; + } + }); + + if ( resize ) { + this._size(); + } + if ( this.uiDialog.is( ":data(resizable)" ) ) { + this.uiDialog.resizable( "option", resizableOptions ); + } + }, + + _setOption: function( key, value ) { + var isDraggable, isResizable, + uiDialog = this.uiDialog; + + switch ( key ) { + case "buttons": + this._createButtons( value ); + break; + case "closeText": + // ensure that we always pass a string + this.uiDialogTitlebarCloseText.text( "" + value ); + break; + case "dialogClass": + uiDialog + .removeClass( this.options.dialogClass ) + .addClass( uiDialogClasses + value ); + break; + case "disabled": + if ( value ) { + uiDialog.addClass( "ui-dialog-disabled" ); + } else { + uiDialog.removeClass( "ui-dialog-disabled" ); + } + break; + case "draggable": + isDraggable = uiDialog.is( ":data(draggable)" ); + if ( isDraggable && !value ) { + uiDialog.draggable( "destroy" ); + } + + if ( !isDraggable && value ) { + this._makeDraggable(); + } + break; + case "position": + this._position( value ); + break; + case "resizable": + // currently resizable, becoming non-resizable + isResizable = uiDialog.is( ":data(resizable)" ); + if ( isResizable && !value ) { + uiDialog.resizable( "destroy" ); + } + + // currently resizable, changing handles + if ( isResizable && typeof value === "string" ) { + uiDialog.resizable( "option", "handles", value ); + } + + // currently non-resizable, becoming resizable + if ( !isResizable && value !== false ) { + this._makeResizable( value ); + } + break; + case "title": + // convert whatever was passed in o a string, for html() to not throw up + $( ".ui-dialog-title", this.uiDialogTitlebar ) + .html( "" + ( value || " " ) ); + break; + } + + this._super( key, value ); + }, + + _size: function() { + /* If the user has resized the dialog, the .ui-dialog and .ui-dialog-content + * divs will both have width and height set, so we need to reset them + */ + var nonContentHeight, minContentHeight, autoHeight, + options = this.options, + isVisible = this.uiDialog.is( ":visible" ); + + // reset content sizing + this.element.show().css({ + width: "auto", + minHeight: 0, + height: 0 + }); + + if ( options.minWidth > options.width ) { + options.width = options.minWidth; + } + + // reset wrapper sizing + // determine the height of all the non-content elements + nonContentHeight = this.uiDialog.css({ + height: "auto", + width: options.width + }) + .outerHeight(); + minContentHeight = Math.max( 0, options.minHeight - nonContentHeight ); + + if ( options.height === "auto" ) { + // only needed for IE6 support + if ( $.support.minHeight ) { + this.element.css({ + minHeight: minContentHeight, + height: "auto" + }); + } else { + this.uiDialog.show(); + autoHeight = this.element.css( "height", "auto" ).height(); + if ( !isVisible ) { + this.uiDialog.hide(); + } + this.element.height( Math.max( autoHeight, minContentHeight ) ); + } + } else { + this.element.height( Math.max( options.height - nonContentHeight, 0 ) ); + } + + if (this.uiDialog.is( ":data(resizable)" ) ) { + this.uiDialog.resizable( "option", "minHeight", this._minHeight() ); + } + } +}); + +$.extend($.ui.dialog, { + uuid: 0, + maxZ: 0, + + getTitleId: function($el) { + var id = $el.attr( "id" ); + if ( !id ) { + this.uuid += 1; + id = this.uuid; + } + return "ui-dialog-title-" + id; + }, + + overlay: function( dialog ) { + this.$el = $.ui.dialog.overlay.create( dialog ); + } +}); + +$.extend( $.ui.dialog.overlay, { + instances: [], + // reuse old instances due to IE memory leak with alpha transparency (see #5185) + oldInstances: [], + maxZ: 0, + events: $.map( + "focus,mousedown,mouseup,keydown,keypress,click".split( "," ), + function( event ) { + return event + ".dialog-overlay"; + } + ).join( " " ), + create: function( dialog ) { + if ( this.instances.length === 0 ) { + // prevent use of anchors and inputs + // we use a setTimeout in case the overlay is created from an + // event that we're going to be cancelling (see #2804) + setTimeout(function() { + // handle $(el).dialog().dialog('close') (see #4065) + if ( $.ui.dialog.overlay.instances.length ) { + $( document ).bind( $.ui.dialog.overlay.events, function( event ) { + // stop events if the z-index of the target is < the z-index of the overlay + // we cannot return true when we don't want to cancel the event (#3523) + if ( $( event.target ).zIndex() < $.ui.dialog.overlay.maxZ ) { + return false; + } + }); + } + }, 1 ); + + // handle window resize + $( window ).bind( "resize.dialog-overlay", $.ui.dialog.overlay.resize ); + } + + var $el = ( this.oldInstances.pop() || $( "
    " ).addClass( "ui-widget-overlay" ) ); + + // allow closing by pressing the escape key + $( document ).bind( "keydown.dialog-overlay", function( event ) { + var instances = $.ui.dialog.overlay.instances; + // only react to the event if we're the top overlay + if ( instances.length !== 0 && instances[ instances.length - 1 ] === $el && + dialog.options.closeOnEscape && !event.isDefaultPrevented() && event.keyCode && + event.keyCode === $.ui.keyCode.ESCAPE ) { + + dialog.close( event ); + event.preventDefault(); + } + }); + + $el.appendTo( document.body ).css({ + width: this.width(), + height: this.height() + }); + + if ( $.fn.bgiframe ) { + $el.bgiframe(); + } + + this.instances.push( $el ); + return $el; + }, + + destroy: function( $el ) { + var indexOf = $.inArray( $el, this.instances ), + maxZ = 0; + + if ( indexOf !== -1 ) { + this.oldInstances.push( this.instances.splice( indexOf, 1 )[ 0 ] ); + } + + if ( this.instances.length === 0 ) { + $( [ document, window ] ).unbind( ".dialog-overlay" ); + } + + $el.height( 0 ).width( 0 ).remove(); + + // adjust the maxZ to allow other modal dialogs to continue to work (see #4309) + $.each( this.instances, function() { + maxZ = Math.max( maxZ, this.css( "z-index" ) ); + }); + this.maxZ = maxZ; + }, + + height: function() { + var scrollHeight, + offsetHeight; + // handle IE + if ( $.ui.ie ) { + scrollHeight = Math.max( + document.documentElement.scrollHeight, + document.body.scrollHeight + ); + offsetHeight = Math.max( + document.documentElement.offsetHeight, + document.body.offsetHeight + ); + + if ( scrollHeight < offsetHeight ) { + return $( window ).height() + "px"; + } else { + return scrollHeight + "px"; + } + // handle "good" browsers + } else { + return $( document ).height() + "px"; + } + }, + + width: function() { + var scrollWidth, + offsetWidth; + // handle IE + if ( $.ui.ie ) { + scrollWidth = Math.max( + document.documentElement.scrollWidth, + document.body.scrollWidth + ); + offsetWidth = Math.max( + document.documentElement.offsetWidth, + document.body.offsetWidth + ); + + if ( scrollWidth < offsetWidth ) { + return $( window ).width() + "px"; + } else { + return scrollWidth + "px"; + } + // handle "good" browsers + } else { + return $( document ).width() + "px"; + } + }, + + resize: function() { + /* If the dialog is draggable and the user drags it past the + * right edge of the window, the document becomes wider so we + * need to stretch the overlay. If the user then drags the + * dialog back to the left, the document will become narrower, + * so we need to shrink the overlay to the appropriate size. + * This is handled by shrinking the overlay before setting it + * to the full document size. + */ + var $overlays = $( [] ); + $.each( $.ui.dialog.overlay.instances, function() { + $overlays = $overlays.add( this ); + }); + + $overlays.css({ + width: 0, + height: 0 + }).css({ + width: $.ui.dialog.overlay.width(), + height: $.ui.dialog.overlay.height() + }); + } +}); + +$.extend( $.ui.dialog.overlay.prototype, { + destroy: function() { + $.ui.dialog.overlay.destroy( this.$el ); + } +}); + +}( jQuery ) ); +(function( $, undefined ) { + +$.widget("ui.draggable", $.ui.mouse, { + version: "1.9.2", + widgetEventPrefix: "drag", + options: { + addClasses: true, + appendTo: "parent", + axis: false, + connectToSortable: false, + containment: false, + cursor: "auto", + cursorAt: false, + grid: false, + handle: false, + helper: "original", + iframeFix: false, + opacity: false, + refreshPositions: false, + revert: false, + revertDuration: 500, + scope: "default", + scroll: true, + scrollSensitivity: 20, + scrollSpeed: 20, + snap: false, + snapMode: "both", + snapTolerance: 20, + stack: false, + zIndex: false + }, + _create: function() { + + if (this.options.helper == 'original' && !(/^(?:r|a|f)/).test(this.element.css("position"))) + this.element[0].style.position = 'relative'; + + (this.options.addClasses && this.element.addClass("ui-draggable")); + (this.options.disabled && this.element.addClass("ui-draggable-disabled")); + + this._mouseInit(); + + }, + + _destroy: function() { + this.element.removeClass( "ui-draggable ui-draggable-dragging ui-draggable-disabled" ); + this._mouseDestroy(); + }, + + _mouseCapture: function(event) { + + var o = this.options; + + // among others, prevent a drag on a resizable-handle + if (this.helper || o.disabled || $(event.target).is('.ui-resizable-handle')) + return false; + + //Quit if we're not on a valid handle + this.handle = this._getHandle(event); + if (!this.handle) + return false; + + $(o.iframeFix === true ? "iframe" : o.iframeFix).each(function() { + $('
    ') + .css({ + width: this.offsetWidth+"px", height: this.offsetHeight+"px", + position: "absolute", opacity: "0.001", zIndex: 1000 + }) + .css($(this).offset()) + .appendTo("body"); + }); + + return true; + + }, + + _mouseStart: function(event) { + + var o = this.options; + + //Create and append the visible helper + this.helper = this._createHelper(event); + + this.helper.addClass("ui-draggable-dragging"); + + //Cache the helper size + this._cacheHelperProportions(); + + //If ddmanager is used for droppables, set the global draggable + if($.ui.ddmanager) + $.ui.ddmanager.current = this; + + /* + * - Position generation - + * This block generates everything position related - it's the core of draggables. + */ + + //Cache the margins of the original element + this._cacheMargins(); + + //Store the helper's css position + this.cssPosition = this.helper.css("position"); + this.scrollParent = this.helper.scrollParent(); + + //The element's absolute position on the page minus margins + this.offset = this.positionAbs = this.element.offset(); + this.offset = { + top: this.offset.top - this.margins.top, + left: this.offset.left - this.margins.left + }; + + $.extend(this.offset, { + click: { //Where the click happened, relative to the element + left: event.pageX - this.offset.left, + top: event.pageY - this.offset.top + }, + parent: this._getParentOffset(), + relative: this._getRelativeOffset() //This is a relative to absolute position minus the actual position calculation - only used for relative positioned helper + }); + + //Generate the original position + this.originalPosition = this.position = this._generatePosition(event); + this.originalPageX = event.pageX; + this.originalPageY = event.pageY; + + //Adjust the mouse offset relative to the helper if 'cursorAt' is supplied + (o.cursorAt && this._adjustOffsetFromHelper(o.cursorAt)); + + //Set a containment if given in the options + if(o.containment) + this._setContainment(); + + //Trigger event + callbacks + if(this._trigger("start", event) === false) { + this._clear(); + return false; + } + + //Recache the helper size + this._cacheHelperProportions(); + + //Prepare the droppable offsets + if ($.ui.ddmanager && !o.dropBehaviour) + $.ui.ddmanager.prepareOffsets(this, event); + + + this._mouseDrag(event, true); //Execute the drag once - this causes the helper not to be visible before getting its correct position + + //If the ddmanager is used for droppables, inform the manager that dragging has started (see #5003) + if ( $.ui.ddmanager ) $.ui.ddmanager.dragStart(this, event); + + return true; + }, + + _mouseDrag: function(event, noPropagation) { + + //Compute the helpers position + this.position = this._generatePosition(event); + this.positionAbs = this._convertPositionTo("absolute"); + + //Call plugins and callbacks and use the resulting position if something is returned + if (!noPropagation) { + var ui = this._uiHash(); + if(this._trigger('drag', event, ui) === false) { + this._mouseUp({}); + return false; + } + this.position = ui.position; + } + + if(!this.options.axis || this.options.axis != "y") this.helper[0].style.left = this.position.left+'px'; + if(!this.options.axis || this.options.axis != "x") this.helper[0].style.top = this.position.top+'px'; + if($.ui.ddmanager) $.ui.ddmanager.drag(this, event); + + return false; + }, + + _mouseStop: function(event) { + + //If we are using droppables, inform the manager about the drop + var dropped = false; + if ($.ui.ddmanager && !this.options.dropBehaviour) + dropped = $.ui.ddmanager.drop(this, event); + + //if a drop comes from outside (a sortable) + if(this.dropped) { + dropped = this.dropped; + this.dropped = false; + } + + //if the original element is no longer in the DOM don't bother to continue (see #8269) + var element = this.element[0], elementInDom = false; + while ( element && (element = element.parentNode) ) { + if (element == document ) { + elementInDom = true; + } + } + if ( !elementInDom && this.options.helper === "original" ) + return false; + + if((this.options.revert == "invalid" && !dropped) || (this.options.revert == "valid" && dropped) || this.options.revert === true || ($.isFunction(this.options.revert) && this.options.revert.call(this.element, dropped))) { + var that = this; + $(this.helper).animate(this.originalPosition, parseInt(this.options.revertDuration, 10), function() { + if(that._trigger("stop", event) !== false) { + that._clear(); + } + }); + } else { + if(this._trigger("stop", event) !== false) { + this._clear(); + } + } + + return false; + }, + + _mouseUp: function(event) { + //Remove frame helpers + $("div.ui-draggable-iframeFix").each(function() { + this.parentNode.removeChild(this); + }); + + //If the ddmanager is used for droppables, inform the manager that dragging has stopped (see #5003) + if( $.ui.ddmanager ) $.ui.ddmanager.dragStop(this, event); + + return $.ui.mouse.prototype._mouseUp.call(this, event); + }, + + cancel: function() { + + if(this.helper.is(".ui-draggable-dragging")) { + this._mouseUp({}); + } else { + this._clear(); + } + + return this; + + }, + + _getHandle: function(event) { + + var handle = !this.options.handle || !$(this.options.handle, this.element).length ? true : false; + $(this.options.handle, this.element) + .find("*") + .andSelf() + .each(function() { + if(this == event.target) handle = true; + }); + + return handle; + + }, + + _createHelper: function(event) { + + var o = this.options; + var helper = $.isFunction(o.helper) ? $(o.helper.apply(this.element[0], [event])) : (o.helper == 'clone' ? this.element.clone().removeAttr('id') : this.element); + + if(!helper.parents('body').length) + helper.appendTo((o.appendTo == 'parent' ? this.element[0].parentNode : o.appendTo)); + + if(helper[0] != this.element[0] && !(/(fixed|absolute)/).test(helper.css("position"))) + helper.css("position", "absolute"); + + return helper; + + }, + + _adjustOffsetFromHelper: function(obj) { + if (typeof obj == 'string') { + obj = obj.split(' '); + } + if ($.isArray(obj)) { + obj = {left: +obj[0], top: +obj[1] || 0}; + } + if ('left' in obj) { + this.offset.click.left = obj.left + this.margins.left; + } + if ('right' in obj) { + this.offset.click.left = this.helperProportions.width - obj.right + this.margins.left; + } + if ('top' in obj) { + this.offset.click.top = obj.top + this.margins.top; + } + if ('bottom' in obj) { + this.offset.click.top = this.helperProportions.height - obj.bottom + this.margins.top; + } + }, + + _getParentOffset: function() { + + //Get the offsetParent and cache its position + this.offsetParent = this.helper.offsetParent(); + var po = this.offsetParent.offset(); + + // This is a special case where we need to modify a offset calculated on start, since the following happened: + // 1. The position of the helper is absolute, so it's position is calculated based on the next positioned parent + // 2. The actual offset parent is a child of the scroll parent, and the scroll parent isn't the document, which means that + // the scroll is included in the initial calculation of the offset of the parent, and never recalculated upon drag + if(this.cssPosition == 'absolute' && this.scrollParent[0] != document && $.contains(this.scrollParent[0], this.offsetParent[0])) { + po.left += this.scrollParent.scrollLeft(); + po.top += this.scrollParent.scrollTop(); + } + + if((this.offsetParent[0] == document.body) //This needs to be actually done for all browsers, since pageX/pageY includes this information + || (this.offsetParent[0].tagName && this.offsetParent[0].tagName.toLowerCase() == 'html' && $.ui.ie)) //Ugly IE fix + po = { top: 0, left: 0 }; + + return { + top: po.top + (parseInt(this.offsetParent.css("borderTopWidth"),10) || 0), + left: po.left + (parseInt(this.offsetParent.css("borderLeftWidth"),10) || 0) + }; + + }, + + _getRelativeOffset: function() { + + if(this.cssPosition == "relative") { + var p = this.element.position(); + return { + top: p.top - (parseInt(this.helper.css("top"),10) || 0) + this.scrollParent.scrollTop(), + left: p.left - (parseInt(this.helper.css("left"),10) || 0) + this.scrollParent.scrollLeft() + }; + } else { + return { top: 0, left: 0 }; + } + + }, + + _cacheMargins: function() { + this.margins = { + left: (parseInt(this.element.css("marginLeft"),10) || 0), + top: (parseInt(this.element.css("marginTop"),10) || 0), + right: (parseInt(this.element.css("marginRight"),10) || 0), + bottom: (parseInt(this.element.css("marginBottom"),10) || 0) + }; + }, + + _cacheHelperProportions: function() { + this.helperProportions = { + width: this.helper.outerWidth(), + height: this.helper.outerHeight() + }; + }, + + _setContainment: function() { + + var o = this.options; + if(o.containment == 'parent') o.containment = this.helper[0].parentNode; + if(o.containment == 'document' || o.containment == 'window') this.containment = [ + o.containment == 'document' ? 0 : $(window).scrollLeft() - this.offset.relative.left - this.offset.parent.left, + o.containment == 'document' ? 0 : $(window).scrollTop() - this.offset.relative.top - this.offset.parent.top, + (o.containment == 'document' ? 0 : $(window).scrollLeft()) + $(o.containment == 'document' ? document : window).width() - this.helperProportions.width - this.margins.left, + (o.containment == 'document' ? 0 : $(window).scrollTop()) + ($(o.containment == 'document' ? document : window).height() || document.body.parentNode.scrollHeight) - this.helperProportions.height - this.margins.top + ]; + + if(!(/^(document|window|parent)$/).test(o.containment) && o.containment.constructor != Array) { + var c = $(o.containment); + var ce = c[0]; if(!ce) return; + var co = c.offset(); + var over = ($(ce).css("overflow") != 'hidden'); + + this.containment = [ + (parseInt($(ce).css("borderLeftWidth"),10) || 0) + (parseInt($(ce).css("paddingLeft"),10) || 0), + (parseInt($(ce).css("borderTopWidth"),10) || 0) + (parseInt($(ce).css("paddingTop"),10) || 0), + (over ? Math.max(ce.scrollWidth,ce.offsetWidth) : ce.offsetWidth) - (parseInt($(ce).css("borderLeftWidth"),10) || 0) - (parseInt($(ce).css("paddingRight"),10) || 0) - this.helperProportions.width - this.margins.left - this.margins.right, + (over ? Math.max(ce.scrollHeight,ce.offsetHeight) : ce.offsetHeight) - (parseInt($(ce).css("borderTopWidth"),10) || 0) - (parseInt($(ce).css("paddingBottom"),10) || 0) - this.helperProportions.height - this.margins.top - this.margins.bottom + ]; + this.relative_container = c; + + } else if(o.containment.constructor == Array) { + this.containment = o.containment; + } + + }, + + _convertPositionTo: function(d, pos) { + + if(!pos) pos = this.position; + var mod = d == "absolute" ? 1 : -1; + var o = this.options, scroll = this.cssPosition == 'absolute' && !(this.scrollParent[0] != document && $.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName); + + return { + top: ( + pos.top // The absolute mouse position + + this.offset.relative.top * mod // Only for relative positioned nodes: Relative offset from element to offset parent + + this.offset.parent.top * mod // The offsetParent's offset without borders (offset + border) + - ( ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ) * mod) + ), + left: ( + pos.left // The absolute mouse position + + this.offset.relative.left * mod // Only for relative positioned nodes: Relative offset from element to offset parent + + this.offset.parent.left * mod // The offsetParent's offset without borders (offset + border) + - ( ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() ) * mod) + ) + }; + + }, + + _generatePosition: function(event) { + + var o = this.options, scroll = this.cssPosition == 'absolute' && !(this.scrollParent[0] != document && $.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName); + var pageX = event.pageX; + var pageY = event.pageY; + + /* + * - Position constraining - + * Constrain the position to a mix of grid, containment. + */ + + if(this.originalPosition) { //If we are not dragging yet, we won't check for options + var containment; + if(this.containment) { + if (this.relative_container){ + var co = this.relative_container.offset(); + containment = [ this.containment[0] + co.left, + this.containment[1] + co.top, + this.containment[2] + co.left, + this.containment[3] + co.top ]; + } + else { + containment = this.containment; + } + + if(event.pageX - this.offset.click.left < containment[0]) pageX = containment[0] + this.offset.click.left; + if(event.pageY - this.offset.click.top < containment[1]) pageY = containment[1] + this.offset.click.top; + if(event.pageX - this.offset.click.left > containment[2]) pageX = containment[2] + this.offset.click.left; + if(event.pageY - this.offset.click.top > containment[3]) pageY = containment[3] + this.offset.click.top; + } + + if(o.grid) { + //Check for grid elements set to 0 to prevent divide by 0 error causing invalid argument errors in IE (see ticket #6950) + var top = o.grid[1] ? this.originalPageY + Math.round((pageY - this.originalPageY) / o.grid[1]) * o.grid[1] : this.originalPageY; + pageY = containment ? (!(top - this.offset.click.top < containment[1] || top - this.offset.click.top > containment[3]) ? top : (!(top - this.offset.click.top < containment[1]) ? top - o.grid[1] : top + o.grid[1])) : top; + + var left = o.grid[0] ? this.originalPageX + Math.round((pageX - this.originalPageX) / o.grid[0]) * o.grid[0] : this.originalPageX; + pageX = containment ? (!(left - this.offset.click.left < containment[0] || left - this.offset.click.left > containment[2]) ? left : (!(left - this.offset.click.left < containment[0]) ? left - o.grid[0] : left + o.grid[0])) : left; + } + + } + + return { + top: ( + pageY // The absolute mouse position + - this.offset.click.top // Click offset (relative to the element) + - this.offset.relative.top // Only for relative positioned nodes: Relative offset from element to offset parent + - this.offset.parent.top // The offsetParent's offset without borders (offset + border) + + ( ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) )) + ), + left: ( + pageX // The absolute mouse position + - this.offset.click.left // Click offset (relative to the element) + - this.offset.relative.left // Only for relative positioned nodes: Relative offset from element to offset parent + - this.offset.parent.left // The offsetParent's offset without borders (offset + border) + + ( ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() )) + ) + }; + + }, + + _clear: function() { + this.helper.removeClass("ui-draggable-dragging"); + if(this.helper[0] != this.element[0] && !this.cancelHelperRemoval) this.helper.remove(); + //if($.ui.ddmanager) $.ui.ddmanager.current = null; + this.helper = null; + this.cancelHelperRemoval = false; + }, + + // From now on bulk stuff - mainly helpers + + _trigger: function(type, event, ui) { + ui = ui || this._uiHash(); + $.ui.plugin.call(this, type, [event, ui]); + if(type == "drag") this.positionAbs = this._convertPositionTo("absolute"); //The absolute position has to be recalculated after plugins + return $.Widget.prototype._trigger.call(this, type, event, ui); + }, + + plugins: {}, + + _uiHash: function(event) { + return { + helper: this.helper, + position: this.position, + originalPosition: this.originalPosition, + offset: this.positionAbs + }; + } + +}); + +$.ui.plugin.add("draggable", "connectToSortable", { + start: function(event, ui) { + + var inst = $(this).data("draggable"), o = inst.options, + uiSortable = $.extend({}, ui, { item: inst.element }); + inst.sortables = []; + $(o.connectToSortable).each(function() { + var sortable = $.data(this, 'sortable'); + if (sortable && !sortable.options.disabled) { + inst.sortables.push({ + instance: sortable, + shouldRevert: sortable.options.revert + }); + sortable.refreshPositions(); // Call the sortable's refreshPositions at drag start to refresh the containerCache since the sortable container cache is used in drag and needs to be up to date (this will ensure it's initialised as well as being kept in step with any changes that might have happened on the page). + sortable._trigger("activate", event, uiSortable); + } + }); + + }, + stop: function(event, ui) { + + //If we are still over the sortable, we fake the stop event of the sortable, but also remove helper + var inst = $(this).data("draggable"), + uiSortable = $.extend({}, ui, { item: inst.element }); + + $.each(inst.sortables, function() { + if(this.instance.isOver) { + + this.instance.isOver = 0; + + inst.cancelHelperRemoval = true; //Don't remove the helper in the draggable instance + this.instance.cancelHelperRemoval = false; //Remove it in the sortable instance (so sortable plugins like revert still work) + + //The sortable revert is supported, and we have to set a temporary dropped variable on the draggable to support revert: 'valid/invalid' + if(this.shouldRevert) this.instance.options.revert = true; + + //Trigger the stop of the sortable + this.instance._mouseStop(event); + + this.instance.options.helper = this.instance.options._helper; + + //If the helper has been the original item, restore properties in the sortable + if(inst.options.helper == 'original') + this.instance.currentItem.css({ top: 'auto', left: 'auto' }); + + } else { + this.instance.cancelHelperRemoval = false; //Remove the helper in the sortable instance + this.instance._trigger("deactivate", event, uiSortable); + } + + }); + + }, + drag: function(event, ui) { + + var inst = $(this).data("draggable"), that = this; + + var checkPos = function(o) { + var dyClick = this.offset.click.top, dxClick = this.offset.click.left; + var helperTop = this.positionAbs.top, helperLeft = this.positionAbs.left; + var itemHeight = o.height, itemWidth = o.width; + var itemTop = o.top, itemLeft = o.left; + + return $.ui.isOver(helperTop + dyClick, helperLeft + dxClick, itemTop, itemLeft, itemHeight, itemWidth); + }; + + $.each(inst.sortables, function(i) { + + var innermostIntersecting = false; + var thisSortable = this; + //Copy over some variables to allow calling the sortable's native _intersectsWith + this.instance.positionAbs = inst.positionAbs; + this.instance.helperProportions = inst.helperProportions; + this.instance.offset.click = inst.offset.click; + + if(this.instance._intersectsWith(this.instance.containerCache)) { + innermostIntersecting = true; + $.each(inst.sortables, function () { + this.instance.positionAbs = inst.positionAbs; + this.instance.helperProportions = inst.helperProportions; + this.instance.offset.click = inst.offset.click; + if (this != thisSortable + && this.instance._intersectsWith(this.instance.containerCache) + && $.ui.contains(thisSortable.instance.element[0], this.instance.element[0])) + innermostIntersecting = false; + return innermostIntersecting; + }); + } + + + if(innermostIntersecting) { + //If it intersects, we use a little isOver variable and set it once, so our move-in stuff gets fired only once + if(!this.instance.isOver) { + + this.instance.isOver = 1; + //Now we fake the start of dragging for the sortable instance, + //by cloning the list group item, appending it to the sortable and using it as inst.currentItem + //We can then fire the start event of the sortable with our passed browser event, and our own helper (so it doesn't create a new one) + this.instance.currentItem = $(that).clone().removeAttr('id').appendTo(this.instance.element).data("sortable-item", true); + this.instance.options._helper = this.instance.options.helper; //Store helper option to later restore it + this.instance.options.helper = function() { return ui.helper[0]; }; + + event.target = this.instance.currentItem[0]; + this.instance._mouseCapture(event, true); + this.instance._mouseStart(event, true, true); + + //Because the browser event is way off the new appended portlet, we modify a couple of variables to reflect the changes + this.instance.offset.click.top = inst.offset.click.top; + this.instance.offset.click.left = inst.offset.click.left; + this.instance.offset.parent.left -= inst.offset.parent.left - this.instance.offset.parent.left; + this.instance.offset.parent.top -= inst.offset.parent.top - this.instance.offset.parent.top; + + inst._trigger("toSortable", event); + inst.dropped = this.instance.element; //draggable revert needs that + //hack so receive/update callbacks work (mostly) + inst.currentItem = inst.element; + this.instance.fromOutside = inst; + + } + + //Provided we did all the previous steps, we can fire the drag event of the sortable on every draggable drag, when it intersects with the sortable + if(this.instance.currentItem) this.instance._mouseDrag(event); + + } else { + + //If it doesn't intersect with the sortable, and it intersected before, + //we fake the drag stop of the sortable, but make sure it doesn't remove the helper by using cancelHelperRemoval + if(this.instance.isOver) { + + this.instance.isOver = 0; + this.instance.cancelHelperRemoval = true; + + //Prevent reverting on this forced stop + this.instance.options.revert = false; + + // The out event needs to be triggered independently + this.instance._trigger('out', event, this.instance._uiHash(this.instance)); + + this.instance._mouseStop(event, true); + this.instance.options.helper = this.instance.options._helper; + + //Now we remove our currentItem, the list group clone again, and the placeholder, and animate the helper back to it's original size + this.instance.currentItem.remove(); + if(this.instance.placeholder) this.instance.placeholder.remove(); + + inst._trigger("fromSortable", event); + inst.dropped = false; //draggable revert needs that + } + + }; + + }); + + } +}); + +$.ui.plugin.add("draggable", "cursor", { + start: function(event, ui) { + var t = $('body'), o = $(this).data('draggable').options; + if (t.css("cursor")) o._cursor = t.css("cursor"); + t.css("cursor", o.cursor); + }, + stop: function(event, ui) { + var o = $(this).data('draggable').options; + if (o._cursor) $('body').css("cursor", o._cursor); + } +}); + +$.ui.plugin.add("draggable", "opacity", { + start: function(event, ui) { + var t = $(ui.helper), o = $(this).data('draggable').options; + if(t.css("opacity")) o._opacity = t.css("opacity"); + t.css('opacity', o.opacity); + }, + stop: function(event, ui) { + var o = $(this).data('draggable').options; + if(o._opacity) $(ui.helper).css('opacity', o._opacity); + } +}); + +$.ui.plugin.add("draggable", "scroll", { + start: function(event, ui) { + var i = $(this).data("draggable"); + if(i.scrollParent[0] != document && i.scrollParent[0].tagName != 'HTML') i.overflowOffset = i.scrollParent.offset(); + }, + drag: function(event, ui) { + + var i = $(this).data("draggable"), o = i.options, scrolled = false; + + if(i.scrollParent[0] != document && i.scrollParent[0].tagName != 'HTML') { + + if(!o.axis || o.axis != 'x') { + if((i.overflowOffset.top + i.scrollParent[0].offsetHeight) - event.pageY < o.scrollSensitivity) + i.scrollParent[0].scrollTop = scrolled = i.scrollParent[0].scrollTop + o.scrollSpeed; + else if(event.pageY - i.overflowOffset.top < o.scrollSensitivity) + i.scrollParent[0].scrollTop = scrolled = i.scrollParent[0].scrollTop - o.scrollSpeed; + } + + if(!o.axis || o.axis != 'y') { + if((i.overflowOffset.left + i.scrollParent[0].offsetWidth) - event.pageX < o.scrollSensitivity) + i.scrollParent[0].scrollLeft = scrolled = i.scrollParent[0].scrollLeft + o.scrollSpeed; + else if(event.pageX - i.overflowOffset.left < o.scrollSensitivity) + i.scrollParent[0].scrollLeft = scrolled = i.scrollParent[0].scrollLeft - o.scrollSpeed; + } + + } else { + + if(!o.axis || o.axis != 'x') { + if(event.pageY - $(document).scrollTop() < o.scrollSensitivity) + scrolled = $(document).scrollTop($(document).scrollTop() - o.scrollSpeed); + else if($(window).height() - (event.pageY - $(document).scrollTop()) < o.scrollSensitivity) + scrolled = $(document).scrollTop($(document).scrollTop() + o.scrollSpeed); + } + + if(!o.axis || o.axis != 'y') { + if(event.pageX - $(document).scrollLeft() < o.scrollSensitivity) + scrolled = $(document).scrollLeft($(document).scrollLeft() - o.scrollSpeed); + else if($(window).width() - (event.pageX - $(document).scrollLeft()) < o.scrollSensitivity) + scrolled = $(document).scrollLeft($(document).scrollLeft() + o.scrollSpeed); + } + + } + + if(scrolled !== false && $.ui.ddmanager && !o.dropBehaviour) + $.ui.ddmanager.prepareOffsets(i, event); + + } +}); + +$.ui.plugin.add("draggable", "snap", { + start: function(event, ui) { + + var i = $(this).data("draggable"), o = i.options; + i.snapElements = []; + + $(o.snap.constructor != String ? ( o.snap.items || ':data(draggable)' ) : o.snap).each(function() { + var $t = $(this); var $o = $t.offset(); + if(this != i.element[0]) i.snapElements.push({ + item: this, + width: $t.outerWidth(), height: $t.outerHeight(), + top: $o.top, left: $o.left + }); + }); + + }, + drag: function(event, ui) { + + var inst = $(this).data("draggable"), o = inst.options; + var d = o.snapTolerance; + + var x1 = ui.offset.left, x2 = x1 + inst.helperProportions.width, + y1 = ui.offset.top, y2 = y1 + inst.helperProportions.height; + + for (var i = inst.snapElements.length - 1; i >= 0; i--){ + + var l = inst.snapElements[i].left, r = l + inst.snapElements[i].width, + t = inst.snapElements[i].top, b = t + inst.snapElements[i].height; + + //Yes, I know, this is insane ;) + if(!((l-d < x1 && x1 < r+d && t-d < y1 && y1 < b+d) || (l-d < x1 && x1 < r+d && t-d < y2 && y2 < b+d) || (l-d < x2 && x2 < r+d && t-d < y1 && y1 < b+d) || (l-d < x2 && x2 < r+d && t-d < y2 && y2 < b+d))) { + if(inst.snapElements[i].snapping) (inst.options.snap.release && inst.options.snap.release.call(inst.element, event, $.extend(inst._uiHash(), { snapItem: inst.snapElements[i].item }))); + inst.snapElements[i].snapping = false; + continue; + } + + if(o.snapMode != 'inner') { + var ts = Math.abs(t - y2) <= d; + var bs = Math.abs(b - y1) <= d; + var ls = Math.abs(l - x2) <= d; + var rs = Math.abs(r - x1) <= d; + if(ts) ui.position.top = inst._convertPositionTo("relative", { top: t - inst.helperProportions.height, left: 0 }).top - inst.margins.top; + if(bs) ui.position.top = inst._convertPositionTo("relative", { top: b, left: 0 }).top - inst.margins.top; + if(ls) ui.position.left = inst._convertPositionTo("relative", { top: 0, left: l - inst.helperProportions.width }).left - inst.margins.left; + if(rs) ui.position.left = inst._convertPositionTo("relative", { top: 0, left: r }).left - inst.margins.left; + } + + var first = (ts || bs || ls || rs); + + if(o.snapMode != 'outer') { + var ts = Math.abs(t - y1) <= d; + var bs = Math.abs(b - y2) <= d; + var ls = Math.abs(l - x1) <= d; + var rs = Math.abs(r - x2) <= d; + if(ts) ui.position.top = inst._convertPositionTo("relative", { top: t, left: 0 }).top - inst.margins.top; + if(bs) ui.position.top = inst._convertPositionTo("relative", { top: b - inst.helperProportions.height, left: 0 }).top - inst.margins.top; + if(ls) ui.position.left = inst._convertPositionTo("relative", { top: 0, left: l }).left - inst.margins.left; + if(rs) ui.position.left = inst._convertPositionTo("relative", { top: 0, left: r - inst.helperProportions.width }).left - inst.margins.left; + } + + if(!inst.snapElements[i].snapping && (ts || bs || ls || rs || first)) + (inst.options.snap.snap && inst.options.snap.snap.call(inst.element, event, $.extend(inst._uiHash(), { snapItem: inst.snapElements[i].item }))); + inst.snapElements[i].snapping = (ts || bs || ls || rs || first); + + }; + + } +}); + +$.ui.plugin.add("draggable", "stack", { + start: function(event, ui) { + + var o = $(this).data("draggable").options; + + var group = $.makeArray($(o.stack)).sort(function(a,b) { + return (parseInt($(a).css("zIndex"),10) || 0) - (parseInt($(b).css("zIndex"),10) || 0); + }); + if (!group.length) { return; } + + var min = parseInt(group[0].style.zIndex) || 0; + $(group).each(function(i) { + this.style.zIndex = min + i; + }); + + this[0].style.zIndex = min + group.length; + + } +}); + +$.ui.plugin.add("draggable", "zIndex", { + start: function(event, ui) { + var t = $(ui.helper), o = $(this).data("draggable").options; + if(t.css("zIndex")) o._zIndex = t.css("zIndex"); + t.css('zIndex', o.zIndex); + }, + stop: function(event, ui) { + var o = $(this).data("draggable").options; + if(o._zIndex) $(ui.helper).css('zIndex', o._zIndex); + } +}); + +})(jQuery); +(function( $, undefined ) { + +$.widget("ui.droppable", { + version: "1.9.2", + widgetEventPrefix: "drop", + options: { + accept: '*', + activeClass: false, + addClasses: true, + greedy: false, + hoverClass: false, + scope: 'default', + tolerance: 'intersect' + }, + _create: function() { + + var o = this.options, accept = o.accept; + this.isover = 0; this.isout = 1; + + this.accept = $.isFunction(accept) ? accept : function(d) { + return d.is(accept); + }; + + //Store the droppable's proportions + this.proportions = { width: this.element[0].offsetWidth, height: this.element[0].offsetHeight }; + + // Add the reference and positions to the manager + $.ui.ddmanager.droppables[o.scope] = $.ui.ddmanager.droppables[o.scope] || []; + $.ui.ddmanager.droppables[o.scope].push(this); + + (o.addClasses && this.element.addClass("ui-droppable")); + + }, + + _destroy: function() { + var drop = $.ui.ddmanager.droppables[this.options.scope]; + for ( var i = 0; i < drop.length; i++ ) + if ( drop[i] == this ) + drop.splice(i, 1); + + this.element.removeClass("ui-droppable ui-droppable-disabled"); + }, + + _setOption: function(key, value) { + + if(key == 'accept') { + this.accept = $.isFunction(value) ? value : function(d) { + return d.is(value); + }; + } + $.Widget.prototype._setOption.apply(this, arguments); + }, + + _activate: function(event) { + var draggable = $.ui.ddmanager.current; + if(this.options.activeClass) this.element.addClass(this.options.activeClass); + (draggable && this._trigger('activate', event, this.ui(draggable))); + }, + + _deactivate: function(event) { + var draggable = $.ui.ddmanager.current; + if(this.options.activeClass) this.element.removeClass(this.options.activeClass); + (draggable && this._trigger('deactivate', event, this.ui(draggable))); + }, + + _over: function(event) { + + var draggable = $.ui.ddmanager.current; + if (!draggable || (draggable.currentItem || draggable.element)[0] == this.element[0]) return; // Bail if draggable and droppable are same element + + if (this.accept.call(this.element[0],(draggable.currentItem || draggable.element))) { + if(this.options.hoverClass) this.element.addClass(this.options.hoverClass); + this._trigger('over', event, this.ui(draggable)); + } + + }, + + _out: function(event) { + + var draggable = $.ui.ddmanager.current; + if (!draggable || (draggable.currentItem || draggable.element)[0] == this.element[0]) return; // Bail if draggable and droppable are same element + + if (this.accept.call(this.element[0],(draggable.currentItem || draggable.element))) { + if(this.options.hoverClass) this.element.removeClass(this.options.hoverClass); + this._trigger('out', event, this.ui(draggable)); + } + + }, + + _drop: function(event,custom) { + + var draggable = custom || $.ui.ddmanager.current; + if (!draggable || (draggable.currentItem || draggable.element)[0] == this.element[0]) return false; // Bail if draggable and droppable are same element + + var childrenIntersection = false; + this.element.find(":data(droppable)").not(".ui-draggable-dragging").each(function() { + var inst = $.data(this, 'droppable'); + if( + inst.options.greedy + && !inst.options.disabled + && inst.options.scope == draggable.options.scope + && inst.accept.call(inst.element[0], (draggable.currentItem || draggable.element)) + && $.ui.intersect(draggable, $.extend(inst, { offset: inst.element.offset() }), inst.options.tolerance) + ) { childrenIntersection = true; return false; } + }); + if(childrenIntersection) return false; + + if(this.accept.call(this.element[0],(draggable.currentItem || draggable.element))) { + if(this.options.activeClass) this.element.removeClass(this.options.activeClass); + if(this.options.hoverClass) this.element.removeClass(this.options.hoverClass); + this._trigger('drop', event, this.ui(draggable)); + return this.element; + } + + return false; + + }, + + ui: function(c) { + return { + draggable: (c.currentItem || c.element), + helper: c.helper, + position: c.position, + offset: c.positionAbs + }; + } + +}); + +$.ui.intersect = function(draggable, droppable, toleranceMode) { + + if (!droppable.offset) return false; + + var x1 = (draggable.positionAbs || draggable.position.absolute).left, x2 = x1 + draggable.helperProportions.width, + y1 = (draggable.positionAbs || draggable.position.absolute).top, y2 = y1 + draggable.helperProportions.height; + var l = droppable.offset.left, r = l + droppable.proportions.width, + t = droppable.offset.top, b = t + droppable.proportions.height; + + switch (toleranceMode) { + case 'fit': + return (l <= x1 && x2 <= r + && t <= y1 && y2 <= b); + break; + case 'intersect': + return (l < x1 + (draggable.helperProportions.width / 2) // Right Half + && x2 - (draggable.helperProportions.width / 2) < r // Left Half + && t < y1 + (draggable.helperProportions.height / 2) // Bottom Half + && y2 - (draggable.helperProportions.height / 2) < b ); // Top Half + break; + case 'pointer': + var draggableLeft = ((draggable.positionAbs || draggable.position.absolute).left + (draggable.clickOffset || draggable.offset.click).left), + draggableTop = ((draggable.positionAbs || draggable.position.absolute).top + (draggable.clickOffset || draggable.offset.click).top), + isOver = $.ui.isOver(draggableTop, draggableLeft, t, l, droppable.proportions.height, droppable.proportions.width); + return isOver; + break; + case 'touch': + return ( + (y1 >= t && y1 <= b) || // Top edge touching + (y2 >= t && y2 <= b) || // Bottom edge touching + (y1 < t && y2 > b) // Surrounded vertically + ) && ( + (x1 >= l && x1 <= r) || // Left edge touching + (x2 >= l && x2 <= r) || // Right edge touching + (x1 < l && x2 > r) // Surrounded horizontally + ); + break; + default: + return false; + break; + } + +}; + +/* + This manager tracks offsets of draggables and droppables +*/ +$.ui.ddmanager = { + current: null, + droppables: { 'default': [] }, + prepareOffsets: function(t, event) { + + var m = $.ui.ddmanager.droppables[t.options.scope] || []; + var type = event ? event.type : null; // workaround for #2317 + var list = (t.currentItem || t.element).find(":data(droppable)").andSelf(); + + droppablesLoop: for (var i = 0; i < m.length; i++) { + + if(m[i].options.disabled || (t && !m[i].accept.call(m[i].element[0],(t.currentItem || t.element)))) continue; //No disabled and non-accepted + for (var j=0; j < list.length; j++) { if(list[j] == m[i].element[0]) { m[i].proportions.height = 0; continue droppablesLoop; } }; //Filter out elements in the current dragged item + m[i].visible = m[i].element.css("display") != "none"; if(!m[i].visible) continue; //If the element is not visible, continue + + if(type == "mousedown") m[i]._activate.call(m[i], event); //Activate the droppable if used directly from draggables + + m[i].offset = m[i].element.offset(); + m[i].proportions = { width: m[i].element[0].offsetWidth, height: m[i].element[0].offsetHeight }; + + } + + }, + drop: function(draggable, event) { + + var dropped = false; + $.each($.ui.ddmanager.droppables[draggable.options.scope] || [], function() { + + if(!this.options) return; + if (!this.options.disabled && this.visible && $.ui.intersect(draggable, this, this.options.tolerance)) + dropped = this._drop.call(this, event) || dropped; + + if (!this.options.disabled && this.visible && this.accept.call(this.element[0],(draggable.currentItem || draggable.element))) { + this.isout = 1; this.isover = 0; + this._deactivate.call(this, event); + } + + }); + return dropped; + + }, + dragStart: function( draggable, event ) { + //Listen for scrolling so that if the dragging causes scrolling the position of the droppables can be recalculated (see #5003) + draggable.element.parentsUntil( "body" ).bind( "scroll.droppable", function() { + if( !draggable.options.refreshPositions ) $.ui.ddmanager.prepareOffsets( draggable, event ); + }); + }, + drag: function(draggable, event) { + + //If you have a highly dynamic page, you might try this option. It renders positions every time you move the mouse. + if(draggable.options.refreshPositions) $.ui.ddmanager.prepareOffsets(draggable, event); + + //Run through all droppables and check their positions based on specific tolerance options + $.each($.ui.ddmanager.droppables[draggable.options.scope] || [], function() { + + if(this.options.disabled || this.greedyChild || !this.visible) return; + var intersects = $.ui.intersect(draggable, this, this.options.tolerance); + + var c = !intersects && this.isover == 1 ? 'isout' : (intersects && this.isover == 0 ? 'isover' : null); + if(!c) return; + + var parentInstance; + if (this.options.greedy) { + // find droppable parents with same scope + var scope = this.options.scope; + var parent = this.element.parents(':data(droppable)').filter(function () { + return $.data(this, 'droppable').options.scope === scope; + }); + + if (parent.length) { + parentInstance = $.data(parent[0], 'droppable'); + parentInstance.greedyChild = (c == 'isover' ? 1 : 0); + } + } + + // we just moved into a greedy child + if (parentInstance && c == 'isover') { + parentInstance['isover'] = 0; + parentInstance['isout'] = 1; + parentInstance._out.call(parentInstance, event); + } + + this[c] = 1; this[c == 'isout' ? 'isover' : 'isout'] = 0; + this[c == "isover" ? "_over" : "_out"].call(this, event); + + // we just moved out of a greedy child + if (parentInstance && c == 'isout') { + parentInstance['isout'] = 0; + parentInstance['isover'] = 1; + parentInstance._over.call(parentInstance, event); + } + }); + + }, + dragStop: function( draggable, event ) { + draggable.element.parentsUntil( "body" ).unbind( "scroll.droppable" ); + //Call prepareOffsets one final time since IE does not fire return scroll events when overflow was caused by drag (see #5003) + if( !draggable.options.refreshPositions ) $.ui.ddmanager.prepareOffsets( draggable, event ); + } +}; + +})(jQuery); +;(jQuery.effects || (function($, undefined) { + +var backCompat = $.uiBackCompat !== false, + // prefix used for storing data on .data() + dataSpace = "ui-effects-"; + +$.effects = { + effect: {} +}; + +/*! + * jQuery Color Animations v2.0.0 + * http://jquery.com/ + * + * Copyright 2012 jQuery Foundation and other contributors + * Released under the MIT license. + * http://jquery.org/license + * + * Date: Mon Aug 13 13:41:02 2012 -0500 + */ +(function( jQuery, undefined ) { + + var stepHooks = "backgroundColor borderBottomColor borderLeftColor borderRightColor borderTopColor color columnRuleColor outlineColor textDecorationColor textEmphasisColor".split(" "), + + // plusequals test for += 100 -= 100 + rplusequals = /^([\-+])=\s*(\d+\.?\d*)/, + // a set of RE's that can match strings and generate color tuples. + stringParsers = [{ + re: /rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*(\d+(?:\.\d+)?)\s*)?\)/, + parse: function( execResult ) { + return [ + execResult[ 1 ], + execResult[ 2 ], + execResult[ 3 ], + execResult[ 4 ] + ]; + } + }, { + re: /rgba?\(\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d+(?:\.\d+)?)\s*)?\)/, + parse: function( execResult ) { + return [ + execResult[ 1 ] * 2.55, + execResult[ 2 ] * 2.55, + execResult[ 3 ] * 2.55, + execResult[ 4 ] + ]; + } + }, { + // this regex ignores A-F because it's compared against an already lowercased string + re: /#([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})/, + parse: function( execResult ) { + return [ + parseInt( execResult[ 1 ], 16 ), + parseInt( execResult[ 2 ], 16 ), + parseInt( execResult[ 3 ], 16 ) + ]; + } + }, { + // this regex ignores A-F because it's compared against an already lowercased string + re: /#([a-f0-9])([a-f0-9])([a-f0-9])/, + parse: function( execResult ) { + return [ + parseInt( execResult[ 1 ] + execResult[ 1 ], 16 ), + parseInt( execResult[ 2 ] + execResult[ 2 ], 16 ), + parseInt( execResult[ 3 ] + execResult[ 3 ], 16 ) + ]; + } + }, { + re: /hsla?\(\s*(\d+(?:\.\d+)?)\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d+(?:\.\d+)?)\s*)?\)/, + space: "hsla", + parse: function( execResult ) { + return [ + execResult[ 1 ], + execResult[ 2 ] / 100, + execResult[ 3 ] / 100, + execResult[ 4 ] + ]; + } + }], + + // jQuery.Color( ) + color = jQuery.Color = function( color, green, blue, alpha ) { + return new jQuery.Color.fn.parse( color, green, blue, alpha ); + }, + spaces = { + rgba: { + props: { + red: { + idx: 0, + type: "byte" + }, + green: { + idx: 1, + type: "byte" + }, + blue: { + idx: 2, + type: "byte" + } + } + }, + + hsla: { + props: { + hue: { + idx: 0, + type: "degrees" + }, + saturation: { + idx: 1, + type: "percent" + }, + lightness: { + idx: 2, + type: "percent" + } + } + } + }, + propTypes = { + "byte": { + floor: true, + max: 255 + }, + "percent": { + max: 1 + }, + "degrees": { + mod: 360, + floor: true + } + }, + support = color.support = {}, + + // element for support tests + supportElem = jQuery( "

    " )[ 0 ], + + // colors = jQuery.Color.names + colors, + + // local aliases of functions called often + each = jQuery.each; + +// determine rgba support immediately +supportElem.style.cssText = "background-color:rgba(1,1,1,.5)"; +support.rgba = supportElem.style.backgroundColor.indexOf( "rgba" ) > -1; + +// define cache name and alpha properties +// for rgba and hsla spaces +each( spaces, function( spaceName, space ) { + space.cache = "_" + spaceName; + space.props.alpha = { + idx: 3, + type: "percent", + def: 1 + }; +}); + +function clamp( value, prop, allowEmpty ) { + var type = propTypes[ prop.type ] || {}; + + if ( value == null ) { + return (allowEmpty || !prop.def) ? null : prop.def; + } + + // ~~ is an short way of doing floor for positive numbers + value = type.floor ? ~~value : parseFloat( value ); + + // IE will pass in empty strings as value for alpha, + // which will hit this case + if ( isNaN( value ) ) { + return prop.def; + } + + if ( type.mod ) { + // we add mod before modding to make sure that negatives values + // get converted properly: -10 -> 350 + return (value + type.mod) % type.mod; + } + + // for now all property types without mod have min and max + return 0 > value ? 0 : type.max < value ? type.max : value; +} + +function stringParse( string ) { + var inst = color(), + rgba = inst._rgba = []; + + string = string.toLowerCase(); + + each( stringParsers, function( i, parser ) { + var parsed, + match = parser.re.exec( string ), + values = match && parser.parse( match ), + spaceName = parser.space || "rgba"; + + if ( values ) { + parsed = inst[ spaceName ]( values ); + + // if this was an rgba parse the assignment might happen twice + // oh well.... + inst[ spaces[ spaceName ].cache ] = parsed[ spaces[ spaceName ].cache ]; + rgba = inst._rgba = parsed._rgba; + + // exit each( stringParsers ) here because we matched + return false; + } + }); + + // Found a stringParser that handled it + if ( rgba.length ) { + + // if this came from a parsed string, force "transparent" when alpha is 0 + // chrome, (and maybe others) return "transparent" as rgba(0,0,0,0) + if ( rgba.join() === "0,0,0,0" ) { + jQuery.extend( rgba, colors.transparent ); + } + return inst; + } + + // named colors + return colors[ string ]; +} + +color.fn = jQuery.extend( color.prototype, { + parse: function( red, green, blue, alpha ) { + if ( red === undefined ) { + this._rgba = [ null, null, null, null ]; + return this; + } + if ( red.jquery || red.nodeType ) { + red = jQuery( red ).css( green ); + green = undefined; + } + + var inst = this, + type = jQuery.type( red ), + rgba = this._rgba = []; + + // more than 1 argument specified - assume ( red, green, blue, alpha ) + if ( green !== undefined ) { + red = [ red, green, blue, alpha ]; + type = "array"; + } + + if ( type === "string" ) { + return this.parse( stringParse( red ) || colors._default ); + } + + if ( type === "array" ) { + each( spaces.rgba.props, function( key, prop ) { + rgba[ prop.idx ] = clamp( red[ prop.idx ], prop ); + }); + return this; + } + + if ( type === "object" ) { + if ( red instanceof color ) { + each( spaces, function( spaceName, space ) { + if ( red[ space.cache ] ) { + inst[ space.cache ] = red[ space.cache ].slice(); + } + }); + } else { + each( spaces, function( spaceName, space ) { + var cache = space.cache; + each( space.props, function( key, prop ) { + + // if the cache doesn't exist, and we know how to convert + if ( !inst[ cache ] && space.to ) { + + // if the value was null, we don't need to copy it + // if the key was alpha, we don't need to copy it either + if ( key === "alpha" || red[ key ] == null ) { + return; + } + inst[ cache ] = space.to( inst._rgba ); + } + + // this is the only case where we allow nulls for ALL properties. + // call clamp with alwaysAllowEmpty + inst[ cache ][ prop.idx ] = clamp( red[ key ], prop, true ); + }); + + // everything defined but alpha? + if ( inst[ cache ] && $.inArray( null, inst[ cache ].slice( 0, 3 ) ) < 0 ) { + // use the default of 1 + inst[ cache ][ 3 ] = 1; + if ( space.from ) { + inst._rgba = space.from( inst[ cache ] ); + } + } + }); + } + return this; + } + }, + is: function( compare ) { + var is = color( compare ), + same = true, + inst = this; + + each( spaces, function( _, space ) { + var localCache, + isCache = is[ space.cache ]; + if (isCache) { + localCache = inst[ space.cache ] || space.to && space.to( inst._rgba ) || []; + each( space.props, function( _, prop ) { + if ( isCache[ prop.idx ] != null ) { + same = ( isCache[ prop.idx ] === localCache[ prop.idx ] ); + return same; + } + }); + } + return same; + }); + return same; + }, + _space: function() { + var used = [], + inst = this; + each( spaces, function( spaceName, space ) { + if ( inst[ space.cache ] ) { + used.push( spaceName ); + } + }); + return used.pop(); + }, + transition: function( other, distance ) { + var end = color( other ), + spaceName = end._space(), + space = spaces[ spaceName ], + startColor = this.alpha() === 0 ? color( "transparent" ) : this, + start = startColor[ space.cache ] || space.to( startColor._rgba ), + result = start.slice(); + + end = end[ space.cache ]; + each( space.props, function( key, prop ) { + var index = prop.idx, + startValue = start[ index ], + endValue = end[ index ], + type = propTypes[ prop.type ] || {}; + + // if null, don't override start value + if ( endValue === null ) { + return; + } + // if null - use end + if ( startValue === null ) { + result[ index ] = endValue; + } else { + if ( type.mod ) { + if ( endValue - startValue > type.mod / 2 ) { + startValue += type.mod; + } else if ( startValue - endValue > type.mod / 2 ) { + startValue -= type.mod; + } + } + result[ index ] = clamp( ( endValue - startValue ) * distance + startValue, prop ); + } + }); + return this[ spaceName ]( result ); + }, + blend: function( opaque ) { + // if we are already opaque - return ourself + if ( this._rgba[ 3 ] === 1 ) { + return this; + } + + var rgb = this._rgba.slice(), + a = rgb.pop(), + blend = color( opaque )._rgba; + + return color( jQuery.map( rgb, function( v, i ) { + return ( 1 - a ) * blend[ i ] + a * v; + })); + }, + toRgbaString: function() { + var prefix = "rgba(", + rgba = jQuery.map( this._rgba, function( v, i ) { + return v == null ? ( i > 2 ? 1 : 0 ) : v; + }); + + if ( rgba[ 3 ] === 1 ) { + rgba.pop(); + prefix = "rgb("; + } + + return prefix + rgba.join() + ")"; + }, + toHslaString: function() { + var prefix = "hsla(", + hsla = jQuery.map( this.hsla(), function( v, i ) { + if ( v == null ) { + v = i > 2 ? 1 : 0; + } + + // catch 1 and 2 + if ( i && i < 3 ) { + v = Math.round( v * 100 ) + "%"; + } + return v; + }); + + if ( hsla[ 3 ] === 1 ) { + hsla.pop(); + prefix = "hsl("; + } + return prefix + hsla.join() + ")"; + }, + toHexString: function( includeAlpha ) { + var rgba = this._rgba.slice(), + alpha = rgba.pop(); + + if ( includeAlpha ) { + rgba.push( ~~( alpha * 255 ) ); + } + + return "#" + jQuery.map( rgba, function( v ) { + + // default to 0 when nulls exist + v = ( v || 0 ).toString( 16 ); + return v.length === 1 ? "0" + v : v; + }).join(""); + }, + toString: function() { + return this._rgba[ 3 ] === 0 ? "transparent" : this.toRgbaString(); + } +}); +color.fn.parse.prototype = color.fn; + +// hsla conversions adapted from: +// https://code.google.com/p/maashaack/source/browse/packages/graphics/trunk/src/graphics/colors/HUE2RGB.as?r=5021 + +function hue2rgb( p, q, h ) { + h = ( h + 1 ) % 1; + if ( h * 6 < 1 ) { + return p + (q - p) * h * 6; + } + if ( h * 2 < 1) { + return q; + } + if ( h * 3 < 2 ) { + return p + (q - p) * ((2/3) - h) * 6; + } + return p; +} + +spaces.hsla.to = function ( rgba ) { + if ( rgba[ 0 ] == null || rgba[ 1 ] == null || rgba[ 2 ] == null ) { + return [ null, null, null, rgba[ 3 ] ]; + } + var r = rgba[ 0 ] / 255, + g = rgba[ 1 ] / 255, + b = rgba[ 2 ] / 255, + a = rgba[ 3 ], + max = Math.max( r, g, b ), + min = Math.min( r, g, b ), + diff = max - min, + add = max + min, + l = add * 0.5, + h, s; + + if ( min === max ) { + h = 0; + } else if ( r === max ) { + h = ( 60 * ( g - b ) / diff ) + 360; + } else if ( g === max ) { + h = ( 60 * ( b - r ) / diff ) + 120; + } else { + h = ( 60 * ( r - g ) / diff ) + 240; + } + + if ( l === 0 || l === 1 ) { + s = l; + } else if ( l <= 0.5 ) { + s = diff / add; + } else { + s = diff / ( 2 - add ); + } + return [ Math.round(h) % 360, s, l, a == null ? 1 : a ]; +}; + +spaces.hsla.from = function ( hsla ) { + if ( hsla[ 0 ] == null || hsla[ 1 ] == null || hsla[ 2 ] == null ) { + return [ null, null, null, hsla[ 3 ] ]; + } + var h = hsla[ 0 ] / 360, + s = hsla[ 1 ], + l = hsla[ 2 ], + a = hsla[ 3 ], + q = l <= 0.5 ? l * ( 1 + s ) : l + s - l * s, + p = 2 * l - q; + + return [ + Math.round( hue2rgb( p, q, h + ( 1 / 3 ) ) * 255 ), + Math.round( hue2rgb( p, q, h ) * 255 ), + Math.round( hue2rgb( p, q, h - ( 1 / 3 ) ) * 255 ), + a + ]; +}; + + +each( spaces, function( spaceName, space ) { + var props = space.props, + cache = space.cache, + to = space.to, + from = space.from; + + // makes rgba() and hsla() + color.fn[ spaceName ] = function( value ) { + + // generate a cache for this space if it doesn't exist + if ( to && !this[ cache ] ) { + this[ cache ] = to( this._rgba ); + } + if ( value === undefined ) { + return this[ cache ].slice(); + } + + var ret, + type = jQuery.type( value ), + arr = ( type === "array" || type === "object" ) ? value : arguments, + local = this[ cache ].slice(); + + each( props, function( key, prop ) { + var val = arr[ type === "object" ? key : prop.idx ]; + if ( val == null ) { + val = local[ prop.idx ]; + } + local[ prop.idx ] = clamp( val, prop ); + }); + + if ( from ) { + ret = color( from( local ) ); + ret[ cache ] = local; + return ret; + } else { + return color( local ); + } + }; + + // makes red() green() blue() alpha() hue() saturation() lightness() + each( props, function( key, prop ) { + // alpha is included in more than one space + if ( color.fn[ key ] ) { + return; + } + color.fn[ key ] = function( value ) { + var vtype = jQuery.type( value ), + fn = ( key === "alpha" ? ( this._hsla ? "hsla" : "rgba" ) : spaceName ), + local = this[ fn ](), + cur = local[ prop.idx ], + match; + + if ( vtype === "undefined" ) { + return cur; + } + + if ( vtype === "function" ) { + value = value.call( this, cur ); + vtype = jQuery.type( value ); + } + if ( value == null && prop.empty ) { + return this; + } + if ( vtype === "string" ) { + match = rplusequals.exec( value ); + if ( match ) { + value = cur + parseFloat( match[ 2 ] ) * ( match[ 1 ] === "+" ? 1 : -1 ); + } + } + local[ prop.idx ] = value; + return this[ fn ]( local ); + }; + }); +}); + +// add .fx.step functions +each( stepHooks, function( i, hook ) { + jQuery.cssHooks[ hook ] = { + set: function( elem, value ) { + var parsed, curElem, + backgroundColor = ""; + + if ( jQuery.type( value ) !== "string" || ( parsed = stringParse( value ) ) ) { + value = color( parsed || value ); + if ( !support.rgba && value._rgba[ 3 ] !== 1 ) { + curElem = hook === "backgroundColor" ? elem.parentNode : elem; + while ( + (backgroundColor === "" || backgroundColor === "transparent") && + curElem && curElem.style + ) { + try { + backgroundColor = jQuery.css( curElem, "backgroundColor" ); + curElem = curElem.parentNode; + } catch ( e ) { + } + } + + value = value.blend( backgroundColor && backgroundColor !== "transparent" ? + backgroundColor : + "_default" ); + } + + value = value.toRgbaString(); + } + try { + elem.style[ hook ] = value; + } catch( error ) { + // wrapped to prevent IE from throwing errors on "invalid" values like 'auto' or 'inherit' + } + } + }; + jQuery.fx.step[ hook ] = function( fx ) { + if ( !fx.colorInit ) { + fx.start = color( fx.elem, hook ); + fx.end = color( fx.end ); + fx.colorInit = true; + } + jQuery.cssHooks[ hook ].set( fx.elem, fx.start.transition( fx.end, fx.pos ) ); + }; +}); + +jQuery.cssHooks.borderColor = { + expand: function( value ) { + var expanded = {}; + + each( [ "Top", "Right", "Bottom", "Left" ], function( i, part ) { + expanded[ "border" + part + "Color" ] = value; + }); + return expanded; + } +}; + +// Basic color names only. +// Usage of any of the other color names requires adding yourself or including +// jquery.color.svg-names.js. +colors = jQuery.Color.names = { + // 4.1. Basic color keywords + aqua: "#00ffff", + black: "#000000", + blue: "#0000ff", + fuchsia: "#ff00ff", + gray: "#808080", + green: "#008000", + lime: "#00ff00", + maroon: "#800000", + navy: "#000080", + olive: "#808000", + purple: "#800080", + red: "#ff0000", + silver: "#c0c0c0", + teal: "#008080", + white: "#ffffff", + yellow: "#ffff00", + + // 4.2.3. "transparent" color keyword + transparent: [ null, null, null, 0 ], + + _default: "#ffffff" +}; + +})( jQuery ); + + + +/******************************************************************************/ +/****************************** CLASS ANIMATIONS ******************************/ +/******************************************************************************/ +(function() { + +var classAnimationActions = [ "add", "remove", "toggle" ], + shorthandStyles = { + border: 1, + borderBottom: 1, + borderColor: 1, + borderLeft: 1, + borderRight: 1, + borderTop: 1, + borderWidth: 1, + margin: 1, + padding: 1 + }; + +$.each([ "borderLeftStyle", "borderRightStyle", "borderBottomStyle", "borderTopStyle" ], function( _, prop ) { + $.fx.step[ prop ] = function( fx ) { + if ( fx.end !== "none" && !fx.setAttr || fx.pos === 1 && !fx.setAttr ) { + jQuery.style( fx.elem, prop, fx.end ); + fx.setAttr = true; + } + }; +}); + +function getElementStyles() { + var style = this.ownerDocument.defaultView ? + this.ownerDocument.defaultView.getComputedStyle( this, null ) : + this.currentStyle, + newStyle = {}, + key, + len; + + // webkit enumerates style porperties + if ( style && style.length && style[ 0 ] && style[ style[ 0 ] ] ) { + len = style.length; + while ( len-- ) { + key = style[ len ]; + if ( typeof style[ key ] === "string" ) { + newStyle[ $.camelCase( key ) ] = style[ key ]; + } + } + } else { + for ( key in style ) { + if ( typeof style[ key ] === "string" ) { + newStyle[ key ] = style[ key ]; + } + } + } + + return newStyle; +} + + +function styleDifference( oldStyle, newStyle ) { + var diff = {}, + name, value; + + for ( name in newStyle ) { + value = newStyle[ name ]; + if ( oldStyle[ name ] !== value ) { + if ( !shorthandStyles[ name ] ) { + if ( $.fx.step[ name ] || !isNaN( parseFloat( value ) ) ) { + diff[ name ] = value; + } + } + } + } + + return diff; +} + +$.effects.animateClass = function( value, duration, easing, callback ) { + var o = $.speed( duration, easing, callback ); + + return this.queue( function() { + var animated = $( this ), + baseClass = animated.attr( "class" ) || "", + applyClassChange, + allAnimations = o.children ? animated.find( "*" ).andSelf() : animated; + + // map the animated objects to store the original styles. + allAnimations = allAnimations.map(function() { + var el = $( this ); + return { + el: el, + start: getElementStyles.call( this ) + }; + }); + + // apply class change + applyClassChange = function() { + $.each( classAnimationActions, function(i, action) { + if ( value[ action ] ) { + animated[ action + "Class" ]( value[ action ] ); + } + }); + }; + applyClassChange(); + + // map all animated objects again - calculate new styles and diff + allAnimations = allAnimations.map(function() { + this.end = getElementStyles.call( this.el[ 0 ] ); + this.diff = styleDifference( this.start, this.end ); + return this; + }); + + // apply original class + animated.attr( "class", baseClass ); + + // map all animated objects again - this time collecting a promise + allAnimations = allAnimations.map(function() { + var styleInfo = this, + dfd = $.Deferred(), + opts = jQuery.extend({}, o, { + queue: false, + complete: function() { + dfd.resolve( styleInfo ); + } + }); + + this.el.animate( this.diff, opts ); + return dfd.promise(); + }); + + // once all animations have completed: + $.when.apply( $, allAnimations.get() ).done(function() { + + // set the final class + applyClassChange(); + + // for each animated element, + // clear all css properties that were animated + $.each( arguments, function() { + var el = this.el; + $.each( this.diff, function(key) { + el.css( key, '' ); + }); + }); + + // this is guarnteed to be there if you use jQuery.speed() + // it also handles dequeuing the next anim... + o.complete.call( animated[ 0 ] ); + }); + }); +}; + +$.fn.extend({ + _addClass: $.fn.addClass, + addClass: function( classNames, speed, easing, callback ) { + return speed ? + $.effects.animateClass.call( this, + { add: classNames }, speed, easing, callback ) : + this._addClass( classNames ); + }, + + _removeClass: $.fn.removeClass, + removeClass: function( classNames, speed, easing, callback ) { + return speed ? + $.effects.animateClass.call( this, + { remove: classNames }, speed, easing, callback ) : + this._removeClass( classNames ); + }, + + _toggleClass: $.fn.toggleClass, + toggleClass: function( classNames, force, speed, easing, callback ) { + if ( typeof force === "boolean" || force === undefined ) { + if ( !speed ) { + // without speed parameter + return this._toggleClass( classNames, force ); + } else { + return $.effects.animateClass.call( this, + (force ? { add: classNames } : { remove: classNames }), + speed, easing, callback ); + } + } else { + // without force parameter + return $.effects.animateClass.call( this, + { toggle: classNames }, force, speed, easing ); + } + }, + + switchClass: function( remove, add, speed, easing, callback) { + return $.effects.animateClass.call( this, { + add: add, + remove: remove + }, speed, easing, callback ); + } +}); + +})(); + +/******************************************************************************/ +/*********************************** EFFECTS **********************************/ +/******************************************************************************/ + +(function() { + +$.extend( $.effects, { + version: "1.9.2", + + // Saves a set of properties in a data storage + save: function( element, set ) { + for( var i=0; i < set.length; i++ ) { + if ( set[ i ] !== null ) { + element.data( dataSpace + set[ i ], element[ 0 ].style[ set[ i ] ] ); + } + } + }, + + // Restores a set of previously saved properties from a data storage + restore: function( element, set ) { + var val, i; + for( i=0; i < set.length; i++ ) { + if ( set[ i ] !== null ) { + val = element.data( dataSpace + set[ i ] ); + // support: jQuery 1.6.2 + // http://bugs.jquery.com/ticket/9917 + // jQuery 1.6.2 incorrectly returns undefined for any falsy value. + // We can't differentiate between "" and 0 here, so we just assume + // empty string since it's likely to be a more common value... + if ( val === undefined ) { + val = ""; + } + element.css( set[ i ], val ); + } + } + }, + + setMode: function( el, mode ) { + if (mode === "toggle") { + mode = el.is( ":hidden" ) ? "show" : "hide"; + } + return mode; + }, + + // Translates a [top,left] array into a baseline value + // this should be a little more flexible in the future to handle a string & hash + getBaseline: function( origin, original ) { + var y, x; + switch ( origin[ 0 ] ) { + case "top": y = 0; break; + case "middle": y = 0.5; break; + case "bottom": y = 1; break; + default: y = origin[ 0 ] / original.height; + } + switch ( origin[ 1 ] ) { + case "left": x = 0; break; + case "center": x = 0.5; break; + case "right": x = 1; break; + default: x = origin[ 1 ] / original.width; + } + return { + x: x, + y: y + }; + }, + + // Wraps the element around a wrapper that copies position properties + createWrapper: function( element ) { + + // if the element is already wrapped, return it + if ( element.parent().is( ".ui-effects-wrapper" )) { + return element.parent(); + } + + // wrap the element + var props = { + width: element.outerWidth(true), + height: element.outerHeight(true), + "float": element.css( "float" ) + }, + wrapper = $( "

    " ) + .addClass( "ui-effects-wrapper" ) + .css({ + fontSize: "100%", + background: "transparent", + border: "none", + margin: 0, + padding: 0 + }), + // Store the size in case width/height are defined in % - Fixes #5245 + size = { + width: element.width(), + height: element.height() + }, + active = document.activeElement; + + // support: Firefox + // Firefox incorrectly exposes anonymous content + // https://bugzilla.mozilla.org/show_bug.cgi?id=561664 + try { + active.id; + } catch( e ) { + active = document.body; + } + + element.wrap( wrapper ); + + // Fixes #7595 - Elements lose focus when wrapped. + if ( element[ 0 ] === active || $.contains( element[ 0 ], active ) ) { + $( active ).focus(); + } + + wrapper = element.parent(); //Hotfix for jQuery 1.4 since some change in wrap() seems to actually lose the reference to the wrapped element + + // transfer positioning properties to the wrapper + if ( element.css( "position" ) === "static" ) { + wrapper.css({ position: "relative" }); + element.css({ position: "relative" }); + } else { + $.extend( props, { + position: element.css( "position" ), + zIndex: element.css( "z-index" ) + }); + $.each([ "top", "left", "bottom", "right" ], function(i, pos) { + props[ pos ] = element.css( pos ); + if ( isNaN( parseInt( props[ pos ], 10 ) ) ) { + props[ pos ] = "auto"; + } + }); + element.css({ + position: "relative", + top: 0, + left: 0, + right: "auto", + bottom: "auto" + }); + } + element.css(size); + + return wrapper.css( props ).show(); + }, + + removeWrapper: function( element ) { + var active = document.activeElement; + + if ( element.parent().is( ".ui-effects-wrapper" ) ) { + element.parent().replaceWith( element ); + + // Fixes #7595 - Elements lose focus when wrapped. + if ( element[ 0 ] === active || $.contains( element[ 0 ], active ) ) { + $( active ).focus(); + } + } + + + return element; + }, + + setTransition: function( element, list, factor, value ) { + value = value || {}; + $.each( list, function( i, x ) { + var unit = element.cssUnit( x ); + if ( unit[ 0 ] > 0 ) { + value[ x ] = unit[ 0 ] * factor + unit[ 1 ]; + } + }); + return value; + } +}); + +// return an effect options object for the given parameters: +function _normalizeArguments( effect, options, speed, callback ) { + + // allow passing all options as the first parameter + if ( $.isPlainObject( effect ) ) { + options = effect; + effect = effect.effect; + } + + // convert to an object + effect = { effect: effect }; + + // catch (effect, null, ...) + if ( options == null ) { + options = {}; + } + + // catch (effect, callback) + if ( $.isFunction( options ) ) { + callback = options; + speed = null; + options = {}; + } + + // catch (effect, speed, ?) + if ( typeof options === "number" || $.fx.speeds[ options ] ) { + callback = speed; + speed = options; + options = {}; + } + + // catch (effect, options, callback) + if ( $.isFunction( speed ) ) { + callback = speed; + speed = null; + } + + // add options to effect + if ( options ) { + $.extend( effect, options ); + } + + speed = speed || options.duration; + effect.duration = $.fx.off ? 0 : + typeof speed === "number" ? speed : + speed in $.fx.speeds ? $.fx.speeds[ speed ] : + $.fx.speeds._default; + + effect.complete = callback || options.complete; + + return effect; +} + +function standardSpeed( speed ) { + // valid standard speeds + if ( !speed || typeof speed === "number" || $.fx.speeds[ speed ] ) { + return true; + } + + // invalid strings - treat as "normal" speed + if ( typeof speed === "string" && !$.effects.effect[ speed ] ) { + // TODO: remove in 2.0 (#7115) + if ( backCompat && $.effects[ speed ] ) { + return false; + } + return true; + } + + return false; +} + +$.fn.extend({ + effect: function( /* effect, options, speed, callback */ ) { + var args = _normalizeArguments.apply( this, arguments ), + mode = args.mode, + queue = args.queue, + effectMethod = $.effects.effect[ args.effect ], + + // DEPRECATED: remove in 2.0 (#7115) + oldEffectMethod = !effectMethod && backCompat && $.effects[ args.effect ]; + + if ( $.fx.off || !( effectMethod || oldEffectMethod ) ) { + // delegate to the original method (e.g., .show()) if possible + if ( mode ) { + return this[ mode ]( args.duration, args.complete ); + } else { + return this.each( function() { + if ( args.complete ) { + args.complete.call( this ); + } + }); + } + } + + function run( next ) { + var elem = $( this ), + complete = args.complete, + mode = args.mode; + + function done() { + if ( $.isFunction( complete ) ) { + complete.call( elem[0] ); + } + if ( $.isFunction( next ) ) { + next(); + } + } + + // if the element is hiddden and mode is hide, + // or element is visible and mode is show + if ( elem.is( ":hidden" ) ? mode === "hide" : mode === "show" ) { + done(); + } else { + effectMethod.call( elem[0], args, done ); + } + } + + // TODO: remove this check in 2.0, effectMethod will always be true + if ( effectMethod ) { + return queue === false ? this.each( run ) : this.queue( queue || "fx", run ); + } else { + // DEPRECATED: remove in 2.0 (#7115) + return oldEffectMethod.call(this, { + options: args, + duration: args.duration, + callback: args.complete, + mode: args.mode + }); + } + }, + + _show: $.fn.show, + show: function( speed ) { + if ( standardSpeed( speed ) ) { + return this._show.apply( this, arguments ); + } else { + var args = _normalizeArguments.apply( this, arguments ); + args.mode = "show"; + return this.effect.call( this, args ); + } + }, + + _hide: $.fn.hide, + hide: function( speed ) { + if ( standardSpeed( speed ) ) { + return this._hide.apply( this, arguments ); + } else { + var args = _normalizeArguments.apply( this, arguments ); + args.mode = "hide"; + return this.effect.call( this, args ); + } + }, + + // jQuery core overloads toggle and creates _toggle + __toggle: $.fn.toggle, + toggle: function( speed ) { + if ( standardSpeed( speed ) || typeof speed === "boolean" || $.isFunction( speed ) ) { + return this.__toggle.apply( this, arguments ); + } else { + var args = _normalizeArguments.apply( this, arguments ); + args.mode = "toggle"; + return this.effect.call( this, args ); + } + }, + + // helper functions + cssUnit: function(key) { + var style = this.css( key ), + val = []; + + $.each( [ "em", "px", "%", "pt" ], function( i, unit ) { + if ( style.indexOf( unit ) > 0 ) { + val = [ parseFloat( style ), unit ]; + } + }); + return val; + } +}); + +})(); + +/******************************************************************************/ +/*********************************** EASING ***********************************/ +/******************************************************************************/ + +(function() { + +// based on easing equations from Robert Penner (http://www.robertpenner.com/easing) + +var baseEasings = {}; + +$.each( [ "Quad", "Cubic", "Quart", "Quint", "Expo" ], function( i, name ) { + baseEasings[ name ] = function( p ) { + return Math.pow( p, i + 2 ); + }; +}); + +$.extend( baseEasings, { + Sine: function ( p ) { + return 1 - Math.cos( p * Math.PI / 2 ); + }, + Circ: function ( p ) { + return 1 - Math.sqrt( 1 - p * p ); + }, + Elastic: function( p ) { + return p === 0 || p === 1 ? p : + -Math.pow( 2, 8 * (p - 1) ) * Math.sin( ( (p - 1) * 80 - 7.5 ) * Math.PI / 15 ); + }, + Back: function( p ) { + return p * p * ( 3 * p - 2 ); + }, + Bounce: function ( p ) { + var pow2, + bounce = 4; + + while ( p < ( ( pow2 = Math.pow( 2, --bounce ) ) - 1 ) / 11 ) {} + return 1 / Math.pow( 4, 3 - bounce ) - 7.5625 * Math.pow( ( pow2 * 3 - 2 ) / 22 - p, 2 ); + } +}); + +$.each( baseEasings, function( name, easeIn ) { + $.easing[ "easeIn" + name ] = easeIn; + $.easing[ "easeOut" + name ] = function( p ) { + return 1 - easeIn( 1 - p ); + }; + $.easing[ "easeInOut" + name ] = function( p ) { + return p < 0.5 ? + easeIn( p * 2 ) / 2 : + 1 - easeIn( p * -2 + 2 ) / 2; + }; +}); + +})(); + +})(jQuery)); +(function( $, undefined ) { + +var rvertical = /up|down|vertical/, + rpositivemotion = /up|left|vertical|horizontal/; + +$.effects.effect.blind = function( o, done ) { + // Create element + var el = $( this ), + props = [ "position", "top", "bottom", "left", "right", "height", "width" ], + mode = $.effects.setMode( el, o.mode || "hide" ), + direction = o.direction || "up", + vertical = rvertical.test( direction ), + ref = vertical ? "height" : "width", + ref2 = vertical ? "top" : "left", + motion = rpositivemotion.test( direction ), + animation = {}, + show = mode === "show", + wrapper, distance, margin; + + // if already wrapped, the wrapper's properties are my property. #6245 + if ( el.parent().is( ".ui-effects-wrapper" ) ) { + $.effects.save( el.parent(), props ); + } else { + $.effects.save( el, props ); + } + el.show(); + wrapper = $.effects.createWrapper( el ).css({ + overflow: "hidden" + }); + + distance = wrapper[ ref ](); + margin = parseFloat( wrapper.css( ref2 ) ) || 0; + + animation[ ref ] = show ? distance : 0; + if ( !motion ) { + el + .css( vertical ? "bottom" : "right", 0 ) + .css( vertical ? "top" : "left", "auto" ) + .css({ position: "absolute" }); + + animation[ ref2 ] = show ? margin : distance + margin; + } + + // start at 0 if we are showing + if ( show ) { + wrapper.css( ref, 0 ); + if ( ! motion ) { + wrapper.css( ref2, margin + distance ); + } + } + + // Animate + wrapper.animate( animation, { + duration: o.duration, + easing: o.easing, + queue: false, + complete: function() { + if ( mode === "hide" ) { + el.hide(); + } + $.effects.restore( el, props ); + $.effects.removeWrapper( el ); + done(); + } + }); + +}; + +})(jQuery); +(function( $, undefined ) { + +$.effects.effect.bounce = function( o, done ) { + var el = $( this ), + props = [ "position", "top", "bottom", "left", "right", "height", "width" ], + + // defaults: + mode = $.effects.setMode( el, o.mode || "effect" ), + hide = mode === "hide", + show = mode === "show", + direction = o.direction || "up", + distance = o.distance, + times = o.times || 5, + + // number of internal animations + anims = times * 2 + ( show || hide ? 1 : 0 ), + speed = o.duration / anims, + easing = o.easing, + + // utility: + ref = ( direction === "up" || direction === "down" ) ? "top" : "left", + motion = ( direction === "up" || direction === "left" ), + i, + upAnim, + downAnim, + + // we will need to re-assemble the queue to stack our animations in place + queue = el.queue(), + queuelen = queue.length; + + // Avoid touching opacity to prevent clearType and PNG issues in IE + if ( show || hide ) { + props.push( "opacity" ); + } + + $.effects.save( el, props ); + el.show(); + $.effects.createWrapper( el ); // Create Wrapper + + // default distance for the BIGGEST bounce is the outer Distance / 3 + if ( !distance ) { + distance = el[ ref === "top" ? "outerHeight" : "outerWidth" ]() / 3; + } + + if ( show ) { + downAnim = { opacity: 1 }; + downAnim[ ref ] = 0; + + // if we are showing, force opacity 0 and set the initial position + // then do the "first" animation + el.css( "opacity", 0 ) + .css( ref, motion ? -distance * 2 : distance * 2 ) + .animate( downAnim, speed, easing ); + } + + // start at the smallest distance if we are hiding + if ( hide ) { + distance = distance / Math.pow( 2, times - 1 ); + } + + downAnim = {}; + downAnim[ ref ] = 0; + // Bounces up/down/left/right then back to 0 -- times * 2 animations happen here + for ( i = 0; i < times; i++ ) { + upAnim = {}; + upAnim[ ref ] = ( motion ? "-=" : "+=" ) + distance; + + el.animate( upAnim, speed, easing ) + .animate( downAnim, speed, easing ); + + distance = hide ? distance * 2 : distance / 2; + } + + // Last Bounce when Hiding + if ( hide ) { + upAnim = { opacity: 0 }; + upAnim[ ref ] = ( motion ? "-=" : "+=" ) + distance; + + el.animate( upAnim, speed, easing ); + } + + el.queue(function() { + if ( hide ) { + el.hide(); + } + $.effects.restore( el, props ); + $.effects.removeWrapper( el ); + done(); + }); + + // inject all the animations we just queued to be first in line (after "inprogress") + if ( queuelen > 1) { + queue.splice.apply( queue, + [ 1, 0 ].concat( queue.splice( queuelen, anims + 1 ) ) ); + } + el.dequeue(); + +}; + +})(jQuery); +(function( $, undefined ) { + +$.effects.effect.clip = function( o, done ) { + // Create element + var el = $( this ), + props = [ "position", "top", "bottom", "left", "right", "height", "width" ], + mode = $.effects.setMode( el, o.mode || "hide" ), + show = mode === "show", + direction = o.direction || "vertical", + vert = direction === "vertical", + size = vert ? "height" : "width", + position = vert ? "top" : "left", + animation = {}, + wrapper, animate, distance; + + // Save & Show + $.effects.save( el, props ); + el.show(); + + // Create Wrapper + wrapper = $.effects.createWrapper( el ).css({ + overflow: "hidden" + }); + animate = ( el[0].tagName === "IMG" ) ? wrapper : el; + distance = animate[ size ](); + + // Shift + if ( show ) { + animate.css( size, 0 ); + animate.css( position, distance / 2 ); + } + + // Create Animation Object: + animation[ size ] = show ? distance : 0; + animation[ position ] = show ? 0 : distance / 2; + + // Animate + animate.animate( animation, { + queue: false, + duration: o.duration, + easing: o.easing, + complete: function() { + if ( !show ) { + el.hide(); + } + $.effects.restore( el, props ); + $.effects.removeWrapper( el ); + done(); + } + }); + +}; + +})(jQuery); +(function( $, undefined ) { + +$.effects.effect.drop = function( o, done ) { + + var el = $( this ), + props = [ "position", "top", "bottom", "left", "right", "opacity", "height", "width" ], + mode = $.effects.setMode( el, o.mode || "hide" ), + show = mode === "show", + direction = o.direction || "left", + ref = ( direction === "up" || direction === "down" ) ? "top" : "left", + motion = ( direction === "up" || direction === "left" ) ? "pos" : "neg", + animation = { + opacity: show ? 1 : 0 + }, + distance; + + // Adjust + $.effects.save( el, props ); + el.show(); + $.effects.createWrapper( el ); + + distance = o.distance || el[ ref === "top" ? "outerHeight": "outerWidth" ]( true ) / 2; + + if ( show ) { + el + .css( "opacity", 0 ) + .css( ref, motion === "pos" ? -distance : distance ); + } + + // Animation + animation[ ref ] = ( show ? + ( motion === "pos" ? "+=" : "-=" ) : + ( motion === "pos" ? "-=" : "+=" ) ) + + distance; + + // Animate + el.animate( animation, { + queue: false, + duration: o.duration, + easing: o.easing, + complete: function() { + if ( mode === "hide" ) { + el.hide(); + } + $.effects.restore( el, props ); + $.effects.removeWrapper( el ); + done(); + } + }); +}; + +})(jQuery); +(function( $, undefined ) { + +$.effects.effect.explode = function( o, done ) { + + var rows = o.pieces ? Math.round( Math.sqrt( o.pieces ) ) : 3, + cells = rows, + el = $( this ), + mode = $.effects.setMode( el, o.mode || "hide" ), + show = mode === "show", + + // show and then visibility:hidden the element before calculating offset + offset = el.show().css( "visibility", "hidden" ).offset(), + + // width and height of a piece + width = Math.ceil( el.outerWidth() / cells ), + height = Math.ceil( el.outerHeight() / rows ), + pieces = [], + + // loop + i, j, left, top, mx, my; + + // children animate complete: + function childComplete() { + pieces.push( this ); + if ( pieces.length === rows * cells ) { + animComplete(); + } + } + + // clone the element for each row and cell. + for( i = 0; i < rows ; i++ ) { // ===> + top = offset.top + i * height; + my = i - ( rows - 1 ) / 2 ; + + for( j = 0; j < cells ; j++ ) { // ||| + left = offset.left + j * width; + mx = j - ( cells - 1 ) / 2 ; + + // Create a clone of the now hidden main element that will be absolute positioned + // within a wrapper div off the -left and -top equal to size of our pieces + el + .clone() + .appendTo( "body" ) + .wrap( "
    " ) + .css({ + position: "absolute", + visibility: "visible", + left: -j * width, + top: -i * height + }) + + // select the wrapper - make it overflow: hidden and absolute positioned based on + // where the original was located +left and +top equal to the size of pieces + .parent() + .addClass( "ui-effects-explode" ) + .css({ + position: "absolute", + overflow: "hidden", + width: width, + height: height, + left: left + ( show ? mx * width : 0 ), + top: top + ( show ? my * height : 0 ), + opacity: show ? 0 : 1 + }).animate({ + left: left + ( show ? 0 : mx * width ), + top: top + ( show ? 0 : my * height ), + opacity: show ? 1 : 0 + }, o.duration || 500, o.easing, childComplete ); + } + } + + function animComplete() { + el.css({ + visibility: "visible" + }); + $( pieces ).remove(); + if ( !show ) { + el.hide(); + } + done(); + } +}; + +})(jQuery); +(function( $, undefined ) { + +$.effects.effect.fade = function( o, done ) { + var el = $( this ), + mode = $.effects.setMode( el, o.mode || "toggle" ); + + el.animate({ + opacity: mode + }, { + queue: false, + duration: o.duration, + easing: o.easing, + complete: done + }); +}; + +})( jQuery ); +(function( $, undefined ) { + +$.effects.effect.fold = function( o, done ) { + + // Create element + var el = $( this ), + props = [ "position", "top", "bottom", "left", "right", "height", "width" ], + mode = $.effects.setMode( el, o.mode || "hide" ), + show = mode === "show", + hide = mode === "hide", + size = o.size || 15, + percent = /([0-9]+)%/.exec( size ), + horizFirst = !!o.horizFirst, + widthFirst = show !== horizFirst, + ref = widthFirst ? [ "width", "height" ] : [ "height", "width" ], + duration = o.duration / 2, + wrapper, distance, + animation1 = {}, + animation2 = {}; + + $.effects.save( el, props ); + el.show(); + + // Create Wrapper + wrapper = $.effects.createWrapper( el ).css({ + overflow: "hidden" + }); + distance = widthFirst ? + [ wrapper.width(), wrapper.height() ] : + [ wrapper.height(), wrapper.width() ]; + + if ( percent ) { + size = parseInt( percent[ 1 ], 10 ) / 100 * distance[ hide ? 0 : 1 ]; + } + if ( show ) { + wrapper.css( horizFirst ? { + height: 0, + width: size + } : { + height: size, + width: 0 + }); + } + + // Animation + animation1[ ref[ 0 ] ] = show ? distance[ 0 ] : size; + animation2[ ref[ 1 ] ] = show ? distance[ 1 ] : 0; + + // Animate + wrapper + .animate( animation1, duration, o.easing ) + .animate( animation2, duration, o.easing, function() { + if ( hide ) { + el.hide(); + } + $.effects.restore( el, props ); + $.effects.removeWrapper( el ); + done(); + }); + +}; + +})(jQuery); +(function( $, undefined ) { + +$.effects.effect.highlight = function( o, done ) { + var elem = $( this ), + props = [ "backgroundImage", "backgroundColor", "opacity" ], + mode = $.effects.setMode( elem, o.mode || "show" ), + animation = { + backgroundColor: elem.css( "backgroundColor" ) + }; + + if (mode === "hide") { + animation.opacity = 0; + } + + $.effects.save( elem, props ); + + elem + .show() + .css({ + backgroundImage: "none", + backgroundColor: o.color || "#ffff99" + }) + .animate( animation, { + queue: false, + duration: o.duration, + easing: o.easing, + complete: function() { + if ( mode === "hide" ) { + elem.hide(); + } + $.effects.restore( elem, props ); + done(); + } + }); +}; + +})(jQuery); +(function( $, undefined ) { + +$.effects.effect.pulsate = function( o, done ) { + var elem = $( this ), + mode = $.effects.setMode( elem, o.mode || "show" ), + show = mode === "show", + hide = mode === "hide", + showhide = ( show || mode === "hide" ), + + // showing or hiding leaves of the "last" animation + anims = ( ( o.times || 5 ) * 2 ) + ( showhide ? 1 : 0 ), + duration = o.duration / anims, + animateTo = 0, + queue = elem.queue(), + queuelen = queue.length, + i; + + if ( show || !elem.is(":visible")) { + elem.css( "opacity", 0 ).show(); + animateTo = 1; + } + + // anims - 1 opacity "toggles" + for ( i = 1; i < anims; i++ ) { + elem.animate({ + opacity: animateTo + }, duration, o.easing ); + animateTo = 1 - animateTo; + } + + elem.animate({ + opacity: animateTo + }, duration, o.easing); + + elem.queue(function() { + if ( hide ) { + elem.hide(); + } + done(); + }); + + // We just queued up "anims" animations, we need to put them next in the queue + if ( queuelen > 1 ) { + queue.splice.apply( queue, + [ 1, 0 ].concat( queue.splice( queuelen, anims + 1 ) ) ); + } + elem.dequeue(); +}; + +})(jQuery); +(function( $, undefined ) { + +$.effects.effect.puff = function( o, done ) { + var elem = $( this ), + mode = $.effects.setMode( elem, o.mode || "hide" ), + hide = mode === "hide", + percent = parseInt( o.percent, 10 ) || 150, + factor = percent / 100, + original = { + height: elem.height(), + width: elem.width(), + outerHeight: elem.outerHeight(), + outerWidth: elem.outerWidth() + }; + + $.extend( o, { + effect: "scale", + queue: false, + fade: true, + mode: mode, + complete: done, + percent: hide ? percent : 100, + from: hide ? + original : + { + height: original.height * factor, + width: original.width * factor, + outerHeight: original.outerHeight * factor, + outerWidth: original.outerWidth * factor + } + }); + + elem.effect( o ); +}; + +$.effects.effect.scale = function( o, done ) { + + // Create element + var el = $( this ), + options = $.extend( true, {}, o ), + mode = $.effects.setMode( el, o.mode || "effect" ), + percent = parseInt( o.percent, 10 ) || + ( parseInt( o.percent, 10 ) === 0 ? 0 : ( mode === "hide" ? 0 : 100 ) ), + direction = o.direction || "both", + origin = o.origin, + original = { + height: el.height(), + width: el.width(), + outerHeight: el.outerHeight(), + outerWidth: el.outerWidth() + }, + factor = { + y: direction !== "horizontal" ? (percent / 100) : 1, + x: direction !== "vertical" ? (percent / 100) : 1 + }; + + // We are going to pass this effect to the size effect: + options.effect = "size"; + options.queue = false; + options.complete = done; + + // Set default origin and restore for show/hide + if ( mode !== "effect" ) { + options.origin = origin || ["middle","center"]; + options.restore = true; + } + + options.from = o.from || ( mode === "show" ? { + height: 0, + width: 0, + outerHeight: 0, + outerWidth: 0 + } : original ); + options.to = { + height: original.height * factor.y, + width: original.width * factor.x, + outerHeight: original.outerHeight * factor.y, + outerWidth: original.outerWidth * factor.x + }; + + // Fade option to support puff + if ( options.fade ) { + if ( mode === "show" ) { + options.from.opacity = 0; + options.to.opacity = 1; + } + if ( mode === "hide" ) { + options.from.opacity = 1; + options.to.opacity = 0; + } + } + + // Animate + el.effect( options ); + +}; + +$.effects.effect.size = function( o, done ) { + + // Create element + var original, baseline, factor, + el = $( this ), + props0 = [ "position", "top", "bottom", "left", "right", "width", "height", "overflow", "opacity" ], + + // Always restore + props1 = [ "position", "top", "bottom", "left", "right", "overflow", "opacity" ], + + // Copy for children + props2 = [ "width", "height", "overflow" ], + cProps = [ "fontSize" ], + vProps = [ "borderTopWidth", "borderBottomWidth", "paddingTop", "paddingBottom" ], + hProps = [ "borderLeftWidth", "borderRightWidth", "paddingLeft", "paddingRight" ], + + // Set options + mode = $.effects.setMode( el, o.mode || "effect" ), + restore = o.restore || mode !== "effect", + scale = o.scale || "both", + origin = o.origin || [ "middle", "center" ], + position = el.css( "position" ), + props = restore ? props0 : props1, + zero = { + height: 0, + width: 0, + outerHeight: 0, + outerWidth: 0 + }; + + if ( mode === "show" ) { + el.show(); + } + original = { + height: el.height(), + width: el.width(), + outerHeight: el.outerHeight(), + outerWidth: el.outerWidth() + }; + + if ( o.mode === "toggle" && mode === "show" ) { + el.from = o.to || zero; + el.to = o.from || original; + } else { + el.from = o.from || ( mode === "show" ? zero : original ); + el.to = o.to || ( mode === "hide" ? zero : original ); + } + + // Set scaling factor + factor = { + from: { + y: el.from.height / original.height, + x: el.from.width / original.width + }, + to: { + y: el.to.height / original.height, + x: el.to.width / original.width + } + }; + + // Scale the css box + if ( scale === "box" || scale === "both" ) { + + // Vertical props scaling + if ( factor.from.y !== factor.to.y ) { + props = props.concat( vProps ); + el.from = $.effects.setTransition( el, vProps, factor.from.y, el.from ); + el.to = $.effects.setTransition( el, vProps, factor.to.y, el.to ); + } + + // Horizontal props scaling + if ( factor.from.x !== factor.to.x ) { + props = props.concat( hProps ); + el.from = $.effects.setTransition( el, hProps, factor.from.x, el.from ); + el.to = $.effects.setTransition( el, hProps, factor.to.x, el.to ); + } + } + + // Scale the content + if ( scale === "content" || scale === "both" ) { + + // Vertical props scaling + if ( factor.from.y !== factor.to.y ) { + props = props.concat( cProps ).concat( props2 ); + el.from = $.effects.setTransition( el, cProps, factor.from.y, el.from ); + el.to = $.effects.setTransition( el, cProps, factor.to.y, el.to ); + } + } + + $.effects.save( el, props ); + el.show(); + $.effects.createWrapper( el ); + el.css( "overflow", "hidden" ).css( el.from ); + + // Adjust + if (origin) { // Calculate baseline shifts + baseline = $.effects.getBaseline( origin, original ); + el.from.top = ( original.outerHeight - el.outerHeight() ) * baseline.y; + el.from.left = ( original.outerWidth - el.outerWidth() ) * baseline.x; + el.to.top = ( original.outerHeight - el.to.outerHeight ) * baseline.y; + el.to.left = ( original.outerWidth - el.to.outerWidth ) * baseline.x; + } + el.css( el.from ); // set top & left + + // Animate + if ( scale === "content" || scale === "both" ) { // Scale the children + + // Add margins/font-size + vProps = vProps.concat([ "marginTop", "marginBottom" ]).concat(cProps); + hProps = hProps.concat([ "marginLeft", "marginRight" ]); + props2 = props0.concat(vProps).concat(hProps); + + el.find( "*[width]" ).each( function(){ + var child = $( this ), + c_original = { + height: child.height(), + width: child.width(), + outerHeight: child.outerHeight(), + outerWidth: child.outerWidth() + }; + if (restore) { + $.effects.save(child, props2); + } + + child.from = { + height: c_original.height * factor.from.y, + width: c_original.width * factor.from.x, + outerHeight: c_original.outerHeight * factor.from.y, + outerWidth: c_original.outerWidth * factor.from.x + }; + child.to = { + height: c_original.height * factor.to.y, + width: c_original.width * factor.to.x, + outerHeight: c_original.height * factor.to.y, + outerWidth: c_original.width * factor.to.x + }; + + // Vertical props scaling + if ( factor.from.y !== factor.to.y ) { + child.from = $.effects.setTransition( child, vProps, factor.from.y, child.from ); + child.to = $.effects.setTransition( child, vProps, factor.to.y, child.to ); + } + + // Horizontal props scaling + if ( factor.from.x !== factor.to.x ) { + child.from = $.effects.setTransition( child, hProps, factor.from.x, child.from ); + child.to = $.effects.setTransition( child, hProps, factor.to.x, child.to ); + } + + // Animate children + child.css( child.from ); + child.animate( child.to, o.duration, o.easing, function() { + + // Restore children + if ( restore ) { + $.effects.restore( child, props2 ); + } + }); + }); + } + + // Animate + el.animate( el.to, { + queue: false, + duration: o.duration, + easing: o.easing, + complete: function() { + if ( el.to.opacity === 0 ) { + el.css( "opacity", el.from.opacity ); + } + if( mode === "hide" ) { + el.hide(); + } + $.effects.restore( el, props ); + if ( !restore ) { + + // we need to calculate our new positioning based on the scaling + if ( position === "static" ) { + el.css({ + position: "relative", + top: el.to.top, + left: el.to.left + }); + } else { + $.each([ "top", "left" ], function( idx, pos ) { + el.css( pos, function( _, str ) { + var val = parseInt( str, 10 ), + toRef = idx ? el.to.left : el.to.top; + + // if original was "auto", recalculate the new value from wrapper + if ( str === "auto" ) { + return toRef + "px"; + } + + return val + toRef + "px"; + }); + }); + } + } + + $.effects.removeWrapper( el ); + done(); + } + }); + +}; + +})(jQuery); +(function( $, undefined ) { + +$.effects.effect.shake = function( o, done ) { + + var el = $( this ), + props = [ "position", "top", "bottom", "left", "right", "height", "width" ], + mode = $.effects.setMode( el, o.mode || "effect" ), + direction = o.direction || "left", + distance = o.distance || 20, + times = o.times || 3, + anims = times * 2 + 1, + speed = Math.round(o.duration/anims), + ref = (direction === "up" || direction === "down") ? "top" : "left", + positiveMotion = (direction === "up" || direction === "left"), + animation = {}, + animation1 = {}, + animation2 = {}, + i, + + // we will need to re-assemble the queue to stack our animations in place + queue = el.queue(), + queuelen = queue.length; + + $.effects.save( el, props ); + el.show(); + $.effects.createWrapper( el ); + + // Animation + animation[ ref ] = ( positiveMotion ? "-=" : "+=" ) + distance; + animation1[ ref ] = ( positiveMotion ? "+=" : "-=" ) + distance * 2; + animation2[ ref ] = ( positiveMotion ? "-=" : "+=" ) + distance * 2; + + // Animate + el.animate( animation, speed, o.easing ); + + // Shakes + for ( i = 1; i < times; i++ ) { + el.animate( animation1, speed, o.easing ).animate( animation2, speed, o.easing ); + } + el + .animate( animation1, speed, o.easing ) + .animate( animation, speed / 2, o.easing ) + .queue(function() { + if ( mode === "hide" ) { + el.hide(); + } + $.effects.restore( el, props ); + $.effects.removeWrapper( el ); + done(); + }); + + // inject all the animations we just queued to be first in line (after "inprogress") + if ( queuelen > 1) { + queue.splice.apply( queue, + [ 1, 0 ].concat( queue.splice( queuelen, anims + 1 ) ) ); + } + el.dequeue(); + +}; + +})(jQuery); +(function( $, undefined ) { + +$.effects.effect.slide = function( o, done ) { + + // Create element + var el = $( this ), + props = [ "position", "top", "bottom", "left", "right", "width", "height" ], + mode = $.effects.setMode( el, o.mode || "show" ), + show = mode === "show", + direction = o.direction || "left", + ref = (direction === "up" || direction === "down") ? "top" : "left", + positiveMotion = (direction === "up" || direction === "left"), + distance, + animation = {}; + + // Adjust + $.effects.save( el, props ); + el.show(); + distance = o.distance || el[ ref === "top" ? "outerHeight" : "outerWidth" ]( true ); + + $.effects.createWrapper( el ).css({ + overflow: "hidden" + }); + + if ( show ) { + el.css( ref, positiveMotion ? (isNaN(distance) ? "-" + distance : -distance) : distance ); + } + + // Animation + animation[ ref ] = ( show ? + ( positiveMotion ? "+=" : "-=") : + ( positiveMotion ? "-=" : "+=")) + + distance; + + // Animate + el.animate( animation, { + queue: false, + duration: o.duration, + easing: o.easing, + complete: function() { + if ( mode === "hide" ) { + el.hide(); + } + $.effects.restore( el, props ); + $.effects.removeWrapper( el ); + done(); + } + }); +}; + +})(jQuery); +(function( $, undefined ) { + +$.effects.effect.transfer = function( o, done ) { + var elem = $( this ), + target = $( o.to ), + targetFixed = target.css( "position" ) === "fixed", + body = $("body"), + fixTop = targetFixed ? body.scrollTop() : 0, + fixLeft = targetFixed ? body.scrollLeft() : 0, + endPosition = target.offset(), + animation = { + top: endPosition.top - fixTop , + left: endPosition.left - fixLeft , + height: target.innerHeight(), + width: target.innerWidth() + }, + startPosition = elem.offset(), + transfer = $( '
    ' ) + .appendTo( document.body ) + .addClass( o.className ) + .css({ + top: startPosition.top - fixTop , + left: startPosition.left - fixLeft , + height: elem.innerHeight(), + width: elem.innerWidth(), + position: targetFixed ? "fixed" : "absolute" + }) + .animate( animation, o.duration, o.easing, function() { + transfer.remove(); + done(); + }); +}; + +})(jQuery); +(function( $, undefined ) { + +var mouseHandled = false; + +$.widget( "ui.menu", { + version: "1.9.2", + defaultElement: "
      ", + delay: 300, + options: { + icons: { + submenu: "ui-icon-carat-1-e" + }, + menus: "ul", + position: { + my: "left top", + at: "right top" + }, + role: "menu", + + // callbacks + blur: null, + focus: null, + select: null + }, + + _create: function() { + this.activeMenu = this.element; + this.element + .uniqueId() + .addClass( "ui-menu ui-widget ui-widget-content ui-corner-all" ) + .toggleClass( "ui-menu-icons", !!this.element.find( ".ui-icon" ).length ) + .attr({ + role: this.options.role, + tabIndex: 0 + }) + // need to catch all clicks on disabled menu + // not possible through _on + .bind( "click" + this.eventNamespace, $.proxy(function( event ) { + if ( this.options.disabled ) { + event.preventDefault(); + } + }, this )); + + if ( this.options.disabled ) { + this.element + .addClass( "ui-state-disabled" ) + .attr( "aria-disabled", "true" ); + } + + this._on({ + // Prevent focus from sticking to links inside menu after clicking + // them (focus should always stay on UL during navigation). + "mousedown .ui-menu-item > a": function( event ) { + event.preventDefault(); + }, + "click .ui-state-disabled > a": function( event ) { + event.preventDefault(); + }, + "click .ui-menu-item:has(a)": function( event ) { + var target = $( event.target ).closest( ".ui-menu-item" ); + if ( !mouseHandled && target.not( ".ui-state-disabled" ).length ) { + mouseHandled = true; + + this.select( event ); + // Open submenu on click + if ( target.has( ".ui-menu" ).length ) { + this.expand( event ); + } else if ( !this.element.is( ":focus" ) ) { + // Redirect focus to the menu + this.element.trigger( "focus", [ true ] ); + + // If the active item is on the top level, let it stay active. + // Otherwise, blur the active item since it is no longer visible. + if ( this.active && this.active.parents( ".ui-menu" ).length === 1 ) { + clearTimeout( this.timer ); + } + } + } + }, + "mouseenter .ui-menu-item": function( event ) { + var target = $( event.currentTarget ); + // Remove ui-state-active class from siblings of the newly focused menu item + // to avoid a jump caused by adjacent elements both having a class with a border + target.siblings().children( ".ui-state-active" ).removeClass( "ui-state-active" ); + this.focus( event, target ); + }, + mouseleave: "collapseAll", + "mouseleave .ui-menu": "collapseAll", + focus: function( event, keepActiveItem ) { + // If there's already an active item, keep it active + // If not, activate the first item + var item = this.active || this.element.children( ".ui-menu-item" ).eq( 0 ); + + if ( !keepActiveItem ) { + this.focus( event, item ); + } + }, + blur: function( event ) { + this._delay(function() { + if ( !$.contains( this.element[0], this.document[0].activeElement ) ) { + this.collapseAll( event ); + } + }); + }, + keydown: "_keydown" + }); + + this.refresh(); + + // Clicks outside of a menu collapse any open menus + this._on( this.document, { + click: function( event ) { + if ( !$( event.target ).closest( ".ui-menu" ).length ) { + this.collapseAll( event ); + } + + // Reset the mouseHandled flag + mouseHandled = false; + } + }); + }, + + _destroy: function() { + // Destroy (sub)menus + this.element + .removeAttr( "aria-activedescendant" ) + .find( ".ui-menu" ).andSelf() + .removeClass( "ui-menu ui-widget ui-widget-content ui-corner-all ui-menu-icons" ) + .removeAttr( "role" ) + .removeAttr( "tabIndex" ) + .removeAttr( "aria-labelledby" ) + .removeAttr( "aria-expanded" ) + .removeAttr( "aria-hidden" ) + .removeAttr( "aria-disabled" ) + .removeUniqueId() + .show(); + + // Destroy menu items + this.element.find( ".ui-menu-item" ) + .removeClass( "ui-menu-item" ) + .removeAttr( "role" ) + .removeAttr( "aria-disabled" ) + .children( "a" ) + .removeUniqueId() + .removeClass( "ui-corner-all ui-state-hover" ) + .removeAttr( "tabIndex" ) + .removeAttr( "role" ) + .removeAttr( "aria-haspopup" ) + .children().each( function() { + var elem = $( this ); + if ( elem.data( "ui-menu-submenu-carat" ) ) { + elem.remove(); + } + }); + + // Destroy menu dividers + this.element.find( ".ui-menu-divider" ).removeClass( "ui-menu-divider ui-widget-content" ); + }, + + _keydown: function( event ) { + var match, prev, character, skip, regex, + preventDefault = true; + + function escape( value ) { + return value.replace( /[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&" ); + } + + switch ( event.keyCode ) { + case $.ui.keyCode.PAGE_UP: + this.previousPage( event ); + break; + case $.ui.keyCode.PAGE_DOWN: + this.nextPage( event ); + break; + case $.ui.keyCode.HOME: + this._move( "first", "first", event ); + break; + case $.ui.keyCode.END: + this._move( "last", "last", event ); + break; + case $.ui.keyCode.UP: + this.previous( event ); + break; + case $.ui.keyCode.DOWN: + this.next( event ); + break; + case $.ui.keyCode.LEFT: + this.collapse( event ); + break; + case $.ui.keyCode.RIGHT: + if ( this.active && !this.active.is( ".ui-state-disabled" ) ) { + this.expand( event ); + } + break; + case $.ui.keyCode.ENTER: + case $.ui.keyCode.SPACE: + this._activate( event ); + break; + case $.ui.keyCode.ESCAPE: + this.collapse( event ); + break; + default: + preventDefault = false; + prev = this.previousFilter || ""; + character = String.fromCharCode( event.keyCode ); + skip = false; + + clearTimeout( this.filterTimer ); + + if ( character === prev ) { + skip = true; + } else { + character = prev + character; + } + + regex = new RegExp( "^" + escape( character ), "i" ); + match = this.activeMenu.children( ".ui-menu-item" ).filter(function() { + return regex.test( $( this ).children( "a" ).text() ); + }); + match = skip && match.index( this.active.next() ) !== -1 ? + this.active.nextAll( ".ui-menu-item" ) : + match; + + // If no matches on the current filter, reset to the last character pressed + // to move down the menu to the first item that starts with that character + if ( !match.length ) { + character = String.fromCharCode( event.keyCode ); + regex = new RegExp( "^" + escape( character ), "i" ); + match = this.activeMenu.children( ".ui-menu-item" ).filter(function() { + return regex.test( $( this ).children( "a" ).text() ); + }); + } + + if ( match.length ) { + this.focus( event, match ); + if ( match.length > 1 ) { + this.previousFilter = character; + this.filterTimer = this._delay(function() { + delete this.previousFilter; + }, 1000 ); + } else { + delete this.previousFilter; + } + } else { + delete this.previousFilter; + } + } + + if ( preventDefault ) { + event.preventDefault(); + } + }, + + _activate: function( event ) { + if ( !this.active.is( ".ui-state-disabled" ) ) { + if ( this.active.children( "a[aria-haspopup='true']" ).length ) { + this.expand( event ); + } else { + this.select( event ); + } + } + }, + + refresh: function() { + var menus, + icon = this.options.icons.submenu, + submenus = this.element.find( this.options.menus ); + + // Initialize nested menus + submenus.filter( ":not(.ui-menu)" ) + .addClass( "ui-menu ui-widget ui-widget-content ui-corner-all" ) + .hide() + .attr({ + role: this.options.role, + "aria-hidden": "true", + "aria-expanded": "false" + }) + .each(function() { + var menu = $( this ), + item = menu.prev( "a" ), + submenuCarat = $( "" ) + .addClass( "ui-menu-icon ui-icon " + icon ) + .data( "ui-menu-submenu-carat", true ); + + item + .attr( "aria-haspopup", "true" ) + .prepend( submenuCarat ); + menu.attr( "aria-labelledby", item.attr( "id" ) ); + }); + + menus = submenus.add( this.element ); + + // Don't refresh list items that are already adapted + menus.children( ":not(.ui-menu-item):has(a)" ) + .addClass( "ui-menu-item" ) + .attr( "role", "presentation" ) + .children( "a" ) + .uniqueId() + .addClass( "ui-corner-all" ) + .attr({ + tabIndex: -1, + role: this._itemRole() + }); + + // Initialize unlinked menu-items containing spaces and/or dashes only as dividers + menus.children( ":not(.ui-menu-item)" ).each(function() { + var item = $( this ); + // hyphen, em dash, en dash + if ( !/[^\-—–\s]/.test( item.text() ) ) { + item.addClass( "ui-widget-content ui-menu-divider" ); + } + }); + + // Add aria-disabled attribute to any disabled menu item + menus.children( ".ui-state-disabled" ).attr( "aria-disabled", "true" ); + + // If the active item has been removed, blur the menu + if ( this.active && !$.contains( this.element[ 0 ], this.active[ 0 ] ) ) { + this.blur(); + } + }, + + _itemRole: function() { + return { + menu: "menuitem", + listbox: "option" + }[ this.options.role ]; + }, + + focus: function( event, item ) { + var nested, focused; + this.blur( event, event && event.type === "focus" ); + + this._scrollIntoView( item ); + + this.active = item.first(); + focused = this.active.children( "a" ).addClass( "ui-state-focus" ); + // Only update aria-activedescendant if there's a role + // otherwise we assume focus is managed elsewhere + if ( this.options.role ) { + this.element.attr( "aria-activedescendant", focused.attr( "id" ) ); + } + + // Highlight active parent menu item, if any + this.active + .parent() + .closest( ".ui-menu-item" ) + .children( "a:first" ) + .addClass( "ui-state-active" ); + + if ( event && event.type === "keydown" ) { + this._close(); + } else { + this.timer = this._delay(function() { + this._close(); + }, this.delay ); + } + + nested = item.children( ".ui-menu" ); + if ( nested.length && ( /^mouse/.test( event.type ) ) ) { + this._startOpening(nested); + } + this.activeMenu = item.parent(); + + this._trigger( "focus", event, { item: item } ); + }, + + _scrollIntoView: function( item ) { + var borderTop, paddingTop, offset, scroll, elementHeight, itemHeight; + if ( this._hasScroll() ) { + borderTop = parseFloat( $.css( this.activeMenu[0], "borderTopWidth" ) ) || 0; + paddingTop = parseFloat( $.css( this.activeMenu[0], "paddingTop" ) ) || 0; + offset = item.offset().top - this.activeMenu.offset().top - borderTop - paddingTop; + scroll = this.activeMenu.scrollTop(); + elementHeight = this.activeMenu.height(); + itemHeight = item.height(); + + if ( offset < 0 ) { + this.activeMenu.scrollTop( scroll + offset ); + } else if ( offset + itemHeight > elementHeight ) { + this.activeMenu.scrollTop( scroll + offset - elementHeight + itemHeight ); + } + } + }, + + blur: function( event, fromFocus ) { + if ( !fromFocus ) { + clearTimeout( this.timer ); + } + + if ( !this.active ) { + return; + } + + this.active.children( "a" ).removeClass( "ui-state-focus" ); + this.active = null; + + this._trigger( "blur", event, { item: this.active } ); + }, + + _startOpening: function( submenu ) { + clearTimeout( this.timer ); + + // Don't open if already open fixes a Firefox bug that caused a .5 pixel + // shift in the submenu position when mousing over the carat icon + if ( submenu.attr( "aria-hidden" ) !== "true" ) { + return; + } + + this.timer = this._delay(function() { + this._close(); + this._open( submenu ); + }, this.delay ); + }, + + _open: function( submenu ) { + var position = $.extend({ + of: this.active + }, this.options.position ); + + clearTimeout( this.timer ); + this.element.find( ".ui-menu" ).not( submenu.parents( ".ui-menu" ) ) + .hide() + .attr( "aria-hidden", "true" ); + + submenu + .show() + .removeAttr( "aria-hidden" ) + .attr( "aria-expanded", "true" ) + .position( position ); + }, + + collapseAll: function( event, all ) { + clearTimeout( this.timer ); + this.timer = this._delay(function() { + // If we were passed an event, look for the submenu that contains the event + var currentMenu = all ? this.element : + $( event && event.target ).closest( this.element.find( ".ui-menu" ) ); + + // If we found no valid submenu ancestor, use the main menu to close all sub menus anyway + if ( !currentMenu.length ) { + currentMenu = this.element; + } + + this._close( currentMenu ); + + this.blur( event ); + this.activeMenu = currentMenu; + }, this.delay ); + }, + + // With no arguments, closes the currently active menu - if nothing is active + // it closes all menus. If passed an argument, it will search for menus BELOW + _close: function( startMenu ) { + if ( !startMenu ) { + startMenu = this.active ? this.active.parent() : this.element; + } + + startMenu + .find( ".ui-menu" ) + .hide() + .attr( "aria-hidden", "true" ) + .attr( "aria-expanded", "false" ) + .end() + .find( "a.ui-state-active" ) + .removeClass( "ui-state-active" ); + }, + + collapse: function( event ) { + var newItem = this.active && + this.active.parent().closest( ".ui-menu-item", this.element ); + if ( newItem && newItem.length ) { + this._close(); + this.focus( event, newItem ); + } + }, + + expand: function( event ) { + var newItem = this.active && + this.active + .children( ".ui-menu " ) + .children( ".ui-menu-item" ) + .first(); + + if ( newItem && newItem.length ) { + this._open( newItem.parent() ); + + // Delay so Firefox will not hide activedescendant change in expanding submenu from AT + this._delay(function() { + this.focus( event, newItem ); + }); + } + }, + + next: function( event ) { + this._move( "next", "first", event ); + }, + + previous: function( event ) { + this._move( "prev", "last", event ); + }, + + isFirstItem: function() { + return this.active && !this.active.prevAll( ".ui-menu-item" ).length; + }, + + isLastItem: function() { + return this.active && !this.active.nextAll( ".ui-menu-item" ).length; + }, + + _move: function( direction, filter, event ) { + var next; + if ( this.active ) { + if ( direction === "first" || direction === "last" ) { + next = this.active + [ direction === "first" ? "prevAll" : "nextAll" ]( ".ui-menu-item" ) + .eq( -1 ); + } else { + next = this.active + [ direction + "All" ]( ".ui-menu-item" ) + .eq( 0 ); + } + } + if ( !next || !next.length || !this.active ) { + next = this.activeMenu.children( ".ui-menu-item" )[ filter ](); + } + + this.focus( event, next ); + }, + + nextPage: function( event ) { + var item, base, height; + + if ( !this.active ) { + this.next( event ); + return; + } + if ( this.isLastItem() ) { + return; + } + if ( this._hasScroll() ) { + base = this.active.offset().top; + height = this.element.height(); + this.active.nextAll( ".ui-menu-item" ).each(function() { + item = $( this ); + return item.offset().top - base - height < 0; + }); + + this.focus( event, item ); + } else { + this.focus( event, this.activeMenu.children( ".ui-menu-item" ) + [ !this.active ? "first" : "last" ]() ); + } + }, + + previousPage: function( event ) { + var item, base, height; + if ( !this.active ) { + this.next( event ); + return; + } + if ( this.isFirstItem() ) { + return; + } + if ( this._hasScroll() ) { + base = this.active.offset().top; + height = this.element.height(); + this.active.prevAll( ".ui-menu-item" ).each(function() { + item = $( this ); + return item.offset().top - base + height > 0; + }); + + this.focus( event, item ); + } else { + this.focus( event, this.activeMenu.children( ".ui-menu-item" ).first() ); + } + }, + + _hasScroll: function() { + return this.element.outerHeight() < this.element.prop( "scrollHeight" ); + }, + + select: function( event ) { + // TODO: It should never be possible to not have an active item at this + // point, but the tests don't trigger mouseenter before click. + this.active = this.active || $( event.target ).closest( ".ui-menu-item" ); + var ui = { item: this.active }; + if ( !this.active.has( ".ui-menu" ).length ) { + this.collapseAll( event, true ); + } + this._trigger( "select", event, ui ); + } +}); + +}( jQuery )); +(function( $, undefined ) { + +$.widget( "ui.progressbar", { + version: "1.9.2", + options: { + value: 0, + max: 100 + }, + + min: 0, + + _create: function() { + this.element + .addClass( "ui-progressbar ui-widget ui-widget-content ui-corner-all" ) + .attr({ + role: "progressbar", + "aria-valuemin": this.min, + "aria-valuemax": this.options.max, + "aria-valuenow": this._value() + }); + + this.valueDiv = $( "
      " ) + .appendTo( this.element ); + + this.oldValue = this._value(); + this._refreshValue(); + }, + + _destroy: function() { + this.element + .removeClass( "ui-progressbar ui-widget ui-widget-content ui-corner-all" ) + .removeAttr( "role" ) + .removeAttr( "aria-valuemin" ) + .removeAttr( "aria-valuemax" ) + .removeAttr( "aria-valuenow" ); + + this.valueDiv.remove(); + }, + + value: function( newValue ) { + if ( newValue === undefined ) { + return this._value(); + } + + this._setOption( "value", newValue ); + return this; + }, + + _setOption: function( key, value ) { + if ( key === "value" ) { + this.options.value = value; + this._refreshValue(); + if ( this._value() === this.options.max ) { + this._trigger( "complete" ); + } + } + + this._super( key, value ); + }, + + _value: function() { + var val = this.options.value; + // normalize invalid value + if ( typeof val !== "number" ) { + val = 0; + } + return Math.min( this.options.max, Math.max( this.min, val ) ); + }, + + _percentage: function() { + return 100 * this._value() / this.options.max; + }, + + _refreshValue: function() { + var value = this.value(), + percentage = this._percentage(); + + if ( this.oldValue !== value ) { + this.oldValue = value; + this._trigger( "change" ); + } + + this.valueDiv + .toggle( value > this.min ) + .toggleClass( "ui-corner-right", value === this.options.max ) + .width( percentage.toFixed(0) + "%" ); + this.element.attr( "aria-valuenow", value ); + } +}); + +})( jQuery ); +(function( $, undefined ) { + +$.widget("ui.resizable", $.ui.mouse, { + version: "1.9.2", + widgetEventPrefix: "resize", + options: { + alsoResize: false, + animate: false, + animateDuration: "slow", + animateEasing: "swing", + aspectRatio: false, + autoHide: false, + containment: false, + ghost: false, + grid: false, + handles: "e,s,se", + helper: false, + maxHeight: null, + maxWidth: null, + minHeight: 10, + minWidth: 10, + zIndex: 1000 + }, + _create: function() { + + var that = this, o = this.options; + this.element.addClass("ui-resizable"); + + $.extend(this, { + _aspectRatio: !!(o.aspectRatio), + aspectRatio: o.aspectRatio, + originalElement: this.element, + _proportionallyResizeElements: [], + _helper: o.helper || o.ghost || o.animate ? o.helper || 'ui-resizable-helper' : null + }); + + //Wrap the element if it cannot hold child nodes + if(this.element[0].nodeName.match(/canvas|textarea|input|select|button|img/i)) { + + //Create a wrapper element and set the wrapper to the new current internal element + this.element.wrap( + $('
      ').css({ + position: this.element.css('position'), + width: this.element.outerWidth(), + height: this.element.outerHeight(), + top: this.element.css('top'), + left: this.element.css('left') + }) + ); + + //Overwrite the original this.element + this.element = this.element.parent().data( + "resizable", this.element.data('resizable') + ); + + this.elementIsWrapper = true; + + //Move margins to the wrapper + this.element.css({ marginLeft: this.originalElement.css("marginLeft"), marginTop: this.originalElement.css("marginTop"), marginRight: this.originalElement.css("marginRight"), marginBottom: this.originalElement.css("marginBottom") }); + this.originalElement.css({ marginLeft: 0, marginTop: 0, marginRight: 0, marginBottom: 0}); + + //Prevent Safari textarea resize + this.originalResizeStyle = this.originalElement.css('resize'); + this.originalElement.css('resize', 'none'); + + //Push the actual element to our proportionallyResize internal array + this._proportionallyResizeElements.push(this.originalElement.css({ position: 'static', zoom: 1, display: 'block' })); + + // avoid IE jump (hard set the margin) + this.originalElement.css({ margin: this.originalElement.css('margin') }); + + // fix handlers offset + this._proportionallyResize(); + + } + + this.handles = o.handles || (!$('.ui-resizable-handle', this.element).length ? "e,s,se" : { n: '.ui-resizable-n', e: '.ui-resizable-e', s: '.ui-resizable-s', w: '.ui-resizable-w', se: '.ui-resizable-se', sw: '.ui-resizable-sw', ne: '.ui-resizable-ne', nw: '.ui-resizable-nw' }); + if(this.handles.constructor == String) { + + if(this.handles == 'all') this.handles = 'n,e,s,w,se,sw,ne,nw'; + var n = this.handles.split(","); this.handles = {}; + + for(var i = 0; i < n.length; i++) { + + var handle = $.trim(n[i]), hname = 'ui-resizable-'+handle; + var axis = $('
      '); + + // Apply zIndex to all handles - see #7960 + axis.css({ zIndex: o.zIndex }); + + //TODO : What's going on here? + if ('se' == handle) { + axis.addClass('ui-icon ui-icon-gripsmall-diagonal-se'); + }; + + //Insert into internal handles object and append to element + this.handles[handle] = '.ui-resizable-'+handle; + this.element.append(axis); + } + + } + + this._renderAxis = function(target) { + + target = target || this.element; + + for(var i in this.handles) { + + if(this.handles[i].constructor == String) + this.handles[i] = $(this.handles[i], this.element).show(); + + //Apply pad to wrapper element, needed to fix axis position (textarea, inputs, scrolls) + if (this.elementIsWrapper && this.originalElement[0].nodeName.match(/textarea|input|select|button/i)) { + + var axis = $(this.handles[i], this.element), padWrapper = 0; + + //Checking the correct pad and border + padWrapper = /sw|ne|nw|se|n|s/.test(i) ? axis.outerHeight() : axis.outerWidth(); + + //The padding type i have to apply... + var padPos = [ 'padding', + /ne|nw|n/.test(i) ? 'Top' : + /se|sw|s/.test(i) ? 'Bottom' : + /^e$/.test(i) ? 'Right' : 'Left' ].join(""); + + target.css(padPos, padWrapper); + + this._proportionallyResize(); + + } + + //TODO: What's that good for? There's not anything to be executed left + if(!$(this.handles[i]).length) + continue; + + } + }; + + //TODO: make renderAxis a prototype function + this._renderAxis(this.element); + + this._handles = $('.ui-resizable-handle', this.element) + .disableSelection(); + + //Matching axis name + this._handles.mouseover(function() { + if (!that.resizing) { + if (this.className) + var axis = this.className.match(/ui-resizable-(se|sw|ne|nw|n|e|s|w)/i); + //Axis, default = se + that.axis = axis && axis[1] ? axis[1] : 'se'; + } + }); + + //If we want to auto hide the elements + if (o.autoHide) { + this._handles.hide(); + $(this.element) + .addClass("ui-resizable-autohide") + .mouseenter(function() { + if (o.disabled) return; + $(this).removeClass("ui-resizable-autohide"); + that._handles.show(); + }) + .mouseleave(function(){ + if (o.disabled) return; + if (!that.resizing) { + $(this).addClass("ui-resizable-autohide"); + that._handles.hide(); + } + }); + } + + //Initialize the mouse interaction + this._mouseInit(); + + }, + + _destroy: function() { + + this._mouseDestroy(); + + var _destroy = function(exp) { + $(exp).removeClass("ui-resizable ui-resizable-disabled ui-resizable-resizing") + .removeData("resizable").removeData("ui-resizable").unbind(".resizable").find('.ui-resizable-handle').remove(); + }; + + //TODO: Unwrap at same DOM position + if (this.elementIsWrapper) { + _destroy(this.element); + var wrapper = this.element; + this.originalElement.css({ + position: wrapper.css('position'), + width: wrapper.outerWidth(), + height: wrapper.outerHeight(), + top: wrapper.css('top'), + left: wrapper.css('left') + }).insertAfter( wrapper ); + wrapper.remove(); + } + + this.originalElement.css('resize', this.originalResizeStyle); + _destroy(this.originalElement); + + return this; + }, + + _mouseCapture: function(event) { + var handle = false; + for (var i in this.handles) { + if ($(this.handles[i])[0] == event.target) { + handle = true; + } + } + + return !this.options.disabled && handle; + }, + + _mouseStart: function(event) { + + var o = this.options, iniPos = this.element.position(), el = this.element; + + this.resizing = true; + this.documentScroll = { top: $(document).scrollTop(), left: $(document).scrollLeft() }; + + // bugfix for http://dev.jquery.com/ticket/1749 + if (el.is('.ui-draggable') || (/absolute/).test(el.css('position'))) { + el.css({ position: 'absolute', top: iniPos.top, left: iniPos.left }); + } + + this._renderProxy(); + + var curleft = num(this.helper.css('left')), curtop = num(this.helper.css('top')); + + if (o.containment) { + curleft += $(o.containment).scrollLeft() || 0; + curtop += $(o.containment).scrollTop() || 0; + } + + //Store needed variables + this.offset = this.helper.offset(); + this.position = { left: curleft, top: curtop }; + this.size = this._helper ? { width: el.outerWidth(), height: el.outerHeight() } : { width: el.width(), height: el.height() }; + this.originalSize = this._helper ? { width: el.outerWidth(), height: el.outerHeight() } : { width: el.width(), height: el.height() }; + this.originalPosition = { left: curleft, top: curtop }; + this.sizeDiff = { width: el.outerWidth() - el.width(), height: el.outerHeight() - el.height() }; + this.originalMousePosition = { left: event.pageX, top: event.pageY }; + + //Aspect Ratio + this.aspectRatio = (typeof o.aspectRatio == 'number') ? o.aspectRatio : ((this.originalSize.width / this.originalSize.height) || 1); + + var cursor = $('.ui-resizable-' + this.axis).css('cursor'); + $('body').css('cursor', cursor == 'auto' ? this.axis + '-resize' : cursor); + + el.addClass("ui-resizable-resizing"); + this._propagate("start", event); + return true; + }, + + _mouseDrag: function(event) { + + //Increase performance, avoid regex + var el = this.helper, o = this.options, props = {}, + that = this, smp = this.originalMousePosition, a = this.axis; + + var dx = (event.pageX-smp.left)||0, dy = (event.pageY-smp.top)||0; + var trigger = this._change[a]; + if (!trigger) return false; + + // Calculate the attrs that will be change + var data = trigger.apply(this, [event, dx, dy]); + + // Put this in the mouseDrag handler since the user can start pressing shift while resizing + this._updateVirtualBoundaries(event.shiftKey); + if (this._aspectRatio || event.shiftKey) + data = this._updateRatio(data, event); + + data = this._respectSize(data, event); + + // plugins callbacks need to be called first + this._propagate("resize", event); + + el.css({ + top: this.position.top + "px", left: this.position.left + "px", + width: this.size.width + "px", height: this.size.height + "px" + }); + + if (!this._helper && this._proportionallyResizeElements.length) + this._proportionallyResize(); + + this._updateCache(data); + + // calling the user callback at the end + this._trigger('resize', event, this.ui()); + + return false; + }, + + _mouseStop: function(event) { + + this.resizing = false; + var o = this.options, that = this; + + if(this._helper) { + var pr = this._proportionallyResizeElements, ista = pr.length && (/textarea/i).test(pr[0].nodeName), + soffseth = ista && $.ui.hasScroll(pr[0], 'left') /* TODO - jump height */ ? 0 : that.sizeDiff.height, + soffsetw = ista ? 0 : that.sizeDiff.width; + + var s = { width: (that.helper.width() - soffsetw), height: (that.helper.height() - soffseth) }, + left = (parseInt(that.element.css('left'), 10) + (that.position.left - that.originalPosition.left)) || null, + top = (parseInt(that.element.css('top'), 10) + (that.position.top - that.originalPosition.top)) || null; + + if (!o.animate) + this.element.css($.extend(s, { top: top, left: left })); + + that.helper.height(that.size.height); + that.helper.width(that.size.width); + + if (this._helper && !o.animate) this._proportionallyResize(); + } + + $('body').css('cursor', 'auto'); + + this.element.removeClass("ui-resizable-resizing"); + + this._propagate("stop", event); + + if (this._helper) this.helper.remove(); + return false; + + }, + + _updateVirtualBoundaries: function(forceAspectRatio) { + var o = this.options, pMinWidth, pMaxWidth, pMinHeight, pMaxHeight, b; + + b = { + minWidth: isNumber(o.minWidth) ? o.minWidth : 0, + maxWidth: isNumber(o.maxWidth) ? o.maxWidth : Infinity, + minHeight: isNumber(o.minHeight) ? o.minHeight : 0, + maxHeight: isNumber(o.maxHeight) ? o.maxHeight : Infinity + }; + + if(this._aspectRatio || forceAspectRatio) { + // We want to create an enclosing box whose aspect ration is the requested one + // First, compute the "projected" size for each dimension based on the aspect ratio and other dimension + pMinWidth = b.minHeight * this.aspectRatio; + pMinHeight = b.minWidth / this.aspectRatio; + pMaxWidth = b.maxHeight * this.aspectRatio; + pMaxHeight = b.maxWidth / this.aspectRatio; + + if(pMinWidth > b.minWidth) b.minWidth = pMinWidth; + if(pMinHeight > b.minHeight) b.minHeight = pMinHeight; + if(pMaxWidth < b.maxWidth) b.maxWidth = pMaxWidth; + if(pMaxHeight < b.maxHeight) b.maxHeight = pMaxHeight; + } + this._vBoundaries = b; + }, + + _updateCache: function(data) { + var o = this.options; + this.offset = this.helper.offset(); + if (isNumber(data.left)) this.position.left = data.left; + if (isNumber(data.top)) this.position.top = data.top; + if (isNumber(data.height)) this.size.height = data.height; + if (isNumber(data.width)) this.size.width = data.width; + }, + + _updateRatio: function(data, event) { + + var o = this.options, cpos = this.position, csize = this.size, a = this.axis; + + if (isNumber(data.height)) data.width = (data.height * this.aspectRatio); + else if (isNumber(data.width)) data.height = (data.width / this.aspectRatio); + + if (a == 'sw') { + data.left = cpos.left + (csize.width - data.width); + data.top = null; + } + if (a == 'nw') { + data.top = cpos.top + (csize.height - data.height); + data.left = cpos.left + (csize.width - data.width); + } + + return data; + }, + + _respectSize: function(data, event) { + + var el = this.helper, o = this._vBoundaries, pRatio = this._aspectRatio || event.shiftKey, a = this.axis, + ismaxw = isNumber(data.width) && o.maxWidth && (o.maxWidth < data.width), ismaxh = isNumber(data.height) && o.maxHeight && (o.maxHeight < data.height), + isminw = isNumber(data.width) && o.minWidth && (o.minWidth > data.width), isminh = isNumber(data.height) && o.minHeight && (o.minHeight > data.height); + + if (isminw) data.width = o.minWidth; + if (isminh) data.height = o.minHeight; + if (ismaxw) data.width = o.maxWidth; + if (ismaxh) data.height = o.maxHeight; + + var dw = this.originalPosition.left + this.originalSize.width, dh = this.position.top + this.size.height; + var cw = /sw|nw|w/.test(a), ch = /nw|ne|n/.test(a); + + if (isminw && cw) data.left = dw - o.minWidth; + if (ismaxw && cw) data.left = dw - o.maxWidth; + if (isminh && ch) data.top = dh - o.minHeight; + if (ismaxh && ch) data.top = dh - o.maxHeight; + + // fixing jump error on top/left - bug #2330 + var isNotwh = !data.width && !data.height; + if (isNotwh && !data.left && data.top) data.top = null; + else if (isNotwh && !data.top && data.left) data.left = null; + + return data; + }, + + _proportionallyResize: function() { + + var o = this.options; + if (!this._proportionallyResizeElements.length) return; + var element = this.helper || this.element; + + for (var i=0; i < this._proportionallyResizeElements.length; i++) { + + var prel = this._proportionallyResizeElements[i]; + + if (!this.borderDif) { + var b = [prel.css('borderTopWidth'), prel.css('borderRightWidth'), prel.css('borderBottomWidth'), prel.css('borderLeftWidth')], + p = [prel.css('paddingTop'), prel.css('paddingRight'), prel.css('paddingBottom'), prel.css('paddingLeft')]; + + this.borderDif = $.map(b, function(v, i) { + var border = parseInt(v,10)||0, padding = parseInt(p[i],10)||0; + return border + padding; + }); + } + + prel.css({ + height: (element.height() - this.borderDif[0] - this.borderDif[2]) || 0, + width: (element.width() - this.borderDif[1] - this.borderDif[3]) || 0 + }); + + }; + + }, + + _renderProxy: function() { + + var el = this.element, o = this.options; + this.elementOffset = el.offset(); + + if(this._helper) { + + this.helper = this.helper || $('
      '); + + // fix ie6 offset TODO: This seems broken + var ie6offset = ($.ui.ie6 ? 1 : 0), + pxyoffset = ( $.ui.ie6 ? 2 : -1 ); + + this.helper.addClass(this._helper).css({ + width: this.element.outerWidth() + pxyoffset, + height: this.element.outerHeight() + pxyoffset, + position: 'absolute', + left: this.elementOffset.left - ie6offset +'px', + top: this.elementOffset.top - ie6offset +'px', + zIndex: ++o.zIndex //TODO: Don't modify option + }); + + this.helper + .appendTo("body") + .disableSelection(); + + } else { + this.helper = this.element; + } + + }, + + _change: { + e: function(event, dx, dy) { + return { width: this.originalSize.width + dx }; + }, + w: function(event, dx, dy) { + var o = this.options, cs = this.originalSize, sp = this.originalPosition; + return { left: sp.left + dx, width: cs.width - dx }; + }, + n: function(event, dx, dy) { + var o = this.options, cs = this.originalSize, sp = this.originalPosition; + return { top: sp.top + dy, height: cs.height - dy }; + }, + s: function(event, dx, dy) { + return { height: this.originalSize.height + dy }; + }, + se: function(event, dx, dy) { + return $.extend(this._change.s.apply(this, arguments), this._change.e.apply(this, [event, dx, dy])); + }, + sw: function(event, dx, dy) { + return $.extend(this._change.s.apply(this, arguments), this._change.w.apply(this, [event, dx, dy])); + }, + ne: function(event, dx, dy) { + return $.extend(this._change.n.apply(this, arguments), this._change.e.apply(this, [event, dx, dy])); + }, + nw: function(event, dx, dy) { + return $.extend(this._change.n.apply(this, arguments), this._change.w.apply(this, [event, dx, dy])); + } + }, + + _propagate: function(n, event) { + $.ui.plugin.call(this, n, [event, this.ui()]); + (n != "resize" && this._trigger(n, event, this.ui())); + }, + + plugins: {}, + + ui: function() { + return { + originalElement: this.originalElement, + element: this.element, + helper: this.helper, + position: this.position, + size: this.size, + originalSize: this.originalSize, + originalPosition: this.originalPosition + }; + } + +}); + +/* + * Resizable Extensions + */ + +$.ui.plugin.add("resizable", "alsoResize", { + + start: function (event, ui) { + var that = $(this).data("resizable"), o = that.options; + + var _store = function (exp) { + $(exp).each(function() { + var el = $(this); + el.data("resizable-alsoresize", { + width: parseInt(el.width(), 10), height: parseInt(el.height(), 10), + left: parseInt(el.css('left'), 10), top: parseInt(el.css('top'), 10) + }); + }); + }; + + if (typeof(o.alsoResize) == 'object' && !o.alsoResize.parentNode) { + if (o.alsoResize.length) { o.alsoResize = o.alsoResize[0]; _store(o.alsoResize); } + else { $.each(o.alsoResize, function (exp) { _store(exp); }); } + }else{ + _store(o.alsoResize); + } + }, + + resize: function (event, ui) { + var that = $(this).data("resizable"), o = that.options, os = that.originalSize, op = that.originalPosition; + + var delta = { + height: (that.size.height - os.height) || 0, width: (that.size.width - os.width) || 0, + top: (that.position.top - op.top) || 0, left: (that.position.left - op.left) || 0 + }, + + _alsoResize = function (exp, c) { + $(exp).each(function() { + var el = $(this), start = $(this).data("resizable-alsoresize"), style = {}, + css = c && c.length ? c : el.parents(ui.originalElement[0]).length ? ['width', 'height'] : ['width', 'height', 'top', 'left']; + + $.each(css, function (i, prop) { + var sum = (start[prop]||0) + (delta[prop]||0); + if (sum && sum >= 0) + style[prop] = sum || null; + }); + + el.css(style); + }); + }; + + if (typeof(o.alsoResize) == 'object' && !o.alsoResize.nodeType) { + $.each(o.alsoResize, function (exp, c) { _alsoResize(exp, c); }); + }else{ + _alsoResize(o.alsoResize); + } + }, + + stop: function (event, ui) { + $(this).removeData("resizable-alsoresize"); + } +}); + +$.ui.plugin.add("resizable", "animate", { + + stop: function(event, ui) { + var that = $(this).data("resizable"), o = that.options; + + var pr = that._proportionallyResizeElements, ista = pr.length && (/textarea/i).test(pr[0].nodeName), + soffseth = ista && $.ui.hasScroll(pr[0], 'left') /* TODO - jump height */ ? 0 : that.sizeDiff.height, + soffsetw = ista ? 0 : that.sizeDiff.width; + + var style = { width: (that.size.width - soffsetw), height: (that.size.height - soffseth) }, + left = (parseInt(that.element.css('left'), 10) + (that.position.left - that.originalPosition.left)) || null, + top = (parseInt(that.element.css('top'), 10) + (that.position.top - that.originalPosition.top)) || null; + + that.element.animate( + $.extend(style, top && left ? { top: top, left: left } : {}), { + duration: o.animateDuration, + easing: o.animateEasing, + step: function() { + + var data = { + width: parseInt(that.element.css('width'), 10), + height: parseInt(that.element.css('height'), 10), + top: parseInt(that.element.css('top'), 10), + left: parseInt(that.element.css('left'), 10) + }; + + if (pr && pr.length) $(pr[0]).css({ width: data.width, height: data.height }); + + // propagating resize, and updating values for each animation step + that._updateCache(data); + that._propagate("resize", event); + + } + } + ); + } + +}); + +$.ui.plugin.add("resizable", "containment", { + + start: function(event, ui) { + var that = $(this).data("resizable"), o = that.options, el = that.element; + var oc = o.containment, ce = (oc instanceof $) ? oc.get(0) : (/parent/.test(oc)) ? el.parent().get(0) : oc; + if (!ce) return; + + that.containerElement = $(ce); + + if (/document/.test(oc) || oc == document) { + that.containerOffset = { left: 0, top: 0 }; + that.containerPosition = { left: 0, top: 0 }; + + that.parentData = { + element: $(document), left: 0, top: 0, + width: $(document).width(), height: $(document).height() || document.body.parentNode.scrollHeight + }; + } + + // i'm a node, so compute top, left, right, bottom + else { + var element = $(ce), p = []; + $([ "Top", "Right", "Left", "Bottom" ]).each(function(i, name) { p[i] = num(element.css("padding" + name)); }); + + that.containerOffset = element.offset(); + that.containerPosition = element.position(); + that.containerSize = { height: (element.innerHeight() - p[3]), width: (element.innerWidth() - p[1]) }; + + var co = that.containerOffset, ch = that.containerSize.height, cw = that.containerSize.width, + width = ($.ui.hasScroll(ce, "left") ? ce.scrollWidth : cw ), height = ($.ui.hasScroll(ce) ? ce.scrollHeight : ch); + + that.parentData = { + element: ce, left: co.left, top: co.top, width: width, height: height + }; + } + }, + + resize: function(event, ui) { + var that = $(this).data("resizable"), o = that.options, + ps = that.containerSize, co = that.containerOffset, cs = that.size, cp = that.position, + pRatio = that._aspectRatio || event.shiftKey, cop = { top:0, left:0 }, ce = that.containerElement; + + if (ce[0] != document && (/static/).test(ce.css('position'))) cop = co; + + if (cp.left < (that._helper ? co.left : 0)) { + that.size.width = that.size.width + (that._helper ? (that.position.left - co.left) : (that.position.left - cop.left)); + if (pRatio) that.size.height = that.size.width / that.aspectRatio; + that.position.left = o.helper ? co.left : 0; + } + + if (cp.top < (that._helper ? co.top : 0)) { + that.size.height = that.size.height + (that._helper ? (that.position.top - co.top) : that.position.top); + if (pRatio) that.size.width = that.size.height * that.aspectRatio; + that.position.top = that._helper ? co.top : 0; + } + + that.offset.left = that.parentData.left+that.position.left; + that.offset.top = that.parentData.top+that.position.top; + + var woset = Math.abs( (that._helper ? that.offset.left - cop.left : (that.offset.left - cop.left)) + that.sizeDiff.width ), + hoset = Math.abs( (that._helper ? that.offset.top - cop.top : (that.offset.top - co.top)) + that.sizeDiff.height ); + + var isParent = that.containerElement.get(0) == that.element.parent().get(0), + isOffsetRelative = /relative|absolute/.test(that.containerElement.css('position')); + + if(isParent && isOffsetRelative) woset -= that.parentData.left; + + if (woset + that.size.width >= that.parentData.width) { + that.size.width = that.parentData.width - woset; + if (pRatio) that.size.height = that.size.width / that.aspectRatio; + } + + if (hoset + that.size.height >= that.parentData.height) { + that.size.height = that.parentData.height - hoset; + if (pRatio) that.size.width = that.size.height * that.aspectRatio; + } + }, + + stop: function(event, ui){ + var that = $(this).data("resizable"), o = that.options, cp = that.position, + co = that.containerOffset, cop = that.containerPosition, ce = that.containerElement; + + var helper = $(that.helper), ho = helper.offset(), w = helper.outerWidth() - that.sizeDiff.width, h = helper.outerHeight() - that.sizeDiff.height; + + if (that._helper && !o.animate && (/relative/).test(ce.css('position'))) + $(this).css({ left: ho.left - cop.left - co.left, width: w, height: h }); + + if (that._helper && !o.animate && (/static/).test(ce.css('position'))) + $(this).css({ left: ho.left - cop.left - co.left, width: w, height: h }); + + } +}); + +$.ui.plugin.add("resizable", "ghost", { + + start: function(event, ui) { + + var that = $(this).data("resizable"), o = that.options, cs = that.size; + + that.ghost = that.originalElement.clone(); + that.ghost + .css({ opacity: .25, display: 'block', position: 'relative', height: cs.height, width: cs.width, margin: 0, left: 0, top: 0 }) + .addClass('ui-resizable-ghost') + .addClass(typeof o.ghost == 'string' ? o.ghost : ''); + + that.ghost.appendTo(that.helper); + + }, + + resize: function(event, ui){ + var that = $(this).data("resizable"), o = that.options; + if (that.ghost) that.ghost.css({ position: 'relative', height: that.size.height, width: that.size.width }); + }, + + stop: function(event, ui){ + var that = $(this).data("resizable"), o = that.options; + if (that.ghost && that.helper) that.helper.get(0).removeChild(that.ghost.get(0)); + } + +}); + +$.ui.plugin.add("resizable", "grid", { + + resize: function(event, ui) { + var that = $(this).data("resizable"), o = that.options, cs = that.size, os = that.originalSize, op = that.originalPosition, a = that.axis, ratio = o._aspectRatio || event.shiftKey; + o.grid = typeof o.grid == "number" ? [o.grid, o.grid] : o.grid; + var ox = Math.round((cs.width - os.width) / (o.grid[0]||1)) * (o.grid[0]||1), oy = Math.round((cs.height - os.height) / (o.grid[1]||1)) * (o.grid[1]||1); + + if (/^(se|s|e)$/.test(a)) { + that.size.width = os.width + ox; + that.size.height = os.height + oy; + } + else if (/^(ne)$/.test(a)) { + that.size.width = os.width + ox; + that.size.height = os.height + oy; + that.position.top = op.top - oy; + } + else if (/^(sw)$/.test(a)) { + that.size.width = os.width + ox; + that.size.height = os.height + oy; + that.position.left = op.left - ox; + } + else { + that.size.width = os.width + ox; + that.size.height = os.height + oy; + that.position.top = op.top - oy; + that.position.left = op.left - ox; + } + } + +}); + +var num = function(v) { + return parseInt(v, 10) || 0; +}; + +var isNumber = function(value) { + return !isNaN(parseInt(value, 10)); +}; + +})(jQuery); +(function( $, undefined ) { + +$.widget("ui.selectable", $.ui.mouse, { + version: "1.9.2", + options: { + appendTo: 'body', + autoRefresh: true, + distance: 0, + filter: '*', + tolerance: 'touch' + }, + _create: function() { + var that = this; + + this.element.addClass("ui-selectable"); + + this.dragged = false; + + // cache selectee children based on filter + var selectees; + this.refresh = function() { + selectees = $(that.options.filter, that.element[0]); + selectees.addClass("ui-selectee"); + selectees.each(function() { + var $this = $(this); + var pos = $this.offset(); + $.data(this, "selectable-item", { + element: this, + $element: $this, + left: pos.left, + top: pos.top, + right: pos.left + $this.outerWidth(), + bottom: pos.top + $this.outerHeight(), + startselected: false, + selected: $this.hasClass('ui-selected'), + selecting: $this.hasClass('ui-selecting'), + unselecting: $this.hasClass('ui-unselecting') + }); + }); + }; + this.refresh(); + + this.selectees = selectees.addClass("ui-selectee"); + + this._mouseInit(); + + this.helper = $("
      "); + }, + + _destroy: function() { + this.selectees + .removeClass("ui-selectee") + .removeData("selectable-item"); + this.element + .removeClass("ui-selectable ui-selectable-disabled"); + this._mouseDestroy(); + }, + + _mouseStart: function(event) { + var that = this; + + this.opos = [event.pageX, event.pageY]; + + if (this.options.disabled) + return; + + var options = this.options; + + this.selectees = $(options.filter, this.element[0]); + + this._trigger("start", event); + + $(options.appendTo).append(this.helper); + // position helper (lasso) + this.helper.css({ + "left": event.clientX, + "top": event.clientY, + "width": 0, + "height": 0 + }); + + if (options.autoRefresh) { + this.refresh(); + } + + this.selectees.filter('.ui-selected').each(function() { + var selectee = $.data(this, "selectable-item"); + selectee.startselected = true; + if (!event.metaKey && !event.ctrlKey) { + selectee.$element.removeClass('ui-selected'); + selectee.selected = false; + selectee.$element.addClass('ui-unselecting'); + selectee.unselecting = true; + // selectable UNSELECTING callback + that._trigger("unselecting", event, { + unselecting: selectee.element + }); + } + }); + + $(event.target).parents().andSelf().each(function() { + var selectee = $.data(this, "selectable-item"); + if (selectee) { + var doSelect = (!event.metaKey && !event.ctrlKey) || !selectee.$element.hasClass('ui-selected'); + selectee.$element + .removeClass(doSelect ? "ui-unselecting" : "ui-selected") + .addClass(doSelect ? "ui-selecting" : "ui-unselecting"); + selectee.unselecting = !doSelect; + selectee.selecting = doSelect; + selectee.selected = doSelect; + // selectable (UN)SELECTING callback + if (doSelect) { + that._trigger("selecting", event, { + selecting: selectee.element + }); + } else { + that._trigger("unselecting", event, { + unselecting: selectee.element + }); + } + return false; + } + }); + + }, + + _mouseDrag: function(event) { + var that = this; + this.dragged = true; + + if (this.options.disabled) + return; + + var options = this.options; + + var x1 = this.opos[0], y1 = this.opos[1], x2 = event.pageX, y2 = event.pageY; + if (x1 > x2) { var tmp = x2; x2 = x1; x1 = tmp; } + if (y1 > y2) { var tmp = y2; y2 = y1; y1 = tmp; } + this.helper.css({left: x1, top: y1, width: x2-x1, height: y2-y1}); + + this.selectees.each(function() { + var selectee = $.data(this, "selectable-item"); + //prevent helper from being selected if appendTo: selectable + if (!selectee || selectee.element == that.element[0]) + return; + var hit = false; + if (options.tolerance == 'touch') { + hit = ( !(selectee.left > x2 || selectee.right < x1 || selectee.top > y2 || selectee.bottom < y1) ); + } else if (options.tolerance == 'fit') { + hit = (selectee.left > x1 && selectee.right < x2 && selectee.top > y1 && selectee.bottom < y2); + } + + if (hit) { + // SELECT + if (selectee.selected) { + selectee.$element.removeClass('ui-selected'); + selectee.selected = false; + } + if (selectee.unselecting) { + selectee.$element.removeClass('ui-unselecting'); + selectee.unselecting = false; + } + if (!selectee.selecting) { + selectee.$element.addClass('ui-selecting'); + selectee.selecting = true; + // selectable SELECTING callback + that._trigger("selecting", event, { + selecting: selectee.element + }); + } + } else { + // UNSELECT + if (selectee.selecting) { + if ((event.metaKey || event.ctrlKey) && selectee.startselected) { + selectee.$element.removeClass('ui-selecting'); + selectee.selecting = false; + selectee.$element.addClass('ui-selected'); + selectee.selected = true; + } else { + selectee.$element.removeClass('ui-selecting'); + selectee.selecting = false; + if (selectee.startselected) { + selectee.$element.addClass('ui-unselecting'); + selectee.unselecting = true; + } + // selectable UNSELECTING callback + that._trigger("unselecting", event, { + unselecting: selectee.element + }); + } + } + if (selectee.selected) { + if (!event.metaKey && !event.ctrlKey && !selectee.startselected) { + selectee.$element.removeClass('ui-selected'); + selectee.selected = false; + + selectee.$element.addClass('ui-unselecting'); + selectee.unselecting = true; + // selectable UNSELECTING callback + that._trigger("unselecting", event, { + unselecting: selectee.element + }); + } + } + } + }); + + return false; + }, + + _mouseStop: function(event) { + var that = this; + + this.dragged = false; + + var options = this.options; + + $('.ui-unselecting', this.element[0]).each(function() { + var selectee = $.data(this, "selectable-item"); + selectee.$element.removeClass('ui-unselecting'); + selectee.unselecting = false; + selectee.startselected = false; + that._trigger("unselected", event, { + unselected: selectee.element + }); + }); + $('.ui-selecting', this.element[0]).each(function() { + var selectee = $.data(this, "selectable-item"); + selectee.$element.removeClass('ui-selecting').addClass('ui-selected'); + selectee.selecting = false; + selectee.selected = true; + selectee.startselected = true; + that._trigger("selected", event, { + selected: selectee.element + }); + }); + this._trigger("stop", event); + + this.helper.remove(); + + return false; + } + +}); + +})(jQuery); +(function( $, undefined ) { + +// number of pages in a slider +// (how many times can you page up/down to go through the whole range) +var numPages = 5; + +$.widget( "ui.slider", $.ui.mouse, { + version: "1.9.2", + widgetEventPrefix: "slide", + + options: { + animate: false, + distance: 0, + max: 100, + min: 0, + orientation: "horizontal", + range: false, + step: 1, + value: 0, + values: null + }, + + _create: function() { + var i, handleCount, + o = this.options, + existingHandles = this.element.find( ".ui-slider-handle" ).addClass( "ui-state-default ui-corner-all" ), + handle = "", + handles = []; + + this._keySliding = false; + this._mouseSliding = false; + this._animateOff = true; + this._handleIndex = null; + this._detectOrientation(); + this._mouseInit(); + + this.element + .addClass( "ui-slider" + + " ui-slider-" + this.orientation + + " ui-widget" + + " ui-widget-content" + + " ui-corner-all" + + ( o.disabled ? " ui-slider-disabled ui-disabled" : "" ) ); + + this.range = $([]); + + if ( o.range ) { + if ( o.range === true ) { + if ( !o.values ) { + o.values = [ this._valueMin(), this._valueMin() ]; + } + if ( o.values.length && o.values.length !== 2 ) { + o.values = [ o.values[0], o.values[0] ]; + } + } + + this.range = $( "
      " ) + .appendTo( this.element ) + .addClass( "ui-slider-range" + + // note: this isn't the most fittingly semantic framework class for this element, + // but worked best visually with a variety of themes + " ui-widget-header" + + ( ( o.range === "min" || o.range === "max" ) ? " ui-slider-range-" + o.range : "" ) ); + } + + handleCount = ( o.values && o.values.length ) || 1; + + for ( i = existingHandles.length; i < handleCount; i++ ) { + handles.push( handle ); + } + + this.handles = existingHandles.add( $( handles.join( "" ) ).appendTo( this.element ) ); + + this.handle = this.handles.eq( 0 ); + + this.handles.add( this.range ).filter( "a" ) + .click(function( event ) { + event.preventDefault(); + }) + .mouseenter(function() { + if ( !o.disabled ) { + $( this ).addClass( "ui-state-hover" ); + } + }) + .mouseleave(function() { + $( this ).removeClass( "ui-state-hover" ); + }) + .focus(function() { + if ( !o.disabled ) { + $( ".ui-slider .ui-state-focus" ).removeClass( "ui-state-focus" ); + $( this ).addClass( "ui-state-focus" ); + } else { + $( this ).blur(); + } + }) + .blur(function() { + $( this ).removeClass( "ui-state-focus" ); + }); + + this.handles.each(function( i ) { + $( this ).data( "ui-slider-handle-index", i ); + }); + + this._on( this.handles, { + keydown: function( event ) { + var allowed, curVal, newVal, step, + index = $( event.target ).data( "ui-slider-handle-index" ); + + switch ( event.keyCode ) { + case $.ui.keyCode.HOME: + case $.ui.keyCode.END: + case $.ui.keyCode.PAGE_UP: + case $.ui.keyCode.PAGE_DOWN: + case $.ui.keyCode.UP: + case $.ui.keyCode.RIGHT: + case $.ui.keyCode.DOWN: + case $.ui.keyCode.LEFT: + event.preventDefault(); + if ( !this._keySliding ) { + this._keySliding = true; + $( event.target ).addClass( "ui-state-active" ); + allowed = this._start( event, index ); + if ( allowed === false ) { + return; + } + } + break; + } + + step = this.options.step; + if ( this.options.values && this.options.values.length ) { + curVal = newVal = this.values( index ); + } else { + curVal = newVal = this.value(); + } + + switch ( event.keyCode ) { + case $.ui.keyCode.HOME: + newVal = this._valueMin(); + break; + case $.ui.keyCode.END: + newVal = this._valueMax(); + break; + case $.ui.keyCode.PAGE_UP: + newVal = this._trimAlignValue( curVal + ( (this._valueMax() - this._valueMin()) / numPages ) ); + break; + case $.ui.keyCode.PAGE_DOWN: + newVal = this._trimAlignValue( curVal - ( (this._valueMax() - this._valueMin()) / numPages ) ); + break; + case $.ui.keyCode.UP: + case $.ui.keyCode.RIGHT: + if ( curVal === this._valueMax() ) { + return; + } + newVal = this._trimAlignValue( curVal + step ); + break; + case $.ui.keyCode.DOWN: + case $.ui.keyCode.LEFT: + if ( curVal === this._valueMin() ) { + return; + } + newVal = this._trimAlignValue( curVal - step ); + break; + } + + this._slide( event, index, newVal ); + }, + keyup: function( event ) { + var index = $( event.target ).data( "ui-slider-handle-index" ); + + if ( this._keySliding ) { + this._keySliding = false; + this._stop( event, index ); + this._change( event, index ); + $( event.target ).removeClass( "ui-state-active" ); + } + } + }); + + this._refreshValue(); + + this._animateOff = false; + }, + + _destroy: function() { + this.handles.remove(); + this.range.remove(); + + this.element + .removeClass( "ui-slider" + + " ui-slider-horizontal" + + " ui-slider-vertical" + + " ui-slider-disabled" + + " ui-widget" + + " ui-widget-content" + + " ui-corner-all" ); + + this._mouseDestroy(); + }, + + _mouseCapture: function( event ) { + var position, normValue, distance, closestHandle, index, allowed, offset, mouseOverHandle, + that = this, + o = this.options; + + if ( o.disabled ) { + return false; + } + + this.elementSize = { + width: this.element.outerWidth(), + height: this.element.outerHeight() + }; + this.elementOffset = this.element.offset(); + + position = { x: event.pageX, y: event.pageY }; + normValue = this._normValueFromMouse( position ); + distance = this._valueMax() - this._valueMin() + 1; + this.handles.each(function( i ) { + var thisDistance = Math.abs( normValue - that.values(i) ); + if ( distance > thisDistance ) { + distance = thisDistance; + closestHandle = $( this ); + index = i; + } + }); + + // workaround for bug #3736 (if both handles of a range are at 0, + // the first is always used as the one with least distance, + // and moving it is obviously prevented by preventing negative ranges) + if( o.range === true && this.values(1) === o.min ) { + index += 1; + closestHandle = $( this.handles[index] ); + } + + allowed = this._start( event, index ); + if ( allowed === false ) { + return false; + } + this._mouseSliding = true; + + this._handleIndex = index; + + closestHandle + .addClass( "ui-state-active" ) + .focus(); + + offset = closestHandle.offset(); + mouseOverHandle = !$( event.target ).parents().andSelf().is( ".ui-slider-handle" ); + this._clickOffset = mouseOverHandle ? { left: 0, top: 0 } : { + left: event.pageX - offset.left - ( closestHandle.width() / 2 ), + top: event.pageY - offset.top - + ( closestHandle.height() / 2 ) - + ( parseInt( closestHandle.css("borderTopWidth"), 10 ) || 0 ) - + ( parseInt( closestHandle.css("borderBottomWidth"), 10 ) || 0) + + ( parseInt( closestHandle.css("marginTop"), 10 ) || 0) + }; + + if ( !this.handles.hasClass( "ui-state-hover" ) ) { + this._slide( event, index, normValue ); + } + this._animateOff = true; + return true; + }, + + _mouseStart: function() { + return true; + }, + + _mouseDrag: function( event ) { + var position = { x: event.pageX, y: event.pageY }, + normValue = this._normValueFromMouse( position ); + + this._slide( event, this._handleIndex, normValue ); + + return false; + }, + + _mouseStop: function( event ) { + this.handles.removeClass( "ui-state-active" ); + this._mouseSliding = false; + + this._stop( event, this._handleIndex ); + this._change( event, this._handleIndex ); + + this._handleIndex = null; + this._clickOffset = null; + this._animateOff = false; + + return false; + }, + + _detectOrientation: function() { + this.orientation = ( this.options.orientation === "vertical" ) ? "vertical" : "horizontal"; + }, + + _normValueFromMouse: function( position ) { + var pixelTotal, + pixelMouse, + percentMouse, + valueTotal, + valueMouse; + + if ( this.orientation === "horizontal" ) { + pixelTotal = this.elementSize.width; + pixelMouse = position.x - this.elementOffset.left - ( this._clickOffset ? this._clickOffset.left : 0 ); + } else { + pixelTotal = this.elementSize.height; + pixelMouse = position.y - this.elementOffset.top - ( this._clickOffset ? this._clickOffset.top : 0 ); + } + + percentMouse = ( pixelMouse / pixelTotal ); + if ( percentMouse > 1 ) { + percentMouse = 1; + } + if ( percentMouse < 0 ) { + percentMouse = 0; + } + if ( this.orientation === "vertical" ) { + percentMouse = 1 - percentMouse; + } + + valueTotal = this._valueMax() - this._valueMin(); + valueMouse = this._valueMin() + percentMouse * valueTotal; + + return this._trimAlignValue( valueMouse ); + }, + + _start: function( event, index ) { + var uiHash = { + handle: this.handles[ index ], + value: this.value() + }; + if ( this.options.values && this.options.values.length ) { + uiHash.value = this.values( index ); + uiHash.values = this.values(); + } + return this._trigger( "start", event, uiHash ); + }, + + _slide: function( event, index, newVal ) { + var otherVal, + newValues, + allowed; + + if ( this.options.values && this.options.values.length ) { + otherVal = this.values( index ? 0 : 1 ); + + if ( ( this.options.values.length === 2 && this.options.range === true ) && + ( ( index === 0 && newVal > otherVal) || ( index === 1 && newVal < otherVal ) ) + ) { + newVal = otherVal; + } + + if ( newVal !== this.values( index ) ) { + newValues = this.values(); + newValues[ index ] = newVal; + // A slide can be canceled by returning false from the slide callback + allowed = this._trigger( "slide", event, { + handle: this.handles[ index ], + value: newVal, + values: newValues + } ); + otherVal = this.values( index ? 0 : 1 ); + if ( allowed !== false ) { + this.values( index, newVal, true ); + } + } + } else { + if ( newVal !== this.value() ) { + // A slide can be canceled by returning false from the slide callback + allowed = this._trigger( "slide", event, { + handle: this.handles[ index ], + value: newVal + } ); + if ( allowed !== false ) { + this.value( newVal ); + } + } + } + }, + + _stop: function( event, index ) { + var uiHash = { + handle: this.handles[ index ], + value: this.value() + }; + if ( this.options.values && this.options.values.length ) { + uiHash.value = this.values( index ); + uiHash.values = this.values(); + } + + this._trigger( "stop", event, uiHash ); + }, + + _change: function( event, index ) { + if ( !this._keySliding && !this._mouseSliding ) { + var uiHash = { + handle: this.handles[ index ], + value: this.value() + }; + if ( this.options.values && this.options.values.length ) { + uiHash.value = this.values( index ); + uiHash.values = this.values(); + } + + this._trigger( "change", event, uiHash ); + } + }, + + value: function( newValue ) { + if ( arguments.length ) { + this.options.value = this._trimAlignValue( newValue ); + this._refreshValue(); + this._change( null, 0 ); + return; + } + + return this._value(); + }, + + values: function( index, newValue ) { + var vals, + newValues, + i; + + if ( arguments.length > 1 ) { + this.options.values[ index ] = this._trimAlignValue( newValue ); + this._refreshValue(); + this._change( null, index ); + return; + } + + if ( arguments.length ) { + if ( $.isArray( arguments[ 0 ] ) ) { + vals = this.options.values; + newValues = arguments[ 0 ]; + for ( i = 0; i < vals.length; i += 1 ) { + vals[ i ] = this._trimAlignValue( newValues[ i ] ); + this._change( null, i ); + } + this._refreshValue(); + } else { + if ( this.options.values && this.options.values.length ) { + return this._values( index ); + } else { + return this.value(); + } + } + } else { + return this._values(); + } + }, + + _setOption: function( key, value ) { + var i, + valsLength = 0; + + if ( $.isArray( this.options.values ) ) { + valsLength = this.options.values.length; + } + + $.Widget.prototype._setOption.apply( this, arguments ); + + switch ( key ) { + case "disabled": + if ( value ) { + this.handles.filter( ".ui-state-focus" ).blur(); + this.handles.removeClass( "ui-state-hover" ); + this.handles.prop( "disabled", true ); + this.element.addClass( "ui-disabled" ); + } else { + this.handles.prop( "disabled", false ); + this.element.removeClass( "ui-disabled" ); + } + break; + case "orientation": + this._detectOrientation(); + this.element + .removeClass( "ui-slider-horizontal ui-slider-vertical" ) + .addClass( "ui-slider-" + this.orientation ); + this._refreshValue(); + break; + case "value": + this._animateOff = true; + this._refreshValue(); + this._change( null, 0 ); + this._animateOff = false; + break; + case "values": + this._animateOff = true; + this._refreshValue(); + for ( i = 0; i < valsLength; i += 1 ) { + this._change( null, i ); + } + this._animateOff = false; + break; + case "min": + case "max": + this._animateOff = true; + this._refreshValue(); + this._animateOff = false; + break; + } + }, + + //internal value getter + // _value() returns value trimmed by min and max, aligned by step + _value: function() { + var val = this.options.value; + val = this._trimAlignValue( val ); + + return val; + }, + + //internal values getter + // _values() returns array of values trimmed by min and max, aligned by step + // _values( index ) returns single value trimmed by min and max, aligned by step + _values: function( index ) { + var val, + vals, + i; + + if ( arguments.length ) { + val = this.options.values[ index ]; + val = this._trimAlignValue( val ); + + return val; + } else { + // .slice() creates a copy of the array + // this copy gets trimmed by min and max and then returned + vals = this.options.values.slice(); + for ( i = 0; i < vals.length; i+= 1) { + vals[ i ] = this._trimAlignValue( vals[ i ] ); + } + + return vals; + } + }, + + // returns the step-aligned value that val is closest to, between (inclusive) min and max + _trimAlignValue: function( val ) { + if ( val <= this._valueMin() ) { + return this._valueMin(); + } + if ( val >= this._valueMax() ) { + return this._valueMax(); + } + var step = ( this.options.step > 0 ) ? this.options.step : 1, + valModStep = (val - this._valueMin()) % step, + alignValue = val - valModStep; + + if ( Math.abs(valModStep) * 2 >= step ) { + alignValue += ( valModStep > 0 ) ? step : ( -step ); + } + + // Since JavaScript has problems with large floats, round + // the final value to 5 digits after the decimal point (see #4124) + return parseFloat( alignValue.toFixed(5) ); + }, + + _valueMin: function() { + return this.options.min; + }, + + _valueMax: function() { + return this.options.max; + }, + + _refreshValue: function() { + var lastValPercent, valPercent, value, valueMin, valueMax, + oRange = this.options.range, + o = this.options, + that = this, + animate = ( !this._animateOff ) ? o.animate : false, + _set = {}; + + if ( this.options.values && this.options.values.length ) { + this.handles.each(function( i ) { + valPercent = ( that.values(i) - that._valueMin() ) / ( that._valueMax() - that._valueMin() ) * 100; + _set[ that.orientation === "horizontal" ? "left" : "bottom" ] = valPercent + "%"; + $( this ).stop( 1, 1 )[ animate ? "animate" : "css" ]( _set, o.animate ); + if ( that.options.range === true ) { + if ( that.orientation === "horizontal" ) { + if ( i === 0 ) { + that.range.stop( 1, 1 )[ animate ? "animate" : "css" ]( { left: valPercent + "%" }, o.animate ); + } + if ( i === 1 ) { + that.range[ animate ? "animate" : "css" ]( { width: ( valPercent - lastValPercent ) + "%" }, { queue: false, duration: o.animate } ); + } + } else { + if ( i === 0 ) { + that.range.stop( 1, 1 )[ animate ? "animate" : "css" ]( { bottom: ( valPercent ) + "%" }, o.animate ); + } + if ( i === 1 ) { + that.range[ animate ? "animate" : "css" ]( { height: ( valPercent - lastValPercent ) + "%" }, { queue: false, duration: o.animate } ); + } + } + } + lastValPercent = valPercent; + }); + } else { + value = this.value(); + valueMin = this._valueMin(); + valueMax = this._valueMax(); + valPercent = ( valueMax !== valueMin ) ? + ( value - valueMin ) / ( valueMax - valueMin ) * 100 : + 0; + _set[ this.orientation === "horizontal" ? "left" : "bottom" ] = valPercent + "%"; + this.handle.stop( 1, 1 )[ animate ? "animate" : "css" ]( _set, o.animate ); + + if ( oRange === "min" && this.orientation === "horizontal" ) { + this.range.stop( 1, 1 )[ animate ? "animate" : "css" ]( { width: valPercent + "%" }, o.animate ); + } + if ( oRange === "max" && this.orientation === "horizontal" ) { + this.range[ animate ? "animate" : "css" ]( { width: ( 100 - valPercent ) + "%" }, { queue: false, duration: o.animate } ); + } + if ( oRange === "min" && this.orientation === "vertical" ) { + this.range.stop( 1, 1 )[ animate ? "animate" : "css" ]( { height: valPercent + "%" }, o.animate ); + } + if ( oRange === "max" && this.orientation === "vertical" ) { + this.range[ animate ? "animate" : "css" ]( { height: ( 100 - valPercent ) + "%" }, { queue: false, duration: o.animate } ); + } + } + } + +}); + +}(jQuery)); +(function( $, undefined ) { + +$.widget("ui.sortable", $.ui.mouse, { + version: "1.9.2", + widgetEventPrefix: "sort", + ready: false, + options: { + appendTo: "parent", + axis: false, + connectWith: false, + containment: false, + cursor: 'auto', + cursorAt: false, + dropOnEmpty: true, + forcePlaceholderSize: false, + forceHelperSize: false, + grid: false, + handle: false, + helper: "original", + items: '> *', + opacity: false, + placeholder: false, + revert: false, + scroll: true, + scrollSensitivity: 20, + scrollSpeed: 20, + scope: "default", + tolerance: "intersect", + zIndex: 1000 + }, + _create: function() { + + var o = this.options; + this.containerCache = {}; + this.element.addClass("ui-sortable"); + + //Get the items + this.refresh(); + + //Let's determine if the items are being displayed horizontally + this.floating = this.items.length ? o.axis === 'x' || (/left|right/).test(this.items[0].item.css('float')) || (/inline|table-cell/).test(this.items[0].item.css('display')) : false; + + //Let's determine the parent's offset + this.offset = this.element.offset(); + + //Initialize mouse events for interaction + this._mouseInit(); + + //We're ready to go + this.ready = true + + }, + + _destroy: function() { + this.element + .removeClass("ui-sortable ui-sortable-disabled"); + this._mouseDestroy(); + + for ( var i = this.items.length - 1; i >= 0; i-- ) + this.items[i].item.removeData(this.widgetName + "-item"); + + return this; + }, + + _setOption: function(key, value){ + if ( key === "disabled" ) { + this.options[ key ] = value; + + this.widget().toggleClass( "ui-sortable-disabled", !!value ); + } else { + // Don't call widget base _setOption for disable as it adds ui-state-disabled class + $.Widget.prototype._setOption.apply(this, arguments); + } + }, + + _mouseCapture: function(event, overrideHandle) { + var that = this; + + if (this.reverting) { + return false; + } + + if(this.options.disabled || this.options.type == 'static') return false; + + //We have to refresh the items data once first + this._refreshItems(event); + + //Find out if the clicked node (or one of its parents) is a actual item in this.items + var currentItem = null, nodes = $(event.target).parents().each(function() { + if($.data(this, that.widgetName + '-item') == that) { + currentItem = $(this); + return false; + } + }); + if($.data(event.target, that.widgetName + '-item') == that) currentItem = $(event.target); + + if(!currentItem) return false; + if(this.options.handle && !overrideHandle) { + var validHandle = false; + + $(this.options.handle, currentItem).find("*").andSelf().each(function() { if(this == event.target) validHandle = true; }); + if(!validHandle) return false; + } + + this.currentItem = currentItem; + this._removeCurrentsFromItems(); + return true; + + }, + + _mouseStart: function(event, overrideHandle, noActivation) { + + var o = this.options; + this.currentContainer = this; + + //We only need to call refreshPositions, because the refreshItems call has been moved to mouseCapture + this.refreshPositions(); + + //Create and append the visible helper + this.helper = this._createHelper(event); + + //Cache the helper size + this._cacheHelperProportions(); + + /* + * - Position generation - + * This block generates everything position related - it's the core of draggables. + */ + + //Cache the margins of the original element + this._cacheMargins(); + + //Get the next scrolling parent + this.scrollParent = this.helper.scrollParent(); + + //The element's absolute position on the page minus margins + this.offset = this.currentItem.offset(); + this.offset = { + top: this.offset.top - this.margins.top, + left: this.offset.left - this.margins.left + }; + + $.extend(this.offset, { + click: { //Where the click happened, relative to the element + left: event.pageX - this.offset.left, + top: event.pageY - this.offset.top + }, + parent: this._getParentOffset(), + relative: this._getRelativeOffset() //This is a relative to absolute position minus the actual position calculation - only used for relative positioned helper + }); + + // Only after we got the offset, we can change the helper's position to absolute + // TODO: Still need to figure out a way to make relative sorting possible + this.helper.css("position", "absolute"); + this.cssPosition = this.helper.css("position"); + + //Generate the original position + this.originalPosition = this._generatePosition(event); + this.originalPageX = event.pageX; + this.originalPageY = event.pageY; + + //Adjust the mouse offset relative to the helper if 'cursorAt' is supplied + (o.cursorAt && this._adjustOffsetFromHelper(o.cursorAt)); + + //Cache the former DOM position + this.domPosition = { prev: this.currentItem.prev()[0], parent: this.currentItem.parent()[0] }; + + //If the helper is not the original, hide the original so it's not playing any role during the drag, won't cause anything bad this way + if(this.helper[0] != this.currentItem[0]) { + this.currentItem.hide(); + } + + //Create the placeholder + this._createPlaceholder(); + + //Set a containment if given in the options + if(o.containment) + this._setContainment(); + + if(o.cursor) { // cursor option + if ($('body').css("cursor")) this._storedCursor = $('body').css("cursor"); + $('body').css("cursor", o.cursor); + } + + if(o.opacity) { // opacity option + if (this.helper.css("opacity")) this._storedOpacity = this.helper.css("opacity"); + this.helper.css("opacity", o.opacity); + } + + if(o.zIndex) { // zIndex option + if (this.helper.css("zIndex")) this._storedZIndex = this.helper.css("zIndex"); + this.helper.css("zIndex", o.zIndex); + } + + //Prepare scrolling + if(this.scrollParent[0] != document && this.scrollParent[0].tagName != 'HTML') + this.overflowOffset = this.scrollParent.offset(); + + //Call callbacks + this._trigger("start", event, this._uiHash()); + + //Recache the helper size + if(!this._preserveHelperProportions) + this._cacheHelperProportions(); + + + //Post 'activate' events to possible containers + if(!noActivation) { + for (var i = this.containers.length - 1; i >= 0; i--) { this.containers[i]._trigger("activate", event, this._uiHash(this)); } + } + + //Prepare possible droppables + if($.ui.ddmanager) + $.ui.ddmanager.current = this; + + if ($.ui.ddmanager && !o.dropBehaviour) + $.ui.ddmanager.prepareOffsets(this, event); + + this.dragging = true; + + this.helper.addClass("ui-sortable-helper"); + this._mouseDrag(event); //Execute the drag once - this causes the helper not to be visible before getting its correct position + return true; + + }, + + _mouseDrag: function(event) { + + //Compute the helpers position + this.position = this._generatePosition(event); + this.positionAbs = this._convertPositionTo("absolute"); + + if (!this.lastPositionAbs) { + this.lastPositionAbs = this.positionAbs; + } + + //Do scrolling + if(this.options.scroll) { + var o = this.options, scrolled = false; + if(this.scrollParent[0] != document && this.scrollParent[0].tagName != 'HTML') { + + if((this.overflowOffset.top + this.scrollParent[0].offsetHeight) - event.pageY < o.scrollSensitivity) + this.scrollParent[0].scrollTop = scrolled = this.scrollParent[0].scrollTop + o.scrollSpeed; + else if(event.pageY - this.overflowOffset.top < o.scrollSensitivity) + this.scrollParent[0].scrollTop = scrolled = this.scrollParent[0].scrollTop - o.scrollSpeed; + + if((this.overflowOffset.left + this.scrollParent[0].offsetWidth) - event.pageX < o.scrollSensitivity) + this.scrollParent[0].scrollLeft = scrolled = this.scrollParent[0].scrollLeft + o.scrollSpeed; + else if(event.pageX - this.overflowOffset.left < o.scrollSensitivity) + this.scrollParent[0].scrollLeft = scrolled = this.scrollParent[0].scrollLeft - o.scrollSpeed; + + } else { + + if(event.pageY - $(document).scrollTop() < o.scrollSensitivity) + scrolled = $(document).scrollTop($(document).scrollTop() - o.scrollSpeed); + else if($(window).height() - (event.pageY - $(document).scrollTop()) < o.scrollSensitivity) + scrolled = $(document).scrollTop($(document).scrollTop() + o.scrollSpeed); + + if(event.pageX - $(document).scrollLeft() < o.scrollSensitivity) + scrolled = $(document).scrollLeft($(document).scrollLeft() - o.scrollSpeed); + else if($(window).width() - (event.pageX - $(document).scrollLeft()) < o.scrollSensitivity) + scrolled = $(document).scrollLeft($(document).scrollLeft() + o.scrollSpeed); + + } + + if(scrolled !== false && $.ui.ddmanager && !o.dropBehaviour) + $.ui.ddmanager.prepareOffsets(this, event); + } + + //Regenerate the absolute position used for position checks + this.positionAbs = this._convertPositionTo("absolute"); + + //Set the helper position + if(!this.options.axis || this.options.axis != "y") this.helper[0].style.left = this.position.left+'px'; + if(!this.options.axis || this.options.axis != "x") this.helper[0].style.top = this.position.top+'px'; + + //Rearrange + for (var i = this.items.length - 1; i >= 0; i--) { + + //Cache variables and intersection, continue if no intersection + var item = this.items[i], itemElement = item.item[0], intersection = this._intersectsWithPointer(item); + if (!intersection) continue; + + // Only put the placeholder inside the current Container, skip all + // items form other containers. This works because when moving + // an item from one container to another the + // currentContainer is switched before the placeholder is moved. + // + // Without this moving items in "sub-sortables" can cause the placeholder to jitter + // beetween the outer and inner container. + if (item.instance !== this.currentContainer) continue; + + if (itemElement != this.currentItem[0] //cannot intersect with itself + && this.placeholder[intersection == 1 ? "next" : "prev"]()[0] != itemElement //no useless actions that have been done before + && !$.contains(this.placeholder[0], itemElement) //no action if the item moved is the parent of the item checked + && (this.options.type == 'semi-dynamic' ? !$.contains(this.element[0], itemElement) : true) + //&& itemElement.parentNode == this.placeholder[0].parentNode // only rearrange items within the same container + ) { + + this.direction = intersection == 1 ? "down" : "up"; + + if (this.options.tolerance == "pointer" || this._intersectsWithSides(item)) { + this._rearrange(event, item); + } else { + break; + } + + this._trigger("change", event, this._uiHash()); + break; + } + } + + //Post events to containers + this._contactContainers(event); + + //Interconnect with droppables + if($.ui.ddmanager) $.ui.ddmanager.drag(this, event); + + //Call callbacks + this._trigger('sort', event, this._uiHash()); + + this.lastPositionAbs = this.positionAbs; + return false; + + }, + + _mouseStop: function(event, noPropagation) { + + if(!event) return; + + //If we are using droppables, inform the manager about the drop + if ($.ui.ddmanager && !this.options.dropBehaviour) + $.ui.ddmanager.drop(this, event); + + if(this.options.revert) { + var that = this; + var cur = this.placeholder.offset(); + + this.reverting = true; + + $(this.helper).animate({ + left: cur.left - this.offset.parent.left - this.margins.left + (this.offsetParent[0] == document.body ? 0 : this.offsetParent[0].scrollLeft), + top: cur.top - this.offset.parent.top - this.margins.top + (this.offsetParent[0] == document.body ? 0 : this.offsetParent[0].scrollTop) + }, parseInt(this.options.revert, 10) || 500, function() { + that._clear(event); + }); + } else { + this._clear(event, noPropagation); + } + + return false; + + }, + + cancel: function() { + + if(this.dragging) { + + this._mouseUp({ target: null }); + + if(this.options.helper == "original") + this.currentItem.css(this._storedCSS).removeClass("ui-sortable-helper"); + else + this.currentItem.show(); + + //Post deactivating events to containers + for (var i = this.containers.length - 1; i >= 0; i--){ + this.containers[i]._trigger("deactivate", null, this._uiHash(this)); + if(this.containers[i].containerCache.over) { + this.containers[i]._trigger("out", null, this._uiHash(this)); + this.containers[i].containerCache.over = 0; + } + } + + } + + if (this.placeholder) { + //$(this.placeholder[0]).remove(); would have been the jQuery way - unfortunately, it unbinds ALL events from the original node! + if(this.placeholder[0].parentNode) this.placeholder[0].parentNode.removeChild(this.placeholder[0]); + if(this.options.helper != "original" && this.helper && this.helper[0].parentNode) this.helper.remove(); + + $.extend(this, { + helper: null, + dragging: false, + reverting: false, + _noFinalSort: null + }); + + if(this.domPosition.prev) { + $(this.domPosition.prev).after(this.currentItem); + } else { + $(this.domPosition.parent).prepend(this.currentItem); + } + } + + return this; + + }, + + serialize: function(o) { + + var items = this._getItemsAsjQuery(o && o.connected); + var str = []; o = o || {}; + + $(items).each(function() { + var res = ($(o.item || this).attr(o.attribute || 'id') || '').match(o.expression || (/(.+)[-=_](.+)/)); + if(res) str.push((o.key || res[1]+'[]')+'='+(o.key && o.expression ? res[1] : res[2])); + }); + + if(!str.length && o.key) { + str.push(o.key + '='); + } + + return str.join('&'); + + }, + + toArray: function(o) { + + var items = this._getItemsAsjQuery(o && o.connected); + var ret = []; o = o || {}; + + items.each(function() { ret.push($(o.item || this).attr(o.attribute || 'id') || ''); }); + return ret; + + }, + + /* Be careful with the following core functions */ + _intersectsWith: function(item) { + + var x1 = this.positionAbs.left, + x2 = x1 + this.helperProportions.width, + y1 = this.positionAbs.top, + y2 = y1 + this.helperProportions.height; + + var l = item.left, + r = l + item.width, + t = item.top, + b = t + item.height; + + var dyClick = this.offset.click.top, + dxClick = this.offset.click.left; + + var isOverElement = (y1 + dyClick) > t && (y1 + dyClick) < b && (x1 + dxClick) > l && (x1 + dxClick) < r; + + if( this.options.tolerance == "pointer" + || this.options.forcePointerForContainers + || (this.options.tolerance != "pointer" && this.helperProportions[this.floating ? 'width' : 'height'] > item[this.floating ? 'width' : 'height']) + ) { + return isOverElement; + } else { + + return (l < x1 + (this.helperProportions.width / 2) // Right Half + && x2 - (this.helperProportions.width / 2) < r // Left Half + && t < y1 + (this.helperProportions.height / 2) // Bottom Half + && y2 - (this.helperProportions.height / 2) < b ); // Top Half + + } + }, + + _intersectsWithPointer: function(item) { + + var isOverElementHeight = (this.options.axis === 'x') || $.ui.isOverAxis(this.positionAbs.top + this.offset.click.top, item.top, item.height), + isOverElementWidth = (this.options.axis === 'y') || $.ui.isOverAxis(this.positionAbs.left + this.offset.click.left, item.left, item.width), + isOverElement = isOverElementHeight && isOverElementWidth, + verticalDirection = this._getDragVerticalDirection(), + horizontalDirection = this._getDragHorizontalDirection(); + + if (!isOverElement) + return false; + + return this.floating ? + ( ((horizontalDirection && horizontalDirection == "right") || verticalDirection == "down") ? 2 : 1 ) + : ( verticalDirection && (verticalDirection == "down" ? 2 : 1) ); + + }, + + _intersectsWithSides: function(item) { + + var isOverBottomHalf = $.ui.isOverAxis(this.positionAbs.top + this.offset.click.top, item.top + (item.height/2), item.height), + isOverRightHalf = $.ui.isOverAxis(this.positionAbs.left + this.offset.click.left, item.left + (item.width/2), item.width), + verticalDirection = this._getDragVerticalDirection(), + horizontalDirection = this._getDragHorizontalDirection(); + + if (this.floating && horizontalDirection) { + return ((horizontalDirection == "right" && isOverRightHalf) || (horizontalDirection == "left" && !isOverRightHalf)); + } else { + return verticalDirection && ((verticalDirection == "down" && isOverBottomHalf) || (verticalDirection == "up" && !isOverBottomHalf)); + } + + }, + + _getDragVerticalDirection: function() { + var delta = this.positionAbs.top - this.lastPositionAbs.top; + return delta != 0 && (delta > 0 ? "down" : "up"); + }, + + _getDragHorizontalDirection: function() { + var delta = this.positionAbs.left - this.lastPositionAbs.left; + return delta != 0 && (delta > 0 ? "right" : "left"); + }, + + refresh: function(event) { + this._refreshItems(event); + this.refreshPositions(); + return this; + }, + + _connectWith: function() { + var options = this.options; + return options.connectWith.constructor == String + ? [options.connectWith] + : options.connectWith; + }, + + _getItemsAsjQuery: function(connected) { + + var items = []; + var queries = []; + var connectWith = this._connectWith(); + + if(connectWith && connected) { + for (var i = connectWith.length - 1; i >= 0; i--){ + var cur = $(connectWith[i]); + for (var j = cur.length - 1; j >= 0; j--){ + var inst = $.data(cur[j], this.widgetName); + if(inst && inst != this && !inst.options.disabled) { + queries.push([$.isFunction(inst.options.items) ? inst.options.items.call(inst.element) : $(inst.options.items, inst.element).not(".ui-sortable-helper").not('.ui-sortable-placeholder'), inst]); + } + }; + }; + } + + queries.push([$.isFunction(this.options.items) ? this.options.items.call(this.element, null, { options: this.options, item: this.currentItem }) : $(this.options.items, this.element).not(".ui-sortable-helper").not('.ui-sortable-placeholder'), this]); + + for (var i = queries.length - 1; i >= 0; i--){ + queries[i][0].each(function() { + items.push(this); + }); + }; + + return $(items); + + }, + + _removeCurrentsFromItems: function() { + + var list = this.currentItem.find(":data(" + this.widgetName + "-item)"); + + this.items = $.grep(this.items, function (item) { + for (var j=0; j < list.length; j++) { + if(list[j] == item.item[0]) + return false; + }; + return true; + }); + + }, + + _refreshItems: function(event) { + + this.items = []; + this.containers = [this]; + var items = this.items; + var queries = [[$.isFunction(this.options.items) ? this.options.items.call(this.element[0], event, { item: this.currentItem }) : $(this.options.items, this.element), this]]; + var connectWith = this._connectWith(); + + if(connectWith && this.ready) { //Shouldn't be run the first time through due to massive slow-down + for (var i = connectWith.length - 1; i >= 0; i--){ + var cur = $(connectWith[i]); + for (var j = cur.length - 1; j >= 0; j--){ + var inst = $.data(cur[j], this.widgetName); + if(inst && inst != this && !inst.options.disabled) { + queries.push([$.isFunction(inst.options.items) ? inst.options.items.call(inst.element[0], event, { item: this.currentItem }) : $(inst.options.items, inst.element), inst]); + this.containers.push(inst); + } + }; + }; + } + + for (var i = queries.length - 1; i >= 0; i--) { + var targetData = queries[i][1]; + var _queries = queries[i][0]; + + for (var j=0, queriesLength = _queries.length; j < queriesLength; j++) { + var item = $(_queries[j]); + + item.data(this.widgetName + '-item', targetData); // Data for target checking (mouse manager) + + items.push({ + item: item, + instance: targetData, + width: 0, height: 0, + left: 0, top: 0 + }); + }; + }; + + }, + + refreshPositions: function(fast) { + + //This has to be redone because due to the item being moved out/into the offsetParent, the offsetParent's position will change + if(this.offsetParent && this.helper) { + this.offset.parent = this._getParentOffset(); + } + + for (var i = this.items.length - 1; i >= 0; i--){ + var item = this.items[i]; + + //We ignore calculating positions of all connected containers when we're not over them + if(item.instance != this.currentContainer && this.currentContainer && item.item[0] != this.currentItem[0]) + continue; + + var t = this.options.toleranceElement ? $(this.options.toleranceElement, item.item) : item.item; + + if (!fast) { + item.width = t.outerWidth(); + item.height = t.outerHeight(); + } + + var p = t.offset(); + item.left = p.left; + item.top = p.top; + }; + + if(this.options.custom && this.options.custom.refreshContainers) { + this.options.custom.refreshContainers.call(this); + } else { + for (var i = this.containers.length - 1; i >= 0; i--){ + var p = this.containers[i].element.offset(); + this.containers[i].containerCache.left = p.left; + this.containers[i].containerCache.top = p.top; + this.containers[i].containerCache.width = this.containers[i].element.outerWidth(); + this.containers[i].containerCache.height = this.containers[i].element.outerHeight(); + }; + } + + return this; + }, + + _createPlaceholder: function(that) { + that = that || this; + var o = that.options; + + if(!o.placeholder || o.placeholder.constructor == String) { + var className = o.placeholder; + o.placeholder = { + element: function() { + + var el = $(document.createElement(that.currentItem[0].nodeName)) + .addClass(className || that.currentItem[0].className+" ui-sortable-placeholder") + .removeClass("ui-sortable-helper")[0]; + + if(!className) + el.style.visibility = "hidden"; + + return el; + }, + update: function(container, p) { + + // 1. If a className is set as 'placeholder option, we don't force sizes - the class is responsible for that + // 2. The option 'forcePlaceholderSize can be enabled to force it even if a class name is specified + if(className && !o.forcePlaceholderSize) return; + + //If the element doesn't have a actual height by itself (without styles coming from a stylesheet), it receives the inline height from the dragged item + if(!p.height()) { p.height(that.currentItem.innerHeight() - parseInt(that.currentItem.css('paddingTop')||0, 10) - parseInt(that.currentItem.css('paddingBottom')||0, 10)); }; + if(!p.width()) { p.width(that.currentItem.innerWidth() - parseInt(that.currentItem.css('paddingLeft')||0, 10) - parseInt(that.currentItem.css('paddingRight')||0, 10)); }; + } + }; + } + + //Create the placeholder + that.placeholder = $(o.placeholder.element.call(that.element, that.currentItem)); + + //Append it after the actual current item + that.currentItem.after(that.placeholder); + + //Update the size of the placeholder (TODO: Logic to fuzzy, see line 316/317) + o.placeholder.update(that, that.placeholder); + + }, + + _contactContainers: function(event) { + + // get innermost container that intersects with item + var innermostContainer = null, innermostIndex = null; + + + for (var i = this.containers.length - 1; i >= 0; i--){ + + // never consider a container that's located within the item itself + if($.contains(this.currentItem[0], this.containers[i].element[0])) + continue; + + if(this._intersectsWith(this.containers[i].containerCache)) { + + // if we've already found a container and it's more "inner" than this, then continue + if(innermostContainer && $.contains(this.containers[i].element[0], innermostContainer.element[0])) + continue; + + innermostContainer = this.containers[i]; + innermostIndex = i; + + } else { + // container doesn't intersect. trigger "out" event if necessary + if(this.containers[i].containerCache.over) { + this.containers[i]._trigger("out", event, this._uiHash(this)); + this.containers[i].containerCache.over = 0; + } + } + + } + + // if no intersecting containers found, return + if(!innermostContainer) return; + + // move the item into the container if it's not there already + if(this.containers.length === 1) { + this.containers[innermostIndex]._trigger("over", event, this._uiHash(this)); + this.containers[innermostIndex].containerCache.over = 1; + } else { + + //When entering a new container, we will find the item with the least distance and append our item near it + var dist = 10000; var itemWithLeastDistance = null; + var posProperty = this.containers[innermostIndex].floating ? 'left' : 'top'; + var sizeProperty = this.containers[innermostIndex].floating ? 'width' : 'height'; + var base = this.positionAbs[posProperty] + this.offset.click[posProperty]; + for (var j = this.items.length - 1; j >= 0; j--) { + if(!$.contains(this.containers[innermostIndex].element[0], this.items[j].item[0])) continue; + if(this.items[j].item[0] == this.currentItem[0]) continue; + var cur = this.items[j].item.offset()[posProperty]; + var nearBottom = false; + if(Math.abs(cur - base) > Math.abs(cur + this.items[j][sizeProperty] - base)){ + nearBottom = true; + cur += this.items[j][sizeProperty]; + } + + if(Math.abs(cur - base) < dist) { + dist = Math.abs(cur - base); itemWithLeastDistance = this.items[j]; + this.direction = nearBottom ? "up": "down"; + } + } + + if(!itemWithLeastDistance && !this.options.dropOnEmpty) //Check if dropOnEmpty is enabled + return; + + this.currentContainer = this.containers[innermostIndex]; + itemWithLeastDistance ? this._rearrange(event, itemWithLeastDistance, null, true) : this._rearrange(event, null, this.containers[innermostIndex].element, true); + this._trigger("change", event, this._uiHash()); + this.containers[innermostIndex]._trigger("change", event, this._uiHash(this)); + + //Update the placeholder + this.options.placeholder.update(this.currentContainer, this.placeholder); + + this.containers[innermostIndex]._trigger("over", event, this._uiHash(this)); + this.containers[innermostIndex].containerCache.over = 1; + } + + + }, + + _createHelper: function(event) { + + var o = this.options; + var helper = $.isFunction(o.helper) ? $(o.helper.apply(this.element[0], [event, this.currentItem])) : (o.helper == 'clone' ? this.currentItem.clone() : this.currentItem); + + if(!helper.parents('body').length) //Add the helper to the DOM if that didn't happen already + $(o.appendTo != 'parent' ? o.appendTo : this.currentItem[0].parentNode)[0].appendChild(helper[0]); + + if(helper[0] == this.currentItem[0]) + this._storedCSS = { width: this.currentItem[0].style.width, height: this.currentItem[0].style.height, position: this.currentItem.css("position"), top: this.currentItem.css("top"), left: this.currentItem.css("left") }; + + if(helper[0].style.width == '' || o.forceHelperSize) helper.width(this.currentItem.width()); + if(helper[0].style.height == '' || o.forceHelperSize) helper.height(this.currentItem.height()); + + return helper; + + }, + + _adjustOffsetFromHelper: function(obj) { + if (typeof obj == 'string') { + obj = obj.split(' '); + } + if ($.isArray(obj)) { + obj = {left: +obj[0], top: +obj[1] || 0}; + } + if ('left' in obj) { + this.offset.click.left = obj.left + this.margins.left; + } + if ('right' in obj) { + this.offset.click.left = this.helperProportions.width - obj.right + this.margins.left; + } + if ('top' in obj) { + this.offset.click.top = obj.top + this.margins.top; + } + if ('bottom' in obj) { + this.offset.click.top = this.helperProportions.height - obj.bottom + this.margins.top; + } + }, + + _getParentOffset: function() { + + + //Get the offsetParent and cache its position + this.offsetParent = this.helper.offsetParent(); + var po = this.offsetParent.offset(); + + // This is a special case where we need to modify a offset calculated on start, since the following happened: + // 1. The position of the helper is absolute, so it's position is calculated based on the next positioned parent + // 2. The actual offset parent is a child of the scroll parent, and the scroll parent isn't the document, which means that + // the scroll is included in the initial calculation of the offset of the parent, and never recalculated upon drag + if(this.cssPosition == 'absolute' && this.scrollParent[0] != document && $.contains(this.scrollParent[0], this.offsetParent[0])) { + po.left += this.scrollParent.scrollLeft(); + po.top += this.scrollParent.scrollTop(); + } + + if((this.offsetParent[0] == document.body) //This needs to be actually done for all browsers, since pageX/pageY includes this information + || (this.offsetParent[0].tagName && this.offsetParent[0].tagName.toLowerCase() == 'html' && $.ui.ie)) //Ugly IE fix + po = { top: 0, left: 0 }; + + return { + top: po.top + (parseInt(this.offsetParent.css("borderTopWidth"),10) || 0), + left: po.left + (parseInt(this.offsetParent.css("borderLeftWidth"),10) || 0) + }; + + }, + + _getRelativeOffset: function() { + + if(this.cssPosition == "relative") { + var p = this.currentItem.position(); + return { + top: p.top - (parseInt(this.helper.css("top"),10) || 0) + this.scrollParent.scrollTop(), + left: p.left - (parseInt(this.helper.css("left"),10) || 0) + this.scrollParent.scrollLeft() + }; + } else { + return { top: 0, left: 0 }; + } + + }, + + _cacheMargins: function() { + this.margins = { + left: (parseInt(this.currentItem.css("marginLeft"),10) || 0), + top: (parseInt(this.currentItem.css("marginTop"),10) || 0) + }; + }, + + _cacheHelperProportions: function() { + this.helperProportions = { + width: this.helper.outerWidth(), + height: this.helper.outerHeight() + }; + }, + + _setContainment: function() { + + var o = this.options; + if(o.containment == 'parent') o.containment = this.helper[0].parentNode; + if(o.containment == 'document' || o.containment == 'window') this.containment = [ + 0 - this.offset.relative.left - this.offset.parent.left, + 0 - this.offset.relative.top - this.offset.parent.top, + $(o.containment == 'document' ? document : window).width() - this.helperProportions.width - this.margins.left, + ($(o.containment == 'document' ? document : window).height() || document.body.parentNode.scrollHeight) - this.helperProportions.height - this.margins.top + ]; + + if(!(/^(document|window|parent)$/).test(o.containment)) { + var ce = $(o.containment)[0]; + var co = $(o.containment).offset(); + var over = ($(ce).css("overflow") != 'hidden'); + + this.containment = [ + co.left + (parseInt($(ce).css("borderLeftWidth"),10) || 0) + (parseInt($(ce).css("paddingLeft"),10) || 0) - this.margins.left, + co.top + (parseInt($(ce).css("borderTopWidth"),10) || 0) + (parseInt($(ce).css("paddingTop"),10) || 0) - this.margins.top, + co.left+(over ? Math.max(ce.scrollWidth,ce.offsetWidth) : ce.offsetWidth) - (parseInt($(ce).css("borderLeftWidth"),10) || 0) - (parseInt($(ce).css("paddingRight"),10) || 0) - this.helperProportions.width - this.margins.left, + co.top+(over ? Math.max(ce.scrollHeight,ce.offsetHeight) : ce.offsetHeight) - (parseInt($(ce).css("borderTopWidth"),10) || 0) - (parseInt($(ce).css("paddingBottom"),10) || 0) - this.helperProportions.height - this.margins.top + ]; + } + + }, + + _convertPositionTo: function(d, pos) { + + if(!pos) pos = this.position; + var mod = d == "absolute" ? 1 : -1; + var o = this.options, scroll = this.cssPosition == 'absolute' && !(this.scrollParent[0] != document && $.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName); + + return { + top: ( + pos.top // The absolute mouse position + + this.offset.relative.top * mod // Only for relative positioned nodes: Relative offset from element to offset parent + + this.offset.parent.top * mod // The offsetParent's offset without borders (offset + border) + - ( ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ) * mod) + ), + left: ( + pos.left // The absolute mouse position + + this.offset.relative.left * mod // Only for relative positioned nodes: Relative offset from element to offset parent + + this.offset.parent.left * mod // The offsetParent's offset without borders (offset + border) + - ( ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() ) * mod) + ) + }; + + }, + + _generatePosition: function(event) { + + var o = this.options, scroll = this.cssPosition == 'absolute' && !(this.scrollParent[0] != document && $.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName); + + // This is another very weird special case that only happens for relative elements: + // 1. If the css position is relative + // 2. and the scroll parent is the document or similar to the offset parent + // we have to refresh the relative offset during the scroll so there are no jumps + if(this.cssPosition == 'relative' && !(this.scrollParent[0] != document && this.scrollParent[0] != this.offsetParent[0])) { + this.offset.relative = this._getRelativeOffset(); + } + + var pageX = event.pageX; + var pageY = event.pageY; + + /* + * - Position constraining - + * Constrain the position to a mix of grid, containment. + */ + + if(this.originalPosition) { //If we are not dragging yet, we won't check for options + + if(this.containment) { + if(event.pageX - this.offset.click.left < this.containment[0]) pageX = this.containment[0] + this.offset.click.left; + if(event.pageY - this.offset.click.top < this.containment[1]) pageY = this.containment[1] + this.offset.click.top; + if(event.pageX - this.offset.click.left > this.containment[2]) pageX = this.containment[2] + this.offset.click.left; + if(event.pageY - this.offset.click.top > this.containment[3]) pageY = this.containment[3] + this.offset.click.top; + } + + if(o.grid) { + var top = this.originalPageY + Math.round((pageY - this.originalPageY) / o.grid[1]) * o.grid[1]; + pageY = this.containment ? (!(top - this.offset.click.top < this.containment[1] || top - this.offset.click.top > this.containment[3]) ? top : (!(top - this.offset.click.top < this.containment[1]) ? top - o.grid[1] : top + o.grid[1])) : top; + + var left = this.originalPageX + Math.round((pageX - this.originalPageX) / o.grid[0]) * o.grid[0]; + pageX = this.containment ? (!(left - this.offset.click.left < this.containment[0] || left - this.offset.click.left > this.containment[2]) ? left : (!(left - this.offset.click.left < this.containment[0]) ? left - o.grid[0] : left + o.grid[0])) : left; + } + + } + + return { + top: ( + pageY // The absolute mouse position + - this.offset.click.top // Click offset (relative to the element) + - this.offset.relative.top // Only for relative positioned nodes: Relative offset from element to offset parent + - this.offset.parent.top // The offsetParent's offset without borders (offset + border) + + ( ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) )) + ), + left: ( + pageX // The absolute mouse position + - this.offset.click.left // Click offset (relative to the element) + - this.offset.relative.left // Only for relative positioned nodes: Relative offset from element to offset parent + - this.offset.parent.left // The offsetParent's offset without borders (offset + border) + + ( ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() )) + ) + }; + + }, + + _rearrange: function(event, i, a, hardRefresh) { + + a ? a[0].appendChild(this.placeholder[0]) : i.item[0].parentNode.insertBefore(this.placeholder[0], (this.direction == 'down' ? i.item[0] : i.item[0].nextSibling)); + + //Various things done here to improve the performance: + // 1. we create a setTimeout, that calls refreshPositions + // 2. on the instance, we have a counter variable, that get's higher after every append + // 3. on the local scope, we copy the counter variable, and check in the timeout, if it's still the same + // 4. this lets only the last addition to the timeout stack through + this.counter = this.counter ? ++this.counter : 1; + var counter = this.counter; + + this._delay(function() { + if(counter == this.counter) this.refreshPositions(!hardRefresh); //Precompute after each DOM insertion, NOT on mousemove + }); + + }, + + _clear: function(event, noPropagation) { + + this.reverting = false; + // We delay all events that have to be triggered to after the point where the placeholder has been removed and + // everything else normalized again + var delayedTriggers = []; + + // We first have to update the dom position of the actual currentItem + // Note: don't do it if the current item is already removed (by a user), or it gets reappended (see #4088) + if(!this._noFinalSort && this.currentItem.parent().length) this.placeholder.before(this.currentItem); + this._noFinalSort = null; + + if(this.helper[0] == this.currentItem[0]) { + for(var i in this._storedCSS) { + if(this._storedCSS[i] == 'auto' || this._storedCSS[i] == 'static') this._storedCSS[i] = ''; + } + this.currentItem.css(this._storedCSS).removeClass("ui-sortable-helper"); + } else { + this.currentItem.show(); + } + + if(this.fromOutside && !noPropagation) delayedTriggers.push(function(event) { this._trigger("receive", event, this._uiHash(this.fromOutside)); }); + if((this.fromOutside || this.domPosition.prev != this.currentItem.prev().not(".ui-sortable-helper")[0] || this.domPosition.parent != this.currentItem.parent()[0]) && !noPropagation) delayedTriggers.push(function(event) { this._trigger("update", event, this._uiHash()); }); //Trigger update callback if the DOM position has changed + + // Check if the items Container has Changed and trigger appropriate + // events. + if (this !== this.currentContainer) { + if(!noPropagation) { + delayedTriggers.push(function(event) { this._trigger("remove", event, this._uiHash()); }); + delayedTriggers.push((function(c) { return function(event) { c._trigger("receive", event, this._uiHash(this)); }; }).call(this, this.currentContainer)); + delayedTriggers.push((function(c) { return function(event) { c._trigger("update", event, this._uiHash(this)); }; }).call(this, this.currentContainer)); + } + } + + + //Post events to containers + for (var i = this.containers.length - 1; i >= 0; i--){ + if(!noPropagation) delayedTriggers.push((function(c) { return function(event) { c._trigger("deactivate", event, this._uiHash(this)); }; }).call(this, this.containers[i])); + if(this.containers[i].containerCache.over) { + delayedTriggers.push((function(c) { return function(event) { c._trigger("out", event, this._uiHash(this)); }; }).call(this, this.containers[i])); + this.containers[i].containerCache.over = 0; + } + } + + //Do what was originally in plugins + if(this._storedCursor) $('body').css("cursor", this._storedCursor); //Reset cursor + if(this._storedOpacity) this.helper.css("opacity", this._storedOpacity); //Reset opacity + if(this._storedZIndex) this.helper.css("zIndex", this._storedZIndex == 'auto' ? '' : this._storedZIndex); //Reset z-index + + this.dragging = false; + if(this.cancelHelperRemoval) { + if(!noPropagation) { + this._trigger("beforeStop", event, this._uiHash()); + for (var i=0; i < delayedTriggers.length; i++) { delayedTriggers[i].call(this, event); }; //Trigger all delayed events + this._trigger("stop", event, this._uiHash()); + } + + this.fromOutside = false; + return false; + } + + if(!noPropagation) this._trigger("beforeStop", event, this._uiHash()); + + //$(this.placeholder[0]).remove(); would have been the jQuery way - unfortunately, it unbinds ALL events from the original node! + this.placeholder[0].parentNode.removeChild(this.placeholder[0]); + + if(this.helper[0] != this.currentItem[0]) this.helper.remove(); this.helper = null; + + if(!noPropagation) { + for (var i=0; i < delayedTriggers.length; i++) { delayedTriggers[i].call(this, event); }; //Trigger all delayed events + this._trigger("stop", event, this._uiHash()); + } + + this.fromOutside = false; + return true; + + }, + + _trigger: function() { + if ($.Widget.prototype._trigger.apply(this, arguments) === false) { + this.cancel(); + } + }, + + _uiHash: function(_inst) { + var inst = _inst || this; + return { + helper: inst.helper, + placeholder: inst.placeholder || $([]), + position: inst.position, + originalPosition: inst.originalPosition, + offset: inst.positionAbs, + item: inst.currentItem, + sender: _inst ? _inst.element : null + }; + } + +}); + +})(jQuery); +(function( $ ) { + +function modifier( fn ) { + return function() { + var previous = this.element.val(); + fn.apply( this, arguments ); + this._refresh(); + if ( previous !== this.element.val() ) { + this._trigger( "change" ); + } + }; +} + +$.widget( "ui.spinner", { + version: "1.9.2", + defaultElement: "", + widgetEventPrefix: "spin", + options: { + culture: null, + icons: { + down: "ui-icon-triangle-1-s", + up: "ui-icon-triangle-1-n" + }, + incremental: true, + max: null, + min: null, + numberFormat: null, + page: 10, + step: 1, + + change: null, + spin: null, + start: null, + stop: null + }, + + _create: function() { + // handle string values that need to be parsed + this._setOption( "max", this.options.max ); + this._setOption( "min", this.options.min ); + this._setOption( "step", this.options.step ); + + // format the value, but don't constrain + this._value( this.element.val(), true ); + + this._draw(); + this._on( this._events ); + this._refresh(); + + // turning off autocomplete prevents the browser from remembering the + // value when navigating through history, so we re-enable autocomplete + // if the page is unloaded before the widget is destroyed. #7790 + this._on( this.window, { + beforeunload: function() { + this.element.removeAttr( "autocomplete" ); + } + }); + }, + + _getCreateOptions: function() { + var options = {}, + element = this.element; + + $.each( [ "min", "max", "step" ], function( i, option ) { + var value = element.attr( option ); + if ( value !== undefined && value.length ) { + options[ option ] = value; + } + }); + + return options; + }, + + _events: { + keydown: function( event ) { + if ( this._start( event ) && this._keydown( event ) ) { + event.preventDefault(); + } + }, + keyup: "_stop", + focus: function() { + this.previous = this.element.val(); + }, + blur: function( event ) { + if ( this.cancelBlur ) { + delete this.cancelBlur; + return; + } + + this._refresh(); + if ( this.previous !== this.element.val() ) { + this._trigger( "change", event ); + } + }, + mousewheel: function( event, delta ) { + if ( !delta ) { + return; + } + if ( !this.spinning && !this._start( event ) ) { + return false; + } + + this._spin( (delta > 0 ? 1 : -1) * this.options.step, event ); + clearTimeout( this.mousewheelTimer ); + this.mousewheelTimer = this._delay(function() { + if ( this.spinning ) { + this._stop( event ); + } + }, 100 ); + event.preventDefault(); + }, + "mousedown .ui-spinner-button": function( event ) { + var previous; + + // We never want the buttons to have focus; whenever the user is + // interacting with the spinner, the focus should be on the input. + // If the input is focused then this.previous is properly set from + // when the input first received focus. If the input is not focused + // then we need to set this.previous based on the value before spinning. + previous = this.element[0] === this.document[0].activeElement ? + this.previous : this.element.val(); + function checkFocus() { + var isActive = this.element[0] === this.document[0].activeElement; + if ( !isActive ) { + this.element.focus(); + this.previous = previous; + // support: IE + // IE sets focus asynchronously, so we need to check if focus + // moved off of the input because the user clicked on the button. + this._delay(function() { + this.previous = previous; + }); + } + } + + // ensure focus is on (or stays on) the text field + event.preventDefault(); + checkFocus.call( this ); + + // support: IE + // IE doesn't prevent moving focus even with event.preventDefault() + // so we set a flag to know when we should ignore the blur event + // and check (again) if focus moved off of the input. + this.cancelBlur = true; + this._delay(function() { + delete this.cancelBlur; + checkFocus.call( this ); + }); + + if ( this._start( event ) === false ) { + return; + } + + this._repeat( null, $( event.currentTarget ).hasClass( "ui-spinner-up" ) ? 1 : -1, event ); + }, + "mouseup .ui-spinner-button": "_stop", + "mouseenter .ui-spinner-button": function( event ) { + // button will add ui-state-active if mouse was down while mouseleave and kept down + if ( !$( event.currentTarget ).hasClass( "ui-state-active" ) ) { + return; + } + + if ( this._start( event ) === false ) { + return false; + } + this._repeat( null, $( event.currentTarget ).hasClass( "ui-spinner-up" ) ? 1 : -1, event ); + }, + // TODO: do we really want to consider this a stop? + // shouldn't we just stop the repeater and wait until mouseup before + // we trigger the stop event? + "mouseleave .ui-spinner-button": "_stop" + }, + + _draw: function() { + var uiSpinner = this.uiSpinner = this.element + .addClass( "ui-spinner-input" ) + .attr( "autocomplete", "off" ) + .wrap( this._uiSpinnerHtml() ) + .parent() + // add buttons + .append( this._buttonHtml() ); + + this.element.attr( "role", "spinbutton" ); + + // button bindings + this.buttons = uiSpinner.find( ".ui-spinner-button" ) + .attr( "tabIndex", -1 ) + .button() + .removeClass( "ui-corner-all" ); + + // IE 6 doesn't understand height: 50% for the buttons + // unless the wrapper has an explicit height + if ( this.buttons.height() > Math.ceil( uiSpinner.height() * 0.5 ) && + uiSpinner.height() > 0 ) { + uiSpinner.height( uiSpinner.height() ); + } + + // disable spinner if element was already disabled + if ( this.options.disabled ) { + this.disable(); + } + }, + + _keydown: function( event ) { + var options = this.options, + keyCode = $.ui.keyCode; + + switch ( event.keyCode ) { + case keyCode.UP: + this._repeat( null, 1, event ); + return true; + case keyCode.DOWN: + this._repeat( null, -1, event ); + return true; + case keyCode.PAGE_UP: + this._repeat( null, options.page, event ); + return true; + case keyCode.PAGE_DOWN: + this._repeat( null, -options.page, event ); + return true; + } + + return false; + }, + + _uiSpinnerHtml: function() { + return ""; + }, + + _buttonHtml: function() { + return "" + + "" + + "" + + "" + + "" + + "" + + ""; + }, + + _start: function( event ) { + if ( !this.spinning && this._trigger( "start", event ) === false ) { + return false; + } + + if ( !this.counter ) { + this.counter = 1; + } + this.spinning = true; + return true; + }, + + _repeat: function( i, steps, event ) { + i = i || 500; + + clearTimeout( this.timer ); + this.timer = this._delay(function() { + this._repeat( 40, steps, event ); + }, i ); + + this._spin( steps * this.options.step, event ); + }, + + _spin: function( step, event ) { + var value = this.value() || 0; + + if ( !this.counter ) { + this.counter = 1; + } + + value = this._adjustValue( value + step * this._increment( this.counter ) ); + + if ( !this.spinning || this._trigger( "spin", event, { value: value } ) !== false) { + this._value( value ); + this.counter++; + } + }, + + _increment: function( i ) { + var incremental = this.options.incremental; + + if ( incremental ) { + return $.isFunction( incremental ) ? + incremental( i ) : + Math.floor( i*i*i/50000 - i*i/500 + 17*i/200 + 1 ); + } + + return 1; + }, + + _precision: function() { + var precision = this._precisionOf( this.options.step ); + if ( this.options.min !== null ) { + precision = Math.max( precision, this._precisionOf( this.options.min ) ); + } + return precision; + }, + + _precisionOf: function( num ) { + var str = num.toString(), + decimal = str.indexOf( "." ); + return decimal === -1 ? 0 : str.length - decimal - 1; + }, + + _adjustValue: function( value ) { + var base, aboveMin, + options = this.options; + + // make sure we're at a valid step + // - find out where we are relative to the base (min or 0) + base = options.min !== null ? options.min : 0; + aboveMin = value - base; + // - round to the nearest step + aboveMin = Math.round(aboveMin / options.step) * options.step; + // - rounding is based on 0, so adjust back to our base + value = base + aboveMin; + + // fix precision from bad JS floating point math + value = parseFloat( value.toFixed( this._precision() ) ); + + // clamp the value + if ( options.max !== null && value > options.max) { + return options.max; + } + if ( options.min !== null && value < options.min ) { + return options.min; + } + + return value; + }, + + _stop: function( event ) { + if ( !this.spinning ) { + return; + } + + clearTimeout( this.timer ); + clearTimeout( this.mousewheelTimer ); + this.counter = 0; + this.spinning = false; + this._trigger( "stop", event ); + }, + + _setOption: function( key, value ) { + if ( key === "culture" || key === "numberFormat" ) { + var prevValue = this._parse( this.element.val() ); + this.options[ key ] = value; + this.element.val( this._format( prevValue ) ); + return; + } + + if ( key === "max" || key === "min" || key === "step" ) { + if ( typeof value === "string" ) { + value = this._parse( value ); + } + } + + this._super( key, value ); + + if ( key === "disabled" ) { + if ( value ) { + this.element.prop( "disabled", true ); + this.buttons.button( "disable" ); + } else { + this.element.prop( "disabled", false ); + this.buttons.button( "enable" ); + } + } + }, + + _setOptions: modifier(function( options ) { + this._super( options ); + this._value( this.element.val() ); + }), + + _parse: function( val ) { + if ( typeof val === "string" && val !== "" ) { + val = window.Globalize && this.options.numberFormat ? + Globalize.parseFloat( val, 10, this.options.culture ) : +val; + } + return val === "" || isNaN( val ) ? null : val; + }, + + _format: function( value ) { + if ( value === "" ) { + return ""; + } + return window.Globalize && this.options.numberFormat ? + Globalize.format( value, this.options.numberFormat, this.options.culture ) : + value; + }, + + _refresh: function() { + this.element.attr({ + "aria-valuemin": this.options.min, + "aria-valuemax": this.options.max, + // TODO: what should we do with values that can't be parsed? + "aria-valuenow": this._parse( this.element.val() ) + }); + }, + + // update the value without triggering change + _value: function( value, allowAny ) { + var parsed; + if ( value !== "" ) { + parsed = this._parse( value ); + if ( parsed !== null ) { + if ( !allowAny ) { + parsed = this._adjustValue( parsed ); + } + value = this._format( parsed ); + } + } + this.element.val( value ); + this._refresh(); + }, + + _destroy: function() { + this.element + .removeClass( "ui-spinner-input" ) + .prop( "disabled", false ) + .removeAttr( "autocomplete" ) + .removeAttr( "role" ) + .removeAttr( "aria-valuemin" ) + .removeAttr( "aria-valuemax" ) + .removeAttr( "aria-valuenow" ); + this.uiSpinner.replaceWith( this.element ); + }, + + stepUp: modifier(function( steps ) { + this._stepUp( steps ); + }), + _stepUp: function( steps ) { + this._spin( (steps || 1) * this.options.step ); + }, + + stepDown: modifier(function( steps ) { + this._stepDown( steps ); + }), + _stepDown: function( steps ) { + this._spin( (steps || 1) * -this.options.step ); + }, + + pageUp: modifier(function( pages ) { + this._stepUp( (pages || 1) * this.options.page ); + }), + + pageDown: modifier(function( pages ) { + this._stepDown( (pages || 1) * this.options.page ); + }), + + value: function( newVal ) { + if ( !arguments.length ) { + return this._parse( this.element.val() ); + } + modifier( this._value ).call( this, newVal ); + }, + + widget: function() { + return this.uiSpinner; + } +}); + +}( jQuery ) ); +(function( $, undefined ) { + +var tabId = 0, + rhash = /#.*$/; + +function getNextTabId() { + return ++tabId; +} + +function isLocal( anchor ) { + return anchor.hash.length > 1 && + anchor.href.replace( rhash, "" ) === + location.href.replace( rhash, "" ) + // support: Safari 5.1 + // Safari 5.1 doesn't encode spaces in window.location + // but it does encode spaces from anchors (#8777) + .replace( /\s/g, "%20" ); +} + +$.widget( "ui.tabs", { + version: "1.9.2", + delay: 300, + options: { + active: null, + collapsible: false, + event: "click", + heightStyle: "content", + hide: null, + show: null, + + // callbacks + activate: null, + beforeActivate: null, + beforeLoad: null, + load: null + }, + + _create: function() { + var that = this, + options = this.options, + active = options.active, + locationHash = location.hash.substring( 1 ); + + this.running = false; + + this.element + .addClass( "ui-tabs ui-widget ui-widget-content ui-corner-all" ) + .toggleClass( "ui-tabs-collapsible", options.collapsible ) + // Prevent users from focusing disabled tabs via click + .delegate( ".ui-tabs-nav > li", "mousedown" + this.eventNamespace, function( event ) { + if ( $( this ).is( ".ui-state-disabled" ) ) { + event.preventDefault(); + } + }) + // support: IE <9 + // Preventing the default action in mousedown doesn't prevent IE + // from focusing the element, so if the anchor gets focused, blur. + // We don't have to worry about focusing the previously focused + // element since clicking on a non-focusable element should focus + // the body anyway. + .delegate( ".ui-tabs-anchor", "focus" + this.eventNamespace, function() { + if ( $( this ).closest( "li" ).is( ".ui-state-disabled" ) ) { + this.blur(); + } + }); + + this._processTabs(); + + if ( active === null ) { + // check the fragment identifier in the URL + if ( locationHash ) { + this.tabs.each(function( i, tab ) { + if ( $( tab ).attr( "aria-controls" ) === locationHash ) { + active = i; + return false; + } + }); + } + + // check for a tab marked active via a class + if ( active === null ) { + active = this.tabs.index( this.tabs.filter( ".ui-tabs-active" ) ); + } + + // no active tab, set to false + if ( active === null || active === -1 ) { + active = this.tabs.length ? 0 : false; + } + } + + // handle numbers: negative, out of range + if ( active !== false ) { + active = this.tabs.index( this.tabs.eq( active ) ); + if ( active === -1 ) { + active = options.collapsible ? false : 0; + } + } + options.active = active; + + // don't allow collapsible: false and active: false + if ( !options.collapsible && options.active === false && this.anchors.length ) { + options.active = 0; + } + + // Take disabling tabs via class attribute from HTML + // into account and update option properly. + if ( $.isArray( options.disabled ) ) { + options.disabled = $.unique( options.disabled.concat( + $.map( this.tabs.filter( ".ui-state-disabled" ), function( li ) { + return that.tabs.index( li ); + }) + ) ).sort(); + } + + // check for length avoids error when initializing empty list + if ( this.options.active !== false && this.anchors.length ) { + this.active = this._findActive( this.options.active ); + } else { + this.active = $(); + } + + this._refresh(); + + if ( this.active.length ) { + this.load( options.active ); + } + }, + + _getCreateEventData: function() { + return { + tab: this.active, + panel: !this.active.length ? $() : this._getPanelForTab( this.active ) + }; + }, + + _tabKeydown: function( event ) { + var focusedTab = $( this.document[0].activeElement ).closest( "li" ), + selectedIndex = this.tabs.index( focusedTab ), + goingForward = true; + + if ( this._handlePageNav( event ) ) { + return; + } + + switch ( event.keyCode ) { + case $.ui.keyCode.RIGHT: + case $.ui.keyCode.DOWN: + selectedIndex++; + break; + case $.ui.keyCode.UP: + case $.ui.keyCode.LEFT: + goingForward = false; + selectedIndex--; + break; + case $.ui.keyCode.END: + selectedIndex = this.anchors.length - 1; + break; + case $.ui.keyCode.HOME: + selectedIndex = 0; + break; + case $.ui.keyCode.SPACE: + // Activate only, no collapsing + event.preventDefault(); + clearTimeout( this.activating ); + this._activate( selectedIndex ); + return; + case $.ui.keyCode.ENTER: + // Toggle (cancel delayed activation, allow collapsing) + event.preventDefault(); + clearTimeout( this.activating ); + // Determine if we should collapse or activate + this._activate( selectedIndex === this.options.active ? false : selectedIndex ); + return; + default: + return; + } + + // Focus the appropriate tab, based on which key was pressed + event.preventDefault(); + clearTimeout( this.activating ); + selectedIndex = this._focusNextTab( selectedIndex, goingForward ); + + // Navigating with control key will prevent automatic activation + if ( !event.ctrlKey ) { + // Update aria-selected immediately so that AT think the tab is already selected. + // Otherwise AT may confuse the user by stating that they need to activate the tab, + // but the tab will already be activated by the time the announcement finishes. + focusedTab.attr( "aria-selected", "false" ); + this.tabs.eq( selectedIndex ).attr( "aria-selected", "true" ); + + this.activating = this._delay(function() { + this.option( "active", selectedIndex ); + }, this.delay ); + } + }, + + _panelKeydown: function( event ) { + if ( this._handlePageNav( event ) ) { + return; + } + + // Ctrl+up moves focus to the current tab + if ( event.ctrlKey && event.keyCode === $.ui.keyCode.UP ) { + event.preventDefault(); + this.active.focus(); + } + }, + + // Alt+page up/down moves focus to the previous/next tab (and activates) + _handlePageNav: function( event ) { + if ( event.altKey && event.keyCode === $.ui.keyCode.PAGE_UP ) { + this._activate( this._focusNextTab( this.options.active - 1, false ) ); + return true; + } + if ( event.altKey && event.keyCode === $.ui.keyCode.PAGE_DOWN ) { + this._activate( this._focusNextTab( this.options.active + 1, true ) ); + return true; + } + }, + + _findNextTab: function( index, goingForward ) { + var lastTabIndex = this.tabs.length - 1; + + function constrain() { + if ( index > lastTabIndex ) { + index = 0; + } + if ( index < 0 ) { + index = lastTabIndex; + } + return index; + } + + while ( $.inArray( constrain(), this.options.disabled ) !== -1 ) { + index = goingForward ? index + 1 : index - 1; + } + + return index; + }, + + _focusNextTab: function( index, goingForward ) { + index = this._findNextTab( index, goingForward ); + this.tabs.eq( index ).focus(); + return index; + }, + + _setOption: function( key, value ) { + if ( key === "active" ) { + // _activate() will handle invalid values and update this.options + this._activate( value ); + return; + } + + if ( key === "disabled" ) { + // don't use the widget factory's disabled handling + this._setupDisabled( value ); + return; + } + + this._super( key, value); + + if ( key === "collapsible" ) { + this.element.toggleClass( "ui-tabs-collapsible", value ); + // Setting collapsible: false while collapsed; open first panel + if ( !value && this.options.active === false ) { + this._activate( 0 ); + } + } + + if ( key === "event" ) { + this._setupEvents( value ); + } + + if ( key === "heightStyle" ) { + this._setupHeightStyle( value ); + } + }, + + _tabId: function( tab ) { + return tab.attr( "aria-controls" ) || "ui-tabs-" + getNextTabId(); + }, + + _sanitizeSelector: function( hash ) { + return hash ? hash.replace( /[!"$%&'()*+,.\/:;<=>?@\[\]\^`{|}~]/g, "\\$&" ) : ""; + }, + + refresh: function() { + var options = this.options, + lis = this.tablist.children( ":has(a[href])" ); + + // get disabled tabs from class attribute from HTML + // this will get converted to a boolean if needed in _refresh() + options.disabled = $.map( lis.filter( ".ui-state-disabled" ), function( tab ) { + return lis.index( tab ); + }); + + this._processTabs(); + + // was collapsed or no tabs + if ( options.active === false || !this.anchors.length ) { + options.active = false; + this.active = $(); + // was active, but active tab is gone + } else if ( this.active.length && !$.contains( this.tablist[ 0 ], this.active[ 0 ] ) ) { + // all remaining tabs are disabled + if ( this.tabs.length === options.disabled.length ) { + options.active = false; + this.active = $(); + // activate previous tab + } else { + this._activate( this._findNextTab( Math.max( 0, options.active - 1 ), false ) ); + } + // was active, active tab still exists + } else { + // make sure active index is correct + options.active = this.tabs.index( this.active ); + } + + this._refresh(); + }, + + _refresh: function() { + this._setupDisabled( this.options.disabled ); + this._setupEvents( this.options.event ); + this._setupHeightStyle( this.options.heightStyle ); + + this.tabs.not( this.active ).attr({ + "aria-selected": "false", + tabIndex: -1 + }); + this.panels.not( this._getPanelForTab( this.active ) ) + .hide() + .attr({ + "aria-expanded": "false", + "aria-hidden": "true" + }); + + // Make sure one tab is in the tab order + if ( !this.active.length ) { + this.tabs.eq( 0 ).attr( "tabIndex", 0 ); + } else { + this.active + .addClass( "ui-tabs-active ui-state-active" ) + .attr({ + "aria-selected": "true", + tabIndex: 0 + }); + this._getPanelForTab( this.active ) + .show() + .attr({ + "aria-expanded": "true", + "aria-hidden": "false" + }); + } + }, + + _processTabs: function() { + var that = this; + + this.tablist = this._getList() + .addClass( "ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all" ) + .attr( "role", "tablist" ); + + this.tabs = this.tablist.find( "> li:has(a[href])" ) + .addClass( "ui-state-default ui-corner-top" ) + .attr({ + role: "tab", + tabIndex: -1 + }); + + this.anchors = this.tabs.map(function() { + return $( "a", this )[ 0 ]; + }) + .addClass( "ui-tabs-anchor" ) + .attr({ + role: "presentation", + tabIndex: -1 + }); + + this.panels = $(); + + this.anchors.each(function( i, anchor ) { + var selector, panel, panelId, + anchorId = $( anchor ).uniqueId().attr( "id" ), + tab = $( anchor ).closest( "li" ), + originalAriaControls = tab.attr( "aria-controls" ); + + // inline tab + if ( isLocal( anchor ) ) { + selector = anchor.hash; + panel = that.element.find( that._sanitizeSelector( selector ) ); + // remote tab + } else { + panelId = that._tabId( tab ); + selector = "#" + panelId; + panel = that.element.find( selector ); + if ( !panel.length ) { + panel = that._createPanel( panelId ); + panel.insertAfter( that.panels[ i - 1 ] || that.tablist ); + } + panel.attr( "aria-live", "polite" ); + } + + if ( panel.length) { + that.panels = that.panels.add( panel ); + } + if ( originalAriaControls ) { + tab.data( "ui-tabs-aria-controls", originalAriaControls ); + } + tab.attr({ + "aria-controls": selector.substring( 1 ), + "aria-labelledby": anchorId + }); + panel.attr( "aria-labelledby", anchorId ); + }); + + this.panels + .addClass( "ui-tabs-panel ui-widget-content ui-corner-bottom" ) + .attr( "role", "tabpanel" ); + }, + + // allow overriding how to find the list for rare usage scenarios (#7715) + _getList: function() { + return this.element.find( "ol,ul" ).eq( 0 ); + }, + + _createPanel: function( id ) { + return $( "
      " ) + .attr( "id", id ) + .addClass( "ui-tabs-panel ui-widget-content ui-corner-bottom" ) + .data( "ui-tabs-destroy", true ); + }, + + _setupDisabled: function( disabled ) { + if ( $.isArray( disabled ) ) { + if ( !disabled.length ) { + disabled = false; + } else if ( disabled.length === this.anchors.length ) { + disabled = true; + } + } + + // disable tabs + for ( var i = 0, li; ( li = this.tabs[ i ] ); i++ ) { + if ( disabled === true || $.inArray( i, disabled ) !== -1 ) { + $( li ) + .addClass( "ui-state-disabled" ) + .attr( "aria-disabled", "true" ); + } else { + $( li ) + .removeClass( "ui-state-disabled" ) + .removeAttr( "aria-disabled" ); + } + } + + this.options.disabled = disabled; + }, + + _setupEvents: function( event ) { + var events = { + click: function( event ) { + event.preventDefault(); + } + }; + if ( event ) { + $.each( event.split(" "), function( index, eventName ) { + events[ eventName ] = "_eventHandler"; + }); + } + + this._off( this.anchors.add( this.tabs ).add( this.panels ) ); + this._on( this.anchors, events ); + this._on( this.tabs, { keydown: "_tabKeydown" } ); + this._on( this.panels, { keydown: "_panelKeydown" } ); + + this._focusable( this.tabs ); + this._hoverable( this.tabs ); + }, + + _setupHeightStyle: function( heightStyle ) { + var maxHeight, overflow, + parent = this.element.parent(); + + if ( heightStyle === "fill" ) { + // IE 6 treats height like minHeight, so we need to turn off overflow + // in order to get a reliable height + // we use the minHeight support test because we assume that only + // browsers that don't support minHeight will treat height as minHeight + if ( !$.support.minHeight ) { + overflow = parent.css( "overflow" ); + parent.css( "overflow", "hidden"); + } + maxHeight = parent.height(); + this.element.siblings( ":visible" ).each(function() { + var elem = $( this ), + position = elem.css( "position" ); + + if ( position === "absolute" || position === "fixed" ) { + return; + } + maxHeight -= elem.outerHeight( true ); + }); + if ( overflow ) { + parent.css( "overflow", overflow ); + } + + this.element.children().not( this.panels ).each(function() { + maxHeight -= $( this ).outerHeight( true ); + }); + + this.panels.each(function() { + $( this ).height( Math.max( 0, maxHeight - + $( this ).innerHeight() + $( this ).height() ) ); + }) + .css( "overflow", "auto" ); + } else if ( heightStyle === "auto" ) { + maxHeight = 0; + this.panels.each(function() { + maxHeight = Math.max( maxHeight, $( this ).height( "" ).height() ); + }).height( maxHeight ); + } + }, + + _eventHandler: function( event ) { + var options = this.options, + active = this.active, + anchor = $( event.currentTarget ), + tab = anchor.closest( "li" ), + clickedIsActive = tab[ 0 ] === active[ 0 ], + collapsing = clickedIsActive && options.collapsible, + toShow = collapsing ? $() : this._getPanelForTab( tab ), + toHide = !active.length ? $() : this._getPanelForTab( active ), + eventData = { + oldTab: active, + oldPanel: toHide, + newTab: collapsing ? $() : tab, + newPanel: toShow + }; + + event.preventDefault(); + + if ( tab.hasClass( "ui-state-disabled" ) || + // tab is already loading + tab.hasClass( "ui-tabs-loading" ) || + // can't switch durning an animation + this.running || + // click on active header, but not collapsible + ( clickedIsActive && !options.collapsible ) || + // allow canceling activation + ( this._trigger( "beforeActivate", event, eventData ) === false ) ) { + return; + } + + options.active = collapsing ? false : this.tabs.index( tab ); + + this.active = clickedIsActive ? $() : tab; + if ( this.xhr ) { + this.xhr.abort(); + } + + if ( !toHide.length && !toShow.length ) { + $.error( "jQuery UI Tabs: Mismatching fragment identifier." ); + } + + if ( toShow.length ) { + this.load( this.tabs.index( tab ), event ); + } + this._toggle( event, eventData ); + }, + + // handles show/hide for selecting tabs + _toggle: function( event, eventData ) { + var that = this, + toShow = eventData.newPanel, + toHide = eventData.oldPanel; + + this.running = true; + + function complete() { + that.running = false; + that._trigger( "activate", event, eventData ); + } + + function show() { + eventData.newTab.closest( "li" ).addClass( "ui-tabs-active ui-state-active" ); + + if ( toShow.length && that.options.show ) { + that._show( toShow, that.options.show, complete ); + } else { + toShow.show(); + complete(); + } + } + + // start out by hiding, then showing, then completing + if ( toHide.length && this.options.hide ) { + this._hide( toHide, this.options.hide, function() { + eventData.oldTab.closest( "li" ).removeClass( "ui-tabs-active ui-state-active" ); + show(); + }); + } else { + eventData.oldTab.closest( "li" ).removeClass( "ui-tabs-active ui-state-active" ); + toHide.hide(); + show(); + } + + toHide.attr({ + "aria-expanded": "false", + "aria-hidden": "true" + }); + eventData.oldTab.attr( "aria-selected", "false" ); + // If we're switching tabs, remove the old tab from the tab order. + // If we're opening from collapsed state, remove the previous tab from the tab order. + // If we're collapsing, then keep the collapsing tab in the tab order. + if ( toShow.length && toHide.length ) { + eventData.oldTab.attr( "tabIndex", -1 ); + } else if ( toShow.length ) { + this.tabs.filter(function() { + return $( this ).attr( "tabIndex" ) === 0; + }) + .attr( "tabIndex", -1 ); + } + + toShow.attr({ + "aria-expanded": "true", + "aria-hidden": "false" + }); + eventData.newTab.attr({ + "aria-selected": "true", + tabIndex: 0 + }); + }, + + _activate: function( index ) { + var anchor, + active = this._findActive( index ); + + // trying to activate the already active panel + if ( active[ 0 ] === this.active[ 0 ] ) { + return; + } + + // trying to collapse, simulate a click on the current active header + if ( !active.length ) { + active = this.active; + } + + anchor = active.find( ".ui-tabs-anchor" )[ 0 ]; + this._eventHandler({ + target: anchor, + currentTarget: anchor, + preventDefault: $.noop + }); + }, + + _findActive: function( index ) { + return index === false ? $() : this.tabs.eq( index ); + }, + + _getIndex: function( index ) { + // meta-function to give users option to provide a href string instead of a numerical index. + if ( typeof index === "string" ) { + index = this.anchors.index( this.anchors.filter( "[href$='" + index + "']" ) ); + } + + return index; + }, + + _destroy: function() { + if ( this.xhr ) { + this.xhr.abort(); + } + + this.element.removeClass( "ui-tabs ui-widget ui-widget-content ui-corner-all ui-tabs-collapsible" ); + + this.tablist + .removeClass( "ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all" ) + .removeAttr( "role" ); + + this.anchors + .removeClass( "ui-tabs-anchor" ) + .removeAttr( "role" ) + .removeAttr( "tabIndex" ) + .removeData( "href.tabs" ) + .removeData( "load.tabs" ) + .removeUniqueId(); + + this.tabs.add( this.panels ).each(function() { + if ( $.data( this, "ui-tabs-destroy" ) ) { + $( this ).remove(); + } else { + $( this ) + .removeClass( "ui-state-default ui-state-active ui-state-disabled " + + "ui-corner-top ui-corner-bottom ui-widget-content ui-tabs-active ui-tabs-panel" ) + .removeAttr( "tabIndex" ) + .removeAttr( "aria-live" ) + .removeAttr( "aria-busy" ) + .removeAttr( "aria-selected" ) + .removeAttr( "aria-labelledby" ) + .removeAttr( "aria-hidden" ) + .removeAttr( "aria-expanded" ) + .removeAttr( "role" ); + } + }); + + this.tabs.each(function() { + var li = $( this ), + prev = li.data( "ui-tabs-aria-controls" ); + if ( prev ) { + li.attr( "aria-controls", prev ); + } else { + li.removeAttr( "aria-controls" ); + } + }); + + this.panels.show(); + + if ( this.options.heightStyle !== "content" ) { + this.panels.css( "height", "" ); + } + }, + + enable: function( index ) { + var disabled = this.options.disabled; + if ( disabled === false ) { + return; + } + + if ( index === undefined ) { + disabled = false; + } else { + index = this._getIndex( index ); + if ( $.isArray( disabled ) ) { + disabled = $.map( disabled, function( num ) { + return num !== index ? num : null; + }); + } else { + disabled = $.map( this.tabs, function( li, num ) { + return num !== index ? num : null; + }); + } + } + this._setupDisabled( disabled ); + }, + + disable: function( index ) { + var disabled = this.options.disabled; + if ( disabled === true ) { + return; + } + + if ( index === undefined ) { + disabled = true; + } else { + index = this._getIndex( index ); + if ( $.inArray( index, disabled ) !== -1 ) { + return; + } + if ( $.isArray( disabled ) ) { + disabled = $.merge( [ index ], disabled ).sort(); + } else { + disabled = [ index ]; + } + } + this._setupDisabled( disabled ); + }, + + load: function( index, event ) { + index = this._getIndex( index ); + var that = this, + tab = this.tabs.eq( index ), + anchor = tab.find( ".ui-tabs-anchor" ), + panel = this._getPanelForTab( tab ), + eventData = { + tab: tab, + panel: panel + }; + + // not remote + if ( isLocal( anchor[ 0 ] ) ) { + return; + } + + this.xhr = $.ajax( this._ajaxSettings( anchor, event, eventData ) ); + + // support: jQuery <1.8 + // jQuery <1.8 returns false if the request is canceled in beforeSend, + // but as of 1.8, $.ajax() always returns a jqXHR object. + if ( this.xhr && this.xhr.statusText !== "canceled" ) { + tab.addClass( "ui-tabs-loading" ); + panel.attr( "aria-busy", "true" ); + + this.xhr + .success(function( response ) { + // support: jQuery <1.8 + // http://bugs.jquery.com/ticket/11778 + setTimeout(function() { + panel.html( response ); + that._trigger( "load", event, eventData ); + }, 1 ); + }) + .complete(function( jqXHR, status ) { + // support: jQuery <1.8 + // http://bugs.jquery.com/ticket/11778 + setTimeout(function() { + if ( status === "abort" ) { + that.panels.stop( false, true ); + } + + tab.removeClass( "ui-tabs-loading" ); + panel.removeAttr( "aria-busy" ); + + if ( jqXHR === that.xhr ) { + delete that.xhr; + } + }, 1 ); + }); + } + }, + + // TODO: Remove this function in 1.10 when ajaxOptions is removed + _ajaxSettings: function( anchor, event, eventData ) { + var that = this; + return { + url: anchor.attr( "href" ), + beforeSend: function( jqXHR, settings ) { + return that._trigger( "beforeLoad", event, + $.extend( { jqXHR : jqXHR, ajaxSettings: settings }, eventData ) ); + } + }; + }, + + _getPanelForTab: function( tab ) { + var id = $( tab ).attr( "aria-controls" ); + return this.element.find( this._sanitizeSelector( "#" + id ) ); + } +}); + +// DEPRECATED +if ( $.uiBackCompat !== false ) { + + // helper method for a lot of the back compat extensions + $.ui.tabs.prototype._ui = function( tab, panel ) { + return { + tab: tab, + panel: panel, + index: this.anchors.index( tab ) + }; + }; + + // url method + $.widget( "ui.tabs", $.ui.tabs, { + url: function( index, url ) { + this.anchors.eq( index ).attr( "href", url ); + } + }); + + // TODO: Remove _ajaxSettings() method when removing this extension + // ajaxOptions and cache options + $.widget( "ui.tabs", $.ui.tabs, { + options: { + ajaxOptions: null, + cache: false + }, + + _create: function() { + this._super(); + + var that = this; + + this._on({ tabsbeforeload: function( event, ui ) { + // tab is already cached + if ( $.data( ui.tab[ 0 ], "cache.tabs" ) ) { + event.preventDefault(); + return; + } + + ui.jqXHR.success(function() { + if ( that.options.cache ) { + $.data( ui.tab[ 0 ], "cache.tabs", true ); + } + }); + }}); + }, + + _ajaxSettings: function( anchor, event, ui ) { + var ajaxOptions = this.options.ajaxOptions; + return $.extend( {}, ajaxOptions, { + error: function( xhr, status ) { + try { + // Passing index avoid a race condition when this method is + // called after the user has selected another tab. + // Pass the anchor that initiated this request allows + // loadError to manipulate the tab content panel via $(a.hash) + ajaxOptions.error( + xhr, status, ui.tab.closest( "li" ).index(), ui.tab[ 0 ] ); + } + catch ( error ) {} + } + }, this._superApply( arguments ) ); + }, + + _setOption: function( key, value ) { + // reset cache if switching from cached to not cached + if ( key === "cache" && value === false ) { + this.anchors.removeData( "cache.tabs" ); + } + this._super( key, value ); + }, + + _destroy: function() { + this.anchors.removeData( "cache.tabs" ); + this._super(); + }, + + url: function( index ){ + this.anchors.eq( index ).removeData( "cache.tabs" ); + this._superApply( arguments ); + } + }); + + // abort method + $.widget( "ui.tabs", $.ui.tabs, { + abort: function() { + if ( this.xhr ) { + this.xhr.abort(); + } + } + }); + + // spinner + $.widget( "ui.tabs", $.ui.tabs, { + options: { + spinner: "Loading…" + }, + _create: function() { + this._super(); + this._on({ + tabsbeforeload: function( event, ui ) { + // Don't react to nested tabs or tabs that don't use a spinner + if ( event.target !== this.element[ 0 ] || + !this.options.spinner ) { + return; + } + + var span = ui.tab.find( "span" ), + html = span.html(); + span.html( this.options.spinner ); + ui.jqXHR.complete(function() { + span.html( html ); + }); + } + }); + } + }); + + // enable/disable events + $.widget( "ui.tabs", $.ui.tabs, { + options: { + enable: null, + disable: null + }, + + enable: function( index ) { + var options = this.options, + trigger; + + if ( index && options.disabled === true || + ( $.isArray( options.disabled ) && $.inArray( index, options.disabled ) !== -1 ) ) { + trigger = true; + } + + this._superApply( arguments ); + + if ( trigger ) { + this._trigger( "enable", null, this._ui( this.anchors[ index ], this.panels[ index ] ) ); + } + }, + + disable: function( index ) { + var options = this.options, + trigger; + + if ( index && options.disabled === false || + ( $.isArray( options.disabled ) && $.inArray( index, options.disabled ) === -1 ) ) { + trigger = true; + } + + this._superApply( arguments ); + + if ( trigger ) { + this._trigger( "disable", null, this._ui( this.anchors[ index ], this.panels[ index ] ) ); + } + } + }); + + // add/remove methods and events + $.widget( "ui.tabs", $.ui.tabs, { + options: { + add: null, + remove: null, + tabTemplate: "
    • #{label}
    • " + }, + + add: function( url, label, index ) { + if ( index === undefined ) { + index = this.anchors.length; + } + + var doInsertAfter, panel, + options = this.options, + li = $( options.tabTemplate + .replace( /#\{href\}/g, url ) + .replace( /#\{label\}/g, label ) ), + id = !url.indexOf( "#" ) ? + url.replace( "#", "" ) : + this._tabId( li ); + + li.addClass( "ui-state-default ui-corner-top" ).data( "ui-tabs-destroy", true ); + li.attr( "aria-controls", id ); + + doInsertAfter = index >= this.tabs.length; + + // try to find an existing element before creating a new one + panel = this.element.find( "#" + id ); + if ( !panel.length ) { + panel = this._createPanel( id ); + if ( doInsertAfter ) { + if ( index > 0 ) { + panel.insertAfter( this.panels.eq( -1 ) ); + } else { + panel.appendTo( this.element ); + } + } else { + panel.insertBefore( this.panels[ index ] ); + } + } + panel.addClass( "ui-tabs-panel ui-widget-content ui-corner-bottom" ).hide(); + + if ( doInsertAfter ) { + li.appendTo( this.tablist ); + } else { + li.insertBefore( this.tabs[ index ] ); + } + + options.disabled = $.map( options.disabled, function( n ) { + return n >= index ? ++n : n; + }); + + this.refresh(); + if ( this.tabs.length === 1 && options.active === false ) { + this.option( "active", 0 ); + } + + this._trigger( "add", null, this._ui( this.anchors[ index ], this.panels[ index ] ) ); + return this; + }, + + remove: function( index ) { + index = this._getIndex( index ); + var options = this.options, + tab = this.tabs.eq( index ).remove(), + panel = this._getPanelForTab( tab ).remove(); + + // If selected tab was removed focus tab to the right or + // in case the last tab was removed the tab to the left. + // We check for more than 2 tabs, because if there are only 2, + // then when we remove this tab, there will only be one tab left + // so we don't need to detect which tab to activate. + if ( tab.hasClass( "ui-tabs-active" ) && this.anchors.length > 2 ) { + this._activate( index + ( index + 1 < this.anchors.length ? 1 : -1 ) ); + } + + options.disabled = $.map( + $.grep( options.disabled, function( n ) { + return n !== index; + }), + function( n ) { + return n >= index ? --n : n; + }); + + this.refresh(); + + this._trigger( "remove", null, this._ui( tab.find( "a" )[ 0 ], panel[ 0 ] ) ); + return this; + } + }); + + // length method + $.widget( "ui.tabs", $.ui.tabs, { + length: function() { + return this.anchors.length; + } + }); + + // panel ids (idPrefix option + title attribute) + $.widget( "ui.tabs", $.ui.tabs, { + options: { + idPrefix: "ui-tabs-" + }, + + _tabId: function( tab ) { + var a = tab.is( "li" ) ? tab.find( "a[href]" ) : tab; + a = a[0]; + return $( a ).closest( "li" ).attr( "aria-controls" ) || + a.title && a.title.replace( /\s/g, "_" ).replace( /[^\w\u00c0-\uFFFF\-]/g, "" ) || + this.options.idPrefix + getNextTabId(); + } + }); + + // _createPanel method + $.widget( "ui.tabs", $.ui.tabs, { + options: { + panelTemplate: "
      " + }, + + _createPanel: function( id ) { + return $( this.options.panelTemplate ) + .attr( "id", id ) + .addClass( "ui-tabs-panel ui-widget-content ui-corner-bottom" ) + .data( "ui-tabs-destroy", true ); + } + }); + + // selected option + $.widget( "ui.tabs", $.ui.tabs, { + _create: function() { + var options = this.options; + if ( options.active === null && options.selected !== undefined ) { + options.active = options.selected === -1 ? false : options.selected; + } + this._super(); + options.selected = options.active; + if ( options.selected === false ) { + options.selected = -1; + } + }, + + _setOption: function( key, value ) { + if ( key !== "selected" ) { + return this._super( key, value ); + } + + var options = this.options; + this._super( "active", value === -1 ? false : value ); + options.selected = options.active; + if ( options.selected === false ) { + options.selected = -1; + } + }, + + _eventHandler: function() { + this._superApply( arguments ); + this.options.selected = this.options.active; + if ( this.options.selected === false ) { + this.options.selected = -1; + } + } + }); + + // show and select event + $.widget( "ui.tabs", $.ui.tabs, { + options: { + show: null, + select: null + }, + _create: function() { + this._super(); + if ( this.options.active !== false ) { + this._trigger( "show", null, this._ui( + this.active.find( ".ui-tabs-anchor" )[ 0 ], + this._getPanelForTab( this.active )[ 0 ] ) ); + } + }, + _trigger: function( type, event, data ) { + var tab, panel, + ret = this._superApply( arguments ); + + if ( !ret ) { + return false; + } + + if ( type === "beforeActivate" ) { + tab = data.newTab.length ? data.newTab : data.oldTab; + panel = data.newPanel.length ? data.newPanel : data.oldPanel; + ret = this._super( "select", event, { + tab: tab.find( ".ui-tabs-anchor" )[ 0], + panel: panel[ 0 ], + index: tab.closest( "li" ).index() + }); + } else if ( type === "activate" && data.newTab.length ) { + ret = this._super( "show", event, { + tab: data.newTab.find( ".ui-tabs-anchor" )[ 0 ], + panel: data.newPanel[ 0 ], + index: data.newTab.closest( "li" ).index() + }); + } + return ret; + } + }); + + // select method + $.widget( "ui.tabs", $.ui.tabs, { + select: function( index ) { + index = this._getIndex( index ); + if ( index === -1 ) { + if ( this.options.collapsible && this.options.selected !== -1 ) { + index = this.options.selected; + } else { + return; + } + } + this.anchors.eq( index ).trigger( this.options.event + this.eventNamespace ); + } + }); + + // cookie option + (function() { + + var listId = 0; + + $.widget( "ui.tabs", $.ui.tabs, { + options: { + cookie: null // e.g. { expires: 7, path: '/', domain: 'jquery.com', secure: true } + }, + _create: function() { + var options = this.options, + active; + if ( options.active == null && options.cookie ) { + active = parseInt( this._cookie(), 10 ); + if ( active === -1 ) { + active = false; + } + options.active = active; + } + this._super(); + }, + _cookie: function( active ) { + var cookie = [ this.cookie || + ( this.cookie = this.options.cookie.name || "ui-tabs-" + (++listId) ) ]; + if ( arguments.length ) { + cookie.push( active === false ? -1 : active ); + cookie.push( this.options.cookie ); + } + return $.cookie.apply( null, cookie ); + }, + _refresh: function() { + this._super(); + if ( this.options.cookie ) { + this._cookie( this.options.active, this.options.cookie ); + } + }, + _eventHandler: function() { + this._superApply( arguments ); + if ( this.options.cookie ) { + this._cookie( this.options.active, this.options.cookie ); + } + }, + _destroy: function() { + this._super(); + if ( this.options.cookie ) { + this._cookie( null, this.options.cookie ); + } + } + }); + + })(); + + // load event + $.widget( "ui.tabs", $.ui.tabs, { + _trigger: function( type, event, data ) { + var _data = $.extend( {}, data ); + if ( type === "load" ) { + _data.panel = _data.panel[ 0 ]; + _data.tab = _data.tab.find( ".ui-tabs-anchor" )[ 0 ]; + } + return this._super( type, event, _data ); + } + }); + + // fx option + // The new animation options (show, hide) conflict with the old show callback. + // The old fx option wins over show/hide anyway (always favor back-compat). + // If a user wants to use the new animation API, they must give up the old API. + $.widget( "ui.tabs", $.ui.tabs, { + options: { + fx: null // e.g. { height: "toggle", opacity: "toggle", duration: 200 } + }, + + _getFx: function() { + var hide, show, + fx = this.options.fx; + + if ( fx ) { + if ( $.isArray( fx ) ) { + hide = fx[ 0 ]; + show = fx[ 1 ]; + } else { + hide = show = fx; + } + } + + return fx ? { show: show, hide: hide } : null; + }, + + _toggle: function( event, eventData ) { + var that = this, + toShow = eventData.newPanel, + toHide = eventData.oldPanel, + fx = this._getFx(); + + if ( !fx ) { + return this._super( event, eventData ); + } + + that.running = true; + + function complete() { + that.running = false; + that._trigger( "activate", event, eventData ); + } + + function show() { + eventData.newTab.closest( "li" ).addClass( "ui-tabs-active ui-state-active" ); + + if ( toShow.length && fx.show ) { + toShow + .animate( fx.show, fx.show.duration, function() { + complete(); + }); + } else { + toShow.show(); + complete(); + } + } + + // start out by hiding, then showing, then completing + if ( toHide.length && fx.hide ) { + toHide.animate( fx.hide, fx.hide.duration, function() { + eventData.oldTab.closest( "li" ).removeClass( "ui-tabs-active ui-state-active" ); + show(); + }); + } else { + eventData.oldTab.closest( "li" ).removeClass( "ui-tabs-active ui-state-active" ); + toHide.hide(); + show(); + } + } + }); +} + +})( jQuery ); +(function( $ ) { + +var increments = 0; + +function addDescribedBy( elem, id ) { + var describedby = (elem.attr( "aria-describedby" ) || "").split( /\s+/ ); + describedby.push( id ); + elem + .data( "ui-tooltip-id", id ) + .attr( "aria-describedby", $.trim( describedby.join( " " ) ) ); +} + +function removeDescribedBy( elem ) { + var id = elem.data( "ui-tooltip-id" ), + describedby = (elem.attr( "aria-describedby" ) || "").split( /\s+/ ), + index = $.inArray( id, describedby ); + if ( index !== -1 ) { + describedby.splice( index, 1 ); + } + + elem.removeData( "ui-tooltip-id" ); + describedby = $.trim( describedby.join( " " ) ); + if ( describedby ) { + elem.attr( "aria-describedby", describedby ); + } else { + elem.removeAttr( "aria-describedby" ); + } +} + +$.widget( "ui.tooltip", { + version: "1.9.2", + options: { + content: function() { + return $( this ).attr( "title" ); + }, + hide: true, + // Disabled elements have inconsistent behavior across browsers (#8661) + items: "[title]:not([disabled])", + position: { + my: "left top+15", + at: "left bottom", + collision: "flipfit flip" + }, + show: true, + tooltipClass: null, + track: false, + + // callbacks + close: null, + open: null + }, + + _create: function() { + this._on({ + mouseover: "open", + focusin: "open" + }); + + // IDs of generated tooltips, needed for destroy + this.tooltips = {}; + // IDs of parent tooltips where we removed the title attribute + this.parents = {}; + + if ( this.options.disabled ) { + this._disable(); + } + }, + + _setOption: function( key, value ) { + var that = this; + + if ( key === "disabled" ) { + this[ value ? "_disable" : "_enable" ](); + this.options[ key ] = value; + // disable element style changes + return; + } + + this._super( key, value ); + + if ( key === "content" ) { + $.each( this.tooltips, function( id, element ) { + that._updateContent( element ); + }); + } + }, + + _disable: function() { + var that = this; + + // close open tooltips + $.each( this.tooltips, function( id, element ) { + var event = $.Event( "blur" ); + event.target = event.currentTarget = element[0]; + that.close( event, true ); + }); + + // remove title attributes to prevent native tooltips + this.element.find( this.options.items ).andSelf().each(function() { + var element = $( this ); + if ( element.is( "[title]" ) ) { + element + .data( "ui-tooltip-title", element.attr( "title" ) ) + .attr( "title", "" ); + } + }); + }, + + _enable: function() { + // restore title attributes + this.element.find( this.options.items ).andSelf().each(function() { + var element = $( this ); + if ( element.data( "ui-tooltip-title" ) ) { + element.attr( "title", element.data( "ui-tooltip-title" ) ); + } + }); + }, + + open: function( event ) { + var that = this, + target = $( event ? event.target : this.element ) + // we need closest here due to mouseover bubbling, + // but always pointing at the same event target + .closest( this.options.items ); + + // No element to show a tooltip for or the tooltip is already open + if ( !target.length || target.data( "ui-tooltip-id" ) ) { + return; + } + + if ( target.attr( "title" ) ) { + target.data( "ui-tooltip-title", target.attr( "title" ) ); + } + + target.data( "ui-tooltip-open", true ); + + // kill parent tooltips, custom or native, for hover + if ( event && event.type === "mouseover" ) { + target.parents().each(function() { + var parent = $( this ), + blurEvent; + if ( parent.data( "ui-tooltip-open" ) ) { + blurEvent = $.Event( "blur" ); + blurEvent.target = blurEvent.currentTarget = this; + that.close( blurEvent, true ); + } + if ( parent.attr( "title" ) ) { + parent.uniqueId(); + that.parents[ this.id ] = { + element: this, + title: parent.attr( "title" ) + }; + parent.attr( "title", "" ); + } + }); + } + + this._updateContent( target, event ); + }, + + _updateContent: function( target, event ) { + var content, + contentOption = this.options.content, + that = this, + eventType = event ? event.type : null; + + if ( typeof contentOption === "string" ) { + return this._open( event, target, contentOption ); + } + + content = contentOption.call( target[0], function( response ) { + // ignore async response if tooltip was closed already + if ( !target.data( "ui-tooltip-open" ) ) { + return; + } + // IE may instantly serve a cached response for ajax requests + // delay this call to _open so the other call to _open runs first + that._delay(function() { + // jQuery creates a special event for focusin when it doesn't + // exist natively. To improve performance, the native event + // object is reused and the type is changed. Therefore, we can't + // rely on the type being correct after the event finished + // bubbling, so we set it back to the previous value. (#8740) + if ( event ) { + event.type = eventType; + } + this._open( event, target, response ); + }); + }); + if ( content ) { + this._open( event, target, content ); + } + }, + + _open: function( event, target, content ) { + var tooltip, events, delayedShow, + positionOption = $.extend( {}, this.options.position ); + + if ( !content ) { + return; + } + + // Content can be updated multiple times. If the tooltip already + // exists, then just update the content and bail. + tooltip = this._find( target ); + if ( tooltip.length ) { + tooltip.find( ".ui-tooltip-content" ).html( content ); + return; + } + + // if we have a title, clear it to prevent the native tooltip + // we have to check first to avoid defining a title if none exists + // (we don't want to cause an element to start matching [title]) + // + // We use removeAttr only for key events, to allow IE to export the correct + // accessible attributes. For mouse events, set to empty string to avoid + // native tooltip showing up (happens only when removing inside mouseover). + if ( target.is( "[title]" ) ) { + if ( event && event.type === "mouseover" ) { + target.attr( "title", "" ); + } else { + target.removeAttr( "title" ); + } + } + + tooltip = this._tooltip( target ); + addDescribedBy( target, tooltip.attr( "id" ) ); + tooltip.find( ".ui-tooltip-content" ).html( content ); + + function position( event ) { + positionOption.of = event; + if ( tooltip.is( ":hidden" ) ) { + return; + } + tooltip.position( positionOption ); + } + if ( this.options.track && event && /^mouse/.test( event.type ) ) { + this._on( this.document, { + mousemove: position + }); + // trigger once to override element-relative positioning + position( event ); + } else { + tooltip.position( $.extend({ + of: target + }, this.options.position ) ); + } + + tooltip.hide(); + + this._show( tooltip, this.options.show ); + // Handle tracking tooltips that are shown with a delay (#8644). As soon + // as the tooltip is visible, position the tooltip using the most recent + // event. + if ( this.options.show && this.options.show.delay ) { + delayedShow = setInterval(function() { + if ( tooltip.is( ":visible" ) ) { + position( positionOption.of ); + clearInterval( delayedShow ); + } + }, $.fx.interval ); + } + + this._trigger( "open", event, { tooltip: tooltip } ); + + events = { + keyup: function( event ) { + if ( event.keyCode === $.ui.keyCode.ESCAPE ) { + var fakeEvent = $.Event(event); + fakeEvent.currentTarget = target[0]; + this.close( fakeEvent, true ); + } + }, + remove: function() { + this._removeTooltip( tooltip ); + } + }; + if ( !event || event.type === "mouseover" ) { + events.mouseleave = "close"; + } + if ( !event || event.type === "focusin" ) { + events.focusout = "close"; + } + this._on( true, target, events ); + }, + + close: function( event ) { + var that = this, + target = $( event ? event.currentTarget : this.element ), + tooltip = this._find( target ); + + // disabling closes the tooltip, so we need to track when we're closing + // to avoid an infinite loop in case the tooltip becomes disabled on close + if ( this.closing ) { + return; + } + + // only set title if we had one before (see comment in _open()) + if ( target.data( "ui-tooltip-title" ) ) { + target.attr( "title", target.data( "ui-tooltip-title" ) ); + } + + removeDescribedBy( target ); + + tooltip.stop( true ); + this._hide( tooltip, this.options.hide, function() { + that._removeTooltip( $( this ) ); + }); + + target.removeData( "ui-tooltip-open" ); + this._off( target, "mouseleave focusout keyup" ); + // Remove 'remove' binding only on delegated targets + if ( target[0] !== this.element[0] ) { + this._off( target, "remove" ); + } + this._off( this.document, "mousemove" ); + + if ( event && event.type === "mouseleave" ) { + $.each( this.parents, function( id, parent ) { + $( parent.element ).attr( "title", parent.title ); + delete that.parents[ id ]; + }); + } + + this.closing = true; + this._trigger( "close", event, { tooltip: tooltip } ); + this.closing = false; + }, + + _tooltip: function( element ) { + var id = "ui-tooltip-" + increments++, + tooltip = $( "
      " ) + .attr({ + id: id, + role: "tooltip" + }) + .addClass( "ui-tooltip ui-widget ui-corner-all ui-widget-content " + + ( this.options.tooltipClass || "" ) ); + $( "
      " ) + .addClass( "ui-tooltip-content" ) + .appendTo( tooltip ); + tooltip.appendTo( this.document[0].body ); + if ( $.fn.bgiframe ) { + tooltip.bgiframe(); + } + this.tooltips[ id ] = element; + return tooltip; + }, + + _find: function( target ) { + var id = target.data( "ui-tooltip-id" ); + return id ? $( "#" + id ) : $(); + }, + + _removeTooltip: function( tooltip ) { + tooltip.remove(); + delete this.tooltips[ tooltip.attr( "id" ) ]; + }, + + _destroy: function() { + var that = this; + + // close open tooltips + $.each( this.tooltips, function( id, element ) { + // Delegate to close method to handle common cleanup + var event = $.Event( "blur" ); + event.target = event.currentTarget = element[0]; + that.close( event, true ); + + // Remove immediately; destroying an open tooltip doesn't use the + // hide animation + $( "#" + id ).remove(); + + // Restore the title + if ( element.data( "ui-tooltip-title" ) ) { + element.attr( "title", element.data( "ui-tooltip-title" ) ); + element.removeData( "ui-tooltip-title" ); + } + }); + } +}); + +}( jQuery ) ); \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/layout/jquery.layout-latest.js b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/layout/jquery.layout-latest.js new file mode 100644 index 000000000..434724d9c --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/layout/jquery.layout-latest.js @@ -0,0 +1,6086 @@ +/** + * @preserve + * jquery.layout 1.4.3 + * $Date: 2015/03/13 22:37:04 $ + * $Rev: 1.0403 $ + * + * Copyright (c) 2014 Kevin Dalman (http://jquery-dev.com) + * Based on work by Fabrizio Balliano (http://www.fabrizioballiano.net) + * + * Dual licensed under the GPL (http://www.gnu.org/licenses/gpl.html) + * and MIT (http://www.opensource.org/licenses/mit-license.php) licenses. + * + * SEE: http://layout.jquery-dev.com/LICENSE.txt + * + * Changelog: http://layout.jquery-dev.com/changelog.cfm + * + * Docs: http://layout.jquery-dev.com/documentation.html + * Tips: http://layout.jquery-dev.com/tips.html + * Help: http://groups.google.com/group/jquery-ui-layout + */ + +/* JavaDoc Info: http://code.google.com/closure/compiler/docs/js-for-compiler.html + * {!Object} non-nullable type (never NULL) + * {?string} nullable type (sometimes NULL) - default for {Object} + * {number=} optional parameter + * {*} ALL types + */ +/* TODO for jQ 2.0 + * change .andSelf() to .addBack() + * check $.fn.disableSelection - this is in jQuery UI 1.9.x + */ + +// NOTE: For best readability, view with a fixed-width font and tabs equal to 4-chars + +;(function ($) { + +// alias Math methods - used a lot! +var min = Math.min +, max = Math.max +, round = Math.floor + +, isStr = function (v) { return $.type(v) === "string"; } + + /** + * @param {!Object} Instance + * @param {Array.} a_fn + */ +, runPluginCallbacks = function (Instance, a_fn) { + if ($.isArray(a_fn)) + for (var i=0, c=a_fn.length; i
      ').appendTo("body") + , d = { width: $c.outerWidth - $c[0].clientWidth, height: 100 - $c[0].clientHeight }; + $c.remove(); + window.scrollbarWidth = d.width; + window.scrollbarHeight = d.height; + return dim.match(/^(width|height)$/) ? d[dim] : d; + } + + +, disableTextSelection: function () { + var $d = $(document) + , s = 'textSelectionDisabled' + , x = 'textSelectionInitialized' + ; + if ($.fn.disableSelection) { + if (!$d.data(x)) // document hasn't been initialized yet + $d.on('mouseup', $.layout.enableTextSelection ).data(x, true); + if (!$d.data(s)) + $d.disableSelection().data(s, true); + } + } +, enableTextSelection: function () { + var $d = $(document) + , s = 'textSelectionDisabled'; + if ($.fn.enableSelection && $d.data(s)) + $d.enableSelection().data(s, false); + } + + + /** + * Returns hash container 'display' and 'visibility' + * + * @see $.swap() - swaps CSS, runs callback, resets CSS + * @param {!Object} $E jQuery element + * @param {boolean=} [force=false] Run even if display != none + * @return {!Object} Returns current style props, if applicable + */ +, showInvisibly: function ($E, force) { + if ($E && $E.length && (force || $E.css("display") === "none")) { // only if not *already hidden* + var s = $E[0].style + // save ONLY the 'style' props because that is what we must restore + , CSS = { display: s.display || '', visibility: s.visibility || '' }; + // show element 'invisibly' so can be measured + $E.css({ display: "block", visibility: "hidden" }); + return CSS; + } + return {}; + } + + /** + * Returns data for setting size of an element (container or a pane). + * + * @see _create(), onWindowResize() for container, plus others for pane + * @return JSON Returns a hash of all dimensions: top, bottom, left, right, outerWidth, innerHeight, etc + */ +, getElementDimensions: function ($E, inset) { + var + // dimensions hash - start with current data IF passed + d = { css: {}, inset: {} } + , x = d.css // CSS hash + , i = { bottom: 0 } // TEMP insets (bottom = complier hack) + , N = $.layout.cssNum + , R = Math.round + , off = $E.offset() + , b, p, ei // TEMP border, padding + ; + d.offsetLeft = off.left; + d.offsetTop = off.top; + + if (!inset) inset = {}; // simplify logic below + + $.each("Left,Right,Top,Bottom".split(","), function (idx, e) { // e = edge + b = x["border" + e] = $.layout.borderWidth($E, e); + p = x["padding"+ e] = $.layout.cssNum($E, "padding"+e); + ei = e.toLowerCase(); + d.inset[ei] = inset[ei] >= 0 ? inset[ei] : p; // any missing insetX value = paddingX + i[ei] = d.inset[ei] + b; // total offset of content from outer side + }); + + x.width = R($E.width()); + x.height = R($E.height()); + x.top = N($E,"top",true); + x.bottom = N($E,"bottom",true); + x.left = N($E,"left",true); + x.right = N($E,"right",true); + + d.outerWidth = R($E.outerWidth()); + d.outerHeight = R($E.outerHeight()); + // calc the TRUE inner-dimensions, even in quirks-mode! + d.innerWidth = max(0, d.outerWidth - i.left - i.right); + d.innerHeight = max(0, d.outerHeight - i.top - i.bottom); + // layoutWidth/Height is used in calcs for manual resizing + // layoutW/H only differs from innerW/H when in quirks-mode - then is like outerW/H + d.layoutWidth = R($E.innerWidth()); + d.layoutHeight = R($E.innerHeight()); + + //if ($E.prop('tagName') === 'BODY') { debugData( d, $E.prop('tagName') ); } // DEBUG + + //d.visible = $E.is(":visible");// && x.width > 0 && x.height > 0; + + return d; + } + +, getElementStyles: function ($E, list) { + var + CSS = {} + , style = $E[0].style + , props = list.split(",") + , sides = "Top,Bottom,Left,Right".split(",") + , attrs = "Color,Style,Width".split(",") + , p, s, a, i, j, k + ; + for (i=0; i < props.length; i++) { + p = props[i]; + if (p.match(/(border|padding|margin)$/)) + for (j=0; j < 4; j++) { + s = sides[j]; + if (p === "border") + for (k=0; k < 3; k++) { + a = attrs[k]; + CSS[p+s+a] = style[p+s+a]; + } + else + CSS[p+s] = style[p+s]; + } + else + CSS[p] = style[p]; + }; + return CSS + } + + /** + * Return the innerWidth for the current browser/doctype + * + * @see initPanes(), sizeMidPanes(), initHandles(), sizeHandles() + * @param {Array.} $E Must pass a jQuery object - first element is processed + * @param {number=} outerWidth (optional) Can pass a width, allowing calculations BEFORE element is resized + * @return {number} Returns the innerWidth of the elem by subtracting padding and borders + */ +, cssWidth: function ($E, outerWidth) { + // a 'calculated' outerHeight can be passed so borders and/or padding are removed if needed + if (outerWidth <= 0) return 0; + + var lb = $.layout.browser + , bs = !lb.boxModel ? "border-box" : lb.boxSizing ? $E.css("boxSizing") : "content-box" + , b = $.layout.borderWidth + , n = $.layout.cssNum + , W = outerWidth + ; + // strip border and/or padding from outerWidth to get CSS Width + if (bs !== "border-box") + W -= (b($E, "Left") + b($E, "Right")); + if (bs === "content-box") + W -= (n($E, "paddingLeft") + n($E, "paddingRight")); + return max(0,W); + } + + /** + * Return the innerHeight for the current browser/doctype + * + * @see initPanes(), sizeMidPanes(), initHandles(), sizeHandles() + * @param {Array.} $E Must pass a jQuery object - first element is processed + * @param {number=} outerHeight (optional) Can pass a width, allowing calculations BEFORE element is resized + * @return {number} Returns the innerHeight of the elem by subtracting padding and borders + */ +, cssHeight: function ($E, outerHeight) { + // a 'calculated' outerHeight can be passed so borders and/or padding are removed if needed + if (outerHeight <= 0) return 0; + + var lb = $.layout.browser + , bs = !lb.boxModel ? "border-box" : lb.boxSizing ? $E.css("boxSizing") : "content-box" + , b = $.layout.borderWidth + , n = $.layout.cssNum + , H = outerHeight + ; + // strip border and/or padding from outerHeight to get CSS Height + if (bs !== "border-box") + H -= (b($E, "Top") + b($E, "Bottom")); + if (bs === "content-box") + H -= (n($E, "paddingTop") + n($E, "paddingBottom")); + return max(0,H); + } + + /** + * Returns the 'current CSS numeric value' for a CSS property - 0 if property does not exist + * + * @see Called by many methods + * @param {Array.} $E Must pass a jQuery object - first element is processed + * @param {string} prop The name of the CSS property, eg: top, width, etc. + * @param {boolean=} [allowAuto=false] true = return 'auto' if that is value; false = return 0 + * @return {(string|number)} Usually used to get an integer value for position (top, left) or size (height, width) + */ +, cssNum: function ($E, prop, allowAuto) { + if (!$E.jquery) $E = $($E); + var CSS = $.layout.showInvisibly($E) + , p = $.css($E[0], prop, true) + , v = allowAuto && p=="auto" ? p : Math.round(parseFloat(p) || 0); + $E.css( CSS ); // RESET + return v; + } + +, borderWidth: function (el, side) { + if (el.jquery) el = el[0]; + var b = "border"+ side.substr(0,1).toUpperCase() + side.substr(1); // left => Left + return $.css(el, b+"Style", true) === "none" ? 0 : Math.round(parseFloat($.css(el, b+"Width", true)) || 0); + } + + /** + * Mouse-tracking utility - FUTURE REFERENCE + * + * init: if (!window.mouse) { + * window.mouse = { x: 0, y: 0 }; + * $(document).mousemove( $.layout.trackMouse ); + * } + * + * @param {Object} evt + * +, trackMouse: function (evt) { + window.mouse = { x: evt.clientX, y: evt.clientY }; + } + */ + + /** + * SUBROUTINE for preventPrematureSlideClose option + * + * @param {Object} evt + * @param {Object=} el + */ +, isMouseOverElem: function (evt, el) { + var + $E = $(el || this) + , d = $E.offset() + , T = d.top + , L = d.left + , R = L + $E.outerWidth() + , B = T + $E.outerHeight() + , x = evt.pageX // evt.clientX ? + , y = evt.pageY // evt.clientY ? + ; + // if X & Y are < 0, probably means is over an open SELECT + return ($.layout.browser.msie && x < 0 && y < 0) || ((x >= L && x <= R) && (y >= T && y <= B)); + } + + /** + * Message/Logging Utility + * + * @example $.layout.msg("My message"); // log text + * @example $.layout.msg("My message", true); // alert text + * @example $.layout.msg({ foo: "bar" }, "Title"); // log hash-data, with custom title + * @example $.layout.msg({ foo: "bar" }, true, "Title", { sort: false }); -OR- + * @example $.layout.msg({ foo: "bar" }, "Title", { sort: false, display: true }); // alert hash-data + * + * @param {(Object|string)} info String message OR Hash/Array + * @param {(Boolean|string|Object)=} [popup=false] True means alert-box - can be skipped + * @param {(Object|string)=} [debugTitle=""] Title for Hash data - can be skipped + * @param {Object=} [debugOpts] Extra options for debug output + */ +, msg: function (info, popup, debugTitle, debugOpts) { + if ($.isPlainObject(info) && window.debugData) { + if (typeof popup === "string") { + debugOpts = debugTitle; + debugTitle = popup; + } + else if (typeof debugTitle === "object") { + debugOpts = debugTitle; + debugTitle = null; + } + var t = debugTitle || "log( )" + , o = $.extend({ sort: false, returnHTML: false, display: false }, debugOpts); + if (popup === true || o.display) + debugData( info, t, o ); + else if (window.console) + console.log(debugData( info, t, o )); + } + else if (popup) + alert(info); + else if (window.console) + console.log(info); + else { + var id = "#layoutLogger" + , $l = $(id); + if (!$l.length) + $l = createLog(); + $l.children("ul").append('
    • '+ info.replace(/\/g,">") +'
    • '); + } + + function createLog () { + var pos = $.support.fixedPosition ? 'fixed' : 'absolute' + , $e = $('
      ' + + '
      ' + + 'XLayout console.log
      ' + + '
        ' + + '
        ' + ).appendTo("body"); + $e.css('left', $(window).width() - $e.outerWidth() - 5) + if ($.ui.draggable) $e.draggable({ handle: ':first-child' }); + return $e; + }; + } + +}; + + +/* + * $.layout.browser REPLACES removed $.browser, with extra data + * Parsing code here adapted from jQuery 1.8 $.browse + */ +(function(){ + var u = navigator.userAgent.toLowerCase() + , m = /(chrome)[ \/]([\w.]+)/.exec( u ) + || /(webkit)[ \/]([\w.]+)/.exec( u ) + || /(opera)(?:.*version|)[ \/]([\w.]+)/.exec( u ) + || /(msie) ([\w.]+)/.exec( u ) + || u.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec( u ) + || [] + , b = m[1] || "" + , v = m[2] || 0 + , ie = b === "msie" + , cm = document.compatMode + , $s = $.support + , bs = $s.boxSizing !== undefined ? $s.boxSizing : $s.boxSizingReliable + , bm = !ie || !cm || cm === "CSS1Compat" || $s.boxModel || false + , lb = $.layout.browser = { + version: v + , safari: b === "webkit" // webkit (NOT chrome) = safari + , webkit: b === "chrome" // chrome = webkit + , msie: ie + , isIE6: ie && v == 6 + // ONLY IE reverts to old box-model - Note that compatMode was deprecated as of IE8 + , boxModel: bm + , boxSizing: !!(typeof bs === "function" ? bs() : bs) + }; + ; + if (b) lb[b] = true; // set CURRENT browser + /* OLD versions of jQuery only set $.support.boxModel after page is loaded + * so if this is IE, use support.boxModel to test for quirks-mode (ONLY IE changes boxModel) */ + if (!bm && !cm) $(function(){ lb.boxModel = $s.boxModel; }); +})(); + + +// DEFAULT OPTIONS +$.layout.defaults = { +/* + * LAYOUT & LAYOUT-CONTAINER OPTIONS + * - none of these options are applicable to individual panes + */ + name: "" // Not required, but useful for buttons and used for the state-cookie +, containerClass: "ui-layout-container" // layout-container element +, inset: null // custom container-inset values (override padding) +, scrollToBookmarkOnLoad: true // after creating a layout, scroll to bookmark in URL (.../page.htm#myBookmark) +, resizeWithWindow: true // bind thisLayout.resizeAll() to the window.resize event +, resizeWithWindowDelay: 200 // delay calling resizeAll because makes window resizing very jerky +, resizeWithWindowMaxDelay: 0 // 0 = none - force resize every XX ms while window is being resized +, maskPanesEarly: false // true = create pane-masks on resizer.mouseDown instead of waiting for resizer.dragstart +, onresizeall_start: null // CALLBACK when resizeAll() STARTS - NOT pane-specific +, onresizeall_end: null // CALLBACK when resizeAll() ENDS - NOT pane-specific +, onload_start: null // CALLBACK when Layout inits - after options initialized, but before elements +, onload_end: null // CALLBACK when Layout inits - after EVERYTHING has been initialized +, onunload_start: null // CALLBACK when Layout is destroyed OR onWindowUnload +, onunload_end: null // CALLBACK when Layout is destroyed OR onWindowUnload +, initPanes: true // false = DO NOT initialize the panes onLoad - will init later +, showErrorMessages: true // enables fatal error messages to warn developers of common errors +, showDebugMessages: false // display console-and-alert debug msgs - IF this Layout version _has_ debugging code! +// Changing this zIndex value will cause other zIndex values to automatically change +, zIndex: null // the PANE zIndex - resizers and masks will be +1 +// DO NOT CHANGE the zIndex values below unless you clearly understand their relationships +, zIndexes: { // set _default_ z-index values here... + pane_normal: 0 // normal z-index for panes + , content_mask: 1 // applied to overlays used to mask content INSIDE panes during resizing + , resizer_normal: 2 // normal z-index for resizer-bars + , pane_sliding: 100 // applied to *BOTH* the pane and its resizer when a pane is 'slid open' + , pane_animate: 1000 // applied to the pane when being animated - not applied to the resizer + , resizer_drag: 10000 // applied to the CLONED resizer-bar when being 'dragged' + } +, errors: { + pane: "pane" // description of "layout pane element" - used only in error messages + , selector: "selector" // description of "jQuery-selector" - used only in error messages + , addButtonError: "Error Adding Button\nInvalid " + , containerMissing: "UI Layout Initialization Error\nThe specified layout-container does not exist." + , centerPaneMissing: "UI Layout Initialization Error\nThe center-pane element does not exist.\nThe center-pane is a required element." + , noContainerHeight: "UI Layout Initialization Warning\nThe layout-container \"CONTAINER\" has no height.\nTherefore the layout is 0-height and hence 'invisible'!" + , callbackError: "UI Layout Callback Error\nThe EVENT callback is not a valid function." + } +/* + * PANE DEFAULT SETTINGS + * - settings under the 'panes' key become the default settings for *all panes* + * - ALL pane-options can also be set specifically for each panes, which will override these 'default values' + */ +, panes: { // default options for 'all panes' - will be overridden by 'per-pane settings' + applyDemoStyles: false // NOTE: renamed from applyDefaultStyles for clarity + , closable: true // pane can open & close + , resizable: true // when open, pane can be resized + , slidable: true // when closed, pane can 'slide open' over other panes - closes on mouse-out + , initClosed: false // true = init pane as 'closed' + , initHidden: false // true = init pane as 'hidden' - no resizer-bar/spacing + // SELECTORS + //, paneSelector: "" // MUST be pane-specific - jQuery selector for pane + , contentSelector: ".ui-layout-content" // INNER div/element to auto-size so only it scrolls, not the entire pane! + , contentIgnoreSelector: ".ui-layout-ignore" // element(s) to 'ignore' when measuring 'content' + , findNestedContent: false // true = $P.find(contentSelector), false = $P.children(contentSelector) + // GENERIC ROOT-CLASSES - for auto-generated classNames + , paneClass: "ui-layout-pane" // Layout Pane + , resizerClass: "ui-layout-resizer" // Resizer Bar + , togglerClass: "ui-layout-toggler" // Toggler Button + , buttonClass: "ui-layout-button" // CUSTOM Buttons - eg: '[ui-layout-button]-toggle/-open/-close/-pin' + // ELEMENT SIZE & SPACING + //, size: 100 // MUST be pane-specific -initial size of pane + , minSize: 0 // when manually resizing a pane + , maxSize: 0 // ditto, 0 = no limit + , spacing_open: 6 // space between pane and adjacent panes - when pane is 'open' + , spacing_closed: 6 // ditto - when pane is 'closed' + , togglerLength_open: 50 // Length = WIDTH of toggler button on north/south sides - HEIGHT on east/west sides + , togglerLength_closed: 50 // 100% OR -1 means 'full height/width of resizer bar' - 0 means 'hidden' + , togglerAlign_open: "center" // top/left, bottom/right, center, OR... + , togglerAlign_closed: "center" // 1 => nn = offset from top/left, -1 => -nn == offset from bottom/right + , togglerContent_open: "" // text or HTML to put INSIDE the toggler + , togglerContent_closed: "" // ditto + // RESIZING OPTIONS + , resizerDblClickToggle: true // + , autoResize: true // IF size is 'auto' or a percentage, then recalc 'pixel size' whenever the layout resizes + , autoReopen: true // IF a pane was auto-closed due to noRoom, reopen it when there is room? False = leave it closed + , resizerDragOpacity: 1 // option for ui.draggable + //, resizerCursor: "" // MUST be pane-specific - cursor when over resizer-bar + , maskContents: false // true = add DIV-mask over-or-inside this pane so can 'drag' over IFRAMES + , maskObjects: false // true = add IFRAME-mask over-or-inside this pane to cover objects/applets - content-mask will overlay this mask + , maskZindex: null // will override zIndexes.content_mask if specified - not applicable to iframe-panes + , resizingGrid: false // grid size that the resizers will snap-to during resizing, eg: [20,20] + , livePaneResizing: false // true = LIVE Resizing as resizer is dragged + , liveContentResizing: false // true = re-measure header/footer heights as resizer is dragged + , liveResizingTolerance: 1 // how many px change before pane resizes, to control performance + // SLIDING OPTIONS + , sliderCursor: "pointer" // cursor when resizer-bar will trigger 'sliding' + , slideTrigger_open: "click" // click, dblclick, mouseenter + , slideTrigger_close: "mouseleave"// click, mouseleave + , slideDelay_open: 300 // applies only for mouseenter event - 0 = instant open + , slideDelay_close: 300 // applies only for mouseleave event (300ms is the minimum!) + , hideTogglerOnSlide: false // when pane is slid-open, should the toggler show? + , preventQuickSlideClose: $.layout.browser.webkit // Chrome triggers slideClosed as it is opening + , preventPrematureSlideClose: false // handle incorrect mouseleave trigger, like when over a SELECT-list in IE + // PANE-SPECIFIC TIPS & MESSAGES + , tips: { + Open: "Open" // eg: "Open Pane" + , Close: "Close" + , Resize: "Resize" + , Slide: "Slide Open" + , Pin: "Pin" + , Unpin: "Un-Pin" + , noRoomToOpen: "Not enough room to show this panel." // alert if user tries to open a pane that cannot + , minSizeWarning: "Panel has reached its minimum size" // displays in browser statusbar + , maxSizeWarning: "Panel has reached its maximum size" // ditto + } + // HOT-KEYS & MISC + , showOverflowOnHover: false // will bind allowOverflow() utility to pane.onMouseOver + , enableCursorHotkey: true // enabled 'cursor' hotkeys + //, customHotkey: "" // MUST be pane-specific - EITHER a charCode OR a character + , customHotkeyModifier: "SHIFT" // either 'SHIFT', 'CTRL' or 'CTRL+SHIFT' - NOT 'ALT' + // PANE ANIMATION + // NOTE: fxSss_open, fxSss_close & fxSss_size options (eg: fxName_open) are auto-generated if not passed + , fxName: "slide" // ('none' or blank), slide, drop, scale -- only relevant to 'open' & 'close', NOT 'size' + , fxSpeed: null // slow, normal, fast, 200, nnn - if passed, will OVERRIDE fxSettings.duration + , fxSettings: {} // can be passed, eg: { easing: "easeOutBounce", duration: 1500 } + , fxOpacityFix: true // tries to fix opacity in IE to restore anti-aliasing after animation + , animatePaneSizing: false // true = animate resizing after dragging resizer-bar OR sizePane() is called + /* NOTE: Action-specific FX options are auto-generated from the options above if not specifically set: + fxName_open: "slide" // 'Open' pane animation + fnName_close: "slide" // 'Close' pane animation + fxName_size: "slide" // 'Size' pane animation - when animatePaneSizing = true + fxSpeed_open: null + fxSpeed_close: null + fxSpeed_size: null + fxSettings_open: {} + fxSettings_close: {} + fxSettings_size: {} + */ + // CHILD/NESTED LAYOUTS + , children: null // Layout-options for nested/child layout - even {} is valid as options + , containerSelector: '' // if child is NOT 'directly nested', a selector to find it/them (can have more than one child layout!) + , initChildren: true // true = child layout will be created as soon as _this_ layout completes initialization + , destroyChildren: true // true = destroy child-layout if this pane is destroyed + , resizeChildren: true // true = trigger child-layout.resizeAll() when this pane is resized + // EVENT TRIGGERING + , triggerEventsOnLoad: false // true = trigger onopen OR onclose callbacks when layout initializes + , triggerEventsDuringLiveResize: true // true = trigger onresize callback REPEATEDLY if livePaneResizing==true + // PANE CALLBACKS + , onshow_start: null // CALLBACK when pane STARTS to Show - BEFORE onopen/onhide_start + , onshow_end: null // CALLBACK when pane ENDS being Shown - AFTER onopen/onhide_end + , onhide_start: null // CALLBACK when pane STARTS to Close - BEFORE onclose_start + , onhide_end: null // CALLBACK when pane ENDS being Closed - AFTER onclose_end + , onopen_start: null // CALLBACK when pane STARTS to Open + , onopen_end: null // CALLBACK when pane ENDS being Opened + , onclose_start: null // CALLBACK when pane STARTS to Close + , onclose_end: null // CALLBACK when pane ENDS being Closed + , onresize_start: null // CALLBACK when pane STARTS being Resized ***FOR ANY REASON*** + , onresize_end: null // CALLBACK when pane ENDS being Resized ***FOR ANY REASON*** + , onsizecontent_start: null // CALLBACK when sizing of content-element STARTS + , onsizecontent_end: null // CALLBACK when sizing of content-element ENDS + , onswap_start: null // CALLBACK when pane STARTS to Swap + , onswap_end: null // CALLBACK when pane ENDS being Swapped + , ondrag_start: null // CALLBACK when pane STARTS being ***MANUALLY*** Resized + , ondrag_end: null // CALLBACK when pane ENDS being ***MANUALLY*** Resized + } +/* + * PANE-SPECIFIC SETTINGS + * - options listed below MUST be specified per-pane - they CANNOT be set under 'panes' + * - all options under the 'panes' key can also be set specifically for any pane + * - most options under the 'panes' key apply only to 'border-panes' - NOT the the center-pane + */ +, north: { + paneSelector: ".ui-layout-north" + , size: "auto" // eg: "auto", "30%", .30, 200 + , resizerCursor: "n-resize" // custom = url(myCursor.cur) + , customHotkey: "" // EITHER a charCode (43) OR a character ("o") + } +, south: { + paneSelector: ".ui-layout-south" + , size: "50%"//"auto" + , resizerCursor: "s-resize" + , customHotkey: "" + , initClosed: true + } +, east: { + paneSelector: ".ui-layout-east" + , size: "5%"//200 + , resizerCursor: "e-resize" + , customHotkey: "" + } +, west: { + paneSelector: ".ui-layout-west" + , size: "70%" //200 + , resizerCursor: "w-resize" + , customHotkey: "" + , initClosed: true + } +, center: { + paneSelector: ".ui-layout-center" + , size: "30%"//"auto" + , minWidth: 0 + , minHeight: 0 + } +}; + +$.layout.optionsMap = { + // layout/global options - NOT pane-options + layout: ("name,instanceKey,stateManagement,effects,inset,zIndexes,errors," + + "zIndex,scrollToBookmarkOnLoad,showErrorMessages,maskPanesEarly," + + "outset,resizeWithWindow,resizeWithWindowDelay,resizeWithWindowMaxDelay," + + "onresizeall,onresizeall_start,onresizeall_end,onload,onload_start,onload_end,onunload,onunload_start,onunload_end").split(",") +// borderPanes: [ ALL options that are NOT specified as 'layout' ] + // default.panes options that apply to the center-pane (most options apply _only_ to border-panes) +, center: ("paneClass,contentSelector,contentIgnoreSelector,findNestedContent,applyDemoStyles,triggerEventsOnLoad," + + "showOverflowOnHover,maskContents,maskObjects,liveContentResizing," + + "containerSelector,children,initChildren,resizeChildren,destroyChildren," + + "onresize,onresize_start,onresize_end,onsizecontent,onsizecontent_start,onsizecontent_end").split(",") + // options that MUST be specifically set 'per-pane' - CANNOT set in the panes (defaults) key +, noDefault: ("paneSelector,resizerCursor,customHotkey").split(",") +}; + +/** + * Processes options passed in converts flat-format data into subkey (JSON) format + * In flat-format, subkeys are _currently_ separated with 2 underscores, like north__optName + * Plugins may also call this method so they can transform their own data + * + * @param {!Object} hash Data/options passed by user - may be a single level or nested levels + * @param {boolean=} [addKeys=false] Should the primary layout.options keys be added if they do not exist? + * @return {Object} Returns hash of minWidth & minHeight + */ +$.layout.transformData = function (hash, addKeys) { + var json = addKeys ? { panes: {}, center: {} } : {} // init return object + , branch, optKey, keys, key, val, i, c; + + if (typeof hash !== "object") return json; // no options passed + + // convert all 'flat-keys' to 'sub-key' format + for (optKey in hash) { + branch = json; + val = hash[ optKey ]; + keys = optKey.split("__"); // eg: west__size or north__fxSettings__duration + c = keys.length - 1; + // convert underscore-delimited to subkeys + for (i=0; i <= c; i++) { + key = keys[i]; + if (i === c) { // last key = value + if ($.isPlainObject( val )) + branch[key] = $.layout.transformData( val ); // RECURSE + else + branch[key] = val; + } + else { + if (!branch[key]) + branch[key] = {}; // create the subkey + // recurse to sub-key for next loop - if not done + branch = branch[key]; + } + } + } + return json; +}; + +// INTERNAL CONFIG DATA - DO NOT CHANGE THIS! +$.layout.backwardCompatibility = { + // data used by renameOldOptions() + map: { + // OLD Option Name: NEW Option Name + applyDefaultStyles: "applyDemoStyles" + // CHILD/NESTED LAYOUTS + , childOptions: "children" + , initChildLayout: "initChildren" + , destroyChildLayout: "destroyChildren" + , resizeChildLayout: "resizeChildren" + , resizeNestedLayout: "resizeChildren" + // MISC Options + , resizeWhileDragging: "livePaneResizing" + , resizeContentWhileDragging: "liveContentResizing" + , triggerEventsWhileDragging: "triggerEventsDuringLiveResize" + , maskIframesOnResize: "maskContents" + // STATE MANAGEMENT + , useStateCookie: "stateManagement.enabled" + , "cookie.autoLoad": "stateManagement.autoLoad" + , "cookie.autoSave": "stateManagement.autoSave" + , "cookie.keys": "stateManagement.stateKeys" + , "cookie.name": "stateManagement.cookie.name" + , "cookie.domain": "stateManagement.cookie.domain" + , "cookie.path": "stateManagement.cookie.path" + , "cookie.expires": "stateManagement.cookie.expires" + , "cookie.secure": "stateManagement.cookie.secure" + // OLD Language options + , noRoomToOpenTip: "tips.noRoomToOpen" + , togglerTip_open: "tips.Close" // open = Close + , togglerTip_closed: "tips.Open" // closed = Open + , resizerTip: "tips.Resize" + , sliderTip: "tips.Slide" + } + +/** +* @param {Object} opts +*/ +, renameOptions: function (opts) { + var map = $.layout.backwardCompatibility.map + , oldData, newData, value + ; + for (var itemPath in map) { + oldData = getBranch( itemPath ); + value = oldData.branch[ oldData.key ]; + if (value !== undefined) { + newData = getBranch( map[itemPath], true ); + newData.branch[ newData.key ] = value; + delete oldData.branch[ oldData.key ]; + } + } + + /** + * @param {string} path + * @param {boolean=} [create=false] Create path if does not exist + */ + function getBranch (path, create) { + var a = path.split(".") // split keys into array + , c = a.length - 1 + , D = { branch: opts, key: a[c] } // init branch at top & set key (last item) + , i = 0, k, undef; + for (; i 0) { + if (autoHide && $E.data('autoHidden') && $E.innerHeight() > 0) { + $E.show().data('autoHidden', false); + if (!browser.mozilla) // FireFox refreshes iframes - IE does not + // make hidden, then visible to 'refresh' display after animation + $E.css(_c.hidden).css(_c.visible); + } + } + else if (autoHide && !$E.data('autoHidden')) + $E.hide().data('autoHidden', true); + } + + /** + * @param {(string|!Object)} el + * @param {number=} outerHeight + * @param {boolean=} [autoHide=false] + */ +, setOuterHeight = function (el, outerHeight, autoHide) { + var $E = el, h; + if (isStr(el)) $E = $Ps[el]; // west + else if (!el.jquery) $E = $(el); + h = cssH($E, outerHeight); + $E.css({ height: h, visibility: "visible" }); // may have been 'hidden' by sizeContent + if (h > 0 && $E.innerWidth() > 0) { + if (autoHide && $E.data('autoHidden')) { + $E.show().data('autoHidden', false); + if (!browser.mozilla) // FireFox refreshes iframes - IE does not + $E.css(_c.hidden).css(_c.visible); + } + } + else if (autoHide && !$E.data('autoHidden')) + $E.hide().data('autoHidden', true); + } + + + /** + * Converts any 'size' params to a pixel/integer size, if not already + * If 'auto' or a decimal/percentage is passed as 'size', a pixel-size is calculated + * + /** + * @param {string} pane + * @param {(string|number)=} size + * @param {string=} [dir] + * @return {number} + */ +, _parseSize = function (pane, size, dir) { + if (!dir) dir = _c[pane].dir; + + if (isStr(size) && size.match(/%/)) + size = (size === '100%') ? -1 : parseInt(size, 10) / 100; // convert % to decimal + + if (size === 0) + return 0; + else if (size >= 1) + return parseInt(size, 10); + + var o = options, avail = 0; + if (dir=="horz") // north or south or center.minHeight + avail = sC.innerHeight - ($Ps.north ? o.north.spacing_open : 0) - ($Ps.south ? o.south.spacing_open : 0); + else if (dir=="vert") // east or west or center.minWidth + avail = sC.innerWidth - ($Ps.west ? o.west.spacing_open : 0) - ($Ps.east ? o.east.spacing_open : 0); + + if (size === -1) // -1 == 100% + return avail; + else if (size > 0) // percentage, eg: .25 + return round(avail * size); + else if (pane=="center") + return 0; + else { // size < 0 || size=='auto' || size==Missing || size==Invalid + // auto-size the pane + var dim = (dir === "horz" ? "height" : "width") + , $P = $Ps[pane] + , $C = dim === 'height' ? $Cs[pane] : false + , vis = $.layout.showInvisibly($P) // show pane invisibly if hidden + , szP = $P.css(dim) // SAVE current pane size + , szC = $C ? $C.css(dim) : 0 // SAVE current content size + ; + $P.css(dim, "auto"); + if ($C) $C.css(dim, "auto"); + size = (dim === "height") ? $P.outerHeight() : $P.outerWidth(); // MEASURE + $P.css(dim, szP).css(vis); // RESET size & visibility + if ($C) $C.css(dim, szC); + return size; + } + } + + /** + * Calculates current 'size' (outer-width or outer-height) of a border-pane - optionally with 'pane-spacing' added + * + * @param {(string|!Object)} pane + * @param {boolean=} [inclSpace=false] + * @return {number} Returns EITHER Width for east/west panes OR Height for north/south panes + */ +, getPaneSize = function (pane, inclSpace) { + var + $P = $Ps[pane] + , o = options[pane] + , s = state[pane] + , oSp = (inclSpace ? o.spacing_open : 0) + , cSp = (inclSpace ? o.spacing_closed : 0) + ; + if (!$P || s.isHidden) + return 0; + else if (s.isClosed || (s.isSliding && inclSpace)) + return cSp; + else if (_c[pane].dir === "horz") + return $P.outerHeight() + oSp; + else // dir === "vert" + return $P.outerWidth() + oSp; + } + + /** + * Calculate min/max pane dimensions and limits for resizing + * + * @param {string} pane + * @param {boolean=} [slide=false] + */ +, setSizeLimits = function (pane, slide) { + if (!isInitialized()) return; + var + o = options[pane] + , s = state[pane] + , c = _c[pane] + , dir = c.dir + , type = c.sizeType.toLowerCase() + , isSliding = (slide != undefined ? slide : s.isSliding) // only open() passes 'slide' param + , $P = $Ps[pane] + , paneSpacing = o.spacing_open + // measure the pane on the *opposite side* from this pane + , altPane = _c.oppositeEdge[pane] + , altS = state[altPane] + , $altP = $Ps[altPane] + , altPaneSize = (!$altP || altS.isVisible===false || altS.isSliding ? 0 : (dir=="horz" ? $altP.outerHeight() : $altP.outerWidth())) + , altPaneSpacing = ((!$altP || altS.isHidden ? 0 : options[altPane][ altS.isClosed !== false ? "spacing_closed" : "spacing_open" ]) || 0) + // limitSize prevents this pane from 'overlapping' opposite pane + , containerSize = (dir=="horz" ? sC.innerHeight : sC.innerWidth) + , minCenterDims = cssMinDims("center") + , minCenterSize = dir=="horz" ? max(options.center.minHeight, minCenterDims.minHeight) : max(options.center.minWidth, minCenterDims.minWidth) + // if pane is 'sliding', then ignore center and alt-pane sizes - because 'overlays' them + , limitSize = (containerSize - paneSpacing - (isSliding ? 0 : (_parseSize("center", minCenterSize, dir) + altPaneSize + altPaneSpacing))) + , minSize = s.minSize = max( _parseSize(pane, o.minSize), cssMinDims(pane).minSize ) + , maxSize = s.maxSize = min( (o.maxSize ? _parseSize(pane, o.maxSize) : 100000), limitSize ) + , r = s.resizerPosition = {} // used to set resizing limits + , top = sC.inset.top + , left = sC.inset.left + , W = sC.innerWidth + , H = sC.innerHeight + , rW = o.spacing_open // subtract resizer-width to get top/left position for south/east + ; + switch (pane) { + case "north": r.min = top + minSize; + r.max = top + maxSize; + break; + case "west": r.min = left + minSize; + r.max = left + maxSize; + break; + case "south": r.min = top + H - maxSize - rW; + r.max = top + H - minSize - rW; + break; + case "east": r.min = left + W - maxSize - rW; + r.max = left + W - minSize - rW; + break; + }; + } + + /** + * Returns data for setting the size/position of center pane. Also used to set Height for east/west panes + * + * @return JSON Returns a hash of all dimensions: top, bottom, left, right, (outer) width and (outer) height + */ +, calcNewCenterPaneDims = function () { + var d = { + top: getPaneSize("north", true) // true = include 'spacing' value for pane + , bottom: getPaneSize("south", true) + , left: getPaneSize("west", true) + , right: getPaneSize("east", true) + , width: 0 + , height: 0 + }; + + // NOTE: sC = state.container + // calc center-pane outer dimensions + d.width = sC.innerWidth - d.left - d.right; // outerWidth + d.height = sC.innerHeight - d.bottom - d.top; // outerHeight + // add the 'container border/padding' to get final positions relative to the container + d.top += sC.inset.top; + d.bottom += sC.inset.bottom; + d.left += sC.inset.left; + d.right += sC.inset.right; + + return d; + } + + + /** + * @param {!Object} el + * @param {boolean=} [allStates=false] + */ +, getHoverClasses = function (el, allStates) { + var + $El = $(el) + , type = $El.data("layoutRole") + , pane = $El.data("layoutEdge") + , o = options[pane] + , root = o[type +"Class"] + , _pane = "-"+ pane // eg: "-west" + , _open = "-open" + , _closed = "-closed" + , _slide = "-sliding" + , _hover = "-hover " // NOTE the trailing space + , _state = $El.hasClass(root+_closed) ? _closed : _open + , _alt = _state === _closed ? _open : _closed + , classes = (root+_hover) + (root+_pane+_hover) + (root+_state+_hover) + (root+_pane+_state+_hover) + ; + if (allStates) // when 'removing' classes, also remove alternate-state classes + classes += (root+_alt+_hover) + (root+_pane+_alt+_hover); + + if (type=="resizer" && $El.hasClass(root+_slide)) + classes += (root+_slide+_hover) + (root+_pane+_slide+_hover); + + return $.trim(classes); + } +, addHover = function (evt, el) { + var $E = $(el || this); + if (evt && $E.data("layoutRole") === "toggler") + evt.stopPropagation(); // prevent triggering 'slide' on Resizer-bar + $E.addClass( getHoverClasses($E) ); + } +, removeHover = function (evt, el) { + var $E = $(el || this); + $E.removeClass( getHoverClasses($E, true) ); + } + +, onResizerEnter = function (evt) { // ALSO called by toggler.mouseenter + var pane = $(this).data("layoutEdge") + , s = state[pane] + , $d = $(document) + ; + // ignore closed-panes and mouse moving back & forth over resizer! + // also ignore if ANY pane is currently resizing + if ( s.isResizing || state.paneResizing ) return; + + if (options.maskPanesEarly) + showMasks( pane, { resizing: true }); + } +, onResizerLeave = function (evt, el) { + var e = el || this // el is only passed when called by the timer + , pane = $(e).data("layoutEdge") + , name = pane +"ResizerLeave" + , $d = $(document) + ; + timer.clear(pane+"_openSlider"); // cancel slideOpen timer, if set + timer.clear(name); // cancel enableSelection timer - may re/set below + // this method calls itself on a timer because it needs to allow + // enough time for dragging to kick-in and set the isResizing flag + // dragging has a 100ms delay set, so this delay must be >100 + if (!el) // 1st call - mouseleave event + timer.set(name, function(){ onResizerLeave(evt, e); }, 200); + // if user is resizing, dragStop will reset everything, so skip it here + else if (options.maskPanesEarly && !state.paneResizing) // 2nd call - by timer + hideMasks(); + } + +/* + * ########################### + * INITIALIZATION METHODS + * ########################### + */ + + /** + * Initialize the layout - called automatically whenever an instance of layout is created + * + * @see none - triggered onInit + * @return mixed true = fully initialized | false = panes not initialized (yet) | 'cancel' = abort + */ +, _create = function () { + // initialize config/options + initOptions(); + var o = options + , s = state; + + // TEMP state so isInitialized returns true during init process + s.creatingLayout = true; + + // init plugins for this layout, if there are any (eg: stateManagement) + runPluginCallbacks( Instance, $.layout.onCreate ); + + // options & state have been initialized, so now run beforeLoad callback + // onload will CANCEL layout creation if it returns false + if (false === _runCallbacks("onload_start")) + return 'cancel'; + + // initialize the container element + _initContainer(); + + // bind hotkey function - keyDown - if required + initHotkeys(); + + // bind window.onunload + $(window).bind("unload."+ sID, unload); + + // init plugins for this layout, if there are any (eg: customButtons) + runPluginCallbacks( Instance, $.layout.onLoad ); + + // if layout elements are hidden, then layout WILL NOT complete initialization! + // initLayoutElements will set initialized=true and run the onload callback IF successful + if (o.initPanes) _initLayoutElements(); + + delete s.creatingLayout; + + return state.initialized; + } + + /** + * Initialize the layout IF not already + * + * @see All methods in Instance run this test + * @return boolean true = layoutElements have been initialized | false = panes are not initialized (yet) + */ +, isInitialized = function () { + if (state.initialized || state.creatingLayout) return true; // already initialized + else return _initLayoutElements(); // try to init panes NOW + } + + /** + * Initialize the layout - called automatically whenever an instance of layout is created + * + * @see _create() & isInitialized + * @param {boolean=} [retry=false] // indicates this is a 2nd try + * @return An object pointer to the instance created + */ +, _initLayoutElements = function (retry) { + // initialize config/options + var o = options; + // CANNOT init panes inside a hidden container! + if (!$N.is(":visible")) { + // handle Chrome bug where popup window 'has no height' + // if layout is BODY element, try again in 50ms + // SEE: http://layout.jquery-dev.com/samples/test_popup_window.html + if ( !retry && browser.webkit && $N[0].tagName === "BODY" ) + setTimeout(function(){ _initLayoutElements(true); }, 50); + return false; + } + + // a center pane is required, so make sure it exists + if (!getPane("center").length) { + return _log( o.errors.centerPaneMissing ); + } + + // TEMP state so isInitialized returns true during init process + state.creatingLayout = true; + + // update Container dims + $.extend(sC, elDims( $N, o.inset )); // passing inset means DO NOT include insetX values + + // initialize all layout elements + initPanes(); // size & position panes - calls initHandles() - which calls initResizable() + + if (o.scrollToBookmarkOnLoad) { + var l = self.location; + if (l.hash) l.replace( l.hash ); // scrollTo Bookmark + } + + // check to see if this layout 'nested' inside a pane + if (Instance.hasParentLayout) + o.resizeWithWindow = false; + // bind resizeAll() for 'this layout instance' to window.resize event + else if (o.resizeWithWindow) + $(window).bind("resize."+ sID, windowResize); + + delete state.creatingLayout; + state.initialized = true; + + // init plugins for this layout, if there are any + runPluginCallbacks( Instance, $.layout.onReady ); + + // now run the onload callback, if exists + _runCallbacks("onload_end"); + + return true; // elements initialized successfully + } + + /** + * Initialize nested layouts for a specific pane - can optionally pass layout-options + * + * @param {(string|Object)} evt_or_pane The pane being opened, ie: north, south, east, or west + * @param {Object=} [opts] Layout-options - if passed, will OVERRRIDE options[pane].children + * @return An object pointer to the layout instance created - or null + */ +, createChildren = function (evt_or_pane, opts) { + var pane = evtPane.call(this, evt_or_pane) + , $P = $Ps[pane] + ; + if (!$P) return; + var $C = $Cs[pane] + , s = state[pane] + , o = options[pane] + , sm = options.stateManagement || {} + , cos = opts ? (o.children = opts) : o.children + ; + if ( $.isPlainObject( cos ) ) + cos = [ cos ]; // convert a hash to a 1-elem array + else if (!cos || !$.isArray( cos )) + return; + + $.each( cos, function (idx, co) { + if ( !$.isPlainObject( co ) ) return; + + // determine which element is supposed to be the 'child container' + // if pane has a 'containerSelector' OR a 'content-div', use those instead of the pane + var $containers = co.containerSelector ? $P.find( co.containerSelector ) : ($C || $P); + + $containers.each(function(){ + var $cont = $(this) + , child = $cont.data("layout") // see if a child-layout ALREADY exists on this element + ; + // if no layout exists, but children are set, try to create the layout now + if (!child) { + // TODO: see about moving this to the stateManagement plugin, as a method + // set a unique child-instance key for this layout, if not already set + setInstanceKey({ container: $cont, options: co }, s ); + // If THIS layout has a hash in stateManagement.autoLoad, + // then see if it also contains state-data for this child-layout + // If so, copy the stateData to child.options.stateManagement.autoLoad + if ( sm.includeChildren && state.stateData[pane] ) { + // THIS layout's state was cached when its state was loaded + var paneChildren = state.stateData[pane].children || {} + , childState = paneChildren[ co.instanceKey ] + , co_sm = co.stateManagement || (co.stateManagement = { autoLoad: true }) + ; + // COPY the stateData into the autoLoad key + if ( co_sm.autoLoad === true && childState ) { + co_sm.autoSave = false; // disable autoSave because saving handled by parent-layout + co_sm.includeChildren = true; // cascade option - FOR NOW + co_sm.autoLoad = $.extend(true, {}, childState); // COPY the state-hash + } + } + + // create the layout + child = $cont.layout( co ); + + // if successful, update data + if (child) { + // add the child and update all layout-pointers + // MAY have already been done by child-layout calling parent.refreshChildren() + refreshChildren( pane, child ); + } + } + }); + }); + } + +, setInstanceKey = function (child, parentPaneState) { + // create a named key for use in state and instance branches + var $c = child.container + , o = child.options + , sm = o.stateManagement + , key = o.instanceKey || $c.data("layoutInstanceKey") + ; + if (!key) key = (sm && sm.cookie ? sm.cookie.name : '') || o.name; // look for a name/key + if (!key) key = "layout"+ (++parentPaneState.childIdx); // if no name/key found, generate one + else key = key.replace(/[^\w-]/gi, '_').replace(/_{2,}/g, '_'); // ensure is valid as a hash key + o.instanceKey = key; + $c.data("layoutInstanceKey", key); // useful if layout is destroyed and then recreated + return key; + } + + /** + * @param {string} pane The pane being opened, ie: north, south, east, or west + * @param {Object=} newChild New child-layout Instance to add to this pane + */ +, refreshChildren = function (pane, newChild) { + var $P = $Ps[pane] + , pC = children[pane] + , s = state[pane] + , o + ; + // check for destroy()ed layouts and update the child pointers & arrays + if ($.isPlainObject( pC )) { + $.each( pC, function (key, child) { + if (child.destroyed) delete pC[key] + }); + // if no more children, remove the children hash + if ($.isEmptyObject( pC )) + pC = children[pane] = null; // clear children hash + } + + // see if there is a directly-nested layout inside this pane + // if there is, then there can be only ONE child-layout, so check that... + if (!newChild && !pC) { + newChild = $P.data("layout"); + } + + // if a newChild instance was passed, add it to children[pane] + if (newChild) { + // update child.state + newChild.hasParentLayout = true; // set parent-flag in child + // instanceKey is a key-name used in both state and children + o = newChild.options; + // set a unique child-instance key for this layout, if not already set + setInstanceKey( newChild, s ); + // add pointer to pane.children hash + if (!pC) pC = children[pane] = {}; // create an empty children hash + pC[ o.instanceKey ] = newChild.container.data("layout"); // add childLayout instance + } + + // ALWAYS refresh the pane.children alias, even if null + Instance[pane].children = children[pane]; + + // if newChild was NOT passed - see if there is a child layout NOW + if (!newChild) { + createChildren(pane); // MAY create a child and re-call this method + } + } + +, windowResize = function () { + var o = options + , delay = Number(o.resizeWithWindowDelay); + if (delay < 10) delay = 100; // MUST have a delay! + // resizing uses a delay-loop because the resize event fires repeatly - except in FF, but delay anyway + timer.clear("winResize"); // if already running + timer.set("winResize", function(){ + timer.clear("winResize"); + timer.clear("winResizeRepeater"); + var dims = elDims( $N, o.inset ); + // only trigger resizeAll() if container has changed size + if (dims.innerWidth !== sC.innerWidth || dims.innerHeight !== sC.innerHeight) + resizeAll(); + }, delay); + // ALSO set fixed-delay timer, if not already running + if (!timer.data["winResizeRepeater"]) setWindowResizeRepeater(); + } + +, setWindowResizeRepeater = function () { + var delay = Number(options.resizeWithWindowMaxDelay); + if (delay > 0) + timer.set("winResizeRepeater", function(){ setWindowResizeRepeater(); resizeAll(); }, delay); + } + +, unload = function () { + var o = options; + + _runCallbacks("onunload_start"); + + // trigger plugin callabacks for this layout (eg: stateManagement) + runPluginCallbacks( Instance, $.layout.onUnload ); + + _runCallbacks("onunload_end"); + } + + /** + * Validate and initialize container CSS and events + * + * @see _create() + */ +, _initContainer = function () { + var + N = $N[0] + , $H = $("html") + , tag = sC.tagName = N.tagName + , id = sC.id = N.id + , cls = sC.className = N.className + , o = options + , name = o.name + , props = "position,margin,padding,border" + , css = "layoutCSS" + , CSS = {} + , hid = "hidden" // used A LOT! + // see if this container is a 'pane' inside an outer-layout + , parent = $N.data("parentLayout") // parent-layout Instance + , pane = $N.data("layoutEdge") // pane-name in parent-layout + , isChild = parent && pane + , num = $.layout.cssNum + , $parent, n + ; + // sC = state.container + sC.selector = $N.selector.split(".slice")[0]; + sC.ref = (o.name ? o.name +' layout / ' : '') + tag + (id ? "#"+id : cls ? '.['+cls+']' : ''); // used in messages + sC.isBody = (tag === "BODY"); + + // try to find a parent-layout + if (!isChild && !sC.isBody) { + $parent = $N.closest("."+ $.layout.defaults.panes.paneClass); + parent = $parent.data("parentLayout"); + pane = $parent.data("layoutEdge"); + isChild = parent && pane; + } + + $N .data({ + layout: Instance + , layoutContainer: sID // FLAG to indicate this is a layout-container - contains unique internal ID + }) + .addClass(o.containerClass) + ; + var layoutMethods = { + destroy: '' + , initPanes: '' + , resizeAll: 'resizeAll' + , resize: 'resizeAll' + }; + // loop hash and bind all methods - include layoutID namespacing + for (name in layoutMethods) { + $N.bind("layout"+ name.toLowerCase() +"."+ sID, Instance[ layoutMethods[name] || name ]); + } + + // if this container is another layout's 'pane', then set child/parent pointers + if (isChild) { + // update parent flag + Instance.hasParentLayout = true; + // set pointers to THIS child-layout (Instance) in parent-layout + parent.refreshChildren( pane, Instance ); + } + + // SAVE original container CSS for use in destroy() + if (!$N.data(css)) { + // handle props like overflow different for BODY & HTML - has 'system default' values + if (sC.isBody) { + // SAVE CSS + $N.data(css, $.extend( styles($N, props), { + height: $N.css("height") + , overflow: $N.css("overflow") + , overflowX: $N.css("overflowX") + , overflowY: $N.css("overflowY") + })); + // ALSO SAVE CSS + $H.data(css, $.extend( styles($H, 'padding'), { + height: "auto" // FF would return a fixed px-size! + , overflow: $H.css("overflow") + , overflowX: $H.css("overflowX") + , overflowY: $H.css("overflowY") + })); + } + else // handle props normally for non-body elements + $N.data(css, styles($N, props+",top,bottom,left,right,width,height,overflow,overflowX,overflowY") ); + } + + try { + // common container CSS + CSS = { + overflow: hid + , overflowX: hid + , overflowY: hid + }; + $N.css( CSS ); + + if (o.inset && !$.isPlainObject(o.inset)) { + // can specify a single number for equal outset all-around + n = parseInt(o.inset, 10) || 0 + o.inset = { + top: n + , bottom: n + , left: n + , right: n + }; + } + + // format html & body if this is a full page layout + if (sC.isBody) { + // if HTML has padding, use this as an outer-spacing around BODY + if (!o.outset) { + // use padding from parent-elem (HTML) as outset + o.outset = { + top: num($H, "paddingTop") + , bottom: num($H, "paddingBottom") + , left: num($H, "paddingLeft") + , right: num($H, "paddingRight") + }; + } + else if (!$.isPlainObject(o.outset)) { + // can specify a single number for equal outset all-around + n = parseInt(o.outset, 10) || 0 + o.outset = { + top: n + , bottom: n + , left: n + , right: n + }; + } + // HTML + $H.css( CSS ).css({ + height: "100%" + , border: "none" // no border or padding allowed when using height = 100% + , padding: 0 // ditto + , margin: 0 + }); + // BODY + if (browser.isIE6) { + // IE6 CANNOT use the trick of setting absolute positioning on all 4 sides - must have 'height' + $N.css({ + width: "100%" + , height: "100%" + , border: "none" // no border or padding allowed when using height = 100% + , padding: 0 // ditto + , margin: 0 + , position: "relative" + }); + // convert body padding to an inset option - the border cannot be measured in IE6! + if (!o.inset) o.inset = elDims( $N ).inset; + } + else { // use absolute positioning for BODY to allow borders & padding without overflow + $N.css({ + width: "auto" + , height: "auto" + , margin: 0 + , position: "absolute" // allows for border and padding on BODY + }); + // apply edge-positioning created above + $N.css( o.outset ); + } + // set current layout-container dimensions + $.extend(sC, elDims( $N, o.inset )); // passing inset means DO NOT include insetX values + } + else { + // container MUST have 'position' + var p = $N.css("position"); + if (!p || !p.match(/(fixed|absolute|relative)/)) + $N.css("position","relative"); + + // set current layout-container dimensions + if ( $N.is(":visible") ) { + $.extend(sC, elDims( $N, o.inset )); // passing inset means DO NOT change insetX (padding) values + if (sC.innerHeight < 1) // container has no 'height' - warn developer + _log( o.errors.noContainerHeight.replace(/CONTAINER/, sC.ref) ); + } + } + + // if container has min-width/height, then enable scrollbar(s) + if ( num($N, "minWidth") ) $N.parent().css("overflowX","auto"); + if ( num($N, "minHeight") ) $N.parent().css("overflowY","auto"); + + } catch (ex) {} + } + + /** + * Bind layout hotkeys - if options enabled + * + * @see _create() and addPane() + * @param {string=} [panes=""] The edge(s) to process + */ +, initHotkeys = function (panes) { + panes = panes ? panes.split(",") : _c.borderPanes; + // bind keyDown to capture hotkeys, if option enabled for ANY pane + $.each(panes, function (i, pane) { + var o = options[pane]; + if (o.enableCursorHotkey || o.customHotkey) { + $(document).bind("keydown."+ sID, keyDown); // only need to bind this ONCE + return false; // BREAK - binding was done + } + }); + } + + /** + * Build final OPTIONS data + * + * @see _create() + */ +, initOptions = function () { + var data, d, pane, key, val, i, c, o; + + // reprocess user's layout-options to have correct options sub-key structure + opts = $.layout.transformData( opts, true ); // panes = default subkey + + // auto-rename old options for backward compatibility + opts = $.layout.backwardCompatibility.renameAllOptions( opts ); + + // if user-options has 'panes' key (pane-defaults), clean it... + if (!$.isEmptyObject(opts.panes)) { + // REMOVE any pane-defaults that MUST be set per-pane + data = $.layout.optionsMap.noDefault; + for (i=0, c=data.length; i 0) { + z.pane_normal = zo; + z.content_mask = max(zo+1, z.content_mask); // MIN = +1 + z.resizer_normal = max(zo+2, z.resizer_normal); // MIN = +2 + } + + // DELETE 'panes' key now that we are done - values were copied to EACH pane + delete options.panes; + + + function createFxOptions ( pane ) { + var o = options[pane] + , d = options.panes; + // ensure fxSettings key to avoid errors + if (!o.fxSettings) o.fxSettings = {}; + if (!d.fxSettings) d.fxSettings = {}; + + $.each(["_open","_close","_size"], function (i,n) { + var + sName = "fxName"+ n + , sSpeed = "fxSpeed"+ n + , sSettings = "fxSettings"+ n + // recalculate fxName according to specificity rules + , fxName = o[sName] = + o[sName] // options.west.fxName_open + || d[sName] // options.panes.fxName_open + || o.fxName // options.west.fxName + || d.fxName // options.panes.fxName + || "none" // MEANS $.layout.defaults.panes.fxName == "" || false || null || 0 + , fxExists = $.effects && ($.effects[fxName] || ($.effects.effect && $.effects.effect[fxName])) + ; + // validate fxName to ensure is valid effect - MUST have effect-config data in options.effects + if (fxName === "none" || !options.effects[fxName] || !fxExists) + fxName = o[sName] = "none"; // effect not loaded OR unrecognized fxName + + // set vars for effects subkeys to simplify logic + var fx = options.effects[fxName] || {} // effects.slide + , fx_all = fx.all || null // effects.slide.all + , fx_pane = fx[pane] || null // effects.slide.west + ; + // create fxSpeed[_open|_close|_size] + o[sSpeed] = + o[sSpeed] // options.west.fxSpeed_open + || d[sSpeed] // options.west.fxSpeed_open + || o.fxSpeed // options.west.fxSpeed + || d.fxSpeed // options.panes.fxSpeed + || null // DEFAULT - let fxSetting.duration control speed + ; + // create fxSettings[_open|_close|_size] + o[sSettings] = $.extend( + true + , {} + , fx_all // effects.slide.all + , fx_pane // effects.slide.west + , d.fxSettings // options.panes.fxSettings + , o.fxSettings // options.west.fxSettings + , d[sSettings] // options.panes.fxSettings_open + , o[sSettings] // options.west.fxSettings_open + ); + }); + + // DONE creating action-specific-settings for this pane, + // so DELETE generic options - are no longer meaningful + delete o.fxName; + delete o.fxSpeed; + delete o.fxSettings; + } + } + + /** + * Initialize module objects, styling, size and position for all panes + * + * @see _initElements() + * @param {string} pane The pane to process + */ +, getPane = function (pane) { + var sel = options[pane].paneSelector + if (sel.substr(0,1)==="#") // ID selector + // NOTE: elements selected 'by ID' DO NOT have to be 'children' + return $N.find(sel).eq(0); + else { // class or other selector + var $P = $N.children(sel).eq(0); + // look for the pane nested inside a 'form' element + return $P.length ? $P : $N.children("form:first").children(sel).eq(0); + } + } + + /** + * @param {Object=} evt + */ +, initPanes = function (evt) { + // stopPropagation if called by trigger("layoutinitpanes") - use evtPane utility + evtPane(evt); + + // NOTE: do north & south FIRST so we can measure their height - do center LAST + $.each(_c.allPanes, function (idx, pane) { + addPane( pane, true ); + }); + + // init the pane-handles NOW in case we have to hide or close the pane below + initHandles(); + + // now that all panes have been initialized and initially-sized, + // make sure there is really enough space available for each pane + $.each(_c.borderPanes, function (i, pane) { + if ($Ps[pane] && state[pane].isVisible) { // pane is OPEN + setSizeLimits(pane); + makePaneFit(pane); // pane may be Closed, Hidden or Resized by makePaneFit() + } + }); + // size center-pane AGAIN in case we 'closed' a border-pane in loop above + sizeMidPanes("center"); + + // Chrome/Webkit sometimes fires callbacks BEFORE it completes resizing! + // Before RC30.3, there was a 10ms delay here, but that caused layout + // to load asynchrously, which is BAD, so try skipping delay for now + + // process pane contents and callbacks, and init/resize child-layout if exists + $.each(_c.allPanes, function (idx, pane) { + afterInitPane(pane); + }); + } + + /** + * Add a pane to the layout - subroutine of initPanes() + * + * @see initPanes() + * @param {string} pane The pane to process + * @param {boolean=} [force=false] Size content after init + */ +, addPane = function (pane, force) { + if ( !force && !isInitialized() ) return; + var + o = options[pane] + , s = state[pane] + , c = _c[pane] + , dir = c.dir + , fx = s.fx + , spacing = o.spacing_open || 0 + , isCenter = (pane === "center") + , CSS = {} + , $P = $Ps[pane] + , size, minSize, maxSize, child + ; + // if pane-pointer already exists, remove the old one first + if ($P) + removePane( pane, false, true, false ); + else + $Cs[pane] = false; // init + + $P = $Ps[pane] = getPane(pane); + if (!$P.length) { + $Ps[pane] = false; // logic + return; + } + + // SAVE original Pane CSS + if (!$P.data("layoutCSS")) { + var props = "position,top,left,bottom,right,width,height,overflow,zIndex,display,backgroundColor,padding,margin,border"; + $P.data("layoutCSS", styles($P, props)); + } + + // create alias for pane data in Instance - initHandles will add more + Instance[pane] = { + name: pane + , pane: $Ps[pane] + , content: $Cs[pane] + , options: options[pane] + , state: state[pane] + , children: children[pane] + }; + + // add classes, attributes & events + $P .data({ + parentLayout: Instance // pointer to Layout Instance + , layoutPane: Instance[pane] // NEW pointer to pane-alias-object + , layoutEdge: pane + , layoutRole: "pane" + }) + .css(c.cssReq).css("zIndex", options.zIndexes.pane_normal) + .css(o.applyDemoStyles ? c.cssDemo : {}) // demo styles + .addClass( o.paneClass +" "+ o.paneClass+"-"+pane ) // default = "ui-layout-pane ui-layout-pane-west" - may be a dupe of 'paneSelector' + .bind("mouseenter."+ sID, addHover ) + .bind("mouseleave."+ sID, removeHover ) + ; + var paneMethods = { + hide: '' + , show: '' + , toggle: '' + , close: '' + , open: '' + , slideOpen: '' + , slideClose: '' + , slideToggle: '' + , size: 'sizePane' + , sizePane: 'sizePane' + , sizeContent: '' + , sizeHandles: '' + , enableClosable: '' + , disableClosable: '' + , enableSlideable: '' + , disableSlideable: '' + , enableResizable: '' + , disableResizable: '' + , swapPanes: 'swapPanes' + , swap: 'swapPanes' + , move: 'swapPanes' + , removePane: 'removePane' + , remove: 'removePane' + , createChildren: '' + , resizeChildren: '' + , resizeAll: 'resizeAll' + , resizeLayout: 'resizeAll' + } + , name; + // loop hash and bind all methods - include layoutID namespacing + for (name in paneMethods) { + $P.bind("layoutpane"+ name.toLowerCase() +"."+ sID, Instance[ paneMethods[name] || name ]); + } + + // see if this pane has a 'scrolling-content element' + initContent(pane, false); // false = do NOT sizeContent() - called later + + if (!isCenter) { + // call _parseSize AFTER applying pane classes & styles - but before making visible (if hidden) + // if o.size is auto or not valid, then MEASURE the pane and use that as its 'size' + size = s.size = _parseSize(pane, o.size); + minSize = _parseSize(pane,o.minSize) || 1; + maxSize = _parseSize(pane,o.maxSize) || 100000; + if (size > 0) size = max(min(size, maxSize), minSize); + s.autoResize = o.autoResize; // used with percentage sizes + + // state for border-panes + s.isClosed = false; // true = pane is closed + s.isSliding = false; // true = pane is currently open by 'sliding' over adjacent panes + s.isResizing= false; // true = pane is in process of being resized + s.isHidden = false; // true = pane is hidden - no spacing, resizer or toggler is visible! + + // array for 'pin buttons' whose classNames are auto-updated on pane-open/-close + if (!s.pins) s.pins = []; + } + // states common to ALL panes + s.tagName = $P[0].tagName; + s.edge = pane; // useful if pane is (or about to be) 'swapped' - easy find out where it is (or is going) + s.noRoom = false; // true = pane 'automatically' hidden due to insufficient room - will unhide automatically + s.isVisible = true; // false = pane is invisible - closed OR hidden - simplify logic + + // init pane positioning + setPanePosition( pane ); + + // if pane is not visible, + if (dir === "horz") // north or south pane + CSS.height = cssH($P, size); + else if (dir === "vert") // east or west pane + CSS.width = cssW($P, size); + //else if (isCenter) {} + + $P.css(CSS); // apply size -- top, bottom & height will be set by sizeMidPanes + if (dir != "horz") sizeMidPanes(pane, true); // true = skipCallback + + // if manually adding a pane AFTER layout initialization, then... + if (state.initialized) { + initHandles( pane ); + initHotkeys( pane ); + } + + // close or hide the pane if specified in settings + if (o.initClosed && o.closable && !o.initHidden) + close(pane, true, true); // true, true = force, noAnimation + else if (o.initHidden || o.initClosed) + hide(pane); // will be completely invisible - no resizer or spacing + else if (!s.noRoom) + // make the pane visible - in case was initially hidden + $P.css("display","block"); + // ELSE setAsOpen() - called later by initHandles() + + // RESET visibility now - pane will appear IF display:block + $P.css("visibility","visible"); + + // check option for auto-handling of pop-ups & drop-downs + if (o.showOverflowOnHover) + $P.hover( allowOverflow, resetOverflow ); + + // if manually adding a pane AFTER layout initialization, then... + if (state.initialized) { + afterInitPane( pane ); + } + } + +, afterInitPane = function (pane) { + var $P = $Ps[pane] + , s = state[pane] + , o = options[pane] + ; + if (!$P) return; + + // see if there is a directly-nested layout inside this pane + if ($P.data("layout")) + refreshChildren( pane, $P.data("layout") ); + + // process pane contents and callbacks, and init/resize child-layout if exists + if (s.isVisible) { // pane is OPEN + if (state.initialized) // this pane was added AFTER layout was created + resizeAll(); // will also sizeContent + else + sizeContent(pane); + + if (o.triggerEventsOnLoad) + _runCallbacks("onresize_end", pane); + else // automatic if onresize called, otherwise call it specifically + // resize child - IF inner-layout already exists (created before this layout) + resizeChildren(pane, true); // a previously existing childLayout + } + + // init childLayouts - even if pane is not visible + if (o.initChildren && o.children) + createChildren(pane); + } + + /** + * @param {string=} panes The pane(s) to process + */ +, setPanePosition = function (panes) { + panes = panes ? panes.split(",") : _c.borderPanes; + + // create toggler DIVs for each pane, and set object pointers for them, eg: $R.north = north toggler DIV + $.each(panes, function (i, pane) { + var $P = $Ps[pane] + , $R = $Rs[pane] + , o = options[pane] + , s = state[pane] + , side = _c[pane].side + , CSS = {} + ; + if (!$P) return; // pane does not exist - skip + + // set css-position to account for container borders & padding + switch (pane) { + case "north": CSS.top = sC.inset.top; + CSS.left = sC.inset.left; + CSS.right = sC.inset.right; + break; + case "south": CSS.bottom = sC.inset.bottom; + CSS.left = sC.inset.left; + CSS.right = sC.inset.right; + break; + case "west": CSS.left = sC.inset.left; // top, bottom & height set by sizeMidPanes() + break; + case "east": CSS.right = sC.inset.right; // ditto + break; + case "center": // top, left, width & height set by sizeMidPanes() + } + // apply position + $P.css(CSS); + + // update resizer position + if ($R && s.isClosed) + $R.css(side, sC.inset[side]); + else if ($R && !s.isHidden) + $R.css(side, sC.inset[side] + getPaneSize(pane)); + }); + } + + /** + * Initialize module objects, styling, size and position for all resize bars and toggler buttons + * + * @see _create() + * @param {string=} [panes=""] The edge(s) to process + */ +, initHandles = function (panes) { + panes = panes ? panes.split(",") : _c.borderPanes; + + // create toggler DIVs for each pane, and set object pointers for them, eg: $R.north = north toggler DIV + $.each(panes, function (i, pane) { + var $P = $Ps[pane]; + $Rs[pane] = false; // INIT + $Ts[pane] = false; + if (!$P) return; // pane does not exist - skip + + var o = options[pane] + , s = state[pane] + , c = _c[pane] + , paneId = o.paneSelector.substr(0,1) === "#" ? o.paneSelector.substr(1) : "" + , rClass = o.resizerClass + , tClass = o.togglerClass + , spacing = (s.isVisible ? o.spacing_open : o.spacing_closed) + , _pane = "-"+ pane // used for classNames + , _state = (s.isVisible ? "-open" : "-closed") // used for classNames + , I = Instance[pane] + // INIT RESIZER BAR + , $R = I.resizer = $Rs[pane] = $("
        ") + // INIT TOGGLER BUTTON + , $T = I.toggler = (o.closable ? $Ts[pane] = $("
        ") : false) + ; + + //if (s.isVisible && o.resizable) ... handled by initResizable + if (!s.isVisible && o.slidable) + $R.attr("title", o.tips.Slide).css("cursor", o.sliderCursor); + + $R // if paneSelector is an ID, then create a matching ID for the resizer, eg: "#paneLeft" => "paneLeft-resizer" + .attr("id", paneId ? paneId +"-resizer" : "" ) + .data({ + parentLayout: Instance + , layoutPane: Instance[pane] // NEW pointer to pane-alias-object + , layoutEdge: pane + , layoutRole: "resizer" + }) + .css(_c.resizers.cssReq).css("zIndex", options.zIndexes.resizer_normal) + .css(o.applyDemoStyles ? _c.resizers.cssDemo : {}) // add demo styles + .addClass(rClass +" "+ rClass+_pane) + .hover(addHover, removeHover) // ALWAYS add hover-classes, even if resizing is not enabled - handle with CSS instead + .hover(onResizerEnter, onResizerLeave) // ALWAYS NEED resizer.mouseleave to balance toggler.mouseenter + .mousedown($.layout.disableTextSelection) // prevent text-selection OUTSIDE resizer + .mouseup($.layout.enableTextSelection) // not really necessary, but just in case + .appendTo($N) // append DIV to container + ; + if ($.fn.disableSelection) + $R.disableSelection(); // prevent text-selection INSIDE resizer + if (o.resizerDblClickToggle) + $R.bind("dblclick."+ sID, toggle ); + + if ($T) { + $T // if paneSelector is an ID, then create a matching ID for the resizer, eg: "#paneLeft" => "#paneLeft-toggler" + .attr("id", paneId ? paneId +"-toggler" : "" ) + .data({ + parentLayout: Instance + , layoutPane: Instance[pane] // NEW pointer to pane-alias-object + , layoutEdge: pane + , layoutRole: "toggler" + }) + .css(_c.togglers.cssReq) // add base/required styles + .css(o.applyDemoStyles ? _c.togglers.cssDemo : {}) // add demo styles + .addClass(tClass +" "+ tClass+_pane) + .hover(addHover, removeHover) // ALWAYS add hover-classes, even if toggling is not enabled - handle with CSS instead + .bind("mouseenter", onResizerEnter) // NEED toggler.mouseenter because mouseenter MAY NOT fire on resizer + .appendTo($R) // append SPAN to resizer DIV + ; + // ADD INNER-SPANS TO TOGGLER + if (o.togglerContent_open) // ui-layout-open + $(""+ o.togglerContent_open +"") + .data({ + layoutEdge: pane + , layoutRole: "togglerContent" + }) + .data("layoutRole", "togglerContent") + .data("layoutEdge", pane) + .addClass("content content-open") + .css("display","none") + .appendTo( $T ) + //.hover( addHover, removeHover ) // use ui-layout-toggler-west-hover .content-open instead! + ; + if (o.togglerContent_closed) // ui-layout-closed + $(""+ o.togglerContent_closed +"") + .data({ + layoutEdge: pane + , layoutRole: "togglerContent" + }) + .addClass("content content-closed") + .css("display","none") + .appendTo( $T ) + //.hover( addHover, removeHover ) // use ui-layout-toggler-west-hover .content-closed instead! + ; + // ADD TOGGLER.click/.hover + enableClosable(pane); + } + + // add Draggable events + initResizable(pane); + + // ADD CLASSNAMES & SLIDE-BINDINGS - eg: class="resizer resizer-west resizer-open" + if (s.isVisible) + setAsOpen(pane); // onOpen will be called, but NOT onResize + else { + setAsClosed(pane); // onClose will be called + bindStartSlidingEvents(pane, true); // will enable events IF option is set + } + + }); + + // SET ALL HANDLE DIMENSIONS + sizeHandles(); + } + + + /** + * Initialize scrolling ui-layout-content div - if exists + * + * @see initPane() - or externally after an Ajax injection + * @param {string} pane The pane to process + * @param {boolean=} [resize=true] Size content after init + */ +, initContent = function (pane, resize) { + if (!isInitialized()) return; + var + o = options[pane] + , sel = o.contentSelector + , I = Instance[pane] + , $P = $Ps[pane] + , $C + ; + if (sel) $C = I.content = $Cs[pane] = (o.findNestedContent) + ? $P.find(sel).eq(0) // match 1-element only + : $P.children(sel).eq(0) + ; + if ($C && $C.length) { + $C.data("layoutRole", "content"); + // SAVE original Content CSS + if (!$C.data("layoutCSS")) + $C.data("layoutCSS", styles($C, "height")); + $C.css( _c.content.cssReq ); + if (o.applyDemoStyles) { + $C.css( _c.content.cssDemo ); // add padding & overflow: auto to content-div + $P.css( _c.content.cssDemoPane ); // REMOVE padding/scrolling from pane + } + // ensure no vertical scrollbar on pane - will mess up measurements + if ($P.css("overflowX").match(/(scroll|auto)/)) { + $P.css("overflow", "hidden"); + } + state[pane].content = {}; // init content state + if (resize !== false) sizeContent(pane); + // sizeContent() is called AFTER init of all elements + } + else + I.content = $Cs[pane] = false; + } + + + /** + * Add resize-bars to all panes that specify it in options + * -dependancy: $.fn.resizable - will skip if not found + * + * @see _create() + * @param {string=} [panes=""] The edge(s) to process + */ +, initResizable = function (panes) { + var draggingAvailable = $.layout.plugins.draggable + , side // set in start() + ; + panes = panes ? panes.split(",") : _c.borderPanes; + + $.each(panes, function (idx, pane) { + var o = options[pane]; + if (!draggingAvailable || !$Ps[pane] || !o.resizable) { + o.resizable = false; + return true; // skip to next + } + + var s = state[pane] + , z = options.zIndexes + , c = _c[pane] + , side = c.dir=="horz" ? "top" : "left" + , $P = $Ps[pane] + , $R = $Rs[pane] + , base = o.resizerClass + , lastPos = 0 // used when live-resizing + , r, live // set in start because may change + // 'drag' classes are applied to the ORIGINAL resizer-bar while dragging is in process + , resizerClass = base+"-drag" // resizer-drag + , resizerPaneClass = base+"-"+pane+"-drag" // resizer-north-drag + // 'helper' class is applied to the CLONED resizer-bar while it is being dragged + , helperClass = base+"-dragging" // resizer-dragging + , helperPaneClass = base+"-"+pane+"-dragging" // resizer-north-dragging + , helperLimitClass = base+"-dragging-limit" // resizer-drag + , helperPaneLimitClass = base+"-"+pane+"-dragging-limit" // resizer-north-drag + , helperClassesSet = false // logic var + ; + + if (!s.isClosed) + $R.attr("title", o.tips.Resize) + .css("cursor", o.resizerCursor); // n-resize, s-resize, etc + + $R.draggable({ + containment: $N[0] // limit resizing to layout container + , axis: (c.dir=="horz" ? "y" : "x") // limit resizing to horz or vert axis + , delay: 0 + , distance: 1 + , grid: o.resizingGrid + // basic format for helper - style it using class: .ui-draggable-dragging + , helper: "clone" + , opacity: o.resizerDragOpacity + , addClasses: false // avoid ui-state-disabled class when disabled + //, iframeFix: o.draggableIframeFix // TODO: consider using when bug is fixed + , zIndex: z.resizer_drag + + , start: function (e, ui) { + // REFRESH options & state pointers in case we used swapPanes + o = options[pane]; + s = state[pane]; + // re-read options + live = o.livePaneResizing; + + // ondrag_start callback - will CANCEL hide if returns false + // TODO: dragging CANNOT be cancelled like this, so see if there is a way? + if (false === _runCallbacks("ondrag_start", pane)) return false; + + s.isResizing = true; // prevent pane from closing while resizing + state.paneResizing = pane; // easy to see if ANY pane is resizing + timer.clear(pane+"_closeSlider"); // just in case already triggered + + // SET RESIZER LIMITS - used in drag() + setSizeLimits(pane); // update pane/resizer state + r = s.resizerPosition; + lastPos = ui.position[ side ] + + $R.addClass( resizerClass +" "+ resizerPaneClass ); // add drag classes + helperClassesSet = false; // reset logic var - see drag() + + // MASK PANES CONTAINING IFRAMES, APPLETS OR OTHER TROUBLESOME ELEMENTS + showMasks( pane, { resizing: true }); + } + + , drag: function (e, ui) { + if (!helperClassesSet) { // can only add classes after clone has been added to the DOM + //$(".ui-draggable-dragging") + ui.helper + .addClass( helperClass +" "+ helperPaneClass ) // add helper classes + .css({ right: "auto", bottom: "auto" }) // fix dir="rtl" issue + .children().css("visibility","hidden") // hide toggler inside dragged resizer-bar + ; + helperClassesSet = true; + // draggable bug!? RE-SET zIndex to prevent E/W resize-bar showing through N/S pane! + if (s.isSliding) $Ps[pane].css("zIndex", z.pane_sliding); + } + // CONTAIN RESIZER-BAR TO RESIZING LIMITS + var limit = 0; + if (ui.position[side] < r.min) { + ui.position[side] = r.min; + limit = -1; + } + else if (ui.position[side] > r.max) { + ui.position[side] = r.max; + limit = 1; + } + // ADD/REMOVE dragging-limit CLASS + if (limit) { + ui.helper.addClass( helperLimitClass +" "+ helperPaneLimitClass ); // at dragging-limit + window.defaultStatus = (limit>0 && pane.match(/(north|west)/)) || (limit<0 && pane.match(/(south|east)/)) ? o.tips.maxSizeWarning : o.tips.minSizeWarning; + } + else { + ui.helper.removeClass( helperLimitClass +" "+ helperPaneLimitClass ); // not at dragging-limit + window.defaultStatus = ""; + } + // DYNAMICALLY RESIZE PANES IF OPTION ENABLED + // won't trigger unless resizer has actually moved! + if (live && Math.abs(ui.position[side] - lastPos) >= o.liveResizingTolerance) { + lastPos = ui.position[side]; + resizePanes(e, ui, pane) + } + } + + , stop: function (e, ui) { + $('body').enableSelection(); // RE-ENABLE TEXT SELECTION + window.defaultStatus = ""; // clear 'resizing limit' message from statusbar + $R.removeClass( resizerClass +" "+ resizerPaneClass ); // remove drag classes from Resizer + s.isResizing = false; + state.paneResizing = false; // easy to see if ANY pane is resizing + resizePanes(e, ui, pane, true); // true = resizingDone + } + + }); + }); + + /** + * resizePanes + * + * Sub-routine called from stop() - and drag() if livePaneResizing + * + * @param {!Object} evt + * @param {!Object} ui + * @param {string} pane + * @param {boolean=} [resizingDone=false] + */ + var resizePanes = function (evt, ui, pane, resizingDone) { + var dragPos = ui.position + , c = _c[pane] + , o = options[pane] + , s = state[pane] + , resizerPos + ; + switch (pane) { + case "north": resizerPos = dragPos.top; break; + case "west": resizerPos = dragPos.left; break; + case "south": resizerPos = sC.layoutHeight - dragPos.top - o.spacing_open; break; + case "east": resizerPos = sC.layoutWidth - dragPos.left - o.spacing_open; break; + }; + // remove container margin from resizer position to get the pane size + var newSize = resizerPos - sC.inset[c.side]; + + // Disable OR Resize Mask(s) created in drag.start + if (!resizingDone) { + // ensure we meet liveResizingTolerance criteria + if (Math.abs(newSize - s.size) < o.liveResizingTolerance) + return; // SKIP resize this time + // resize the pane + manualSizePane(pane, newSize, false, true); // true = noAnimation + sizeMasks(); // resize all visible masks + } + else { // resizingDone + // ondrag_end callback + if (false !== _runCallbacks("ondrag_end", pane)) + manualSizePane(pane, newSize, false, true); // true = noAnimation + hideMasks(true); // true = force hiding all masks even if one is 'sliding' + if (s.isSliding) // RE-SHOW 'object-masks' so objects won't show through sliding pane + showMasks( pane, { resizing: true }); + } + }; + } + + /** + * sizeMask + * + * Needed to overlay a DIV over an IFRAME-pane because mask CANNOT be *inside* the pane + * Called when mask created, and during livePaneResizing + */ +, sizeMask = function () { + var $M = $(this) + , pane = $M.data("layoutMask") // eg: "west" + , s = state[pane] + ; + // only masks over an IFRAME-pane need manual resizing + if (s.tagName == "IFRAME" && s.isVisible) // no need to mask closed/hidden panes + $M.css({ + top: s.offsetTop + , left: s.offsetLeft + , width: s.outerWidth + , height: s.outerHeight + }); + /* ALT Method... + var $P = $Ps[pane]; + $M.css( $P.position() ).css({ width: $P[0].offsetWidth, height: $P[0].offsetHeight }); + */ + } +, sizeMasks = function () { + $Ms.each( sizeMask ); // resize all 'visible' masks + } + + /** + * @param {string} pane The pane being resized, animated or isSliding + * @param {Object=} [args] (optional) Options: which masks to apply, and to which panes + */ +, showMasks = function (pane, args) { + var c = _c[pane] + , panes = ["center"] + , z = options.zIndexes + , a = $.extend({ + objectsOnly: false + , animation: false + , resizing: true + , sliding: state[pane].isSliding + }, args ) + , o, s + ; + if (a.resizing) + panes.push( pane ); + if (a.sliding) + panes.push( _c.oppositeEdge[pane] ); // ADD the oppositeEdge-pane + + if (c.dir === "horz") { + panes.push("west"); + panes.push("east"); + } + + $.each(panes, function(i,p){ + s = state[p]; + o = options[p]; + if (s.isVisible && ( o.maskObjects || (!a.objectsOnly && o.maskContents) )) { + getMasks(p).each(function(){ + sizeMask.call(this); + this.style.zIndex = s.isSliding ? z.pane_sliding+1 : z.pane_normal+1 + this.style.display = "block"; + }); + } + }); + } + + /** + * @param {boolean=} force Hide masks even if a pane is sliding + */ +, hideMasks = function (force) { + // ensure no pane is resizing - could be a timing issue + if (force || !state.paneResizing) { + $Ms.hide(); // hide ALL masks + } + // if ANY pane is sliding, then DO NOT remove masks from panes with maskObjects enabled + else if (!force && !$.isEmptyObject( state.panesSliding )) { + var i = $Ms.length - 1 + , p, $M; + for (; i >= 0; i--) { + $M = $Ms.eq(i); + p = $M.data("layoutMask"); + if (!options[p].maskObjects) { + $M.hide(); + } + } + } + } + + /** + * @param {string} pane + */ +, getMasks = function (pane) { + var $Masks = $([]) + , $M, i = 0, c = $Ms.length + ; + for (; i CSS + if (sC.tagName === "BODY" && ($N = $("html")).data(css)) // RESET CSS + $N.css( $N.data(css) ).removeData(css); + + // trigger plugins for this layout, if there are any + runPluginCallbacks( Instance, $.layout.onDestroy ); + + // trigger state-management and onunload callback + unload(); + + // clear the Instance of everything except for container & options (so could recreate) + // RE-CREATE: myLayout = myLayout.container.layout( myLayout.options ); + for (var n in Instance) + if (!n.match(/^(container|options)$/)) delete Instance[ n ]; + // add a 'destroyed' flag to make it easy to check + Instance.destroyed = true; + + // if this is a child layout, CLEAR the child-pointer in the parent + /* for now the pointer REMAINS, but with only container, options and destroyed keys + if (parentPane) { + var layout = parentPane.pane.data("parentLayout") + , key = layout.options.instanceKey || 'error'; + // THIS SYNTAX MAY BE WRONG! + parentPane.children[key] = layout.children[ parentPane.name ].children[key] = null; + } + */ + + return Instance; // for coding convenience + } + + /** + * Remove a pane from the layout - subroutine of destroy() + * + * @see destroy() + * @param {(string|Object)} evt_or_pane The pane to process + * @param {boolean=} [remove=false] Remove the DOM element? + * @param {boolean=} [skipResize=false] Skip calling resizeAll()? + * @param {boolean=} [destroyChild=true] Destroy Child-layouts? If not passed, obeys options setting + */ +, removePane = function (evt_or_pane, remove, skipResize, destroyChild) { + if (!isInitialized()) return; + var pane = evtPane.call(this, evt_or_pane) + , $P = $Ps[pane] + , $C = $Cs[pane] + , $R = $Rs[pane] + , $T = $Ts[pane] + ; + // NOTE: elements can still exist even after remove() + // so check for missing data(), which is cleared by removed() + if ($P && $.isEmptyObject( $P.data() )) $P = false; + if ($C && $.isEmptyObject( $C.data() )) $C = false; + if ($R && $.isEmptyObject( $R.data() )) $R = false; + if ($T && $.isEmptyObject( $T.data() )) $T = false; + + if ($P) $P.stop(true, true); + + var o = options[pane] + , s = state[pane] + , d = "layout" + , css = "layoutCSS" + , pC = children[pane] + , hasChildren = $.isPlainObject( pC ) && !$.isEmptyObject( pC ) + , destroy = destroyChild !== undefined ? destroyChild : o.destroyChildren + ; + // FIRST destroy the child-layout(s) + if (hasChildren && destroy) { + $.each( pC, function (key, child) { + if (!child.destroyed) + child.destroy(true);// tell child-layout to destroy ALL its child-layouts too + if (child.destroyed) // destroy was successful + delete pC[key]; + }); + // if no more children, remove the children hash + if ($.isEmptyObject( pC )) { + pC = children[pane] = null; // clear children hash + hasChildren = false; + } + } + + // Note: can't 'remove' a pane element with non-destroyed children + if ($P && remove && !hasChildren) + $P.remove(); // remove the pane-element and everything inside it + else if ($P && $P[0]) { + // create list of ALL pane-classes that need to be removed + var root = o.paneClass // default="ui-layout-pane" + , pRoot = root +"-"+ pane // eg: "ui-layout-pane-west" + , _open = "-open" + , _sliding= "-sliding" + , _closed = "-closed" + , classes = [ root, root+_open, root+_closed, root+_sliding, // generic classes + pRoot, pRoot+_open, pRoot+_closed, pRoot+_sliding ] // pane-specific classes + ; + $.merge(classes, getHoverClasses($P, true)); // ADD hover-classes + // remove all Layout classes from pane-element + $P .removeClass( classes.join(" ") ) // remove ALL pane-classes + .removeData("parentLayout") + .removeData("layoutPane") + .removeData("layoutRole") + .removeData("layoutEdge") + .removeData("autoHidden") // in case set + .unbind("."+ sID) // remove ALL Layout events + // TODO: remove these extra unbind commands when jQuery is fixed + //.unbind("mouseenter"+ sID) + //.unbind("mouseleave"+ sID) + ; + // do NOT reset CSS if this pane/content is STILL the container of a nested layout! + // the nested layout will reset its 'container' CSS when/if it is destroyed + if (hasChildren && $C) { + // a content-div may not have a specific width, so give it one to contain the Layout + $C.width( $C.width() ); + $.each( pC, function (key, child) { + child.resizeAll(); // resize the Layout + }); + } + else if ($C) + $C.css( $C.data(css) ).removeData(css).removeData("layoutRole"); + // remove pane AFTER content in case there was a nested layout + if (!$P.data(d)) + $P.css( $P.data(css) ).removeData(css); + } + + // REMOVE pane resizer and toggler elements + if ($T) $T.remove(); + if ($R) $R.remove(); + + // CLEAR all pointers and state data + Instance[pane] = $Ps[pane] = $Cs[pane] = $Rs[pane] = $Ts[pane] = false; + s = { removed: true }; + + if (!skipResize) + resizeAll(); + } + + +/* + * ########################### + * ACTION METHODS + * ########################### + */ + + /** + * @param {string} pane + */ +, _hidePane = function (pane) { + var $P = $Ps[pane] + , o = options[pane] + , s = $P[0].style + ; + if (o.useOffscreenClose) { + if (!$P.data(_c.offscreenReset)) + $P.data(_c.offscreenReset, { left: s.left, right: s.right }); + $P.css( _c.offscreenCSS ); + } + else + $P.hide().removeData(_c.offscreenReset); + } + + /** + * @param {string} pane + */ +, _showPane = function (pane) { + var $P = $Ps[pane] + , o = options[pane] + , off = _c.offscreenCSS + , old = $P.data(_c.offscreenReset) + , s = $P[0].style + ; + $P .show() // ALWAYS show, just in case + .removeData(_c.offscreenReset); + if (o.useOffscreenClose && old) { + if (s.left == off.left) + s.left = old.left; + if (s.right == off.right) + s.right = old.right; + } + } + + + /** + * Completely 'hides' a pane, including its spacing - as if it does not exist + * The pane is not actually 'removed' from the source, so can use 'show' to un-hide it + * + * @param {(string|Object)} evt_or_pane The pane being hidden, ie: north, south, east, or west + * @param {boolean=} [noAnimation=false] + */ +, hide = function (evt_or_pane, noAnimation) { + if (!isInitialized()) return; + var pane = evtPane.call(this, evt_or_pane) + , o = options[pane] + , s = state[pane] + , $P = $Ps[pane] + , $R = $Rs[pane] + ; + if (pane === "center" || !$P || s.isHidden) return; // pane does not exist OR is already hidden + + // onhide_start callback - will CANCEL hide if returns false + if (state.initialized && false === _runCallbacks("onhide_start", pane)) return; + + s.isSliding = false; // just in case + delete state.panesSliding[pane]; + + // now hide the elements + if ($R) $R.hide(); // hide resizer-bar + if (!state.initialized || s.isClosed) { + s.isClosed = true; // to trigger open-animation on show() + s.isHidden = true; + s.isVisible = false; + if (!state.initialized) + _hidePane(pane); // no animation when loading page + sizeMidPanes(_c[pane].dir === "horz" ? "" : "center"); + if (state.initialized || o.triggerEventsOnLoad) + _runCallbacks("onhide_end", pane); + } + else { + s.isHiding = true; // used by onclose + close(pane, false, noAnimation); // adjust all panes to fit + } + } + + /** + * Show a hidden pane - show as 'closed' by default unless openPane = true + * + * @param {(string|Object)} evt_or_pane The pane being opened, ie: north, south, east, or west + * @param {boolean=} [openPane=false] + * @param {boolean=} [noAnimation=false] + * @param {boolean=} [noAlert=false] + */ +, show = function (evt_or_pane, openPane, noAnimation, noAlert) { + if (!isInitialized()) return; + var pane = evtPane.call(this, evt_or_pane) + , o = options[pane] + , s = state[pane] + , $P = $Ps[pane] + , $R = $Rs[pane] + ; + if (pane === "center" || !$P || !s.isHidden) return; // pane does not exist OR is not hidden + + // onshow_start callback - will CANCEL show if returns false + if (false === _runCallbacks("onshow_start", pane)) return; + + s.isShowing = true; // used by onopen/onclose + //s.isHidden = false; - will be set by open/close - if not cancelled + s.isSliding = false; // just in case + delete state.panesSliding[pane]; + + // now show the elements + //if ($R) $R.show(); - will be shown by open/close + if (openPane === false) + close(pane, true); // true = force + else + open(pane, false, noAnimation, noAlert); // adjust all panes to fit + } + + + /** + * Toggles a pane open/closed by calling either open or close + * + * @param {(string|Object)} evt_or_pane The pane being toggled, ie: north, south, east, or west + * @param {boolean=} [slide=false] + */ +, toggle = function (evt_or_pane, slide) { + if (!isInitialized()) return; + var evt = evtObj(evt_or_pane) + , pane = evtPane.call(this, evt_or_pane) + , s = state[pane] + ; + if (evt) // called from to $R.dblclick OR triggerPaneEvent + evt.stopImmediatePropagation(); + if (s.isHidden) + show(pane); // will call 'open' after unhiding it + else if (s.isClosed) + open(pane, !!slide); + else + close(pane); + } + + + /** + * Utility method used during init or other auto-processes + * + * @param {string} pane The pane being closed + * @param {boolean=} [setHandles=false] + */ +, _closePane = function (pane, setHandles) { + var + $P = $Ps[pane] + , s = state[pane] + ; + _hidePane(pane); + s.isClosed = true; + s.isVisible = false; + if (setHandles) setAsClosed(pane); + } + + /** + * Close the specified pane (animation optional), and resize all other panes as needed + * + * @param {(string|Object)} evt_or_pane The pane being closed, ie: north, south, east, or west + * @param {boolean=} [force=false] + * @param {boolean=} [noAnimation=false] + * @param {boolean=} [skipCallback=false] + */ +, close = function (evt_or_pane, force, noAnimation, skipCallback) { + var pane = evtPane.call(this, evt_or_pane); + if (pane === "center") return; // validate + // if pane has been initialized, but NOT the complete layout, close pane instantly + if (!state.initialized && $Ps[pane]) { + _closePane(pane, true); // INIT pane as closed + return; + } + if (!isInitialized()) return; + + var + $P = $Ps[pane] + , $R = $Rs[pane] + , $T = $Ts[pane] + , o = options[pane] + , s = state[pane] + , c = _c[pane] + , doFX, isShowing, isHiding, wasSliding; + + // QUEUE in case another action/animation is in progress + $N.queue(function( queueNext ){ + + if ( !$P + || (!o.closable && !s.isShowing && !s.isHiding) // invalid request // (!o.resizable && !o.closable) ??? + || (!force && s.isClosed && !s.isShowing) // already closed + ) return queueNext(); + + // onclose_start callback - will CANCEL hide if returns false + // SKIP if just 'showing' a hidden pane as 'closed' + var abort = !s.isShowing && false === _runCallbacks("onclose_start", pane); + + // transfer logic vars to temp vars + isShowing = s.isShowing; + isHiding = s.isHiding; + wasSliding = s.isSliding; + // now clear the logic vars (REQUIRED before aborting) + delete s.isShowing; + delete s.isHiding; + + if (abort) return queueNext(); + + doFX = !noAnimation && !s.isClosed && (o.fxName_close != "none"); + s.isMoving = true; + s.isClosed = true; + s.isVisible = false; + // update isHidden BEFORE sizing panes + if (isHiding) s.isHidden = true; + else if (isShowing) s.isHidden = false; + + if (s.isSliding) // pane is being closed, so UNBIND trigger events + bindStopSlidingEvents(pane, false); // will set isSliding=false + else // resize panes adjacent to this one + sizeMidPanes(_c[pane].dir === "horz" ? "" : "center", false); // false = NOT skipCallback + + // if this pane has a resizer bar, move it NOW - before animation + setAsClosed(pane); + + // CLOSE THE PANE + if (doFX) { // animate the close + lockPaneForFX(pane, true); // need to set left/top so animation will work + $P.hide( o.fxName_close, o.fxSettings_close, o.fxSpeed_close, function () { + lockPaneForFX(pane, false); // undo + if (s.isClosed) close_2(); + queueNext(); + }); + } + else { // hide the pane without animation + _hidePane(pane); + close_2(); + queueNext(); + }; + }); + + // SUBROUTINE + function close_2 () { + s.isMoving = false; + bindStartSlidingEvents(pane, true); // will enable if o.slidable = true + + // if opposite-pane was autoClosed, see if it can be autoOpened now + var altPane = _c.oppositeEdge[pane]; + if (state[ altPane ].noRoom) { + setSizeLimits( altPane ); + makePaneFit( altPane ); + } + + if (!skipCallback && (state.initialized || o.triggerEventsOnLoad)) { + // onclose callback - UNLESS just 'showing' a hidden pane as 'closed' + if (!isShowing) _runCallbacks("onclose_end", pane); + // onhide OR onshow callback + if (isShowing) _runCallbacks("onshow_end", pane); + if (isHiding) _runCallbacks("onhide_end", pane); + } + } + } + + /** + * @param {string} pane The pane just closed, ie: north, south, east, or west + */ +, setAsClosed = function (pane) { + if (!$Rs[pane]) return; // handles not initialized yet! + var + $P = $Ps[pane] + , $R = $Rs[pane] + , $T = $Ts[pane] + , o = options[pane] + , s = state[pane] + , side = _c[pane].side + , rClass = o.resizerClass + , tClass = o.togglerClass + , _pane = "-"+ pane // used for classNames + , _open = "-open" + , _sliding= "-sliding" + , _closed = "-closed" + ; + $R + .css(side, sC.inset[side]) // move the resizer + .removeClass( rClass+_open +" "+ rClass+_pane+_open ) + .removeClass( rClass+_sliding +" "+ rClass+_pane+_sliding ) + .addClass( rClass+_closed +" "+ rClass+_pane+_closed ) + ; + // handle already-hidden panes in case called by swap() or a similar method + if (s.isHidden) $R.hide(); // hide resizer-bar + + // DISABLE 'resizing' when closed - do this BEFORE bindStartSlidingEvents? + if (o.resizable && $.layout.plugins.draggable) + $R + .draggable("disable") + .removeClass("ui-state-disabled") // do NOT apply disabled styling - not suitable here + .css("cursor", "default") + .attr("title","") + ; + + // if pane has a toggler button, adjust that too + if ($T) { + $T + .removeClass( tClass+_open +" "+ tClass+_pane+_open ) + .addClass( tClass+_closed +" "+ tClass+_pane+_closed ) + .attr("title", o.tips.Open) // may be blank + ; + // toggler-content - if exists + $T.children(".content-open").hide(); + $T.children(".content-closed").css("display","block"); + } + + // sync any 'pin buttons' + syncPinBtns(pane, false); + + if (state.initialized) { + // resize 'length' and position togglers for adjacent panes + sizeHandles(); + } + } + + /** + * Open the specified pane (animation optional), and resize all other panes as needed + * + * @param {(string|Object)} evt_or_pane The pane being opened, ie: north, south, east, or west + * @param {boolean=} [slide=false] + * @param {boolean=} [noAnimation=false] + * @param {boolean=} [noAlert=false] + */ +, open = function (evt_or_pane, slide, noAnimation, noAlert) { + if (!isInitialized()) return; + var pane = evtPane.call(this, evt_or_pane) + , $P = $Ps[pane] + , $R = $Rs[pane] + , $T = $Ts[pane] + , o = options[pane] + , s = state[pane] + , c = _c[pane] + , doFX, isShowing + ; + if (pane === "center") return; // validate + // QUEUE in case another action/animation is in progress + $N.queue(function( queueNext ){ + + if ( !$P + || (!o.resizable && !o.closable && !s.isShowing) // invalid request + || (s.isVisible && !s.isSliding) // already open + ) return queueNext(); + + // pane can ALSO be unhidden by just calling show(), so handle this scenario + if (s.isHidden && !s.isShowing) { + queueNext(); // call before show() because it needs the queue free + show(pane, true); + return; + } + + if (s.autoResize && s.size != o.size) // resize pane to original size set in options + sizePane(pane, o.size, true, true, true); // true=skipCallback/noAnimation/forceResize + else + // make sure there is enough space available to open the pane + setSizeLimits(pane, slide); + + // onopen_start callback - will CANCEL open if returns false + var cbReturn = _runCallbacks("onopen_start", pane); + + if (cbReturn === "abort") + return queueNext(); + + // update pane-state again in case options were changed in onopen_start + if (cbReturn !== "NC") // NC = "No Callback" + setSizeLimits(pane, slide); + + if (s.minSize > s.maxSize) { // INSUFFICIENT ROOM FOR PANE TO OPEN! + syncPinBtns(pane, false); // make sure pin-buttons are reset + if (!noAlert && o.tips.noRoomToOpen) + alert(o.tips.noRoomToOpen); + return queueNext(); // ABORT + } + + if (slide) // START Sliding - will set isSliding=true + bindStopSlidingEvents(pane, true); // BIND trigger events to close sliding-pane + else if (s.isSliding) // PIN PANE (stop sliding) - open pane 'normally' instead + bindStopSlidingEvents(pane, false); // UNBIND trigger events - will set isSliding=false + else if (o.slidable) + bindStartSlidingEvents(pane, false); // UNBIND trigger events + + s.noRoom = false; // will be reset by makePaneFit if 'noRoom' + makePaneFit(pane); + + // transfer logic var to temp var + isShowing = s.isShowing; + // now clear the logic var + delete s.isShowing; + + doFX = !noAnimation && s.isClosed && (o.fxName_open != "none"); + s.isMoving = true; + s.isVisible = true; + s.isClosed = false; + // update isHidden BEFORE sizing panes - WHY??? Old? + if (isShowing) s.isHidden = false; + + if (doFX) { // ANIMATE + // mask adjacent panes with objects + lockPaneForFX(pane, true); // need to set left/top so animation will work + $P.show( o.fxName_open, o.fxSettings_open, o.fxSpeed_open, function() { + lockPaneForFX(pane, false); // undo + if (s.isVisible) open_2(); // continue + queueNext(); + }); + } + else { // no animation + _showPane(pane);// just show pane and... + open_2(); // continue + queueNext(); + }; + }); + + // SUBROUTINE + function open_2 () { + s.isMoving = false; + + // cure iframe display issues + _fixIframe(pane); + + // NOTE: if isSliding, then other panes are NOT 'resized' + if (!s.isSliding) { // resize all panes adjacent to this one + sizeMidPanes(_c[pane].dir=="vert" ? "center" : "", false); // false = NOT skipCallback + } + + // set classes, position handles and execute callbacks... + setAsOpen(pane); + }; + + } + + /** + * @param {string} pane The pane just opened, ie: north, south, east, or west + * @param {boolean=} [skipCallback=false] + */ +, setAsOpen = function (pane, skipCallback) { + var + $P = $Ps[pane] + , $R = $Rs[pane] + , $T = $Ts[pane] + , o = options[pane] + , s = state[pane] + , side = _c[pane].side + , rClass = o.resizerClass + , tClass = o.togglerClass + , _pane = "-"+ pane // used for classNames + , _open = "-open" + , _closed = "-closed" + , _sliding= "-sliding" + ; + $R + .css(side, sC.inset[side] + getPaneSize(pane)) // move the resizer + .removeClass( rClass+_closed +" "+ rClass+_pane+_closed ) + .addClass( rClass+_open +" "+ rClass+_pane+_open ) + ; + if (s.isSliding) + $R.addClass( rClass+_sliding +" "+ rClass+_pane+_sliding ) + else // in case 'was sliding' + $R.removeClass( rClass+_sliding +" "+ rClass+_pane+_sliding ) + + removeHover( 0, $R ); // remove hover classes + if (o.resizable && $.layout.plugins.draggable) + $R .draggable("enable") + .css("cursor", o.resizerCursor) + .attr("title", o.tips.Resize); + else if (!s.isSliding) + $R.css("cursor", "default"); // n-resize, s-resize, etc + + // if pane also has a toggler button, adjust that too + if ($T) { + $T .removeClass( tClass+_closed +" "+ tClass+_pane+_closed ) + .addClass( tClass+_open +" "+ tClass+_pane+_open ) + .attr("title", o.tips.Close); // may be blank + removeHover( 0, $T ); // remove hover classes + // toggler-content - if exists + $T.children(".content-closed").hide(); + $T.children(".content-open").css("display","block"); + } + + // sync any 'pin buttons' + syncPinBtns(pane, !s.isSliding); + + // update pane-state dimensions - BEFORE resizing content + $.extend(s, elDims($P)); + + if (state.initialized) { + // resize resizer & toggler sizes for all panes + sizeHandles(); + // resize content every time pane opens - to be sure + sizeContent(pane, true); // true = remeasure headers/footers, even if 'pane.isMoving' + } + + if (!skipCallback && (state.initialized || o.triggerEventsOnLoad) && $P.is(":visible")) { + // onopen callback + _runCallbacks("onopen_end", pane); + // onshow callback - TODO: should this be here? + if (s.isShowing) _runCallbacks("onshow_end", pane); + + // ALSO call onresize because layout-size *may* have changed while pane was closed + if (state.initialized) + _runCallbacks("onresize_end", pane); + } + + // TODO: Somehow sizePane("north") is being called after this point??? + } + + + /** + * slideOpen / slideClose / slideToggle + * + * Pass-though methods for sliding + */ +, slideOpen = function (evt_or_pane) { + if (!isInitialized()) return; + var evt = evtObj(evt_or_pane) + , pane = evtPane.call(this, evt_or_pane) + , s = state[pane] + , delay = options[pane].slideDelay_open + ; + if (pane === "center") return; // validate + // prevent event from triggering on NEW resizer binding created below + if (evt) evt.stopImmediatePropagation(); + + if (s.isClosed && evt && evt.type === "mouseenter" && delay > 0) + // trigger = mouseenter - use a delay + timer.set(pane+"_openSlider", open_NOW, delay); + else + open_NOW(); // will unbind events if is already open + + /** + * SUBROUTINE for timed open + */ + function open_NOW () { + if (!s.isClosed) // skip if no longer closed! + bindStopSlidingEvents(pane, true); // BIND trigger events to close sliding-pane + else if (!s.isMoving) + open(pane, true); // true = slide - open() will handle binding + }; + } + +, slideClose = function (evt_or_pane) { + if (!isInitialized()) return; + var evt = evtObj(evt_or_pane) + , pane = evtPane.call(this, evt_or_pane) + , o = options[pane] + , s = state[pane] + , delay = s.isMoving ? 1000 : 300 // MINIMUM delay - option may override + ; + if (pane === "center") return; // validate + if (s.isClosed || s.isResizing) + return; // skip if already closed OR in process of resizing + else if (o.slideTrigger_close === "click") + close_NOW(); // close immediately onClick + else if (o.preventQuickSlideClose && s.isMoving) + return; // handle Chrome quick-close on slide-open + else if (o.preventPrematureSlideClose && evt && $.layout.isMouseOverElem(evt, $Ps[pane])) + return; // handle incorrect mouseleave trigger, like when over a SELECT-list in IE + else if (evt) // trigger = mouseleave - use a delay + // 1 sec delay if 'opening', else .3 sec + timer.set(pane+"_closeSlider", close_NOW, max(o.slideDelay_close, delay)); + else // called programically + close_NOW(); + + /** + * SUBROUTINE for timed close + */ + function close_NOW () { + if (s.isClosed) // skip 'close' if already closed! + bindStopSlidingEvents(pane, false); // UNBIND trigger events - TODO: is this needed here? + else if (!s.isMoving) + close(pane); // close will handle unbinding + }; + } + + /** + * @param {(string|Object)} evt_or_pane The pane being opened, ie: north, south, east, or west + */ +, slideToggle = function (evt_or_pane) { + var pane = evtPane.call(this, evt_or_pane); + toggle(pane, true); + } + + + /** + * Must set left/top on East/South panes so animation will work properly + * + * @param {string} pane The pane to lock, 'east' or 'south' - any other is ignored! + * @param {boolean} doLock true = set left/top, false = remove + */ +, lockPaneForFX = function (pane, doLock) { + var $P = $Ps[pane] + , s = state[pane] + , o = options[pane] + , z = options.zIndexes + ; + if (doLock) { + showMasks( pane, { animation: true, objectsOnly: true }); + $P.css({ zIndex: z.pane_animate }); // overlay all elements during animation + if (pane=="south") + $P.css({ top: sC.inset.top + sC.innerHeight - $P.outerHeight() }); + else if (pane=="east") + $P.css({ left: sC.inset.left + sC.innerWidth - $P.outerWidth() }); + } + else { // animation DONE - RESET CSS + hideMasks(); + $P.css({ zIndex: (s.isSliding ? z.pane_sliding : z.pane_normal) }); + if (pane=="south") + $P.css({ top: "auto" }); + // if pane is positioned 'off-screen', then DO NOT screw with it! + else if (pane=="east" && !$P.css("left").match(/\-99999/)) + $P.css({ left: "auto" }); + // fix anti-aliasing in IE - only needed for animations that change opacity + if (browser.msie && o.fxOpacityFix && o.fxName_open != "slide" && $P.css("filter") && $P.css("opacity") == 1) + $P[0].style.removeAttribute('filter'); + } + } + + + /** + * Toggle sliding functionality of a specific pane on/off by adding removing 'slide open' trigger + * + * @see open(), close() + * @param {string} pane The pane to enable/disable, 'north', 'south', etc. + * @param {boolean} enable Enable or Disable sliding? + */ +, bindStartSlidingEvents = function (pane, enable) { + var o = options[pane] + , $P = $Ps[pane] + , $R = $Rs[pane] + , evtName = o.slideTrigger_open.toLowerCase() + ; + if (!$R || (enable && !o.slidable)) return; + + // make sure we have a valid event + if (evtName.match(/mouseover/)) + evtName = o.slideTrigger_open = "mouseenter"; + else if (!evtName.match(/(click|dblclick|mouseenter)/)) + evtName = o.slideTrigger_open = "click"; + + // must remove double-click-toggle when using dblclick-slide + if (o.resizerDblClickToggle && evtName.match(/click/)) { + $R[enable ? "unbind" : "bind"]('dblclick.'+ sID, toggle) + } + + $R + // add or remove event + [enable ? "bind" : "unbind"](evtName +'.'+ sID, slideOpen) + // set the appropriate cursor & title/tip + .css("cursor", enable ? o.sliderCursor : "default") + .attr("title", enable ? o.tips.Slide : "") + ; + } + + /** + * Add or remove 'mouseleave' events to 'slide close' when pane is 'sliding' open or closed + * Also increases zIndex when pane is sliding open + * See bindStartSlidingEvents for code to control 'slide open' + * + * @see slideOpen(), slideClose() + * @param {string} pane The pane to process, 'north', 'south', etc. + * @param {boolean} enable Enable or Disable events? + */ +, bindStopSlidingEvents = function (pane, enable) { + var o = options[pane] + , s = state[pane] + , c = _c[pane] + , z = options.zIndexes + , evtName = o.slideTrigger_close.toLowerCase() + , action = (enable ? "bind" : "unbind") + , $P = $Ps[pane] + , $R = $Rs[pane] + ; + timer.clear(pane+"_closeSlider"); // just in case + + if (enable) { + s.isSliding = true; + state.panesSliding[pane] = true; + // remove 'slideOpen' event from resizer + // ALSO will raise the zIndex of the pane & resizer + bindStartSlidingEvents(pane, false); + } + else { + s.isSliding = false; + delete state.panesSliding[pane]; + } + + // RE/SET zIndex - increases when pane is sliding-open, resets to normal when not + $P.css("zIndex", enable ? z.pane_sliding : z.pane_normal); + $R.css("zIndex", enable ? z.pane_sliding+2 : z.resizer_normal); // NOTE: mask = pane_sliding+1 + + // make sure we have a valid event + if (!evtName.match(/(click|mouseleave)/)) + evtName = o.slideTrigger_close = "mouseleave"; // also catches 'mouseout' + + // add/remove slide triggers + $R[action](evtName, slideClose); // base event on resize + // need extra events for mouseleave + if (evtName === "mouseleave") { + // also close on pane.mouseleave + $P[action]("mouseleave."+ sID, slideClose); + // cancel timer when mouse moves between 'pane' and 'resizer' + $R[action]("mouseenter."+ sID, cancelMouseOut); + $P[action]("mouseenter."+ sID, cancelMouseOut); + } + + if (!enable) + timer.clear(pane+"_closeSlider"); + else if (evtName === "click" && !o.resizable) { + // IF pane is not resizable (which already has a cursor and tip) + // then set the a cursor & title/tip on resizer when sliding + $R.css("cursor", enable ? o.sliderCursor : "default"); + $R.attr("title", enable ? o.tips.Close : ""); // use Toggler-tip, eg: "Close Pane" + } + + // SUBROUTINE for mouseleave timer clearing + function cancelMouseOut (evt) { + timer.clear(pane+"_closeSlider"); + evt.stopPropagation(); + } + } + + + /** + * Hides/closes a pane if there is insufficient room - reverses this when there is room again + * MUST have already called setSizeLimits() before calling this method + * + * @param {string} pane The pane being resized + * @param {boolean=} [isOpening=false] Called from onOpen? + * @param {boolean=} [skipCallback=false] Should the onresize callback be run? + * @param {boolean=} [force=false] + */ +, makePaneFit = function (pane, isOpening, skipCallback, force) { + var o = options[pane] + , s = state[pane] + , c = _c[pane] + , $P = $Ps[pane] + , $R = $Rs[pane] + , isSidePane = c.dir==="vert" + , hasRoom = false + ; + // special handling for center & east/west panes + if (pane === "center" || (isSidePane && s.noVerticalRoom)) { + // see if there is enough room to display the pane + // ERROR: hasRoom = s.minHeight <= s.maxHeight && (isSidePane || s.minWidth <= s.maxWidth); + hasRoom = (s.maxHeight >= 0); + if (hasRoom && s.noRoom) { // previously hidden due to noRoom, so show now + _showPane(pane); + if ($R) $R.show(); + s.isVisible = true; + s.noRoom = false; + if (isSidePane) s.noVerticalRoom = false; + _fixIframe(pane); + } + else if (!hasRoom && !s.noRoom) { // not currently hidden, so hide now + _hidePane(pane); + if ($R) $R.hide(); + s.isVisible = false; + s.noRoom = true; + } + } + + // see if there is enough room to fit the border-pane + if (pane === "center") { + // ignore center in this block + } + else if (s.minSize <= s.maxSize) { // pane CAN fit + hasRoom = true; + if (s.size > s.maxSize) // pane is too big - shrink it + sizePane(pane, s.maxSize, skipCallback, true, force); // true = noAnimation + else if (s.size < s.minSize) // pane is too small - enlarge it + sizePane(pane, s.minSize, skipCallback, true, force); // true = noAnimation + // need s.isVisible because new pseudoClose method keeps pane visible, but off-screen + else if ($R && s.isVisible && $P.is(":visible")) { + // make sure resizer-bar is positioned correctly + // handles situation where nested layout was 'hidden' when initialized + var pos = s.size + sC.inset[c.side]; + if ($.layout.cssNum( $R, c.side ) != pos) $R.css( c.side, pos ); + } + + // if was previously hidden due to noRoom, then RESET because NOW there is room + if (s.noRoom) { + // s.noRoom state will be set by open or show + if (s.wasOpen && o.closable) { + if (o.autoReopen) + open(pane, false, true, true); // true = noAnimation, true = noAlert + else // leave the pane closed, so just update state + s.noRoom = false; + } + else + show(pane, s.wasOpen, true, true); // true = noAnimation, true = noAlert + } + } + else { // !hasRoom - pane CANNOT fit + if (!s.noRoom) { // pane not set as noRoom yet, so hide or close it now... + s.noRoom = true; // update state + s.wasOpen = !s.isClosed && !s.isSliding; + if (s.isClosed){} // SKIP + else if (o.closable) // 'close' if possible + close(pane, true, true); // true = force, true = noAnimation + else // 'hide' pane if cannot just be closed + hide(pane, true); // true = noAnimation + } + } + } + + + /** + * manualSizePane is an exposed flow-through method allowing extra code when pane is 'manually resized' + * + * @param {(string|Object)} evt_or_pane The pane being resized + * @param {number} size The *desired* new size for this pane - will be validated + * @param {boolean=} [skipCallback=false] Should the onresize callback be run? + * @param {boolean=} [noAnimation=false] + * @param {boolean=} [force=false] Force resizing even if does not seem necessary + */ +, manualSizePane = function (evt_or_pane, size, skipCallback, noAnimation, force) { + if (!isInitialized()) return; + var pane = evtPane.call(this, evt_or_pane) + , o = options[pane] + , s = state[pane] + // if resizing callbacks have been delayed and resizing is now DONE, force resizing to complete... + , forceResize = force || (o.livePaneResizing && !s.isResizing) + ; + if (pane === "center") return; // validate + // ANY call to manualSizePane disables autoResize - ie, percentage sizing + s.autoResize = false; + // flow-through... + sizePane(pane, size, skipCallback, noAnimation, forceResize); // will animate resize if option enabled + } + + /** + * sizePane is called only by internal methods whenever a pane needs to be resized + * + * @param {(string|Object)} evt_or_pane The pane being resized + * @param {number} size The *desired* new size for this pane - will be validated + * @param {boolean=} [skipCallback=false] Should the onresize callback be run? + * @param {boolean=} [noAnimation=false] + * @param {boolean=} [force=false] Force resizing even if does not seem necessary + */ +, sizePane = function (evt_or_pane, size, skipCallback, noAnimation, force) { + if (!isInitialized()) return; + var pane = evtPane.call(this, evt_or_pane) // probably NEVER called from event? + , o = options[pane] + , s = state[pane] + , $P = $Ps[pane] + , $R = $Rs[pane] + , side = _c[pane].side + , dimName = _c[pane].sizeType.toLowerCase() + , skipResizeWhileDragging = s.isResizing && !o.triggerEventsDuringLiveResize + , doFX = noAnimation !== true && o.animatePaneSizing + , oldSize, newSize + ; + if (pane === "center") return; // validate + // QUEUE in case another action/animation is in progress + $N.queue(function( queueNext ){ + // calculate 'current' min/max sizes + setSizeLimits(pane); // update pane-state + oldSize = s.size; + size = _parseSize(pane, size); // handle percentages & auto + size = max(size, _parseSize(pane, o.minSize)); + size = min(size, s.maxSize); + if (size < s.minSize) { // not enough room for pane! + queueNext(); // call before makePaneFit() because it needs the queue free + makePaneFit(pane, false, skipCallback); // will hide or close pane + return; + } + + // IF newSize is same as oldSize, then nothing to do - abort + if (!force && size === oldSize) + return queueNext(); + + s.newSize = size; + + // onresize_start callback CANNOT cancel resizing because this would break the layout! + if (!skipCallback && state.initialized && s.isVisible) + _runCallbacks("onresize_start", pane); + + // resize the pane, and make sure its visible + newSize = cssSize(pane, size); + + if (doFX && $P.is(":visible")) { // ANIMATE + var fx = $.layout.effects.size[pane] || $.layout.effects.size.all + , easing = o.fxSettings_size.easing || fx.easing + , z = options.zIndexes + , props = {}; + props[ dimName ] = newSize +'px'; + s.isMoving = true; + // overlay all elements during animation + $P.css({ zIndex: z.pane_animate }) + .show().animate( props, o.fxSpeed_size, easing, function(){ + // reset zIndex after animation + $P.css({ zIndex: (s.isSliding ? z.pane_sliding : z.pane_normal) }); + s.isMoving = false; + delete s.newSize; + sizePane_2(); // continue + queueNext(); + }); + } + else { // no animation + $P.css( dimName, newSize ); // resize pane + delete s.newSize; + // if pane is visible, then + if ($P.is(":visible")) + sizePane_2(); // continue + else { + // pane is NOT VISIBLE, so just update state data... + // when pane is *next opened*, it will have the new size + s.size = size; // update state.size + //$.extend(s, elDims($P)); // update state dimensions - CANNOT do this when not visible! } + } + queueNext(); + }; + + }); + + // SUBROUTINE + function sizePane_2 () { + /* Panes are sometimes not sized precisely in some browsers!? + * This code will resize the pane up to 3 times to nudge the pane to the correct size + */ + var actual = dimName==='width' ? $P.outerWidth() : $P.outerHeight() + , tries = [{ + pane: pane + , count: 1 + , target: size + , actual: actual + , correct: (size === actual) + , attempt: size + , cssSize: newSize + }] + , lastTry = tries[0] + , thisTry = {} + , msg = 'Inaccurate size after resizing the '+ pane +'-pane.' + ; + while ( !lastTry.correct ) { + thisTry = { pane: pane, count: lastTry.count+1, target: size }; + + if (lastTry.actual > size) + thisTry.attempt = max(0, lastTry.attempt - (lastTry.actual - size)); + else // lastTry.actual < size + thisTry.attempt = max(0, lastTry.attempt + (size - lastTry.actual)); + + thisTry.cssSize = cssSize(pane, thisTry.attempt); + $P.css( dimName, thisTry.cssSize ); + + thisTry.actual = dimName=='width' ? $P.outerWidth() : $P.outerHeight(); + thisTry.correct = (size === thisTry.actual); + + // log attempts and alert the user of this *non-fatal error* (if showDebugMessages) + if ( tries.length === 1) { + _log(msg, false, true); + _log(lastTry, false, true); + } + _log(thisTry, false, true); + // after 4 tries, is as close as its gonna get! + if (tries.length > 3) break; + + tries.push( thisTry ); + lastTry = tries[ tries.length - 1 ]; + } + // END TESTING CODE + + // update pane-state dimensions + s.size = size; + $.extend(s, elDims($P)); + + if (s.isVisible && $P.is(":visible")) { + // reposition the resizer-bar + if ($R) $R.css( side, size + sC.inset[side] ); + // resize the content-div + sizeContent(pane); + } + + if (!skipCallback && !skipResizeWhileDragging && state.initialized && s.isVisible) + _runCallbacks("onresize_end", pane); + + // resize all the adjacent panes, and adjust their toggler buttons + // when skipCallback passed, it means the controlling method will handle 'other panes' + if (!skipCallback) { + // also no callback if live-resize is in progress and NOT triggerEventsDuringLiveResize + if (!s.isSliding) sizeMidPanes(_c[pane].dir=="horz" ? "" : "center", skipResizeWhileDragging, force); + sizeHandles(); + } + + // if opposite-pane was autoClosed, see if it can be autoOpened now + var altPane = _c.oppositeEdge[pane]; + if (size < oldSize && state[ altPane ].noRoom) { + setSizeLimits( altPane ); + makePaneFit( altPane, false, skipCallback ); + } + + // DEBUG - ALERT user/developer so they know there was a sizing problem + if (tries.length > 1) + _log(msg +'\nSee the Error Console for details.', true, true); + } + } + + /** + * @see initPanes(), sizePane(), resizeAll(), open(), close(), hide() + * @param {(Array.|string)} panes The pane(s) being resized, comma-delmited string + * @param {boolean=} [skipCallback=false] Should the onresize callback be run? + * @param {boolean=} [force=false] + */ +, sizeMidPanes = function (panes, skipCallback, force) { + panes = (panes ? panes : "east,west,center").split(","); + + $.each(panes, function (i, pane) { + if (!$Ps[pane]) return; // NO PANE - skip + var + o = options[pane] + , s = state[pane] + , $P = $Ps[pane] + , $R = $Rs[pane] + , isCenter= (pane=="center") + , hasRoom = true + , CSS = {} + // if pane is not visible, show it invisibly NOW rather than for *each call* in this script + , visCSS = $.layout.showInvisibly($P) + + , newCenter = calcNewCenterPaneDims() + ; + + // update pane-state dimensions + $.extend(s, elDims($P)); + + if (pane === "center") { + if (!force && s.isVisible && newCenter.width === s.outerWidth && newCenter.height === s.outerHeight) { + $P.css(visCSS); + return true; // SKIP - pane already the correct size + } + // set state for makePaneFit() logic + $.extend(s, cssMinDims(pane), { + maxWidth: newCenter.width + , maxHeight: newCenter.height + }); + CSS = newCenter; + s.newWidth = CSS.width; + s.newHeight = CSS.height; + // convert OUTER width/height to CSS width/height + CSS.width = cssW($P, CSS.width); + // NEW - allow pane to extend 'below' visible area rather than hide it + CSS.height = cssH($P, CSS.height); + hasRoom = CSS.width >= 0 && CSS.height >= 0; // height >= 0 = ALWAYS TRUE NOW + + // during layout init, try to shrink east/west panes to make room for center + if (!state.initialized && o.minWidth > newCenter.width) { + var + reqPx = o.minWidth - s.outerWidth + , minE = options.east.minSize || 0 + , minW = options.west.minSize || 0 + , sizeE = state.east.size + , sizeW = state.west.size + , newE = sizeE + , newW = sizeW + ; + if (reqPx > 0 && state.east.isVisible && sizeE > minE) { + newE = max( sizeE-minE, sizeE-reqPx ); + reqPx -= sizeE-newE; + } + if (reqPx > 0 && state.west.isVisible && sizeW > minW) { + newW = max( sizeW-minW, sizeW-reqPx ); + reqPx -= sizeW-newW; + } + // IF we found enough extra space, then resize the border panes as calculated + if (reqPx === 0) { + if (sizeE && sizeE != minE) + sizePane('east', newE, true, true, force); // true = skipCallback/noAnimation - initPanes will handle when done + if (sizeW && sizeW != minW) + sizePane('west', newW, true, true, force); // true = skipCallback/noAnimation + // now start over! + sizeMidPanes('center', skipCallback, force); + $P.css(visCSS); + return; // abort this loop + } + } + } + else { // for east and west, set only the height, which is same as center height + // set state.min/maxWidth/Height for makePaneFit() logic + if (s.isVisible && !s.noVerticalRoom) + $.extend(s, elDims($P), cssMinDims(pane)) + if (!force && !s.noVerticalRoom && newCenter.height === s.outerHeight) { + $P.css(visCSS); + return true; // SKIP - pane already the correct size + } + // east/west have same top, bottom & height as center + CSS.top = newCenter.top; + CSS.bottom = newCenter.bottom; + s.newSize = newCenter.height + // NEW - allow pane to extend 'below' visible area rather than hide it + CSS.height = cssH($P, newCenter.height); + s.maxHeight = CSS.height; + hasRoom = (s.maxHeight >= 0); // ALWAYS TRUE NOW + if (!hasRoom) s.noVerticalRoom = true; // makePaneFit() logic + } + + if (hasRoom) { + // resizeAll passes skipCallback because it triggers callbacks after ALL panes are resized + if (!skipCallback && state.initialized) + _runCallbacks("onresize_start", pane); + + $P.css(CSS); // apply the CSS to pane + if (pane !== "center") + sizeHandles(pane); // also update resizer length + if (s.noRoom && !s.isClosed && !s.isHidden) + makePaneFit(pane); // will re-open/show auto-closed/hidden pane + if (s.isVisible) { + $.extend(s, elDims($P)); // update pane dimensions + if (state.initialized) sizeContent(pane); // also resize the contents, if exists + } + } + else if (!s.noRoom && s.isVisible) // no room for pane + makePaneFit(pane); // will hide or close pane + + // reset visibility, if necessary + $P.css(visCSS); + + delete s.newSize; + delete s.newWidth; + delete s.newHeight; + + if (!s.isVisible) + return true; // DONE - next pane + + /* + * Extra CSS for IE6 or IE7 in Quirks-mode - add 'width' to NORTH/SOUTH panes + * Normally these panes have only 'left' & 'right' positions so pane auto-sizes + * ALSO required when pane is an IFRAME because will NOT default to 'full width' + * TODO: Can I use width:100% for a north/south iframe? + * TODO: Sounds like a job for $P.outerWidth( sC.innerWidth ) SETTER METHOD + */ + if (pane === "center") { // finished processing midPanes + var fix = browser.isIE6 || !browser.boxModel; + if ($Ps.north && (fix || state.north.tagName=="IFRAME")) + $Ps.north.css("width", cssW($Ps.north, sC.innerWidth)); + if ($Ps.south && (fix || state.south.tagName=="IFRAME")) + $Ps.south.css("width", cssW($Ps.south, sC.innerWidth)); + } + + // resizeAll passes skipCallback because it triggers callbacks after ALL panes are resized + if (!skipCallback && state.initialized) + _runCallbacks("onresize_end", pane); + }); + } + + + /** + * @see window.onresize(), callbacks or custom code + * @param {(Object|boolean)=} evt_or_refresh If 'true', then also reset pane-positioning + */ +, resizeAll = function (evt_or_refresh) { + var oldW = sC.innerWidth + , oldH = sC.innerHeight + ; + // stopPropagation if called by trigger("layoutdestroy") - use evtPane utility + evtPane(evt_or_refresh); + + // cannot size layout when 'container' is hidden or collapsed + if (!$N.is(":visible")) return; + + if (!state.initialized) { + _initLayoutElements(); + return; // no need to resize since we just initialized! + } + + if (evt_or_refresh === true && $.isPlainObject(options.outset)) { + // update container CSS in case outset option has changed + $N.css( options.outset ); + } + // UPDATE container dimensions + $.extend(sC, elDims( $N, options.inset )); + if (!sC.outerHeight) return; + + // if 'true' passed, refresh pane & handle positioning too + if (evt_or_refresh === true) { + setPanePosition(); + } + + // onresizeall_start will CANCEL resizing if returns false + // state.container has already been set, so user can access this info for calcuations + if (false === _runCallbacks("onresizeall_start")) return false; + + var // see if container is now 'smaller' than before + shrunkH = (sC.innerHeight < oldH) + , shrunkW = (sC.innerWidth < oldW) + , $P, o, s + ; + // NOTE special order for sizing: S-N-E-W + $.each(["south","north","east","west"], function (i, pane) { + if (!$Ps[pane]) return; // no pane - SKIP + o = options[pane]; + s = state[pane]; + if (s.autoResize && s.size != o.size) // resize pane to original size set in options + sizePane(pane, o.size, true, true, true); // true=skipCallback/noAnimation/forceResize + else { + setSizeLimits(pane); + makePaneFit(pane, false, true, true); // true=skipCallback/forceResize + } + }); + + sizeMidPanes("", true, true); // true=skipCallback/forceResize + sizeHandles(); // reposition the toggler elements + + // trigger all individual pane callbacks AFTER layout has finished resizing + $.each(_c.allPanes, function (i, pane) { + $P = $Ps[pane]; + if (!$P) return; // SKIP + if (state[pane].isVisible) // undefined for non-existent panes + _runCallbacks("onresize_end", pane); // callback - if exists + }); + + _runCallbacks("onresizeall_end"); + //_triggerLayoutEvent(pane, 'resizeall'); + } + + /** + * Whenever a pane resizes or opens that has a nested layout, trigger resizeAll + * + * @param {(string|Object)} evt_or_pane The pane just resized or opened + */ +, resizeChildren = function (evt_or_pane, skipRefresh) { + var pane = evtPane.call(this, evt_or_pane); + + if (!options[pane].resizeChildren) return; + + // ensure the pane-children are up-to-date + if (!skipRefresh) refreshChildren( pane ); + var pC = children[pane]; + if ($.isPlainObject( pC )) { + // resize one or more children + $.each( pC, function (key, child) { + if (!child.destroyed) child.resizeAll(); + }); + } + } + + /** + * IF pane has a content-div, then resize all elements inside pane to fit pane-height + * + * @param {(string|Object)} evt_or_panes The pane(s) being resized + * @param {boolean=} [remeasure=false] Should the content (header/footer) be remeasured? + */ +, sizeContent = function (evt_or_panes, remeasure) { + if (!isInitialized()) return; + + var panes = evtPane.call(this, evt_or_panes); + panes = panes ? panes.split(",") : _c.allPanes; + + $.each(panes, function (idx, pane) { + var + $P = $Ps[pane] + , $C = $Cs[pane] + , o = options[pane] + , s = state[pane] + , m = s.content // m = measurements + ; + if (!$P || !$C || !$P.is(":visible")) return true; // NOT VISIBLE - skip + + // if content-element was REMOVED, update OR remove the pointer + if (!$C.length) { + initContent(pane, false); // false = do NOT sizeContent() - already there! + if (!$C) return; // no replacement element found - pointer have been removed + } + + // onsizecontent_start will CANCEL resizing if returns false + if (false === _runCallbacks("onsizecontent_start", pane)) return; + + // skip re-measuring offsets if live-resizing + if ((!s.isMoving && !s.isResizing) || o.liveContentResizing || remeasure || m.top == undefined) { + _measure(); + // if any footers are below pane-bottom, they may not measure correctly, + // so allow pane overflow and re-measure + if (m.hiddenFooters > 0 && $P.css("overflow") === "hidden") { + $P.css("overflow", "visible"); + _measure(); // remeasure while overflowing + $P.css("overflow", "hidden"); + } + } + // NOTE: spaceAbove/Below *includes* the pane paddingTop/Bottom, but not pane.borders + var newH = s.innerHeight - (m.spaceAbove - s.css.paddingTop) - (m.spaceBelow - s.css.paddingBottom); + + if (!$C.is(":visible") || m.height != newH) { + // size the Content element to fit new pane-size - will autoHide if not enough room + setOuterHeight($C, newH, true); // true=autoHide + m.height = newH; // save new height + }; + + if (state.initialized) + _runCallbacks("onsizecontent_end", pane); + + function _below ($E) { + return max(s.css.paddingBottom, (parseInt($E.css("marginBottom"), 10) || 0)); + }; + + function _measure () { + var + ignore = options[pane].contentIgnoreSelector + , $Fs = $C.nextAll().not(".ui-layout-mask").not(ignore || ":lt(0)") // not :lt(0) = ALL + , $Fs_vis = $Fs.filter(':visible') + , $F = $Fs_vis.filter(':last') + ; + m = { + top: $C[0].offsetTop + , height: $C.outerHeight() + , numFooters: $Fs.length + , hiddenFooters: $Fs.length - $Fs_vis.length + , spaceBelow: 0 // correct if no content footer ($E) + } + m.spaceAbove = m.top; // just for state - not used in calc + m.bottom = m.top + m.height; + if ($F.length) + //spaceBelow = (LastFooter.top + LastFooter.height) [footerBottom] - Content.bottom + max(LastFooter.marginBottom, pane.paddingBotom) + m.spaceBelow = ($F[0].offsetTop + $F.outerHeight()) - m.bottom + _below($F); + else // no footer - check marginBottom on Content element itself + m.spaceBelow = _below($C); + }; + }); + } + + + /** + * Called every time a pane is opened, closed, or resized to slide the togglers to 'center' and adjust their length if necessary + * + * @see initHandles(), open(), close(), resizeAll() + * @param {(string|Object)=} evt_or_panes The pane(s) being resized + */ +, sizeHandles = function (evt_or_panes) { + var panes = evtPane.call(this, evt_or_panes) + panes = panes ? panes.split(",") : _c.borderPanes; + + $.each(panes, function (i, pane) { + var + o = options[pane] + , s = state[pane] + , $P = $Ps[pane] + , $R = $Rs[pane] + , $T = $Ts[pane] + , $TC + ; + if (!$P || !$R) return; + + var + dir = _c[pane].dir + , _state = (s.isClosed ? "_closed" : "_open") + , spacing = o["spacing"+ _state] + , togAlign = o["togglerAlign"+ _state] + , togLen = o["togglerLength"+ _state] + , paneLen + , left + , offset + , CSS = {} + ; + + if (spacing === 0) { + $R.hide(); + return; + } + else if (!s.noRoom && !s.isHidden) // skip if resizer was hidden for any reason + $R.show(); // in case was previously hidden + + // Resizer Bar is ALWAYS same width/height of pane it is attached to + if (dir === "horz") { // north/south + //paneLen = $P.outerWidth(); // s.outerWidth || + paneLen = sC.innerWidth; // handle offscreen-panes + s.resizerLength = paneLen; + left = $.layout.cssNum($P, "left") + $R.css({ + width: cssW($R, paneLen) // account for borders & padding + , height: cssH($R, spacing) // ditto + , left: left > -9999 ? left : sC.inset.left // handle offscreen-panes + }); + } + else { // east/west + paneLen = $P.outerHeight(); // s.outerHeight || + s.resizerLength = paneLen; + $R.css({ + height: cssH($R, paneLen) // account for borders & padding + , width: cssW($R, spacing) // ditto + , top: sC.inset.top + getPaneSize("north", true) // TODO: what if no North pane? + //, top: $.layout.cssNum($Ps["center"], "top") + }); + } + + // remove hover classes + removeHover( o, $R ); + + if ($T) { + if (togLen === 0 || (s.isSliding && o.hideTogglerOnSlide)) { + $T.hide(); // always HIDE the toggler when 'sliding' + return; + } + else + $T.show(); // in case was previously hidden + + if (!(togLen > 0) || togLen === "100%" || togLen > paneLen) { + togLen = paneLen; + offset = 0; + } + else { // calculate 'offset' based on options.PANE.togglerAlign_open/closed + if (isStr(togAlign)) { + switch (togAlign) { + case "top": + case "left": offset = 0; + break; + case "bottom": + case "right": offset = paneLen - togLen; + break; + case "middle": + case "center": + default: offset = round((paneLen - togLen) / 2); // 'default' catches typos + } + } + else { // togAlign = number + var x = parseInt(togAlign, 10); // + if (togAlign >= 0) offset = x; + else offset = paneLen - togLen + x; // NOTE: x is negative! + } + } + + if (dir === "horz") { // north/south + var width = cssW($T, togLen); + $T.css({ + width: width // account for borders & padding + , height: cssH($T, spacing) // ditto + , left: offset // TODO: VERIFY that toggler positions correctly for ALL values + , top: 0 + }); + // CENTER the toggler content SPAN + $T.children(".content").each(function(){ + $TC = $(this); + $TC.css("marginLeft", round((width-$TC.outerWidth())/2)); // could be negative + }); + } + else { // east/west + var height = cssH($T, togLen); + $T.css({ + height: height // account for borders & padding + , width: cssW($T, spacing) // ditto + , top: offset // POSITION the toggler + , left: 0 + }); + // CENTER the toggler content SPAN + $T.children(".content").each(function(){ + $TC = $(this); + $TC.css("marginTop", round((height-$TC.outerHeight())/2)); // could be negative + }); + } + + // remove ALL hover classes + removeHover( 0, $T ); + } + + // DONE measuring and sizing this resizer/toggler, so can be 'hidden' now + if (!state.initialized && (o.initHidden || s.isHidden)) { + $R.hide(); + if ($T) $T.hide(); + } + }); + } + + + /** + * @param {(string|Object)} evt_or_pane + */ +, enableClosable = function (evt_or_pane) { + if (!isInitialized()) return; + var pane = evtPane.call(this, evt_or_pane) + , $T = $Ts[pane] + , o = options[pane] + ; + if (!$T) return; + o.closable = true; + $T .bind("click."+ sID, function(evt){ evt.stopPropagation(); toggle(pane); }) + .css("visibility", "visible") + .css("cursor", "pointer") + .attr("title", state[pane].isClosed ? o.tips.Open : o.tips.Close) // may be blank + .show(); + } + /** + * @param {(string|Object)} evt_or_pane + * @param {boolean=} [hide=false] + */ +, disableClosable = function (evt_or_pane, hide) { + if (!isInitialized()) return; + var pane = evtPane.call(this, evt_or_pane) + , $T = $Ts[pane] + ; + if (!$T) return; + options[pane].closable = false; + // is closable is disable, then pane MUST be open! + if (state[pane].isClosed) open(pane, false, true); + $T .unbind("."+ sID) + .css("visibility", hide ? "hidden" : "visible") // instead of hide(), which creates logic issues + .css("cursor", "default") + .attr("title", ""); + } + + + /** + * @param {(string|Object)} evt_or_pane + */ +, enableSlidable = function (evt_or_pane) { + if (!isInitialized()) return; + var pane = evtPane.call(this, evt_or_pane) + , $R = $Rs[pane] + ; + if (!$R || !$R.data('draggable')) return; + options[pane].slidable = true; + if (state[pane].isClosed) + bindStartSlidingEvents(pane, true); + } + /** + * @param {(string|Object)} evt_or_pane + */ +, disableSlidable = function (evt_or_pane) { + if (!isInitialized()) return; + var pane = evtPane.call(this, evt_or_pane) + , $R = $Rs[pane] + ; + if (!$R) return; + options[pane].slidable = false; + if (state[pane].isSliding) + close(pane, false, true); + else { + bindStartSlidingEvents(pane, false); + $R .css("cursor", "default") + .attr("title", ""); + removeHover(null, $R[0]); // in case currently hovered + } + } + + + /** + * @param {(string|Object)} evt_or_pane + */ +, enableResizable = function (evt_or_pane) { + if (!isInitialized()) return; + var pane = evtPane.call(this, evt_or_pane) + , $R = $Rs[pane] + , o = options[pane] + ; + if (!$R || !$R.data('draggable')) return; + o.resizable = true; + $R.draggable("enable"); + if (!state[pane].isClosed) + $R .css("cursor", o.resizerCursor) + .attr("title", o.tips.Resize); + } + /** + * @param {(string|Object)} evt_or_pane + */ +, disableResizable = function (evt_or_pane) { + if (!isInitialized()) return; + var pane = evtPane.call(this, evt_or_pane) + , $R = $Rs[pane] + ; + if (!$R || !$R.data('draggable')) return; + options[pane].resizable = false; + $R .draggable("disable") + .css("cursor", "default") + .attr("title", ""); + removeHover(null, $R[0]); // in case currently hovered + } + + + /** + * Move a pane from source-side (eg, west) to target-side (eg, east) + * If pane exists on target-side, move that to source-side, ie, 'swap' the panes + * + * @param {(string|Object)} evt_or_pane1 The pane/edge being swapped + * @param {string} pane2 ditto + */ +, swapPanes = function (evt_or_pane1, pane2) { + if (!isInitialized()) return; + var pane1 = evtPane.call(this, evt_or_pane1); + // change state.edge NOW so callbacks can know where pane is headed... + state[pane1].edge = pane2; + state[pane2].edge = pane1; + // run these even if NOT state.initialized + if (false === _runCallbacks("onswap_start", pane1) + || false === _runCallbacks("onswap_start", pane2) + ) { + state[pane1].edge = pane1; // reset + state[pane2].edge = pane2; + return; + } + + var + oPane1 = copy( pane1 ) + , oPane2 = copy( pane2 ) + , sizes = {} + ; + sizes[pane1] = oPane1 ? oPane1.state.size : 0; + sizes[pane2] = oPane2 ? oPane2.state.size : 0; + + // clear pointers & state + $Ps[pane1] = false; + $Ps[pane2] = false; + state[pane1] = {}; + state[pane2] = {}; + + // ALWAYS remove the resizer & toggler elements + if ($Ts[pane1]) $Ts[pane1].remove(); + if ($Ts[pane2]) $Ts[pane2].remove(); + if ($Rs[pane1]) $Rs[pane1].remove(); + if ($Rs[pane2]) $Rs[pane2].remove(); + $Rs[pane1] = $Rs[pane2] = $Ts[pane1] = $Ts[pane2] = false; + + // transfer element pointers and data to NEW Layout keys + move( oPane1, pane2 ); + move( oPane2, pane1 ); + + // cleanup objects + oPane1 = oPane2 = sizes = null; + + // make panes 'visible' again + if ($Ps[pane1]) $Ps[pane1].css(_c.visible); + if ($Ps[pane2]) $Ps[pane2].css(_c.visible); + + // fix any size discrepancies caused by swap + resizeAll(); + + // run these even if NOT state.initialized + _runCallbacks("onswap_end", pane1); + _runCallbacks("onswap_end", pane2); + + return; + + function copy (n) { // n = pane + var + $P = $Ps[n] + , $C = $Cs[n] + ; + return !$P ? false : { + pane: n + , P: $P ? $P[0] : false + , C: $C ? $C[0] : false + , state: $.extend(true, {}, state[n]) + , options: $.extend(true, {}, options[n]) + } + }; + + function move (oPane, pane) { + if (!oPane) return; + var + P = oPane.P + , C = oPane.C + , oldPane = oPane.pane + , c = _c[pane] + // save pane-options that should be retained + , s = $.extend(true, {}, state[pane]) + , o = options[pane] + // RETAIN side-specific FX Settings - more below + , fx = { resizerCursor: o.resizerCursor } + , re, size, pos + ; + $.each("fxName,fxSpeed,fxSettings".split(","), function (i, k) { + fx[k +"_open"] = o[k +"_open"]; + fx[k +"_close"] = o[k +"_close"]; + fx[k +"_size"] = o[k +"_size"]; + }); + + // update object pointers and attributes + $Ps[pane] = $(P) + .data({ + layoutPane: Instance[pane] // NEW pointer to pane-alias-object + , layoutEdge: pane + }) + .css(_c.hidden) + .css(c.cssReq) + ; + $Cs[pane] = C ? $(C) : false; + + // set options and state + options[pane] = $.extend(true, {}, oPane.options, fx); + state[pane] = $.extend(true, {}, oPane.state); + + // change classNames on the pane, eg: ui-layout-pane-east ==> ui-layout-pane-west + re = new RegExp(o.paneClass +"-"+ oldPane, "g"); + P.className = P.className.replace(re, o.paneClass +"-"+ pane); + + // ALWAYS regenerate the resizer & toggler elements + initHandles(pane); // create the required resizer & toggler + + // if moving to different orientation, then keep 'target' pane size + if (c.dir != _c[oldPane].dir) { + size = sizes[pane] || 0; + setSizeLimits(pane); // update pane-state + size = max(size, state[pane].minSize); + // use manualSizePane to disable autoResize - not useful after panes are swapped + manualSizePane(pane, size, true, true); // true/true = skipCallback/noAnimation + } + else // move the resizer here + $Rs[pane].css(c.side, sC.inset[c.side] + (state[pane].isVisible ? getPaneSize(pane) : 0)); + + + // ADD CLASSNAMES & SLIDE-BINDINGS + if (oPane.state.isVisible && !s.isVisible) + setAsOpen(pane, true); // true = skipCallback + else { + setAsClosed(pane); + bindStartSlidingEvents(pane, true); // will enable events IF option is set + } + + // DESTROY the object + oPane = null; + }; + } + + + /** + * INTERNAL method to sync pin-buttons when pane is opened or closed + * Unpinned means the pane is 'sliding' - ie, over-top of the adjacent panes + * + * @see open(), setAsOpen(), setAsClosed() + * @param {string} pane These are the params returned to callbacks by layout() + * @param {boolean} doPin True means set the pin 'down', False means 'up' + */ +, syncPinBtns = function (pane, doPin) { + if ($.layout.plugins.buttons) + $.each(state[pane].pins, function (i, selector) { + $.layout.buttons.setPinState(Instance, $(selector), pane, doPin); + }); + } + +; // END var DECLARATIONS + + /** + * Capture keys when enableCursorHotkey - toggle pane if hotkey pressed + * + * @see document.keydown() + */ + function keyDown (evt) { + if (!evt) return true; + var code = evt.keyCode; + if (code < 33) return true; // ignore special keys: ENTER, TAB, etc + + var + PANE = { + 38: "north" // Up Cursor - $.ui.keyCode.UP + , 40: "south" // Down Cursor - $.ui.keyCode.DOWN + , 37: "west" // Left Cursor - $.ui.keyCode.LEFT + , 39: "east" // Right Cursor - $.ui.keyCode.RIGHT + } + , ALT = evt.altKey // no worky! + , SHIFT = evt.shiftKey + , CTRL = evt.ctrlKey + , CURSOR = (CTRL && code >= 37 && code <= 40) + , o, k, m, pane + ; + + if (CURSOR && options[PANE[code]].enableCursorHotkey) // valid cursor-hotkey + pane = PANE[code]; + else if (CTRL || SHIFT) // check to see if this matches a custom-hotkey + $.each(_c.borderPanes, function (i, p) { // loop each pane to check its hotkey + o = options[p]; + k = o.customHotkey; + m = o.customHotkeyModifier; // if missing or invalid, treated as "CTRL+SHIFT" + if ((SHIFT && m=="SHIFT") || (CTRL && m=="CTRL") || (CTRL && SHIFT)) { // Modifier matches + if (k && code === (isNaN(k) || k <= 9 ? k.toUpperCase().charCodeAt(0) : k)) { // Key matches + pane = p; + return false; // BREAK + } + } + }); + + // validate pane + if (!pane || !$Ps[pane] || !options[pane].closable || state[pane].isHidden) + return true; + + toggle(pane); + + evt.stopPropagation(); + evt.returnValue = false; // CANCEL key + return false; + }; + + +/* + * ###################################### + * UTILITY METHODS + * called externally or by initButtons + * ###################################### + */ + + /** + * Change/reset a pane overflow setting & zIndex to allow popups/drop-downs to work + * + * @param {Object=} [el] (optional) Can also be 'bound' to a click, mouseOver, or other event + */ + function allowOverflow (el) { + if (!isInitialized()) return; + if (this && this.tagName) el = this; // BOUND to element + var $P; + if (isStr(el)) + $P = $Ps[el]; + else if ($(el).data("layoutRole")) + $P = $(el); + else + $(el).parents().each(function(){ + if ($(this).data("layoutRole")) { + $P = $(this); + return false; // BREAK + } + }); + if (!$P || !$P.length) return; // INVALID + + var + pane = $P.data("layoutEdge") + , s = state[pane] + ; + + // if pane is already raised, then reset it before doing it again! + // this would happen if allowOverflow is attached to BOTH the pane and an element + if (s.cssSaved) + resetOverflow(pane); // reset previous CSS before continuing + + // if pane is raised by sliding or resizing, or its closed, then abort + if (s.isSliding || s.isResizing || s.isClosed) { + s.cssSaved = false; + return; + } + + var + newCSS = { zIndex: (options.zIndexes.resizer_normal + 1) } + , curCSS = {} + , of = $P.css("overflow") + , ofX = $P.css("overflowX") + , ofY = $P.css("overflowY") + ; + // determine which, if any, overflow settings need to be changed + if (of != "visible") { + curCSS.overflow = of; + newCSS.overflow = "visible"; + } + if (ofX && !ofX.match(/(visible|auto)/)) { + curCSS.overflowX = ofX; + newCSS.overflowX = "visible"; + } + if (ofY && !ofY.match(/(visible|auto)/)) { + curCSS.overflowY = ofX; + newCSS.overflowY = "visible"; + } + + // save the current overflow settings - even if blank! + s.cssSaved = curCSS; + + // apply new CSS to raise zIndex and, if necessary, make overflow 'visible' + $P.css( newCSS ); + + // make sure the zIndex of all other panes is normal + $.each(_c.allPanes, function(i, p) { + if (p != pane) resetOverflow(p); + }); + + }; + /** + * @param {Object=} [el] (optional) Can also be 'bound' to a click, mouseOver, or other event + */ + function resetOverflow (el) { + if (!isInitialized()) return; + if (this && this.tagName) el = this; // BOUND to element + var $P; + if (isStr(el)) + $P = $Ps[el]; + else if ($(el).data("layoutRole")) + $P = $(el); + else + $(el).parents().each(function(){ + if ($(this).data("layoutRole")) { + $P = $(this); + return false; // BREAK + } + }); + if (!$P || !$P.length) return; // INVALID + + var + pane = $P.data("layoutEdge") + , s = state[pane] + , CSS = s.cssSaved || {} + ; + // reset the zIndex + if (!s.isSliding && !s.isResizing) + $P.css("zIndex", options.zIndexes.pane_normal); + + // reset Overflow - if necessary + $P.css( CSS ); + + // clear var + s.cssSaved = false; + }; + +/* + * ##################### + * CREATE/RETURN LAYOUT + * ##################### + */ + + // validate that container exists + var $N = $(this).eq(0); // FIRST matching Container element + if (!$N.length) { + return _log( options.errors.containerMissing ); + }; + + // Users retrieve Instance of a layout with: $N.layout() OR $N.data("layout") + // return the Instance-pointer if layout has already been initialized + if ($N.data("layoutContainer") && $N.data("layout")) + return $N.data("layout"); // cached pointer + + // init global vars + var + $Ps = {} // Panes x5 - set in initPanes() + , $Cs = {} // Content x5 - set in initPanes() + , $Rs = {} // Resizers x4 - set in initHandles() + , $Ts = {} // Togglers x4 - set in initHandles() + , $Ms = $([]) // Masks - up to 2 masks per pane (IFRAME + DIV) + // aliases for code brevity + , sC = state.container // alias for easy access to 'container dimensions' + , sID = state.id // alias for unique layout ID/namespace - eg: "layout435" + ; + + // create Instance object to expose data & option Properties, and primary action Methods + var Instance = { + // layout data + options: options // property - options hash + , state: state // property - dimensions hash + // object pointers + , container: $N // property - object pointers for layout container + , panes: $Ps // property - object pointers for ALL Panes: panes.north, panes.center + , contents: $Cs // property - object pointers for ALL Content: contents.north, contents.center + , resizers: $Rs // property - object pointers for ALL Resizers, eg: resizers.north + , togglers: $Ts // property - object pointers for ALL Togglers, eg: togglers.north + // border-pane open/close + , hide: hide // method - ditto + , show: show // method - ditto + , toggle: toggle // method - pass a 'pane' ("north", "west", etc) + , open: open // method - ditto + , close: close // method - ditto + , slideOpen: slideOpen // method - ditto + , slideClose: slideClose // method - ditto + , slideToggle: slideToggle // method - ditto + // pane actions + , setSizeLimits: setSizeLimits // method - pass a 'pane' - update state min/max data + , _sizePane: sizePane // method -intended for user by plugins only! + , sizePane: manualSizePane // method - pass a 'pane' AND an 'outer-size' in pixels or percent, or 'auto' + , sizeContent: sizeContent // method - pass a 'pane' + , swapPanes: swapPanes // method - pass TWO 'panes' - will swap them + , showMasks: showMasks // method - pass a 'pane' OR list of panes - default = all panes with mask option set + , hideMasks: hideMasks // method - ditto' + // pane element methods + , initContent: initContent // method - ditto + , addPane: addPane // method - pass a 'pane' + , removePane: removePane // method - pass a 'pane' to remove from layout, add 'true' to delete the pane-elem + , createChildren: createChildren // method - pass a 'pane' and (optional) layout-options (OVERRIDES options[pane].children + , refreshChildren: refreshChildren // method - pass a 'pane' and a layout-instance + // special pane option setting + , enableClosable: enableClosable // method - pass a 'pane' + , disableClosable: disableClosable // method - ditto + , enableSlidable: enableSlidable // method - ditto + , disableSlidable: disableSlidable // method - ditto + , enableResizable: enableResizable // method - ditto + , disableResizable: disableResizable// method - ditto + // utility methods for panes + , allowOverflow: allowOverflow // utility - pass calling element (this) + , resetOverflow: resetOverflow // utility - ditto + // layout control + , destroy: destroy // method - no parameters + , initPanes: isInitialized // method - no parameters + , resizeAll: resizeAll // method - no parameters + // callback triggering + , runCallbacks: _runCallbacks // method - pass evtName & pane (if a pane-event), eg: trigger("onopen", "west") + // alias collections of options, state and children - created in addPane and extended elsewhere + , hasParentLayout: false // set by initContainer() + , children: children // pointers to child-layouts, eg: Instance.children.west.layoutName + , north: false // alias group: { name: pane, pane: $Ps[pane], options: options[pane], state: state[pane], children: children[pane] } + , south: false // ditto + , west: false // ditto + , east: false // ditto + , center: false // ditto + }; + + // create the border layout NOW + if (_create() === 'cancel') // onload_start callback returned false to CANCEL layout creation + return null; + else // true OR false -- if layout-elements did NOT init (hidden or do not exist), can auto-init later + return Instance; // return the Instance object + +} + + +})( jQuery ); + + + + +/** + * jquery.layout.state 1.2 + * $Date: 2015/03/13 22:37:04 $ + * + * Copyright (c) 2014 + * Kevin Dalman (http://allpro.net) + * + * Dual licensed under the GPL (http://www.gnu.org/licenses/gpl.html) + * and MIT (http://www.opensource.org/licenses/mit-license.php) licenses. + * + * @requires: UI Layout 1.4.0 or higher + * @requires: $.ui.cookie (above) + * + * @see: http://groups.google.com/group/jquery-ui-layout + */ +;(function ($) { + +if (!$.layout) return; + + +/** + * UI COOKIE UTILITY + * + * A $.cookie OR $.ui.cookie namespace *should be standard*, but until then... + * This creates $.ui.cookie so Layout does not need the cookie.jquery.js plugin + * NOTE: This utility is REQUIRED by the layout.state plugin + * + * Cookie methods in Layout are created as part of State Management + */ +if (!$.ui) $.ui = {}; +$.ui.cookie = { + + // cookieEnabled is not in DOM specs, but DOES works in all browsers,including IE6 + acceptsCookies: !!navigator.cookieEnabled + +, read: function (name) { + var + c = document.cookie + , cs = c ? c.split(';') : [] + , pair, data, i + ; + for (i=0; pair=cs[i]; i++) { + data = $.trim(pair).split('='); // name=value => [ name, value ] + if (data[0] == name) // found the layout cookie + return decodeURIComponent(data[1]); + } + return null; + } + +, write: function (name, val, cookieOpts) { + var params = "" + , date = "" + , clear = false + , o = cookieOpts || {} + , x = o.expires || null + , t = $.type(x) + ; + if (t === "date") + date = x; + else if (t === "string" && x > 0) { + x = parseInt(x,10); + t = "number"; + } + if (t === "number") { + date = new Date(); + if (x > 0) + date.setDate(date.getDate() + x); + else { + date.setFullYear(1970); + clear = true; + } + } + if (date) params += ";expires="+ date.toUTCString(); + if (o.path) params += ";path="+ o.path; + if (o.domain) params += ";domain="+ o.domain; + if (o.secure) params += ";secure"; + document.cookie = name +"="+ (clear ? "" : encodeURIComponent( val )) + params; // write or clear cookie + } + +, clear: function (name) { + $.ui.cookie.write(name, "", {expires: -1}); + } + +}; +// if cookie.jquery.js is not loaded, create an alias to replicate it +// this may be useful to other plugins or code dependent on that plugin +if (!$.cookie) $.cookie = function (k, v, o) { + var C = $.ui.cookie; + if (v === null) + C.clear(k); + else if (v === undefined) + return C.read(k); + else + C.write(k, v, o); +}; + + + +/** + * State-management options stored in options.stateManagement, which includes a .cookie hash + * Default options saves ALL KEYS for ALL PANES, ie: pane.size, pane.isClosed, pane.isHidden + * + * // STATE/COOKIE OPTIONS + * @example $(el).layout({ + stateManagement: { + enabled: true + , stateKeys: "east.size,west.size,east.isClosed,west.isClosed" + , cookie: { name: "appLayout", path: "/" } + } + }) + * @example $(el).layout({ stateManagement__enabled: true }) // enable auto-state-management using cookies + * @example $(el).layout({ stateManagement__cookie: { name: "appLayout", path: "/" } }) + * @example $(el).layout({ stateManagement__cookie__name: "appLayout", stateManagement__cookie__path: "/" }) + * + * // STATE/COOKIE METHODS + * @example myLayout.saveCookie( "west.isClosed,north.size,south.isHidden", {expires: 7} ); + * @example myLayout.loadCookie(); + * @example myLayout.deleteCookie(); + * @example var JSON = myLayout.readState(); // CURRENT Layout State + * @example var JSON = myLayout.readCookie(); // SAVED Layout State (from cookie) + * @example var JSON = myLayout.state.stateData; // LAST LOADED Layout State (cookie saved in layout.state hash) + * + * CUSTOM STATE-MANAGEMENT (eg, saved in a database) + * @example var JSON = myLayout.readState( "west.isClosed,north.size,south.isHidden" ); + * @example myLayout.loadState( JSON ); + */ + +// tell Layout that the state plugin is available +$.layout.plugins.stateManagement = true; + +// Add State-Management options to layout.defaults +$.layout.defaults.stateManagement = { + enabled: false // true = enable state-management, even if not using cookies +, autoSave: true // Save a state-cookie when page exits? +, autoLoad: true // Load the state-cookie when Layout inits? +, animateLoad: true // animate panes when loading state into an active layout +, includeChildren: true // recurse into child layouts to include their state as well + // List state-data to save - must be pane-specific +, stateKeys: "north.size,south.size,east.size,west.size,"+ + "north.isClosed,south.isClosed,east.isClosed,west.isClosed,"+ + "north.isHidden,south.isHidden,east.isHidden,west.isHidden" +, cookie: { + name: "" // If not specified, will use Layout.name, else just "Layout" + , domain: "" // blank = current domain + , path: "" // blank = current page, "/" = entire website + , expires: "" // 'days' to keep cookie - leave blank for 'session cookie' + , secure: false + } +}; + +// Set stateManagement as a 'layout-option', NOT a 'pane-option' +$.layout.optionsMap.layout.push("stateManagement"); +// Update config so layout does not move options into the pane-default branch (panes) +$.layout.config.optionRootKeys.push("stateManagement"); + +/* + * State Management methods + */ +$.layout.state = { + + /** + * Get the current layout state and save it to a cookie + * + * myLayout.saveCookie( keys, cookieOpts ) + * + * @param {Object} inst + * @param {(string|Array)=} keys + * @param {Object=} cookieOpts + */ + saveCookie: function (inst, keys, cookieOpts) { + var o = inst.options + , sm = o.stateManagement + , oC = $.extend(true, {}, sm.cookie, cookieOpts || null) + , data = inst.state.stateData = inst.readState( keys || sm.stateKeys ) // read current panes-state + ; + $.ui.cookie.write( oC.name || o.name || "Layout", $.layout.state.encodeJSON(data), oC ); + return $.extend(true, {}, data); // return COPY of state.stateData data + } + + /** + * Remove the state cookie + * + * @param {Object} inst + */ +, deleteCookie: function (inst) { + var o = inst.options; + $.ui.cookie.clear( o.stateManagement.cookie.name || o.name || "Layout" ); + } + + /** + * Read & return data from the cookie - as JSON + * + * @param {Object} inst + */ +, readCookie: function (inst) { + var o = inst.options; + var c = $.ui.cookie.read( o.stateManagement.cookie.name || o.name || "Layout" ); + // convert cookie string back to a hash and return it + return c ? $.layout.state.decodeJSON(c) : {}; + } + + /** + * Get data from the cookie and USE IT to loadState + * + * @param {Object} inst + */ +, loadCookie: function (inst) { + var c = $.layout.state.readCookie(inst); // READ the cookie + if (c && !$.isEmptyObject( c )) { + inst.state.stateData = $.extend(true, {}, c); // SET state.stateData + inst.loadState(c); // LOAD the retrieved state + } + return c; + } + + /** + * Update layout options from the cookie, if one exists + * + * @param {Object} inst + * @param {Object=} stateData + * @param {boolean=} animate + */ +, loadState: function (inst, data, opts) { + if (!$.isPlainObject( data ) || $.isEmptyObject( data )) return; + + // normalize data & cache in the state object + data = inst.state.stateData = $.layout.transformData( data ); // panes = default subkey + + // add missing/default state-restore options + var smo = inst.options.stateManagement; + opts = $.extend({ + animateLoad: false //smo.animateLoad + , includeChildren: smo.includeChildren + }, opts ); + + if (!inst.state.initialized) { + /* + * layout NOT initialized, so just update its options + */ + // MUST remove pane.children keys before applying to options + // use a copy so we don't remove keys from original data + var o = $.extend(true, {}, data); + //delete o.center; // center has no state-data - only children + $.each($.layout.config.allPanes, function (idx, pane) { + if (o[pane]) delete o[pane].children; + }); + // update CURRENT layout-options with saved state data + $.extend(true, inst.options, o); + } + else { + /* + * layout already initialized, so modify layout's configuration + */ + var noAnimate = !opts.animateLoad + , o, c, h, state, open + ; + $.each($.layout.config.borderPanes, function (idx, pane) { + o = data[ pane ]; + if (!$.isPlainObject( o )) return; // no key, skip pane + + s = o.size; + c = o.initClosed; + h = o.initHidden; + ar = o.autoResize + state = inst.state[pane]; + open = state.isVisible; + + // reset autoResize + if (ar) + state.autoResize = ar; + // resize BEFORE opening + if (!open) + inst._sizePane(pane, s, false, false, false); // false=skipCallback/noAnimation/forceResize + // open/close as necessary - DO NOT CHANGE THIS ORDER! + if (h === true) inst.hide(pane, noAnimate); + else if (c === true) inst.close(pane, false, noAnimate); + else if (c === false) inst.open (pane, false, noAnimate); + else if (h === false) inst.show (pane, false, noAnimate); + // resize AFTER any other actions + if (open) + inst._sizePane(pane, s, false, false, noAnimate); // animate resize if option passed + }); + + /* + * RECURSE INTO CHILD-LAYOUTS + */ + if (opts.includeChildren) { + var paneStateChildren, childState; + $.each(inst.children, function (pane, paneChildren) { + paneStateChildren = data[pane] ? data[pane].children : 0; + if (paneStateChildren && paneChildren) { + $.each(paneChildren, function (stateKey, child) { + childState = paneStateChildren[stateKey]; + if (child && childState) + child.loadState( childState ); + }); + } + }); + } + } + } + + /** + * Get the *current layout state* and return it as a hash + * + * @param {Object=} inst // Layout instance to get state for + * @param {object=} [opts] // State-Managements override options + */ +, readState: function (inst, opts) { + // backward compatility + if ($.type(opts) === 'string') opts = { keys: opts }; + if (!opts) opts = {}; + var sm = inst.options.stateManagement + , ic = opts.includeChildren + , recurse = ic !== undefined ? ic : sm.includeChildren + , keys = opts.stateKeys || sm.stateKeys + , alt = { isClosed: 'initClosed', isHidden: 'initHidden' } + , state = inst.state + , panes = $.layout.config.allPanes + , data = {} + , pair, pane, key, val + , ps, pC, child, array, count, branch + ; + if ($.isArray(keys)) keys = keys.join(","); + // convert keys to an array and change delimiters from '__' to '.' + keys = keys.replace(/__/g, ".").split(','); + // loop keys and create a data hash + for (var i=0, n=keys.length; i < n; i++) { + pair = keys[i].split("."); + pane = pair[0]; + key = pair[1]; + if ($.inArray(pane, panes) < 0) continue; // bad pane! + val = state[ pane ][ key ]; + if (val == undefined) continue; + if (key=="isClosed" && state[pane]["isSliding"]) + val = true; // if sliding, then *really* isClosed + ( data[pane] || (data[pane]={}) )[ alt[key] ? alt[key] : key ] = val; + } + + // recurse into the child-layouts for each pane + if (recurse) { + $.each(panes, function (idx, pane) { + pC = inst.children[pane]; + ps = state.stateData[pane]; + if ($.isPlainObject( pC ) && !$.isEmptyObject( pC )) { + // ensure a key exists for this 'pane', eg: branch = data.center + branch = data[pane] || (data[pane] = {}); + if (!branch.children) branch.children = {}; + $.each( pC, function (key, child) { + // ONLY read state from an initialize layout + if ( child.state.initialized ) + branch.children[ key ] = $.layout.state.readState( child ); + // if we have PREVIOUS (onLoad) state for this child-layout, KEEP IT! + else if ( ps && ps.children && ps.children[ key ] ) { + branch.children[ key ] = $.extend(true, {}, ps.children[ key ] ); + } + }); + } + }); + } + + return data; + } + + /** + * Stringify a JSON hash so can save in a cookie or db-field + */ +, encodeJSON: function (json) { + var local = window.JSON || {}; + return (local.stringify || stringify)(json); + + function stringify (h) { + var D=[], i=0, k, v, t // k = key, v = value + , a = $.isArray(h) + ; + for (k in h) { + v = h[k]; + t = typeof v; + if (t == 'string') // STRING - add quotes + v = '"'+ v +'"'; + else if (t == 'object') // SUB-KEY - recurse into it + v = parse(v); + D[i++] = (!a ? '"'+ k +'":' : '') + v; + } + return (a ? '[' : '{') + D.join(',') + (a ? ']' : '}'); + }; + } + + /** + * Convert stringified JSON back to a hash object + * @see $.parseJSON(), adding in jQuery 1.4.1 + */ +, decodeJSON: function (str) { + try { return $.parseJSON ? $.parseJSON(str) : window["eval"]("("+ str +")") || {}; } + catch (e) { return {}; } + } + + +, _create: function (inst) { + var s = $.layout.state + , o = inst.options + , sm = o.stateManagement + ; + // ADD State-Management plugin methods to inst + $.extend( inst, { + // readCookie - update options from cookie - returns hash of cookie data + readCookie: function () { return s.readCookie(inst); } + // deleteCookie + , deleteCookie: function () { s.deleteCookie(inst); } + // saveCookie - optionally pass keys-list and cookie-options (hash) + , saveCookie: function (keys, cookieOpts) { return s.saveCookie(inst, keys, cookieOpts); } + // loadCookie - readCookie and use to loadState() - returns hash of cookie data + , loadCookie: function () { return s.loadCookie(inst); } + // loadState - pass a hash of state to use to update options + , loadState: function (stateData, opts) { s.loadState(inst, stateData, opts); } + // readState - returns hash of current layout-state + , readState: function (keys) { return s.readState(inst, keys); } + // add JSON utility methods too... + , encodeJSON: s.encodeJSON + , decodeJSON: s.decodeJSON + }); + + // init state.stateData key, even if plugin is initially disabled + inst.state.stateData = {}; + + // autoLoad MUST BE one of: data-array, data-hash, callback-function, or TRUE + if ( !sm.autoLoad ) return; + + // When state-data exists in the autoLoad key USE IT, + // even if stateManagement.enabled == false + if ($.isPlainObject( sm.autoLoad )) { + if (!$.isEmptyObject( sm.autoLoad )) { + inst.loadState( sm.autoLoad ); + } + } + else if ( sm.enabled ) { + // update the options from cookie or callback + // if options is a function, call it to get stateData + if ($.isFunction( sm.autoLoad )) { + var d = {}; + try { + d = sm.autoLoad( inst, inst.state, inst.options, inst.options.name || '' ); // try to get data from fn + } catch (e) {} + if (d && $.isPlainObject( d ) && !$.isEmptyObject( d )) + inst.loadState(d); + } + else // any other truthy value will trigger loadCookie + inst.loadCookie(); + } + } + +, _unload: function (inst) { + var sm = inst.options.stateManagement; + if (sm.enabled && sm.autoSave) { + // if options is a function, call it to save the stateData + if ($.isFunction( sm.autoSave )) { + try { + sm.autoSave( inst, inst.state, inst.options, inst.options.name || '' ); // try to get data from fn + } catch (e) {} + } + else // any truthy value will trigger saveCookie + inst.saveCookie(); + } + } + +}; + +// add state initialization method to Layout's onCreate array of functions +$.layout.onCreate.push( $.layout.state._create ); +$.layout.onUnload.push( $.layout.state._unload ); + +})( jQuery ); + + + +/** + * @preserve jquery.layout.buttons 1.0 + * $Date: 2015/03/13 22:37:04 $ + * + * Copyright (c) 2011 + * Kevin Dalman (http://allpro.net) + * + * Dual licensed under the GPL (http://www.gnu.org/licenses/gpl.html) + * and MIT (http://www.opensource.org/licenses/mit-license.php) licenses. + * + * @dependancies: UI Layout 1.3.0.rc30.1 or higher + * + * @support: http://groups.google.com/group/jquery-ui-layout + * + * Docs: [ to come ] + * Tips: [ to come ] + */ +;(function ($) { + +if (!$.layout) return; + + +// tell Layout that the state plugin is available +$.layout.plugins.buttons = true; + +// Add State-Management options to layout.defaults +$.layout.defaults.autoBindCustomButtons = false; +// Set stateManagement as a layout-option, NOT a pane-option +$.layout.optionsMap.layout.push("autoBindCustomButtons"); + +var lang = $.layout.language; + +/* + * Button methods + */ +$.layout.buttons = { + // set data used by multiple methods below + config: { + borderPanes: "north,south,west,east" + } + + /** + * Searches for .ui-layout-button-xxx elements and auto-binds them as layout-buttons + * + * @see _create() + */ +, init: function (inst) { + var pre = "ui-layout-button-" + , layout = inst.options.name || "" + , name; + $.each("toggle,open,close,pin,toggle-slide,open-slide".split(","), function (i, action) { + $.each($.layout.buttons.config.borderPanes.split(","), function (ii, pane) { + $("."+pre+action+"-"+pane).each(function(){ + // if button was previously 'bound', data.layoutName was set, but is blank if layout has no 'name' + name = $(this).data("layoutName") || $(this).attr("layoutName"); + if (name == undefined || name === layout) + inst.bindButton(this, action, pane); + }); + }); + }); + } + + /** + * Helper function to validate params received by addButton utilities + * + * Two classes are added to the element, based on the buttonClass... + * The type of button is appended to create the 2nd className: + * - ui-layout-button-pin + * - ui-layout-pane-button-toggle + * - ui-layout-pane-button-open + * - ui-layout-pane-button-close + * + * @param {(string|!Object)} selector jQuery selector (or element) for button, eg: ".ui-layout-north .toggle-button" + * @param {string} pane Name of the pane the button is for: 'north', 'south', etc. + * @return {Array.} If both params valid, the element matching 'selector' in a jQuery wrapper - otherwise returns null + */ +, get: function (inst, selector, pane, action) { + var $E = $(selector) + , o = inst.options + , err = o.showErrorMessages + ; + if (!$E.length) { // element not found + if (err) alert(lang.errButton + lang.selector +": "+ selector); + } + else if ($.layout.buttons.config.borderPanes.indexOf(pane) === -1) { // invalid 'pane' sepecified + if (err) alert(lang.errButton + lang.pane +": "+ pane); + $E = $(""); // NO BUTTON + } + else { // VALID + var btn = o[pane].buttonClass +"-"+ action; + $E .addClass( btn +" "+ btn +"-"+ pane ) + .data("layoutName", o.name); // add layout identifier - even if blank! + } + return $E; + } + + + /** + * NEW syntax for binding layout-buttons - will eventually replace addToggle, addOpen, etc. + * + * @param {(string|!Object)} sel jQuery selector (or element) for button, eg: ".ui-layout-north .toggle-button" + * @param {string} action + * @param {string} pane + */ +, bind: function (inst, sel, action, pane) { + var _ = $.layout.buttons; + switch (action.toLowerCase()) { + case "toggle": _.addToggle (inst, sel, pane); break; + case "open": _.addOpen (inst, sel, pane); break; + case "close": _.addClose (inst, sel, pane); break; + case "pin": _.addPin (inst, sel, pane); break; + case "toggle-slide": _.addToggle (inst, sel, pane, true); break; + case "open-slide": _.addOpen (inst, sel, pane, true); break; + } + return inst; + } + + /** + * Add a custom Toggler button for a pane + * + * @param {(string|!Object)} selector jQuery selector (or element) for button, eg: ".ui-layout-north .toggle-button" + * @param {string} pane Name of the pane the button is for: 'north', 'south', etc. + * @param {boolean=} slide true = slide-open, false = pin-open + */ +, addToggle: function (inst, selector, pane, slide) { + $.layout.buttons.get(inst, selector, pane, "toggle") + .click(function(evt){ + inst.toggle(pane, !!slide); + evt.stopPropagation(); + }); + return inst; + } + + /** + * Add a custom Open button for a pane + * + * @param {(string|!Object)} selector jQuery selector (or element) for button, eg: ".ui-layout-north .toggle-button" + * @param {string} pane Name of the pane the button is for: 'north', 'south', etc. + * @param {boolean=} slide true = slide-open, false = pin-open + */ +, addOpen: function (inst, selector, pane, slide) { + $.layout.buttons.get(inst, selector, pane, "open") + .attr("title", lang.Open) + .click(function (evt) { + inst.open(pane, !!slide); + evt.stopPropagation(); + }); + return inst; + } + + /** + * Add a custom Close button for a pane + * + * @param {(string|!Object)} selector jQuery selector (or element) for button, eg: ".ui-layout-north .toggle-button" + * @param {string} pane Name of the pane the button is for: 'north', 'south', etc. + */ +, addClose: function (inst, selector, pane) { + $.layout.buttons.get(inst, selector, pane, "close") + .attr("title", lang.Close) + .click(function (evt) { + inst.close(pane); + evt.stopPropagation(); + }); + return inst; + } + + /** + * Add a custom Pin button for a pane + * + * Four classes are added to the element, based on the paneClass for the associated pane... + * Assuming the default paneClass and the pin is 'up', these classes are added for a west-pane pin: + * - ui-layout-pane-pin + * - ui-layout-pane-west-pin + * - ui-layout-pane-pin-up + * - ui-layout-pane-west-pin-up + * + * @param {(string|!Object)} selector jQuery selector (or element) for button, eg: ".ui-layout-north .toggle-button" + * @param {string} pane Name of the pane the pin is for: 'north', 'south', etc. + */ +, addPin: function (inst, selector, pane) { + var $E = $.layout.buttons.get(inst, selector, pane, "pin"); + if ($E.length) { + var s = inst.state[pane]; + $E.click(function (evt) { + $.layout.buttons.setPinState(inst, $(this), pane, (s.isSliding || s.isClosed)); + if (s.isSliding || s.isClosed) inst.open( pane ); // change from sliding to open + else inst.close( pane ); // slide-closed + evt.stopPropagation(); + }); + // add up/down pin attributes and classes + $.layout.buttons.setPinState(inst, $E, pane, (!s.isClosed && !s.isSliding)); + // add this pin to the pane data so we can 'sync it' automatically + // PANE.pins key is an array so we can store multiple pins for each pane + s.pins.push( selector ); // just save the selector string + } + return inst; + } + + /** + * Change the class of the pin button to make it look 'up' or 'down' + * + * @see addPin(), syncPins() + * @param {Array.} $Pin The pin-span element in a jQuery wrapper + * @param {string} pane These are the params returned to callbacks by layout() + * @param {boolean} doPin true = set the pin 'down', false = set it 'up' + */ +, setPinState: function (inst, $Pin, pane, doPin) { + var updown = $Pin.attr("pin"); + if (updown && doPin === (updown=="down")) return; // already in correct state + var + pin = inst.options[pane].buttonClass +"-pin" + , side = pin +"-"+ pane + , UP = pin +"-up "+ side +"-up" + , DN = pin +"-down "+side +"-down" + ; + $Pin + .attr("pin", doPin ? "down" : "up") // logic + .attr("title", doPin ? lang.Unpin : lang.Pin) + .removeClass( doPin ? UP : DN ) + .addClass( doPin ? DN : UP ) + ; + } + + /** + * INTERNAL function to sync 'pin buttons' when pane is opened or closed + * Unpinned means the pane is 'sliding' - ie, over-top of the adjacent panes + * + * @see open(), close() + * @param {string} pane These are the params returned to callbacks by layout() + * @param {boolean} doPin True means set the pin 'down', False means 'up' + */ +, syncPinBtns: function (inst, pane, doPin) { + // REAL METHOD IS _INSIDE_ LAYOUT - THIS IS HERE JUST FOR REFERENCE + $.each(state[pane].pins, function (i, selector) { + $.layout.buttons.setPinState(inst, $(selector), pane, doPin); + }); + } + + +, _load: function (inst) { + // ADD Button methods to Layout Instance + $.extend( inst, { + bindButton: function (selector, action, pane) { return $.layout.buttons.bind(inst, selector, action, pane); } + // DEPRECATED METHODS... + , addToggleBtn: function (selector, pane, slide) { return $.layout.buttons.addToggle(inst, selector, pane, slide); } + , addOpenBtn: function (selector, pane, slide) { return $.layout.buttons.addOpen(inst, selector, pane, slide); } + , addCloseBtn: function (selector, pane) { return $.layout.buttons.addClose(inst, selector, pane); } + , addPinBtn: function (selector, pane) { return $.layout.buttons.addPin(inst, selector, pane); } + }); + + // init state array to hold pin-buttons + for (var i=0; i<4; i++) { + var pane = $.layout.buttons.config.borderPanes[i]; + inst.state[pane].pins = []; + } + + // auto-init buttons onLoad if option is enabled + if ( inst.options.autoBindCustomButtons ) + $.layout.buttons.init(inst); + } + +, _unload: function (inst) { + // TODO: unbind all buttons??? + } + +}; + +// add initialization method to Layout's onLoad array of functions +$.layout.onLoad.push( $.layout.buttons._load ); +//$.layout.onUnload.push( $.layout.buttons._unload ); + +})( jQuery ); + + + + +/** + * jquery.layout.browserZoom 1.0 + * $Date: 2015/03/13 22:37:04 $ + * + * Copyright (c) 2012 + * Kevin Dalman (http://allpro.net) + * + * Dual licensed under the GPL (http://www.gnu.org/licenses/gpl.html) + * and MIT (http://www.opensource.org/licenses/mit-license.php) licenses. + * + * @requires: UI Layout 1.3.0.rc30.1 or higher + * + * @see: http://groups.google.com/group/jquery-ui-layout + * + * TODO: Extend logic to handle other problematic zooming in browsers + * TODO: Add hotkey/mousewheel bindings to _instantly_ respond to these zoom event + */ +(function ($) { + +// tell Layout that the plugin is available +$.layout.plugins.browserZoom = true; + +$.layout.defaults.browserZoomCheckInterval = 1000; +$.layout.optionsMap.layout.push("browserZoomCheckInterval"); + +/* + * browserZoom methods + */ +$.layout.browserZoom = { + + _init: function (inst) { + // abort if browser does not need this check + if ($.layout.browserZoom.ratio() !== false) + $.layout.browserZoom._setTimer(inst); + } + +, _setTimer: function (inst) { + // abort if layout destroyed or browser does not need this check + if (inst.destroyed) return; + var o = inst.options + , s = inst.state + // don't need check if inst has parentLayout, but check occassionally in case parent destroyed! + // MINIMUM 100ms interval, for performance + , ms = inst.hasParentLayout ? 5000 : Math.max( o.browserZoomCheckInterval, 100 ) + ; + // set the timer + setTimeout(function(){ + if (inst.destroyed || !o.resizeWithWindow) return; + var d = $.layout.browserZoom.ratio(); + if (d !== s.browserZoom) { + s.browserZoom = d; + inst.resizeAll(); + } + // set a NEW timeout + $.layout.browserZoom._setTimer(inst); + } + , ms ); + } + +, ratio: function () { + var w = window + , s = screen + , d = document + , dE = d.documentElement || d.body + , b = $.layout.browser + , v = b.version + , r, sW, cW + ; + // we can ignore all browsers that fire window.resize event onZoom + if (!b.msie || v > 8) + return false; // don't need to track zoom + if (s.deviceXDPI && s.systemXDPI) // syntax compiler hack + return calc(s.deviceXDPI, s.systemXDPI); + // everything below is just for future reference! + if (b.webkit && (r = d.body.getBoundingClientRect)) + return calc((r.left - r.right), d.body.offsetWidth); + if (b.webkit && (sW = w.outerWidth)) + return calc(sW, w.innerWidth); + if ((sW = s.width) && (cW = dE.clientWidth)) + return calc(sW, cW); + return false; // no match, so cannot - or don't need to - track zoom + + function calc (x,y) { return (parseInt(x,10) / parseInt(y,10) * 100).toFixed(); } + } + +}; +// add initialization method to Layout's onLoad array of functions +$.layout.onReady.push( $.layout.browserZoom._init ); + + +})( jQuery ); + + + + +/** + * UI Layout Plugin: Slide-Offscreen Animation + * + * Prevent panes from being 'hidden' so that an iframes/objects + * does not reload/refresh when pane 'opens' again. + * This plug-in adds a new animation called "slideOffscreen". + * It is identical to the normal "slide" effect, but avoids hiding the element + * + * Requires Layout 1.3.0.RC30.1 or later for Close offscreen + * Requires Layout 1.3.0.RC30.5 or later for Hide, initClosed & initHidden offscreen + * + * Version: 1.1 - 2012-11-18 + * Author: Kevin Dalman (kevin@jquery-dev.com) + * @preserve jquery.layout.slideOffscreen-1.1.js + */ +;(function ($) { + +// Add a new "slideOffscreen" effect +if ($.effects) { + + // add an option so initClosed and initHidden will work + $.layout.defaults.panes.useOffscreenClose = false; // user must enable when needed + /* set the new animation as the default for all panes + $.layout.defaults.panes.fxName = "slideOffscreen"; + */ + + if ($.layout.plugins) + $.layout.plugins.effects.slideOffscreen = true; + + // dupe 'slide' effect defaults as new effect defaults + $.layout.effects.slideOffscreen = $.extend(true, {}, $.layout.effects.slide); + + // add new effect to jQuery UI + $.effects.slideOffscreen = function(o) { + return this.queue(function(){ + + var fx = $.effects + , opt = o.options + , $el = $(this) + , pane = $el.data('layoutEdge') + , state = $el.data('parentLayout').state + , dist = state[pane].size + , s = this.style + , props = ['top','bottom','left','right'] + // Set options + , mode = fx.setMode($el, opt.mode || 'show') // Set Mode + , show = (mode == 'show') + , dir = opt.direction || 'left' // Default Direction + , ref = (dir == 'up' || dir == 'down') ? 'top' : 'left' + , pos = (dir == 'up' || dir == 'left') + , offscrn = $.layout.config.offscreenCSS || {} + , keyLR = $.layout.config.offscreenReset + , keyTB = 'offscreenResetTop' // only used internally + , animation = {} + ; + // Animation settings + animation[ref] = (show ? (pos ? '+=' : '-=') : (pos ? '-=' : '+=')) + dist; + + if (show) { // show() animation, so save top/bottom but retain left/right set when 'hidden' + $el.data(keyTB, { top: s.top, bottom: s.bottom }); + + // set the top or left offset in preparation for animation + // Note: ALL animations work by shifting the top or left edges + if (pos) { // top (north) or left (west) + $el.css(ref, isNaN(dist) ? "-" + dist : -dist); // Shift outside the left/top edge + } + else { // bottom (south) or right (east) - shift all the way across container + if (dir === 'right') + $el.css({ left: state.container.layoutWidth, right: 'auto' }); + else // dir === bottom + $el.css({ top: state.container.layoutHeight, bottom: 'auto' }); + } + // restore the left/right setting if is a top/bottom animation + if (ref === 'top') + $el.css( $el.data( keyLR ) || {} ); + } + else { // hide() animation, so save ALL CSS + $el.data(keyTB, { top: s.top, bottom: s.bottom }); + $el.data(keyLR, { left: s.left, right: s.right }); + } + + // Animate + $el.show().animate(animation, { queue: false, duration: o.duration, easing: opt.easing, complete: function(){ + // Restore top/bottom + if ($el.data( keyTB )) + $el.css($el.data( keyTB )).removeData( keyTB ); + if (show) // Restore left/right too + $el.css($el.data( keyLR ) || {}).removeData( keyLR ); + else // Move the pane off-screen (left: -99999, right: 'auto') + $el.css( offscrn ); + + if (o.callback) o.callback.apply(this, arguments); // Callback + $el.dequeue(); + }}); + + }); + }; + +} + +})( jQuery ); \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/modalService.js b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/modalService.js new file mode 100644 index 000000000..74c848e8d --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/modalService.js @@ -0,0 +1,185 @@ +angular.module("modalServices",[]).service('modalService', ['$modal', function ($modal) { + + + this.showSuccess = function(heading, messageBody){ + var modalInstance = $modal.open({ + templateUrl: 'modal_informative.html', + controller: 'modalpopupController', + resolve: { + message: function () { + $(".overlayed").css("display","none"); + $(".loadingId").css("display","none"); + var message = { + title: heading, + text: messageBody + }; + return message; + } + } + }); + }; + this.showFailure = function(heading, messageBody){ + var modalInstance = $modal.open({ + templateUrl: 'modal_warning.html', + controller: 'modalpopupController', + resolve: { + message: function () { + var message = { + title: heading, + text: messageBody + }; + return message; + } + } + }); + }; + + this.showMessage = function(heading, messageBody){ + var modalInstance = $modal.open({ + templateUrl: 'modal_message.html', + controller: 'modalpopupController', + resolve: { + message: function () { + var message = { + title: heading, + text: messageBody + }; + return message; + } + } + }); + }; + + this.showWarning = function(heading, messageBody){ + var modalInstance = $modal.open({ + templateUrl: 'modal_warning_message.html', + controller: 'modalpopupController', + resolve: { + message: function () { + var message = { + title: heading, + text: messageBody + }; + return message; + } + } + }); + }; + + this.popupConfirmWin = function(title, msgBody, callback){ + var modalInstance = $modal.open({ + templateUrl: 'confirmation_informative.html', + controller: 'modalpopupController', + resolve: { + message: function () { + var message = { + title: title, + text: msgBody + }; + return message; + } + } + }); + var args = Array.prototype.slice.call( arguments, 0 ); + args.splice( 0, 3); + modalInstance.result.then(function(){ + callback.apply(null, args); + }, function() { + })['finally'](function(){ + modalInstance = undefined; + }); + + }; + this.popupConfirmWinWithCancel = function(title, msgBody, callback,dismissCallback){ + var modalInstance = $modal.open({ + templateUrl: 'confirmation_informative.html', + controller: 'modalpopupController', + resolve: { + message: function () { + var message = { + title: title, + text: msgBody + }; + return message; + } + } + }); + var args = Array.prototype.slice.call( arguments, 0 ); + args.splice( 0, 3); + modalInstance.result.then(function(){ + callback.apply(null, args); + }, function() { + dismissCallback(); + })['finally'](function(){ + modalInstance = undefined; + }); + + }; + this.popupDeleteConfirmWin = function(title, msgBody, callback, argForCallBack){ + var modalInstance = $modal.open({ + templateUrl: 'confirmation_for_delete.html', + controller: 'modalpopupController', + resolve: { + message: function () { + var message = { + title: title, + text: msgBody + }; + return message; + } + } + }); + + modalInstance.result.then(function(){ + callback(argForCallBack); + }, function() { + })['finally'](function(){ + modalInstance = undefined; + }); + + }; + + this.popupSuccessRedirectWin = function(title, msgBody, redirectUrl){ + var modalInstance = $modal.open({ + templateUrl: 'modal_informative.html', + controller: 'modalpopupController', + resolve: { + message: function () { + var message = { + title: title, + text: msgBody + }; + return message; + } + } + }); + modalInstance.result.then(function() { + }, function() { + window.location.href=redirectUrl; + })['finally'](function(){ + modalInstance = undefined; + }); + }; + + this.popupWarningRedirectWin = function(title, msgBody, redirectUrl){ + var modalInstance = $modal.open({ + templateUrl: 'modal_warning_message.html', + controller: 'modalpopupController', + resolve: { + message: function () { + var message = { + title: title, + text: msgBody + }; + return message; + } + } + }); + modalInstance.result.then(function() { + }, function() { + window.location.href=redirectUrl; + })['finally'](function(){ + modalInstance = undefined; + }); + }; + }]); \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/moment.min.js b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/moment.min.js new file mode 100644 index 000000000..62b1697b6 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/moment.min.js @@ -0,0 +1,6 @@ +// moment.js +// version : 2.1.0 +// author : Tim Wood +// license : MIT +// momentjs.com +!function(t){function e(t,e){return function(n){return u(t.call(this,n),e)}}function n(t,e){return function(n){return this.lang().ordinal(t.call(this,n),e)}}function s(){}function i(t){a(this,t)}function r(t){var e=t.years||t.year||t.y||0,n=t.months||t.month||t.M||0,s=t.weeks||t.week||t.w||0,i=t.days||t.day||t.d||0,r=t.hours||t.hour||t.h||0,a=t.minutes||t.minute||t.m||0,o=t.seconds||t.second||t.s||0,u=t.milliseconds||t.millisecond||t.ms||0;this._input=t,this._milliseconds=u+1e3*o+6e4*a+36e5*r,this._days=i+7*s,this._months=n+12*e,this._data={},this._bubble()}function a(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);return t}function o(t){return 0>t?Math.ceil(t):Math.floor(t)}function u(t,e){for(var n=t+"";n.lengthn;n++)~~t[n]!==~~e[n]&&r++;return r+i}function f(t){return t?ie[t]||t.toLowerCase().replace(/(.)s$/,"$1"):t}function l(t,e){return e.abbr=t,x[t]||(x[t]=new s),x[t].set(e),x[t]}function _(t){if(!t)return H.fn._lang;if(!x[t]&&A)try{require("./lang/"+t)}catch(e){return H.fn._lang}return x[t]}function m(t){return t.match(/\[.*\]/)?t.replace(/^\[|\]$/g,""):t.replace(/\\/g,"")}function y(t){var e,n,s=t.match(E);for(e=0,n=s.length;n>e;e++)s[e]=ue[s[e]]?ue[s[e]]:m(s[e]);return function(i){var r="";for(e=0;n>e;e++)r+=s[e]instanceof Function?s[e].call(i,t):s[e];return r}}function M(t,e){function n(e){return t.lang().longDateFormat(e)||e}for(var s=5;s--&&N.test(e);)e=e.replace(N,n);return re[e]||(re[e]=y(e)),re[e](t)}function g(t,e){switch(t){case"DDDD":return V;case"YYYY":return X;case"YYYYY":return $;case"S":case"SS":case"SSS":case"DDD":return I;case"MMM":case"MMMM":case"dd":case"ddd":case"dddd":return R;case"a":case"A":return _(e._l)._meridiemParse;case"X":return B;case"Z":case"ZZ":return j;case"T":return q;case"MM":case"DD":case"YY":case"HH":case"hh":case"mm":case"ss":case"M":case"D":case"d":case"H":case"h":case"m":case"s":return J;default:return new RegExp(t.replace("\\",""))}}function p(t){var e=(j.exec(t)||[])[0],n=(e+"").match(ee)||["-",0,0],s=+(60*n[1])+~~n[2];return"+"===n[0]?-s:s}function D(t,e,n){var s,i=n._a;switch(t){case"M":case"MM":i[1]=null==e?0:~~e-1;break;case"MMM":case"MMMM":s=_(n._l).monthsParse(e),null!=s?i[1]=s:n._isValid=!1;break;case"D":case"DD":case"DDD":case"DDDD":null!=e&&(i[2]=~~e);break;case"YY":i[0]=~~e+(~~e>68?1900:2e3);break;case"YYYY":case"YYYYY":i[0]=~~e;break;case"a":case"A":n._isPm=_(n._l).isPM(e);break;case"H":case"HH":case"h":case"hh":i[3]=~~e;break;case"m":case"mm":i[4]=~~e;break;case"s":case"ss":i[5]=~~e;break;case"S":case"SS":case"SSS":i[6]=~~(1e3*("0."+e));break;case"X":n._d=new Date(1e3*parseFloat(e));break;case"Z":case"ZZ":n._useUTC=!0,n._tzm=p(e)}null==e&&(n._isValid=!1)}function Y(t){var e,n,s=[];if(!t._d){for(e=0;7>e;e++)t._a[e]=s[e]=null==t._a[e]?2===e?1:0:t._a[e];s[3]+=~~((t._tzm||0)/60),s[4]+=~~((t._tzm||0)%60),n=new Date(0),t._useUTC?(n.setUTCFullYear(s[0],s[1],s[2]),n.setUTCHours(s[3],s[4],s[5],s[6])):(n.setFullYear(s[0],s[1],s[2]),n.setHours(s[3],s[4],s[5],s[6])),t._d=n}}function w(t){var e,n,s=t._f.match(E),i=t._i;for(t._a=[],e=0;eo&&(u=o,s=n);a(t,s)}function v(t){var e,n=t._i,s=K.exec(n);if(s){for(t._f="YYYY-MM-DD"+(s[2]||" "),e=0;4>e;e++)if(te[e][1].exec(n)){t._f+=te[e][0];break}j.exec(n)&&(t._f+=" Z"),w(t)}else t._d=new Date(n)}function T(e){var n=e._i,s=G.exec(n);n===t?e._d=new Date:s?e._d=new Date(+s[1]):"string"==typeof n?v(e):d(n)?(e._a=n.slice(0),Y(e)):e._d=n instanceof Date?new Date(+n):new Date(n)}function b(t,e,n,s,i){return i.relativeTime(e||1,!!n,t,s)}function S(t,e,n){var s=W(Math.abs(t)/1e3),i=W(s/60),r=W(i/60),a=W(r/24),o=W(a/365),u=45>s&&["s",s]||1===i&&["m"]||45>i&&["mm",i]||1===r&&["h"]||22>r&&["hh",r]||1===a&&["d"]||25>=a&&["dd",a]||45>=a&&["M"]||345>a&&["MM",W(a/30)]||1===o&&["y"]||["yy",o];return u[2]=e,u[3]=t>0,u[4]=n,b.apply({},u)}function F(t,e,n){var s,i=n-e,r=n-t.day();return r>i&&(r-=7),i-7>r&&(r+=7),s=H(t).add("d",r),{week:Math.ceil(s.dayOfYear()/7),year:s.year()}}function O(t){var e=t._i,n=t._f;return null===e||""===e?null:("string"==typeof e&&(t._i=e=_().preparse(e)),H.isMoment(e)?(t=a({},e),t._d=new Date(+e._d)):n?d(n)?k(t):w(t):T(t),new i(t))}function z(t,e){H.fn[t]=H.fn[t+"s"]=function(t){var n=this._isUTC?"UTC":"";return null!=t?(this._d["set"+n+e](t),H.updateOffset(this),this):this._d["get"+n+e]()}}function C(t){H.duration.fn[t]=function(){return this._data[t]}}function L(t,e){H.duration.fn["as"+t]=function(){return+this/e}}for(var H,P,U="2.1.0",W=Math.round,x={},A="undefined"!=typeof module&&module.exports,G=/^\/?Date\((\-?\d+)/i,Z=/(\-)?(\d*)?\.?(\d+)\:(\d+)\:(\d+)\.?(\d{3})?/,E=/(\[[^\[]*\])|(\\)?(Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|YYYYY|YYYY|YY|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|mm?|ss?|SS?S?|X|zz?|ZZ?|.)/g,N=/(\[[^\[]*\])|(\\)?(LT|LL?L?L?|l{1,4})/g,J=/\d\d?/,I=/\d{1,3}/,V=/\d{3}/,X=/\d{1,4}/,$=/[+\-]?\d{1,6}/,R=/[0-9]*['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+|[\u0600-\u06FF\/]+(\s*?[\u0600-\u06FF]+){1,2}/i,j=/Z|[\+\-]\d\d:?\d\d/i,q=/T/i,B=/[\+\-]?\d+(\.\d{1,3})?/,K=/^\s*\d{4}-\d\d-\d\d((T| )(\d\d(:\d\d(:\d\d(\.\d\d?\d?)?)?)?)?([\+\-]\d\d:?\d\d)?)?/,Q="YYYY-MM-DDTHH:mm:ssZ",te=[["HH:mm:ss.S",/(T| )\d\d:\d\d:\d\d\.\d{1,3}/],["HH:mm:ss",/(T| )\d\d:\d\d:\d\d/],["HH:mm",/(T| )\d\d:\d\d/],["HH",/(T| )\d\d/]],ee=/([\+\-]|\d\d)/gi,ne="Date|Hours|Minutes|Seconds|Milliseconds".split("|"),se={Milliseconds:1,Seconds:1e3,Minutes:6e4,Hours:36e5,Days:864e5,Months:2592e6,Years:31536e6},ie={ms:"millisecond",s:"second",m:"minute",h:"hour",d:"day",w:"week",M:"month",y:"year"},re={},ae="DDD w W M D d".split(" "),oe="M D H h m s w W".split(" "),ue={M:function(){return this.month()+1},MMM:function(t){return this.lang().monthsShort(this,t)},MMMM:function(t){return this.lang().months(this,t)},D:function(){return this.date()},DDD:function(){return this.dayOfYear()},d:function(){return this.day()},dd:function(t){return this.lang().weekdaysMin(this,t)},ddd:function(t){return this.lang().weekdaysShort(this,t)},dddd:function(t){return this.lang().weekdays(this,t)},w:function(){return this.week()},W:function(){return this.isoWeek()},YY:function(){return u(this.year()%100,2)},YYYY:function(){return u(this.year(),4)},YYYYY:function(){return u(this.year(),5)},gg:function(){return u(this.weekYear()%100,2)},gggg:function(){return this.weekYear()},ggggg:function(){return u(this.weekYear(),5)},GG:function(){return u(this.isoWeekYear()%100,2)},GGGG:function(){return this.isoWeekYear()},GGGGG:function(){return u(this.isoWeekYear(),5)},e:function(){return this.weekday()},E:function(){return this.isoWeekday()},a:function(){return this.lang().meridiem(this.hours(),this.minutes(),!0)},A:function(){return this.lang().meridiem(this.hours(),this.minutes(),!1)},H:function(){return this.hours()},h:function(){return this.hours()%12||12},m:function(){return this.minutes()},s:function(){return this.seconds()},S:function(){return~~(this.milliseconds()/100)},SS:function(){return u(~~(this.milliseconds()/10),2)},SSS:function(){return u(this.milliseconds(),3)},Z:function(){var t=-this.zone(),e="+";return 0>t&&(t=-t,e="-"),e+u(~~(t/60),2)+":"+u(~~t%60,2)},ZZ:function(){var t=-this.zone(),e="+";return 0>t&&(t=-t,e="-"),e+u(~~(10*t/6),4)},z:function(){return this.zoneAbbr()},zz:function(){return this.zoneName()},X:function(){return this.unix()}};ae.length;)P=ae.pop(),ue[P+"o"]=n(ue[P],P);for(;oe.length;)P=oe.pop(),ue[P+P]=e(ue[P],2);for(ue.DDDD=e(ue.DDD,3),s.prototype={set:function(t){var e,n;for(n in t)e=t[n],"function"==typeof e?this[n]=e:this["_"+n]=e},_months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),months:function(t){return this._months[t.month()]},_monthsShort:"Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec".split("_"),monthsShort:function(t){return this._monthsShort[t.month()]},monthsParse:function(t){var e,n,s;for(this._monthsParse||(this._monthsParse=[]),e=0;12>e;e++)if(this._monthsParse[e]||(n=H([2e3,e]),s="^"+this.months(n,"")+"|^"+this.monthsShort(n,""),this._monthsParse[e]=new RegExp(s.replace(".",""),"i")),this._monthsParse[e].test(t))return e},_weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),weekdays:function(t){return this._weekdays[t.day()]},_weekdaysShort:"Sun_Mon_Tue_Wed_Thu_Fri_Sat".split("_"),weekdaysShort:function(t){return this._weekdaysShort[t.day()]},_weekdaysMin:"Su_Mo_Tu_We_Th_Fr_Sa".split("_"),weekdaysMin:function(t){return this._weekdaysMin[t.day()]},weekdaysParse:function(t){var e,n,s;for(this._weekdaysParse||(this._weekdaysParse=[]),e=0;7>e;e++)if(this._weekdaysParse[e]||(n=H([2e3,1]).day(e),s="^"+this.weekdays(n,"")+"|^"+this.weekdaysShort(n,"")+"|^"+this.weekdaysMin(n,""),this._weekdaysParse[e]=new RegExp(s.replace(".",""),"i")),this._weekdaysParse[e].test(t))return e},_longDateFormat:{LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D YYYY",LLL:"MMMM D YYYY LT",LLLL:"dddd, MMMM D YYYY LT"},longDateFormat:function(t){var e=this._longDateFormat[t];return!e&&this._longDateFormat[t.toUpperCase()]&&(e=this._longDateFormat[t.toUpperCase()].replace(/MMMM|MM|DD|dddd/g,function(t){return t.slice(1)}),this._longDateFormat[t]=e),e},isPM:function(t){return"p"===(t+"").toLowerCase()[0]},_meridiemParse:/[ap]\.?m?\.?/i,meridiem:function(t,e,n){return t>11?n?"pm":"PM":n?"am":"AM"},_calendar:{sameDay:"[Today at] LT",nextDay:"[Tomorrow at] LT",nextWeek:"dddd [at] LT",lastDay:"[Yesterday at] LT",lastWeek:"[Last] dddd [at] LT",sameElse:"L"},calendar:function(t,e){var n=this._calendar[t];return"function"==typeof n?n.apply(e):n},_relativeTime:{future:"in %s",past:"%s ago",s:"a few seconds",m:"a minute",mm:"%d minutes",h:"an hour",hh:"%d hours",d:"a day",dd:"%d days",M:"a month",MM:"%d months",y:"a year",yy:"%d years"},relativeTime:function(t,e,n,s){var i=this._relativeTime[n];return"function"==typeof i?i(t,e,n,s):i.replace(/%d/i,t)},pastFuture:function(t,e){var n=this._relativeTime[t>0?"future":"past"];return"function"==typeof n?n(e):n.replace(/%s/i,e)},ordinal:function(t){return this._ordinal.replace("%d",t)},_ordinal:"%d",preparse:function(t){return t},postformat:function(t){return t},week:function(t){return F(t,this._week.dow,this._week.doy).week},_week:{dow:0,doy:6}},H=function(t,e,n){return O({_i:t,_f:e,_l:n,_isUTC:!1})},H.utc=function(t,e,n){return O({_useUTC:!0,_isUTC:!0,_l:n,_i:t,_f:e})},H.unix=function(t){return H(1e3*t)},H.duration=function(t,e){var n,s,i=H.isDuration(t),a="number"==typeof t,o=i?t._input:a?{}:t,u=Z.exec(t);return a?e?o[e]=t:o.milliseconds=t:u&&(n="-"===u[1]?-1:1,o={y:0,d:~~u[2]*n,h:~~u[3]*n,m:~~u[4]*n,s:~~u[5]*n,ms:~~u[6]*n}),s=new r(o),i&&t.hasOwnProperty("_lang")&&(s._lang=t._lang),s},H.version=U,H.defaultFormat=Q,H.updateOffset=function(){},H.lang=function(t,e){return t?(e?l(t,e):x[t]||_(t),H.duration.fn._lang=H.fn._lang=_(t),void 0):H.fn._lang._abbr},H.langData=function(t){return t&&t._lang&&t._lang._abbr&&(t=t._lang._abbr),_(t)},H.isMoment=function(t){return t instanceof i},H.isDuration=function(t){return t instanceof r},H.fn=i.prototype={clone:function(){return H(this)},valueOf:function(){return+this._d+6e4*(this._offset||0)},unix:function(){return Math.floor(+this/1e3)},toString:function(){return this.format("ddd MMM DD YYYY HH:mm:ss [GMT]ZZ")},toDate:function(){return this._offset?new Date(+this):this._d},toISOString:function(){return M(H(this).utc(),"YYYY-MM-DD[T]HH:mm:ss.SSS[Z]")},toArray:function(){var t=this;return[t.year(),t.month(),t.date(),t.hours(),t.minutes(),t.seconds(),t.milliseconds()]},isValid:function(){return null==this._isValid&&(this._isValid=this._a?!c(this._a,(this._isUTC?H.utc(this._a):H(this._a)).toArray()):!isNaN(this._d.getTime())),!!this._isValid},utc:function(){return this.zone(0)},local:function(){return this.zone(0),this._isUTC=!1,this},format:function(t){var e=M(this,t||H.defaultFormat);return this.lang().postformat(e)},add:function(t,e){var n;return n="string"==typeof t?H.duration(+e,t):H.duration(t,e),h(this,n,1),this},subtract:function(t,e){var n;return n="string"==typeof t?H.duration(+e,t):H.duration(t,e),h(this,n,-1),this},diff:function(t,e,n){var s,i,r=this._isUTC?H(t).zone(this._offset||0):H(t).local(),a=6e4*(this.zone()-r.zone());return e=f(e),"year"===e||"month"===e?(s=432e5*(this.daysInMonth()+r.daysInMonth()),i=12*(this.year()-r.year())+(this.month()-r.month()),i+=(this-H(this).startOf("month")-(r-H(r).startOf("month")))/s,i-=6e4*(this.zone()-H(this).startOf("month").zone()-(r.zone()-H(r).startOf("month").zone()))/s,"year"===e&&(i/=12)):(s=this-r,i="second"===e?s/1e3:"minute"===e?s/6e4:"hour"===e?s/36e5:"day"===e?(s-a)/864e5:"week"===e?(s-a)/6048e5:s),n?i:o(i)},from:function(t,e){return H.duration(this.diff(t)).lang(this.lang()._abbr).humanize(!e)},fromNow:function(t){return this.from(H(),t)},calendar:function(){var t=this.diff(H().startOf("day"),"days",!0),e=-6>t?"sameElse":-1>t?"lastWeek":0>t?"lastDay":1>t?"sameDay":2>t?"nextDay":7>t?"nextWeek":"sameElse";return this.format(this.lang().calendar(e,this))},isLeapYear:function(){var t=this.year();return 0===t%4&&0!==t%100||0===t%400},isDST:function(){return this.zone()+H(t).startOf(e)},isBefore:function(t,e){return e="undefined"!=typeof e?e:"millisecond",+this.clone().startOf(e)<+H(t).startOf(e)},isSame:function(t,e){return e="undefined"!=typeof e?e:"millisecond",+this.clone().startOf(e)===+H(t).startOf(e)},min:function(t){return t=H.apply(null,arguments),this>t?this:t},max:function(t){return t=H.apply(null,arguments),t>this?this:t},zone:function(t){var e=this._offset||0;return null==t?this._isUTC?e:this._d.getTimezoneOffset():("string"==typeof t&&(t=p(t)),Math.abs(t)<16&&(t=60*t),this._offset=t,this._isUTC=!0,e!==t&&h(this,H.duration(e-t,"m"),1,!0),this)},zoneAbbr:function(){return this._isUTC?"UTC":""},zoneName:function(){return this._isUTC?"Coordinated Universal Time":""},daysInMonth:function(){return H.utc([this.year(),this.month()+1,0]).date()},dayOfYear:function(t){var e=W((H(this).startOf("day")-H(this).startOf("year"))/864e5)+1;return null==t?e:this.add("d",t-e)},weekYear:function(t){var e=F(this,this.lang()._week.dow,this.lang()._week.doy).year;return null==t?e:this.add("y",t-e)},isoWeekYear:function(t){var e=F(this,1,4).year;return null==t?e:this.add("y",t-e)},week:function(t){var e=this.lang().week(this);return null==t?e:this.add("d",7*(t-e))},isoWeek:function(t){var e=F(this,1,4).week;return null==t?e:this.add("d",7*(t-e))},weekday:function(t){var e=(this._d.getDay()+7-this.lang()._week.dow)%7;return null==t?e:this.add("d",t-e)},isoWeekday:function(t){return null==t?this.day()||7:this.day(this.day()%7?t:t-7)},lang:function(e){return e===t?this._lang:(this._lang=_(e),this)}},P=0;PERROR: ' + evt.data); +} + +function writeToScreen(message) { + var pre = document.createElement("p"); + pre.style.wordWrap = "break-word"; + pre.innerHTML = message; + output.append(pre); +} diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/utils/dummy.txt b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/utils/dummy.txt new file mode 100644 index 000000000..e69de29bb diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/utils/page-resource.js b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/utils/page-resource.js new file mode 100644 index 000000000..8449ecfce --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/utils/page-resource.js @@ -0,0 +1,95 @@ +function loadjscssfile(filename, filetype){ + if (filetype=="js"){ //if filename is a external JavaScript file + var done = false; + var script = document.createElement('script'); + script.src = filename; + script.async = false; + document.head.appendChild(script); + }else if (filetype=="css"){ //if filename is an external CSS file + var fileref=document.createElement("link") + fileref.setAttribute("rel", "stylesheet") + fileref.setAttribute("type", "text/css") + fileref.setAttribute("async", false) + fileref.setAttribute("href", filename) + document.head.appendChild(fileref); + } +} + +function loadResource(){ + //css + loadjscssfile("app/fusion/external/ebz/fn-ebz.css", "css"); + loadjscssfile("app/fusion/external/ebz/sandbox/styles/demo.css", "css"); + loadjscssfile("app/fusion/external/ebz/sandbox/styles/base.css", "css"); + loadjscssfile("app/fusion/external/ebz/sandbox/styles/btn.css", "css"); + loadjscssfile("app/fusion/external/ebz/sandbox/styles/dtpk.css", "css"); + loadjscssfile("app/fusion/external/ebz/sandbox/styles/frms.css", "css"); + loadjscssfile("app/fusion/external/ebz/sandbox/styles/sldr.css", "css"); + loadjscssfile("app/fusion/external/ebz/sandbox/styles/style.css", "css"); + loadjscssfile("app/fusion/external/ebz/sandbox/styles/tbs.css", "css"); + loadjscssfile("app/fusion/external/ebz/ebz_header/portal_ebz_header.css", "css"); + loadjscssfile("static/fusion/css/jquery-ui.css", "css"); + + + loadjscssfile("app/fusion/external/ebz/ebz_header/header.css", "css"); + loadjscssfile("app/fusion/external/ebz/ebz_header/footer.css", "css"); + // Basic AngularJS --> + loadjscssfile("app/fusion/external/ebz/angular_js/angular.js", "js"); + loadjscssfile("app/fusion/external/ebz/angular_js/angular-sanitize.js", "js"); + loadjscssfile("app/fusion/external/ebz/angular_js/angular-route.min.js", "js"); + loadjscssfile("app/fusion/external/ebz/angular_js/angular-cookies.js", "js"); + loadjscssfile("app/fusion/external/ebz/angular_js/gestures.js", "js"); + loadjscssfile("app/fusion/external/ebz/angular_js/app.js", "js"); + + loadjscssfile("app/fusion/external/ebz/sandbox/att-abs-tpls.js", "js"); + + // jQuery --> + loadjscssfile("static/js/jquery-1.10.2.js", "js"); + loadjscssfile("static/js/jquery.mask.min.js", "js"); + loadjscssfile("static/js/jquery-ui.js", "js"); + + // AngularJS Gridster --> + loadjscssfile("static/fusion/js/att_angular_gridster/ui-gridster-tpls.js", "js"); + loadjscssfile("static/fusion/js/att_angular_gridster/angular-gridster.js", "js"); + + // AngularJS Config --> + loadjscssfile("app/fusion/external/ebz/angular_js/checklist-model.js", "js"); + + // Utility --> + loadjscssfile("app/fusion/scripts/modalService.js", "js"); + loadjscssfile("app/fusion/external/angular-ui/ui-bootstrap-tpls-1.1.2.min.js", "js"); + + // Controller js --> + loadjscssfile("app/fusion/scripts/controllers/profile-search-controller.js", "js"); + loadjscssfile("app/fusion/scripts/controllers/profile-controller.js", "js"); + loadjscssfile("app/fusion/scripts/controllers/post-search-controller.js", "js"); + loadjscssfile("app/fusion/scripts/controllers/self-profile-controller.js", "js"); + loadjscssfile("app/fusion/scripts/controllers/rolefunctionpopupController.js", "js"); + loadjscssfile("app/fusion/scripts/controllers/modelpopupController.js", "js"); + + // Header and Footer --> + loadjscssfile("app/fusion/scripts/directives/footer.js", "js"); + loadjscssfile("app/fusion/external/ebz/js/footer.js", "js"); + loadjscssfile("app/fusion/scripts/directives/header.js", "js"); + loadjscssfile("app/fusion/scripts/directives/leftMenu.js", "js"); + + // Services --> + loadjscssfile("app/fusion/scripts/services/profileService.js", "js"); + loadjscssfile("app/fusion/scripts/services/userInfoService.js", "js"); + loadjscssfile("app/fusion/scripts/services/leftMenuService.js", "js"); + loadjscssfile("app/fusion/scripts/controllers/profileController.js", "js"); +} + +window.onload = loadResource(); +window.onload = function(){ + var appLoadingInterval = setInterval(function(){ loadApp() }, 500); + var count=0; + function loadApp(){ + count++ + if(typeof angular !== 'undefined') { + angular.bootstrap(document, ['abs']); + clearInterval(appLoadingInterval); + }else if(count>10){ + clearInterval(appLoadingInterval); + } + } +} diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/utils/sandbox-resources.html b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/utils/sandbox-resources.html new file mode 100644 index 000000000..d04eba9ce --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/utils/sandbox-resources.html @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/admin-page/admin.html b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/admin-page/admin.html new file mode 100644 index 000000000..f83888d91 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/admin-page/admin.html @@ -0,0 +1,115 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
        +
        +
        +
        +
        +
        +
        +
        + + diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/admin-page/profile.html b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/admin-page/profile.html new file mode 100644 index 000000000..7ee430206 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/admin-page/profile.html @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + +
        +
        +
        +
        +
        +
        + + diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/dummy.txt b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/dummy.txt new file mode 100644 index 000000000..e69de29bb diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/footer.html b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/footer.html new file mode 100644 index 000000000..561487316 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/footer.html @@ -0,0 +1,42 @@ + + +
        + +
        +
        + +
        + +
        +
        +
        + + +
        +
        + +
        +
        +
        +
        +
        +
        + diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/header.html b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/header.html new file mode 100644 index 000000000..adb5be35a --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/header.html @@ -0,0 +1,186 @@ + +
        +
        +
        +
        +
        + + +
        +
        +
        +
        +
      • +
        + ECOMP Portal +
      • +
        +
        + + +
        + + +
        + +
        +
        +
        +
      • + Unable to load menus +
      • +
        +
      • +
        + + +
        +
      • +
      •  
      • +
        + +
        + +
        +
        +
        +
        +
        +
        +
        +
        + + diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/left_menu.html b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/left_menu.html new file mode 100644 index 000000000..84ee6eadd --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/left_menu.html @@ -0,0 +1,41 @@ + +
        + + + +     {{app_name}} + +
        +
        +
        +
        + + + + + +
        +
        +
        +
        +
        \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/admin_menu_edit.html b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/admin_menu_edit.html new file mode 100644 index 000000000..ee23635fa --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/admin_menu_edit.html @@ -0,0 +1,175 @@ + + +
        +
        +
        +

        Admin Menu Items

        +
        +
        + Add menu item here: +
        +
        + +
        +
        +
        + Existing menu items: +
        +
        + + + +
        +
      + +
      +
      + + + +
      Number of records to show: +
      + +
      +
      + + + + + + + + diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/broadcast.html b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/broadcast.html new file mode 100644 index 000000000..a14da0565 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/broadcast.html @@ -0,0 +1,61 @@ + +
      +
      +

      Broadcast Message Edit

      +
      + +
      + Please edit the broadcast message details below: 

      +
      +
      + +
      +
      +
      +
      + + +
      + +
      +
      + + +
      + +
      +
      + +
      + +
      +
      +
      +
      + +
      +
      + + +
      +
      +
      diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/broadcast_list.html b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/broadcast_list.html new file mode 100644 index 000000000..e9c4c291c --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/broadcast_list.html @@ -0,0 +1,71 @@ + +
      + +
      + +

      Broadcast Messages

      +
      +
      + {{location.label}} Messages +
      + + + + + + + + + + + + + + + + + {{message.id}} + + + + + + + + + + + +
      No.Message TextStart DateEnd DateSort OrderServerActive?Delete?
      {{$index+1}}{{message.messageText}} + {{message.displayStartDate}} + {{message.displayEndDate}}{{message.sortOrder}}{{message.siteCd}} +
      + +
      +
      +
      +
      +
      + +


      +
      +
      +
      diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/collaborate_list.html b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/collaborate_list.html new file mode 100644 index 000000000..5f07a47b8 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/collaborate_list.html @@ -0,0 +1,57 @@ + +
      +
      +

      User List

      +
      + + + + + + + + + + + + + + + + + + + + + + +
      User IDLast NameFirst NameEmailUser IDOnline/Offline
      {{rowData.id}}{{rowData.lastName}}{{rowData.firstName}}{{rowData.email}}{{rowData.orgUserId}} + Offline + Online +
      +
      +
      + + + + Add the Chrome Extension for DescktopCapture and refresh page +
      +
      diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/jcs_admin.html b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/jcs_admin.html new file mode 100644 index 000000000..7da457803 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/jcs_admin.html @@ -0,0 +1,87 @@ + +
      + +

      Cache Regions

      +
      +
      + These are the regions which are currently defined in the cache. 'Items' and 'Bytes' refer to the elements currently in memory (not spooled). + You can clear all items for a region by clicking on the Clear icon next to the desired region below. You can also clear all regions + which empties the entire cache. +
      + +
      +
      +
      Cache Name
      +
      # of Items
      +
      Bytes
      +
      Status
      +
      Memory Hits
      +
      Aux Hits
      +
      Not Found Misses
      +
      Expired Misses
      +
      Clear?
      +
      Items
      +
      +
      +
      + +
      {{region.size}}
      +
      {{region.byteCount}}
      +
      {{region.status}}
      +
      {{region.hitCountRam}}
      +
      {{region.hitCountAux}}
      +
      {{region.missCountNotFound}}
      +
      {{region.missCountExpired}}
      +
      +
      +
      +
      + + +
      +
      +
      + +
      Key
      +
      Eternal?
      +
      Created
      +
      Max Life
      +
      Expires
      +
      Clear?
      +
      +
      +
      + + +
      {{item.eternal}}
      +
      {{item.createTime}}
      +
      {{item.maxLifeSeconds}}
      +
      {{item.expiresInSeconds}}
      +
      +
      +
      +
      +
      +
      +
      +
      +
      diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/popup_modal.html b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/popup_modal.html new file mode 100644 index 000000000..3cde902c2 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/popup_modal.html @@ -0,0 +1,282 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/popup_modal_fn_menu_add.html b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/popup_modal_fn_menu_add.html new file mode 100644 index 000000000..760f10b55 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/popup_modal_fn_menu_add.html @@ -0,0 +1,155 @@ + + + + diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/popup_modal_fn_menu_edit.html b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/popup_modal_fn_menu_edit.html new file mode 100644 index 000000000..4c23ba6fc --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/popup_modal_fn_menu_edit.html @@ -0,0 +1,148 @@ + + + + diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/popup_modal_role.html b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/popup_modal_role.html new file mode 100644 index 000000000..4663bd466 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/popup_modal_role.html @@ -0,0 +1,82 @@ + + + + + + diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/popup_modal_rolefunction.html b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/popup_modal_rolefunction.html new file mode 100644 index 000000000..b9e8ef0e8 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/popup_modal_rolefunction.html @@ -0,0 +1,46 @@ + + + + diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/post_search.html b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/post_search.html new file mode 100644 index 000000000..2c4846ddc --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/post_search.html @@ -0,0 +1,139 @@ + +
      +

      User Search

      +
      + Please enter search criteria below:
      + +
      + Last Name:
      + +
      + +
      + First Name:
      + +
      + +
      + User ID:
      + +
      + +
      + Manager User ID:
      + +
      +
      +
      + Organization:
      + +
      + +
      + Email:
      + +
      +
      +
      + + + +
      +
      + + {{noResultsString}} + +
      + + + + + + + + + + + + + + + + + + + + + + + + + +
      NoNameOrgUserIdOrganizationPhoneEmailImport?
      + {{$index + 1}} + +
      + {{profile.lastName}}, {{profile.firstName}} +
      + + +
      + {{profile.orgUserId}} + + {{profile.orgCode}} + + {{profile.phone}} + + {{profile.email}} + +
      +
      + +
      +
      +
      + Exists +
      +
      +
      + Rows Per Page: + +
      +
      + Current Page: + +
      +
      + Total Page(s): + +
      + +
      + +
      + +
      + +
      diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/profile_detail.html b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/profile_detail.html new file mode 100644 index 000000000..31f68577d --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/profile_detail.html @@ -0,0 +1,188 @@ + +
      +
      +

      Profile Edit

      +
      + Please edit the profile details below: 

      + +
      +
      + +
      + +
      +
      + +
      + +
      +
      + +
      +   +
      +
      + +
      +
      +
      +
      + +
      + +
      +
      + +
      + +
      +
      + +
      + +
      +
      + +
      +
      +
      +
      + +
      + +
      +
      + +
      + +
      +
      + +
      + +
      +
      + +
      +
      +
      +
      + +
      + +
      +
      +
      +
      + +
      +
      + +
      + +
      +
      +
      +
      +
      +
      +
      +
      +
      + +
      + +
      + +
      +
      + + + +
      + + + + + + + + + + + + + + + + +
      NameRemove?
      {{ role.name }} + +
      + + + + + + +
      diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/profile_search.html b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/profile_search.html new file mode 100644 index 000000000..9f49a80ff --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/profile_search.html @@ -0,0 +1,72 @@ + +
      + +

      Profile Search

      + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      User IDLast NameFirst NameEmailUser IDManager User IDEditActive?
      +
      + +
      +
      + +
      + Records Per Page: + +
      + + + + +
      + +
      diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/role.html b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/role.html new file mode 100644 index 000000000..d372f9159 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/role.html @@ -0,0 +1,118 @@ + +
      +
      + +
      +

      Role Edit

      +
      +
      + Please edit the role details below: 
      + +
      +
      + +
      + +
      +
      + +
      + +
      + +
      + +
      +
      + + +
      + + + + + + + + + + + + + + +
      NameRemove?
      {{ roleFunction.name }} +
      +
      + Manage Role Functions

      + +
      + + +
      + + + + + + + + + + + + + + +
      NameRemove?
      {{ role.name }} +
      +
      + +
      + + + + + + + + + + + + + + +
      Role
      +
      + +
      +
      {{ availableRole.name }}
      +
      +
      +
      diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/role_function_list.html b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/role_function_list.html new file mode 100644 index 000000000..b08510368 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/role_function_list.html @@ -0,0 +1,88 @@ + +
      +
      + +

      Role Functions

      +
      + +
      + +
      +

      + +
      + +
      +
      + Click on the edit icon to update a role function, the plus icon to add additional role functions, or the delete icon to remove them. +
      +
      +
      + + + + + + + + + + + + + + + + + +
      NameCodeEdit?Delete?
      + +
      +
      + +
      +
      +
      + + +
      + +
      +
      + +
      +
      +
      +
      + +
      +
      + + +
      + +
      diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/role_list.html b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/role_list.html new file mode 100644 index 000000000..1100cbb07 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/role_list.html @@ -0,0 +1,61 @@ + +
      + +

      Roles

      +
      +
      +Click on a Role to view its details. + +
      +
      + + + + + + + + + + + + + + + + + + +
      NamePriorityActive?Delete?
      {{ availableRole.name }}{{ availableRole.priority }} +
      + +
      +
      +
      +
      +
      + +
      + +
      + +
      diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/self_profile.html b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/self_profile.html new file mode 100644 index 000000000..0f1877c58 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/self_profile.html @@ -0,0 +1,183 @@ + + + +

      Self Profile

      +
      + Please edit the profile details below: 

      + +
      +
      + +
      + +
      +
      + +
      + +
      +
      + +
      + +
      +
      + +
      +
      +
      +
      + +
      + +
      +
      + +
      + +
      +
      + +
      + +
      +
      + +
      +
      +
      +
      + +
      + +
      +
      + +
      + +
      +
      + +
      + +
      +
      + +
      +
      +
      +
      + +
      + +
      +
      +
      +
      + +
      +
      + +
      + +
      +
      +
      +
      +
      +
      +
      +
      +
      + +
      + +
      + +
      +
      + + + +
      + + + + + + + + + + + + + + + + +
      NameRemove?
      {{ role.name }} + +
      + + + diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/usage_list.html b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/usage_list.html new file mode 100644 index 000000000..9bb2c8695 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/profile-page/usage_list.html @@ -0,0 +1,64 @@ + +
      +
      +

      Users

      +
      + +
      + The following shows all users currently logged into the application. Click the icon to expel a user from the application. +
      +
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      Current User Sessions
      User IdUser NameEmailLast Access Time (minutes)Time Remaining (minutes)Expire User Session?
      {{user.id}}{{user.lastName}}{{user.email}}{{user.lastAccess}}{{user.remaining}}
      Current Session
      + +
      +
      +
      +
      diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/workflows/workflow-landing.html b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/workflows/workflow-landing.html new file mode 100644 index 000000000..2b5e3b602 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/workflows/workflow-landing.html @@ -0,0 +1,130 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      +
      +
      +
      +
      +
      +
      +
      + + diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/workflows/workflow-listing.html b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/workflows/workflow-listing.html new file mode 100644 index 000000000..ceb886778 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/workflows/workflow-listing.html @@ -0,0 +1,85 @@ + +
      +
      +
      +
      +

      +

      +
      +
      +
      +
      + +
      +
      +
      +
      +
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      IdNameKeyDescriptionWorkflow Server URLViewActiveCreated Created ByActionScheduleEditDelete?
      {{workflow.id}}{{workflow.name}}{{workflow.workflowKey}}{{workflow.description}}{{workflow.runLink}}
      {{workflow.active}}{{workflow.created}}{{workflow.createdBy}}
      +
      + diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/workflows/workflow-new.html b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/workflows/workflow-new.html new file mode 100644 index 000000000..4622b928f --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/workflows/workflow-new.html @@ -0,0 +1,108 @@ + +
      + +
      +
      + +
      + + +
      + + +
      + Workflow Name is required !!! +
      + +
      +
      + + +
      + +
      + + +
      + Workflow Key is required !!! +
      + +
      +
      + + +
      + + +
      + +
      +
      + +
      + +
      + +
      + +
      + Run Link is required !!! + Not valid url! +
      + +
      + + + +
      + +
      + + + Active + Inactive + + +
      +
      + + +
      +
      +
      +
      diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/workflows/workflow-preview.html b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/workflows/workflow-preview.html new file mode 100644 index 000000000..80fece4ef --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/workflows/workflow-preview.html @@ -0,0 +1,36 @@ + +
      + +
      +
      + +
      + +
      + +
      +
      +
      +
      diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/workflows/workflow-remove.html b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/workflows/workflow-remove.html new file mode 100644 index 000000000..e21efad8e --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/workflows/workflow-remove.html @@ -0,0 +1,38 @@ + +
      + +
      +
      + +
      + +
      + + +
      +
      +
      +
      diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/workflows/workflow-schedule.html b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/workflows/workflow-schedule.html new file mode 100644 index 000000000..aebc04fbd --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/view-models/workflows/workflow-schedule.html @@ -0,0 +1,116 @@ + +
      + + +
      +
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + : + + + + + + + +
      + + +
      +
      +
      + + +Pick a date: + +Hour: + +Minute: +
      +
      + +
      +
      + + + +
      +
      +
      +
      +
      + +
      +
      + + +
      +
      +
      +
      + + + +
      +
      +
      diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/webrtc/RTCMultiConnection.js b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/webrtc/RTCMultiConnection.js new file mode 100644 index 000000000..449e8d591 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/webrtc/RTCMultiConnection.js @@ -0,0 +1,6788 @@ +// Last time updated at Monday, December 21st, 2015, 5:25:26 PM + +// Quick-Demo for newbies: http://jsfiddle.net/c46de0L8/ +// Another simple demo: http://jsfiddle.net/zar6fg60/ + +// Latest file can be found here: https://cdn.webrtc-experiment.com/RTCMultiConnection.js + +// Muaz Khan - www.MuazKhan.com +// MIT License - www.WebRTC-Experiment.com/licence +// Documentation - www.RTCMultiConnection.org/docs +// FAQ - www.RTCMultiConnection.org/FAQ +// Changes log - www.RTCMultiConnection.org/changes-log/ +// Demos - www.WebRTC-Experiment.com/RTCMultiConnection + +// _________________________ +// RTCMultiConnection-v2.2.2 + +(function() { + + // RMC == RTCMultiConnection + // usually page-URL is used as channel-id + // you can always override it! + // www.RTCMultiConnection.org/docs/channel-id/ + window.RMCDefaultChannel = location.href.replace(/\/|:|#|\?|\$|\^|%|\.|`|~|!|\+|@|\[|\||]|\|*. /g, '').split('\n').join('').split('\r').join(''); + + // www.RTCMultiConnection.org/docs/constructor/ + window.RTCMultiConnection = function(channel) { + // an instance of constructor + var connection = this; + + // a reference to RTCMultiSession + var rtcMultiSession; + + // setting default channel or channel passed through constructor + connection.channel = channel || RMCDefaultChannel; + + // to allow single user to join multiple rooms; + // you can change this property at runtime! + connection.isAcceptNewSession = true; + + // www.RTCMultiConnection.org/docs/open/ + connection.open = function(args) { + connection.isAcceptNewSession = false; + + // www.RTCMultiConnection.org/docs/session-initiator/ + // you can always use this property to determine room owner! + connection.isInitiator = true; + + var dontTransmit = false; + + // a channel can contain multiple rooms i.e. sessions + if (args) { + if (isString(args)) { + connection.sessionid = args; + } else { + if (!isNull(args.transmitRoomOnce)) { + connection.transmitRoomOnce = args.transmitRoomOnce; + } + + if (!isNull(args.dontTransmit)) { + dontTransmit = args.dontTransmit; + } + + if (!isNull(args.sessionid)) { + connection.sessionid = args.sessionid; + } + } + } + + // if firebase && if session initiator + if (connection.socket && connection.socket.remove) { + connection.socket.remove(); + } + + if (!connection.sessionid) connection.sessionid = connection.channel; + connection.sessionDescription = { + sessionid: connection.sessionid, + userid: connection.userid, + session: connection.session, + extra: connection.extra + }; + + if (!connection.sessionDescriptions[connection.sessionDescription.sessionid]) { + connection.numberOfSessions++; + connection.sessionDescriptions[connection.sessionDescription.sessionid] = connection.sessionDescription; + } + + // connect with signaling channel + initRTCMultiSession(function() { + // "captureUserMediaOnDemand" is disabled by default. + // invoke "getUserMedia" only when first participant found. + rtcMultiSession.captureUserMediaOnDemand = args ? !!args.captureUserMediaOnDemand : false; + + if (args && args.onMediaCaptured) { + connection.onMediaCaptured = args.onMediaCaptured; + } + + // for session-initiator, user-media is captured as soon as "open" is invoked. + if (!rtcMultiSession.captureUserMediaOnDemand) captureUserMedia(function() { + rtcMultiSession.initSession({ + sessionDescription: connection.sessionDescription, + dontTransmit: dontTransmit + }); + + invokeMediaCaptured(connection); + }); + + if (rtcMultiSession.captureUserMediaOnDemand) { + rtcMultiSession.initSession({ + sessionDescription: connection.sessionDescription, + dontTransmit: dontTransmit + }); + } + }); + return connection.sessionDescription; + }; + + // www.RTCMultiConnection.org/docs/connect/ + connection.connect = function(sessionid) { + // a channel can contain multiple rooms i.e. sessions + if (sessionid) { + connection.sessionid = sessionid; + } + + // connect with signaling channel + initRTCMultiSession(function() { + log('Signaling channel is ready.'); + }); + + return this; + }; + + // www.RTCMultiConnection.org/docs/join/ + connection.join = joinSession; + + // www.RTCMultiConnection.org/docs/send/ + connection.send = function(data, _channel) { + if (connection.numberOfConnectedUsers <= 0) { + // no connections + setTimeout(function() { + // try again + connection.send(data, _channel); + }, 1000); + return; + } + + // send file/data or /text + if (!data) + throw 'No file, data or text message to share.'; + + // connection.send([file1, file2, file3]) + // you can share multiple files, strings or data objects using "send" method! + if (data instanceof Array && !isNull(data[0].size) && !isNull(data[0].type)) { + // this mechanism can cause failure for subsequent packets/data + // on Firefox especially; and on chrome as well! + // todo: need to use setTimeout instead. + for (var i = 0; i < data.length; i++) { + data[i].size && data[i].type && connection.send(data[i], _channel); + } + return; + } + + // File or Blob object MUST have "type" and "size" properties + if (!isNull(data.size) && !isNull(data.type)) { + if (!connection.enableFileSharing) { + throw '"enableFileSharing" boolean MUST be "true" to support file sharing.'; + } + + if (!rtcMultiSession.fileBufferReader) { + initFileBufferReader(connection, function(fbr) { + rtcMultiSession.fileBufferReader = fbr; + connection.send(data, _channel); + }); + return; + } + + var extra = merge({ + userid: connection.userid + }, data.extra || connection.extra); + + rtcMultiSession.fileBufferReader.readAsArrayBuffer(data, function(uuid) { + rtcMultiSession.fileBufferReader.getNextChunk(uuid, function(nextChunk, isLastChunk, extra) { + if (_channel) _channel.send(nextChunk); + else rtcMultiSession.send(nextChunk); + }); + }, extra); + } else { + // to allow longest string messages + // and largest data objects + // or anything of any size! + // to send multiple data objects concurrently! + + TextSender.send({ + text: data, + channel: rtcMultiSession, + _channel: _channel, + connection: connection + }); + } + }; + + function initRTCMultiSession(onSignalingReady) { + if (screenFrame) { + loadScreenFrame(); + } + + // RTCMultiSession is the backbone object; + // this object MUST be initialized once! + if (rtcMultiSession) return onSignalingReady(); + + // your everything is passed over RTCMultiSession constructor! + rtcMultiSession = new RTCMultiSession(connection, onSignalingReady); + } + + connection.disconnect = function() { + if (rtcMultiSession) rtcMultiSession.disconnect(); + rtcMultiSession = null; + }; + + function joinSession(session, joinAs) { + if (isString(session)) { + connection.skipOnNewSession = true; + } + + if (!rtcMultiSession) { + log('Signaling channel is not ready. Connecting...'); + // connect with signaling channel + initRTCMultiSession(function() { + log('Signaling channel is connected. Joining the session again...'); + setTimeout(function() { + joinSession(session, joinAs); + }, 1000); + }); + return; + } + + // connection.join('sessionid'); + if (isString(session)) { + if (connection.sessionDescriptions[session]) { + session = connection.sessionDescriptions[session]; + } else + return setTimeout(function() { + log('Session-Descriptions not found. Rechecking..'); + joinSession(session, joinAs); + }, 1000); + } + + // connection.join('sessionid', { audio: true }); + if (joinAs) { + return captureUserMedia(function() { + session.oneway = true; + joinSession(session); + }, joinAs); + } + + if (!session || !session.userid || !session.sessionid) { + error('missing arguments', arguments); + + var error = 'Invalid data passed over "connection.join" method.'; + connection.onstatechange({ + userid: 'browser', + extra: {}, + name: 'Unexpected data detected.', + reason: error + }); + + throw error; + } + + if (!connection.dontOverrideSession) { + connection.session = session.session; + } + + var extra = connection.extra || session.extra || {}; + + // todo: need to verify that if-block statement works as expected. + // expectations: if it is oneway streaming; or if it is data-only connection + // then, it shouldn't capture user-media on participant's side. + if (session.oneway || isData(session)) { + rtcMultiSession.joinSession(session, extra); + } else { + captureUserMedia(function() { + rtcMultiSession.joinSession(session, extra); + }); + } + } + + var isFirstSession = true; + + // www.RTCMultiConnection.org/docs/captureUserMedia/ + + function captureUserMedia(callback, _session, dontCheckChromExtension) { + // capture user's media resources + var session = _session || connection.session; + + if (isEmpty(session)) { + if (callback) callback(); + return; + } + + // you can force to skip media capturing! + if (connection.dontCaptureUserMedia) { + return callback(); + } + + // if it is data-only connection + // if it is one-way connection and current user is participant + if (isData(session) || (!connection.isInitiator && session.oneway)) { + // www.RTCMultiConnection.org/docs/attachStreams/ + connection.attachStreams = []; + return callback(); + } + + var constraints = { + audio: !!session.audio ? { + mandatory: {}, + optional: [{ + chromeRenderToAssociatedSink: true + }] + } : false, + video: !!session.video + }; + + // if custom audio device is selected + if (connection._mediaSources.audio) { + constraints.audio.optional.push({ + sourceId: connection._mediaSources.audio + }); + } + + // if custom video device is selected + if (connection._mediaSources.video) { + constraints.video = { + optional: [{ + sourceId: connection._mediaSources.video + }] + }; + } + + // for connection.session = {}; + if (!session.screen && !constraints.audio && !constraints.video) { + return callback(); + } + + var screen_constraints = { + audio: false, + video: { + mandatory: { + chromeMediaSource: DetectRTC.screen.chromeMediaSource, + maxWidth: screen.width > 1920 ? screen.width : 1920, + maxHeight: screen.height > 1080 ? screen.height : 1080 + }, + optional: [] + } + }; + + if (isFirefox && session.screen) { + if (location.protocol !== 'https:') { + return error(SCREEN_COMMON_FAILURE); + } + warn(Firefox_Screen_Capturing_Warning); + + screen_constraints.video = merge(screen_constraints.video.mandatory, { + mozMediaSource: 'window', // mozMediaSource is redundant here + mediaSource: 'window' // 'screen' || 'window' + }); + + // Firefox is supporting audio+screen from single getUserMedia request + // audio+video+screen will become audio+screen for Firefox + // because Firefox isn't supporting multi-streams feature version < 38 + // version >38 supports multi-stream sharing. + // we can use: firefoxVersion < 38 + // however capturing audio and screen using single getUserMedia is a better option + if (constraints.audio /* && !session.video */ ) { + screen_constraints.audio = true; + constraints = {}; + } + + delete screen_constraints.video.chromeMediaSource; + } + + // if screen is prompted + if (session.screen) { + if (isChrome && DetectRTC.screen.extensionid != ReservedExtensionID) { + useCustomChromeExtensionForScreenCapturing = true; + } + + if (isChrome && !useCustomChromeExtensionForScreenCapturing && !dontCheckChromExtension && !DetectRTC.screen.sourceId) { + listenEventHandler('message', onIFrameCallback); + + function onIFrameCallback(event) { + if (event.data && event.data.chromeMediaSourceId) { + // this event listener is no more needed + window.removeEventListener('message', onIFrameCallback); + + var sourceId = event.data.chromeMediaSourceId; + + DetectRTC.screen.sourceId = sourceId; + DetectRTC.screen.chromeMediaSource = 'desktop'; + + if (sourceId == 'PermissionDeniedError') { + var mediaStreamError = { + message: location.protocol == 'https:' ? 'User denied to share content of his screen.' : SCREEN_COMMON_FAILURE, + name: 'PermissionDeniedError', + constraintName: screen_constraints, + session: session + }; + currentUserMediaRequest.mutex = false; + DetectRTC.screen.sourceId = null; + return connection.onMediaError(mediaStreamError); + } + + captureUserMedia(callback, _session); + } + + if (event.data && event.data.chromeExtensionStatus) { + warn('Screen capturing extension status is:', event.data.chromeExtensionStatus); + DetectRTC.screen.chromeMediaSource = 'screen'; + captureUserMedia(callback, _session, true); + } + } + + if (!screenFrame) { + loadScreenFrame(); + } + + screenFrame.postMessage(); + return; + } + + // check if screen capturing extension is installed. + if (isChrome && useCustomChromeExtensionForScreenCapturing && !dontCheckChromExtension && DetectRTC.screen.chromeMediaSource == 'screen' && DetectRTC.screen.extensionid) { + if (DetectRTC.screen.extensionid == ReservedExtensionID && document.domain.indexOf('webrtc-experiment.com') == -1) { + return captureUserMedia(callback, _session, true); + } + + log('checking if chrome extension is installed.'); + DetectRTC.screen.getChromeExtensionStatus(function(status) { + if (status == 'installed-enabled') { + DetectRTC.screen.chromeMediaSource = 'desktop'; + } + + captureUserMedia(callback, _session, true); + log('chrome extension is installed?', DetectRTC.screen.chromeMediaSource == 'desktop'); + }); + return; + } + + if (isChrome && useCustomChromeExtensionForScreenCapturing && DetectRTC.screen.chromeMediaSource == 'desktop' && !DetectRTC.screen.sourceId) { + DetectRTC.screen.getSourceId(function(sourceId) { + if (sourceId == 'PermissionDeniedError') { + var mediaStreamError = { + message: 'User denied to share content of his screen.', + name: 'PermissionDeniedError', + constraintName: screen_constraints, + session: session + }; + currentUserMediaRequest.mutex = false; + DetectRTC.screen.chromeMediaSource = 'desktop'; + return connection.onMediaError(mediaStreamError); + } + + if (sourceId == 'No-Response') { + error('Chrome extension seems not available. Make sure that manifest.json#L16 has valid content-script matches pointing to your URL.'); + DetectRTC.screen.chromeMediaSource = 'screen'; + return captureUserMedia(callback, _session, true); + } + + captureUserMedia(callback, _session, true); + }); + return; + } + + if (isChrome && DetectRTC.screen.chromeMediaSource == 'desktop') { + screen_constraints.video.mandatory.chromeMediaSourceId = DetectRTC.screen.sourceId; + } + + var _isFirstSession = isFirstSession; + + _captureUserMedia(screen_constraints, constraints.audio || constraints.video ? function() { + + if (_isFirstSession) isFirstSession = true; + + _captureUserMedia(constraints, callback); + } : callback); + } else _captureUserMedia(constraints, callback, session.audio && !session.video); + + function _captureUserMedia(forcedConstraints, forcedCallback, isRemoveVideoTracks, dontPreventSSLAutoAllowed) { + connection.onstatechange({ + userid: 'browser', + extra: {}, + name: 'fetching-usermedia', + reason: 'About to capture user-media with constraints: ' + toStr(forcedConstraints) + }); + + + if (connection.preventSSLAutoAllowed && !dontPreventSSLAutoAllowed && isChrome) { + // if navigator.customGetUserMediaBar.js is missing + if (!navigator.customGetUserMediaBar) { + loadScript(connection.resources.customGetUserMediaBar, function() { + _captureUserMedia(forcedConstraints, forcedCallback, isRemoveVideoTracks, dontPreventSSLAutoAllowed); + }); + return; + } + + navigator.customGetUserMediaBar(forcedConstraints, function() { + _captureUserMedia(forcedConstraints, forcedCallback, isRemoveVideoTracks, true); + }, function() { + connection.onMediaError({ + name: 'PermissionDeniedError', + message: 'User denied permission.', + constraintName: forcedConstraints, + session: session + }); + }); + return; + } + + var mediaConfig = { + onsuccess: function(stream, returnBack, idInstance, streamid) { + onStreamSuccessCallback(stream, returnBack, idInstance, streamid, forcedConstraints, forcedCallback, isRemoveVideoTracks, screen_constraints, constraints, session); + }, + onerror: function(e, constraintUsed) { + // http://goo.gl/hrwF1a + if (isFirefox) { + if (e == 'PERMISSION_DENIED') { + e = { + message: '', + name: 'PermissionDeniedError', + constraintName: constraintUsed, + session: session + }; + } + } + + if (isFirefox && constraintUsed.video && constraintUsed.video.mozMediaSource) { + mediaStreamError = { + message: Firefox_Screen_Capturing_Warning, + name: e.name || 'PermissionDeniedError', + constraintName: constraintUsed, + session: session + }; + + connection.onMediaError(mediaStreamError); + return; + } + + if (isString(e)) { + return connection.onMediaError({ + message: 'Unknown Error', + name: e, + constraintName: constraintUsed, + session: session + }); + } + + // it seems that chrome 35+ throws "DevicesNotFoundError" exception + // when any of the requested media is either denied or absent + if (e.name && (e.name == 'PermissionDeniedError' || e.name == 'DevicesNotFoundError')) { + var mediaStreamError = 'Either: '; + mediaStreamError += '\n Media resolutions are not permitted.'; + mediaStreamError += '\n Another application is using same media device.'; + mediaStreamError += '\n Media device is not attached or drivers not installed.'; + mediaStreamError += '\n You denied access once and it is still denied.'; + + if (e.message && e.message.length) { + mediaStreamError += '\n ' + e.message; + } + + mediaStreamError = { + message: mediaStreamError, + name: e.name, + constraintName: constraintUsed, + session: session + }; + + connection.onMediaError(mediaStreamError); + + if (isChrome && (session.audio || session.video)) { + // todo: this snippet fails if user has two or more + // microphone/webcam attached. + DetectRTC.load(function() { + // it is possible to check presence of the microphone before using it! + if (session.audio && !DetectRTC.hasMicrophone) { + warn('It seems that you have no microphone attached to your device/system.'); + session.audio = session.audio = false; + + if (!session.video) { + alert('It seems that you are capturing microphone and there is no device available or access is denied. Reloading...'); + location.reload(); + } + } + + // it is possible to check presence of the webcam before using it! + if (session.video && !DetectRTC.hasWebcam) { + warn('It seems that you have no webcam attached to your device/system.'); + session.video = session.video = false; + + if (!session.audio) { + alert('It seems that you are capturing webcam and there is no device available or access is denied. Reloading...'); + location.reload(); + } + } + + if (!DetectRTC.hasMicrophone && !DetectRTC.hasWebcam) { + alert('It seems that either both microphone/webcam are not available or access is denied. Reloading...'); + location.reload(); + } else if (!connection.getUserMediaPromptedOnce) { + // make maximum two tries! + connection.getUserMediaPromptedOnce = true; + captureUserMedia(callback, session); + } + }); + } + } + + if (e.name && e.name == 'ConstraintNotSatisfiedError') { + var mediaStreamError = 'Either: '; + mediaStreamError += '\n You are prompting unknown media resolutions.'; + mediaStreamError += '\n You are using invalid media constraints.'; + + if (e.message && e.message.length) { + mediaStreamError += '\n ' + e.message; + } + + mediaStreamError = { + message: mediaStreamError, + name: e.name, + constraintName: constraintUsed, + session: session + }; + + connection.onMediaError(mediaStreamError); + } + + if (session.screen) { + if (isFirefox) { + error(Firefox_Screen_Capturing_Warning); + } else if (location.protocol !== 'https:') { + if (!isNodeWebkit && (location.protocol == 'file:' || location.protocol == 'http:')) { + error('You cannot use HTTP or file protocol for screen capturing. You must either use HTTPs or chrome extension page or Node-Webkit page.'); + } + } else { + error('Unable to detect actual issue. Maybe "deprecated" screen capturing flag was not set using command line or maybe you clicked "No" button or maybe chrome extension returned invalid "sourceId". Please install chrome-extension: http://bit.ly/webrtc-screen-extension'); + } + } + + currentUserMediaRequest.mutex = false; + + // to make sure same stream can be captured again! + var idInstance = JSON.stringify(constraintUsed); + if (currentUserMediaRequest.streams[idInstance]) { + delete currentUserMediaRequest.streams[idInstance]; + } + }, + mediaConstraints: connection.mediaConstraints || {} + }; + + mediaConfig.constraints = forcedConstraints || constraints; + mediaConfig.connection = connection; + getUserMedia(mediaConfig); + } + } + + function onStreamSuccessCallback(stream, returnBack, idInstance, streamid, forcedConstraints, forcedCallback, isRemoveVideoTracks, screen_constraints, constraints, session) { + if (!streamid) streamid = getRandomString(); + + connection.onstatechange({ + userid: 'browser', + extra: {}, + name: 'usermedia-fetched', + reason: 'Captured user media using constraints: ' + toStr(forcedConstraints) + }); + + if (isRemoveVideoTracks) { + stream = convertToAudioStream(stream); + } + + connection.localStreamids.push(streamid); + stream.onended = function() { + if (streamedObject.mediaElement && !streamedObject.mediaElement.parentNode && document.getElementById(stream.streamid)) { + streamedObject.mediaElement = document.getElementById(stream.streamid); + } + + // when a stream is stopped; it must be removed from "attachStreams" array + connection.attachStreams.forEach(function(_stream, index) { + if (_stream == stream) { + delete connection.attachStreams[index]; + connection.attachStreams = swap(connection.attachStreams); + } + }); + + onStreamEndedHandler(streamedObject, connection); + + if (connection.streams[streamid]) { + connection.removeStream(streamid); + } + + // if user clicks "stop" button to close screen sharing + var _stream = connection.streams[streamid]; + if (_stream && _stream.sockets.length) { + _stream.sockets.forEach(function(socket) { + socket.send({ + streamid: _stream.streamid, + stopped: true + }); + }); + } + + currentUserMediaRequest.mutex = false; + // to make sure same stream can be captured again! + if (currentUserMediaRequest.streams[idInstance]) { + delete currentUserMediaRequest.streams[idInstance]; + } + + // to allow re-capturing of the screen + DetectRTC.screen.sourceId = null; + }; + + if (!isIE) { + stream.streamid = streamid; + stream.isScreen = forcedConstraints == screen_constraints; + stream.isVideo = forcedConstraints == constraints && !!constraints.video; + stream.isAudio = forcedConstraints == constraints && !!constraints.audio && !constraints.video; + + // if muted stream is negotiated + stream.preMuted = { + audio: stream.getAudioTracks().length && !stream.getAudioTracks()[0].enabled, + video: stream.getVideoTracks().length && !stream.getVideoTracks()[0].enabled + }; + } + + var mediaElement = createMediaElement(stream, session); + mediaElement.muted = true; + + var streamedObject = { + stream: stream, + streamid: streamid, + mediaElement: mediaElement, + blobURL: mediaElement.mozSrcObject ? URL.createObjectURL(stream) : mediaElement.src, + type: 'local', + userid: connection.userid, + extra: connection.extra, + session: session, + isVideo: !!stream.isVideo, + isAudio: !!stream.isAudio, + isScreen: !!stream.isScreen, + isInitiator: !!connection.isInitiator, + rtcMultiConnection: connection + }; + + if (isFirstSession) { + connection.attachStreams.push(stream); + } + isFirstSession = false; + + connection.streams[streamid] = connection._getStream(streamedObject); + + if (!returnBack) { + connection.onstream(streamedObject); + } + + if (connection.setDefaultEventsForMediaElement) { + connection.setDefaultEventsForMediaElement(mediaElement, streamid); + } + + if (forcedCallback) forcedCallback(stream, streamedObject); + + if (connection.onspeaking) { + initHark({ + stream: stream, + streamedObject: streamedObject, + connection: connection + }); + } + } + + // www.RTCMultiConnection.org/docs/captureUserMedia/ + connection.captureUserMedia = captureUserMedia; + + // www.RTCMultiConnection.org/docs/leave/ + connection.leave = function(userid) { + if (!rtcMultiSession) return; + + isFirstSession = true; + + if (userid) { + connection.eject(userid); + return; + } + + rtcMultiSession.leave(); + }; + + // www.RTCMultiConnection.org/docs/eject/ + connection.eject = function(userid) { + if (!connection.isInitiator) throw 'Only session-initiator can eject a user.'; + if (!connection.peers[userid]) throw 'You ejected invalid user.'; + connection.peers[userid].sendCustomMessage({ + ejected: true + }); + }; + + // www.RTCMultiConnection.org/docs/close/ + connection.close = function() { + // close entire session + connection.autoCloseEntireSession = true; + connection.leave(); + }; + + // www.RTCMultiConnection.org/docs/renegotiate/ + connection.renegotiate = function(stream, session) { + if (connection.numberOfConnectedUsers <= 0) { + // no connections + setTimeout(function() { + // try again + connection.renegotiate(stream, session); + }, 1000); + return; + } + + rtcMultiSession.addStream({ + renegotiate: session || merge({ + oneway: true + }, connection.session), + stream: stream + }); + }; + + connection.attachExternalStream = function(stream, isScreen) { + var constraints = {}; + if (stream.getAudioTracks && stream.getAudioTracks().length) { + constraints.audio = true; + } + if (stream.getVideoTracks && stream.getVideoTracks().length) { + constraints.video = true; + } + + var screen_constraints = { + video: { + chromeMediaSource: 'fake' + } + }; + var forcedConstraints = isScreen ? screen_constraints : constraints; + onStreamSuccessCallback(stream, false, '', null, forcedConstraints, false, false, screen_constraints, constraints, constraints); + }; + + // www.RTCMultiConnection.org/docs/addStream/ + connection.addStream = function(session, socket) { + // www.RTCMultiConnection.org/docs/renegotiation/ + + if (connection.numberOfConnectedUsers <= 0) { + // no connections + setTimeout(function() { + // try again + connection.addStream(session, socket); + }, 1000); + return; + } + + // renegotiate new media stream + if (session) { + var isOneWayStreamFromParticipant; + if (!connection.isInitiator && session.oneway) { + session.oneway = false; + isOneWayStreamFromParticipant = true; + } + + captureUserMedia(function(stream) { + if (isOneWayStreamFromParticipant) { + session.oneway = true; + } + addStream(stream); + }, session); + } else addStream(); + + function addStream(stream) { + rtcMultiSession.addStream({ + stream: stream, + renegotiate: session || connection.session, + socket: socket + }); + } + }; + + // www.RTCMultiConnection.org/docs/removeStream/ + connection.removeStream = function(streamid, dontRenegotiate) { + if (connection.numberOfConnectedUsers <= 0) { + // no connections + setTimeout(function() { + // try again + connection.removeStream(streamid, dontRenegotiate); + }, 1000); + return; + } + + if (!streamid) streamid = 'all'; + if (!isString(streamid) || streamid.search(/all|audio|video|screen/gi) != -1) { + function _detachStream(_stream, config) { + if (config.local && _stream.type != 'local') return; + if (config.remote && _stream.type != 'remote') return; + + // connection.removeStream({screen:true}); + if (config.screen && !!_stream.isScreen) { + connection.detachStreams.push(_stream.streamid); + } + + // connection.removeStream({audio:true}); + if (config.audio && !!_stream.isAudio) { + connection.detachStreams.push(_stream.streamid); + } + + // connection.removeStream({video:true}); + if (config.video && !!_stream.isVideo) { + connection.detachStreams.push(_stream.streamid); + } + + // connection.removeStream({}); + if (!config.audio && !config.video && !config.screen) { + connection.detachStreams.push(_stream.streamid); + } + + if (connection.detachStreams.indexOf(_stream.streamid) != -1) { + log('removing stream', _stream.streamid); + onStreamEndedHandler(_stream, connection); + + if (config.stop) { + connection.stopMediaStream(_stream.stream); + } + } + } + + for (var stream in connection.streams) { + if (connection._skip.indexOf(stream) == -1) { + _stream = connection.streams[stream]; + + if (streamid == 'all') _detachStream(_stream, { + audio: true, + video: true, + screen: true + }); + + else if (isString(streamid)) { + // connection.removeStream('screen'); + var config = {}; + config[streamid] = true; + _detachStream(_stream, config); + } else _detachStream(_stream, streamid); + } + } + + if (!dontRenegotiate && connection.detachStreams.length) { + connection.renegotiate(); + } + + return; + } + + var stream = connection.streams[streamid]; + + // detach pre-attached streams + if (!stream) return warn('No such stream exists. Stream-id:', streamid); + + // www.RTCMultiConnection.org/docs/detachStreams/ + connection.detachStreams.push(stream.streamid); + + log('removing stream', stream.streamid); + onStreamEndedHandler(stream, connection); + + // todo: how to allow "stop" function? + // connection.stopMediaStream(stream.stream) + + if (!dontRenegotiate) { + connection.renegotiate(); + } + }; + + connection.switchStream = function(session) { + if (connection.numberOfConnectedUsers <= 0) { + // no connections + setTimeout(function() { + // try again + connection.switchStream(session); + }, 1000); + return; + } + + connection.removeStream('all', true); + connection.addStream(session); + }; + + // www.RTCMultiConnection.org/docs/sendCustomMessage/ + connection.sendCustomMessage = function(message) { + if (!rtcMultiSession || !rtcMultiSession.defaultSocket) { + return setTimeout(function() { + connection.sendCustomMessage(message); + }, 1000); + } + + rtcMultiSession.defaultSocket.send({ + customMessage: true, + message: message + }); + }; + + // set RTCMultiConnection defaults on constructor invocation + setDefaults(connection); + }; + + function RTCMultiSession(connection, callbackForSignalingReady) { + var socketObjects = {}; + var sockets = []; + var rtcMultiSession = this; + var participants = {}; + + if (!rtcMultiSession.fileBufferReader && connection.session.data && connection.enableFileSharing) { + initFileBufferReader(connection, function(fbr) { + rtcMultiSession.fileBufferReader = fbr; + }); + } + + var textReceiver = new TextReceiver(connection); + + function onDataChannelMessage(e) { + if (e.data.checkingPresence && connection.channels[e.userid]) { + connection.channels[e.userid].send({ + presenceDetected: true + }); + return; + } + + if (e.data.presenceDetected && connection.peers[e.userid]) { + connection.peers[e.userid].connected = true; + return; + } + + if (e.data.type === 'text') { + textReceiver.receive(e.data, e.userid, e.extra); + } else { + if (connection.autoTranslateText) { + e.original = e.data; + connection.Translator.TranslateText(e.data, function(translatedText) { + e.data = translatedText; + connection.onmessage(e); + }); + } else connection.onmessage(e); + } + } + + function onNewSession(session) { + if (connection.skipOnNewSession) return; + + if (!session.session) session.session = {}; + if (!session.extra) session.extra = {}; + + // todo: make sure this works as expected. + // i.e. "onNewSession" should be fired only for + // sessionid that is passed over "connect" method. + if (connection.sessionid && session.sessionid != connection.sessionid) return; + + if (connection.onNewSession) { + session.join = function(forceSession) { + if (!forceSession) return connection.join(session); + + for (var f in forceSession) { + session.session[f] = forceSession[f]; + } + + // keeping previous state + var isDontCaptureUserMedia = connection.dontCaptureUserMedia; + + connection.dontCaptureUserMedia = false; + connection.captureUserMedia(function() { + connection.dontCaptureUserMedia = true; + connection.join(session); + + // returning back previous state + connection.dontCaptureUserMedia = isDontCaptureUserMedia; + }, forceSession); + }; + if (!session.extra) session.extra = {}; + + return connection.onNewSession(session); + } + + connection.join(session); + } + + function updateSocketForLocalStreams(socket) { + for (var i = 0; i < connection.localStreamids.length; i++) { + var streamid = connection.localStreamids[i]; + if (connection.streams[streamid]) { + // using "sockets" array to keep references of all sockets using + // this media stream; so we can fire "onStreamEndedHandler" among all users. + connection.streams[streamid].sockets.push(socket); + } + } + } + + function newPrivateSocket(_config) { + var socketConfig = { + channel: _config.channel, + onmessage: socketResponse, + onopen: function(_socket) { + if (_socket) socket = _socket; + + if (isofferer && !peer) { + peerConfig.session = connection.session; + if (!peer) peer = new PeerConnection(); + peer.create('offer', peerConfig); + } + + _config.socketIndex = socket.index = sockets.length; + socketObjects[socketConfig.channel] = socket; + sockets[_config.socketIndex] = socket; + + updateSocketForLocalStreams(socket); + + if (!socket.__push) { + socket.__push = socket.send; + socket.send = function(message) { + message.userid = message.userid || connection.userid; + message.extra = message.extra || connection.extra || {}; + + socket.__push(message); + }; + } + } + }; + + socketConfig.callback = function(_socket) { + socket = _socket; + socketConfig.onopen(); + }; + + var socket = connection.openSignalingChannel(socketConfig); + if (socket) socketConfig.onopen(socket); + + var isofferer = _config.isofferer, + peer; + + var peerConfig = { + onopen: onChannelOpened, + onicecandidate: function(candidate) { + if (!connection.candidates) throw 'ICE candidates are mandatory.'; + if (!connection.iceProtocols) throw 'At least one must be true; UDP or TCP.'; + + var iceCandidates = connection.candidates; + + var stun = iceCandidates.stun; + var turn = iceCandidates.turn; + + if (!isNull(iceCandidates.reflexive)) stun = iceCandidates.reflexive; + if (!isNull(iceCandidates.relay)) turn = iceCandidates.relay; + + if (!iceCandidates.host && !!candidate.candidate.match(/a=candidate.*typ host/g)) return; + if (!turn && !!candidate.candidate.match(/a=candidate.*typ relay/g)) return; + if (!stun && !!candidate.candidate.match(/a=candidate.*typ srflx/g)) return; + + var protocol = connection.iceProtocols; + + if (!protocol.udp && !!candidate.candidate.match(/a=candidate.* udp/g)) return; + if (!protocol.tcp && !!candidate.candidate.match(/a=candidate.* tcp/g)) return; + + if (!window.selfNPObject) window.selfNPObject = candidate; + + socket && socket.send({ + candidate: JSON.stringify({ + candidate: candidate.candidate, + sdpMid: candidate.sdpMid, + sdpMLineIndex: candidate.sdpMLineIndex + }) + }); + }, + onmessage: function(data) { + if (!data) return; + + var abToStr = ab2str(data); + if (abToStr.indexOf('"userid":') != -1) { + abToStr = JSON.parse(abToStr); + onDataChannelMessage(abToStr); + } else if (data instanceof ArrayBuffer || data instanceof DataView) { + if (!connection.enableFileSharing) { + throw 'It seems that receiving data is either "Blob" or "File" but file sharing is disabled.'; + } + + if (!rtcMultiSession.fileBufferReader) { + var that = this; + initFileBufferReader(connection, function(fbr) { + rtcMultiSession.fileBufferReader = fbr; + that.onmessage(data); + }); + return; + } + + var fileBufferReader = rtcMultiSession.fileBufferReader; + + fileBufferReader.convertToObject(data, function(chunk) { + if (chunk.maxChunks || chunk.readyForNextChunk) { + // if target peer requested next chunk + if (chunk.readyForNextChunk) { + fileBufferReader.getNextChunk(chunk.uuid, function(nextChunk, isLastChunk, extra) { + rtcMultiSession.send(nextChunk); + }); + return; + } + + // if chunk is received + fileBufferReader.addChunk(chunk, function(promptNextChunk) { + // request next chunk + rtcMultiSession.send(promptNextChunk); + }); + return; + } + + connection.onmessage({ + data: chunk, + userid: _config.userid, + extra: _config.extra + }); + }); + return; + } + }, + onaddstream: function(stream, session) { + session = session || _config.renegotiate || connection.session; + + // if it is data-only connection; then return. + if (isData(session)) return; + + if (session.screen && (session.audio || session.video)) { + if (!_config.gotAudioOrVideo) { + // audio/video are fired earlier than screen + _config.gotAudioOrVideo = true; + session.screen = false; + } else { + // screen stream is always fired later + session.audio = false; + session.video = false; + } + } + + var preMuted = {}; + + if (_config.streaminfo) { + var streaminfo = _config.streaminfo.split('----'); + var strInfo = JSON.parse(streaminfo[streaminfo.length - 1]); + + if (!isIE) { + stream.streamid = strInfo.streamid; + stream.isScreen = !!strInfo.isScreen; + stream.isVideo = !!strInfo.isVideo; + stream.isAudio = !!strInfo.isAudio; + preMuted = strInfo.preMuted; + } + + streaminfo.pop(); + _config.streaminfo = streaminfo.join('----'); + } + + var mediaElement = createMediaElement(stream, merge({ + remote: true + }, session)); + + if (connection.setDefaultEventsForMediaElement) { + connection.setDefaultEventsForMediaElement(mediaElement, stream.streamid); + } + + if (!isPluginRTC && !stream.getVideoTracks().length) { + function eventListener() { + setTimeout(function() { + mediaElement.muted = false; + afterRemoteStreamStartedFlowing({ + mediaElement: mediaElement, + session: session, + stream: stream, + preMuted: preMuted + }); + }, 3000); + + mediaElement.removeEventListener('play', eventListener); + } + return mediaElement.addEventListener('play', eventListener, false); + } + + waitUntilRemoteStreamStartsFlowing({ + mediaElement: mediaElement, + session: session, + stream: stream, + preMuted: preMuted + }); + }, + + onremovestream: function(stream) { + if (stream && stream.streamid) { + stream = connection.streams[stream.streamid]; + if (stream) { + log('on:stream:ended via on:remove:stream', stream); + onStreamEndedHandler(stream, connection); + } + } else log('on:remove:stream', stream); + }, + + onclose: function(e) { + e.extra = _config.extra; + e.userid = _config.userid; + connection.onclose(e); + + // suggested in #71 by "efaj" + if (connection.channels[e.userid]) { + delete connection.channels[e.userid]; + } + }, + onerror: function(e) { + e.extra = _config.extra; + e.userid = _config.userid; + connection.onerror(e); + }, + + oniceconnectionstatechange: function(event) { + log('oniceconnectionstatechange', toStr(event)); + + if (peer.connection && peer.connection.iceConnectionState == 'connected' && peer.connection.iceGatheringState == 'complete' && peer.connection.signalingState == 'stable' && connection.numberOfConnectedUsers == 1) { + connection.onconnected({ + userid: _config.userid, + extra: _config.extra, + peer: connection.peers[_config.userid], + targetuser: _config.userinfo + }); + } + + if (!connection.isInitiator && peer.connection && peer.connection.iceConnectionState == 'connected' && peer.connection.iceGatheringState == 'complete' && peer.connection.signalingState == 'stable' && connection.numberOfConnectedUsers == 1) { + connection.onstatechange({ + userid: _config.userid, + extra: _config.extra, + name: 'connected-with-initiator', + reason: 'ICE connection state seems connected; gathering state is completed; and signaling state is stable.' + }); + } + + if (connection.peers[_config.userid] && connection.peers[_config.userid].oniceconnectionstatechange) { + connection.peers[_config.userid].oniceconnectionstatechange(event); + } + + // if ICE connectivity check is failed; renegotiate or redial + if (connection.peers[_config.userid] && connection.peers[_config.userid].peer.connection.iceConnectionState == 'failed') { + connection.onfailed({ + userid: _config.userid, + extra: _config.extra, + peer: connection.peers[_config.userid], + targetuser: _config.userinfo + }); + } + + if (connection.peers[_config.userid] && connection.peers[_config.userid].peer.connection.iceConnectionState == 'disconnected') { + !peer.connection.renegotiate && connection.ondisconnected({ + userid: _config.userid, + extra: _config.extra, + peer: connection.peers[_config.userid], + targetuser: _config.userinfo + }); + peer.connection.renegotiate = false; + } + + if (!connection.autoReDialOnFailure) return; + + if (connection.peers[_config.userid]) { + if (connection.peers[_config.userid].peer.connection.iceConnectionState != 'disconnected') { + _config.redialing = false; + } + + if (connection.peers[_config.userid].peer.connection.iceConnectionState == 'disconnected' && !_config.redialing) { + _config.redialing = true; + warn('Peer connection is closed.', toStr(connection.peers[_config.userid].peer.connection), 'ReDialing..'); + connection.peers[_config.userid].socket.send({ + redial: true + }); + + // to make sure all old "remote" streams are also removed! + connection.streams.remove({ + remote: true, + userid: _config.userid + }); + } + } + }, + + onsignalingstatechange: function(event) { + log('onsignalingstatechange', toStr(event)); + }, + + attachStreams: connection.dontAttachStream ? [] : connection.attachStreams, + iceServers: connection.iceServers, + rtcConfiguration: connection.rtcConfiguration, + bandwidth: connection.bandwidth, + sdpConstraints: connection.sdpConstraints, + optionalArgument: connection.optionalArgument, + disableDtlsSrtp: connection.disableDtlsSrtp, + dataChannelDict: connection.dataChannelDict, + preferSCTP: connection.preferSCTP, + + onSessionDescription: function(sessionDescription, streaminfo) { + sendsdp({ + sdp: sessionDescription, + socket: socket, + streaminfo: streaminfo + }); + }, + trickleIce: connection.trickleIce, + processSdp: connection.processSdp, + sendStreamId: function(stream) { + socket && socket.send({ + streamid: stream.streamid, + isScreen: !!stream.isScreen, + isAudio: !!stream.isAudio, + isVideo: !!stream.isVideo + }); + }, + rtcMultiConnection: connection + }; + + function waitUntilRemoteStreamStartsFlowing(args) { + // chrome for android may have some features missing + if (isMobileDevice || isPluginRTC || (isNull(connection.waitUntilRemoteStreamStartsFlowing) || !connection.waitUntilRemoteStreamStartsFlowing)) { + return afterRemoteStreamStartedFlowing(args); + } + + if (!args.numberOfTimes) args.numberOfTimes = 0; + args.numberOfTimes++; + + if (!(args.mediaElement.readyState <= HTMLMediaElement.HAVE_CURRENT_DATA || args.mediaElement.paused || args.mediaElement.currentTime <= 0)) { + return afterRemoteStreamStartedFlowing(args); + } + + if (args.numberOfTimes >= 60) { // wait 60 seconds while video is delivered! + return socket.send({ + failedToReceiveRemoteVideo: true, + streamid: args.stream.streamid + }); + } + + setTimeout(function() { + log('Waiting for incoming remote stream to be started flowing: ' + args.numberOfTimes + ' seconds.'); + waitUntilRemoteStreamStartsFlowing(args); + }, 900); + } + + function initFakeChannel() { + if (!connection.fakeDataChannels || connection.channels[_config.userid]) return; + + // for non-data connections; allow fake data sender! + if (!connection.session.data) { + var fakeChannel = { + send: function(data) { + socket.send({ + fakeData: data + }); + }, + readyState: 'open' + }; + // connection.channels['user-id'].send(data); + connection.channels[_config.userid] = { + channel: fakeChannel, + send: function(data) { + this.channel.send(data); + } + }; + peerConfig.onopen(fakeChannel); + } + } + + function afterRemoteStreamStartedFlowing(args) { + var mediaElement = args.mediaElement; + var session = args.session; + var stream = args.stream; + + stream.onended = function() { + if (streamedObject.mediaElement && !streamedObject.mediaElement.parentNode && document.getElementById(stream.streamid)) { + streamedObject.mediaElement = document.getElementById(stream.streamid); + } + + onStreamEndedHandler(streamedObject, connection); + }; + + var streamedObject = { + mediaElement: mediaElement, + + stream: stream, + streamid: stream.streamid, + session: session || connection.session, + + blobURL: isPluginRTC ? '' : mediaElement.mozSrcObject ? URL.createObjectURL(stream) : mediaElement.src, + type: 'remote', + + extra: _config.extra, + userid: _config.userid, + + isVideo: isPluginRTC ? !!session.video : !!stream.isVideo, + isAudio: isPluginRTC ? !!session.audio && !session.video : !!stream.isAudio, + isScreen: !!stream.isScreen, + isInitiator: !!_config.isInitiator, + + rtcMultiConnection: connection, + socket: socket + }; + + // connection.streams['stream-id'].mute({audio:true}) + connection.streams[stream.streamid] = connection._getStream(streamedObject); + connection.onstream(streamedObject); + + if (!isEmpty(args.preMuted) && (args.preMuted.audio || args.preMuted.video)) { + var fakeObject = merge({}, streamedObject); + fakeObject.session = merge(fakeObject.session, args.preMuted); + + fakeObject.isAudio = !!fakeObject.session.audio && !fakeObject.session.video; + fakeObject.isVideo = !!fakeObject.session.video; + fakeObject.isScreen = false; + + connection.onmute(fakeObject); + } + + log('on:add:stream', streamedObject); + + onSessionOpened(); + + if (connection.onspeaking) { + initHark({ + stream: stream, + streamedObject: streamedObject, + connection: connection + }); + } + } + + function onChannelOpened(channel) { + _config.channel = channel; + + // connection.channels['user-id'].send(data); + connection.channels[_config.userid] = { + channel: _config.channel, + send: function(data) { + connection.send(data, this.channel); + } + }; + + connection.onopen({ + extra: _config.extra, + userid: _config.userid, + channel: channel + }); + + // fetch files from file-queue + for (var q in connection.fileQueue) { + connection.send(connection.fileQueue[q], channel); + } + + if (isData(connection.session)) onSessionOpened(); + + if (connection.partOfScreen && connection.partOfScreen.sharing) { + connection.peers[_config.userid].sharePartOfScreen(connection.partOfScreen); + } + } + + function updateSocket() { + // todo: need to check following {if-block} MUST not affect "redial" process + if (socket.userid == _config.userid) + return; + + socket.userid = _config.userid; + sockets[_config.socketIndex] = socket; + + connection.numberOfConnectedUsers++; + // connection.peers['user-id'].addStream({audio:true}) + connection.peers[_config.userid] = { + socket: socket, + peer: peer, + userid: _config.userid, + extra: _config.extra, + userinfo: _config.userinfo, + addStream: function(session00) { + // connection.peers['user-id'].addStream({audio: true, video: true); + + connection.addStream(session00, this.socket); + }, + removeStream: function(streamid) { + if (!connection.streams[streamid]) + return warn('No such stream exists. Stream-id:', streamid); + + this.peer.connection.removeStream(connection.streams[streamid].stream); + this.renegotiate(); + }, + renegotiate: function(stream, session) { + // connection.peers['user-id'].renegotiate(); + + connection.renegotiate(stream, session); + }, + changeBandwidth: function(bandwidth) { + // connection.peers['user-id'].changeBandwidth(); + + if (!bandwidth) throw 'You MUST pass bandwidth object.'; + if (isString(bandwidth)) throw 'Pass object for bandwidth instead of string; e.g. {audio:10, video:20}'; + + // set bandwidth for self + this.peer.bandwidth = bandwidth; + + // ask remote user to synchronize bandwidth + this.socket.send({ + changeBandwidth: true, + bandwidth: bandwidth + }); + }, + sendCustomMessage: function(message) { + // connection.peers['user-id'].sendCustomMessage(); + + this.socket.send({ + customMessage: true, + message: message + }); + }, + onCustomMessage: function(message) { + log('Received "private" message from', this.userid, + isString(message) ? message : toStr(message)); + }, + drop: function(dontSendMessage) { + // connection.peers['user-id'].drop(); + + for (var stream in connection.streams) { + if (connection._skip.indexOf(stream) == -1) { + stream = connection.streams[stream]; + + if (stream.userid == connection.userid && stream.type == 'local') { + this.peer.connection.removeStream(stream.stream); + onStreamEndedHandler(stream, connection); + } + + if (stream.type == 'remote' && stream.userid == this.userid) { + onStreamEndedHandler(stream, connection); + } + } + } + + !dontSendMessage && this.socket.send({ + drop: true + }); + }, + hold: function(holdMLine) { + // connection.peers['user-id'].hold(); + + if (peer.prevCreateType == 'answer') { + this.socket.send({ + unhold: true, + holdMLine: holdMLine || 'both', + takeAction: true + }); + return; + } + + this.socket.send({ + hold: true, + holdMLine: holdMLine || 'both' + }); + + this.peer.hold = true; + this.fireHoldUnHoldEvents({ + kind: holdMLine, + isHold: true, + userid: connection.userid, + remoteUser: this.userid + }); + }, + unhold: function(holdMLine) { + // connection.peers['user-id'].unhold(); + + if (peer.prevCreateType == 'answer') { + this.socket.send({ + unhold: true, + holdMLine: holdMLine || 'both', + takeAction: true + }); + return; + } + + this.socket.send({ + unhold: true, + holdMLine: holdMLine || 'both' + }); + + this.peer.hold = false; + this.fireHoldUnHoldEvents({ + kind: holdMLine, + isHold: false, + userid: connection.userid, + remoteUser: this.userid + }); + }, + fireHoldUnHoldEvents: function(e) { + // this method is for inner usages only! + + var isHold = e.isHold; + var kind = e.kind; + var userid = e.remoteUser || e.userid; + + // hold means inactive a specific media line! + // a media line can contain multiple synced sources (ssrc) + // i.e. a media line can reference multiple tracks! + // that's why hold will affect all relevant tracks in a specific media line! + for (var stream in connection.streams) { + if (connection._skip.indexOf(stream) == -1) { + stream = connection.streams[stream]; + + if (stream.userid == userid) { + // www.RTCMultiConnection.org/docs/onhold/ + if (isHold) + connection.onhold(merge({ + kind: kind + }, stream)); + + // www.RTCMultiConnection.org/docs/onunhold/ + if (!isHold) + connection.onunhold(merge({ + kind: kind + }, stream)); + } + } + } + }, + redial: function() { + // connection.peers['user-id'].redial(); + + // 1st of all; remove all relevant remote media streams + for (var stream in connection.streams) { + if (connection._skip.indexOf(stream) == -1) { + stream = connection.streams[stream]; + + if (stream.userid == this.userid && stream.type == 'remote') { + onStreamEndedHandler(stream, connection); + } + } + } + + log('ReDialing...'); + + socket.send({ + recreatePeer: true + }); + + peer = new PeerConnection(); + peer.create('offer', peerConfig); + }, + sharePartOfScreen: function(args) { + // www.RTCMultiConnection.org/docs/onpartofscreen/ + var that = this; + var lastScreenshot = ''; + + function partOfScreenCapturer() { + // if stopped + if (that.stopPartOfScreenSharing) { + that.stopPartOfScreenSharing = false; + + if (connection.onpartofscreenstopped) { + connection.onpartofscreenstopped(); + } + return; + } + + // if paused + if (that.pausePartOfScreenSharing) { + if (connection.onpartofscreenpaused) { + connection.onpartofscreenpaused(); + } + + return setTimeout(partOfScreenCapturer, args.interval || 200); + } + + capturePartOfScreen({ + element: args.element, + connection: connection, + callback: function(screenshot) { + if (!connection.channels[that.userid]) { + throw 'No such data channel exists.'; + } + + // don't share repeated content + if (screenshot != lastScreenshot) { + lastScreenshot = screenshot; + connection.channels[that.userid].send({ + screenshot: screenshot, + isPartOfScreen: true + }); + } + + // "once" can be used to share single screenshot + !args.once && setTimeout(partOfScreenCapturer, args.interval || 200); + } + }); + } + + partOfScreenCapturer(); + }, + getConnectionStats: function(callback, interval) { + if (!callback) throw 'callback is mandatory.'; + + if (!window.getConnectionStats) { + loadScript(connection.resources.getConnectionStats, invoker); + } else invoker(); + + function invoker() { + RTCPeerConnection.prototype.getConnectionStats = window.getConnectionStats; + peer.connection && peer.connection.getConnectionStats(callback, interval); + } + }, + takeSnapshot: function(callback) { + takeSnapshot({ + userid: this.userid, + connection: connection, + callback: callback + }); + } + }; + } + + function onSessionOpened() { + // original conferencing infrastructure! + if (connection.isInitiator && getLength(participants) && getLength(participants) <= connection.maxParticipantsAllowed) { + if (!connection.session.oneway && !connection.session.broadcast) { + defaultSocket.send({ + sessionid: connection.sessionid, + newParticipant: _config.userid || socket.channel, + userData: { + userid: _config.userid || socket.channel, + extra: _config.extra + } + }); + } + } + + // 1st: renegotiation is supported only on chrome + // 2nd: must not renegotiate same media multiple times + // 3rd: todo: make sure that target-user has no such "renegotiated" media. + if (_config.userinfo.browser == 'chrome' && !_config.renegotiatedOnce) { + // this code snippet is added to make sure that "previously-renegotiated" streams are also + // renegotiated to this new user + for (var rSession in connection.renegotiatedSessions) { + _config.renegotiatedOnce = true; + + if (connection.renegotiatedSessions[rSession] && connection.renegotiatedSessions[rSession].stream) { + connection.peers[_config.userid].renegotiate(connection.renegotiatedSessions[rSession].stream, connection.renegotiatedSessions[rSession].session); + } + } + } + } + + function socketResponse(response) { + if (isRMSDeleted) return; + + if (response.userid == connection.userid) + return; + + if (response.sdp) { + _config.userid = response.userid; + _config.extra = response.extra || {}; + _config.renegotiate = response.renegotiate; + _config.streaminfo = response.streaminfo; + _config.isInitiator = response.isInitiator; + _config.userinfo = response.userinfo; + + var sdp = JSON.parse(response.sdp); + + if (sdp.type == 'offer') { + // to synchronize SCTP or RTP + peerConfig.preferSCTP = !!response.preferSCTP; + connection.fakeDataChannels = !!response.fakeDataChannels; + } + + // initializing fake channel + initFakeChannel(); + + sdpInvoker(sdp, response.labels); + } + + if (response.candidate) { + peer && peer.addIceCandidate(JSON.parse(response.candidate)); + } + + if (response.streamid) { + if (!rtcMultiSession.streamids) { + rtcMultiSession.streamids = {}; + } + if (!rtcMultiSession.streamids[response.streamid]) { + rtcMultiSession.streamids[response.streamid] = response.streamid; + connection.onstreamid(response); + } + } + + if (response.mute || response.unmute) { + if (response.promptMuteUnmute) { + if (!connection.privileges.canMuteRemoteStream) { + connection.onstatechange({ + userid: response.userid, + extra: response.extra, + name: 'mute-request-denied', + reason: response.userid + ' tried to mute your stream; however "privileges.canMuteRemoteStream" is "false".' + }); + return; + } + + if (connection.streams[response.streamid]) { + if (response.mute && !connection.streams[response.streamid].muted) { + connection.streams[response.streamid].mute(response.session); + } + if (response.unmute && connection.streams[response.streamid].muted) { + connection.streams[response.streamid].unmute(response.session); + } + } + } else { + var streamObject = {}; + if (connection.streams[response.streamid]) { + streamObject = connection.streams[response.streamid]; + } + + var session = response.session; + var fakeObject = merge({}, streamObject); + fakeObject.session = session; + + fakeObject.isAudio = !!fakeObject.session.audio && !fakeObject.session.video; + fakeObject.isVideo = !!fakeObject.session.video; + fakeObject.isScreen = !!fakeObject.session.screen; + + if (response.mute) connection.onmute(fakeObject || response); + if (response.unmute) connection.onunmute(fakeObject || response); + } + } + + if (response.isVolumeChanged) { + log('Volume of stream: ' + response.streamid + ' has changed to: ' + response.volume); + if (connection.streams[response.streamid]) { + var mediaElement = connection.streams[response.streamid].mediaElement; + if (mediaElement) mediaElement.volume = response.volume; + } + } + + // to stop local stream + if (response.stopped) { + if (connection.streams[response.streamid]) { + onStreamEndedHandler(connection.streams[response.streamid], connection); + } + } + + // to stop remote stream + if (response.promptStreamStop /* && !connection.isInitiator */ ) { + if (!connection.privileges.canStopRemoteStream) { + connection.onstatechange({ + userid: response.userid, + extra: response.extra, + name: 'stop-request-denied', + reason: response.userid + ' tried to stop your stream; however "privileges.canStopRemoteStream" is "false".' + }); + return; + } + warn('Remote stream has been manually stopped!'); + if (connection.streams[response.streamid]) { + connection.streams[response.streamid].stop(); + } + } + + if (response.left) { + // firefox is unable to stop remote streams + // firefox doesn't auto stop streams when peer.close() is called. + if (isFirefox) { + var userLeft = response.userid; + for (var stream in connection.streams) { + stream = connection.streams[stream]; + if (stream.userid == userLeft) { + connection.stopMediaStream(stream); + onStreamEndedHandler(stream, connection); + } + } + } + + if (peer && peer.connection) { + // todo: verify if-block's 2nd condition + if (peer.connection.signalingState != 'closed' && peer.connection.iceConnectionState.search(/disconnected|failed/gi) == -1) { + peer.connection.close(); + } + peer.connection = null; + } + + if (participants[response.userid]) delete participants[response.userid]; + + if (response.closeEntireSession) { + connection.onSessionClosed(response); + connection.leave(); + return; + } + + connection.remove(response.userid); + + onLeaveHandler({ + userid: response.userid, + extra: response.extra || {}, + entireSessionClosed: !!response.closeEntireSession + }, connection); + } + + // keeping session active even if initiator leaves + if (response.playRoleOfBroadcaster) { + if (response.extra) { + // clone extra-data from initial moderator + connection.extra = merge(connection.extra, response.extra); + } + if (response.participants) { + participants = response.participants; + + // make sure that if 2nd initiator leaves; control is shifted to 3rd person. + if (participants[connection.userid]) { + delete participants[connection.userid]; + } + + if (sockets[0] && sockets[0].userid == response.userid) { + delete sockets[0]; + sockets = swap(sockets); + } + + if (socketObjects[response.userid]) { + delete socketObjects[response.userid]; + } + } + + setTimeout(connection.playRoleOfInitiator, 2000); + } + + if (response.changeBandwidth) { + if (!connection.peers[response.userid]) throw 'No such peer exists.'; + + // synchronize bandwidth + connection.peers[response.userid].peer.bandwidth = response.bandwidth; + + // renegotiate to apply bandwidth + connection.peers[response.userid].renegotiate(); + } + + if (response.customMessage) { + if (!connection.peers[response.userid]) throw 'No such peer exists.'; + if (response.message.ejected) { + if (connection.sessionDescriptions[connection.sessionid].userid != response.userid) { + throw 'only initiator can eject a user.'; + } + // initiator ejected this user + connection.leave(); + + connection.onSessionClosed({ + userid: response.userid, + extra: response.extra || _config.extra, + isEjected: true + }); + } else connection.peers[response.userid].onCustomMessage(response.message); + } + + if (response.drop) { + if (!connection.peers[response.userid]) throw 'No such peer exists.'; + connection.peers[response.userid].drop(true); + connection.peers[response.userid].renegotiate(); + + connection.ondrop(response.userid); + } + + if (response.hold || response.unhold) { + if (!connection.peers[response.userid]) throw 'No such peer exists.'; + + if (response.takeAction) { + connection.peers[response.userid][!!response.hold ? 'hold' : 'unhold'](response.holdMLine); + return; + } + + connection.peers[response.userid].peer.hold = !!response.hold; + connection.peers[response.userid].peer.holdMLine = response.holdMLine; + + socket.send({ + isRenegotiate: true + }); + + connection.peers[response.userid].fireHoldUnHoldEvents({ + kind: response.holdMLine, + isHold: !!response.hold, + userid: response.userid + }); + } + + if (response.isRenegotiate) { + connection.peers[response.userid].renegotiate(null, connection.peers[response.userid].peer.session); + } + + // fake data channels! + if (response.fakeData) { + peerConfig.onmessage(response.fakeData); + } + + // sometimes we don't need to renegotiate e.g. when peers are disconnected + // or if it is firefox + if (response.recreatePeer) { + peer = new PeerConnection(); + } + + // remote video failed either out of ICE gathering process or ICE connectivity check-up + // or IceAgent was unable to locate valid candidates/ports. + if (response.failedToReceiveRemoteVideo) { + log('Remote peer hasn\'t received stream: ' + response.streamid + '. Renegotiating...'); + if (connection.peers[response.userid]) { + connection.peers[response.userid].renegotiate(); + } + } + + if (response.redial) { + if (connection.peers[response.userid]) { + if (connection.peers[response.userid].peer.connection.iceConnectionState != 'disconnected') { + _config.redialing = false; + } + + if (connection.peers[response.userid].peer.connection.iceConnectionState == 'disconnected' && !_config.redialing) { + _config.redialing = true; + + warn('Peer connection is closed.', toStr(connection.peers[response.userid].peer.connection), 'ReDialing..'); + connection.peers[response.userid].redial(); + } + } + } + } + + connection.playRoleOfInitiator = function() { + connection.dontCaptureUserMedia = true; + connection.open(); + sockets = swap(sockets); + connection.dontCaptureUserMedia = false; + }; + + connection.askToShareParticipants = function() { + defaultSocket && defaultSocket.send({ + askToShareParticipants: true + }); + }; + + connection.shareParticipants = function(args) { + var message = { + joinUsers: participants, + userid: connection.userid, + extra: connection.extra + }; + + if (args) { + if (args.dontShareWith) message.dontShareWith = args.dontShareWith; + if (args.shareWith) message.shareWith = args.shareWith; + } + + defaultSocket.send(message); + }; + + function sdpInvoker(sdp, labels) { + if (sdp.type == 'answer') { + peer.setRemoteDescription(sdp); + updateSocket(); + return; + } + if (!_config.renegotiate && sdp.type == 'offer') { + peerConfig.offerDescription = sdp; + + peerConfig.session = connection.session; + if (!peer) peer = new PeerConnection(); + peer.create('answer', peerConfig); + + updateSocket(); + return; + } + + var session = _config.renegotiate; + // detach streams + detachMediaStream(labels, peer.connection); + + if (session.oneway || isData(session)) { + createAnswer(); + delete _config.renegotiate; + } else { + if (_config.capturing) + return; + + _config.capturing = true; + + connection.captureUserMedia(function(stream) { + _config.capturing = false; + + peer.addStream(stream); + + connection.renegotiatedSessions[JSON.stringify(_config.renegotiate)] = { + session: _config.renegotiate, + stream: stream + }; + + delete _config.renegotiate; + + createAnswer(); + }, _config.renegotiate); + } + + function createAnswer() { + peer.recreateAnswer(sdp, session, function(_sdp, streaminfo) { + sendsdp({ + sdp: _sdp, + socket: socket, + streaminfo: streaminfo + }); + connection.detachStreams = []; + }); + } + } + } + + function detachMediaStream(labels, peer) { + if (!labels) return; + for (var i = 0; i < labels.length; i++) { + var label = labels[i]; + if (connection.streams[label]) { + peer.removeStream(connection.streams[label].stream); + } + } + } + + function sendsdp(e) { + e.socket.send({ + sdp: JSON.stringify({ + sdp: e.sdp.sdp, + type: e.sdp.type + }), + renegotiate: !!e.renegotiate ? e.renegotiate : false, + streaminfo: e.streaminfo || '', + labels: e.labels || [], + preferSCTP: !!connection.preferSCTP, + fakeDataChannels: !!connection.fakeDataChannels, + isInitiator: !!connection.isInitiator, + userinfo: { + browser: isFirefox ? 'firefox' : 'chrome' + } + }); + } + + // sharing new user with existing participants + + function onNewParticipant(response) { + var channel = response.newParticipant; + + if (!channel || !!participants[channel] || channel == connection.userid) + return; + + var new_channel = connection.token(); + newPrivateSocket({ + channel: new_channel, + extra: response.userData ? response.userData.extra : response.extra, + userid: response.userData ? response.userData.userid : response.userid + }); + + defaultSocket.send({ + participant: true, + targetUser: channel, + channel: new_channel + }); + } + + // if a user leaves + + function clearSession() { + connection.numberOfConnectedUsers--; + + var alertMessage = { + left: true, + extra: connection.extra || {}, + userid: connection.userid, + sessionid: connection.sessionid + }; + + if (connection.isInitiator) { + // if initiator wants to close entire session + if (connection.autoCloseEntireSession) { + alertMessage.closeEntireSession = true; + } else if (sockets[0]) { + // shift initiation control to another user + sockets[0].send({ + playRoleOfBroadcaster: true, + userid: connection.userid, + extra: connection.extra, + participants: participants + }); + } + } + + sockets.forEach(function(socket, i) { + socket.send(alertMessage); + + if (socketObjects[socket.channel]) { + delete socketObjects[socket.channel]; + } + + delete sockets[i]; + }); + + sockets = swap(sockets); + + connection.refresh(); + + webAudioMediaStreamSources.forEach(function(mediaStreamSource) { + // if source is connected; then chrome will crash on unload. + mediaStreamSource.disconnect(); + }); + + webAudioMediaStreamSources = []; + } + + // www.RTCMultiConnection.org/docs/remove/ + connection.remove = function(userid) { + if (rtcMultiSession.requestsFrom && rtcMultiSession.requestsFrom[userid]) delete rtcMultiSession.requestsFrom[userid]; + + if (connection.peers[userid]) { + if (connection.peers[userid].peer && connection.peers[userid].peer.connection) { + if (connection.peers[userid].peer.connection.signalingState != 'closed') { + connection.peers[userid].peer.connection.close(); + } + connection.peers[userid].peer.connection = null; + } + delete connection.peers[userid]; + } + if (participants[userid]) { + delete participants[userid]; + } + + for (var stream in connection.streams) { + stream = connection.streams[stream]; + if (stream.userid == userid) { + onStreamEndedHandler(stream, connection); + delete connection.streams[stream]; + } + } + + if (socketObjects[userid]) { + delete socketObjects[userid]; + } + }; + + // www.RTCMultiConnection.org/docs/refresh/ + connection.refresh = function() { + // if firebase; remove data from firebase servers + if (connection.isInitiator && !!connection.socket && !!connection.socket.remove) { + connection.socket.remove(); + } + + participants = {}; + + // to stop/remove self streams + for (var i = 0; i < connection.attachStreams.length; i++) { + connection.stopMediaStream(connection.attachStreams[i]); + } + + // to allow capturing of identical streams + currentUserMediaRequest = { + streams: [], + mutex: false, + queueRequests: [] + }; + + rtcMultiSession.isOwnerLeaving = true; + + connection.isInitiator = false; + connection.isAcceptNewSession = true; + connection.attachMediaStreams = []; + connection.sessionDescription = null; + connection.sessionDescriptions = {}; + connection.localStreamids = []; + connection.preRecordedMedias = {}; + connection.snapshots = {}; + + connection.numberOfConnectedUsers = 0; + connection.numberOfSessions = 0; + + connection.attachStreams = []; + connection.detachStreams = []; + connection.fileQueue = {}; + connection.channels = {}; + connection.renegotiatedSessions = {}; + + for (var peer in connection.peers) { + if (peer != connection.userid) { + delete connection.peers[peer]; + } + } + + // to make sure remote streams are also removed! + for (var stream in connection.streams) { + if (connection._skip.indexOf(stream) == -1) { + onStreamEndedHandler(connection.streams[stream], connection); + delete connection.streams[stream]; + } + } + + socketObjects = {}; + sockets = []; + participants = {}; + }; + + // www.RTCMultiConnection.org/docs/reject/ + connection.reject = function(userid) { + if (!isString(userid)) userid = userid.userid; + defaultSocket.send({ + rejectedRequestOf: userid + }); + + // remove relevant data to allow him join again + connection.remove(userid); + }; + + rtcMultiSession.leaveHandler = function(e) { + if (!connection.leaveOnPageUnload) return; + + if (isNull(e.keyCode)) { + return clearSession(); + } + + if (e.keyCode == 116) { + clearSession(); + } + }; + + listenEventHandler('beforeunload', rtcMultiSession.leaveHandler); + listenEventHandler('keyup', rtcMultiSession.leaveHandler); + + rtcMultiSession.onLineOffLineHandler = function() { + if (!navigator.onLine) { + rtcMultiSession.isOffLine = true; + } else if (rtcMultiSession.isOffLine) { + rtcMultiSession.isOffLine = !navigator.onLine; + + // defaultSocket = getDefaultSocketRef(); + + // pending tasks should be resumed? + // sockets should be reconnected? + // peers should be re-established? + } + }; + + listenEventHandler('load', rtcMultiSession.onLineOffLineHandler); + listenEventHandler('online', rtcMultiSession.onLineOffLineHandler); + listenEventHandler('offline', rtcMultiSession.onLineOffLineHandler); + + function onSignalingReady() { + if (rtcMultiSession.signalingReady) return; + rtcMultiSession.signalingReady = true; + + setTimeout(callbackForSignalingReady, 1000); + + if (!connection.isInitiator) { + // as soon as signaling gateway is connected; + // user should check existing rooms! + defaultSocket && defaultSocket.send({ + searchingForRooms: true + }); + } + } + + function joinParticipants(joinUsers) { + for (var user in joinUsers) { + if (!participants[joinUsers[user]]) { + onNewParticipant({ + sessionid: connection.sessionid, + newParticipant: joinUsers[user], + userid: connection.userid, + extra: connection.extra + }); + } + } + } + + function getDefaultSocketRef() { + return connection.openSignalingChannel({ + onmessage: function(response) { + // RMS == RTCMultiSession + if (isRMSDeleted) return; + + // if message is sent by same user + if (response.userid == connection.userid) return; + + if (response.sessionid && response.userid) { + if (!connection.sessionDescriptions[response.sessionid]) { + connection.numberOfSessions++; + connection.sessionDescriptions[response.sessionid] = response; + + // fire "onNewSession" only if: + // 1) "isAcceptNewSession" boolean is true + // 2) "sessionDescriptions" object isn't having same session i.e. to prevent duplicate invocations + if (connection.isAcceptNewSession) { + + if (!connection.dontOverrideSession) { + connection.session = response.session; + } + + onNewSession(response); + } + } + } + + if (response.newParticipant && !connection.isAcceptNewSession && rtcMultiSession.broadcasterid === response.userid) { + if (response.newParticipant != connection.userid) { + onNewParticipant(response); + } + } + + if (getLength(participants) < connection.maxParticipantsAllowed && response.targetUser == connection.userid && response.participant) { + if (connection.peers[response.userid] && !connection.peers[response.userid].peer) { + delete participants[response.userid]; + delete connection.peers[response.userid]; + connection.isAcceptNewSession = true; + return acceptRequest(response); + } + + if (!participants[response.userid]) { + acceptRequest(response); + } + } + + if (response.acceptedRequestOf == connection.userid) { + connection.onstatechange({ + userid: response.userid, + extra: response.extra, + name: 'request-accepted', + reason: response.userid + ' accepted your participation request.' + }); + } + + if (response.rejectedRequestOf == connection.userid) { + connection.onstatechange({ + userid: response.userid, + extra: response.extra, + name: 'request-rejected', + reason: response.userid + ' rejected your participation request.' + }); + } + + if (response.customMessage) { + if (response.message.drop) { + connection.ondrop(response.userid); + + connection.attachStreams = []; + // "drop" should detach all local streams + for (var stream in connection.streams) { + if (connection._skip.indexOf(stream) == -1) { + stream = connection.streams[stream]; + if (stream.type == 'local') { + connection.detachStreams.push(stream.streamid); + onStreamEndedHandler(stream, connection); + } else onStreamEndedHandler(stream, connection); + } + } + + if (response.message.renegotiate) { + // renegotiate; so "peer.removeStream" happens. + connection.renegotiate(); + } + } else if (connection.onCustomMessage) { + connection.onCustomMessage(response.message); + } + } + + if (connection.isInitiator && response.searchingForRooms) { + defaultSocket && defaultSocket.send({ + sessionDescription: connection.sessionDescription, + responseFor: response.userid + }); + } + + if (response.sessionDescription && response.responseFor == connection.userid) { + var sessionDescription = response.sessionDescription; + if (!connection.sessionDescriptions[sessionDescription.sessionid]) { + connection.numberOfSessions++; + connection.sessionDescriptions[sessionDescription.sessionid] = sessionDescription; + } + } + + if (connection.isInitiator && response.askToShareParticipants && defaultSocket) { + connection.shareParticipants({ + shareWith: response.userid + }); + } + + // participants are shared with single user + if (response.shareWith == connection.userid && response.dontShareWith != connection.userid && response.joinUsers) { + joinParticipants(response.joinUsers); + } + + // participants are shared with all users + if (!response.shareWith && response.joinUsers) { + if (response.dontShareWith) { + if (connection.userid != response.dontShareWith) { + joinParticipants(response.joinUsers); + } + } else joinParticipants(response.joinUsers); + } + + if (response.messageFor == connection.userid && response.presenceState) { + if (response.presenceState == 'checking') { + defaultSocket.send({ + messageFor: response.userid, + presenceState: 'available', + _config: response._config + }); + log('participant asked for availability'); + } + + if (response.presenceState == 'available') { + rtcMultiSession.presenceState = 'available'; + + connection.onstatechange({ + userid: 'browser', + extra: {}, + name: 'room-available', + reason: 'Initiator is available and room is active.' + }); + + joinSession(response._config); + } + } + + if (response.donotJoin && response.messageFor == connection.userid) { + log(response.userid, 'is not joining your room.'); + } + + // if initiator disconnects sockets, participants should also disconnect + if (response.isDisconnectSockets) { + log('Disconnecting your sockets because initiator also disconnected his sockets.'); + connection.disconnect(); + } + }, + callback: function(socket) { + socket && this.onopen(socket); + }, + onopen: function(socket) { + if (socket) defaultSocket = socket; + if (onSignalingReady) onSignalingReady(); + + rtcMultiSession.defaultSocket = defaultSocket; + + if (!defaultSocket.__push) { + defaultSocket.__push = defaultSocket.send; + defaultSocket.send = function(message) { + message.userid = message.userid || connection.userid; + message.extra = message.extra || connection.extra || {}; + + defaultSocket.__push(message); + }; + } + } + }); + } + + // default-socket is a common socket shared among all users in a specific channel; + // to share participation requests; room descriptions; and other stuff. + var defaultSocket = getDefaultSocketRef(); + + rtcMultiSession.defaultSocket = defaultSocket; + + if (defaultSocket && onSignalingReady) setTimeout(onSignalingReady, 2000); + + if (connection.session.screen) { + loadScreenFrame(); + } + // CUSTOM CODE // + + /* Commenting this + connection.getExternalIceServers && loadIceFrame(function(iceServers) + { + connection.iceServers = connection.iceServers.concat(iceServers); + }); + */ + + // CUSTOM CODE // + + if (connection.log == false) connection.skipLogs(); + if (connection.onlog) { + log = warn = error = function() { + var log = {}; + var index = 0; + Array.prototype.slice.call(arguments).forEach(function(argument) { + log[index++] = toStr(argument); + }); + toStr = function(str) { + return str; + }; + connection.onlog(log); + }; + } + + function setDirections() { + var userMaxParticipantsAllowed = 0; + + // if user has set a custom max participant setting, remember it + if (connection.maxParticipantsAllowed != 256) { + userMaxParticipantsAllowed = connection.maxParticipantsAllowed; + } + + if (connection.direction == 'one-way') connection.session.oneway = true; + if (connection.direction == 'one-to-one') connection.maxParticipantsAllowed = 1; + if (connection.direction == 'one-to-many') connection.session.broadcast = true; + if (connection.direction == 'many-to-many') { + if (!connection.maxParticipantsAllowed || connection.maxParticipantsAllowed == 1) { + connection.maxParticipantsAllowed = 256; + } + } + + // if user has set a custom max participant setting, set it back + if (userMaxParticipantsAllowed && connection.maxParticipantsAllowed != 1) { + connection.maxParticipantsAllowed = userMaxParticipantsAllowed; + } + } + + // open new session + this.initSession = function(args) { + rtcMultiSession.isOwnerLeaving = false; + + setDirections(); + participants = {}; + + rtcMultiSession.isOwnerLeaving = false; + + if (!isNull(args.transmitRoomOnce)) { + connection.transmitRoomOnce = args.transmitRoomOnce; + } + + function transmit() { + if (defaultSocket && getLength(participants) < connection.maxParticipantsAllowed && !rtcMultiSession.isOwnerLeaving) { + defaultSocket.send(connection.sessionDescription); + } + + if (!connection.transmitRoomOnce && !rtcMultiSession.isOwnerLeaving) + setTimeout(transmit, connection.interval || 3000); + } + + // todo: test and fix next line. + if (!args.dontTransmit /* || connection.transmitRoomOnce */ ) transmit(); + }; + + function joinSession(_config, skipOnStateChange) { + if (rtcMultiSession.donotJoin && rtcMultiSession.donotJoin == _config.sessionid) { + return; + } + + // dontOverrideSession allows you force RTCMultiConnection + // to not override default session for participants; + // by default, session is always overridden and set to the session coming from initiator! + if (!connection.dontOverrideSession) { + connection.session = _config.session || {}; + } + + // make sure that inappropriate users shouldn't receive onNewSession event + rtcMultiSession.broadcasterid = _config.userid; + + if (_config.sessionid) { + // used later to prevent external rooms messages to be used by this user! + connection.sessionid = _config.sessionid; + } + + connection.isAcceptNewSession = false; + + var channel = getRandomString(); + newPrivateSocket({ + channel: channel, + extra: _config.extra || {}, + userid: _config.userid + }); + + var offers = {}; + if (connection.attachStreams.length) { + var stream = connection.attachStreams[connection.attachStreams.length - 1]; + if (!!stream.getAudioTracks && stream.getAudioTracks().length) { + offers.audio = true; + } + if (stream.getVideoTracks().length) { + offers.video = true; + } + } + + if (!isEmpty(offers)) { + log(toStr(offers)); + } else log('Seems data-only connection.'); + + connection.onstatechange({ + userid: _config.userid, + extra: {}, + name: 'connecting-with-initiator', + reason: 'Checking presence of the initiator; and the room.' + }); + + defaultSocket.send({ + participant: true, + channel: channel, + targetUser: _config.userid, + session: connection.session, + offers: { + audio: !!offers.audio, + video: !!offers.video + } + }); + + connection.skipOnNewSession = false; + invokeMediaCaptured(connection); + } + + // join existing session + this.joinSession = function(_config) { + if (!defaultSocket) + return setTimeout(function() { + warn('Default-Socket is not yet initialized.'); + rtcMultiSession.joinSession(_config); + }, 1000); + + _config = _config || {}; + participants = {}; + + rtcMultiSession.presenceState = 'checking'; + + connection.onstatechange({ + userid: _config.userid, + extra: _config.extra || {}, + name: 'detecting-room-presence', + reason: 'Checking presence of the room.' + }); + + function contactInitiator() { + defaultSocket.send({ + messageFor: _config.userid, + presenceState: rtcMultiSession.presenceState, + _config: { + userid: _config.userid, + extra: _config.extra || {}, + sessionid: _config.sessionid, + session: _config.session || false + } + }); + } + contactInitiator(); + + function checker() { + if (rtcMultiSession.presenceState == 'checking') { + warn('Unable to reach initiator. Trying again...'); + contactInitiator(); + setTimeout(function() { + if (rtcMultiSession.presenceState == 'checking') { + connection.onstatechange({ + userid: _config.userid, + extra: _config.extra || {}, + name: 'room-not-available', + reason: 'Initiator seems absent. Waiting for someone to open the room.' + }); + + connection.isAcceptNewSession = true; + setTimeout(checker, 2000); + } + }, 2000); + } + } + + setTimeout(checker, 3000); + }; + + connection.donotJoin = function(sessionid) { + rtcMultiSession.donotJoin = sessionid; + + var session = connection.sessionDescriptions[sessionid]; + if (!session) return; + + defaultSocket.send({ + donotJoin: true, + messageFor: session.userid, + sessionid: sessionid + }); + + participants = {}; + connection.isAcceptNewSession = true; + connection.sessionid = null; + }; + + // send file/data or text message + this.send = function(message, _channel) { + if (!(message instanceof ArrayBuffer || message instanceof DataView)) { + message = str2ab({ + extra: connection.extra, + userid: connection.userid, + data: message + }); + } + + if (_channel) { + if (_channel.readyState == 'open') { + _channel.send(message); + } + return; + } + + for (var dataChannel in connection.channels) { + var channel = connection.channels[dataChannel].channel; + if (channel.readyState == 'open') { + channel.send(message); + } + } + }; + + // leave session + this.leave = function() { + clearSession(); + }; + + // renegotiate new stream + this.addStream = function(e) { + var session = e.renegotiate; + + if (!connection.renegotiatedSessions[JSON.stringify(e.renegotiate)]) { + connection.renegotiatedSessions[JSON.stringify(e.renegotiate)] = { + session: e.renegotiate, + stream: e.stream + }; + } + + if (e.socket) { + if (e.socket.userid != connection.userid) { + addStream(connection.peers[e.socket.userid]); + } + } else { + for (var peer in connection.peers) { + if (peer != connection.userid) { + addStream(connection.peers[peer]); + } + } + } + + function addStream(_peer) { + var socket = _peer.socket; + + if (!socket) { + warn(_peer, 'doesn\'t has socket.'); + return; + } + + updateSocketForLocalStreams(socket); + + if (!_peer || !_peer.peer) { + throw 'No peer to renegotiate.'; + } + + var peer = _peer.peer; + + if (e.stream) { + if (!peer.attachStreams) { + peer.attachStreams = []; + } + + peer.attachStreams.push(e.stream); + } + + // detaching old streams + detachMediaStream(connection.detachStreams, peer.connection); + + if (e.stream && (session.audio || session.video || session.screen)) { + peer.addStream(e.stream); + } + + peer.recreateOffer(session, function(sdp, streaminfo) { + sendsdp({ + sdp: sdp, + socket: socket, + renegotiate: session, + labels: connection.detachStreams, + streaminfo: streaminfo + }); + connection.detachStreams = []; + }); + } + }; + + // www.RTCMultiConnection.org/docs/request/ + connection.request = function(userid, extra) { + connection.captureUserMedia(function() { + // open private socket that will be used to receive offer-sdp + newPrivateSocket({ + channel: connection.userid, + extra: extra || {}, + userid: userid + }); + + // ask other user to create offer-sdp + defaultSocket.send({ + participant: true, + targetUser: userid + }); + }); + }; + + function acceptRequest(response) { + if (!rtcMultiSession.requestsFrom) rtcMultiSession.requestsFrom = {}; + if (rtcMultiSession.requestsFrom[response.userid]) return; + + var obj = { + userid: response.userid, + extra: response.extra, + channel: response.channel || response.userid, + session: response.session || connection.session + }; + + // check how participant is willing to join + if (response.offers) { + if (response.offers.audio && response.offers.video) { + log('target user has both audio/video streams.'); + } else if (response.offers.audio && !response.offers.video) { + log('target user has only audio stream.'); + } else if (!response.offers.audio && response.offers.video) { + log('target user has only video stream.'); + } else { + log('target user has no stream; it seems one-way streaming or data-only connection.'); + } + + var mandatory = connection.sdpConstraints.mandatory; + if (isNull(mandatory.OfferToReceiveAudio)) { + connection.sdpConstraints.mandatory.OfferToReceiveAudio = !!response.offers.audio; + } + if (isNull(mandatory.OfferToReceiveVideo)) { + connection.sdpConstraints.mandatory.OfferToReceiveVideo = !!response.offers.video; + } + + log('target user\'s SDP has?', toStr(connection.sdpConstraints.mandatory)); + } + + rtcMultiSession.requestsFrom[response.userid] = obj; + + // www.RTCMultiConnection.org/docs/onRequest/ + if (connection.onRequest && connection.isInitiator) { + connection.onRequest(obj); + } else _accept(obj); + } + + function _accept(e) { + if (rtcMultiSession.captureUserMediaOnDemand) { + rtcMultiSession.captureUserMediaOnDemand = false; + connection.captureUserMedia(function() { + _accept(e); + + invokeMediaCaptured(connection); + }); + return; + } + + log('accepting request from', e.userid); + participants[e.userid] = e.userid; + newPrivateSocket({ + isofferer: true, + userid: e.userid, + channel: e.channel, + extra: e.extra || {}, + session: e.session || connection.session + }); + } + + // www.RTCMultiConnection.org/docs/accept/ + connection.accept = function(e) { + // for backward compatibility + if (arguments.length > 1 && isString(arguments[0])) { + e = {}; + if (arguments[0]) e.userid = arguments[0]; + if (arguments[1]) e.extra = arguments[1]; + if (arguments[2]) e.channel = arguments[2]; + } + + connection.captureUserMedia(function() { + _accept(e); + }); + }; + + var isRMSDeleted = false; + this.disconnect = function() { + this.isOwnerLeaving = true; + + if (!connection.keepStreamsOpened) { + for (var streamid in connection.localStreams) { + connection.localStreams[streamid].stop(); + } + connection.localStreams = {}; + + currentUserMediaRequest = { + streams: [], + mutex: false, + queueRequests: [] + }; + } + + if (connection.isInitiator) { + defaultSocket.send({ + isDisconnectSockets: true + }); + } + + connection.refresh(); + + rtcMultiSession.defaultSocket = defaultSocket = null; + isRMSDeleted = true; + + connection.ondisconnected({ + userid: connection.userid, + extra: connection.extra, + peer: connection.peers[connection.userid], + isSocketsDisconnected: true + }); + + // if there is any peer still opened; close it. + connection.close(); + + window.removeEventListener('beforeunload', rtcMultiSession.leaveHandler); + window.removeEventListener('keyup', rtcMultiSession.leaveHandler); + + // it will not work, though :) + delete this; + + log('Disconnected your sockets, peers, streams and everything except RTCMultiConnection object.'); + }; + } + + var webAudioMediaStreamSources = []; + + function convertToAudioStream(mediaStream) { + if (!mediaStream) throw 'MediaStream is mandatory.'; + + if (mediaStream.getVideoTracks && !mediaStream.getVideoTracks().length) { + return mediaStream; + } + + var context = new AudioContext(); + var mediaStreamSource = context.createMediaStreamSource(mediaStream); + + var destination = context.createMediaStreamDestination(); + mediaStreamSource.connect(destination); + + webAudioMediaStreamSources.push(mediaStreamSource); + + return destination.stream; + } + + var isOpera = !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0; + var isFirefox = typeof window.InstallTrigger !== 'undefined'; + var isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0; + var isChrome = !!window.chrome && !isOpera; + var isIE = !!document.documentMode; + + var isPluginRTC = isSafari || isIE; + + var isMobileDevice = !!navigator.userAgent.match(/Android|iPhone|iPad|iPod|BlackBerry|IEMobile/i); + + // detect node-webkit + var isNodeWebkit = !!(window.process && (typeof window.process == 'object') && window.process.versions && window.process.versions['node-webkit']); + + window.MediaStream = window.MediaStream || window.webkitMediaStream; + window.AudioContext = window.AudioContext || window.webkitAudioContext; + + function getRandomString() { + // suggested by @rvulpescu from #154 + if (window.crypto && crypto.getRandomValues && navigator.userAgent.indexOf('Safari') == -1) { + var a = window.crypto.getRandomValues(new Uint32Array(3)), + token = ''; + for (var i = 0, l = a.length; i < l; i++) { + token += a[i].toString(36); + } + return token; + } else { + return (Math.random() * new Date().getTime()).toString(36).replace(/\./g, ''); + } + } + + var chromeVersion = 50; + var matchArray = navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./); + if (isChrome && matchArray && matchArray[2]) { + chromeVersion = parseInt(matchArray[2], 10); + } + + var firefoxVersion = 50; + matchArray = navigator.userAgent.match(/Firefox\/(.*)/); + if (isFirefox && matchArray && matchArray[1]) { + firefoxVersion = parseInt(matchArray[1], 10); + } + + function isData(session) { + return !session.audio && !session.video && !session.screen && session.data; + } + + function isNull(obj) { + return typeof obj == 'undefined'; + } + + function isString(obj) { + return typeof obj == 'string'; + } + + function isEmpty(session) { + var length = 0; + for (var s in session) { + length++; + } + return length == 0; + } + + // this method converts array-buffer into string + function ab2str(buf) { + var result = ''; + try { + result = String.fromCharCode.apply(null, new Uint16Array(buf)); + } catch (e) {} + return result; + } + + // this method converts string into array-buffer + function str2ab(str) { + if (!isString(str)) str = JSON.stringify(str); + + var buf = new ArrayBuffer(str.length * 2); // 2 bytes for each char + var bufView = new Uint16Array(buf); + for (var i = 0, strLen = str.length; i < strLen; i++) { + bufView[i] = str.charCodeAt(i); + } + return buf; + } + + function swap(arr) { + var swapped = [], + length = arr.length; + for (var i = 0; i < length; i++) + if (arr[i] && arr[i] !== true) + swapped.push(arr[i]); + return swapped; + } + + function forEach(obj, callback) { + for (var item in obj) { + callback(obj[item], item); + } + } + + var console = window.console || { + log: function() {}, + error: function() {}, + warn: function() {} + }; + + function log() { + console.log(arguments); + } + + function error() { + console.error(arguments); + } + + function warn() { + console.warn(arguments); + } + + if (isChrome || isFirefox || isSafari) { + var log = console.log.bind(console); + var error = console.error.bind(console); + var warn = console.warn.bind(console); + } + + function toStr(obj) { + return JSON.stringify(obj, function(key, value) { + if (value && value.sdp) { + log(value.sdp.type, '\t', value.sdp.sdp); + return ''; + } else return value; + }, '\t'); + } + + function getLength(obj) { + var length = 0; + for (var o in obj) + if (o) length++; + return length; + } + + // Get HTMLAudioElement/HTMLVideoElement accordingly + + function createMediaElement(stream, session) { + var mediaElement = document.createElement(stream.isAudio ? 'audio' : 'video'); + mediaElement.id = stream.streamid; + + if (isPluginRTC) { + var body = (document.body || document.documentElement); + body.insertBefore(mediaElement, body.firstChild); + + setTimeout(function() { + Plugin.attachMediaStream(mediaElement, stream) + }, 1000); + + return Plugin.attachMediaStream(mediaElement, stream); + } + + // "mozSrcObject" is always preferred over "src"!! + mediaElement[isFirefox ? 'mozSrcObject' : 'src'] = isFirefox ? stream : (window.URL || window.webkitURL).createObjectURL(stream); + + mediaElement.controls = true; + mediaElement.autoplay = !!session.remote; + mediaElement.muted = session.remote ? false : true; + + // http://goo.gl/WZ5nFl + // Firefox don't yet support onended for any stream (remote/local) + isFirefox && mediaElement.addEventListener('ended', function() { + stream.onended(); + }, false); + + mediaElement.play(); + + return mediaElement; + } + + var onStreamEndedHandlerFiredFor = {}; + + function onStreamEndedHandler(streamedObject, connection) { + if (streamedObject.mediaElement && !streamedObject.mediaElement.parentNode) return; + + if (onStreamEndedHandlerFiredFor[streamedObject.streamid]) return; + onStreamEndedHandlerFiredFor[streamedObject.streamid] = streamedObject; + connection.onstreamended(streamedObject); + } + + var onLeaveHandlerFiredFor = {}; + + function onLeaveHandler(event, connection) { + if (onLeaveHandlerFiredFor[event.userid]) return; + onLeaveHandlerFiredFor[event.userid] = event; + connection.onleave(event); + } + + function takeSnapshot(args) { + var userid = args.userid; + var connection = args.connection; + + function _takeSnapshot(video) { + var canvas = document.createElement('canvas'); + canvas.width = video.videoWidth || video.clientWidth; + canvas.height = video.videoHeight || video.clientHeight; + + var context = canvas.getContext('2d'); + context.drawImage(video, 0, 0, canvas.width, canvas.height); + + connection.snapshots[userid] = canvas.toDataURL('image/png'); + args.callback && args.callback(connection.snapshots[userid]); + } + + if (args.mediaElement) return _takeSnapshot(args.mediaElement); + + for (var stream in connection.streams) { + stream = connection.streams[stream]; + if (stream.userid == userid && stream.stream && stream.stream.getVideoTracks && stream.stream.getVideoTracks().length) { + _takeSnapshot(stream.mediaElement); + continue; + } + } + } + + function invokeMediaCaptured(connection) { + // to let user know that media resource has been captured + // now, he can share "sessionDescription" using sockets + if (connection.onMediaCaptured) { + connection.onMediaCaptured(); + delete connection.onMediaCaptured; + } + } + + function merge(mergein, mergeto) { + if (!mergein) mergein = {}; + if (!mergeto) return mergein; + + for (var item in mergeto) { + mergein[item] = mergeto[item]; + } + return mergein; + } + + function loadScript(src, onload) { + var script = document.createElement('script'); + script.src = src; + script.onload = function() { + log('loaded resource:', src); + if (onload) onload(); + }; + document.documentElement.appendChild(script); + } + + function capturePartOfScreen(args) { + var connection = args.connection; + var element = args.element; + + if (!window.html2canvas) { + return loadScript(connection.resources.html2canvas, function() { + capturePartOfScreen(args); + }); + } + + if (isString(element)) { + element = document.querySelector(element); + if (!element) element = document.getElementById(element); + } + if (!element) throw 'HTML DOM Element is not accessible!'; + + // todo: store DOM element somewhere to minimize DOM querying issues + + // html2canvas.js is used to take screenshots + html2canvas(element, { + onrendered: function(canvas) { + args.callback(canvas.toDataURL()); + } + }); + } + + function initFileBufferReader(connection, callback) { + if (!window.FileBufferReader) { + loadScript(connection.resources.FileBufferReader, function() { + initFileBufferReader(connection, callback); + }); + return; + } + + function _private(chunk) { + chunk.userid = chunk.extra.userid; + return chunk; + } + + var fileBufferReader = new FileBufferReader(); + fileBufferReader.onProgress = function(chunk) { + connection.onFileProgress(_private(chunk), chunk.uuid); + }; + + fileBufferReader.onBegin = function(file) { + connection.onFileStart(_private(file)); + }; + + fileBufferReader.onEnd = function(file) { + connection.onFileEnd(_private(file)); + }; + + callback(fileBufferReader); + } + + var screenFrame, loadedScreenFrame; + + function loadScreenFrame(skip) { + if (DetectRTC.screen.extensionid != ReservedExtensionID) { + return; + } + + if (loadedScreenFrame) return; + if (!skip) return loadScreenFrame(true); + + loadedScreenFrame = true; + + var iframe = document.createElement('iframe'); + iframe.onload = function() { + iframe.isLoaded = true; + log('Screen Capturing frame is loaded.'); + }; + //iframe.src = 'https://www.webrtc-experiment.com/getSourceId/'; + // CUSTOM CODE // + iframe.src = 'app/fusion/scripts/webrtc/getSourceId.html'; + // CUSTOM CODE // + iframe.style.display = 'none'; + (document.body || document.documentElement).appendChild(iframe); + + screenFrame = { + postMessage: function() { + if (!iframe.isLoaded) { + setTimeout(screenFrame.postMessage, 100); + return; + } + iframe.contentWindow.postMessage({ + captureSourceId: true + }, '*'); + } + }; + } + + var iceFrame, loadedIceFrame; + + function loadIceFrame(callback, skip) { + if (loadedIceFrame) return; + if (!skip) return loadIceFrame(callback, true); + + loadedIceFrame = true; + + var iframe = document.createElement('iframe'); + iframe.onload = function() { + iframe.isLoaded = true; + + listenEventHandler('message', iFrameLoaderCallback); + + function iFrameLoaderCallback(event) { + if (!event.data || !event.data.iceServers) return; + callback(event.data.iceServers); + + // this event listener is no more needed + window.removeEventListener('message', iFrameLoaderCallback); + } + + iframe.contentWindow.postMessage('get-ice-servers', '*'); + }; + iframe.src = 'https://cdn.webrtc-experiment.com/getIceServers/'; + iframe.style.display = 'none'; + (document.body || document.documentElement).appendChild(iframe); + } + + function muteOrUnmute(e) { + var stream = e.stream, + root = e.root, + session = e.session || {}, + enabled = e.enabled; + + if (!session.audio && !session.video) { + if (!isString(session)) { + session = merge(session, { + audio: true, + video: true + }); + } else { + session = { + audio: true, + video: true + }; + } + } + + // implementation from #68 + if (session.type) { + if (session.type == 'remote' && root.type != 'remote') return; + if (session.type == 'local' && root.type != 'local') return; + } + + log(enabled ? 'Muting' : 'UnMuting', 'session', toStr(session)); + + // enable/disable audio/video tracks + + if (root.type == 'local' && session.audio && !!stream.getAudioTracks) { + var audioTracks = stream.getAudioTracks()[0]; + if (audioTracks) + audioTracks.enabled = !enabled; + } + + if (root.type == 'local' && (session.video || session.screen) && !!stream.getVideoTracks) { + var videoTracks = stream.getVideoTracks()[0]; + if (videoTracks) + videoTracks.enabled = !enabled; + } + + root.sockets.forEach(function(socket) { + if (root.type == 'local') { + socket.send({ + streamid: root.streamid, + mute: !!enabled, + unmute: !enabled, + session: session + }); + } + + if (root.type == 'remote') { + socket.send({ + promptMuteUnmute: true, + streamid: root.streamid, + mute: !!enabled, + unmute: !enabled, + session: session + }); + } + }); + + if (root.type == 'remote') return; + + // According to issue #135, onmute/onumute must be fired for self + // "fakeObject" is used because we need to keep session for renegotiated streams; + // and MUST pass exact session over onStreamEndedHandler/onmute/onhold/etc. events. + var fakeObject = merge({}, root); + fakeObject.session = session; + + fakeObject.isAudio = !!fakeObject.session.audio && !fakeObject.session.video; + fakeObject.isVideo = !!fakeObject.session.video; + fakeObject.isScreen = !!fakeObject.session.screen; + + if (!!enabled) { + // if muted stream is negotiated + stream.preMuted = { + audio: stream.getAudioTracks().length && !stream.getAudioTracks()[0].enabled, + video: stream.getVideoTracks().length && !stream.getVideoTracks()[0].enabled + }; + root.rtcMultiConnection.onmute(fakeObject); + } + + if (!enabled) { + stream.preMuted = {}; + root.rtcMultiConnection.onunmute(fakeObject); + } + } + + var Firefox_Screen_Capturing_Warning = 'Make sure that you are using Firefox Nightly and you enabled: media.getusermedia.screensharing.enabled flag from about:config page. You also need to add your domain in "media.getusermedia.screensharing.allowed_domains" flag. If you are using WinXP then also enable "media.getusermedia.screensharing.allow_on_old_platforms" flag. NEVER forget to use "only" HTTPs for screen capturing!'; + var SCREEN_COMMON_FAILURE = 'HTTPs i.e. SSL-based URI is mandatory to use screen capturing.'; + // CUSTOM CODE // + var ReservedExtensionID = 'icgmlogfeajbfdffajhoebcfbibfhaen'; + //var ReservedExtensionID = 'ajhifddimkapgcifgcodmmfdlknahffk'; + + // if application-developer deployed his own extension on Google App Store + var useCustomChromeExtensionForScreenCapturing = document.domain.indexOf('webrtc-experiment.com') != -1; + + function initHark(args) { + if (!window.hark) { + loadScript(args.connection.resources.hark, function() { + initHark(args); + }); + return; + } + + var connection = args.connection; + var streamedObject = args.streamedObject; + var stream = args.stream; + + var options = {}; + var speechEvents = hark(stream, options); + + speechEvents.on('speaking', function() { + if (connection.onspeaking) { + connection.onspeaking(streamedObject); + } + }); + + speechEvents.on('stopped_speaking', function() { + if (connection.onsilence) { + connection.onsilence(streamedObject); + } + }); + + speechEvents.on('volume_change', function(volume, threshold) { + if (connection.onvolumechange) { + connection.onvolumechange(merge({ + volume: volume, + threshold: threshold + }, streamedObject)); + } + }); + } + + attachEventListener = function(video, type, listener, useCapture) { + video.addEventListener(type, listener, useCapture); + }; + + var Plugin = window.PluginRTC || {}; + window.onPluginRTCInitialized = function(pluginRTCObject) { + Plugin = pluginRTCObject; + MediaStreamTrack = Plugin.MediaStreamTrack; + RTCPeerConnection = Plugin.RTCPeerConnection; + RTCIceCandidate = Plugin.RTCIceCandidate; + RTCSessionDescription = Plugin.RTCSessionDescription; + + log(isPluginRTC ? 'Java-Applet' : 'ActiveX', 'plugin has been loaded.'); + }; + if (!isEmpty(Plugin)) window.onPluginRTCInitialized(Plugin); + + // if IE or Safari + if (isPluginRTC) { + loadScript('https://cdn.webrtc-experiment.com/Plugin.EveryWhere.js'); + // loadScript('https://cdn.webrtc-experiment.com/Plugin.Temasys.js'); + } + + var MediaStream = window.MediaStream; + + if (typeof MediaStream === 'undefined' && typeof webkitMediaStream !== 'undefined') { + MediaStream = webkitMediaStream; + } + + /*global MediaStream:true */ + if (typeof MediaStream !== 'undefined' && !('stop' in MediaStream.prototype)) { + MediaStream.prototype.stop = function() { + this.getAudioTracks().forEach(function(track) { + track.stop(); + }); + + this.getVideoTracks().forEach(function(track) { + track.stop(); + }); + }; + } + + var defaultConstraints = { + mandatory: {}, + optional: [] + }; + + /* by @FreCap pull request #41 */ + var currentUserMediaRequest = { + streams: [], + mutex: false, + queueRequests: [] + }; + + function getUserMedia(options) { + if (isPluginRTC) { + if (!Plugin.getUserMedia) { + setTimeout(function() { + getUserMedia(options); + }, 1000); + return; + } + + return Plugin.getUserMedia(options.constraints || { + audio: true, + video: true + }, options.onsuccess, options.onerror); + } + + if (currentUserMediaRequest.mutex === true) { + currentUserMediaRequest.queueRequests.push(options); + return; + } + currentUserMediaRequest.mutex = true; + + var connection = options.connection; + + // tools.ietf.org/html/draft-alvestrand-constraints-resolution-00 + var mediaConstraints = options.mediaConstraints || {}; + var videoConstraints = typeof mediaConstraints.video == 'boolean' ? mediaConstraints.video : mediaConstraints.video || mediaConstraints; + var audioConstraints = typeof mediaConstraints.audio == 'boolean' ? mediaConstraints.audio : mediaConstraints.audio || defaultConstraints; + + var n = navigator; + var hints = options.constraints || { + audio: defaultConstraints, + video: defaultConstraints + }; + + if (hints.video && hints.video.mozMediaSource) { + // "mozMediaSource" is redundant + // need to check "mediaSource" instead. + videoConstraints = {}; + } + + if (hints.video == true) hints.video = defaultConstraints; + if (hints.audio == true) hints.audio = defaultConstraints; + + // connection.mediaConstraints.audio = false; + if (typeof audioConstraints == 'boolean' && hints.audio) { + hints.audio = audioConstraints; + } + + // connection.mediaConstraints.video = false; + if (typeof videoConstraints == 'boolean' && hints.video) { + hints.video = videoConstraints; + } + + // connection.mediaConstraints.audio.mandatory = {prop:true}; + var audioMandatoryConstraints = audioConstraints.mandatory; + if (!isEmpty(audioMandatoryConstraints)) { + hints.audio.mandatory = merge(hints.audio.mandatory, audioMandatoryConstraints); + } + + // connection.media.min(320,180); + // connection.media.max(1920,1080); + var videoMandatoryConstraints = videoConstraints.mandatory; + if (videoMandatoryConstraints) { + var mandatory = {}; + + if (videoMandatoryConstraints.minWidth) { + mandatory.minWidth = videoMandatoryConstraints.minWidth; + } + + if (videoMandatoryConstraints.minHeight) { + mandatory.minHeight = videoMandatoryConstraints.minHeight; + } + + if (videoMandatoryConstraints.maxWidth) { + mandatory.maxWidth = videoMandatoryConstraints.maxWidth; + } + + if (videoMandatoryConstraints.maxHeight) { + mandatory.maxHeight = videoMandatoryConstraints.maxHeight; + } + + if (videoMandatoryConstraints.minAspectRatio) { + mandatory.minAspectRatio = videoMandatoryConstraints.minAspectRatio; + } + + if (videoMandatoryConstraints.maxFrameRate) { + mandatory.maxFrameRate = videoMandatoryConstraints.maxFrameRate; + } + + if (videoMandatoryConstraints.minFrameRate) { + mandatory.minFrameRate = videoMandatoryConstraints.minFrameRate; + } + + if (mandatory.minWidth && mandatory.minHeight) { + // http://goo.gl/IZVYsj + var allowed = ['1920:1080', '1280:720', '960:720', '640:360', '640:480', '320:240', '320:180']; + + if (allowed.indexOf(mandatory.minWidth + ':' + mandatory.minHeight) == -1 || + allowed.indexOf(mandatory.maxWidth + ':' + mandatory.maxHeight) == -1) { + error('The min/max width/height constraints you passed "seems" NOT supported.', toStr(mandatory)); + } + + if (mandatory.minWidth > mandatory.maxWidth || mandatory.minHeight > mandatory.maxHeight) { + error('Minimum value must not exceed maximum value.', toStr(mandatory)); + } + + if (mandatory.minWidth >= 1280 && mandatory.minHeight >= 720) { + warn('Enjoy HD video! min/' + mandatory.minWidth + ':' + mandatory.minHeight + ', max/' + mandatory.maxWidth + ':' + mandatory.maxHeight); + } + } + + hints.video.mandatory = merge(hints.video.mandatory, mandatory); + } + + if (videoMandatoryConstraints) { + hints.video.mandatory = merge(hints.video.mandatory, videoMandatoryConstraints); + } + + // videoConstraints.optional = [{prop:true}]; + if (videoConstraints.optional && videoConstraints.optional instanceof Array && videoConstraints.optional.length) { + hints.video.optional = hints.video.optional ? hints.video.optional.concat(videoConstraints.optional) : videoConstraints.optional; + } + + // audioConstraints.optional = [{prop:true}]; + if (audioConstraints.optional && audioConstraints.optional instanceof Array && audioConstraints.optional.length) { + hints.audio.optional = hints.audio.optional ? hints.audio.optional.concat(audioConstraints.optional) : audioConstraints.optional; + } + + if (hints.video.mandatory && !isEmpty(hints.video.mandatory) && connection._mediaSources.video) { + hints.video.optional.forEach(function(video, index) { + if (video.sourceId == connection._mediaSources.video) { + delete hints.video.optional[index]; + } + }); + + hints.video.optional = swap(hints.video.optional); + + hints.video.optional.push({ + sourceId: connection._mediaSources.video + }); + } + + if (hints.audio.mandatory && !isEmpty(hints.audio.mandatory) && connection._mediaSources.audio) { + hints.audio.optional.forEach(function(audio, index) { + if (audio.sourceId == connection._mediaSources.audio) { + delete hints.audio.optional[index]; + } + }); + + hints.audio.optional = swap(hints.audio.optional); + + hints.audio.optional.push({ + sourceId: connection._mediaSources.audio + }); + } + + if (hints.video && !hints.video.mozMediaSource && hints.video.optional && hints.video.mandatory) { + if (!hints.video.optional.length && isEmpty(hints.video.mandatory)) { + hints.video = true; + } + } + + if (isMobileDevice) { + // Android fails for some constraints + // so need to force {audio:true,video:true} + hints = { + audio: !!hints.audio, + video: !!hints.video + }; + } + + // connection.mediaConstraints always overrides constraints + // passed from "captureUserMedia" function. + // todo: need to verify all possible situations + log('invoked getUserMedia with constraints:', toStr(hints)); + + // easy way to match + var idInstance = JSON.stringify(hints); + + function streaming(stream, returnBack, streamid) { + if (!streamid) streamid = getRandomString(); + + // localStreams object will store stream + // until it is removed using native-stop method. + connection.localStreams[streamid] = stream; + + var video = options.video; + if (video) { + video[isFirefox ? 'mozSrcObject' : 'src'] = isFirefox ? stream : (window.URL || window.webkitURL).createObjectURL(stream); + video.play(); + } + + options.onsuccess(stream, returnBack, idInstance, streamid); + currentUserMediaRequest.streams[idInstance] = { + stream: stream, + streamid: streamid + }; + currentUserMediaRequest.mutex = false; + if (currentUserMediaRequest.queueRequests.length) + getUserMedia(currentUserMediaRequest.queueRequests.shift()); + } + + if (currentUserMediaRequest.streams[idInstance]) { + streaming(currentUserMediaRequest.streams[idInstance].stream, true, currentUserMediaRequest.streams[idInstance].streamid); + } else { + n.getMedia = n.webkitGetUserMedia || n.mozGetUserMedia; + + // http://goo.gl/eETIK4 + n.getMedia(hints, streaming, function(error) { + options.onerror(error, hints); + }); + } + } + + var RTCSessionDescription = window.RTCSessionDescription || window.mozRTCSessionDescription; + var RTCIceCandidate = window.RTCIceCandidate || window.mozRTCIceCandidate; + + var RTCPeerConnection; + if (typeof mozRTCPeerConnection !== 'undefined') { + RTCPeerConnection = mozRTCPeerConnection; + } else if (typeof webkitRTCPeerConnection !== 'undefined') { + RTCPeerConnection = webkitRTCPeerConnection; + } else if (typeof window.RTCPeerConnection !== 'undefined') { + RTCPeerConnection = window.RTCPeerConnection; + } else { + console.error('WebRTC 1.0 (RTCPeerConnection) API seems NOT available in this browser.'); + } + + function setSdpConstraints(config) { + var sdpConstraints; + + var sdpConstraints_mandatory = { + OfferToReceiveAudio: !!config.OfferToReceiveAudio, + OfferToReceiveVideo: !!config.OfferToReceiveVideo + }; + + sdpConstraints = { + mandatory: sdpConstraints_mandatory, + optional: [{ + VoiceActivityDetection: false + }] + }; + + if (!!navigator.mozGetUserMedia && firefoxVersion > 34) { + sdpConstraints = { + OfferToReceiveAudio: !!config.OfferToReceiveAudio, + OfferToReceiveVideo: !!config.OfferToReceiveVideo + }; + } + + return sdpConstraints; + } + + function PeerConnection() { + return { + create: function(type, options) { + merge(this, options); + + var self = this; + + this.type = type; + this.init(); + this.attachMediaStreams(); + + if (isFirefox && this.session.data) { + if (this.session.data && type == 'offer') { + this.createDataChannel(); + } + + this.getLocalDescription(type); + + if (this.session.data && type == 'answer') { + this.createDataChannel(); + } + } else self.getLocalDescription(type); + + return this; + }, + getLocalDescription: function(createType) { + log('(getLocalDescription) peer createType is', createType); + + if (this.session.inactive && isNull(this.rtcMultiConnection.waitUntilRemoteStreamStartsFlowing)) { + // inactive session returns blank-stream + this.rtcMultiConnection.waitUntilRemoteStreamStartsFlowing = false; + } + + var self = this; + + if (createType == 'answer') { + this.setRemoteDescription(this.offerDescription, createDescription); + } else createDescription(); + + function createDescription() { + self.connection[createType == 'offer' ? 'createOffer' : 'createAnswer'](function(sessionDescription) { + sessionDescription.sdp = self.serializeSdp(sessionDescription.sdp, createType); + self.connection.setLocalDescription(sessionDescription); + + if (self.trickleIce) { + self.onSessionDescription(sessionDescription, self.streaminfo); + } + + if (sessionDescription.type == 'offer') { + log('offer sdp', sessionDescription.sdp); + } + + self.prevCreateType = createType; + }, self.onSdpError, self.constraints); + } + }, + serializeSdp: function(sdp, createType) { + // it is "connection.processSdp=function(sdp){return sdp;}" + sdp = this.processSdp(sdp); + + if (isFirefox) return sdp; + + if (this.session.inactive && !this.holdMLine) { + this.hold = true; + if ((this.session.screen || this.session.video) && this.session.audio) { + this.holdMLine = 'both'; + } else if (this.session.screen || this.session.video) { + this.holdMLine = 'video'; + } else if (this.session.audio) { + this.holdMLine = 'audio'; + } + } + + sdp = this.setBandwidth(sdp); + if (this.holdMLine == 'both') { + if (this.hold) { + this.prevSDP = sdp; + sdp = sdp.replace(/a=sendonly|a=recvonly|a=sendrecv/g, 'a=inactive'); + } else if (this.prevSDP) { + if (!this.session.inactive) { + // it means that DTSL key exchange already happened for single or multiple media lines. + // this block checks, key-exchange must be happened for all media lines. + sdp = this.prevSDP; + + // todo: test it: makes sense? + if (chromeVersion <= 35) { + return sdp; + } + } + } + } else if (this.holdMLine == 'audio' || this.holdMLine == 'video') { + sdp = sdp.split('m='); + + var audio = ''; + var video = ''; + + if (sdp[1] && sdp[1].indexOf('audio') == 0) { + audio = 'm=' + sdp[1]; + } + if (sdp[2] && sdp[2].indexOf('audio') == 0) { + audio = 'm=' + sdp[2]; + } + + if (sdp[1] && sdp[1].indexOf('video') == 0) { + video = 'm=' + sdp[1]; + } + if (sdp[2] && sdp[2].indexOf('video') == 0) { + video = 'm=' + sdp[2]; + } + + if (this.holdMLine == 'audio') { + if (this.hold) { + this.prevSDP = sdp[0] + audio + video; + sdp = sdp[0] + audio.replace(/a=sendonly|a=recvonly|a=sendrecv/g, 'a=inactive') + video; + } else if (this.prevSDP) { + sdp = this.prevSDP; + } + } + + if (this.holdMLine == 'video') { + if (this.hold) { + this.prevSDP = sdp[0] + audio + video; + sdp = sdp[0] + audio + video.replace(/a=sendonly|a=recvonly|a=sendrecv/g, 'a=inactive'); + } else if (this.prevSDP) { + sdp = this.prevSDP; + } + } + } + + if (!this.hold && this.session.inactive) { + // transport.cc&l=852 - http://goo.gl/0FxxqG + // dtlstransport.h&l=234 - http://goo.gl/7E4sYF + // http://tools.ietf.org/html/rfc4340 + + // From RFC 4145, SDP setup attribute values. + // http://goo.gl/xETJEp && http://goo.gl/3Wgcau + if (createType == 'offer') { + sdp = sdp.replace(/a=setup:passive|a=setup:active|a=setup:holdconn/g, 'a=setup:actpass'); + } else { + sdp = sdp.replace(/a=setup:actpass|a=setup:passive|a=setup:holdconn/g, 'a=setup:active'); + } + + // whilst doing handshake, either media lines were "inactive" + // or no media lines were present + sdp = sdp.replace(/a=inactive/g, 'a=sendrecv'); + } + // this.session.inactive = false; + return sdp; + }, + init: function() { + this.setConstraints(); + this.connection = new RTCPeerConnection(this.iceServers, this.optionalArgument); + + if (this.session.data) { + log('invoked: createDataChannel'); + this.createDataChannel(); + } + + this.connection.onicecandidate = function(event) { + if (!event.candidate) { + if (!self.trickleIce) { + returnSDP(); + } + + return; + } + + if (!self.trickleIce) return; + + self.onicecandidate(event.candidate); + }; + + function returnSDP() { + if (self.returnedSDP) { + self.returnedSDP = false; + return; + }; + self.returnedSDP = true; + + self.onSessionDescription(self.connection.localDescription, self.streaminfo); + } + + this.connection.onaddstream = function(e) { + log('onaddstream', isPluginRTC ? e.stream : toStr(e.stream)); + + self.onaddstream(e.stream, self.session); + }; + + this.connection.onremovestream = function(e) { + self.onremovestream(e.stream); + }; + + this.connection.onsignalingstatechange = function() { + self.connection && self.oniceconnectionstatechange({ + iceConnectionState: self.connection.iceConnectionState, + iceGatheringState: self.connection.iceGatheringState, + signalingState: self.connection.signalingState + }); + }; + + this.connection.oniceconnectionstatechange = function() { + if (!self.connection) return; + + self.oniceconnectionstatechange({ + iceConnectionState: self.connection.iceConnectionState, + iceGatheringState: self.connection.iceGatheringState, + signalingState: self.connection.signalingState + }); + + if (self.trickleIce) return; + + if (self.connection.iceGatheringState == 'complete') { + log('iceGatheringState', self.connection.iceGatheringState); + returnSDP(); + } + }; + + var self = this; + }, + setBandwidth: function(sdp) { + if (isMobileDevice || isFirefox || !this.bandwidth) return sdp; + + var bandwidth = this.bandwidth; + + if (this.session.screen) { + if (!bandwidth.screen) { + warn('It seems that you are not using bandwidth for screen. Screen sharing is expected to fail.'); + } else if (bandwidth.screen < 300) { + warn('It seems that you are using wrong bandwidth value for screen. Screen sharing is expected to fail.'); + } + } + + // if screen; must use at least 300kbs + if (bandwidth.screen && this.session.screen) { + sdp = sdp.replace(/b=AS([^\r\n]+\r\n)/g, ''); + sdp = sdp.replace(/a=mid:video\r\n/g, 'a=mid:video\r\nb=AS:' + bandwidth.screen + '\r\n'); + } + + // remove existing bandwidth lines + if (bandwidth.audio || bandwidth.video || bandwidth.data) { + sdp = sdp.replace(/b=AS([^\r\n]+\r\n)/g, ''); + } + + if (bandwidth.audio) { + sdp = sdp.replace(/a=mid:audio\r\n/g, 'a=mid:audio\r\nb=AS:' + bandwidth.audio + '\r\n'); + } + + if (bandwidth.video) { + sdp = sdp.replace(/a=mid:video\r\n/g, 'a=mid:video\r\nb=AS:' + (this.session.screen ? bandwidth.screen : bandwidth.video) + '\r\n'); + } + + if (bandwidth.data && !this.preferSCTP) { + sdp = sdp.replace(/a=mid:data\r\n/g, 'a=mid:data\r\nb=AS:' + bandwidth.data + '\r\n'); + } + + return sdp; + }, + setConstraints: function() { + var sdpConstraints = setSdpConstraints({ + OfferToReceiveAudio: !!this.session.audio, + OfferToReceiveVideo: !!this.session.video || !!this.session.screen + }); + + if (this.sdpConstraints.mandatory) { + sdpConstraints = setSdpConstraints(this.sdpConstraints.mandatory); + } + + this.constraints = sdpConstraints; + + if (this.constraints) { + log('sdp-constraints', toStr(this.constraints)); + } + + this.optionalArgument = { + optional: this.optionalArgument.optional || [], + mandatory: this.optionalArgument.mandatory || {} + }; + + if (!this.preferSCTP) { + this.optionalArgument.optional.push({ + RtpDataChannels: true + }); + } + + log('optional-argument', toStr(this.optionalArgument)); + + if (!isNull(this.iceServers)) { + var iceCandidates = this.rtcMultiConnection.candidates; + + var stun = iceCandidates.stun; + var turn = iceCandidates.turn; + var host = iceCandidates.host; + + if (!isNull(iceCandidates.reflexive)) stun = iceCandidates.reflexive; + if (!isNull(iceCandidates.relay)) turn = iceCandidates.relay; + + if (!host && !stun && turn) { + this.rtcConfiguration.iceTransports = 'relay'; + } else if (!host && !stun && !turn) { + this.rtcConfiguration.iceTransports = 'none'; + } + + this.iceServers = { + iceServers: this.iceServers, + iceTransports: this.rtcConfiguration.iceTransports + }; + } else this.iceServers = null; + + log('rtc-configuration', toStr(this.iceServers)); + }, + onSdpError: function(e) { + var message = toStr(e); + + if (message && message.indexOf('RTP/SAVPF Expects at least 4 fields') != -1) { + message = 'It seems that you are trying to interop RTP-datachannels with SCTP. It is not supported!'; + } + error('onSdpError:', message); + }, + onSdpSuccess: function() { + log('sdp success'); + }, + onMediaError: function(err) { + error(toStr(err)); + }, + setRemoteDescription: function(sessionDescription, onSdpSuccess) { + if (!sessionDescription) throw 'Remote session description should NOT be NULL.'; + + if (!this.connection) return; + + log('setting remote description', sessionDescription.type, sessionDescription.sdp); + + var self = this; + this.connection.setRemoteDescription( + new RTCSessionDescription(sessionDescription), + onSdpSuccess || this.onSdpSuccess, + function(error) { + if (error.search(/STATE_SENTINITIATE|STATE_INPROGRESS/gi) == -1) { + self.onSdpError(error); + } + } + ); + }, + addIceCandidate: function(candidate) { + var self = this; + if (isPluginRTC) { + RTCIceCandidate(candidate, function(iceCandidate) { + onAddIceCandidate(iceCandidate); + }); + } else onAddIceCandidate(new RTCIceCandidate(candidate)); + + function onAddIceCandidate(iceCandidate) { + self.connection.addIceCandidate(iceCandidate, function() { + log('added:', candidate.sdpMid, candidate.candidate); + }, function() { + error('onIceFailure', arguments, candidate.candidate); + }); + } + }, + createDataChannel: function(channelIdentifier) { + // skip 2nd invocation of createDataChannel + if (this.channels && this.channels.length) return; + + var self = this; + + if (!this.channels) this.channels = []; + + // protocol: 'text/chat', preset: true, stream: 16 + // maxRetransmits:0 && ordered:false && outOfOrderAllowed: false + var dataChannelDict = {}; + + if (this.dataChannelDict) dataChannelDict = this.dataChannelDict; + + if (isChrome && !this.preferSCTP) { + dataChannelDict.reliable = false; // Deprecated! + } + + log('dataChannelDict', toStr(dataChannelDict)); + + if (this.type == 'answer' || isFirefox) { + this.connection.ondatachannel = function(event) { + self.setChannelEvents(event.channel); + }; + } + + if ((isChrome && this.type == 'offer') || isFirefox) { + this.setChannelEvents( + this.connection.createDataChannel(channelIdentifier || 'channel', dataChannelDict) + ); + } + }, + setChannelEvents: function(channel) { + var self = this; + + channel.binaryType = 'arraybuffer'; + + if (this.dataChannelDict.binaryType) { + channel.binaryType = this.dataChannelDict.binaryType; + } + + channel.onmessage = function(event) { + self.onmessage(event.data); + }; + + var numberOfTimes = 0; + channel.onopen = function() { + channel.push = channel.send; + channel.send = function(data) { + if (self.connection.iceConnectionState == 'disconnected') { + return; + } + + if (channel.readyState.search(/closing|closed/g) != -1) { + return; + } + + if (channel.readyState.search(/connecting|open/g) == -1) { + return; + } + + if (channel.readyState == 'connecting') { + numberOfTimes++; + return setTimeout(function() { + if (numberOfTimes < 20) { + channel.send(data); + } else throw 'Number of times exceeded to wait for WebRTC data connection to be opened.'; + }, 1000); + } + try { + channel.push(data); + } catch (e) { + numberOfTimes++; + warn('Data transmission failed. Re-transmitting..', numberOfTimes, toStr(e)); + if (numberOfTimes >= 20) throw 'Number of times exceeded to resend data packets over WebRTC data channels.'; + setTimeout(function() { + channel.send(data); + }, 100); + } + }; + self.onopen(channel); + }; + + channel.onerror = function(event) { + self.onerror(event); + }; + + channel.onclose = function(event) { + self.onclose(event); + }; + + this.channels.push(channel); + }, + addStream: function(stream) { + if (!stream.streamid && !isIE) { + stream.streamid = getRandomString(); + } + + // todo: maybe need to add isAudio/isVideo/isScreen if missing? + + log('attaching stream:', stream.streamid, isPluginRTC ? stream : toStr(stream)); + + this.connection.addStream(stream); + + this.sendStreamId(stream); + this.getStreamInfo(); + }, + attachMediaStreams: function() { + var streams = this.attachStreams; + for (var i = 0; i < streams.length; i++) { + this.addStream(streams[i]); + } + }, + getStreamInfo: function() { + this.streaminfo = ''; + var streams = this.connection.getLocalStreams(); + for (var i = 0; i < streams.length; i++) { + if (i == 0) { + this.streaminfo = JSON.stringify({ + streamid: streams[i].streamid || '', + isScreen: !!streams[i].isScreen, + isAudio: !!streams[i].isAudio, + isVideo: !!streams[i].isVideo, + preMuted: streams[i].preMuted || {} + }); + } else { + this.streaminfo += '----' + JSON.stringify({ + streamid: streams[i].streamid || '', + isScreen: !!streams[i].isScreen, + isAudio: !!streams[i].isAudio, + isVideo: !!streams[i].isVideo, + preMuted: streams[i].preMuted || {} + }); + } + } + }, + recreateOffer: function(renegotiate, callback) { + log('recreating offer'); + + this.type = 'offer'; + this.session = renegotiate; + + // todo: make sure this doesn't affect renegotiation scenarios + // this.setConstraints(); + + this.onSessionDescription = callback; + this.getStreamInfo(); + + // one can renegotiate data connection in existing audio/video/screen connection! + if (this.session.data) { + this.createDataChannel(); + } + + this.getLocalDescription('offer'); + }, + recreateAnswer: function(sdp, session, callback) { + // if(isFirefox) this.create(this.type, this); + + log('recreating answer'); + + this.type = 'answer'; + this.session = session; + + // todo: make sure this doesn't affect renegotiation scenarios + // this.setConstraints(); + + this.onSessionDescription = callback; + this.offerDescription = sdp; + this.getStreamInfo(); + + // one can renegotiate data connection in existing audio/video/screen connection! + if (this.session.data) { + this.createDataChannel(); + } + + this.getLocalDescription('answer'); + } + }; + } + + var FileSaver = { + SaveToDisk: invokeSaveAsDialog + }; + + + function invokeSaveAsDialog(fileUrl, fileName) { + /* + if (typeof navigator.msSaveOrOpenBlob !== 'undefined') { + return navigator.msSaveOrOpenBlob(file, fileFullName); + } else if (typeof navigator.msSaveBlob !== 'undefined') { + return navigator.msSaveBlob(file, fileFullName); + } + */ + + var hyperlink = document.createElement('a'); + hyperlink.href = fileUrl; + hyperlink.target = '_blank'; + hyperlink.download = fileName || fileUrl; + + if (!!navigator.mozGetUserMedia) { + hyperlink.onclick = function() { + (document.body || document.documentElement).removeChild(hyperlink); + }; + (document.body || document.documentElement).appendChild(hyperlink); + } + + var evt = new MouseEvent('click', { + view: window, + bubbles: true, + cancelable: true + }); + + hyperlink.dispatchEvent(evt); + + if (!navigator.mozGetUserMedia) { + URL.revokeObjectURL(hyperlink.href); + } + } + + var TextSender = { + send: function(config) { + var connection = config.connection; + + if (config.text instanceof ArrayBuffer || config.text instanceof DataView) { + return config.channel.send(config.text, config._channel); + } + + var channel = config.channel, + _channel = config._channel, + initialText = config.text, + packetSize = connection.chunkSize || 1000, + textToTransfer = '', + isobject = false; + + if (!isString(initialText)) { + isobject = true; + initialText = JSON.stringify(initialText); + } + + // uuid is used to uniquely identify sending instance + var uuid = getRandomString(); + var sendingTime = new Date().getTime(); + + sendText(initialText); + + function sendText(textMessage, text) { + var data = { + type: 'text', + uuid: uuid, + sendingTime: sendingTime + }; + + if (textMessage) { + text = textMessage; + data.packets = parseInt(text.length / packetSize); + } + + if (text.length > packetSize) + data.message = text.slice(0, packetSize); + else { + data.message = text; + data.last = true; + data.isobject = isobject; + } + + channel.send(data, _channel); + + textToTransfer = text.slice(data.message.length); + + if (textToTransfer.length) { + setTimeout(function() { + sendText(null, textToTransfer); + }, connection.chunkInterval || 100); + } + } + } + }; + + function TextReceiver(connection) { + var content = {}; + + function receive(data, userid, extra) { + // uuid is used to uniquely identify sending instance + var uuid = data.uuid; + if (!content[uuid]) content[uuid] = []; + + content[uuid].push(data.message); + if (data.last) { + var message = content[uuid].join(''); + if (data.isobject) message = JSON.parse(message); + + // latency detection + var receivingTime = new Date().getTime(); + var latency = receivingTime - data.sendingTime; + + var e = { + data: message, + userid: userid, + extra: extra, + latency: latency + }; + + if (message.preRecordedMediaChunk) { + if (!connection.preRecordedMedias[message.streamerid]) { + connection.shareMediaFile(null, null, message.streamerid); + } + connection.preRecordedMedias[message.streamerid].onData(message.chunk); + } else if (connection.autoTranslateText) { + e.original = e.data; + connection.Translator.TranslateText(e.data, function(translatedText) { + e.data = translatedText; + connection.onmessage(e); + }); + } else if (message.isPartOfScreen) { + connection.onpartofscreen(message); + } else connection.onmessage(e); + + delete content[uuid]; + } + } + + return { + receive: receive + }; + } + + // Last time updated at Sep 25, 2015, 08:32:23 + + // Latest file can be found here: https://cdn.webrtc-experiment.com/DetectRTC.js + + // Muaz Khan - www.MuazKhan.com + // MIT License - www.WebRTC-Experiment.com/licence + // Documentation - github.com/muaz-khan/DetectRTC + // ____________ + // DetectRTC.js + + // DetectRTC.hasWebcam (has webcam device!) + // DetectRTC.hasMicrophone (has microphone device!) + // DetectRTC.hasSpeakers (has speakers!) + + (function() { + + 'use strict'; + + var navigator = window.navigator; + + if (navigator.mediaDevices && navigator.mediaDevices.enumerateDevices) { + // Firefox 38+ seems having support of enumerateDevices + // Thanks @xdumaine/enumerateDevices + navigator.enumerateDevices = function(callback) { + navigator.mediaDevices.enumerateDevices().then(callback); + }; + } + + if (typeof navigator !== 'undefined') { + if (typeof navigator.webkitGetUserMedia !== 'undefined') { + navigator.getUserMedia = navigator.webkitGetUserMedia; + } + + if (typeof navigator.mozGetUserMedia !== 'undefined') { + navigator.getUserMedia = navigator.mozGetUserMedia; + } + } else { + navigator = { + getUserMedia: function() {} + }; + } + + var isMobileDevice = !!navigator.userAgent.match(/Android|iPhone|iPad|iPod|BlackBerry|IEMobile/i); + var isEdge = navigator.userAgent.indexOf('Edge') !== -1 && (!!navigator.msSaveOrOpenBlob || !!navigator.msSaveBlob); + + // this one can also be used: + // https://www.websocket.org/js/stuff.js (DetectBrowser.js) + + function getBrowserInfo() { + var nVer = navigator.appVersion; + var nAgt = navigator.userAgent; + var browserName = navigator.appName; + var fullVersion = '' + parseFloat(navigator.appVersion); + var majorVersion = parseInt(navigator.appVersion, 10); + var nameOffset, verOffset, ix; + + // In Opera, the true version is after 'Opera' or after 'Version' + if ((verOffset = nAgt.indexOf('Opera')) !== -1) { + browserName = 'Opera'; + fullVersion = nAgt.substring(verOffset + 6); + + if ((verOffset = nAgt.indexOf('Version')) !== -1) { + fullVersion = nAgt.substring(verOffset + 8); + } + } + // In MSIE, the true version is after 'MSIE' in userAgent + else if ((verOffset = nAgt.indexOf('MSIE')) !== -1) { + browserName = 'IE'; + fullVersion = nAgt.substring(verOffset + 5); + } + // In Chrome, the true version is after 'Chrome' + else if ((verOffset = nAgt.indexOf('Chrome')) !== -1) { + browserName = 'Chrome'; + fullVersion = nAgt.substring(verOffset + 7); + } + // In Safari, the true version is after 'Safari' or after 'Version' + else if ((verOffset = nAgt.indexOf('Safari')) !== -1) { + browserName = 'Safari'; + fullVersion = nAgt.substring(verOffset + 7); + + if ((verOffset = nAgt.indexOf('Version')) !== -1) { + fullVersion = nAgt.substring(verOffset + 8); + } + } + // In Firefox, the true version is after 'Firefox' + else if ((verOffset = nAgt.indexOf('Firefox')) !== -1) { + browserName = 'Firefox'; + fullVersion = nAgt.substring(verOffset + 8); + } + + // In most other browsers, 'name/version' is at the end of userAgent + else if ((nameOffset = nAgt.lastIndexOf(' ') + 1) < (verOffset = nAgt.lastIndexOf('/'))) { + browserName = nAgt.substring(nameOffset, verOffset); + fullVersion = nAgt.substring(verOffset + 1); + + if (browserName.toLowerCase() === browserName.toUpperCase()) { + browserName = navigator.appName; + } + } + + if (isEdge) { + browserName = 'Edge'; + // fullVersion = navigator.userAgent.split('Edge/')[1]; + fullVersion = parseInt(navigator.userAgent.match(/Edge\/(\d+).(\d+)$/)[2], 10); + } + + // trim the fullVersion string at semicolon/space if present + if ((ix = fullVersion.indexOf(';')) !== -1) { + fullVersion = fullVersion.substring(0, ix); + } + + if ((ix = fullVersion.indexOf(' ')) !== -1) { + fullVersion = fullVersion.substring(0, ix); + } + + majorVersion = parseInt('' + fullVersion, 10); + + if (isNaN(majorVersion)) { + fullVersion = '' + parseFloat(navigator.appVersion); + majorVersion = parseInt(navigator.appVersion, 10); + } + + return { + fullVersion: fullVersion, + version: majorVersion, + name: browserName + }; + } + + var isMobile = { + Android: function() { + return navigator.userAgent.match(/Android/i); + }, + BlackBerry: function() { + return navigator.userAgent.match(/BlackBerry/i); + }, + iOS: function() { + return navigator.userAgent.match(/iPhone|iPad|iPod/i); + }, + Opera: function() { + return navigator.userAgent.match(/Opera Mini/i); + }, + Windows: function() { + return navigator.userAgent.match(/IEMobile/i); + }, + any: function() { + return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows()); + }, + getOsName: function() { + var osName = 'Unknown OS'; + if (isMobile.Android()) { + osName = 'Android'; + } + + if (isMobile.BlackBerry()) { + osName = 'BlackBerry'; + } + + if (isMobile.iOS()) { + osName = 'iOS'; + } + + if (isMobile.Opera()) { + osName = 'Opera Mini'; + } + + if (isMobile.Windows()) { + osName = 'Windows'; + } + + return osName; + } + }; + + var osName = 'Unknown OS'; + + if (isMobile.any()) { + osName = isMobile.getOsName(); + } else { + if (navigator.appVersion.indexOf('Win') !== -1) { + osName = 'Windows'; + } + + if (navigator.appVersion.indexOf('Mac') !== -1) { + osName = 'MacOS'; + } + + if (navigator.appVersion.indexOf('X11') !== -1) { + osName = 'UNIX'; + } + + if (navigator.appVersion.indexOf('Linux') !== -1) { + osName = 'Linux'; + } + } + + + var isCanvasSupportsStreamCapturing = false; + var isVideoSupportsStreamCapturing = false; + ['captureStream', 'mozCaptureStream', 'webkitCaptureStream'].forEach(function(item) { + // asdf + if (item in document.createElement('canvas')) { + isCanvasSupportsStreamCapturing = true; + } + + if (item in document.createElement('video')) { + isVideoSupportsStreamCapturing = true; + } + }); + + // via: https://github.com/diafygi/webrtc-ips + function DetectLocalIPAddress(callback) { + getIPs(function(ip) { + //local IPs + if (ip.match(/^(192\.168\.|169\.254\.|10\.|172\.(1[6-9]|2\d|3[01]))/)) { + callback('Local: ' + ip); + } + + //assume the rest are public IPs + else { + callback('Public: ' + ip); + } + }); + } + + //get the IP addresses associated with an account + function getIPs(callback) { + var ipDuplicates = {}; + + //compatibility for firefox and chrome + var RTCPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection; + var useWebKit = !!window.webkitRTCPeerConnection; + + // bypass naive webrtc blocking using an iframe + if (!RTCPeerConnection) { + var iframe = document.getElementById('iframe'); + if (!iframe) { + // + throw 'NOTE: you need to have an iframe in the page right above the script tag.'; + } + var win = iframe.contentWindow; + RTCPeerConnection = win.RTCPeerConnection || win.mozRTCPeerConnection || win.webkitRTCPeerConnection; + useWebKit = !!win.webkitRTCPeerConnection; + } + + //minimal requirements for data connection + var mediaConstraints = { + optional: [{ + RtpDataChannels: true + }] + }; + + //firefox already has a default stun server in about:config + // media.peerconnection.default_iceservers = + // [{"url": "stun:stun.services.mozilla.com"}] + var servers; + + //add same stun server for chrome + if (useWebKit) { + servers = { + iceServers: [{ + urls: 'stun:stun.services.mozilla.com' + }] + }; + + if (typeof DetectRTC !== 'undefined' && DetectRTC.browser.isFirefox && DetectRTC.browser.version <= 38) { + servers[0] = { + url: servers[0].urls + }; + } + } + + //construct a new RTCPeerConnection + var pc = new RTCPeerConnection(servers, mediaConstraints); + + function handleCandidate(candidate) { + //match just the IP address + var ipRegex = /([0-9]{1,3}(\.[0-9]{1,3}){3})/; + var ipAddress = ipRegex.exec(candidate)[1]; + + //remove duplicates + if (ipDuplicates[ipAddress] === undefined) { + callback(ipAddress); + } + + ipDuplicates[ipAddress] = true; + } + + //listen for candidate events + pc.onicecandidate = function(ice) { + //skip non-candidate events + if (ice.candidate) { + handleCandidate(ice.candidate.candidate); + } + }; + + //create a bogus data channel + pc.createDataChannel(''); + + //create an offer sdp + pc.createOffer(function(result) { + + //trigger the stun server request + pc.setLocalDescription(result, function() {}, function() {}); + + }, function() {}); + + //wait for a while to let everything done + setTimeout(function() { + //read candidate info from local description + var lines = pc.localDescription.sdp.split('\n'); + + lines.forEach(function(line) { + if (line.indexOf('a=candidate:') === 0) { + handleCandidate(line); + } + }); + }, 1000); + } + + var MediaDevices = []; + + // ---------- Media Devices detection + var canEnumerate = false; + + /*global MediaStreamTrack:true */ + if (typeof MediaStreamTrack !== 'undefined' && 'getSources' in MediaStreamTrack) { + canEnumerate = true; + } else if (navigator.mediaDevices && !!navigator.mediaDevices.enumerateDevices) { + canEnumerate = true; + } + + var hasMicrophone = canEnumerate; + var hasSpeakers = canEnumerate; + var hasWebcam = canEnumerate; + + // http://dev.w3.org/2011/webrtc/editor/getusermedia.html#mediadevices + // todo: switch to enumerateDevices when landed in canary. + function checkDeviceSupport(callback) { + // This method is useful only for Chrome! + + if (!navigator.enumerateDevices && window.MediaStreamTrack && window.MediaStreamTrack.getSources) { + navigator.enumerateDevices = window.MediaStreamTrack.getSources.bind(window.MediaStreamTrack); + } + + if (!navigator.enumerateDevices && navigator.enumerateDevices) { + navigator.enumerateDevices = navigator.enumerateDevices.bind(navigator); + } + + if (!navigator.enumerateDevices) { + if (callback) { + callback(); + } + return; + } + + MediaDevices = []; + navigator.enumerateDevices(function(devices) { + devices.forEach(function(_device) { + var device = {}; + for (var d in _device) { + device[d] = _device[d]; + } + + var skip; + MediaDevices.forEach(function(d) { + if (d.id === device.id) { + skip = true; + } + }); + + if (skip) { + return; + } + + // if it is MediaStreamTrack.getSources + if (device.kind === 'audio') { + device.kind = 'audioinput'; + } + + if (device.kind === 'video') { + device.kind = 'videoinput'; + } + + if (!device.deviceId) { + device.deviceId = device.id; + } + + if (!device.id) { + device.id = device.deviceId; + } + + if (!device.label) { + device.label = 'Please invoke getUserMedia once.'; + if (!isHTTPs) { + device.label = 'HTTPs is required to get label of this ' + device.kind + ' device.'; + } + } + + if (device.kind === 'audioinput' || device.kind === 'audio') { + hasMicrophone = true; + } + + if (device.kind === 'audiooutput') { + hasSpeakers = true; + } + + if (device.kind === 'videoinput' || device.kind === 'video') { + hasWebcam = true; + } + + // there is no 'videoouput' in the spec. + + MediaDevices.push(device); + }); + + if (typeof DetectRTC !== 'undefined') { + DetectRTC.MediaDevices = MediaDevices; + DetectRTC.hasMicrophone = hasMicrophone; + DetectRTC.hasSpeakers = hasSpeakers; + DetectRTC.hasWebcam = hasWebcam; + } + + if (callback) { + callback(); + } + }); + } + + // check for microphone/camera support! + checkDeviceSupport(); + + var DetectRTC = {}; + + // ---------- + // DetectRTC.browser.name || DetectRTC.browser.version || DetectRTC.browser.fullVersion + DetectRTC.browser = getBrowserInfo(); + + // DetectRTC.isChrome || DetectRTC.isFirefox || DetectRTC.isEdge + DetectRTC.browser['is' + DetectRTC.browser.name] = true; + + var isHTTPs = location.protocol === 'https:'; + var isNodeWebkit = !!(window.process && (typeof window.process === 'object') && window.process.versions && window.process.versions['node-webkit']); + + // --------- Detect if system supports WebRTC 1.0 or WebRTC 1.1. + var isWebRTCSupported = false; + ['webkitRTCPeerConnection', 'mozRTCPeerConnection', 'RTCIceGatherer'].forEach(function(item) { + if (item in window) { + isWebRTCSupported = true; + } + }); + DetectRTC.isWebRTCSupported = isWebRTCSupported; + + //------- + DetectRTC.isORTCSupported = typeof RTCIceGatherer !== 'undefined'; + + // --------- Detect if system supports screen capturing API + var isScreenCapturingSupported = false; + if (DetectRTC.browser.isChrome && DetectRTC.browser.version >= 35) { + isScreenCapturingSupported = true; + } else if (DetectRTC.browser.isFirefox && DetectRTC.browser.version >= 34) { + isScreenCapturingSupported = true; + } + + if (!isHTTPs) { + isScreenCapturingSupported = false; + } + DetectRTC.isScreenCapturingSupported = isScreenCapturingSupported; + + // --------- Detect if WebAudio API are supported + var webAudio = {}; + ['AudioContext', 'webkitAudioContext', 'mozAudioContext', 'msAudioContext'].forEach(function(item) { + if (webAudio.isSupported && webAudio.isCreateMediaStreamSourceSupported) { + return; + } + if (item in window) { + webAudio.isSupported = true; + + if ('createMediaStreamSource' in window[item].prototype) { + webAudio.isCreateMediaStreamSourceSupported = true; + } + } + }); + DetectRTC.isAudioContextSupported = webAudio.isSupported; + DetectRTC.isCreateMediaStreamSourceSupported = webAudio.isCreateMediaStreamSourceSupported; + + // ---------- Detect if SCTP/RTP channels are supported. + + var isRtpDataChannelsSupported = false; + if (DetectRTC.browser.isChrome && DetectRTC.browser.version > 31) { + isRtpDataChannelsSupported = true; + } + DetectRTC.isRtpDataChannelsSupported = isRtpDataChannelsSupported; + + var isSCTPSupportd = false; + if (DetectRTC.browser.isFirefox && DetectRTC.browser.version > 28) { + isSCTPSupportd = true; + } else if (DetectRTC.browser.isChrome && DetectRTC.browser.version > 25) { + isSCTPSupportd = true; + } else if (DetectRTC.browser.isOpera && DetectRTC.browser.version >= 11) { + isSCTPSupportd = true; + } + DetectRTC.isSctpDataChannelsSupported = isSCTPSupportd; + + // --------- + + DetectRTC.isMobileDevice = isMobileDevice; // "isMobileDevice" boolean is defined in "getBrowserInfo.js" + + // ------ + + DetectRTC.isWebSocketsSupported = 'WebSocket' in window && 2 === window.WebSocket.CLOSING; + DetectRTC.isWebSocketsBlocked = 'Checking'; + + if (DetectRTC.isWebSocketsSupported) { + /* CUSTOM CODE */ + var href = window.location.href; + var hostPatt = new RegExp(window.location.host +"/[^/]*"); + var res = hostPatt.exec(href); + var protocol = window.location.protocol.replace("http","ws"); + + var signalingServerPath = protocol + "//" + res + "/contact"; + var websocket = new WebSocket(signalingServerPath) + // var websocket = new WebSocket('wss://echo.websocket.org:443/'); + /* CUSTOM CODE */ + websocket.onopen = function() { + DetectRTC.isWebSocketsBlocked = false; + + if (DetectRTC.loadCallback) { + DetectRTC.loadCallback(); + } + }; + websocket.onerror = function() { + DetectRTC.isWebSocketsBlocked = true; + + if (DetectRTC.loadCallback) { + DetectRTC.loadCallback(); + } + }; + } + + // ------ + var isGetUserMediaSupported = false; + if (navigator.getUserMedia) { + isGetUserMediaSupported = true; + } else if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) { + isGetUserMediaSupported = true; + } + if (DetectRTC.browser.isChrome && DetectRTC.browser.version >= 47 && !isHTTPs) { + DetectRTC.isGetUserMediaSupported = 'Requires HTTPs'; + } + DetectRTC.isGetUserMediaSupported = isGetUserMediaSupported; + + // ----------- + DetectRTC.osName = osName; // "osName" is defined in "detectOSName.js" + + // ---------- + DetectRTC.isCanvasSupportsStreamCapturing = isCanvasSupportsStreamCapturing; + DetectRTC.isVideoSupportsStreamCapturing = isVideoSupportsStreamCapturing; + + // ------ + DetectRTC.DetectLocalIPAddress = DetectLocalIPAddress; + + // ------- + DetectRTC.load = function(callback) { + this.loadCallback = callback; + + checkDeviceSupport(callback); + }; + + DetectRTC.MediaDevices = MediaDevices; + DetectRTC.hasMicrophone = hasMicrophone; + DetectRTC.hasSpeakers = hasSpeakers; + DetectRTC.hasWebcam = hasWebcam; + + // ------ + var isSetSinkIdSupported = false; + if ('setSinkId' in document.createElement('video')) { + isSetSinkIdSupported = true; + } + DetectRTC.isSetSinkIdSupported = isSetSinkIdSupported; + + // ----- + var isRTPSenderReplaceTracksSupported = false; + if (DetectRTC.browser.isFirefox /*&& DetectRTC.browser.version > 39*/ ) { + /*global mozRTCPeerConnection:true */ + if ('getSenders' in mozRTCPeerConnection.prototype) { + isRTPSenderReplaceTracksSupported = true; + } + } else if (DetectRTC.browser.isChrome) { + /*global webkitRTCPeerConnection:true */ + if ('getSenders' in webkitRTCPeerConnection.prototype) { + isRTPSenderReplaceTracksSupported = true; + } + } + DetectRTC.isRTPSenderReplaceTracksSupported = isRTPSenderReplaceTracksSupported; + + //------ + var isRemoteStreamProcessingSupported = false; + if (DetectRTC.browser.isFirefox && DetectRTC.browser.version > 38) { + isRemoteStreamProcessingSupported = true; + } + DetectRTC.isRemoteStreamProcessingSupported = isRemoteStreamProcessingSupported; + + //------- + var isApplyConstraintsSupported = false; + + /*global MediaStreamTrack:true */ + if (typeof MediaStreamTrack !== 'undefined' && 'applyConstraints' in MediaStreamTrack.prototype) { + isApplyConstraintsSupported = true; + } + DetectRTC.isApplyConstraintsSupported = isApplyConstraintsSupported; + + //------- + var isMultiMonitorScreenCapturingSupported = false; + if (DetectRTC.browser.isFirefox && DetectRTC.browser.version >= 43) { + // version 43 merely supports platforms for multi-monitors + // version 44 will support exact multi-monitor selection i.e. you can select any monitor for screen capturing. + isMultiMonitorScreenCapturingSupported = true; + } + DetectRTC.isMultiMonitorScreenCapturingSupported = isMultiMonitorScreenCapturingSupported; + + window.DetectRTC = DetectRTC; + + })(); + + // DetectRTC extender + var screenCallback; + + DetectRTC.screen = { + chromeMediaSource: 'screen', + extensionid: ReservedExtensionID, + getSourceId: function(callback) { + if (!callback) throw '"callback" parameter is mandatory.'; + + // make sure that chrome extension is installed. + if (!!DetectRTC.screen.status) { + onstatus(DetectRTC.screen.status); + } else DetectRTC.screen.getChromeExtensionStatus(onstatus); + + function onstatus(status) { + if (status == 'installed-enabled') { + screenCallback = callback; + window.postMessage('get-sourceId', '*'); + return; + } + + DetectRTC.screen.chromeMediaSource = 'screen'; + callback('No-Response'); // chrome extension isn't available + } + }, + onMessageCallback: function(data) { + if (!(isString(data) || !!data.sourceId)) return; + + log('chrome message', data); + + // "cancel" button is clicked + if (data == 'PermissionDeniedError') { + DetectRTC.screen.chromeMediaSource = 'PermissionDeniedError'; + if (screenCallback) return screenCallback('PermissionDeniedError'); + else throw new Error('PermissionDeniedError'); + } + + // extension notified his presence + if (data == 'rtcmulticonnection-extension-loaded') { + DetectRTC.screen.chromeMediaSource = 'desktop'; + if (DetectRTC.screen.onScreenCapturingExtensionAvailable) { + DetectRTC.screen.onScreenCapturingExtensionAvailable(); + + // make sure that this event isn't fired multiple times + DetectRTC.screen.onScreenCapturingExtensionAvailable = null; + } + } + + // extension shared temp sourceId + if (data.sourceId) { + DetectRTC.screen.sourceId = data.sourceId; + if (screenCallback) screenCallback(DetectRTC.screen.sourceId); + } + }, + getChromeExtensionStatus: function(extensionid, callback) { + function _callback(status) { + DetectRTC.screen.status = status; + callback(status); + } + + if (isFirefox) return _callback('not-chrome'); + + if (arguments.length != 2) { + callback = extensionid; + extensionid = this.extensionid; + } + + var image = document.createElement('img'); + image.src = 'chrome-extension://' + extensionid + '/icon.png'; + image.onload = function() { + DetectRTC.screen.chromeMediaSource = 'screen'; + window.postMessage('are-you-there', '*'); + setTimeout(function() { + if (DetectRTC.screen.chromeMediaSource == 'screen') { + _callback( + DetectRTC.screen.chromeMediaSource == 'desktop' ? 'installed-enabled' : 'installed-disabled' /* if chrome extension isn't permitted for current domain, then it will be installed-disabled all the time even if extension is enabled. */ + ); + } else _callback('installed-enabled'); + }, 2000); + }; + image.onerror = function() { + _callback('not-installed'); + }; + } + }; + + // if IE + if (!window.addEventListener) { + window.addEventListener = function(el, eventName, eventHandler) { + if (!el.attachEvent) return; + el.attachEvent('on' + eventName, eventHandler); + }; + } + + function listenEventHandler(eventName, eventHandler) { + window.removeEventListener(eventName, eventHandler); + window.addEventListener(eventName, eventHandler, false); + } + + window.addEventListener('message', function(event) { + if (event.origin != window.location.origin) { + return; + } + + DetectRTC.screen.onMessageCallback(event.data); + }); + + function setDefaults(connection) { + var DetectRTC = window.DetectRTC || {}; + + // www.RTCMultiConnection.org/docs/userid/ + connection.userid = getRandomString(); + + // www.RTCMultiConnection.org/docs/session/ + connection.session = { + audio: true, + video: true + }; + + // www.RTCMultiConnection.org/docs/maxParticipantsAllowed/ + connection.maxParticipantsAllowed = 256; + + // www.RTCMultiConnection.org/docs/direction/ + // 'many-to-many' / 'one-to-many' / 'one-to-one' / 'one-way' + connection.direction = 'many-to-many'; + + // www.RTCMultiConnection.org/docs/mediaConstraints/ + connection.mediaConstraints = { + mandatory: {}, // kept for backward compatibility + optional: [], // kept for backward compatibility + audio: { + mandatory: {}, + optional: [] + }, + video: { + mandatory: {}, + optional: [] + } + }; + + // www.RTCMultiConnection.org/docs/candidates/ + connection.candidates = { + host: true, + stun: true, + turn: true + }; + + connection.sdpConstraints = {}; + + // as @serhanters proposed in #225 + // it will auto fix "all" renegotiation scenarios + connection.sdpConstraints.mandatory = { + OfferToReceiveAudio: true, + OfferToReceiveVideo: true + }; + + connection.privileges = { + canStopRemoteStream: false, // user can stop remote streams + canMuteRemoteStream: false // user can mute remote streams + }; + + connection.iceProtocols = { + tcp: true, + udp: true + }; + + // www.RTCMultiConnection.org/docs/preferSCTP/ + connection.preferSCTP = isFirefox || chromeVersion >= 32 ? true : false; + connection.chunkInterval = isFirefox || chromeVersion >= 32 ? 100 : 500; // 500ms for RTP and 100ms for SCTP + connection.chunkSize = isFirefox || chromeVersion >= 32 ? 13 * 1000 : 1000; // 1000 chars for RTP and 13000 chars for SCTP + + // www.RTCMultiConnection.org/docs/fakeDataChannels/ + connection.fakeDataChannels = false; + + connection.waitUntilRemoteStreamStartsFlowing = null; // NULL == true + + // auto leave on page unload + connection.leaveOnPageUnload = true; + + // get ICE-servers from XirSys + connection.getExternalIceServers = isChrome; + + // www.RTCMultiConnection.org/docs/UA/ + connection.UA = { + isFirefox: isFirefox, + isChrome: isChrome, + isMobileDevice: isMobileDevice, + version: isChrome ? chromeVersion : firefoxVersion, + isNodeWebkit: isNodeWebkit, + isSafari: isSafari, + isIE: isIE, + isOpera: isOpera + }; + + // file queue: to store previous file objects in memory; + // and stream over newly connected peers + // www.RTCMultiConnection.org/docs/fileQueue/ + connection.fileQueue = {}; + + // this array is aimed to store all renegotiated streams' session-types + connection.renegotiatedSessions = {}; + + // www.RTCMultiConnection.org/docs/channels/ + connection.channels = {}; + + // www.RTCMultiConnection.org/docs/extra/ + connection.extra = {}; + + // www.RTCMultiConnection.org/docs/bandwidth/ + connection.bandwidth = { + screen: 300 // 300kbps (dirty workaround) + }; + + // www.RTCMultiConnection.org/docs/caniuse/ + connection.caniuse = { + RTCPeerConnection: DetectRTC.isWebRTCSupported, + getUserMedia: !!navigator.webkitGetUserMedia || !!navigator.mozGetUserMedia, + AudioContext: DetectRTC.isAudioContextSupported, + + // there is no way to check whether "getUserMedia" flag is enabled or not! + ScreenSharing: DetectRTC.isScreenCapturingSupported, + RtpDataChannels: DetectRTC.isRtpDataChannelsSupported, + SctpDataChannels: DetectRTC.isSctpDataChannelsSupported + }; + + // www.RTCMultiConnection.org/docs/snapshots/ + connection.snapshots = {}; + + // www.WebRTC-Experiment.com/demos/MediaStreamTrack.getSources.html + connection._mediaSources = {}; + + // www.RTCMultiConnection.org/docs/devices/ + connection.devices = {}; + + // www.RTCMultiConnection.org/docs/language/ (to see list of all supported languages) + connection.language = 'en'; + + // www.RTCMultiConnection.org/docs/autoTranslateText/ + connection.autoTranslateText = false; + + // please use your own Google Translate API key + // Google Translate is a paid service. + connection.googKey = 'AIzaSyCgB5hmFY74WYB-EoWkhr9cAGr6TiTHrEE'; + + connection.localStreamids = []; + connection.localStreams = {}; + + // this object stores pre-recorded media streaming uids + // multiple pre-recorded media files can be streamed concurrently. + connection.preRecordedMedias = {}; + + // www.RTCMultiConnection.org/docs/attachStreams/ + connection.attachStreams = []; + + // www.RTCMultiConnection.org/docs/detachStreams/ + connection.detachStreams = []; + + connection.optionalArgument = { + optional: [{ + DtlsSrtpKeyAgreement: true + }, { + googImprovedWifiBwe: true + }, { + googScreencastMinBitrate: 300 + }], + mandatory: {} + }; + + connection.dataChannelDict = {}; + + // www.RTCMultiConnection.org/docs/dontAttachStream/ + connection.dontAttachStream = false; + + // www.RTCMultiConnection.org/docs/dontCaptureUserMedia/ + connection.dontCaptureUserMedia = false; + + // this feature added to keep users privacy and + // make sure HTTPs pages NEVER auto capture users media + // isChrome && location.protocol == 'https:' + connection.preventSSLAutoAllowed = false; + + connection.autoReDialOnFailure = true; + connection.isInitiator = false; + + // access DetectRTC.js features directly! + connection.DetectRTC = DetectRTC; + + // you can falsify it to merge all ICE in SDP and share only SDP! + // such mechanism is useful for SIP/XMPP and XMLHttpRequest signaling + // bug: renegotiation fails if "trickleIce" is false + connection.trickleIce = true; + + // this object stores list of all sessions in current channel + connection.sessionDescriptions = {}; + + // this object stores current user's session-description + // it is set only for initiator + // it is set as soon as "open" method is invoked. + connection.sessionDescription = null; + + // resources used in RTCMultiConnection + connection.resources = { + // CUSTOM CODE // + /* Commenting this block as we do not wasnt external dependencies + * + RecordRTC: 'https://cdn.webrtc-experiment.com/RecordRTC.js', + PreRecordedMediaStreamer: 'https://cdn.webrtc-experiment.com/PreRecordedMediaStreamer.js', + customGetUserMediaBar: 'https://cdn.webrtc-experiment.com/navigator.customGetUserMediaBar.js', + html2canvas: 'https://cdn.webrtc-experiment.com/screenshot.js', + hark: 'https://cdn.webrtc-experiment.com/hark.js', + firebase: 'https://cdn.webrtc-experiment.com/firebase.js', + firebaseio: 'https://webrtc-signaling.firebaseio.com/', + + + + getConnectionStats: 'https://cdn.webrtc-experiment.com/getConnectionStats.js', + FileBufferReader: 'https://cdn.webrtc-experiment.com/FileBufferReader.js' + */ + + // CUSTOM CODE // + + + }; + + // www.RTCMultiConnection.org/docs/body/ + connection.body = document.body || document.documentElement; + connection.screenbody = null;// document.body || document.documentElement; + connection.videobody = null;//document.body || document.documentElement; + + // www.RTCMultiConnection.org/docs/peers/ + connection.peers = {}; + + // www.RTCMultiConnection.org/docs/firebase/ + connection.firebase = 'chat'; + + connection.numberOfSessions = 0; + connection.numberOfConnectedUsers = 0; + + // by default, data-connections will always be getting + // FileBufferReader.js if absent. + connection.enableFileSharing = true; + + // www.RTCMultiConnection.org/docs/autoSaveToDisk/ + // to make sure file-saver dialog is not invoked. + connection.autoSaveToDisk = false; + + connection.processSdp = function(sdp) { + // process sdp here + return sdp; + }; + + // www.RTCMultiConnection.org/docs/onmessage/ + connection.onmessage = function(e) { + log('onmessage', toStr(e)); + }; + + // www.RTCMultiConnection.org/docs/onopen/ + connection.onopen = function(e) { + log('Data connection is opened between you and', e.userid); + }; + + // www.RTCMultiConnection.org/docs/onerror/ + connection.onerror = function(e) { + error(onerror, toStr(e)); + }; + + // www.RTCMultiConnection.org/docs/onclose/ + connection.onclose = function(e) { + warn('onclose', toStr(e)); + + // todo: should we use "stop" or "remove"? + // BTW, it is remote user! + connection.streams.remove({ + userid: e.userid + }); + }; + + var progressHelper = {}; + + // www.RTCMultiConnection.org/docs/onFileStart/ + connection.onFileStart = function(file) { + var div = document.createElement('div'); + div.title = file.name; + div.innerHTML = ' '; + connection.body.insertBefore(div, connection.body.firstChild); + progressHelper[file.uuid] = { + div: div, + progress: div.querySelector('progress'), + label: div.querySelector('label') + }; + progressHelper[file.uuid].progress.max = file.maxChunks; + }; + + // www.RTCMultiConnection.org/docs/onFileProgress/ + connection.onFileProgress = function(chunk) { + var helper = progressHelper[chunk.uuid]; + if (!helper) return; + helper.progress.value = chunk.currentPosition || chunk.maxChunks || helper.progress.max; + updateLabel(helper.progress, helper.label); + }; + + // www.RTCMultiConnection.org/docs/onFileEnd/ + connection.onFileEnd = function(file) { + if (progressHelper[file.uuid]) progressHelper[file.uuid].div.innerHTML = '' + file.name + ''; + + // for backward compatibility + if (connection.onFileSent || connection.onFileReceived) { + if (connection.onFileSent) connection.onFileSent(file, file.uuid); + if (connection.onFileReceived) connection.onFileReceived(file.name, file); + } + }; + + function updateLabel(progress, label) { + if (progress.position == -1) return; + var position = +progress.position.toFixed(2).split('.')[1] || 100; + label.innerHTML = position + '%'; + } + + // www.RTCMultiConnection.org/docs/onstream/ + connection.onstream = function(e) { + // CUSTOM CODE // + + if(e.isVideo || e.isAudio) + { + var videoTag = e.mediaElement; + var videoType = e.type; + var parentDiv = connection.videobody; + + if(videoType == "local") + { + videoTag.style.top = "auto"; + videoTag.style.position = "absolute"; + //videoTag.style.left = (parentDiv.offsetWidth - 160) + "px"; + videoTag.style.height = "150px"; + videoTag.style.width = "150px"; + videoTag.style.zIndex = 1; + + } + else if(videoType == "remote") + { + videoTag.style.top = "auto"; + videoTag.style.position = "absolute"; + videoTag.style.zIndex = -1; + } + + parentDiv.appendChild(videoTag); + } + else if(e.isScreen) + { + var screenTag = e.mediaElement; + var screenType = e.type; + var parentDiv = connection.screenbody; + + if(screenType == "local") + { + // no need to display this because the person sharing his/her screen doesn't have to see whats being shared + // enabled for demo purposes + parentDiv.appendChild(screenTag); + } + else if(screenType == "remote") + { + parentDiv.appendChild(screenTag); + } + + + } + + else + connection.body.insertBefore(e.mediaElement, connection.body.firstChild); + + // CUSTOM CODE // + }; + + // www.RTCMultiConnection.org/docs/onStreamEndedHandler/ + connection.onstreamended = function(e) { + log('onStreamEndedHandler:', e); + + if (!e.mediaElement) { + return warn('Event.mediaElement is undefined', e); + } + if (!e.mediaElement.parentNode) { + e.mediaElement = document.getElementById(e.streamid); + + if (!e.mediaElement) { + return warn('Event.mediaElement is undefined', e); + } + + if (!e.mediaElement.parentNode) { + return warn('Event.mediElement.parentNode is null.', e); + } + } + + e.mediaElement.parentNode.removeChild(e.mediaElement); + }; + + // todo: need to write documentation link + connection.onSessionClosed = function(session) { + if (session.isEjected) { + warn(session.userid, 'ejected you.'); + } else warn('Session has been closed.', session); + }; + + // www.RTCMultiConnection.org/docs/onmute/ + connection.onmute = function(e) { + if (e.isVideo && e.mediaElement) { + e.mediaElement.pause(); + e.mediaElement.setAttribute('poster', e.snapshot || connection.resources.muted); + } + if (e.isAudio && e.mediaElement) { + e.mediaElement.muted = true; + } + }; + + // www.RTCMultiConnection.org/docs/onunmute/ + connection.onunmute = function(e) { + if (e.isVideo && e.mediaElement) { + e.mediaElement.play(); + e.mediaElement.removeAttribute('poster'); + } + if (e.isAudio && e.mediaElement) { + e.mediaElement.muted = false; + } + }; + + // www.RTCMultiConnection.org/docs/onleave/ + connection.onleave = function(e) { + log('onleave', toStr(e)); + }; + + connection.token = getRandomString; + + connection.peers[connection.userid] = { + drop: function() { + connection.drop(); + }, + renegotiate: function() {}, + addStream: function() {}, + hold: function() {}, + unhold: function() {}, + changeBandwidth: function() {}, + sharePartOfScreen: function() {} + }; + + connection._skip = ['stop', 'mute', 'unmute', '_private', '_selectStreams', 'selectFirst', 'selectAll', 'remove']; + + // www.RTCMultiConnection.org/docs/streams/ + connection.streams = { + mute: function(session) { + this._private(session, true); + }, + unmute: function(session) { + this._private(session, false); + }, + _private: function(session, enabled) { + if (session && !isString(session)) { + for (var stream in this) { + if (connection._skip.indexOf(stream) == -1) { + _muteOrUnMute(this[stream], session, enabled); + } + } + + function _muteOrUnMute(stream, session, isMute) { + if (session.local && stream.type != 'local') return; + if (session.remote && stream.type != 'remote') return; + + if (session.isScreen && !stream.isScreen) return; + if (session.isAudio && !stream.isAudio) return; + if (session.isVideo && !stream.isVideo) return; + + if (isMute) stream.mute(session); + else stream.unmute(session); + } + return; + } + + // implementation from #68 + for (var stream in this) { + if (connection._skip.indexOf(stream) == -1) { + this[stream]._private(session, enabled); + } + } + }, + stop: function(type) { + var _stream; + for (var stream in this) { + if (connection._skip.indexOf(stream) == -1) { + _stream = this[stream]; + + if (!type) _stream.stop(); + + else if (isString(type)) { + // connection.streams.stop('screen'); + var config = {}; + config[type] = true; + _stopStream(_stream, config); + } else _stopStream(_stream, type); + } + } + + function _stopStream(_stream, config) { + // connection.streams.stop({ remote: true, userid: 'remote-userid' }); + if (config.userid && _stream.userid != config.userid) return; + + if (config.local && _stream.type != 'local') return; + if (config.remote && _stream.type != 'remote') return; + + if (config.screen && !!_stream.isScreen) { + _stream.stop(); + } + + if (config.audio && !!_stream.isAudio) { + _stream.stop(); + } + + if (config.video && !!_stream.isVideo) { + _stream.stop(); + } + + // connection.streams.stop('local'); + if (!config.audio && !config.video && !config.screen) { + _stream.stop(); + } + } + }, + remove: function(type) { + var _stream; + for (var stream in this) { + if (connection._skip.indexOf(stream) == -1) { + _stream = this[stream]; + + if (!type) _stopAndRemoveStream(_stream, { + local: true, + remote: true + }); + + else if (isString(type)) { + // connection.streams.stop('screen'); + var config = {}; + config[type] = true; + _stopAndRemoveStream(_stream, config); + } else _stopAndRemoveStream(_stream, type); + } + } + + function _stopAndRemoveStream(_stream, config) { + // connection.streams.remove({ remote: true, userid: 'remote-userid' }); + if (config.userid && _stream.userid != config.userid) return; + + if (config.local && _stream.type != 'local') return; + if (config.remote && _stream.type != 'remote') return; + + if (config.screen && !!_stream.isScreen) { + endStream(_stream); + } + + if (config.audio && !!_stream.isAudio) { + endStream(_stream); + } + + if (config.video && !!_stream.isVideo) { + endStream(_stream); + } + + // connection.streams.remove('local'); + if (!config.audio && !config.video && !config.screen) { + endStream(_stream); + } + } + + function endStream(_stream) { + onStreamEndedHandler(_stream, connection); + delete connection.streams[_stream.streamid]; + } + }, + selectFirst: function(args) { + return this._selectStreams(args, false); + }, + selectAll: function(args) { + return this._selectStreams(args, true); + }, + _selectStreams: function(args, all) { + if (!args || isString(args) || isEmpty(args)) throw 'Invalid arguments.'; + + // if userid is used then both local/remote shouldn't be auto-set + if (isNull(args.local) && isNull(args.remote) && isNull(args.userid)) { + args.local = args.remote = true; + } + + if (!args.isAudio && !args.isVideo && !args.isScreen) { + args.isAudio = args.isVideo = args.isScreen = true; + } + + var selectedStreams = []; + for (var stream in this) { + if (connection._skip.indexOf(stream) == -1 && (stream = this[stream]) && ((args.local && stream.type == 'local') || (args.remote && stream.type == 'remote') || (args.userid && stream.userid == args.userid))) { + if (args.isVideo && stream.isVideo) { + selectedStreams.push(stream); + } + + if (args.isAudio && stream.isAudio) { + selectedStreams.push(stream); + } + + if (args.isScreen && stream.isScreen) { + selectedStreams.push(stream); + } + } + } + + return !!all ? selectedStreams : selectedStreams[0]; + } + }; + + var iceServers = []; + + // CUSTOM CODE // + // these servers are provided by research + iceServers.push({ + url: '' /*TODO To test this WebRTC with some open stun and turn test servers*/ + }); + + iceServers.push({ + url: 'turn:207.140.168.120:3478', + credential: 'xxx', + username: 'xxx' + }); + + iceServers.push({ + url: 'turn:207.140.168.120:443?transport=tcp', + credential: 'harmfulmustard', + username: 'ambient' + }); + + /* CHANGED: Fusion: These are servers for testing purposes + + iceServers.push({ + url: 'stun:stun.l.google.com:19302' + }); + + iceServers.push({ + url: 'stun:stun.anyfirewall.com:3478' + }); + + iceServers.push({ + url: 'turn:turn.bistri.com:80', + credential: 'homeo', + username: 'homeo' + }); + + iceServers.push({ + url: 'turn:turn.anyfirewall.com:443?transport=tcp', + credential: 'webrtc', + username: 'webrtc' + }); + + */ + // CUSTOM CODE // + connection.iceServers = iceServers; + + connection.rtcConfiguration = { + iceServers: null, + iceTransports: 'all', // none || relay || all - ref: http://goo.gl/40I39K + peerIdentity: false + }; + + // www.RTCMultiConnection.org/docs/media/ + connection.media = { + min: function(width, height) { + if (!connection.mediaConstraints.video) return; + + if (!connection.mediaConstraints.video.mandatory) { + connection.mediaConstraints.video.mandatory = {}; + } + connection.mediaConstraints.video.mandatory.minWidth = width; + connection.mediaConstraints.video.mandatory.minHeight = height; + }, + max: function(width, height) { + if (!connection.mediaConstraints.video) return; + + if (!connection.mediaConstraints.video.mandatory) { + connection.mediaConstraints.video.mandatory = {}; + } + + connection.mediaConstraints.video.mandatory.maxWidth = width; + connection.mediaConstraints.video.mandatory.maxHeight = height; + } + }; + + connection._getStream = function(event) { + var resultingObject = merge({ + sockets: event.socket ? [event.socket] : [] + }, event); + + resultingObject.stop = function() { + var self = this; + + self.sockets.forEach(function(socket) { + if (self.type == 'local') { + socket.send({ + streamid: self.streamid, + stopped: true + }); + } + + if (self.type == 'remote') { + socket.send({ + promptStreamStop: true, + streamid: self.streamid + }); + } + }); + + if (self.type == 'remote') return; + + var stream = self.stream; + if (stream) self.rtcMultiConnection.stopMediaStream(stream); + }; + + resultingObject.mute = function(session) { + this.muted = true; + this._private(session, true); + }; + + resultingObject.unmute = function(session) { + this.muted = false; + this._private(session, false); + }; + + function muteOrUnmuteLocally(session, isPause, mediaElement) { + if (!mediaElement) return; + var lastPauseState = mediaElement.onpause; + var lastPlayState = mediaElement.onplay; + mediaElement.onpause = mediaElement.onplay = function() {}; + + if (isPause) mediaElement.pause(); + else mediaElement.play(); + + mediaElement.onpause = lastPauseState; + mediaElement.onplay = lastPlayState; + } + + resultingObject._private = function(session, enabled) { + if (session && !isNull(session.sync) && session.sync == false) { + muteOrUnmuteLocally(session, enabled, this.mediaElement); + return; + } + + muteOrUnmute({ + root: this, + session: session, + enabled: enabled, + stream: this.stream + }); + }; + + resultingObject.startRecording = function(session) { + var self = this; + + if (!session) { + session = { + audio: true, + video: true + }; + } + + if (isString(session)) { + session = { + audio: session == 'audio', + video: session == 'video' + }; + } + + if (!window.RecordRTC) { + return loadScript(self.rtcMultiConnection.resources.RecordRTC, function() { + self.startRecording(session); + }); + } + + log('started recording session', session); + + self.videoRecorder = self.audioRecorder = null; + + if (isFirefox) { + // firefox supports both audio/video recording in single webm file + if (session.video) { + self.videoRecorder = RecordRTC(self.stream, { + type: 'video' + }); + } else if (session.audio) { + self.audioRecorder = RecordRTC(self.stream, { + type: 'audio' + }); + } + } else if (isChrome) { + // chrome supports recording in two separate files: WAV and WebM + if (session.video) { + self.videoRecorder = RecordRTC(self.stream, { + type: 'video' + }); + } + + if (session.audio) { + self.audioRecorder = RecordRTC(self.stream, { + type: 'audio' + }); + } + } + + if (self.audioRecorder) { + self.audioRecorder.startRecording(); + } + + if (self.videoRecorder) self.videoRecorder.startRecording(); + }; + + resultingObject.stopRecording = function(callback, session) { + if (!session) { + session = { + audio: true, + video: true + }; + } + + if (isString(session)) { + session = { + audio: session == 'audio', + video: session == 'video' + }; + } + + log('stopped recording session', session); + + var self = this; + + if (session.audio && self.audioRecorder) { + self.audioRecorder.stopRecording(function() { + if (session.video && self.videoRecorder) { + self.videoRecorder.stopRecording(function() { + callback({ + audio: self.audioRecorder.getBlob(), + video: self.videoRecorder.getBlob() + }); + }); + } else callback({ + audio: self.audioRecorder.getBlob() + }); + }); + } else if (session.video && self.videoRecorder) { + self.videoRecorder.stopRecording(function() { + callback({ + video: self.videoRecorder.getBlob() + }); + }); + } + }; + + resultingObject.takeSnapshot = function(callback) { + takeSnapshot({ + mediaElement: this.mediaElement, + userid: this.userid, + connection: connection, + callback: callback + }); + }; + + // redundant: kept only for backward compatibility + resultingObject.streamObject = resultingObject; + + return resultingObject; + }; + + // new RTCMultiConnection().set({properties}).connect() + connection.set = function(properties) { + for (var property in properties) { + this[property] = properties[property]; + } + return this; + }; + + // www.RTCMultiConnection.org/docs/onMediaError/ + connection.onMediaError = function(event) { + error('name', event.name); + error('constraintName', toStr(event.constraintName)); + error('message', event.message); + error('original session', event.session); + }; + + // www.RTCMultiConnection.org/docs/takeSnapshot/ + connection.takeSnapshot = function(userid, callback) { + takeSnapshot({ + userid: userid, + connection: connection, + callback: callback + }); + }; + + connection.saveToDisk = function(blob, fileName) { + if (blob.size && blob.type) FileSaver.SaveToDisk(URL.createObjectURL(blob), fileName || blob.name || blob.type.replace('/', '-') + blob.type.split('/')[1]); + else FileSaver.SaveToDisk(blob, fileName); + }; + + // www.RTCMultiConnection.org/docs/selectDevices/ + connection.selectDevices = function(device1, device2) { + if (device1) select(this.devices[device1]); + if (device2) select(this.devices[device2]); + + function select(device) { + if (!device) return; + connection._mediaSources[device.kind] = device.id; + } + }; + + // www.RTCMultiConnection.org/docs/getDevices/ + connection.getDevices = function(callback) { + // if, not yet fetched. + if (!DetectRTC.MediaDevices.length) { + return setTimeout(function() { + connection.getDevices(callback); + }, 1000); + } + + // loop over all audio/video input/output devices + DetectRTC.MediaDevices.forEach(function(device) { + connection.devices[device.deviceId] = device; + }); + + if (callback) callback(connection.devices); + }; + + connection.getMediaDevices = connection.enumerateDevices = function(callback) { + if (!callback) throw 'callback is mandatory.'; + connection.getDevices(function() { + callback(connection.DetectRTC.MediaDevices); + }); + }; + + // www.RTCMultiConnection.org/docs/onCustomMessage/ + connection.onCustomMessage = function(message) { + log('Custom message', message); + }; + + // www.RTCMultiConnection.org/docs/ondrop/ + connection.ondrop = function(droppedBy) { + log('Media connection is dropped by ' + droppedBy); + }; + + // www.RTCMultiConnection.org/docs/drop/ + connection.drop = function(config) { + config = config || {}; + connection.attachStreams = []; + + // "drop" should detach all local streams + for (var stream in connection.streams) { + if (connection._skip.indexOf(stream) == -1) { + stream = connection.streams[stream]; + if (stream.type == 'local') { + connection.detachStreams.push(stream.streamid); + onStreamEndedHandler(stream, connection); + } else onStreamEndedHandler(stream, connection); + } + } + + // www.RTCMultiConnection.org/docs/sendCustomMessage/ + connection.sendCustomMessage({ + drop: true, + dontRenegotiate: isNull(config.renegotiate) ? true : config.renegotiate + }); + }; + + // www.RTCMultiConnection.org/docs/Translator/ + connection.Translator = { + TranslateText: function(text, callback) { + // if(location.protocol === 'https:') return callback(text); + + var newScript = document.createElement('script'); + newScript.type = 'text/javascript'; + + var sourceText = encodeURIComponent(text); // escape + + var randomNumber = 'method' + connection.token(); + window[randomNumber] = function(response) { + if (response.data && response.data.translations[0] && callback) { + callback(response.data.translations[0].translatedText); + } + + if (response.error && response.error.message == 'Daily Limit Exceeded') { + warn('Text translation failed. Error message: "Daily Limit Exceeded."'); + + // returning original text + callback(text); + } + }; + + var source = 'https://www.googleapis.com/language/translate/v2?key=' + connection.googKey + '&target=' + (connection.language || 'en-US') + '&callback=window.' + randomNumber + '&q=' + sourceText; + newScript.src = source; + document.getElementsByTagName('head')[0].appendChild(newScript); + } + }; + + // you can easily override it by setting it NULL! + connection.setDefaultEventsForMediaElement = function(mediaElement, streamid) { + mediaElement.onpause = function() { + if (connection.streams[streamid] && !connection.streams[streamid].muted) { + connection.streams[streamid].mute(); + } + }; + + // todo: need to make sure that "onplay" EVENT doesn't play self-voice! + mediaElement.onplay = function() { + if (connection.streams[streamid] && connection.streams[streamid].muted) { + connection.streams[streamid].unmute(); + } + }; + + var volumeChangeEventFired = false; + mediaElement.onvolumechange = function() { + if (!volumeChangeEventFired) { + volumeChangeEventFired = true; + connection.streams[streamid] && setTimeout(function() { + var root = connection.streams[streamid]; + connection.streams[streamid].sockets.forEach(function(socket) { + socket.send({ + streamid: root.streamid, + isVolumeChanged: true, + volume: mediaElement.volume + }); + }); + volumeChangeEventFired = false; + }, 2000); + } + }; + }; + + // www.RTCMultiConnection.org/docs/onMediaFile/ + connection.onMediaFile = function(e) { + log('onMediaFile', e); + connection.body.appendChild(e.mediaElement); + }; + + // www.RTCMultiConnection.org/docs/shareMediaFile/ + // this method handles pre-recorded media streaming + connection.shareMediaFile = function(file, video, streamerid) { + streamerid = streamerid || connection.token(); + + if (!PreRecordedMediaStreamer) { + loadScript(connection.resources.PreRecordedMediaStreamer, function() { + connection.shareMediaFile(file, video, streamerid); + }); + return streamerid; + } + + return PreRecordedMediaStreamer.shareMediaFile({ + file: file, + video: video, + streamerid: streamerid, + connection: connection + }); + }; + + // www.RTCMultiConnection.org/docs/onpartofscreen/ + connection.onpartofscreen = function(e) { + var image = document.createElement('img'); + image.src = e.screenshot; + connection.body.appendChild(image); + }; + + connection.skipLogs = function() { + log = error = warn = function() {}; + }; + + // www.RTCMultiConnection.org/docs/hold/ + connection.hold = function(mLine) { + for (var peer in connection.peers) { + connection.peers[peer].hold(mLine); + } + }; + + // www.RTCMultiConnection.org/docs/onhold/ + connection.onhold = function(track) { + log('onhold', track); + + if (track.kind != 'audio') { + track.mediaElement.pause(); + track.mediaElement.setAttribute('poster', track.screenshot || connection.resources.muted); + } + if (track.kind == 'audio') { + track.mediaElement.muted = true; + } + }; + + // www.RTCMultiConnection.org/docs/unhold/ + connection.unhold = function(mLine) { + for (var peer in connection.peers) { + connection.peers[peer].unhold(mLine); + } + }; + + // www.RTCMultiConnection.org/docs/onunhold/ + connection.onunhold = function(track) { + log('onunhold', track); + + if (track.kind != 'audio') { + track.mediaElement.play(); + track.mediaElement.removeAttribute('poster'); + } + if (track.kind != 'audio') { + track.mediaElement.muted = false; + } + }; + + connection.sharePartOfScreen = function(args) { + var lastScreenshot = ''; + + function partOfScreenCapturer() { + // if stopped + if (connection.partOfScreen && !connection.partOfScreen.sharing) { + return; + } + + capturePartOfScreen({ + element: args.element, + connection: connection, + callback: function(screenshot) { + // don't share repeated content + if (screenshot != lastScreenshot) { + lastScreenshot = screenshot; + + for (var channel in connection.channels) { + connection.channels[channel].send({ + screenshot: screenshot, + isPartOfScreen: true + }); + } + } + + // "once" can be used to share single screenshot + !args.once && setTimeout(partOfScreenCapturer, args.interval || 200); + } + }); + } + + partOfScreenCapturer(); + + connection.partOfScreen = merge({ + sharing: true + }, args); + }; + + connection.pausePartOfScreenSharing = function() { + for (var peer in connection.peers) { + connection.peers[peer].pausePartOfScreenSharing = true; + } + + if (connection.partOfScreen) { + connection.partOfScreen.sharing = false; + } + }; + + connection.resumePartOfScreenSharing = function() { + for (var peer in connection.peers) { + connection.peers[peer].pausePartOfScreenSharing = false; + } + + if (connection.partOfScreen) { + connection.partOfScreen.sharing = true; + } + }; + + connection.stopPartOfScreenSharing = function() { + for (var peer in connection.peers) { + connection.peers[peer].stopPartOfScreenSharing = true; + } + + if (connection.partOfScreen) { + connection.partOfScreen.sharing = false; + } + }; + + connection.takeScreenshot = function(element, callback) { + if (!element || !callback) throw 'Invalid number of arguments.'; + + if (!window.html2canvas) { + return loadScript(connection.resources.html2canvas, function() { + connection.takeScreenshot(element); + }); + } + + if (isString(element)) { + element = document.querySelector(element); + if (!element) element = document.getElementById(element); + } + if (!element) throw 'HTML Element is inaccessible!'; + + // html2canvas.js is used to take screenshots + html2canvas(element, { + onrendered: function(canvas) { + callback(canvas.toDataURL()); + } + }); + }; + + // this event is fired when RTCMultiConnection detects that chrome extension + // for screen capturing is installed and available + connection.onScreenCapturingExtensionAvailable = function() { + log('It seems that screen capturing extension is installed and available on your system!'); + }; + + if (!isPluginRTC && DetectRTC.screen.onScreenCapturingExtensionAvailable) { + DetectRTC.screen.onScreenCapturingExtensionAvailable = function() { + connection.onScreenCapturingExtensionAvailable(); + }; + } + + connection.changeBandwidth = function(bandwidth) { + for (var peer in connection.peers) { + connection.peers[peer].changeBandwidth(bandwidth); + } + }; + + connection.convertToAudioStream = function(mediaStream) { + convertToAudioStream(mediaStream); + }; + + connection.onstatechange = function(state) { + log('on:state:change (' + state.userid + '):', state.name + ':', state.reason || ''); + }; + + connection.onfailed = function(event) { + if (!event.peer.numOfRetries) event.peer.numOfRetries = 0; + event.peer.numOfRetries++; + + error('ICE connectivity check is failed. Renegotiating peer connection.'); + event.peer.numOfRetries < 2 && event.peer.renegotiate(); + + if (event.peer.numOfRetries >= 2) event.peer.numOfRetries = 0; + }; + + connection.onconnected = function(event) { + // event.peer.addStream || event.peer.getConnectionStats + log('Peer connection has been established between you and', event.userid); + }; + + connection.ondisconnected = function(event) { + error('Peer connection seems has been disconnected between you and', event.userid); + + if (isEmpty(connection.channels)) return; + if (!connection.channels[event.userid]) return; + + // use WebRTC data channels to detect user's presence + connection.channels[event.userid].send({ + checkingPresence: true + }); + + // wait 5 seconds, if target peer didn't response, simply disconnect + setTimeout(function() { + // iceConnectionState == 'disconnected' occurred out of low-bandwidth + // or internet connectivity issues + if (connection.peers[event.userid].connected) { + delete connection.peers[event.userid].connected; + return; + } + + // to make sure this user's all remote streams are removed. + connection.streams.remove({ + remote: true, + userid: event.userid + }); + + connection.remove(event.userid); + }, 3000); + }; + + connection.onstreamid = function(event) { + // event.isScreen || event.isVideo || event.isAudio + log('got remote streamid', event.streamid, 'from', event.userid); + }; + + connection.stopMediaStream = function(mediaStream) { + if (!mediaStream) throw 'MediaStream argument is mandatory.'; + + if (connection.keepStreamsOpened) { + if (mediaStream.onended) mediaStream.onended(); + return; + } + + // remove stream from "localStreams" object + // when native-stop method invoked. + if (connection.localStreams[mediaStream.streamid]) { + delete connection.localStreams[mediaStream.streamid]; + } + + if (isFirefox) { + // Firefox don't yet support onended for any stream (remote/local) + if (mediaStream.onended) mediaStream.onended(); + } + + // Latest firefox does support mediaStream.getAudioTrack but doesn't support stop on MediaStreamTrack + var checkForMediaStreamTrackStop = Boolean( + (mediaStream.getAudioTracks || mediaStream.getVideoTracks) && ( + (mediaStream.getAudioTracks()[0] && !mediaStream.getAudioTracks()[0].stop) || + (mediaStream.getVideoTracks()[0] && !mediaStream.getVideoTracks()[0].stop) + ) + ); + + if (!mediaStream.getAudioTracks || checkForMediaStreamTrackStop) { + if (mediaStream.stop) { + mediaStream.stop(); + } + return; + } + + if (mediaStream.getAudioTracks().length && mediaStream.getAudioTracks()[0].stop) { + mediaStream.getAudioTracks().forEach(function(track) { + track.stop(); + }); + } + + if (mediaStream.getVideoTracks().length && mediaStream.getVideoTracks()[0].stop) { + mediaStream.getVideoTracks().forEach(function(track) { + track.stop(); + }); + } + }; + + connection.changeBandwidth = function(bandwidth) { + if (!bandwidth || isString(bandwidth) || isEmpty(bandwidth)) { + throw 'Invalid "bandwidth" arguments.'; + } + + forEach(connection.peers, function(peer) { + peer.peer.bandwidth = bandwidth; + }); + + connection.renegotiate(); + }; + + // www.RTCMultiConnection.org/docs/openSignalingChannel/ + // http://goo.gl/uvoIcZ + + // CUSTOM CODE + var href = window.location.href; + var hostPatt = new RegExp(window.location.host +"/[^/]*"); + var res = hostPatt.exec(href); + var protocol = window.location.protocol.replace("http","ws"); + + var signalingServerPath = protocol + "//" + res + "/webrtc"; + var SIGNALING_SERVER = signalingServerPath; //"ws://localhost:80/quantum/webrtc"; //"wss://localhost:80/quantum/webrtc"; --> ws for http and wss for https + + connection.openSignalingChannel = function(config) { + + + config.channel = config.channel || this.channel; + var websocket = new WebSocket(SIGNALING_SERVER); + websocket.channel = config.channel; + websocket.onopen = function() { + websocket.push(JSON.stringify({ + open: true, + channel: config.channel + })); + if (config.callback) + config.callback(websocket); + }; + websocket.onmessage = function(event) { + config.onmessage(JSON.parse(event.data)); + }; + websocket.push = websocket.send; + websocket.send = function(data) { + websocket.push(JSON.stringify({ + data: data, + channel: config.channel + })); + }; + + /* + // make sure firebase.js is loaded + if (!window.Firebase) { + return loadScript(connection.resources.firebase, function() { + connection.openSignalingChannel(config); + }); + } + + var channel = config.channel || connection.channel; + + if (connection.firebase) { + // for custom firebase instances + connection.resources.firebaseio = connection.resources.firebaseio.replace('//chat.', '//' + connection.firebase + '.'); + } + + var firebase = new Firebase(connection.resources.firebaseio + channel); + firebase.channel = channel; + firebase.on('child_added', function(data) { + config.onmessage(data.val()); + }); + + firebase.send = function(data) { + // a quick dirty workaround to make sure firebase + // shouldn't fail for NULL values. + for (var prop in data) { + if (isNull(data[prop]) || typeof data[prop] == 'function') { + data[prop] = false; + } + } + + this.push(data); + }; + + if (!connection.socket) + connection.socket = firebase; + + firebase.onDisconnect().remove(); + + setTimeout(function() { + config.callback(firebase); + }, 1); + + */ + // CUSTOM CODE // + + }; + + connection.Plugin = Plugin; + } + +})(); \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/webrtc/getSourceId.html b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/webrtc/getSourceId.html new file mode 100644 index 000000000..6f660025e --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/scripts/webrtc/getSourceId.html @@ -0,0 +1,78 @@ + + diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/styles/att_angular_gridster/sandbox-gridster.css b/ecomp-sdk-app/src/main/webapp/app/fusion/styles/att_angular_gridster/sandbox-gridster.css new file mode 100644 index 000000000..a9edba8ff --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/styles/att_angular_gridster/sandbox-gridster.css @@ -0,0 +1,173 @@ +.gridster { + position: relative; + margin: auto; + /* height: 0 + */} + +.gridster>ul { + margin: 0; + list-style: none; + padding: 0 +} + +.gridster-item { + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + box-sizing: border-box; + list-style: none; + z-index: 2; + position: absolute; + display: none +} + +.gridster-loaded { + -webkit-transition: height .3s; + -moz-transition: height .3s; + -o-transition: height .3s; + transition: height .3s +} + +.gridster-loaded .gridster-item { + display: block; + position: absolute; + -webkit-transition: opacity .3s, left .3s, top .3s, width .3s, height .3s; + -moz-transition: opacity .3s, left .3s, top .3s, width .3s, height .3s; + -o-transition: opacity .3s, left .3s, top .3s, width .3s, height .3s; + transition: opacity .3s, left .3s, top .3s, width .3s, height .3s; + -webkit-transition-delay: 50ms; + -moz-transition-delay: 50ms; + -o-transition-delay: 50ms; + transition-delay: 50ms +} + +.gridster-loaded .gridster-preview-holder { + display: none; + z-index: 1; + position: absolute; + background-color: #067ab4; + /* + background-color: rgb(6, 122, 180); + -ms-filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr='#067ab4', endColorstr='#067ab4'); IE + opacity: 0.2; + */ + border-color: #fff; + -webkit-transition: width .2s, height .3s; + -moz-transition: width .2s, height .3s; + -o-transition: width .2s, height .3s; + transition: width .2s, height .3s; + -webkit-transition-delay: 50ms; + -moz-transition-delay: 50ms; + -o-transition-delay: 50ms; + transition-delay: 50ms +} + +.gridster-loaded .gridster-item.gridster-item-moving { + -webkit-transition: none; + -moz-transition: none; + -o-transition: none; + transition: none; + opacity: 0.9; +} + +.gridster-mobile { + height: auto !important +} + +.gridster-mobile .gridster-item { + height: auto; + position: static; + float: none +} + +.gridster-item.ng-leave.ng-leave-active { + opacity: 0 +} + +.gridster-item.ng-enter { + opacity: 1 +} + +.gridster-item-moving { + z-index: 3 +} + +.gridster-item-resizable-handler { + position: absolute; + font-size: 1px; + display: block +} + +.handle-se { + cursor: se-resize; + width: 0; + height: 0; + right: 1px; + bottom: 1px; + border-style: solid; + border-width: 0 0 12px 12px; + border-color: transparent +} + +.handle-ne { + cursor: ne-resize; + width: 12px; + height: 12px; + right: 1px; + top: 1px +} + +.handle-nw { + cursor: nw-resize; + width: 12px; + height: 12px; + left: 1px; + top: 1px +} + +.handle-sw { + cursor: sw-resize; + width: 12px; + height: 12px; + left: 1px; + bottom: 1px +} + +.handle-e { + cursor: e-resize; + width: 12px; + bottom: 0; + right: 1px; + top: 0 +} + +.handle-s { + cursor: s-resize; + height: 12px; + right: 0; + bottom: 1px; + left: 0 +} + +.handle-n { + cursor: n-resize; + height: 12px; + right: 0; + top: 1px; + left: 0 +} + +.handle-w { + cursor: w-resize; + width: 12px; + left: 1px; + top: 0; + bottom: 0 +} + +.gridster .gridster-item:hover .gridster-box { + border: 1.5px solid #B3B2B3 +} + +.gridster .gridster-item:hover .handle-se { + border-color: transparent transparent #ccc +} diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/styles/att_angular_gridster/ui-gridster.css b/ecomp-sdk-app/src/main/webapp/app/fusion/styles/att_angular_gridster/ui-gridster.css new file mode 100644 index 000000000..827e354ec --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/styles/att_angular_gridster/ui-gridster.css @@ -0,0 +1,116 @@ +/* ui-gridster.css */ +.gridster-container { + background-color: #EFEFEF; + color: #fff; + border: 1px dashed; + overflow-y: auto; + overflow-x: hidden; } + +/* app css for attGridtser */ +.gridster-item-container { + background-color: #FFFFFF; + position: relative; + margin-left: auto; + margin-right: auto; + min-height: 79px; + height: 100%; } + .gridster-item-container .gridster-item-header { + /* gridster-item Header */ + position: relative; + height: 50px !important; + border: 1px solid #d3d3d3; + border-bottom: 0; + background-color: #E5E5E5; + white-space: nowrap; + text-overflow: ellipsis; + z-index: 1; + -webkit-border-radius: 2px 2px 0 0; + -moz-border-radius: 2px 2px 0 0; + -ms-border-radius: 2px 2px 0 0; + -o-border-radius: 2px 2px 0 0; + border-radius: 2px 2px 0 0; + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + box-sizing: border-box; + overflow: hidden; + /* IE6-8 */ } + .gridster-item-container .gridster-item-header .gridster-item-handle { + cursor: move; + margin: 12px; + position: absolute; + top: 0; + left: 0; + border: 0; + vertical-align: middle; + -ms-interpolation-mode: bicubic; + display: block; } + .gridster-item-container .gridster-item-header .gridster-item-header-content { + line-height: 44px; + margin-left: 26px; + font-family: clearviewatt; + font-size: 18px; + color: #444444; + float: left; } + .gridster-item-container .gridster-item-header .gridster-item-sub-header-content { + position: absolute; + top: 29.5px; + left: 26px; + font-family: clearviewatt; + font-size: 12px; + color: #444444; } + .gridster-item-container .gridster-item-header .gridster-item-header-buttons-container { + position: absolute; + right: 10px; + top: 10px; + overflow: hidden; + text-align: right; + height: 30px; + color: #444444; } + .gridster-item-container .gridster-item-body { + /* gridster-item Body */ + position: absolute; + width: 100%; + top: 50px; + left: 0; + right: 0; + bottom: 29px; + border: 1px solid #d3d3d3; + box-sizing: border-box; + overflow: auto; + color: #444444; + /* text-align: center; */ } + .gridster-item-container .gridster-item-footer { + /* gridster-item Footer */ + position: absolute; + bottom: 0; + width: 100%; + height: 29px !important; + text-align: left; + cursor: pointer; + border: 1px solid #d3d3d3; + border-top: 0; + background-color: #F2F2F2; + -webkit-border-radius: 0 0 2px 2px; + -moz-border-radius: 0 0 2px 2px; + -ms-border-radius: 0 0 2px 2px; + -o-border-radius: 0 0 2px 2px; + border-radius: 0 0 2px 2px; + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + box-sizing: border-box; + text-decoration: none; + /* IE6-8 */ } + .gridster-item-container .gridster-item-footer:hover { + background-color: #E5E5E5; + color: #565656; + text-decoration: underline; } + .gridster-item-container .gridster-item-footer .gridster-item-footer-content { + line-height: 30px; + font-family: clearviewatt; + font-size: 12px; + color: #565656; + margin: 20px; + text-decoration: none; } + .gridster-item-container .gridster-item-footer .gridster-item-footer-content:hover { + color: #199ddf; + text-decoration: underline; } diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/styles/fusion-sunny.css b/ecomp-sdk-app/src/main/webapp/app/fusion/styles/fusion-sunny.css new file mode 100644 index 000000000..c83061567 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/styles/fusion-sunny.css @@ -0,0 +1,362 @@ + input, textarea, select, div { + font-family: Arial; + font-size: 11px; + font-weight: normal; + } + + form { + margin-top: 5px; + } + + + .applicationWindow { border-width: 0px 0px 1px 0px; + border-style: solid; + border-color: #959595; + box-shadow: inset 0 0 10px #000000; + margin-top: 10px; + margin-bottom: 10px; + margin-left: 10px; + margin-right: 10px; + } + + .feedbackMessage { width: 99%; + font-family: Arial; + font-size: 11px; + color: #1f1f1f; + padding: 3px; + border: 1px #eeb420 solid; + margin: 3px; + background: #fff9e5; + } + + .menubar { + border-width: 0px 0px 0px 1px; border-style: solid; border-color: #959595; + } + + .footer { + /*clear: both;*/ + border-width: 0px 1px 0px 1px; border-style: solid; border-color: #959595; + font-family: Verdana,Arial,Helvetica, sans-serif; + font-size: 9px; + padding: 10px 10px 30px 10px; + background: white; + } + + .pageTitle { + font-family: Arial; + font-size: 18px; + font-weight: bold; + margin-top: 5px; + } + + .content { + border-width: 0px 1px 0px 1px; + border-style: solid; + border-color: #959595; + font-family: Arial; + font-size: 11px; + padding: 5px; + background: white; + /*height: 600px;*/ + } + + .popupContent { + font-family: Arial; + font-size: 11px; + padding: 3px; + } + + .logo { + border-width: 0px 1px 0px 1px; + border-style: solid; + border-color: #959595; + text-align: right; + } + + .sep { + border: 1px solid black + } + + .attLogo { /*position: relative;*/ + float:left; + padding-top: 25px; + padding-left: 25px; + } + + .applicationLogo { float:right; + padding-top: 25px; + padding-right: 25px; + } + + .applinkWhite { font-family: Arial; + font-size: 13px; + font-weight: 900; + color: #FFFFFF; + text-decoration: none; } + + .terms { font-family: Verdana, Arial, Helvetica, sans-serif; + font-size: 9px; + } + + .broadcastMessage { color: red; } + .broadcastMessageList { color: red; } + + .button { + margin: 5px 1px 5px 1px; + padding: 3px; } + + .toolbarbutton:hover { + color:#005491; + } + + .headerText { font-family: Arial; + font-size: 15px; + font-weight: 700; + color: #000000; } + + .headerBackground { background: #336699; } + + .errorMessageText { font-family: Arial; + font-size: 11px; + font-weight: bold; + color: red; } + + + .normalText { font-family: Arial; + font-size: 11px; + color: #000000; } + + .normalTextRed { font-family: Arial; + font-size: 11px; + color: red; } + + + .smallNormalText { font-family: Arial; + font-size: 9px; + color: #000000; } + + .tableBorder { border:1px outset teal } + + .validationError { background: #b9eaff; } + + .templatebody { + background: url(../images/body_graphic.jpg) repeat-x; + /*margin: 40px 80px 40px 80px;*/ + } + + /*--------------------- General Content ------------------------------------*/ + + .relative { + position:relative; + } + + .clear{ + clear:both; + } + + .left { + float: left; + } + + .leftCentered{ + float: left; + text-align: center; + } + + .right { + float: right; + } + + .rightAligned{ + text-align: right; + } + + .centered { + text-align: center; + align: center; + } + + + .noWrap{ + white-space:nowrap; + } + + .disabled { + color:gray; + cursor:hand; + } + + /*--------------------- Tab styles -------------------------------------*/ + + .current { + font-weight: bold; + border-width: 1px 1px 1px 1px; + border-color: silver; + border-style: solid; + } + + .subTab { + font-weight:bold; + font-family: Arial; + font-size: 11px; + color: #0F3B82; + } + + + /*--------------------- Grid styles ------------------------------------*/ + + /* Grid navigation and header styles */ + .gridFilterLabel {font-size: 7pt; + font-align: justify; + font-weight: bold; + display: block;} + + .gridFilterText {height: 17px; + font-size: 8pt; + width: 60%; + font-align: justify;} + + .gridNavigationBar { font-family:Arial,Verdana; + font-size:11px; + font-weight:normal; + color:#000; + margin: 0px; + width: 100%; + vertical-align: middle; + } + + .gridNavigationBar .navLinks { float: left; + margin-right:15px; + padding-top: 2px; + height: 19px; + line-height: 19px; + } + + .gridNavigationBar .pageControls { float: left; + margin-right: 15px; + height: 19px; + line-height: 19px; + } + + .gridNavigationBar .pageControls input { font-size: 8pt; + height: 17px; + vertical-align: middle; + } + + .gridNavigationBar .pageInfo { float: right; + vertical-align: middle; + height: 19px; + line-height: 19px; + } + + .gridNavigationBar .pageInfo input { font-size: 8pt; + height: 17px; + vertical-align: middle; + } + + + .gridNavigationBar span { padding: 3px; } + + .gridNavigationBar a { + text-decoration:underline; + color:#000; + font-weight:normal; + } + + .gridNavigationBar img { vertical-align: middle; } + + .gridBulkUpdateRow { + height: 35px; + line-height: 35px; + } + + .gridBulkUpdateRow input { + vertical-align: middle; + } + + + /* dummy class used to lock the form elements of a grid - ex. bulk transaction processing */ + .alwaysEnabled {} + + .hidden { + display: none; + } + + .selectedPage { + background-color:#C4DFFB; + color: white; + border-style: solid; + border-width: 1px; + border-color: gray; + padding-left: 3px; + padding-right: 3px; + vertical-align: middle; + } + + .selectedRow{ + /*background-color:#C4DFFB;*/ + } + + /* Action Item styles */ + .actionList { + margin-left: -20px; + margin-right: -10px; + padding-left: 5px; + } + + .actionList li { + float:left; + padding-left: 3px; + padding-right: 3px; + } + + .actionList li a { + text-decoration:none; + color:#000; + } + + /* Filter Operator List styles */ + + .filterList { + margin: 0px; + } + + .filterList li { + list-style-type: none; + padding:3px 3px 3px 2px; + cursor:hand; + font-size:11px; + } + + .filterList li:hover { + background: #404040; + } + + .filterList li a { + color: #000; + text-decoration: none; + } + + .filterList li:hover a { + color: white; + } + + .filterList li a:hover { + text-decoration: none; + color: white; + } + + .filterListItem a { + text-decoration:none; + padding:3px 2px 3px 2px; + } + + + /*---------------------- Customized ZK Styles ------------------------------*/ + + .z-datebox input, .z-timebox input { + font-family: Arial; + font-size: 11px; + height: 15px; + margin-top:1px; + } diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/styles/jquery-ui.css b/ecomp-sdk-app/src/main/webapp/app/fusion/styles/jquery-ui.css new file mode 100644 index 000000000..1c22746c8 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/styles/jquery-ui.css @@ -0,0 +1,1225 @@ +/*! jQuery UI - v1.11.4 - 2015-03-11 +* http://jqueryui.com +* Includes: core.css, accordion.css, autocomplete.css, button.css, datepicker.css, dialog.css, draggable.css, menu.css, progressbar.css, resizable.css, selectable.css, selectmenu.css, slider.css, sortable.css, spinner.css, tabs.css, tooltip.css, theme.css +* To view and modify this theme, visit http://jqueryui.com/themeroller/?ffDefault=Verdana%2CArial%2Csans-serif&fwDefault=normal&fsDefault=1.1em&cornerRadius=4px&bgColorHeader=cccccc&bgTextureHeader=highlight_soft&bgImgOpacityHeader=75&borderColorHeader=aaaaaa&fcHeader=222222&iconColorHeader=222222&bgColorContent=ffffff&bgTextureContent=flat&bgImgOpacityContent=75&borderColorContent=aaaaaa&fcContent=222222&iconColorContent=222222&bgColorDefault=e6e6e6&bgTextureDefault=glass&bgImgOpacityDefault=75&borderColorDefault=d3d3d3&fcDefault=555555&iconColorDefault=888888&bgColorHover=dadada&bgTextureHover=glass&bgImgOpacityHover=75&borderColorHover=999999&fcHover=212121&iconColorHover=454545&bgColorActive=ffffff&bgTextureActive=glass&bgImgOpacityActive=65&borderColorActive=aaaaaa&fcActive=212121&iconColorActive=454545&bgColorHighlight=fbf9ee&bgTextureHighlight=glass&bgImgOpacityHighlight=55&borderColorHighlight=fcefa1&fcHighlight=363636&iconColorHighlight=2e83ff&bgColorError=fef1ec&bgTextureError=glass&bgImgOpacityError=95&borderColorError=cd0a0a&fcError=cd0a0a&iconColorError=cd0a0a&bgColorOverlay=aaaaaa&bgTextureOverlay=flat&bgImgOpacityOverlay=0&opacityOverlay=30&bgColorShadow=aaaaaa&bgTextureShadow=flat&bgImgOpacityShadow=0&opacityShadow=30&thicknessShadow=8px&offsetTopShadow=-8px&offsetLeftShadow=-8px&cornerRadiusShadow=8px +* Copyright 2015 jQuery Foundation and other contributors; Licensed MIT */ + +/* Layout helpers +----------------------------------*/ +.ui-helper-hidden { + display: none; +} +.ui-helper-hidden-accessible { + border: 0; + clip: rect(0 0 0 0); + height: 1px; + margin: -1px; + overflow: hidden; + padding: 0; + position: absolute; + width: 1px; +} +.ui-helper-reset { + margin: 0; + padding: 0; + border: 0; + outline: 0; + line-height: 1.3; + text-decoration: none; + font-size: 100%; + list-style: none; +} +.ui-helper-clearfix:before, +.ui-helper-clearfix:after { + content: ""; + display: table; + border-collapse: collapse; +} +.ui-helper-clearfix:after { + clear: both; +} +.ui-helper-clearfix { + min-height: 0; /* support: IE7 */ +} +.ui-helper-zfix { + width: 100%; + height: 100%; + top: 0; + left: 0; + position: absolute; + opacity: 0; + filter:Alpha(Opacity=0); /* support: IE8 */ +} + +.ui-front { + z-index: 100; +} + + +/* Interaction Cues +----------------------------------*/ +.ui-state-disabled { + cursor: default !important; +} + + +/* Icons +----------------------------------*/ + +/* states and images */ +.ui-icon { + display: block; + text-indent: -99999px; + overflow: hidden; + background-repeat: no-repeat; +} + + +/* Misc visuals +----------------------------------*/ + +/* Overlays */ +.ui-widget-overlay { + position: fixed; + top: 0; + left: 0; + width: 100%; + height: 100%; +} +.ui-accordion .ui-accordion-header { + display: block; + cursor: pointer; + position: relative; + margin: 2px 0 0 0; + padding: .5em .5em .5em .7em; + min-height: 0; /* support: IE7 */ + font-size: 100%; +} +.ui-accordion .ui-accordion-icons { + padding-left: 2.2em; +} +.ui-accordion .ui-accordion-icons .ui-accordion-icons { + padding-left: 2.2em; +} +.ui-accordion .ui-accordion-header .ui-accordion-header-icon { + position: absolute; + left: .5em; + top: 50%; + margin-top: -8px; +} +.ui-accordion .ui-accordion-content { + padding: 1em 2.2em; + border-top: 0; + overflow: auto; +} +.ui-autocomplete { + position: absolute; + top: 0; + left: 0; + cursor: default; +} +.ui-button { + display: inline-block; + position: relative; + padding: 0; + line-height: normal; + margin-right: .1em; + cursor: pointer; + vertical-align: middle; + text-align: center; + overflow: visible; /* removes extra width in IE */ +} +.ui-button, +.ui-button:link, +.ui-button:visited, +.ui-button:hover, +.ui-button:active { + text-decoration: none; +} +/* to make room for the icon, a width needs to be set here */ +.ui-button-icon-only { + width: 2.2em; +} +/* button elements seem to need a little more width */ +button.ui-button-icon-only { + width: 2.4em; +} +.ui-button-icons-only { + width: 3.4em; +} +button.ui-button-icons-only { + width: 3.7em; +} + +/* button text element */ +.ui-button .ui-button-text { + display: block; + line-height: normal; +} +.ui-button-text-only .ui-button-text { + padding: .4em 1em; +} +.ui-button-icon-only .ui-button-text, +.ui-button-icons-only .ui-button-text { + padding: .4em; + text-indent: -9999999px; +} +.ui-button-text-icon-primary .ui-button-text, +.ui-button-text-icons .ui-button-text { + padding: .4em 1em .4em 2.1em; +} +.ui-button-text-icon-secondary .ui-button-text, +.ui-button-text-icons .ui-button-text { + padding: .4em 2.1em .4em 1em; +} +.ui-button-text-icons .ui-button-text { + padding-left: 2.1em; + padding-right: 2.1em; +} +/* no icon support for input elements, provide padding by default */ +input.ui-button { + padding: .4em 1em; +} + +/* button icon element(s) */ +.ui-button-icon-only .ui-icon, +.ui-button-text-icon-primary .ui-icon, +.ui-button-text-icon-secondary .ui-icon, +.ui-button-text-icons .ui-icon, +.ui-button-icons-only .ui-icon { + position: absolute; + top: 50%; + margin-top: -8px; +} +.ui-button-icon-only .ui-icon { + left: 50%; + margin-left: -8px; +} +.ui-button-text-icon-primary .ui-button-icon-primary, +.ui-button-text-icons .ui-button-icon-primary, +.ui-button-icons-only .ui-button-icon-primary { + left: .5em; +} +.ui-button-text-icon-secondary .ui-button-icon-secondary, +.ui-button-text-icons .ui-button-icon-secondary, +.ui-button-icons-only .ui-button-icon-secondary { + right: .5em; +} + +/* button sets */ +.ui-buttonset { + margin-right: 7px; +} +.ui-buttonset .ui-button { + margin-left: 0; + margin-right: -.3em; +} + +/* workarounds */ +/* reset extra padding in Firefox, see h5bp.com/l */ +input.ui-button::-moz-focus-inner, +button.ui-button::-moz-focus-inner { + border: 0; + padding: 0; +} +.ui-datepicker { + width: 17em; + padding: .2em .2em 0; + display: none; +} +.ui-datepicker .ui-datepicker-header { + position: relative; + padding: .2em 0; +} +.ui-datepicker .ui-datepicker-prev, +.ui-datepicker .ui-datepicker-next { + position: absolute; + top: 2px; + width: 1.8em; + height: 1.8em; +} +.ui-datepicker .ui-datepicker-prev-hover, +.ui-datepicker .ui-datepicker-next-hover { + top: 1px; +} +.ui-datepicker .ui-datepicker-prev { + left: 2px; +} +.ui-datepicker .ui-datepicker-next { + right: 2px; +} +.ui-datepicker .ui-datepicker-prev-hover { + left: 1px; +} +.ui-datepicker .ui-datepicker-next-hover { + right: 1px; +} +.ui-datepicker .ui-datepicker-prev span, +.ui-datepicker .ui-datepicker-next span { + display: block; + position: absolute; + left: 50%; + margin-left: -8px; + top: 50%; + margin-top: -8px; +} +.ui-datepicker .ui-datepicker-title { + margin: 0 2.3em; + line-height: 1.8em; + text-align: center; +} +.ui-datepicker .ui-datepicker-title select { + font-size: 1em; + margin: 1px 0; +} +.ui-datepicker select.ui-datepicker-month, +.ui-datepicker select.ui-datepicker-year { + width: 45%; +} +.ui-datepicker table { + width: 100%; + font-size: .9em; + border-collapse: collapse; + margin: 0 0 .4em; +} +.ui-datepicker th { + padding: .7em .3em; + text-align: center; + font-weight: bold; + border: 0; +} +.ui-datepicker td { + border: 0; + padding: 1px; +} +.ui-datepicker td span, +.ui-datepicker td a { + display: block; + padding: .2em; + text-align: right; + text-decoration: none; +} +.ui-datepicker .ui-datepicker-buttonpane { + background-image: none; + margin: .7em 0 0 0; + padding: 0 .2em; + border-left: 0; + border-right: 0; + border-bottom: 0; +} +.ui-datepicker .ui-datepicker-buttonpane button { + float: right; + margin: .5em .2em .4em; + cursor: pointer; + padding: .2em .6em .3em .6em; + width: auto; + overflow: visible; +} +.ui-datepicker .ui-datepicker-buttonpane button.ui-datepicker-current { + float: left; +} + +/* with multiple calendars */ +.ui-datepicker.ui-datepicker-multi { + width: auto; +} +.ui-datepicker-multi .ui-datepicker-group { + float: left; +} +.ui-datepicker-multi .ui-datepicker-group table { + width: 95%; + margin: 0 auto .4em; +} +.ui-datepicker-multi-2 .ui-datepicker-group { + width: 50%; +} +.ui-datepicker-multi-3 .ui-datepicker-group { + width: 33.3%; +} +.ui-datepicker-multi-4 .ui-datepicker-group { + width: 25%; +} +.ui-datepicker-multi .ui-datepicker-group-last .ui-datepicker-header, +.ui-datepicker-multi .ui-datepicker-group-middle .ui-datepicker-header { + border-left-width: 0; +} +.ui-datepicker-multi .ui-datepicker-buttonpane { + clear: left; +} +.ui-datepicker-row-break { + clear: both; + width: 100%; + font-size: 0; +} + +/* RTL support */ +.ui-datepicker-rtl { + direction: rtl; +} +.ui-datepicker-rtl .ui-datepicker-prev { + right: 2px; + left: auto; +} +.ui-datepicker-rtl .ui-datepicker-next { + left: 2px; + right: auto; +} +.ui-datepicker-rtl .ui-datepicker-prev:hover { + right: 1px; + left: auto; +} +.ui-datepicker-rtl .ui-datepicker-next:hover { + left: 1px; + right: auto; +} +.ui-datepicker-rtl .ui-datepicker-buttonpane { + clear: right; +} +.ui-datepicker-rtl .ui-datepicker-buttonpane button { + float: left; +} +.ui-datepicker-rtl .ui-datepicker-buttonpane button.ui-datepicker-current, +.ui-datepicker-rtl .ui-datepicker-group { + float: right; +} +.ui-datepicker-rtl .ui-datepicker-group-last .ui-datepicker-header, +.ui-datepicker-rtl .ui-datepicker-group-middle .ui-datepicker-header { + border-right-width: 0; + border-left-width: 1px; +} +.ui-dialog { + overflow: hidden; + position: absolute; + top: 0; + left: 0; + padding: .2em; + outline: 0; +} +.ui-dialog .ui-dialog-titlebar { + padding: .4em 1em; + position: relative; +} +.ui-dialog .ui-dialog-title { + float: left; + margin: .1em 0; + white-space: nowrap; + width: 90%; + overflow: hidden; + text-overflow: ellipsis; +} +.ui-dialog .ui-dialog-titlebar-close { + position: absolute; + right: .3em; + top: 50%; + width: 20px; + margin: -10px 0 0 0; + padding: 1px; + height: 20px; +} +.ui-dialog .ui-dialog-content { + position: relative; + border: 0; + padding: .5em 1em; + background: none; + overflow: auto; +} +.ui-dialog .ui-dialog-buttonpane { + text-align: left; + border-width: 1px 0 0 0; + background-image: none; + margin-top: .5em; + padding: .3em 1em .5em .4em; +} +.ui-dialog .ui-dialog-buttonpane .ui-dialog-buttonset { + float: right; +} +.ui-dialog .ui-dialog-buttonpane button { + margin: .5em .4em .5em 0; + cursor: pointer; +} +.ui-dialog .ui-resizable-se { + width: 12px; + height: 12px; + right: -5px; + bottom: -5px; + background-position: 16px 16px; +} +.ui-draggable .ui-dialog-titlebar { + cursor: move; +} +.ui-draggable-handle { + -ms-touch-action: none; + touch-action: none; +} +.ui-menu { + list-style: none; + padding: 0; + margin: 0; + display: block; + outline: none; +} +.ui-menu .ui-menu { + position: absolute; +} +.ui-menu .ui-menu-item { + position: relative; + margin: 0; + padding: 3px 1em 3px .4em; + cursor: pointer; + min-height: 0; /* support: IE7 */ + /* support: IE10, see #8844 */ + list-style-image: url("data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"); +} +.ui-menu .ui-menu-divider { + margin: 5px 0; + height: 0; + font-size: 0; + line-height: 0; + border-width: 1px 0 0 0; +} +.ui-menu .ui-state-focus, +.ui-menu .ui-state-active { + margin: -1px; +} + +/* icon support */ +.ui-menu-icons { + position: relative; +} +.ui-menu-icons .ui-menu-item { + padding-left: 2em; +} + +/* left-aligned */ +.ui-menu .ui-icon { + position: absolute; + top: 0; + bottom: 0; + left: .2em; + margin: auto 0; +} + +/* right-aligned */ +.ui-menu .ui-menu-icon { + left: auto; + right: 0; +} +.ui-progressbar { + height: 2em; + text-align: left; + overflow: hidden; +} +.ui-progressbar .ui-progressbar-value { + margin: -1px; + height: 100%; +} +.ui-progressbar .ui-progressbar-overlay { + background: url("data:image/gif;base64,R0lGODlhKAAoAIABAAAAAP///yH/C05FVFNDQVBFMi4wAwEAAAAh+QQJAQABACwAAAAAKAAoAAACkYwNqXrdC52DS06a7MFZI+4FHBCKoDeWKXqymPqGqxvJrXZbMx7Ttc+w9XgU2FB3lOyQRWET2IFGiU9m1frDVpxZZc6bfHwv4c1YXP6k1Vdy292Fb6UkuvFtXpvWSzA+HycXJHUXiGYIiMg2R6W459gnWGfHNdjIqDWVqemH2ekpObkpOlppWUqZiqr6edqqWQAAIfkECQEAAQAsAAAAACgAKAAAApSMgZnGfaqcg1E2uuzDmmHUBR8Qil95hiPKqWn3aqtLsS18y7G1SzNeowWBENtQd+T1JktP05nzPTdJZlR6vUxNWWjV+vUWhWNkWFwxl9VpZRedYcflIOLafaa28XdsH/ynlcc1uPVDZxQIR0K25+cICCmoqCe5mGhZOfeYSUh5yJcJyrkZWWpaR8doJ2o4NYq62lAAACH5BAkBAAEALAAAAAAoACgAAAKVDI4Yy22ZnINRNqosw0Bv7i1gyHUkFj7oSaWlu3ovC8GxNso5fluz3qLVhBVeT/Lz7ZTHyxL5dDalQWPVOsQWtRnuwXaFTj9jVVh8pma9JjZ4zYSj5ZOyma7uuolffh+IR5aW97cHuBUXKGKXlKjn+DiHWMcYJah4N0lYCMlJOXipGRr5qdgoSTrqWSq6WFl2ypoaUAAAIfkECQEAAQAsAAAAACgAKAAAApaEb6HLgd/iO7FNWtcFWe+ufODGjRfoiJ2akShbueb0wtI50zm02pbvwfWEMWBQ1zKGlLIhskiEPm9R6vRXxV4ZzWT2yHOGpWMyorblKlNp8HmHEb/lCXjcW7bmtXP8Xt229OVWR1fod2eWqNfHuMjXCPkIGNileOiImVmCOEmoSfn3yXlJWmoHGhqp6ilYuWYpmTqKUgAAIfkECQEAAQAsAAAAACgAKAAAApiEH6kb58biQ3FNWtMFWW3eNVcojuFGfqnZqSebuS06w5V80/X02pKe8zFwP6EFWOT1lDFk8rGERh1TTNOocQ61Hm4Xm2VexUHpzjymViHrFbiELsefVrn6XKfnt2Q9G/+Xdie499XHd2g4h7ioOGhXGJboGAnXSBnoBwKYyfioubZJ2Hn0RuRZaflZOil56Zp6iioKSXpUAAAh+QQJAQABACwAAAAAKAAoAAACkoQRqRvnxuI7kU1a1UU5bd5tnSeOZXhmn5lWK3qNTWvRdQxP8qvaC+/yaYQzXO7BMvaUEmJRd3TsiMAgswmNYrSgZdYrTX6tSHGZO73ezuAw2uxuQ+BbeZfMxsexY35+/Qe4J1inV0g4x3WHuMhIl2jXOKT2Q+VU5fgoSUI52VfZyfkJGkha6jmY+aaYdirq+lQAACH5BAkBAAEALAAAAAAoACgAAAKWBIKpYe0L3YNKToqswUlvznigd4wiR4KhZrKt9Upqip61i9E3vMvxRdHlbEFiEXfk9YARYxOZZD6VQ2pUunBmtRXo1Lf8hMVVcNl8JafV38aM2/Fu5V16Bn63r6xt97j09+MXSFi4BniGFae3hzbH9+hYBzkpuUh5aZmHuanZOZgIuvbGiNeomCnaxxap2upaCZsq+1kAACH5BAkBAAEALAAAAAAoACgAAAKXjI8By5zf4kOxTVrXNVlv1X0d8IGZGKLnNpYtm8Lr9cqVeuOSvfOW79D9aDHizNhDJidFZhNydEahOaDH6nomtJjp1tutKoNWkvA6JqfRVLHU/QUfau9l2x7G54d1fl995xcIGAdXqMfBNadoYrhH+Mg2KBlpVpbluCiXmMnZ2Sh4GBqJ+ckIOqqJ6LmKSllZmsoq6wpQAAAh+QQJAQABACwAAAAAKAAoAAAClYx/oLvoxuJDkU1a1YUZbJ59nSd2ZXhWqbRa2/gF8Gu2DY3iqs7yrq+xBYEkYvFSM8aSSObE+ZgRl1BHFZNr7pRCavZ5BW2142hY3AN/zWtsmf12p9XxxFl2lpLn1rseztfXZjdIWIf2s5dItwjYKBgo9yg5pHgzJXTEeGlZuenpyPmpGQoKOWkYmSpaSnqKileI2FAAACH5BAkBAAEALAAAAAAoACgAAAKVjB+gu+jG4kORTVrVhRlsnn2dJ3ZleFaptFrb+CXmO9OozeL5VfP99HvAWhpiUdcwkpBH3825AwYdU8xTqlLGhtCosArKMpvfa1mMRae9VvWZfeB2XfPkeLmm18lUcBj+p5dnN8jXZ3YIGEhYuOUn45aoCDkp16hl5IjYJvjWKcnoGQpqyPlpOhr3aElaqrq56Bq7VAAAOw=="); + height: 100%; + filter: alpha(opacity=25); /* support: IE8 */ + opacity: 0.25; +} +.ui-progressbar-indeterminate .ui-progressbar-value { + background-image: none; +} +.ui-resizable { + position: relative; +} +.ui-resizable-handle { + position: absolute; + font-size: 0.1px; + display: block; + -ms-touch-action: none; + touch-action: none; +} +.ui-resizable-disabled .ui-resizable-handle, +.ui-resizable-autohide .ui-resizable-handle { + display: none; +} +.ui-resizable-n { + cursor: n-resize; + height: 7px; + width: 100%; + top: -5px; + left: 0; +} +.ui-resizable-s { + cursor: s-resize; + height: 7px; + width: 100%; + bottom: -5px; + left: 0; +} +.ui-resizable-e { + cursor: e-resize; + width: 7px; + right: -5px; + top: 0; + height: 100%; +} +.ui-resizable-w { + cursor: w-resize; + width: 7px; + left: -5px; + top: 0; + height: 100%; +} +.ui-resizable-se { + cursor: se-resize; + width: 12px; + height: 12px; + right: 1px; + bottom: 1px; +} +.ui-resizable-sw { + cursor: sw-resize; + width: 9px; + height: 9px; + left: -5px; + bottom: -5px; +} +.ui-resizable-nw { + cursor: nw-resize; + width: 9px; + height: 9px; + left: -5px; + top: -5px; +} +.ui-resizable-ne { + cursor: ne-resize; + width: 9px; + height: 9px; + right: -5px; + top: -5px; +} +.ui-selectable { + -ms-touch-action: none; + touch-action: none; +} +.ui-selectable-helper { + position: absolute; + z-index: 100; + border: 1px dotted black; +} +.ui-selectmenu-menu { + padding: 0; + margin: 0; + position: absolute; + top: 0; + left: 0; + display: none; +} +.ui-selectmenu-menu .ui-menu { + overflow: auto; + /* Support: IE7 */ + overflow-x: hidden; + padding-bottom: 1px; +} +.ui-selectmenu-menu .ui-menu .ui-selectmenu-optgroup { + font-size: 1em; + font-weight: bold; + line-height: 1.5; + padding: 2px 0.4em; + margin: 0.5em 0 0 0; + height: auto; + border: 0; +} +.ui-selectmenu-open { + display: block; +} +.ui-selectmenu-button { + display: inline-block; + overflow: hidden; + position: relative; + text-decoration: none; + cursor: pointer; +} +.ui-selectmenu-button span.ui-icon { + right: 0.5em; + left: auto; + margin-top: -8px; + position: absolute; + top: 50%; +} +.ui-selectmenu-button span.ui-selectmenu-text { + text-align: left; + padding: 0.4em 2.1em 0.4em 1em; + display: block; + line-height: 1.4; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} +.ui-slider { + position: relative; + text-align: left; +} +.ui-slider .ui-slider-handle { + position: absolute; + z-index: 2; + width: 1.2em; + height: 1.2em; + cursor: default; + -ms-touch-action: none; + touch-action: none; +} +.ui-slider .ui-slider-range { + position: absolute; + z-index: 1; + font-size: .7em; + display: block; + border: 0; + background-position: 0 0; +} + +/* support: IE8 - See #6727 */ +.ui-slider.ui-state-disabled .ui-slider-handle, +.ui-slider.ui-state-disabled .ui-slider-range { + filter: inherit; +} + +.ui-slider-horizontal { + height: .8em; +} +.ui-slider-horizontal .ui-slider-handle { + top: -.3em; + margin-left: -.6em; +} +.ui-slider-horizontal .ui-slider-range { + top: 0; + height: 100%; +} +.ui-slider-horizontal .ui-slider-range-min { + left: 0; +} +.ui-slider-horizontal .ui-slider-range-max { + right: 0; +} + +.ui-slider-vertical { + width: .8em; + height: 100px; +} +.ui-slider-vertical .ui-slider-handle { + left: -.3em; + margin-left: 0; + margin-bottom: -.6em; +} +.ui-slider-vertical .ui-slider-range { + left: 0; + width: 100%; +} +.ui-slider-vertical .ui-slider-range-min { + bottom: 0; +} +.ui-slider-vertical .ui-slider-range-max { + top: 0; +} +.ui-sortable-handle { + -ms-touch-action: none; + touch-action: none; +} +.ui-spinner { + position: relative; + display: inline-block; + overflow: hidden; + padding: 0; + vertical-align: middle; +} +.ui-spinner-input { + border: none; + background: none; + color: inherit; + padding: 0; + margin: .2em 0; + vertical-align: middle; + margin-left: .4em; + margin-right: 22px; +} +.ui-spinner-button { + width: 16px; + height: 50%; + font-size: .5em; + padding: 0; + margin: 0; + text-align: center; + position: absolute; + cursor: default; + display: block; + overflow: hidden; + right: 0; +} +/* more specificity required here to override default borders */ +.ui-spinner a.ui-spinner-button { + border-top: none; + border-bottom: none; + border-right: none; +} +/* vertically center icon */ +.ui-spinner .ui-icon { + position: absolute; + margin-top: -8px; + top: 50%; + left: 0; +} +.ui-spinner-up { + top: 0; +} +.ui-spinner-down { + bottom: 0; +} + +/* TR overrides */ +.ui-spinner .ui-icon-triangle-1-s { + /* need to fix icons sprite */ + background-position: -65px -16px; +} +.ui-tabs { + position: relative;/* position: relative prevents IE scroll bug (element with position: relative inside container with overflow: auto appear as "fixed") */ + padding: .2em; +} +.ui-tabs .ui-tabs-nav { + margin: 0; + padding: .2em .2em 0; +} +.ui-tabs .ui-tabs-nav li { + list-style: none; + float: left; + position: relative; + top: 0; + margin: 1px .2em 0 0; + border-bottom-width: 0; + padding: 0; + white-space: nowrap; +} +.ui-tabs .ui-tabs-nav .ui-tabs-anchor { + float: left; + padding: .5em 1em; + text-decoration: none; +} +.ui-tabs .ui-tabs-nav li.ui-tabs-active { + margin-bottom: -1px; + padding-bottom: 1px; +} +.ui-tabs .ui-tabs-nav li.ui-tabs-active .ui-tabs-anchor, +.ui-tabs .ui-tabs-nav li.ui-state-disabled .ui-tabs-anchor, +.ui-tabs .ui-tabs-nav li.ui-tabs-loading .ui-tabs-anchor { + cursor: text; +} +.ui-tabs-collapsible .ui-tabs-nav li.ui-tabs-active .ui-tabs-anchor { + cursor: pointer; +} +.ui-tabs .ui-tabs-panel { + display: block; + border-width: 0; + padding: 1em 1.4em; + background: none; +} +.ui-tooltip { + padding: 8px; + position: absolute; + z-index: 9999; + max-width: 300px; + -webkit-box-shadow: 0 0 5px #aaa; + box-shadow: 0 0 5px #aaa; +} +body .ui-tooltip { + border-width: 2px; +} + +/* Component containers +----------------------------------*/ +.ui-widget { + font-family: Verdana,Arial,sans-serif; + font-size: 1.1em; +} +.ui-widget .ui-widget { + font-size: 1em; +} +.ui-widget input, +.ui-widget select, +.ui-widget textarea, +.ui-widget button { + font-family: Verdana,Arial,sans-serif; + font-size: 1em; +} +.ui-widget-content { + border: 1px solid #aaaaaa; + background: #ffffff url("images/ui-bg_flat_75_ffffff_40x100.png") 50% 50% repeat-x; + color: #222222; +} +.ui-widget-content a { + color: #222222; +} +.ui-widget-header { + border: 1px solid #aaaaaa; + background: #cccccc url("images/ui-bg_highlight-soft_75_cccccc_1x100.png") 50% 50% repeat-x; + color: #222222; + font-weight: bold; +} +.ui-widget-header a { + color: #222222; +} + +/* Interaction states +----------------------------------*/ +.ui-state-default, +.ui-widget-content .ui-state-default, +.ui-widget-header .ui-state-default { + border: 1px solid #d3d3d3; + background: #e6e6e6 url("images/ui-bg_glass_75_e6e6e6_1x400.png") 50% 50% repeat-x; + font-weight: normal; + color: #555555; +} +.ui-state-default a, +.ui-state-default a:link, +.ui-state-default a:visited { + color: #555555; + text-decoration: none; +} +.ui-state-hover, +.ui-widget-content .ui-state-hover, +.ui-widget-header .ui-state-hover, +.ui-state-focus, +.ui-widget-content .ui-state-focus, +.ui-widget-header .ui-state-focus { + border: 1px solid #999999; + background: #dadada url("images/ui-bg_glass_75_dadada_1x400.png") 50% 50% repeat-x; + font-weight: normal; + color: #212121; +} +.ui-state-hover a, +.ui-state-hover a:hover, +.ui-state-hover a:link, +.ui-state-hover a:visited, +.ui-state-focus a, +.ui-state-focus a:hover, +.ui-state-focus a:link, +.ui-state-focus a:visited { + color: #212121; + text-decoration: none; +} +.ui-state-active, +.ui-widget-content .ui-state-active, +.ui-widget-header .ui-state-active { + border: 1px solid #aaaaaa; + background: #ffffff url("images/ui-bg_glass_65_ffffff_1x400.png") 50% 50% repeat-x; + font-weight: normal; + color: #212121; +} +.ui-state-active a, +.ui-state-active a:link, +.ui-state-active a:visited { + color: #212121; + text-decoration: none; +} + +/* Interaction Cues +----------------------------------*/ +.ui-state-highlight, +.ui-widget-content .ui-state-highlight, +.ui-widget-header .ui-state-highlight { + border: 1px solid #fcefa1; + background: #fbf9ee url("images/ui-bg_glass_55_fbf9ee_1x400.png") 50% 50% repeat-x; + color: #363636; +} +.ui-state-highlight a, +.ui-widget-content .ui-state-highlight a, +.ui-widget-header .ui-state-highlight a { + color: #363636; +} +.ui-state-error, +.ui-widget-content .ui-state-error, +.ui-widget-header .ui-state-error { + border: 1px solid #cd0a0a; + background: #fef1ec url("images/ui-bg_glass_95_fef1ec_1x400.png") 50% 50% repeat-x; + color: #cd0a0a; +} +.ui-state-error a, +.ui-widget-content .ui-state-error a, +.ui-widget-header .ui-state-error a { + color: #cd0a0a; +} +.ui-state-error-text, +.ui-widget-content .ui-state-error-text, +.ui-widget-header .ui-state-error-text { + color: #cd0a0a; +} +.ui-priority-primary, +.ui-widget-content .ui-priority-primary, +.ui-widget-header .ui-priority-primary { + font-weight: bold; +} +.ui-priority-secondary, +.ui-widget-content .ui-priority-secondary, +.ui-widget-header .ui-priority-secondary { + opacity: .7; + filter:Alpha(Opacity=70); /* support: IE8 */ + font-weight: normal; +} +.ui-state-disabled, +.ui-widget-content .ui-state-disabled, +.ui-widget-header .ui-state-disabled { + opacity: .35; + filter:Alpha(Opacity=35); /* support: IE8 */ + background-image: none; +} +.ui-state-disabled .ui-icon { + filter:Alpha(Opacity=35); /* support: IE8 - See #6059 */ +} + +/* Icons +----------------------------------*/ + +/* states and images */ +.ui-icon { + width: 16px; + height: 16px; +} +.ui-icon, +.ui-widget-content .ui-icon { + background-image: url("images/ui-icons_222222_256x240.png"); +} +.ui-widget-header .ui-icon { + background-image: url("images/ui-icons_222222_256x240.png"); +} +.ui-state-default .ui-icon { + background-image: url("images/ui-icons_888888_256x240.png"); +} +.ui-state-hover .ui-icon, +.ui-state-focus .ui-icon { + background-image: url("images/ui-icons_454545_256x240.png"); +} +.ui-state-active .ui-icon { + background-image: url("images/ui-icons_454545_256x240.png"); +} +.ui-state-highlight .ui-icon { + background-image: url("images/ui-icons_2e83ff_256x240.png"); +} +.ui-state-error .ui-icon, +.ui-state-error-text .ui-icon { + background-image: url("images/ui-icons_cd0a0a_256x240.png"); +} + +/* positioning */ +.ui-icon-blank { background-position: 16px 16px; } +.ui-icon-carat-1-n { background-position: 0 0; } +.ui-icon-carat-1-ne { background-position: -16px 0; } +.ui-icon-carat-1-e { background-position: -32px 0; } +.ui-icon-carat-1-se { background-position: -48px 0; } +.ui-icon-carat-1-s { background-position: -64px 0; } +.ui-icon-carat-1-sw { background-position: -80px 0; } +.ui-icon-carat-1-w { background-position: -96px 0; } +.ui-icon-carat-1-nw { background-position: -112px 0; } +.ui-icon-carat-2-n-s { background-position: -128px 0; } +.ui-icon-carat-2-e-w { background-position: -144px 0; } +.ui-icon-triangle-1-n { background-position: 0 -16px; } +.ui-icon-triangle-1-ne { background-position: -16px -16px; } +.ui-icon-triangle-1-e { background-position: -32px -16px; } +.ui-icon-triangle-1-se { background-position: -48px -16px; } +.ui-icon-triangle-1-s { background-position: -64px -16px; } +.ui-icon-triangle-1-sw { background-position: -80px -16px; } +.ui-icon-triangle-1-w { background-position: -96px -16px; } +.ui-icon-triangle-1-nw { background-position: -112px -16px; } +.ui-icon-triangle-2-n-s { background-position: -128px -16px; } +.ui-icon-triangle-2-e-w { background-position: -144px -16px; } +.ui-icon-arrow-1-n { background-position: 0 -32px; } +.ui-icon-arrow-1-ne { background-position: -16px -32px; } +.ui-icon-arrow-1-e { background-position: -32px -32px; } +.ui-icon-arrow-1-se { background-position: -48px -32px; } +.ui-icon-arrow-1-s { background-position: -64px -32px; } +.ui-icon-arrow-1-sw { background-position: -80px -32px; } +.ui-icon-arrow-1-w { background-position: -96px -32px; } +.ui-icon-arrow-1-nw { background-position: -112px -32px; } +.ui-icon-arrow-2-n-s { background-position: -128px -32px; } +.ui-icon-arrow-2-ne-sw { background-position: -144px -32px; } +.ui-icon-arrow-2-e-w { background-position: -160px -32px; } +.ui-icon-arrow-2-se-nw { background-position: -176px -32px; } +.ui-icon-arrowstop-1-n { background-position: -192px -32px; } +.ui-icon-arrowstop-1-e { background-position: -208px -32px; } +.ui-icon-arrowstop-1-s { background-position: -224px -32px; } +.ui-icon-arrowstop-1-w { background-position: -240px -32px; } +.ui-icon-arrowthick-1-n { background-position: 0 -48px; } +.ui-icon-arrowthick-1-ne { background-position: -16px -48px; } +.ui-icon-arrowthick-1-e { background-position: -32px -48px; } +.ui-icon-arrowthick-1-se { background-position: -48px -48px; } +.ui-icon-arrowthick-1-s { background-position: -64px -48px; } +.ui-icon-arrowthick-1-sw { background-position: -80px -48px; } +.ui-icon-arrowthick-1-w { background-position: -96px -48px; } +.ui-icon-arrowthick-1-nw { background-position: -112px -48px; } +.ui-icon-arrowthick-2-n-s { background-position: -128px -48px; } +.ui-icon-arrowthick-2-ne-sw { background-position: -144px -48px; } +.ui-icon-arrowthick-2-e-w { background-position: -160px -48px; } +.ui-icon-arrowthick-2-se-nw { background-position: -176px -48px; } +.ui-icon-arrowthickstop-1-n { background-position: -192px -48px; } +.ui-icon-arrowthickstop-1-e { background-position: -208px -48px; } +.ui-icon-arrowthickstop-1-s { background-position: -224px -48px; } +.ui-icon-arrowthickstop-1-w { background-position: -240px -48px; } +.ui-icon-arrowreturnthick-1-w { background-position: 0 -64px; } +.ui-icon-arrowreturnthick-1-n { background-position: -16px -64px; } +.ui-icon-arrowreturnthick-1-e { background-position: -32px -64px; } +.ui-icon-arrowreturnthick-1-s { background-position: -48px -64px; } +.ui-icon-arrowreturn-1-w { background-position: -64px -64px; } +.ui-icon-arrowreturn-1-n { background-position: -80px -64px; } +.ui-icon-arrowreturn-1-e { background-position: -96px -64px; } +.ui-icon-arrowreturn-1-s { background-position: -112px -64px; } +.ui-icon-arrowrefresh-1-w { background-position: -128px -64px; } +.ui-icon-arrowrefresh-1-n { background-position: -144px -64px; } +.ui-icon-arrowrefresh-1-e { background-position: -160px -64px; } +.ui-icon-arrowrefresh-1-s { background-position: -176px -64px; } +.ui-icon-arrow-4 { background-position: 0 -80px; } +.ui-icon-arrow-4-diag { background-position: -16px -80px; } +.ui-icon-extlink { background-position: -32px -80px; } +.ui-icon-newwin { background-position: -48px -80px; } +.ui-icon-refresh { background-position: -64px -80px; } +.ui-icon-shuffle { background-position: -80px -80px; } +.ui-icon-transfer-e-w { background-position: -96px -80px; } +.ui-icon-transferthick-e-w { background-position: -112px -80px; } +.ui-icon-folder-collapsed { background-position: 0 -96px; } +.ui-icon-folder-open { background-position: -16px -96px; } +.ui-icon-document { background-position: -32px -96px; } +.ui-icon-document-b { background-position: -48px -96px; } +.ui-icon-note { background-position: -64px -96px; } +.ui-icon-mail-closed { background-position: -80px -96px; } +.ui-icon-mail-open { background-position: -96px -96px; } +.ui-icon-suitcase { background-position: -112px -96px; } +.ui-icon-comment { background-position: -128px -96px; } +.ui-icon-person { background-position: -144px -96px; } +.ui-icon-print { background-position: -160px -96px; } +.ui-icon-trash { background-position: -176px -96px; } +.ui-icon-locked { background-position: -192px -96px; } +.ui-icon-unlocked { background-position: -208px -96px; } +.ui-icon-bookmark { background-position: -224px -96px; } +.ui-icon-tag { background-position: -240px -96px; } +.ui-icon-home { background-position: 0 -112px; } +.ui-icon-flag { background-position: -16px -112px; } +.ui-icon-calendar { background-position: -32px -112px; } +.ui-icon-cart { background-position: -48px -112px; } +.ui-icon-pencil { background-position: -64px -112px; } +.ui-icon-clock { background-position: -80px -112px; } +.ui-icon-disk { background-position: -96px -112px; } +.ui-icon-calculator { background-position: -112px -112px; } +.ui-icon-zoomin { background-position: -128px -112px; } +.ui-icon-zoomout { background-position: -144px -112px; } +.ui-icon-search { background-position: -160px -112px; } +.ui-icon-wrench { background-position: -176px -112px; } +.ui-icon-gear { background-position: -192px -112px; } +.ui-icon-heart { background-position: -208px -112px; } +.ui-icon-star { background-position: -224px -112px; } +.ui-icon-link { background-position: -240px -112px; } +.ui-icon-cancel { background-position: 0 -128px; } +.ui-icon-plus { background-position: -16px -128px; } +.ui-icon-plusthick { background-position: -32px -128px; } +.ui-icon-minus { background-position: -48px -128px; } +.ui-icon-minusthick { background-position: -64px -128px; } +.ui-icon-close { background-position: -80px -128px; } +.ui-icon-closethick { background-position: -96px -128px; } +.ui-icon-key { background-position: -112px -128px; } +.ui-icon-lightbulb { background-position: -128px -128px; } +.ui-icon-scissors { background-position: -144px -128px; } +.ui-icon-clipboard { background-position: -160px -128px; } +.ui-icon-copy { background-position: -176px -128px; } +.ui-icon-contact { background-position: -192px -128px; } +.ui-icon-image { background-position: -208px -128px; } +.ui-icon-video { background-position: -224px -128px; } +.ui-icon-script { background-position: -240px -128px; } +.ui-icon-alert { background-position: 0 -144px; } +.ui-icon-info { background-position: -16px -144px; } +.ui-icon-notice { background-position: -32px -144px; } +.ui-icon-help { background-position: -48px -144px; } +.ui-icon-check { background-position: -64px -144px; } +.ui-icon-bullet { background-position: -80px -144px; } +.ui-icon-radio-on { background-position: -96px -144px; } +.ui-icon-radio-off { background-position: -112px -144px; } +.ui-icon-pin-w { background-position: -128px -144px; } +.ui-icon-pin-s { background-position: -144px -144px; } +.ui-icon-play { background-position: 0 -160px; } +.ui-icon-pause { background-position: -16px -160px; } +.ui-icon-seek-next { background-position: -32px -160px; } +.ui-icon-seek-prev { background-position: -48px -160px; } +.ui-icon-seek-end { background-position: -64px -160px; } +.ui-icon-seek-start { background-position: -80px -160px; } +/* ui-icon-seek-first is deprecated, use ui-icon-seek-start instead */ +.ui-icon-seek-first { background-position: -80px -160px; } +.ui-icon-stop { background-position: -96px -160px; } +.ui-icon-eject { background-position: -112px -160px; } +.ui-icon-volume-off { background-position: -128px -160px; } +.ui-icon-volume-on { background-position: -144px -160px; } +.ui-icon-power { background-position: 0 -176px; } +.ui-icon-signal-diag { background-position: -16px -176px; } +.ui-icon-signal { background-position: -32px -176px; } +.ui-icon-battery-0 { background-position: -48px -176px; } +.ui-icon-battery-1 { background-position: -64px -176px; } +.ui-icon-battery-2 { background-position: -80px -176px; } +.ui-icon-battery-3 { background-position: -96px -176px; } +.ui-icon-circle-plus { background-position: 0 -192px; } +.ui-icon-circle-minus { background-position: -16px -192px; } +.ui-icon-circle-close { background-position: -32px -192px; } +.ui-icon-circle-triangle-e { background-position: -48px -192px; } +.ui-icon-circle-triangle-s { background-position: -64px -192px; } +.ui-icon-circle-triangle-w { background-position: -80px -192px; } +.ui-icon-circle-triangle-n { background-position: -96px -192px; } +.ui-icon-circle-arrow-e { background-position: -112px -192px; } +.ui-icon-circle-arrow-s { background-position: -128px -192px; } +.ui-icon-circle-arrow-w { background-position: -144px -192px; } +.ui-icon-circle-arrow-n { background-position: -160px -192px; } +.ui-icon-circle-zoomin { background-position: -176px -192px; } +.ui-icon-circle-zoomout { background-position: -192px -192px; } +.ui-icon-circle-check { background-position: -208px -192px; } +.ui-icon-circlesmall-plus { background-position: 0 -208px; } +.ui-icon-circlesmall-minus { background-position: -16px -208px; } +.ui-icon-circlesmall-close { background-position: -32px -208px; } +.ui-icon-squaresmall-plus { background-position: -48px -208px; } +.ui-icon-squaresmall-minus { background-position: -64px -208px; } +.ui-icon-squaresmall-close { background-position: -80px -208px; } +.ui-icon-grip-dotted-vertical { background-position: 0 -224px; } +.ui-icon-grip-dotted-horizontal { background-position: -16px -224px; } +.ui-icon-grip-solid-vertical { background-position: -32px -224px; } +.ui-icon-grip-solid-horizontal { background-position: -48px -224px; } +.ui-icon-gripsmall-diagonal-se { background-position: -64px -224px; } +.ui-icon-grip-diagonal-se { background-position: -80px -224px; } + + +/* Misc visuals +----------------------------------*/ + +/* Corner radius */ +.ui-corner-all, +.ui-corner-top, +.ui-corner-left, +.ui-corner-tl { + border-top-left-radius: 4px; +} +.ui-corner-all, +.ui-corner-top, +.ui-corner-right, +.ui-corner-tr { + border-top-right-radius: 4px; +} +.ui-corner-all, +.ui-corner-bottom, +.ui-corner-left, +.ui-corner-bl { + border-bottom-left-radius: 4px; +} +.ui-corner-all, +.ui-corner-bottom, +.ui-corner-right, +.ui-corner-br { + border-bottom-right-radius: 4px; +} + +/* Overlays */ +.ui-widget-overlay { + background: #aaaaaa url("images/ui-bg_flat_0_aaaaaa_40x100.png") 50% 50% repeat-x; + opacity: .3; + filter: Alpha(Opacity=30); /* support: IE8 */ +} +.ui-widget-shadow { + margin: -8px 0 0 -8px; + padding: 8px; + background: #aaaaaa url("images/ui-bg_flat_0_aaaaaa_40x100.png") 50% 50% repeat-x; + opacity: .3; + filter: Alpha(Opacity=30); /* support: IE8 */ + border-radius: 8px; +} diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/styles/layout/layout-default-latest.css b/ecomp-sdk-app/src/main/webapp/app/fusion/styles/layout/layout-default-latest.css new file mode 100644 index 000000000..aa382de3a --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/styles/layout/layout-default-latest.css @@ -0,0 +1,224 @@ +/* + * Default Layout Theme + * + * Created for jquery.layout + * + * Copyright (c) 2010 + * Fabrizio Balliano (http://www.fabrizioballiano.net) + * Kevin Dalman (http://allpro.net) + * + * Dual licensed under the GPL (http://www.gnu.org/licenses/gpl.html) + * and MIT (http://www.opensource.org/licenses/mit-license.php) licenses. + * + * Last Updated: 2010-02-10 + * NOTE: For best code readability, view this with a fixed-space font and tabs equal to 4-chars + */ + +/* + * DEFAULT FONT + * Just to make demo-pages look better - not actually relevant to Layout! + */ +body { + font-family: Geneva, Arial, Helvetica, sans-serif; + font-size: 100%; + *font-size: 80%; +} + +/* + * PANES & CONTENT-DIVs + */ +.ui-layout-pane { /* all 'panes' */ + background: #FFF; + border: 1px solid #BBB; + padding: 10px; + overflow: auto; + /* DO NOT add scrolling (or padding) to 'panes' that have a content-div, + otherwise you may get double-scrollbars - on the pane AND on the content-div + - use ui-layout-wrapper class if pane has a content-div + - use ui-layout-container if pane has an inner-layout + */ + } + /* (scrolling) content-div inside pane allows for fixed header(s) and/or footer(s) */ + .ui-layout-content { + padding: 10px; + position: relative; /* contain floated or positioned elements */ + overflow: auto; /* add scrolling to content-div */ + } + +/* + * UTILITY CLASSES + * Must come AFTER pane-class above so will override + * These classes are NOT auto-generated and are NOT used by Layout + */ +.layout-child-container, +.layout-content-container { + padding: 0; + overflow: hidden; +} +.layout-child-container { + border: 0; /* remove border because inner-layout-panes probably have borders */ +} +.layout-scroll { + overflow: auto; +} +.layout-hide { + display: none; +} + +/* + * RESIZER-BARS + */ +.ui-layout-resizer { /* all 'resizer-bars' */ + background: #DDD; + border: 1px solid #BBB; + border-width: 0; + } + .ui-layout-resizer-drag { /* REAL resizer while resize in progress */ + } + .ui-layout-resizer-hover { /* affects both open and closed states */ + } + /* NOTE: It looks best when 'hover' and 'dragging' are set to the same color, + otherwise color shifts while dragging when bar can't keep up with mouse */ + .ui-layout-resizer-open-hover , /* hover-color to 'resize' */ + .ui-layout-resizer-dragging { /* resizer beging 'dragging' */ + background: #C4E1A4; + } + .ui-layout-resizer-dragging { /* CLONED resizer being dragged */ + border: 1px solid #BBB; + } + .ui-layout-resizer-north-dragging, + .ui-layout-resizer-south-dragging { + border-width: 1px 0; + } + .ui-layout-resizer-west-dragging, + .ui-layout-resizer-east-dragging { + border-width: 0 1px; + } + /* NOTE: Add a 'dragging-limit' color to provide visual feedback when resizer hits min/max size limits */ + .ui-layout-resizer-dragging-limit { /* CLONED resizer at min or max size-limit */ + background: #E1A4A4; /* red */ + } + + .ui-layout-resizer-closed-hover { /* hover-color to 'slide open' */ + background: #EBD5AA; + } + .ui-layout-resizer-sliding { /* resizer when pane is 'slid open' */ + opacity: .10; /* show only a slight shadow */ + filter: alpha(opacity=10); + } + .ui-layout-resizer-sliding-hover { /* sliding resizer - hover */ + opacity: 1.00; /* on-hover, show the resizer-bar normally */ + filter: alpha(opacity=100); + } + /* sliding resizer - add 'outside-border' to resizer on-hover + * this sample illustrates how to target specific panes and states */ + .ui-layout-resizer-north-sliding-hover { border-bottom-width: 1px; } + .ui-layout-resizer-south-sliding-hover { border-top-width: 1px; } + .ui-layout-resizer-west-sliding-hover { border-right-width: 1px; } + .ui-layout-resizer-east-sliding-hover { border-left-width: 1px; } + +/* + * TOGGLER-BUTTONS + */ +.ui-layout-toggler { + border: 1px solid #BBB; /* match pane-border */ + background-color: #BBB; + } + .ui-layout-resizer-hover .ui-layout-toggler { + opacity: .60; + filter: alpha(opacity=60); + } + .ui-layout-toggler-hover , /* need when NOT resizable */ + .ui-layout-resizer-hover .ui-layout-toggler-hover { /* need specificity when IS resizable */ + background-color: #FC6; + opacity: 1.00; + filter: alpha(opacity=100); + } + .ui-layout-toggler-north , + .ui-layout-toggler-south { + border-width: 0 1px; /* left/right borders */ + } + .ui-layout-toggler-west , + .ui-layout-toggler-east { + border-width: 1px 0; /* top/bottom borders */ + } + /* hide the toggler-button when the pane is 'slid open' */ + .ui-layout-resizer-sliding .ui-layout-toggler { + display: none; + } + /* + * style the text we put INSIDE the togglers + */ + .ui-layout-toggler .content { + color: #666; + font-size: 12px; + font-weight: bold; + width: 100%; + padding-bottom: 0.35ex; /* to 'vertically center' text inside text-span */ + } + +/* + * PANE-MASKS + * these styles are hard-coded on mask elems, but are also + * included here as !important to ensure will overrides any generic styles + */ +.ui-layout-mask { + border: none !important; + padding: 0 !important; + margin: 0 !important; + overflow: hidden !important; + position: absolute !important; + opacity: 0 !important; + filter: Alpha(Opacity="0") !important; +} +.ui-layout-mask-inside-pane { /* masks always inside pane EXCEPT when pane is an iframe */ + top: 0 !important; + left: 0 !important; + width: 100% !important; + height: 100% !important; +} +div.ui-layout-mask {} /* standard mask for iframes */ +iframe.ui-layout-mask {} /* extra mask for objects/applets */ + +/* + * Default printing styles + */ +@media print { + /* + * Unless you want to print the layout as it appears onscreen, + * these html/body styles are needed to allow the content to 'flow' + */ + html { + height: auto !important; + overflow: visible !important; + } + body.ui-layout-container { + position: static !important; + top: auto !important; + bottom: auto !important; + left: auto !important; + right: auto !important; + /* only IE6 has container width & height set by Layout */ + _width: auto !important; + _height: auto !important; + } + .ui-layout-resizer, .ui-layout-toggler { + display: none !important; + } + /* + * Default pane print styles disables positioning, borders and backgrounds. + * You can modify these styles however it suit your needs. + */ + .ui-layout-pane { + border: none !important; + background: transparent !important; + position: relative !important; + top: auto !important; + bottom: auto !important; + left: auto !important; + right: auto !important; + width: auto !important; + height: auto !important; + overflow: visible !important; + } +} \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/fusion/styles/workflows/workflows.css b/ecomp-sdk-app/src/main/webapp/app/fusion/styles/workflows/workflows.css new file mode 100644 index 000000000..b9d0146c1 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusion/styles/workflows/workflows.css @@ -0,0 +1,50 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +.scrolling-table{ + width: 1200px; +} +.scrolling-table .scroll-viewport { + height: 200px !important; + width: 99.5% !important; + background-color:white; +} + +.scrolling-table .scroll-overview{ + margin-top:-14px !important; +} + +.scrolling-table .scroll-viewport:hover{ + background-color:white; +} + +.scrolling-table #att-scroll-table-content{ + height:200px; + position: absolute !important; + width:700px; + padding-left: 0px; + padding-top: 0px; + padding-bottom: 0px; + padding-right:5px; +} + +.workflow-popup-body{ + position: relative; + padding: 30px; +} diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/drools/controller/drools-list-controller.js b/ecomp-sdk-app/src/main/webapp/app/fusionapp/drools/controller/drools-list-controller.js new file mode 100644 index 000000000..4e6243458 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusionapp/drools/controller/drools-list-controller.js @@ -0,0 +1,62 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +app.controller("droolsListController", function ($scope,$http,droolsService, modalService, $modal) { + // Table Data + droolsService.getDrools().then(function(data){ + + var j = data; + $scope.tableData = JSON.parse(j.data); + //$scope.resetMenu(); + + },function(error){ + console.log("failed"); + reloadPageOnce(); + }); + + $scope.viewPerPage = 20; + $scope.scrollViewsPerPage = 2; + $scope.currentPage = 1; + $scope.totalPage; + $scope.searchCategory = ""; + $scope.searchString = ""; + /* modalService.showSuccess('','Modal Sample') ; */ + for(x in $scope.tableData){ + if($scope.tableData[x].active_yn=='Y') + $scope.tableData[x].active_yn=true; + else + $scope.tableData[x].active_yn=false; + } + $scope.openDialog = function(droolFile){ + droolsService.setSelectedFile(droolFile); + $modal.open({ + templateUrl: 'app/fusionapp/drools/view-models/droolsView.html', + controller: 'droolsViewController' + + }) + } + + + +}); + +function openInNewTab(url) { + var win = window.open(url, '_blank'); + win.focus(); +}; diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/drools/controller/drools-view-controller.js b/ecomp-sdk-app/src/main/webapp/app/fusionapp/drools/controller/drools-view-controller.js new file mode 100644 index 000000000..c475e175b --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusionapp/drools/controller/drools-view-controller.js @@ -0,0 +1,64 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +app.controller('droolsViewController', function ($scope,modalService,droolsService){ + + + $scope.resultsString = ""; + // Table Data + droolsService.getDroolDetails(droolsService.getSelectedFile()).then(function(data){ + + var j = data; + $scope.postDroolsBean = JSON.parse(j.data); + //execute($scope.postDroolsBean); + + },function(error){ + console.log("failed"); + //reloadPageOnce(); + }); + + + + $scope.execute = function(postDroolsBean) { + console.log(postDroolsBean); + var uuu = "post_drools/execute"; + var postData={postDroolsBean:postDroolsBean}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){ + $scope.resultsString=data.resultsString; + console.log($scope.resultsString); + }); + }, + error : function(data){ + console.log(data); + modalService.showFailure("Fail","Error while executing: "+ data.responseText); + } + }); + + }; + + + + }); diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/drools/controller/droolsController.js b/ecomp-sdk-app/src/main/webapp/app/fusionapp/drools/controller/droolsController.js new file mode 100644 index 000000000..f9c0e234f --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusionapp/drools/controller/droolsController.js @@ -0,0 +1,30 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +app.config(function($routeProvider) { + $routeProvider + .when('/view', { + templateUrl: 'app/fusionapp/drools/view-models/droolsView.html', + controller : "droolsViewController" + }) + .otherwise({ + templateUrl: 'app/fusionapp/drools/view-models/droolsList.html', + controller : "droolsListController" + }); +}); diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/drools/controller/dummy.txt b/ecomp-sdk-app/src/main/webapp/app/fusionapp/drools/controller/dummy.txt new file mode 100644 index 000000000..e69de29bb diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/drools/directives/dummy.txt b/ecomp-sdk-app/src/main/webapp/app/fusionapp/drools/directives/dummy.txt new file mode 100644 index 000000000..e69de29bb diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/drools/services/droolsService.js b/ecomp-sdk-app/src/main/webapp/app/fusionapp/drools/services/droolsService.js new file mode 100644 index 000000000..d1dbfa6c3 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusionapp/drools/services/droolsService.js @@ -0,0 +1,76 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +app.factory('droolsService', function ($http, $q) { + return { + getDrools: function() { + return $http.get('getDrools') + .then(function(response) { + if (typeof response.data === 'object') { + return response.data; + } else { + return $q.reject(response.data); + } + + }, function(response) { + // something went wrong + return $q.reject(response.data); + }); + }, + + getDroolDetails: function(selectedFile) { + return $http.get('getDroolDetails'+'?selectedFile=' + selectedFile ) + .then(function(response) { + if (typeof response.data === 'object') { + return response.data; + } else { + return $q.reject(response.data); + } + + }, function(response) { + // something went wrong + return $q.reject(response.data); + }); + }, + + getRole: function(roleId) { + + return $http.get('get_role?role_id=' + roleId) + .then(function(response) { + if (typeof response.data === 'object') { + return response.data; + } else { + return $q.reject(response.data); + } + + }, function(response) { + // something went wrong + return $q.reject(response.data); + }); + }, + + getSelectedFile: function() { + return this.selectedFile; + }, + + setSelectedFile: function(_selectedFile) { + this.selectedFile = _selectedFile; + } + }; +}); diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/drools/utils/dummy.txt b/ecomp-sdk-app/src/main/webapp/app/fusionapp/drools/utils/dummy.txt new file mode 100644 index 000000000..e69de29bb diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/drools/view-models/droolsList.html b/ecomp-sdk-app/src/main/webapp/app/fusionapp/drools/view-models/droolsList.html new file mode 100644 index 000000000..e1f7f6da1 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusionapp/drools/view-models/droolsList.html @@ -0,0 +1,47 @@ + +
      +
      +

      Drools List

      +
      + + + + + + + + + + + + + + + + + + +
      Drools File NameClass NameRun Rule
      {{rowData.droolsFile}}{{rowData.className}} +
      +
      +
      +
      + diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/drools/view-models/droolsSinglePage.html b/ecomp-sdk-app/src/main/webapp/app/fusionapp/drools/view-models/droolsSinglePage.html new file mode 100644 index 000000000..1d4f1bfd2 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusionapp/drools/view-models/droolsSinglePage.html @@ -0,0 +1,92 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      +
      +
      +
      +
      +
      + + diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/drools/view-models/droolsView.html b/ecomp-sdk-app/src/main/webapp/app/fusionapp/drools/view-models/droolsView.html new file mode 100644 index 000000000..dbe9121aa --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusionapp/drools/view-models/droolsView.html @@ -0,0 +1,61 @@ + + + diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/drools/view-models/dummy.txt b/ecomp-sdk-app/src/main/webapp/app/fusionapp/drools/view-models/dummy.txt new file mode 100644 index 000000000..e69de29bb diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/external/dummy.txt b/ecomp-sdk-app/src/main/webapp/app/fusionapp/external/dummy.txt new file mode 100644 index 000000000..e69de29bb diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/fonts/dummy.txt b/ecomp-sdk-app/src/main/webapp/app/fusionapp/fonts/dummy.txt new file mode 100644 index 000000000..e69de29bb diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/7450-icon.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/7450-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..52ab2b54c3fc7277c1686de3ffa379100462702b GIT binary patch literal 465 zcmV;?0WSWDP)nA3K5i6$_kWVe}vt?!LWQiPz z{K0HJS|%#()JEDoTN2~{Tr6-mBm-dYO7SbrC^^>;?hq6IDh z>S(neYL&zmu`4SCHd!TlA&8Z`7A~DGneEMWGh$@tbwx&2lME+J3o9%0&5|y=Tc$8sB7ZP@wMu#rX)OoyL@pi761~#H&2zp0*$I31TPo&r00000NkvXX Hu0mjfnX|^h literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/7450-text.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/7450-text.png new file mode 100644 index 0000000000000000000000000000000000000000..9b3c3325148e4b876953a48281deb0b21e73eed6 GIT binary patch literal 295 zcmeAS@N?(olHy`uVBq!ia0vp^Q$U!J8A$qnnlv3qu?6^qxc&!&(3-C~KoQ20AirP+ zhi5m^fSmK5E{-7;jBhU(`mrcVv_0$(2>9pzK;!?}Ii5N?-#Ow~^P8r=y^+{d!#6or ztZa?1PsQowHHNd#rv0}`ZS?+acQXEEz2?nrR1;U6 zZC3mjyTeIGM}lkRWMy4R>DPP-6kaJ7pibJ@YVw{G`uXW5^B##j9|r*V(E z^z_LyL)|~;b51Qc)I$ztaD0e0swz2hGPH# literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/7750-icon.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/7750-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..9ee5499a9b46f35fa26098851f626d52c0116d84 GIT binary patch literal 565 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZMW&u7SuK)l42Qq;qNg#MX`%|Dc z!IB`qUg`*e z{{NrT&k_}`EWM~x%=kJ>9nX}Eg%dtJlm7MP<>lr7m;ceYKl$+FiSrlw&$p`ui~0Yr z|Jlu>D(Ci3FZpKApGoaMq}Bv&5?;@`tmQ{e0#5kK9()ggW2ypCV6B z*@&E1?0jif|E|5QvUgw6%y4ZE4(dRzBgnH5rVHZG5gV zt?HBXnZ50__1`(cTp39(ybteLsn7dynO#)(B#B=;8bow!Vj4b`+37v#NP6-3YSzT| znn=IDLh_%I3+3v+zpr1;(0_k_n(=q@=RfaP|835+d%Zu+@b>>2i}(N4-q&A#@^}5R zUvK`K&cA%#{^svL=HLI^UUP1LRKw|?@xjl&+9wsg`+w$bedz6f)731${EzuP-{R=@ z|IwR*|KHyK|9$=ci81f%|GeKn&C&kjzp1croNxDcrsePd+`zav%=4Ukj_#YMXTNVx Q0LCJNr>mdKI;Vst0Q6iq*#H0l literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/7750-text.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/7750-text.png new file mode 100644 index 0000000000000000000000000000000000000000..aeb2dd002fa857bf4e0901fd52e290eeef36a4a2 GIT binary patch literal 632 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZMW&u7Su0Z-f>EL7Xu|Ghaf+azI z!3+Wp4EyINygy&i(0|`xeSpH_QoZdA42%yvT^vIy;@%u!-sq@SuAGRL}bsimH+?EvTeojo1)AgC+g%adAg*p_vyzUmH$u9 z=CkPFe;e3-uYdZ^`+tM=FWY?ziaJx4&#}#Kw(_IIyaV^8x1D`7=gavjRpYyP@j16& zat1Bkq2rO4b|{@I-fy}NpMTRl|L-i1=j2OW-BfOS)$X>Z>C4Ac&P#V5Uj29;->)cv z_n)t=|8hE^EOL&<^3|2PWFdJjlvb>X={x{wT|u#*}44czaM|f7i-mAIPRy__J8XZ zmfw!|=T$#C>dgGee{0I`bMX^-IwTHuygGQ)_1~`*`|Vz>Ucc`bcH%#;{I}`bq!MlZ Pg5uND)z4*}Q$iB}`({;g literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/apn-dns-icon.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/apn-dns-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..0ba5c5235ad4857ed999c596c47e0a2a52f63d89 GIT binary patch literal 1065 zcmb7@=`))N0LG)b)n!bugSKd_V@hYLj%Bx0Qmu?D%^D%C7-3{fv5T%F=@74Dcd@3F zj=VMx77oSC`Pcrq+lCk!#R>T-ojP)(9Y4`pD zU3T2|#j|uvHTHJbC99)|T*5kX@z0Q)>T&8FdY>XYJ$w)+mi<9HSGR#q^qo)1$;4QS zk*CDn{(<^!oLq2FGP?Bn5D0Y}s3N4AnQ?j6YLuolIy1Y`GpB7f3E%O$nPcX1Ge%yF zj+CoJr#N)xb|D;lL^h^UpehmweR$>4>$tloAp(#2Ykr7eT3ep* zH0{{v$(fPgFYg(NfcPFm5WZl!3I=1uS9gwoY9-4st1;XGEsb)uP>|HR$y`UopTwId z365j4@z|706Sxi}ajWZ9hij0Wc@S=qoteyyLt+%S>VWRU-<)eACRArlItG9|oB~qe zb3ZCoMbJzcE_#)3gQKnl^sg*1*ySWIQ4{f?f6iLGSig}T@~(3jT;qS|P!&f5mG6j& zKD)zlUBWT`V_q@{DCguUD$AS4v9CYyx(8P-+7}5m1_8A$sR}R24WT+mk@g0W#y5*( zkJm?K*~P(NfSQk$+$d(YyP8&;LC_?pw1kPXBJWVvX_HjX>}L|LWO`C&YRImJf3=A) zuLGR3k{y+%m$$4O|;PsbgP@vuVD+^dXv;Y3gLdy@EmC$GsyO-xc zu!Edf6SljDm3Q;Y37!M{2HN}e0!5ZJR2JDbAuDCQpTR+8fkrVZ-;>M+(_R&Pz5pv2 zwNf9Q=ka7d1w8D7DuF=sQRaJ~>XlvbnjQLvEL7Xu|Ghaf+azI z!3+)z{R#KyH|&3Z-XK6hV12jo8!>`|C@sy!W?Gxcy8yPydlm{!PkEG#@&Y!RsSsi^Uz-@sPB#1 zww9c(P>1IeA9S2dc6)f6>FwWWenY-Gs~5GEhVR}fUpu&c-mUg!YVtQ9syn~^-FCy^ z$1aUGYf{_in`~UqJx$Q^x5R;V&!_o2_bm*q{MNtv)rZ^#pFVz@INj)XzFqVEqM%=^ z4jE}bnm>QPS)0f6_NcqJSl*b&e|^2adzQ>hd1F;+<#c<#@B8`8HdinBo672I`REwng0i#Tlea3O7`tO+f?zW+WV2X z!9Bg_o#*+v{yQA}{d9tVjULAz;j``Kr?cdKCjLKr{J8D1^^5Bt6{pvK<^O#0rtrZh zE_$EjD?h8M?cVtNp!&)BXZrO&PsjiJG=2Y{r`5-1T$yihow;XYof1#-`7PHb1^!rh zUh{Y*$Kjg|NA9KfHy(30yY}1c%)awhNvsq5Pt@J>sas*QNb^r@eNr3uj)scw$*JYZ zS+X{*@!fJJU3~UCXXkgtT~Y82nses(JNGaD#N6ud7#jM&c$~2O`{kck-823&A8t8u z@P1%@k-YQWKT&+_^1Jg^^Hs_J&c9d_e}3l!{{Pw*$qT-p-Ei)D6~~Y5%*Idee~sSR zf9`qC>)lsZ*F_6R>&e?Qbkr38Ej*X{;QEgndIzh#?0df3@0-L~>bPgyiwpU+{|g=F zGS}NQSjE4oPe_wrYS^-G*Vps(j6U0H7Ew0Z0QU7P+qMG9IF^FQ}=nZ3FPpDc(3CT|8$S3j3^P65 zTd$w`$M|dY+DGy`gZEn>m#RCTf93jz^XZ@eKiJ>e-(SBpfBtGdd&$h`^pM}5`}h8k z`jh>O@!O;I??3&%ZIokqR(J$L>6e+Fm#jQd8L)=dnXd*3MR(d*CA$GmE4>*5c*w?B3q1ne*WuRM3? z&sXoIkFfyzKi=!#|M>v|=e}9od>S)9c<#9`Ru|ve?7uDZ?$eHwPvz!E&w2M@*TJ{{ z_Fb3$@bTl`TTjmF>2IrCe?Gfc_k7*z&Ho;tnQLDNRQ8`K@TE*sOZ?>rz|dvzboFyt I=akR{0BKp_ga7~l literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/atcf-text.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/atcf-text.png new file mode 100644 index 0000000000000000000000000000000000000000..1566d5be0a846d8da4a59f332c94fe92213116e3 GIT binary patch literal 650 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZMW&u7Su0Z-f>EL7Xu|GhaLM1_d z!3+ZX*E2XYB=o=kKVPB1;Qal7uDCD-1_s8Do-U3d6^w7MpDkLWAkg-(LAPG%#ozmH zR&GkpX8mAc^z>DAx#t!4jVD#?ITTw2oDf9*(l6H>E@fmz-U_~!DerV)a_Etx*FIk2 zH=V^iJ>z^!RMm1d`MzZ*w%@V%*EavV_TA6AuP4p_{YOPSsQizn2=A)n_IerlKd#C@ zmAgM*|8V44-937DNZD$vGqa|3?4q%s#Q12ejiqb9a_3NqhBirpFVYbdBh$(^npTF4q5T^&-1I zHRaDF{qT}c(He2TmbqB{^?X)0%{uc(QAytK=Vy51KR&Z&yBPoL*Pqhu`ut~wZBDT4 zdw$w``rftozf9h9KDqd)cx}1P{yhxWP5(a*{ImbP^UVDpo)>jieVfm__1ZN36Mt0e zSNw85J)QOR{g25j#Bcu->GEB*rS`?_w*07l8g>`sPAM)){})s<<0E(EExXL0vx~K* z{@wU@XS#8a<%I0p{dNU$(vOQCd=jpI)V?<7#KO0iqhuq$?p&W$eexvBwwkEg+yuL? zscS>u);In&i2K#+01y`>knvzopr02v2faR2}S literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/atgw-icon.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/atgw-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..2904d2770551ffc743b9e62859713385f74b6839 GIT binary patch literal 388 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_0wi;`T%Ezd!07Gi;uuoF`1Xz??_&djwm@eN z6=%&BhX}Pc5sk(V?{|Jm)n0pd<)?j$2J2sGZn~@DISGVbHa_*xw|2jke)-eQIXi>5 zTd$w`$M|dY+DGy`gZEn>m#RCTf93jz^XZ@eKiJ>e-(SBpfBtGdd&$h`^pM}5`}h8k z`jh>O@!O;I??3&%ZIokqR(J$L>6e+Fm#jQd8L)=dnXd*3MR(d*CA$GmE4>*5c*w?B3q1ne*WuRM3? z&sXoIkFfyzKi=!#|M>v|=e}9od>S)9c<#9`Ru|ve?7uDZ?$eHwPvz!E&w2M@*TJ{{ z_Fb3$@bTl`TTjmF>2IrCe?Gfc_k7*z&Ho;tnQLDNRQ8`K@TE*sOZ?>rz|dvzboFyt I=akR{0BKp_ga7~l literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/atgw-text.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/atgw-text.png new file mode 100644 index 0000000000000000000000000000000000000000..f7c50c602c842834c15008e3881a55b1a9d25219 GIT binary patch literal 780 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZMW&u7Su0Z-f>EL7Xu|Ghaf+azI z!3+it4EyIN2o#)eP*@-EzW@H82Di@)3``}SE{-7;ac>S7G6IzzQuw`m+cCZfZXg>7 z=3F+4o+jMZnDM6Kxb*-3n@_HIE4UzFm9%ZI#w~ZJUWw$jfB)|P`1(H6ch3FBk6ld#GHV{4JhkJ7udUj56zvg>&g>-@7v()gY& zvg6l!74xw2Pu$bPTPB{9eE+A%hs|H_!k!CXg5krV?cv6rwfFMlExsA@)~@`s^OxCyy&opuCl{d4v|T^TG7 zT8!F`weN`P>g-(kPx@W{le6p_n0K6B9Uwh*{?VZ6HF3+{KAe3hU4sAPr9jcxzyIWy zcQ}8joc)8{{$p>VQv7?yoVB0YpYWf2ZY%%Z>-18KdHl6rE7YdmSKaSz$G?E0%L!3(ec__|SfZiJ;@#MP-rABx@L`eH0+YiZVG zzB<4+<Y#d)@D(=6xW=`a;pD7{@?vu zEl$~PWuVo+E%EJU3>*ApigX literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/bgcf-icon.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/bgcf-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..2904d2770551ffc743b9e62859713385f74b6839 GIT binary patch literal 388 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_0wi;`T%Ezd!07Gi;uuoF`1Xz??_&djwm@eN z6=%&BhX}Pc5sk(V?{|Jm)n0pd<)?j$2J2sGZn~@DISGVbHa_*xw|2jke)-eQIXi>5 zTd$w`$M|dY+DGy`gZEn>m#RCTf93jz^XZ@eKiJ>e-(SBpfBtGdd&$h`^pM}5`}h8k z`jh>O@!O;I??3&%ZIokqR(J$L>6e+Fm#jQd8L)=dnXd*3MR(d*CA$GmE4>*5c*w?B3q1ne*WuRM3? z&sXoIkFfyzKi=!#|M>v|=e}9od>S)9c<#9`Ru|ve?7uDZ?$eHwPvz!E&w2M@*TJ{{ z_Fb3$@bTl`TTjmF>2IrCe?Gfc_k7*z&Ho;tnQLDNRQ8`K@TE*sOZ?>rz|dvzboFyt I=akR{0BKp_ga7~l literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/bgcf-text.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/bgcf-text.png new file mode 100644 index 0000000000000000000000000000000000000000..b1e0869eca40dd406454f224177ddc7bbfd6583b GIT binary patch literal 645 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZMW&u7Su0Z-f>EL7Xu|GhaLM1_d z!3+it3Je7e0_XqVpTB;8LjU`K#AUOeF)%Q`@pN$vsbGA2?QYm>1%b9i#lzuvjMo^o)>UOvTR{6D0D#=*gYFPRJ1Z`pV)%YCtHbawBu_#X@2Yn=D( z*wwvWCurI3H<2g!KRo#Vdsg*o<%e>m6GcL`KAe5F?AuN2lhyC0?BzReyMNEU?=J&> zOqTqtbn1%@m;U$3GFtcbwjIBarnt!V?l)DNSvLiDo-YoV@}+m5&GqRwUu-D(-cWhVe${@RY3I4WZ-2m2nY+jM`&O;Vh`aysVEjyvcnwRXy^*zt*{gH^`zhb7 zGvE3CtLE|7^ImWJYkRug>HfFHYwNDQcP&qi=!;lown*i+>4STp|4zw#vwYi+Yx_7} zo&R0*|NGhx3oVpB2iMQN`+oj@1^$M8vM+M@C-P_SH~c)`{?sS-10OZ{@29=~y!_tP z>!mjOpTlR+z2nT(g4ddI$yNGbaq;i3N3=YM9@YeS3u_QJnjEbh0%LD=87 Y@0q&NrX$?+7$^=sUHx3vIVCg!0Bo#YB>(^b literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/com-icon.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/com-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..59463a91779bfb5f18ff47a0f8e86d4963902df1 GIT binary patch literal 437 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZM#sNMdu0Z-fiD3KGM@>L&f+azI z!3+)W|1%gk>_6Wxkg$G!!2N<($Gs zb|yP)Du~T}Zm(Rc-ftEZ$D!CF;FKYzG*`3j%hvE;VatkBTjTkDvD(%Ah??KLtm+iM z=k?NK{hrY_k2c?WzWm3Bhlktw?XRC*zHhDmM6P|r|({$dr^|3H6WKr(o``njxgN@xNA+^XKg7@r+fJHTJ~jd@3djmv|>A4Gnz zf3n$hKz@RQttZp}4O~1{)BARbOt~YO`R>yHEgZoL?sC2l80~j4SnIOEL7Xu|Ghaf+azI z!3+ux0t^Z3@6R{r-~ax6K|q7t-CvU#7#Np$x;TbZFuuKdv2TfjKl`rBWkzPM*zu@`eT>s~dlZO_*C2llM+m|U57;XY5L>OptagZh&f{pFMwv--fJ z`>0Mk-rVjT`)dbY#VchCVt4IlU!V3_tH%1{bpIcc^Iu*)R&Jl2|Bm~|v@4U1-aHnN zzNXoI=)Lbg4e@&Moa`I%XNC8&?Y|!TqjtAc?v3Ld>woQy|JCBh+O2qh&*y9QH5>m| zZ#N4sx?L{!xv=@p&!+l`l~#`*bo2avcr4y8U$1rcGYtOzuV@wfeqWcFavx9o-?vYXcE2R|$82k${KwxW_s`llt&hsRmi{LrE=1%h zcYJu|iRn%Ezh8T{x$OPoLixpEtF|20x8q&^Yg4rT^PIiEmi6;4&{_XWYjdpD@>kw= zTsICDb?tk(SfKE#jr5=LMgH^cYJYusd3iZHWB&#DR)Jlj*&>tY10$2c)78&qol`;+ E0FtCHoB#j- literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/default-icon.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/default-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..296a6f5c22c4e67a21280a8b92690ce63a86e9d4 GIT binary patch literal 329 zcmeAS@N?(olHy`uVBq!ia0vp^^+4Rg!3-pSemT+rqznRlLR^7#BV#QPeZ2A!gsy#j z^Xm%`z5Mh6h@QQE3q+5eygV}Z#I<9$Uw;1B!hO#is7IhA$S;`TKM3+Lh%iVoC}lVZ zX$gFp50u;C>EaktaqI1^-F!_33~d*coLZ|Y|8L*wCYGq6Hbuxb{u94XdbXt0l2fKj zt=5Wv`te6;>)Xn;6OKRMpS`{J{Qpz$`5wNnly9-In}6PZUi?23zREw!zwefP-JH~; znE$T6uH1K}-eH55JyHK=1aVc?0F^!e{1cV>6aV%1kF5OvRkL?p|1kX{SoZ$S_&@w# yTK{hS0aE+l-Tve2U;P^cF8_XB1yoRXbY86N#?6Hy$L<6Dz~JfX=d#Wzp$P!f)2eI$ literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/dra-epc-icon.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/dra-epc-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..74bfcfcec12c94c1d58181b42ffe2c4297d890ec GIT binary patch literal 700 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZMW&u7Su0Z-f>EL7Xu|GhaLM1_d z!3+)s4fFT+Com}d7g&GZ;Qsr7HMQSM7#Nt8JzX3_Dj45hzu5O!fv4@FRm%}WPQ~~C zH?6+txAx}0mOl4+v#0L&j`|wlqEz9c?;0qAj4n=jHs|xCut)R1KbXJ8H*(*!Db{pU`_(^u*&UB|ldB zYd&@Um-+R>)almybeBB7e&>uZgM7t@_4>b}eq^hfUR-t8UGDGN-fxvNpGIn@$ya_U z-5~fqsKMzgL?O~QXQC)JQ_G#>`H~ZA}SKs~qBz4>GNSV`V^N*Nrj{jD3{o|dh zKWp3X)=$^-HLRH)Q+v4nmwfHvU)STm=>FE{-_>K+o!@>ne_!3EUpJ@Dzxhf%{@$DL z@O$q*zdUvO@0YWm!>hH(Iv?usic&;6P1J<0xDe(t`gyaAJ3&21)`r~jD|eq?o$>tFubY~; zj=oUN|6VERdoJ_x$6a%_tJgE#dvVx##azqUDYsuday(`I!)E4t+a-J2&xcFD`cbCz zG`8m6r-u97&HQ^Vwyz8RHTTF3wmmo7uQ_knQ)I66?c3MR%Y92XsqW^_4WISdy?7T_ lHs8MNhwbupKhTJJ2Iuw|JwB~Z{lLV;;OXk;vd$@?2>_N=ff)b* literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/dra-epc-text.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/dra-epc-text.png new file mode 100644 index 0000000000000000000000000000000000000000..00f2a2e45e571fb29122d8c61fecb46ddf3416e1 GIT binary patch literal 820 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZMW&u7Su0Z-f>EL7Xu|GhaLM1_d z!3+)a_uv1&-he^jeZN40LqNg#^Rv`0GcYjC_H=O!sbG9N^KRKv1s*qU$2z42`~IIk zH?fX2)#^Fdn>91vXrCxt>uWkA!JfrY0ET|N51iF;=2O#}qJP~BUa(HLP>hRwsgm?< z9{>M&Pun~>p6l)V=@!BDJHmd!jh~L6L|aXHzcnkD)lK*-zRb<-=l4Z1JAGFC{G2Y6 zxIx!}|MO%0PWPF)SL=dlF2FlA9Gfnd;f|hxp&Tm=D#~Ge|y&7sjpYtCmVLEuxtK< z{STwsX6>5rWy<_SujeUi`5(=w{;w^vZvXCWns=}KSzWN_4gX|ru}H&9@9XZ@UsNdB zq$ex0e1H8n?~TUZ{!%Z?@9(Ww)^k*RVZrvxxIVhxq)14AFQ55={m;c;IjsAA?)^SF zuLGa*Qa%0O*sq(N=c-n4ouhEh)%wu-rsD~+wOeOhtG{=TOY^a%35TS`k$ewDerx-@ zEf-JpxjB8?_x-&4pGV^Re;n1X``GJc#S+h#^F6P<vHXR8%30NOWztXn zKl4_;(-8XQKy1C`of>4o$0Cg^jdpPj^wVu ze{ZBeXs7Hx$P&+<d3YCIj1N8>%04ZMf~q)^*aBxk6&y0W@*3DN%yPR@AnV? z#@`I&s5>Q}rNuCP{ukw2S#^&ZzowrT{jOf`c9uWY>4kUOclj&7wWY#kTzd9B3A7ix zVDK)`K59Z&-#EL7Xu|GhaLM1_d z!3+)s4fFT+Com}d7g&GZ;Qsr7HMQSM7#Nt8JzX3_Dj45hzu5O!fv4@FRm%}WPQ~~C zH?6+txAx}0mOl4+v#0L&j`|wlqEz9c?;0qAj4n=jHs|xCut)R1KbXJ8H*(*!Db{pU`_(^u*&UB|ldB zYd&@Um-+R>)almybeBB7e&>uZgM7t@_4>b}eq^hfUR-t8UGDGN-fxvNpGIn@$ya_U z-5~fqsKMzgL?O~QXQC)JQ_G#>`H~ZA}SKs~qBz4>GNSV`V^N*Nrj{jD3{o|dh zKWp3X)=$^-HLRH)Q+v4nmwfHvU)STm=>FE{-_>K+o!@>ne_!3EUpJ@Dzxhf%{@$DL z@O$q*zdUvO@0YWm!>hH(Iv?usic&;6P1J<0xDe(t`gyaAJ3&21)`r~jD|eq?o$>tFubY~; zj=oUN|6VERdoJ_x$6a%_tJgE#dvVx##azqUDYsuday(`I!)E4t+a-J2&xcFD`cbCz zG`8m6r-u97&HQ^Vwyz8RHTTF3wmmo7uQ_knQ)I66?c3MR%Y92XsqW^_4WISdy?7T_ lHs8MNhwbupKhTJJ2Iuw|JwB~Z{lLV;;OXk;vd$@?2>_N=ff)b* literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/dra-ims-text.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/dra-ims-text.png new file mode 100644 index 0000000000000000000000000000000000000000..1d54d9aa9e412850ae9f5428b42161b07ea49cc5 GIT binary patch literal 851 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZMW&u7Su0Z-f>EL7Xu|Ghaf+azI z!3+ux3A`?mc5e_n2Tan|x#Z_XZwne!p;&8)U3j!hZIe;R-AdGIU!C-Z(b z@kuT*cU6@$m#n+FW1iKIl*!x$HaBy`I^JCWXLnR#pKl$z&|aacpB2Y^4%olqGzmIA zx8{87w?$%K8!wCLX+KzZRO@byUs~zjp8^uW*~^XpsDJ(H`0mQDfYb?nt6Iww((MhU z-`Pp+-z)ZVf$_Ta@iSuI|4UkN=0of=IN-p{#7hTb75{g2B3NIm$QXme)Ui?`{IS1;eK|1vt`^{dG@>noN`+Id>2lBIpQ z(C?pz%s!TSmK8hASkhOQwoT%`UG0w#8@tzwq#D?{?Da1A()0Ss^tl!fpB3+H%G=o? zH1F28jq|@7ub6Ljt=!5zp&->^`R9fClOMiw-uLRP&JG{l(l6x|zy1aBTk@QlExG&W zP0369ramdV{n-0L?T5d$s_)}YH+nBJu_=C0@B6Uu_4|K6{+$2!Wx4&|m;Uv?F3;ch z{a)$!@|R2gEMBbfb*<h&>af%)#4(+n=PFX>w!^h zXW{~Vc7Nutma4MXxu#64i+qwP9KXEbh$nOHzNoHWYV)?c%e^Q*+x*L{v%UALV&m7n zmD>H^5B}0SmSX3%?foxy!J}uz8RqZ2w(phsuBC^EL7Xu|GhaLM1_d z!3+Wh3=R9=|G&S!;Cw>Bd6DgSn~-tu|#gYwIJb}X-r zQoC~0#s8OQfzPF6JJuSl3|Yy9Tyz5i*h^p8!?OPSm3IM>ZOabter-JI9!e*~{y zX}?f!dGFm>f##9FI75pc&d+eWn)Ranl&AXdS#SRoJ=w}Cb>fWwb9c!FYt!o5!uY)T zW|@CJeAKmXm)MybnX!p8AeJl4su9(-|%Yg#)}Ow~x4GATv9_jJom)Kj>>qn;(zxd{{pu_Eu|OQ z+iSM_|90%`+^@};D|{VDSz*AWcuJo{&9>aEX@-u&UnwU7OnW;eJ0EMJtt=k49ya~970 zDJK=%^ZV#M{_yK*)rX(|zoXy(YeDz)-lx6)_e)ZvK9Ar04yI z(mQ#lzyFkeFTZT6Y4&{YY0d9C-EL7Xu|Ghaf+azI z!3+)!`|tNB2r#TaZ!llseL%qhFW(;w3{2jhE{-7;ac>SV@&c6}Quw`m+i`YoCLo)E zp`kcx88=^(15eyJ$91QE?|&1fbb8^UcYk~q$8#N4c>E~(Wpt2+?=sCx-G5(|J>+Y; zx8@X2XuZ&yzz4P!cl7?eQSy)dnc(#?B6a1;ildtGX}2$FL|*89u<6jVKO(1+KEG#7GB>uHI%QLqv(hxR zKa+yeyYC(ckm`1I)3fc1ZSBa(=Pb-|LAymJZ@!`J~DOQ2hnSlcNwye_urV@u>J1mk9}84zAQSdYp-OiSbaL) zczRKC^~Z+u-{v`{Oo_=nb$w=t+03mq9)|3Tm)FdglhY-InD zUwV7LYD=q@o4(3)R`YZH|35Fbd%H@)@8^e`A5DIJ|MT(pbvc<>jfBDtL87vGuOpI&Z->84&rPFp;g?q{WPL-{XuBz^@ jZ@&Nj`|rPX`;jR7SR)r{{q@Y7KxxO*)z4*}Q$iB}&n$=h literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/eatf-icon.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/eatf-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..59463a91779bfb5f18ff47a0f8e86d4963902df1 GIT binary patch literal 437 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZM#sNMdu0Z-fiD3KGM@>L&f+azI z!3+)W|1%gk>_6Wxkg$G!!2N<($Gs zb|yP)Du~T}Zm(Rc-ftEZ$D!CF;FKYzG*`3j%hvE;VatkBTjTkDvD(%Ah??KLtm+iM z=k?NK{hrY_k2c?WzWm3Bhlktw?XRC*zHhDmM6P|r|({$dr^|3H6WKr(o``njxgN@xNA+^XL&0wqCy z!3_Hw9264P8@!({a6jODe}SF!e|H83MrBVI$B>G+x7Tjx9WoGLxcIdptnmO)zAIEW@dz+_4nSrpVxnRD!6`b_px=Kg7t2tt-5z@ zf7bEin;H-Q-c|eidu)#Ui~L!ZDW{ef6#c*WD>iTT_UG51|2-=D+WYUSn|6YhMei#2 z7rlQKJ=baHM2kK0rBUzMH}byQy{k-dzwK82xvK7SZcX}>{%-!3YgaZo&;LImsxYJ8 ze{OCHuJ~kUw`MFwURk2uV}qSep1xz<%WGPrysghn=O6i`(ORY hD_xbBe?mvv4FO#pa%=3xK; literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/ecscf-icon.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/ecscf-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..dafbe9e0a17dbbe9a16debf0023eb9916cb1d63b GIT binary patch literal 855 zcmb7??@v;D0LDpEl&mTUZp3mpi^X}1z1P5YR z2`mPK5yL;2TM#n*y;0#I`XqC|g|thQU&IR;{Cs>8I~iK8swxl^GPaAVQ6!t81;r+B za@?OzS6o?V8G{jK<>&4#k}aEiGhu8^j*ED|CAp?1NT>DkSI=NwBl&_8?AL?MNV$h8 z7BMfz*V@iJIKDN$mgn4&Ipd8U+E%E@=nn3metFL!>n7`v?u8BVMmbS3uF;uIZLLtw z^VKYDDQoJc9?N6oTV!`BEFTtB3IsyGwVv)3Yl(h+w{WV=;(eHYJ$ zo-5Uum7kcW#f9W?P8KU`J_DrK?in=oT;Bkjs&nI)ydT2R%2R=>k--3U<+kGSIsN-# z1?5pk5tXf}BG*EAqP-nTyzmF6uPV7#Exh?L7)BTfwmYjSI{YJ!A*3Xr!%LH|1{Pij zA0PJ88?>qMe>bzsg4HzpKUaO%n%S_q9>j)azLdJ7`#VuzhnDapb>3CAHB4Ho;*Y@A zm4@~-sU(uRAy|jy=_@0s{hZim+y=)wGproTM*h`#(tPQ)o{?%B$^W&dM>x{Id@-X* zA%bqzoPDy%F=73Z*XUiZJ*J$E8Vk(wioj9J;&c;NMQRaXcY;YTEWtn!7h-_SpcgAh zydp3Imb87~7Z`Mmzk`_;pl18E9a3u^wa)~0&&k_}Y-+_<-_qJsU}KUIO!$Rkv4tlQ(W^6ZyWS3 literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/ecscf-text.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/ecscf-text.png new file mode 100644 index 0000000000000000000000000000000000000000..ca98a51d2a619445c58c0d8b7ce3d711e0fdfd50 GIT binary patch literal 604 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZMW&u7Su0Z-f>EL7Xu|GhaLM1_d z!3+lb83Ov>|G&S!K*3?YK*RY2(Y*}q3=E8iJzX3_Dj45hxj1Q#fD=|l?$c+NZx>!k)syInuaow*&RUb0cJ%*>_#e9sw$=osUzOnd5*l~fMOr(FXa0BZeG|783EyHb zHQk~)@$oV>rI}pChV8%Jy*X2-+RS2?SpggC$DSi zb93&rPI|L&-|hY{rjb9yzWu-R{M_p7tua5Qwg28%wrjopYPD+4ny$n5_XjQieWiYW zV*ecr+b!?@Io|)As5W^{^QyMRe{a3L9xUBrrSA6ValxOzo@?%H)y#Rm*L#=$j}20X zKiZwWQ{m3OeUGrv@A_&lY56&ZHP@~iX$t)m*~?!OwX$fl?$)ZjMW!+@%k?$|Etxtc zhll;wvFPK4S?Z=ArcYS=&>_CC_{rr>ms9nxPmDh*XZOILg1da} fmy6hmzwzJMw~Dl?7<>}-1I3M}tDnm{r-UW|@(@B& literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/emsc-icon.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/emsc-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..2904d2770551ffc743b9e62859713385f74b6839 GIT binary patch literal 388 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_0wi;`T%Ezd!07Gi;uuoF`1Xz??_&djwm@eN z6=%&BhX}Pc5sk(V?{|Jm)n0pd<)?j$2J2sGZn~@DISGVbHa_*xw|2jke)-eQIXi>5 zTd$w`$M|dY+DGy`gZEn>m#RCTf93jz^XZ@eKiJ>e-(SBpfBtGdd&$h`^pM}5`}h8k z`jh>O@!O;I??3&%ZIokqR(J$L>6e+Fm#jQd8L)=dnXd*3MR(d*CA$GmE4>*5c*w?B3q1ne*WuRM3? z&sXoIkFfyzKi=!#|M>v|=e}9od>S)9c<#9`Ru|ve?7uDZ?$eHwPvz!E&w2M@*TJ{{ z_Fb3$@bTl`TTjmF>2IrCe?Gfc_k7*z&Ho;tnQLDNRQ8`K@TE*sOZ?>rz|dvzboFyt I=akR{0BKp_ga7~l literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/enb-icon.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/enb-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..e03be510de2ca17e373aa3d7ecd1e08e0fd48ad3 GIT binary patch literal 1127 zcmb7@`#0MM0L9}G)Z+wI^<3h#oqFtqO1(~ZB1TaaiqTH16m4ys*{WV4-;^Mv8jV+v zSfVR6q8@cdYvemQ-lbVfF(zpnk0_CnkorcFS^tCGbMO89bbq`hVfX+eeJgz!3}zG* z=ofxK;J@f;9rRX$*zN%CVdo?L52*hC+DaJSKUkWkhvOq)C?6MCoEl7%kc|*^V6`F7=Lqaayb$v2O2z?KEh%p9i{gcq@ zyUzkjJ6{5{u3@B9h&TlMRb8!zx-5&}J>;*`wpFy8uF3MF{Bq|dKSYs zONpaI{d5HXb?laP>)pE1`kmVO>zt?B@p#4Bn2o_PD#75^;{FfB6D#@H{^-sNV;EGj z)d<}uMKRr%c`u#+;~oTe!UbT<+AE96?z0+Bg&H09O2g%e@0j0Sz%Z!IH-&DuCMPBa zgMeHfHqFP}B5AOpTa%pJb$8qWJH;c>azd(88_E~JQn@p!f{4eq6jo-;RK10}HE^r}5=z$?$_aHmgHO0ocpO(&D#vdI5w|BCsU_9fwI)y=qmx z>r5WglHH|{phuih71+lh_RgPtNi-vEAF*#~w2}e(2R~m#K6LR=*kXi}D$Njjj8cbe z*aO`#rb}eO&=hBJ17r9N&W!2pccNrlu0p@CYQ-^`S*vY9p(#0FZOfcATFu$h-tf(f zL*On}#!@=wwmWh8vT!n7^aN=w(jvgP*JRho{x!g<0&Vf7Zd*I&KnZku*_s3ifB;p9 zp=sBRcFf6m)+`e`V z$gw@>dgNb(d9Y{`pNAD8k2(9bXWB`cUa+h-%j7Y;o<5#p-I%^a>vA~)n?Q8W1_vxi z9mf4C-RdR<11maAE?i5}GkCqOyQHI}#Oi8`SNj&v>ha|~Llg5yM^P!zM%D7wMh;J` zp+}vf8b|f*!#69}D*QFbRZ|B1#sXs6QdM3HyaSdc&7ugy0u|6k31VNw79 literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/enb-text.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/enb-text.png new file mode 100644 index 0000000000000000000000000000000000000000..9fbf8c298b26cbeb3134ba77feef6d10102869d9 GIT binary patch literal 627 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZMW&u7Su0Z-f>EL7Xu|GhaLM1_d z!3+it3Jm|>C+t6ee|>>KLw~^hxl0$cGB7aS@^oAq69B+etF_Ens}l&P_#f}uQzVvB$if>^Jb;>UZ|u5J6`IbrS7HS#52XH1u0{-MMF z+nxRrjaK!VF5daY4>{+j9De>rc^}{OecLqaQf;Rm5w^RjJ-^>)*6~%B!;Ow<9PacF zzAP{FzWnF0z>{a)=et~xU^nRY`UX_Uksjf6{dFmv4&JHIce;+iLWWsqlL}mH$-q;?wl3 zslro&dvZgvet1j#`eRh`b=}S6Y1f`r&oAMMt+SonCHDQF8S9mu=XYLs=xvpmGT*;2 z{ImUuR{h_?_cxuF(iOMUSA4`dfBAvd^XW&v*E(9}uD-+{|8kmqCBv`h^2h5k>&|YM z-M2XAuzb*A`Q3kCK0mSY)cvCE`xb1y@^JMp#pG>PbAEco|2C?VH_889Q~uKMSjK1R zqo?lA%Koo&_xtbnEBxB$o?p7m{`=2^L33~Zp0oS=)|Ykv%;xO~cmL0~ ze7f*^nPHa3(XCZ$do1rgO4+ySp}lm?j}H$IxAV)}p)>yP|2hBd!ey3g)%NND(*T2~ LtDnm{r-UW|%ehT^ literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/enum-icon.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/enum-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..daee75ac845c72c81c4077652946c2ec71c151b1 GIT binary patch literal 646 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZMW&u7Su0Z-f>EL7Xu|GhaLM1_d z!3+)s4gLG?|7Q@G|K1=#Az}UbMCR643=E8KJzX3_Dj471I-3`x$kX;v;VNz8FRL?R!sGB% zj^Lng-IE2vxgK>*i?6?J&ARe=-9(x1r-S-xoNRcvyft^}z3}bNyv2Sy-~X_Eb@lpR zDbv-b>jJ(WUKPJ6FZH5&>ioQ4&z^64p`P(+aqb-ZU~l%fbN{PwRZQDt|365+y~6gM z{i^xZ7BjYd(|=?*J)>~R-uivhPsx4emN;`|%J=*3y&XT4ANI>!EPj3W`}g3_!Iwig zUO!(yVOreA@_+u<&wYG$_~4(J>*hRo^8DkU(}yokJFC3n>ajoazugZk{-gX&|MOY%`!%1tSIxWo>0ji66{50u6-B(D>U78 zzLS4d)jiAl%_6*ePyPETZ!`DN&w_tXHdeE$v|ant{CG$hn>i!pf|9k%KcmMGF z^|AH;zcJtYZ@cT$zd(D42l7+){d_h%|DS$NP3L((6-H-ZvS9FZ^>bP0l+XkK#JF+s literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/enum-text.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/enum-text.png new file mode 100644 index 0000000000000000000000000000000000000000..f04e3d5c5e95c6eecb935773f308fed2e7b8d5f3 GIT binary patch literal 551 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZMW&u7Su0Z-f>EL7Xu|GhaLM1_d z!3+lb8Tu0h);s(^-!MNw;eEk<&3Rf$3=E8Yo-U3d6^w7MKFnLAAaL|!YQGY*)~|p1 zxBYf0AE|5Pt)6{n&j0qVS!eazIBN}#NhJ3eB8YGC&*yDt@Tn@@vFZ7{^u)7O<~I*5 zJf*)re7oEZ@h8)&s(R(7+43(s=vDQ7i|ZE+-EXgIUUp* zSN^Dc|9SKF%87CEVSlSTYxn7VtC^r5JYRpaU769D=@;JJ?)zzR?EJQ+y>)eOZ={&N zKYRbF{5Rg-ehF^$zdkAReAw9WEb6Zj8+Y4}e^*|=jIMRD zW8v-+obEzV_Fb imzS6O&$mNk{Aac2>bmS2%2EW3HwI5vKbLh*2~7YayC+Ei literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/esmlc-icon.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/esmlc-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..2904d2770551ffc743b9e62859713385f74b6839 GIT binary patch literal 388 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_0wi;`T%Ezd!07Gi;uuoF`1Xz??_&djwm@eN z6=%&BhX}Pc5sk(V?{|Jm)n0pd<)?j$2J2sGZn~@DISGVbHa_*xw|2jke)-eQIXi>5 zTd$w`$M|dY+DGy`gZEn>m#RCTf93jz^XZ@eKiJ>e-(SBpfBtGdd&$h`^pM}5`}h8k z`jh>O@!O;I??3&%ZIokqR(J$L>6e+Fm#jQd8L)=dnXd*3MR(d*CA$GmE4>*5c*w?B3q1ne*WuRM3? z&sXoIkFfyzKi=!#|M>v|=e}9od>S)9c<#9`Ru|ve?7uDZ?$eHwPvz!E&w2M@*TJ{{ z_Fb3$@bTl`TTjmF>2IrCe?Gfc_k7*z&Ho;tnQLDNRQ8`K@TE*sOZ?>rz|dvzboFyt I=akR{0BKp_ga7~l literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/esmlc-text.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/esmlc-text.png new file mode 100644 index 0000000000000000000000000000000000000000..0a29e736f2410bd5f0312fe20dbfc518322d09a6 GIT binary patch literal 701 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZMW&u7Su0Z-f>EL7Xu|GhaLM1_d z!3+Wp3aUZOeAM5= zAH;2#y6$F`$$s6q^BuKXpCoR&#ZXh{{@g z`0G%y>plNJh7vv?tkoGc6ItzxwA#D(pOHsd-cfon!Q%CKayq?TYR5v zr}g&Kb+MIGe;&>kZnXH;%zXd#WUFtF%WDeOH<$m+J!7_G$+7dt|GnPA9sgMIR>`^< zd;J}&j>-HE+U#H3+m$i#%60McpW?qRzVgLLxU@?7>&@@EKa%b1%zv$&v&}A~%x>?! zgEg<(t?ja#@1M?`7#22v`990DM}Ldgzk2Og_G){4D}U|X`iGtSkIhS7tDpMa?zn^a zzR9<0?#thb&9wiU^W%`ZWLr$tqw||)ZeQOMS$j6--~Wm_*L`}1zru{?&zJW$I%DF# z^5Rzcr2MP@@1GU?oZ>upK3lx>{hgt0Vf(&qU6FraU(s!U$9uP4>^z_MZK1hfy;Bq^t!N91hfy;Bq^t!N95 zTd$w`$M|dY+DGy`gZEn>m#RCTf93jz^XZ@eKiJ>e-(SBpfBtGdd&$h`^pM}5`}h8k z`jh>O@!O;I??3&%ZIokqR(J$L>6e+Fm#jQd8L)=dnXd*3MR(d*CA$GmE4>*5c*w?B3q1ne*WuRM3? z&sXoIkFfyzKi=!#|M>v|=e}9od>S)9c<#9`Ru|ve?7uDZ?$eHwPvz!E&w2M@*TJ{{ z_Fb3$@bTl`TTjmF>2IrCe?Gfc_k7*z&Ho;tnQLDNRQ8`K@TE*sOZ?>rz|dvzboFyt I=akR{0BKp_ga7~l literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/gmlc-text.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/gmlc-text.png new file mode 100644 index 0000000000000000000000000000000000000000..43cf74d9bd1a09c5dc7fc4f98c378f733f650de1 GIT binary patch literal 755 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZMW&u7Su0Z-f>EL7Xu|Ghaf+azI z!3+ux1`Pe@6ZQwJzu)j)pkV%vlMh1~7?`3xT^vIyZoR#JchX`7fwqT?Q4WGz-v3YA z&Nlh4K*UnBYi|yItDd5GO1R#Azl!H1RP@U~C`!7@;_lqf-LKB1Sf;D@20q^(T#|Qg zapf(|`jXn)x({ua@BFs)xzg&FS5Muqv|5@Zca~fB^;+B7-k2w6TkQ+4PV$;>?sRj{ z_o+`;eeM5u&NpnTowSoQ{|~jI$^IX-_nn6%=f>H<(Pq+A?!}ZO*@# zbDaO)-2VPWBk=X-rn#lhwbwLS@|M-#j`tfJ^nY0VJ~OpGr^IJ{Yx0hd z-;)h@eO5Gx{rURSuDZt?*Z*nlceH=K&y_cFN{n+Wzzwf9~*Sw0^y3-@2Njz=QI8{x81r^*+n%XFmepPF`j> zKgW7`^7ZfczncZm74m+4dByu3vy6Rztp1c~ZLg#9W;ClIW3RdTb@J0?GweQ{ER4QVJO9$T(1RD!?OxufS-9fUMVTEr zUSC%FXLiMiJbV4!esBAC7U{YbulL>aefm58Zp+=S@B3qgo8nWqT$ i_4ob2LHzUo!fmARaQ5OC6?1@TkipZ{&t;ucLK6TQbf($> literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/hlr-icon.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/hlr-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..daee75ac845c72c81c4077652946c2ec71c151b1 GIT binary patch literal 646 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZMW&u7Su0Z-f>EL7Xu|GhaLM1_d z!3+)s4gLG?|7Q@G|K1=#Az}UbMCR643=E8KJzX3_Dj471I-3`x$kX;v;VNz8FRL?R!sGB% zj^Lng-IE2vxgK>*i?6?J&ARe=-9(x1r-S-xoNRcvyft^}z3}bNyv2Sy-~X_Eb@lpR zDbv-b>jJ(WUKPJ6FZH5&>ioQ4&z^64p`P(+aqb-ZU~l%fbN{PwRZQDt|365+y~6gM z{i^xZ7BjYd(|=?*J)>~R-uivhPsx4emN;`|%J=*3y&XT4ANI>!EPj3W`}g3_!Iwig zUO!(yVOreA@_+u<&wYG$_~4(J>*hRo^8DkU(}yokJFC3n>ajoazugZk{-gX&|MOY%`!%1tSIxWo>0ji66{50u6-B(D>U78 zzLS4d)jiAl%_6*ePyPETZ!`DN&w_tXHdeE$v|ant{CG$hn>i!pf|9k%KcmMGF z^|AH;zcJtYZ@cT$zd(D42l7+){d_h%|DS$NP3L((6-H-ZvS9FZ^>bP0l+XkK#JF+s literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/hlr-text.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/hlr-text.png new file mode 100644 index 0000000000000000000000000000000000000000..b2762502b069ca30cb4087e49d8c1ff377c42b55 GIT binary patch literal 376 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZM#sNMdu0Z-fiD3KGM@>L&0wqCy z!3+%!``_PBP!I?xn7_W?;Jk;@FK(dR6Hgb%kczmsSI>4GHsE1My!p}pj>_75|1-ti z6Q=#zG9{{g?t78MiH!~$*02DTgMol^c*=^0W^;Krwie_*<5+siy{T+APhkG#n+x(k zC6~XR{pZWu?5bbiO!eQ}CtY8ck{o%rKPl_lyDzW2FY8%fh_%E>nA}{d=>bP0l+XkKn6$yz literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/hss-epc-icon.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/hss-epc-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..daee75ac845c72c81c4077652946c2ec71c151b1 GIT binary patch literal 646 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZMW&u7Su0Z-f>EL7Xu|GhaLM1_d z!3+)s4gLG?|7Q@G|K1=#Az}UbMCR643=E8KJzX3_Dj471I-3`x$kX;v;VNz8FRL?R!sGB% zj^Lng-IE2vxgK>*i?6?J&ARe=-9(x1r-S-xoNRcvyft^}z3}bNyv2Sy-~X_Eb@lpR zDbv-b>jJ(WUKPJ6FZH5&>ioQ4&z^64p`P(+aqb-ZU~l%fbN{PwRZQDt|365+y~6gM z{i^xZ7BjYd(|=?*J)>~R-uivhPsx4emN;`|%J=*3y&XT4ANI>!EPj3W`}g3_!Iwig zUO!(yVOreA@_+u<&wYG$_~4(J>*hRo^8DkU(}yokJFC3n>ajoazugZk{-gX&|MOY%`!%1tSIxWo>0ji66{50u6-B(D>U78 zzLS4d)jiAl%_6*ePyPETZ!`DN&w_tXHdeE$v|ant{CG$hn>i!pf|9k%KcmMGF z^|AH;zcJtYZ@cT$zd(D42l7+){d_h%|DS$NP3L((6-H-ZvS9FZ^>bP0l+XkK#JF+s literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/hss-epc-text.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/hss-epc-text.png new file mode 100644 index 0000000000000000000000000000000000000000..9739214fb407ff52edc0d21c66cf4a9141a23e21 GIT binary patch literal 726 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZMW&u7Su0Z-f>EL7Xu|GhaLM1_d z!3+ux4FC5xB&@$LVDP@b;C#URMGTXe7#NsrJzX3_Dj471INP_{fT!(Y=Uagj{EFY} zH$Ru?5)53DXJE{2KYP{vXSzYFo$7iFk4YqhiG2kO4Rf=9zhmFem{jrUPu`)}8JXM9 zC@S@t@2!h^F{xWRKkKhcdETCtU&VLLEZmd%^>Uy`&DCsGCYk)GzfQ9+}rX? zcz@NNm*!{d6sCPpn(Zd<_w{o57VYr0_vPM{@93Y$=Y3OYQ(f@8r$N(8{lUJ2! zc0Bf7eg2TsqK669>)!iE{?ZXWxpuMd=l||SGjAB(`|?Z4EGchK=J%)d?8jz@*)!d9 ze_?*NZsE;`ibCCseZT*|-rn+}Z+?s{&>3EHbN6U|O@0}~>puI@`}13Uls+5Xkb9wi z{zJ%*SO>A~kF*27`Q~li{kCymll{Hz`@XKtuYDbT|JSv4zdte?{j3Wro`>yo&Cae` zwbIUdfqzEjr%Lgaw_*(!hc`>am016yq){s&mS#I zeu+=`_rhht-n;&vf397eedT?*&A%*r>$i2Y{rr9{QnUP^{o~U2_#fM1l`Ct0e^=+) z_#^voZ^Qxbnyvjaud90P-CF)zc;l-A_Nf_FYvT86#Ks@-(b>+M@b$)W2dma$tRfa^Bq6b;Ub&?f?8I8RB`QaQM$2$T_>L$@Y^H QFqtuUy85}Sb4q9e0IDa5X#fBK literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/hss-ims-icon.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/hss-ims-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..daee75ac845c72c81c4077652946c2ec71c151b1 GIT binary patch literal 646 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZMW&u7Su0Z-f>EL7Xu|GhaLM1_d z!3+)s4gLG?|7Q@G|K1=#Az}UbMCR643=E8KJzX3_Dj471I-3`x$kX;v;VNz8FRL?R!sGB% zj^Lng-IE2vxgK>*i?6?J&ARe=-9(x1r-S-xoNRcvyft^}z3}bNyv2Sy-~X_Eb@lpR zDbv-b>jJ(WUKPJ6FZH5&>ioQ4&z^64p`P(+aqb-ZU~l%fbN{PwRZQDt|365+y~6gM z{i^xZ7BjYd(|=?*J)>~R-uivhPsx4emN;`|%J=*3y&XT4ANI>!EPj3W`}g3_!Iwig zUO!(yVOreA@_+u<&wYG$_~4(J>*hRo^8DkU(}yokJFC3n>ajoazugZk{-gX&|MOY%`!%1tSIxWo>0ji66{50u6-B(D>U78 zzLS4d)jiAl%_6*ePyPETZ!`DN&w_tXHdeE$v|ant{CG$hn>i!pf|9k%KcmMGF z^|AH;zcJtYZ@cT$zd(D42l7+){d_h%|DS$NP3L((6-H-ZvS9FZ^>bP0l+XkK#JF+s literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/hss-ims-text.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/hss-ims-text.png new file mode 100644 index 0000000000000000000000000000000000000000..ec69f2599a89ad45dba8e58d50d846e7e090f5d7 GIT binary patch literal 757 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZMW&u7Su0Z-f>EL7Xu|Ghaf+azI z!3+lb8Tu0x3hvK;FW}G+aDKfq@6l2Q2Bug~7srr_xHktHfhrjq7W`c)z7oXBJAN-r zk3CU?p}#YVKQs5<|5SF@GgJOt=$h3oUdRNT)oILrbzssPp1-qx2)<&NdOT)jnVrqgYmL92+*~|U zo_zwJl2u+BpDc%StAk5=^0SQR?e^cd&&y?~{2<(6xp;0pSL>@4N6y&S?b??YIc4kn z9qO?fGrN-t{$B}~v{RGQ{5i?D!{*S*$vf*$N-&+Pn0Y4Ub+Sg&Qg8i+gEN0g7<(UL z;Ye9$5iD;gmz$`fzu?Qk&*8cYITgG=l6-9w5#{Zv9WSUU%WQzYHmVkUEtT0%XeSz|FV?%(YyvB^}EYo#jX7#bTnW8?&{X_8!FD9 zzJ7Q0%=6E!6!yJ}0MwdZyP*If09`1R&^UpG+g-uPW5i8|R1tE#tt zN&m`o_q0LHRiLtp^|2nMzd(Xd!^$;)My#!QInQ4tzI1(?-LJ1QEz{p!J+^)=ci_)e z)ux{=o;?)}HoW3P@2PP08$V~fJ{*2`^-_Jo`11Alf9S+&^>bP0l+XkK8&;t# literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/icscf-icon.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/icscf-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..dafbe9e0a17dbbe9a16debf0023eb9916cb1d63b GIT binary patch literal 855 zcmb7??@v;D0LDpEl&mTUZp3mpi^X}1z1P5YR z2`mPK5yL;2TM#n*y;0#I`XqC|g|thQU&IR;{Cs>8I~iK8swxl^GPaAVQ6!t81;r+B za@?OzS6o?V8G{jK<>&4#k}aEiGhu8^j*ED|CAp?1NT>DkSI=NwBl&_8?AL?MNV$h8 z7BMfz*V@iJIKDN$mgn4&Ipd8U+E%E@=nn3metFL!>n7`v?u8BVMmbS3uF;uIZLLtw z^VKYDDQoJc9?N6oTV!`BEFTtB3IsyGwVv)3Yl(h+w{WV=;(eHYJ$ zo-5Uum7kcW#f9W?P8KU`J_DrK?in=oT;Bkjs&nI)ydT2R%2R=>k--3U<+kGSIsN-# z1?5pk5tXf}BG*EAqP-nTyzmF6uPV7#Exh?L7)BTfwmYjSI{YJ!A*3Xr!%LH|1{Pij zA0PJ88?>qMe>bzsg4HzpKUaO%n%S_q9>j)azLdJ7`#VuzhnDapb>3CAHB4Ho;*Y@A zm4@~-sU(uRAy|jy=_@0s{hZim+y=)wGproTM*h`#(tPQ)o{?%B$^W&dM>x{Id@-X* zA%bqzoPDy%F=73Z*XUiZJ*J$E8Vk(wioj9J;&c;NMQRaXcY;YTEWtn!7h-_SpcgAh zydp3Imb87~7Z`Mmzk`_;pl18E9a3u^wa)~0&&k_}Y-+_<-_qJsU}KUIO!$Rkv4tlQ(W^6ZyWS3 literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/icscf-text.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/icscf-text.png new file mode 100644 index 0000000000000000000000000000000000000000..6dbfc819cc612b6c1148c4882c1b114cdf5cedc5 GIT binary patch literal 657 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZMW&u7Su0Z-f>EL7Xu|GhaLM1_d z!3+lb6BrZ<)}R01AK>u*zQFv3-Wk8j85kIUc)B=-R4~3d*a%e0(6Hd|O7WFUASMID zvZZ`w%Iu8_Jo*7Q^ky%6_&2`na*|`F=4STpn(b3u>UwR@tmpjbeTe^4VVuh2zX@99 zBAfa$FI`bOxmvZ=^P*?LzXRHTEID zKXOI?+Lx+SaPi{Ia+mTiTQAMwU*NBz$=J9oeYVui1ix9@ngLS#ReJsfF8j0Sex^`c zN~O$`6;f|2W#f_smR0UZsJyt|?B0x^8UME(&fFF|!|Bkpx&ZD=H}{|8!aeV*&$@9&-2ct8V2)&3+#hBSlgx8-bN%hR*A}g~I(dT7g3`F^C)s=I zA1vCLdn~zriEgcoOp*+1*jtn9H>+h%|6<){>Bg7nEpINX8TGQ)Nyv)*+n0|VJ55-( z)W@f=9dgw(ObC~s<#*|db+X6Wq7uHNpG+1`42!$7|No^Ru03z2t(>x`VB44agZIBZ vivY!6!i4=_Rm!G0)a}3j{`>F0C{#V8*XETGu?$}~gH(FD`njxgN@xNA_B&Qs literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/ipag-icon.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/ipag-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..6f15bdbf4793415b578edba7d857b391ea3f0279 GIT binary patch literal 95 zcmeAS@N?(olHy`uVBq!ia0vp^^&rd$BpBWuQ`iTjm`Z~Df*BafCZDwc@+3T6978G? qlNabpur5vz>1hfy;Bq^t!N91hfy;Bq^t!N9mTUZp3mpi^X}1z1P5YR z2`mPK5yL;2TM#n*y;0#I`XqC|g|thQU&IR;{Cs>8I~iK8swxl^GPaAVQ6!t81;r+B za@?OzS6o?V8G{jK<>&4#k}aEiGhu8^j*ED|CAp?1NT>DkSI=NwBl&_8?AL?MNV$h8 z7BMfz*V@iJIKDN$mgn4&Ipd8U+E%E@=nn3metFL!>n7`v?u8BVMmbS3uF;uIZLLtw z^VKYDDQoJc9?N6oTV!`BEFTtB3IsyGwVv)3Yl(h+w{WV=;(eHYJ$ zo-5Uum7kcW#f9W?P8KU`J_DrK?in=oT;Bkjs&nI)ydT2R%2R=>k--3U<+kGSIsN-# z1?5pk5tXf}BG*EAqP-nTyzmF6uPV7#Exh?L7)BTfwmYjSI{YJ!A*3Xr!%LH|1{Pij zA0PJ88?>qMe>bzsg4HzpKUaO%n%S_q9>j)azLdJ7`#VuzhnDapb>3CAHB4Ho;*Y@A zm4@~-sU(uRAy|jy=_@0s{hZim+y=)wGproTM*h`#(tPQ)o{?%B$^W&dM>x{Id@-X* zA%bqzoPDy%F=73Z*XUiZJ*J$E8Vk(wioj9J;&c;NMQRaXcY;YTEWtn!7h-_SpcgAh zydp3Imb87~7Z`Mmzk`_;pl18E9a3u^wa)~0&&k_}Y-+_<-_qJsU}KUIO!$Rkv4tlQ(W^6ZyWS3 literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/isbc-text.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/isbc-text.png new file mode 100644 index 0000000000000000000000000000000000000000..a842e9ffde944cfb18270e2469d46eb8d5821e99 GIT binary patch literal 649 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZMW&u7Su0Z-f>EL7Xu|GhaLM1_d z!3+it4E_5P0_Oj}-=Oebpy2#^t{FE)85kHpc)B=-R4~51c02E}g23^Ihh`iuFsl4N z{jO|=g2uhDsV|Ru{eQnoHL$M2E6@&T8Up-N_R98+|FOWk{paaR*3Ws3*@b0IJ@3to zWO49T#?ARQrAI$3nzsAz_G!Cc zZJs-S!-h9E(`{Rq$8ByKjeIFET6p!dtq|Hhp$o zp1oC8*YrPc?YMorm-_2Gd+fb$^SpQ8i=+RnlRvgXYwf#l@;ZHA&hM-KHl*NR(So~wlPW$vU6e1>xnp(y*~^ZH+Mc@Y-u3^~ zxw@2%a}4L-e|KNtXkg@(`)}4q7i^hVfA`wkVy&#=dac^OGydw;{aY4sBmVXIOSi7; z%nQGo{QKu}$NIb9b%c1Ix7Bf~>Bh7EdHUz`4G-PV^4IUbcb~aZIdS^rv}4PT-Qewh z5M_I6_uISs9<7r)?5j8bZ;n)6m51l1{UJMp&3{kZ|NozH`$D7jeYZdR&x=p-4*$D2 zV7bBVO!_z8&9WzBGS{<&t;ucLK6T4vu1Aq literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/iwf-icon.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/iwf-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a82e73c193297eabbdb8f1f862ddac30d78454cf GIT binary patch literal 696 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZMW&u7Su0Z-f>EL7Xu|GhaLM1_d z!3+ZH6&M`;zYpl&-%v0=;l9Cnw=G%53=B;2o-U3d6^w6Z-pzZWz|+cY*se19!{>kc zyUnegs!bewUbRZsPY+$mHcCY4gQ{yK+t2rI{E)w%d>O6hqxw@qIC z?>E84PZm8`e)x^nu};s!{Yt$3>ouhQy;%{X_WR*eeb#uv^4>qux;uOFS6Dq?|Fq(P zbl%)w+3pGdwSF(TP%r(x;%V@=H|kzL&hXha%{v$N{@=%U*T27iEr0vi%jNg}R%hP% zuP!CN{Qc9L^Sd*CY`@`o-*?9TZ)uOelvjS)|K-{F$GMNcoPYk)x?|q`tLHwJngSn?|BCk?F8*s% zlsozFRPXy&BcA=_FZi|Z`u{zbzrKHPY&OG!U7COAd-GratzLKPulm$W`9~|xRMhXZ z{2SKe@#{1H<33)IXfq{l)yRZCUTn=_-FkpR^vE@?AXY;Fs_73;(;ypTGS- z>fr8OS^v-WiGA>Vum6WD{L!25{88p!F%SGplzA6Vu79-7VqN%$<5zM|Gqi&em%+o!(Qhiw1!U;cw%*suJFQ~yoZ`KliIvfnf8SMtQtx=a3F`rpTE t8}9#^o>2FB_WeK4%=iC1n-5|BXHMLFRZ#Tv8&JAr@O1TaS?83{1OQX&h#vp| literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/iwf-text.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/iwf-text.png new file mode 100644 index 0000000000000000000000000000000000000000..4d0092eb0ba59affba0db2a4cabc1192a8e2b20a GIT binary patch literal 595 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZMW&u7Su0Z-f>EL7Xu|GhaLM1_d z!3+%w3=ReX3IFF8>=)?2e}4V@K=rl985kIMdAc};R4~4sdbV$|fdJcalNkwT{O|ow z4PT^b$#W`h)7-O-P{NX<$7Qfe7dhOrNw&IT7vHIK(#Zt#FxfvPP7XEAHJ#xM5@O%4d9`$+B z88-H1t|`)cJN_Sf{_l0AmA2u;FQ*EQ{H)AR{AFYuc=D{!Yki$Pjnl*2lnOh(@T=_n zVXN`G>5|i5oxSH+k7oRS`{!oeNB`Q#^MBmjxN}?F`@e3sr}c~eWo%d7|7BPAXTt1oqc{=S)*Z#W0_qV1Tem3#uqrYqKx*2=OX)^v}_*cLG&!^M+xQPGk*Lu2B UHc!1-0gPh?Pgg&ebxsLQ0N7YT!vFvP literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/lrf-rdf-icon.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/lrf-rdf-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..82b5c473bee9504bc5d5d9044a3f5a992502516f GIT binary patch literal 953 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZMW&u7Su0Z-f>EL7Xu|GhaLM1_d z!3+Wo=l?VG&wsDruz!8R{Q`pkTNC$H3=GT)o-U3d6^w6h{4ZLfA#(I%!*eD3mTTYZ zZ?3(WvHYy$E2G;1D`!3Zz5QGJ3XLbp-1m?@9R$-zZ(C(U84EjXU^K1$qWa!{yxU&U^Mqnt6cHX`ycYX-D4Pn99o!q|ZODJb{(de|uI>n!U~Xm*CC^ zTC4XR4u4rEt9{${X@~7Y?d89u*I1ZUo4OLc(s17PDbX!;Mp~Md$w&Vu&wFe zwny?&deI$06`8(cQ{8`*d|z9+&Z=O2&xi85GwU;w-Z0mkt|?_GYncC{IV9d}DdWDP zcJ8>>@7ecEn|f1l*Kfh~A9>6xbo;(`7o=`jZyW!z{)w{%&$p@KckFJ6$EDsaYJR?7 zx9^tij!jwPf3YfihW+1{{`J2u&;R#jIf!Ym zS^e)~-Lde>CF|oGRO}zle*47S_*D3*+xoWMJRjQ4AgcefD>_KB1TDM1449J`JYD@< J);T3K0RVwr0!07- literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/lrf-rdf-text.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/lrf-rdf-text.png new file mode 100644 index 0000000000000000000000000000000000000000..14daba85503440b4f70fed21c83123b3e5d15a72 GIT binary patch literal 638 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZMW&u7Su0Z-f>EL7Xu|GhaLM1_d z!3+it4FC5RC^YoXPYAewUf}(D@rlv$3=E7Gl60GlBdjdvTleo)SR&t<)~x@0PVqTQ5b-yY+vLYA{Te=x2j<=j{vXnP)am&+ zvsNM3^xfsOOZ>k1Z`o>XWIJb>{F2lwtc%xC@p{jG<=J<`VCJ&F33vRjxNQFC=X>;? zzs-R+b{)ye8|T%wKL0i~%I9~b&!hTg{ zoqbG+{iKGSwXWX_7pHB0)$eHXI(bps^RLqv^oDP+b}DwiCa(0d)JEFW38R{{Q~5_;kj<>9^ANU;VYcchx)nug;EG8 f{XHZY{EL7Xu|GhaLM1_d z!3+)t3<(VZ3jg#&IYaem)}*%#hc?nr4` zee|ZloSUk<_Ai}U_4CE7ML+-e&0_lzGxNZsTN{?k@BRMN?Zzo{)>luihi5$fz4ySq zCp&zZ8_pGXO6~e}=ae{C^~qS@xfM6=s!v}%J%53Vl-rMhnti`HZ~gkcZ9`}Nzk>Pt z)q3{q#%K7o(rq>iH#}-=n)7k1U)}8XSNHuT9-jZQYQK{o|F^~Wy{DU&-~1^0?8lmY z`~Qoa@8&C2wtKXB*RRsAPq*FvDs+DN^7!|=Y}>V`@W_{aJ2-#$ynMTQjgM#KJ}uVI zU7PNShQQr^vn0RsrMOo@7R3v zknp~bzPCS~3VZ(iyFlL?EB1Y?+OPS4%oUEW`FK&j$1@vmo}n@K(W%(5z;`^r^*X{B=$kMH|Y=y*i+Drd%BHFhpNcjlV1jUQhhUjEfoo=KkX!}A)0t#z?{e`^o3 zZ~OZCaK6=_C*Hp_>kq~}_{g)izV_FP_ovq%{+As8b#JTrUzZ8hPye~cJ)Qq2_r&}C zE6>lm7x`bL|LXs1|F(y0{a7lq<$tu??Q7d5+H3!PwBLW{KYs(a$$|MZmY%;~&-UX$ z`0l#Tf7gG1p15 zTd$w`$M|dY+DGy`gZEn>m#RCTf93jz^XZ@eKiJ>e-(SBpfBtGdd&$h`^pM}5`}h8k z`jh>O@!O;I??3&%ZIokqR(J$L>6e+Fm#jQd8L)=dnXd*3MR(d*CA$GmE4>*5c*w?B3q1ne*WuRM3? z&sXoIkFfyzKi=!#|M>v|=e}9od>S)9c<#9`Ru|ve?7uDZ?$eHwPvz!E&w2M@*TJ{{ z_Fb3$@bTl`TTjmF>2IrCe?Gfc_k7*z&Ho;tnQLDNRQ8`K@TE*sOZ?>rz|dvzboFyt I=akR{0BKp_ga7~l literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/mgc8-text.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/mgc8-text.png new file mode 100644 index 0000000000000000000000000000000000000000..2ba933a74015951a442990285b1e467031a5d58f GIT binary patch literal 771 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZMW&u7Su0Z-f>EL7Xu|GhaLM1_d z!3+it3B=3=B+Jo-U3d6^w5V8ZrXa9#Z(d-0YZK0+0y= z0anXXx8$gEIA5IAAmDJ}|Noo!UKbXB^I%`TPF>dEv_prU(xL{ziLUB8N`CDBG#=JR zOy&I7E_cl}UtLo?_0+DLo&0wXdK|4N5#Ik-=*Qf*;!mV!*PiriT>Wk7TdM<)b1OfX zd+8qR*Kj$sC)GH4)xC(`%+z=0_4NU6wr7ja=BcP|=-5`7uYSDwzERoP6Y}fZn>*I@ ze%i6!w0He_a((aj#_j*EHXD4ge=ql^;=pTfd;gQRQRjYUWb_yB_qMp~ z{8w?Ozwg4GXaBIq%d%{%eRbTD)9YVS#f0i&x5R0k_66SY7j&Q1^_B(fcY3_Wy#B~> zRlh%yin|Wk|K4i#X|c+z;0>R;3%v^+C2JqEKhghDa>;$WqRrYfo9^y@vg6;^*8i&> z9j-m3!s5F9Lwe&>tA7uBzKY-bVJdm<;;)@|WIi4Ke>BbJfZ>lnrr%GUj}_7U$lW75 z&3o#JU#Hg3lHR`2_29i683iZfq^sq1|NiHdh97!*?*aeCi9xq5`2N=ix%^u>VNS8g zavsI%bCwr=ME}44?O6mUy(CQ7|5c@InuGEF`|rR1{#ys9{(t`c_a6h}k)CTmoEh~% ON5 zTd$w`$M|dY+DGy`gZEn>m#RCTf93jz^XZ@eKiJ>e-(SBpfBtGdd&$h`^pM}5`}h8k z`jh>O@!O;I??3&%ZIokqR(J$L>6e+Fm#jQd8L)=dnXd*3MR(d*CA$GmE4>*5c*w?B3q1ne*WuRM3? z&sXoIkFfyzKi=!#|M>v|=e}9od>S)9c<#9`Ru|ve?7uDZ?$eHwPvz!E&w2M@*TJ{{ z_Fb3$@bTl`TTjmF>2IrCe?Gfc_k7*z&Ho;tnQLDNRQ8`K@TE*sOZ?>rz|dvzboFyt I=akR{0BKp_ga7~l literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/mgcf-emsc-text.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/mgcf-emsc-text.png new file mode 100644 index 0000000000000000000000000000000000000000..74bf8f2c66fe26d5285c68efaddebcbe1efab21c GIT binary patch literal 1140 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZMW&u7Su0Z-f>EL7Xu|Ghaf+azI z!3+)s4FU`b``;(5KR@5#et*E`(?4f2FfiZoba4!+h&@k# ziSmyH4K1{VK8pErovbl?tA%=+1K8Ej?%-|^Y$#;A#BGG)TFrI zxPswqu#{u`ZyAfnw~yt|{eJX#enbkNY0~l5bz9Gz72u z*^)n7;mMTq%pOPUj%x~O-l#m|}-`g6WjrfOd5|2Hi|)Ae^(M_u=^Qx5Ce=S_Jy z?-A$!DuxATPCWl>dHwHG{raD$jsie%>P7EGtsZM}DzMP%;Y@4CBA|9iY_ zLFb|+>nt|8vL(5m3cL4^{jkl0yX_51r9B5!r(C>VyYs8b)IaTO*=zPH-aJz}|NA}Z zN&ftMzfb+v9J7M=-fzQ6e>a^k{n_!R`_l5@Ql3EhUl(s=%m31}PwSuY>D;~>?{*%r z`xE#3HP2Pvmyw$V|1a4ee((51f2Hkd^A|sB;=f^B=i;ZK(^u5&_E37>|DA2WUj5o! zu8}$S*Ztk~U$VG@n!Al6q6Hlmh{u0&|J$IZG>L!iDcLJk0ydGR$N35tzA~+U&y~OT z_1*HuH7aILEAN#DFMQ`}U+z7ng6C)0#K$f9p%dCqyVgfsv55KfGD%qX=N^U+40^vT z+&AVQ+QB#3U$eJu!jJYQ^PjV7xwr65Jg@n)uIpcJC zjye0jucu8K&fH(*(-8c+KEZBxer>km`SSU;NBv(P`uSV_i>1`RoyR@pzvv#|eZM!X rl~M1?GTmAKtNw5OgA~nR=6}vrdmXZmMzTHt=4J*@S3j3^P65 zTd$w`$M|dY+DGy`gZEn>m#RCTf93jz^XZ@eKiJ>e-(SBpfBtGdd&$h`^pM}5`}h8k z`jh>O@!O;I??3&%ZIokqR(J$L>6e+Fm#jQd8L)=dnXd*3MR(d*CA$GmE4>*5c*w?B3q1ne*WuRM3? z&sXoIkFfyzKi=!#|M>v|=e}9od>S)9c<#9`Ru|ve?7uDZ?$eHwPvz!E&w2M@*TJ{{ z_Fb3$@bTl`TTjmF>2IrCe?Gfc_k7*z&Ho;tnQLDNRQ8`K@TE*sOZ?>rz|dvzboFyt I=akR{0BKp_ga7~l literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/mgw-text.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/mgw-text.png new file mode 100644 index 0000000000000000000000000000000000000000..a2470f5d133ece5544bcb9e7d2965cf5dbe3cfc6 GIT binary patch literal 823 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZMW&u7Su0Z-f>EL7Xu|GhaLM1_d z!3+%n3TRfe66;s zlsosxp?jmX!Y4}(TgyjIfA!;HJ8nJXXckiP7P&8wn6hf60e%T7D~?!~WzwmTjzUKVL57c=Rx{vCsP`QZgO zUw&mUh`$qAH(j^V?tjvXsps$PJ9?q|k+S4RPdky_&llTWKc3~z^hsGoc~R;l|H`_s z`zKoKwPOyNmCOkJraJ%q(3`=8rn zRuyfSo@*BE=3H~yKhP#_ol9r7S^3YOrt+_D3)hQ$x7wBF-g;|#&8w)?EBkIGTh4#w zAL{x3Pi3s`pTLyo=}&*|zdbvd5tQN_|6SXBBa~_GpSu0`-+%x8_g^!Zg7BEvTwfr= TogDZ9lpsA_{an^LB{Ts5Bd)Cb literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/mind-icon.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/mind-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..daee75ac845c72c81c4077652946c2ec71c151b1 GIT binary patch literal 646 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZMW&u7Su0Z-f>EL7Xu|GhaLM1_d z!3+)s4gLG?|7Q@G|K1=#Az}UbMCR643=E8KJzX3_Dj471I-3`x$kX;v;VNz8FRL?R!sGB% zj^Lng-IE2vxgK>*i?6?J&ARe=-9(x1r-S-xoNRcvyft^}z3}bNyv2Sy-~X_Eb@lpR zDbv-b>jJ(WUKPJ6FZH5&>ioQ4&z^64p`P(+aqb-ZU~l%fbN{PwRZQDt|365+y~6gM z{i^xZ7BjYd(|=?*J)>~R-uivhPsx4emN;`|%J=*3y&XT4ANI>!EPj3W`}g3_!Iwig zUO!(yVOreA@_+u<&wYG$_~4(J>*hRo^8DkU(}yokJFC3n>ajoazugZk{-gX&|MOY%`!%1tSIxWo>0ji66{50u6-B(D>U78 zzLS4d)jiAl%_6*ePyPETZ!`DN&w_tXHdeE$v|ant{CG$hn>i!pf|9k%KcmMGF z^|AH;zcJtYZ@cT$zd(D42l7+){d_h%|DS$NP3L((6-H-ZvS9FZ^>bP0l+XkK#JF+s literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/mind-text.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/mind-text.png new file mode 100644 index 0000000000000000000000000000000000000000..84f9d86d79fe9f3ef1c6301f65b46280dd308321 GIT binary patch literal 550 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZMW&u7Su0Z-f>EL7Xu|GhaLM1_d z!3_KR84?WE3ph0Vzdv8${rP}`T6LSn3=E9Do-U3d6^w7MU0gRuL8SFzGdIh24&(R# zHyuqVzje%3ZAr}8U+<4KKNog=#Q(cZBDu%#7=oCQt^33HeH0_dJ09KZQH%LF_Mi8h zo$Z-j-rfJ>0)NkwGtSNvHnXT$UN)2r|I5#JK&^gif8c(Z3#%S>Z?9SV!!dr&zqlix zPAC4FCI2P$^8eglLHU2H7%cW&{@hl>Y0-W3OZ4fv?=O6=>UFN`%~+fCWAF5ruP=Kv z@6)kjzpa1q)7N`X1^0hBDZBLlj<4NGZT&iHYmd}_KWUknTK;~2>D;I~dBaD^S0&$F z{P0_XbKCr14TAC4_p(IP-TD31_DANCh<_imvwqgd`fdJOcjMo`8Sjz}|1SFDBmec`@8WIsB416X?_Imv-u~B@mzS6O j&$p{ZXZ-vAV?V=&?yfm)-Ty^_(Z=BE>gTe~DWM4f2ZA=y literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/mme-icon.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/mme-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..58ab86c5933c0aad87db2d095076149b51d26484 GIT binary patch literal 232 zcmeAS@N?(olHy`uVBq!ia0vp^Q$U!J8A$qnnlv3qu?6^qxc&!&(3-C~KoQ20AirP+ zhi5m^fSd`QE{-7;ac{5LavfC=V0qxsHAPO*{bN#-Wz?bF9mgw&>^! b{%4GrcU^lEndM~xbQ^=GtDnm{r-UW|szqhQ literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/mme-text.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/mme-text.png new file mode 100644 index 0000000000000000000000000000000000000000..e524f192c82bb73e202b79182d657927d32462d4 GIT binary patch literal 252 zcmeAS@N?(olHy`uVBq!ia0vp^Q$U!J8A$qnnlv3qu?6^qxc&!&(3-C~KoQ20AirP+ zhi5m^fSe_sE{-7;jBigEavcf~aJ?uVw4}#+M(&N&WG5!Q1G<0DUDEA|h)_%IGC0rZ zIOEX#pb0zgyi)jmc$3cStL6tL;%cnkW%3GdL26Qijr>mdKI;Vst046MJIsgCw literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/mrf-icon.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/mrf-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..59463a91779bfb5f18ff47a0f8e86d4963902df1 GIT binary patch literal 437 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZM#sNMdu0Z-fiD3KGM@>L&f+azI z!3+)W|1%gk>_6Wxkg$G!!2N<($Gs zb|yP)Du~T}Zm(Rc-ftEZ$D!CF;FKYzG*`3j%hvE;VatkBTjTkDvD(%Ah??KLtm+iM z=k?NK{hrY_k2c?WzWm3Bhlktw?XRC*zHhDmM6P|r|({$dr^|3H6WKr(o``njxgN@xNA+^XEL7Xu|Ghaf+azI z!3+%n3)0RwWCB6O z?~={QiX6-dB?}ttU6;K7zbW~$1&?`AxJllxTnAqZ?p3=#eb|3sy%NKcr?=MJzWUCl zX-Z6d)BC>%zISk6IOG#vqf;uYWcjMt_)pVW`xQTHm(TLIzBAY4%gNP0pE!2?JRD!^ zm1)_by?y@n{pT#}+&*f5wad5A=YMpWZLOu9?A?;mI_YlL)6+LAUN|9sUGtYE!?fvt z<}T&hl+#~#bx-}8JqA9Oc0YHVny~5q(`7&2K6=@5Z@sko4L+|r>u(L`-mhBmyxWVl zy)Mn`e1GJPjq^p&#HeAw(5ZGnf=pWUjMqWZ6bf`)!^&w zEfe*#0>34`S^Oscb7JbZiu3$Oj$W^s5dXpU|CIQGUGsOG5 zTd$w`$M|dY+DGy`gZEn>m#RCTf93jz^XZ@eKiJ>e-(SBpfBtGdd&$h`^pM}5`}h8k z`jh>O@!O;I??3&%ZIokqR(J$L>6e+Fm#jQd8L)=dnXd*3MR(d*CA$GmE4>*5c*w?B3q1ne*WuRM3? z&sXoIkFfyzKi=!#|M>v|=e}9od>S)9c<#9`Ru|ve?7uDZ?$eHwPvz!E&w2M@*TJ{{ z_Fb3$@bTl`TTjmF>2IrCe?Gfc_k7*z&Ho;tnQLDNRQ8`K@TE*sOZ?>rz|dvzboFyt I=akR{0BKp_ga7~l literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/msn-icon.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/msn-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..8386fcb44ff81ceba2217e0a5786ed2dcd66028b GIT binary patch literal 465 zcmV;?0WSWDP)mu^pozi}_9$E|65PaB z;V5)zkj95N2k926B-z_OyCyQi3 zsH-Hjh@vbL#4d}b3qdU3HGl4OPHZ2x+agA0zOHDIt4W3vrVA@6bIqbM+l(Hv zwOM%3zRGNwW=rHJi{y4@{#hkG2(;#%IU*Z(W{BSD>E<;**$I31z?A+@00000NkvXX Hu0mjfE4kN> literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/msn-text.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/msn-text.png new file mode 100644 index 0000000000000000000000000000000000000000..954982f15f8fc4958f47c0e4f54031c32d17df6e GIT binary patch literal 318 zcmeAS@N?(olHy`uVBq!ia0vp^Q$U!J8A$qnnlv3qu?6^qxc&!&(3-C~KoQ20AirP+ zhi5m^fShNZE{-7;ac@r<`Y}85v?i_(3h?uOt{o7h@HW(fQ`qmo)SjRvX9PFNs>Urn zA);(A!B^}0qc=OY z;F4sk|6J7&yK85|_PjjzHet5rq@Zo{r}f+yd~-B6UFYJwJ8B!AB=qN9xmkPZ`Rua? zYrKvfT6^=!G^yyu_&4h|atB0~{aycMndB*>tEaktaqI1^-F!_33~d*coLZ|Y|8L*wCYGq6Hbuxb{u94XdbXt0l2fKj zt=5Wv`te6;>)Xn;6OKRMpS`{J{Qpz$`5wNnly9-In}6PZUi?23zREw!zwefP-JH~; znE$T6uH1K}-eH55JyHK=1aVc?0F^!e{1cV>6aV%1kF5OvRkL?p|1kX{SoZ$S_&@w# yTK{hS0aE+l-Tve2U;P^cF8_XB1yoRXbY86N#?6Hy$L<6Dz~JfX=d#Wzp$P!f)2eI$ literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/n7450-icon.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/n7450-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..1ed07db41f7397e45f5a3e07f37a819507c6ed13 GIT binary patch literal 464 zcmV;>0WbcEP)jq_gkv`UTL>yxGzV@17yFPllVf{q`WU0ahNh&XIl|R0}#oxqnuel{*?h`w9rj**TH)I#H27{<cXF4C_wH7ybMH9B+P|Q!{WD?~9Jqk9 z#A;jART4R3S5^pv@j=stAXaW#xHP)tZf~xc5hFWaS7hXBl2Hlj!ph1#TT9pzK;!?}Ii5N?-#Ow~^P8r=y^+{d!#6or ztZa?1PsQowHHNd#rv0}`ZS?+acQXEEz2?nrR1;U6 zZC3mjyTeIGM}lkRWMy4R>DPP-6kaJ7pibJ@YVw{G`uXW5^B##j9|r*V(E z^z_LyL)|~;b51Qc)I$ztaD0e0swz2hGPH# literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/n7750a-icon.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/n7750a-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..79ba2fc22c19c1e00b8b2db4e31c1fb672e97d27 GIT binary patch literal 393 zcmeAS@N?(olHy`uVBq!ia0vp^^&rg13?%;)_Xhwewg8_H*Z*J;TJtprD8g70+xoA<<~gp)q&et1vY zTg>2Jva&jzQTbx{-QA1=5=qP^Tn*per$6?5-+oVFZ*mp)*Lkme-O}YEVw?Ag*9QK2 lwr>8*xAq$RJ9htKo%!lxj<4{MZeU0sTjZT6%3iV=L2t$*QjC9d91Y+mN+BkhIG-M9ze7c7io%WGRagR6t*M$@SWc8!q^g%&4I zO7cA~dfK4_SRxuEMoSdfJxKFrcd$JYD@<);T3K0RScB BXe9su literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/n7750b-icon.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/n7750b-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..bfce0b12d09a81a0549a77ce89416c673d555c85 GIT binary patch literal 393 zcmV;40e1e0P)mJ{XN5CzBVGV`z1*1t|Z4J_$sC6Y!(J2=D?fmWL)l&vJg`BLPStgEN44n9-{NMz0p6hy|n*tzWbQ zOanlQc)&O;zSW2XNdH6F!M8ANDdx1L*ae=q9$oDW2f=uPco8mVYLl< nU-U-lox8rKxBo+Vz}=l+ndsTjZT6%3iV=L2t$*QjC9d91Y+mN+BkhIG-M9ze7c7io%WGRagR6t*M$@SWc8!q^g%&4I zO7cA~dfK4_SRxuEMoSdfJxKFrcd$JYD@<);T3K0RScB BXe9su literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/n7750c-icon.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/n7750c-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..47870bc53180e6bf810ccc4e9a5c113a94b6eca8 GIT binary patch literal 391 zcmeAS@N?(olHy`uVBq!ia0vp^^&rg13?%;)_Xhwewg8_H*Z*J;TJtprD8g70=t5HaJMNcpYcKV1GTTg=y{_uP(r#>JPMpmu_>^#b!Ba|Pi;LS`kZbBgco<`W1x zfBRmg!}?!Gr8JlXoNO2znJoVOebZ$2?Ql*&^6@uf|L$MDrlu@vE4BULo$1edH3 literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/n7750c-text.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/n7750c-text.png new file mode 100644 index 0000000000000000000000000000000000000000..afad34de6d70444900e634b801f1f06f37e48b61 GIT binary patch literal 258 zcmeAS@N?(olHy`uVBq!ia0vp^^&rg13?%;)_Xhwewg8_H*Z*J;TJtprD8g70sTjZT6%3iV=L2t$*QjC9d91Y+mN+BkhIG-M9ze7c7io%WGRagR6t*M$@SWc8!q^g%&4I zO7cA~dfK4_SRxuEMoSdfJxKFrcd$JYD@<);T3K0RScB BXe9su literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/n7750d-icon.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/n7750d-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..f407a0f6bf8c50669ea56ec445c792db4d42227f GIT binary patch literal 391 zcmV;20eJq2P)#Hsc*e4&Ai|al%YN`;UNa;1%jWjxQ8io}?%;Ht`65gW41m~x z1%x&PVA@$>`2(VwD?A(HRg*Dq1zwPg8t(;Ok&7B11wNS@`NGNj;l>Rf^7^oblvW62 z4G9Db5NHcN0U}`lxCt;3T!zN=k(uBX^Mjv65I`npf>v1As{v)N7Er_z(n$ajfrNP^ zpok+(O`A9LRBgJm;M2JVza>lTqWhr1V4J-tykO>}OzX6Hh*06EN z?wrcr4FIQl-uKP|yy_Qgpa?(+p#p*gQ2+g8oOb)sZ&1Hu{TB9n+HW$GdEo9g^!KH| lQT?5}d`++aLAk@t%`chi@oc66FbV(w002ovPDHLkV1n2JrN;mO literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/n7750d-text.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/n7750d-text.png new file mode 100644 index 0000000000000000000000000000000000000000..6e25a269fdb09968c1f9aa673265ff9ffd1149ed GIT binary patch literal 258 zcmeAS@N?(olHy`uVBq!ia0vp^^&rg13?%;)_Xhwewg8_H*Z*J;TJtprD8g70E?OvGO%cnytE0LSkpoQof#;gVERf9J`Vx zt>V?3I^l-IpWM2~`9J1c^i9?lxT}#-RQ8ME6RVu06<73*HxDEePwqOVEihTrK%R-) zWkN=i!`=gm4R3TqA1w4OcpIJ}Wa0hY+^71&f?He$2LpRpUD$3koocv$;LL(7i<5%B zywA%%Y-IChZq+TR{$ToobP0l+XkKgJWZY literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/nb-icon.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/nb-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..e03be510de2ca17e373aa3d7ecd1e08e0fd48ad3 GIT binary patch literal 1127 zcmb7@`#0MM0L9}G)Z+wI^<3h#oqFtqO1(~ZB1TaaiqTH16m4ys*{WV4-;^Mv8jV+v zSfVR6q8@cdYvemQ-lbVfF(zpnk0_CnkorcFS^tCGbMO89bbq`hVfX+eeJgz!3}zG* z=ofxK;J@f;9rRX$*zN%CVdo?L52*hC+DaJSKUkWkhvOq)C?6MCoEl7%kc|*^V6`F7=Lqaayb$v2O2z?KEh%p9i{gcq@ zyUzkjJ6{5{u3@B9h&TlMRb8!zx-5&}J>;*`wpFy8uF3MF{Bq|dKSYs zONpaI{d5HXb?laP>)pE1`kmVO>zt?B@p#4Bn2o_PD#75^;{FfB6D#@H{^-sNV;EGj z)d<}uMKRr%c`u#+;~oTe!UbT<+AE96?z0+Bg&H09O2g%e@0j0Sz%Z!IH-&DuCMPBa zgMeHfHqFP}B5AOpTa%pJb$8qWJH;c>azd(88_E~JQn@p!f{4eq6jo-;RK10}HE^r}5=z$?$_aHmgHO0ocpO(&D#vdI5w|BCsU_9fwI)y=qmx z>r5WglHH|{phuih71+lh_RgPtNi-vEAF*#~w2}e(2R~m#K6LR=*kXi}D$Njjj8cbe z*aO`#rb}eO&=hBJ17r9N&W!2pccNrlu0p@CYQ-^`S*vY9p(#0FZOfcATFu$h-tf(f zL*On}#!@=wwmWh8vT!n7^aN=w(jvgP*JRho{x!g<0&Vf7Zd*I&KnZku*_s3ifB;p9 zp=sBRcFf6m)+`e`V z$gw@>dgNb(d9Y{`pNAD8k2(9bXWB`cUa+h-%j7Y;o<5#p-I%^a>vA~)n?Q8W1_vxi z9mf4C-RdR<11maAE?i5}GkCqOyQHI}#Oi8`SNj&v>ha|~Llg5yM^P!zM%D7wMh;J` zp+}vf8b|f*!#69}D*QFbRZ|B1#sXs6QdM3HyaSdc&7ugy0u|6k31VNw79 literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/nb-text.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/nb-text.png new file mode 100644 index 0000000000000000000000000000000000000000..bbc1357baae8e44ed76bf861794a931631608e91 GIT binary patch literal 499 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZMW&u7Su0Z-f>EL7Xu|Ghaf+azI z!3+rv0t^Zc0qghAH+bKF{(eFH-Se>w42;p9E{-7;ac>S7G6IzzQuw{x?3i2x$bJTf z2XC(&>}yrvX}hTTM}w=W_W$&`8O}yK-CjQ`GyNOJq?R7Mpg`oK`b{r}OD6L3D=nj# zMfbdCUmx{DBYwLYL!lL$GzrAj@U*V#2=_!vs z*F4u}?kL)H>xXHkoyRpZJM*jaeQNKS)K9y=?|ryf@W*h;Der$*%Z9%`*q{8fwq8l@ z%GLF!Bhw!)Ztb6XzUk9H6DFTOH&`^f zEZ=Vbo_=eGs@gw^#;WJarvz{Q(9pU2>xN&w@u!X2|88vfG*PtP_*-)Qx2G1fe`@&G z$@DLo+yD2~cLm+4OH*Db*Z;U~r1STN=ziB=`KLGe1-IFKi>{CKyeN8q!T-m*-|zeV b4i~XM(eKFa5}mM9ps@6G^>bP0l+XkK18EIj literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/pas-icon.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/pas-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..74bfcfcec12c94c1d58181b42ffe2c4297d890ec GIT binary patch literal 700 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZMW&u7Su0Z-f>EL7Xu|GhaLM1_d z!3+)s4fFT+Com}d7g&GZ;Qsr7HMQSM7#Nt8JzX3_Dj45hzu5O!fv4@FRm%}WPQ~~C zH?6+txAx}0mOl4+v#0L&j`|wlqEz9c?;0qAj4n=jHs|xCut)R1KbXJ8H*(*!Db{pU`_(^u*&UB|ldB zYd&@Um-+R>)almybeBB7e&>uZgM7t@_4>b}eq^hfUR-t8UGDGN-fxvNpGIn@$ya_U z-5~fqsKMzgL?O~QXQC)JQ_G#>`H~ZA}SKs~qBz4>GNSV`V^N*Nrj{jD3{o|dh zKWp3X)=$^-HLRH)Q+v4nmwfHvU)STm=>FE{-_>K+o!@>ne_!3EUpJ@Dzxhf%{@$DL z@O$q*zdUvO@0YWm!>hH(Iv?usic&;6P1J<0xDe(t`gyaAJ3&21)`r~jD|eq?o$>tFubY~; zj=oUN|6VERdoJ_x$6a%_tJgE#dvVx##azqUDYsuday(`I!)E4t+a-J2&xcFD`cbCz zG`8m6r-u97&HQ^Vwyz8RHTTF3wmmo7uQ_knQ)I66?c3MR%Y92XsqW^_4WISdy?7T_ lHs8MNhwbupKhTJJ2Iuw|JwB~Z{lLV;;OXk;vd$@?2>_N=ff)b* literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/pas-text.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/pas-text.png new file mode 100644 index 0000000000000000000000000000000000000000..48b1e273bc3c98d26e86fec07def2773ac26a8e3 GIT binary patch literal 596 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZMW&u7Su0Z-f>EL7Xu|GhaLM1_d z!3+)w4GabX1^?G8yuaVSfByM^8-HKVW?*34?djqeQo;E4+QDga6a-oyGJ5H-a@YQ! zezq~j`i9;l)-^@@LvOu2b3az>_|Jv^c?6Mw<@1^qdnW6zi+ZBD%e3XH>rZz3Pv(Br zvnQWh7g{yt&aw&pwJGvzR?FV1_}SrF9W8V3da&K4*Ib{>Cp*@z-el%@KwF22TP;6r z#+e0n@4nxx+wHLTaxROj!j{^Cpjg)TGS`nEI{NNt;Wz1wx04RMWBV>xaCdra*qNU< z+gJX*^X}-q_ct4V`oB(JbNg>IvplEz-$NTe7y9k554`a8@0ra_t+f^Qzpm_?8?tfk zpWpH??HWAo&-A|jJ|`si{WY_WI_C1r_NRL6+-j5l?0EUDhQUGdKEFhXxbF{*?Jvw* zvoq{(SEZkNf8Dog{;wCC!)~AW`+94d{>kZ0tAl^V#qY6kU90xhH-63AMf2~zpXcn} zu;|8t8CUdH7C7Yk{XbCrqmB2-*TdG^XNA3EL7Xu|GhaLM1_d z!3+Wo`vV*p=Knw6zdqr;f3}lTW4?&Gb>5eDcYDC#OHY9H)1ce!h9k^N066@t@D@ z4BRUZ`oE~#_dxy9&!+h|p2pgj00m?|t&@+6{~-J{)qc|ccwWYeU(7s=7QeQewg@EG zGaRm47RNqI#NA%`dN14R)$=ubIYQX}q;ovKc6jLz&zg7ZPw8JcAo+3f>y`0S#4ojL zuKaXHU$XwhrqaM3&mSA#z3t02Xt?$E`S%_CYy!Xk{^>E=p>sX2{^~L2H!=!A>*GaQ z=7kkk@A>jmwOPWiY4!Q}2W&i=PCP9C$vi{db3>Db^&eK>Qzy80y!p2(BbYtyK;k#< zm+X@qGS{3vA6&1)Ddf*EdA=L3+Ce90@!9{G3@5QTDK{VVH|$qGc-DKv!FbX53%?AQ z7a!C&-?u2~TYFr6Tcb|@pP#$!54u!6IUfF>Rr%o2{RezLen_7Y*#Cb0hR25gh0mn) z|C!G0mh?69f5)wPh3j71Up!NJ{lEOdp9T3Xm;cYdAziKi{4al?l>C9p|Lz`-w?E(e zU$v>)oZ~s>o{r{Q2xamgix%zL;UtZP!OBEB?{$u|CnbJod#{W;?n(-w5e`21& z?(Dy-=N@tSwEn*!yM)Teb@f8an;h5KeT}cyRq06oyZbL|$L^fmX&Zm--z!&Wev2un z=9hfvMWyzuEB`0kPkFwB{r|t|e^Z`a{jdFM!S)|-O9h|*%Rig(`2PQG^Uu}%{y+Ut z-|@fg#)rBt|Lre2+;ac#^n{KB-~ahP^r?9GFZgbL(7uBItJ_wn)II!nduLn05sSM2 i=jXqi{|^QIXVo?Eu@YT-js=)P89ZJ6T-G@yGywos*sXN{ literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/pcef-text.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/pcef-text.png new file mode 100644 index 0000000000000000000000000000000000000000..23faa7d7fa5c4e7ffd648a74e1f06ea6405a9ceb GIT binary patch literal 539 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZMW&u7Su0Z-f>EL7Xu|GhaLM1_d z!3+it0S){66&MQU|9^j8VEz3BuP>}+3=E7-o-U3d6^w7M-R)a!z|;2dSmA*u>mUBh zFPq6KJ}WJ(JLJ&G?{deQ+&6U`VUCq^;!tc6fD=5CaYgpLIqoZ^)!#dDT;vVw@37C7 zpS({?_rDL)W_|hCACX)~@y4J}vlhuk4>0rPnfc94enS zO-;VP|K;yR^E;pAiuLj>vQ|6$_@{ks-TjJ*OA8;@-b>r_iOX_jmi+urqJI_t9_P~3 z`?GbQ%3r3>yWXp`_e@<~yL=yS{p_WyCa({VxB9*6)zKe!{kNp=d;0nHZ~dy<(RFjP zo)%x^lkTwnJK@1?)jzJotCVzbN2kl59b%3wE6nAwq|4EYMYt0KfnK%ufIQC(d1EH z9d}ol)i0-)v67ogKAC^!vig!rG$y(WhKQ=Z1;?oa>l@Nhf7yj{(Y4-da{fGIft aKV#n>yGxskw%i5A6@#a%pUXO@geCx3B_W0Y literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/pcrf-icon.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/pcrf-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..17ed4a4a6411af3a73bbe20029cbded82ce90a02 GIT binary patch literal 785 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZMW&u7Su0Z-f>EL7Xu|GhaLM1_d z!3+Wo`vV*p=Knw6zdqr;f3}lTW4?&Gb>5eDcYDC#OHY9H)1ce!h9k^N066@t@D@ z4BRUZ`oE~#_dxy9&!+h|p2pgj00m?|t&@+6{~-J{)qc|ccwWYeU(7s=7QeQewg@EG zGaRm47RNqI#NA%`dN14R)$=ubIYQX}q;ovKc6jLz&zg7ZPw8JcAo+3f>y`0S#4ojL zuKaXHU$XwhrqaM3&mSA#z3t02Xt?$E`S%_CYy!Xk{^>E=p>sX2{^~L2H!=!A>*GaQ z=7kkk@A>jmwOPWiY4!Q}2W&i=PCP9C$vi{db3>Db^&eK>Qzy80y!p2(BbYtyK;k#< zm+X@qGS{3vA6&1)Ddf*EdA=L3+Ce90@!9{G3@5QTDK{VVH|$qGc-DKv!FbX53%?AQ z7a!C&-?u2~TYFr6Tcb|@pP#$!54u!6IUfF>Rr%o2{RezLen_7Y*#Cb0hR25gh0mn) z|C!G0mh?69f5)wPh3j71Up!NJ{lEOdp9T3Xm;cYdAziKi{4al?l>C9p|Lz`-w?E(e zU$v>)oZ~s>o{r{Q2xamgix%zL;UtZP!OBEB?{$u|CnbJod#{W;?n(-w5e`21& z?(Dy-=N@tSwEn*!yM)Teb@f8an;h5KeT}cyRq06oyZbL|$L^fmX&Zm--z!&Wev2un z=9hfvMWyzuEB`0kPkFwB{r|t|e^Z`a{jdFM!S)|-O9h|*%Rig(`2PQG^Uu}%{y+Ut z-|@fg#)rBt|Lre2+;ac#^n{KB-~ahP^r?9GFZgbL(7uBItJ_wn)II!nduLn05sSM2 i=jXqi{|^QIXVo?Eu@YT-js=)P89ZJ6T-G@yGywos*sXN{ literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/pcrf-text.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/pcrf-text.png new file mode 100644 index 0000000000000000000000000000000000000000..e48c305e21622fb96a703c6dc7c582dce9dbe481 GIT binary patch literal 594 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZMW&u7Su0Z-f>EL7Xu|GhaLM1_d z!3+)t4E_7x|3AOJK;eFZKtsU%o>hy?7#J9Ldb&77QFwz zN%}OF5 zee(1`zq#%2H;8X6xFvjfcb%NG?c?J*{^iem^}kD0ui|I?zHs)9HTT7SP5<`EyZ-QQ zqx0>vH>~`0YW-20`tMKbA6{<>?*0CuwZ7N8yX3yey^r3n?|x)FG=1OO8INw4{oJ_! zWR3mR`M-{yEZM*1{MjFO|9nv2Q@^xVum9}h-JiGH&!2ztxqRhY+4x^O6xM%Q`k=)2 z>g8WXeeu!H%xmsX)US&Ae?)rIiQ~`hf9yL^zJ1R}*85LH?Vd?b72v8{bxeN$^l3kf zR_V?w``2?+D}LPy4*x^HESg@|tX!*c%Q~xe$It2iUT?}?E4%L8|NqIgUtV5b?myqI g_7^(i@72GI5q}%?Hy)WV2N=Z+p00i_>zopr0Gy#yK>z>% literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/pcscf-icon.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/pcscf-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..dafbe9e0a17dbbe9a16debf0023eb9916cb1d63b GIT binary patch literal 855 zcmb7??@v;D0LDpEl&mTUZp3mpi^X}1z1P5YR z2`mPK5yL;2TM#n*y;0#I`XqC|g|thQU&IR;{Cs>8I~iK8swxl^GPaAVQ6!t81;r+B za@?OzS6o?V8G{jK<>&4#k}aEiGhu8^j*ED|CAp?1NT>DkSI=NwBl&_8?AL?MNV$h8 z7BMfz*V@iJIKDN$mgn4&Ipd8U+E%E@=nn3metFL!>n7`v?u8BVMmbS3uF;uIZLLtw z^VKYDDQoJc9?N6oTV!`BEFTtB3IsyGwVv)3Yl(h+w{WV=;(eHYJ$ zo-5Uum7kcW#f9W?P8KU`J_DrK?in=oT;Bkjs&nI)ydT2R%2R=>k--3U<+kGSIsN-# z1?5pk5tXf}BG*EAqP-nTyzmF6uPV7#Exh?L7)BTfwmYjSI{YJ!A*3Xr!%LH|1{Pij zA0PJ88?>qMe>bzsg4HzpKUaO%n%S_q9>j)azLdJ7`#VuzhnDapb>3CAHB4Ho;*Y@A zm4@~-sU(uRAy|jy=_@0s{hZim+y=)wGproTM*h`#(tPQ)o{?%B$^W&dM>x{Id@-X* zA%bqzoPDy%F=73Z*XUiZJ*J$E8Vk(wioj9J;&c;NMQRaXcY;YTEWtn!7h-_SpcgAh zydp3Imb87~7Z`Mmzk`_;pl18E9a3u^wa)~0&&k_}Y-+_<-_qJsU}KUIO!$Rkv4tlQ(W^6ZyWS3 literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/pcscf-text.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/pcscf-text.png new file mode 100644 index 0000000000000000000000000000000000000000..b8d2c3dc8f5cb680d27b56cd945f1a02366afaf4 GIT binary patch literal 744 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZMW&u7Su0Z-f>EL7Xu|Ghaf+azI z!3+)t37 z&P7SSHRCxHP{Jp{k-+r-|K?yD?$f%fuWkBlQaSCsZ;}Rs%sc-I28ZvH^fg;%1WEaH zG1kwmNXxt=$FsE0FiTNbd&Wxbc_G)a2r;MSqXVKWsDNE;*iaq=GSK;%1iT zJGRed5O^1rV#}je&hR2MPQ9>GE#a@!$;4?j!m?4S)7G!~9>bE!dGmat)q>6cj?bTy z__jRpE8~vEKO;L5+oIHLOY?b;kEnS*HAbE&nE7$?aeI z-`Ml_rQ)9~D$jlXNAp_!jpdteNXjgE`&)O<^GI%q9X-bm{4YDvLD}FAp@V0)i`=gC^n;MI^pHNk~DG>H@t&Gv}dtX0irxtld{yU_%b;>J= z;D*v^lTE((?q>^#D)_kZ$y}BVDtA6{hYR=CaTQ@y{dl_ixvX5 zTd$w`$M|dY+DGy`gZEn>m#RCTf93jz^XZ@eKiJ>e-(SBpfBtGdd&$h`^pM}5`}h8k z`jh>O@!O;I??3&%ZIokqR(J$L>6e+Fm#jQd8L)=dnXd*3MR(d*CA$GmE4>*5c*w?B3q1ne*WuRM3? z&sXoIkFfyzKi=!#|M>v|=e}9od>S)9c<#9`Ru|ve?7uDZ?$eHwPvz!E&w2M@*TJ{{ z_Fb3$@bTl`TTjmF>2IrCe?Gfc_k7*z&Ho;tnQLDNRQ8`K@TE*sOZ?>rz|dvzboFyt I=akR{0BKp_ga7~l literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/pgw-text.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/pgw-text.png new file mode 100644 index 0000000000000000000000000000000000000000..d5f86b59a72535a341332d2e4cbd7c1324489964 GIT binary patch literal 807 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZMW&u7Su0Z-f>EL7Xu|GhaLM1_d z!3+it3Je7e3H$%wUoX)Ae*XD@?cEpM7#NuPJY5_^Dj44!G-qUB;9yV)|9>Xx5PwHG zP$LjTE>HK=-K=ZtsKC))8(;H(y022irV}S*UMKaLJi1FdipweEPzZD;f~Yl~3JdbgM7bA&!@xc*cqs?^@3N=s zXJ!97TU!(26G~>fu#|`nxFVvQ8IR3bZY1X?7vsvqfq__Pzmu~Ul&{oFs znRbU}&#p05y7yzp!;IR1@SBgPM%{YmZmL*tq+Qki%5$gB8)R3m4V?XF#*LmAfBT=k zcy`)-Zus`=xrPo-ZtMR|W{)xYbolU5mD~5T=9X&&GiK*a{BiE*=QGEbI;GiV>+=b{ zpAu3m&~^WlZElP9vh5T1c{j!X6g@PlWl#B!?4>Ii-s}rY*seE4aN{3oc@yD@4d*x9 z&)vT62IIsJ6Z_3S{^t)byAjFM>nmqv_xW~F+S-pkhHIZC9hd6-qb<+czUEL7Xu|GhaLM1_d z!3+Wo=l?VG&wsDruz!8R{Q`pkTNC$H3=GT)o-U3d6^w6h{4ZLfA#(I%!*eD3mTTYZ zZ?3(WvHYy$E2G;1D`!3Zz5QGJ3XLbp-1m?@9R$-zZ(C(U84EjXU^K1$qWa!{yxU&U^Mqnt6cHX`ycYX-D4Pn99o!q|ZODJb{(de|uI>n!U~Xm*CC^ zTC4XR4u4rEt9{${X@~7Y?d89u*I1ZUo4OLc(s17PDbX!;Mp~Md$w&Vu&wFe zwny?&deI$06`8(cQ{8`*d|z9+&Z=O2&xi85GwU;w-Z0mkt|?_GYncC{IV9d}DdWDP zcJ8>>@7ecEn|f1l*Kfh~A9>6xbo;(`7o=`jZyW!z{)w{%&$p@KckFJ6$EDsaYJR?7 zx9^tij!jwPf3YfihW+1{{`J2u&;R#jIf!Ym zS^e)~-Lde>CF|oGRO}zle*47S_*D3*+xoWMJRjQ4AgcefD>_KB1TDM1449J`JYD@< J);T3K0RVwr0!07- literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/plrf-text.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/plrf-text.png new file mode 100644 index 0000000000000000000000000000000000000000..72662ef42ceef27f9879f1e294f0e63235857ebd GIT binary patch literal 735 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZMW&u7Su0Z-f>EL7Xu|GhaLM1_d z!3+Wp1`PY(|3BZa(2%fxen7$f(^u!NWnf@(^K@|xsbGA2^Kag6E1rgjmKO8*8t?o+ z`|lZ7_^Cx-Czy)Jo_uc~oN>LK(@F97r9AJ;CcaQ~pn#k2YkU09Lw2wKY!(nM6WpJa zdgSSY`8!Pye{|e;cFyP8=*IuwPMYtux%i#&SdE_lms*>b*4b-iI==Mjzi-v8;Pd;j ziM8x_vr?Vm`Ghmi51f23=lok6jz_{~yuTzW9h~hd@+SE|wyS!#Z@>M=1%97i|M;kH z6LECA%F;slQwM&^^Gsj+d|TbWnS%Ba=j^o}UzhKG|09==<-r@t`qs+2*n%tf1=D{f zvI8ys9XoaM|FfU#^Ya+|es0^F;5V~AXj@Rt+tY7mzve&l|7h_`wfHL)JKxt?D@8tg zvvuE<`4gwI|J3_0apm_P75NYD_lvmy#clKbcthx8M}wdSuiy6zO#Iib zf7o92E6@1Cx~-p%hJDeup7RRZxa-feNdNg`LD6gF6G|Vy?pxDlW+!$2?e?D% zDHU7ye@b{=^Xbmlx^FSB{+ul?_;JHGdadF;LY-g(v^ z4g0_T@5}s=T^o7pZv6fKvH$)?*Z5akD)z4*}Q$iB}OH`Ux literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/psap-icon.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/psap-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..2145c5f6a35f9b6bd2d71f0c9d3020384919f2f2 GIT binary patch literal 322 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf`3?xk^GbjKl{s5m4S0IfH{P~{u0{JW@L4Lsu z`|ItK1Ey~V^6z=NIEGZjy}g{s)oj4i_VB`2hU5wcUCWNk@BgLWQt`RirObBh*uL-n zg0GyHgq9`sn9j&P&mie-!Tg|~k!kuOhF`J@k2eH8JNWm&r%5aLSG1}z^=x}7VX#;4 zrd}^&t;_*_1{MyP=j1hfy;Bq^t!N91hfy;Bq^t!N95 zTd$w`$M|dY+DGy`gZEn>m#RCTf93jz^XZ@eKiJ>e-(SBpfBtGdd&$h`^pM}5`}h8k z`jh>O@!O;I??3&%ZIokqR(J$L>6e+Fm#jQd8L)=dnXd*3MR(d*CA$GmE4>*5c*w?B3q1ne*WuRM3? z&sXoIkFfyzKi=!#|M>v|=e}9od>S)9c<#9`Ru|ve?7uDZ?$eHwPvz!E&w2M@*TJ{{ z_Fb3$@bTl`TTjmF>2IrCe?Gfc_k7*z&Ho;tnQLDNRQ8`K@TE*sOZ?>rz|dvzboFyt I=akR{0BKp_ga7~l literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/rg-text.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/rg-text.png new file mode 100644 index 0000000000000000000000000000000000000000..ab93224c14ffd98aa3e8daac8ef436e97d869cef GIT binary patch literal 540 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZMW&u7Su0Z-f>EL7Xu|GhaLM1_d z!3+)o4gLG)Cnzx7|NmZ~z+nCPy)G@+7#J9vJzX3_Dj45hJ-BJHfSf!hDm z=Q0L)tefrWyY=Rre9<$H)_X|Ry|C^;fD;kV#qO`wbGdWlXui@(eY3~R_CM4=o!+)T zbd$Hy64lq=X0J`y;CXLJ?0)@~4^&T_U3GtY?y370z5nvGcB^DEty0o|eQ#gzpTBIe zca~TMRA%;dsO_E>{`PR3bV7V3kLuchxBaI7td@8QPMNl!O6O^>wk2Ea?gM9zwa^q(+sm*+286Ff7!B-`Mah5lL2qjs16@aucNJH`C{ecQS@+iM!K?DvI# zQp!Kabl0vg-aV(}_6m8%AOHUyUvzVB@xcWbUuY-Hul;s29S0%$htc?L+!O07JzIg1 O#o+1c=d#Wzp$Pz literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/rnc-icon.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/rnc-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..733d3da5db77c25d591b3f49f5149a88809b97b8 GIT binary patch literal 591 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZMW&u7Su0Z-f>EL7Xu|GhaLM1_d z!3+Tn`|tl}aG3vIz#yStq2T=b4mORu3=E9hJY5_^Dj45hyV&*EfT#6g;UneSn;vg@ z|9{izO*$1Um5-Q7q7eNviQQ7r$40%V?t)_f9NB9`n^TC z`cKLJwG}$WfBq$yiwfpy`^0W%{;gY^cI<=pF|WC@tzI9>d)|K5 zJb2$gNYrkE6WX{aD`Vv}Y zj8O(#1pYK^%&nTkbnyDk^0dR-r#v|Q_9wr=A76=mjs@>OEw3}5?Dlc%fs*^dUc0Xb zPI+{?saW^W$E^>1Ts`-(%+cgHJ>9x*H~0DL(tW!$FHVm$SYML(E9mr`^-f>;!wP~E ze=m}rw{@jKO?20fl`~vC_N_hYzPIzjpU255rQ7EB%)e89zxMlGDDijt-+lU*H+}qU zl>7erpMVedymmct-?O{o==zHKuTAqg>Z~5_e!uVcJMDw-#cLuzz6;y=DEnCT>8dxM fi;+#Kzpbwsqx;<2`11!~{4#jD`njxgN@xNAS0hN3 literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/rnc-text.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/rnc-text.png new file mode 100644 index 0000000000000000000000000000000000000000..24cab754a1f0a10c7de436fd8020a9d0af0d747b GIT binary patch literal 646 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZMW&u7Su0Z-f>EL7Xu|GhaLM1_d z!3+Wp2@Ui2_XjX2-2Z=meSyLI241HJ3=E8KJzX3_Dj45hbDXqVL8SFzjDrYk%isKO zp=T}%8RQG(xIdr2)n$K1{HZ+>$vuY05X3yMDQ0OK=DQhp-kyDS_sO@i?OUu(C3jc6 zcaBN_K0ofA_o?v6*mX;u9lrLqGxA*eDnI#1%k?ZjUoCfbUwr35vrSlA{=R({#-+a$ zx<&8)xPSi4=lp%QE;au*nZJJi<*E9Trw?i@^|9FZ)4%TP^Qb%VJ3f63-F)jh(+|D- zy*qk0zdwF${=x3slNoEK^Dp}H_sWlFdm4IvYulgSD*tEq(Wzg5@2dKD^RQ0s$LMEe z_rpG?vwKYEcfb4Q{Kk9rVN5FyU9a4C{iJMHwfenXS7z;Wt@!vo?~gCMd^~jeA@}T;-s{vI7JbiN-oN_QA@_|R z=4#d#cir;~t=%WB5c6Y`$Ubhln-?Xj_pJE+r{wD<$CY26zq#$S>*-(XDRxoZ_m^Jy z5cuxr--pjHxo@;lS$0MIs_}n~WbU}1n?l-Cc-!Tc$A7D@&oVmZb8_MFT9^5DwZFc+ hyu92Wol(E5equm!Cezca;=p9V;OXk;vd$@?2>=wmWxxOc literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/sbc-icon.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/sbc-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..dafbe9e0a17dbbe9a16debf0023eb9916cb1d63b GIT binary patch literal 855 zcmb7??@v;D0LDpEl&mTUZp3mpi^X}1z1P5YR z2`mPK5yL;2TM#n*y;0#I`XqC|g|thQU&IR;{Cs>8I~iK8swxl^GPaAVQ6!t81;r+B za@?OzS6o?V8G{jK<>&4#k}aEiGhu8^j*ED|CAp?1NT>DkSI=NwBl&_8?AL?MNV$h8 z7BMfz*V@iJIKDN$mgn4&Ipd8U+E%E@=nn3metFL!>n7`v?u8BVMmbS3uF;uIZLLtw z^VKYDDQoJc9?N6oTV!`BEFTtB3IsyGwVv)3Yl(h+w{WV=;(eHYJ$ zo-5Uum7kcW#f9W?P8KU`J_DrK?in=oT;Bkjs&nI)ydT2R%2R=>k--3U<+kGSIsN-# z1?5pk5tXf}BG*EAqP-nTyzmF6uPV7#Exh?L7)BTfwmYjSI{YJ!A*3Xr!%LH|1{Pij zA0PJ88?>qMe>bzsg4HzpKUaO%n%S_q9>j)azLdJ7`#VuzhnDapb>3CAHB4Ho;*Y@A zm4@~-sU(uRAy|jy=_@0s{hZim+y=)wGproTM*h`#(tPQ)o{?%B$^W&dM>x{Id@-X* zA%bqzoPDy%F=73Z*XUiZJ*J$E8Vk(wioj9J;&c;NMQRaXcY;YTEWtn!7h-_SpcgAh zydp3Imb87~7Z`Mmzk`_;pl18E9a3u^wa)~0&&k_}Y-+_<-_qJsU}KUIO!$Rkv4tlQ(W^6ZyWS3 literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/sbc-text.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/sbc-text.png new file mode 100644 index 0000000000000000000000000000000000000000..f71bfba57edc959609aea78340bc8206ba273f8a GIT binary patch literal 632 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZMW&u7Su0Z-f>EL7Xu|Ghaf+azI z!3+)t3<3%3&o|89-yfiG|9wHm%pWWa42%yvT^vIy;@%uEWCSWbr0{$Bwqtw|azHi^ z?76$^_EZ@bMut5Vf0l;c{$79ctiaS;rNwF!y?11JJXTLW$jI>dbLgL+&s1O6?09ee z<3?C(ONY7ZfyZ+iYNpI)nmhGl@?Lk5D3g1^A`jLsbKf^lXy5#eC+ym@8#IgUa({83 zUiZgZIN`Om{I=RvE94j+1m%jluH#j*6lc7#%8v1zOLgJyx@DpZRbx&b?$<4^k@2rq zwB6Eg!v4s-Ca(D0M*9$%r`K&7T>i|XB- zzO{SLCth3jcT?mO?Th`Vo?cfi^j1PdFrN^e$M=%9kdA{L1`rVqp zb)i$A&*c2EZ0q$G1>67p{hQH!q<44e{|~QBCAHN3;-lvL`xsO6S9$MT`=425e^>Wg z@Vs3p9wjhwlg+nS`6(SsZEyP8?{)WmXU8tzR=xl2w)65IUW#mL&f+azI z!3+)W|1%gk>_6Wxkg$G!!2N<($Gs zb|yP)Du~T}Zm(Rc-ftEZ$D!CF;FKYzG*`3j%hvE;VatkBTjTkDvD(%Ah??KLtm+iM z=k?NK{hrY_k2c?WzWm3Bhlktw?XRC*zHhDmM6P|r|({$dr^|3H6WKr(o``njxgN@xNA+^XEL7Xu|GhaLM1_d z!3+us4g32Y7z_#m1m>^*|Nj2@1BLcV3=B+1JY5_^Dj44!G-L#-Wi~re&c@5D{ z;p-vqAIV!-9X#%1+Tyn1#r$;FtB&ixi|l{>K=R3g<^zSCFHefGZ@B!>{%i2{nL_?5 zFI>)>m0q6d`-n;S^~Yte&V0N!JvO~e+D2sMHsK;2o()pv3nCf+U;DnTKJnYu)j>9# z&r*~1qUBGYP_kZrDQ_7=huMMOH;j!hFTBP2CHG)J?<4-1Hl4g-lgq_6ODF0+eHtEJ zzoBwl){13bGyV%|xj$&&NcyV$b8`LuN#@VL;kLRDZl|NrB_j%pDv%;tr;fM@@MnDg`vfD zuf>l^JzlN;&Zw=}|9N~3ZTnGmN4p&il$m??N8D z-2e8hAuli$GA;PG)^^QYv>I{QGa+{`>F0BT@GK6NQ^MB=0#0O0%A>elF{r G5}E+a#J+C; literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/scscf-icon.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/scscf-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..dafbe9e0a17dbbe9a16debf0023eb9916cb1d63b GIT binary patch literal 855 zcmb7??@v;D0LDpEl&mTUZp3mpi^X}1z1P5YR z2`mPK5yL;2TM#n*y;0#I`XqC|g|thQU&IR;{Cs>8I~iK8swxl^GPaAVQ6!t81;r+B za@?OzS6o?V8G{jK<>&4#k}aEiGhu8^j*ED|CAp?1NT>DkSI=NwBl&_8?AL?MNV$h8 z7BMfz*V@iJIKDN$mgn4&Ipd8U+E%E@=nn3metFL!>n7`v?u8BVMmbS3uF;uIZLLtw z^VKYDDQoJc9?N6oTV!`BEFTtB3IsyGwVv)3Yl(h+w{WV=;(eHYJ$ zo-5Uum7kcW#f9W?P8KU`J_DrK?in=oT;Bkjs&nI)ydT2R%2R=>k--3U<+kGSIsN-# z1?5pk5tXf}BG*EAqP-nTyzmF6uPV7#Exh?L7)BTfwmYjSI{YJ!A*3Xr!%LH|1{Pij zA0PJ88?>qMe>bzsg4HzpKUaO%n%S_q9>j)azLdJ7`#VuzhnDapb>3CAHB4Ho;*Y@A zm4@~-sU(uRAy|jy=_@0s{hZim+y=)wGproTM*h`#(tPQ)o{?%B$^W&dM>x{Id@-X* zA%bqzoPDy%F=73Z*XUiZJ*J$E8Vk(wioj9J;&c;NMQRaXcY;YTEWtn!7h-_SpcgAh zydp3Imb87~7Z`Mmzk`_;pl18E9a3u^wa)~0&&k_}Y-+_<-_qJsU}KUIO!$Rkv4tlQ(W^6ZyWS3 literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/scscf-text.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/scscf-text.png new file mode 100644 index 0000000000000000000000000000000000000000..fd3cab5370aafb46ce6c8adc33d0a688cf1027e4 GIT binary patch literal 704 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZMW&u7Su0Z-f>EL7Xu|Ghaf+azI z!3+)!^Y^b$P+;g62q-YPfByaS&LDXP1||(p7srr_xHktFd4Wm~Dg0i(?Kt~tCLkLK z{IVqVtofP}N*tBgOfP<~zxg(+)M@&cSv&8qH+%e0W11g>?8UZuhkb7-3%ul=?0%=Sglx}&foW2UzOMX%&{9c+gBgoEv>e#_Rs+%&xlXyq4DW*+L|{~ zVzT!+P5-lSOHy5k@$K~?T^E1%^#7^)v+dvV#83;7Y~#1q(Oa6!H@%#`xliWgzps}M z6(O<_E=cep;D|v>7!=CAa{0t?aJAoyg#S2M*C#!_1OQZTyo{__oa7TGmI1eON2yz zTkLaU$D1Y63`cMKtXsucv&+@~n$a;k$&!PI;vy-J57zEf7=KKin tVSFd+oxR}w{A>Sz|E=49|NVDls@{F6iAby3%N$U;@O1TaS?83{1OOW3ZIA!} literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/sdg-icon.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/sdg-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..b4c0288b594ffb937beab64aefa2550dd84e2216 GIT binary patch literal 491 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZMW&u7Su0Z-f>EL7Xu|GhaLM1_d z!3+Wo=l?S#%-`=|pzuDR|9-)G+nqk_3=E7xo-U3d6^w6hI_4c#5NUaMpt>P2xk{~c5x(T|S^w=(^H0Z&_Gv7g66E!Fx|2zIs-emS))@Y0XLNjiJ-d^0?)*7D z|DUbzrfb$O{yn?q=ld7a|9<2;*#Gk5qMDzdo}QkrAOG+8&)?pE6Y>%p`zzg<#eTH^ z^bd=FEPu8>`#6*Q=L&|C$897w95{dWcvSrB^!@t!9}M}~Ce)nie;R6MHRo5Fd}P>m zpOHUn?(6jVy2gKBeZI>7>9SnApTfMt41XQ@J2Fg1e*c0xZRg$V4fnVGK35t4|Nhg{ z{U!E(Kc~J6f3m)k;d)EWg{^{LrwM-vT<9+F?;qpW3D0U}>i$1?a(eoI$$z{*w!7Bl m|2WhCzId{J{64T>|FgxhGu^3=F}4SWJ%gvKpUXO@geCyM4+>lW literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/sdg-text.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/sdg-text.png new file mode 100644 index 0000000000000000000000000000000000000000..3881e6622916e0211231650c50afff82ad926842 GIT binary patch literal 696 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZMW&u7Su0Z-f>EL7Xu|GhaLM1_d z!3+is`~RQsPf%cRD3~80@c#b#-j%nt7#Nu3JzX3_Dj44!Yy>K0Xjt%frT9uF5R+lX z_oCP+nHI(uLWfkRMBo3PTK;PK&jU-=aX+r8+p1)Huq9!CCu6qY#YlN2Lp523dv+%R zwC)BtZ{yt!9Gg@;(H5xzfJQp*sgq-c7L&wmc6jc zjiwC`{a2h&`E%(&m2cGd&&B70I+ITF3Z8v({-x3rH6Hf+=JM+v{{6aJ-d0d}*V2>x ze+q3aPu86N=-I4sb#2TX#TR`{yv$8NZmhqIhuN&YT9gn zx4rmvdiKS-YuisOf7`6H`SJ9>PpdSJJeN71UhliF`&XHagQ#%$->LF%Y#27M%5IEL zbX}PAS#>Fs&Be>B|I<8`R7{o=?1aeg=!U<|QecjS@-U{=`4XuP)XB#k0YQ`&B~L k-U|EgzyJRGZygG?pFwzzn_Zx{!ak5nPgg&ebxsLQ0Aq7(b^rhX literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/sgsns4-icon.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/sgsns4-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..8df1aac1415f563dc7172d80f44e451c23364b72 GIT binary patch literal 230 zcmeAS@N?(olHy`uVBq!ia0vp^Q$U!J8A$qnnlv3qu?6^qxc&!&(3-C~KoQ20AirP+ zhi5m^fSf*07srr_xVP6f@-`@lumlKmd%G2gh$&yZXrgyWLhML>|y^}qI#e$h5bwbS5C_8n>x3ZZXJ1+`njfIX?Bj{?R8wIZq=o~o7)=j zzV^j}Wot#eGcIiYU48!T|GXbpiud|`Tp#t_M>BHSvSr`)@E^%dyzyjhldp2#{686f Ymv>!zV-^+@2y_{Pr>mdKI;Vst0A*!i)c^nh literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/sgsns4-text.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/sgsns4-text.png new file mode 100644 index 0000000000000000000000000000000000000000..92cbd290aa90b5a971a2d3d90130b5210402c7de GIT binary patch literal 469 zcmV;`0V@89P)b z_KsEh#mEvkc=9yN=0=M&X)UoTDK?uY^WExVCYg_>{RiP2)o$~ z&VZ}s+3L-PwXyigI9gfmv&n?Ly!4CF56TlwUWU7Yd>HM4RemfM`F*sGl(Sj7sq#Eo z{viR4H4I2}hTpDw%`rH^2x26n_ ztvP-pbAxHe;@8&R?U?RZ$mvUKk=*RNZ*^lz+nDFDF{F&6qrcv7NBCA1<&h*~00000 LNkvXXu0mjf;7jKY literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/sgw-icon.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/sgw-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..2904d2770551ffc743b9e62859713385f74b6839 GIT binary patch literal 388 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_0wi;`T%Ezd!07Gi;uuoF`1Xz??_&djwm@eN z6=%&BhX}Pc5sk(V?{|Jm)n0pd<)?j$2J2sGZn~@DISGVbHa_*xw|2jke)-eQIXi>5 zTd$w`$M|dY+DGy`gZEn>m#RCTf93jz^XZ@eKiJ>e-(SBpfBtGdd&$h`^pM}5`}h8k z`jh>O@!O;I??3&%ZIokqR(J$L>6e+Fm#jQd8L)=dnXd*3MR(d*CA$GmE4>*5c*w?B3q1ne*WuRM3? z&sXoIkFfyzKi=!#|M>v|=e}9od>S)9c<#9`Ru|ve?7uDZ?$eHwPvz!E&w2M@*TJ{{ z_Fb3$@bTl`TTjmF>2IrCe?Gfc_k7*z&Ho;tnQLDNRQ8`K@TE*sOZ?>rz|dvzboFyt I=akR{0BKp_ga7~l literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/sgw-text.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/sgw-text.png new file mode 100644 index 0000000000000000000000000000000000000000..0801d79747d29fd37b58f4f84bd0dc6af78aa875 GIT binary patch literal 884 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZMW&u7Su0Z-f>EL7Xu|Ghaf+azI z!3+)!0RjvP1qti#&+p%FaQ^*=$;vM|x&DU)F(rLZN@Zp00hwV$0 zV|bFR;-6Z6TEa5x%>H#OhyFcya&YCZ?8nlE5tlZ0s@A$as1(THJ|S?zX2Y!gW%oFj zEUbxqQ*o}@Wx@IFET?wt-}3AB3G0v1{I^yV{)xT(3n>Wt^#rv=R zrYFA??f(+Wx3l1p!S?;iFAIO&d$#}ibvc!u34X^J51TFMdB3r*>D~6Z;?v9DztvyD ziu~GlNhIPIKU>AKYkQ)7 zoE$IPR&D;>sIBv|)c@no{}0aZI49A%1GZQO+_~-0szkky9nf?}*^hX^*B1r7i+t0q z9{PQ;yY$6LZMp9!ZgbzbSBB$izm->#DywP4;=N~CwElanl5aUSX-NuyUpMR0d+~Nr zPJ+w}e>Z-Tl0(mI5YE7N@__(TCpJ1vK>CfB*gW g-@5(C)W7|Vb7uZqvMnYYl$#hlUHx3vIVCg!0O|YD+W-In literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/siad-icon.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/siad-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..b2a0585aa0aba2257ac8f6fb33c980ed8dc2d941 GIT binary patch literal 774 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZMW&u7Su0Z-f>EL7Xu|GhaLM1_d z!3+Wh3=R9=|G&S!;Cw>Bd6DgSn~-tu|#gYwIJb}X-r zQoC~0#s8OQfzPF6JJuSl3|Yy9Tyz5i*h^p8!?OPSm3IM>ZOabter-JI9!e*~{y zX}?f!dGFm>f##9FI75pc&d+eWn)Ranl&AXdS#SRoJ=w}Cb>fWwb9c!FYt!o5!uY)T zW|@CJeAKmXm)MybnX!p8AeJl4su9(-|%Yg#)}Ow~x4GATv9_jJom)Kj>>qn;(zxd{{pu_Eu|OQ z+iSM_|90%`+^@};D|{VDSz*AWcuJo{&9>aEX@-u&UnwU7OnW;eJ0EMJtt=k49ya~970 zDJK=%^ZV#M{_yK*)rX(|zoXy(YeDz)-lx6)_e)ZvK9Ar04yI z(mQ#lzyFkeFTZT6Y4&{YY0d9C-EL7Xu|Ghaf+azI z!3+)!0RjvL3JL4)&+p&={(J$Wh@>e415>1@i(^Pd+?xZ8j6kJL3;wOo>)0RyWHK;3 zSabbhU$cS$%LC>x2ZxsL^*6nDmucSop!YwF;}Bz0sKQ;`+pYrx#8Q zz5HvPSK+4o4F$K{cb2|Zzj%F<{LSV6e@1<3e!+fm`-%$-;)S+#&5x40A7bhDA@lf+ z4?ky{mM-6zRio#6;XTW{$4AxYYoD@w^7-wlix-M34{ZMXZDsvyS4EjWZ#S;qV(NZl z!unMcuKai!rP0o|>Hcy3k#s6;)4{d+Gf9kyS^OGk2@hJXZ z|3^=^UH)UR;1`p)Ke4-i{;yxR#=UpZ@n<_<=4t*CyqrI){bQs0%KP75U*KS1U`djA z_C0>4V8Dv=r429Q{{M`fdH(t5pEY*#QK))G)1p5?cRn~sgOZY`tDnm{r-UW|jIy4m literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/ss7-gport-icon.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/ss7-gport-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..319bb37c9059a91ad924df29591ef434e45d2f9e GIT binary patch literal 286 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZMYymzYuK&RxwB~CLP=v80$S;_| z;n|HeAm^B;i(^Q|t+%%}a!91ZyXzrO0Uh|-~ZM-`rYao+I3a&lRKlVr|swN z505HtOI&hZj;H)z(#51X z`>Si_|97r_o4m(YuJYui&-+2D{eS+-+W-E&{?Gr6L2@A5qGY3hwmC`f;8q8^Zs!-) Y&1oX?Y-Jzb0)52b>FVdQ&MBb@0OSgW$N&HU literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/ss7-gport-text.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/ss7-gport-text.png new file mode 100644 index 0000000000000000000000000000000000000000..1ba8a76d722b69b39d64a9aa5547af7a510d2aaa GIT binary patch literal 418 zcmeAS@N?(olHy`uVBq!ia0vp^^&rg13?%;)_Xhwewg8_H*Z*J;TJtprD8g70%(RZ4|C}aNBoMmPfA_V!4Q5^EUYUhSxG#vGj3uw zYvCcDPt3Pnz0BY1@Begs?f=r#Mx9)zMa|yjXjlAGi$APywlL1|#}Br5^)F<%88L2S zu=Do_vtGh^Gt5ElN7f9*84ib=3=)&mVhBf3d#T}e`N;+!Tf43YL{?x+m+U=vxQX@7?_><^`g>AVGE-wPkN@uXYQTJHKbRn~V z*~UMi-KgP~;wBdBgyfeBcbcyX>y%qsuo^Q6%K98`h~93uuil|lV&l&l=DNTjX7F_N Kb6Mw<&;$U2$*PP1 literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/ss7gport-icon.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/ss7gport-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..daee75ac845c72c81c4077652946c2ec71c151b1 GIT binary patch literal 646 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZMW&u7Su0Z-f>EL7Xu|GhaLM1_d z!3+)s4gLG?|7Q@G|K1=#Az}UbMCR643=E8KJzX3_Dj471I-3`x$kX;v;VNz8FRL?R!sGB% zj^Lng-IE2vxgK>*i?6?J&ARe=-9(x1r-S-xoNRcvyft^}z3}bNyv2Sy-~X_Eb@lpR zDbv-b>jJ(WUKPJ6FZH5&>ioQ4&z^64p`P(+aqb-ZU~l%fbN{PwRZQDt|365+y~6gM z{i^xZ7BjYd(|=?*J)>~R-uivhPsx4emN;`|%J=*3y&XT4ANI>!EPj3W`}g3_!Iwig zUO!(yVOreA@_+u<&wYG$_~4(J>*hRo^8DkU(}yokJFC3n>ajoazugZk{-gX&|MOY%`!%1tSIxWo>0ji66{50u6-B(D>U78 zzLS4d)jiAl%_6*ePyPETZ!`DN&w_tXHdeE$v|ant{CG$hn>i!pf|9k%KcmMGF z^|AH;zcJtYZ@cT$zd(D42l7+){d_h%|DS$NP3L((6-H-ZvS9FZ^>bP0l+XkK#JF+s literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/ss7gport-text.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/ss7gport-text.png new file mode 100644 index 0000000000000000000000000000000000000000..8656f9f8476839743a5f361cc393ff43d7efed2f GIT binary patch literal 1011 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZMW&u7Su0Z-f>EL7Xu|GhaLM1_d z!3+uo`|tms&tM=B;BbC@Lc{z1TSWmY7#NtNJY5_^Dj46+xO-`-29N9P`2vO-KmO@k zM+x#T+c0b9qr6S)e%(HssOS>#U!!Xg92p$5;%Cr{XcnER>zDBH{hx!3Ne%LOe@}3* z9Y2|AEkGEnAY)zjp29rGi_mQMWFA&mWWf=Z`4uo<4K-`{Nql%wDDO#LQS(7yV}UE?@KPKNjcDe}29Bpz!8{ zo$u3nX1>4wZtXS8^Z!rX?OFKp-;4*ouhKvNnRM5=x%+R21j&OiIDIx$1? zHr~S-~u4B@87g2X}mj8~OdmqnHt^QiS?}a_P z&K?dn?e6At#szI+^OegL3vB-fEl_p+#$A?DHj(}1`n^5BTKDaH(AcsnPGHG=&*py> zueU#EwR`-S|K}6C!awhM1%m#v9C*9>e*DL(ig_Ch>l3Pv{0b5N@O*jMx#`cDJ6zki z&QGr}?O#{gxjFC$@9T|8%wF|Z-)&v5bMCIr9~$=Zk7iHp{C`(p?aSf)cR$C6$Lla~{SdG(8gxy1`F><^89UB2kw{^-wbU+&cl@fV%h z-~BiLp?v)h-Q|xy+>)w)dx`(oPWJD1ePIv9*9O;YWvlv~EV=%Fl!c<1_=~__uG#yq zsVi>V_HUO)-i7|Y-8Ny1=43T`@2}C-KX1o;)MNj{MKWKGU)gzi>HpoOkpaJU`W#*$ z|5!0U_GNyj^cIzC<>%x(nCp(UF!^wDd+l$TcWuL48BY6pp7Y6dX_3X}v`wdVchqK_ zx4ivq|IZIGRrRjBE_~Pjx*8bk;roAGU0;XH{9pg)KSREU^Y-AtjG4eZ$l&Sf=d#Wz Gp$Pz~M<@sY literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/switch-icon.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/switch-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..6e512719d73e0cb9576cdca11e2161231904c0af GIT binary patch literal 877 zcmV-z1CsoSP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D03mcmSad^jWnpw_ zZ*Cw|X>DZyGB7bUIx#RhGC3eIG&(amIyE-q^PkNC00PxXL_t(YOTAWUPZLoTJ=2{o zl$I7KTV;t0;+D9@_y?dglhI{pJJwe_E)FCmxH3!f(_Yrp7ONYgZ2nYoX9i;u7{`v4ZLzh-oe z_6+zj;PlC}*B!u+Hw?SY3BP9;9`}%ljRd2Jgyx{BUpI6dhS1QYRG{lsoMny?@Qo_r zLFM5Kb!2iW^>>D#e@sL+_hZ=Fi%Gm0I#x97k4P0h_4Sh@7o|EwgwTYK1gBxMI$*Wh z5mq18t(_e`$5^;RqeJd;ZZ|FEU-a(~WuJLx53OVd9OpjfL#bOnn zIN8PO`ZL5nEhGMQRaSD^4QQ%`5y|U>Hldk`>$ttJgiv5gcuMWh`^}d)&z=aci<8q% zKM_{(%wxV8nuOTvNN5&*Z>ZL99ealx(kAlRi5s|cbxBro+UaK;IrEs$_q3w9B3;MX z`45!Jg&Ng=?F9#8Zt5n2gArND3HljFFz+;dB=2cOlMpv^ed`tWkK#282iFKGm5az1 zGV)v~=1{H_<=OBX)5yFJ+pkTBqPZdko&#e)bh!<9P6&SaT6`HFcUIIeJV!QfR4V64 z#W9|F_3B#DCgijaV01XDo{X;?56{a+6Kw1D{+e17!fB`9fF^m&H$$6{Lk0TPRZ|D~ z;@m@A7{3O$Yfwg*D>?1-*TK9--UyQ`NW=WpEw$-mu-P09qB`=$EGm_fOqI*wRyLz* zR#;Yhm`okWfo5zgOz%1wZPj;v{iWz#M8f8mrmlY96Pwuh@&?6HUKw;$`?>2F%%GI;-?uo4AwA0@UditM%t>h-> zi^e%3Tn>+FSFURnjre0l1Yg!DLXh_=Li8l`_W*tZ2i!}YA%PpB00000NkvXXu0mjf Dt;dng literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/tas-icon.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/tas-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..59463a91779bfb5f18ff47a0f8e86d4963902df1 GIT binary patch literal 437 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZM#sNMdu0Z-fiD3KGM@>L&f+azI z!3+)W|1%gk>_6Wxkg$G!!2N<($Gs zb|yP)Du~T}Zm(Rc-ftEZ$D!CF;FKYzG*`3j%hvE;VatkBTjTkDvD(%Ah??KLtm+iM z=k?NK{hrY_k2c?WzWm3Bhlktw?XRC*zHhDmM6P|r|({$dr^|3H6WKr(o``njxgN@xNA+^XEL7Xu|GhaLM1_d z!3_QT84?@>)}R01U~vDv!u)`OXk(vv1_q{so-U3d6^w6h-tXJ2CDQhBBI}9M_3!_u z?O&k1He&WihP3z1U#+u(Cod0Xnfg=Ei9@kP07OJwVNZ%OZ9BInPL^T&F9-iW7xYE! z1iCZAtUhw;2i{&;+w8n-x~Q!E)_6NDIa})m=O6bUn|u6zlj|!s72RVJu|feE4)Yfp zmMmgSU~TYfzazUOdETvZhDY;ab_+LEZT`i`AXc=zkngW!@o#PhmRk%7i=CMow%mMK zo9AlB{W#Tajn(;g*&pujoo9D~Gof&E@Ncd?pE4fUUUoX-{Ym(@B*UHR3%asv{1bwo z@2{U<)*5fLI=ta$=3fqmt0w#6nRl;GQ2(mEj;Hif*D}9X;xSWizn(V#^7bDo-}zr0 z^?#GUO0>iXp0b`Q_i-=4PS?muU_Yul&K*}VNP zudL~s|AF2gm*rnrz4(`$_0nF$({Xy`w>Po+t~_?7EM$pcZQTRUsrN+})YR*IEiv%w zfA#zH`jy;Y|NcAs;ivfS=V$$<`!GCc|E??bx4PbS^OJ+MhbPAWmSW%DI`J>>*~z(@ z>}^|~B-Z}la$i6A=)ctYFDv3y{%<*-<(ZK6{+P@s0{PX%|xwA%#&c8nO zYs2|J2mWp^y6b&s-;_Q0Hf zR{!5@Q+spe!2kb-*=Fzep5&hww8rMYCotHiBSLWczyE9g^FNrrL2{DHd{9zn@O1Ta JS?83{1OWDC%_RT; literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/transcoder-icon.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/transcoder-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..b2a0585aa0aba2257ac8f6fb33c980ed8dc2d941 GIT binary patch literal 774 zcmeAS@N?(olHy`uVBq!ia0vp^^&rf_3?x4$zf}ZMW&u7Su0Z-f>EL7Xu|GhaLM1_d z!3+Wh3=R9=|G&S!;Cw>Bd6DgSn~-tu|#gYwIJb}X-r zQoC~0#s8OQfzPF6JJuSl3|Yy9Tyz5i*h^p8!?OPSm3IM>ZOabter-JI9!e*~{y zX}?f!dGFm>f##9FI75pc&d+eWn)Ranl&AXdS#SRoJ=w}Cb>fWwb9c!FYt!o5!uY)T zW|@CJeAKmXm)MybnX!p8AeJl4su9(-|%Yg#)}Ow~x4GATv9_jJom)Kj>>qn;(zxd{{pu_Eu|OQ z+iSM_|90%`+^@};D|{VDSz*AWcuJo{&9>aEX@-u&UnwU7OnW;eJ0EMJtt=k49ya~970 zDJK=%^ZV#M{_yK*)rX(|zoXy(YeDz)-lx6)_e)ZvK9Ar04yI z(mQ#lzyFkeFTZT6Y4&{YY0d9C-EL7Xu|GhaLM1_d z!3_QT865tenZ0f2ey5e7#LU_JzX3_Dj44!WMl-YWmNb#-^@i6$a>&@ zz3=9GtG+`4HOwt6ho1l5|K{GYFDGns&1bDKQSP<)@3UaWeBNW?$M&4uwYm83MDyEn zZ@P~tM7_9pM`_ma#d~|)PW5MYtvtE!m3+kd{7qlC=JKUVEXm(~;pVxFU6);6q_)=Z zmj7HG&ewCF>*Mur=k9Cv-2QXbUBb?}=*aiRpM7ecN3P%2j4SymR#(p=d%5gi(A$8h zcB7Bi&;8MPJgGQSGs5s0|K1}ZUyF2CDNg=%`L@TOQpLK9eb$%XeVACVSn&LWTi$G! zn40@F7e?2t{`vc4XVqTaRL&oAAMZa?PO+DY-FJS8#g>)roIfU6djFXJC)TuYVx{N5 z&}G(_ME-2+`c-%5dHX8=^15Shj~5*-aj9;w7xR8H{X=$5kYGqn0=G=&EctGpkUuN3 zz5BlZbQKE-D>>*^a(4QC0-2)np4dN{VybR>_ISL^v*csae_AZg z`v-;BNF1_=I&t@r@(WpSN2>$kl1KZGvaIfo*mwB;{O!F9ia7dGAG!1YvplW#`1Z}a z?>;ORUt{qo)4P@>{>cIRut0ORn^n#EpEE?}9*XF9tJ!VyGgno$y18HZ#TCzx>bo=Z ze_ysp@%_I2o&19*XC!TyO3v`hF+bjC`#G_H+K>I-?ZpYg|M{~%sn>s6m~5DSGh)s= z-rbtdtFtXHh{yb$_%m>wX2goC;g;F`?)R0Pqkr)4Gu94~sWDpp%1{1%+TPk~_wZLi z&NI(n_YIAkYQ!)0^>NpEV}trgPczl++Gt?OdNXNSI^UD8lz5lUauVUj->DxbrMSkW@dU}?zZmU2ktG(2je2!e7 z%13kGUCljve6B&v=eKq?sde(-tu>U?Yo44wCT*V(um7WlnQcDP)wrkIPrIe;({b2; z^7tXEXRGfnFMRO&aYyu|YAu8Mhkuvvh!bJ!wav<}iQ#^^A@tGvDz^_0?N8P|yslsK zy|rKY<;R#`duvvO)K8hexc0ev==2%W>{3`h-wyp3yT@MUzsjYnUcJ^c^w%r@fBNU( zQlH)DpW7SPCpWuVoSFV=Z|vOv9=})qkPhGV_;O)q98j$AZCAdryXRN?)lHWUye`o0 zwm&1DoUi}0?{d%of4LVQsg*p4nbIj!1V%Y0T9|QVhtM(c$ z>p8Db6DDUc=~@5OPiN%qCsu7JXjt9;jJf{k@y@JS{HFh3P7^WT_uMf4?FG~NgPlrt zfBhZ#UX)4p<$l`VGUtjP0 f?}mTrX{a{f^*Q5Ea(W|`MRgNrFEz7dCe4ue@ z$(7HKelD$?|9toKI;YQ{{Qf4UrKy%y9Oc(LdA021j9ROf^8VyyPbT8~(LjXLHPVR1)JuAflz z^V8GQ)8|VR2GuHGQu-jw-;p_2%KAdBm(e|%a#=TqPHJ(9#5D}4Xhg}>h3YM)Scxa`Aw z$rZr#ZvdAshun788eqQ>K@!yWiDo?G``{ks++;~3cPQ~nx?U|3vI_$kg zw!2I}m8&oCKXbPKq`e9&)R!du(w7sy5%t3Ikn%N-^@rt>^|TJ@OMIThmzI|H|3?0S X^go|3{B6($CJhEpS3j3^P6Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D1UpGYK~z{r?U>h3 z8$l4p`Nt8xB$(b?z(PVG9ta%?4nh&8JOUCD?S)STnK?Q-imE>w4nlvNpylM`q^PJU--+DZ+}hgO zhldB(UKv3i;t?a{s@~bzDJ(4X`F!78XA72hqku1%F4=tfq~oGTSFs9Kik{eb#--wF@EC- znRo(PS3;C|d3npr%f@>$NK2kdN=llVntFPALZMKU5E4H_LqqlT^&cn1ln(>~w99QW zNK1&)(o$Rj2AUQ)#R#!*P?(VKAOs+^w6uiJ=jUh2WRUjo@Q~4`F9V0{PDrlbogs#7 zb#;~YbiisLLn5SbpPwP-L}zCw-hQS6Hhq14xblz??UZn$B^|KkV(%d#sVJ$Y3G6Ao z%}^wc4cqpus^&r;P37+Hj&`uHu+Z4pC>eBhb&ZdYOJ*Ocsj1PL2i_9me5D<5 zc@iOo;P4t99kn&#U@({sLbOvJ92^i2OifL393gOaQZim_Kei^wK~Y^@%?DubIU!Vn z8l#n0&(VrqmA&VLwzjr(<6(f9$OxQMl&!6;+%#;>@!sAZ^WF0dX%3k?*WBD({G?_M zu>d7=t;=i<;X0m>8V%4ILhI}6351v;w1dUP#e`KhF)<-I<5h-h-3Pe1xn_u6gtHn0 z2(i)0KtpC(7FQzB+uO^`Mc_h0$xRYYwkAOG@IVyoQxn23zydWH;*CL-&IW9_d>qRg zgU!uNGDI(Rq-<_(=57jbNHEC&2Jn-tyRz(469SyW`}_N-@9*#X`}^@lh7G8ae9}(G zwY4>qA-E#k+}zL(=I7^=ZH$kPkNC-8$oS~N!9iJIz_j@7M8vDD<@UpwrC$1ChLSFT zCndv#p!*?~BO@cWCdAH^***kF5_`WL*B!i*hKGkW&OOstpVsCqr#^KlA-pMTH$*dRvei{L+@w-FBi1=={BR?-T0F#rGn07*qoM6N<$ Ef*vt3kN^Mx literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/usp-dns-icon.png b/ecomp-sdk-app/src/main/webapp/app/fusionapp/icons/usp-dns-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..0ba5c5235ad4857ed999c596c47e0a2a52f63d89 GIT binary patch literal 1065 zcmb7@=`))N0LG)b)n!bugSKd_V@hYLj%Bx0Qmu?D%^D%C7-3{fv5T%F=@74Dcd@3F zj=VMx77oSC`Pcrq+lCk!#R>T-ojP)(9Y4`pD zU3T2|#j|uvHTHJbC99)|T*5kX@z0Q)>T&8FdY>XYJ$w)+mi<9HSGR#q^qo)1$;4QS zk*CDn{(<^!oLq2FGP?Bn5D0Y}s3N4AnQ?j6YLuolIy1Y`GpB7f3E%O$nPcX1Ge%yF zj+CoJr#N)xb|D;lL^h^UpehmweR$>4>$tloAp(#2Ykr7eT3ep* zH0{{v$(fPgFYg(NfcPFm5WZl!3I=1uS9gwoY9-4st1;XGEsb)uP>|HR$y`UopTwId z365j4@z|706Sxi}ajWZ9hij0Wc@S=qoteyyLt+%S>VWRU-<)eACRArlItG9|oB~qe zb3ZCoMbJzcE_#)3gQKnl^sg*1*ySWIQ4{f?f6iLGSig}T@~(3jT;qS|P!&f5mG6j& zKD)zlUBWT`V_q@{DCguUD$AS4v9CYyx(8P-+7}5m1_8A$sR}R24WT+mk@g0W#y5*( zkJm?K*~P(NfSQk$+$d(YyP8&;LC_?pw1kPXBJWVvX_HjX>}L|LWO`C&YRImJf3=A) zuLGR3k{y+%m$$4O|;PsbgP@vuVD+^dXv;Y3gLdy@EmC$GsyO-xc zu!Edf6SljDm3Q;Y37!M{2HN}e0!5ZJR2JDbAuDCQpTR+8fkrVZ-;>M+(_R&Pz5pv2 zwNf9Q=ka7d1w8D7DuF=sQRaJ~>XlvbnjQLvEL7Xu|Ghaf+azI z!3_Hi82aBQ2q-k%cbI>EeL+Cq(OY~B3`~nWT^vIy;@%u+1gd0cSnzkH_(~9Km+bDF zg)%Hn410V(Cuhjqe*b@ybb;2fd9KAB(HFh0WFBbm7if!cRc(tmEbVAi-JaXGhQHLt zRmm&bb5X{R?;qs<=|*=Rm~M5a^j2R=bGy5TNo}F}8P*@Zd*;dCnYpQ=qAT!oE$fMH zk2&)%efhTZ$n#hBSN_CQ-ZOrB$8Jre!G(`2119#z)cPGYkNUSb;L6vHP8UCJ+?%rR zssHVHDNpa$t!Q5GbaSqr{LWt%3pz_{bQlzie{4Lm>~Fs7{MK2o&mYL2+_da`PR^@4 z`y-~TyRUaJu68=}>R%n@t+O8JgX=S*KMJCEng#UJ>(S6+)zo0+PY6ZUE5HZ`D%Z;nbuzt?2^oNWC$FDb3r z^T?)Y=he0b7>RORoLi~8KkDV$;|Ds|Mb?gc8YjrNIOtt@(nf*8^7e4 z@^hJt3rrSGgxegAc- zk(^)f**V#fvht}uZSVU&7pzSUt*Np3q0jSg>9ngKk`rZWBF&}*&y5N@djA2p{e|OS zvLaLMmxQ0a1yuN5{%y#!I^ES3|DM!7sNFwp@6~b*<%f^`UR~eR^}YYYPx0l!r|&&$ z|5@{&YsN8t-h$2cXMec)+qwUk8}%*O{`l>M50#5AT5WwJ{;NGt*ZNmGC{&;U^gad5`p=|Oc|U;F SKgA!EEInQQT-G@yGywpJ$GtKD literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/images/dummy.txt b/ecomp-sdk-app/src/main/webapp/app/fusionapp/images/dummy.txt new file mode 100644 index 000000000..e69de29bb diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/scripts/controller/dummy.txt b/ecomp-sdk-app/src/main/webapp/app/fusionapp/scripts/controller/dummy.txt new file mode 100644 index 000000000..e69de29bb diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/scripts/controller/sample-page-controller.js b/ecomp-sdk-app/src/main/webapp/app/fusionapp/scripts/controller/sample-page-controller.js new file mode 100644 index 000000000..0ea98a9c4 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusionapp/scripts/controller/sample-page-controller.js @@ -0,0 +1,80 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +app.controller('samplePageController', function($scope, $http,ProfileService,modalService){ + $scope.tableData=[]; + $scope.viewPerPage=20; + $scope.scrollViewPerPage=2; + $scope.currentPage=1; + $scope.totalPage; + $scope.searchCategory; + $scope.searchString=""; + $scope.currentPageNum=1; + ProfileService.getProfilePagination(1,$scope.viewPerPage).then(function(data){ + var j = data; + $scope.data = JSON.parse(j.data); + $scope.tableData =JSON.parse($scope.data.profileList); + $scope.totalPages =JSON.parse($scope.data.totalPage); + for(x in $scope.tableData){ + if($scope.tableData[x].active_yn=='Y') + $scope.tableData[x].active_yn=true; + else + $scope.tableData[x].active_yn=false; + } + //$scope.resetMenu(); + },function(error){ + console.log("failed"); + reloadPageOnce(); + }); + + $scope.$watch('currentPageNum', function(val) { + + ProfileService.getProfilePagination(val,$scope.viewPerPage).then(function(data){ + var j = data; + $scope.data = JSON.parse(j.data); + $scope.tableData =JSON.parse($scope.data.profileList); + $scope.totalPages =JSON.parse($scope.data.totalPage); + for(x in $scope.tableData){ + if($scope.tableData[x].active_yn=='Y') + $scope.tableData[x].active_yn=true; + else + $scope.tableData[x].active_yn=false; + } + //$scope.resetMenu(); + },function(error){ + console.log("failed"); + }); + + }); + + $scope.editRow = function(profileId){ + window.location = 'userProfile#/profile/' + profileId; + } + + $scope.toggleProfileActive = function(rowData) { + modalService.popupConfirmWinWithCancel("Confirm","You are about to change user's active status. Do you want to continue?", + function(){ + $http.get("profile/toggleProfileActive?profile_id="+rowData.id).success(function(){}); + }, + function(){ + rowData.active=!rowData.active; + }) + }; + +}); diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/scripts/controller/sample-page-iframe-controller.js b/ecomp-sdk-app/src/main/webapp/app/fusionapp/scripts/controller/sample-page-iframe-controller.js new file mode 100644 index 000000000..4ff99cb42 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusionapp/scripts/controller/sample-page-iframe-controller.js @@ -0,0 +1,23 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +app.controller('samplePageWithIframeController', function($scope, $http,ProfileService,modalService){ + + +}); diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/scripts/controller/sampleController.js b/ecomp-sdk-app/src/main/webapp/app/fusionapp/scripts/controller/sampleController.js new file mode 100644 index 000000000..3d3daf5fd --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusionapp/scripts/controller/sampleController.js @@ -0,0 +1,30 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +app.config(function($routeProvider) { + $routeProvider + .when('/iframe', { + templateUrl: 'app/fusionapp/scripts/view-models/sampleWithIframe.html', + controller : "samplePageWithIframeController" + }) + .otherwise({ + templateUrl: 'app/fusionapp/scripts/view-models/sample.html', + controller : "samplePageController" + }); +}); diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/scripts/directives/dummy.txt b/ecomp-sdk-app/src/main/webapp/app/fusionapp/scripts/directives/dummy.txt new file mode 100644 index 000000000..e69de29bb diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/scripts/utils/dummy.txt b/ecomp-sdk-app/src/main/webapp/app/fusionapp/scripts/utils/dummy.txt new file mode 100644 index 000000000..e69de29bb diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/scripts/view-models/dummy.txt b/ecomp-sdk-app/src/main/webapp/app/fusionapp/scripts/view-models/dummy.txt new file mode 100644 index 000000000..e69de29bb diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/scripts/view-models/sample.html b/ecomp-sdk-app/src/main/webapp/app/fusionapp/scripts/view-models/sample.html new file mode 100644 index 000000000..5b555aa47 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusionapp/scripts/view-models/sample.html @@ -0,0 +1,60 @@ + +
      + +

      Profile Search

      + + + + + + + + + + + + + + + + + + + + + + + +
      User IDLast NameFirst NameEmailUser IDManager User ID
      + +
      + Rows Per Page: + +
      +
      + Current Page: + +
      +
      + Total Page(s): + +
      +
      diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/scripts/view-models/sampleWithIframe.html b/ecomp-sdk-app/src/main/webapp/app/fusionapp/scripts/view-models/sampleWithIframe.html new file mode 100644 index 000000000..612e6a8c4 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusionapp/scripts/view-models/sampleWithIframe.html @@ -0,0 +1,22 @@ + +
      + +
      diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/scripts/view-models/singlePageSample.html b/ecomp-sdk-app/src/main/webapp/app/fusionapp/scripts/view-models/singlePageSample.html new file mode 100644 index 000000000..7bded9d61 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/fusionapp/scripts/view-models/singlePageSample.html @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      +
      +
      +
      +
      +
      + + diff --git a/ecomp-sdk-app/src/main/webapp/app/fusionapp/styles/dummy.txt b/ecomp-sdk-app/src/main/webapp/app/fusionapp/styles/dummy.txt new file mode 100644 index 000000000..e69de29bb diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/CSS/Notification/angular-csp.css b/ecomp-sdk-app/src/main/webapp/app/policyApp/CSS/Notification/angular-csp.css new file mode 100644 index 000000000..7d724742d --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/CSS/Notification/angular-csp.css @@ -0,0 +1,22 @@ +/* Include this file in your html if you are using the CSP mode. */ + +[ng\:cloak], [ng-cloak], [data-ng-cloak], [x-ng-cloak], +.ng-cloak, .x-ng-cloak, +.ng-hide { + display: none !important; +} + +ng\:form { + display: block; +} + +.ng-animate-block-transitions { + transition:0s all!important; + -webkit-transition:0s all!important; +} + +/* show the element during a show/hide animation when the + * animation is ongoing, but the .ng-hide class is active */ +.ng-hide-add-active, .ng-hide-remove { + display: block!important; +} diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/CSS/Notification/angular-ui-notification.min.css b/ecomp-sdk-app/src/main/webapp/app/policyApp/CSS/Notification/angular-ui-notification.min.css new file mode 100644 index 000000000..5417bb40c --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/CSS/Notification/angular-ui-notification.min.css @@ -0,0 +1 @@ +.ui-notification{position:fixed;z-index:9999;top:-100px;right:10px;width:300px;cursor:pointer;-webkit-transition:all ease .5s;-o-transition:all ease .5s;transition:all ease .5s;color:#fff;background:#428bca;box-shadow:5px 5px 10px rgba(0,0,0,.3)}.ui-notification.killed{-webkit-transition:opacity ease 1s;-o-transition:opacity ease 1s;transition:opacity ease 1s;opacity:0}.ui-notification>h3{font-size:14px;font-weight:700;display:block;margin:10px 10px 0;padding:0 0 5px;text-align:left;border-bottom:1px solid rgba(255,255,255,.3)}.ui-notification a{color:#fff}.ui-notification a:hover{text-decoration:underline}.ui-notification>.message{margin:10px}.ui-notification.warning{color:#fff;background:#f0ad4e}.ui-notification.error{color:#fff;background:#d9534f}.ui-notification.success{color:#fff;background:#5cb85c}.ui-notification.info{color:#fff;background:#5bc0de}.ui-notification:hover{opacity:.7} \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/CSS/Notification/angular-ui-notification.min.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/CSS/Notification/angular-ui-notification.min.js new file mode 100644 index 000000000..e9bcb4ccd --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/CSS/Notification/angular-ui-notification.min.js @@ -0,0 +1 @@ +angular.module("ui-notification",[]),angular.module("ui-notification").value("uiNotificationTemplates","angular-ui-notification.html"),angular.module("ui-notification").factory("Notification",["$timeout","uiNotificationTemplates","$http","$compile","$templateCache","$rootScope","$injector","$sce",function(t,e,i,n,a,o,s,c){var r=10,l=10,u=10,p=10,d=5e3,f=[],m=function(s,m){"object"!=typeof s&&(s={message:s}),s.template=s.template?s.template:e,s.delay=angular.isUndefined(s.delay)?d:s.delay,s.type=m?m:"",i.get(s.template,{cache:a}).success(function(e){var i=o.$new();if(i.message=c.trustAsHtml(s.message),i.title=c.trustAsHtml(s.title),i.t=s.type.substr(0,1),i.delay=s.delay,"object"==typeof s.scope)for(var a in s.scope)i[a]=s.scope[a];var d=function(){for(var t=0,e=0,i=r,n=f.length-1;n>=0;n--){var a=f[n],o=parseInt(a[0].offsetHeight),s=parseInt(a[0].offsetWidth);c+o>window.innerHeight&&(i=r,e++,t=0);var c=i+(0===t?0:u),d=l+e*(p+s);a.css("top",c+"px"),a.css("right",d+"px"),i=c+o,t++}},m=n(e)(i);m.addClass(s.type),m.bind("webkitTransitionEnd oTransitionEnd otransitionend transitionend msTransitionEnd click",function(t){("click"===t.type||"opacity"===t.propertyName&&t.elapsedTime>=1)&&(m.remove(),f.splice(f.indexOf(m),1),d())}),t(function(){m.addClass("killed")},s.delay),angular.element(document.getElementsByTagName("body")).append(m),f.push(m),t(d)}).error(function(t){throw new Error("Template ("+s.template+") could not be loaded. "+t)})};return m.config=function(t){r=t.top?t.top:r,u=t.verticalSpacing?t.verticalSpacing:u},m.primary=function(){this(args,"")},m.error=function(t){this(t,"error")},m.success=function(t){this(t,"success")},m.info=function(t){this(t,"info")},m.warning=function(t){this(t,"warning")},m}]),angular.module("ui-notification").run(["$templateCache",function(t){t.put("angular-ui-notification.html",'

      ')}]); \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/CSS/bootstrap.min.css b/ecomp-sdk-app/src/main/webapp/app/policyApp/CSS/bootstrap.min.css new file mode 100644 index 000000000..cd1c616ad --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/CSS/bootstrap.min.css @@ -0,0 +1,5 @@ +/*! + * Bootstrap v3.3.4 (http://getbootstrap.com) + * Copyright 2011-2015 Twitter, Inc. + * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) + *//*! normalize.css v3.0.2 | MIT License | git.io/normalize */html{font-family:sans-serif;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%}body{margin:0}article,aside,details,figcaption,figure,footer,header,hgroup,main,menu,nav,section,summary{display:block}audio,canvas,progress,video{display:inline-block;vertical-align:baseline}audio:not([controls]){display:none;height:0}[hidden],template{display:none}a{background-color:transparent}a:active,a:hover{outline:0}abbr[title]{border-bottom:1px dotted}b,strong{font-weight:700}dfn{font-style:italic}h1{margin:.67em 0;font-size:2em}mark{color:#000;background:#ff0}small{font-size:80%}sub,sup{position:relative;font-size:75%;line-height:0;vertical-align:baseline}sup{top:-.5em}sub{bottom:-.25em}img{border:0}svg:not(:root){overflow:hidden}figure{margin:1em 40px}hr{height:0;-webkit-box-sizing:content-box;-moz-box-sizing:content-box;box-sizing:content-box}pre{overflow:auto}code,kbd,pre,samp{font-family:monospace,monospace;font-size:1em}button,input,optgroup,select,textarea{margin:0;font:inherit;color:inherit}button{overflow:visible}button,select{text-transform:none}button,html input[type=button],input[type=reset],input[type=submit]{-webkit-appearance:button;cursor:pointer}button[disabled],html input[disabled]{cursor:default}button::-moz-focus-inner,input::-moz-focus-inner{padding:0;border:0}input{line-height:normal}input[type=checkbox],input[type=radio]{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;padding:0}input[type=number]::-webkit-inner-spin-button,input[type=number]::-webkit-outer-spin-button{height:auto}input[type=search]{-webkit-box-sizing:content-box;-moz-box-sizing:content-box;box-sizing:content-box;-webkit-appearance:textfield}input[type=search]::-webkit-search-cancel-button,input[type=search]::-webkit-search-decoration{-webkit-appearance:none}fieldset{padding:.35em .625em .75em;margin:0 2px;border:1px solid silver}legend{padding:0;border:0}textarea{overflow:auto}optgroup{font-weight:700}table{border-spacing:0;border-collapse:collapse}td,th{padding:0}/*! Source: https://github.com/h5bp/html5-boilerplate/blob/master/src/css/main.css */@media print{*,:after,:before{color:#000!important;text-shadow:none!important;background:0 0!important;-webkit-box-shadow:none!important;box-shadow:none!important}a,a:visited{text-decoration:underline}a[href]:after{content:" (" attr(href) ")"}abbr[title]:after{content:" (" attr(title) ")"}a[href^="javascript:"]:after,a[href^="#"]:after{content:""}blockquote,pre{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}img,tr{page-break-inside:avoid}img{max-width:100%!important}h2,h3,p{orphans:3;widows:3}h2,h3{page-break-after:avoid}select{background:#fff!important}.navbar{display:none}.btn>.caret,.dropup>.btn>.caret{border-top-color:#000!important}.label{border:1px solid #000}.table{border-collapse:collapse!important}.table td,.table th{background-color:#fff!important}.table-bordered td,.table-bordered th{border:1px solid #ddd!important}}@font-face{font-family:'Glyphicons Halflings';src:url(../fonts/glyphicons-halflings-regular.eot);src:url(../fonts/glyphicons-halflings-regular.eot?#iefix) format('embedded-opentype'),url(../fonts/glyphicons-halflings-regular.woff2) format('woff2'),url(../fonts/glyphicons-halflings-regular.woff) format('woff'),url(../fonts/glyphicons-halflings-regular.ttf) format('truetype'),url(../fonts/glyphicons-halflings-regular.svg#glyphicons_halflingsregular) format('svg')}.glyphicon{position:relative;top:1px;display:inline-block;font-family:'Glyphicons Halflings';font-style:normal;font-weight:400;line-height:1;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.glyphicon-asterisk:before{content:"\2a"}.glyphicon-plus:before{content:"\2b"}.glyphicon-eur:before,.glyphicon-euro:before{content:"\20ac"}.glyphicon-minus:before{content:"\2212"}.glyphicon-cloud:before{content:"\2601"}.glyphicon-envelope:before{content:"\2709"}.glyphicon-pencil:before{content:"\270f"}.glyphicon-glass:before{content:"\e001"}.glyphicon-music:before{content:"\e002"}.glyphicon-search:before{content:"\e003"}.glyphicon-heart:before{content:"\e005"}.glyphicon-star:before{content:"\e006"}.glyphicon-star-empty:before{content:"\e007"}.glyphicon-user:before{content:"\e008"}.glyphicon-film:before{content:"\e009"}.glyphicon-th-large:before{content:"\e010"}.glyphicon-th:before{content:"\e011"}.glyphicon-th-list:before{content:"\e012"}.glyphicon-ok:before{content:"\e013"}.glyphicon-remove:before{content:"\e014"}.glyphicon-zoom-in:before{content:"\e015"}.glyphicon-zoom-out:before{content:"\e016"}.glyphicon-off:before{content:"\e017"}.glyphicon-signal:before{content:"\e018"}.glyphicon-cog:before{content:"\e019"}.glyphicon-trash:before{content:"\e020"}.glyphicon-home:before{content:"\e021"}.glyphicon-file:before{content:"\e022"}.glyphicon-time:before{content:"\e023"}.glyphicon-road:before{content:"\e024"}.glyphicon-download-alt:before{content:"\e025"}.glyphicon-download:before{content:"\e026"}.glyphicon-upload:before{content:"\e027"}.glyphicon-inbox:before{content:"\e028"}.glyphicon-play-circle:before{content:"\e029"}.glyphicon-repeat:before{content:"\e030"}.glyphicon-refresh:before{content:"\e031"}.glyphicon-list-alt:before{content:"\e032"}.glyphicon-lock:before{content:"\e033"}.glyphicon-flag:before{content:"\e034"}.glyphicon-headphones:before{content:"\e035"}.glyphicon-volume-off:before{content:"\e036"}.glyphicon-volume-down:before{content:"\e037"}.glyphicon-volume-up:before{content:"\e038"}.glyphicon-qrcode:before{content:"\e039"}.glyphicon-barcode:before{content:"\e040"}.glyphicon-tag:before{content:"\e041"}.glyphicon-tags:before{content:"\e042"}.glyphicon-book:before{content:"\e043"}.glyphicon-bookmark:before{content:"\e044"}.glyphicon-print:before{content:"\e045"}.glyphicon-camera:before{content:"\e046"}.glyphicon-font:before{content:"\e047"}.glyphicon-bold:before{content:"\e048"}.glyphicon-italic:before{content:"\e049"}.glyphicon-text-height:before{content:"\e050"}.glyphicon-text-width:before{content:"\e051"}.glyphicon-align-left:before{content:"\e052"}.glyphicon-align-center:before{content:"\e053"}.glyphicon-align-right:before{content:"\e054"}.glyphicon-align-justify:before{content:"\e055"}.glyphicon-list:before{content:"\e056"}.glyphicon-indent-left:before{content:"\e057"}.glyphicon-indent-right:before{content:"\e058"}.glyphicon-facetime-video:before{content:"\e059"}.glyphicon-picture:before{content:"\e060"}.glyphicon-map-marker:before{content:"\e062"}.glyphicon-adjust:before{content:"\e063"}.glyphicon-tint:before{content:"\e064"}.glyphicon-edit:before{content:"\e065"}.glyphicon-share:before{content:"\e066"}.glyphicon-check:before{content:"\e067"}.glyphicon-move:before{content:"\e068"}.glyphicon-step-backward:before{content:"\e069"}.glyphicon-fast-backward:before{content:"\e070"}.glyphicon-backward:before{content:"\e071"}.glyphicon-play:before{content:"\e072"}.glyphicon-pause:before{content:"\e073"}.glyphicon-stop:before{content:"\e074"}.glyphicon-forward:before{content:"\e075"}.glyphicon-fast-forward:before{content:"\e076"}.glyphicon-step-forward:before{content:"\e077"}.glyphicon-eject:before{content:"\e078"}.glyphicon-chevron-left:before{content:"\e079"}.glyphicon-chevron-right:before{content:"\e080"}.glyphicon-plus-sign:before{content:"\e081"}.glyphicon-minus-sign:before{content:"\e082"}.glyphicon-remove-sign:before{content:"\e083"}.glyphicon-ok-sign:before{content:"\e084"}.glyphicon-question-sign:before{content:"\e085"}.glyphicon-info-sign:before{content:"\e086"}.glyphicon-screenshot:before{content:"\e087"}.glyphicon-remove-circle:before{content:"\e088"}.glyphicon-ok-circle:before{content:"\e089"}.glyphicon-ban-circle:before{content:"\e090"}.glyphicon-arrow-left:before{content:"\e091"}.glyphicon-arrow-right:before{content:"\e092"}.glyphicon-arrow-up:before{content:"\e093"}.glyphicon-arrow-down:before{content:"\e094"}.glyphicon-share-alt:before{content:"\e095"}.glyphicon-resize-full:before{content:"\e096"}.glyphicon-resize-small:before{content:"\e097"}.glyphicon-exclamation-sign:before{content:"\e101"}.glyphicon-gift:before{content:"\e102"}.glyphicon-leaf:before{content:"\e103"}.glyphicon-fire:before{content:"\e104"}.glyphicon-eye-open:before{content:"\e105"}.glyphicon-eye-close:before{content:"\e106"}.glyphicon-warning-sign:before{content:"\e107"}.glyphicon-plane:before{content:"\e108"}.glyphicon-calendar:before{content:"\e109"}.glyphicon-random:before{content:"\e110"}.glyphicon-comment:before{content:"\e111"}.glyphicon-magnet:before{content:"\e112"}.glyphicon-chevron-up:before{content:"\e113"}.glyphicon-chevron-down:before{content:"\e114"}.glyphicon-retweet:before{content:"\e115"}.glyphicon-shopping-cart:before{content:"\e116"}.glyphicon-folder-close:before{content:"\e117"}.glyphicon-folder-open:before{content:"\e118"}.glyphicon-resize-vertical:before{content:"\e119"}.glyphicon-resize-horizontal:before{content:"\e120"}.glyphicon-hdd:before{content:"\e121"}.glyphicon-bullhorn:before{content:"\e122"}.glyphicon-bell:before{content:"\e123"}.glyphicon-certificate:before{content:"\e124"}.glyphicon-thumbs-up:before{content:"\e125"}.glyphicon-thumbs-down:before{content:"\e126"}.glyphicon-hand-right:before{content:"\e127"}.glyphicon-hand-left:before{content:"\e128"}.glyphicon-hand-up:before{content:"\e129"}.glyphicon-hand-down:before{content:"\e130"}.glyphicon-circle-arrow-right:before{content:"\e131"}.glyphicon-circle-arrow-left:before{content:"\e132"}.glyphicon-circle-arrow-up:before{content:"\e133"}.glyphicon-circle-arrow-down:before{content:"\e134"}.glyphicon-globe:before{content:"\e135"}.glyphicon-wrench:before{content:"\e136"}.glyphicon-tasks:before{content:"\e137"}.glyphicon-filter:before{content:"\e138"}.glyphicon-briefcase:before{content:"\e139"}.glyphicon-fullscreen:before{content:"\e140"}.glyphicon-dashboard:before{content:"\e141"}.glyphicon-paperclip:before{content:"\e142"}.glyphicon-heart-empty:before{content:"\e143"}.glyphicon-link:before{content:"\e144"}.glyphicon-phone:before{content:"\e145"}.glyphicon-pushpin:before{content:"\e146"}.glyphicon-usd:before{content:"\e148"}.glyphicon-gbp:before{content:"\e149"}.glyphicon-sort:before{content:"\e150"}.glyphicon-sort-by-alphabet:before{content:"\e151"}.glyphicon-sort-by-alphabet-alt:before{content:"\e152"}.glyphicon-sort-by-order:before{content:"\e153"}.glyphicon-sort-by-order-alt:before{content:"\e154"}.glyphicon-sort-by-attributes:before{content:"\e155"}.glyphicon-sort-by-attributes-alt:before{content:"\e156"}.glyphicon-unchecked:before{content:"\e157"}.glyphicon-expand:before{content:"\e158"}.glyphicon-collapse-down:before{content:"\e159"}.glyphicon-collapse-up:before{content:"\e160"}.glyphicon-log-in:before{content:"\e161"}.glyphicon-flash:before{content:"\e162"}.glyphicon-log-out:before{content:"\e163"}.glyphicon-new-window:before{content:"\e164"}.glyphicon-record:before{content:"\e165"}.glyphicon-save:before{content:"\e166"}.glyphicon-open:before{content:"\e167"}.glyphicon-saved:before{content:"\e168"}.glyphicon-import:before{content:"\e169"}.glyphicon-export:before{content:"\e170"}.glyphicon-send:before{content:"\e171"}.glyphicon-floppy-disk:before{content:"\e172"}.glyphicon-floppy-saved:before{content:"\e173"}.glyphicon-floppy-remove:before{content:"\e174"}.glyphicon-floppy-save:before{content:"\e175"}.glyphicon-floppy-open:before{content:"\e176"}.glyphicon-credit-card:before{content:"\e177"}.glyphicon-transfer:before{content:"\e178"}.glyphicon-cutlery:before{content:"\e179"}.glyphicon-header:before{content:"\e180"}.glyphicon-compressed:before{content:"\e181"}.glyphicon-earphone:before{content:"\e182"}.glyphicon-phone-alt:before{content:"\e183"}.glyphicon-tower:before{content:"\e184"}.glyphicon-stats:before{content:"\e185"}.glyphicon-sd-video:before{content:"\e186"}.glyphicon-hd-video:before{content:"\e187"}.glyphicon-subtitles:before{content:"\e188"}.glyphicon-sound-stereo:before{content:"\e189"}.glyphicon-sound-dolby:before{content:"\e190"}.glyphicon-sound-5-1:before{content:"\e191"}.glyphicon-sound-6-1:before{content:"\e192"}.glyphicon-sound-7-1:before{content:"\e193"}.glyphicon-copyright-mark:before{content:"\e194"}.glyphicon-registration-mark:before{content:"\e195"}.glyphicon-cloud-download:before{content:"\e197"}.glyphicon-cloud-upload:before{content:"\e198"}.glyphicon-tree-conifer:before{content:"\e199"}.glyphicon-tree-deciduous:before{content:"\e200"}.glyphicon-cd:before{content:"\e201"}.glyphicon-save-file:before{content:"\e202"}.glyphicon-open-file:before{content:"\e203"}.glyphicon-level-up:before{content:"\e204"}.glyphicon-copy:before{content:"\e205"}.glyphicon-paste:before{content:"\e206"}.glyphicon-alert:before{content:"\e209"}.glyphicon-equalizer:before{content:"\e210"}.glyphicon-king:before{content:"\e211"}.glyphicon-queen:before{content:"\e212"}.glyphicon-pawn:before{content:"\e213"}.glyphicon-bishop:before{content:"\e214"}.glyphicon-knight:before{content:"\e215"}.glyphicon-baby-formula:before{content:"\e216"}.glyphicon-tent:before{content:"\26fa"}.glyphicon-blackboard:before{content:"\e218"}.glyphicon-bed:before{content:"\e219"}.glyphicon-apple:before{content:"\f8ff"}.glyphicon-erase:before{content:"\e221"}.glyphicon-hourglass:before{content:"\231b"}.glyphicon-lamp:before{content:"\e223"}.glyphicon-duplicate:before{content:"\e224"}.glyphicon-piggy-bank:before{content:"\e225"}.glyphicon-scissors:before{content:"\e226"}.glyphicon-bitcoin:before{content:"\e227"}.glyphicon-btc:before{content:"\e227"}.glyphicon-xbt:before{content:"\e227"}.glyphicon-yen:before{content:"\00a5"}.glyphicon-jpy:before{content:"\00a5"}.glyphicon-ruble:before{content:"\20bd"}.glyphicon-rub:before{content:"\20bd"}.glyphicon-scale:before{content:"\e230"}.glyphicon-ice-lolly:before{content:"\e231"}.glyphicon-ice-lolly-tasted:before{content:"\e232"}.glyphicon-education:before{content:"\e233"}.glyphicon-option-horizontal:before{content:"\e234"}.glyphicon-option-vertical:before{content:"\e235"}.glyphicon-menu-hamburger:before{content:"\e236"}.glyphicon-modal-window:before{content:"\e237"}.glyphicon-oil:before{content:"\e238"}.glyphicon-grain:before{content:"\e239"}.glyphicon-sunglasses:before{content:"\e240"}.glyphicon-text-size:before{content:"\e241"}.glyphicon-text-color:before{content:"\e242"}.glyphicon-text-background:before{content:"\e243"}.glyphicon-object-align-top:before{content:"\e244"}.glyphicon-object-align-bottom:before{content:"\e245"}.glyphicon-object-align-horizontal:before{content:"\e246"}.glyphicon-object-align-left:before{content:"\e247"}.glyphicon-object-align-vertical:before{content:"\e248"}.glyphicon-object-align-right:before{content:"\e249"}.glyphicon-triangle-right:before{content:"\e250"}.glyphicon-triangle-left:before{content:"\e251"}.glyphicon-triangle-bottom:before{content:"\e252"}.glyphicon-triangle-top:before{content:"\e253"}.glyphicon-console:before{content:"\e254"}.glyphicon-superscript:before{content:"\e255"}.glyphicon-subscript:before{content:"\e256"}.glyphicon-menu-left:before{content:"\e257"}.glyphicon-menu-right:before{content:"\e258"}.glyphicon-menu-down:before{content:"\e259"}.glyphicon-menu-up:before{content:"\e260"}*{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}:after,:before{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}html{font-size:10px;-webkit-tap-highlight-color:rgba(0,0,0,0)}body{font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:14px;line-height:1.42857143;color:#333;background-color:#fff}button,input,select,textarea{font-family:inherit;font-size:inherit;line-height:inherit}a{color:#337ab7;text-decoration:none}a:focus,a:hover{color:#23527c;text-decoration:underline}a:focus{outline:thin dotted;outline:5px auto -webkit-focus-ring-color;outline-offset:-2px}figure{margin:0}img{vertical-align:middle}.carousel-inner>.item>a>img,.carousel-inner>.item>img,.img-responsive,.thumbnail a>img,.thumbnail>img{display:block;max-width:100%;height:auto}.img-rounded{border-radius:6px}.img-thumbnail{display:inline-block;max-width:100%;height:auto;padding:4px;line-height:1.42857143;background-color:#fff;border:1px solid #ddd;border-radius:4px;-webkit-transition:all .2s ease-in-out;-o-transition:all .2s ease-in-out;transition:all .2s ease-in-out}.img-circle{border-radius:50%}hr{margin-top:20px;margin-bottom:20px;border:0;border-top:1px solid #eee}.sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);border:0}.sr-only-focusable:active,.sr-only-focusable:focus{position:static;width:auto;height:auto;margin:0;overflow:visible;clip:auto}[role=button]{cursor:pointer}.h1,.h2,.h3,.h4,.h5,.h6,h1,h2,h3,h4,h5,h6{font-family:inherit;font-weight:500;line-height:1.1;color:inherit}.h1 .small,.h1 small,.h2 .small,.h2 small,.h3 .small,.h3 small,.h4 .small,.h4 small,.h5 .small,.h5 small,.h6 .small,.h6 small,h1 .small,h1 small,h2 .small,h2 small,h3 .small,h3 small,h4 .small,h4 small,h5 .small,h5 small,h6 .small,h6 small{font-weight:400;line-height:1;color:#777}.h1,.h2,.h3,h1,h2,h3{margin-top:20px;margin-bottom:10px}.h1 .small,.h1 small,.h2 .small,.h2 small,.h3 .small,.h3 small,h1 .small,h1 small,h2 .small,h2 small,h3 .small,h3 small{font-size:65%}.h4,.h5,.h6,h4,h5,h6{margin-top:10px;margin-bottom:10px}.h4 .small,.h4 small,.h5 .small,.h5 small,.h6 .small,.h6 small,h4 .small,h4 small,h5 .small,h5 small,h6 .small,h6 small{font-size:75%}.h1,h1{font-size:36px}.h2,h2{font-size:30px}.h3,h3{font-size:24px}.h4,h4{font-size:18px}.h5,h5{font-size:14px}.h6,h6{font-size:12px}p{margin:0 0 10px}.lead{margin-bottom:20px;font-size:16px;font-weight:300;line-height:1.4}@media (min-width:768px){.lead{font-size:21px}}.small,small{font-size:85%}.mark,mark{padding:.2em;background-color:#fcf8e3}.text-left{text-align:left}.text-right{text-align:right}.text-center{text-align:center}.text-justify{text-align:justify}.text-nowrap{white-space:nowrap}.text-lowercase{text-transform:lowercase}.text-uppercase{text-transform:uppercase}.text-capitalize{text-transform:capitalize}.text-muted{color:#777}.text-primary{color:#337ab7}a.text-primary:hover{color:#286090}.text-success{color:#3c763d}a.text-success:hover{color:#2b542c}.text-info{color:#31708f}a.text-info:hover{color:#245269}.text-warning{color:#8a6d3b}a.text-warning:hover{color:#66512c}.text-danger{color:#a94442}a.text-danger:hover{color:#843534}.bg-primary{color:#fff;background-color:#337ab7}a.bg-primary:hover{background-color:#286090}.bg-success{background-color:#dff0d8}a.bg-success:hover{background-color:#c1e2b3}.bg-info{background-color:#d9edf7}a.bg-info:hover{background-color:#afd9ee}.bg-warning{background-color:#fcf8e3}a.bg-warning:hover{background-color:#f7ecb5}.bg-danger{background-color:#f2dede}a.bg-danger:hover{background-color:#e4b9b9}.page-header{padding-bottom:9px;margin:40px 0 20px;border-bottom:1px solid #eee}ol,ul{margin-top:0;margin-bottom:10px}ol ol,ol ul,ul ol,ul ul{margin-bottom:0}.list-unstyled{padding-left:0;list-style:none}.list-inline{padding-left:0;margin-left:-5px;list-style:none}.list-inline>li{display:inline-block;padding-right:5px;padding-left:5px}dl{margin-top:0;margin-bottom:20px}dd,dt{line-height:1.42857143}dt{font-weight:700}dd{margin-left:0}@media (min-width:768px){.dl-horizontal dt{float:left;width:160px;overflow:hidden;clear:left;text-align:right;text-overflow:ellipsis;white-space:nowrap}.dl-horizontal dd{margin-left:180px}}abbr[data-original-title],abbr[title]{cursor:help;border-bottom:1px dotted #777}.initialism{font-size:90%;text-transform:uppercase}blockquote{padding:10px 20px;margin:0 0 20px;font-size:17.5px;border-left:5px solid #eee}blockquote ol:last-child,blockquote p:last-child,blockquote ul:last-child{margin-bottom:0}blockquote .small,blockquote footer,blockquote small{display:block;font-size:80%;line-height:1.42857143;color:#777}blockquote .small:before,blockquote footer:before,blockquote small:before{content:'\2014 \00A0'}.blockquote-reverse,blockquote.pull-right{padding-right:15px;padding-left:0;text-align:right;border-right:5px solid #eee;border-left:0}.blockquote-reverse .small:before,.blockquote-reverse footer:before,.blockquote-reverse small:before,blockquote.pull-right .small:before,blockquote.pull-right footer:before,blockquote.pull-right small:before{content:''}.blockquote-reverse .small:after,.blockquote-reverse footer:after,.blockquote-reverse small:after,blockquote.pull-right .small:after,blockquote.pull-right footer:after,blockquote.pull-right small:after{content:'\00A0 \2014'}address{margin-bottom:20px;font-style:normal;line-height:1.42857143}code,kbd,pre,samp{font-family:Menlo,Monaco,Consolas,"Courier New",monospace}code{padding:2px 4px;font-size:90%;color:#c7254e;background-color:#f9f2f4;border-radius:4px}kbd{padding:2px 4px;font-size:90%;color:#fff;background-color:#333;border-radius:3px;-webkit-box-shadow:inset 0 -1px 0 rgba(0,0,0,.25);box-shadow:inset 0 -1px 0 rgba(0,0,0,.25)}kbd kbd{padding:0;font-size:100%;font-weight:700;-webkit-box-shadow:none;box-shadow:none}pre{display:block;padding:9.5px;margin:0 0 10px;font-size:13px;line-height:1.42857143;color:#333;word-break:break-all;word-wrap:break-word;background-color:#f5f5f5;border:1px solid #ccc;border-radius:4px}pre code{padding:0;font-size:inherit;color:inherit;white-space:pre-wrap;background-color:transparent;border-radius:0}.pre-scrollable{max-height:340px;overflow-y:scroll}.container{padding-right:15px;padding-left:15px;margin-right:auto;margin-left:auto}@media (min-width:768px){.container{width:750px}}@media (min-width:992px){.container{width:970px}}@media (min-width:1200px){.container{width:1170px}}.container-fluid{padding-right:15px;padding-left:15px;margin-right:auto;margin-left:auto}.row{margin-right:-15px;margin-left:-15px}.col-lg-1,.col-lg-10,.col-lg-11,.col-lg-12,.col-lg-2,.col-lg-3,.col-lg-4,.col-lg-5,.col-lg-6,.col-lg-7,.col-lg-8,.col-lg-9,.col-md-1,.col-md-10,.col-md-11,.col-md-12,.col-md-2,.col-md-3,.col-md-4,.col-md-5,.col-md-6,.col-md-7,.col-md-8,.col-md-9,.col-sm-1,.col-sm-10,.col-sm-11,.col-sm-12,.col-sm-2,.col-sm-3,.col-sm-4,.col-sm-5,.col-sm-6,.col-sm-7,.col-sm-8,.col-sm-9,.col-xs-1,.col-xs-10,.col-xs-11,.col-xs-12,.col-xs-2,.col-xs-3,.col-xs-4,.col-xs-5,.col-xs-6,.col-xs-7,.col-xs-8,.col-xs-9{position:relative;min-height:1px;padding-right:15px;padding-left:15px}.col-xs-1,.col-xs-10,.col-xs-11,.col-xs-12,.col-xs-2,.col-xs-3,.col-xs-4,.col-xs-5,.col-xs-6,.col-xs-7,.col-xs-8,.col-xs-9{float:left}.col-xs-12{width:100%}.col-xs-11{width:91.66666667%}.col-xs-10{width:83.33333333%}.col-xs-9{width:75%}.col-xs-8{width:66.66666667%}.col-xs-7{width:58.33333333%}.col-xs-6{width:50%}.col-xs-5{width:41.66666667%}.col-xs-4{width:33.33333333%}.col-xs-3{width:25%}.col-xs-2{width:16.66666667%}.col-xs-1{width:8.33333333%}.col-xs-pull-12{right:100%}.col-xs-pull-11{right:91.66666667%}.col-xs-pull-10{right:83.33333333%}.col-xs-pull-9{right:75%}.col-xs-pull-8{right:66.66666667%}.col-xs-pull-7{right:58.33333333%}.col-xs-pull-6{right:50%}.col-xs-pull-5{right:41.66666667%}.col-xs-pull-4{right:33.33333333%}.col-xs-pull-3{right:25%}.col-xs-pull-2{right:16.66666667%}.col-xs-pull-1{right:8.33333333%}.col-xs-pull-0{right:auto}.col-xs-push-12{left:100%}.col-xs-push-11{left:91.66666667%}.col-xs-push-10{left:83.33333333%}.col-xs-push-9{left:75%}.col-xs-push-8{left:66.66666667%}.col-xs-push-7{left:58.33333333%}.col-xs-push-6{left:50%}.col-xs-push-5{left:41.66666667%}.col-xs-push-4{left:33.33333333%}.col-xs-push-3{left:25%}.col-xs-push-2{left:16.66666667%}.col-xs-push-1{left:8.33333333%}.col-xs-push-0{left:auto}.col-xs-offset-12{margin-left:100%}.col-xs-offset-11{margin-left:91.66666667%}.col-xs-offset-10{margin-left:83.33333333%}.col-xs-offset-9{margin-left:75%}.col-xs-offset-8{margin-left:66.66666667%}.col-xs-offset-7{margin-left:58.33333333%}.col-xs-offset-6{margin-left:50%}.col-xs-offset-5{margin-left:41.66666667%}.col-xs-offset-4{margin-left:33.33333333%}.col-xs-offset-3{margin-left:25%}.col-xs-offset-2{margin-left:16.66666667%}.col-xs-offset-1{margin-left:8.33333333%}.col-xs-offset-0{margin-left:0}@media (min-width:768px){.col-sm-1,.col-sm-10,.col-sm-11,.col-sm-12,.col-sm-2,.col-sm-3,.col-sm-4,.col-sm-5,.col-sm-6,.col-sm-7,.col-sm-8,.col-sm-9{float:left}.col-sm-12{width:100%}.col-sm-11{width:91.66666667%}.col-sm-10{width:83.33333333%}.col-sm-9{width:75%}.col-sm-8{width:66.66666667%}.col-sm-7{width:58.33333333%}.col-sm-6{width:50%}.col-sm-5{width:41.66666667%}.col-sm-4{width:33.33333333%}.col-sm-3{width:25%}.col-sm-2{width:16.66666667%}.col-sm-1{width:8.33333333%}.col-sm-pull-12{right:100%}.col-sm-pull-11{right:91.66666667%}.col-sm-pull-10{right:83.33333333%}.col-sm-pull-9{right:75%}.col-sm-pull-8{right:66.66666667%}.col-sm-pull-7{right:58.33333333%}.col-sm-pull-6{right:50%}.col-sm-pull-5{right:41.66666667%}.col-sm-pull-4{right:33.33333333%}.col-sm-pull-3{right:25%}.col-sm-pull-2{right:16.66666667%}.col-sm-pull-1{right:8.33333333%}.col-sm-pull-0{right:auto}.col-sm-push-12{left:100%}.col-sm-push-11{left:91.66666667%}.col-sm-push-10{left:83.33333333%}.col-sm-push-9{left:75%}.col-sm-push-8{left:66.66666667%}.col-sm-push-7{left:58.33333333%}.col-sm-push-6{left:50%}.col-sm-push-5{left:41.66666667%}.col-sm-push-4{left:33.33333333%}.col-sm-push-3{left:25%}.col-sm-push-2{left:16.66666667%}.col-sm-push-1{left:8.33333333%}.col-sm-push-0{left:auto}.col-sm-offset-12{margin-left:100%}.col-sm-offset-11{margin-left:91.66666667%}.col-sm-offset-10{margin-left:83.33333333%}.col-sm-offset-9{margin-left:75%}.col-sm-offset-8{margin-left:66.66666667%}.col-sm-offset-7{margin-left:58.33333333%}.col-sm-offset-6{margin-left:50%}.col-sm-offset-5{margin-left:41.66666667%}.col-sm-offset-4{margin-left:33.33333333%}.col-sm-offset-3{margin-left:25%}.col-sm-offset-2{margin-left:16.66666667%}.col-sm-offset-1{margin-left:8.33333333%}.col-sm-offset-0{margin-left:0}}@media (min-width:992px){.col-md-1,.col-md-10,.col-md-11,.col-md-12,.col-md-2,.col-md-3,.col-md-4,.col-md-5,.col-md-6,.col-md-7,.col-md-8,.col-md-9{float:left}.col-md-12{width:100%}.col-md-11{width:91.66666667%}.col-md-10{width:83.33333333%}.col-md-9{width:75%}.col-md-8{width:66.66666667%}.col-md-7{width:58.33333333%}.col-md-6{width:50%}.col-md-5{width:41.66666667%}.col-md-4{width:33.33333333%}.col-md-3{width:25%}.col-md-2{width:16.66666667%}.col-md-1{width:8.33333333%}.col-md-pull-12{right:100%}.col-md-pull-11{right:91.66666667%}.col-md-pull-10{right:83.33333333%}.col-md-pull-9{right:75%}.col-md-pull-8{right:66.66666667%}.col-md-pull-7{right:58.33333333%}.col-md-pull-6{right:50%}.col-md-pull-5{right:41.66666667%}.col-md-pull-4{right:33.33333333%}.col-md-pull-3{right:25%}.col-md-pull-2{right:16.66666667%}.col-md-pull-1{right:8.33333333%}.col-md-pull-0{right:auto}.col-md-push-12{left:100%}.col-md-push-11{left:91.66666667%}.col-md-push-10{left:83.33333333%}.col-md-push-9{left:75%}.col-md-push-8{left:66.66666667%}.col-md-push-7{left:58.33333333%}.col-md-push-6{left:50%}.col-md-push-5{left:41.66666667%}.col-md-push-4{left:33.33333333%}.col-md-push-3{left:25%}.col-md-push-2{left:16.66666667%}.col-md-push-1{left:8.33333333%}.col-md-push-0{left:auto}.col-md-offset-12{margin-left:100%}.col-md-offset-11{margin-left:91.66666667%}.col-md-offset-10{margin-left:83.33333333%}.col-md-offset-9{margin-left:75%}.col-md-offset-8{margin-left:66.66666667%}.col-md-offset-7{margin-left:58.33333333%}.col-md-offset-6{margin-left:50%}.col-md-offset-5{margin-left:41.66666667%}.col-md-offset-4{margin-left:33.33333333%}.col-md-offset-3{margin-left:25%}.col-md-offset-2{margin-left:16.66666667%}.col-md-offset-1{margin-left:8.33333333%}.col-md-offset-0{margin-left:0}}@media (min-width:1200px){.col-lg-1,.col-lg-10,.col-lg-11,.col-lg-12,.col-lg-2,.col-lg-3,.col-lg-4,.col-lg-5,.col-lg-6,.col-lg-7,.col-lg-8,.col-lg-9{float:left}.col-lg-12{width:100%}.col-lg-11{width:91.66666667%}.col-lg-10{width:83.33333333%}.col-lg-9{width:75%}.col-lg-8{width:66.66666667%}.col-lg-7{width:58.33333333%}.col-lg-6{width:50%}.col-lg-5{width:41.66666667%}.col-lg-4{width:33.33333333%}.col-lg-3{width:25%}.col-lg-2{width:16.66666667%}.col-lg-1{width:8.33333333%}.col-lg-pull-12{right:100%}.col-lg-pull-11{right:91.66666667%}.col-lg-pull-10{right:83.33333333%}.col-lg-pull-9{right:75%}.col-lg-pull-8{right:66.66666667%}.col-lg-pull-7{right:58.33333333%}.col-lg-pull-6{right:50%}.col-lg-pull-5{right:41.66666667%}.col-lg-pull-4{right:33.33333333%}.col-lg-pull-3{right:25%}.col-lg-pull-2{right:16.66666667%}.col-lg-pull-1{right:8.33333333%}.col-lg-pull-0{right:auto}.col-lg-push-12{left:100%}.col-lg-push-11{left:91.66666667%}.col-lg-push-10{left:83.33333333%}.col-lg-push-9{left:75%}.col-lg-push-8{left:66.66666667%}.col-lg-push-7{left:58.33333333%}.col-lg-push-6{left:50%}.col-lg-push-5{left:41.66666667%}.col-lg-push-4{left:33.33333333%}.col-lg-push-3{left:25%}.col-lg-push-2{left:16.66666667%}.col-lg-push-1{left:8.33333333%}.col-lg-push-0{left:auto}.col-lg-offset-12{margin-left:100%}.col-lg-offset-11{margin-left:91.66666667%}.col-lg-offset-10{margin-left:83.33333333%}.col-lg-offset-9{margin-left:75%}.col-lg-offset-8{margin-left:66.66666667%}.col-lg-offset-7{margin-left:58.33333333%}.col-lg-offset-6{margin-left:50%}.col-lg-offset-5{margin-left:41.66666667%}.col-lg-offset-4{margin-left:33.33333333%}.col-lg-offset-3{margin-left:25%}.col-lg-offset-2{margin-left:16.66666667%}.col-lg-offset-1{margin-left:8.33333333%}.col-lg-offset-0{margin-left:0}}table{background-color:transparent}caption{padding-top:8px;padding-bottom:8px;color:#777;text-align:left}th{text-align:left}.table{width:100%;max-width:100%;margin-bottom:20px}.table>tbody>tr>td,.table>tbody>tr>th,.table>tfoot>tr>td,.table>tfoot>tr>th,.table>thead>tr>td,.table>thead>tr>th{padding:8px;line-height:1.42857143;vertical-align:top;border-top:1px solid #ddd}.table>thead>tr>th{vertical-align:bottom;border-bottom:2px solid #ddd}.table>caption+thead>tr:first-child>td,.table>caption+thead>tr:first-child>th,.table>colgroup+thead>tr:first-child>td,.table>colgroup+thead>tr:first-child>th,.table>thead:first-child>tr:first-child>td,.table>thead:first-child>tr:first-child>th{border-top:0}.table>tbody+tbody{border-top:2px solid #ddd}.table .table{background-color:#fff}.table-condensed>tbody>tr>td,.table-condensed>tbody>tr>th,.table-condensed>tfoot>tr>td,.table-condensed>tfoot>tr>th,.table-condensed>thead>tr>td,.table-condensed>thead>tr>th{padding:5px}.table-bordered{border:1px solid #ddd}.table-bordered>tbody>tr>td,.table-bordered>tbody>tr>th,.table-bordered>tfoot>tr>td,.table-bordered>tfoot>tr>th,.table-bordered>thead>tr>td,.table-bordered>thead>tr>th{border:1px solid #ddd}.table-bordered>thead>tr>td,.table-bordered>thead>tr>th{border-bottom-width:2px}.table-striped>tbody>tr:nth-of-type(odd){background-color:#f9f9f9}.table-hover>tbody>tr:hover{background-color:#f5f5f5}table col[class*=col-]{position:static;display:table-column;float:none}table td[class*=col-],table th[class*=col-]{position:static;display:table-cell;float:none}.table>tbody>tr.active>td,.table>tbody>tr.active>th,.table>tbody>tr>td.active,.table>tbody>tr>th.active,.table>tfoot>tr.active>td,.table>tfoot>tr.active>th,.table>tfoot>tr>td.active,.table>tfoot>tr>th.active,.table>thead>tr.active>td,.table>thead>tr.active>th,.table>thead>tr>td.active,.table>thead>tr>th.active{background-color:#f5f5f5}.table-hover>tbody>tr.active:hover>td,.table-hover>tbody>tr.active:hover>th,.table-hover>tbody>tr:hover>.active,.table-hover>tbody>tr>td.active:hover,.table-hover>tbody>tr>th.active:hover{background-color:#e8e8e8}.table>tbody>tr.success>td,.table>tbody>tr.success>th,.table>tbody>tr>td.success,.table>tbody>tr>th.success,.table>tfoot>tr.success>td,.table>tfoot>tr.success>th,.table>tfoot>tr>td.success,.table>tfoot>tr>th.success,.table>thead>tr.success>td,.table>thead>tr.success>th,.table>thead>tr>td.success,.table>thead>tr>th.success{background-color:#dff0d8}.table-hover>tbody>tr.success:hover>td,.table-hover>tbody>tr.success:hover>th,.table-hover>tbody>tr:hover>.success,.table-hover>tbody>tr>td.success:hover,.table-hover>tbody>tr>th.success:hover{background-color:#d0e9c6}.table>tbody>tr.info>td,.table>tbody>tr.info>th,.table>tbody>tr>td.info,.table>tbody>tr>th.info,.table>tfoot>tr.info>td,.table>tfoot>tr.info>th,.table>tfoot>tr>td.info,.table>tfoot>tr>th.info,.table>thead>tr.info>td,.table>thead>tr.info>th,.table>thead>tr>td.info,.table>thead>tr>th.info{background-color:#d9edf7}.table-hover>tbody>tr.info:hover>td,.table-hover>tbody>tr.info:hover>th,.table-hover>tbody>tr:hover>.info,.table-hover>tbody>tr>td.info:hover,.table-hover>tbody>tr>th.info:hover{background-color:#c4e3f3}.table>tbody>tr.warning>td,.table>tbody>tr.warning>th,.table>tbody>tr>td.warning,.table>tbody>tr>th.warning,.table>tfoot>tr.warning>td,.table>tfoot>tr.warning>th,.table>tfoot>tr>td.warning,.table>tfoot>tr>th.warning,.table>thead>tr.warning>td,.table>thead>tr.warning>th,.table>thead>tr>td.warning,.table>thead>tr>th.warning{background-color:#fcf8e3}.table-hover>tbody>tr.warning:hover>td,.table-hover>tbody>tr.warning:hover>th,.table-hover>tbody>tr:hover>.warning,.table-hover>tbody>tr>td.warning:hover,.table-hover>tbody>tr>th.warning:hover{background-color:#faf2cc}.table>tbody>tr.danger>td,.table>tbody>tr.danger>th,.table>tbody>tr>td.danger,.table>tbody>tr>th.danger,.table>tfoot>tr.danger>td,.table>tfoot>tr.danger>th,.table>tfoot>tr>td.danger,.table>tfoot>tr>th.danger,.table>thead>tr.danger>td,.table>thead>tr.danger>th,.table>thead>tr>td.danger,.table>thead>tr>th.danger{background-color:#f2dede}.table-hover>tbody>tr.danger:hover>td,.table-hover>tbody>tr.danger:hover>th,.table-hover>tbody>tr:hover>.danger,.table-hover>tbody>tr>td.danger:hover,.table-hover>tbody>tr>th.danger:hover{background-color:#ebcccc}.table-responsive{min-height:.01%;overflow-x:auto}@media screen and (max-width:767px){.table-responsive{width:100%;margin-bottom:15px;overflow-y:hidden;-ms-overflow-style:-ms-autohiding-scrollbar;border:1px solid #ddd}.table-responsive>.table{margin-bottom:0}.table-responsive>.table>tbody>tr>td,.table-responsive>.table>tbody>tr>th,.table-responsive>.table>tfoot>tr>td,.table-responsive>.table>tfoot>tr>th,.table-responsive>.table>thead>tr>td,.table-responsive>.table>thead>tr>th{white-space:nowrap}.table-responsive>.table-bordered{border:0}.table-responsive>.table-bordered>tbody>tr>td:first-child,.table-responsive>.table-bordered>tbody>tr>th:first-child,.table-responsive>.table-bordered>tfoot>tr>td:first-child,.table-responsive>.table-bordered>tfoot>tr>th:first-child,.table-responsive>.table-bordered>thead>tr>td:first-child,.table-responsive>.table-bordered>thead>tr>th:first-child{border-left:0}.table-responsive>.table-bordered>tbody>tr>td:last-child,.table-responsive>.table-bordered>tbody>tr>th:last-child,.table-responsive>.table-bordered>tfoot>tr>td:last-child,.table-responsive>.table-bordered>tfoot>tr>th:last-child,.table-responsive>.table-bordered>thead>tr>td:last-child,.table-responsive>.table-bordered>thead>tr>th:last-child{border-right:0}.table-responsive>.table-bordered>tbody>tr:last-child>td,.table-responsive>.table-bordered>tbody>tr:last-child>th,.table-responsive>.table-bordered>tfoot>tr:last-child>td,.table-responsive>.table-bordered>tfoot>tr:last-child>th{border-bottom:0}}fieldset{min-width:0;padding:0;margin:0;border:0}legend{display:block;width:100%;padding:0;margin-bottom:20px;font-size:21px;line-height:inherit;color:#333;border:0;border-bottom:1px solid #e5e5e5}label{display:inline-block;max-width:100%;margin-bottom:5px;font-weight:700}input[type=search]{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}input[type=checkbox],input[type=radio]{margin:4px 0 0;margin-top:1px \9;line-height:normal}input[type=file]{display:block}input[type=range]{display:block;width:100%}select[multiple],select[size]{height:auto}input[type=file]:focus,input[type=checkbox]:focus,input[type=radio]:focus{outline:thin dotted;outline:5px auto -webkit-focus-ring-color;outline-offset:-2px}output{display:block;padding-top:7px;font-size:14px;line-height:1.42857143;color:#555}.form-control{display:block;width:100%;height:34px;padding:6px 12px;font-size:14px;line-height:1.42857143;color:#555;background-color:#fff;background-image:none;border:1px solid #ccc;border-radius:4px;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,.075);box-shadow:inset 0 1px 1px rgba(0,0,0,.075);-webkit-transition:border-color ease-in-out .15s,-webkit-box-shadow ease-in-out .15s;-o-transition:border-color ease-in-out .15s,box-shadow ease-in-out .15s;transition:border-color ease-in-out .15s,box-shadow ease-in-out .15s}.form-control:focus{border-color:#66afe9;outline:0;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6);box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6)}.form-control::-moz-placeholder{color:#999;opacity:1}.form-control:-ms-input-placeholder{color:#999}.form-control::-webkit-input-placeholder{color:#999}.form-control[disabled],.form-control[readonly],fieldset[disabled] .form-control{background-color:#eee;opacity:1}.form-control[disabled],fieldset[disabled] .form-control{cursor:not-allowed}textarea.form-control{height:auto}input[type=search]{-webkit-appearance:none}@media screen and (-webkit-min-device-pixel-ratio:0){input[type=date],input[type=time],input[type=datetime-local],input[type=month]{line-height:34px}.input-group-sm input[type=date],.input-group-sm input[type=time],.input-group-sm input[type=datetime-local],.input-group-sm input[type=month],input[type=date].input-sm,input[type=time].input-sm,input[type=datetime-local].input-sm,input[type=month].input-sm{line-height:30px}.input-group-lg input[type=date],.input-group-lg input[type=time],.input-group-lg input[type=datetime-local],.input-group-lg input[type=month],input[type=date].input-lg,input[type=time].input-lg,input[type=datetime-local].input-lg,input[type=month].input-lg{line-height:46px}}.form-group{margin-bottom:15px}.checkbox,.radio{position:relative;display:block;margin-top:10px;margin-bottom:10px}.checkbox label,.radio label{min-height:20px;padding-left:20px;margin-bottom:0;font-weight:400;cursor:pointer}.checkbox input[type=checkbox],.checkbox-inline input[type=checkbox],.radio input[type=radio],.radio-inline input[type=radio]{position:absolute;margin-top:4px \9;margin-left:-20px}.checkbox+.checkbox,.radio+.radio{margin-top:-5px}.checkbox-inline,.radio-inline{position:relative;display:inline-block;padding-left:20px;margin-bottom:0;font-weight:400;vertical-align:middle;cursor:pointer}.checkbox-inline+.checkbox-inline,.radio-inline+.radio-inline{margin-top:0;margin-left:10px}fieldset[disabled] input[type=checkbox],fieldset[disabled] input[type=radio],input[type=checkbox].disabled,input[type=checkbox][disabled],input[type=radio].disabled,input[type=radio][disabled]{cursor:not-allowed}.checkbox-inline.disabled,.radio-inline.disabled,fieldset[disabled] .checkbox-inline,fieldset[disabled] .radio-inline{cursor:not-allowed}.checkbox.disabled label,.radio.disabled label,fieldset[disabled] .checkbox label,fieldset[disabled] .radio label{cursor:not-allowed}.form-control-static{min-height:34px;padding-top:7px;padding-bottom:7px;margin-bottom:0}.form-control-static.input-lg,.form-control-static.input-sm{padding-right:0;padding-left:0}.input-sm{height:30px;padding:5px 10px;font-size:12px;line-height:1.5;border-radius:3px}select.input-sm{height:30px;line-height:30px}select[multiple].input-sm,textarea.input-sm{height:auto}.form-group-sm .form-control{height:30px;padding:5px 10px;font-size:12px;line-height:1.5;border-radius:3px}select.form-group-sm .form-control{height:30px;line-height:30px}select[multiple].form-group-sm .form-control,textarea.form-group-sm .form-control{height:auto}.form-group-sm .form-control-static{height:30px;min-height:32px;padding:5px 10px;font-size:12px;line-height:1.5}.input-lg{height:46px;padding:10px 16px;font-size:18px;line-height:1.3333333;border-radius:6px}select.input-lg{height:46px;line-height:46px}select[multiple].input-lg,textarea.input-lg{height:auto}.form-group-lg .form-control{height:46px;padding:10px 16px;font-size:18px;line-height:1.3333333;border-radius:6px}select.form-group-lg .form-control{height:46px;line-height:46px}select[multiple].form-group-lg .form-control,textarea.form-group-lg .form-control{height:auto}.form-group-lg .form-control-static{height:46px;min-height:38px;padding:10px 16px;font-size:18px;line-height:1.3333333}.has-feedback{position:relative}.has-feedback .form-control{padding-right:42.5px}.form-control-feedback{position:absolute;top:0;right:0;z-index:2;display:block;width:34px;height:34px;line-height:34px;text-align:center;pointer-events:none}.input-lg+.form-control-feedback{width:46px;height:46px;line-height:46px}.input-sm+.form-control-feedback{width:30px;height:30px;line-height:30px}.has-success .checkbox,.has-success .checkbox-inline,.has-success .control-label,.has-success .help-block,.has-success .radio,.has-success .radio-inline,.has-success.checkbox label,.has-success.checkbox-inline label,.has-success.radio label,.has-success.radio-inline label{color:#3c763d}.has-success .form-control{border-color:#3c763d;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,.075);box-shadow:inset 0 1px 1px rgba(0,0,0,.075)}.has-success .form-control:focus{border-color:#2b542c;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 6px #67b168;box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 6px #67b168}.has-success .input-group-addon{color:#3c763d;background-color:#dff0d8;border-color:#3c763d}.has-success .form-control-feedback{color:#3c763d}.has-warning .checkbox,.has-warning .checkbox-inline,.has-warning .control-label,.has-warning .help-block,.has-warning .radio,.has-warning .radio-inline,.has-warning.checkbox label,.has-warning.checkbox-inline label,.has-warning.radio label,.has-warning.radio-inline label{color:#8a6d3b}.has-warning .form-control{border-color:#8a6d3b;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,.075);box-shadow:inset 0 1px 1px rgba(0,0,0,.075)}.has-warning .form-control:focus{border-color:#66512c;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 6px #c0a16b;box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 6px #c0a16b}.has-warning .input-group-addon{color:#8a6d3b;background-color:#fcf8e3;border-color:#8a6d3b}.has-warning .form-control-feedback{color:#8a6d3b}.has-error .checkbox,.has-error .checkbox-inline,.has-error .control-label,.has-error .help-block,.has-error .radio,.has-error .radio-inline,.has-error.checkbox label,.has-error.checkbox-inline label,.has-error.radio label,.has-error.radio-inline label{color:#a94442}.has-error .form-control{border-color:#a94442;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,.075);box-shadow:inset 0 1px 1px rgba(0,0,0,.075)}.has-error .form-control:focus{border-color:#843534;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 6px #ce8483;box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 6px #ce8483}.has-error .input-group-addon{color:#a94442;background-color:#f2dede;border-color:#a94442}.has-error .form-control-feedback{color:#a94442}.has-feedback label~.form-control-feedback{top:25px}.has-feedback label.sr-only~.form-control-feedback{top:0}.help-block{display:block;margin-top:5px;margin-bottom:10px;color:#737373}@media (min-width:768px){.form-inline .form-group{display:inline-block;margin-bottom:0;vertical-align:middle}.form-inline .form-control{display:inline-block;width:auto;vertical-align:middle}.form-inline .form-control-static{display:inline-block}.form-inline .input-group{display:inline-table;vertical-align:middle}.form-inline .input-group .form-control,.form-inline .input-group .input-group-addon,.form-inline .input-group .input-group-btn{width:auto}.form-inline .input-group>.form-control{width:100%}.form-inline .control-label{margin-bottom:0;vertical-align:middle}.form-inline .checkbox,.form-inline .radio{display:inline-block;margin-top:0;margin-bottom:0;vertical-align:middle}.form-inline .checkbox label,.form-inline .radio label{padding-left:0}.form-inline .checkbox input[type=checkbox],.form-inline .radio input[type=radio]{position:relative;margin-left:0}.form-inline .has-feedback .form-control-feedback{top:0}}.form-horizontal .checkbox,.form-horizontal .checkbox-inline,.form-horizontal .radio,.form-horizontal .radio-inline{padding-top:7px;margin-top:0;margin-bottom:0}.form-horizontal .checkbox,.form-horizontal .radio{min-height:27px}.form-horizontal .form-group{margin-right:-15px;margin-left:-15px}@media (min-width:768px){.form-horizontal .control-label{padding-top:7px;margin-bottom:0;text-align:right}}.form-horizontal .has-feedback .form-control-feedback{right:15px}@media (min-width:768px){.form-horizontal .form-group-lg .control-label{padding-top:14.33px}}@media (min-width:768px){.form-horizontal .form-group-sm .control-label{padding-top:6px}}.btn{display:inline-block;padding:6px 12px;margin-bottom:0;font-size:14px;font-weight:400;line-height:1.42857143;text-align:center;white-space:nowrap;vertical-align:middle;-ms-touch-action:manipulation;touch-action:manipulation;cursor:pointer;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;background-image:none;border:1px solid transparent;border-radius:4px}.btn.active.focus,.btn.active:focus,.btn.focus,.btn:active.focus,.btn:active:focus,.btn:focus{outline:thin dotted;outline:5px auto -webkit-focus-ring-color;outline-offset:-2px}.btn.focus,.btn:focus,.btn:hover{color:#333;text-decoration:none}.btn.active,.btn:active{background-image:none;outline:0;-webkit-box-shadow:inset 0 3px 5px rgba(0,0,0,.125);box-shadow:inset 0 3px 5px rgba(0,0,0,.125)}.btn.disabled,.btn[disabled],fieldset[disabled] .btn{pointer-events:none;cursor:not-allowed;filter:alpha(opacity=65);-webkit-box-shadow:none;box-shadow:none;opacity:.65}.btn-default{color:#333;background-color:#fff;border-color:#ccc}.btn-default.active,.btn-default.focus,.btn-default:active,.btn-default:focus,.btn-default:hover,.open>.dropdown-toggle.btn-default{color:#333;background-color:#e6e6e6;border-color:#adadad}.btn-default.active,.btn-default:active,.open>.dropdown-toggle.btn-default{background-image:none}.btn-default.disabled,.btn-default.disabled.active,.btn-default.disabled.focus,.btn-default.disabled:active,.btn-default.disabled:focus,.btn-default.disabled:hover,.btn-default[disabled],.btn-default[disabled].active,.btn-default[disabled].focus,.btn-default[disabled]:active,.btn-default[disabled]:focus,.btn-default[disabled]:hover,fieldset[disabled] .btn-default,fieldset[disabled] .btn-default.active,fieldset[disabled] .btn-default.focus,fieldset[disabled] .btn-default:active,fieldset[disabled] .btn-default:focus,fieldset[disabled] .btn-default:hover{background-color:#fff;border-color:#ccc}.btn-default .badge{color:#fff;background-color:#333}.btn-primary{color:#fff;background-color:#337ab7;border-color:#2e6da4}.btn-primary.active,.btn-primary.focus,.btn-primary:active,.btn-primary:focus,.btn-primary:hover,.open>.dropdown-toggle.btn-primary{color:#fff;background-color:#286090;border-color:#204d74}.btn-primary.active,.btn-primary:active,.open>.dropdown-toggle.btn-primary{background-image:none}.btn-primary.disabled,.btn-primary.disabled.active,.btn-primary.disabled.focus,.btn-primary.disabled:active,.btn-primary.disabled:focus,.btn-primary.disabled:hover,.btn-primary[disabled],.btn-primary[disabled].active,.btn-primary[disabled].focus,.btn-primary[disabled]:active,.btn-primary[disabled]:focus,.btn-primary[disabled]:hover,fieldset[disabled] .btn-primary,fieldset[disabled] .btn-primary.active,fieldset[disabled] .btn-primary.focus,fieldset[disabled] .btn-primary:active,fieldset[disabled] .btn-primary:focus,fieldset[disabled] .btn-primary:hover{background-color:#337ab7;border-color:#2e6da4}.btn-primary .badge{color:#337ab7;background-color:#fff}.btn-success{color:#fff;background-color:#5cb85c;border-color:#4cae4c}.btn-success.active,.btn-success.focus,.btn-success:active,.btn-success:focus,.btn-success:hover,.open>.dropdown-toggle.btn-success{color:#fff;background-color:#449d44;border-color:#398439}.btn-success.active,.btn-success:active,.open>.dropdown-toggle.btn-success{background-image:none}.btn-success.disabled,.btn-success.disabled.active,.btn-success.disabled.focus,.btn-success.disabled:active,.btn-success.disabled:focus,.btn-success.disabled:hover,.btn-success[disabled],.btn-success[disabled].active,.btn-success[disabled].focus,.btn-success[disabled]:active,.btn-success[disabled]:focus,.btn-success[disabled]:hover,fieldset[disabled] .btn-success,fieldset[disabled] .btn-success.active,fieldset[disabled] .btn-success.focus,fieldset[disabled] .btn-success:active,fieldset[disabled] .btn-success:focus,fieldset[disabled] .btn-success:hover{background-color:#5cb85c;border-color:#4cae4c}.btn-success .badge{color:#5cb85c;background-color:#fff}.btn-info{color:#fff;background-color:#5bc0de;border-color:#46b8da}.btn-info.active,.btn-info.focus,.btn-info:active,.btn-info:focus,.btn-info:hover,.open>.dropdown-toggle.btn-info{color:#fff;background-color:#31b0d5;border-color:#269abc}.btn-info.active,.btn-info:active,.open>.dropdown-toggle.btn-info{background-image:none}.btn-info.disabled,.btn-info.disabled.active,.btn-info.disabled.focus,.btn-info.disabled:active,.btn-info.disabled:focus,.btn-info.disabled:hover,.btn-info[disabled],.btn-info[disabled].active,.btn-info[disabled].focus,.btn-info[disabled]:active,.btn-info[disabled]:focus,.btn-info[disabled]:hover,fieldset[disabled] .btn-info,fieldset[disabled] .btn-info.active,fieldset[disabled] .btn-info.focus,fieldset[disabled] .btn-info:active,fieldset[disabled] .btn-info:focus,fieldset[disabled] .btn-info:hover{background-color:#5bc0de;border-color:#46b8da}.btn-info .badge{color:#5bc0de;background-color:#fff}.btn-warning{color:#fff;background-color:#f0ad4e;border-color:#eea236}.btn-warning.active,.btn-warning.focus,.btn-warning:active,.btn-warning:focus,.btn-warning:hover,.open>.dropdown-toggle.btn-warning{color:#fff;background-color:#ec971f;border-color:#d58512}.btn-warning.active,.btn-warning:active,.open>.dropdown-toggle.btn-warning{background-image:none}.btn-warning.disabled,.btn-warning.disabled.active,.btn-warning.disabled.focus,.btn-warning.disabled:active,.btn-warning.disabled:focus,.btn-warning.disabled:hover,.btn-warning[disabled],.btn-warning[disabled].active,.btn-warning[disabled].focus,.btn-warning[disabled]:active,.btn-warning[disabled]:focus,.btn-warning[disabled]:hover,fieldset[disabled] .btn-warning,fieldset[disabled] .btn-warning.active,fieldset[disabled] .btn-warning.focus,fieldset[disabled] .btn-warning:active,fieldset[disabled] .btn-warning:focus,fieldset[disabled] .btn-warning:hover{background-color:#f0ad4e;border-color:#eea236}.btn-warning .badge{color:#f0ad4e;background-color:#fff}.btn-danger{color:#fff;background-color:#d9534f;border-color:#d43f3a}.btn-danger.active,.btn-danger.focus,.btn-danger:active,.btn-danger:focus,.btn-danger:hover,.open>.dropdown-toggle.btn-danger{color:#fff;background-color:#c9302c;border-color:#ac2925}.btn-danger.active,.btn-danger:active,.open>.dropdown-toggle.btn-danger{background-image:none}.btn-danger.disabled,.btn-danger.disabled.active,.btn-danger.disabled.focus,.btn-danger.disabled:active,.btn-danger.disabled:focus,.btn-danger.disabled:hover,.btn-danger[disabled],.btn-danger[disabled].active,.btn-danger[disabled].focus,.btn-danger[disabled]:active,.btn-danger[disabled]:focus,.btn-danger[disabled]:hover,fieldset[disabled] .btn-danger,fieldset[disabled] .btn-danger.active,fieldset[disabled] .btn-danger.focus,fieldset[disabled] .btn-danger:active,fieldset[disabled] .btn-danger:focus,fieldset[disabled] .btn-danger:hover{background-color:#d9534f;border-color:#d43f3a}.btn-danger .badge{color:#d9534f;background-color:#fff}.btn-link{font-weight:400;color:#337ab7;border-radius:0}.btn-link,.btn-link.active,.btn-link:active,.btn-link[disabled],fieldset[disabled] .btn-link{background-color:transparent;-webkit-box-shadow:none;box-shadow:none}.btn-link,.btn-link:active,.btn-link:focus,.btn-link:hover{border-color:transparent}.btn-link:focus,.btn-link:hover{color:#23527c;text-decoration:underline;background-color:transparent}.btn-link[disabled]:focus,.btn-link[disabled]:hover,fieldset[disabled] .btn-link:focus,fieldset[disabled] .btn-link:hover{color:#777;text-decoration:none}.btn-group-lg>.btn,.btn-lg{padding:10px 16px;font-size:18px;line-height:1.3333333;border-radius:6px}.btn-group-sm>.btn,.btn-sm{padding:5px 10px;font-size:12px;line-height:1.5;border-radius:3px}.btn-group-xs>.btn,.btn-xs{padding:1px 5px;font-size:12px;line-height:1.5;border-radius:3px}.btn-block{display:block;width:100%}.btn-block+.btn-block{margin-top:5px}input[type=button].btn-block,input[type=reset].btn-block,input[type=submit].btn-block{width:100%}.fade{opacity:0;-webkit-transition:opacity .15s linear;-o-transition:opacity .15s linear;transition:opacity .15s linear}.fade.in{opacity:1}.collapse{display:none}.collapse.in{display:block}tr.collapse.in{display:table-row}tbody.collapse.in{display:table-row-group}.collapsing{position:relative;height:0;overflow:hidden;-webkit-transition-timing-function:ease;-o-transition-timing-function:ease;transition-timing-function:ease;-webkit-transition-duration:.35s;-o-transition-duration:.35s;transition-duration:.35s;-webkit-transition-property:height,visibility;-o-transition-property:height,visibility;transition-property:height,visibility}.caret{display:inline-block;width:0;height:0;margin-left:2px;vertical-align:middle;border-top:4px dashed;border-right:4px solid transparent;border-left:4px solid transparent}.dropdown,.dropup{position:relative}.dropdown-toggle:focus{outline:0}.dropdown-menu{position:absolute;top:100%;left:0;z-index:1000;display:none;float:left;min-width:160px;padding:5px 0;margin:2px 0 0;font-size:14px;text-align:left;list-style:none;background-color:#fff;-webkit-background-clip:padding-box;background-clip:padding-box;border:1px solid #ccc;border:1px solid rgba(0,0,0,.15);border-radius:4px;-webkit-box-shadow:0 6px 12px rgba(0,0,0,.175);box-shadow:0 6px 12px rgba(0,0,0,.175)}.dropdown-menu.pull-right{right:0;left:auto}.dropdown-menu .divider{height:1px;margin:9px 0;overflow:hidden;background-color:#e5e5e5}.dropdown-menu>li>a{display:block;padding:3px 20px;clear:both;font-weight:400;line-height:1.42857143;color:#333;white-space:nowrap}.dropdown-menu>li>a:focus,.dropdown-menu>li>a:hover{color:#262626;text-decoration:none;background-color:#f5f5f5}.dropdown-menu>.active>a,.dropdown-menu>.active>a:focus,.dropdown-menu>.active>a:hover{color:#fff;text-decoration:none;background-color:#337ab7;outline:0}.dropdown-menu>.disabled>a,.dropdown-menu>.disabled>a:focus,.dropdown-menu>.disabled>a:hover{color:#777}.dropdown-menu>.disabled>a:focus,.dropdown-menu>.disabled>a:hover{text-decoration:none;cursor:not-allowed;background-color:transparent;background-image:none;filter:progid:DXImageTransform.Microsoft.gradient(enabled=false)}.open>.dropdown-menu{display:block}.open>a{outline:0}.dropdown-menu-right{right:0;left:auto}.dropdown-menu-left{right:auto;left:0}.dropdown-header{display:block;padding:3px 20px;font-size:12px;line-height:1.42857143;color:#777;white-space:nowrap}.dropdown-backdrop{position:fixed;top:0;right:0;bottom:0;left:0;z-index:990}.pull-right>.dropdown-menu{right:0;left:auto}.dropup .caret,.navbar-fixed-bottom .dropdown .caret{content:"";border-top:0;border-bottom:4px solid}.dropup .dropdown-menu,.navbar-fixed-bottom .dropdown .dropdown-menu{top:auto;bottom:100%;margin-bottom:2px}@media (min-width:768px){.navbar-right .dropdown-menu{right:0;left:auto}.navbar-right .dropdown-menu-left{right:auto;left:0}}.btn-group,.btn-group-vertical{position:relative;display:inline-block;vertical-align:middle}.btn-group-vertical>.btn,.btn-group>.btn{position:relative;float:left}.btn-group-vertical>.btn.active,.btn-group-vertical>.btn:active,.btn-group-vertical>.btn:focus,.btn-group-vertical>.btn:hover,.btn-group>.btn.active,.btn-group>.btn:active,.btn-group>.btn:focus,.btn-group>.btn:hover{z-index:2}.btn-group .btn+.btn,.btn-group .btn+.btn-group,.btn-group .btn-group+.btn,.btn-group .btn-group+.btn-group{margin-left:-1px}.btn-toolbar{margin-left:-5px}.btn-toolbar .btn-group,.btn-toolbar .input-group{float:left}.btn-toolbar>.btn,.btn-toolbar>.btn-group,.btn-toolbar>.input-group{margin-left:5px}.btn-group>.btn:not(:first-child):not(:last-child):not(.dropdown-toggle){border-radius:0}.btn-group>.btn:first-child{margin-left:0}.btn-group>.btn:first-child:not(:last-child):not(.dropdown-toggle){border-top-right-radius:0;border-bottom-right-radius:0}.btn-group>.btn:last-child:not(:first-child),.btn-group>.dropdown-toggle:not(:first-child){border-top-left-radius:0;border-bottom-left-radius:0}.btn-group>.btn-group{float:left}.btn-group>.btn-group:not(:first-child):not(:last-child)>.btn{border-radius:0}.btn-group>.btn-group:first-child:not(:last-child)>.btn:last-child,.btn-group>.btn-group:first-child:not(:last-child)>.dropdown-toggle{border-top-right-radius:0;border-bottom-right-radius:0}.btn-group>.btn-group:last-child:not(:first-child)>.btn:first-child{border-top-left-radius:0;border-bottom-left-radius:0}.btn-group .dropdown-toggle:active,.btn-group.open .dropdown-toggle{outline:0}.btn-group>.btn+.dropdown-toggle{padding-right:8px;padding-left:8px}.btn-group>.btn-lg+.dropdown-toggle{padding-right:12px;padding-left:12px}.btn-group.open .dropdown-toggle{-webkit-box-shadow:inset 0 3px 5px rgba(0,0,0,.125);box-shadow:inset 0 3px 5px rgba(0,0,0,.125)}.btn-group.open .dropdown-toggle.btn-link{-webkit-box-shadow:none;box-shadow:none}.btn .caret{margin-left:0}.btn-lg .caret{border-width:5px 5px 0;border-bottom-width:0}.dropup .btn-lg .caret{border-width:0 5px 5px}.btn-group-vertical>.btn,.btn-group-vertical>.btn-group,.btn-group-vertical>.btn-group>.btn{display:block;float:none;width:100%;max-width:100%}.btn-group-vertical>.btn-group>.btn{float:none}.btn-group-vertical>.btn+.btn,.btn-group-vertical>.btn+.btn-group,.btn-group-vertical>.btn-group+.btn,.btn-group-vertical>.btn-group+.btn-group{margin-top:-1px;margin-left:0}.btn-group-vertical>.btn:not(:first-child):not(:last-child){border-radius:0}.btn-group-vertical>.btn:first-child:not(:last-child){border-top-right-radius:4px;border-bottom-right-radius:0;border-bottom-left-radius:0}.btn-group-vertical>.btn:last-child:not(:first-child){border-top-left-radius:0;border-top-right-radius:0;border-bottom-left-radius:4px}.btn-group-vertical>.btn-group:not(:first-child):not(:last-child)>.btn{border-radius:0}.btn-group-vertical>.btn-group:first-child:not(:last-child)>.btn:last-child,.btn-group-vertical>.btn-group:first-child:not(:last-child)>.dropdown-toggle{border-bottom-right-radius:0;border-bottom-left-radius:0}.btn-group-vertical>.btn-group:last-child:not(:first-child)>.btn:first-child{border-top-left-radius:0;border-top-right-radius:0}.btn-group-justified{display:table;width:100%;table-layout:fixed;border-collapse:separate}.btn-group-justified>.btn,.btn-group-justified>.btn-group{display:table-cell;float:none;width:1%}.btn-group-justified>.btn-group .btn{width:100%}.btn-group-justified>.btn-group .dropdown-menu{left:auto}[data-toggle=buttons]>.btn input[type=checkbox],[data-toggle=buttons]>.btn input[type=radio],[data-toggle=buttons]>.btn-group>.btn input[type=checkbox],[data-toggle=buttons]>.btn-group>.btn input[type=radio]{position:absolute;clip:rect(0,0,0,0);pointer-events:none}.input-group{position:relative;display:table;border-collapse:separate}.input-group[class*=col-]{float:none;padding-right:0;padding-left:0}.input-group .form-control{position:relative;z-index:2;float:left;width:100%;margin-bottom:0}.input-group-lg>.form-control,.input-group-lg>.input-group-addon,.input-group-lg>.input-group-btn>.btn{height:46px;padding:10px 16px;font-size:18px;line-height:1.3333333;border-radius:6px}select.input-group-lg>.form-control,select.input-group-lg>.input-group-addon,select.input-group-lg>.input-group-btn>.btn{height:46px;line-height:46px}select[multiple].input-group-lg>.form-control,select[multiple].input-group-lg>.input-group-addon,select[multiple].input-group-lg>.input-group-btn>.btn,textarea.input-group-lg>.form-control,textarea.input-group-lg>.input-group-addon,textarea.input-group-lg>.input-group-btn>.btn{height:auto}.input-group-sm>.form-control,.input-group-sm>.input-group-addon,.input-group-sm>.input-group-btn>.btn{height:30px;padding:5px 10px;font-size:12px;line-height:1.5;border-radius:3px}select.input-group-sm>.form-control,select.input-group-sm>.input-group-addon,select.input-group-sm>.input-group-btn>.btn{height:30px;line-height:30px}select[multiple].input-group-sm>.form-control,select[multiple].input-group-sm>.input-group-addon,select[multiple].input-group-sm>.input-group-btn>.btn,textarea.input-group-sm>.form-control,textarea.input-group-sm>.input-group-addon,textarea.input-group-sm>.input-group-btn>.btn{height:auto}.input-group .form-control,.input-group-addon,.input-group-btn{display:table-cell}.input-group .form-control:not(:first-child):not(:last-child),.input-group-addon:not(:first-child):not(:last-child),.input-group-btn:not(:first-child):not(:last-child){border-radius:0}.input-group-addon,.input-group-btn{width:1%;white-space:nowrap;vertical-align:middle}.input-group-addon{padding:6px 12px;font-size:14px;font-weight:400;line-height:1;color:#555;text-align:center;background-color:#eee;border:1px solid #ccc;border-radius:4px}.input-group-addon.input-sm{padding:5px 10px;font-size:12px;border-radius:3px}.input-group-addon.input-lg{padding:10px 16px;font-size:18px;border-radius:6px}.input-group-addon input[type=checkbox],.input-group-addon input[type=radio]{margin-top:0}.input-group .form-control:first-child,.input-group-addon:first-child,.input-group-btn:first-child>.btn,.input-group-btn:first-child>.btn-group>.btn,.input-group-btn:first-child>.dropdown-toggle,.input-group-btn:last-child>.btn-group:not(:last-child)>.btn,.input-group-btn:last-child>.btn:not(:last-child):not(.dropdown-toggle){border-top-right-radius:0;border-bottom-right-radius:0}.input-group-addon:first-child{border-right:0}.input-group .form-control:last-child,.input-group-addon:last-child,.input-group-btn:first-child>.btn-group:not(:first-child)>.btn,.input-group-btn:first-child>.btn:not(:first-child),.input-group-btn:last-child>.btn,.input-group-btn:last-child>.btn-group>.btn,.input-group-btn:last-child>.dropdown-toggle{border-top-left-radius:0;border-bottom-left-radius:0}.input-group-addon:last-child{border-left:0}.input-group-btn{position:relative;font-size:0;white-space:nowrap}.input-group-btn>.btn{position:relative}.input-group-btn>.btn+.btn{margin-left:-1px}.input-group-btn>.btn:active,.input-group-btn>.btn:focus,.input-group-btn>.btn:hover{z-index:2}.input-group-btn:first-child>.btn,.input-group-btn:first-child>.btn-group{margin-right:-1px}.input-group-btn:last-child>.btn,.input-group-btn:last-child>.btn-group{margin-left:-1px}.nav{padding-left:0;margin-bottom:0;list-style:none}.nav>li{position:relative;display:block}.nav>li>a{position:relative;display:block;padding:10px 15px}.nav>li>a:focus,.nav>li>a:hover{text-decoration:none;background-color:#eee}.nav>li.disabled>a{color:#777}.nav>li.disabled>a:focus,.nav>li.disabled>a:hover{color:#777;text-decoration:none;cursor:not-allowed;background-color:transparent}.nav .open>a,.nav .open>a:focus,.nav .open>a:hover{background-color:#eee;border-color:#337ab7}.nav .nav-divider{height:1px;margin:9px 0;overflow:hidden;background-color:#e5e5e5}.nav>li>a>img{max-width:none}.nav-tabs{border-bottom:1px solid #ddd}.nav-tabs>li{float:left;margin-bottom:-1px}.nav-tabs>li>a{margin-right:2px;line-height:1.42857143;border:1px solid transparent;border-radius:4px 4px 0 0}.nav-tabs>li>a:hover{border-color:#eee #eee #ddd}.nav-tabs>li.active>a,.nav-tabs>li.active>a:focus,.nav-tabs>li.active>a:hover{color:#555;cursor:default;background-color:#fff;border:1px solid #ddd;border-bottom-color:transparent}.nav-tabs.nav-justified{width:100%;border-bottom:0}.nav-tabs.nav-justified>li{float:none}.nav-tabs.nav-justified>li>a{margin-bottom:5px;text-align:center}.nav-tabs.nav-justified>.dropdown .dropdown-menu{top:auto;left:auto}@media (min-width:768px){.nav-tabs.nav-justified>li{display:table-cell;width:1%}.nav-tabs.nav-justified>li>a{margin-bottom:0}}.nav-tabs.nav-justified>li>a{margin-right:0;border-radius:4px}.nav-tabs.nav-justified>.active>a,.nav-tabs.nav-justified>.active>a:focus,.nav-tabs.nav-justified>.active>a:hover{border:1px solid #ddd}@media (min-width:768px){.nav-tabs.nav-justified>li>a{border-bottom:1px solid #ddd;border-radius:4px 4px 0 0}.nav-tabs.nav-justified>.active>a,.nav-tabs.nav-justified>.active>a:focus,.nav-tabs.nav-justified>.active>a:hover{border-bottom-color:#fff}}.nav-pills>li{float:left}.nav-pills>li>a{border-radius:4px}.nav-pills>li+li{margin-left:2px}.nav-pills>li.active>a,.nav-pills>li.active>a:focus,.nav-pills>li.active>a:hover{color:#fff;background-color:#337ab7}.nav-stacked>li{float:none}.nav-stacked>li+li{margin-top:2px;margin-left:0}.nav-justified{width:100%}.nav-justified>li{float:none}.nav-justified>li>a{margin-bottom:5px;text-align:center}.nav-justified>.dropdown .dropdown-menu{top:auto;left:auto}@media (min-width:768px){.nav-justified>li{display:table-cell;width:1%}.nav-justified>li>a{margin-bottom:0}}.nav-tabs-justified{border-bottom:0}.nav-tabs-justified>li>a{margin-right:0;border-radius:4px}.nav-tabs-justified>.active>a,.nav-tabs-justified>.active>a:focus,.nav-tabs-justified>.active>a:hover{border:1px solid #ddd}@media (min-width:768px){.nav-tabs-justified>li>a{border-bottom:1px solid #ddd;border-radius:4px 4px 0 0}.nav-tabs-justified>.active>a,.nav-tabs-justified>.active>a:focus,.nav-tabs-justified>.active>a:hover{border-bottom-color:#fff}}.tab-content>.tab-pane{display:none}.tab-content>.active{display:block}.nav-tabs .dropdown-menu{margin-top:-1px;border-top-left-radius:0;border-top-right-radius:0}.navbar{position:relative;min-height:50px;margin-bottom:20px;border:1px solid transparent}@media (min-width:768px){.navbar{border-radius:4px}}@media (min-width:768px){.navbar-header{float:left}}.navbar-collapse{padding-right:15px;padding-left:15px;overflow-x:visible;-webkit-overflow-scrolling:touch;border-top:1px solid transparent;-webkit-box-shadow:inset 0 1px 0 rgba(255,255,255,.1);box-shadow:inset 0 1px 0 rgba(255,255,255,.1)}.navbar-collapse.in{overflow-y:auto}@media (min-width:768px){.navbar-collapse{width:auto;border-top:0;-webkit-box-shadow:none;box-shadow:none}.navbar-collapse.collapse{display:block!important;height:auto!important;padding-bottom:0;overflow:visible!important}.navbar-collapse.in{overflow-y:visible}.navbar-fixed-bottom .navbar-collapse,.navbar-fixed-top .navbar-collapse,.navbar-static-top .navbar-collapse{padding-right:0;padding-left:0}}.navbar-fixed-bottom .navbar-collapse,.navbar-fixed-top .navbar-collapse{max-height:340px}@media (max-device-width:480px)and (orientation:landscape){.navbar-fixed-bottom .navbar-collapse,.navbar-fixed-top .navbar-collapse{max-height:200px}}.container-fluid>.navbar-collapse,.container-fluid>.navbar-header,.container>.navbar-collapse,.container>.navbar-header{margin-right:-15px;margin-left:-15px}@media (min-width:768px){.container-fluid>.navbar-collapse,.container-fluid>.navbar-header,.container>.navbar-collapse,.container>.navbar-header{margin-right:0;margin-left:0}}.navbar-static-top{z-index:1000;border-width:0 0 1px}@media (min-width:768px){.navbar-static-top{border-radius:0}}.navbar-fixed-bottom,.navbar-fixed-top{position:fixed;right:0;left:0;z-index:1030}@media (min-width:768px){.navbar-fixed-bottom,.navbar-fixed-top{border-radius:0}}.navbar-fixed-top{top:0;border-width:0 0 1px}.navbar-fixed-bottom{bottom:0;margin-bottom:0;border-width:1px 0 0}.navbar-brand{float:left;height:50px;padding:15px 15px;font-size:18px;line-height:20px}.navbar-brand:focus,.navbar-brand:hover{text-decoration:none}.navbar-brand>img{display:block}@media (min-width:768px){.navbar>.container .navbar-brand,.navbar>.container-fluid .navbar-brand{margin-left:-15px}}.navbar-toggle{position:relative;float:right;padding:9px 10px;margin-top:8px;margin-right:15px;margin-bottom:8px;background-color:transparent;background-image:none;border:1px solid transparent;border-radius:4px}.navbar-toggle:focus{outline:0}.navbar-toggle .icon-bar{display:block;width:22px;height:2px;border-radius:1px}.navbar-toggle .icon-bar+.icon-bar{margin-top:4px}@media (min-width:768px){.navbar-toggle{display:none}}.navbar-nav{margin:7.5px -15px}.navbar-nav>li>a{padding-top:10px;padding-bottom:10px;line-height:20px}@media (max-width:767px){.navbar-nav .open .dropdown-menu{position:static;float:none;width:auto;margin-top:0;background-color:transparent;border:0;-webkit-box-shadow:none;box-shadow:none}.navbar-nav .open .dropdown-menu .dropdown-header,.navbar-nav .open .dropdown-menu>li>a{padding:5px 15px 5px 25px}.navbar-nav .open .dropdown-menu>li>a{line-height:20px}.navbar-nav .open .dropdown-menu>li>a:focus,.navbar-nav .open .dropdown-menu>li>a:hover{background-image:none}}@media (min-width:768px){.navbar-nav{float:left;margin:0}.navbar-nav>li{float:left}.navbar-nav>li>a{padding-top:15px;padding-bottom:15px}}.navbar-form{padding:10px 15px;margin-top:8px;margin-right:-15px;margin-bottom:8px;margin-left:-15px;border-top:1px solid transparent;border-bottom:1px solid transparent;-webkit-box-shadow:inset 0 1px 0 rgba(255,255,255,.1),0 1px 0 rgba(255,255,255,.1);box-shadow:inset 0 1px 0 rgba(255,255,255,.1),0 1px 0 rgba(255,255,255,.1)}@media (min-width:768px){.navbar-form .form-group{display:inline-block;margin-bottom:0;vertical-align:middle}.navbar-form .form-control{display:inline-block;width:auto;vertical-align:middle}.navbar-form .form-control-static{display:inline-block}.navbar-form .input-group{display:inline-table;vertical-align:middle}.navbar-form .input-group .form-control,.navbar-form .input-group .input-group-addon,.navbar-form .input-group .input-group-btn{width:auto}.navbar-form .input-group>.form-control{width:100%}.navbar-form .control-label{margin-bottom:0;vertical-align:middle}.navbar-form .checkbox,.navbar-form .radio{display:inline-block;margin-top:0;margin-bottom:0;vertical-align:middle}.navbar-form .checkbox label,.navbar-form .radio label{padding-left:0}.navbar-form .checkbox input[type=checkbox],.navbar-form .radio input[type=radio]{position:relative;margin-left:0}.navbar-form .has-feedback .form-control-feedback{top:0}}@media (max-width:767px){.navbar-form .form-group{margin-bottom:5px}.navbar-form .form-group:last-child{margin-bottom:0}}@media (min-width:768px){.navbar-form{width:auto;padding-top:0;padding-bottom:0;margin-right:0;margin-left:0;border:0;-webkit-box-shadow:none;box-shadow:none}}.navbar-nav>li>.dropdown-menu{margin-top:0;border-top-left-radius:0;border-top-right-radius:0}.navbar-fixed-bottom .navbar-nav>li>.dropdown-menu{margin-bottom:0;border-top-left-radius:4px;border-top-right-radius:4px;border-bottom-right-radius:0;border-bottom-left-radius:0}.navbar-btn{margin-top:8px;margin-bottom:8px}.navbar-btn.btn-sm{margin-top:10px;margin-bottom:10px}.navbar-btn.btn-xs{margin-top:14px;margin-bottom:14px}.navbar-text{margin-top:15px;margin-bottom:15px}@media (min-width:768px){.navbar-text{float:left;margin-right:15px;margin-left:15px}}@media (min-width:768px){.navbar-left{float:left!important}.navbar-right{float:right!important;margin-right:-15px}.navbar-right~.navbar-right{margin-right:0}}.navbar-default{background-color:#f8f8f8;border-color:#e7e7e7}.navbar-default .navbar-brand{color:#777}.navbar-default .navbar-brand:focus,.navbar-default .navbar-brand:hover{color:#5e5e5e;background-color:transparent}.navbar-default .navbar-text{color:#777}.navbar-default .navbar-nav>li>a{color:#777}.navbar-default .navbar-nav>li>a:focus,.navbar-default .navbar-nav>li>a:hover{color:#333;background-color:transparent}.navbar-default .navbar-nav>.active>a,.navbar-default .navbar-nav>.active>a:focus,.navbar-default .navbar-nav>.active>a:hover{color:#555;background-color:#e7e7e7}.navbar-default .navbar-nav>.disabled>a,.navbar-default .navbar-nav>.disabled>a:focus,.navbar-default .navbar-nav>.disabled>a:hover{color:#ccc;background-color:transparent}.navbar-default .navbar-toggle{border-color:#ddd}.navbar-default .navbar-toggle:focus,.navbar-default .navbar-toggle:hover{background-color:#ddd}.navbar-default .navbar-toggle .icon-bar{background-color:#888}.navbar-default .navbar-collapse,.navbar-default .navbar-form{border-color:#e7e7e7}.navbar-default .navbar-nav>.open>a,.navbar-default .navbar-nav>.open>a:focus,.navbar-default .navbar-nav>.open>a:hover{color:#555;background-color:#e7e7e7}@media (max-width:767px){.navbar-default .navbar-nav .open .dropdown-menu>li>a{color:#777}.navbar-default .navbar-nav .open .dropdown-menu>li>a:focus,.navbar-default .navbar-nav .open .dropdown-menu>li>a:hover{color:#333;background-color:transparent}.navbar-default .navbar-nav .open .dropdown-menu>.active>a,.navbar-default .navbar-nav .open .dropdown-menu>.active>a:focus,.navbar-default .navbar-nav .open .dropdown-menu>.active>a:hover{color:#555;background-color:#e7e7e7}.navbar-default .navbar-nav .open .dropdown-menu>.disabled>a,.navbar-default .navbar-nav .open .dropdown-menu>.disabled>a:focus,.navbar-default .navbar-nav .open .dropdown-menu>.disabled>a:hover{color:#ccc;background-color:transparent}}.navbar-default .navbar-link{color:#777}.navbar-default .navbar-link:hover{color:#333}.navbar-default .btn-link{color:#777}.navbar-default .btn-link:focus,.navbar-default .btn-link:hover{color:#333}.navbar-default .btn-link[disabled]:focus,.navbar-default .btn-link[disabled]:hover,fieldset[disabled] .navbar-default .btn-link:focus,fieldset[disabled] .navbar-default .btn-link:hover{color:#ccc}.navbar-inverse{background-color:#222;border-color:#080808}.navbar-inverse .navbar-brand{color:#9d9d9d}.navbar-inverse .navbar-brand:focus,.navbar-inverse .navbar-brand:hover{color:#fff;background-color:transparent}.navbar-inverse .navbar-text{color:#9d9d9d}.navbar-inverse .navbar-nav>li>a{color:#9d9d9d}.navbar-inverse .navbar-nav>li>a:focus,.navbar-inverse .navbar-nav>li>a:hover{color:#fff;background-color:transparent}.navbar-inverse .navbar-nav>.active>a,.navbar-inverse .navbar-nav>.active>a:focus,.navbar-inverse .navbar-nav>.active>a:hover{color:#fff;background-color:#080808}.navbar-inverse .navbar-nav>.disabled>a,.navbar-inverse .navbar-nav>.disabled>a:focus,.navbar-inverse .navbar-nav>.disabled>a:hover{color:#444;background-color:transparent}.navbar-inverse .navbar-toggle{border-color:#333}.navbar-inverse .navbar-toggle:focus,.navbar-inverse .navbar-toggle:hover{background-color:#333}.navbar-inverse .navbar-toggle .icon-bar{background-color:#fff}.navbar-inverse .navbar-collapse,.navbar-inverse .navbar-form{border-color:#101010}.navbar-inverse .navbar-nav>.open>a,.navbar-inverse .navbar-nav>.open>a:focus,.navbar-inverse .navbar-nav>.open>a:hover{color:#fff;background-color:#080808}@media (max-width:767px){.navbar-inverse .navbar-nav .open .dropdown-menu>.dropdown-header{border-color:#080808}.navbar-inverse .navbar-nav .open .dropdown-menu .divider{background-color:#080808}.navbar-inverse .navbar-nav .open .dropdown-menu>li>a{color:#9d9d9d}.navbar-inverse .navbar-nav .open .dropdown-menu>li>a:focus,.navbar-inverse .navbar-nav .open .dropdown-menu>li>a:hover{color:#fff;background-color:transparent}.navbar-inverse .navbar-nav .open .dropdown-menu>.active>a,.navbar-inverse .navbar-nav .open .dropdown-menu>.active>a:focus,.navbar-inverse .navbar-nav .open .dropdown-menu>.active>a:hover{color:#fff;background-color:#080808}.navbar-inverse .navbar-nav .open .dropdown-menu>.disabled>a,.navbar-inverse .navbar-nav .open .dropdown-menu>.disabled>a:focus,.navbar-inverse .navbar-nav .open .dropdown-menu>.disabled>a:hover{color:#444;background-color:transparent}}.navbar-inverse .navbar-link{color:#9d9d9d}.navbar-inverse .navbar-link:hover{color:#fff}.navbar-inverse .btn-link{color:#9d9d9d}.navbar-inverse .btn-link:focus,.navbar-inverse .btn-link:hover{color:#fff}.navbar-inverse .btn-link[disabled]:focus,.navbar-inverse .btn-link[disabled]:hover,fieldset[disabled] .navbar-inverse .btn-link:focus,fieldset[disabled] .navbar-inverse .btn-link:hover{color:#444}.breadcrumb{padding:8px 15px;margin-bottom:20px;list-style:none;background-color:#f5f5f5;border-radius:4px}.breadcrumb>li{display:inline-block}.breadcrumb>li+li:before{padding:0 5px;color:#ccc;content:"/\00a0"}.breadcrumb>.active{color:#777}.pagination{display:inline-block;padding-left:0;margin:20px 0;border-radius:4px}.pagination>li{display:inline}.pagination>li>a,.pagination>li>span{position:relative;float:left;padding:6px 12px;margin-left:-1px;line-height:1.42857143;color:#337ab7;text-decoration:none;background-color:#fff;border:1px solid #ddd}.pagination>li:first-child>a,.pagination>li:first-child>span{margin-left:0;border-top-left-radius:4px;border-bottom-left-radius:4px}.pagination>li:last-child>a,.pagination>li:last-child>span{border-top-right-radius:4px;border-bottom-right-radius:4px}.pagination>li>a:focus,.pagination>li>a:hover,.pagination>li>span:focus,.pagination>li>span:hover{color:#23527c;background-color:#eee;border-color:#ddd}.pagination>.active>a,.pagination>.active>a:focus,.pagination>.active>a:hover,.pagination>.active>span,.pagination>.active>span:focus,.pagination>.active>span:hover{z-index:2;color:#fff;cursor:default;background-color:#337ab7;border-color:#337ab7}.pagination>.disabled>a,.pagination>.disabled>a:focus,.pagination>.disabled>a:hover,.pagination>.disabled>span,.pagination>.disabled>span:focus,.pagination>.disabled>span:hover{color:#777;cursor:not-allowed;background-color:#fff;border-color:#ddd}.pagination-lg>li>a,.pagination-lg>li>span{padding:10px 16px;font-size:18px}.pagination-lg>li:first-child>a,.pagination-lg>li:first-child>span{border-top-left-radius:6px;border-bottom-left-radius:6px}.pagination-lg>li:last-child>a,.pagination-lg>li:last-child>span{border-top-right-radius:6px;border-bottom-right-radius:6px}.pagination-sm>li>a,.pagination-sm>li>span{padding:5px 10px;font-size:12px}.pagination-sm>li:first-child>a,.pagination-sm>li:first-child>span{border-top-left-radius:3px;border-bottom-left-radius:3px}.pagination-sm>li:last-child>a,.pagination-sm>li:last-child>span{border-top-right-radius:3px;border-bottom-right-radius:3px}.pager{padding-left:0;margin:20px 0;text-align:center;list-style:none}.pager li{display:inline}.pager li>a,.pager li>span{display:inline-block;padding:5px 14px;background-color:#fff;border:1px solid #ddd;border-radius:15px}.pager li>a:focus,.pager li>a:hover{text-decoration:none;background-color:#eee}.pager .next>a,.pager .next>span{float:right}.pager .previous>a,.pager .previous>span{float:left}.pager .disabled>a,.pager .disabled>a:focus,.pager .disabled>a:hover,.pager .disabled>span{color:#777;cursor:not-allowed;background-color:#fff}.label{display:inline;padding:.2em .6em .3em;font-size:75%;font-weight:700;line-height:1;color:#fff;text-align:center;white-space:nowrap;vertical-align:baseline;border-radius:.25em}a.label:focus,a.label:hover{color:#fff;text-decoration:none;cursor:pointer}.label:empty{display:none}.btn .label{position:relative;top:-1px}.label-default{background-color:#777}.label-default[href]:focus,.label-default[href]:hover{background-color:#5e5e5e}.label-primary{background-color:#337ab7}.label-primary[href]:focus,.label-primary[href]:hover{background-color:#286090}.label-success{background-color:#5cb85c}.label-success[href]:focus,.label-success[href]:hover{background-color:#449d44}.label-info{background-color:#5bc0de}.label-info[href]:focus,.label-info[href]:hover{background-color:#31b0d5}.label-warning{background-color:#f0ad4e}.label-warning[href]:focus,.label-warning[href]:hover{background-color:#ec971f}.label-danger{background-color:#d9534f}.label-danger[href]:focus,.label-danger[href]:hover{background-color:#c9302c}.badge{display:inline-block;min-width:10px;padding:3px 7px;font-size:12px;font-weight:700;line-height:1;color:#fff;text-align:center;white-space:nowrap;vertical-align:baseline;background-color:#777;border-radius:10px}.badge:empty{display:none}.btn .badge{position:relative;top:-1px}.btn-group-xs>.btn .badge,.btn-xs .badge{top:0;padding:1px 5px}a.badge:focus,a.badge:hover{color:#fff;text-decoration:none;cursor:pointer}.list-group-item.active>.badge,.nav-pills>.active>a>.badge{color:#337ab7;background-color:#fff}.list-group-item>.badge{float:right}.list-group-item>.badge+.badge{margin-right:5px}.nav-pills>li>a>.badge{margin-left:3px}.jumbotron{padding:30px 15px;margin-bottom:30px;color:inherit;background-color:#eee}.jumbotron .h1,.jumbotron h1{color:inherit}.jumbotron p{margin-bottom:15px;font-size:21px;font-weight:200}.jumbotron>hr{border-top-color:#d5d5d5}.container .jumbotron,.container-fluid .jumbotron{border-radius:6px}.jumbotron .container{max-width:100%}@media screen and (min-width:768px){.jumbotron{padding:48px 0}.container .jumbotron,.container-fluid .jumbotron{padding-right:60px;padding-left:60px}.jumbotron .h1,.jumbotron h1{font-size:63px}}.thumbnail{display:block;padding:4px;margin-bottom:20px;line-height:1.42857143;background-color:#fff;border:1px solid #ddd;border-radius:4px;-webkit-transition:border .2s ease-in-out;-o-transition:border .2s ease-in-out;transition:border .2s ease-in-out}.thumbnail a>img,.thumbnail>img{margin-right:auto;margin-left:auto}a.thumbnail.active,a.thumbnail:focus,a.thumbnail:hover{border-color:#337ab7}.thumbnail .caption{padding:9px;color:#333}.alert{padding:15px;margin-bottom:20px;border:1px solid transparent;border-radius:4px}.alert h4{margin-top:0;color:inherit}.alert .alert-link{font-weight:700}.alert>p,.alert>ul{margin-bottom:0}.alert>p+p{margin-top:5px}.alert-dismissable,.alert-dismissible{padding-right:35px}.alert-dismissable .close,.alert-dismissible .close{position:relative;top:-2px;right:-21px;color:inherit}.alert-success{color:#3c763d;background-color:#dff0d8;border-color:#d6e9c6}.alert-success hr{border-top-color:#c9e2b3}.alert-success .alert-link{color:#2b542c}.alert-info{color:#31708f;background-color:#d9edf7;border-color:#bce8f1}.alert-info hr{border-top-color:#a6e1ec}.alert-info .alert-link{color:#245269}.alert-warning{color:#8a6d3b;background-color:#fcf8e3;border-color:#faebcc}.alert-warning hr{border-top-color:#f7e1b5}.alert-warning .alert-link{color:#66512c}.alert-danger{color:#a94442;background-color:#f2dede;border-color:#ebccd1}.alert-danger hr{border-top-color:#e4b9c0}.alert-danger .alert-link{color:#843534}@-webkit-keyframes progress-bar-stripes{from{background-position:40px 0}to{background-position:0 0}}@-o-keyframes progress-bar-stripes{from{background-position:40px 0}to{background-position:0 0}}@keyframes progress-bar-stripes{from{background-position:40px 0}to{background-position:0 0}}.progress{height:20px;margin-bottom:20px;overflow:hidden;background-color:#f5f5f5;border-radius:4px;-webkit-box-shadow:inset 0 1px 2px rgba(0,0,0,.1);box-shadow:inset 0 1px 2px rgba(0,0,0,.1)}.progress-bar{float:left;width:0;height:100%;font-size:12px;line-height:20px;color:#fff;text-align:center;background-color:#337ab7;-webkit-box-shadow:inset 0 -1px 0 rgba(0,0,0,.15);box-shadow:inset 0 -1px 0 rgba(0,0,0,.15);-webkit-transition:width .6s ease;-o-transition:width .6s ease;transition:width .6s ease}.progress-bar-striped,.progress-striped .progress-bar{background-image:-webkit-linear-gradient(45deg,rgba(255,255,255,.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,.15) 50%,rgba(255,255,255,.15) 75%,transparent 75%,transparent);background-image:-o-linear-gradient(45deg,rgba(255,255,255,.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,.15) 50%,rgba(255,255,255,.15) 75%,transparent 75%,transparent);background-image:linear-gradient(45deg,rgba(255,255,255,.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,.15) 50%,rgba(255,255,255,.15) 75%,transparent 75%,transparent);-webkit-background-size:40px 40px;background-size:40px 40px}.progress-bar.active,.progress.active .progress-bar{-webkit-animation:progress-bar-stripes 2s linear infinite;-o-animation:progress-bar-stripes 2s linear infinite;animation:progress-bar-stripes 2s linear infinite}.progress-bar-success{background-color:#5cb85c}.progress-striped .progress-bar-success{background-image:-webkit-linear-gradient(45deg,rgba(255,255,255,.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,.15) 50%,rgba(255,255,255,.15) 75%,transparent 75%,transparent);background-image:-o-linear-gradient(45deg,rgba(255,255,255,.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,.15) 50%,rgba(255,255,255,.15) 75%,transparent 75%,transparent);background-image:linear-gradient(45deg,rgba(255,255,255,.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,.15) 50%,rgba(255,255,255,.15) 75%,transparent 75%,transparent)}.progress-bar-info{background-color:#5bc0de}.progress-striped .progress-bar-info{background-image:-webkit-linear-gradient(45deg,rgba(255,255,255,.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,.15) 50%,rgba(255,255,255,.15) 75%,transparent 75%,transparent);background-image:-o-linear-gradient(45deg,rgba(255,255,255,.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,.15) 50%,rgba(255,255,255,.15) 75%,transparent 75%,transparent);background-image:linear-gradient(45deg,rgba(255,255,255,.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,.15) 50%,rgba(255,255,255,.15) 75%,transparent 75%,transparent)}.progress-bar-warning{background-color:#f0ad4e}.progress-striped .progress-bar-warning{background-image:-webkit-linear-gradient(45deg,rgba(255,255,255,.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,.15) 50%,rgba(255,255,255,.15) 75%,transparent 75%,transparent);background-image:-o-linear-gradient(45deg,rgba(255,255,255,.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,.15) 50%,rgba(255,255,255,.15) 75%,transparent 75%,transparent);background-image:linear-gradient(45deg,rgba(255,255,255,.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,.15) 50%,rgba(255,255,255,.15) 75%,transparent 75%,transparent)}.progress-bar-danger{background-color:#d9534f}.progress-striped .progress-bar-danger{background-image:-webkit-linear-gradient(45deg,rgba(255,255,255,.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,.15) 50%,rgba(255,255,255,.15) 75%,transparent 75%,transparent);background-image:-o-linear-gradient(45deg,rgba(255,255,255,.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,.15) 50%,rgba(255,255,255,.15) 75%,transparent 75%,transparent);background-image:linear-gradient(45deg,rgba(255,255,255,.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,.15) 50%,rgba(255,255,255,.15) 75%,transparent 75%,transparent)}.media{margin-top:15px}.media:first-child{margin-top:0}.media,.media-body{overflow:hidden;zoom:1}.media-body{width:10000px}.media-object{display:block}.media-right,.media>.pull-right{padding-left:10px}.media-left,.media>.pull-left{padding-right:10px}.media-body,.media-left,.media-right{display:table-cell;vertical-align:top}.media-middle{vertical-align:middle}.media-bottom{vertical-align:bottom}.media-heading{margin-top:0;margin-bottom:5px}.media-list{padding-left:0;list-style:none}.list-group{padding-left:0;margin-bottom:20px}.list-group-item{position:relative;display:block;padding:10px 15px;margin-bottom:-1px;background-color:#fff;border:1px solid #ddd}.list-group-item:first-child{border-top-left-radius:4px;border-top-right-radius:4px}.list-group-item:last-child{margin-bottom:0;border-bottom-right-radius:4px;border-bottom-left-radius:4px}a.list-group-item{color:#555}a.list-group-item .list-group-item-heading{color:#333}a.list-group-item:focus,a.list-group-item:hover{color:#555;text-decoration:none;background-color:#f5f5f5}.list-group-item.disabled,.list-group-item.disabled:focus,.list-group-item.disabled:hover{color:#777;cursor:not-allowed;background-color:#eee}.list-group-item.disabled .list-group-item-heading,.list-group-item.disabled:focus .list-group-item-heading,.list-group-item.disabled:hover .list-group-item-heading{color:inherit}.list-group-item.disabled .list-group-item-text,.list-group-item.disabled:focus .list-group-item-text,.list-group-item.disabled:hover .list-group-item-text{color:#777}.list-group-item.active,.list-group-item.active:focus,.list-group-item.active:hover{z-index:2;color:#fff;background-color:#337ab7;border-color:#337ab7}.list-group-item.active .list-group-item-heading,.list-group-item.active .list-group-item-heading>.small,.list-group-item.active .list-group-item-heading>small,.list-group-item.active:focus .list-group-item-heading,.list-group-item.active:focus .list-group-item-heading>.small,.list-group-item.active:focus .list-group-item-heading>small,.list-group-item.active:hover .list-group-item-heading,.list-group-item.active:hover .list-group-item-heading>.small,.list-group-item.active:hover .list-group-item-heading>small{color:inherit}.list-group-item.active .list-group-item-text,.list-group-item.active:focus .list-group-item-text,.list-group-item.active:hover .list-group-item-text{color:#c7ddef}.list-group-item-success{color:#3c763d;background-color:#dff0d8}a.list-group-item-success{color:#3c763d}a.list-group-item-success .list-group-item-heading{color:inherit}a.list-group-item-success:focus,a.list-group-item-success:hover{color:#3c763d;background-color:#d0e9c6}a.list-group-item-success.active,a.list-group-item-success.active:focus,a.list-group-item-success.active:hover{color:#fff;background-color:#3c763d;border-color:#3c763d}.list-group-item-info{color:#31708f;background-color:#d9edf7}a.list-group-item-info{color:#31708f}a.list-group-item-info .list-group-item-heading{color:inherit}a.list-group-item-info:focus,a.list-group-item-info:hover{color:#31708f;background-color:#c4e3f3}a.list-group-item-info.active,a.list-group-item-info.active:focus,a.list-group-item-info.active:hover{color:#fff;background-color:#31708f;border-color:#31708f}.list-group-item-warning{color:#8a6d3b;background-color:#fcf8e3}a.list-group-item-warning{color:#8a6d3b}a.list-group-item-warning .list-group-item-heading{color:inherit}a.list-group-item-warning:focus,a.list-group-item-warning:hover{color:#8a6d3b;background-color:#faf2cc}a.list-group-item-warning.active,a.list-group-item-warning.active:focus,a.list-group-item-warning.active:hover{color:#fff;background-color:#8a6d3b;border-color:#8a6d3b}.list-group-item-danger{color:#a94442;background-color:#f2dede}a.list-group-item-danger{color:#a94442}a.list-group-item-danger .list-group-item-heading{color:inherit}a.list-group-item-danger:focus,a.list-group-item-danger:hover{color:#a94442;background-color:#ebcccc}a.list-group-item-danger.active,a.list-group-item-danger.active:focus,a.list-group-item-danger.active:hover{color:#fff;background-color:#a94442;border-color:#a94442}.list-group-item-heading{margin-top:0;margin-bottom:5px}.list-group-item-text{margin-bottom:0;line-height:1.3}.panel{margin-bottom:20px;background-color:#fff;border:1px solid transparent;border-radius:4px;-webkit-box-shadow:0 1px 1px rgba(0,0,0,.05);box-shadow:0 1px 1px rgba(0,0,0,.05)}.panel-body{padding:15px}.panel-heading{padding:10px 15px;border-bottom:1px solid transparent;border-top-left-radius:3px;border-top-right-radius:3px}.panel-heading>.dropdown .dropdown-toggle{color:inherit}.panel-title{margin-top:0;margin-bottom:0;font-size:16px;color:inherit}.panel-title>.small,.panel-title>.small>a,.panel-title>a,.panel-title>small,.panel-title>small>a{color:inherit}.panel-footer{padding:10px 15px;background-color:#f5f5f5;border-top:1px solid #ddd;border-bottom-right-radius:3px;border-bottom-left-radius:3px}.panel>.list-group,.panel>.panel-collapse>.list-group{margin-bottom:0}.panel>.list-group .list-group-item,.panel>.panel-collapse>.list-group .list-group-item{border-width:1px 0;border-radius:0}.panel>.list-group:first-child .list-group-item:first-child,.panel>.panel-collapse>.list-group:first-child .list-group-item:first-child{border-top:0;border-top-left-radius:3px;border-top-right-radius:3px}.panel>.list-group:last-child .list-group-item:last-child,.panel>.panel-collapse>.list-group:last-child .list-group-item:last-child{border-bottom:0;border-bottom-right-radius:3px;border-bottom-left-radius:3px}.panel-heading+.list-group .list-group-item:first-child{border-top-width:0}.list-group+.panel-footer{border-top-width:0}.panel>.panel-collapse>.table,.panel>.table,.panel>.table-responsive>.table{margin-bottom:0}.panel>.panel-collapse>.table caption,.panel>.table caption,.panel>.table-responsive>.table caption{padding-right:15px;padding-left:15px}.panel>.table-responsive:first-child>.table:first-child,.panel>.table:first-child{border-top-left-radius:3px;border-top-right-radius:3px}.panel>.table-responsive:first-child>.table:first-child>tbody:first-child>tr:first-child,.panel>.table-responsive:first-child>.table:first-child>thead:first-child>tr:first-child,.panel>.table:first-child>tbody:first-child>tr:first-child,.panel>.table:first-child>thead:first-child>tr:first-child{border-top-left-radius:3px;border-top-right-radius:3px}.panel>.table-responsive:first-child>.table:first-child>tbody:first-child>tr:first-child td:first-child,.panel>.table-responsive:first-child>.table:first-child>tbody:first-child>tr:first-child th:first-child,.panel>.table-responsive:first-child>.table:first-child>thead:first-child>tr:first-child td:first-child,.panel>.table-responsive:first-child>.table:first-child>thead:first-child>tr:first-child th:first-child,.panel>.table:first-child>tbody:first-child>tr:first-child td:first-child,.panel>.table:first-child>tbody:first-child>tr:first-child th:first-child,.panel>.table:first-child>thead:first-child>tr:first-child td:first-child,.panel>.table:first-child>thead:first-child>tr:first-child th:first-child{border-top-left-radius:3px}.panel>.table-responsive:first-child>.table:first-child>tbody:first-child>tr:first-child td:last-child,.panel>.table-responsive:first-child>.table:first-child>tbody:first-child>tr:first-child th:last-child,.panel>.table-responsive:first-child>.table:first-child>thead:first-child>tr:first-child td:last-child,.panel>.table-responsive:first-child>.table:first-child>thead:first-child>tr:first-child th:last-child,.panel>.table:first-child>tbody:first-child>tr:first-child td:last-child,.panel>.table:first-child>tbody:first-child>tr:first-child th:last-child,.panel>.table:first-child>thead:first-child>tr:first-child td:last-child,.panel>.table:first-child>thead:first-child>tr:first-child th:last-child{border-top-right-radius:3px}.panel>.table-responsive:last-child>.table:last-child,.panel>.table:last-child{border-bottom-right-radius:3px;border-bottom-left-radius:3px}.panel>.table-responsive:last-child>.table:last-child>tbody:last-child>tr:last-child,.panel>.table-responsive:last-child>.table:last-child>tfoot:last-child>tr:last-child,.panel>.table:last-child>tbody:last-child>tr:last-child,.panel>.table:last-child>tfoot:last-child>tr:last-child{border-bottom-right-radius:3px;border-bottom-left-radius:3px}.panel>.table-responsive:last-child>.table:last-child>tbody:last-child>tr:last-child td:first-child,.panel>.table-responsive:last-child>.table:last-child>tbody:last-child>tr:last-child th:first-child,.panel>.table-responsive:last-child>.table:last-child>tfoot:last-child>tr:last-child td:first-child,.panel>.table-responsive:last-child>.table:last-child>tfoot:last-child>tr:last-child th:first-child,.panel>.table:last-child>tbody:last-child>tr:last-child td:first-child,.panel>.table:last-child>tbody:last-child>tr:last-child th:first-child,.panel>.table:last-child>tfoot:last-child>tr:last-child td:first-child,.panel>.table:last-child>tfoot:last-child>tr:last-child th:first-child{border-bottom-left-radius:3px}.panel>.table-responsive:last-child>.table:last-child>tbody:last-child>tr:last-child td:last-child,.panel>.table-responsive:last-child>.table:last-child>tbody:last-child>tr:last-child th:last-child,.panel>.table-responsive:last-child>.table:last-child>tfoot:last-child>tr:last-child td:last-child,.panel>.table-responsive:last-child>.table:last-child>tfoot:last-child>tr:last-child th:last-child,.panel>.table:last-child>tbody:last-child>tr:last-child td:last-child,.panel>.table:last-child>tbody:last-child>tr:last-child th:last-child,.panel>.table:last-child>tfoot:last-child>tr:last-child td:last-child,.panel>.table:last-child>tfoot:last-child>tr:last-child th:last-child{border-bottom-right-radius:3px}.panel>.panel-body+.table,.panel>.panel-body+.table-responsive,.panel>.table+.panel-body,.panel>.table-responsive+.panel-body{border-top:1px solid #ddd}.panel>.table>tbody:first-child>tr:first-child td,.panel>.table>tbody:first-child>tr:first-child th{border-top:0}.panel>.table-bordered,.panel>.table-responsive>.table-bordered{border:0}.panel>.table-bordered>tbody>tr>td:first-child,.panel>.table-bordered>tbody>tr>th:first-child,.panel>.table-bordered>tfoot>tr>td:first-child,.panel>.table-bordered>tfoot>tr>th:first-child,.panel>.table-bordered>thead>tr>td:first-child,.panel>.table-bordered>thead>tr>th:first-child,.panel>.table-responsive>.table-bordered>tbody>tr>td:first-child,.panel>.table-responsive>.table-bordered>tbody>tr>th:first-child,.panel>.table-responsive>.table-bordered>tfoot>tr>td:first-child,.panel>.table-responsive>.table-bordered>tfoot>tr>th:first-child,.panel>.table-responsive>.table-bordered>thead>tr>td:first-child,.panel>.table-responsive>.table-bordered>thead>tr>th:first-child{border-left:0}.panel>.table-bordered>tbody>tr>td:last-child,.panel>.table-bordered>tbody>tr>th:last-child,.panel>.table-bordered>tfoot>tr>td:last-child,.panel>.table-bordered>tfoot>tr>th:last-child,.panel>.table-bordered>thead>tr>td:last-child,.panel>.table-bordered>thead>tr>th:last-child,.panel>.table-responsive>.table-bordered>tbody>tr>td:last-child,.panel>.table-responsive>.table-bordered>tbody>tr>th:last-child,.panel>.table-responsive>.table-bordered>tfoot>tr>td:last-child,.panel>.table-responsive>.table-bordered>tfoot>tr>th:last-child,.panel>.table-responsive>.table-bordered>thead>tr>td:last-child,.panel>.table-responsive>.table-bordered>thead>tr>th:last-child{border-right:0}.panel>.table-bordered>tbody>tr:first-child>td,.panel>.table-bordered>tbody>tr:first-child>th,.panel>.table-bordered>thead>tr:first-child>td,.panel>.table-bordered>thead>tr:first-child>th,.panel>.table-responsive>.table-bordered>tbody>tr:first-child>td,.panel>.table-responsive>.table-bordered>tbody>tr:first-child>th,.panel>.table-responsive>.table-bordered>thead>tr:first-child>td,.panel>.table-responsive>.table-bordered>thead>tr:first-child>th{border-bottom:0}.panel>.table-bordered>tbody>tr:last-child>td,.panel>.table-bordered>tbody>tr:last-child>th,.panel>.table-bordered>tfoot>tr:last-child>td,.panel>.table-bordered>tfoot>tr:last-child>th,.panel>.table-responsive>.table-bordered>tbody>tr:last-child>td,.panel>.table-responsive>.table-bordered>tbody>tr:last-child>th,.panel>.table-responsive>.table-bordered>tfoot>tr:last-child>td,.panel>.table-responsive>.table-bordered>tfoot>tr:last-child>th{border-bottom:0}.panel>.table-responsive{margin-bottom:0;border:0}.panel-group{margin-bottom:20px}.panel-group .panel{margin-bottom:0;border-radius:4px}.panel-group .panel+.panel{margin-top:5px}.panel-group .panel-heading{border-bottom:0}.panel-group .panel-heading+.panel-collapse>.list-group,.panel-group .panel-heading+.panel-collapse>.panel-body{border-top:1px solid #ddd}.panel-group .panel-footer{border-top:0}.panel-group .panel-footer+.panel-collapse .panel-body{border-bottom:1px solid #ddd}.panel-default{border-color:#ddd}.panel-default>.panel-heading{color:#333;background-color:#f5f5f5;border-color:#ddd}.panel-default>.panel-heading+.panel-collapse>.panel-body{border-top-color:#ddd}.panel-default>.panel-heading .badge{color:#f5f5f5;background-color:#333}.panel-default>.panel-footer+.panel-collapse>.panel-body{border-bottom-color:#ddd}.panel-primary{border-color:#337ab7}.panel-primary>.panel-heading{color:#fff;background-color:#337ab7;border-color:#337ab7}.panel-primary>.panel-heading+.panel-collapse>.panel-body{border-top-color:#337ab7}.panel-primary>.panel-heading .badge{color:#337ab7;background-color:#fff}.panel-primary>.panel-footer+.panel-collapse>.panel-body{border-bottom-color:#337ab7}.panel-success{border-color:#d6e9c6}.panel-success>.panel-heading{color:#3c763d;background-color:#dff0d8;border-color:#d6e9c6}.panel-success>.panel-heading+.panel-collapse>.panel-body{border-top-color:#d6e9c6}.panel-success>.panel-heading .badge{color:#dff0d8;background-color:#3c763d}.panel-success>.panel-footer+.panel-collapse>.panel-body{border-bottom-color:#d6e9c6}.panel-info{border-color:#bce8f1}.panel-info>.panel-heading{color:#31708f;background-color:#d9edf7;border-color:#bce8f1}.panel-info>.panel-heading+.panel-collapse>.panel-body{border-top-color:#bce8f1}.panel-info>.panel-heading .badge{color:#d9edf7;background-color:#31708f}.panel-info>.panel-footer+.panel-collapse>.panel-body{border-bottom-color:#bce8f1}.panel-warning{border-color:#faebcc}.panel-warning>.panel-heading{color:#8a6d3b;background-color:#fcf8e3;border-color:#faebcc}.panel-warning>.panel-heading+.panel-collapse>.panel-body{border-top-color:#faebcc}.panel-warning>.panel-heading .badge{color:#fcf8e3;background-color:#8a6d3b}.panel-warning>.panel-footer+.panel-collapse>.panel-body{border-bottom-color:#faebcc}.panel-danger{border-color:#ebccd1}.panel-danger>.panel-heading{color:#a94442;background-color:#f2dede;border-color:#ebccd1}.panel-danger>.panel-heading+.panel-collapse>.panel-body{border-top-color:#ebccd1}.panel-danger>.panel-heading .badge{color:#f2dede;background-color:#a94442}.panel-danger>.panel-footer+.panel-collapse>.panel-body{border-bottom-color:#ebccd1}.embed-responsive{position:relative;display:block;height:0;padding:0;overflow:hidden}.embed-responsive .embed-responsive-item,.embed-responsive embed,.embed-responsive iframe,.embed-responsive object,.embed-responsive video{position:absolute;top:0;bottom:0;left:0;width:100%;height:100%;border:0}.embed-responsive-16by9{padding-bottom:56.25%}.embed-responsive-4by3{padding-bottom:75%}.well{min-height:20px;padding:19px;margin-bottom:20px;background-color:#f5f5f5;border:1px solid #e3e3e3;border-radius:4px;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,.05);box-shadow:inset 0 1px 1px rgba(0,0,0,.05)}.well blockquote{border-color:#ddd;border-color:rgba(0,0,0,.15)}.well-lg{padding:24px;border-radius:6px}.well-sm{padding:9px;border-radius:3px}.close{float:right;font-size:21px;font-weight:700;line-height:1;color:#000;text-shadow:0 1px 0 #fff;filter:alpha(opacity=20);opacity:.2}.close:focus,.close:hover{color:#000;text-decoration:none;cursor:pointer;filter:alpha(opacity=50);opacity:.5}button.close{-webkit-appearance:none;padding:0;cursor:pointer;background:0 0;border:0}.modal-open{overflow:hidden}.modal{position:fixed;top:0;right:0;bottom:0;left:0;z-index:1050;display:none;overflow:hidden;-webkit-overflow-scrolling:touch;outline:0}.modal.fade .modal-dialog{-webkit-transition:-webkit-transform .3s ease-out;-o-transition:-o-transform .3s ease-out;transition:transform .3s ease-out;-webkit-transform:translate(0,-25%);-ms-transform:translate(0,-25%);-o-transform:translate(0,-25%);transform:translate(0,-25%)}.modal.in .modal-dialog{-webkit-transform:translate(0,0);-ms-transform:translate(0,0);-o-transform:translate(0,0);transform:translate(0,0)}.modal-open .modal{overflow-x:hidden;overflow-y:auto}.modal-dialog{position:relative;width:auto;margin:10px}.modal-content{position:relative;background-color:#fff;-webkit-background-clip:padding-box;background-clip:padding-box;border:1px solid #999;border:1px solid rgba(0,0,0,.2);border-radius:6px;outline:0;-webkit-box-shadow:0 3px 9px rgba(0,0,0,.5);box-shadow:0 3px 9px rgba(0,0,0,.5)}.modal-backdrop{position:fixed;top:0;right:0;bottom:0;left:0;z-index:1040;background-color:#000}.modal-backdrop.fade{filter:alpha(opacity=0);opacity:0}.modal-backdrop.in{filter:alpha(opacity=50);opacity:.5}.modal-header{min-height:16.43px;padding:15px;border-bottom:1px solid #e5e5e5}.modal-header .close{margin-top:-2px}.modal-title{margin:0;line-height:1.42857143}.modal-body{position:relative;padding:15px}.modal-footer{padding:15px;text-align:right;border-top:1px solid #e5e5e5}.modal-footer .btn+.btn{margin-bottom:0;margin-left:5px}.modal-footer .btn-group .btn+.btn{margin-left:-1px}.modal-footer .btn-block+.btn-block{margin-left:0}.modal-scrollbar-measure{position:absolute;top:-9999px;width:50px;height:50px;overflow:scroll}@media (min-width:768px){.modal-dialog{width:600px;margin:30px auto}.modal-content{-webkit-box-shadow:0 5px 15px rgba(0,0,0,.5);box-shadow:0 5px 15px rgba(0,0,0,.5)}.modal-sm{width:300px}}@media (min-width:992px){.modal-lg{width:900px}}.tooltip{position:absolute;z-index:1070;display:block;font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:12px;font-weight:400;line-height:1.4;filter:alpha(opacity=0);opacity:0}.tooltip.in{filter:alpha(opacity=90);opacity:.9}.tooltip.top{padding:5px 0;margin-top:-3px}.tooltip.right{padding:0 5px;margin-left:3px}.tooltip.bottom{padding:5px 0;margin-top:3px}.tooltip.left{padding:0 5px;margin-left:-3px}.tooltip-inner{max-width:200px;padding:3px 8px;color:#fff;text-align:center;text-decoration:none;background-color:#000;border-radius:4px}.tooltip-arrow{position:absolute;width:0;height:0;border-color:transparent;border-style:solid}.tooltip.top .tooltip-arrow{bottom:0;left:50%;margin-left:-5px;border-width:5px 5px 0;border-top-color:#000}.tooltip.top-left .tooltip-arrow{right:5px;bottom:0;margin-bottom:-5px;border-width:5px 5px 0;border-top-color:#000}.tooltip.top-right .tooltip-arrow{bottom:0;left:5px;margin-bottom:-5px;border-width:5px 5px 0;border-top-color:#000}.tooltip.right .tooltip-arrow{top:50%;left:0;margin-top:-5px;border-width:5px 5px 5px 0;border-right-color:#000}.tooltip.left .tooltip-arrow{top:50%;right:0;margin-top:-5px;border-width:5px 0 5px 5px;border-left-color:#000}.tooltip.bottom .tooltip-arrow{top:0;left:50%;margin-left:-5px;border-width:0 5px 5px;border-bottom-color:#000}.tooltip.bottom-left .tooltip-arrow{top:0;right:5px;margin-top:-5px;border-width:0 5px 5px;border-bottom-color:#000}.tooltip.bottom-right .tooltip-arrow{top:0;left:5px;margin-top:-5px;border-width:0 5px 5px;border-bottom-color:#000}.popover{position:absolute;top:0;left:0;z-index:1060;display:none;max-width:276px;padding:1px;font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:14px;font-weight:400;line-height:1.42857143;text-align:left;white-space:normal;background-color:#fff;-webkit-background-clip:padding-box;background-clip:padding-box;border:1px solid #ccc;border:1px solid rgba(0,0,0,.2);border-radius:6px;-webkit-box-shadow:0 5px 10px rgba(0,0,0,.2);box-shadow:0 5px 10px rgba(0,0,0,.2)}.popover.top{margin-top:-10px}.popover.right{margin-left:10px}.popover.bottom{margin-top:10px}.popover.left{margin-left:-10px}.popover-title{padding:8px 14px;margin:0;font-size:14px;background-color:#f7f7f7;border-bottom:1px solid #ebebeb;border-radius:5px 5px 0 0}.popover-content{padding:9px 14px}.popover>.arrow,.popover>.arrow:after{position:absolute;display:block;width:0;height:0;border-color:transparent;border-style:solid}.popover>.arrow{border-width:11px}.popover>.arrow:after{content:"";border-width:10px}.popover.top>.arrow{bottom:-11px;left:50%;margin-left:-11px;border-top-color:#999;border-top-color:rgba(0,0,0,.25);border-bottom-width:0}.popover.top>.arrow:after{bottom:1px;margin-left:-10px;content:" ";border-top-color:#fff;border-bottom-width:0}.popover.right>.arrow{top:50%;left:-11px;margin-top:-11px;border-right-color:#999;border-right-color:rgba(0,0,0,.25);border-left-width:0}.popover.right>.arrow:after{bottom:-10px;left:1px;content:" ";border-right-color:#fff;border-left-width:0}.popover.bottom>.arrow{top:-11px;left:50%;margin-left:-11px;border-top-width:0;border-bottom-color:#999;border-bottom-color:rgba(0,0,0,.25)}.popover.bottom>.arrow:after{top:1px;margin-left:-10px;content:" ";border-top-width:0;border-bottom-color:#fff}.popover.left>.arrow{top:50%;right:-11px;margin-top:-11px;border-right-width:0;border-left-color:#999;border-left-color:rgba(0,0,0,.25)}.popover.left>.arrow:after{right:1px;bottom:-10px;content:" ";border-right-width:0;border-left-color:#fff}.carousel{position:relative}.carousel-inner{position:relative;width:100%;overflow:hidden}.carousel-inner>.item{position:relative;display:none;-webkit-transition:.6s ease-in-out left;-o-transition:.6s ease-in-out left;transition:.6s ease-in-out left}.carousel-inner>.item>a>img,.carousel-inner>.item>img{line-height:1}@media all and (transform-3d),(-webkit-transform-3d){.carousel-inner>.item{-webkit-transition:-webkit-transform .6s ease-in-out;-o-transition:-o-transform .6s ease-in-out;transition:transform .6s ease-in-out;-webkit-backface-visibility:hidden;backface-visibility:hidden;-webkit-perspective:1000;perspective:1000}.carousel-inner>.item.active.right,.carousel-inner>.item.next{left:0;-webkit-transform:translate3d(100%,0,0);transform:translate3d(100%,0,0)}.carousel-inner>.item.active.left,.carousel-inner>.item.prev{left:0;-webkit-transform:translate3d(-100%,0,0);transform:translate3d(-100%,0,0)}.carousel-inner>.item.active,.carousel-inner>.item.next.left,.carousel-inner>.item.prev.right{left:0;-webkit-transform:translate3d(0,0,0);transform:translate3d(0,0,0)}}.carousel-inner>.active,.carousel-inner>.next,.carousel-inner>.prev{display:block}.carousel-inner>.active{left:0}.carousel-inner>.next,.carousel-inner>.prev{position:absolute;top:0;width:100%}.carousel-inner>.next{left:100%}.carousel-inner>.prev{left:-100%}.carousel-inner>.next.left,.carousel-inner>.prev.right{left:0}.carousel-inner>.active.left{left:-100%}.carousel-inner>.active.right{left:100%}.carousel-control{position:absolute;top:0;bottom:0;left:0;width:15%;font-size:20px;color:#fff;text-align:center;text-shadow:0 1px 2px rgba(0,0,0,.6);filter:alpha(opacity=50);opacity:.5}.carousel-control.left{background-image:-webkit-linear-gradient(left,rgba(0,0,0,.5) 0,rgba(0,0,0,.0001) 100%);background-image:-o-linear-gradient(left,rgba(0,0,0,.5) 0,rgba(0,0,0,.0001) 100%);background-image:-webkit-gradient(linear,left top,right top,from(rgba(0,0,0,.5)),to(rgba(0,0,0,.0001)));background-image:linear-gradient(to right,rgba(0,0,0,.5) 0,rgba(0,0,0,.0001) 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#80000000', endColorstr='#00000000', GradientType=1);background-repeat:repeat-x}.carousel-control.right{right:0;left:auto;background-image:-webkit-linear-gradient(left,rgba(0,0,0,.0001) 0,rgba(0,0,0,.5) 100%);background-image:-o-linear-gradient(left,rgba(0,0,0,.0001) 0,rgba(0,0,0,.5) 100%);background-image:-webkit-gradient(linear,left top,right top,from(rgba(0,0,0,.0001)),to(rgba(0,0,0,.5)));background-image:linear-gradient(to right,rgba(0,0,0,.0001) 0,rgba(0,0,0,.5) 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#00000000', endColorstr='#80000000', GradientType=1);background-repeat:repeat-x}.carousel-control:focus,.carousel-control:hover{color:#fff;text-decoration:none;filter:alpha(opacity=90);outline:0;opacity:.9}.carousel-control .glyphicon-chevron-left,.carousel-control .glyphicon-chevron-right,.carousel-control .icon-next,.carousel-control .icon-prev{position:absolute;top:50%;z-index:5;display:inline-block}.carousel-control .glyphicon-chevron-left,.carousel-control .icon-prev{left:50%;margin-left:-10px}.carousel-control .glyphicon-chevron-right,.carousel-control .icon-next{right:50%;margin-right:-10px}.carousel-control .icon-next,.carousel-control .icon-prev{width:20px;height:20px;margin-top:-10px;font-family:serif;line-height:1}.carousel-control .icon-prev:before{content:'\2039'}.carousel-control .icon-next:before{content:'\203a'}.carousel-indicators{position:absolute;bottom:10px;left:50%;z-index:15;width:60%;padding-left:0;margin-left:-30%;text-align:center;list-style:none}.carousel-indicators li{display:inline-block;width:10px;height:10px;margin:1px;text-indent:-999px;cursor:pointer;background-color:#000 \9;background-color:rgba(0,0,0,0);border:1px solid #fff;border-radius:10px}.carousel-indicators .active{width:12px;height:12px;margin:0;background-color:#fff}.carousel-caption{position:absolute;right:15%;bottom:20px;left:15%;z-index:10;padding-top:20px;padding-bottom:20px;color:#fff;text-align:center;text-shadow:0 1px 2px rgba(0,0,0,.6)}.carousel-caption .btn{text-shadow:none}@media screen and (min-width:768px){.carousel-control .glyphicon-chevron-left,.carousel-control .glyphicon-chevron-right,.carousel-control .icon-next,.carousel-control .icon-prev{width:30px;height:30px;margin-top:-15px;font-size:30px}.carousel-control .glyphicon-chevron-left,.carousel-control .icon-prev{margin-left:-15px}.carousel-control .glyphicon-chevron-right,.carousel-control .icon-next{margin-right:-15px}.carousel-caption{right:20%;left:20%;padding-bottom:30px}.carousel-indicators{bottom:20px}}.btn-group-vertical>.btn-group:after,.btn-group-vertical>.btn-group:before,.btn-toolbar:after,.btn-toolbar:before,.clearfix:after,.clearfix:before,.container-fluid:after,.container-fluid:before,.container:after,.container:before,.dl-horizontal dd:after,.dl-horizontal dd:before,.form-horizontal .form-group:after,.form-horizontal .form-group:before,.modal-footer:after,.modal-footer:before,.nav:after,.nav:before,.navbar-collapse:after,.navbar-collapse:before,.navbar-header:after,.navbar-header:before,.navbar:after,.navbar:before,.pager:after,.pager:before,.panel-body:after,.panel-body:before,.row:after,.row:before{display:table;content:" "}.btn-group-vertical>.btn-group:after,.btn-toolbar:after,.clearfix:after,.container-fluid:after,.container:after,.dl-horizontal dd:after,.form-horizontal .form-group:after,.modal-footer:after,.nav:after,.navbar-collapse:after,.navbar-header:after,.navbar:after,.pager:after,.panel-body:after,.row:after{clear:both}.center-block{display:block;margin-right:auto;margin-left:auto}.pull-right{float:right!important}.pull-left{float:left!important}.hide{display:none!important}.show{display:block!important}.invisible{visibility:hidden}.text-hide{font:0/0 a;color:transparent;text-shadow:none;background-color:transparent;border:0}.hidden{display:none!important}.affix{position:fixed}@-ms-viewport{width:device-width}.visible-lg,.visible-md,.visible-sm,.visible-xs{display:none!important}.visible-lg-block,.visible-lg-inline,.visible-lg-inline-block,.visible-md-block,.visible-md-inline,.visible-md-inline-block,.visible-sm-block,.visible-sm-inline,.visible-sm-inline-block,.visible-xs-block,.visible-xs-inline,.visible-xs-inline-block{display:none!important}@media (max-width:767px){.visible-xs{display:block!important}table.visible-xs{display:table}tr.visible-xs{display:table-row!important}td.visible-xs,th.visible-xs{display:table-cell!important}}@media (max-width:767px){.visible-xs-block{display:block!important}}@media (max-width:767px){.visible-xs-inline{display:inline!important}}@media (max-width:767px){.visible-xs-inline-block{display:inline-block!important}}@media (min-width:768px)and (max-width:991px){.visible-sm{display:block!important}table.visible-sm{display:table}tr.visible-sm{display:table-row!important}td.visible-sm,th.visible-sm{display:table-cell!important}}@media (min-width:768px)and (max-width:991px){.visible-sm-block{display:block!important}}@media (min-width:768px)and (max-width:991px){.visible-sm-inline{display:inline!important}}@media (min-width:768px)and (max-width:991px){.visible-sm-inline-block{display:inline-block!important}}@media (min-width:992px)and (max-width:1199px){.visible-md{display:block!important}table.visible-md{display:table}tr.visible-md{display:table-row!important}td.visible-md,th.visible-md{display:table-cell!important}}@media (min-width:992px)and (max-width:1199px){.visible-md-block{display:block!important}}@media (min-width:992px)and (max-width:1199px){.visible-md-inline{display:inline!important}}@media (min-width:992px)and (max-width:1199px){.visible-md-inline-block{display:inline-block!important}}@media (min-width:1200px){.visible-lg{display:block!important}table.visible-lg{display:table}tr.visible-lg{display:table-row!important}td.visible-lg,th.visible-lg{display:table-cell!important}}@media (min-width:1200px){.visible-lg-block{display:block!important}}@media (min-width:1200px){.visible-lg-inline{display:inline!important}}@media (min-width:1200px){.visible-lg-inline-block{display:inline-block!important}}@media (max-width:767px){.hidden-xs{display:none!important}}@media (min-width:768px)and (max-width:991px){.hidden-sm{display:none!important}}@media (min-width:992px)and (max-width:1199px){.hidden-md{display:none!important}}@media (min-width:1200px){.hidden-lg{display:none!important}}.visible-print{display:none!important}@media print{.visible-print{display:block!important}table.visible-print{display:table}tr.visible-print{display:table-row!important}td.visible-print,th.visible-print{display:table-cell!important}}.visible-print-block{display:none!important}@media print{.visible-print-block{display:block!important}}.visible-print-inline{display:none!important}@media print{.visible-print-inline{display:inline!important}}.visible-print-inline-block{display:none!important}@media print{.visible-print-inline-block{display:inline-block!important}}@media print{.hidden-print{display:none!important}} \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/CSS/bootstrap.min.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/CSS/bootstrap.min.js new file mode 100644 index 000000000..133aeecb9 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/CSS/bootstrap.min.js @@ -0,0 +1,7 @@ +/*! + * Bootstrap v3.3.5 (http://getbootstrap.com) + * Copyright 2011-2015 Twitter, Inc. + * Licensed under the MIT license + */ +if("undefined"==typeof jQuery)throw new Error("Bootstrap's JavaScript requires jQuery");+function(a){"use strict";var b=a.fn.jquery.split(" ")[0].split(".");if(b[0]<2&&b[1]<9||1==b[0]&&9==b[1]&&b[2]<1)throw new Error("Bootstrap's JavaScript requires jQuery version 1.9.1 or higher")}(jQuery),+function(a){"use strict";function b(){var a=document.createElement("bootstrap"),b={WebkitTransition:"webkitTransitionEnd",MozTransition:"transitionend",OTransition:"oTransitionEnd otransitionend",transition:"transitionend"};for(var c in b)if(void 0!==a.style[c])return{end:b[c]};return!1}a.fn.emulateTransitionEnd=function(b){var c=!1,d=this;a(this).one("bsTransitionEnd",function(){c=!0});var e=function(){c||a(d).trigger(a.support.transition.end)};return setTimeout(e,b),this},a(function(){a.support.transition=b(),a.support.transition&&(a.event.special.bsTransitionEnd={bindType:a.support.transition.end,delegateType:a.support.transition.end,handle:function(b){return a(b.target).is(this)?b.handleObj.handler.apply(this,arguments):void 0}})})}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var c=a(this),e=c.data("bs.alert");e||c.data("bs.alert",e=new d(this)),"string"==typeof b&&e[b].call(c)})}var c='[data-dismiss="alert"]',d=function(b){a(b).on("click",c,this.close)};d.VERSION="3.3.5",d.TRANSITION_DURATION=150,d.prototype.close=function(b){function c(){g.detach().trigger("closed.bs.alert").remove()}var e=a(this),f=e.attr("data-target");f||(f=e.attr("href"),f=f&&f.replace(/.*(?=#[^\s]*$)/,""));var g=a(f);b&&b.preventDefault(),g.length||(g=e.closest(".alert")),g.trigger(b=a.Event("close.bs.alert")),b.isDefaultPrevented()||(g.removeClass("in"),a.support.transition&&g.hasClass("fade")?g.one("bsTransitionEnd",c).emulateTransitionEnd(d.TRANSITION_DURATION):c())};var e=a.fn.alert;a.fn.alert=b,a.fn.alert.Constructor=d,a.fn.alert.noConflict=function(){return a.fn.alert=e,this},a(document).on("click.bs.alert.data-api",c,d.prototype.close)}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.button"),f="object"==typeof b&&b;e||d.data("bs.button",e=new c(this,f)),"toggle"==b?e.toggle():b&&e.setState(b)})}var c=function(b,d){this.$element=a(b),this.options=a.extend({},c.DEFAULTS,d),this.isLoading=!1};c.VERSION="3.3.5",c.DEFAULTS={loadingText:"loading..."},c.prototype.setState=function(b){var c="disabled",d=this.$element,e=d.is("input")?"val":"html",f=d.data();b+="Text",null==f.resetText&&d.data("resetText",d[e]()),setTimeout(a.proxy(function(){d[e](null==f[b]?this.options[b]:f[b]),"loadingText"==b?(this.isLoading=!0,d.addClass(c).attr(c,c)):this.isLoading&&(this.isLoading=!1,d.removeClass(c).removeAttr(c))},this),0)},c.prototype.toggle=function(){var a=!0,b=this.$element.closest('[data-toggle="buttons"]');if(b.length){var c=this.$element.find("input");"radio"==c.prop("type")?(c.prop("checked")&&(a=!1),b.find(".active").removeClass("active"),this.$element.addClass("active")):"checkbox"==c.prop("type")&&(c.prop("checked")!==this.$element.hasClass("active")&&(a=!1),this.$element.toggleClass("active")),c.prop("checked",this.$element.hasClass("active")),a&&c.trigger("change")}else this.$element.attr("aria-pressed",!this.$element.hasClass("active")),this.$element.toggleClass("active")};var d=a.fn.button;a.fn.button=b,a.fn.button.Constructor=c,a.fn.button.noConflict=function(){return a.fn.button=d,this},a(document).on("click.bs.button.data-api",'[data-toggle^="button"]',function(c){var d=a(c.target);d.hasClass("btn")||(d=d.closest(".btn")),b.call(d,"toggle"),a(c.target).is('input[type="radio"]')||a(c.target).is('input[type="checkbox"]')||c.preventDefault()}).on("focus.bs.button.data-api blur.bs.button.data-api",'[data-toggle^="button"]',function(b){a(b.target).closest(".btn").toggleClass("focus",/^focus(in)?$/.test(b.type))})}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.carousel"),f=a.extend({},c.DEFAULTS,d.data(),"object"==typeof b&&b),g="string"==typeof b?b:f.slide;e||d.data("bs.carousel",e=new c(this,f)),"number"==typeof b?e.to(b):g?e[g]():f.interval&&e.pause().cycle()})}var c=function(b,c){this.$element=a(b),this.$indicators=this.$element.find(".carousel-indicators"),this.options=c,this.paused=null,this.sliding=null,this.interval=null,this.$active=null,this.$items=null,this.options.keyboard&&this.$element.on("keydown.bs.carousel",a.proxy(this.keydown,this)),"hover"==this.options.pause&&!("ontouchstart"in document.documentElement)&&this.$element.on("mouseenter.bs.carousel",a.proxy(this.pause,this)).on("mouseleave.bs.carousel",a.proxy(this.cycle,this))};c.VERSION="3.3.5",c.TRANSITION_DURATION=600,c.DEFAULTS={interval:5e3,pause:"hover",wrap:!0,keyboard:!0},c.prototype.keydown=function(a){if(!/input|textarea/i.test(a.target.tagName)){switch(a.which){case 37:this.prev();break;case 39:this.next();break;default:return}a.preventDefault()}},c.prototype.cycle=function(b){return b||(this.paused=!1),this.interval&&clearInterval(this.interval),this.options.interval&&!this.paused&&(this.interval=setInterval(a.proxy(this.next,this),this.options.interval)),this},c.prototype.getItemIndex=function(a){return this.$items=a.parent().children(".item"),this.$items.index(a||this.$active)},c.prototype.getItemForDirection=function(a,b){var c=this.getItemIndex(b),d="prev"==a&&0===c||"next"==a&&c==this.$items.length-1;if(d&&!this.options.wrap)return b;var e="prev"==a?-1:1,f=(c+e)%this.$items.length;return this.$items.eq(f)},c.prototype.to=function(a){var b=this,c=this.getItemIndex(this.$active=this.$element.find(".item.active"));return a>this.$items.length-1||0>a?void 0:this.sliding?this.$element.one("slid.bs.carousel",function(){b.to(a)}):c==a?this.pause().cycle():this.slide(a>c?"next":"prev",this.$items.eq(a))},c.prototype.pause=function(b){return b||(this.paused=!0),this.$element.find(".next, .prev").length&&a.support.transition&&(this.$element.trigger(a.support.transition.end),this.cycle(!0)),this.interval=clearInterval(this.interval),this},c.prototype.next=function(){return this.sliding?void 0:this.slide("next")},c.prototype.prev=function(){return this.sliding?void 0:this.slide("prev")},c.prototype.slide=function(b,d){var e=this.$element.find(".item.active"),f=d||this.getItemForDirection(b,e),g=this.interval,h="next"==b?"left":"right",i=this;if(f.hasClass("active"))return this.sliding=!1;var j=f[0],k=a.Event("slide.bs.carousel",{relatedTarget:j,direction:h});if(this.$element.trigger(k),!k.isDefaultPrevented()){if(this.sliding=!0,g&&this.pause(),this.$indicators.length){this.$indicators.find(".active").removeClass("active");var l=a(this.$indicators.children()[this.getItemIndex(f)]);l&&l.addClass("active")}var m=a.Event("slid.bs.carousel",{relatedTarget:j,direction:h});return a.support.transition&&this.$element.hasClass("slide")?(f.addClass(b),f[0].offsetWidth,e.addClass(h),f.addClass(h),e.one("bsTransitionEnd",function(){f.removeClass([b,h].join(" ")).addClass("active"),e.removeClass(["active",h].join(" ")),i.sliding=!1,setTimeout(function(){i.$element.trigger(m)},0)}).emulateTransitionEnd(c.TRANSITION_DURATION)):(e.removeClass("active"),f.addClass("active"),this.sliding=!1,this.$element.trigger(m)),g&&this.cycle(),this}};var d=a.fn.carousel;a.fn.carousel=b,a.fn.carousel.Constructor=c,a.fn.carousel.noConflict=function(){return a.fn.carousel=d,this};var e=function(c){var d,e=a(this),f=a(e.attr("data-target")||(d=e.attr("href"))&&d.replace(/.*(?=#[^\s]+$)/,""));if(f.hasClass("carousel")){var g=a.extend({},f.data(),e.data()),h=e.attr("data-slide-to");h&&(g.interval=!1),b.call(f,g),h&&f.data("bs.carousel").to(h),c.preventDefault()}};a(document).on("click.bs.carousel.data-api","[data-slide]",e).on("click.bs.carousel.data-api","[data-slide-to]",e),a(window).on("load",function(){a('[data-ride="carousel"]').each(function(){var c=a(this);b.call(c,c.data())})})}(jQuery),+function(a){"use strict";function b(b){var c,d=b.attr("data-target")||(c=b.attr("href"))&&c.replace(/.*(?=#[^\s]+$)/,"");return a(d)}function c(b){return this.each(function(){var c=a(this),e=c.data("bs.collapse"),f=a.extend({},d.DEFAULTS,c.data(),"object"==typeof b&&b);!e&&f.toggle&&/show|hide/.test(b)&&(f.toggle=!1),e||c.data("bs.collapse",e=new d(this,f)),"string"==typeof b&&e[b]()})}var d=function(b,c){this.$element=a(b),this.options=a.extend({},d.DEFAULTS,c),this.$trigger=a('[data-toggle="collapse"][href="#'+b.id+'"],[data-toggle="collapse"][data-target="#'+b.id+'"]'),this.transitioning=null,this.options.parent?this.$parent=this.getParent():this.addAriaAndCollapsedClass(this.$element,this.$trigger),this.options.toggle&&this.toggle()};d.VERSION="3.3.5",d.TRANSITION_DURATION=350,d.DEFAULTS={toggle:!0},d.prototype.dimension=function(){var a=this.$element.hasClass("width");return a?"width":"height"},d.prototype.show=function(){if(!this.transitioning&&!this.$element.hasClass("in")){var b,e=this.$parent&&this.$parent.children(".panel").children(".in, .collapsing");if(!(e&&e.length&&(b=e.data("bs.collapse"),b&&b.transitioning))){var f=a.Event("show.bs.collapse");if(this.$element.trigger(f),!f.isDefaultPrevented()){e&&e.length&&(c.call(e,"hide"),b||e.data("bs.collapse",null));var g=this.dimension();this.$element.removeClass("collapse").addClass("collapsing")[g](0).attr("aria-expanded",!0),this.$trigger.removeClass("collapsed").attr("aria-expanded",!0),this.transitioning=1;var h=function(){this.$element.removeClass("collapsing").addClass("collapse in")[g](""),this.transitioning=0,this.$element.trigger("shown.bs.collapse")};if(!a.support.transition)return h.call(this);var i=a.camelCase(["scroll",g].join("-"));this.$element.one("bsTransitionEnd",a.proxy(h,this)).emulateTransitionEnd(d.TRANSITION_DURATION)[g](this.$element[0][i])}}}},d.prototype.hide=function(){if(!this.transitioning&&this.$element.hasClass("in")){var b=a.Event("hide.bs.collapse");if(this.$element.trigger(b),!b.isDefaultPrevented()){var c=this.dimension();this.$element[c](this.$element[c]())[0].offsetHeight,this.$element.addClass("collapsing").removeClass("collapse in").attr("aria-expanded",!1),this.$trigger.addClass("collapsed").attr("aria-expanded",!1),this.transitioning=1;var e=function(){this.transitioning=0,this.$element.removeClass("collapsing").addClass("collapse").trigger("hidden.bs.collapse")};return a.support.transition?void this.$element[c](0).one("bsTransitionEnd",a.proxy(e,this)).emulateTransitionEnd(d.TRANSITION_DURATION):e.call(this)}}},d.prototype.toggle=function(){this[this.$element.hasClass("in")?"hide":"show"]()},d.prototype.getParent=function(){return a(this.options.parent).find('[data-toggle="collapse"][data-parent="'+this.options.parent+'"]').each(a.proxy(function(c,d){var e=a(d);this.addAriaAndCollapsedClass(b(e),e)},this)).end()},d.prototype.addAriaAndCollapsedClass=function(a,b){var c=a.hasClass("in");a.attr("aria-expanded",c),b.toggleClass("collapsed",!c).attr("aria-expanded",c)};var e=a.fn.collapse;a.fn.collapse=c,a.fn.collapse.Constructor=d,a.fn.collapse.noConflict=function(){return a.fn.collapse=e,this},a(document).on("click.bs.collapse.data-api",'[data-toggle="collapse"]',function(d){var e=a(this);e.attr("data-target")||d.preventDefault();var f=b(e),g=f.data("bs.collapse"),h=g?"toggle":e.data();c.call(f,h)})}(jQuery),+function(a){"use strict";function b(b){var c=b.attr("data-target");c||(c=b.attr("href"),c=c&&/#[A-Za-z]/.test(c)&&c.replace(/.*(?=#[^\s]*$)/,""));var d=c&&a(c);return d&&d.length?d:b.parent()}function c(c){c&&3===c.which||(a(e).remove(),a(f).each(function(){var d=a(this),e=b(d),f={relatedTarget:this};e.hasClass("open")&&(c&&"click"==c.type&&/input|textarea/i.test(c.target.tagName)&&a.contains(e[0],c.target)||(e.trigger(c=a.Event("hide.bs.dropdown",f)),c.isDefaultPrevented()||(d.attr("aria-expanded","false"),e.removeClass("open").trigger("hidden.bs.dropdown",f))))}))}function d(b){return this.each(function(){var c=a(this),d=c.data("bs.dropdown");d||c.data("bs.dropdown",d=new g(this)),"string"==typeof b&&d[b].call(c)})}var e=".dropdown-backdrop",f='[data-toggle="dropdown"]',g=function(b){a(b).on("click.bs.dropdown",this.toggle)};g.VERSION="3.3.5",g.prototype.toggle=function(d){var e=a(this);if(!e.is(".disabled, :disabled")){var f=b(e),g=f.hasClass("open");if(c(),!g){"ontouchstart"in document.documentElement&&!f.closest(".navbar-nav").length&&a(document.createElement("div")).addClass("dropdown-backdrop").insertAfter(a(this)).on("click",c);var h={relatedTarget:this};if(f.trigger(d=a.Event("show.bs.dropdown",h)),d.isDefaultPrevented())return;e.trigger("focus").attr("aria-expanded","true"),f.toggleClass("open").trigger("shown.bs.dropdown",h)}return!1}},g.prototype.keydown=function(c){if(/(38|40|27|32)/.test(c.which)&&!/input|textarea/i.test(c.target.tagName)){var d=a(this);if(c.preventDefault(),c.stopPropagation(),!d.is(".disabled, :disabled")){var e=b(d),g=e.hasClass("open");if(!g&&27!=c.which||g&&27==c.which)return 27==c.which&&e.find(f).trigger("focus"),d.trigger("click");var h=" li:not(.disabled):visible a",i=e.find(".dropdown-menu"+h);if(i.length){var j=i.index(c.target);38==c.which&&j>0&&j--,40==c.which&&jdocument.documentElement.clientHeight;this.$element.css({paddingLeft:!this.bodyIsOverflowing&&a?this.scrollbarWidth:"",paddingRight:this.bodyIsOverflowing&&!a?this.scrollbarWidth:""})},c.prototype.resetAdjustments=function(){this.$element.css({paddingLeft:"",paddingRight:""})},c.prototype.checkScrollbar=function(){var a=window.innerWidth;if(!a){var b=document.documentElement.getBoundingClientRect();a=b.right-Math.abs(b.left)}this.bodyIsOverflowing=document.body.clientWidth
      ',trigger:"hover focus",title:"",delay:0,html:!1,container:!1,viewport:{selector:"body",padding:0}},c.prototype.init=function(b,c,d){if(this.enabled=!0,this.type=b,this.$element=a(c),this.options=this.getOptions(d),this.$viewport=this.options.viewport&&a(a.isFunction(this.options.viewport)?this.options.viewport.call(this,this.$element):this.options.viewport.selector||this.options.viewport),this.inState={click:!1,hover:!1,focus:!1},this.$element[0]instanceof document.constructor&&!this.options.selector)throw new Error("`selector` option must be specified when initializing "+this.type+" on the window.document object!");for(var e=this.options.trigger.split(" "),f=e.length;f--;){var g=e[f];if("click"==g)this.$element.on("click."+this.type,this.options.selector,a.proxy(this.toggle,this));else if("manual"!=g){var h="hover"==g?"mouseenter":"focusin",i="hover"==g?"mouseleave":"focusout";this.$element.on(h+"."+this.type,this.options.selector,a.proxy(this.enter,this)),this.$element.on(i+"."+this.type,this.options.selector,a.proxy(this.leave,this))}}this.options.selector?this._options=a.extend({},this.options,{trigger:"manual",selector:""}):this.fixTitle()},c.prototype.getDefaults=function(){return c.DEFAULTS},c.prototype.getOptions=function(b){return b=a.extend({},this.getDefaults(),this.$element.data(),b),b.delay&&"number"==typeof b.delay&&(b.delay={show:b.delay,hide:b.delay}),b},c.prototype.getDelegateOptions=function(){var b={},c=this.getDefaults();return this._options&&a.each(this._options,function(a,d){c[a]!=d&&(b[a]=d)}),b},c.prototype.enter=function(b){var c=b instanceof this.constructor?b:a(b.currentTarget).data("bs."+this.type);return c||(c=new this.constructor(b.currentTarget,this.getDelegateOptions()),a(b.currentTarget).data("bs."+this.type,c)),b instanceof a.Event&&(c.inState["focusin"==b.type?"focus":"hover"]=!0),c.tip().hasClass("in")||"in"==c.hoverState?void(c.hoverState="in"):(clearTimeout(c.timeout),c.hoverState="in",c.options.delay&&c.options.delay.show?void(c.timeout=setTimeout(function(){"in"==c.hoverState&&c.show()},c.options.delay.show)):c.show())},c.prototype.isInStateTrue=function(){for(var a in this.inState)if(this.inState[a])return!0;return!1},c.prototype.leave=function(b){var c=b instanceof this.constructor?b:a(b.currentTarget).data("bs."+this.type);return c||(c=new this.constructor(b.currentTarget,this.getDelegateOptions()),a(b.currentTarget).data("bs."+this.type,c)),b instanceof a.Event&&(c.inState["focusout"==b.type?"focus":"hover"]=!1),c.isInStateTrue()?void 0:(clearTimeout(c.timeout),c.hoverState="out",c.options.delay&&c.options.delay.hide?void(c.timeout=setTimeout(function(){"out"==c.hoverState&&c.hide()},c.options.delay.hide)):c.hide())},c.prototype.show=function(){var b=a.Event("show.bs."+this.type);if(this.hasContent()&&this.enabled){this.$element.trigger(b);var d=a.contains(this.$element[0].ownerDocument.documentElement,this.$element[0]);if(b.isDefaultPrevented()||!d)return;var e=this,f=this.tip(),g=this.getUID(this.type);this.setContent(),f.attr("id",g),this.$element.attr("aria-describedby",g),this.options.animation&&f.addClass("fade");var h="function"==typeof this.options.placement?this.options.placement.call(this,f[0],this.$element[0]):this.options.placement,i=/\s?auto?\s?/i,j=i.test(h);j&&(h=h.replace(i,"")||"top"),f.detach().css({top:0,left:0,display:"block"}).addClass(h).data("bs."+this.type,this),this.options.container?f.appendTo(this.options.container):f.insertAfter(this.$element),this.$element.trigger("inserted.bs."+this.type);var k=this.getPosition(),l=f[0].offsetWidth,m=f[0].offsetHeight;if(j){var n=h,o=this.getPosition(this.$viewport);h="bottom"==h&&k.bottom+m>o.bottom?"top":"top"==h&&k.top-mo.width?"left":"left"==h&&k.left-lg.top+g.height&&(e.top=g.top+g.height-i)}else{var j=b.left-f,k=b.left+f+c;jg.right&&(e.left=g.left+g.width-k)}return e},c.prototype.getTitle=function(){var a,b=this.$element,c=this.options;return a=b.attr("data-original-title")||("function"==typeof c.title?c.title.call(b[0]):c.title)},c.prototype.getUID=function(a){do a+=~~(1e6*Math.random());while(document.getElementById(a));return a},c.prototype.tip=function(){if(!this.$tip&&(this.$tip=a(this.options.template),1!=this.$tip.length))throw new Error(this.type+" `template` option must consist of exactly 1 top-level element!");return this.$tip},c.prototype.arrow=function(){return this.$arrow=this.$arrow||this.tip().find(".tooltip-arrow")},c.prototype.enable=function(){this.enabled=!0},c.prototype.disable=function(){this.enabled=!1},c.prototype.toggleEnabled=function(){this.enabled=!this.enabled},c.prototype.toggle=function(b){var c=this;b&&(c=a(b.currentTarget).data("bs."+this.type),c||(c=new this.constructor(b.currentTarget,this.getDelegateOptions()),a(b.currentTarget).data("bs."+this.type,c))),b?(c.inState.click=!c.inState.click,c.isInStateTrue()?c.enter(c):c.leave(c)):c.tip().hasClass("in")?c.leave(c):c.enter(c)},c.prototype.destroy=function(){var a=this;clearTimeout(this.timeout),this.hide(function(){a.$element.off("."+a.type).removeData("bs."+a.type),a.$tip&&a.$tip.detach(),a.$tip=null,a.$arrow=null,a.$viewport=null})};var d=a.fn.tooltip;a.fn.tooltip=b,a.fn.tooltip.Constructor=c,a.fn.tooltip.noConflict=function(){return a.fn.tooltip=d,this}}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.popover"),f="object"==typeof b&&b;(e||!/destroy|hide/.test(b))&&(e||d.data("bs.popover",e=new c(this,f)),"string"==typeof b&&e[b]())})}var c=function(a,b){this.init("popover",a,b)};if(!a.fn.tooltip)throw new Error("Popover requires tooltip.js");c.VERSION="3.3.5",c.DEFAULTS=a.extend({},a.fn.tooltip.Constructor.DEFAULTS,{placement:"right",trigger:"click",content:"",template:''}),c.prototype=a.extend({},a.fn.tooltip.Constructor.prototype),c.prototype.constructor=c,c.prototype.getDefaults=function(){return c.DEFAULTS},c.prototype.setContent=function(){var a=this.tip(),b=this.getTitle(),c=this.getContent();a.find(".popover-title")[this.options.html?"html":"text"](b),a.find(".popover-content").children().detach().end()[this.options.html?"string"==typeof c?"html":"append":"text"](c),a.removeClass("fade top bottom left right in"),a.find(".popover-title").html()||a.find(".popover-title").hide()},c.prototype.hasContent=function(){return this.getTitle()||this.getContent()},c.prototype.getContent=function(){var a=this.$element,b=this.options;return a.attr("data-content")||("function"==typeof b.content?b.content.call(a[0]):b.content)},c.prototype.arrow=function(){return this.$arrow=this.$arrow||this.tip().find(".arrow")};var d=a.fn.popover;a.fn.popover=b,a.fn.popover.Constructor=c,a.fn.popover.noConflict=function(){return a.fn.popover=d,this}}(jQuery),+function(a){"use strict";function b(c,d){this.$body=a(document.body),this.$scrollElement=a(a(c).is(document.body)?window:c),this.options=a.extend({},b.DEFAULTS,d),this.selector=(this.options.target||"")+" .nav li > a",this.offsets=[],this.targets=[],this.activeTarget=null,this.scrollHeight=0,this.$scrollElement.on("scroll.bs.scrollspy",a.proxy(this.process,this)),this.refresh(),this.process()}function c(c){return this.each(function(){var d=a(this),e=d.data("bs.scrollspy"),f="object"==typeof c&&c;e||d.data("bs.scrollspy",e=new b(this,f)),"string"==typeof c&&e[c]()})}b.VERSION="3.3.5",b.DEFAULTS={offset:10},b.prototype.getScrollHeight=function(){return this.$scrollElement[0].scrollHeight||Math.max(this.$body[0].scrollHeight,document.documentElement.scrollHeight)},b.prototype.refresh=function(){var b=this,c="offset",d=0;this.offsets=[],this.targets=[],this.scrollHeight=this.getScrollHeight(),a.isWindow(this.$scrollElement[0])||(c="position",d=this.$scrollElement.scrollTop()),this.$body.find(this.selector).map(function(){var b=a(this),e=b.data("target")||b.attr("href"),f=/^#./.test(e)&&a(e);return f&&f.length&&f.is(":visible")&&[[f[c]().top+d,e]]||null}).sort(function(a,b){return a[0]-b[0]}).each(function(){b.offsets.push(this[0]),b.targets.push(this[1])})},b.prototype.process=function(){var a,b=this.$scrollElement.scrollTop()+this.options.offset,c=this.getScrollHeight(),d=this.options.offset+c-this.$scrollElement.height(),e=this.offsets,f=this.targets,g=this.activeTarget;if(this.scrollHeight!=c&&this.refresh(),b>=d)return g!=(a=f[f.length-1])&&this.activate(a);if(g&&b=e[a]&&(void 0===e[a+1]||b .dropdown-menu > .active").removeClass("active").end().find('[data-toggle="tab"]').attr("aria-expanded",!1),b.addClass("active").find('[data-toggle="tab"]').attr("aria-expanded",!0),h?(b[0].offsetWidth,b.addClass("in")):b.removeClass("fade"),b.parent(".dropdown-menu").length&&b.closest("li.dropdown").addClass("active").end().find('[data-toggle="tab"]').attr("aria-expanded",!0),e&&e()}var g=d.find("> .active"),h=e&&a.support.transition&&(g.length&&g.hasClass("fade")||!!d.find("> .fade").length);g.length&&h?g.one("bsTransitionEnd",f).emulateTransitionEnd(c.TRANSITION_DURATION):f(),g.removeClass("in")};var d=a.fn.tab;a.fn.tab=b,a.fn.tab.Constructor=c,a.fn.tab.noConflict=function(){return a.fn.tab=d,this};var e=function(c){c.preventDefault(),b.call(a(this),"show")};a(document).on("click.bs.tab.data-api",'[data-toggle="tab"]',e).on("click.bs.tab.data-api",'[data-toggle="pill"]',e)}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.affix"),f="object"==typeof b&&b;e||d.data("bs.affix",e=new c(this,f)),"string"==typeof b&&e[b]()})}var c=function(b,d){this.options=a.extend({},c.DEFAULTS,d),this.$target=a(this.options.target).on("scroll.bs.affix.data-api",a.proxy(this.checkPosition,this)).on("click.bs.affix.data-api",a.proxy(this.checkPositionWithEventLoop,this)),this.$element=a(b),this.affixed=null,this.unpin=null,this.pinnedOffset=null,this.checkPosition()};c.VERSION="3.3.5",c.RESET="affix affix-top affix-bottom",c.DEFAULTS={offset:0,target:window},c.prototype.getState=function(a,b,c,d){var e=this.$target.scrollTop(),f=this.$element.offset(),g=this.$target.height();if(null!=c&&"top"==this.affixed)return c>e?"top":!1;if("bottom"==this.affixed)return null!=c?e+this.unpin<=f.top?!1:"bottom":a-d>=e+g?!1:"bottom";var h=null==this.affixed,i=h?e:f.top,j=h?g:b;return null!=c&&c>=e?"top":null!=d&&i+j>=a-d?"bottom":!1},c.prototype.getPinnedOffset=function(){if(this.pinnedOffset)return this.pinnedOffset;this.$element.removeClass(c.RESET).addClass("affix");var a=this.$target.scrollTop(),b=this.$element.offset();return this.pinnedOffset=b.top-a},c.prototype.checkPositionWithEventLoop=function(){setTimeout(a.proxy(this.checkPosition,this),1)},c.prototype.checkPosition=function(){if(this.$element.is(":visible")){var b=this.$element.height(),d=this.options.offset,e=d.top,f=d.bottom,g=Math.max(a(document).height(),a(document.body).height());"object"!=typeof d&&(f=e=d),"function"==typeof e&&(e=d.top(this.$element)),"function"==typeof f&&(f=d.bottom(this.$element));var h=this.getState(g,b,e,f);if(this.affixed!=h){null!=this.unpin&&this.$element.css("top","");var i="affix"+(h?"-"+h:""),j=a.Event(i+".bs.affix");if(this.$element.trigger(j),j.isDefaultPrevented())return;this.affixed=h,this.unpin="bottom"==h?this.getPinnedOffset():null,this.$element.removeClass(c.RESET).addClass(i).trigger(i.replace("affix","affixed")+".bs.affix")}"bottom"==h&&this.$element.offset({top:g-b-f})}};var d=a.fn.affix;a.fn.affix=b,a.fn.affix.Constructor=c,a.fn.affix.noConflict=function(){return a.fn.affix=d,this},a(window).on("load",function(){a('[data-spy="affix"]').each(function(){var c=a(this),d=c.data();d.offset=d.offset||{},null!=d.offsetBottom&&(d.offset.bottom=d.offsetBottom),null!=d.offsetTop&&(d.offset.top=d.offsetTop),b.call(c,d)})})}(jQuery); \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/CSS/select.css b/ecomp-sdk-app/src/main/webapp/app/policyApp/CSS/select.css new file mode 100644 index 000000000..b07b4f8a2 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/CSS/select.css @@ -0,0 +1,287 @@ +@CHARSET "ISO-8859-1"; +/*! + * ui-select + * http://github.com/angular-ui/ui-select + * Version: 0.11.2 - 2015-03-17T04:08:46.478Z + * License: MIT + */ + + +/* Style when highlighting a search. */ +.ui-select-highlight { + font-weight: bold; +} + +.ui-select-offscreen { + clip: rect(0 0 0 0) !important; + width: 1px !important; + height: 1px !important; + border: 0 !important; + margin: 0 !important; + padding: 0 !important; + overflow: hidden !important; + position: absolute !important; + outline: 0 !important; + left: 0px !important; + top: 0px !important; +} + +/* Select2 theme */ + +/* Mark invalid Select2 */ +.ng-dirty.ng-invalid > a.select2-choice { + border-color: #D44950; +} + +.select2-result-single { + padding-left: 0; +} + +.select2-locked > .select2-search-choice-close{ + display:none; +} + +.select-locked > .ui-select-match-close{ + display:none; +} + +body > .select2-container.open { + z-index: 9999; /* The z-index Select2 applies to the select2-drop */ +} + +/* Selectize theme */ + +/* Helper class to show styles when focus */ +.selectize-input.selectize-focus{ + border-color: #007FBB !important; +} + +/* Fix input width for Selectize theme */ +.selectize-control > .selectize-input > input { + width: 100%; +} + +/* Fix dropdown width for Selectize theme */ +.selectize-control > .selectize-dropdown { + width: 100%; +} + +/* Mark invalid Selectize */ +.ng-dirty.ng-invalid > div.selectize-input { + border-color: #D44950; +} + + +/* Bootstrap theme */ + +/* Helper class to show styles when focus */ +.btn-default-focus { + color: #333; + background-color: #EBEBEB; + border-color: #ADADAD; + text-decoration: none; + outline: 5px auto -webkit-focus-ring-color; + outline-offset: -2px; + box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(102, 175, 233, 0.6); +} + +.ui-select-bootstrap .ui-select-toggle { + position: relative; +} + +.ui-select-bootstrap .ui-select-toggle > .caret { + position: absolute; + height: 10px; + top: 50%; + right: 10px; + margin-top: -2px; +} + +/* Fix Bootstrap dropdown position when inside a input-group */ +.input-group > .ui-select-bootstrap.dropdown { + /* Instead of relative */ + position: static; +} + +.input-group > .ui-select-bootstrap > input.ui-select-search.form-control { + border-radius: 4px; /* FIXME hardcoded value :-/ */ + border-top-right-radius: 0; + border-bottom-right-radius: 0; +} + +.ui-select-bootstrap > .ui-select-match > .btn{ + /* Instead of center because of .btn */ + text-align: left !important; +} + +.ui-select-bootstrap > .ui-select-match > .caret { + position: absolute; + top: 45%; + right: 15px; +} + +/* See Scrollable Menu with Bootstrap 3 http://stackoverflow.com/questions/19227496 */ +.ui-select-bootstrap > .ui-select-choices { + width: 100%; + height: auto; + max-height: 200px; + overflow-x: hidden; + margin-top: -1px; +} + +body > .ui-select-bootstrap.open { + z-index: 1000; /* Standard Bootstrap dropdown z-index */ +} + +.ui-select-multiple.ui-select-bootstrap { + height: auto; + padding: 3px 3px 0 3px; +} + +.ui-select-multiple.ui-select-bootstrap input.ui-select-search { + background-color: transparent !important; /* To prevent double background when disabled */ + border: none; + outline: none; + height: 1.666666em; + margin-bottom: 3px; +} + +.ui-select-multiple.ui-select-bootstrap .ui-select-match .close { + font-size: 1.6em; + line-height: 0.75; +} + +.ui-select-multiple.ui-select-bootstrap .ui-select-match-item { + outline: 0; + margin: 0 3px 3px 0; +} + +.ui-select-multiple .ui-select-match-item { + position: relative; +} + +.ui-select-multiple .ui-select-match-item.dropping-before:before { + content: ""; + position: absolute; + top: 0; + right: 100%; + height: 100%; + margin-right: 2px; + border-left: 1px solid #428bca; +} + +.ui-select-multiple .ui-select-match-item.dropping-after:after { + content: ""; + position: absolute; + top: 0; + left: 100%; + height: 100%; + margin-left: 2px; + border-right: 1px solid #428bca; +} + +.ui-select-bootstrap .ui-select-choices-row>a { + display: block; + padding: 3px 20px; + clear: both; + font-weight: 400; + line-height: 1.42857143; + color: #333; + white-space: nowrap; +} + +.ui-select-bootstrap .ui-select-choices-row>a:hover, .ui-select-bootstrap .ui-select-choices-row>a:focus { + text-decoration: none; + color: #262626; + background-color: #f5f5f5; +} + +.ui-select-bootstrap .ui-select-choices-row.active>a { + color: #fff; + text-decoration: none; + outline: 0; + background-color: #428bca; +} + +.ui-select-bootstrap .ui-select-choices-row.disabled>a, +.ui-select-bootstrap .ui-select-choices-row.active.disabled>a { + color: #777; + cursor: not-allowed; + background-color: #fff; +} + +/* fix hide/show angular animation */ +.ui-select-match.ng-hide-add, +.ui-select-search.ng-hide-add { + display: none !important; +} + +/* Mark invalid Bootstrap */ +.ui-select-bootstrap.ng-dirty.ng-invalid > button.btn.ui-select-match { + border-color: #D44950; +} + +.icon-lock { + width: 48px; + height: 48px; + position: relative; + overflow: hidden; + margin-left: 25px; + margin-bottom: 25px; +} + +.icon-lock .lock-top-1 { + width: 40%; + height: 40%; + position: absolute; + left: 50%; + margin-left: -20%; + top: 14%; + background-color: #000; + border-radius: 40%; +} + +.icon-lock .lock-top-2 { + width: 24%; + height: 40%; + position: absolute; + left: 50%; + margin-left: -12%; + top: 22%; + background-color: #151517; + border-radius: 25%; +} + +.icon-lock .lock-body { + width: 60%; + height: 48%; + position: absolute; + left: 50%; + margin-left: -30%; + bottom: 11%; + background-color: #000; + border-radius: 15%; +} + +.icon-lock .lock-hole { + width: 16%; + height: 16%; + position: absolute; + left: 50%; + margin-left: -8%; + top: 51%; + border-radius: 100%; + background-color: #151517; +} + +.icon-lock .lock-hole:after { + content: ""; + width: 43%; + height: 78%; + position: absolute; + left: 50%; + margin-left: -20%; + top: 100%; + background-color: inherit; +} + \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/CSS/select.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/CSS/select.js new file mode 100644 index 000000000..e83214358 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/CSS/select.js @@ -0,0 +1,1748 @@ +/*! + * ui-select + * http://github.com/angular-ui/ui-select + * Version: 0.11.2 - 2015-03-17T04:08:46.474Z + * License: MIT + */ + + +(function () { +"use strict"; + +var KEY = { + TAB: 9, + ENTER: 13, + ESC: 27, + SPACE: 32, + LEFT: 37, + UP: 38, + RIGHT: 39, + DOWN: 40, + SHIFT: 16, + CTRL: 17, + ALT: 18, + PAGE_UP: 33, + PAGE_DOWN: 34, + HOME: 36, + END: 35, + BACKSPACE: 8, + DELETE: 46, + COMMAND: 91, + + MAP: { 91 : "COMMAND", 8 : "BACKSPACE" , 9 : "TAB" , 13 : "ENTER" , 16 : "SHIFT" , 17 : "CTRL" , 18 : "ALT" , 19 : "PAUSEBREAK" , 20 : "CAPSLOCK" , 27 : "ESC" , 32 : "SPACE" , 33 : "PAGE_UP", 34 : "PAGE_DOWN" , 35 : "END" , 36 : "HOME" , 37 : "LEFT" , 38 : "UP" , 39 : "RIGHT" , 40 : "DOWN" , 43 : "+" , 44 : "PRINTSCREEN" , 45 : "INSERT" , 46 : "DELETE", 48 : "0" , 49 : "1" , 50 : "2" , 51 : "3" , 52 : "4" , 53 : "5" , 54 : "6" , 55 : "7" , 56 : "8" , 57 : "9" , 59 : ";", 61 : "=" , 65 : "A" , 66 : "B" , 67 : "C" , 68 : "D" , 69 : "E" , 70 : "F" , 71 : "G" , 72 : "H" , 73 : "I" , 74 : "J" , 75 : "K" , 76 : "L", 77 : "M" , 78 : "N" , 79 : "O" , 80 : "P" , 81 : "Q" , 82 : "R" , 83 : "S" , 84 : "T" , 85 : "U" , 86 : "V" , 87 : "W" , 88 : "X" , 89 : "Y" , 90 : "Z", 96 : "0" , 97 : "1" , 98 : "2" , 99 : "3" , 100 : "4" , 101 : "5" , 102 : "6" , 103 : "7" , 104 : "8" , 105 : "9", 106 : "*" , 107 : "+" , 109 : "-" , 110 : "." , 111 : "/", 112 : "F1" , 113 : "F2" , 114 : "F3" , 115 : "F4" , 116 : "F5" , 117 : "F6" , 118 : "F7" , 119 : "F8" , 120 : "F9" , 121 : "F10" , 122 : "F11" , 123 : "F12", 144 : "NUMLOCK" , 145 : "SCROLLLOCK" , 186 : ";" , 187 : "=" , 188 : "," , 189 : "-" , 190 : "." , 191 : "/" , 192 : "`" , 219 : "[" , 220 : "\\" , 221 : "]" , 222 : "'" + }, + + isControl: function (e) { + var k = e.which; + switch (k) { + case KEY.COMMAND: + case KEY.SHIFT: + case KEY.CTRL: + case KEY.ALT: + return true; + } + + if (e.metaKey) return true; + + return false; + }, + isFunctionKey: function (k) { + k = k.which ? k.which : k; + return k >= 112 && k <= 123; + }, + isVerticalMovement: function (k){ + return ~[KEY.UP, KEY.DOWN].indexOf(k); + }, + isHorizontalMovement: function (k){ + return ~[KEY.LEFT,KEY.RIGHT,KEY.BACKSPACE,KEY.DELETE].indexOf(k); + } + }; + +/** + * Add querySelectorAll() to jqLite. + * + * jqLite find() is limited to lookups by tag name. + * TODO This will change with future versions of AngularJS, to be removed when this happens + * + * See jqLite.find - why not use querySelectorAll? https://github.com/angular/angular.js/issues/3586 + * See feat(jqLite): use querySelectorAll instead of getElementsByTagName in jqLite.find https://github.com/angular/angular.js/pull/3598 + */ +if (angular.element.prototype.querySelectorAll === undefined) { + angular.element.prototype.querySelectorAll = function(selector) { + return angular.element(this[0].querySelectorAll(selector)); + }; +} + +/** + * Add closest() to jqLite. + */ +if (angular.element.prototype.closest === undefined) { + angular.element.prototype.closest = function( selector) { + var elem = this[0]; + var matchesSelector = elem.matches || elem.webkitMatchesSelector || elem.mozMatchesSelector || elem.msMatchesSelector; + + while (elem) { + if (matchesSelector.bind(elem)(selector)) { + return elem; + } else { + elem = elem.parentElement; + } + } + return false; + }; +} + +var latestId = 0; + +var uis = angular.module('ui.select', []) + +.constant('uiSelectConfig', { + theme: 'bootstrap', + searchEnabled: true, + sortable: false, + placeholder: '', // Empty by default, like HTML tag "); + $compile(focusser)(scope); + $select.focusser = focusser; + + //Input that will handle focus + $select.focusInput = focusser; + + element.parent().append(focusser); + focusser.bind("focus", function(){ + scope.$evalAsync(function(){ + $select.focus = true; + }); + }); + focusser.bind("blur", function(){ + scope.$evalAsync(function(){ + $select.focus = false; + }); + }); + focusser.bind("keydown", function(e){ + + if (e.which === KEY.BACKSPACE) { + e.preventDefault(); + e.stopPropagation(); + $select.select(undefined); + scope.$apply(); + return; + } + + if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC) { + return; + } + + if (e.which == KEY.DOWN || e.which == KEY.UP || e.which == KEY.ENTER || e.which == KEY.SPACE){ + e.preventDefault(); + e.stopPropagation(); + $select.activate(); + } + + scope.$digest(); + }); + + focusser.bind("keyup input", function(e){ + + if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || e.which == KEY.ENTER || e.which === KEY.BACKSPACE) { + return; + } + + $select.activate(focusser.val()); //User pressed some regular key, so we pass it to the search input + focusser.val(''); + scope.$digest(); + + }); + + + } + }; +}]); +// Make multiple matches sortable +uis.directive('uiSelectSort', ['$timeout', 'uiSelectConfig', 'uiSelectMinErr', function($timeout, uiSelectConfig, uiSelectMinErr) { + return { + require: '^uiSelect', + link: function(scope, element, attrs, $select) { + if (scope[attrs.uiSelectSort] === null) { + throw uiSelectMinErr('sort', "Expected a list to sort"); + } + + var options = angular.extend({ + axis: 'horizontal' + }, + scope.$eval(attrs.uiSelectSortOptions)); + + var axis = options.axis, + draggingClassName = 'dragging', + droppingClassName = 'dropping', + droppingBeforeClassName = 'dropping-before', + droppingAfterClassName = 'dropping-after'; + + scope.$watch(function(){ + return $select.sortable; + }, function(n){ + if (n) { + element.attr('draggable', true); + } else { + element.removeAttr('draggable'); + } + }); + + element.on('dragstart', function(e) { + element.addClass(draggingClassName); + + (e.dataTransfer || e.originalEvent.dataTransfer).setData('text/plain', scope.$index); + }); + + element.on('dragend', function() { + element.removeClass(draggingClassName); + }); + + var move = function(from, to) { + /*jshint validthis: true */ + this.splice(to, 0, this.splice(from, 1)[0]); + }; + + var dragOverHandler = function(e) { + e.preventDefault(); + + var offset = axis === 'vertical' ? e.offsetY || e.layerY || (e.originalEvent ? e.originalEvent.offsetY : 0) : e.offsetX || e.layerX || (e.originalEvent ? e.originalEvent.offsetX : 0); + + if (offset < (this[axis === 'vertical' ? 'offsetHeight' : 'offsetWidth'] / 2)) { + element.removeClass(droppingAfterClassName); + element.addClass(droppingBeforeClassName); + + } else { + element.removeClass(droppingBeforeClassName); + element.addClass(droppingAfterClassName); + } + }; + + var dropTimeout; + + var dropHandler = function(e) { + e.preventDefault(); + + var droppedItemIndex = parseInt((e.dataTransfer || e.originalEvent.dataTransfer).getData('text/plain'), 10); + + // prevent event firing multiple times in firefox + $timeout.cancel(dropTimeout); + dropTimeout = $timeout(function() { + _dropHandler(droppedItemIndex); + }, 20); + }; + + var _dropHandler = function(droppedItemIndex) { + var theList = scope.$eval(attrs.uiSelectSort), + itemToMove = theList[droppedItemIndex], + newIndex = null; + + if (element.hasClass(droppingBeforeClassName)) { + if (droppedItemIndex < scope.$index) { + newIndex = scope.$index - 1; + } else { + newIndex = scope.$index; + } + } else { + if (droppedItemIndex < scope.$index) { + newIndex = scope.$index; + } else { + newIndex = scope.$index + 1; + } + } + + move.apply(theList, [droppedItemIndex, newIndex]); + + scope.$apply(function() { + scope.$emit('uiSelectSort:change', { + array: theList, + item: itemToMove, + from: droppedItemIndex, + to: newIndex + }); + }); + + element.removeClass(droppingClassName); + element.removeClass(droppingBeforeClassName); + element.removeClass(droppingAfterClassName); + + element.off('drop', dropHandler); + }; + + element.on('dragenter', function() { + if (element.hasClass(draggingClassName)) { + return; + } + + element.addClass(droppingClassName); + + element.on('dragover', dragOverHandler); + element.on('drop', dropHandler); + }); + + element.on('dragleave', function(e) { + if (e.target != element) { + return; + } + element.removeClass(droppingClassName); + element.removeClass(droppingBeforeClassName); + element.removeClass(droppingAfterClassName); + + element.off('dragover', dragOverHandler); + element.off('drop', dropHandler); + }); + } + }; +}]); + +/** + * Parses "repeat" attribute. + * + * Taken from AngularJS ngRepeat source code + * See https://github.com/angular/angular.js/blob/v1.2.15/src/ng/directive/ngRepeat.js#L211 + * + * Original discussion about parsing "repeat" attribute instead of fully relying on ng-repeat: + * https://github.com/angular-ui/ui-select/commit/5dd63ad#commitcomment-5504697 + */ + +uis.service('uisRepeatParser', ['uiSelectMinErr','$parse', function(uiSelectMinErr, $parse) { + var self = this; + + /** + * Example: + * expression = "address in addresses | filter: {street: $select.search} track by $index" + * itemName = "address", + * source = "addresses | filter: {street: $select.search}", + * trackByExp = "$index", + */ + self.parse = function(expression) { + + var match = expression.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/); + + if (!match) { + throw uiSelectMinErr('iexp', "Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.", + expression); + } + + return { + itemName: match[2], // (lhs) Left-hand side, + source: $parse(match[3]), + trackByExp: match[4], + modelMapper: $parse(match[1] || match[2]) + }; + + }; + + self.getGroupNgRepeatExpression = function() { + return '$group in $select.groups'; + }; + + self.getNgRepeatExpression = function(itemName, source, trackByExp, grouped) { + var expression = itemName + ' in ' + (grouped ? '$group.items' : source); + if (trackByExp) { + expression += ' track by ' + trackByExp; + } + return expression; + }; +}]); + +}()); +angular.module("ui.select").run(["$templateCache", function($templateCache) {$templateCache.put("bootstrap/choices.tpl.html","
        0\">
      • 0\">
      "); +$templateCache.put("bootstrap/match-multiple.tpl.html"," × "); +$templateCache.put("bootstrap/match.tpl.html","
      {{$select.placeholder}}
      "); +$templateCache.put("bootstrap/select-multiple.tpl.html","
      "); +$templateCache.put("bootstrap/select.tpl.html","
      "); +$templateCache.put("select2/choices.tpl.html","
      "); +$templateCache.put("select2/match-multiple.tpl.html","
    • "); +$templateCache.put("select2/match.tpl.html","{{$select.placeholder}} "); +$templateCache.put("select2/select-multiple.tpl.html","
      "); +$templateCache.put("select2/select.tpl.html","
      "); +$templateCache.put("selectize/choices.tpl.html","
      "); +$templateCache.put("selectize/match.tpl.html","
      "); +$templateCache.put("selectize/select.tpl.html","
      ");}]); + + \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/CSS/w3.css b/ecomp-sdk-app/src/main/webapp/app/policyApp/CSS/w3.css new file mode 100644 index 000000000..572f0b17e --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/CSS/w3.css @@ -0,0 +1,360 @@ +@CHARSET "ISO-8859-1"; +/* W3.CSS 2.63 by Jan Egil and Borge Refsnes. Do not remove this line */ +*{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box} +/* Extract from normalize.css by Nicolas Gallagher and Jonathan Neal git.io/normalize */ +html{-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%}body{margin:0} +article,aside,details,figcaption,figure,footer,header,hgroup,main,menu,nav,section,summary{display:block} +audio,canvas,video{display:inline-block;vertical-align:baseline} +audio:not([controls]){display:none;height:0}[hidden],template{display:none} +a{background-color:transparent}a:active,a:hover{outline:0}abbr[title]{border-bottom:1px dotted} +dfn{font-style:italic}mark{background:#ff0;color:#000} +small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline} +sup{top:-0.5em}sub{bottom:-0.25em} +img{border:0}svg:not(:root){overflow:hidden}figure{margin:1em 40px} +hr{-moz-box-sizing:content-box;box-sizing:content-box} +code,kbd,pre,samp{font-family:monospace,monospace;font-size:1em} +button,input,select,textarea{font:inherit;margin:0} +button{overflow:visible}button,select{text-transform:none} +button,html input[type=button],input[type=reset],input[type=submit]{-webkit-appearance:button;cursor:pointer} +button[disabled],html input[disabled]{cursor:default} +button::-moz-focus-inner,input::-moz-focus-inner{border:0;padding:0} +input[type=checkbox],input[type=radio]{padding:0} +input[type=number]::-webkit-inner-spin-button,input[type=number]::-webkit-outer-spin-button{height:auto} +input[type=search]{box-sizing:content-box;-webkit-appearance:textfield;-moz-box-sizing:content-box;-webkit-box-sizing:content-box} +input[type=search]::-webkit-search-cancel-button,input[type=search]::-webkit-search-decoration{-webkit-appearance:none} +fieldset{border:1px solid #c0c0c0;margin:0 2px;padding:.35em .625em .75em} +legend{border:0;padding:0}pre,textarea{overflow:auto} +/*End extract from normalize.css*/ +html,body{font-family:Verdana,sans-serif;font-size:15px;line-height:1.5}html{overflow-x:hidden} +h1,h2,h3,h4,h5,h6,.w3-slim,.w3-wide{font-family:"Segoe UI",Arial,sans-serif} +h1{font-size:36px}h2{font-size:30px}h3{font-size:24px}h4{font-size:20px}h5{font-size:18px}h6{font-size:16px} +.w3-serif{font-family:"Times New Roman",Times,serif} +h1,h2,h3,h4,h5,h6{font-weight:400;margin:10px 0}.w3-wide{letter-spacing:4px} +h1 a,h2 a,h3 a,h4 a,h5 a,h6 a{font-weight:inherit} +hr{height:0;border:0;border-top:1px solid #eee;margin:20px 0} +img{margin-bottom:-5px}a{color:inherit} +table{border-collapse:collapse;border-spacing:0;width:100%;display:table} +table,th,td{border:none} +.w3-table-all{border:1px solid #ccc} +.w3-bordered tr,.w3-table-all tr{border-bottom:1px solid #ddd} +.w3-striped tbody tr:nth-child(even){background-color:#f1f1f1} +.w3-table-all tr:nth-child(odd){background-color:#fff} +.w3-table-all tr:nth-child(even){background-color:#f1f1f1} +.w3-hoverable tbody tr:hover,.w3-ul.w3-hoverable li:hover{background-color:#ccc} +.w3-centered tr th,.w3-centered tr td{text-align:center} +.w3-table td,.w3-table th,.w3-table-all td,.w3-table-all th{padding:6px 8px;display:table-cell;text-align:left;vertical-align:top} +.w3-table th:first-child,.w3-table td:first-child,.w3-table-all th:first-child,.w3-table-all td:first-child{padding-left:16px} +.w3-btn,.w3-btn-block{border:none;display:inline-block;outline:0;padding:6px 16px;vertical-align:middle;overflow:hidden;text-decoration:none!important;color:#fff;background-color:#000;text-align:center;cursor:pointer;white-space:nowrap} +.w3-btn.w3-disabled,.w3-btn-block.w3-disabled,.w3-btn-floating.w3-disabled,.w3-btn:disabled,.w3-btn-floating:disabled,.w3-btn-floating-large.w3-disabled,.w3-btn-floating-large:disabled{cursor:not-allowed;opacity:0.3} +.w3-btn.w3-disabled *,.w3-btn-block.w3-disabled,.w3-btn-floating.w3-disabled *,.w3-btn:disabled *,.w3-btn-floating:disabled *{pointer-events:none} +.w3-btn.w3-disabled:hover,.w3-btn-block.w3-disabled:hover,.w3-btn:disabled:hover,.w3-btn-floating.w3-disabled:hover,.w3-btn-floating:disabled:hover, +.w3-btn-floating-large.w3-disabled:hover,.w3-btn-floating-large:disabled:hover{box-shadow:none} +.w3-btn:hover,.w3-btn-block:hover,.w3-btn-floating:hover,.w3-btn-floating-large:hover{box-shadow:0 8px 16px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19)} +.w3-btn-block{width:100%} +.w3-btn,.w3-btn-floating,.w3-btn-floating-large,.w3-closenav,.w3-opennav{-webkit-touch-callout:none;-webkit-user-select:none;-khtml-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none} +.w3-btn-floating,.w3-btn-floating-large{display:inline-block;text-align:center;color:#fff;background-color:#000;position:relative;overflow:hidden;z-index:1;padding:0;border-radius:50%;cursor:pointer;font-size:24px} +.w3-btn-floating{width:40px;height:40px;line-height:40px} +.w3-btn-floating-large{width:56px;height:56px;line-height:56px} +.w3-btn-group .w3-btn{float:left} +.w3-btn.w3-ripple{position:relative} +.w3-ripple:after{content:"";background:#90EE90;display:block;position:absolute;padding-top:300%;padding-left:350%;margin-left:-20px!important;margin-top:-120%;opacity:0;transition:.8s} +.w3-ripple:active:after{padding:0;margin:0;opacity:1;transition:0s} +.w3-badge,.w3-tag,.w3-sign{background-color:#000;color:#fff;display:inline-block;padding-left:8px;padding-right:8px;text-align:center} +.w3-badge{border-radius:50%} +ul.w3-ul{list-style-type:none;padding:0;margin:0} +ul.w3-ul li{padding:6px 2px 6px 16px;border-bottom:1px solid #ddd} +ul.w3-ul li:last-child{border-bottom:none} +.w3-tooltip,.w3-display-container{position:relative} +.w3-fluid{max-width:100%;height:auto} +.w3-tooltip .w3-text{display:none} +.w3-tooltip:hover .w3-text{display:inline-block} +.w3-navbar{list-style-type:none;margin:0;padding:0;overflow:hidden} +.w3-navbar li{float:left}.w3-navbar li a{display:block;padding:8px 16px}.w3-navbar li a:hover{color:#000;background-color:#ccc} +.w3-navbar .w3-dropdown-hover,.w3-navbar .w3-dropdown-click{position:static} +.w3-navbar .w3-dropdown-hover:hover,.w3-navbar .w3-dropdown-hover:first-child,.w3-navbar .w3-dropdown-click:hover{background-color:#ccc;color:#000} +.w3-navbar a,.w3-topnav a,.w3-sidenav a,.w3-dropnav a,.w3-dropdown-content a,.w3-accordion-content a{text-decoration:none!important} +.w3-navbar .w3-opennav.w3-right{float:right!important}.w3-topnav{padding:8px 8px} +.w3-topnav a{padding:0 8px;border-bottom:3px solid transparent;-webkit-transition:border-bottom .3s;transition:border-bottom .3s} +.w3-topnav a:hover{border-bottom:3px solid #fff}.w3-topnav .w3-dropdown-hover a{border-bottom:0} +.w3-opennav,.w3-closenav{color:inherit}.w3-opennav:hover,.w3-closenav:hover{cursor:pointer;opacity:0.8} +.w3-btn,.w3-btn-floating,.w3-btn-floating-large,.w3-btn-block,.w3-hover-shadow,.w3-hover-opacity, +.w3-navbar a,.w3-sidenav a,.w3-dropnav a,.w3-pagination li a,.w3-hoverable tbody tr,.w3-hoverable li,.w3-accordion-content a,.w3-dropdown-content a,.w3-dropdown-click:hover,.w3-dropdown-hover:hover,.w3-opennav,.w3-closenav,.w3-closebtn, +.w3-hover-amber,.w3-hover-aqua,.w3-hover-blue,.w3-hover-light-blue,.w3-hover-brown,.w3-hover-cyan,.w3-hover-blue-grey,.w3-hover-green,.w3-hover-light-green,.w3-hover-indigo,.w3-hover-khaki,.w3-hover-lime,.w3-hover-orange,.w3-hover-deep-orange,.w3-hover-pink, +.w3-hover-purple,.w3-hover-deep-purple,.w3-hover-red,.w3-hover-sand,.w3-hover-teal,.w3-hover-yellow,.w3-hover-white,.w3-hover-black,.w3-hover-grey,.w3-hover-light-grey,.w3-hover-dark-grey,.w3-hover-text-amber,.w3-hover-text-aqua,.w3-hover-text-blue,.w3-hover-text-light-blue, +.w3-hover-text-brown,.w3-hover-text-cyan,.w3-hover-text-blue-grey,.w3-hover-text-green,.w3-hover-text-light-green,.w3-hover-text-indigo,.w3-hover-text-khaki,.w3-hover-text-lime,.w3-hover-text-orange,.w3-hover-text-deep-orange,.w3-hover-text-pink,.w3-hover-text-purple, +.w3-hover-text-deep-purple,.w3-hover-text-red,.w3-hover-text-sand,.w3-hover-text-teal,.w3-hover-text-yellow,.w3-hover-text-white,.w3-hover-text-black,.w3-hover-text-grey,.w3-hover-text-light-grey,.w3-hover-text-dark-grey +{-webkit-transition:background-color .3s,color .15s,box-shadow .3s,opacity 0.3s;transition:background-color .3s,color .15s,box-shadow .3s,opacity 0.3s} +.w3-sidenav{height:100%;width:200px;background-color:#fff;position:fixed!important;z-index:1;overflow:auto} +.w3-sidenav a{padding:4px 2px 4px 16px}.w3-sidenav a:hover{background-color:#ccc}.w3-sidenav a,.w3-dropnav a{display:block} +.w3-sidenav .w3-dropdown-hover:hover,.w3-sidenav .w3-dropdown-hover:first-child,.w3-sidenav .w3-dropdown-click:hover{background-color:#ccc;color:#000} +.w3-sidenav .w3-dropdown-hover,.w3-sidenav .w3-dropdown-click {width:100%}.w3-sidenav .w3-dropdown-hover .w3-dropdown-content,.w3-sidenav .w3-dropdown-click .w3-dropdown-content{min-width:100%} +.w3-main,#main{transition:margin-left .4s} +.w3-dropnav{background-color:#fff}.w3-dropnav a:hover{text-decoration:underline!important} +.w3-modal{z-index:3;display:none;padding-top:100px;position:fixed;left:0;top:0;width:100%;height:100%;overflow:auto;background-color:rgb(0,0,0);background-color:rgba(0,0,0,0.4)} +.w3-modal-content{margin:auto;background-color:#fff;position:relative;padding:0;outline:0;width:600px}.w3-closebtn{text-decoration:none;float:right;font-size:24px;font-weight:bold;color:inherit} +.w3-closebtn:hover,.w3-closebtn:focus{color:#000;text-decoration:none;cursor:pointer} +.w3-pagination{display:inline-block;padding:0;margin:0}.w3-pagination li{display:inline} +.w3-pagination li a{text-decoration:none;color:#000;float:left;padding:8px 16px} +.w3-pagination li a:hover,.w3-pagination li a:focus{background-color:#ccc} +.w3-input-group,.w3-group{margin-top:24px;margin-bottom:24px} +.w3-input{padding:8px;display:block;border:none;border-bottom:1px solid #808080;width:100%} +.w3-label{color:#009688}.w3-input:not(:valid)~.w3-validate{color:#f44336} +.w3-select{padding:8px 0;width:100%;color:#000;border:1px solid transparent;border-bottom:1px solid #009688} +.w3-select select:focus{color:#000;border:1px solid #009688}.w3-select option[disabled]{color:#009688} +.w3-dropdown-click,.w3-dropdown-hover{position:relative;display:inline-block;cursor:pointer} +.w3-dropdown-hover:hover .w3-dropdown-content{display:block;z-index:1} +.w3-dropdown-content{cursor:auto;color:#000;background-color:#fff;display:none;position:absolute;min-width:160px;margin:0;padding:0} +.w3-dropdown-content a{padding:6px 16px;display:block} +.w3-dropdown-content a:hover{background-color:#ccc} +.w3-accordion {width:100%;cursor:pointer} +.w3-accordion-content{cursor:auto;display:none;position:relative;width:100%;margin:0;padding:0} +.w3-accordion-content a{padding:6px 16px;display:block}.w3-accordion-content a:hover{background-color:#ccc} +.w3-progress-container{width:100%;height:1.5em;position:relative;background-color:#f1f1f1} +.w3-progressbar{background-color:#757575;height:100%;position:absolute;line-height:inherit} +input[type=checkbox].w3-check,input[type=radio].w3-radio{width:24px;height:24px;position:relative;top:6px} +input[type=checkbox].w3-check:checked+.w3-validate,input[type=radio].w3-radio:checked+.w3-validate{color:#009688} +input[type=checkbox].w3-check:disabled+.w3-validate,input[type=radio].w3-radio:disabled+.w3-validate{color:#aaa} +.w3-responsive{overflow-x:auto} +.w3-container:after,.w3-row:after,.w3-row-padding:after,.w3-topnav:after,.w3-clear:after,.w3-btn-group:before,.w3-btn-group:after +{content:"";display:table;clear:both} +.w3-col,.w3-half,.w3-third,.w3-twothird,.w3-threequarter,.w3-quarter{float:left;width:100%} +.w3-col.s1{width:8.33333%} +.w3-col.s2{width:16.66666%} +.w3-col.s3{width:24.99999%} +.w3-col.s4{width:33.33333%} +.w3-col.s5{width:41.66666%} +.w3-col.s6{width:49.99999%} +.w3-col.s7{width:58.33333%} +.w3-col.s8{width:66.66666%} +.w3-col.s9{width:74.99999%} +.w3-col.s10{width:83.33333%} +.w3-col.s11{width:91.66666%} +.w3-col.s12,.w3-half,.w3-third,.w3-twothird,.w3-threequarter,.w3-quarter{width:99.99999%} +@media only screen and (min-width:601px){ +.w3-col.m1{width:8.33333%} +.w3-col.m2{width:16.66666%} +.w3-col.m3,.w3-quarter{width:24.99999%} +.w3-col.m4,.w3-third{width:33.33333%} +.w3-col.m5{width:41.66666%} +.w3-col.m6,.w3-half{width:49.99999%} +.w3-col.m7{width:58.33333%} +.w3-col.m8,.w3-twothird{width:66.66666%} +.w3-col.m9,.w3-threequarter{width:74.99999%} +.w3-col.m10{width:83.33333%} +.w3-col.m11{width:91.66666%} +.w3-col.m12{width:99.99999%}} +@media only screen and (min-width:993px){ +.w3-col.l1{width:8.33333%} +.w3-col.l2{width:16.66666%} +.w3-col.l3,.w3-quarter{width:24.99999%} +.w3-col.l4,.w3-third{width:33.33333%} +.w3-col.l5{width:41.66666%} +.w3-col.l6,.w3-half{width:49.99999%} +.w3-col.l7{width:58.33333%} +.w3-col.l8,.w3-twothird{width:66.66666%} +.w3-col.l9,.w3-threequarter{width:74.99999%} +.w3-col.l10{width:83.33333%} +.w3-col.l11{width:91.66666%} +.w3-col.l12{width:99.99999%}} +.w3-content{max-width:980px;margin:auto} +.w3-rest{overflow:hidden} +.w3-hide{display:none!important}.w3-show-block,.w3-show{display:block!important}.w3-show-inline-block{display:inline-block!important} +@media (max-width:600px){.w3-modal-content{margin:0 10px;width:auto!important}.w3-modal{padding-top:30px}} +@media (max-width:768px){.w3-modal-content{width:500px}.w3-modal{padding-top:50px}} +@media (min-width:993px){.w3-modal-content{width:900px}} +@media screen and (max-width:600px){.w3-topnav a{display:block}.w3-navbar li:not(.w3-opennav){float:none;width:100%!important}.w3-navbar li.w3-right{float:none!important}} +@media screen and (max-width:600px){.w3-topnav .w3-dropdown-hover .w3-dropdown-content,.w3-navbar .w3-dropdown-click .w3-dropdown-content,.w3-navbar .w3-dropdown-hover .w3-dropdown-content{position:relative}} +@media screen and (max-width:600px){.w3-topnav,.w3-navbar{text-align:center}} +@media (max-width:600px){.w3-hide-small{display:none!important}} +@media (max-width:992px) and (min-width:601px){.w3-hide-medium{display:none!important}} +@media (min-width:993px){.w3-hide-large{display:none!important}} +@media screen and (max-width:992px){.w3-sidenav.w3-collapse{display:none}.w3-main{margin-left:0!important}} +@media screen and (min-width:992px){.w3-sidenav.w3-collapse{display:block!important}} +.w3-top,.w3-bottom{position:fixed;width:100%;z-index:1}.w3-top{top:0}.w3-bottom{bottom:0} +.w3-overlay{position:fixed;display:none;width:100%;height:100%;top:0;left:0;right:0;bottom:0;background-color:rgba(0,0,0,0.5);z-index:2} +.w3-left{float:left!important}.w3-right{float:right!important} +.w3-tiny{font-size:10px!important}.w3-small{font-size:12px!important} +.w3-medium{font-size:15px!important} +.w3-large{font-size:18px!important} +.w3-xlarge{font-size:24px!important} +.w3-xxlarge{font-size:36px!important} +.w3-xxxlarge{font-size:48px!important} +.w3-jumbo{font-size:64px!important} +.w3-vertical{word-break:break-all;line-height:1;text-align:center;width:0.6em} +.w3-left-align{text-align:left!important}.w3-right-align{text-align:right!important} +.w3-justify{text-align:justify!important} +.w3-center{text-align:center!important} +.w3-display-topleft{position:absolute;left:0;top:0}.w3-display-topright{position:absolute;right:0;top:0} +.w3-display-bottomleft{position:absolute;left:0;bottom:0}.w3-display-bottomright{position:absolute;right:0;bottom:0} +.w3-display-middle{position:absolute;left:0;bottom:50%;width:100%;text-align:center} +.w3-display-topmiddle{position:absolute;left:0;top:0;width:100%;text-align:center}.w3-display-bottommiddle{position:absolute;left:0;bottom:0;width:100%;text-align:center} +.w3-circle{border-radius:50%!important} +.w3-round-small{border-radius:2px!important}.w3-round,.w3-round-medium{border-radius:4px!important} +.w3-round-large{border-radius:8px!important}.w3-round-xlarge{border-radius:16px!important} +.w3-round-xxlarge{border-radius:32px!important}.w3-round-jumbo{border-radius:64px!important} +.w3-border-0{border:0!important} +.w3-border{border:1px solid #ccc!important} +.w3-border-top{border-top:1px solid #ccc!important}.w3-border-bottom{border-bottom:1px solid #ccc!important} +.w3-border-left{border-left:1px solid #ccc!important}.w3-border-right{border-right:1px solid #ccc!important} +.w3-margin{margin:16px!important}.w3-margin-0{margin:0!important} +.w3-margin-top{margin-top:16px!important}.w3-margin-bottom{margin-bottom:16px!important} +.w3-margin-left{margin-left:16px!important}.w3-margin-right{margin-right:16px!important} +.w3-section{margin-top:16px!important;margin-bottom:16px!important} +.w3-padding-tiny{padding:2px 4px!important} +.w3-padding-small{padding:4px 8px!important} +.w3-padding-medium,.w3-padding,.w3-form{padding:8px 16px!important} +.w3-padding-large{padding:12px 24px!important} +.w3-padding-xlarge{padding:16px 32px!important} +.w3-padding-xxlarge{padding:24px 48px!important} +.w3-padding-jumbo{padding:32px 64px!important} +.w3-padding-4,.w3-padding-hor-4{padding-top:4px!important;padding-bottom:4px!important} +.w3-padding-8,.w3-padding-hor-8{padding-top:8px!important;padding-bottom:8px!important} +.w3-padding-12,.w3-padding-hor-12{padding-top:12px!important;padding-bottom:12px!important} +.w3-padding-16,.w3-padding-hor-16{padding-top:16px!important;padding-bottom:16px!important} +.w3-padding-24,.w3-padding-hor-24{padding-top:24px!important;padding-bottom:24px!important} +.w3-padding-32,.w3-padding-hor-32{padding-top:32px!important;padding-bottom:32px!important} +.w3-padding-48,.w3-padding-hor-48{padding-top:48px!important;padding-bottom:48px!important} +.w3-padding-64,.w3-padding-hor-64{padding-top:64px!important;padding-bottom:64px!important} +.w3-padding-128,.w3-padding-hor-128{padding-top:128px!important;padding-bottom:128px!important} +.w3-padding-0{padding:0!important} +/* Will be removed in a later version */ +.w3-padding-ver-4{padding-left:4px!important;padding-right:4px!important} +.w3-padding-ver-8{padding-left:8px!important;padding-right:8px!important} +.w3-padding-ver-12{padding-left:12px!important;padding-right:12px!important} +.w3-padding-ver-16{padding-left:16px!important;padding-right:16px!important} +.w3-padding-ver-24{padding-left:24px!important;padding-right:24px!important} +.w3-padding-ver-32{padding-left:32px!important;padding-right:32px!important} +.w3-padding-ver-48{padding-left:48px!important;padding-right:48px!important} +.w3-padding-ver-64{padding-left:64px!important;padding-right:64px!important} +/* End remove */ +.w3-padding-top{padding-top:8px!important}.w3-padding-bottom{padding-bottom:8px!important} +.w3-padding-left{padding-left:16px!important}.w3-padding-right{padding-right:16px!important} +.w3-topbar{border-top:6px solid #ccc!important}.w3-bottombar{border-bottom:6px solid #ccc!important} +.w3-leftbar{border-left:6px solid #ccc!important}.w3-rightbar{border-right:6px solid #ccc!important} +.w3-row-padding,.w3-row-padding>.w3-half,.w3-row-padding>.w3-third,.w3-row-padding>.w3-twothird,.w3-row-padding>.w3-threequarter,.w3-row-padding>.w3-quarter,.w3-row-padding>.w3-col{padding:0 8px} +.w3-spin{animation:w3-spin 2s infinite linear;-webkit-animation:w3-spin 2s infinite linear} +@-webkit-keyframes w3-spin{ +0%{-webkit-transform:rotate(0deg);transform:rotate(0deg)} +100%{-webkit-transform:rotate(359deg);transform:rotate(359deg)}} +@keyframes w3-spin{ +0%{-webkit-transform:rotate(0deg);transform: rotate(0deg)} +100%{-webkit-transform:rotate(359deg);transform:rotate(359deg)}} +.w3-container{padding:0.01em 16px} +.w3-example{background-color:#f1f1f1;padding:0.01em 16px} +.w3-code{font-family:Consolas,"courier new";font-size:16px;line-height:1.4;width:auto;background-color:#fff;padding:8px 12px;border-left:4px solid #009688;word-wrap:break-word} +.w3-example,.w3-code,.w3-reference{margin:20px 0} +.w3-card{border:1px solid #ccc} +.w3-card-2,.w3-example{box-shadow:0 2px 4px 0 rgba(0,0,0,0.16),0 2px 10px 0 rgba(0,0,0,0.12)!important} +.w3-card-4,.w3-hover-shadow:hover{box-shadow:0 4px 8px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19)!important} +.w3-card-8{box-shadow:0 8px 16px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19)!important} +.w3-card-12{box-shadow:0 12px 16px 0 rgba(0,0,0,0.24),0 17px 50px 0 rgba(0,0,0,0.19)!important} +.w3-card-16{box-shadow:0 16px 24px 0 rgba(0,0,0,0.22),0 25px 55px 0 rgba(0,0,0,0.21)!important} +.w3-card-24{box-shadow:0 24px 24px 0 rgba(0,0,0,0.2),0 40px 77px 0 rgba(0,0,0,0.22)!important} +.w3-animate-fading{-webkit-animation:fading 10s infinite;animation:fading 10s infinite} +@-webkit-keyframes fading{0%{opacity:0}50%{opacity:1}100%{opacity:0}} +@keyframes fading{0%{opacity:0}50%{opacity:1}100%{opacity:0}} +.w3-animate-opacity{-webkit-animation:opac 1.5s;animation:opac 1.5s} +@-webkit-keyframes opac{from{opacity:0} to{opacity:1}} +@keyframes opac{from{opacity:0} to{opacity:1}} +.w3-animate-top{position:relative;-webkit-animation:animatetop 0.4s;animation:animatetop 0.4s} +@-webkit-keyframes animatetop{from{top:-300px;opacity:0} to{top:0;opacity:1}} +@keyframes animatetop{from{top:-300px;opacity:0} to{top:0;opacity:1}} +.w3-animate-left{position:relative;-webkit-animation:animateleft 0.4s;animation:animateleft 0.4s} +@-webkit-keyframes animateleft{from{left:-300px;opacity:0} to{left:0;opacity:1}} +@keyframes animateleft{from{left:-300px;opacity:0} to{left:0;opacity:1}} +.w3-animate-right{position:relative;-webkit-animation:animateright 0.4s;animation:animateright 0.4s} +@-webkit-keyframes animateright{from{right:-300px;opacity:0} to{right:0;opacity:1}} +@keyframes animateright{from{right:-300px;opacity:0} to{right:0;opacity:1}} +.w3-animate-bottom{position:relative;-webkit-animation:animatebottom 0.4s;animation:animatebottom 0.4s} +@-webkit-keyframes animatebottom{from{bottom:-300px;opacity:0} to{bottom:0px;opacity:1}} +@keyframes animatebottom{from{bottom:-300px;opacity:0} to{bottom:0;opacity:1}} +.w3-animate-zoom {-webkit-animation:animatezoom 0.6s;animation:animatezoom 0.6s} +@-webkit-keyframes animatezoom{from{-webkit-transform:scale(0)} to{-webkit-transform:scale(1)}} +@keyframes animatezoom{from{transform:scale(0)} to{transform:scale(1)}} +.w3-animate-input{-webkit-transition:width 0.4s ease-in-out;transition:width 0.4s ease-in-out}.w3-animate-input:focus{width:100%!important} +.w3-transparent{background-color:transparent!important} +.w3-hover-none:hover{box-shadow:none!important;background-color:transparent!important} +.w3-amber,.w3-hover-amber:hover{color:#000!important;background-color:#ffc107!important} +.w3-aqua,.w3-hover-aqua:hover{color:#000!important;background-color:#00ffff!important} +.w3-blue,.w3-hover-blue:hover{color:#fff!important;background-color:#2196F3!important} +.w3-light-blue,.w3-hover-light-blue:hover{color:#000!important;background-color:#87CEEB!important} +.w3-brown,.w3-hover-brown:hover{color:#fff!important;background-color:#795548!important} +.w3-cyan,.w3-hover-cyan:hover{color:#000!important;background-color:#00bcd4!important} +.w3-blue-grey,.w3-hover-blue-grey:hover{color:#fff!important;background-color:#607d8b!important} +.w3-green,.w3-hover-green:hover{color:#fff!important;background-color:#4CAF50!important} +.w3-light-green,.w3-hover-light-green:hover{color:#000!important;background-color:#8bc34a!important} +.w3-indigo,.w3-hover-indigo:hover{color:#fff!important;background-color:#3f51b5!important} +.w3-khaki,.w3-hover-khaki:hover{color:#000!important;background-color:#f0e68c!important} +.w3-lime,.w3-hover-lime:hover{color:#000!important;background-color:#cddc39!important} +.w3-orange,.w3-hover-orange:hover{color:#000!important;background-color:#ff9800!important} +.w3-deep-orange,.w3-hover-deep-orange:hover{color:#fff!important;background-color:#ff5722!important} +.w3-pink,.w3-hover-pink:hover{color:#fff!important;background-color:#e91e63!important} +.w3-purple,.w3-hover-purple:hover{color:#fff!important;background-color:#9c27b0!important} +.w3-deep-purple,.w3-hover-deep-purple:hover{color:#fff!important;background-color:#673ab7!important} +.w3-red,.w3-hover-red:hover{color:#fff!important;background-color:#f44336!important} +.w3-sand,.w3-hover-sand:hover{color:#000!important;background-color:#fdf5e6!important} +.w3-teal,.w3-hover-teal:hover{color:#fff!important;background-color:#009688!important} +.w3-yellow,.w3-hover-yellow:hover{color:#000!important;background-color:#ffeb3b!important} +.w3-white,.w3-hover-white:hover{color:#000!important;background-color:#fff!important} +.w3-black,.w3-hover-black:hover{color:#fff!important;background-color:#000!important} +.w3-grey,.w3-hover-grey:hover{color:#000!important;background-color:#9e9e9e!important} +.w3-light-grey,.w3-hover-light-grey:hover{color:#000!important;background-color:#f1f1f1!important} +.w3-dark-grey,.w3-hover-dark-grey:hover{color:#fff!important;background-color:#616161!important} +.w3-pale-red,.w3-hover-pale-red:hover{color:#000!important;background-color:#ffe7e7!important}.w3-pale-green,.w3-hover-pale-green:hover{color:#000!important;background-color:#e7ffe7!important} +.w3-pale-yellow,.w3-hover-pale-yellow:hover{color:#000!important;background-color:#ffffd7!important}.w3-pale-blue,.w3-hover-pale-blue:hover{color:#000!important;background-color:#e7ffff!important} +.w3-text-amber,.w3-hover-text-amber:hover{color:#ffc107!important} +.w3-text-aqua,.w3-hover-text-aqua:hover{color:#00ffff!important} +.w3-text-blue,.w3-hover-text-blue:hover{color:#2196F3!important} +.w3-text-light-blue,.w3-hover-text-light-blue:hover{color:#87CEEB!important} +.w3-text-brown,.w3-hover-text-brown:hover{color:#795548!important} +.w3-text-cyan,.w3-hover-text-cyan:hover{color:#00bcd4!important} +.w3-text-blue-grey,.w3-hover-text-blue-grey:hover{color:#607d8b!important} +.w3-text-green,.w3-hover-text-green:hover{color:#4CAF50!important} +.w3-text-light-green,.w3-hover-text-light-green:hover{color:#8bc34a!important} +.w3-text-indigo,.w3-hover-text-indigo:hover{color:#3f51b5!important} +.w3-text-khaki,.w3-hover-text-khaki:hover{color:#b4aa50!important} +.w3-text-lime,.w3-hover-text-lime:hover{color:#cddc39!important} +.w3-text-orange,.w3-hover-text-orange:hover{color:#ff9800!important} +.w3-text-deep-orange,.w3-hover-text-deep-orange:hover{color:#ff5722!important} +.w3-text-pink,.w3-hover-text-pink:hover{color:#e91e63!important} +.w3-text-purple,.w3-hover-text-purple:hover{color:#9c27b0!important} +.w3-text-deep-purple,.w3-hover-text-deep-purple:hover{color:#673ab7!important} +.w3-text-red,.w3-hover-text-red:hover{color:#f44336!important} +.w3-text-sand,.w3-hover-text-sand:hover{color:#fdf5e6!important} +.w3-text-teal,.w3-hover-text-teal:hover{color:#009688!important} +.w3-text-yellow,.w3-hover-text-yellow:hover{color:#d2be0e!important} +.w3-text-white,.w3-hover-text-white:hover{color:#fff!important} +.w3-text-black,.w3-hover-text-black:hover{color:#000!important} +.w3-text-grey,.w3-hover-text-grey:hover{color:#757575!important} +.w3-text-light-grey,.w3-hover-text-light-grey:hover{color:#f1f1f1!important} +.w3-text-dark-grey,.w3-hover-text-dark-grey:hover{color:#3a3a3a!important} +.w3-border-amber,.w3-hover-border-amber:hover{border-color:#ffc107!important} +.w3-border-aqua,.w3-hover-border-aqua:hover{border-color:#00ffff!important} +.w3-border-blue,.w3-hover-border-blue:hover{border-color:#2196F3!important} +.w3-border-light-blue,.w3-hover-border-light-blue:hover{border-color:#87CEEB!important} +.w3-border-brown,.w3-hover-border-brown:hover{border-color:#795548!important} +.w3-border-cyan,.w3-hover-border-cyan:hover{border-color:#00bcd4!important} +.w3-border-blue-grey,.w3-hover-blue-grey:hover{border-color:#607d8b!important} +.w3-border-green,.w3-hover-border-green:hover{border-color:#4CAF50!important} +.w3-border-light-green,.w3-hover-border-light-green:hover{border-color:#8bc34a!important} +.w3-border-indigo,.w3-hover-border-indigo:hover{border-color:#3f51b5!important} +.w3-border-khaki,.w3-hover-border-khaki:hover{border-color:#f0e68c!important} +.w3-border-lime,.w3-hover-border-lime:hover{border-color:#cddc39!important} +.w3-border-orange,.w3-hover-border-orange:hover{border-color:#ff9800!important} +.w3-border-deep-orange,.w3-hover-border-deep-orange:hover{border-color:#ff5722!important} +.w3-border-pink,.w3-hover-border-pink:hover{border-color:#e91e63!important} +.w3-border-purple,.w3-hover-border-purple:hover{border-color:#9c27b0!important} +.w3-border-deep-purple,.w3-hover-border-deep-purple:hover{border-color:#673ab7!important} +.w3-border-red,.w3-hover-border-red:hover{border-color:#f44336!important} +.w3-border-sand,.w3-hover-border-sand:hover{border-color:#fdf5e6!important} +.w3-border-teal,.w3-hover-border-teal:hover{border-color:#009688!important} +.w3-border-yellow,.w3-hover-border-yellow:hover{border-color:#ffeb3b!important} +.w3-border-white,.w3-hover-border-white:hover{border-color:#fff!important} +.w3-border-black,.w3-hover-border-black:hover{border-color:#000!important} +.w3-border-grey,.w3-hover-border-grey:hover{border-color:#9e9e9e!important} +.w3-border-light-grey,.w3-hover-border-light-grey:hover{border-color:#f1f1f1!important} +.w3-border-dark-grey,.w3-hover-border-dark-grey:hover{border-color:#616161!important} +.w3-border-pale-red,.w3-hover-border-pale-red:hover{border-color:#ffe7e7!important}.w3-border-pale-green,.w3-hover-border-pale-green:hover{border-color:#e7ffe7!important} +.w3-border-pale-yellow,.w3-hover-border-pale-yellow:hover{border-color:#ffffd7!important}.w3-border-pale-blue,.w3-hover-border-pale-blue:hover{border-color:#e7ffff!important} +.w3-opacity,.w3-hover-opacity:hover{opacity:0.60} +.w3-text-shadow{text-shadow:1px 1px 0 #444}.w3-text-shadow-white{text-shadow:1px 1px 0 #ddd} \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/JSONDataFiles/JSONConfig.json b/ecomp-sdk-app/src/main/webapp/app/policyApp/JSONDataFiles/JSONConfig.json new file mode 100644 index 000000000..23f985962 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/JSONDataFiles/JSONConfig.json @@ -0,0 +1,132 @@ +[ + { + "serviceTypePolicyName": "Registration Failure(Trinity)", + "verticaMetrics": "DATETIMEUTC\n VNFC_NAME\n BW_SIP_STATS_REGISTER_RESPONSE_CODE_VALUE \nBW_SIP_STATS_REGISTER_RESPONSE_INS \n BW_SIP_STATS_REGISTER_RESPONSE_OUTS", + "attributes": { + "Onset&abatement anomaly detection": { + "PtileLimit": "Percentile value used by anomaly detection model", + "Threshold": "initial value for the quantile at percentile(PtileLimit) used by the anomaly detection model", + "Window": "Number of weeks anomaly detection model keeps in memory to estimate Threshold", + "Training": "Number of historical weeks anomaly detection model needs for training ", + "FractionSamplePerDay": "This corresponds to the minimum number of samples per day to be used in the daily percentile computation when updating the distribution tail crossing model. When there are less samples than that threshold, the model is not updated with these samples. " + }, + "Onset signature trigger": { + "ConsecutiveIntervalOnset": "Number of consecutive intervals normalized metric must trigger the anomaly detection model before resulting in an action", + "RetryTimer": "Minimum interval between policy triggers" + }, + "Abatement signature trigger": { + "ConsecutiveIntervalAbatement": "Number of consecutive intervals normalized metric does not trigger the anomaly detection model after onset signature was triggered" + }, + "Onset & abatement UEB notification": { + "OnsetMessage": "Value of field OnSetMessage sent by Analytics Engine published on UEB", + "AbatementMessage": "Value of field AbatementMessage sent by Analytics Engine published on UEB", + "PolicyName": "Value of field PolicyName sent by Analytics Engine published on UEB" + } + }, + "policyDescription": "Policy to detect instances where SIP registration rate exceeds a normal level over a number of consecutive sampling periods. \n Notes \n (1) Vertica metrics normalized and combined in a SIP registration failure probability per Site and per VM. \n (2) Anomaly detection model operates on SIP registration failure probability. \n (3) Anomaly detection consists of an estimated distribution percentile threshold crossing. \n (4) Actions: Send email and/or UEB notification" + }, + { + "serviceTypePolicyName": "International Fraud(Trinity)", + "verticaMetrics": "INTERVAL_START_TS\n CUSTOMER\n A_SITE\n A_SBG\n BW\n Z_COUNTRY\n CALL_COUNT\n MINUTES_OF_USE", + "attributes": { + "Onset&abatement anomaly detection": { + "PtileLimit": "Percentile value used by anomaly detection model", + "Threshold": "initial value for the quantile at percentile(PtileLimit) used by the anomaly detection model", + "Window": "Number of weeks anomaly detection model keeps in memory to estimate Threshold", + "Training": "Number of historical weeks anomaly detection model needs for training ", + "FractionSamplePerDay": "This corresponds to the minimum number of samples per day to be used in the daily percentile computation when updating the distribution tail crossing model. When there are less samples than that threshold, the model is not updated with these samples. " + }, + "Onset signature trigger": { + "ConsecutiveIntervalOnset": "Number of consecutive intervals normalized metric must trigger the anomaly detection model before resulting in an action", + "RetryTimer": "Minimum interval between policy triggers" + }, + "Abatement signature trigger": { + "ConsecutiveIntervalAbatement": "Number of consecutive intervals normalized metric does not trigger the anomaly detection model after onset signature was triggered" + }, + "Onset & abatement UEB notification ": { + "OnsetMessage": "Value of field OnSetMessage sent by Analytics Engine published on UEB", + "AbatementMessage": "Value of field AbatementMessage sent by Analytics Engine published on UEB", + "PolicyName": "Value of field PolicyName sent by Analytics Engine published on UEB" + } + }, + "policyDescription": "Policy to detect instances where count of calls towards an international destination exceeds a normal level over a number of consecutive sampling periods. \n Notes \n (1) Vertica metrics normalized and combined in a SIP registration failure probability per Customer, per Site and per VM. \n (2) Anomaly detection model operates on counts towards an international destination. \n (3) Anomaly detection consists of an estimated distribution percentile threshold crossing. \n (4) Actions: Send email and/or UEB notification" + }, + { + "serviceTypePolicyName": "No dial tone(Trinity)", + "verticaMetrics": "INTERVAL_START_TS\n SUM(CALLS_ATTEMPTED)\n SUM(NO_ANSWER_OR_VOICE_MAIL)\n A_SITE or A_SBG or BW or CUSTOMER", + "attributes": { + "Onset&abatement anomaly detection": { + "PtileLimit": "Percentile value used by anomaly detection model", + "Threshold": "initial value for the quantile at percentile(PtileLimit) used by the anomaly detection model", + "Window": "Number of weeks anomaly detection model keeps in memory to estimate Threshold", + "Training": "Number of historical weeks anomaly detection model needs for training ", + "FractionSamplePerDay": "This corresponds to the minimum number of samples per day to be used in the daily percentile computation when updating the distribution tail crossing model. When there are less samples than that threshold, the model is not updated with these samples. " + }, + "Onset signature trigger": { + "ConsecutiveIntervalOnset": "Number of consecutive intervals normalized metric must trigger the anomaly detection model before resulting in an action", + "RetryTimer": "Minimum interval between policy triggers" + }, + "Abatement signature trigger": { + "ConsecutiveIntervalAbatement": "Number of consecutive intervals normalized metric does not trigger the anomaly detection model after onset signature was triggered" + }, + "Onset & abatement UEB notification ": { + "OnsetMessage": "Value of field OnSetMessage sent by Analytics Engine published on UEB", + "AbatementMessage": "Value of field AbatementMessage sent by Analytics Engine published on UEB", + "PolicyName": "Value of field PolicyName sent by Analytics Engine published on UEB" + } + }, + "policyDescription": "Policy to detect ? \n Notes:\n (1) Actions: Send email and/or UEB notification" + }, + { + "serviceTypePolicyName": "Call storm(Trinity)", + "verticaMetrics": "", + "attributes": { + "Onset&abatement anomaly detection": { + "SeasonLength": "Metric seasonality (5min sampling period with 7 days seasonality: 7*288) used by Holt-Winters model", + "TrainLength": "Training length (5min sampling period with 7 days seasonality and 5 cycles training: 7*288*5) used by Holt-Winters", + "Alpha": "Smoothing parameter (range 0-1, default 0.2)", + "Beta": "Trend parameter (range 0-1, default 0) ", + "Gamma": "Seasonality (range 0-1, default 0.05)", + "Deviation Threshold": "Approximately a limit on the factor by how much current value has deviated compared to expected variance" + }, + "Onset signature trigger": { + "RetryTimer": "Minimum interval between policy triggers" + }, + "Abatement signature trigger": { + "Hw-Timeout": "Maximum time for an HealthCheck response (measured from the time a positive App-C response was received)", + "OnSetMessage": "Value of field Message sent by Analytics Engine published on UEB " + }, + "Onset & abatement UEB notification ": { + "AbatementMessage": "Value of field AbatementMessage sent by Analytics Engine published on UEB", + "PolicyName": "Value of field PolicyName sent by Analytics Engine published on UEB" + } + }, + "policyDescription": "Policy to detect instances where count of Formatted table ? exceeds a predicted level. \n Notes \n (1) Vertica metrics normalized and combined in ? per Customer, per Site and per VM. \n (2) Anomaly detection model operates on ? \n (3) Anomaly detection consists of detecting deviations from Holt-Winters predictions. \n (4) Actions: Send email and/or UEB notification" + }, + { + "serviceTypePolicyName": "Registration storm(Trinity)", + "verticaMetrics": "", + "attributes": { + "Onset&abatement anomaly detection": { + "SeasonLength": "Metric seasonality (5min sampling period with 7 days seasonality: 7*288) used by Holt-Winters model", + "TrainLength": "Training length (5min sampling period with 7 days seasonality and 5 cycles training: 7*288*5) used by Holt-Winters", + "Alpha": "Smoothing parameter (range 0-1, default 0.2)", + "Beta": "Trend parameter (range 0-1, default 0) ", + "Gamma": "Seasonality (range 0-1, default 0.05)", + "Deviation Threshold": "Approximately a limit on the factor by how much current value has deviated compared to expected variance" + }, + "Onset signature trigger": { + "RetryTimer": "Minimum interval between policy triggers" + }, + "Abatement signature trigger": { + "Hw-Timeout": "Maximum time for an HealthCheck response (measured from the time a positive App-C response was received)", + "OnSetMessage": "Value of field Message sent by Analytics Engine published on UEB " + }, + "Onset & abatement UEB notification ": { + "AbatementMessage": "Value of field AbatementMessage sent by Analytics Engine published on UEB", + "PolicyName": "Value of field PolicyName sent by Analytics Engine published on UEB" + } + }, + "policyDescription": "Policy to detect instances where count of Formatted table ? exceeds a predicted level. \n Notes \n (1) Vertica metrics normalized and combined in ? per Customer, per Site and per VM. \n (2) Anomaly detection model operates on ? \n (3) Anomaly detection consists of detecting deviations from Holt-Winters predictions. \n (4) Actions: Send email and/or UEB notification" + } +] \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/Properties/config.json b/ecomp-sdk-app/src/main/webapp/app/policyApp/Properties/config.json new file mode 100644 index 000000000..0d4fa3033 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/Properties/config.json @@ -0,0 +1,3 @@ +{ + "PAP_URL" : "http://localhost:8070/pap/@Auth@dGVzdHBhcDphbHBoYTEyMw==" +} \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/ActionPolicyDictionary.html b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/ActionPolicyDictionary.html new file mode 100644 index 000000000..b30fc7530 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/ActionPolicyDictionary.html @@ -0,0 +1,89 @@ + + + diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/AttributeDictionary.html b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/AttributeDictionary.html new file mode 100644 index 000000000..e8ff563a5 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/AttributeDictionary.html @@ -0,0 +1,80 @@ + + + diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/BRMSParamDictionary.html b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/BRMSParamDictionary.html new file mode 100644 index 000000000..d8013b997 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/BRMSParamDictionary.html @@ -0,0 +1,47 @@ + + + + diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/CLPepOptionsDictionary.html b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/CLPepOptionsDictionary.html new file mode 100644 index 000000000..fba9e8de8 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/CLPepOptionsDictionary.html @@ -0,0 +1,65 @@ + + + diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/CLServiceTypeDictionary.html b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/CLServiceTypeDictionary.html new file mode 100644 index 000000000..c3d0d3fac --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/CLServiceTypeDictionary.html @@ -0,0 +1,43 @@ + + + diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/CLSiteDictionary.html b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/CLSiteDictionary.html new file mode 100644 index 000000000..f140f9d1b --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/CLSiteDictionary.html @@ -0,0 +1,43 @@ + + + diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/CLVarbindDictionary.html b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/CLVarbindDictionary.html new file mode 100644 index 000000000..52754586c --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/CLVarbindDictionary.html @@ -0,0 +1,48 @@ + + + diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/CLVnfTypeDictionary.html b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/CLVnfTypeDictionary.html new file mode 100644 index 000000000..3e01e6844 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/CLVnfTypeDictionary.html @@ -0,0 +1,43 @@ + + + diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/CLVsclActionDictionary.html b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/CLVsclActionDictionary.html new file mode 100644 index 000000000..7716122dc --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/CLVsclActionDictionary.html @@ -0,0 +1,43 @@ + + + diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/DecisionSettingsDictionary.html b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/DecisionSettingsDictionary.html new file mode 100644 index 000000000..072ccbdb1 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/DecisionSettingsDictionary.html @@ -0,0 +1,60 @@ + + + diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/DescriptiveScopeDictionary.html b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/DescriptiveScopeDictionary.html new file mode 100644 index 000000000..2daaaf815 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/DescriptiveScopeDictionary.html @@ -0,0 +1,65 @@ + + + \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/EcompNameDictionary.html b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/EcompNameDictionary.html new file mode 100644 index 000000000..8bfb091de --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/EcompNameDictionary.html @@ -0,0 +1,43 @@ + + + diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/EnforcerTypeDictionary.html b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/EnforcerTypeDictionary.html new file mode 100644 index 000000000..87aaae473 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/EnforcerTypeDictionary.html @@ -0,0 +1,51 @@ + + + diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/FWActionListDictionary.html b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/FWActionListDictionary.html new file mode 100644 index 000000000..8bbb2cfd1 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/FWActionListDictionary.html @@ -0,0 +1,43 @@ + + + diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/FWAddressGroupDictionary.html b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/FWAddressGroupDictionary.html new file mode 100644 index 000000000..b0f9d6556 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/FWAddressGroupDictionary.html @@ -0,0 +1,62 @@ + + + diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/FWParentListDictionary.html b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/FWParentListDictionary.html new file mode 100644 index 000000000..f7de1685e --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/FWParentListDictionary.html @@ -0,0 +1,81 @@ + + + diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/FWPortListDictionary.html b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/FWPortListDictionary.html new file mode 100644 index 000000000..cb0991133 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/FWPortListDictionary.html @@ -0,0 +1,43 @@ + + + diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/FWPrefixListDictionary.html b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/FWPrefixListDictionary.html new file mode 100644 index 000000000..ab96f1faa --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/FWPrefixListDictionary.html @@ -0,0 +1,49 @@ + + + diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/FWProtocolListDictionary.html b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/FWProtocolListDictionary.html new file mode 100644 index 000000000..92f478750 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/FWProtocolListDictionary.html @@ -0,0 +1,43 @@ + + + diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/FWSecurityZoneDictionary.html b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/FWSecurityZoneDictionary.html new file mode 100644 index 000000000..2e47c7ce1 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/FWSecurityZoneDictionary.html @@ -0,0 +1,43 @@ + + + diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/FWServiceGroupDictionary.html b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/FWServiceGroupDictionary.html new file mode 100644 index 000000000..0936d342e --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/FWServiceGroupDictionary.html @@ -0,0 +1,57 @@ + + + diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/FWServiceListDictionary.html b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/FWServiceListDictionary.html new file mode 100644 index 000000000..46d2f1d24 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/FWServiceListDictionary.html @@ -0,0 +1,87 @@ + + + diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/FWTermListDictionary.html b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/FWTermListDictionary.html new file mode 100644 index 000000000..62b9f9b2d --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/FWTermListDictionary.html @@ -0,0 +1,176 @@ + + + diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/FWZoneDictionary.html b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/FWZoneDictionary.html new file mode 100644 index 000000000..3ccc4660e --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/FWZoneDictionary.html @@ -0,0 +1,43 @@ + + + diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/MSConfigNameDictionary.html b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/MSConfigNameDictionary.html new file mode 100644 index 000000000..d1dfd80c6 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/MSConfigNameDictionary.html @@ -0,0 +1,43 @@ + + + diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/MSDCAEUUIDDictionary.html b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/MSDCAEUUIDDictionary.html new file mode 100644 index 000000000..3edaf78fb --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/MSDCAEUUIDDictionary.html @@ -0,0 +1,43 @@ + + + diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/MSLocationDictionary.html b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/MSLocationDictionary.html new file mode 100644 index 000000000..d6994e951 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/MSLocationDictionary.html @@ -0,0 +1,43 @@ + + + diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/MSModelsDictionary.html b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/MSModelsDictionary.html new file mode 100644 index 000000000..816192e97 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/MSModelsDictionary.html @@ -0,0 +1,41 @@ + + + diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/PSClosedLoopDictionary.html b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/PSClosedLoopDictionary.html new file mode 100644 index 000000000..eeb2def79 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/PSClosedLoopDictionary.html @@ -0,0 +1,43 @@ + + + \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/PSGroupPolicyScopeDictionary.html b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/PSGroupPolicyScopeDictionary.html new file mode 100644 index 000000000..93371ea97 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/PSGroupPolicyScopeDictionary.html @@ -0,0 +1,65 @@ + + + \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/PSResourceDictionary.html b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/PSResourceDictionary.html new file mode 100644 index 000000000..c7d0f35d7 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/PSResourceDictionary.html @@ -0,0 +1,43 @@ + + + \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/PSServiceDictionary.html b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/PSServiceDictionary.html new file mode 100644 index 000000000..b2b9589bb --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/PSServiceDictionary.html @@ -0,0 +1,43 @@ + + + \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/PSTypeDictionary.html b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/PSTypeDictionary.html new file mode 100644 index 000000000..f48e71f3c --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/PSTypeDictionary.html @@ -0,0 +1,43 @@ + + + \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/RiskTypeDictionary.html b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/RiskTypeDictionary.html new file mode 100644 index 000000000..75b49bf46 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/RiskTypeDictionary.html @@ -0,0 +1,43 @@ + + + diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/SafePolicyWarningDictionary.html b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/SafePolicyWarningDictionary.html new file mode 100644 index 000000000..726e02235 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Dictionary/SafePolicyWarningDictionary.html @@ -0,0 +1,49 @@ + + + \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Edit_Roles_Window.html b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Edit_Roles_Window.html new file mode 100644 index 000000000..2c19e02dd --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/Edit_Roles_Window.html @@ -0,0 +1,48 @@ + + + \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/PDPTabWindows/AddorEditPDPtoGroup.html b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/PDPTabWindows/AddorEditPDPtoGroup.html new file mode 100644 index 000000000..a38b0bb9e --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/PDPTabWindows/AddorEditPDPtoGroup.html @@ -0,0 +1,56 @@ + + + diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/PDPTabWindows/PdpStatusWindow.html b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/PDPTabWindows/PdpStatusWindow.html new file mode 100644 index 000000000..195ac8332 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/PDPTabWindows/PdpStatusWindow.html @@ -0,0 +1,73 @@ + + + + diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/PushtabWindow/removeGroupPoliciesWindow.html b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/PushtabWindow/removeGroupPoliciesWindow.html new file mode 100644 index 000000000..389d31374 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/PushtabWindow/removeGroupPoliciesWindow.html @@ -0,0 +1,35 @@ + + + diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/new_PDPGroup_Window.html b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/new_PDPGroup_Window.html new file mode 100644 index 000000000..9de838015 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/Windows/new_PDPGroup_Window.html @@ -0,0 +1,94 @@ + + + + + + + diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/AutoPushController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/AutoPushController.js new file mode 100644 index 000000000..c6a6e3587 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/AutoPushController.js @@ -0,0 +1,201 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +app.controller('policyPushController', function ($scope, PDPService, AdminTabService, AutoPushService, modalService, $modal, Notification,$filter){ + $( "#dialog" ).hide(); + + $scope.isDisabled = true; + $scope.loading = true; + + AdminTabService.getData().then(function(data){ + var j = data; + $scope.data = JSON.parse(j.data); + $scope.lockdowndata = JSON.parse($scope.data.lockdowndata); + if($scope.lockdowndata[0].lockdown == true){ + $scope.isDisabled = true; + }else{ + $scope.isDisabled = false; + } + console.log($scope.data); + },function(error){ + console.log("failed"); + }); + + $scope.pdpdata; + PDPService.getPDPData().then(function (data) { + var j = data; + $scope.pdpdata = JSON.parse(j.data); + console.log($scope.pdpdata); + $scope.pushTabPDPGrid.data = $scope.pdpdata; + }, function (error) { + console.log("failed"); + }); + + $scope.getPDPData = function(){ + $scope.pushTabPDPGrid.data = $scope.pdpdata; + }; + $scope.filterPdpGroup; + $scope.filterPDPGroupData = function() { + $scope.pushTabPDPGrid.data = $filter('filter')($scope.pdpdata, $scope.filterPdpGroup, undefined); + }; + + $scope.pushTabPDPGrid = { + onRegisterApi: function(gridApi) { + $scope.gridApi = gridApi; + }, + enableFiltering: true, + columnDefs: [ + { field: 'default',displayName : '', enableFiltering : false, enableSorting : false, + cellTemplate: ' ', + width: '8%' + }, + { field: 'id', displayName : 'ID'}, + { field: 'name', displayName : 'Name' }, + { field: 'description' } + ] + }; + + + $scope.editPDPGroupWindow = function (selectedPdpGroupData) { + $scope.removePDPGroupPolicies = selectedPdpGroupData; + if($scope.isDisabled){ + Notification.error("Policy Application has been LockDown."); + }else{ + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl: 'remove_PDPGroupPolicies_popup.html', + controller: 'removeGroupPoliciesController', + resolve: { + message: function () { + var message = { + selectedPdpGroupData: $scope.removePDPGroupPolicies + }; + return message; + } + } + }); + modalInstance.result.then(function (response) { + console.log('response', response); + $scope.pdpdata = JSON.parse(response.data); + $scope.pushTabPDPGrid.data = $scope.pdpdata; + }); + } + }; + + $scope.gridOptions = { + onRegisterApi: function(gridApi) { + $scope.gridPolicyApi = gridApi; + }, + enableSorting: true, + enableFiltering: true, + showTreeExpandNoChildren: true, + paginationPageSizes: [10, 20, 50, 100], + paginationPageSize: 20, + columnDefs: [{name: 'name'}, {name: 'version'}, {name: 'dateModified'}] + }; + + $scope.files; + var data = []; + $scope.filterPolicy; + $scope.filterPolicyData = function() { + $scope.gridOptions.data = $filter('filter')($scope.files, $scope.filterPolicy, undefined); + }; + + AutoPushService.getAutoPushPoliciesData().then(function (data1) { + $scope.loading = false; + $scope.files = data1.data; + var data = data1.data; + + var id=0; + var writeoutNode = function(childArray, currentLevel, dataArray){ + childArray.forEach( function(childNode){ + if (childNode.files.length > 0){ + childNode.$$treeLevel = currentLevel; + id=childNode.categoryId; + if(childNode.categoryId == childNode.parentCategoryId){ + childNode.parent=''; + } + }else{ + if((id!=childNode.parentCategoryId) || (childNode.categoryId == childNode.parentCategoryId)){ + if(childNode.categoryId == childNode.parentCategoryId){ + childNode.parent=''; + } + childNode.$$treeLevel = currentLevel; + } + } + dataArray.push( childNode ); + writeoutNode( childNode.files, currentLevel + 1, dataArray ); + }); + }; + + $scope.gridOptions.data = []; + writeoutNode(data, 0, $scope.gridOptions.data); + }, function (error) { + console.log("failed"); + }); + + + + $scope.pushPoliciesButton = function(){ + var policySelection = $scope.gridPolicyApi.selection.getSelectedRows(); + console.log(policySelection); + var currentSelection = $scope.gridApi.selection.getSelectedRows(); + if(policySelection.length == 0 && currentSelection.length == 0){ + Notification.error("Please Select Policy and PDP Group to Push"); + } + if(policySelection.length == 0 && currentSelection.length != 0){ + Notification.error("Please Select Policy to Push"); + } + if(policySelection.length != 0 && currentSelection.length == 0){ + Notification.error("Please Select PDP Group to Push"); + } + if(policySelection.length != 0 && currentSelection.length != 0){ + var finalData = { + "pdpDatas": currentSelection, + "policyDatas": policySelection + }; + console.log(finalData); + var uuu = "auto_Push/PushPolicyToPDP.htm"; + var postData={pushTabData: finalData}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){ + $scope.data=data.data; + $scope.pdpdata = JSON.parse(data.data); + $scope.pushTabPDPGrid.data = $scope.pdpdata; + Notification.success("Policy Pushed Successfully"); + }); + console.log($scope.data); + }, + error : function(data){ + Notification.error("Error Occured while Pushing Policy."); + } + }); + + } + }; + + +}); diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/AutoPushTabController/RemovePDPGroupPoliciesController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/AutoPushTabController/RemovePDPGroupPoliciesController.js new file mode 100644 index 000000000..2a6c8c38f --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/AutoPushTabController/RemovePDPGroupPoliciesController.js @@ -0,0 +1,85 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +var removeGroupPoliciesController = function ($scope, $modalInstance, message, Notification){ + if(message.selectedPdpGroupData !=null){ + $scope.label='Remove PDP Group Policies' + $scope.disableCd=true; + } + $scope.policies = message.selectedPdpGroupData.policies; + $scope.pdpGroupData = message.selectedPdpGroupData; + + $scope.removePoliciesGrid = { + data : 'policies', + enableFiltering: true, + columnDefs: [ + { field: 'root', displayName : 'Root', width : '10%'}, + { field: 'name', displayName : 'Name' }, + { field: 'version' , width : '10%'}, + { field: 'id' } + ] + }; + + $scope.removePoliciesGrid.onRegisterApi = function(gridApi){ + //set gridApi on scope + $scope.gridApi = gridApi; + gridApi.selection.on.rowSelectionChanged($scope,function(row){ + var msg = 'row selected ' + row.isSelected; + }); + + gridApi.selection.on.rowSelectionChangedBatch($scope,function(rows){ + var msg = 'rows changed ' + rows.length; + }); + }; + + $scope.removePolicies = function() { + $scope.removeGroupData = []; + angular.forEach($scope.gridApi.selection.getSelectedRows(), function (data, index) { + $scope.removeGroupData.push(data); + }); + var uuu = "auto_Push/remove_GroupPolicies.htm"; + var postData={data: $scope.removeGroupData, + activePdpGroup : $scope.pdpGroupData}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){ + $scope.data=data.data;}); + console.log($scope.data); + $modalInstance.close({data:$scope.data}); + Notification.success("Policy Removed Successfully"); + }, + error : function(data){ + Notification.error("Error Occured while removing Policy"); + } + }); + + }; + + $scope.close = function() { + $modalInstance.close(); + }; +} diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/DictionaryController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/DictionaryController.js new file mode 100644 index 000000000..ea3f6c8dc --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/DictionaryController.js @@ -0,0 +1,82 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +var mainDictionarys = ["Action Policy", "BRMS Policy", "Common Dictionary", "ClosedLoop Policy","Decision Policy", "Descriptive Policy", + "Enforcer Policy", "Firewall Policy", "MicroService Policy", "Policy Scope", "Safe Policy Dictionary"]; +var subDictionarys = [["Action Dictionary"], + ["BRMS Param Template"], + ["Attribute Dictionary","EcompName Dictionary"], + ["PEP Options","Site Dictionary","Service Dictionary","Varbind Dictionary", "VNF Type","VSCL Action"], + ["Settings Dictionary"], + ["Descriptive Scope"], + ["Enforcer Dictionary"], + ["Action List", "Address Group", "Parent Dictionary List", "Port List", "Prefix List", "Protocol List", "Security Zone", "Service Group", "Service List", "Term List", "Zone"], + ["DCAE UUID","MicroService ConfigName","MicroService Location", "MicroService Models"], + ["Closed Loop", "Group Policy Scope", "Resource", "Service", "Type"], + ["Risk Type", "Safe Policy Warning"]]; +app.controller('dictionaryTabController', function ($scope, AdminTabService, modalService, $modal){ + $( "#dialog" ).hide(); + + $scope.isDisabled = true; + AdminTabService.getData().then(function(data){ + var j = data; + $scope.data = JSON.parse(j.data); + $scope.lockdowndata = JSON.parse($scope.data.lockdowndata); + if($scope.lockdowndata[0].lockdown == true){ + $scope.isDisabled = true; + this.isDisabled = true; + }else{ + $scope.isDisabled = false; + this.isDisabled = false; + } + console.log($scope.data); + },function(error){ + console.log("failed"); + }); + + $scope.options1 = mainDictionarys; + $scope.options2 = []; + $scope.getOptions2 = function(){ + var key = $scope.options1.indexOf($scope.option1); + var myNewOptions = subDictionarys[key]; + $scope.options2 = myNewOptions; + }; + + $scope.import = function() { + $scope.data = {}; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'import_dictionary_popup.html', + controller: 'importDictionaryController', + resolve: { + message: function () { + var message = { + data: $scope.data + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + }); + }; + +}); \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/FileSaver.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/FileSaver.js new file mode 100644 index 000000000..8a77cd007 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/FileSaver.js @@ -0,0 +1,170 @@ +var saveAs = saveAs || (function(view) { + "use strict"; + // IE <10 is explicitly unsupported + if (typeof view === "undefined" || typeof navigator !== "undefined" && /MSIE [1-9]\./.test(navigator.userAgent)) { + return; + } + var + doc = view.document + // only get URL when necessary in case Blob.js hasn't overridden it yet + , get_URL = function() { + return view.URL || view.webkitURL || view; + } + , save_link = doc.createElementNS("http://www.w3.org/1999/xhtml", "a") + , can_use_save_link = "download" in save_link + , click = function(node) { + var event = new MouseEvent("click"); + node.dispatchEvent(event); + } + , is_safari = /constructor/i.test(view.HTMLElement) + , throw_outside = function(ex) { + (view.setImmediate || view.setTimeout)(function() { + throw ex; + }, 0); + } + , force_saveable_type = "application/octet-stream" + // the Blob API is fundamentally broken as there is no "downloadfinished" event to subscribe to + , arbitrary_revoke_timeout = 1000 * 40 // in ms + , revoke = function(file) { + var revoker = function() { + if (typeof file === "string") { // file is an object URL + get_URL().revokeObjectURL(file); + } else { // file is a File + file.remove(); + } + }; + setTimeout(revoker, arbitrary_revoke_timeout); + } + , dispatch = function(filesaver, event_types, event) { + event_types = [].concat(event_types); + var i = event_types.length; + while (i--) { + var listener = filesaver["on" + event_types[i]]; + if (typeof listener === "function") { + try { + listener.call(filesaver, event || filesaver); + } catch (ex) { + throw_outside(ex); + } + } + } + } + , auto_bom = function(blob) { + // prepend BOM for UTF-8 XML and text/* types (including HTML) + // note: your browser will automatically convert UTF-16 U+FEFF to EF BB BF + if (/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(blob.type)) { + return new Blob([String.fromCharCode(0xFEFF), blob], {type: blob.type}); + } + return blob; + } + , FileSaver = function(blob, name, no_auto_bom) { + if (!no_auto_bom) { + blob = auto_bom(blob); + } + // First try a.download, then web filesystem, then object URLs + var + filesaver = this + , type = blob.type + , force = type === force_saveable_type + , object_url + , dispatch_all = function() { + dispatch(filesaver, "writestart progress write writeend".split(" ")); + } + // on any filesys errors revert to saving with object URLs + , fs_error = function() { + if (force && is_safari && view.FileReader) { + // Safari doesn't allow downloading of blob urls + var reader = new FileReader(); + reader.onloadend = function() { + var base64Data = reader.result; + view.location.href = "data:attachment/file" + base64Data.slice(base64Data.search(/[,;]/)); + filesaver.readyState = filesaver.DONE; + dispatch_all(); + }; + reader.readAsDataURL(blob); + filesaver.readyState = filesaver.INIT; + return; + } + // don't create more object URLs than needed + if (!object_url) { + object_url = get_URL().createObjectURL(blob); + } + if (force) { + view.location.href = object_url; + } else { + var opened = view.open(object_url, "_blank"); + if (!opened) { + // Apple does not allow window.open, see https://developer.apple.com/library/safari/documentation/Tools/Conceptual/SafariExtensionGuide/WorkingwithWindowsandTabs/WorkingwithWindowsandTabs.html + view.location.href = object_url; + } + } + filesaver.readyState = filesaver.DONE; + dispatch_all(); + revoke(object_url); + } + ; + filesaver.readyState = filesaver.INIT; + + if (can_use_save_link) { + object_url = get_URL().createObjectURL(blob); + setTimeout(function() { + save_link.href = object_url; + save_link.download = name; + click(save_link); + dispatch_all(); + revoke(object_url); + filesaver.readyState = filesaver.DONE; + }); + return; + } + + fs_error(); + } + , FS_proto = FileSaver.prototype + , saveAs = function(blob, name, no_auto_bom) { + return new FileSaver(blob, name || blob.name || "download", no_auto_bom); + } + ; + // IE 10+ (native saveAs) + if (typeof navigator !== "undefined" && navigator.msSaveOrOpenBlob) { + return function(blob, name, no_auto_bom) { + name = name || blob.name || "download"; + + if (!no_auto_bom) { + blob = auto_bom(blob); + } + return navigator.msSaveOrOpenBlob(blob, name); + }; + } + + FS_proto.abort = function(){}; + FS_proto.readyState = FS_proto.INIT = 0; + FS_proto.WRITING = 1; + FS_proto.DONE = 2; + + FS_proto.error = + FS_proto.onwritestart = + FS_proto.onprogress = + FS_proto.onwrite = + FS_proto.onabort = + FS_proto.onerror = + FS_proto.onwriteend = + null; + + return saveAs; + }( + typeof self !== "undefined" && self + || typeof window !== "undefined" && window + || this.content + )); +// `self` is undefined in Firefox for Android content script context +// while `this` is nsIContentFrameMessageManager +// with an attribute `content` that corresponds to the window + +if (typeof module !== "undefined" && module.exports) { + module.exports.saveAs = saveAs; +} else if ((typeof define !== "undefined" && define !== null) && (define.amd !== null)) { + define([], function() { + return saveAs; + }); +} \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/ImportDictionaryController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/ImportDictionaryController.js new file mode 100644 index 000000000..c8e535363 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/ImportDictionaryController.js @@ -0,0 +1,53 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +var importDictionaryController = function ($scope, $modalInstance, message, $http, PapUrlService, UserInfoService){ + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + }); + + /*getting user info from session*/ + var loginId = null; + UserInfoService.getFunctionalMenuStaticDetailSession() + .then(function (response) { + loginId = response.userid; + }); + + $scope.uploadFile = function(files) { + var fd = new FormData(); + fd.append("file", files[0]); + + $http.post(papUrl + "/ecomp/dictionary/import_dictionary.htm/" + loginId, fd, { + withCredentials: false, + headers: {'Content-Type': undefined}, + transformRequest: angular.identity + }).success().error( ); + }; + + $scope.close = function() { + $modalInstance.close(); + }; +} \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/PDPTabController/AddorEditPdpInGroup.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/PDPTabController/AddorEditPdpInGroup.js new file mode 100644 index 000000000..c1d42287d --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/PDPTabController/AddorEditPdpInGroup.js @@ -0,0 +1,62 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +var pdpInGroupController = function ($scope, $modalInstance, message, Notification){ + $scope.edit = 'false'; + if(message.pdpInGroup==null) + $scope.label='Add PDP to Group' + else{ + $scope.label='Edit PDP In Group' + $scope.disableCd=true; + $scope.edit = 'true'; + } + $scope.editPDPInGroup = message.pdpInGroup; + $scope.editActivePDP = message.activePDP; + + $scope.savePDPInGroup = function(pdpInGroup) { + var uuu = "pdp_Group/save_pdpTogroup.htm"; + var postData={pdpInGroup: pdpInGroup, + activePDP: $scope.editActivePDP, + update : $scope.edit}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){ + $scope.data=data.data;}); + console.log($scope.data); + $modalInstance.close({data:$scope.data}); + }, + error : function(data){ + Notification.error("Error Occured while Creating/Updating a PDP Group"); + } + }); + }; + + $scope.close = function() { + $modalInstance.close(); + }; +} + diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/PDPTabController/PDPGroupStatusController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/PDPTabController/PDPGroupStatusController.js new file mode 100644 index 000000000..293b853b9 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/PDPTabController/PDPGroupStatusController.js @@ -0,0 +1,44 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +var pdpGroupStatusController = function ($scope, $modalInstance, message){ + if(message.status==null) { + $scope.label = 'No Status to Display' + }else{ + $scope.label='Status' + $scope.disableCd=true; + $scope.policies = message.policies; + $scope.pdpStatusDatas = message.status; + } + + $scope.policiesGrid = { + data : 'policies', + enableFiltering: true, + columnDefs: [ + { field: 'name', displayName : 'Name' } + ] + }; + + $scope.close = function() { + $modalInstance.close(); + }; +} \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/PolicyAddScopeRoleController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/PolicyAddScopeRoleController.js new file mode 100644 index 000000000..4722144bc --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/PolicyAddScopeRoleController.js @@ -0,0 +1,65 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + * + */ +var editRoleController = function ($scope, RolesTabService, $modalInstance, message){ + if(message.editRoleData!=null){ + $scope.label='Edit Role' + $scope.disableCd=true; + } + $scope.editRole = message.editRoleData; + + RolesTabService.getPolicyScopesData().then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.scopeDatas = JSON.parse($scope.data.scopeDatas); + console.log($scope.scopeDatas); + }, function (error) { + console.log("failed"); + }); + + $scope.saveRole = function(editRoleData) { + var uuu = "save_NonSuperRolesData.htm"; + var postData={editRoleData: editRoleData}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){ + $scope.rolesDatas=data.rolesDatas;}); + console.log($scope.rolesDatas); + $modalInstance.close({rolesDatas:$scope.rolesDatas}); + }, + error : function(data){ + alert("Error while saving Role."); + } + }); + }; + + $scope.close = function() { + $modalInstance.close(); + }; +} \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/PolicyRolesController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/PolicyRolesController.js new file mode 100644 index 000000000..d5859abe3 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/PolicyRolesController.js @@ -0,0 +1,95 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + * + */ +app.controller('policyRolesController', function ($scope, RolesTabService,modalService, $modal, AdminTabService, Notification){ + $( "#dialog" ).hide(); + + $scope.isDisabled = true; + AdminTabService.getData().then(function(data){ + var j = data; + $scope.data = JSON.parse(j.data); + $scope.lockdowndata = JSON.parse($scope.data.lockdowndata); + if($scope.lockdowndata[0].lockdown == true){ + $scope.isDisabled = true; + }else{ + $scope.isDisabled = false; + } + console.log($scope.data); + },function(error){ + console.log("failed"); + }); + + $scope.scopeDatas = []; + RolesTabService.getRolesData().then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.rolesDatas = JSON.parse($scope.data.rolesDatas); + console.log($scope.rolesDatas); + }, function (error) { + console.log("failed"); + }); + + $scope.rolesTableGrid = { + data : 'rolesDatas', + enableFiltering: true, + columnDefs: [{ + field: 'id', enableFiltering: false, + cellTemplate: + '', width: '8%' + }, + { field: 'loginId.userName', displayName : 'Name'}, + { field: 'scope', displayName : 'Scope' }, + { field: 'role', displayName : 'Role' } + ] + }; + + + $scope.editRoleName = null; + + $scope.editRolesWindow = function(editRoleData) { + if($scope.lockdowndata[0].lockdown == true){ + Notification.error("Policy Application has been Locked") + }else{ + $scope.editRoleName = editRoleData; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'edit_Role_popup.html', + controller: 'editRoleController', + resolve: { + message: function () { + var message = { + editRoleData: $scope.editRoleName + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + }); + } + + }; + +}); \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dashboardController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dashboardController.js new file mode 100644 index 000000000..9ff974351 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dashboardController.js @@ -0,0 +1,125 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +app.controller('policyDashboardHealthController', function ($scope,DashboardService,modalService, $modal){ + $( "#dialog" ).hide(); + $scope.pdpTableDatas = []; + $scope.papTableDatas = []; + $scope.policyActivityTableDatas = []; + DashboardService.getSystemAlertData().then(function(data){ + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.systemAlertsTableDatas =JSON.parse($scope.data.systemAlertsTableDatas); + },function(error){ + console.log("failed"); + //reloadPageOnce(); + }); + + DashboardService.getPAPStatusData().then(function(data){ + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.papTableMapDatas =JSON.parse($scope.data.papTableDatas); + if($scope.papTableMapDatas != null){ + for(i = 0; i < $scope.papTableMapDatas.length; i++){ + $scope.papTableDatas.push($scope.papTableMapDatas[i].map); + } + } + },function(error){ + console.log("failed"); + //reloadPageOnce(); + }); + + DashboardService.getPDPStatusData().then(function(data){ + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.pdpTableMapDatas =JSON.parse($scope.data.pdpTableDatas); + if($scope.pdpTableMapDatas != null) { + for (i = 0; i < $scope.pdpTableMapDatas.length; i++) { + $scope.pdpTableDatas.push($scope.pdpTableMapDatas[i].map); + } + } + },function(error){ + console.log("failed"); + //reloadPageOnce(); + }); + + DashboardService.getPolicyActivityData().then(function(data){ + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.policyActivityTableMapDatas =JSON.parse($scope.data.policyActivityTableDatas); + if($scope.policyActivityTableMapDatas != null) { + for (i = 0; i < $scope.policyActivityTableMapDatas.length; i++) { + $scope.policyActivityTableDatas.push($scope.policyActivityTableMapDatas[i].map); + } + } + },function(error){ + console.log("failed"); + //reloadPageOnce(); + }); + + $scope.availableGridHealthDatas = { + data : 'systemAlertsTableDatas', + enableFiltering: true, + columnDefs: [{ field: 'id'}, + { field: 'type'}, + { field: 'system'}, + {field: 'logtype'}, + {field : 'date' ,type: 'date', cellFilter: 'date:\'yyyy-MM-dd\'' }, + {field : 'description'} + ], + }; + + $scope.papStatusDatas = { + data : 'papTableDatas', + enableFiltering: true, + columnDefs: [{ field: 'system'}, + { field: 'status'}, + { field: 'noOfPolicy'}, + {field: 'noOfConnectedTrap'} + ], + }; + + $scope.pdpStatusDatas = { + data : 'pdpTableDatas', + enableFiltering: true, + columnDefs: [{ field: 'id'}, + { field: 'name'}, + { field: 'groupname'}, + {field: 'status'}, + {field : 'description' }, + {field : 'permitCount'}, + {field : 'denyCount'}, + {field : 'naCount'} + ], + }; + + $scope.policyActivityDatas = { + data : 'policyActivityTableDatas', + enableFiltering: true, + columnDefs: [{ field: 'policyId'}, + { field: 'fireCount'}, + { field: 'system'} + ], + }; +}); \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dashboard_Logging_Controller.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dashboard_Logging_Controller.js new file mode 100644 index 000000000..7b07b1d71 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dashboard_Logging_Controller.js @@ -0,0 +1,81 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +app.controller('policyDashboardController', function ($scope,DashboardService,modalService, $modal, uiGridConstants,Grid){ + $( "#dialog" ).hide(); + + $scope.loading = true; + DashboardService.getData().then(function(data){ + $scope.loading = false; + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.availableLoggingDatas =JSON.parse($scope.data.availableLoggingDatas); + console.log($scope.availableLoggingDatas); + },function(error){ + console.log("failed"); + //reloadPageOnce(); + }); + + $scope.availableGridLoggingDatas = { + data : 'availableLoggingDatas', + enableFiltering: true, + columnDefs: [{ field: 'id'}, + { field: 'type'}, + { field: 'system'}, + {field: 'logtype'}, + {field : 'date' ,type: 'date', cellFilter: 'date:\'yyyy-MM-dd HH:MM:ss a\'' }, + {field : 'description'} + ], + enableGridMenu: true, + enableSelectAll: true, + exporterCsvFilename: 'DashboardLogging.csv', + exporterPdfDefaultStyle: {fontSize: 9}, + exporterPdfTableStyle: {margin: [30, 30, 30, 30]}, + exporterPdfTableHeaderStyle: {fontSize: 10, bold: true, italics: true, color: 'red'}, + exporterPdfHeader: { text: "My Header", style: 'headerStyle' }, + exporterPdfFooter: function ( currentPage, pageCount ) { + return { text: currentPage.toString() + ' of ' + pageCount.toString(), style: 'footerStyle' }; + }, + exporterPdfCustomFormatter: function ( docDefinition ) { + docDefinition.styles.headerStyle = { fontSize: 22, bold: true }; + docDefinition.styles.footerStyle = { fontSize: 10, bold: true }; + return docDefinition; + }, + exporterFieldCallback: function(grid, row, col, input) { + if( col.name == 'date') { + var date = new Date(input); + return date; + } else { + return input; + } + }, + exporterPdfOrientation: 'portrait', + exporterPdfPageSize: 'LETTER', + exporterPdfMaxGridWidth: 500, + exporterCsvLinkElement: angular.element(document.querySelectorAll(".custom-csv-link-location")), + onRegisterApi: function(gridApi){ + $scope.gridApi = gridApi; + } + + }; + +}); + diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/BRMSParamDictController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/BRMSParamDictController.js new file mode 100644 index 000000000..030f08f43 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/BRMSParamDictController.js @@ -0,0 +1,88 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +var editBRMSParamController = function ($scope, $modalInstance, message, $http, PapUrlService, UserInfoService, Notification){ + if(message.brmsParamDictionaryData==null) + $scope.label='Add BRMS Rule' + else{ + $scope.label='Edit BRMS Rule' + $scope.disableCd=true; + } + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + }); + + /*getting user info from session*/ + var loginId = null; + UserInfoService.getFunctionalMenuStaticDetailSession() + .then(function (response) { + loginId = response.userid; + }); + + $scope.editBRMSParam = message.brmsParamDictionaryData; + + $scope.uploadFile = function(files) { + var fd = new FormData(); + fd.append("file", files[0]); + $http.post(papUrl + "/ecomp/brms_dictionary/set_BRMSParamData.htm", fd, { + withCredentials: false, + headers: {'Content-Type': undefined }, + transformRequest: angular.identity + }).success().error( ); + + }; + + $scope.MyFile = []; + $scope.saveBRMSParam = function(brmsParamDictionaryData) { + var file = $scope.MyFile; + var uuu = papUrl + "/ecomp/brms_dictionary/save_BRMSParam.htm"; + var postData={brmsParamDictionaryData: brmsParamDictionaryData, loginId: loginId}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){ + $scope.brmsParamDictionaryDatas=data.brmsParamDictionaryDatas;}); + if($scope.brmsParamDictionaryDatas == "Duplicate"){ + Notification.error("BRMSParan Dictionary exists with Same Name.") + }else{ + console.log($scope.brmsParamDictionaryDatas); + $modalInstance.close({brmsParamDictionaryDatas:$scope.brmsParamDictionaryDatas}); + } + }, + error : function(data){ + alert("Error while saving."); + } + }); + }; + + $scope.close = function() { + $modalInstance.close(); + }; +} \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/CLPepOptionsDictController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/CLPepOptionsDictController.js new file mode 100644 index 000000000..5ec078f11 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/CLPepOptionsDictController.js @@ -0,0 +1,120 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +var editPEPOptionsController = function ($scope, $modalInstance, message, PapUrlService, UserInfoService, Notification){ + if(message.pepOptionsDictionaryData==null) + $scope.label='Add PEP Options', + $scope.choices = []; + else{ + $scope.label='Edit PEP Options' + $scope.disableCd=true; + $scope.choices = []; + var headers = message.pepOptionsDictionaryData.actions; + var SplitChars = ':#@'; + if (headers.indexOf(SplitChars) >= 0) { + var splitHeader = headers.split(SplitChars); + var singleHeader = splitHeader; + var splitEqual = '=#@'; + for(i = 0; i < singleHeader.length; i++){ + if (singleHeader[i].indexOf(splitEqual) >= 0) { + var splitValue = singleHeader[i].split(splitEqual); + var key = splitValue[0]; + var value = splitValue[1]; + var newItemNo = $scope.choices.length+1; + $scope.choices.push({'id':'choice'+newItemNo, 'option': key , 'number' : value }); + } + } + }else{ + var splitEqual = '=#@'; + if (headers.indexOf(splitEqual) >= 0) { + var splitValue = headers.split(splitEqual); + var key = splitValue[0]; + var value = splitValue[1]; + $scope.choices.push({'id':'choice'+1, 'option': key , 'number' : value }); + } + } + } + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + }); + + /*getting user info from session*/ + var loginId = null; + UserInfoService.getFunctionalMenuStaticDetailSession() + .then(function (response) { + loginId = response.userid; + }); + + $scope.editPEPOptions = message.pepOptionsDictionaryData; + + $scope.saveCLPepOptions = function(pepOptionsDictionaryData) { + var finalData = extend(pepOptionsDictionaryData, $scope.actions[0]); + var uuu = papUrl + "/ecomp/cl_dictionary/save_pepOptions.htm"; + var postData={pepOptionsDictionaryData: finalData, loginId: loginId}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){ + $scope.pepOptionsDictionaryDatas=data.pepOptionsDictionaryDatas;}); + if($scope.pepOptionsDictionaryDatas == "Duplicate"){ + Notification.error("PEP Options Dictionary exists with Same PEP Name.") + }else{ + console.log($scope.pepOptionsDictionaryDatas); + $modalInstance.close({pepOptionsDictionaryDatas:$scope.pepOptionsDictionaryDatas}); + } + }, + error : function(data){ + alert("Error while saving."); + } + }); + }; + + $scope.close = function() { + $modalInstance.close(); + }; + + function extend(obj, src) { + for (var key in src) { + if (src.hasOwnProperty(key)) obj[key] = src[key]; + } + return obj; + } + + $scope.actions = [{"attributes" : $scope.choices}]; + $scope.addNewChoice = function() { + var newItemNo = $scope.choices.length+1; + $scope.choices.push({'id':'choice'+newItemNo}); + }; + $scope.removeChoice = function() { + var lastItem = $scope.choices.length-1; + $scope.choices.splice(lastItem); + }; + +} \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/CLServiceDictController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/CLServiceDictController.js new file mode 100644 index 000000000..c3acc72b2 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/CLServiceDictController.js @@ -0,0 +1,75 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +var editCLServiceController = function ($scope, $modalInstance, message, PapUrlService, UserInfoService, Notification){ + if(message.closedLoopServiceDictionaryData==null) + $scope.label='Add Service Name' + else{ + $scope.label='Edit Service Name' + $scope.disableCd=true; + } + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + }); + + /*getting user info from session*/ + var loginId = null; + UserInfoService.getFunctionalMenuStaticDetailSession() + .then(function (response) { + loginId = response.userid; + }); + + $scope.editCLService = message.closedLoopServiceDictionaryData; + + $scope.saveCLServiceDict = function(closedLoopServiceDictionaryData) { + var uuu = papUrl + "/ecomp/cl_dictionary/save_service.htm"; + var postData={closedLoopServiceDictionaryData: closedLoopServiceDictionaryData, loginId: loginId}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){ + $scope.closedLoopServiceDictionaryDatas=data.closedLoopServiceDictionaryDatas;}); + if($scope.closedLoopServiceDictionaryDatas == "Duplicate"){ + Notification.error("ClosedLoop Service Dictionary exists with Same Service Name.") + }else{ + console.log($scope.closedLoopServiceDictionaryDatas); + $modalInstance.close({closedLoopServiceDictionaryDatas:$scope.closedLoopServiceDictionaryDatas}); + } + }, + error : function(data){ + alert("Error while saving."); + } + }); + }; + + $scope.close = function() { + $modalInstance.close(); + }; +} \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/CLSiteDictController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/CLSiteDictController.js new file mode 100644 index 000000000..7150ca891 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/CLSiteDictController.js @@ -0,0 +1,75 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +var editCLSiteController = function ($scope, $modalInstance, message, PapUrlService, UserInfoService, Notification){ + if(message.closedLoopSiteDictionaryData==null) + $scope.label='Add Site Name' + else{ + $scope.label='Edit Site Name' + $scope.disableCd=true; + } + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + }); + + /*getting user info from session*/ + var loginId = null; + UserInfoService.getFunctionalMenuStaticDetailSession() + .then(function (response) { + loginId = response.userid; + }); + + $scope.editCLSite = message.closedLoopSiteDictionaryData; + + $scope.saveCLSite = function(closedLoopSiteDictionaryData) { + var uuu = papUrl + "/ecomp/cl_dictionary/save_siteName.htm"; + var postData={closedLoopSiteDictionaryData: closedLoopSiteDictionaryData, loginId: loginId}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){ + $scope.closedLoopSiteDictionaryDatas=data.closedLoopSiteDictionaryDatas;}); + if($scope.closedLoopSiteDictionaryDatas == "Duplicate"){ + Notification.error("ClosedLoop Site Dictionary exists with Same Site Name.") + }else{ + console.log($scope.closedLoopSiteDictionaryDatas); + $modalInstance.close({closedLoopSiteDictionaryDatas:$scope.closedLoopSiteDictionaryDatas}); + } + }, + error : function(data){ + alert("Error while saving."); + } + }); + }; + + $scope.close = function() { + $modalInstance.close(); + }; +} \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/CLVarbindDictController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/CLVarbindDictController.js new file mode 100644 index 000000000..03c2eb345 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/CLVarbindDictController.js @@ -0,0 +1,75 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +var editCLVarbindController = function ($scope, $modalInstance, message, PapUrlService, UserInfoService, Notification){ + if(message.varbindDictionaryData==null) + $scope.label='Add Varbind ' + else{ + $scope.label='Edit Varbind' + $scope.disableCd=true; + } + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + }); + + /*getting user info from session*/ + var loginId = null; + UserInfoService.getFunctionalMenuStaticDetailSession() + .then(function (response) { + loginId = response.userid; + }); + + $scope.editCLVarbind = message.varbindDictionaryData; + + $scope.saveCLVarbind = function(varbindDictionaryData) { + var uuu = papUrl + "/ecomp/cl_dictionary/save_varbind.htm"; + var postData={varbindDictionaryData: varbindDictionaryData, loginId: loginId}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){ + $scope.varbindDictionaryDatas=data.varbindDictionaryDatas;}); + if($scope.varbindDictionaryDatas == "Duplicate"){ + Notification.error("ClosedLoop Varbind Dictionary exists with Same Varbind Name.") + }else{ + console.log($scope.varbindDictionaryDatas); + $modalInstance.close({varbindDictionaryDatas:$scope.varbindDictionaryDatas}); + } + }, + error : function(data){ + alert("Error while saving."); + } + }); + }; + + $scope.close = function() { + $modalInstance.close(); + }; +} \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/CLVnfTypeDictController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/CLVnfTypeDictController.js new file mode 100644 index 000000000..5b46e67a2 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/CLVnfTypeDictController.js @@ -0,0 +1,75 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +var editVnfTypeController = function ($scope, $modalInstance, message, PapUrlService, UserInfoService, Notification){ + if(message.vnfTypeDictionaryData==null) + $scope.label='Add VNF Type' + else{ + $scope.label='Edit VNF Type' + $scope.disableCd=true; + } + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + }); + + /*getting user info from session*/ + var loginId = null; + UserInfoService.getFunctionalMenuStaticDetailSession() + .then(function (response) { + loginId = response.userid; + }); + + $scope.editVnfType = message.vnfTypeDictionaryData; + + $scope.saveCLVnfType = function(vnfTypeDictionaryData) { + var uuu = papUrl + "/ecomp/cl_dictionary/save_vnfType.htm"; + var postData={vnfTypeDictionaryData: vnfTypeDictionaryData, loginId: loginId}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){ + $scope.vnfTypeDictionaryDatas=data.vnfTypeDictionaryDatas;}); + if($scope.vnfTypeDictionaryDatas == "Duplicate"){ + Notification.error("ClosedLoop VNFType Dictionary exists with Same VNFType Name.") + }else{ + console.log($scope.vnfTypeDictionaryDatas); + $modalInstance.close({vnfTypeDictionaryDatas:$scope.vnfTypeDictionaryDatas}); + } + }, + error : function(data){ + alert("Error while saving."); + } + }); + }; + + $scope.close = function() { + $modalInstance.close(); + }; +} \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/CLVsclActionDictController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/CLVsclActionDictController.js new file mode 100644 index 000000000..d69a30e7a --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/CLVsclActionDictController.js @@ -0,0 +1,75 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +var editVsclActionController = function ($scope, $modalInstance, message, PapUrlService, UserInfoService, Notification){ + if(message.vsclActionDictionaryData==null) + $scope.label='Add VSCL Action' + else{ + $scope.label='Edit VSCL Action' + $scope.disableCd=true; + } + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + }); + + /*getting user info from session*/ + var loginId = null; + UserInfoService.getFunctionalMenuStaticDetailSession() + .then(function (response) { + loginId = response.userid; + }); + + $scope.editvsclAction = message.vsclActionDictionaryData; + + $scope.saveCLVSCLAction = function(vsclActionDictionaryData) { + var uuu = papUrl + "/ecomp/cl_dictionary/save_vsclAction.htm"; + var postData={vsclActionDictionaryData: vsclActionDictionaryData, loginId: loginId}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){ + $scope.vsclActionDictionaryDatas=data.vsclActionDictionaryDatas;}); + if($scope.vsclActionDictionaryDatas == "Duplicate"){ + Notification.error("ClosedLoop VSCLAction Dictionary exists with Same VSCLAction Name.") + }else{ + console.log($scope.vsclActionDictionaryDatas); + $modalInstance.close({vsclActionDictionaryDatas:$scope.vsclActionDictionaryDatas}); + } + }, + error : function(data){ + alert("Error while saving."); + } + }); + }; + + $scope.close = function() { + $modalInstance.close(); + }; +} \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/DecisionSettingsDictController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/DecisionSettingsDictController.js new file mode 100644 index 000000000..cbe99c094 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/DecisionSettingsDictController.js @@ -0,0 +1,75 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +var editSettingsDictController = function ($scope, $modalInstance, message, PapUrlService, UserInfoService, Notification){ + if(message.settingsDictionaryData==null) + $scope.label='Add Decision Settings' + else{ + $scope.label='Edit Decision Settings' + $scope.disableCd=true; + } + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + }); + + /*getting user info from session*/ + var loginId = null; + UserInfoService.getFunctionalMenuStaticDetailSession() + .then(function (response) { + loginId = response.userid; + }); + + $scope.editSettingsDict = message.settingsDictionaryData; + + $scope.saveDecisionSettings = function(settingsDictionaryData) { + var uuu = papUrl + "/ecomp/decision_dictionary/save_Settings.htm"; + var postData={settingsDictionaryData: settingsDictionaryData, loginId: loginId}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){ + $scope.settingsDictionaryDatas=data.settingsDictionaryDatas;}); + if($scope.settingsDictionaryDatas == "Duplicate"){ + Notification.error("Decision Dictionary exists with Same Settings Name.") + }else{ + console.log($scope.settingsDictionaryDatas); + $modalInstance.close({settingsDictionaryDatas:$scope.settingsDictionaryDatas}); + } + }, + error : function(data){ + alert("Error while saving."); + } + }); + }; + + $scope.close = function() { + $modalInstance.close(); + }; +} \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/DescriptiveSearchDictController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/DescriptiveSearchDictController.js new file mode 100644 index 000000000..f78cedc24 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/DescriptiveSearchDictController.js @@ -0,0 +1,121 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +var editDescriptiveScopeController = function ($scope, $modalInstance, message, PapUrlService, UserInfoService, Notification){ + if(message.descriptiveScopeDictionaryData==null) + $scope.label='Add Descriptive Scope', + $scope.choices = []; + else{ + $scope.label='Edit Descriptive Scope' + $scope.disableCd=true; + $scope.choices = []; + var headers = message.descriptiveScopeDictionaryData.search; + var SplitChars = 'AND'; + if (headers.indexOf(SplitChars) >= 0) { + var splitHeader = headers.split(SplitChars); + var singleHeader = splitHeader; + var splitEqual = ':'; + for(i = 0; i < singleHeader.length; i++){ + if (singleHeader[i].indexOf(splitEqual) >= 0) { + var splitValue = singleHeader[i].split(splitEqual); + var key = splitValue[0]; + var value = splitValue[1]; + var newItemNo = $scope.choices.length+1; + $scope.choices.push({'id':'choice'+newItemNo, 'option': key , 'number' : value }); + } + } + }else{ + var splitEqual = ':'; + if (headers.indexOf(splitEqual) >= 0) { + var splitValue = headers.split(splitEqual); + var key = splitValue[0]; + var value = splitValue[1]; + $scope.choices.push({'id':'choice'+1, 'option': key , 'number' : value }); + } + } + } + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + }); + + /*getting user info from session*/ + var loginId = null; + UserInfoService.getFunctionalMenuStaticDetailSession() + .then(function (response) { + loginId = response.userid; + }); + + $scope.editDescriptiveScope = message.descriptiveScopeDictionaryData; + + $scope.saveDescriptiveScope = function(descriptiveScopeDictionaryData) { + var finalData = extend(descriptiveScopeDictionaryData, $scope.actions[0]); + var uuu = papUrl + "/ecomp/descriptive_dictionary/save_descriptive.htm"; + var postData={descriptiveScopeDictionaryData: finalData, loginId: loginId}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){ + $scope.descriptiveScopeDictionaryDatas=data.descriptiveScopeDictionaryDatas;}); + if($scope.descriptiveScopeDictionaryDatas == "Duplicate"){ + Notification.error("Descriptive Scope Dictionary exists with Same Scope Name.") + }else{ + console.log($scope.descriptiveScopeDictionaryDatas); + $modalInstance.close({descriptiveScopeDictionaryDatas:$scope.descriptiveScopeDictionaryDatas}); + } + + }, + error : function(data){ + alert("Error while saving."); + } + }); + }; + + $scope.close = function() { + $modalInstance.close(); + }; + + function extend(obj, src) { + for (var key in src) { + if (src.hasOwnProperty(key)) obj[key] = src[key]; + } + return obj; + } + + $scope.actions = [{"attributes" : $scope.choices}]; + $scope.addNewChoice = function() { + var newItemNo = $scope.choices.length+1; + $scope.choices.push({'id':'choice'+newItemNo}); + }; + $scope.removeChoice = function() { + var lastItem = $scope.choices.length-1; + $scope.choices.splice(lastItem); + }; + +} \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/EnforcerDictController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/EnforcerDictController.js new file mode 100644 index 000000000..caf17204f --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/EnforcerDictController.js @@ -0,0 +1,70 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +var editEnforcerTypeController = function ($scope, $modalInstance, message, PapUrlService, UserInfoService){ + if(message.enforcerDictionaryData==null) + $scope.label='Add Enforcing Type' + else{ + $scope.label='Edit Enforcing Type' + $scope.disableCd=true; + } + $scope.editEnforcerType = message.enforcerDictionaryData; + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + }); + + /*getting user info from session*/ + var loginId = null; + UserInfoService.getFunctionalMenuStaticDetailSession() + .then(function (response) { + loginId = response.userid; + }); + + $scope.saveEnforcerType = function(enforcerDictionaryData) { + var uuu = papUrl + "/ecomp/enforcer_dictionary/save_enforcerType.htm"; + var postData={enforcerDictionaryData: enforcerDictionaryData, loginId: loginId}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){ + $scope.enforcerDictionaryDatas=data.enforcerDictionaryDatas;}); + console.log($scope.enforcerDictionaryDatas); + $modalInstance.close({enforcerDictionaryDatas:$scope.enforcerDictionaryDatas}); + }, + error : function(data){ + alert("Error while saving."); + } + }); + }; + + $scope.close = function() { + $modalInstance.close(); + }; +} \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/FWActionListDictController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/FWActionListDictController.js new file mode 100644 index 000000000..14432e9b9 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/FWActionListDictController.js @@ -0,0 +1,75 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +var editFWActionListController = function ($scope, $modalInstance, message, PapUrlService, UserInfoService, Notification){ + if(message.actionListDictionaryData==null) + $scope.label='Add Action Name' + else{ + $scope.label='Edit Action Name' + $scope.disableCd=true; + } + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + }); + + /*getting user info from session*/ + var loginId = null; + UserInfoService.getFunctionalMenuStaticDetailSession() + .then(function (response) { + loginId = response.userid; + }); + + $scope.editActionList = message.actionListDictionaryData; + + $scope.saveFWActionList = function(actionListDictionaryData) { + var uuu = papUrl + "/ecomp/fw_dictionary/save_ActionList.htm"; + var postData={actionListDictionaryData: actionListDictionaryData, loginId: loginId}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){ + $scope.actionListDictionaryDatas=data.actionListDictionaryDatas;}); + if($scope.actionListDictionaryDatas == "Duplicate"){ + Notification.error("FW ActionList Dictionary exists with Same ActionList Name.") + }else{ + console.log($scope.actionListDictionaryDatas); + $modalInstance.close({actionListDictionaryDatas:$scope.actionListDictionaryDatas}); + } + }, + error : function(data){ + alert("Error while saving."); + } + }); + }; + + $scope.close = function() { + $modalInstance.close(); + }; +} \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/FWAddressGroupDictController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/FWAddressGroupDictController.js new file mode 100644 index 000000000..57d9ae95d --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/FWAddressGroupDictController.js @@ -0,0 +1,120 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +var editFWAddressGroupController = function ($scope, $modalInstance, message, FWDictionaryService, PapUrlService, UserInfoService, Notification){ + if(message.addressGroupDictionaryData==null) + $scope.label='Add Address Group', + $scope.apchoices = []; + else{ + $scope.label='Edit Address Group' + $scope.disableCd=true; + $scope.apchoices = []; + var headers = message.addressGroupDictionaryData.prefixList; + var splitEqual = ','; + if(headers != null){ + if (headers.indexOf(splitEqual) >= 0) { + var splitValue = headers.split(splitEqual); + for(i = 0; i < splitValue.length; i++){ + var key = splitValue[i]; + $scope.apchoices.push({'id':'choice'+i+1, 'option': key}); + } + }else{ + var key = headers; + $scope.apchoices.push({'id':'choice'+1, 'option': key}); + } + } + } + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + + FWDictionaryService.getPrefixListDictionaryDataByName(papUrl).then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.prefixListDictionaryDatas = JSON.parse($scope.data.prefixListDictionaryDatas); + console.log($scope.prefixListDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + + }); + + /*getting user info from session*/ + var loginId = null; + UserInfoService.getFunctionalMenuStaticDetailSession() + .then(function (response) { + loginId = response.userid; + }); + + $scope.editAddressGroup = message.addressGroupDictionaryData; + + $scope.saveFWAddressGroup = function(addressGroupDictionaryData) { + var finalData = extend(addressGroupDictionaryData, $scope.attributeDatas[0]); + var uuu = papUrl + "/ecomp/fw_dictionary/save_addressGroup.htm"; + var postData={addressGroupDictionaryData: finalData, loginId: loginId}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){ + $scope.addressGroupDictionaryDatas=data.addressGroupDictionaryDatas;}); + if($scope.addressGroupDictionaryDatas == "Duplicate"){ + Notification.error("FW AddressGroup Dictionary exists with Same Address group Name.") + }else{ + console.log($scope.addressGroupDictionaryDatas); + $modalInstance.close({addressGroupDictionaryDatas:$scope.addressGroupDictionaryDatas}); + } + }, + error : function(data){ + alert("Error while saving."); + } + }); + }; + + $scope.close = function() { + $modalInstance.close(); + }; + + function extend(obj, src) { + for (var key in src) { + if (src.hasOwnProperty(key)) obj[key] = src[key]; + } + return obj; + } + + $scope.attributeDatas = [{"attributes" : $scope.apchoices}]; + $scope.addAPNewChoice = function() { + var newItemNo = $scope.apchoices.length+1; + $scope.apchoices.push({'id':'choice'+newItemNo}); + }; + $scope.removeAPChoice = function() { + var lastItem = $scope.apchoices.length-1; + $scope.apchoices.splice(lastItem); + }; +} \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/FWParentListDictController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/FWParentListDictController.js new file mode 100644 index 000000000..d73faf5f7 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/FWParentListDictController.js @@ -0,0 +1,156 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +var editFWParentListController = function ($scope, $modalInstance, message, PapUrlService, UserInfoService, FWDictionaryService, Notification){ + if(message.fwDictListDictionaryData==null){ + $scope.slchoices = []; + $scope.alchoices = []; + $scope.label='Add Parent List' + }else{ + $scope.label='Edit Parent List' + $scope.disableCd=true; + $scope.slchoices = []; + $scope.alchoices = []; + var slList = message.fwDictListDictionaryData.serviceList; + var alList = message.fwDictListDictionaryData.addressList; + var splitEqual = ','; + if(slList != null){ + if (slList.indexOf(splitEqual) >= 0) { + var splitValue = slList.split(splitEqual); + for(i = 0; i < splitValue.length; i++){ + var key = splitValue[i]; + $scope.slchoices.push({'id':'choice'+i+1, 'option': key}); + } + }else{ + var key = slList; + $scope.slchoices.push({'id':'choice'+1, 'option': key}); + } + } + if(alList != null){ + if (alList.indexOf(splitEqual) >= 0) { + var splitALValue = alList.split(splitEqual); + for(i = 0; i < splitALValue.length; i++){ + var key = splitALValue[i]; + $scope.alchoices.push({'id':'choice'+i+1, 'option': key}); + } + }else{ + var key = alList; + $scope.alchoices.push({'id':'choice'+1, 'option': key}); + } + } + } + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + + FWDictionaryService.getServiceListDictionaryDataByName(papUrl).then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.serviceListDictionaryDatas = JSON.parse($scope.data.serviceListDictionaryDatas); + console.log($scope.serviceListDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + + FWDictionaryService.getAddressGroupDictionaryDataByName(papUrl).then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.addressGroupDictionaryDatas = JSON.parse($scope.data.addressGroupDictionaryDatas); + console.log($scope.addressGroupDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + }); + + /*getting user info from session*/ + var loginId = null; + UserInfoService.getFunctionalMenuStaticDetailSession() + .then(function (response) { + loginId = response.userid; + }); + + $scope.editParentList = message.fwDictListDictionaryData; + + $scope.saveFWParentList = function(fwDictListDictionaryData) { + var addSLData = extend(fwDictListDictionaryData, $scope.attributeDatas[0]); + var finalData = extend(addSLData, $scope.attributeALDatas[0]); + var uuu = papUrl + "/ecomp/fw_dictionary/save_FWDictionaryList.htm"; + var postData={fwDictListDictionaryData: finalData, loginId: loginId}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){ + $scope.fwDictListDictionaryDatas=data.fwDictListDictionaryDatas;}); + if($scope.fwDictListDictionaryDatas == "Duplicate"){ + Notification.error("FW DictionaryList Dictionary exists with Same Name.") + }else{ + console.log($scope.fwDictListDictionaryDatas); + $modalInstance.close({fwDictListDictionaryDatas:$scope.fwDictListDictionaryDatas}); + } + }, + error : function(data){ + alert("Error while saving."); + } + }); + }; + + $scope.close = function() { + $modalInstance.close(); + }; + + function extend(obj, src) { + for (var key in src) { + if (src.hasOwnProperty(key)) obj[key] = src[key]; + } + return obj; + } + + + $scope.attributeDatas = [{"attributes" : $scope.slchoices}]; + $scope.addServiceGroupNewChoice = function() { + var newItemNo = $scope.slchoices.length+1; + $scope.slchoices.push({'id':'choice'+newItemNo}); + }; + $scope.removeServiceGroupChoice = function() { + var lastItem = $scope.slchoices.length-1; + $scope.slchoices.splice(lastItem); + }; + + $scope.attributeALDatas = [{"alAttributes" : $scope.alchoices}]; + $scope.addAddressGroupNewChoice = function() { + var newItemNo = $scope.alchoices.length+1; + $scope.alchoices.push({'id':'choice'+newItemNo}); + }; + $scope.removeAddressGroupChoice = function() { + var lastItem = $scope.alchoices.length-1; + $scope.alchoices.splice(lastItem); + }; +} \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/FWPortListDictController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/FWPortListDictController.js new file mode 100644 index 000000000..a2fbfe6d2 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/FWPortListDictController.js @@ -0,0 +1,75 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +var editFWPortListController = function ($scope, $modalInstance, message, PapUrlService, UserInfoService, Notification){ + if(message.portListDictionaryData==null) + $scope.label='Add Port Name' + else{ + $scope.label='Edit Port Name' + $scope.disableCd=true; + } + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + }); + + /*getting user info from session*/ + var loginId = null; + UserInfoService.getFunctionalMenuStaticDetailSession() + .then(function (response) { + loginId = response.userid; + }); + + $scope.editPortList = message.portListDictionaryData; + + $scope.saveFWPortList = function(portListDictionaryData) { + var uuu = papUrl + "/ecomp/fw_dictionary/save_portName.htm"; + var postData={portListDictionaryData: portListDictionaryData, loginId: loginId}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){ + $scope.portListDictionaryDatas=data.portListDictionaryDatas;}); + if($scope.portListDictionaryDatas == "Duplicate"){ + Notification.error("FW PortList Dictionary exists with Same Port Name.") + }else{ + console.log($scope.portListDictionaryDatas); + $modalInstance.close({portListDictionaryDatas:$scope.portListDictionaryDatas}); + } + }, + error : function(data){ + alert("Error while saving."); + } + }); + }; + + $scope.close = function() { + $modalInstance.close(); + }; +} \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/FWPrefixListDictController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/FWPrefixListDictController.js new file mode 100644 index 000000000..f4e66e09c --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/FWPrefixListDictController.js @@ -0,0 +1,103 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +var editFWPrefixListController = function ($scope, $modalInstance, message, Notification, PapUrlService, UserInfoService, Notification){ + $scope.validate = 'false'; + if(message.prefixListDictionaryData==null) + $scope.label='Add PrefixList' + else{ + $scope.label='Edit PrefixList' + $scope.disableCd=true; + } + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + }); + + /*getting user info from session*/ + var loginId = null; + UserInfoService.getFunctionalMenuStaticDetailSession() + .then(function (response) { + loginId = response.userid; + }); + + $scope.editPrefixList = message.prefixListDictionaryData; + + $scope.saveFWPrefixList = function(prefixListDictionaryData) { + if($scope.validate == 'true'){ + var uuu = papUrl + "/ecomp/fw_dictionary/save_prefixList.htm"; + var postData={prefixListDictionaryData: prefixListDictionaryData, loginId: loginId}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){ + $scope.prefixListDictionaryDatas=data.prefixListDictionaryDatas;}); + if($scope.prefixListDictionaryDatas == "Duplicate"){ + Notification.error("FW PrefixList Dictionary exists with Same PrefixList Name.") + }else{ + console.log($scope.prefixListDictionaryDatas); + $modalInstance.close({prefixListDictionaryDatas:$scope.prefixListDictionaryDatas}); + } + }, + error : function(data){ + alert("Error while saving."); + } + }); + }else{ + Notification.error('Prefix List Validation is Not Successful'); + } + + }; + + $scope.validateFWPrefixList = function(prefixListDictionaryData) { + var uuu = papUrl + "/ecomp/fw_dictionary/validate_prefixList.htm"; + var postData={prefixListDictionaryData: prefixListDictionaryData}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){ + $scope.result=data.result;}); + console.log($scope.result); + if($scope.result == 'error'){ + Notification.error('IP not according to CIDR notation'); + }else{ + $scope.validate = 'true'; + } + } + }); + }; + + $scope.close = function() { + $modalInstance.close(); + }; +} \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/FWProtocolListDictController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/FWProtocolListDictController.js new file mode 100644 index 000000000..4de12b8fe --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/FWProtocolListDictController.js @@ -0,0 +1,75 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +var editFWProtocolListController = function ($scope, $modalInstance, message, PapUrlService, UserInfoService, Notification){ + if(message.protocolListDictionaryData==null) + $scope.label='Add Protocol Name' + else{ + $scope.label='Edit Protocol Name' + $scope.disableCd=true; + } + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + }); + + /*getting user info from session*/ + var loginId = null; + UserInfoService.getFunctionalMenuStaticDetailSession() + .then(function (response) { + loginId = response.userid; + }); + + $scope.editProtocolList = message.protocolListDictionaryData; + + $scope.saveProtocolList = function(protocolListDictionaryData) { + var uuu = papUrl + "/ecomp/fw_dictionary/save_protocolList.htm"; + var postData={protocolListDictionaryData: protocolListDictionaryData, loginId: loginId}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){ + $scope.protocolListDictionaryDatas=data.protocolListDictionaryDatas;}); + if($scope.protocolListDictionaryDatas == "Duplicate"){ + Notification.error("FW ProtocolList Dictionary exists with Same Protocol Name.") + }else{ + console.log($scope.protocolListDictionaryDatas); + $modalInstance.close({protocolListDictionaryDatas:$scope.protocolListDictionaryDatas}); + } + }, + error : function(data){ + alert("Error while saving."); + } + }); + }; + + $scope.close = function() { + $modalInstance.close(); + }; +} \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/FWSecurityZoneDictController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/FWSecurityZoneDictController.js new file mode 100644 index 000000000..cd43a41b8 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/FWSecurityZoneDictController.js @@ -0,0 +1,75 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +var editfwSecurityZoneController = function ($scope, $modalInstance, message, PapUrlService, UserInfoService, Notification){ + if(message.securityZoneDictionaryData==null) + $scope.label='Add Security Zone' + else{ + $scope.label='Edit Security Zone' + $scope.disableCd=true; + } + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + }); + + /*getting user info from session*/ + var loginId = null; + UserInfoService.getFunctionalMenuStaticDetailSession() + .then(function (response) { + loginId = response.userid; + }); + + $scope.editSecurityZone = message.securityZoneDictionaryData; + + $scope.saveSecurityZone = function(securityZoneDictionaryData) { + var uuu = papUrl + "/ecomp/fw_dictionary/save_securityZone.htm"; + var postData={securityZoneDictionaryData: securityZoneDictionaryData, loginId: loginId}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){ + $scope.securityZoneDictionaryDatas=data.securityZoneDictionaryDatas;}); + if($scope.securityZoneDictionaryDatas == "Duplicate"){ + Notification.error("FW SecurityZone Dictionary exists with Same Zone Name.") + }else{ + console.log($scope.securityZoneDictionaryDatas); + $modalInstance.close({securityZoneDictionaryDatas:$scope.securityZoneDictionaryDatas}); + } + }, + error : function(data){ + alert("Error while saving."); + } + }); + }; + + $scope.close = function() { + $modalInstance.close(); + }; +} \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/FWServiceGroupDictController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/FWServiceGroupDictController.js new file mode 100644 index 000000000..3cf6d9be7 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/FWServiceGroupDictController.js @@ -0,0 +1,121 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +var editFWServiceGroupController = function ($scope, $modalInstance, message, PapUrlService, UserInfoService, FWDictionaryService, Notification){ + if(message.serviceGroupDictionaryData==null){ + $scope.slchoices = []; + $scope.label='Add Service Group' + }else{ + $scope.label='Edit Service Group' + $scope.disableCd=true; + $scope.slchoices = []; + var headers = message.serviceGroupDictionaryData.serviceList; + var splitEqual = ','; + if(headers != null){ + if (headers.indexOf(splitEqual) >= 0) { + var splitValue = headers.split(splitEqual); + for(i = 0; i < splitValue.length; i++){ + var key = splitValue[i]; + $scope.slchoices.push({'id':'choice'+i+1, 'option': key}); + } + }else{ + var key = headers; + $scope.slchoices.push({'id':'choice'+1, 'option': key}); + } + } + } + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + + FWDictionaryService.getServiceListDictionaryDataByName(papUrl).then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.serviceListDictionaryDatas = JSON.parse($scope.data.serviceListDictionaryDatas); + console.log($scope.serviceListDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + }); + + /*getting user info from session*/ + var loginId = null; + UserInfoService.getFunctionalMenuStaticDetailSession() + .then(function (response) { + loginId = response.userid; + }); + + $scope.editServiceGroup = message.serviceGroupDictionaryData; + + $scope.saveFWServiceGroup = function(serviceGroupDictionaryData) { + var finalData = extend(serviceGroupDictionaryData, $scope.attributeDatas[0]); + var uuu = papUrl + "/ecomp/fw_dictionary/save_serviceGroup.htm"; + var postData={serviceGroupDictionaryData: finalData, loginId: loginId}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){ + $scope.serviceGroupDictionaryDatas=data.serviceGroupDictionaryDatas;}); + if($scope.serviceGroupDictionaryDatas == "Duplicate"){ + Notification.error("FW Service Group Dictionary exists with Same Group Name.") + }else{ + console.log($scope.serviceGroupDictionaryDatas); + $modalInstance.close({serviceGroupDictionaryDatas:$scope.serviceGroupDictionaryDatas}); + } + }, + error : function(data){ + alert("Error while saving."); + } + }); + }; + + $scope.close = function() { + $modalInstance.close(); + }; + + function extend(obj, src) { + for (var key in src) { + if (src.hasOwnProperty(key)) obj[key] = src[key]; + } + return obj; + } + + + + $scope.attributeDatas = [{"attributes" : $scope.slchoices}]; + $scope.addServiceGroupNewChoice = function() { + var newItemNo = $scope.slchoices.length+1; + $scope.slchoices.push({'id':'choice'+newItemNo}); + }; + $scope.removeServiceGroupChoice = function() { + var lastItem = $scope.slchoices.length-1; + $scope.slchoices.splice(lastItem); + }; +} \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/FWServiceListDictController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/FWServiceListDictController.js new file mode 100644 index 000000000..73da6c486 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/FWServiceListDictController.js @@ -0,0 +1,147 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +var editFWServiceListController = function ($scope, $modalInstance, message, FWDictionaryService, PapUrlService, UserInfoService, Notification){ + $scope.protocolListDictionaryDatas =[]; + + $scope.tpchoices = []; + $scope.apchoices = []; + if(message.serviceListDictionaryData==null){ + $scope.label='Add Service List' + }else{ + $scope.label='Edit Service List' + $scope.disableCd=true; + var tcpheaders = message.serviceListDictionaryData.serviceTransProtocol; + var splitEqual = ','; + if(tcpheaders != null){ + if (tcpheaders.indexOf(splitEqual) >= 0) { + var splitValue = tcpheaders.split(splitEqual); + for(i = 0; i < splitValue.length; i++){ + var key = splitValue[i]; + $scope.tpchoices.push({'id':'choice'+i+1, 'option': key}); + } + }else{ + var key = tcpheaders; + $scope.tpchoices.push({'id':'choice'+1, 'option': key}); + } + } + var appheaders = message.serviceListDictionaryData.serviceAppProtocol; + var splitEqual1 = ','; + if(appheaders != null){ + if (appheaders.indexOf(splitEqual1) >= 0) { + var splitValue1 = appheaders.split(splitEqual1); + for(i = 0; i < splitValue1.length; i++){ + var key1 = splitValue1[i]; + $scope.apchoices.push({'id':'choice'+i+1, 'option': key1}); + } + }else{ + var key1 = appheaders; + $scope.apchoices.push({'id':'choice'+1, 'option': key1}); + } + } + } + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + + FWDictionaryService.getProtocolListDictionaryDataByName(papUrl).then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.protocolListDictionaryDatas = JSON.parse($scope.data.protocolListDictionaryDatas); + console.log($scope.protocolListDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + }); + + /*getting user info from session*/ + var loginId = null; + UserInfoService.getFunctionalMenuStaticDetailSession() + .then(function (response) { + loginId = response.userid; + }); + + $scope.editServiceList = message.serviceListDictionaryData; + + $scope.saveFWServiceList = function(serviceListDictionaryData) { + var addtcpData = extend(serviceListDictionaryData, $scope.attributeTCPDatas[0]); + var finalData = extend(addtcpData, $scope.attributeAPPDatas[0]); + var uuu = papUrl + "/ecomp/fw_dictionary/save_serviceList.htm"; + var postData={serviceListDictionaryData: finalData, loginId: loginId}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){ + $scope.serviceListDictionaryDatas=data.serviceListDictionaryDatas;}); + if($scope.serviceListDictionaryDatas == "Duplicate"){ + Notification.error("FW ServiceList Dictionary exists with Same ServiceList Name.") + }else{ + console.log($scope.serviceListDictionaryDatas); + $modalInstance.close({serviceListDictionaryDatas:$scope.serviceListDictionaryDatas}); + } + }, + error : function(data){ + alert("Error while saving."); + } + }); + }; + + $scope.close = function() { + $modalInstance.close(); + }; + + function extend(obj, src) { + for (var key in src) { + if (src.hasOwnProperty(key)) obj[key] = src[key]; + } + return obj; + } + + $scope.attributeTCPDatas = [{"transportProtocols" : $scope.tpchoices}]; + $scope.addTPNewChoice = function() { + var newItemNo = $scope.tpchoices.length+1; + $scope.tpchoices.push({'id':'choice'+newItemNo}); + }; + $scope.removeTPChoice = function() { + var lastItem = $scope.tpchoices.length-1; + $scope.tpchoices.splice(lastItem); + }; + + + $scope.attributeAPPDatas = [{"appProtocols" : $scope.apchoices}]; + $scope.addAPNewChoice = function() { + var newItemNo = $scope.apchoices.length+1; + $scope.apchoices.push({'id':'choice'+newItemNo}); + }; + $scope.removeAPChoice = function() { + var lastItem = $scope.apchoices.length-1; + $scope.apchoices.splice(lastItem); + }; +} \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/FWTermListDictController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/FWTermListDictController.js new file mode 100644 index 000000000..8615082a2 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/FWTermListDictController.js @@ -0,0 +1,331 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +var editFWTermListController = function ($scope, $modalInstance, message, FWDictionaryService, PapUrlService, UserInfoService, Notification){ + $scope.fromZonechoices = []; + $scope.toZonechoices = []; + $scope.sourceListchoices = []; + $scope.destinationListchoices = []; + $scope.sourceServicechoices = []; + $scope.destinationServicechoices = []; + $scope.actionListchoices = []; + if(message.termListDictionaryData==null){ + $scope.label='Add Term List Name' + }else{ + $scope.label='Edit Term List Name' + $scope.disableCd=true; + var fromZoneheaders = message.termListDictionaryData.fromZone; + var splitFromZone = ','; + if(fromZoneheaders != null){ + if (fromZoneheaders.indexOf(splitFromZone) >= 0) { + var splitFromZoneValue = fromZoneheaders.split(splitFromZone); + for(i = 0; i < splitFromZoneValue.length; i++){ + var key = splitFromZoneValue[i]; + $scope.fromZonechoices.push({'id':'choice'+i+1, 'option': key}); + } + }else{ + var key = fromZoneheaders; + $scope.fromZonechoices.push({'id':'choice'+1, 'option': key}); + } + } + + var toZoneheaders = message.termListDictionaryData.toZone; + var splitToZone = ','; + if(toZoneheaders != null){ + if (toZoneheaders.indexOf(splitToZone) >= 0) { + var splitToZoneValue = toZoneheaders.split(splitToZone); + for(i = 0; i < splitToZoneValue.length; i++){ + var key = splitToZoneValue[i]; + $scope.toZonechoices.push({'id':'choice'+i+1, 'option': key}); + } + }else{ + var key = toZoneheaders; + $scope.toZonechoices.push({'id':'choice'+1, 'option': key}); + } + } + + var srcIPheaders = message.termListDictionaryData.srcIPList; + var splitSrcIP = ','; + if(srcIPheaders != null){ + if (srcIPheaders.indexOf(splitSrcIP) >= 0) { + var splitSrcIPValue = srcIPheaders.split(splitSrcIP); + for(i = 0; i < splitSrcIPValue.length; i++){ + var key = splitSrcIPValue[i]; + $scope.sourceListchoices.push({'id':'choice'+i+1, 'option': key}); + } + }else{ + var key = srcIPheaders; + $scope.sourceListchoices.push({'id':'choice'+1, 'option': key}); + } + } + + var desIPheaders = message.termListDictionaryData.destIPList; + var splitDesIP = ','; + if(desIPheaders != null){ + if (desIPheaders.indexOf(splitDesIP) >= 0) { + var splitDestIPValue = desIPheaders.split(splitDesIP); + for(i = 0; i < splitDestIPValue.length; i++){ + var key = splitDestIPValue[i]; + $scope.destinationListchoices.push({'id':'choice'+i+1, 'option': key}); + } + }else{ + var key = desIPheaders; + $scope.destinationListchoices.push({'id':'choice'+1, 'option': key}); + } + } + + var srcServheaders = message.termListDictionaryData.srcPortList; + var splitSrcServ = ','; + if(srcServheaders != null){ + if (srcServheaders.indexOf(splitSrcServ) >= 0) { + var splitSrcServValue = srcServheaders.split(splitSrcServ); + for(i = 0; i < splitSrcServValue.length; i++){ + var key = splitSrcServValue[i]; + $scope.sourceServicechoices.push({'id':'choice'+i+1, 'option': key}); + } + }else{ + var key = srcServheaders; + $scope.sourceServicechoices.push({'id':'choice'+1, 'option': key}); + } + } + + var desServheaders = message.termListDictionaryData.destPortList; + var splitdesSer = ','; + if(desServheaders != null){ + if (desServheaders.indexOf(splitdesSer) >= 0) { + var splitDesSerValue = desServheaders.split(splitdesSer); + for(i = 0; i < splitDesSerValue.length; i++){ + var key = splitDesSerValue[i]; + $scope.destinationServicechoices.push({'id':'choice'+i+1, 'option': key}); + } + }else{ + var key = desServheaders; + $scope.destinationServicechoices.push({'id':'choice'+1, 'option': key}); + } + } + + var actionheaders = message.termListDictionaryData.action; + var splitAction = ','; + if(actionheaders != null){ + if (actionheaders.indexOf(splitAction) >= 0) { + var splitActionValue = actionheaders.split(splitAction); + for(i = 0; i < splitActionValue.length; i++){ + var key = splitActionValue[i]; + $scope.actionListchoices.push({'id':'choice'+i+1, 'option': key}); + } + }else{ + var key = actionheaders; + $scope.actionListchoices.push({'id':'choice'+1, 'option': key}); + } + } + } + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + + FWDictionaryService.getPrefixListDictionaryDataByName(papUrl).then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.prefixListDictionaryDatas = JSON.parse($scope.data.prefixListDictionaryDatas); + console.log($scope.prefixListDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + + FWDictionaryService.getZoneDictionaryDataByName(papUrl).then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.zoneDictionaryDatas = JSON.parse($scope.data.zoneDictionaryDatas); + console.log($scope.zoneDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + + FWDictionaryService.getAddressGroupDictionaryDataByName(papUrl).then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.addressGroupDictionaryDatas = JSON.parse($scope.data.addressGroupDictionaryDatas); + console.log($scope.addressGroupDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + + FWDictionaryService.getServiceListDictionaryDataByName(papUrl).then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.serviceListDictionaryDatas = JSON.parse($scope.data.serviceListDictionaryDatas); + console.log($scope.serviceListDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + + FWDictionaryService.getServiceGroupDictionaryDataByName(papUrl).then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.serviceGroupDictionaryDatas = JSON.parse($scope.data.serviceGroupDictionaryDatas); + console.log($scope.serviceGroupDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + + FWDictionaryService.getActionListDictionaryDataByName(papUrl).then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.actionListDictionaryDatas = JSON.parse($scope.data.actionListDictionaryDatas); + console.log($scope.actionListDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + }); + + /*getting user info from session*/ + var loginId = null; + UserInfoService.getFunctionalMenuStaticDetailSession() + .then(function (response) { + loginId = response.userid; + }); + + $scope.editTermList = message.termListDictionaryData; + + $scope.saveTermName = function(termListDictionaryData) { + var mergeFromZoneData = extend(termListDictionaryData, $scope.fromZoneDatas[0]); + var mergeToData = extend(mergeFromZoneData, $scope.toZoneDatas[0]); + var mergeSourceListData = extend(mergeToData, $scope.sourceListDatas[0]); + var mergeDListData = extend(mergeSourceListData, $scope.destinationListDatas[0]); + var mergeSServicesData = extend(mergeDListData, $scope.sourceServicesDatas[0]); + var mergeDServicesData = extend(mergeSServicesData, $scope.destinationServicesDatas[0]); + var finalData = extend(mergeDServicesData, $scope.actionListDatas[0]); + var uuu = papUrl + "/ecomp/fw_dictionary/save_termList.htm"; + var postData={termListDictionaryData: finalData, loginId: loginId}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){ + $scope.termListDictionaryDatas=data.termListDictionaryDatas;}); + if($scope.termListDictionaryDatas == "Duplicate"){ + Notification.error("FW TermList Dictionary exists with Same Term Name.") + }else{ + console.log($scope.termListDictionaryDatas); + $modalInstance.close({termListDictionaryDatas:$scope.termListDictionaryDatas}); + } + }, + error : function(data){ + alert("Error while saving."); + } + }); + }; + + $scope.close = function() { + $modalInstance.close(); + }; + + + function extend(obj, src) { + for (var key in src) { + if (src.hasOwnProperty(key)) obj[key] = src[key]; + } + return obj; + } + + $scope.fromZoneDatas = [{"fromZoneDatas" : $scope.fromZonechoices}]; + $scope.addFromZoneNewChoice = function() { + var newItemNo = $scope.fromZonechoices.length+1; + $scope.fromZonechoices.push({'id':'choice'+newItemNo}); + }; + $scope.removeFromZoneChoice = function() { + var lastItem = $scope.fromZonechoices.length-1; + $scope.fromZonechoices.splice(lastItem); + }; + + $scope.toZoneDatas = [{"toZoneDatas" : $scope.toZonechoices}]; + $scope.addToZoneNewChoice = function() { + var newItemNo = $scope.toZonechoices.length+1; + $scope.toZonechoices.push({'id':'choice'+newItemNo}); + }; + $scope.removeToZoneChoice = function() { + var lastItem = $scope.toZonechoices.length-1; + $scope.toZonechoices.splice(lastItem); + }; + + $scope.sourceListDatas = [{"sourceListDatas" : $scope.sourceListchoices}]; + $scope.addSourceListNewChoice = function() { + var newItemNo = $scope.sourceListchoices.length+1; + $scope.sourceListchoices.push({'id':'choice'+newItemNo}); + }; + $scope.removeSourceListChoice = function() { + var lastItem = $scope.sourceListchoices.length-1; + $scope.sourceListchoices.splice(lastItem); + }; + + $scope.destinationListDatas = [{"destinationListDatas" : $scope.destinationListchoices}]; + $scope.addDListNewChoice = function() { + var newItemNo = $scope.destinationListchoices.length+1; + $scope.destinationListchoices.push({'id':'choice'+newItemNo}); + }; + $scope.removeDlistChoice = function() { + var lastItem = $scope.destinationListchoices.length-1; + $scope.destinationListchoices.splice(lastItem); + }; + + $scope.sourceServicesDatas = [{"sourceServiceDatas" : $scope.sourceServicechoices}]; + $scope.addSourceServiceNewChoice = function() { + var newItemNo = $scope.sourceServicechoices.length+1; + $scope.sourceServicechoices.push({'id':'choice'+newItemNo}); + }; + $scope.removeSourceServiceChoice = function() { + var lastItem = $scope.sourceServicechoices.length-1; + $scope.sourceServicechoices.splice(lastItem); + }; + + $scope.destinationServicesDatas = [{"destinationServiceDatas" : $scope.destinationServicechoices}]; + $scope.addDServicesNewChoice = function() { + var newItemNo = $scope.destinationServicechoices.length+1; + $scope.destinationServicechoices.push({'id':'choice'+newItemNo}); + }; + $scope.removeDServicesChoice = function() { + var lastItem = $scope.destinationServicechoices.length-1; + $scope.destinationServicechoices.splice(lastItem); + }; + + $scope.actionListDatas = [{"actionListDatas" : $scope.actionListchoices}]; + $scope.addActionListNewChoice = function() { + var newItemNo = $scope.actionListchoices.length+1; + $scope.actionListchoices.push({'id':'choice'+newItemNo}); + }; + $scope.removeActionListChoice = function() { + var lastItem = $scope.actionListchoices.length-1; + $scope.actionListchoices.splice(lastItem); + }; +} \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/FWZoneDictController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/FWZoneDictController.js new file mode 100644 index 000000000..8780ddd35 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/FWZoneDictController.js @@ -0,0 +1,75 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +var editFWZoneController = function ($scope, $modalInstance, message, PapUrlService, UserInfoService, Notification){ + if(message.zoneDictionaryData==null) + $scope.label='Add Zone Name' + else{ + $scope.label='Edit Zone Name' + $scope.disableCd=true; + } + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + }); + + /*getting user info from session*/ + var loginId = null; + UserInfoService.getFunctionalMenuStaticDetailSession() + .then(function (response) { + loginId = response.userid; + }); + + $scope.editZoneName = message.zoneDictionaryData; + + $scope.saveZoneName = function(zoneDictionaryData) { + var uuu = papUrl + "/ecomp/fw_dictionary/save_zoneName.htm"; + var postData={zoneDictionaryData: zoneDictionaryData, loginId: loginId}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){ + $scope.zoneDictionaryDatas=data.zoneDictionaryDatas;}); + if($scope.zoneDictionaryDatas == "Duplicate"){ + Notification.error("FW Zone Dictionary exists with Same Zone Name.") + }else{ + console.log($scope.zoneDictionaryDatas); + $modalInstance.close({zoneDictionaryDatas:$scope.zoneDictionaryDatas}); + } + }, + error : function(data){ + alert("Error while saving."); + } + }); + }; + + $scope.close = function() { + $modalInstance.close(); + }; +} \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/MSConfigNameDictController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/MSConfigNameDictController.js new file mode 100644 index 000000000..d96a62ad8 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/MSConfigNameDictController.js @@ -0,0 +1,76 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +var editMSConfigController = function ($scope, $modalInstance, message, PapUrlService, UserInfoService, Notification){ + if(message.microServiceCongigNameDictionaryData==null) + $scope.label='Add Config Name' + else{ + $scope.label='Edit Config Name' + $scope.disableCd=true; + } + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + + }); + + /*getting user info from session*/ + var loginId = null; + UserInfoService.getFunctionalMenuStaticDetailSession() + .then(function (response) { + loginId = response.userid; + }); + + $scope.editMSConfig = message.microServiceCongigNameDictionaryData; + + $scope.saveMSConfig = function(microServiceCongigNameDictionaryData) { + var uuu = papUrl + "/ecomp/ms_dictionary/save_configName.htm"; + var postData={microServiceCongigNameDictionaryData: microServiceCongigNameDictionaryData, loginId: loginId}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){ + $scope.microServiceCongigNameDictionaryDatas=data.microServiceCongigNameDictionaryDatas;}); + if($scope.microServiceCongigNameDictionaryDatas == "Duplicate"){ + Notification.error("MS ConfigName Dictionary exists with Same Config Name.") + }else{ + console.log($scope.microServiceCongigNameDictionaryDatas); + $modalInstance.close({microServiceCongigNameDictionaryDatas:$scope.microServiceCongigNameDictionaryDatas}); + } + }, + error : function(data){ + alert("Error while saving."); + } + }); + }; + + $scope.close = function() { + $modalInstance.close(); + }; +} \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/MSDcaeUUIDDictController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/MSDcaeUUIDDictController.js new file mode 100644 index 000000000..c08dbbe22 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/MSDcaeUUIDDictController.js @@ -0,0 +1,76 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +var editDCAEuuidController = function ($scope, $modalInstance, message, PapUrlService, UserInfoService, Notification){ + if(message.dcaeUUIDDictionaryData==null) + $scope.label='Add Micro Service UUID' + else{ + $scope.label='Edit Micro Service UUID' + $scope.disableCd=true; + } + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + + }); + + /*getting user info from session*/ + var loginId = null; + UserInfoService.getFunctionalMenuStaticDetailSession() + .then(function (response) { + loginId = response.userid; + }); + + $scope.editDCAEuuid = message.dcaeUUIDDictionaryData; + + $scope.saveDCAEUUID = function(dcaeUUIDDictionaryData) { + var uuu = papUrl + "/ecomp/ms_dictionary/save_dcaeUUID.htm"; + var postData={dcaeUUIDDictionaryData: dcaeUUIDDictionaryData, loginId: loginId}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){ + $scope.dcaeUUIDDictionaryDatas=data.dcaeUUIDDictionaryDatas;}); + if($scope.dcaeUUIDDictionaryDatas == "Duplicate"){ + Notification.error("MS DCAEUUID Dictionary exists with Same DCAEUUID Name.") + }else{ + console.log($scope.dcaeUUIDDictionaryDatas); + $modalInstance.close({dcaeUUIDDictionaryDatas:$scope.dcaeUUIDDictionaryDatas}); + } + }, + error : function(data){ + alert("Error while saving."); + } + }); + }; + + $scope.close = function() { + $modalInstance.close(); + }; +} \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/MSLocationDictController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/MSLocationDictController.js new file mode 100644 index 000000000..001f635a9 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/MSLocationDictController.js @@ -0,0 +1,76 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +var editMSLocationController = function ($scope, $modalInstance, message, PapUrlService, UserInfoService, Notification){ + if(message.microServiceLocationDictionaryData==null) + $scope.label='Add Micro Service Location' + else{ + $scope.label='Edit Micro Service Location' + $scope.disableCd=true; + } + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + + }); + + /*getting user info from session*/ + var loginId = null; + UserInfoService.getFunctionalMenuStaticDetailSession() + .then(function (response) { + loginId = response.userid; + }); + + $scope.editMSLocation = message.microServiceLocationDictionaryData; + + $scope.saveMSLocation = function(microServiceLocationDictionaryData) { + var uuu = papUrl + "/ecomp/ms_dictionary/save_location.htm"; + var postData={microServiceLocationDictionaryData: microServiceLocationDictionaryData, loginId: loginId}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){ + $scope.microServiceLocationDictionaryDatas=data.microServiceLocationDictionaryDatas;}); + if($scope.microServiceLocationDictionaryDatas == "Duplicate"){ + Notification.error("MS Location Dictionary exists with Same Location Name.") + }else{ + console.log($scope.microServiceLocationDictionaryDatas); + $modalInstance.close({microServiceLocationDictionaryDatas:$scope.microServiceLocationDictionaryDatas}); + } + }, + error : function(data){ + alert("Error while saving."); + } + }); + }; + + $scope.close = function() { + $modalInstance.close(); + }; +} \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/MSModelsDictController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/MSModelsDictController.js new file mode 100644 index 000000000..101f2c1c9 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/MSModelsDictController.js @@ -0,0 +1,87 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +var editMSModelController = function ($scope, $modalInstance, message, $http, PapUrlService, UserInfoService, Notification){ + if(message.microServiceModelsDictionaryData==null) + $scope.label='Add Micro Service Model' + else{ + $scope.label='Edit Micro Service Model' + $scope.disableCd=true; + } + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + + }); + + /*getting user info from session*/ + var loginId = null; + UserInfoService.getFunctionalMenuStaticDetailSession() + .then(function (response) { + loginId = response.userid; + }); + + $scope.editMSmodelName = message.microServiceModelsDictionaryData; + + $scope.uploadFile = function(files) { + var fd = new FormData(); + fd.append("file", files[0]); + $http.post(papUrl + "/ecomp/ms_dictionary/set_MSModelData.htm", fd, { + withCredentials: false, + headers: {'Content-Type': undefined }, + transformRequest: angular.identity + }).success().error( ); + + }; + + $scope.saveMSModel = function(microServiceModelsDictionaryData) { + var uuu = papUrl + "/ecomp/ms_dictionary/save_model.htm"; + var postData={microServiceModelsDictionaryData: microServiceModelsDictionaryData, loginId: loginId}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){ + $scope.microServiceModelsDictionaryDatas=data.microServiceModelsDictionaryDatas;}); + if($scope.microServiceModelsDictionaryDatas == "Duplicate"){ + Notification.error("MS Models Dictionary exists with Same Model Name.") + }else{ + console.log($scope.microServiceModelsDictionaryDatas); + $modalInstance.close({microServiceModelsDictionaryDatas:$scope.microServiceModelsDictionaryDatas}); + } + }, + error : function(data){ + alert("Error while saving."); + } + }); + }; + + $scope.close = function() { + $modalInstance.close(); + }; +} \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/PSClosedLoopDictController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/PSClosedLoopDictController.js new file mode 100644 index 000000000..6986209cd --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/PSClosedLoopDictController.js @@ -0,0 +1,75 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +var editPSClosedLoopController = function ($scope, $modalInstance, message, PapUrlService, UserInfoService, Notification){ + if(message.psClosedLoopDictionaryData==null) + $scope.label='Add New Policy Scope ClosedLoop' + else{ + $scope.label='Edit Policy Scope ClosedLoop' + $scope.disableCd=true; + } + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + }); + + /*getting user info from session*/ + var loginId = null; + UserInfoService.getFunctionalMenuStaticDetailSession() + .then(function (response) { + loginId = response.userid; + }); + + $scope.editPSClosedLoop = message.psClosedLoopDictionaryData; + + $scope.savePSClosedLoop = function(psClosedLoopDictionaryData) { + var uuu = papUrl + "/ecomp/ps_dictionary/save_psClosedLoop.htm"; + var postData={psClosedLoopDictionaryData: psClosedLoopDictionaryData, loginId: loginId}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){ + $scope.psClosedLoopDictionaryDatas=data.psClosedLoopDictionaryDatas;}); + if($scope.psClosedLoopDictionaryDatas == "Duplicate"){ + Notification.error("ClosedLoop Dictionary exists with Same ClosedLoop Name.") + }else{ + console.log($scope.psClosedLoopDictionaryDatas); + $modalInstance.close({psClosedLoopDictionaryDatas:$scope.psClosedLoopDictionaryDatas}); + } + }, + error : function(data){ + alert("Error while saving."); + } + }); + }; + + $scope.close = function() { + $modalInstance.close(); + }; +} \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/PSGroupPolicyScopeDictController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/PSGroupPolicyScopeDictController.js new file mode 100644 index 000000000..ec1c575df --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/PSGroupPolicyScopeDictController.js @@ -0,0 +1,137 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +var editPSGroupPolicyScopeController = function ($scope, $modalInstance, message, PolicyScopeService, PapUrlService, UserInfoService, Notification){ + $scope.edit = false; + if(message.groupPolicyScopeListData==null) + $scope.label='Add New Group Policy Scope' + else{ + $scope.label='Edit Group Policy Scope' + $scope.disableCd=true; + $scope.edit = true; + } + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + + PolicyScopeService.getPSServiceDictionaryDataByName(papUrl).then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.psServiceDictionaryDatas = JSON.parse($scope.data.psServiceDictionaryDatas); + console.log($scope.psServiceDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + + PolicyScopeService.getPSTypeDictionaryDataByName(papUrl).then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.psTypeDictionaryDatas = JSON.parse($scope.data.psTypeDictionaryDatas); + console.log($scope.psTypeDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + + PolicyScopeService.getPSResourceDictionaryDataByName(papUrl).then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.psResourceDictionaryDatas = JSON.parse($scope.data.psResourceDictionaryDatas); + console.log($scope.psResourceDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + + PolicyScopeService.getPSClosedLoopDictionaryDataByName(papUrl).then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.psClosedLoopDictionaryDatas = JSON.parse($scope.data.psClosedLoopDictionaryDatas); + console.log($scope.psClosedLoopDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + }); + + /*getting user info from session*/ + var loginId = null; + UserInfoService.getFunctionalMenuStaticDetailSession() + .then(function (response) { + loginId = response.userid; + }); + + $scope.editPSGroupPolicyScope = message.groupPolicyScopeListData; + $scope.editPSGroupPolicyScope1 = {resource: [], type:[], service: [], closedloop: []}; + if($scope.edit){ + if(message.groupPolicyScopeListData.groupList != null){ + var splitValue = message.groupPolicyScopeListData.groupList.split(","); + console.log(splitValue); + $scope.splittedGroupListValues = []; + var splitResource = splitValue[0].split("="); + $scope.editPSGroupPolicyScope1.resource.push(splitResource[1]); + var splitType = splitValue[1].split("="); + $scope.editPSGroupPolicyScope1.type.push(splitType[1]); + var splitService = splitValue[2].split("="); + $scope.editPSGroupPolicyScope1.service.push(splitService[1]); + var splitCloop = splitValue[3].split("="); + $scope.editPSGroupPolicyScope1.closedloop.push(splitCloop[1]); + } + } + + $scope.savePSGroupPolicyScope = function(groupPolicyScopeListData, groupPolicyScopeListData1) { + console.log(groupPolicyScopeListData1); + var uuu = papUrl + "/ecomp/ps_dictionary/save_psGroupPolicyScope.htm"; + var postData={groupPolicyScopeListData: groupPolicyScopeListData, + groupPolicyScopeListData1: groupPolicyScopeListData1, loginId: loginId}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){ + $scope.groupPolicyScopeListDatas=data.groupPolicyScopeListDatas;}); + if($scope.groupPolicyScopeListDatas == "Duplicate"){ + Notification.error("GroupPolicyScope Dictionary exists with Same Group Name.") + }else if($scope.groupPolicyScopeListDatas == "DuplicateGroup"){ + Notification.error("GroupPolicyScope Dictionary exists with Same Group List.") + }else{ + console.log($scope.groupPolicyScopeListDatas); + $modalInstance.close({groupPolicyScopeListDatas:$scope.groupPolicyScopeListDatas}); + } + }, + error : function(data){ + alert("Error while saving."); + } + }); + }; + + $scope.close = function() { + $modalInstance.close(); + }; +} \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/PSResourceDictController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/PSResourceDictController.js new file mode 100644 index 000000000..7aaf21834 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/PSResourceDictController.js @@ -0,0 +1,75 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +var editPSResourceController = function ($scope, $modalInstance, message, PapUrlService, UserInfoService, Notification){ + if(message.psResourceDictionaryData==null) + $scope.label='Add New Resource' + else{ + $scope.label='Edit Resource' + $scope.disableCd=true; + } + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + }); + + /*getting user info from session*/ + var loginId = null; + UserInfoService.getFunctionalMenuStaticDetailSession() + .then(function (response) { + loginId = response.userid; + }); + + $scope.editPSResource = message.psResourceDictionaryData; + + $scope.savePSResource = function(psResourceDictionaryData) { + var uuu = papUrl + "/ecomp/ps_dictionary/save_psResource.htm"; + var postData={psResourceDictionaryData: psResourceDictionaryData, loginId: loginId}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){ + $scope.psResourceDictionaryDatas=data.psResourceDictionaryDatas;}); + if($scope.psResourceDictionaryDatas == "Duplicate"){ + Notification.error("Resource Dictionary exists with Same Resource Name.") + }else{ + console.log($scope.psResourceDictionaryDatas); + $modalInstance.close({psResourceDictionaryDatas:$scope.psResourceDictionaryDatas}); + } + }, + error : function(data){ + alert("Error while saving."); + } + }); + }; + + $scope.close = function() { + $modalInstance.close(); + }; +} \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/PSServiceDictController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/PSServiceDictController.js new file mode 100644 index 000000000..5cccf30ad --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/PSServiceDictController.js @@ -0,0 +1,75 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +var editPSServiceController = function ($scope, $modalInstance, message, PapUrlService, UserInfoService, Notification){ + if(message.psServiceDictionaryData==null) + $scope.label='Add New Service' + else{ + $scope.label='Edit Service' + $scope.disableCd=true; + } + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + }); + + /*getting user info from session*/ + var loginId = null; + UserInfoService.getFunctionalMenuStaticDetailSession() + .then(function (response) { + loginId = response.userid; + }); + + $scope.editPSService = message.psServiceDictionaryData; + + $scope.savePSService = function(psServiceDictionaryData) { + var uuu = papUrl + "/ecomp/ps_dictionary/save_psService.htm"; + var postData={psServiceDictionaryData: psServiceDictionaryData, loginId: loginId}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){ + $scope.psServiceDictionaryDatas=data.psServiceDictionaryDatas;}); + if($scope.psServiceDictionaryDatas == "Duplicate"){ + Notification.error("Service Dictionary exists with Same Service Name.") + }else{ + console.log($scope.psServiceDictionaryDatas); + $modalInstance.close({psServiceDictionaryDatas:$scope.psServiceDictionaryDatas}); + } + }, + error : function(data){ + alert("Error while saving."); + } + }); + }; + + $scope.close = function() { + $modalInstance.close(); + }; +} \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/PSTypeDictController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/PSTypeDictController.js new file mode 100644 index 000000000..b3d5b833b --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/PSTypeDictController.js @@ -0,0 +1,76 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +var editPSTypeController = function ($scope, $modalInstance, message, PapUrlService, UserInfoService, Notification){ + if(message.psTypeDictionaryData==null) + $scope.label='Add New Type' + else{ + $scope.label='Edit Type' + $scope.disableCd=true; + } + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + }); + + /*getting user info from session*/ + var loginId = null; + UserInfoService.getFunctionalMenuStaticDetailSession() + .then(function (response) { + loginId = response.userid; + }); + + $scope.editPSType = message.psTypeDictionaryData; + + $scope.savePSType = function(psTypeDictionaryData) { + var uuu = papUrl + "/ecomp/ps_dictionary/save_psType.htm"; + var postData={psTypeDictionaryData: psTypeDictionaryData, loginId: loginId}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){ + $scope.psTypeDictionaryDatas=data.psTypeDictionaryDatas;}); + console.log($scope.psTypeDictionaryDatas); + if($scope.psTypeDictionaryDatas == "Duplicate"){ + Notification.error("Type Dictionary exists with Same Type Name.") + }else{ + console.log($scope.psTypeDictionaryDatas); + $modalInstance.close({psTypeDictionaryDatas:$scope.psTypeDictionaryDatas}); + } + }, + error : function(data){ + alert("Error while saving."); + } + }); + }; + + $scope.close = function() { + $modalInstance.close(); + }; +} \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/RiskTypeDictController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/RiskTypeDictController.js new file mode 100644 index 000000000..9df0d4771 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/RiskTypeDictController.js @@ -0,0 +1,75 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +var editRiskTypeController = function ($scope, $modalInstance, message, PapUrlService, UserInfoService, Notification){ + if(message.riskTypeDictionaryData==null) + $scope.label='Add New Type' + else{ + $scope.label='Edit Type' + $scope.disableCd=true; + } + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + }); + + /*getting user info from session*/ + var loginId = null; + UserInfoService.getFunctionalMenuStaticDetailSession() + .then(function (response) { + loginId = response.userid; + }); + + $scope.editRiskType = message.riskTypeDictionaryData; + + $scope.saveRiskType = function(riskTypeDictionaryData) { + var uuu = papUrl + "/ecomp/sp_dictionary/save_riskType.htm"; + var postData={riskTypeDictionaryData: riskTypeDictionaryData, loginId: loginId}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){ + $scope.riskTypeDictionaryDatas=data.riskTypeDictionaryDatas;}); + if($scope.riskTypeDictionaryDatas == "Duplicate"){ + Notification.error("Risk type Dictionary exists with Same RiskType Name.") + }else{ + console.log($scope.riskTypeDictionaryDatas); + $modalInstance.close({riskTypeDictionaryDatas:$scope.riskTypeDictionaryDatas}); + } + }, + error : function(data){ + alert("Error while saving."); + } + }); + }; + + $scope.close = function() { + $modalInstance.close(); + }; +} \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/SafePolicyWarningDictController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/SafePolicyWarningDictController.js new file mode 100644 index 000000000..4fe700768 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/SafePolicyWarningDictController.js @@ -0,0 +1,107 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +var editSafePolicyWarningController = function ($scope, $modalInstance, message, SafePolicyService, PapUrlService, UserInfoService, Notification){ + $scope.edit = false; + if(message.safePolicyWarningData==null) + $scope.label='Add New Safe Policy Warning' + else{ + $scope.label='Edit Safe Policy Warning' + $scope.disableCd=true; + $scope.edit = true; + } + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + + SafePolicyService.getSafePolicyWarningDictionaryDataByName(papUrl).then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.safePolicyWarningDatas = JSON.parse($scope.data.safePolicyWarningDatas); + console.log($scope.safePolicyWarningDatas); + }, function (error) { + console.log("failed"); + }); + SafePolicyService.getRiskTypeDictionaryDataByName(papUrl).then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.riskTypeDictionaryDatas = JSON.parse($scope.data.riskTypeDictionaryDatas); + console.log($scope.riskTypeDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + }); + + /*getting user info from session*/ + var loginId = null; + UserInfoService.getFunctionalMenuStaticDetailSession() + .then(function (response) { + loginId = response.userid; + }); + + $scope.editSafePolicyWarning = message.safePolicyWarningData; + $scope.editSafePolicyWarning1 = {resource: [], type:[], service: [], closedloop: []}; + if($scope.edit){ + if(message.safePolicyWarningData.groupList != null){ + var splitValue = message.safePolicyWarningData.groupList.split(","); + console.log(splitValue); + $scope.splittedGroupListValues = []; + var splitResource = splitValue[0].split("="); + $scope.editSafePolicyWarningScope1.riskType.push(splitResource[1]); + } + } + + $scope.saveSafePolicyWarning = function(safePolicyWarningData) { + console.log(safePolicyWarningData); + var uuu = papUrl + "/ecomp/sp_dictionary/save_safePolicyWarning.htm"; + var postData={safePolicyWarningData: safePolicyWarningData, loginId: loginId}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){ + $scope.safePolicyWarningDatas=data.safePolicyWarningDatas;}); + if($scope.safePolicyWarningDatas == "Duplicate"){ + Notification.error("Safe Policy Dictionary exists with Same Name.") + }else{ + console.log($scope.safePolicyWarningDatas); + $modalInstance.close({safePolicyWarningDatas:$scope.safePolicyWarningDatas}); + } + }, + error : function(data){ + alert("Error while saving."); + } + }); + }; + + $scope.close = function() { + $modalInstance.close(); + }; +} \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/actionPolicyDictController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/actionPolicyDictController.js new file mode 100644 index 000000000..b889a98cb --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/actionPolicyDictController.js @@ -0,0 +1,119 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +var editActionPolicyDictController = function ($scope, $modalInstance, message, PapUrlService, UserInfoService, Notification){ + if(message.actionPolicyDictionaryData==null) + $scope.label='Add Action Dictionary', + $scope.choices = []; + else{ + $scope.choices = []; + $scope.label='Edit Action Dictionary' + $scope.disableCd=true; + var headers = message.actionPolicyDictionaryData.header; + var SplitChars = ':'; + if (headers.indexOf(SplitChars) >= 0) { + var splitHeader = headers.split(SplitChars); + var singleHeader = splitHeader; + var splitEqual = '='; + for(i = 0; i < singleHeader.length; i++){ + if (singleHeader[i].indexOf(splitEqual) >= 0) { + var splitValue = singleHeader[i].split(splitEqual); + var key = splitValue[0]; + var value = splitValue[1]; + var newItemNo = $scope.choices.length+1; + $scope.choices.push({'id':'choice'+newItemNo, 'option': key , 'number' : value }); + } + } + }else{ + var splitEqual = '='; + if (headers.indexOf(splitEqual) >= 0) { + var splitValue = headers.split(splitEqual); + var key = splitValue[0]; + var value = splitValue[1]; + $scope.choices.push({'id':'choice'+1, 'option': key , 'number' : value }); + } + } + } + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + }); + + /*getting user info from session*/ + var loginId = null; + UserInfoService.getFunctionalMenuStaticDetailSession() + .then(function (response) { + loginId = response.userid; + }); + + $scope.editActionDict = message.actionPolicyDictionaryData; + $scope.saveActionDict = function(actionPolicyDictionaryData) { + var finalData = extend(actionPolicyDictionaryData, $scope.headerDatas[0]); + var uuu = papUrl + "/ecomp/action_dictionary/save_ActionDict.htm"; + var postData={actionPolicyDictionaryData: finalData, loginId: loginId}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){ + $scope.actionPolicyDictionaryDatas=data.actionPolicyDictionaryDatas;}); + if($scope.actionPolicyDictionaryDatas == "Duplicate"){ + Notification.error("ActionPolicy Dictionary exists with Same Attribute Name.") + }else{ + console.log($scope.actionPolicyDictionaryDatas); + $modalInstance.close({actionPolicyDictionaryDatas:$scope.actionPolicyDictionaryDatas}); + } + }, + error : function(data){ + alert("Error while saving."); + } + }); + }; + + $scope.close = function() { + $modalInstance.close(); + }; + + function extend(obj, src) { + for (var key in src) { + if (src.hasOwnProperty(key)) obj[key] = src[key]; + } + return obj; + } + + $scope.headerDatas = [{"headers" : $scope.choices}]; + $scope.addNewChoice = function() { + var newItemNo = $scope.choices.length+1; + $scope.choices.push({'id':'choice'+newItemNo}); + }; + $scope.removeChoice = function() { + var lastItem = $scope.choices.length-1; + $scope.choices.splice(lastItem); + }; + +} \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/attributeDictController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/attributeDictController.js new file mode 100644 index 000000000..9e32f0304 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/attributeDictController.js @@ -0,0 +1,109 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +var editAttributeController = function ($scope, $modalInstance, message, PapUrlService, UserInfoService, Notification){ + if(message.attributeDictionaryData==null) + $scope.label='Add New Attribute', + $scope.attributes = []; + else{ + $scope.attributes = []; + $scope.label='Edit Attribute' + $scope.disableCd=true; + var headers = message.attributeDictionaryData.attributeValue; + var splitEqual = ','; + if(headers != null){ + if (headers.indexOf(splitEqual) >= 0) { + var splitValue = headers.split(splitEqual); + for(i = 0; i < splitValue.length; i++){ + var key = splitValue[i]; + $scope.attributes.push({'id':'choice'+i+1, 'attributeValues': key}); + } + }else{ + var key = headers; + $scope.attributes.push({'id':'choice'+1, 'attributeValues': key}); + } + } + } + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl) + }); + + /*getting user info from session*/ + var loginId = null; + UserInfoService.getFunctionalMenuStaticDetailSession() + .then(function (response) { + loginId = response.userid; + }); + + $scope.editAttributeName = message.attributeDictionaryData; + + $scope.saveAttributeName = function(attributeDictionaryData) { + var finalData = extend(attributeDictionaryData, $scope.attributeDatas[0]); + var uuu = papUrl + "/ecomp/attribute_dictionary/save_attribute.htm"; + var postData={attributeDictionaryData: attributeDictionaryData, loginId: loginId}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){ + $scope.attributeDictionaryDatas=data.attributeDictionaryDatas;}); + if($scope.attributeDictionaryDatas == "Duplicate"){ + Notification.error("Attribute Dictionary exists with Same Attribute Name.") + }else{ + console.log($scope.attributeDictionaryDatas); + $modalInstance.close({attributeDictionaryDatas:$scope.attributeDictionaryDatas}); + } + }, + error : function(data){ + alert("Error while saving."); + } + }); + }; + + function extend(obj, src) { + for (var key in src) { + if (src.hasOwnProperty(key)) obj[key] = src[key]; + } + return obj; + } + + $scope.attributeDatas = [{"userDataTypeValues" : $scope.attributes}]; + $scope.addNewChoice = function() { + var newItemNo = $scope.attributes.length+1; + $scope.attributes.push({'id':'choice'+newItemNo}); + }; + $scope.removeChoice = function() { + var lastItem = $scope.attributes.length-1; + $scope.attributes.splice(lastItem); + }; + + $scope.close = function() { + $modalInstance.close(); + }; +} \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/ecompNameEditorController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/ecompNameEditorController.js new file mode 100644 index 000000000..5dd19a7fc --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryController/ecompNameEditorController.js @@ -0,0 +1,74 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +var editEcompNameController = function ($scope, $modalInstance, message, PapUrlService, UserInfoService, Notification){ + if(message.ecompNameDictionaryData==null) + $scope.label='Add New Ecomp Name' + else{ + $scope.label='Edit Ecomp Name' + $scope.disableCd=true; + } + $scope.editEcompName = message.ecompNameDictionaryData; + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + }); + + /*getting user info from session*/ + var loginId = null; + UserInfoService.getFunctionalMenuStaticDetailSession() + .then(function (response) { + loginId = response.userid; + }); + + $scope.saveEcompName = function(ecompNameDictionaryData) { + var uuu = papUrl + "/ecomp/ecomp_dictionary/save_ecompName.htm"; + var postData={ecompNameDictionaryData: ecompNameDictionaryData, loginId: loginId}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){ + $scope.ecompNameDictionaryDatas=data.ecompNameDictionaryDatas;}); + if($scope.ecompNameDictionaryDatas == "Duplicate"){ + Notification.error("EcompName Dictionary exists with Same Ecomp Name.") + }else{ + console.log($scope.ecompNameDictionaryDatas); + $modalInstance.close({ecompNameDictionaryDatas:$scope.ecompNameDictionaryDatas}); + } + }, + error : function(data){ + alert("Error while saving."); + } + }); + }; + + $scope.close = function() { + $modalInstance.close(); + }; +} \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/BRMSParamDictGridController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/BRMSParamDictGridController.js new file mode 100644 index 000000000..642fca248 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/BRMSParamDictGridController.js @@ -0,0 +1,127 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +app.controller('brmsParamDictGridController', function ($scope, DictionaryService,modalService, $modal, PapUrlService){ + $( "#dialog" ).hide(); + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + + DictionaryService.getBRMSParamDictionaryData(papUrl).then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.brmsParamDictionaryDatas = JSON.parse($scope.data.brmsParamDictionaryDatas); + console.log($scope.brmsParamDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + + }); + + $scope.brmsParamDictionaryGrid = { + data : 'brmsParamDictionaryDatas', + enableFiltering: true, + exporterCsvFilename: 'BRMSParamDictionary.csv', + enableGridMenu: true, + enableSelectAll: true, + columnDefs: [{ + field: 'id', enableFiltering: false, headerCellTemplate: '' + + '', + cellTemplate: + ' ', width: '8%' + }, + { field: 'ruleName', displayName : 'Rule Name'}, + { field: 'description'}, + {field: 'userCreatedBy.userName', displayName : 'Created By'}, + {field: 'createdDate',type: 'date', cellFilter: 'date:\'yyyy-MM-dd\'' } + ], + exporterPdfDefaultStyle: {fontSize: 9}, + exporterPdfTableStyle: {margin: [30, 30, 30, 30]}, + exporterPdfTableHeaderStyle: {fontSize: 10, bold: true, italics: true, color: 'red'}, + exporterPdfHeader: { text: "My Header", style: 'headerStyle' }, + exporterPdfFooter: function ( currentPage, pageCount ) { + return { text: currentPage.toString() + ' of ' + pageCount.toString(), style: 'footerStyle' }; + }, + exporterPdfCustomFormatter: function ( docDefinition ) { + docDefinition.styles.headerStyle = { fontSize: 22, bold: true }; + docDefinition.styles.footerStyle = { fontSize: 10, bold: true }; + return docDefinition; + }, + exporterPdfOrientation: 'portrait', + exporterPdfPageSize: 'LETTER', + exporterPdfMaxGridWidth: 500, + exporterCsvLinkElement: angular.element(document.querySelectorAll(".custom-csv-link-location")), + onRegisterApi: function(gridApi){ + $scope.gridApi = gridApi; + } + }; + + $scope.editBRMSParam = null; + $scope.createNewBRMSParamWindow = function(){ + $scope.editBRMSParam = null; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_brmsParam_popup.html', + controller: 'editBRMSParamController', + resolve: { + message: function () { + var message = { + brmsParamDictionaryDatas: $scope.editBRMSParam + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.brmsParamDictionaryDatas=response.brmsParamDictionaryDatas; + }); + }; + + $scope.deleteBRMSParam = function(data) { + modalService.popupConfirmWin("Confirm","You are about to delete the BRMS Param Name "+data.ruleName+". \n Do you want to continue?", + function(){ + var uuu = papUrl + "/ecomp/brms_dictionary/remove_brmsParam.htm"; + var postData={data: data}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){$scope.brmsParamDictionaryDatas=data.brmsParamDictionaryDatas;}); + }, + error : function(data){ + console.log(data); + modalService.showFailure("Fail","Error while deleting: "+ data.responseText); + } + }); + + }) + }; + +}); \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/CLPepOptionsDictGridController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/CLPepOptionsDictGridController.js new file mode 100644 index 000000000..5600ed16b --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/CLPepOptionsDictGridController.js @@ -0,0 +1,183 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +app.controller('pepOptionsDictGridController', function ($scope, PapUrlService, CLDictionaryService,modalService, $modal){ + $( "#dialog" ).hide(); + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + + CLDictionaryService.getPepOptionsDictionaryData(papUrl).then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.pepOptionsDictionaryDatas = JSON.parse($scope.data.pepOptionsDictionaryDatas); + console.log($scope.pepOptionsDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + + }); + + $scope.pepOptionsDictionaryGrid = { + data : 'pepOptionsDictionaryDatas', + enableFiltering: true, + exporterCsvFilename: 'PEPOptions.csv', + enableGridMenu: true, + enableSelectAll: true, + columnDefs: [{ + field: 'id', enableFiltering: false, headerCellTemplate: '' + + '', + cellTemplate: + ' ' + + ' ', width: '8%' + }, + { field: 'pepName', displayName : 'PEP Name'}, + { field: 'actions', displayName : 'Actions'}, + { field: 'description'}, + {field: 'userCreatedBy.userName', displayName : 'Created By'}, + {field: 'userModifiedBy.userName', displayName : 'Modified By'}, + {field: 'createdDate',type: 'date', cellFilter: 'date:\'yyyy-MM-dd\'' }, + {field: 'modifiedDate',type: 'date', cellFilter: 'date:\'yyyy-MM-dd\'' } + ], + exporterPdfDefaultStyle: {fontSize: 9}, + exporterPdfTableStyle: {margin: [30, 30, 30, 30]}, + exporterPdfTableHeaderStyle: {fontSize: 10, bold: true, italics: true, color: 'red'}, + exporterPdfHeader: { text: "My Header", style: 'headerStyle' }, + exporterPdfFooter: function ( currentPage, pageCount ) { + return { text: currentPage.toString() + ' of ' + pageCount.toString(), style: 'footerStyle' }; + }, + exporterPdfCustomFormatter: function ( docDefinition ) { + docDefinition.styles.headerStyle = { fontSize: 22, bold: true }; + docDefinition.styles.footerStyle = { fontSize: 10, bold: true }; + return docDefinition; + }, + exporterPdfOrientation: 'portrait', + exporterPdfPageSize: 'LETTER', + exporterPdfMaxGridWidth: 500, + exporterCsvLinkElement: angular.element(document.querySelectorAll(".custom-csv-link-location")), + onRegisterApi: function(gridApi){ + $scope.gridApi = gridApi; + } + }; + + $scope.editPEPOptions = null; + $scope.createNewPEPOptionsWindow = function(){ + $scope.editEcompName = null; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_PEPOptions_popup.html', + controller: 'editPEPOptionsController', + resolve: { + message: function () { + var message = { + pepOptionsDictionaryDatas: $scope.editPEPOptions + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.pepOptionsDictionaryDatas=response.pepOptionsDictionaryDatas; + }); + }; + + $scope.editPEPOptionsWindow = function(pepOptionsDictionaryData) { + $scope.editPEPOptions = pepOptionsDictionaryData; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_PEPOptions_popup.html', + controller: 'editPEPOptionsController', + resolve: { + message: function () { + var message = { + pepOptionsDictionaryData: $scope.editPEPOptions + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.pepOptionsDictionaryDatas = response.pepOptionsDictionaryDatas; + }); + }; + + $scope.deletePEPOptions = function(data) { + var uuu = "searchDictionary.htm"; + var postData={data: data, type: "pepOptions"}; + var searchString = "\n"; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(resultList){ + $scope.$apply(function(){ + $scope.list =resultList.result;}); + $scope.searchData = JSON.stringify(resultList.result); + $scope.searchDatas = JSON.parse($scope.searchData); + $scope.success = true; + var i; + if($scope.searchDatas.length > 0){ + for(i = 0 ; i < $scope.searchDatas.length; i++){ + searchString += $scope.searchDatas[i].name + "\n"; + } + }else{ + searchString += "No Policies is Using this Value" + } + + console.log($scope.list); + if($scope.success){ + modalService.popupConfirmWin("Confirm","You are about to delete the PEP Options : "+data.pepName+". \n "+searchString+" \n Do you want to continue?", + function(){ + var uuu = papUrl + "/ecomp/cl_dictionary/remove_pepOptions.htm"; + var postData={data: data}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){$scope.pepOptionsDictionaryDatas=data.pepOptionsDictionaryDatas;}); + }, + error : function(data){ + console.log(data); + modalService.showFailure("Fail","Error while deleting: "+ data.responseText); + } + }); + + })} + }, + error : function(data){ + alert("Error while Searching."); + } + }); + }; + +}); \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/CLServiceDictGridController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/CLServiceDictGridController.js new file mode 100644 index 000000000..8f5893da9 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/CLServiceDictGridController.js @@ -0,0 +1,161 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +app.controller('serviceDictGridController', function ($scope, PapUrlService, CLDictionaryService,modalService, $modal){ + $( "#dialog" ).hide(); + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + + CLDictionaryService.getServiceDictionaryData(papUrl).then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.closedLoopServiceDictionaryDatas = JSON.parse($scope.data.closedLoopServiceDictionaryDatas); + console.log($scope.closedLoopServiceDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + + }); + + $scope.serviceDictionaryGrid = { + data : 'closedLoopServiceDictionaryDatas', + enableFiltering: true, + columnDefs: [{ + field: 'id', enableFiltering: false, headerCellTemplate: '' + + '', + cellTemplate: + ' ' + + ' ', width: '8%' + }, + { field: 'serviceName', displayName : 'Service Name'}, + { field: 'description'}, + {field: 'userCreatedBy.userName', displayName : 'Created By'}, + {field: 'userModifiedBy.userName', displayName : 'Modified By'}, + {field: 'createdDate',type: 'date', cellFilter: 'date:\'yyyy-MM-dd\'' }, + {field: 'modifiedDate',type: 'date', cellFilter: 'date:\'yyyy-MM-dd\'' } + ] + }; + + $scope.editCLService = null; + $scope.createNewServiceDictWindow = function(){ + $scope.editCLService = null; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_CLService_popup.html', + controller: 'editCLServiceController', + resolve: { + message: function () { + var message = { + closedLoopServiceDictionaryDatas: $scope.editCLService + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.closedLoopServiceDictionaryDatas=response.closedLoopServiceDictionaryDatas; + }); + }; + + $scope.editServiceDictWindow = function(closedLoopServiceDictionaryData) { + $scope.editCLService = closedLoopServiceDictionaryData; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_CLService_popup.html', + controller: 'editCLServiceController', + resolve: { + message: function () { + var message = { + closedLoopServiceDictionaryData: $scope.editCLService + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.closedLoopServiceDictionaryDatas = response.closedLoopServiceDictionaryDatas; + }); + }; + + $scope.deleteServiceDict = function(data) { + var uuu = "searchDictionary.htm"; + var postData={data: data, type: "clService"}; + var searchString = "\n"; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(resultList){ + $scope.$apply(function(){ + $scope.list =resultList.result;}); + $scope.searchData = JSON.stringify(resultList.result); + $scope.searchDatas = JSON.parse($scope.searchData); + $scope.success = true; + var i; + if($scope.searchDatas.length > 0){ + for(i = 0 ; i < $scope.searchDatas.length; i++){ + searchString += $scope.searchDatas[i].name + "\n"; + } + }else{ + searchString += "No Policies is Using this Value" + } + + console.log($scope.list); + if($scope.success){ + modalService.popupConfirmWin("Confirm","You are about to delete the Service Dictionary "+data.serviceName+". \n "+searchString+" \n Do you want to continue?", + function(){ + var uuu = papUrl + "/ecomp/cl_dictionary/remove_Service.htm"; + var postData={data: data}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){$scope.closedLoopServiceDictionaryDatas=data.closedLoopServiceDictionaryDatas;}); + }, + error : function(data){ + console.log(data); + modalService.showFailure("Fail","Error while deleting: "+ data.responseText); + } + }); + + })} + }, + error : function(data){ + alert("Error while Searching."); + } + }); + }; + + +}); \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/CLSiteDictGridController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/CLSiteDictGridController.js new file mode 100644 index 000000000..0a0e72a7f --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/CLSiteDictGridController.js @@ -0,0 +1,161 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +app.controller('siteDictGridController', function ($scope, PapUrlService, CLDictionaryService,modalService, $modal){ + $( "#dialog" ).hide(); + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + + CLDictionaryService.getSiteDictionaryData(papUrl).then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.closedLoopSiteDictionaryDatas = JSON.parse($scope.data.closedLoopSiteDictionaryDatas); + console.log($scope.closedLoopSiteDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + + }); + + $scope.siteDictionaryGrid = { + data : 'closedLoopSiteDictionaryDatas', + enableFiltering: true, + columnDefs: [{ + field: 'id', enableFiltering: false, headerCellTemplate: '' + + '', + cellTemplate: + ' ' + + ' ', width: '8%' + }, + { field: 'siteName', displayName : 'Site Name'}, + { field: 'description'}, + {field: 'userCreatedBy.userName', displayName : 'Created By'}, + {field: 'userModifiedBy.userName', displayName : 'Modified By'}, + {field: 'createdDate',type: 'date', cellFilter: 'date:\'yyyy-MM-dd\'' }, + {field: 'modifiedDate',type: 'date', cellFilter: 'date:\'yyyy-MM-dd\'' } + ] + }; + + $scope.editCLSite = null; + $scope.createNewSiteDictWindow = function(){ + $scope.editCLSite = null; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_CLSite_popup.html', + controller: 'editCLSiteController', + resolve: { + message: function () { + var message = { + closedLoopSiteDictionaryDatas: $scope.editCLSite + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.closedLoopSiteDictionaryDatas=response.closedLoopSiteDictionaryDatas; + }); + }; + + $scope.editSiteDictWindow = function(closedLoopSiteDictionaryData) { + $scope.editCLSite = closedLoopSiteDictionaryData; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_CLSite_popup.html', + controller: 'editCLSiteController', + resolve: { + message: function () { + var message = { + closedLoopSiteDictionaryData: $scope.editCLSite + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.closedLoopSiteDictionaryDatas = response.closedLoopSiteDictionaryDatas; + }); + }; + + $scope.deleteSiteDict = function(data) { + var uuu = "searchDictionary.htm"; + var postData={data: data, type: "clSite"}; + var searchString = "\n"; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(resultList){ + $scope.$apply(function(){ + $scope.list =resultList.result;}); + $scope.searchData = JSON.stringify(resultList.result); + $scope.searchDatas = JSON.parse($scope.searchData); + $scope.success = true; + var i; + if($scope.searchDatas.length > 0){ + for(i = 0 ; i < $scope.searchDatas.length; i++){ + searchString += $scope.searchDatas[i].name + "\n"; + } + }else{ + searchString += "No Policies is Using this Value" + } + + console.log($scope.list); + if($scope.success){ + modalService.popupConfirmWin("Confirm","You are about to delete the Site Dictionary : "+data.siteName+". \n "+searchString+" \n Do you want to continue?", + function(){ + var uuu = papUrl + "/ecomp/cl_dictionary/remove_site.htm"; + var postData={data: data}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){$scope.closedLoopSiteDictionaryDatas=data.closedLoopSiteDictionaryDatas;}); + }, + error : function(data){ + console.log(data); + modalService.showFailure("Fail","Error while deleting: "+ data.responseText); + } + }); + + })} + }, + error : function(data){ + alert("Error while Searching."); + } + }); + }; + + +}); \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/CLVarbindDictGridController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/CLVarbindDictGridController.js new file mode 100644 index 000000000..87ccac953 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/CLVarbindDictGridController.js @@ -0,0 +1,184 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +app.controller('varbindDictGridController', function ($scope, PapUrlService, CLDictionaryService,modalService, $modal){ + $( "#dialog" ).hide(); + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + + CLDictionaryService.getVarbindDictionaryData(papUrl).then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.varbindDictionaryDatas = JSON.parse($scope.data.varbindDictionaryDatas); + console.log($scope.varbindDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + + }); + + $scope.varbindDictionaryGrid = { + data : 'varbindDictionaryDatas', + enableFiltering: true, + exporterCsvFilename: 'VarbindDictionary.csv', + enableGridMenu: true, + enableSelectAll: true, + columnDefs: [{ + field: 'id', enableFiltering: false, headerCellTemplate: '' + + '', + cellTemplate: + ' ' + + ' ', width: '8%' + }, + { field: 'varbindName', displayName : 'Varbind Name'}, + { field: 'varbindDescription', displayName : 'Varbind Description'}, + { field: 'varbindOID', displayName : 'Varbind OID'}, + {field: 'userCreatedBy.userName', displayName : 'Created By'}, + {field: 'userModifiedBy.userName', displayName : 'Modified By'}, + {field: 'createdDate',type: 'date', cellFilter: 'date:\'yyyy-MM-dd\'' }, + {field: 'modifiedDate',type: 'date', cellFilter: 'date:\'yyyy-MM-dd\'' } + ], + exporterPdfDefaultStyle: {fontSize: 9}, + exporterPdfTableStyle: {margin: [30, 30, 30, 30]}, + exporterPdfTableHeaderStyle: {fontSize: 10, bold: true, italics: true, color: 'red'}, + exporterPdfHeader: { text: "My Header", style: 'headerStyle' }, + exporterPdfFooter: function ( currentPage, pageCount ) { + return { text: currentPage.toString() + ' of ' + pageCount.toString(), style: 'footerStyle' }; + }, + exporterPdfCustomFormatter: function ( docDefinition ) { + docDefinition.styles.headerStyle = { fontSize: 22, bold: true }; + docDefinition.styles.footerStyle = { fontSize: 10, bold: true }; + return docDefinition; + }, + exporterPdfOrientation: 'portrait', + exporterPdfPageSize: 'LETTER', + exporterPdfMaxGridWidth: 500, + exporterCsvLinkElement: angular.element(document.querySelectorAll(".custom-csv-link-location")), + onRegisterApi: function(gridApi){ + $scope.gridApi = gridApi; + } + }; + + $scope.editCLVarbind = null; + $scope.createNewVarbindDictWindow = function(){ + $scope.editCLVarbind = null; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_varbind_popup.html', + controller: 'editCLVarbindController', + resolve: { + message: function () { + var message = { + varbindDictionaryDatas: $scope.editCLVarbind + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.varbindDictionaryDatas=response.varbindDictionaryDatas; + }); + }; + + $scope.editVarbindDictWindow = function(varbindDictionaryData) { + $scope.editCLVarbind = varbindDictionaryData; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_varbind_popup.html', + controller: 'editCLVarbindController', + resolve: { + message: function () { + var message = { + varbindDictionaryData: $scope.editCLVarbind + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.varbindDictionaryDatas = response.varbindDictionaryDatas; + }); + }; + + $scope.deleteVarbindDictionary = function(data) { + var uuu = "searchDictionary.htm"; + var postData={data: data, type: "clVarbind"}; + var searchString = "\n"; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(resultList){ + $scope.$apply(function(){ + $scope.list =resultList.result;}); + $scope.searchData = JSON.stringify(resultList.result); + $scope.searchDatas = JSON.parse($scope.searchData); + $scope.success = true; + var i; + if($scope.searchDatas.length > 0){ + for(i = 0 ; i < $scope.searchDatas.length; i++){ + searchString += $scope.searchDatas[i].name + "\n"; + } + }else{ + searchString += "No Policies is Using this Value" + } + + console.log($scope.list); + if($scope.success){ + modalService.popupConfirmWin("Confirm","You are about to delete the Varbind Dictionary "+data.varbindName+". \n "+searchString+" \n Do you want to continue?", + function(){ + var uuu = papUrl + "/ecomp/cl_dictionary/remove_varbindDict.htm"; + var postData={data: data}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){$scope.varbindDictionaryDatas=data.varbindDictionaryDatas;}); + }, + error : function(data){ + console.log(data); + modalService.showFailure("Fail","Error while deleting: "+ data.responseText); + } + }); + + })} + }, + error : function(data){ + alert("Error while Searching."); + } + }); + }; + + +}); \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/CLVnfTypeDictGridController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/CLVnfTypeDictGridController.js new file mode 100644 index 000000000..4e5f27ca4 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/CLVnfTypeDictGridController.js @@ -0,0 +1,181 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +app.controller('vnfTypeDictGridController', function ($scope, PapUrlService, CLDictionaryService,modalService, $modal){ + $( "#dialog" ).hide(); + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + + CLDictionaryService.getVnfTypeDictionaryData(papUrl).then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.vnfTypeDictionaryDatas = JSON.parse($scope.data.vnfTypeDictionaryDatas); + console.log($scope.vnfTypeDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + + }); + + $scope.vnfTypeDictionaryGrid = { + data : 'vnfTypeDictionaryDatas', + enableFiltering: true, + exporterCsvFilename: 'VNFType.csv', + enableGridMenu: true, + enableSelectAll: true, + columnDefs: [{ + field: 'id', enableFiltering: false, headerCellTemplate: '' + + '', + cellTemplate: + ' ' + + ' ', width: '8%' + }, + { field: 'vnftype', displayName : 'VNF Type'}, + { field: 'description'}, + {field: 'userCreatedBy.userName', displayName : 'Created By'}, + {field: 'userModifiedBy.userName', displayName : 'Modified By'}, + {field: 'createdDate',type: 'date', cellFilter: 'date:\'yyyy-MM-dd\'' }, + {field: 'modifiedDate',type: 'date', cellFilter: 'date:\'yyyy-MM-dd\'' } + ], + exporterPdfDefaultStyle: {fontSize: 9}, + exporterPdfTableStyle: {margin: [30, 30, 30, 30]}, + exporterPdfTableHeaderStyle: {fontSize: 10, bold: true, italics: true, color: 'red'}, + exporterPdfHeader: { text: "My Header", style: 'headerStyle' }, + exporterPdfFooter: function ( currentPage, pageCount ) { + return { text: currentPage.toString() + ' of ' + pageCount.toString(), style: 'footerStyle' }; + }, + exporterPdfCustomFormatter: function ( docDefinition ) { + docDefinition.styles.headerStyle = { fontSize: 22, bold: true }; + docDefinition.styles.footerStyle = { fontSize: 10, bold: true }; + return docDefinition; + }, + exporterPdfOrientation: 'portrait', + exporterPdfPageSize: 'LETTER', + exporterPdfMaxGridWidth: 500, + exporterCsvLinkElement: angular.element(document.querySelectorAll(".custom-csv-link-location")), + onRegisterApi: function(gridApi){ + $scope.gridApi = gridApi; + } + }; + + $scope.editVnfType = null; + $scope.createNewVnfTypeWindow = function(){ + $scope.editVnfType = null; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_vnfType_popup.html', + controller: 'editVnfTypeController', + resolve: { + message: function () { + var message = { + vnfTypeDictionaryDatas: $scope.editVnfType + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.vnfTypeDictionaryDatas=response.vnfTypeDictionaryDatas; + }); + }; + + $scope.editVnfTypeWindow = function(vnfTypeDictionaryData) { + $scope.editVnfType = vnfTypeDictionaryData; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_vnfType_popup.html', + controller: 'editVnfTypeController', + resolve: { + message: function () { + var message = { + vnfTypeDictionaryData: $scope.editVnfType + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.vnfTypeDictionaryDatas = response.vnfTypeDictionaryDatas; + }); + }; + + $scope.deleteVnfType = function(data) { + var uuu = "searchDictionary.htm"; + var postData={data: data, type: "attribute"}; + var searchString = "\n"; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(resultList){ + $scope.$apply(function(){ + $scope.list =resultList.result;}); + $scope.searchData = JSON.stringify(resultList.result); + $scope.searchDatas = JSON.parse($scope.searchData); + $scope.success = true; + var i; + if($scope.searchDatas.length > 0){ + for(i = 0 ; i < $scope.searchDatas.length; i++){ + searchString += $scope.searchDatas[i].name + "\n"; + } + }else{ + searchString += "No Policies is Using this Value" + } + + console.log($scope.list); + if($scope.success){ + modalService.popupConfirmWin("Confirm","You are about to delete the Vnf Type Dictionary Item "+data.vnftype+". \n "+searchString+" \n Do you want to continue?", + function(){ + var uuu = papUrl + "/ecomp/cl_dictionary/remove_vnfType.htm"; + var postData={data: data}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){$scope.vnfTypeDictionaryDatas=data.vnfTypeDictionaryDatas;}); + }, + error : function(data){ + console.log(data); + modalService.showFailure("Fail","Error while deleting: "+ data.responseText); + } + }); + + })} + }, + error : function(data){ + alert("Error while Searching."); + } + }); + }; +}); \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/CLVsclActionDictGridController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/CLVsclActionDictGridController.js new file mode 100644 index 000000000..1ff52f203 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/CLVsclActionDictGridController.js @@ -0,0 +1,183 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +app.controller('vsclActionDictGridController', function ($scope, PapUrlService, CLDictionaryService,modalService, $modal){ + $( "#dialog" ).hide(); + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + + CLDictionaryService.getVSCLActionDictionaryData(papUrl).then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.vsclActionDictionaryDatas = JSON.parse($scope.data.vsclActionDictionaryDatas); + console.log($scope.vsclActionDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + + }); + + $scope.vsclActionDictionaryGrid = { + data : 'vsclActionDictionaryDatas', + enableFiltering: true, + exporterCsvFilename: 'VSCLAction.csv', + enableGridMenu: true, + enableSelectAll: true, + columnDefs: [{ + field: 'id', enableFiltering: false, headerCellTemplate: '' + + '', + cellTemplate: + ' ' + + ' ', width: '8%' + }, + { field: 'vsclaction', displayName : 'VSCL Action'}, + { field: 'description'}, + {field: 'userCreatedBy.userName', displayName : 'Created By'}, + {field: 'userModifiedBy.userName', displayName : 'Modified By'}, + {field: 'createdDate',type: 'date', cellFilter: 'date:\'yyyy-MM-dd\'' }, + {field: 'modifiedDate',type: 'date', cellFilter: 'date:\'yyyy-MM-dd\'' } + ], + exporterPdfDefaultStyle: {fontSize: 9}, + exporterPdfTableStyle: {margin: [30, 30, 30, 30]}, + exporterPdfTableHeaderStyle: {fontSize: 10, bold: true, italics: true, color: 'red'}, + exporterPdfHeader: { text: "My Header", style: 'headerStyle' }, + exporterPdfFooter: function ( currentPage, pageCount ) { + return { text: currentPage.toString() + ' of ' + pageCount.toString(), style: 'footerStyle' }; + }, + exporterPdfCustomFormatter: function ( docDefinition ) { + docDefinition.styles.headerStyle = { fontSize: 22, bold: true }; + docDefinition.styles.footerStyle = { fontSize: 10, bold: true }; + return docDefinition; + }, + exporterPdfOrientation: 'portrait', + exporterPdfPageSize: 'LETTER', + exporterPdfMaxGridWidth: 500, + exporterCsvLinkElement: angular.element(document.querySelectorAll(".custom-csv-link-location")), + onRegisterApi: function(gridApi){ + $scope.gridApi = gridApi; + } + }; + + $scope.editvsclAction = null; + $scope.createvsclActionWindow = function(){ + $scope.editvsclAction = null; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_vsclAction_popup.html', + controller: 'editVsclActionController', + resolve: { + message: function () { + var message = { + vsclActionDictionaryDatas: $scope.editvsclAction + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.vsclActionDictionaryDatas=response.vsclActionDictionaryDatas; + }); + }; + + $scope.editvsclActionWindow = function(vsclActionDictionaryData) { + $scope.editvsclAction = vsclActionDictionaryData; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_vsclAction_popup.html', + controller: 'editVsclActionController', + resolve: { + message: function () { + var message = { + vsclActionDictionaryData: $scope.editvsclAction + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.vsclActionDictionaryDatas = response.vsclActionDictionaryDatas; + }); + }; + + $scope.success = false; + $scope.deletevsclAction = function(data) { + var uuu = "searchDictionary.htm"; + var postData={data: data, type: "clVSCL"}; + var searchString = "\n"; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(resultList){ + $scope.$apply(function(){ + $scope.list =resultList.result;}); + $scope.searchData = JSON.stringify(resultList.result); + $scope.searchDatas = JSON.parse($scope.searchData); + $scope.success = true; + var i; + if($scope.searchDatas.length > 0){ + for(i = 0 ; i < $scope.searchDatas.length; i++){ + searchString += $scope.searchDatas[i].name + "\n"; + } + }else{ + searchString += "No Policies is Using this Value" + } + + console.log($scope.list); + if($scope.success){ + modalService.popupConfirmWin("Confirm","You are about to delete the Vscl Action Item "+data.vsclaction+". \n "+searchString+" \n Do you want to continue?", + function(){ + var uuu = papUrl + "/ecomp/cl_dictionary/remove_VsclAction.htm"; + var postData={data: data}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){$scope.vsclActionDictionaryDatas=data.vsclActionDictionaryDatas;}); + }, + error : function(data){ + console.log(data); + modalService.showFailure("Fail","Error while deleting: "+ data.responseText); + } + }); + + })} + }, + error : function(data){ + alert("Error while Searching."); + } + }); + }; + +}); \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/DecisionSettingsDictGridController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/DecisionSettingsDictGridController.js new file mode 100644 index 000000000..8a81853a6 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/DecisionSettingsDictGridController.js @@ -0,0 +1,151 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +app.controller('decisionSettingsDictGridController', function ($scope, DictionaryService,modalService, $modal, PapUrlService){ + $( "#dialog" ).hide(); + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + + DictionaryService.getDecisionSettingsDictionaryData(papUrl).then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.settingsDictionaryDatas = JSON.parse($scope.data.settingsDictionaryDatas); + console.log($scope.settingsDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + + }); + + $scope.decisionSettingsDictionaryGrid = { + data : 'settingsDictionaryDatas', + enableFiltering: true, + exporterCsvFilename: 'Settings.csv', + enableGridMenu: true, + enableSelectAll: true, + columnDefs: [{ + field: 'id', enableFiltering: false, headerCellTemplate: '' + + '', + cellTemplate: + ' ' + + ' ', width: '8%' + },{ field: 'xacmlId', displayName : 'Settings ID'}, + { field: 'datatypeBean.shortName', displayName : 'Data Type' }, + { field: 'description' }, + {field: 'userCreatedBy.userName', displayName : 'Created By' }, + {field: 'userModifiedBy.userName', displayName : 'Modified By'}, + {field: 'createdDate',type: 'date', cellFilter: 'date:\'yyyy-MM-dd\'' }, + {field: 'modifiedDate',type: 'date', cellFilter: 'date:\'yyyy-MM-dd\'' } + ], + exporterPdfDefaultStyle: {fontSize: 9}, + exporterPdfTableStyle: {margin: [30, 30, 30, 30]}, + exporterPdfTableHeaderStyle: {fontSize: 10, bold: true, italics: true, color: 'red'}, + exporterPdfHeader: { text: "My Header", style: 'headerStyle' }, + exporterPdfFooter: function ( currentPage, pageCount ) { + return { text: currentPage.toString() + ' of ' + pageCount.toString(), style: 'footerStyle' }; + }, + exporterPdfCustomFormatter: function ( docDefinition ) { + docDefinition.styles.headerStyle = { fontSize: 22, bold: true }; + docDefinition.styles.footerStyle = { fontSize: 10, bold: true }; + return docDefinition; + }, + exporterPdfOrientation: 'portrait', + exporterPdfPageSize: 'LETTER', + exporterPdfMaxGridWidth: 500, + exporterCsvLinkElement: angular.element(document.querySelectorAll(".custom-csv-link-location")), + onRegisterApi: function(gridApi){ + $scope.gridApi = gridApi; + } + }; + + $scope.editSettingsDict = null; + $scope.createNewSettingsDictWindow = function(){ + $scope.editSettingsDict = null; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_SettingsDict_popup.html', + controller: 'editSettingsDictController', + resolve: { + message: function () { + var message = { + settingsDictionaryDatas: $scope.editSettingsDict + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.settingsDictionaryDatas=response.settingsDictionaryDatas; + }); + }; + + $scope.editSettingsDictWindow = function(settingsDictionaryData) { + $scope.editSettingsDict = settingsDictionaryData; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_SettingsDict_popup.html', + controller: 'editSettingsDictController', + resolve: { + message: function () { + var message = { + settingsDictionaryData: $scope.editSettingsDict + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.settingsDictionaryDatas = response.settingsDictionaryDatas; + }); + }; + + $scope.deleteSettingsDict = function(data) { + modalService.popupConfirmWin("Confirm","You are about to delete the Settings Dictionary "+data.xacmlId+". Do you want to continue?", + function(){ + var uuu = papUrl + "/ecomp/settings_dictionary/remove_settings.htm"; + var postData={data: data}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){$scope.settingsDictionaryDatas=data.settingsDictionaryDatas;}); + }, + error : function(data){ + console.log(data); + modalService.showFailure("Fail","Error while deleting: "+ data.responseText); + } + }); + + }) + }; + + +}); \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/DescriptiveScopeDictGridController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/DescriptiveScopeDictGridController.js new file mode 100644 index 000000000..b35a28de2 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/DescriptiveScopeDictGridController.js @@ -0,0 +1,150 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +app.controller('descriptiveDictGridController', function ($scope, DictionaryService,modalService, $modal, PapUrlService){ + $( "#dialog" ).hide(); + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + + DictionaryService.getDescriptiveDictionaryData(papUrl).then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.descriptiveScopeDictionaryDatas = JSON.parse($scope.data.descriptiveScopeDictionaryDatas); + console.log($scope.descriptiveScopeDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + + }); + + $scope.descriptiveDictionaryGrid = { + data : 'descriptiveScopeDictionaryDatas', + enableFiltering: true, + exporterCsvFilename: 'SearchCriteria.csv', + enableGridMenu: true, + enableSelectAll: true, + columnDefs: [{ + field: 'id', enableFiltering: false, headerCellTemplate: '' + + '', + cellTemplate: + ' ' + + ' ', width: '8%' + },{ field: 'scopeName', displayName : 'Descriptive Scope Name'}, + { field: 'search', displayName : 'Search Criteria' }, + { field: 'description' }, + {field: 'userCreatedBy.userName', displayName : 'Created By' }, + {field: 'userModifiedBy.userName', displayName : 'Modified By'}, + {field: 'createdDate',type: 'date', cellFilter: 'date:\'yyyy-MM-dd\'' }, + {field: 'modifiedDate',type: 'date', cellFilter: 'date:\'yyyy-MM-dd\'' } + ], + exporterPdfDefaultStyle: {fontSize: 9}, + exporterPdfTableStyle: {margin: [30, 30, 30, 30]}, + exporterPdfTableHeaderStyle: {fontSize: 10, bold: true, italics: true, color: 'red'}, + exporterPdfHeader: { text: "My Header", style: 'headerStyle' }, + exporterPdfFooter: function ( currentPage, pageCount ) { + return { text: currentPage.toString() + ' of ' + pageCount.toString(), style: 'footerStyle' }; + }, + exporterPdfCustomFormatter: function ( docDefinition ) { + docDefinition.styles.headerStyle = { fontSize: 22, bold: true }; + docDefinition.styles.footerStyle = { fontSize: 10, bold: true }; + return docDefinition; + }, + exporterPdfOrientation: 'portrait', + exporterPdfPageSize: 'LETTER', + exporterPdfMaxGridWidth: 500, + exporterCsvLinkElement: angular.element(document.querySelectorAll(".custom-csv-link-location")), + onRegisterApi: function(gridApi){ + $scope.gridApi = gridApi; + } + }; + + $scope.editDescriptiveScope = null; + $scope.createNewDescriptiveScopeWindow = function(){ + $scope.editDescriptiveScope = null; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_descriptiveScope_popup.html', + controller: 'editDescriptiveScopeController', + resolve: { + message: function () { + var message = { + descriptiveScopeDictionaryDatas: $scope.editDescriptiveScope + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.descriptiveScopeDictionaryDatas=response.descriptiveScopeDictionaryDatas; + }); + }; + + $scope.editDescriptiveScopeWindow = function(descriptiveScopeDictionaryData) { + $scope.editDescriptiveScope = descriptiveScopeDictionaryData; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_descriptiveScope_popup.html', + controller: 'editDescriptiveScopeController', + resolve: { + message: function () { + var message = { + descriptiveScopeDictionaryData: $scope.editDescriptiveScope + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.descriptiveScopeDictionaryDatas = response.descriptiveScopeDictionaryDatas; + }); + }; + + $scope.deleteDescriptiveScope = function(data) { + modalService.popupConfirmWin("Confirm","You are about to delete the Descriptive Scope : "+data.scopeName+". Do you want to continue?", + function(){ + var uuu = papUrl + "/ecomp/descriptive_dictionary/remove_descriptiveScope.htm"; + var postData={data: data}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){$scope.descriptiveScopeDictionaryDatas=data.descriptiveScopeDictionaryDatas;}); + }, + error : function(data){ + console.log(data); + modalService.showFailure("Fail","Error while deleting: "+ data.responseText); + } + }); + + }) + }; +}); \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/EnforcerTypeDictGridController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/EnforcerTypeDictGridController.js new file mode 100644 index 000000000..d5fceb8d6 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/EnforcerTypeDictGridController.js @@ -0,0 +1,126 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +app.controller('enforcerDictGridController', function ($scope, DictionaryService,modalService, $modal, PapUrlService){ + $( "#dialog" ).hide(); + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + + + DictionaryService.getEnforcerDictionaryData(papUrl).then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.enforcerDictionaryDatas = JSON.parse($scope.data.enforcerDictionaryDatas); + console.log($scope.enforcerDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + + }); + + $scope.enforcerDictionaryGrid = { + data : 'enforcerDictionaryDatas', + enableFiltering: true, + columnDefs: [{ + field: 'id', enableFiltering: false, headerCellTemplate: '' + + '', + cellTemplate: + ' ' + + ' ', width: '8%' + },{ field: 'enforcingType', displayName : 'Enforcing Type'}, + { field: 'script' , displayName : 'Script'}, + {field: 'connectionQuery', displayName : 'Connection Query' }, + {field: 'valueQuery', displayName : 'Value Query'} + ] + }; + + $scope.editEnforcerType = null; + $scope.createNewEnforcerTypeWindow = function(){ + $scope.editEnforcerType = null; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_EnforcerType_popup.html', + controller: 'editEnforcerTypeController', + resolve: { + message: function () { + var message = { + enforcerDictionaryDatas: $scope.editEnforcerType + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.enforcerDictionaryDatas=response.enforcerDictionaryDatas; + }); + }; + + $scope.editEnforcerTypeWindow = function(enforcerDictionaryData) { + $scope.editEnforcerType = enforcerDictionaryData; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_EnforcerType_popup.html', + controller: 'editEnforcerTypeController', + resolve: { + message: function () { + var message = { + enforcerDictionaryData: $scope.editEnforcerType + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.enforcerDictionaryDatas = response.enforcerDictionaryDatas; + }); + }; + + $scope.deleteEnforcerType = function(data) { + modalService.popupConfirmWin("Confirm","You are about to delete the Enforcing Type "+data.enforcingType+". Do you want to continue?", + function(){ + var uuu = papUrl + "/ecomp/enforcer_dictionary/remove_enforcer.htm"; + var postData={data: data}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){$scope.enforcerDictionaryDatas=data.enforcerDictionaryDatas;}); + }, + error : function(data){ + console.log(data); + modalService.showFailure("Fail","Error while deleting: "+ data.responseText); + } + }); + + }) + }; +}); \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/FWActionListDictGridController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/FWActionListDictGridController.js new file mode 100644 index 000000000..6f8c0aad5 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/FWActionListDictGridController.js @@ -0,0 +1,145 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +app.controller('actionListDictGridController', function ($scope, FWDictionaryService,modalService, $modal, PapUrlService){ + $( "#dialog" ).hide(); + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + + FWDictionaryService.getActionListDictionaryData(papUrl).then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.actionListDictionaryDatas = JSON.parse($scope.data.actionListDictionaryDatas); + console.log($scope.actionListDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + + }); + + $scope.actionListDictionaryGrid = { + data : 'actionListDictionaryDatas', + enableFiltering: true, + exporterCsvFilename: 'ActionList.csv', + enableGridMenu: true, + enableSelectAll: true, + columnDefs: [{ + field: 'id', enableFiltering: false, headerCellTemplate: '' + + '', + cellTemplate: + ' ' + + ' ', width: '8%' + },{ field: 'actionName', displayName : 'Action Name'}, + { field: 'description' } + ], + exporterPdfDefaultStyle: {fontSize: 9}, + exporterPdfTableStyle: {margin: [30, 30, 30, 30]}, + exporterPdfTableHeaderStyle: {fontSize: 10, bold: true, italics: true, color: 'red'}, + exporterPdfHeader: { text: "My Header", style: 'headerStyle' }, + exporterPdfFooter: function ( currentPage, pageCount ) { + return { text: currentPage.toString() + ' of ' + pageCount.toString(), style: 'footerStyle' }; + }, + exporterPdfCustomFormatter: function ( docDefinition ) { + docDefinition.styles.headerStyle = { fontSize: 22, bold: true }; + docDefinition.styles.footerStyle = { fontSize: 10, bold: true }; + return docDefinition; + }, + exporterPdfOrientation: 'portrait', + exporterPdfPageSize: 'LETTER', + exporterPdfMaxGridWidth: 500, + exporterCsvLinkElement: angular.element(document.querySelectorAll(".custom-csv-link-location")), + onRegisterApi: function(gridApi){ + $scope.gridApi = gridApi; + } + }; + + $scope.editActionList = null; + $scope.createNewFWActionListWindow = function(){ + $scope.editActionList = null; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_FWActionList_popup.html', + controller: 'editFWActionListController', + resolve: { + message: function () { + var message = { + actionListDictionaryDatas: $scope.editActionList + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.actionListDictionaryDatas=response.actionListDictionaryDatas; + }); + }; + + $scope.editFWActionListWindow = function(actionListDictionaryData) { + $scope.editActionList = actionListDictionaryData; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_FWActionList_popup.html', + controller: 'editFWActionListController', + resolve: { + message: function () { + var message = { + actionListDictionaryData: $scope.editActionList + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.actionListDictionaryDatas = response.actionListDictionaryDatas; + }); + }; + + $scope.deleteFWActionList = function(data) { + modalService.popupConfirmWin("Confirm","You are about to delete the Action List "+data.actionName+". Do you want to continue?", + function(){ + var uuu = papUrl + "/ecomp/fw_dictionary/remove_ActionList.htm"; + var postData={data: data}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){$scope.actionListDictionaryDatas=data.actionListDictionaryDatas;}); + }, + error : function(data){ + console.log(data); + modalService.showFailure("Fail","Error while deleting: "+ data.responseText); + } + }); + + }) + }; +}); \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/FWAddressGroupDictGridController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/FWAddressGroupDictGridController.js new file mode 100644 index 000000000..4220a7c6d --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/FWAddressGroupDictGridController.js @@ -0,0 +1,146 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +app.controller('addressGroupDictGridController', function ($scope, FWDictionaryService,modalService, $modal, PapUrlService){ + $( "#dialog" ).hide(); + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + + FWDictionaryService.getAddressGroupDictionaryData(papUrl).then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.addressGroupDictionaryDatas = JSON.parse($scope.data.addressGroupDictionaryDatas); + console.log($scope.addressGroupDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + }); + + $scope.addressGroupDictionaryGrid = { + data : 'addressGroupDictionaryDatas', + enableFiltering: true, + exporterCsvFilename: 'AddressGroup.csv', + enableGridMenu: true, + enableSelectAll: true, + columnDefs: [{ + field: 'id', enableFiltering: false, headerCellTemplate: '' + + '', + cellTemplate: + ' ' + + ' ', width: '8%' + },{ field: 'groupName', displayName : 'Group Name'}, + { field: 'prefixList', displayName : 'Prefix List' }, + { field: 'description' } + ], + exporterPdfDefaultStyle: {fontSize: 9}, + exporterPdfTableStyle: {margin: [30, 30, 30, 30]}, + exporterPdfTableHeaderStyle: {fontSize: 10, bold: true, italics: true, color: 'red'}, + exporterPdfHeader: { text: "My Header", style: 'headerStyle' }, + exporterPdfFooter: function ( currentPage, pageCount ) { + return { text: currentPage.toString() + ' of ' + pageCount.toString(), style: 'footerStyle' }; + }, + exporterPdfCustomFormatter: function ( docDefinition ) { + docDefinition.styles.headerStyle = { fontSize: 22, bold: true }; + docDefinition.styles.footerStyle = { fontSize: 10, bold: true }; + return docDefinition; + }, + exporterPdfOrientation: 'portrait', + exporterPdfPageSize: 'LETTER', + exporterPdfMaxGridWidth: 500, + exporterCsvLinkElement: angular.element(document.querySelectorAll(".custom-csv-link-location")), + onRegisterApi: function(gridApi){ + $scope.gridApi = gridApi; + } + }; + + + $scope.editAddressGroup = null; + $scope.createNewFWAddressGroupWindow = function(){ + $scope.editAddressGroup = null; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_FWAddressGroup_popup.html', + controller: 'editFWAddressGroupController', + resolve: { + message: function () { + var message = { + addressGroupDictionaryDatas: $scope.editAddressGroup + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.addressGroupDictionaryDatas=response.addressGroupDictionaryDatas; + }); + }; + + $scope.editFWAddressGroupWindow = function(addressGroupDictionaryData) { + $scope.editAddressGroup = addressGroupDictionaryData; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_FWAddressGroup_popup.html', + controller: 'editFWAddressGroupController', + resolve: { + message: function () { + var message = { + addressGroupDictionaryData: $scope.editAddressGroup + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.addressGroupDictionaryDatas = response.addressGroupDictionaryDatas; + }); + }; + + $scope.deleteFWAddressGroup = function(data) { + modalService.popupConfirmWin("Confirm","You are about to delete the Address Group "+data.groupName+". Do you want to continue?", + function(){ + var uuu = papUrl + "/ecomp/fw_dictionary/remove_AddressGroup.htm"; + var postData={data: data}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){$scope.addressGroupDictionaryDatas=data.addressGroupDictionaryDatas;}); + }, + error : function(data){ + console.log(data); + modalService.showFailure("Fail","Error while deleting: "+ data.responseText); + } + }); + + }) + }; +}); \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/FWParentListDictGridController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/FWParentListDictGridController.js new file mode 100644 index 000000000..a4fc959f6 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/FWParentListDictGridController.js @@ -0,0 +1,149 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +app.controller('parentDictGridController', function ($scope, FWDictionaryService,modalService, $modal, PapUrlService){ + $( "#dialog" ).hide(); + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + + FWDictionaryService.getParentListDictionaryData(papUrl).then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.fwDictListDictionaryDatas = JSON.parse($scope.data.fwDictListDictionaryDatas); + console.log($scope.fwDictListDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + }); + + + + $scope.parentDictionaryGrid = { + data : 'fwDictListDictionaryDatas', + enableFiltering: true, + exporterCsvFilename: 'ParentList.csv', + enableGridMenu: true, + enableSelectAll: true, + columnDefs: [{ + field: 'id', enableFiltering: false, headerCellTemplate: '' + + '', + cellTemplate: + ' ' + + ' ', width: '8%' + },{ field: 'parentItemName', displayName : 'Parent Name'}, + { field: 'description', displayName : 'Description' }, + { field: 'addressList', displayName : 'Address List' }, + { field: 'serviceList', displayName : 'Service List' } + ], + exporterPdfDefaultStyle: {fontSize: 9}, + exporterPdfTableStyle: {margin: [30, 30, 30, 30]}, + exporterPdfTableHeaderStyle: {fontSize: 10, bold: true, italics: true, color: 'red'}, + exporterPdfHeader: { text: "My Header", style: 'headerStyle' }, + exporterPdfFooter: function ( currentPage, pageCount ) { + return { text: currentPage.toString() + ' of ' + pageCount.toString(), style: 'footerStyle' }; + }, + exporterPdfCustomFormatter: function ( docDefinition ) { + docDefinition.styles.headerStyle = { fontSize: 22, bold: true }; + docDefinition.styles.footerStyle = { fontSize: 10, bold: true }; + return docDefinition; + }, + exporterPdfOrientation: 'portrait', + exporterPdfPageSize: 'LETTER', + exporterPdfMaxGridWidth: 500, + exporterCsvLinkElement: angular.element(document.querySelectorAll(".custom-csv-link-location")), + onRegisterApi: function(gridApi){ + $scope.gridApi = gridApi; + } + }; + + $scope.editParentList = null; + $scope.createNewFWParentListWindow = function(){ + $scope.editParentList = null; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_fwParentList_popup.html', + controller: 'editFWParentListController', + resolve: { + message: function () { + var message = { + fwDictListDictionaryDatas: $scope.editParentList + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.fwDictListDictionaryDatas=response.fwDictListDictionaryDatas; + }); + }; + + $scope.editFWParentListWindow = function(fwDictListDictionaryData) { + $scope.editParentList = fwDictListDictionaryData; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_fwParentList_popup.html', + controller: 'editFWParentListController', + resolve: { + message: function () { + var message = { + fwDictListDictionaryData: $scope.editParentList + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.fwDictListDictionaryDatas = response.fwDictListDictionaryDatas; + }); + }; + + $scope.deleteFWParentList = function(data) { + modalService.popupConfirmWin("Confirm","You are about to delete the Parent List: "+data.parentItemName+". Do you want to continue?", + function(){ + var uuu = papUrl + "/ecomp/fw_dictionary/remove_FWDictionaryList.htm"; + var postData={data: data}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){$scope.fwDictListDictionaryDatas=data.fwDictListDictionaryDatas;}); + }, + error : function(data){ + console.log(data); + modalService.showFailure("Fail","Error while deleting: "+ data.responseText); + } + }); + + }) + }; + +}); \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/FWPortListDictGridController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/FWPortListDictGridController.js new file mode 100644 index 000000000..647b97a80 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/FWPortListDictGridController.js @@ -0,0 +1,132 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +app.controller('portListDictGridController', function ($scope, FWDictionaryService,modalService, $modal, PapUrlService){ + $( "#dialog" ).hide(); + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + + FWDictionaryService.getPortListDictionaryData(papUrl).then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.portListDictionaryDatas = JSON.parse($scope.data.portListDictionaryDatas); + console.log($scope.portListDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + + FWDictionaryService.getPortListDictionaryData(papUrl).then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.portListDictionaryDatas = JSON.parse($scope.data.portListDictionaryDatas); + console.log($scope.portListDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + }); + + $scope.portListDictionaryGrid = { + data : 'portListDictionaryDatas', + enableFiltering: true, + columnDefs: [{ + field: 'id', enableFiltering: false, headerCellTemplate: '' + + '', + cellTemplate: + ' ' + + ' ', width: '8%' + },{ field: 'portName', displayName : 'Port Name'}, + { field: 'description' } + ] + }; + + $scope.editPortList = null; + $scope.createNewFWPortListWindow = function(){ + $scope.editPortList = null; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_FWPortList_popup.html', + controller: 'editFWPortListController', + resolve: { + message: function () { + var message = { + portListDictionaryDatas: $scope.editPortList + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.portListDictionaryDatas=response.portListDictionaryDatas; + }); + }; + + $scope.editFWPortListWindow = function(portListDictionaryData) { + $scope.editPortList = portListDictionaryData; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_FWPortList_popup.html', + controller: 'editFWPortListController', + resolve: { + message: function () { + var message = { + portListDictionaryData: $scope.editPortList + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.portListDictionaryDatas = response.portListDictionaryDatas; + }); + }; + + $scope.deleteFWPortList = function(data) { + modalService.popupConfirmWin("Confirm","You are about to delete the Port List "+data.portName+". Do you want to continue?", + function(){ + var uuu = papUrl + "/ecomp/fw_dictionary/remove_PortList.htm"; + var postData={data: data}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){$scope.portListDictionaryDatas=data.portListDictionaryDatas;}); + }, + error : function(data){ + console.log(data); + modalService.showFailure("Fail","Error while deleting: "+ data.responseText); + } + }); + + }) + }; +}); \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/FWPrefixListDictGridController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/FWPrefixListDictGridController.js new file mode 100644 index 000000000..09f3f3eb4 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/FWPrefixListDictGridController.js @@ -0,0 +1,148 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +app.controller('prefixListDictGridController', function ($scope, FWDictionaryService,modalService, $modal, PapUrlService){ + $( "#dialog" ).hide(); + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + + FWDictionaryService.getPrefixListDictionaryData(papUrl).then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.prefixListDictionaryDatas = JSON.parse($scope.data.prefixListDictionaryDatas); + console.log($scope.prefixListDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + + }); + + $scope.prefixListDictionaryGrid = { + data : 'prefixListDictionaryDatas', + enableFiltering: true, + exporterCsvFilename: 'PrefixList.csv', + enableGridMenu: true, + enableSelectAll: true, + columnDefs: [{ + field: 'id', enableFiltering: false, headerCellTemplate: '' + + '', + cellTemplate: + ' ' + + ' ', width: '8%' + },{ field: 'prefixListName', displayName : 'PrefixList Name'}, + { field: 'description' }, + {field: 'prefixListValue', displayName : 'PrefixList Value' } + ], + exporterPdfDefaultStyle: {fontSize: 9}, + exporterPdfTableStyle: {margin: [30, 30, 30, 30]}, + exporterPdfTableHeaderStyle: {fontSize: 10, bold: true, italics: true, color: 'red'}, + exporterPdfHeader: { text: "My Header", style: 'headerStyle' }, + exporterPdfFooter: function ( currentPage, pageCount ) { + return { text: currentPage.toString() + ' of ' + pageCount.toString(), style: 'footerStyle' }; + }, + exporterPdfCustomFormatter: function ( docDefinition ) { + docDefinition.styles.headerStyle = { fontSize: 22, bold: true }; + docDefinition.styles.footerStyle = { fontSize: 10, bold: true }; + return docDefinition; + }, + exporterPdfOrientation: 'portrait', + exporterPdfPageSize: 'LETTER', + exporterPdfMaxGridWidth: 500, + exporterCsvLinkElement: angular.element(document.querySelectorAll(".custom-csv-link-location")), + onRegisterApi: function(gridApi){ + $scope.gridApi = gridApi; + } + }; + + + $scope.editPrefixList = null; + $scope.createNewFWPrefixListWindow = function(){ + $scope.editPrefixList = null; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_FWPrefixList_popup.html', + controller: 'editFWPrefixListController', + resolve: { + message: function () { + var message = { + prefixListDictionaryDatas: $scope.editPrefixList + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.prefixListDictionaryDatas=response.prefixListDictionaryDatas; + }); + }; + + $scope.editFWPrefixListWindow = function(prefixListDictionaryData) { + $scope.editPrefixList = prefixListDictionaryData; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_FWPrefixList_popup.html', + controller: 'editFWPrefixListController', + resolve: { + message: function () { + var message = { + prefixListDictionaryData: $scope.editPrefixList + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.prefixListDictionaryDatas = response.prefixListDictionaryDatas; + }); + }; + + $scope.deleteFWPrefixList = function(data) { + modalService.popupConfirmWin("Confirm","You are about to delete the Prefix List "+data.prefixListName+". Do you want to continue?", + function(){ + var uuu = papUrl + "/ecomp/fw_dictionary/remove_PrefixList.htm"; + var postData={data: data}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){$scope.prefixListDictionaryDatas=data.prefixListDictionaryDatas;}); + }, + error : function(data){ + console.log(data); + modalService.showFailure("Fail","Error while deleting: "+ data.responseText); + } + }); + + }) + }; + +}); \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/FWProtocolListDictGridController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/FWProtocolListDictGridController.js new file mode 100644 index 000000000..e31d0757b --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/FWProtocolListDictGridController.js @@ -0,0 +1,157 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +app.controller('protocolListDictGridController', function ($scope, FWDictionaryService,modalService, $modal, PapUrlService){ + $( "#dialog" ).hide(); + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + + FWDictionaryService.getProtocolListDictionaryData(papUrl).then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.protocolListDictionaryDatas = JSON.parse($scope.data.protocolListDictionaryDatas); + console.log($scope.protocolListDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + + FWDictionaryService.getProtocolListDictionaryData(papUrl).then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.protocolListDictionaryDatas = JSON.parse($scope.data.protocolListDictionaryDatas); + console.log($scope.protocolListDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + + }); + + $scope.protocolListDictionaryGrid = { + data : 'protocolListDictionaryDatas', + enableFiltering: true, + exporterCsvFilename: 'ProtocolList.csv', + enableGridMenu: true, + enableSelectAll: true, + columnDefs: [{ + field: 'id', enableFiltering: false, headerCellTemplate: '' + + '', + cellTemplate: + ' ' + + ' ', width: '8%' + },{ field: 'protocolName', displayName : 'Protocol Name'}, + { field: 'description' } + ], + exporterPdfDefaultStyle: {fontSize: 9}, + exporterPdfTableStyle: {margin: [30, 30, 30, 30]}, + exporterPdfTableHeaderStyle: {fontSize: 10, bold: true, italics: true, color: 'red'}, + exporterPdfHeader: { text: "My Header", style: 'headerStyle' }, + exporterPdfFooter: function ( currentPage, pageCount ) { + return { text: currentPage.toString() + ' of ' + pageCount.toString(), style: 'footerStyle' }; + }, + exporterPdfCustomFormatter: function ( docDefinition ) { + docDefinition.styles.headerStyle = { fontSize: 22, bold: true }; + docDefinition.styles.footerStyle = { fontSize: 10, bold: true }; + return docDefinition; + }, + exporterPdfOrientation: 'portrait', + exporterPdfPageSize: 'LETTER', + exporterPdfMaxGridWidth: 500, + exporterCsvLinkElement: angular.element(document.querySelectorAll(".custom-csv-link-location")), + onRegisterApi: function(gridApi){ + $scope.gridApi = gridApi; + } + }; + + + $scope.editProtocolList = null; + $scope.createNewFWProtocolListWindow = function(){ + $scope.editProtocolList = null; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_FWProtocolList_popup.html', + controller: 'editFWProtocolListController', + resolve: { + message: function () { + var message = { + protocolListDictionaryDatas: $scope.editProtocolList + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.protocolListDictionaryDatas=response.protocolListDictionaryDatas; + }); + }; + + $scope.editFWProtocolListWindow = function(protocolListDictionaryData) { + $scope.editProtocolList = protocolListDictionaryData; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_FWProtocolList_popup.html', + controller: 'editFWProtocolListController', + resolve: { + message: function () { + var message = { + protocolListDictionaryData: $scope.editProtocolList + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.protocolListDictionaryDatas = response.protocolListDictionaryDatas; + }); + }; + + $scope.deleteFWProtocolList = function(data) { + modalService.popupConfirmWin("Confirm","You are about to delete the Protocol List "+data.protocolName+". Do you want to continue?", + function(){ + var uuu = papUrl + "/ecomp/fw_dictionary/remove_protocol.htm"; + var postData={data: data}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){$scope.protocolListDictionaryDatas=data.protocolListDictionaryDatas;}); + }, + error : function(data){ + console.log(data); + modalService.showFailure("Fail","Error while deleting: "+ data.responseText); + } + }); + + }) + }; + +}); \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/FWSecurityZoneDictGridController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/FWSecurityZoneDictGridController.js new file mode 100644 index 000000000..7f1367924 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/FWSecurityZoneDictGridController.js @@ -0,0 +1,147 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +app.controller('securityZoneDictGridController', function ($scope, FWDictionaryService,modalService, $modal, PapUrlService){ + $( "#dialog" ).hide(); + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + + FWDictionaryService.getSecurityZoneDictionaryData(papUrl).then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.securityZoneDictionaryDatas = JSON.parse($scope.data.securityZoneDictionaryDatas); + console.log($scope.securityZoneDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + + }); + + + $scope.securityZoneDictionaryGrid = { + data : 'securityZoneDictionaryDatas', + enableFiltering: true, + exporterCsvFilename: 'SecurityZone.csv', + enableGridMenu: true, + enableSelectAll: true, + columnDefs: [{ + field: 'id', enableFiltering: false, headerCellTemplate: '' + + '', + cellTemplate: + ' ' + + ' ', width: '8%' + },{ field: 'zoneName', displayName : 'Zone Name'}, + { field: 'zoneValue', displayName : 'Zone Value' } + ], + exporterPdfDefaultStyle: {fontSize: 9}, + exporterPdfTableStyle: {margin: [30, 30, 30, 30]}, + exporterPdfTableHeaderStyle: {fontSize: 10, bold: true, italics: true, color: 'red'}, + exporterPdfHeader: { text: "My Header", style: 'headerStyle' }, + exporterPdfFooter: function ( currentPage, pageCount ) { + return { text: currentPage.toString() + ' of ' + pageCount.toString(), style: 'footerStyle' }; + }, + exporterPdfCustomFormatter: function ( docDefinition ) { + docDefinition.styles.headerStyle = { fontSize: 22, bold: true }; + docDefinition.styles.footerStyle = { fontSize: 10, bold: true }; + return docDefinition; + }, + exporterPdfOrientation: 'portrait', + exporterPdfPageSize: 'LETTER', + exporterPdfMaxGridWidth: 500, + exporterCsvLinkElement: angular.element(document.querySelectorAll(".custom-csv-link-location")), + onRegisterApi: function(gridApi){ + $scope.gridApi = gridApi; + } + }; + + $scope.editSecurityZone = null; + $scope.createNewFWSecurityZoneWindow = function(){ + $scope.editSecurityZone = null; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_fwSecurityZone_popup.html', + controller: 'editfwSecurityZoneController', + resolve: { + message: function () { + var message = { + securityZoneDictionaryDatas: $scope.editSecurityZone + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.securityZoneDictionaryDatas=response.securityZoneDictionaryDatas; + }); + }; + + $scope.editFWSecurityZoneWindow = function(securityZoneDictionaryData) { + $scope.editSecurityZone = securityZoneDictionaryData; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_fwSecurityZone_popup.html', + controller: 'editfwSecurityZoneController', + resolve: { + message: function () { + var message = { + securityZoneDictionaryData: $scope.editSecurityZone + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.securityZoneDictionaryDatas = response.securityZoneDictionaryDatas; + }); + }; + + $scope.deleteFWSecurityZone = function(data) { + modalService.popupConfirmWin("Confirm","You are about to delete the Security Zone "+data.zoneName+". Do you want to continue?", + function(){ + var uuu = papUrl + "/ecomp/fw_dictionary/remove_securityZone.htm"; + var postData={data: data}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){$scope.securityZoneDictionaryDatas=data.securityZoneDictionaryDatas;}); + }, + error : function(data){ + console.log(data); + modalService.showFailure("Fail","Error while deleting: "+ data.responseText); + } + }); + + }) + }; + +}); \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/FWServiceGroupDictGridController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/FWServiceGroupDictGridController.js new file mode 100644 index 000000000..fd6bba456 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/FWServiceGroupDictGridController.js @@ -0,0 +1,147 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +app.controller('serviceGroupDictGridController', function ($scope, FWDictionaryService,modalService, $modal, PapUrlService){ + $( "#dialog" ).hide(); + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + + FWDictionaryService.getServiceGroupDictionaryData(papUrl).then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.serviceGroupDictionaryDatas = JSON.parse($scope.data.serviceGroupDictionaryDatas); + console.log($scope.serviceGroupDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + }); + + + + $scope.serviceGroupDictionaryGrid = { + data : 'serviceGroupDictionaryDatas', + enableFiltering: true, + exporterCsvFilename: 'ServiceGroup.csv', + enableGridMenu: true, + enableSelectAll: true, + columnDefs: [{ + field: 'id', enableFiltering: false, headerCellTemplate: '' + + '', + cellTemplate: + ' ' + + ' ', width: '8%' + },{ field: 'groupName', displayName : 'Group Name'}, + { field: 'serviceList', displayName : 'Service List' } + ], + exporterPdfDefaultStyle: {fontSize: 9}, + exporterPdfTableStyle: {margin: [30, 30, 30, 30]}, + exporterPdfTableHeaderStyle: {fontSize: 10, bold: true, italics: true, color: 'red'}, + exporterPdfHeader: { text: "My Header", style: 'headerStyle' }, + exporterPdfFooter: function ( currentPage, pageCount ) { + return { text: currentPage.toString() + ' of ' + pageCount.toString(), style: 'footerStyle' }; + }, + exporterPdfCustomFormatter: function ( docDefinition ) { + docDefinition.styles.headerStyle = { fontSize: 22, bold: true }; + docDefinition.styles.footerStyle = { fontSize: 10, bold: true }; + return docDefinition; + }, + exporterPdfOrientation: 'portrait', + exporterPdfPageSize: 'LETTER', + exporterPdfMaxGridWidth: 500, + exporterCsvLinkElement: angular.element(document.querySelectorAll(".custom-csv-link-location")), + onRegisterApi: function(gridApi){ + $scope.gridApi = gridApi; + } + }; + + $scope.editServiceGroup = null; + $scope.createNewFWServiceGroupWindow = function(){ + $scope.editServiceGroup = null; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_fwServiceGroup_popup.html', + controller: 'editFWServiceGroupController', + resolve: { + message: function () { + var message = { + serviceGroupDictionaryDatas: $scope.editServiceGroup + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.serviceGroupDictionaryDatas=response.serviceGroupDictionaryDatas; + }); + }; + + $scope.editFWServiceGroupWindow = function(serviceGroupDictionaryData) { + $scope.editServiceGroup = serviceGroupDictionaryData; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_fwServiceGroup_popup.html', + controller: 'editFWServiceGroupController', + resolve: { + message: function () { + var message = { + serviceGroupDictionaryData: $scope.editServiceGroup + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.serviceGroupDictionaryDatas = response.serviceGroupDictionaryDatas; + }); + }; + + $scope.deleteFWServiceGroup = function(data) { + modalService.popupConfirmWin("Confirm","You are about to delete the Service Group: "+data.groupName+". Do you want to continue?", + function(){ + var uuu = papUrl + "/ecomp/fw_dictionary/remove_serviceGroup.htm"; + var postData={data: data}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){$scope.serviceGroupDictionaryDatas=data.serviceGroupDictionaryDatas;}); + }, + error : function(data){ + console.log(data); + modalService.showFailure("Fail","Error while deleting: "+ data.responseText); + } + }); + + }) + }; + +}); \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/FWServiceListDictGridController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/FWServiceListDictGridController.js new file mode 100644 index 000000000..1b56240fd --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/FWServiceListDictGridController.js @@ -0,0 +1,162 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +app.controller('serviceListDictGridController', function ($scope, FWDictionaryService,modalService, $modal, PapUrlService){ + $( "#dialog" ).hide(); + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + + FWDictionaryService.getServiceListDictionaryData(papUrl).then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.serviceListDictionaryDatas = JSON.parse($scope.data.serviceListDictionaryDatas); + console.log($scope.serviceListDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + + FWDictionaryService.getProtocolListDictionaryData(papUrl).then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.protocolListDictionaryDatas = JSON.parse($scope.data.protocolListDictionaryDatas); + console.log($scope.protocolListDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + + }); + + + + $scope.serviceListDictionaryGrid = { + data : 'serviceListDictionaryDatas', + enableFiltering: true, + exporterCsvFilename: 'ServiceList.csv', + enableGridMenu: true, + enableSelectAll: true, + columnDefs: [{ + field: 'id', enableFiltering: false, headerCellTemplate: '' + + '', + cellTemplate: + ' ' + + ' ', width: '8%' + },{ field: 'serviceName', displayName : 'Service Name'}, + { field: 'serviceDescription' , displayName : 'Description'}, + {field: 'serviceType', displayName : 'Service Type' }, + {field: 'serviceTransProtocol', displayName : 'Transport Protocol'}, + {field: 'serviceAppProtocol',displayName : 'APP Protocol' }, + {field: 'servicePorts',displayName : 'Ports' } + ], + exporterPdfDefaultStyle: {fontSize: 9}, + exporterPdfTableStyle: {margin: [30, 30, 30, 30]}, + exporterPdfTableHeaderStyle: {fontSize: 10, bold: true, italics: true, color: 'red'}, + exporterPdfHeader: { text: "My Header", style: 'headerStyle' }, + exporterPdfFooter: function ( currentPage, pageCount ) { + return { text: currentPage.toString() + ' of ' + pageCount.toString(), style: 'footerStyle' }; + }, + exporterPdfCustomFormatter: function ( docDefinition ) { + docDefinition.styles.headerStyle = { fontSize: 22, bold: true }; + docDefinition.styles.footerStyle = { fontSize: 10, bold: true }; + return docDefinition; + }, + exporterPdfOrientation: 'portrait', + exporterPdfPageSize: 'LETTER', + exporterPdfMaxGridWidth: 500, + exporterCsvLinkElement: angular.element(document.querySelectorAll(".custom-csv-link-location")), + onRegisterApi: function(gridApi){ + $scope.gridApi = gridApi; + } + }; + + $scope.editServiceList = null; + $scope.createNewFWServiceListWindow = function(){ + $scope.editServiceList = null; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_FWServiceList_popup.html', + controller: 'editFWServiceListController', + resolve: { + message: function () { + var message = { + serviceListDictionaryDatas: $scope.editServiceList + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.serviceListDictionaryDatas=response.serviceListDictionaryDatas; + }); + }; + + $scope.editFWServiceListWindow = function(serviceListDictionaryData) { + $scope.editServiceList = serviceListDictionaryData; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_FWServiceList_popup.html', + controller: 'editFWServiceListController', + resolve: { + message: function () { + var message = { + serviceListDictionaryData: $scope.editServiceList + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.serviceListDictionaryDatas = response.serviceListDictionaryDatas; + }); + }; + + $scope.deleteFWServiceList = function(data) { + modalService.popupConfirmWin("Confirm","You are about to delete the Service List "+data.serviceName+". Do you want to continue?", + function(){ + var uuu = papUrl + "/ecomp/fw_dictionary/remove_serviceList.htm"; + var postData={data: data}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){$scope.serviceListDictionaryDatas=data.serviceListDictionaryDatas;}); + }, + error : function(data){ + console.log(data); + modalService.showFailure("Fail","Error while deleting: "+ data.responseText); + } + }); + + }) + }; + +}); \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/FWTermListDictGridController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/FWTermListDictGridController.js new file mode 100644 index 000000000..3ba588da9 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/FWTermListDictGridController.js @@ -0,0 +1,159 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +app.controller('termListDictGridController', function ($scope, FWDictionaryService,modalService, $modal, PapUrlService){ + $( "#dialog" ).hide(); + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + + FWDictionaryService.getTermListDictionaryData(papUrl).then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.termListDictionaryDatas = JSON.parse($scope.data.termListDictionaryDatas); + console.log($scope.termListDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + + + }); + + $scope.termListDictionaryGrid = { + data : 'termListDictionaryDatas', + enableFiltering: true, + exporterCsvFilename: 'TermList.csv', + enableGridMenu: true, + enableSelectAll: true, + columnDefs: [{ + field: 'id', enableFiltering: false, headerCellTemplate: '' + + '', + cellTemplate: + ' ' + + ' ', width: '8%' + },{ field: 'termName', displayName : 'Term-Name'}, + { field: 'termDescription', displayName : 'Term-Description' }, + { field: 'fromZone', displayName : 'From Zone' }, + {field: 'toZone', displayName : 'To Zone' }, + {field: 'srcIPList', displayName : 'Source-IP-List'}, + {field: 'destIPList',displayName : 'Destination-IP-List' }, + {field: 'srcPortList',displayName : 'Source-Port-List' }, + {field: 'destPortList',displayName : 'Destination-Port-List' }, + {field: 'action',displayName : 'Action List' }, + {field: 'userCreatedBy.userName',displayName : 'Created By' }, + {field: 'userModifiedBy.userName',displayName : 'Modified By'}, + {field: 'createdDate',type: 'date', cellFilter: 'date:\'yyyy-MM-dd\'' }, + {field: 'modifiedDate',type: 'date', cellFilter: 'date:\'yyyy-MM-dd\'' } + ], + exporterPdfDefaultStyle: {fontSize: 9}, + exporterPdfTableStyle: {margin: [30, 30, 30, 30]}, + exporterPdfTableHeaderStyle: {fontSize: 10, bold: true, italics: true, color: 'red'}, + exporterPdfHeader: { text: "My Header", style: 'headerStyle' }, + exporterPdfFooter: function ( currentPage, pageCount ) { + return { text: currentPage.toString() + ' of ' + pageCount.toString(), style: 'footerStyle' }; + }, + exporterPdfCustomFormatter: function ( docDefinition ) { + docDefinition.styles.headerStyle = { fontSize: 22, bold: true }; + docDefinition.styles.footerStyle = { fontSize: 10, bold: true }; + return docDefinition; + }, + exporterPdfOrientation: 'portrait', + exporterPdfPageSize: 'LETTER', + exporterPdfMaxGridWidth: 500, + exporterCsvLinkElement: angular.element(document.querySelectorAll(".custom-csv-link-location")), + onRegisterApi: function(gridApi){ + $scope.gridApi = gridApi; + } + }; + + $scope.editTermList = null; + $scope.createNewFWTermListWindow = function(){ + $scope.editTermList = null; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_fwTermList_popup.html', + controller: 'editFWTermListController', + resolve: { + message: function () { + var message = { + termListDictionaryDatas: $scope.editTermList + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.termListDictionaryDatas=response.termListDictionaryDatas; + }); + }; + + $scope.editFWTermListWindow = function(termListDictionaryData) { + $scope.editTermList = termListDictionaryData; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_fwTermList_popup.html', + controller: 'editFWTermListController', + resolve: { + message: function () { + var message = { + termListDictionaryData: $scope.editTermList + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.termListDictionaryDatas = response.termListDictionaryDatas; + }); + }; + + $scope.deleteFWTermList = function(data) { + modalService.popupConfirmWin("Confirm","You are about to delete the TermList "+data.termName+". Do you want to continue?", + function(){ + var uuu = papUrl + "/ecomp/fw_dictionary/remove_termList.htm"; + var postData={data: data}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){$scope.termListDictionaryDatas=data.termListDictionaryDatas;}); + }, + error : function(data){ + console.log(data); + modalService.showFailure("Fail","Error while deleting: "+ data.responseText); + } + }); + + }) + }; + + +}); \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/FWZoneDictGridController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/FWZoneDictGridController.js new file mode 100644 index 000000000..bbdd03c14 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/FWZoneDictGridController.js @@ -0,0 +1,148 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +app.controller('zoneDictGridController', function ($scope, FWDictionaryService,modalService, $modal, PapUrlService){ + $( "#dialog" ).hide(); + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + + FWDictionaryService.getZoneDictionaryData(papUrl).then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.zoneDictionaryDatas = JSON.parse($scope.data.zoneDictionaryDatas); + console.log($scope.zoneDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + + }); + + + $scope.zoneDictionaryGrid = { + data : 'zoneDictionaryDatas', + enableFiltering: true, + exporterCsvFilename: 'Zone.csv', + enableGridMenu: true, + enableSelectAll: true, + columnDefs: [{ + field: 'id', enableFiltering: false, headerCellTemplate: '' + + '', + cellTemplate: + ' ' + + ' ', width: '8%' + },{ field: 'zoneName', displayName : 'Zone Name'}, + { field: 'zoneValue', displayName : 'Zone Value' } + ], + exporterPdfDefaultStyle: {fontSize: 9}, + exporterPdfTableStyle: {margin: [30, 30, 30, 30]}, + exporterPdfTableHeaderStyle: {fontSize: 10, bold: true, italics: true, color: 'red'}, + exporterPdfHeader: { text: "My Header", style: 'headerStyle' }, + exporterPdfFooter: function ( currentPage, pageCount ) { + return { text: currentPage.toString() + ' of ' + pageCount.toString(), style: 'footerStyle' }; + }, + exporterPdfCustomFormatter: function ( docDefinition ) { + docDefinition.styles.headerStyle = { fontSize: 22, bold: true }; + docDefinition.styles.footerStyle = { fontSize: 10, bold: true }; + return docDefinition; + }, + exporterPdfOrientation: 'portrait', + exporterPdfPageSize: 'LETTER', + exporterPdfMaxGridWidth: 500, + exporterCsvLinkElement: angular.element(document.querySelectorAll(".custom-csv-link-location")), + onRegisterApi: function(gridApi){ + $scope.gridApi = gridApi; + } + }; + + $scope.editZoneName = null; + $scope.createNewFWZoneWindow = function(){ + $scope.editZoneName = null; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_FWZone_popup.html', + controller: 'editFWZoneController', + resolve: { + message: function () { + var message = { + zoneDictionaryDatas: $scope.editZoneName + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.zoneDictionaryDatas=response.zoneDictionaryDatas; + }); + }; + + $scope.editFWZoneWindow = function(zoneDictionaryData) { + $scope.editZoneName = zoneDictionaryData; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_FWZone_popup.html', + controller: 'editFWZoneController', + resolve: { + message: function () { + var message = { + zoneDictionaryData: $scope.editZoneName + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.zoneDictionaryDatas = response.zoneDictionaryDatas; + }); + }; + + $scope.deleteFWZone = function(data) { + modalService.popupConfirmWin("Confirm","You are about to delete the Zone Name "+data.zoneName+". Do you want to continue?", + function(){ + var uuu = papUrl + "/ecomp/fw_dictionary/remove_zone.htm"; + var postData={data: data}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){$scope.zoneDictionaryDatas=data.zoneDictionaryDatas;}); + }, + error : function(data){ + console.log(data); + modalService.showFailure("Fail","Error while deleting: "+ data.responseText); + } + }); + + }) + }; + + +}); \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/MSConfigNameDictGridController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/MSConfigNameDictGridController.js new file mode 100644 index 000000000..15a296799 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/MSConfigNameDictGridController.js @@ -0,0 +1,124 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +app.controller('msConfigNameDictGridController', function ($scope, MSDictionaryService,modalService, $modal, PapUrlService){ + $( "#dialog" ).hide(); + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + + MSDictionaryService.getMSConfigNameDictionaryData(papUrl).then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.microServiceCongigNameDictionaryDatas = JSON.parse($scope.data.microServiceCongigNameDictionaryDatas); + console.log($scope.microServiceCongigNameDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + + }); + + + $scope.msConfigNameDictionaryGrid = { + data : 'microServiceCongigNameDictionaryDatas', + enableFiltering: true, + columnDefs: [{ + field: 'id', enableFiltering: false, headerCellTemplate: '' + + '', + cellTemplate: + ' ' + + ' ', width: '8%' + },{ field: 'name', displayName : 'Name'}, + { field: 'descriptionValue', displayName : 'Description' } + ] + }; + + $scope.editMSConfig = null; + $scope.createNewMSConfigNameWindow = function(){ + $scope.editMSConfig = null; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_msConfigName_popup.html', + controller: 'editMSConfigController', + resolve: { + message: function () { + var message = { + microServiceCongigNameDictionaryDatas: $scope.editMSConfig + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.microServiceCongigNameDictionaryDatas=response.microServiceCongigNameDictionaryDatas; + }); + }; + + $scope.editMSConfigNameWindow = function(microServiceCongigNameDictionaryData) { + $scope.editMSConfig = microServiceCongigNameDictionaryData; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_msConfigName_popup.html', + controller: 'editMSConfigController', + resolve: { + message: function () { + var message = { + microServiceCongigNameDictionaryData: $scope.editMSConfig + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.microServiceCongigNameDictionaryDatas = response.microServiceCongigNameDictionaryDatas; + }); + }; + + $scope.deleteMSConfigName = function(data) { + modalService.popupConfirmWin("Confirm","You are about to delete the Micro Service Config Name "+data.name+". Do you want to continue?", + function(){ + var uuu = papUrl + "/ecomp/ms_dictionary/remove_msConfigName.htm"; + var postData={data: data}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){$scope.microServiceCongigNameDictionaryDatas=data.microServiceCongigNameDictionaryDatas;}); + }, + error : function(data){ + console.log(data); + modalService.showFailure("Fail","Error while deleting: "+ data.responseText); + } + }); + + }) + }; +}); \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/MSDcaeUUIDDictGridController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/MSDcaeUUIDDictGridController.js new file mode 100644 index 000000000..731731ff3 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/MSDcaeUUIDDictGridController.js @@ -0,0 +1,124 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +app.controller('msDCAEUUIDDictGridController', function ($scope, MSDictionaryService,modalService, $modal, PapUrlService){ + $( "#dialog" ).hide(); + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + + MSDictionaryService.getDCAEUUIDDictionaryData(papUrl).then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.dcaeUUIDDictionaryDatas = JSON.parse($scope.data.dcaeUUIDDictionaryDatas); + console.log($scope.dcaeUUIDDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + + }); + + $scope.dcaeUUIDDictionaryGrid = { + data : 'dcaeUUIDDictionaryDatas', + enableFiltering: true, + columnDefs: [{ + field: 'id', enableFiltering: false, headerCellTemplate: '' + + '', + cellTemplate: + ' ' + + ' ', width: '8%' + },{ field: 'name', displayName : 'Name'}, + { field: 'description' } + ] + }; + + $scope.editDCAEuuid = null; + $scope.createNewMSDCAEUUIDWindow = function(){ + $scope.editDCAEuuid = null; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_DCAEuuid_popup.html', + controller: 'editDCAEuuidController', + resolve: { + message: function () { + var message = { + dcaeUUIDDictionaryDatas: $scope.editDCAEuuid + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.dcaeUUIDDictionaryDatas=response.dcaeUUIDDictionaryDatas; + }); + }; + + $scope.editMSDCAEUUIDWindow = function(dcaeUUIDDictionaryData) { + $scope.editDCAEuuid = dcaeUUIDDictionaryData; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_DCAEuuid_popup.html', + controller: 'editDCAEuuidController', + resolve: { + message: function () { + var message = { + dcaeUUIDDictionaryData: $scope.editDCAEuuid + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.dcaeUUIDDictionaryDatas = response.dcaeUUIDDictionaryDatas; + }); + }; + + $scope.deleteMSDCAEUUID = function(data) { + modalService.popupConfirmWin("Confirm","You are about to delete the DCAE UUID : "+data.name+". Do you want to continue?", + function(){ + var uuu = papUrl + "/ecomp/ms_dictionary/remove_dcaeuuid.htm"; + var postData={data: data}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){$scope.dcaeUUIDDictionaryDatas=data.dcaeUUIDDictionaryDatas;}); + }, + error : function(data){ + console.log(data); + modalService.showFailure("Fail","Error while deleting: "+ data.responseText); + } + }); + + }) + }; + +}); \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/MSLocationDictGridController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/MSLocationDictGridController.js new file mode 100644 index 000000000..e3d7b1ab7 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/MSLocationDictGridController.js @@ -0,0 +1,124 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +app.controller('msLocationDictGridController', function ($scope, MSDictionaryService,modalService, $modal, PapUrlService){ + $( "#dialog" ).hide(); + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + + MSDictionaryService.getMSLocationDictionaryData(papUrl).then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.microServiceLocationDictionaryDatas = JSON.parse($scope.data.microServiceLocationDictionaryDatas); + console.log($scope.microServiceLocationDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + + }); + + $scope.msLocationDictionaryGrid = { + data : 'microServiceLocationDictionaryDatas', + enableFiltering: true, + columnDefs: [{ + field: 'id', enableFiltering: false, headerCellTemplate: '' + + '', + cellTemplate: + ' ' + + ' ', width: '8%' + },{ field: 'name', displayName : 'Name'}, + { field: 'descriptionValue', displayName : 'Description' } + ] + }; + + $scope.editMSLocation = null; + $scope.createNewMSLocationWindow = function(){ + $scope.editMSLocation = null; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_msLocation_popup.html', + controller: 'editMSLocationController', + resolve: { + message: function () { + var message = { + microServiceLocationDictionaryDatas: $scope.editMSLocation + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.microServiceLocationDictionaryDatas=response.microServiceLocationDictionaryDatas; + }); + }; + + $scope.editMSLocationWindow = function(microServiceLocationDictionaryData) { + $scope.editMSLocation = microServiceLocationDictionaryData; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_msLocation_popup.html', + controller: 'editMSLocationController', + resolve: { + message: function () { + var message = { + microServiceLocationDictionaryData: $scope.editMSLocation + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.microServiceLocationDictionaryDatas = response.microServiceLocationDictionaryDatas; + }); + }; + + $scope.deleteMSLocation = function(data) { + modalService.popupConfirmWin("Confirm","You are about to delete the Micro Service Location "+data.name+". Do you want to continue?", + function(){ + var uuu = papUrl + "/ecomp/ms_dictionary/remove_msLocation.htm"; + var postData={data: data}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){$scope.microServiceLocationDictionaryDatas=data.microServiceLocationDictionaryDatas;}); + }, + error : function(data){ + console.log(data); + modalService.showFailure("Fail","Error while deleting: "+ data.responseText); + } + }); + + }) + }; + +}); \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/MSModelDictGridController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/MSModelDictGridController.js new file mode 100644 index 000000000..4556a8296 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/MSModelDictGridController.js @@ -0,0 +1,124 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +app.controller('msModelsDictGridController', function ($scope, MSDictionaryService,modalService, $modal, PapUrlService){ + $( "#dialog" ).hide(); + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + + MSDictionaryService.getMSModelDictionaryData(papUrl).then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.microServiceModelsDictionaryDatas = JSON.parse($scope.data.microServiceModelsDictionaryDatas); + console.log($scope.microServiceModelsDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + + }); + + $scope.msModelsDictionaryGrid = { + data : 'microServiceModelsDictionaryDatas', + enableFiltering: true, + columnDefs: [{ + field: 'id', enableFiltering: false, headerCellTemplate: '' + + '', + cellTemplate: + ' ', width: '8%' + },{ field: 'modelName', displayName : 'Micro Service Model'}, + { field: 'description' }, + { field: 'version', displayName : 'Model Version' }, + {field: 'userCreatedBy.userName', displayName : 'Imported By' } + ] + }; + $scope.editMSmodelName = null; + $scope.createNewMSModelsWindow = function(){ + $scope.editMSmodelName = null; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_msModel_popup.html', + controller: 'editMSModelController', + resolve: { + message: function () { + var message = { + microServiceModelsDictionaryDatas: $scope.editMSmodelName + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.microServiceModelsDictionaryDatas=response.microServiceModelsDictionaryDatas; + }); + }; + + $scope.editMSModelsWindow = function(microServiceModelsDictionaryData) { + $scope.editMSmodelName = microServiceModelsDictionaryData; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_msModel_popup.html', + controller: 'editMSModelController', + resolve: { + message: function () { + var message = { + microServiceModelsDictionaryData: $scope.editMSmodelName + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.microServiceModelsDictionaryDatas = response.microServiceModelsDictionaryDatas; + }); + }; + + $scope.deleteMSModels = function(data) { + modalService.popupConfirmWin("Confirm","You are about to delete the MicroService Model : "+data.modelName+". Do you want to continue?", + function(){ + var uuu = papUrl + "/ecomp/ms_dictionary/remove_msModel.htm"; + var postData={data: data}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){$scope.microServiceModelsDictionaryDatas=data.microServiceModelsDictionaryDatas;}); + }, + error : function(data){ + console.log(data); + modalService.showFailure("Fail","Error while deleting: "+ data.responseText); + } + }); + + }) + }; + +}); \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/PSClosedLoopDictGridController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/PSClosedLoopDictGridController.js new file mode 100644 index 000000000..ba64bc8e1 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/PSClosedLoopDictGridController.js @@ -0,0 +1,123 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +app.controller('psClosedLoopDictGridController', function ($scope, PolicyScopeService,modalService, $modal, PapUrlService){ + $( "#dialog" ).hide(); + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + + PolicyScopeService.getPSClosedLoopDictionaryData(papUrl).then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.psClosedLoopDictionaryDatas = JSON.parse($scope.data.psClosedLoopDictionaryDatas); + console.log($scope.psClosedLoopDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + + }); + + $scope.psClosedLoopDictionaryGrid = { + data : 'psClosedLoopDictionaryDatas', + enableFiltering: true, + columnDefs: [{ + field: 'id', enableFiltering: false, headerCellTemplate: '' + + '', + cellTemplate: + ' ' + + ' ', width: '8%' + },{ field: 'name', displayName : 'Closed Loop Name'}, + { field: 'descriptionValue' , displayName : 'Description'} + ] + }; + + $scope.editPSClosedLoop = null; + $scope.createNewPSClosedLoopWindow = function(){ + $scope.editPSClosedLoop = null; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_PSClosedLoop_popup.html', + controller: 'editPSClosedLoopController', + resolve: { + message: function () { + var message = { + psClosedLoopDictionaryDatas: $scope.editPSClosedLoop + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.psClosedLoopDictionaryDatas=response.psClosedLoopDictionaryDatas; + }); + }; + + $scope.editPSClosedLoopWindow = function(psClosedLoopDictionaryData) { + $scope.editPSClosedLoop = psClosedLoopDictionaryData; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_PSClosedLoop_popup.html', + controller: 'editPSClosedLoopController', + resolve: { + message: function () { + var message = { + psClosedLoopDictionaryData: $scope.editPSClosedLoop + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.psClosedLoopDictionaryDatas = response.psClosedLoopDictionaryDatas; + }); + }; + + $scope.deletePSClosedLoop = function(data) { + modalService.popupConfirmWin("Confirm","You are about to delete the Closed Loop "+data.name+". Do you want to continue?", + function(){ + var uuu = papUrl + "/ecomp/ps_dictionary/remove_PSClosedLoop.htm"; + var postData={data: data}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){$scope.psClosedLoopDictionaryDatas=data.psClosedLoopDictionaryDatas;}); + }, + error : function(data){ + console.log(data); + modalService.showFailure("Fail","Error while deleting: "+ data.responseText); + } + }); + + }) + }; +}); \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/PSGroupPolicyScopeDictGridController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/PSGroupPolicyScopeDictGridController.js new file mode 100644 index 000000000..756be7661 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/PSGroupPolicyScopeDictGridController.js @@ -0,0 +1,127 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +app.controller('psGroupPolicyScopeDictGridController', function ($scope, PolicyScopeService,modalService, $modal, PapUrlService){ + $( "#dialog" ).hide(); + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + + PolicyScopeService.getPSGroupPolicyScopeDictionaryData(papUrl).then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.groupPolicyScopeListDatas = JSON.parse($scope.data.groupPolicyScopeListDatas); + console.log($scope.groupPolicyScopeListDatas); + }, function (error) { + console.log("failed"); + }); + + }); + + $scope.psGroupPolicyScopeDictionaryGrid = { + data : 'groupPolicyScopeListDatas', + enableFiltering: true, + columnDefs: [{ + field: 'id', enableFiltering: false, headerCellTemplate: '' + + '', + cellTemplate: + ' ' + + ' ', width: '8%' + },{ field: 'groupName', displayName : 'Policy Scope Group Name'}, + { field: 'groupList', displayName : 'Policy Scope List'} + ], + onRegisterApi: function(gridApi){ + $scope.gridApi = gridApi; + $scope.gridApi.core.refresh(); + } + }; + + $scope.editPSGroupPolicyScope = null; + $scope.createNewGroupPolicyScopeWindow = function(){ + $scope.editPSGroupPolicyScope = null; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_PSGroupPolicyScope_popup.html', + controller: 'editPSGroupPolicyScopeController', + resolve: { + message: function () { + var message = { + groupPolicyScopeListDatas: $scope.editPSGroupPolicyScope + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.groupPolicyScopeListDatas=response.groupPolicyScopeListDatas; + }); + }; + + $scope.editGroupPolicyScopeWindow = function(groupPolicyScopeListData) { + $scope.editPSGroupPolicyScope = groupPolicyScopeListData; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_PSGroupPolicyScope_popup.html', + controller: 'editPSGroupPolicyScopeController', + resolve: { + message: function () { + var message = { + groupPolicyScopeListData: $scope.editPSGroupPolicyScope + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.groupPolicyScopeListDatas = response.groupPolicyScopeListDatas; + }); + }; + + $scope.deleteGroupPolicyScope = function(data) { + modalService.popupConfirmWin("Confirm","You are about to delete the Group Policy Scope "+data.name+". Do you want to continue?", + function(){ + var uuu = papUrl + "/ecomp/ps_dictionary/remove_GroupPolicyScope.htm"; + var postData={data: data}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){$scope.groupPolicyScopeListDatas=data.groupPolicyScopeListDatas;}); + }, + error : function(data){ + console.log(data); + modalService.showFailure("Fail","Error while deleting: "+ data.responseText); + } + }); + + }) + }; +}); \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/PSResourceDictGridController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/PSResourceDictGridController.js new file mode 100644 index 000000000..e4ad05263 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/PSResourceDictGridController.js @@ -0,0 +1,123 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +app.controller('psResourceDictGridController', function ($scope, PolicyScopeService,modalService, $modal, PapUrlService){ + $( "#dialog" ).hide(); + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + + PolicyScopeService.getPSResourceDictionaryData(papUrl).then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.psResourceDictionaryDatas = JSON.parse($scope.data.psResourceDictionaryDatas); + console.log($scope.psResourceDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + + }); + + $scope.psResourceDictionaryGrid = { + data : 'psResourceDictionaryDatas', + enableFiltering: true, + columnDefs: [{ + field: 'id', enableFiltering: false, headerCellTemplate: '' + + '', + cellTemplate: + ' ' + + ' ', width: '8%' + },{ field: 'name', displayName : 'Resource Name'}, + { field: 'descriptionValue' } + ] + }; + + $scope.editPSResource = null; + $scope.createNewPSResourceWindow = function(){ + $scope.editPSResource = null; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_PSResource_popup.html', + controller: 'editPSResourceController', + resolve: { + message: function () { + var message = { + psResourceDictionaryDatas: $scope.editPSResource + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.psResourceDictionaryDatas=response.psResourceDictionaryDatas; + }); + }; + + $scope.editPSResourceWindow = function(psResourceDictionaryData) { + $scope.editPSResource = psResourceDictionaryData; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_PSResource_popup.html', + controller: 'editPSResourceController', + resolve: { + message: function () { + var message = { + psResourceDictionaryData: $scope.editPSResource + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.psResourceDictionaryDatas = response.psResourceDictionaryDatas; + }); + }; + + $scope.deletePSResource = function(data) { + modalService.popupConfirmWin("Confirm","You are about to delete the Resource "+data.name+". Do you want to continue?", + function(){ + var uuu = papUrl + "/ecomp/ps_dictionary/remove_PSResource.htm"; + var postData={data: data}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){$scope.psResourceDictionaryDatas=data.psResourceDictionaryDatas;}); + }, + error : function(data){ + console.log(data); + modalService.showFailure("Fail","Error while deleting: "+ data.responseText); + } + }); + + }) + }; +}); \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/PSServiceDictGridController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/PSServiceDictGridController.js new file mode 100644 index 000000000..ac16a3eb2 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/PSServiceDictGridController.js @@ -0,0 +1,122 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +app.controller('psServiceDictGridController', function ($scope, PolicyScopeService,modalService, $modal, PapUrlService){ + $( "#dialog" ).hide(); + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + + PolicyScopeService.getPSServiceDictionaryData(papUrl).then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.psServiceDictionaryDatas = JSON.parse($scope.data.psServiceDictionaryDatas); + console.log($scope.psServiceDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + }); + + $scope.psServiceDictionaryGrid = { + data : 'psServiceDictionaryDatas', + enableFiltering: true, + columnDefs: [{ + field: 'id', enableFiltering: false, headerCellTemplate: '' + + '', + cellTemplate: + ' ' + + ' ', width: '8%' + },{ field: 'name', displayName : 'Service Name'}, + { field: 'descriptionValue' } + ] + }; + + $scope.editPSService = null; + $scope.createNewPSServiceWindow = function(){ + $scope.editPSService = null; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_PSService_popup.html', + controller: 'editPSServiceController', + resolve: { + message: function () { + var message = { + psServiceDictionaryDatas: $scope.editPSService + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.psServiceDictionaryDatas=response.psServiceDictionaryDatas; + }); + }; + + $scope.editPSServiceWindow = function(psServiceDictionaryData) { + $scope.editPSService = psServiceDictionaryData; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_PSService_popup.html', + controller: 'editPSServiceController', + resolve: { + message: function () { + var message = { + psServiceDictionaryData: $scope.editPSService + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.psServiceDictionaryDatas = response.psServiceDictionaryDatas; + }); + }; + + $scope.deletePSService = function(data) { + modalService.popupConfirmWin("Confirm","You are about to delete the Port List "+data.name+". Do you want to continue?", + function(){ + var uuu = papUrl + "/ecomp/ps_dictionary/remove_PSService.htm"; + var postData={data: data}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){$scope.psServiceDictionaryDatas=data.psServiceDictionaryDatas;}); + }, + error : function(data){ + console.log(data); + modalService.showFailure("Fail","Error while deleting: "+ data.responseText); + } + }); + + }) + }; +}); \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/PSTypeDictGridController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/PSTypeDictGridController.js new file mode 100644 index 000000000..e66b58931 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/PSTypeDictGridController.js @@ -0,0 +1,122 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +app.controller('psTypeDictGridController', function ($scope, PolicyScopeService,modalService, $modal, PapUrlService){ + $( "#dialog" ).hide(); + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + + PolicyScopeService.getPSTypeDictionaryData(papUrl).then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.psTypeDictionaryDatas = JSON.parse($scope.data.psTypeDictionaryDatas); + console.log($scope.psTypeDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + }); + + $scope.psTypeDictionaryGrid = { + data : 'psTypeDictionaryDatas', + enableFiltering: true, + columnDefs: [{ + field: 'id', enableFiltering: false, headerCellTemplate: '' + + '', + cellTemplate: + ' ' + + ' ', width: '8%' + },{ field: 'name', displayName : 'Type Name'}, + { field: 'descriptionValue' } + ] + }; + + $scope.editPSType = null; + $scope.createPSTypeWindow = function(){ + $scope.editPSType = null; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_PSType_popup.html', + controller: 'editPSTypeController', + resolve: { + message: function () { + var message = { + psTypeDictionaryDatas: $scope.editPSType + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.psTypeDictionaryDatas=response.psTypeDictionaryDatas; + }); + }; + + $scope.editPSTypeWindow = function(psTypeDictionaryData) { + $scope.editPSType = psTypeDictionaryData; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_PSType_popup.html', + controller: 'editPSTypeController', + resolve: { + message: function () { + var message = { + psTypeDictionaryData: $scope.editPSType + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.psTypeDictionaryDatas = response.psTypeDictionaryDatas; + }); + }; + + $scope.deletePSType = function(data) { + modalService.popupConfirmWin("Confirm","You are about to delete the Type "+data.name+". Do you want to continue?", + function(){ + var uuu = papUrl + "/ecomp/ps_dictionary/remove_PSType.htm"; + var postData={data: data}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){$scope.psTypeDictionaryDatas=data.psTypeDictionaryDatas;}); + }, + error : function(data){ + console.log(data); + modalService.showFailure("Fail","Error while deleting: "+ data.responseText); + } + }); + + }) + }; +}); \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/RiskTypeDictGridController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/RiskTypeDictGridController.js new file mode 100644 index 000000000..d22a1ce48 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/RiskTypeDictGridController.js @@ -0,0 +1,152 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +app.controller('riskTypeDictGridController', function ($scope, SafePolicyService,modalService,PapUrlService, $modal, uiGridConstants,Grid){ + $( "#dialog" ).hide(); + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + + SafePolicyService.getRiskTypeDictionaryData(papUrl).then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.riskTypeDictionaryDatas = JSON.parse($scope.data.riskTypeDictionaryDatas); + console.log($scope.riskTypeDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + }); + + $scope.riskTypeDictionaryGrid = { + data : 'riskTypeDictionaryDatas', + enableFiltering: true, + exporterCsvFilename: 'RiskType.csv', + enableGridMenu: true, + enableSelectAll: true, + columnDefs: [{ + field: 'id', enableFiltering: false, headerCellTemplate: '' + + '', + cellTemplate: + ' ' + + ' ', width: '8%' + }, + { field: 'riskName', displayName : 'Risk Type Name' }, + { field: 'description', width: '20%' }, + {field: 'userCreatedBy.userName', displayName : 'Created By'}, + {field: 'userModifiedBy.userName', displayName : 'Modified By' }, + {field: 'createdDate',type: 'date', cellFilter: 'date:\'yyyy-MM-dd\''}, + {field: 'modifiedDate',type: 'date', cellFilter: 'date:\'yyyy-MM-dd\''} + ], + enableColumnResize : true, + exporterPdfDefaultStyle: {fontSize: 9}, + exporterPdfTableStyle: {margin: [30, 30, 30, 30]}, + exporterPdfTableHeaderStyle: {fontSize: 10, bold: true, italics: true, color: 'red'}, + exporterPdfHeader: { text: "My Header", style: 'headerStyle' }, + exporterPdfFooter: function ( currentPage, pageCount ) { + return { text: currentPage.toString() + ' of ' + pageCount.toString(), style: 'footerStyle' }; + }, + exporterPdfCustomFormatter: function ( docDefinition ) { + docDefinition.styles.headerStyle = { fontSize: 22, bold: true }; + docDefinition.styles.footerStyle = { fontSize: 10, bold: true }; + return docDefinition; + }, + exporterPdfOrientation: 'portrait', + exporterPdfPageSize: 'LETTER', + exporterPdfMaxGridWidth: 500, + exporterCsvLinkElement: angular.element(document.querySelectorAll(".custom-csv-link-location")), + onRegisterApi: function(gridApi){ + $scope.gridApi = gridApi; + } + }; + + + $scope.editRiskType = null; + $scope.createNewRiskType = function(){ + $scope.editRiskType = null; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_riskType_popup.html', + controller: 'editRiskTypeController', + resolve: { + message: function () { + var message = { + riskTypeDictionaryDatas: $scope.editRiskType + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.riskTypeDictionaryDatas=response.riskTypeDictionaryDatas; + }); + }; + + $scope.editRiskTypeWindow = function(riskTypeDictionaryData) { + $scope.editRiskType = riskTypeDictionaryData; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_riskType_popup.html', + controller: 'editRiskTypeController', + resolve: { + message: function () { + var message = { + riskTypeDictionaryData: $scope.editRiskType + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.riskTypeDictionaryDatas = response.riskTypeDictionaryData; + }); + }; + + $scope.deleteRiskType = function(data) { + modalService.popupConfirmWin("Confirm","You are about to delete the Ecomp Name "+data.riskType+". Do you want to continue?", + function(){ + var uuu = papUrl + "/ecomp/sp_dictionary/remove_riskType.htm"; + var postData={data: data}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){$scope.riskTypeDictionaryDatas=data.riskTypeDictionaryDatas;}); + }, + error : function(data){ + console.log(data); + modalService.showFailure("Fail","Error while deleting: "+ data.responseText); + } + }); + + }) + }; + +}); \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/SafePolicyWarningDictGridController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/SafePolicyWarningDictGridController.js new file mode 100644 index 000000000..303ae5704 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/SafePolicyWarningDictGridController.js @@ -0,0 +1,127 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +app.controller('safePolicyWarningDictGridController', function ($scope, SafePolicyService,modalService, $modal, PapUrlService){ + $( "#dialog" ).hide(); + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + + SafePolicyService.getSafePolicyWarningDictionaryData(papUrl).then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.safePolicyWarningDatas = JSON.parse($scope.data.safePolicyWarningDatas); + console.log($scope.safePolicyWarningDatas); + }, function (error) { + console.log("failed"); + }); + + }); + + $scope.safePolicyWarningDictionaryGrid = { + data : 'safePolicyWarningDatas', + enableFiltering: true, + columnDefs: [{ + field: 'id', enableFiltering: false, headerCellTemplate: '' + + '', + cellTemplate: + ' ' + + ' ', width: '8%' + },{ field: 'name', displayName : 'Safe Policy Warning Name'}, + { field: 'riskType', displayName : 'Risk Type'},{ field: 'message', displayName : 'Message'} + ], + onRegisterApi: function(gridApi){ + $scope.gridApi = gridApi; + $scope.gridApi.core.refresh(); + } + }; + + $scope.editSafePolicyWarning = null; + $scope.createNewSafePolicyWarningWindow = function(){ + $scope.editSafePolicyWarning = null; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_SafePolicyWarning_popup.html', + controller: 'editSafePolicyWarningController', + resolve: { + message: function () { + var message = { + safePolicyWarningDatas: $scope.editSafePolicyWarningScope + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.safePolicyWarningDatas=response.safePolicyWarningDatas; + }); + }; + + $scope.editSafePolicyWarningWindow = function(safePolicyWarningData) { + $scope.editSafePolicyWarning = safePolicyWarningData; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_SafePolicyWarning_popup.html', + controller: 'editSafePolicyWarningController', + resolve: { + message: function () { + var message = { + safePolicyWarningData: $scope.editSafePolicyWarning + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.groupPolicyScopeListDatas = response.safePolicyWarningData; + }); + }; + + $scope.deleteSafePolicyWarning = function(data) { + modalService.popupConfirmWin("Confirm","You are about to delete the Safe Policy Warning "+data.name+". Do you want to continue?", + function(){ + var uuu = papUrl + "/ecomp/sp_dictionary/remove_SafePolicyWarning.htm"; + var postData={data: data}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){$scope.safePolicyWarningDatas=data.safePolicyWarningDatas;}); + }, + error : function(data){ + console.log(data); + modalService.showFailure("Fail","Error while deleting: "+ data.responseText); + } + }); + + }) + }; +}); \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/actionPolicyDictGridController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/actionPolicyDictGridController.js new file mode 100644 index 000000000..223aec6cf --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/actionPolicyDictGridController.js @@ -0,0 +1,161 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +var Actiontype = ["REST"]; +app.controller('actionPolicyDictGridController', function ($scope, DictionaryService,modalService, $modal, uiGridConstants,Grid, PapUrlService){ + $( "#dialog" ).hide(); + $scope.type = Actiontype; + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + + DictionaryService.getActionPolicyDictionaryData(papUrl).then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.actionPolicyDictionaryDatas = JSON.parse($scope.data.actionPolicyDictionaryDatas); + console.log($scope.actionPolicyDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + + }); + + $scope.actionPolicyDictionaryGrid = { + enableFiltering: true, + data: 'actionPolicyDictionaryDatas', + exporterCsvFilename: 'ActionPolicyDictionary.csv', + enableGridMenu: true, + enableSelectAll: true, + columnDefs: [{ + field: 'id', + enableFiltering: false, + headerCellTemplate: '' + + '', + cellTemplate: ' ' + + ' ', + width: '8%' + }, + {field: 'attributeName', displayName: 'Attribute Name'}, + {field: 'type'}, + {field: 'url'}, + {field: 'method'}, + {field: 'header', displayName: 'Headers'}, + {field: 'description'}, + {field: 'userCreatedBy.userName', displayName: 'Created By'}, + {field: 'userModifiedBy.userName', displayName: 'Modified By'}, + {field: 'createdDate', type: 'date', cellFilter: 'date:\'yyyy-MM-dd\''}, + {field: 'modifiedDate', type: 'date', cellFilter: 'date:\'yyyy-MM-dd\''} + ], + exporterPdfDefaultStyle: {fontSize: 9}, + exporterPdfTableStyle: {margin: [30, 30, 30, 30]}, + exporterPdfTableHeaderStyle: {fontSize: 10, bold: true, italics: true, color: 'red'}, + exporterPdfHeader: { text: "My Header", style: 'headerStyle' }, + exporterPdfFooter: function ( currentPage, pageCount ) { + return { text: currentPage.toString() + ' of ' + pageCount.toString(), style: 'footerStyle' }; + }, + exporterPdfCustomFormatter: function ( docDefinition ) { + docDefinition.styles.headerStyle = { fontSize: 22, bold: true }; + docDefinition.styles.footerStyle = { fontSize: 10, bold: true }; + return docDefinition; + }, + exporterPdfOrientation: 'portrait', + exporterPdfPageSize: 'LETTER', + exporterPdfMaxGridWidth: 500, + exporterCsvLinkElement: angular.element(document.querySelectorAll(".custom-csv-link-location")), + onRegisterApi: function(gridApi){ + $scope.gridApi = gridApi; + } + }; + + + $scope.editActionPolicyName = null; + $scope.createNewActionPolicyDictWindow = function () { + $scope.editActionPolicyName = null; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl: 'add_actionPolicyDict_popup.html', + controller: 'editActionPolicyDictController', + resolve: { + message: function () { + var message = { + actionPolicyDictionaryDatas: $scope.editActionPolicyName + }; + return message; + } + } + }); + modalInstance.result.then(function (response) { + console.log('response', response); + $scope.actionPolicyDictionaryDatas = response.actionPolicyDictionaryDatas; + }); + }; + + $scope.editActionPolicyDictWindow = function (actionPolicyDictionaryData) { + $scope.editActionPolicyName = actionPolicyDictionaryData; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl: 'add_actionPolicyDict_popup.html', + controller: 'editActionPolicyDictController', + resolve: { + message: function () { + var message = { + actionPolicyDictionaryData: $scope.editActionPolicyName + }; + return message; + } + } + }); + modalInstance.result.then(function (response) { + console.log('response', response); + $scope.actionPolicyDictionaryDatas = response.actionPolicyDictionaryDatas; + }); + }; + + $scope.deleteActionPolicyDict = function (data) { + modalService.popupConfirmWin("Confirm", "You are about to delete the Action Policy Dictionary Item " + data.attributeName + ". Do you want to continue?", + function () { + var uuu = papUrl + "/ecomp/action_dictionary/remove_actionPolicyDict.htm"; + var postData = {data: data}; + $.ajax({ + type: 'POST', + url: uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success: function (data) { + $scope.$apply(function () { + $scope.actionPolicyDictionaryDatas = data.actionPolicyDictionaryDatas; + }); + }, + error: function (data) { + console.log(data); + modalService.showFailure("Fail", "Error while deleting: " + data.responseText); + } + }); + + }) + }; +}); \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/attributeDictGridController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/attributeDictGridController.js new file mode 100644 index 000000000..5405bb0d7 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/attributeDictGridController.js @@ -0,0 +1,159 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +app.controller('attributeDictGridController', function ($scope, DictionaryService, PapUrlService, modalService, $modal){ + $( "#dialog" ).hide(); + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + DictionaryService.getAttributeDictionaryData(papUrl).then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.attributeDictionaryDatas = JSON.parse($scope.data.attributeDictionaryDatas); + console.log($scope.attributeDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + }); + + $scope.exportData = function () { + var blob = new Blob([document.getElementById('attributeTable').innerHTML], { + type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8" + }); + saveAs(blob, "Attribute.xls"); + }; + + $scope.attributeDictionaryGrid = { + data : 'attributeDictionaryDatas', + enableFiltering: true, + exporterCsvFilename: 'Attribute.csv', + enableGridMenu: true, + enableSelectAll: true, + columnDefs: [{ + field: 'id' , enableFiltering: false, headerCellTemplate: '' + + '', + cellTemplate: + ' ' + + ' ', width: '8%' + },{ field: 'xacmlId', displayName : 'Attribute ID'}, + { field: 'datatypeBean.shortName', displayName : 'Data Type' }, + { field: 'attributeValue'}, + { field: 'description' }, + { field: 'priority' , displayName : 'Priority'}, + {field: 'userCreatedBy.userName', displayName : 'Created By' }, + {field: 'userModifiedBy.userName', displayName : 'Modified By'}, + {field: 'createdDate',type: 'date', cellFilter: 'date:\'yyyy-MM-dd\'' }, + {field: 'modifiedDate',type: 'date', cellFilter: 'date:\'yyyy-MM-dd\'' } + ], + exporterPdfDefaultStyle: {fontSize: 9}, + exporterPdfTableStyle: {margin: [30, 30, 30, 30]}, + exporterPdfTableHeaderStyle: {fontSize: 10, bold: true, italics: true, color: 'red'}, + exporterPdfHeader: { text: "My Header", style: 'headerStyle' }, + exporterPdfFooter: function ( currentPage, pageCount ) { + return { text: currentPage.toString() + ' of ' + pageCount.toString(), style: 'footerStyle' }; + }, + exporterPdfCustomFormatter: function ( docDefinition ) { + docDefinition.styles.headerStyle = { fontSize: 22, bold: true }; + docDefinition.styles.footerStyle = { fontSize: 10, bold: true }; + return docDefinition; + }, + exporterPdfOrientation: 'portrait', + exporterPdfPageSize: 'LETTER', + exporterPdfMaxGridWidth: 500, + exporterCsvLinkElement: angular.element(document.querySelectorAll(".custom-csv-link-location")), + onRegisterApi: function(gridApi){ + $scope.gridApi = gridApi; + } + }; + + + $scope.editAttributeName = null; + $scope.createNewAttributeWindow = function(){ + $scope.editAttributeName = null; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_Attribute_popup.html', + controller: 'editAttributeController', + resolve: { + message: function () { + var message = { + attributeDictionaryDatas: $scope.editAttributeName + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.attributeDictionaryDatas=response.attributeDictionaryDatas; + }); + }; + + $scope.editAttributeWindow = function(attributeDictionaryData) { + $scope.editAttributeName = attributeDictionaryData; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_Attribute_popup.html', + controller: 'editAttributeController', + resolve: { + message: function () { + var message = { + attributeDictionaryData: $scope.editAttributeName + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.attributeDictionaryDatas = response.attributeDictionaryDatas; + }); + }; + + $scope.deleteAttribute = function(data) { + modalService.popupConfirmWin("Confirm","You are about to delete the Attribute Dictionary : "+data.xacmlId+". \n "+searchString+" \n Do you want to continue?", + function(){ + var uuu = papUrl + "/ecomp/attribute_dictionary/remove_attribute.htm"; + var postData={data: data}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){$scope.attributeDictionaryDatas=data.attributeDictionaryDatas;}); + }, + error : function(data){ + console.log(data); + modalService.showFailure("Fail","Error while deleting: "+ data.responseText); + } + }); + + }) + }; + + +}); \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/ecompNameDictGridController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/ecompNameDictGridController.js new file mode 100644 index 000000000..3ae3ee21d --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/dictionaryGridController/ecompNameDictGridController.js @@ -0,0 +1,152 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + */ +app.controller('ecompNameDictGridController', function ($scope, DictionaryService,modalService,PapUrlService, $modal, uiGridConstants,Grid){ + $( "#dialog" ).hide(); + + var papUrl; + PapUrlService.getPapUrl().then(function(data) { + var config = data; + papUrl = config.PAP_URL; + console.log(papUrl); + + DictionaryService.getEcompDictionaryData(papUrl).then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.ecompNameDictionaryDatas = JSON.parse($scope.data.ecompNameDictionaryDatas); + console.log($scope.ecompNameDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + }); + + $scope.ecompNameDictionaryGrid = { + data : 'ecompNameDictionaryDatas', + enableFiltering: true, + exporterCsvFilename: 'EcompName.csv', + enableGridMenu: true, + enableSelectAll: true, + columnDefs: [{ + field: 'id', enableFiltering: false, headerCellTemplate: '' + + '', + cellTemplate: + ' ' + + ' ', width: '8%' + }, + { field: 'ecompName', displayName : 'Ecomp Name' }, + { field: 'description', width: '20%' }, + {field: 'userCreatedBy.userName', displayName : 'Created By'}, + {field: 'userModifiedBy.userName', displayName : 'Modified By' }, + {field: 'createdDate',type: 'date', cellFilter: 'date:\'yyyy-MM-dd\''}, + {field: 'modifiedDate',type: 'date', cellFilter: 'date:\'yyyy-MM-dd\''} + ], + enableColumnResize : true, + exporterPdfDefaultStyle: {fontSize: 9}, + exporterPdfTableStyle: {margin: [30, 30, 30, 30]}, + exporterPdfTableHeaderStyle: {fontSize: 10, bold: true, italics: true, color: 'red'}, + exporterPdfHeader: { text: "My Header", style: 'headerStyle' }, + exporterPdfFooter: function ( currentPage, pageCount ) { + return { text: currentPage.toString() + ' of ' + pageCount.toString(), style: 'footerStyle' }; + }, + exporterPdfCustomFormatter: function ( docDefinition ) { + docDefinition.styles.headerStyle = { fontSize: 22, bold: true }; + docDefinition.styles.footerStyle = { fontSize: 10, bold: true }; + return docDefinition; + }, + exporterPdfOrientation: 'portrait', + exporterPdfPageSize: 'LETTER', + exporterPdfMaxGridWidth: 500, + exporterCsvLinkElement: angular.element(document.querySelectorAll(".custom-csv-link-location")), + onRegisterApi: function(gridApi){ + $scope.gridApi = gridApi; + } + }; + + + $scope.editEcompName = null; + $scope.createNewEcompName = function(){ + $scope.editEcompName = null; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_ecompName_popup.html', + controller: 'editEcompNameController', + resolve: { + message: function () { + var message = { + ecompNameDictionaryDatas: $scope.editEcompName + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.ecompNameDictionaryDatas=response.ecompNameDictionaryDatas; + }); + }; + + $scope.editEcompNameWindow = function(ecompNameDictionaryData) { + $scope.editEcompName = ecompNameDictionaryData; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_ecompName_popup.html', + controller: 'editEcompNameController', + resolve: { + message: function () { + var message = { + ecompNameDictionaryData: $scope.editEcompName + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.ecompNameDictionaryDatas = response.ecompNameDictionaryDatas; + }); + }; + + $scope.deleteEcompName = function(data) { + modalService.popupConfirmWin("Confirm","You are about to delete the Ecomp Name "+data.ecompName+". Do you want to continue?", + function(){ + var uuu = papUrl + "/ecomp/ecomp_dictionary/remove_ecomp.htm"; + var postData={data: data}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){$scope.ecompNameDictionaryDatas=data.ecompNameDictionaryDatas;}); + }, + error : function(data){ + console.log(data); + modalService.showFailure("Fail","Error while deleting: "+ data.responseText); + } + }); + + }) + }; + +}); \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/editorTabController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/editorTabController.js new file mode 100644 index 000000000..d9a6bbcc1 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/editorTabController.js @@ -0,0 +1,211 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/* +/!** + *!/ +(function(window, angular, $) { + 'use strict'; + app.controller('policyeditorTabController', [ + '$scope', '$translate', '$cookies', 'fileManagerConfig', 'item', 'fileNavigator', 'fileUploader', + function($scope, $translate, $cookies, fileManagerConfig, Item, FileNavigator, FileUploader) { + +/!*app.controller('policyeditorTabController', function ($scope, $translate, $cookies, fileManagerConfig, Item, FileNavigator, FileUploader){*!/ + $( "#dialog" ).hide(); + $scope.config = fileManagerConfig; + $scope.reverse = false; + $scope.predicate = ['model.type', 'model.name']; + $scope.order = function(predicate) { + $scope.reverse = ($scope.predicate[1] === predicate) ? !$scope.reverse : false; + $scope.predicate[1] = predicate; + }; + + $scope.query = ''; + $scope.temp = new Item(); + $scope.fileNavigator = new FileNavigator(); + $scope.fileUploader = FileUploader; + $scope.uploadFileList = []; + $scope.viewTemplate = $cookies.viewTemplate || 'main-table.html'; + + $scope.setTemplate = function(name) { + $scope.viewTemplate = $cookies.viewTemplate = name; + }; + + $scope.changeLanguage = function (locale) { + if (locale) { + return $translate.use($cookies.language = locale); + } + $translate.use($cookies.language || fileManagerConfig.defaultLang); + }; + + $scope.touch = function(item) { + item = item instanceof Item ? item : new Item(); + item.revert(); + $scope.temp = item; + }; + + $scope.smartClick = function(item) { + if (item.isFolder()) { + return $scope.fileNavigator.folderClick(item); + } + if (item.isImage()) { + return $scope.openImagePreview(item); + } + if (item.isEditable()) { + return $scope.openEditItem(item); + } + }; + + $scope.openImagePreview = function(item) { + item.inprocess = true; + $scope.modal('imagepreview') + .find('#imagepreview-target') + .attr('src', item.getUrl(true)) + .unbind('load error') + .on('load error', function() { + item.inprocess = false; + $scope.$apply(); + }); + return $scope.touch(item); + }; + + $scope.openEditItem = function(item) { + item.getContent(); + $scope.modal('edit'); + return $scope.touch(item); + }; + + $scope.modal = function(id, hide) { + return $('#' + id).modal(hide ? 'hide' : 'show'); + }; + + $scope.isInThisPath = function(path) { + var currentPath = $scope.fileNavigator.currentPath.join('/'); + return currentPath.indexOf(path) !== -1; + }; + + $scope.edit = function(item) { + item.edit().then(function() { + $scope.modal('edit', true); + }); + }; + + $scope.changePermissions = function(item) { + item.changePermissions().then(function() { + $scope.modal('changepermissions', true); + }); + }; + + $scope.copy = function(item) { + var samePath = item.tempModel.path.join() === item.model.path.join(); + if (samePath && $scope.fileNavigator.fileNameExists(item.tempModel.name)) { + item.error = $translate.instant('error_invalid_filename'); + return false; + } + item.copy().then(function() { + $scope.fileNavigator.refresh(); + $scope.modal('copy', true); + }); + }; + + $scope.compress = function(item) { + item.compress().then(function() { + $scope.fileNavigator.refresh(); + if (! $scope.config.compressAsync) { + return $scope.modal('compress', true); + } + item.asyncSuccess = true; + }, function() { + item.asyncSuccess = false; + }); + }; + + $scope.extract = function(item) { + item.extract().then(function() { + $scope.fileNavigator.refresh(); + if (! $scope.config.extractAsync) { + return $scope.modal('extract', true); + } + item.asyncSuccess = true; + }, function() { + item.asyncSuccess = false; + }); + }; + + $scope.remove = function(item) { + item.remove().then(function() { + $scope.fileNavigator.refresh(); + $scope.modal('delete', true); + }); + }; + + $scope.rename = function(item) { + var samePath = item.tempModel.path.join() === item.model.path.join(); + if (samePath && $scope.fileNavigator.fileNameExists(item.tempModel.name)) { + item.error = $translate.instant('error_invalid_filename'); + return false; + } + item.rename().then(function() { + $scope.fileNavigator.refresh(); + $scope.modal('rename', true); + }); + }; + + $scope.createFolder = function(item) { + var name = item.tempModel.name && item.tempModel.name.trim(); + item.tempModel.type = 'dir'; + item.tempModel.path = $scope.fileNavigator.currentPath; + if (name && !$scope.fileNavigator.fileNameExists(name)) { + item.createFolder().then(function() { + $scope.fileNavigator.refresh(); + $scope.modal('newfolder', true); + }); + } else { + item.error = $translate.instant('error_invalid_filename'); + return false; + } + }; + + $scope.uploadFiles = function() { + $scope.fileUploader.upload($scope.uploadFileList, $scope.fileNavigator.currentPath).then(function() { + $scope.fileNavigator.refresh(); + $scope.modal('uploadfile', true); + }, function(data) { + var errorMsg = data.result && data.result.error || $translate.instant('error_uploading_files'); + $scope.temp.error = errorMsg; + }); + }; + + $scope.getQueryParam = function(param) { + var found; + window.location.search.substr(1).split('&').forEach(function(item) { + if (param === item.split('=')[0]) { + found = item.split('=')[1]; + return false; + } + }); + return found; + }; + + $scope.changeLanguage($scope.getQueryParam('lang')); + $scope.isWindows = $scope.getQueryParam('server') === 'Windows'; + $scope.fileNavigator.refresh(); + }]); +})(window, angular, jQuery);*/ diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/pdpController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/pdpController.js new file mode 100644 index 000000000..368375cda --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/pdpController.js @@ -0,0 +1,178 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +app.controller('pdpTabController', function ($scope,PDPService,modalService, $modal, AdminTabService){ + $( "#dialog" ).hide(); + + $scope.isDisabled = true; + $scope.createPdpGroupId = false; + $scope.deletePdpGroupId = false; + $scope.editPdpGroupId = false; + $scope.pdpdatas = []; + AdminTabService.getData().then(function(data){ + var j = data; + $scope.data = JSON.parse(j.data); + $scope.lockdowndata = JSON.parse($scope.data.lockdowndata); + if($scope.lockdowndata[0].lockdown == true){ + $scope.isDisabled = true; + }else{ + $scope.isDisabled = false; + } + console.log($scope.data); + + AdminTabService.getRolesData().then(function(data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.userRolesDatas = JSON.parse($scope.data.userRolesDatas); + console.log($scope.userRolesDatas); + if($scope.isDisabled == false){ + if($scope.userRolesDatas[0] == 'super-admin' || $scope.userRolesDatas[0] == 'admin'){ + $scope.createPdpGroupId = true; + $scope.deletePdpGroupId = true; + $scope.editPdpGroupId = true; + }else if($scope.userRolesDatas[0] == 'super-editor' || $scope.userRolesDatas[0] == 'editor'){ + $scope.editPdpGroupId = true; + }else if($scope.userRolesDatas[0] == 'super-guest' || $scope.userRolesDatas[0] == 'guest'){ + $scope.editPdpGroupId = true; + } + } + + PDPService.getPDPGroupEntityData().then(function(data){ + var j = data; + $scope.pdpdatas = JSON.parse(j.data); + console.log($scope.pdpdatas); + },function(error){ + console.log("failed"); + }); + },function (error) { + console.log("failed"); + }); + },function(error){ + console.log("failed"); + }); + + + $scope.addNewPDPGroupFunctionPopup = function() { + $scope.editPDPGroup = null; + $( "#dialog" ).dialog({ + modal: true + }); + }; + + $scope.editPDPGroup = null; + var dialog = null; + $scope.editPDPGroupFunctionPopup = function(pdpGroupData) { + $scope.editPDPGroup = pdpGroupData; + $( "#dialog" ).dialog({ + modal: true + }); + }; + + $scope.editPDPGroupFunctionModalPopup = function(pdpGroupData) { + $scope.editPDPGroup = pdpGroupData; + if($scope.userRolesDatas[0] == 'super-guest' || $scope.userRolesDatas[0] == 'guest'){ + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl: 'show_policies_pdp_group_popup.html', + controller: 'editPDPGrouppopupController', + resolve: { + message: function () { + var message = { + pdpGroupData : $scope.editPDPGroup + }; + return message; + } + } + }); + }else{ + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl: 'edit_pdp_group_popup.html', + controller: 'editPDPGrouppopupController', + resolve: { + message: function () { + var message = { + pdpGroupData : $scope.editPDPGroup + }; + return message; + } + } + }); + } + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.pdpdatas=response.data; + }); + }; + + $scope.addNewPDPGroupPopUpWindow = function(editPDPGroup) { + $scope.editPDPGroup = null; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'add_pdp_group_popup.html', + controller: 'editPDPGrouppopupController', + resolve: { + message: function () { + var message = { + data: $scope.editPDPGroup + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.pdpdatas=JSON.parse(response.data); + }); + }; + + $scope.addNewPDPGroupFunctionPopup = function() { + $scope.editPDPGroup = null; + $( "#dialog" ).dialog({ + modal: true + }); + }; + + $scope.removePDPGroup = function(pdpGroupData) { + modalService.popupConfirmWin("Confirm","You are about to delete the PDP Group "+pdpGroupData.name+". Do you want to continue?", + function(){ + var uuu = "pdp_Group/remove_pdp_group.htm"; + var postData={pdpGroupData: pdpGroupData}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){$scope.pdpdata=data.data;}); + $scope.pdpdatas=JSON.parse(data.data); + }, + error : function(data){ + console.log(data); + modalService.showFailure("Fail","Error while deleting: "+ data.responseText); + } + }); + + }) + + }; +}); diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/pdpGroupPopUpController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/pdpGroupPopUpController.js new file mode 100644 index 000000000..31a094e5f --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/pdpGroupPopUpController.js @@ -0,0 +1,179 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +var editPDPGrouppopupController = function ($scope, $modalInstance, message, modalService, $modal, Notification){ + if(message.pdpGroupData==null) + $scope.label='Add New PDP Group' + else{ + $scope.label='Edit PDP Group' + $scope.disableCd=true; + $scope.policies = message.pdpGroupData.policies; + $scope.pdps = message.pdpGroupData.pdps; + $scope.selectedPdp = message.pdpGroupData; + } + $scope.editPDPGroup = message.pdpGroupData; + + $scope.policiesGrid = { + data : 'policies', + enableFiltering: true, + columnDefs: [ + { field: 'root', displayName : 'Root', width : '10%'}, + { field: 'name', displayName : 'Name' }, + { field: 'version' , width : '10%'}, + { field: 'id' } + ] + }; + + $scope.pdpsGrid = { + data : 'pdps', + enableFiltering: true, + columnDefs: [{ + field: 'id', enableFiltering: false, headerCellTemplate: '' + + '', + cellTemplate: + ' ' + + ' '+ + '', width: '15%' + }, + { field: 'id', displayName : 'PDP URL'}, + { field: 'jmxPort', displayName : 'JMX Port' , width : '10%' }, + { field: 'name' , displayName : 'PDP Name'}, + { field: 'description' } + ] + }; + + $scope.createNewPDPInGroup = function(pdpInGroup) { + $scope.pdpInGroup = null; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl : 'create_newPDP_InGroup.html', + controller: 'pdpInGroupController', + resolve: { + message: function () { + var message = { + data: $scope.pdpInGroup, + activePDP : $scope.selectedPdp + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.data=response.data; + }); + }; + + $scope.editPDPInGroup = function(pdpInGroup) { + $scope.editPDPInGroupData = pdpInGroup; + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl: 'create_newPDP_InGroup.html', + controller: 'pdpInGroupController', + resolve: { + message: function () { + var message = { + pdpInGroup : $scope.editPDPInGroupData, + activePDP : $scope.selectedPdp + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.data=response.data; + }); + }; + + $scope.deletePDPFromGroup = function(data){ + modalService.popupConfirmWin("Confirm","You are about to delete the PDP Group : "+data.name+". Do you want to continue?", + function(){ + var uuu = "pdp_Group/remove_pdpFromGroup.htm"; + var postData={data: data, + activePDP : $scope.selectedPdp}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){$scope.data=data.data;}); + Notification.success("PDP Group Deleted Successfully"); + }, + error : function(data){ + console.log(data); + Notification.error("Error Occured While Deleting a PDP Group") + //modalService.showFailure("Fail","Error while deleting: "+ data.responseText); + } + }); + + }) + }; + + $scope.statusOfPDP = function(status){ + $scope.pdpStatus = status; + console.log($scope.pdpStatus); + var modalInstance = $modal.open({ + backdrop: 'static', keyboard: false, + templateUrl: 'pdpGroupStatusWindow.html', + controller: 'pdpGroupStatusController', + resolve: { + message: function () { + var message = { + status : $scope.pdpStatus, + policies : $scope.policies + }; + return message; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.data=response.data; + }); + }; + + $scope.savePDPGroup = function(pdpGroupData) { + var uuu = "pdp_Group/save_pdp_group.htm"; + var postData={pdpGroupData: pdpGroupData}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){ + $scope.data=data.data;}); + console.log($scope.data); + $modalInstance.close({data:$scope.data}); + }, + error : function(data){ + alert("Error while saving."); + } + }); + }; + + $scope.close = function() { + $modalInstance.close(); + }; +} \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/policyAdminTabController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/policyAdminTabController.js new file mode 100644 index 000000000..698b7e807 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/policyAdminTabController.js @@ -0,0 +1,70 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + * + */ +app.controller("policyAdminController", function($scope, AdminTabService, modalService, $modal, Notification){ + $( "#dialog" ).hide(); + + $scope.isDisabled = true; + AdminTabService.getData().then(function(data){ + var j = data; + $scope.data = JSON.parse(j.data); + $scope.lockdowndata = JSON.parse($scope.data.lockdowndata); + if($scope.lockdowndata[0].lockdown == true){ + $scope.isDisabled = true; + }else{ + $scope.isDisabled = false; + } + console.log($scope.data); + },function(error){ + console.log("failed"); + }); + + $scope.saveLockDownValue = function(lockdownValue){ + console.log(lockdownValue); + if(lockdownValue == true){ + Notification.success("Policy Application has been Locked Successfully"); + $scope.isDisabled = true; + }else{ + Notification.success("Policy Application has been UnLocked Successfully"); + $scope.isDisabled = false; + } + var uuu = "adminTabController/save_LockDownValue.htm"; + var postData={lockdowndata: {lockdown : lockdownValue}}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){ + $scope.data=data.data; + }); + console.log($scope.data); + }, + error : function(data){ + alert("Error Occured while saving Lockdown Value."); + } + }); + }; +}); \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/policyController.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/policyController.js new file mode 100644 index 000000000..c5822a7e7 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/controller/policyController.js @@ -0,0 +1,65 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +/** + * + */ +angular.module('abs').requires.push('ui.grid','ui.grid.pagination','ui.grid.selection', 'ui.grid.exporter', 'ui.grid.edit', 'ui.grid.autoResize', + 'ui.grid.resizeColumns','ngRoute', 'pascalprecht.translate', 'ngCookies', 'ui-notification', 'ui.grid.treeView'); +app.config(function($routeProvider) { + $routeProvider + .when('/Editor', { + templateUrl:'app/policyApp/policy-models/Editor/src/templates/main.html', + controller : "FileManagerCtrl" + }) + .when('/Dictionary', { + templateUrl: 'app/policyApp/policy-models/policy_Dictionary.html', + controller : "dictionaryTabController" + }) + .when('/Pdp', { + templateUrl: 'app/policyApp/policy-models/policy_PDPManagement.html', + controller : "pdpTabController" + }) + .when('/Push', { + templateUrl: 'app/policyApp/policy-models/policy_AutoPush.html', + controller : "policyPushController" + }) + .when('/Admin', { + templateUrl: 'app/policyApp/policy-models/policy_AdminTab.html', + controller : "policyAdminController" + }) + .when('/Roles', { + templateUrl: 'app/policyApp/policy-models/policy_Roles.html', + controller : "policyRolesController" + }) + .when('/Dashboard', { + templateUrl: 'app/policyApp/policy-models/policy_DashboardLogging.html', + controller : "policyDashboardController" + }) + .when('/Dashboard_Health', { + templateUrl: 'app/policyApp/policy-models/policy_DashboardHealth.html', + controller : "policyDashboardHealthController" + }) + .otherwise({ + templateUrl:'app/policyApp/policy-models/Editor/src/templates/main.html', + controller : "FileManagerCtrl" + }); + +}); \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/images/loading.gif b/ecomp-sdk-app/src/main/webapp/app/policyApp/images/loading.gif new file mode 100644 index 0000000000000000000000000000000000000000..cccb0fc9fc763bc5f1a7418c69ce02af37e65ae4 GIT binary patch literal 6820 zcmaLcXHb)Ey1?;}M(7~~2r*y+O7Ar&YUsTMf*`$0?;X_8LzCW-B25vbDn&$!^dblX z0wM^~1VseI_HxjDch8yG-Sd3ROrCuC&HuWuJL;NhczIhTfD+&f0I;{Wr>v|T5D<`+ zl{Gs%TUS^2;ll?KiPYcU5BN_H?k}{mucNKMqXRa`#orlg>uMY9?q%yB>f-6-1;Bj+ z187gbhC89tQ#CeHRy0tR6cqD9^oM|BS*^=G0 zIJI3 zw;Lg#J3cFFHN0>IUA??AG&~Tzp0dg1@nOdWGPdVEG$Jx|uv~ZyZ1g^FVEWh^M4Kv< zt8d8}_AH;?bkKk~GLfAoUr~HHCnEuKf>DxJBj5%Fe&|(O3^i70Ujf?5#&dkBIG2Q% z4|Vs&ri~TiJ!m<#nw|U7-UR#2?ZBOdEhFeU-vWRNNI+6 zyB9b4^JZ*@F>rw%Ar7`z<+;nb?$tN+X4+>T z4ub4|mzem>d3iKIJpdXGYIedELV}m3Ooxdxd74ce$vxhv`{Rg#ep|1@l;JYTV&Jdf z;VoqvYn>ef-(;JCMlt;USgw+j=Hm~JzZNIW(qvSv&gV3rIjjD*@J3u+oE84-`#G8$ zF~gscZ#KDxXO8qvLSqu`StkcDp)Tj5i^ZqR2+Lqy&P{3}trCQ6%m`gOtH69}=Z_(( z{{RN|8w?IP<74^<46{>+3GZ((4~>6*Y%OsRucv1$Uvf_uG@&S^D0&l&^P4N8w+pf1 zhI(3E8C}L&2_J0=YM!i&Ak9i2pSS7yMw8^%>5f#_G(W?l?(JrBGZf?)=g-2Oh=Kt# z0qU`0pj=`5lu#L4auC7`Z-lM{2t+GVaJ7gF?a6wbbbO1$i(SRwIU{2JLKMmbX^U&RD$LuR7TJ&e}1& zThKDT#1L?@c0(IqUs@E*81;DqYeS%-FmFtn^Obf163{2hjyv@}mfh^I%dwatoMpEc zC(Objo(iL!kN4YN9BPWvN@WexQX({Owijbp_KdG*@~f2^lxf{Tt5wQp%i32O-`{5(y$0=-Hq9Z2LHridcgAu&d zFVM_Sd0y4V&j}IOluMZ@LDOun7Ch&b%b(NV%h^v-e_k#3i;v&3m4r-$h-eWhp zxZEsfCHU$WTVWuf}p4e z_!^p6u({*s9lh~-@Magjin}N~B~4S`kGk_#pDWPRd!89G0Nw)W5nqfA8KLW=iPR;! z^InYzg9Muc6T^V%?64ej2{tI`wy1*(g1f*-+|!FUOPB=81;pAVuzFPCNzni(tX%$S zIk%!wG5T4G6EF2(o92_DBa)O$`S8qJC4PH~DNn z`purPMa`I>!_2X1;ob)V0n>H!gi(;5%F~t+9GtEau{i;WK#tU3nzAXkRR!dqWQ+7p zKOjFzL8&0H;@(WEnML%?(V9(_V+Ht9gLwgo>-Vz=5o#-%_p`<#HE^8=L(TW6sv=U? zf6g>IWb(^rG@grDcAeBPiV(CESaGF_(sO(m{*6Hpn&%0EL}{|-4h8XtDHeXK{Gie~ z+leC&zU=Me|LRV=G_oRUTAX+$Q1wSYkBk?=FRxixO>CJ7s>2&wm9w8Zp>~oS!nVZypWaWmCo)ATD@s&&g`pLccB`Xg!can+S}iLILr zPd*V}7UaRi;Cu(qA|GdLv2lflhpcu!Q~z;rtQ~YEpmE^>U13ak>Q`1GHCHHG>Y-uS zv(y&r&=3LsBFNs#0fsi9b=q2WYUN*KK>tq0{~xKrW_z3dAro(Y{&}Y6DVb5X8=W16 z21I^S>3+0sB%a>jh3$2|RzrB?=5u2XjK*v)F|?a86d{NfFEglhF-lL8z&euNYFh|U zX8qa3-30sqplbku_>0yN2rz^k2aE-SY*41&ae8clg~EwsF9&Yw(yDmjKr^yHp3==& zK(e4x?R8IBhA6ayaEsXXG{vXK;dy^CZ%agN>4@&Q2qZV-cWSy=p-uT_xeLms)J3Qq zGsyhf7O!1HJ{pw%(a37!=z`Pk*MtrKm1EM*Te({&2))6|2^3I>vK`EesTrtDP#0LV`8Q&&^e=Ovf zb&>QDYKuPmiCcRwW@Nr)>izgIjiT^8-K{f) zXxDA@#*?*QTEE1IvtE`BAAT|3v2Z4cy!T=7u@DOiaudPViPnYtKbaAtoGlLL2>!+= zKU+*Eu`t9=a`D(z*8~5Z6!3rWL4P`mvLuk%Skt~gN$D}kt01)E`DukzpH*6Unqo<` zz~?(Eiq8%DZPld>WFdw_UXmIng*q(eLVDTMy#Jk5yG1+Z(P<4 z&ZvPoB|lcKbxbh=Qg;(uJNl}J?0WBy0bqlp_M{Hz%c-z=h!4u4;tf%cdL{oZWbu7I zX!G_Q`jp4s;NgYU-J|Kjwri-p_e{zUZbDd!6z|nTfN}x}aQ9Ommw90-lT+%SfqC|u zC;JlIscBZ~^jM}O0zS30CrMQQA3hjW)i#BF{gj4Nzj3Q!CXMJOQg0*(S`If0G{;>U z!Zg;4*fYyZ8QDoV9=b-v%MM|5gIKBND$YbrtB8x=2@7fqF=R-b(z^W>{c&i za4Y#vI~>;Npm0^4sg#xytE_i(E^dV&SD1Ix5yMB5U4Ua02ZO#8ocPdb@{LB>kDt5; zbz%%0&=wH|F?(&(8MM-#rDdzBZ^Rb(?WO=$D6-m9dgeP|}tW{nx{ z3=3&nx&Kg3zFCCT>(i7*5ohqs&fsDHM#3!DO~Ij6Cb#1B{yX2MvyHcSM>)d(dL2`w zvtzbw1^IdiUS>~F{W`-142A!5073q%7HqZ?E{f`*uxf5rJt>ONjOVXBP~ea}9YBOs z!5G6)K1CR9HZXJU^&9?sTVPpDEx^B7LYAumTF=jE{jX>6$&7x@+ZmbJ@kyi2Y{SB zz^TnC@wZf}TgaHkBKb$%J(Zn))qO+ZO~sH7-1tyfdq4p@jF>fRtXGA}TxwsAkV$yx zur$5dn_soz|K{x;21c!aK>BoC2sZ_3z^`^Y0C_Z-=RRSfTH9a^?==rwtHIm2x!)3)4j{le=8WN26R`2@q0w$WgzO(c(+9&arq^Ik-vI*qvQd=JkxZ|<3V>HVYp&T8LD zg5w}jWj6h=YbNF^_r2-($m9!c0#1mx@TfRvh`|P+nhClI>^Ku*IyWv%-WmCEAVB~r zYEu6d#O7a+ewV3r+#TJpO$VwrS(dsG$J21d^+)GcLXiDv7pJ-Jf+9;x_AHnd;t;2T z2|pHAE#?E~Ze#>avMMh|{@gXxVVEjC_&+CI=)Z$$M*hx=A$CUGbns7JdQVR*zw=W4 zMU&(AiRBbb{%W+E=1{&qx0-S5Q@cxR1OXf@oXDuelL?@61WaLm=C#_=v05#QbOTVG zbGQ9q4!Y(XhI*brlbcYO3qn)OnUfq32rzUa$=j!02}s66tup}xV9tetWP5LXY+PW; z{VU*NQD}4BBVoVxo9@<6pP&mnalG}miFtjjR)g4#VrcixRvfGnMdm3R6%_!!HY!M3 zdJI~TJ-fg&z0SS$oT~->W}S7e@}uv}*VUuHfL6J@sT@>758wwvb9UhOF&K%+QfmLLlVP7$Rf*+uDf~vKtC4R-T8_ARHlF76@|YI`+u_Sl*Ix^xAxK^ZX=VN%8WR^aaqns_^Q% zUtzJwFYgd@(4qU^u5#Vf7`s{mnW4#A5TLyPM4KUxkp};qM%4e63;eV%F{gbw@0rEH zk_LnzPzO*nv74jtEaIwsKMqd-KMHI!&ZWL4VJ(fW|)gwT(HS)m+AVcrqKDzL;`O2N`N4>_MaR)|Pc-(@LCc$XWcmG1=LyQh|l zeSC2nEpX74XpXc1$&|lRG8Cuh@k=!tIxIWq>Y4f8_F7U^p~F=aQ#9v zvtDq~=88IqfVK^JyVb3)eIJ1#MzyHKv&XmP(V_1;>+o5oK!is7ELt?xo(>_%vwzW$z{QJ&|2(W&z=G;6q zvZvCbSTC=;IdSk=JnMR5q0)+2y1hncQfZglPIB#8Z^IkFweEd-WZse;jl46mDLL!F3W@a(m^9==>oy*3PYob*fo3?L1?XP_NA~&O^)^{`~H3^zlOPUyX zkr;og_OC+pVC{0&txMbYeJLyOzC@Ii>muxYu{satgb$1PHfcW?2ZWXzYp$1%Zl%V_zV9iPjaS$h75 zd%s$ucaWyT-VfR!ImdQF8cs}i2IfMhIhUavA!3w)Nq3-Wy|q`X%kx3n7(|#7z=^_poEh-BERgX zg@U9P9V2I*ao%(9O8*ECy$~1Oc{+W6a)_Tj-wnTD!vr&57H(r9l~_?Do5-|CQ!J4u zE!)7-JU>l{sNw*v5Fxr+J*ZT#j|N0adsJmMi&`Za+-YjP(#?LaqWVeSfI>k`(U6km z)6k6e3A~k+J6qe#?4rWc=P4PhLts#^T=n{s+P8b@W1lBwsJ{ZE4rIBlwh)kyGzwUo zrOTHgFBvpu%M$?+K*m6gTt)+NFo<3YeE#pU^qkQkIzSTWjM#!T(n~a@1nh5y{8^n3 z#9bARW22NQ(vFg}8j?I?q7v*qv#i~0Jr}c@I3v9j;els>zOJu9a|#$6J~8Sf{dc}@ z^H3^#+Q$Mg3SRNJ?0tjJC7oY;L;FjkL6lhbiNn-Y7Or+vJ>G9JpjY~850?=kmwDEn zg*4b)3kjrw&Aiy7{6#1~(tiFGfusV&29Y5XlhI2avv)G{NZQ;eYMm~K`v*ylfuM}IgJdVb_YdHeEP)5PRCxdx>&tS{oNS?z1D;)q6w5W+#lhcDgil~>7U1;A=Na5|wEXh8c`{JUTGsv#ly}XR zYlHEiHpg??Jq|EOf)>?HQ>DajFB!UX&=T7mp|FkYdnOlCdtKcU?)xiHn@&4-twaDV z#x$5O&VVATX5rba3ojyDR4-oqtC`Zhz$fsHKX#=+o3Mo6jD9LvLT7OaW}Id0}=7rF#CTo~=Kr`6}$~%e}STaiEEK zXzDNY`*WlA%D4JDosPL~T#rE90-$8hC~aD(*qrTu-Me_( z9FTbt%CRL`p+ewFXDFnu2-(L z>(rT!_GbWCC2;x8bo(&N0%&VJ@UG%nXx`#FCU!y&JavT1`31OyqJ`1tfQ>-3nLPY7 z)>IcDI^A&b5_GS~U9QX0Mr5n3M9hig3?<06ST)r}GDvYZK%v)Y@}-KSDWqxx3k~s1y+WyA;#$tMo}Pq73fefq z+4_lR=~59zu;kv;8%*yj;|DW#`V44TAF~YjO=@@9$nVvLAwMb8Gyl3wcTe*DDjWFj z{BF9LWL;0F&qNQ${Mk)%Ga~z;f$N9tS2dcIM}?~gNGh*beplHufhxTm!9C*!4!YZ8 z=P#*`F<|}LZfGMVZpr?P#0R$Uu==F!sr!(>pvt)8Xq}x(#z@6lrsHAOM8M7GjNGg{_ky%_nUVXMUV$g$ULEd&t>&r0nDlHgt9-hvj Li@*OP`t$q`mG8q8 literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/images/loading_bar.gif b/ecomp-sdk-app/src/main/webapp/app/policyApp/images/loading_bar.gif new file mode 100644 index 0000000000000000000000000000000000000000..eed8a505e7772839854a867ea79a3733fbc10755 GIT binary patch literal 28954 zcmd>`X*|^Z+x}<9%$Q-+xMqY%gR+H&Qm(dZ43&_Cq+L=ZNgI+FYeEr1*0E$?hV1K% zEkv}TvWy7Xi%_Kh=R2eAx_^|E6c47MC!szhA!k2~qfraUrh0*bag~bKffBGf)jbDGKv5}^R!A@0WG7lX58OhH` z3>y5d2>p5JpM@b8@%4Ms%hgAkOTU@<2x6!a?^2T#hqEs5w_IA)v(a{NVSGdmd)7y4 zrC)u5YQxbjk*&!ab)paZAtg^f9&@T>GaU7lBU^^@O48Nvos)&z^kd(Q%$4qF>6xFW zxw^Z#{eeLHAaC0G`QEx67!c$id?zF<^#0xO$cTH<^w{{QgcyHsG$JiEJ?&;zMt0`I z-29wEMsZ$IX-PpvS!H>3RV^#E-W$RDxVfq2$^;@|~&5`PthdUb{Cbz^=Jor{Q z1-=@z6T!>yjD9UJ)=Q(0)& z*Z4A7?N*5j;3B@9EZ?!i;`glgsBwW&mtreqJocr!^_=a=cO~nrf zTj)JLB6~~n-ak*-uJs@O!@R&(P*yb!K7^?F>85838M)J=9~WvG7ZTH^U%Xx@E13qL z2KYc~>ZTLpr(Zl<$jhAupG;HZLPpwj=j(;2m}&6glvPZFuLgWOHFXP#Nz*Ud7V-+F z!PnIEWFaGKy0iN~e^Agz^WXl3UZl|Mv=vtd)F)nQu-OvZD)&*6jzKQRor!yATguMv z&|MbxXkeq$4cqjtQSdqa#gDq{yle8^7tZJ8>EZ3=bJO>hzu%qPx2Z%y34TE$|NV%_ zsOXqjdR%-$;)A5*>LL8obn0_iow@ZURGJbVpax;UgO86H$HA^e$vwV z^x5+lFWcHXsLMq=CB!8{df9z%-}Mg;ydN4F9vht)|1dfAaqP7?ktn%b5Pfa&>mnAX zjiU+XEFcg%_&$J%7e`I>SQ8-nGGps(q)?)gvd}r_Vg0a^{7e<~mUoV{KX1ek(*Pp+F z;$3FC{Dgi~@zg+TtZu;Zt&>P3X;bygLd12;C*9Q^t9zmsW9?3qvTRo#v^LufErVgZqf~w99(omR{;i*K9j4D;wM|>v_qFpR?GADcDrj#f?0sJ#b;akt zyBbn^5`%WhyzdX%w+Z_$#L%Rn|K1*JX))A7fA706GjI8UaEs8h1NW_xQU@Z=S$EKo zt6i9Uo36B-9gKDy_}qjroPIwTOG7K95H$YNt2%mk6nyyL0eO0lf~RA1X%svT@K*9l zphpJYoQ3r$csJl}g#=B5SK{n63f@gk)iiiF;4OmZb;W5EJRtBiEzC#3n*&eH|IRdc zmsc*0g7*jBC3uTA)}!DR9z8w^Uai0HGrRz~U@s>%N2s42E-T(33trWZ%PWfp*|euvxTYD&&Yj{zgG3sTf zRC1*mlR<{9_TYu2GSpamvOv?k8_~$9?w13^Q63Vc7k2)w|ZYi+2@Jy4T|CWDIQ^b@={uM z`&p0q(SuVXJuQ{4--N^A6ar+p}^5xBVZ~)Zh9^F1@P0+q~v=5;(k-of+z7F`jY*|8|ysclOoI z{ve%A*Aj#G?2tblVyyb-gL?<4x88*ww!d~d_)mpE(bXj?2CNHy2kcg&l5*|`M9$^Q z4@O?D+cOw#KY$&Kx%%-|a;(#g{7|e1+R5^kd+i_lZCl#gpwF$TX&*j7LrwbfulkDtrBUT~-B}f0R+m zcSJF#QX<_Zw`rx=OTO^6q!H{&;veoF>pczX3p(vb#tPZq>&A=vL(h#D|25>jt_Gu& z7g>d=UW0$1h{YSVl+O*MPgE>yGC;1T2L6d;@?mW3SeVrrc2&6bqjuH!zZ5Ul5ckwDf7Ar@BJ*#85CjB4J8KtxOKHhb zDZZOj!5dSi4fN*}tn?jCj`}N0cPm+hc0H#3F1D#bMj%ElT3Sc~Zzq+?xV~!ClRibm|sv&!xnMAh~^MdJUHzJPswFXk3Gp)4~w{kkGU8WXml2@@8wbvYC?J z7`*(-wL8=D@Y)PI~lew@SjcLxj zh4qjzwb~BbT6o|@S6J&t(Zt<9u2_!Hj-8~$e;Vm{_=_O4 z&>i8Tt1;`pF^}ihtb4ZESax4!#n<_{M}>5lRTV}QMIpmQ7o%lKqRX}LFdTdvrOpGt zORm?GXkyjtC2}UE7YKr(K@@tOMIehtw4pQkq=^i;sE{~b1G&bywby@Rn^oWKRdwuM zgc!_#id|@UD$Ca>{^o8g4LQ3 zt;M1$no6Fj339Kyyk+?1HjW@%OAf9*ZN|R4Hp?ywwa(DM&3z5Bbq$ZPDmyX3fV$En zF=U7J*~BpYh_esE?bA||qg)iMQxa{h6_Wh*4@co>I0oy|3Po}U4QGsJqGjqI4cQZ| z+RxcnnhTF!tv-A(L+jBvUq*J5@<;}wnL0mmhmZo(M3S{$RG}5j#8^9*Xo_+j7KXRqEsHO4#4HsNgZrjAAnW#uR=3yS}!5iZir4(Ww>+uhMj@mhk!Mr`r4)Rs4GC6n7=v4YxCuu*Q^e9;|xer?#UGWBF~3 zIJl1>Eo5&&hE-&y{cD@-G5a@ml}ZksS6a?HbU9XT2mhb{K(zk{DFT+{hdud^-sFEL zMZkmn7Y+rG#;RamQ3$lqp|X?k9>*(I}U z3^@LqZw6<#xMWWZesiWBR#GC8ZlZ~{c;(xw_;W(Hl>^Rs`}m%Vu#1e2ij9e*C&WKU zOioHoNui39APo`_kV0pZr1GQ`(8454p13e0H}6q>!%xTGoLM6vTrGg9wCxliWZOzH z)G9k(Gln}xN5;n{Cq90do|^eIH~Z!DG*zuI+xr;)X+1^B9C<7Sw%ebF$&c{a6Q!N= z6Cii{XC4)qJiV+2iIx*ZXg1K>;#{R4_I}yP@g^6Bn;I@BFSf)`T=@i661DtL($;ot zQi3<1nUrB7jrrK(1yKl3Gq`)@?DOP(g%W(a_8EtAtR5$APcKk2E9_s%HPV<49-VfCF4Upx$^2s zVQCp3Ote|h*qfruBi+rV94VSzf#|J4zVbh+=VM3ovKAJTQWPPxuYKr~3gYK_6PA~8 z2cE=4V&r6-82C7+FQOyS37!Vs+nhq@INqf4+cy|mj!j!sYNevcA%(0P1m{T&xKb4I z7<_{>gSiJsF>rSuS}dl(-ALYYZ++GvhI;o4spBbFS!26eq@pvU8@WD+tO*xv)rKRN z*@(c92a)pqfm$oh_TSZ(N$n5P1Kz|@Qk@OMDH}4}5Q>2YO!Pq;Gb&nT*i<9L$V8rp zM;~(hHU+7PxVNhqRq$oTBpwt2X6BAnY?afDxt_~lMN8mzB}X6ZOqE0VZE74!xU-Az zePWP_&if^A(!EC`iq{j5h?gB|7^FK!ydI1e!mU^vAAL#TTt?m#>vNe!`U=MbuqAVr z=*dHDS^vp*^;W)Xr}^X~{8g`?iGQ+-e=M)raNZ`r<9K>z-m6Qcnfcw`{Ns5JzQRoO z;*hGkhnt{_x*KY@00XWg6kf`z63@c&Z){!fD=5;4oXjyS`75}=UkT=;j znaoe2z~B=2)?V~FCi#J$sko2A+ z4i~b*!By7Qn0*cjIU?avU(|Vg1a+goQ5+im(2^0=Cte2 zj};8wnIA8ieKJ2$!RuOz|NmgHUoF@F6rIcc;Iuz8ThL20&OdGKEl(49x7wgf2OfVi z$(}3}*9~YNoZ05$Ix+Iq+0|W1$=KVJNb*G!P4LQrs(53eK;0C*98m}Fou$K=KJYPNq zRrPo@?=sb0V2&cSlMf?>(;te6N4UEm$ZkwI*-C#=XxpbB%^#N4S>iY`od0<9g`RSk zDZYz2xs#288!?F_viUntUS6qvcDO?yPvU$<#g+zT9Lu$FFxgW{NnFJQc^l~|t4L9y z^Job^+OhRHvU-!?7ZcxN^xb(QAi0d^rpMVi4lih9@nH07=ZqpDOSS}wr zeq7R&<-FDg=60R1NStKxDk0TbH&-j-NyxQL$&x(E#&W%WXBa zXoe(;5J-zf5w7IG`8N>p8h44K9en|R?vj5OVr+8u-96JYsqaGnG*my0;%J|cNGgmU zsHKK5Av{ncLeE`Z=KisICM?WxAayXtc|eZGOVt2BL>Ch02q1n43kx?x@QWc!+!6wI z>A3OUl}xjWcDLV>l1%4Vt~=J&sVOmO)@d0rI&gX%6@LgLX|qKmAz+1kb>^L1vIgBt z0zZ(HzT(YrPMwV3Xl|p+@H;vV_E;JR4=G+3^f~jIl8Y|iVOHKtC#Ph3-|It`#fw8R z>B_|;5s$}9$Lk`M%cdIN*p|qIU@eRw2sv-3l}co^=ISGF>O|gyKv)E$BFD4Go2T*%l}nU z_%gkqF3#?#^f`)D+yR}Je;m4$b*GG|Bcj`WX5wnuc90o-qTO(Fb-xDG@Rq5sFHx98 zQicRE6cWTx<#1zSAPF7p@5hzGjP$HbMs_k)02)ULaQ$Dt6uOKg#Zo{AVDiO<%PWh& z4|!ib%`5K`=w>%}A$p_&Ofcm@5C;U*0(zQzrrDpkQuuY@+adyCL-GuJ2r`2<{7e3B z6f)F!BiTVis|HPox+qeoOQ{O@IpmENa;^z7)eTj{iP&9)A6G%Et9*>01+x~lv{g{{Mrfx|tyeJ#qTvj|a*qWdl zt6yHSw)TZ6rGwmSzgCz4Od!qNogdxH8@PD_QFUuvs^Um2pwAogzVg$ZEwLK&FnAd+ zT%XWnrh(*{M0VrQGCl+(3{7Uyz8?5VpY|QG_%G*ysauOQs6rFsl=UK)y&=41sVo{g}09FaV1 zl@Pdvj|G<$XH!uAF)$kTntq^svP>WYo*-d$Mn1`HSK4qwM%J)(I-_FA@?{Veoz5i) zg*(Y75NuwbO<-MWq=u+YAAX-*+BR(Suyx0}^LbhE@8x*f&pf7}4u#Go;Rt$X>Cs|7 zVs6QcM7tyIg?E>|PAPRq^G%d}Y@5$2|InR&p<>}#X?Eq;xBTRC|M*wIcjn)3Hm8Zv zQ+m)F6z#M_$cIUue#_D7EG+RYu=cz+M|0{uf^Z+}<-(#qHgGJTj9=6UV({f?PxGc& zUO0RkflP8-$7~(&Bh0-TKrfEzQBXU87ksY2Tj0|R!-IQ2y)?1B{prPlLxx9A`P~o@ zMM|$Rm^m$Q`O$s2*yheIJ!uN1;FX`(s)7!O!RGL8)epC4yJ@ql=6c+P_2+tBdYVl& z;x>*u%1M)lYcYW~X7&hq8-vf7)0WHjAlw=$pZgNSY`?ruNzVE*oblI_y_*@XJoCFz z($hE%#FG$w_4uKIit9K@W~<+`9h!m9KGe%*FMJfn?Y~zeynA{1)HAUU+de%#_+b0= z8;6#!v)wnBFV4LU+qd|6AUVM0-+{s$i}*5q)8iYr<;3|;8!PQulc$sF9Ga5eGg(wx z`+CH&WU-=U>YIz(b&f^6dCLdb#5)|D7y_wch;pd$?SQ+!aendNE#fW6B7!kJ<2RRB zrhsN*vI~kz^1g>(xmiW+0v)ekb+(IFzA6yFFirXe2$d#MMQY66Hy^sDK7O}|Mbyed z1enTAnh4-4R$_|Qx(B(TN0m2Ti9>WLEvs-*QsiW*kS@wku4V*R8pa<@&GmK*6JB;a zoJmjGiN{#0(uV5SE;e0I^hgs|$dh}Tuq#;VSQ=yz?@&_gHXcxTnQrp%P72G-!(Y&F zr;qksgu72Fp)M(fMj39)Qnl90)Db?{mEkb;y2~#tySsw+jW1N8ruH!ue(l)ij&>s= zca=p=vT5(I!0WmEiKySeGu-t)@E`w zieN#m=2cQuXYnd3Gk{r~lr_I9ZV#q%>I31cQTuN7_61PTpQVw@Y5)|Q>rtwBff{NA zDK;5UkOUu%#Jk#jz#<;y>f+}VAQIF)29fQ6um&i*$JDkz+auDH5kkH zIUG5bv$F~hi(IqoPkI!=NB3RAVwcO~l-O4v8*F38>)wo)O+K3+FaOwRrm@_mRDPbz_Uoq#5=t0aAl3!Df}9;dq;3I-OfH3MJL-Il7+D_7j#2S+pnxPDQveN1d@1Y zq-%4J!#5>IwGr@!{E1t{$6>Na%njtvQtMEvItY2)#F;af7yIj%(nx>)kI?P!A2 zrt}_Q4zWW=;k%IdPD3iLNcim5ag~&7x}#ev_dc7f5x(H8Er9#*qME8W;XKv4dtc4R zXGYoErrQ2`upL;$i5s(Q*Yz%Q{Q(zTKKJtrBL5W=!XL6&>y#=D!V1v?x_@9Z4Ywq( z9kq5mI&NF}gPdKz%c7qzkrcqu#e0x0-ct@Uz7rVa8}I*J7JZgvF)!ygT`X5XvoP6( z#ijX6oq(LIVy-N{d0j|)RVaXAnY59`bteGP0Z7UOy7P!vgl<>Eh#X@xy$__IxL2 zr$2x!2H=ixP_c(TW4+@lN(u@#)o$~gAcYm;SL&?3^xXJ~t2ZP^OB4;^CXKLBz zlb%BCgH>q!V%cU5_-f}?cQ=CP91DS_8X#Q6RoU)d!Vo$CQ87mpRUb&{yR&T=;PX0k zD}>Lj0G|Vw@HvRMAkrVW{RcT)7}viG74l@$c*w@|M1&#(4A(65z|_#1DmoB;I!Ka- z=LAH~CmIdna737b72R{0wN;!?qX7%P4l;=}$Rx@z7;w6n!QuB0h>iyL69Qk~A4<8& zNiUOphttvwCuP$aEBQ1|OM2pmk-;VriMS%e#wsLD*@+e&mu78~Q4gh;o=);|JT1G# zfW)&Anz*vyTe{e?N92vl1$~OM+8n!xfIu3@5C1y-?BMFJ zpIQ%odoiPBcLF)vy?c2DR~Cn2vt7Q7X1iAW%V>Jj<65V}o|QMNF5b?7L-WN0y4HJ2 zw@4Yu4PFp#`cBhFxHJt_rUKXhK+5KZ^I?d|XDX@!_N#00|x?r~H=EoAWB=YcN^^NU|$U$LKs zGPw;rMbkba`MNOP#_%bv3nfSp)AOlgb*zW;Lj}Ct#62E7@~PVjpmK-usW!41vlex| zUS#OS+&T9}eYDWJ=EQ5PgL>i6V39-9_YNzPAH*9Tz#n{gxXbrmdRtbqwNEc8A&yT_ zYE2@I23z-o=!*qIeAS>{!fs+GO7`ihA5J4q6bvRvVMB$De=mOB@WpIJOR)O&+SF`&ZM+K_vZtDOxf z{5w<_8gO~#)_9+9_v@K!S3~kRcTDQ#DhiqtpvbR5E~8*rs|XCnFEqVM`_3;kEfXky z=j=eBPzFaR?H-}|7!)e}pdr}}d+FJ=-6+Y7R|Bh5$#w&D&lL)ZIPpe`TfDzAMAJJI z&L;X(?I;*tbpy9}S(q6jhG6$46}!fUp28b`xMAH>I8u9r9Th=8AC8nju z6CC-5<5?~on)ZF4U9zb(9nf^T)qQ`+HToTnR4Q=0bWVv!NZp{y$F`Bo3Ry(86~jve zJ#{pS`p^cp1vEaLiE_6eu5l6FIl+Vxwv8bi7G6lY@Oz}3sOIDU!p4e)TP<<5@?jFv zZy5q`HDNe!vOzF1Dwn=4A>-p?#p=;ZO&eP}do%e1lc#QPn;5;^Lix6^0f{8;rO~=F zVLXva`mM5&Vx8I>;X>j{S6WR^WL|AMdSUEp`!?PDJ$rA7?wUDyCUURQYoDAk2(IxC zr-dw&@57}JW*plqO#xBL!_3<=YFbM>Y``H+LQpWlTa+2I~< z;cw7@z9bu1g^mrt&ko&N153fhSdM=gVLVcvKQx+T_q=(mhb^&pylestSD*TuZA4*aq`1OxFkq?F@VIl;5_9%%e%UC@7QZRFFp&W_8+p$Nw5 zr;)tv4;VX$<0Zo(nG9EsFuogn@6LmOBq)OU&exy@_d8-&Dxj+|*~O*hg`9F}ZdU1% zk?ihbzZS20RSep2CPM;*Dif(vwd!|0pL)4-M`~5cQtL(Im>LCnjzkH==%H6KOD9{s z`0Pv6k%YEM`XgxWh#R^PzUSnR){7dhzASLE3JK4#o!7DF8XS&ZsFhX0|5O@bn8jO_I|N=ewNHVW}IsKL!xklc<4Zv10O zDTQ`U?|ORjp`T#kJwisNr8RBn{H;|HkguWj{QPbaK6ndt+B2IWJ(XW^)iiBSq)k*CZ=wHukoZM zzTU{;>sG+mbF%SQ#UQ>GDWSL-Sxyf@d<~Rx2bE3nhg0n8kZYU`mrip*U|YUxTRG*Tjy=2SidM zjuT0*v7x0V$uQXRCF6UVfUj>2 zXBKRFJo+&I&NVrn=O*Xm^4kx;NiOKHjZ{JjiDNZkHbLsA-4-wD+hyJJ_C8WoWTXE$ zIkuhCdYQSFUGe$ZvYFO`)3SOQ(Wl{h zQPJ&K3S$OyZ>`Ks&rP`P4BLvJ?AYtGI!nD{k@9Y?FL1Z==l+1;lX8cGY+51G4lI5n zeP!`pJl0@o?%3CMw9jc%_6TC$cr>?NVt$MvOTL1_Q|P)_6{Ktb1nUt!Nx5Ws=B#$p z=7};50bDP!j;aSmFh<#5KfSU1t9(Yw85qfqt!pbjzewO1$qASF$;$Pv3+#WRNGdyS zjkl8v*`E)!a~@nhg2)bSIh(ViY4ya{8?NTRie$h|A}N@olJ_B%yssQ-9263ICn*pT zN&oM(4Z@kFe&AAE%~U|wV6scfDvF>6eqL7DPm%0-T|#q}R ztl6V__7ZK+3yw&pA)lJF)_4W4phhd?Tfay*&NB03qY1E@l;(A3K+FrMb%pF2D{TM>V{2W4lu`^=D8ZLE( z-FGtpZM(5Kv~9qlZE|Vgv4Tyb5N%toas)%jSP_c4ikp%Q$YgLGJ6I@>QT`&!h~vj< zt_}@7uUw`VmkdM_(DuGqAf#}F!K3LLbvS;WEA6qU6?D7cE1ywhIP#MklvCHqYF!sJ zu{ya=sGmdId0g7A;?g!R)qv_E{(5(>7rAaOhM&06s}2kyA=;i9l3s~dXPCoQ8Is}H z#Y1HHN-+l1)=}J}5vU1T`A|-M`VPSsgfr?Ucuph(59VVqt9ZreDsEWO4EYD)77@3+ zaX1>F?X8XE-)LJR%_{!Zl0L%ez(j(|jty)G9cG>e^wD(1`$PxTlA+Wjh_-zUCzI0{ zxeDp2cxe8ZsBb2pq}xazd7!8VOG)7M-!q(1UzcW+dyKD<_OKQGB_r?Y+e2e{ZHDRR z3xqI0A1%KO_q(3=9XS!Q=w^SUs<0Qpc+7a6-(cxX&D?v)+iGIzvI={R0avysnMSnz{NZslRq3 zESu}~h#YhOYoFTql1T2mCzxUyY{Q(v$lH*c(C1`ZKd(8BiGaQ1gfoF4u^xHFtk5+X z&1aeF4JN?We^^)F1d^1oo>_wH5Hf^zEePo0)M zUuU|nXWuaDC+v3-d>4D+#+P60@H35GK4fFIOdR$lglyICZuIt6qX z#NAaj6<|@RBd@AcpbPB1aU0ZcpLHU-rNT@wRRosFxPV$%_p^b8Awb>Vu-HvY)P1zx z;H1ETs>x#%_MV+Q4#HZ-Hsq5lc`aDTjexo>8r;GRWsJTzsQvHfdc%2?mDxshblJs6 zW&|hIBA6}Ve|`in^pRL@@=39Y!J8D_C3rtI}e4~#R|LV z2aa5|G0g>`;3`~E8eVwwk42@`0dx%#%1v;y>^61gHR?cf^o2W2gU^@xL57{Y!#_BL zyHc@NY?D3@=r7VG&5>_8dP#rk<-@Mtp8m9atHv0}uy_BZSYGmJ2uHFBrP>m;<~Q=^)sh{W$j97cwgDdu?%X6osc<$4_r$;Z|soDF!{wG`9P84U!p* zK%DCV4Qih_{47M>H$@C#8d!J;!_A9ZZA8{G(WsOnnx8bEqZCgB4ans7vr;c5mZ%%l z7I#zGOi%o%3Y>r0VX|AWXcOcrN8{Gqf^WRl4;GcMGB?db&nAU0Q8#0Wx({)wyO>Me z5?ty=Gy=gS0h#EDxU%c+3^x~N%F}wli}e+kYSI+6UDcTWabR` zo{JYsDUpvSIIpyhXSp|4febqWWZ1(Xs|g88g}h`WpxO9g#&G>Qk&f#dl!KHrH7w}FxMm0xD~Co2)NescGzSHokg=2W64U6#!fbLe<} zgqFKbCTaNzE(7SjLT7=|sA$xgTSd+u{n(`P@aPC);GKWpl9%Kam~N#; zf=FANV8C`*$7Ck?5vCgk(CQL-ybFSAfGJ5XKErF26elB%`IuFJt zUIif|))`IV6Qk{L?@Bxs1f#1uXMG0Ly=?x-rp_1Rx5u7$W?dgI>l>dRubg#ZVfJVS zGB>WRp_dicuUoB&A!APEKf{MxeErn6T=L!{X(+>fb9176jtylsJ+T*RW?mPre>vY- z4ZP%Z%LUi3b3NIv|4yw`uG~dj=B1hzy5^6=5Bj}z2M**#oR_%?a_uv}S;{+i0eau# zn93g$%8=0Tpp?MhxVy0E;cp=hDE!o7vP-#rpX{viUo7R@-d^#VSET}&T9Xk0LXC-3 zxmxW|-(3Ia`A%w0*$+#JLAAkDGTdOtr8bFLkte8H!V29V-je-0syzXBm$9?M_n80S zZm?~VagsjZ1_E@8^O%KC$J`MjiKI!LDXAQUSqt*Pq?=ukbqwk{@y<%DI_w}=} z*A(|6DXTSd+`f;p@8s=x9!p_qyOAWQ@3Yr4RyTG>G>5xuUjEA6b9{K zZ89~I{Felk1{>Be>q2g5GGoEs-nFEo`hsKyGh@< zTb;w*Y{1bVR@P9(dpSN;Ch{Cq^`R}3*ZezoLly6Yr8=a+ z5E80GV#RD;r(zX7K^-#UWZK!-pn@%6LMgR!0Fl%71>kiZpW7KpPkJgY$_b=6s<5rY z3@;NWN<=!ywX<4$e{%N-hr1!Id^1+mAO+0j;`t!$2X2@38RPf7P0W-_d>5~skDd8) z3s}mT^z6#d=%|!%%1iZF7V6E-Nqzorsgu>8&d&9si2&b^aHsG_cQX)mFQLp{MghBz}@*R zPelznfTcY4tEDtgxKYq9O##00!U=ms?dxMJV70H#M#GTj1I$FtkMr7wv(F~%E$a2S zJht2z1UO5UGBDxf(4l)alN|2;vs3!YaqP;QGL+At?{oYXH^3=fu+qgyDHfE00x|yo@@M-!Ihg!lLeiKUnL)ElquUa6K#ay9O zIGlDZShFc%L$CzsL%Kci4i*1}y&JElAIvyS{oTtS`8Er ziK>aajPZqLL+su0gT0S8bqsK$oRdGIoL4H|^}%9(66cFj&G!G?)0MqLg9<<_P5}s> z02P3&>{YgAj)4MD`mzkD0F)sL*c(3n8+%_~Vs9hfBv>9)0D{=Na#3Fxk3iBZ-p~7s zuE4cMyRI;$x$8fBFU&;ZI|kVv6Ihl6G@v}`EHuPnZw8mW5$>F%8$&g4hm!6pPvN>b zb0eD);Z5n*sK=SFlz{NLir+k4-L!7*5ZsbCN@bd*KnO z1XJJlL8|>u^8AG9_d{^=Aij~DTy)91SR8pIBNnXXjYdD;rJI=t?ZV`DnykwRBqPnv zWa}g9Wr`QS?R;;EV*9R>i)nq0orwO}CN@z%{npPi_6P!X>iV}Y{3n=O1^ow^m`ck@ zPr%-Gzq0peNH0=M&j8Lu2#bGYNrmZsY#{3w4I{eqN8kRw3-j;_a$1k#p=?6}8aYI~ zg3%HllR|F4J_#n5y9LyqG(p&X@WgqeHq#4T`7ckL6PW2Z9=yGvtjWwF|-yurIjD2g4}mz{aWN|o@eEw-4DB^ z)m9twXl_)?!9P2=@9U@MmKVxrIyeQO%duZS?Y+0p^YhN|fW_(Ihui_>w=e&uJ(}+! z4o4$fUjLSQU)oc?#oS2lg4G!d_mjVaH&|UZ{t5rd{|=Zl1eXw>cf^XhSo$;0=1?*s5QePI4~@YdO6^C}x{ozhE^j{lK+ zcY@se1<1Y6zezjQ%(rZti4TADFBd}oTB-$Ifoefh$mXc+BcK+fdZr;|tyuRpZruGi zW^d`H(P;E8J-miyjSsgi>6XARSar+Q{$Zp8;!W#$u{)qV{%J&61eC{5ZkAgrk5gwR zdFmqpcxyQb_T(JdtQVI8R+qW^g04&84O8QQH*7x}0&mI>@Lt63he8~C0NzV+x7kwM zt@R`BMnu$8WLID6xMl46Bg6swf);o2>SRfzs~*$cV})L;1$qOK0c_QpKh0r!67L_} zUFpKP5b}99Y8|vqD728n*(QXA5`kJqU5*iTkFZ$;YI(-xpCJx+U+_nR+zSG4hb8dV zh?BSiz}p3E6QFa`QfDJ&P3!Hd zWRpi3jmW|##>vffQC+|83(hueXu;!wnMAo4B5>yl)LAj-Z0%09B8@52EjxgjG>&73 zcAPvsQlr*>{O0YB_9K2un>r3B?49X2lYF~_!`z(_hnl)9(SbG>9k#Mo&34|*>{9FS ze0YA->n#F#jo&pAggC(g26AH3Hn}XYT*z=6kggy5EQ6hs*Bl5*-ch{iOuJK7{uH-9<`_V@HJnln%em)^}oy~Av4(%wtn&RPSX=# zzZmAbmUBa#>6X?1y3QnLJgI!M#bUyzD$Zcn%OEXkddS<$x5`UwE1S={9s3({2L=Zb zNnso-84W39v~sL*Xm~_WS_oC(*NZPp#mOx0+9AhDW|dViOP*zCRWSb&|vVp9d;{k^J_HlSE{|-A#Fblf3c|Cpj~0nPHLhGsRIpRTcFLbjl-zMW9ak z;NmVk#z{5Bu|Y=vifZr^D8*TeS5V&RrNHe>9)9V2HN8E{tl0PKmZdm{rofGJw4&Ki zoMX@&e{a9^a0kO89U%AHUy%Dzpy2;@Jn0>|LgEKC$%$NXEH-xN&khmc#p{EHk~8H^_>VbFLI?Gwv(htHwgTf@lqSC#C)OQEu1x8W4__q=->H}7^6(@}lDCdjNL4n*D1 z9i_jP@*GyMj0Ka5K4Qqwh*ESmNRF^6c@Od&IyMov67+%Me4rHPm+_>&wfuMPHv7)q z&MVWfiXnizqb?4=j}5DPEr;@Iv_AKss2eC^Ae9N04;>YFQsQ&TZn)|g>x{Vj5{!ZL zvT>ae1OwpYHH_1S{)vRVQC2$Kz{yRD1p851DXnMhTtJsKGtsHE0a{3?}F8E~rC z7I=l0qiQRi1Kl-KwQ=D9y7_0e?s^vf`z;**TmO_wA0U;>0Ce*_HHRm8hyMe*%}TxV zw{TarH!iJei|boOf>mwr(=ClDy_4yt0J=MWf$pMi+aIlJPWfDi`-{QGpF$SOF1SCF<$LFUr=gzI&^9P1%!xvUAct>`0?ac<#!54`&VenL0wFq!o`bf3B-c$~9!)9`&Uo6KFzW{GhYvkjre>q^ zShKl4)9?@I_MJJj)G@!l)G=qph?zyaPa--7-cJl^YZ!_r4qdZONH1uFpqozz%p?tl zkzr>_K)u`?3?{GdaH51isIs;Sy`dU7n(M6aM)9FNb;KsG#YA^3|M{79V+C#2N6w?D zRd~w%vMr+Qh{bmZk+rexP?B(FQ> z0y-&Uk8x zxV`%LZMDQxMkVW$lJ9&OPA<$U8Of;R)XS?~oDhF%!ra!AYuNMQ6(Q{FIL&$Ytxp_p zY8e3D7Rtdt*}eShbj!i@<)2<~7PC20Y4q2R!26ps6nOuOXOiG{;GrXZ2I^UN)ksh+ z$U0S-b#V6uBJq;-KY9CJ_?;ibodEgC1my?D#Ap(l4lW9EmbF2>oO>#)Sm|jtx+aVP=VLh?GCif6jFRzM{e<;%&x#{xT&iA?Ai%{gfaJi12 zQg2T1RUPVR7~JQ$<&?Ws4)dO`{y`0kF5moglkB6Fz5=={GG66aK8`<@-bT5-N!-Ht zd*W@C2_@d;3cHy1t{+f3D5>nC@XJNc;@s~#ISAU5)P0krCKb-R)Y*}Nh)Zgy&fTFnt#*IW^ zP~uPo1Mb?k8_6I^gc+jmG}O<%$hmWAW800y-Pm@9HnuzOCzFIcVaZYMAjSz&bp(?6 zAMf+ne~-NVAj!O;Z=jF{B5zi_gr|%`s@Ek2pZEg%2(Uae(>RiS--I-h;-_zCo#wyN zPl5kXBgrPEX3_dg0?y!^Qo>8~>zQ$H&OFX608TQiu;2ciZPDVpcy8UC>U$Z~%|n+B z7sJa1Q*<;+C(!uy1zr+-lksO1KJ~irMs}R2La!esyW)g}KEy4TKAKY{D^mpb`+S~U zjksyCCjmvRcRcA%h+@Xo2t0I_Gv8iU*8MwggVH2#xdc=%XS(-i!Zf2c=##9X#HKm* za)FIcjBh`CV}9%WSEKf0u1W>wW|z0mbey~pZU4$5HnZT>@yaeJ#sNoq9Ih9rI3|b& zeyr<-A1Lf{l&!Px{7b0+SKbaexa>2=uR?_?E5_zH$sJW)bcY~HoT`oOpPRe#7H^NV z|DCsIW9BEaPmtZ8;@8;i#j30UhhiEY;Ssnxy&D^m@&Xz{^=mByzRt8eWS7r&a+VT3 zE-cOshW)kpW#`cgU+0Z$1Ij_r{V(S2ygzTO+OJM*OgS6`T0wtwDK{MKvb*&6h#TSg0U%&XATrpN%=SNTjv6)u;z%K2gd*rWZtGl4JCJIcex^JvA4J?os-1-R z?K6_N9rL%T+>SZ?Dxwo~%(v}K2Oaa2LkBPy-MBl7KkgPU@wWPpI?zR^4wP%2_El5R-*ovqpwt~go{KZxz*ZBgFU-#zAJ2i1XeW0fO05qHPeUn6cu18&6q$&62v zliWZD6~R=p(sdhHR!re_yUN|)_SxO-wu0VD;Q0nuXVIpy@YSwM2Nj18!f9at=6l4w zjT3QCf`}U?7k^dwS-r9NPZPedOB#Lv28TL-rT|46=? zgKym2vM}{{_e9xrE9bfow_4s({_!aR?lRZ+SIdjJ!JGeTS!{Os^}dBm*iia~ixwB3~cF?7t`#LwasBtb@m~eL!%_5hY zKg*U*TioO{f0(@;xt3l<%m&V#Sss1~Zke3t7d50@qxLu418UehmvfvaiORV%`~A{S zo}1uBpoR=0f>%uu?F+w;>PN{%xO&NSDNNLqQ znZh}GcA}+%6KJP9z`>%;P;5a<_{ozL`>!C&rtW+43Y;s%=P@YPK61+ByF^Z)X6`ZI z$ai}Un7peO^C)bjxC;a3h7ZBhy!w>n9{DO3487$ZJ>#%7naZZ!f}4RM<(g4T7V?q} z6I!vMtU+xFg;isPFm8R^qi04-I;e4%TOqH9D&+pfiJ|0Ck$3Lkz}aBbCGMTsTZ1u9 zKiPWtJ5gU;B5I8&G0MvKi9|=r{rC$Y?*4vw`im?w1SHrAf9+T)e^*tHt-w#Hxi$n( zb0R&6#x=c4kE(3Mk1{G&@Mq*yN$HN}G|9Xf&E*_-Y%~GG#;su37?vZ^aN>T~cyeM? z$Cl!;tVK-~$C#3VoJd=z@h`;nJX3A_6Xip%BG*@pe9;0&&otT3kt-A_^*2|@se@CH zXxJqBg0-v)58mj2qXr-n9Zv*`xI}sCh?GCN8ycF zWy;gzH$F6N(BCnO%WI_ze!cuudwKN6XS;cu!=CGG&b;zs*TGCt=;+y13t5=>Dl5X3 z8zeg{h5iXst3+>jZBsZl^TzIx(ro9I_Vcq{7b_(P4@KD6+4G5sKh$W$!m=8~F3V8% zs`;OIKDYkP?qy)(=Ad%%yO0xE*9M|ajej19JrPK0#8W0gVx8FiZvEOs36G{q|2vlz zU!(cs%*Kj(vP#Fw2D|6SD|nYLOjZi7FZ)olI(uQPY~9c{!4}~U&eQz=%_H0YBi9YN zNj2x{e!Ker>h8?Hnmp4m972fM&@iD87R{G{lua5zVJa?|pn?d+1&T@)kO79kX|z+M zjMgmBuoWmEghdEo10-14s*;F85D2RaR*9t;6j9WUQ3RF2blxvP)YG0b%a8L<+~;}T z_qngjG>a8!>;uDn_Q?F6gXH6fB)@f8=&1V{3tMwJJQ9|>R4|NdCDOWgsQdbLxt4~O zK{U`d6q0J>ea8KR16M9zyLx@-#!vI%XKmhx9H0q;bDn8uKe>C`CGGcR;%l)2SV zx8-$=K%JM4zUPukABI%Oa3PIRYTrQX%rJ9{7^!Kn>CRrpjHnB5<7D6s1uH{Tfj5(n z6Ns|DlRU9MarMDb9ohDi6JCEuzjlCeKFmDJpxGg>Z#}Fd=XTCR&D3?pU@I25Y<=Hl z@$=dFlg1u!()i#6+vD_T0$x#I`KC#u+nl@Xj5CE0@0(PU@Vp9u>Z!;`DDmVR)z=Mo z%EJ)h9jM+ifUm6&L!@J+(Mw{edz5xU0NH*^d>kBsQ4|5&IQ54V1iT6QeEzz-vIMHB zP*2^TBG`M`n}{x<9}?`2ybKg|`k}3G{rl+^ok*OHY>P6BQ7;f5A<(EcN1zY^ZH&Wa z+XBPUZdy|!m$_I+wk?Q>;LM+NBh>mLwbiZ|B;Mi*ri@^!d2k@xOKTsQb>Ge17aRfh<-G|in-igp z^oe5|UDZ|P>yVCoQL^^0F(Sd@VgRpjm()~c!o}=-msp3B{9v^g_Hm1S2g-Wir#41b z$+OhNu~Yf6Y$@`l`Mgy$6k=-ooFs`#p9M+ zO<*RBZ@wPDiigRz@n^tHsQ-guq4NC@U$!-Zf^^0Uf1)Cto@u5E2_M+Iqjh>zdOGCg zHTjbZuLiBy7w5E2^%rNBg|ZbW!%X%C-SSGhy}XWf#Dd!*@7PJkR|A4ivw}Je(plyKR{=EmJaqQ6cQ}5r-=n|=9 zQ@(KuO_FPyyE~uA@ zDu!%Mt}Cq&eAuFQJRq_dvM`Z4nt~;`x@&?bndw_8>v+}4`*w?8_kLW>ghb=oaoB zj~|pv_2bxOCk|V!-emM_xof>fL_JKv{bqzwbC6~_yH2W_hjUk|`HMGW#*$5f*&MiJ z+@+H|8 z*mZozzuRELKznBkxg##KzEFJb=N78vBe|E#~N$b=E z>!TKI=pL}XDH%utitmAnI*Q|J6gZDkO$UMbm<@YC8ZMDPEq&Svk7J!nNZk4k+#gOX z|9|$aL)`YjKgtJr#}b20P$H%_F%Gc!VE`eA&r3-be3O=%iZscxKpw{D4dbW28(c}jA4T|uZq4x`hnh3-zKr%<<>IQu1!H(TGqw+ zu42vu2w^QqKoxv{46kb^T%ju)xjZ~7nNEJ!z6Iw)*K45ay1696C}gfCYxvHtwW zQ}+j}nB^|5Yo;IFXgYBFhgQ!QPe!ZuVyG27KF%tazn@ap`p+57?Y`{&tw)TWKdi`( zzOX-WN{i5b2puz=-2&UU$Pf?j7!t+@o**ipgxewjhqId9UmxlApC}X@P>jMB8qTk>`x^ZuWXKc3htio9#d}Y<2G$&kMk{m>U@H zQh9|qe=xnn&$s2$@0MpKI0Wd6~(4c-YbeegS}t;dF5nOXlUiHE?F;rTBUxH7W< literal 0 HcmV?d00001 diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/libs/README.md b/ecomp-sdk-app/src/main/webapp/app/policyApp/libs/README.md new file mode 100644 index 000000000..3aa457dbe --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/libs/README.md @@ -0,0 +1,48 @@ +tableExport.jquery.plugin +========================= + +

      Export HTML Table to

      +
        +
      • JSON +
      • XML +
      • PNG +
      • CSV +
      • TXT +
      • SQL +
      • MS-Word +
      • Ms-Excel +
      • Ms-Powerpoint +
      • PDF +
      + +Installation +============ +jquery Plugin
      +<script type="text/javascript" src="tableExport.js">
      +<script type="text/javascript" src="jquery.base64.js">
      +
      +PNG Export +========== +<script type="text/javascript" src="html2canvas.js"> + +PDF Export +========== +<script type="text/javascript" src="jspdf/libs/sprintf.js">
      +<script type="text/javascript" src="jspdf/jspdf.js">
      +<script type="text/javascript" src="jspdf/libs/base64.js">
      + +Usage +====== +onClick ="$('#tableID').tableExport({type:'pdf',escape:'false'});"
      + +Options +======= +separator: ','
      +ignoreColumn: [2,3],
      +tableName:'yourTableName'
      +type:'csv'
      +pdfFontSize:14
      +pdfLeftMargin:20
      +escape:'true'
      +htmlContent:'false'
      +consoleLog:'false'
      diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular-cookies/.bower.json b/ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular-cookies/.bower.json new file mode 100644 index 000000000..10e57c5c1 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular-cookies/.bower.json @@ -0,0 +1,19 @@ +{ + "name": "angular-cookies", + "version": "1.3.20", + "main": "./angular-cookies.js", + "ignore": [], + "dependencies": { + "angular": "1.3.20" + }, + "homepage": "https://github.com/angular/bower-angular-cookies", + "_release": "1.3.20", + "_resolution": { + "type": "version", + "tag": "v1.3.20", + "commit": "fe6acf196d30f65b2d75438c9f7d9eb283da0d6f" + }, + "_source": "git://github.com/angular/bower-angular-cookies.git", + "_target": "~1.3.17", + "_originalSource": "angular-cookies" +} \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular-cookies/README.md b/ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular-cookies/README.md new file mode 100644 index 000000000..7b190d346 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular-cookies/README.md @@ -0,0 +1,68 @@ +# packaged angular-cookies + +This repo is for distribution on `npm` and `bower`. The source for this module is in the +[main AngularJS repo](https://github.com/angular/angular.js/tree/master/src/ngCookies). +Please file issues and pull requests against that repo. + +## Install + +You can install this package either with `npm` or with `bower`. + +### npm + +```shell +npm install angular-cookies +``` + +Then add `ngCookies` as a dependency for your app: + +```javascript +angular.module('myApp', [require('angular-cookies')]); +``` + +### bower + +```shell +bower install angular-cookies +``` + +Add a ` +``` + +Then add `ngCookies` as a dependency for your app: + +```javascript +angular.module('myApp', ['ngCookies']); +``` + +## Documentation + +Documentation is available on the +[AngularJS docs site](http://docs.angularjs.org/api/ngCookies). + +## License + +The MIT License + +Copyright (c) 2010-2015 Google, Inc. http://angularjs.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular-cookies/angular-cookies.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular-cookies/angular-cookies.js new file mode 100644 index 000000000..d564aa251 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular-cookies/angular-cookies.js @@ -0,0 +1,207 @@ +/** + * @license AngularJS v1.3.20 + * (c) 2010-2014 Google, Inc. http://angularjs.org + * License: MIT + */ +(function(window, angular, undefined) {'use strict'; + +/** + * @ngdoc module + * @name ngCookies + * @description + * + * # ngCookies + * + * The `ngCookies` module provides a convenient wrapper for reading and writing browser cookies. + * + * + *
      + * + * See {@link ngCookies.$cookies `$cookies`} and + * {@link ngCookies.$cookieStore `$cookieStore`} for usage. + */ + + +angular.module('ngCookies', ['ng']). + /** + * @ngdoc service + * @name $cookies + * + * @description + * Provides read/write access to browser's cookies. + * + * Only a simple Object is exposed and by adding or removing properties to/from this object, new + * cookies are created/deleted at the end of current $eval. + * The object's properties can only be strings. + * + * Requires the {@link ngCookies `ngCookies`} module to be installed. + * + * @example + * + * ```js + * angular.module('cookiesExample', ['ngCookies']) + * .controller('ExampleController', ['$cookies', function($cookies) { + * // Retrieving a cookie + * var favoriteCookie = $cookies.myFavorite; + * // Setting a cookie + * $cookies.myFavorite = 'oatmeal'; + * }]); + * ``` + */ + factory('$cookies', ['$rootScope', '$browser', function($rootScope, $browser) { + var cookies = {}, + lastCookies = {}, + lastBrowserCookies, + runEval = false, + copy = angular.copy, + isUndefined = angular.isUndefined; + + //creates a poller fn that copies all cookies from the $browser to service & inits the service + $browser.addPollFn(function() { + var currentCookies = $browser.cookies(); + if (lastBrowserCookies != currentCookies) { //relies on browser.cookies() impl + lastBrowserCookies = currentCookies; + copy(currentCookies, lastCookies); + copy(currentCookies, cookies); + if (runEval) $rootScope.$apply(); + } + })(); + + runEval = true; + + //at the end of each eval, push cookies + //TODO: this should happen before the "delayed" watches fire, because if some cookies are not + // strings or browser refuses to store some cookies, we update the model in the push fn. + $rootScope.$watch(push); + + return cookies; + + + /** + * Pushes all the cookies from the service to the browser and verifies if all cookies were + * stored. + */ + function push() { + var name, + value, + browserCookies, + updated; + + //delete any cookies deleted in $cookies + for (name in lastCookies) { + if (isUndefined(cookies[name])) { + $browser.cookies(name, undefined); + delete lastCookies[name]; + } + } + + //update all cookies updated in $cookies + for (name in cookies) { + value = cookies[name]; + if (!angular.isString(value)) { + value = '' + value; + cookies[name] = value; + } + if (value !== lastCookies[name]) { + $browser.cookies(name, value); + lastCookies[name] = value; + updated = true; + } + } + + //verify what was actually stored + if (updated) { + browserCookies = $browser.cookies(); + + for (name in cookies) { + if (cookies[name] !== browserCookies[name]) { + //delete or reset all cookies that the browser dropped from $cookies + if (isUndefined(browserCookies[name])) { + delete cookies[name]; + delete lastCookies[name]; + } else { + cookies[name] = lastCookies[name] = browserCookies[name]; + } + } + } + } + } + }]). + + + /** + * @ngdoc service + * @name $cookieStore + * @requires $cookies + * + * @description + * Provides a key-value (string-object) storage, that is backed by session cookies. + * Objects put or retrieved from this storage are automatically serialized or + * deserialized by angular's toJson/fromJson. + * + * Requires the {@link ngCookies `ngCookies`} module to be installed. + * + * @example + * + * ```js + * angular.module('cookieStoreExample', ['ngCookies']) + * .controller('ExampleController', ['$cookieStore', function($cookieStore) { + * // Put cookie + * $cookieStore.put('myFavorite','oatmeal'); + * // Get cookie + * var favoriteCookie = $cookieStore.get('myFavorite'); + * // Removing a cookie + * $cookieStore.remove('myFavorite'); + * }]); + * ``` + */ + factory('$cookieStore', ['$cookies', function($cookies) { + + return { + /** + * @ngdoc method + * @name $cookieStore#get + * + * @description + * Returns the value of given cookie key + * + * @param {string} key Id to use for lookup. + * @returns {Object} Deserialized cookie value. + */ + get: function(key) { + var value = $cookies[key]; + return value ? angular.fromJson(value) : value; + }, + + /** + * @ngdoc method + * @name $cookieStore#put + * + * @description + * Sets a value for given cookie key + * + * @param {string} key Id for the `value`. + * @param {Object} value Value to be stored. + */ + put: function(key, value) { + $cookies[key] = angular.toJson(value); + }, + + /** + * @ngdoc method + * @name $cookieStore#remove + * + * @description + * Remove given cookie + * + * @param {string} key Id of the key-value pair to delete. + */ + remove: function(key) { + delete $cookies[key]; + } + }; + + }]); + + +})(window, window.angular); diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular-cookies/angular-cookies.min.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular-cookies/angular-cookies.min.js new file mode 100644 index 000000000..f73736b53 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular-cookies/angular-cookies.min.js @@ -0,0 +1,8 @@ +/* + AngularJS v1.3.20 + (c) 2010-2014 Google, Inc. http://angularjs.org + License: MIT +*/ +(function(p,g,n){'use strict';g.module("ngCookies",["ng"]).factory("$cookies",["$rootScope","$browser",function(e,b){var c={},f={},h,k=!1,l=g.copy,m=g.isUndefined;b.addPollFn(function(){var a=b.cookies();h!=a&&(h=a,l(a,f),l(a,c),k&&e.$apply())})();k=!0;e.$watch(function(){var a,d,e;for(a in f)m(c[a])&&(b.cookies(a,n),delete f[a]);for(a in c)d=c[a],g.isString(d)||(d=""+d,c[a]=d),d!==f[a]&&(b.cookies(a,d),f[a]=d,e=!0);if(e)for(a in d=b.cookies(),c)c[a]!==d[a]&&(m(d[a])?(delete c[a],delete f[a]):c[a]= +f[a]=d[a])});return c}]).factory("$cookieStore",["$cookies",function(e){return{get:function(b){return(b=e[b])?g.fromJson(b):b},put:function(b,c){e[b]=g.toJson(c)},remove:function(b){delete e[b]}}}])})(window,window.angular); +//# sourceMappingURL=angular-cookies.min.js.map diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular-cookies/angular-cookies.min.js.map b/ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular-cookies/angular-cookies.min.js.map new file mode 100644 index 000000000..87491ad1b --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular-cookies/angular-cookies.min.js.map @@ -0,0 +1,8 @@ +{ +"version":3, +"file":"angular-cookies.min.js", +"lineCount":7, +"mappings":"A;;;;;aAKC,SAAQ,CAACA,CAAD,CAASC,CAAT,CAAkBC,CAAlB,CAA6B,CAmBtCD,CAAAE,OAAA,CAAe,WAAf,CAA4B,CAAC,IAAD,CAA5B,CAAAC,QAAA,CA0BW,UA1BX,CA0BuB,CAAC,YAAD,CAAe,UAAf,CAA2B,QAAQ,CAACC,CAAD,CAAaC,CAAb,CAAuB,CAAA,IACvEC,EAAU,EAD6D,CAEvEC,EAAc,EAFyD,CAGvEC,CAHuE,CAIvEC,EAAU,CAAA,CAJ6D,CAKvEC,EAAOV,CAAAU,KALgE,CAMvEC,EAAcX,CAAAW,YAGlBN,EAAAO,UAAA,CAAmB,QAAQ,EAAG,CAC5B,IAAIC,EAAiBR,CAAAC,QAAA,EACjBE,EAAJ,EAA0BK,CAA1B,GACEL,CAGA,CAHqBK,CAGrB,CAFAH,CAAA,CAAKG,CAAL,CAAqBN,CAArB,CAEA,CADAG,CAAA,CAAKG,CAAL,CAAqBP,CAArB,CACA,CAAIG,CAAJ,EAAaL,CAAAU,OAAA,EAJf,CAF4B,CAA9B,CAAA,EAUAL,EAAA,CAAU,CAAA,CAKVL,EAAAW,OAAA,CASAC,QAAa,EAAG,CAAA,IACVC,CADU,CAEVC,CAFU,CAIVC,CAGJ,KAAKF,CAAL,GAAaV,EAAb,CACMI,CAAA,CAAYL,CAAA,CAAQW,CAAR,CAAZ,CAAJ,GACEZ,CAAAC,QAAA,CAAiBW,CAAjB,CAAuBhB,CAAvB,CACA,CAAA,OAAOM,CAAA,CAAYU,CAAZ,CAFT,CAOF,KAAKA,CAAL,GAAaX,EAAb,CACEY,CAKA,CALQZ,CAAA,CAAQW,CAAR,CAKR,CAJKjB,CAAAoB,SAAA,CAAiBF,CAAjB,CAIL,GAHEA,CACA,CADQ,EACR,CADaA,CACb,CAAAZ,CAAA,CAAQW,CAAR,CAAA,CAAgBC,CAElB,EAAIA,CAAJ,GAAcX,CAAA,CAAYU,CAAZ,CAAd,GACEZ,CAAAC,QAAA,CAAiBW,CAAjB,CAAuBC,CAAvB,CAEA,CADAX,CAAA,CAAYU,CAAZ,CACA,CADoBC,CACpB,CAAAC,CAAA,CAAU,CAAA,CAHZ,CAQF,IAAIA,CAAJ,CAGE,IAAKF,CAAL,GAFAI,EAEaf,CAFID,CAAAC,QAAA,EAEJA,CAAAA,CAAb,CACMA,CAAA,CAAQW,CAAR,CAAJ,GAAsBI,CAAA,CAAeJ,CAAf,CAAtB,GAEMN,CAAA,CAAYU,CAAA,CAAeJ,CAAf,CAAZ,CAAJ,EACE,OAAOX,CAAA,CAAQW,CAAR,CACP,CAAA,OAAOV,CAAA,CAAYU,CAAZ,CAFT,EAIEX,CAAA,CAAQW,CAAR,CAJF;AAIkBV,CAAA,CAAYU,CAAZ,CAJlB,CAIsCI,CAAA,CAAeJ,CAAf,CANxC,CAjCU,CAThB,CAEA,OAAOX,EA1BoE,CAA1D,CA1BvB,CAAAH,QAAA,CAqIW,cArIX,CAqI2B,CAAC,UAAD,CAAa,QAAQ,CAACmB,CAAD,CAAW,CAErD,MAAO,CAWLC,IAAKA,QAAQ,CAACC,CAAD,CAAM,CAEjB,MAAO,CADHN,CACG,CADKI,CAAA,CAASE,CAAT,CACL,EAAQxB,CAAAyB,SAAA,CAAiBP,CAAjB,CAAR,CAAkCA,CAFxB,CAXd,CA0BLQ,IAAKA,QAAQ,CAACF,CAAD,CAAMN,CAAN,CAAa,CACxBI,CAAA,CAASE,CAAT,CAAA,CAAgBxB,CAAA2B,OAAA,CAAeT,CAAf,CADQ,CA1BrB,CAuCLU,OAAQA,QAAQ,CAACJ,CAAD,CAAM,CACpB,OAAOF,CAAA,CAASE,CAAT,CADa,CAvCjB,CAF8C,CAAhC,CArI3B,CAnBsC,CAArC,CAAD,CAyMGzB,MAzMH,CAyMWA,MAAAC,QAzMX;", +"sources":["angular-cookies.js"], +"names":["window","angular","undefined","module","factory","$rootScope","$browser","cookies","lastCookies","lastBrowserCookies","runEval","copy","isUndefined","addPollFn","currentCookies","$apply","$watch","push","name","value","updated","isString","browserCookies","$cookies","get","key","fromJson","put","toJson","remove"] +} diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular-cookies/bower.json b/ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular-cookies/bower.json new file mode 100644 index 000000000..d4075a279 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular-cookies/bower.json @@ -0,0 +1,9 @@ +{ + "name": "angular-cookies", + "version": "1.3.20", + "main": "./angular-cookies.js", + "ignore": [], + "dependencies": { + "angular": "1.3.20" + } +} diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular-cookies/index.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular-cookies/index.js new file mode 100644 index 000000000..657667549 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular-cookies/index.js @@ -0,0 +1,2 @@ +require('./angular-cookies'); +module.exports = 'ngCookies'; diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular-cookies/package.json b/ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular-cookies/package.json new file mode 100644 index 000000000..97e74204f --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular-cookies/package.json @@ -0,0 +1,26 @@ +{ + "name": "angular-cookies", + "version": "1.3.20", + "description": "AngularJS module for cookies", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "https://github.com/angular/angular.js.git" + }, + "keywords": [ + "angular", + "framework", + "browser", + "cookies", + "client-side" + ], + "author": "Angular Core Team ", + "license": "MIT", + "bugs": { + "url": "https://github.com/angular/angular.js/issues" + }, + "homepage": "http://angularjs.org" +} diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular-translate/angular-translate.min.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular-translate/angular-translate.min.js new file mode 100644 index 000000000..933deba79 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular-translate/angular-translate.min.js @@ -0,0 +1,6 @@ +/*! + * angular-translate - v2.9.1 - 2016-02-13 + * + * Copyright (c) 2016 The angular-translate team, Pascal Precht; Licensed MIT + */ +!function(a,b){"function"==typeof define&&define.amd?define([],function(){return b()}):"object"==typeof exports?module.exports=b():b()}(this,function(){function a(a){"use strict";var b=a.storageKey(),c=a.storage(),d=function(){var d=a.preferredLanguage();angular.isString(d)?a.use(d):c.put(b,a.use())};d.displayName="fallbackFromIncorrectStorageValue",c?c.get(b)?a.use(c.get(b))["catch"](d):d():angular.isString(a.preferredLanguage())&&a.use(a.preferredLanguage())}function b(){"use strict";var a,b,c=null,d=!1,e=!1;b={sanitize:function(a,b){return"text"===b&&(a=g(a)),a},escape:function(a,b){return"text"===b&&(a=f(a)),a},sanitizeParameters:function(a,b){return"params"===b&&(a=h(a,g)),a},escapeParameters:function(a,b){return"params"===b&&(a=h(a,f)),a}},b.escaped=b.escapeParameters,this.addStrategy=function(a,c){return b[a]=c,this},this.removeStrategy=function(a){return delete b[a],this},this.useStrategy=function(a){return d=!0,c=a,this},this.$get=["$injector","$log",function(f,g){var h={},i=function(a,c,d){return angular.forEach(d,function(d){if(angular.isFunction(d))a=d(a,c);else if(angular.isFunction(b[d]))a=b[d](a,c);else{if(!angular.isString(b[d]))throw new Error("pascalprecht.translate.$translateSanitization: Unknown sanitization strategy: '"+d+"'");if(!h[b[d]])try{h[b[d]]=f.get(b[d])}catch(e){throw h[b[d]]=function(){},new Error("pascalprecht.translate.$translateSanitization: Unknown sanitization strategy: '"+d+"'")}a=h[b[d]](a,c)}}),a},j=function(){d||e||(g.warn("pascalprecht.translate.$translateSanitization: No sanitization strategy has been configured. This can have serious security implications. See http://angular-translate.github.io/docs/#/guide/19_security for details."),e=!0)};return f.has("$sanitize")&&(a=f.get("$sanitize")),{useStrategy:function(a){return function(b){a.useStrategy(b)}}(this),sanitize:function(a,b,d){if(c||j(),arguments.length<3&&(d=c),!d)return a;var e=angular.isArray(d)?d:[d];return i(a,b,e)}}}];var f=function(a){var b=angular.element("
      ");return b.text(a),b.html()},g=function(b){if(!a)throw new Error("pascalprecht.translate.$translateSanitization: Error cannot find $sanitize service. Either include the ngSanitize module (https://docs.angularjs.org/api/ngSanitize) or use a sanitization strategy which does not depend on $sanitize, such as 'escape'.");return a(b)},h=function(a,b){if(angular.isObject(a)){var c=angular.isArray(a)?[]:{};return angular.forEach(a,function(a,d){c[d]=h(a,b)}),c}return angular.isNumber(a)?a:b(a)}}function c(a,b,c,d){"use strict";var e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t={},u=[],v=a,w=[],x="translate-cloak",y=!1,z=!1,A=".",B=!1,C=0,D=!0,E="default",F={"default":function(a){return(a||"").split("-").join("_")},java:function(a){var b=(a||"").split("-").join("_"),c=b.split("_");return c.length>1?c[0].toLowerCase()+"_"+c[1].toUpperCase():b},bcp47:function(a){var b=(a||"").split("_").join("-"),c=b.split("-");return c.length>1?c[0].toLowerCase()+"-"+c[1].toUpperCase():b}},G="2.9.1",H=function(){if(angular.isFunction(d.getLocale))return d.getLocale();var a,c,e=b.$get().navigator,f=["language","browserLanguage","systemLanguage","userLanguage"];if(angular.isArray(e.languages))for(a=0;ac;c++)if(a[c]===b)return c;return-1},K=function(){return this.toString().replace(/^\s+|\s+$/g,"")},L=function(a){if(a){for(var b=[],c=angular.lowercase(a),d=0,e=u.length;e>d;d++)b.push(angular.lowercase(u[d]));if(J(b,c)>-1)return a;if(f){var g;for(var h in f){var i=!1,j=Object.prototype.hasOwnProperty.call(f,h)&&angular.lowercase(h)===angular.lowercase(a);if("*"===h.slice(-1)&&(i=h.slice(0,-1)===a.slice(0,h.length-1)),(j||i)&&(g=f[h],J(b,angular.lowercase(g))>-1))return g}}var k=a.split("_");return k.length>1&&J(b,angular.lowercase(k[0]))>-1?k[0]:void 0}},M=function(a,b){if(!a&&!b)return t;if(a&&!b){if(angular.isString(a))return t[a]}else angular.isObject(t[a])||(t[a]={}),angular.extend(t[a],N(b));return this};this.translations=M,this.cloakClassName=function(a){return a?(x=a,this):x},this.nestedObjectDelimeter=function(a){return a?(A=a,this):A};var N=function(a,b,c,d){var e,f,g,h;b||(b=[]),c||(c={});for(e in a)Object.prototype.hasOwnProperty.call(a,e)&&(h=a[e],angular.isObject(h)?N(h,b.concat(e),c,e):(f=b.length?""+b.join(A)+A+e:e,b.length&&e===d&&(g=""+b.join(A),c[g]="@:"+f),c[f]=h));return c};N.displayName="flatObject",this.addInterpolation=function(a){return w.push(a),this},this.useMessageFormatInterpolation=function(){return this.useInterpolation("$translateMessageFormatInterpolation")},this.useInterpolation=function(a){return n=a,this},this.useSanitizeValueStrategy=function(a){return c.useStrategy(a),this},this.preferredLanguage=function(a){return a?(O(a),this):e};var O=function(a){return a&&(e=a),e};this.translationNotFoundIndicator=function(a){return this.translationNotFoundIndicatorLeft(a),this.translationNotFoundIndicatorRight(a),this},this.translationNotFoundIndicatorLeft=function(a){return a?(q=a,this):q},this.translationNotFoundIndicatorRight=function(a){return a?(r=a,this):r},this.fallbackLanguage=function(a){return P(a),this};var P=function(a){return a?(angular.isString(a)?(h=!0,g=[a]):angular.isArray(a)&&(h=!1,g=a),angular.isString(e)&&J(g,e)<0&&g.push(e),this):h?g[0]:g};this.use=function(a){if(a){if(!t[a]&&!o)throw new Error("$translateProvider couldn't find translationTable for langKey: '"+a+"'");return i=a,this}return i};var Q=function(a){return a?(v=a,this):l?l+v:v};this.storageKey=Q,this.useUrlLoader=function(a,b){return this.useLoader("$translateUrlLoader",angular.extend({url:a},b))},this.useStaticFilesLoader=function(a){return this.useLoader("$translateStaticFilesLoader",a)},this.useLoader=function(a,b){return o=a,p=b||{},this},this.useLocalStorage=function(){return this.useStorage("$translateLocalStorage")},this.useCookieStorage=function(){return this.useStorage("$translateCookieStorage")},this.useStorage=function(a){return k=a,this},this.storagePrefix=function(a){return a?(l=a,this):a},this.useMissingTranslationHandlerLog=function(){return this.useMissingTranslationHandler("$translateMissingTranslationHandlerLog")},this.useMissingTranslationHandler=function(a){return m=a,this},this.usePostCompiling=function(a){return y=!!a,this},this.forceAsyncReload=function(a){return z=!!a,this},this.uniformLanguageTag=function(a){return a?angular.isString(a)&&(a={standard:a}):a={},E=a.standard,this},this.determinePreferredLanguage=function(a){var b=a&&angular.isFunction(a)?a():I();return e=u.length?L(b)||b:b,this},this.registerAvailableLanguageKeys=function(a,b){return a?(u=a,b&&(f=b),this):u},this.useLoaderCache=function(a){return a===!1?s=void 0:a===!0?s=!0:"undefined"==typeof a?s="$translationCache":a&&(s=a),this},this.directivePriority=function(a){return void 0===a?C:(C=a,this)},this.statefulFilter=function(a){return void 0===a?D:(D=a,this)},this.$get=["$log","$injector","$rootScope","$q",function(a,b,c,d){var f,l,u,E=b.get(n||"$translateDefaultInterpolation"),F=!1,H={},I={},R=function(a,b,c,h,j){var m=j&&j!==i?L(j)||j:i;if(angular.isArray(a)){var n=function(a){for(var e={},f=[],g=function(a){var f=d.defer(),g=function(b){e[a]=b,f.resolve([a,b])};return R(a,b,c,h,j).then(g,g),f.promise},i=0,k=a.length;k>i;i++)f.push(g(a[i]));return d.all(f).then(function(){return e})};return n(a)}var o=d.defer();a&&(a=K.apply(a));var p=function(){var a=e?I[e]:I[m];if(l=0,k&&!a){var b=f.get(v);if(a=I[b],g&&g.length){var c=J(g,b);l=0===c?1:0,J(g,e)<0&&g.push(e)}}return a}();if(p){var q=function(){j||(m=i),ca(a,b,c,h,m).then(o.resolve,o.reject)};q.displayName="promiseResolved",p["finally"](q,o.reject)}else ca(a,b,c,h,m).then(o.resolve,o.reject);return o.promise},S=function(a){return q&&(a=[q,a].join(" ")),r&&(a=[a,r].join(" ")),a},T=function(a){i=a,k&&f.put(R.storageKey(),i),c.$emit("$translateChangeSuccess",{language:a}),E.setLocale(i);var b=function(a,b){H[b].setLocale(i)};b.displayName="eachInterpolatorLocaleSetter",angular.forEach(H,b),c.$emit("$translateChangeEnd",{language:a})},U=function(a){if(!a)throw"No language key specified for loading.";var e=d.defer();c.$emit("$translateLoadingStart",{language:a}),F=!0;var f=s;"string"==typeof f&&(f=b.get(f));var g=angular.extend({},p,{key:a,$http:angular.extend({},{cache:f},p.$http)}),h=function(b){var d={};c.$emit("$translateLoadingSuccess",{language:a}),angular.isArray(b)?angular.forEach(b,function(a){angular.extend(d,N(a))}):angular.extend(d,N(b)),F=!1,e.resolve({key:a,table:d}),c.$emit("$translateLoadingEnd",{language:a})};h.displayName="onLoaderSuccess";var i=function(a){c.$emit("$translateLoadingError",{language:a}),e.reject(a),c.$emit("$translateLoadingEnd",{language:a})};return i.displayName="onLoaderError",b.get(o)(g).then(h,i),e.promise};if(k&&(f=b.get(k),!f.get||!f.put))throw new Error("Couldn't use storage '"+k+"', missing get() or put() method!");if(w.length){var V=function(a){var c=b.get(a);c.setLocale(e||i),H[c.getInterpolationIdentifier()]=c};V.displayName="interpolationFactoryAdder",angular.forEach(w,V)}var W=function(a){var b=d.defer();if(Object.prototype.hasOwnProperty.call(t,a))b.resolve(t[a]);else if(I[a]){var c=function(a){M(a.key,a.table),b.resolve(a.table)};c.displayName="translationTableResolver",I[a].then(c,b.reject)}else b.reject();return b.promise},X=function(a,b,c,e){var f=d.defer(),g=function(d){if(Object.prototype.hasOwnProperty.call(d,b)){e.setLocale(a);var g=d[b];"@:"===g.substr(0,2)?X(a,g.substr(2),c,e).then(f.resolve,f.reject):f.resolve(e.interpolate(d[b],c)),e.setLocale(i)}else f.reject()};return g.displayName="fallbackTranslationResolver",W(a).then(g,f.reject),f.promise},Y=function(a,b,c,d){var e,f=t[a];if(f&&Object.prototype.hasOwnProperty.call(f,b)){if(d.setLocale(a),e=d.interpolate(f[b],c),"@:"===e.substr(0,2))return Y(a,e.substr(2),c,d);d.setLocale(i)}return e},Z=function(a,c){if(m){var d=b.get(m)(a,i,c);return void 0!==d?d:a}return a},$=function(a,b,c,e,f){var h=d.defer();if(a0?u:l,a,b,c,d)},ba=function(a,b,c){return _(u>0?u:l,a,b,c)},ca=function(a,b,c,e,f){var h=d.defer(),i=f?t[f]:t,j=c?H[c]:E;if(i&&Object.prototype.hasOwnProperty.call(i,a)){var k=i[a];"@:"===k.substr(0,2)?R(k.substr(2),b,c,e,f).then(h.resolve,h.reject):h.resolve(j.interpolate(k,b))}else{var l;m&&!F&&(l=Z(a,b)),f&&g&&g.length?aa(a,b,j,e).then(function(a){h.resolve(a)},function(a){h.reject(S(a))}):m&&!F&&l?e?h.resolve(e):h.resolve(l):e?h.resolve(e):h.reject(S(a))}return h.promise},da=function(a,b,c,d){var e,f=d?t[d]:t,h=E;if(H&&Object.prototype.hasOwnProperty.call(H,c)&&(h=H[c]),f&&Object.prototype.hasOwnProperty.call(f,a)){var i=f[a];e="@:"===i.substr(0,2)?da(i.substr(2),b,c,d):h.interpolate(i,b)}else{var j;m&&!F&&(j=Z(a,b)),d&&g&&g.length?(l=0,e=ba(a,b,h)):e=m&&!F&&j?j:S(a)}return e},ea=function(a){j===a&&(j=void 0),I[a]=void 0};R.preferredLanguage=function(a){return a&&O(a),e},R.cloakClassName=function(){return x},R.nestedObjectDelimeter=function(){return A},R.fallbackLanguage=function(a){if(void 0!==a&&null!==a){if(P(a),o&&g&&g.length)for(var b=0,c=g.length;c>b;b++)I[g[b]]||(I[g[b]]=U(g[b]));R.use(R.use())}return h?g[0]:g},R.useFallbackLanguage=function(a){if(void 0!==a&&null!==a)if(a){var b=J(g,a);b>-1&&(u=b)}else u=0},R.proposedLanguage=function(){return j},R.storage=function(){return f},R.negotiateLocale=L,R.use=function(a){if(!a)return i;var b=d.defer();c.$emit("$translateChangeStart",{language:a});var e=L(a);return e&&(a=e),!z&&t[a]||!o||I[a]?j===a&&I[a]?I[a].then(function(a){return b.resolve(a.key),a},function(a){return b.reject(a),d.reject(a)}):(b.resolve(a),T(a)):(j=a,I[a]=U(a).then(function(c){return M(c.key,c.table),b.resolve(c.key),j===a&&T(c.key),c},function(a){return c.$emit("$translateChangeError",{language:a}),b.reject(a),c.$emit("$translateChangeEnd",{language:a}),d.reject(a)}),I[a]["finally"](function(){ea(a)})),b.promise},R.storageKey=function(){return Q()},R.isPostCompilingEnabled=function(){return y},R.isForceAsyncReloadEnabled=function(){return z},R.refresh=function(a){function b(){f.resolve(),c.$emit("$translateRefreshEnd",{language:a})}function e(){f.reject(),c.$emit("$translateRefreshEnd",{language:a})}if(!o)throw new Error("Couldn't refresh translation table, no loader registered!");var f=d.defer();if(c.$emit("$translateRefreshStart",{language:a}),a)if(t[a]){var h=function(c){M(c.key,c.table),a===i&&T(i),b()};h.displayName="refreshPostProcessor",U(a).then(h,e)}else e();else{var j=[],k={};if(g&&g.length)for(var l=0,m=g.length;m>l;l++)j.push(U(g[l])),k[g[l]]=!0;i&&!k[i]&&j.push(U(i));var n=function(a){t={},angular.forEach(a,function(a){M(a.key,a.table)}),i&&T(i),b()};n.displayName="refreshPostProcessor",d.all(j).then(n,e)}return f.promise},R.instant=function(a,b,c,d){var f=d&&d!==i?L(d)||d:i;if(null===a||angular.isUndefined(a))return a;if(angular.isArray(a)){for(var h={},j=0,k=a.length;k>j;j++)h[a[j]]=R.instant(a[j],b,c,d);return h}if(angular.isString(a)&&a.length<1)return a;a&&(a=K.apply(a));var l,n=[];e&&n.push(e),f&&n.push(f),g&&g.length&&(n=n.concat(g));for(var o=0,p=n.length;p>o;o++){var s=n[o];if(t[s]&&"undefined"!=typeof t[s][a]&&(l=da(a,b,c,f)),"undefined"!=typeof l)break}return l||""===l||(q||r?l=S(a):(l=E.interpolate(a,b),m&&!F&&(l=Z(a,b)))),l},R.versionInfo=function(){return G},R.loaderCache=function(){return s},R.directivePriority=function(){return C},R.statefulFilter=function(){return D},R.isReady=function(){return B};var fa=d.defer();fa.promise.then(function(){B=!0}),R.onReady=function(a){var b=d.defer();return angular.isFunction(a)&&b.promise.then(a),B?b.resolve():fa.promise.then(b.resolve),b.promise};var ga=c.$on("$translateReady",function(){fa.resolve(),ga(),ga=null}),ha=c.$on("$translateChangeEnd",function(){fa.resolve(),ha(),ha=null});if(o){if(angular.equals(t,{})&&R.use()&&R.use(R.use()),g&&g.length)for(var ia=function(a){return M(a.key,a.table),c.$emit("$translateChangeEnd",{language:a.key}),a},ja=0,ka=g.length;ka>ja;ja++){var la=g[ja];(z||!t[la])&&(I[la]=U(la).then(ia))}}else c.$emit("$translateReady",{language:R.use()});return R}]}function d(a,b){"use strict";var c,d={},e="default";return d.setLocale=function(a){c=a},d.getInterpolationIdentifier=function(){return e},d.useSanitizeValueStrategy=function(a){return b.useStrategy(a),this},d.interpolate=function(c,d){d=d||{},d=b.sanitize(d,"params");var e=a(c)(d);return e=b.sanitize(e,"text")},d}function e(a,b,c,d,e,g){"use strict";var h=function(){return this.toString().replace(/^\s+|\s+$/g,"")};return{restrict:"AE",scope:!0,priority:a.directivePriority(),compile:function(b,i){var j=i.translateValues?i.translateValues:void 0,k=i.translateInterpolation?i.translateInterpolation:void 0,l=b[0].outerHTML.match(/translate-value-+/i),m="^(.*)("+c.startSymbol()+".*"+c.endSymbol()+")(.*)",n="^(.*)"+c.startSymbol()+"(.*)"+c.endSymbol()+"(.*)";return function(b,o,p){b.interpolateParams={},b.preText="",b.postText="",b.translateNamespace=f(b);var q={},r=function(a,c,d){if(c.translateValues&&angular.extend(a,e(c.translateValues)(b.$parent)),l)for(var f in d)if(Object.prototype.hasOwnProperty.call(c,f)&&"translateValue"===f.substr(0,14)&&"translateValues"!==f){var g=angular.lowercase(f.substr(14,1))+f.substr(15);a[g]=d[f]}},s=function(a){if(angular.isFunction(s._unwatchOld)&&(s._unwatchOld(),s._unwatchOld=void 0),angular.equals(a,"")||!angular.isDefined(a)){var d=h.apply(o.text()),e=d.match(m);if(angular.isArray(e)){b.preText=e[1],b.postText=e[3],q.translate=c(e[2])(b.$parent);var f=d.match(n);angular.isArray(f)&&f[2]&&f[2].length&&(s._unwatchOld=b.$watch(f[2],function(a){q.translate=a,y()}))}else q.translate=d?d:void 0}else q.translate=a;y()},t=function(a){p.$observe(a,function(b){q[a]=b,y()})};r(b.interpolateParams,p,i);var u=!0;p.$observe("translate",function(a){"undefined"==typeof a?s(""):""===a&&u||(q.translate=a,y()),u=!1});for(var v in p)p.hasOwnProperty(v)&&"translateAttr"===v.substr(0,13)&&t(v);if(p.$observe("translateDefault",function(a){b.defaultText=a,y()}),j&&p.$observe("translateValues",function(a){a&&b.$parent.$watch(function(){angular.extend(b.interpolateParams,e(a)(b.$parent))})}),l){var w=function(a){p.$observe(a,function(c){var d=angular.lowercase(a.substr(14,1))+a.substr(15);b.interpolateParams[d]=c})};for(var x in p)Object.prototype.hasOwnProperty.call(p,x)&&"translateValue"===x.substr(0,14)&&"translateValues"!==x&&w(x)}var y=function(){for(var a in q)q.hasOwnProperty(a)&&void 0!==q[a]&&z(a,q[a],b,b.interpolateParams,b.defaultText,b.translateNamespace)},z=function(b,c,d,e,f,g){c?(g&&"."===c.charAt(0)&&(c=g+c),a(c,e,k,f,d.translateLanguage).then(function(a){A(a,d,!0,b)},function(a){A(a,d,!1,b)})):A(c,d,!1,b)},A=function(b,c,e,f){if("translate"===f){e||"undefined"==typeof c.defaultText||(b=c.defaultText),o.empty().append(c.preText+b+c.postText);var g=a.isPostCompilingEnabled(),h="undefined"!=typeof i.translateCompile,j=h&&"false"!==i.translateCompile;(g&&!h||j)&&d(o.contents())(c)}else{e||"undefined"==typeof c.defaultText||(b=c.defaultText);var k=p.$attr[f];"data-"===k.substr(0,5)&&(k=k.substr(5)),k=k.substr(15),o.attr(k,b)}};(j||l||p.translateDefault)&&b.$watch("interpolateParams",y,!0),b.$watch("translateLanguage",y);var B=g.$on("$translateChangeSuccess",y);o.text().length?s(p.translate?p.translate:""):p.translate&&s(p.translate),y(),b.$on("$destroy",B)}}}}function f(a){"use strict";return a.translateNamespace?a.translateNamespace:a.$parent?f(a.$parent):void 0}function g(a,b){"use strict";return{compile:function(c){var d=function(){c.addClass(a.cloakClassName())},e=function(){c.removeClass(a.cloakClassName())};return a.onReady(function(){e()}),d(),function(c,f,g){g.translateCloak&&g.translateCloak.length&&(g.$observe("translateCloak",function(b){a(b).then(e,d)}),b.$on("$translateChangeSuccess",function(){a(g.translateCloak).then(e,d)}))}}}}function h(){"use strict";return{restrict:"A",scope:!0,compile:function(){return{pre:function(a,b,c){a.translateNamespace=f(a),a.translateNamespace&&"."===c.translateNamespace.charAt(0)?a.translateNamespace+=c.translateNamespace:a.translateNamespace=c.translateNamespace}}}}}function f(a){"use strict";return a.translateNamespace?a.translateNamespace:a.$parent?f(a.$parent):void 0}function i(){"use strict";return{restrict:"A",scope:!0,compile:function(){return function(a,b,c){c.$observe("translateLanguage",function(b){a.translateLanguage=b})}}}}function j(a,b){"use strict";var c=function(c,d,e,f){return angular.isObject(d)||(d=a(d)(this)),b.instant(c,d,e,f)};return b.statefulFilter()&&(c.$stateful=!0),c}function k(a){"use strict";return a("translations")}return angular.module("pascalprecht.translate",["ng"]).run(a),a.$inject=["$translate"],a.displayName="runTranslate",angular.module("pascalprecht.translate").provider("$translateSanitization",b),angular.module("pascalprecht.translate").constant("pascalprechtTranslateOverrider",{}).provider("$translate",c),c.$inject=["$STORAGE_KEY","$windowProvider","$translateSanitizationProvider","pascalprechtTranslateOverrider"],c.displayName="displayName",angular.module("pascalprecht.translate").factory("$translateDefaultInterpolation",d),d.$inject=["$interpolate","$translateSanitization"],d.displayName="$translateDefaultInterpolation",angular.module("pascalprecht.translate").constant("$STORAGE_KEY","NG_TRANSLATE_LANG_KEY"),angular.module("pascalprecht.translate").directive("translate",e),e.$inject=["$translate","$q","$interpolate","$compile","$parse","$rootScope"],e.displayName="translateDirective",angular.module("pascalprecht.translate").directive("translateCloak",g),g.$inject=["$translate","$rootScope"],g.displayName="translateCloakDirective",angular.module("pascalprecht.translate").directive("translateNamespace",h),h.displayName="translateNamespaceDirective",angular.module("pascalprecht.translate").directive("translateLanguage",i),i.displayName="translateLanguageDirective",angular.module("pascalprecht.translate").filter("translate",j),j.$inject=["$parse","$translate"],j.displayName="translateFilterFactory",angular.module("pascalprecht.translate").factory("$translationCache",k),k.$inject=["$cacheFactory"],k.displayName="$translationCache","pascalprecht.translate"}); \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular/.bower.json b/ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular/.bower.json new file mode 100644 index 000000000..e7ab211e3 --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular/.bower.json @@ -0,0 +1,17 @@ +{ + "name": "angular", + "version": "1.3.20", + "main": "./angular.js", + "ignore": [], + "dependencies": {}, + "homepage": "https://github.com/angular/bower-angular", + "_release": "1.3.20", + "_resolution": { + "type": "version", + "tag": "v1.3.20", + "commit": "0cd10f27471310fe07167b00f8a4242c6bba4df2" + }, + "_source": "git://github.com/angular/bower-angular.git", + "_target": "~1.3.15", + "_originalSource": "angular" +} \ No newline at end of file diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular/README.md b/ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular/README.md new file mode 100644 index 000000000..d1bc0eddf --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular/README.md @@ -0,0 +1,64 @@ +# packaged angular + +This repo is for distribution on `npm` and `bower`. The source for this module is in the +[main AngularJS repo](https://github.com/angular/angular.js). +Please file issues and pull requests against that repo. + +## Install + +You can install this package either with `npm` or with `bower`. + +### npm + +```shell +npm install angular +``` + +Then add a ` +``` + +Or `require('angular')` from your code. + +### bower + +```shell +bower install angular +``` + +Then add a ` +``` + +## Documentation + +Documentation is available on the +[AngularJS docs site](http://docs.angularjs.org/). + +## License + +The MIT License + +Copyright (c) 2010-2015 Google, Inc. http://angularjs.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular/angular-csp.css b/ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular/angular-csp.css new file mode 100644 index 000000000..0ce9d864c --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular/angular-csp.css @@ -0,0 +1,13 @@ +/* Include this file in your html if you are using the CSP mode. */ + +@charset "UTF-8"; + +[ng\:cloak], [ng-cloak], [data-ng-cloak], [x-ng-cloak], +.ng-cloak, .x-ng-cloak, +.ng-hide:not(.ng-hide-animate) { + display: none !important; +} + +ng\:form { + display: block; +} diff --git a/ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular/angular.js b/ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular/angular.js new file mode 100644 index 000000000..2445ab55e --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/app/policyApp/libs/bower_components/angular/angular.js @@ -0,0 +1,26451 @@ +/** + * @license AngularJS v1.3.20 + * (c) 2010-2014 Google, Inc. http://angularjs.org + * License: MIT + */ +(function(window, document, undefined) {'use strict'; + +/** + * @description + * + * This object provides a utility for producing rich Error messages within + * Angular. It can be called as follows: + * + * var exampleMinErr = minErr('example'); + * throw exampleMinErr('one', 'This {0} is {1}', foo, bar); + * + * The above creates an instance of minErr in the example namespace. The + * resulting error will have a namespaced error code of example.one. The + * resulting error will replace {0} with the value of foo, and {1} with the + * value of bar. The object is not restricted in the number of arguments it can + * take. + * + * If fewer arguments are specified than necessary for interpolation, the extra + * interpolation markers will be preserved in the final string. + * + * Since data will be parsed statically during a build step, some restrictions + * are applied with respect to how minErr instances are created and called. + * Instances should have names of the form namespaceMinErr for a minErr created + * using minErr('namespace') . Error codes, namespaces and template strings + * should all be static strings, not variables or general expressions. + * + * @param {string} module The namespace to use for the new minErr instance. + * @param {function} ErrorConstructor Custom error constructor to be instantiated when returning + * error from returned function, for cases when a particular type of error is useful. + * @returns {function(code:string, template:string, ...templateArgs): Error} minErr instance + */ + +function minErr(module, ErrorConstructor) { + ErrorConstructor = ErrorConstructor || Error; + return function() { + var code = arguments[0], + prefix = '[' + (module ? module + ':' : '') + code + '] ', + template = arguments[1], + templateArgs = arguments, + + message, i; + + message = prefix + template.replace(/\{\d+\}/g, function(match) { + var index = +match.slice(1, -1), arg; + + if (index + 2 < templateArgs.length) { + return toDebugString(templateArgs[index + 2]); + } + return match; + }); + + message = message + '\nhttp://errors.angularjs.org/1.3.20/' + + (module ? module + '/' : '') + code; + for (i = 2; i < arguments.length; i++) { + message = message + (i == 2 ? '?' : '&') + 'p' + (i - 2) + '=' + + encodeURIComponent(toDebugString(arguments[i])); + } + return new ErrorConstructor(message); + }; +} + +/* We need to tell jshint what variables are being exported */ +/* global angular: true, + msie: true, + jqLite: true, + jQuery: true, + slice: true, + splice: true, + push: true, + toString: true, + ngMinErr: true, + angularModule: true, + uid: true, + REGEX_STRING_REGEXP: true, + VALIDITY_STATE_PROPERTY: true, + + lowercase: true, + uppercase: true, + manualLowercase: true, + manualUppercase: true, + nodeName_: true, + isArrayLike: true, + forEach: true, + sortedKeys: true, + forEachSorted: true, + reverseParams: true, + nextUid: true, + setHashKey: true, + extend: true, + int: true, + inherit: true, + noop: true, + identity: true, + valueFn: true, + isUndefined: true, + isDefined: true, + isObject: true, + isString: true, + isNumber: true, + isDate: true, + isArray: true, + isFunction: true, + isRegExp: true, + isWindow: true, + isScope: true, + isFile: true, + isFormData: true, + isBlob: true, + isBoolean: true, + isPromiseLike: true, + trim: true, + escapeForRegexp: true, + isElement: true, + makeMap: true, + includes: true, + arrayRemove: true, + copy: true, + shallowCopy: true, + equals: true, + csp: true, + concat: true, + sliceArgs: true, + bind: true, + toJsonReplacer: true, + toJson: true, + fromJson: true, + startingTag: true, + tryDecodeURIComponent: true, + parseKeyValue: true, + toKeyValue: true, + encodeUriSegment: true, + encodeUriQuery: true, + angularInit: true, + bootstrap: true, + getTestability: true, + snake_case: true, + bindJQuery: true, + assertArg: true, + assertArgFn: true, + assertNotHasOwnProperty: true, + getter: true, + getBlockNodes: true, + hasOwnProperty: true, + createMap: true, + + NODE_TYPE_ELEMENT: true, + NODE_TYPE_ATTRIBUTE: true, + NODE_TYPE_TEXT: true, + NODE_TYPE_COMMENT: true, + NODE_TYPE_DOCUMENT: true, + NODE_TYPE_DOCUMENT_FRAGMENT: true, +*/ + +//////////////////////////////////// + +/** + * @ngdoc module + * @name ng + * @module ng + * @description + * + * # ng (core module) + * The ng module is loaded by default when an AngularJS application is started. The module itself + * contains the essential components for an AngularJS application to function. The table below + * lists a high level breakdown of each of the services/factories, filters, directives and testing + * components available within this core module. + * + *
      + */ + +var REGEX_STRING_REGEXP = /^\/(.+)\/([a-z]*)$/; + +// The name of a form control's ValidityState property. +// This is used so that it's possible for internal tests to create mock ValidityStates. +var VALIDITY_STATE_PROPERTY = 'validity'; + +/** + * @ngdoc function + * @name angular.lowercase + * @module ng + * @kind function + * + * @description Converts the specified string to lowercase. + * @param {string} string String to be converted to lowercase. + * @returns {string} Lowercased string. + */ +var lowercase = function(string) {return isString(string) ? string.toLowerCase() : string;}; +var hasOwnProperty = Object.prototype.hasOwnProperty; + +/** + * @ngdoc function + * @name angular.uppercase + * @module ng + * @kind function + * + * @description Converts the specified string to uppercase. + * @param {string} string String to be converted to uppercase. + * @returns {string} Uppercased string. + */ +var uppercase = function(string) {return isString(string) ? string.toUpperCase() : string;}; + + +var manualLowercase = function(s) { + /* jshint bitwise: false */ + return isString(s) + ? s.replace(/[A-Z]/g, function(ch) {return String.fromCharCode(ch.charCodeAt(0) | 32);}) + : s; +}; +var manualUppercase = function(s) { + /* jshint bitwise: false */ + return isString(s) + ? s.replace(/[a-z]/g, function(ch) {return String.fromCharCode(ch.charCodeAt(0) & ~32);}) + : s; +}; + + +// String#toLowerCase and String#toUpperCase don't produce correct results in browsers with Turkish +// locale, for this reason we need to detect this case and redefine lowercase/uppercase methods +// with correct but slower alternatives. +if ('i' !== 'I'.toLowerCase()) { + lowercase = manualLowercase; + uppercase = manualUppercase; +} + + +var + msie, // holds major version number for IE, or NaN if UA is not IE. + jqLite, // delay binding since jQuery could be loaded after us. + jQuery, // delay binding + slice = [].slice, + splice = [].splice, + push = [].push, + toString = Object.prototype.toString, + ngMinErr = minErr('ng'), + + /** @name angular */ + angular = window.angular || (window.angular = {}), + angularModule, + uid = 0; + +/** + * documentMode is an IE-only property + * http://msdn.microsoft.com/en-us/library/ie/cc196988(v=vs.85).aspx + */ +msie = document.documentMode; + + +/** + * @private + * @param {*} obj + * @return {boolean} Returns true if `obj` is an array or array-like object (NodeList, Arguments, + * String ...) + */ +function isArrayLike(obj) { + if (obj == null || isWindow(obj)) { + return false; + } + + // Support: iOS 8.2 (not reproducible in simulator) + // "length" in obj used to prevent JIT error (gh-11508) + var length = "length" in Object(obj) && obj.length; + + if (obj.nodeType === NODE_TYPE_ELEMENT && length) { + return true; + } + + return isString(obj) || isArray(obj) || length === 0 || + typeof length === 'number' && length > 0 && (length - 1) in obj; +} + +/** + * @ngdoc function + * @name angular.forEach + * @module ng + * @kind function + * + * @description + * Invokes the `iterator` function once for each item in `obj` collection, which can be either an + * object or an array. The `iterator` function is invoked with `iterator(value, key, obj)`, where `value` + * is the value of an object property or an array element, `key` is the object property key or + * array element index and obj is the `obj` itself. Specifying a `context` for the function is optional. + * + * It is worth noting that `.forEach` does not iterate over inherited properties because it filters + * using the `hasOwnProperty` method. + * + * Unlike ES262's + * [Array.prototype.forEach](http://www.ecma-international.org/ecma-262/5.1/#sec-15.4.4.18), + * Providing 'undefined' or 'null' values for `obj` will not throw a TypeError, but rather just + * return the value provided. + * + ```js + var values = {name: 'misko', gender: 'male'}; + var log = []; + angular.forEach(values, function(value, key) { + this.push(key + ': ' + value); + }, log); + expect(log).toEqual(['name: misko', 'gender: male']); + ``` + * + * @param {Object|Array} obj Object to iterate over. + * @param {Function} iterator Iterator function. + * @param {Object=} context Object to become context (`this`) for the iterator function. + * @returns {Object|Array} Reference to `obj`. + */ + +function forEach(obj, iterator, context) { + var key, length; + if (obj) { + if (isFunction(obj)) { + for (key in obj) { + // Need to check if hasOwnProperty exists, + // as on IE8 the result of querySelectorAll is an object without a hasOwnProperty function + if (key != 'prototype' && key != 'length' && key != 'name' && (!obj.hasOwnProperty || obj.hasOwnProperty(key))) { + iterator.call(context, obj[key], key, obj); + } + } + } else if (isArray(obj) || isArrayLike(obj)) { + var isPrimitive = typeof obj !== 'object'; + for (key = 0, length = obj.length; key < length; key++) { + if (isPrimitive || key in obj) { + iterator.call(context, obj[key], key, obj); + } + } + } else if (obj.forEach && obj.forEach !== forEach) { + obj.forEach(iterator, context, obj); + } else { + for (key in obj) { + if (obj.hasOwnProperty(key)) { + iterator.call(context, obj[key], key, obj); + } + } + } + } + return obj; +} + +function sortedKeys(obj) { + return Object.keys(obj).sort(); +} + +function forEachSorted(obj, iterator, context) { + var keys = sortedKeys(obj); + for (var i = 0; i < keys.length; i++) { + iterator.call(context, obj[keys[i]], keys[i]); + } + return keys; +} + + +/** + * when using forEach the params are value, key, but it is often useful to have key, value. + * @param {function(string, *)} iteratorFn + * @returns {function(*, string)} + */ +function reverseParams(iteratorFn) { + return function(value, key) { iteratorFn(key, value); }; +} + +/** + * A consistent way of creating unique IDs in angular. + * + * Using simple numbers allows us to generate 28.6 million unique ids per second for 10 years before + * we hit number precision issues in JavaScript. + * + * Math.pow(2,53) / 60 / 60 / 24 / 365 / 10 = 28.6M + * + * @returns {number} an unique alpha-numeric string + */ +function nextUid() { + return ++uid; +} + + +/** + * Set or clear the hashkey for an object. + * @param obj object + * @param h the hashkey (!truthy to delete the hashkey) + */ +function setHashKey(obj, h) { + if (h) { + obj.$$hashKey = h; + } else { + delete obj.$$hashKey; + } +} + +/** + * @ngdoc function + * @name angular.extend + * @module ng + * @kind function + * + * @description + * Extends the destination object `dst` by copying own enumerable properties from the `src` object(s) + * to `dst`. You can specify multiple `src` objects. If you want to preserve original objects, you can do so + * by passing an empty object as the target: `var object = angular.extend({}, object1, object2)`. + * Note: Keep in mind that `angular.extend` does not support recursive merge (deep copy). + * + * @param {Object} dst Destination object. + * @param {...Object} src Source object(s). + * @returns {Object} Reference to `dst`. + */ +function extend(dst) { + var h = dst.$$hashKey; + + for (var i = 1, ii = arguments.length; i < ii; i++) { + var obj = arguments[i]; + if (obj) { + var keys = Object.keys(obj); + for (var j = 0, jj = keys.length; j < jj; j++) { + var key = keys[j]; + dst[key] = obj[key]; + } + } + } + + setHashKey(dst, h); + return dst; +} + +function int(str) { + return parseInt(str, 10); +} + + +function inherit(parent, extra) { + return extend(Object.create(parent), extra); +} + +/** + * @ngdoc function + * @name angular.noop + * @module ng + * @kind function + * + * @description + * A function that performs no operations. This function can be useful when writing code in the + * functional style. + ```js + function foo(callback) { + var result = calculateResult(); + (callback || angular.noop)(result); + } + ``` + */ +function noop() {} +noop.$inject = []; + + +/** + * @ngdoc function + * @name angular.identity + * @module ng + * @kind function + * + * @description + * A function that returns its first argument. This function is useful when writing code in the + * functional style. + * + ```js + function transformer(transformationFn, value) { + return (transformationFn || angular.identity)(value); + }; + ``` + * @param {*} value to be returned. + * @returns {*} the value passed in. + */ +function identity($) {return $;} +identity.$inject = []; + + +function valueFn(value) {return function() {return value;};} + +/** + * @ngdoc function + * @name angular.isUndefined + * @module ng + * @kind function + * + * @description + * Determines if a reference is undefined. + * + * @param {*} value Reference to check. + * @returns {boolean} True if `value` is undefined. + */ +function isUndefined(value) {return typeof value === 'undefined';} + + +/** + * @ngdoc function + * @name angular.isDefined + * @module ng + * @kind function + * + * @description + * Determines if a reference is defined. + * + * @param {*} value Reference to check. + * @returns {boolean} True if `value` is defined. + */ +function isDefined(value) {return typeof value !== 'undefined';} + + +/** + * @ngdoc function + * @name angular.isObject + * @module ng + * @kind function + * + * @description + * Determines if a reference is an `Object`. Unlike `typeof` in JavaScript, `null`s are not + * considered to be objects. Note that JavaScript arrays are objects. + * + * @param {*} value Reference to check. + * @returns {boolean} True if `value` is an `Object` but not `null`. + */ +function isObject(value) { + // http://jsperf.com/isobject4 + return value !== null && typeof value === 'object'; +} + + +/** + * @ngdoc function + * @name angular.isString + * @module ng + * @kind function + * + * @description + * Determines if a reference is a `String`. + * + * @param {*} value Reference to check. + * @returns {boolean} True if `value` is a `String`. + */ +function isString(value) {return typeof value === 'string';} + + +/** + * @ngdoc function + * @name angular.isNumber + * @module ng + * @kind function + * + * @description + * Determines if a reference is a `Number`. + * + * This includes the "special" numbers `NaN`, `+Infinity` and `-Infinity`. + * + * If you wish to exclude these then you can use the native + * [`isFinite'](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isFinite) + * method. + * + * @param {*} value Reference to check. + * @returns {boolean} True if `value` is a `Number`. + */ +function isNumber(value) {return typeof value === 'number';} + + +/** + * @ngdoc function + * @name angular.isDate + * @module ng + * @kind function + * + * @description + * Determines if a value is a date. + * + * @param {*} value Reference to check. + * @returns {boolean} True if `value` is a `Date`. + */ +function isDate(value) { + return toString.call(value) === '[object Date]'; +} + + +/** + * @ngdoc function + * @name angular.isArray + * @module ng + * @kind function + * + * @description + * Determines if a reference is an `Array`. + * + * @param {*} value Reference to check. + * @returns {boolean} True if `value` is an `Array`. + */ +var isArray = Array.isArray; + +/** + * @ngdoc function + * @name angular.isFunction + * @module ng + * @kind function + * + * @description + * Determines if a reference is a `Function`. + * + * @param {*} value Reference to check. + * @returns {boolean} True if `value` is a `Function`. + */ +function isFunction(value) {return typeof value === 'function';} + + +/** + * Determines if a value is a regular expression object. + * + * @private + * @param {*} value Reference to check. + * @returns {boolean} True if `value` is a `RegExp`. + */ +function isRegExp(value) { + return toString.call(value) === '[object RegExp]'; +} + + +/** + * Checks if `obj` is a window object. + * + * @private + * @param {*} obj Object to check + * @returns {boolean} True if `obj` is a window obj. + */ +function isWindow(obj) { + return obj && obj.window === obj; +} + + +function isScope(obj) { + return obj && obj.$evalAsync && obj.$watch; +} + + +function isFile(obj) { + return toString.call(obj) === '[object File]'; +} + + +function isFormData(obj) { + return toString.call(obj) === '[object FormData]'; +} + + +function isBlob(obj) { + return toString.call(obj) === '[object Blob]'; +} + + +function isBoolean(value) { + return typeof value === 'boolean'; +} + + +function isPromiseLike(obj) { + return obj && isFunction(obj.then); +} + + +var trim = function(value) { + return isString(value) ? value.trim() : value; +}; + +// Copied from: +// http://docs.closure-library.googlecode.com/git/local_closure_goog_string_string.js.source.html#line1021 +// Prereq: s is a string. +var escapeForRegexp = function(s) { + return s.replace(/([-()\[\]{}+?*.$\^|,:#= 0) + array.splice(index, 1); + return value; +} + +/** + * @ngdoc function + * @name angular.copy + * @module ng + * @kind function + * + * @description + * Creates a deep copy of `source`, which should be an object or an array. + * + * * If no destination is supplied, a copy of the object or array is created. + * * If a destination is provided, all of its elements (for arrays) or properties (for objects) + * are deleted and then all elements/properties from the source are copied to it. + * * If `source` is not an object or array (inc. `null` and `undefined`), `source` is returned. + * * If `source` is identical to 'destination' an exception will be thrown. + * + * @param {*} source The source that will be used to make a copy. + * Can be any type, including primitives, `null`, and `undefined`. + * @param {(Object|Array)=} destination Destination into which the source is copied. If + * provided, must be of the same type as `source`. + * @returns {*} The copy or updated `destination`, if `destination` was specified. + * + * @example + + +
      +
      + Name:
      + E-mail:
      + Gender: male + female
      + + +
      +
      form = {{user | json}}
      +
      master = {{master | json}}
      +
      + + +
      +
      + */ +function copy(source, destination, stackSource, stackDest) { + if (isWindow(source) || isScope(source)) { + throw ngMinErr('cpws', + "Can't copy! Making copies of Window or Scope instances is not supported."); + } + + if (!destination) { + destination = source; + if (source) { + if (isArray(source)) { + destination = copy(source, [], stackSource, stackDest); + } else if (isDate(source)) { + destination = new Date(source.getTime()); + } else if (isRegExp(source)) { + destination = new RegExp(source.source, source.toString().match(/[^\/]*$/)[0]); + destination.lastIndex = source.lastIndex; + } else if (isObject(source)) { + var emptyObject = Object.create(Object.getPrototypeOf(source)); + destination = copy(source, emptyObject, stackSource, stackDest); + } + } + } else { + if (source === destination) throw ngMinErr('cpi', + "Can't copy! Source and destination are identical."); + + stackSource = stackSource || []; + stackDest = stackDest || []; + + if (isObject(source)) { + var index = stackSource.indexOf(source); + if (index !== -1) return stackDest[index]; + + stackSource.push(source); + stackDest.push(destination); + } + + var result; + if (isArray(source)) { + destination.length = 0; + for (var i = 0; i < source.length; i++) { + result = copy(source[i], null, stackSource, stackDest); + if (isObject(source[i])) { + stackSource.push(source[i]); + stackDest.push(result); + } + destination.push(result); + } + } else { + var h = destination.$$hashKey; + if (isArray(destination)) { + destination.length = 0; + } else { + forEach(destination, function(value, key) { + delete destination[key]; + }); + } + for (var key in source) { + if (source.hasOwnProperty(key)) { + result = copy(source[key], null, stackSource, stackDest); + if (isObject(source[key])) { + stackSource.push(source[key]); + stackDest.push(result); + } + destination[key] = result; + } + } + setHashKey(destination,h); + } + + } + return destination; +} + +/** + * Creates a shallow copy of an object, an array or a primitive. + * + * Assumes that there are no proto properties for objects. + */ +function shallowCopy(src, dst) { + if (isArray(src)) { + dst = dst || []; + + for (var i = 0, ii = src.length; i < ii; i++) { + dst[i] = src[i]; + } + } else if (isObject(src)) { + dst = dst || {}; + + for (var key in src) { + if (!(key.charAt(0) === '$' && key.charAt(1) === '$')) { + dst[key] = src[key]; + } + } + } + + return dst || src; +} + + +/** + * @ngdoc function + * @name angular.equals + * @module ng + * @kind function + * + * @description + * Determines if two objects or two values are equivalent. Supports value types, regular + * expressions, arrays and objects. + * + * Two objects or values are considered equivalent if at least one of the following is true: + * + * * Both objects or values pass `===` comparison. + * * Both objects or values are of the same type and all of their properties are equal by + * comparing them with `angular.equals`. + * * Both values are NaN. (In JavaScript, NaN == NaN => false. But we consider two NaN as equal) + * * Both values represent the same regular expression (In JavaScript, + * /abc/ == /abc/ => false. But we consider two regular expressions as equal when their textual + * representation matches). + * + * During a property comparison, properties of `function` type and properties with names + * that begin with `$` are ignored. + * + * Scope and DOMWindow objects are being compared only by identify (`===`). + * + * @param {*} o1 Object or value to compare. + * @param {*} o2 Object or value to compare. + * @returns {boolean} True if arguments are equal. + */ +function equals(o1, o2) { + if (o1 === o2) return true; + if (o1 === null || o2 === null) return false; + if (o1 !== o1 && o2 !== o2) return true; // NaN === NaN + var t1 = typeof o1, t2 = typeof o2, length, key, keySet; + if (t1 == t2) { + if (t1 == 'object') { + if (isArray(o1)) { + if (!isArray(o2)) return false; + if ((length = o1.length) == o2.length) { + for (key = 0; key < length; key++) { + if (!equals(o1[key], o2[key])) return false; + } + return true; + } + } else if (isDate(o1)) { + if (!isDate(o2)) return false; + return equals(o1.getTime(), o2.getTime()); + } else if (isRegExp(o1)) { + return isRegExp(o2) ? o1.toString() == o2.toString() : false; + } else { + if (isScope(o1) || isScope(o2) || isWindow(o1) || isWindow(o2) || + isArray(o2) || isDate(o2) || isRegExp(o2)) return false; + keySet = {}; + for (key in o1) { + if (key.charAt(0) === '$' || isFunction(o1[key])) continue; + if (!equals(o1[key], o2[key])) return false; + keySet[key] = true; + } + for (key in o2) { + if (!keySet.hasOwnProperty(key) && + key.charAt(0) !== '$' && + o2[key] !== undefined && + !isFunction(o2[key])) return false; + } + return true; + } + } + } + return false; +} + +var csp = function() { + if (isDefined(csp.isActive_)) return csp.isActive_; + + var active = !!(document.querySelector('[ng-csp]') || + document.querySelector('[data-ng-csp]')); + + if (!active) { + try { + /* jshint -W031, -W054 */ + new Function(''); + /* jshint +W031, +W054 */ + } catch (e) { + active = true; + } + } + + return (csp.isActive_ = active); +}; + + + +function concat(array1, array2, index) { + return array1.concat(slice.call(array2, index)); +} + +function sliceArgs(args, startIndex) { + return slice.call(args, startIndex || 0); +} + + +/* jshint -W101 */ +/** + * @ngdoc function + * @name angular.bind + * @module ng + * @kind function + * + * @description + * Returns a function which calls function `fn` bound to `self` (`self` becomes the `this` for + * `fn`). You can supply optional `args` that are prebound to the function. This feature is also + * known as [partial application](http://en.wikipedia.org/wiki/Partial_application), as + * distinguished from [function currying](http://en.wikipedia.org/wiki/Currying#Contrast_with_partial_function_application). + * + * @param {Object} self Context which `fn` should be evaluated in. + * @param {function()} fn Function to be bound. + * @param {...*} args Optional arguments to be prebound to the `fn` function call. + * @returns {function()} Function that wraps the `fn` with all the specified bindings. + */ +/* jshint +W101 */ +function bind(self, fn) { + var curryArgs = arguments.length > 2 ? sliceArgs(arguments, 2) : []; + if (isFunction(fn) && !(fn instanceof RegExp)) { + return curryArgs.length + ? function() { + return arguments.length + ? fn.apply(self, concat(curryArgs, arguments, 0)) + : fn.apply(self, curryArgs); + } + : function() { + return arguments.length + ? fn.apply(self, arguments) + : fn.call(self); + }; + } else { + // in IE, native methods are not functions so they cannot be bound (note: they don't need to be) + return fn; + } +} + + +function toJsonReplacer(key, value) { + var val = value; + + if (typeof key === 'string' && key.charAt(0) === '$' && key.charAt(1) === '$') { + val = undefined; + } else if (isWindow(value)) { + val = '$WINDOW'; + } else if (value && document === value) { + val = '$DOCUMENT'; + } else if (isScope(value)) { + val = '$SCOPE'; + } + + return val; +} + + +/** + * @ngdoc function + * @name angular.toJson + * @module ng + * @kind function + * + * @description + * Serializes input into a JSON-formatted string. Properties with leading $$ characters will be + * stripped since angular uses this notation internally. + * + * @param {Object|Array|Date|string|number} obj Input to be serialized into JSON. + * @param {boolean|number} [pretty=2] If set to true, the JSON output will contain newlines and whitespace. + * If set to an integer, the JSON output will contain that many spaces per indentation. + * @returns {string|undefined} JSON-ified string representing `obj`. + */ +function toJson(obj, pretty) { + if (typeof obj === 'undefined') return undefined; + if (!isNumber(pretty)) { + pretty = pretty ? 2 : null; + } + return JSON.stringify(obj, toJsonReplacer, pretty); +} + + +/** + * @ngdoc function + * @name angular.fromJson + * @module ng + * @kind function + * + * @description + * Deserializes a JSON string. + * + * @param {string} json JSON string to deserialize. + * @returns {Object|Array|string|number} Deserialized JSON string. + */ +function fromJson(json) { + return isString(json) + ? JSON.parse(json) + : json; +} + + +/** + * @returns {string} Returns the string representation of the element. + */ +function startingTag(element) { + element = jqLite(element).clone(); + try { + // turns out IE does not let you set .html() on elements which + // are not allowed to have children. So we just ignore it. + element.empty(); + } catch (e) {} + var elemHtml = jqLite('
      ').append(element).html(); + try { + return element[0].nodeType === NODE_TYPE_TEXT ? lowercase(elemHtml) : + elemHtml. + match(/^(<[^>]+>)/)[1]. + replace(/^<([\w\-]+)/, function(match, nodeName) { return '<' + lowercase(nodeName); }); + } catch (e) { + return lowercase(elemHtml); + } + +} + + +///////////////////////////////////////////////// + +/** + * Tries to decode the URI component without throwing an exception. + * + * @private + * @param str value potential URI component to check. + * @returns {boolean} True if `value` can be decoded + * with the decodeURIComponent function. + */ +function tryDecodeURIComponent(value) { + try { + return decodeURIComponent(value); + } catch (e) { + // Ignore any invalid uri component + } +} + + +/** + * Parses an escaped url query string into key-value pairs. + * @returns {Object.} + */ +function parseKeyValue(/**string*/keyValue) { + var obj = {}, key_value, key; + forEach((keyValue || "").split('&'), function(keyValue) { + if (keyValue) { + key_value = keyValue.replace(/\+/g,'%20').split('='); + key = tryDecodeURIComponent(key_value[0]); + if (isDefined(key)) { + var val = isDefined(key_value[1]) ? tryDecodeURIComponent(key_value[1]) : true; + if (!hasOwnProperty.call(obj, key)) { + obj[key] = val; + } else if (isArray(obj[key])) { + obj[key].push(val); + } else { + obj[key] = [obj[key],val]; + } + } + } + }); + return obj; +} + +function toKeyValue(obj) { + var parts = []; + forEach(obj, function(value, key) { + if (isArray(value)) { + forEach(value, function(arrayValue) { + parts.push(encodeUriQuery(key, true) + + (arrayValue === true ? '' : '=' + encodeUriQuery(arrayValue, true))); + }); + } else { + parts.push(encodeUriQuery(key, true) + + (value === true ? '' : '=' + encodeUriQuery(value, true))); + } + }); + return parts.length ? parts.join('&') : ''; +} + + +/** + * We need our custom method because encodeURIComponent is too aggressive and doesn't follow + * http://www.ietf.org/rfc/rfc3986.txt with regards to the character set (pchar) allowed in path + * segments: + * segment = *pchar + * pchar = unreserved / pct-encoded / sub-delims / ":" / "@" + * pct-encoded = "%" HEXDIG HEXDIG + * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" + * sub-delims = "!" / "$" / "&" / "'" / "(" / ")" + * / "*" / "+" / "," / ";" / "=" + */ +function encodeUriSegment(val) { + return encodeUriQuery(val, true). + replace(/%26/gi, '&'). + replace(/%3D/gi, '='). + replace(/%2B/gi, '+'); +} + + +/** + * This method is intended for encoding *key* or *value* parts of query component. We need a custom + * method because encodeURIComponent is too aggressive and encodes stuff that doesn't have to be + * encoded per http://tools.ietf.org/html/rfc3986: + * query = *( pchar / "/" / "?" ) + * pchar = unreserved / pct-encoded / sub-delims / ":" / "@" + * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" + * pct-encoded = "%" HEXDIG HEXDIG + * sub-delims = "!" / "$" / "&" / "'" / "(" / ")" + * / "*" / "+" / "," / ";" / "=" + */ +function encodeUriQuery(val, pctEncodeSpaces) { + return encodeURIComponent(val). + replace(/%40/gi, '@'). + replace(/%3A/gi, ':'). + replace(/%24/g, '$'). + replace(/%2C/gi, ','). + replace(/%3B/gi, ';'). + replace(/%20/g, (pctEncodeSpaces ? '%20' : '+')); +} + +var ngAttrPrefixes = ['ng-', 'data-ng-', 'ng:', 'x-ng-']; + +function getNgAttribute(element, ngAttr) { + var attr, i, ii = ngAttrPrefixes.length; + element = jqLite(element); + for (i = 0; i < ii; ++i) { + attr = ngAttrPrefixes[i] + ngAttr; + if (isString(attr = element.attr(attr))) { + return attr; + } + } + return null; +} + +/** + * @ngdoc directive + * @name ngApp + * @module ng + * + * @element ANY + * @param {angular.Module} ngApp an optional application + * {@link angular.module module} name to load. + * @param {boolean=} ngStrictDi if this attribute is present on the app element, the injector will be + * created in "strict-di" mode. This means that the application will fail to invoke functions which + * do not use explicit function annotation (and are thus unsuitable for minification), as described + * in {@link guide/di the Dependency Injection guide}, and useful debugging info will assist in + * tracking down the root of these bugs. + * + * @description + * + * Use this directive to **auto-bootstrap** an AngularJS application. The `ngApp` directive + * designates the **root element** of the application and is typically placed near the root element + * of the page - e.g. on the `` or `` tags. + * + * Only one AngularJS application can be auto-bootstrapped per HTML document. The first `ngApp` + * found in the document will be used to define the root element to auto-bootstrap as an + * application. To run multiple applications in an HTML document you must manually bootstrap them using + * {@link angular.bootstrap} instead. AngularJS applications cannot be nested within each other. + * + * You can specify an **AngularJS module** to be used as the root module for the application. This + * module will be loaded into the {@link auto.$injector} when the application is bootstrapped. It + * should contain the application code needed or have dependencies on other modules that will + * contain the code. See {@link angular.module} for more information. + * + * In the example below if the `ngApp` directive were not placed on the `html` element then the + * document would not be compiled, the `AppController` would not be instantiated and the `{{ a+b }}` + * would not be resolved to `3`. + * + * `ngApp` is the easiest, and most common way to bootstrap an application. + * + + +
      + I can add: {{a}} + {{b}} = {{ a+b }} +
      +
      + + angular.module('ngAppDemo', []).controller('ngAppDemoController', function($scope) { + $scope.a = 1; + $scope.b = 2; + }); + +
      + * + * Using `ngStrictDi`, you would see something like this: + * + + +
      +
      + I can add: {{a}} + {{b}} = {{ a+b }} + +

      This renders because the controller does not fail to + instantiate, by using explicit annotation style (see + script.js for details) +

      +
      + +
      + Name:
      + Hello, {{name}}! + +

      This renders because the controller does not fail to + instantiate, by using explicit annotation style + (see script.js for details) +

      +
      + +
      + I can add: {{a}} + {{b}} = {{ a+b }} + +

      The controller could not be instantiated, due to relying + on automatic function annotations (which are disabled in + strict mode). As such, the content of this section is not + interpolated, and there should be an error in your web console. +

      +
      +
      +
      + + angular.module('ngAppStrictDemo', []) + // BadController will fail to instantiate, due to relying on automatic function annotation, + // rather than an explicit annotation + .controller('BadController', function($scope) { + $scope.a = 1; + $scope.b = 2; + }) + // Unlike BadController, GoodController1 and GoodController2 will not fail to be instantiated, + // due to using explicit annotations using the array style and $inject property, respectively. + .controller('GoodController1', ['$scope', function($scope) { + $scope.a = 1; + $scope.b = 2; + }]) + .controller('GoodController2', GoodController2); + function GoodController2($scope) { + $scope.name = "World"; + } + GoodController2.$inject = ['$scope']; + + + div[ng-controller] { + margin-bottom: 1em; + -webkit-border-radius: 4px; + border-radius: 4px; + border: 1px solid; + padding: .5em; + } + div[ng-controller^=Good] { + border-color: #d6e9c6; + background-color: #dff0d8; + color: #3c763d; + } + div[ng-controller^=Bad] { + border-color: #ebccd1; + background-color: #f2dede; + color: #a94442; + margin-bottom: 0; + } + +
      + */ +function angularInit(element, bootstrap) { + var appElement, + module, + config = {}; + + // The element `element` has priority over any other element + forEach(ngAttrPrefixes, function(prefix) { + var name = prefix + 'app'; + + if (!appElement && element.hasAttribute && element.hasAttribute(name)) { + appElement = element; + module = element.getAttribute(name); + } + }); + forEach(ngAttrPrefixes, function(prefix) { + var name = prefix + 'app'; + var candidate; + + if (!appElement && (candidate = element.querySelector('[' + name.replace(':', '\\:') + ']'))) { + appElement = candidate; + module = candidate.getAttribute(name); + } + }); + if (appElement) { + config.strictDi = getNgAttribute(appElement, "strict-di") !== null; + bootstrap(appElement, module ? [module] : [], config); + } +} + +/** + * @ngdoc function + * @name angular.bootstrap + * @module ng + * @description + * Use this function to manually start up angular application. + * + * See: {@link guide/bootstrap Bootstrap} + * + * Note that Protractor based end-to-end tests cannot use this function to bootstrap manually. + * They must use {@link ng.directive:ngApp ngApp}. + * + * Angular will detect if it has been loaded into the browser more than once and only allow the + * first loaded script to be bootstrapped and will report a warning to the browser console for + * each of the subsequent scripts. This prevents strange results in applications, where otherwise + * multiple instances of Angular try to work on the DOM. + * + * ```html + * + * + * + *
      + * {{greeting}} + *
      + * + * + * + * + * + * ``` + * + * @param {DOMElement} element DOM element which is the root of angular application. + * @param {Array=} modules an array of modules to load into the application. + * Each item in the array should be the name of a predefined module or a (DI annotated) + * function that will be invoked by the injector as a `config` block. + * See: {@link angular.module modules} + * @param {Object=} config an object for defining configuration options for the application. The + * following keys are supported: + * + * * `strictDi` - disable automatic function annotation for the application. This is meant to + * assist in finding bugs which break minified code. Defaults to `false`. + * + * @returns {auto.$injector} Returns the newly created injector for this app. + */ +function bootstrap(element, modules, config) { + if (!isObject(config)) config = {}; + var defaultConfig = { + strictDi: false + }; + config = extend(defaultConfig, config); + var doBootstrap = function() { + element = jqLite(element); + + if (element.injector()) { + var tag = (element[0] === document) ? 'document' : startingTag(element); + //Encode angle brackets to prevent input from being sanitized to empty string #8683 + throw ngMinErr( + 'btstrpd', + "App Already Bootstrapped with this Element '{0}'", + tag.replace(//,'>')); + } + + modules = modules || []; + modules.unshift(['$provide', function($provide) { + $provide.value('$rootElement', element); + }]); + + if (config.debugInfoEnabled) { + // Pushing so that this overrides `debugInfoEnabled` setting defined in user's `modules`. + modules.push(['$compileProvider', function($compileProvider) { + $compileProvider.debugInfoEnabled(true); + }]); + } + + modules.unshift('ng'); + var injector = createInjector(modules, config.strictDi); + injector.invoke(['$rootScope', '$rootElement', '$compile', '$injector', + function bootstrapApply(scope, element, compile, injector) { + scope.$apply(function() { + element.data('$injector', injector); + compile(element)(scope); + }); + }] + ); + return injector; + }; + + var NG_ENABLE_DEBUG_INFO = /^NG_ENABLE_DEBUG_INFO!/; + var NG_DEFER_BOOTSTRAP = /^NG_DEFER_BOOTSTRAP!/; + + if (window && NG_ENABLE_DEBUG_INFO.test(window.name)) { + config.debugInfoEnabled = true; + window.name = window.name.replace(NG_ENABLE_DEBUG_INFO, ''); + } + + if (window && !NG_DEFER_BOOTSTRAP.test(window.name)) { + return doBootstrap(); + } + + window.name = window.name.replace(NG_DEFER_BOOTSTRAP, ''); + angular.resumeBootstrap = function(extraModules) { + forEach(extraModules, function(module) { + modules.push(module); + }); + return doBootstrap(); + }; + + if (isFunction(angular.resumeDeferredBootstrap)) { + angular.resumeDeferredBootstrap(); + } +} + +/** + * @ngdoc function + * @name angular.reloadWithDebugInfo + * @module ng + * @description + * Use this function to reload the current application with debug information turned on. + * This takes precedence over a call to `$compileProvider.debugInfoEnabled(false)`. + * + * See {@link ng.$compileProvider#debugInfoEnabled} for more. + */ +function reloadWithDebugInfo() { + window.name = 'NG_ENABLE_DEBUG_INFO!' + window.name; + window.location.reload(); +} + +/** + * @name angular.getTestability + * @module ng + * @description + * Get the testability service for the instance of Angular on the given + * element. + * @param {DOMElement} element DOM element which is the root of angular application. + */ +function getTestability(rootElement) { + var injector = angular.element(rootElement).injector(); + if (!injector) { + throw ngMinErr('test', + 'no injector found for element argument to getTestability'); + } + return injector.get('$$testability'); +} + +var SNAKE_CASE_REGEXP = /[A-Z]/g; +function snake_case(name, separator) { + separator = separator || '_'; + return name.replace(SNAKE_CASE_REGEXP, function(letter, pos) { + return (pos ? separator : '') + letter.toLowerCase(); + }); +} + +var bindJQueryFired = false; +var skipDestroyOnNextJQueryCleanData; +function bindJQuery() { + var originalCleanData; + + if (bindJQueryFired) { + return; + } + + // bind to jQuery if present; + jQuery = window.jQuery; + // Use jQuery if it exists with proper functionality, otherwise default to us. + // Angular 1.2+ requires jQuery 1.7+ for on()/off() support. + // Angular 1.3+ technically requires at least jQuery 2.1+ but it may work with older + // versions. It will not work for sure with jQuery <1.7, though. + if (jQuery && jQuery.fn.on) { + jqLite = jQuery; + extend(jQuery.fn, { + scope: JQLitePrototype.scope, + isolateScope: JQLitePrototype.isolateScope, + controller: JQLitePrototype.controller, + injector: JQLitePrototype.injector, + inheritedData: JQLitePrototype.inheritedData + }); + + // All nodes removed from the DOM via various jQuery APIs like .remove() + // are passed through jQuery.cleanData. Monkey-patch this method to fire + // the $destroy event on all removed nodes. + originalCleanData = jQuery.cleanData; + jQuery.cleanData = function(elems) { + var events; + if (!skipDestroyOnNextJQueryCleanData) { + for (var i = 0, elem; (elem = elems[i]) != null; i++) { + events = jQuery._data(elem, "events"); + if (events && events.$destroy) { + jQuery(elem).triggerHandler('$destroy'); + } + } + } else { + skipDestroyOnNextJQueryCleanData = false; + } + originalCleanData(elems); + }; + } else { + jqLite = JQLite; + } + + angular.element = jqLite; + + // Prevent double-proxying. + bindJQueryFired = true; +} + +/** + * throw error if the argument is falsy. + */ +function assertArg(arg, name, reason) { + if (!arg) { + throw ngMinErr('areq', "Argument '{0}' is {1}", (name || '?'), (reason || "required")); + } + return arg; +} + +function assertArgFn(arg, name, acceptArrayAnnotation) { + if (acceptArrayAnnotation && isArray(arg)) { + arg = arg[arg.length - 1]; + } + + assertArg(isFunction(arg), name, 'not a function, got ' + + (arg && typeof arg === 'object' ? arg.constructor.name || 'Object' : typeof arg)); + return arg; +} + +/** + * throw error if the name given is hasOwnProperty + * @param {String} name the name to test + * @param {String} context the context in which the name is used, such as module or directive + */ +function assertNotHasOwnProperty(name, context) { + if (name === 'hasOwnProperty') { + throw ngMinErr('badname', "hasOwnProperty is not a valid {0} name", context); + } +} + +/** + * Return the value accessible from the object by path. Any undefined traversals are ignored + * @param {Object} obj starting object + * @param {String} path path to traverse + * @param {boolean} [bindFnToScope=true] + * @returns {Object} value as accessible by path + */ +//TODO(misko): this function needs to be removed +function getter(obj, path, bindFnToScope) { + if (!path) return obj; + var keys = path.split('.'); + var key; + var lastInstance = obj; + var len = keys.length; + + for (var i = 0; i < len; i++) { + key = keys[i]; + if (obj) { + obj = (lastInstance = obj)[key]; + } + } + if (!bindFnToScope && isFunction(obj)) { + return bind(lastInstance, obj); + } + return obj; +} + +/** + * Return the DOM siblings between the first and last node in the given array. + * @param {Array} array like object + * @returns {jqLite} jqLite collection containing the nodes + */ +function getBlockNodes(nodes) { + // TODO(perf): just check if all items in `nodes` are siblings and if they are return the original + // collection, otherwise update the original collection. + var node = nodes[0]; + var endNode = nodes[nodes.length - 1]; + var blockNodes = [node]; + + do { + node = node.nextSibling; + if (!node) break; + blockNodes.push(node); + } while (node !== endNode); + + return jqLite(blockNodes); +} + + +/** + * Creates a new object without a prototype. This object is useful for lookup without having to + * guard against prototypically inherited properties via hasOwnProperty. + * + * Related micro-benchmarks: + * - http://jsperf.com/object-create2 + * - http://jsperf.com/proto-map-lookup/2 + * - http://jsperf.com/for-in-vs-object-keys2 + * + * @returns {Object} + */ +function createMap() { + return Object.create(null); +} + +var NODE_TYPE_ELEMENT = 1; +var NODE_TYPE_ATTRIBUTE = 2; +var NODE_TYPE_TEXT = 3; +var NODE_TYPE_COMMENT = 8; +var NODE_TYPE_DOCUMENT = 9; +var NODE_TYPE_DOCUMENT_FRAGMENT = 11; + +/** + * @ngdoc type + * @name angular.Module + * @module ng + * @description + * + * Interface for configuring angular {@link angular.module modules}. + */ + +function setupModuleLoader(window) { + + var $injectorMinErr = minErr('$injector'); + var ngMinErr = minErr('ng'); + + function ensure(obj, name, factory) { + return obj[name] || (obj[name] = factory()); + } + + var angular = ensure(window, 'angular', Object); + + // We need to expose `angular.$$minErr` to modules such as `ngResource` that reference it during bootstrap + angular.$$minErr = angular.$$minErr || minErr; + + return ensure(angular, 'module', function() { + /** @type {Object.} */ + var modules = {}; + + /** + * @ngdoc function + * @name angular.module + * @module ng + * @description + * + * The `angular.module` is a global place for creating, registering and retrieving Angular + * modules. + * All modules (angular core or 3rd party) that should be available to an application must be + * registered using this mechanism. + * + * When passed two or more arguments, a new module is created. If passed only one argument, an + * existing module (the name passed as the first argument to `module`) is retrieved. + * + * + * # Module + * + * A module is a collection of services, directives, controllers, filters, and configuration information. + * `angular.module` is used to configure the {@link auto.$injector $injector}. + * + * ```js + * // Create a new module + * var myModule = angular.module('myModule', []); + * + * // register a new service + * myModule.value('appName', 'MyCoolApp'); + * + * // configure existing services inside initialization blocks. + * myModule.config(['$locationProvider', function($locationProvider) { + * // Configure existing providers + * $locationProvider.hashPrefix('!'); + * }]); + * ``` + * + * Then you can create an injector and load your modules like this: + * + * ```js + * var injector = angular.injector(['ng', 'myModule']) + * ``` + * + * However it's more likely that you'll just use + * {@link ng.directive:ngApp ngApp} or + * {@link angular.bootstrap} to simplify this process for you. + * + * @param {!string} name The name of the module to create or retrieve. + * @param {!Array.=} requires If specified then new module is being created. If + * unspecified then the module is being retrieved for further configuration. + * @param {Function=} configFn Optional configuration function for the module. Same as + * {@link angular.Module#config Module#config()}. + * @returns {module} new module with the {@link angular.Module} api. + */ + return function module(name, requires, configFn) { + var assertNotHasOwnProperty = function(name, context) { + if (name === 'hasOwnProperty') { + throw ngMinErr('badname', 'hasOwnProperty is not a valid {0} name', context); + } + }; + + assertNotHasOwnProperty(name, 'module'); + if (requires && modules.hasOwnProperty(name)) { + modules[name] = null; + } + return ensure(modules, name, function() { + if (!requires) { + throw $injectorMinErr('nomod', "Module '{0}' is not available! You either misspelled " + + "the module name or forgot to load it. If registering a module ensure that you " + + "specify the dependencies as the second argument.", name); + } + + /** @type {!Array.>} */ + var invokeQueue = []; + + /** @type {!Array.} */ + var configBlocks = []; + + /** @type {!Array.} */ + var runBlocks = []; + + var config = invokeLater('$injector', 'invoke', 'push', configBlocks); + + /** @type {angular.Module} */ + var moduleInstance = { + // Private state + _invokeQueue: invokeQueue, + _configBlocks: configBlocks, + _runBlocks: runBlocks, + + /** + * @ngdoc property + * @name angular.Module#requires + * @module ng + * + * @description + * Holds the list of modules which the injector will load before the current module is + * loaded. + */ + requires: requires, + + /** + * @ngdoc property + * @name angular.Module#name + * @module ng + * + * @description + * Name of the module. + */ + name: name, + + + /** + * @ngdoc method + * @name angular.Module#provider + * @module ng + * @param {string} name service name + * @param {Function} providerType Construction function for creating new instance of the + * service. + * @description + * See {@link auto.$provide#provider $provide.provider()}. + */ + provider: invokeLater('$provide', 'provider'), + + /** + * @ngdoc method + * @name angular.Module#factory + * @module ng + * @param {string} name service name + * @param {Function} providerFunction Function for creating new instance of the service. + * @description + * See {@link auto.$provide#factory $provide.factory()}. + */ + factory: invokeLater('$provide', 'factory'), + + /** + * @ngdoc method + * @name angular.Module#service + * @module ng + * @param {string} name service name + * @param {Function} constructor A constructor function that will be instantiated. + * @description + * See {@link auto.$provide#service $provide.service()}. + */ + service: invokeLater('$provide', 'service'), + + /** + * @ngdoc method + * @name angular.Module#value + * @module ng + * @param {string} name service name + * @param {*} object Service instance object. + * @description + * See {@link auto.$provide#value $provide.value()}. + */ + value: invokeLater('$provide', 'value'), + + /** + * @ngdoc method + * @name angular.Module#constant + * @module ng + * @param {string} name constant name + * @param {*} object Constant value. + * @description + * Because the constant are fixed, they get applied before other provide methods. + * See {@link auto.$provide#constant $provide.constant()}. + */ + constant: invokeLater('$provide', 'constant', 'unshift'), + + /** + * @ngdoc method + * @name angular.Module#animation + * @module ng + * @param {string} name animation name + * @param {Function} animationFactory Factory function for creating new instance of an + * animation. + * @description + * + * **NOTE**: animations take effect only if the **ngAnimate** module is loaded. + * + * + * Defines an animation hook that can be later used with + * {@link ngAnimate.$animate $animate} service and directives that use this service. + * + * ```js + * module.animation('.animation-name', function($inject1, $inject2) { + * return { + * eventName : function(element, done) { + * //code to run the animation + * //once complete, then run done() + * return function cancellationFunction(element) { + * //code to cancel the animation + * } + * } + * } + * }) + * ``` + * + * See {@link ng.$animateProvider#register $animateProvider.register()} and + * {@link ngAnimate ngAnimate module} for more information. + */ + animation: invokeLater('$animateProvider', 'register'), + + /** + * @ngdoc method + * @name angular.Module#filter + * @module ng + * @param {string} name Filter name - this must be a valid angular expression identifier + * @param {Function} filterFactory Factory function for creating new instance of filter. + * @description + * See {@link ng.$filterProvider#register $filterProvider.register()}. + * + *
      + * **Note:** Filter names must be valid angular {@link expression} identifiers, such as `uppercase` or `orderBy`. + * Names with special characters, such as hyphens and dots, are not allowed. If you wish to namespace + * your filters, then you can use capitalization (`myappSubsectionFilterx`) or underscores + * (`myapp_subsection_filterx`). + *
      + */ + filter: invokeLater('$filterProvider', 'register'), + + /** + * @ngdoc method + * @name angular.Module#controller + * @module ng + * @param {string|Object} name Controller name, or an object map of controllers where the + * keys are the names and the values are the constructors. + * @param {Function} constructor Controller constructor function. + * @description + * See {@link ng.$controllerProvider#register $controllerProvider.register()}. + */ + controller: invokeLater('$controllerProvider', 'register'), + + /** + * @ngdoc method + * @name angular.Module#directive + * @module ng + * @param {string|Object} name Directive name, or an object map of directives where the + * keys are the names and the values are the factories. + * @param {Function} directiveFactory Factory function for creating new instance of + * directives. + * @description + * See {@link ng.$compileProvider#directive $compileProvider.directive()}. + */ + directive: invokeLater('$compileProvider', 'directive'), + + /** + * @ngdoc method + * @name angular.Module#config + * @module ng + * @param {Function} configFn Execute this function on module load. Useful for service + * configuration. + * @description + * Use this method to register work which needs to be performed on module loading. + * For more about how to configure services, see + * {@link providers#provider-recipe Provider Recipe}. + */ + config: config, + + /** + * @ngdoc method + * @name angular.Module#run + * @module ng + * @param {Function} initializationFn Execute this function after injector creation. + * Useful for application initialization. + * @description + * Use this method to register work which should be performed when the injector is done + * loading all modules. + */ + run: function(block) { + runBlocks.push(block); + return this; + } + }; + + if (configFn) { + config(configFn); + } + + return moduleInstance; + + /** + * @param {string} provider + * @param {string} method + * @param {String=} insertMethod + * @returns {angular.Module} + */ + function invokeLater(provider, method, insertMethod, queue) { + if (!queue) queue = invokeQueue; + return function() { + queue[insertMethod || 'push']([provider, method, arguments]); + return moduleInstance; + }; + } + }); + }; + }); + +} + +/* global: toDebugString: true */ + +function serializeObject(obj) { + var seen = []; + + return JSON.stringify(obj, function(key, val) { + val = toJsonReplacer(key, val); + if (isObject(val)) { + + if (seen.indexOf(val) >= 0) return '<>'; + + seen.push(val); + } + return val; + }); +} + +function toDebugString(obj) { + if (typeof obj === 'function') { + return obj.toString().replace(/ \{[\s\S]*$/, ''); + } else if (typeof obj === 'undefined') { + return 'undefined'; + } else if (typeof obj !== 'string') { + return serializeObject(obj); + } + return obj; +} + +/* global angularModule: true, + version: true, + + $LocaleProvider, + $CompileProvider, + + htmlAnchorDirective, + inputDirective, + inputDirective, + formDirective, + scriptDirective, + selectDirective, + styleDirective, + optionDirective, + ngBindDirective, + ngBindHtmlDirective, + ngBindTemplateDirective, + ngClassDirective, + ngClassEvenDirective, + ngClassOddDirective, + ngCspDirective, + ngCloakDirective, + ngControllerDirective, + ngFormDirective, + ngHideDirective, + ngIfDirective, + ngIncludeDirective, + ngIncludeFillContentDirective, + ngInitDirective, + ngNonBindableDirective, + ngPluralizeDirective, + ngRepeatDirective, + ngShowDirective, + ngStyleDirective, + ngSwitchDirective, + ngSwitchWhenDirective, + ngSwitchDefaultDirective, + ngOptionsDirective, + ngTranscludeDirective, + ngModelDirective, + ngListDirective, + ngChangeDirective, + patternDirective, + patternDirective, + requiredDirective, + requiredDirective, + minlengthDirective, + minlengthDirective, + maxlengthDirective, + maxlengthDirective, + ngValueDirective, + ngModelOptionsDirective, + ngAttributeAliasDirectives, + ngEventDirectives, + + $AnchorScrollProvider, + $AnimateProvider, + $BrowserProvider, + $CacheFactoryProvider, + $ControllerProvider, + $DocumentProvider, + $ExceptionHandlerProvider, + $FilterProvider, + $InterpolateProvider, + $IntervalProvider, + $HttpProvider, + $HttpBackendProvider, + $LocationProvider, + $LogProvider, + $ParseProvider, + $RootScopeProvider, + $QProvider, + $$QProvider, + $$SanitizeUriProvider, + $SceProvider, + $SceDelegateProvider, + $SnifferProvider, + $TemplateCacheProvider, + $TemplateRequestProvider, + $$TestabilityProvider, + $TimeoutProvider, + $$RAFProvider, + $$AsyncCallbackProvider, + $WindowProvider, + $$jqLiteProvider +*/ + + +/** + * @ngdoc object + * @name angular.version + * @module ng + * @description + * An object that contains information about the current AngularJS version. This object has the + * following properties: + * + * - `full` – `{string}` – Full version string, such as "0.9.18". + * - `major` – `{number}` – Major version number, such as "0". + * - `minor` – `{number}` – Minor version number, such as "9". + * - `dot` – `{number}` – Dot version number, such as "18". + * - `codeName` – `{string}` – Code name of the release, such as "jiggling-armfat". + */ +var version = { + full: '1.3.20', // all of these placeholder strings will be replaced by grunt's + major: 1, // package task + minor: 3, + dot: 20, + codeName: 'shallow-translucence' +}; + + +function publishExternalAPI(angular) { + extend(angular, { + 'bootstrap': bootstrap, + 'copy': copy, + 'extend': extend, + 'equals': equals, + 'element': jqLite, + 'forEach': forEach, + 'injector': createInjector, + 'noop': noop, + 'bind': bind, + 'toJson': toJson, + 'fromJson': fromJson, + 'identity': identity, + 'isUndefined': isUndefined, + 'isDefined': isDefined, + 'isString': isString, + 'isFunction': isFunction, + 'isObject': isObject, + 'isNumber': isNumber, + 'isElement': isElement, + 'isArray': isArray, + 'version': version, + 'isDate': isDate, + 'lowercase': lowercase, + 'uppercase': uppercase, + 'callbacks': {counter: 0}, + 'getTestability': getTestability, + '$$minErr': minErr, + '$$csp': csp, + 'reloadWithDebugInfo': reloadWithDebugInfo + }); + + angularModule = setupModuleLoader(window); + try { + angularModule('ngLocale'); + } catch (e) { + angularModule('ngLocale', []).provider('$locale', $LocaleProvider); + } + + angularModule('ng', ['ngLocale'], ['$provide', + function ngModule($provide) { + // $$sanitizeUriProvider needs to be before $compileProvider as it is used by it. + $provide.provider({ + $$sanitizeUri: $$SanitizeUriProvider + }); + $provide.provider('$compile', $CompileProvider). + directive({ + a: htmlAnchorDirective, + input: inputDirective, + textarea: inputDirective, + form: formDirective, + script: scriptDirective, + select: selectDirective, + style: styleDirective, + option: optionDirective, + ngBind: ngBindDirective, + ngBindHtml: ngBindHtmlDirective, + ngBindTemplate: ngBindTemplateDirective, + ngClass: ngClassDirective, + ngClassEven: ngClassEvenDirective, + ngClassOdd: ngClassOddDirective, + ngCloak: ngCloakDirective, + ngController: ngControllerDirective, + ngForm: ngFormDirective, + ngHide: ngHideDirective, + ngIf: ngIfDirective, + ngInclude: ngIncludeDirective, + ngInit: ngInitDirective, + ngNonBindable: ngNonBindableDirective, + ngPluralize: ngPluralizeDirective, + ngRepeat: ngRepeatDirective, + ngShow: ngShowDirective, + ngStyle: ngStyleDirective, + ngSwitch: ngSwitchDirective, + ngSwitchWhen: ngSwitchWhenDirective, + ngSwitchDefault: ngSwitchDefaultDirective, + ngOptions: ngOptionsDirective, + ngTransclude: ngTranscludeDirective, + ngModel: ngModelDirective, + ngList: ngListDirective, + ngChange: ngChangeDirective, + pattern: patternDirective, + ngPattern: patternDirective, + required: requiredDirective, + ngRequired: requiredDirective, + minlength: minlengthDirective, + ngMinlength: minlengthDirective, + maxlength: maxlengthDirective, + ngMaxlength: maxlengthDirective, + ngValue: ngValueDirective, + ngModelOptions: ngModelOptionsDirective + }). + directive({ + ngInclude: ngIncludeFillContentDirective + }). + directive(ngAttributeAliasDirectives). + directive(ngEventDirectives); + $provide.provider({ + $anchorScroll: $AnchorScrollProvider, + $animate: $AnimateProvider, + $browser: $BrowserProvider, + $cacheFactory: $CacheFactoryProvider, + $controller: $ControllerProvider, + $document: $DocumentProvider, + $exceptionHandler: $ExceptionHandlerProvider, + $filter: $FilterProvider, + $interpolate: $InterpolateProvider, + $interval: $IntervalProvider, + $http: $HttpProvider, + $httpBackend: $HttpBackendProvider, + $location: $LocationProvider, + $log: $LogProvider, + $parse: $ParseProvider, + $rootScope: $RootScopeProvider, + $q: $QProvider, + $$q: $$QProvider, + $sce: $SceProvider, + $sceDelegate: $SceDelegateProvider, + $sniffer: $SnifferProvider, + $templateCache: $TemplateCacheProvider, + $templateRequest: $TemplateRequestProvider, + $$testability: $$TestabilityProvider, + $timeout: $TimeoutProvider, + $window: $WindowProvider, + $$rAF: $$RAFProvider, + $$asyncCallback: $$AsyncCallbackProvider, + $$jqLite: $$jqLiteProvider + }); + } + ]); +} + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Any commits to this file should be reviewed with security in mind. * + * Changes to this file can potentially create security vulnerabilities. * + * An approval from 2 Core members with history of modifying * + * this file is required. * + * * + * Does the change somehow allow for arbitrary javascript to be executed? * + * Or allows for someone to change the prototype of built-in objects? * + * Or gives undesired access to variables likes document or window? * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/* global JQLitePrototype: true, + addEventListenerFn: true, + removeEventListenerFn: true, + BOOLEAN_ATTR: true, + ALIASED_ATTR: true, +*/ + +////////////////////////////////// +//JQLite +////////////////////////////////// + +/** + * @ngdoc function + * @name angular.element + * @module ng + * @kind function + * + * @description + * Wraps a raw DOM element or HTML string as a [jQuery](http://jquery.com) element. + * + * If jQuery is available, `angular.element` is an alias for the + * [jQuery](http://api.jquery.com/jQuery/) function. If jQuery is not available, `angular.element` + * delegates to Angular's built-in subset of jQuery, called "jQuery lite" or "jqLite." + * + *
      jqLite is a tiny, API-compatible subset of jQuery that allows + * Angular to manipulate the DOM in a cross-browser compatible way. **jqLite** implements only the most + * commonly needed functionality with the goal of having a very small footprint.
      + * + * To use `jQuery`, simply ensure it is loaded before the `angular.js` file. + * + *
      **Note:** all element references in Angular are always wrapped with jQuery or + * jqLite; they are never raw DOM references.
      + * + * ## Angular's jqLite + * jqLite provides only the following jQuery methods: + * + * - [`addClass()`](http://api.jquery.com/addClass/) + * - [`after()`](http://api.jquery.com/after/) + * - [`append()`](http://api.jquery.com/append/) + * - [`attr()`](http://api.jquery.com/attr/) - Does not support functions as parameters + * - [`bind()`](http://api.jquery.com/bind/) - Does not support namespaces, selectors or eventData + * - [`children()`](http://api.jquery.com/children/) - Does not support selectors + * - [`clone()`](http://api.jquery.com/clone/) + * - [`contents()`](http://api.jquery.com/contents/) + * - [`css()`](http://api.jquery.com/css/) - Only retrieves inline-styles, does not call `getComputedStyle()`. As a setter, does not convert numbers to strings or append 'px'. + * - [`data()`](http://api.jquery.com/data/) + * - [`detach()`](http://api.jquery.com/detach/) + * - [`empty()`](http://api.jquery.com/empty/) + * - [`eq()`](http://api.jquery.com/eq/) + * - [`find()`](http://api.jquery.com/find/) - Limited to lookups by tag name + * - [`hasClass()`](http://api.jquery.com/hasClass/) + * - [`html()`](http://api.jquery.com/html/) + * - [`next()`](http://api.jquery.com/next/) - Does not support selectors + * - [`on()`](http://api.jquery.com/on/) - Does not support namespaces, selectors or eventData + * - [`off()`](http://api.jquery.com/off/) - Does not support namespaces or selectors + * - [`one()`](http://api.jquery.com/one/) - Does not support namespaces or selectors + * - [`parent()`](http://api.jquery.com/parent/) - Does not support selectors + * - [`prepend()`](http://api.jquery.com/prepend/) + * - [`prop()`](http://api.jquery.com/prop/) + * - [`ready()`](http://api.jquery.com/ready/) + * - [`remove()`](http://api.jquery.com/remove/) + * - [`removeAttr()`](http://api.jquery.com/removeAttr/) + * - [`removeClass()`](http://api.jquery.com/removeClass/) + * - [`removeData()`](http://api.jquery.com/removeData/) + * - [`replaceWith()`](http://api.jquery.com/replaceWith/) + * - [`text()`](http://api.jquery.com/text/) + * - [`toggleClass()`](http://api.jquery.com/toggleClass/) + * - [`triggerHandler()`](http://api.jquery.com/triggerHandler/) - Passes a dummy event object to handlers. + * - [`unbind()`](http://api.jquery.com/unbind/) - Does not support namespaces + * - [`val()`](http://api.jquery.com/val/) + * - [`wrap()`](http://api.jquery.com/wrap/) + * + * ## jQuery/jqLite Extras + * Angular also provides the following additional methods and events to both jQuery and jqLite: + * + * ### Events + * - `$destroy` - AngularJS intercepts all jqLite/jQuery's DOM destruction apis and fires this event + * on all DOM nodes being removed. This can be used to clean up any 3rd party bindings to the DOM + * element before it is removed. + * + * ### Methods + * - `controller(name)` - retrieves the controller of the current element or its parent. By default + * retrieves controller associated with the `ngController` directive. If `name` is provided as + * camelCase directive name, then the controller for this directive will be retrieved (e.g. + * `'ngModel'`). + * - `injector()` - retrieves the injector of the current element or its parent. + * - `scope()` - retrieves the {@link ng.$rootScope.Scope scope} of the current + * element or its parent. Requires {@link guide/production#disabling-debug-data Debug Data} to + * be enabled. + * - `isolateScope()` - retrieves an isolate {@link ng.$rootScope.Scope scope} if one is attached directly to the + * current element. This getter should be used only on elements that contain a directive which starts a new isolate + * scope. Calling `scope()` on this element always returns the original non-isolate scope. + * Requires {@link guide/production#disabling-debug-data Debug Data} to be enabled. + * - `inheritedData()` - same as `data()`, but walks up the DOM until a value is found or the top + * parent element is reached. + * + * @param {string|DOMElement} element HTML string or DOMElement to be wrapped into jQuery. + * @returns {Object} jQuery object. + */ + +JQLite.expando = 'ng339'; + +var jqCache = JQLite.cache = {}, + jqId = 1, + addEventListenerFn = function(element, type, fn) { + element.addEventListener(type, fn, false); + }, + removeEventListenerFn = function(element, type, fn) { + element.removeEventListener(type, fn, false); + }; + +/* + * !!! This is an undocumented "private" function !!! + */ +JQLite._data = function(node) { + //jQuery always returns an object on cache miss + return this.cache[node[this.expando]] || {}; +}; + +function jqNextId() { return ++jqId; } + + +var SPECIAL_CHARS_REGEXP = /([\:\-\_]+(.))/g; +var MOZ_HACK_REGEXP = /^moz([A-Z])/; +var MOUSE_EVENT_MAP= { mouseleave: "mouseout", mouseenter: "mouseover"}; +var jqLiteMinErr = minErr('jqLite'); + +/** + * Converts snake_case to camelCase. + * Also there is special case for Moz prefix starting with upper case letter. + * @param name Name to normalize + */ +function camelCase(name) { + return name. + replace(SPECIAL_CHARS_REGEXP, function(_, separator, letter, offset) { + return offset ? letter.toUpperCase() : letter; + }). + replace(MOZ_HACK_REGEXP, 'Moz$1'); +} + +var SINGLE_TAG_REGEXP = /^<(\w+)\s*\/?>(?:<\/\1>|)$/; +var HTML_REGEXP = /<|&#?\w+;/; +var TAG_NAME_REGEXP = /<([\w:]+)/; +var XHTML_TAG_REGEXP = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi; + +var wrapMap = { + 'option': [1, ''], + + 'thead': [1, '', '
      '], + 'col': [2, '', '
      '], + 'tr': [2, '', '
      '], + 'td': [3, '', '
      '], + '_default': [0, "", ""] +}; + +wrapMap.optgroup = wrapMap.option; +wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead; +wrapMap.th = wrapMap.td; + + +function jqLiteIsTextNode(html) { + return !HTML_REGEXP.test(html); +} + +function jqLiteAcceptsData(node) { + // The window object can accept data but has no nodeType + // Otherwise we are only interested in elements (1) and documents (9) + var nodeType = node.nodeType; + return nodeType === NODE_TYPE_ELEMENT || !nodeType || nodeType === NODE_TYPE_DOCUMENT; +} + +function jqLiteBuildFragment(html, context) { + var tmp, tag, wrap, + fragment = context.createDocumentFragment(), + nodes = [], i; + + if (jqLiteIsTextNode(html)) { + // Convert non-html into a text node + nodes.push(context.createTextNode(html)); + } else { + // Convert html into DOM nodes + tmp = tmp || fragment.appendChild(context.createElement("div")); + tag = (TAG_NAME_REGEXP.exec(html) || ["", ""])[1].toLowerCase(); + wrap = wrapMap[tag] || wrapMap._default; + tmp.innerHTML = wrap[1] + html.replace(XHTML_TAG_REGEXP, "<$1>") + wrap[2]; + + // Descend through wrappers to the right content + i = wrap[0]; + while (i--) { + tmp = tmp.lastChild; + } + + nodes = concat(nodes, tmp.childNodes); + + tmp = fragment.firstChild; + tmp.textContent = ""; + } + + // Remove wrapper from fragment + fragment.textContent = ""; + fragment.innerHTML = ""; // Clear inner HTML + forEach(nodes, function(node) { + fragment.appendChild(node); + }); + + return fragment; +} + +function jqLiteParseHTML(html, context) { + context = context || document; + var parsed; + + if ((parsed = SINGLE_TAG_REGEXP.exec(html))) { + return [context.createElement(parsed[1])]; + } + + if ((parsed = jqLiteBuildFragment(html, context))) { + return parsed.childNodes; + } + + return []; +} + +///////////////////////////////////////////// +function JQLite(element) { + if (element instanceof JQLite) { + return element; + } + + var argIsString; + + if (isString(element)) { + element = trim(element); + argIsString = true; + } + if (!(this instanceof JQLite)) { + if (argIsString && element.charAt(0) != '<') { + throw jqLiteMinErr('nosel', 'Looking up elements via selectors is not supported by jqLite! See: http://docs.angularjs.org/api/angular.element'); + } + return new JQLite(element); + } + + if (argIsString) { + jqLiteAddNodes(this, jqLiteParseHTML(element)); + } else { + jqLiteAddNodes(this, element); + } +} + +function jqLiteClone(element) { + return element.cloneNode(true); +} + +function jqLiteDealoc(element, onlyDescendants) { + if (!onlyDescendants) jqLiteRemoveData(element); + + if (element.querySelectorAll) { + var descendants = element.querySelectorAll('*'); + for (var i = 0, l = descendants.length; i < l; i++) { + jqLiteRemoveData(descendants[i]); + } + } +} + +function jqLiteOff(element, type, fn, unsupported) { + if (isDefined(unsupported)) throw jqLiteMinErr('offargs', 'jqLite#off() does not support the `selector` argument'); + + var expandoStore = jqLiteExpandoStore(element); + var events = expandoStore && expandoStore.events; + var handle = expandoStore && expandoStore.handle; + + if (!handle) return; //no listeners registered + + if (!type) { + for (type in events) { + if (type !== '$destroy') { + removeEventListenerFn(element, type, handle); + } + delete events[type]; + } + } else { + forEach(type.split(' '), function(type) { + if (isDefined(fn)) { + var listenerFns = events[type]; + arrayRemove(listenerFns || [], fn); + if (listenerFns && listenerFns.length > 0) { + return; + } + } + + removeEventListenerFn(element, type, handle); + delete events[type]; + }); + } +} + +function jqLiteRemoveData(element, name) { + var expandoId = element.ng339; + var expandoStore = expandoId && jqCache[expandoId]; + + if (expandoStore) { + if (name) { + delete expandoStore.data[name]; + return; + } + + if (expandoStore.handle) { + if (expandoStore.events.$destroy) { + expandoStore.handle({}, '$destroy'); + } + jqLiteOff(element); + } + delete jqCache[expandoId]; + element.ng339 = undefined; // don't delete DOM expandos. IE and Chrome don't like it + } +} + + +function jqLiteExpandoStore(element, createIfNecessary) { + var expandoId = element.ng339, + expandoStore = expandoId && jqCache[expandoId]; + + if (createIfNecessary && !expandoStore) { + element.ng339 = expandoId = jqNextId(); + expandoStore = jqCache[expandoId] = {events: {}, data: {}, handle: undefined}; + } + + return expandoStore; +} + + +function jqLiteData(element, key, value) { + if (jqLiteAcceptsData(element)) { + + var isSimpleSetter = isDefined(value); + var isSimpleGetter = !isSimpleSetter && key && !isObject(key); + var massGetter = !key; + var expandoStore = jqLiteExpandoStore(element, !isSimpleGetter); + var data = expandoStore && expandoStore.data; + + if (isSimpleSetter) { // data('key', value) + data[key] = value; + } else { + if (massGetter) { // data() + return data; + } else { + if (isSimpleGetter) { // data('key') + // don't force creation of expandoStore if it doesn't exist yet + return data && data[key]; + } else { // mass-setter: data({key1: val1, key2: val2}) + extend(data, key); + } + } + } + } +} + +function jqLiteHasClass(element, selector) { + if (!element.getAttribute) return false; + return ((" " + (element.getAttribute('class') || '') + " ").replace(/[\n\t]/g, " "). + indexOf(" " + selector + " ") > -1); +} + +function jqLiteRemoveClass(element, cssClasses) { + if (cssClasses && element.setAttribute) { + forEach(cssClasses.split(' '), function(cssClass) { + element.setAttribute('class', trim( + (" " + (element.getAttribute('class') || '') + " ") + .replace(/[\n\t]/g, " ") + .replace(" " + trim(cssClass) + " ", " ")) + ); + }); + } +} + +function jqLiteAddClass(element, cssClasses) { + if (cssClasses && element.setAttribute) { + var existingClasses = (' ' + (element.getAttribute('class') || '') + ' ') + .replace(/[\n\t]/g, " "); + + forEach(cssClasses.split(' '), function(cssClass) { + cssClass = trim(cssClass); + if (existingClasses.indexOf(' ' + cssClass + ' ') === -1) { + existingClasses += cssClass + ' '; + } + }); + + element.setAttribute('class', trim(existingClasses)); + } +} + + +function jqLiteAddNodes(root, elements) { + // THIS CODE IS VERY HOT. Don't make changes without benchmarking. + + if (elements) { + + // if a Node (the most common case) + if (elements.nodeType) { + root[root.length++] = elements; + } else { + var length = elements.length; + + // if an Array or NodeList and not a Window + if (typeof length === 'number' && elements.window !== elements) { + if (length) { + for (var i = 0; i < length; i++) { + root[root.length++] = elements[i]; + } + } + } else { + root[root.length++] = elements; + } + } + } +} + + +function jqLiteController(element, name) { + return jqLiteInheritedData(element, '$' + (name || 'ngController') + 'Controller'); +} + +function jqLiteInheritedData(element, name, value) { + // if element is the document object work with the html element instead + // this makes $(document).scope() possible + if (element.nodeType == NODE_TYPE_DOCUMENT) { + element = element.documentElement; + } + var names = isArray(name) ? name : [name]; + + while (element) { + for (var i = 0, ii = names.length; i < ii; i++) { + if ((value = jqLite.data(element, names[i])) !== undefined) return value; + } + + // If dealing with a document fragment node with a host element, and no parent, use the host + // element as the parent. This enables directives within a Shadow DOM or polyfilled Shadow DOM + // to lookup parent controllers. + element = element.parentNode || (element.nodeType === NODE_TYPE_DOCUMENT_FRAGMENT && element.host); + } +} + +function jqLiteEmpty(element) { + jqLiteDealoc(element, true); + while (element.firstChild) { + element.removeChild(element.firstChild); + } +} + +function jqLiteRemove(element, keepData) { + if (!keepData) jqLiteDealoc(element); + var parent = element.parentNode; + if (parent) parent.removeChild(element); +} + + +function jqLiteDocumentLoaded(action, win) { + win = win || window; + if (win.document.readyState === 'complete') { + // Force the action to be run async for consistent behaviour + // from the action's point of view + // i.e. it will definitely not be in a $apply + win.setTimeout(action); + } else { + // No need to unbind this handler as load is only ever called once + jqLite(win).on('load', action); + } +} + +////////////////////////////////////////// +// Functions which are declared directly. +////////////////////////////////////////// +var JQLitePrototype = JQLite.prototype = { + ready: function(fn) { + var fired = false; + + function trigger() { + if (fired) return; + fired = true; + fn(); + } + + // check if document is already loaded + if (document.readyState === 'complete') { + setTimeout(trigger); + } else { + this.on('DOMContentLoaded', trigger); // works for modern browsers and IE9 + // we can not use jqLite since we are not done loading and jQuery could be loaded later. + // jshint -W064 + JQLite(window).on('load', trigger); // fallback to window.onload for others + // jshint +W064 + } + }, + toString: function() { + var value = []; + forEach(this, function(e) { value.push('' + e);}); + return '[' + value.join(', ') + ']'; + }, + + eq: function(index) { + return (index >= 0) ? jqLite(this[index]) : jqLite(this[this.length + index]); + }, + + length: 0, + push: push, + sort: [].sort, + splice: [].splice +}; + +////////////////////////////////////////// +// Functions iterating getter/setters. +// these functions return self on setter and +// value on get. +////////////////////////////////////////// +var BOOLEAN_ATTR = {}; +forEach('multiple,selected,checked,disabled,readOnly,required,open'.split(','), function(value) { + BOOLEAN_ATTR[lowercase(value)] = value; +}); +var BOOLEAN_ELEMENTS = {}; +forEach('input,select,option,textarea,button,form,details'.split(','), function(value) { + BOOLEAN_ELEMENTS[value] = true; +}); +var ALIASED_ATTR = { + 'ngMinlength': 'minlength', + 'ngMaxlength': 'maxlength', + 'ngMin': 'min', + 'ngMax': 'max', + 'ngPattern': 'pattern' +}; + +function getBooleanAttrName(element, name) { + // check dom last since we will most likely fail on name + var booleanAttr = BOOLEAN_ATTR[name.toLowerCase()]; + + // booleanAttr is here twice to minimize DOM access + return booleanAttr && BOOLEAN_ELEMENTS[nodeName_(element)] && booleanAttr; +} + +function getAliasedAttrName(element, name) { + var nodeName = element.nodeName; + return (nodeName === 'INPUT' || nodeName === 'TEXTAREA') && ALIASED_ATTR[name]; +} + +forEach({ + data: jqLiteData, + removeData: jqLiteRemoveData +}, function(fn, name) { + JQLite[name] = fn; +}); + +forEach({ + data: jqLiteData, + inheritedData: jqLiteInheritedData, + + scope: function(element) { + // Can't use jqLiteData here directly so we stay compatible with jQuery! + return jqLite.data(element, '$scope') || jqLiteInheritedData(element.parentNode || element, ['$isolateScope', '$scope']); + }, + + isolateScope: function(element) { + // Can't use jqLiteData here directly so we stay compatible with jQuery! + return jqLite.data(element, '$isolateScope') || jqLite.data(element, '$isolateScopeNoTemplate'); + }, + + controller: jqLiteController, + + injector: function(element) { + return jqLiteInheritedData(element, '$injector'); + }, + + removeAttr: function(element, name) { + element.removeAttribute(name); + }, + + hasClass: jqLiteHasClass, + + css: function(element, name, value) { + name = camelCase(name); + + if (isDefined(value)) { + element.style[name] = value; + } else { + return element.style[name]; + } + }, + + attr: function(element, name, value) { + var nodeType = element.nodeType; + if (nodeType === NODE_TYPE_TEXT || nodeType === NODE_TYPE_ATTRIBUTE || nodeType === NODE_TYPE_COMMENT) { + return; + } + var lowercasedName = lowercase(name); + if (BOOLEAN_ATTR[lowercasedName]) { + if (isDefined(value)) { + if (!!value) { + element[name] = true; + element.setAttribute(name, lowercasedName); + } else { + element[name] = false; + element.removeAttribute(lowercasedName); + } + } else { + return (element[name] || + (element.attributes.getNamedItem(name) || noop).specified) + ? lowercasedName + : undefined; + } + } else if (isDefined(value)) { + element.setAttribute(name, value); + } else if (element.getAttribute) { + // the extra argument "2" is to get the right thing for a.href in IE, see jQuery code + // some elements (e.g. Document) don't have get attribute, so return undefined + var ret = element.getAttribute(name, 2); + // normalize non-existing attributes to undefined (as jQuery) + return ret === null ? undefined : ret; + } + }, + + prop: function(element, name, value) { + if (isDefined(value)) { + element[name] = value; + } else { + return element[name]; + } + }, + + text: (function() { + getText.$dv = ''; + return getText; + + function getText(element, value) { + if (isUndefined(value)) { + var nodeType = element.nodeType; + return (nodeType === NODE_TYPE_ELEMENT || nodeType === NODE_TYPE_TEXT) ? element.textContent : ''; + } + element.textContent = value; + } + })(), + + val: function(element, value) { + if (isUndefined(value)) { + if (element.multiple && nodeName_(element) === 'select') { + var result = []; + forEach(element.options, function(option) { + if (option.selected) { + result.push(option.value || option.text); + } + }); + return result.length === 0 ? null : result; + } + return element.value; + } + element.value = value; + }, + + html: function(element, value) { + if (isUndefined(value)) { + return element.innerHTML; + } + jqLiteDealoc(element, true); + element.innerHTML = value; + }, + + empty: jqLiteEmpty +}, function(fn, name) { + /** + * Properties: writes return selection, reads return first value + */ + JQLite.prototype[name] = function(arg1, arg2) { + var i, key; + var nodeCount = this.length; + + // jqLiteHasClass has only two arguments, but is a getter-only fn, so we need to special-case it + // in a way that survives minification. + // jqLiteEmpty takes no arguments but is a setter. + if (fn !== jqLiteEmpty && + (((fn.length == 2 && (fn !== jqLiteHasClass && fn !== jqLiteController)) ? arg1 : arg2) === undefined)) { + if (isObject(arg1)) { + + // we are a write, but the object properties are the key/values + for (i = 0; i < nodeCount; i++) { + if (fn === jqLiteData) { + // data() takes the whole object in jQuery + fn(this[i], arg1); + } else { + for (key in arg1) { + fn(this[i], key, arg1[key]); + } + } + } + // return self for chaining + return this; + } else { + // we are a read, so read the first child. + // TODO: do we still need this? + var value = fn.$dv; + // Only if we have $dv do we iterate over all, otherwise it is just the first element. + var jj = (value === undefined) ? Math.min(nodeCount, 1) : nodeCount; + for (var j = 0; j < jj; j++) { + var nodeValue = fn(this[j], arg1, arg2); + value = value ? value + nodeValue : nodeValue; + } + return value; + } + } else { + // we are a write, so apply to all children + for (i = 0; i < nodeCount; i++) { + fn(this[i], arg1, arg2); + } + // return self for chaining + return this; + } + }; +}); + +function createEventHandler(element, events) { + var eventHandler = function(event, type) { + // jQuery specific api + event.isDefaultPrevented = function() { + return event.defaultPrevented; + }; + + var eventFns = events[type || event.type]; + var eventFnsLength = eventFns ? eventFns.length : 0; + + if (!eventFnsLength) return; + + if (isUndefined(event.immediatePropagationStopped)) { + var originalStopImmediatePropagation = event.stopImmediatePropagation; + event.stopImmediatePropagation = function() { + event.immediatePropagationStopped = true; + + if (event.stopPropagation) { + event.stopPropagation(); + } + + if (originalStopImmediatePropagation) { + originalStopImmediatePropagation.call(event); + } + }; + } + + event.isImmediatePropagationStopped = function() { + return event.immediatePropagationStopped === true; + }; + + // Copy event handlers in case event handlers array is modified during execution. + if ((eventFnsLength > 1)) { + eventFns = shallowCopy(eventFns); + } + + for (var i = 0; i < eventFnsLength; i++) { + if (!event.isImmediatePropagationStopped()) { + eventFns[i].call(element, event); + } + } + }; + + // TODO: this is a hack for angularMocks/clearDataCache that makes it possible to deregister all + // events on `element` + eventHandler.elem = element; + return eventHandler; +} + +////////////////////////////////////////// +// Functions iterating traversal. +// These functions chain results into a single +// selector. +////////////////////////////////////////// +forEach({ + removeData: jqLiteRemoveData, + + on: function jqLiteOn(element, type, fn, unsupported) { + if (isDefined(unsupported)) throw jqLiteMinErr('onargs', 'jqLite#on() does not support the `selector` or `eventData` parameters'); + + // Do not add event handlers to non-elements because they will not be cleaned up. + if (!jqLiteAcceptsData(element)) { + return; + } + + var expandoStore = jqLiteExpandoStore(element, true); + var events = expandoStore.events; + var handle = expandoStore.handle; + + if (!handle) { + handle = expandoStore.handle = createEventHandler(element, events); + } + + // http://jsperf.com/string-indexof-vs-split + var types = type.indexOf(' ') >= 0 ? type.split(' ') : [type]; + var i = types.length; + + while (i--) { + type = types[i]; + var eventFns = events[type]; + + if (!eventFns) { + events[type] = []; + + if (type === 'mouseenter' || type === 'mouseleave') { + // Refer to jQuery's implementation of mouseenter & mouseleave + // Read about mouseenter and mouseleave: + // http://www.quirksmode.org/js/events_mouse.html#link8 + + jqLiteOn(element, MOUSE_EVENT_MAP[type], function(event) { + var target = this, related = event.relatedTarget; + // For mousenter/leave call the handler if related is outside the target. + // NB: No relatedTarget if the mouse left/entered the browser window + if (!related || (related !== target && !target.contains(related))) { + handle(event, type); + } + }); + + } else { + if (type !== '$destroy') { + addEventListenerFn(element, type, handle); + } + } + eventFns = events[type]; + } + eventFns.push(fn); + } + }, + + off: jqLiteOff, + + one: function(element, type, fn) { + element = jqLite(element); + + //add the listener twice so that when it is called + //you can remove the original function and still be + //able to call element.off(ev, fn) normally + element.on(type, function onFn() { + element.off(type, fn); + element.off(type, onFn); + }); + element.on(type, fn); + }, + + replaceWith: function(element, replaceNode) { + var index, parent = element.parentNode; + jqLiteDealoc(element); + forEach(new JQLite(replaceNode), function(node) { + if (index) { + parent.insertBefore(node, index.nextSibling); + } else { + parent.replaceChild(node, element); + } + index = node; + }); + }, + + children: function(element) { + var children = []; + forEach(element.childNodes, function(element) { + if (element.nodeType === NODE_TYPE_ELEMENT) + children.push(element); + }); + return children; + }, + + contents: function(element) { + return element.contentDocument || element.childNodes || []; + }, + + append: function(element, node) { + var nodeType = element.nodeType; + if (nodeType !== NODE_TYPE_ELEMENT && nodeType !== NODE_TYPE_DOCUMENT_FRAGMENT) return; + + node = new JQLite(node); + + for (var i = 0, ii = node.length; i < ii; i++) { + var child = node[i]; + element.appendChild(child); + } + }, + + prepend: function(element, node) { + if (element.nodeType === NODE_TYPE_ELEMENT) { + var index = element.firstChild; + forEach(new JQLite(node), function(child) { + element.insertBefore(child, index); + }); + } + }, + + wrap: function(element, wrapNode) { + wrapNode = jqLite(wrapNode).eq(0).clone()[0]; + var parent = element.parentNode; + if (parent) { + parent.replaceChild(wrapNode, element); + } + wrapNode.appendChild(element); + }, + + remove: jqLiteRemove, + + detach: function(element) { + jqLiteRemove(element, true); + }, + + after: function(element, newElement) { + var index = element, parent = element.parentNode; + newElement = new JQLite(newElement); + + for (var i = 0, ii = newElement.length; i < ii; i++) { + var node = newElement[i]; + parent.insertBefore(node, index.nextSibling); + index = node; + } + }, + + addClass: jqLiteAddClass, + removeClass: jqLiteRemoveClass, + + toggleClass: function(element, selector, condition) { + if (selector) { + forEach(selector.split(' '), function(className) { + var classCondition = condition; + if (isUndefined(classCondition)) { + classCondition = !jqLiteHasClass(element, className); + } + (classCondition ? jqLiteAddClass : jqLiteRemoveClass)(element, className); + }); + } + }, + + parent: function(element) { + var parent = element.parentNode; + return parent && parent.nodeType !== NODE_TYPE_DOCUMENT_FRAGMENT ? parent : null; + }, + + next: function(element) { + return element.nextElementSibling; + }, + + find: function(element, selector) { + if (element.getElementsByTagName) { + return element.getElementsByTagName(selector); + } else { + return []; + } + }, + + clone: jqLiteClone, + + triggerHandler: function(element, event, extraParameters) { + + var dummyEvent, eventFnsCopy, handlerArgs; + var eventName = event.type || event; + var expandoStore = jqLiteExpandoStore(element); + var events = expandoStore && expandoStore.events; + var eventFns = events && events[eventName]; + + if (eventFns) { + // Create a dummy event to pass to the handlers + dummyEvent = { + preventDefault: function() { this.defaultPrevented = true; }, + isDefaultPrevented: function() { return this.defaultPrevented === true; }, + stopImmediatePropagation: function() { this.immediatePropagationStopped = true; }, + isImmediatePropagationStopped: function() { return this.immediatePropagationStopped === true; }, + stopPropagation: noop, + type: eventName, + target: element + }; + + // If a custom event was provided then extend our dummy event with it + if (event.type) { + dummyEvent = extend(dummyEvent, event); + } + + // Copy event handlers in case event handlers array is modified during execution. + eventFnsCopy = shallowCopy(eventFns); + handlerArgs = extraParameters ? [dummyEvent].concat(extraParameters) : [dummyEvent]; + + forEach(eventFnsCopy, function(fn) { + if (!dummyEvent.isImmediatePropagationStopped()) { + fn.apply(element, handlerArgs); + } + }); + } + } +}, function(fn, name) { + /** + * chaining functions + */ + JQLite.prototype[name] = function(arg1, arg2, arg3) { + var value; + + for (var i = 0, ii = this.length; i < ii; i++) { + if (isUndefined(value)) { + value = fn(this[i], arg1, arg2, arg3); + if (isDefined(value)) { + // any function which returns a value needs to be wrapped + value = jqLite(value); + } + } else { + jqLiteAddNodes(value, fn(this[i], arg1, arg2, arg3)); + } + } + return isDefined(value) ? value : this; + }; + + // bind legacy bind/unbind to on/off + JQLite.prototype.bind = JQLite.prototype.on; + JQLite.prototype.unbind = JQLite.prototype.off; +}); + + +// Provider for private $$jqLite service +function $$jqLiteProvider() { + this.$get = function $$jqLite() { + return extend(JQLite, { + hasClass: function(node, classes) { + if (node.attr) node = node[0]; + return jqLiteHasClass(node, classes); + }, + addClass: function(node, classes) { + if (node.attr) node = node[0]; + return jqLiteAddClass(node, classes); + }, + removeClass: function(node, classes) { + if (node.attr) node = node[0]; + return jqLiteRemoveClass(node, classes); + } + }); + }; +} + +/** + * Computes a hash of an 'obj'. + * Hash of a: + * string is string + * number is number as string + * object is either result of calling $$hashKey function on the object or uniquely generated id, + * that is also assigned to the $$hashKey property of the object. + * + * @param obj + * @returns {string} hash string such that the same input will have the same hash string. + * The resulting string key is in 'type:hashKey' format. + */ +function hashKey(obj, nextUidFn) { + var key = obj && obj.$$hashKey; + + if (key) { + if (typeof key === 'function') { + key = obj.$$hashKey(); + } + return key; + } + + var objType = typeof obj; + if (objType == 'function' || (objType == 'object' && obj !== null)) { + key = obj.$$hashKey = objType + ':' + (nextUidFn || nextUid)(); + } else { + key = objType + ':' + obj; + } + + return key; +} + +/** + * HashMap which can use objects as keys + */ +function HashMap(array, isolatedUid) { + if (isolatedUid) { + var uid = 0; + this.nextUid = function() { + return ++uid; + }; + } + forEach(array, this.put, this); +} +HashMap.prototype = { + /** + * Store key value pair + * @param key key to store can be any type + * @param value value to store can be any type + */ + put: function(key, value) { + this[hashKey(key, this.nextUid)] = value; + }, + + /** + * @param key + * @returns {Object} the value for the key + */ + get: function(key) { + return this[hashKey(key, this.nextUid)]; + }, + + /** + * Remove the key/value pair + * @param key + */ + remove: function(key) { + var value = this[key = hashKey(key, this.nextUid)]; + delete this[key]; + return value; + } +}; + +/** + * @ngdoc function + * @module ng + * @name angular.injector + * @kind function + * + * @description + * Creates an injector object that can be used for retrieving services as well as for + * dependency injection (see {@link guide/di dependency injection}). + * + * @param {Array.} modules A list of module functions or their aliases. See + * {@link angular.module}. The `ng` module must be explicitly added. + * @param {boolean=} [strictDi=false] Whether the injector should be in strict mode, which + * disallows argument name annotation inference. + * @returns {injector} Injector object. See {@link auto.$injector $injector}. + * + * @example + * Typical usage + * ```js + * // create an injector + * var $injector = angular.injector(['ng']); + * + * // use the injector to kick off your application + * // use the type inference to auto inject arguments, or use implicit injection + * $injector.invoke(function($rootScope, $compile, $document) { + * $compile($document)($rootScope); + * $rootScope.$digest(); + * }); + * ``` + * + * Sometimes you want to get access to the injector of a currently running Angular app + * from outside Angular. Perhaps, you want to inject and compile some markup after the + * application has been bootstrapped. You can do this using the extra `injector()` added + * to JQuery/jqLite elements. See {@link angular.element}. + * + * *This is fairly rare but could be the case if a third party library is injecting the + * markup.* + * + * In the following example a new block of HTML containing a `ng-controller` + * directive is added to the end of the document body by JQuery. We then compile and link + * it into the current AngularJS scope. + * + * ```js + * var $div = $('
      {{content.label}}
      '); + * $(document.body).append($div); + * + * angular.element(document).injector().invoke(function($compile) { + * var scope = angular.element($div).scope(); + * $compile($div)(scope); + * }); + * ``` + */ + + +/** + * @ngdoc module + * @name auto + * @description + * + * Implicit module which gets automatically added to each {@link auto.$injector $injector}. + */ + +var FN_ARGS = /^function\s*[^\(]*\(\s*([^\)]*)\)/m; +var FN_ARG_SPLIT = /,/; +var FN_ARG = /^\s*(_?)(\S+?)\1\s*$/; +var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg; +var $injectorMinErr = minErr('$injector'); + +function anonFn(fn) { + // For anonymous functions, showing at the very least the function signature can help in + // debugging. + var fnText = fn.toString().replace(STRIP_COMMENTS, ''), + args = fnText.match(FN_ARGS); + if (args) { + return 'function(' + (args[1] || '').replace(/[\s\r\n]+/, ' ') + ')'; + } + return 'fn'; +} + +function annotate(fn, strictDi, name) { + var $inject, + fnText, + argDecl, + last; + + if (typeof fn === 'function') { + if (!($inject = fn.$inject)) { + $inject = []; + if (fn.length) { + if (strictDi) { + if (!isString(name) || !name) { + name = fn.name || anonFn(fn); + } + throw $injectorMinErr('strictdi', + '{0} is not using explicit annotation and cannot be invoked in strict mode', name); + } + fnText = fn.toString().replace(STRIP_COMMENTS, ''); + argDecl = fnText.match(FN_ARGS); + forEach(argDecl[1].split(FN_ARG_SPLIT), function(arg) { + arg.replace(FN_ARG, function(all, underscore, name) { + $inject.push(name); + }); + }); + } + fn.$inject = $inject; + } + } else if (isArray(fn)) { + last = fn.length - 1; + assertArgFn(fn[last], 'fn'); + $inject = fn.slice(0, last); + } else { + assertArgFn(fn, 'fn', true); + } + return $inject; +} + +/////////////////////////////////////// + +/** + * @ngdoc service + * @name $injector + * + * @description + * + * `$injector` is used to retrieve object instances as defined by + * {@link auto.$provide provider}, instantiate types, invoke methods, + * and load modules. + * + * The following always holds true: + * + * ```js + * var $injector = angular.injector(); + * expect($injector.get('$injector')).toBe($injector); + * expect($injector.invoke(function($injector) { + * return $injector; + * })).toBe($injector); + * ``` + * + * # Injection Function Annotation + * + * JavaScript does not have annotations, and annotations are needed for dependency injection. The + * following are all valid ways of annotating function with injection arguments and are equivalent. + * + * ```js + * // inferred (only works if code not minified/obfuscated) + * $injector.invoke(function(serviceA){}); + * + * // annotated + * function explicit(serviceA) {}; + * explicit.$inject = ['serviceA']; + * $injector.invoke(explicit); + * + * // inline + * $injector.invoke(['serviceA', function(serviceA){}]); + * ``` + * + * ## Inference + * + * In JavaScript calling `toString()` on a function returns the function definition. The definition + * can then be parsed and the function arguments can be extracted. This method of discovering + * annotations is disallowed when the injector is in strict mode. + * *NOTE:* This does not work with minification, and obfuscation tools since these tools change the + * argument names. + * + * ## `$inject` Annotation + * By adding an `$inject` property onto a function the injection parameters can be specified. + * + * ## Inline + * As an array of injection names, where the last item in the array is the function to call. + */ + +/** + * @ngdoc method + * @name $injector#get + * + * @description + * Return an instance of the service. + * + * @param {string} name The name of the instance to retrieve. + * @param {string=} caller An optional string to provide the origin of the function call for error messages. + * @return {*} The instance. + */ + +/** + * @ngdoc method + * @name $injector#invoke + * + * @description + * Invoke the method and supply the method arguments from the `$injector`. + * + * @param {Function|Array.} fn The injectable function to invoke. Function parameters are + * injected according to the {@link guide/di $inject Annotation} rules. + * @param {Object=} self The `this` for the invoked method. + * @param {Object=} locals Optional object. If preset then any argument names are read from this + * object first, before the `$injector` is consulted. + * @returns {*} the value returned by the invoked `fn` function. + */ + +/** + * @ngdoc method + * @name $injector#has + * + * @description + * Allows the user to query if the particular service exists. + * + * @param {string} name Name of the service to query. + * @returns {boolean} `true` if injector has given service. + */ + +/** + * @ngdoc method + * @name $injector#instantiate + * @description + * Create a new instance of JS type. The method takes a constructor function, invokes the new + * operator, and supplies all of the arguments to the constructor function as specified by the + * constructor annotation. + * + * @param {Function} Type Annotated constructor function. + * @param {Object=} locals Optional object. If preset then any argument names are read from this + * object first, before the `$injector` is consulted. + * @returns {Object} new instance of `Type`. + */ + +/** + * @ngdoc method + * @name $injector#annotate + * + * @description + * Returns an array of service names which the function is requesting for injection. This API is + * used by the injector to determine which services need to be injected into the function when the + * function is invoked. There are three ways in which the function can be annotated with the needed + * dependencies. + * + * # Argument names + * + * The simplest form is to extract the dependencies from the arguments of the function. This is done + * by converting the function into a string using `toString()` method and extracting the argument + * names. + * ```js + * // Given + * function MyController($scope, $route) { + * // ... + * } + * + * // Then + * expect(injector.annotate(MyController)).toEqual(['$scope', '$route']); + * ``` + * + * You can disallow this method by using strict injection mode. + * + * This method does not work with code minification / obfuscation. For this reason the following + * annotation strategies are supported. + * + * # The `$inject` property + * + * If a function has an `$inject` property and its value is an array of strings, then the strings + * represent names of services to be injected into the function. + * ```js + * // Given + * var MyController = function(obfuscatedScope, obfuscatedRoute) { + * // ... + * } + * // Define function dependencies + * MyController['$inject'] = ['$scope', '$route']; + * + * // Then + * expect(injector.annotate(MyController)).toEqual(['$scope', '$route']); + * ``` + * + * # The array notation + * + * It is often desirable to inline Injected functions and that's when setting the `$inject` property + * is very inconvenient. In these situations using the array notation to specify the dependencies in + * a way that survives minification is a better choice: + * + * ```js + * // We wish to write this (not minification / obfuscation safe) + * injector.invoke(function($compile, $rootScope) { + * // ... + * }); + * + * // We are forced to write break inlining + * var tmpFn = function(obfuscatedCompile, obfuscatedRootScope) { + * // ... + * }; + * tmpFn.$inject = ['$compile', '$rootScope']; + * injector.invoke(tmpFn); + * + * // To better support inline function the inline annotation is supported + * injector.invoke(['$compile', '$rootScope', function(obfCompile, obfRootScope) { + * // ... + * }]); + * + * // Therefore + * expect(injector.annotate( + * ['$compile', '$rootScope', function(obfus_$compile, obfus_$rootScope) {}]) + * ).toEqual(['$compile', '$rootScope']); + * ``` + * + * @param {Function|Array.} fn Function for which dependent service names need to + * be retrieved as described above. + * + * @param {boolean=} [strictDi=false] Disallow argument name annotation inference. + * + * @returns {Array.} The names of the services which the function requires. + */ + + + + +/** + * @ngdoc service + * @name $provide + * + * @description + * + * The {@link auto.$provide $provide} service has a number of methods for registering components + * with the {@link auto.$injector $injector}. Many of these functions are also exposed on + * {@link angular.Module}. + * + * An Angular **service** is a singleton object created by a **service factory**. These **service + * factories** are functions which, in turn, are created by a **service provider**. + * The **service providers** are constructor functions. When instantiated they must contain a + * property called `$get`, which holds the **service factory** function. + * + * When you request a service, the {@link auto.$injector $injector} is responsible for finding the + * correct **service provider**, instantiating it and then calling its `$get` **service factory** + * function to get the instance of the **service**. + * + * Often services have no configuration options and there is no need to add methods to the service + * provider. The provider will be no more than a constructor function with a `$get` property. For + * these cases the {@link auto.$provide $provide} service has additional helper methods to register + * services without specifying a provider. + * + * * {@link auto.$provide#provider provider(provider)} - registers a **service provider** with the + * {@link auto.$injector $injector} + * * {@link auto.$provide#constant constant(obj)} - registers a value/object that can be accessed by + * providers and services. + * * {@link auto.$provide#value value(obj)} - registers a value/object that can only be accessed by + * services, not providers. + * * {@link auto.$provide#factory factory(fn)} - registers a service **factory function**, `fn`, + * that will be wrapped in a **service provider** object, whose `$get` property will contain the + * given factory function. + * * {@link auto.$provide#service service(class)} - registers a **constructor function**, `class` + * that will be wrapped in a **service provider** object, whose `$get` property will instantiate + * a new object using the given constructor function. + * + * See the individual methods for more information and examples. + */ + +/** + * @ngdoc method + * @name $provide#provider + * @description + * + * Register a **provider function** with the {@link auto.$injector $injector}. Provider functions + * are constructor functions, whose instances are responsible for "providing" a factory for a + * service. + * + * Service provider names start with the name of the service they provide followed by `Provider`. + * For example, the {@link ng.$log $log} service has a provider called + * {@link ng.$logProvider $logProvider}. + * + * Service provider objects can have additional methods which allow configuration of the provider + * and its service. Importantly, you can configure what kind of service is created by the `$get` + * method, or how that service will act. For example, the {@link ng.$logProvider $logProvider} has a + * method {@link ng.$logProvider#debugEnabled debugEnabled} + * which lets you specify whether the {@link ng.$log $log} service will log debug messages to the + * console or not. + * + * @param {string} name The name of the instance. NOTE: the provider will be available under `name + + 'Provider'` key. + * @param {(Object|function())} provider If the provider is: + * + * - `Object`: then it should have a `$get` method. The `$get` method will be invoked using + * {@link auto.$injector#invoke $injector.invoke()} when an instance needs to be created. + * - `Constructor`: a new instance of the provider will be created using + * {@link auto.$injector#instantiate $injector.instantiate()}, then treated as `object`. + * + * @returns {Object} registered provider instance + + * @example + * + * The following example shows how to create a simple event tracking service and register it using + * {@link auto.$provide#provider $provide.provider()}. + * + * ```js + * // Define the eventTracker provider + * function EventTrackerProvider() { + * var trackingUrl = '/track'; + * + * // A provider method for configuring where the tracked events should been saved + * this.setTrackingUrl = function(url) { + * trackingUrl = url; + * }; + * + * // The service factory function + * this.$get = ['$http', function($http) { + * var trackedEvents = {}; + * return { + * // Call this to track an event + * event: function(event) { + * var count = trackedEvents[event] || 0; + * count += 1; + * trackedEvents[event] = count; + * return count; + * }, + * // Call this to save the tracked events to the trackingUrl + * save: function() { + * $http.post(trackingUrl, trackedEvents); + * } + * }; + * }]; + * } + * + * describe('eventTracker', function() { + * var postSpy; + * + * beforeEach(module(function($provide) { + * // Register the eventTracker provider + * $provide.provider('eventTracker', EventTrackerProvider); + * })); + * + * beforeEach(module(function(eventTrackerProvider) { + * // Configure eventTracker provider + * eventTrackerProvider.setTrackingUrl('/custom-track'); + * })); + * + * it('tracks events', inject(function(eventTracker) { + * expect(eventTracker.event('login')).toEqual(1); + * expect(eventTracker.event('login')).toEqual(2); + * })); + * + * it('saves to the tracking url', inject(function(eventTracker, $http) { + * postSpy = spyOn($http, 'post'); + * eventTracker.event('login'); + * eventTracker.save(); + * expect(postSpy).toHaveBeenCalled(); + * expect(postSpy.mostRecentCall.args[0]).not.toEqual('/track'); + * expect(postSpy.mostRecentCall.args[0]).toEqual('/custom-track'); + * expect(postSpy.mostRecentCall.args[1]).toEqual({ 'login': 1 }); + * })); + * }); + * ``` + */ + +/** + * @ngdoc method + * @name $provide#factory + * @description + * + * Register a **service factory**, which will be called to return the service instance. + * This is short for registering a service where its provider consists of only a `$get` property, + * which is the given service factory function. + * You should use {@link auto.$provide#factory $provide.factory(getFn)} if you do not need to + * configure your service in a provider. + * + * @param {string} name The name of the instance. + * @param {Function|Array.} $getFn The injectable $getFn for the instance creation. + * Internally this is a short hand for `$provide.provider(name, {$get: $getFn})`. + * @returns {Object} registered provider instance + * + * @example + * Here is an example of registering a service + * ```js + * $provide.factory('ping', ['$http', function($http) { + * return function ping() { + * return $http.send('/ping'); + * }; + * }]); + * ``` + * You would then inject and use this service like this: + * ```js + * someModule.controller('Ctrl', ['ping', function(ping) { + * ping(); + * }]); + * ``` + */ + + +/** + * @ngdoc method + * @name $provide#service + * @description + * + * Register a **service constructor**, which will be invoked with `new` to create the service + * instance. + * This is short for registering a service where its provider's `$get` property is the service + * constructor function that will be used to instantiate the service instance. + * + * You should use {@link auto.$provide#service $provide.service(class)} if you define your service + * as a type/class. + * + * @param {string} name The name of the instance. + * @param {Function|Array.} constructor An injectable class (constructor function) + * that will be instantiated. + * @returns {Object} registered provider instance + * + * @example + * Here is an example of registering a service using + * {@link auto.$provide#service $provide.service(class)}. + * ```js + * var Ping = function($http) { + * this.$http = $http; + * }; + * + * Ping.$inject = ['$http']; + * + * Ping.prototype.send = function() { + * return this.$http.get('/ping'); + * }; + * $provide.service('ping', Ping); + * ``` + * You would then inject and use this service like this: + * ```js + * someModule.controller('Ctrl', ['ping', function(ping) { + * ping.send(); + * }]); + * ``` + */ + + +/** + * @ngdoc method + * @name $provide#value + * @description + * + * Register a **value service** with the {@link auto.$injector $injector}, such as a string, a + * number, an array, an object or a function. This is short for registering a service where its + * provider's `$get` property is a factory function that takes no arguments and returns the **value + * service**. + * + * Value services are similar to constant services, except that they cannot be injected into a + * module configuration function (see {@link angular.Module#config}) but they can be overridden by + * an Angular + * {@link auto.$provide#decorator decorator}. + * + * @param {string} name The name of the instance. + * @param {*} value The value. + * @returns {Object} registered provider instance + * + * @example + * Here are some examples of creating value services. + * ```js + * $provide.value('ADMIN_USER', 'admin'); + * + * $provide.value('RoleLookup', { admin: 0, writer: 1, reader: 2 }); + * + * $provide.value('halfOf', function(value) { + * return value / 2; + * }); + * ``` + */ + + +/** + * @ngdoc method + * @name $provide#constant + * @description + * + * Register a **constant service**, such as a string, a number, an array, an object or a function, + * with the {@link auto.$injector $injector}. Unlike {@link auto.$provide#value value} it can be + * injected into a module configuration function (see {@link angular.Module#config}) and it cannot + * be overridden by an Angular {@link auto.$provide#decorator decorator}. + * + * @param {string} name The name of the constant. + * @param {*} value The constant value. + * @returns {Object} registered instance + * + * @example + * Here a some examples of creating constants: + * ```js + * $provide.constant('SHARD_HEIGHT', 306); + * + * $provide.constant('MY_COLOURS', ['red', 'blue', 'grey']); + * + * $provide.constant('double', function(value) { + * return value * 2; + * }); + * ``` + */ + + +/** + * @ngdoc method + * @name $provide#decorator + * @description + * + * Register a **service decorator** with the {@link auto.$injector $injector}. A service decorator + * intercepts the creation of a service, allowing it to override or modify the behaviour of the + * service. The object returned by the decorator may be the original service, or a new service + * object which replaces or wraps and delegates to the original service. + * + * @param {string} name The name of the service to decorate. + * @param {Function|Array.} decorator This function will be invoked when the service needs to be + * instantiated and should return the decorated service instance. The function is called using + * the {@link auto.$injector#invoke injector.invoke} method and is therefore fully injectable. + * Local injection arguments: + * + * * `$delegate` - The original service instance, which can be monkey patched, configured, + * decorated or delegated to. + * + * @example + * Here we decorate the {@link ng.$log $log} service to convert warnings to errors by intercepting + * calls to {@link ng.$log#error $log.warn()}. + * ```js + * $provide.decorator('$log', ['$delegate', function($delegate) { + * $delegate.warn = $delegate.error; + * return $delegate; + * }]); + * ``` + */ + + +function createInjector(modulesToLoad, strictDi) { + strictDi = (strictDi === true); + var INSTANTIATING = {}, + providerSuffix = 'Provider', + path = [], + loadedModules = new HashMap([], true), + providerCache = { + $provide: { + provider: supportObject(provider), + factory: supportObject(factory), + service: supportObject(service), + value: supportObject(value), + constant: supportObject(constant), + decorator: decorator + } + }, + providerInjector = (providerCache.$injector = + createInternalInjector(providerCache, function(serviceName, caller) { + if (angular.isString(caller)) { + path.push(caller); + } + throw $injectorMinErr('unpr', "Unknown provider: {0}", path.join(' <- ')); + })), + instanceCache = {}, + instanceInjector = (instanceCache.$injector = + createInternalInjector(instanceCache, function(serviceName, caller) { + var provider = providerInjector.get(serviceName + providerSuffix, caller); + return instanceInjector.invoke(provider.$get, provider, undefined, serviceName); + })); + + + forEach(loadModules(modulesToLoad), function(fn) { instanceInjector.invoke(fn || noop); }); + + return instanceInjector; + + //////////////////////////////////// + // $provider + //////////////////////////////////// + + function supportObject(delegate) { + return function(key, value) { + if (isObject(key)) { + forEach(key, reverseParams(delegate)); + } else { + return delegate(key, value); + } + }; + } + + function provider(name, provider_) { + assertNotHasOwnProperty(name, 'service'); + if (isFunction(provider_) || isArray(provider_)) { + provider_ = providerInjector.instantiate(provider_); + } + if (!provider_.$get) { + throw $injectorMinErr('pget', "Provider '{0}' must define $get factory method.", name); + } + return providerCache[name + providerSuffix] = provider_; + } + + function enforceReturnValue(name, factory) { + return function enforcedReturnValue() { + var result = instanceInjector.invoke(factory, this); + if (isUndefined(result)) { + throw $injectorMinErr('undef', "Provider '{0}' must return a value from $get factory method.", name); + } + return result; + }; + } + + function factory(name, factoryFn, enforce) { + return provider(name, { + $get: enforce !== false ? enforceReturnValue(name, factoryFn) : factoryFn + }); + } + + function service(name, constructor) { + return factory(name, ['$injector', function($injector) { + return $injector.instantiate(constructor); + }]); + } + + function value(name, val) { return factory(name, valueFn(val), false); } + + function constant(name, value) { + assertNotHasOwnProperty(name, 'constant'); + providerCache[name] = value; + instanceCache[name] = value; + } + + function decorator(serviceName, decorFn) { + var origProvider = providerInjector.get(serviceName + providerSuffix), + orig$get = origProvider.$get; + + origProvider.$get = function() { + var origInstance = instanceInjector.invoke(orig$get, origProvider); + return instanceInjector.invoke(decorFn, null, {$delegate: origInstance}); + }; + } + + //////////////////////////////////// + // Module Loading + //////////////////////////////////// + function loadModules(modulesToLoad) { + var runBlocks = [], moduleFn; + forEach(modulesToLoad, function(module) { + if (loadedModules.get(module)) return; + loadedModules.put(module, true); + + function runInvokeQueue(queue) { + var i, ii; + for (i = 0, ii = queue.length; i < ii; i++) { + var invokeArgs = queue[i], + provider = providerInjector.get(invokeArgs[0]); + + provider[invokeArgs[1]].apply(provider, invokeArgs[2]); + } + } + + try { + if (isString(module)) { + moduleFn = angularModule(module); + runBlocks = runBlocks.concat(loadModules(moduleFn.requires)).concat(moduleFn._runBlocks); + runInvokeQueue(moduleFn._invokeQueue); + runInvokeQueue(moduleFn._configBlocks); + } else if (isFunction(module)) { + runBlocks.push(providerInjector.invoke(module)); + } else if (isArray(module)) { + runBlocks.push(providerInjector.invoke(module)); + } else { + assertArgFn(module, 'module'); + } + } catch (e) { + if (isArray(module)) { + module = module[module.length - 1]; + } + if (e.message && e.stack && e.stack.indexOf(e.message) == -1) { + // Safari & FF's stack traces don't contain error.message content + // unlike those of Chrome and IE + // So if stack doesn't contain message, we create a new string that contains both. + // Since error.stack is read-only in Safari, I'm overriding e and not e.stack here. + /* jshint -W022 */ + e = e.message + '\n' + e.stack; + } + throw $injectorMinErr('modulerr', "Failed to instantiate module {0} due to:\n{1}", + module, e.stack || e.message || e); + } + }); + return runBlocks; + } + + //////////////////////////////////// + // internal Injector + //////////////////////////////////// + + function createInternalInjector(cache, factory) { + + function getService(serviceName, caller) { + if (cache.hasOwnProperty(serviceName)) { + if (cache[serviceName] === INSTANTIATING) { + throw $injectorMinErr('cdep', 'Circular dependency found: {0}', + serviceName + ' <- ' + path.join(' <- ')); + } + return cache[serviceName]; + } else { + try { + path.unshift(serviceName); + cache[serviceName] = INSTANTIATING; + return cache[serviceName] = factory(serviceName, caller); + } catch (err) { + if (cache[serviceName] === INSTANTIATING) { + delete cache[serviceName]; + } + throw err; + } finally { + path.shift(); + } + } + } + + function invoke(fn, self, locals, serviceName) { + if (typeof locals === 'string') { + serviceName = locals; + locals = null; + } + + var args = [], + $inject = createInjector.$$annotate(fn, strictDi, serviceName), + length, i, + key; + + for (i = 0, length = $inject.length; i < length; i++) { + key = $inject[i]; + if (typeof key !== 'string') { + throw $injectorMinErr('itkn', + 'Incorrect injection token! Expected service name as string, got {0}', key); + } + args.push( + locals && locals.hasOwnProperty(key) + ? locals[key] + : getService(key, serviceName) + ); + } + if (isArray(fn)) { + fn = fn[length]; + } + + // http://jsperf.com/angularjs-invoke-apply-vs-switch + // #5388 + return fn.apply(self, args); + } + + function instantiate(Type, locals, serviceName) { + // Check if Type is annotated and use just the given function at n-1 as parameter + // e.g. someModule.factory('greeter', ['$window', function(renamed$window) {}]); + // Object creation: http://jsperf.com/create-constructor/2 + var instance = Object.create((isArray(Type) ? Type[Type.length - 1] : Type).prototype || null); + var returnedValue = invoke(Type, instance, locals, serviceName); + + return isObject(returnedValue) || isFunction(returnedValue) ? returnedValue : instance; + } + + return { + invoke: invoke, + instantiate: instantiate, + get: getService, + annotate: createInjector.$$annotate, + has: function(name) { + return providerCache.hasOwnProperty(name + providerSuffix) || cache.hasOwnProperty(name); + } + }; + } +} + +createInjector.$$annotate = annotate; + +/** + * @ngdoc provider + * @name $anchorScrollProvider + * + * @description + * Use `$anchorScrollProvider` to disable automatic scrolling whenever + * {@link ng.$location#hash $location.hash()} changes. + */ +function $AnchorScrollProvider() { + + var autoScrollingEnabled = true; + + /** + * @ngdoc method + * @name $anchorScrollProvider#disableAutoScrolling + * + * @description + * By default, {@link ng.$anchorScroll $anchorScroll()} will automatically detect changes to + * {@link ng.$location#hash $location.hash()} and scroll to the element matching the new hash.
      + * Use this method to disable automatic scrolling. + * + * If automatic scrolling is disabled, one must explicitly call + * {@link ng.$anchorScroll $anchorScroll()} in order to scroll to the element related to the + * current hash. + */ + this.disableAutoScrolling = function() { + autoScrollingEnabled = false; + }; + + /** + * @ngdoc service + * @name $anchorScroll + * @kind function + * @requires $window + * @requires $location + * @requires $rootScope + * + * @description + * When called, it checks the current value of {@link ng.$location#hash $location.hash()} and + * scrolls to the related element, according to the rules specified in the + * [Html5 spec](http://dev.w3.org/html5/spec/Overview.html#the-indicated-part-of-the-document). + * + * It also watches the {@link ng.$location#hash $location.hash()} and automatically scrolls to + * match any anchor whenever it changes. This can be disabled by calling + * {@link ng.$anchorScrollProvider#disableAutoScrolling $anchorScrollProvider.disableAutoScrolling()}. + * + * Additionally, you can use its {@link ng.$anchorScroll#yOffset yOffset} property to specify a + * vertical scroll-offset (either fixed or dynamic). + * + * @property {(number|function|jqLite)} yOffset + * If set, specifies a vertical scroll-offset. This is often useful when there are fixed + * positioned elements at the top of the page, such as navbars, headers etc. + * + * `yOffset` can be specified in various ways: + * - **number**: A fixed number of pixels to be used as offset.

      + * - **function**: A getter function called everytime `$anchorScroll()` is executed. Must return + * a number representing the offset (in pixels).

      + * - **jqLite**: A jqLite/jQuery element to be used for specifying the offset. The distance from + * the top of the page to the element's bottom will be used as offset.
      + * **Note**: The element will be taken into account only as long as its `position` is set to + * `fixed`. This option is useful, when dealing with responsive navbars/headers that adjust + * their height and/or positioning according to the viewport's size. + * + *
      + *
      + * In order for `yOffset` to work properly, scrolling should take place on the document's root and + * not some child element. + *
      + * + * @example + + +
      + Go to bottom + You're at the bottom! +
      +
      + + angular.module('anchorScrollExample', []) + .controller('ScrollController', ['$scope', '$location', '$anchorScroll', + function ($scope, $location, $anchorScroll) { + $scope.gotoBottom = function() { + // set the location.hash to the id of + // the element you wish to scroll to. + $location.hash('bottom'); + + // call $anchorScroll() + $anchorScroll(); + }; + }]); + + + #scrollArea { + height: 280px; + overflow: auto; + } + + #bottom { + display: block; + margin-top: 2000px; + } + +
      + * + *
      + * The example below illustrates the use of a vertical scroll-offset (specified as a fixed value). + * See {@link ng.$anchorScroll#yOffset $anchorScroll.yOffset} for more details. + * + * @example + + + +
      + Anchor {{x}} of 5 +
      +
      + + angular.module('anchorScrollOffsetExample', []) + .run(['$anchorScroll', function($anchorScroll) { + $anchorScroll.yOffset = 50; // always scroll by 50 extra pixels + }]) + .controller('headerCtrl', ['$anchorScroll', '$location', '$scope', + function ($anchorScroll, $location, $scope) { + $scope.gotoAnchor = function(x) { + var newHash = 'anchor' + x; + if ($location.hash() !== newHash) { + // set the $location.hash to `newHash` and + // $anchorScroll will automatically scroll to it + $location.hash('anchor' + x); + } else { + // call $anchorScroll() explicitly, + // since $location.hash hasn't changed + $anchorScroll(); + } + }; + } + ]); + + + body { + padding-top: 50px; + } + + .anchor { + border: 2px dashed DarkOrchid; + padding: 10px 10px 200px 10px; + } + + .fixed-header { + background-color: rgba(0, 0, 0, 0.2); + height: 50px; + position: fixed; + top: 0; left: 0; right: 0; + } + + .fixed-header > a { + display: inline-block; + margin: 5px 15px; + } + +
      + */ + this.$get = ['$window', '$location', '$rootScope', function($window, $location, $rootScope) { + var document = $window.document; + + // Helper function to get first anchor from a NodeList + // (using `Array#some()` instead of `angular#forEach()` since it's more performant + // and working in all supported browsers.) + function getFirstAnchor(list) { + var result = null; + Array.prototype.some.call(list, function(element) { + if (nodeName_(element) === 'a') { + result = element; + return true; + } + }); + return result; + } + + function getYOffset() { + + var offset = scroll.yOffset; + + if (isFunction(offset)) { + offset = offset(); + } else if (isElement(offset)) { + var elem = offset[0]; + var style = $window.getComputedStyle(elem); + if (style.position !== 'fixed') { + offset = 0; + } else { + offset = elem.getBoundingClientRect().bottom; + } + } else if (!isNumber(offset)) { + offset = 0; + } + + return offset; + } + + function scrollTo(elem) { + if (elem) { + elem.scrollIntoView(); + + var offset = getYOffset(); + + if (offset) { + // `offset` is the number of pixels we should scroll UP in order to align `elem` properly. + // This is true ONLY if the call to `elem.scrollIntoView()` initially aligns `elem` at the + // top of the viewport. + // + // IF the number of pixels from the top of `elem` to the end of the page's content is less + // than the height of the viewport, then `elem.scrollIntoView()` will align the `elem` some + // way down the page. + // + // This is often the case for elements near the bottom of the page. + // + // In such cases we do not need to scroll the whole `offset` up, just the difference between + // the top of the element and the offset, which is enough to align the top of `elem` at the + // desired position. + var elemTop = elem.getBoundingClientRect().top; + $window.scrollBy(0, elemTop - offset); + } + } else { + $window.scrollTo(0, 0); + } + } + + function scroll() { + var hash = $location.hash(), elm; + + // empty hash, scroll to the top of the page + if (!hash) scrollTo(null); + + // element with given id + else if ((elm = document.getElementById(hash))) scrollTo(elm); + + // first anchor with given name :-D + else if ((elm = getFirstAnchor(document.getElementsByName(hash)))) scrollTo(elm); + + // no element and hash == 'top', scroll to the top of the page + else if (hash === 'top') scrollTo(null); + } + + // does not scroll when user clicks on anchor link that is currently on + // (no url change, no $location.hash() change), browser native does scroll + if (autoScrollingEnabled) { + $rootScope.$watch(function autoScrollWatch() {return $location.hash();}, + function autoScrollWatchAction(newVal, oldVal) { + // skip the initial scroll if $location.hash is empty + if (newVal === oldVal && newVal === '') return; + + jqLiteDocumentLoaded(function() { + $rootScope.$evalAsync(scroll); + }); + }); + } + + return scroll; + }]; +} + +var $animateMinErr = minErr('$animate'); + +/** + * @ngdoc provider + * @name $animateProvider + * + * @description + * Default implementation of $animate that doesn't perform any animations, instead just + * synchronously performs DOM + * updates and calls done() callbacks. + * + * In order to enable animations the ngAnimate module has to be loaded. + * + * To see the functional implementation check out src/ngAnimate/animate.js + */ +var $AnimateProvider = ['$provide', function($provide) { + + + this.$$selectors = {}; + + + /** + * @ngdoc method + * @name $animateProvider#register + * + * @description + * Registers a new injectable animation factory function. The factory function produces the + * animation object which contains callback functions for each event that is expected to be + * animated. + * + * * `eventFn`: `function(Element, doneFunction)` The element to animate, the `doneFunction` + * must be called once the element animation is complete. If a function is returned then the + * animation service will use this function to cancel the animation whenever a cancel event is + * triggered. + * + * + * ```js + * return { + * eventFn : function(element, done) { + * //code to run the animation + * //once complete, then run done() + * return function cancellationFunction() { + * //code to cancel the animation + * } + * } + * } + * ``` + * + * @param {string} name The name of the animation. + * @param {Function} factory The factory function that will be executed to return the animation + * object. + */ + this.register = function(name, factory) { + var key = name + '-animation'; + if (name && name.charAt(0) != '.') throw $animateMinErr('notcsel', + "Expecting class selector starting with '.' got '{0}'.", name); + this.$$selectors[name.substr(1)] = key; + $provide.factory(key, factory); + }; + + /** + * @ngdoc method + * @name $animateProvider#classNameFilter + * + * @description + * Sets and/or returns the CSS class regular expression that is checked when performing + * an animation. Upon bootstrap the classNameFilter value is not set at all and will + * therefore enable $animate to attempt to perform an animation on any element. + * When setting the classNameFilter value, animations will only be performed on elements + * that successfully match the filter expression. This in turn can boost performance + * for low-powered devices as well as applications containing a lot of structural operations. + * @param {RegExp=} expression The className expression which will be checked against all animations + * @return {RegExp} The current CSS className expression value. If null then there is no expression value + */ + this.classNameFilter = function(expression) { + if (arguments.length === 1) { + this.$$classNameFilter = (expression instanceof RegExp) ? expression : null; + } + return this.$$classNameFilter; + }; + + this.$get = ['$$q', '$$asyncCallback', '$rootScope', function($$q, $$asyncCallback, $rootScope) { + + var currentDefer; + + function runAnimationPostDigest(fn) { + var cancelFn, defer = $$q.defer(); + defer.promise.$$cancelFn = function ngAnimateMaybeCancel() { + cancelFn && cancelFn(); + }; + + $rootScope.$$postDigest(function ngAnimatePostDigest() { + cancelFn = fn(function ngAnimateNotifyComplete() { + defer.resolve(); + }); + }); + + return defer.promise; + } + + function resolveElementClasses(element, classes) { + var toAdd = [], toRemove = []; + + var hasClasses = createMap(); + forEach((element.attr('class') || '').split(/\s+/), function(className) { + hasClasses[className] = true; + }); + + forEach(classes, function(status, className) { + var hasClass = hasClasses[className]; + + // If the most recent class manipulation (via $animate) was to remove the class, and the + // element currently has the class, the class is scheduled for removal. Otherwise, if + // the most recent class manipulation (via $animate) was to add the class, and the + // element does not currently have the class, the class is scheduled to be added. + if (status === false && hasClass) { + toRemove.push(className); + } else if (status === true && !hasClass) { + toAdd.push(className); + } + }); + + return (toAdd.length + toRemove.length) > 0 && + [toAdd.length ? toAdd : null, toRemove.length ? toRemove : null]; + } + + function cachedClassManipulation(cache, classes, op) { + for (var i=0, ii = classes.length; i < ii; ++i) { + var className = classes[i]; + cache[className] = op; + } + } + + function asyncPromise() { + // only serve one instance of a promise in order to save CPU cycles + if (!currentDefer) { + currentDefer = $$q.defer(); + $$asyncCallback(function() { + currentDefer.resolve(); + currentDefer = null; + }); + } + return currentDefer.promise; + } + + function applyStyles(element, options) { + if (angular.isObject(options)) { + var styles = extend(options.from || {}, options.to || {}); + element.css(styles); + } + } + + /** + * + * @ngdoc service + * @name $animate + * @description The $animate service provides rudimentary DOM manipulation functions to + * insert, remove and move elements within the DOM, as well as adding and removing classes. + * This service is the core service used by the ngAnimate $animator service which provides + * high-level animation hooks for CSS and JavaScript. + * + * $animate is available in the AngularJS core, however, the ngAnimate module must be included + * to enable full out animation support. Otherwise, $animate will only perform simple DOM + * manipulation operations. + * + * To learn more about enabling animation support, click here to visit the {@link ngAnimate + * ngAnimate module page} as well as the {@link ngAnimate.$animate ngAnimate $animate service + * page}. + */ + return { + animate: function(element, from, to) { + applyStyles(element, { from: from, to: to }); + return asyncPromise(); + }, + + /** + * + * @ngdoc method + * @name $animate#enter + * @kind function + * @description Inserts the element into the DOM either after the `after` element or + * as the first child within the `parent` element. When the function is called a promise + * is returned that will be resolved at a later time. + * @param {DOMElement} element the element which will be inserted into the DOM + * @param {DOMElement} parent the parent element which will append the element as + * a child (if the after element is not present) + * @param {DOMElement} after the sibling element which will append the element + * after itself + * @param {object=} options an optional collection of styles that will be applied to the element. + * @return {Promise} the animation callback promise + */ + enter: function(element, parent, after, options) { + applyStyles(element, options); + after ? after.after(element) + : parent.prepend(element); + return asyncPromise(); + }, + + /** + * + * @ngdoc method + * @name $animate#leave + * @kind function + * @description Removes the element from the DOM. When the function is called a promise + * is returned that will be resolved at a later time. + * @param {DOMElement} element the element which will be removed from the DOM + * @param {object=} options an optional collection of options that will be applied to the element. + * @return {Promise} the animation callback promise + */ + leave: function(element, options) { + applyStyles(element, options); + element.remove(); + return asyncPromise(); + }, + + /** + * + * @ngdoc method + * @name $animate#move + * @kind function + * @description Moves the position of the provided element within the DOM to be placed + * either after the `after` element or inside of the `parent` element. When the function + * is called a promise is returned that will be resolved at a later time. + * + * @param {DOMElement} element the element which will be moved around within the + * DOM + * @param {DOMElement} parent the parent element where the element will be + * inserted into (if the after element is not present) + * @param {DOMElement} after the sibling element where the element will be + * positioned next to + * @param {object=} options an optional collection of options that will be applied to the element. + * @return {Promise} the animation callback promise + */ + move: function(element, parent, after, options) { + // Do not remove element before insert. Removing will cause data associated with the + // element to be dropped. Insert will implicitly do the remove. + return this.enter(element, parent, after, options); + }, + + /** + * + * @ngdoc method + * @name $animate#addClass + * @kind function + * @description Adds the provided className CSS class value to the provided element. + * When the function is called a promise is returned that will be resolved at a later time. + * @param {DOMElement} element the element which will have the className value + * added to it + * @param {string} className the CSS class which will be added to the element + * @param {object=} options an optional collection of options that will be applied to the element. + * @return {Promise} the animation callback promise + */ + addClass: function(element, className, options) { + return this.setClass(element, className, [], options); + }, + + $$addClassImmediately: function(element, className, options) { + element = jqLite(element); + className = !isString(className) + ? (isArray(className) ? className.join(' ') : '') + : className; + forEach(element, function(element) { + jqLiteAddClass(element, className); + }); + applyStyles(element, options); + return asyncPromise(); + }, + + /** + * + * @ngdoc method + * @name $animate#removeClass + * @kind function + * @description Removes the provided className CSS class value from the provided element. + * When the function is called a promise is returned that will be resolved at a later time. + * @param {DOMElement} element the element which will have the className value + * removed from it + * @param {string} className the CSS class which will be removed from the element + * @param {object=} options an optional collection of options that will be applied to the element. + * @return {Promise} the animation callback promise + */ + removeClass: function(element, className, options) { + return this.setClass(element, [], className, options); + }, + + $$removeClassImmediately: function(element, className, options) { + element = jqLite(element); + className = !isString(className) + ? (isArray(className) ? className.join(' ') : '') + : className; + forEach(element, function(element) { + jqLiteRemoveClass(element, className); + }); + applyStyles(element, options); + return asyncPromise(); + }, + + /** + * + * @ngdoc method + * @name $animate#setClass + * @kind function + * @description Adds and/or removes the given CSS classes to and from the element. + * When the function is called a promise is returned that will be resolved at a later time. + * @param {DOMElement} element the element which will have its CSS classes changed + * removed from it + * @param {string} add the CSS classes which will be added to the element + * @param {string} remove the CSS class which will be removed from the element + * @param {object=} options an optional collection of options that will be applied to the element. + * @return {Promise} the animation callback promise + */ + setClass: function(element, add, remove, options) { + var self = this; + var STORAGE_KEY = '$$animateClasses'; + var createdCache = false; + element = jqLite(element); + + var cache = element.data(STORAGE_KEY); + if (!cache) { + cache = { + classes: {}, + options: options + }; + createdCache = true; + } else if (options && cache.options) { + cache.options = angular.extend(cache.options || {}, options); + } + + var classes = cache.classes; + + add = isArray(add) ? add : add.split(' '); + remove = isArray(remove) ? remove : remove.split(' '); + cachedClassManipulation(classes, add, true); + cachedClassManipulation(classes, remove, false); + + if (createdCache) { + cache.promise = runAnimationPostDigest(function(done) { + var cache = element.data(STORAGE_KEY); + element.removeData(STORAGE_KEY); + + // in the event that the element is removed before postDigest + // is run then the cache will be undefined and there will be + // no need anymore to add or remove and of the element classes + if (cache) { + var classes = resolveElementClasses(element, cache.classes); + if (classes) { + self.$$setClassImmediately(element, classes[0], classes[1], cache.options); + } + } + + done(); + }); + element.data(STORAGE_KEY, cache); + } + + return cache.promise; + }, + + $$setClassImmediately: function(element, add, remove, options) { + add && this.$$addClassImmediately(element, add); + remove && this.$$removeClassImmediately(element, remove); + applyStyles(element, options); + return asyncPromise(); + }, + + enabled: noop, + cancel: noop + }; + }]; +}]; + +function $$AsyncCallbackProvider() { + this.$get = ['$$rAF', '$timeout', function($$rAF, $timeout) { + return $$rAF.supported + ? function(fn) { return $$rAF(fn); } + : function(fn) { + return $timeout(fn, 0, false); + }; + }]; +} + +/* global stripHash: true */ + +/** + * ! This is a private undocumented service ! + * + * @name $browser + * @requires $log + * @description + * This object has two goals: + * + * - hide all the global state in the browser caused by the window object + * - abstract away all the browser specific features and inconsistencies + * + * For tests we provide {@link ngMock.$browser mock implementation} of the `$browser` + * service, which can be used for convenient testing of the application without the interaction with + * the real browser apis. + */ +/** + * @param {object} window The global window object. + * @param {object} document jQuery wrapped document. + * @param {object} $log window.console or an object with the same interface. + * @param {object} $sniffer $sniffer service + */ +function Browser(window, document, $log, $sniffer) { + var self = this, + rawDocument = document[0], + location = window.location, + history = window.history, + setTimeout = window.setTimeout, + clearTimeout = window.clearTimeout, + pendingDeferIds = {}; + + self.isMock = false; + + var outstandingRequestCount = 0; + var outstandingRequestCallbacks = []; + + // TODO(vojta): remove this temporary api + self.$$completeOutstandingRequest = completeOutstandingRequest; + self.$$incOutstandingRequestCount = function() { outstandingRequestCount++; }; + + /** + * Executes the `fn` function(supports currying) and decrements the `outstandingRequestCallbacks` + * counter. If the counter reaches 0, all the `outstandingRequestCallbacks` are executed. + */ + function completeOutstandingRequest(fn) { + try { + fn.apply(null, sliceArgs(arguments, 1)); + } finally { + outstandingRequestCount--; + if (outstandingRequestCount === 0) { + while (outstandingRequestCallbacks.length) { + try { + outstandingRequestCallbacks.pop()(); + } catch (e) { + $log.error(e); + } + } + } + } + } + + function getHash(url) { + var index = url.indexOf('#'); + return index === -1 ? '' : url.substr(index); + } + + /** + * @private + * Note: this method is used only by scenario runner + * TODO(vojta): prefix this method with $$ ? + * @param {function()} callback Function that will be called when no outstanding request + */ + self.notifyWhenNoOutstandingRequests = function(callback) { + // force browser to execute all pollFns - this is needed so that cookies and other pollers fire + // at some deterministic time in respect to the test runner's actions. Leaving things up to the + // regular poller would result in flaky tests. + forEach(pollFns, function(pollFn) { pollFn(); }); + + if (outstandingRequestCount === 0) { + callback(); + } else { + outstandingRequestCallbacks.push(callback); + } + }; + + ////////////////////////////////////////////////////////////// + // Poll Watcher API + ////////////////////////////////////////////////////////////// + var pollFns = [], + pollTimeout; + + /** + * @name $browser#addPollFn + * + * @param {function()} fn Poll function to add + * + * @description + * Adds a function to the list of functions that poller periodically executes, + * and starts polling if not started yet. + * + * @returns {function()} the added function + */ + self.addPollFn = function(fn) { + if (isUndefined(pollTimeout)) startPoller(100, setTimeout); + pollFns.push(fn); + return fn; + }; + + /** + * @param {number} interval How often should browser call poll functions (ms) + * @param {function()} setTimeout Reference to a real or fake `setTimeout` function. + * + * @description + * Configures the poller to run in the specified intervals, using the specified + * setTimeout fn and kicks it off. + */ + function startPoller(interval, setTimeout) { + (function check() { + forEach(pollFns, function(pollFn) { pollFn(); }); + pollTimeout = setTimeout(check, interval); + })(); + } + + ////////////////////////////////////////////////////////////// + // URL API + ////////////////////////////////////////////////////////////// + + var cachedState, lastHistoryState, + lastBrowserUrl = location.href, + baseElement = document.find('base'), + reloadLocation = null; + + cacheState(); + lastHistoryState = cachedState; + + /** + * @name $browser#url + * + * @description + * GETTER: + * Without any argument, this method just returns current value of location.href. + * + * SETTER: + * With at least one argument, this method sets url to new value. + * If html5 history api supported, pushState/replaceState is used, otherwise + * location.href/location.replace is used. + * Returns its own instance to allow chaining + * + * NOTE: this api is intended for use only by the $location service. Please use the + * {@link ng.$location $location service} to change url. + * + * @param {string} url New url (when used as setter) + * @param {boolean=} replace Should new url replace current history record? + * @param {object=} state object to use with pushState/replaceState + */ + self.url = function(url, replace, state) { + // In modern browsers `history.state` is `null` by default; treating it separately + // from `undefined` would cause `$browser.url('/foo')` to change `history.state` + // to undefined via `pushState`. Instead, let's change `undefined` to `null` here. + if (isUndefined(state)) { + state = null; + } + + // Android Browser BFCache causes location, history reference to become stale. + if (location !== window.location) location = window.location; + if (history !== window.history) history = window.history; + + // setter + if (url) { + var sameState = lastHistoryState === state; + + // Don't change anything if previous and current URLs and states match. This also prevents + // IE<10 from getting into redirect loop when in LocationHashbangInHtml5Url mode. + // See https://github.com/angular/angular.js/commit/ffb2701 + if (lastBrowserUrl === url && (!$sniffer.history || sameState)) { + return self; + } + var sameBase = lastBrowserUrl && stripHash(lastBrowserUrl) === stripHash(url); + lastBrowserUrl = url; + lastHistoryState = state; + // Don't use history API if only the hash changed + // due to a bug in IE10/IE11 which leads + // to not firing a `hashchange` nor `popstate` event + // in some cases (see #9143). + if ($sniffer.history && (!sameBase || !sameState)) { + history[replace ? 'replaceState' : 'pushState'](state, '', url); + cacheState(); + // Do the assignment again so that those two variables are referentially identical. + lastHistoryState = cachedState; + } else { + if (!sameBase || reloadLocation) { + reloadLocation = url; + } + if (replace) { + location.replace(url); + } else if (!sameBase) { + location.href = url; + } else { + location.hash = getHash(url); + } + } + return self; + // getter + } else { + // - reloadLocation is needed as browsers don't allow to read out + // the new location.href if a reload happened. + // - the replacement is a workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=407172 + return reloadLocation || location.href.replace(/%27/g,"'"); + } + }; + + /** + * @name $browser#state + * + * @description + * This method is a getter. + * + * Return history.state or null if history.state is undefined. + * + * @returns {object} state + */ + self.state = function() { + return cachedState; + }; + + var urlChangeListeners = [], + urlChangeInit = false; + + function cacheStateAndFireUrlChange() { + cacheState(); + fireUrlChange(); + } + + function getCurrentState() { + try { + return history.state; + } catch (e) { + // MSIE can reportedly throw when there is no state (UNCONFIRMED). + } + } + + // This variable should be used *only* inside the cacheState function. + var lastCachedState = null; + function cacheState() { + // This should be the only place in $browser where `history.state` is read. + cachedState = getCurrentState(); + cachedState = isUndefined(cachedState) ? null : cachedState; + + // Prevent callbacks fo fire twice if both hashchange & popstate were fired. + if (equals(cachedState, lastCachedState)) { + cachedState = lastCachedState; + } + lastCachedState = cachedState; + } + + function fireUrlChange() { + if (lastBrowserUrl === self.url() && lastHistoryState === cachedState) { + return; + } + + lastBrowserUrl = self.url(); + lastHistoryState = cachedState; + forEach(urlChangeListeners, function(listener) { + listener(self.url(), cachedState); + }); + } + + /** + * @name $browser#onUrlChange + * + * @description + * Register callback function that will be called, when url changes. + * + * It's only called when the url is changed from outside of angular: + * - user types different url into address bar + * - user clicks on history (forward/back) button + * - user clicks on a link + * + * It's not called when url is changed by $browser.url() method + * + * The listener gets called with new url as parameter. + * + * NOTE: this api is intended for use only by the $location service. Please use the + * {@link ng.$location $location service} to monitor url changes in angular apps. + * + * @param {function(string)} listener Listener function to be called when url changes. + * @return {function(string)} Returns the registered listener fn - handy if the fn is anonymous. + */ + self.onUrlChange = function(callback) { + // TODO(vojta): refactor to use node's syntax for events + if (!urlChangeInit) { + // We listen on both (hashchange/popstate) when available, as some browsers (e.g. Opera) + // don't fire popstate when user change the address bar and don't fire hashchange when url + // changed by push/replaceState + + // html5 history api - popstate event + if ($sniffer.history) jqLite(window).on('popstate', cacheStateAndFireUrlChange); + // hashchange event + jqLite(window).on('hashchange', cacheStateAndFireUrlChange); + + urlChangeInit = true; + } + + urlChangeListeners.push(callback); + return callback; + }; + + /** + * Checks whether the url has changed outside of Angular. + * Needs to be exported to be able to check for changes that have been done in sync, + * as hashchange/popstate events fire in async. + */ + self.$$checkUrlChange = fireUrlChange; + + ////////////////////////////////////////////////////////////// + // Misc API + ////////////////////////////////////////////////////////////// + + /** + * @name $browser#baseHref + * + * @description + * Returns current + * (always relative - without domain) + * + * @returns {string} The current base href + */ + self.baseHref = function() { + var href = baseElement.attr('href'); + return href ? href.replace(/^(https?\:)?\/\/[^\/]*/, '') : ''; + }; + + ////////////////////////////////////////////////////////////// + // Cookies API + ////////////////////////////////////////////////////////////// + var lastCookies = {}; + var lastCookieString = ''; + var cookiePath = self.baseHref(); + + function safeDecodeURIComponent(str) { + try { + return decodeURIComponent(str); + } catch (e) { + return str; + } + } + + /** + * @name $browser#cookies + * + * @param {string=} name Cookie name + * @param {string=} value Cookie value + * + * @description + * The cookies method provides a 'private' low level access to browser cookies. + * It is not meant to be used directly, use the $cookie service instead. + * + * The return values vary depending on the arguments that the method was called with as follows: + * + * - cookies() -> hash of all cookies, this is NOT a copy of the internal state, so do not modify + * it + * - cookies(name, value) -> set name to value, if value is undefined delete the cookie + * - cookies(name) -> the same as (name, undefined) == DELETES (no one calls it right now that + * way) + * + * @returns {Object} Hash of all cookies (if called without any parameter) + */ + self.cookies = function(name, value) { + var cookieLength, cookieArray, cookie, i, index; + + if (name) { + if (value === undefined) { + rawDocument.cookie = encodeURIComponent(name) + "=;path=" + cookiePath + + ";expires=Thu, 01 Jan 1970 00:00:00 GMT"; + } else { + if (isString(value)) { + cookieLength = (rawDocument.cookie = encodeURIComponent(name) + '=' + encodeURIComponent(value) + + ';path=' + cookiePath).length + 1; + + // per http://www.ietf.org/rfc/rfc2109.txt browser must allow at minimum: + // - 300 cookies + // - 20 cookies per unique domain + // - 4096 bytes per cookie + if (cookieLength > 4096) { + $log.warn("Cookie '" + name + + "' possibly not set or overflowed because it was too large (" + + cookieLength + " > 4096 bytes)!"); + } + } + } + } else { + if (rawDocument.cookie !== lastCookieString) { + lastCookieString = rawDocument.cookie; + cookieArray = lastCookieString.split("; "); + lastCookies = {}; + + for (i = 0; i < cookieArray.length; i++) { + cookie = cookieArray[i]; + index = cookie.indexOf('='); + if (index > 0) { //ignore nameless cookies + name = safeDecodeURIComponent(cookie.substring(0, index)); + // the first value that is seen for a cookie is the most + // specific one. values for the same cookie name that + // follow are for less specific paths. + if (lastCookies[name] === undefined) { + lastCookies[name] = safeDecodeURIComponent(cookie.substring(index + 1)); + } + } + } + } + return lastCookies; + } + }; + + + /** + * @name $browser#defer + * @param {function()} fn A function, who's execution should be deferred. + * @param {number=} [delay=0] of milliseconds to defer the function execution. + * @returns {*} DeferId that can be used to cancel the task via `$browser.defer.cancel()`. + * + * @description + * Executes a fn asynchronously via `setTimeout(fn, delay)`. + * + * Unlike when calling `setTimeout` directly, in test this function is mocked and instead of using + * `setTimeout` in tests, the fns are queued in an array, which can be programmatically flushed + * via `$browser.defer.flush()`. + * + */ + self.defer = function(fn, delay) { + var timeoutId; + outstandingRequestCount++; + timeoutId = setTimeout(function() { + delete pendingDeferIds[timeoutId]; + completeOutstandingRequest(fn); + }, delay || 0); + pendingDeferIds[timeoutId] = true; + return timeoutId; + }; + + + /** + * @name $browser#defer.cancel + * + * @description + * Cancels a deferred task identified with `deferId`. + * + * @param {*} deferId Token returned by the `$browser.defer` function. + * @returns {boolean} Returns `true` if the task hasn't executed yet and was successfully + * canceled. + */ + self.defer.cancel = function(deferId) { + if (pendingDeferIds[deferId]) { + delete pendingDeferIds[deferId]; + clearTimeout(deferId); + completeOutstandingRequest(noop); + return true; + } + return false; + }; + +} + +function $BrowserProvider() { + this.$get = ['$window', '$log', '$sniffer', '$document', + function($window, $log, $sniffer, $document) { + return new Browser($window, $document, $log, $sniffer); + }]; +} + +/** + * @ngdoc service + * @name $cacheFactory + * + * @description + * Factory that constructs {@link $cacheFactory.Cache Cache} objects and gives access to + * them. + * + * ```js + * + * var cache = $cacheFactory('cacheId'); + * expect($cacheFactory.get('cacheId')).toBe(cache); + * expect($cacheFactory.get('noSuchCacheId')).not.toBeDefined(); + * + * cache.put("key", "value"); + * cache.put("another key", "another value"); + * + * // We've specified no options on creation + * expect(cache.info()).toEqual({id: 'cacheId', size: 2}); + * + * ``` + * + * + * @param {string} cacheId Name or id of the newly created cache. + * @param {object=} options Options object that specifies the cache behavior. Properties: + * + * - `{number=}` `capacity` — turns the cache into LRU cache. + * + * @returns {object} Newly created cache object with the following set of methods: + * + * - `{object}` `info()` — Returns id, size, and options of cache. + * - `{{*}}` `put({string} key, {*} value)` — Puts a new key-value pair into the cache and returns + * it. + * - `{{*}}` `get({string} key)` — Returns cached value for `key` or undefined for cache miss. + * - `{void}` `remove({string} key)` — Removes a key-value pair from the cache. + * - `{void}` `removeAll()` — Removes all cached values. + * - `{void}` `destroy()` — Removes references to this cache from $cacheFactory. + * + * @example + + +
      + + + + +

      Cached Values

      +
      + + : + +
      + +

      Cache Info

      +
      + + : + +
      +
      +
      + + angular.module('cacheExampleApp', []). + controller('CacheController', ['$scope', '$cacheFactory', function($scope, $cacheFactory) { + $scope.keys = []; + $scope.cache = $cacheFactory('cacheId'); + $scope.put = function(key, value) { + if ($scope.cache.get(key) === undefined) { + $scope.keys.push(key); + } + $scope.cache.put(key, value === undefined ? null : value); + }; + }]); + + + p { + margin: 10px 0 3px; + } + +
      + */ +function $CacheFactoryProvider() { + + this.$get = function() { + var caches = {}; + + function cacheFactory(cacheId, options) { + if (cacheId in caches) { + throw minErr('$cacheFactory')('iid', "CacheId '{0}' is already taken!", cacheId); + } + + var size = 0, + stats = extend({}, options, {id: cacheId}), + data = {}, + capacity = (options && options.capacity) || Number.MAX_VALUE, + lruHash = {}, + freshEnd = null, + staleEnd = null; + + /** + * @ngdoc type + * @name $cacheFactory.Cache + * + * @description + * A cache object used to store and retrieve data, primarily used by + * {@link $http $http} and the {@link ng.directive:script script} directive to cache + * templates and other data. + * + * ```js + * angular.module('superCache') + * .factory('superCache', ['$cacheFactory', function($cacheFactory) { + * return $cacheFactory('super-cache'); + * }]); + * ``` + * + * Example test: + * + * ```js + * it('should behave like a cache', inject(function(superCache) { + * superCache.put('key', 'value'); + * superCache.put('another key', 'another value'); + * + * expect(superCache.info()).toEqual({ + * id: 'super-cache', + * size: 2 + * }); + * + * superCache.remove('another key'); + * expect(superCache.get('another key')).toBeUndefined(); + * + * superCache.removeAll(); + * expect(superCache.info()).toEqual({ + * id: 'super-cache', + * size: 0 + * }); + * })); + * ``` + */ + return caches[cacheId] = { + + /** + * @ngdoc method + * @name $cacheFactory.Cache#put + * @kind function + * + * @description + * Inserts a named entry into the {@link $cacheFactory.Cache Cache} object to be + * retrieved later, and incrementing the size of the cache if the key was not already + * present in the cache. If behaving like an LRU cache, it will also remove stale + * entries from the set. + * + * It will not insert undefined values into the cache. + * + * @param {string} key the key under which the cached data is stored. + * @param {*} value the value to store alongside the key. If it is undefined, the key + * will not be stored. + * @returns {*} the value stored. + */ + put: function(key, value) { + if (capacity < Number.MAX_VALUE) { + var lruEntry = lruHash[key] || (lruHash[key] = {key: key}); + + refresh(lruEntry); + } + + if (isUndefined(value)) return; + if (!(key in data)) size++; + data[key] = value; + + if (size > capacity) { + this.remove(staleEnd.key); + } + + return value; + }, + + /** + * @ngdoc method + * @name $cacheFactory.Cache#get + * @kind function + * + * @description + * Retrieves named data stored in the {@link $cacheFactory.Cache Cache} object. + * + * @param {string} key the key of the data to be retrieved + * @returns {*} the value stored. + */ + get: function(key) { + if (capacity < Number.MAX_VALUE) { + var lruEntry = lruHash[key]; + + if (!lruEntry) return; + + refresh(lruEntry); + } + + return data[key]; + }, + + + /** + * @ngdoc method + * @name $cacheFactory.Cache#remove + * @kind function + * + * @description + * Removes an entry from the {@link $cacheFactory.Cache Cache} object. + * + * @param {string} key the key of the entry to be removed + */ + remove: function(key) { + if (capacity < Number.MAX_VALUE) { + var lruEntry = lruHash[key]; + + if (!lruEntry) return; + + if (lruEntry == freshEnd) freshEnd = lruEntry.p; + if (lruEntry == staleEnd) staleEnd = lruEntry.n; + link(lruEntry.n,lruEntry.p); + + delete lruHash[key]; + } + + delete data[key]; + size--; + }, + + + /** + * @ngdoc method + * @name $cacheFactory.Cache#removeAll + * @kind function + * + * @description + * Clears the cache object of any entries. + */ + removeAll: function() { + data = {}; + size = 0; + lruHash = {}; + freshEnd = staleEnd = null; + }, + + + /** + * @ngdoc method + * @name $cacheFactory.Cache#destroy + * @kind function + * + * @description + * Destroys the {@link $cacheFactory.Cache Cache} object entirely, + * removing it from the {@link $cacheFactory $cacheFactory} set. + */ + destroy: function() { + data = null; + stats = null; + lruHash = null; + delete caches[cacheId]; + }, + + + /** + * @ngdoc method + * @name $cacheFactory.Cache#info + * @kind function + * + * @description + * Retrieve information regarding a particular {@link $cacheFactory.Cache Cache}. + * + * @returns {object} an object with the following properties: + *
        + *
      • **id**: the id of the cache instance
      • + *
      • **size**: the number of entries kept in the cache instance
      • + *
      • **...**: any additional properties from the options object when creating the + * cache.
      • + *
      + */ + info: function() { + return extend({}, stats, {size: size}); + } + }; + + + /** + * makes the `entry` the freshEnd of the LRU linked list + */ + function refresh(entry) { + if (entry != freshEnd) { + if (!staleEnd) { + staleEnd = entry; + } else if (staleEnd == entry) { + staleEnd = entry.n; + } + + link(entry.n, entry.p); + link(entry, freshEnd); + freshEnd = entry; + freshEnd.n = null; + } + } + + + /** + * bidirectionally links two entries of the LRU linked list + */ + function link(nextEntry, prevEntry) { + if (nextEntry != prevEntry) { + if (nextEntry) nextEntry.p = prevEntry; //p stands for previous, 'prev' didn't minify + if (prevEntry) prevEntry.n = nextEntry; //n stands for next, 'next' didn't minify + } + } + } + + + /** + * @ngdoc method + * @name $cacheFactory#info + * + * @description + * Get information about all the caches that have been created + * + * @returns {Object} - key-value map of `cacheId` to the result of calling `cache#info` + */ + cacheFactory.info = function() { + var info = {}; + forEach(caches, function(cache, cacheId) { + info[cacheId] = cache.info(); + }); + return info; + }; + + + /** + * @ngdoc method + * @name $cacheFactory#get + * + * @description + * Get access to a cache object by the `cacheId` used when it was created. + * + * @param {string} cacheId Name or id of a cache to access. + * @returns {object} Cache object identified by the cacheId or undefined if no such cache. + */ + cacheFactory.get = function(cacheId) { + return caches[cacheId]; + }; + + + return cacheFactory; + }; +} + +/** + * @ngdoc service + * @name $templateCache + * + * @description + * The first time a template is used, it is loaded in the template cache for quick retrieval. You + * can load templates directly into the cache in a `script` tag, or by consuming the + * `$templateCache` service directly. + * + * Adding via the `script` tag: + * + * ```html + * + * ``` + * + * **Note:** the `script` tag containing the template does not need to be included in the `head` of + * the document, but it must be a descendent of the {@link ng.$rootElement $rootElement} (IE, + * element with ng-app attribute), otherwise the template will be ignored. + * + * Adding via the `$templateCache` service: + * + * ```js + * var myApp = angular.module('myApp', []); + * myApp.run(function($templateCache) { + * $templateCache.put('templateId.html', 'This is the content of the template'); + * }); + * ``` + * + * To retrieve the template later, simply use it in your HTML: + * ```html + *
      + * ``` + * + * or get it via Javascript: + * ```js + * $templateCache.get('templateId.html') + * ``` + * + * See {@link ng.$cacheFactory $cacheFactory}. + * + */ +function $TemplateCacheProvider() { + this.$get = ['$cacheFactory', function($cacheFactory) { + return $cacheFactory('templates'); + }]; +} + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Any commits to this file should be reviewed with security in mind. * + * Changes to this file can potentially create security vulnerabilities. * + * An approval from 2 Core members with history of modifying * + * this file is required. * + * * + * Does the change somehow allow for arbitrary javascript to be executed? * + * Or allows for someone to change the prototype of built-in objects? * + * Or gives undesired access to variables likes document or window? * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/* ! VARIABLE/FUNCTION NAMING CONVENTIONS THAT APPLY TO THIS FILE! + * + * DOM-related variables: + * + * - "node" - DOM Node + * - "element" - DOM Element or Node + * - "$node" or "$element" - jqLite-wrapped node or element + * + * + * Compiler related stuff: + * + * - "linkFn" - linking fn of a single directive + * - "nodeLinkFn" - function that aggregates all linking fns for a particular node + * - "childLinkFn" - function that aggregates all linking fns for child nodes of a particular node + * - "compositeLinkFn" - function that aggregates all linking fns for a compilation root (nodeList) + */ + + +/** + * @ngdoc service + * @name $compile + * @kind function + * + * @description + * Compiles an HTML string or DOM into a template and produces a template function, which + * can then be used to link {@link ng.$rootScope.Scope `scope`} and the template together. + * + * The compilation is a process of walking the DOM tree and matching DOM elements to + * {@link ng.$compileProvider#directive directives}. + * + *
      + * **Note:** This document is an in-depth reference of all directive options. + * For a gentle introduction to directives with examples of common use cases, + * see the {@link guide/directive directive guide}. + *
      + * + * ## Comprehensive Directive API + * + * There are many different options for a directive. + * + * The difference resides in the return value of the factory function. + * You can either return a "Directive Definition Object" (see below) that defines the directive properties, + * or just the `postLink` function (all other properties will have the default values). + * + *
      + * **Best Practice:** It's recommended to use the "directive definition object" form. + *
      + * + * Here's an example directive declared with a Directive Definition Object: + * + * ```js + * var myModule = angular.module(...); + * + * myModule.directive('directiveName', function factory(injectables) { + * var directiveDefinitionObject = { + * priority: 0, + * template: '
      ', // or // function(tElement, tAttrs) { ... }, + * // or + * // templateUrl: 'directive.html', // or // function(tElement, tAttrs) { ... }, + * transclude: false, + * restrict: 'A', + * templateNamespace: 'html', + * scope: false, + * controller: function($scope, $element, $attrs, $transclude, otherInjectables) { ... }, + * controllerAs: 'stringIdentifier', + * bindToController: false, + * require: 'siblingDirectiveName', // or // ['^parentDirectiveName', '?optionalDirectiveName', '?^optionalParent'], + * compile: function compile(tElement, tAttrs, transclude) { + * return { + * pre: function preLink(scope, iElement, iAttrs, controller) { ... }, + * post: function postLink(scope, iElement, iAttrs, controller) { ... } + * } + * // or + * // return function postLink( ... ) { ... } + * }, + * // or + * // link: { + * // pre: function preLink(scope, iElement, iAttrs, controller) { ... }, + * // post: function postLink(scope, iElement, iAttrs, controller) { ... } + * // } + * // or + * // link: function postLink( ... ) { ... } + * }; + * return directiveDefinitionObject; + * }); + * ``` + * + *
      + * **Note:** Any unspecified options will use the default value. You can see the default values below. + *
      + * + * Therefore the above can be simplified as: + * + * ```js + * var myModule = angular.module(...); + * + * myModule.directive('directiveName', function factory(injectables) { + * var directiveDefinitionObject = { + * link: function postLink(scope, iElement, iAttrs) { ... } + * }; + * return directiveDefinitionObject; + * // or + * // return function postLink(scope, iElement, iAttrs) { ... } + * }); + * ``` + * + * + * + * ### Directive Definition Object + * + * The directive definition object provides instructions to the {@link ng.$compile + * compiler}. The attributes are: + * + * #### `multiElement` + * When this property is set to true, the HTML compiler will collect DOM nodes between + * nodes with the attributes `directive-name-start` and `directive-name-end`, and group them + * together as the directive elements. It is recommended that this feature be used on directives + * which are not strictly behavioural (such as {@link ngClick}), and which + * do not manipulate or replace child nodes (such as {@link ngInclude}). + * + * #### `priority` + * When there are multiple directives defined on a single DOM element, sometimes it + * is necessary to specify the order in which the directives are applied. The `priority` is used + * to sort the directives before their `compile` functions get called. Priority is defined as a + * number. Directives with greater numerical `priority` are compiled first. Pre-link functions + * are also run in priority order, but post-link functions are run in reverse order. The order + * of directives with the same priority is undefined. The default priority is `0`. + * + * #### `terminal` + * If set to true then the current `priority` will be the last set of directives + * which will execute (any directives at the current priority will still execute + * as the order of execution on same `priority` is undefined). Note that expressions + * and other directives used in the directive's template will also be excluded from execution. + * + * #### `scope` + * **If set to `true`,** then a new scope will be created for this directive. If multiple directives on the + * same element request a new scope, only one new scope is created. The new scope rule does not + * apply for the root of the template since the root of the template always gets a new scope. + * + * **If set to `{}` (object hash),** then a new "isolate" scope is created. The 'isolate' scope differs from + * normal scope in that it does not prototypically inherit from the parent scope. This is useful + * when creating reusable components, which should not accidentally read or modify data in the + * parent scope. + * + * The 'isolate' scope takes an object hash which defines a set of local scope properties + * derived from the parent scope. These local properties are useful for aliasing values for + * templates. Locals definition is a hash of local scope property to its source: + * + * * `@` or `@attr` - bind a local scope property to the value of DOM attribute. The result is + * always a string since DOM attributes are strings. If no `attr` name is specified then the + * attribute name is assumed to be the same as the local name. + * Given `` and widget definition + * of `scope: { localName:'@myAttr' }`, then widget scope property `localName` will reflect + * the interpolated value of `hello {{name}}`. As the `name` attribute changes so will the + * `localName` property on the widget scope. The `name` is read from the parent scope (not + * component scope). + * + * * `=` or `=attr` - set up bi-directional binding between a local scope property and the + * parent scope property of name defined via the value of the `attr` attribute. If no `attr` + * name is specified then the attribute name is assumed to be the same as the local name. + * Given `` and widget definition of + * `scope: { localModel:'=myAttr' }`, then widget scope property `localModel` will reflect the + * value of `parentModel` on the parent scope. Any changes to `parentModel` will be reflected + * in `localModel` and any changes in `localModel` will reflect in `parentModel`. If the parent + * scope property doesn't exist, it will throw a NON_ASSIGNABLE_MODEL_EXPRESSION exception. You + * can avoid this behavior using `=?` or `=?attr` in order to flag the property as optional. If + * you want to shallow watch for changes (i.e. $watchCollection instead of $watch) you can use + * `=*` or `=*attr` (`=*?` or `=*?attr` if the property is optional). + * + * * `&` or `&attr` - provides a way to execute an expression in the context of the parent scope. + * If no `attr` name is specified then the attribute name is assumed to be the same as the + * local name. Given `` and widget definition of + * `scope: { localFn:'&myAttr' }`, then isolate scope property `localFn` will point to + * a function wrapper for the `count = count + value` expression. Often it's desirable to + * pass data from the isolated scope via an expression to the parent scope, this can be + * done by passing a map of local variable names and values into the expression wrapper fn. + * For example, if the expression is `increment(amount)` then we can specify the amount value + * by calling the `localFn` as `localFn({amount: 22})`. + * + * + * #### `bindToController` + * When an isolate scope is used for a component (see above), and `controllerAs` is used, `bindToController: true` will + * allow a component to have its properties bound to the controller, rather than to scope. When the controller + * is instantiated, the initial values of the isolate scope bindings are already available. + * + * #### `controller` + * Controller constructor function. The controller is instantiated before the + * pre-linking phase and it is shared with other directives (see + * `require` attribute). This allows the directives to communicate with each other and augment + * each other's behavior. The controller is injectable (and supports bracket notation) with the following locals: + * + * * `$scope` - Current scope associated with the element + * * `$element` - Current element + * * `$attrs` - Current attributes object for the element + * * `$transclude` - A transclude linking function pre-bound to the correct transclusion scope: + * `function([scope], cloneLinkingFn, futureParentElement)`. + * * `scope`: optional argument to override the scope. + * * `cloneLinkingFn`: optional argument to create clones of the original transcluded content. + * * `futureParentElement`: + * * defines the parent to which the `cloneLinkingFn` will add the cloned elements. + * * default: `$element.parent()` resp. `$element` for `transclude:'element'` resp. `transclude:true`. + * * only needed for transcludes that are allowed to contain non html elements (e.g. SVG elements) + * and when the `cloneLinkinFn` is passed, + * as those elements need to created and cloned in a special way when they are defined outside their + * usual containers (e.g. like ``). + * * See also the `directive.templateNamespace` property. + * + * + * #### `require` + * Require another directive and inject its controller as the fourth argument to the linking function. The + * `require` takes a string name (or array of strings) of the directive(s) to pass in. If an array is used, the + * injected argument will be an array in corresponding order. If no such directive can be + * found, or if the directive does not have a controller, then an error is raised (unless no link function + * is specified, in which case error checking is skipped). The name can be prefixed with: + * + * * (no prefix) - Locate the required controller on the current element. Throw an error if not found. + * * `?` - Attempt to locate the required controller or pass `null` to the `link` fn if not found. + * * `^` - Locate the required controller by searching the element and its parents. Throw an error if not found. + * * `^^` - Locate the required controller by searching the element's parents. Throw an error if not found. + * * `?^` - Attempt to locate the required controller by searching the element and its parents or pass + * `null` to the `link` fn if not found. + * * `?^^` - Attempt to locate the required controller by searching the element's parents, or pass + * `null` to the `link` fn if not found. + * + * + * #### `controllerAs` + * Controller alias at the directive scope. An alias for the controller so it + * can be referenced at the directive template. The directive needs to define a scope for this + * configuration to be used. Useful in the case when directive is used as component. + * + * + * #### `restrict` + * String of subset of `EACM` which restricts the directive to a specific directive + * declaration style. If omitted, the defaults (elements and attributes) are used. + * + * * `E` - Element name (default): `` + * * `A` - Attribute (default): `
      ` + * * `C` - Class: `
      ` + * * `M` - Comment: `` + * + * + * #### `templateNamespace` + * String representing the document type used by the markup in the template. + * AngularJS needs this information as those elements need to be created and cloned + * in a special way when they are defined outside their usual containers like `` and ``. + * + * * `html` - All root nodes in the template are HTML. Root nodes may also be + * top-level elements such as `` or ``. + * * `svg` - The root nodes in the template are SVG elements (excluding ``). + * * `math` - The root nodes in the template are MathML elements (excluding ``). + * + * If no `templateNamespace` is specified, then the namespace is considered to be `html`. + * + * #### `template` + * HTML markup that may: + * * Replace the contents of the directive's element (default). + * * Replace the directive's element itself (if `replace` is true - DEPRECATED). + * * Wrap the contents of the directive's element (if `transclude` is true). + * + * Value may be: + * + * * A string. For example `
      {{delete_str}}
      `. + * * A function which takes two arguments `tElement` and `tAttrs` (described in the `compile` + * function api below) and returns a string value. + * + * + * #### `templateUrl` + * This is similar to `template` but the template is loaded from the specified URL, asynchronously. + * + * Because template loading is asynchronous the compiler will suspend compilation of directives on that element + * for later when the template has been resolved. In the meantime it will continue to compile and link + * sibling and parent elements as though this element had not contained any directives. + * + * The compiler does not suspend the entire compilation to wait for templates to be loaded because this + * would result in the whole app "stalling" until all templates are loaded asynchronously - even in the + * case when only one deeply nested directive has `templateUrl`. + * + * Template loading is asynchronous even if the template has been preloaded into the {@link $templateCache} + * + * You can specify `templateUrl` as a string representing the URL or as a function which takes two + * arguments `tElement` and `tAttrs` (described in the `compile` function api below) and returns + * a string value representing the url. In either case, the template URL is passed through {@link + * $sce#getTrustedResourceUrl $sce.getTrustedResourceUrl}. + * + * + * #### `replace` ([*DEPRECATED*!], will be removed in next major release - i.e. v2.0) + * specify what the template should replace. Defaults to `false`. + * + * * `true` - the template will replace the directive's element. + * * `false` - the template will replace the contents of the directive's element. + * + * The replacement process migrates all of the attributes / classes from the old element to the new + * one. See the {@link guide/directive#template-expanding-directive + * Directives Guide} for an example. + * + * There are very few scenarios where element replacement is required for the application function, + * the main one being reusable custom components that are used within SVG contexts + * (because SVG doesn't work with custom elements in the DOM tree). + * + * #### `transclude` + * Extract the contents of the element where the directive appears and make it available to the directive. + * The contents are compiled and provided to the directive as a **transclusion function**. See the + * {@link $compile#transclusion Transclusion} section below. + * + * There are two kinds of transclusion depending upon whether you want to transclude just the contents of the + * directive's element or the entire element: + * + * * `true` - transclude the content (i.e. the child nodes) of the directive's element. + * * `'element'` - transclude the whole of the directive's element including any directives on this + * element that defined at a lower priority than this directive. When used, the `template` + * property is ignored. + * + * + * #### `compile` + * + * ```js + * function compile(tElement, tAttrs, transclude) { ... } + * ``` + * + * The compile function deals with transforming the template DOM. Since most directives do not do + * template transformation, it is not used often. The compile function takes the following arguments: + * + * * `tElement` - template element - The element where the directive has been declared. It is + * safe to do template transformation on the element and child elements only. + * + * * `tAttrs` - template attributes - Normalized list of attributes declared on this element shared + * between all directive compile functions. + * + * * `transclude` - [*DEPRECATED*!] A transclude linking function: `function(scope, cloneLinkingFn)` + * + *
      + * **Note:** The template instance and the link instance may be different objects if the template has + * been cloned. For this reason it is **not** safe to do anything other than DOM transformations that + * apply to all cloned DOM nodes within the compile function. Specifically, DOM listener registration + * should be done in a linking function rather than in a compile function. + *
      + + *
      + * **Note:** The compile function cannot handle directives that recursively use themselves in their + * own templates or compile functions. Compiling these directives results in an infinite loop and a + * stack overflow errors. + * + * This can be avoided by manually using $compile in the postLink function to imperatively compile + * a directive's template instead of relying on automatic template compilation via `template` or + * `templateUrl` declaration or manual compilation inside the compile function. + *
      + * + *
      + * **Note:** The `transclude` function that is passed to the compile function is deprecated, as it + * e.g. does not know about the right outer scope. Please use the transclude function that is passed + * to the link function instead. + *
      + + * A compile function can have a return value which can be either a function or an object. + * + * * returning a (post-link) function - is equivalent to registering the linking function via the + * `link` property of the config object when the compile function is empty. + * + * * returning an object with function(s) registered via `pre` and `post` properties - allows you to + * control when a linking function should be called during the linking phase. See info about + * pre-linking and post-linking functions below. + * + * + * #### `link` + * This property is used only if the `compile` property is not defined. + * + * ```js + * function link(scope, iElement, iAttrs, controller, transcludeFn) { ... } + * ``` + * + * The link function is responsible for registering DOM listeners as well as updating the DOM. It is + * executed after the template has been cloned. This is where most of the directive logic will be + * put. + * + * * `scope` - {@link ng.$rootScope.Scope Scope} - The scope to be used by the + * directive for registering {@link ng.$rootScope.Scope#$watch watches}. + * + * * `iElement` - instance element - The element where the directive is to be used. It is safe to + * manipulate the children of the element only in `postLink` function since the children have + * already been linked. + * + * * `iAttrs` - instance attributes - Normalized list of attributes declared on this element shared + * between all directive linking functions. + * + * * `controller` - the directive's required controller instance(s) - Instances are shared + * among all directives, which allows the directives to use the controllers as a communication + * channel. The exact value depends on the directive's `require` property: + * * `string`: the controller instance + * * `array`: array of controller instances + * * no controller(s) required: `undefined` + * + * If a required controller cannot be found, and it is optional, the instance is `null`, + * otherwise the {@link error:$compile:ctreq Missing Required Controller} error is thrown. + * + * * `transcludeFn` - A transclude linking function pre-bound to the correct transclusion scope. + * This is the same as the `$transclude` + * parameter of directive controllers, see there for details. + * `function([scope], cloneLinkingFn, futureParentElement)`. + * + * #### Pre-linking function + * + * Executed before the child elements are linked. Not safe to do DOM transformation since the + * compiler linking function will fail to locate the correct elements for linking. + * + * #### Post-linking function + * + * Executed after the child elements are linked. + * + * Note that child elements that contain `templateUrl` directives will not have been compiled + * and linked since they are waiting for their template to load asynchronously and their own + * compilation and linking has been suspended until that occurs. + * + * It is safe to do DOM transformation in the post-linking function on elements that are not waiting + * for their async templates to be resolved. + * + * + * ### Transclusion + * + * Transclusion is the process of extracting a collection of DOM elements from one part of the DOM and + * copying them to another part of the DOM, while maintaining their connection to the original AngularJS + * scope from where they were taken. + * + * Transclusion is used (often with {@link ngTransclude}) to insert the + * original contents of a directive's element into a specified place in the template of the directive. + * The benefit of transclusion, over simply moving the DOM elements manually, is that the transcluded + * content has access to the properties on the scope from which it was taken, even if the directive + * has isolated scope. + * See the {@link guide/directive#creating-a-directive-that-wraps-other-elements Directives Guide}. + * + * This makes it possible for the widget to have private state for its template, while the transcluded + * content has access to its originating scope. + * + *
      + * **Note:** When testing an element transclude directive you must not place the directive at the root of the + * DOM fragment that is being compiled. See {@link guide/unit-testing#testing-transclusion-directives + * Testing Transclusion Directives}. + *
      + * + * #### Transclusion Functions + * + * When a directive requests transclusion, the compiler extracts its contents and provides a **transclusion + * function** to the directive's `link` function and `controller`. This transclusion function is a special + * **linking function** that will return the compiled contents linked to a new transclusion scope. + * + *
      + * If you are just using {@link ngTransclude} then you don't need to worry about this function, since + * ngTransclude will deal with it for us. + *
      + * + * If you want to manually control the insertion and removal of the transcluded content in your directive + * then you must use this transclude function. When you call a transclude function it returns a a jqLite/JQuery + * object that contains the compiled DOM, which is linked to the correct transclusion scope. + * + * When you call a transclusion function you can pass in a **clone attach function**. This function accepts + * two parameters, `function(clone, scope) { ... }`, where the `clone` is a fresh compiled copy of your transcluded + * content and the `scope` is the newly created transclusion scope, to which the clone is bound. + * + *
      + * **Best Practice**: Always provide a `cloneFn` (clone attach function) when you call a translude function + * since you then get a fresh clone of the original DOM and also have access to the new transclusion scope. + *
      + * + * It is normal practice to attach your transcluded content (`clone`) to the DOM inside your **clone + * attach function**: + * + * ```js + * var transcludedContent, transclusionScope; + * + * $transclude(function(clone, scope) { + * element.append(clone); + * transcludedContent = clone; + * transclusionScope = scope; + * }); + * ``` + * + * Later, if you want to remove the transcluded content from your DOM then you should also destroy the + * associated transclusion scope: + * + * ```js + * transcludedContent.remove(); + * transclusionScope.$destroy(); + * ``` + * + *
      + * **Best Practice**: if you intend to add and remove transcluded content manually in your directive + * (by calling the transclude function to get the DOM and and calling `element.remove()` to remove it), + * then you are also responsible for calling `$destroy` on the transclusion scope. + *
      + * + * The built-in DOM manipulation directives, such as {@link ngIf}, {@link ngSwitch} and {@link ngRepeat} + * automatically destroy their transluded clones as necessary so you do not need to worry about this if + * you are simply using {@link ngTransclude} to inject the transclusion into your directive. + * + * + * #### Transclusion Scopes + * + * When you call a transclude function it returns a DOM fragment that is pre-bound to a **transclusion + * scope**. This scope is special, in that it is a child of the directive's scope (and so gets destroyed + * when the directive's scope gets destroyed) but it inherits the properties of the scope from which it + * was taken. + * + * For example consider a directive that uses transclusion and isolated scope. The DOM hierarchy might look + * like this: + * + * ```html + *
      + *
      + *
      + *
      + *
      + *
      + * ``` + * + * The `$parent` scope hierarchy will look like this: + * + * ``` + * - $rootScope + * - isolate + * - transclusion + * ``` + * + * but the scopes will inherit prototypically from different scopes to their `$parent`. + * + * ``` + * - $rootScope + * - transclusion + * - isolate + * ``` + * + * + * ### Attributes + * + * The {@link ng.$compile.directive.Attributes Attributes} object - passed as a parameter in the + * `link()` or `compile()` functions. It has a variety of uses. + * + * accessing *Normalized attribute names:* + * Directives like 'ngBind' can be expressed in many ways: 'ng:bind', `data-ng-bind`, or 'x-ng-bind'. + * the attributes object allows for normalized access to + * the attributes. + * + * * *Directive inter-communication:* All directives share the same instance of the attributes + * object which allows the directives to use the attributes object as inter directive + * communication. + * + * * *Supports interpolation:* Interpolation attributes are assigned to the attribute object + * allowing other directives to read the interpolated value. + * + * * *Observing interpolated attributes:* Use `$observe` to observe the value changes of attributes + * that contain interpolation (e.g. `src="{{bar}}"`). Not only is this very efficient but it's also + * the only way to easily get the actual value because during the linking phase the interpolation + * hasn't been evaluated yet and so the value is at this time set to `undefined`. + * + * ```js + * function linkingFn(scope, elm, attrs, ctrl) { + * // get the attribute value + * console.log(attrs.ngModel); + * + * // change the attribute + * attrs.$set('ngModel', 'new value'); + * + * // observe changes to interpolated attribute + * attrs.$observe('ngModel', function(value) { + * console.log('ngModel has changed value to ' + value); + * }); + * } + * ``` + * + * ## Example + * + *
      + * **Note**: Typically directives are registered with `module.directive`. The example below is + * to illustrate how `$compile` works. + *
      + * + + + +
      +
      +
      +
      +
      +
      + + it('should auto compile', function() { + var textarea = $('textarea'); + var output = $('div[compile]'); + // The initial state reads 'Hello Angular'. + expect(output.getText()).toBe('Hello Angular'); + textarea.clear(); + textarea.sendKeys('{{name}}!'); + expect(output.getText()).toBe('Angular!'); + }); + +
      + + * + * + * @param {string|DOMElement} element Element or HTML string to compile into a template function. + * @param {function(angular.Scope, cloneAttachFn=)} transclude function available to directives - DEPRECATED. + * + *
      + * **Note:** Passing a `transclude` function to the $compile function is deprecated, as it + * e.g. will not use the right outer scope. Please pass the transclude function as a + * `parentBoundTranscludeFn` to the link function instead. + *
      + * + * @param {number} maxPriority only apply directives lower than given priority (Only effects the + * root element(s), not their children) + * @returns {function(scope, cloneAttachFn=, options=)} a link function which is used to bind template + * (a DOM element/tree) to a scope. Where: + * + * * `scope` - A {@link ng.$rootScope.Scope Scope} to bind to. + * * `cloneAttachFn` - If `cloneAttachFn` is provided, then the link function will clone the + * `template` and call the `cloneAttachFn` function allowing the caller to attach the + * cloned elements to the DOM document at the appropriate place. The `cloneAttachFn` is + * called as:
      `cloneAttachFn(clonedElement, scope)` where: + * + * * `clonedElement` - is a clone of the original `element` passed into the compiler. + * * `scope` - is the current scope with which the linking function is working with. + * + * * `options` - An optional object hash with linking options. If `options` is provided, then the following + * keys may be used to control linking behavior: + * + * * `parentBoundTranscludeFn` - the transclude function made available to + * directives; if given, it will be passed through to the link functions of + * directives found in `element` during compilation. + * * `transcludeControllers` - an object hash with keys that map controller names + * to controller instances; if given, it will make the controllers + * available to directives. + * * `futureParentElement` - defines the parent to which the `cloneAttachFn` will add + * the cloned elements; only needed for transcludes that are allowed to contain non html + * elements (e.g. SVG elements). See also the directive.controller property. + * + * Calling the linking function returns the element of the template. It is either the original + * element passed in, or the clone of the element if the `cloneAttachFn` is provided. + * + * After linking the view is not updated until after a call to $digest which typically is done by + * Angular automatically. + * + * If you need access to the bound view, there are two ways to do it: + * + * - If you are not asking the linking function to clone the template, create the DOM element(s) + * before you send them to the compiler and keep this reference around. + * ```js + * var element = $compile('

      {{total}}

      ')(scope); + * ``` + * + * - if on the other hand, you need the element to be cloned, the view reference from the original + * example would not point to the clone, but rather to the original template that was cloned. In + * this case, you can access the clone via the cloneAttachFn: + * ```js + * var templateElement = angular.element('

      {{total}}

      '), + * scope = ....; + * + * var clonedElement = $compile(templateElement)(scope, function(clonedElement, scope) { + * //attach the clone to DOM document at the right place + * }); + * + * //now we have reference to the cloned DOM via `clonedElement` + * ``` + * + * + * For information on how the compiler works, see the + * {@link guide/compiler Angular HTML Compiler} section of the Developer Guide. + */ + +var $compileMinErr = minErr('$compile'); + +/** + * @ngdoc provider + * @name $compileProvider + * + * @description + */ +$CompileProvider.$inject = ['$provide', '$$sanitizeUriProvider']; +function $CompileProvider($provide, $$sanitizeUriProvider) { + var hasDirectives = {}, + Suffix = 'Directive', + COMMENT_DIRECTIVE_REGEXP = /^\s*directive\:\s*([\w\-]+)\s+(.*)$/, + CLASS_DIRECTIVE_REGEXP = /(([\w\-]+)(?:\:([^;]+))?;?)/, + ALL_OR_NOTHING_ATTRS = makeMap('ngSrc,ngSrcset,src,srcset'), + REQUIRE_PREFIX_REGEXP = /^(?:(\^\^?)?(\?)?(\^\^?)?)?/; + + // Ref: http://developers.whatwg.org/webappapis.html#event-handler-idl-attributes + // The assumption is that future DOM event attribute names will begin with + // 'on' and be composed of only English letters. + var EVENT_HANDLER_ATTR_REGEXP = /^(on[a-z]+|formaction)$/; + + function parseIsolateBindings(scope, directiveName) { + var LOCAL_REGEXP = /^\s*([@&]|=(\*?))(\??)\s*(\w*)\s*$/; + + var bindings = {}; + + forEach(scope, function(definition, scopeName) { + var match = definition.match(LOCAL_REGEXP); + + if (!match) { + throw $compileMinErr('iscp', + "Invalid isolate scope definition for directive '{0}'." + + " Definition: {... {1}: '{2}' ...}", + directiveName, scopeName, definition); + } + + bindings[scopeName] = { + mode: match[1][0], + collection: match[2] === '*', + optional: match[3] === '?', + attrName: match[4] || scopeName + }; + }); + + return bindings; + } + + /** + * @ngdoc method + * @name $compileProvider#directive + * @kind function + * + * @description + * Register a new directive with the compiler. + * + * @param {string|Object} name Name of the directive in camel-case (i.e. ngBind which + * will match as ng-bind), or an object map of directives where the keys are the + * names and the values are the factories. + * @param {Function|Array} directiveFactory An injectable directive factory function. See + * {@link guide/directive} for more info. + * @returns {ng.$compileProvider} Self for chaining. + */ + this.directive = function registerDirective(name, directiveFactory) { + assertNotHasOwnProperty(name, 'directive'); + if (isString(name)) { + assertArg(directiveFactory, 'directiveFactory'); + if (!hasDirectives.hasOwnProperty(name)) { + hasDirectives[name] = []; + $provide.factory(name + Suffix, ['$injector', '$exceptionHandler', + function($injector, $exceptionHandler) { + var directives = []; + forEach(hasDirectives[name], function(directiveFactory, index) { + try { + var directive = $injector.invoke(directiveFactory); + if (isFunction(directive)) { + directive = { compile: valueFn(directive) }; + } else if (!directive.compile && directive.link) { + directive.compile = valueFn(directive.link); + } + directive.priority = directive.priority || 0; + directive.index = index; + directive.name = directive.name || name; + directive.require = directive.require || (directive.controller && directive.name); + directive.restrict = directive.restrict || 'EA'; + if (isObject(directive.scope)) { + directive.$$isolateBindings = parseIsolateBindings(directive.scope, directive.name); + } + directives.push(directive); + } catch (e) { + $exceptionHandler(e); + } + }); + return directives; + }]); + } + hasDirectives[name].push(directiveFactory); + } else { + forEach(name, reverseParams(registerDirective)); + } + return this; + }; + + + /** + * @ngdoc method + * @name $compileProvider#aHrefSanitizationWhitelist + * @kind function + * + * @description + * Retrieves or overrides the default regular expression that is used for whitelisting of safe + * urls during a[href] sanitization. + * + * The sanitization is a security measure aimed at preventing XSS attacks via html links. + * + * Any url about to be assigned to a[href] via data-binding is first normalized and turned into + * an absolute url. Afterwards, the url is matched against the `aHrefSanitizationWhitelist` + * regular expression. If a match is found, the original url is written into the dom. Otherwise, + * the absolute url is prefixed with `'unsafe:'` string and only then is it written into the DOM. + * + * @param {RegExp=} regexp New regexp to whitelist urls with. + * @returns {RegExp|ng.$compileProvider} Current RegExp if called without value or self for + * chaining otherwise. + */ + this.aHrefSanitizationWhitelist = function(regexp) { + if (isDefined(regexp)) { + $$sanitizeUriProvider.aHrefSanitizationWhitelist(regexp); + return this; + } else { + return $$sanitizeUriProvider.aHrefSanitizationWhitelist(); + } + }; + + + /** + * @ngdoc method + * @name $compileProvider#imgSrcSanitizationWhitelist + * @kind function + * + * @description + * Retrieves or overrides the default regular expression that is used for whitelisting of safe + * urls during img[src] sanitization. + * + * The sanitization is a security measure aimed at prevent XSS attacks via html links. + * + * Any url about to be assigned to img[src] via data-binding is first normalized and turned into + * an absolute url. Afterwards, the url is matched against the `imgSrcSanitizationWhitelist` + * regular expression. If a match is found, the original url is written into the dom. Otherwise, + * the absolute url is prefixed with `'unsafe:'` string and only then is it written into the DOM. + * + * @param {RegExp=} regexp New regexp to whitelist urls with. + * @returns {RegExp|ng.$compileProvider} Current RegExp if called without value or self for + * chaining otherwise. + */ + this.imgSrcSanitizationWhitelist = function(regexp) { + if (isDefined(regexp)) { + $$sanitizeUriProvider.imgSrcSanitizationWhitelist(regexp); + return this; + } else { + return $$sanitizeUriProvider.imgSrcSanitizationWhitelist(); + } + }; + + /** + * @ngdoc method + * @name $compileProvider#debugInfoEnabled + * + * @param {boolean=} enabled update the debugInfoEnabled state if provided, otherwise just return the + * current debugInfoEnabled state + * @returns {*} current value if used as getter or itself (chaining) if used as setter + * + * @kind function + * + * @description + * Call this method to enable/disable various debug runtime information in the compiler such as adding + * binding information and a reference to the current scope on to DOM elements. + * If enabled, the compiler will add the following to DOM elements that have been bound to the scope + * * `ng-binding` CSS class + * * `$binding` data property containing an array of the binding expressions + * + * You may want to disable this in production for a significant performance boost. See + * {@link guide/production#disabling-debug-data Disabling Debug Data} for more. + * + * The default value is true. + */ + var debugInfoEnabled = true; + this.debugInfoEnabled = function(enabled) { + if (isDefined(enabled)) { + debugInfoEnabled = enabled; + return this; + } + return debugInfoEnabled; + }; + + this.$get = [ + '$injector', '$interpolate', '$exceptionHandler', '$templateRequest', '$parse', + '$controller', '$rootScope', '$document', '$sce', '$animate', '$$sanitizeUri', + function($injector, $interpolate, $exceptionHandler, $templateRequest, $parse, + $controller, $rootScope, $document, $sce, $animate, $$sanitizeUri) { + + var Attributes = function(element, attributesToCopy) { + if (attributesToCopy) { + var keys = Object.keys(attributesToCopy); + var i, l, key; + + for (i = 0, l = keys.length; i < l; i++) { + key = keys[i]; + this[key] = attributesToCopy[key]; + } + } else { + this.$attr = {}; + } + + this.$$element = element; + }; + + Attributes.prototype = { + /** + * @ngdoc method + * @name $compile.directive.Attributes#$normalize + * @kind function + * + * @description + * Converts an attribute name (e.g. dash/colon/underscore-delimited string, optionally prefixed with `x-` or + * `data-`) to its normalized, camelCase form. + * + * Also there is special case for Moz prefix starting with upper case letter. + * + * For further information check out the guide on {@link guide/directive#matching-directives Matching Directives} + * + * @param {string} name Name to normalize + */ + $normalize: directiveNormalize, + + + /** + * @ngdoc method + * @name $compile.directive.Attributes#$addClass + * @kind function + * + * @description + * Adds the CSS class value specified by the classVal parameter to the element. If animations + * are enabled then an animation will be triggered for the class addition. + * + * @param {string} classVal The className value that will be added to the element + */ + $addClass: function(classVal) { + if (classVal && classVal.length > 0) { + $animate.addClass(this.$$element, classVal); + } + }, + + /** + * @ngdoc method + * @name $compile.directive.Attributes#$removeClass + * @kind function + * + * @description + * Removes the CSS class value specified by the classVal parameter from the element. If + * animations are enabled then an animation will be triggered for the class removal. + * + * @param {string} classVal The className value that will be removed from the element + */ + $removeClass: function(classVal) { + if (classVal && classVal.length > 0) { + $animate.removeClass(this.$$element, classVal); + } + }, + + /** + * @ngdoc method + * @name $compile.directive.Attributes#$updateClass + * @kind function + * + * @description + * Adds and removes the appropriate CSS class values to the element based on the difference + * between the new and old CSS class values (specified as newClasses and oldClasses). + * + * @param {string} newClasses The current CSS className value + * @param {string} oldClasses The former CSS className value + */ + $updateClass: function(newClasses, oldClasses) { + var toAdd = tokenDifference(newClasses, oldClasses); + if (toAdd && toAdd.length) { + $animate.addClass(this.$$element, toAdd); + } + + var toRemove = tokenDifference(oldClasses, newClasses); + if (toRemove && toRemove.length) { + $animate.removeClass(this.$$element, toRemove); + } + }, + + /** + * Set a normalized attribute on the element in a way such that all directives + * can share the attribute. This function properly handles boolean attributes. + * @param {string} key Normalized key. (ie ngAttribute) + * @param {string|boolean} value The value to set. If `null` attribute will be deleted. + * @param {boolean=} writeAttr If false, does not write the value to DOM element attribute. + * Defaults to true. + * @param {string=} attrName Optional none normalized name. Defaults to key. + */ + $set: function(key, value, writeAttr, attrName) { + // TODO: decide whether or not to throw an error if "class" + //is set through this function since it may cause $updateClass to + //become unstable. + + var node = this.$$element[0], + booleanKey = getBooleanAttrName(node, key), + aliasedKey = getAliasedAttrName(node, key), + observer = key, + nodeName; + + if (booleanKey) { + this.$$element.prop(key, value); + attrName = booleanKey; + } else if (aliasedKey) { + this[aliasedKey] = value; + observer = aliasedKey; + } + + this[key] = value; + + // translate normalized key to actual key + if (attrName) { + this.$attr[key] = attrName; + } else { + attrName = this.$attr[key]; + if (!attrName) { + this.$attr[key] = attrName = snake_case(key, '-'); + } + } + + nodeName = nodeName_(this.$$element); + + if ((nodeName === 'a' && key === 'href') || + (nodeName === 'img' && key === 'src')) { + // sanitize a[href] and img[src] values + this[key] = value = $$sanitizeUri(value, key === 'src'); + } else if (nodeName === 'img' && key === 'srcset') { + // sanitize img[srcset] values + var result = ""; + + // first check if there are spaces because it's not the same pattern + var trimmedSrcset = trim(value); + // ( 999x ,| 999w ,| ,|, ) + var srcPattern = /(\s+\d+x\s*,|\s+\d+w\s*,|\s+,|,\s+)/; + var pattern = /\s/.test(trimmedSrcset) ? srcPattern : /(,)/; + + // split srcset into tuple of uri and descriptor except for the last item + var rawUris = trimmedSrcset.split(pattern); + + // for each tuples + var nbrUrisWith2parts = Math.floor(rawUris.length / 2); + for (var i = 0; i < nbrUrisWith2parts; i++) { + var innerIdx = i * 2; + // sanitize the uri + result += $$sanitizeUri(trim(rawUris[innerIdx]), true); + // add the descriptor + result += (" " + trim(rawUris[innerIdx + 1])); + } + + // split the last item into uri and descriptor + var lastTuple = trim(rawUris[i * 2]).split(/\s/); + + // sanitize the last uri + result += $$sanitizeUri(trim(lastTuple[0]), true); + + // and add the last descriptor if any + if (lastTuple.length === 2) { + result += (" " + trim(lastTuple[1])); + } + this[key] = value = result; + } + + if (writeAttr !== false) { + if (value === null || value === undefined) { + this.$$element.removeAttr(attrName); + } else { + this.$$element.attr(attrName, value); + } + } + + // fire observers + var $$observers = this.$$observers; + $$observers && forEach($$observers[observer], function(fn) { + try { + fn(value); + } catch (e) { + $exceptionHandler(e); + } + }); + }, + + + /** + * @ngdoc method + * @name $compile.directive.Attributes#$observe + * @kind function + * + * @description + * Observes an interpolated attribute. + * + * The observer function will be invoked once during the next `$digest` following + * compilation. The observer is then invoked whenever the interpolated value + * changes. + * + * @param {string} key Normalized key. (ie ngAttribute) . + * @param {function(interpolatedValue)} fn Function that will be called whenever + the interpolated value of the attribute changes. + * See the {@link guide/directive#text-and-attribute-bindings Directives} guide for more info. + * @returns {function()} Returns a deregistration function for this observer. + */ + $observe: function(key, fn) { + var attrs = this, + $$observers = (attrs.$$observers || (attrs.$$observers = createMap())), + listeners = ($$observers[key] || ($$observers[key] = [])); + + listeners.push(fn); + $rootScope.$evalAsync(function() { + if (!listeners.$$inter && attrs.hasOwnProperty(key)) { + // no one registered attribute interpolation function, so lets call it manually + fn(attrs[key]); + } + }); + + return function() { + arrayRemove(listeners, fn); + }; + } + }; + + + function safeAddClass($element, className) { + try { + $element.addClass(className); + } catch (e) { + // ignore, since it means that we are trying to set class on + // SVG element, where class name is read-only. + } + } + + + var startSymbol = $interpolate.startSymbol(), + endSymbol = $interpolate.endSymbol(), + denormalizeTemplate = (startSymbol == '{{' || endSymbol == '}}') + ? identity + : function denormalizeTemplate(template) { + return template.replace(/\{\{/g, startSymbol).replace(/}}/g, endSymbol); + }, + NG_ATTR_BINDING = /^ngAttr[A-Z]/; + + compile.$$addBindingInfo = debugInfoEnabled ? function $$addBindingInfo($element, binding) { + var bindings = $element.data('$binding') || []; + + if (isArray(binding)) { + bindings = bindings.concat(binding); + } else { + bindings.push(binding); + } + + $element.data('$binding', bindings); + } : noop; + + compile.$$addBindingClass = debugInfoEnabled ? function $$addBindingClass($element) { + safeAddClass($element, 'ng-binding'); + } : noop; + + compile.$$addScopeInfo = debugInfoEnabled ? function $$addScopeInfo($element, scope, isolated, noTemplate) { + var dataName = isolated ? (noTemplate ? '$isolateScopeNoTemplate' : '$isolateScope') : '$scope'; + $element.data(dataName, scope); + } : noop; + + compile.$$addScopeClass = debugInfoEnabled ? function $$addScopeClass($element, isolated) { + safeAddClass($element, isolated ? 'ng-isolate-scope' : 'ng-scope'); + } : noop; + + return compile; + + //================================ + + function compile($compileNodes, transcludeFn, maxPriority, ignoreDirective, + previousCompileContext) { + if (!($compileNodes instanceof jqLite)) { + // jquery always rewraps, whereas we need to preserve the original selector so that we can + // modify it. + $compileNodes = jqLite($compileNodes); + } + // We can not compile top level text elements since text nodes can be merged and we will + // not be able to attach scope data to them, so we will wrap them in + forEach($compileNodes, function(node, index) { + if (node.nodeType == NODE_TYPE_TEXT && node.nodeValue.match(/\S+/) /* non-empty */ ) { + $compileNodes[index] = jqLite(node).wrap('').parent()[0]; + } + }); + var compositeLinkFn = + compileNodes($compileNodes, transcludeFn, $compileNodes, + maxPriority, ignoreDirective, previousCompileContext); + compile.$$addScopeClass($compileNodes); + var namespace = null; + return function publicLinkFn(scope, cloneConnectFn, options) { + assertArg(scope, 'scope'); + + options = options || {}; + var parentBoundTranscludeFn = options.parentBoundTranscludeFn, + transcludeControllers = options.transcludeControllers, + futureParentElement = options.futureParentElement; + + // When `parentBoundTranscludeFn` is passed, it is a + // `controllersBoundTransclude` function (it was previously passed + // as `transclude` to directive.link) so we must unwrap it to get + // its `boundTranscludeFn` + if (parentBoundTranscludeFn && parentBoundTranscludeFn.$$boundTransclude) { + parentBoundTranscludeFn = parentBoundTranscludeFn.$$boundTransclude; + } + + if (!namespace) { + namespace = detectNamespaceForChildElements(futureParentElement); + } + var $linkNode; + if (namespace !== 'html') { + // When using a directive with replace:true and templateUrl the $compileNodes + // (or a child element inside of them) + // might change, so we need to recreate the namespace adapted compileNodes + // for call to the link function. + // Note: This will already clone the nodes... + $linkNode = jqLite( + wrapTemplate(namespace, jqLite('
      ').append($compileNodes).html()) + ); + } else if (cloneConnectFn) { + // important!!: we must call our jqLite.clone() since the jQuery one is trying to be smart + // and sometimes changes the structure of the DOM. + $linkNode = JQLitePrototype.clone.call($compileNodes); + } else { + $linkNode = $compileNodes; + } + + if (transcludeControllers) { + for (var controllerName in transcludeControllers) { + $linkNode.data('$' + controllerName + 'Controller', transcludeControllers[controllerName].instance); + } + } + + compile.$$addScopeInfo($linkNode, scope); + + if (cloneConnectFn) cloneConnectFn($linkNode, scope); + if (compositeLinkFn) compositeLinkFn(scope, $linkNode, $linkNode, parentBoundTranscludeFn); + return $linkNode; + }; + } + + function detectNamespaceForChildElements(parentElement) { + // TODO: Make this detect MathML as well... + var node = parentElement && parentElement[0]; + if (!node) { + return 'html'; + } else { + return nodeName_(node) !== 'foreignobject' && node.toString().match(/SVG/) ? 'svg' : 'html'; + } + } + + /** + * Compile function matches each node in nodeList against the directives. Once all directives + * for a particular node are collected their compile functions are executed. The compile + * functions return values - the linking functions - are combined into a composite linking + * function, which is the a linking function for the node. + * + * @param {NodeList} nodeList an array of nodes or NodeList to compile + * @param {function(angular.Scope, cloneAttachFn=)} transcludeFn A linking function, where the + * scope argument is auto-generated to the new child of the transcluded parent scope. + * @param {DOMElement=} $rootElement If the nodeList is the root of the compilation tree then + * the rootElement must be set the jqLite collection of the compile root. This is + * needed so that the jqLite collection items can be replaced with widgets. + * @param {number=} maxPriority Max directive priority. + * @returns {Function} A composite linking function of all of the matched directives or null. + */ + function compileNodes(nodeList, transcludeFn, $rootElement, maxPriority, ignoreDirective, + previousCompileContext) { + var linkFns = [], + attrs, directives, nodeLinkFn, childNodes, childLinkFn, linkFnFound, nodeLinkFnFound; + + for (var i = 0; i < nodeList.length; i++) { + attrs = new Attributes(); + + // we must always refer to nodeList[i] since the nodes can be replaced underneath us. + directives = collectDirectives(nodeList[i], [], attrs, i === 0 ? maxPriority : undefined, + ignoreDirective); + + nodeLinkFn = (directives.length) + ? applyDirectivesToNode(directives, nodeList[i], attrs, transcludeFn, $rootElement, + null, [], [], previousCompileContext) + : null; + + if (nodeLinkFn && nodeLinkFn.scope) { + compile.$$addScopeClass(attrs.$$element); + } + + childLinkFn = (nodeLinkFn && nodeLinkFn.terminal || + !(childNodes = nodeList[i].childNodes) || + !childNodes.length) + ? null + : compileNodes(childNodes, + nodeLinkFn ? ( + (nodeLinkFn.transcludeOnThisElement || !nodeLinkFn.templateOnThisElement) + && nodeLinkFn.transclude) : transcludeFn); + + if (nodeLinkFn || childLinkFn) { + linkFns.push(i, nodeLinkFn, childLinkFn); + linkFnFound = true; + nodeLinkFnFound = nodeLinkFnFound || nodeLinkFn; + } + + //use the previous context only for the first element in the virtual group + previousCompileContext = null; + } + + // return a linking function if we have found anything, null otherwise + return linkFnFound ? compositeLinkFn : null; + + function compositeLinkFn(scope, nodeList, $rootElement, parentBoundTranscludeFn) { + var nodeLinkFn, childLinkFn, node, childScope, i, ii, idx, childBoundTranscludeFn; + var stableNodeList; + + + if (nodeLinkFnFound) { + // copy nodeList so that if a nodeLinkFn removes or adds an element at this DOM level our + // offsets don't get screwed up + var nodeListLength = nodeList.length; + stableNodeList = new Array(nodeListLength); + + // create a sparse array by only copying the elements which have a linkFn + for (i = 0; i < linkFns.length; i+=3) { + idx = linkFns[i]; + stableNodeList[idx] = nodeList[idx]; + } + } else { + stableNodeList = nodeList; + } + + for (i = 0, ii = linkFns.length; i < ii;) { + node = stableNodeList[linkFns[i++]]; + nodeLinkFn = linkFns[i++]; + childLinkFn = linkFns[i++]; + + if (nodeLinkFn) { + if (nodeLinkFn.scope) { + childScope = scope.$new(); + compile.$$addScopeInfo(jqLite(node), childScope); + } else { + childScope = scope; + } + + if (nodeLinkFn.transcludeOnThisElement) { + childBoundTranscludeFn = createBoundTranscludeFn( + scope, nodeLinkFn.transclude, parentBoundTranscludeFn, + nodeLinkFn.elementTranscludeOnThisElement); + + } else if (!nodeLinkFn.templateOnThisElement && parentBoundTranscludeFn) { + childBoundTranscludeFn = parentBoundTranscludeFn; + + } else if (!parentBoundTranscludeFn && transcludeFn) { + childBoundTranscludeFn = createBoundTranscludeFn(scope, transcludeFn); + + } else { + childBoundTranscludeFn = null; + } + + nodeLinkFn(childLinkFn, childScope, node, $rootElement, childBoundTranscludeFn); + + } else if (childLinkFn) { + childLinkFn(scope, node.childNodes, undefined, parentBoundTranscludeFn); + } + } + } + } + + function createBoundTranscludeFn(scope, transcludeFn, previousBoundTranscludeFn, elementTransclusion) { + + var boundTranscludeFn = function(transcludedScope, cloneFn, controllers, futureParentElement, containingScope) { + + if (!transcludedScope) { + transcludedScope = scope.$new(false, containingScope); + transcludedScope.$$transcluded = true; + } + + return transcludeFn(transcludedScope, cloneFn, { + parentBoundTranscludeFn: previousBoundTranscludeFn, + transcludeControllers: controllers, + futureParentElement: futureParentElement + }); + }; + + return boundTranscludeFn; + } + + /** + * Looks for directives on the given node and adds them to the directive collection which is + * sorted. + * + * @param node Node to search. + * @param directives An array to which the directives are added to. This array is sorted before + * the function returns. + * @param attrs The shared attrs object which is used to populate the normalized attributes. + * @param {number=} maxPriority Max directive priority. + */ + function collectDirectives(node, directives, attrs, maxPriority, ignoreDirective) { + var nodeType = node.nodeType, + attrsMap = attrs.$attr, + match, + className; + + switch (nodeType) { + case NODE_TYPE_ELEMENT: /* Element */ + // use the node name: + addDirective(directives, + directiveNormalize(nodeName_(node)), 'E', maxPriority, ignoreDirective); + + // iterate over the attributes + for (var attr, name, nName, ngAttrName, value, isNgAttr, nAttrs = node.attributes, + j = 0, jj = nAttrs && nAttrs.length; j < jj; j++) { + var attrStartName = false; + var attrEndName = false; + + attr = nAttrs[j]; + name = attr.name; + value = trim(attr.value); + + // support ngAttr attribute binding + ngAttrName = directiveNormalize(name); + if (isNgAttr = NG_ATTR_BINDING.test(ngAttrName)) { + name = name.replace(PREFIX_REGEXP, '') + .substr(8).replace(/_(.)/g, function(match, letter) { + return letter.toUpperCase(); + }); + } + + var directiveNName = ngAttrName.replace(/(Start|End)$/, ''); + if (directiveIsMultiElement(directiveNName)) { + if (ngAttrName === directiveNName + 'Start') { + attrStartName = name; + attrEndName = name.substr(0, name.length - 5) + 'end'; + name = name.substr(0, name.length - 6); + } + } + + nName = directiveNormalize(name.toLowerCase()); + attrsMap[nName] = name; + if (isNgAttr || !attrs.hasOwnProperty(nName)) { + attrs[nName] = value; + if (getBooleanAttrName(node, nName)) { + attrs[nName] = true; // presence means true + } + } + addAttrInterpolateDirective(node, directives, value, nName, isNgAttr); + addDirective(directives, nName, 'A', maxPriority, ignoreDirective, attrStartName, + attrEndName); + } + + // use class as directive + className = node.className; + if (isObject(className)) { + // Maybe SVGAnimatedString + className = className.animVal; + } + if (isString(className) && className !== '') { + while (match = CLASS_DIRECTIVE_REGEXP.exec(className)) { + nName = directiveNormalize(match[2]); + if (addDirective(directives, nName, 'C', maxPriority, ignoreDirective)) { + attrs[nName] = trim(match[3]); + } + className = className.substr(match.index + match[0].length); + } + } + break; + case NODE_TYPE_TEXT: /* Text Node */ + addTextInterpolateDirective(directives, node.nodeValue); + break; + case NODE_TYPE_COMMENT: /* Comment */ + try { + match = COMMENT_DIRECTIVE_REGEXP.exec(node.nodeValue); + if (match) { + nName = directiveNormalize(match[1]); + if (addDirective(directives, nName, 'M', maxPriority, ignoreDirective)) { + attrs[nName] = trim(match[2]); + } + } + } catch (e) { + // turns out that under some circumstances IE9 throws errors when one attempts to read + // comment's node value. + // Just ignore it and continue. (Can't seem to reproduce in test case.) + } + break; + } + + directives.sort(byPriority); + return directives; + } + + /** + * Given a node with an directive-start it collects all of the siblings until it finds + * directive-end. + * @param node + * @param attrStart + * @param attrEnd + * @returns {*} + */ + function groupScan(node, attrStart, attrEnd) { + var nodes = []; + var depth = 0; + if (attrStart && node.hasAttribute && node.hasAttribute(attrStart)) { + do { + if (!node) { + throw $compileMinErr('uterdir', + "Unterminated attribute, found '{0}' but no matching '{1}' found.", + attrStart, attrEnd); + } + if (node.nodeType == NODE_TYPE_ELEMENT) { + if (node.hasAttribute(attrStart)) depth++; + if (node.hasAttribute(attrEnd)) depth--; + } + nodes.push(node); + node = node.nextSibling; + } while (depth > 0); + } else { + nodes.push(node); + } + + return jqLite(nodes); + } + + /** + * Wrapper for linking function which converts normal linking function into a grouped + * linking function. + * @param linkFn + * @param attrStart + * @param attrEnd + * @returns {Function} + */ + function groupElementsLinkFnWrapper(linkFn, attrStart, attrEnd) { + return function(scope, element, attrs, controllers, transcludeFn) { + element = groupScan(element[0], attrStart, attrEnd); + return linkFn(scope, element, attrs, controllers, transcludeFn); + }; + } + + /** + * Once the directives have been collected, their compile functions are executed. This method + * is responsible for inlining directive templates as well as terminating the application + * of the directives if the terminal directive has been reached. + * + * @param {Array} directives Array of collected directives to execute their compile function. + * this needs to be pre-sorted by priority order. + * @param {Node} compileNode The raw DOM node to apply the compile functions to + * @param {Object} templateAttrs The shared attribute function + * @param {function(angular.Scope, cloneAttachFn=)} transcludeFn A linking function, where the + * scope argument is auto-generated to the new + * child of the transcluded parent scope. + * @param {JQLite} jqCollection If we are working on the root of the compile tree then this + * argument has the root jqLite array so that we can replace nodes + * on it. + * @param {Object=} originalReplaceDirective An optional directive that will be ignored when + * compiling the transclusion. + * @param {Array.} preLinkFns + * @param {Array.} postLinkFns + * @param {Object} previousCompileContext Context used for previous compilation of the current + * node + * @returns {Function} linkFn + */ + function applyDirectivesToNode(directives, compileNode, templateAttrs, transcludeFn, + jqCollection, originalReplaceDirective, preLinkFns, postLinkFns, + previousCompileContext) { + previousCompileContext = previousCompileContext || {}; + + var terminalPriority = -Number.MAX_VALUE, + newScopeDirective, + controllerDirectives = previousCompileContext.controllerDirectives, + controllers, + newIsolateScopeDirective = previousCompileContext.newIsolateScopeDirective, + templateDirective = previousCompileContext.templateDirective, + nonTlbTranscludeDirective = previousCompileContext.nonTlbTranscludeDirective, + hasTranscludeDirective = false, + hasTemplate = false, + hasElementTranscludeDirective = previousCompileContext.hasElementTranscludeDirective, + $compileNode = templateAttrs.$$element = jqLite(compileNode), + directive, + directiveName, + $template, + replaceDirective = originalReplaceDirective, + childTranscludeFn = transcludeFn, + linkFn, + directiveValue; + + // executes all directives on the current element + for (var i = 0, ii = directives.length; i < ii; i++) { + directive = directives[i]; + var attrStart = directive.$$start; + var attrEnd = directive.$$end; + + // collect multiblock sections + if (attrStart) { + $compileNode = groupScan(compileNode, attrStart, attrEnd); + } + $template = undefined; + + if (terminalPriority > directive.priority) { + break; // prevent further processing of directives + } + + if (directiveValue = directive.scope) { + + // skip the check for directives with async templates, we'll check the derived sync + // directive when the template arrives + if (!directive.templateUrl) { + if (isObject(directiveValue)) { + // This directive is trying to add an isolated scope. + // Check that there is no scope of any kind already + assertNoDuplicate('new/isolated scope', newIsolateScopeDirective || newScopeDirective, + directive, $compileNode); + newIsolateScopeDirective = directive; + } else { + // This directive is trying to add a child scope. + // Check that there is no isolated scope already + assertNoDuplicate('new/isolated scope', newIsolateScopeDirective, directive, + $compileNode); + } + } + + newScopeDirective = newScopeDirective || directive; + } + + directiveName = directive.name; + + if (!directive.templateUrl && directive.controller) { + directiveValue = directive.controller; + controllerDirectives = controllerDirectives || {}; + assertNoDuplicate("'" + directiveName + "' controller", + controllerDirectives[directiveName], directive, $compileNode); + controllerDirectives[directiveName] = directive; + } + + if (directiveValue = directive.transclude) { + hasTranscludeDirective = true; + + // Special case ngIf and ngRepeat so that we don't complain about duplicate transclusion. + // This option should only be used by directives that know how to safely handle element transclusion, + // where the transcluded nodes are added or replaced after linking. + if (!directive.$$tlb) { + assertNoDuplicate('transclusion', nonTlbTranscludeDirective, directive, $compileNode); + nonTlbTranscludeDirective = directive; + } + + if (directiveValue == 'element') { + hasElementTranscludeDirective = true; + terminalPriority = directive.priority; + $template = $compileNode; + $compileNode = templateAttrs.$$element = + jqLite(document.createComment(' ' + directiveName + ': ' + + templateAttrs[directiveName] + ' ')); + compileNode = $compileNode[0]; + replaceWith(jqCollection, sliceArgs($template), compileNode); + + childTranscludeFn = compile($template, transcludeFn, terminalPriority, + replaceDirective && replaceDirective.name, { + // Don't pass in: + // - controllerDirectives - otherwise we'll create duplicates controllers + // - newIsolateScopeDirective or templateDirective - combining templates with + // element transclusion doesn't make sense. + // + // We need only nonTlbTranscludeDirective so that we prevent putting transclusion + // on the same element more than once. + nonTlbTranscludeDirective: nonTlbTranscludeDirective + }); + } else { + $template = jqLite(jqLiteClone(compileNode)).contents(); + $compileNode.empty(); // clear contents + childTranscludeFn = compile($template, transcludeFn); + } + } + + if (directive.template) { + hasTemplate = true; + assertNoDuplicate('template', templateDirective, directive, $compileNode); + templateDirective = directive; + + directiveValue = (isFunction(directive.template)) + ? directive.template($compileNode, templateAttrs) + : directive.template; + + directiveValue = denormalizeTemplate(directiveValue); + + if (directive.replace) { + replaceDirective = directive; + if (jqLiteIsTextNode(directiveValue)) { + $template = []; + } else { + $template = removeComments(wrapTemplate(directive.templateNamespace, trim(directiveValue))); + } + compileNode = $template[0]; + + if ($template.length != 1 || compileNode.nodeType !== NODE_TYPE_ELEMENT) { + throw $compileMinErr('tplrt', + "Template for directive '{0}' must have exactly one root element. {1}", + directiveName, ''); + } + + replaceWith(jqCollection, $compileNode, compileNode); + + var newTemplateAttrs = {$attr: {}}; + + // combine directives from the original node and from the template: + // - take the array of directives for this element + // - split it into two parts, those that already applied (processed) and those that weren't (unprocessed) + // - collect directives from the template and sort them by priority + // - combine directives as: processed + template + unprocessed + var templateDirectives = collectDirectives(compileNode, [], newTemplateAttrs); + var unprocessedDirectives = directives.splice(i + 1, directives.length - (i + 1)); + + if (newIsolateScopeDirective) { + markDirectivesAsIsolate(templateDirectives); + } + directives = directives.concat(templateDirectives).concat(unprocessedDirectives); + mergeTemplateAttributes(templateAttrs, newTemplateAttrs); + + ii = directives.length; + } else { + $compileNode.html(directiveValue); + } + } + + if (directive.templateUrl) { + hasTemplate = true; + assertNoDuplicate('template', templateDirective, directive, $compileNode); + templateDirective = directive; + + if (directive.replace) { + replaceDirective = directive; + } + + nodeLinkFn = compileTemplateUrl(directives.splice(i, directives.length - i), $compileNode, + templateAttrs, jqCollection, hasTranscludeDirective && childTranscludeFn, preLinkFns, postLinkFns, { + controllerDirectives: controllerDirectives, + newIsolateScopeDirective: newIsolateScopeDirective, + templateDirective: templateDirective, + nonTlbTranscludeDirective: nonTlbTranscludeDirective + }); + ii = directives.length; + } else if (directive.compile) { + try { + linkFn = directive.compile($compileNode, templateAttrs, childTranscludeFn); + if (isFunction(linkFn)) { + addLinkFns(null, linkFn, attrStart, attrEnd); + } else if (linkFn) { + addLinkFns(linkFn.pre, linkFn.post, attrStart, attrEnd); + } + } catch (e) { + $exceptionHandler(e, startingTag($compileNode)); + } + } + + if (directive.terminal) { + nodeLinkFn.terminal = true; + terminalPriority = Math.max(terminalPriority, directive.priority); + } + + } + + nodeLinkFn.scope = newScopeDirective && newScopeDirective.scope === true; + nodeLinkFn.transcludeOnThisElement = hasTranscludeDirective; + nodeLinkFn.elementTranscludeOnThisElement = hasElementTranscludeDirective; + nodeLinkFn.templateOnThisElement = hasTemplate; + nodeLinkFn.transclude = childTranscludeFn; + + previousCompileContext.hasElementTranscludeDirective = hasElementTranscludeDirective; + + // might be normal or delayed nodeLinkFn depending on if templateUrl is present + return nodeLinkFn; + + //////////////////// + + function addLinkFns(pre, post, attrStart, attrEnd) { + if (pre) { + if (attrStart) pre = groupElementsLinkFnWrapper(pre, attrStart, attrEnd); + pre.require = directive.require; + pre.directiveName = directiveName; + if (newIsolateScopeDirective === directive || directive.$$isolateScope) { + pre = cloneAndAnnotateFn(pre, {isolateScope: true}); + } + preLinkFns.push(pre); + } + if (post) { + if (attrStart) post = groupElementsLinkFnWrapper(post, attrStart, attrEnd); + post.require = directive.require; + post.directiveName = directiveName; + if (newIsolateScopeDirective === directive || directive.$$isolateScope) { + post = cloneAndAnnotateFn(post, {isolateScope: true}); + } + postLinkFns.push(post); + } + } + + + function getControllers(directiveName, require, $element, elementControllers) { + var value, retrievalMethod = 'data', optional = false; + var $searchElement = $element; + var match; + if (isString(require)) { + match = require.match(REQUIRE_PREFIX_REGEXP); + require = require.substring(match[0].length); + + if (match[3]) { + if (match[1]) match[3] = null; + else match[1] = match[3]; + } + if (match[1] === '^') { + retrievalMethod = 'inheritedData'; + } else if (match[1] === '^^') { + retrievalMethod = 'inheritedData'; + $searchElement = $element.parent(); + } + if (match[2] === '?') { + optional = true; + } + + value = null; + + if (elementControllers && retrievalMethod === 'data') { + if (value = elementControllers[require]) { + value = value.instance; + } + } + value = value || $searchElement[retrievalMethod]('$' + require + 'Controller'); + + if (!value && !optional) { + throw $compileMinErr('ctreq', + "Controller '{0}', required by directive '{1}', can't be found!", + require, directiveName); + } + return value || null; + } else if (isArray(require)) { + value = []; + forEach(require, function(require) { + value.push(getControllers(directiveName, require, $element, elementControllers)); + }); + } + return value; + } + + + function nodeLinkFn(childLinkFn, scope, linkNode, $rootElement, boundTranscludeFn) { + var i, ii, linkFn, controller, isolateScope, elementControllers, transcludeFn, $element, + attrs; + + if (compileNode === linkNode) { + attrs = templateAttrs; + $element = templateAttrs.$$element; + } else { + $element = jqLite(linkNode); + attrs = new Attributes($element, templateAttrs); + } + + if (newIsolateScopeDirective) { + isolateScope = scope.$new(true); + } + + if (boundTranscludeFn) { + // track `boundTranscludeFn` so it can be unwrapped if `transcludeFn` + // is later passed as `parentBoundTranscludeFn` to `publicLinkFn` + transcludeFn = controllersBoundTransclude; + transcludeFn.$$boundTransclude = boundTranscludeFn; + } + + if (controllerDirectives) { + // TODO: merge `controllers` and `elementControllers` into single object. + controllers = {}; + elementControllers = {}; + forEach(controllerDirectives, function(directive) { + var locals = { + $scope: directive === newIsolateScopeDirective || directive.$$isolateScope ? isolateScope : scope, + $element: $element, + $attrs: attrs, + $transclude: transcludeFn + }, controllerInstance; + + controller = directive.controller; + if (controller == '@') { + controller = attrs[directive.name]; + } + + controllerInstance = $controller(controller, locals, true, directive.controllerAs); + + // For directives with element transclusion the element is a comment, + // but jQuery .data doesn't support attaching data to comment nodes as it's hard to + // clean up (http://bugs.jquery.com/ticket/8335). + // Instead, we save the controllers for the element in a local hash and attach to .data + // later, once we have the actual element. + elementControllers[directive.name] = controllerInstance; + if (!hasElementTranscludeDirective) { + $element.data('$' + directive.name + 'Controller', controllerInstance.instance); + } + + controllers[directive.name] = controllerInstance; + }); + } + + if (newIsolateScopeDirective) { + compile.$$addScopeInfo($element, isolateScope, true, !(templateDirective && (templateDirective === newIsolateScopeDirective || + templateDirective === newIsolateScopeDirective.$$originalDirective))); + compile.$$addScopeClass($element, true); + + var isolateScopeController = controllers && controllers[newIsolateScopeDirective.name]; + var isolateBindingContext = isolateScope; + if (isolateScopeController && isolateScopeController.identifier && + newIsolateScopeDirective.bindToController === true) { + isolateBindingContext = isolateScopeController.instance; + } + + forEach(isolateScope.$$isolateBindings = newIsolateScopeDirective.$$isolateBindings, function(definition, scopeName) { + var attrName = definition.attrName, + optional = definition.optional, + mode = definition.mode, // @, =, or & + lastValue, + parentGet, parentSet, compare; + + switch (mode) { + + case '@': + attrs.$observe(attrName, function(value) { + isolateBindingContext[scopeName] = value; + }); + attrs.$$observers[attrName].$$scope = scope; + if (attrs[attrName]) { + // If the attribute has been provided then we trigger an interpolation to ensure + // the value is there for use in the link fn + isolateBindingContext[scopeName] = $interpolate(attrs[attrName])(scope); + } + break; + + case '=': + if (optional && !attrs[attrName]) { + return; + } + parentGet = $parse(attrs[attrName]); + if (parentGet.literal) { + compare = equals; + } else { + compare = function(a, b) { return a === b || (a !== a && b !== b); }; + } + parentSet = parentGet.assign || function() { + // reset the change, or we will throw this exception on every $digest + lastValue = isolateBindingContext[scopeName] = parentGet(scope); + throw $compileMinErr('nonassign', + "Expression '{0}' used with directive '{1}' is non-assignable!", + attrs[attrName], newIsolateScopeDirective.name); + }; + lastValue = isolateBindingContext[scopeName] = parentGet(scope); + var parentValueWatch = function parentValueWatch(parentValue) { + if (!compare(parentValue, isolateBindingContext[scopeName])) { + // we are out of sync and need to copy + if (!compare(parentValue, lastValue)) { + // parent changed and it has precedence + isolateBindingContext[scopeName] = parentValue; + } else { + // if the parent can be assigned then do so + parentSet(scope, parentValue = isolateBindingContext[scopeName]); + } + } + return lastValue = parentValue; + }; + parentValueWatch.$stateful = true; + var unwatch; + if (definition.collection) { + unwatch = scope.$watchCollection(attrs[attrName], parentValueWatch); + } else { + unwatch = scope.$watch($parse(attrs[attrName], parentValueWatch), null, parentGet.literal); + } + isolateScope.$on('$destroy', unwatch); + break; + + case '&': + parentGet = $parse(attrs[attrName]); + isolateBindingContext[scopeName] = function(locals) { + return parentGet(scope, locals); + }; + break; + } + }); + } + if (controllers) { + forEach(controllers, function(controller) { + controller(); + }); + controllers = null; + } + + // PRELINKING + for (i = 0, ii = preLinkFns.length; i < ii; i++) { + linkFn = preLinkFns[i]; + invokeLinkFn(linkFn, + linkFn.isolateScope ? isolateScope : scope, + $element, + attrs, + linkFn.require && getControllers(linkFn.directiveName, linkFn.require, $element, elementControllers), + transcludeFn + ); + } + + // RECURSION + // We only pass the isolate scope, if the isolate directive has a template, + // otherwise the child elements do not belong to the isolate directive. + var scopeToChild = scope; + if (newIsolateScopeDirective && (newIsolateScopeDirective.template || newIsolateScopeDirective.templateUrl === null)) { + scopeToChild = isolateScope; + } + childLinkFn && childLinkFn(scopeToChild, linkNode.childNodes, undefined, boundTranscludeFn); + + // POSTLINKING + for (i = postLinkFns.length - 1; i >= 0; i--) { + linkFn = postLinkFns[i]; + invokeLinkFn(linkFn, + linkFn.isolateScope ? isolateScope : scope, + $element, + attrs, + linkFn.require && getControllers(linkFn.directiveName, linkFn.require, $element, elementControllers), + transcludeFn + ); + } + + // This is the function that is injected as `$transclude`. + // Note: all arguments are optional! + function controllersBoundTransclude(scope, cloneAttachFn, futureParentElement) { + var transcludeControllers; + + // No scope passed in: + if (!isScope(scope)) { + futureParentElement = cloneAttachFn; + cloneAttachFn = scope; + scope = undefined; + } + + if (hasElementTranscludeDirective) { + transcludeControllers = elementControllers; + } + if (!futureParentElement) { + futureParentElement = hasElementTranscludeDirective ? $element.parent() : $element; + } + return boundTranscludeFn(scope, cloneAttachFn, transcludeControllers, futureParentElement, scopeToChild); + } + } + } + + function markDirectivesAsIsolate(directives) { + // mark all directives as needing isolate scope. + for (var j = 0, jj = directives.length; j < jj; j++) { + directives[j] = inherit(directives[j], {$$isolateScope: true}); + } + } + + /** + * looks up the directive and decorates it with exception handling and proper parameters. We + * call this the boundDirective. + * + * @param {string} name name of the directive to look up. + * @param {string} location The directive must be found in specific format. + * String containing any of theses characters: + * + * * `E`: element name + * * `A': attribute + * * `C`: class + * * `M`: comment + * @returns {boolean} true if directive was added. + */ + function addDirective(tDirectives, name, location, maxPriority, ignoreDirective, startAttrName, + endAttrName) { + if (name === ignoreDirective) return null; + var match = null; + if (hasDirectives.hasOwnProperty(name)) { + for (var directive, directives = $injector.get(name + Suffix), + i = 0, ii = directives.length; i < ii; i++) { + try { + directive = directives[i]; + if ((maxPriority === undefined || maxPriority > directive.priority) && + directive.restrict.indexOf(location) != -1) { + if (startAttrName) { + directive = inherit(directive, {$$start: startAttrName, $$end: endAttrName}); + } + tDirectives.push(directive); + match = directive; + } + } catch (e) { $exceptionHandler(e); } + } + } + return match; + } + + + /** + * looks up the directive and returns true if it is a multi-element directive, + * and therefore requires DOM nodes between -start and -end markers to be grouped + * together. + * + * @param {string} name name of the directive to look up. + * @returns true if directive was registered as multi-element. + */ + function directiveIsMultiElement(name) { + if (hasDirectives.hasOwnProperty(name)) { + for (var directive, directives = $injector.get(name + Suffix), + i = 0, ii = directives.length; i < ii; i++) { + directive = directives[i]; + if (directive.multiElement) { + return true; + } + } + } + return false; + } + + /** + * When the element is replaced with HTML template then the new attributes + * on the template need to be merged with the existing attributes in the DOM. + * The desired effect is to have both of the attributes present. + * + * @param {object} dst destination attributes (original DOM) + * @param {object} src source attributes (from the directive template) + */ + function mergeTemplateAttributes(dst, src) { + var srcAttr = src.$attr, + dstAttr = dst.$attr, + $element = dst.$$element; + + // reapply the old attributes to the new element + forEach(dst, function(value, key) { + if (key.charAt(0) != '$') { + if (src[key] && src[key] !== value) { + value += (key === 'style' ? ';' : ' ') + src[key]; + } + dst.$set(key, value, true, srcAttr[key]); + } + }); + + // copy the new attributes on the old attrs object + forEach(src, function(value, key) { + if (key == 'class') { + safeAddClass($element, value); + dst['class'] = (dst['class'] ? dst['class'] + ' ' : '') + value; + } else if (key == 'style') { + $element.attr('style', $element.attr('style') + ';' + value); + dst['style'] = (dst['style'] ? dst['style'] + ';' : '') + value; + // `dst` will never contain hasOwnProperty as DOM parser won't let it. + // You will get an "InvalidCharacterError: DOM Exception 5" error if you + // have an attribute like "has-own-property" or "data-has-own-property", etc. + } else if (key.charAt(0) != '$' && !dst.hasOwnProperty(key)) { + dst[key] = value; + dstAttr[key] = srcAttr[key]; + } + }); + } + + + function compileTemplateUrl(directives, $compileNode, tAttrs, + $rootElement, childTranscludeFn, preLinkFns, postLinkFns, previousCompileContext) { + var linkQueue = [], + afterTemplateNodeLinkFn, + afterTemplateChildLinkFn, + beforeTemplateCompileNode = $compileNode[0], + origAsyncDirective = directives.shift(), + derivedSyncDirective = inherit(origAsyncDirective, { + templateUrl: null, transclude: null, replace: null, $$originalDirective: origAsyncDirective + }), + templateUrl = (isFunction(origAsyncDirective.templateUrl)) + ? origAsyncDirective.templateUrl($compileNode, tAttrs) + : origAsyncDirective.templateUrl, + templateNamespace = origAsyncDirective.templateNamespace; + + $compileNode.empty(); + + $templateRequest(templateUrl) + .then(function(content) { + var compileNode, tempTemplateAttrs, $template, childBoundTranscludeFn; + + content = denormalizeTemplate(content); + + if (origAsyncDirective.replace) { + if (jqLiteIsTextNode(content)) { + $template = []; + } else { + $template = removeComments(wrapTemplate(templateNamespace, trim(content))); + } + compileNode = $template[0]; + + if ($template.length != 1 || compileNode.nodeType !== NODE_TYPE_ELEMENT) { + throw $compileMinErr('tplrt', + "Template for directive '{0}' must have exactly one root element. {1}", + origAsyncDirective.name, templateUrl); + } + + tempTemplateAttrs = {$attr: {}}; + replaceWith($rootElement, $compileNode, compileNode); + var templateDirectives = collectDirectives(compileNode, [], tempTemplateAttrs); + + if (isObject(origAsyncDirective.scope)) { + markDirectivesAsIsolate(templateDirectives); + } + directives = templateDirectives.concat(directives); + mergeTemplateAttributes(tAttrs, tempTemplateAttrs); + } else { + compileNode = beforeTemplateCompileNode; + $compileNode.html(content); + } + + directives.unshift(derivedSyncDirective); + + afterTemplateNodeLinkFn = applyDirectivesToNode(directives, compileNode, tAttrs, + childTranscludeFn, $compileNode, origAsyncDirective, preLinkFns, postLinkFns, + previousCompileContext); + forEach($rootElement, function(node, i) { + if (node == compileNode) { + $rootElement[i] = $compileNode[0]; + } + }); + afterTemplateChildLinkFn = compileNodes($compileNode[0].childNodes, childTranscludeFn); + + while (linkQueue.length) { + var scope = linkQueue.shift(), + beforeTemplateLinkNode = linkQueue.shift(), + linkRootElement = linkQueue.shift(), + boundTranscludeFn = linkQueue.shift(), + linkNode = $compileNode[0]; + + if (scope.$$destroyed) continue; + + if (beforeTemplateLinkNode !== beforeTemplateCompileNode) { + var oldClasses = beforeTemplateLinkNode.className; + + if (!(previousCompileContext.hasElementTranscludeDirective && + origAsyncDirective.replace)) { + // it was cloned therefore we have to clone as well. + linkNode = jqLiteClone(compileNode); + } + replaceWith(linkRootElement, jqLite(beforeTemplateLinkNode), linkNode); + + // Copy in CSS classes from original node + safeAddClass(jqLite(linkNode), oldClasses); + } + if (afterTemplateNodeLinkFn.transcludeOnThisElement) { + childBoundTranscludeFn = createBoundTranscludeFn(scope, afterTemplateNodeLinkFn.transclude, boundTranscludeFn); + } else { + childBoundTranscludeFn = boundTranscludeFn; + } + afterTemplateNodeLinkFn(afterTemplateChildLinkFn, scope, linkNode, $rootElement, + childBoundTranscludeFn); + } + linkQueue = null; + }); + + return function delayedNodeLinkFn(ignoreChildLinkFn, scope, node, rootElement, boundTranscludeFn) { + var childBoundTranscludeFn = boundTranscludeFn; + if (scope.$$destroyed) return; + if (linkQueue) { + linkQueue.push(scope, + node, + rootElement, + childBoundTranscludeFn); + } else { + if (afterTemplateNodeLinkFn.transcludeOnThisElement) { + childBoundTranscludeFn = createBoundTranscludeFn(scope, afterTemplateNodeLinkFn.transclude, boundTranscludeFn); + } + afterTemplateNodeLinkFn(afterTemplateChildLinkFn, scope, node, rootElement, childBoundTranscludeFn); + } + }; + } + + + /** + * Sorting function for bound directives. + */ + function byPriority(a, b) { + var diff = b.priority - a.priority; + if (diff !== 0) return diff; + if (a.name !== b.name) return (a.name < b.name) ? -1 : 1; + return a.index - b.index; + } + + + function assertNoDuplicate(what, previousDirective, directive, element) { + if (previousDirective) { + throw $compileMinErr('multidir', 'Multiple directives [{0}, {1}] asking for {2} on: {3}', + previousDirective.name, directive.name, what, startingTag(element)); + } + } + + + function addTextInterpolateDirective(directives, text) { + var interpolateFn = $interpolate(text, true); + if (interpolateFn) { + directives.push({ + priority: 0, + compile: function textInterpolateCompileFn(templateNode) { + var templateNodeParent = templateNode.parent(), + hasCompileParent = !!templateNodeParent.length; + + // When transcluding a template that has bindings in the root + // we don't have a parent and thus need to add the class during linking fn. + if (hasCompileParent) compile.$$addBindingClass(templateNodeParent); + + return function textInterpolateLinkFn(scope, node) { + var parent = node.parent(); + if (!hasCompileParent) compile.$$addBindingClass(parent); + compile.$$addBindingInfo(parent, interpolateFn.expressions); + scope.$watch(interpolateFn, function interpolateFnWatchAction(value) { + node[0].nodeValue = value; + }); + }; + } + }); + } + } + + + function wrapTemplate(type, template) { + type = lowercase(type || 'html'); + switch (type) { + case 'svg': + case 'math': + var wrapper = document.createElement('div'); + wrapper.innerHTML = '<' + type + '>' + template + ''; + return wrapper.childNodes[0].childNodes; + default: + return template; + } + } + + + function getTrustedContext(node, attrNormalizedName) { + if (attrNormalizedName == "srcdoc") { + return $sce.HTML; + } + var tag = nodeName_(node); + // maction[xlink:href] can source SVG. It's not limited to . + if (attrNormalizedName == "xlinkHref" || + (tag == "form" && attrNormalizedName == "action") || + (tag != "img" && (attrNormalizedName == "src" || + attrNormalizedName == "ngSrc"))) { + return $sce.RESOURCE_URL; + } + } + + + function addAttrInterpolateDirective(node, directives, value, name, allOrNothing) { + var trustedContext = getTrustedContext(node, name); + allOrNothing = ALL_OR_NOTHING_ATTRS[name] || allOrNothing; + + var interpolateFn = $interpolate(value, true, trustedContext, allOrNothing); + + // no interpolation found -> ignore + if (!interpolateFn) return; + + + if (name === "multiple" && nodeName_(node) === "select") { + throw $compileMinErr("selmulti", + "Binding to the 'multiple' attribute is not supported. Element: {0}", + startingTag(node)); + } + + directives.push({ + priority: 100, + compile: function() { + return { + pre: function attrInterpolatePreLinkFn(scope, element, attr) { + var $$observers = (attr.$$observers || (attr.$$observers = {})); + + if (EVENT_HANDLER_ATTR_REGEXP.test(name)) { + throw $compileMinErr('nodomevents', + "Interpolations for HTML DOM event attributes are disallowed. Please use the " + + "ng- versions (such as ng-click instead of onclick) instead."); + } + + // If the attribute has changed since last $interpolate()ed + var newValue = attr[name]; + if (newValue !== value) { + // we need to interpolate again since the attribute value has been updated + // (e.g. by another directive's compile function) + // ensure unset/empty values make interpolateFn falsy + interpolateFn = newValue && $interpolate(newValue, true, trustedContext, allOrNothing); + value = newValue; + } + + // if attribute was updated so that there is no interpolation going on we don't want to + // register any observers + if (!interpolateFn) return; + + // initialize attr object so that it's ready in case we need the value for isolate + // scope initialization, otherwise the value would not be available from isolate + // directive's linking fn during linking phase + attr[name] = interpolateFn(scope); + + ($$observers[name] || ($$observers[name] = [])).$$inter = true; + (attr.$$observers && attr.$$observers[name].$$scope || scope). + $watch(interpolateFn, function interpolateFnWatchAction(newValue, oldValue) { + //special case for class attribute addition + removal + //so that class changes can tap into the animation + //hooks provided by the $animate service. Be sure to + //skip animations when the first digest occurs (when + //both the new and the old values are the same) since + //the CSS classes are the non-interpolated values + if (name === 'class' && newValue != oldValue) { + attr.$updateClass(newValue, oldValue); + } else { + attr.$set(name, newValue); + } + }); + } + }; + } + }); + } + + + /** + * This is a special jqLite.replaceWith, which can replace items which + * have no parents, provided that the containing jqLite collection is provided. + * + * @param {JqLite=} $rootElement The root of the compile tree. Used so that we can replace nodes + * in the root of the tree. + * @param {JqLite} elementsToRemove The jqLite element which we are going to replace. We keep + * the shell, but replace its DOM node reference. + * @param {Node} newNode The new DOM node. + */ + function replaceWith($rootElement, elementsToRemove, newNode) { + var firstElementToRemove = elementsToRemove[0], + removeCount = elementsToRemove.length, + parent = firstElementToRemove.parentNode, + i, ii; + + if ($rootElement) { + for (i = 0, ii = $rootElement.length; i < ii; i++) { + if ($rootElement[i] == firstElementToRemove) { + $rootElement[i++] = newNode; + for (var j = i, j2 = j + removeCount - 1, + jj = $rootElement.length; + j < jj; j++, j2++) { + if (j2 < jj) { + $rootElement[j] = $rootElement[j2]; + } else { + delete $rootElement[j]; + } + } + $rootElement.length -= removeCount - 1; + + // If the replaced element is also the jQuery .context then replace it + // .context is a deprecated jQuery api, so we should set it only when jQuery set it + // http://api.jquery.com/context/ + if ($rootElement.context === firstElementToRemove) { + $rootElement.context = newNode; + } + break; + } + } + } + + if (parent) { + parent.replaceChild(newNode, firstElementToRemove); + } + + // TODO(perf): what's this document fragment for? is it needed? can we at least reuse it? + var fragment = document.createDocumentFragment(); + fragment.appendChild(firstElementToRemove); + + // Copy over user data (that includes Angular's $scope etc.). Don't copy private + // data here because there's no public interface in jQuery to do that and copying over + // event listeners (which is the main use of private data) wouldn't work anyway. + jqLite(newNode).data(jqLite(firstElementToRemove).data()); + + // Remove data of the replaced element. We cannot just call .remove() + // on the element it since that would deallocate scope that is needed + // for the new node. Instead, remove the data "manually". + if (!jQuery) { + delete jqLite.cache[firstElementToRemove[jqLite.expando]]; + } else { + // jQuery 2.x doesn't expose the data storage. Use jQuery.cleanData to clean up after + // the replaced element. The cleanData version monkey-patched by Angular would cause + // the scope to be trashed and we do need the very same scope to work with the new + // element. However, we cannot just cache the non-patched version and use it here as + // that would break if another library patches the method after Angular does (one + // example is jQuery UI). Instead, set a flag indicating scope destroying should be + // skipped this one time. + skipDestroyOnNextJQueryCleanData = true; + jQuery.cleanData([firstElementToRemove]); + } + + for (var k = 1, kk = elementsToRemove.length; k < kk; k++) { + var element = elementsToRemove[k]; + jqLite(element).remove(); // must do this way to clean up expando + fragment.appendChild(element); + delete elementsToRemove[k]; + } + + elementsToRemove[0] = newNode; + elementsToRemove.length = 1; + } + + + function cloneAndAnnotateFn(fn, annotation) { + return extend(function() { return fn.apply(null, arguments); }, fn, annotation); + } + + + function invokeLinkFn(linkFn, scope, $element, attrs, controllers, transcludeFn) { + try { + linkFn(scope, $element, attrs, controllers, transcludeFn); + } catch (e) { + $exceptionHandler(e, startingTag($element)); + } + } + }]; +} + +var PREFIX_REGEXP = /^((?:x|data)[\:\-_])/i; +/** + * Converts all accepted directives format into proper directive name. + * @param name Name to normalize + */ +function directiveNormalize(name) { + return camelCase(name.replace(PREFIX_REGEXP, '')); +} + +/** + * @ngdoc type + * @name $compile.directive.Attributes + * + * @description + * A shared object between directive compile / linking functions which contains normalized DOM + * element attributes. The values reflect current binding state `{{ }}`. The normalization is + * needed since all of these are treated as equivalent in Angular: + * + * ``` + * + * ``` + */ + +/** + * @ngdoc property + * @name $compile.directive.Attributes#$attr + * + * @description + * A map of DOM element attribute names to the normalized name. This is + * needed to do reverse lookup from normalized name back to actual name. + */ + + +/** + * @ngdoc method + * @name $compile.directive.Attributes#$set + * @kind function + * + * @description + * Set DOM element attribute value. + * + * + * @param {string} name Normalized element attribute name of the property to modify. The name is + * reverse-translated using the {@link ng.$compile.directive.Attributes#$attr $attr} + * property to the original name. + * @param {string} value Value to set the attribute to. The value can be an interpolated string. + */ + + + +/** + * Closure compiler type information + */ + +function nodesetLinkingFn( + /* angular.Scope */ scope, + /* NodeList */ nodeList, + /* Element */ rootElement, + /* function(Function) */ boundTranscludeFn +) {} + +function directiveLinkingFn( + /* nodesetLinkingFn */ nodesetLinkingFn, + /* angular.Scope */ scope, + /* Node */ node, + /* Element */ rootElement, + /* function(Function) */ boundTranscludeFn +) {} + +function tokenDifference(str1, str2) { + var values = '', + tokens1 = str1.split(/\s+/), + tokens2 = str2.split(/\s+/); + + outer: + for (var i = 0; i < tokens1.length; i++) { + var token = tokens1[i]; + for (var j = 0; j < tokens2.length; j++) { + if (token == tokens2[j]) continue outer; + } + values += (values.length > 0 ? ' ' : '') + token; + } + return values; +} + +function removeComments(jqNodes) { + jqNodes = jqLite(jqNodes); + var i = jqNodes.length; + + if (i <= 1) { + return jqNodes; + } + + while (i--) { + var node = jqNodes[i]; + if (node.nodeType === NODE_TYPE_COMMENT) { + splice.call(jqNodes, i, 1); + } + } + return jqNodes; +} + +var $controllerMinErr = minErr('$controller'); + +/** + * @ngdoc provider + * @name $controllerProvider + * @description + * The {@link ng.$controller $controller service} is used by Angular to create new + * controllers. + * + * This provider allows controller registration via the + * {@link ng.$controllerProvider#register register} method. + */ +function $ControllerProvider() { + var controllers = {}, + globals = false, + CNTRL_REG = /^(\S+)(\s+as\s+(\w+))?$/; + + + /** + * @ngdoc method + * @name $controllerProvider#register + * @param {string|Object} name Controller name, or an object map of controllers where the keys are + * the names and the values are the constructors. + * @param {Function|Array} constructor Controller constructor fn (optionally decorated with DI + * annotations in the array notation). + */ + this.register = function(name, constructor) { + assertNotHasOwnProperty(name, 'controller'); + if (isObject(name)) { + extend(controllers, name); + } else { + controllers[name] = constructor; + } + }; + + /** + * @ngdoc method + * @name $controllerProvider#allowGlobals + * @description If called, allows `$controller` to find controller constructors on `window` + */ + this.allowGlobals = function() { + globals = true; + }; + + + this.$get = ['$injector', '$window', function($injector, $window) { + + /** + * @ngdoc service + * @name $controller + * @requires $injector + * + * @param {Function|string} constructor If called with a function then it's considered to be the + * controller constructor function. Otherwise it's considered to be a string which is used + * to retrieve the controller constructor using the following steps: + * + * * check if a controller with given name is registered via `$controllerProvider` + * * check if evaluating the string on the current scope returns a constructor + * * if $controllerProvider#allowGlobals, check `window[constructor]` on the global + * `window` object (not recommended) + * + * The string can use the `controller as property` syntax, where the controller instance is published + * as the specified property on the `scope`; the `scope` must be injected into `locals` param for this + * to work correctly. + * + * @param {Object} locals Injection locals for Controller. + * @return {Object} Instance of given controller. + * + * @description + * `$controller` service is responsible for instantiating controllers. + * + * It's just a simple call to {@link auto.$injector $injector}, but extracted into + * a service, so that one can override this service with [BC version](https://gist.github.com/1649788). + */ + return function(expression, locals, later, ident) { + // PRIVATE API: + // param `later` --- indicates that the controller's constructor is invoked at a later time. + // If true, $controller will allocate the object with the correct + // prototype chain, but will not invoke the controller until a returned + // callback is invoked. + // param `ident` --- An optional label which overrides the label parsed from the controller + // expression, if any. + var instance, match, constructor, identifier; + later = later === true; + if (ident && isString(ident)) { + identifier = ident; + } + + if (isString(expression)) { + match = expression.match(CNTRL_REG); + if (!match) { + throw $controllerMinErr('ctrlfmt', + "Badly formed controller string '{0}'. " + + "Must match `__name__ as __id__` or `__name__`.", expression); + } + constructor = match[1], + identifier = identifier || match[3]; + expression = controllers.hasOwnProperty(constructor) + ? controllers[constructor] + : getter(locals.$scope, constructor, true) || + (globals ? getter($window, constructor, true) : undefined); + + assertArgFn(expression, constructor, true); + } + + if (later) { + // Instantiate controller later: + // This machinery is used to create an instance of the object before calling the + // controller's constructor itself. + // + // This allows properties to be added to the controller before the constructor is + // invoked. Primarily, this is used for isolate scope bindings in $compile. + // + // This feature is not intended for use by applications, and is thus not documented + // publicly. + // Object creation: http://jsperf.com/create-constructor/2 + var controllerPrototype = (isArray(expression) ? + expression[expression.length - 1] : expression).prototype; + instance = Object.create(controllerPrototype || null); + + if (identifier) { + addIdentifier(locals, identifier, instance, constructor || expression.name); + } + + return extend(function() { + $injector.invoke(expression, instance, locals, constructor); + return instance; + }, { + instance: instance, + identifier: identifier + }); + } + + instance = $injector.instantiate(expression, locals, constructor); + + if (identifier) { + addIdentifier(locals, identifier, instance, constructor || expression.name); + } + + return instance; + }; + + function addIdentifier(locals, identifier, instance, name) { + if (!(locals && isObject(locals.$scope))) { + throw minErr('$controller')('noscp', + "Cannot export controller '{0}' as '{1}'! No $scope object provided via `locals`.", + name, identifier); + } + + locals.$scope[identifier] = instance; + } + }]; +} + +/** + * @ngdoc service + * @name $document + * @requires $window + * + * @description + * A {@link angular.element jQuery or jqLite} wrapper for the browser's `window.document` object. + * + * @example + + +
      +

      $document title:

      +

      window.document title:

      +
      +
      + + angular.module('documentExample', []) + .controller('ExampleController', ['$scope', '$document', function($scope, $document) { + $scope.title = $document[0].title; + $scope.windowTitle = angular.element(window.document)[0].title; + }]); + +
      + */ +function $DocumentProvider() { + this.$get = ['$window', function(window) { + return jqLite(window.document); + }]; +} + +/** + * @ngdoc service + * @name $exceptionHandler + * @requires ng.$log + * + * @description + * Any uncaught exception in angular expressions is delegated to this service. + * The default implementation simply delegates to `$log.error` which logs it into + * the browser console. + * + * In unit tests, if `angular-mocks.js` is loaded, this service is overridden by + * {@link ngMock.$exceptionHandler mock $exceptionHandler} which aids in testing. + * + * ## Example: + * + * ```js + * angular.module('exceptionOverride', []).factory('$exceptionHandler', function() { + * return function(exception, cause) { + * exception.message += ' (caused by "' + cause + '")'; + * throw exception; + * }; + * }); + * ``` + * + * This example will override the normal action of `$exceptionHandler`, to make angular + * exceptions fail hard when they happen, instead of just logging to the console. + * + *
      + * Note, that code executed in event-listeners (even those registered using jqLite's `on`/`bind` + * methods) does not delegate exceptions to the {@link ng.$exceptionHandler $exceptionHandler} + * (unless executed during a digest). + * + * If you wish, you can manually delegate exceptions, e.g. + * `try { ... } catch(e) { $exceptionHandler(e); }` + * + * @param {Error} exception Exception associated with the error. + * @param {string=} cause optional information about the context in which + * the error was thrown. + * + */ +function $ExceptionHandlerProvider() { + this.$get = ['$log', function($log) { + return function(exception, cause) { + $log.error.apply($log, arguments); + }; + }]; +} + +var APPLICATION_JSON = 'application/json'; +var CONTENT_TYPE_APPLICATION_JSON = {'Content-Type': APPLICATION_JSON + ';charset=utf-8'}; +var JSON_START = /^\[|^\{(?!\{)/; +var JSON_ENDS = { + '[': /]$/, + '{': /}$/ +}; +var JSON_PROTECTION_PREFIX = /^\)\]\}',?\n/; + +function defaultHttpResponseTransform(data, headers) { + if (isString(data)) { + // Strip json vulnerability protection prefix and trim whitespace + var tempData = data.replace(JSON_PROTECTION_PREFIX, '').trim(); + + if (tempData) { + var contentType = headers('Content-Type'); + if ((contentType && (contentType.indexOf(APPLICATION_JSON) === 0)) || isJsonLike(tempData)) { + data = fromJson(tempData); + } + } + } + + return data; +} + +function isJsonLike(str) { + var jsonStart = str.match(JSON_START); + return jsonStart && JSON_ENDS[jsonStart[0]].test(str); +} + +/** + * Parse headers into key value object + * + * @param {string} headers Raw headers as a string + * @returns {Object} Parsed headers as key value object + */ +function parseHeaders(headers) { + var parsed = createMap(), key, val, i; + + if (!headers) return parsed; + + forEach(headers.split('\n'), function(line) { + i = line.indexOf(':'); + key = lowercase(trim(line.substr(0, i))); + val = trim(line.substr(i + 1)); + + if (key) { + parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val; + } + }); + + return parsed; +} + + +/** + * Returns a function that provides access to parsed headers. + * + * Headers are lazy parsed when first requested. + * @see parseHeaders + * + * @param {(string|Object)} headers Headers to provide access to. + * @returns {function(string=)} Returns a getter function which if called with: + * + * - if called with single an argument returns a single header value or null + * - if called with no arguments returns an object containing all headers. + */ +function headersGetter(headers) { + var headersObj = isObject(headers) ? headers : undefined; + + return function(name) { + if (!headersObj) headersObj = parseHeaders(headers); + + if (name) { + var value = headersObj[lowercase(name)]; + if (value === void 0) { + value = null; + } + return value; + } + + return headersObj; + }; +} + + +/** + * Chain all given functions + * + * This function is used for both request and response transforming + * + * @param {*} data Data to transform. + * @param {function(string=)} headers HTTP headers getter fn. + * @param {number} status HTTP status code of the response. + * @param {(Function|Array.)} fns Function or an array of functions. + * @returns {*} Transformed data. + */ +function transformData(data, headers, status, fns) { + if (isFunction(fns)) + return fns(data, headers, status); + + forEach(fns, function(fn) { + data = fn(data, headers, status); + }); + + return data; +} + + +function isSuccess(status) { + return 200 <= status && status < 300; +} + + +/** + * @ngdoc provider + * @name $httpProvider + * @description + * Use `$httpProvider` to change the default behavior of the {@link ng.$http $http} service. + * */ +function $HttpProvider() { + /** + * @ngdoc property + * @name $httpProvider#defaults + * @description + * + * Object containing default values for all {@link ng.$http $http} requests. + * + * - **`defaults.cache`** - {Object} - an object built with {@link ng.$cacheFactory `$cacheFactory`} + * that will provide the cache for all requests who set their `cache` property to `true`. + * If you set the `default.cache = false` then only requests that specify their own custom + * cache object will be cached. See {@link $http#caching $http Caching} for more information. + * + * - **`defaults.xsrfCookieName`** - {string} - Name of cookie containing the XSRF token. + * Defaults value is `'XSRF-TOKEN'`. + * + * - **`defaults.xsrfHeaderName`** - {string} - Name of HTTP header to populate with the + * XSRF token. Defaults value is `'X-XSRF-TOKEN'`. + * + * - **`defaults.headers`** - {Object} - Default headers for all $http requests. + * Refer to {@link ng.$http#setting-http-headers $http} for documentation on + * setting default headers. + * - **`defaults.headers.common`** + * - **`defaults.headers.post`** + * - **`defaults.headers.put`** + * - **`defaults.headers.patch`** + * + **/ + var defaults = this.defaults = { + // transform incoming response data + transformResponse: [defaultHttpResponseTransform], + + // transform outgoing request data + transformRequest: [function(d) { + return isObject(d) && !isFile(d) && !isBlob(d) && !isFormData(d) ? toJson(d) : d; + }], + + // default headers + headers: { + common: { + 'Accept': 'application/json, text/plain, */*' + }, + post: shallowCopy(CONTENT_TYPE_APPLICATION_JSON), + put: shallowCopy(CONTENT_TYPE_APPLICATION_JSON), + patch: shallowCopy(CONTENT_TYPE_APPLICATION_JSON) + }, + + xsrfCookieName: 'XSRF-TOKEN', + xsrfHeaderName: 'X-XSRF-TOKEN' + }; + + var useApplyAsync = false; + /** + * @ngdoc method + * @name $httpProvider#useApplyAsync + * @description + * + * Configure $http service to combine processing of multiple http responses received at around + * the same time via {@link ng.$rootScope.Scope#$applyAsync $rootScope.$applyAsync}. This can result in + * significant performance improvement for bigger applications that make many HTTP requests + * concurrently (common during application bootstrap). + * + * Defaults to false. If no value is specifed, returns the current configured value. + * + * @param {boolean=} value If true, when requests are loaded, they will schedule a deferred + * "apply" on the next tick, giving time for subsequent requests in a roughly ~10ms window + * to load and share the same digest cycle. + * + * @returns {boolean|Object} If a value is specified, returns the $httpProvider for chaining. + * otherwise, returns the current configured value. + **/ + this.useApplyAsync = function(value) { + if (isDefined(value)) { + useApplyAsync = !!value; + return this; + } + return useApplyAsync; + }; + + /** + * @ngdoc property + * @name $httpProvider#interceptors + * @description + * + * Array containing service factories for all synchronous or asynchronous {@link ng.$http $http} + * pre-processing of request or postprocessing of responses. + * + * These service factories are ordered by request, i.e. they are applied in the same order as the + * array, on request, but reverse order, on response. + * + * {@link ng.$http#interceptors Interceptors detailed info} + **/ + var interceptorFactories = this.interceptors = []; + + this.$get = ['$httpBackend', '$browser', '$cacheFactory', '$rootScope', '$q', '$injector', + function($httpBackend, $browser, $cacheFactory, $rootScope, $q, $injector) { + + var defaultCache = $cacheFactory('$http'); + + /** + * Interceptors stored in reverse order. Inner interceptors before outer interceptors. + * The reversal is needed so that we can build up the interception chain around the + * server request. + */ + var reversedInterceptors = []; + + forEach(interceptorFactories, function(interceptorFactory) { + reversedInterceptors.unshift(isString(interceptorFactory) + ? $injector.get(interceptorFactory) : $injector.invoke(interceptorFactory)); + }); + + /** + * @ngdoc service + * @kind function + * @name $http + * @requires ng.$httpBackend + * @requires $cacheFactory + * @requires $rootScope + * @requires $q + * @requires $injector + * + * @description + * The `$http` service is a core Angular service that facilitates communication with the remote + * HTTP servers via the browser's [XMLHttpRequest](https://developer.mozilla.org/en/xmlhttprequest) + * object or via [JSONP](http://en.wikipedia.org/wiki/JSONP). + * + * For unit testing applications that use `$http` service, see + * {@link ngMock.$httpBackend $httpBackend mock}. + * + * For a higher level of abstraction, please check out the {@link ngResource.$resource + * $resource} service. + * + * The $http API is based on the {@link ng.$q deferred/promise APIs} exposed by + * the $q service. While for simple usage patterns this doesn't matter much, for advanced usage + * it is important to familiarize yourself with these APIs and the guarantees they provide. + * + * + * ## General usage + * The `$http` service is a function which takes a single argument — a configuration object — + * that is used to generate an HTTP request and returns a {@link ng.$q promise} + * with two $http specific methods: `success` and `error`. + * + * ```js + * // Simple GET request example : + * $http.get('/someUrl'). + * success(function(data, status, headers, config) { + * // this callback will be called asynchronously + * // when the response is available + * }). + * error(function(data, status, headers, config) { + * // called asynchronously if an error occurs + * // or server returns response with an error status. + * }); + * ``` + * + * ```js + * // Simple POST request example (passing data) : + * $http.post('/someUrl', {msg:'hello word!'}). + * success(function(data, status, headers, config) { + * // this callback will be called asynchronously + * // when the response is available + * }). + * error(function(data, status, headers, config) { + * // called asynchronously if an error occurs + * // or server returns response with an error status. + * }); + * ``` + * + * + * Since the returned value of calling the $http function is a `promise`, you can also use + * the `then` method to register callbacks, and these callbacks will receive a single argument – + * an object representing the response. See the API signature and type info below for more + * details. + * + * A response status code between 200 and 299 is considered a success status and + * will result in the success callback being called. Note that if the response is a redirect, + * XMLHttpRequest will transparently follow it, meaning that the error callback will not be + * called for such responses. + * + * ## Writing Unit Tests that use $http + * When unit testing (using {@link ngMock ngMock}), it is necessary to call + * {@link ngMock.$httpBackend#flush $httpBackend.flush()} to flush each pending + * request using trained responses. + * + * ``` + * $httpBackend.expectGET(...); + * $http.get(...); + * $httpBackend.flush(); + * ``` + * + * ## Shortcut methods + * + * Shortcut methods are also available. All shortcut methods require passing in the URL, and + * request data must be passed in for POST/PUT requests. + * + * ```js + * $http.get('/someUrl').success(successCallback); + * $http.post('/someUrl', data).success(successCallback); + * ``` + * + * Complete list of shortcut methods: + * + * - {@link ng.$http#get $http.get} + * - {@link ng.$http#head $http.head} + * - {@link ng.$http#post $http.post} + * - {@link ng.$http#put $http.put} + * - {@link ng.$http#delete $http.delete} + * - {@link ng.$http#jsonp $http.jsonp} + * - {@link ng.$http#patch $http.patch} + * + * + * ## Setting HTTP Headers + * + * The $http service will automatically add certain HTTP headers to all requests. These defaults + * can be fully configured by accessing the `$httpProvider.defaults.headers` configuration + * object, which currently contains this default configuration: + * + * - `$httpProvider.defaults.headers.common` (headers that are common for all requests): + * - `Accept: application/json, text/plain, * / *` + * - `$httpProvider.defaults.headers.post`: (header defaults for POST requests) + * - `Content-Type: application/json` + * - `$httpProvider.defaults.headers.put` (header defaults for PUT requests) + * - `Content-Type: application/json` + * + * To add or overwrite these defaults, simply add or remove a property from these configuration + * objects. To add headers for an HTTP method other than POST or PUT, simply add a new object + * with the lowercased HTTP method name as the key, e.g. + * `$httpProvider.defaults.headers.get = { 'My-Header' : 'value' }. + * + * The defaults can also be set at runtime via the `$http.defaults` object in the same + * fashion. For example: + * + * ``` + * module.run(function($http) { + * $http.defaults.headers.common.Authorization = 'Basic YmVlcDpib29w' + * }); + * ``` + * + * In addition, you can supply a `headers` property in the config object passed when + * calling `$http(config)`, which overrides the defaults without changing them globally. + * + * To explicitly remove a header automatically added via $httpProvider.defaults.headers on a per request basis, + * Use the `headers` property, setting the desired header to `undefined`. For example: + * + * ```js + * var req = { + * method: 'POST', + * url: 'http://example.com', + * headers: { + * 'Content-Type': undefined + * }, + * data: { test: 'test' } + * } + * + * $http(req).success(function(){...}).error(function(){...}); + * ``` + * + * ## Transforming Requests and Responses + * + * Both requests and responses can be transformed using transformation functions: `transformRequest` + * and `transformResponse`. These properties can be a single function that returns + * the transformed value (`function(data, headersGetter, status)`) or an array of such transformation functions, + * which allows you to `push` or `unshift` a new transformation function into the transformation chain. + * + * ### Default Transformations + * + * The `$httpProvider` provider and `$http` service expose `defaults.transformRequest` and + * `defaults.transformResponse` properties. If a request does not provide its own transformations + * then these will be applied. + * + * You can augment or replace the default transformations by modifying these properties by adding to or + * replacing the array. + * + * Angular provides the following default transformations: + * + * Request transformations (`$httpProvider.defaults.transformRequest` and `$http.defaults.transformRequest`): + * + * - If the `data` property of the request configuration object contains an object, serialize it + * into JSON format. + * + * Response transformations (`$httpProvider.defaults.transformResponse` and `$http.defaults.transformResponse`): + * + * - If XSRF prefix is detected, strip it (see Security Considerations section below). + * - If JSON response is detected, deserialize it using a JSON parser. + * + * + * ### Overriding the Default Transformations Per Request + * + * If you wish override the request/response transformations only for a single request then provide + * `transformRequest` and/or `transformResponse` properties on the configuration object passed + * into `$http`. + * + * Note that if you provide these properties on the config object the default transformations will be + * overwritten. If you wish to augment the default transformations then you must include them in your + * local transformation array. + * + * The following code demonstrates adding a new response transformation to be run after the default response + * transformations have been run. + * + * ```js + * function appendTransform(defaults, transform) { + * + * // We can't guarantee that the default transformation is an array + * defaults = angular.isArray(defaults) ? defaults : [defaults]; + * + * // Append the new transformation to the defaults + * return defaults.concat(transform); + * } + * + * $http({ + * url: '...', + * method: 'GET', + * transformResponse: appendTransform($http.defaults.transformResponse, function(value) { + * return doTransform(value); + * }) + * }); + * ``` + * + * + * ## Caching + * + * To enable caching, set the request configuration `cache` property to `true` (to use default + * cache) or to a custom cache object (built with {@link ng.$cacheFactory `$cacheFactory`}). + * When the cache is enabled, `$http` stores the response from the server in the specified + * cache. The next time the same request is made, the response is served from the cache without + * sending a request to the server. + * + * Note that even if the response is served from cache, delivery of the data is asynchronous in + * the same way that real requests are. + * + * If there are multiple GET requests for the same URL that should be cached using the same + * cache, but the cache is not populated yet, only one request to the server will be made and + * the remaining requests will be fulfilled using the response from the first request. + * + * You can change the default cache to a new object (built with + * {@link ng.$cacheFactory `$cacheFactory`}) by updating the + * {@link ng.$http#defaults `$http.defaults.cache`} property. All requests who set + * their `cache` property to `true` will now use this cache object. + * + * If you set the default cache to `false` then only requests that specify their own custom + * cache object will be cached. + * + * ## Interceptors + * + * Before you start creating interceptors, be sure to understand the + * {@link ng.$q $q and deferred/promise APIs}. + * + * For purposes of global error handling, authentication, or any kind of synchronous or + * asynchronous pre-processing of request or postprocessing of responses, it is desirable to be + * able to intercept requests before they are handed to the server and + * responses before they are handed over to the application code that + * initiated these requests. The interceptors leverage the {@link ng.$q + * promise APIs} to fulfill this need for both synchronous and asynchronous pre-processing. + * + * The interceptors are service factories that are registered with the `$httpProvider` by + * adding them to the `$httpProvider.interceptors` array. The factory is called and + * injected with dependencies (if specified) and returns the interceptor. + * + * There are two kinds of interceptors (and two kinds of rejection interceptors): + * + * * `request`: interceptors get called with a http `config` object. The function is free to + * modify the `config` object or create a new one. The function needs to return the `config` + * object directly, or a promise containing the `config` or a new `config` object. + * * `requestError`: interceptor gets called when a previous interceptor threw an error or + * resolved with a rejection. + * * `response`: interceptors get called with http `response` object. The function is free to + * modify the `response` object or create a new one. The function needs to return the `response` + * object directly, or as a promise containing the `response` or a new `response` object. + * * `responseError`: interceptor gets called when a previous interceptor threw an error or + * resolved with a rejection. + * + * + * ```js + * // register the interceptor as a service + * $provide.factory('myHttpInterceptor', function($q, dependency1, dependency2) { + * return { + * // optional method + * 'request': function(config) { + * // do something on success + * return config; + * }, + * + * // optional method + * 'requestError': function(rejection) { + * // do something on error + * if (canRecover(rejection)) { + * return responseOrNewPromise + * } + * return $q.reject(rejection); + * }, + * + * + * + * // optional method + * 'response': function(response) { + * // do something on success + * return response; + * }, + * + * // optional method + * 'responseError': function(rejection) { + * // do something on error + * if (canRecover(rejection)) { + * return responseOrNewPromise + * } + * return $q.reject(rejection); + * } + * }; + * }); + * + * $httpProvider.interceptors.push('myHttpInterceptor'); + * + * + * // alternatively, register the interceptor via an anonymous factory + * $httpProvider.interceptors.push(function($q, dependency1, dependency2) { + * return { + * 'request': function(config) { + * // same as above + * }, + * + * 'response': function(response) { + * // same as above + * } + * }; + * }); + * ``` + * + * ## Security Considerations + * + * When designing web applications, consider security threats from: + * + * - [JSON vulnerability](http://haacked.com/archive/2008/11/20/anatomy-of-a-subtle-json-vulnerability.aspx) + * - [XSRF](http://en.wikipedia.org/wiki/Cross-site_request_forgery) + * + * Both server and the client must cooperate in order to eliminate these threats. Angular comes + * pre-configured with strategies that address these issues, but for this to work backend server + * cooperation is required. + * + * ### JSON Vulnerability Protection + * + * A [JSON vulnerability](http://haacked.com/archive/2008/11/20/anatomy-of-a-subtle-json-vulnerability.aspx) + * allows third party website to turn your JSON resource URL into + * [JSONP](http://en.wikipedia.org/wiki/JSONP) request under some conditions. To + * counter this your server can prefix all JSON requests with following string `")]}',\n"`. + * Angular will automatically strip the prefix before processing it as JSON. + * + * For example if your server needs to return: + * ```js + * ['one','two'] + * ``` + * + * which is vulnerable to attack, your server can return: + * ```js + * )]}', + * ['one','two'] + * ``` + * + * Angular will strip the prefix, before processing the JSON. + * + * + * ### Cross Site Request Forgery (XSRF) Protection + * + * [XSRF](http://en.wikipedia.org/wiki/Cross-site_request_forgery) is a technique by which + * an unauthorized site can gain your user's private data. Angular provides a mechanism + * to counter XSRF. When performing XHR requests, the $http service reads a token from a cookie + * (by default, `XSRF-TOKEN`) and sets it as an HTTP header (`X-XSRF-TOKEN`). Since only + * JavaScript that runs on your domain could read the cookie, your server can be assured that + * the XHR came from JavaScript running on your domain. The header will not be set for + * cross-domain requests. + * + * To take advantage of this, your server needs to set a token in a JavaScript readable session + * cookie called `XSRF-TOKEN` on the first HTTP GET request. On subsequent XHR requests the + * server can verify that the cookie matches `X-XSRF-TOKEN` HTTP header, and therefore be sure + * that only JavaScript running on your domain could have sent the request. The token must be + * unique for each user and must be verifiable by the server (to prevent the JavaScript from + * making up its own tokens). We recommend that the token is a digest of your site's + * authentication cookie with a [salt](https://en.wikipedia.org/wiki/Salt_(cryptography)) + * for added security. + * + * The name of the headers can be specified using the xsrfHeaderName and xsrfCookieName + * properties of either $httpProvider.defaults at config-time, $http.defaults at run-time, + * or the per-request config object. + * + * + * @param {object} config Object describing the request to be made and how it should be + * processed. The object has following properties: + * + * - **method** – `{string}` – HTTP method (e.g. 'GET', 'POST', etc) + * - **url** – `{string}` – Absolute or relative URL of the resource that is being requested. + * - **params** – `{Object.}` – Map of strings or objects which will be turned + * to `?key1=value1&key2=value2` after the url. If the value is not a string, it will be + * JSONified. + * - **data** – `{string|Object}` – Data to be sent as the request message data. + * - **headers** – `{Object}` – Map of strings or functions which return strings representing + * HTTP headers to send to the server. If the return value of a function is null, the + * header will not be sent. + * - **xsrfHeaderName** – `{string}` – Name of HTTP header to populate with the XSRF token. + * - **xsrfCookieName** – `{string}` – Name of cookie containing the XSRF token. + * - **transformRequest** – + * `{function(data, headersGetter)|Array.}` – + * transform function or an array of such functions. The transform function takes the http + * request body and headers and returns its transformed (typically serialized) version. + * See {@link ng.$http#overriding-the-default-transformations-per-request + * Overriding the Default Transformations} + * - **transformResponse** – + * `{function(data, headersGetter, status)|Array.}` – + * transform function or an array of such functions. The transform function takes the http + * response body, headers and status and returns its transformed (typically deserialized) version. + * See {@link ng.$http#overriding-the-default-transformations-per-request + * Overriding the Default Transformations} + * - **cache** – `{boolean|Cache}` – If true, a default $http cache will be used to cache the + * GET request, otherwise if a cache instance built with + * {@link ng.$cacheFactory $cacheFactory}, this cache will be used for + * caching. + * - **timeout** – `{number|Promise}` – timeout in milliseconds, or {@link ng.$q promise} + * that should abort the request when resolved. + * - **withCredentials** - `{boolean}` - whether to set the `withCredentials` flag on the + * XHR object. See [requests with credentials](https://developer.mozilla.org/docs/Web/HTTP/Access_control_CORS#Requests_with_credentials) + * for more information. + * - **responseType** - `{string}` - see + * [requestType](https://developer.mozilla.org/en-US/docs/DOM/XMLHttpRequest#responseType). + * + * @returns {HttpPromise} Returns a {@link ng.$q promise} object with the + * standard `then` method and two http specific methods: `success` and `error`. The `then` + * method takes two arguments a success and an error callback which will be called with a + * response object. The `success` and `error` methods take a single argument - a function that + * will be called when the request succeeds or fails respectively. The arguments passed into + * these functions are destructured representation of the response object passed into the + * `then` method. The response object has these properties: + * + * - **data** – `{string|Object}` – The response body transformed with the transform + * functions. + * - **status** – `{number}` – HTTP status code of the response. + * - **headers** – `{function([headerName])}` – Header getter function. + * - **config** – `{Object}` – The configuration object that was used to generate the request. + * - **statusText** – `{string}` – HTTP status text of the response. + * + * @property {Array.} pendingRequests Array of config objects for currently pending + * requests. This is primarily meant to be used for debugging purposes. + * + * + * @example + + +
      + + +
      + + + +
      http status code: {{status}}
      +
      http response data: {{data}}
      +
      +
      + + angular.module('httpExample', []) + .controller('FetchController', ['$scope', '$http', '$templateCache', + function($scope, $http, $templateCache) { + $scope.method = 'GET'; + $scope.url = 'http-hello.html'; + + $scope.fetch = function() { + $scope.code = null; + $scope.response = null; + + $http({method: $scope.method, url: $scope.url, cache: $templateCache}). + success(function(data, status) { + $scope.status = status; + $scope.data = data; + }). + error(function(data, status) { + $scope.data = data || "Request failed"; + $scope.status = status; + }); + }; + + $scope.updateModel = function(method, url) { + $scope.method = method; + $scope.url = url; + }; + }]); + + + Hello, $http! + + + var status = element(by.binding('status')); + var data = element(by.binding('data')); + var fetchBtn = element(by.id('fetchbtn')); + var sampleGetBtn = element(by.id('samplegetbtn')); + var sampleJsonpBtn = element(by.id('samplejsonpbtn')); + var invalidJsonpBtn = element(by.id('invalidjsonpbtn')); + + it('should make an xhr GET request', function() { + sampleGetBtn.click(); + fetchBtn.click(); + expect(status.getText()).toMatch('200'); + expect(data.getText()).toMatch(/Hello, \$http!/); + }); + +// Commented out due to flakes. See https://github.com/angular/angular.js/issues/9185 +// it('should make a JSONP request to angularjs.org', function() { +// sampleJsonpBtn.click(); +// fetchBtn.click(); +// expect(status.getText()).toMatch('200'); +// expect(data.getText()).toMatch(/Super Hero!/); +// }); + + it('should make JSONP request to invalid URL and invoke the error handler', + function() { + invalidJsonpBtn.click(); + fetchBtn.click(); + expect(status.getText()).toMatch('0'); + expect(data.getText()).toMatch('Request failed'); + }); + +
      + */ + function $http(requestConfig) { + + if (!angular.isObject(requestConfig)) { + throw minErr('$http')('badreq', 'Http request configuration must be an object. Received: {0}', requestConfig); + } + + var config = extend({ + method: 'get', + transformRequest: defaults.transformRequest, + transformResponse: defaults.transformResponse + }, requestConfig); + + config.headers = mergeHeaders(requestConfig); + config.method = uppercase(config.method); + + var serverRequest = function(config) { + var headers = config.headers; + var reqData = transformData(config.data, headersGetter(headers), undefined, config.transformRequest); + + // strip content-type if data is undefined + if (isUndefined(reqData)) { + forEach(headers, function(value, header) { + if (lowercase(header) === 'content-type') { + delete headers[header]; + } + }); + } + + if (isUndefined(config.withCredentials) && !isUndefined(defaults.withCredentials)) { + config.withCredentials = defaults.withCredentials; + } + + // send request + return sendReq(config, reqData).then(transformResponse, transformResponse); + }; + + var chain = [serverRequest, undefined]; + var promise = $q.when(config); + + // apply interceptors + forEach(reversedInterceptors, function(interceptor) { + if (interceptor.request || interceptor.requestError) { + chain.unshift(interceptor.request, interceptor.requestError); + } + if (interceptor.response || interceptor.responseError) { + chain.push(interceptor.response, interceptor.responseError); + } + }); + + while (chain.length) { + var thenFn = chain.shift(); + var rejectFn = chain.shift(); + + promise = promise.then(thenFn, rejectFn); + } + + promise.success = function(fn) { + assertArgFn(fn, 'fn'); + + promise.then(function(response) { + fn(response.data, response.status, response.headers, config); + }); + return promise; + }; + + promise.error = function(fn) { + assertArgFn(fn, 'fn'); + + promise.then(null, function(response) { + fn(response.data, response.status, response.headers, config); + }); + return promise; + }; + + return promise; + + function transformResponse(response) { + // make a copy since the response must be cacheable + var resp = extend({}, response); + if (!response.data) { + resp.data = response.data; + } else { + resp.data = transformData(response.data, response.headers, response.status, config.transformResponse); + } + return (isSuccess(response.status)) + ? resp + : $q.reject(resp); + } + + function executeHeaderFns(headers) { + var headerContent, processedHeaders = {}; + + forEach(headers, function(headerFn, header) { + if (isFunction(headerFn)) { + headerContent = headerFn(); + if (headerContent != null) { + processedHeaders[header] = headerContent; + } + } else { + processedHeaders[header] = headerFn; + } + }); + + return processedHeaders; + } + + function mergeHeaders(config) { + var defHeaders = defaults.headers, + reqHeaders = extend({}, config.headers), + defHeaderName, lowercaseDefHeaderName, reqHeaderName; + + defHeaders = extend({}, defHeaders.common, defHeaders[lowercase(config.method)]); + + // using for-in instead of forEach to avoid unecessary iteration after header has been found + defaultHeadersIteration: + for (defHeaderName in defHeaders) { + lowercaseDefHeaderName = lowercase(defHeaderName); + + for (reqHeaderName in reqHeaders) { + if (lowercase(reqHeaderName) === lowercaseDefHeaderName) { + continue defaultHeadersIteration; + } + } + + reqHeaders[defHeaderName] = defHeaders[defHeaderName]; + } + + // execute if header value is a function for merged headers + return executeHeaderFns(reqHeaders); + } + } + + $http.pendingRequests = []; + + /** + * @ngdoc method + * @name $http#get + * + * @description + * Shortcut method to perform `GET` request. + * + * @param {string} url Relative or absolute URL specifying the destination of the request + * @param {Object=} config Optional configuration object + * @returns {HttpPromise} Future object + */ + + /** + * @ngdoc method + * @name $http#delete + * + * @description + * Shortcut method to perform `DELETE` request. + * + * @param {string} url Relative or absolute URL specifying the destination of the request + * @param {Object=} config Optional configuration object + * @returns {HttpPromise} Future object + */ + + /** + * @ngdoc method + * @name $http#head + * + * @description + * Shortcut method to perform `HEAD` request. + * + * @param {string} url Relative or absolute URL specifying the destination of the request + * @param {Object=} config Optional configuration object + * @returns {HttpPromise} Future object + */ + + /** + * @ngdoc method + * @name $http#jsonp + * + * @description + * Shortcut method to perform `JSONP` request. + * + * @param {string} url Relative or absolute URL specifying the destination of the request. + * The name of the callback should be the string `JSON_CALLBACK`. + * @param {Object=} config Optional configuration object + * @returns {HttpPromise} Future object + */ + createShortMethods('get', 'delete', 'head', 'jsonp'); + + /** + * @ngdoc method + * @name $http#post + * + * @description + * Shortcut method to perform `POST` request. + * + * @param {string} url Relative or absolute URL specifying the destination of the request + * @param {*} data Request content + * @param {Object=} config Optional configuration object + * @returns {HttpPromise} Future object + */ + + /** + * @ngdoc method + * @name $http#put + * + * @description + * Shortcut method to perform `PUT` request. + * + * @param {string} url Relative or absolute URL specifying the destination of the request + * @param {*} data Request content + * @param {Object=} config Optional configuration object + * @returns {HttpPromise} Future object + */ + + /** + * @ngdoc method + * @name $http#patch + * + * @description + * Shortcut method to perform `PATCH` request. + * + * @param {string} url Relative or absolute URL specifying the destination of the request + * @param {*} data Request content + * @param {Object=} config Optional configuration object + * @returns {HttpPromise} Future object + */ + createShortMethodsWithData('post', 'put', 'patch'); + + /** + * @ngdoc property + * @name $http#defaults + * + * @description + * Runtime equivalent of the `$httpProvider.defaults` property. Allows configuration of + * default headers, withCredentials as well as request and response transformations. + * + * See "Setting HTTP Headers" and "Transforming Requests and Responses" sections above. + */ + $http.defaults = defaults; + + + return $http; + + + function createShortMethods(names) { + forEach(arguments, function(name) { + $http[name] = function(url, config) { + return $http(extend(config || {}, { + method: name, + url: url + })); + }; + }); + } + + + function createShortMethodsWithData(name) { + forEach(arguments, function(name) { + $http[name] = function(url, data, config) { + return $http(extend(config || {}, { + method: name, + url: url, + data: data + })); + }; + }); + } + + + /** + * Makes the request. + * + * !!! ACCESSES CLOSURE VARS: + * $httpBackend, defaults, $log, $rootScope, defaultCache, $http.pendingRequests + */ + function sendReq(config, reqData) { + var deferred = $q.defer(), + promise = deferred.promise, + cache, + cachedResp, + reqHeaders = config.headers, + url = buildUrl(config.url, config.params); + + $http.pendingRequests.push(config); + promise.then(removePendingReq, removePendingReq); + + + if ((config.cache || defaults.cache) && config.cache !== false && + (config.method === 'GET' || config.method === 'JSONP')) { + cache = isObject(config.cache) ? config.cache + : isObject(defaults.cache) ? defaults.cache + : defaultCache; + } + + if (cache) { + cachedResp = cache.get(url); + if (isDefined(cachedResp)) { + if (isPromiseLike(cachedResp)) { + // cached request has already been sent, but there is no response yet + cachedResp.then(resolvePromiseWithResult, resolvePromiseWithResult); + } else { + // serving from cache + if (isArray(cachedResp)) { + resolvePromise(cachedResp[1], cachedResp[0], shallowCopy(cachedResp[2]), cachedResp[3]); + } else { + resolvePromise(cachedResp, 200, {}, 'OK'); + } + } + } else { + // put the promise for the non-transformed response into cache as a placeholder + cache.put(url, promise); + } + } + + + // if we won't have the response in cache, set the xsrf headers and + // send the request to the backend + if (isUndefined(cachedResp)) { + var xsrfValue = urlIsSameOrigin(config.url) + ? $browser.cookies()[config.xsrfCookieName || defaults.xsrfCookieName] + : undefined; + if (xsrfValue) { + reqHeaders[(config.xsrfHeaderName || defaults.xsrfHeaderName)] = xsrfValue; + } + + $httpBackend(config.method, url, reqData, done, reqHeaders, config.timeout, + config.withCredentials, config.responseType); + } + + return promise; + + + /** + * Callback registered to $httpBackend(): + * - caches the response if desired + * - resolves the raw $http promise + * - calls $apply + */ + function done(status, response, headersString, statusText) { + if (cache) { + if (isSuccess(status)) { + cache.put(url, [status, response, parseHeaders(headersString), statusText]); + } else { + // remove promise from the cache + cache.remove(url); + } + } + + function resolveHttpPromise() { + resolvePromise(response, status, headersString, statusText); + } + + if (useApplyAsync) { + $rootScope.$applyAsync(resolveHttpPromise); + } else { + resolveHttpPromise(); + if (!$rootScope.$$phase) $rootScope.$apply(); + } + } + + + /** + * Resolves the raw $http promise. + */ + function resolvePromise(response, status, headers, statusText) { + //status: HTTP response status code, 0, -1 (aborted by timeout / promise) + status = status >= -1 ? status : 0; + + (isSuccess(status) ? deferred.resolve : deferred.reject)({ + data: response, + status: status, + headers: headersGetter(headers), + config: config, + statusText: statusText + }); + } + + function resolvePromiseWithResult(result) { + resolvePromise(result.data, result.status, shallowCopy(result.headers()), result.statusText); + } + + function removePendingReq() { + var idx = $http.pendingRequests.indexOf(config); + if (idx !== -1) $http.pendingRequests.splice(idx, 1); + } + } + + + function buildUrl(url, params) { + if (!params) return url; + var parts = []; + forEachSorted(params, function(value, key) { + if (value === null || isUndefined(value)) return; + if (!isArray(value)) value = [value]; + + forEach(value, function(v) { + if (isObject(v)) { + if (isDate(v)) { + v = v.toISOString(); + } else { + v = toJson(v); + } + } + parts.push(encodeUriQuery(key) + '=' + + encodeUriQuery(v)); + }); + }); + if (parts.length > 0) { + url += ((url.indexOf('?') == -1) ? '?' : '&') + parts.join('&'); + } + return url; + } + }]; +} + +function createXhr() { + return new window.XMLHttpRequest(); +} + +/** + * @ngdoc service + * @name $httpBackend + * @requires $window + * @requires $document + * + * @description + * HTTP backend used by the {@link ng.$http service} that delegates to + * XMLHttpRequest object or JSONP and deals with browser incompatibilities. + * + * You should never need to use this service directly, instead use the higher-level abstractions: + * {@link ng.$http $http} or {@link ngResource.$resource $resource}. + * + * During testing this implementation is swapped with {@link ngMock.$httpBackend mock + * $httpBackend} which can be trained with responses. + */ +function $HttpBackendProvider() { + this.$get = ['$browser', '$window', '$document', function($browser, $window, $document) { + return createHttpBackend($browser, createXhr, $browser.defer, $window.angular.callbacks, $document[0]); + }]; +} + +function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDocument) { + // TODO(vojta): fix the signature + return function(method, url, post, callback, headers, timeout, withCredentials, responseType) { + $browser.$$incOutstandingRequestCount(); + url = url || $browser.url(); + + if (lowercase(method) == 'jsonp') { + var callbackId = '_' + (callbacks.counter++).toString(36); + callbacks[callbackId] = function(data) { + callbacks[callbackId].data = data; + callbacks[callbackId].called = true; + }; + + var jsonpDone = jsonpReq(url.replace('JSON_CALLBACK', 'angular.callbacks.' + callbackId), + callbackId, function(status, text) { + completeRequest(callback, status, callbacks[callbackId].data, "", text); + callbacks[callbackId] = noop; + }); + } else { + + var xhr = createXhr(); + + xhr.open(method, url, true); + forEach(headers, function(value, key) { + if (isDefined(value)) { + xhr.setRequestHeader(key, value); + } + }); + + xhr.onload = function requestLoaded() { + var statusText = xhr.statusText || ''; + + // responseText is the old-school way of retrieving response (supported by IE9) + // response/responseType properties were introduced in XHR Level2 spec (supported by IE10) + var response = ('response' in xhr) ? xhr.response : xhr.responseText; + + // normalize IE9 bug (http://bugs.jquery.com/ticket/1450) + var status = xhr.status === 1223 ? 204 : xhr.status; + + // fix status code when it is 0 (0 status is undocumented). + // Occurs when accessing file resources or on Android 4.1 stock browser + // while retrieving files from application cache. + if (status === 0) { + status = response ? 200 : urlResolve(url).protocol == 'file' ? 404 : 0; + } + + completeRequest(callback, + status, + response, + xhr.getAllResponseHeaders(), + statusText); + }; + + var requestError = function() { + // The response is always empty + // See https://xhr.spec.whatwg.org/#request-error-steps and https://fetch.spec.whatwg.org/#concept-network-error + completeRequest(callback, -1, null, null, ''); + }; + + xhr.onerror = requestError; + xhr.onabort = requestError; + + if (withCredentials) { + xhr.withCredentials = true; + } + + if (responseType) { + try { + xhr.responseType = responseType; + } catch (e) { + // WebKit added support for the json responseType value on 09/03/2013 + // https://bugs.webkit.org/show_bug.cgi?id=73648. Versions of Safari prior to 7 are + // known to throw when setting the value "json" as the response type. Other older + // browsers implementing the responseType + // + // The json response type can be ignored if not supported, because JSON payloads are + // parsed on the client-side regardless. + if (responseType !== 'json') { + throw e; + } + } + } + + xhr.send(post || null); + } + + if (timeout > 0) { + var timeoutId = $browserDefer(timeoutRequest, timeout); + } else if (isPromiseLike(timeout)) { + timeout.then(timeoutRequest); + } + + + function timeoutRequest() { + jsonpDone && jsonpDone(); + xhr && xhr.abort(); + } + + function completeRequest(callback, status, response, headersString, statusText) { + // cancel timeout and subsequent timeout promise resolution + if (timeoutId !== undefined) { + $browserDefer.cancel(timeoutId); + } + jsonpDone = xhr = null; + + callback(status, response, headersString, statusText); + $browser.$$completeOutstandingRequest(noop); + } + }; + + function jsonpReq(url, callbackId, done) { + // we can't use jQuery/jqLite here because jQuery does crazy stuff with script elements, e.g.: + // - fetches local scripts via XHR and evals them + // - adds and immediately removes script elements from the document + var script = rawDocument.createElement('script'), callback = null; + script.type = "text/javascript"; + script.src = url; + script.async = true; + + callback = function(event) { + removeEventListenerFn(script, "load", callback); + removeEventListenerFn(script, "error", callback); + rawDocument.body.removeChild(script); + script = null; + var status = -1; + var text = "unknown"; + + if (event) { + if (event.type === "load" && !callbacks[callbackId].called) { + event = { type: "error" }; + } + text = event.type; + status = event.type === "error" ? 404 : 200; + } + + if (done) { + done(status, text); + } + }; + + addEventListenerFn(script, "load", callback); + addEventListenerFn(script, "error", callback); + rawDocument.body.appendChild(script); + return callback; + } +} + +var $interpolateMinErr = minErr('$interpolate'); + +/** + * @ngdoc provider + * @name $interpolateProvider + * + * @description + * + * Used for configuring the interpolation markup. Defaults to `{{` and `}}`. + * + * @example + + + +
      + //demo.label// +
      +
      + + it('should interpolate binding with custom symbols', function() { + expect(element(by.binding('demo.label')).getText()).toBe('This binding is brought you by // interpolation symbols.'); + }); + +
      + */ +function $InterpolateProvider() { + var startSymbol = '{{'; + var endSymbol = '}}'; + + /** + * @ngdoc method + * @name $interpolateProvider#startSymbol + * @description + * Symbol to denote start of expression in the interpolated string. Defaults to `{{`. + * + * @param {string=} value new value to set the starting symbol to. + * @returns {string|self} Returns the symbol when used as getter and self if used as setter. + */ + this.startSymbol = function(value) { + if (value) { + startSymbol = value; + return this; + } else { + return startSymbol; + } + }; + + /** + * @ngdoc method + * @name $interpolateProvider#endSymbol + * @description + * Symbol to denote the end of expression in the interpolated string. Defaults to `}}`. + * + * @param {string=} value new value to set the ending symbol to. + * @returns {string|self} Returns the symbol when used as getter and self if used as setter. + */ + this.endSymbol = function(value) { + if (value) { + endSymbol = value; + return this; + } else { + return endSymbol; + } + }; + + + this.$get = ['$parse', '$exceptionHandler', '$sce', function($parse, $exceptionHandler, $sce) { + var startSymbolLength = startSymbol.length, + endSymbolLength = endSymbol.length, + escapedStartRegexp = new RegExp(startSymbol.replace(/./g, escape), 'g'), + escapedEndRegexp = new RegExp(endSymbol.replace(/./g, escape), 'g'); + + function escape(ch) { + return '\\\\\\' + ch; + } + + /** + * @ngdoc service + * @name $interpolate + * @kind function + * + * @requires $parse + * @requires $sce + * + * @description + * + * Compiles a string with markup into an interpolation function. This service is used by the + * HTML {@link ng.$compile $compile} service for data binding. See + * {@link ng.$interpolateProvider $interpolateProvider} for configuring the + * interpolation markup. + * + * + * ```js + * var $interpolate = ...; // injected + * var exp = $interpolate('Hello {{name | uppercase}}!'); + * expect(exp({name:'Angular'}).toEqual('Hello ANGULAR!'); + * ``` + * + * `$interpolate` takes an optional fourth argument, `allOrNothing`. If `allOrNothing` is + * `true`, the interpolation function will return `undefined` unless all embedded expressions + * evaluate to a value other than `undefined`. + * + * ```js + * var $interpolate = ...; // injected + * var context = {greeting: 'Hello', name: undefined }; + * + * // default "forgiving" mode + * var exp = $interpolate('{{greeting}} {{name}}!'); + * expect(exp(context)).toEqual('Hello !'); + * + * // "allOrNothing" mode + * exp = $interpolate('{{greeting}} {{name}}!', false, null, true); + * expect(exp(context)).toBeUndefined(); + * context.name = 'Angular'; + * expect(exp(context)).toEqual('Hello Angular!'); + * ``` + * + * `allOrNothing` is useful for interpolating URLs. `ngSrc` and `ngSrcset` use this behavior. + * + * ####Escaped Interpolation + * $interpolate provides a mechanism for escaping interpolation markers. Start and end markers + * can be escaped by preceding each of their characters with a REVERSE SOLIDUS U+005C (backslash). + * It will be rendered as a regular start/end marker, and will not be interpreted as an expression + * or binding. + * + * This enables web-servers to prevent script injection attacks and defacing attacks, to some + * degree, while also enabling code examples to work without relying on the + * {@link ng.directive:ngNonBindable ngNonBindable} directive. + * + * **For security purposes, it is strongly encouraged that web servers escape user-supplied data, + * replacing angle brackets (<, >) with &lt; and &gt; respectively, and replacing all + * interpolation start/end markers with their escaped counterparts.** + * + * Escaped interpolation markers are only replaced with the actual interpolation markers in rendered + * output when the $interpolate service processes the text. So, for HTML elements interpolated + * by {@link ng.$compile $compile}, or otherwise interpolated with the `mustHaveExpression` parameter + * set to `true`, the interpolated text must contain an unescaped interpolation expression. As such, + * this is typically useful only when user-data is used in rendering a template from the server, or + * when otherwise untrusted data is used by a directive. + * + * + * + *
      + *

      {{apptitle}}: \{\{ username = "defaced value"; \}\} + *

      + *

      {{username}} attempts to inject code which will deface the + * application, but fails to accomplish their task, because the server has correctly + * escaped the interpolation start/end markers with REVERSE SOLIDUS U+005C (backslash) + * characters.

      + *

      Instead, the result of the attempted script injection is visible, and can be removed + * from the database by an administrator.

      + *
      + *
      + *
      + * + * @param {string} text The text with markup to interpolate. + * @param {boolean=} mustHaveExpression if set to true then the interpolation string must have + * embedded expression in order to return an interpolation function. Strings with no + * embedded expression will return null for the interpolation function. + * @param {string=} trustedContext when provided, the returned function passes the interpolated + * result through {@link ng.$sce#getTrusted $sce.getTrusted(interpolatedResult, + * trustedContext)} before returning it. Refer to the {@link ng.$sce $sce} service that + * provides Strict Contextual Escaping for details. + * @param {boolean=} allOrNothing if `true`, then the returned function returns undefined + * unless all embedded expressions evaluate to a value other than `undefined`. + * @returns {function(context)} an interpolation function which is used to compute the + * interpolated string. The function has these parameters: + * + * - `context`: evaluation context for all expressions embedded in the interpolated text + */ + function $interpolate(text, mustHaveExpression, trustedContext, allOrNothing) { + allOrNothing = !!allOrNothing; + var startIndex, + endIndex, + index = 0, + expressions = [], + parseFns = [], + textLength = text.length, + exp, + concat = [], + expressionPositions = []; + + while (index < textLength) { + if (((startIndex = text.indexOf(startSymbol, index)) != -1) && + ((endIndex = text.indexOf(endSymbol, startIndex + startSymbolLength)) != -1)) { + if (index !== startIndex) { + concat.push(unescapeText(text.substring(index, startIndex))); + } + exp = text.substring(startIndex + startSymbolLength, endIndex); + expressions.push(exp); + parseFns.push($parse(exp, parseStringifyInterceptor)); + index = endIndex + endSymbolLength; + expressionPositions.push(concat.length); + concat.push(''); + } else { + // we did not find an interpolation, so we have to add the remainder to the separators array + if (index !== textLength) { + concat.push(unescapeText(text.substring(index))); + } + break; + } + } + + // Concatenating expressions makes it hard to reason about whether some combination of + // concatenated values are unsafe to use and could easily lead to XSS. By requiring that a + // single expression be used for iframe[src], object[src], etc., we ensure that the value + // that's used is assigned or constructed by some JS code somewhere that is more testable or + // make it obvious that you bound the value to some user controlled value. This helps reduce + // the load when auditing for XSS issues. + if (trustedContext && concat.length > 1) { + throw $interpolateMinErr('noconcat', + "Error while interpolating: {0}\nStrict Contextual Escaping disallows " + + "interpolations that concatenate multiple expressions when a trusted value is " + + "required. See http://docs.angularjs.org/api/ng.$sce", text); + } + + if (!mustHaveExpression || expressions.length) { + var compute = function(values) { + for (var i = 0, ii = expressions.length; i < ii; i++) { + if (allOrNothing && isUndefined(values[i])) return; + concat[expressionPositions[i]] = values[i]; + } + return concat.join(''); + }; + + var getValue = function(value) { + return trustedContext ? + $sce.getTrusted(trustedContext, value) : + $sce.valueOf(value); + }; + + var stringify = function(value) { + if (value == null) { // null || undefined + return ''; + } + switch (typeof value) { + case 'string': + break; + case 'number': + value = '' + value; + break; + default: + value = toJson(value); + } + + return value; + }; + + return extend(function interpolationFn(context) { + var i = 0; + var ii = expressions.length; + var values = new Array(ii); + + try { + for (; i < ii; i++) { + values[i] = parseFns[i](context); + } + + return compute(values); + } catch (err) { + var newErr = $interpolateMinErr('interr', "Can't interpolate: {0}\n{1}", text, + err.toString()); + $exceptionHandler(newErr); + } + + }, { + // all of these properties are undocumented for now + exp: text, //just for compatibility with regular watchers created via $watch + expressions: expressions, + $$watchDelegate: function(scope, listener, objectEquality) { + var lastValue; + return scope.$watchGroup(parseFns, function interpolateFnWatcher(values, oldValues) { + var currValue = compute(values); + if (isFunction(listener)) { + listener.call(this, currValue, values !== oldValues ? lastValue : currValue, scope); + } + lastValue = currValue; + }, objectEquality); + } + }); + } + + function unescapeText(text) { + return text.replace(escapedStartRegexp, startSymbol). + replace(escapedEndRegexp, endSymbol); + } + + function parseStringifyInterceptor(value) { + try { + value = getValue(value); + return allOrNothing && !isDefined(value) ? value : stringify(value); + } catch (err) { + var newErr = $interpolateMinErr('interr', "Can't interpolate: {0}\n{1}", text, + err.toString()); + $exceptionHandler(newErr); + } + } + } + + + /** + * @ngdoc method + * @name $interpolate#startSymbol + * @description + * Symbol to denote the start of expression in the interpolated string. Defaults to `{{`. + * + * Use {@link ng.$interpolateProvider#startSymbol `$interpolateProvider.startSymbol`} to change + * the symbol. + * + * @returns {string} start symbol. + */ + $interpolate.startSymbol = function() { + return startSymbol; + }; + + + /** + * @ngdoc method + * @name $interpolate#endSymbol + * @description + * Symbol to denote the end of expression in the interpolated string. Defaults to `}}`. + * + * Use {@link ng.$interpolateProvider#endSymbol `$interpolateProvider.endSymbol`} to change + * the symbol. + * + * @returns {string} end symbol. + */ + $interpolate.endSymbol = function() { + return endSymbol; + }; + + return $interpolate; + }]; +} + +function $IntervalProvider() { + this.$get = ['$rootScope', '$window', '$q', '$$q', + function($rootScope, $window, $q, $$q) { + var intervals = {}; + + + /** + * @ngdoc service + * @name $interval + * + * @description + * Angular's wrapper for `window.setInterval`. The `fn` function is executed every `delay` + * milliseconds. + * + * The return value of registering an interval function is a promise. This promise will be + * notified upon each tick of the interval, and will be resolved after `count` iterations, or + * run indefinitely if `count` is not defined. The value of the notification will be the + * number of iterations that have run. + * To cancel an interval, call `$interval.cancel(promise)`. + * + * In tests you can use {@link ngMock.$interval#flush `$interval.flush(millis)`} to + * move forward by `millis` milliseconds and trigger any functions scheduled to run in that + * time. + * + *
      + * **Note**: Intervals created by this service must be explicitly destroyed when you are finished + * with them. In particular they are not automatically destroyed when a controller's scope or a + * directive's element are destroyed. + * You should take this into consideration and make sure to always cancel the interval at the + * appropriate moment. See the example below for more details on how and when to do this. + *
      + * + * @param {function()} fn A function that should be called repeatedly. + * @param {number} delay Number of milliseconds between each function call. + * @param {number=} [count=0] Number of times to repeat. If not set, or 0, will repeat + * indefinitely. + * @param {boolean=} [invokeApply=true] If set to `false` skips model dirty checking, otherwise + * will invoke `fn` within the {@link ng.$rootScope.Scope#$apply $apply} block. + * @returns {promise} A promise which will be notified on each iteration. + * + * @example + * + * + * + * + *
      + *
      + * Date format:
      + * Current time is: + *
      + * Blood 1 : {{blood_1}} + * Blood 2 : {{blood_2}} + * + * + * + *
      + *
      + * + *
      + *
      + */ + function interval(fn, delay, count, invokeApply) { + var setInterval = $window.setInterval, + clearInterval = $window.clearInterval, + iteration = 0, + skipApply = (isDefined(invokeApply) && !invokeApply), + deferred = (skipApply ? $$q : $q).defer(), + promise = deferred.promise; + + count = isDefined(count) ? count : 0; + + promise.then(null, null, fn); + + promise.$$intervalId = setInterval(function tick() { + deferred.notify(iteration++); + + if (count > 0 && iteration >= count) { + deferred.resolve(iteration); + clearInterval(promise.$$intervalId); + delete intervals[promise.$$intervalId]; + } + + if (!skipApply) $rootScope.$apply(); + + }, delay); + + intervals[promise.$$intervalId] = deferred; + + return promise; + } + + + /** + * @ngdoc method + * @name $interval#cancel + * + * @description + * Cancels a task associated with the `promise`. + * + * @param {promise} promise returned by the `$interval` function. + * @returns {boolean} Returns `true` if the task was successfully canceled. + */ + interval.cancel = function(promise) { + if (promise && promise.$$intervalId in intervals) { + intervals[promise.$$intervalId].reject('canceled'); + $window.clearInterval(promise.$$intervalId); + delete intervals[promise.$$intervalId]; + return true; + } + return false; + }; + + return interval; + }]; +} + +/** + * @ngdoc service + * @name $locale + * + * @description + * $locale service provides localization rules for various Angular components. As of right now the + * only public api is: + * + * * `id` – `{string}` – locale id formatted as `languageId-countryId` (e.g. `en-us`) + */ +function $LocaleProvider() { + this.$get = function() { + return { + id: 'en-us', + + NUMBER_FORMATS: { + DECIMAL_SEP: '.', + GROUP_SEP: ',', + PATTERNS: [ + { // Decimal Pattern + minInt: 1, + minFrac: 0, + maxFrac: 3, + posPre: '', + posSuf: '', + negPre: '-', + negSuf: '', + gSize: 3, + lgSize: 3 + },{ //Currency Pattern + minInt: 1, + minFrac: 2, + maxFrac: 2, + posPre: '\u00A4', + posSuf: '', + negPre: '(\u00A4', + negSuf: ')', + gSize: 3, + lgSize: 3 + } + ], + CURRENCY_SYM: '$' + }, + + DATETIME_FORMATS: { + MONTH: + 'January,February,March,April,May,June,July,August,September,October,November,December' + .split(','), + SHORTMONTH: 'Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec'.split(','), + DAY: 'Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday'.split(','), + SHORTDAY: 'Sun,Mon,Tue,Wed,Thu,Fri,Sat'.split(','), + AMPMS: ['AM','PM'], + medium: 'MMM d, y h:mm:ss a', + 'short': 'M/d/yy h:mm a', + fullDate: 'EEEE, MMMM d, y', + longDate: 'MMMM d, y', + mediumDate: 'MMM d, y', + shortDate: 'M/d/yy', + mediumTime: 'h:mm:ss a', + shortTime: 'h:mm a', + ERANAMES: [ + "Before Christ", + "Anno Domini" + ], + ERAS: [ + "BC", + "AD" + ] + }, + + pluralCat: function(num) { + if (num === 1) { + return 'one'; + } + return 'other'; + } + }; + }; +} + +var PATH_MATCH = /^([^\?#]*)(\?([^#]*))?(#(.*))?$/, + DEFAULT_PORTS = {'http': 80, 'https': 443, 'ftp': 21}; +var $locationMinErr = minErr('$location'); + + +/** + * Encode path using encodeUriSegment, ignoring forward slashes + * + * @param {string} path Path to encode + * @returns {string} + */ +function encodePath(path) { + var segments = path.split('/'), + i = segments.length; + + while (i--) { + segments[i] = encodeUriSegment(segments[i]); + } + + return segments.join('/'); +} + +function parseAbsoluteUrl(absoluteUrl, locationObj) { + var parsedUrl = urlResolve(absoluteUrl); + + locationObj.$$protocol = parsedUrl.protocol; + locationObj.$$host = parsedUrl.hostname; + locationObj.$$port = int(parsedUrl.port) || DEFAULT_PORTS[parsedUrl.protocol] || null; +} + + +function parseAppUrl(relativeUrl, locationObj) { + var prefixed = (relativeUrl.charAt(0) !== '/'); + if (prefixed) { + relativeUrl = '/' + relativeUrl; + } + var match = urlResolve(relativeUrl); + locationObj.$$path = decodeURIComponent(prefixed && match.pathname.charAt(0) === '/' ? + match.pathname.substring(1) : match.pathname); + locationObj.$$search = parseKeyValue(match.search); + locationObj.$$hash = decodeURIComponent(match.hash); + + // make sure path starts with '/'; + if (locationObj.$$path && locationObj.$$path.charAt(0) != '/') { + locationObj.$$path = '/' + locationObj.$$path; + } +} + + +/** + * + * @param {string} begin + * @param {string} whole + * @returns {string} returns text from whole after begin or undefined if it does not begin with + * expected string. + */ +function beginsWith(begin, whole) { + if (whole.indexOf(begin) === 0) { + return whole.substr(begin.length); + } +} + + +function stripHash(url) { + var index = url.indexOf('#'); + return index == -1 ? url : url.substr(0, index); +} + +function trimEmptyHash(url) { + return url.replace(/(#.+)|#$/, '$1'); +} + + +function stripFile(url) { + return url.substr(0, stripHash(url).lastIndexOf('/') + 1); +} + +/* return the server only (scheme://host:port) */ +function serverBase(url) { + return url.substring(0, url.indexOf('/', url.indexOf('//') + 2)); +} + + +/** + * LocationHtml5Url represents an url + * This object is exposed as $location service when HTML5 mode is enabled and supported + * + * @constructor + * @param {string} appBase application base URL + * @param {string} appBaseNoFile application base URL stripped of any filename + * @param {string} basePrefix url path prefix + */ +function LocationHtml5Url(appBase, appBaseNoFile, basePrefix) { + this.$$html5 = true; + basePrefix = basePrefix || ''; + parseAbsoluteUrl(appBase, this); + + + /** + * Parse given html5 (regular) url string into properties + * @param {string} url HTML5 url + * @private + */ + this.$$parse = function(url) { + var pathUrl = beginsWith(appBaseNoFile, url); + if (!isString(pathUrl)) { + throw $locationMinErr('ipthprfx', 'Invalid url "{0}", missing path prefix "{1}".', url, + appBaseNoFile); + } + + parseAppUrl(pathUrl, this); + + if (!this.$$path) { + this.$$path = '/'; + } + + this.$$compose(); + }; + + /** + * Compose url and update `absUrl` property + * @private + */ + this.$$compose = function() { + var search = toKeyValue(this.$$search), + hash = this.$$hash ? '#' + encodeUriSegment(this.$$hash) : ''; + + this.$$url = encodePath(this.$$path) + (search ? '?' + search : '') + hash; + this.$$absUrl = appBaseNoFile + this.$$url.substr(1); // first char is always '/' + }; + + this.$$parseLinkUrl = function(url, relHref) { + if (relHref && relHref[0] === '#') { + // special case for links to hash fragments: + // keep the old url and only replace the hash fragment + this.hash(relHref.slice(1)); + return true; + } + var appUrl, prevAppUrl; + var rewrittenUrl; + + if ((appUrl = beginsWith(appBase, url)) !== undefined) { + prevAppUrl = appUrl; + if ((appUrl = beginsWith(basePrefix, appUrl)) !== undefined) { + rewrittenUrl = appBaseNoFile + (beginsWith('/', appUrl) || appUrl); + } else { + rewrittenUrl = appBase + prevAppUrl; + } + } else if ((appUrl = beginsWith(appBaseNoFile, url)) !== undefined) { + rewrittenUrl = appBaseNoFile + appUrl; + } else if (appBaseNoFile == url + '/') { + rewrittenUrl = appBaseNoFile; + } + if (rewrittenUrl) { + this.$$parse(rewrittenUrl); + } + return !!rewrittenUrl; + }; +} + + +/** + * LocationHashbangUrl represents url + * This object is exposed as $location service when developer doesn't opt into html5 mode. + * It also serves as the base class for html5 mode fallback on legacy browsers. + * + * @constructor + * @param {string} appBase application base URL + * @param {string} appBaseNoFile application base URL stripped of any filename + * @param {string} hashPrefix hashbang prefix + */ +function LocationHashbangUrl(appBase, appBaseNoFile, hashPrefix) { + + parseAbsoluteUrl(appBase, this); + + + /** + * Parse given hashbang url into properties + * @param {string} url Hashbang url + * @private + */ + this.$$parse = function(url) { + var withoutBaseUrl = beginsWith(appBase, url) || beginsWith(appBaseNoFile, url); + var withoutHashUrl; + + if (!isUndefined(withoutBaseUrl) && withoutBaseUrl.charAt(0) === '#') { + + // The rest of the url starts with a hash so we have + // got either a hashbang path or a plain hash fragment + withoutHashUrl = beginsWith(hashPrefix, withoutBaseUrl); + if (isUndefined(withoutHashUrl)) { + // There was no hashbang prefix so we just have a hash fragment + withoutHashUrl = withoutBaseUrl; + } + + } else { + // There was no hashbang path nor hash fragment: + // If we are in HTML5 mode we use what is left as the path; + // Otherwise we ignore what is left + if (this.$$html5) { + withoutHashUrl = withoutBaseUrl; + } else { + withoutHashUrl = ''; + if (isUndefined(withoutBaseUrl)) { + appBase = url; + this.replace(); + } + } + } + + parseAppUrl(withoutHashUrl, this); + + this.$$path = removeWindowsDriveName(this.$$path, withoutHashUrl, appBase); + + this.$$compose(); + + /* + * In Windows, on an anchor node on documents loaded from + * the filesystem, the browser will return a pathname + * prefixed with the drive name ('/C:/path') when a + * pathname without a drive is set: + * * a.setAttribute('href', '/foo') + * * a.pathname === '/C:/foo' //true + * + * Inside of Angular, we're always using pathnames that + * do not include drive names for routing. + */ + function removeWindowsDriveName(path, url, base) { + /* + Matches paths for file protocol on windows, + such as /C:/foo/bar, and captures only /foo/bar. + */ + var windowsFilePathExp = /^\/[A-Z]:(\/.*)/; + + var firstPathSegmentMatch; + + //Get the relative path from the input URL. + if (url.indexOf(base) === 0) { + url = url.replace(base, ''); + } + + // The input URL intentionally contains a first path segment that ends with a colon. + if (windowsFilePathExp.exec(url)) { + return path; + } + + firstPathSegmentMatch = windowsFilePathExp.exec(path); + return firstPathSegmentMatch ? firstPathSegmentMatch[1] : path; + } + }; + + /** + * Compose hashbang url and update `absUrl` property + * @private + */ + this.$$compose = function() { + var search = toKeyValue(this.$$search), + hash = this.$$hash ? '#' + encodeUriSegment(this.$$hash) : ''; + + this.$$url = encodePath(this.$$path) + (search ? '?' + search : '') + hash; + this.$$absUrl = appBase + (this.$$url ? hashPrefix + this.$$url : ''); + }; + + this.$$parseLinkUrl = function(url, relHref) { + if (stripHash(appBase) == stripHash(url)) { + this.$$parse(url); + return true; + } + return false; + }; +} + + +/** + * LocationHashbangUrl represents url + * This object is exposed as $location service when html5 history api is enabled but the browser + * does not support it. + * + * @constructor + * @param {string} appBase application base URL + * @param {string} appBaseNoFile application base URL stripped of any filename + * @param {string} hashPrefix hashbang prefix + */ +function LocationHashbangInHtml5Url(appBase, appBaseNoFile, hashPrefix) { + this.$$html5 = true; + LocationHashbangUrl.apply(this, arguments); + + this.$$parseLinkUrl = function(url, relHref) { + if (relHref && relHref[0] === '#') { + // special case for links to hash fragments: + // keep the old url and only replace the hash fragment + this.hash(relHref.slice(1)); + return true; + } + + var rewrittenUrl; + var appUrl; + + if (appBase == stripHash(url)) { + rewrittenUrl = url; + } else if ((appUrl = beginsWith(appBaseNoFile, url))) { + rewrittenUrl = appBase + hashPrefix + appUrl; + } else if (appBaseNoFile === url + '/') { + rewrittenUrl = appBaseNoFile; + } + if (rewrittenUrl) { + this.$$parse(rewrittenUrl); + } + return !!rewrittenUrl; + }; + + this.$$compose = function() { + var search = toKeyValue(this.$$search), + hash = this.$$hash ? '#' + encodeUriSegment(this.$$hash) : ''; + + this.$$url = encodePath(this.$$path) + (search ? '?' + search : '') + hash; + // include hashPrefix in $$absUrl when $$url is empty so IE9 does not reload page because of removal of '#' + this.$$absUrl = appBase + hashPrefix + this.$$url; + }; + +} + + +var locationPrototype = { + + /** + * Are we in html5 mode? + * @private + */ + $$html5: false, + + /** + * Has any change been replacing? + * @private + */ + $$replace: false, + + /** + * @ngdoc method + * @name $location#absUrl + * + * @description + * This method is getter only. + * + * Return full url representation with all segments encoded according to rules specified in + * [RFC 3986](http://www.ietf.org/rfc/rfc3986.txt). + * + * + * ```js + * // given url http://example.com/#/some/path?foo=bar&baz=xoxo + * var absUrl = $location.absUrl(); + * // => "http://example.com/#/some/path?foo=bar&baz=xoxo" + * ``` + * + * @return {string} full url + */ + absUrl: locationGetter('$$absUrl'), + + /** + * @ngdoc method + * @name $location#url + * + * @description + * This method is getter / setter. + * + * Return url (e.g. `/path?a=b#hash`) when called without any parameter. + * + * Change path, search and hash, when called with parameter and return `$location`. + * + * + * ```js + * // given url http://example.com/#/some/path?foo=bar&baz=xoxo + * var url = $location.url(); + * // => "/some/path?foo=bar&baz=xoxo" + * ``` + * + * @param {string=} url New url without base prefix (e.g. `/path?a=b#hash`) + * @return {string} url + */ + url: function(url) { + if (isUndefined(url)) + return this.$$url; + + var match = PATH_MATCH.exec(url); + if (match[1] || url === '') this.path(decodeURIComponent(match[1])); + if (match[2] || match[1] || url === '') this.search(match[3] || ''); + this.hash(match[5] || ''); + + return this; + }, + + /** + * @ngdoc method + * @name $location#protocol + * + * @description + * This method is getter only. + * + * Return protocol of current url. + * + * + * ```js + * // given url http://example.com/#/some/path?foo=bar&baz=xoxo + * var protocol = $location.protocol(); + * // => "http" + * ``` + * + * @return {string} protocol of current url + */ + protocol: locationGetter('$$protocol'), + + /** + * @ngdoc method + * @name $location#host + * + * @description + * This method is getter only. + * + * Return host of current url. + * + * Note: compared to the non-angular version `location.host` which returns `hostname:port`, this returns the `hostname` portion only. + * + * + * ```js + * // given url http://example.com/#/some/path?foo=bar&baz=xoxo + * var host = $location.host(); + * // => "example.com" + * + * // given url http://user:password@example.com:8080/#/some/path?foo=bar&baz=xoxo + * host = $location.host(); + * // => "example.com" + * host = location.host; + * // => "example.com:8080" + * ``` + * + * @return {string} host of current url. + */ + host: locationGetter('$$host'), + + /** + * @ngdoc method + * @name $location#port + * + * @description + * This method is getter only. + * + * Return port of current url. + * + * + * ```js + * // given url http://example.com/#/some/path?foo=bar&baz=xoxo + * var port = $location.port(); + * // => 80 + * ``` + * + * @return {Number} port + */ + port: locationGetter('$$port'), + + /** + * @ngdoc method + * @name $location#path + * + * @description + * This method is getter / setter. + * + * Return path of current url when called without any parameter. + * + * Change path when called with parameter and return `$location`. + * + * Note: Path should always begin with forward slash (/), this method will add the forward slash + * if it is missing. + * + * + * ```js + * // given url http://example.com/#/some/path?foo=bar&baz=xoxo + * var path = $location.path(); + * // => "/some/path" + * ``` + * + * @param {(string|number)=} path New path + * @return {string} path + */ + path: locationGetterSetter('$$path', function(path) { + path = path !== null ? path.toString() : ''; + return path.charAt(0) == '/' ? path : '/' + path; + }), + + /** + * @ngdoc method + * @name $location#search + * + * @description + * This method is getter / setter. + * + * Return search part (as object) of current url when called without any parameter. + * + * Change search part when called with parameter and return `$location`. + * + * + * ```js + * // given url http://example.com/#/some/path?foo=bar&baz=xoxo + * var searchObject = $location.search(); + * // => {foo: 'bar', baz: 'xoxo'} + * + * // set foo to 'yipee' + * $location.search('foo', 'yipee'); + * // $location.search() => {foo: 'yipee', baz: 'xoxo'} + * ``` + * + * @param {string|Object.|Object.>} search New search params - string or + * hash object. + * + * When called with a single argument the method acts as a setter, setting the `search` component + * of `$location` to the specified value. + * + * If the argument is a hash object containing an array of values, these values will be encoded + * as duplicate search parameters in the url. + * + * @param {(string|Number|Array|boolean)=} paramValue If `search` is a string or number, then `paramValue` + * will override only a single search property. + * + * If `paramValue` is an array, it will override the property of the `search` component of + * `$location` specified via the first argument. + * + * If `paramValue` is `null`, the property specified via the first argument will be deleted. + * + * If `paramValue` is `true`, the property specified via the first argument will be added with no + * value nor trailing equal sign. + * + * @return {Object} If called with no arguments returns the parsed `search` object. If called with + * one or more arguments returns `$location` object itself. + */ + search: function(search, paramValue) { + switch (arguments.length) { + case 0: + return this.$$search; + case 1: + if (isString(search) || isNumber(search)) { + search = search.toString(); + this.$$search = parseKeyValue(search); + } else if (isObject(search)) { + search = copy(search, {}); + // remove object undefined or null properties + forEach(search, function(value, key) { + if (value == null) delete search[key]; + }); + + this.$$search = search; + } else { + throw $locationMinErr('isrcharg', + 'The first argument of the `$location#search()` call must be a string or an object.'); + } + break; + default: + if (isUndefined(paramValue) || paramValue === null) { + delete this.$$search[search]; + } else { + this.$$search[search] = paramValue; + } + } + + this.$$compose(); + return this; + }, + + /** + * @ngdoc method + * @name $location#hash + * + * @description + * This method is getter / setter. + * + * Return hash fragment when called without any parameter. + * + * Change hash fragment when called with parameter and return `$location`. + * + * + * ```js + * // given url http://example.com/#/some/path?foo=bar&baz=xoxo#hashValue + * var hash = $location.hash(); + * // => "hashValue" + * ``` + * + * @param {(string|number)=} hash New hash fragment + * @return {string} hash + */ + hash: locationGetterSetter('$$hash', function(hash) { + return hash !== null ? hash.toString() : ''; + }), + + /** + * @ngdoc method + * @name $location#replace + * + * @description + * If called, all changes to $location during current `$digest` will be replacing current history + * record, instead of adding new one. + */ + replace: function() { + this.$$replace = true; + return this; + } +}; + +forEach([LocationHashbangInHtml5Url, LocationHashbangUrl, LocationHtml5Url], function(Location) { + Location.prototype = Object.create(locationPrototype); + + /** + * @ngdoc method + * @name $location#state + * + * @description + * This method is getter / setter. + * + * Return the history state object when called without any parameter. + * + * Change the history state object when called with one parameter and return `$location`. + * The state object is later passed to `pushState` or `replaceState`. + * + * NOTE: This method is supported only in HTML5 mode and only in browsers supporting + * the HTML5 History API (i.e. methods `pushState` and `replaceState`). If you need to support + * older browsers (like IE9 or Android < 4.0), don't use this method. + * + * @param {object=} state State object for pushState or replaceState + * @return {object} state + */ + Location.prototype.state = function(state) { + if (!arguments.length) + return this.$$state; + + if (Location !== LocationHtml5Url || !this.$$html5) { + throw $locationMinErr('nostate', 'History API state support is available only ' + + 'in HTML5 mode and only in browsers supporting HTML5 History API'); + } + // The user might modify `stateObject` after invoking `$location.state(stateObject)` + // but we're changing the $$state reference to $browser.state() during the $digest + // so the modification window is narrow. + this.$$state = isUndefined(state) ? null : state; + + return this; + }; +}); + + +function locationGetter(property) { + return function() { + return this[property]; + }; +} + + +function locationGetterSetter(property, preprocess) { + return function(value) { + if (isUndefined(value)) + return this[property]; + + this[property] = preprocess(value); + this.$$compose(); + + return this; + }; +} + + +/** + * @ngdoc service + * @name $location + * + * @requires $rootElement + * + * @description + * The $location service parses the URL in the browser address bar (based on the + * [window.location](https://developer.mozilla.org/en/window.location)) and makes the URL + * available to your application. Changes to the URL in the address bar are reflected into + * $location service and changes to $location are reflected into the browser address bar. + * + * **The $location service:** + * + * - Exposes the current URL in the browser address bar, so you can + * - Watch and observe the URL. + * - Change the URL. + * - Synchronizes the URL with the browser when the user + * - Changes the address bar. + * - Clicks the back or forward button (or clicks a History link). + * - Clicks on a link. + * - Represents the URL object as a set of methods (protocol, host, port, path, search, hash). + * + * For more information see {@link guide/$location Developer Guide: Using $location} + */ + +/** + * @ngdoc provider + * @name $locationProvider + * @description + * Use the `$locationProvider` to configure how the application deep linking paths are stored. + */ +function $LocationProvider() { + var hashPrefix = '', + html5Mode = { + enabled: false, + requireBase: true, + rewriteLinks: true + }; + + /** + * @ngdoc method + * @name $locationProvider#hashPrefix + * @description + * @param {string=} prefix Prefix for hash part (containing path and search) + * @returns {*} current value if used as getter or itself (chaining) if used as setter + */ + this.hashPrefix = function(prefix) { + if (isDefined(prefix)) { + hashPrefix = prefix; + return this; + } else { + return hashPrefix; + } + }; + + /** + * @ngdoc method + * @name $locationProvider#html5Mode + * @description + * @param {(boolean|Object)=} mode If boolean, sets `html5Mode.enabled` to value. + * If object, sets `enabled`, `requireBase` and `rewriteLinks` to respective values. Supported + * properties: + * - **enabled** – `{boolean}` – (default: false) If true, will rely on `history.pushState` to + * change urls where supported. Will fall back to hash-prefixed paths in browsers that do not + * support `pushState`. + * - **requireBase** - `{boolean}` - (default: `true`) When html5Mode is enabled, specifies + * whether or not a tag is required to be present. If `enabled` and `requireBase` are + * true, and a base tag is not present, an error will be thrown when `$location` is injected. + * See the {@link guide/$location $location guide for more information} + * - **rewriteLinks** - `{boolean}` - (default: `true`) When html5Mode is enabled, + * enables/disables url rewriting for relative links. + * + * @returns {Object} html5Mode object if used as getter or itself (chaining) if used as setter + */ + this.html5Mode = function(mode) { + if (isBoolean(mode)) { + html5Mode.enabled = mode; + return this; + } else if (isObject(mode)) { + + if (isBoolean(mode.enabled)) { + html5Mode.enabled = mode.enabled; + } + + if (isBoolean(mode.requireBase)) { + html5Mode.requireBase = mode.requireBase; + } + + if (isBoolean(mode.rewriteLinks)) { + html5Mode.rewriteLinks = mode.rewriteLinks; + } + + return this; + } else { + return html5Mode; + } + }; + + /** + * @ngdoc event + * @name $location#$locationChangeStart + * @eventType broadcast on root scope + * @description + * Broadcasted before a URL will change. + * + * This change can be prevented by calling + * `preventDefault` method of the event. See {@link ng.$rootScope.Scope#$on} for more + * details about event object. Upon successful change + * {@link ng.$location#$locationChangeSuccess $locationChangeSuccess} is fired. + * + * The `newState` and `oldState` parameters may be defined only in HTML5 mode and when + * the browser supports the HTML5 History API. + * + * @param {Object} angularEvent Synthetic event object. + * @param {string} newUrl New URL + * @param {string=} oldUrl URL that was before it was changed. + * @param {string=} newState New history state object + * @param {string=} oldState History state object that was before it was changed. + */ + + /** + * @ngdoc event + * @name $location#$locationChangeSuccess + * @eventType broadcast on root scope + * @description + * Broadcasted after a URL was changed. + * + * The `newState` and `oldState` parameters may be defined only in HTML5 mode and when + * the browser supports the HTML5 History API. + * + * @param {Object} angularEvent Synthetic event object. + * @param {string} newUrl New URL + * @param {string=} oldUrl URL that was before it was changed. + * @param {string=} newState New history state object + * @param {string=} oldState History state object that was before it was changed. + */ + + this.$get = ['$rootScope', '$browser', '$sniffer', '$rootElement', '$window', + function($rootScope, $browser, $sniffer, $rootElement, $window) { + var $location, + LocationMode, + baseHref = $browser.baseHref(), // if base[href] is undefined, it defaults to '' + initialUrl = $browser.url(), + appBase; + + if (html5Mode.enabled) { + if (!baseHref && html5Mode.requireBase) { + throw $locationMinErr('nobase', + "$location in HTML5 mode requires a tag to be present!"); + } + appBase = serverBase(initialUrl) + (baseHref || '/'); + LocationMode = $sniffer.history ? LocationHtml5Url : LocationHashbangInHtml5Url; + } else { + appBase = stripHash(initialUrl); + LocationMode = LocationHashbangUrl; + } + var appBaseNoFile = stripFile(appBase); + + $location = new LocationMode(appBase, appBaseNoFile, '#' + hashPrefix); + $location.$$parseLinkUrl(initialUrl, initialUrl); + + $location.$$state = $browser.state(); + + var IGNORE_URI_REGEXP = /^\s*(javascript|mailto):/i; + + function setBrowserUrlWithFallback(url, replace, state) { + var oldUrl = $location.url(); + var oldState = $location.$$state; + try { + $browser.url(url, replace, state); + + // Make sure $location.state() returns referentially identical (not just deeply equal) + // state object; this makes possible quick checking if the state changed in the digest + // loop. Checking deep equality would be too expensive. + $location.$$state = $browser.state(); + } catch (e) { + // Restore old values if pushState fails + $location.url(oldUrl); + $location.$$state = oldState; + + throw e; + } + } + + $rootElement.on('click', function(event) { + // TODO(vojta): rewrite link when opening in new tab/window (in legacy browser) + // currently we open nice url link and redirect then + + if (!html5Mode.rewriteLinks || event.ctrlKey || event.metaKey || event.shiftKey || event.which == 2 || event.button == 2) return; + + var elm = jqLite(event.target); + + // traverse the DOM up to find first A tag + while (nodeName_(elm[0]) !== 'a') { + // ignore rewriting if no A tag (reached root element, or no parent - removed from document) + if (elm[0] === $rootElement[0] || !(elm = elm.parent())[0]) return; + } + + var absHref = elm.prop('href'); + // get the actual href attribute - see + // http://msdn.microsoft.com/en-us/library/ie/dd347148(v=vs.85).aspx + var relHref = elm.attr('href') || elm.attr('xlink:href'); + + if (isObject(absHref) && absHref.toString() === '[object SVGAnimatedString]') { + // SVGAnimatedString.animVal should be identical to SVGAnimatedString.baseVal, unless during + // an animation. + absHref = urlResolve(absHref.animVal).href; + } + + // Ignore when url is started with javascript: or mailto: + if (IGNORE_URI_REGEXP.test(absHref)) return; + + if (absHref && !elm.attr('target') && !event.isDefaultPrevented()) { + if ($location.$$parseLinkUrl(absHref, relHref)) { + // We do a preventDefault for all urls that are part of the angular application, + // in html5mode and also without, so that we are able to abort navigation without + // getting double entries in the location history. + event.preventDefault(); + // update location manually + if ($location.absUrl() != $browser.url()) { + $rootScope.$apply(); + // hack to work around FF6 bug 684208 when scenario runner clicks on links + $window.angular['ff-684208-preventDefault'] = true; + } + } + } + }); + + + // rewrite hashbang url <> html5 url + if (trimEmptyHash($location.absUrl()) != trimEmptyHash(initialUrl)) { + $browser.url($location.absUrl(), true); + } + + var initializing = true; + + // update $location when $browser url changes + $browser.onUrlChange(function(newUrl, newState) { + + if (isUndefined(beginsWith(appBaseNoFile, newUrl))) { + // If we are navigating outside of the app then force a reload + $window.location.href = newUrl; + return; + } + + $rootScope.$evalAsync(function() { + var oldUrl = $location.absUrl(); + var oldState = $location.$$state; + var defaultPrevented; + + $location.$$parse(newUrl); + $location.$$state = newState; + + defaultPrevented = $rootScope.$broadcast('$locationChangeStart', newUrl, oldUrl, + newState, oldState).defaultPrevented; + + // if the location was changed by a `$locationChangeStart` handler then stop + // processing this location change + if ($location.absUrl() !== newUrl) return; + + if (defaultPrevented) { + $location.$$parse(oldUrl); + $location.$$state = oldState; + setBrowserUrlWithFallback(oldUrl, false, oldState); + } else { + initializing = false; + afterLocationChange(oldUrl, oldState); + } + }); + if (!$rootScope.$$phase) $rootScope.$digest(); + }); + + // update browser + $rootScope.$watch(function $locationWatch() { + var oldUrl = trimEmptyHash($browser.url()); + var newUrl = trimEmptyHash($location.absUrl()); + var oldState = $browser.state(); + var currentReplace = $location.$$replace; + var urlOrStateChanged = oldUrl !== newUrl || + ($location.$$html5 && $sniffer.history && oldState !== $location.$$state); + + if (initializing || urlOrStateChanged) { + initializing = false; + + $rootScope.$evalAsync(function() { + var newUrl = $location.absUrl(); + var defaultPrevented = $rootScope.$broadcast('$locationChangeStart', newUrl, oldUrl, + $location.$$state, oldState).defaultPrevented; + + // if the location was changed by a `$locationChangeStart` handler then stop + // processing this location change + if ($location.absUrl() !== newUrl) return; + + if (defaultPrevented) { + $location.$$parse(oldUrl); + $location.$$state = oldState; + } else { + if (urlOrStateChanged) { + setBrowserUrlWithFallback(newUrl, currentReplace, + oldState === $location.$$state ? null : $location.$$state); + } + afterLocationChange(oldUrl, oldState); + } + }); + } + + $location.$$replace = false; + + // we don't need to return anything because $evalAsync will make the digest loop dirty when + // there is a change + }); + + return $location; + + function afterLocationChange(oldUrl, oldState) { + $rootScope.$broadcast('$locationChangeSuccess', $location.absUrl(), oldUrl, + $location.$$state, oldState); + } +}]; +} + +/** + * @ngdoc service + * @name $log + * @requires $window + * + * @description + * Simple service for logging. Default implementation safely writes the message + * into the browser's console (if present). + * + * The main purpose of this service is to simplify debugging and troubleshooting. + * + * The default is to log `debug` messages. You can use + * {@link ng.$logProvider ng.$logProvider#debugEnabled} to change this. + * + * @example + + + angular.module('logExample', []) + .controller('LogController', ['$scope', '$log', function($scope, $log) { + $scope.$log = $log; + $scope.message = 'Hello World!'; + }]); + + +
      +

      Reload this page with open console, enter text and hit the log button...

      + Message: + + + + + + +
      +
      +
      + */ + +/** + * @ngdoc provider + * @name $logProvider + * @description + * Use the `$logProvider` to configure how the application logs messages + */ +function $LogProvider() { + var debug = true, + self = this; + + /** + * @ngdoc method + * @name $logProvider#debugEnabled + * @description + * @param {boolean=} flag enable or disable debug level messages + * @returns {*} current value if used as getter or itself (chaining) if used as setter + */ + this.debugEnabled = function(flag) { + if (isDefined(flag)) { + debug = flag; + return this; + } else { + return debug; + } + }; + + this.$get = ['$window', function($window) { + return { + /** + * @ngdoc method + * @name $log#log + * + * @description + * Write a log message + */ + log: consoleLog('log'), + + /** + * @ngdoc method + * @name $log#info + * + * @description + * Write an information message + */ + info: consoleLog('info'), + + /** + * @ngdoc method + * @name $log#warn + * + * @description + * Write a warning message + */ + warn: consoleLog('warn'), + + /** + * @ngdoc method + * @name $log#error + * + * @description + * Write an error message + */ + error: consoleLog('error'), + + /** + * @ngdoc method + * @name $log#debug + * + * @description + * Write a debug message + */ + debug: (function() { + var fn = consoleLog('debug'); + + return function() { + if (debug) { + fn.apply(self, arguments); + } + }; + }()) + }; + + function formatError(arg) { + if (arg instanceof Error) { + if (arg.stack) { + arg = (arg.message && arg.stack.indexOf(arg.message) === -1) + ? 'Error: ' + arg.message + '\n' + arg.stack + : arg.stack; + } else if (arg.sourceURL) { + arg = arg.message + '\n' + arg.sourceURL + ':' + arg.line; + } + } + return arg; + } + + function consoleLog(type) { + var console = $window.console || {}, + logFn = console[type] || console.log || noop, + hasApply = false; + + // Note: reading logFn.apply throws an error in IE11 in IE8 document mode. + // The reason behind this is that console.log has type "object" in IE8... + try { + hasApply = !!logFn.apply; + } catch (e) {} + + if (hasApply) { + return function() { + var args = []; + forEach(arguments, function(arg) { + args.push(formatError(arg)); + }); + return logFn.apply(console, args); + }; + } + + // we are IE which either doesn't have window.console => this is noop and we do nothing, + // or we are IE where console.log doesn't have apply so we log at least first 2 args + return function(arg1, arg2) { + logFn(arg1, arg2 == null ? '' : arg2); + }; + } + }]; +} + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Any commits to this file should be reviewed with security in mind. * + * Changes to this file can potentially create security vulnerabilities. * + * An approval from 2 Core members with history of modifying * + * this file is required. * + * * + * Does the change somehow allow for arbitrary javascript to be executed? * + * Or allows for someone to change the prototype of built-in objects? * + * Or gives undesired access to variables likes document or window? * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +var $parseMinErr = minErr('$parse'); + +// Sandboxing Angular Expressions +// ------------------------------ +// Angular expressions are generally considered safe because these expressions only have direct +// access to `$scope` and locals. However, one can obtain the ability to execute arbitrary JS code by +// obtaining a reference to native JS functions such as the Function constructor. +// +// As an example, consider the following Angular expression: +// +// {}.toString.constructor('alert("evil JS code")') +// +// This sandboxing technique is not perfect and doesn't aim to be. The goal is to prevent exploits +// against the expression language, but not to prevent exploits that were enabled by exposing +// sensitive JavaScript or browser APIs on Scope. Exposing such objects on a Scope is never a good +// practice and therefore we are not even trying to protect against interaction with an object +// explicitly exposed in this way. +// +// In general, it is not possible to access a Window object from an angular expression unless a +// window or some DOM object that has a reference to window is published onto a Scope. +// Similarly we prevent invocations of function known to be dangerous, as well as assignments to +// native objects. +// +// See https://docs.angularjs.org/guide/security + + +function ensureSafeMemberName(name, fullExpression) { + if (name === "__defineGetter__" || name === "__defineSetter__" + || name === "__lookupGetter__" || name === "__lookupSetter__" + || name === "__proto__") { + throw $parseMinErr('isecfld', + 'Attempting to access a disallowed field in Angular expressions! ' + + 'Expression: {0}', fullExpression); + } + return name; +} + +function getStringValue(name, fullExpression) { + // From the JavaScript docs: + // Property names must be strings. This means that non-string objects cannot be used + // as keys in an object. Any non-string object, including a number, is typecasted + // into a string via the toString method. + // + // So, to ensure that we are checking the same `name` that JavaScript would use, + // we cast it to a string, if possible. + // Doing `name + ''` can cause a repl error if the result to `toString` is not a string, + // this is, this will handle objects that misbehave. + name = name + ''; + if (!isString(name)) { + throw $parseMinErr('iseccst', + 'Cannot convert object to primitive value! ' + + 'Expression: {0}', fullExpression); + } + return name; +} + +function ensureSafeObject(obj, fullExpression) { + // nifty check if obj is Function that is fast and works across iframes and other contexts + if (obj) { + if (obj.constructor === obj) { + throw $parseMinErr('isecfn', + 'Referencing Function in Angular expressions is disallowed! Expression: {0}', + fullExpression); + } else if (// isWindow(obj) + obj.window === obj) { + throw $parseMinErr('isecwindow', + 'Referencing the Window in Angular expressions is disallowed! Expression: {0}', + fullExpression); + } else if (// isElement(obj) + obj.children && (obj.nodeName || (obj.prop && obj.attr && obj.find))) { + throw $parseMinErr('isecdom', + 'Referencing DOM nodes in Angular expressions is disallowed! Expression: {0}', + fullExpression); + } else if (// block Object so that we can't get hold of dangerous Object.* methods + obj === Object) { + throw $parseMinErr('isecobj', + 'Referencing Object in Angular expressions is disallowed! Expression: {0}', + fullExpression); + } + } + return obj; +} + +var CALL = Function.prototype.call; +var APPLY = Function.prototype.apply; +var BIND = Function.prototype.bind; + +function ensureSafeFunction(obj, fullExpression) { + if (obj) { + if (obj.constructor === obj) { + throw $parseMinErr('isecfn', + 'Referencing Function in Angular expressions is disallowed! Expression: {0}', + fullExpression); + } else if (obj === CALL || obj === APPLY || obj === BIND) { + throw $parseMinErr('isecff', + 'Referencing call, apply or bind in Angular expressions is disallowed! Expression: {0}', + fullExpression); + } + } +} + +//Keyword constants +var CONSTANTS = createMap(); +forEach({ + 'null': function() { return null; }, + 'true': function() { return true; }, + 'false': function() { return false; }, + 'undefined': function() {} +}, function(constantGetter, name) { + constantGetter.constant = constantGetter.literal = constantGetter.sharedGetter = true; + CONSTANTS[name] = constantGetter; +}); + +//Not quite a constant, but can be lex/parsed the same +CONSTANTS['this'] = function(self) { return self; }; +CONSTANTS['this'].sharedGetter = true; + + +//Operators - will be wrapped by binaryFn/unaryFn/assignment/filter +var OPERATORS = extend(createMap(), { + '+':function(self, locals, a, b) { + a=a(self, locals); b=b(self, locals); + if (isDefined(a)) { + if (isDefined(b)) { + return a + b; + } + return a; + } + return isDefined(b) ? b : undefined;}, + '-':function(self, locals, a, b) { + a=a(self, locals); b=b(self, locals); + return (isDefined(a) ? a : 0) - (isDefined(b) ? b : 0); + }, + '*':function(self, locals, a, b) {return a(self, locals) * b(self, locals);}, + '/':function(self, locals, a, b) {return a(self, locals) / b(self, locals);}, + '%':function(self, locals, a, b) {return a(self, locals) % b(self, locals);}, + '===':function(self, locals, a, b) {return a(self, locals) === b(self, locals);}, + '!==':function(self, locals, a, b) {return a(self, locals) !== b(self, locals);}, + '==':function(self, locals, a, b) {return a(self, locals) == b(self, locals);}, + '!=':function(self, locals, a, b) {return a(self, locals) != b(self, locals);}, + '<':function(self, locals, a, b) {return a(self, locals) < b(self, locals);}, + '>':function(self, locals, a, b) {return a(self, locals) > b(self, locals);}, + '<=':function(self, locals, a, b) {return a(self, locals) <= b(self, locals);}, + '>=':function(self, locals, a, b) {return a(self, locals) >= b(self, locals);}, + '&&':function(self, locals, a, b) {return a(self, locals) && b(self, locals);}, + '||':function(self, locals, a, b) {return a(self, locals) || b(self, locals);}, + '!':function(self, locals, a) {return !a(self, locals);}, + + //Tokenized as operators but parsed as assignment/filters + '=':true, + '|':true +}); +var ESCAPE = {"n":"\n", "f":"\f", "r":"\r", "t":"\t", "v":"\v", "'":"'", '"':'"'}; + + +///////////////////////////////////////// + + +/** + * @constructor + */ +var Lexer = function(options) { + this.options = options; +}; + +Lexer.prototype = { + constructor: Lexer, + + lex: function(text) { + this.text = text; + this.index = 0; + this.tokens = []; + + while (this.index < this.text.length) { + var ch = this.text.charAt(this.index); + if (ch === '"' || ch === "'") { + this.readString(ch); + } else if (this.isNumber(ch) || ch === '.' && this.isNumber(this.peek())) { + this.readNumber(); + } else if (this.isIdent(ch)) { + this.readIdent(); + } else if (this.is(ch, '(){}[].,;:?')) { + this.tokens.push({index: this.index, text: ch}); + this.index++; + } else if (this.isWhitespace(ch)) { + this.index++; + } else { + var ch2 = ch + this.peek(); + var ch3 = ch2 + this.peek(2); + var op1 = OPERATORS[ch]; + var op2 = OPERATORS[ch2]; + var op3 = OPERATORS[ch3]; + if (op1 || op2 || op3) { + var token = op3 ? ch3 : (op2 ? ch2 : ch); + this.tokens.push({index: this.index, text: token, operator: true}); + this.index += token.length; + } else { + this.throwError('Unexpected next character ', this.index, this.index + 1); + } + } + } + return this.tokens; + }, + + is: function(ch, chars) { + return chars.indexOf(ch) !== -1; + }, + + peek: function(i) { + var num = i || 1; + return (this.index + num < this.text.length) ? this.text.charAt(this.index + num) : false; + }, + + isNumber: function(ch) { + return ('0' <= ch && ch <= '9') && typeof ch === "string"; + }, + + isWhitespace: function(ch) { + // IE treats non-breaking space as \u00A0 + return (ch === ' ' || ch === '\r' || ch === '\t' || + ch === '\n' || ch === '\v' || ch === '\u00A0'); + }, + + isIdent: function(ch) { + return ('a' <= ch && ch <= 'z' || + 'A' <= ch && ch <= 'Z' || + '_' === ch || ch === '$'); + }, + + isExpOperator: function(ch) { + return (ch === '-' || ch === '+' || this.isNumber(ch)); + }, + + throwError: function(error, start, end) { + end = end || this.index; + var colStr = (isDefined(start) + ? 's ' + start + '-' + this.index + ' [' + this.text.substring(start, end) + ']' + : ' ' + end); + throw $parseMinErr('lexerr', 'Lexer Error: {0} at column{1} in expression [{2}].', + error, colStr, this.text); + }, + + readNumber: function() { + var number = ''; + var start = this.index; + while (this.index < this.text.length) { + var ch = lowercase(this.text.charAt(this.index)); + if (ch == '.' || this.isNumber(ch)) { + number += ch; + } else { + var peekCh = this.peek(); + if (ch == 'e' && this.isExpOperator(peekCh)) { + number += ch; + } else if (this.isExpOperator(ch) && + peekCh && this.isNumber(peekCh) && + number.charAt(number.length - 1) == 'e') { + number += ch; + } else if (this.isExpOperator(ch) && + (!peekCh || !this.isNumber(peekCh)) && + number.charAt(number.length - 1) == 'e') { + this.throwError('Invalid exponent'); + } else { + break; + } + } + this.index++; + } + this.tokens.push({ + index: start, + text: number, + constant: true, + value: Number(number) + }); + }, + + readIdent: function() { + var start = this.index; + while (this.index < this.text.length) { + var ch = this.text.charAt(this.index); + if (!(this.isIdent(ch) || this.isNumber(ch))) { + break; + } + this.index++; + } + this.tokens.push({ + index: start, + text: this.text.slice(start, this.index), + identifier: true + }); + }, + + readString: function(quote) { + var start = this.index; + this.index++; + var string = ''; + var rawString = quote; + var escape = false; + while (this.index < this.text.length) { + var ch = this.text.charAt(this.index); + rawString += ch; + if (escape) { + if (ch === 'u') { + var hex = this.text.substring(this.index + 1, this.index + 5); + if (!hex.match(/[\da-f]{4}/i)) + this.throwError('Invalid unicode escape [\\u' + hex + ']'); + this.index += 4; + string += String.fromCharCode(parseInt(hex, 16)); + } else { + var rep = ESCAPE[ch]; + string = string + (rep || ch); + } + escape = false; + } else if (ch === '\\') { + escape = true; + } else if (ch === quote) { + this.index++; + this.tokens.push({ + index: start, + text: rawString, + constant: true, + value: string + }); + return; + } else { + string += ch; + } + this.index++; + } + this.throwError('Unterminated quote', start); + } +}; + + +function isConstant(exp) { + return exp.constant; +} + +/** + * @constructor + */ +var Parser = function(lexer, $filter, options) { + this.lexer = lexer; + this.$filter = $filter; + this.options = options; +}; + +Parser.ZERO = extend(function() { + return 0; +}, { + sharedGetter: true, + constant: true +}); + +Parser.prototype = { + constructor: Parser, + + parse: function(text) { + this.text = text; + this.tokens = this.lexer.lex(text); + + var value = this.statements(); + + if (this.tokens.length !== 0) { + this.throwError('is an unexpected token', this.tokens[0]); + } + + value.literal = !!value.literal; + value.constant = !!value.constant; + + return value; + }, + + primary: function() { + var primary; + if (this.expect('(')) { + primary = this.filterChain(); + this.consume(')'); + } else if (this.expect('[')) { + primary = this.arrayDeclaration(); + } else if (this.expect('{')) { + primary = this.object(); + } else if (this.peek().identifier && this.peek().text in CONSTANTS) { + primary = CONSTANTS[this.consume().text]; + } else if (this.peek().identifier) { + primary = this.identifier(); + } else if (this.peek().constant) { + primary = this.constant(); + } else { + this.throwError('not a primary expression', this.peek()); + } + + var next, context; + while ((next = this.expect('(', '[', '.'))) { + if (next.text === '(') { + primary = this.functionCall(primary, context); + context = null; + } else if (next.text === '[') { + context = primary; + primary = this.objectIndex(primary); + } else if (next.text === '.') { + context = primary; + primary = this.fieldAccess(primary); + } else { + this.throwError('IMPOSSIBLE'); + } + } + return primary; + }, + + throwError: function(msg, token) { + throw $parseMinErr('syntax', + 'Syntax Error: Token \'{0}\' {1} at column {2} of the expression [{3}] starting at [{4}].', + token.text, msg, (token.index + 1), this.text, this.text.substring(token.index)); + }, + + peekToken: function() { + if (this.tokens.length === 0) + throw $parseMinErr('ueoe', 'Unexpected end of expression: {0}', this.text); + return this.tokens[0]; + }, + + peek: function(e1, e2, e3, e4) { + return this.peekAhead(0, e1, e2, e3, e4); + }, + peekAhead: function(i, e1, e2, e3, e4) { + if (this.tokens.length > i) { + var token = this.tokens[i]; + var t = token.text; + if (t === e1 || t === e2 || t === e3 || t === e4 || + (!e1 && !e2 && !e3 && !e4)) { + return token; + } + } + return false; + }, + + expect: function(e1, e2, e3, e4) { + var token = this.peek(e1, e2, e3, e4); + if (token) { + this.tokens.shift(); + return token; + } + return false; + }, + + consume: function(e1) { + if (this.tokens.length === 0) { + throw $parseMinErr('ueoe', 'Unexpected end of expression: {0}', this.text); + } + + var token = this.expect(e1); + if (!token) { + this.throwError('is unexpected, expecting [' + e1 + ']', this.peek()); + } + return token; + }, + + unaryFn: function(op, right) { + var fn = OPERATORS[op]; + return extend(function $parseUnaryFn(self, locals) { + return fn(self, locals, right); + }, { + constant:right.constant, + inputs: [right] + }); + }, + + binaryFn: function(left, op, right, isBranching) { + var fn = OPERATORS[op]; + return extend(function $parseBinaryFn(self, locals) { + return fn(self, locals, left, right); + }, { + constant: left.constant && right.constant, + inputs: !isBranching && [left, right] + }); + }, + + identifier: function() { + var id = this.consume().text; + + //Continue reading each `.identifier` unless it is a method invocation + while (this.peek('.') && this.peekAhead(1).identifier && !this.peekAhead(2, '(')) { + id += this.consume().text + this.consume().text; + } + + return getterFn(id, this.options, this.text); + }, + + constant: function() { + var value = this.consume().value; + + return extend(function $parseConstant() { + return value; + }, { + constant: true, + literal: true + }); + }, + + statements: function() { + var statements = []; + while (true) { + if (this.tokens.length > 0 && !this.peek('}', ')', ';', ']')) + statements.push(this.filterChain()); + if (!this.expect(';')) { + // optimize for the common case where there is only one statement. + // TODO(size): maybe we should not support multiple statements? + return (statements.length === 1) + ? statements[0] + : function $parseStatements(self, locals) { + var value; + for (var i = 0, ii = statements.length; i < ii; i++) { + value = statements[i](self, locals); + } + return value; + }; + } + } + }, + + filterChain: function() { + var left = this.expression(); + var token; + while ((token = this.expect('|'))) { + left = this.filter(left); + } + return left; + }, + + filter: function(inputFn) { + var fn = this.$filter(this.consume().text); + var argsFn; + var args; + + if (this.peek(':')) { + argsFn = []; + args = []; // we can safely reuse the array + while (this.expect(':')) { + argsFn.push(this.expression()); + } + } + + var inputs = [inputFn].concat(argsFn || []); + + return extend(function $parseFilter(self, locals) { + var input = inputFn(self, locals); + if (args) { + args[0] = input; + + var i = argsFn.length; + while (i--) { + args[i + 1] = argsFn[i](self, locals); + } + + return fn.apply(undefined, args); + } + + return fn(input); + }, { + constant: !fn.$stateful && inputs.every(isConstant), + inputs: !fn.$stateful && inputs + }); + }, + + expression: function() { + return this.assignment(); + }, + + assignment: function() { + var left = this.ternary(); + var right; + var token; + if ((token = this.expect('='))) { + if (!left.assign) { + this.throwError('implies assignment but [' + + this.text.substring(0, token.index) + '] can not be assigned to', token); + } + right = this.ternary(); + return extend(function $parseAssignment(scope, locals) { + return left.assign(scope, right(scope, locals), locals); + }, { + inputs: [left, right] + }); + } + return left; + }, + + ternary: function() { + var left = this.logicalOR(); + var middle; + var token; + if ((token = this.expect('?'))) { + middle = this.assignment(); + if (this.consume(':')) { + var right = this.assignment(); + + return extend(function $parseTernary(self, locals) { + return left(self, locals) ? middle(self, locals) : right(self, locals); + }, { + constant: left.constant && middle.constant && right.constant + }); + } + } + + return left; + }, + + logicalOR: function() { + var left = this.logicalAND(); + var token; + while ((token = this.expect('||'))) { + left = this.binaryFn(left, token.text, this.logicalAND(), true); + } + return left; + }, + + logicalAND: function() { + var left = this.equality(); + var token; + while ((token = this.expect('&&'))) { + left = this.binaryFn(left, token.text, this.equality(), true); + } + return left; + }, + + equality: function() { + var left = this.relational(); + var token; + while ((token = this.expect('==','!=','===','!=='))) { + left = this.binaryFn(left, token.text, this.relational()); + } + return left; + }, + + relational: function() { + var left = this.additive(); + var token; + while ((token = this.expect('<', '>', '<=', '>='))) { + left = this.binaryFn(left, token.text, this.additive()); + } + return left; + }, + + additive: function() { + var left = this.multiplicative(); + var token; + while ((token = this.expect('+','-'))) { + left = this.binaryFn(left, token.text, this.multiplicative()); + } + return left; + }, + + multiplicative: function() { + var left = this.unary(); + var token; + while ((token = this.expect('*','/','%'))) { + left = this.binaryFn(left, token.text, this.unary()); + } + return left; + }, + + unary: function() { + var token; + if (this.expect('+')) { + return this.primary(); + } else if ((token = this.expect('-'))) { + return this.binaryFn(Parser.ZERO, token.text, this.unary()); + } else if ((token = this.expect('!'))) { + return this.unaryFn(token.text, this.unary()); + } else { + return this.primary(); + } + }, + + fieldAccess: function(object) { + var getter = this.identifier(); + + return extend(function $parseFieldAccess(scope, locals, self) { + var o = self || object(scope, locals); + return (o == null) ? undefined : getter(o); + }, { + assign: function(scope, value, locals) { + var o = object(scope, locals); + if (!o) object.assign(scope, o = {}, locals); + return getter.assign(o, value); + } + }); + }, + + objectIndex: function(obj) { + var expression = this.text; + + var indexFn = this.expression(); + this.consume(']'); + + return extend(function $parseObjectIndex(self, locals) { + var o = obj(self, locals), + i = getStringValue(indexFn(self, locals), expression), + v; + + ensureSafeMemberName(i, expression); + if (!o) return undefined; + v = ensureSafeObject(o[i], expression); + return v; + }, { + assign: function(self, value, locals) { + var key = ensureSafeMemberName(getStringValue(indexFn(self, locals), expression), expression); + // prevent overwriting of Function.constructor which would break ensureSafeObject check + var o = ensureSafeObject(obj(self, locals), expression); + if (!o) obj.assign(self, o = {}, locals); + return o[key] = value; + } + }); + }, + + functionCall: function(fnGetter, contextGetter) { + var argsFn = []; + if (this.peekToken().text !== ')') { + do { + argsFn.push(this.expression()); + } while (this.expect(',')); + } + this.consume(')'); + + var expressionText = this.text; + // we can safely reuse the array across invocations + var args = argsFn.length ? [] : null; + + return function $parseFunctionCall(scope, locals) { + var context = contextGetter ? contextGetter(scope, locals) : isDefined(contextGetter) ? undefined : scope; + var fn = fnGetter(scope, locals, context) || noop; + + if (args) { + var i = argsFn.length; + while (i--) { + args[i] = ensureSafeObject(argsFn[i](scope, locals), expressionText); + } + } + + ensureSafeObject(context, expressionText); + ensureSafeFunction(fn, expressionText); + + // IE doesn't have apply for some native functions + var v = fn.apply + ? fn.apply(context, args) + : fn(args[0], args[1], args[2], args[3], args[4]); + + if (args) { + // Free-up the memory (arguments of the last function call). + args.length = 0; + } + + return ensureSafeObject(v, expressionText); + }; + }, + + // This is used with json array declaration + arrayDeclaration: function() { + var elementFns = []; + if (this.peekToken().text !== ']') { + do { + if (this.peek(']')) { + // Support trailing commas per ES5.1. + break; + } + elementFns.push(this.expression()); + } while (this.expect(',')); + } + this.consume(']'); + + return extend(function $parseArrayLiteral(self, locals) { + var array = []; + for (var i = 0, ii = elementFns.length; i < ii; i++) { + array.push(elementFns[i](self, locals)); + } + return array; + }, { + literal: true, + constant: elementFns.every(isConstant), + inputs: elementFns + }); + }, + + object: function() { + var keys = [], valueFns = []; + if (this.peekToken().text !== '}') { + do { + if (this.peek('}')) { + // Support trailing commas per ES5.1. + break; + } + var token = this.consume(); + if (token.constant) { + keys.push(token.value); + } else if (token.identifier) { + keys.push(token.text); + } else { + this.throwError("invalid key", token); + } + this.consume(':'); + valueFns.push(this.expression()); + } while (this.expect(',')); + } + this.consume('}'); + + return extend(function $parseObjectLiteral(self, locals) { + var object = {}; + for (var i = 0, ii = valueFns.length; i < ii; i++) { + object[keys[i]] = valueFns[i](self, locals); + } + return object; + }, { + literal: true, + constant: valueFns.every(isConstant), + inputs: valueFns + }); + } +}; + + +////////////////////////////////////////////////// +// Parser helper functions +////////////////////////////////////////////////// + +function setter(obj, locals, path, setValue, fullExp) { + ensureSafeObject(obj, fullExp); + ensureSafeObject(locals, fullExp); + + var element = path.split('.'), key; + for (var i = 0; element.length > 1; i++) { + key = ensureSafeMemberName(element.shift(), fullExp); + var propertyObj = (i === 0 && locals && locals[key]) || obj[key]; + if (!propertyObj) { + propertyObj = {}; + obj[key] = propertyObj; + } + obj = ensureSafeObject(propertyObj, fullExp); + } + key = ensureSafeMemberName(element.shift(), fullExp); + ensureSafeObject(obj[key], fullExp); + obj[key] = setValue; + return setValue; +} + +var getterFnCacheDefault = createMap(); +var getterFnCacheExpensive = createMap(); + +function isPossiblyDangerousMemberName(name) { + return name == 'constructor'; +} + +/** + * Implementation of the "Black Hole" variant from: + * - http://jsperf.com/angularjs-parse-getter/4 + * - http://jsperf.com/path-evaluation-simplified/7 + */ +function cspSafeGetterFn(key0, key1, key2, key3, key4, fullExp, expensiveChecks) { + ensureSafeMemberName(key0, fullExp); + ensureSafeMemberName(key1, fullExp); + ensureSafeMemberName(key2, fullExp); + ensureSafeMemberName(key3, fullExp); + ensureSafeMemberName(key4, fullExp); + var eso = function(o) { + return ensureSafeObject(o, fullExp); + }; + var eso0 = (expensiveChecks || isPossiblyDangerousMemberName(key0)) ? eso : identity; + var eso1 = (expensiveChecks || isPossiblyDangerousMemberName(key1)) ? eso : identity; + var eso2 = (expensiveChecks || isPossiblyDangerousMemberName(key2)) ? eso : identity; + var eso3 = (expensiveChecks || isPossiblyDangerousMemberName(key3)) ? eso : identity; + var eso4 = (expensiveChecks || isPossiblyDangerousMemberName(key4)) ? eso : identity; + + return function cspSafeGetter(scope, locals) { + var pathVal = (locals && locals.hasOwnProperty(key0)) ? locals : scope; + + if (pathVal == null) return pathVal; + pathVal = eso0(pathVal[key0]); + + if (!key1) return pathVal; + if (pathVal == null) return undefined; + pathVal = eso1(pathVal[key1]); + + if (!key2) return pathVal; + if (pathVal == null) return undefined; + pathVal = eso2(pathVal[key2]); + + if (!key3) return pathVal; + if (pathVal == null) return undefined; + pathVal = eso3(pathVal[key3]); + + if (!key4) return pathVal; + if (pathVal == null) return undefined; + pathVal = eso4(pathVal[key4]); + + return pathVal; + }; +} + +function getterFnWithEnsureSafeObject(fn, fullExpression) { + return function(s, l) { + return fn(s, l, ensureSafeObject, fullExpression); + }; +} + +function getterFn(path, options, fullExp) { + var expensiveChecks = options.expensiveChecks; + var getterFnCache = (expensiveChecks ? getterFnCacheExpensive : getterFnCacheDefault); + var fn = getterFnCache[path]; + if (fn) return fn; + + + var pathKeys = path.split('.'), + pathKeysLength = pathKeys.length; + + // http://jsperf.com/angularjs-parse-getter/6 + if (options.csp) { + if (pathKeysLength < 6) { + fn = cspSafeGetterFn(pathKeys[0], pathKeys[1], pathKeys[2], pathKeys[3], pathKeys[4], fullExp, expensiveChecks); + } else { + fn = function cspSafeGetter(scope, locals) { + var i = 0, val; + do { + val = cspSafeGetterFn(pathKeys[i++], pathKeys[i++], pathKeys[i++], pathKeys[i++], + pathKeys[i++], fullExp, expensiveChecks)(scope, locals); + + locals = undefined; // clear after first iteration + scope = val; + } while (i < pathKeysLength); + return val; + }; + } + } else { + var code = ''; + if (expensiveChecks) { + code += 's = eso(s, fe);\nl = eso(l, fe);\n'; + } + var needsEnsureSafeObject = expensiveChecks; + forEach(pathKeys, function(key, index) { + ensureSafeMemberName(key, fullExp); + var lookupJs = (index + // we simply dereference 's' on any .dot notation + ? 's' + // but if we are first then we check locals first, and if so read it first + : '((l&&l.hasOwnProperty("' + key + '"))?l:s)') + '.' + key; + if (expensiveChecks || isPossiblyDangerousMemberName(key)) { + lookupJs = 'eso(' + lookupJs + ', fe)'; + needsEnsureSafeObject = true; + } + code += 'if(s == null) return undefined;\n' + + 's=' + lookupJs + ';\n'; + }); + code += 'return s;'; + + /* jshint -W054 */ + var evaledFnGetter = new Function('s', 'l', 'eso', 'fe', code); // s=scope, l=locals, eso=ensureSafeObject + /* jshint +W054 */ + evaledFnGetter.toString = valueFn(code); + if (needsEnsureSafeObject) { + evaledFnGetter = getterFnWithEnsureSafeObject(evaledFnGetter, fullExp); + } + fn = evaledFnGetter; + } + + fn.sharedGetter = true; + fn.assign = function(self, value, locals) { + return setter(self, locals, path, value, path); + }; + getterFnCache[path] = fn; + return fn; +} + +var objectValueOf = Object.prototype.valueOf; + +function getValueOf(value) { + return isFunction(value.valueOf) ? value.valueOf() : objectValueOf.call(value); +} + +/////////////////////////////////// + +/** + * @ngdoc service + * @name $parse + * @kind function + * + * @description + * + * Converts Angular {@link guide/expression expression} into a function. + * + * ```js + * var getter = $parse('user.name'); + * var setter = getter.assign; + * var context = {user:{name:'angular'}}; + * var locals = {user:{name:'local'}}; + * + * expect(getter(context)).toEqual('angular'); + * setter(context, 'newValue'); + * expect(context.user.name).toEqual('newValue'); + * expect(getter(context, locals)).toEqual('local'); + * ``` + * + * + * @param {string} expression String expression to compile. + * @returns {function(context, locals)} a function which represents the compiled expression: + * + * * `context` – `{object}` – an object against which any expressions embedded in the strings + * are evaluated against (typically a scope object). + * * `locals` – `{object=}` – local variables context object, useful for overriding values in + * `context`. + * + * The returned function also has the following properties: + * * `literal` – `{boolean}` – whether the expression's top-level node is a JavaScript + * literal. + * * `constant` – `{boolean}` – whether the expression is made entirely of JavaScript + * constant literals. + * * `assign` – `{?function(context, value)}` – if the expression is assignable, this will be + * set to a function to change its value on the given context. + * + */ + + +/** + * @ngdoc provider + * @name $parseProvider + * + * @description + * `$parseProvider` can be used for configuring the default behavior of the {@link ng.$parse $parse} + * service. + */ +function $ParseProvider() { + var cacheDefault = createMap(); + var cacheExpensive = createMap(); + + + + this.$get = ['$filter', '$sniffer', function($filter, $sniffer) { + var $parseOptions = { + csp: $sniffer.csp, + expensiveChecks: false + }, + $parseOptionsExpensive = { + csp: $sniffer.csp, + expensiveChecks: true + }; + + function wrapSharedExpression(exp) { + var wrapped = exp; + + if (exp.sharedGetter) { + wrapped = function $parseWrapper(self, locals) { + return exp(self, locals); + }; + wrapped.literal = exp.literal; + wrapped.constant = exp.constant; + wrapped.assign = exp.assign; + } + + return wrapped; + } + + return function $parse(exp, interceptorFn, expensiveChecks) { + var parsedExpression, oneTime, cacheKey; + + switch (typeof exp) { + case 'string': + cacheKey = exp = exp.trim(); + + var cache = (expensiveChecks ? cacheExpensive : cacheDefault); + parsedExpression = cache[cacheKey]; + + if (!parsedExpression) { + if (exp.charAt(0) === ':' && exp.charAt(1) === ':') { + oneTime = true; + exp = exp.substring(2); + } + + var parseOptions = expensiveChecks ? $parseOptionsExpensive : $parseOptions; + var lexer = new Lexer(parseOptions); + var parser = new Parser(lexer, $filter, parseOptions); + parsedExpression = parser.parse(exp); + + if (parsedExpression.constant) { + parsedExpression.$$watchDelegate = constantWatchDelegate; + } else if (oneTime) { + //oneTime is not part of the exp passed to the Parser so we may have to + //wrap the parsedExpression before adding a $$watchDelegate + parsedExpression = wrapSharedExpression(parsedExpression); + parsedExpression.$$watchDelegate = parsedExpression.literal ? + oneTimeLiteralWatchDelegate : oneTimeWatchDelegate; + } else if (parsedExpression.inputs) { + parsedExpression.$$watchDelegate = inputsWatchDelegate; + } + + cache[cacheKey] = parsedExpression; + } + return addInterceptor(parsedExpression, interceptorFn); + + case 'function': + return addInterceptor(exp, interceptorFn); + + default: + return addInterceptor(noop, interceptorFn); + } + }; + + function collectExpressionInputs(inputs, list) { + for (var i = 0, ii = inputs.length; i < ii; i++) { + var input = inputs[i]; + if (!input.constant) { + if (input.inputs) { + collectExpressionInputs(input.inputs, list); + } else if (list.indexOf(input) === -1) { // TODO(perf) can we do better? + list.push(input); + } + } + } + + return list; + } + + function expressionInputDirtyCheck(newValue, oldValueOfValue) { + + if (newValue == null || oldValueOfValue == null) { // null/undefined + return newValue === oldValueOfValue; + } + + if (typeof newValue === 'object') { + + // attempt to convert the value to a primitive type + // TODO(docs): add a note to docs that by implementing valueOf even objects and arrays can + // be cheaply dirty-checked + newValue = getValueOf(newValue); + + if (typeof newValue === 'object') { + // objects/arrays are not supported - deep-watching them would be too expensive + return false; + } + + // fall-through to the primitive equality check + } + + //Primitive or NaN + return newValue === oldValueOfValue || (newValue !== newValue && oldValueOfValue !== oldValueOfValue); + } + + function inputsWatchDelegate(scope, listener, objectEquality, parsedExpression) { + var inputExpressions = parsedExpression.$$inputs || + (parsedExpression.$$inputs = collectExpressionInputs(parsedExpression.inputs, [])); + + var lastResult; + + if (inputExpressions.length === 1) { + var oldInputValue = expressionInputDirtyCheck; // init to something unique so that equals check fails + inputExpressions = inputExpressions[0]; + return scope.$watch(function expressionInputWatch(scope) { + var newInputValue = inputExpressions(scope); + if (!expressionInputDirtyCheck(newInputValue, oldInputValue)) { + lastResult = parsedExpression(scope); + oldInputValue = newInputValue && getValueOf(newInputValue); + } + return lastResult; + }, listener, objectEquality); + } + + var oldInputValueOfValues = []; + for (var i = 0, ii = inputExpressions.length; i < ii; i++) { + oldInputValueOfValues[i] = expressionInputDirtyCheck; // init to something unique so that equals check fails + } + + return scope.$watch(function expressionInputsWatch(scope) { + var changed = false; + + for (var i = 0, ii = inputExpressions.length; i < ii; i++) { + var newInputValue = inputExpressions[i](scope); + if (changed || (changed = !expressionInputDirtyCheck(newInputValue, oldInputValueOfValues[i]))) { + oldInputValueOfValues[i] = newInputValue && getValueOf(newInputValue); + } + } + + if (changed) { + lastResult = parsedExpression(scope); + } + + return lastResult; + }, listener, objectEquality); + } + + function oneTimeWatchDelegate(scope, listener, objectEquality, parsedExpression) { + var unwatch, lastValue; + return unwatch = scope.$watch(function oneTimeWatch(scope) { + return parsedExpression(scope); + }, function oneTimeListener(value, old, scope) { + lastValue = value; + if (isFunction(listener)) { + listener.apply(this, arguments); + } + if (isDefined(value)) { + scope.$$postDigest(function() { + if (isDefined(lastValue)) { + unwatch(); + } + }); + } + }, objectEquality); + } + + function oneTimeLiteralWatchDelegate(scope, listener, objectEquality, parsedExpression) { + var unwatch, lastValue; + return unwatch = scope.$watch(function oneTimeWatch(scope) { + return parsedExpression(scope); + }, function oneTimeListener(value, old, scope) { + lastValue = value; + if (isFunction(listener)) { + listener.call(this, value, old, scope); + } + if (isAllDefined(value)) { + scope.$$postDigest(function() { + if (isAllDefined(lastValue)) unwatch(); + }); + } + }, objectEquality); + + function isAllDefined(value) { + var allDefined = true; + forEach(value, function(val) { + if (!isDefined(val)) allDefined = false; + }); + return allDefined; + } + } + + function constantWatchDelegate(scope, listener, objectEquality, parsedExpression) { + var unwatch; + return unwatch = scope.$watch(function constantWatch(scope) { + return parsedExpression(scope); + }, function constantListener(value, old, scope) { + if (isFunction(listener)) { + listener.apply(this, arguments); + } + unwatch(); + }, objectEquality); + } + + function addInterceptor(parsedExpression, interceptorFn) { + if (!interceptorFn) return parsedExpression; + var watchDelegate = parsedExpression.$$watchDelegate; + + var regularWatch = + watchDelegate !== oneTimeLiteralWatchDelegate && + watchDelegate !== oneTimeWatchDelegate; + + var fn = regularWatch ? function regularInterceptedExpression(scope, locals) { + var value = parsedExpression(scope, locals); + return interceptorFn(value, scope, locals); + } : function oneTimeInterceptedExpression(scope, locals) { + var value = parsedExpression(scope, locals); + var result = interceptorFn(value, scope, locals); + // we only return the interceptor's result if the + // initial value is defined (for bind-once) + return isDefined(value) ? result : value; + }; + + // Propagate $$watchDelegates other then inputsWatchDelegate + if (parsedExpression.$$watchDelegate && + parsedExpression.$$watchDelegate !== inputsWatchDelegate) { + fn.$$watchDelegate = parsedExpression.$$watchDelegate; + } else if (!interceptorFn.$stateful) { + // If there is an interceptor, but no watchDelegate then treat the interceptor like + // we treat filters - it is assumed to be a pure function unless flagged with $stateful + fn.$$watchDelegate = inputsWatchDelegate; + fn.inputs = [parsedExpression]; + } + + return fn; + } + }]; +} + +/** + * @ngdoc service + * @name $q + * @requires $rootScope + * + * @description + * A service that helps you run functions asynchronously, and use their return values (or exceptions) + * when they are done processing. + * + * This is an implementation of promises/deferred objects inspired by + * [Kris Kowal's Q](https://github.com/kriskowal/q). + * + * $q can be used in two fashions --- one which is more similar to Kris Kowal's Q or jQuery's Deferred + * implementations, and the other which resembles ES6 promises to some degree. + * + * # $q constructor + * + * The streamlined ES6 style promise is essentially just using $q as a constructor which takes a `resolver` + * function as the first argument. This is similar to the native Promise implementation from ES6 Harmony, + * see [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). + * + * While the constructor-style use is supported, not all of the supporting methods from ES6 Harmony promises are + * available yet. + * + * It can be used like so: + * + * ```js + * // for the purpose of this example let's assume that variables `$q` and `okToGreet` + * // are available in the current lexical scope (they could have been injected or passed in). + * + * function asyncGreet(name) { + * // perform some asynchronous operation, resolve or reject the promise when appropriate. + * return $q(function(resolve, reject) { + * setTimeout(function() { + * if (okToGreet(name)) { + * resolve('Hello, ' + name + '!'); + * } else { + * reject('Greeting ' + name + ' is not allowed.'); + * } + * }, 1000); + * }); + * } + * + * var promise = asyncGreet('Robin Hood'); + * promise.then(function(greeting) { + * alert('Success: ' + greeting); + * }, function(reason) { + * alert('Failed: ' + reason); + * }); + * ``` + * + * Note: progress/notify callbacks are not currently supported via the ES6-style interface. + * + * However, the more traditional CommonJS-style usage is still available, and documented below. + * + * [The CommonJS Promise proposal](http://wiki.commonjs.org/wiki/Promises) describes a promise as an + * interface for interacting with an object that represents the result of an action that is + * performed asynchronously, and may or may not be finished at any given point in time. + * + * From the perspective of dealing with error handling, deferred and promise APIs are to + * asynchronous programming what `try`, `catch` and `throw` keywords are to synchronous programming. + * + * ```js + * // for the purpose of this example let's assume that variables `$q` and `okToGreet` + * // are available in the current lexical scope (they could have been injected or passed in). + * + * function asyncGreet(name) { + * var deferred = $q.defer(); + * + * setTimeout(function() { + * deferred.notify('About to greet ' + name + '.'); + * + * if (okToGreet(name)) { + * deferred.resolve('Hello, ' + name + '!'); + * } else { + * deferred.reject('Greeting ' + name + ' is not allowed.'); + * } + * }, 1000); + * + * return deferred.promise; + * } + * + * var promise = asyncGreet('Robin Hood'); + * promise.then(function(greeting) { + * alert('Success: ' + greeting); + * }, function(reason) { + * alert('Failed: ' + reason); + * }, function(update) { + * alert('Got notification: ' + update); + * }); + * ``` + * + * At first it might not be obvious why this extra complexity is worth the trouble. The payoff + * comes in the way of guarantees that promise and deferred APIs make, see + * https://github.com/kriskowal/uncommonjs/blob/master/promises/specification.md. + * + * Additionally the promise api allows for composition that is very hard to do with the + * traditional callback ([CPS](http://en.wikipedia.org/wiki/Continuation-passing_style)) approach. + * For more on this please see the [Q documentation](https://github.com/kriskowal/q) especially the + * section on serial or parallel joining of promises. + * + * # The Deferred API + * + * A new instance of deferred is constructed by calling `$q.defer()`. + * + * The purpose of the deferred object is to expose the associated Promise instance as well as APIs + * that can be used for signaling the successful or unsuccessful completion, as well as the status + * of the task. + * + * **Methods** + * + * - `resolve(value)` – resolves the derived promise with the `value`. If the value is a rejection + * constructed via `$q.reject`, the promise will be rejected instead. + * - `reject(reason)` – rejects the derived promise with the `reason`. This is equivalent to + * resolving it with a rejection constructed via `$q.reject`. + * - `notify(value)` - provides updates on the status of the promise's execution. This may be called + * multiple times before the promise is either resolved or rejected. + * + * **Properties** + * + * - promise – `{Promise}` – promise object associated with this deferred. + * + * + * # The Promise API + * + * A new promise instance is created when a deferred instance is created and can be retrieved by + * calling `deferred.promise`. + * + * The purpose of the promise object is to allow for interested parties to get access to the result + * of the deferred task when it completes. + * + * **Methods** + * + * - `then(successCallback, errorCallback, notifyCallback)` – regardless of when the promise was or + * will be resolved or rejected, `then` calls one of the success or error callbacks asynchronously + * as soon as the result is available. The callbacks are called with a single argument: the result + * or rejection reason. Additionally, the notify callback may be called zero or more times to + * provide a progress indication, before the promise is resolved or rejected. + * + * This method *returns a new promise* which is resolved or rejected via the return value of the + * `successCallback`, `errorCallback`. It also notifies via the return value of the + * `notifyCallback` method. The promise cannot be resolved or rejected from the notifyCallback + * method. + * + * - `catch(errorCallback)` – shorthand for `promise.then(null, errorCallback)` + * + * - `finally(callback, notifyCallback)` – allows you to observe either the fulfillment or rejection of a promise, + * but to do so without modifying the final value. This is useful to release resources or do some + * clean-up that needs to be done whether the promise was rejected or resolved. See the [full + * specification](https://github.com/kriskowal/q/wiki/API-Reference#promisefinallycallback) for + * more information. + * + * # Chaining promises + * + * Because calling the `then` method of a promise returns a new derived promise, it is easily + * possible to create a chain of promises: + * + * ```js + * promiseB = promiseA.then(function(result) { + * return result + 1; + * }); + * + * // promiseB will be resolved immediately after promiseA is resolved and its value + * // will be the result of promiseA incremented by 1 + * ``` + * + * It is possible to create chains of any length and since a promise can be resolved with another + * promise (which will defer its resolution further), it is possible to pause/defer resolution of + * the promises at any point in the chain. This makes it possible to implement powerful APIs like + * $http's response interceptors. + * + * + * # Differences between Kris Kowal's Q and $q + * + * There are two main differences: + * + * - $q is integrated with the {@link ng.$rootScope.Scope} Scope model observation + * mechanism in angular, which means faster propagation of resolution or rejection into your + * models and avoiding unnecessary browser repaints, which would result in flickering UI. + * - Q has many more features than $q, but that comes at a cost of bytes. $q is tiny, but contains + * all the important functionality needed for common async tasks. + * + * # Testing + * + * ```js + * it('should simulate promise', inject(function($q, $rootScope) { + * var deferred = $q.defer(); + * var promise = deferred.promise; + * var resolvedValue; + * + * promise.then(function(value) { resolvedValue = value; }); + * expect(resolvedValue).toBeUndefined(); + * + * // Simulate resolving of promise + * deferred.resolve(123); + * // Note that the 'then' function does not get called synchronously. + * // This is because we want the promise API to always be async, whether or not + * // it got called synchronously or asynchronously. + * expect(resolvedValue).toBeUndefined(); + * + * // Propagate promise resolution to 'then' functions using $apply(). + * $rootScope.$apply(); + * expect(resolvedValue).toEqual(123); + * })); + * ``` + * + * @param {function(function, function)} resolver Function which is responsible for resolving or + * rejecting the newly created promise. The first parameter is a function which resolves the + * promise, the second parameter is a function which rejects the promise. + * + * @returns {Promise} The newly created promise. + */ +function $QProvider() { + + this.$get = ['$rootScope', '$exceptionHandler', function($rootScope, $exceptionHandler) { + return qFactory(function(callback) { + $rootScope.$evalAsync(callback); + }, $exceptionHandler); + }]; +} + +function $$QProvider() { + this.$get = ['$browser', '$exceptionHandler', function($browser, $exceptionHandler) { + return qFactory(function(callback) { + $browser.defer(callback); + }, $exceptionHandler); + }]; +} + +/** + * Constructs a promise manager. + * + * @param {function(function)} nextTick Function for executing functions in the next turn. + * @param {function(...*)} exceptionHandler Function into which unexpected exceptions are passed for + * debugging purposes. + * @returns {object} Promise manager. + */ +function qFactory(nextTick, exceptionHandler) { + var $qMinErr = minErr('$q', TypeError); + function callOnce(self, resolveFn, rejectFn) { + var called = false; + function wrap(fn) { + return function(value) { + if (called) return; + called = true; + fn.call(self, value); + }; + } + + return [wrap(resolveFn), wrap(rejectFn)]; + } + + /** + * @ngdoc method + * @name ng.$q#defer + * @kind function + * + * @description + * Creates a `Deferred` object which represents a task which will finish in the future. + * + * @returns {Deferred} Returns a new instance of deferred. + */ + var defer = function() { + return new Deferred(); + }; + + function Promise() { + this.$$state = { status: 0 }; + } + + Promise.prototype = { + then: function(onFulfilled, onRejected, progressBack) { + var result = new Deferred(); + + this.$$state.pending = this.$$state.pending || []; + this.$$state.pending.push([result, onFulfilled, onRejected, progressBack]); + if (this.$$state.status > 0) scheduleProcessQueue(this.$$state); + + return result.promise; + }, + + "catch": function(callback) { + return this.then(null, callback); + }, + + "finally": function(callback, progressBack) { + return this.then(function(value) { + return handleCallback(value, true, callback); + }, function(error) { + return handleCallback(error, false, callback); + }, progressBack); + } + }; + + //Faster, more basic than angular.bind http://jsperf.com/angular-bind-vs-custom-vs-native + function simpleBind(context, fn) { + return function(value) { + fn.call(context, value); + }; + } + + function processQueue(state) { + var fn, promise, pending; + + pending = state.pending; + state.processScheduled = false; + state.pending = undefined; + for (var i = 0, ii = pending.length; i < ii; ++i) { + promise = pending[i][0]; + fn = pending[i][state.status]; + try { + if (isFunction(fn)) { + promise.resolve(fn(state.value)); + } else if (state.status === 1) { + promise.resolve(state.value); + } else { + promise.reject(state.value); + } + } catch (e) { + promise.reject(e); + exceptionHandler(e); + } + } + } + + function scheduleProcessQueue(state) { + if (state.processScheduled || !state.pending) return; + state.processScheduled = true; + nextTick(function() { processQueue(state); }); + } + + function Deferred() { + this.promise = new Promise(); + //Necessary to support unbound execution :/ + this.resolve = simpleBind(this, this.resolve); + this.reject = simpleBind(this, this.reject); + this.notify = simpleBind(this, this.notify); + } + + Deferred.prototype = { + resolve: function(val) { + if (this.promise.$$state.status) return; + if (val === this.promise) { + this.$$reject($qMinErr( + 'qcycle', + "Expected promise to be resolved with value other than itself '{0}'", + val)); + } else { + this.$$resolve(val); + } + + }, + + $$resolve: function(val) { + var then, fns; + + fns = callOnce(this, this.$$resolve, this.$$reject); + try { + if ((isObject(val) || isFunction(val))) then = val && val.then; + if (isFunction(then)) { + this.promise.$$state.status = -1; + then.call(val, fns[0], fns[1], this.notify); + } else { + this.promise.$$state.value = val; + this.promise.$$state.status = 1; + scheduleProcessQueue(this.promise.$$state); + } + } catch (e) { + fns[1](e); + exceptionHandler(e); + } + }, + + reject: function(reason) { + if (this.promise.$$state.status) return; + this.$$reject(reason); + }, + + $$reject: function(reason) { + this.promise.$$state.value = reason; + this.promise.$$state.status = 2; + scheduleProcessQueue(this.promise.$$state); + }, + + notify: function(progress) { + var callbacks = this.promise.$$state.pending; + + if ((this.promise.$$state.status <= 0) && callbacks && callbacks.length) { + nextTick(function() { + var callback, result; + for (var i = 0, ii = callbacks.length; i < ii; i++) { + result = callbacks[i][0]; + callback = callbacks[i][3]; + try { + result.notify(isFunction(callback) ? callback(progress) : progress); + } catch (e) { + exceptionHandler(e); + } + } + }); + } + } + }; + + /** + * @ngdoc method + * @name $q#reject + * @kind function + * + * @description + * Creates a promise that is resolved as rejected with the specified `reason`. This api should be + * used to forward rejection in a chain of promises. If you are dealing with the last promise in + * a promise chain, you don't need to worry about it. + * + * When comparing deferreds/promises to the familiar behavior of try/catch/throw, think of + * `reject` as the `throw` keyword in JavaScript. This also means that if you "catch" an error via + * a promise error callback and you want to forward the error to the promise derived from the + * current promise, you have to "rethrow" the error by returning a rejection constructed via + * `reject`. + * + * ```js + * promiseB = promiseA.then(function(result) { + * // success: do something and resolve promiseB + * // with the old or a new result + * return result; + * }, function(reason) { + * // error: handle the error if possible and + * // resolve promiseB with newPromiseOrValue, + * // otherwise forward the rejection to promiseB + * if (canHandle(reason)) { + * // handle the error and recover + * return newPromiseOrValue; + * } + * return $q.reject(reason); + * }); + * ``` + * + * @param {*} reason Constant, message, exception or an object representing the rejection reason. + * @returns {Promise} Returns a promise that was already resolved as rejected with the `reason`. + */ + var reject = function(reason) { + var result = new Deferred(); + result.reject(reason); + return result.promise; + }; + + var makePromise = function makePromise(value, resolved) { + var result = new Deferred(); + if (resolved) { + result.resolve(value); + } else { + result.reject(value); + } + return result.promise; + }; + + var handleCallback = function handleCallback(value, isResolved, callback) { + var callbackOutput = null; + try { + if (isFunction(callback)) callbackOutput = callback(); + } catch (e) { + return makePromise(e, false); + } + if (isPromiseLike(callbackOutput)) { + return callbackOutput.then(function() { + return makePromise(value, isResolved); + }, function(error) { + return makePromise(error, false); + }); + } else { + return makePromise(value, isResolved); + } + }; + + /** + * @ngdoc method + * @name $q#when + * @kind function + * + * @description + * Wraps an object that might be a value or a (3rd party) then-able promise into a $q promise. + * This is useful when you are dealing with an object that might or might not be a promise, or if + * the promise comes from a source that can't be trusted. + * + * @param {*} value Value or a promise + * @returns {Promise} Returns a promise of the passed value or promise + */ + + + var when = function(value, callback, errback, progressBack) { + var result = new Deferred(); + result.resolve(value); + return result.promise.then(callback, errback, progressBack); + }; + + /** + * @ngdoc method + * @name $q#all + * @kind function + * + * @description + * Combines multiple promises into a single promise that is resolved when all of the input + * promises are resolved. + * + * @param {Array.|Object.} promises An array or hash of promises. + * @returns {Promise} Returns a single promise that will be resolved with an array/hash of values, + * each value corresponding to the promise at the same index/key in the `promises` array/hash. + * If any of the promises is resolved with a rejection, this resulting promise will be rejected + * with the same rejection value. + */ + + function all(promises) { + var deferred = new Deferred(), + counter = 0, + results = isArray(promises) ? [] : {}; + + forEach(promises, function(promise, key) { + counter++; + when(promise).then(function(value) { + if (results.hasOwnProperty(key)) return; + results[key] = value; + if (!(--counter)) deferred.resolve(results); + }, function(reason) { + if (results.hasOwnProperty(key)) return; + deferred.reject(reason); + }); + }); + + if (counter === 0) { + deferred.resolve(results); + } + + return deferred.promise; + } + + var $Q = function Q(resolver) { + if (!isFunction(resolver)) { + throw $qMinErr('norslvr', "Expected resolverFn, got '{0}'", resolver); + } + + if (!(this instanceof Q)) { + // More useful when $Q is the Promise itself. + return new Q(resolver); + } + + var deferred = new Deferred(); + + function resolveFn(value) { + deferred.resolve(value); + } + + function rejectFn(reason) { + deferred.reject(reason); + } + + resolver(resolveFn, rejectFn); + + return deferred.promise; + }; + + $Q.defer = defer; + $Q.reject = reject; + $Q.when = when; + $Q.all = all; + + return $Q; +} + +function $$RAFProvider() { //rAF + this.$get = ['$window', '$timeout', function($window, $timeout) { + var requestAnimationFrame = $window.requestAnimationFrame || + $window.webkitRequestAnimationFrame; + + var cancelAnimationFrame = $window.cancelAnimationFrame || + $window.webkitCancelAnimationFrame || + $window.webkitCancelRequestAnimationFrame; + + var rafSupported = !!requestAnimationFrame; + var rafFn = rafSupported + ? function(fn) { + var id = requestAnimationFrame(fn); + return function() { + cancelAnimationFrame(id); + }; + } + : function(fn) { + var timer = $timeout(fn, 16.66, false); // 1000 / 60 = 16.666 + return function() { + $timeout.cancel(timer); + }; + }; + + queueFn.supported = rafSupported; + + var cancelLastRAF; + var taskCount = 0; + var taskQueue = []; + return queueFn; + + function flush() { + for (var i = 0; i < taskQueue.length; i++) { + var task = taskQueue[i]; + if (task) { + taskQueue[i] = null; + task(); + } + } + taskCount = taskQueue.length = 0; + } + + function queueFn(asyncFn) { + var index = taskQueue.length; + + taskCount++; + taskQueue.push(asyncFn); + + if (index === 0) { + cancelLastRAF = rafFn(flush); + } + + return function cancelQueueFn() { + if (index >= 0) { + taskQueue[index] = null; + index = null; + + if (--taskCount === 0 && cancelLastRAF) { + cancelLastRAF(); + cancelLastRAF = null; + taskQueue.length = 0; + } + } + }; + } + }]; +} + +/** + * DESIGN NOTES + * + * The design decisions behind the scope are heavily favored for speed and memory consumption. + * + * The typical use of scope is to watch the expressions, which most of the time return the same + * value as last time so we optimize the operation. + * + * Closures construction is expensive in terms of speed as well as memory: + * - No closures, instead use prototypical inheritance for API + * - Internal state needs to be stored on scope directly, which means that private state is + * exposed as $$____ properties + * + * Loop operations are optimized by using while(count--) { ... } + * - this means that in order to keep the same order of execution as addition we have to add + * items to the array at the beginning (unshift) instead of at the end (push) + * + * Child scopes are created and removed often + * - Using an array would be slow since inserts in middle are expensive so we use linked list + * + * There are few watches then a lot of observers. This is why you don't want the observer to be + * implemented in the same way as watch. Watch requires return of initialization function which + * are expensive to construct. + */ + + +/** + * @ngdoc provider + * @name $rootScopeProvider + * @description + * + * Provider for the $rootScope service. + */ + +/** + * @ngdoc method + * @name $rootScopeProvider#digestTtl + * @description + * + * Sets the number of `$digest` iterations the scope should attempt to execute before giving up and + * assuming that the model is unstable. + * + * The current default is 10 iterations. + * + * In complex applications it's possible that the dependencies between `$watch`s will result in + * several digest iterations. However if an application needs more than the default 10 digest + * iterations for its model to stabilize then you should investigate what is causing the model to + * continuously change during the digest. + * + * Increasing the TTL could have performance implications, so you should not change it without + * proper justification. + * + * @param {number} limit The number of digest iterations. + */ + + +/** + * @ngdoc service + * @name $rootScope + * @description + * + * Every application has a single root {@link ng.$rootScope.Scope scope}. + * All other scopes are descendant scopes of the root scope. Scopes provide separation + * between the model and the view, via a mechanism for watching the model for changes. + * They also provide an event emission/broadcast and subscription facility. See the + * {@link guide/scope developer guide on scopes}. + */ +function $RootScopeProvider() { + var TTL = 10; + var $rootScopeMinErr = minErr('$rootScope'); + var lastDirtyWatch = null; + var applyAsyncId = null; + + this.digestTtl = function(value) { + if (arguments.length) { + TTL = value; + } + return TTL; + }; + + function createChildScopeClass(parent) { + function ChildScope() { + this.$$watchers = this.$$nextSibling = + this.$$childHead = this.$$childTail = null; + this.$$listeners = {}; + this.$$listenerCount = {}; + this.$id = nextUid(); + this.$$ChildScope = null; + } + ChildScope.prototype = parent; + return ChildScope; + } + + this.$get = ['$injector', '$exceptionHandler', '$parse', '$browser', + function($injector, $exceptionHandler, $parse, $browser) { + + function destroyChildScope($event) { + $event.currentScope.$$destroyed = true; + } + + /** + * @ngdoc type + * @name $rootScope.Scope + * + * @description + * A root scope can be retrieved using the {@link ng.$rootScope $rootScope} key from the + * {@link auto.$injector $injector}. Child scopes are created using the + * {@link ng.$rootScope.Scope#$new $new()} method. (Most scopes are created automatically when + * compiled HTML template is executed.) See also the {@link guide/scope Scopes guide} for + * an in-depth introduction and usage examples. + * + * + * # Inheritance + * A scope can inherit from a parent scope, as in this example: + * ```js + var parent = $rootScope; + var child = parent.$new(); + + parent.salutation = "Hello"; + expect(child.salutation).toEqual('Hello'); + + child.salutation = "Welcome"; + expect(child.salutation).toEqual('Welcome'); + expect(parent.salutation).toEqual('Hello'); + * ``` + * + * When interacting with `Scope` in tests, additional helper methods are available on the + * instances of `Scope` type. See {@link ngMock.$rootScope.Scope ngMock Scope} for additional + * details. + * + * + * @param {Object.=} providers Map of service factory which need to be + * provided for the current scope. Defaults to {@link ng}. + * @param {Object.=} instanceCache Provides pre-instantiated services which should + * append/override services provided by `providers`. This is handy + * when unit-testing and having the need to override a default + * service. + * @returns {Object} Newly created scope. + * + */ + function Scope() { + this.$id = nextUid(); + this.$$phase = this.$parent = this.$$watchers = + this.$$nextSibling = this.$$prevSibling = + this.$$childHead = this.$$childTail = null; + this.$root = this; + this.$$destroyed = false; + this.$$listeners = {}; + this.$$listenerCount = {}; + this.$$isolateBindings = null; + } + + /** + * @ngdoc property + * @name $rootScope.Scope#$id + * + * @description + * Unique scope ID (monotonically increasing) useful for debugging. + */ + + /** + * @ngdoc property + * @name $rootScope.Scope#$parent + * + * @description + * Reference to the parent scope. + */ + + /** + * @ngdoc property + * @name $rootScope.Scope#$root + * + * @description + * Reference to the root scope. + */ + + Scope.prototype = { + constructor: Scope, + /** + * @ngdoc method + * @name $rootScope.Scope#$new + * @kind function + * + * @description + * Creates a new child {@link ng.$rootScope.Scope scope}. + * + * The parent scope will propagate the {@link ng.$rootScope.Scope#$digest $digest()} event. + * The scope can be removed from the scope hierarchy using {@link ng.$rootScope.Scope#$destroy $destroy()}. + * + * {@link ng.$rootScope.Scope#$destroy $destroy()} must be called on a scope when it is + * desired for the scope and its child scopes to be permanently detached from the parent and + * thus stop participating in model change detection and listener notification by invoking. + * + * @param {boolean} isolate If true, then the scope does not prototypically inherit from the + * parent scope. The scope is isolated, as it can not see parent scope properties. + * When creating widgets, it is useful for the widget to not accidentally read parent + * state. + * + * @param {Scope} [parent=this] The {@link ng.$rootScope.Scope `Scope`} that will be the `$parent` + * of the newly created scope. Defaults to `this` scope if not provided. + * This is used when creating a transclude scope to correctly place it + * in the scope hierarchy while maintaining the correct prototypical + * inheritance. + * + * @returns {Object} The newly created child scope. + * + */ + $new: function(isolate, parent) { + var child; + + parent = parent || this; + + if (isolate) { + child = new Scope(); + child.$root = this.$root; + } else { + // Only create a child scope class if somebody asks for one, + // but cache it to allow the VM to optimize lookups. + if (!this.$$ChildScope) { + this.$$ChildScope = createChildScopeClass(this); + } + child = new this.$$ChildScope(); + } + child.$parent = parent; + child.$$prevSibling = parent.$$childTail; + if (parent.$$childHead) { + parent.$$childTail.$$nextSibling = child; + parent.$$childTail = child; + } else { + parent.$$childHead = parent.$$childTail = child; + } + + // When the new scope is not isolated or we inherit from `this`, and + // the parent scope is destroyed, the property `$$destroyed` is inherited + // prototypically. In all other cases, this property needs to be set + // when the parent scope is destroyed. + // The listener needs to be added after the parent is set + if (isolate || parent != this) child.$on('$destroy', destroyChildScope); + + return child; + }, + + /** + * @ngdoc method + * @name $rootScope.Scope#$watch + * @kind function + * + * @description + * Registers a `listener` callback to be executed whenever the `watchExpression` changes. + * + * - The `watchExpression` is called on every call to {@link ng.$rootScope.Scope#$digest + * $digest()} and should return the value that will be watched. (Since + * {@link ng.$rootScope.Scope#$digest $digest()} reruns when it detects changes the + * `watchExpression` can execute multiple times per + * {@link ng.$rootScope.Scope#$digest $digest()} and should be idempotent.) + * - The `listener` is called only when the value from the current `watchExpression` and the + * previous call to `watchExpression` are not equal (with the exception of the initial run, + * see below). Inequality is determined according to reference inequality, + * [strict comparison](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators) + * via the `!==` Javascript operator, unless `objectEquality == true` + * (see next point) + * - When `objectEquality == true`, inequality of the `watchExpression` is determined + * according to the {@link angular.equals} function. To save the value of the object for + * later comparison, the {@link angular.copy} function is used. This therefore means that + * watching complex objects will have adverse memory and performance implications. + * - The watch `listener` may change the model, which may trigger other `listener`s to fire. + * This is achieved by rerunning the watchers until no changes are detected. The rerun + * iteration limit is 10 to prevent an infinite loop deadlock. + * + * + * If you want to be notified whenever {@link ng.$rootScope.Scope#$digest $digest} is called, + * you can register a `watchExpression` function with no `listener`. (Be prepared for + * multiple calls to your `watchExpression` because it will execute multiple times in a + * single {@link ng.$rootScope.Scope#$digest $digest} cycle if a change is detected.) + * + * After a watcher is registered with the scope, the `listener` fn is called asynchronously + * (via {@link ng.$rootScope.Scope#$evalAsync $evalAsync}) to initialize the + * watcher. In rare cases, this is undesirable because the listener is called when the result + * of `watchExpression` didn't change. To detect this scenario within the `listener` fn, you + * can compare the `newVal` and `oldVal`. If these two values are identical (`===`) then the + * listener was called due to initialization. + * + * + * + * # Example + * ```js + // let's assume that scope was dependency injected as the $rootScope + var scope = $rootScope; + scope.name = 'misko'; + scope.counter = 0; + + expect(scope.counter).toEqual(0); + scope.$watch('name', function(newValue, oldValue) { + scope.counter = scope.counter + 1; + }); + expect(scope.counter).toEqual(0); + + scope.$digest(); + // the listener is always called during the first $digest loop after it was registered + expect(scope.counter).toEqual(1); + + scope.$digest(); + // but now it will not be called unless the value changes + expect(scope.counter).toEqual(1); + + scope.name = 'adam'; + scope.$digest(); + expect(scope.counter).toEqual(2); + + + + // Using a function as a watchExpression + var food; + scope.foodCounter = 0; + expect(scope.foodCounter).toEqual(0); + scope.$watch( + // This function returns the value being watched. It is called for each turn of the $digest loop + function() { return food; }, + // This is the change listener, called when the value returned from the above function changes + function(newValue, oldValue) { + if ( newValue !== oldValue ) { + // Only increment the counter if the value changed + scope.foodCounter = scope.foodCounter + 1; + } + } + ); + // No digest has been run so the counter will be zero + expect(scope.foodCounter).toEqual(0); + + // Run the digest but since food has not changed count will still be zero + scope.$digest(); + expect(scope.foodCounter).toEqual(0); + + // Update food and run digest. Now the counter will increment + food = 'cheeseburger'; + scope.$digest(); + expect(scope.foodCounter).toEqual(1); + + * ``` + * + * + * + * @param {(function()|string)} watchExpression Expression that is evaluated on each + * {@link ng.$rootScope.Scope#$digest $digest} cycle. A change in the return value triggers + * a call to the `listener`. + * + * - `string`: Evaluated as {@link guide/expression expression} + * - `function(scope)`: called with current `scope` as a parameter. + * @param {function(newVal, oldVal, scope)} listener Callback called whenever the value + * of `watchExpression` changes. + * + * - `newVal` contains the current value of the `watchExpression` + * - `oldVal` contains the previous value of the `watchExpression` + * - `scope` refers to the current scope + * @param {boolean=} objectEquality Compare for object equality using {@link angular.equals} instead of + * comparing for reference equality. + * @returns {function()} Returns a deregistration function for this listener. + */ + $watch: function(watchExp, listener, objectEquality) { + var get = $parse(watchExp); + + if (get.$$watchDelegate) { + return get.$$watchDelegate(this, listener, objectEquality, get); + } + var scope = this, + array = scope.$$watchers, + watcher = { + fn: listener, + last: initWatchVal, + get: get, + exp: watchExp, + eq: !!objectEquality + }; + + lastDirtyWatch = null; + + if (!isFunction(listener)) { + watcher.fn = noop; + } + + if (!array) { + array = scope.$$watchers = []; + } + // we use unshift since we use a while loop in $digest for speed. + // the while loop reads in reverse order. + array.unshift(watcher); + + return function deregisterWatch() { + arrayRemove(array, watcher); + lastDirtyWatch = null; + }; + }, + + /** + * @ngdoc method + * @name $rootScope.Scope#$watchGroup + * @kind function + * + * @description + * A variant of {@link ng.$rootScope.Scope#$watch $watch()} where it watches an array of `watchExpressions`. + * If any one expression in the collection changes the `listener` is executed. + * + * - The items in the `watchExpressions` array are observed via standard $watch operation and are examined on every + * call to $digest() to see if any items changes. + * - The `listener` is called whenever any expression in the `watchExpressions` array changes. + * + * @param {Array.} watchExpressions Array of expressions that will be individually + * watched using {@link ng.$rootScope.Scope#$watch $watch()} + * + * @param {function(newValues, oldValues, scope)} listener Callback called whenever the return value of any + * expression in `watchExpressions` changes + * The `newValues` array contains the current values of the `watchExpressions`, with the indexes matching + * those of `watchExpression` + * and the `oldValues` array contains the previous values of the `watchExpressions`, with the indexes matching + * those of `watchExpression` + * The `scope` refers to the current scope. + * @returns {function()} Returns a de-registration function for all listeners. + */ + $watchGroup: function(watchExpressions, listener) { + var oldValues = new Array(watchExpressions.length); + var newValues = new Array(watchExpressions.length); + var deregisterFns = []; + var self = this; + var changeReactionScheduled = false; + var firstRun = true; + + if (!watchExpressions.length) { + // No expressions means we call the listener ASAP + var shouldCall = true; + self.$evalAsync(function() { + if (shouldCall) listener(newValues, newValues, self); + }); + return function deregisterWatchGroup() { + shouldCall = false; + }; + } + + if (watchExpressions.length === 1) { + // Special case size of one + return this.$watch(watchExpressions[0], function watchGroupAction(value, oldValue, scope) { + newValues[0] = value; + oldValues[0] = oldValue; + listener(newValues, (value === oldValue) ? newValues : oldValues, scope); + }); + } + + forEach(watchExpressions, function(expr, i) { + var unwatchFn = self.$watch(expr, function watchGroupSubAction(value, oldValue) { + newValues[i] = value; + oldValues[i] = oldValue; + if (!changeReactionScheduled) { + changeReactionScheduled = true; + self.$evalAsync(watchGroupAction); + } + }); + deregisterFns.push(unwatchFn); + }); + + function watchGroupAction() { + changeReactionScheduled = false; + + if (firstRun) { + firstRun = false; + listener(newValues, newValues, self); + } else { + listener(newValues, oldValues, self); + } + } + + return function deregisterWatchGroup() { + while (deregisterFns.length) { + deregisterFns.shift()(); + } + }; + }, + + + /** + * @ngdoc method + * @name $rootScope.Scope#$watchCollection + * @kind function + * + * @description + * Shallow watches the properties of an object and fires whenever any of the properties change + * (for arrays, this implies watching the array items; for object maps, this implies watching + * the properties). If a change is detected, the `listener` callback is fired. + * + * - The `obj` collection is observed via standard $watch operation and is examined on every + * call to $digest() to see if any items have been added, removed, or moved. + * - The `listener` is called whenever anything within the `obj` has changed. Examples include + * adding, removing, and moving items belonging to an object or array. + * + * + * # Example + * ```js + $scope.names = ['igor', 'matias', 'misko', 'james']; + $scope.dataCount = 4; + + $scope.$watchCollection('names', function(newNames, oldNames) { + $scope.dataCount = newNames.length; + }); + + expect($scope.dataCount).toEqual(4); + $scope.$digest(); + + //still at 4 ... no changes + expect($scope.dataCount).toEqual(4); + + $scope.names.pop(); + $scope.$digest(); + + //now there's been a change + expect($scope.dataCount).toEqual(3); + * ``` + * + * + * @param {string|function(scope)} obj Evaluated as {@link guide/expression expression}. The + * expression value should evaluate to an object or an array which is observed on each + * {@link ng.$rootScope.Scope#$digest $digest} cycle. Any shallow change within the + * collection will trigger a call to the `listener`. + * + * @param {function(newCollection, oldCollection, scope)} listener a callback function called + * when a change is detected. + * - The `newCollection` object is the newly modified data obtained from the `obj` expression + * - The `oldCollection` object is a copy of the former collection data. + * Due to performance considerations, the`oldCollection` value is computed only if the + * `listener` function declares two or more arguments. + * - The `scope` argument refers to the current scope. + * + * @returns {function()} Returns a de-registration function for this listener. When the + * de-registration function is executed, the internal watch operation is terminated. + */ + $watchCollection: function(obj, listener) { + $watchCollectionInterceptor.$stateful = true; + + var self = this; + // the current value, updated on each dirty-check run + var newValue; + // a shallow copy of the newValue from the last dirty-check run, + // updated to match newValue during dirty-check run + var oldValue; + // a shallow copy of the newValue from when the last change happened + var veryOldValue; + // only track veryOldValue if the listener is asking for it + var trackVeryOldValue = (listener.length > 1); + var changeDetected = 0; + var changeDetector = $parse(obj, $watchCollectionInterceptor); + var internalArray = []; + var internalObject = {}; + var initRun = true; + var oldLength = 0; + + function $watchCollectionInterceptor(_value) { + newValue = _value; + var newLength, key, bothNaN, newItem, oldItem; + + // If the new value is undefined, then return undefined as the watch may be a one-time watch + if (isUndefined(newValue)) return; + + if (!isObject(newValue)) { // if primitive + if (oldValue !== newValue) { + oldValue = newValue; + changeDetected++; + } + } else if (isArrayLike(newValue)) { + if (oldValue !== internalArray) { + // we are transitioning from something which was not an array into array. + oldValue = internalArray; + oldLength = oldValue.length = 0; + changeDetected++; + } + + newLength = newValue.length; + + if (oldLength !== newLength) { + // if lengths do not match we need to trigger change notification + changeDetected++; + oldValue.length = oldLength = newLength; + } + // copy the items to oldValue and look for changes. + for (var i = 0; i < newLength; i++) { + oldItem = oldValue[i]; + newItem = newValue[i]; + + bothNaN = (oldItem !== oldItem) && (newItem !== newItem); + if (!bothNaN && (oldItem !== newItem)) { + changeDetected++; + oldValue[i] = newItem; + } + } + } else { + if (oldValue !== internalObject) { + // we are transitioning from something which was not an object into object. + oldValue = internalObject = {}; + oldLength = 0; + changeDetected++; + } + // copy the items to oldValue and look for changes. + newLength = 0; + for (key in newValue) { + if (newValue.hasOwnProperty(key)) { + newLength++; + newItem = newValue[key]; + oldItem = oldValue[key]; + + if (key in oldValue) { + bothNaN = (oldItem !== oldItem) && (newItem !== newItem); + if (!bothNaN && (oldItem !== newItem)) { + changeDetected++; + oldValue[key] = newItem; + } + } else { + oldLength++; + oldValue[key] = newItem; + changeDetected++; + } + } + } + if (oldLength > newLength) { + // we used to have more keys, need to find them and destroy them. + changeDetected++; + for (key in oldValue) { + if (!newValue.hasOwnProperty(key)) { + oldLength--; + delete oldValue[key]; + } + } + } + } + return changeDetected; + } + + function $watchCollectionAction() { + if (initRun) { + initRun = false; + listener(newValue, newValue, self); + } else { + listener(newValue, veryOldValue, self); + } + + // make a copy for the next time a collection is changed + if (trackVeryOldValue) { + if (!isObject(newValue)) { + //primitive + veryOldValue = newValue; + } else if (isArrayLike(newValue)) { + veryOldValue = new Array(newValue.length); + for (var i = 0; i < newValue.length; i++) { + veryOldValue[i] = newValue[i]; + } + } else { // if object + veryOldValue = {}; + for (var key in newValue) { + if (hasOwnProperty.call(newValue, key)) { + veryOldValue[key] = newValue[key]; + } + } + } + } + } + + return this.$watch(changeDetector, $watchCollectionAction); + }, + + /** + * @ngdoc method + * @name $rootScope.Scope#$digest + * @kind function + * + * @description + * Processes all of the {@link ng.$rootScope.Scope#$watch watchers} of the current scope and + * its children. Because a {@link ng.$rootScope.Scope#$watch watcher}'s listener can change + * the model, the `$digest()` keeps calling the {@link ng.$rootScope.Scope#$watch watchers} + * until no more listeners are firing. This means that it is possible to get into an infinite + * loop. This function will throw `'Maximum iteration limit exceeded.'` if the number of + * iterations exceeds 10. + * + * Usually, you don't call `$digest()` directly in + * {@link ng.directive:ngController controllers} or in + * {@link ng.$compileProvider#directive directives}. + * Instead, you should call {@link ng.$rootScope.Scope#$apply $apply()} (typically from within + * a {@link ng.$compileProvider#directive directive}), which will force a `$digest()`. + * + * If you want to be notified whenever `$digest()` is called, + * you can register a `watchExpression` function with + * {@link ng.$rootScope.Scope#$watch $watch()} with no `listener`. + * + * In unit tests, you may need to call `$digest()` to simulate the scope life cycle. + * + * # Example + * ```js + var scope = ...; + scope.name = 'misko'; + scope.counter = 0; + + expect(scope.counter).toEqual(0); + scope.$watch('name', function(newValue, oldValue) { + scope.counter = scope.counter + 1; + }); + expect(scope.counter).toEqual(0); + + scope.$digest(); + // the listener is always called during the first $digest loop after it was registered + expect(scope.counter).toEqual(1); + + scope.$digest(); + // but now it will not be called unless the value changes + expect(scope.counter).toEqual(1); + + scope.name = 'adam'; + scope.$digest(); + expect(scope.counter).toEqual(2); + * ``` + * + */ + $digest: function() { + var watch, value, last, + watchers, + length, + dirty, ttl = TTL, + next, current, target = this, + watchLog = [], + logIdx, logMsg, asyncTask; + + beginPhase('$digest'); + // Check for changes to browser url that happened in sync before the call to $digest + $browser.$$checkUrlChange(); + + if (this === $rootScope && applyAsyncId !== null) { + // If this is the root scope, and $applyAsync has scheduled a deferred $apply(), then + // cancel the scheduled $apply and flush the queue of expressions to be evaluated. + $browser.defer.cancel(applyAsyncId); + flushApplyAsync(); + } + + lastDirtyWatch = null; + + do { // "while dirty" loop + dirty = false; + current = target; + + while (asyncQueue.length) { + try { + asyncTask = asyncQueue.shift(); + asyncTask.scope.$eval(asyncTask.expression, asyncTask.locals); + } catch (e) { + $exceptionHandler(e); + } + lastDirtyWatch = null; + } + + traverseScopesLoop: + do { // "traverse the scopes" loop + if ((watchers = current.$$watchers)) { + // process our watches + length = watchers.length; + while (length--) { + try { + watch = watchers[length]; + // Most common watches are on primitives, in which case we can short + // circuit it with === operator, only when === fails do we use .equals + if (watch) { + if ((value = watch.get(current)) !== (last = watch.last) && + !(watch.eq + ? equals(value, last) + : (typeof value === 'number' && typeof last === 'number' + && isNaN(value) && isNaN(last)))) { + dirty = true; + lastDirtyWatch = watch; + watch.last = watch.eq ? copy(value, null) : value; + watch.fn(value, ((last === initWatchVal) ? value : last), current); + if (ttl < 5) { + logIdx = 4 - ttl; + if (!watchLog[logIdx]) watchLog[logIdx] = []; + watchLog[logIdx].push({ + msg: isFunction(watch.exp) ? 'fn: ' + (watch.exp.name || watch.exp.toString()) : watch.exp, + newVal: value, + oldVal: last + }); + } + } else if (watch === lastDirtyWatch) { + // If the most recently dirty watcher is now clean, short circuit since the remaining watchers + // have already been tested. + dirty = false; + break traverseScopesLoop; + } + } + } catch (e) { + $exceptionHandler(e); + } + } + } + + // Insanity Warning: scope depth-first traversal + // yes, this code is a bit crazy, but it works and we have tests to prove it! + // this piece should be kept in sync with the traversal in $broadcast + if (!(next = (current.$$childHead || + (current !== target && current.$$nextSibling)))) { + while (current !== target && !(next = current.$$nextSibling)) { + current = current.$parent; + } + } + } while ((current = next)); + + // `break traverseScopesLoop;` takes us to here + + if ((dirty || asyncQueue.length) && !(ttl--)) { + clearPhase(); + throw $rootScopeMinErr('infdig', + '{0} $digest() iterations reached. Aborting!\n' + + 'Watchers fired in the last 5 iterations: {1}', + TTL, watchLog); + } + + } while (dirty || asyncQueue.length); + + clearPhase(); + + while (postDigestQueue.length) { + try { + postDigestQueue.shift()(); + } catch (e) { + $exceptionHandler(e); + } + } + }, + + + /** + * @ngdoc event + * @name $rootScope.Scope#$destroy + * @eventType broadcast on scope being destroyed + * + * @description + * Broadcasted when a scope and its children are being destroyed. + * + * Note that, in AngularJS, there is also a `$destroy` jQuery event, which can be used to + * clean up DOM bindings before an element is removed from the DOM. + */ + + /** + * @ngdoc method + * @name $rootScope.Scope#$destroy + * @kind function + * + * @description + * Removes the current scope (and all of its children) from the parent scope. Removal implies + * that calls to {@link ng.$rootScope.Scope#$digest $digest()} will no longer + * propagate to the current scope and its children. Removal also implies that the current + * scope is eligible for garbage collection. + * + * The `$destroy()` is usually used by directives such as + * {@link ng.directive:ngRepeat ngRepeat} for managing the + * unrolling of the loop. + * + * Just before a scope is destroyed, a `$destroy` event is broadcasted on this scope. + * Application code can register a `$destroy` event handler that will give it a chance to + * perform any necessary cleanup. + * + * Note that, in AngularJS, there is also a `$destroy` jQuery event, which can be used to + * clean up DOM bindings before an element is removed from the DOM. + */ + $destroy: function() { + // we can't destroy the root scope or a scope that has been already destroyed + if (this.$$destroyed) return; + var parent = this.$parent; + + this.$broadcast('$destroy'); + this.$$destroyed = true; + if (this === $rootScope) return; + + for (var eventName in this.$$listenerCount) { + decrementListenerCount(this, this.$$listenerCount[eventName], eventName); + } + + // sever all the references to parent scopes (after this cleanup, the current scope should + // not be retained by any of our references and should be eligible for garbage collection) + if (parent.$$childHead == this) parent.$$childHead = this.$$nextSibling; + if (parent.$$childTail == this) parent.$$childTail = this.$$prevSibling; + if (this.$$prevSibling) this.$$prevSibling.$$nextSibling = this.$$nextSibling; + if (this.$$nextSibling) this.$$nextSibling.$$prevSibling = this.$$prevSibling; + + // Disable listeners, watchers and apply/digest methods + this.$destroy = this.$digest = this.$apply = this.$evalAsync = this.$applyAsync = noop; + this.$on = this.$watch = this.$watchGroup = function() { return noop; }; + this.$$listeners = {}; + + // All of the code below is bogus code that works around V8's memory leak via optimized code + // and inline caches. + // + // see: + // - https://code.google.com/p/v8/issues/detail?id=2073#c26 + // - https://github.com/angular/angular.js/issues/6794#issuecomment-38648909 + // - https://github.com/angular/angular.js/issues/1313#issuecomment-10378451 + + this.$parent = this.$$nextSibling = this.$$prevSibling = this.$$childHead = + this.$$childTail = this.$root = this.$$watchers = null; + }, + + /** + * @ngdoc method + * @name $rootScope.Scope#$eval + * @kind function + * + * @description + * Executes the `expression` on the current scope and returns the result. Any exceptions in + * the expression are propagated (uncaught). This is useful when evaluating Angular + * expressions. + * + * # Example + * ```js + var scope = ng.$rootScope.Scope(); + scope.a = 1; + scope.b = 2; + + expect(scope.$eval('a+b')).toEqual(3); + expect(scope.$eval(function(scope){ return scope.a + scope.b; })).toEqual(3); + * ``` + * + * @param {(string|function())=} expression An angular expression to be executed. + * + * - `string`: execute using the rules as defined in {@link guide/expression expression}. + * - `function(scope)`: execute the function with the current `scope` parameter. + * + * @param {(object)=} locals Local variables object, useful for overriding values in scope. + * @returns {*} The result of evaluating the expression. + */ + $eval: function(expr, locals) { + return $parse(expr)(this, locals); + }, + + /** + * @ngdoc method + * @name $rootScope.Scope#$evalAsync + * @kind function + * + * @description + * Executes the expression on the current scope at a later point in time. + * + * The `$evalAsync` makes no guarantees as to when the `expression` will be executed, only + * that: + * + * - it will execute after the function that scheduled the evaluation (preferably before DOM + * rendering). + * - at least one {@link ng.$rootScope.Scope#$digest $digest cycle} will be performed after + * `expression` execution. + * + * Any exceptions from the execution of the expression are forwarded to the + * {@link ng.$exceptionHandler $exceptionHandler} service. + * + * __Note:__ if this function is called outside of a `$digest` cycle, a new `$digest` cycle + * will be scheduled. However, it is encouraged to always call code that changes the model + * from within an `$apply` call. That includes code evaluated via `$evalAsync`. + * + * @param {(string|function())=} expression An angular expression to be executed. + * + * - `string`: execute using the rules as defined in {@link guide/expression expression}. + * - `function(scope)`: execute the function with the current `scope` parameter. + * + * @param {(object)=} locals Local variables object, useful for overriding values in scope. + */ + $evalAsync: function(expr, locals) { + // if we are outside of an $digest loop and this is the first time we are scheduling async + // task also schedule async auto-flush + if (!$rootScope.$$phase && !asyncQueue.length) { + $browser.defer(function() { + if (asyncQueue.length) { + $rootScope.$digest(); + } + }); + } + + asyncQueue.push({scope: this, expression: expr, locals: locals}); + }, + + $$postDigest: function(fn) { + postDigestQueue.push(fn); + }, + + /** + * @ngdoc method + * @name $rootScope.Scope#$apply + * @kind function + * + * @description + * `$apply()` is used to execute an expression in angular from outside of the angular + * framework. (For example from browser DOM events, setTimeout, XHR or third party libraries). + * Because we are calling into the angular framework we need to perform proper scope life + * cycle of {@link ng.$exceptionHandler exception handling}, + * {@link ng.$rootScope.Scope#$digest executing watches}. + * + * ## Life cycle + * + * # Pseudo-Code of `$apply()` + * ```js + function $apply(expr) { + try { + return $eval(expr); + } catch (e) { + $exceptionHandler(e); + } finally { + $root.$digest(); + } + } + * ``` + * + * + * Scope's `$apply()` method transitions through the following stages: + * + * 1. The {@link guide/expression expression} is executed using the + * {@link ng.$rootScope.Scope#$eval $eval()} method. + * 2. Any exceptions from the execution of the expression are forwarded to the + * {@link ng.$exceptionHandler $exceptionHandler} service. + * 3. The {@link ng.$rootScope.Scope#$watch watch} listeners are fired immediately after the + * expression was executed using the {@link ng.$rootScope.Scope#$digest $digest()} method. + * + * + * @param {(string|function())=} exp An angular expression to be executed. + * + * - `string`: execute using the rules as defined in {@link guide/expression expression}. + * - `function(scope)`: execute the function with current `scope` parameter. + * + * @returns {*} The result of evaluating the expression. + */ + $apply: function(expr) { + try { + beginPhase('$apply'); + return this.$eval(expr); + } catch (e) { + $exceptionHandler(e); + } finally { + clearPhase(); + try { + $rootScope.$digest(); + } catch (e) { + $exceptionHandler(e); + throw e; + } + } + }, + + /** + * @ngdoc method + * @name $rootScope.Scope#$applyAsync + * @kind function + * + * @description + * Schedule the invocation of $apply to occur at a later time. The actual time difference + * varies across browsers, but is typically around ~10 milliseconds. + * + * This can be used to queue up multiple expressions which need to be evaluated in the same + * digest. + * + * @param {(string|function())=} exp An angular expression to be executed. + * + * - `string`: execute using the rules as defined in {@link guide/expression expression}. + * - `function(scope)`: execute the function with current `scope` parameter. + */ + $applyAsync: function(expr) { + var scope = this; + expr && applyAsyncQueue.push($applyAsyncExpression); + scheduleApplyAsync(); + + function $applyAsyncExpression() { + scope.$eval(expr); + } + }, + + /** + * @ngdoc method + * @name $rootScope.Scope#$on + * @kind function + * + * @description + * Listens on events of a given type. See {@link ng.$rootScope.Scope#$emit $emit} for + * discussion of event life cycle. + * + * The event listener function format is: `function(event, args...)`. The `event` object + * passed into the listener has the following attributes: + * + * - `targetScope` - `{Scope}`: the scope on which the event was `$emit`-ed or + * `$broadcast`-ed. + * - `currentScope` - `{Scope}`: the scope that is currently handling the event. Once the + * event propagates through the scope hierarchy, this property is set to null. + * - `name` - `{string}`: name of the event. + * - `stopPropagation` - `{function=}`: calling `stopPropagation` function will cancel + * further event propagation (available only for events that were `$emit`-ed). + * - `preventDefault` - `{function}`: calling `preventDefault` sets `defaultPrevented` flag + * to true. + * - `defaultPrevented` - `{boolean}`: true if `preventDefault` was called. + * + * @param {string} name Event name to listen on. + * @param {function(event, ...args)} listener Function to call when the event is emitted. + * @returns {function()} Returns a deregistration function for this listener. + */ + $on: function(name, listener) { + var namedListeners = this.$$listeners[name]; + if (!namedListeners) { + this.$$listeners[name] = namedListeners = []; + } + namedListeners.push(listener); + + var current = this; + do { + if (!current.$$listenerCount[name]) { + current.$$listenerCount[name] = 0; + } + current.$$listenerCount[name]++; + } while ((current = current.$parent)); + + var self = this; + return function() { + var indexOfListener = namedListeners.indexOf(listener); + if (indexOfListener !== -1) { + namedListeners[indexOfListener] = null; + decrementListenerCount(self, 1, name); + } + }; + }, + + + /** + * @ngdoc method + * @name $rootScope.Scope#$emit + * @kind function + * + * @description + * Dispatches an event `name` upwards through the scope hierarchy notifying the + * registered {@link ng.$rootScope.Scope#$on} listeners. + * + * The event life cycle starts at the scope on which `$emit` was called. All + * {@link ng.$rootScope.Scope#$on listeners} listening for `name` event on this scope get + * notified. Afterwards, the event traverses upwards toward the root scope and calls all + * registered listeners along the way. The event will stop propagating if one of the listeners + * cancels it. + * + * Any exception emitted from the {@link ng.$rootScope.Scope#$on listeners} will be passed + * onto the {@link ng.$exceptionHandler $exceptionHandler} service. + * + * @param {string} name Event name to emit. + * @param {...*} args Optional one or more arguments which will be passed onto the event listeners. + * @return {Object} Event object (see {@link ng.$rootScope.Scope#$on}). + */ + $emit: function(name, args) { + var empty = [], + namedListeners, + scope = this, + stopPropagation = false, + event = { + name: name, + targetScope: scope, + stopPropagation: function() {stopPropagation = true;}, + preventDefault: function() { + event.defaultPrevented = true; + }, + defaultPrevented: false + }, + listenerArgs = concat([event], arguments, 1), + i, length; + + do { + namedListeners = scope.$$listeners[name] || empty; + event.currentScope = scope; + for (i = 0, length = namedListeners.length; i < length; i++) { + + // if listeners were deregistered, defragment the array + if (!namedListeners[i]) { + namedListeners.splice(i, 1); + i--; + length--; + continue; + } + try { + //allow all listeners attached to the current scope to run + namedListeners[i].apply(null, listenerArgs); + } catch (e) { + $exceptionHandler(e); + } + } + //if any listener on the current scope stops propagation, prevent bubbling + if (stopPropagation) { + event.currentScope = null; + return event; + } + //traverse upwards + scope = scope.$parent; + } while (scope); + + event.currentScope = null; + + return event; + }, + + + /** + * @ngdoc method + * @name $rootScope.Scope#$broadcast + * @kind function + * + * @description + * Dispatches an event `name` downwards to all child scopes (and their children) notifying the + * registered {@link ng.$rootScope.Scope#$on} listeners. + * + * The event life cycle starts at the scope on which `$broadcast` was called. All + * {@link ng.$rootScope.Scope#$on listeners} listening for `name` event on this scope get + * notified. Afterwards, the event propagates to all direct and indirect scopes of the current + * scope and calls all registered listeners along the way. The event cannot be canceled. + * + * Any exception emitted from the {@link ng.$rootScope.Scope#$on listeners} will be passed + * onto the {@link ng.$exceptionHandler $exceptionHandler} service. + * + * @param {string} name Event name to broadcast. + * @param {...*} args Optional one or more arguments which will be passed onto the event listeners. + * @return {Object} Event object, see {@link ng.$rootScope.Scope#$on} + */ + $broadcast: function(name, args) { + var target = this, + current = target, + next = target, + event = { + name: name, + targetScope: target, + preventDefault: function() { + event.defaultPrevented = true; + }, + defaultPrevented: false + }; + + if (!target.$$listenerCount[name]) return event; + + var listenerArgs = concat([event], arguments, 1), + listeners, i, length; + + //down while you can, then up and next sibling or up and next sibling until back at root + while ((current = next)) { + event.currentScope = current; + listeners = current.$$listeners[name] || []; + for (i = 0, length = listeners.length; i < length; i++) { + // if listeners were deregistered, defragment the array + if (!listeners[i]) { + listeners.splice(i, 1); + i--; + length--; + continue; + } + + try { + listeners[i].apply(null, listenerArgs); + } catch (e) { + $exceptionHandler(e); + } + } + + // Insanity Warning: scope depth-first traversal + // yes, this code is a bit crazy, but it works and we have tests to prove it! + // this piece should be kept in sync with the traversal in $digest + // (though it differs due to having the extra check for $$listenerCount) + if (!(next = ((current.$$listenerCount[name] && current.$$childHead) || + (current !== target && current.$$nextSibling)))) { + while (current !== target && !(next = current.$$nextSibling)) { + current = current.$parent; + } + } + } + + event.currentScope = null; + return event; + } + }; + + var $rootScope = new Scope(); + + //The internal queues. Expose them on the $rootScope for debugging/testing purposes. + var asyncQueue = $rootScope.$$asyncQueue = []; + var postDigestQueue = $rootScope.$$postDigestQueue = []; + var applyAsyncQueue = $rootScope.$$applyAsyncQueue = []; + + return $rootScope; + + + function beginPhase(phase) { + if ($rootScope.$$phase) { + throw $rootScopeMinErr('inprog', '{0} already in progress', $rootScope.$$phase); + } + + $rootScope.$$phase = phase; + } + + function clearPhase() { + $rootScope.$$phase = null; + } + + + function decrementListenerCount(current, count, name) { + do { + current.$$listenerCount[name] -= count; + + if (current.$$listenerCount[name] === 0) { + delete current.$$listenerCount[name]; + } + } while ((current = current.$parent)); + } + + /** + * function used as an initial value for watchers. + * because it's unique we can easily tell it apart from other values + */ + function initWatchVal() {} + + function flushApplyAsync() { + while (applyAsyncQueue.length) { + try { + applyAsyncQueue.shift()(); + } catch (e) { + $exceptionHandler(e); + } + } + applyAsyncId = null; + } + + function scheduleApplyAsync() { + if (applyAsyncId === null) { + applyAsyncId = $browser.defer(function() { + $rootScope.$apply(flushApplyAsync); + }); + } + } + }]; +} + +/** + * @description + * Private service to sanitize uris for links and images. Used by $compile and $sanitize. + */ +function $$SanitizeUriProvider() { + var aHrefSanitizationWhitelist = /^\s*(https?|ftp|mailto|tel|file):/, + imgSrcSanitizationWhitelist = /^\s*((https?|ftp|file|blob):|data:image\/)/; + + /** + * @description + * Retrieves or overrides the default regular expression that is used for whitelisting of safe + * urls during a[href] sanitization. + * + * The sanitization is a security measure aimed at prevent XSS attacks via html links. + * + * Any url about to be assigned to a[href] via data-binding is first normalized and turned into + * an absolute url. Afterwards, the url is matched against the `aHrefSanitizationWhitelist` + * regular expression. If a match is found, the original url is written into the dom. Otherwise, + * the absolute url is prefixed with `'unsafe:'` string and only then is it written into the DOM. + * + * @param {RegExp=} regexp New regexp to whitelist urls with. + * @returns {RegExp|ng.$compileProvider} Current RegExp if called without value or self for + * chaining otherwise. + */ + this.aHrefSanitizationWhitelist = function(regexp) { + if (isDefined(regexp)) { + aHrefSanitizationWhitelist = regexp; + return this; + } + return aHrefSanitizationWhitelist; + }; + + + /** + * @description + * Retrieves or overrides the default regular expression that is used for whitelisting of safe + * urls during img[src] sanitization. + * + * The sanitization is a security measure aimed at prevent XSS attacks via html links. + * + * Any url about to be assigned to img[src] via data-binding is first normalized and turned into + * an absolute url. Afterwards, the url is matched against the `imgSrcSanitizationWhitelist` + * regular expression. If a match is found, the original url is written into the dom. Otherwise, + * the absolute url is prefixed with `'unsafe:'` string and only then is it written into the DOM. + * + * @param {RegExp=} regexp New regexp to whitelist urls with. + * @returns {RegExp|ng.$compileProvider} Current RegExp if called without value or self for + * chaining otherwise. + */ + this.imgSrcSanitizationWhitelist = function(regexp) { + if (isDefined(regexp)) { + imgSrcSanitizationWhitelist = regexp; + return this; + } + return imgSrcSanitizationWhitelist; + }; + + this.$get = function() { + return function sanitizeUri(uri, isImage) { + var regex = isImage ? imgSrcSanitizationWhitelist : aHrefSanitizationWhitelist; + var normalizedVal; + normalizedVal = urlResolve(uri).href; + if (normalizedVal !== '' && !normalizedVal.match(regex)) { + return 'unsafe:' + normalizedVal; + } + return uri; + }; + }; +} + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Any commits to this file should be reviewed with security in mind. * + * Changes to this file can potentially create security vulnerabilities. * + * An approval from 2 Core members with history of modifying * + * this file is required. * + * * + * Does the change somehow allow for arbitrary javascript to be executed? * + * Or allows for someone to change the prototype of built-in objects? * + * Or gives undesired access to variables likes document or window? * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +var $sceMinErr = minErr('$sce'); + +var SCE_CONTEXTS = { + HTML: 'html', + CSS: 'css', + URL: 'url', + // RESOURCE_URL is a subtype of URL used in contexts where a privileged resource is sourced from a + // url. (e.g. ng-include, script src, templateUrl) + RESOURCE_URL: 'resourceUrl', + JS: 'js' +}; + +// Helper functions follow. + +function adjustMatcher(matcher) { + if (matcher === 'self') { + return matcher; + } else if (isString(matcher)) { + // Strings match exactly except for 2 wildcards - '*' and '**'. + // '*' matches any character except those from the set ':/.?&'. + // '**' matches any character (like .* in a RegExp). + // More than 2 *'s raises an error as it's ill defined. + if (matcher.indexOf('***') > -1) { + throw $sceMinErr('iwcard', + 'Illegal sequence *** in string matcher. String: {0}', matcher); + } + matcher = escapeForRegexp(matcher). + replace('\\*\\*', '.*'). + replace('\\*', '[^:/.?&;]*'); + return new RegExp('^' + matcher + '$'); + } else if (isRegExp(matcher)) { + // The only other type of matcher allowed is a Regexp. + // Match entire URL / disallow partial matches. + // Flags are reset (i.e. no global, ignoreCase or multiline) + return new RegExp('^' + matcher.source + '$'); + } else { + throw $sceMinErr('imatcher', + 'Matchers may only be "self", string patterns or RegExp objects'); + } +} + + +function adjustMatchers(matchers) { + var adjustedMatchers = []; + if (isDefined(matchers)) { + forEach(matchers, function(matcher) { + adjustedMatchers.push(adjustMatcher(matcher)); + }); + } + return adjustedMatchers; +} + + +/** + * @ngdoc service + * @name $sceDelegate + * @kind function + * + * @description + * + * `$sceDelegate` is a service that is used by the `$sce` service to provide {@link ng.$sce Strict + * Contextual Escaping (SCE)} services to AngularJS. + * + * Typically, you would configure or override the {@link ng.$sceDelegate $sceDelegate} instead of + * the `$sce` service to customize the way Strict Contextual Escaping works in AngularJS. This is + * because, while the `$sce` provides numerous shorthand methods, etc., you really only need to + * override 3 core functions (`trustAs`, `getTrusted` and `valueOf`) to replace the way things + * work because `$sce` delegates to `$sceDelegate` for these operations. + * + * Refer {@link ng.$sceDelegateProvider $sceDelegateProvider} to configure this service. + * + * The default instance of `$sceDelegate` should work out of the box with little pain. While you + * can override it completely to change the behavior of `$sce`, the common case would + * involve configuring the {@link ng.$sceDelegateProvider $sceDelegateProvider} instead by setting + * your own whitelists and blacklists for trusting URLs used for loading AngularJS resources such as + * templates. Refer {@link ng.$sceDelegateProvider#resourceUrlWhitelist + * $sceDelegateProvider.resourceUrlWhitelist} and {@link + * ng.$sceDelegateProvider#resourceUrlBlacklist $sceDelegateProvider.resourceUrlBlacklist} + */ + +/** + * @ngdoc provider + * @name $sceDelegateProvider + * @description + * + * The `$sceDelegateProvider` provider allows developers to configure the {@link ng.$sceDelegate + * $sceDelegate} service. This allows one to get/set the whitelists and blacklists used to ensure + * that the URLs used for sourcing Angular templates are safe. Refer {@link + * ng.$sceDelegateProvider#resourceUrlWhitelist $sceDelegateProvider.resourceUrlWhitelist} and + * {@link ng.$sceDelegateProvider#resourceUrlBlacklist $sceDelegateProvider.resourceUrlBlacklist} + * + * For the general details about this service in Angular, read the main page for {@link ng.$sce + * Strict Contextual Escaping (SCE)}. + * + * **Example**: Consider the following case. + * + * - your app is hosted at url `http://myapp.example.com/` + * - but some of your templates are hosted on other domains you control such as + * `http://srv01.assets.example.com/`,  `http://srv02.assets.example.com/`, etc. + * - and you have an open redirect at `http://myapp.example.com/clickThru?...`. + * + * Here is what a secure configuration for this scenario might look like: + * + * ``` + * angular.module('myApp', []).config(function($sceDelegateProvider) { + * $sceDelegateProvider.resourceUrlWhitelist([ + * // Allow same origin resource loads. + * 'self', + * // Allow loading from our assets domain. Notice the difference between * and **. + * 'http://srv*.assets.example.com/**' + * ]); + * + * // The blacklist overrides the whitelist so the open redirect here is blocked. + * $sceDelegateProvider.resourceUrlBlacklist([ + * 'http://myapp.example.com/clickThru**' + * ]); + * }); + * ``` + */ + +function $SceDelegateProvider() { + this.SCE_CONTEXTS = SCE_CONTEXTS; + + // Resource URLs can also be trusted by policy. + var resourceUrlWhitelist = ['self'], + resourceUrlBlacklist = []; + + /** + * @ngdoc method + * @name $sceDelegateProvider#resourceUrlWhitelist + * @kind function + * + * @param {Array=} whitelist When provided, replaces the resourceUrlWhitelist with the value + * provided. This must be an array or null. A snapshot of this array is used so further + * changes to the array are ignored. + * + * Follow {@link ng.$sce#resourceUrlPatternItem this link} for a description of the items + * allowed in this array. + * + * Note: **an empty whitelist array will block all URLs**! + * + * @return {Array} the currently set whitelist array. + * + * The **default value** when no whitelist has been explicitly set is `['self']` allowing only + * same origin resource requests. + * + * @description + * Sets/Gets the whitelist of trusted resource URLs. + */ + this.resourceUrlWhitelist = function(value) { + if (arguments.length) { + resourceUrlWhitelist = adjustMatchers(value); + } + return resourceUrlWhitelist; + }; + + /** + * @ngdoc method + * @name $sceDelegateProvider#resourceUrlBlacklist + * @kind function + * + * @param {Array=} blacklist When provided, replaces the resourceUrlBlacklist with the value + * provided. This must be an array or null. A snapshot of this array is used so further + * changes to the array are ignored. + * + * Follow {@link ng.$sce#resourceUrlPatternItem this link} for a description of the items + * allowed in this array. + * + * The typical usage for the blacklist is to **block + * [open redirects](http://cwe.mitre.org/data/definitions/601.html)** served by your domain as + * these would otherwise be trusted but actually return content from the redirected domain. + * + * Finally, **the blacklist overrides the whitelist** and has the final say. + * + * @return {Array} the currently set blacklist array. + * + * The **default value** when no whitelist has been explicitly set is the empty array (i.e. there + * is no blacklist.) + * + * @description + * Sets/Gets the blacklist of trusted resource URLs. + */ + + this.resourceUrlBlacklist = function(value) { + if (arguments.length) { + resourceUrlBlacklist = adjustMatchers(value); + } + return resourceUrlBlacklist; + }; + + this.$get = ['$injector', function($injector) { + + var htmlSanitizer = function htmlSanitizer(html) { + throw $sceMinErr('unsafe', 'Attempting to use an unsafe value in a safe context.'); + }; + + if ($injector.has('$sanitize')) { + htmlSanitizer = $injector.get('$sanitize'); + } + + + function matchUrl(matcher, parsedUrl) { + if (matcher === 'self') { + return urlIsSameOrigin(parsedUrl); + } else { + // definitely a regex. See adjustMatchers() + return !!matcher.exec(parsedUrl.href); + } + } + + function isResourceUrlAllowedByPolicy(url) { + var parsedUrl = urlResolve(url.toString()); + var i, n, allowed = false; + // Ensure that at least one item from the whitelist allows this url. + for (i = 0, n = resourceUrlWhitelist.length; i < n; i++) { + if (matchUrl(resourceUrlWhitelist[i], parsedUrl)) { + allowed = true; + break; + } + } + if (allowed) { + // Ensure that no item from the blacklist blocked this url. + for (i = 0, n = resourceUrlBlacklist.length; i < n; i++) { + if (matchUrl(resourceUrlBlacklist[i], parsedUrl)) { + allowed = false; + break; + } + } + } + return allowed; + } + + function generateHolderType(Base) { + var holderType = function TrustedValueHolderType(trustedValue) { + this.$$unwrapTrustedValue = function() { + return trustedValue; + }; + }; + if (Base) { + holderType.prototype = new Base(); + } + holderType.prototype.valueOf = function sceValueOf() { + return this.$$unwrapTrustedValue(); + }; + holderType.prototype.toString = function sceToString() { + return this.$$unwrapTrustedValue().toString(); + }; + return holderType; + } + + var trustedValueHolderBase = generateHolderType(), + byType = {}; + + byType[SCE_CONTEXTS.HTML] = generateHolderType(trustedValueHolderBase); + byType[SCE_CONTEXTS.CSS] = generateHolderType(trustedValueHolderBase); + byType[SCE_CONTEXTS.URL] = generateHolderType(trustedValueHolderBase); + byType[SCE_CONTEXTS.JS] = generateHolderType(trustedValueHolderBase); + byType[SCE_CONTEXTS.RESOURCE_URL] = generateHolderType(byType[SCE_CONTEXTS.URL]); + + /** + * @ngdoc method + * @name $sceDelegate#trustAs + * + * @description + * Returns an object that is trusted by angular for use in specified strict + * contextual escaping contexts (such as ng-bind-html, ng-include, any src + * attribute interpolation, any dom event binding attribute interpolation + * such as for onclick, etc.) that uses the provided value. + * See {@link ng.$sce $sce} for enabling strict contextual escaping. + * + * @param {string} type The kind of context in which this value is safe for use. e.g. url, + * resourceUrl, html, js and css. + * @param {*} value The value that that should be considered trusted/safe. + * @returns {*} A value that can be used to stand in for the provided `value` in places + * where Angular expects a $sce.trustAs() return value. + */ + function trustAs(type, trustedValue) { + var Constructor = (byType.hasOwnProperty(type) ? byType[type] : null); + if (!Constructor) { + throw $sceMinErr('icontext', + 'Attempted to trust a value in invalid context. Context: {0}; Value: {1}', + type, trustedValue); + } + if (trustedValue === null || trustedValue === undefined || trustedValue === '') { + return trustedValue; + } + // All the current contexts in SCE_CONTEXTS happen to be strings. In order to avoid trusting + // mutable objects, we ensure here that the value passed in is actually a string. + if (typeof trustedValue !== 'string') { + throw $sceMinErr('itype', + 'Attempted to trust a non-string value in a content requiring a string: Context: {0}', + type); + } + return new Constructor(trustedValue); + } + + /** + * @ngdoc method + * @name $sceDelegate#valueOf + * + * @description + * If the passed parameter had been returned by a prior call to {@link ng.$sceDelegate#trustAs + * `$sceDelegate.trustAs`}, returns the value that had been passed to {@link + * ng.$sceDelegate#trustAs `$sceDelegate.trustAs`}. + * + * If the passed parameter is not a value that had been returned by {@link + * ng.$sceDelegate#trustAs `$sceDelegate.trustAs`}, returns it as-is. + * + * @param {*} value The result of a prior {@link ng.$sceDelegate#trustAs `$sceDelegate.trustAs`} + * call or anything else. + * @returns {*} The `value` that was originally provided to {@link ng.$sceDelegate#trustAs + * `$sceDelegate.trustAs`} if `value` is the result of such a call. Otherwise, returns + * `value` unchanged. + */ + function valueOf(maybeTrusted) { + if (maybeTrusted instanceof trustedValueHolderBase) { + return maybeTrusted.$$unwrapTrustedValue(); + } else { + return maybeTrusted; + } + } + + /** + * @ngdoc method + * @name $sceDelegate#getTrusted + * + * @description + * Takes the result of a {@link ng.$sceDelegate#trustAs `$sceDelegate.trustAs`} call and + * returns the originally supplied value if the queried context type is a supertype of the + * created type. If this condition isn't satisfied, throws an exception. + * + * @param {string} type The kind of context in which this value is to be used. + * @param {*} maybeTrusted The result of a prior {@link ng.$sceDelegate#trustAs + * `$sceDelegate.trustAs`} call. + * @returns {*} The value the was originally provided to {@link ng.$sceDelegate#trustAs + * `$sceDelegate.trustAs`} if valid in this context. Otherwise, throws an exception. + */ + function getTrusted(type, maybeTrusted) { + if (maybeTrusted === null || maybeTrusted === undefined || maybeTrusted === '') { + return maybeTrusted; + } + var constructor = (byType.hasOwnProperty(type) ? byType[type] : null); + if (constructor && maybeTrusted instanceof constructor) { + return maybeTrusted.$$unwrapTrustedValue(); + } + // If we get here, then we may only take one of two actions. + // 1. sanitize the value for the requested type, or + // 2. throw an exception. + if (type === SCE_CONTEXTS.RESOURCE_URL) { + if (isResourceUrlAllowedByPolicy(maybeTrusted)) { + return maybeTrusted; + } else { + throw $sceMinErr('insecurl', + 'Blocked loading resource from url not allowed by $sceDelegate policy. URL: {0}', + maybeTrusted.toString()); + } + } else if (type === SCE_CONTEXTS.HTML) { + return htmlSanitizer(maybeTrusted); + } + throw $sceMinErr('unsafe', 'Attempting to use an unsafe value in a safe context.'); + } + + return { trustAs: trustAs, + getTrusted: getTrusted, + valueOf: valueOf }; + }]; +} + + +/** + * @ngdoc provider + * @name $sceProvider + * @description + * + * The $sceProvider provider allows developers to configure the {@link ng.$sce $sce} service. + * - enable/disable Strict Contextual Escaping (SCE) in a module + * - override the default implementation with a custom delegate + * + * Read more about {@link ng.$sce Strict Contextual Escaping (SCE)}. + */ + +/* jshint maxlen: false*/ + +/** + * @ngdoc service + * @name $sce + * @kind function + * + * @description + * + * `$sce` is a service that provides Strict Contextual Escaping services to AngularJS. + * + * # Strict Contextual Escaping + * + * Strict Contextual Escaping (SCE) is a mode in which AngularJS requires bindings in certain + * contexts to result in a value that is marked as safe to use for that context. One example of + * such a context is binding arbitrary html controlled by the user via `ng-bind-html`. We refer + * to these contexts as privileged or SCE contexts. + * + * As of version 1.2, Angular ships with SCE enabled by default. + * + * Note: When enabled (the default), IE<11 in quirks mode is not supported. In this mode, IE<11 allow + * one to execute arbitrary javascript by the use of the expression() syntax. Refer + * to learn more about them. + * You can ensure your document is in standards mode and not quirks mode by adding `` + * to the top of your HTML document. + * + * SCE assists in writing code in way that (a) is secure by default and (b) makes auditing for + * security vulnerabilities such as XSS, clickjacking, etc. a lot easier. + * + * Here's an example of a binding in a privileged context: + * + * ``` + * + *
      + * ``` + * + * Notice that `ng-bind-html` is bound to `userHtml` controlled by the user. With SCE + * disabled, this application allows the user to render arbitrary HTML into the DIV. + * In a more realistic example, one may be rendering user comments, blog articles, etc. via + * bindings. (HTML is just one example of a context where rendering user controlled input creates + * security vulnerabilities.) + * + * For the case of HTML, you might use a library, either on the client side, or on the server side, + * to sanitize unsafe HTML before binding to the value and rendering it in the document. + * + * How would you ensure that every place that used these types of bindings was bound to a value that + * was sanitized by your library (or returned as safe for rendering by your server?) How can you + * ensure that you didn't accidentally delete the line that sanitized the value, or renamed some + * properties/fields and forgot to update the binding to the sanitized value? + * + * To be secure by default, you want to ensure that any such bindings are disallowed unless you can + * determine that something explicitly says it's safe to use a value for binding in that + * context. You can then audit your code (a simple grep would do) to ensure that this is only done + * for those values that you can easily tell are safe - because they were received from your server, + * sanitized by your library, etc. You can organize your codebase to help with this - perhaps + * allowing only the files in a specific directory to do this. Ensuring that the internal API + * exposed by that code doesn't markup arbitrary values as safe then becomes a more manageable task. + * + * In the case of AngularJS' SCE service, one uses {@link ng.$sce#trustAs $sce.trustAs} + * (and shorthand methods such as {@link ng.$sce#trustAsHtml $sce.trustAsHtml}, etc.) to + * obtain values that will be accepted by SCE / privileged contexts. + * + * + * ## How does it work? + * + * In privileged contexts, directives and code will bind to the result of {@link ng.$sce#getTrusted + * $sce.getTrusted(context, value)} rather than to the value directly. Directives use {@link + * ng.$sce#parseAs $sce.parseAs} rather than `$parse` to watch attribute bindings, which performs the + * {@link ng.$sce#getTrusted $sce.getTrusted} behind the scenes on non-constant literals. + * + * As an example, {@link ng.directive:ngBindHtml ngBindHtml} uses {@link + * ng.$sce#parseAsHtml $sce.parseAsHtml(binding expression)}. Here's the actual code (slightly + * simplified): + * + * ``` + * var ngBindHtmlDirective = ['$sce', function($sce) { + * return function(scope, element, attr) { + * scope.$watch($sce.parseAsHtml(attr.ngBindHtml), function(value) { + * element.html(value || ''); + * }); + * }; + * }]; + * ``` + * + * ## Impact on loading templates + * + * This applies both to the {@link ng.directive:ngInclude `ng-include`} directive as well as + * `templateUrl`'s specified by {@link guide/directive directives}. + * + * By default, Angular only loads templates from the same domain and protocol as the application + * document. This is done by calling {@link ng.$sce#getTrustedResourceUrl + * $sce.getTrustedResourceUrl} on the template URL. To load templates from other domains and/or + * protocols, you may either either {@link ng.$sceDelegateProvider#resourceUrlWhitelist whitelist + * them} or {@link ng.$sce#trustAsResourceUrl wrap it} into a trusted value. + * + * *Please note*: + * The browser's + * [Same Origin Policy](https://code.google.com/p/browsersec/wiki/Part2#Same-origin_policy_for_XMLHttpRequest) + * and [Cross-Origin Resource Sharing (CORS)](http://www.w3.org/TR/cors/) + * policy apply in addition to this and may further restrict whether the template is successfully + * loaded. This means that without the right CORS policy, loading templates from a different domain + * won't work on all browsers. Also, loading templates from `file://` URL does not work on some + * browsers. + * + * ## This feels like too much overhead + * + * It's important to remember that SCE only applies to interpolation expressions. + * + * If your expressions are constant literals, they're automatically trusted and you don't need to + * call `$sce.trustAs` on them (remember to include the `ngSanitize` module) (e.g. + * `
      `) just works. + * + * Additionally, `a[href]` and `img[src]` automatically sanitize their URLs and do not pass them + * through {@link ng.$sce#getTrusted $sce.getTrusted}. SCE doesn't play a role here. + * + * The included {@link ng.$sceDelegate $sceDelegate} comes with sane defaults to allow you to load + * templates in `ng-include` from your application's domain without having to even know about SCE. + * It blocks loading templates from other domains or loading templates over http from an https + * served document. You can change these by setting your own custom {@link + * ng.$sceDelegateProvider#resourceUrlWhitelist whitelists} and {@link + * ng.$sceDelegateProvider#resourceUrlBlacklist blacklists} for matching such URLs. + * + * This significantly reduces the overhead. It is far easier to pay the small overhead and have an + * application that's secure and can be audited to verify that with much more ease than bolting + * security onto an application later. + * + * + * ## What trusted context types are supported? + * + * | Context | Notes | + * |---------------------|----------------| + * | `$sce.HTML` | For HTML that's safe to source into the application. The {@link ng.directive:ngBindHtml ngBindHtml} directive uses this context for bindings. If an unsafe value is encountered and the {@link ngSanitize $sanitize} module is present this will sanitize the value instead of throwing an error. | + * | `$sce.CSS` | For CSS that's safe to source into the application. Currently unused. Feel free to use it in your own directives. | + * | `$sce.URL` | For URLs that are safe to follow as links. Currently unused (`
      Note that `$sce.RESOURCE_URL` makes a stronger statement about the URL than `$sce.URL` does and therefore contexts requiring values trusted for `$sce.RESOURCE_URL` can be used anywhere that values trusted for `$sce.URL` are required. | + * | `$sce.JS` | For JavaScript that is safe to execute in your application's context. Currently unused. Feel free to use it in your own directives. | + * + * ## Format of items in {@link ng.$sceDelegateProvider#resourceUrlWhitelist resourceUrlWhitelist}/{@link ng.$sceDelegateProvider#resourceUrlBlacklist Blacklist}
      + * + * Each element in these arrays must be one of the following: + * + * - **'self'** + * - The special **string**, `'self'`, can be used to match against all URLs of the **same + * domain** as the application document using the **same protocol**. + * - **String** (except the special value `'self'`) + * - The string is matched against the full *normalized / absolute URL* of the resource + * being tested (substring matches are not good enough.) + * - There are exactly **two wildcard sequences** - `*` and `**`. All other characters + * match themselves. + * - `*`: matches zero or more occurrences of any character other than one of the following 6 + * characters: '`:`', '`/`', '`.`', '`?`', '`&`' and ';'. It's a useful wildcard for use + * in a whitelist. + * - `**`: matches zero or more occurrences of *any* character. As such, it's not + * appropriate for use in a scheme, domain, etc. as it would match too much. (e.g. + * http://**.example.com/ would match http://evil.com/?ignore=.example.com/ and that might + * not have been the intention.) Its usage at the very end of the path is ok. (e.g. + * http://foo.example.com/templates/**). + * - **RegExp** (*see caveat below*) + * - *Caveat*: While regular expressions are powerful and offer great flexibility, their syntax + * (and all the inevitable escaping) makes them *harder to maintain*. It's easy to + * accidentally introduce a bug when one updates a complex expression (imho, all regexes should + * have good test coverage). For instance, the use of `.` in the regex is correct only in a + * small number of cases. A `.` character in the regex used when matching the scheme or a + * subdomain could be matched against a `:` or literal `.` that was likely not intended. It + * is highly recommended to use the string patterns and only fall back to regular expressions + * as a last resort. + * - The regular expression must be an instance of RegExp (i.e. not a string.) It is + * matched against the **entire** *normalized / absolute URL* of the resource being tested + * (even when the RegExp did not have the `^` and `$` codes.) In addition, any flags + * present on the RegExp (such as multiline, global, ignoreCase) are ignored. + * - If you are generating your JavaScript from some other templating engine (not + * recommended, e.g. in issue [#4006](https://github.com/angular/angular.js/issues/4006)), + * remember to escape your regular expression (and be aware that you might need more than + * one level of escaping depending on your templating engine and the way you interpolated + * the value.) Do make use of your platform's escaping mechanism as it might be good + * enough before coding your own. E.g. Ruby has + * [Regexp.escape(str)](http://www.ruby-doc.org/core-2.0.0/Regexp.html#method-c-escape) + * and Python has [re.escape](http://docs.python.org/library/re.html#re.escape). + * Javascript lacks a similar built in function for escaping. Take a look at Google + * Closure library's [goog.string.regExpEscape(s)]( + * http://docs.closure-library.googlecode.com/git/closure_goog_string_string.js.source.html#line962). + * + * Refer {@link ng.$sceDelegateProvider $sceDelegateProvider} for an example. + * + * ## Show me an example using SCE. + * + * + * + *
      + *

      + * User comments
      + * By default, HTML that isn't explicitly trusted (e.g. Alice's comment) is sanitized when + * $sanitize is available. If $sanitize isn't available, this results in an error instead of an + * exploit. + *
      + *
      + * {{userComment.name}}: + * + *
      + *
      + *
      + *
      + *
      + * + * + * angular.module('mySceApp', ['ngSanitize']) + * .controller('AppController', ['$http', '$templateCache', '$sce', + * function($http, $templateCache, $sce) { + * var self = this; + * $http.get("test_data.json", {cache: $templateCache}).success(function(userComments) { + * self.userComments = userComments; + * }); + * self.explicitlyTrustedHtml = $sce.trustAsHtml( + * 'Hover over this text.'); + * }]); + * + * + * + * [ + * { "name": "Alice", + * "htmlComment": + * "Is anyone reading this?" + * }, + * { "name": "Bob", + * "htmlComment": "Yes! Am I the only other one?" + * } + * ] + * + * + * + * describe('SCE doc demo', function() { + * it('should sanitize untrusted values', function() { + * expect(element.all(by.css('.htmlComment')).first().getInnerHtml()) + * .toBe('Is anyone reading this?'); + * }); + * + * it('should NOT sanitize explicitly trusted values', function() { + * expect(element(by.id('explicitlyTrustedHtml')).getInnerHtml()).toBe( + * 'Hover over this text.'); + * }); + * }); + * + *
      + * + * + * + * ## Can I disable SCE completely? + * + * Yes, you can. However, this is strongly discouraged. SCE gives you a lot of security benefits + * for little coding overhead. It will be much harder to take an SCE disabled application and + * either secure it on your own or enable SCE at a later stage. It might make sense to disable SCE + * for cases where you have a lot of existing code that was written before SCE was introduced and + * you're migrating them a module at a time. + * + * That said, here's how you can completely disable SCE: + * + * ``` + * angular.module('myAppWithSceDisabledmyApp', []).config(function($sceProvider) { + * // Completely disable SCE. For demonstration purposes only! + * // Do not use in new projects. + * $sceProvider.enabled(false); + * }); + * ``` + * + */ +/* jshint maxlen: 100 */ + +function $SceProvider() { + var enabled = true; + + /** + * @ngdoc method + * @name $sceProvider#enabled + * @kind function + * + * @param {boolean=} value If provided, then enables/disables SCE. + * @return {boolean} true if SCE is enabled, false otherwise. + * + * @description + * Enables/disables SCE and returns the current value. + */ + this.enabled = function(value) { + if (arguments.length) { + enabled = !!value; + } + return enabled; + }; + + + /* Design notes on the default implementation for SCE. + * + * The API contract for the SCE delegate + * ------------------------------------- + * The SCE delegate object must provide the following 3 methods: + * + * - trustAs(contextEnum, value) + * This method is used to tell the SCE service that the provided value is OK to use in the + * contexts specified by contextEnum. It must return an object that will be accepted by + * getTrusted() for a compatible contextEnum and return this value. + * + * - valueOf(value) + * For values that were not produced by trustAs(), return them as is. For values that were + * produced by trustAs(), return the corresponding input value to trustAs. Basically, if + * trustAs is wrapping the given values into some type, this operation unwraps it when given + * such a value. + * + * - getTrusted(contextEnum, value) + * This function should return the a value that is safe to use in the context specified by + * contextEnum or throw and exception otherwise. + * + * NOTE: This contract deliberately does NOT state that values returned by trustAs() must be + * opaque or wrapped in some holder object. That happens to be an implementation detail. For + * instance, an implementation could maintain a registry of all trusted objects by context. In + * such a case, trustAs() would return the same object that was passed in. getTrusted() would + * return the same object passed in if it was found in the registry under a compatible context or + * throw an exception otherwise. An implementation might only wrap values some of the time based + * on some criteria. getTrusted() might return a value and not throw an exception for special + * constants or objects even if not wrapped. All such implementations fulfill this contract. + * + * + * A note on the inheritance model for SCE contexts + * ------------------------------------------------ + * I've used inheritance and made RESOURCE_URL wrapped types a subtype of URL wrapped types. This + * is purely an implementation details. + * + * The contract is simply this: + * + * getTrusted($sce.RESOURCE_URL, value) succeeding implies that getTrusted($sce.URL, value) + * will also succeed. + * + * Inheritance happens to capture this in a natural way. In some future, we + * may not use inheritance anymore. That is OK because no code outside of + * sce.js and sceSpecs.js would need to be aware of this detail. + */ + + this.$get = ['$parse', '$sceDelegate', function( + $parse, $sceDelegate) { + // Prereq: Ensure that we're not running in IE<11 quirks mode. In that mode, IE < 11 allow + // the "expression(javascript expression)" syntax which is insecure. + if (enabled && msie < 8) { + throw $sceMinErr('iequirks', + 'Strict Contextual Escaping does not support Internet Explorer version < 11 in quirks ' + + 'mode. You can fix this by adding the text to the top of your HTML ' + + 'document. See http://docs.angularjs.org/api/ng.$sce for more information.'); + } + + var sce = shallowCopy(SCE_CONTEXTS); + + /** + * @ngdoc method + * @name $sce#isEnabled + * @kind function + * + * @return {Boolean} true if SCE is enabled, false otherwise. If you want to set the value, you + * have to do it at module config time on {@link ng.$sceProvider $sceProvider}. + * + * @description + * Returns a boolean indicating if SCE is enabled. + */ + sce.isEnabled = function() { + return enabled; + }; + sce.trustAs = $sceDelegate.trustAs; + sce.getTrusted = $sceDelegate.getTrusted; + sce.valueOf = $sceDelegate.valueOf; + + if (!enabled) { + sce.trustAs = sce.getTrusted = function(type, value) { return value; }; + sce.valueOf = identity; + } + + /** + * @ngdoc method + * @name $sce#parseAs + * + * @description + * Converts Angular {@link guide/expression expression} into a function. This is like {@link + * ng.$parse $parse} and is identical when the expression is a literal constant. Otherwise, it + * wraps the expression in a call to {@link ng.$sce#getTrusted $sce.getTrusted(*type*, + * *result*)} + * + * @param {string} type The kind of SCE context in which this result will be used. + * @param {string} expression String expression to compile. + * @returns {function(context, locals)} a function which represents the compiled expression: + * + * * `context` – `{object}` – an object against which any expressions embedded in the strings + * are evaluated against (typically a scope object). + * * `locals` – `{object=}` – local variables context object, useful for overriding values in + * `context`. + */ + sce.parseAs = function sceParseAs(type, expr) { + var parsed = $parse(expr); + if (parsed.literal && parsed.constant) { + return parsed; + } else { + return $parse(expr, function(value) { + return sce.getTrusted(type, value); + }); + } + }; + + /** + * @ngdoc method + * @name $sce#trustAs + * + * @description + * Delegates to {@link ng.$sceDelegate#trustAs `$sceDelegate.trustAs`}. As such, + * returns an object that is trusted by angular for use in specified strict contextual + * escaping contexts (such as ng-bind-html, ng-include, any src attribute + * interpolation, any dom event binding attribute interpolation such as for onclick, etc.) + * that uses the provided value. See * {@link ng.$sce $sce} for enabling strict contextual + * escaping. + * + * @param {string} type The kind of context in which this value is safe for use. e.g. url, + * resource_url, html, js and css. + * @param {*} value The value that that should be considered trusted/safe. + * @returns {*} A value that can be used to stand in for the provided `value` in places + * where Angular expects a $sce.trustAs() return value. + */ + + /** + * @ngdoc method + * @name $sce#trustAsHtml + * + * @description + * Shorthand method. `$sce.trustAsHtml(value)` → + * {@link ng.$sceDelegate#trustAs `$sceDelegate.trustAs($sce.HTML, value)`} + * + * @param {*} value The value to trustAs. + * @returns {*} An object that can be passed to {@link ng.$sce#getTrustedHtml + * $sce.getTrustedHtml(value)} to obtain the original value. (privileged directives + * only accept expressions that are either literal constants or are the + * return value of {@link ng.$sce#trustAs $sce.trustAs}.) + */ + + /** + * @ngdoc method + * @name $sce#trustAsUrl + * + * @description + * Shorthand method. `$sce.trustAsUrl(value)` → + * {@link ng.$sceDelegate#trustAs `$sceDelegate.trustAs($sce.URL, value)`} + * + * @param {*} value The value to trustAs. + * @returns {*} An object that can be passed to {@link ng.$sce#getTrustedUrl + * $sce.getTrustedUrl(value)} to obtain the original value. (privileged directives + * only accept expressions that are either literal constants or are the + * return value of {@link ng.$sce#trustAs $sce.trustAs}.) + */ + + /** + * @ngdoc method + * @name $sce#trustAsResourceUrl + * + * @description + * Shorthand method. `$sce.trustAsResourceUrl(value)` → + * {@link ng.$sceDelegate#trustAs `$sceDelegate.trustAs($sce.RESOURCE_URL, value)`} + * + * @param {*} value The value to trustAs. + * @returns {*} An object that can be passed to {@link ng.$sce#getTrustedResourceUrl + * $sce.getTrustedResourceUrl(value)} to obtain the original value. (privileged directives + * only accept expressions that are either literal constants or are the return + * value of {@link ng.$sce#trustAs $sce.trustAs}.) + */ + + /** + * @ngdoc method + * @name $sce#trustAsJs + * + * @description + * Shorthand method. `$sce.trustAsJs(value)` → + * {@link ng.$sceDelegate#trustAs `$sceDelegate.trustAs($sce.JS, value)`} + * + * @param {*} value The value to trustAs. + * @returns {*} An object that can be passed to {@link ng.$sce#getTrustedJs + * $sce.getTrustedJs(value)} to obtain the original value. (privileged directives + * only accept expressions that are either literal constants or are the + * return value of {@link ng.$sce#trustAs $sce.trustAs}.) + */ + + /** + * @ngdoc method + * @name $sce#getTrusted + * + * @description + * Delegates to {@link ng.$sceDelegate#getTrusted `$sceDelegate.getTrusted`}. As such, + * takes the result of a {@link ng.$sce#trustAs `$sce.trustAs`}() call and returns the + * originally supplied value if the queried context type is a supertype of the created type. + * If this condition isn't satisfied, throws an exception. + * + * @param {string} type The kind of context in which this value is to be used. + * @param {*} maybeTrusted The result of a prior {@link ng.$sce#trustAs `$sce.trustAs`} + * call. + * @returns {*} The value the was originally provided to + * {@link ng.$sce#trustAs `$sce.trustAs`} if valid in this context. + * Otherwise, throws an exception. + */ + + /** + * @ngdoc method + * @name $sce#getTrustedHtml + * + * @description + * Shorthand method. `$sce.getTrustedHtml(value)` → + * {@link ng.$sceDelegate#getTrusted `$sceDelegate.getTrusted($sce.HTML, value)`} + * + * @param {*} value The value to pass to `$sce.getTrusted`. + * @returns {*} The return value of `$sce.getTrusted($sce.HTML, value)` + */ + + /** + * @ngdoc method + * @name $sce#getTrustedCss + * + * @description + * Shorthand method. `$sce.getTrustedCss(value)` → + * {@link ng.$sceDelegate#getTrusted `$sceDelegate.getTrusted($sce.CSS, value)`} + * + * @param {*} value The value to pass to `$sce.getTrusted`. + * @returns {*} The return value of `$sce.getTrusted($sce.CSS, value)` + */ + + /** + * @ngdoc method + * @name $sce#getTrustedUrl + * + * @description + * Shorthand method. `$sce.getTrustedUrl(value)` → + * {@link ng.$sceDelegate#getTrusted `$sceDelegate.getTrusted($sce.URL, value)`} + * + * @param {*} value The value to pass to `$sce.getTrusted`. + * @returns {*} The return value of `$sce.getTrusted($sce.URL, value)` + */ + + /** + * @ngdoc method + * @name $sce#getTrustedResourceUrl + * + * @description + * Shorthand method. `$sce.getTrustedResourceUrl(value)` → + * {@link ng.$sceDelegate#getTrusted `$sceDelegate.getTrusted($sce.RESOURCE_URL, value)`} + * + * @param {*} value The value to pass to `$sceDelegate.getTrusted`. + * @returns {*} The return value of `$sce.getTrusted($sce.RESOURCE_URL, value)` + */ + + /** + * @ngdoc method + * @name $sce#getTrustedJs + * + * @description + * Shorthand method. `$sce.getTrustedJs(value)` → + * {@link ng.$sceDelegate#getTrusted `$sceDelegate.getTrusted($sce.JS, value)`} + * + * @param {*} value The value to pass to `$sce.getTrusted`. + * @returns {*} The return value of `$sce.getTrusted($sce.JS, value)` + */ + + /** + * @ngdoc method + * @name $sce#parseAsHtml + * + * @description + * Shorthand method. `$sce.parseAsHtml(expression string)` → + * {@link ng.$sce#parseAs `$sce.parseAs($sce.HTML, value)`} + * + * @param {string} expression String expression to compile. + * @returns {function(context, locals)} a function which represents the compiled expression: + * + * * `context` – `{object}` – an object against which any expressions embedded in the strings + * are evaluated against (typically a scope object). + * * `locals` – `{object=}` – local variables context object, useful for overriding values in + * `context`. + */ + + /** + * @ngdoc method + * @name $sce#parseAsCss + * + * @description + * Shorthand method. `$sce.parseAsCss(value)` → + * {@link ng.$sce#parseAs `$sce.parseAs($sce.CSS, value)`} + * + * @param {string} expression String expression to compile. + * @returns {function(context, locals)} a function which represents the compiled expression: + * + * * `context` – `{object}` – an object against which any expressions embedded in the strings + * are evaluated against (typically a scope object). + * * `locals` – `{object=}` – local variables context object, useful for overriding values in + * `context`. + */ + + /** + * @ngdoc method + * @name $sce#parseAsUrl + * + * @description + * Shorthand method. `$sce.parseAsUrl(value)` → + * {@link ng.$sce#parseAs `$sce.parseAs($sce.URL, value)`} + * + * @param {string} expression String expression to compile. + * @returns {function(context, locals)} a function which represents the compiled expression: + * + * * `context` – `{object}` – an object against which any expressions embedded in the strings + * are evaluated against (typically a scope object). + * * `locals` – `{object=}` – local variables context object, useful for overriding values in + * `context`. + */ + + /** + * @ngdoc method + * @name $sce#parseAsResourceUrl + * + * @description + * Shorthand method. `$sce.parseAsResourceUrl(value)` → + * {@link ng.$sce#parseAs `$sce.parseAs($sce.RESOURCE_URL, value)`} + * + * @param {string} expression String expression to compile. + * @returns {function(context, locals)} a function which represents the compiled expression: + * + * * `context` – `{object}` – an object against which any expressions embedded in the strings + * are evaluated against (typically a scope object). + * * `locals` – `{object=}` – local variables context object, useful for overriding values in + * `context`. + */ + + /** + * @ngdoc method + * @name $sce#parseAsJs + * + * @description + * Shorthand method. `$sce.parseAsJs(value)` → + * {@link ng.$sce#parseAs `$sce.parseAs($sce.JS, value)`} + * + * @param {string} expression String expression to compile. + * @returns {function(context, locals)} a function which represents the compiled expression: + * + * * `context` – `{object}` – an object against which any expressions embedded in the strings + * are evaluated against (typically a scope object). + * * `locals` – `{object=}` – local variables context object, useful for overriding values in + * `context`. + */ + + // Shorthand delegations. + var parse = sce.parseAs, + getTrusted = sce.getTrusted, + trustAs = sce.trustAs; + + forEach(SCE_CONTEXTS, function(enumValue, name) { + var lName = lowercase(name); + sce[camelCase("parse_as_" + lName)] = function(expr) { + return parse(enumValue, expr); + }; + sce[camelCase("get_trusted_" + lName)] = function(value) { + return getTrusted(enumValue, value); + }; + sce[camelCase("trust_as_" + lName)] = function(value) { + return trustAs(enumValue, value); + }; + }); + + return sce; + }]; +} + +/** + * !!! This is an undocumented "private" service !!! + * + * @name $sniffer + * @requires $window + * @requires $document + * + * @property {boolean} history Does the browser support html5 history api ? + * @property {boolean} transitions Does the browser support CSS transition events ? + * @property {boolean} animations Does the browser support CSS animation events ? + * + * @description + * This is very simple implementation of testing browser's features. + */ +function $SnifferProvider() { + this.$get = ['$window', '$document', function($window, $document) { + var eventSupport = {}, + android = + int((/android (\d+)/.exec(lowercase(($window.navigator || {}).userAgent)) || [])[1]), + boxee = /Boxee/i.test(($window.navigator || {}).userAgent), + document = $document[0] || {}, + vendorPrefix, + vendorRegex = /^(Moz|webkit|ms)(?=[A-Z])/, + bodyStyle = document.body && document.body.style, + transitions = false, + animations = false, + match; + + if (bodyStyle) { + for (var prop in bodyStyle) { + if (match = vendorRegex.exec(prop)) { + vendorPrefix = match[0]; + vendorPrefix = vendorPrefix.substr(0, 1).toUpperCase() + vendorPrefix.substr(1); + break; + } + } + + if (!vendorPrefix) { + vendorPrefix = ('WebkitOpacity' in bodyStyle) && 'webkit'; + } + + transitions = !!(('transition' in bodyStyle) || (vendorPrefix + 'Transition' in bodyStyle)); + animations = !!(('animation' in bodyStyle) || (vendorPrefix + 'Animation' in bodyStyle)); + + if (android && (!transitions || !animations)) { + transitions = isString(document.body.style.webkitTransition); + animations = isString(document.body.style.webkitAnimation); + } + } + + + return { + // Android has history.pushState, but it does not update location correctly + // so let's not use the history API at all. + // http://code.google.com/p/android/issues/detail?id=17471 + // https://github.com/angular/angular.js/issues/904 + + // older webkit browser (533.9) on Boxee box has exactly the same problem as Android has + // so let's not use the history API also + // We are purposefully using `!(android < 4)` to cover the case when `android` is undefined + // jshint -W018 + history: !!($window.history && $window.history.pushState && !(android < 4) && !boxee), + // jshint +W018 + hasEvent: function(event) { + // IE9 implements 'input' event it's so fubared that we rather pretend that it doesn't have + // it. In particular the event is not fired when backspace or delete key are pressed or + // when cut operation is performed. + // IE10+ implements 'input' event but it erroneously fires under various situations, + // e.g. when placeholder changes, or a form is focused. + if (event === 'input' && msie <= 11) return false; + + if (isUndefined(eventSupport[event])) { + var divElm = document.createElement('div'); + eventSupport[event] = 'on' + event in divElm; + } + + return eventSupport[event]; + }, + csp: csp(), + vendorPrefix: vendorPrefix, + transitions: transitions, + animations: animations, + android: android + }; + }]; +} + +var $compileMinErr = minErr('$compile'); + +/** + * @ngdoc service + * @name $templateRequest + * + * @description + * The `$templateRequest` service runs security checks then downloads the provided template using + * `$http` and, upon success, stores the contents inside of `$templateCache`. If the HTTP request + * fails or the response data of the HTTP request is empty, a `$compile` error will be thrown (the + * exception can be thwarted by setting the 2nd parameter of the function to true). Note that the + * contents of `$templateCache` are trusted, so the call to `$sce.getTrustedUrl(tpl)` is omitted + * when `tpl` is of type string and `$templateCache` has the matching entry. + * + * @param {string|TrustedResourceUrl} tpl The HTTP request template URL + * @param {boolean=} ignoreRequestError Whether or not to ignore the exception when the request fails or the template is empty + * + * @return {Promise} the HTTP Promise for the given. + * + * @property {number} totalPendingRequests total amount of pending template requests being downloaded. + */ +function $TemplateRequestProvider() { + this.$get = ['$templateCache', '$http', '$q', '$sce', function($templateCache, $http, $q, $sce) { + function handleRequestFn(tpl, ignoreRequestError) { + handleRequestFn.totalPendingRequests++; + + // We consider the template cache holds only trusted templates, so + // there's no need to go through whitelisting again for keys that already + // are included in there. This also makes Angular accept any script + // directive, no matter its name. However, we still need to unwrap trusted + // types. + if (!isString(tpl) || !$templateCache.get(tpl)) { + tpl = $sce.getTrustedResourceUrl(tpl); + } + + var transformResponse = $http.defaults && $http.defaults.transformResponse; + + if (isArray(transformResponse)) { + transformResponse = transformResponse.filter(function(transformer) { + return transformer !== defaultHttpResponseTransform; + }); + } else if (transformResponse === defaultHttpResponseTransform) { + transformResponse = null; + } + + var httpOptions = { + cache: $templateCache, + transformResponse: transformResponse + }; + + return $http.get(tpl, httpOptions) + ['finally'](function() { + handleRequestFn.totalPendingRequests--; + }) + .then(function(response) { + return response.data; + }, handleError); + + function handleError(resp) { + if (!ignoreRequestError) { + throw $compileMinErr('tpload', 'Failed to load template: {0}', tpl); + } + return $q.reject(resp); + } + } + + handleRequestFn.totalPendingRequests = 0; + + return handleRequestFn; + }]; +} + +function $$TestabilityProvider() { + this.$get = ['$rootScope', '$browser', '$location', + function($rootScope, $browser, $location) { + + /** + * @name $testability + * + * @description + * The private $$testability service provides a collection of methods for use when debugging + * or by automated test and debugging tools. + */ + var testability = {}; + + /** + * @name $$testability#findBindings + * + * @description + * Returns an array of elements that are bound (via ng-bind or {{}}) + * to expressions matching the input. + * + * @param {Element} element The element root to search from. + * @param {string} expression The binding expression to match. + * @param {boolean} opt_exactMatch If true, only returns exact matches + * for the expression. Filters and whitespace are ignored. + */ + testability.findBindings = function(element, expression, opt_exactMatch) { + var bindings = element.getElementsByClassName('ng-binding'); + var matches = []; + forEach(bindings, function(binding) { + var dataBinding = angular.element(binding).data('$binding'); + if (dataBinding) { + forEach(dataBinding, function(bindingName) { + if (opt_exactMatch) { + var matcher = new RegExp('(^|\\s)' + escapeForRegexp(expression) + '(\\s|\\||$)'); + if (matcher.test(bindingName)) { + matches.push(binding); + } + } else { + if (bindingName.indexOf(expression) != -1) { + matches.push(binding); + } + } + }); + } + }); + return matches; + }; + + /** + * @name $$testability#findModels + * + * @description + * Returns an array of elements that are two-way found via ng-model to + * expressions matching the input. + * + * @param {Element} element The element root to search from. + * @param {string} expression The model expression to match. + * @param {boolean} opt_exactMatch If true, only returns exact matches + * for the expression. + */ + testability.findModels = function(element, expression, opt_exactMatch) { + var prefixes = ['ng-', 'data-ng-', 'ng\\:']; + for (var p = 0; p < prefixes.length; ++p) { + var attributeEquals = opt_exactMatch ? '=' : '*='; + var selector = '[' + prefixes[p] + 'model' + attributeEquals + '"' + expression + '"]'; + var elements = element.querySelectorAll(selector); + if (elements.length) { + return elements; + } + } + }; + + /** + * @name $$testability#getLocation + * + * @description + * Shortcut for getting the location in a browser agnostic way. Returns + * the path, search, and hash. (e.g. /path?a=b#hash) + */ + testability.getLocation = function() { + return $location.url(); + }; + + /** + * @name $$testability#setLocation + * + * @description + * Shortcut for navigating to a location without doing a full page reload. + * + * @param {string} url The location url (path, search and hash, + * e.g. /path?a=b#hash) to go to. + */ + testability.setLocation = function(url) { + if (url !== $location.url()) { + $location.url(url); + $rootScope.$digest(); + } + }; + + /** + * @name $$testability#whenStable + * + * @description + * Calls the callback when $timeout and $http requests are completed. + * + * @param {function} callback + */ + testability.whenStable = function(callback) { + $browser.notifyWhenNoOutstandingRequests(callback); + }; + + return testability; + }]; +} + +function $TimeoutProvider() { + this.$get = ['$rootScope', '$browser', '$q', '$$q', '$exceptionHandler', + function($rootScope, $browser, $q, $$q, $exceptionHandler) { + var deferreds = {}; + + + /** + * @ngdoc service + * @name $timeout + * + * @description + * Angular's wrapper for `window.setTimeout`. The `fn` function is wrapped into a try/catch + * block and delegates any exceptions to + * {@link ng.$exceptionHandler $exceptionHandler} service. + * + * The return value of registering a timeout function is a promise, which will be resolved when + * the timeout is reached and the timeout function is executed. + * + * To cancel a timeout request, call `$timeout.cancel(promise)`. + * + * In tests you can use {@link ngMock.$timeout `$timeout.flush()`} to + * synchronously flush the queue of deferred functions. + * + * @param {function()} fn A function, whose execution should be delayed. + * @param {number=} [delay=0] Delay in milliseconds. + * @param {boolean=} [invokeApply=true] If set to `false` skips model dirty checking, otherwise + * will invoke `fn` within the {@link ng.$rootScope.Scope#$apply $apply} block. + * @returns {Promise} Promise that will be resolved when the timeout is reached. The value this + * promise will be resolved with is the return value of the `fn` function. + * + */ + function timeout(fn, delay, invokeApply) { + var skipApply = (isDefined(invokeApply) && !invokeApply), + deferred = (skipApply ? $$q : $q).defer(), + promise = deferred.promise, + timeoutId; + + timeoutId = $browser.defer(function() { + try { + deferred.resolve(fn()); + } catch (e) { + deferred.reject(e); + $exceptionHandler(e); + } + finally { + delete deferreds[promise.$$timeoutId]; + } + + if (!skipApply) $rootScope.$apply(); + }, delay); + + promise.$$timeoutId = timeoutId; + deferreds[timeoutId] = deferred; + + return promise; + } + + + /** + * @ngdoc method + * @name $timeout#cancel + * + * @description + * Cancels a task associated with the `promise`. As a result of this, the promise will be + * resolved with a rejection. + * + * @param {Promise=} promise Promise returned by the `$timeout` function. + * @returns {boolean} Returns `true` if the task hasn't executed yet and was successfully + * canceled. + */ + timeout.cancel = function(promise) { + if (promise && promise.$$timeoutId in deferreds) { + deferreds[promise.$$timeoutId].reject('canceled'); + delete deferreds[promise.$$timeoutId]; + return $browser.defer.cancel(promise.$$timeoutId); + } + return false; + }; + + return timeout; + }]; +} + +// NOTE: The usage of window and document instead of $window and $document here is +// deliberate. This service depends on the specific behavior of anchor nodes created by the +// browser (resolving and parsing URLs) that is unlikely to be provided by mock objects and +// cause us to break tests. In addition, when the browser resolves a URL for XHR, it +// doesn't know about mocked locations and resolves URLs to the real document - which is +// exactly the behavior needed here. There is little value is mocking these out for this +// service. +var urlParsingNode = document.createElement("a"); +var originUrl = urlResolve(window.location.href); + + +/** + * + * Implementation Notes for non-IE browsers + * ---------------------------------------- + * Assigning a URL to the href property of an anchor DOM node, even one attached to the DOM, + * results both in the normalizing and parsing of the URL. Normalizing means that a relative + * URL will be resolved into an absolute URL in the context of the application document. + * Parsing means that the anchor node's host, hostname, protocol, port, pathname and related + * properties are all populated to reflect the normalized URL. This approach has wide + * compatibility - Safari 1+, Mozilla 1+, Opera 7+,e etc. See + * http://www.aptana.com/reference/html/api/HTMLAnchorElement.html + * + * Implementation Notes for IE + * --------------------------- + * IE <= 10 normalizes the URL when assigned to the anchor node similar to the other + * browsers. However, the parsed components will not be set if the URL assigned did not specify + * them. (e.g. if you assign a.href = "foo", then a.protocol, a.host, etc. will be empty.) We + * work around that by performing the parsing in a 2nd step by taking a previously normalized + * URL (e.g. by assigning to a.href) and assigning it a.href again. This correctly populates the + * properties such as protocol, hostname, port, etc. + * + * References: + * http://developer.mozilla.org/en-US/docs/Web/API/HTMLAnchorElement + * http://www.aptana.com/reference/html/api/HTMLAnchorElement.html + * http://url.spec.whatwg.org/#urlutils + * https://github.com/angular/angular.js/pull/2902 + * http://james.padolsey.com/javascript/parsing-urls-with-the-dom/ + * + * @kind function + * @param {string} url The URL to be parsed. + * @description Normalizes and parses a URL. + * @returns {object} Returns the normalized URL as a dictionary. + * + * | member name | Description | + * |---------------|----------------| + * | href | A normalized version of the provided URL if it was not an absolute URL | + * | protocol | The protocol including the trailing colon | + * | host | The host and port (if the port is non-default) of the normalizedUrl | + * | search | The search params, minus the question mark | + * | hash | The hash string, minus the hash symbol + * | hostname | The hostname + * | port | The port, without ":" + * | pathname | The pathname, beginning with "/" + * + */ +function urlResolve(url) { + var href = url; + + if (msie) { + // Normalize before parse. Refer Implementation Notes on why this is + // done in two steps on IE. + urlParsingNode.setAttribute("href", href); + href = urlParsingNode.href; + } + + urlParsingNode.setAttribute('href', href); + + // urlParsingNode provides the UrlUtils interface - http://url.spec.whatwg.org/#urlutils + return { + href: urlParsingNode.href, + protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, '') : '', + host: urlParsingNode.host, + search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, '') : '', + hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '', + hostname: urlParsingNode.hostname, + port: urlParsingNode.port, + pathname: (urlParsingNode.pathname.charAt(0) === '/') + ? urlParsingNode.pathname + : '/' + urlParsingNode.pathname + }; +} + +/** + * Parse a request URL and determine whether this is a same-origin request as the application document. + * + * @param {string|object} requestUrl The url of the request as a string that will be resolved + * or a parsed URL object. + * @returns {boolean} Whether the request is for the same origin as the application document. + */ +function urlIsSameOrigin(requestUrl) { + var parsed = (isString(requestUrl)) ? urlResolve(requestUrl) : requestUrl; + return (parsed.protocol === originUrl.protocol && + parsed.host === originUrl.host); +} + +/** + * @ngdoc service + * @name $window + * + * @description + * A reference to the browser's `window` object. While `window` + * is globally available in JavaScript, it causes testability problems, because + * it is a global variable. In angular we always refer to it through the + * `$window` service, so it may be overridden, removed or mocked for testing. + * + * Expressions, like the one defined for the `ngClick` directive in the example + * below, are evaluated with respect to the current scope. Therefore, there is + * no risk of inadvertently coding in a dependency on a global value in such an + * expression. + * + * @example + + + +
      + + +
      +
      + + it('should display the greeting in the input box', function() { + element(by.model('greeting')).sendKeys('Hello, E2E Tests'); + // If we click the button it will block the test runner + // element(':button').click(); + }); + +
      + */ +function $WindowProvider() { + this.$get = valueFn(window); +} + +/* global currencyFilter: true, + dateFilter: true, + filterFilter: true, + jsonFilter: true, + limitToFilter: true, + lowercaseFilter: true, + numberFilter: true, + orderByFilter: true, + uppercaseFilter: true, + */ + +/** + * @ngdoc provider + * @name $filterProvider + * @description + * + * Filters are just functions which transform input to an output. However filters need to be + * Dependency Injected. To achieve this a filter definition consists of a factory function which is + * annotated with dependencies and is responsible for creating a filter function. + * + *
      + * **Note:** Filter names must be valid angular {@link expression} identifiers, such as `uppercase` or `orderBy`. + * Names with special characters, such as hyphens and dots, are not allowed. If you wish to namespace + * your filters, then you can use capitalization (`myappSubsectionFilterx`) or underscores + * (`myapp_subsection_filterx`). + *
      + * + * ```js + * // Filter registration + * function MyModule($provide, $filterProvider) { + * // create a service to demonstrate injection (not always needed) + * $provide.value('greet', function(name){ + * return 'Hello ' + name + '!'; + * }); + * + * // register a filter factory which uses the + * // greet service to demonstrate DI. + * $filterProvider.register('greet', function(greet){ + * // return the filter function which uses the greet service + * // to generate salutation + * return function(text) { + * // filters need to be forgiving so check input validity + * return text && greet(text) || text; + * }; + * }); + * } + * ``` + * + * The filter function is registered with the `$injector` under the filter name suffix with + * `Filter`. + * + * ```js + * it('should be the same instance', inject( + * function($filterProvider) { + * $filterProvider.register('reverse', function(){ + * return ...; + * }); + * }, + * function($filter, reverseFilter) { + * expect($filter('reverse')).toBe(reverseFilter); + * }); + * ``` + * + * + * For more information about how angular filters work, and how to create your own filters, see + * {@link guide/filter Filters} in the Angular Developer Guide. + */ + +/** + * @ngdoc service + * @name $filter + * @kind function + * @description + * Filters are used for formatting data displayed to the user. + * + * The general syntax in templates is as follows: + * + * {{ expression [| filter_name[:parameter_value] ... ] }} + * + * @param {String} name Name of the filter function to retrieve + * @return {Function} the filter function + * @example + + +
      +

      {{ originalText }}

      +

      {{ filteredText }}

      +
      +
      + + + angular.module('filterExample', []) + .controller('MainCtrl', function($scope, $filter) { + $scope.originalText = 'hello'; + $scope.filteredText = $filter('uppercase')($scope.originalText); + }); + +
      + */ +$FilterProvider.$inject = ['$provide']; +function $FilterProvider($provide) { + var suffix = 'Filter'; + + /** + * @ngdoc method + * @name $filterProvider#register + * @param {string|Object} name Name of the filter function, or an object map of filters where + * the keys are the filter names and the values are the filter factories. + * + *
      + * **Note:** Filter names must be valid angular {@link expression} identifiers, such as `uppercase` or `orderBy`. + * Names with special characters, such as hyphens and dots, are not allowed. If you wish to namespace + * your filters, then you can use capitalization (`myappSubsectionFilterx`) or underscores + * (`myapp_subsection_filterx`). + *
      + * @returns {Object} Registered filter instance, or if a map of filters was provided then a map + * of the registered filter instances. + */ + function register(name, factory) { + if (isObject(name)) { + var filters = {}; + forEach(name, function(filter, key) { + filters[key] = register(key, filter); + }); + return filters; + } else { + return $provide.factory(name + suffix, factory); + } + } + this.register = register; + + this.$get = ['$injector', function($injector) { + return function(name) { + return $injector.get(name + suffix); + }; + }]; + + //////////////////////////////////////// + + /* global + currencyFilter: false, + dateFilter: false, + filterFilter: false, + jsonFilter: false, + limitToFilter: false, + lowercaseFilter: false, + numberFilter: false, + orderByFilter: false, + uppercaseFilter: false, + */ + + register('currency', currencyFilter); + register('date', dateFilter); + register('filter', filterFilter); + register('json', jsonFilter); + register('limitTo', limitToFilter); + register('lowercase', lowercaseFilter); + register('number', numberFilter); + register('orderBy', orderByFilter); + register('uppercase', uppercaseFilter); +} + +/** + * @ngdoc filter + * @name filter + * @kind function + * + * @description + * Selects a subset of items from `array` and returns it as a new array. + * + * @param {Array} array The source array. + * @param {string|Object|function()} expression The predicate to be used for selecting items from + * `array`. + * + * Can be one of: + * + * - `string`: The string is used for matching against the contents of the `array`. All strings or + * objects with string properties in `array` that match this string will be returned. This also + * applies to nested object properties. + * The predicate can be negated by prefixing the string with `!`. + * + * - `Object`: A pattern object can be used to filter specific properties on objects contained + * by `array`. For example `{name:"M", phone:"1"}` predicate will return an array of items + * which have property `name` containing "M" and property `phone` containing "1". A special + * property name `$` can be used (as in `{$:"text"}`) to accept a match against any + * property of the object or its nested object properties. That's equivalent to the simple + * substring match with a `string` as described above. The predicate can be negated by prefixing + * the string with `!`. + * For example `{name: "!M"}` predicate will return an array of items which have property `name` + * not containing "M". + * + * Note that a named property will match properties on the same level only, while the special + * `$` property will match properties on the same level or deeper. E.g. an array item like + * `{name: {first: 'John', last: 'Doe'}}` will **not** be matched by `{name: 'John'}`, but + * **will** be matched by `{$: 'John'}`. + * + * - `function(value, index)`: A predicate function can be used to write arbitrary filters. The + * function is called for each element of `array`. The final result is an array of those + * elements that the predicate returned true for. + * + * @param {function(actual, expected)|true|undefined} comparator Comparator which is used in + * determining if the expected value (from the filter expression) and actual value (from + * the object in the array) should be considered a match. + * + * Can be one of: + * + * - `function(actual, expected)`: + * The function will be given the object value and the predicate value to compare and + * should return true if both values should be considered equal. + * + * - `true`: A shorthand for `function(actual, expected) { return angular.equals(actual, expected)}`. + * This is essentially strict comparison of expected and actual. + * + * - `false|undefined`: A short hand for a function which will look for a substring match in case + * insensitive way. + * + * @example + + +
      + + Search: + + + + + + +
      NamePhone
      {{friend.name}}{{friend.phone}}
      +
      + Any:
      + Name only
      + Phone only
      + Equality
      + + + + + + +
      NamePhone
      {{friendObj.name}}{{friendObj.phone}}
      +
      + + var expectFriendNames = function(expectedNames, key) { + element.all(by.repeater(key + ' in friends').column(key + '.name')).then(function(arr) { + arr.forEach(function(wd, i) { + expect(wd.getText()).toMatch(expectedNames[i]); + }); + }); + }; + + it('should search across all fields when filtering with a string', function() { + var searchText = element(by.model('searchText')); + searchText.clear(); + searchText.sendKeys('m'); + expectFriendNames(['Mary', 'Mike', 'Adam'], 'friend'); + + searchText.clear(); + searchText.sendKeys('76'); + expectFriendNames(['John', 'Julie'], 'friend'); + }); + + it('should search in specific fields when filtering with a predicate object', function() { + var searchAny = element(by.model('search.$')); + searchAny.clear(); + searchAny.sendKeys('i'); + expectFriendNames(['Mary', 'Mike', 'Julie', 'Juliette'], 'friendObj'); + }); + it('should use a equal comparison when comparator is true', function() { + var searchName = element(by.model('search.name')); + var strict = element(by.model('strict')); + searchName.clear(); + searchName.sendKeys('Julie'); + strict.click(); + expectFriendNames(['Julie'], 'friendObj'); + }); + +
      + */ +function filterFilter() { + return function(array, expression, comparator) { + if (!isArray(array)) return array; + + var expressionType = (expression !== null) ? typeof expression : 'null'; + var predicateFn; + var matchAgainstAnyProp; + + switch (expressionType) { + case 'function': + predicateFn = expression; + break; + case 'boolean': + case 'null': + case 'number': + case 'string': + matchAgainstAnyProp = true; + //jshint -W086 + case 'object': + //jshint +W086 + predicateFn = createPredicateFn(expression, comparator, matchAgainstAnyProp); + break; + default: + return array; + } + + return array.filter(predicateFn); + }; +} + +// Helper functions for `filterFilter` +function createPredicateFn(expression, comparator, matchAgainstAnyProp) { + var shouldMatchPrimitives = isObject(expression) && ('$' in expression); + var predicateFn; + + if (comparator === true) { + comparator = equals; + } else if (!isFunction(comparator)) { + comparator = function(actual, expected) { + if (isUndefined(actual)) { + // No substring matching against `undefined` + return false; + } + if ((actual === null) || (expected === null)) { + // No substring matching against `null`; only match against `null` + return actual === expected; + } + if (isObject(actual) || isObject(expected)) { + // Prevent an object to be considered equal to a string like `'[object'` + return false; + } + + actual = lowercase('' + actual); + expected = lowercase('' + expected); + return actual.indexOf(expected) !== -1; + }; + } + + predicateFn = function(item) { + if (shouldMatchPrimitives && !isObject(item)) { + return deepCompare(item, expression.$, comparator, false); + } + return deepCompare(item, expression, comparator, matchAgainstAnyProp); + }; + + return predicateFn; +} + +function deepCompare(actual, expected, comparator, matchAgainstAnyProp, dontMatchWholeObject) { + var actualType = (actual !== null) ? typeof actual : 'null'; + var expectedType = (expected !== null) ? typeof expected : 'null'; + + if ((expectedType === 'string') && (expected.charAt(0) === '!')) { + return !deepCompare(actual, expected.substring(1), comparator, matchAgainstAnyProp); + } else if (isArray(actual)) { + // In case `actual` is an array, consider it a match + // if ANY of it's items matches `expected` + return actual.some(function(item) { + return deepCompare(item, expected, comparator, matchAgainstAnyProp); + }); + } + + switch (actualType) { + case 'object': + var key; + if (matchAgainstAnyProp) { + for (key in actual) { + if ((key.charAt(0) !== '$') && deepCompare(actual[key], expected, comparator, true)) { + return true; + } + } + return dontMatchWholeObject ? false : deepCompare(actual, expected, comparator, false); + } else if (expectedType === 'object') { + for (key in expected) { + var expectedVal = expected[key]; + if (isFunction(expectedVal) || isUndefined(expectedVal)) { + continue; + } + + var matchAnyProperty = key === '$'; + var actualVal = matchAnyProperty ? actual : actual[key]; + if (!deepCompare(actualVal, expectedVal, comparator, matchAnyProperty, matchAnyProperty)) { + return false; + } + } + return true; + } else { + return comparator(actual, expected); + } + break; + case 'function': + return false; + default: + return comparator(actual, expected); + } +} + +/** + * @ngdoc filter + * @name currency + * @kind function + * + * @description + * Formats a number as a currency (ie $1,234.56). When no currency symbol is provided, default + * symbol for current locale is used. + * + * @param {number} amount Input to filter. + * @param {string=} symbol Currency symbol or identifier to be displayed. + * @param {number=} fractionSize Number of decimal places to round the amount to, defaults to default max fraction size for current locale + * @returns {string} Formatted number. + * + * + * @example + + + +
      +
      + default currency symbol ($): {{amount | currency}}
      + custom currency identifier (USD$): {{amount | currency:"USD$"}} + no fractions (0): {{amount | currency:"USD$":0}} +
      +
      + + it('should init with 1234.56', function() { + expect(element(by.id('currency-default')).getText()).toBe('$1,234.56'); + expect(element(by.id('currency-custom')).getText()).toBe('USD$1,234.56'); + expect(element(by.id('currency-no-fractions')).getText()).toBe('USD$1,235'); + }); + it('should update', function() { + if (browser.params.browser == 'safari') { + // Safari does not understand the minus key. See + // https://github.com/angular/protractor/issues/481 + return; + } + element(by.model('amount')).clear(); + element(by.model('amount')).sendKeys('-1234'); + expect(element(by.id('currency-default')).getText()).toBe('($1,234.00)'); + expect(element(by.id('currency-custom')).getText()).toBe('(USD$1,234.00)'); + expect(element(by.id('currency-no-fractions')).getText()).toBe('(USD$1,234)'); + }); + +
      + */ +currencyFilter.$inject = ['$locale']; +function currencyFilter($locale) { + var formats = $locale.NUMBER_FORMATS; + return function(amount, currencySymbol, fractionSize) { + if (isUndefined(currencySymbol)) { + currencySymbol = formats.CURRENCY_SYM; + } + + if (isUndefined(fractionSize)) { + fractionSize = formats.PATTERNS[1].maxFrac; + } + + // if null or undefined pass it through + return (amount == null) + ? amount + : formatNumber(amount, formats.PATTERNS[1], formats.GROUP_SEP, formats.DECIMAL_SEP, fractionSize). + replace(/\u00A4/g, currencySymbol); + }; +} + +/** + * @ngdoc filter + * @name number + * @kind function + * + * @description + * Formats a number as text. + * + * If the input is null or undefined, it will just be returned. + * If the input is infinite (Infinity/-Infinity) the Infinity symbol '∞' is returned. + * If the input is not a number an empty string is returned. + * + * @param {number|string} number Number to format. + * @param {(number|string)=} fractionSize Number of decimal places to round the number to. + * If this is not provided then the fraction size is computed from the current locale's number + * formatting pattern. In the case of the default locale, it will be 3. + * @returns {string} Number rounded to decimalPlaces and places a “,” after each third digit. + * + * @example + + + +
      + Enter number:
      + Default formatting: {{val | number}}
      + No fractions: {{val | number:0}}
      + Negative number: {{-val | number:4}} +
      +
      + + it('should format numbers', function() { + expect(element(by.id('number-default')).getText()).toBe('1,234.568'); + expect(element(by.binding('val | number:0')).getText()).toBe('1,235'); + expect(element(by.binding('-val | number:4')).getText()).toBe('-1,234.5679'); + }); + + it('should update', function() { + element(by.model('val')).clear(); + element(by.model('val')).sendKeys('3374.333'); + expect(element(by.id('number-default')).getText()).toBe('3,374.333'); + expect(element(by.binding('val | number:0')).getText()).toBe('3,374'); + expect(element(by.binding('-val | number:4')).getText()).toBe('-3,374.3330'); + }); + +
      + */ + + +numberFilter.$inject = ['$locale']; +function numberFilter($locale) { + var formats = $locale.NUMBER_FORMATS; + return function(number, fractionSize) { + + // if null or undefined pass it through + return (number == null) + ? number + : formatNumber(number, formats.PATTERNS[0], formats.GROUP_SEP, formats.DECIMAL_SEP, + fractionSize); + }; +} + +var DECIMAL_SEP = '.'; +function formatNumber(number, pattern, groupSep, decimalSep, fractionSize) { + if (!isFinite(number) || isObject(number)) return ''; + + var isNegative = number < 0; + number = Math.abs(number); + var numStr = number + '', + formatedText = '', + parts = []; + + var hasExponent = false; + if (numStr.indexOf('e') !== -1) { + var match = numStr.match(/([\d\.]+)e(-?)(\d+)/); + if (match && match[2] == '-' && match[3] > fractionSize + 1) { + number = 0; + } else { + formatedText = numStr; + hasExponent = true; + } + } + + if (!hasExponent) { + var fractionLen = (numStr.split(DECIMAL_SEP)[1] || '').length; + + // determine fractionSize if it is not specified + if (isUndefined(fractionSize)) { + fractionSize = Math.min(Math.max(pattern.minFrac, fractionLen), pattern.maxFrac); + } + + // safely round numbers in JS without hitting imprecisions of floating-point arithmetics + // inspired by: + // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round + number = +(Math.round(+(number.toString() + 'e' + fractionSize)).toString() + 'e' + -fractionSize); + + var fraction = ('' + number).split(DECIMAL_SEP); + var whole = fraction[0]; + fraction = fraction[1] || ''; + + var i, pos = 0, + lgroup = pattern.lgSize, + group = pattern.gSize; + + if (whole.length >= (lgroup + group)) { + pos = whole.length - lgroup; + for (i = 0; i < pos; i++) { + if ((pos - i) % group === 0 && i !== 0) { + formatedText += groupSep; + } + formatedText += whole.charAt(i); + } + } + + for (i = pos; i < whole.length; i++) { + if ((whole.length - i) % lgroup === 0 && i !== 0) { + formatedText += groupSep; + } + formatedText += whole.charAt(i); + } + + // format fraction part. + while (fraction.length < fractionSize) { + fraction += '0'; + } + + if (fractionSize && fractionSize !== "0") formatedText += decimalSep + fraction.substr(0, fractionSize); + } else { + if (fractionSize > 0 && number < 1) { + formatedText = number.toFixed(fractionSize); + number = parseFloat(formatedText); + } + } + + if (number === 0) { + isNegative = false; + } + + parts.push(isNegative ? pattern.negPre : pattern.posPre, + formatedText, + isNegative ? pattern.negSuf : pattern.posSuf); + return parts.join(''); +} + +function padNumber(num, digits, trim) { + var neg = ''; + if (num < 0) { + neg = '-'; + num = -num; + } + num = '' + num; + while (num.length < digits) num = '0' + num; + if (trim) + num = num.substr(num.length - digits); + return neg + num; +} + + +function dateGetter(name, size, offset, trim) { + offset = offset || 0; + return function(date) { + var value = date['get' + name](); + if (offset > 0 || value > -offset) + value += offset; + if (value === 0 && offset == -12) value = 12; + return padNumber(value, size, trim); + }; +} + +function dateStrGetter(name, shortForm) { + return function(date, formats) { + var value = date['get' + name](); + var get = uppercase(shortForm ? ('SHORT' + name) : name); + + return formats[get][value]; + }; +} + +function timeZoneGetter(date) { + var zone = -1 * date.getTimezoneOffset(); + var paddedZone = (zone >= 0) ? "+" : ""; + + paddedZone += padNumber(Math[zone > 0 ? 'floor' : 'ceil'](zone / 60), 2) + + padNumber(Math.abs(zone % 60), 2); + + return paddedZone; +} + +function getFirstThursdayOfYear(year) { + // 0 = index of January + var dayOfWeekOnFirst = (new Date(year, 0, 1)).getDay(); + // 4 = index of Thursday (+1 to account for 1st = 5) + // 11 = index of *next* Thursday (+1 account for 1st = 12) + return new Date(year, 0, ((dayOfWeekOnFirst <= 4) ? 5 : 12) - dayOfWeekOnFirst); +} + +function getThursdayThisWeek(datetime) { + return new Date(datetime.getFullYear(), datetime.getMonth(), + // 4 = index of Thursday + datetime.getDate() + (4 - datetime.getDay())); +} + +function weekGetter(size) { + return function(date) { + var firstThurs = getFirstThursdayOfYear(date.getFullYear()), + thisThurs = getThursdayThisWeek(date); + + var diff = +thisThurs - +firstThurs, + result = 1 + Math.round(diff / 6.048e8); // 6.048e8 ms per week + + return padNumber(result, size); + }; +} + +function ampmGetter(date, formats) { + return date.getHours() < 12 ? formats.AMPMS[0] : formats.AMPMS[1]; +} + +function eraGetter(date, formats) { + return date.getFullYear() <= 0 ? formats.ERAS[0] : formats.ERAS[1]; +} + +function longEraGetter(date, formats) { + return date.getFullYear() <= 0 ? formats.ERANAMES[0] : formats.ERANAMES[1]; +} + +var DATE_FORMATS = { + yyyy: dateGetter('FullYear', 4), + yy: dateGetter('FullYear', 2, 0, true), + y: dateGetter('FullYear', 1), + MMMM: dateStrGetter('Month'), + MMM: dateStrGetter('Month', true), + MM: dateGetter('Month', 2, 1), + M: dateGetter('Month', 1, 1), + dd: dateGetter('Date', 2), + d: dateGetter('Date', 1), + HH: dateGetter('Hours', 2), + H: dateGetter('Hours', 1), + hh: dateGetter('Hours', 2, -12), + h: dateGetter('Hours', 1, -12), + mm: dateGetter('Minutes', 2), + m: dateGetter('Minutes', 1), + ss: dateGetter('Seconds', 2), + s: dateGetter('Seconds', 1), + // while ISO 8601 requires fractions to be prefixed with `.` or `,` + // we can be just safely rely on using `sss` since we currently don't support single or two digit fractions + sss: dateGetter('Milliseconds', 3), + EEEE: dateStrGetter('Day'), + EEE: dateStrGetter('Day', true), + a: ampmGetter, + Z: timeZoneGetter, + ww: weekGetter(2), + w: weekGetter(1), + G: eraGetter, + GG: eraGetter, + GGG: eraGetter, + GGGG: longEraGetter +}; + +var DATE_FORMATS_SPLIT = /((?:[^yMdHhmsaZEwG']+)|(?:'(?:[^']|'')*')|(?:E+|y+|M+|d+|H+|h+|m+|s+|a|Z|G+|w+))(.*)/, + NUMBER_STRING = /^\-?\d+$/; + +/** + * @ngdoc filter + * @name date + * @kind function + * + * @description + * Formats `date` to a string based on the requested `format`. + * + * `format` string can be composed of the following elements: + * + * * `'yyyy'`: 4 digit representation of year (e.g. AD 1 => 0001, AD 2010 => 2010) + * * `'yy'`: 2 digit representation of year, padded (00-99). (e.g. AD 2001 => 01, AD 2010 => 10) + * * `'y'`: 1 digit representation of year, e.g. (AD 1 => 1, AD 199 => 199) + * * `'MMMM'`: Month in year (January-December) + * * `'MMM'`: Month in year (Jan-Dec) + * * `'MM'`: Month in year, padded (01-12) + * * `'M'`: Month in year (1-12) + * * `'dd'`: Day in month, padded (01-31) + * * `'d'`: Day in month (1-31) + * * `'EEEE'`: Day in Week,(Sunday-Saturday) + * * `'EEE'`: Day in Week, (Sun-Sat) + * * `'HH'`: Hour in day, padded (00-23) + * * `'H'`: Hour in day (0-23) + * * `'hh'`: Hour in AM/PM, padded (01-12) + * * `'h'`: Hour in AM/PM, (1-12) + * * `'mm'`: Minute in hour, padded (00-59) + * * `'m'`: Minute in hour (0-59) + * * `'ss'`: Second in minute, padded (00-59) + * * `'s'`: Second in minute (0-59) + * * `'sss'`: Millisecond in second, padded (000-999) + * * `'a'`: AM/PM marker + * * `'Z'`: 4 digit (+sign) representation of the timezone offset (-1200-+1200) + * * `'ww'`: Week of year, padded (00-53). Week 01 is the week with the first Thursday of the year + * * `'w'`: Week of year (0-53). Week 1 is the week with the first Thursday of the year + * * `'G'`, `'GG'`, `'GGG'`: The abbreviated form of the era string (e.g. 'AD') + * * `'GGGG'`: The long form of the era string (e.g. 'Anno Domini') + * + * `format` string can also be one of the following predefined + * {@link guide/i18n localizable formats}: + * + * * `'medium'`: equivalent to `'MMM d, y h:mm:ss a'` for en_US locale + * (e.g. Sep 3, 2010 12:05:08 PM) + * * `'short'`: equivalent to `'M/d/yy h:mm a'` for en_US locale (e.g. 9/3/10 12:05 PM) + * * `'fullDate'`: equivalent to `'EEEE, MMMM d, y'` for en_US locale + * (e.g. Friday, September 3, 2010) + * * `'longDate'`: equivalent to `'MMMM d, y'` for en_US locale (e.g. September 3, 2010) + * * `'mediumDate'`: equivalent to `'MMM d, y'` for en_US locale (e.g. Sep 3, 2010) + * * `'shortDate'`: equivalent to `'M/d/yy'` for en_US locale (e.g. 9/3/10) + * * `'mediumTime'`: equivalent to `'h:mm:ss a'` for en_US locale (e.g. 12:05:08 PM) + * * `'shortTime'`: equivalent to `'h:mm a'` for en_US locale (e.g. 12:05 PM) + * + * `format` string can contain literal values. These need to be escaped by surrounding with single quotes (e.g. + * `"h 'in the morning'"`). In order to output a single quote, escape it - i.e., two single quotes in a sequence + * (e.g. `"h 'o''clock'"`). + * + * @param {(Date|number|string)} date Date to format either as Date object, milliseconds (string or + * number) or various ISO 8601 datetime string formats (e.g. yyyy-MM-ddTHH:mm:ss.sssZ and its + * shorter versions like yyyy-MM-ddTHH:mmZ, yyyy-MM-dd or yyyyMMddTHHmmssZ). If no timezone is + * specified in the string input, the time is considered to be in the local timezone. + * @param {string=} format Formatting rules (see Description). If not specified, + * `mediumDate` is used. + * @param {string=} timezone Timezone to be used for formatting. Right now, only `'UTC'` is supported. + * If not specified, the timezone of the browser will be used. + * @returns {string} Formatted string or the input if input is not recognized as date/millis. + * + * @example + + + {{1288323623006 | date:'medium'}}: + {{1288323623006 | date:'medium'}}
      + {{1288323623006 | date:'yyyy-MM-dd HH:mm:ss Z'}}: + {{1288323623006 | date:'yyyy-MM-dd HH:mm:ss Z'}}
      + {{1288323623006 | date:'MM/dd/yyyy @ h:mma'}}: + {{'1288323623006' | date:'MM/dd/yyyy @ h:mma'}}
      + {{1288323623006 | date:"MM/dd/yyyy 'at' h:mma"}}: + {{'1288323623006' | date:"MM/dd/yyyy 'at' h:mma"}}
      +
      + + it('should format date', function() { + expect(element(by.binding("1288323623006 | date:'medium'")).getText()). + toMatch(/Oct 2\d, 2010 \d{1,2}:\d{2}:\d{2} (AM|PM)/); + expect(element(by.binding("1288323623006 | date:'yyyy-MM-dd HH:mm:ss Z'")).getText()). + toMatch(/2010\-10\-2\d \d{2}:\d{2}:\d{2} (\-|\+)?\d{4}/); + expect(element(by.binding("'1288323623006' | date:'MM/dd/yyyy @ h:mma'")).getText()). + toMatch(/10\/2\d\/2010 @ \d{1,2}:\d{2}(AM|PM)/); + expect(element(by.binding("'1288323623006' | date:\"MM/dd/yyyy 'at' h:mma\"")).getText()). + toMatch(/10\/2\d\/2010 at \d{1,2}:\d{2}(AM|PM)/); + }); + +
      + */ +dateFilter.$inject = ['$locale']; +function dateFilter($locale) { + + + var R_ISO8601_STR = /^(\d{4})-?(\d\d)-?(\d\d)(?:T(\d\d)(?::?(\d\d)(?::?(\d\d)(?:\.(\d+))?)?)?(Z|([+-])(\d\d):?(\d\d))?)?$/; + // 1 2 3 4 5 6 7 8 9 10 11 + function jsonStringToDate(string) { + var match; + if (match = string.match(R_ISO8601_STR)) { + var date = new Date(0), + tzHour = 0, + tzMin = 0, + dateSetter = match[8] ? date.setUTCFullYear : date.setFullYear, + timeSetter = match[8] ? date.setUTCHours : date.setHours; + + if (match[9]) { + tzHour = int(match[9] + match[10]); + tzMin = int(match[9] + match[11]); + } + dateSetter.call(date, int(match[1]), int(match[2]) - 1, int(match[3])); + var h = int(match[4] || 0) - tzHour; + var m = int(match[5] || 0) - tzMin; + var s = int(match[6] || 0); + var ms = Math.round(parseFloat('0.' + (match[7] || 0)) * 1000); + timeSetter.call(date, h, m, s, ms); + return date; + } + return string; + } + + + return function(date, format, timezone) { + var text = '', + parts = [], + fn, match; + + format = format || 'mediumDate'; + format = $locale.DATETIME_FORMATS[format] || format; + if (isString(date)) { + date = NUMBER_STRING.test(date) ? int(date) : jsonStringToDate(date); + } + + if (isNumber(date)) { + date = new Date(date); + } + + if (!isDate(date)) { + return date; + } + + while (format) { + match = DATE_FORMATS_SPLIT.exec(format); + if (match) { + parts = concat(parts, match, 1); + format = parts.pop(); + } else { + parts.push(format); + format = null; + } + } + + if (timezone && timezone === 'UTC') { + date = new Date(date.getTime()); + date.setMinutes(date.getMinutes() + date.getTimezoneOffset()); + } + forEach(parts, function(value) { + fn = DATE_FORMATS[value]; + text += fn ? fn(date, $locale.DATETIME_FORMATS) + : value.replace(/(^'|'$)/g, '').replace(/''/g, "'"); + }); + + return text; + }; +} + + +/** + * @ngdoc filter + * @name json + * @kind function + * + * @description + * Allows you to convert a JavaScript object into JSON string. + * + * This filter is mostly useful for debugging. When using the double curly {{value}} notation + * the binding is automatically converted to JSON. + * + * @param {*} object Any JavaScript object (including arrays and primitive types) to filter. + * @param {number=} spacing The number of spaces to use per indentation, defaults to 2. + * @returns {string} JSON string. + * + * + * @example + + +
      {{ {'name':'value'} | json }}
      +
      {{ {'name':'value'} | json:4 }}
      +
      + + it('should jsonify filtered objects', function() { + expect(element(by.id('default-spacing')).getText()).toMatch(/\{\n "name": ?"value"\n}/); + expect(element(by.id('custom-spacing')).getText()).toMatch(/\{\n "name": ?"value"\n}/); + }); + +
      + * + */ +function jsonFilter() { + return function(object, spacing) { + if (isUndefined(spacing)) { + spacing = 2; + } + return toJson(object, spacing); + }; +} + + +/** + * @ngdoc filter + * @name lowercase + * @kind function + * @description + * Converts string to lowercase. + * @see angular.lowercase + */ +var lowercaseFilter = valueFn(lowercase); + + +/** + * @ngdoc filter + * @name uppercase + * @kind function + * @description + * Converts string to uppercase. + * @see angular.uppercase + */ +var uppercaseFilter = valueFn(uppercase); + +/** + * @ngdoc filter + * @name limitTo + * @kind function + * + * @description + * Creates a new array or string containing only a specified number of elements. The elements + * are taken from either the beginning or the end of the source array, string or number, as specified by + * the value and sign (positive or negative) of `limit`. If a number is used as input, it is + * converted to a string. + * + * @param {Array|string|number} input Source array, string or number to be limited. + * @param {string|number} limit The length of the returned array or string. If the `limit` number + * is positive, `limit` number of items from the beginning of the source array/string are copied. + * If the number is negative, `limit` number of items from the end of the source array/string + * are copied. The `limit` will be trimmed if it exceeds `array.length` + * @returns {Array|string} A new sub-array or substring of length `limit` or less if input array + * had less than `limit` elements. + * + * @example + + + +
      + Limit {{numbers}} to: +

      Output numbers: {{ numbers | limitTo:numLimit }}

      + Limit {{letters}} to: +

      Output letters: {{ letters | limitTo:letterLimit }}

      + Limit {{longNumber}} to: +

      Output long number: {{ longNumber | limitTo:longNumberLimit }}

      +
      +
      + + var numLimitInput = element(by.model('numLimit')); + var letterLimitInput = element(by.model('letterLimit')); + var longNumberLimitInput = element(by.model('longNumberLimit')); + var limitedNumbers = element(by.binding('numbers | limitTo:numLimit')); + var limitedLetters = element(by.binding('letters | limitTo:letterLimit')); + var limitedLongNumber = element(by.binding('longNumber | limitTo:longNumberLimit')); + + it('should limit the number array to first three items', function() { + expect(numLimitInput.getAttribute('value')).toBe('3'); + expect(letterLimitInput.getAttribute('value')).toBe('3'); + expect(longNumberLimitInput.getAttribute('value')).toBe('3'); + expect(limitedNumbers.getText()).toEqual('Output numbers: [1,2,3]'); + expect(limitedLetters.getText()).toEqual('Output letters: abc'); + expect(limitedLongNumber.getText()).toEqual('Output long number: 234'); + }); + + // There is a bug in safari and protractor that doesn't like the minus key + // it('should update the output when -3 is entered', function() { + // numLimitInput.clear(); + // numLimitInput.sendKeys('-3'); + // letterLimitInput.clear(); + // letterLimitInput.sendKeys('-3'); + // longNumberLimitInput.clear(); + // longNumberLimitInput.sendKeys('-3'); + // expect(limitedNumbers.getText()).toEqual('Output numbers: [7,8,9]'); + // expect(limitedLetters.getText()).toEqual('Output letters: ghi'); + // expect(limitedLongNumber.getText()).toEqual('Output long number: 342'); + // }); + + it('should not exceed the maximum size of input array', function() { + numLimitInput.clear(); + numLimitInput.sendKeys('100'); + letterLimitInput.clear(); + letterLimitInput.sendKeys('100'); + longNumberLimitInput.clear(); + longNumberLimitInput.sendKeys('100'); + expect(limitedNumbers.getText()).toEqual('Output numbers: [1,2,3,4,5,6,7,8,9]'); + expect(limitedLetters.getText()).toEqual('Output letters: abcdefghi'); + expect(limitedLongNumber.getText()).toEqual('Output long number: 2345432342'); + }); + +
      +*/ +function limitToFilter() { + return function(input, limit) { + if (isNumber(input)) input = input.toString(); + if (!isArray(input) && !isString(input)) return input; + + if (Math.abs(Number(limit)) === Infinity) { + limit = Number(limit); + } else { + limit = int(limit); + } + + //NaN check on limit + if (limit) { + return limit > 0 ? input.slice(0, limit) : input.slice(limit); + } else { + return isString(input) ? "" : []; + } + }; +} + +/** + * @ngdoc filter + * @name orderBy + * @kind function + * + * @description + * Orders a specified `array` by the `expression` predicate. It is ordered alphabetically + * for strings and numerically for numbers. Note: if you notice numbers are not being sorted + * correctly, make sure they are actually being saved as numbers and not strings. + * + * @param {Array} array The array to sort. + * @param {function(*)|string|Array.<(function(*)|string)>=} expression A predicate to be + * used by the comparator to determine the order of elements. + * + * Can be one of: + * + * - `function`: Getter function. The result of this function will be sorted using the + * `<`, `===`, `>` operator. + * - `string`: An Angular expression. The result of this expression is used to compare elements + * (for example `name` to sort by a property called `name` or `name.substr(0, 3)` to sort by + * 3 first characters of a property called `name`). The result of a constant expression + * is interpreted as a property name to be used in comparisons (for example `"special name"` + * to sort object by the value of their `special name` property). An expression can be + * optionally prefixed with `+` or `-` to control ascending or descending sort order + * (for example, `+name` or `-name`). If no property is provided, (e.g. `'+'`) then the array + * element itself is used to compare where sorting. + * - `Array`: An array of function or string predicates. The first predicate in the array + * is used for sorting, but when two items are equivalent, the next predicate is used. + * + * If the predicate is missing or empty then it defaults to `'+'`. + * + * @param {boolean=} reverse Reverse the order of the array. + * @returns {Array} Sorted copy of the source array. + * + * + * @example + * The example below demonstrates a simple ngRepeat, where the data is sorted + * by age in descending order (predicate is set to `'-age'`). + * `reverse` is not set, which means it defaults to `false`. + + + +
      + + + + + + + + + + + +
      NamePhone NumberAge
      {{friend.name}}{{friend.phone}}{{friend.age}}
      +
      +
      +
      + * + * The predicate and reverse parameters can be controlled dynamically through scope properties, + * as shown in the next example. + * @example + + + +
      +
      Sorting predicate = {{predicate}}; reverse = {{reverse}}
      +
      + [ unsorted ] + + + + + + + + + + + +
      Name + (^)Phone NumberAge
      {{friend.name}}{{friend.phone}}{{friend.age}}
      +
      +
      +
      + * + * It's also possible to call the orderBy filter manually, by injecting `$filter`, retrieving the + * filter routine with `$filter('orderBy')`, and calling the returned filter routine with the + * desired parameters. + * + * Example: + * + * @example + + +
      + + + + + + + + + + + +
      Name + (^)Phone NumberAge
      {{friend.name}}{{friend.phone}}{{friend.age}}
      +
      +
      + + + angular.module('orderByExample', []) + .controller('ExampleController', ['$scope', '$filter', function($scope, $filter) { + var orderBy = $filter('orderBy'); + $scope.friends = [ + { name: 'John', phone: '555-1212', age: 10 }, + { name: 'Mary', phone: '555-9876', age: 19 }, + { name: 'Mike', phone: '555-4321', age: 21 }, + { name: 'Adam', phone: '555-5678', age: 35 }, + { name: 'Julie', phone: '555-8765', age: 29 } + ]; + $scope.order = function(predicate, reverse) { + $scope.friends = orderBy($scope.friends, predicate, reverse); + }; + $scope.order('-age',false); + }]); + +
      + */ +orderByFilter.$inject = ['$parse']; +function orderByFilter($parse) { + return function(array, sortPredicate, reverseOrder) { + if (!(isArrayLike(array))) return array; + sortPredicate = isArray(sortPredicate) ? sortPredicate : [sortPredicate]; + if (sortPredicate.length === 0) { sortPredicate = ['+']; } + sortPredicate = sortPredicate.map(function(predicate) { + var descending = false, get = predicate || identity; + if (isString(predicate)) { + if ((predicate.charAt(0) == '+' || predicate.charAt(0) == '-')) { + descending = predicate.charAt(0) == '-'; + predicate = predicate.substring(1); + } + if (predicate === '') { + // Effectively no predicate was passed so we compare identity + return reverseComparator(compare, descending); + } + get = $parse(predicate); + if (get.constant) { + var key = get(); + return reverseComparator(function(a, b) { + return compare(a[key], b[key]); + }, descending); + } + } + return reverseComparator(function(a, b) { + return compare(get(a),get(b)); + }, descending); + }); + return slice.call(array).sort(reverseComparator(comparator, reverseOrder)); + + function comparator(o1, o2) { + for (var i = 0; i < sortPredicate.length; i++) { + var comp = sortPredicate[i](o1, o2); + if (comp !== 0) return comp; + } + return 0; + } + function reverseComparator(comp, descending) { + return descending + ? function(a, b) {return comp(b,a);} + : comp; + } + + function isPrimitive(value) { + switch (typeof value) { + case 'number': /* falls through */ + case 'boolean': /* falls through */ + case 'string': + return true; + default: + return false; + } + } + + function objectToString(value) { + if (value === null) return 'null'; + if (typeof value.valueOf === 'function') { + value = value.valueOf(); + if (isPrimitive(value)) return value; + } + if (typeof value.toString === 'function') { + value = value.toString(); + if (isPrimitive(value)) return value; + } + return ''; + } + + function compare(v1, v2) { + var t1 = typeof v1; + var t2 = typeof v2; + if (t1 === t2 && t1 === "object") { + v1 = objectToString(v1); + v2 = objectToString(v2); + } + if (t1 === t2) { + if (t1 === "string") { + v1 = v1.toLowerCase(); + v2 = v2.toLowerCase(); + } + if (v1 === v2) return 0; + return v1 < v2 ? -1 : 1; + } else { + return t1 < t2 ? -1 : 1; + } + } + }; +} + +function ngDirective(directive) { + if (isFunction(directive)) { + directive = { + link: directive + }; + } + directive.restrict = directive.restrict || 'AC'; + return valueFn(directive); +} + +/** + * @ngdoc directive + * @name a + * @restrict E + * + * @description + * Modifies the default behavior of the html A tag so that the default action is prevented when + * the href attribute is empty. + * + * This change permits the easy creation of action links with the `ngClick` directive + * without changing the location or causing page reloads, e.g.: + * `Add Item` + */ +var htmlAnchorDirective = valueFn({ + restrict: 'E', + compile: function(element, attr) { + if (!attr.href && !attr.xlinkHref && !attr.name) { + return function(scope, element) { + // If the linked element is not an anchor tag anymore, do nothing + if (element[0].nodeName.toLowerCase() !== 'a') return; + + // SVGAElement does not use the href attribute, but rather the 'xlinkHref' attribute. + var href = toString.call(element.prop('href')) === '[object SVGAnimatedString]' ? + 'xlink:href' : 'href'; + element.on('click', function(event) { + // if we have no href url, then don't navigate anywhere. + if (!element.attr(href)) { + event.preventDefault(); + } + }); + }; + } + } +}); + +/** + * @ngdoc directive + * @name ngHref + * @restrict A + * @priority 99 + * + * @description + * Using Angular markup like `{{hash}}` in an href attribute will + * make the link go to the wrong URL if the user clicks it before + * Angular has a chance to replace the `{{hash}}` markup with its + * value. Until Angular replaces the markup the link will be broken + * and will most likely return a 404 error. The `ngHref` directive + * solves this problem. + * + * The wrong way to write it: + * ```html + * link1 + * ``` + * + * The correct way to write it: + * ```html + * link1 + * ``` + * + * @element A + * @param {template} ngHref any string which can contain `{{}}` markup. + * + * @example + * This example shows various combinations of `href`, `ng-href` and `ng-click` attributes + * in links and their different behaviors: + + +
      + link 1 (link, don't reload)
      + link 2 (link, don't reload)
      + link 3 (link, reload!)
      + anchor (link, don't reload)
      + anchor (no link)
      + link (link, change location) +
      + + it('should execute ng-click but not reload when href without value', function() { + element(by.id('link-1')).click(); + expect(element(by.model('value')).getAttribute('value')).toEqual('1'); + expect(element(by.id('link-1')).getAttribute('href')).toBe(''); + }); + + it('should execute ng-click but not reload when href empty string', function() { + element(by.id('link-2')).click(); + expect(element(by.model('value')).getAttribute('value')).toEqual('2'); + expect(element(by.id('link-2')).getAttribute('href')).toBe(''); + }); + + it('should execute ng-click and change url when ng-href specified', function() { + expect(element(by.id('link-3')).getAttribute('href')).toMatch(/\/123$/); + + element(by.id('link-3')).click(); + + // At this point, we navigate away from an Angular page, so we need + // to use browser.driver to get the base webdriver. + + browser.wait(function() { + return browser.driver.getCurrentUrl().then(function(url) { + return url.match(/\/123$/); + }); + }, 5000, 'page should navigate to /123'); + }); + + xit('should execute ng-click but not reload when href empty string and name specified', function() { + element(by.id('link-4')).click(); + expect(element(by.model('value')).getAttribute('value')).toEqual('4'); + expect(element(by.id('link-4')).getAttribute('href')).toBe(''); + }); + + it('should execute ng-click but not reload when no href but name specified', function() { + element(by.id('link-5')).click(); + expect(element(by.model('value')).getAttribute('value')).toEqual('5'); + expect(element(by.id('link-5')).getAttribute('href')).toBe(null); + }); + + it('should only change url when only ng-href', function() { + element(by.model('value')).clear(); + element(by.model('value')).sendKeys('6'); + expect(element(by.id('link-6')).getAttribute('href')).toMatch(/\/6$/); + + element(by.id('link-6')).click(); + + // At this point, we navigate away from an Angular page, so we need + // to use browser.driver to get the base webdriver. + browser.wait(function() { + return browser.driver.getCurrentUrl().then(function(url) { + return url.match(/\/6$/); + }); + }, 5000, 'page should navigate to /6'); + }); + +
      + */ + +/** + * @ngdoc directive + * @name ngSrc + * @restrict A + * @priority 99 + * + * @description + * Using Angular markup like `{{hash}}` in a `src` attribute doesn't + * work right: The browser will fetch from the URL with the literal + * text `{{hash}}` until Angular replaces the expression inside + * `{{hash}}`. The `ngSrc` directive solves this problem. + * + * The buggy way to write it: + * ```html + * + * ``` + * + * The correct way to write it: + * ```html + * + * ``` + * + * @element IMG + * @param {template} ngSrc any string which can contain `{{}}` markup. + */ + +/** + * @ngdoc directive + * @name ngSrcset + * @restrict A + * @priority 99 + * + * @description + * Using Angular markup like `{{hash}}` in a `srcset` attribute doesn't + * work right: The browser will fetch from the URL with the literal + * text `{{hash}}` until Angular replaces the expression inside + * `{{hash}}`. The `ngSrcset` directive solves this problem. + * + * The buggy way to write it: + * ```html + * + * ``` + * + * The correct way to write it: + * ```html + * + * ``` + * + * @element IMG + * @param {template} ngSrcset any string which can contain `{{}}` markup. + */ + +/** + * @ngdoc directive + * @name ngDisabled + * @restrict A + * @priority 100 + * + * @description + * + * This directive sets the `disabled` attribute on the element if the + * {@link guide/expression expression} inside `ngDisabled` evaluates to truthy. + * + * A special directive is necessary because we cannot use interpolation inside the `disabled` + * attribute. The following example would make the button enabled on Chrome/Firefox + * but not on older IEs: + * + * ```html + * + *
      + * + *
      + * ``` + * + * This is because the HTML specification does not require browsers to preserve the values of + * boolean attributes such as `disabled` (Their presence means true and their absence means false.) + * If we put an Angular interpolation expression into such an attribute then the + * binding information would be lost when the browser removes the attribute. + * + * @example + + + Click me to toggle:
      + +
      + + it('should toggle button', function() { + expect(element(by.css('button')).getAttribute('disabled')).toBeFalsy(); + element(by.model('checked')).click(); + expect(element(by.css('button')).getAttribute('disabled')).toBeTruthy(); + }); + +
      + * + * @element INPUT + * @param {expression} ngDisabled If the {@link guide/expression expression} is truthy, + * then the `disabled` attribute will be set on the element + */ + + +/** + * @ngdoc directive + * @name ngChecked + * @restrict A + * @priority 100 + * + * @description + * The HTML specification does not require browsers to preserve the values of boolean attributes + * such as checked. (Their presence means true and their absence means false.) + * If we put an Angular interpolation expression into such an attribute then the + * binding information would be lost when the browser removes the attribute. + * The `ngChecked` directive solves this problem for the `checked` attribute. + * This complementary directive is not removed by the browser and so provides + * a permanent reliable place to store the binding information. + * @example + + + Check me to check both:
      + +
      + + it('should check both checkBoxes', function() { + expect(element(by.id('checkSlave')).getAttribute('checked')).toBeFalsy(); + element(by.model('master')).click(); + expect(element(by.id('checkSlave')).getAttribute('checked')).toBeTruthy(); + }); + +
      + * + * @element INPUT + * @param {expression} ngChecked If the {@link guide/expression expression} is truthy, + * then special attribute "checked" will be set on the element + */ + + +/** + * @ngdoc directive + * @name ngReadonly + * @restrict A + * @priority 100 + * + * @description + * The HTML specification does not require browsers to preserve the values of boolean attributes + * such as readonly. (Their presence means true and their absence means false.) + * If we put an Angular interpolation expression into such an attribute then the + * binding information would be lost when the browser removes the attribute. + * The `ngReadonly` directive solves this problem for the `readonly` attribute. + * This complementary directive is not removed by the browser and so provides + * a permanent reliable place to store the binding information. + * @example + + + Check me to make text readonly:
      + +
      + + it('should toggle readonly attr', function() { + expect(element(by.css('[type="text"]')).getAttribute('readonly')).toBeFalsy(); + element(by.model('checked')).click(); + expect(element(by.css('[type="text"]')).getAttribute('readonly')).toBeTruthy(); + }); + +
      + * + * @element INPUT + * @param {expression} ngReadonly If the {@link guide/expression expression} is truthy, + * then special attribute "readonly" will be set on the element + */ + + +/** + * @ngdoc directive + * @name ngSelected + * @restrict A + * @priority 100 + * + * @description + * The HTML specification does not require browsers to preserve the values of boolean attributes + * such as selected. (Their presence means true and their absence means false.) + * If we put an Angular interpolation expression into such an attribute then the + * binding information would be lost when the browser removes the attribute. + * The `ngSelected` directive solves this problem for the `selected` attribute. + * This complementary directive is not removed by the browser and so provides + * a permanent reliable place to store the binding information. + * + * @example + + + Check me to select:
      + +
      + + it('should select Greetings!', function() { + expect(element(by.id('greet')).getAttribute('selected')).toBeFalsy(); + element(by.model('selected')).click(); + expect(element(by.id('greet')).getAttribute('selected')).toBeTruthy(); + }); + +
      + * + * @element OPTION + * @param {expression} ngSelected If the {@link guide/expression expression} is truthy, + * then special attribute "selected" will be set on the element + */ + +/** + * @ngdoc directive + * @name ngOpen + * @restrict A + * @priority 100 + * + * @description + * The HTML specification does not require browsers to preserve the values of boolean attributes + * such as open. (Their presence means true and their absence means false.) + * If we put an Angular interpolation expression into such an attribute then the + * binding information would be lost when the browser removes the attribute. + * The `ngOpen` directive solves this problem for the `open` attribute. + * This complementary directive is not removed by the browser and so provides + * a permanent reliable place to store the binding information. + * @example + + + Check me check multiple:
      +
      + Show/Hide me +
      +
      + + it('should toggle open', function() { + expect(element(by.id('details')).getAttribute('open')).toBeFalsy(); + element(by.model('open')).click(); + expect(element(by.id('details')).getAttribute('open')).toBeTruthy(); + }); + +
      + * + * @element DETAILS + * @param {expression} ngOpen If the {@link guide/expression expression} is truthy, + * then special attribute "open" will be set on the element + */ + +var ngAttributeAliasDirectives = {}; + + +// boolean attrs are evaluated +forEach(BOOLEAN_ATTR, function(propName, attrName) { + // binding to multiple is not supported + if (propName == "multiple") return; + + var normalized = directiveNormalize('ng-' + attrName); + ngAttributeAliasDirectives[normalized] = function() { + return { + restrict: 'A', + priority: 100, + link: function(scope, element, attr) { + scope.$watch(attr[normalized], function ngBooleanAttrWatchAction(value) { + attr.$set(attrName, !!value); + }); + } + }; + }; +}); + +// aliased input attrs are evaluated +forEach(ALIASED_ATTR, function(htmlAttr, ngAttr) { + ngAttributeAliasDirectives[ngAttr] = function() { + return { + priority: 100, + link: function(scope, element, attr) { + //special case ngPattern when a literal regular expression value + //is used as the expression (this way we don't have to watch anything). + if (ngAttr === "ngPattern" && attr.ngPattern.charAt(0) == "/") { + var match = attr.ngPattern.match(REGEX_STRING_REGEXP); + if (match) { + attr.$set("ngPattern", new RegExp(match[1], match[2])); + return; + } + } + + scope.$watch(attr[ngAttr], function ngAttrAliasWatchAction(value) { + attr.$set(ngAttr, value); + }); + } + }; + }; +}); + +// ng-src, ng-srcset, ng-href are interpolated +forEach(['src', 'srcset', 'href'], function(attrName) { + var normalized = directiveNormalize('ng-' + attrName); + ngAttributeAliasDirectives[normalized] = function() { + return { + priority: 99, // it needs to run after the attributes are interpolated + link: function(scope, element, attr) { + var propName = attrName, + name = attrName; + + if (attrName === 'href' && + toString.call(element.prop('href')) === '[object SVGAnimatedString]') { + name = 'xlinkHref'; + attr.$attr[name] = 'xlink:href'; + propName = null; + } + + attr.$observe(normalized, function(value) { + if (!value) { + if (attrName === 'href') { + attr.$set(name, null); + } + return; + } + + attr.$set(name, value); + + // on IE, if "ng:src" directive declaration is used and "src" attribute doesn't exist + // then calling element.setAttribute('src', 'foo') doesn't do anything, so we need + // to set the property as well to achieve the desired effect. + // we use attr[attrName] value since $set can sanitize the url. + if (msie && propName) element.prop(propName, attr[name]); + }); + } + }; + }; +}); + +/* global -nullFormCtrl, -SUBMITTED_CLASS, addSetValidityMethod: true + */ +var nullFormCtrl = { + $addControl: noop, + $$renameControl: nullFormRenameControl, + $removeControl: noop, + $setValidity: noop, + $setDirty: noop, + $setPristine: noop, + $setSubmitted: noop +}, +SUBMITTED_CLASS = 'ng-submitted'; + +function nullFormRenameControl(control, name) { + control.$name = name; +} + +/** + * @ngdoc type + * @name form.FormController + * + * @property {boolean} $pristine True if user has not interacted with the form yet. + * @property {boolean} $dirty True if user has already interacted with the form. + * @property {boolean} $valid True if all of the containing forms and controls are valid. + * @property {boolean} $invalid True if at least one containing control or form is invalid. + * @property {boolean} $submitted True if user has submitted the form even if its invalid. + * + * @property {Object} $error Is an object hash, containing references to controls or + * forms with failing validators, where: + * + * - keys are validation tokens (error names), + * - values are arrays of controls or forms that have a failing validator for given error name. + * + * Built-in validation tokens: + * + * - `email` + * - `max` + * - `maxlength` + * - `min` + * - `minlength` + * - `number` + * - `pattern` + * - `required` + * - `url` + * - `date` + * - `datetimelocal` + * - `time` + * - `week` + * - `month` + * + * @description + * `FormController` keeps track of all its controls and nested forms as well as the state of them, + * such as being valid/invalid or dirty/pristine. + * + * Each {@link ng.directive:form form} directive creates an instance + * of `FormController`. + * + */ +//asks for $scope to fool the BC controller module +FormController.$inject = ['$element', '$attrs', '$scope', '$animate', '$interpolate']; +function FormController(element, attrs, $scope, $animate, $interpolate) { + var form = this, + controls = []; + + var parentForm = form.$$parentForm = element.parent().controller('form') || nullFormCtrl; + + // init state + form.$error = {}; + form.$$success = {}; + form.$pending = undefined; + form.$name = $interpolate(attrs.name || attrs.ngForm || '')($scope); + form.$dirty = false; + form.$pristine = true; + form.$valid = true; + form.$invalid = false; + form.$submitted = false; + + parentForm.$addControl(form); + + /** + * @ngdoc method + * @name form.FormController#$rollbackViewValue + * + * @description + * Rollback all form controls pending updates to the `$modelValue`. + * + * Updates may be pending by a debounced event or because the input is waiting for a some future + * event defined in `ng-model-options`. This method is typically needed by the reset button of + * a form that uses `ng-model-options` to pend updates. + */ + form.$rollbackViewValue = function() { + forEach(controls, function(control) { + control.$rollbackViewValue(); + }); + }; + + /** + * @ngdoc method + * @name form.FormController#$commitViewValue + * + * @description + * Commit all form controls pending updates to the `$modelValue`. + * + * Updates may be pending by a debounced event or because the input is waiting for a some future + * event defined in `ng-model-options`. This method is rarely needed as `NgModelController` + * usually handles calling this in response to input events. + */ + form.$commitViewValue = function() { + forEach(controls, function(control) { + control.$commitViewValue(); + }); + }; + + /** + * @ngdoc method + * @name form.FormController#$addControl + * + * @description + * Register a control with the form. + * + * Input elements using ngModelController do this automatically when they are linked. + */ + form.$addControl = function(control) { + // Breaking change - before, inputs whose name was "hasOwnProperty" were quietly ignored + // and not added to the scope. Now we throw an error. + assertNotHasOwnProperty(control.$name, 'input'); + controls.push(control); + + if (control.$name) { + form[control.$name] = control; + } + }; + + // Private API: rename a form control + form.$$renameControl = function(control, newName) { + var oldName = control.$name; + + if (form[oldName] === control) { + delete form[oldName]; + } + form[newName] = control; + control.$name = newName; + }; + + /** + * @ngdoc method + * @name form.FormController#$removeControl + * + * @description + * Deregister a control from the form. + * + * Input elements using ngModelController do this automatically when they are destroyed. + */ + form.$removeControl = function(control) { + if (control.$name && form[control.$name] === control) { + delete form[control.$name]; + } + forEach(form.$pending, function(value, name) { + form.$setValidity(name, null, control); + }); + forEach(form.$error, function(value, name) { + form.$setValidity(name, null, control); + }); + forEach(form.$$success, function(value, name) { + form.$setValidity(name, null, control); + }); + + arrayRemove(controls, control); + }; + + + /** + * @ngdoc method + * @name form.FormController#$setValidity + * + * @description + * Sets the validity of a form control. + * + * This method will also propagate to parent forms. + */ + addSetValidityMethod({ + ctrl: this, + $element: element, + set: function(object, property, controller) { + var list = object[property]; + if (!list) { + object[property] = [controller]; + } else { + var index = list.indexOf(controller); + if (index === -1) { + list.push(controller); + } + } + }, + unset: function(object, property, controller) { + var list = object[property]; + if (!list) { + return; + } + arrayRemove(list, controller); + if (list.length === 0) { + delete object[property]; + } + }, + parentForm: parentForm, + $animate: $animate + }); + + /** + * @ngdoc method + * @name form.FormController#$setDirty + * + * @description + * Sets the form to a dirty state. + * + * This method can be called to add the 'ng-dirty' class and set the form to a dirty + * state (ng-dirty class). This method will also propagate to parent forms. + */ + form.$setDirty = function() { + $animate.removeClass(element, PRISTINE_CLASS); + $animate.addClass(element, DIRTY_CLASS); + form.$dirty = true; + form.$pristine = false; + parentForm.$setDirty(); + }; + + /** + * @ngdoc method + * @name form.FormController#$setPristine + * + * @description + * Sets the form to its pristine state. + * + * This method can be called to remove the 'ng-dirty' class and set the form to its pristine + * state (ng-pristine class). This method will also propagate to all the controls contained + * in this form. + * + * Setting a form back to a pristine state is often useful when we want to 'reuse' a form after + * saving or resetting it. + */ + form.$setPristine = function() { + $animate.setClass(element, PRISTINE_CLASS, DIRTY_CLASS + ' ' + SUBMITTED_CLASS); + form.$dirty = false; + form.$pristine = true; + form.$submitted = false; + forEach(controls, function(control) { + control.$setPristine(); + }); + }; + + /** + * @ngdoc method + * @name form.FormController#$setUntouched + * + * @description + * Sets the form to its untouched state. + * + * This method can be called to remove the 'ng-touched' class and set the form controls to their + * untouched state (ng-untouched class). + * + * Setting a form controls back to their untouched state is often useful when setting the form + * back to its pristine state. + */ + form.$setUntouched = function() { + forEach(controls, function(control) { + control.$setUntouched(); + }); + }; + + /** + * @ngdoc method + * @name form.FormController#$setSubmitted + * + * @description + * Sets the form to its submitted state. + */ + form.$setSubmitted = function() { + $animate.addClass(element, SUBMITTED_CLASS); + form.$submitted = true; + parentForm.$setSubmitted(); + }; +} + +/** + * @ngdoc directive + * @name ngForm + * @restrict EAC + * + * @description + * Nestable alias of {@link ng.directive:form `form`} directive. HTML + * does not allow nesting of form elements. It is useful to nest forms, for example if the validity of a + * sub-group of controls needs to be determined. + * + * Note: the purpose of `ngForm` is to group controls, + * but not to be a replacement for the `
      ` tag with all of its capabilities + * (e.g. posting to the server, ...). + * + * @param {string=} ngForm|name Name of the form. If specified, the form controller will be published into + * related scope, under this name. + * + */ + + /** + * @ngdoc directive + * @name form + * @restrict E + * + * @description + * Directive that instantiates + * {@link form.FormController FormController}. + * + * If the `name` attribute is specified, the form controller is published onto the current scope under + * this name. + * + * # Alias: {@link ng.directive:ngForm `ngForm`} + * + * In Angular, forms can be nested. This means that the outer form is valid when all of the child + * forms are valid as well. However, browsers do not allow nesting of `` elements, so + * Angular provides the {@link ng.directive:ngForm `ngForm`} directive which behaves identically to + * `` but can be nested. This allows you to have nested forms, which is very useful when + * using Angular validation directives in forms that are dynamically generated using the + * {@link ng.directive:ngRepeat `ngRepeat`} directive. Since you cannot dynamically generate the `name` + * attribute of input elements using interpolation, you have to wrap each set of repeated inputs in an + * `ngForm` directive and nest these in an outer `form` element. + * + * + * # CSS classes + * - `ng-valid` is set if the form is valid. + * - `ng-invalid` is set if the form is invalid. + * - `ng-pristine` is set if the form is pristine. + * - `ng-dirty` is set if the form is dirty. + * - `ng-submitted` is set if the form was submitted. + * + * Keep in mind that ngAnimate can detect each of these classes when added and removed. + * + * + * # Submitting a form and preventing the default action + * + * Since the role of forms in client-side Angular applications is different than in classical + * roundtrip apps, it is desirable for the browser not to translate the form submission into a full + * page reload that sends the data to the server. Instead some javascript logic should be triggered + * to handle the form submission in an application-specific way. + * + * For this reason, Angular prevents the default action (form submission to the server) unless the + * `` element has an `action` attribute specified. + * + * You can use one of the following two ways to specify what javascript method should be called when + * a form is submitted: + * + * - {@link ng.directive:ngSubmit ngSubmit} directive on the form element + * - {@link ng.directive:ngClick ngClick} directive on the first + * button or input field of type submit (input[type=submit]) + * + * To prevent double execution of the handler, use only one of the {@link ng.directive:ngSubmit ngSubmit} + * or {@link ng.directive:ngClick ngClick} directives. + * This is because of the following form submission rules in the HTML specification: + * + * - If a form has only one input field then hitting enter in this field triggers form submit + * (`ngSubmit`) + * - if a form has 2+ input fields and no buttons or input[type=submit] then hitting enter + * doesn't trigger submit + * - if a form has one or more input fields and one or more buttons or input[type=submit] then + * hitting enter in any of the input fields will trigger the click handler on the *first* button or + * input[type=submit] (`ngClick`) *and* a submit handler on the enclosing form (`ngSubmit`) + * + * Any pending `ngModelOptions` changes will take place immediately when an enclosing form is + * submitted. Note that `ngClick` events will occur before the model is updated. Use `ngSubmit` + * to have access to the updated model. + * + * ## Animation Hooks + * + * Animations in ngForm are triggered when any of the associated CSS classes are added and removed. + * These classes are: `.ng-pristine`, `.ng-dirty`, `.ng-invalid` and `.ng-valid` as well as any + * other validations that are performed within the form. Animations in ngForm are similar to how + * they work in ngClass and animations can be hooked into using CSS transitions, keyframes as well + * as JS animations. + * + * The following example shows a simple way to utilize CSS transitions to style a form element + * that has been rendered as invalid after it has been validated: + * + *
      + * //be sure to include ngAnimate as a module to hook into more
      + * //advanced animations
      + * .my-form {
      + *   transition:0.5s linear all;
      + *   background: white;
      + * }
      + * .my-form.ng-invalid {
      + *   background: red;
      + *   color:white;
      + * }
      + * 
      + * + * @example + + + + + + userType: + Required!
      + userType = {{userType}}
      + myForm.input.$valid = {{myForm.input.$valid}}
      + myForm.input.$error = {{myForm.input.$error}}
      + myForm.$valid = {{myForm.$valid}}
      + myForm.$error.required = {{!!myForm.$error.required}}
      + +
      + + it('should initialize to model', function() { + var userType = element(by.binding('userType')); + var valid = element(by.binding('myForm.input.$valid')); + + expect(userType.getText()).toContain('guest'); + expect(valid.getText()).toContain('true'); + }); + + it('should be invalid if empty', function() { + var userType = element(by.binding('userType')); + var valid = element(by.binding('myForm.input.$valid')); + var userInput = element(by.model('userType')); + + userInput.clear(); + userInput.sendKeys(''); + + expect(userType.getText()).toEqual('userType ='); + expect(valid.getText()).toContain('false'); + }); + +
      + * + * @param {string=} name Name of the form. If specified, the form controller will be published into + * related scope, under this name. + */ +var formDirectiveFactory = function(isNgForm) { + return ['$timeout', function($timeout) { + var formDirective = { + name: 'form', + restrict: isNgForm ? 'EAC' : 'E', + controller: FormController, + compile: function ngFormCompile(formElement, attr) { + // Setup initial state of the control + formElement.addClass(PRISTINE_CLASS).addClass(VALID_CLASS); + + var nameAttr = attr.name ? 'name' : (isNgForm && attr.ngForm ? 'ngForm' : false); + + return { + pre: function ngFormPreLink(scope, formElement, attr, controller) { + // if `action` attr is not present on the form, prevent the default action (submission) + if (!('action' in attr)) { + // we can't use jq events because if a form is destroyed during submission the default + // action is not prevented. see #1238 + // + // IE 9 is not affected because it doesn't fire a submit event and try to do a full + // page reload if the form was destroyed by submission of the form via a click handler + // on a button in the form. Looks like an IE9 specific bug. + var handleFormSubmission = function(event) { + scope.$apply(function() { + controller.$commitViewValue(); + controller.$setSubmitted(); + }); + + event.preventDefault(); + }; + + addEventListenerFn(formElement[0], 'submit', handleFormSubmission); + + // unregister the preventDefault listener so that we don't not leak memory but in a + // way that will achieve the prevention of the default action. + formElement.on('$destroy', function() { + $timeout(function() { + removeEventListenerFn(formElement[0], 'submit', handleFormSubmission); + }, 0, false); + }); + } + + var parentFormCtrl = controller.$$parentForm; + + if (nameAttr) { + setter(scope, null, controller.$name, controller, controller.$name); + attr.$observe(nameAttr, function(newValue) { + if (controller.$name === newValue) return; + setter(scope, null, controller.$name, undefined, controller.$name); + parentFormCtrl.$$renameControl(controller, newValue); + setter(scope, null, controller.$name, controller, controller.$name); + }); + } + formElement.on('$destroy', function() { + parentFormCtrl.$removeControl(controller); + if (nameAttr) { + setter(scope, null, attr[nameAttr], undefined, controller.$name); + } + extend(controller, nullFormCtrl); //stop propagating child destruction handlers upwards + }); + } + }; + } + }; + + return formDirective; + }]; +}; + +var formDirective = formDirectiveFactory(); +var ngFormDirective = formDirectiveFactory(true); + +/* global VALID_CLASS: false, + INVALID_CLASS: false, + PRISTINE_CLASS: false, + DIRTY_CLASS: false, + UNTOUCHED_CLASS: false, + TOUCHED_CLASS: false, + ngModelMinErr: false, +*/ + +// Regex code is obtained from SO: https://stackoverflow.com/questions/3143070/javascript-regex-iso-datetime#answer-3143231 +var ISO_DATE_REGEXP = /\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z)/; +var URL_REGEXP = /^(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?$/; +var EMAIL_REGEXP = /^[a-z0-9!#$%&'*+\/=?^_`{|}~.-]+@[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)*$/i; +var NUMBER_REGEXP = /^\s*(\-|\+)?(\d+|(\d*(\.\d*)))\s*$/; +var DATE_REGEXP = /^(\d{4})-(\d{2})-(\d{2})$/; +var DATETIMELOCAL_REGEXP = /^(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d)(?::(\d\d)(\.\d{1,3})?)?$/; +var WEEK_REGEXP = /^(\d{4})-W(\d\d)$/; +var MONTH_REGEXP = /^(\d{4})-(\d\d)$/; +var TIME_REGEXP = /^(\d\d):(\d\d)(?::(\d\d)(\.\d{1,3})?)?$/; + +var inputType = { + + /** + * @ngdoc input + * @name input[text] + * + * @description + * Standard HTML text input with angular data binding, inherited by most of the `input` elements. + * + * + * @param {string} ngModel Assignable angular expression to data-bind to. + * @param {string=} name Property name of the form under which the control is published. + * @param {string=} required Adds `required` validation error key if the value is not entered. + * @param {string=} ngRequired Adds `required` attribute and `required` validation constraint to + * the element when the ngRequired expression evaluates to true. Use `ngRequired` instead of + * `required` when you want to data-bind to the `required` attribute. + * @param {number=} ngMinlength Sets `minlength` validation error key if the value is shorter than + * minlength. + * @param {number=} ngMaxlength Sets `maxlength` validation error key if the value is longer than + * maxlength. Setting the attribute to a negative or non-numeric value, allows view values of + * any length. + * @param {string=} pattern Similar to `ngPattern` except that the attribute value is the actual string + * that contains the regular expression body that will be converted to a regular expression + * as in the ngPattern directive. + * @param {string=} ngPattern Sets `pattern` validation error key if the ngModel value does not match + * a RegExp found by evaluating the Angular expression given in the attribute value. + * If the expression evaluates to a RegExp object then this is used directly. + * If the expression is a string then it will be converted to a RegExp after wrapping it in `^` and `$` + * characters. For instance, `"abc"` will be converted to `new RegExp('^abc$')`. + * @param {string=} ngChange Angular expression to be executed when input changes due to user + * interaction with the input element. + * @param {boolean=} [ngTrim=true] If set to false Angular will not automatically trim the input. + * This parameter is ignored for input[type=password] controls, which will never trim the + * input. + * + * @example + + + +
      + Single word: + + Required! + + Single word only! + + text = {{example.text}}
      + myForm.input.$valid = {{myForm.input.$valid}}
      + myForm.input.$error = {{myForm.input.$error}}
      + myForm.$valid = {{myForm.$valid}}
      + myForm.$error.required = {{!!myForm.$error.required}}
      +
      +
      + + var text = element(by.binding('example.text')); + var valid = element(by.binding('myForm.input.$valid')); + var input = element(by.model('example.text')); + + it('should initialize to model', function() { + expect(text.getText()).toContain('guest'); + expect(valid.getText()).toContain('true'); + }); + + it('should be invalid if empty', function() { + input.clear(); + input.sendKeys(''); + + expect(text.getText()).toEqual('text ='); + expect(valid.getText()).toContain('false'); + }); + + it('should be invalid if multi word', function() { + input.clear(); + input.sendKeys('hello world'); + + expect(valid.getText()).toContain('false'); + }); + +
      + */ + 'text': textInputType, + + /** + * @ngdoc input + * @name input[date] + * + * @description + * Input with date validation and transformation. In browsers that do not yet support + * the HTML5 date input, a text element will be used. In that case, text must be entered in a valid ISO-8601 + * date format (yyyy-MM-dd), for example: `2009-01-06`. Since many + * modern browsers do not yet support this input type, it is important to provide cues to users on the + * expected input format via a placeholder or label. + * + * The model must always be a Date object, otherwise Angular will throw an error. + * Invalid `Date` objects (dates whose `getTime()` is `NaN`) will be rendered as an empty string. + * + * The timezone to be used to read/write the `Date` instance in the model can be defined using + * {@link ng.directive:ngModelOptions ngModelOptions}. By default, this is the timezone of the browser. + * + * @param {string} ngModel Assignable angular expression to data-bind to. + * @param {string=} name Property name of the form under which the control is published. + * @param {string=} min Sets the `min` validation error key if the value entered is less than `min`. This must be a + * valid ISO date string (yyyy-MM-dd). + * @param {string=} max Sets the `max` validation error key if the value entered is greater than `max`. This must be + * a valid ISO date string (yyyy-MM-dd). + * @param {string=} required Sets `required` validation error key if the value is not entered. + * @param {string=} ngRequired Adds `required` attribute and `required` validation constraint to + * the element when the ngRequired expression evaluates to true. Use `ngRequired` instead of + * `required` when you want to data-bind to the `required` attribute. + * @param {string=} ngChange Angular expression to be executed when input changes due to user + * interaction with the input element. + * + * @example + + + +
      + Pick a date in 2013: + + + Required! + + Not a valid date! + value = {{example.value | date: "yyyy-MM-dd"}}
      + myForm.input.$valid = {{myForm.input.$valid}}
      + myForm.input.$error = {{myForm.input.$error}}
      + myForm.$valid = {{myForm.$valid}}
      + myForm.$error.required = {{!!myForm.$error.required}}
      +
      +
      + + var value = element(by.binding('example.value | date: "yyyy-MM-dd"')); + var valid = element(by.binding('myForm.input.$valid')); + var input = element(by.model('example.value')); + + // currently protractor/webdriver does not support + // sending keys to all known HTML5 input controls + // for various browsers (see https://github.com/angular/protractor/issues/562). + function setInput(val) { + // set the value of the element and force validation. + var scr = "var ipt = document.getElementById('exampleInput'); " + + "ipt.value = '" + val + "';" + + "angular.element(ipt).scope().$apply(function(s) { s.myForm[ipt.name].$setViewValue('" + val + "'); });"; + browser.executeScript(scr); + } + + it('should initialize to model', function() { + expect(value.getText()).toContain('2013-10-22'); + expect(valid.getText()).toContain('myForm.input.$valid = true'); + }); + + it('should be invalid if empty', function() { + setInput(''); + expect(value.getText()).toEqual('value ='); + expect(valid.getText()).toContain('myForm.input.$valid = false'); + }); + + it('should be invalid if over max', function() { + setInput('2015-01-01'); + expect(value.getText()).toContain(''); + expect(valid.getText()).toContain('myForm.input.$valid = false'); + }); + +
      + */ + 'date': createDateInputType('date', DATE_REGEXP, + createDateParser(DATE_REGEXP, ['yyyy', 'MM', 'dd']), + 'yyyy-MM-dd'), + + /** + * @ngdoc input + * @name input[datetime-local] + * + * @description + * Input with datetime validation and transformation. In browsers that do not yet support + * the HTML5 date input, a text element will be used. In that case, the text must be entered in a valid ISO-8601 + * local datetime format (yyyy-MM-ddTHH:mm:ss), for example: `2010-12-28T14:57:00`. + * + * The model must always be a Date object, otherwise Angular will throw an error. + * Invalid `Date` objects (dates whose `getTime()` is `NaN`) will be rendered as an empty string. + * + * The timezone to be used to read/write the `Date` instance in the model can be defined using + * {@link ng.directive:ngModelOptions ngModelOptions}. By default, this is the timezone of the browser. + * + * @param {string} ngModel Assignable angular expression to data-bind to. + * @param {string=} name Property name of the form under which the control is published. + * @param {string=} min Sets the `min` validation error key if the value entered is less than `min`. This must be a + * valid ISO datetime format (yyyy-MM-ddTHH:mm:ss). + * @param {string=} max Sets the `max` validation error key if the value entered is greater than `max`. This must be + * a valid ISO datetime format (yyyy-MM-ddTHH:mm:ss). + * @param {string=} required Sets `required` validation error key if the value is not entered. + * @param {string=} ngRequired Adds `required` attribute and `required` validation constraint to + * the element when the ngRequired expression evaluates to true. Use `ngRequired` instead of + * `required` when you want to data-bind to the `required` attribute. + * @param {string=} ngChange Angular expression to be executed when input changes due to user + * interaction with the input element. + * + * @example + + + +
      + Pick a date between in 2013: + + + Required! + + Not a valid date! + value = {{example.value | date: "yyyy-MM-ddTHH:mm:ss"}}
      + myForm.input.$valid = {{myForm.input.$valid}}
      + myForm.input.$error = {{myForm.input.$error}}
      + myForm.$valid = {{myForm.$valid}}
      + myForm.$error.required = {{!!myForm.$error.required}}
      +
      +
      + + var value = element(by.binding('example.value | date: "yyyy-MM-ddTHH:mm:ss"')); + var valid = element(by.binding('myForm.input.$valid')); + var input = element(by.model('example.value')); + + // currently protractor/webdriver does not support + // sending keys to all known HTML5 input controls + // for various browsers (https://github.com/angular/protractor/issues/562). + function setInput(val) { + // set the value of the element and force validation. + var scr = "var ipt = document.getElementById('exampleInput'); " + + "ipt.value = '" + val + "';" + + "angular.element(ipt).scope().$apply(function(s) { s.myForm[ipt.name].$setViewValue('" + val + "'); });"; + browser.executeScript(scr); + } + + it('should initialize to model', function() { + expect(value.getText()).toContain('2010-12-28T14:57:00'); + expect(valid.getText()).toContain('myForm.input.$valid = true'); + }); + + it('should be invalid if empty', function() { + setInput(''); + expect(value.getText()).toEqual('value ='); + expect(valid.getText()).toContain('myForm.input.$valid = false'); + }); + + it('should be invalid if over max', function() { + setInput('2015-01-01T23:59:00'); + expect(value.getText()).toContain(''); + expect(valid.getText()).toContain('myForm.input.$valid = false'); + }); + +
      + */ + 'datetime-local': createDateInputType('datetimelocal', DATETIMELOCAL_REGEXP, + createDateParser(DATETIMELOCAL_REGEXP, ['yyyy', 'MM', 'dd', 'HH', 'mm', 'ss', 'sss']), + 'yyyy-MM-ddTHH:mm:ss.sss'), + + /** + * @ngdoc input + * @name input[time] + * + * @description + * Input with time validation and transformation. In browsers that do not yet support + * the HTML5 date input, a text element will be used. In that case, the text must be entered in a valid ISO-8601 + * local time format (HH:mm:ss), for example: `14:57:00`. Model must be a Date object. This binding will always output a + * Date object to the model of January 1, 1970, or local date `new Date(1970, 0, 1, HH, mm, ss)`. + * + * The model must always be a Date object, otherwise Angular will throw an error. + * Invalid `Date` objects (dates whose `getTime()` is `NaN`) will be rendered as an empty string. + * + * The timezone to be used to read/write the `Date` instance in the model can be defined using + * {@link ng.directive:ngModelOptions ngModelOptions}. By default, this is the timezone of the browser. + * + * @param {string} ngModel Assignable angular expression to data-bind to. + * @param {string=} name Property name of the form under which the control is published. + * @param {string=} min Sets the `min` validation error key if the value entered is less than `min`. This must be a + * valid ISO time format (HH:mm:ss). + * @param {string=} max Sets the `max` validation error key if the value entered is greater than `max`. This must be a + * valid ISO time format (HH:mm:ss). + * @param {string=} required Sets `required` validation error key if the value is not entered. + * @param {string=} ngRequired Adds `required` attribute and `required` validation constraint to + * the element when the ngRequired expression evaluates to true. Use `ngRequired` instead of + * `required` when you want to data-bind to the `required` attribute. + * @param {string=} ngChange Angular expression to be executed when input changes due to user + * interaction with the input element. + * + * @example + + + +
      + Pick a between 8am and 5pm: + + + Required! + + Not a valid date! + value = {{example.value | date: "HH:mm:ss"}}
      + myForm.input.$valid = {{myForm.input.$valid}}
      + myForm.input.$error = {{myForm.input.$error}}
      + myForm.$valid = {{myForm.$valid}}
      + myForm.$error.required = {{!!myForm.$error.required}}
      +
      +
      + + var value = element(by.binding('example.value | date: "HH:mm:ss"')); + var valid = element(by.binding('myForm.input.$valid')); + var input = element(by.model('example.value')); + + // currently protractor/webdriver does not support + // sending keys to all known HTML5 input controls + // for various browsers (https://github.com/angular/protractor/issues/562). + function setInput(val) { + // set the value of the element and force validation. + var scr = "var ipt = document.getElementById('exampleInput'); " + + "ipt.value = '" + val + "';" + + "angular.element(ipt).scope().$apply(function(s) { s.myForm[ipt.name].$setViewValue('" + val + "'); });"; + browser.executeScript(scr); + } + + it('should initialize to model', function() { + expect(value.getText()).toContain('14:57:00'); + expect(valid.getText()).toContain('myForm.input.$valid = true'); + }); + + it('should be invalid if empty', function() { + setInput(''); + expect(value.getText()).toEqual('value ='); + expect(valid.getText()).toContain('myForm.input.$valid = false'); + }); + + it('should be invalid if over max', function() { + setInput('23:59:00'); + expect(value.getText()).toContain(''); + expect(valid.getText()).toContain('myForm.input.$valid = false'); + }); + +
      + */ + 'time': createDateInputType('time', TIME_REGEXP, + createDateParser(TIME_REGEXP, ['HH', 'mm', 'ss', 'sss']), + 'HH:mm:ss.sss'), + + /** + * @ngdoc input + * @name input[week] + * + * @description + * Input with week-of-the-year validation and transformation to Date. In browsers that do not yet support + * the HTML5 week input, a text element will be used. In that case, the text must be entered in a valid ISO-8601 + * week format (yyyy-W##), for example: `2013-W02`. + * + * The model must always be a Date object, otherwise Angular will throw an error. + * Invalid `Date` objects (dates whose `getTime()` is `NaN`) will be rendered as an empty string. + * + * The timezone to be used to read/write the `Date` instance in the model can be defined using + * {@link ng.directive:ngModelOptions ngModelOptions}. By default, this is the timezone of the browser. + * + * @param {string} ngModel Assignable angular expression to data-bind to. + * @param {string=} name Property name of the form under which the control is published. + * @param {string=} min Sets the `min` validation error key if the value entered is less than `min`. This must be a + * valid ISO week format (yyyy-W##). + * @param {string=} max Sets the `max` validation error key if the value entered is greater than `max`. This must be + * a valid ISO week format (yyyy-W##). + * @param {string=} required Sets `required` validation error key if the value is not entered. + * @param {string=} ngRequired Adds `required` attribute and `required` validation constraint to + * the element when the ngRequired expression evaluates to true. Use `ngRequired` instead of + * `required` when you want to data-bind to the `required` attribute. + * @param {string=} ngChange Angular expression to be executed when input changes due to user + * interaction with the input element. + * + * @example + + + +
      + Pick a date between in 2013: + + + Required! + + Not a valid date! + value = {{example.value | date: "yyyy-Www"}}
      + myForm.input.$valid = {{myForm.input.$valid}}
      + myForm.input.$error = {{myForm.input.$error}}
      + myForm.$valid = {{myForm.$valid}}
      + myForm.$error.required = {{!!myForm.$error.required}}
      +
      +
      + + var value = element(by.binding('example.value | date: "yyyy-Www"')); + var valid = element(by.binding('myForm.input.$valid')); + var input = element(by.model('example.value')); + + // currently protractor/webdriver does not support + // sending keys to all known HTML5 input controls + // for various browsers (https://github.com/angular/protractor/issues/562). + function setInput(val) { + // set the value of the element and force validation. + var scr = "var ipt = document.getElementById('exampleInput'); " + + "ipt.value = '" + val + "';" + + "angular.element(ipt).scope().$apply(function(s) { s.myForm[ipt.name].$setViewValue('" + val + "'); });"; + browser.executeScript(scr); + } + + it('should initialize to model', function() { + expect(value.getText()).toContain('2013-W01'); + expect(valid.getText()).toContain('myForm.input.$valid = true'); + }); + + it('should be invalid if empty', function() { + setInput(''); + expect(value.getText()).toEqual('value ='); + expect(valid.getText()).toContain('myForm.input.$valid = false'); + }); + + it('should be invalid if over max', function() { + setInput('2015-W01'); + expect(value.getText()).toContain(''); + expect(valid.getText()).toContain('myForm.input.$valid = false'); + }); + +
      + */ + 'week': createDateInputType('week', WEEK_REGEXP, weekParser, 'yyyy-Www'), + + /** + * @ngdoc input + * @name input[month] + * + * @description + * Input with month validation and transformation. In browsers that do not yet support + * the HTML5 month input, a text element will be used. In that case, the text must be entered in a valid ISO-8601 + * month format (yyyy-MM), for example: `2009-01`. + * + * The model must always be a Date object, otherwise Angular will throw an error. + * Invalid `Date` objects (dates whose `getTime()` is `NaN`) will be rendered as an empty string. + * If the model is not set to the first of the month, the next view to model update will set it + * to the first of the month. + * + * The timezone to be used to read/write the `Date` instance in the model can be defined using + * {@link ng.directive:ngModelOptions ngModelOptions}. By default, this is the timezone of the browser. + * + * @param {string} ngModel Assignable angular expression to data-bind to. + * @param {string=} name Property name of the form under which the control is published. + * @param {string=} min Sets the `min` validation error key if the value entered is less than `min`. This must be + * a valid ISO month format (yyyy-MM). + * @param {string=} max Sets the `max` validation error key if the value entered is greater than `max`. This must + * be a valid ISO month format (yyyy-MM). + * @param {string=} required Sets `required` validation error key if the value is not entered. + * @param {string=} ngRequired Adds `required` attribute and `required` validation constraint to + * the element when the ngRequired expression evaluates to true. Use `ngRequired` instead of + * `required` when you want to data-bind to the `required` attribute. + * @param {string=} ngChange Angular expression to be executed when input changes due to user + * interaction with the input element. + * + * @example + + + +
      + Pick a month in 2013: + + + Required! + + Not a valid month! + value = {{example.value | date: "yyyy-MM"}}
      + myForm.input.$valid = {{myForm.input.$valid}}
      + myForm.input.$error = {{myForm.input.$error}}
      + myForm.$valid = {{myForm.$valid}}
      + myForm.$error.required = {{!!myForm.$error.required}}
      +
      +
      + + var value = element(by.binding('example.value | date: "yyyy-MM"')); + var valid = element(by.binding('myForm.input.$valid')); + var input = element(by.model('example.value')); + + // currently protractor/webdriver does not support + // sending keys to all known HTML5 input controls + // for various browsers (https://github.com/angular/protractor/issues/562). + function setInput(val) { + // set the value of the element and force validation. + var scr = "var ipt = document.getElementById('exampleInput'); " + + "ipt.value = '" + val + "';" + + "angular.element(ipt).scope().$apply(function(s) { s.myForm[ipt.name].$setViewValue('" + val + "'); });"; + browser.executeScript(scr); + } + + it('should initialize to model', function() { + expect(value.getText()).toContain('2013-10'); + expect(valid.getText()).toContain('myForm.input.$valid = true'); + }); + + it('should be invalid if empty', function() { + setInput(''); + expect(value.getText()).toEqual('value ='); + expect(valid.getText()).toContain('myForm.input.$valid = false'); + }); + + it('should be invalid if over max', function() { + setInput('2015-01'); + expect(value.getText()).toContain(''); + expect(valid.getText()).toContain('myForm.input.$valid = false'); + }); + +
      + */ + 'month': createDateInputType('month', MONTH_REGEXP, + createDateParser(MONTH_REGEXP, ['yyyy', 'MM']), + 'yyyy-MM'), + + /** + * @ngdoc input + * @name input[number] + * + * @description + * Text input with number validation and transformation. Sets the `number` validation + * error if not a valid number. + * + *
      + * The model must always be of type `number` otherwise Angular will throw an error. + * Be aware that a string containing a number is not enough. See the {@link ngModel:numfmt} + * error docs for more information and an example of how to convert your model if necessary. + *
      + * + * @param {string} ngModel Assignable angular expression to data-bind to. + * @param {string=} name Property name of the form under which the control is published. + * @param {string=} min Sets the `min` validation error key if the value entered is less than `min`. + * @param {string=} max Sets the `max` validation error key if the value entered is greater than `max`. + * @param {string=} required Sets `required` validation error key if the value is not entered. + * @param {string=} ngRequired Adds `required` attribute and `required` validation constraint to + * the element when the ngRequired expression evaluates to true. Use `ngRequired` instead of + * `required` when you want to data-bind to the `required` attribute. + * @param {number=} ngMinlength Sets `minlength` validation error key if the value is shorter than + * minlength. + * @param {number=} ngMaxlength Sets `maxlength` validation error key if the value is longer than + * maxlength. Setting the attribute to a negative or non-numeric value, allows view values of + * any length. + * @param {string=} pattern Similar to `ngPattern` except that the attribute value is the actual string + * that contains the regular expression body that will be converted to a regular expression + * as in the ngPattern directive. + * @param {string=} ngPattern Sets `pattern` validation error key if the ngModel value does not match + * a RegExp found by evaluating the Angular expression given in the attribute value. + * If the expression evaluates to a RegExp object then this is used directly. + * If the expression is a string then it will be converted to a RegExp after wrapping it in `^` and `$` + * characters. For instance, `"abc"` will be converted to `new RegExp('^abc$')`. + * @param {string=} ngChange Angular expression to be executed when input changes due to user + * interaction with the input element. + * + * @example + + + +
      + Number: + + Required! + + Not valid number! + value = {{example.value}}
      + myForm.input.$valid = {{myForm.input.$valid}}
      + myForm.input.$error = {{myForm.input.$error}}
      + myForm.$valid = {{myForm.$valid}}
      + myForm.$error.required = {{!!myForm.$error.required}}
      +
      +
      + + var value = element(by.binding('example.value')); + var valid = element(by.binding('myForm.input.$valid')); + var input = element(by.model('example.value')); + + it('should initialize to model', function() { + expect(value.getText()).toContain('12'); + expect(valid.getText()).toContain('true'); + }); + + it('should be invalid if empty', function() { + input.clear(); + input.sendKeys(''); + expect(value.getText()).toEqual('value ='); + expect(valid.getText()).toContain('false'); + }); + + it('should be invalid if over max', function() { + input.clear(); + input.sendKeys('123'); + expect(value.getText()).toEqual('value ='); + expect(valid.getText()).toContain('false'); + }); + +
      + */ + 'number': numberInputType, + + + /** + * @ngdoc input + * @name input[url] + * + * @description + * Text input with URL validation. Sets the `url` validation error key if the content is not a + * valid URL. + * + *
      + * **Note:** `input[url]` uses a regex to validate urls that is derived from the regex + * used in Chromium. If you need stricter validation, you can use `ng-pattern` or modify + * the built-in validators (see the {@link guide/forms Forms guide}) + *
      + * + * @param {string} ngModel Assignable angular expression to data-bind to. + * @param {string=} name Property name of the form under which the control is published. + * @param {string=} required Sets `required` validation error key if the value is not entered. + * @param {string=} ngRequired Adds `required` attribute and `required` validation constraint to + * the element when the ngRequired expression evaluates to true. Use `ngRequired` instead of + * `required` when you want to data-bind to the `required` attribute. + * @param {number=} ngMinlength Sets `minlength` validation error key if the value is shorter than + * minlength. + * @param {number=} ngMaxlength Sets `maxlength` validation error key if the value is longer than + * maxlength. Setting the attribute to a negative or non-numeric value, allows view values of + * any length. + * @param {string=} pattern Similar to `ngPattern` except that the attribute value is the actual string + * that contains the regular expression body that will be converted to a regular expression + * as in the ngPattern directive. + * @param {string=} ngPattern Sets `pattern` validation error key if the ngModel value does not match + * a RegExp found by evaluating the Angular expression given in the attribute value. + * If the expression evaluates to a RegExp object then this is used directly. + * If the expression is a string then it will be converted to a RegExp after wrapping it in `^` and `$` + * characters. For instance, `"abc"` will be converted to `new RegExp('^abc$')`. + * @param {string=} ngChange Angular expression to be executed when input changes due to user + * interaction with the input element. + * + * @example + + + +
      + URL: + + Required! + + Not valid url! + text = {{url.text}}
      + myForm.input.$valid = {{myForm.input.$valid}}
      + myForm.input.$error = {{myForm.input.$error}}
      + myForm.$valid = {{myForm.$valid}}
      + myForm.$error.required = {{!!myForm.$error.required}}
      + myForm.$error.url = {{!!myForm.$error.url}}
      +
      +
      + + var text = element(by.binding('url.text')); + var valid = element(by.binding('myForm.input.$valid')); + var input = element(by.model('url.text')); + + it('should initialize to model', function() { + expect(text.getText()).toContain('http://google.com'); + expect(valid.getText()).toContain('true'); + }); + + it('should be invalid if empty', function() { + input.clear(); + input.sendKeys(''); + + expect(text.getText()).toEqual('text ='); + expect(valid.getText()).toContain('false'); + }); + + it('should be invalid if not url', function() { + input.clear(); + input.sendKeys('box'); + + expect(valid.getText()).toContain('false'); + }); + +
      + */ + 'url': urlInputType, + + + /** + * @ngdoc input + * @name input[email] + * + * @description + * Text input with email validation. Sets the `email` validation error key if not a valid email + * address. + * + *
      + * **Note:** `input[email]` uses a regex to validate email addresses that is derived from the regex + * used in Chromium. If you need stricter validation (e.g. requiring a top-level domain), you can + * use `ng-pattern` or modify the built-in validators (see the {@link guide/forms Forms guide}) + *
      + * + * @param {string} ngModel Assignable angular expression to data-bind to. + * @param {string=} name Property name of the form under which the control is published. + * @param {string=} required Sets `required` validation error key if the value is not entered. + * @param {string=} ngRequired Adds `required` attribute and `required` validation constraint to + * the element when the ngRequired expression evaluates to true. Use `ngRequired` instead of + * `required` when you want to data-bind to the `required` attribute. + * @param {number=} ngMinlength Sets `minlength` validation error key if the value is shorter than + * minlength. + * @param {number=} ngMaxlength Sets `maxlength` validation error key if the value is longer than + * maxlength. Setting the attribute to a negative or non-numeric value, allows view values of + * any length. + * @param {string=} pattern Similar to `ngPattern` except that the attribute value is the actual string + * that contains the regular expression body that will be converted to a regular expression + * as in the ngPattern directive. + * @param {string=} ngPattern Sets `pattern` validation error key if the ngModel value does not match + * a RegExp found by evaluating the Angular expression given in the attribute value. + * If the expression evaluates to a RegExp object then this is used directly. + * If the expression is a string then it will be converted to a RegExp after wrapping it in `^` and `$` + * characters. For instance, `"abc"` will be converted to `new RegExp('^abc$')`. + * @param {string=} ngChange Angular expression to be executed when input changes due to user + * interaction with the input element. + * + * @example + + + +
      + Email: + + Required! + + Not valid email! + text = {{email.text}}
      + myForm.input.$valid = {{myForm.input.$valid}}
      + myForm.input.$error = {{myForm.input.$error}}
      + myForm.$valid = {{myForm.$valid}}
      + myForm.$error.required = {{!!myForm.$error.required}}
      + myForm.$error.email = {{!!myForm.$error.email}}
      +
      +
      + + var text = element(by.binding('email.text')); + var valid = element(by.binding('myForm.input.$valid')); + var input = element(by.model('email.text')); + + it('should initialize to model', function() { + expect(text.getText()).toContain('me@example.com'); + expect(valid.getText()).toContain('true'); + }); + + it('should be invalid if empty', function() { + input.clear(); + input.sendKeys(''); + expect(text.getText()).toEqual('text ='); + expect(valid.getText()).toContain('false'); + }); + + it('should be invalid if not email', function() { + input.clear(); + input.sendKeys('xxx'); + + expect(valid.getText()).toContain('false'); + }); + +
      + */ + 'email': emailInputType, + + + /** + * @ngdoc input + * @name input[radio] + * + * @description + * HTML radio button. + * + * @param {string} ngModel Assignable angular expression to data-bind to. + * @param {string} value The value to which the expression should be set when selected. + * @param {string=} name Property name of the form under which the control is published. + * @param {string=} ngChange Angular expression to be executed when input changes due to user + * interaction with the input element. + * @param {string} ngValue Angular expression which sets the value to which the expression should + * be set when selected. + * + * @example + + + +
      + Red
      + Green
      + Blue
      + color = {{color.name | json}}
      +
      + Note that `ng-value="specialValue"` sets radio item's value to be the value of `$scope.specialValue`. +
      + + it('should change state', function() { + var color = element(by.binding('color.name')); + + expect(color.getText()).toContain('blue'); + + element.all(by.model('color.name')).get(0).click(); + + expect(color.getText()).toContain('red'); + }); + +
      + */ + 'radio': radioInputType, + + + /** + * @ngdoc input + * @name input[checkbox] + * + * @description + * HTML checkbox. + * + * @param {string} ngModel Assignable angular expression to data-bind to. + * @param {string=} name Property name of the form under which the control is published. + * @param {expression=} ngTrueValue The value to which the expression should be set when selected. + * @param {expression=} ngFalseValue The value to which the expression should be set when not selected. + * @param {string=} ngChange Angular expression to be executed when input changes due to user + * interaction with the input element. + * + * @example + + + +
      + Value1:
      + Value2:
      + value1 = {{checkboxModel.value1}}
      + value2 = {{checkboxModel.value2}}
      +
      +
      + + it('should change state', function() { + var value1 = element(by.binding('checkboxModel.value1')); + var value2 = element(by.binding('checkboxModel.value2')); + + expect(value1.getText()).toContain('true'); + expect(value2.getText()).toContain('YES'); + + element(by.model('checkboxModel.value1')).click(); + element(by.model('checkboxModel.value2')).click(); + + expect(value1.getText()).toContain('false'); + expect(value2.getText()).toContain('NO'); + }); + +
      + */ + 'checkbox': checkboxInputType, + + 'hidden': noop, + 'button': noop, + 'submit': noop, + 'reset': noop, + 'file': noop +}; + +function stringBasedInputType(ctrl) { + ctrl.$formatters.push(function(value) { + return ctrl.$isEmpty(value) ? value : value.toString(); + }); +} + +function textInputType(scope, element, attr, ctrl, $sniffer, $browser) { + baseInputType(scope, element, attr, ctrl, $sniffer, $browser); + stringBasedInputType(ctrl); +} + +function baseInputType(scope, element, attr, ctrl, $sniffer, $browser) { + var type = lowercase(element[0].type); + + // In composition mode, users are still inputing intermediate text buffer, + // hold the listener until composition is done. + // More about composition events: https://developer.mozilla.org/en-US/docs/Web/API/CompositionEvent + if (!$sniffer.android) { + var composing = false; + + element.on('compositionstart', function(data) { + composing = true; + }); + + element.on('compositionend', function() { + composing = false; + listener(); + }); + } + + var listener = function(ev) { + if (timeout) { + $browser.defer.cancel(timeout); + timeout = null; + } + if (composing) return; + var value = element.val(), + event = ev && ev.type; + + // By default we will trim the value + // If the attribute ng-trim exists we will avoid trimming + // If input type is 'password', the value is never trimmed + if (type !== 'password' && (!attr.ngTrim || attr.ngTrim !== 'false')) { + value = trim(value); + } + + // If a control is suffering from bad input (due to native validators), browsers discard its + // value, so it may be necessary to revalidate (by calling $setViewValue again) even if the + // control's value is the same empty value twice in a row. + if (ctrl.$viewValue !== value || (value === '' && ctrl.$$hasNativeValidators)) { + ctrl.$setViewValue(value, event); + } + }; + + // if the browser does support "input" event, we are fine - except on IE9 which doesn't fire the + // input event on backspace, delete or cut + if ($sniffer.hasEvent('input')) { + element.on('input', listener); + } else { + var timeout; + + var deferListener = function(ev, input, origValue) { + if (!timeout) { + timeout = $browser.defer(function() { + timeout = null; + if (!input || input.value !== origValue) { + listener(ev); + } + }); + } + }; + + element.on('keydown', function(event) { + var key = event.keyCode; + + // ignore + // command modifiers arrows + if (key === 91 || (15 < key && key < 19) || (37 <= key && key <= 40)) return; + + deferListener(event, this, this.value); + }); + + // if user modifies input value using context menu in IE, we need "paste" and "cut" events to catch it + if ($sniffer.hasEvent('paste')) { + element.on('paste cut', deferListener); + } + } + + // if user paste into input using mouse on older browser + // or form autocomplete on newer browser, we need "change" event to catch it + element.on('change', listener); + + ctrl.$render = function() { + element.val(ctrl.$isEmpty(ctrl.$viewValue) ? '' : ctrl.$viewValue); + }; +} + +function weekParser(isoWeek, existingDate) { + if (isDate(isoWeek)) { + return isoWeek; + } + + if (isString(isoWeek)) { + WEEK_REGEXP.lastIndex = 0; + var parts = WEEK_REGEXP.exec(isoWeek); + if (parts) { + var year = +parts[1], + week = +parts[2], + hours = 0, + minutes = 0, + seconds = 0, + milliseconds = 0, + firstThurs = getFirstThursdayOfYear(year), + addDays = (week - 1) * 7; + + if (existingDate) { + hours = existingDate.getHours(); + minutes = existingDate.getMinutes(); + seconds = existingDate.getSeconds(); + milliseconds = existingDate.getMilliseconds(); + } + + return new Date(year, 0, firstThurs.getDate() + addDays, hours, minutes, seconds, milliseconds); + } + } + + return NaN; +} + +function createDateParser(regexp, mapping) { + return function(iso, date) { + var parts, map; + + if (isDate(iso)) { + return iso; + } + + if (isString(iso)) { + // When a date is JSON'ified to wraps itself inside of an extra + // set of double quotes. This makes the date parsing code unable + // to match the date string and parse it as a date. + if (iso.charAt(0) == '"' && iso.charAt(iso.length - 1) == '"') { + iso = iso.substring(1, iso.length - 1); + } + if (ISO_DATE_REGEXP.test(iso)) { + return new Date(iso); + } + regexp.lastIndex = 0; + parts = regexp.exec(iso); + + if (parts) { + parts.shift(); + if (date) { + map = { + yyyy: date.getFullYear(), + MM: date.getMonth() + 1, + dd: date.getDate(), + HH: date.getHours(), + mm: date.getMinutes(), + ss: date.getSeconds(), + sss: date.getMilliseconds() / 1000 + }; + } else { + map = { yyyy: 1970, MM: 1, dd: 1, HH: 0, mm: 0, ss: 0, sss: 0 }; + } + + forEach(parts, function(part, index) { + if (index < mapping.length) { + map[mapping[index]] = +part; + } + }); + return new Date(map.yyyy, map.MM - 1, map.dd, map.HH, map.mm, map.ss || 0, map.sss * 1000 || 0); + } + } + + return NaN; + }; +} + +function createDateInputType(type, regexp, parseDate, format) { + return function dynamicDateInputType(scope, element, attr, ctrl, $sniffer, $browser, $filter) { + badInputChecker(scope, element, attr, ctrl); + baseInputType(scope, element, attr, ctrl, $sniffer, $browser); + var timezone = ctrl && ctrl.$options && ctrl.$options.timezone; + var previousDate; + + ctrl.$$parserName = type; + ctrl.$parsers.push(function(value) { + if (ctrl.$isEmpty(value)) return null; + if (regexp.test(value)) { + // Note: We cannot read ctrl.$modelValue, as there might be a different + // parser/formatter in the processing chain so that the model + // contains some different data format! + var parsedDate = parseDate(value, previousDate); + if (timezone === 'UTC') { + parsedDate.setMinutes(parsedDate.getMinutes() - parsedDate.getTimezoneOffset()); + } + return parsedDate; + } + return undefined; + }); + + ctrl.$formatters.push(function(value) { + if (value && !isDate(value)) { + throw ngModelMinErr('datefmt', 'Expected `{0}` to be a date', value); + } + if (isValidDate(value)) { + previousDate = value; + if (previousDate && timezone === 'UTC') { + var timezoneOffset = 60000 * previousDate.getTimezoneOffset(); + previousDate = new Date(previousDate.getTime() + timezoneOffset); + } + return $filter('date')(value, format, timezone); + } else { + previousDate = null; + return ''; + } + }); + + if (isDefined(attr.min) || attr.ngMin) { + var minVal; + ctrl.$validators.min = function(value) { + return !isValidDate(value) || isUndefined(minVal) || parseDate(value) >= minVal; + }; + attr.$observe('min', function(val) { + minVal = parseObservedDateValue(val); + ctrl.$validate(); + }); + } + + if (isDefined(attr.max) || attr.ngMax) { + var maxVal; + ctrl.$validators.max = function(value) { + return !isValidDate(value) || isUndefined(maxVal) || parseDate(value) <= maxVal; + }; + attr.$observe('max', function(val) { + maxVal = parseObservedDateValue(val); + ctrl.$validate(); + }); + } + + function isValidDate(value) { + // Invalid Date: getTime() returns NaN + return value && !(value.getTime && value.getTime() !== value.getTime()); + } + + function parseObservedDateValue(val) { + return isDefined(val) ? (isDate(val) ? val : parseDate(val)) : undefined; + } + }; +} + +function badInputChecker(scope, element, attr, ctrl) { + var node = element[0]; + var nativeValidation = ctrl.$$hasNativeValidators = isObject(node.validity); + if (nativeValidation) { + ctrl.$parsers.push(function(value) { + var validity = element.prop(VALIDITY_STATE_PROPERTY) || {}; + // Detect bug in FF35 for input[email] (https://bugzilla.mozilla.org/show_bug.cgi?id=1064430): + // - also sets validity.badInput (should only be validity.typeMismatch). + // - see http://www.whatwg.org/specs/web-apps/current-work/multipage/forms.html#e-mail-state-(type=email) + // - can ignore this case as we can still read out the erroneous email... + return validity.badInput && !validity.typeMismatch ? undefined : value; + }); + } +} + +function numberInputType(scope, element, attr, ctrl, $sniffer, $browser) { + badInputChecker(scope, element, attr, ctrl); + baseInputType(scope, element, attr, ctrl, $sniffer, $browser); + + ctrl.$$parserName = 'number'; + ctrl.$parsers.push(function(value) { + if (ctrl.$isEmpty(value)) return null; + if (NUMBER_REGEXP.test(value)) return parseFloat(value); + return undefined; + }); + + ctrl.$formatters.push(function(value) { + if (!ctrl.$isEmpty(value)) { + if (!isNumber(value)) { + throw ngModelMinErr('numfmt', 'Expected `{0}` to be a number', value); + } + value = value.toString(); + } + return value; + }); + + if (isDefined(attr.min) || attr.ngMin) { + var minVal; + ctrl.$validators.min = function(value) { + return ctrl.$isEmpty(value) || isUndefined(minVal) || value >= minVal; + }; + + attr.$observe('min', function(val) { + if (isDefined(val) && !isNumber(val)) { + val = parseFloat(val, 10); + } + minVal = isNumber(val) && !isNaN(val) ? val : undefined; + // TODO(matsko): implement validateLater to reduce number of validations + ctrl.$validate(); + }); + } + + if (isDefined(attr.max) || attr.ngMax) { + var maxVal; + ctrl.$validators.max = function(value) { + return ctrl.$isEmpty(value) || isUndefined(maxVal) || value <= maxVal; + }; + + attr.$observe('max', function(val) { + if (isDefined(val) && !isNumber(val)) { + val = parseFloat(val, 10); + } + maxVal = isNumber(val) && !isNaN(val) ? val : undefined; + // TODO(matsko): implement validateLater to reduce number of validations + ctrl.$validate(); + }); + } +} + +function urlInputType(scope, element, attr, ctrl, $sniffer, $browser) { + // Note: no badInputChecker here by purpose as `url` is only a validation + // in browsers, i.e. we can always read out input.value even if it is not valid! + baseInputType(scope, element, attr, ctrl, $sniffer, $browser); + stringBasedInputType(ctrl); + + ctrl.$$parserName = 'url'; + ctrl.$validators.url = function(modelValue, viewValue) { + var value = modelValue || viewValue; + return ctrl.$isEmpty(value) || URL_REGEXP.test(value); + }; +} + +function emailInputType(scope, element, attr, ctrl, $sniffer, $browser) { + // Note: no badInputChecker here by purpose as `url` is only a validation + // in browsers, i.e. we can always read out input.value even if it is not valid! + baseInputType(scope, element, attr, ctrl, $sniffer, $browser); + stringBasedInputType(ctrl); + + ctrl.$$parserName = 'email'; + ctrl.$validators.email = function(modelValue, viewValue) { + var value = modelValue || viewValue; + return ctrl.$isEmpty(value) || EMAIL_REGEXP.test(value); + }; +} + +function radioInputType(scope, element, attr, ctrl) { + // make the name unique, if not defined + if (isUndefined(attr.name)) { + element.attr('name', nextUid()); + } + + var listener = function(ev) { + if (element[0].checked) { + ctrl.$setViewValue(attr.value, ev && ev.type); + } + }; + + element.on('click', listener); + + ctrl.$render = function() { + var value = attr.value; + element[0].checked = (value == ctrl.$viewValue); + }; + + attr.$observe('value', ctrl.$render); +} + +function parseConstantExpr($parse, context, name, expression, fallback) { + var parseFn; + if (isDefined(expression)) { + parseFn = $parse(expression); + if (!parseFn.constant) { + throw ngModelMinErr('constexpr', 'Expected constant expression for `{0}`, but saw ' + + '`{1}`.', name, expression); + } + return parseFn(context); + } + return fallback; +} + +function checkboxInputType(scope, element, attr, ctrl, $sniffer, $browser, $filter, $parse) { + var trueValue = parseConstantExpr($parse, scope, 'ngTrueValue', attr.ngTrueValue, true); + var falseValue = parseConstantExpr($parse, scope, 'ngFalseValue', attr.ngFalseValue, false); + + var listener = function(ev) { + ctrl.$setViewValue(element[0].checked, ev && ev.type); + }; + + element.on('click', listener); + + ctrl.$render = function() { + element[0].checked = ctrl.$viewValue; + }; + + // Override the standard `$isEmpty` because the $viewValue of an empty checkbox is always set to `false` + // This is because of the parser below, which compares the `$modelValue` with `trueValue` to convert + // it to a boolean. + ctrl.$isEmpty = function(value) { + return value === false; + }; + + ctrl.$formatters.push(function(value) { + return equals(value, trueValue); + }); + + ctrl.$parsers.push(function(value) { + return value ? trueValue : falseValue; + }); +} + + +/** + * @ngdoc directive + * @name textarea + * @restrict E + * + * @description + * HTML textarea element control with angular data-binding. The data-binding and validation + * properties of this element are exactly the same as those of the + * {@link ng.directive:input input element}. + * + * @param {string} ngModel Assignable angular expression to data-bind to. + * @param {string=} name Property name of the form under which the control is published. + * @param {string=} required Sets `required` validation error key if the value is not entered. + * @param {string=} ngRequired Adds `required` attribute and `required` validation constraint to + * the element when the ngRequired expression evaluates to true. Use `ngRequired` instead of + * `required` when you want to data-bind to the `required` attribute. + * @param {number=} ngMinlength Sets `minlength` validation error key if the value is shorter than + * minlength. + * @param {number=} ngMaxlength Sets `maxlength` validation error key if the value is longer than + * maxlength. Setting the attribute to a negative or non-numeric value, allows view values of any + * length. + * @param {string=} ngPattern Sets `pattern` validation error key if the value does not match the + * RegExp pattern expression. Expected value is `/regexp/` for inline patterns or `regexp` for + * patterns defined as scope expressions. + * @param {string=} ngChange Angular expression to be executed when input changes due to user + * interaction with the input element. + * @param {boolean=} [ngTrim=true] If set to false Angular will not automatically trim the input. + */ + + +/** + * @ngdoc directive + * @name input + * @restrict E + * + * @description + * HTML input element control. When used together with {@link ngModel `ngModel`}, it provides data-binding, + * input state control, and validation. + * Input control follows HTML5 input types and polyfills the HTML5 validation behavior for older browsers. + * + *
      + * **Note:** Not every feature offered is available for all input types. + * Specifically, data binding and event handling via `ng-model` is unsupported for `input[file]`. + *
      + * + * @param {string} ngModel Assignable angular expression to data-bind to. + * @param {string=} name Property name of the form under which the control is published. + * @param {string=} required Sets `required` validation error key if the value is not entered. + * @param {boolean=} ngRequired Sets `required` attribute if set to true + * @param {number=} ngMinlength Sets `minlength` validation error key if the value is shorter than + * minlength. + * @param {number=} ngMaxlength Sets `maxlength` validation error key if the value is longer than + * maxlength. Setting the attribute to a negative or non-numeric value, allows view values of any + * length. + * @param {string=} ngPattern Sets `pattern` validation error key if the value does not match the + * RegExp pattern expression. Expected value is `/regexp/` for inline patterns or `regexp` for + * patterns defined as scope expressions. + * @param {string=} ngChange Angular expression to be executed when input changes due to user + * interaction with the input element. + * @param {boolean=} [ngTrim=true] If set to false Angular will not automatically trim the input. + * This parameter is ignored for input[type=password] controls, which will never trim the + * input. + * + * @example + + + +
      +
      + User name: + + Required!
      + Last name: + + Too short! + + Too long!
      +
      +
      + user = {{user}}
      + myForm.userName.$valid = {{myForm.userName.$valid}}
      + myForm.userName.$error = {{myForm.userName.$error}}
      + myForm.lastName.$valid = {{myForm.lastName.$valid}}
      + myForm.lastName.$error = {{myForm.lastName.$error}}
      + myForm.$valid = {{myForm.$valid}}
      + myForm.$error.required = {{!!myForm.$error.required}}
      + myForm.$error.minlength = {{!!myForm.$error.minlength}}
      + myForm.$error.maxlength = {{!!myForm.$error.maxlength}}
      +
      +
      + + var user = element(by.exactBinding('user')); + var userNameValid = element(by.binding('myForm.userName.$valid')); + var lastNameValid = element(by.binding('myForm.lastName.$valid')); + var lastNameError = element(by.binding('myForm.lastName.$error')); + var formValid = element(by.binding('myForm.$valid')); + var userNameInput = element(by.model('user.name')); + var userLastInput = element(by.model('user.last')); + + it('should initialize to model', function() { + expect(user.getText()).toContain('{"name":"guest","last":"visitor"}'); + expect(userNameValid.getText()).toContain('true'); + expect(formValid.getText()).toContain('true'); + }); + + it('should be invalid if empty when required', function() { + userNameInput.clear(); + userNameInput.sendKeys(''); + + expect(user.getText()).toContain('{"last":"visitor"}'); + expect(userNameValid.getText()).toContain('false'); + expect(formValid.getText()).toContain('false'); + }); + + it('should be valid if empty when min length is set', function() { + userLastInput.clear(); + userLastInput.sendKeys(''); + + expect(user.getText()).toContain('{"name":"guest","last":""}'); + expect(lastNameValid.getText()).toContain('true'); + expect(formValid.getText()).toContain('true'); + }); + + it('should be invalid if less than required min length', function() { + userLastInput.clear(); + userLastInput.sendKeys('xx'); + + expect(user.getText()).toContain('{"name":"guest"}'); + expect(lastNameValid.getText()).toContain('false'); + expect(lastNameError.getText()).toContain('minlength'); + expect(formValid.getText()).toContain('false'); + }); + + it('should be invalid if longer than max length', function() { + userLastInput.clear(); + userLastInput.sendKeys('some ridiculously long name'); + + expect(user.getText()).toContain('{"name":"guest"}'); + expect(lastNameValid.getText()).toContain('false'); + expect(lastNameError.getText()).toContain('maxlength'); + expect(formValid.getText()).toContain('false'); + }); + +
      + */ +var inputDirective = ['$browser', '$sniffer', '$filter', '$parse', + function($browser, $sniffer, $filter, $parse) { + return { + restrict: 'E', + require: ['?ngModel'], + link: { + pre: function(scope, element, attr, ctrls) { + if (ctrls[0]) { + (inputType[lowercase(attr.type)] || inputType.text)(scope, element, attr, ctrls[0], $sniffer, + $browser, $filter, $parse); + } + } + } + }; +}]; + + + +var CONSTANT_VALUE_REGEXP = /^(true|false|\d+)$/; +/** + * @ngdoc directive + * @name ngValue + * + * @description + * Binds the given expression to the value of `